From f1d55c688ad4a6075c6cc7dab4d30784290671dc Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 22 Dec 2020 00:59:07 +0100 Subject: [PATCH] cx16 registers should come first in subroutine arg list --- compiler/res/prog8lib/cx16/syslib.p8 | 9 +- compiler/src/prog8/ast/base/Base.kt | 5 ++ .../src/prog8/ast/processing/AstChecker.kt | 8 ++ .../target/c64/codegen/FunctionCallAsmGen.kt | 3 +- examples/cx16/imageviewer/bmp_module.p8 | 6 +- examples/cx16/imageviewer/pcx_module.p8 | 12 ++- examples/test.p8 | 82 +++++++++++++++++-- 7 files changed, 106 insertions(+), 19 deletions(-) diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index d737fc31f..3ad4b972a 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -222,14 +222,15 @@ romsub $ff08 = FB_get_pixels(uword pointer @R0, uword count @R1) clobbers(A,X,Y romsub $ff0b = FB_set_pixel(ubyte color @A) clobbers(A,X,Y) romsub $ff0e = FB_set_pixels(uword pointer @R0, uword count @R1) clobbers(A,X,Y) romsub $ff11 = FB_set_8_pixels(ubyte pattern @A, ubyte color @X) clobbers(A,X,Y) -romsub $ff14 = FB_set_8_pixels_opaque(ubyte mask @A, ubyte color1 @X, ubyte color2 @Y, ubyte pattern @R0) clobbers(A,X,Y) -romsub $ff17 = FB_fill_pixels(ubyte color @A, uword count @R0, uword pstep @R1) clobbers(A,X,Y) +romsub $ff14 = FB_set_8_pixels_opaque(ubyte pattern @R0, ubyte mask @A, ubyte color1 @X, ubyte color2 @Y) clobbers(A,X,Y) +romsub $ff14 = FB_set_8_pixels_opaque_OLD(ubyte mask @A, ubyte color1 @X, ubyte color2 @Y) clobbers(A,X,Y) ; TODO WEG!!!! +romsub $ff17 = FB_fill_pixels(uword count @R0, uword pstep @R1, ubyte color @A) clobbers(A,X,Y) romsub $ff1a = FB_filter_pixels(uword pointer @ R0, uword count @R1) clobbers(A,X,Y) romsub $ff1d = FB_move_pixels(uword sx @R0, uword sy @R1, uword tx @R2, uword ty @R3, uword count @R4) clobbers(A,X,Y) ; misc -romsub $fef0 = sprite_set_image(ubyte number @A, ubyte width @X, ubyte height @Y, uword pixels @R0, uword mask @R1, ubyte bpp @R2, ubyte apply_mask @Pc) clobbers(A,X,Y) -> ubyte @Pc -romsub $fef3 = sprite_set_position(ubyte number @A, uword x @R0, uword y @R1) clobbers(A,X,Y) +romsub $fef0 = sprite_set_image(uword pixels @R0, uword mask @R1, ubyte bpp @R2, ubyte number @A, ubyte width @X, ubyte height @Y, ubyte apply_mask @Pc) clobbers(A,X,Y) -> ubyte @Pc +romsub $fef3 = sprite_set_position(uword x @R0, uword y @R1, ubyte number @A) clobbers(A,X,Y) romsub $fee4 = memory_fill(uword address @R0, uword num_bytes @R1, ubyte value @A) clobbers(A,X,Y) romsub $fee7 = memory_copy(uword source @R0, uword target @R1, uword num_bytes @R2) clobbers(A,X,Y) romsub $feea = memory_crc(uword address @R0, uword num_bytes @R1) clobbers(A,X,Y) -> uword @R2 diff --git a/compiler/src/prog8/ast/base/Base.kt b/compiler/src/prog8/ast/base/Base.kt index f0a636192..d3c21f4e2 100644 --- a/compiler/src/prog8/ast/base/Base.kt +++ b/compiler/src/prog8/ast/base/Base.kt @@ -151,6 +151,11 @@ val ElementArrayTypes = mapOf( DataType.UWORD to DataType.ARRAY_UW, DataType.FLOAT to DataType.ARRAY_F ) +val Cx16VirtualRegisters = setOf(RegisterOrPair.R0, RegisterOrPair.R1, RegisterOrPair.R2, RegisterOrPair.R3, + RegisterOrPair.R4, RegisterOrPair.R5, RegisterOrPair.R6, RegisterOrPair.R7, + RegisterOrPair.R8, RegisterOrPair.R9, RegisterOrPair.R10, RegisterOrPair.R11, + RegisterOrPair.R12, RegisterOrPair.R13, RegisterOrPair.R14, RegisterOrPair.R15) + // find the parent node of a specific type or interface // (useful to figure out in what namespace/block something is defined, etc) diff --git a/compiler/src/prog8/ast/processing/AstChecker.kt b/compiler/src/prog8/ast/processing/AstChecker.kt index 18e8ca627..22418d681 100644 --- a/compiler/src/prog8/ast/processing/AstChecker.kt +++ b/compiler/src/prog8/ast/processing/AstChecker.kt @@ -336,6 +336,14 @@ internal class AstChecker(private val program: Program, if(carryParameter!=null && carryParameter !== subroutine.asmParameterRegisters.last()) err("carry parameter has to come last") + val cx16virtualRegParameters = subroutine.asmParameterRegisters.withIndex().filter { it.value.registerOrPair in Cx16VirtualRegisters } + if(cx16virtualRegParameters.isNotEmpty()) { + for(elt in cx16virtualRegParameters.withIndex()) { + if(elt.index != elt.value.index) + err("cx16 virtual register parameters have to be specified first") + } + } + } else { // Pass-by-reference datatypes can not occur as parameters to a subroutine directly // Instead, their reference (address) should be passed (as an UWORD). diff --git a/compiler/src/prog8/compiler/target/c64/codegen/FunctionCallAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/FunctionCallAsmGen.kt index 78212e7f2..61f66ae2d 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/FunctionCallAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/FunctionCallAsmGen.kt @@ -113,8 +113,7 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg argi.value.second.registerOrPair == RegisterOrPair.Y -> { asmgen.out(" ldy P8ESTACK_LO+${argi.index},x") } - argi.value.second.registerOrPair in setOf(RegisterOrPair.R0, RegisterOrPair.R1, RegisterOrPair.R2, RegisterOrPair.R3, RegisterOrPair.R4, RegisterOrPair.R5, RegisterOrPair.R6, RegisterOrPair.R7, - RegisterOrPair.R8, RegisterOrPair.R9, RegisterOrPair.R10, RegisterOrPair.R11, RegisterOrPair.R12, RegisterOrPair.R13, RegisterOrPair.R14, RegisterOrPair.R15) -> { + argi.value.second.registerOrPair in Cx16VirtualRegisters -> { asmgen.out(""" lda P8ESTACK_LO+${argi.index},x sta cx16.${argi.value.second.registerOrPair.toString().toLowerCase()} diff --git a/examples/cx16/imageviewer/bmp_module.p8 b/examples/cx16/imageviewer/bmp_module.p8 index d59e97c3f..2fc6d8bb5 100644 --- a/examples/cx16/imageviewer/bmp_module.p8 +++ b/examples/cx16/imageviewer/bmp_module.p8 @@ -104,8 +104,10 @@ bmp_module { } } 1 -> { - for x in 0 to width-1 step 8 - cx16.FB_set_8_pixels_opaque(255, 255, 0, c64.CHRIN()) + for x in 0 to width-1 step 8 { + cx16.r0 = c64.CHRIN() + cx16.FB_set_8_pixels_opaque_OLD(255, 255, 0) ; TODO update + } } } diff --git a/examples/cx16/imageviewer/pcx_module.p8 b/examples/cx16/imageviewer/pcx_module.p8 index f78fb63a3..97d39773b 100644 --- a/examples/cx16/imageviewer/pcx_module.p8 +++ b/examples/cx16/imageviewer/pcx_module.p8 @@ -100,13 +100,17 @@ bitmap { b &= %00111111 ubyte dat = c64.CHRIN() repeat b { - if y_ok - cx16.FB_set_8_pixels_opaque(255, 255, 0, dat) + if y_ok { + cx16.r0 = dat + cx16.FB_set_8_pixels_opaque_OLD(255, 255, 0) ; TODO update + } px += 8 } } else { - if y_ok - cx16.FB_set_8_pixels_opaque(255, 255, 0, b) + if y_ok { + cx16.r0 = b + cx16.FB_set_8_pixels_opaque_OLD(255, 255, 0) ; TODO update + } px += 8 } if px==width diff --git a/examples/test.p8 b/examples/test.p8 index 88b39658f..4edba6d6d 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,16 +1,84 @@ %import textio -%import diskio -%import floats -%import graphics +;%import diskio +;%import floats +;%import graphics %zeropage basicsafe %import test_stack %option no_sysinit main { - sub start () { - float fl - fl = log2(10) - floats.print_f(fl) + ;romsub $ff14 = FB_set_8_pixels_opaque(ubyte pattern @R0, ubyte mask @A, ubyte color1 @X, ubyte color2 @Y) clobbers(A,X,Y) + ;romsub $ff14 = FB_set_8_pixels_opaque_OLD(ubyte mask @A, ubyte color1 @X, ubyte color2 @Y) clobbers(A,X,Y) + + asmsub set_8_pixels_opaque(ubyte pattern @R0, ubyte mask @A, ubyte color1 @X, ubyte color2 @Y) clobbers(A,X,Y) { + + %asm {{ + sta _a + stx _x + sty _y + + lda _a + jsr txt.print_ub + lda #13 + jsr c64.CHROUT + lda _x + jsr txt.print_ub + lda #13 + jsr c64.CHROUT + lda _y + jsr txt.print_ub + lda #13 + jsr c64.CHROUT + lda cx16.r0 + ldy cx16.r0+1 + jsr txt.print_uw + lda #13 + jsr c64.CHROUT + rts + +_a .byte 0 +_x .byte 0 +_y .byte 0 + }} + } + + asmsub set_8_pixels_opaque_OLD(ubyte mask @A, ubyte color1 @X, ubyte color2 @Y) clobbers(A,X,Y) { + %asm {{ + sta _a + stx _x + sty _y + + lda _a + jsr txt.print_ub + lda #13 + jsr c64.CHROUT + lda _x + jsr txt.print_ub + lda #13 + jsr c64.CHROUT + lda _y + jsr txt.print_ub + lda #13 + jsr c64.CHROUT + rts + +_a .byte 0 +_x .byte 0 +_y .byte 0 + }} + } + + sub start () { +; cx16.r0 = 65535 +; set_8_pixels_opaque_OLD(111,222,33) +; txt.chrout('\n') + ubyte bb = 44 + set_8_pixels_opaque(bb,111,222,33) + txt.chrout('\n') + set_8_pixels_opaque(c64.CHRIN(),111,222,33) + txt.chrout('\n') + + test_stack.test() } }