Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve romability of low-level libs #160

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions compiler/res/prog8lib/c128/syslib.p8
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,12 @@ sys {
lda P8ZP_SCRATCH_W2+1
sta save_SCRATCH_ZPWORD2+1
rts
save_SCRATCH_ZPB1 .byte 0
save_SCRATCH_ZPREG .byte 0
save_SCRATCH_ZPWORD1 .word 0
save_SCRATCH_ZPWORD2 .word 0
.section BSS
save_SCRATCH_ZPB1 .byte ?
save_SCRATCH_ZPREG .byte ?
save_SCRATCH_ZPWORD1 .word ?
save_SCRATCH_ZPWORD2 .word ?
.send BSS
; !notreached!
}}
}
Expand All @@ -488,8 +490,8 @@ save_SCRATCH_ZPWORD2 .word 0
asmsub set_irq(uword handler @AY) clobbers(A) {
%asm {{
sei
sta _modified+1
sty _modified+2
sta _vector
sty _vector+1
lda #<_irq_handler
sta cbm.CINV
lda #>_irq_handler
Expand All @@ -499,8 +501,8 @@ asmsub set_irq(uword handler @AY) clobbers(A) {
_irq_handler
jsr sys.save_prog8_internals
cld
_modified
jsr $ffff ; modified

jsr _run_custom
pha
jsr sys.restore_prog8_internals
pla
Expand All @@ -515,6 +517,12 @@ _modified
tax
pla
rti
_run_custom
jmp (_vector)
.section BSS
_vector .word ?
.send BSS
; !notreached!
}}
}

Expand All @@ -537,8 +545,8 @@ asmsub restore_irq() clobbers(A) {
asmsub set_rasterirq(uword handler @AY, uword rasterpos @R0) clobbers(A) {
%asm {{
sei
sta _modified+1
sty _modified+2
sta _vector
sty _vector+1
lda cx16.r0
ldy cx16.r0+1
jsr _setup_raster_irq
Expand All @@ -552,8 +560,8 @@ asmsub set_rasterirq(uword handler @AY, uword rasterpos @R0) clobbers(A) {
_raster_irq_handler
jsr sys.save_prog8_internals
cld
_modified
jsr $ffff ; modified

jsr _run_custom
pha
jsr sys.restore_prog8_internals
lda #$ff
Expand All @@ -567,6 +575,12 @@ _modified
tax
pla
rti
_run_custom
jmp (_vector)
.section BSS
_vector .word ?
.send BSS


_setup_raster_irq
pha
Expand Down Expand Up @@ -1063,10 +1077,11 @@ cx16 {
dey
bpl -
rts

.section BSS
_cx16_vreg_storage
.word 0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0
.word ?,?,?,?,?,?,?,?
.word ?,?,?,?,?,?,?,?
.send BSS
; !notreached!
}}
}
Expand Down Expand Up @@ -1131,6 +1146,7 @@ asmsub init_system_phase2() {

asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
; TODO: Romable (It's technically an easy fix, but i've decided not to touch it for now)
%asm {{
lda #0
sta $ff00 ; default bank 15
Expand Down
13 changes: 7 additions & 6 deletions compiler/res/prog8lib/c64/floats.asm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ FL_ONE_const .byte 129 ; 1.0
FL_ZERO_const .byte 0,0,0,0,0 ; 0.0
FL_LOG2_const .byte $80, $31, $72, $17, $f8 ; log(2)


floats_temp_var .byte 0,0,0,0,0 ; temporary storage for a float
.section BSS
floats_temp_var .byte ?,?,?,?,? ; temporary storage for a float
.send BSS

ub2float .proc
; -- convert ubyte in SCRATCH_ZPB1 to float at address A/Y
Expand Down Expand Up @@ -178,10 +179,10 @@ dec_var_f .proc
jmp MOVMF
.pend


fmath_float1 .byte 0,0,0,0,0 ; storage for a mflpt5 value
fmath_float2 .byte 0,0,0,0,0 ; storage for a mflpt5 value

.section BSS
fmath_float1 .byte ?,?,?,?,? ; storage for a mflpt5 value
fmath_float2 .byte ?,?,?,?,? ; storage for a mflpt5 value
.send BSS

var_fac1_less_f .proc
; -- is the float in FAC1 < the variable AY? Result in A. Clobbers X.
Expand Down
47 changes: 33 additions & 14 deletions compiler/res/prog8lib/c64/syslib.p8
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ inline asmsub getbanks() -> ubyte @A {
}}
}

; TODO: Romable
asmsub x16jsrfar() {
%asm {{
; setup a JSRFAR call (using X16 call convention)
Expand Down Expand Up @@ -474,10 +475,12 @@ sys {
lda P8ZP_SCRATCH_W2+1
sta save_SCRATCH_ZPWORD2+1
rts
save_SCRATCH_ZPB1 .byte 0
save_SCRATCH_ZPREG .byte 0
save_SCRATCH_ZPWORD1 .word 0
save_SCRATCH_ZPWORD2 .word 0
.section BSS
save_SCRATCH_ZPB1 .byte ?
save_SCRATCH_ZPREG .byte ?
save_SCRATCH_ZPWORD1 .word ?
save_SCRATCH_ZPWORD2 .word ?
.send BSS
; !notreached!
}}
}
Expand All @@ -503,8 +506,8 @@ save_SCRATCH_ZPWORD2 .word 0
asmsub set_irq(uword handler @AY) clobbers(A) {
%asm {{
sei
sta _modified+1
sty _modified+2
sta _vector
sty _vector+1
lda #<_irq_handler
sta cbm.CINV
lda #>_irq_handler
Expand All @@ -514,8 +517,8 @@ asmsub set_irq(uword handler @AY) clobbers(A) {
_irq_handler
jsr sys.save_prog8_internals
cld
_modified
jsr $ffff ; modified

jsr _run_custom
pha
jsr sys.restore_prog8_internals
pla
Expand All @@ -530,6 +533,13 @@ _modified
tax
pla
rti

_run_custom
jmp (_vector)
.section BSS
_vector .word ?
.send BSS
; !notreached!
}}
}

Expand All @@ -552,8 +562,8 @@ asmsub restore_irq() clobbers(A) {
asmsub set_rasterirq(uword handler @AY, uword rasterpos @R0) clobbers(A) {
%asm {{
sei
sta _modified+1
sty _modified+2
sta _vector
sty _vector+1
lda cx16.r0
ldy cx16.r0+1
jsr _setup_raster_irq
Expand All @@ -567,8 +577,8 @@ asmsub set_rasterirq(uword handler @AY, uword rasterpos @R0) clobbers(A) {
_raster_irq_handler
jsr sys.save_prog8_internals
cld
_modified
jsr $ffff ; modified

jsr _run_custom
pha
jsr sys.restore_prog8_internals
lda #$ff
Expand All @@ -583,6 +593,12 @@ _modified
pla
rti

_run_custom
jmp (_vector)
.section BSS
_vector .word ?
.send BSS

_setup_raster_irq
pha
lda #%01111111
Expand Down Expand Up @@ -1080,9 +1096,11 @@ cx16 {
bpl -
rts

.section BSS
_cx16_vreg_storage
.word 0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0
.word ?,?,?,?,?,?,?,?
.word ?,?,?,?,?,?,?,?
.send BSS
; !notreached!
}}
}
Expand Down Expand Up @@ -1157,6 +1175,7 @@ asmsub init_system_phase2() {

asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
; TODO: Romable
%asm {{
lda #%00101111
sta $00
Expand Down
24 changes: 15 additions & 9 deletions compiler/res/prog8lib/conv.p8
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ conv {

; ----- number conversions to decimal strings ----

str @shared string_out = "????????????????" ; result buffer for the string conversion routines
ubyte[16] @shared string_out ; result buffer for the string conversion routines

asmsub str_ub0(ubyte value @A) clobbers(X) -> str @AY {
; ---- convert the ubyte in A in decimal string form, with left padding 0s (3 positions total)
Expand Down Expand Up @@ -402,7 +402,9 @@ _digit
+ iny
bne _parse
; never reached
_negative .byte 0
.section BSS
_negative .byte ?
.send BSS
; !notreached!
}}
}
Expand Down Expand Up @@ -699,12 +701,14 @@ ShiftedBcdTab
.byte $30,$31,$32,$33,$34,$38,$39,$3A,$3B,$3C
.byte $40,$41,$42,$43,$44,$48,$49,$4A,$4B,$4C

decTenThousands .byte 0
decThousands .byte 0
decHundreds .byte 0
decTens .byte 0
decOnes .byte 0
.byte 0 ; zero-terminate the decimal output string
.section BSS
decTenThousands .byte ?
decThousands .byte ?
decHundreds .byte ?
decTens .byte ?
decOnes .byte ?
.byte ? ; zero-terminate the decimal output string, set to 0 by bss init mechanisms
.send BSS
; !notreached!
}}
}
Expand Down Expand Up @@ -756,7 +760,9 @@ asmsub internal_uword2hex (uword value @AY) clobbers(A,Y) {
sta output+2
sty output+3
rts
output .text "0000", $00 ; 0-terminated output buffer (to make printing easier)
.section BSS
output .fill 5 ; 0-terminated output buffer (to make printing easier)
.send BSS
; !notreached!
}}
}
Expand Down
Loading