diff --git a/Makefile b/Makefile index 6ea9062..59497a8 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ LIBS=clib-6502.a # Common source files -ASM_SRCS = tk2k_startup.s +ASM_SRCS = tk2k_startup.s preserve_zero_pages.s C_SRCS = main.c monitor_subroutines.c utility.c \ game_graphics.c game_logic.c input.c \ line_data.c tiles.c graph_misc_data.c \ @@ -26,8 +26,7 @@ all: $(PRG).wav cc6502 --core=6502 -O2 --list-file=$(@:%.o=obj/%.lst) --char-is-unsigned --pedantic-errors -o obj/$@ $< $(PRG).hex: $(OBJS) -# (cd obj ; ln6502 -g ../linker-files/linker.scm $^ -o ../out/$@ $(LIBS) -l --cross-reference --cstartup=tk2k --no-automatic-placement-rules --output-format intel-hex --hosted) - (cd obj ; ln6502 -g ../linker-files/linker.scm $^ -o ../out/$@ $(LIBS) -l --cross-reference --cstartup=tk2k --no-automatic-placement-rules --output-format intel-hex) + (cd obj ; ln6502 -g ../linker-files/linker.scm $^ -o ../out/$@ $(LIBS) -l --cross-reference --cstartup=tk2k --no-automatic-placement-rules --output-format intel-hex --rom-code) $(PRG).bin: $(PRG).hex (cd out ; objcopy -I ihex -O binary $(PRG).hex $(PRG).bin) diff --git a/linker-files/linker.scm b/linker-files/linker.scm index 1d70f5f..8e7a438 100644 --- a/linker-files/linker.scm +++ b/linker-files/linker.scm @@ -4,11 +4,10 @@ (memory firstPage (address (#x100 . #x1ff)) (section stack)) (memory reserved (address (#x200 . #x7ff)) (type ram)) (memory program (address (#x801 . #x1fff)) (type ram) -;;; (section (programStart #x801) (startup #x80e) code switch idata cdata data_init_table)) - (section (programStart #x801) (startup #x80e) code)) + (section (programStart #x801) startup code)) (memory displayPage1 (address (#x2000 . #x3fff)) (type ram) (section loadscreen)) (memory upperData (address (#x4000 . #x85ff)) (type ram) (section switch idata cdata data_init_table)) ;;; usermem goes from 0x4000 to 0x9FFFF (included), we are splitting it - (memory upperMem (address (#x8600 . #x95ff)) (type ram) (section cstack zdata data heap)) + (memory upperMem (address (#x8600 . #x95ff)) (type ram) (section cstack zdata data heap zpsave)) (memory dosMem (address (#x9600 . #x9fff)) (type ram)) (memory displayPage2 (address (#xa000 . #xbfff)) (type ram)) (memory io (address (#xc000 . #xc0ff)) (type ram)) diff --git a/src/main.c b/src/main.c index 9153677..6b4874b 100644 --- a/src/main.c +++ b/src/main.c @@ -11,6 +11,7 @@ #include "game_graphics.h" #include "monitor_subroutines.h" +#pragma require __preserve_zp // Make sure the loading screen is included #pragma require __loading_screen diff --git a/src/preserve_zero_pages.s b/src/preserve_zero_pages.s new file mode 100644 index 0000000..c600175 --- /dev/null +++ b/src/preserve_zero_pages.s @@ -0,0 +1,12 @@ + .rtmodel version, "1" + .rtmodel core, "*" + + ;; External declarations + .section registers ; pseudo registers in zero page + + .section zpsave, noinit + .pubweak __preserve_zp +__preserve_zp: ; This symbol meant to be required + .space 256 + .require __preserve_zp_needed + .require __restore_zp_needed \ No newline at end of file diff --git a/src/tk2k_startup.s b/src/tk2k_startup.s index 4530af4..aa48beb 100644 --- a/src/tk2k_startup.s +++ b/src/tk2k_startup.s @@ -7,6 +7,7 @@ .section heap .section data_init_table .section registers ; pseudo registers in zero page + .section zpsave ; this is where pseudo registers are saved .extern main, exit, __low_level_init .extern _Zp, _Vsp, _Vfp @@ -19,14 +20,23 @@ call: .macro dest .section programStart, root __program_root_section: - .word nextLine - .byte 0x0a, 0x00 ; 10 - .byte 0x8c, 0x32, 0x30, 0x36, 0x32, 0x00 ; CALL 2062 -nextLine: .byte 0x00, 0x00 ; end of program - + jmp __program_start .section startup, root, noreorder __program_start: .section startup, noreorder + .pubweak __preserve_zp_needed +__preserve_zp_needed: + ldx #.sectionSize registers - 1 +- lda zp:.sectionStart registers,x + sta .sectionStart zpsave,x + dex + bpl - + + .section startup, root, noreorder + lda #.byte0(.sectionEnd cstack) + sta zp:_Vsp + lda #.byte1(.sectionEnd cstack) + sta zp:_Vsp+1 jsr __low_level_init ;;; Initialize data sections if needed.