/
life.s
89 lines (87 loc) · 1.04 KB
/
life.s
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
jmp start
tmp:
.byte 0
savecarry:
.byte 1
inbyte:
.byte 0
.align 2
outrow:
.word neighbors
inrow:
.word buf0
.org $1000
start:
countrow:
; count neighbors across one screen row
; inrow => pointer to row of 5 bytes
; initialize input index
lda #0
sta inbyte
; get carry from last byte in row
ldy #4
lda (inrow),y
rol
rol
sta savecarry
next_byte:
; get next byte, exiting if at end of row
ldy inbyte
cpy #5
beq end
lda (inrow),y
pha
iny
sty inbyte
lda #0
tay
pla
next_bit:
sta tmp
lda savecarry
ror ; carry from previous byte
lda #0
tax ; x is our neighbor counter
lda tmp
rol
ror
bcc chkbit1
inx
chkbit1:
ror
bcc chkbit2
inx
chkbit2:
ror
bcc store
inx
store:
rol
rol
sta savecarry
ror
sta tmp
txa
sta (outrow),y
iny
cpy #7
bne check_end
; NYI get first bit from next byte
; NYI if at last byte, get from first in row
lda tmp
bne next_bit
check_end:
cpy #8
beq next_byte
lda tmp
bne next_bit
end:
brk
.org $2000
buf0:
.fill 120 255
buf1:
.fill 120 255
.org $2400
neighbors:
.fill 960 0