Put a score beside a moving object, label a map or draw a message inside a panel. This routine draws an 8×8 character or a counted string at a pixel position you choose. It uses the existing span backend, so your text and shapes agree about where pixels live.

Include it, then draw a string
Reserve 96 bytes at T plus 48 at BP, separate from code, stack, font, string and bitmap. This complete caller uses 256×192 pixels, T at $0400 and BP at $0380. The bitmap is $0600–$1DFF. The caller owns SAM/VDG setup; this is the monochrome PMODE 4 allocation, with 32 consecutive bytes per scanline.
Define TEXT_WIDTH, TEXT_HEIGHT, TEXT_PEN_MAX and TEXT_PACKED as shown in the caller. Include the text CPU component and its existing span backend once. Mono targets use pen maximum 1 and packed 0; CPC uses 3 and 1. BP must be zero page on 6502; T need not be. Scratch needs no initialisation; public inputs do.
After the display setup, this is an ordinary game call. The mailbox which follows is just how the verifier submits more requests.
Draw PIXEL TEXT at (21,37)
; A normal game call: eight-pixel advance, off-grid origin, opaque label.
ldd #21
std T+0
ldd #37
std T+2
ldd #font_data
std T+4
ldd #label_data
std T+6
ldd #64
std T+11
ldd #0
std T+18
ldd #0
std T+20
ldd #256
std T+22
ldd #192
std T+24
lda #10
sta T+8
lda #65
sta T+9
lda #32
sta T+10
lda #63
sta T+13
lda #1
sta T+14
lda #1
sta T+15
lda #0
sta T+16
jsr text_string
lda #0
sta COMMAND
lda #239
sta COMMAND+1Call text_string, then read T+17. Change X/Y and the string address/length to draw another label. For one character, set T+9 and call text_char; string address and length are then ignored. There is no retained scene, cursor or game loop inside the routine.
The calling contract
Words and the 32-bit count use big-endian order. The origin is the cell’s top-left corner, with Y downwards. Pens are 0–1, selecting stored bitmap bits; the display palette/attributes determine their colours. Both pen inputs must be valid, even when transparent mode does not draw the background.
| T offset | Supply or read |
|---|---|
| 0,2 | Signed 16-bit X,Y origin, each −512..511 |
| 4 | Font address word |
| 6,8 | String address word and byte length 0..255 |
| 9 | Single code byte for text_char |
| 10,11 | First code byte and glyph-count word, 1..256 |
| 13 | Fallback code, which must exist in the font |
| 14 | 0 transparent, 1 opaque |
| 15,16 | Foreground and background pen bytes |
| 17 | Output: 1 accepted, 0 rejected |
| 18,20,22,24 | Scissor left,top,right,bottom words; right/bottom exclusive |
| 26 | Output signed word: next X |
| 28,29 | Output bytes: codes consumed, substitutions |
| 30 | Output word: backend span calls |
| 32 | Output 32-bit destination-byte writes |
| 36–95 | Private scratch |
A string is counted, not zero-terminated. A zero byte is a code; there is no newline, wrapping or implicit case conversion. An empty string is accepted without source reads or drawing, after declaration checks. A glyph always advances by eight: nextX = inputX + 8*consumed, including blank, substituted and fully clipped glyphs. That output is signed 16-bit, not a byte that wraps at 255.
The scissor must be nonempty and inside this physical bitmap. The routine intersects glyph runs with it before calling the backend. A completely clipped valid string still succeeds. Bad coordinates, mode, pens, font range, fallback, scissor or a source/font end beyond $10000 reject before destination writes, with the original X returned and zero counters. An allocation ending exactly at $10000 is allowed by the arithmetic check.
Inputs 0–16 and 18–25 survive. Source ranges must actually be readable in your machine’s current mapping: arithmetic checks cannot establish memory ownership or negotiate a bank switch. Keep the font/string stable and disjoint from code, contexts, stack and destination for the whole call.
Supply a font you own
Each glyph is eight bytes, top row first, bit 7 leftmost. The address of a row is font + (code-first)*8 + row. The optional original Code198x font supplies 64 glyphs for ASCII 32..95, occupying 512 bytes under the sample repository’s MIT licence. It was drawn for these examples, not copied from a machine ROM. Its visible design is five columns by seven rows inside each 8×8 cell.
You can supply a ten-digit font in just 80 bytes, or a contiguous 256-code font in 2,048. First code plus glyph count must not exceed 256; fallback must belong to that range. Unsupported codes use the fallback and increase the substitution count, even when clipped. Lowercase needs its own glyphs or explicit conversion in your caller.
Open the sample font data
Original 64-glyph 8×8 font
; SPDX-License-Identifier: MIT
; Original Code198x diagnostic glyphs, ASCII 32..95. Eight MSB-left rows each.
fcb $00,$00,$00,$00,$00,$00,$00,$00 ; code 32
fcb $10,$10,$10,$10,$10,$00,$10,$00 ; code 33
fcb $28,$28,$28,$00,$00,$00,$00,$00 ; code 34
fcb $28,$7c,$28,$28,$7c,$28,$00,$00 ; code 35
fcb $10,$3c,$50,$38,$14,$78,$10,$00 ; code 36
fcb $64,$68,$08,$10,$20,$2c,$4c,$00 ; code 37
fcb $30,$48,$50,$20,$54,$48,$34,$00 ; code 38
fcb $10,$10,$20,$00,$00,$00,$00,$00 ; code 39
fcb $08,$10,$20,$20,$20,$10,$08,$00 ; code 40
fcb $20,$10,$08,$08,$08,$10,$20,$00 ; code 41
fcb $00,$54,$38,$7c,$38,$54,$00,$00 ; code 42
fcb $00,$10,$10,$7c,$10,$10,$00,$00 ; code 43
fcb $00,$00,$00,$00,$00,$10,$20,$00 ; code 44
fcb $00,$00,$00,$7c,$00,$00,$00,$00 ; code 45
fcb $00,$00,$00,$00,$00,$00,$10,$00 ; code 46
fcb $04,$08,$08,$10,$20,$20,$40,$00 ; code 47
fcb $38,$44,$4c,$54,$64,$44,$38,$00 ; code 48
fcb $10,$30,$10,$10,$10,$10,$38,$00 ; code 49
fcb $38,$44,$04,$08,$10,$20,$7c,$00 ; code 50
fcb $78,$04,$04,$38,$04,$04,$78,$00 ; code 51
fcb $08,$18,$28,$48,$7c,$08,$08,$00 ; code 52
fcb $7c,$40,$40,$78,$04,$04,$78,$00 ; code 53
fcb $38,$40,$40,$78,$44,$44,$38,$00 ; code 54
fcb $7c,$04,$08,$10,$20,$20,$20,$00 ; code 55
fcb $38,$44,$44,$38,$44,$44,$38,$00 ; code 56
fcb $38,$44,$44,$3c,$04,$04,$38,$00 ; code 57
fcb $00,$10,$00,$00,$10,$00,$00,$00 ; code 58
fcb $00,$10,$00,$00,$10,$10,$20,$00 ; code 59
fcb $04,$08,$10,$20,$10,$08,$04,$00 ; code 60
fcb $00,$00,$7c,$00,$7c,$00,$00,$00 ; code 61
fcb $40,$20,$10,$08,$10,$20,$40,$00 ; code 62
fcb $38,$44,$04,$08,$10,$00,$10,$00 ; code 63
fcb $38,$44,$5c,$54,$5c,$40,$38,$00 ; code 64
fcb $38,$44,$44,$7c,$44,$44,$44,$00 ; code 65
fcb $78,$44,$44,$78,$44,$44,$78,$00 ; code 66
fcb $38,$44,$40,$40,$40,$44,$38,$00 ; code 67
fcb $78,$44,$44,$44,$44,$44,$78,$00 ; code 68
fcb $7c,$40,$40,$78,$40,$40,$7c,$00 ; code 69
fcb $7c,$40,$40,$78,$40,$40,$40,$00 ; code 70
fcb $38,$44,$40,$5c,$44,$44,$3c,$00 ; code 71
fcb $44,$44,$44,$7c,$44,$44,$44,$00 ; code 72
fcb $38,$10,$10,$10,$10,$10,$38,$00 ; code 73
fcb $1c,$08,$08,$08,$48,$48,$30,$00 ; code 74
fcb $44,$48,$50,$60,$50,$48,$44,$00 ; code 75
fcb $40,$40,$40,$40,$40,$40,$7c,$00 ; code 76
fcb $44,$6c,$54,$54,$44,$44,$44,$00 ; code 77
fcb $44,$64,$64,$54,$4c,$4c,$44,$00 ; code 78
fcb $38,$44,$44,$44,$44,$44,$38,$00 ; code 79
fcb $78,$44,$44,$78,$40,$40,$40,$00 ; code 80
fcb $38,$44,$44,$44,$54,$48,$34,$00 ; code 81
fcb $78,$44,$44,$78,$50,$48,$44,$00 ; code 82
fcb $3c,$40,$40,$38,$04,$04,$78,$00 ; code 83
fcb $7c,$10,$10,$10,$10,$10,$10,$00 ; code 84
fcb $44,$44,$44,$44,$44,$44,$38,$00 ; code 85
fcb $44,$44,$44,$44,$44,$28,$10,$00 ; code 86
fcb $44,$44,$44,$54,$54,$6c,$44,$00 ; code 87
fcb $44,$44,$28,$10,$28,$44,$44,$00 ; code 88
fcb $44,$44,$28,$10,$10,$10,$10,$00 ; code 89
fcb $7c,$04,$08,$10,$20,$40,$7c,$00 ; code 90
fcb $38,$20,$20,$20,$20,$20,$38,$00 ; code 91
fcb $40,$20,$20,$10,$08,$08,$04,$00 ; code 92
fcb $38,$08,$08,$08,$08,$08,$38,$00 ; code 93
fcb $10,$28,$44,$00,$00,$00,$00,$00 ; code 94
fcb $00,$00,$00,$00,$00,$00,$7c,$00 ; code 95Translation and byte boundaries
Glyph-local (3,5) at origin (21,37) lands at (24,42). The next cell starts at X=29. A blank space moves the next cell too: ink, cell bounds and advance are different things. Move a glyph, keep its shape works through that translation, clipping and division/remainder without requiring an algebra course.
Eight pixels at an arbitrary X can touch two mono bytes, or three four-pixel CPC bytes. The component finds foreground runs in each glyph row and sends them to bp_hspan. Transparent mode leaves zero font bits alone. Opaque mode paints the cell’s background row first, then its foreground runs; it replaces the visible clipped cell, including the blank rows/columns.
For the ten-code PIXEL TEXT, transparent drawing at X=24 and X=31 makes 77 / 77 destination-byte writes; opaque makes 157 / 237. Foreground uses 77 spans; opaque adds 80 background spans. Gaps and edge masks affect those counts, so an unaligned cell is not automatically more expensive in every workload.
This baseline favours understandable composition. Opaque drawing touches foreground bytes again after clearing their background. A masked KEEP/image blitter could combine those operations; pre-shifted glyph phases trade more font storage for less shifting/address work. Compare masked sprites and pre-shifted sprites. Those are design choices to measure, not invisible upgrades to this routine.
The text component assembles to 2,058 bytes, plus 470 for the backend, the chosen font/string and the contexts. Reset setup, display and stack are additional. These are storage and byte-write measurements, not cycle counts or a frame-budget promise.
Own the display and scratch
Clobbers: D/X/Y/CC; U and DP survive. Reserve a conservative 64-byte stack budget beyond your other calls/interrupts. T and BP are non-re-entrant. No call changes interrupt state, waits for a frame or synchronises video. On 6502, text temporarily uses BP+46/47 for indirect source reads, with no live source pointer carried over a span call. The caller owns banks, display access and interruption/coexistence policy.
Open the reusable 6809 text component
Include the text component once alongside its backend
; SPDX-License-Identifier: MIT
; Original 8x8 fixed-width text using bp_hspan; no display/font/OS setup.
; T: 96 private bytes; BP: separate 48 bytes (zero page on 6502).
; All registers/flags used by the backend may change. Non-re-entrant.
; See README.md for trusted source allocations, pens, bounds and outputs.
t_x equ T+0
t_y equ T+2
t_font equ T+4
t_source equ T+6
t_length equ T+8
t_code equ T+9
t_first equ T+10
t_count equ T+11
t_fallback equ T+13
t_mode equ T+14
t_fg equ T+15
t_bg equ T+16
t_status equ T+17
t_clip_l equ T+18
t_clip_t equ T+20
t_clip_r equ T+22
t_clip_b equ T+24
t_next_x equ T+26
t_consumed equ T+28
t_missing equ T+29
t_calls equ T+30
t_writes equ T+32
t_entry equ T+36
t_limit equ T+37
t_i equ T+38
t_index equ T+40
t_end equ T+42
t_pointer equ T+44
t_row equ T+46
t_column equ T+47
t_bits equ T+48
t_run equ T+49
t_start equ T+50
t_left equ T+52
t_right equ T+54
t_py equ T+56
t_pen equ T+58
t_temp equ T+60
t_work equ T+64
t_cmp equ T+95
bp_x0 equ BP+0
bp_y0 equ BP+2
bp_x1 equ BP+4
bp_op equ BP+8
bp_pen equ BP+11
bp_writes equ BP+40
g_cmp equ T+95
text_char
lda #$00
sta t_entry
jmp text_enter
text_string
lda #$01
sta t_entry
jmp text_enter
text_enter
lda #$00
sta t_status
lda #$00
sta t_writes+3
lda #$00
sta t_writes+2
lda #$00
sta t_writes+1
lda #$00
sta t_writes
ldd #$0000
std t_calls
lda #$00
sta t_consumed
lda #$00
sta t_missing
ldd t_x
std t_next_x
; Validate the complete declaration before drawing; no source read yet.
lda #$fe
eora #$80
sta g_cmp
lda t_x
eora #$80
cmpa g_cmp
lblo text_done
lbne text_branch_1
lda #$00
sta g_cmp
lda t_x+1
cmpa g_cmp
lblo text_done
text_branch_1
lda #$01
eora #$80
sta g_cmp
lda t_x
eora #$80
cmpa g_cmp
lblo text_branch_2
lbne text_done
lda #$ff
sta g_cmp
lda t_x+1
cmpa g_cmp
lblo text_branch_2
lbne text_done
text_branch_2
lda #$fe
eora #$80
sta g_cmp
lda t_y
eora #$80
cmpa g_cmp
lblo text_done
lbne text_branch_3
lda #$00
sta g_cmp
lda t_y+1
cmpa g_cmp
lblo text_done
text_branch_3
lda #$01
eora #$80
sta g_cmp
lda t_y
eora #$80
cmpa g_cmp
lblo text_branch_4
lbne text_done
lda #$ff
sta g_cmp
lda t_y+1
cmpa g_cmp
lblo text_branch_4
lbne text_done
text_branch_4
lda #$01
sta g_cmp
lda t_mode
cmpa g_cmp
lblo text_branch_5
lbne text_done
text_branch_5
ldd #$0000
std t_temp
lda t_fg
sta t_temp+1
ldd #TEXT_PEN_MAX
std t_end
lda t_end
sta g_cmp
lda t_temp
cmpa g_cmp
lblo text_branch_6
lbne text_done
lda t_end+1
sta g_cmp
lda t_temp+1
cmpa g_cmp
lblo text_branch_6
lbne text_done
text_branch_6
ldd #$0000
std t_temp
lda t_bg
sta t_temp+1
ldd #TEXT_PEN_MAX
std t_end
lda t_end
sta g_cmp
lda t_temp
cmpa g_cmp
lblo text_branch_7
lbne text_done
lda t_end+1
sta g_cmp
lda t_temp+1
cmpa g_cmp
lblo text_branch_7
lbne text_done
text_branch_7
lda #$00
eora #$80
sta g_cmp
lda t_clip_l
eora #$80
cmpa g_cmp
lblo text_done
lbne text_branch_8
lda #$00
sta g_cmp
lda t_clip_l+1
cmpa g_cmp
lblo text_done
text_branch_8
lda #$00
eora #$80
sta g_cmp
lda t_clip_t
eora #$80
cmpa g_cmp
lblo text_done
lbne text_branch_9
lda #$00
sta g_cmp
lda t_clip_t+1
cmpa g_cmp
lblo text_done
text_branch_9
lda t_clip_r
eora #$80
sta g_cmp
lda t_clip_l
eora #$80
cmpa g_cmp
lblo text_branch_10
lbne text_done
lda t_clip_r+1
sta g_cmp
lda t_clip_l+1
cmpa g_cmp
lblo text_branch_10
jmp text_done
text_branch_10
lda t_clip_b
eora #$80
sta g_cmp
lda t_clip_t
eora #$80
cmpa g_cmp
lblo text_branch_11
lbne text_done
lda t_clip_b+1
sta g_cmp
lda t_clip_t+1
cmpa g_cmp
lblo text_branch_11
jmp text_done
text_branch_11
ldd #TEXT_WIDTH
std t_end
lda t_end
sta g_cmp
lda t_clip_r
cmpa g_cmp
lblo text_branch_12
lbne text_done
lda t_end+1
sta g_cmp
lda t_clip_r+1
cmpa g_cmp
lblo text_branch_12
lbne text_done
text_branch_12
ldd #TEXT_HEIGHT
std t_end
lda t_end
sta g_cmp
lda t_clip_b
cmpa g_cmp
lblo text_branch_13
lbne text_done
lda t_end+1
sta g_cmp
lda t_clip_b+1
cmpa g_cmp
lblo text_branch_13
lbne text_done
text_branch_13
lda #$00
sta g_cmp
lda t_count
cmpa g_cmp
lbne text_branch_14
lda #$00
sta g_cmp
lda t_count+1
cmpa g_cmp
lbne text_branch_14
jmp text_done
text_branch_14
lda #$01
sta g_cmp
lda t_count
cmpa g_cmp
lblo text_branch_15
lbne text_done
lda #$00
sta g_cmp
lda t_count+1
cmpa g_cmp
lblo text_branch_15
lbne text_done
text_branch_15
ldd #$0000
std t_end
lda t_first
sta t_end+1
ldd t_end
addd t_count
std t_end
lda #$01
sta g_cmp
lda t_end
cmpa g_cmp
lblo text_branch_16
lbne text_done
lda #$00
sta g_cmp
lda t_end+1
cmpa g_cmp
lblo text_branch_16
lbne text_done
text_branch_16
ldd #$0000
std t_index
lda t_fallback
sta t_index+1
ldd #$0000
std t_temp
lda t_first
sta t_temp+1
lda t_temp
sta g_cmp
lda t_index
cmpa g_cmp
lblo text_done
lbne text_branch_17
lda t_temp+1
sta g_cmp
lda t_index+1
cmpa g_cmp
lblo text_done
text_branch_17
lda t_end
sta g_cmp
lda t_index
cmpa g_cmp
lblo text_branch_18
lbne text_done
lda t_end+1
sta g_cmp
lda t_index+1
cmpa g_cmp
lblo text_branch_18
jmp text_done
text_branch_18
ldd t_count
std t_temp
lsl t_temp+1
rol t_temp
lsl t_temp+1
rol t_temp
lsl t_temp+1
rol t_temp
ldd t_temp
addd t_font
std t_temp
lda #$00
sta g_cmp
lda t_temp
cmpa g_cmp
lbne text_branch_20
lda #$00
sta g_cmp
lda t_temp+1
cmpa g_cmp
lbne text_branch_20
jmp text_branch_19
text_branch_20
lda t_font
sta g_cmp
lda t_temp
cmpa g_cmp
lblo text_done
lbne text_branch_21
lda t_font+1
sta g_cmp
lda t_temp+1
cmpa g_cmp
lblo text_done
text_branch_21
text_branch_19
lda #$01
sta t_limit
lda #$00
sta g_cmp
lda t_entry
cmpa g_cmp
lbne text_branch_23
jmp text_branch_22
text_branch_23
lda t_length
sta t_limit
ldd #$0000
std t_temp
lda t_length
sta t_temp+1
ldd t_temp
addd t_source
std t_temp
lda #$00
sta g_cmp
lda t_temp
cmpa g_cmp
lbne text_branch_25
lda #$00
sta g_cmp
lda t_temp+1
cmpa g_cmp
lbne text_branch_25
jmp text_branch_24
text_branch_25
lda t_source
sta g_cmp
lda t_temp
cmpa g_cmp
lblo text_done
lbne text_branch_26
lda t_source+1
sta g_cmp
lda t_temp+1
cmpa g_cmp
lblo text_done
text_branch_26
text_branch_24
text_branch_22
lda #$01
sta t_status
lda #$00
sta t_i
text_glyph
lda t_limit
sta g_cmp
lda t_i
cmpa g_cmp
lblo text_branch_27
jmp text_done
text_branch_27
lda #$00
sta g_cmp
lda t_entry
cmpa g_cmp
lbne text_branch_30
jmp text_branch_28
text_branch_30
ldd #$0000
std t_pointer
lda t_i
sta t_pointer+1
ldd t_pointer
addd t_source
std t_pointer
ldx t_pointer
lda ,x
sta t_index+1
ldd #$0000
std t_temp
lda #$00
sta t_index
jmp text_branch_29
text_branch_28
ldd #$0000
std t_index
lda t_code
sta t_index+1
text_branch_29
ldd #$0000
std t_temp
lda t_first
sta t_temp+1
lda t_temp
sta g_cmp
lda t_index
cmpa g_cmp
lblo text_branch_31
lbne text_branch_33
lda t_temp+1
sta g_cmp
lda t_index+1
cmpa g_cmp
lblo text_branch_31
text_branch_33
ldd t_index
subd t_temp
std t_index
lda t_count
sta g_cmp
lda t_index
cmpa g_cmp
lblo text_branch_32
lbne text_branch_34
lda t_count+1
sta g_cmp
lda t_index+1
cmpa g_cmp
lblo text_branch_32
text_branch_34
text_branch_31
ldd #$0000
std t_index
lda t_fallback
sta t_index+1
ldd #$0000
std t_temp
lda t_first
sta t_temp+1
ldd t_index
subd t_temp
std t_index
lda t_missing
adda #$01
sta t_missing
text_branch_32
lsl t_index+1
rol t_index
lsl t_index+1
rol t_index
lsl t_index+1
rol t_index
ldd t_font
std t_pointer
ldd t_pointer
addd t_index
std t_pointer
lda #$00
sta t_row
text_row
lda #$08
sta g_cmp
lda t_row
cmpa g_cmp
lblo text_branch_35
jmp text_next_glyph
text_branch_35
ldd t_y
std t_py
ldd #$0000
std t_temp
lda t_row
sta t_temp+1
ldd t_py
addd t_temp
std t_py
lda #$00
sta g_cmp
lda t_mode
cmpa g_cmp
lbne text_branch_37
jmp text_branch_36
text_branch_37
ldd t_next_x
std t_left
ldd t_next_x
std t_right
ldd t_right
addd #$0008
std t_right
lda t_bg
sta t_pen
jsr text_span
text_branch_36
ldx t_pointer
lda ,x
sta t_bits
ldd t_pointer
addd #$0001
std t_pointer
lda #$00
sta t_column
lda #$00
sta t_run
text_bit
lda #$08
sta g_cmp
lda t_column
cmpa g_cmp
lblo text_branch_38
jmp text_row_end
text_branch_38
lda t_bits
anda #$80
lbeq text_branch_39
lda #$00
sta g_cmp
lda t_run
cmpa g_cmp
lbne text_branch_40
text_branch_41
lda t_column
sta t_start
lda #$01
sta t_run
jmp text_branch_40
text_branch_39
lda #$00
sta g_cmp
lda t_run
cmpa g_cmp
lbne text_branch_42
jmp text_branch_40
text_branch_42
jsr text_run
lda #$00
sta t_run
text_branch_40
lsl t_bits
lda t_column
adda #$01
sta t_column
jmp text_bit
text_row_end
lda #$00
sta g_cmp
lda t_run
cmpa g_cmp
lbne text_branch_44
jmp text_branch_43
text_branch_44
jsr text_run
text_branch_43
lda t_row
adda #$01
sta t_row
jmp text_row
text_next_glyph
ldd t_next_x
addd #$0008
std t_next_x
lda t_i
adda #$01
sta t_i
lda t_i
sta t_consumed
jmp text_glyph
text_done
rts
text_run
ldd #$0000
std t_left
lda t_start
sta t_left+1
ldd t_left
addd t_next_x
std t_left
ldd #$0000
std t_right
lda t_column
sta t_right+1
ldd t_right
addd t_next_x
std t_right
lda t_fg
sta t_pen
jmp text_span
text_span
; Intersect a half-open run with the validated physical-screen scissor.
lda t_clip_t
eora #$80
sta g_cmp
lda t_py
eora #$80
cmpa g_cmp
lblo text_span_done
lbne text_branch_45
lda t_clip_t+1
sta g_cmp
lda t_py+1
cmpa g_cmp
lblo text_span_done
text_branch_45
lda t_clip_b
eora #$80
sta g_cmp
lda t_py
eora #$80
cmpa g_cmp
lblo text_branch_46
lbne text_span_done
lda t_clip_b+1
sta g_cmp
lda t_py+1
cmpa g_cmp
lblo text_branch_46
jmp text_span_done
text_branch_46
lda t_clip_l
eora #$80
sta g_cmp
lda t_right
eora #$80
cmpa g_cmp
lblo text_span_done
lbne text_branch_47
lda t_clip_l+1
sta g_cmp
lda t_right+1
cmpa g_cmp
lblo text_span_done
lbeq text_span_done
text_branch_47
lda t_clip_r
eora #$80
sta g_cmp
lda t_left
eora #$80
cmpa g_cmp
lblo text_branch_48
lbne text_span_done
lda t_clip_r+1
sta g_cmp
lda t_left+1
cmpa g_cmp
lblo text_branch_48
jmp text_span_done
text_branch_48
lda t_clip_l
eora #$80
sta g_cmp
lda t_left
eora #$80
cmpa g_cmp
lblo text_branch_50
lbne text_branch_49
lda t_clip_l+1
sta g_cmp
lda t_left+1
cmpa g_cmp
lblo text_branch_50
jmp text_branch_49
text_branch_50
ldd t_clip_l
std t_left
text_branch_49
lda t_clip_r
eora #$80
sta g_cmp
lda t_right
eora #$80
cmpa g_cmp
lblo text_branch_51
lbne text_branch_52
lda t_clip_r+1
sta g_cmp
lda t_right+1
cmpa g_cmp
lblo text_branch_51
lbeq text_branch_51
text_branch_52
ldd t_clip_r
std t_right
text_branch_51
ldd t_left
std bp_x0
ldd t_right
std bp_x1
ldd t_py
std bp_y0
ifne TEXT_PACKED
lda #$00
sta bp_op
lda t_pen
sta bp_pen
else
lda #$01
sta bp_op
lda #$00
sta g_cmp
lda t_pen
cmpa g_cmp
lbne text_branch_54
jmp text_branch_53
text_branch_54
lda #$00
sta bp_op
text_branch_53
endc
jsr bp_hspan
lda #$00
sta t_work+3
lda #$00
sta t_work+2
lda #$00
sta t_work+1
lda #$00
sta t_work
lda bp_writes+1
sta t_work+3
lda bp_writes
sta t_work+2
lda t_writes+3
adda t_work+3
sta t_writes+3
lda t_writes+2
adca t_work+2
sta t_writes+2
lda t_writes+1
adca t_work+1
sta t_writes+1
lda t_writes
adca t_work
sta t_writes
ldd t_calls
addd #$0001
std t_calls
text_span_done
rts
text_endWhat was verified
76 calls completed using Asm198x 0.0.71 and native Emu198x 0.39.0 in this original reset configuration. Every call compares the full bitmap, guards, font/string preservation, inputs, acceptance, advance, consumption/substitutions and work counters with an independent pixel model. Cases include phases, negative origins, scissor edges, all pen pairs, empty/long strings, fallback, 256-code fonts and rejected declarations. Selected whole native frames also match independently composed pixels.
Wrong glyph-bit and string-advance builds each completed accepted calls and failed both memory and picture checks. Retained records are bound to source and exact tools, with failure tests for missing/corrupted evidence. This establishes the stated reset fixture; stock-OS loading, real-hardware timing and tear-free live drawing need their own checks.
- Complete caller and execution evidence
- Full contract, costs and MIT attribution
- Compare text paths
- Underlying pixels and spans
Make the letters bigger
A title need not use the same tiny cells as a score. Repeat each source pixel twice in both directions and an 8×8 cell becomes 16×16. Use different factors for deliberately wide or tall lettering: 3×2 gives a 24×16 cell. The font still stores just eight bytes per glyph.

