scanned libraries for self-modifying code/inline vars (romable problem)

This commit is contained in:
Irmen de Jong 2025-04-14 21:15:32 +02:00
parent f829b689db
commit 14a2b96609
15 changed files with 58 additions and 21 deletions

View File

@ -218,6 +218,8 @@ $modifiedLabel cmp #0 ; modified
}
asmgen.out(loopLabel)
asmgen.translate(forloop.statements)
asmgen.romableError("self-modifying code (forloop over bytes range)", forloop.position) // TODO fix romable; there is self-modifying code below
if(stepsize>0) {
asmgen.out("""
lda $varname
@ -227,7 +229,6 @@ $modifiedLabel cmp #0 ; modified
$modifiedLabel cmp #0 ; modified
bmi $loopLabel
beq $loopLabel""")
asmgen.romableError("self-modifying code (forloop over range)", forloop.position) // TODO fix romable
} else {
asmgen.out("""
lda $varname
@ -236,7 +237,6 @@ $modifiedLabel cmp #0 ; modified
sta $varname
$modifiedLabel cmp #0 ; modified
bpl $loopLabel""")
asmgen.romableError("self-modifying code (forloop over range)", forloop.position) // TODO fix romable
}
asmgen.out(endLabel)
}
@ -375,6 +375,7 @@ $modifiedLabel2 cmp #0 ; modified
$loopLabel""")
asmgen.translate(stmt.statements)
asmgen.romableError("self-modifying code (forloop over word range)", stmt.position) // TODO fix romable; there is self-modifying code below
if (iterableDt.isUnsignedWordArray) {
asmgen.out("""
lda $varname
@ -392,7 +393,6 @@ $modifiedLabel2 lda #0 ; modified
bcc $endLabel
bcs $loopLabel
$endLabel""")
asmgen.romableError("self-modifying code (forloop over range)", stmt.position) // TODO fix romable
} else {
asmgen.out("""
lda $varname
@ -410,7 +410,6 @@ $modifiedLabel lda #0 ; modified
eor #$80
+ bpl $loopLabel
$endLabel""")
asmgen.romableError("self-modifying code (forloop over range)", stmt.position) // TODO fix romable
}
}
@ -443,7 +442,7 @@ $modifiedLabel sbc #0 ; modified
eor #$80
+ bpl $loopLabel
$endLabel""")
asmgen.romableError("self-modifying code (forloop over range)", stmt.position) // TODO fix romable
asmgen.romableError("self-modifying code (forloop over words range)", stmt.position) // TODO fix romable
}
private fun precheckFromToWord(iterableDt: DataType, stepsize: Int, fromVar: String, endLabel: String) {

View File

@ -1077,6 +1077,7 @@ cx16 {
dey
bpl -
rts
.section BSS
_cx16_vreg_storage
.word ?,?,?,?,?,?,?,?

View File

@ -296,6 +296,7 @@ _scroll_screen ; scroll only the screen memory
asmsub setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers(A, Y) {
; ---- sets the character in the screen matrix at the given position
; TODO: Romable
%asm {{
pha
tya
@ -320,6 +321,7 @@ _screenrows .word cbm.Screen + range(0, 1000, 40)
asmsub getchr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
; ---- get the character in the screen matrix at the given location
; TODO: Romable
%asm {{
pha
tya
@ -340,6 +342,7 @@ _mod lda $ffff ; modified
asmsub setclr (ubyte col @X, ubyte row @Y, ubyte color @A) clobbers(A, Y) {
; ---- set the color in A on the screen matrix at the given position
; TODO: Romable
%asm {{
pha
tya
@ -364,6 +367,7 @@ _colorrows .word $d800 + range(0, 1000, 40)
asmsub getclr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
; ---- get the color in the screen color matrix at the given location
; TODO: Romable
%asm {{
pha
tya
@ -384,6 +388,7 @@ _mod lda $ffff ; modified
sub setcc (ubyte col, ubyte row, ubyte character, ubyte charcolor) {
; ---- set char+color at the given position on the screen
; TODO: Romable
%asm {{
lda row
asl a

View File

@ -192,6 +192,7 @@ graphics {
}
if length!=0 {
; TODO: Romable
%asm {{
lda p8v_length
and #7

View File

@ -299,6 +299,7 @@ _scroll_screen ; scroll only the screen memory
asmsub setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers(A, Y) {
; ---- sets the character in the screen matrix at the given position
; TODO: Romable
%asm {{
pha
tya
@ -323,6 +324,7 @@ _screenrows .word cbm.Screen + range(0, 1000, 40)
asmsub getchr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
; ---- get the character in the screen matrix at the given location
; TODO: Romable
%asm {{
pha
tya
@ -343,6 +345,7 @@ _mod lda $ffff ; modified
asmsub setclr (ubyte col @X, ubyte row @Y, ubyte color @A) clobbers(A, Y) {
; ---- set the color in A on the screen matrix at the given position
; TODO: Romable
%asm {{
pha
tya
@ -367,6 +370,7 @@ _colorrows .word $d800 + range(0, 1000, 40)
asmsub getclr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
; ---- get the color in the screen color matrix at the given location
; TODO: Romable
%asm {{
pha
tya
@ -387,6 +391,7 @@ _mod lda $ffff ; modified
sub setcc (ubyte col, ubyte row, ubyte character, ubyte charcolor) {
; ---- set char+color at the given position on the screen
; TODO: Romable
%asm {{
lda row
asl a

View File

@ -416,6 +416,7 @@ byte_read_loop: ; fallback if MACPTR isn't supported on the device
sta m_in_buffer+2
}}
while num_bytes!=0 {
; TODO: Romable
%asm {{
jsr cbm.CHRIN
m_in_buffer sta $ffff ; modified

View File

@ -154,9 +154,9 @@ gfx_hires {
inc cx16.VERA_ADDR_L
bne ++
inc cx16.VERA_ADDR_M
+ bne +
+ bne +
inc cx16.VERA_ADDR_H
+ inx ; next pixel
+ inx ; next pixel
}}
}
}

View File

@ -1053,6 +1053,7 @@ asmsub save_virtual_registers() clobbers(A,Y) {
dey
bpl -
rts
.section BSS
_cx16_vreg_storage
.word ?,?,?,?,?,?,?,?
@ -1183,6 +1184,7 @@ asmsub enable_irq_handlers(bool disable_all_irq_sources @Pc) clobbers(A,Y) {
; to the registered handler for each type. (Only Vera IRQs supported for now).
; The handlers don't need to clear its ISR bit, but have to return 0 or 1 in A,
; where 1 means: continue with the system IRQ handler, 0 means: don't call that.
; TODO: Romable
%asm {{
php
sei
@ -1266,6 +1268,7 @@ _default_aflow_handler
asmsub set_vsync_irq_handler(uword address @AY) clobbers(A) {
; Sets the VSYNC irq handler to use with enable_irq_handlers(). Also enables VSYNC irqs.
; TODO: Romable
%asm {{
php
sei
@ -1281,6 +1284,7 @@ asmsub set_vsync_irq_handler(uword address @AY) clobbers(A) {
asmsub set_line_irq_handler(uword rasterline @R0, uword address @AY) clobbers(A,Y) {
; Sets the LINE irq handler to use with enable_irq_handlers(), for the given rasterline. Also enables LINE irqs.
; You can use sys.set_rasterline() later to adjust the rasterline on which to trigger.
; TODO: Romable
%asm {{
php
sei
@ -1298,6 +1302,7 @@ asmsub set_line_irq_handler(uword rasterline @R0, uword address @AY) clobbers(A,
asmsub set_sprcol_irq_handler(uword address @AY) clobbers(A) {
; Sets the SPRCOL irq handler to use with enable_irq_handlers(). Also enables SPRCOL irqs.
; TODO: Romable
%asm {{
php
sei
@ -1313,6 +1318,7 @@ asmsub set_sprcol_irq_handler(uword address @AY) clobbers(A) {
asmsub set_aflow_irq_handler(uword address @AY) clobbers(A) {
; Sets the AFLOW irq handler to use with enable_irq_handlers(). Also enables AFLOW irqs.
; NOTE: the handler itself must fill the audio fifo buffer to at least 25% full again (1 KB) or the aflow irq will keep triggering!
; TODO: Romable
%asm {{
php
sei

View File

@ -95,6 +95,7 @@ asmsub get_cursor() -> ubyte @X, ubyte @Y {
asmsub fill_screen (ubyte character @ A, ubyte color @ Y) clobbers(A, X) {
; ---- fill the character screen with the given fill character and character color.
; TODO: Romable
%asm {{
sty _ly+1
pha
@ -142,6 +143,7 @@ set_vera_textmatrix_addresses:
asmsub clear_screenchars (ubyte character @ A) clobbers(X, Y) {
; ---- clear the character screen with the given fill character (leaves colors)
; (assumes screen matrix is at the default address)
; TODO: Romable
%asm {{
pha
jsr cbm.SCREEN ; get dimensions in X/Y
@ -171,6 +173,7 @@ _lx ldx #0 ; modified
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)
; TODO: Romable
%asm {{
sta _la+1
jsr cbm.SCREEN ; get dimensions in X/Y
@ -269,6 +272,7 @@ sub kata() {
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
; TODO: Romable
%asm {{
jsr cbm.SCREEN
dex
@ -313,6 +317,7 @@ _lx ldx #0 ; modified
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
; TODO: Romable
%asm {{
jsr cbm.SCREEN
dex
@ -365,6 +370,7 @@ _lx ldx #0 ; modified
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
; TODO: Romable
%asm {{
jsr cbm.SCREEN
stx _nextline+1
@ -413,6 +419,7 @@ _nextline
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
; TODO: Romable
%asm {{
jsr cbm.SCREEN
stx _nextline+1

View File

@ -153,6 +153,7 @@ asmsub scroll_down () clobbers(A,X) {
asmsub setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers(A, Y) {
; ---- sets the character in the screen matrix at the given position
; TODO: Romable
%asm {{
pha
tya
@ -177,6 +178,7 @@ _screenrows .word cbm.Screen + range(0, 1000, 40)
asmsub getchr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
; ---- get the character in the screen matrix at the given location
; TODO: Romable
%asm {{
pha
tya
@ -202,6 +204,7 @@ sub setclr (ubyte col, ubyte row, ubyte color) {
sub setcc (ubyte col, ubyte row, ubyte character, ubyte charcolor) {
; ---- set char at the given position on the screen. charcolor is ignored on PET
; TODO: Romable
%asm {{
lda row
asl a

View File

@ -369,6 +369,7 @@ close_end:
sta m_in_buffer+2
}}
while num_bytes!=0 {
; TODO: Romable
%asm {{
jsr cbm.CHRIN
m_in_buffer sta $ffff ; modified

View File

@ -8,6 +8,7 @@ sorting {
; NOTE: all word arrays are assumed to be @nosplit!!
; NOTE: sorting is done in ascending order!!!
; TODO: Romable
asmsub gnomesort_ub(uword bytearray @AY, ubyte num_elements @X) {
%asm {{

View File

@ -1,8 +1,7 @@
TODO
====
romable: check library files for routines that are not yet romable and add "TODO: Romable" comment
romable: fix as many of those issues as possible to improve romability of library code
romable: fix as many of the "TODO: Romable" issues as possible to improve romability of library code
...

View File

@ -276,10 +276,12 @@ _no_msb_size
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!
}}
}
@ -512,9 +514,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!
}}
}

View File

@ -209,10 +209,12 @@ _longcopy
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!
}}
}
@ -443,9 +445,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!
}}
}