Compare commits

...

5 Commits
master ... 6502

Author SHA1 Message Date
Florian Reitz
27cad58424 Fix in INIT 2021-08-24 18:53:52 +02:00
Florian Reitz
06139a74f8 Merge branch 'master' into 6502 2021-04-19 18:12:00 +02:00
Florian Reitz
a790af1af4 Merge remote-tracking branch 'origin/devel' into 6502 2020-02-09 17:52:17 +01:00
Florian Reitz
dd571057de Translation bugs 2019-11-10 09:28:31 +01:00
Florian Reitz
181b85b616 Changes for 6502 cpu 2019-08-10 21:16:10 +02:00
7 changed files with 195 additions and 47 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

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

View File

@ -1,7 +1,7 @@
;*******************************
;
; Apple][Sd Firmware
; Version 1.2.2
; Version 1.2.3
; Main source
;
; (c) Florian Reitz, 2017 - 2021
@ -90,9 +90,14 @@
BPL @INIT ; and skip boot if pressed
@NEXTSLOT: LDA CURSLOT ; skip boot when no card
DEC A
SBC #1
STA CMDHI ; use CMDHI/LO as pointer
.IFPC02
STZ CMDLO
.ELSE
LDA #0
STA CMDLO
.ENDIF
JMP (CMDLO)
@INIT: JSR INIT
@ -107,16 +112,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 +153,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
@ -172,7 +195,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
@ -182,6 +206,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
@ -190,6 +229,7 @@ DRIVER: CLC ; ProDOS entry
CPY #PDZPSIZE
BCC @RESTZP
.IFPC02
LDA R33,X ; get retval
PHA
LDA R32,X
@ -200,11 +240,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
;*******************************
@ -220,15 +274,21 @@ DRIVER: CLC ; ProDOS entry
;*******************************
.segment "EXTROM"
INIT: STZ CTRL,X ; reset SPI controller
INIT:
.IFPC02
STZ CTRL,X ; reset SPI controller
.ELSE
LDA #0
STA CTRL,X
.ENDIF
LDA #SS0 ; set CS high
STA SS,X
LDY #10
LDA #DUMMY
@LOOP: STA DATA,X
@WAIT: BIT CTRL,X
BPL @WAIT
@LOOP: LDA #DUMMY
STA DATA,X
@WAIT: LDA CTRL,X
BPL @WAIT ; wait for TC (bit 7) to get high
DEY
BNE @LOOP ; do 10 times
LDA SS,X
@ -354,7 +414,7 @@ INIT: STZ CTRL,X ; reset SPI controller
KNOWNRTS: RTS
TEXT: .asciiz " Apple][Sd v1.2.2 (c)2021 Florian Reitz"
TEXT: .asciiz " Apple][Sd v1.2.3 (c)2021 Florian Reitz"
.assert(*-TEXT)=40, error, "TEXT must be 40 bytes long"

View File

@ -1,7 +1,7 @@
;*******************************
;
; Apple][Sd Firmware
; Version 1.2.2
; Version 1.2.3
; Helper functions
;
; (c) Florian Reitz, 2017 - 2021
@ -32,16 +32,27 @@
;
;*******************************
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: LDA CTRL,X ; TC is in N
BPL @WAIT
INY
CPY #6
BCC @LOOP
.IFPC02
PLY
.ELSE
PLA
TAY
.ENDIF
RTS
@ -54,8 +65,9 @@ SDCMD: PHY
GETR1: LDA #DUMMY
STA DATA,X
@WAIT: BIT CTRL,X
@WAIT: LDA CTRL,X ; TC is in N
BPL @WAIT
LDA DATA,X ; get response
BMI GETR1 ; wait for MSB=0
PHA
@ -74,13 +86,19 @@ 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: LDA CTRL,X ; TC is in N
BPL @WAIT
LDA DATA,X
PHA
DEY
@ -94,7 +112,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
@ -110,16 +133,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
@ -131,7 +167,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
@ -146,20 +186,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
@ -172,7 +221,6 @@ COMMAND: PHY ; save Y
LDA #DUMMY
STA DATA,X ; dummy crc
JSR GETR1
PLY ; restore Y
RTS
@ -188,7 +236,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
@ -208,7 +256,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
@ -228,7 +276,7 @@ WRPROT: PHA
INITED: PHA
LDA #CARD_INIT ; 0: card not initialized
BIT SS,X ; 1: card initialized
AND SS,X ; 1: card initialized
CLC
BNE @DONE
SEC

View File

@ -1,7 +1,7 @@
;*******************************
;
; Apple][Sd Firmware
; Version 1.2.2
; Version 1.2.3
; ProDOS functions
;
; (c) Florian Reitz, 2017 - 2021
@ -171,11 +171,11 @@ READ: JSR CARDDET ; check for card
@IOERROR: SEC ; an error occured
LDA #ERR_IOERR
BRA @DONE
BCS @DONE
@NDERROR: SEC ; an error occured
LDA #ERR_NODRIVE
BRA @DONE
BCS @DONE
;*******************************
@ -251,8 +251,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

@ -1,10 +1,10 @@
;*******************************
;
; Apple][Sd Firmware
; Version 1.2.2
; Version 1.2
; Smartport functions
;
; (c) Florian Reitz, 2017 - 2021
; (c) Florian Reitz, 2017 - 2018
;
; X register usually contains SLOT16
; Y register is used for counting or SLOT
@ -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
@ -95,19 +108,19 @@ SMARTPORT: LDY #SMZPSIZE-1 ; save zeropage area for Smarport
BCC @RESTZP
TXA
;warum feste anzahl an bytes für return wert?
LDY #2 ; highbyte of # bytes transferred
LDX #0 ; low byte of # bytes transferred
;warum wird mit #1 verglichen?
CMP #1 ; C=1 if A != NO_ERR
RTS
@COUNTMISMATCH:
LDA #ERR_BADPCNT
BRA @END
BNE @END
.IFPC02
@JMPSPCOMMAND: ; use offset from cmd*2
JMP (SPDISPATCH,X)
.ENDIF
@ -126,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
@ -148,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
@ -164,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
@ -280,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

@ -1,4 +1,5 @@
# AppleIISd
SD card based ProFile replacement for enhanced Apple IIe and IIgs computers
The **AppleIISd** is a SD card based replaced for the ProFile harddrive. In contrast to other SD card based devices, this card does not replace a Disk II drive. Data is saved directly onto the SD card, not via images on a FAT system, like on other cards. The SD card is accessable with [CiderPress](http://a2ciderpress.com/).
@ -8,6 +9,7 @@ A Xilinx CPLD is used as a SPI controller and translates, together with the ROM
The assembler sources are written for CC65. The [schematics](Binary/AppleIISd.pdf) are available as PDF.
## Features
* works with ProDOS and GS/OS
* up to 128MB storage space (4x 65535 blocks)
* ProDOS and Smartport driver in ROM
@ -18,7 +20,9 @@ The assembler sources are written for CC65. The [schematics](Binary/AppleIISd.pd
* Skip boot when Open-Apple key is pressed
## Requirements
The AppleIISd requires an enhanced IIe or IIgs computer. The ROM code uses some 65c02 opcodes and will therefore not work on a II, II+ or unenhanced IIe. It has been tested in the following combinations:
* Apple IIgs Rom 01, GS/OS 6.0.4
* Apple IIgs Rom 01, Prodos 2.4.1
* Apple IIgs Rom 01, Prodos 1.9
@ -27,6 +31,7 @@ The AppleIISd requires an enhanced IIe or IIgs computer. The ROM code uses some
* Apple IIe enhanced, 64k, Prodos 1.9
## Binary distribution
The following files in [Binary/](Binary) have been provided to eliminate the need to compile assembler or VHDL sources.
| File | Purpose |
@ -41,6 +46,7 @@ The following files in [Binary/](Binary) have been provided to eliminate the nee
| Gerber_Vx.x.zip | Gerber files for different hw revisions |
## Smartport drive remapping
The AppleIISd features Smartport drivers in ROM to provide more than two drives in both GS/OS and ProDOS.
As ProDOS supports only two drives per slot, additional drives on a Smartport device are mapped to 'phantom slots'. Version prior to version 2 supported only the remapping of drives when the card was in slot 5. Starting with version 2, the remapping seems to work on all slots. The following list shows the assignments as slot/drive, when no other devices are attached:
@ -56,15 +62,19 @@ As ProDOS supports only two drives per slot, additional drives on a Smartport de
When more devices are connected, things get a little confusing ;-)
## Building the sources
Be sure to have the newest version of CC65 (V2.16) and some kind of Make instaled, then type one of the following comands:
```
```bash
make # generate binaries
make OPTIONS=mapfile,listing # generate mapfile and listing, too
make clean # delete binaries
```
Alternatively use the VisualStudio solution.
## Timing
The clock of the SPI bus *SCK* may be derived from either *Phi0* or the *7M* clock. Additionally, the divisor may be 2 to 8.
The following measurements were taken with the divisor set to 2, resulting in *fSCK* of 500kHz and 3.5MHz. Reading of a byte requires that a dummy byte is sent on the bus, before the answer can be read. Therefore the measurement is the time between sending the byte and receiving the answer. The measurement for reading of a whole 512 byte block includes the SD card commands to do so.
@ -78,7 +88,7 @@ This shows that the required to read a single byte can be reduced significantly
The time for reading a 512 byte block could *only* be halved, but there are for sure opportunities for optimization in the code surrounding the reading.
```
```asm
* single byte @ 500kHz
LDA #$FF
STA $C0C0
@ -97,8 +107,8 @@ STA $C0C0
LDA $C0C0
```
## Registers
The control registers of the *AppleIISd* are mapped to the usual I/O space at **$C0n0 - $C0n3**, where n is slot+8. All registers and bits are read/write, except where noted.
| Address | Function | Default value |
@ -131,14 +141,15 @@ The control registers of the *AppleIISd* are mapped to the usual I/O space at **
**INIT** Initialized - This bit is set to 1 when the SD card has been initialized by the firmware. Do not write manually.
## TODOs
* Much more testing
* Enable more than 4 volumes under GS/OS
* Support for 6502 CPUs
* Support for 6502 CPUs
* Support for CP/M
## Known Bugs
* Programs not startable from partitions 3 and 4 under ProDOS
* Programs not startable from partitions 3 and 4 under ProDOS
![Front_Img_Smd](Images/Card%20Front%20SMD.jpg)
![Front_Img](Images/Card%20Front.jpg)