Use cheap local labels for self-modifying code where possible. Fixes #89

This commit is contained in:
Joshua Bell 2018-11-24 11:17:46 -08:00
parent ae2938c58e
commit a93663b1bc
10 changed files with 97 additions and 94 deletions

View File

@ -152,20 +152,23 @@ well in the future.
## Self-modifying code
* Add a label for the value being modified (byte or address)
* Add a label for the value being modified (byte or address). Use
[cheap local labels](https://cc65.github.io/doc/ca65.html#ss6.5) via the
`@`-prefix where possible so make self-modification references more
visible.
```asm
sta jump_addr
stx jump_addr+1
jump_addr := *+1
sta @jump_addr
stx @jump_addr+1
@jump_addr := *+1
jmp $0000
```
```asm
sty count
sty @count
ldy #0
: sta table,y
iny
count := *+1
cpy #count
@count := *+1
cpy #00
bne :-
```

View File

@ -1182,13 +1182,13 @@ read: lda #0
;;; ============================================================
.proc read_file_page
copy16 read_params::data_buffer, store_addr
copy16 read_params::data_buffer, @store_addr
lda #' ' ; fill buffer with spaces
ldx #0
sta RAMWRTOFF
store_addr := *+1
@store_addr := *+1
store: sta default_buffer,x ; self-modified
inx
bne store

View File

@ -2046,15 +2046,15 @@ monitor:
stax ptr
ldy #0
lda (ptr),y
sta len
sta @len
beq done
loop: iny
: iny
lda ($06),y
ora #$80
jsr COUT
len := *+1
@len := *+1
cpy #0 ; self-modified
bne loop
bne :-
done: rts
.endproc

View File

@ -3503,7 +3503,7 @@ LBDE1: sub16 event_xcoord, portmap::viewloc::xcoord, event_xcoord
rts
.proc LBE08
copy16 #$0800, LBE37
copy16 #$0800, addr
lda LBFC9
jsr LBF10
lda LBFCB
@ -3520,9 +3520,9 @@ LBE27: lda LBE5C
bcs LBE34
sta PAGE2ON ; aux $2000-$3FFF
LBE34: lda ($06),y
LBE37 := * + 1
addr := *+1
sta dummy1234
inc16 LBE37
inc16 addr
lda LBE5C
cmp LBFCC
bcs LBE4E
@ -3531,7 +3531,7 @@ LBE37 := * + 1
LBE4E: jsr LBF52
dex
bne LBE21
ldax LBE37
ldax addr
rts
.byte 0
@ -3539,7 +3539,7 @@ LBE5C: .byte 0
.endproc
.proc LBE5D
copy16 #$800, LBEBC
copy16 #$800, addr
ldx LBFCD
ldy LBFCE
lda #$FF
@ -3580,7 +3580,7 @@ LBEAE: lda LBF0B
bcs :+
sta PAGE2ON ; aux $2000-$3FFF
LBEBC := *+1
addr := *+1
: lda $0800 ; self-modified
pha
@ -3607,7 +3607,7 @@ LBEDD: lda ($06),y
pha
LBEEB: pla
sta ($06),y
inc16 LBEBC
inc16 addr
lda LBF0B
cmp LBFCC
bcs LBF03

View File

@ -748,16 +748,16 @@ L45C7: sta unit_num
and #$80 ; high bit is drive (0=D1, 1=D2)
beq :+
ldx #$21
: stx bf_lo ; D1=$11, D2=$21
: stx @bf_lsb ; D1=$11, D2=$21
lda unit_num
and #$70
lsr a
lsr a
lsr a
clc
adc bf_lo
sta bf_lo
bf_lo := *+1
adc @bf_lsb
sta @bf_lsb
@bf_lsb := *+1
lda $BF00 ; self-modified to $BFds
sta ptr+1
lda #0 ; Bug: assumes driver is at $XX00 ???
@ -1345,14 +1345,14 @@ L4AEA: jsr L4B5F
.endproc
.proc copy_LD3EE_str
stax destptr
stax @destptr
sta ALTZPOFF
lda LCBANK2
lda LCBANK2
ldx LD3EE
: lda LD3EE,x
destptr := *+1
@destptr := *+1
sta dummy1234,x
dex
bpl :-
@ -1364,14 +1364,14 @@ L4AEA: jsr L4B5F
.endproc
.proc copy_LD3AD_str
stax destptr
stax @destptr
sta ALTZPOFF
lda LCBANK2
lda LCBANK2
ldx LD3AD
: lda LD3AD,x
destptr := *+1
@destptr := *+1
sta dummy1234,x
dex
bpl :-
@ -7660,7 +7660,7 @@ ascii_digits:
adc ($06),y
sta ($08),y
lda ($06),y
sta compare_y
sta @compare_y
: inc L84D0
iny
lda ($06),y
@ -7668,7 +7668,7 @@ ascii_digits:
ldy L84D0
sta ($08),y
ldy L84CF
compare_y := *+1
@compare_y := *+1
cpy #0 ; self-modified
bcc :-
rts
@ -8447,8 +8447,8 @@ create_icon:
lsr a
lsr a
ora #$C0
sta load_CxFB
load_CxFB := *+2
sta @load_CxFB
@load_CxFB := *+2
lda $C7FB ; self-modified $CxFB
and #$01 ; $CxFB bit 1 = ProFile, apparently???
beq use_profile_icon
@ -9098,14 +9098,14 @@ L9051: lda LEBFC
sta ($06),y
dey
lda ($06),y
sta L906D
sta @compare
sta path_buf3,y
L9066: iny
: iny
lda ($06),y
sta path_buf3,y
L906D := *+1
@compare := *+1
cpy #$00 ; self-modified
bne L9066
bne :-
ldy #$01
lda #' '
sta ($06),y
@ -9276,12 +9276,12 @@ L918D: .byte 0
beq do_str2
;; Copy $8 (str1)
sta len1
sta @len
: iny
inx
lda (str1),y
sta buf,x
len1 := *+1
@len := *+1
cpy #0 ; self-modified
bne :-
@ -9295,13 +9295,13 @@ do_str2:
ldy #0
lda (str2),y
beq done
sta len2
sta @len
iny
: iny
inx
lda (str2),y
sta buf,x
len2 := *+1
@len := *+1
cpy #0 ; self-modified
bne :-
@ -9366,19 +9366,19 @@ index: .byte 0
.proc smartport_eject
ptr := $6
sta compare
sta @compare
ldy #0
loop: lda device_to_icon_map,y
: lda device_to_icon_map,y
compare := *+1
@compare := *+1
cmp #0
beq found
cpy DEVCNT
beq exit
iny
bne loop
bne :-
exit: rts
found: lda DEVLST,y ;
@ -9390,16 +9390,16 @@ found: lda DEVLST,y ;
and #$80 ; high bit is drive (0=D1, 1=D2)
beq :+
ldx #$21
: stx bf_lo ; D1=$11, D2=$21
: stx @bf_lsb ; D1=$11, D2=$21
lda unit_num
and #$70
lsr a
lsr a
lsr a
clc
adc bf_lo
sta bf_lo
bf_lo := *+1
adc @bf_lsb
sta @bf_lsb
@bf_lsb := *+1
lda $BF00 ; self-modified to $BFds
sta ptr+1
lda #0 ; Bug: assumes driver is at $XX00 ???
@ -11407,7 +11407,7 @@ dialog_param_addr:
tya
asl a
tax
copy16 dialog_proc_table,x, jump_addr
copy16 dialog_proc_table,x, @jump_addr
lda #0
sta prompt_ip_flag
@ -11425,7 +11425,7 @@ dialog_param_addr:
copy16 #rts1, jump_relay+1
jsr set_cursor_pointer
jump_addr := *+1
@jump_addr := *+1
jmp dummy0000 ; self-modified
.endproc
@ -14239,17 +14239,17 @@ trash_name: PASCAL_STRING " Trash "
and #$80 ; drive 2?
beq :+
ldx #$21 ; LSB DEVADR for slot 1, drive 2
: stx addr_lsb
: stx @addr_lsb
lda L0A02 ; unit_num (again)
and #$70 ; slot number
lsr a
lsr a
lsr a
clc
adc addr_lsb
sta addr_lsb
adc @addr_lsb
sta @addr_lsb
addr_lsb := *+1
@addr_lsb := *+1
lda MLI ; self-modified
sta ptr+1 ; $Cn firmware address
@ -14707,8 +14707,8 @@ L0D7F: cmp #$0B
lsr a
lsr a
ora #$C0
sta slot_msb
slot_msb := *+2
sta @slot_msb
@slot_msb := *+2
lda $C7FB ; self-modified
and #$01
bne L0DA2
@ -14721,13 +14721,13 @@ L0DA9: ldax #str_unidisk_xy
L0DAD: stax $06
ldy #$00
lda ($06),y
sta L0DBE
L0DB8: iny
sta @compare
: iny
lda ($06),y
sta ($08),y
L0DBE := *+1
@compare := *+1
cpy #0
bne L0DB8
bne :-
tay
L0DC2: pla
pha
@ -14749,8 +14749,8 @@ L0DC2: pla
lsr a
lsr a
ora #$C0
sta L0DE3
L0DE3 := *+2
sta @msb
@msb := *+2
lda $C7FB ; self-modified
and #$01
bne L0DEC
@ -14853,12 +14853,12 @@ prepare:
pha
asl a
tax
copy16 slot_string_table,x, item_ptr
copy16 slot_string_table,x, @item_ptr
ldx startup_menu_item_1 ; replace second-from-last char
dex
lda char
item_ptr := *+1
@item_ptr := *+1
sta dummy1234,x
pla

View File

@ -1037,13 +1037,13 @@ get_srcbits_jmp_addr := *+1
: ldy src_width_bytes
loop:
:
load_addr := *+1
lda $FFFF,y ; off-screen BMP will be patched here
and #$7F
sta bitmap_buffer,y
dey
bpl loop
bpl :-
bmi shift_bits_clc_jmp
.endproc

View File

@ -763,17 +763,17 @@ L0D26: sta L0D50
and #$80
beq L0D34
ldx #$21
L0D34: stx load_addr
L0D34: stx @load_addr
lda L0D50
and #$70
lsr a
lsr a
lsr a
clc
adc load_addr
sta load_addr
adc @load_addr
sta @load_addr
load_addr := * + 1
@load_addr := *+1
lda MLI ; self-modified
sta $07
lda #$00

View File

@ -1050,16 +1050,16 @@ L126F: sta L12C0
and #$80
beq L1281
ldx #$21
L1281: stx L1294
L1281: stx @lsb
lda L12C0
and #$70
lsr a
lsr a
lsr a
clc
adc L1294
sta L1294
L1294 := * + 1
adc @lsb
sta @lsb
@lsb := *+1
lda MLI
sta $07
lda #$00
@ -1093,16 +1093,16 @@ L12C1: sta L1306
and #$80
beq L12D3
ldx #$21
L12D3: stx L12E6
L12D3: stx @lsb
lda L1306
and #$70
lsr a
lsr a
lsr a
clc
adc L12E6
sta L12E6
L12E6 := * + 1
adc @lsb
sta @lsb
@lsb := *+1
lda MLI
sta $07
lda #$00
@ -1157,16 +1157,16 @@ L132C: ldy #0
and #$80
beq L134D
ldx #$21
L134D: stx L1360
L134D: stx @lsb
lda L124A
and #$70
lsr a
lsr a
lsr a
clc
adc L1360
sta L1360
L1360 := * + 1
adc @lsb
sta @lsb
@lsb := *+1
lda MLI
sta $06+1
lda #$00

View File

@ -36,8 +36,8 @@ L9017: lda $0C00
rts
L903C: ldx #$01
copy16 selector_menu_addr, load
load := *+1
copy16 selector_menu_addr, @load
@load := *+1
lda dummy1234
cmp #$0D
bcc L9052
@ -1450,31 +1450,31 @@ L9DED: sta ALTZPOFF
txa
rts
L9E05: stax L9E1B
L9E05: stax @addr
sta ALTZPOFF
lda LCBANK2
lda LCBANK2
ldx LD3EE
L9E17: lda LD3EE,x
L9E1B := *+1
: lda LD3EE,x
@addr := *+1
sta dummy1234,x
dex
bpl L9E17
bpl :-
sta ALTZPON
lda LCBANK1
lda LCBANK1
rts
L9E2A: stax L9E40
L9E2A: stax @addr
sta ALTZPOFF
lda LCBANK2
lda LCBANK2
ldx LD3AD
L9E3C: lda LD3AD,x
L9E40 := *+1
: lda LD3AD,x
@addr := *+1
sta dummy1234,x
dex
bpl L9E3C
bpl :-
sta ALTZPON
lda LCBANK1
lda LCBANK1

View File

@ -50,11 +50,11 @@ routine_table: .addr $7000, $7000, $7000
pla
asl a
tax
copy16 routine_table,x, jump
copy16 routine_table,x, @jump
ldy stash_y
ldx stash_x
jump := * + 1
@jump := *+1
jmp dummy1234
stash_x: .byte 0