From: geijoenr Date: Fri, 20 Feb 2015 20:44:11 +0000 (+0000) Subject: msx2: generate 8k banked ascii rom X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=3301dbb4ddd342b0eb2ba3197c4c3783f9de042d;p=FUZIX.git msx2: generate 8k banked ascii rom Switching to a banked rom simplifies the bootstrap, allows us to discard it and also opens the possibility of appending a romfs after the kernel --- diff --git a/Kernel/platform-msx2/Makefile b/Kernel/platform-msx2/Makefile index 8be6eb5b..22f28ca9 100644 --- a/Kernel/platform-msx2/Makefile +++ b/Kernel/platform-msx2/Makefile @@ -44,4 +44,5 @@ clean: image: dd if=../fuzix.bin of=../fuzix.com bs=256 skip=1 - dd if=../fuzix.bin of=../fuzix.rom bs=16384 conv=sync + dd if=../fuzix_boot.bin of=../fuzix.ascii8.rom skip=1 bs=16384 conv=sync + dd if=../fuzix.bin of=../fuzix.ascii8.rom seek=1 bs=16384 conv=sync diff --git a/Kernel/platform-msx2/bootrom.s b/Kernel/platform-msx2/bootrom.s index 832ac7e5..ee1ab9fc 100644 --- a/Kernel/platform-msx2/bootrom.s +++ b/Kernel/platform-msx2/bootrom.s @@ -1,3 +1,6 @@ + ; + ; bootstrap for ASCII 8kb mapped rom + ; .area _BOOT .db 'A' @@ -5,20 +8,17 @@ .dw bootstrap .dw 0,0,0,0,0,0 - .globl enaslt - ; data to save from bios - .globl _slotrom - .globl _slotram - .globl _vdpport - .globl _infobits - .globl _machine_type + .include "msx2.def" .globl find_ram - .globl kstack_top - + .globl enaslt ; At this point the BIOS has detected the cartridge AB signature and - ; jumped here; we have the rom bios in bank 0, ram in bank 3, and rom - ; in bank 1 (this code). + ; jumped here; we have the rom bios in slot_page 0, ram in slot_page 3, and rom + ; in slot_page 1 (this code). + ; + ; Kernel is in mapped ROM pages 0x02 to 0x08, this code is in page 0x00 + ; We just set RAM in slot_page 2 and copy over the kernel in chunks of 8K + ; bootstrap: di ld sp,#0xf340 ; temporary stack @@ -29,114 +29,86 @@ bootstrap: ld ix,#0x00d5 call #0x015f - ; read slot registers from bios before overwritting them + ; + ; set ram in slot_page 2 + ; call find_ram - ld hl,#0x8000 - call enaslt ; set bank 2 to ram + ld hl,#PAGE2_BASE + call enaslt - ld a, #4 - out (0xFE),a + ld b,#3 ; starting ram page (copy to 3,2,1,4) + ld c,#2 ; starting rom page (copy from 2,3,4,5,6,7,8,9) - call find_ram - ld d,a - call find_rom - ld e,a +nextrampage: + ld a, b + out (RAM_PAGE2),a - ; read machine info bits - ld bc,(0x002b) ; localization and interrupt frequency - ld hl,(0x0006) ; vdp ports - inc h - inc l - ld a,(0x002d) ; machine type + ld a,c + ld (ASCII8_ROM_PAGE1),a - ex af,af' - ld a,e + exx + ld hl, #ASCII8_PAGE1_BASE + ld de, #PAGE2_BASE + ld bc, #0x2000 + ldir exx - ld hl,#0xc000 - ld sp,#0xa000 ; keep stack in ram - call enaslt ; set bank 3 to rom + inc c + ld a,c + ld (ASCII8_ROM_PAGE1),a - ; copy kernel page 0 from bank 3 to ram in bank 2 - ; it contains the common area if the rom > 48Kb - ld hl, #0xc000 - ld de, #0x8000 - ld bc, #0x4000 + exx + ld hl, #ASCII8_PAGE1_BASE + ld de, #PAGE2_BASE+0x2000 + ld bc, #0x2000 ldir - exx + + inc c + dec b + ld a,b + cp #3 + jr z, done + or a + jr nz, nextrampage + ld b, #4 + jr nextrampage +done: + ; + ; Collect BIOS info bits and stash to ram + ; + call find_ram ; this requires ram page 0 in slot_page 3 + ld d,a + call find_rom + ld e,a + + ld a, #4 + out (RAM_PAGE3),a + + ld bc,(BIOS_VERSION1) ; localization and interrupt frequency + ld hl,(BIOS_VDP_IOPORT) ; vdp ports + inc h + inc l + ld a,(BIOS_MACHINE_TYPE) ; machine type + ld sp,#0xe100 push de push bc push hl - ld hl,#0xc000 ; set bank 3 back to ram - ld a,d - call enaslt - pop hl - pop bc - pop de + push af - ld a, #4 - out (0xFF),a + ; + ; prepare for all-ram + ; ld a,d - ld (_slotram),a - ld a,e - ld (_slotrom),a - ld (_infobits),bc - ld (_vdpport),hl - ex af,af' - ld (_machine_type),a - - ld sp, #kstack_top ; move stack to final location - - ; set cartridge rom in bank 0 - ld a,e - ld hl,#0 - call enaslt - - ; copy kernel page 3 to ram - ld a, #3 - out (0xFE),a - ld hl, #0x0 - ld de, #0x8000 - ld bc, #0x4000 - ldir - - ; set ram in bank 0 and cartridge rom in bank 2 - ld a,(_slotram) - ld hl,#0 + ld hl,#PAGE0_BASE call enaslt - ld a,(_slotrom) - ld hl,#0x8000 - call enaslt - - ; copy kernel pages 2 and 1 to ram - ld a, #2 - out (0xFC),a - ld hl, #0x4000 - ld de, #0x0 - ld bc, #0x4000 - ldir - ld a, #1 - out (0xFC),a - ld hl, #0x8000 - ld de, #0x0 - ld bc, #0x4000 - ldir - ; prepare mapped ram pages for all-ram ld a, #3 - out (0xFC), a + out (RAM_PAGE0), a ld a, #2 - out (0xFD), a + out (RAM_PAGE1), a ld a, #1 - out (0xFE), a - ld a, #4 - out (0xFF),a - - ; set bank 2 to ram - ld a,(_slotram) - ld hl,#0x8000 - call enaslt + out (RAM_PAGE2), a ; jump to start while keeping rom in page 1 (we are running from it) ; will switch to all-ram in there @@ -146,7 +118,7 @@ bootstrap: ; find slot currently set in page 1 ; returns slot in reg a using FxxxSSPP format (see enaslt) find_rom: - in a,(0xa8) + in a,(SLOT_SEL) rrca rrca and #3 @@ -173,7 +145,7 @@ find_rom0: ; find slot currently set in page 3 ; returns slot in reg a using FxxxSSPP format (see enaslt) find_ram: - in a,(0xa8) + in a,(SLOT_SEL) rlca rlca and #3 @@ -211,10 +183,10 @@ find_ram0: enaslt: call selprm ; calculate bit pattern and mask code jp m, eneslt ; if expanded set secondary first - in a,(0xa8) + in a,(SLOT_SEL) and c or b - out (0xa8),a ; set primary slot + out (SLOT_SEL),a ; set primary slot ret eneslt: push hl @@ -265,11 +237,11 @@ selexp: pop af push af ld d,a - in a,(0xa8) + in a,(SLOT_SEL) ld b,a and #0x3F or c - out (0xa8),a ; set bank 3 to target slot + out (SLOT_SEL),a ; set bank 3 to target slot ld a,d rrca rrca @@ -285,14 +257,14 @@ selexp1: ld a,e cpl ld h,a - ld a,(0xffff) ; read and update secondary slot register + ld a,(SUBSLOT_SEL) ; read and update secondary slot register cpl ld l,a and h ; strip off old bits or d ; add new bits - ld (0xffff),a + ld (SUBSLOT_SEL),a ld a,b - out (0xa8),a ; restore status + out (SLOT_SEL),a ; restore status pop af and #3 ret diff --git a/Kernel/platform-msx2/crt0.s b/Kernel/platform-msx2/crt0.s index dc83cc96..017e77d6 100644 --- a/Kernel/platform-msx2/crt0.s +++ b/Kernel/platform-msx2/crt0.s @@ -2,7 +2,6 @@ ; WRS: Note we list all our segments here, even though ; we don't use them all, because their ordering is set ; when they are first seen. - .area _BOOT .area _CODE .area _CODE2 .area _VIDEO @@ -41,11 +40,12 @@ .globl _vdpport .globl _infobits .globl _machine_type - .globl find_ram ; startup code @0x100 .area _CODE + .include "msx2.def" + ; ; Execution begins with us correctly mapped and at 0x0x100 ; @@ -55,26 +55,28 @@ .ds 0x100 start: di - ; Debug port ld a, #0x23 - out (0x2e), a + out (OPENMSX_DEBUG1), a ld a, #'@' - out (0x2f), a + out (OPENMSX_DEBUG2), a + ; + ; unstash info bits + ; + pop af + pop hl + pop bc + pop de - ; read slot before switching ram page - ld a,(_slotram) - ld hl,#0x4000 + ld sp, #kstack_top + ; + ; set ram in slot_page1 + ; + ex af,af' + ld a,d + exx + ld hl, #PAGE1_BASE call enaslt - ld a,(_slotram) - ld d,a - ld a,(_slotrom) - ld e,a - ld bc,(_infobits) - ld hl,(_vdpport) - ld a,(_machine_type) - exx - ex af,af' ; move the common memory where it belongs ld hl, #s__INITIALIZER ld de, #s__COMMONMEM @@ -108,6 +110,6 @@ start: call init_hardware call _fuzix_main di -stop: halt +stop: halt jr stop diff --git a/Kernel/platform-msx2/fuzix.lnk b/Kernel/platform-msx2/fuzix.lnk index 8abe5027..4fd1e2ec 100644 --- a/Kernel/platform-msx2/fuzix.lnk +++ b/Kernel/platform-msx2/fuzix.lnk @@ -1,11 +1,9 @@ -mwxuy -i fuzix.ihx -b _CODE=0x0000 --b _BOOT=0x4000 -b _COMMONMEM=0xF000 -b _DISCARD=0xE000 -l z80 -platform-msx2/bootrom.rel platform-msx2/crt0.rel platform-msx2/commonmem.rel platform-msx2/msx2.rel diff --git a/Kernel/platform-msx2/fuzix_boot.lnk b/Kernel/platform-msx2/fuzix_boot.lnk new file mode 100644 index 00000000..6a5e06e9 --- /dev/null +++ b/Kernel/platform-msx2/fuzix_boot.lnk @@ -0,0 +1,6 @@ +-mwxuy +-i fuzix_boot.ihx +-b _BOOT=0x4000 +-l z80 +platform-msx2/bootrom.rel +-e diff --git a/Kernel/platform-msx2/image.mk b/Kernel/platform-msx2/image.mk new file mode 100644 index 00000000..82553f22 --- /dev/null +++ b/Kernel/platform-msx2/image.mk @@ -0,0 +1,14 @@ +fuzix.ihx: target $(OBJS) platform-$(TARGET)/fuzix.lnk tools/bankld/sdldz80 + $(CROSS_LD) -n -k $(LIBZ80) -f platform-$(TARGET)/fuzix.lnk + $(CROSS_LD) -n -k $(LIBZ80) -f platform-$(TARGET)/fuzix_boot.lnk + +fuzix.bin: fuzix.ihx bootrom.bin tools/bihx tools/analysemap tools/memhogs tools/binman tools/bintomdv cpm-loader/cpmload.bin + -cp hogs.txt hogs.txt.old + tools/memhogs hogs.txt + head -5 hogs.txt + tools/bihx fuzix.ihx + tools/analysemap 48Kb kernel - .area _CODE _mapslot_bank1: ld hl,#0x4000 - jp mapslot + jr enaslt _mapslot_bank2: ld hl,#0x8000 - jp mapslot -mapslot: + +enaslt: call setprm ; calculate bit pattern and mask code jp m, mapsec ; if expanded set secondary first in a,(0xa8) @@ -338,7 +336,7 @@ mapsec: ; here need to store the slot that is being set.... call setexp ; set secondary slot pop hl - jr mapslot + jr enaslt ; calculate bit pattern and mask setprm: