use H register instead of HRAM byte to store alive neighbor count
This commit is contained in:
@@ -375,7 +375,9 @@ Start:
|
|||||||
|
|
||||||
jp .mainloop
|
jp .mainloop
|
||||||
|
|
||||||
CountLiveNeighbors: MACRO
|
AddLiveNeighbors: MACRO
|
||||||
|
; H register will store number of alive neighbors
|
||||||
|
|
||||||
; load current cell and mask out bits that are not neighbors
|
; load current cell and mask out bits that are not neighbors
|
||||||
ld c, LOW(Cells + \1)
|
ld c, LOW(Cells + \1)
|
||||||
ld a, [$FF00+c]
|
ld a, [$FF00+c]
|
||||||
@@ -387,23 +389,27 @@ CountLiveNeighbors: MACRO
|
|||||||
add a, e
|
add a, e
|
||||||
ld e, a
|
ld e, a
|
||||||
ld a, [de]
|
ld a, [de]
|
||||||
ld b, a
|
|
||||||
|
|
||||||
; add to alive
|
; add to alive
|
||||||
ldh a, [Alive]
|
add a, h
|
||||||
add a, b
|
ld h, a
|
||||||
ldh [Alive], a
|
|
||||||
ENDM
|
ENDM
|
||||||
|
|
||||||
Conway: MACRO
|
Conway: MACRO
|
||||||
|
; \1 = mask for neighbors in inner cell
|
||||||
|
; \2 = first useful neighbor 2x2 cell
|
||||||
|
; \3 = mask for first useful neighbor 2x2 cell
|
||||||
|
; \4 = mask for second useful neighbor 2x2 cell
|
||||||
|
; \5 = mask for third useful neighbor 2x2 cell
|
||||||
|
|
||||||
; reset alive counter
|
; reset alive counter
|
||||||
xor a
|
ld h, 0
|
||||||
ldh [Alive], a
|
|
||||||
|
|
||||||
CountLiveNeighbors 0, \1
|
; Check all neighbors
|
||||||
CountLiveNeighbors (1 + (\2 + 0) % 8), \3
|
AddLiveNeighbors 0, \1
|
||||||
CountLiveNeighbors (1 + (\2 + 1) % 8), \4
|
AddLiveNeighbors (1 + (\2 + 0) % 8), \3
|
||||||
CountLiveNeighbors (1 + (\2 + 2) % 8), \5
|
AddLiveNeighbors (1 + (\2 + 1) % 8), \4
|
||||||
|
AddLiveNeighbors (1 + (\2 + 2) % 8), \5
|
||||||
|
|
||||||
; load current group mask
|
; load current group mask
|
||||||
ld b, (~\1) & $F
|
ld b, (~\1) & $F
|
||||||
@@ -414,8 +420,8 @@ Conway: MACRO
|
|||||||
; mask data
|
; mask data
|
||||||
and a, b
|
and a, b
|
||||||
|
|
||||||
; load alive count
|
; put alive neighbors in A
|
||||||
ldh a, [Alive]
|
ld a, h
|
||||||
|
|
||||||
jr z, .dead\@
|
jr z, .dead\@
|
||||||
;.alive
|
;.alive
|
||||||
@@ -656,7 +662,6 @@ Buffer1: ds 20 * 18
|
|||||||
SECTION "Compute Memory", HRAM
|
SECTION "Compute Memory", HRAM
|
||||||
Old: ds 2 ; pointer to bufferX
|
Old: ds 2 ; pointer to bufferX
|
||||||
New: ds 2 ; pointer to bufferX
|
New: ds 2 ; pointer to bufferX
|
||||||
Alive: ds 1
|
|
||||||
XLoop: ds 1
|
XLoop: ds 1
|
||||||
YLoop: ds 1
|
YLoop: ds 1
|
||||||
Cells: ds 9
|
Cells: ds 9
|
||||||
|
|||||||
Reference in New Issue
Block a user