diff --git a/docs/source/todo.rst b/docs/source/todo.rst index b6ad0d73c..11340b44a 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,10 +2,13 @@ TODO ==== +- BUG FIX: fix register argument clobbering when calling asmsubs. (see fixme_argclobber.p8) + + - finalize (most) of the still missing "new" assignment asm code generation - aliases for imported symbols for example perhaps '%alias print = c64scr.print' - option to load library files from a directory instead of the embedded ones (easier library development/debugging) -- investigate support for 8bitguy's Commander X16 platform https://murray2.com/forums/commander-x16.9/ and https://github.com/commanderx16/x16-docs +- investigate support for 8bitguy's Commander X16 platform https://www.commanderx16.com and https://github.com/commanderx16/x16-docs - see if we can group some errors together for instance the (now single) errors about unidentified symbols diff --git a/examples/fixme_argclobber.p8 b/examples/fixme_argclobber.p8 new file mode 100644 index 000000000..e9fcfec45 --- /dev/null +++ b/examples/fixme_argclobber.p8 @@ -0,0 +1,47 @@ +%import c64lib +%import c64utils +%import c64flt +%zeropage basicsafe +%option enable_floats + + +; TODO: fix register argument clobbering when calling asmsubs. +; for instance if the first arg goes into Y, and the second in A, +; but when calculating the second argument clobbers Y, the first argument gets destroyed. + +main { + + sub start() { + function(20, calculate()) + asmfunction(20, calculate()) + + c64.CHROUT('\n') + + if @($0400)==@($0402) and @($0401) == @($0403) { + c64scr.print("ok: results are same\n") + } else { + c64scr.print("error: result differ; arg got clobbered\n") + } + } + + sub function(ubyte a1, ubyte a2) { + ; non-asm function passes via stack, this is ok + @($0400) = a1 + @($0401) = a2 + } + + asmsub asmfunction(ubyte a1 @ Y, ubyte a2 @ A) { + ; asm-function passes via registers, risk of clobbering + %asm {{ + sty $0402 + sta $0403 + }} + } + + sub calculate() -> ubyte { + Y = 99 + return Y + } +} + + diff --git a/examples/structs.p8 b/examples/structs.p8 index aa85a04eb..1c44fc4d3 100644 --- a/examples/structs.p8 +++ b/examples/structs.p8 @@ -20,7 +20,7 @@ main { other = purple - other.red /= 3 + other.red /= 2 other.green = 10 + other.green / 2 other.blue = 99 diff --git a/examples/tehtriz.p8 b/examples/tehtriz.p8 index 76f593856..20873510d 100644 --- a/examples/tehtriz.p8 +++ b/examples/tehtriz.p8 @@ -549,7 +549,7 @@ blocklogic { sub noCollision(ubyte xpos, ubyte ypos) -> ubyte { ubyte i for i in 15 downto 0 { - ; TODO FIX THIS when compiling without optimizations (codegen problem: clobbering register arguments): + ; TODO FIX THIS when compiling without optimizations (codegen problem: clobbering register arguments, see fixme_argclobber): if currentBlock[i] and c64scr.getchr(xpos + (i&3), ypos+i/4)!=32 return false }