reg_x removal: math.asm and some others

This commit is contained in:
Irmen de Jong 2020-09-13 20:38:50 +02:00
parent 9938959026
commit ea8b7ab193
7 changed files with 27 additions and 18 deletions

View File

@ -3,6 +3,8 @@
FL_ONE_const .byte 129 ; 1.0 FL_ONE_const .byte 129 ; 1.0
FL_ZERO_const .byte 0,0,0,0,0 ; 0.0 FL_ZERO_const .byte 0,0,0,0,0 ; 0.0
floats_store_reg .byte 0 ; temp storage
ub2float .proc ub2float .proc
; -- convert ubyte in SCRATCH_ZPB1 to float at address A/Y ; -- convert ubyte in SCRATCH_ZPB1 to float at address A/Y

View File

@ -194,7 +194,7 @@ asmsub GETADRAY () clobbers(X) -> uword @ AY {
sub print_f (float value) { sub print_f (float value) {
; ---- prints the floating point value (without a newline). ; ---- prints the floating point value (without a newline).
%asm {{ %asm {{
stx P8ZP_SCRATCH_REG_X stx floats_store_reg
lda #<value lda #<value
ldy #>value ldy #>value
jsr MOVFM ; load float into fac1 jsr MOVFM ; load float into fac1
@ -207,7 +207,7 @@ sub print_f (float value) {
jsr c64.CHROUT jsr c64.CHROUT
iny iny
bne - bne -
ldx P8ZP_SCRATCH_REG_X ldx floats_store_reg
+ rts + rts
}} }}
} }

View File

@ -299,8 +299,8 @@ _irq_handler_init
sta IRQ_SCRATCH_ZPB1 sta IRQ_SCRATCH_ZPB1
lda P8ZP_SCRATCH_REG lda P8ZP_SCRATCH_REG
sta IRQ_SCRATCH_ZPREG sta IRQ_SCRATCH_ZPREG
lda P8ZP_SCRATCH_REG_X lda P8ZP_SCRATCH_REG_X ; TODO remove REG_X
sta IRQ_SCRATCH_ZPREGX sta IRQ_SCRATCH_ZPREGX ; TODO remove this storage byte
lda P8ZP_SCRATCH_W1 lda P8ZP_SCRATCH_W1
sta IRQ_SCRATCH_ZPWORD1 sta IRQ_SCRATCH_ZPWORD1
lda P8ZP_SCRATCH_W1+1 lda P8ZP_SCRATCH_W1+1
@ -325,8 +325,8 @@ _irq_handler_end
sta P8ZP_SCRATCH_B1 sta P8ZP_SCRATCH_B1
lda IRQ_SCRATCH_ZPREG lda IRQ_SCRATCH_ZPREG
sta P8ZP_SCRATCH_REG sta P8ZP_SCRATCH_REG
lda IRQ_SCRATCH_ZPREGX lda IRQ_SCRATCH_ZPREGX ; TODO remove this storage location
sta P8ZP_SCRATCH_REG_X sta P8ZP_SCRATCH_REG_X ; TODO remove _REG_X
lda IRQ_SCRATCH_ZPWORD1 lda IRQ_SCRATCH_ZPWORD1
sta P8ZP_SCRATCH_W1 sta P8ZP_SCRATCH_W1
lda IRQ_SCRATCH_ZPWORD1+1 lda IRQ_SCRATCH_ZPWORD1+1

View File

@ -213,7 +213,7 @@ asmsub byte2decimal (byte value @ A) -> ubyte @ Y, ubyte @ A, ubyte @ X {
asmsub ubyte2hex (ubyte value @ A) -> ubyte @ A, ubyte @ Y { 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) ; ---- A to hex petscii string in AY (first hex char in A, second hex char in Y)
%asm {{ %asm {{
stx P8ZP_SCRATCH_REG_X stx P8ZP_SCRATCH_REG
pha pha
and #$0f and #$0f
tax tax
@ -225,7 +225,7 @@ asmsub ubyte2hex (ubyte value @ A) -> ubyte @ A, ubyte @ Y {
lsr a lsr a
tax tax
lda _hex_digits,x lda _hex_digits,x
ldx P8ZP_SCRATCH_REG_X ldx P8ZP_SCRATCH_REG
rts rts
_hex_digits .text "0123456789abcdef" ; can probably be reused for other stuff as well _hex_digits .text "0123456789abcdef" ; can probably be reused for other stuff as well

View File

@ -130,7 +130,7 @@ asmsub GETADRAY () clobbers(X) -> uword @ AY {
sub print_f (float value) { sub print_f (float value) {
; ---- prints the floating point value (without a newline). ; ---- prints the floating point value (without a newline).
%asm {{ %asm {{
stx P8ZP_SCRATCH_REG_X phx
lda #<value lda #<value
ldy #>value ldy #>value
jsr MOVFM ; load float into fac1 jsr MOVFM ; load float into fac1
@ -143,7 +143,7 @@ sub print_f (float value) {
jsr c64.CHROUT jsr c64.CHROUT
iny iny
bne - bne -
ldx P8ZP_SCRATCH_REG_X plx
+ rts + rts
}} }}
} }

View File

@ -11,6 +11,10 @@
; http://codebase64.org/doku.php?id=base:6502_6510_maths ; http://codebase64.org/doku.php?id=base:6502_6510_maths
; ;
math_store_reg .byte 0 ; temporary storage
multiply_bytes .proc multiply_bytes .proc
; -- multiply 2 bytes A and Y, result as byte in A (signed or unsigned) ; -- multiply 2 bytes A and Y, result as byte in A (signed or unsigned)
sta P8ZP_SCRATCH_B1 ; num1 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) ; -- multiply 2 bytes A and Y, result as word in A/Y (unsigned)
sta P8ZP_SCRATCH_B1 sta P8ZP_SCRATCH_B1
sty P8ZP_SCRATCH_REG sty P8ZP_SCRATCH_REG
stx P8ZP_SCRATCH_REG_X stx math_store_reg
lda #0 lda #0
ldx #8 ldx #8
lsr P8ZP_SCRATCH_B1 lsr P8ZP_SCRATCH_B1
@ -44,7 +48,7 @@ multiply_bytes_16 .proc
bne - bne -
tay tay
lda P8ZP_SCRATCH_B1 lda P8ZP_SCRATCH_B1
ldx P8ZP_SCRATCH_REG_X ldx math_store_reg
rts rts
.pend .pend
@ -57,7 +61,7 @@ multiply_words .proc
sta P8ZP_SCRATCH_W2 sta P8ZP_SCRATCH_W2
sty P8ZP_SCRATCH_W2+1 sty P8ZP_SCRATCH_W2+1
stx P8ZP_SCRATCH_REG_X stx P8ZP_SCRATCH_REG
mult16 lda #0 mult16 lda #0
sta result+2 ; clear upper bits of product sta result+2 ; clear upper bits of product
@ -79,7 +83,7 @@ mult16 lda #0
ror result ror result
dex dex
bne - bne -
ldx P8ZP_SCRATCH_REG_X ldx P8ZP_SCRATCH_REG
rts rts
result .byte 0,0,0,0 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 ; division by zero will result in quotient = 255 and remainder = original number
sty P8ZP_SCRATCH_REG sty P8ZP_SCRATCH_REG
sta P8ZP_SCRATCH_B1 sta P8ZP_SCRATCH_B1
stx P8ZP_SCRATCH_REG_X stx math_store_reg
lda #0 lda #0
ldx #8 ldx #8
@ -137,7 +141,7 @@ divmod_ub_asm .proc
dex dex
bne - bne -
ldy P8ZP_SCRATCH_B1 ldy P8ZP_SCRATCH_B1
ldx P8ZP_SCRATCH_REG_X ldx math_store_reg
rts rts
.pend .pend
@ -197,7 +201,7 @@ result = dividend ;save memory by reusing divident to store the result
sta _divisor sta _divisor
sty _divisor+1 sty _divisor+1
stx P8ZP_SCRATCH_REG_X stx P8ZP_SCRATCH_REG
lda #0 ;preset remainder to 0 lda #0 ;preset remainder to 0
sta remainder sta remainder
sta remainder+1 sta remainder+1
@ -224,7 +228,7 @@ result = dividend ;save memory by reusing divident to store the result
lda result lda result
ldy result+1 ldy result+1
ldx P8ZP_SCRATCH_REG_X ldx P8ZP_SCRATCH_REG
rts rts
_divisor .word 0 _divisor .word 0
.pend .pend

View File

@ -3,6 +3,9 @@
%import cx16flt %import cx16flt
%zeropage basicsafe %zeropage basicsafe
; TODO fix this, only black squares output...
main { main {
const uword width = 60 const uword width = 60
const uword height = 50 const uword height = 50