From 97b8cb748de9801cb1fcee57ab6e09e7207b5d7d Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 25 Oct 2024 22:52:26 +0200 Subject: [PATCH] more ifexpression codegen tweaks --- .../src/prog8/codegen/cpu6502/IfElseAsmGen.kt | 27 ++++++++++++++++++ compiler/res/prog8lib/cx16/bmx.p8 | 1 + examples/test.p8 | 28 +++++++++---------- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/IfElseAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/IfElseAsmGen.kt index aa65714cb..78e4d9f82 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/IfElseAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/IfElseAsmGen.kt @@ -417,6 +417,33 @@ internal class IfElseAsmGen(private val program: PtProgram, } } + if(constValue!=0) { + // TODO reuse more code from regular if statements. Need a shared routine like isWordExprEqualNumber() ? + when(condition.operator) { + "==" -> { + // if w==number + asmgen.assignExpressionToRegister(condition.left, RegisterOrPair.AY, signed) + asmgen.out(""" + cmp #<$constValue + bne $falseLabel + cpy #>$constValue + bne $falseLabel""") + return + } + "!=" -> { + // if w!=number + asmgen.assignExpressionToRegister(condition.left, RegisterOrPair.AY, signed) + asmgen.out(""" + cmp #<$constValue + bne + + cpy #>$constValue + beq $falseLabel ++""") + return + } + } + } + // TODO don't store condition as expression result but just use the flags, like a normal PtIfElse translation does assignConditionValueToRegisterAndTest(condition) asmgen.out(" beq $falseLabel") diff --git a/compiler/res/prog8lib/cx16/bmx.p8 b/compiler/res/prog8lib/cx16/bmx.p8 index bdac5c13b..fa13cb2cf 100644 --- a/compiler/res/prog8lib/cx16/bmx.p8 +++ b/compiler/res/prog8lib/cx16/bmx.p8 @@ -1,4 +1,5 @@ ; Routines to load and save "BMX" files (commander X16 bitmap format) Version 1. +; Bitmap data is loaded directly into VRAM without intermediary buffering. ; Only uncompressed images are supported for now. ; BMX Specification: https://cx16forum.com/forum/viewtopic.php?t=6945 diff --git a/examples/test.p8 b/examples/test.p8 index c40a607cc..5a634e714 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -5,21 +5,19 @@ main { sub start() { - byte @shared ww = -99 - ww++ - - if ww&1 ==0 - txt.print("x ") - - if ww&64 ==0 - txt.print("a ") - - if ww&128!=0 - txt.print("neg ") - - txt.print_ub(if ww & 64==0 111 else 222) - txt.spc() - txt.print_ub(if ww & 128!=0 111 else 222) + word @shared ww = 11111 + txt.print_ub(if ww==11111 111 else 222) txt.spc() + txt.print_ub(if ww!=11111 111 else 222) + txt.nl() + + if ww==11111 + txt.print("one\n") + else + txt.print("two\n") + if ww!=11111 + txt.print("one\n") + else + txt.print("two\n") } }