diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt index cb7cb02b7..9cbacffb0 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt @@ -1944,11 +1944,9 @@ internal class AssignmentAsmGen(private val program: PtProgram, when(target.kind) { TargetStorageKind.VARIABLE -> { asmgen.out(""" - stx P8ZP_SCRATCH_REG ldx #<${target.asmVarname} ldy #>${target.asmVarname} jsr floats.MOVMF - ldx P8ZP_SCRATCH_REG """) } TargetStorageKind.ARRAY -> { diff --git a/compiler/res/prog8lib/atari/textio.p8 b/compiler/res/prog8lib/atari/textio.p8 index 0a1e56d63..bae6c50bf 100644 --- a/compiler/res/prog8lib/atari/textio.p8 +++ b/compiler/res/prog8lib/atari/textio.p8 @@ -153,10 +153,9 @@ asmsub print (str text @ AY) clobbers(A,Y) { }} } -asmsub print_ub0 (ubyte value @ A) clobbers(A,Y) { +asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) { ; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total) %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.ubyte2decimal pha tya @@ -164,16 +163,13 @@ asmsub print_ub0 (ubyte value @ A) clobbers(A,Y) { pla jsr chrout txa - jsr chrout - ldx P8ZP_SCRATCH_REG - rts + jmp chrout }} } -asmsub print_ub (ubyte value @ A) clobbers(A,Y) { +asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) { ; ---- print the ubyte in A in decimal form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.ubyte2decimal _print_byte_digits pha @@ -189,16 +185,13 @@ _print_byte_digits beq _ones jsr chrout _ones txa - jsr chrout - ldx P8ZP_SCRATCH_REG - rts + jmp chrout }} } -asmsub print_b (byte value @ A) clobbers(A,Y) { +asmsub print_b (byte value @ A) clobbers(A,X,Y) { ; ---- print the byte in A in decimal form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG pha cmp #0 bpl + @@ -210,10 +203,9 @@ asmsub print_b (byte value @ A) clobbers(A,Y) { }} } -asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well) %asm {{ - stx P8ZP_SCRATCH_REG bcc + pha lda #'$' @@ -222,16 +214,13 @@ asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { + jsr conv.ubyte2hex jsr chrout tya - jsr chrout - ldx P8ZP_SCRATCH_REG - rts + jmp chrout }} } -asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the ubyte in A in binary form (if Carry is set, a radix prefix '%' is printed as well) %asm {{ - stx P8ZP_SCRATCH_REG sta P8ZP_SCRATCH_B1 bcc + lda #'%' @@ -244,12 +233,11 @@ asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { + jsr chrout dey bne - - ldx P8ZP_SCRATCH_REG rts }} } -asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the uword in A/Y in binary form (if Carry is set, a radix prefix '%' is printed as well) %asm {{ pha @@ -261,7 +249,7 @@ asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { }} } -asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the uword in A/Y in hexadecimal form (4 digits) ; (if Carry is set, a radix prefix '$' is printed as well) %asm {{ @@ -274,10 +262,9 @@ asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { }} } -asmsub print_uw0 (uword value @ AY) clobbers(A,Y) { +asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) { ; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total) %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.uword2decimal ldy #0 - lda conv.uword2decimal.decTenThousands,y @@ -285,17 +272,14 @@ asmsub print_uw0 (uword value @ AY) clobbers(A,Y) { jsr chrout iny bne - -+ ldx P8ZP_SCRATCH_REG - rts ++ rts }} } -asmsub print_uw (uword value @ AY) clobbers(A,Y) { +asmsub print_uw (uword value @ AY) clobbers(A,X,Y) { ; ---- print the uword in A/Y in decimal form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.uword2decimal - ldx P8ZP_SCRATCH_REG ldy #0 - lda conv.uword2decimal.decTenThousands,y beq _allzero @@ -316,7 +300,7 @@ _allzero }} } -asmsub print_w (word value @ AY) clobbers(A,Y) { +asmsub print_w (word value @ AY) clobbers(A,X,Y) { ; ---- print the (signed) word in A/Y in decimal form, without left padding 0's %asm {{ cpy #0 @@ -388,7 +372,7 @@ sub setcc (ubyte column, ubyte row, ubyte char, ubyte charcolor) { }} } -asmsub plot (ubyte col @ Y, ubyte row @ A) clobbers(A) { +asmsub plot (ubyte col @ Y, ubyte row @ A) { ; ---- set cursor at specific position ; TODO %asm {{ diff --git a/compiler/res/prog8lib/c128/syslib.p8 b/compiler/res/prog8lib/c128/syslib.p8 index fcada06c7..28a5822ed 100644 --- a/compiler/res/prog8lib/c128/syslib.p8 +++ b/compiler/res/prog8lib/c128/syslib.p8 @@ -104,34 +104,26 @@ romsub $FFF3 = IOBASE() -> uword @ XY ; read base addr ; ---- utilities ----- -asmsub STOP2() -> ubyte @A { +asmsub STOP2() clobbers(X) -> ubyte @A { ; -- check if STOP key was pressed, returns true if so. More convenient to use than STOP() because that only sets the carry status flag. %asm {{ - txa - pha jsr cbm.STOP beq + - pla - tax lda #0 rts -+ pla - tax - lda #1 ++ lda #1 rts }} } -asmsub RDTIM16() -> uword @AY { +asmsub RDTIM16() clobbers(X) -> uword @AY { ; -- like RDTIM() but only returning the lower 16 bits in AY for convenience %asm {{ - stx P8ZP_SCRATCH_REG jsr cbm.RDTIM pha txa tay pla - ldx P8ZP_SCRATCH_REG rts }} } diff --git a/compiler/res/prog8lib/c128/textio.p8 b/compiler/res/prog8lib/c128/textio.p8 index 5552f6e3e..c8cc8585c 100644 --- a/compiler/res/prog8lib/c128/textio.p8 +++ b/compiler/res/prog8lib/c128/textio.p8 @@ -97,13 +97,12 @@ sub uppercase() { c128.VM1 &= ~2 } -asmsub scroll_left (bool alsocolors @ Pc) clobbers(A, Y) { +asmsub scroll_left (bool alsocolors @ Pc) clobbers(A, X, Y) { ; ---- scroll the whole screen 1 character to the left ; contents of the rightmost column are unchanged, you should clear/refill this yourself ; Carry flag determines if screen color data must be scrolled too %asm {{ - stx P8ZP_SCRATCH_REG bcc _scroll_screen + ; scroll the screen and the color memory @@ -133,17 +132,15 @@ _scroll_screen ; scroll only the screen memory dey bpl - - ldx P8ZP_SCRATCH_REG rts }} } -asmsub scroll_right (bool alsocolors @ Pc) clobbers(A) { +asmsub scroll_right (bool alsocolors @ Pc) clobbers(A,X) { ; ---- scroll the whole screen 1 character to the right ; contents of the leftmost column are unchanged, you should clear/refill this yourself ; Carry flag determines if screen color data must be scrolled too %asm {{ - stx P8ZP_SCRATCH_REG bcc _scroll_screen + ; scroll the screen and the color memory @@ -169,17 +166,15 @@ _scroll_screen ; scroll only the screen memory dex bpl - - ldx P8ZP_SCRATCH_REG rts }} } -asmsub scroll_up (bool alsocolors @ Pc) clobbers(A) { +asmsub scroll_up (bool alsocolors @ Pc) clobbers(A,X) { ; ---- scroll the whole screen 1 character up ; contents of the bottom row are unchanged, you should refill/clear this yourself ; Carry flag determines if screen color data must be scrolled too %asm {{ - stx P8ZP_SCRATCH_REG bcc _scroll_screen + ; scroll the screen and the color memory @@ -205,17 +200,15 @@ _scroll_screen ; scroll only the screen memory dex bpl - - ldx P8ZP_SCRATCH_REG rts }} } -asmsub scroll_down (bool alsocolors @ Pc) clobbers(A) { +asmsub scroll_down (bool alsocolors @ Pc) clobbers(A,X) { ; ---- scroll the whole screen 1 character down ; contents of the top row are unchanged, you should refill/clear this yourself ; Carry flag determines if screen color data must be scrolled too %asm {{ - stx P8ZP_SCRATCH_REG bcc _scroll_screen + ; scroll the screen and the color memory @@ -241,7 +234,6 @@ _scroll_screen ; scroll only the screen memory dex bpl - - ldx P8ZP_SCRATCH_REG rts }} } @@ -266,10 +258,9 @@ asmsub print (str text @ AY) clobbers(A,Y) { }} } -asmsub print_ub0 (ubyte value @ A) clobbers(A,Y) { +asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) { ; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total) %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.ubyte2decimal pha tya @@ -277,16 +268,13 @@ asmsub print_ub0 (ubyte value @ A) clobbers(A,Y) { pla jsr cbm.CHROUT txa - jsr cbm.CHROUT - ldx P8ZP_SCRATCH_REG - rts + jmp cbm.CHROUT }} } -asmsub print_ub (ubyte value @ A) clobbers(A,Y) { +asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) { ; ---- print the ubyte in A in decimal form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.ubyte2decimal _print_byte_digits pha @@ -302,16 +290,13 @@ _print_byte_digits beq _ones jsr cbm.CHROUT _ones txa - jsr cbm.CHROUT - ldx P8ZP_SCRATCH_REG - rts + jmp cbm.CHROUT }} } -asmsub print_b (byte value @ A) clobbers(A,Y) { +asmsub print_b (byte value @ A) clobbers(A,X,Y) { ; ---- print the byte in A in decimal form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG pha cmp #0 bpl + @@ -323,10 +308,9 @@ asmsub print_b (byte value @ A) clobbers(A,Y) { }} } -asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well) %asm {{ - stx P8ZP_SCRATCH_REG bcc + pha lda #'$' @@ -335,16 +319,13 @@ asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { + jsr conv.ubyte2hex jsr cbm.CHROUT tya - jsr cbm.CHROUT - ldx P8ZP_SCRATCH_REG - rts + jmp cbm.CHROUT }} } -asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the ubyte in A in binary form (if Carry is set, a radix prefix '%' is printed as well) %asm {{ - stx P8ZP_SCRATCH_REG sta P8ZP_SCRATCH_B1 bcc + lda #'%' @@ -357,12 +338,11 @@ asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { + jsr cbm.CHROUT dey bne - - ldx P8ZP_SCRATCH_REG rts }} } -asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the uword in A/Y in binary form (if Carry is set, a radix prefix '%' is printed as well) %asm {{ pha @@ -374,7 +354,7 @@ asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { }} } -asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the uword in A/Y in hexadecimal form (4 digits) ; (if Carry is set, a radix prefix '$' is printed as well) %asm {{ @@ -387,10 +367,9 @@ asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { }} } -asmsub print_uw0 (uword value @ AY) clobbers(A,Y) { +asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) { ; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total) %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.uword2decimal ldy #0 - lda conv.uword2decimal.decTenThousands,y @@ -398,17 +377,14 @@ asmsub print_uw0 (uword value @ AY) clobbers(A,Y) { jsr cbm.CHROUT iny bne - -+ ldx P8ZP_SCRATCH_REG - rts ++ rts }} } -asmsub print_uw (uword value @ AY) clobbers(A,Y) { +asmsub print_uw (uword value @ AY) clobbers(A,X,Y) { ; ---- print the uword in A/Y in decimal form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.uword2decimal - ldx P8ZP_SCRATCH_REG ldy #0 - lda conv.uword2decimal.decTenThousands,y beq _allzero @@ -429,7 +405,7 @@ _allzero }} } -asmsub print_w (word value @ AY) clobbers(A,Y) { +asmsub print_w (word value @ AY) clobbers(A,X,Y) { ; ---- print the (signed) word in A/Y in decimal form, without left padding 0's %asm {{ cpy #0 @@ -583,15 +559,10 @@ _colormod sta $ffff ; modified }} } -asmsub plot (ubyte col @ Y, ubyte row @ A) clobbers(A) { - ; ---- safe wrapper around PLOT kernal routine, to save the X register. +asmsub plot (ubyte col @ Y, ubyte row @ X) { %asm {{ - stx P8ZP_SCRATCH_REG - tax clc - jsr cbm.PLOT - ldx P8ZP_SCRATCH_REG - rts + jmp cbm.PLOT }} } diff --git a/compiler/res/prog8lib/c64/floats.asm b/compiler/res/prog8lib/c64/floats.asm index 4d0c92b03..8ee4c97d3 100644 --- a/compiler/res/prog8lib/c64/floats.asm +++ b/compiler/res/prog8lib/c64/floats.asm @@ -5,13 +5,11 @@ FL_ZERO_const .byte 0,0,0,0,0 ; 0.0 FL_LOG2_const .byte $80, $31, $72, $17, $f8 ; log(2) -floats_store_reg .byte 0 ; temp storage floats_temp_var .byte 0,0,0,0,0 ; temporary storage for a float ub2float .proc ; -- convert ubyte in SCRATCH_ZPB1 to float at address A/Y - ; clobbers A, Y - stx P8ZP_SCRATCH_REG + ; clobbers A, X, Y sta P8ZP_SCRATCH_W2 sty P8ZP_SCRATCH_W2+1 ldy P8ZP_SCRATCH_B1 @@ -19,15 +17,12 @@ ub2float .proc jsr GIVAYF _fac_to_mem ldx P8ZP_SCRATCH_W2 ldy P8ZP_SCRATCH_W2+1 - jsr MOVMF - ldx P8ZP_SCRATCH_REG - rts + jmp MOVMF .pend b2float .proc ; -- convert byte in SCRATCH_ZPB1 to float at address A/Y - ; clobbers A, Y - stx P8ZP_SCRATCH_REG + ; clobbers A, X, Y sta P8ZP_SCRATCH_W2 sty P8ZP_SCRATCH_W2+1 lda P8ZP_SCRATCH_B1 @@ -37,7 +32,7 @@ b2float .proc uw2float .proc ; -- convert uword in SCRATCH_ZPWORD1 to float at address A/Y - stx P8ZP_SCRATCH_REG + ; clobbers X sta P8ZP_SCRATCH_W2 sty P8ZP_SCRATCH_W2+1 lda P8ZP_SCRATCH_W1 @@ -48,7 +43,7 @@ uw2float .proc w2float .proc ; -- convert word in SCRATCH_ZPWORD1 to float at address A/Y - stx P8ZP_SCRATCH_REG + ; clobbers X sta P8ZP_SCRATCH_W2 sty P8ZP_SCRATCH_W2+1 ldy P8ZP_SCRATCH_W1 @@ -60,7 +55,7 @@ w2float .proc cast_from_uw .proc ; -- uword in A/Y into float var at (P8ZP_SCRATCH_W2) - stx P8ZP_SCRATCH_REG + ; clobbers X jsr GIVUAYFAY jmp ub2float._fac_to_mem .pend @@ -68,7 +63,7 @@ cast_from_uw .proc cast_from_w .proc ; -- word in A/Y into float var at (P8ZP_SCRATCH_W2) - stx P8ZP_SCRATCH_REG + ; clobbers X jsr GIVAYFAY jmp ub2float._fac_to_mem .pend @@ -76,7 +71,7 @@ cast_from_w .proc cast_from_ub .proc ; -- ubyte in Y into float var at (P8ZP_SCRATCH_W2) - stx P8ZP_SCRATCH_REG + ; clobbers X jsr FREADUY jmp ub2float._fac_to_mem .pend @@ -84,38 +79,37 @@ cast_from_ub .proc cast_from_b .proc ; -- byte in A into float var at (P8ZP_SCRATCH_W2) - stx P8ZP_SCRATCH_REG + ; clobbers X jsr FREADSA jmp ub2float._fac_to_mem .pend cast_as_uw_into_ya .proc ; also used for float 2 ub ; -- cast float at A/Y to uword into Y/A + ; clobbers X jsr MOVFM jmp cast_FAC1_as_uw_into_ya .pend cast_as_w_into_ay .proc ; also used for float 2 b ; -- cast float at A/Y to word into A/Y + ; clobbers X jsr MOVFM jmp cast_FAC1_as_w_into_ay .pend cast_FAC1_as_uw_into_ya .proc ; also used for float 2 ub ; -- cast fac1 to uword into Y/A - stx P8ZP_SCRATCH_REG - jsr GETADR ; into Y/A - ldx P8ZP_SCRATCH_REG - rts + ; clobbers X + jmp GETADR ; into Y/A .pend cast_FAC1_as_w_into_ay .proc ; also used for float 2 b ; -- cast fac1 to word into A/Y - stx P8ZP_SCRATCH_REG + ; clobbers X jsr AYINT ldy floats.AYINT_facmo lda floats.AYINT_facmo+1 - ldx P8ZP_SCRATCH_REG rts .pend @@ -145,25 +139,23 @@ copy_float .proc inc_var_f .proc ; -- add 1 to float pointed to by A/Y + ; clobbers X sta P8ZP_SCRATCH_W1 sty P8ZP_SCRATCH_W1+1 - stx P8ZP_SCRATCH_REG jsr MOVFM lda #FL_ONE_const jsr FADD ldx P8ZP_SCRATCH_W1 ldy P8ZP_SCRATCH_W1+1 - jsr MOVMF - ldx P8ZP_SCRATCH_REG - rts + jmp MOVMF .pend dec_var_f .proc ; -- subtract 1 from float pointed to by A/Y + ; clobbers X sta P8ZP_SCRATCH_W1 sty P8ZP_SCRATCH_W1+1 - stx P8ZP_SCRATCH_REG lda #FL_ONE_const jsr MOVFM @@ -172,9 +164,7 @@ dec_var_f .proc jsr FSUB ldx P8ZP_SCRATCH_W1 ldy P8ZP_SCRATCH_W1+1 - jsr MOVMF - ldx P8ZP_SCRATCH_REG - rts + jmp MOVMF .pend @@ -183,10 +173,8 @@ fmath_float2 .byte 0,0,0,0,0 ; storage for a mflpt5 value var_fac1_less_f .proc - ; -- is the float in FAC1 < the variable AY? - stx P8ZP_SCRATCH_REG + ; -- is the float in FAC1 < the variable AY? Result in A. Clobbers X. jsr FCOMP - ldx P8ZP_SCRATCH_REG cmp #255 beq + lda #0 @@ -196,10 +184,8 @@ var_fac1_less_f .proc .pend var_fac1_lesseq_f .proc - ; -- is the float in FAC1 <= the variable AY? - stx P8ZP_SCRATCH_REG + ; -- is the float in FAC1 <= the variable AY? Result in A. Clobbers X. jsr FCOMP - ldx P8ZP_SCRATCH_REG cmp #0 beq + cmp #255 @@ -211,10 +197,8 @@ var_fac1_lesseq_f .proc .pend var_fac1_greater_f .proc - ; -- is the float in FAC1 > the variable AY? - stx P8ZP_SCRATCH_REG + ; -- is the float in FAC1 > the variable AY? Result in A. Clobbers X. jsr FCOMP - ldx P8ZP_SCRATCH_REG cmp #1 beq + lda #0 @@ -224,10 +208,9 @@ var_fac1_greater_f .proc .pend var_fac1_greatereq_f .proc - ; -- is the float in FAC1 >= the variable AY? - stx P8ZP_SCRATCH_REG - jsr FCOMP ldx P8ZP_SCRATCH_REG + ; -- is the float in FAC1 >= the variable AY? Result in A. Clobbers X. + jsr FCOMP cmp #0 beq + cmp #1 @@ -239,16 +222,14 @@ var_fac1_greatereq_f .proc .pend var_fac1_notequal_f .proc - ; -- are the floats numbers in FAC1 and the variable AY *not* identical? - stx P8ZP_SCRATCH_REG + ; -- are the floats numbers in FAC1 and the variable AY *not* identical? Result in A. Clobbers X. jsr FCOMP - ldx P8ZP_SCRATCH_REG and #1 rts .pend vars_equal_f .proc - ; -- are the mflpt5 numbers in P8ZP_SCRATCH_W1 and AY identical? + ; -- are the mflpt5 numbers in P8ZP_SCRATCH_W1 and AY identical? Result in A sta P8ZP_SCRATCH_W2 sty P8ZP_SCRATCH_W2+1 ldy #0 @@ -279,13 +260,11 @@ _false lda #0 vars_less_f .proc - ; -- is float in AY < float in P8ZP_SCRATCH_W2 ? + ; -- is float in AY < float in P8ZP_SCRATCH_W2 ? Result in A. Clobbers X. jsr MOVFM lda P8ZP_SCRATCH_W2 ldy P8ZP_SCRATCH_W2+1 - stx P8ZP_SCRATCH_REG jsr FCOMP - ldx P8ZP_SCRATCH_REG cmp #255 bne + lda #1 @@ -295,13 +274,11 @@ vars_less_f .proc .pend vars_lesseq_f .proc - ; -- is float in AY <= float in P8ZP_SCRATCH_W2 ? + ; -- is float in AY <= float in P8ZP_SCRATCH_W2 ? Result in A. Clobbers X. jsr MOVFM lda P8ZP_SCRATCH_W2 ldy P8ZP_SCRATCH_W2+1 - stx P8ZP_SCRATCH_REG jsr FCOMP - ldx P8ZP_SCRATCH_REG cmp #255 bne + - lda #1 @@ -313,7 +290,7 @@ vars_lesseq_f .proc .pend less_f .proc - ; -- is f1 < f2? + ; -- is f1 < f2? Result in A. Clobbers X. jsr compare_floats cmp #255 beq compare_floats._return_true @@ -322,7 +299,7 @@ less_f .proc lesseq_f .proc - ; -- is f1 <= f2? + ; -- is f1 <= f2? Result in A. Clobbers X. jsr compare_floats cmp #255 beq compare_floats._return_true @@ -332,7 +309,7 @@ lesseq_f .proc .pend greater_f .proc - ; -- is f1 > f2? + ; -- is f1 > f2? Result in A. Clobbers X. jsr compare_floats cmp #1 beq compare_floats._return_true @@ -340,7 +317,7 @@ greater_f .proc .pend greatereq_f .proc - ; -- is f1 >= f2? + ; -- is f1 >= f2? Result in A. Clobbers X. jsr compare_floats cmp #1 beq compare_floats._return_true @@ -351,6 +328,7 @@ greatereq_f .proc set_array_float_from_fac1 .proc ; -- set the float in FAC1 in the array (index in A, array in P8ZP_SCRATCH_W1) + ; clobbers X sta P8ZP_SCRATCH_B1 asl a asl a @@ -361,11 +339,8 @@ set_array_float_from_fac1 .proc adc P8ZP_SCRATCH_W1 bcc + iny -+ stx floats_store_reg - tax - jsr MOVMF - ldx floats_store_reg - rts ++ tax + jmp MOVMF .pend diff --git a/compiler/res/prog8lib/c64/floats.p8 b/compiler/res/prog8lib/c64/floats.p8 index cd50b3381..2a544754a 100644 --- a/compiler/res/prog8lib/c64/floats.p8 +++ b/compiler/res/prog8lib/c64/floats.p8 @@ -159,12 +159,9 @@ asmsub GETADRAY () clobbers(X) -> uword @ AY { sub rndf() -> float { %asm {{ - stx P8ZP_SCRATCH_REG lda #1 jsr FREADSA - jsr RND ; rng into fac1 - ldx P8ZP_SCRATCH_REG - rts + jmp RND ; rng into fac1 }} } diff --git a/compiler/res/prog8lib/c64/floats_funcs.asm b/compiler/res/prog8lib/c64/floats_funcs.asm index 19faa85fb..a06747e77 100644 --- a/compiler/res/prog8lib/c64/floats_funcs.asm +++ b/compiler/res/prog8lib/c64/floats_funcs.asm @@ -139,17 +139,11 @@ func_all_f_stack .proc .pend func_abs_f_into_FAC1 .proc - stx P8ZP_SCRATCH_REG jsr MOVFM - jsr ABS - ldx P8ZP_SCRATCH_REG - rts + jmp ABS .pend func_sqrt_into_FAC1 .proc - stx P8ZP_SCRATCH_REG jsr MOVFM - jsr SQR - ldx P8ZP_SCRATCH_REG - rts + jmp SQR .pend diff --git a/compiler/res/prog8lib/c64/graphics.p8 b/compiler/res/prog8lib/c64/graphics.p8 index 504bd6b77..e9684c491 100644 --- a/compiler/res/prog8lib/c64/graphics.p8 +++ b/compiler/res/prog8lib/c64/graphics.p8 @@ -185,7 +185,6 @@ graphics { lda length and #7 sta separate_pixels - stx P8ZP_SCRATCH_REG lsr length+1 ror length lsr length+1 @@ -210,8 +209,7 @@ _modified stx $ffff ; modified inc _modified+2 + dey bne _modified -_zero ldx P8ZP_SCRATCH_REG - +_zero ldy separate_pixels beq hline_zero2 lda _modified+1 diff --git a/compiler/res/prog8lib/c64/syslib.p8 b/compiler/res/prog8lib/c64/syslib.p8 index 1280a1f7c..33dfafeb8 100644 --- a/compiler/res/prog8lib/c64/syslib.p8 +++ b/compiler/res/prog8lib/c64/syslib.p8 @@ -104,34 +104,26 @@ romsub $FFED = SCREEN() -> ubyte @ X, ubyte @ Y ; read number of romsub $FFF0 = PLOT(ubyte col @ Y, ubyte row @ X, bool dir @ Pc) -> ubyte @ X, ubyte @ Y ; read/set position of cursor on screen. Use txt.plot for a 'safe' wrapper that preserves X. romsub $FFF3 = IOBASE() -> uword @ XY ; read base address of I/O devices -asmsub STOP2() -> ubyte @A { +asmsub STOP2() clobbers(X) -> ubyte @A { ; -- check if STOP key was pressed, returns true if so. More convenient to use than STOP() because that only sets the carry status flag. %asm {{ - txa - pha jsr cbm.STOP beq + - pla - tax lda #0 rts -+ pla - tax - lda #1 ++ lda #1 rts }} } -asmsub RDTIM16() -> uword @AY { +asmsub RDTIM16() clobbers(X) -> uword @AY { ; -- like RDTIM() but only returning the lower 16 bits in AY for convenience %asm {{ - stx P8ZP_SCRATCH_REG jsr cbm.RDTIM pha txa tay pla - ldx P8ZP_SCRATCH_REG rts }} } diff --git a/compiler/res/prog8lib/c64/textio.p8 b/compiler/res/prog8lib/c64/textio.p8 index 0cc5544ce..cd62921e7 100644 --- a/compiler/res/prog8lib/c64/textio.p8 +++ b/compiler/res/prog8lib/c64/textio.p8 @@ -96,13 +96,12 @@ sub uppercase() { c64.VMCSB &= ~2 } -asmsub scroll_left (bool alsocolors @ Pc) clobbers(A, Y) { +asmsub scroll_left (bool alsocolors @ Pc) clobbers(A, X, Y) { ; ---- scroll the whole screen 1 character to the left ; contents of the rightmost column are unchanged, you should clear/refill this yourself ; Carry flag determines if screen color data must be scrolled too %asm {{ - stx P8ZP_SCRATCH_REG bcc _scroll_screen + ; scroll the screen and the color memory @@ -132,17 +131,15 @@ _scroll_screen ; scroll only the screen memory dey bpl - - ldx P8ZP_SCRATCH_REG rts }} } -asmsub scroll_right (bool alsocolors @ Pc) clobbers(A) { +asmsub scroll_right (bool alsocolors @ Pc) clobbers(A,X) { ; ---- scroll the whole screen 1 character to the right ; contents of the leftmost column are unchanged, you should clear/refill this yourself ; Carry flag determines if screen color data must be scrolled too %asm {{ - stx P8ZP_SCRATCH_REG bcc _scroll_screen + ; scroll the screen and the color memory @@ -168,17 +165,15 @@ _scroll_screen ; scroll only the screen memory dex bpl - - ldx P8ZP_SCRATCH_REG rts }} } -asmsub scroll_up (bool alsocolors @ Pc) clobbers(A) { +asmsub scroll_up (bool alsocolors @ Pc) clobbers(A,X) { ; ---- scroll the whole screen 1 character up ; contents of the bottom row are unchanged, you should refill/clear this yourself ; Carry flag determines if screen color data must be scrolled too %asm {{ - stx P8ZP_SCRATCH_REG bcc _scroll_screen + ; scroll the screen and the color memory @@ -204,17 +199,15 @@ _scroll_screen ; scroll only the screen memory dex bpl - - ldx P8ZP_SCRATCH_REG rts }} } -asmsub scroll_down (bool alsocolors @ Pc) clobbers(A) { +asmsub scroll_down (bool alsocolors @ Pc) clobbers(A,X) { ; ---- scroll the whole screen 1 character down ; contents of the top row are unchanged, you should refill/clear this yourself ; Carry flag determines if screen color data must be scrolled too %asm {{ - stx P8ZP_SCRATCH_REG bcc _scroll_screen + ; scroll the screen and the color memory @@ -240,7 +233,6 @@ _scroll_screen ; scroll only the screen memory dex bpl - - ldx P8ZP_SCRATCH_REG rts }} } @@ -265,10 +257,9 @@ asmsub print (str text @ AY) clobbers(A,Y) { }} } -asmsub print_ub0 (ubyte value @ A) clobbers(A,Y) { +asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) { ; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total) %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.ubyte2decimal pha tya @@ -276,16 +267,13 @@ asmsub print_ub0 (ubyte value @ A) clobbers(A,Y) { pla jsr cbm.CHROUT txa - jsr cbm.CHROUT - ldx P8ZP_SCRATCH_REG - rts + jmp cbm.CHROUT }} } -asmsub print_ub (ubyte value @ A) clobbers(A,Y) { +asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) { ; ---- print the ubyte in A in decimal form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.ubyte2decimal _print_byte_digits pha @@ -301,16 +289,13 @@ _print_byte_digits beq _ones jsr cbm.CHROUT _ones txa - jsr cbm.CHROUT - ldx P8ZP_SCRATCH_REG - rts + jmp cbm.CHROUT }} } -asmsub print_b (byte value @ A) clobbers(A,Y) { +asmsub print_b (byte value @ A) clobbers(A,X,Y) { ; ---- print the byte in A in decimal form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG pha cmp #0 bpl + @@ -322,10 +307,9 @@ asmsub print_b (byte value @ A) clobbers(A,Y) { }} } -asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well) %asm {{ - stx P8ZP_SCRATCH_REG bcc + pha lda #'$' @@ -334,16 +318,13 @@ asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { + jsr conv.ubyte2hex jsr cbm.CHROUT tya - jsr cbm.CHROUT - ldx P8ZP_SCRATCH_REG - rts + jmp cbm.CHROUT }} } -asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the ubyte in A in binary form (if Carry is set, a radix prefix '%' is printed as well) %asm {{ - stx P8ZP_SCRATCH_REG sta P8ZP_SCRATCH_B1 bcc + lda #'%' @@ -356,12 +337,11 @@ asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { + jsr cbm.CHROUT dey bne - - ldx P8ZP_SCRATCH_REG rts }} } -asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the uword in A/Y in binary form (if Carry is set, a radix prefix '%' is printed as well) %asm {{ pha @@ -373,7 +353,7 @@ asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { }} } -asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the uword in A/Y in hexadecimal form (4 digits) ; (if Carry is set, a radix prefix '$' is printed as well) %asm {{ @@ -386,10 +366,9 @@ asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { }} } -asmsub print_uw0 (uword value @ AY) clobbers(A,Y) { +asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) { ; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total) %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.uword2decimal ldy #0 - lda conv.uword2decimal.decTenThousands,y @@ -397,17 +376,14 @@ asmsub print_uw0 (uword value @ AY) clobbers(A,Y) { jsr cbm.CHROUT iny bne - -+ ldx P8ZP_SCRATCH_REG - rts ++ rts }} } -asmsub print_uw (uword value @ AY) clobbers(A,Y) { +asmsub print_uw (uword value @ AY) clobbers(A,X,Y) { ; ---- print the uword in A/Y in decimal form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.uword2decimal - ldx P8ZP_SCRATCH_REG ldy #0 - lda conv.uword2decimal.decTenThousands,y beq _allzero @@ -428,7 +404,7 @@ _allzero }} } -asmsub print_w (word value @ AY) clobbers(A,Y) { +asmsub print_w (word value @ AY) clobbers(A,X,Y) { ; ---- print the (signed) word in A/Y in decimal form, without left padding 0's %asm {{ cpy #0 @@ -582,15 +558,10 @@ _colormod sta $ffff ; modified }} } -asmsub plot (ubyte col @ Y, ubyte row @ A) clobbers(A) { - ; ---- safe wrapper around PLOT kernal routine, to save the X register. +asmsub plot (ubyte col @ Y, ubyte row @ X) { %asm {{ - stx P8ZP_SCRATCH_REG - tax clc - jsr cbm.PLOT - ldx P8ZP_SCRATCH_REG - rts + jmp cbm.PLOT }} } diff --git a/compiler/res/prog8lib/conv.p8 b/compiler/res/prog8lib/conv.p8 index 63f937b67..065e64702 100644 --- a/compiler/res/prog8lib/conv.p8 +++ b/compiler/res/prog8lib/conv.p8 @@ -8,25 +8,22 @@ conv { str @shared string_out = "????????????????" ; result buffer for the string conversion routines -asmsub str_ub0 (ubyte value @ A) clobbers(A,Y) { +asmsub str_ub0 (ubyte value @ A) clobbers(A,X,Y) { ; ---- convert the ubyte in A in decimal string form, with left padding 0s (3 positions total) %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.ubyte2decimal sty string_out sta string_out+1 stx string_out+2 lda #0 sta string_out+3 - ldx P8ZP_SCRATCH_REG rts }} } -asmsub str_ub (ubyte value @ A) clobbers(A,Y) { +asmsub str_ub (ubyte value @ A) clobbers(A,X,Y) { ; ---- convert the ubyte in A in decimal string form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG ldy #0 sty P8ZP_SCRATCH_B1 jsr conv.ubyte2decimal @@ -52,15 +49,13 @@ _output_byte_digits iny lda #0 sta string_out,y - ldx P8ZP_SCRATCH_REG rts }} } -asmsub str_b (byte value @ A) clobbers(A,Y) { +asmsub str_b (byte value @ A) clobbers(A,X,Y) { ; ---- convert the byte in A in decimal string form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG ldy #0 sty P8ZP_SCRATCH_B1 cmp #0 @@ -75,7 +70,7 @@ asmsub str_b (byte value @ A) clobbers(A,Y) { }} } -asmsub str_ubhex (ubyte value @ A) clobbers(A,Y) { +asmsub str_ubhex (ubyte value @ A) clobbers(A,X,Y) { ; ---- convert the ubyte in A in hex string form %asm {{ jsr conv.ubyte2hex @@ -87,7 +82,7 @@ asmsub str_ubhex (ubyte value @ A) clobbers(A,Y) { }} } -asmsub str_ubbin (ubyte value @ A) clobbers(A,Y) { +asmsub str_ubbin (ubyte value @ A) clobbers(A,X,Y) { ; ---- convert the ubyte in A in binary string form %asm {{ sta P8ZP_SCRATCH_B1 @@ -106,7 +101,7 @@ _digit sta string_out,y }} } -asmsub str_uwbin (uword value @ AY) clobbers(A,Y) { +asmsub str_uwbin (uword value @ AY) clobbers(A,X,Y) { ; ---- convert the uword in A/Y in binary string form %asm {{ sta P8ZP_SCRATCH_REG @@ -145,10 +140,9 @@ asmsub str_uwhex (uword value @ AY) clobbers(A,Y) { }} } -asmsub str_uw0 (uword value @ AY) clobbers(A,Y) { +asmsub str_uw0 (uword value @ AY) clobbers(A,X,Y) { ; ---- convert the uword in A/Y in decimal string form, with left padding 0s (5 positions total) %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.uword2decimal ldy #0 - lda conv.uword2decimal.decTenThousands,y @@ -156,15 +150,13 @@ asmsub str_uw0 (uword value @ AY) clobbers(A,Y) { beq + iny bne - -+ ldx P8ZP_SCRATCH_REG - rts ++ rts }} } -asmsub str_uw (uword value @ AY) clobbers(A,Y) { +asmsub str_uw (uword value @ AY) clobbers(A,X,Y) { ; ---- convert the uword in A/Y in decimal string form, without left padding 0s %asm {{ - stx P8ZP_SCRATCH_REG jsr conv.uword2decimal ldx #0 _output_digits @@ -182,7 +174,6 @@ _gotdigit sta string_out,x bne _gotdigit _end lda #0 sta string_out,x - ldx P8ZP_SCRATCH_REG rts _allzero lda #'0' @@ -192,12 +183,11 @@ _allzero lda #'0' }} } -asmsub str_w (word value @ AY) clobbers(A,Y) { +asmsub str_w (word value @ AY) clobbers(A,X,Y) { ; ---- convert the (signed) word in A/Y in decimal string form, without left padding 0's %asm {{ cpy #0 bpl str_uw - stx P8ZP_SCRATCH_REG pha lda #'-' sta string_out @@ -700,10 +690,9 @@ 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) clobbers(X) -> 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 pha and #$0f tax @@ -715,7 +704,6 @@ asmsub ubyte2hex (ubyte value @A) -> ubyte @A, ubyte @Y { lsr a tax lda _hex_digits,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/cx16/diskio.p8 b/compiler/res/prog8lib/cx16/diskio.p8 index de57f4f01..92bf58225 100644 --- a/compiler/res/prog8lib/cx16/diskio.p8 +++ b/compiler/res/prog8lib/cx16/diskio.p8 @@ -488,7 +488,6 @@ io_error: sta P8ZP_SCRATCH_W1 lda address+1 sta P8ZP_SCRATCH_W1+1 - stx P8ZP_SCRATCH_REG ldx end_address ldy end_address+1 lda headerless @@ -499,7 +498,6 @@ io_error: + lda # ubyte @A { + asmsub vload(str name @R0, ubyte bank @A, uword address @R1) clobbers(X, Y) -> ubyte @A { ; -- like the basic command VLOAD "filename",drivenumber,bank,address ; loads a file into Vera's video memory in the given bank:address, returns success in A ; the file has to have the usual 2 byte header (which will be skipped) %asm {{ clc internal_vload: - phx pha ldx drivenumber bcc + @@ -642,13 +638,12 @@ internal_vload: + jsr cbm.CLRCHN lda #1 jsr cbm.CLOSE - plx lda P8ZP_SCRATCH_B1 rts }} } - asmsub vload_raw(str name @R0, ubyte bank @A, uword address @R1) -> ubyte @A { + asmsub vload_raw(str name @R0, ubyte bank @A, uword address @R1) clobbers(X, Y) -> ubyte @A { ; -- like the basic command BVLOAD "filename",drivenumber,bank,address ; loads a file into Vera's video memory in the given bank:address, returns success in A ; the file is read fully including the first two bytes. diff --git a/compiler/res/prog8lib/cx16/floats.p8 b/compiler/res/prog8lib/cx16/floats.p8 index dfc5b5d1c..b1ef77556 100644 --- a/compiler/res/prog8lib/cx16/floats.p8 +++ b/compiler/res/prog8lib/cx16/floats.p8 @@ -99,14 +99,11 @@ asmsub FREADSA (byte value @A) clobbers(A,X,Y) { asmsub GIVUAYFAY (uword value @ AY) clobbers(A,X,Y) { ; ---- unsigned 16 bit word in A/Y (lo/hi) to fac1 %asm {{ - phx sty $c4 ; facmo ($64 on c128) sta $c5 ; facmo+1 ($65 on c128) ldx #$90 sec - jsr FLOATC - plx - rts + jmp FLOATC }} } @@ -144,11 +141,8 @@ asmsub FREADUY (ubyte value @Y) { sub rndf() -> float { %asm {{ - phx lda #1 - jsr RND_0 - plx - rts + jmp RND_0 }} } diff --git a/compiler/res/prog8lib/cx16/gfx2.p8 b/compiler/res/prog8lib/cx16/gfx2.p8 index ccdfde960..927eb5e4f 100644 --- a/compiler/res/prog8lib/cx16/gfx2.p8 +++ b/compiler/res/prog8lib/cx16/gfx2.p8 @@ -222,7 +222,6 @@ _done position(x, y) %asm {{ lda color - phx ldx length+1 beq + ldy #0 @@ -236,7 +235,7 @@ _done - sta cx16.VERA_DATA0 dey bne - -+ plx ++ }} } 6 -> { @@ -262,7 +261,6 @@ _done sta cx16.VERA_ADDR_L lda cx16.r0+1 sta cx16.VERA_ADDR_M - phx ldx x }} @@ -285,10 +283,6 @@ _done + inx ; next pixel }} } - - %asm {{ - plx - }} } } } @@ -933,13 +927,12 @@ skip: }} } - asmsub next_pixels(uword pixels @AY, uword amount @R0) clobbers(A, Y) { + asmsub next_pixels(uword pixels @AY, uword amount @R0) clobbers(A, X, Y) { ; -- sets the next bunch of pixels from a prepared array of bytes. ; for 8 bpp screens this will plot 1 pixel per byte. ; for 1 bpp screens it will plot 8 pixels at once (colors are the bit patterns per byte). ; for 2 bpp screens it will plot 4 pixels at once (colors are the bit patterns per byte). %asm {{ - phx sta P8ZP_SCRATCH_W1 sty P8ZP_SCRATCH_W1+1 ldx cx16.r0+1 @@ -961,14 +954,13 @@ skip: iny dex bne - -+ plx ++ rts }} } - asmsub set_8_pixels_from_bits(ubyte bits @R0, ubyte oncolor @A, ubyte offcolor @Y) { + asmsub set_8_pixels_from_bits(ubyte bits @R0, ubyte oncolor @A, ubyte offcolor @Y) clobbers(X) { ; this is only useful in 256 color mode where one pixel equals one byte value. %asm {{ - phx ldx #8 - asl cx16.r0 bcc + @@ -977,7 +969,6 @@ skip: + sty cx16.VERA_DATA0 + dex bne - - plx rts }} } @@ -1048,7 +1039,6 @@ skip: position(x,y) y++ %asm {{ - phx ldx color lda cx16.VERA_DATA1 sta P8ZP_SCRATCH_B1 @@ -1060,7 +1050,6 @@ skip: + lda cx16.VERA_DATA0 ; don't write a pixel, but do advance to the next address + dey bne - - plx }} } x+=8 diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index 59608c45f..873611984 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -53,25 +53,21 @@ romsub $FFF3 = IOBASE() -> uword @ XY ; read base addr ; ---- utility -asmsub STOP2() -> ubyte @A { +asmsub STOP2() clobbers(X) -> ubyte @A { ; -- check if STOP key was pressed, returns true if so. More convenient to use than STOP() because that only sets the carry status flag. %asm {{ - phx jsr cbm.STOP beq + - plx lda #0 rts -+ plx - lda #1 ++ lda #1 rts }} } -asmsub RDTIM16() -> uword @AY { +asmsub RDTIM16() clobbers(X) -> uword @AY { ; -- like RDTIM() but only returning the lower 16 bits in AY for convenience. Also avoids ram bank issue for irqs. %asm {{ - phx php sei jsr cbm.RDTIM @@ -81,7 +77,6 @@ asmsub RDTIM16() -> uword @AY { txa tay pla - plx rts }} } @@ -454,15 +449,12 @@ asmsub mouse_config2(ubyte shape @A) clobbers (A, X, Y) { }} } -asmsub mouse_pos() -> ubyte @A { +asmsub mouse_pos() clobbers(X) -> ubyte @A { ; -- short wrapper around mouse_get() kernal routine: ; -- gets the position of the mouse cursor in cx16.r0 and cx16.r1 (x/y coordinate), returns mouse button status. %asm {{ - phx ldx #cx16.r0 - jsr cx16.mouse_get - plx - rts + jmp cx16.mouse_get }} } @@ -500,7 +492,7 @@ inline asmsub getrambank() -> ubyte @A { }} } -asmsub numbanks() -> uword @AY { +asmsub numbanks() clobbers(X) -> uword @AY { ; -- Returns the number of available RAM banks according to the kernal (each bank is 8 Kb). ; Note that the number of such banks can be 256 so a word is returned. ; But just looking at the A register (the LSB of the result word) could suffice if you know that A=0 means 256 banks: @@ -508,15 +500,13 @@ asmsub numbanks() -> uword @AY { ; Kernal's MEMTOP routine reports 0 in this case but that doesn't mean 'zero banks', instead it means 256 banks, ; as there is no X16 without at least 1 page of banked RAM. So this routine returns 256 instead of 0. %asm {{ - phx sec jsr cbm.MEMTOP ldy #0 cmp #0 bne + iny -+ plx - rts ++ rts }} } @@ -974,19 +964,17 @@ asmsub set_rasterline(uword line @AY) { void cx16.i2c_write_byte($42, $05, activity) } - asmsub wait(uword jiffies @AY) { + asmsub wait(uword jiffies @AY) clobbers(X) { ; --- wait approximately the given number of jiffies (1/60th seconds) (N or N+1) ; note: the system irq handler has to be active for this to work as it depends on the system jiffy clock ; note: this routine cannot be used from inside a irq handler %asm {{ - phx sta P8ZP_SCRATCH_W1 sty P8ZP_SCRATCH_W1+1 _loop lda P8ZP_SCRATCH_W1 ora P8ZP_SCRATCH_W1+1 bne + - plx rts + sei diff --git a/compiler/res/prog8lib/cx16/textio.p8 b/compiler/res/prog8lib/cx16/textio.p8 index 3876e92c6..6eb1bb88e 100644 --- a/compiler/res/prog8lib/cx16/textio.p8 +++ b/compiler/res/prog8lib/cx16/textio.p8 @@ -42,11 +42,10 @@ asmsub column(ubyte col @A) clobbers(A, X, Y) { }} } -asmsub fill_screen (ubyte char @ A, ubyte color @ Y) clobbers(A) { +asmsub fill_screen (ubyte char @ A, ubyte color @ Y) clobbers(A, X) { ; ---- fill the character screen with the given fill character and character color. %asm {{ sty _ly+1 - phx pha jsr cbm.SCREEN ; get dimensions in X/Y txa @@ -75,8 +74,7 @@ _ly ldy #1 ; modified stz cx16.VERA_ADDR_L inc cx16.VERA_ADDR_M ; next line bra _lx -+ plx - rts ++ rts set_vera_textmatrix_addresses: stz cx16.VERA_CTRL @@ -90,11 +88,10 @@ set_vera_textmatrix_addresses: }} } -asmsub clear_screenchars (ubyte char @ A) clobbers(Y) { +asmsub clear_screenchars (ubyte char @ A) clobbers(X, Y) { ; ---- clear the character screen with the given fill character (leaves colors) ; (assumes screen matrix is at the default address) %asm {{ - phx pha jsr cbm.SCREEN ; get dimensions in X/Y txa @@ -116,16 +113,14 @@ _lx ldx #0 ; modified stz cx16.VERA_ADDR_L inc cx16.VERA_ADDR_M ; next line bra _lx -+ plx - rts ++ rts }} } -asmsub clear_screencolors (ubyte color @ A) clobbers(Y) { +asmsub clear_screencolors (ubyte color @ A) clobbers(X, Y) { ; ---- clear the character screen colors with the given color (leaves characters). ; (assumes color matrix is at the default address) %asm {{ - phx sta _la+1 jsr cbm.SCREEN ; get dimensions in X/Y txa @@ -150,8 +145,7 @@ _la lda #0 ; modified sta cx16.VERA_ADDR_L inc cx16.VERA_ADDR_M ; next line bra _lx -+ plx - rts ++ rts }} } @@ -192,11 +186,10 @@ sub iso_off() { } -asmsub scroll_left() clobbers(A, Y) { +asmsub scroll_left() clobbers(A, X, Y) { ; ---- scroll the whole screen 1 character to the left ; contents of the rightmost column are unchanged, you should clear/refill this yourself %asm {{ - phx jsr cbm.SCREEN dex stx _lx+1 @@ -233,16 +226,14 @@ _lx ldx #0 ; modified lda #0 sta cx16.VERA_CTRL - plx rts }} } -asmsub scroll_right() clobbers(A,Y) { +asmsub scroll_right() clobbers(A,X,Y) { ; ---- scroll the whole screen 1 character to the right ; contents of the leftmost column are unchanged, you should clear/refill this yourself %asm {{ - phx jsr cbm.SCREEN dex stx _lx+1 @@ -287,16 +278,14 @@ _lx ldx #0 ; modified lda #0 sta cx16.VERA_CTRL - plx rts }} } -asmsub scroll_up() clobbers(A, Y) { +asmsub scroll_up() clobbers(A, X, Y) { ; ---- scroll the whole screen 1 character up ; contents of the bottom row are unchanged, you should refill/clear this yourself %asm {{ - phx jsr cbm.SCREEN stx _nextline+1 dey @@ -337,16 +326,14 @@ _nextline + lda #0 sta cx16.VERA_CTRL - plx rts }} } -asmsub scroll_down() clobbers(A, Y) { +asmsub scroll_down() clobbers(A, X, Y) { ; ---- scroll the whole screen 1 character down ; contents of the top row are unchanged, you should refill/clear this yourself %asm {{ - phx jsr cbm.SCREEN stx _nextline+1 dey @@ -393,7 +380,6 @@ _nextline + lda #0 sta cx16.VERA_CTRL - plx rts }} } @@ -418,10 +404,9 @@ asmsub print (str text @ AY) clobbers(A,Y) { }} } -asmsub print_ub0 (ubyte value @ A) clobbers(A,Y) { +asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) { ; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total) %asm {{ - phx jsr conv.ubyte2decimal pha tya @@ -429,16 +414,13 @@ asmsub print_ub0 (ubyte value @ A) clobbers(A,Y) { pla jsr cbm.CHROUT txa - jsr cbm.CHROUT - plx - rts + jmp cbm.CHROUT }} } -asmsub print_ub (ubyte value @ A) clobbers(A,Y) { +asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) { ; ---- print the ubyte in A in decimal form, without left padding 0s %asm {{ - phx jsr conv.ubyte2decimal _print_byte_digits pha @@ -454,16 +436,13 @@ _print_byte_digits beq _ones jsr cbm.CHROUT _ones txa - jsr cbm.CHROUT - plx - rts + jmp cbm.CHROUT }} } -asmsub print_b (byte value @ A) clobbers(A,Y) { +asmsub print_b (byte value @ A) clobbers(A,X,Y) { ; ---- print the byte in A in decimal form, without left padding 0s %asm {{ - phx pha cmp #0 bpl + @@ -475,10 +454,9 @@ asmsub print_b (byte value @ A) clobbers(A,Y) { }} } -asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well) %asm {{ - phx bcc + pha lda #'$' @@ -487,16 +465,13 @@ asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { + jsr conv.ubyte2hex jsr cbm.CHROUT tya - jsr cbm.CHROUT - plx - rts + jmp cbm.CHROUT }} } -asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the ubyte in A in binary form (if Carry is set, a radix prefix '%' is printed as well) %asm {{ - phx sta P8ZP_SCRATCH_B1 bcc + lda #'%' @@ -509,12 +484,11 @@ asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,Y) { + jsr cbm.CHROUT dey bne - - plx rts }} } -asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the uword in A/Y in binary form (if Carry is set, a radix prefix '%' is printed as well) %asm {{ pha @@ -526,7 +500,7 @@ asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { }} } -asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { +asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) { ; ---- print the uword in A/Y in hexadecimal form (4 digits) ; (if Carry is set, a radix prefix '$' is printed as well) %asm {{ @@ -539,10 +513,9 @@ asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,Y) { }} } -asmsub print_uw0 (uword value @ AY) clobbers(A,Y) { +asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) { ; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total) %asm {{ - phx jsr conv.uword2decimal ldy #0 - lda conv.uword2decimal.decTenThousands,y @@ -550,17 +523,14 @@ asmsub print_uw0 (uword value @ AY) clobbers(A,Y) { jsr cbm.CHROUT iny bne - -+ plx - rts ++ rts }} } -asmsub print_uw (uword value @ AY) clobbers(A,Y) { +asmsub print_uw (uword value @ AY) clobbers(A,X,Y) { ; ---- print the uword in A/Y in decimal form, without left padding 0s %asm {{ - phx jsr conv.uword2decimal - plx ldy #0 - lda conv.uword2decimal.decTenThousands,y beq _allzero @@ -581,7 +551,7 @@ _allzero }} } -asmsub print_w (word value @ AY) clobbers(A,Y) { +asmsub print_w (word value @ AY) clobbers(A,X,Y) { ; ---- print the (signed) word in A/Y in decimal form, without left padding 0's %asm {{ cpy #0 @@ -704,12 +674,11 @@ asmsub getclr (ubyte col @A, ubyte row @Y) -> ubyte @ A { }} } -sub setcc (ubyte column, ubyte row, ubyte char, ubyte charcolor) { +sub setcc (ubyte column, ubyte row, ubyte char, ubyte charcolor) { ; ---- set char+color at the given position on the screen ; note: color handling is the same as on the C64: it only sets the foreground color and leaves the background color as is. ; Use setcc2 if you want Cx-16 specific feature of setting both Bg+Fg colors (is faster as well). %asm {{ - phx lda column asl a tax @@ -732,7 +701,6 @@ sub setcc (ubyte column, ubyte row, ubyte char, ubyte charcolor) { and #$f0 ora P8ZP_SCRATCH_B1 sta cx16.VERA_DATA0 - plx rts }} } @@ -742,7 +710,6 @@ sub setcc2 (ubyte column, ubyte row, ubyte char, ubyte colors) { ; note: on the CommanderX16 this allows you to set both Fg and Bg colors; ; use the high nybble in A to set the Bg color! Is a bit faster than setcc() too. %asm {{ - phx lda column asl a tax @@ -760,20 +727,14 @@ sub setcc2 (ubyte column, ubyte row, ubyte char, ubyte colors) { inc cx16.VERA_ADDR_L lda colors sta cx16.VERA_DATA0 - plx rts }} } -asmsub plot (ubyte col @ Y, ubyte row @ A) clobbers(A) { - ; ---- safe wrapper around PLOT kernal routine, to save the X register. +asmsub plot (ubyte col @ Y, ubyte row @ X) { %asm {{ - phx - tax clc - jsr cbm.PLOT - plx - rts + jmp cbm.PLOT }} } diff --git a/compiler/res/prog8lib/diskio.p8 b/compiler/res/prog8lib/diskio.p8 index 51334a6c7..44378f6da 100644 --- a/compiler/res/prog8lib/diskio.p8 +++ b/compiler/res/prog8lib/diskio.p8 @@ -455,13 +455,11 @@ io_error: sta P8ZP_SCRATCH_W1 lda address+1 sta P8ZP_SCRATCH_W1+1 - stx P8ZP_SCRATCH_REG lda #value jsr MOVFM ; load float into fac1 @@ -18,8 +17,7 @@ sub print_f(float value) { jsr cbm.CHROUT iny bne - -+ ldx floats_store_reg - rts ++ rts }} } @@ -44,10 +42,7 @@ sub sin(float angle) -> float { lda #angle jsr MOVFM - stx P8ZP_SCRATCH_REG - jsr SIN - ldx P8ZP_SCRATCH_REG - rts + jmp SIN }} } @@ -56,9 +51,7 @@ sub cos(float angle) -> float { lda #angle jsr MOVFM - stx P8ZP_SCRATCH_REG - jsr COS - ldx P8ZP_SCRATCH_REG + jmp COS rts }} } @@ -68,10 +61,7 @@ sub tan(float value) -> float { lda #value jsr MOVFM - stx P8ZP_SCRATCH_REG - jsr TAN - ldx P8ZP_SCRATCH_REG - rts + jmp TAN }} } @@ -80,10 +70,7 @@ sub atan(float value) -> float { lda #value jsr MOVFM - stx P8ZP_SCRATCH_REG - jsr ATN - ldx P8ZP_SCRATCH_REG - rts + jmp ATN }} } @@ -92,10 +79,7 @@ sub ln(float value) -> float { lda #value jsr MOVFM - stx P8ZP_SCRATCH_REG - jsr LOG - ldx P8ZP_SCRATCH_REG - rts + jmp LOG }} } @@ -104,15 +88,12 @@ sub log2(float value) -> float { lda #value jsr MOVFM - stx P8ZP_SCRATCH_REG jsr LOG jsr MOVEF lda #FL_LOG2_const jsr MOVFM - jsr FDIVT - ldx P8ZP_SCRATCH_REG - rts + jmp FDIVT }} } @@ -122,12 +103,9 @@ sub rad(float angle) -> float { lda #angle jsr MOVFM - stx P8ZP_SCRATCH_REG lda #<_pi_div_180 ldy #>_pi_div_180 - jsr FMULT - ldx P8ZP_SCRATCH_REG - rts + jmp FMULT _pi_div_180 .byte 123, 14, 250, 53, 18 ; pi / 180 }} } @@ -138,11 +116,9 @@ sub deg(float angle) -> float { lda #angle jsr MOVFM - stx P8ZP_SCRATCH_REG lda #<_one_over_pi_div_180 ldy #>_one_over_pi_div_180 - jsr FMULT - ldx P8ZP_SCRATCH_REG + jmp FMULT rts _one_over_pi_div_180 .byte 134, 101, 46, 224, 211 ; 1 / (pi * 180) }} @@ -153,11 +129,8 @@ sub round(float value) -> float { lda #value jsr MOVFM - stx P8ZP_SCRATCH_REG jsr FADDH - jsr INT - ldx P8ZP_SCRATCH_REG - rts + jmp INT }} } @@ -166,10 +139,7 @@ sub floor(float value) -> float { lda #value jsr MOVFM - stx P8ZP_SCRATCH_REG - jsr INT - ldx P8ZP_SCRATCH_REG - rts + jmp INT }} } @@ -179,7 +149,6 @@ sub ceil(float value) -> float { lda #value jsr MOVFM - stx P8ZP_SCRATCH_REG ldx #fmath_float1 jsr MOVMF @@ -192,8 +161,7 @@ sub ceil(float value) -> float { lda #FL_ONE_const jsr FADD -+ ldx P8ZP_SCRATCH_REG - rts ++ rts }} } @@ -202,14 +170,11 @@ sub rndseedf(float seed) { seed = -seed ; make sure fp seed is always negative %asm {{ - stx floats_store_reg lda #seed jsr MOVFM ; load float into fac1 lda #-1 - jsr floats.RND - ldx floats_store_reg - rts + jmp floats.RND }} } diff --git a/compiler/res/prog8lib/math.asm b/compiler/res/prog8lib/math.asm index add505203..3d5d9e36c 100644 --- a/compiler/res/prog8lib/math.asm +++ b/compiler/res/prog8lib/math.asm @@ -7,9 +7,6 @@ ; -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 @@ -30,7 +27,6 @@ multiply_bytes_into_word .proc ; -- multiply 2 bytes A and Y, result as word in A/Y (unsigned) sta P8ZP_SCRATCH_B1 sty P8ZP_SCRATCH_REG - stx math_store_reg lda #0 ldx #8 lsr P8ZP_SCRATCH_B1 @@ -43,7 +39,6 @@ multiply_bytes_into_word .proc bne - tay lda P8ZP_SCRATCH_B1 - ldx math_store_reg rts .pend @@ -55,7 +50,6 @@ multiply_words .proc sta P8ZP_SCRATCH_W2 sty P8ZP_SCRATCH_W2+1 - stx P8ZP_SCRATCH_REG mult16 lda #0 sta result+2 ; clear upper bits of product @@ -77,7 +71,6 @@ mult16 lda #0 ror result dex bne - - ldx P8ZP_SCRATCH_REG lda result ldy result+1 rts @@ -124,7 +117,6 @@ 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 math_store_reg lda #0 ldx #8 @@ -137,7 +129,6 @@ divmod_ub_asm .proc dex bne - ldy P8ZP_SCRATCH_B1 - ldx math_store_reg rts .pend @@ -197,7 +188,6 @@ result = dividend ;save memory by reusing divident to store the result sta _divisor sty _divisor+1 - stx P8ZP_SCRATCH_REG lda #0 ;preset remainder to 0 sta remainder sta remainder+1 @@ -224,7 +214,6 @@ result = dividend ;save memory by reusing divident to store the result lda result ldy result+1 - ldx P8ZP_SCRATCH_REG rts _divisor .word 0 .pend @@ -800,7 +789,6 @@ tempsq = P8ZP_SCRATCH_B1 ; temp byte for intermediate result sta numberl sty numberh - stx P8ZP_SCRATCH_REG lda #$00 ; clear a sta squarel ; clear square low byte @@ -838,7 +826,6 @@ _nosqadd: lda squarel ldy squareh - ldx P8ZP_SCRATCH_REG rts .pend diff --git a/compiler/res/prog8lib/prog8_funcs.asm b/compiler/res/prog8lib/prog8_funcs.asm index 67681684a..4c59bb36b 100644 --- a/compiler/res/prog8lib/prog8_funcs.asm +++ b/compiler/res/prog8lib/prog8_funcs.asm @@ -130,8 +130,6 @@ func_sqrt16_into_A .proc ; integer square root from http://6502org.wikidot.com/software-math-sqrt sta P8ZP_SCRATCH_W1 sty P8ZP_SCRATCH_W1+1 - txa - pha lda #0 sta P8ZP_SCRATCH_B1 sta P8ZP_SCRATCH_REG @@ -154,8 +152,6 @@ func_sqrt16_into_A .proc rol P8ZP_SCRATCH_REG dex bne - - pla - tax lda P8ZP_SCRATCH_B1 rts .pend diff --git a/compiler/res/prog8lib/string.p8 b/compiler/res/prog8lib/string.p8 index 41835f066..84e79c19a 100644 --- a/compiler/res/prog8lib/string.p8 +++ b/compiler/res/prog8lib/string.p8 @@ -282,7 +282,6 @@ _done rts str = P8ZP_SCRATCH_W1 - stx P8ZP_SCRATCH_REG sta str sty str+1 lda cx16.r0 @@ -294,7 +293,6 @@ str = P8ZP_SCRATCH_W1 jsr _match lda #0 rol a - ldx P8ZP_SCRATCH_REG rts diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 65c4fd82e..3c9b6ca03 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,7 +1,6 @@ TODO ==== -- (branch): clean up all X register special handling in p8 code inline asm - (branch): clean up docs about eval stack and X register - (branch): fix optimizeCmpSequence in AsmOptimizer - (branch): fix inplaceModification TODO in AugmentableAssignmentAsmGen diff --git a/examples/cx16/cobramk3-gfx.p8 b/examples/cx16/cobramk3-gfx.p8 index 1b4a0d4d5..f52fe583e 100644 --- a/examples/cx16/cobramk3-gfx.p8 +++ b/examples/cx16/cobramk3-gfx.p8 @@ -63,9 +63,8 @@ main { cx16.GRAPH_put_next_char(c) } - asmsub print_number_gfx(ubyte num @ A) clobbers(A,Y) { + asmsub print_number_gfx(ubyte num @ A) clobbers(A,X,Y) { %asm {{ - phx jsr conv.ubyte2decimal phx pha @@ -81,9 +80,7 @@ main { beq _ones jsr cx16.GRAPH_put_char _ones pla - jsr cx16.GRAPH_put_char - plx - rts + jmp cx16.GRAPH_put_char }} }