Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
592 changes: 592 additions & 0 deletions docs/c128-port-notes.md

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions editor.asm
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,18 @@ CLR_PTR: .res 2 ; color RAM row pointer
CLR_KWLEN: .res 1 ; keyword length returned by col_try_keyword
CLR_CTMP: .res 2 ; colortab walk pointer (col_try_keyword internal)

; col_try_keyword uses ZP scratch at $3A for the matched token byte.
; This byte is above the editor's reserved ZP block ($02-$1B) and is
; the same address used by modtok.asm — safe to alias here since the
; col_try_keyword needs one byte of scratch for the matched token byte.
; It borrows the first byte of the *module* scratch pool rather than
; spending one of the editor's own reserved bytes — safe only because the
; editor never calls tokenizer code directly.
KW_TOKEN = $3A ; token byte from col_try_keyword (colorize scratch)
;
; This is the one place the editor reaches across into module zero page, so
; it must track any relocation of that pool: hence zp.inc rather than a
; literal. See docs/c128-port-notes.md ("Cross-tier alias") — the intent is
; to retire this alias once the C128 map puts both tiers in one region.
.include "zp.inc"

KW_TOKEN = ZP_SCRATCH+0 ; token byte from col_try_keyword (colorize scratch)


.segment "LOADADDR"
Expand Down
Empty file modified make_disk.py
100644 → 100755
Empty file.
39 changes: 22 additions & 17 deletions modasm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ COLS = 40
DEFAULT_COLOR = 14 ; light blue

; ---- ZP ----
SRC_PTR = $FB ; lo (hi=$FC) - source walker, gap-aware
TMP = $3A ; general scratch (hi=$3B)
TMP2 = $3C ; (hi=$3D)
TMP3 = $3E ; (hi=$3F)
; Addresses come from zp.inc (see docs/c128-port-notes.md).
.include "zp.inc"

SRC_PTR = ZP_PTR2 ; lo (hi=+1) - source walker, gap-aware
TMP = ZP_SCRATCH+0 ; general scratch (hi=+1)
TMP2 = ZP_SCRATCH+2 ; (hi=+3)
TMP3 = ZP_SCRATCH+4 ; (hi=+5)

; ---- Mode constants ----
MODE_IMP = 0
Expand Down Expand Up @@ -127,7 +130,9 @@ ASM_FNAME_LEN = $C021 ; output filename length
ASM_FNAME = $C022 ; output filename (16 bytes)

; ---- ZP save area ----
ZP_SAVE = $C03A ; 10 bytes: saves $3A-$3F, $FB-$FE
; 10 bytes: saves the 6-byte ZP_SCRATCH block plus ZP_PTR2/ZP_PTR3.
; (Not zero page itself — module scratch RAM above the $A000 image.)
ZP_SAVE = $C03A

; ---- Gap pointers (copied from params) ----
ASM_GAP_S_LO = $C032
Expand Down Expand Up @@ -276,18 +281,18 @@ assemble:
; Save ZP
ldx #0
@zpsave:
lda $3A,x
lda ZP_SCRATCH,x
sta ZP_SAVE,x
inx
cpx #6
cpx #ZP_SCRATCH_LEN
bne @zpsave
lda $FB
lda ZP_PTR2
sta ZP_SAVE+6
lda $FC
lda ZP_PTR2+1
sta ZP_SAVE+7
lda $FD
lda ZP_PTR3
sta ZP_SAVE+8
lda $FE
lda ZP_PTR3+1
sta ZP_SAVE+9

; Copy gap/buffer params
Expand Down Expand Up @@ -453,18 +458,18 @@ assemble:
ldx #0
@zprest:
lda ZP_SAVE,x
sta $3A,x
sta ZP_SCRATCH,x
inx
cpx #6
cpx #ZP_SCRATCH_LEN
bne @zprest
lda ZP_SAVE+6
sta $FB
sta ZP_PTR2
lda ZP_SAVE+7
sta $FC
sta ZP_PTR2+1
lda ZP_SAVE+8
sta $FD
sta ZP_PTR3
lda ZP_SAVE+9
sta $FE
sta ZP_PTR3+1
cli ; re-enable IRQ before returning
rts

Expand Down
19 changes: 11 additions & 8 deletions moddet.asm
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ MOD_NEW_END_HI = $0220
MOD_MAGIC_VAL = $4D

