-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsxbios.c
340 lines (278 loc) · 5.38 KB
/
msxbios.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*
http://map.grauw.nl/resources/msxbios.php
http://map.grauw.nl/resources/msxsystemvars.php
https://www.msx.org/wiki/System_variables_and_work_area
*/
#include "msxbios.h"
#define MSXUSR_LOAD_A() __asm__("ld a,l");
#define MSXUSR_LOAD_E() __asm__("ld e,h");
#define MSXUSR_RTN_HL()
#define MSXUSR_RTN_A() __asm__("ld l,a");
#define MSXUSR_RTN_Z()\
__asm__("ld l,#0");\
__asm__("ret nz");\
__asm__("inc l");
#define MSXUSR_RTN_C()\
__asm__("ld l,#0");\
__asm__("ret nc");\
__asm__("inc l");
union {
struct {
uint16_t iy,ix,de,bc,af,hl;
} w;
struct {
uint8_t iyl,iyh,ixl,ixh,e,d,c,b,f,a,l,h;
} b;
} REGS;
void LOAD_REGS() {
__asm__("ld de,(_REGS+4)");
__asm__("ld bc,(_REGS+6)");
__asm__("ld a,(_REGS+9)");
__asm__("ld hl,(_REGS+10)");
// TODO: load other regs?
}
#define MSXUSR_LOAD_REGS(bioscall)\
LOAD_REGS();\
MSXUSR(bioscall);
void RDSLT(uint8_t slot, uint16_t addr) {
REGS.b.a = slot;
REGS.w.hl = addr;
MSXUSR_LOAD_REGS(0x000c);
}
void WRSLT(uint8_t slot, uint16_t addr, uint8_t value) {
REGS.b.a = slot;
REGS.w.hl = addr;
REGS.b.e = value;
MSXUSR_LOAD_REGS(0x0014);
}
void DISSCR() __z88dk_fastcall {
MSXUSR(0x0041);
}
void ENASCR() __z88dk_fastcall {
MSXUSR(0x0044);
}
void WRTVDP(uint16_t reg_data) __z88dk_fastcall {
reg_data;
__asm__("ld b,l");
__asm__("ld c,h");
MSXUSR(0x0047);
}
uint8_t RDVRM(uint16_t addr) __z88dk_fastcall {
addr;
MSXUSR(0x004a);
MSXUSR_RTN_A();
}
void WRTVRM(uint16_t addr, uint8_t data) {
REGS.w.hl = addr;
REGS.b.a = data;
MSXUSR_LOAD_REGS(0x004d);
}
void SETRD() {
MSXUSR(0x0050);
}
void SETWRT() {
MSXUSR(0x0053);
}
void FILVRM(uint16_t start, uint16_t len, uint8_t data) {
REGS.w.hl = start;
REGS.w.bc = len;
REGS.b.a = data;
MSXUSR_LOAD_REGS(0x0056);
}
void LDIRMV(uint8_t* mdest, uint16_t vsrc, uint16_t count) {
REGS.w.de = (uint16_t)mdest;
REGS.w.hl = vsrc;
REGS.w.bc = count;
MSXUSR_LOAD_REGS(0x0059);
}
void LDIRVM(uint16_t vdest, const uint8_t* msrc, uint16_t count) {
REGS.w.de = vdest;
REGS.w.hl = (uint16_t)msrc;
REGS.w.bc = count;
MSXUSR_LOAD_REGS(0x005c);
}
void CHGMOD(uint8_t mode) __z88dk_fastcall {
mode;
MSXUSR_LOAD_A();
MSXUSR(0x005f);
}
void CHGCLR() __z88dk_fastcall {
// TODO
MSXUSR(0x0062);
}
void CLRSPR() __z88dk_fastcall {
MSXUSR(0x0069);
}
void INITXT() __z88dk_fastcall {
MSXUSR(0x006c);
}
void INIT32() __z88dk_fastcall {
MSXUSR(0x006f);
}
void INIGRP() __z88dk_fastcall {
MSXUSR(0x0072);
}
void INIMLT() __z88dk_fastcall {
MSXUSR(0x0075);
}
uint16_t CALPAT() __z88dk_fastcall {
MSXUSR(0x0084);
MSXUSR_RTN_HL();
}
uint16_t CALATR() __z88dk_fastcall {
MSXUSR(0x0087);
MSXUSR_RTN_HL();
}
uint8_t GSPSIZ() __z88dk_fastcall {
MSXUSR(0x008a);
MSXUSR_RTN_A();
}
void GRPPRT(char ch) __z88dk_fastcall {
ch;
MSXUSR_LOAD_A();
MSXUSR(0x008d);
}
void GICINI() __z88dk_fastcall {
MSXUSR(0x0090);
}
void WRTPSG(uint16_t reg_data) __z88dk_fastcall {
reg_data;
MSXUSR_LOAD_A();
MSXUSR_LOAD_E();
MSXUSR(0x0093);
}
uint8_t CHSNS() __z88dk_fastcall {
MSXUSR(0x009c);
MSXUSR_RTN_Z();
}
char CHGET() __z88dk_fastcall {
MSXUSR(0x009f);
MSXUSR_RTN_A();
}
void CHPUT(char ch) __z88dk_fastcall {
ch;
MSXUSR_LOAD_A();
MSXUSR(0x00a2);
}
void LPTOUT(char ch) __z88dk_fastcall {
ch;
MSXUSR_LOAD_A();
MSXUSR(0x00a5);
}
void BEEP() __z88dk_fastcall {
MSXUSR(0x00c0);
}
void CLS() __z88dk_fastcall {
__asm__("xor a");
MSXUSR(0x00c3);
}
void POSIT(uint16_t yx) __z88dk_fastcall {
yx;
MSXUSR(0x00c6);
}
void TOTEXT() __z88dk_fastcall {
MSXUSR(0x00d2);
}
uint8_t GTSTCK(uint8_t index) __z88dk_fastcall {
index;
MSXUSR_LOAD_A();
MSXUSR(0x00d5);
MSXUSR_RTN_A();
}
uint8_t GTTRIG(uint8_t index) __z88dk_fastcall {
index;
MSXUSR_LOAD_A();
MSXUSR(0x00d8);
MSXUSR_RTN_A();
}
uint8_t GTPAD(uint8_t index) __z88dk_fastcall {
index;
MSXUSR_LOAD_A();
MSXUSR(0x00db);
MSXUSR_RTN_A();
}
uint8_t GTPDL(uint8_t index) __z88dk_fastcall {
index;
MSXUSR_LOAD_A();
MSXUSR(0x00de);
MSXUSR_RTN_A();
}
/*
void RIGHTC() __z88dk_fastcall {
MSXUSR(0x00fc);
}
void LEFTC() __z88dk_fastcall {
MSXUSR(0x00ff);
}
void UPC() __z88dk_fastcall {
MSXUSR(0x0102);
}
uint8_t TUPC() __z88dk_fastcall {
MSXUSR(0x0105);
MSXUSR_RTN_C();
}
void DOWNC() __z88dk_fastcall {
MSXUSR(0x0108);
}
uint8_t TDOWNC() __z88dk_fastcall {
MSXUSR(0x010b);
MSXUSR_RTN_C();
}
void SCALXY() __z88dk_fastcall {
MSXUSR(0x010e);
}
*/
void MAPXY() __z88dk_fastcall {
MSXUSR(0x0111);
}
uint16_t FETCHC_ADDR() __z88dk_fastcall {
MSXUSR(0x0114);
}
/*
void STOREC(uint16_t addr, uint8_t mask) {
REGS.w.hl = addr;
REGS.b.a = mask;
MSXUSR_LOAD_REGS(0x0117);
}
void SETATR(uint8_t attr) __z88dk_fastcall {
attr;
MSXUSR_LOAD_A();
MSXUSR(0x011a);
}
uint8_t READC() __z88dk_fastcall {
MSXUSR(0x011d);
MSXUSR_RTN_A();
}
void SETC() __z88dk_fastcall {
MSXUSR(0x0120);
}
void NSETCX(uint16_t fillcount) __z88dk_fastcall {
fillcount;
MSXUSR(0x0123);
}
*/
uint8_t RDVDP() __z88dk_fastcall {
MSXUSR(0x013e);
MSXUSR_RTN_A();
}
uint8_t SNSMAT(uint8_t row) __z88dk_fastcall {
row;
MSXUSR_LOAD_A();
MSXUSR(0x0141);
MSXUSR_RTN_A();
}
void KILBUF() __z88dk_fastcall {
MSXUSR(0x0156);
}
// for stdio.h
int putchar(int ch) {
CHPUT(ch);
if (ch == '\n') CHPUT('\r'); // convert CR to CRLF
return ch;
}
char getchar() {
char ch = CHGET();
putchar(ch); // echo
if (ch == '\r') ch = '\n';
return ch;
}