-
Notifications
You must be signed in to change notification settings - Fork 10
/
str_gets.c
50 lines (45 loc) · 1.03 KB
/
str_gets.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <vdp.h>
#include <kscan.h>
// read from keyboard - limits to maxlen chars
// no autorepeat :)
void gets(char *buf, int maxlen) {
char oldch;
int cnt = maxlen;
oldch = 255;
while (cnt) {
vdpchar(nTextPos, 30); // cursor
while (kscan(5) == oldch) { // wait for key, 99/4 mode, allow interrupts
VDP_INT_ENABLE;
VDP_INT_DISABLE;
}
oldch = KSCAN_KEY;
switch (oldch) {
case '\r':
cnt = 0;
*buf = '\0';
vdpchar(nTextPos, ' ');
putchar('\n');
// wait for enter to be released
while (kscan(5) == oldch) {
VDP_INT_ENABLE;
VDP_INT_DISABLE;
}
break;
case 8: // backspace
if (cnt < maxlen) {
++cnt;
vdpchar(nTextPos, ' ');
--nTextPos;
--buf;
}
break;
default:
if ((oldch >= ' ') && (oldch <= 'Z') && (cnt > 1)) {
putchar(oldch);
*(buf++)=oldch;
--cnt;
}
break;
}
}
}