zxdiv: Spectrum 128K + DivIDE or DivMMC ESXDOS boot support
authorAlan Cox <alan@linux.intel.com>
Sun, 2 Dec 2018 23:16:05 +0000 (23:16 +0000)
committerAlan Cox <alan@linux.intel.com>
Sun, 2 Dec 2018 23:16:05 +0000 (23:16 +0000)
Build a suitable image to load via ESXDOS 0.8.6 on DivMMC or DivIDE (same
image for both)

Kernel/platform-zxdiv/Makefile
Kernel/platform-zxdiv/README
Kernel/platform-zxdiv/load-esx.s [new file with mode: 0644]

index e9e2973..af7d023 100644 (file)
@@ -46,6 +46,8 @@ $(AOBJS): %.rel: %.s
 
 clean:
        rm -f $(OBJS) *.lst *.asm *.sym *.rst *.rel core *~ 
+       rm -f BOOT.BIN strap.bin load-esx.ihx load-esx.tmp
+       rm -f FUZIX.BIN FUZIX
 
 # Re-order the image and snapshop it
 image:
@@ -60,3 +62,17 @@ image:
        # Banked segments 1 and 7
        dd if=../bank2.bin bs=16384 skip=3 >>strap.bin conv=sync
        dd if=../bank3.bin bs=16384 skip=3 >>strap.bin conv=sync
+
+       # Build an esxdos friendly setup
+       sdasz80 -o load-esx.s
+       sdldz80 -i load-esx.rel
+       makebin -s 8704 load-esx.ihx load-esx.tmp
+       # Generate the image file we need
+       dd if=load-esx.tmp of=FUZIX bs=8192 skip=1
+
+       # Now build a FUZIX.BIN to load
+       # in the order we need it
+       dd if=../common.bin bs=65536 count=1 conv=sync | \
+               dd of=FUZIX.BIN
+       dd if=../bank2.bin bs=16384 skip=3 >>FUZIX.BIN conv=sync
+       dd if=../bank3.bin bs=16384 skip=3 >>FUZIX.BIN conv=sync
index d595814..b9747fa 100644 (file)
@@ -24,12 +24,15 @@ DivIDE and DIVMMC we do
        0000-1FFF, 
        5-0: are the bank at 2000-3FFF
 
-To make our life miserable however the boot firmware loads stuff into page 3
-switches to it and locks it. Fortunately it turns out we can trojan Fatware
-0.14 as it expects a \fatware\boot.bin and providing it is 8K will just use it.
-This means we still have to have a fat partition but it'll do for now to get
-us going because it'll blindly load our loader into page 3, switch it to 0
-and then run it.
+To load we use the ESXDOS extension that is generally found with most
+DivMMC and DivIDE interfaces. Copy FUZIX.BIN into / on the ESXDOS drive and
+copy FUZIX into BIN. Then boot from ESXDOS with .fuzix
+
+Alternatively you can use FATWARE 0.14 for an autoboot by placing BOOT.BIN
+in \fatware and placing the strap.bin on the second sector onwards of the disk
+image in the boot area before your partitions (make sure your media is
+partitioned for more than 63 boot sectors). If using an hdf image you can dd to
+byte 1046 onwards. Only DivIDE is supported for the autoboot trick.
 
 We run with the following mapping
 
@@ -67,6 +70,7 @@ To Do:
 -      Why does ls /bin lose the lowest pixel row of the 'yes' command ?
        (Seems we lose the bottom line of the left most char - off by one bug
         in zxvid ?)
+-      If loading via ESX works remove the old clunky loader and fix reboot
 -      Hand optimized bank exchange and bank to bank copy routines. These are
        fairly performance critical due to the limitations of the memory model.
        Right now we ldir in one case (could be faster abusing stack), and
@@ -183,3 +187,4 @@ DONE        -       Move video to 4000 and data to 6000 so that we have video
 DONE   -       Colour attributes
 DONE   -       Graphics mapping
 DONE   -       Kempston joystick and mouse
