-
Notifications
You must be signed in to change notification settings - Fork 0
/
conio_cputc.c
64 lines (55 loc) · 1.57 KB
/
conio_cputc.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
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "conio.h"
void inc_row() {
int y = 23;
if (nTextFlags & TEXT_HEIGHT_30) {
y = 29;
}
if (conio_y >= y) {
scrn_scroll();
conio_y = y;
} else {
++conio_y;
}
}
void cputc(int ch) {
if (ch >= ' ') {
vsetchar(conio_getvram(), ch);
++conio_x;
if (conio_x > nTextEnd-nTextRow) {
conio_x=0;
inc_row();
}
} else {
// handle some control codes
switch (ch) {
case '\b': // backspace
--conio_x;
if (conio_x < 0) {
conio_x = nTextEnd-nTextRow+1;
if (conio_y > 0) --conio_y;
}
break;
case '\f': // form feed (clear screen)
clrscr();
break;
case '\n': // newline - next row and return to 0
inc_row();
conio_x = 0;
break;
case '\r': // carriage return - return to 0 on same row
conio_x = 0;
break;
case '\t': // tab - move to next tabstop (every 4)
conio_x++;
while (conio_x&0x03) ++conio_x; // every four characters is a tab
if (conio_x > nTextEnd-nTextRow) {
conio_x = 0;
inc_row();
}
break;
case '\v': // vertical tab - next row, same x
inc_row();
break;
}
}
}