From fc38be63767f4fd0f49592b51d5ebaebb979f0e1 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 12 Oct 2025 01:44:16 +0200 Subject: [PATCH] fix a const long value hex asm mistake, fix conv.str_l(0) empty output --- .../src/prog8/codegen/cpu6502/AsmGen.kt | 8 ++++---- compiler/res/prog8lib/conv.p8 | 4 ++++ docs/source/todo.rst | 2 ++ examples/test.p8 | 19 ++++++++++++------- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index 79cff3325..252d1f774 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -870,13 +870,13 @@ class AsmGen6502Internal ( when(target.kind) { TargetStorageKind.VARIABLE -> { out(""" - lda #${hex.substring(6,8)} + lda #$${hex.substring(6,8)} sta ${target.asmVarname} - lda #${hex.substring(4, 6)} + lda #$${hex.substring(4, 6)} sta ${target.asmVarname}+1 - lda #${hex.substring(2, 4)} + lda #$${hex.substring(2, 4)} sta ${target.asmVarname}+2 - lda #${hex.take(2)} + lda #$${hex.take(2)} sta ${target.asmVarname}+3""") } TargetStorageKind.ARRAY -> TODO("assign long to array ${target.position}") diff --git a/compiler/res/prog8lib/conv.p8 b/compiler/res/prog8lib/conv.p8 index 28ca57904..ab2d2f33a 100644 --- a/compiler/res/prog8lib/conv.p8 +++ b/compiler/res/prog8lib/conv.p8 @@ -269,6 +269,10 @@ sub str_l (long value) -> str { bne + inx bne - ++ cpx #10 ; just all 0? keep one + bne + + dex + + ; x points at the rightmost leading 0 lda negative beq + diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 1083fecc1..c7d3dadc9 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,6 +1,8 @@ TODO ==== +fix crash for txt.print_l(conv.str_l(0)) + STRUCTS and TYPED POINTERS -------------------------- diff --git a/examples/test.p8 b/examples/test.p8 index 6897f2a93..9926c9231 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,12 +3,17 @@ main { sub start() { - long lv1, lv2, lv3 - - lv1 = 999999 - lv2 = 555555 - lv3 = 222222 - lv1 = lv2-(lv3*2) - txt.print_l(lv1) + txt.print_l(0) + txt.nl() + txt.print(conv.str_l(0)) +; long lv1, lv2, lv3 +; +; lv1 = 999999 +; lv2 = 555555 +; lv3 = 222222 +; lv1 = lv2-(lv3 | $2222) +; txt.print_l(lv1) +; txt.spc() +; txt.print_ulhex(lv1, true) } }