Merge PR 124 'Optimised CREATE, removed dead code...'

This commit is contained in:
Bobbi Webber-Manners 2021-10-18 18:18:56 -04:00
parent 058cb4f718
commit 9f82312da2
6 changed files with 185 additions and 447 deletions

Binary file not shown.

View File

@ -929,10 +929,10 @@ MKERROR4 DW ERROR27
* $2C -(GSOS bad byte count) * $2C -(GSOS bad byte count)
* $2D -(GSOS bad block number) * $2D -(GSOS bad block number)
* $2E - Disk switched Disk changed * $2E - Disk switched Disk changed
* $2F - Device is offline (drive empty) * $2F - Device is offline (drive empty/absent)
* $40 - Invalid pathname syntax. Bad filename * $40 - Invalid pathname syntax. Bad filename
* $41 -(Duplicate filename. (split from $47) Is a directory) * $41 -(Duplicate filename. split from $47) Is a directory)
* $42 - File Control Block table full. Too many open * $42 - File Control Block table full. Too many open
* $43 - Invalid reference number. Channel not open * $43 - Invalid reference number. Channel not open
* $44 - Path not found. (Dir not found) File not found * $44 - Path not found. (Dir not found) File not found
@ -946,7 +946,7 @@ MKERROR4 DW ERROR27
* $4C - End of file has been encountered. End of file * $4C - End of file has been encountered. End of file
* $4D - Position out of range. Past end of file * $4D - Position out of range. Past end of file
* $4E - Access error. (see also $4F) RD/WR: Insufficient access, also Dir not empty * $4E - Access error. (see also $4F) RD/WR: Insufficient access, also Dir not empty
* $4F - (GSOS Buffer too small) (Access error. (split from $4E) REN/DEL: Locked) * $4F -(Access error. split from $4E) REN/DEL/SAV: Locked
* $50 - File already open. Can't - file open * $50 - File already open. Can't - file open
* $51 - Directory count error. Broken directory * $51 - Directory count error. Broken directory
* $52 - Not a ProDOS disk. Disk not recognised * $52 - Not a ProDOS disk. Disk not recognised
@ -960,7 +960,7 @@ MKERROR4 DW ERROR27
* $5A - Bit map disk address is impossible. Sector not found * $5A - Bit map disk address is impossible. Sector not found
* $5B -(GSOS Bad ChangePath pathname) * $5B -(GSOS Bad ChangePath pathname)
* $5C -(GSOS Not executable file) * $5C -(GSOS Not executable file)
* $5D -(GSOS OS/FS not found) (EOF during load or save) Data lost * $5D -(GSOS OS/FS not found) (EOF during load or save) Data lost
* $5E -(Couldn't open to save) Can't save * $5E -(Couldn't open to save) Can't save
* $5F -(GSOS Too many applications) * $5F -(GSOS Too many applications)
* $60+ - (GSOS) * $60+ - (GSOS)
@ -997,7 +997,7 @@ ERROR4D DW $C100
ERROR4E DW $BD00 ERROR4E DW $BD00
ASC 'Insufficient access' ; $4E - Access error (see also $4F) ASC 'Insufficient access' ; $4E - Access error (see also $4F)
ERROR4F DW $C300 ERROR4F DW $C300
ASC 'Locked' ; $4F - Access error (split from $4E) ASC 'Entry locked' ; $4F - Access error (split from $4E)
ERROR50 DW $C200 ERROR50 DW $C200
ASC 'Can' ASC 'Can'
DB $27 DB $27

View File

@ -174,7 +174,7 @@ BYTE00 BEQ BYTE00A ; OSBYTE 0,0 - generate error
RTS ; %000x1xxx host type, 'A'pple RTS ; %000x1xxx host type, 'A'pple
BYTE00A BRK BYTE00A BRK
DB $F7 DB $F7
HELLO ASC 'Applecorn MOS 2021-10-17' HELLO ASC 'Applecorn MOS 2021-10-18'
DB $00 ; Unify MOS messages DB $00 ; Unify MOS messages

View File

@ -51,14 +51,14 @@ RDPLCP HEX 04 ; Number of parameters
WRITEPL HEX 04 ; Number of parameters WRITEPL HEX 04 ; Number of parameters
DB $01 ; Reference number DB $01 ; Reference number
DW BLKBUF ; Pointer to data buffer DW BLKBUF ; Pointer to data buffer
DW $00 ; Request count DW $0000 ; Request count
DW $0000 ; Trans count DW $0000 ; Trans count
* Used for file copy only because we can't trash BLKBUF * Used for file copy only because we can't trash BLKBUF
WRTPLCP HEX 04 ; Number of parameters WRTPLCP HEX 04 ; Number of parameters
DB $01 ; Reference number DB $01 ; Reference number
DW COPYBUF ; Pointer to data buffer DW COPYBUF ; Pointer to data buffer
DW $00 ; Request count DW $0000 ; Request count
DW $0000 ; Trans count DW $0000 ; Trans count
CLSPL HEX 01 ; Number of parameters CLSPL HEX 01 ; Number of parameters
@ -128,25 +128,3 @@ QUITPL HEX 04 ; Number of parameters

View File

@ -161,6 +161,10 @@ CRTFILE JSR MLI ; GET_TIME
RTS RTS
* Open disk file * Open disk file
OPENMOSFILE LDA #<MOSFILE ; Open filename in MOSFILE
STA OPENPL+1
LDA #>MOSFILE
STA OPENPL+2
OPENFILE JSR MLI OPENFILE JSR MLI
DB OPENCMD DB OPENCMD
DW OPENPL DW OPENPL
@ -193,46 +197,3 @@ GETPREF JSR MLI
* Map of file reference numbers to IOBUF1..4 * Map of file reference numbers to IOBUF1..4
FILEREFS DB $00,$00,$00,$00 FILEREFS DB $00,$00,$00,$00

View File

@ -14,6 +14,7 @@
* 15-Oct-2021 LOADFILE updated. * 15-Oct-2021 LOADFILE updated.
* 16-Oct-2021 LOADFILE only reads object info once. * 16-Oct-2021 LOADFILE only reads object info once.
* 17-Oct-2021 SAVEFILE updated. * 17-Oct-2021 SAVEFILE updated.
* 18-Oct-2021 Optimised CREATE, removed dead code, RDDATA and WRDATA.
INFOFILE >>> ENTMAIN INFOFILE >>> ENTMAIN
@ -54,29 +55,26 @@ DODELETE LDA #<MOSFILE ; Attempt to destroy file
* ProDOS file handling to create a directory * ProDOS file handling to create a directory
* Invoked by AppleMOS OSFILE * Invoked by AppleMOS OSFILE
* Return A=02 on success (ie: 'directory') * Return A=$02 on success (ie: 'directory')
* A>$1F ProDOS error, translated by OSFILE handler * A>$1F ProDOS error, translated by OSFILE handler
MAKEDIR >>> ENTMAIN MAKEDIR >>> ENTMAIN
JSR PREPATH ; Preprocess pathname JSR PREPATH ; Preprocess pathname
JSR UPDFB ; Update FILEBLK JSR UPDFB ; Update FILEBLK
JSR COPYFB ; Copy back to aux mem
CMP #$02 CMP #$02
BEQ :EXIT ; Dir already exists BEQ :EXIT1 ; Dir already exists
LDA #$0D ; 'Directory'
LDA #$0D ; OBJT='Directory'
STA CREATEPL+7 ; ->Storage type STA CREATEPL+7 ; ->Storage type
LDA #$0F ; 'Directory' LDA #$0F ; TYPE='Directory'
STA CREATEPL+4 ; ->File type LDX #$00 ; LOAD=$0000
STZ CREATEPL+5 ; Aux type LSB LDY #$00
STZ CREATEPL+6 ; Aux type MSB JSR CREATEOBJ
LDA #$C3 ; Default permissions
STA CREATEPL+3
JSR CRTFILE ; Create MOSFILE
BCS :EXIT ; Failed, exit with ProDOS result BCS :EXIT ; Failed, exit with ProDOS result
JSR UPDFB ; Update FILEBLK JSR UPDFB ; Update FILEBLK, returns A=$02
JSR COPYFB ; Copy FILEBLK to aux mem :EXIT1 JSR COPYFB ; Copy FILEBLK to aux mem
LDA #$02 ; Success, $02=dir created
:EXIT >>> XF2AUX,OSFILERET :EXIT >>> XF2AUX,OSFILERET
* ProDOS file handling to rename a file * ProDOS file handling to rename a file
RENFILE >>> ENTMAIN RENFILE >>> ENTMAIN
JSR PREPATH ; Preprocess arg1 JSR PREPATH ; Preprocess arg1
@ -294,7 +292,7 @@ OFILE >>> ENTMAIN
AND #$C0 ; Keep just action bits AND #$C0 ; Keep just action bits
PHA ; Preserve arg for later PHA ; Preserve arg for later
JSR PREPATH ; Preprocess pathname JSR PREPATH ; Preprocess pathname
BCS :JMPEXIT ; Bad filename BCS :JMPEXIT1 ; Bad filename
PLA PLA
PHA PHA
CMP #$80 ; Is it "w"? CMP #$80 ; Is it "w"?
@ -307,6 +305,8 @@ OFILE >>> ENTMAIN
PLA ; Get action back PLA ; Get action back
BPL :NOTDIR2 ; OPENIN(dir) allowed BPL :NOTDIR2 ; OPENIN(dir) allowed
LDA #$41 ; $41=Directory exists LDA #$41 ; $41=Directory exists
PHA ; Balance PLA
:JMPEXIT1 PLA
:JMPEXIT JMP FINDEXIT :JMPEXIT JMP FINDEXIT
:NOTDIR PLA :NOTDIR PLA
:NOTDIR2 CMP #$80 ; Write mode :NOTDIR2 CMP #$80 ; Write mode
@ -315,21 +315,9 @@ OFILE >>> ENTMAIN
BEQ :S0 ; No file, don't try to delete BEQ :S0 ; No file, don't try to delete
JSR DODELETE JSR DODELETE
BCS FINDEXIT ; Abort if error BCS FINDEXIT ; Abort if error
:S0 LDA #$01 ; Storage type - file :S0 LDX #$00 ; LOAD=$0000
STA CREATEPL+7 LDY #$00
LDA #$06 ; Filetype BIN JSR CREATEFILE
STA CREATEPL+4
LDA #<MOSFILE
STA OPENPL+1
LDA #>MOSFILE
STA OPENPL+2
LDA #$00 ; Auxtype
STA CREATEPL+5
LDA #$00
STA CREATEPL+6
LDA #$C3 ; Default permissions
STA CREATEPL+3
JSR CRTFILE ; Create MOSFILE
BCS FINDEXIT ; Abort if error BCS FINDEXIT ; Abort if error
* Looking for a buffer should be done before creating a file * Looking for a buffer should be done before creating a file
:S1 LDA #$00 ; Look for empty slot :S1 LDA #$00 ; Look for empty slot
@ -349,8 +337,6 @@ OFILE >>> ENTMAIN
BCS FINDEXIT BCS FINDEXIT
LDA OPENPL2+5 ; File ref number LDA OPENPL2+5 ; File ref number
LDX BUFIDX LDX BUFIDX
* CPX #$FF ; Checked for earlier
* BEQ FINDEXIT
STA FILEREFS,X ; Record the ref number STA FILEREFS,X ; Record the ref number
FINDEXIT JSR CHKNOTFND ; Convert NotFound to $00 FINDEXIT JSR CHKNOTFND ; Convert NotFound to $00
>>> XF2AUX,OSFINDRET >>> XF2AUX,OSFINDRET
@ -362,7 +348,6 @@ BUFIDX DB $00
* ProDOS can do CLOSE#0 but we need to manually update FILEREFS * ProDOS can do CLOSE#0 but we need to manually update FILEREFS
CFILE >>> ENTMAIN CFILE >>> ENTMAIN
LDX #$00 ; Prepare for one file LDX #$00 ; Prepare for one file
* LDA MOSFILE ; File ref number
TYA ; File ref number TYA ; File ref number
BNE :CFILE1 ; Close one file BNE :CFILE1 ; Close one file
LDX #$03 ; Loop through all files LDX #$03 ; Loop through all files
@ -387,11 +372,10 @@ CFILE >>> ENTMAIN
PLX PLX
BCS FINDEXIT BCS FINDEXIT
* ProDOS file handling for MOS OSBGET call * ProDOS file handling for MOS OSBGET call
* Returns with char read in A and error num in Y (or 0) * Returns with char read in A and error num in Y (or 0)
FILEGET >>> ENTMAIN FILEGET >>> ENTMAIN
* LDA MOSFILE ; File ref number
* STA READPL2+1
STY READPL2+1 ; File ref number STY READPL2+1 ; File ref number
JSR MLI JSR MLI
DB READCMD DB READCMD
@ -402,12 +386,11 @@ FILEGET >>> ENTMAIN
LDA BLKBUF LDA BLKBUF
:EXIT >>> XF2AUX,OSBGETRET :EXIT >>> XF2AUX,OSBGETRET
* ProDOS file handling for MOS OSBPUT call * ProDOS file handling for MOS OSBPUT call
* Enters with char to write in A * Enters with char to write in A
FILEPUT >>> ENTMAIN FILEPUT >>> ENTMAIN
STA BLKBUF ; Char to write STA BLKBUF ; Byte to write
* LDA MOSFILE ; File ref number
* STA WRITEPL+1
STY WRITEPL+1 ; File ref number STY WRITEPL+1 ; File ref number
LDA #$01 ; Bytes to write LDA #$01 ; Bytes to write
STA WRITEPL+4 STA WRITEPL+4
@ -419,11 +402,10 @@ FILEPUT >>> ENTMAIN
:FILEPUT2 >>> XF2AUX,OSBPUTRET :FILEPUT2 >>> XF2AUX,OSBPUTRET
* ProDOS file handling for OSBYTE $7F EOF * ProDOS file handling for FSC $01 called by OSBYTE $7F EOF
* Returns EOF status in A ($FF for EOF, $00 otherwise) * Returns EOF status in A ($FF for EOF, $00 otherwise)
* A=channel to test * A=channel to test
FILEEOF >>> ENTMAIN FILEEOF >>> ENTMAIN
* LDA MOSFILE ; File ref number
STA GEOFPL+1 STA GEOFPL+1
STA GMARKPL+1 STA GMARKPL+1
JSR MLI JSR MLI
@ -431,7 +413,6 @@ FILEEOF >>> ENTMAIN
DW GEOFPL DW GEOFPL
TAY TAY
BCS :EXIT ; Abort with any error BCS :EXIT ; Abort with any error
JSR MLI JSR MLI
DB GMARKCMD DB GMARKCMD
DW GMARKPL DW GMARKPL
@ -461,30 +442,21 @@ FILEEOF >>> ENTMAIN
* ProDOS file handling for OSARGS flush commands * ProDOS file handling for OSARGS flush commands
FLUSH >>> ENTMAIN FLUSH >>> ENTMAIN
* LDA MOSFILE ; File ref number
* STA FLSHPL+1
STY FLSHPL+1 ; File ref number STY FLSHPL+1 ; File ref number
JSR MLI JSR MLI
DB FLSHCMD DB FLSHCMD
DW FLSHPL DW FLSHPL
>>> XF2AUX,OSARGSRET JMP TELLEXIT
* ProDOS file handling for OSARGS set ptr command * ProDOS file handling for OSARGS set ptr command
* GMARKPL+1=channel, GMARKPL+2,+3,+4=offset already set * GMARKPL+1=channel, GMARKPL+2,+3,+4=offset already set
SEEK >>> ENTMAIN SEEK >>> ENTMAIN
* LDA MOSFILE ; File ref number
* STA GMARKPL+1 ; GET_MARK has same params
* LDA MOSFILE+2 ; Desired offset in MOSFILE[2..4]
* STA GMARKPL+2
* LDA MOSFILE+3
* STA GMARKPL+3
* LDA MOSFILE+4
* STA GMARKPL+4
JSR MLI JSR MLI
DB SMARKCMD DB SMARKCMD
DW GMARKPL DW GMARKPL
JMP TELLEXIT JMP TELLEXIT
* >>> XF2AUX,OSARGSRET
* ProDOS file handling for OSARGS get ptr command * ProDOS file handling for OSARGS get ptr command
* and for OSARGs get length command * and for OSARGs get length command
@ -492,13 +464,7 @@ SEEK >>> ENTMAIN
SIZE LDX #$02 ; $02=SIZE, Read EXT SIZE LDX #$02 ; $02=SIZE, Read EXT
BNE TELL2 BNE TELL2
TELL LDX #$00 ; $00=TELL, Read PTR TELL LDX #$00 ; $00=TELL, Read PTR
TELL2 TELL2 STY GMARKPL+1 ; File ref number
* >>> ENTMAIN
* LDA MOSFILE ; File ref number
* STA GMARKPL+1
* LDA MOSFILE+2 ; Mode (0=pos, otherwise len)
* CMP #$00
STY GMARKPL+1 ; File ref number
PHA ; Pointer to zero page PHA ; Pointer to zero page
CPX #$00 ; OSARGS parameter CPX #$00 ; OSARGS parameter
BEQ :POS BEQ :POS
@ -511,7 +477,6 @@ TELL2
DW GMARKPL DW GMARKPL
:S1 PLX ; Pointer to ZP control block :S1 PLX ; Pointer to ZP control block
BCS TELLEXIT ; Exit with error BCS TELLEXIT ; Exit with error
* LDX MOSFILE+1 ; Pointer to ZP control block
>>> ALTZP ; Alt ZP & Alt LC on >>> ALTZP ; Alt ZP & Alt LC on
LDA GMARKPL+2 LDA GMARKPL+2
STA $00,X STA $00,X
@ -523,14 +488,6 @@ TELL2
>>> MAINZP ; Alt ZP off, ROM back in >>> MAINZP ; Alt ZP off, ROM back in
LDA #$00 ; 0=Ok LDA #$00 ; 0=Ok
TELLEXIT >>> XF2AUX,OSARGSRET TELLEXIT >>> XF2AUX,OSARGSRET
*:ERR LDX MOSFILE+1 ; Address of ZP control block
* >>> ALTZP ; Alt ZP & Alt LC on
* STZ $00,X
* STZ $01,X
* STZ $02,X
* STZ $03,X
* >>> MAINZP ; Alt ZP off, ROM back in
* BRA :EXIT
ZPMOS EQU $30 ZPMOS EQU $30
@ -548,9 +505,6 @@ LOADFILE >>> ENTMAIN
JSR PREPATH ; Preprocess pathname JSR PREPATH ; Preprocess pathname
JSR WILDONE ; Handle any wildcards JSR WILDONE ; Handle any wildcards
JSR UPDFB ; Get object info JSR UPDFB ; Get object info
* JSR EXISTS ; See if it exists ...
* BCS :EXIT2
CMP #$20 CMP #$20
BCS :JMPEXIT ; Error occured BCS :JMPEXIT ; Error occured
CMP #$01 ; Is it a file CMP #$01 ; Is it a file
@ -561,15 +515,7 @@ LOADFILE >>> ENTMAIN
:JMPEXIT JMP :EXIT2 ; Return error :JMPEXIT JMP :EXIT2 ; Return error
* EXISTS has done GETINFO, so file info already loaded * EXISTS has done GETINFO, so file info already loaded
:ISFILE :ISFILE LDA ZPMOS+4 ; If FBEXEC is zero, use addr
* LDA FBEXEC ; If FBEXEC is zero, use addr
* BEQ :CBADDR ; in the control block
* LDA GINFOPL+5 ; Otherwise, use file's address
* STA FBLOAD+0 ; Aux type LSB
* LDA GINFOPL+6 ; Aux type MSB
* STA FBLOAD+1
LDA ZPMOS+4 ; If FBEXEC is zero, use addr
BEQ :CBADDR ; in the control block BEQ :CBADDR ; in the control block
LDA FBLOAD+0 ; Otherwise, use file's address LDA FBLOAD+0 ; Otherwise, use file's address
STA ZPMOS+0 STA ZPMOS+0
@ -577,146 +523,94 @@ LOADFILE >>> ENTMAIN
STA ZPMOS+1 STA ZPMOS+1
:CBADDR :CBADDR
* NB: This is the file allocation, not the file size, so it can validly be >64K * LDA #<MOSFILE
* as the actual data may be <64K * STA OPENPL+1
* LDA #$60 ; *TO DO* Error=file too long * LDA #>MOSFILE
* LDX GINFOPL+9 * STA OPENPL+2
* BNE :EXIT2 ; size>128K, too big to load JSR OPENMOSFILE
* LDX GINFOPL+8
* BMI :EXIT2 ; size>64K, too big to load
* BEQ :EXITOK ; size=0, nothing to load
* STX :BLOCKS
LDA #<MOSFILE
STA OPENPL+1
LDA #>MOSFILE
STA OPENPL+2
JSR OPENFILE
BCS :EXIT2 ; File not opened BCS :EXIT2 ; File not opened
* TO DO: make subroutine callable by GBPB
* LDA FBLOAD+0 ; A4=>start address to load to
* STA A4L
* LDA FBLOAD+1
* STA A4H
:L1 LDA OPENPL+5 ; File ref number :L1 LDA OPENPL+5 ; File ref number
STA READPL+1 JSR READDATA ; Read data from open file
JSR RDFILE
* BCC :S1
* CMP #$4C ; EOF
* BEQ :EXITOK
* BEQ :EOF
* BRA :READERR
BCS :READERR ; Close file and return any error
:S1 * STA READPL+1
* CLC * JSR RDFILE
LDA #<BLKBUF ; LSB of start of data buffer * BCS :READERR ; Close file and return any error
STA A1L ; A1=>start of data buffer *
ADC READPL+6 ; LSB of trans count *:S1
STA A2L ; A2=>end of data buffer ** CLC
LDA #>BLKBUF * LDA #<BLKBUF ; LSB of start of data buffer
STA A1H * STA A1L ; A1=>start of data buffer
ADC READPL+7 ; MSB of trans count
STA A2H
* LDA FBLOAD+0 ; A4=>address to load to
* STA A4L
* LDA FBLOAD+1
* STA A4H
* INC FBLOAD+1 ; Step to next block
* INC FBLOAD+1
LDA ZPMOS+0 ; A4=>address to load to
STA A4L
LDA ZPMOS+1
STA A4H
INC ZPMOS+1 ; Step to next block
INC ZPMOS+1
* CLC
* LDA A1L ; A2=>end of data buffer
* ADC READPL+6 ; LSB of trans count * ADC READPL+6 ; LSB of trans count
* STA A2L * STA A2L ; A2=>end of data buffer
* LDA A1H * LDA #>BLKBUF
* STA A1H
* ADC READPL+7 ; MSB of trans count * ADC READPL+7 ; MSB of trans count
* STA A2H * STA A2H
* LDA ZPMOS+0 ; A4=>address to load to
* LDA FBEXEC ; If FBEXEC is zero, use addr
* CMP #$00 ; in the control block
* BEQ :CBADDR
* LDA #<MOSFILE ; Otherwise use file addr
* STA GINFOPL+1
* LDA #>MOSFILE
* STA GINFOPL+2
* JSR GETINFO ; GET_FILE_INFO
* BCS :READERR
* LDA GINFOPL+5 ; Aux type LSB
* STA FBLOAD+0
* LDA GINFOPL+6 ; Aux type MSB
* STA FBLOAD+1
*:CBADDR LDA FBLOAD
* STA A4L * STA A4L
* STA FBEXEC ; EXEC = LOAD * LDA ZPMOS+1
* LDA FBLOAD+1
* STA A4H * STA A4H
* STA FBEXEC+1 * INC ZPMOS+1 ; Step to next block
* LDX :BLOCKS * INC ZPMOS+1
*:L2 CPX #$00 *
* BEQ :S2 * SEC ; Main -> AUX
* INC * JSR AUXMOVE ; A4 updated to next address
* INC * JMP :L1
* DEX *
* BRA :L2 *:READERR CMP #$4C
*:S2 STA A4H * BNE :EXITERR
*:EXITOK LDA #$00 ; $00=Success
*:EXITERR
SEC ; Main -> AUX PHA ; Save result
JSR AUXMOVE ; A4 updated to next address
JMP :L1
* DEC :BLOCKS
* BNE :L1
* BEQ :EXITOK
* INC :BLOCKS
* BRA :L1
:READERR CMP #$4C
BNE :EXITERR
:EXITOK LDA #$00 ; $00=Success
:EXITERR PHA
LDA OPENPL+5 ; File ref num LDA OPENPL+5 ; File ref num
STA CLSPL+1 STA CLSPL+1
JSR CLSFILE JSR CLSFILE
PLA PLA
BNE :EXIT2 BNE :EXIT2
* PHA
* JSR UPDFB ; Update FILEBLK
JSR COPYFB ; Copy FILEBLK to auxmem JSR COPYFB ; Copy FILEBLK to auxmem
LDA #$01 ; $01=File LDA #$01 ; $01=File
* PLA ; Get return code back
:EXIT2 >>> XF2AUX,OSFILERET :EXIT2 >>> XF2AUX,OSFILERET
*:BLOCKS DB $00
*:NOTFILE ROL A ; 0->0, 2->5 * A=channel, MOSZP+0/1=address to load to, TO DO: MOS+4/5=length to read
* EOR #$05 ; 0->5, 2->0 READDATA STA READPL+1
* ADC #$41 ; 0->$46, 2->$41 :RDLP JSR RDFILE
*:NOTFND PHA BCS :READERR ; Close file and return any error
* BRA :EXIT
*:READERR LDA #$5D ; Read error LDA #<BLKBUF ; LSB of start of data buffer
* PHA STA A1L ; A1=>start of data buffer
* BRA :EOF2 ADC READPL+6 ; LSB of trans count
*:EXITOK TAX ; X=>LSB end of data buffer
*:EOF LDA #$01 ; Success ('File')
* PHA LDA #>BLKBUF ; MSB of start of data buffer
*:EOF2 LDA OPENPL+5 ; File ref num STA A1H ; A1=>start of data buffer
* STA CLSPL+1 ADC READPL+7 ; MSB of trans count
* JSR CLSFILE TAY ; Y=>MSB end of data buffer
*:EXIT JSR UPDFB ; Update FILEBLK
* JSR COPYFB ; Copy FILEBLK to auxmem TXA
* PLA ; Get return code back BNE :L2
*:EXIT2 >>> XF2AUX,OSFILERET DEY
*:BLOCKS DB $00 :L2 DEX ; XY=XY-1, end address is start+len-1
STX A2L ; A2=>end of data buffer
STY A2H
LDA ZPMOS+0 ; A4=>address to load to
STA A4L
LDA ZPMOS+1
STA A4H
INC ZPMOS+1 ; Step to next block
INC ZPMOS+1
SEC ; Main -> AUX
JSR AUXMOVE ; A4 updated to next address
JMP :RDLP
:READERR CMP #$4C
BNE :EXITERR
:EXITOK LDA #$00 ; $00=Success
:EXITERR RTS
* ProDOS file handling for MOS OSFILE SAVE call * ProDOS file handling for MOS OSFILE SAVE call
@ -739,8 +633,7 @@ SAVEFILE >>> ENTMAIN
BEQ :L0 ; >16M BEQ :L0 ; >16M
:TOOBIG JMP :CANTSAVE :TOOBIG JMP :CANTSAVE
:L0 :L0 JSR PREPATH ; Preprocess pathname
JSR PREPATH ; Preprocess pathname
JSR EXISTS ; See if file exists ... JSR EXISTS ; See if file exists ...
CMP #$01 CMP #$01
BEQ :NOTDIR ; Overwrite file BEQ :NOTDIR ; Overwrite file
@ -757,41 +650,42 @@ SAVEFILE >>> ENTMAIN
JSR MLI JSR MLI
DB DESTCMD DB DESTCMD
DW DESTPL DW DESTPL
BCS :JMPEXIT2 ; Error trying to delete BCS :EXIT2 ; Error trying to delete
:NOFILE :NOFILE LDX FBLOAD+0 ; Auxtype = load address
* STZ :BLOCKS LDY FBLOAD+1
* LDA #$01 ; Storage type - file JSR CREATEFILE
* STA CREATEPL+7 BCS :JMPEXIT2 ; Error trying to create
* LDA #$06 ; Filetype BIN
* STA CREATEPL+4
* LDA #<MOSFILE * LDA #<MOSFILE
* STA OPENPL+1 * STA OPENPL+1
* LDA #>MOSFILE * LDA #>MOSFILE
* STA OPENPL+2 * STA OPENPL+2
* LDA FBLOAD ; Auxtype = load address JSR OPENMOSFILE
* STA CREATEPL+5
* LDA FBLOAD+1
* STA CREATEPL+6
* LDA #$C3 ; Default permissions
* STA CREATEPL+3
* JSR CRTFILE
JSR CREATE
BCS :JMPEXIT2 ; Error trying to create
JSR OPENFILE
BCS :JMPEXIT2 ; Error trying to open BCS :JMPEXIT2 ; Error trying to open
LDA OPENPL+5 ; File ref number
JSR WRITEDATA
:L1 :EXIT1 PHA ; Save result
* LDA FBSTRT+0 ; Set up for current block LDA OPENPL+5 ; File ref num
* STA A1L ; A1=>source start STA CLSPL+1
* STA A2L JSR CLSFILE
* LDA FBSTRT+1 PLA
* STA A1H BNE :EXIT2 ; Error returned
* STA A2H JSR UPDFB ; Update FILEBLK
* INC A2H ; A2=>source start+$200 = 512 bytes JSR COPYFB ; Copy FILEBLK to aux mem
* INC A2H LDA #$01 ; Return A='File'
LDA #$00 ; 512 bytes request count :EXIT2 CMP #$4E
BNE :EXIT3 ; Change 'Insuff. access'
LDA #$4F ; to 'Locked'
:EXIT3 >>> XF2AUX,OSFILERET
:CANTSAVE LDA #$5E ; Can't open/create
BRA :EXIT3 ; TO DO: Error=File too long
* A=channel, FBSTRT+0/1=address to save from
* :LENREM+0/1=length to write
WRITEDATA STA WRITEPL+1
:L1 LDA #$00 ; 512 bytes request count
STA WRITEPL+4 STA WRITEPL+4
LDA #$02 LDA #$02
STA WRITEPL+5 STA WRITEPL+5
@ -805,8 +699,7 @@ SAVEFILE >>> ENTMAIN
ORA WRITEPL+5 ORA WRITEPL+5
BEQ :SAVEOK ; Zero bytes remaining BEQ :SAVEOK ; Zero bytes remaining
:L15 :L15 SEC
SEC
LDA :LENREM+0 ; LENREM=LENREM-count LDA :LENREM+0 ; LENREM=LENREM-count
SBC WRITEPL+4 SBC WRITEPL+4
STA :LENREM+0 STA :LENREM+0
@ -818,50 +711,22 @@ SAVEFILE >>> ENTMAIN
LDA FBSTRT+0 LDA FBSTRT+0
STA A1L ; A1=>start of this block STA A1L ; A1=>start of this block
ADC WRITEPL+4 ADC WRITEPL+4
STA A2L ; A2=>end of this block
STA FBSTRT+0 ; Update FBSTRT=>start of next block STA FBSTRT+0 ; Update FBSTRT=>start of next block
TAX ; X=>end of this block
LDA FBSTRT+1 LDA FBSTRT+1
STA A1H STA A1H
ADC WRITEPL+5 ADC WRITEPL+5
STA A2H
STA FBSTRT+1 STA FBSTRT+1
TAY
TXA
BNE :L2
DEY
:L2 DEX ; XY=XY-1, end address is start+len-1
STX A2L ; A2=>end of data buffer
STY A2H
* LDA OPENPL+5 ; File ref number
* STA WRITEPL+1
* LDA #$00 ; 512 byte request count
* STA WRITEPL+4
* LDA #$02
* STA WRITEPL+5
* LDX :BLOCKS
*:L2 CPX #$00 ; Adjust for subsequent blks
* BEQ :S1
* INC A1H
* INC A1H
* INC A2H
* INC A2H
* DEX
* BRA :L2
*
*:FWD1 BRA :CANTOPEN ; Forwarding call from above
*
*:S1 LDA :LENREM+1 ; MSB of length remaining
* CMP #$02
* BCS :S2 ; MSB of len >= 2 (not last)
* CMP #$00 ; If no bytes left ...
* BNE :S3
* LDA :LENREM
* BNE :S3
* BRA :NORMALEND
*
*:S3 LDA FBEND ; Adjust for last block
* STA A2L
* LDA FBEND+1
* STA A2H
* LDA :LENREM
* STA WRITEPL+4 ; Remaining bytes to write
* LDA :LENREM+1
* STA WRITEPL+5
*
:S2 LDA #<BLKBUF :S2 LDA #<BLKBUF
STA A4L STA A4L
LDA #>BLKBUF LDA #>BLKBUF
@ -869,91 +734,31 @@ SAVEFILE >>> ENTMAIN
CLC ; Aux -> Main CLC ; Aux -> Main
JSR AUXMOVE ; Copy data from aux to local buffer JSR AUXMOVE ; Copy data from aux to local buffer
LDA OPENPL+5 ; File ref number
STA WRITEPL+1
JSR WRTFILE ; Write the data JSR WRTFILE ; Write the data
BCS :WRITEERR BCS :WRITEERR
JMP :L1 ; Loop back for next block JMP :L1 ; Loop back for next block
:SAVEOK ; Enter here with A=$00
* BRA :UPDLEN :WRITEERR RTS
*
*:ENDLOOP INC :BLOCKS
* BRA :L1
*
*:UPDLEN SEC ; Update length remaining
* LDA :LENREM
* SBC WRITEPL+4
* STA :LENREM
* LDA :LENREM+1
* SBC WRITEPL+5
* STA :LENREM+1
* BRA :ENDLOOP
:CANTSAVE LDA #$5E ; Can't open/create
BRA :EXIT3 ; TO DO: Error=File too long
:SAVEOK ; Arrive here with A=$00
:WRITEERR PHA
LDA OPENPL+5 ; File ref num
STA CLSPL+1
JSR CLSFILE
PLA
BNE :EXIT2 ; Error returned
JSR UPDFB ; Update FILEBLK
JSR COPYFB ; Copy FILEBLK to aux mem
LDA #$01 ; Return A='File'
:EXIT2 CMP #$4E
BNE :EXIT3 ; Change 'Insuff. access'
LDA #$4F ; to 'Locked'
:EXIT3 >>> XF2AUX,OSFILERET
:LENREM DW $0000 ; Remaining length :LENREM DW $0000 ; Remaining length
* LDA #$5D ; Write error
* PLA
* BRA :EXIT2
*
*:NORMALEND LDA OPENPL+5 ; File ref num
* STA CLSPL+1
* JSR CLSFILE
* BCC :OK ; If close OK
* LDA #$5D ; Write error
* BRA :EXIT2
*:OK LDA #$01 ; Success ('File')
*:EXIT JSR UPDFB ; Update FILEBLK
* JSR COPYFB ; Copy FILEBLK to aux mem
*:EXIT2 CMP #$4E
* BNE :EXIT3 ; Change 'Insuff. access'
* LDA #$4F ; to 'Locked'
*:EXIT3 >>> XF2AUX,OSFILERET
*:BLOCKS DB $00
*:LENREM DW $0000 ; Remaining length
CREATEFILE LDA #$01 ; Storage type - file
CREATE
LDA #$01 ; Storage type - file
STA CREATEPL+7 STA CREATEPL+7
LDA #$06 ; Filetype BIN LDA #$06 ; Filetype BIN
STA CREATEPL+4
LDA #<MOSFILE CREATEOBJ STA CREATEPL+4 ; Type = BIN or DIR
STA OPENPL+1 STX CREATEPL+5 ; Auxtype = load address
LDA #>MOSFILE STY CREATEPL+6
STA OPENPL+2
LDA FBLOAD ; Auxtype = load address
STA CREATEPL+5
LDA FBLOAD+1
STA CREATEPL+6
LDA #$C3 ; Default permissions
STA CREATEPL+3
JMP CRTFILE JMP CRTFILE
* Update FILEBLK before returning to aux memory * Update FILEBLK before returning to aux memory
* Returns A=object type or ProDOS error * Returns A=object type or ProDOS error
UPDFB LDA #<MOSFILE UPDFB LDA #<MOSFILE
STA OPENPL+1 * STA OPENPL+1
STA GINFOPL+1 STA GINFOPL+1
LDA #>MOSFILE LDA #>MOSFILE
STA OPENPL+2 * STA OPENPL+2
STA GINFOPL+2 STA GINFOPL+2
JSR GETINFO ; Call GET_FILE_INFO JSR GETINFO ; Call GET_FILE_INFO
BCC :UPDFB1 BCC :UPDFB1
@ -1017,7 +822,7 @@ UPDFB LDA #<MOSFILE
STA FBATTR+2 STA FBATTR+2
STZ FBATTR+3 STZ FBATTR+3
JSR OPENFILE ; Open file JSR OPENMOSFILE ; Open file
BCS :ERR BCS :ERR
LDA OPENPL+5 ; File ref number LDA OPENPL+5 ; File ref number
STA GMARKPL+1 STA GMARKPL+1
@ -1299,9 +1104,3 @@ MAINRDMEM STA A1L
LDA (A1L) LDA (A1L)
MAINRDEXIT >>> XF2AUX,NULLRTS ; Back to an RTS MAINRDEXIT >>> XF2AUX,NULLRTS ; Back to an RTS