-
Notifications
You must be signed in to change notification settings - Fork 0
/
list42_life.asm
1210 lines (1062 loc) · 41.9 KB
/
list42_life.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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; ************************************************************
;; list_life()
;; ************************************************************
;; prev = this;
;; ul = ur = ll = lr = 0;
;; *new = 0;
;; for(;;) {
;; /* did we write an X co-ordinate? */
;; if(*new < 0)
;; new+=2;
;; if(prev == this) {
;; /* start a new group of rows */
;; if(*this == 0) {
;; *new = 0;
;; return;
;; }
;; y = *this++;
;; } else {
;; /* move to next row and work out which ones to scan */
;; if(*prev == y)
;; prev++;
;; y-=2;
;; if(*this == y)
;; this++;
;; }
;; /* write new row co-ordinate */
;; *new = y + 1;
;; for(;;) {
;; /* skip to the leftmost cell */
;; x = *prev;
;; if(x > *this)
;; x = *this;
;; /* end of line? */
;; if(x >= 0)
;; break;
;; for(;;) {
;; ur = lr = 0;
;; /* add a column to the bitmap */
;; if(*prev == x) {
;; ur = *(prev + 1);
;; prev += 2;
;; }
;; if(*this == x) {
;; lr = *(this + 1);
;; this += 2;
;; }
;; if ((ul | ur | ll | lr) == 0) {
;; break;
;; }
;; /* UL table lookup, produces bits 7 and 6 */
;; page = ll >> 4;
;; index = ul;
;; outcome = table[(page << 8) | index] & 0xC0;
;; /* LL table lookup, produces bits 3 and 2 */
;; page = ul & 0x0F;
;; index = ll;
;; outcome |= table[(page << 8) | index] & 0x0C;
;; /* UR table lookup, produces bits 5 and 4 */
;; page = ((lr & 0xC0) | (ll & 0x30)) >> 4;
;; index = (ur & 0xCC) | (ul & 0x33);
;; outcome |= table[(page << 8) | index] & 0x30;
;; /* LR table lookup, produces bits 1 and 0 */
;; page = (ur & 0x0C) | (ul & 0x03);
;; index = (lr & 0xCC) | (ll & 0x33);
;; outcome |= table[(page << 8) | index] & 0x03;
;; if (outcome) {
;; if (*new < 0) {
;; // last coordinate was an X
;; new += 2;
;; } else {
;; // last coordinate was a Y
;; new += 1;
;; }
;; *new = x - 3;
;; *(new + 1) = outcome;
;; }
;; /* move right */
;; ul = ur;
;; ll = lr;
;; x += 4;
;; }
;; }
;; }
;;}
;;
;; Args are (this) and (new)
.list_life
{
;; keep Y as the constant 1 for efficient access of the high byte of a short
LDY #1
;; prev = this;
LDA this
STA prev
LDA this + 1
STA prev + 1
;; ul = ur = ll = lr = 0;
STZ ul
STZ ur
STZ ll
STZ lr
;; *new = 0;
LDA #0
STA (new)
STA (new), Y
;; for(;;) {
.level1
;; /* did we write an X co-ordinate? */
;; if(*new < 0)
;; new += 2;
LDA (new), Y
BPL skip_inc_new
M_INCREMENT_BY_3 new ; an X values is a two byte coordinate and a one-byte bitmap
.skip_inc_new
;; if(prev == this) {
;; /* start a new group of rows */
;; if(*this == 0) {
;; *new = 0;
;; return;
;; }
;; y = *this++;
;; } else {
;; /* move to next row and work out which ones to scan */
;; if(*prev == y)
;; prev++;
;; y-=2;
;; if(*this == y)
;; this++;
;; }
;; if(prev == this) {
LDA prev
CMP this
BNE else1
LDA prev + 1
CMP this + 1
BNE else1
;; if(*this == 0) {
LDA (this)
ORA (this), Y
BNE this_not_zero
;; *new = 0;
LDA #0
STA (new)
STA (new), Y
M_INCREMENT_BY_2 new
;; return;
RTS
.this_not_zero
;; y = *this++;
LDA (this)
STA yy
LDA (this), Y
STA yy + 1
M_INCREMENT_BY_2 this
BRA endif1
.else1
;; if(*prev == y)
;; prev++;
LDA (prev)
CMP yy
BNE skip_inc_prev
LDA (prev), Y
CMP yy + 1
BNE skip_inc_prev
M_INCREMENT_BY_2 prev
.skip_inc_prev
;; y-=2;
LDA yy
SEC
SBC #2
STA yy
BCS no_carry
DEC yy + 1
.no_carry
;; if(*this == y)
;; this++;
LDA (this)
CMP yy
BNE skip_inc_this
LDA (this), Y
CMP yy + 1
BNE skip_inc_this
M_INCREMENT_BY_2 this
.skip_inc_this
.endif1
;; /* write new row co-ordinate */
;; *new = y + 1;
LDA yy
CLC
ADC #1
STA (new)
LDA yy + 1
ADC #0
STA (new), Y
;; for(;;) {
.level2
;; /* skip to the leftmost cell */
;; x = *prev;
LDA (prev)
STA xx
LDA (prev), Y
STA xx + 1
;; if(x > *this)
;; x = *this;
M_ASSIGN_IF_GREATER xx, this
;; /* end of line? */
;; if(x >= 0)
;; break;
LDA xx + 1
BMI x_negative
JMP level1
.x_negative
;; for(;;) {
.level3
;; /* add a column to the bitmap */
;; ur = lr = 0;
STZ ur
STZ lr
;; if(*prev == x) {
;; ur = *(prev + 1);
;; prev += 2;
;; }
M_UPDATE_CHUNK_IF_EQUAL_TO_X prev, ur
;; if(*this == x) {
;; lr = *(this + 1);
;; this += 2;
;; }
M_UPDATE_CHUNK_IF_EQUAL_TO_X this, lr
;; if ((ul | ur | ll | lr) == 0) {
;; break;
;; }
LDA ul
ORA ur
ORA ll
ORA lr
BNE not_break
JMP level2
.not_break
; inputs for first bitpair
; AAAA ....
; AaaA ....
; BBBB ....
; .... ....
;; /* UL table lookup, produces bits 7 and 6 */
;; page = ll >> 4;
;; index = ul;
;; outcome = table[(page << 8) | index] & 0xC0;
STZ outcome
LDA ul
ORA ll
BEQ left_zero
LDX ll ; 3 - read a nibble for the first bitpair
LDA bp1_convert, X ; 4 - convert nibble to high pointer
STA bp1_table + 2 ; 4
LDY ul ; 3 - read a byte
.bp1_table ;
LDA table_base, Y ; 4 - get the first bitpair of the result
AND #&C0 ; 2
ORA outcome
STA outcome ; 3 - store our work in progress
; 27 cycles so far
; inputs for second bitpair
; .... ....
; AAAA ....
; BbbB ....
; BBBB ....
;; /* LL table lookup, produces bits 3 and 2 */
;; page = ul & 0x0F;
;; index = ll;
;; outcome |= table[(page << 8) | index] & 0x0C;
LDA bp2_convert, Y ; 4 - convert nibble to high pointer
STA bp2_table + 2 ; 4
.bp2_table ;
LDA table_base, X ; 4 - get the second bitpair of the result
AND #&0C ; 2
ORA outcome ; 3 - combine
STA outcome ; 3 - and store
; 27+30 cycles so far
.left_zero
; inputs for third bitpair
; ..AA CC..
; ..Aa cC..
; ..BB DD..
; .... ....
;; /* UR table lookup, produces bits 5 and 4 */
;; page = ((lr & 0xC0) | (ll & 0x30)) >> 4;
;; index = (ur & 0xCC) | (ul & 0x33);
;; outcome |= table[(page << 8) | index] & 0x30;
LDA ll ; 3 - read first half nibble for the third bitpair
AND #&30 ; 2
STA t ; 3
LDA lr ; 3 - read second half nibble
AND #&C0 ; 2
ORA t ; 3
TAX ; 2 - read the nibble index for the third bitpair
LDA bp3_convert, X ; 4 - convert nibble to high pointer
STA bp3_table + 2 ; 4
LDA ul ; 3 - read a half byte
AND #&33 ; 2
STA t ; 3
LDA ur ; 3 - read a half byte
AND #&CC ; 2
ORA t ; 3 - combine to make the byte
TAX ; 2
.bp3_table ;
LDA table_base, X ; 4 - get the third bitpair of the result
AND #&30 ; 2
ORA outcome ; 3 - combine
STA outcome ; 3 - and store
; 27+30+62 cycles so far
; inputs for fourth bitpair
; .... ....
; ..AA CC..
; ..Bb dD..
; ..BB DD..
;; /* LR table lookup, produces bits 1 and 0 */
;; page = (ur & 0x0C) | (ul & 0x03);
;; index = (lr & 0xCC) | (ll & 0x33);
;; outcome |= table[(page << 8) | index] & 0x03;
LDA ul ; 3 - read first half nibble for the fourth bitpair
AND #&03 ; 2
STA t ; 3
LDA ur ; 3 - read second half nibble
AND #&0C ; 2
ORA t ; 3
CLC ; 2 - read the nibble index for the fourth bitpair
ADC #>table_base ; 2 - convert nibble to high pointer
STA bp4_table + 2 ; 4
LDA ll ; 3 - read a half byte
AND #&33 ; 2
STA t ; 3
LDA lr ; 3 - read a half byte
AND #&CC ; 2
ORA t ; 3 - combine to make the byte
TAX ; 2
.bp4_table ;
LDA table_base, X ; 4 - get the fourth bitpair of the result
AND #&03 ; 2
LDY #1 ; restore constant Y value
ORA outcome ; 3 - combine - result is in A
; 148
;; A now holds the new chunk
;; if (outcome) {
;; if (*new < 0) {
;; // last coordinate was an X
;; new += 2;
;; } else {
;; // last coordinate was a Y
;; new += 1;
;; }
;; *new = x - 3;
;; *(new + 1) = outcome;
;; }
BEQ endif2
STA outcome
LDA (new), Y
BMI last_was_x
M_INCREMENT_BY_2 new
BRA store_x
.last_was_x
M_INCREMENT_BY_3 new
.store_x
LDA xx
SEC
SBC #3
STA (new)
LDA xx + 1
SBC #0
STA (new), Y
INY
LDA outcome
STA (new), Y
DEY
.endif2
;; /* move right */
;; ul = ur;
;; ll = lr;
LDA ur
STA ul
LDA lr
STA ll
;; x += 4;
LDA xx
CLC
ADC #4
STA xx
BCC jmp_level3
INC xx + 1
.jmp_level3
JMP level3
;; }
;; }
;; }
}
;; ************************************************************
;; moves the x/y start to the top left corner
;; ************************************************************
;;
;; as list42 life doesn't support zooming, the offset is fixed
.list_life_offset_top_left
LDA xstart
SEC
SBC #&80
STA xstart
LDA xstart + 1
SBC #0
STA xstart + 1
LDA ystart
CLC
ADC #&80
STA ystart
LDA ystart + 1
ADC #0
STA ystart + 1
RTS
;; ************************************************************
;; counts the cells (in BCD)
;; ************************************************************
;; (list) points to the cell list to count
;;
.list_life_count_cells
{
LDX #cell_count - count_base
JSR clear_count
LDY #1
.loop
LDA (list), Y ; the sign bit indicates X vs Y coordinates
BPL y_or_termiator
INY
LDA (list), Y ; read the bitmap
DEY
TAX
LDA bitcnt, X
LDX #cell_count - count_base
JSR add_to_count
M_INCREMENT_BY_3 list
BRA loop
.y_or_termiator
ORA (list)
BEQ exit
.inc_by_2
M_INCREMENT_BY_2 list
BRA loop
.exit
RTS
}
;; ************************************************************
;; prune the universe
;; ************************************************************
;; (this) points to the source list
;; (new) points to the destination list
.list_life_prune_cells
{
LDY #1
.loop
LDA (this), Y ; is it an X or a Y coordinate?
BPL is_y_or_terminator
CMP #&80 ; at the left edge?
BEQ skip_copy_x
CMP #&FF ; at the right edge?
BEQ skip_copy_x
INY
LDA (this), Y
STA (new), Y
DEY
LDA (this), Y
STA (new), Y
LDA (this)
STA (new)
M_INCREMENT_BY_3 new
.skip_copy_x
M_INCREMENT_BY_3 this
BRA loop
.is_y_or_terminator
TAX ; test for the terminating 0000
ORA (this)
BEQ terminator
TXA
CMP #&7F ; at the top edge?
BEQ skip_row ; yes, skip the whole row
CMP #&00 ; at the bottom edge?
BEQ skip_row ; no, copy the y coord and continue processing x coords
LDA (this), Y
STA (new), Y
LDA (this)
STA (new)
M_INCREMENT_BY_2 new
M_INCREMENT_BY_2 this
JMP loop
.skip_row
M_INCREMENT_BY_2 this
.skip_row_loop
LDA (this), Y ; is it an X or a Y coordinate?
BPL is_y_or_terminator
M_INCREMENT_BY_3 this
BRA skip_row_loop
.terminator
LDA #0
STA (new)
STA (new), Y
M_INCREMENT_BY_2 new
RTS
}
;; ************************************************************
;; list_life_load_buffer()
;; ************************************************************
;; Initializes the (this) buffer from the 256x256 screen_base
;;
.list_life_load_buffer
{
RTS
}
;; ************************************************************
;; list_life_update_delta()
;; ************************************************************
;; (list) points to the cell list
;; NOTE: this won't actually work in C, as the list offsets are butchered
;; TODO: add suitable casts so it will with list being char *
;; xend = xstart + 256;
;; yend = ystart - 8;
;; while (1) {
;; yy = *list;
;; if (ystart < yy) {
;; list += 2
;; // Skip over x-coordinates
;; while (*list < 0) {
;; list += 3;
;; }
;; } else if (yend < yy) {
;; list += 2
;; temp = 32 * (ystart - yy);
;; while (1);
;; xx = *list;
;; // Test if we have read a y coordinate
;; if (xx >= 0) {
;; break;
;; }
;; bmp = *(list + 2);
;; list += 3;
;; if (xx >= xstart && xx < xend) {
;; X_reg = temp + (xx - xstart) >> 3;
;; ul = bmp & 0xF0
;; ll = (bmp & 0x0F) << 4
;; ur = 0
;; lr = 0
;; Y_reg = (xx - xstart) & 7;
;; while (Y_reg != 0) {
;; {ul, ur} >>= 1
;; {ll, lr} >>= 1
;; Y_reg--;
;; }
;; ;; a chunk is 4 bits wide, and can align with a byte in 8 possible ways
;; *(delta_base + X_reg) |= ul;
;; *(delta_base + 1 + X_reg) |= ur;
;; *(delta_base + 32 + X_reg) |= ll;
;; *(delta_base + 33 + X_reg) |= lr;
;; }
;; }
;; } else {
;; return;
;; }
;; }
.list_life_update_delta
{
;; test for 4x2 straddling the delta buffer last time
LDA (list) ; Load the LSB of the first Y coordinate
EOR ystart ; Compare to the LSB of the ystart
AND #&01 ; If the bit 0s are the same
BEQ no_straddle ; then things are nicely aligned
LDX #&1F ; otherwise copy the line that overflowed the delta buffer
.copy_loop
LDA DELTA_BASE + 256, X
STA DELTA_BASE, X
STZ DELTA_BASE + 256, X ; and clear the buffer, for the overflow this time
DEX
BPL copy_loop
.no_straddle
;; xend = xstart + 256;
CLC
LDA xstart
ADC #&FD ; only render 253 pixels, so overflow of the 4x2 pixel
STA xend ; block cannot happen
LDA xstart + 1
ADC #&00
STA xend + 1
;; yend = ystart - 8;
LDA ystart
SEC
SBC #8
STA yend
LDA ystart + 1
SBC #0
STA yend + 1;
;; while (1) {
.while_level1
;; yy = *list;
LDY #0
LDA (list), Y
STA yy
INY
LDA (list), Y
STA yy + 1
;; if (ystart < yy) {
;; yy and ystart can only be positive (or zero), so we can use 16-bit unsigned comparison
LDA ystart
CMP yy
LDA ystart + 1
SBC yy + 1
BCS else1
;; list += 2
M_INCREMENT_BY_2 list ;; skip over y
;; // Skip over x-coordinates
;; while (*list < 0) {
;; list += 3;
;; }
LDY #1
.skip_over_x
LDA (list), Y
BPL while_level1
M_INCREMENT_BY_3 list
BRA skip_over_x
;; } else if (yend < yy) {
.else1
;; yy and yend can only be positive (or zero), so we can use 16-bit unsigned comparison
LDA yend
CMP yy
LDA yend + 1
SBC yy + 1
BCC not_else2
RTS
.not_else2
;; list += 2
M_INCREMENT_BY_2 list ;; skip over y
;; temp = 32 * (ystart - yy);
;; 8 bits is sufficient here, as the Y strip is 8 pixels high
LDA ystart
SEC
SBC yy
ASL A
ASL A
ASL A
ASL A
ASL A
STA temp
;; while(1) {
.while_level2
;; xx = *list;
LDY #0
LDA (list), Y
STA xx
INY
LDA (list), Y
STA xx + 1
;; // Test if we have read a y coordinate
;; if (xx >= 0) {
;; break;
;; }
BMI less_than_zero
JMP while_level1
.less_than_zero
;; bmp = *(list + 2);
;; list += 3;
INY
LDA (list), Y
STA bitmap
M_INCREMENT_BY_3 list
;; if (xx >= xstart && xx < xend) {
;; xx and xstart and xend can only be negative, so we can use 16-bit unsigned comparison
LDA xx
CMP xstart
LDA xx + 1
SBC xstart + 1
BCC while_level2
LDA xx
CMP xend
LDA xx + 1
SBC xend + 1
BCS while_level2
;; X_reg = temp + (xx - xstart) >> 3;
;; ul = bmp & 0xF0
;; ll = (bmp & 0x0F) << 4
;; ur = 0
;; lr = 0
;; Y_reg = (xx - xstart) & 7;
;; while (Y_reg != 0) {
;; {ul, ur} >>= 1
;; {ll, lr} >>= 1
;; Y_reg--;
;; }
;; ;; a chunk is 4 bits wide, and can align with a byte in 8 possible ways
LDA xx
SEC
SBC xstart
TAY
LSR A
LSR A
LSR A
CLC
ADC temp
TAX
LDA bitmap
AND #&F0
STA ul
LDA bitmap
ASL A
ASL A
ASL A
ASL A
STA ll
STZ ur
STZ lr
TYA
AND #&07
TAY
BEQ skip_shift_bitmap
.shift_bitmap_loop
LSR ul
ROR ur
LSR ll
ROR lr
DEY
BNE shift_bitmap_loop
.skip_shift_bitmap
;; *(delta_base + X_reg) |= ul;
;; *(delta_base + 1 + X_reg) |= ur;
;; *(delta_base + 32 + X_reg) |= ll;
;; *(delta_base + 33 + X_reg) |= lr;
LDA DELTA_BASE, X
ORA ul
STA DELTA_BASE, X
LDA DELTA_BASE + 1, X
ORA ur
STA DELTA_BASE + 1, X
LDA DELTA_BASE + 32, X
ORA ll
STA DELTA_BASE + 32, X
LDA DELTA_BASE + 33, X
ORA lr
STA DELTA_BASE + 33, X
JMP while_level2
;; } else {
;; return;
;; }
;; }
}
ALIGN 256
;; .... LOOK-UP TABLES ....
.bitcnt
EQUB &00,&01,&01,&02,&01,&02,&02,&03,&01,&02,&02,&03,&02,&03,&03,&04
EQUB &01,&02,&02,&03,&02,&03,&03,&04,&02,&03,&03,&04,&03,&04,&04,&05
EQUB &01,&02,&02,&03,&02,&03,&03,&04,&02,&03,&03,&04,&03,&04,&04,&05
EQUB &02,&03,&03,&04,&03,&04,&04,&05,&03,&04,&04,&05,&04,&05,&05,&06
EQUB &01,&02,&02,&03,&02,&03,&03,&04,&02,&03,&03,&04,&03,&04,&04,&05
EQUB &02,&03,&03,&04,&03,&04,&04,&05,&03,&04,&04,&05,&04,&05,&05,&06
EQUB &02,&03,&03,&04,&03,&04,&04,&05,&03,&04,&04,&05,&04,&05,&05,&06
EQUB &03,&04,&04,&05,&04,&05,&05,&06,&04,&05,&05,&06,&05,&06,&06,&07
EQUB &01,&02,&02,&03,&02,&03,&03,&04,&02,&03,&03,&04,&03,&04,&04,&05
EQUB &02,&03,&03,&04,&03,&04,&04,&05,&03,&04,&04,&05,&04,&05,&05,&06
EQUB &02,&03,&03,&04,&03,&04,&04,&05,&03,&04,&04,&05,&04,&05,&05,&06
EQUB &03,&04,&04,&05,&04,&05,&05,&06,&04,&05,&05,&06,&05,&06,&06,&07
EQUB &02,&03,&03,&04,&03,&04,&04,&05,&03,&04,&04,&05,&04,&05,&05,&06
EQUB &03,&04,&04,&05,&04,&05,&05,&06,&04,&05,&05,&06,&05,&06,&06,&07
EQUB &03,&04,&04,&05,&04,&05,&05,&06,&04,&05,&05,&06,&05,&06,&06,&07
EQUB &04,&05,&05,&06,&05,&06,&06,&07,&05,&06,&06,&07,&06,&07,&07,&08
.bp1_convert
.bp3_convert
FOR i, 0, 255
EQUB (>table_base) + (i >> 4)
NEXT
.bp2_convert
.bp4_convert
FOR i, 0, 255
EQUB (>table_base) + (i AND &0F)
NEXT
;; A7 A6 A5 A4 C7 C6
;; A3 A2 A1 A0 C3 C2
;; B7 B6 B5 B4 D7 D6
;; B3 B2 B1 B0 D3 D2
;;
;; 4K lookup table, broken into page and index:
;;
;; X11 X10 X9 X8 <<< Page
;; X7 X6 X5 X4 <<< Index
;; X3 X2 X1 X0 <<< Index
;;
;; Upper Left - produces bits (7) and [6]
;; B7 B6 B5 B4
;; A7 A4 A5 A4
;; A3 (A2)[A1] A0
;;
;; Upper Right - produces bits (5) and [4]
;; D7 D6 B5 B4
;; C7 C6 A5 A4
;; [C3] C2 A1 (A0)
;;
;; Lower Left - produces bits (3) and [2]
;; A3 A2 A1 A0
;; B7 (B6)[B5] B4
;; B3 B2 B1 B0
;;
;; Lower Right - produces bits (1) and [0]
;; C3 C2 A1 A0
;; [D7] D6 B5 (B4)
;; D3 D2 B1 B0
;;
;; Data created by code in misc/list42_life.c
.table_base
EQUB &00,&00,&00,&00,&00,&00,&00,&44,&00,&00,&00,&22,&00,&11,&88,&ff
EQUB &00,&00,&00,&66,&00,&55,&44,&73,&00,&33,&22,&77,&11,&76,&ff,&fa
EQUB &00,&00,&00,&66,&00,&44,&cc,&ee,&00,&22,&aa,&ec,&88,&ff,&e6,&f5
EQUB &00,&66,&66,&66,&44,&37,&ee,&bb,&22,&77,&ce,&dd,&ff,&be,&d7,&90
EQUB &00,&00,&00,&44,&00,&55,&cc,&d9,&00,&11,&88,&ff,&99,&dc,&dd,&fa
EQUB &00,&55,&44,&73,&55,&00,&d9,&aa,&11,&76,&ff,&fa,&dc,&aa,&fa,&aa
EQUB &00,&44,&cc,&ee,&cc,&9d,&cc,&bb,&88,&ff,&6e,&7d,&dd,&be,&77,&30
EQUB &44,&37,&ee,&bb,&9d,&aa,&bb,&aa,&ff,&be,&5f,&18,&be,&aa,&12,&00
EQUB &00,&00,&00,&22,&00,&11,&88,&ff,&00,&33,&aa,&b9,&99,&bb,&b3,&f5
EQUB &00,&33,&22,&77,&11,&67,&ff,&eb,&33,&33,&9b,&dd,&bb,&ee,&d7,&c0
EQUB &00,&22,&aa,&ec,&88,&ff,&e6,&f5,&aa,&b9,&00,&55,&b3,&f5,&55,&55
EQUB &22,&77,&ce,&dd,&ff,&af,&d7,&81,&9b,&dd,&55,&55,&d7,&84,&55,&00
EQUB &00,&11,&88,&ff,&99,&cd,&dd,&eb,&99,&bb,&3b,&7d,&99,&ee,&77,&60
EQUB &11,&67,&ff,&eb,&cd,&aa,&eb,&aa,&bb,&ee,&5f,&48,&ee,&aa,&42,&00
EQUB &88,&ff,&6e,&7d,&dd,&af,&77,&21,&3b,&7d,&55,&55,&77,&24,&55,&00
EQUB &ff,&af,&5f,&09,&af,&aa,&03,&00,&5f,&0c,&55,&00,&06,&00,&00,&00
EQUB &00,&00,&00,&66,&00,&55,&44,&73,&00,&33,&22,&75,&11,&76,&ff,&f8
EQUB &00,&77,&66,&73,&55,&22,&73,&22,&33,&76,&57,&50,&76,&22,&da,&88
EQUB &00,&66,&66,&64,&44,&37,&ee,&b9,&22,&75,&cc,&dd,&ff,&bc,&d5,&90
EQUB &66,&37,&46,&11,&37,&22,&9b,&88,&57,&14,&dd,&98,&9e,&88,&90,&80
EQUB &00,&55,&44,&73,&55,&00,&d9,&aa,&11,&76,&ff,&f8,&dc,&aa,&fa,&a8
EQUB &55,&22,&73,&22,&00,&22,&aa,&aa,&76,&22,&da,&88,&aa,&aa,&8a,&88
EQUB &44,&37,&ee,&b9,&9d,&aa,&bb,&a8,&ff,&bc,&5d,&18,&be,&a8,&10,&00
EQUB &37,&22,&9b,&88,&aa,&aa,&8a,&88,&9e,&88,&18,&08,&8a,&88,&00,&00
EQUB &00,&33,&22,&75,&11,&67,&ff,&e9,&33,&31,&99,&dd,&bb,&ec,&d5,&c0
EQUB &33,&67,&57,&41,&67,&22,&cb,&88,&13,&44,&dd,&c8,&ce,&88,&c0,&80
EQUB &22,&75,&cc,&dd,&ff,&ad,&d5,&81,&99,&dd,&55,&55,&d5,&84,&55,&00
EQUB &57,&05,&dd,&89,&8f,&88,&81,&80,&dd,&8c,&55,&00,&84,&80,&00,&00
EQUB &11,&67,&ff,&e9,&cd,&aa,&eb,&a8,&bb,&ec,&5d,&48,&ee,&a8,&40,&00
EQUB &67,&22,&cb,&88,&aa,&aa,&8a,&88,&ce,&88,&48,&08,&8a,&88,&00,&00
EQUB &ff,&ad,&5d,&09,&af,&a8,&01,&00,&5d,&0c,&55,&00,&04,&00,&00,&00
EQUB &8f,&88,&09,&08,&8a,&88,&00,&00,&0c,&08,&00,&00,&00,&00,&00,&00
EQUB &00,&00,&00,&66,&00,&44,&cc,&ea,&00,&22,&aa,&ec,&88,&ff,&e6,&f1
EQUB &00,&66,&66,&62,&44,&33,&ea,&bb,&22,&77,&ce,&d9,&ff,&ba,&d3,&90
EQUB &00,&66,&ee,&ec,&cc,&ae,&e6,&a0,&aa,&ec,&44,&44,&e6,&b5,&44,&11
EQUB &66,&26,&ce,&88,&ae,&bb,&82,&91,&ce,&9d,&44,&11,&97,&90,&11,&10
EQUB &00,&44,&cc,&ea,&cc,&99,&c8,&bb,&88,&ff,&6e,&79,&dd,&ba,&73,&30
EQUB &44,&33,&ea,&bb,&99,&aa,&bb,&aa,&ff,&ba,&5b,&18,&ba,&aa,&12,&00
EQUB &cc,&ae,&6e,&28,&8c,&bb,&22,&31,&6e,&3d,&44,&11,&37,&30,&11,&10
EQUB &ae,&bb,&0a,&19,&bb,&aa,&13,&00,&1f,&18,&11,&10,&12,&00,&10,&00
EQUB &00,&22,&aa,&ec,&88,&ff,&e6,&f1,&aa,&b9,&00,&55,&b3,&f5,&55,&51
EQUB &22,&77,&ce,&d9,&ff,&ab,&d3,&81,&9b,&dd,&55,&51,&d7,&80,&51,&00
EQUB &aa,&ec,&44,&44,&e6,&b5,&44,&11,&00,&55,&44,&55,&55,&15,&55,&11
EQUB &ce,&9d,&44,&11,&97,&81,&11,&01,&55,&15,&55,&11,&15,&00,&11,&00
EQUB &88,&ff,&6e,&79,&dd,&ab,&73,&21,&3b,&7d,&55,&51,&77,&20,&51,&00
EQUB &ff,&ab,&5b,&09,&ab,&aa,&03,&00,&5f,&08,&51,&00,&02,&00,&00,&00