-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.asm
More file actions
454 lines (374 loc) · 7.69 KB
/
source.asm
File metadata and controls
454 lines (374 loc) · 7.69 KB
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
ORG 40000
INITALCLEAR LD A,0 ; colour 2 is RED
OUT (0FEh),A ; set border to that colou
; Code to clear the screen. Taken from Lab 3.
LD A,231
;Colour bit. We want solid black for this.
LD HL,4000h
;We're drawing to the display file, which
;starts at address 4000h.
LD BC,1800h
;Select every pixel to clear.
LD (HL),0
LD D, H
LD E, 1
LDIR ;Clear the entire screen.
DRAWBLACKLINE ;Draws a black square on the screen.
LD HL,5800h
LD (HL), A
;Dump colour bit to display file
JP HOLDINGPATTERN
;Go back to the loop.
STEPUP CALL EDGETOP
CALL COLORCHECK
;Check if at an edge, and check the current colour
LD A,L
;Can only call SBC on register A, so put L into it.
SBC A,32
;We must go back 32 blocks to get to the point directly above.
CALL C,DECH
;Decrement H if there's a carry.
LD L,A
;Load our recalculated L.
LD (HL),231
;Make the new block black
JP WAIT
STEPDOWN CALL EDGEBOTTOM
CALL COLORCHECK
;Check if at an edge, and check the current colour
LD A,L
;Can only call SBC on register A, so put L into it.
ADD A,32
;We must go forward 32 blocks to get to the point directly below.
CALL C,INCH
;Increment H if there's a carry.
LD L,A
;Load our recalculated L.
LD (HL),231
;Make the new block black
JP WAIT
STEPRIGHT CALL EDGERIGHT
CALL COLORCHECK
;Check if at an edge, and check the current colour
INC HL
;Move to the next block
LD (HL),231
;Make the new block black
JP WAIT
STEPLEFT CALL EDGELEFT
;Try to check if the block is running away
CALL COLORCHECK
;Check if at an edge, and check the current colour
DEC HL
;Move to the next block
LD (HL),231
;Make the new block black
JP WAIT
WAIT HALT ;This
HALT ;Makes
HALT ;A
HALT ;Nice
HALT ;Delay
JP HOLDINGPATTERN
HOLDINGPATTERN OR C
;Not entirely sure why this is here. We saw it in a lab,
;and it breaks without it. So hey.
;--- Start W key spotting ---
LD A,0FBh
;Read Q - T.
IN A,(0FEh)
;Read the keyboard input port.
RRA ;Cycle to the W key.
RRA
JP NC,STEPUP ;If W is pressed, move up.
;--- End W key spotting ---
;--- Start A key spotting ---
LD A,0FDh
;Read A - G
IN A,(0FEh)
;Read the keyboard input port.
RRA ;Cycle to the A key
JP NC,STEPLEFT ; If A is pressed, move left.
;--- End A key spotting ---
;--- Start D key spotting ---
LD A,0FDh
;Read A - G
IN A,(0FEh)
;Read the keyboard input port.
RRA ;Cycle to the D key.
RRA
RRA
JP NC,STEPRIGHT ;If D is pressed, move right.
;--- End D key spotting ---
;--- Start S key spotting ---
LD A,0FDh
;Read A - G
IN A,(0FEh)
;Read the keyboard input port.
RRA ;Cycle to the S key.
RRA
JP NC,STEPDOWN ;If S is pressed, move down.
;--- End S key spotting ---
;--- Start E key spotting ---
LD A,0FBh
;Read Q - T.
IN A,(0FEh)
;Read the keyboard input port.
RRA ;Cycle to the E key.
RRA
RRA
JP NC,DUMPBLOCK ;If E is pressed, dump a block.
;--- End E key spotting ---
;--- Start Space key spotting ---
LD A,07Fh
;Read break (SPACE).
IN A,(0FEh)
;Read the keyboard input port.
RRA ;Cycle to the Space key.
CALL NC, STARTLOOP
;--- End Space key spotting --
;--- Start Q key spotting ---
LD A,0FBh
;Read Q - T.
IN A,(0FEh)
;Read the keyboard input port.
RRA ;Cycle to the Q key.
CALL NC,CLSINIT ;If Q is pressed, move up.
;--- End Q key spotting ---
JP HOLDINGPATTERN ;Nothing's been pressed, so loop back.
CLSINIT LD HL,5800h
CALL CLS
LD HL,5800h
LD (HL),231
RET
CLS LD (HL),63
;Tests to ensure loops round the entire screen.
INC L
LD A,0
CP L
CALL Z,INCH
LD A,5Bh
CP H
RET Z
;End loop tests.
JP CLS ;Keep looping.
STARTLOOP CALL NC, CLEARBLOCK
LD HL, 5800h
CALL GENLOOP
LD HL, 5800h
CALL REPLACELOOP
LD HL, 5800h
RET
DUMPBLOCK LD (HL),112 ;Make the current block black
JP HOLDINGPATTERN ;Go back to checking for keys.
CLEARBLOCK LD (HL),63 ;Clears the block.
RET
YELLOWBLOCK LD (HL),112
RET
INCH INC H ;Increment H.
RET
DECH DEC H ;Decrement H.
RET
EDGELEFT LD A,0 ;Check we're at the start
CP L ;of a chunk.
RET NZ ;And jump out if we're not.
LD A,88 ;Check we're in the first
CP H ;chunk.
RET NZ ;And jump out if we're not.
JP WAIT
;Co-ord is 1,1 - Block movement.
EDGERIGHT LD A,0FFh ;Check we're in the end
CP L ;of a chunk.
RET NZ ;And jump out if we're not.
LD A,5Ah ;Check we're in the last
CP H ;chunk.
RET NZ ;And jump out if we're not.
JP WAIT
;Co-ord is 31,24 - Block movement.
EDGETOP LD A,58h ;Check we're in the top
CP H ;chunk.
RET NZ ;And jump out if we're not.
LD A,31 ;Check we're in the top
CP L ;row.
RET C ;And jump out if we're not.
JP WAIT
;In very top row - Block movement.
EDGEBOTTOM LD A,5Ah ;Check we're in the bottom
CP H ;chunk.
RET NZ ;And jump out if we're not.
LD A,223 ;Check we're in the bottom
CP L ;row
RET NC ;And jump out if we're not.
JP WAIT
;In very bottom row - Block movement.
COLORCHECK LD A,(HL)
CP 63
CALL Z,CLEARBLOCK
CP 231
CALL Z,CLEARBLOCK
CP 112
CALL Z,MARKER
RET
MARKER LD D,1
RET
GENLOOP LD E,0
CALL CHECKSUITE
;LD E,3 ;Debug code
CALL GOD
;Tests to ensure loops round the entire screen.
INC L
LD A,0
CP L
CALL Z,INCH
LD A,5Bh
CP H
RET Z
;End loop tests.
JP GENLOOP ;Keep looping.
REPLACELOOP CALL BLOCKMOVE
;Tests to ensure loops round the entire screen.
INC L
LD A,0
CP L
CALL Z,INCH
LD A,5Bh
CP H
RET Z
;End loop tests.
JP REPLACELOOP ;Keep looping.
GOD LD A,E ;Carries out the relevant actions.
CP 0
CALL Z,KILLBLOCK
;CALL Z,KEEPBLOCK
LD A,E
CP 1
CALL Z,KILLBLOCK
;CALL Z,KEEPBLOCK
LD A,E
CP 2
;CALL Z,KILLBLOCK
CALL Z,KEEPBLOCK
LD A,E
CP 3
;CALL Z,KILLBLOCK
;CALL Z,KEEPBLOCK
CALL Z,CREATEBLOCK
LD A,E
CP 4
CALL NC,KILLBLOCK
;CALL NC,KEEPBLOCK
;CALL NC,CREATEBLOCK
LD E,0
RET
KILLBLOCK PUSH HL ;Store where we are in display.
CALL MOVEMEMORY ;Move to our temporary RAM area.
LD (HL),56 ;Blank it.
POP HL ;Move back.
RET
CREATEBLOCK PUSH HL
CALL MOVEMEMORY
LD (HL),112 ;Yellow it.
POP HL
RET
KEEPBLOCK PUSH HL
LD D,(HL)
CALL MOVEMEMORY
LD (HL),D ;Maintain the state.
POP HL
RET
MOVEMEMORY INC L
LD A,H
ADD A,40 ;Move up 40*255 memory locations.
LD H,A
RET
BLOCKMOVE PUSH HL
CALL MOVEMEMORY ;Find the relevant location in RAM.
LD D,(HL) ;Drop the colour block to temporary storage.
POP HL ;Return to the display.
LD (HL),D ;Drop the colour.
RET
CHECKSUITE ;Check straight up.
PUSH HL
LD A,L
SBC A,32
CALL C,DECH
LD L,A
LD A,(HL)
CP 112 ;Is it yellow?
CALL Z,INCE
POP HL
;Done checking up.
;Check down.
PUSH HL
LD A,L
ADD A,32
CALL C,INCH
LD L,A
LD A,(HL)
CP 112 ;Is it yellow?
CALL Z,INCE
POP HL
;Done checking down.
;Check left
PUSH HL
DEC HL
LD A,(HL)
CP 112 ;Is it yellow?
CALL Z,INCE
POP HL
;Done checking left.
;Check right.
PUSH HL
INC HL
LD A,(HL)
CP 112 ;Is it yellow?
CALL Z,INCE
POP HL
;Done checking right.
;Check up and left.
PUSH HL
LD A,L
SBC A,32
CALL C,DECH
LD L,A
LD A,(HL)
CP 112 ;Is it yellow?
CALL Z,INCE
POP HL
;Done checking up left.
;Check up and right..
PUSH HL
LD A,L
SBC A,30
CALL C,DECH
LD L,A
LD A,(HL)
CP 112 ;Is it yellow?
CALL Z,INCE
POP HL
;Done checking up right.
;Check down and left.
PUSH HL
LD A,L
ADD A,31
CALL C,INCH
LD L,A
LD A,(HL)
CP 112 ;Is it yellow?
CALL Z,INCE
POP HL
;Done checking down left.
;Check down and right.
PUSH HL
LD A,L
ADD A,33
CALL C,INCH
LD L,A
LD A,(HL)
CP 112 ;Is it yellow?
CALL Z,INCE
POP HL
;Done checking down right.
RET
INCE INC E
RET