Restore ZP saving, add initialization of ZP, remove BASIC stub

This commit is contained in:
hkz 2025-07-28 17:37:26 +02:00
commit 3bbaae64d5
5 changed files with 32 additions and 11 deletions

View file

@ -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)

View file

@ -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))

View file

@ -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

12
src/preserve_zero_pages.s Normal file
View file

@ -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

View file

@ -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.