Page 1 of 1
Time-limited get-key
Posted: Fri Sep 10, 2021 2:42 pm
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!
Re: Time-limited get-key
Posted: Fri Sep 10, 2021 5:36 pm
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?
Re: Time-limited get-key
Posted: Sat Sep 11, 2021 3:16 pm
by sblendorio
It's an IMSAI 8080, so it's an Intel 8080 @ 2 MHz
Re: Time-limited get-key
Posted: Sat Sep 11, 2021 4:23 pm
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?
Re: Time-limited get-key
Posted: Mon Sep 13, 2021 12:50 pm
by sblendorio
thank you!