Changes for 6502 cpu

This commit is contained in:
Florian Reitz 2019-06-16 17:40:48 +02:00
parent f885de091e
commit 181b85b616
7 changed files with 184 additions and 33 deletions

View File

@ -9,7 +9,7 @@
# Space or comma separated list of cc65 supported target platforms to build for.
# Default: c64 (lowercase!)
TARGETS := apple2enh
TARGETS := apple2
# Name of the final, single-file executable.
# Default: name of the current dir with target name appended

View File

@ -55,6 +55,7 @@ SS := DATA+3
DUMMY = $FF
FRX = $10 ; CTRL register
ECE = $04
TC = $80
SS0 = $01 ; SS register
SDHC = $10
WP = $20

View File

@ -89,9 +89,16 @@
BPL @INIT ; and skip boot if pressed
@NEXTSLOT: LDA CURSLOT ; skip boot when no card
.IFPC02
DEC A
STA CMDHI ; use CMDHI/LO as pointer
STZ CMDLO
.ELSE
SBC #1
STA CMDHI
LDA #0
STA CMDLO
.ENDIF
JMP (CMDLO)
@INIT: JSR INIT
@ -107,16 +114,29 @@
; load disk blocks 0 and 1 to $800 and $A00
@BOOT: LDA #$08 ; load to $800
STA BUFFER+1 ; buffer hi
.IFPC02
STZ BUFFER ; buffer lo
STZ BLOCKNUM+1 ; block hi
STZ BLOCKNUM ; block lo
.ELSE
LDA #0
STA BUFFER
STA BLOCKNUM+1
STA BLOCKNUM
.ENDIF
JSR READ
BCS @NEXTSLOT ; load not successful
LDA #$0A
STA BUFFER+1 ; buffer hi
.IFPC02
STZ BUFFER ; buffer lo
STZ BLOCKNUM+1 ; block hi
.ELSE
LDA #0
STA BUFFER
STA BLOCKNUM+1
.ENDIF
LDA #$01
STA BLOCKNUM ; block lo
JSR READ
@ -135,7 +155,12 @@ DRIVER: CLC ; ProDOS entry
SEC ; Smartport entry
@PRODOS: PHP ; transfer P to X
.IFPC02
PLX
.ELSE
PLA
TAX
.ENDIF
LDY #PDZPSIZE-1 ; save zeropage area for ProDOS
@SAVEZP: LDA PDZPAREA,Y
PHA
@ -162,14 +187,16 @@ DRIVER: CLC ; ProDOS entry
STA SLOT16 ; $s0
TAX ; X holds now SLOT16
BIT $CFFF
JMP DRIVEREXT
JSR CARDDET
.segment "EXTROM"
DRIVEREXT: JSR CARDDET
BCC @INITED
LDA #ERR_OFFLINE; no card inserted
BRA @END
BCS @END
@INITED: LDA #INITED ; check for init
BIT SS,X
AND SS,X
BNE @DISP
JSR INIT
BCS @END ; Init failed
@ -180,7 +207,8 @@ DRIVER: CLC ; ProDOS entry
BCS @SMARTPORT ; Smartport dispatcher
JSR PRODOS ; ProDOS dispatcher
@END: PHX
@END: .IFPC02
PHX
LDX SLOT ; X holds $0s
STA R30,X ; save A
PLA
@ -190,6 +218,21 @@ DRIVER: CLC ; ProDOS entry
PHP
PLA
STA R33,X ; save P
.ELSE
PHP
PHA
TXA
PHA
LDX SLOT
PLA
STA R31,X ; save X
TYA
STA R32,X ; save Y
PLA
STA R30,X ; save A
PLA
STA R33,X ; save P
.ENDIF
LDY #0
@RESTZP: PLA ; restore zeropage area
@ -198,6 +241,7 @@ DRIVER: CLC ; ProDOS entry
CPY #PDZPSIZE
BCC @RESTZP
.IFPC02
LDA R33,X ; get retval
PHA
LDA R32,X
@ -208,11 +252,25 @@ DRIVER: CLC ; ProDOS entry
PLX ; restore X
PLY ; restore Y
PLP ; restore P
.ELSE
LDA R33,X
PHA
LDA R30,X
PHA
LDA R32,X
PHA
LDA R31,X
TAX ; restore X
PLA
TAY ; restore Y
PLA ; restore A
PLP ; restore P
.ENDIF
RTS
@SMARTPORT: CLC
JSR SMARTPORT
BRA @END
JMP @END
;*******************************
@ -227,7 +285,6 @@ DRIVER: CLC ; ProDOS entry
;
;*******************************
.segment "EXTROM"
INIT: LDA #$03 ; set SPI mode 3
STA CTRL,X
LDA SS,X
@ -239,7 +296,7 @@ INIT: LDA #$03 ; set SPI mode 3
LDA #DUMMY
@LOOP: STA DATA,X
@WAIT: BIT CTRL,X
@WAIT: AND CTRL,X
BPL @WAIT
DEY
BNE @LOOP ; do 10 times
@ -368,7 +425,7 @@ INIT: LDA #$03 ; set SPI mode 3
RTS
TEXT: .asciiz " Apple][Sd v1.2.1 (c)2018 Florian Reitz "
TEXT: .asciiz " Apple][Sd v1.2.2 (c)2019 Florian Reitz "
CMD0: .byt $40, $00, $00
.byt $00, $00, $95

