ROM code with support for $C800 and slot independence

This commit is contained in:
dschmenk 2015-02-04 15:49:05 -08:00
parent 396bbf871d
commit 0376c18141
5 changed files with 437 additions and 246 deletions

29
pidrive/Makefile Executable file
View File

@ -0,0 +1,29 @@
.SUFFIXES =
AFLAGS = -o $@
ROM = ROM\#062000
VDRV = PIDRIVE\#062000
VCLK = PICLOCK\#062000
#
# Image filetypes for CiderPress
#
PLATYPE = \#ed0000
BINTYPE = \#060000
SYSTYPE = \#ff0000
TXTTYPE = \#040000
all: $(ROM) $(VDRV) $(VCLK)
clean:
-rm $(ROM) $(VDRV) $(VCLK) *.o *~
$(ROM): rom.s
ca65 rom.s -o rom.o
ld65 -o $(ROM) -C rom.cfg rom.o
$(VDRV): pidrive.s
ca65 pidrive.s -o pidrive.o
ld65 -o $(VDRV) -C drvr.cfg pidrive.o
$(VCLK): piclock.s
ca65 piclock.s -o piclock.o
ld65 -o $(VCLK) -C drvr.cfg piclock.o

Binary file not shown.

View File

@ -1,5 +1,5 @@
MEMORY {
ROM: start = $c000, size = $8000, file = %O;
ROM: start = $c700, size = $0800, file = %O;
}
SEGMENTS {
CODE: load = ROM, type = ro;

View File

@ -1,38 +1,412 @@
;****************************************
;*
;* SIDRIVE (SERIAL INTERFACE DRIVE) ROM
;*
;****************************************
;DEBUG = 1
.DEFINE EQU =
.DEFINE DB .BYTE
.DEFINE DW .WORD
.DEFINE PAGE .ALIGN 256
.DEFINE ORG .ORG
.CODE
.SCOPE
ROMSLOT EQU 0
.INCLUDE "slotrom.s"
.ENDSCOPE
.SCOPE
ROMSLOT EQU 1
.INCLUDE "slotrom.s"
.ENDSCOPE
.SCOPE
ROMSLOT EQU 2
.INCLUDE "slotrom.s"
.ENDSCOPE
.SCOPE
ROMSLOT EQU 3
.INCLUDE "slotrom.s"
.ENDSCOPE
.SCOPE
ROMSLOT EQU 4
.INCLUDE "slotrom.s"
.ENDSCOPE
.SCOPE
ROMSLOT EQU 5
.INCLUDE "slotrom.s"
.ENDSCOPE
.SCOPE
ROMSLOT EQU 6
.INCLUDE "slotrom.s"
.ENDSCOPE
.SCOPE
ROMSLOT EQU 7
.INCLUDE "slotrom.s"
.ENDSCOPE
;*
;* ACIA REGISTERS
;*
ACIADR EQU $C088
ACIASR EQU $C089
ACIACR EQU $C08A
ACIAMR EQU $C08B
;*
;* APPLE I/O LOCATIONS
;*
INDCTR EQU $0400
KEYBD EQU $C000
STROBE EQU $C010
XROMOFF EQU $CFFF
ROMEN EQU $C082
;*
;* DRIVER SCRATCHSCRTCH
;*
SCRTCH0 EQU $0478
SCRTCH1 EQU $04F8 ; SYNCED FLAG
SCRTCH2 EQU $0578
SCRTCH3 EQU $05F8
SCRTCH4 EQU $0678
SCRTCH5 EQU $06F8
SCRTCH6 EQU $0778
SCRTCH7 EQU $07F8
CMDACK EQU SCRTCH0
SYNCED EQU SCRTCH1
SAVE16 EQU SCRTCH2
IOSLOT EQU $07F8 ; CURRENT SLOT FOR IRQ HANDLING
;*
;* UTIL ROUTINES
;*
COUT EQU $FDED
CROUT EQU $FD8E
PRBYTE EQU $FDDA
PRHEX EQU $FDE3
PRNTAX EQU $F941
RDKEY EQU $FD0C
RDCHAR EQU $FD35
GETLN EQU $FD6A
MONITOR EQU $FF69
;*
;* ZERO PAGE PARAMETERS
;*
SLOT16 EQU $3C
PDCMD EQU $42
PDUNIT EQU $43
PDBUFF EQU $44
PDBUFL EQU $44
PDBUFH EQU $45
PDBLKL EQU $46
PDBLKH EQU $47
;*
;* PRODOS COMMANDS
;*
PDSTAT EQU 0
PDREAD EQU 1
PDWRITE EQU 2
PDFORMT EQU 3
;*
;* PRODOS ERRORS
;*
PDNOERR EQU $00
PDIOERR EQU $27
PDNODEV EQU $28
PDWRPRT EQU $2B
;*
;* SIDRIVE SYNC and SYNC_ACK
;*
SYNC_REQ EQU $80
SYNC_ACK EQU $81
;****************************************
;*
;* OPTION ROM SPACE @ $C800
;*
;****************************************
ORG $C800
;*
;* RETURN SLOT*16 IN X REG, SLOT IN Y REG
;*
GETSLOT:
TSX
LDA $102,X ; GET MSB OF RETURN ADDRESS
STA IOSLOT
AND #$0F
TAY
LDA SLOT16
STA SAVE16,Y ; SAVE SLOT16 LOCATION
TYA
ASL
ASL
ASL
ASL
STA SLOT16
TAX
RTS
;*
;* OUTPUT BYTE TO ACIA
;*
SENDACC:
PHA
LDA SLOT16
ORA #$89+1 ; ACIASR
TAX
SENDWT: LDA $C000-1,X
AND #$10
BEQ SENDWT
DEX ; ACIADR
PLA
STA $C000-1,X ; AVOID PHANTOM READ OF DATA REG
RTS
;*
;* INPUT BYTE FROM ACIA
;*
RECVACC:
LDX SLOT16
RECVWT: LDA ACIASR,X
AND #$08
BEQ RECVWT
LDA ACIADR,X
RTS
;*
;* WAIT FOR DELAY
;*
WAIT: SEC
WAIT2: PHA
WAIT3: SBC #$01
BNE WAIT3
PLA
SBC #$01
BNE WAIT2
RTS
;*
;* SYNC WITH HOST
;*
SYNC: LDA INDCTR
PHA
LDX SLOT16
LDA #$0B
STA ACIASR,X ; RESET STATUS REGISTER
STA ACIACR,X ; SET CONTROL REGISTER
LDA #$10
STA ACIAMR,X ; SET COMMAND REGISTER (115K BAUD)
LDA #$80
JSR WAIT
STA STROBE ; CLEAR KEYBOARD STROBE
SYNCLP: LDA #SYNC_REQ
JSR SENDACC
INY
TYA
AND #$07
TAY
LDA SPIN,Y
STA INDCTR
LDA #$FF
JSR WAIT
LDA KEYBD
BPL CHKRSP
STA STROBE
PLA
.IFNDEF DEBUG
STA INDCTR
.ENDIF
NODEV: LDA #PDNODEV
RTS
SPIN: DB $A1, $AF, $AD, $DC, $A1, $AF, $AD, $DC
CHKRSP: LDX SLOT16
LDA ACIASR,X
AND #$08
BEQ SYNCLP
LDA ACIADR,X
CMP #SYNC_ACK
BNE SYNCLP
LDA IOSLOT
AND #$0F
TAY
LDA #SYNC_ACK
STA SYNCED,Y
PLA
.IFNDEF DEBUG
STA INDCTR
.ENDIF
;*
;* DO STATUS, READ, WRITE COMMAND
;*
DOCMD:
LDA SYNCED,Y ; CHECK FOR ANY REASON TO RESYNC
CMP #SYNC_ACK
BNE SYNC
LDA ACIACR,X
CMP #$0B
BNE SYNC
LDA ACIAMR,X
CMP #$10
BNE SYNC
LDA PDUNIT ; FORMAT COMMAND FOR SIDRIVE AND SEND IT
ASL
LDA PDCMD
ROL
ASL
ORA #$A0
JSR SENDACC
CLC
ADC #$01
STA CMDACK,Y
LDA PDBLKL
JSR SENDACC
LDA PDBLKH
JSR SENDACC
CHKACK: JSR RECVACC ; WAIT FOR CORRECT ACK (MAY BE OUTSTANDING A2PI REQUESTS)
CMP CMDACK,Y
BNE CHKACK
;*
;* BRANCH TO COMMAND HANDLER
;*
LDY PDCMD ; CPY #PDSTATUS
BEQ STATUS
DEY ; CPY #PDREAD
BEQ RDBLK
DEY ; CPY #PDWRITE
BEQ WRBLK
.IFDEF DEBUG
LDA #'?'
STA INDCTR+6
.ENDIF
IOERR: LDA #PDIOERR
RTS
;*
;* SIDRIVE STATUS - RETURN NUMBER OF BLOCKS OR NODEV
;*
STATUS:
.IFDEF DEBUG
LDA #'S'-$40
STA INDCTR+3
.ENDIF
JSR RECVACC
LDX #$FF
LDY #$FF
; PHA
; JSR RECVACC
; TAY
; PLA
; TAX
; BNE :+
; CPY #$00
; BEQ NODEV
;: LDA #$00
RTS
;*
;* READ A BLOCK (512 BYTES) FROM SIDRIVE
;*
RDBLK:
.IFDEF DEBUG
LDA #'R'-$40 ; LDY #$00
STA INDCTR+4
.ENDIF
RDBLKL: JSR RECVACC
STA (PDBUFF),Y
INY
BNE RDBLKL
INC PDBUFH
RDBLKH: JSR RECVACC
STA (PDBUFF),Y
INY
BNE RDBLKH
JMP RECVACC
;*
;* WRITE A BLOCK (512 BYTES) TO SIDRIVE
;*
WRBLK:
.IFDEF DEBUG
LDA #'W'-$40 ; LDY #$00
STA INDCTR+5
.ENDIF
WRBLKL: LDA (PDBUFF),Y
JSR SENDACC
INY
BNE WRBLKL
INC PDBUFH
WRBLKH: LDA (PDBUFF),Y
JSR SENDACC
INY
BNE WRBLKH
JMP RECVACC
;*
;* FILL REMAINING ROM WITH 0'S
;*
.REPEAT $CF00-*
DB $00
.ENDREP
.ASSERT * = $CF00, error, "Code not page size"
;****************************************
;*
;* SLOT INDEPENDENT ROM CODE @ $Cn00
;*
;****************************************
ORG $C700 ; EASY SLOT ADDRESS TO ASSEMBLE
;*
;* AUTOSTART BOOT SIGNATURE
;*
LDX #$20
LDY #$00
LDX #$03
STX $3C
;*
;* AUTOSTART/PR# ENTRYPOINT
;*
.IFDEF DEBUG
LDA #'*'
STA INDCTR+7
.ENDIF
PHP
SEI
STA XROMOFF
JSR GETSLOT
LDA #$00
STA SYNCED,Y ; CLEAR SYNCED FLAG
;*
;* CREATE COMMAND BUFFER FOR BOOT BLOCK
;*
STX PDUNIT ; SLOT * 16, DEV 0
LDX #$00
STX PDBLKL
STX PDBLKH
STX PDBUFL
INX ; LDX #PDREAD
STX PDCMD
LDX #$08
STX PDBUFH
JSR SYNC
BEQ BOOT
PLP
LDA $00
BEQ CONT
RTS
CONT: JMP $FABA ; JUMP BACK TO AUTOSTART BOOT SCANNER ROM
BOOT: PLP
JMP $801
;*
;* PRODOS INTELLIGENT DEVICE ENTRYPOINT
;*
CMDENTRY:
PHP
SEI
STA XROMOFF
JSR GETSLOT
.IFDEF DEBUG
LDA PDCMD
ORA #'0'
STA INDCTR+1
.ENDIF
JSR DOCMD
PLP
PHA ; RESTORE ORIGINAL SLOT16 VALUE
TYA
PHA
LDA IOSLOT
AND #$0F
TAY
LDA SAVE16,Y ; SAVED ORIGINAL SLOT16 VALUE
STA SLOT16
PLA
TAY
PLA
;*
;* CHECK FOR ERROR
;*
BNE CMDERR
CLC ; ALL GOOD, CLEAR ERROR FLAG
RTS
CMDERR:
.IFDEF DEBUG
PHA
STA $2FF
LDA #'E'-$40
STA INDCTR+2
: LDA KEYBD
BPL :-
STA STROBE
CMP #'M'+$80
BNE :+
LDA ROMEN
JMP MONITOR
: PLA
.ENDIF
SEC ; SET ERROR FLAG
RTS
ENDCMD:
.REPEAT $C700+250-*
DB $00
.ENDREP
DB "Si" ; SIGNATURE
DW 0 ; USE STATUS TO GET SIZE
DB $97 ; REMOVEABLE, 2 DEVICES, R/W
DB <CMDENTRY

View File

@ -1,212 +0,0 @@
PISLOT EQU ROMSLOT
BOOTDEV EQU ROMSLOT*16
ORG $C000+ROMSLOT*256
;*
;* ACIA REGISTERS
;*
ACIADR EQU $C088+PISLOT*16
ACIASR EQU $C089+PISLOT*16
ACIACR EQU $C08A+PISLOT*16
ACIAMR EQU $C08B+PISLOT*16
;*
;* APPLE I/O LOCATIONS
;*
INDCTR EQU $0400
KEYBD EQU $C000
STROBE EQU $C010
;*
;* DRIVER SCRATCHPAD
;*
PAD0 EQU $0478+ROMSLOT
PAD1 EQU $04F8+ROMSLOT
PAD2 EQU $0578+ROMSLOT
PAD3 EQU $05F8+ROMSLOT
PAD4 EQU $0678+ROMSLOT
PAD5 EQU $06F8+ROMSLOT
PAD6 EQU $0778+ROMSLOT
PAD7 EQU $07F8+ROMSLOT
;*
;* UTIL ROUTINES
;*
WAIT EQU $FCA8
COUT EQU $FDED
CROUT EQU $FD8E
PRBYTE EQU $FDDA
PRHEX EQU $FDE3
PRNTAX EQU $F941
RDKEY EQU $FD0C
RDCHAR EQU $FD35
GETLN EQU $FD6A
;*
;* ZERO PAGE PARAMETERS
;*
PDCMD EQU $42
PDUNIT EQU $43
PDBUFF EQU $44
PDBUFL EQU $44
PDBUFH EQU $45
PDBLKL EQU $46
PDBLKH EQU $47
;*
;* PRODOS COMMANDS
;*
PDSTAT EQU 0
PDREAD EQU 1
PDWRITE EQU 2
PDFORMT EQU 3
;*
;* PRODOS ERRORS
;*
PDNOERR EQU $00
PDIOERR EQU $27
PDNODEV EQU $28
PDWRPRT EQU $2B
;*
;* AUTOSTART BOOT SIGNATURE
;*
LDX #$20
LDY #$00
LDX #$03
STX $3C
;*
;* INIT ACIA
;*
STY PAD1 ; CLEAR SYNCED FLAG
STY ACIASR ; RESET STATUS REGISTER
LDA #$0B
STA ACIACR ; SET CONTROL REGISTER
LDA #$10
STA ACIAMR ; SET COMMAND REGISTER (115K BAUD)
;*
;* CREATE COMMAND BUFFER FOR BOOT BLOCK
;*
STY PDUNIT
STY PDBUFL
STY PDBLKL
STY PDBLKH
INY ; LDY #PDREAD
STY PDCMD
LDY #$08
STY PDBUFH
JSR DOCMD
BCC BOOT
LDA $00
BEQ CONT
RTS
CONT: JMP $FABA ; JUMP BACK TO AUTOSTART BOOT SCANNER ROM
BOOT: LDX #BOOTDEV
STX PDUNIT
JMP $801
;*
;* PRODOS INTELLIGENT DEVICE ENTRYPOINT
;*
DOCMD: PHP
SEI
LDA PAD1
CMP #$81
BEQ SNDCMD
;*
;* SYNC WITH HOST
;*
SYNC: LDA #$80
STA ACIADR
LDA INDCTR
PHA
INX
TXA
AND #$07
TAX
LDA SPIN,X
STA INDCTR
LDA #$FF
JSR WAIT
PLA
STA INDCTR
LDA KEYBD
BPL CHKRSP
STA STROBE
BMI IOERR
SPIN: DB $A1, $AF, $AD, $DC, $A1, $AF, $AD, $DC
CHKRSP: LDA ACIASR
AND #$08
BEQ SYNC
LDA ACIADR
CMP #$81
BNE SYNC
STA PAD1
SNDCMD: LDA PDUNIT
ASL
LDA PDCMD
ROL
ASL
ORA #$A0
STA PAD0
JSR SENDACC
LDA PDBLKL
JSR SENDACC
LDA PDBLKH
JSR SENDACC
CHKACK: JSR RECVACC
TAX
DEX
CPX PAD0
BNE CHKACK
LDY PDCMD
BEQ STATUS
LDX #$02 ; # OF PAGES TO XFER
DEY ; CPY #PDREAD
BEQ RDBLK
DEY ; CMP #PDWRITE
BEQ WRBLK
IOERR: LDA #PDIOERR
CMDERR: PLP
SEC
RTS
RDBLK: JSR RECVACC
STA (PDBUFF),Y
INY
BNE RDBLK
INC PDBUFH
DEX
BNE RDBLK
STATUS: LDX #$FF
DEY ; LDY #$FF
CMDEX: JSR RECVACC
BNE CMDERR
PLP
CLC
RTS
WRBLK: LDA (PDBUFF),Y
JSR SENDACC
INY
BNE WRBLK
INC PDBUFH
DEX
BNE WRBLK
BEQ CMDEX
;*
;* ACIA I/O ROUTINES
;*
SENDACC:
PHA
SENDWT: LDA ACIASR
AND #$10
BEQ SENDWT
PLA
STA ACIADR
RTS
RECVACC:
RECVWT: LDA ACIASR
AND #$08
BEQ RECVWT
LDA ACIADR
RTS
ENDCMD:
.REPEAT $C000+ROMSLOT*256+250-*
DB $FF
.ENDREP
DB "Pi"
DW 0
DB $97
DB <DOCMD
.ASSERT * = $C000+(ROMSLOT+1)*256, error, "Code not page size"