Code cleanup

This commit is contained in:
Bobbi Webber-Manners 2019-10-21 15:38:32 -04:00
parent a5c123725d
commit 05e5e40815
3 changed files with 25 additions and 64 deletions

View File

@ -800,7 +800,8 @@ F_OPEN CALL F_SFIRST
_F_OPEN LD IX,PATHBUF ; Destination buffer _F_OPEN LD IX,PATHBUF ; Destination buffer
CALL FCB2PATH ; Populate PATHLEN and PATH CALL FCB2PATH ; Populate PATHLEN and PATH
PUSH DE ; Preserve pointer to FCB PUSH DE ; Copy pointer to FCB ...
POP IY ; ... into IY
; Work out which IOBUF to allocate for this file ; Work out which IOBUF to allocate for this file
XOR A ; Looking for FRN slot with value 0 XOR A ; Looking for FRN slot with value 0
@ -818,16 +819,9 @@ _F_OPEN LD IX,PATHBUF ; Destination buffer
CP 0 ; See if there was an error CP 0 ; See if there was an error
JP NZ,FOERR ; Handle error JP NZ,FOERR ; Handle error
POP DE ; Restore pointer to FCB
; Store ProDOS FRN in S2 field of FCB ; Store ProDOS FRN in S2 field of FCB
LD A,(FOMLIN) ; Get ProDOS file reference number LD A,(FOMLIN) ; Get ProDOS file reference number
LD H,D ; Pointer to FCB ... LD (IY+0EH),A ; Store file reference number in S2 field
LD L,E ; ... into HL
LD BC,0EH ; Offset to S2 field (reserved field)
ADD HL,BC ; Compute address
LD (HL),A ; Store file reference number in S2 field
PUSH HL ; Keep pointer into FCB for later
; ProDOS GET_EOF call ; ProDOS GET_EOF call
; Assumes no files > 64K on ProDOS filesystem ; Assumes no files > 64K on ProDOS filesystem
@ -840,15 +834,11 @@ _F_OPEN LD IX,PATHBUF ; Destination buffer
CALL LEN2RECS ; Leaves number of records in A CALL LEN2RECS ; Leaves number of records in A
; Store records used ; Store records used
POP HL ; Recover pointer into FCB LD (IY+0FH),A ; Set records used field
INC HL ; Advance to records used (offset 0FH)
LD (HL),A ; Set records used
; Set sequential record number to zero ; Set sequential record number to zero
LD BC,20H-0FH ; Skip ahead to offset 20H - seq rec num
ADD HL,BC ; ...
XOR A ; Zero the sequential record number XOR A ; Zero the sequential record number
LD (HL),A ; ... LD (IY+20H),A ; ...
; Store ProDOS FRN in slot FRN1 - FRN4 ; Store ProDOS FRN in slot FRN1 - FRN4
LD A,(TEMPBYTE) ; Obtain IOBUF idx (1,2,3,4) LD A,(TEMPBYTE) ; Obtain IOBUF idx (1,2,3,4)
@ -863,8 +853,7 @@ _F_OPEN LD IX,PATHBUF ; Destination buffer
LD L,A ; Copy to L LD L,A ; Copy to L
RET ; Done RET ; Done
FOERR POP DE ; Restore the stack FOERR LD A,0FFH ; Error return status
LD A,0FFH ; Error return status
LD L,A ; Copy to L LD L,A ; Copy to L
RET ; Done (error) RET ; Done (error)
@ -896,12 +885,10 @@ F_CLOSE LD H,D ; Pointer to FCB ...
XOR A ; And zero it XOR A ; And zero it
LD (HL),A ; ... LD (HL),A ; ...
LD H,D ; Pointer to FCB ... PUSH DE ; Copy pointer to FCB ...
LD L,E ; ... into HL POP IX ; ... into IX
LD BC,0EH ; Offset to S2 field (reserved field)
ADD HL,BC ; Compute address
XOR A ; Zero out the S2 field XOR A ; Zero out the S2 field
LD (HL),A ; ... LD (IX+0EH),A ; ...
FCSUCC XOR A ; Return zero for error FCSUCC XOR A ; Return zero for error
LD L,A ; Return in L also LD L,A ; Return in L also
@ -1010,18 +997,13 @@ FDERR LD A,0FFH ; 0FFH for error
; Returns error codes in A and L: ; Returns error codes in A and L:
; 0 OK, 1 EOF, 9 invalid FCB, 10 media changed, 0FFH h/w error ; 0 OK, 1 EOF, 9 invalid FCB, 10 media changed, 0FFH h/w error
; TODO Handle multiple extents ; TODO Handle multiple extents
F_READ PUSH DE ; Preserve pointer to FCB F_READ PUSH DE ; Copy pointer to FCB ...
LD H,D ; Pointer to FCB ... POP IX ; ... into IX
LD L,E ; ... into HL LD A,(IX+0EH) ; Obtain file reference num from FCB S2
LD BC,0EH ; Offset to S2 field (reserved field)
ADD HL,BC ; Compute address
LD A,(HL) ; Obtain file reference num from FCB S2
LD (SMMLIN),A ; Store in parameter list for SET_MARK LD (SMMLIN),A ; Store in parameter list for SET_MARK
LD (FRMLIN),A ; Store in parameter list for READ LD (FRMLIN),A ; Store in parameter list for READ
LD BC,20H-0EH ; Skip ahead to seq record num in FCB LD A,(IX+20H) ; Obtain sequential record number
ADD HL,BC ; ...
LD A,(HL) ; Obtain sequential record number
CALL RECS2LEN ; Leaves the length in bytes in HL CALL RECS2LEN ; Leaves the length in bytes in HL
LD (SMMLIP1),HL ; Write 16 bit length in FRMLIP1,FRMLIP2 LD (SMMLIP1),HL ; Write 16 bit length in FRMLIP1,FRMLIP2
XOR A ; Set FRMLIP3 to zero XOR A ; Set FRMLIP3 to zero
@ -1048,26 +1030,18 @@ F_READ PUSH DE ; Preserve pointer to FCB
CP 0 ; See if there was some other error CP 0 ; See if there was some other error
JP NZ,FRERR ; If so, return code 0FFH (h/w error) JP NZ,FRERR ; If so, return code 0FFH (h/w error)
POP DE ; Get pointer to FCB back INC (IX+20H) ; Increment sequential record number
LD H,D ; Pointer to FCB ...
LD L,E ; ... into HL
LD BC,20H ; Advance to sequential rec number field
ADD HL,BC ; ...
INC (HL) ; Increment sequential record number
XOR A ; Zero for success XOR A ; Zero for success
LD L,A ; Return code in L also LD L,A ; Return code in L also
RET ; Done RET ; Done
FREOF POP DE ; Fix up stack FREOF LD A,1 ; EOF return code
LD A,1 ; EOF return code
LD L,A ; Return code in L also LD L,A ; Return code in L also
RET ; Done (EOF) RET ; Done (EOF)
FRBFCB POP DE ; Fix up stack FRBFCB LD A,9 ; Invalid FCB return code
LD A,9 ; Invalid FCB return code
LD L,A ; Return code in L also LD L,A ; Return code in L also
RET ; Done (Bad FCB) RET ; Done (Bad FCB)
FRERR POP DE ; Fix up stack FRERR LD A,0FFH ; All other errors are 0FFH
LD A,0FFH ; All other errors are 0FFH
LD L,A ; Return code in L aslo LD L,A ; Return code in L aslo
RET ; Done (error) RET ; Done (error)
@ -1076,18 +1050,13 @@ FRERR POP DE ; Fix up stack
; Returns error codes in A and L: ; Returns error codes in A and L:
; 0 OK, 1 dir full, 2 disk full, 9 invalid FCB, 10 media changed, 0FFH h/w error ; 0 OK, 1 dir full, 2 disk full, 9 invalid FCB, 10 media changed, 0FFH h/w error
; TODO Handle multiple extents ; TODO Handle multiple extents
F_WRITE PUSH DE ; Preserve pointer to FCB F_WRITE PUSH DE ; Copy pointer to FCB ...
LD H,D ; Pointer to FCB ... POP IX ; ... into IX
LD L,E ; ... into HL LD A,(IX+0EH) ; Obtain file reference num from FCB S2
LD BC,0EH ; Offset to S2 field (reserved field)
ADD HL,BC ; Compute address
LD A,(HL) ; Obtain file reference num from FCB S2
LD (SMMLIN),A ; Store in parameter list for SET_MARK LD (SMMLIN),A ; Store in parameter list for SET_MARK
LD (FWMLIN),A ; Store in parameter list for WRITE LD (FWMLIN),A ; Store in parameter list for WRITE
LD BC,20H-0EH ; Skip ahead to seq record num in FCB LD A,(IX+20H) ; Obtain sequential record number
ADD HL,BC ; ...
LD A,(HL) ; Obtain sequential record number
CALL RECS2LEN ; Leaves the length in bytes in HL CALL RECS2LEN ; Leaves the length in bytes in HL
;; ; DEBUG ;; ; DEBUG
@ -1125,26 +1094,18 @@ F_WRITE PUSH DE ; Preserve pointer to FCB
CP 0 ; See if there was some other error CP 0 ; See if there was some other error
JP NZ,FWERR ; If so, return code 0FFH (h/w error) JP NZ,FWERR ; If so, return code 0FFH (h/w error)
POP DE ; Get pointer to FCB back INC (IX+20H) ; Increment sequential record number
LD H,D ; Pointer to FCB ...
LD L,E ; ... into HL
LD BC,20H ; Advance to sequential rec number field
ADD HL,BC ; ...
INC (HL) ; Increment sequential record number
XOR A ; Zero for success XOR A ; Zero for success
LD L,A ; Return code in L also LD L,A ; Return code in L also
RET ; Done RET ; Done
FWBFCB POP DE ; Clean up the stack FWBFCB LD A,9 ; Invalid FCB return code
LD A,9 ; Invalid FCB return code
LD L,A ; Return code in L also LD L,A ; Return code in L also
RET ; Done (EOF) RET ; Done (EOF)
FWDF POP DE ; Clean up the stack FWDF LD A,2 ; Disk full return code
LD A,2 ; Disk full return code
LD L,A ; Return code in L also LD L,A ; Return code in L also
RET ; Done (Disk Full) RET ; Done (Disk Full)
FWERR POP DE ; Clean up the stack FWERR LD A,0FFH ; All other errors are 0FFH
LD A,0FFH ; All other errors are 0FFH
LD L,A ; Return code in L aslo LD L,A ; Return code in L aslo
RET ; Done (error) RET ; Done (error)

Binary file not shown.

Binary file not shown.