Choose scaled-text/6809.inc instead of the fixed bitmap-text CPU include. It exports the same text_char and text_string labels, so include only one. Keep this machine’s existing backend and required helper/tables. The allocations remain 96 bytes at T plus 48 at BP. Add two explicit inputs: T+68 is scale X and T+69 is scale Y, each an integer from 1 to 4. Set both, even for 1×1; an old fixed-width caller leaves those bytes uninitialised.
Initialise font, pens, scissor and both scales before text_string
; SPDX-License-Identifier: MIT
; A normal game call: enlarged glyph cells, off-grid origin, opaque label.
ldd #21
std T+0
ldd #37
std T+2
ldd #font_data
std T+4
ldd #label_data
std T+6
ldd #64
std T+11
ldd #0
std T+18
ldd #0
std T+20
ldd #256
std T+22
ldd #192
std T+24
lda #MESSAGE_LENGTH
sta T+8
lda #65
sta T+9
lda #32
sta T+10
lda #63
sta T+13
lda #1
sta T+14
lda #1
sta T+15
lda #0
sta T+16
lda #SCALE_X
sta T+68
lda #SCALE_Y
sta T+69
jsr text_stringThe existing font/range, fallback, source/count, mode, pens and scissor contract still applies. Inputs T+0..16, +18..25 and +68..69 survive. T+17 reports acceptance; T+26 returns X + length×8×scaleX as a word. Clipped, blank and fallback codes still advance. At scale X=4, 255 codes advance 8,160 pixels; a byte would lose most of that result. A rejected declaration preserves the original X and returns zero consumed, fallback, span and write counts before any destination writes.
Each font pixel becomes a rectangle, rather than a smoothed edge. For a destination-local pixel, the source position is (x div scaleX, y div scaleY). Equivalently, source column 3 at scale X=2 occupies local columns 6 and 7. Add the cell origin, then clip. A cut-off letter keeps that sampling phase: it does not start again at font column zero at the clipping edge. Integer division and remainders and glyph-local coordinates explain those two steps.
The native code scales the endpoints of each foreground run and repeats source rows. The independent checker instead samples destination pixels using integer division. Transparent zero bits preserve the picture underneath; opaque mode paints the enlarged background cell first, then its ink. Opaque spaces therefore clear their whole enlarged cells. Neither mode clears unused panel space.
Make it your own: wide lettering
The maintained custom caller changes 2×2 to 3×2 and replaces the ten-byte PIXEL TEXT message with four-byte BIG!. Its cells become 24×16, and the four-code label advances 96 pixels. The font and workspace sizes stay the same. Change the counted length with the message.
Choose independent X/Y enlargement and a counted label
; SPDX-License-Identifier: MIT
CUSTOM_TEXT equ 1
SCALE_X equ 3
SCALE_Y equ 2
MESSAGE_LENGTH equ 4
include "caller.inc"
Use 1×4 or 4×1 for other shapes; all sixteen pairs are executed. These factors describe logical pixels. Equal X/Y factors preserve the native raster’s pixel proportions, which are not necessarily square on a physical display. The captures do not calibrate a television’s aspect ratio.
Bigger glyphs, but an old drawing step
The following fragment is deliberately wrong. The glyph is now 16 pixels wide, but the next origin still moves eight. WAVE overlaps its neighbours. In opaque mode, a later background cell can erase part of the preceding letter.
Deliberately wrong: keep an eight-pixel advance
; BEGIN WRONG
ldd t_next_x
addd #8
std t_next_x
Restore the cached 8×scaleX advance, then check both the final X and the full picture:
Correct: move by the enlarged cell width
; BEGIN FIX
ldd t_next_x
addd t_advance
std t_next_x
Size has a drawing cost
The scaled component uses 2,590 code bytes with the qualified assembler; the backend remains 470. The original sample font is still 512 bytes, and T/BP remain 96+48. BBC scanline tables, display memory, caller, string and stack remain separate. Keep a conservative 64-byte stack budget plus your caller/interrupt depth, and the renderer’s CPU/register obligations above.
For the same original W! label at (21,37), opaque mode and the same pens, native counters report. Cell dimensions are logical pixels:
| Scale | Cell (px) | Spans | Byte writes |
|---|---|---|---|
| 1×1 | 8×8 | 38 | 54 |
| 2×2 | 16×16 | 76 | 168 |
| 3×3 | 24×24 | 114 | 282 |
| 4×4 | 32×32 | 152 | 416 |
Doubling both factors quadruples a cell’s background area. Horizontal enlargement widens runs and changes byte crossings; vertical enlargement repeats rows and spans. CPC packs four pen indices per byte while the mono backends pack eight pixels, so their write counts differ. Counters include repeated writes to a byte. They measure drawing work, not cycles or a frame budget.
A separate pre-rendered size costs more assets but can avoid runtime expansion. Pre-shifted/masked blitters or precomposed hardware characters offer other trade-offs. Fully clipped cells skip raster work after resolving fallback, retaining logical advance and consumed/missing counts. This avoids expanding invisible rows in long offscreen strings.
The component owns T/BP, is non-re-entrant and supplies no OS negotiation, banking, interrupt protection or safe display interval. Keep source, font, code, contexts, stack and bitmap distinct and stable. This is a direct character/string renderer: the current fixed/proportional text-layout wrappers assume eight-pixel cells and row heights and cannot simply be placed over this include. A scaled layout must agree on both dimensions. Scaled wrapping, baselines and kerning remain separate work. The bounded shrinking routine below resamples ink inside an eight-byte cell. The glyph transform below supplies flips and quarter-turns before drawing.
The complete source and retained records contain 155 positive native calls, the customisation and completed wrong/fixed observations. Full bitmap allocations, neighbours, public outputs, counted source/font immutability and selected entire native frames match independent expectations. Coverage includes all scale pairs, every horizontal bit phase, pens, partial/full clipping, empty/255-code input, a 256-glyph declaration and invalid declarations. Qualified tools are Asm198x 0.0.71 and Emu198x 0.41.0 for this named reset/display path; original hardware, stock-OS coexistence, live tearing and other modes need separate checks.
Turn or reflect a glyph
An arrow can point in four directions without four hand-drawn assets. This separate 6809 glyph_transform routine takes eight row bytes and writes eight transformed bytes. It can turn by 0°, 90°, 180° or 270° clockwise, then optionally reflect horizontally. It does not draw or rotate the arrangement of a string.

