From 44fec2c72906c03a4337b21af55d40d7f1e70804 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 6 Sep 2024 15:56:41 +0200 Subject: [PATCH] some additional last minute optimization to life example --- examples/cx16/life.p8 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/cx16/life.p8 b/examples/cx16/life.p8 index d7c96ce14..79b21a95a 100644 --- a/examples/cx16/life.p8 +++ b/examples/cx16/life.p8 @@ -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