2021-07-28 04:17:47 +00:00
|
|
|
* MAINMEM.S
|
2021-07-29 18:43:56 +00:00
|
|
|
* (c) Bobbi 2021 GPL v3
|
2021-07-28 04:17:47 +00:00
|
|
|
* Code that runs on the Apple //e in main memory
|
|
|
|
* This code is mostly glue between the BBC Micro code
|
|
|
|
* running in aux mem and ProDOS
|
|
|
|
|
|
|
|
* Set prefix if not already set
|
|
|
|
SETPRFX LDA #GPFXCMD
|
2021-07-30 20:49:34 +00:00
|
|
|
STA :OPC7 ; Initialize cmd byte to $C7
|
2021-07-28 04:17:47 +00:00
|
|
|
:L1 JSR MLI
|
|
|
|
:OPC7 DB $00
|
|
|
|
DW GSPFXPL
|
|
|
|
LDX $0300
|
2021-07-29 18:43:56 +00:00
|
|
|
BNE RTSINST
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $BF30
|
2021-07-30 20:49:34 +00:00
|
|
|
STA ONLPL+1 ; Device number
|
2021-07-28 04:17:47 +00:00
|
|
|
JSR MLI
|
|
|
|
DB ONLNCMD
|
|
|
|
DW ONLPL
|
|
|
|
LDA $0301
|
|
|
|
AND #$0F
|
|
|
|
TAX
|
|
|
|
INX
|
|
|
|
STX $0300
|
|
|
|
LDA #$2F
|
|
|
|
STA $0301
|
|
|
|
DEC :OPC7
|
|
|
|
BNE :L1
|
2021-07-29 18:43:56 +00:00
|
|
|
RTSINST RTS
|
2021-07-28 04:17:47 +00:00
|
|
|
|
2021-07-29 00:47:26 +00:00
|
|
|
* Disconnect /RAM ramdrive to avoid aux corruption
|
2021-07-28 04:17:47 +00:00
|
|
|
* Stolen from Beagle Bros Extra K
|
|
|
|
DISCONN LDA $BF98
|
|
|
|
AND #$30
|
|
|
|
CMP #$30
|
|
|
|
BNE :S1
|
|
|
|
LDA $BF26
|
|
|
|
CMP $BF10
|
|
|
|
BNE :S2
|
|
|
|
LDA $BF27
|
|
|
|
CMP $BF11
|
|
|
|
BEQ :S1
|
|
|
|
:S2 LDY $BF31
|
|
|
|
:L1 LDA $BF32,Y
|
|
|
|
AND #$F3
|
|
|
|
CMP #$B3
|
|
|
|
BEQ :S3
|
|
|
|
DEY
|
|
|
|
BPL :L1
|
|
|
|
BMI :S1
|
|
|
|
:S3 LDA $BF32,Y
|
|
|
|
STA $0302
|
|
|
|
:L2 LDA $BF33,Y
|
|
|
|
STA $BF32,Y
|
|
|
|
BEQ :S4
|
|
|
|
INY
|
|
|
|
BNE :L2
|
|
|
|
:S4 LDA $BF26
|
|
|
|
STA $0300
|
|
|
|
LDA $BF27
|
|
|
|
STA $0301
|
|
|
|
LDA $BF10
|
|
|
|
STA $BF26
|
|
|
|
LDA $BF11
|
|
|
|
STA $BF27
|
|
|
|
DEC $BF31
|
|
|
|
:S1 RTS
|
|
|
|
|
2021-07-29 00:47:26 +00:00
|
|
|
* Reset handler - invoked on Ctrl-Reset
|
2021-07-28 04:17:47 +00:00
|
|
|
* XFER to AUXMOS ($C000) in aux, AuxZP on, LC on
|
|
|
|
RESET TSX
|
|
|
|
STX $0100
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C08B ; Rd/Wt LC, bank one
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,AUXMOS
|
|
|
|
>>> XFAUX
|
2021-07-28 04:17:47 +00:00
|
|
|
RTS
|
|
|
|
|
2021-07-29 00:47:26 +00:00
|
|
|
* Copy 512 bytes from BLKBUF to AUXBLK in aux LC
|
2021-07-28 04:17:47 +00:00
|
|
|
COPYAUXBLK
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C08B ; R/W LC RAM, bank 1
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
STA $C009 ; Alt ZP (and Alt LC) on
|
2021-07-28 04:17:47 +00:00
|
|
|
|
|
|
|
LDY #$00
|
2021-07-29 00:47:26 +00:00
|
|
|
:L1 LDA BLKBUF,Y
|
2021-07-30 20:49:34 +00:00
|
|
|
STA $C005 ; Write aux mem
|
2021-07-28 04:17:47 +00:00
|
|
|
STA AUXBLK,Y
|
2021-07-30 20:49:34 +00:00
|
|
|
STA $C004 ; Write main mem
|
2021-07-28 04:17:47 +00:00
|
|
|
CPY #$FF
|
|
|
|
BEQ :S1
|
|
|
|
INY
|
|
|
|
BRA :L1
|
|
|
|
|
|
|
|
:S1 LDY #$00
|
2021-07-29 00:47:26 +00:00
|
|
|
:L2 LDA BLKBUF+$100,Y
|
2021-07-30 20:49:34 +00:00
|
|
|
STA $C005 ; Write aux mem
|
2021-07-28 04:17:47 +00:00
|
|
|
STA AUXBLK+$100,Y
|
2021-07-30 20:49:34 +00:00
|
|
|
STA $C004 ; Write main mem
|
2021-07-28 04:17:47 +00:00
|
|
|
CPY #$FF
|
|
|
|
BEQ :S2
|
|
|
|
INY
|
|
|
|
BRA :L2
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
:S2 STA $C008 ; Alt ZP off
|
|
|
|
LDA $C081 ; Bank the ROM back in
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C081
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* ProDOS file handling for MOS OSFIND OPEN call
|
|
|
|
* Options in A: $40 'r', $80 'w', $C0 'rw'
|
2021-07-30 20:49:34 +00:00
|
|
|
OFILE LDX $0100 ; Recover SP
|
2021-07-28 04:17:47 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
PHA ; Option
|
|
|
|
LDA $C081 ; ROM, please
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C081
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
PLA ; Get option back
|
2021-07-29 00:47:26 +00:00
|
|
|
PHA
|
2021-07-30 20:49:34 +00:00
|
|
|
CMP #$80 ; Write mode
|
2021-07-30 01:17:12 +00:00
|
|
|
BNE :S0
|
2021-07-29 00:47:26 +00:00
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #<MOSFILE ; Attempt to destroy file
|
2021-07-29 00:47:26 +00:00
|
|
|
STA DESTPL+1
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA DESTPL+2
|
|
|
|
JSR MLI
|
|
|
|
DB DESTCMD
|
|
|
|
DW DESTPL
|
2021-07-28 04:17:47 +00:00
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #<MOSFILE ; Attempt to create file
|
2021-07-29 00:47:26 +00:00
|
|
|
STA CREATEPL+1
|
|
|
|
STA OPENPL+1
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA CREATEPL+2
|
|
|
|
STA OPENPL+2
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$C3 ; Access unlocked
|
2021-07-29 00:47:26 +00:00
|
|
|
STA CREATEPL+3
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$06 ; Filetype BIN
|
2021-07-29 00:47:26 +00:00
|
|
|
STA CREATEPL+4
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$00 ; Auxtype
|
2021-07-29 00:47:26 +00:00
|
|
|
STA CREATEPL+5
|
|
|
|
LDA #$00
|
|
|
|
STA CREATEPL+6
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$01 ; Storage type - file
|
2021-07-29 00:47:26 +00:00
|
|
|
STA CREATEPL+7
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $BF90 ; Current date
|
2021-07-29 00:47:26 +00:00
|
|
|
STA CREATEPL+8
|
|
|
|
LDA $BF91
|
|
|
|
STA CREATEPL+9
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $BF92 ; Current time
|
2021-07-29 00:47:26 +00:00
|
|
|
STA CREATEPL+10
|
|
|
|
LDA $BF93
|
|
|
|
STA CREATEPL+11
|
|
|
|
JSR CRTFILE
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
:S0 LDA #$00 ; Look for empty slot
|
2021-07-28 04:17:47 +00:00
|
|
|
JSR FINDBUF
|
|
|
|
STX BUFIDX
|
|
|
|
CPX #$00
|
|
|
|
BNE :S1
|
|
|
|
LDA #<IOBUF1
|
|
|
|
LDY #>IOBUF1
|
|
|
|
BRA :S4
|
|
|
|
:S1 CPX #$01
|
|
|
|
BNE :S2
|
|
|
|
LDA #<IOBUF2
|
|
|
|
LDY #>IOBUF2
|
|
|
|
BRA :S4
|
|
|
|
:S2 CPX #$02
|
|
|
|
BNE :S3
|
|
|
|
LDA #<IOBUF3
|
|
|
|
LDY #>IOBUF3
|
|
|
|
BRA :S4
|
|
|
|
:S3 CPX #$03
|
2021-07-30 20:49:34 +00:00
|
|
|
BNE :NOTFND ; Out of buffers really
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA #<IOBUF4
|
|
|
|
LDY #>IOBUF4
|
|
|
|
|
|
|
|
:S4 STA OPENPL2+3
|
|
|
|
STY OPENPL2+4
|
|
|
|
|
|
|
|
LDA #<MOSFILE
|
|
|
|
STA OPENPL2+1
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA OPENPL2+2
|
|
|
|
JSR MLI
|
|
|
|
DB OPENCMD
|
|
|
|
DW OPENPL2
|
|
|
|
BCS :NOTFND
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA OPENPL2+5 ; File ref number
|
2021-07-28 04:17:47 +00:00
|
|
|
PHA
|
|
|
|
LDX BUFIDX
|
|
|
|
CPX #$FF
|
|
|
|
BEQ FINDEXIT
|
2021-07-30 20:49:34 +00:00
|
|
|
STA FILEREFS,X ; Record ref number
|
2021-07-28 04:17:47 +00:00
|
|
|
BRA FINDEXIT
|
|
|
|
:NOTFND LDA #$00
|
|
|
|
PHA
|
2021-07-30 20:49:34 +00:00
|
|
|
FINDEXIT LDA $C08B ; R/W RAM, LC bank 1
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,OSFINDRET
|
2021-07-28 04:17:47 +00:00
|
|
|
PLA
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFAUX
|
2021-07-28 04:17:47 +00:00
|
|
|
BUFIDX DB $00
|
|
|
|
|
|
|
|
* ProDOS file handling for MOS OSFIND CLOSE call
|
2021-07-30 20:49:34 +00:00
|
|
|
CFILE LDX $0100 ; Recover SP
|
2021-07-28 04:17:47 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C081 ; ROM, please
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C081
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA MOSFILE ; File ref number
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CLSPL+1
|
|
|
|
JSR CLSFILE
|
|
|
|
|
|
|
|
LDA MOSFILE
|
|
|
|
JSR FINDBUF
|
|
|
|
CPX #$FF
|
|
|
|
BEQ :S1
|
|
|
|
|
|
|
|
LDA #$00
|
|
|
|
STA FILEREFS,X
|
|
|
|
|
|
|
|
:S1 JMP FINDEXIT
|
|
|
|
|
|
|
|
* Map of file reference numbers to IOBUF1..4
|
|
|
|
FILEREFS DB $00,$00,$00,$00
|
|
|
|
|
|
|
|
* Search FILEREFS for value in A
|
|
|
|
FINDBUF LDX #$00
|
|
|
|
:L1 CMP FILEREFS,X
|
|
|
|
BEQ :END
|
|
|
|
INX
|
|
|
|
CPX #$04
|
|
|
|
BNE :L1
|
2021-07-30 20:49:34 +00:00
|
|
|
LDX #$FF ; $FF for not found
|
2021-07-28 04:17:47 +00:00
|
|
|
:END RTS
|
|
|
|
|
|
|
|
* ProDOS file handling for MOS OSBGET call
|
|
|
|
* Returns with char read in A and error num in X (or 0)
|
2021-07-30 20:49:34 +00:00
|
|
|
FILEGET LDX $0100 ; Recover SP
|
2021-07-28 04:17:47 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C081 ; ROM, please
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C081
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA MOSFILE ; File ref number
|
2021-07-28 04:17:47 +00:00
|
|
|
STA READPL2+1
|
|
|
|
JSR MLI
|
|
|
|
DB READCMD
|
|
|
|
DW READPL2
|
|
|
|
BCC :NOERR
|
2021-07-30 20:49:34 +00:00
|
|
|
TAY ; Error number in Y
|
2021-07-28 04:17:47 +00:00
|
|
|
BRA GETEXIT
|
|
|
|
:NOERR LDX #$00
|
2021-07-29 00:47:26 +00:00
|
|
|
LDA BLKBUF
|
2021-07-28 04:17:47 +00:00
|
|
|
PHA
|
2021-07-30 20:49:34 +00:00
|
|
|
GETEXIT LDA $C08B ; R/W RAM, LC bank 1
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,OSBGETRET
|
2021-07-28 04:17:47 +00:00
|
|
|
PLA
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFAUX
|
2021-07-28 04:17:47 +00:00
|
|
|
|
|
|
|
* ProDOS file handling for MOS OSBPUT call
|
2021-07-29 00:47:26 +00:00
|
|
|
* Enters with char to write in A
|
2021-07-30 20:49:34 +00:00
|
|
|
FILEPUT LDX $0100 ; Recover SP
|
2021-07-28 04:17:47 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
STA BLKBUF ; Char to write
|
|
|
|
LDA $C081 ; ROM, please
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C081
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA MOSFILE ; File ref number
|
2021-07-29 00:47:26 +00:00
|
|
|
STA WRITEPL+1
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$01 ; Bytes to write
|
2021-07-29 00:47:26 +00:00
|
|
|
STA WRITEPL+4
|
|
|
|
LDA #$00
|
|
|
|
STA WRITEPL+5
|
|
|
|
JSR WRTFILE
|
|
|
|
|
|
|
|
* There is no way to report an error it seems!
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C08B ; R/W RAM, LC bank 1
|
2021-07-29 00:47:26 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,OSBPUTRET
|
|
|
|
>>> XFAUX
|
2021-07-29 18:43:56 +00:00
|
|
|
|
|
|
|
* ProDOS file handling for OSBYTE $7F EOF
|
|
|
|
* Returns EOF status in A ($FF for EOF, $00 otherwise)
|
2021-07-30 20:49:34 +00:00
|
|
|
FILEEOF LDX $0100 ; Recover SP
|
2021-07-29 18:43:56 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C081 ; ROM, please
|
2021-07-29 18:43:56 +00:00
|
|
|
LDA $C081
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA MOSFILE ; File ref number
|
2021-07-29 18:43:56 +00:00
|
|
|
STA GEOFPL+1
|
|
|
|
STA GMARKPL+1
|
|
|
|
JSR MLI
|
|
|
|
DB GEOFCMD
|
|
|
|
DW GEOFPL
|
2021-07-30 20:49:34 +00:00
|
|
|
BCS :ISEOF ; If error, just say EOF
|
2021-07-29 18:43:56 +00:00
|
|
|
|
|
|
|
JSR MLI
|
|
|
|
DB GMARKCMD
|
|
|
|
DW GMARKPL
|
2021-07-30 20:49:34 +00:00
|
|
|
BCS :ISEOF ; If error, just say EOF
|
2021-07-29 18:43:56 +00:00
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA GEOFPL+2 ; Subtract Mark from EOF
|
2021-07-29 18:43:56 +00:00
|
|
|
SEC
|
|
|
|
SBC GMARKPL+2
|
|
|
|
STA :REMAIN
|
|
|
|
LDA GEOFPL+3
|
|
|
|
SBC GMARKPL+3
|
|
|
|
STA :REMAIN+1
|
|
|
|
LDA GEOFPL+4
|
|
|
|
SBC GMARKPL+4
|
|
|
|
STA :REMAIN+2
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA :REMAIN ; Check bytes remaining
|
2021-07-29 18:43:56 +00:00
|
|
|
BNE :NOTEOF
|
|
|
|
LDA :REMAIN+1
|
|
|
|
BNE :NOTEOF
|
|
|
|
LDA :REMAIN+2
|
|
|
|
BNE :NOTEOF
|
|
|
|
:ISEOF LDA #$FF
|
|
|
|
BRA :EXIT
|
|
|
|
:NOTEOF LDA #$00
|
2021-07-30 20:49:34 +00:00
|
|
|
:EXIT PHA ; Preserve return code
|
|
|
|
LDA $C08B ; R/W RAM, LC bank 1
|
2021-07-29 18:43:56 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,CHKEOFRET
|
|
|
|
PLA ; Recover return code
|
|
|
|
>>> XFAUX
|
|
|
|
:REMAIN DS 3 ; Remaining bytes
|
2021-07-28 04:17:47 +00:00
|
|
|
|
2021-07-30 19:47:36 +00:00
|
|
|
* ProDOS file handling for OSARGS flush commands
|
2021-07-30 20:49:34 +00:00
|
|
|
FLUSH LDX $0100 ; Recover SP
|
2021-07-30 19:47:36 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C081 ; ROM, please
|
2021-07-30 19:47:36 +00:00
|
|
|
LDA $C081
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA MOSFILE ; File ref number
|
2021-07-30 19:47:36 +00:00
|
|
|
STA FLSHPL+1
|
|
|
|
JSR MLI
|
|
|
|
DB FLSHCMD
|
|
|
|
DW FLSHPL
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C08B ; R/W RAM, LC bank 1
|
2021-07-30 19:47:36 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,OSARGSRET
|
|
|
|
>>> XFAUX
|
2021-07-30 19:47:36 +00:00
|
|
|
|
2021-07-28 04:17:47 +00:00
|
|
|
* ProDOS file handling for MOS OSFILE LOAD call
|
|
|
|
* Return A=0 if successful
|
|
|
|
* A=1 if file not found
|
|
|
|
* A=2 if read error
|
2021-07-30 20:49:34 +00:00
|
|
|
LOADFILE LDX $0100 ; Recover SP
|
2021-07-28 04:17:47 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C081 ; Gimme the ROM!
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C081
|
|
|
|
|
|
|
|
STZ :BLOCKS
|
|
|
|
LDA #<MOSFILE
|
|
|
|
STA OPENPL+1
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA OPENPL+2
|
|
|
|
JSR OPENFILE
|
2021-07-30 20:49:34 +00:00
|
|
|
BCS :NOTFND ; File not found
|
|
|
|
:L1 LDA OPENPL+5 ; File ref number
|
2021-07-28 04:17:47 +00:00
|
|
|
STA READPL+1
|
2021-07-29 00:47:26 +00:00
|
|
|
JSR RDFILE
|
2021-07-28 04:17:47 +00:00
|
|
|
BCC :S1
|
2021-07-30 20:49:34 +00:00
|
|
|
CMP #$4C ; EOF
|
2021-07-28 04:17:47 +00:00
|
|
|
BEQ :EOF
|
|
|
|
BRA :READERR
|
|
|
|
|
2021-07-29 00:47:26 +00:00
|
|
|
:S1 LDA #<BLKBUF
|
2021-07-28 04:17:47 +00:00
|
|
|
STA A1L
|
2021-07-29 00:47:26 +00:00
|
|
|
LDA #>BLKBUF
|
2021-07-28 04:17:47 +00:00
|
|
|
STA A1H
|
|
|
|
|
2021-07-29 00:47:26 +00:00
|
|
|
LDA #<BLKBUFEND
|
2021-07-28 04:17:47 +00:00
|
|
|
STA A2L
|
2021-07-29 00:47:26 +00:00
|
|
|
LDA #>BLKBUFEND
|
2021-07-28 04:17:47 +00:00
|
|
|
STA A2H
|
|
|
|
|
|
|
|
LDA FBLOAD
|
|
|
|
STA A4L
|
|
|
|
LDA FBLOAD+1
|
|
|
|
LDX :BLOCKS
|
|
|
|
:L2 CPX #$00
|
|
|
|
BEQ :S2
|
|
|
|
INC
|
|
|
|
INC
|
|
|
|
DEX
|
|
|
|
BRA :L2
|
|
|
|
:S2 STA A4H
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
SEC ; Main -> AUX
|
2021-07-28 04:17:47 +00:00
|
|
|
JSR AUXMOVE
|
|
|
|
|
|
|
|
INC :BLOCKS
|
|
|
|
BRA :L1
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
:NOTFND LDA #$01 ; Nothing found
|
2021-07-28 04:17:47 +00:00
|
|
|
PHA
|
|
|
|
BRA :EXIT
|
2021-07-30 20:49:34 +00:00
|
|
|
:READERR LDA #$02 ; Read error
|
2021-07-28 04:17:47 +00:00
|
|
|
PHA
|
|
|
|
BRA :EOF2
|
2021-07-30 20:49:34 +00:00
|
|
|
:EOF LDA #$00 ; Success
|
2021-07-28 04:17:47 +00:00
|
|
|
PHA
|
2021-07-30 20:49:34 +00:00
|
|
|
:EOF2 LDA OPENPL+5 ; File ref num
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CLSPL+1
|
|
|
|
JSR CLSFILE
|
2021-07-30 20:49:34 +00:00
|
|
|
:EXIT LDA $C08B ; R/W RAM, bank 1
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,OSFILERET
|
2021-07-28 04:17:47 +00:00
|
|
|
PLA
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFAUX
|
2021-07-28 04:17:47 +00:00
|
|
|
:BLOCKS DB $00
|
|
|
|
|
|
|
|
* ProDOS file handling for MOS OSFILE SAVE call
|
|
|
|
* Return A=0 if successful
|
|
|
|
* A=1 if unable to create/open
|
|
|
|
* A=2 if error during save
|
2021-07-30 20:49:34 +00:00
|
|
|
SAVEFILE LDX $0100 ; Recover SP
|
2021-07-28 04:17:47 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C081 ; Gimme the ROM!
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C081
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #<MOSFILE ; Attempt to destroy file
|
2021-07-29 18:43:56 +00:00
|
|
|
STA DESTPL+1
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA DESTPL+2
|
|
|
|
JSR MLI
|
|
|
|
DB DESTCMD
|
|
|
|
DW DESTPL
|
|
|
|
|
2021-07-28 04:17:47 +00:00
|
|
|
STZ :BLOCKS
|
|
|
|
LDA #<MOSFILE
|
|
|
|
STA CREATEPL+1
|
|
|
|
STA OPENPL+1
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA CREATEPL+2
|
|
|
|
STA OPENPL+2
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$C3 ; Access unlocked
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CREATEPL+3
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$06 ; Filetype BIN
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CREATEPL+4
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA FBSTRT ; Auxtype = save address
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CREATEPL+5
|
|
|
|
LDA FBSTRT+1
|
|
|
|
STA CREATEPL+6
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$01 ; Storage type - file
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CREATEPL+7
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $BF90 ; Current date
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CREATEPL+8
|
|
|
|
LDA $BF91
|
|
|
|
STA CREATEPL+9
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $BF92 ; Current time
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CREATEPL+10
|
|
|
|
LDA $BF93
|
|
|
|
STA CREATEPL+11
|
|
|
|
JSR CRTFILE
|
2021-07-30 20:49:34 +00:00
|
|
|
BCS :FWD1 ; :CANTOPEN error
|
2021-07-28 04:17:47 +00:00
|
|
|
JSR OPENFILE
|
2021-07-30 20:49:34 +00:00
|
|
|
BCS :FWD1 ; :CANTOPEN error
|
2021-07-28 04:17:47 +00:00
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
SEC ; Compute file length
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA FBEND
|
|
|
|
SBC FBSTRT
|
|
|
|
STA :LEN
|
|
|
|
LDA FBEND+1
|
|
|
|
SBC FBSTRT+1
|
|
|
|
STA :LEN+1
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
:L1 LDA FBSTRT ; Setup for first block
|
2021-07-28 04:17:47 +00:00
|
|
|
STA A1L
|
|
|
|
STA A2L
|
|
|
|
LDA FBSTRT+1
|
|
|
|
STA A1H
|
|
|
|
STA A2H
|
2021-07-30 20:49:34 +00:00
|
|
|
INC A2H ; $200 = 512 bytes
|
2021-07-28 04:17:47 +00:00
|
|
|
INC A2H
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA OPENPL+5 ; File ref number
|
2021-07-29 00:47:26 +00:00
|
|
|
STA WRITEPL+1
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$00 ; 512 byte request count
|
2021-07-28 04:17:47 +00:00
|
|
|
STA WRITEPL+4
|
|
|
|
LDA #$02
|
|
|
|
STA WRITEPL+5
|
|
|
|
LDX :BLOCKS
|
2021-07-30 20:49:34 +00:00
|
|
|
:L2 CPX #$00 ; Adjust for subsequent blks
|
2021-07-28 04:17:47 +00:00
|
|
|
BEQ :S1
|
|
|
|
INC A1H
|
|
|
|
INC A1H
|
|
|
|
INC A2H
|
|
|
|
INC A2H
|
|
|
|
DEX
|
|
|
|
BRA :L2
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
:FWD1 BRA :CANTOPEN ; Forwarding call from above
|
2021-07-28 04:17:47 +00:00
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
:S1 LDA :LEN+1 ; MSB of length remaining
|
2021-07-28 04:17:47 +00:00
|
|
|
CMP #$02
|
2021-07-30 20:49:34 +00:00
|
|
|
BCS :S2 ; MSB of len >= 2 (not last)
|
2021-07-28 04:17:47 +00:00
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
CMP #$00 ; If no bytes left ...
|
2021-07-28 04:17:47 +00:00
|
|
|
BNE :S3
|
|
|
|
LDA :LEN
|
|
|
|
BNE :S3
|
|
|
|
BRA :NORMALEND
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
:S3 LDA FBEND ; Adjust for last block
|
2021-07-28 04:17:47 +00:00
|
|
|
STA A2L
|
|
|
|
LDA FBEND+1
|
|
|
|
STA A2H
|
|
|
|
LDA :LEN
|
2021-07-30 20:49:34 +00:00
|
|
|
STA WRITEPL+4 ; Remaining bytes to write
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA :LEN+1
|
|
|
|
STA WRITEPL+5
|
|
|
|
|
2021-07-29 00:47:26 +00:00
|
|
|
:S2 LDA #<BLKBUF
|
2021-07-28 04:17:47 +00:00
|
|
|
STA A4L
|
2021-07-29 00:47:26 +00:00
|
|
|
LDA #>BLKBUF
|
2021-07-28 04:17:47 +00:00
|
|
|
STA A4H
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
CLC ; Aux -> Main
|
2021-07-28 04:17:47 +00:00
|
|
|
JSR AUXMOVE
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA OPENPL+5 ; File ref number
|
2021-07-28 04:17:47 +00:00
|
|
|
STA WRITEPL+1
|
2021-07-29 00:47:26 +00:00
|
|
|
JSR WRTFILE
|
2021-07-28 04:17:47 +00:00
|
|
|
BCS :WRITEERR
|
|
|
|
|
|
|
|
BRA :UPDLEN
|
|
|
|
|
|
|
|
:ENDLOOP INC :BLOCKS
|
|
|
|
BRA :L1
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
:UPDLEN SEC ; Update length remaining
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA :LEN
|
|
|
|
SBC WRITEPL+4
|
|
|
|
STA :LEN
|
|
|
|
LDA :LEN+1
|
|
|
|
SBC WRITEPL+5
|
|
|
|
STA :LEN+1
|
|
|
|
BRA :ENDLOOP
|
|
|
|
|
|
|
|
:CANTOPEN
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$01 ; Can't open/create
|
2021-07-28 04:17:47 +00:00
|
|
|
BRA :EXIT
|
|
|
|
:WRITEERR
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA OPENPL+5 ; File ref num
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CLSPL+1
|
|
|
|
JSR CLSFILE
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$02 ; Write error
|
2021-07-28 04:17:47 +00:00
|
|
|
BRA :EXIT
|
|
|
|
:NORMALEND
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA OPENPL+5 ; File ref num
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CLSPL+1
|
|
|
|
JSR CLSFILE
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA #$00 ; Success!
|
|
|
|
BCC :EXIT ; If close OK
|
|
|
|
LDA #$02 ; Write error
|
2021-07-28 04:17:47 +00:00
|
|
|
:EXIT PHA
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C08B ; R/W RAM, bank 1
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,OSFILERET
|
2021-07-28 04:17:47 +00:00
|
|
|
PLA
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFAUX
|
2021-07-28 04:17:47 +00:00
|
|
|
:LEN DW $0000
|
|
|
|
:BLOCKS DB $00
|
|
|
|
|
|
|
|
* Quit to ProDOS
|
2021-07-30 20:49:34 +00:00
|
|
|
QUIT INC $3F4 ; Invalidate powerup byte
|
|
|
|
STA $C054 ; PAGE2 off
|
2021-07-28 04:17:47 +00:00
|
|
|
JSR MLI
|
|
|
|
DB QUITCMD
|
|
|
|
DW QUITPL
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Obtain catalog of current PREFIX dir
|
2021-07-30 20:49:34 +00:00
|
|
|
CATALOG LDX $0100 ; Recover SP
|
2021-07-28 04:17:47 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C081 ; Select ROM
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C081
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
JSR MLI ; Fetch prefix into BLKBUF
|
2021-07-28 04:17:47 +00:00
|
|
|
DB GPFXCMD
|
|
|
|
DW GPFXPL
|
2021-07-30 20:49:34 +00:00
|
|
|
BNE CATEXIT ; If prefix not set
|
2021-07-28 04:17:47 +00:00
|
|
|
|
2021-07-29 00:47:26 +00:00
|
|
|
LDA #<BLKBUF
|
2021-07-28 04:17:47 +00:00
|
|
|
STA OPENPL+1
|
2021-07-29 00:47:26 +00:00
|
|
|
LDA #>BLKBUF
|
2021-07-28 04:17:47 +00:00
|
|
|
STA OPENPL+2
|
|
|
|
JSR OPENFILE
|
2021-07-30 20:49:34 +00:00
|
|
|
BCS CATEXIT ; Can't open dir
|
2021-07-28 04:17:47 +00:00
|
|
|
|
|
|
|
CATREENTRY
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA OPENPL+5 ; File ref num
|
2021-07-28 04:17:47 +00:00
|
|
|
STA READPL+1
|
2021-07-29 00:47:26 +00:00
|
|
|
JSR RDFILE
|
2021-07-28 04:17:47 +00:00
|
|
|
BCC :S1
|
2021-07-30 20:49:34 +00:00
|
|
|
CMP #$4C ; EOF
|
2021-07-28 04:17:47 +00:00
|
|
|
BEQ :EOF
|
|
|
|
BRA :READERR
|
|
|
|
|
|
|
|
:S1 JSR COPYAUXBLK
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C08B ; R/W RAM, bank 1
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,PRONEBLK
|
|
|
|
>>> XFAUX
|
2021-07-28 04:17:47 +00:00
|
|
|
|
|
|
|
:READERR
|
2021-07-30 20:49:34 +00:00
|
|
|
:EOF LDA OPENPL+5 ; File ref num
|
2021-07-28 04:17:47 +00:00
|
|
|
STA CLSPL+1
|
|
|
|
JSR CLSFILE
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
CATEXIT LDA $C08B ; R/W LC RAM, bank 1
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,STARCATRET
|
2021-07-28 04:17:47 +00:00
|
|
|
PLA
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFAUX
|
2021-07-28 04:17:47 +00:00
|
|
|
|
|
|
|
* PRONEBLK call returns here ...
|
|
|
|
CATALOGRET
|
2021-07-30 20:49:34 +00:00
|
|
|
LDX #0100 ; Recover SP
|
2021-07-28 04:17:47 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C081 ; ROM please
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C081
|
|
|
|
BRA CATREENTRY
|
|
|
|
|
|
|
|
* Set the prefix
|
2021-07-30 20:49:34 +00:00
|
|
|
SETPFX LDX $0100 ; Recover SP
|
2021-07-28 04:17:47 +00:00
|
|
|
TXS
|
2021-07-30 20:49:34 +00:00
|
|
|
LDA $C081 ; ROM, ta!
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C081
|
|
|
|
JSR MLI
|
|
|
|
DB SPFXCMD
|
|
|
|
DW SPFXPL
|
|
|
|
BCC :S1
|
2021-07-30 20:49:34 +00:00
|
|
|
JSR BELL ; Beep on error
|
2021-07-28 04:17:47 +00:00
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
:S1 LDA $C08B ; R/W LC RAM, bank 1
|
2021-07-28 04:17:47 +00:00
|
|
|
LDA $C08B
|
2021-07-30 20:49:34 +00:00
|
|
|
>>> XFADDR,STARDIRRET
|
|
|
|
>>> XFAUX
|
2021-07-28 04:17:47 +00:00
|
|
|
|
|
|
|
* Create disk file
|
|
|
|
CRTFILE JSR MLI
|
|
|
|
DB CREATCMD
|
|
|
|
DW CREATEPL
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Open disk file
|
|
|
|
OPENFILE JSR MLI
|
|
|
|
DB OPENCMD
|
|
|
|
DW OPENPL
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Close disk file
|
|
|
|
CLSFILE JSR MLI
|
|
|
|
DB CLSCMD
|
|
|
|
DW CLSPL
|
|
|
|
RTS
|
|
|
|
|
2021-07-29 00:47:26 +00:00
|
|
|
* Read 512 bytes into BLKBUF
|
|
|
|
RDFILE JSR MLI
|
2021-07-28 04:17:47 +00:00
|
|
|
DB READCMD
|
|
|
|
DW READPL
|
|
|
|
RTS
|
|
|
|
|
2021-07-29 00:47:26 +00:00
|
|
|
* Write data in BLKBUF to disk
|
|
|
|
WRTFILE JSR MLI
|
2021-07-28 04:17:47 +00:00
|
|
|
DB WRITECMD
|
|
|
|
DW WRITEPL
|
|
|
|
RTS
|
|
|
|
|
|
|
|
HELLO ASC "Applecorn - (c) Bobbi 2021 GPLv3"
|
|
|
|
HEX 00
|
|
|
|
CANTOPEN ASC "Unable to open BASIC.ROM"
|
|
|
|
HEX 00
|
|
|
|
ROMFILE STR "BASIC.ROM"
|
|
|
|
|
|
|
|
* ProDOS Parameter lists for MLI calls
|
2021-07-30 20:49:34 +00:00
|
|
|
OPENPL HEX 03 ; Number of parameters
|
|
|
|
DW $0000 ; Pointer to filename
|
|
|
|
DW IOBUF0 ; Pointer to IO buffer
|
|
|
|
DB $00 ; Reference number returned
|
|
|
|
|
|
|
|
OPENPL2 HEX 03 ; Number of parameters
|
|
|
|
DW $0000 ; Pointer to filename
|
|
|
|
DW $0000 ; Pointer to IO buffer
|
|
|
|
DB $00 ; Reference number returned
|
|
|
|
|
|
|
|
CREATEPL HEX 07 ; Number of parameters
|
|
|
|
DW $0000 ; Pointer to filename
|
|
|
|
DB $00 ; Access
|
|
|
|
DB $00 ; File type
|
|
|
|
DW $0000 ; Aux type
|
|
|
|
DB $00 ; Storage type
|
|
|
|
DW $0000 ; Create date
|
|
|
|
DW $0000 ; Create time
|
|
|
|
|
|
|
|
DESTPL HEX 01 ; Number of parameters
|
|
|
|
DW $0000 ; Pointer to filename
|
|
|
|
|
|
|
|
READPL HEX 04 ; Number of parameters
|
|
|
|
DB $00 ; Reference number
|
|
|
|
DW BLKBUF ; Pointer to data buffer
|
|
|
|
DW 512 ; Request count
|
|
|
|
DW $0000 ; Trans count
|
|
|
|
|
|
|
|
READPL2 HEX 04 ; Number of parameters
|
|
|
|
DB #00 ; Reference number
|
|
|
|
DW BLKBUF ; Pointer to data buffer
|
|
|
|
DW 1 ; Request count
|
|
|
|
DW $0000 ; Trans count
|
|
|
|
|
|
|
|
WRITEPL HEX 04 ; Number of parameters
|
|
|
|
DB $01 ; Reference number
|
|
|
|
DW BLKBUF ; Pointer to data buffer
|
|
|
|
DW $00 ; Request count
|
|
|
|
DW $0000 ; Trans count
|
|
|
|
|
|
|
|
CLSPL HEX 01 ; Number of parameters
|
|
|
|
DB $00 ; Reference number
|
|
|
|
|
|
|
|
FLSHPL HEX 01 ; Number of parameters
|
|
|
|
DB $00 ; Reference number
|
|
|
|
|
|
|
|
ONLPL HEX 02 ; Number of parameters
|
|
|
|
DB $00 ; Unit num
|
|
|
|
DW $301 ; Buffer
|
|
|
|
|
|
|
|
GSPFXPL HEX 01 ; Number of parameters
|
|
|
|
DW $300 ; Buffer
|
|
|
|
|
|
|
|
GPFXPL HEX 01 ; Number of parameters
|
|
|
|
DW BLKBUF ; Buffer
|
|
|
|
|
|
|
|
SPFXPL HEX 01 ; Number of parameters
|
|
|
|
DW MOSFILE ; Buffer
|
|
|
|
|
|
|
|
GMARKPL HEX 02 ; Number of parameters
|
|
|
|
DB $00 ; File reference number
|
|
|
|
DB $00 ; Mark (24 bit)
|
2021-07-29 18:43:56 +00:00
|
|
|
DB $00
|
|
|
|
DB $00
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
GEOFPL HEX 02 ; Number of parameters
|
|
|
|
DB $00 ; File reference number
|
|
|
|
DB $00 ; EOF (24 bit)
|
2021-07-29 18:43:56 +00:00
|
|
|
DB $00
|
|
|
|
DB $00
|
|
|
|
|
2021-07-30 20:49:34 +00:00
|
|
|
QUITPL HEX 04 ; Number of parameters
|
2021-07-28 04:17:47 +00:00
|
|
|
DB $00
|
|
|
|
DW $0000
|
|
|
|
DB $00
|
|
|
|
DW $0000
|
|
|
|
|
|
|
|
* Buffer for Acorn MOS filename
|
2021-07-30 20:49:34 +00:00
|
|
|
MOSFILE DS 64 ; 64 bytes max prefix/file len
|
2021-07-28 04:17:47 +00:00
|
|
|
|
|
|
|
* Acorn MOS format OSFILE param list
|
|
|
|
FILEBLK
|
2021-07-30 20:49:34 +00:00
|
|
|
FBPTR DW $0000 ; Pointer to name (in aux)
|
|
|
|
FBLOAD DW $0000 ; Load address
|
2021-07-28 04:17:47 +00:00
|
|
|
DW $0000
|
2021-07-30 20:49:34 +00:00
|
|
|
FBEXEC DW $0000 ; Exec address
|
2021-07-28 04:17:47 +00:00
|
|
|
DW $0000
|
2021-07-30 20:49:34 +00:00
|
|
|
FBSTRT DW $0000 ; Start address for SAVE
|
2021-07-28 04:17:47 +00:00
|
|
|
DW $0000
|
2021-07-30 20:49:34 +00:00
|
|
|
FBEND DW $0000 ; End address for SAVE
|
2021-07-28 04:17:47 +00:00
|
|
|
DW $0000
|
|
|
|
|