-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIOLib.asm
310 lines (309 loc) · 6.3 KB
/
IOLib.asm
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
;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 4.0.0 #11528 (MINGW64)
;--------------------------------------------------------
.module IOLib
.optsdcc -mz80
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
.globl _IOSize
.globl _IOPointer
.globl _IOStart
.globl _IOStatus
.globl _IOPlay
.globl _IOStop
.globl _IOFrame
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
_G2G_IOPinPort = 0x0001
_G2G_NMIPort = 0x0002
_G2G_TxPort = 0x0003
_G2G_RxPort = 0x0004
_G2G_StatusPort = 0x0005
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
.area _DATA
_IOStatus::
.ds 1
_IOStart::
.ds 2
_IOPointer::
.ds 2
_IOSize::
.ds 2
_IOFrame_count_65536_12:
.ds 2
_IOFrame_frame_65536_12:
.ds 2
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
.area _INITIALIZED
;--------------------------------------------------------
; absolute external ram data
;--------------------------------------------------------
.area _DABS (ABS)
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
.area _HOME
.area _GSINIT
.area _GSFINAL
.area _GSINIT
;IOLib.c:47: static int count = 0;
ld hl, #0x0000
ld (_IOFrame_count_65536_12), hl
;IOLib.c:48: static int frame = 0;
ld l, #0x00
ld (_IOFrame_frame_65536_12), hl
;--------------------------------------------------------
; Home
;--------------------------------------------------------
.area _HOME
.area _HOME
;--------------------------------------------------------
; code
;--------------------------------------------------------
.area _CODE
;IOLib.c:11: void IOPlay(unsigned char *IOData, unsigned int size)
; ---------------------------------
; Function IOPlay
; ---------------------------------
_IOPlay::
;IOLib.c:13: G2G_NMIPort = 0x80;
ld a, #0x80
out (_G2G_NMIPort), a
;IOLib.c:14: G2G_IOPinPort = 0x00;
ld a, #0x00
out (_G2G_IOPinPort), a
;IOLib.c:15: IOStart = IOData;
pop de
pop bc
push bc
push de
ld (_IOStart), bc
;IOLib.c:16: IOPointer = IOData;
ld (_IOPointer), bc
;IOLib.c:17: IOSize = size;
ld iy, #4
add iy, sp
ld a, 0 (iy)
ld (_IOSize+0), a
ld a, 1 (iy)
ld (_IOSize+1), a
;IOLib.c:18: IOStatus=IO_PLAYING;
ld hl,#_IOStatus + 0
ld (hl), #0x01
;IOLib.c:19: }
ret
;IOLib.c:21: void IOStop(void)
; ---------------------------------
; Function IOStop
; ---------------------------------
_IOStop::
;IOLib.c:23: G2G_NMIPort = 0x80;
ld a, #0x80
out (_G2G_NMIPort), a
;IOLib.c:24: G2G_IOPinPort = 0x00;
ld a, #0x00
out (_G2G_IOPinPort), a
;IOLib.c:27: for(int i=7;i>=0;i--)
ld de, #0x0007
00103$:
bit 7, d
jr NZ,00101$
;IOLib.c:30: G2G_IOPinPort = byte;
ld a, #0x00
out (_G2G_IOPinPort), a
;IOLib.c:32: G2G_IOPinPort = byte;
ld a, #0x01
out (_G2G_IOPinPort), a
;IOLib.c:33: byte &= 0xFE;
ld bc, #0x0000
;IOLib.c:34: G2G_IOPinPort = byte;
ld a, #0x00
out (_G2G_IOPinPort), a
;IOLib.c:27: for(int i=7;i>=0;i--)
dec de
jr 00103$
00101$:
;IOLib.c:36: byte |= 1 << 1;
set 1, c
;IOLib.c:37: G2G_IOPinPort = byte;
ld a, c
out (_G2G_IOPinPort), a
;IOLib.c:39: G2G_IOPinPort = byte;
ld a, #0x00
out (_G2G_IOPinPort), a
;IOLib.c:41: IOStatus = IO_STOPPED;
ld hl,#_IOStatus + 0
ld (hl), #0x00
;IOLib.c:42: }
ret
;IOLib.c:45: void IOFrame(void)
; ---------------------------------
; Function IOFrame
; ---------------------------------
_IOFrame::
push ix
ld ix,#0
add ix,sp
push af
push af
;IOLib.c:50: if(IOStatus == IO_PLAYING)
ld a,(#_IOStatus + 0)
dec a
jp NZ,00114$
;IOLib.c:80: frame++;
ld bc, (_IOFrame_frame_65536_12)
inc bc
;IOLib.c:52: if(frame == 0)
ld iy, #_IOFrame_frame_65536_12
ld a, 1 (iy)
or a, 0 (iy)
jp NZ, 00107$
;IOLib.c:55: for(int i=7;i>=0;i--)
ld -2 (ix), #0x07
xor a, a
ld -1 (ix), a
00112$:
bit 7, -1 (ix)
jr NZ,00101$
;IOLib.c:58: byte |= (((*IOPointer)>>i) & 1)<<2;
ld hl, (_IOPointer)
ld e, (hl)
ld a, -2 (ix)
inc a
jr 00150$
00149$:
srl e
00150$:
dec a
jr NZ, 00149$
ld a, e
and a, #0x01
ld l, a
ld h, #0x00
add hl, hl
add hl, hl
ex de,hl
;IOLib.c:59: IOPointer++;
ld hl, (_IOPointer)
inc hl
ld (_IOPointer), hl
;IOLib.c:60: byte |= (((*IOPointer)>>i) & 1)<<3;
ld hl, (_IOPointer)
ld l, (hl)
ld a, -2 (ix)
inc a
jr 00152$
00151$:
srl l
00152$:
dec a
jr NZ, 00151$
ld a, l
and a, #0x01
ld l, a
ld h, #0x00
add hl, hl
add hl, hl
add hl, hl
ld a, e
or a, l
ld e, a
ld a, d
or a, h
;IOLib.c:61: IOPointer--;
ld hl, (_IOPointer)
dec hl
ld (_IOPointer), hl
;IOLib.c:62: G2G_IOPinPort = byte;
ld a, e
out (_G2G_IOPinPort), a
;IOLib.c:63: byte |= 1;
set 0, e
;IOLib.c:64: G2G_IOPinPort = byte;
ld a, e
out (_G2G_IOPinPort), a
;IOLib.c:65: byte &= 0xFE;
ld a, e
and a, #0xfe
ld -4 (ix), a
ld -3 (ix), #0x00
;IOLib.c:66: G2G_IOPinPort = byte;
ld a, -4 (ix)
out (_G2G_IOPinPort), a
;IOLib.c:55: for(int i=7;i>=0;i--)
ld l, -2 (ix)
ld h, -1 (ix)
dec hl
ld -2 (ix), l
ld -1 (ix), h
jr 00112$
00101$:
;IOLib.c:68: byte |= 1 << 1;
ld e, -4 (ix)
set 1, e
;IOLib.c:69: G2G_IOPinPort = byte;
ld a, e
out (_G2G_IOPinPort), a
;IOLib.c:71: G2G_IOPinPort = byte;
ld a, #0x00
out (_G2G_IOPinPort), a
;IOLib.c:73: IOPointer+=2;
ld hl, (_IOPointer)
inc hl
inc hl
ld (_IOPointer), hl
;IOLib.c:74: count+=2;
ld hl, (_IOFrame_count_65536_12)
inc hl
inc hl
ld (_IOFrame_count_65536_12), hl
;IOLib.c:75: if(count >= IOSize)
ld de, (_IOFrame_count_65536_12)
ld hl, #_IOSize
ld a, e
sub a, (hl)
ld a, d
inc hl
sbc a, (hl)
jr C,00103$
;IOLib.c:77: IOStatus = IO_STOPPED;
ld hl,#_IOStatus + 0
ld (hl), #0x00
;IOLib.c:78: count = 0;
ld hl, #0x0000
ld (_IOFrame_count_65536_12), hl
00103$:
;IOLib.c:80: frame++;
ld (_IOFrame_frame_65536_12), bc
jr 00114$
00107$:
;IOLib.c:84: frame++;
ld (_IOFrame_frame_65536_12), bc
;IOLib.c:85: if(frame >= 3)
ld iy, #_IOFrame_frame_65536_12
ld a, 0 (iy)
sub a, #0x03
ld a, 1 (iy)
rla
ccf
rra
sbc a, #0x80
jr C,00114$
;IOLib.c:86: frame = 0;
ld hl, #0x0000
ld (_IOFrame_frame_65536_12), hl
00114$:
;IOLib.c:89: }
ld sp, ix
pop ix
ret
.area _CODE
.area _INITIALIZER
.area _CABS (ABS)