This commit is contained in:
Joppe Blondel
2026-10-01 12:44:11 +02:00
parent d19ffc70a1
commit 47fffc2e71
9 changed files with 467 additions and 19 deletions
+61 -1
View File
@@ -2,6 +2,12 @@ STACK_TOP = 0xFFFF
DELAY_LOOPS_PER_MS = 40
RESIDENT_BASE = 0xC000
RESIDENT_ROM_SOURCE = 0x0080
BANK_CONTROL_PORT = 0x00
BOOT_BANK_MAPPING = 0x06 ; ROM on, banking on, upper 16K at C000-FFFF
ROM_DISABLE_BIT = 0x01
BANK_SELECT_BIT = 0x02
BANK_ENABLE_BIT = 0x04
BANK_MODE_CLEAR_MASK = 0xF9 ; preserve ROM-disable and auxiliary outputs
.include "bios.inc"
@@ -16,6 +22,9 @@ RESIDENT_ROM_SOURCE = 0x0080
.globl _bios_try_getc
.globl _bios_getc
.globl _bios_init
.globl _bios_bank
.globl _bios_rom_disable
.globl _bank_control_shadow
.globl resident_image_end
.globl s__DATA
.globl l__DATA
@@ -30,6 +39,10 @@ RESIDENT_ROM_SOURCE = 0x0080
.org 0x08
boot_copy:
di
; Keep ROM enabled while mapping the upper physical 16K at C000-FFFF.
; The resident copy therefore survives either banked mode after boot.
ld a, #BOOT_BANK_MAPPING
out (BANK_CONTROL_PORT), a
ld sp, #STACK_TOP
ld hl, #RESIDENT_ROM_SOURCE
ld de, #RESIDENT_BASE
@@ -66,7 +79,8 @@ boot_copy:
; Stable BIOS jump table for ROM-resident applications.
; C050 putc(A), C053 try_getc(), C056 getc(), C059 io_out(A,L),
; C05C io_in(A), C05F delay_ms(HL), C062 monitor warm start.
; C05C io_in(A), C05F delay_ms(HL), C062 monitor warm start,
; C065 bank(A), C068 disable ROM.
.org BIOS_PUTC
jp bios_service_putc
.org BIOS_TRY_GETC
@@ -81,6 +95,17 @@ boot_copy:
jp bios_service_delay_ms
.org BIOS_MONITOR
jp init
.org BIOS_BANK
jp _bios_bank
.org BIOS_ROM_DISABLE
jp _bios_rom_disable
; Port 00 is write-only. Keep its last BIOS-managed value outside the C data
; areas so a monitor warm start does not reset it. The bootstrap establishes
; this same value in the hardware before the resident image is copied.
.org RESIDENT_BASE + 0x70
_bank_control_shadow::
.db BOOT_BANK_MAPPING
.area _HOME
init:
@@ -135,6 +160,41 @@ resident_image_end:
.area _CODE
; Select a RAM mapping while retaining the shadowed ROM-disable bit.
; Input: A=0 selects lower 48K + upper 16K; any other value selects upper 64K.
; Both modes keep banking enabled. A and flags are preserved.
_bios_bank::
push af
or a
jr z, bios_bank_split
ld a, (_bank_control_shadow)
and #BANK_MODE_CLEAR_MASK
or #BANK_ENABLE_BIT
jr bios_bank_update
bios_bank_split:
ld a, (_bank_control_shadow)
and #BANK_MODE_CLEAR_MASK
or #(BANK_ENABLE_BIT | BANK_SELECT_BIT)
bios_bank_update:
ld (_bank_control_shadow), a
out (BANK_CONTROL_PORT), a
pop af
ret
; Permanently hide ROM until reset, preserving the selected RAM mapping.
; A and flags are preserved.
_bios_rom_disable::
push af
ld a, (_bank_control_shadow)
or #ROM_DISABLE_BIT
ld (_bank_control_shadow), a
out (BANK_CONTROL_PORT), a
pop af
ret
; BIOS ABI services preserve registers except documented return values.
bios_service_putc:
push af