View File

@ -30,16 +30,32 @@
;
;*******************************
SDCMD: PHY
SDCMD: .IFPC02
PHY
.ELSE
TYA
PHA
.ENDIF
LDY #0
@LOOP: LDA (CMDLO),Y
STA DATA,X
@WAIT: BIT CTRL,X ; TC is in N
@WAIT: .IFPC02
BIT CTRL,X ; TC is in N
BPL @WAIT
.ELSE
LDA #TC
AND CTRL,X
BNE @WAIT
.ENDIF
INY
CPY #6
BCC @LOOP
.IFPC02
PLY
.ELSE
PLA
TAY
.ENDIF
RTS
@ -52,8 +68,14 @@ SDCMD: PHY
GETR1: LDA #DUMMY
STA DATA,X
@WAIT: BIT CTRL,X
@WAIT: .IFPC02
BIT CTRL,X ; TC is in N
BPL @WAIT
.ELSE
LDA #TC
AND CTRL,X
BNE @WAIT
.ENDIF
LDA DATA,X ; get response
BMI GETR1 ; wait for MSB=0
PHA
@ -72,13 +94,24 @@ GETR1: LDA #DUMMY
GETR3: JSR GETR1 ; get R1 first
PHA ; save R1
.IFPC02
PHY ; save Y
.ELSE
TYA
PHA
.ENDIF
LDY #04 ; load counter
JMP @WAIT ; first byte is already there
@LOOP: LDA #DUMMY ; send dummy
STA DATA,X
@WAIT: BIT CTRL,X
@WAIT: .IFPC02
BIT CTRL,X ; TC is in N
BPL @WAIT
.ELSE
LDA #TC
AND CTRL,X
BNE @WAIT
.ENDIF
LDA DATA,X
PHA
DEY
@ -92,7 +125,12 @@ GETR3: JSR GETR1 ; get R1 first
STA R31,Y
PLA
STA R30,Y ; R30 is MSB
.IFPC02
PLY ; restore Y
.ELSE
PLA
TAY
.ENDIF
LDA #DUMMY
STA DATA,X ; send another dummy
PLA ; restore R1
@ -108,16 +146,29 @@ GETR3: JSR GETR1 ; get R1 first
;
;*******************************
GETBLOCK: PHX ; save X
GETBLOCK: .IFPC02
PHX ; save X
PHY ; save Y
.ELSE
TXA
PHA ; save X
TYA
PHA ; save y
.ENDIF
LDX SLOT ; SLOT is now in X
LDY SLOT16
LDA BLOCKNUM ; store block num
STA R33,X ; in R30-R33
LDA BLOCKNUM+1
STA R32,X
.IFPC02
STZ R31,X
STZ R30,X
.ELSE
LDA #0
STA R31,X
STA R30,X
.ENDIF
TYA ; get SLOT16
EOR DSNUMBER
@ -129,7 +180,11 @@ GETBLOCK: PHX ; save X
@DRIVE: BIT DSNUMBER ; drive number
BPL @SDHC ; D1
LDA R31,X ; D2
.IFPC02
INC A
.ELSE
ADC #1
.ENDIF
STA R31,X
@SDHC: LDA #SDHC
@ -144,20 +199,29 @@ GETBLOCK: PHX ; save X
DEY
BNE @LOOP
@END: PLY ; restore Y
@END: .IFPC02
PLY ; restore Y
PLX ; restore X
.ELSE
PLA
TAY ; restore y
PLA
TAX ; restore x
.ENDIF
RTS
;*******************************
;
; Send SD command
; X must contain SLOT16
; Cmd is in A
;
; Y is destroyed
;
;*******************************
COMMAND: PHY ; save Y
LDY SLOT
COMMAND: LDY SLOT
STA DATA,X ; send command
LDA R30,Y ; get arg from R30 on
STA DATA,X
@ -170,7 +234,6 @@ COMMAND: PHY ; save Y
LDA #DUMMY
STA DATA,X ; dummy crc
JSR GETR1
PLY ; restore Y
RTS
@ -186,7 +249,7 @@ COMMAND: PHY ; save Y
CARDDET: PHA
LDA #CD ; 0: card in
BIT SS,X ; 1: card out
AND SS,X ; 1: card out
CLC
BEQ @DONE ; card is in
SEC ; card is out
@ -206,7 +269,7 @@ CARDDET: PHA
WRPROT: PHA
LDA #WP ; 0: write enabled
BIT SS,X ; 1: write disabled
AND SS,X ; 1: write disabled
CLC
BEQ @DONE
SEC

