Debug flags added, block and command sequences moved to subroutine

This commit is contained in:
freitz85 2017-07-16 15:36:47 +02:00
parent 240b301bad
commit 624bd4e9a7
2 changed files with 806 additions and 794 deletions

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,12 @@
DAT DAT
XC ; enable 65C02 code XC ; enable 65C02 code
DEBUG = 1
DO DEBUG
ORG $8000
ELSE
ORG $C800 ; Expansion ROM ORG $C800 ; Expansion ROM
FIN
* Memory defines * Memory defines
@ -53,9 +58,16 @@ DUMMY = $FF
LDX #$03 LDX #$03
STX WORK STX WORK
PAG
* find slot nr * find slot nr
DO DEBUG
LDA #$04
STA SLOT
LDA #$C4
STA CURSLOT
LDA #$40
STA SLOT16
ELSE
JSR $FF58 JSR $FF58
TSX TSX
LDA $0100,X LDA $0100,X
@ -68,6 +80,8 @@ DUMMY = $FF
ASL A ASL A
ASL A ASL A
STA SLOT16 ; $s0 STA SLOT16 ; $s0
FIN
TAX ; X holds now SLOT16
JSR INIT JSR INIT
BIT $CFFF BIT $CFFF
@ -89,9 +103,10 @@ INSLP LDA $BF32,X ; get a devnum
* restore the devnum to the list * restore the devnum to the list
LDX $BF31 ; get devcnt again LDX $BF31 ; get devcnt again
CPX #$0D device table full? CPX #$0D ; device table full?
BNE INSLP2 BNE INSLP2
JSR $FF3A ; bell
JMP INSOUT ; do something! JMP INSOUT ; do something!
INSLP2 LDA $BF32-1,X ; move all entries down INSLP2 LDA $BF32-1,X ; move all entries down
@ -103,14 +118,18 @@ INSLP2 LDA $BF32-1,X ; move all entries down
STA $BF32 ; slot, drive 1 at top of list STA $BF32 ; slot, drive 1 at top of list
INC $BF31 ; update devcnt INC $BF31 ; update devcnt
PAG
* now insert the device driver vector * now insert the device driver vector
LDA SLOT LDA SLOT
ASL
TAX TAX
LDA #<DRIVER LDA #<DRIVER
STA $BF10,X STA $BF10,X ; write to driver table
DO DEBUG
LDA #>DRIVER
ELSE
LDA CURSLOT LDA CURSLOT
FIN
STA $BF11,X STA $BF11,X
INSOUT RTS INSOUT RTS
@ -123,6 +142,14 @@ INSOUT RTS
******************************** ********************************
DRIVER CLD DRIVER CLD
DO DEBUG
LDA #$04
STA SLOT
LDA #$C4
STA CURSLOT
LDA #$40
STA SLOT16
ELSE
JSR $FF58 ; find slot nr JSR $FF58 ; find slot nr
TSX TSX
LDA $0100,X LDA $0100,X
@ -135,6 +162,7 @@ DRIVER CLD
ASL A ASL A
ASL A ASL A
STA SLOT16 ; $s0 STA SLOT16 ; $s0
FIN
TAX ; X holds now SLOT16 TAX ; X holds now SLOT16
BIT $CFFF BIT $CFFF
@ -156,10 +184,10 @@ DRIVER CLD
:WRITE JMP WRITE :WRITE JMP WRITE
:FORMAT JMP FORMAT :FORMAT JMP FORMAT
PAG
* Signature bytes * Signature bytes
ORG $C8FC DS \ ; fill with zeroes
DS -4 ; locate to $C8FC
DW $FFFF ; 65535 blocks DW $FFFF ; 65535 blocks
DB $47 ; Status bits DB $47 ; Status bits
DB #<DRIVER ; LSB of driver DB #<DRIVER ; LSB of driver
@ -177,10 +205,7 @@ DRIVER CLD
* *
******************************** ********************************
ORG $C900
INIT CLD INIT CLD
LDX SLOT16
LDA #$03 ; set SPI mode 3 LDA #$03 ; set SPI mode 3
STA CTRL,X STA CTRL,X
LDA #SSNONE LDA #SSNONE
@ -279,18 +304,18 @@ INIT CLD
BNE :IOERROR ; error! BNE :IOERROR ; error!
:END CLC ; all ok :END CLC ; all ok
LDX #0 LDY #0
BCC :END1 BCC :END1
:CDERROR SEC :CDERROR SEC
LDX #$28 ; no card error LDY #$28 ; no card error
BCS :END1 BCS :END1
:IOERROR SEC :IOERROR SEC
LDX #$27 ; init error LDY #$27 ; init error
:END1 LDA #SSNONE ; deselect card :END1 LDA #SSNONE ; deselect card
STA SS,X STA SS,X
LDA #0 ; set div to 2 LDA #0 ; set div to 2
STA DIV,X STA DIV,X
TXA ; retval in A TYA ; retval in A
RTS RTS
@ -313,7 +338,7 @@ CMD PHY
PLY PLY
RTS RTS
PAG
******************************** ********************************
* *
* Get R1 * Get R1
@ -346,17 +371,16 @@ GETR1 LDA #DUMMY
GETR3 JSR GETR1 ; get R1 first GETR3 JSR GETR1 ; get R1 first
PHA ; save R1 PHA ; save R1
PHY ; save Y PHY ; save Y
LDA #04 ; load counter LDY #04 ; load counter
STA WORK
LDY SLOT
:LOOP LDA #DUMMY ; send dummy :LOOP LDA #DUMMY ; send dummy
STA DATA,X STA DATA,X
:WAIT BIT CTRL,X :WAIT BIT CTRL,X
BPL :WAIT BPL :WAIT
LDA DATA,X LDA DATA,X
PHA PHA
DEC WORK DEY
BNE :LOOP ; do 4 times BNE :LOOP ; do 4 times
LDY SLOT
PLA PLA
STA R33,Y ; save R3 STA R33,Y ; save R3
PLA PLA
@ -364,7 +388,7 @@ GETR3 JSR GETR1 ; get R1 first
PLA PLA
STA R31,Y STA R31,Y
PLA PLA
STA R30,X STA R30,Y
PLY ; restore Y PLY ; restore Y
LDA #DUMMY LDA #DUMMY
STA DATA,X ; send another dummy STA DATA,X ; send another dummy
@ -372,10 +396,88 @@ GETR3 JSR GETR1 ; get R1 first
RTS RTS
********************************
*
* Calculate block address
* Block no is in $46-47
* Address is in R30-R33
*
********************************
BLOCK PHY ; save Y
LDY SLOT
LDA $46 ; store block num
STA R33,Y ; in R30-R33
LDA $47
STA R32,Y
LDA #0
STA R31,Y
STA R30,Y
PHX
LDY #9
LDX SLOT ; ASL can't be done 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
PLX
PLY ; restore Y
RTS
********************************
*
* Send SD command
* Cmd is in A
*
********************************
COMMAND PLY ; save Y
LDY SLOT
STA DATA,X ; send command
:WAIT BIT CTRL,X
BPL :WAIT
:ARG LDA R30,Y ; get arg from R30 on
STA DATA,X
:WAIT1 BIT CTRL,X
BPL :WAIT1
LDA R31,Y
STA DATA,X
:WAIT11 BIT CTRL,X
BPL :WAIT11
LDA R32,Y
STA DATA,X
:WAIT12 BIT CTRL,X
BPL :WAIT12
LDA R33,Y
STA DATA,X
:WAIT13 BIT CTRL,X
BPL :WAIT13
LDA #DUMMY
STA DATA,X ; dummy crc
:WAIT2 BIT CTRL,X
BPL :WAIT2
:GETR1 LDA #DUMMY
STA DATA,X ; get R1
:WAIT3 BIT CTRL,X
BPL :WAIT3
LDA DATA,X ; get response
*
* TODO: check for error!
*
CMP #$FE
BNE :GETR1 ; wait for $FE
PLY ; restore Y
RTS
******************************** ********************************
* *
* Status request * Status request
* $43 Unt number DSSS000 * $43 Unit number DSSS000
* $44-45 Unused * $44-45 Unused
* $46-47 Unused * $46-47 Unused
* *
@ -416,66 +518,12 @@ STATUS CLC ; no error
* TODO: check for card detect! * TODO: check for card detect!
READ LDA #SS0 ; enable /CS READ JSR BLOCK ; calc block address
LDA #SS0 ; enable /CS
STA SS,X STA SS,X
PHY ; save Y
LDY SLOT
LDA $46 ; store block num
STA R33,Y ; in R30-R33
LDA $47
STA R32,Y
LDA #0
STA R31,Y
STA R30,Y
PHX
PHY
LDY #9
LDX SLOT ; ASL can't be done 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
PLY
PLX
LDA #$51 ; send CMD17 LDA #$51 ; send CMD17
STA DATA,X JSR COMMAND ; send command
:WAIT BIT CTRL,X
BPL :WAIT
:ARG LDA R30,Y ; get arg from R30 on
STA DATA,X
:WAIT1 BIT CTRL,X
BPL :WAIT1
LDA R31,Y
STA DATA,X
:WAIT11 BIT CTRL,X
BPL :WAIT11
LDA R32,Y
STA DATA,X
:WAIT12 BIT CTRL,X
BPL :WAIT12
LDA R33,Y
STA DATA,X
:WAIT13 BIT CTRL,X
BPL :WAIT13
LDA #DUMMY
STA DATA,X ; dummy crc
:WAIT2 BIT CTRL,X
BPL :WAIT2
:GETR1 LDA #DUMMY
STA DATA,X ; get R1
:WAIT3 BIT CTRL,X
BPL :WAIT3
LDA DATA,X ; get response
*
* TODO: check for error!
*
CMP #$FE
BNE :GETR1 ; wait for $FE
PHY PHY
LDY #2 ; read data from card LDY #2 ; read data from card
@ -495,7 +543,7 @@ READ LDA #SS0 ; enable /CS
BNE :LOOPY BNE :LOOPY
PLY PLY
:OK JSR GETR3 ; read 2 bytes crc JSR GETR3 ; read 2 bytes crc
LDA #SSNONE LDA #SSNONE
STA SS,X ; disable /CS STA SS,X ; disable /CS
CLC ; no error CLC ; no error
@ -528,66 +576,12 @@ READ LDA #SS0 ; enable /CS
* TODO: check for card detect and write protect! * TODO: check for card detect and write protect!
WRITE LDA #SS0 ; enable /CS WRITE JSR BLOCK ; calc block address
LDA #SS0 ; enable /CS
STA SS,X STA SS,X
PHY
LDY SLOT
LDA $46 ; store block num
STA R33,Y
LDA $47
STA R32,Y
LDA #0
STA R31,Y
STA R30,Y
PHX
PHY
LDY #9
LDX SLOT ; ASL can't be done 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
PLY
PLX
LDA #$58 ; send CMD24 LDA #$58 ; send CMD24
STA DATA,X JSR COMMAND ; send command
:WAIT BIT CTRL,X
BPL :WAIT
:ARG LDA R30,Y ; get arg from R30 on
STA DATA,X
:WAIT1 BIT CTRL,X
BPL :WAIT1
LDA R31,Y
STA DATA,X
:WAIT11 BIT CTRL,X
BPL :WAIT11
LDA R32,Y
STA DATA,X
:WAIT12 BIT CTRL,X
BPL :WAIT12
LDA R33,Y
STA DATA,X
:WAIT13 BIT CTRL,X
BPL :WAIT13
LDA #DUMMY
STA DATA,X ; dummy crc
:WAIT2 BIT CTRL,X
BPL :WAIT2
:GETR1 LDA #DUMMY
STA DATA,X ; get R1
:WAIT3 BIT CTRL,X
BPL :WAIT3
LDA DATA,X ; get response
*
* TODO: check for error!
*
CMP #$FE
BNE :GETR1 ; wait for $FE
PHY PHY
LDY #2 ; send data to card LDY #2 ; send data to card
@ -612,7 +606,7 @@ WRITE LDA #SS0 ; enable /CS
BNE :CRC BNE :CRC
PLY PLY
:OK LDA #SSNONE ; disable /CS LDA #SSNONE ; disable /CS
STA SS,X STA SS,X
CLC ; no error CLC ; no error
LDA #0 LDA #0
@ -632,7 +626,6 @@ FORMAT SEC
RTS RTS
CMD0 HEX 400000 CMD0 HEX 400000
HEX 000095 HEX 000095
CMD1 HEX 410000 CMD1 HEX 410000
@ -647,4 +640,3 @@ ACMD4140 HEX 694000
HEX 000077 HEX 000077
ACMD410 HEX 690000 ACMD410 HEX 690000
HEX 0000FF HEX 0000FF
PAG