From f849639df2fabb7aa6dcfc9e8cc6203c76ed24ee Mon Sep 17 00:00:00 2001 From: Florian Reitz Date: Thu, 4 Jun 2020 13:02:00 +0200 Subject: [PATCH 1/3] Fix for unintended PGMEN usage --- .gitignore | 2 ++ ProFile.zip => Binary/ProFile.zip | Bin Firmware/src/AppleIISd.inc | 1 - Firmware/src/AppleIISd.s | 23 +++++++++-------------- Firmware/src/Smartport.s | 2 ++ README.md | 2 ++ 6 files changed, 15 insertions(+), 15 deletions(-) rename ProFile.zip => Binary/ProFile.zip (100%) diff --git a/.gitignore b/.gitignore index 3096d2b..0d6d309 100644 --- a/.gitignore +++ b/.gitignore @@ -219,3 +219,5 @@ VHDL/_pace\.ucf VHDL/AppleIISd\.tim VHDL/AppleIISd\.jed + +Firmware/AppleIISd.bin diff --git a/ProFile.zip b/Binary/ProFile.zip similarity index 100% rename from ProFile.zip rename to Binary/ProFile.zip diff --git a/Firmware/src/AppleIISd.inc b/Firmware/src/AppleIISd.inc index 5659e3e..e1838b9 100644 --- a/Firmware/src/AppleIISd.inc +++ b/Firmware/src/AppleIISd.inc @@ -48,7 +48,6 @@ KNOWNRTS := $FF58 OAPPLE := $C061 ; open apple key DATA := $C080 CTRL := DATA+1 -DIV := DATA+2 SS := DATA+3 ; Constants diff --git a/Firmware/src/AppleIISd.s b/Firmware/src/AppleIISd.s index 7e17e4a..46f08bb 100644 --- a/Firmware/src/AppleIISd.s +++ b/Firmware/src/AppleIISd.s @@ -1,10 +1,10 @@ ;******************************* ; ; Apple][Sd Firmware -; Version 1.2.1 +; Version 1.2.2 ; Main source ; -; (c) Florian Reitz, 2017 - 2018 +; (c) Florian Reitz, 2017 - 2020 ; ; X register usually contains SLOT16 ; Y register is used for counting or SLOT @@ -53,7 +53,8 @@ LDX #$20 LDX #$00 LDX #$03 - LDX #$00 ; is Smartport controller + ;LDX #$00 ; is Smartport controller + LDX #$3C ; is a disk controller SEI ; find slot LDA #$60 ; opcode for RTS @@ -65,7 +66,6 @@ STA CURSLOT ; $Cs AND #$0F STA SLOT ; $0s - TAY ; Y holds now SLOT ASL A ASL A ASL A @@ -95,7 +95,6 @@ JMP (CMDLO) @INIT: JSR INIT - CMP #NO_ERR BNE @NEXTSLOT ; init not successful ;******************************* @@ -228,13 +227,9 @@ DRIVER: CLC ; ProDOS entry ;******************************* .segment "EXTROM" -INIT: LDA #$03 ; set SPI mode 3 - STA CTRL,X - LDA SS,X - ORA #SS0 ; set CS high +INIT: STZ CTRL,X ; reset SPI controller + LDA #SS0 ; set CS high STA SS,X - LDA #7 ; set 400 kHz - STA DIV,X LDY #10 LDA #DUMMY @@ -362,13 +357,13 @@ INIT: LDA #$03 ; set SPI mode 3 @END1: LDA SS,X ; set CS high ORA #SS0 STA SS,X - LDA #0 ; set div to 2 - STA DIV,X TYA ; retval in A RTS -TEXT: .asciiz " Apple][Sd v1.2.1 (c)2018 Florian Reitz " +TEXT: .asciiz " Apple][Sd v1.2.2 (c)2020 Florian Reitz" + .assert(*-TEXT)=40, error, "TEXT must be 40 bytes long" + CMD0: .byt $40, $00, $00 .byt $00, $00, $95 diff --git a/Firmware/src/Smartport.s b/Firmware/src/Smartport.s index da41235..ce781c3 100644 --- a/Firmware/src/Smartport.s +++ b/Firmware/src/Smartport.s @@ -95,8 +95,10 @@ SMARTPORT: LDY #SMZPSIZE-1 ; save zeropage area for Smarport BCC @RESTZP TXA +;warum feste anzahl an bytes für return wert? LDY #2 ; highbyte of # bytes transferred LDX #0 ; low byte of # bytes transferred +;warum wird mit #1 verglichen? CMP #1 ; C=1 if A != NO_ERR RTS diff --git a/README.md b/README.md index f946d9b..f5cdc73 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,8 @@ The control registers of the *AppleIISd* are mapped to the usual I/O space at ** **DATA** SPI data register - Is used for both input and output. When the register is written to, the controller will output the byte on the SPI bus. When it is read from, it reflects the data that was received over the SPI bus. +**PGMEN** Program Enable - Enable programing of the internal firmware eeprom. Should be reset immediately after writing to the device. + **ECE** External Clock Enable - This bit enables the the external clock input to the SPI controller. In the *AppleIISd*, this effectively switches the SPI clock between 500kHz (ECE = 0) and 3.5MHz (ECE = 1). **FRX** Fast Receive mode - When set to 1, fast receive mode triggers shifting upon reading or writing the SPI Data register. When set to 0, shifting is only triggered by writing the SPI data register. From c3d693f268d13b57ca80c643a9a94e066bf24c58 Mon Sep 17 00:00:00 2001 From: Florian Reitz Date: Thu, 4 Jun 2020 16:48:30 +0200 Subject: [PATCH 2/3] Local replacement for KNOWNRTS --- Firmware/src/AppleIISd.inc | 5 ++--- Firmware/src/AppleIISd.s | 14 +++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Firmware/src/AppleIISd.inc b/Firmware/src/AppleIISd.inc index e1838b9..8ff13b3 100644 --- a/Firmware/src/AppleIISd.inc +++ b/Firmware/src/AppleIISd.inc @@ -1,10 +1,10 @@ ;******************************* ; ; Apple][Sd Firmware -; Version 1.2 +; Version 1.2.2 ; Defines ; -; (c) Florian Reitz, 2017 - 2018 +; (c) Florian Reitz, 2017 - 2020 ; ; X register usually contains SLOT16 ; Y register is used for counting or SLOT @@ -44,7 +44,6 @@ DRVNUM := $0678 CURSLOT := $07F8 ; $Cs ; Rom equates -KNOWNRTS := $FF58 OAPPLE := $C061 ; open apple key DATA := $C080 CTRL := DATA+1 diff --git a/Firmware/src/AppleIISd.s b/Firmware/src/AppleIISd.s index 46f08bb..d3c439c 100644 --- a/Firmware/src/AppleIISd.s +++ b/Firmware/src/AppleIISd.s @@ -57,9 +57,8 @@ LDX #$3C ; is a disk controller SEI ; find slot - LDA #$60 ; opcode for RTS - STA SLOT - JSR SLOT + BIT $CFFF + JSR KNOWNRTS TSX LDA $0100,X CLI @@ -72,7 +71,6 @@ ASL A STA SLOT16 ; $s0 TAX ; X holds now SLOT16 - BIT $CFFF LDY #0 ; display copyright message @DRAW: LDA TEXT,Y @@ -144,9 +142,8 @@ DRIVER: CLC ; ProDOS entry ; Has this to be done every time this gets called or only on boot??? SEI - LDA #$60 ; opcode for RTS - STA SLOT - JSR SLOT + BIT $CFFF + JSR KNOWNRTS TSX LDA $0100,X CLI @@ -160,7 +157,6 @@ DRIVER: CLC ; ProDOS entry ASL A STA SLOT16 ; $s0 TAX ; X holds now SLOT16 - BIT $CFFF JSR CARDDET BCC @INITED @@ -358,7 +354,7 @@ INIT: STZ CTRL,X ; reset SPI controller ORA #SS0 STA SS,X TYA ; retval in A - RTS +KNOWNRTS: RTS TEXT: .asciiz " Apple][Sd v1.2.2 (c)2020 Florian Reitz" From 71428384ccca0bf91df26a5cc9e3f80aa21ee896 Mon Sep 17 00:00:00 2001 From: Florian Reitz Date: Thu, 4 Jun 2020 18:06:07 +0200 Subject: [PATCH 3/3] Check card status in ProDOS commands --- Binary/AppleIISd.bin | Bin 2048 -> 2048 bytes Binary/Flasher.dsk | Bin 143360 -> 143360 bytes Firmware/src/AppleIISd.inc | 2 +- Firmware/src/AppleIISd.s | 15 ++++++--------- Firmware/src/Helper.s | 34 ++++++++++++++++++++++++++++------ Firmware/src/ProDOS.s | 35 +++++++++++++++++++++++++++++------ 6 files changed, 64 insertions(+), 22 deletions(-) diff --git a/Binary/AppleIISd.bin b/Binary/AppleIISd.bin index d0ea52268a246cf00d6d09f2cd69f255f6616b60..311a4eee8ded642084f1dbae20f21b8a404c2281 100644 GIT binary patch delta 712 zcmZ8fO=uHA7@gVO{8}}Y91`^~qP7W@v<(#lNt#BqS;{JCL29J9Vu}rfT8&64{zO7V z0)>rxXmY45u@$DLh^Gj}&{HPa;DX13KZsC0?ZsLv7^kh6;LPd0$NT2Jk4f25wyq*7 zf+AZC%$#VxMMm;^1;DYnO_O_nCS;{2Gq|jPvMJYdG^pv=oH-ji6N|)#QMy+8gsr;} z!^{q$3DE42pwGOeaOEK2pV)pr4*s2+v)K=zNKG;zP%T-Og1oCVfJSqx1Kh28ipc%O zgO>TJXOAivE~Mp7=zQ3l8NwtJMpp?+5(2de>~AsIZRXNqsJv+)%i0Kzw4@}#qwR=5 z{UZTd7e3cwsU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6Z9 znUxCJBe=y#+A&J2J@Z5C!w&gY5IQ#di8uDi2{hP!2{)fR7w$TKEYyiFZK|oOsl(n= zzPj4FTD&`a_Cn9eGkAYj&&A7fU=JMUBD&C_u;QRRMA351EK{7T^Y%d09>}wS=)*pZ zP*J%|go@sciS0yBG~*LGj_5j=U8KIq^cR>zbR>DZK4u0m~Kqs69z3+n@IWW?8Lvh}~hS6c9p=6_gZ zE-gsMsPtr?=42oAX>J828NcG8dfG7c(zzSQ4fQ?Ye?tO^Il>fyb0@*i%_!_dBNA@7zF%+rBQ3ky zpnS>SojOMv1+TgVhvXM+u!TLJiRpL1w!$W#83G%y2M!)OO!1G@n0?4)hk-}c@oM#H JwF+-~e*rA{dZ_>a delta 828 zcma)(&ubG=5XW~-v}2MrqV=Lk;;bzO6QPn#ixq1(5RrOVFprIgG??IBrODU!9!YC@tO6S|Ohz!eS%Zl@`1Kza}^pVazd zY8qrjjaJ^CraKdHlw%^EUE0~!@IOxG6Lu`2gH{l+Luo^-NWwraj%2=@vxBP@+VP)2)h6P diff --git a/Firmware/src/AppleIISd.inc b/Firmware/src/AppleIISd.inc index 8ff13b3..2edf35a 100644 --- a/Firmware/src/AppleIISd.inc +++ b/Firmware/src/AppleIISd.inc @@ -57,7 +57,7 @@ SS0 = $01 ; SS register SDHC = $10 WP = $20 CD = $40 -INITED = $80 +CARD_INIT = $80 SMDRIVERVER = $120B ; Version 1.2 Beta diff --git a/Firmware/src/AppleIISd.s b/Firmware/src/AppleIISd.s index d3c439c..00854c1 100644 --- a/Firmware/src/AppleIISd.s +++ b/Firmware/src/AppleIISd.s @@ -11,12 +11,15 @@ ; ;******************************* +.export INIT + .import PRODOS .import SMARTPORT .import GETR1 .import GETR3 .import SDCMD .import CARDDET +.import INITED .import READ .include "AppleIISd.inc" @@ -158,14 +161,8 @@ DRIVER: CLC ; ProDOS entry STA SLOT16 ; $s0 TAX ; X holds now SLOT16 - JSR CARDDET - BCC @INITED - LDA #ERR_OFFLINE; no card inserted - BRA @END - -@INITED: LDA #INITED ; check for init - BIT SS,X - BNE @DISP + JSR INITED ; check for init + BCC @DISP JSR INIT BCS @END ; Init failed @@ -339,7 +336,7 @@ INIT: STZ CTRL,X ; reset SPI controller BNE @IOERROR ; error! @END: LDA SS,X - ORA #INITED ; initialized + ORA #CARD_INIT ; initialized STA SS,X LDA CTRL,X ORA #ECE ; enable 7MHz diff --git a/Firmware/src/Helper.s b/Firmware/src/Helper.s index 0f659e2..3204d37 100644 --- a/Firmware/src/Helper.s +++ b/Firmware/src/Helper.s @@ -1,23 +1,25 @@ ;******************************* ; ; Apple][Sd Firmware -; Version 1.2 +; Version 1.2.2 ; Helper functions ; -; (c) Florian Reitz, 2017 - 2018 +; (c) Florian Reitz, 2017 - 2020 ; ; X register usually contains SLOT16 ; Y register is used for counting or SLOT ; ;******************************* -.export COMMAND .export SDCMD -.export GETBLOCK -.export CARDDET -.export WRPROT .export GETR1 .export GETR3 +.export GETBLOCK +.export COMMAND +.export CARDDET +.export WRPROT +.export INITED + .include "AppleIISd.inc" .segment "EXTROM" @@ -212,3 +214,23 @@ WRPROT: PHA SEC @DONE: PLA RTS + + +;******************************* +; +; Check if card is initialized +; X must contain SLOT16 +; +; C Clear - card initialized +; Set - card not initialized +; +;******************************* + +INITED: PHA + LDA #CARD_INIT ; 0: card not initialized + BIT SS,X ; 1: card initialized + CLC + BNE @DONE + SEC +@DONE: PLA + RTS diff --git a/Firmware/src/ProDOS.s b/Firmware/src/ProDOS.s index 0cd0493..603a9d0 100644 --- a/Firmware/src/ProDOS.s +++ b/Firmware/src/ProDOS.s @@ -1,10 +1,10 @@ ;******************************* ; ; Apple][Sd Firmware -; Version 1.2 +; Version 1.2.2 ; ProDOS functions ; -; (c) Florian Reitz, 2017 - 2018 +; (c) Florian Reitz, 2017 - 2020 ; ; X register usually contains SLOT16 ; Y register is used for counting or SLOT @@ -19,6 +19,9 @@ .import COMMAND .import SDCMD .import GETBLOCK +.import CARDDET +.import INITED +.import INIT .import WRPROT .import GETR1 .import GETR3 @@ -67,6 +70,7 @@ PRODOS: LDA DCMD ; get command ; C Clear - No error ; Set - Error ; A $00 - No error +; $28 - No card inserted ; $2B - Card write protected ; X - Blocks avail (low byte) ; Y - Blocks avail (high byte) @@ -74,7 +78,12 @@ PRODOS: LDA DCMD ; get command ;******************************* STATUS: LDA #NO_ERR ; Thanks for this one, Antoine! - JSR WRPROT + JSR CARDDET + BCC @WRPROT + LDA #ERR_NODRIVE; no card inserted + BNE @DONE + +@WRPROT: JSR WRPROT BCC @DONE LDA #ERR_NOWRITE; card write protected @@ -94,10 +103,20 @@ STATUS: LDA #NO_ERR ; Thanks for this one, Antoine! ; Set - Error ; A $00 - No error ; $27 - Bad block number +; $28 - No card inserted ; ;******************************* -READ: JSR GETBLOCK ; calc block address +READ: JSR CARDDET ; check for card + BCS @NDERROR ; no card + + JSR INITED ; check for initialization + BCC @GETBLOCK + + JSR INIT ; initialize card + BCS @NDERROR ; init failed + +@GETBLOCK: JSR GETBLOCK ; calc block address LDA SS,X ; enable /CS AND #<~SS0 @@ -105,7 +124,7 @@ READ: JSR GETBLOCK ; calc block address LDA #$51 ; send CMD17 JSR COMMAND ; send command CMP #0 - BNE @ERROR ; check for error + BNE @IOERROR ; check for error @GETTOK: LDA #DUMMY ; get data token STA DATA,X @@ -150,10 +169,14 @@ READ: JSR GETBLOCK ; calc block address PLP RTS -@ERROR: SEC ; an error occured +@IOERROR: SEC ; an error occured LDA #ERR_IOERR BRA @DONE +@NDERROR: SEC ; an error occured + LDA #ERR_NODRIVE + BRA @DONE + ;******************************* ;