From 457e8bff9c994342dd441c4c14f84f2c0643854d Mon Sep 17 00:00:00 2001 From: Florian Reitz Date: Tue, 22 May 2018 21:53:11 +0200 Subject: [PATCH] Prepared for Smartport --- src/AppleIISd.cfg | 2 +- src/AppleIISd.inc | 7 +++-- src/AppleIISd.s | 78 ++++++++++++++++++++++++++++------------------- src/Helper.s | 4 +-- src/ProDOS.s | 12 ++++---- src/Smartport.s | 2 +- 6 files changed, 61 insertions(+), 44 deletions(-) diff --git a/src/AppleIISd.cfg b/src/AppleIISd.cfg index 8ce9bef..16c6c0b 100644 --- a/src/AppleIISd.cfg +++ b/src/AppleIISd.cfg @@ -9,7 +9,7 @@ MEMORY { MAIN: file = %O, define = yes, start = %S, size = $C000 - %S; BSS: file = "", start = __MAIN_LAST__, size = $C000 - __MAIN_LAST__; - SLOTROM: file = %O, fill = yes start = $C700, size = $00FC; + SLOTROM: file = %O, fill = yes start = $C700, size = $00FB; SLOTID: file = %O, start = $C7FB, size = $0005; EXTROM: file = %O, fill = yes start = $C800, size = $0700; } diff --git a/src/AppleIISd.inc b/src/AppleIISd.inc index 3ff3e04..6736e65 100644 --- a/src/AppleIISd.inc +++ b/src/AppleIISd.inc @@ -12,11 +12,12 @@ ;******************************* ; ZP locations +PSAVE := $3D ; P save location SLOT16 := $3E ; $s0 -> slot * 16 SLOT := $3F ; $0s CMDLO := $40 CMDHI := $41 -PDZPAREA = SLOT16 +PDZPAREA = PSAVE PDZPSIZE = CMDHI-PDZPAREA+1 ; ProDOS @@ -42,9 +43,11 @@ R30 := $0478 R31 := $04F8 R32 := $0578 R33 := $05F8 +DRVNUM := $0678 CURSLOT := $07F8 ; $Cs -; Slot equates +; Rom equates +KNOWNRTS := $FF58 OAPPLE := $C061 ; open apple key DATA := $C080 CTRL := DATA+1 diff --git a/src/AppleIISd.s b/src/AppleIISd.s index 515a16f..51e3f31 100644 --- a/src/AppleIISd.s +++ b/src/AppleIISd.s @@ -11,12 +11,13 @@ ; ;******************************* -.import PD_DISP +.import PRODOS .import SMARTPORT .import GETR1 .import GETR3 .import SDCMD .import CARDDET +.import READ .include "AppleIISd.inc" @@ -55,9 +56,24 @@ ; LDX #$00 ; is Smartport controller LDX #$3C -PRODOS: - SEI ; no interrupts if booting + SEI ; find slot + JSR KNOWNRTS + TSX + LDA $0100,X + CLI + STA CURSLOT ; $Cs + AND #$0F + STA SLOT ; $0s + TAY ; Y holds now SLOT + ASL A + ASL A + ASL A + ASL A + STA SLOT16 ; $s0 + TAX ; X holds now SLOT16 BIT $CFFF + + ; LDY #0 ; display copyright message ;@DRAW: LDA TEXT,Y ; BEQ @OAPPLE ; check for NULL @@ -67,7 +83,7 @@ PRODOS: ; BPL @DRAW @OAPPLE: BIT OAPPLE ; check for OA key - BPL @BOOT ; and skip boot if pressed + BPL @INIT ; and skip boot if pressed @NEXTSLOT: LDA CURSLOT ; skip boot when no card DEC A @@ -75,6 +91,9 @@ PRODOS: STZ CMDLO JMP (CMDLO) +@INIT: JSR INIT + CMP #NO_ERR + BNE @NEXTSLOT ; init not successful ;******************************* ; @@ -82,31 +101,23 @@ PRODOS: ; ;******************************* -@BOOT: LDA #$01 ; READ - STA DCMD ; load command - LDA #$08 +; load disk blocks 0 and 1 to $800 and $A00 +@BOOT: LDA #$08 ; load to $800 STA BUFFER+1 ; buffer hi STZ BUFFER ; buffer lo STZ BLOCKNUM+1 ; block hi STZ BLOCKNUM ; block lo - LDA #>DRIVER - JSR DRIVER ; call driver - CMP #0 - BNE @NEXTSLOT ; init not successful + JSR READ + BCS @NEXTSLOT ; load not successful - LDA #$01 ; READ - STA DCMD ; load command - STX DSNUMBER ; slot number LDA #$0A STA BUFFER+1 ; buffer hi STZ BUFFER ; buffer lo STZ BLOCKNUM+1 ; block hi LDA #$01 STA BLOCKNUM ; block lo - JSR DRIVER ; call driver - CMP #0 - BNE @NEXTSLOT ; init not successful - LDX SLOT16 + JSR READ + BCS @NEXTSLOT ; load not successful JMP $801 ; goto bootloader @@ -120,37 +131,38 @@ DRIVER: CLC ; ProDOS entry BCC @PRODOS SEC ; Smartport entry -@PRODOS: PHA ; make room for retval - LDY PDZPSIZE-1 ; save zeropage area for ProDOS +@PRODOS: PHP ; transfer P to X + PLX + LDY #PDZPSIZE-1 ; save zeropage area for ProDOS @SAVEZP: LDA PDZPAREA,Y PHA DEY BPL @SAVEZP + STX PSAVE ; save X (P) - PHP ; push twice for PD/SP switch - PHP +; Has this to be done every time this gets called or only on boot??? SEI - LDA #$60 ; opcode for RTS - STA SLOT - JSR SLOT + LDA #$60 ; opcode for RTS + STA SLOT + JSR SLOT TSX LDA $0100,X + CLI STA CURSLOT ; $Cs AND #$0F - PLP STA SLOT ; $0s TAY ; Y holds now SLOT ASL A ASL A ASL A ASL A - STA SLOT16 ; $s0 TAX ; X holds now SLOT16 BIT $CFFF + JSR CARDDET BCC @INITED - LDA ERR_OFFLINE ; no card inserted + LDA #ERR_OFFLINE; no card inserted BRA @END @INITED: LDA #INITED ; check for init @@ -159,7 +171,9 @@ DRIVER: CLC ; ProDOS entry JSR INIT BCS @END ; Init failed -@DISP: PLP ; get PSW from stack +@DISP: LDA PSAVE ; get saved P value + PHA ; and transfer to P + PLP BCS @SMARTPORT ; Smartport dispatcher JSR PRODOS ; ProDOS dispatcher @@ -178,7 +192,7 @@ DRIVER: CLC ; ProDOS entry @RESTZP: PLA ; restore zeropage area STA PDZPAREA,Y INY - CPY PDZPSIZE + CPY #PDZPSIZE BCC @RESTZP LDA R33,X ; get retval @@ -337,11 +351,11 @@ INIT: LDA #$03 ; set SPI mode 3 ORA #ECE ; enable 7MHz STA CTRL,X CLC ; all ok - LDY NO_ERR + LDY #NO_ERR BCC @END1 @IOERROR: SEC - LDY ERR_IOERR ; init error + LDY #ERR_IOERR ; init error @END1: LDA SS,X ; set CS high ORA #SS0 STA SS,X diff --git a/src/Helper.s b/src/Helper.s index 9cc5801..1ecbed8 100644 --- a/src/Helper.s +++ b/src/Helper.s @@ -112,6 +112,7 @@ GETR3: JSR GETR1 ; get R1 first GETBLOCK: PHX ; save X PHY ; save Y LDX SLOT ; SLOT is now in X + LDY SLOT16 LDA BLOCKNUM ; store block num STA R33,X ; in R30-R33 LDA BLOCKNUM+1 @@ -119,7 +120,7 @@ GETBLOCK: PHX ; save X STZ R31,X STZ R30,X - TXA ; get SLOT + TYA ; get SLOT16 EOR DSNUMBER AND #$70 ; check only slot bits BEQ @DRIVE ; it is our slot @@ -133,7 +134,6 @@ GETBLOCK: PHX ; save X STA R31,X @SDHC: LDA #SDHC - LDY SLOT16 ; SLOT16 is now in Y AND SS,Y ; if card is SDHC, BNE @END ; use block addressing diff --git a/src/ProDOS.s b/src/ProDOS.s index b816eec..7c7017f 100644 --- a/src/ProDOS.s +++ b/src/ProDOS.s @@ -48,7 +48,7 @@ PRODOS: LDA DCMD ; get command BEQ @READ CMP #2 BEQ @WRITE - LDA ERR_BADCMD ; unknown command + LDA #ERR_BADCMD ; unknown command SEC RTS @@ -76,7 +76,7 @@ PRODOS: LDA DCMD ; get command STATUS: LDA NO_ERR ; no error JSR WRPROT BCC @DONE - LDA ERR_NOWRITE ; card write protected + LDA #ERR_NOWRITE; card write protected @DONE: LDX #$FF ; 32 MB partition LDY #$FF @@ -139,7 +139,7 @@ READ: JSR GETBLOCK ; calc block address AND #<~FRX STA CTRL,X CLC ; no error - LDA NO_ERR + LDA #NO_ERR @DONE: PHP PHA @@ -151,7 +151,7 @@ READ: JSR GETBLOCK ; calc block address RTS @ERROR: SEC ; an error occured - LDA ERR_IOERR + LDA #ERR_IOERR BRA @DONE @@ -227,9 +227,9 @@ WRITE: JSR WRPROT RTS @IOERROR: SEC ; an error occured - LDA ERR_IOERR + LDA #ERR_IOERR BRA @DONE @WPERROR: SEC - LDA ERR_NOWRITE + LDA #ERR_NOWRITE BRA @DONE diff --git a/src/Smartport.s b/src/Smartport.s index 4d10ec1..4d74b13 100644 --- a/src/Smartport.s +++ b/src/Smartport.s @@ -15,7 +15,7 @@ .include "AppleIISd.inc" -.segment "SLOTROM" +.segment "EXTROM" ;*******************************