-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmididisp.s
302 lines (280 loc) · 6.97 KB
/
mididisp.s
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
DISPLAY_ENABLED equ 1
PANNED_NOTE_NEW equ 1
org 00f0h
defw 0500h, prgEnd - main, 0, 0, 0, 0, 0, 0
macro exos n
rst 30h
defb n
endm
main:
di
ld sp, 0100h
ld a, 0ffh
out (0b2h), a
ld hl, resetRoutine
ld (0bff8h), hl
ld hl, (0bffdh)
ld a, (0bfffh)
ld (page1Segment), hl
ld (page3Segment), a
out (0b3h), a
ld a, l
out (0b1h), a
ld a, h
out (0b2h), a
ei
ld bc, 011ah ; ST_FLAG
ld d, 0
exos 16
ld bc, 011bh ; BORD_VID
ld d, 0
exos 16
halt
halt
call allocateMemory
call displayInit
.l1: call restoreLPT
call restoreIRQHandler
call load_midi_file
call z, load_envelopes
di
ld hl, msg_creatingTables
call status_message
call daveInit
ld hl, msg_clear
call status_message
call setPlayerLPT
call midi_reset
call setIRQHandler
.l2: ei
halt
ld a, 4
out (0b5h), a
in a, (0b5h)
cpl
and 8bh
jr z, .l2
di
bit 1, a ; F8
jp nz, resetRoutine
or a
jp m, .l1 ; F1
and 08h ; F6
jr nz, .l3
call midi_stop ; F4
jr .l2
.l3: call midi_file_rewind
jr .l2
allocateMemory:
ld hl, fileNameBuffer
xor a
.l1: ld (hl), a
inc hl
exos 24
jp nz, resetRoutine
ld a, c
cp 0fch
jr c, .l1
ld (videoSegment), a
.l2: dec hl
ld a, (hl)
or a
ret z
ld c, a
exos 25
jr .l2
load_midi_file:
ld a, (no_file_chooser)
or a
jr nz, .l3
ld de, exdosFDCommand
exos 26
jr nz, .l2
ld hl, fileNameBuffer
push hl
ld hl, 2045h ; "E "
push hl
ld hl, 4c49h ; "IL"
push hl
ld hl, 4607h ; 7, "F"
push hl
ld hl, 0
add hl, sp
ld e, l
ld d, h
exos 26
pop hl
pop hl
pop hl
pop hl
jr nz, .l2
ld de, fileNameBuffer
.l1: ld hl, file_buf
ld bc, FILE_BUF_SIZE
jp midi_file_load
.l2: ld a, 1
ld (no_file_chooser), a
.l3: ld de, defaultMIDIFileName
jr .l1
load_envelopes:
ld a, 1
ld de, envelopeFileName
exos 1
jr nz, .l1
inc a
ld de, midi_pgm_layer2
ld bc, 1024 + 8192
exos 6
xor 0e4h ; .EOF
jr nz, .l2
ld a, c
cp low (8192 - 5)
ld a, b
sbc a, high (8192 - 5)
jr nc, .l2
ld a, 1
exos 3
ret
.l1: ld hl, errMsg_envNotFound
jp error_exit
.l2: ld hl, errMsg_envInvalid
jp error_exit
daveInit:
call testCPUFrequency ; returns with B = 0
ld a, 25
cp l ; Carry = 1 if Z80 frequency > 5 MHz
ld a, 03h
rla
rla ; Z80 <= 5 MHz: 0Ch, > 5 MHz: 0Eh
out (0bfh), a
jp dave_init
; L = 1 kHz interrupts per video frame
testCPUFrequency:
di
ld a, 04h
out (0bfh), a
xor a
ld b, a
out (0a7h), a
ld c, b
call .l1
ld l, b
.l1: in a, (0b4h)
and 11h
or c
rlca
and 66h
ld c, a ; -ON--ON-
rlca ; ON--ON--
xor c ; OXN-OXN-
bit 2, a
jr z, .l2
inc l ; 1 kHz interrupt
.l2: cp 0c0h
jr c, .l1 ; not 50 Hz interrupt ?
ret
setIRQHandler:
di
ld a, 0c3h ; = JP nn
ld hl, irqRoutine
ld (0038h), a
ld (0039h), hl
ld a, 30h ; video interrupt only
out (0b4h), a
ei
ret
restoreIRQHandler:
di
ld a, 0f5h ; = PUSH AF
ld hl, 1837h ; = SCF, JR +d
ld (0038h), a
ld (0039h), hl
ld a, 3ch ; video + 1 Hz interrupt
out (0b4h), a
ei
ret
irqRoutine:
push af
ld a, 30h
out (0b4h), a
push bc
push de
push hl
in a, (0b3h)
push af
ld a, (page3Segment)
out (0b3h), a
push ix
call dave_play
call displayUpdate
pop ix
pop af
out (0b3h), a
pop hl
pop de
pop bc
pop af
ei
ret
vsync_wait:
.l1: in a, (0b4h)
and 10h
jr z, .l1
.l2: in a, (0b4h)
and 10h
jr nz, .l2
ret
; HL = message address
status_message:
in a, (0b3h)
push af
ld a, 0ffh
out (0b3h), a
ld de, (0fff6h)
ld a, d
or high 0c000h
ld d, a
ld bc, 40
xor a
.l1: cp (hl)
jr z, .l2
ldi
jp pe, .l1
jr .l3
.l2: ld a, 20h
ld (de), a
inc de
dec bc
ld a, c
or b
jr nz, .l2
.l3: pop af
out (0b3h), a
ret
; HL = error message address
error_exit:
di
call status_message
ld b, 100
.l1: call vsync_wait
djnz .l1
resetRoutine:
di
ld sp, 3800h
ld a, 0ffh
out (0b2h), a
ld hl, resetRoutine
ld (0bff8h), hl
call restoreIRQHandler
ld c, 40h
exos 0
ld a, 01h
out (0b3h), a
ld a, 6
jp 0c00dh
include "daveplay.s"
include "midi_in.s"
include "display.s"
include "decompress_m2_new.s"
include "globals.s"
prgEnd: