Time-limited get-key

Post Reply
sblendorio
Member
Posts: 20
Joined: Tue Jan 19, 2021 9:03 am

Time-limited get-key

Post by sblendorio »

Hi, I'm trying to make a pause (like "sleep()" or "msleep()") that can be interruptable by a key pression. I tried this but did not work.

Code: Select all

char pausekey() {
    int t;
    char ch;
    for (t=0; t<1000; ++t) {
        ch = getk();
        if (ch) return ch;
        msleep(10);
    }
    return 0;
}
Target is CP/M on 8080 (clib=8080).

Thanks in advance!
User avatar
dom
Well known member
Posts: 1448
Joined: Sun Jul 15, 2007 10:01 pm

Re: Time-limited get-key

Post by dom »

I've just tried this out and this should work.

It will be dependent on the clock speed: what environment are you testing this in?
sblendorio
Member
Posts: 20
Joined: Tue Jan 19, 2021 9:03 am

Re: Time-limited get-key

Post by sblendorio »

It's an IMSAI 8080, so it's an Intel 8080 @ 2 MHz
User avatar
dom
Well known member
Posts: 1448
Joined: Sun Jul 15, 2007 10:01 pm

Re: Time-limited get-key

Post by dom »

That shouldn't be the problem I was thinking of then!

I'm using this program:

Code: Select all

#include <stdio.h>
#include <stdlib.h>

char pausekey() {
    int t;
    int ch;
    for (t=0; t<1000; ++t) {
        ch = getk();
        if (ch) return ch;
        msleep(10);
    }
    return 0;
}

int getsp() {
#asm
        ld      hl,0
        add     hl,sp
#endasm
}

int main() {

        while ( 1 ) {
                int ch = pausekey();

                printf("Read sp %d %d\n",getsp(),ch);
        }
}
And z80pack, and this yields this result:

Code: Select all

54K CP/M 2.2 VERS B02

A>c:
C>dir
C: A        COM
C>a
Read sp -15525 102
Read sp -15525 102
Read sp -15525 97
Read sp -15525 49
Read sp -15525 50
Read sp -15525 111
Read sp -15525 112
Read sp -15525 107
Read sp -15525 109
Read sp -15525 110
Read sp -15525 102
Read sp -15525 106
Read sp -15525 108
Read sp -15525 101
Read sp -15525 106
Read sp -15525 106
Read sp -15525 0
Read sp -15525 0
Read sp -15525 0
Read sp -15525 0
So it does appear to be working in general. The delay seems to be longer than 10 seconds, I think this is because the delay loop is tuned to a z80 running at 4Mhz.

Given that it appears to work, what's the issue that you are seeing?
sblendorio
Member
Posts: 20
Joined: Tue Jan 19, 2021 9:03 am

Re: Time-limited get-key

Post by sblendorio »

thank you!
Post Reply