-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstdio.c
More file actions
130 lines (111 loc) · 1.57 KB
/
Copy pathstdio.c
File metadata and controls
130 lines (111 loc) · 1.57 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "stdio.h"
#include "bdos.h"
#define INITXT 0x006C
#define EXPTBL 0xFCC1
#define CALSLT 0x001C
uint VAddr = 0;
uint CsrX = 0;
uint CsrY = 0;
__at(0xF3B0) uchar LINLEN;
__at(0xF3AE) uchar LINL40;
__at(0xf3dc) uchar CSRX;
__at(0xf3dd) uchar CSRY;
void iniTxt() __naked
{
LINLEN = 80;
LINL40 = 80;
CsrX = 0;
CsrY = 0;
VAddr = 0;
__asm
push ix
ld ix,#INITXT
ld iy,(EXPTBL-1)
call CALSLT
di
pop ix
ret
__endasm;
}
int putchar(int c)
{
if (c >= 0)
_putch((char)c);
return c;
}
int getchar()
{
return 0;
}
bool is_key_pressed()
{
uchar row;
for(row = 0; row < 11; row++)
{
PPIC = (PPIC & 0xf0) | row;
if (PPIB != 255) return TRUE;
}
return FALSE;
}
void _putch(uchar c) __naked
{
switch(c)
{
case 0x0a:
CsrY++;
break;
case 0x0d:
CsrX = 0;
break;
default:
if (c > 31)
{
VAddr = CsrX + (CsrY << 6) + (CsrY << 4);
__asm
call ___sdcc_enter_ix
ld a,(_VAddr)
out (#0x99),a
ld a,(_VAddr+1)
and a,#0x3f
or a,#0x40
out (#0x99),a
ld a, 4 (ix)
out (#0x98),a
ld sp, ix
pop ix
__endasm;
CsrX++;
}
break;
}
if (CsrX > 79)
{
CsrX = 0;
CsrY++;
}
if (CsrY > 23)
{
CsrY = 0;
}
return;
}
char _getch() __naked
{
__asm
ret
__endasm;
}
void fputs(const char *s)
{
while(*s != NULL)
_putch(*s++);
}
uint getXY()
{
return CsrX << 8 | CsrY;
}
void setXY(uint xy)
{
CsrY = (uchar)(xy & 0x00ff);
CsrX = (uchar)(xy >> 8);
}