+DONE   -       Finish off testing the ESX loader
diff --git a/Kernel/platform-zxdiv/load-esx.s b/Kernel/platform-zxdiv/load-esx.s
new file mode 100644 (file)
index 0000000..e244e57
--- /dev/null
@@ -0,0 +1,190 @@
+;
+;      We are running at 0x2000 so the final work we do requires some care
+;      that we don't blow ourselves up. We place the needed code in the
+;      loaded image (see load-esx2.s)
+;
+
+       .area _BOOT(ABS)
+       .org 0x2000
+
+       ; We get run with a valid SP but it's lurking in high space so
+       ; move sp for banking.
+start:
+       ld (escape),sp
+       ld sp,#0x8000
+       xor a
+       rst 8
+       .db 0x89
+       ld (drive),a
+
+       ld hl, #filename
+       ld b, #0x01
+       ld a,(drive)
+
+       rst 8
+       .db 0x9A
+       
+       jr c, failure           ; C???
+
+       ld (handle),a
+
+       ; Target for 0-3FFF
+       ld a,#0x16              ; Stuff the first 16K in bank 6
+       ld hl,#0xC000
+       call load16k
+
+       ; Target for 4000-7FFF
+       ld a,#0x14              ; Second 16K for 4000-7FFF into page 4
+       ld hl,#0xC000
+       call load16k
+
+       ; Target for 8000-BFFF
+       ld a,#0x10
+       ld hl,#0x8000
+       call load16k    ; Load 8000-BFFF in situ
+
+       ld a,#0x10
+       ld hl,#0xC000
+       call load16k    ; Load C000-FFFF in situ (CODE1 BANK0)
+
+       ld a,#0x11      
+       ld hl,#0xC000
+       call load16k    ; Load C000-FFFF in situ (CODE2 BANK1)
+
+       ld a,#0x17
+       ld hl,#0xC000
+       call load16k    ; Load C000-FFFF in situ (CODE3 BANK 7)
+
+       ld a,(handle)
+       rst 8
+       .db 0x9B
+
+       ; We can now commit violence
+
+       ld a,#0x0C      ; bank 4, alt screen
+       ld bc,#0x7ffd
+       out (c),a       ; Alt screen on to hide the evidence
+
+       ; We are blowing away stuff the ROM interrupt routine wants to
+       ; touch so stop it
+
+       di
+
+       ; We must not touch the stack from here until we change sp
+
+       ; Move 4000-7FFF into place
+       ld hl,#0xC000
+       ld de,#0x4000
+       ld b,d
+       ld c,e
+       ldir
+
+       ; Next we want bank 6 where we hid the low stuff
+
+       ld bc,#0x7ffd
+       ld a,#0x0E
+       out (c),a
+
+       ld hl,#strap
+       ld de,#0x4000
+       ld bc,#0x0100
+       ldir
+
+       ; Now the delicate bit of the operation - taking over the DivMMC/IDE
+       ; ROM image
+       jp 0x4000               ; vector for the final strap code which
+                               ; moves the DivMMC bits into place and
+                               ; runs the image. We have this loaded
+                               ; over a bit of video space
+
+load16k:
+       ld bc,#0x7FFD
+       out (c),a               ; paging for this load
+
+       ld a,(handle)
+       ld bc,#0x4000
+       rst 8
+       .byte 0x9D
+       ret nc
+failure:
+       ld hl,#ohpoo
+fail:
+       ld a,(hl)
+       inc hl
+       or a
+       jr z, faildone
+       rst 0x10
+       jr fail
+       ; throw ourselves under the bus
+faildone:
+       ld a,(handle)
+       or a
+       jr z, noclose
+       rst 8
+       .byte 0x9B
+noclose:
+       ld sp,(escape)
+       ret
+
+ohpoo:
+       .ascii 'Unable to load Fuzix image'
+       .db 13,0
+filename:
+       .asciz 'FUZIX.BIN'
+handle:
+       .db 0
+drive:
+       .db 0
+escape:
+       .dw 0
+
+;
+;      Code run from 0x4000
+;
+
+strap:
+
+       ld a,#0x80
+       out (0xE3),a            ; ESX EPROM forced mapped low
+       ld a,#0xC9              ; RET
+       ld (0x3D00),a           ; autopage range
+       call 0x3D00             ; force page
+       ld a,#0x83              ; ESX EPROM and page 3
+       out (0xE3),a
+       ld hl,#0xC000           ; Move the low 8K into page 3
+       ld de,#0x2000
+       ld b,d
+       ld c,e
+       ldir
+       ld a,#0x40
+       out (0xE3),a            ; MAPRAM mode
+       ld de,#0x2000           ; Move the last 8K into place
+       ld b,d
+       ld c,e
+       ldir
+
+       ; The eagle has landed
+
+       ld a,#0x10              ; bank 0 alt screen
+       ld bc,#0x7ffd
+       out (c),a               ; memory as we want it
+       ld hl,#0x2200
+       ; 0x2200 should start with a signature of ZB then the execute
+       ; address
+       ld a,(hl)
+       cp #'Z'
+       jr nz, failed
+       inc hl
+       ld a,(hl)
+       cp #'B'
+       jr nz, failed
+       inc hl
+       ld a,(hl)
+       inc hl
+       ld h,(hl)
+       ld l,a
+       jp (hl)
+failed:
+       ; The machine is busted by this point
+       di
+       halt