Skip to content

Commit 31ad261

Browse files
authored
fix: relieve code overflow that crashed string operations (#145)
## Problem The resident (non-paged) code section had overflowed past `$C000` into kernel-reserved I/O space by `$95` bytes — the standing `BROKEN BUILD` assembler warning. This stranded `StringTempWrite` across the `$C000` boundary (its body ran into `$C001+`, which the F256 maps to I/O registers, not code). Since `StringTempWrite` is called whenever a **temporary string** is built — string concatenation, `STR$`, `CHR$`, substrings — any such operation executed I/O space as code and crashed the machine. Programs relying on string concatenation crashed. `ashanghai.bas` died on its first concat (`"ashanghai/"+name$+".pal"`) during asset loading. ## Fix Move the boot-only `DisplayBannerText` routine (and its print macros) out of resident code into a slot 3 kernel module, called once at boot via the generated banking thunk. The banner's string/build data stays resident and is read from the module (resident code stays visible from slot 3). This frees ~230 bytes of resident code. Result: the `$C000` overflow is gone, and `StringTempWrite` (now at `$befc`) sits safely below the boundary. ## Verification (MAME) - Build shows **no** `$C000` overflow warning. - Boot banner renders correctly (machine name, info, kernel, build version/timestamp). - `a$="x"+"y"` prints `xy`; `STR$`, `CHR$`, `LEFT$`, `MID$`, `RIGHT$` all work. - `ashanghai.bas` loads all assets and reaches the game. Note: this is a stopgap for the space pressure; the general fix is the paging rework. Signed-off-by: Matthias Brukner <mbrukner@gmail.com>
1 parent 9924166 commit 31ad261

2 files changed

Lines changed: 166 additions & 150 deletions

File tree

source/common/aa.system/00start.asm

Lines changed: 2 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -106,156 +106,8 @@ Start: ldx #$FF ; stack reset
106106
jmp WarmStart
107107
.endif
108108

109-
;;
110-
; Print hardware, ROM & build info at designated banner positions
111-
;;
112-
DisplayBannerText:
113-
.print_machine_name
114-
.print_machine_info
115-
.print_kernel_info
116-
.print_build_version
117-
.print_build_timestamp
118-
119-
; position cursor below the banner
120-
.set_line #Banner.Height-1
121-
.print_char #13
122-
123-
rts
124-
125-
print_char .macro
126-
lda \1
127-
jsr EXTPrintCharacter
128-
.endm
129-
130-
print_hex .macro
131-
lda \1
132-
jsr PrintHex
133-
.endm
134-
135-
set_color .macro
136-
print_char \1+128
137-
.endm
138-
139-
set_column .macro
140-
lda \1
141-
sta EXTColumn
142-
.endm
143-
144-
set_line .macro
145-
lda \1
146-
sta EXTRow
147-
jsr EXTSetCurrentLine
148-
.endm
149-
150-
is_jr .macro
151-
stz $0001
152-
lda $D6A7
153-
and #$10
154-
.endm
155-
156-
print_machine_name .macro
157-
.set_line #Banner.Machine_Name_Line
158-
.set_column #Banner.Machine_Name_Column
159-
.set_color #Banner.Machine_Name_Colors[0]
160-
stz $0001
161-
lda $D6A7
162-
and #$32
163-
cmp #$10
164-
beq _wld
165-
cmp #$22
166-
beq _wld
167-
lda #<Machine_Name_Prefix.FNX
168-
ldx #>Machine_Name_Prefix.FNX
169-
bra +
170-
_wld:
171-
lda #<Machine_Name_Prefix.WLD
172-
ldx #>Machine_Name_Prefix.WLD
173-
+ jsr PrintStringXA
174-
175-
.set_color #Banner.Machine_Name_Colors[1]
176-
stz $0001
177-
lda $D6A7
178-
bit #$10
179-
beq _jr_or_jr2
180-
bit #$02
181-
beq _k2
182-
lda #<Machine_Name.K
183-
ldx #>Machine_Name.K
184-
bra +
185-
_k2:
186-
lda #<Machine_Name.K2
187-
ldx #>Machine_Name.K2
188-
bra +
189-
_jr_or_jr2:
190-
bit #$20
191-
beq _jr
192-
lda #<Machine_Name.Jr2
193-
ldx #>Machine_Name.Jr2
194-
bra +
195-
_jr:
196-
lda #<Machine_Name.Jr
197-
ldx #>Machine_Name.Jr
198-
+ jsr PrintStringXA
199-
200-
.endm
201-
202-
print_machine_info .macro
203-
.set_color #Banner.Machine_Info_Color
204-
.set_line #Banner.Machine_Info_Line
205-
.set_column #Banner.Machine_Info_Column
206-
207-
stz $0001
208-
209-
.print_hex $D6AD
210-
.print_hex $D6AC
211-
.print_hex $D6AB
212-
.print_hex $D6AA
213-
.print_char #' '
214-
.print_char $D6A8
215-
.print_char $D6A9
216-
217-
.print_char #' '
218-
;
219-
; print core version (1x vs 2x)
220-
;
221-
lda #'1' ; default to '1'
222-
bit $D6A7 ; test the 7th bit of machine ID
223-
bpl +
224-
lda #'2'
225-
+ jsr EXTPrintCharacter
226-
.print_char #'x'
227-
228-
.endm
229-
230-
print_kernel_info .macro
231-
.set_color #Banner.Kernel_Info_Color
232-
.set_line #Banner.Kernel_Info_Line
233-
.set_column #Banner.Kernel_Info_Column
234-
235-
lda #$08
236-
ldx #$E0
237-
jsr PrintStringXA
238-
.endm
239-
240-
print_build_version .macro
241-
.set_color #Banner.Build_Version_Color
242-
.set_line #Banner.Build_Version_Line
243-
.set_column #Banner.Build_Version_Column
244-
245-
lda #<Build_Version
246-
ldx #>Build_Version
247-
jsr PrintStringXA
248-
.endm
249-
250-
print_build_timestamp .macro
251-
.set_color #Banner.Build_Timestamp_Color
252-
.set_line #Banner.Build_Timestamp_Line
253-
.set_column #Banner.Build_Timestamp_Column
254-
255-
lda #<Build_Timestamp
256-
ldx #>Build_Timestamp
257-
jsr PrintStringXA
258-
.endm
109+
; Machine name, build version and timestamp data. Kept resident (read by the
110+
; DisplayBannerText code, now in the slot 3 kernel module bannerinfo.asm).
259111

260112
Machine_Name_Prefix .namespace
261113
FNX: .text "FOENIX ", 0
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
; ************************************************************************************************
2+
; ************************************************************************************************
3+
;
4+
; Name: bannerinfo.asm
5+
; Purpose: Print hardware/ROM/build info banner (slot 3 module)
6+
; Created: 10th July 2026
7+
; Author: Matthias Brukner (mbrukner@gmail.com)
8+
;
9+
; Moved out of the resident code section (00start.asm) to relieve the
10+
; non-paged code overflow past $C000. Called once at boot via the
11+
; generated slot-3 thunk. String/build data stays resident in
12+
; 00start.asm and is read from here (resident code is visible).
13+
;
14+
; ************************************************************************************************
15+
; ************************************************************************************************
16+
17+
.section code
18+
19+
;;
20+
; Print hardware, ROM & build info at designated banner positions
21+
;;
22+
Export_DisplayBannerText:
23+
.print_machine_name
24+
.print_machine_info
25+
.print_kernel_info
26+
.print_build_version
27+
.print_build_timestamp
28+
29+
; position cursor below the banner
30+
.set_line #Banner.Height-1
31+
.print_char #13
32+
33+
rts
34+
35+
print_char .macro
36+
lda \1
37+
jsr EXTPrintCharacter
38+
.endm
39+
40+
print_hex .macro
41+
lda \1
42+
jsr PrintHex
43+
.endm
44+
45+
set_color .macro
46+
print_char \1+128
47+
.endm
48+
49+
set_column .macro
50+
lda \1
51+
sta EXTColumn
52+
.endm
53+
54+
set_line .macro
55+
lda \1
56+
sta EXTRow
57+
jsr EXTSetCurrentLine
58+
.endm
59+
60+
print_machine_name .macro
61+
.set_line #Banner.Machine_Name_Line
62+
.set_column #Banner.Machine_Name_Column
63+
.set_color #Banner.Machine_Name_Colors[0]
64+
stz $0001
65+
lda $D6A7
66+
and #$32
67+
cmp #$10
68+
beq _wld
69+
cmp #$22
70+
beq _wld
71+
lda #<Machine_Name_Prefix.FNX
72+
ldx #>Machine_Name_Prefix.FNX
73+
bra +
74+
_wld:
75+
lda #<Machine_Name_Prefix.WLD
76+
ldx #>Machine_Name_Prefix.WLD
77+
+ jsr PrintStringXA
78+
79+
.set_color #Banner.Machine_Name_Colors[1]
80+
stz $0001
81+
lda $D6A7
82+
bit #$10
83+
beq _jr_or_jr2
84+
bit #$02
85+
beq _k2
86+
lda #<Machine_Name.K
87+
ldx #>Machine_Name.K
88+
bra +
89+
_k2:
90+
lda #<Machine_Name.K2
91+
ldx #>Machine_Name.K2
92+
bra +
93+
_jr_or_jr2:
94+
bit #$20
95+
beq _jr
96+
lda #<Machine_Name.Jr2
97+
ldx #>Machine_Name.Jr2
98+
bra +
99+
_jr:
100+
lda #<Machine_Name.Jr
101+
ldx #>Machine_Name.Jr
102+
+ jsr PrintStringXA
103+
104+
.endm
105+
106+
print_machine_info .macro
107+
.set_color #Banner.Machine_Info_Color
108+
.set_line #Banner.Machine_Info_Line
109+
.set_column #Banner.Machine_Info_Column
110+
111+
stz $0001
112+
113+
.print_hex $D6AD
114+
.print_hex $D6AC
115+
.print_hex $D6AB
116+
.print_hex $D6AA
117+
.print_char #' '
118+
.print_char $D6A8
119+
.print_char $D6A9
120+
121+
.print_char #' '
122+
;
123+
; print core version (1x vs 2x)
124+
;
125+
lda #'1' ; default to '1'
126+
bit $D6A7 ; test the 7th bit of machine ID
127+
bpl +
128+
lda #'2'
129+
+ jsr EXTPrintCharacter
130+
.print_char #'x'
131+
132+
.endm
133+
134+
print_kernel_info .macro
135+
.set_color #Banner.Kernel_Info_Color
136+
.set_line #Banner.Kernel_Info_Line
137+
.set_column #Banner.Kernel_Info_Column
138+
139+
lda #$08
140+
ldx #$E0
141+
jsr PrintStringXA
142+
.endm
143+
144+
print_build_version .macro
145+
.set_color #Banner.Build_Version_Color
146+
.set_line #Banner.Build_Version_Line
147+
.set_column #Banner.Build_Version_Column
148+
149+
lda #<Build_Version
150+
ldx #>Build_Version
151+
jsr PrintStringXA
152+
.endm
153+
154+
print_build_timestamp .macro
155+
.set_color #Banner.Build_Timestamp_Color
156+
.set_line #Banner.Build_Timestamp_Line
157+
.set_column #Banner.Build_Timestamp_Column
158+
159+
lda #<Build_Timestamp
160+
ldx #>Build_Timestamp
161+
jsr PrintStringXA
162+
.endm
163+
164+
.send code

0 commit comments

Comments
 (0)