From ea8b7ab1935981bf5919cd161dbe9e0103d42c80 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 13 Sep 2020 20:38:50 +0200 Subject: [PATCH] reg_x removal: math.asm and some others --- compiler/res/prog8lib/c64floats.asm | 2 ++ compiler/res/prog8lib/c64flt.p8 | 4 ++-- compiler/res/prog8lib/c64lib.p8 | 8 ++++---- compiler/res/prog8lib/conv.p8 | 4 ++-- compiler/res/prog8lib/cx16flt.p8 | 4 ++-- compiler/res/prog8lib/math.asm | 20 ++++++++++++-------- examples/cx16/mandelbrot.p8 | 3 +++ 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/compiler/res/prog8lib/c64floats.asm b/compiler/res/prog8lib/c64floats.asm index 5d0f501e7..28364e1c5 100644 --- a/compiler/res/prog8lib/c64floats.asm +++ b/compiler/res/prog8lib/c64floats.asm @@ -3,6 +3,8 @@ FL_ONE_const .byte 129 ; 1.0 FL_ZERO_const .byte 0,0,0,0,0 ; 0.0 +floats_store_reg .byte 0 ; temp storage + ub2float .proc ; -- convert ubyte in SCRATCH_ZPB1 to float at address A/Y diff --git a/compiler/res/prog8lib/c64flt.p8 b/compiler/res/prog8lib/c64flt.p8 index 8850a333f..7b15cd7ae 100644 --- a/compiler/res/prog8lib/c64flt.p8 +++ b/compiler/res/prog8lib/c64flt.p8 @@ -194,7 +194,7 @@ asmsub GETADRAY () clobbers(X) -> uword @ AY { sub print_f (float value) { ; ---- prints the floating point value (without a newline). %asm {{ - stx P8ZP_SCRATCH_REG_X + stx floats_store_reg lda #value jsr MOVFM ; load float into fac1 @@ -207,7 +207,7 @@ sub print_f (float value) { jsr c64.CHROUT iny bne - - ldx P8ZP_SCRATCH_REG_X + ldx floats_store_reg + rts }} } diff --git a/compiler/res/prog8lib/c64lib.p8 b/compiler/res/prog8lib/c64lib.p8 index 879e30cf2..1101348c4 100644 --- a/compiler/res/prog8lib/c64lib.p8 +++ b/compiler/res/prog8lib/c64lib.p8 @@ -299,8 +299,8 @@ _irq_handler_init sta IRQ_SCRATCH_ZPB1 lda P8ZP_SCRATCH_REG sta IRQ_SCRATCH_ZPREG - lda P8ZP_SCRATCH_REG_X - sta IRQ_SCRATCH_ZPREGX + lda P8ZP_SCRATCH_REG_X ; TODO remove REG_X + sta IRQ_SCRATCH_ZPREGX ; TODO remove this storage byte lda P8ZP_SCRATCH_W1 sta IRQ_SCRATCH_ZPWORD1 lda P8ZP_SCRATCH_W1+1 @@ -325,8 +325,8 @@ _irq_handler_end sta P8ZP_SCRATCH_B1 lda IRQ_SCRATCH_ZPREG sta P8ZP_SCRATCH_REG - lda IRQ_SCRATCH_ZPREGX - sta P8ZP_SCRATCH_REG_X + lda IRQ_SCRATCH_ZPREGX ; TODO remove this storage location + sta P8ZP_SCRATCH_REG_X ; TODO remove _REG_X lda IRQ_SCRATCH_ZPWORD1 sta P8ZP_SCRATCH_W1 lda IRQ_SCRATCH_ZPWORD1+1 diff --git a/compiler/res/prog8lib/conv.p8 b/compiler/res/prog8lib/conv.p8 index 1c147c75e..8318e7f86 100644 --- a/compiler/res/prog8lib/conv.p8 +++ b/compiler/res/prog8lib/conv.p8 @@ -213,7 +213,7 @@ asmsub byte2decimal (byte value @ A) -> ubyte @ Y, ubyte @ A, ubyte @ X { asmsub ubyte2hex (ubyte value @ A) -> ubyte @ A, ubyte @ Y { ; ---- A to hex petscii string in AY (first hex char in A, second hex char in Y) %asm {{ - stx P8ZP_SCRATCH_REG_X + stx P8ZP_SCRATCH_REG pha and #$0f tax @@ -225,7 +225,7 @@ asmsub ubyte2hex (ubyte value @ A) -> ubyte @ A, ubyte @ Y { lsr a tax lda _hex_digits,x - ldx P8ZP_SCRATCH_REG_X + ldx P8ZP_SCRATCH_REG rts _hex_digits .text "0123456789abcdef" ; can probably be reused for other stuff as well diff --git a/compiler/res/prog8lib/cx16flt.p8 b/compiler/res/prog8lib/cx16flt.p8 index 3a43abb42..e8f2bfddb 100644 --- a/compiler/res/prog8lib/cx16flt.p8 +++ b/compiler/res/prog8lib/cx16flt.p8 @@ -130,7 +130,7 @@ asmsub GETADRAY () clobbers(X) -> uword @ AY { sub print_f (float value) { ; ---- prints the floating point value (without a newline). %asm {{ - stx P8ZP_SCRATCH_REG_X + phx lda #value jsr MOVFM ; load float into fac1 @@ -143,7 +143,7 @@ sub print_f (float value) { jsr c64.CHROUT iny bne - - ldx P8ZP_SCRATCH_REG_X + plx + rts }} } diff --git a/compiler/res/prog8lib/math.asm b/compiler/res/prog8lib/math.asm index 0a202670f..4de7e2efa 100644 --- a/compiler/res/prog8lib/math.asm +++ b/compiler/res/prog8lib/math.asm @@ -11,6 +11,10 @@ ; http://codebase64.org/doku.php?id=base:6502_6510_maths ; + +math_store_reg .byte 0 ; temporary storage + + multiply_bytes .proc ; -- multiply 2 bytes A and Y, result as byte in A (signed or unsigned) sta P8ZP_SCRATCH_B1 ; num1 @@ -31,7 +35,7 @@ multiply_bytes_16 .proc ; -- multiply 2 bytes A and Y, result as word in A/Y (unsigned) sta P8ZP_SCRATCH_B1 sty P8ZP_SCRATCH_REG - stx P8ZP_SCRATCH_REG_X + stx math_store_reg lda #0 ldx #8 lsr P8ZP_SCRATCH_B1 @@ -44,7 +48,7 @@ multiply_bytes_16 .proc bne - tay lda P8ZP_SCRATCH_B1 - ldx P8ZP_SCRATCH_REG_X + ldx math_store_reg rts .pend @@ -57,7 +61,7 @@ multiply_words .proc sta P8ZP_SCRATCH_W2 sty P8ZP_SCRATCH_W2+1 - stx P8ZP_SCRATCH_REG_X + stx P8ZP_SCRATCH_REG mult16 lda #0 sta result+2 ; clear upper bits of product @@ -79,7 +83,7 @@ mult16 lda #0 ror result dex bne - - ldx P8ZP_SCRATCH_REG_X + ldx P8ZP_SCRATCH_REG rts result .byte 0,0,0,0 @@ -124,7 +128,7 @@ divmod_ub_asm .proc ; division by zero will result in quotient = 255 and remainder = original number sty P8ZP_SCRATCH_REG sta P8ZP_SCRATCH_B1 - stx P8ZP_SCRATCH_REG_X + stx math_store_reg lda #0 ldx #8 @@ -137,7 +141,7 @@ divmod_ub_asm .proc dex bne - ldy P8ZP_SCRATCH_B1 - ldx P8ZP_SCRATCH_REG_X + ldx math_store_reg rts .pend @@ -197,7 +201,7 @@ result = dividend ;save memory by reusing divident to store the result sta _divisor sty _divisor+1 - stx P8ZP_SCRATCH_REG_X + stx P8ZP_SCRATCH_REG lda #0 ;preset remainder to 0 sta remainder sta remainder+1 @@ -224,7 +228,7 @@ result = dividend ;save memory by reusing divident to store the result lda result ldy result+1 - ldx P8ZP_SCRATCH_REG_X + ldx P8ZP_SCRATCH_REG rts _divisor .word 0 .pend diff --git a/examples/cx16/mandelbrot.p8 b/examples/cx16/mandelbrot.p8 index b51210825..49f04fd06 100644 --- a/examples/cx16/mandelbrot.p8 +++ b/examples/cx16/mandelbrot.p8 @@ -3,6 +3,9 @@ %import cx16flt %zeropage basicsafe +; TODO fix this, only black squares output... + + main { const uword width = 60 const uword height = 50