From: Alan Cox Date: Wed, 11 Jul 2018 12:47:59 +0000 (+0100) Subject: trs80: Booting and banking work X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=f2a24eacddd72a270c9f89d6dad3098a173c3609;p=FUZIX.git trs80: Booting and banking work 1. Get rid of BANK94, make the new bank code the default as it works fine without a 3rd party bank card 2. Generate "proper" TRS80 disk images. Our boot disk was 40 track DSSD with sectors numbered from 0. A normal TRS80 disk numbers from 1. 3. Turn on disk skewing so the media layout is a bit more optimal --- diff --git a/Kernel/platform-trs80/Makefile b/Kernel/platform-trs80/Makefile index 5540280a..88718140 100644 --- a/Kernel/platform-trs80/Makefile +++ b/Kernel/platform-trs80/Makefile @@ -3,7 +3,7 @@ CSRCS = devlpr.c devtty.c devfd.c devhd.c devgfx.c CSRCS += devices.c main.c devinput.c DISCARD_CSRCS = discard.c devhd_discard.c -ASRCS = trs80.s trs80-bank94.s crt0.s +ASRCS = trs80.s trs80-bank.s crt0.s ASRCS += tricks.s commonmem.s floppy.s drivewire.s DSRCS = ../dev/devdw.c @@ -36,6 +36,12 @@ clean: rm -f $(OBJS) $(JUNK) core *~ image: trs80load.bin + dd if=/dev/zero of=boot.raw bs=256 count=720 + # Boot block at 0,0 + dd if=trs80load.bin of=boot.raw bs=256 count=1 conv=notrunc + # Kernel lives on the end of the disk (so we can add an fs) + dd if=../fuzix.bin of=boot.raw bs=1 seek=133632 conv=notrunc + ../tools/makejv3 -s -t dd40s -d boot.raw boot4p.jv3 trs80load.bin: trs80load.s sdasz80 -o trs80load.s diff --git a/Kernel/platform-trs80/README b/Kernel/platform-trs80/README index 1b0fee8f..98408e67 100644 --- a/Kernel/platform-trs80/README +++ b/Kernel/platform-trs80/README @@ -3,7 +3,8 @@ TRS80 Model 4/4P This port supports the following configurations currently - TRS80 Model 4/4P (including gate array floppy disk workarounds) + TRS80 Model 4/4P (including gate array floppy disk workarounds) with + 128K of RAM fitted Options: Floppy Disk (somewhat basic support, no format tool yet) Hard Disk (Tandy compatible) @@ -15,6 +16,8 @@ This port supports the following configurations currently Micro Labs Grafyx Alpha Joystick IDE adapter + Alpha Technologies SuperMem (on port 0x43) + Anitek HyperMem (on port 0x90) Not Supported: XLR8R - to do it well is a different port @@ -33,7 +36,7 @@ Emulator Bugs: tree. Requirements: - 128K RAM fitted + 128K or banked RAM fitted Hard disk drive (will be used for swap), or a suitable memory expander board could be used with a bit of tweaking (or both!) (The hard disk code should work with the Lo-tech IDE adapter but diff --git a/Kernel/platform-trs80/config.h b/Kernel/platform-trs80/config.h index bd3d9e01..d4ee99b8 100644 --- a/Kernel/platform-trs80/config.h +++ b/Kernel/platform-trs80/config.h @@ -23,13 +23,7 @@ /* Full key up/down support */ #define CONFIG_INPUT_GRABMAX 3 -/* Support extra banked expansion memory using port 0x94 */ -#define CONFIG_MAP94 -#ifdef CONFIG_MAP94 #define MAX_MAPS 62 -#else -#define MAX_MAPS 2 -#endif #define MAP_SIZE 0x8000 diff --git a/Kernel/platform-trs80/discard.c b/Kernel/platform-trs80/discard.c index 9dcac114..57cd8be8 100644 --- a/Kernel/platform-trs80/discard.c +++ b/Kernel/platform-trs80/discard.c @@ -18,19 +18,15 @@ void map_init(void) { } -uint8_t nbanks = 2; /* Default 2 banks, unless port 94 probe updates */ +uint8_t nbanks = 2; /* Default 2 banks, unless we probe and find a + banked memory card */ void pagemap_init(void) { -#ifdef CONFIG_MAP94 int i = nbanks - 1; while (i) { pagemap_add(i); /* Mode 3, U64K low 32K mapped as low 32K */ pagemap_add(i|0x80); /* Mode 3, U64K high 32K mapped as low 32K */ i--; } -#else - pagemap_add(0x63); /* Mode 3, U64K low 32K mapped as low 32K */ - pagemap_add(0x73); /* Mode 3, U64K high 32K mapped as low 32K */ -#endif } diff --git a/Kernel/platform-trs80/fuzix.lnk b/Kernel/platform-trs80/fuzix.lnk index e2458e48..7547e181 100644 --- a/Kernel/platform-trs80/fuzix.lnk +++ b/Kernel/platform-trs80/fuzix.lnk @@ -6,7 +6,7 @@ platform-trs80/crt0.rel platform-trs80/commonmem.rel platform-trs80/trs80.rel -platform-trs80/trs80-bank94.rel +platform-trs80/trs80-bank.rel start.rel version.rel lowlevel-z80.rel diff --git a/Kernel/platform-trs80/trs80-bank.s b/Kernel/platform-trs80/trs80-bank.s index 942c24fd..7fb10a38 100644 --- a/Kernel/platform-trs80/trs80-bank.s +++ b/Kernel/platform-trs80/trs80-bank.s @@ -1,5 +1,6 @@ ; -; TRS 80 banking logic for the base Model 4 and 4P +; TRS 80 banking logic for the base Model 4 and 4P with +; the port 0x94 banking extensions. ; .module trs80bank @@ -16,9 +17,10 @@ .globl _modout ; imported symbols - .globl _program_vectors + .globl _program_vectors .globl _ramsize .globl _procmem + .globl _nbanks .globl s__COMMONMEM .globl l__COMMONMEM @@ -32,16 +34,11 @@ .area _CODE init_hardware: - in a,(0x94) ; Check for the Huffman banking - cp #0xFF ; mod. If so set 0x94 bit 0 so - jr z, bank_normal ; we run sanely - set 0,a - out (0x94),a -bank_normal: - ; set system RAM size - ld hl, #128 + call detect94 ld (_ramsize), hl - ld hl, #(128-64) ; 64K for kernel + ld de, #64 ; for kernel + or a + sbc hl, de ld (_procmem), hl ; set up interrupt vectors for the kernel (also sets up common memory in page 0x000F which is unused) @@ -65,16 +62,68 @@ bank_normal: .area _COMMONMEM -opsave: .db 0x06 +opsave: .db 0x06 ; used as a word so keep together +save94: .db 0x01 _opreg: .db 0x06 ; kernel map, 80 columns _modout: .db 0x50 ; 80 column, sound enabled, altchars off, ; external I/O enabled, 4MHz + +detect94: + in a,(0x94) + cp #0xFF + jr z, bank94_absent +; +; Seems we have banking extensions present +; +; Write 0xA5 into a fixed location in all banks but zero +; +; For each bank check the byte selected is A5 and write the bank into +; it. When we see a bank not reporting A5 we have found the wrap. +; + ld a, #0x63 ; map extended memory into low 32K + out (0x84),a + ld a, #0xA5 + ld bc, #0x1f94 + ld hl, #0x80 ; pick somewhere which won't hit us! +markall: + out (c), b + ld (hl), a + djnz markall + +scanall: inc b + bit 5, b + jr nz, scandone + out (c), b + cp (hl) ; Still A5 ? + jr nz, scandone + ld (hl), b + jr scanall +scandone: + ld a,(_opreg) ; restore mapping of kernel + out (0x84),a + ld a, b + ld (_nbanks), a + xor a + ; B is the first bank we don't have, 0 based, so B is number of + ; 64K banks we found (max 32) + srl b ; BA *= 64 + rra + srl b + rr a + ld l, a ; Report size in HL + ld h, b + ret +bank94_absent: + xor a + ld h, a + ld l, #128 ; We ought to check/abort on a 64K box ? + ret ; ; Mapping set up for the TRS80 4/4P ; ; The top 32K bank holds kernel code and pieces of common memory -; The lower 32K is switched between the various user banks. On a -; 4 or 4P without add in magic thats 0x62 and 0x63 mappings. +; The lower 32K is switched between the various user banks and the +; base kernel bank ; map_kernel: push af @@ -82,11 +131,13 @@ map_kernel: and #0x8C ; keep video bits or #0x02 ; map 2, base memory ld (_opreg), a - out (0x84), a + out (0x84), a ; base memory so 0x94 doesn't matter pop af ret ; ; Userspace mapping is mode 3, U64K/L32 mapped at L64K/L32 +; Mapping codes 0x63 / 0x73. 0x94 on a bank expanded TRS80 then +; selects how the upper bank decodes ; map_process: ld a, h @@ -95,10 +146,18 @@ map_process: map_process_hl: ld a, (_opreg) and #0x8C - or (hl) ; udata page + or #0x63 + bit 7, (hl) ; low or high ? + jr z, maplo + or #0x10 +maplo: ld (_opreg), a out (0x84), a - ret + ld a, (hl) + and #0x1F + ret z ; not using bank94 + out (0x94), a + ret map_process_a: ; used by bankfork push af @@ -106,9 +165,18 @@ map_process_a: ; used by bankfork ld b, a ld a, (_opreg) and #0x8C - or b + or #0x63 + bit 7, b + jr z, maplo2 + or #0x10 +maplo2: ld (_opreg), a out (0x84), a + ld a, b + and #0x1f + jr z, nobank94 ; zero means no bank94 hw present + out (0x94), a +nobank94: pop bc pop af ret @@ -126,20 +194,25 @@ map_save: push af ld a, (_opreg) and #0x73 ld (opsave), a + in a,(0x94) + ld (save94), a pop af ret map_restore: push af push bc - ld a, (opsave) - ld b, a + ld bc, (opsave) ; c = opsave b = save94 ld a, (_opreg) and #0x8C - or b + or c ld (_opreg), a out (0x84), a + ld a, b + and #0x1f + jr z, norestore94 + out (0x94), a +norestore94: pop bc pop af ret - diff --git a/Kernel/platform-trs80/trs80-bank94.s b/Kernel/platform-trs80/trs80-bank94.s deleted file mode 100644 index 7fb10a38..00000000 --- a/Kernel/platform-trs80/trs80-bank94.s +++ /dev/null @@ -1,218 +0,0 @@ -; -; TRS 80 banking logic for the base Model 4 and 4P with -; the port 0x94 banking extensions. -; - - .module trs80bank - - ; exported symbols - .globl init_hardware - .globl map_kernel - .globl map_process - .globl map_process_a - .globl map_process_always - .globl map_save - .globl map_restore - .globl _opreg - .globl _modout - - ; imported symbols - .globl _program_vectors - .globl _ramsize - .globl _procmem - .globl _nbanks - - .globl s__COMMONMEM - .globl l__COMMONMEM - - .include "kernel.def" - .include "../kernel.def" - -; ----------------------------------------------------------------------------- -; KERNEL MEMORY BANK (below 0xE800, only accessible when the kernel is mapped) -; ----------------------------------------------------------------------------- - .area _CODE - -init_hardware: - call detect94 - ld (_ramsize), hl - ld de, #64 ; for kernel - or a - sbc hl, de - ld (_procmem), hl - - ; set up interrupt vectors for the kernel (also sets up common memory in page 0x000F which is unused) - ld hl, #0 - push hl - call _program_vectors - pop hl - - im 1 ; set CPU interrupt mode - - ; interrupt mask - ; 60Hz timer on - - ld a, #0x24 ; 0x20 for serial - out (0xe0), a - ret - - -;------------------------------------------------------------------------------ -; COMMON MEMORY PROCEDURES FOLLOW - - .area _COMMONMEM - -opsave: .db 0x06 ; used as a word so keep together -save94: .db 0x01 -_opreg: .db 0x06 ; kernel map, 80 columns -_modout: .db 0x50 ; 80 column, sound enabled, altchars off, - ; external I/O enabled, 4MHz - -detect94: - in a,(0x94) - cp #0xFF - jr z, bank94_absent -; -; Seems we have banking extensions present -; -; Write 0xA5 into a fixed location in all banks but zero -; -; For each bank check the byte selected is A5 and write the bank into -; it. When we see a bank not reporting A5 we have found the wrap. -; - ld a, #0x63 ; map extended memory into low 32K - out (0x84),a - ld a, #0xA5 - ld bc, #0x1f94 - ld hl, #0x80 ; pick somewhere which won't hit us! -markall: - out (c), b - ld (hl), a - djnz markall - -scanall: inc b - bit 5, b - jr nz, scandone - out (c), b - cp (hl) ; Still A5 ? - jr nz, scandone - ld (hl), b - jr scanall -scandone: - ld a,(_opreg) ; restore mapping of kernel - out (0x84),a - ld a, b - ld (_nbanks), a - xor a - ; B is the first bank we don't have, 0 based, so B is number of - ; 64K banks we found (max 32) - srl b ; BA *= 64 - rra - srl b - rr a - ld l, a ; Report size in HL - ld h, b - ret -bank94_absent: - xor a - ld h, a - ld l, #128 ; We ought to check/abort on a 64K box ? - ret -; -; Mapping set up for the TRS80 4/4P -; -; The top 32K bank holds kernel code and pieces of common memory -; The lower 32K is switched between the various user banks and the -; base kernel bank -; -map_kernel: - push af - ld a, (_opreg) - and #0x8C ; keep video bits - or #0x02 ; map 2, base memory - ld (_opreg), a - out (0x84), a ; base memory so 0x94 doesn't matter - pop af - ret -; -; Userspace mapping is mode 3, U64K/L32 mapped at L64K/L32 -; Mapping codes 0x63 / 0x73. 0x94 on a bank expanded TRS80 then -; selects how the upper bank decodes -; -map_process: - ld a, h - or l - jr z, map_kernel -map_process_hl: - ld a, (_opreg) - and #0x8C - or #0x63 - bit 7, (hl) ; low or high ? - jr z, maplo - or #0x10 -maplo: - ld (_opreg), a - out (0x84), a - ld a, (hl) - and #0x1F - ret z ; not using bank94 - out (0x94), a - ret - -map_process_a: ; used by bankfork - push af - push bc - ld b, a - ld a, (_opreg) - and #0x8C - or #0x63 - bit 7, b - jr z, maplo2 - or #0x10 -maplo2: - ld (_opreg), a - out (0x84), a - ld a, b - and #0x1f - jr z, nobank94 ; zero means no bank94 hw present - out (0x94), a -nobank94: - pop bc - pop af - ret - -map_process_always: - push af - push hl - ld hl, #U_DATA__U_PAGE - call map_process_hl - pop hl - pop af - ret - -map_save: push af - ld a, (_opreg) - and #0x73 - ld (opsave), a - in a,(0x94) - ld (save94), a - pop af - ret - -map_restore: - push af - push bc - ld bc, (opsave) ; c = opsave b = save94 - ld a, (_opreg) - and #0x8C - or c - ld (_opreg), a - out (0x84), a - ld a, b - and #0x1f - jr z, norestore94 - out (0x94), a -norestore94: - pop bc - pop af - ret diff --git a/Kernel/platform-trs80/trs80load.s b/Kernel/platform-trs80/trs80load.s index f1f613d0..56d6bc4e 100644 --- a/Kernel/platform-trs80/trs80load.s +++ b/Kernel/platform-trs80/trs80load.s @@ -102,13 +102,12 @@ seekstat: .ascii 'seek\0' bad: jr bad secmove: xor a - dec a ld (secnum), a nextsec: ld a, (secnum) inc a ld (secnum), a - cp #18 + cp #19 ; was 18 jr z, lastsec push hl call floppy_read