-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconio_cgetc.c
48 lines (42 loc) · 1.35 KB
/
conio_cgetc.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
#include "vdp.h"
#include "conio.h"
#include "kscan.h"
int conio_cursorFlag = 1;
int conio_cursorChar = 30; // you can override this!
int conio_allowInts = 1; // you can override this to disable Interrupts
extern unsigned char last_conio_key; // in kbhit
#define BLINK_RATE 200
// no keyboard buffer on the TI, but to support kbhit() we will implement a single-key one
// requires a NEW keypress (or buffered from kbhit)
// Note this will turn interrupts OFF (if they were on) unless conio_allowInts is 0
// If you have interrupts ON, then you MUST disable the blinking cursor.
unsigned char cgetc() {
unsigned char k = -1;
int blink = -BLINK_RATE;
if (last_conio_key != 255) {
k = last_conio_key;
last_conio_key = 255;
return k;
}
do {
if (conio_allowInts) {
VDP_INT_POLL;
}
if (conio_cursorFlag) {
if (blink == -BLINK_RATE) {
vsetchar(conio_getvram(), conio_cursorChar);
}
if (blink == 0) {
vsetchar(conio_getvram(), ' ');
}
if (blink < BLINK_RATE) {
++blink;
} else {
blink = -BLINK_RATE;
}
}
k = kscan(5);
} while ((k == 255) || ((KSCAN_STATUS&KSCAN_MASK) == 0));
vsetchar(conio_getvram(), ' ');
return k;
}