diff --git a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt index fd7c5f359..3b302aa63 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt @@ -240,16 +240,28 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge } } DataType.UWORD -> { - if(amount<=2) - repeat(amount) { asmgen.out(" lsr $ESTACK_HI_PLUS1_HEX,x | ror $ESTACK_LO_PLUS1_HEX,x") } - else - asmgen.out(" jsr math.shift_right_uw_$amount") // 3-7 (8+ is done via other optimizations) + if (amount<=2) repeat(amount) { asmgen.out(" lsr $ESTACK_HI_PLUS1_HEX,x | ror $ESTACK_LO_PLUS1_HEX,x") } + else { + var left = amount + while(left>=7) { + asmgen.out(" jsr math.shift_right_uw_7") + left -= 7 + } + if(left>0) + asmgen.out(" jsr math.shift_right_uw_$left") + } } DataType.WORD -> { - if(amount<=2) - repeat(amount) { asmgen.out(" lda $ESTACK_HI_PLUS1_HEX,x | asl a | ror $ESTACK_HI_PLUS1_HEX,x | ror $ESTACK_LO_PLUS1_HEX,x") } - else - asmgen.out(" jsr math.shift_right_w_$amount") // 3-7 (8+ is done via other optimizations) + if (amount<=2) repeat(amount) { asmgen.out(" lda $ESTACK_HI_PLUS1_HEX,x | asl a | ror $ESTACK_HI_PLUS1_HEX,x | ror $ESTACK_LO_PLUS1_HEX,x") } + else { + var left=amount + while(left>=7) { + asmgen.out(" jsr math.shift_right_w_7") + left -= 7 + } + if(left>0) + asmgen.out(" jsr math.shift_right_w_$left") + } } else -> throw AssemblyError("weird type") } @@ -269,10 +281,15 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge } } else { - if(amount<=2) { - repeat(amount) { asmgen.out(" asl $ESTACK_LO_PLUS1_HEX,x | rol $ESTACK_HI_PLUS1_HEX,x") } - } else { - asmgen.out(" jsr math.shift_left_w_$amount") // 3-7 (8+ is done via other optimizations) + if (amount<=2) repeat(amount) { asmgen.out(" asl $ESTACK_LO_PLUS1_HEX,x | rol $ESTACK_HI_PLUS1_HEX,x") } + else { + var left=amount + while(left>=7) { + asmgen.out(" jsr math.shift_left_w_7") + left -= 7 + } + if(left > 0) + asmgen.out(" jsr math.shift_left_w_$left") } } return diff --git a/examples/cube3d-sprites.p8 b/examples/cube3d-sprites.p8 index 069b692b3..59771ab42 100644 --- a/examples/cube3d-sprites.p8 +++ b/examples/cube3d-sprites.p8 @@ -1,8 +1,6 @@ %import c64lib %import c64utils -; TODO fix compiler errors when compiling without optimizations - spritedata $2000 { ; this memory block contains the sprite data