44and generates corresponding entry points. If paging is enabled, includes
55the 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+
710Outputs 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 ("\t stz Slot3Depth" )
36+ print ("\t lda 8+4" )
37+ print ("\t clc" )
38+ print ("\t adc #3" )
39+ print ("\t sta Slot3ModulePage" )
40+ print ("\t rts" )
41+ print ("" )
42+ print ("Slot3BankIn:" )
43+ print ("\t phy" )
44+ print ("\t pha" )
45+ print ("\t inc Slot3Depth" )
46+ print ("\t lda Slot3Depth" )
47+ print ("\t cmp #1" )
48+ print ("\t bne +" )
49+ print ("\t ldy 8+3" )
50+ print ("\t sty Slot3Saved" )
51+ print ("\t ldy Slot3ModulePage" )
52+ print ("\t sty 8+3" )
53+ print ("+\t pla" )
54+ print ("\t ply" )
55+ print ("\t rts" )
56+ print ("" )
57+ print ("Slot3BankOut:" )
58+ print ("\t pha" )
59+ print ("\t phy" )
60+ print ("\t dec Slot3Depth" )
61+ print ("\t bne +" )
62+ print ("\t ldy Slot3Saved" )
63+ print ("\t sty 8+3" )
64+ print ("+\t ply" )
65+ print ("\t pla" )
66+ print ("\t rts" )
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 ("\t inc 8+5" )
37- print (f"\t jsr\t Export_{ routine } " )
38- print ("\t php" )
39- for _ in range (incs ):
78+ print (f"\t jsr\t Export_{ routine } " )
79+ print ("\t php" )
4080 print ("\t dec 8+5" )
41- print ("\t plp" )
42- print ("\t rts" )
81+ print ("\t plp" )
82+ print ("\t rts" )
83+ elif page == 2 :
84+ print ("\t jsr Slot3BankIn" )
85+ print (f"\t jsr\t Export_{ routine } " )
86+ print ("\t php" )
87+ print ("\t jsr Slot3BankOut" )
88+ print ("\t plp" )
89+ print ("\t rts" )
4390 else :
4491 print (f"\t jmp\t Export_{ 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