; ---- Zero page -------------------------------------------------------------
SRC_PTR = $FB ; source walk pointer (lo/hi)
DST_PTR = $FD ; output write pointer (lo/hi)
COPY_SRC = $F7 ; copy-back source (lo/hi)
COPY_DST = $F9 ; copy-back dest (lo/hi)
LINENO = $3A ; 16-bit line number scratch (lo/hi)
NZFLAG = $3C ; non-zero digit seen (decimal output)
KWTAB = $3D ; keyword table walker (lo/hi)
OVFLAG = $3F ; output-overflow flag ($FF = won't fit)
; Addresses come from zp.inc (see docs/c128-port-notes.md).
.include "zp.inc"

SRC_PTR = ZP_PTR2 ; source walk pointer (lo/hi)
DST_PTR = ZP_PTR3 ; output write pointer (lo/hi)
COPY_SRC = ZP_PTR0 ; copy-back source (lo/hi)
COPY_DST = ZP_PTR1 ; copy-back dest (lo/hi)
LINENO = ZP_SCRATCH+0 ; 16-bit line number scratch (lo/hi)
NZFLAG = ZP_SCRATCH+2 ; non-zero digit seen (decimal output)
KWTAB = ZP_SCRATCH+3 ; keyword table walker (lo/hi)
OVFLAG = ZP_SCRATCH+5 ; output-overflow flag ($FF = won't fit)



Expand Down
39 changes: 21 additions & 18 deletions moddis.asm
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ MOD_NEW_END_HI = $0220
CHROUT = $FFD2

; ---- ZP ----
SRC_PTR = $FB ; lo (hi=$FC) - source walker
DST_PTR = $FD ; output pointer lo (hi at $FE); consecutive pair for (addr),y
TMP = $3A ; scratch (hi=$3B)
TMP2 = $3C ; scratch (hi=$3D)
TMP3 = $3E ; scratch (hi=$3F)
; Addresses come from zp.inc (see docs/c128-port-notes.md).
.include "zp.inc"

SRC_PTR = ZP_PTR2 ; lo (hi=+1) - source walker
DST_PTR = ZP_PTR3 ; output pointer lo (hi at +1); consecutive pair for (addr),y
TMP = ZP_SCRATCH+0 ; scratch (hi=+1)
TMP2 = ZP_SCRATCH+2 ; scratch (hi=+3)
TMP3 = ZP_SCRATCH+4 ; scratch (hi=+5)

; ---- ZP save area and disassembler state ----
; Declared at the end of this file (after all code/tables) as plain labels
Expand Down Expand Up @@ -128,18 +131,18 @@ disassemble:
; Save ZP
ldx #0
@zpsave:
lda $3A,x
lda ZP_SCRATCH,x
sta ZP_SAVE,x
inx
cpx #6
cpx #ZP_SCRATCH_LEN
bne @zpsave
lda $FB
lda ZP_PTR2
sta ZP_SAVE+6
lda $FC
lda ZP_PTR2+1
sta ZP_SAVE+7
lda $FD
lda ZP_PTR3
sta ZP_SAVE+8
lda $FE
lda ZP_PTR3+1
sta ZP_SAVE+9

; Copy params
Expand Down Expand Up @@ -321,18 +324,18 @@ disassemble:
ldx #0
@zprestore:
lda ZP_SAVE,x
sta $3A,x
sta ZP_SCRATCH,x
inx
cpx #6
cpx #ZP_SCRATCH_LEN
bne @zprestore
lda ZP_SAVE+6
sta $FB
sta ZP_PTR2
lda ZP_SAVE+7
sta $FC
sta ZP_PTR2+1
lda ZP_SAVE+8
sta $FD
sta ZP_PTR3
lda ZP_SAVE+9
sta $FE
sta ZP_PTR3+1

; Report success
lda #$02
Expand Down Expand Up @@ -1122,7 +1125,7 @@ mnem_strs:
; TXS/TYA corruption bug this file used to have.
; ============================================================================

ZP_SAVE: .res 10 ; saves $3A-$3F, $FB-$FE
ZP_SAVE: .res 10 ; saves ZP_SCRATCH (6) + ZP_PTR2/ZP_PTR3 (4)
DIS_PC_LO: .res 1 ; current PC lo
DIS_PC_HI: .res 1 ; current PC hi
DIS_SRC_END_LO: .res 1 ; end of source binary lo (= GAP_START)
Expand Down
25 changes: 14 additions & 11 deletions moddsk.asm
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ DSK_FREE_LO: .res 1 ; blocks free lo
DSK_FREE_HI: .res 1 ; blocks free hi
DSK_DISKNAME: .res 16 ; disk name, 16 bytes PETSCII
DSK_DISKID: .res 2 ; disk id, 2 bytes
DSK_ZP_SAVE: .res 4 ; saved ZP $FB-$FE
DSK_ZP_SAVE: .res 4 ; saved ZP_PTR2 / ZP_PTR3
DSK_TMP: .res 1 ; general scratch byte
DSK_TMP2: .res 1 ; second scratch byte
DSK_NAMELEN_TMP: .res 1 ; scratch for rename/format input length
Expand All @@ -186,8 +186,11 @@ DSK_CACHE: .res 680 ; directory cache: 34 entries × 20 bytes
; throughout the code will resolve correctly via the linker.

; Zero page pointers (saved/restored)
DSK_PTR = $FB ; lo (hi = $FC)
DSK_PTR2 = $FD ; lo (hi = $FE)
; Addresses come from zp.inc (see docs/c128-port-notes.md).
.include "zp.inc"

DSK_PTR = ZP_PTR2 ; lo (hi = +1)
DSK_PTR2 = ZP_PTR3 ; lo (hi = +1)

; ============================================================================
; Module entry point
Expand Down Expand Up @@ -215,13 +218,13 @@ disk_main:
sta $01

; Save ZP
lda $FB
lda ZP_PTR2
sta DSK_ZP_SAVE+0
lda $FC
lda ZP_PTR2+1
sta DSK_ZP_SAVE+1
lda $FD
lda ZP_PTR3
sta DSK_ZP_SAVE+2
lda $FE
lda ZP_PTR3+1
sta DSK_ZP_SAVE+3

; Copy drive from parameter block
Expand Down Expand Up @@ -328,13 +331,13 @@ disk_main:
dsk_exit:
; Restore ZP
lda DSK_ZP_SAVE+0
sta $FB
sta ZP_PTR2
lda DSK_ZP_SAVE+1
sta $FC
sta ZP_PTR2+1
lda DSK_ZP_SAVE+2
sta $FD
sta ZP_PTR3
lda DSK_ZP_SAVE+3
sta $FE
sta ZP_PTR3+1
rts

; ============================================================================
Expand Down
41 changes: 22 additions & 19 deletions modren.asm
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ SPIN_COLOR_A = $01
SPIN_COLOR_B = $00

; ---- Zero page (saved / restored around module call) ----
SRC_PTR = $FB ; 16-bit source walker ($FC = hi)
DST_PTR = $FD ; 16-bit destination ptr ($FE = hi)
TMP = $3A ; scratch lo ($3B = hi)
TMP2 = $3C ; number lo ($3D = TMP2+1 = hi)
TMP3 = $3E ; table ptr lo ($3F = TMP3+1 = hi)
; Addresses come from zp.inc (see docs/c128-port-notes.md).
.include "zp.inc"

SRC_PTR = ZP_PTR2 ; 16-bit source walker (+1 = hi)
DST_PTR = ZP_PTR3 ; 16-bit destination ptr (+1 = hi)
TMP = ZP_SCRATCH+0 ; scratch lo (+1 = hi)
TMP2 = ZP_SCRATCH+2 ; number lo (TMP2+1 = hi)
TMP3 = ZP_SCRATCH+4 ; table ptr lo (TMP3+1 = hi)

; ============================================================================
.segment "LOADADDR"
Expand All @@ -78,22 +81,22 @@ modren_entry:
cli
rts
:
; Save ZP $3A-$3F
; Save the ZP_SCRATCH block
ldx #0
@zpsave:
lda $3A,x
lda ZP_SCRATCH,x
sta ZP_SAVE,x
inx
cpx #6
cpx #ZP_SCRATCH_LEN
bne @zpsave
; Save $FB-$FE
lda $FB
; Save ZP_PTR2 / ZP_PTR3
lda ZP_PTR2
sta ZP_SAVE+6
lda $FC
lda ZP_PTR2+1
sta ZP_SAVE+7
lda $FD
lda ZP_PTR3
sta ZP_SAVE+8
lda $FE
lda ZP_PTR3+1
sta ZP_SAVE+9

; Copy MOD parameters into local state
Expand Down Expand Up @@ -164,18 +167,18 @@ modren_entry:
ldx #0
@zprestore:
lda ZP_SAVE,x
sta $3A,x
sta ZP_SCRATCH,x
inx
cpx #6
cpx #ZP_SCRATCH_LEN
bne @zprestore
lda ZP_SAVE+6
sta $FB
sta ZP_PTR2
lda ZP_SAVE+7
sta $FC
sta ZP_PTR2+1
lda ZP_SAVE+8
sta $FD
sta ZP_PTR3
lda ZP_SAVE+9
sta $FE
sta ZP_PTR3+1

cli
rts
Expand Down
7 changes: 6 additions & 1 deletion modscr.asm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ IDE_LEN_LO = <($9FFF - $0801 + 1)
IDE_LEN_HI = >($9FFF - $0801 + 1)

; ---- Scratch ----
TMP16 = $3C ; lo (hi=$3D)
; Address comes from zp.inc (see docs/c128-port-notes.md). The BASIC ABI
; locations above (TXTTAB, VARTAB, MEMSIZ) are fixed by the ROM and are
; deliberately NOT part of the relocatable pool.
.include "zp.inc"

TMP16 = ZP_SCRATCH+2 ; lo (hi=+3)

; Metadata fetch buffer (module RAM, reused after verify)
META_BUF = $B000
Expand Down
9 changes: 7 additions & 2 deletions modscrh.asm
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,13 @@ VEC_IERROR = $0300
VEC_IMAIN = $0302
VEC_IGONE = $0308

; ZP scratch
HND_TMP = $3C ; lo (hi=$3D) — scratch pointer (no conflict during script)
; ZP scratch — address comes from zp.inc (see docs/c128-port-notes.md).
; NOTE: the BASIC ABI locations this module also uses (TXTTAB, VARTAB,
; VARPNT, BASIC_TXTPTR, and AYINT's $14/$15 output) are fixed by the ROM and
; are deliberately NOT part of the relocatable pool.
.include "zp.inc"

HND_TMP = ZP_SCRATCH+2 ; lo (hi=+3) — scratch pointer (no conflict during script)

; Module status
MOD_STATUS = $021E
Expand Down
Loading
Loading