Check card status in ProDOS commands

This commit is contained in:
Florian Reitz 2020-06-04 18:06:07 +02:00
parent c3d693f268
commit 71428384cc
6 changed files with 64 additions and 22 deletions

Binary file not shown.

Binary file not shown.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
;*******************************
;