Define F as 32 writable bytes, include cross-platform/patterns/rendering/glyph-transform/6809.inc once, and set the source address, destination address and flags before calling glyph_transform. No extra zero-page or direct-page allocation is required. The complete caller owns the same display setup and text backend as the enlarged example above.
Transform eight bytes, then draw the result
; SPDX-License-Identifier: MIT
ldd #font_data+304
std F
ldd #8320
std F+2
lda #GLYPH_FLAGS
sta F+4
jsr glyph_transform
; SPDX-License-Identifier: MIT
; A normal game call: enlarged glyph cells, off-grid origin, opaque label.
ldd #21
std T+0
ldd #37
std T+2
ldd #8320
std T+4
ldd #label_data
std T+6
ldd #1
std T+11
ldd #0
std T+18
ldd #0
std T+20
ldd #256
std T+22
ldd #192
std T+24
lda #MESSAGE_LENGTH
sta T+8
lda #65
sta T+9
lda #65
sta T+10
lda #65
sta T+13
lda #1
sta T+14
lda #1
sta T+15
lda #0
sta T+16
lda #SCALE_X
sta T+68
lda #SCALE_Y
sta T+69
jsr text_stringThe first call produces a one-glyph font in RAM. The rest declares that font to the existing renderer and draws it. The source is our original F glyph; the one-glyph output is deliberately assigned code 65. Change the source address to reuse the component for your own icon. No other part of the font is required by the transform.
| F offset | Supply or read |
|---|---|
| 0 | Source address word, eight readable bytes |
| 2 | Destination address word, eight writable bytes |
| 4 | Flags 0..7: quarter-turns in bits 0..1, horizontal reflection in bit 2 |
| 5 | Output: 1 completed, 0 rejected |
| 6..31 | Private scratch, including an eight-byte snapshot |
Use big-endian words. Inputs 0..4 survive. Flags above 7, or either address above $FFF8, reject before source/destination access. An allocation ending exactly at $10000 passes the arithmetic check; you still own its mapping and access permissions. Keep F, code and stack disjoint from both glyph buffers. Source and destination may overlap, including exact in-place operation: the routine snapshots all eight rows before clearing output.
Clobbers: D/X and CC; Y/U/DP survive. Scratch is non-re-entrant. Reserve a conservative 16 stack bytes beyond the caller and interrupt requirements. The routine changes no interrupt policy or display state. An interrupt handler must preserve live registers and leave its buffers and scratch alone. The later drawing call retains the renderer’s separate stack and hardware obligations.
The top-left dot must move to the top-right
Coordinates inside the glyph run from 0 to 7, with Y down. A clockwise quarter-turn maps (x,y) to (7−y,x): local (0,0) becomes (7,0). Twice gives (7−x,7−y); three turns gives (y,7−x); four returns the original. Reflection then maps final X to 7−X. Doing the reflection first generally gives a different result.
The transformed glyph still occupies an 8×8 cell. Scale 4 makes it a 32×32 drawn cell; translation places it at the chosen screen origin. Layout advance and the order of characters do not rotate. Proportional widths and bearings need their own matching metrics; they are not updated by turning the ink. The Maths for Games overview places this alongside planned transform coverage without requiring that future lesson to use the routine.
Make it your own: a reflected icon
Change GLYPH_FLAGS from 1 to 4: no turn, then horizontal reflection. The stem of F moves to the right and its top bar stays horizontal. The input/output sizes and reusable component stay the same.
Reflect the same source glyph
; SPDX-License-Identifier: MIT
CUSTOM_TEXT equ 1
SCALE_X equ 4
SCALE_Y equ 4
MESSAGE_LENGTH equ 1
GLYPH_FLAGS equ 4
include "caller.inc"
To retain a whole transformed font, call once per glyph and move both pointers by eight. Check the whole bank in your caller. Per-glyph overlap safety does not make an overlapping bank traversal safe: one result could overwrite the next source glyph. Use separate banks or arrange traversal/snapshots deliberately.
Common mistake: a diagonal reflection instead of a turn
Swapping X and Y alone produces (y,x). That is a transpose: on this F, the long top bar points down from the left instead of becoming the right-hand vertical bar. The wrong routine returns success and stays inside its output buffer. Neither property proves that its picture is right.
Deliberately wrong mapping:
Swap coordinates without reversing an axis
; BEGIN WRONG
lda f_dy
sta f_dx
Restore the missing 7−y:
Turn the glyph clockwise
; BEGIN FIX
lda #$07
sta f_dx
lda f_dx
suba f_dy
sta f_dx
Pay once, cache, or store the variants
The transform component occupies 448 bytes, including its eight masks; it needs 32 bytes at F, eight bytes for each retained result. Font, renderer, backend, bitmap, caller and stack are additional.
A valid call reads eight source bytes into its snapshot, clears eight output bytes and scans all 64 source pixels. Each set pixel then reads and writes its destination byte. These are glyph-buffer operations, not all CPU accesses or cycle timings. More quarter-turns add coordinate arithmetic per set pixel. The original F contains 14 set pixels, so it makes that many destination read/modify/write operations after the eight clears.
Cache the result while it is useful, or prepare the variants at build time. Eight orientations cost 64 bytes per glyph rather than eight; eight whole 64-glyph banks cost 4,096 rather than 512. Stored variants avoid this transform call but still need drawing or transfer work. A hardware flip can be a better choice where the native display supports one; these bitmap backends do not gain that facility from this routine. No cycle or frame-budget claim follows from a correct still image.
All eight transforms preserve every source bit exactly. Arbitrary-angle rotation, larger pictures and pixel-aspect correction remain separate extensions. The bounded shrinking routine below supplies one explicit sampling policy.
What the transform checks establish
596 native observations completed on this machine with Asm198x 0.0.71 and Emu198x 0.41.0: all eight orientations, every single source pixel, asymmetric/full/empty glyphs, partial/exact overlap, invalid flags and wrapping addresses, plus normal, customised, faulty and repaired paths. Complete glyph/source/guard memory and selected full bitmap/native frames match an independent matrix-based oracle. The wrong rotation completed and failed the correct-image comparison; the repaired build matches the positive binary.
This is the same original reset configuration as the enlargement example, with exclusive ownership of the display and buffers. Stock OS integration, original hardware, interrupt coexistence and cycle timing need separate qualification. Retained replay binds source and tools and rejects incomplete, missing, corrupted and rehashed-but-wrong evidence.
Open the glyph transform routine
Transform a glyph independently of the display
; SPDX-License-Identifier: MIT
; Transform one MSB-left 8x8 glyph. F = 32 caller-owned RAM bytes.
; 6502 additionally needs GP = two zero-page bytes, disjoint from F and data.
; Flags 0..3 clockwise quarter-turns, bit 2 horizontal reflection AFTER rotation.
; Snapshot input before any output; overlapping source/destination is supported.
f_source equ F+0
f_dest equ F+2
f_flags equ F+4
f_status equ F+5
f_ptr equ F+6
f_x equ F+8
f_y equ F+9
f_dx equ F+10
f_dy equ F+11
f_bits equ F+12
f_mask equ F+13
f_turns equ F+14
f_i equ F+15
f_copy equ F+16
f_tmp equ F+24
f_cmp equ F+31
glyph_cmp equ F+31
glyph_transform
lda #$00
sta f_status
lda #$07
sta glyph_cmp
lda f_flags
cmpa glyph_cmp
lblo glyph_branch_1
lbne glyph_done
glyph_branch_1
lda #$ff
sta glyph_cmp
lda f_source
cmpa glyph_cmp
lblo glyph_branch_2
lbne glyph_done
lda #$f8
sta glyph_cmp
lda f_source+1
cmpa glyph_cmp
lblo glyph_branch_2
lbne glyph_done
glyph_branch_2
lda #$ff
sta glyph_cmp
lda f_dest
cmpa glyph_cmp
lblo glyph_branch_3
lbne glyph_done
lda #$f8
sta glyph_cmp
lda f_dest+1
cmpa glyph_cmp
lblo glyph_branch_3
lbne glyph_done
glyph_branch_3
; Copy all eight source rows before clearing the destination.
lda #$00
sta f_i
ldd f_source
std f_ptr
glyph_snapshot
ldx f_ptr
lda ,x
ldx #f_copy
ldb f_i
sta b,x
ldd f_ptr
addd #$0001
std f_ptr
lda f_i
adda #$01
sta f_i
lda #$08
sta glyph_cmp
lda f_i
cmpa glyph_cmp
lblo glyph_snapshot
glyph_branch_4
lda #$00
sta f_i
ldd f_dest
std f_ptr
glyph_clear
lda #$00
ldx f_ptr
sta ,x
ldd f_ptr
addd #$0001
std f_ptr
lda f_i
adda #$01
sta f_i
lda #$08
sta glyph_cmp
lda f_i
cmpa glyph_cmp
lblo glyph_clear
glyph_branch_5
lda #$00
sta f_y
glyph_row
ldx #f_copy
ldb f_y
lda b,x
sta f_bits
lda #$00
sta f_x
glyph_pixel
lda f_bits
anda #$80
lbeq glyph_next
lda f_x
sta f_dx
lda f_y
sta f_dy
lda f_flags
anda #3
sta f_turns
glyph_turn
lda #$00
sta glyph_cmp
lda f_turns
cmpa glyph_cmp
lbne glyph_branch_6
jmp glyph_reflect
glyph_branch_6
lda f_dx
sta f_tmp
; BEGIN ROTATION FIX: (x,y) becomes (7-y,x), not (y,x).
lda #$07
sta f_dx
lda f_dx
suba f_dy
sta f_dx
; END ROTATION FIX
lda f_tmp
sta f_dy
lda f_turns
adda #$ff
sta f_turns
jmp glyph_turn
glyph_reflect
lda f_flags
anda #4
lbeq glyph_store
lda #$07
sta f_tmp
lda f_tmp
suba f_dx
sta f_tmp
lda f_tmp
sta f_dx
glyph_store
ldx #glyph_masks
ldb f_dx
lda b,x
sta f_mask
ldd #$0000
std f_ptr
lda f_dy
sta f_ptr+1
ldd f_ptr
addd f_dest
std f_ptr
ldx f_ptr
lda ,x
ora f_mask
ldx f_ptr
sta ,x
glyph_next
lsl f_bits
lda f_x
adda #$01
sta f_x
lda #$08
sta glyph_cmp
lda f_x
cmpa glyph_cmp
lblo glyph_pixel
glyph_branch_7
lda f_y
adda #$01
sta f_y
lda #$08
sta glyph_cmp
lda f_y
cmpa glyph_cmp
lblo glyph_row
glyph_branch_8
lda #$01
sta f_status
glyph_done
rts
glyph_masks
fcb 128,64,32,16,8,4,2,1
glyph_transform_endShrink the ink, keep the cell
Need a smaller icon? glyph_resize resamples an 8×8 source into a width and height you choose, each 1..8. The result still occupies eight bytes: useful pixels sit at the top-left, with zero padding to the right and below. Your existing renderer can draw that cell without learning a new asset format. The whole source cell is sampled, including blank margins: the requested rectangle is not a measured tight ink box.

