From 950bc4b9379bc58ae41473b451cd02a561733c12 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 21 Dec 2020 21:04:29 +0100 Subject: [PATCH] cx16 virtual registers R0-R15 also available on C64 target (although in a different location in memory) --- compiler/res/prog8lib/c64/syslib.p8 | 27 ++++++++++++++ compiler/res/prog8lib/cx16/graphics.p8 | 36 +++++++------------ compiler/res/prog8lib/cx16/syslib.p8 | 1 + .../target/c64/C64MachineDefinition.kt | 1 - .../target/cx16/CX16MachineDefinition.kt | 1 - examples/test.p8 | 28 +++++++++++++-- 6 files changed, 67 insertions(+), 27 deletions(-) diff --git a/compiler/res/prog8lib/c64/syslib.p8 b/compiler/res/prog8lib/c64/syslib.p8 index 68de2dac7..b9101ca41 100644 --- a/compiler/res/prog8lib/c64/syslib.p8 +++ b/compiler/res/prog8lib/c64/syslib.p8 @@ -462,3 +462,30 @@ _raster_irq_handler } + + +cx16 { + + ; the sixteen virtual 16-bit registers that the CX16 has defined in the zeropage + ; they are simulated on the C64 as well but their location in memory is different + ; (because there's no room for them in the zeropage) + ; they are allocated at the bottom of the eval-stack (should be ample space unless + ; you're doing insane nesting of expressions...) + &uword r0 = $cf00 + &uword r1 = $cf02 + &uword r2 = $cf04 + &uword r3 = $cf06 + &uword r4 = $cf08 + &uword r5 = $cf0a + &uword r6 = $cf0c + &uword r7 = $cf0e + &uword r8 = $cf10 + &uword r9 = $cf12 + &uword r10 = $cf14 + &uword r11 = $cf16 + &uword r12 = $cf18 + &uword r13 = $cf1a + &uword r14 = $cf1c + &uword r15 = $cf1e + +} diff --git a/compiler/res/prog8lib/cx16/graphics.p8 b/compiler/res/prog8lib/cx16/graphics.p8 index ded477762..b9269b468 100644 --- a/compiler/res/prog8lib/cx16/graphics.p8 +++ b/compiler/res/prog8lib/cx16/graphics.p8 @@ -48,31 +48,31 @@ graphics { while xx>=yy { cx16.r0 = xcenter + xx cx16.r1 = ycenter + yy - cx16.FB_cursor_position() + cx16.FB_cursor_position2() cx16.FB_set_pixel(1) cx16.r0 = xcenter - xx - cx16.FB_cursor_position() + cx16.FB_cursor_position2() cx16.FB_set_pixel(1) cx16.r0 = xcenter + xx cx16.r1 = ycenter - yy - cx16.FB_cursor_position() + cx16.FB_cursor_position2() cx16.FB_set_pixel(1) cx16.r0 = xcenter - xx - cx16.FB_cursor_position() + cx16.FB_cursor_position2() cx16.FB_set_pixel(1) cx16.r0 = xcenter + yy cx16.r1 = ycenter + xx - cx16.FB_cursor_position() + cx16.FB_cursor_position2() cx16.FB_set_pixel(1) cx16.r0 = xcenter - yy - cx16.FB_cursor_position() + cx16.FB_cursor_position2() cx16.FB_set_pixel(1) cx16.r0 = xcenter + yy cx16.r1 = ycenter - xx - cx16.FB_cursor_position() + cx16.FB_cursor_position2() cx16.FB_set_pixel(1) cx16.r0 = xcenter - yy - cx16.FB_cursor_position() + cx16.FB_cursor_position2() cx16.FB_set_pixel(1) yy++ if decisionOver2<=0 { @@ -102,27 +102,19 @@ graphics { ubyte ycenter_min_xx = ycenter - xx uword @zp plotx - cx16.r0 = xcenter-xx - cx16.r1 = ycenter_plus_yy - cx16.FB_cursor_position() + cx16.FB_cursor_position(xcenter-xx, ycenter_plus_yy) repeat xx*2+1 cx16.FB_set_pixel(1) - cx16.r0 = xcenter-xx - cx16.r1 = ycenter_min_yy - cx16.FB_cursor_position() + cx16.FB_cursor_position(xcenter-xx, ycenter_min_yy) repeat xx*2+1 cx16.FB_set_pixel(1) - cx16.r0 = xcenter-yy - cx16.r1 = ycenter_plus_xx - cx16.FB_cursor_position() + cx16.FB_cursor_position(xcenter-yy, ycenter_plus_xx) repeat yy*2+1 cx16.FB_set_pixel(1) - cx16.r0 = xcenter-yy - cx16.r1 = ycenter_min_xx - cx16.FB_cursor_position() + cx16.FB_cursor_position(xcenter-yy, ycenter_min_xx) repeat yy*2+1 cx16.FB_set_pixel(1) @@ -137,9 +129,7 @@ graphics { } sub plot(uword plotx, ubyte ploty) { - cx16.r0 = plotx - cx16.r1 = ploty - cx16.FB_cursor_position() + cx16.FB_cursor_position(plotx, ploty) cx16.FB_set_pixel(1) } } diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index e55bb0404..d737fc31f 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -215,6 +215,7 @@ romsub $fef6 = FB_init() clobbers(A,X,Y) romsub $fef9 = FB_get_info() clobbers(X,Y) -> byte @A, uword @R0, uword @R1 ; width=r0, height=r1 romsub $fefc = FB_set_palette(uword pointer @R0, ubyte index @A, ubyte bytecount @X) clobbers(A,X,Y) romsub $feff = FB_cursor_position(uword x @R0, uword y @R1) clobbers(A,X,Y) +romsub $feff = FB_cursor_position2() clobbers(A,X,Y) ; alias for the previous routine, but avoiding having to respecify both x and y every time romsub $ff02 = FB_cursor_next_line(uword x @R0) clobbers(A,X,Y) romsub $ff05 = FB_get_pixel() clobbers(X,Y) -> ubyte @A romsub $ff08 = FB_get_pixels(uword pointer @R0, uword count @R1) clobbers(A,X,Y) diff --git a/compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt b/compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt index 3e57d3f9a..82ac78050 100644 --- a/compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt +++ b/compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt @@ -24,7 +24,6 @@ internal object C64MachineDefinition: IMachineDefinition { override val RAW_LOAD_ADDRESS = 0xc000 // the 2*256 byte evaluation stack (on which bytes, words, and even floats are stored during calculations) - // and some heavily used string constants derived from the two values above override val ESTACK_LO = 0xce00 // $ce00-$ceff inclusive override val ESTACK_HI = 0xcf00 // $ce00-$ceff inclusive diff --git a/compiler/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt b/compiler/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt index 51e7e60fc..fa999b7d2 100644 --- a/compiler/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt +++ b/compiler/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt @@ -21,7 +21,6 @@ internal object CX16MachineDefinition: IMachineDefinition { override val RAW_LOAD_ADDRESS = 0x8000 // the 2*256 byte evaluation stack (on which bytes, words, and even floats are stored during calculations) - // and some heavily used string constants derived from the two values above override val ESTACK_LO = 0x0400 // $0400-$04ff inclusive override val ESTACK_HI = 0x0500 // $0500-$05ff inclusive diff --git a/examples/test.p8 b/examples/test.p8 index c90ab3bdc..fcab98cfe 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -8,9 +8,33 @@ main { - romsub $ff2c = GRAPH_draw_line(uword x1 @R0, uword y1 @R1, uword x2 @R2, uword y2 @R3) clobbers(A,X,Y) ; uses x1=r0, y1=r1, x2=r2, y2=r3 + asmsub GRAPH_draw_line(uword x1 @R0, uword y1 @R1, uword x2 @R2, uword y2 @R3) clobbers(A,X,Y) { + %asm {{ + lda cx16.r0 + ldy cx16.r0+1 + jsr txt.print_uw + lda #13 + jsr c64.CHROUT + lda cx16.r1 + ldy cx16.r1+1 + jsr txt.print_uw + lda #13 + jsr c64.CHROUT + lda cx16.r2 + ldy cx16.r2+1 + jsr txt.print_uw + lda #13 + jsr c64.CHROUT + lda cx16.r3 + ldy cx16.r3+1 + jsr txt.print_uw + lda #13 + jsr c64.CHROUT + rts + }} + } sub start () { - GRAPH_draw_line(1,2,3,4) + GRAPH_draw_line(1111,2222,3333,4444) ; TODO allocate R0-R15 for the C64 as well (at the bottom of the eval stack hi at $cf00) } }