-
Notifications
You must be signed in to change notification settings - Fork 0
/
horace.asm
303 lines (278 loc) · 5.32 KB
/
horace.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
ENTRY_POINT EQU 0x8000
;Spectrum screen size 256 pixels wide x 192 scan lines
; 32 x 24 Characters
; keyboard ports:
; todo fill in the rest.
; f7fe 12345
; fbfe qwert
; fdfe asdfg
; fefe shift/z/x/c/v
org ENTRY_POINT
call 0xdaf
xor a
call 0x229b
;a beginner's, unoptimised sprite routine
main:
halt ;the HALT is important to avoid sprite flicker, and it slows down the program
call deletesprites ;we need to delete the old position of the sprite
call checkkeys
call drawsprites ;get correct preshifted graphic, and draw it on the screen
call getcell
call colourcells
jr main ;loop!
deletesprites: ;we need to delete the old sprite before we draw the new one. The sprite is 2 bytes wide & 16 pixels high
;hatman
ld bc,(hatmanx) ;make C=hatmanx and B=hatmany, remember LD BC,(hatmanx) gets both hatmanx and hatmany in one LD as they are adjacent in memory
call yx2pix ;point DE at the corresponding screen address
ld b,16 ;sprite is 16 lines high
delp_hatman:
xor a ;empty A to delete
ld (de),a ;repeat a total of 2 times
inc e ;next column along
ld (de),a
dec e ;move DE back to start of line
call nextlinedown ;move DE down one line
djnz delp_hatman ;repeat 16 times
;biker1
ld bc,(bikerx)
call yx2pix
ld b,16
delp_biker:
xor a
ld (de),a
inc e
ld (de),a
dec e
call nextlinedown
djnz delp_biker
ret
checkkeys:
ld bc,0xfdfe
in a, (c) ; reads ports, affects flags, but doesnt store value to a register
rra ; outermost bit = key0 = A
push af
call nc, moveleft
pop af
rra ; outermost bit = key1 = S
push af
call nc, movedown
pop af
rra ; outermost bit = key2 = D
push af
call nc, moveright
pop af
ld bc,0xfbfe
in a, (c)
rra ; key Q
push af
;call nc, whateverQcando
pop af
rra ; key W
push af
call nc, moveup
pop af
ret
moveup:
ld a, (hatmany)
cp 0
ret z
sub hatmanspeed
ld (hatmany),a
ret
movedown:
ld a, (hatmany)
cp 176
ret z
add a, hatmanspeed
ld (hatmany),a
ret
moveleft:
ld a, (hatmanx)
cp 0
ret z
sub hatmanspeed
ld (hatmanx),a
ret
moveright:
ld a, (hatmanx)
cp 240
ret z
add a, hatmanspeed
ld (hatmanx),a
ret
drawsprites:
;hatman
ld bc,(hatmanx) ;make C=hatmanx and B=hatmany, remember LD BC,(hatmanx) gets both hatmanx and hatmany in one LD as they are adjacent in memory
call yx2pix ;point DE at corresponding screen position
call getsprite_hatman ;point HL at the correct graphic
ld b,16 ;sprite is 16 lines high
dslp_hatman:
ld a,(hl) ;take a byte of graphic
ld (de),a ;and put it on the screen
inc hl ;next byte of graphic
inc e ;next column on screen
ld a,(hl) ;repeat for 2 bytes across
ld (de),a
inc hl
dec e ;move DE back to left hand side of sprite
call nextlinedown
djnz dslp_hatman ;repeat for all 16 lines
;biker1
ld bc,(bikerx)
call yx2pix
call getsprite_biker
ld b,16
dslp_biker:
ld a,(hl)
ld (de),a
inc hl
inc e
ld a,(hl)
ld (de),a
inc hl
dec e
call nextlinedown
djnz dslp_biker
ret
nextlinedown: ;don't worry about how this works yet!
inc d ;just arrive with DE in the display file
ld a,d ;and it gets moved down one line
and 7
ret nz
ld a,e
add a,32
ld e,a
ret c
ld a,d
sub 8
ld d,a
ret
yx2pix: ;don't worry about how this works yet! just arrive with arrive with B=y 0-192, C=x 0-255
ld a,b ;return with DE at corresponding place on the screen
rra
rra
rra
and 24
or 64
ld d,a
ld a,b
and 7
or d
ld d,a
ld a,b
rla
rla
and 224
ld e,a
ld a,c
rra
rra
rra
and 31
or e
ld e,a
ret
getsprite_hatman:
ld a, (hatmananimtimer)
dec a
ld (hatmananimtimer), a
cp 0
call z, animframeends
ret z
ld hl,hatman
ld a, (hatmancurrentframe)
cp 0
ret z
ld hl, hatman+32
ret
getsprite_biker:
ld hl, biker
animframeends:
ld a, (hatmananimdelay)
ld (hatmananimtimer), a
call changeanimframe
ret
; so far this only supports a two frame animation
changeanimframe:
ld a, (hatmancurrentframe)
xor %00000001
ld (hatmancurrentframe), a
ret
;c Divided by d:
;Inputs:
; C is the numerator
; D is the denominator
;Outputs:
; A is the remainder
; B is 0
; C is the result of C/D
; D,E,H,L are not changed
;
getcell:
ld a, (hatmanx)
ld c, a
ld a, 8
ld d, a
ld b,8
xor a
sla c
rla
cp d
jr c,$+4
inc c
sub d
djnz $-8
ld a,c
ld (hatmancellx), a
ld a, (hatmany)
ld c, a
ld a, 8
ld d, a
ld b,8
xor a
sla c
rla
cp d
jr c,$+4
inc c
sub d
djnz $-8
ld a,c
ld (hatmancelly), a
ret
;attribute memory begins at 0x5800
;0x5800 + ((y*32) + x)
colourcells:
ld de, 0x5800
ld a, (hatmancelly)
ld hl, 0
ld l, a
add hl,hl ;x2
add hl,hl ;x4
add hl,hl ;x8
add hl,hl ;x16
add hl,hl ;x32
ld b,0
ld a, (hatmancellx)
ld c,a
add hl, de
add hl, bc ; hl now contains exact memory address for colour attributes at players xy
ld a, (hatmanattributes)
ld (hl), a
ld a, (hatmanattributes+1)
ld b, 0
ld c, 1
add hl,bc
ld (hl), a
ld a, (hatmanattributes+2)
ld c, 31
add hl,bc
ld (hl),a
ld a, (hatmanattributes+3)
ld c, 1
add hl,bc
ld (hl),a
ret
include "hatman.asm"
include "biker.asm"
end ENTRY_POINT