-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameoflife.asm
574 lines (517 loc) · 6.82 KB
/
gameoflife.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
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
ORG 40000
MAIN CALL CLS
CALL ATT
CALL SET1
CALL KLOOP
RET
KLOOP
LD A,0
LD A,0FBh ; check keyboard for ‘Break Key’
IN A,(0FEh) ; and read the port
RRA ; check the appropriate bit
JP NC, EXIT ; and exit if it was pressed
LD A,0FDh; check keyboard for movement or select keys
IN A,(0FEh)
RRA
RRA
RRA
JP NC,RIGHT
LD A,0FDh ; check keyboard for movement or select keys
IN A,(0FEh)
RRA
JP NC,LEFT
LD A,0FBh
IN A,(0FEh)
RRA
RRA
JP NC,UP
LD A,0FDh
IN A,(0FEh)
RRA
RRA
JP NC,DOWN
LD A,0FBh
IN A,(0FEh)
RRA
RRA
RRA
JP NC,SELECT
LD A,07Fh
IN A,(0FEh)
RRA
JP NC,STEP
LD A,0
LD A,0FBh
IN A,(0FEh)
RRA
RRA
RRA
RRA
JP NC, RESET
JP KLOOP
CLS
LD HL,4000h
LD (HL),0
LD D,H
LD E,1
LD BC,17FFh
LDIR
RET
ATT
LD HL,5800h
LD (HL),01111000b
LD D,H
LD E,1
LD BC,02FFh
LDIR
RET
SET1
LD HL,5800h
LD (HL),11111000b
RET
DELAYL LD BC,3500h ;Load large number into BC
TIMEL DEC BC
LD A,B
OR C
JP NZ,TIMEL ;Dec BC and check B and C for 0, loop till zero.
RET
DELAYS LD BC,2000h ;Load large number into BC
TIMES DEC BC
LD A,B
OR C
JP NZ,TIMES ;Dec BC and check B and C for 0, loop till zero.
RET
RIGHT LD A,L
CP 1Fh
JP Z,RCHKL
CP 3Fh
JP Z,RCHKL
CP 5Fh
JP Z,RCHKL
CP 7Fh
JP Z,RCHKL
CP 9Fh
JP Z,RCHKL
CP 0BFh
JP Z,RCHKL
CP 0DFh
JP Z,RCHKL
CP 0FFh
JP Z,RCHKL
LD A,(HL)
SUB 10000000b
LD (HL),A
INC HL
LD A,(HL)
ADD A,10000000b
LD (HL),A
RCHKL LD A,0FDh; check keyboard for movement or select keys
IN A,(0FEh)
RRA
RRA
RRA
JP NC,RCHKL
JP KLOOP
LEFT LD A,L
CP 00h
JP Z,LCHKL
CP 20h
JP Z,LCHKL
CP 40h
JP Z,LCHKL
CP 60h
JP Z,LCHKL
CP 80h
JP Z,LCHKL
CP 0A0h
JP Z,LCHKL
CP 0C0h
JP Z,LCHKL
CP 0E0h
JP Z,LCHKL
LD A,(HL)
SUB 10000000b
LD (HL),A
DEC HL
LD A,(HL)
ADD A,10000000b
LD (HL),A
LCHKL LD A,0FDh ; check keyboard for movement or select keys
IN A,(0FEh)
RRA
JP NC,LCHKL
JP KLOOP
UP LD DE,-20h
PUSH HL
ADD HL,DE
LD A,H
SUB 57h
POP HL
JP Z,UCHKL
LD A,(HL)
SUB 10000000b
LD (HL),A
LD DE,-20h
ADD HL,DE
LD A,(HL)
ADD A,10000000b
LD (HL),A
UCHKL LD A,0FBh
IN A,(0FEh)
RRA
RRA
JP NC,UCHKL
JP KLOOP
DOWN
PUSH HL
LD DE,20h
ADD HL,DE
LD A,H
SUB 5Bh
POP HL
JP Z,DCHKL
LD A,(HL)
SUB 10000000b
LD (HL),A
LD DE,20h
ADD HL,DE
LD A,(HL)
ADD A,10000000b
LD (HL),A
DCHKL LD A,0FDh
IN A,(0FEh)
RRA
RRA
JP NC,DCHKL
JP KLOOP
SELECT LD A,(HL)
SUB 11011000b
JP Z,DSELECT
LD (HL),11011000b
SCHKL LD A,0FBh
IN A,(0FEh)
RRA
RRA
RRA
JP NC,SCHKL
JP KLOOP
DSELECT LD (HL),11111000b
JP SCHKL
RESET
RSCHKL LD A,0
LD A,0FBh
IN A,(0FEh)
RRA
RRA
RRA
RRA
JP NC,RSCHKL
JP MAIN
STEP
PUSH HL
LD A,(HL)
SUB 10000000b
LD (HL),A
JP PHASE1
STEND POP HL
LD A,(HL)
ADD A,10000000b
LD (HL),A
;STCHKL LD A,07Fh
;IN A,(0FEh)
;RRA
;JP NC,STCHKL
JP KLOOP
PHASE1
LD HL,5800h
LD DE,0A800h
LD BC,300h
P1LOOP LD A,(HL)
SUB 01011000b
JP Z,SVON
JP SVOFF
SVDONE INC HL
INC DE
DEC BC
LD A,B
OR C
JP NZ,P1LOOP
JP PHASE2
SVON
PUSH HL
LD H,D
LD L,E
LD (HL),0001h
POP HL
JP SVDONE
SVOFF
PUSH HL
LD H,D
LD L,E
LD (HL),00ffh
POP HL
JP SVDONE
PHASE2 LD HL,0A800h
LD BC,300h
P2LOOP PUSH BC
LD C,0
CALL DCHECK
CALL NORTH
CALL NE
CALL EAST
CALL SE
CALL SOUTH
CALL SW
CALL WEST
CALL NW
LD DE,1000h
PUSH HL
ADD HL,DE
LD (HL),C
POP HL
INC HL
POP BC
DEC BC
LD A,B
OR C
JP NZ,P2LOOP
JP PHASE3
PHASE3 LD HL,0A800h
LD BC,300h
P3LOOP LD A,(HL)
SUB 01h
JP Z,LCELL
JP DCELL
P3END DEC BC
LD A,B
OR C
POP HL
JP Z,STEND
INC HL
JP P3LOOP
LCELL PUSH HL
LD DE,1000h
ADD HL,DE
LD A,(HL)
SUB 2
JP Z,P3END
SUB 1
JP Z,P3END
JP DEATH
DCELL PUSH HL
LD DE,1000h
ADD HL,DE
LD A,(HL)
SUB 3
JP Z,LIVE
JP P3END
LIVE LD DE,6000h
LD A,H
SUB D
LD H,A
LD A,L
SUB E
LD L,A
LD (HL),01011000b
JP P3END
DEATH LD DE,6000h
LD A,H
SUB D
LD H,A
LD A,L
SUB E
LD L,A
LD (HL),01111000b
JP P3END
DCHECK ;Direction check for phase 2
;North check
PUSH HL
LD DE,-20h
ADD HL,DE
LD A,H
CP 0A7h
JP NZ,NSET
JP NRESET
DCNE POP HL
;South check
PUSH HL
LD DE,20h
ADD HL,DE
LD A,H
SUB 0ABh
JP NZ,SSET
JP SRESET
DCSE POP HL
;East check
LD A,L
CP 1Fh
JP Z,ELOOPND
CP 3Fh
JP Z,ELOOPND
CP 5Fh
JP Z,ELOOPND
CP 7Fh
JP Z,ELOOPND
CP 9Fh
JP Z,ELOOPND
CP 0BFh
JP Z,ELOOPND
CP 0DFh
JP Z,ELOOPND
CP 0FFh
JP Z,ELOOPND
JP NZ,ESET
ELOOPND JP ERESET
DCEE
;West check
LD A,L
CP 00h
JP Z,WLOOPND
CP 20h
JP Z,WLOOPND
CP 40h
JP Z,WLOOPND
CP 60h
JP Z,WLOOPND
CP 80h
JP Z,WLOOPND
CP 0A0h
JP Z,WLOOPND
CP 0C0h
JP Z,WLOOPND
CP 0E0h
JP Z,WLOOPND
JP NZ,WSET
WLOOPND JP WRESET
DCWE RET
NSET SET 7,B ;set North 'flag'
SET 6,B ;set North East 'flag'
SET 0,B ;set North West 'flag'
JP DCNE ;return to DCHECK
NRESET RES 7,B ;reset North 'flag'
JP DCNE ;return to DCHECK
SSET SET 3,B ;set South 'flag'
SET 4,B ;set South East 'flag'
SET 2,B ;set South West 'flag'
JP DCSE ;return to DCHECK
SRESET RES 3,B ;reset South 'flag'
JP DCSE ;return to DCHECK
ESET SET 5,B ;set East 'flag'
JP DCEE
ERESET RES 5,B ;reset East 'flag'
RES 6,B ;reset North East 'flag'
RES 4,B ;reset South East 'flag'
JP DCEE
WSET SET 1,B ;set West 'flag'
JP DCWE
WRESET RES 1,B ;reset West 'flag'
RES 0,B ;reset North West 'flag'
RES 2,B ;reset South West 'flag'
JP DCWE
NORTH PUSH HL
LD A,B
RLA
LD B,A
JP NC,NEND
LD DE,-20h
ADD HL,DE
LD A,(HL)
SUB 01h
JP NZ,NEND
INC C
NEND POP HL
RET
NE PUSH HL
LD A,B
RLA
LD B,A
JP NC,NEEND
INC HL
LD DE,-20h
ADD HL,DE
LD A,(HL)
SUB 01h
JP NZ,NEEND
INC C
NEEND POP HL
RET
EAST PUSH HL
LD A,B
RLA
LD B,A
JP NC,EEND
INC HL
LD A,(HL)
SUB 01h
JP NZ,EEND
INC C
EEND POP HL
RET
SE PUSH HL
LD A,B
RLA
LD B,A
JP NC,SEEND
INC HL
LD DE,20h
ADD HL,DE
LD A,(HL)
SUB 01h
JP NZ,SEEND
INC C
SEEND POP HL
RET
SOUTH PUSH HL
LD A,B
RLA
LD B,A
JP NC,SEND
LD DE,20h
ADD HL,DE
LD A,(HL)
SUB 01h
JP NZ,SEND
INC C
SEND POP HL
RET
SW PUSH HL
LD A,B
RLA
LD B,A
JP NC,SWEND
LD DE,20h
ADD HL,DE
DEC HL
LD A,(HL)
SUB 01h
JP NZ,SWEND
INC C
SWEND POP HL
RET
WEST PUSH HL
LD A,B
RLA
LD B,A
JP NC,WEND
DEC HL
LD A,(HL)
SUB 01h
JP NZ,WEND
INC C
WEND POP HL
RET
NW PUSH HL
LD A,B
RLA
LD B,A
JP NC,NWEND
DEC HL
LD DE,-20h
ADD HL,DE
LD A,(HL)
SUB 01h
JP NZ,NWEND
INC C
NWEND POP HL
RET
EXIT RET