Skip to content

Commit 8bf6578

Browse files
authored
feat: DIR improvements, CD command, and slot 3 module architecture (#118)
1 parent 59af723 commit 8bf6578

28 files changed

Lines changed: 2027 additions & 955 deletions

File tree

modules/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ all:
2323
$(Q)$(CCOPY) ..$(S)source$(S)common$(S)generated$(S)kwdtext.dat tokeniser$(S)__kwdtext.asm
2424
$(Q)$(PYTHON) _scripts$(S)makebuild.py tokeniser
2525

26-
$(Q)$(PYTHON) _scripts$(S)makebuild.py graphics $(BUILD_DIR) --page 2
26+
$(Q)$(PYTHON) _scripts$(S)makebuild.py graphics $(BUILD_DIR)
2727
$(Q)$(PYTHON) _scripts$(S)makebuild.py hardware $(BUILD_DIR)
28-
$(Q)$(PYTHON) _scripts$(S)makebuild.py kernel $(BUILD_DIR)
28+
$(Q)$(PYTHON) _scripts$(S)makebuild.py kernel $(BUILD_DIR) --page 2
2929
$(Q)$(PYTHON) _scripts$(S)makebuild.py sound $(BUILD_DIR) --page 2
3030

3131
$(Q)$(PYTHON) _scripts$(S)makeexport.py >$(BUILD_DIR)$(S)_exports.module.asm

modules/_scripts/makebuild.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def process_source(path: Path, out: TextIO, *, page: int = 1) -> list[str]:
6060
normalized = " ".join(line.split())
6161
if normalized == ".section code":
6262
out.write("\t\t.section page2\n")
63-
out.write("\t\t.logical * + $6000\n")
63+
out.write("\t\t.logical * + $2000\n")
6464
continue
6565
elif normalized == ".send code":
6666
out.write("\t\t.here\n")

modules/_scripts/makeexport.py

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
and generates corresponding entry points. If paging is enabled, includes
55
the necessary assembly code to handle memory bank switching.
66
7+
Page 1 modules use slot 5 (inc/dec 8+5).
8+
Page 2 modules use slot 3 (save/restore 8+3 with depth counter).
9+
710
Outputs the entry points code to standard output.
811
"""
912

@@ -18,28 +21,72 @@ def main(*, build_dir: Path) -> None:
1821

1922
print(f"PagingEnabled = {1 if paging else 0}")
2023

21-
# Map module page number to MMU slot increments from slot 5 default (N+2):
22-
# page 1 (sb04 = N+3): 1 increment past default
23-
# page 2 (sb05 = N+4): 2 increments past default
24-
page_to_incs = {1: 1, 2: 2}
24+
has_page2 = any(exports[m]["page"] == 2 for m in exports)
25+
26+
if paging and has_page2:
27+
# These routines are included inside an existing .section code block
28+
# in 00start.asm, so no .section/.send wrappers are needed here.
29+
# Slot3ModulePage/Slot3Depth/Slot3Saved are declared in 04data.inc
30+
# (placed before numberBuffer/decimalBuffer to survive buffer overflows).
31+
print("")
32+
print("; --- Slot 3 module bank switching ---")
33+
print("")
34+
print("Slot3Init:")
35+
print("\tstz Slot3Depth")
36+
print("\tlda 8+4")
37+
print("\tclc")
38+
print("\tadc #3")
39+
print("\tsta Slot3ModulePage")
40+
print("\trts")
41+
print("")
42+
print("Slot3BankIn:")
43+
print("\tphy")
44+
print("\tpha")
45+
print("\tinc Slot3Depth")
46+
print("\tlda Slot3Depth")
47+
print("\tcmp #1")
48+
print("\tbne +")
49+
print("\tldy 8+3")
50+
print("\tsty Slot3Saved")
51+
print("\tldy Slot3ModulePage")
52+
print("\tsty 8+3")
53+
print("+\tpla")
54+
print("\tply")
55+
print("\trts")
56+
print("")
57+
print("Slot3BankOut:")
58+
print("\tpha")
59+
print("\tphy")
60+
print("\tdec Slot3Depth")
61+
print("\tbne +")
62+
print("\tldy Slot3Saved")
63+
print("\tsty 8+3")
64+
print("+\tply")
65+
print("\tpla")
66+
print("\trts")
2567

2668
for module in exports:
2769
page = exports[module]["page"]
2870
routines = exports[module]["routines"]
2971
module_name = exports[module]["name"]
30-
incs = page_to_incs[page]
3172
print(f"\t.if {module_name}Integrated == 1")
3273
for routine in routines:
3374
print(f"{routine}:")
3475
if paging:
35-
for _ in range(incs):
76+
if page == 1:
3677
print("\tinc 8+5")
37-
print(f"\tjsr\tExport_{routine}")
38-
print("\tphp")
39-
for _ in range(incs):
78+
print(f"\tjsr\tExport_{routine}")
79+
print("\tphp")
4080
print("\tdec 8+5")
41-
print("\tplp")
42-
print("\trts")
81+
print("\tplp")
82+
print("\trts")
83+
elif page == 2:
84+
print("\tjsr Slot3BankIn")
85+
print(f"\tjsr\tExport_{routine}")
86+
print("\tphp")
87+
print("\tjsr Slot3BankOut")
88+
print("\tplp")
89+
print("\trts")
4390
else:
4491
print(f"\tjmp\tExport_{routine}")
4592

@@ -50,7 +97,7 @@ def read_exports(build_dir: Path) -> dict[str, dict]:
5097
"""Read all `.exports` files from the build directory.
5198
5299
Files named `<module>_p2.exports` are treated as page 2 exports
53-
(requiring double inc/dec 8+5). All others are page 1.
100+
(slot 3 via save/restore 8+3). All others are page 1 (slot 5 via inc/dec 8+5).
54101
"""
55102
all_exports: dict[str, dict] = {}
56103

0 commit comments

Comments
 (0)