aboutsummaryrefslogtreecommitdiff
path: root/reloc.s
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-04-23 06:36:00 -0400
committerB. Watson <urchlay@slackware.uk>2025-04-23 06:36:00 -0400
commit8158e2e1b60484c8c12da62afbd439d810e96c3e (patch)
treef30742bcd6a57c63f0d1c26b0bbca3f3ccdd3b89 /reloc.s
parent3a120e78480a3b43c5cf32d9e6efae5a698abd38 (diff)
downloadatari8-self-relocator-8158e2e1b60484c8c12da62afbd439d810e96c3e.tar.gz
reloc.s: optimize for size.
Diffstat (limited to 'reloc.s')
-rw-r--r--reloc.s37
1 files changed, 28 insertions, 9 deletions
diff --git a/reloc.s b/reloc.s
index 3702430..530e303 100644
--- a/reloc.s
+++ b/reloc.s
@@ -1,4 +1,8 @@
+; uncomment to enable user-friendly "MEMLO is too high" error.
+; adds ~80 bytes to the code size (40% larger).
+ ;verbose_memlo_check = 1
+
.export _main
.include "atari.inc"
@@ -39,6 +43,7 @@ memlo_00:
bcs memlo_ok
+ .ifdef verbose_memlo_check
; whoops, MEMLO is too high
whoops:
ldx #0
@@ -61,22 +66,31 @@ exitwait:
lda #0
sta COLOR2
rts
+ .else
+ lda #$40
+ sta COLOR2
+freeze: bne freeze
+ .endif
memlo_ok:
- ; adjust addresses before moving the code
+ ; adjust addresses before moving the code.
+ ; point to the relocation table...
lda #<table
sta table_ptr
lda #>table
sta table_ptr+1
fixup_addrs:
+ ; walk the reloc table
ldy #1
lda (table_ptr),y
sta code_ptr+1
dey
lda (table_ptr),y
sta code_ptr
- inc table_ptr ; point to next entry
+
+ ; point to next table entry
+ inc table_ptr
bne tp1ok
inc table_ptr+1
tp1ok:
@@ -84,7 +98,8 @@ tp1ok:
bne tp2ok
inc table_ptr+1
tp2ok:
- ora code_ptr+1 ; quit if we hit $0000 in the table
+
+ ora code_ptr+1 ; A still has code_ptr, quit if we hit $0000 in the table
beq fixup_done
lda (code_ptr),y ; Y still 0
sec
@@ -127,7 +142,6 @@ move_loop:
dex
bne move_loop
-
; bump MEMLO to point one byte past the end of the moved code.
lda code_end
sec
@@ -136,12 +150,13 @@ move_loop:
lda code_end+1
sbc code_start+1
sta code_end+1
- inc code_end
- bne ceok
- inc code_end+1 ; code_end is now the code length + 1 byte
-ceok:
+ ;inc code_end
+ ;bne ceok
+ ;inc code_end+1 ; code_end is now the code length + 1 byte
+;ceok:
lda code_end
- clc
+ ;clc
+ sec
adc MEMLO
sta MEMLO
lda code_end+1
@@ -175,11 +190,15 @@ do_init:
done:
rts
+ .ifdef verbose_memlo_check
whoops_msg: .byte "MEMLO is too high! Press any key to exit.", EOL
whoops_len = (*-whoops_msg)
+ .endif
end_addr:
+ .out .sprintf("reloc.s code size $%04x (%d)", (* - start_addr), (* - start_addr))
+
; this was for testing only. mkrelocxex.c adds the init address.
; .word INITAD
; .word INITAD+1