2021-09-07 02:28:07 +00:00
|
|
|
* MAINMEM.MISC.S
|
|
|
|
* (c) Bobbi 2021 GPLv3
|
|
|
|
*
|
|
|
|
* Miscellaneous routines used by main memory code.
|
|
|
|
|
2022-12-20 01:30:34 +00:00
|
|
|
FKEYLENS DS 16 ; Length of f-key definitions 0..15
|
|
|
|
FKEYBUF DS 256 ; 256 bytes for f-key definitions
|
2022-12-19 03:40:40 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-22 02:05:42 +00:00
|
|
|
* Copy a block of main memory
|
|
|
|
* A1L/A1H: Start address
|
|
|
|
* A2L/A2H: End address
|
|
|
|
* A4L/A4H: Destination start address
|
2021-11-05 23:16:22 +00:00
|
|
|
MEMCPY LDA (A1L)
|
|
|
|
STA (A4L)
|
|
|
|
LDA A1H
|
|
|
|
CMP A2H
|
|
|
|
BNE :S1
|
|
|
|
LDA A1L
|
|
|
|
CMP A2L
|
|
|
|
BNE :S1
|
|
|
|
:DONE RTS
|
|
|
|
:S1 INC A1L
|
|
|
|
BNE :S2
|
|
|
|
INC A1H
|
|
|
|
:S2 INC A4L
|
|
|
|
BNE :S3
|
|
|
|
INC A4H
|
|
|
|
:S3 BRA MEMCPY
|
2021-09-22 02:05:42 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
|
|
|
|
* Search FILEREFS for value in A
|
2021-09-15 04:02:08 +00:00
|
|
|
* On return, buffer number is in X (or $FF if no bufs)
|
2021-11-05 23:16:22 +00:00
|
|
|
FINDBUF LDX #$00
|
|
|
|
:L1 CMP FILEREFS,X
|
|
|
|
BEQ :END
|
|
|
|
INX
|
|
|
|
CPX #$04
|
|
|
|
BNE :L1
|
|
|
|
LDX #$FF ; $FF for not found
|
|
|
|
:END RTS
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-15 04:02:08 +00:00
|
|
|
* Obtain I/O buffer address
|
|
|
|
* On entry: buffer number in X
|
|
|
|
* On exit: buffer address in AY
|
|
|
|
* Carry set if no bufs, clear otherwise
|
2021-11-05 23:16:22 +00:00
|
|
|
BUFADDR CPX #$00
|
|
|
|
BNE :S1
|
|
|
|
LDA #<IOBUF1
|
|
|
|
LDY #>IOBUF1
|
|
|
|
BRA :EXIT
|
|
|
|
:S1 CPX #$01
|
|
|
|
BNE :S2
|
|
|
|
LDA #<IOBUF2
|
|
|
|
LDY #>IOBUF2
|
|
|
|
BRA :EXIT
|
|
|
|
:S2 CPX #$02
|
|
|
|
BNE :S3
|
|
|
|
LDA #<IOBUF3
|
|
|
|
LDY #>IOBUF3
|
|
|
|
BRA :EXIT
|
|
|
|
:S3 CPX #$03
|
|
|
|
BNE :NOBUFS
|
|
|
|
LDA #<IOBUF4
|
|
|
|
LDY #>IOBUF4
|
|
|
|
:EXIT CLC
|
|
|
|
RTS
|
|
|
|
:NOBUFS SEC
|
|
|
|
RTS
|
2021-11-04 02:55:05 +00:00
|
|
|
|
2021-09-15 04:02:08 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Check if file exists
|
2021-11-04 02:55:05 +00:00
|
|
|
* Returns A=0 if doesn't exist, A=1 file, A=2 dir
|
2021-11-05 23:16:22 +00:00
|
|
|
EXISTS LDA #<MOSFILE
|
|
|
|
STA GINFOPL+1
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA GINFOPL+2
|
|
|
|
JSR GETINFO ; GET_FILE_INFO
|
|
|
|
LDA #$00
|
|
|
|
BCS :EXIT ; Any error -> $00
|
|
|
|
LDA GINFOPL+7 ; Storage type
|
|
|
|
CMP #$0D
|
|
|
|
LDA #$01 ; File -> $01
|
|
|
|
ADC #$00 ; Dir. -> $02
|
|
|
|
:EXIT RTS
|
2021-10-24 17:34:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
* Copy FILEBLK to OSFILECB in aux memory
|
2021-09-07 02:28:07 +00:00
|
|
|
* Preserves A
|
2021-11-05 23:16:22 +00:00
|
|
|
COPYFB PHA
|
|
|
|
LDX #$11 ; 18 bytes in FILEBLK
|
2022-10-12 04:00:36 +00:00
|
|
|
STA WRCARDRAM ; Write to aux mem
|
2021-11-05 23:16:22 +00:00
|
|
|
:L1 LDA FILEBLK,X
|
|
|
|
STA OSFILECB,X
|
|
|
|
DEX
|
|
|
|
BPL :L1
|
2022-10-12 04:00:36 +00:00
|
|
|
STA WRMAINRAM ; Write to main mem again
|
2021-11-05 23:16:22 +00:00
|
|
|
PLA
|
|
|
|
RTS
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Get file info
|
2021-11-05 23:16:22 +00:00
|
|
|
GETINFO JSR MLI
|
|
|
|
DB GINFOCMD
|
|
|
|
DW GINFOPL
|
|
|
|
RTS
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Set file info
|
2021-11-05 23:16:22 +00:00
|
|
|
SETINFO LDA #$07 ; SET_FILE_INFO 7 parms
|
|
|
|
STA GINFOPL
|
|
|
|
JSR MLI
|
|
|
|
DB SINFOCMD
|
|
|
|
DW GINFOPL ; Re-use PL from GFI
|
|
|
|
LDA #$0A ; GET_FILE_INFO 10 parms
|
|
|
|
STA GINFOPL
|
|
|
|
RTS
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Create disk file
|
2021-09-07 03:43:42 +00:00
|
|
|
* Uses filename in MOSFILE
|
2021-11-05 23:16:22 +00:00
|
|
|
CRTFILE JSR MLI ; GET_TIME
|
|
|
|
DB GTIMECMD
|
|
|
|
LDA #<MOSFILE
|
|
|
|
STA CREATEPL+1
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA CREATEPL+2
|
|
|
|
LDA #$C3 ; Open permissions
|
|
|
|
STA CREATEPL+3
|
2022-10-09 01:38:12 +00:00
|
|
|
LDA PRODOSDATE ; Current date
|
2021-11-05 23:16:22 +00:00
|
|
|
STA CREATEPL+8
|
2022-10-09 01:38:12 +00:00
|
|
|
LDA PRODOSDATE+1
|
2021-11-05 23:16:22 +00:00
|
|
|
STA CREATEPL+9
|
2022-10-09 01:38:12 +00:00
|
|
|
LDA PRODOSTIME ; Current time
|
2021-11-05 23:16:22 +00:00
|
|
|
STA CREATEPL+10
|
2022-10-09 01:38:12 +00:00
|
|
|
LDA PRODOSTIME+1
|
2021-11-05 23:16:22 +00:00
|
|
|
STA CREATEPL+11
|
|
|
|
JSR MLI
|
|
|
|
DB CREATCMD
|
|
|
|
DW CREATEPL
|
|
|
|
RTS
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Open disk file
|
2021-11-05 23:16:22 +00:00
|
|
|
OPENMOSFILE LDA #<MOSFILE ; Open filename in MOSFILE
|
|
|
|
STA OPENPL+1
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA OPENPL+2
|
|
|
|
OPENFILE JSR MLI
|
|
|
|
DB OPENCMD
|
|
|
|
DW OPENPL
|
|
|
|
RTS
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Close disk file
|
2021-11-05 23:16:22 +00:00
|
|
|
CLSFILE JSR MLI
|
|
|
|
DB CLSCMD
|
|
|
|
DW CLSPL
|
|
|
|
RTS
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Read 512 bytes into BLKBUF
|
2021-11-05 23:16:22 +00:00
|
|
|
RDFILE JSR MLI
|
|
|
|
DB READCMD
|
|
|
|
DW READPL
|
|
|
|
RTS
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Write data in BLKBUF to disk
|
2021-11-05 23:16:22 +00:00
|
|
|
WRTFILE JSR MLI
|
|
|
|
DB WRITECMD
|
|
|
|
DW WRITEPL
|
|
|
|
RTS
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Put ProDOS prefix in PREFIX
|
2021-11-05 23:16:22 +00:00
|
|
|
GETPREF JSR MLI
|
|
|
|
DB GPFXCMD
|
|
|
|
DW GPFXPL
|
|
|
|
RTS
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2022-12-22 23:26:50 +00:00
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Map of file reference numbers to IOBUF1..4
|
2021-11-05 23:16:22 +00:00
|
|
|
FILEREFS DB $00,$00,$00,$00
|
|
|
|
|