View File

@ -152,7 +152,7 @@ READ: JSR GETBLOCK ; calc block address
@ERROR: SEC ; an error occured
LDA #ERR_IOERR
BRA @DONE
BCS @DONE
;*******************************
@ -228,8 +228,8 @@ WRITE: JSR WRPROT
@IOERROR: SEC ; an error occured
LDA #ERR_IOERR
BRA @DONE
BCS @DONE
@WPERROR: SEC
LDA #ERR_NOWRITE
BRA @DONE
BCS @DONE

View File

@ -70,7 +70,12 @@ SMARTPORT: LDY #SMZPSIZE-1 ; save zeropage area for Smarport
CPX #$09+1 ; command too large
BCS @END
.IFPC02
LDA (SMPARAMLIST) ; parameter count
.ELSE
LDY #0
LDA (SMPARAMLIST),Y
.ENDIF
CMP REQPARAMCOUNT,X
BNE @COUNTMISMATCH
@ -82,7 +87,15 @@ SMARTPORT: LDY #SMZPSIZE-1 ; save zeropage area for Smarport
TXA ; SMCMD
ASL A ; shift for use of word addresses
TAX
.IFPC02
JSR @JMPSPCOMMAND ; Y holds SLOT
.ELSE
LDA SPDISPATCH+1,X
PHA
LDA SPDISPATCH,X
PHA
RTS ; jump to cmd offset
.ENDIF
BCS @END ; jump on error
LDA #NO_ERR
@ -102,10 +115,12 @@ SMARTPORT: LDY #SMZPSIZE-1 ; save zeropage area for Smarport
@COUNTMISMATCH:
LDA #ERR_BADPCNT
BRA @END
BNE @END
.IFPC02
@JMPSPCOMMAND: ; use offset from cmd*2
JMP (SPDISPATCH,X)
.ENDIF
@ -124,7 +139,12 @@ SMSTATUS: JSR GETCSLIST
; TODO support partitions based on card size
@STATUS00: LDA #4 ; support 4 partitions
.IFPC02
STA (SMCMDLIST)
.ELSE
LDY #0
STA (SMCMDLIST),Y
.ENDIF
LDY #7
@LOOP00: LDA STATUS00DATA-1,Y
@ -146,7 +166,12 @@ SMSTATUS: JSR GETCSLIST
RTS
@GETDCB: LDA #1 ; return 'empty' DCB, one byte
.IFPC02
STA (SMCMDLIST)
.ELSE
LDY #0
STA (SMCMDLIST),Y
.ENDIF
TAY
LDA #NO_ERR
STA (SMCMDLIST),Y
@ -162,7 +187,12 @@ SMSTATUS: JSR GETCSLIST
@WRPROT: JSR WRPROT
BCC @STATUSBYTE
ORA #$04 ; SD card write-protected
@STATUSBYTE:STA (SMCMDLIST)
@STATUSBYTE:.IFPC02
STA (SMCMDLIST)
.ELSE
LDY #0
STA (SMCMDLIST),Y
.ENDIF
LDY #1 ; block count, always $00FFFF
LDA #$FF
@ -278,18 +308,18 @@ TRANSLATE: LDA DRVNUM,Y
BEQ @UNIT3
CMP #4
BEQ @UNIT4
BRA @BADUNIT ; only 4 partitions are supported
BNE @BADUNIT ; only 4 partitions are supported
@UNIT1: LDA SLOT16 ; this slot
BRA @STORE
BNE @STORE
@UNIT2: LDA SLOT16
ORA #$80 ; drive 1
BRA @STORE
BNE @STORE
@UNIT3: LDA SLOT16
DEC A ; phantom slot
BRA @STORE
SBC #1 ; phantom slot
BNE @STORE
@UNIT4: LDA SLOT16
DEC A ; phantom slot
SBC #1 ; phantom slot
ORA #$80 ; drive 1
@STORE: STA DSNUMBER ; store in ProDOS variable

View File

@ -84,7 +84,7 @@ int main()
cprintf("\r\nFlashing EXTROM: ");
if(writeChip(buffer + 256, pExtRom, fileSize - 256))
{
cprintf("\r\n\r\nFlashing finished!\n");
cprintf("\r\n\r\n\aFlashing finished!\n");
}
else
{