Define RZ as 32 writable bytes and include cross-platform/patterns/rendering/glyph-resize/6809.inc once. No extra zero-page or direct-page allocation is needed. Set both pointers and both dimensions before calling glyph_resize. Scratch needs no initialisation.
These are the complete caller’s scratch addresses. Choose free RAM in your own game; the address declaration does not allocate or protect it. The include is separate from the renderer and backend already shown above. Adjust repository-relative paths to match your project’s files.
Name the caller-owned scratch storage
RZ equ 1152Include the reusable resize component once
include "../../../../../cross-platform/patterns/rendering/glyph-resize/6809.inc"Resample one glyph, then draw its padded cell
; SPDX-License-Identifier: MIT
ldd #font_data+304
std RZ
ldd #8320
std RZ+2
lda #GLYPH_WIDTH
sta RZ+4
lda #GLYPH_HEIGHT
sta RZ+5
jsr glyph_resize
; SPDX-License-Identifier: MIT
; A normal game call: enlarged glyph cells, off-grid origin, opaque label.
ldd #21
std T+0
ldd #37
std T+2
ldd #8320
std T+4
ldd #label_data
std T+6
ldd #1
std T+11
ldd #0
std T+18
ldd #0
std T+20
ldd #256
std T+22
ldd #192
std T+24
lda #MESSAGE_LENGTH
sta T+8
lda #65
sta T+9
lda #65
sta T+10
lda #65
sta T+13
lda #1
sta T+14
lda #1
sta T+15
lda #0
sta T+16
lda #SCALE_X
sta T+68
lda #SCALE_Y
sta T+69
jsr text_stringThe source is our original F; the caller assigns its resized output code 65 in a one-glyph font. The second part declares that font and calls the existing enlarged renderer. The resize routine itself draws nothing and changes no text metrics. Transparent drawing leaves zero padding alone. Opaque drawing still paints the background across the whole padded 8×8 cell (32×32 at the demo’s scale four), not just the requested sampling rectangle.
| RZ offset | Supply or read |
|---|---|
| 0 | Source address word, eight readable bytes |
| 2 | Destination address word, eight writable bytes |
| 4,5 | Width and height bytes, each 1..8 |
| 6 | Output: 1 completed, 0 rejected |
| 7..31 | Private scratch, including eight source snapshot bytes |
Words are big-endian; inputs 0..5 survive. Dimensions outside 1..8 or either pointer above $FFF8 reject before source/destination access. An eight-byte range ending at $10000 passes the arithmetic check; you must still own its mapped memory. Source and destination may overlap, even exactly, because all source rows are copied before output is cleared. Keep RZ, code and stack disjoint from both.
Clobbers: D/X and CC; Y/U/DP survive. The routine is non-re-entrant and changes no interrupt/display policy. Reserve a conservative 16-byte stack allowance beyond caller/interrupt requirements. An interrupt handler must preserve live registers and avoid its scratch and buffers. The later renderer retains its own stack, bank, display-access and interrupt obligations. This reset caller owns the same machine-specific display setup as the examples above; it is not a stock-OS launcher.
Sampling is a choice
Destination (x,y) selects source (x*8 div width, y*8 div height). This is an explicit top-left nearest-neighbour convention: select one source pixel, with no interpolation. Width five samples columns 0,1,3,4,6; width four samples 0,2,4,6. Height follows the same rule independently. An 8×8 request is the identity; 1×1 retains only the top-left source pixel.
The 6809 implementation uses bounded error accumulators. Add eight after each output pixel, subtract width and advance the source column while the error is at least width. Reset that state at the next row. The independent oracle uses direct division, so it checks the recurrence against a different calculation. Division and remainders explain the quotient and leftover; local-to-screen coordinates place the resulting cell.
A one-pixel vertical stroke in source column one disappears at width four: that column is never sampled. A specially drawn small icon can be clearer. Averaging, coverage filters and pixel-centre sampling would give different results; they are not hidden options in this routine. Logical bitmap pixels can also have non-square physical proportions, which these numeric dimensions do not correct.
Make it your own: a short, wide icon
Change GLYPH_WIDTH/GLYPH_HEIGHT from 5/7 to 8/4. Horizontal detail returns while alternate source rows are omitted. The result still occupies eight bytes, and the renderer’s cell and advance stay unchanged.
Keep all columns and halve the useful height
; SPDX-License-Identifier: MIT
CUSTOM_TEXT equ 1
SCALE_X equ 4
SCALE_Y equ 4
MESSAGE_LENGTH equ 1
GLYPH_WIDTH equ 8
GLYPH_HEIGHT equ 4
include "caller.inc"
Replace the eight source bytes to resize another icon. A larger input, target above eight, tightly packed variable-size output or proportional metrics needs a different contract. For a bank, validate the complete allocation before calling once per glyph. Per-call overlap safety does not make an overlapping bank traversal safe: an early result may overwrite a later source. Prefer separate banks or plan snapshots/traversal explicitly.
Common mistake: crop instead of resample
The following fragment is deliberately wrong. It advances the source column by one per output pixel. At width five it takes columns 0..4 and drops the right side, rather than selecting across the whole source. Y still resamples correctly in this example. The F’s bars acquire the wrong proportions despite a successful, in-bounds call.
Wrong: take only the left source columns
; BEGIN WRONG
lda r_sx
adda #$01
sta r_sx
Restore the accumulator which distributes eight source steps over the requested width:
Resample across the whole source width
; BEGIN FIX
lda r_xe
adda #$08
sta r_xe
resize_x_sample
lda r_width
sta resize_cmp
lda r_xe
cmpa resize_cmp
lblo resize_x_ready
resize_branch_9
lda r_xe
suba r_width
sta r_xe
lda r_sx
adda #$01
sta r_sx
jmp resize_x_sample
resize_x_ready
Work, storage and quality
The component occupies 506 bytes, including its eight masks. It needs 32 bytes at RZ, and eight bytes per retained result. Font, renderer, backend, caller, display memory and stack remain additional.
Each valid call snapshots eight source bytes, clears eight result bytes and samples width×height pixels, from 1 to 64. Each sampled set bit reads and writes its destination byte. These are glyph-buffer operations, not all CPU accesses or measured cycles. Smaller requests also perform repeated accumulator subtraction; cost does not fall simply in proportion to output area.
The output always costs eight bytes, even for 1×1. This implementation preserves a convenient asset format rather than packing smaller glyphs. Cache a useful size or prepare it at build time. All 64 dimension pairs, including the 8×8 identity, cost 512 bytes per source glyph if stored together; one source costs eight. Store only the sizes your game needs. A hand-designed small font may preserve strokes better, and enlargement after shrinking cannot recover discarded details.
This does not change text advance, bearings or wrapping. A proportional font must keep its cropped pixels and metric table in agreement. Arbitrary angles, targets above eight and scale-aware layout remain separate extensions.
What the resize checks establish
543 native observations completed for this machine with Asm198x 0.0.71 and Emu198x 0.41.0: all 64 size pairs on four source shapes, every source pixel at four representative dimensions, partial/exact overlap, rejected dimensions/addresses, normal/customised callers, and completed wrong/repaired sampling. Complete glyph/source/guard data and selected full bitmap/native frames match an independent division-based oracle. Retained controls reject missing, incomplete, corrupted and rehashed-but-wrong evidence.
This qualifies the named original reset fixture, not stock-OS loading, original hardware, interrupt coexistence or cycle timing. Width/height are useful ink bounds inside the padded cell, not a promise of variable-size layout or hardware upload.
Open the glyph shrinking routine
Resample independently of the display
; SPDX-License-Identifier: MIT
; Shrink an MSB-left 8x8 glyph into 1..8 by 1..8 ink bounds, zero-padded to 8x8.
; RZ = 32 RAM bytes; 6502 RP = separate two zero-page bytes.
; Source sampling: floor(destination*8/size), top-left convention. Snapshot permits overlap.
r_source equ RZ+0
r_dest equ RZ+2
r_width equ RZ+4
r_height equ RZ+5
r_status equ RZ+6
r_ptr equ RZ+8
r_x equ RZ+10
r_y equ RZ+11
r_sx equ RZ+12
r_sy equ RZ+13
r_xe equ RZ+14
r_ye equ RZ+15
r_bits equ RZ+16
r_mask equ RZ+17
r_cmp equ RZ+23
r_copy equ RZ+24
resize_cmp equ RZ+23
glyph_resize
lda #$00
sta r_status
lda #$01
sta resize_cmp
lda r_width
cmpa resize_cmp
lblo resize_done
resize_branch_1
lda #$08
sta resize_cmp
lda r_width
cmpa resize_cmp
lblo resize_branch_2
lbne resize_done
resize_branch_2
lda #$01
sta resize_cmp
lda r_height
cmpa resize_cmp
lblo resize_done
resize_branch_3
lda #$08
sta resize_cmp
lda r_height
cmpa resize_cmp
lblo resize_branch_4
lbne resize_done
resize_branch_4
lda #$ff
sta resize_cmp
lda r_source
cmpa resize_cmp
lblo resize_branch_5
lbne resize_done
lda #$f8
sta resize_cmp
lda r_source+1
cmpa resize_cmp
lblo resize_branch_5
lbne resize_done
resize_branch_5
lda #$ff
sta resize_cmp
lda r_dest
cmpa resize_cmp
lblo resize_branch_6
lbne resize_done
lda #$f8
sta resize_cmp
lda r_dest+1
cmpa resize_cmp
lblo resize_branch_6
lbne resize_done
resize_branch_6
lda #$00
sta r_x
ldd r_source
std r_ptr
resize_snapshot
ldx r_ptr
lda ,x
ldx #r_copy
ldb r_x
sta b,x
ldd r_ptr
addd #$0001
std r_ptr
lda r_x
adda #$01
sta r_x
lda #$08
sta resize_cmp
lda r_x
cmpa resize_cmp
lblo resize_snapshot
resize_branch_7
lda #$00
sta r_x
ldd r_dest
std r_ptr
resize_clear
lda #$00
ldx r_ptr
sta ,x
ldd r_ptr
addd #$0001
std r_ptr
lda r_x
adda #$01
sta r_x
lda #$08
sta resize_cmp
lda r_x
cmpa resize_cmp
lblo resize_clear
resize_branch_8
lda #$00
sta r_y
lda #$00
sta r_sy
lda #$00
sta r_ye
resize_row
ldx #r_copy
ldb r_sy
lda b,x
sta r_bits
lda #$00
sta r_x
lda #$00
sta r_sx
lda #$00
sta r_xe
resize_pixel
ldx #resize_masks
ldb r_sx
lda b,x
anda r_bits
lbeq resize_next
ldx #resize_masks
ldb r_x
lda b,x
sta r_mask
ldd #$0000
std r_ptr
lda r_y
sta r_ptr+1
ldd r_ptr
addd r_dest
std r_ptr
ldx r_ptr
lda ,x
ora r_mask
ldx r_ptr
sta ,x
resize_next
; BEGIN SAMPLING FIX: accumulate eight source steps per destination width.
lda r_xe
adda #$08
sta r_xe
resize_x_sample
lda r_width
sta resize_cmp
lda r_xe
cmpa resize_cmp
lblo resize_x_ready
resize_branch_9
lda r_xe
suba r_width
sta r_xe
lda r_sx
adda #$01
sta r_sx
jmp resize_x_sample
resize_x_ready
; END SAMPLING FIX
lda r_x
adda #$01
sta r_x
lda r_width
sta resize_cmp
lda r_x
cmpa resize_cmp
lblo resize_pixel
resize_branch_10
lda r_ye
adda #$08
sta r_ye
resize_y_sample
lda r_height
sta resize_cmp
lda r_ye
cmpa resize_cmp
lblo resize_y_ready
resize_branch_11
lda r_ye
suba r_height
sta r_ye
lda r_sy
adda #$01
sta r_sy
jmp resize_y_sample
resize_y_ready
lda r_y
adda #$01
sta r_y
lda r_height
sta resize_cmp
lda r_y
cmpa resize_cmp
lblo resize_row
resize_branch_12
lda #$01
sta r_status
resize_done
rts
resize_masks
fcb 128,64,32,16,8,4,2,1
glyph_resize_endRead the reusable integer-enlarged renderer
Scaled foreground runs over the existing native span backend
; SPDX-License-Identifier: MIT
; Integer-enlarged 8x8 glyphs using the existing bp_hspan backend.
; T: 96 bytes, with scale inputs T+68/69 (1..4). BP: separate 48 bytes.
; All registers/flags used by the backend may change. Non-re-entrant.
; See README.md for trusted source allocations, pens, bounds and outputs.
t_x equ T+0
t_y equ T+2
t_font equ T+4
t_source equ T+6
t_length equ T+8
t_code equ T+9
t_first equ T+10
t_count equ T+11
t_fallback equ T+13
t_mode equ T+14
t_fg equ T+15
t_bg equ T+16
t_status equ T+17
t_clip_l equ T+18
t_clip_t equ T+20
t_clip_r equ T+22
t_clip_b equ T+24
t_next_x equ T+26
t_consumed equ T+28
t_missing equ T+29
t_calls equ T+30
t_writes equ T+32
t_entry equ T+36
t_limit equ T+37
t_i equ T+38
t_index equ T+40
t_end equ T+42
t_pointer equ T+44
t_row equ T+46
t_column equ T+47
t_bits equ T+48
t_run equ T+49
t_start equ T+50
t_left equ T+52
t_right equ T+54
t_py equ T+56
t_pen equ T+58
t_temp equ T+60
t_work equ T+64
t_sx equ T+68
t_sy equ T+69
t_advance equ T+70
t_repeat equ T+74
t_product equ T+76
t_factor equ T+78
t_raw equ T+80
t_cmp equ T+95
bp_x0 equ BP+0
bp_y0 equ BP+2
bp_x1 equ BP+4
bp_op equ BP+8
bp_pen equ BP+11
bp_writes equ BP+40
g_cmp equ T+95
text_char
lda #$00
sta t_entry
jmp text_enter
text_string
lda #$01
sta t_entry
jmp text_enter
text_enter
lda #$00
sta t_status
lda #$00
sta t_writes+3
lda #$00
sta t_writes+2
lda #$00
sta t_writes+1
lda #$00
sta t_writes
ldd #$0000
std t_calls
lda #$00
sta t_consumed
lda #$00
sta t_missing
ldd t_x
std t_next_x
; Validate the complete declaration before drawing; no source read yet.
lda #$fe
eora #$80
sta g_cmp
lda t_x
eora #$80
cmpa g_cmp
lblo text_done
lbne text_branch_1
lda #$00
sta g_cmp
lda t_x+1
cmpa g_cmp
lblo text_done
text_branch_1
lda #$01
eora #$80
sta g_cmp
lda t_x
eora #$80
cmpa g_cmp
lblo text_branch_2
lbne text_done
lda #$ff
sta g_cmp
lda t_x+1
cmpa g_cmp
lblo text_branch_2
lbne text_done
text_branch_2
lda #$fe
eora #$80
sta g_cmp
lda t_y
eora #$80
cmpa g_cmp
lblo text_done
lbne text_branch_3
lda #$00
sta g_cmp
lda t_y+1
cmpa g_cmp
lblo text_done
text_branch_3
lda #$01
eora #$80
sta g_cmp
lda t_y
eora #$80
cmpa g_cmp
lblo text_branch_4
lbne text_done
lda #$ff
sta g_cmp
lda t_y+1
cmpa g_cmp
lblo text_branch_4
lbne text_done
text_branch_4
lda #$01
sta g_cmp
lda t_sx
cmpa g_cmp
lblo text_done
text_branch_5
lda #$04
sta g_cmp
lda t_sx
cmpa g_cmp
lblo text_branch_6
lbne text_done
text_branch_6
lda #$01
sta g_cmp
lda t_sy
cmpa g_cmp
lblo text_done
text_branch_7
lda #$04
sta g_cmp
lda t_sy
cmpa g_cmp
lblo text_branch_8
lbne text_done
text_branch_8
lda #$01
sta g_cmp
lda t_mode
cmpa g_cmp
lblo text_branch_9
lbne text_done
text_branch_9
ldd #$0000
std t_temp
lda t_fg
sta t_temp+1
ldd #TEXT_PEN_MAX
std t_end
lda t_end
sta g_cmp
lda t_temp
cmpa g_cmp
lblo text_branch_10
lbne text_done
lda t_end+1
sta g_cmp
lda t_temp+1
cmpa g_cmp
lblo text_branch_10
lbne text_done
text_branch_10
ldd #$0000
std t_temp
lda t_bg
sta t_temp+1
ldd #TEXT_PEN_MAX
std t_end
lda t_end
sta g_cmp
lda t_temp
cmpa g_cmp
lblo text_branch_11
lbne text_done
lda t_end+1
sta g_cmp
lda t_temp+1
cmpa g_cmp
lblo text_branch_11
lbne text_done
text_branch_11
lda #$00
eora #$80
sta g_cmp
lda t_clip_l
eora #$80
cmpa g_cmp
lblo text_done
lbne text_branch_12
lda #$00
sta g_cmp
lda t_clip_l+1
cmpa g_cmp
lblo text_done
text_branch_12
lda #$00
eora #$80
sta g_cmp
lda t_clip_t
eora #$80
cmpa g_cmp
lblo text_done
lbne text_branch_13
lda #$00
sta g_cmp
lda t_clip_t+1
cmpa g_cmp
lblo text_done
text_branch_13
lda t_clip_r
eora #$80
sta g_cmp
lda t_clip_l
eora #$80
cmpa g_cmp
lblo text_branch_14
lbne text_done
lda t_clip_r+1
sta g_cmp
lda t_clip_l+1
cmpa g_cmp
lblo text_branch_14
jmp text_done
text_branch_14
lda t_clip_b
eora #$80
sta g_cmp
lda t_clip_t
eora #$80
cmpa g_cmp
lblo text_branch_15
lbne text_done
lda t_clip_b+1
sta g_cmp
lda t_clip_t+1
cmpa g_cmp
lblo text_branch_15
jmp text_done
text_branch_15
ldd #TEXT_WIDTH
std t_end
lda t_end
sta g_cmp
lda t_clip_r
cmpa g_cmp
lblo text_branch_16
lbne text_done
lda t_end+1
sta g_cmp
lda t_clip_r+1
cmpa g_cmp
lblo text_branch_16
lbne text_done
text_branch_16
ldd #TEXT_HEIGHT
std t_end
lda t_end
sta g_cmp
lda t_clip_b
cmpa g_cmp
lblo text_branch_17
lbne text_done
lda t_end+1
sta g_cmp
lda t_clip_b+1
cmpa g_cmp
lblo text_branch_17
lbne text_done
text_branch_17
lda #$00
sta g_cmp
lda t_count
cmpa g_cmp
lbne text_branch_18
lda #$00
sta g_cmp
lda t_count+1
cmpa g_cmp
lbne text_branch_18
jmp text_done
text_branch_18
lda #$01
sta g_cmp
lda t_count
cmpa g_cmp
lblo text_branch_19
lbne text_done
lda #$00
sta g_cmp
lda t_count+1
cmpa g_cmp
lblo text_branch_19
lbne text_done
text_branch_19
ldd #$0000
std t_end
lda t_first
sta t_end+1
ldd t_end
addd t_count
std t_end
lda #$01
sta g_cmp
lda t_end
cmpa g_cmp
lblo text_branch_20
lbne text_done
lda #$00
sta g_cmp
lda t_end+1
cmpa g_cmp
lblo text_branch_20
lbne text_done
text_branch_20
ldd #$0000
std t_index
lda t_fallback
sta t_index+1
ldd #$0000
std t_temp
lda t_first
sta t_temp+1
lda t_temp
sta g_cmp
lda t_index
cmpa g_cmp
lblo text_done
lbne text_branch_21
lda t_temp+1
sta g_cmp
lda t_index+1
cmpa g_cmp
lblo text_done
text_branch_21
lda t_end
sta g_cmp
lda t_index
cmpa g_cmp
lblo text_branch_22
lbne text_done
lda t_end+1
sta g_cmp
lda t_index+1
cmpa g_cmp
lblo text_branch_22
jmp text_done
text_branch_22
ldd t_count
std t_temp
lsl t_temp+1
rol t_temp
lsl t_temp+1
rol t_temp
lsl t_temp+1
rol t_temp
ldd t_temp
addd t_font
std t_temp
lda #$00
sta g_cmp
lda t_temp
cmpa g_cmp
lbne text_branch_24
lda #$00
sta g_cmp
lda t_temp+1
cmpa g_cmp
lbne text_branch_24
jmp text_branch_23
text_branch_24
lda t_font
sta g_cmp
lda t_temp
cmpa g_cmp
lblo text_done
lbne text_branch_25
lda t_font+1
sta g_cmp
lda t_temp+1
cmpa g_cmp
lblo text_done
text_branch_25
text_branch_23
lda #$01
sta t_limit
lda #$00
sta g_cmp
lda t_entry
cmpa g_cmp
lbne text_branch_27
jmp text_branch_26
text_branch_27
lda t_length
sta t_limit
ldd #$0000
std t_temp
lda t_length
sta t_temp+1
ldd t_temp
addd t_source
std t_temp
lda #$00
sta g_cmp
lda t_temp
cmpa g_cmp
lbne text_branch_29
lda #$00
sta g_cmp
lda t_temp+1
cmpa g_cmp
lbne text_branch_29
jmp text_branch_28
text_branch_29
lda t_source
sta g_cmp
lda t_temp
cmpa g_cmp
lblo text_done
lbne text_branch_30
lda t_source+1
sta g_cmp
lda t_temp+1
cmpa g_cmp
lblo text_done
text_branch_30
text_branch_28
text_branch_26
ldd #$0000
std t_advance
lda t_sx
sta t_advance+1
lsl t_advance+1
rol t_advance
lsl t_advance+1
rol t_advance
lsl t_advance+1
rol t_advance
lda #$01
sta t_status
lda #$00
sta t_i
text_glyph
lda t_limit
sta g_cmp
lda t_i
cmpa g_cmp
lblo text_branch_31
jmp text_done
text_branch_31
lda #$00
sta g_cmp
lda t_entry
cmpa g_cmp
lbne text_branch_34
jmp text_branch_32
text_branch_34
ldd #$0000
std t_pointer
lda t_i
sta t_pointer+1
ldd t_pointer
addd t_source
std t_pointer
ldx t_pointer
lda ,x
sta t_index+1
ldd #$0000
std t_temp
lda #$00
sta t_index
jmp text_branch_33
text_branch_32
ldd #$0000
std t_index
lda t_code
sta t_index+1
text_branch_33
ldd #$0000
std t_temp
lda t_first
sta t_temp+1
lda t_temp
sta g_cmp
lda t_index
cmpa g_cmp
lblo text_branch_35
lbne text_branch_37
lda t_temp+1
sta g_cmp
lda t_index+1
cmpa g_cmp
lblo text_branch_35
text_branch_37
ldd t_index
subd t_temp
std t_index
lda t_count
sta g_cmp
lda t_index
cmpa g_cmp
lblo text_branch_36
lbne text_branch_38
lda t_count+1
sta g_cmp
lda t_index+1
cmpa g_cmp
lblo text_branch_36
text_branch_38
text_branch_35
ldd #$0000
std t_index
lda t_fallback
sta t_index+1
ldd #$0000
std t_temp
lda t_first
sta t_temp+1
ldd t_index
subd t_temp
std t_index
lda t_missing
adda #$01
sta t_missing
text_branch_36
; Reject fully clipped glyph cells after resolving fallback, before reading font rows.
lda t_clip_r
eora #$80
sta g_cmp
lda t_next_x
eora #$80
cmpa g_cmp
lblo text_branch_39
lbne text_next_glyph
lda t_clip_r+1
sta g_cmp
lda t_next_x+1
cmpa g_cmp
lblo text_branch_39
jmp text_next_glyph
text_branch_39
ldd t_next_x
std t_temp
ldd t_temp
addd t_advance
std t_temp
lda t_clip_l
eora #$80
sta g_cmp
lda t_temp
eora #$80
cmpa g_cmp
lblo text_next_glyph
lbne text_branch_40
lda t_clip_l+1
sta g_cmp
lda t_temp+1
cmpa g_cmp
lblo text_next_glyph
lbeq text_next_glyph
text_branch_40
lda t_clip_b
eora #$80
sta g_cmp
lda t_y
eora #$80
cmpa g_cmp
lblo text_branch_41
lbne text_next_glyph
lda t_clip_b+1
sta g_cmp
lda t_y+1
cmpa g_cmp
lblo text_branch_41
jmp text_next_glyph
text_branch_41
ldd #$0000
std t_temp
lda t_sy
sta t_temp+1
lsl t_temp+1
rol t_temp
lsl t_temp+1
rol t_temp
lsl t_temp+1
rol t_temp
ldd t_temp
addd t_y
std t_temp
lda t_clip_t
eora #$80
sta g_cmp
lda t_temp
eora #$80
cmpa g_cmp
lblo text_next_glyph
lbne text_branch_42
lda t_clip_t+1
sta g_cmp
lda t_temp+1
cmpa g_cmp
lblo text_next_glyph
lbeq text_next_glyph
text_branch_42
lsl t_index+1
rol t_index
lsl t_index+1
rol t_index
lsl t_index+1
rol t_index
ldd t_font
std t_pointer
ldd t_pointer
addd t_index
std t_pointer
lda #$00
sta t_row
text_row
lda #$08
sta g_cmp
lda t_row
cmpa g_cmp
lblo text_branch_43
jmp text_next_glyph
text_branch_43
ldx t_pointer
lda ,x
sta t_raw
lda #$00
sta t_repeat
text_scaled_row
ldd t_y
std t_py
ldd #$0000
std t_temp
lda t_row
sta t_temp+1
ldd t_temp
std t_product
ldd #$0000
std t_temp
lda t_sy
sta t_factor
text_branch_44
ldd t_temp
addd t_product
std t_temp
lda t_factor
adda #$ff
sta t_factor
lda #$00
sta g_cmp
lda t_factor
cmpa g_cmp
lbne text_branch_44
text_branch_45
ldd t_py
addd t_temp
std t_py
ldd #$0000
std t_temp
lda t_repeat
sta t_temp+1
ldd t_py
addd t_temp
std t_py
lda #$00
sta g_cmp
lda t_mode
cmpa g_cmp
lbne text_branch_47
jmp text_branch_46
text_branch_47
ldd t_next_x
std t_left
ldd t_next_x
std t_right
ldd t_right
addd t_advance
std t_right
lda t_bg
sta t_pen
jsr text_span
text_branch_46
lda t_raw
sta t_bits
lda #$00
sta t_column
lda #$00
sta t_run
text_bit
lda #$08
sta g_cmp
lda t_column
cmpa g_cmp
lblo text_branch_48
jmp text_row_end
text_branch_48
lda t_bits
anda #$80
lbeq text_branch_49
lda #$00
sta g_cmp
lda t_run
cmpa g_cmp
lbne text_branch_50
text_branch_51
lda t_column
sta t_start
lda #$01
sta t_run
jmp text_branch_50
text_branch_49
lda #$00
sta g_cmp
lda t_run
cmpa g_cmp
lbne text_branch_52
jmp text_branch_50
text_branch_52
jsr text_run
lda #$00
sta t_run
text_branch_50
lsl t_bits
lda t_column
adda #$01
sta t_column
jmp text_bit
text_row_end
lda #$00
sta g_cmp
lda t_run
cmpa g_cmp
lbne text_branch_54
jmp text_branch_53
text_branch_54
jsr text_run
text_branch_53
lda t_repeat
adda #$01
sta t_repeat
lda t_sy
sta g_cmp
lda t_repeat
cmpa g_cmp
lblo text_scaled_row
text_branch_55
ldd t_pointer
addd #$0001
std t_pointer
lda t_row
adda #$01
sta t_row
jmp text_row
text_next_glyph
; BEGIN ADVANCE FIX: move by the enlarged glyph cell width.
ldd t_next_x
addd t_advance
std t_next_x
; END ADVANCE FIX
lda t_i
adda #$01
sta t_i
lda t_i
sta t_consumed
jmp text_glyph
text_done
rts
text_run
ldd #$0000
std t_left
lda t_start
sta t_left+1
ldd t_left
std t_product
ldd #$0000
std t_left
lda t_sx
sta t_factor
text_branch_56
ldd t_left
addd t_product
std t_left
lda t_factor
adda #$ff
sta t_factor
lda #$00
sta g_cmp
lda t_factor
cmpa g_cmp
lbne text_branch_56
text_branch_57
ldd t_left
addd t_next_x
std t_left
ldd #$0000
std t_right
lda t_column
sta t_right+1
ldd t_right
std t_product
ldd #$0000
std t_right
lda t_sx
sta t_factor
text_branch_58
ldd t_right
addd t_product
std t_right
lda t_factor
adda #$ff
sta t_factor
lda #$00
sta g_cmp
lda t_factor
cmpa g_cmp
lbne text_branch_58
text_branch_59
ldd t_right
addd t_next_x
std t_right
lda t_fg
sta t_pen
jmp text_span
text_span
; Intersect a half-open run with the validated physical-screen scissor.
lda t_clip_t
eora #$80
sta g_cmp
lda t_py
eora #$80
cmpa g_cmp
lblo text_span_done
lbne text_branch_60
lda t_clip_t+1
sta g_cmp
lda t_py+1
cmpa g_cmp
lblo text_span_done
text_branch_60
lda t_clip_b
eora #$80
sta g_cmp
lda t_py
eora #$80
cmpa g_cmp
lblo text_branch_61
lbne text_span_done
lda t_clip_b+1
sta g_cmp
lda t_py+1
cmpa g_cmp
lblo text_branch_61
jmp text_span_done
text_branch_61
lda t_clip_l
eora #$80
sta g_cmp
lda t_right
eora #$80
cmpa g_cmp
lblo text_span_done
lbne text_branch_62
lda t_clip_l+1
sta g_cmp
lda t_right+1
cmpa g_cmp
lblo text_span_done
lbeq text_span_done
text_branch_62
lda t_clip_r
eora #$80
sta g_cmp
lda t_left
eora #$80
cmpa g_cmp
lblo text_branch_63
lbne text_span_done
lda t_clip_r+1
sta g_cmp
lda t_left+1
cmpa g_cmp
lblo text_branch_63
jmp text_span_done
text_branch_63
lda t_clip_l
eora #$80
sta g_cmp
lda t_left
eora #$80
cmpa g_cmp
lblo text_branch_65
lbne text_branch_64
lda t_clip_l+1
sta g_cmp
lda t_left+1
cmpa g_cmp
lblo text_branch_65
jmp text_branch_64
text_branch_65
ldd t_clip_l
std t_left
text_branch_64
lda t_clip_r
eora #$80
sta g_cmp
lda t_right
eora #$80
cmpa g_cmp
lblo text_branch_66
lbne text_branch_67
lda t_clip_r+1
sta g_cmp
lda t_right+1
cmpa g_cmp
lblo text_branch_66
lbeq text_branch_66
text_branch_67
ldd t_clip_r
std t_right
text_branch_66
ldd t_left
std bp_x0
ldd t_right
std bp_x1
ldd t_py
std bp_y0
ifne TEXT_PACKED
lda #$00
sta bp_op
lda t_pen
sta bp_pen
else
lda #$01
sta bp_op
lda #$00
sta g_cmp
lda t_pen
cmpa g_cmp
lbne text_branch_69
jmp text_branch_68
text_branch_69
lda #$00
sta bp_op
text_branch_68
endc
jsr bp_hspan
lda #$00
sta t_work+3
lda #$00
sta t_work+2
lda #$00
sta t_work+1
lda #$00
sta t_work
lda bp_writes+1
sta t_work+3
lda bp_writes
sta t_work+2
lda t_writes+3
adda t_work+3
sta t_writes+3
lda t_writes+2
adca t_work+2
sta t_writes+2
lda t_writes+1
adca t_work+1
sta t_writes+1
lda t_writes
adca t_work
sta t_writes
ldd t_calls
addd #$0001
std t_calls
text_span_done
rts
text_end