ProDOS functions moved to separate file

Debug functions removed
This commit is contained in:
Florian Reitz 2017-12-17 20:39:59 +01:00
parent f656800697
commit 13bfa30227
6 changed files with 241 additions and 357 deletions

Binary file not shown.

View File

@ -18,6 +18,7 @@
<None Include="src\AppleIISd.inc" />
<None Include="src\AppleIISd.s" />
<None Include="src\Helper.s" />
<None Include="src\ProDOS.s" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{9EA7EC3D-1771-420F-932F-231A35ED1200}</ProjectGuid>

View File

@ -16,6 +16,9 @@
<None Include="src\AppleIISd.inc">
<Filter>src</Filter>
</None>
<None Include="src\ProDOS.s">
<Filter>src</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Filter Include="src">

View File

@ -1,7 +1,8 @@
;*******************************
;
; Apple][Sd Firmware
; Version 1.0
; Version 1.1
; Defines
;
; (c) Florian Reitz, 2017
;

View File

@ -11,19 +11,42 @@
;
;*******************************
.import COMMAND
.import SDCMD
.import GETBLOCK
.import CARDDET
.import WRPROT
.import GETR1
.import GETR3
.import SDCMD
.import CARDDET
.import STATUS
.import READ
.import WRITE
.include "AppleIISd.inc"
.define DEBUG 0
; signature bytes
;*******************************
;
; Signature bytes
;
; 65535 blocks
; Removable media
; Non-interruptable
; 2 drives
; Read, write and status allowed
;
;*******************************
.segment "SLOTID"
.dbyt $FFFF ; 65535 blocks
.byt $97 ; Status bits
.byt <DRIVER ; LSB of driver
;*******************************
;
; Bootcode
;
; Is executed on boot or PR#
;
;*******************************
.segment "SLOTROM"
LDX #$20
@ -32,15 +55,6 @@
LDX #$3C
; find slot nr
.if DEBUG
LDA #$04
STA SLOT
LDA #$C4
STA CURSLOT
LDA #$40
.else
PHP
SEI
LDA #$60 ; opcode for RTS
@ -56,7 +70,6 @@
ASL A
ASL A
ASL A
.endif
STA SLOT16 ; $s0
TAX ; X holds now SLOT16
@ -84,61 +97,12 @@
@INIT: JSR INIT
;*******************************
;
; Install SD card driver
;
;*******************************
.if DEBUG
; see if slot has a driver already
LDX $BF31 ; get devcnt
@INSTALL: LDA $BF32,X ; get a devnum
AND #$70 ; isolate slot
CMP SLOT16 ; slot?
BEQ @INSOUT ; yes, skip it
DEX
BPL @INSTALL ; keep up the search
; restore the devnum to the list
LDX $BF31 ; get devcnt again
CPX #$0D ; device table full?
BNE @INST2
JSR $FF3A ; bell
JMP @INSOUT ; do something!
@INST2: LDA $BF32-1,X ; move all entries down
STA $BF32,X ; to make room at front
DEX ; for a new entry
BNE @INST2
LDA #$04 ; ProFile type device
ORA SLOT16
STA $BF32 ; slot, drive 1 at top of list
INC $BF31 ; update devcnt
; now insert the device driver vector
LDA SLOT
ASL
TAX
LDA #<DRIVER
STA $BF10,X ; write to driver table
LDA #>DRIVER
STA $BF11,X
@INSOUT: RTS
;*******************************
;
; Boot from SD card
;
;*******************************
.else
;@BOOT: CMP #0
; BNE @NEXTSLOT ; init not successful
@BOOT: LDA #$01
@ -167,7 +131,6 @@
JSR READ ; call driver
LDX SLOT16
JMP $801 ; goto bootloader
.endif
;*******************************
@ -187,15 +150,6 @@ DRIVER: CLD
PHA
LDA CMDHI
PHA
.if DEBUG
LDA #$04
STA SLOT
LDA #$C4
STA CURSLOT
LDA #$40
.else
PHP
SEI
LDA #$60 ; opcode for RTS
@ -211,7 +165,6 @@ DRIVER: CLD
ASL A
ASL A
ASL A
.endif
STA SLOT16 ; $s0
TAX ; X holds now SLOT16
@ -231,10 +184,6 @@ DRIVER: CLD
BEQ @READ
CMP #2
BEQ @WRITE
.if DEBUG
CMP #$FF
BEQ @TEST
.endif
LDA #1 ; unknown command
SEC
BRA @RESTZP
@ -245,10 +194,6 @@ DRIVER: CLD
BRA @RESTZP
@WRITE: JSR WRITE
BRA @RESTZP
.if DEBUG
@TEST: JSR TEST ; do device test
BRA @RESTZP
.endif
@INIT: JSR INIT
BCC @CMD ; init ok
@ -267,23 +212,6 @@ DRIVER: CLD
RTS
;*******************************
;
; Signature bytes
;
; 65535 blocks
; Removable media
; Non-interruptable
; 2 drives
; Read, write and status allowed
;
;*******************************
.segment "SLOTID"
.dbyt $FFFF ; 65535 blocks
.byt $97 ; Status bits
.byt <DRIVER ; LSB of driver
;*******************************
;
; Initialize SD card
@ -437,260 +365,6 @@ INIT: LDA #$03 ; set SPI mode 3
RTS
;*******************************
;
; Status request
; $43 Unit number DSSS000
; $44-45 Unused
; $46-47 Unused
;
; C Clear - No error
; Set - Error
; A $00 - No error
; $2B - Card write protected
; $2F - No card inserted
; X - Blocks avail (low byte)
; Y - Blocks avail (high byte)
;
;*******************************
STATUS: LDA #0 ; no error
JSR WRPROT
BCC @DONE
LDA #$2B ; card write protected
@DONE: LDX #$FF ; 32 MB partition
LDY #$FF
RTS
;*******************************
;
; Read 512 byte block
; $43 Unit number DSSS0000
; $44-45 Address (LO/HI) of buffer
; $46-47 Block number (LO/HI)
;
; C Clear - No error
; Set - Error
; A $00 - No error
; $27 - Bad block number
;
;*******************************
READ: JSR GETBLOCK ; calc block address
LDA SS,X ; enable /CS
AND #<~SS0
STA SS,X
LDA #$51 ; send CMD17
JSR COMMAND ; send command
CMP #0
BNE @ERROR ; check for error
@GETTOK: LDA #DUMMY ; get data token
STA DATA,X
LDA DATA,X ; get response
CMP #$FE
BNE @GETTOK ; wait for $FE
LDA CTRL,X ; enable FRX
ORA #FRX
STA CTRL,X
LDA #DUMMY
STA DATA,X
LDY #0
@LOOP1: LDA DATA,X ; read data from card
STA (BUFFER),Y
INY
BNE @LOOP1
INC BUFFER+1 ; inc msb on page boundary
@LOOP2: LDA DATA,X
STA (BUFFER),Y
INY
BNE @LOOP2
DEC BUFFER+1
@CRC: LDA DATA,X ; read two bytes crc
LDA DATA,X ; and ignore
LDA DATA,X ; read a dummy byte
LDA CTRL,X ; disable FRX
AND #<~FRX
STA CTRL,X
CLC ; no error
LDA #0
@DONE: PHP
PHA
LDA SS,X
ORA #SS0
STA SS,X ; disable /CS
PLA
PLP
RTS
@ERROR: SEC ; an error occured
LDA #$27
BRA @DONE
;*******************************
;
; Write 512 byte block
; $43 Unit number DSSS0000
; $44-45 Address (LO/HI) of buffer
; $46-47 Block number (LO/HI)
;
; C Clear - No error
; Set - Error
; A $00 - No error
; $27 - I/O error or bad block number
; $2B - Card write protected
;
;*******************************
WRITE: JSR WRPROT
BCS @WPERROR ; card write protected
JSR GETBLOCK ; calc block address
LDA SS,X ; enable /CS
AND #<~SS0
STA SS,X
LDA #$58 ; send CMD24
JSR COMMAND ; send command
CMP #0
BNE @IOERROR ; check for error
LDA #DUMMY
STA DATA,X ; send dummy
LDA #$FE
STA DATA,X ; send data token
LDY #0
@LOOP1: LDA (BUFFER),Y
STA DATA,X
INY
BNE @LOOP1
INC BUFFER+1
@LOOP2: LDA (BUFFER),Y
STA DATA,X
INY
BNE @LOOP2
DEC BUFFER+1
@CRC: LDA #DUMMY
STA DATA,X ; send 2 dummy crc bytes
STA DATA,X
STA DATA,X ; get data response
LDA DATA,X
AND #$1F
CMP #$05
BNE @IOERROR ; check for write error
CLC ; no error
LDA #0
@DONE: PHP
PHA
@WAIT: LDA #DUMMY
STA DATA,X ; wait for write cycle
LDA DATA,X ; to complete
BEQ @WAIT
LDA SS,X ; disable /CS
ORA #SS0
STA SS,X
PLA
PLP
RTS
@IOERROR: SEC ; an error occured
LDA #$27
BRA @DONE
@WPERROR: SEC
LDA #$2B
BRA @DONE
;*******************************
;
; Test routine
;
;*******************************
.if DEBUG
TEST: LDA SLOT16
PHA
LDA SLOT
PHA
; get buffer
LDA #2 ; get 512 byte buffer
JSR $BEF5 ; call GETBUFR
BCS @ERROR
STA BUFFER+1
STZ BUFFER
PLA
STA SLOT
PLA
STA SLOT16
; fill buffer
LDY #0
@LOOP: TYA
STA (BUFFER),Y
INY
BNE @LOOP
INC BUFFER+1
@LOOP1: TYA
STA (BUFFER),Y
INY
BNE @LOOP1
DEC BUFFER+1
STZ BLOCK ; block number
STZ BLOCK+1
LDX SLOT16
; write to card
JSR WRITE
BCS @ERROR
; read from card
JSR READ
BCS @ERROR
; check for errors
LDY #0
@LOOP2: TYA
CMP (BUFFER),Y
BNE @ERRCMP ; error in buffer
INY
BNE @LOOP2
INC BUFFER+1
@LOOP3: TYA
CMP (BUFFER),Y
BNE @ERRCMP
INY
BNE @LOOP3
DEC BUFFER+1
; free buffer
JSR $BEF8 ; call FREEBUFR
CLC
LDA #0
RTS
@ERROR: BRK
@ERRCMP: BRK
.endif
TEXT: .asciiz " Apple][Sd v1.1 (c)2017 Florian Reitz"
CMD0: .byt $40, $00, $00

205
src/ProDOS.s Normal file
View File

@ -0,0 +1,205 @@
;*******************************
;
; Apple][Sd Firmware
; Version 1.1
; ProDOS functions
;
; (c) Florian Reitz, 2017
;
; X register usually contains SLOT16
; Y register is used for counting or SLOT
;
;*******************************
.export STATUS
.export READ
.export WRITE
.import COMMAND
.import SDCMD
.import GETBLOCK
.import WRPROT
.import GETR1
.import GETR3
.include "AppleIISd.inc"
.segment "EXTROM"
;*******************************
;
; Status request
; $43 Unit number DSSS000
; $44-45 Unused
; $46-47 Unused
;
; C Clear - No error
; Set - Error
; A $00 - No error
; $2B - Card write protected
; $2F - No card inserted
; X - Blocks avail (low byte)
; Y - Blocks avail (high byte)
;
;*******************************
STATUS: LDA #0 ; no error
JSR WRPROT
BCC @DONE
LDA #$2B ; card write protected
@DONE: LDX #$FF ; 32 MB partition
LDY #$FF
RTS
;*******************************
;
; Read 512 byte block
; $43 Unit number DSSS0000
; $44-45 Address (LO/HI) of buffer
; $46-47 Block number (LO/HI)
;
; C Clear - No error
; Set - Error
; A $00 - No error
; $27 - Bad block number
;
;*******************************
READ: JSR GETBLOCK ; calc block address
LDA SS,X ; enable /CS
AND #<~SS0
STA SS,X
LDA #$51 ; send CMD17
JSR COMMAND ; send command
CMP #0
BNE @ERROR ; check for error
@GETTOK: LDA #DUMMY ; get data token
STA DATA,X
LDA DATA,X ; get response
CMP #$FE
BNE @GETTOK ; wait for $FE
LDA CTRL,X ; enable FRX
ORA #FRX
STA CTRL,X
LDA #DUMMY
STA DATA,X
LDY #0
@LOOP1: LDA DATA,X ; read data from card
STA (BUFFER),Y
INY
BNE @LOOP1
INC BUFFER+1 ; inc msb on page boundary
@LOOP2: LDA DATA,X
STA (BUFFER),Y
INY
BNE @LOOP2
DEC BUFFER+1
@CRC: LDA DATA,X ; read two bytes crc
LDA DATA,X ; and ignore
LDA DATA,X ; read a dummy byte
LDA CTRL,X ; disable FRX
AND #<~FRX
STA CTRL,X
CLC ; no error
LDA #0
@DONE: PHP
PHA
LDA SS,X
ORA #SS0
STA SS,X ; disable /CS
PLA
PLP
RTS
@ERROR: SEC ; an error occured
LDA #$27
BRA @DONE
;*******************************
;
; Write 512 byte block
; $43 Unit number DSSS0000
; $44-45 Address (LO/HI) of buffer
; $46-47 Block number (LO/HI)
;
; C Clear - No error
; Set - Error
; A $00 - No error
; $27 - I/O error or bad block number
; $2B - Card write protected
;
;*******************************
WRITE: JSR WRPROT
BCS @WPERROR ; card write protected
JSR GETBLOCK ; calc block address
LDA SS,X ; enable /CS
AND #<~SS0
STA SS,X
LDA #$58 ; send CMD24
JSR COMMAND ; send command
CMP #0
BNE @IOERROR ; check for error
LDA #DUMMY
STA DATA,X ; send dummy
LDA #$FE
STA DATA,X ; send data token
LDY #0
@LOOP1: LDA (BUFFER),Y
STA DATA,X
INY
BNE @LOOP1
INC BUFFER+1
@LOOP2: LDA (BUFFER),Y
STA DATA,X
INY
BNE @LOOP2
DEC BUFFER+1
@CRC: LDA #DUMMY
STA DATA,X ; send 2 dummy crc bytes
STA DATA,X
STA DATA,X ; get data response
LDA DATA,X
AND #$1F
CMP #$05
BNE @IOERROR ; check for write error
CLC ; no error
LDA #0
@DONE: PHP
PHA
@WAIT: LDA #DUMMY
STA DATA,X ; wait for write cycle
LDA DATA,X ; to complete
BEQ @WAIT
LDA SS,X ; disable /CS
ORA #SS0
STA SS,X
PLA
PLP
RTS
@IOERROR: SEC ; an error occured
LDA #$27
BRA @DONE
@WPERROR: SEC
LDA #$2B
BRA @DONE