zx128: Make the adjustments in the asm needed for banked binary support
authorAlan Cox <alan@linux.intel.com>
Sun, 8 Feb 2015 17:00:54 +0000 (17:00 +0000)
committerAlan Cox <alan@linux.intel.com>
Sun, 8 Feb 2015 17:00:54 +0000 (17:00 +0000)
Kernel/platform-zx128/Makefile
Kernel/platform-zx128/README
Kernel/platform-zx128/config.h
Kernel/platform-zx128/crt0.s
Kernel/platform-zx128/fuzix.lnk
Kernel/platform-zx128/tricks.s
Kernel/platform-zx128/zx128.s

index 9f41fa7..d4cfa7a 100644 (file)
@@ -1,5 +1,5 @@
 CSRCS = devtty.c bankzx128.c devices.c main.c devmdv.c
-DSRCS = ../dev/devide.c ../dev/mbr.c
+DSRCS = ../dev/devide.c ../dev/mbr.c ../dev/blkdev.c
 
 ASRCS = crt0.s zx128.s zxvideo.s microdrive.s
 ASRCS += tricks.s commonmem.s
index afacafd..b40fc83 100644 (file)
@@ -1,12 +1,6 @@
 An FUZIX target for ZX Spectrum 128.
 
-This is mid rework as a banked platform test be warned.
-
-The new memory layout looks like this
-
-
-0000-3FFF      ROM (we hack it a bit to allow for our RST and IRQ vectors
-               but in theory we can avoid that)
+0000-3FFF      Fixed BASIC ROM
 4000-7FFF      Kernel data, common read/write space, constants, common read
                only, plenty of space
 8000-BFFF      _DISCARD area - blown away when we exec init
@@ -31,37 +25,23 @@ Moving the entire kernel into a banked cartridge gets us more banks for user
 processes but leaves us with common at 0x4000 so its tight below 0x8000
 
 The other half of the problem on the ZX Spectrum128 is the fact binaries
-must be linked with a different base (0xC000 for 16K, 0x8000 for 32K).
-
-
-
-
-
+must be linked with a different base (0xC000 for 16K, 0x8000 for 32K) so
+we need to sort out relocatables
 
 Big part of the code was taken from z80pack and msx1 ports.
 
 ZX Spectrum has a memory layout like follows:
 
 0000-3FFF      ROM
-4000-57FF      Screen pixel data
+4000-57FF      Screen pixel data (movable into bank 7 on the 128K)
 5800-5AFF      Screen attributes data
 5B00-FFFF      RAM
 
-1 memory bank exists at 0xC000, one of 6 16384-byte pages can be mapped there.
+1 memory bank exists at 0xC000, one of 6 16384-byte pages can be mapped there
+on the 128.
+
+TODO:
 
-So the fuzix port is limited to those features:
+Use IM2 so we can capture timer interrupts correctly. This is a hack but
+it's necessary and is also how all the spectrum games do it.
 
-1) Code1 segment should be flashed into ROM (instead of BASIC-128 in a simplest case).
-2) We have memory "hole" at screen area (4000-5AFF), which we can not use for code or data.
-   So we can not allow Code1 to be larger than 0x4000 bytes.
-3) We need to store some bootloader procedure in Code1, which should read fuzix image
-   data from somewhere (for now this is done via emulator hack) and place it in RAM at
-   correct addresses.
-4) Common area can not be at F000 as usual because F000 belongs to banking area.
-5) Maximum user program size is 16384 bytes.
-6) ZX Spectrum 128 had not any official floppy disk controller. Third-party hardware
-   (like popular in Eastern Europe Betadisk Interface) was designed to be compatible 
-   with old software, so contains some terrible features like FDC port visibility 
-   limited to 256-bytes long area of ROM. Outside this area any requests to FDC ports 
-   are ignored. This makes disk driver implementation very tricky until we have more 
-   smart linker.
\ No newline at end of file
index 6926cb4..6603a23 100644 (file)
@@ -72,3 +72,4 @@
 #undef  SWAPDEV           /* Do not use swap */
 #define NBUFS    10       /* Number of block buffers */
 #define NMOUNTS         4        /* Number of mounts at a time */
+#define MAX_BLKDEV 2       /* 2 IDE drives, 1 SD drive */
index 9c1f0e1..b3609da 100644 (file)
@@ -115,14 +115,18 @@ init_continue:
 
 boot_stack .equ 0xc000
        ld sp, #boot_stack
+       push af
        call mdv_boot
+       pop af
        .endif
 
 
         ld sp, #kstack_top
 
         ; Configure memory map
+       push af
         call init_early
+       pop af
 
         ; our COMMONMEM is located in main code-data blob, so we
         ; do not need to move it manually
@@ -141,10 +145,14 @@ boot_stack .equ 0xc000
         ldir
 
         ; Hardware setup
+       push af
         call init_hardware
+       pop af
 
         ; Call the C main routine
+       push af
         call _fuzix_main
+       pop af
     
         ; main shouldn't return, but if it does...
         di
@@ -153,4 +161,4 @@ stop:   halt
 
        .area _STUBS
 stubs:
-       .ds 384
+       .ds 768
index ea14ec3..78652dd 100644 (file)
@@ -14,8 +14,8 @@ platform-zx128/zxvideo.rel
 platform-zx128/main.rel
 start.rel
 version.rel
-lowlevel-z80.rel
-usermem_std-z80.rel
+lowlevel-z80-banked.rel
+usermem_std-z80-banked.rel
 platform-zx128/tricks.rel
 timer.rel
 kdata.rel
@@ -42,4 +42,5 @@ devsys.rel
 platform-zx128/devtty.rel
 platform-zx128/devide.rel
 platform-zx128/mbr.rel
+platform-zx128/blkdev.rel
 -e
index 5665cf4..d57ebdb 100644 (file)
@@ -36,7 +36,9 @@
 ; This function can have no arguments or auto variables.
 _switchout:
         di
+       push af
         call _chksigs
+       pop af
         ; save machine state
 
         ld hl, #0 ; return code set here is ignored, but _switchin can 
@@ -65,7 +67,9 @@ _switchout:
        out (c), a
 
         ; find another process to run (may select this one again)
+       push af
         call _getproc
+       pop af
 
         push hl
         call _switchin
@@ -238,7 +242,9 @@ _dofork:
         ; Make a new process table entry, etc.
         ld  hl, (fork_proc_ptr)
         push hl
+       push af
         call _newproc
+       pop af
         pop bc 
 
         ; runticks = 0;
index 12d3c4e..c817d8f 100644 (file)
         .globl outstring
         .globl outstringhex
 
+       .globl __bank_0_1
+       .globl __bank_0_2
+       .globl __bank_0_3
+       .globl __bank_1_2
+       .globl __bank_1_3
+       .globl __bank_2_1
+       .globl __bank_2_3
+       .globl __bank_3_1
+       .globl __bank_3_2
+
         .include "kernel.def"
         .include "../kernel.def"
 
@@ -168,3 +178,17 @@ place_for_b:                ; And BC - here
         .db 0
 place_for_c:
         .db 0
+
+;
+;      Banking helpers
+;
+__bank_0_1:
+__bank_0_2:
+__bank_0_3:
+__bank_1_2:
+__bank_1_3:
+__bank_2_1:
+__bank_2_3:
+__bank_3_1:
+__bank_3_2:
+       ret