comment about implementation in life example

This commit is contained in:
Irmen de Jong 2024-09-06 16:14:10 +02:00
parent 44fec2c729
commit d4d8e1b1ba
3 changed files with 22 additions and 2 deletions

View File

@ -1,14 +1,20 @@
TODO
====
TODO creates buggy code in 6502: (ok in IR)
TODO creates buggy code in 6502 (except PET!!!): (also ok in IR)
main {
sub start() {
uword active_world = memory("world", 80*50, 0)
uword cell_off = 500
const uword STRIDE = 40
sys.memset(active_world, 80*50, 1)
txt.print_ub(active_world[500] + active_world[501]) ; TODO prints 1, must be 2
txt.nl()
txt.print_ub(active_world[cell_off] + active_world[cell_off_1]) ; TODO prints 1, must be 2
txt.nl()
txt.print_ub(count()) ; TODO prints 1, must be 8
txt.nl()
sub count() -> ubyte {
return active_world[cell_off-STRIDE-1] + active_world[cell_off-STRIDE] + active_world[cell_off-STRIDE+1] +

View File

@ -95,6 +95,13 @@ main {
if active_world == world1
new_world = world2
; To avoid re-calculating word index lookups into the new- and active world arrays,
; we calculate the required pointer values upfront.
; Inside the loop we can use ptr+x just fine (results in efficient LDA (ptr),Y instruction because x is a byte type),
; and for each row we simply add the stride to the pointer.
; It's more readable to use active_world[offset] etc, but offset is a word value, and this produces
; inefficient assembly code because we can't use a register indexed mode in this case. Costly inside a loop.
uword @requirezp new_world_ptr = new_world + STRIDE+1-DXOFFSET
uword @requirezp active_world_ptr = active_world + STRIDE+1-DXOFFSET

View File

@ -5,10 +5,17 @@
main {
sub start() {
uword active_world = memory("world", 80*50, 0)
uword cell_off = 500
uword @shared cell_off = 500
uword @shared cell_off_1 = cell_off+1
const uword STRIDE = 40
sys.memset(active_world, 80*50, 1)
txt.print_ub(active_world[500] + active_world[501]) ; TODO prints 1, must be 2
txt.nl()
txt.print_ub(active_world[cell_off] + active_world[cell_off_1]) ; TODO prints 1, must be 2
txt.nl()
txt.print_ub(count()) ; TODO prints 1, must be 8
txt.nl()
sub count() -> ubyte {
return active_world[cell_off-STRIDE-1] + active_world[cell_off-STRIDE] + active_world[cell_off-STRIDE+1] +