From 51d708bbdd1b311c521190083167fc0fb536f59a Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 12 Mar 2024 23:27:15 +0100 Subject: [PATCH] fix monogfx issue --- compiler/res/prog8lib/cx16/monogfx.p8 | 2 - compiler/res/prog8lib/virtual/monogfx.p8 | 2 +- compiler/src/prog8/compiler/Compiler.kt | 14 +-- docs/source/todo.rst | 2 + examples/test.p8 | 146 +++++------------------ 5 files changed, 37 insertions(+), 129 deletions(-) diff --git a/compiler/res/prog8lib/cx16/monogfx.p8 b/compiler/res/prog8lib/cx16/monogfx.p8 index f0b588ec3..c21c691d9 100644 --- a/compiler/res/prog8lib/cx16/monogfx.p8 +++ b/compiler/res/prog8lib/cx16/monogfx.p8 @@ -7,8 +7,6 @@ ; NOTE: a lot of the code here is similar or the same to that in gfx2 ; NOTE: For sake of speed, NO BOUNDS CHECKING is performed in most routines! ; You'll have to make sure yourself that you're not writing outside of bitmap boundaries! -; -; TODO: implement invert mode for horizontal lines (will fix disc and fillrect as well) monogfx { diff --git a/compiler/res/prog8lib/virtual/monogfx.p8 b/compiler/res/prog8lib/virtual/monogfx.p8 index da442d795..dd229d798 100644 --- a/compiler/res/prog8lib/virtual/monogfx.p8 +++ b/compiler/res/prog8lib/virtual/monogfx.p8 @@ -409,7 +409,7 @@ monogfx { dy = stack_dy[cx16.r12L] yy+=dy } - cx16.r11L = pget(xx as uword, yy as uword) ; old_color + cx16.r11L = pget(xx as uword, yy as uword) as ubyte ; old_color if cx16.r11L == cx16.r10L return if xx<0 or xx>width-1 or yy<0 or yy>height-1 diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index f4bf2b883..ac1991f94 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -56,8 +56,6 @@ class CompilerArguments(val filepath: Path, fun compileProgram(args: CompilerArguments): CompilationResult? { - lateinit var program: Program - lateinit var importedFiles: List val compTarget = when(args.compilationTarget) { @@ -72,10 +70,12 @@ fun compileProgram(args: CompilerArguments): CompilationResult? { var compilationOptions: CompilationOptions var ast: PtProgram? = null + var resultingProgram: Program? = null + var importedFiles: List = emptyList() try { val totalTime = measureTimeMillis { - val (programresult, options, imported) = parseMainModule(args.filepath, args.errors, compTarget, args.sourceDirs) + val (program, options, imported) = parseMainModule(args.filepath, args.errors, compTarget, args.sourceDirs) compilationOptions = options with(compilationOptions) { @@ -96,7 +96,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? { symbolDefs = args.symbolDefs strictBool = args.strictBool } - program = programresult + resultingProgram = program importedFiles = imported processAst(program, args.errors, compilationOptions) @@ -164,16 +164,16 @@ fun compileProgram(args: CompilerArguments): CompilationResult? { System.err.flush() val seconds = totalTime/1000.0 println("\nTotal compilation+assemble time: ${round(seconds*100.0)/100.0} sec.") - return CompilationResult(program, ast, compilationOptions, importedFiles) + return CompilationResult(resultingProgram!!, ast, compilationOptions, importedFiles) } catch (px: ParseError) { System.out.flush() System.err.print("\n\u001b[91m") // bright red System.err.println("${px.position.toClickableStr()} parse error: ${px.message}".trim()) System.err.print("\u001b[0m") // reset } catch (ac: ErrorsReportedException) { - if(args.printAst1) { + if(args.printAst1 && resultingProgram!=null) { println("\n*********** COMPILER AST *************") - printProgram(program) + printProgram(resultingProgram!!) println("*********** COMPILER AST END *************\n") } if (args.printAst2) { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index ebb95291c..e8ea637fd 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,6 +1,8 @@ TODO ==== +fix containment check is currently not supported inside complex expressions + ... diff --git a/examples/test.p8 b/examples/test.p8 index bda9df96b..3cbc66110 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,127 +1,35 @@ -%import textio -%option no_sysinit -%zeropage basicsafe +%import math +%import monogfx main { sub start() { - uword @shared ref = $2000 - ref[5]=10 - txt.print_ub(ref[5]) - txt.spc() - ref[5]-- - txt.print_ub(ref[5]) - txt.spc() - ref[5]++ - txt.print_ub(ref[5]) - txt.nl() - ref[5]-=2 - txt.print_ub(ref[5]) - txt.spc() - ref[5]+=2 - txt.print_ub(ref[5]) - txt.nl() - ref[5]-=3 - txt.print_ub(ref[5]) - txt.spc() - ref[5]+=3 - txt.print_ub(ref[5]) - txt.nl() + monogfx.lores() + monogfx.drawmode(monogfx.MODE_INVERT) + + uword x1, x2 + uword y1, y2 + + repeat 200 { + x1 = math.rnd() + y1 = math.rnd() % 240 + x2 = math.rnd() + y2 = math.rnd() % 240 + monogfx.line(x1, y1, x2, y2, true) + } + + repeat 5 { + for cx16.r9L in 0 to 200 { + monogfx.vertical_line(cx16.r9L, 10, 200, true) + } + } - ubyte[] array = [1,2,3,4,5,10] - array[5]=10 - txt.print_ub(array[5]) - txt.spc() - array[5]-- - txt.print_ub(array[5]) - txt.spc() - array[5]++ - txt.print_ub(array[5]) - txt.nl() - array[5]-=2 - txt.print_ub(array[5]) - txt.spc() - array[5]+=2 - txt.print_ub(array[5]) - txt.nl() - array[5]-=3 - txt.print_ub(array[5]) - txt.spc() - array[5]+=3 - txt.print_ub(array[5]) - txt.nl() - - -; cx16.r0L = 5 -; ref[cx16.r0L]=10 -; txt.print_ub(ref[cx16.r0L]) -; txt.spc() -; ref[cx16.r0L]-- -; txt.print_ub(ref[cx16.r0L]) -; txt.spc() -; ref[cx16.r0L]++ -; txt.print_ub(ref[cx16.r0L]) -; txt.nl() -; -; uword @shared uw = 1000 -; word @shared sw = -1000 -; -; txt.print_uw(uw) -; txt.spc() -; uw++ -; txt.print_uw(uw) -; txt.spc() -; uw-- -; txt.print_uw(uw) -; txt.nl() -; uw = $00ff -; txt.print_uw(uw) -; txt.spc() -; uw++ -; txt.print_uw(uw) -; txt.spc() -; uw-- -; txt.print_uw(uw) -; txt.nl() -; -; txt.print_w(sw) -; txt.spc() -; sw++ -; txt.print_w(sw) -; txt.spc() -; sw-- -; txt.print_w(sw) -; txt.nl() -; sw = $00ff -; txt.print_w(sw) -; txt.spc() -; sw++ -; txt.print_w(sw) -; txt.spc() -; sw-- -; txt.print_w(sw) -; txt.nl() -; sw = -257 -; txt.print_w(sw) -; txt.spc() -; sw++ -; txt.print_w(sw) -; txt.spc() -; sw-- -; txt.print_w(sw) -; txt.nl() - - /* - seekerRef[SKR_X]-- this code looks very wrong with the pha/pla stuff - bulletRef[BD_Y]--/++ - enemyRef[EN_MOVE_CNT]--/++ - - signed word--/++ - unsigned word--/++ - - attackRef+=FIELD_COUNT - -*/ + monogfx.disc(160, 120, 100, true) + monogfx.fillrect(20, 100, 280, 50, true) + monogfx.drawmode(monogfx.MODE_STIPPLE) + monogfx.fillrect(80, 10, 50, 220, true) + repeat { + } } }