From 510ca042c92a2adf5e8b79ed92d3e967f3fc82ae Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 22 Nov 2020 18:17:43 +0100 Subject: [PATCH] stack tested for most example programs --- compiler/res/prog8lib/c64/graphics.p8 | 11 ++++++++++- compiler/res/prog8lib/cx16/graphics.p8 | 8 ++++++++ compiler/res/prog8lib/test_stack.p8 | 1 + docs/source/todo.rst | 1 - examples/balloonflight.p8 | 4 ++++ examples/balls.p8 | 6 ++++++ examples/cube3d-float.p8 | 3 +++ examples/cube3d-gfx.p8 | 3 +++ examples/cube3d-sprites.p8 | 3 +++ examples/cube3d.p8 | 3 +++ examples/cx16/cobramk3-gfx.p8 | 3 +++ examples/line-circle-gfx.p8 | 6 ++++++ examples/line-circle-txt.p8 | 3 +++ examples/mandelbrot-gfx.p8 | 3 +++ examples/mandelbrot.p8 | 3 +++ examples/numbergame.p8 | 3 +++ examples/plasma.p8 | 6 +++++- examples/primes.p8 | 3 +++ examples/sorting.p8 | 2 ++ examples/tehtriz.p8 | 4 ++++ examples/testforloops.p8 | 4 ++++ examples/textelite.p8 | 3 +++ examples/turtle-gfx.p8 | 3 +++ 23 files changed, 86 insertions(+), 3 deletions(-) diff --git a/compiler/res/prog8lib/c64/graphics.p8 b/compiler/res/prog8lib/c64/graphics.p8 index 8fbe03f42..90c22073d 100644 --- a/compiler/res/prog8lib/c64/graphics.p8 +++ b/compiler/res/prog8lib/c64/graphics.p8 @@ -12,11 +12,20 @@ graphics { sub enable_bitmap_mode() { ; enable bitmap screen, erase it and set colors to black/white. - c64.SCROLY |= %00100000 + c64.SCROLY = %00111000 + c64.SCROLX = %00001000 c64.VMCSB = (c64.VMCSB & %11110000) | %00001000 ; $2000-$3fff clear_screen(1, 0) } + sub disable_bitmap_mode() { + ; enables text mode, erase the text screen, color white + c64.SCROLY = %00011000 + c64.SCROLX = %00001000 + c64.VMCSB = (c64.VMCSB & %11110000) | %00000100 ; $1000-$2fff + txt.fill_screen(' ', 1) + } + sub clear_screen(ubyte pixelcolor, ubyte bgcolor) { memset(BITMAP_ADDRESS, 320*200/8, 0) txt.fill_screen(pixelcolor << 4 | bgcolor, 0) diff --git a/compiler/res/prog8lib/cx16/graphics.p8 b/compiler/res/prog8lib/cx16/graphics.p8 index e2bbc4d51..0b9a74559 100644 --- a/compiler/res/prog8lib/cx16/graphics.p8 +++ b/compiler/res/prog8lib/cx16/graphics.p8 @@ -1,5 +1,6 @@ %target cx16 %import syslib +%import textio ; bitmap pixel graphics module for the CommanderX16 ; wraps the graphics functions that are in ROM. @@ -17,6 +18,13 @@ graphics { clear_screen(1, 0) } + sub disable_bitmap_mode() { + ; enables text mode, erase the text screen, color white + void cx16.screen_set_mode(2) + txt.fill_screen(' ', 1) ; TODO doesn't seem to fully clear the text screen after returning from gfx mode + } + + sub clear_screen(ubyte pixelcolor, ubyte bgcolor) { cx16.GRAPH_set_colors(pixelcolor, pixelcolor, bgcolor) cx16.GRAPH_clear() diff --git a/compiler/res/prog8lib/test_stack.p8 b/compiler/res/prog8lib/test_stack.p8 index a079cca48..1c1f51c19 100644 --- a/compiler/res/prog8lib/test_stack.p8 +++ b/compiler/res/prog8lib/test_stack.p8 @@ -1,3 +1,4 @@ +%import textio test_stack { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 755605602..43ea74f75 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,7 +2,6 @@ TODO ==== -- check cpu stack consistency in all examples - make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_' - option to load the built-in library files from a directory instead of the embedded ones (for easier library development/debugging) - see if we can group some errors together for instance the (now single) errors about unidentified symbols diff --git a/examples/balloonflight.p8 b/examples/balloonflight.p8 index 38b466b96..ccc7abcb6 100644 --- a/examples/balloonflight.p8 +++ b/examples/balloonflight.p8 @@ -1,6 +1,7 @@ %target c64 %import syslib %import textio +%import test_stack %zeropage basicsafe main { @@ -23,6 +24,9 @@ main { ubyte upwards = true repeat { + ;txt.plot(0,0) + ;test_stack.test() + ubyte mountain = 223 ; slope upwards if active_height < target_height { active_height++ diff --git a/examples/balls.p8 b/examples/balls.p8 index a149af5c0..0bbcfb4f6 100644 --- a/examples/balls.p8 +++ b/examples/balls.p8 @@ -1,4 +1,6 @@ %import textio +%import test_stack + %zeropage basicsafe ; Note: this program is compatible with C64 and CX16. @@ -86,12 +88,16 @@ main { ; read clock uword jiffies %asm {{ + stx P8ZP_SCRATCH_REG jsr c64.RDTIM sta jiffies stx jiffies+1 + ldx P8ZP_SCRATCH_REG }} txt.print("\nbenchmark: ") txt.print_uw(jiffies) txt.print(" jiffies for 1000 frames.\n") + + ; test_stack.test() } } diff --git a/examples/cube3d-float.p8 b/examples/cube3d-float.p8 index a40cee432..7a704ad48 100644 --- a/examples/cube3d-float.p8 +++ b/examples/cube3d-float.p8 @@ -1,5 +1,6 @@ %import floats %import textio +%import test_stack %zeropage basicsafe ; Note: this program is compatible with C64 and CX16. @@ -41,6 +42,8 @@ main { txt.print(" jiffies/fr = ") txt.print_ub(60/timer_jiffies) txt.print(" fps") + + ;test_stack.test() } } diff --git a/examples/cube3d-gfx.p8 b/examples/cube3d-gfx.p8 index 570f60dce..f6311f24e 100644 --- a/examples/cube3d-gfx.p8 +++ b/examples/cube3d-gfx.p8 @@ -1,5 +1,6 @@ %import syslib %import graphics +%import test_stack ; Note: this program is compatible with C64 and CX16. @@ -37,6 +38,8 @@ main { anglez+=452 wait_a_little_bit() + + ; test_stack.test() } } diff --git a/examples/cube3d-sprites.p8 b/examples/cube3d-sprites.p8 index be664bdaa..aa5ef2464 100644 --- a/examples/cube3d-sprites.p8 +++ b/examples/cube3d-sprites.p8 @@ -1,6 +1,7 @@ %target c64 %import syslib %import textio +%import test_stack spritedata $2000 { ; this memory block contains the sprite data @@ -95,6 +96,8 @@ main { txt.print(" jiffies/fr = ") txt.print_ub(60/c64.TIME_LO) txt.print(" fps") + + ; test_stack.test() } } diff --git a/examples/cube3d.p8 b/examples/cube3d.p8 index dd8abda45..5f825bda5 100644 --- a/examples/cube3d.p8 +++ b/examples/cube3d.p8 @@ -1,5 +1,6 @@ %target c64 %import syslib +%import test_stack %import textio main { @@ -33,6 +34,8 @@ main { txt.print_ub(60/c64.TIME_LO) txt.print(" fps") c64.TIME_LO=0 + + ; test_stack.test() } } diff --git a/examples/cx16/cobramk3-gfx.p8 b/examples/cx16/cobramk3-gfx.p8 index 9e4422e5e..c0442ac41 100644 --- a/examples/cx16/cobramk3-gfx.p8 +++ b/examples/cx16/cobramk3-gfx.p8 @@ -1,5 +1,6 @@ %target cx16 %import syslib +%import test_stack %import conv ; TODO add all other Elite's ships, show their name, advance to next ship on keypress @@ -41,6 +42,8 @@ main { anglex += 217 angley -= 505 anglez += 452 + + ; test_stack.test() } } diff --git a/examples/line-circle-gfx.p8 b/examples/line-circle-gfx.p8 index 75a2f8698..f8471254b 100644 --- a/examples/line-circle-gfx.p8 +++ b/examples/line-circle-gfx.p8 @@ -1,4 +1,5 @@ %import graphics +%import test_stack ; Note: this program is compatible with C64 and CX16. @@ -6,8 +7,13 @@ main { sub start() { graphics.enable_bitmap_mode() + draw_lines() draw_circles() + + ; graphics.disable_bitmap_mode() + ; test_stack.test() + repeat { } } diff --git a/examples/line-circle-txt.p8 b/examples/line-circle-txt.p8 index 2783562d6..64f3cc8db 100644 --- a/examples/line-circle-txt.p8 +++ b/examples/line-circle-txt.p8 @@ -1,5 +1,6 @@ %import textio %import syslib +%import test_stack %zeropage basicsafe ; Note: this program is compatible with C64 and CX16. @@ -40,6 +41,8 @@ main { rect(10, 10, 10, 10, false) rect(6, 0, 16, 20, true) + ; test_stack.test() + sub rect(ubyte x1, ubyte y1, ubyte x2, ubyte y2, ubyte fill) { ubyte x diff --git a/examples/mandelbrot-gfx.p8 b/examples/mandelbrot-gfx.p8 index 27a88e49a..d0cc253bf 100644 --- a/examples/mandelbrot-gfx.p8 +++ b/examples/mandelbrot-gfx.p8 @@ -1,5 +1,6 @@ %import graphics %import floats +%import test_stack %zeropage floatsafe ; Draw a mandelbrot in graphics mode (the image will be 256 x 200 pixels). @@ -44,6 +45,8 @@ main { } } + ; test_stack.test() + repeat { } } diff --git a/examples/mandelbrot.p8 b/examples/mandelbrot.p8 index 50fd45f95..983be7a50 100644 --- a/examples/mandelbrot.p8 +++ b/examples/mandelbrot.p8 @@ -1,5 +1,6 @@ %import textio %import floats +%import test_stack %zeropage basicsafe ; Note: this program is compatible with C64 and CX16. @@ -57,5 +58,7 @@ main { txt.print("finished in ") floats.print_f(duration) txt.print(" seconds!\n") + + ; test_stack.test() } } diff --git a/examples/numbergame.p8 b/examples/numbergame.p8 index eee717b11..61e6621df 100644 --- a/examples/numbergame.p8 +++ b/examples/numbergame.p8 @@ -1,5 +1,6 @@ %import textio %import conv +%import test_stack %zeropage basicsafe ; The classic number guessing game. @@ -59,6 +60,8 @@ main { txt.print("Thanks for playing, ") txt.print(name) txt.print(".\n") + + ; test_stack.test() } } } diff --git a/examples/plasma.p8 b/examples/plasma.p8 index 81d9dc0ed..44044db22 100644 --- a/examples/plasma.p8 +++ b/examples/plasma.p8 @@ -1,5 +1,6 @@ %target c64 %import syslib +%import test_stack %import textio ; converted from plasma test program for cc65. @@ -26,7 +27,7 @@ main { ; ubyte v = c64.VMCSB c64.CIA2PRA = (block & $FC) | (lsb(SCREEN1 >> 14) ^ $03) - repeat { + repeat 100 { doplasma(SCREEN1) c64.VMCSB = PAGE1 doplasma(SCREEN2) @@ -37,6 +38,9 @@ main { ;c64.VMCSB = v ;c64.CIA2PRA = block ;txt.print("done!\n") + ;test_stack.test() + ;repeat { + ;} } ; several variables outside of doplasma to make them retain their value diff --git a/examples/primes.p8 b/examples/primes.p8 index 91a95e0ac..dacad844e 100644 --- a/examples/primes.p8 +++ b/examples/primes.p8 @@ -1,4 +1,5 @@ %import textio +%import test_stack %zeropage basicsafe ; Note: this program is compatible with C64 and CX16. @@ -26,6 +27,8 @@ main { txt.print("number of primes (expected 54): ") txt.print_ub(amount) txt.chrout('\n') + + ; test_stack.test() } diff --git a/examples/sorting.p8 b/examples/sorting.p8 index ef9d86f0e..c7d67d2e6 100644 --- a/examples/sorting.p8 +++ b/examples/sorting.p8 @@ -1,4 +1,5 @@ %import textio +%import test_stack %zeropage basicsafe ; Note: this program is compatible with C64 and CX16. @@ -31,6 +32,7 @@ main { txt.print("reversed\n") print_arrays() + ;test_stack.test() return diff --git a/examples/tehtriz.p8 b/examples/tehtriz.p8 index 908af1601..8e021aeda 100644 --- a/examples/tehtriz.p8 +++ b/examples/tehtriz.p8 @@ -10,6 +10,7 @@ %target c64 %import syslib %import textio +%import test_stack main { @@ -67,6 +68,9 @@ waitkey: } drawScore() + + ; txt.plot(0,0) + ; test_stack.test() } ubyte key=c64.GETIN() diff --git a/examples/testforloops.p8 b/examples/testforloops.p8 index 0d907a13a..79fb0b48f 100644 --- a/examples/testforloops.p8 +++ b/examples/testforloops.p8 @@ -1,4 +1,5 @@ %import textio +%import test_stack %zeropage basicsafe ; Note: this program is compatible with C64 and CX16. @@ -963,6 +964,9 @@ main { txt.print("ok\n") else txt.print("fail!!!\n") + + + test_stack.test() } sub wait_input() { diff --git a/examples/textelite.p8 b/examples/textelite.p8 index 31e48c16e..71a79494b 100644 --- a/examples/textelite.p8 +++ b/examples/textelite.p8 @@ -1,6 +1,7 @@ %import textio %import conv %import diskio +%import test_stack %option no_sysinit %zeropage basicsafe @@ -26,6 +27,8 @@ main { planet.display(false) repeat { + ; test_stack.test() + str input = "????????" txt.print("\nCash: ") util.print_10s(ship.cash) diff --git a/examples/turtle-gfx.p8 b/examples/turtle-gfx.p8 index 688eadbed..08a038069 100644 --- a/examples/turtle-gfx.p8 +++ b/examples/turtle-gfx.p8 @@ -1,6 +1,7 @@ %target c64 %import floats %import graphics +%import test_stack %zeropage floatsafe main { @@ -18,6 +19,8 @@ main { turtle.rt(94) } + ; test_stack.test() + repeat { } }