-
Notifications
You must be signed in to change notification settings - Fork 0
/
desolcod0.asm
317 lines (289 loc) · 4.59 KB
/
desolcod0.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
311
312
313
314
315
316
317
ColorNone .equ 00000000b
ColorC000 .equ 11111111b ; Color for data on C000-DFFF
ColorE000 .equ 11111110b ; Color for data on E000-FFFF - game screen
ColorBoth .equ 00000000b ; Color for '1' bit in both spaces
; Palette colors
Col0000 .equ ColorNone ;0
Col0001 .equ ColorE000 ;1
Col0010 .equ ColorC000 ;2
Col0011 .equ ColorBoth ;3
Col0100 .equ ColorNone ;4
Col0101 .equ ColorE000 ;5
Col0110 .equ ColorC000 ;6
Col0111 .equ ColorBoth ;7
Col1000 .equ ColorNone ;8
Col1001 .equ ColorE000 ;9
Col1010 .equ ColorC000 ;10
Col1011 .equ ColorBoth ;11
Col1100 .equ ColorNone ;12
Col1101 .equ ColorE000 ;13
Col1110 .equ ColorC000 ;14
Col1111 .equ ColorBoth ;15
;----------------------------------------------------------------------------
Start .equ 280h
.EXPORT KeyLineEx, KeyLine0, KeyLine1, KeyLine5, KeyLine6, KeyLine7
.EXPORT BorderColor
.EXPORT CpHLDE, SoundLookShoot
;----------------------------------------------------------------------------
.org 100h
di
xra a
out 10h
lxi sp,100h
lxi h,0C3F3h
shld 0
mov a,h
lxi h,Restart
shld 2
sta 38h
lxi h,KEYINT
shld 38h+1
; Move encoded block from Start to C000h
lxi d,Start ; source addr
lxi b,0C000h ; destination addr
Init_1:
ldax d
inx d
stax b
inr c
jnz Init_1
inr b
jnz Init_1
; Decompress the encoded block from C000h to Start
lxi d,0C000h
lxi b,Start
call dzx0
; Clear memory from C000h to FFFFh
lxi b,0C000h ; destination addr
Init_2:
stax b
inr c
jnz Init_2
inr b
jnz Init_2
ei
hlt
; Programming the Palette
lxi d, 100Fh
lxi h, Palette+15
PaletLoop:
mov a, e
out 2
mov a, m
out 0Ch
out 0Ch
out 0Ch
out 0Ch
out 0Ch
dcx h
out 0Ch
dcr e
out 0Ch
dcr d
out 0Ch
jnz PaletLoop
Restart:
lxi sp,100h
mvi a, 88h
out 4 ; initialize R-Sound 2
ei
jp Start
KEYINT:
push psw
mvi a, 8Ah
out 0
; Keyboard scan
in 1
ori 00011111b
sta KeyLineEx
mvi a, 0FEh
out 3
in 2
sta KeyLine0
mvi a, 0FDh
out 3
in 2
sta KeyLine1
mvi a, 0DFh
out 3
in 2
sta KeyLine5
mvi a, 0BFh
out 3
in 2
sta KeyLine6
mvi a, 07Fh
out 3
in 2
sta KeyLine7
; Scrolling, screen mode, border
mvi a, 88h
out 0
mvi a, 2
out 1
mvi a, 23
out 3 ; scrolling
lda BorderColor
ani 0Fh
out 2 ; screen mode and border
;
pop psw
ei
ret
KeyLineEx: .db 11111111b
KeyLine0: .db 11111111b
KeyLine1: .db 11111111b
KeyLine5: .db 11111111b
KeyLine6: .db 11111111b
KeyLine7: .db 11111111b
BorderColor: .db 0 ; border color number 0..15
Palette:
.db Col0000,Col0001,Col0010,Col0011
.db Col0100,Col0101,Col0110,Col0111
.db Col1000,Col1001,Col1010,Col1011
.db Col1100,Col1101,Col1110,Col1111
; Compare HL and DE
CpHLDE:
push h
mov a, l ;
sbb e ;
mov l, a ;
mov a, h ;
sbb d ;
mov h, a ;
jc $+7 ;
ora l ;
jmp $+5 ;
ora l ;
stc ;
pop h
ret
; Short sound on look/shoot action
SoundLookShoot:
MVI H, 00Ah ; Counter 1
XRA A
SoundLookShoot_1:
MVI L, 080h ; Counter 2
SoundLookShoot_2:
DCR L
JNZ SoundLookShoot_2 ; delay
XRI 001h ; inverse bit 0
OUT 000h
DCR H
JNZ SoundLookShoot_1 ; Loop 30 times
ret
; ZX0 decompressor code by Ivan Gorodetsky
; https://github.com/ivagorRetrocomp/DeZX/blob/main/ZX0/8080/OLD_V1/dzx0_CLASSIC.asm
; input: de=compressed data start
; bc=uncompressed destination start
#ifdef BACKWARD
#define NEXT_HL dcx h
#define NEXT_DE dcx d
#define NEXT_BC dcx b
#else
#define NEXT_HL inx h
#define NEXT_DE inx d
#define NEXT_BC inx b
#endif
dzx0:
#ifdef BACKWARD
lxi h,1
push h
dcr l
#else
lxi h,0FFFFh
push h
inx h
#endif
mvi a,080h
dzx0_literals:
call dzx0_elias
call dzx0_ldir
jc dzx0_new_offset
call dzx0_elias
dzx0_copy:
xchg
xthl
push h
dad b
xchg
call dzx0_ldir
xchg
pop h
xthl
xchg
jnc dzx0_literals
dzx0_new_offset:
call dzx0_elias
#ifdef BACKWARD
inx sp
inx sp
dcr h
rz
dcr l
push psw
mov a,l
#else
mov h,a
pop psw
xra a
sub l
rz
push h
#endif
rar\ mov h,a
ldax d
rar\ mov l,a
NEXT_DE
#ifdef BACKWARD
inx h
#endif
xthl
mov a,h
lxi h,1
#ifdef BACKWARD
cc dzx0_elias_backtrack
#else
cnc dzx0_elias_backtrack
#endif
inx h
jmp dzx0_copy
dzx0_elias:
inr l
dzx0_elias_loop:
add a
jnz dzx0_elias_skip
ldax d
NEXT_DE
ral
dzx0_elias_skip:
#ifdef BACKWARD
rnc
#else
rc
#endif
dzx0_elias_backtrack:
dad h
add a
jnc dzx0_elias_loop
jmp dzx0_elias
dzx0_ldir:
push psw
dzx0_ldir1:
ldax d
stax b
NEXT_DE
NEXT_BC
dcx h
mov a,h
ora l
jnz dzx0_ldir1
pop psw
add a
ret
;----------------------------------------------------------------------------
; Filler
.org Start-1
.db 0
.end
;----------------------------------------------------------------------------