2017-12-03 21:18:37 +00:00
|
|
|
;*******************************
|
|
|
|
;
|
|
|
|
; Apple][Sd Firmware
|
2020-06-04 16:06:07 +00:00
|
|
|
; Version 1.2.2
|
2017-12-17 19:21:30 +00:00
|
|
|
; Helper functions
|
2017-12-03 21:18:37 +00:00
|
|
|
;
|
2021-02-20 12:59:37 +00:00
|
|
|
; (c) Florian Reitz, 2017 - 2021
|
2017-12-03 21:18:37 +00:00
|
|
|
;
|
|
|
|
; X register usually contains SLOT16
|
|
|
|
; Y register is used for counting or SLOT
|
|
|
|
;
|
|
|
|
;*******************************
|
|
|
|
|
|
|
|
.export SDCMD
|
2020-06-04 16:06:07 +00:00
|
|
|
.export GETR1
|
|
|
|
.export GETR3
|
2017-12-03 21:18:37 +00:00
|
|
|
.export GETBLOCK
|
2020-06-04 16:06:07 +00:00
|
|
|
.export COMMAND
|
2017-12-03 21:18:37 +00:00
|
|
|
.export CARDDET
|
|
|
|
.export WRPROT
|
2020-06-04 16:06:07 +00:00
|
|
|
.export INITED
|
|
|
|
|
2017-12-03 21:18:37 +00:00
|
|
|
|
|
|
|
.include "AppleIISd.inc"
|
|
|
|
.segment "EXTROM"
|
|
|
|
|
|
|
|
|
|
|
|
;*******************************
|
|
|
|
;
|
|
|
|
; Send SD command
|
|
|
|
; Call with command in CMDHI and CMDLO
|
|
|
|
;
|
|
|
|
;*******************************
|
|
|
|
|
|
|
|
SDCMD: PHY
|
|
|
|
LDY #0
|
|
|
|
@LOOP: LDA (CMDLO),Y
|
|
|
|
STA DATA,X
|
|
|
|
@WAIT: BIT CTRL,X ; TC is in N
|
|
|
|
BPL @WAIT
|
|
|
|
INY
|
|
|
|
CPY #6
|
|
|
|
BCC @LOOP
|
|
|
|
PLY
|
|
|
|
RTS
|
|
|
|
|
|
|
|
|
|
|
|
;*******************************
|
|
|
|
;
|
|
|
|
; Get R1
|
|
|
|
; R1 is in A
|
|
|
|
;
|
|
|
|
;*******************************
|
|
|
|
|
|
|
|
GETR1: LDA #DUMMY
|
|
|
|
STA DATA,X
|
|
|
|
@WAIT: BIT CTRL,X
|
|
|
|
BPL @WAIT
|
|
|
|
LDA DATA,X ; get response
|
2018-07-07 15:28:30 +00:00
|
|
|
BMI GETR1 ; wait for MSB=0
|
2017-12-03 21:18:37 +00:00
|
|
|
PHA
|
|
|
|
LDA #DUMMY
|
|
|
|
STA DATA,X ; send another dummy
|
|
|
|
PLA ; restore R1
|
|
|
|
RTS
|
|
|
|
|
|
|
|
;*******************************
|
|
|
|
;
|
2017-12-17 19:21:30 +00:00
|
|
|
; Get R3 or R7
|
2017-12-03 21:18:37 +00:00
|
|
|
; R1 is in A
|
|
|
|
; R3 is in scratchpad ram
|
|
|
|
;
|
|
|
|
;*******************************
|
|
|
|
|
|
|
|
GETR3: JSR GETR1 ; get R1 first
|
|
|
|
PHA ; save R1
|
|
|
|
PHY ; save Y
|
|
|
|
LDY #04 ; load counter
|
2017-12-17 19:21:30 +00:00
|
|
|
JMP @WAIT ; first byte is already there
|
2017-12-03 21:18:37 +00:00
|
|
|
@LOOP: LDA #DUMMY ; send dummy
|
|
|
|
STA DATA,X
|
|
|
|
@WAIT: BIT CTRL,X
|
|
|
|
BPL @WAIT
|
|
|
|
LDA DATA,X
|
|
|
|
PHA
|
|
|
|
DEY
|
|
|
|
BNE @LOOP ; do 4 times
|
|
|
|
LDY SLOT
|
|
|
|
PLA
|
|
|
|
STA R33,Y ; save R3
|
|
|
|
PLA
|
|
|
|
STA R32,Y
|
|
|
|
PLA
|
|
|
|
STA R31,Y
|
|
|
|
PLA
|
2017-12-17 19:21:30 +00:00
|
|
|
STA R30,Y ; R30 is MSB
|
2017-12-03 21:18:37 +00:00
|
|
|
PLY ; restore Y
|
|
|
|
LDA #DUMMY
|
|
|
|
STA DATA,X ; send another dummy
|
|
|
|
PLA ; restore R1
|
|
|
|
RTS
|
|
|
|
|
|
|
|
|
|
|
|
;*******************************
|
|
|
|
;
|
|
|
|
; Calculate block address
|
|
|
|
; Unit number is in $43 DSSS0000
|
|
|
|
; Block no is in $46-47
|
|
|
|
; Address is in R30-R33
|
|
|
|
;
|
|
|
|
;*******************************
|
|
|
|
|
|
|
|
GETBLOCK: PHX ; save X
|
|
|
|
PHY ; save Y
|
2018-05-13 15:58:41 +00:00
|
|
|
LDX SLOT ; SLOT is now in X
|
2018-05-22 19:53:11 +00:00
|
|
|
LDY SLOT16
|
2018-05-13 15:58:41 +00:00
|
|
|
LDA BLOCKNUM ; store block num
|
2017-12-03 21:18:37 +00:00
|
|
|
STA R33,X ; in R30-R33
|
2018-05-13 15:58:41 +00:00
|
|
|
LDA BLOCKNUM+1
|
2017-12-03 21:18:37 +00:00
|
|
|
STA R32,X
|
2017-12-17 20:27:04 +00:00
|
|
|
STZ R31,X
|
|
|
|
STZ R30,X
|
2017-12-03 21:18:37 +00:00
|
|
|
|
2018-05-22 19:53:11 +00:00
|
|
|
TYA ; get SLOT16
|
2018-05-13 15:58:41 +00:00
|
|
|
EOR DSNUMBER
|
|
|
|
AND #$70 ; check only slot bits
|
|
|
|
BEQ @DRIVE ; it is our slot
|
|
|
|
LDA #2 ; it is a phantom slot
|
2017-12-03 21:18:37 +00:00
|
|
|
STA R31,X
|
|
|
|
|
2018-05-13 15:58:41 +00:00
|
|
|
@DRIVE: BIT DSNUMBER ; drive number
|
|
|
|
BPL @SDHC ; D1
|
|
|
|
LDA R31,X ; D2
|
2017-12-17 20:27:04 +00:00
|
|
|
INC A
|
|
|
|
STA R31,X
|
|
|
|
|
2017-12-03 21:18:37 +00:00
|
|
|
@SDHC: LDA #SDHC
|
|
|
|
AND SS,Y ; if card is SDHC,
|
|
|
|
BNE @END ; use block addressing
|
|
|
|
|
|
|
|
LDY #9 ; ASL can't be used with Y
|
|
|
|
@LOOP: ASL R33,X ; mul block num
|
|
|
|
ROL R32,X ; by 512 to get
|
|
|
|
ROL R31,X ; real address
|
|
|
|
ROL R30,X
|
|
|
|
DEY
|
|
|
|
BNE @LOOP
|
|
|
|
|
|
|
|
@END: PLY ; restore Y
|
|
|
|
PLX ; restore X
|
|
|
|
RTS
|
|
|
|
|
|
|
|
|
|
|
|
;*******************************
|
|
|
|
;
|
|
|
|
; Send SD command
|
|
|
|
; Cmd is in A
|
|
|
|
;
|
|
|
|
;*******************************
|
|
|
|
|
|
|
|
COMMAND: PHY ; save Y
|
|
|
|
LDY SLOT
|
|
|
|
STA DATA,X ; send command
|
|
|
|
LDA R30,Y ; get arg from R30 on
|
|
|
|
STA DATA,X
|
|
|
|
LDA R31,Y
|
|
|
|
STA DATA,X
|
|
|
|
LDA R32,Y
|
|
|
|
STA DATA,X
|
|
|
|
LDA R33,Y
|
|
|
|
STA DATA,X
|
|
|
|
LDA #DUMMY
|
|
|
|
STA DATA,X ; dummy crc
|
|
|
|
JSR GETR1
|
|
|
|
PLY ; restore Y
|
|
|
|
RTS
|
|
|
|
|
|
|
|
|
|
|
|
;*******************************
|
|
|
|
;
|
|
|
|
; Check for card detect
|
2018-05-28 22:36:39 +00:00
|
|
|
; X must contain SLOT16
|
2017-12-03 21:18:37 +00:00
|
|
|
;
|
|
|
|
; C Clear - card in slot
|
|
|
|
; Set - no card in slot
|
|
|
|
;
|
|
|
|
;*******************************
|
|
|
|
|
|
|
|
CARDDET: PHA
|
|
|
|
LDA #CD ; 0: card in
|
|
|
|
BIT SS,X ; 1: card out
|
|
|
|
CLC
|
|
|
|
BEQ @DONE ; card is in
|
|
|
|
SEC ; card is out
|
|
|
|
@DONE: PLA
|
|
|
|
RTS
|
|
|
|
|
|
|
|
|
|
|
|
;*******************************
|
|
|
|
;
|
|
|
|
; Check for write protect
|
2018-05-28 22:36:39 +00:00
|
|
|
; X must contain SLOT16
|
2017-12-03 21:18:37 +00:00
|
|
|
;
|
|
|
|
; C Clear - card not protected
|
|
|
|
; Set - card write protected
|
|
|
|
;
|
|
|
|
;*******************************
|
|
|
|
|
|
|
|
WRPROT: PHA
|
|
|
|
LDA #WP ; 0: write enabled
|
|
|
|
BIT SS,X ; 1: write disabled
|
|
|
|
CLC
|
|
|
|
BEQ @DONE
|
|
|
|
SEC
|
|
|
|
@DONE: PLA
|
|
|
|
RTS
|
2020-06-04 16:06:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
;*******************************
|
|
|
|
;
|
|
|
|
; 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
|