some additional last minute optimization to life example

This commit is contained in:
Irmen de Jong 2024-09-06 15:56:41 +02:00
parent a80a6913e3
commit 44fec2c729

View File

@ -89,14 +89,15 @@ main {
sub next_gen() {
const ubyte DXOFFSET = 0
const ubyte DYOFFSET = 2
uword voffset = STRIDE+1-DXOFFSET
uword @zp offset
ubyte[2] cell_chars = [sc:' ', sc:'●']
uword @requirezp new_world = world1
if active_world == world1
new_world = world2
uword @requirezp new_world_ptr = new_world + STRIDE+1-DXOFFSET
uword @requirezp active_world_ptr = active_world + STRIDE+1-DXOFFSET
ubyte x
ubyte y
for y in DYOFFSET to HEIGHT+DYOFFSET-1 {
@ -104,11 +105,9 @@ main {
cx16.vaddr_autoincr(1, $b000 + 256*y, 0, 2) ; allows us to use simple Vera data byte assigns later instead of setchr() calls
for x in DXOFFSET to WIDTH+DXOFFSET-1 {
offset = voffset + x
; count the living neighbors
ubyte cell = active_world[offset]
uword @requirezp ptr = active_world + offset - STRIDE - 1
ubyte cell = @(active_world_ptr + x)
uword @requirezp ptr = active_world_ptr + x - STRIDE - 1
ubyte neighbors = @(ptr) + @(ptr+1) + @(ptr+2) +
@(ptr+STRIDE) + cell + @(ptr+STRIDE+2) +
@(ptr+STRIDE*2) + @(ptr+STRIDE*2+1) + @(ptr+STRIDE*2+2)
@ -118,13 +117,14 @@ main {
cell=1
else if neighbors!=4
cell=0
new_world[offset] = cell
@(new_world_ptr + x) = cell
; draw new cell
; txt.setchr(x,y,cell_chars[cell])
cx16.VERA_DATA0 = cell_chars[cell]
}
voffset += STRIDE
active_world_ptr += STRIDE
new_world_ptr += STRIDE
}
active_world = new_world