Updates to run6502 file modules and test programs

This commit is contained in:
Curtis F Kaylor 2020-10-14 10:59:25 -04:00
parent 1cc2caa794
commit 4c27db63ee
12 changed files with 368 additions and 187 deletions

View File

@ -4,27 +4,33 @@
SUBROUTINE DIRECT
TOPDIR BYTE "/",0 ;Root Directory
UPDIR BYTE "..",0 ;Parent Directory
;getcwd(drv, &dir) - Get Current Directory
;Args: A = Drive Identifier
; Y,X = Pointer to String
;Returns: A = Result (0 = Success, $FF = Failure)
;Returns: A = Length of Directory Name
; Y = Error Code (0 = None)
GETCWD: JSR FSDRVN ;Convert Drive Letter to Drive Number
BCS .DRVERR ;If Invalid Return Error
LDA #'T' ;Set Command to GETCWD
GETCWD: JSR FSADDR ;Set String Buffer Address
TAY ;Set Drive ID
CLC ;Set Mode to GETCWD
LDA #'U' ;Set Command to GETSETDIR
.FSCMDX JSR FSCMD ;Execute Command
TXA ;Return Length of Name
.DRVERR RTS
RTS
;chdir(drv, &dir) - Get Current Directory
;chdir(drv, &dir) - Set Current Directory
;Args: A = Drive Identifier
; Y,X = Pointer to String
;Returns: A = Result (0 = Succes, $FF = Failure)
; Y = Error Code (0 = None)
CHDIR: JSR FSDRVN ;Convert Drive Letter to Drive Number
BCS .DRVERR ;If Invalid Return Error
LDA #'U' ;Set Command to GETCWD
BNE .FSCMDX ;Execute Command and Return Result
;Returns: A = Error Code (0 = None)
CHDIR: JSR FSNAME ;Set Directory Name
TAY ;Set Drive ID
SEC ;Set Mode to CHDIR
LDA #'U' ;Set Command to GETSETDIR
.FSCMDY JSR FSCMD ;Execute Command
TYA ;Return Length of Name
RTS
;rmdir(drv, &dir) - Create Directory
;Args: A = Drive Identifier
@ -38,12 +44,7 @@ RMDIR: SEC ;Set Mode to RMDIR
; Y,X = Address of Directory Name String
;Returns: A = Error Code (0 = None)
MKDIR: CLC ;Set Mode to MKDIR
.MRDIR PHP ;Save Status Register
JSR FSDRVN ;Convert Drive Letter to Drive Number
BCS .DRVERR ;If Invalid Return Error
PLP ;Restore Status Register
.MRDIR JSR FSNAME ;Set Directory Name
TAY ;Set Drive ID
LDA #'X' ;Set Command to MKRMDIR
BNE .FSCMDX ;Execute Command and Return Result
.PLAERR PLP ;Restore Status Register
RTS ;and Return
BNE .FSCMDY ;Execute Command and Return Result

View File

@ -4,16 +4,18 @@
* Requires fileio.h02 *
******************************************/
const char topdir[]; //Root Directory Relative Path
const char updir[]; //Parent Directory Relative Path
/* Change Directory *
* Args: drv - Drive/Disk Identifier *
* &dir - Directory Name *
* Returns: char r - Result, 0=Success *
* char e - Error, 0=None */
* Returns: char e - Error, 0=None */
char chdir();
/* Get Current Working Directory *
* Args: drv - Drive/Disk Identifier *
* &dir - Directory Name *
* &dir - Directory String *
* Returns: char n - Length of Name *
* 0 = None or Error *
* char e - Error, 0=None */
@ -22,8 +24,7 @@ char getcwd();
/* Make Directory *
* Args: drv - Drive/Disk Identifier *
* &dir - Directory Name *
* Returns: char r - Result, 0=Success *
* char e - Error, 0=None */
* Returns: char e - Error, 0=None */
char mkdir();
/* Remove Directory *

View File

@ -2,6 +2,8 @@
; This is the reference implementation of the dirent module
; Requires external functions FSADDR, FSCMD, and FSDRVN (fileio.h02)
ATTRD BYTE "AHRDS" ;File Attribute Descriptions
SUBROUTINE DIRENT
;opndir() - Open Directory for Reading
@ -9,9 +11,10 @@
; Y,X = Pointer to Directory Name
;Returns: A = File Pointer (0 = Not Opened)
; Y = Error Code (0 = None)
OPNDIR: JSR FSDRVN ;Convert Drive Letter to Drive Number
BCS .OPNERR ;If Invalid Return Error
LDA #'D' ;Set Command to OPENDIR
OPNDIR: JSR FSNAME ;Set File Name
TAY ;Set Drive Letter
SEC ;Set Mode to OPENDIR
LDA #'O' ;Set Command to OPEN
.FSCMDX JSR FSCMD ;Execute Command
TXA ;Return Channel
RTS
@ -36,14 +39,15 @@ RDHDR: SEC ;Set Mode to HEADER
RDDIR: CLC ;Set Mode to ENTRY
.RDDIR JSR FSADDR ;Save Address
TAY ;Set Channel
LDA #'J' ;Set Command to READDIR
LDA #'D' ;Set Command to READDIR
BNE .FSCMDX ;Execute and Return Result
;clsdir() - Close Directory File
;Args: A = Directory File Pointer
;Returns: A = Error Code (0 = Success)
CLSDIR: TAY ;Set Channel
LDA #'B' ;Set Command to CLOSEDIR
SEC ;Set Mode to CLOSEDIR
LDA #'C' ;Set Command to CLOSE
JSR FSCMD ;Execute Command
TYA ;and Return Error Code
RTS

View File

@ -2,9 +2,20 @@
* dirent - Directory Entries Module for run6502 emulator *
**********************************************************/
/* File Attributes */
struct attrs {char arch, hidden, rdonly, subdir, system;};
const char attrd[]; //Single Character Descriptions
/* Timestamp - Matches module time.h02 structure tm */
struct ts {char year, month, day, hour, minute, second;};
/* Directory Entry */
struct dirent {
char name[128]; //Entry Filename
struct attrs attr; //File Attributes
struct ts time; //Timestamp
int size; //Size in Bytes
char name[128]; //Entry Filename
};
/* Directory Header */

View File

@ -1,11 +1,14 @@
; C02 Module fileio Assembly Language Eoutines for run6502 emulator
; This is the reference implementation of the fileo module
; The run6502 program has been customized with an emulated file
; routine at the address set with the -F command line option
; The file routine is JSRed with the command code in A, and any
; parameters in Y and/or X. After command execution. Y and/or X
; will contain any return values. Y is usually the error code.
; The run6502 program has been customized with an emulated file command
; routine at the address set with the -F command line option.
; The file routine is JSRed with the command in A, and any parameters
; in Y and/or X. After command execution. Y and/or X will contain any
; return values, with Y is usually the error code.
;
; The Command Routine FSCMD is defines in file include/run6502.a02
SUBROUTINE FILEIO
@ -16,43 +19,63 @@ DISKS EQU 1 ;Number of Disks in Drive
DISK BYTE 0
;File Open Modes
MREAD EQU $00
MWRITE EQU $80
MREAD EQU $00 ;Open for Read
MWRITE EQU $40 ;Open for Write
MAPPND EQU $80 ;Open for Append
MRECRD EQU $C0 ;Record Oriented File
;File Open Types
TTEXT EQU $00 ;Open as Texy File
TBNRY EQU $20 ;Open as Binary File
; File Load Modes
MRELCT EQU $00 ;Relocate (Load at Specified Address)
MABSLT EQU $80 ;Absolute (Load at Address in File Header)
;ferror(chan, &msg) - Check for Error
;Args: A = Channel Number
; Y,X = String Address
;Returns: A = Last Error ($FF - Invalid Channel)
; Y = Error (0=None)
FERROR: JSR FSADDR ;Set Buffer Address
TAY ;Set Channel Number
LDA #'Y' ;Set Command to FERROR
BNE .FEXECX ;Execute and Return Result in A
;fflush(chan) - Flush Write Buffer to File
;Args: A = Channel
;Returns: A = Error (0=None)
;Returns: A = Status (0=Success, $FF = Failure)
; Y = Error (0=None)
FFLUSH: TAY ;Set Channel Number
LDA #'F' ;Set Command to FLUSH
BNE .FEXECX ;Execute and Return Result in A
.FEXEC JSR FSCMD ;Execute Command
TYA ;Return Error Code
;fopen(mode, &name) - Open File
;Args: A = Mode + Drive ID
;Setup: Call FSRECS with Record Size if Mode is MRECRD
;Args: A = File Mode | Drive ID
; Y,X = Pointer to File Name
;Returns: A = File Channel (0=File Not Opened)
; Y = Error (0=None)
FOPEN: JSR FSNAME ;Set Filename
TAX ;Pass Mode to X
.FOPEN TAX ;Pass File Mode to X
JSR FSDRVN ;Convert Drive Letter to Drive Number
BCS .RETURN ;If Error, Return Carry Set
BCS .FOPERR ;If Error, Return Carry Set
TAY ;Pass Drive Number in Y
CLC ;Set Mode to FOPEN
LDA #'O' ;Set Command to OPEN
.FEXECX JSR FSCMD ;Execute Command
TXA ;Return Channel in A
RTS
.FOPERR RTS
;fclose(chan) - Close File
;Args: A = Channel Number
;Returns: A = Error (0=None)
FCLOSE: TAY ;Set Channel
CLC ;Set Mode to FCLOSE
LDA #'C' ;Set Command to CLOSE
BNE .FEXEC ;Execute and Return Error in A
.FEXECY JSR FSCMD ;Execute Command
TYA ;Return Errno
RTS
;feof(chan) - Check for End of File
;Args: A = Channel Number
@ -61,7 +84,8 @@ FCLOSE: TAY ;Set Channel
; Otherwise, Error Code
FEOF: TAY ;Set Channel
LDA #'E' ;Set Command to EOF
BNE .FEXEC ;Execute and Return Error in A
BNE .FEXECY ;Execute and Return Errno
;fgetc(chan) - Read Character from File
;Args: A = Channel Number
@ -69,7 +93,7 @@ FEOF: TAY ;Set Channel
; Y = Error Code ($00 - Success)
FGETC: TAY ;Set Channel
LDA #'G' ;Set Command to GET
BNE .FEXECX ;Execute and Return Result in A
BNE .FEXECX ;Execute and Return Result
;fgets(chan, &s) - Read String from File
;Args: A = Channel Number
@ -81,13 +105,34 @@ FGETS: JSR FSADDR ;Set String Address
LDA #'H' ;Set Command to GETS
BNE .FEXECX ;Execute and Return Result in A
;fgetr(chan, recno) - Read Record from File
;Setup: Call FSADDR with buffer address
;Args: A = Channel Number
; Y,X = Record Number
;Returns: A = Error Code
; Y,X = Next Record Number
FGETR: JSR FSINDX ;Set Record Number
TAY ;Set Channel Number
SEC ;Set Mode to RECORD
LDA #'R' ;Set Command to READ
BNE .FSCMD ;Execute Command and Return
;fgetw(chan) - Read Word from File
;Args: A = Channel Number
;Returns: A = Error Code ($00 - Success)
; Y,X = Word
FGETW: TAY ;Set Channel
CLC ;Set Mode to Get
LDA #'J' ;Set Command to GET
BNE .FSCMD ;Execute Command and Return
;fputc(chan, char) - Write Character to File
;Args: A = Character to Write
; Y = Channel Number
;Returns: A = Error Code ($00 - Success)
FPUTC: TAX ;Set Character to Write
LDA #'P' ;Set Command to PUT
BNE .FEXEC ;Execute and Return Error in A
BNE .FEXECX ;Execute and Return Result in A
;fputln(chan, &s) - Write String to File with Newline
;Args: A = Channel Number
@ -97,6 +142,18 @@ FPUTC: TAX ;Set Character to Write
FPUTLN: SEC ;Append Newline
BCS .FPUTSA ;Write String to File
;fputr(chan, recno) - Write Record from File
;Setup: Call FSADDR with buffer address
;Args: A = Channel Number
; Y,X = Record Number
;Returns: A = Error Code
; Y,X = Next Record Number
FPUTR: JSR FSINDX ;Set Record Number
TAY ;Set Channel Number
SEC ;Set Mode to RECORD
LDA #'W' ;Set Command to READ
BNE .FSCMD ;Execute Command and Return
;fputs(chan, &s) - Write String to File
;Args: A = Channel Number
; Y,X = Address of String
@ -108,17 +165,54 @@ FPUTS: CLC ;Do Not Append Newline
LDA #'Q' ;Set Command to PUTS
BNE .FEXECX ;Execute and Return Result in A
;fread(chan, count) - Read Bytes from File
;fputw(chan, word) - Write Word to File
;Args: A = Channel Number
; Y,X = Word
;Returns: A = Error Code ($00 - Success)
FPUTW: JSR FSADDR ;Set File Buffer Address
TAY ;Set Channel
SEC ;Set Mode to PUT
LDA #'J' ;Set Command to WORD
BNE .FEXECY ;Execute and Return Result in A
;fread(count, chan) - Read Bytes from File
;Setup: Call FSADDR with array address
;Args: A = Number of Bytes to Read
; Y = Channel Number
;Returns: A = Number of Bytes Read
; Y = Error Code ($00 - Success)
FREAD: TAX ;Set Number of Bytes to Write
LDA #'R' ;Set Command to READ
BNE .FEXECX ;Execute and Return Result in A
FREAD: TAX ;Set Number of Bytes to Write
CLC ;Set Mode to BYTES
LDA #'R' ;Set Command to READ
BNE .FEXECX ;Execute and Return Result in A
;fwrite(chan, count) - Write Bytes to File
;rewind(chan) - Move to Beginning of File
;Args: A = Channel Number
;Returns: A = Error Code ($00 - Success)
REWIND: LDX #0 ;Set Position to $0000
LDY #0 ;and Fall Through to FSEEK
;fseek(chan, pos) - Move to Position in File
;Args: A = Channel Number
; Y,X = Position
;Returns: A = Error Code ($00 = Success)
FSEEK: JSR FSINDX ;Set File Index to Position`
TAY ;Set Channel to A
CLC ;Set Mode to SEEK
LDA #'Z' ;Set Command to SEEK
BNE .FEXECY ;Execute and Return Errno
;ftell(chan, pos) - Get Position in File
;Args: A = Channel Number
;Returns: A = Error Code ($00 = Success)
; Y,X = Position in File ($FFFF = Failure)
FTELL: JSR FSADDR ;Set File Address to Position`
TAY ;Set Channel to A
SEC ;Set Mode to TELL
LDA #'Z' ;Set Command to SEEK
BNE .FSCMD ;Execute Command and Return
;fwrite(count cban) - Write Bytes to File
;Setup: Call FSADDR with array address
;Args: A = Number of Bytes to Write
; Y = Channel Number
@ -138,7 +232,7 @@ FWRITE: TAX ;Set Number of Bytes to Write
FLOAD: CMP #MABSLT ;Check Load Mode
BNE .ERR22 ;If Invalid, Return Error
LDA #'L' ;Set Command to LOAD
JMP FSCMD ;Execute Command and Return
BNE .FSCMD ;Execute Command and Return
.ERR22 LDA #22
RTS
@ -153,16 +247,6 @@ FSAVE: ORA $0 ;If Not Drive 0
LDA #'S' ;Set Command to SAVE
BNE .FSCMD ;Execute Command and Return
;ferror(chan, &msg) - Check for Error
;Args: A = Channel Number
; Y,X = String Address
;Returns: A = Last Error ($FF - Invalid Channel)
; Y = Error (0=None)
FERROR: JSR FSADDR ;Set Buffer Address
TAY ;Set Channel Number
LDA #'Y' ;Set Command to FERROR
BNE .FEXECX ;Execute and Return Result in A
;File System Commands
;Convert Drive Letter Into Drive Number
@ -189,58 +273,77 @@ FSDRVN: SEC
FSINIT: LDA #'I' ;Set Command to INITFS
.FSCMD JMP FSCMD ;Execute Command and Return
;fsrecs(size) - Set File Record Size
;Args: A = Size
FSRECS: TAX ;Set Y.X to 0,A
LDY #0 ;and Fall The to FSINDX
;fsindx(&array) - Set File Record Number
;Args: Y,X = Record Number
FSINDX: PHP ;Save Status Register
PHA ;Save Accumulator
SEC ;Set Mode to FILEINDX
BCS .FSADDR ;Execute ADDRESS and Restore Accumulator
;fsaddr(&array) - Set File Buffer Address
;Emulation: sets internal variable filebuff
;Args: Y,X = Address of String or Array
FSADDR: PHA ;Save Accumulator
LDA #'A' ;Set Command to ADDRESS
BNE .FSCMDA ;Execute and Restore Accumulator
;fsname(&name) - Set File Name
;Emulation: sets internal variable filename
;Args: Y,X = Address of Filename
FSNAME: PHA ;Save Accumulator
LDA #'N' ;Set command to name
.FSCMDA JSR FSCMD ;Execute command
FSADDR: PHP ;Save Status Register
PHA ;Save Accumulator
CLC ;Set mode to FILEADDR
.FSADDR LDA #'A' ;Set Command to ADDRESS
JSR FSCMD ;Execute command
PLA ;Restore Accumulator
PLP ;Restore Status Register
RTS
;fscmd(cmd, args) - File I/O Command Processor
;Args: A = Command Code
; Y,X = Arguments(s)
;Returns: A = Command Code (usually)
; Y = Error Code (usually)
; X = Result (when applicable)
FSCMD: EQU $FFE6 ;run6502 File I/O Command Routine
;fsbuff(&name) - Set File Buffer
;Args: Y,X = Address of String
FSBUFF: PHA ;Save Accumulator
PHP ;Save Status Register
SEC ;Set Mode to FILEBUFF
BCS .SETNAM ;Execute Command 'N' and Return
;fsname(&name) - Set File Name
;Args: Y,X = Address of Filename
FSNAME: PHA ;Save Accumulator
PHP ;Save Status Register
CLC ;Set Mode to FILENAME
.SETNAM LDA #'N' ;Set command to name
.FSCMDA JSR FSCMD ;Execute command
PLP ;Restore Status Register
PLA ;Restore Accumulator
RTS
; Command Description Arguments Requires Returns
; FSADDR Set Buffer Address A='A', YX=Addr YX=Addr
; CLOSEDIR Close Directory A='B', Y=Chan Y=Err
; FCLOSE Close File A='C', Y=Chan Y=Err
; OPENDIR Open Directory A='D', YX=Name Y=Err, X=Chan
; FEOF Check for EOF A="E'. Y=Chan Y=Err ($FF=EOF)
; FFLUSH Flush Output A='F', Y=Chan Y=Err
; FGETC Get Character A='G', Y=Chan Y=Err, X=Char
; FGETS Get String A='H', Y=Chan # Y=Err
; FSINIT Init File System A='I'
; READDIR Read Dir Entry A='J', Y=Chan # Y=Err
; REMOVE Remove File A='K', YX=Name Y=Err
; FLOAD Load File A='L' * A=Err, YX=End
; RENAME Rename File A='M', YX=New + Y=Err
; FSNAME Set Filename A='N', YX=Name
; FOPEN Open File A='O', Y=Mode + Y=Err
; FPUTC Put Character A='P', Y=Chan, X=Char Y=Err
; FPUTS Put String A='Q', Y=Chan # Y=Err
; FREAD Read Bytes A='R', Y=Chan, X=Count # Y=Err, X=Count
; FSAVE Save File A='S', Y=Chan, YX=End * Y=Err
; GETCWD Get Current Dir A='T', Y=Chan, YX=Addr Y=Err, X=Len
; CHDIR Change Directory A='U', YX=Name Y=Err
; GCDRIVE Get/Set Cur Drive A='V', Y=Drive, C=Mode Y=Err, X=Result
; FWRITE Write Bytes A='W', Y=Chan, X=Count # Y=Err, X=Count
; MKRMDIR Create/Remove Dir A='X', YX=Name, C=Mode Y=Err, X=Result
; FERROR Get Last Error A='Y', Y=Chan # Y=Err
; Command Description Arguments Returns
; FSADDR Set Buffer Address A='A',YX=Addr YX=Addr
; FCLOSE Close File A='C',Y=Chan,CC Y=Err
; CLOSEDIR Close Directory A='C',Y=Chan,CS Y=Err
; READDIR Read Dir Entry A='D',Y=Chan (1) Y=Err
; FEOF Check for EOF A="E',Y=Chan Y=Err ($FF=EOF)
; FFLUSH Flush Output A='F',Y=Chan Y=Err
; FGETC Get Character A='G',Y=Chan Y=Err, X=Char
; FGETS Get String A='H',Y=Chan (1) Y=Err
; FSINIT Init File System A='I',
; REMOVE Remove File A='K',YX=Name Err
; FLOAD Load File A='L' (3) A=Err, YX=End
; RENAME Rename File A='M',YX=New (2) Y=Err
; FSNAME Set Filename A='N',YX=Name,CC
; FOPEN Open File A='O',Y=Mode|Drive,CC (2) Y=Err, X=Chan
; OPENDIR Open Directory A='O',Y=Drive,CS (2) Y=Err, X=Chan
; FPUTC Put Character A='P',Y=Chan,X=Char Y=Err, X=Char
; FPUTS Put String A='Q',Y=Chan (1) Y=Err
; FREAD Read Bytes A='R',Y=Chan,X=Count (1) Y=Err, X=Count
; FSAVE Save File A='S',Y=Chan,YX=End (3) Y=Err
; GETCWD Get Current Dir A='U',Y=Drive (1) Y=Err, X=Len
; CHDIR Change Directory A='U',Y=Drive (2) Y=Err
; GETDRV Get Current Drive A='V',CC Y=Err, X=Result
; CHDRV Set Current Drive A='V',Y=Drive,CS Y=Err, X=Result
; FWRITE Write Bytes A='W',Y=Chan, X=Count (1) Y=Err, X=Count
; MKDIR Create Directory A='X',Y=Drive,CC (2) Y=Err, X=Result
; RMDIR Remove Directory A='X',Y=Drive,CS (2) Y=Err, X=Result
; FERROR Get Last Error A='Y',Y=Chan (1) Y=Err
; # Requires call to FSADDR
; + Requires call to FSNAMR
; * Requires calls to FSADDR and FSNAME
; (1) Requires call to FSADDR
; (2) Requires call to FSNAME (and FSINDX for FOPEN w/MRECRD)
; (3) Requires calls to FSADDR and FSNAME

View File

@ -10,7 +10,13 @@ const char disk[];
/* File Open Modes */
#define MREAD $00 //Open File for Read
#define MWRITE $80 //Open File for Write
#define MWRITE $40 //Open File for Write
#define MAPPND $80 //Open File for Append
#define MRECRD $C0 //Open File to Read/Write Records
/* File Open Types */
#define TTEXT $00 //Text File
#define TBNRY $20 //Binary File
/* File Load Modes */
#define MRELCT $00 //Relocate (Load at Specified Address)
@ -42,12 +48,13 @@ char ferror();
/* File Flush *
* Flush File Output Buffer *
* Args: char f - File Channel *
* Returns: char e - Error (0=None) */
* Returns: char status (0=Succes) *
* char e - Error (0=None) */
char fflush();
/* File Get Character *
* Args: char f - File Channel *
* Read Character from Fie *
* Read Character from File *
* Returns: char c - Character *
* char e - Error (0=None) */
char fgetc();
@ -61,6 +68,13 @@ char fgetc();
* char e - Error (0=None) */
char fgets();
/* File Get Word *
* Args: char f - File Channel *
* Read Integer from File *
* Returns: char e - Error (0=None) *
* int w - Word */
char fgetc();
/* File Load *
* Loads File into Memory *
* Setup: fsname(&filename) *
@ -78,11 +92,12 @@ char fload();
char e - Error (0=None) */
char fopen();
/* File Put Character *
* Write Character to File *
* Args: char c - Character *
* char f - File Channel *
* Returns: char e - Error (0=None) */
/* File Put Character *
* Write Character to File *
* Args: char c - Character *
* char f - File Channel *
* Returns: char w - Character Written *
* char e - Error (0=None) */
char fputc();
/* File Put Line *
@ -103,6 +118,15 @@ char fputln();
* char e - Error (0=None) */
char fputs();
/* File Put Word *
* Writes up to 128 characters *
* of string to file *
* Args: char f - File Channel *
* int w - Word to Write *
* Returns: char e - Error (255=EOF) *
* int r - Word Written */
char fputw();
/* File Read *
* Read up to n bytes from file *
* Setup: fsaddr(&array) *
@ -135,6 +159,13 @@ char fsave();
* char res - Result */
char fscmd();
/* File Seek *
* Move to Position in File *
* Args: char f - File Channel *
* int p - Position in File *
* Returns: char e - Error (0=None) */
char fseek();
/* File System Init *
* Initialize File System */
char fsinit();
@ -144,6 +175,14 @@ char fsinit();
* Args: int &name - Filename */
char fsname();
/* File Tell *
* Get Position in File *
* Args: char f - File Channel *
* Returns: char e - Error (0=None) *
* int r - Position *
* $FFFF = Failure */
char ftell();
/* File Write *
* Write n nytes to file *
* Setup: fsaddr(&array) *
@ -152,3 +191,9 @@ char fsinit();
* Returns: char n - Bytes Written *
* char e - Error (0=None) */
char fwrite();
/* Rewind file *
* Move to Beginning of File *
* Args: char f - File Channel *
* Returns: char e - Error (0=None) */
char rewind();

View File

@ -9,23 +9,23 @@
;Args: A = Drive Identifier
; Y,X = Address of Directory Name String
;Returns: A = Error Code (0 = None)
REMOVE: JSR FSDRVN ;Validate Drive Number
BCS .RETURN ;If Invalid Return Error
REMOVE: JSR FSNAME ;Set File Buffer to New Name
TAY ;Set Drive ID
LDA #'K' ;Set Command to KILL (REMOVE)
.FSCMDX JSR FSCMD ;Execute Command
TXA ;Return Result
.FEXECY JSR FSCMD ;Execute Command
TYA ;Return Errno
RTS
;rename(drv, &filnam) - Rename File to filnam
;rename(drv, &new) - Rename File to filnam
;Setup: Call FSNAME with Address of Old Name
;Args: A = Drive Identifier
; Y,X = Address of Directory Name String
; Y,X = Address of New Name
;Returns: A = Error Code (0 = None)
RENAME: JSR FSDRVN ;Convert Drive Letter to Drive Number
BCS .RETURN ;If Invalid Return Error
RENAME: JSR FSBUFF ;Set File Buffer to New Name
TAY ;Set Drive ID
LDA #'M' ;Set Command to KILL (REMOVE)
BNE .FSCMDX ;Execute Command and Return Result
BNE .FEXECY ;Execute Command and Return Errno
;inidrv(drv) - Initialize Disk Drive
;Args: A = Drive Identifier
;Returns: A = Error Code (0 = None)
@ -34,14 +34,13 @@ INIDRV: LDA #$FF ;Return Error - Not Implemented
;chdrv() - Set Current Drive/Disk
;Args: A = Drive# | Disk#
;Returns: A = Result (0 - Success)
; Y = Error Code (0 = None)
;Returns: Y = Error Code (0 = None)
CHDRV: JSR FSDRVN ;Validate Drive Number
BCS .RETURN ;If Invalid Return Error
TAY ;Set Drive Number
SEC ;Set Mode to Change
LDA #'V' ;Set Command to DRIVE
BNE .FSCMDX ;Execute Command and Return Result
BNE .FEXECY ;Execute Command and Return Errno
;getdrv() - Get Current Drive/Disk
;Returns: A = Drive# | Disk# (0=Failure)

View File

@ -22,9 +22,8 @@ char getdrv();
char remove();
/* Rename File *
* Setup: fsname(&o) - Old File Name *
* Args: char d - Drive ID | Disk # *
* int &n - New File Name *
* Returns: char r - Result, 0=Success *
* char e - Error, 0=None */
* Setup: fsname(&old) - Old File Name *
* Args: char drv - Drive ID | Disk # *
* int &new - New File Name *
* Returns: char e - Error, 0=None */
char rename();

View File

@ -13,7 +13,6 @@
#include <fileio.h02>
#include <direct.h02>
const char dir = "TEMPDIR";
char d, err, i, n, r;
char m[128], s[128];
@ -30,29 +29,30 @@ void prtcwd() {
putln(&s);
}
void chkerr() {
void chkerr(aa) {
if (err) {
printf(err, "ERROR %d - ");
ferror(0, m); putln(m);
if (aa and aa<>err) goto exit;
}
else if (r) putln("FAILED");
else putln("SUCCESS");
}
void chgdir(aa, yy, xx) {
setdst(); printf("CHDIR '%s': ");
n, err = chdir(0,yy,xx); chkerr();
setdst(); printf("CHDIR(0,\"%s\"): ");
err = chdir(0,yy,xx); chkerr(0);
prtcwd();
}
void mrdir() {
setdst(&dir); printf("MKDIR(\"%s\"): ");
r,err = mkdir(&dir); chkerr();
setdst(&dir); printf("MKDIR(0, \"%s\"): ");
err = mkdir(0, &dir); chkerr(17);
chgdir(&dir);
anykey();
chgdir("..");
chgdir(updir);
setdst(&dir); printf("RMDIR(\"%s\"): ");
r,err = rmdir(&dir); chkerr();
err = rmdir(0, &dir); chkerr(0);
}
error:

View File

@ -13,41 +13,60 @@
#include <string.h02>
#include <fileio.h02>
#include <dirent.h02>
#include <time.h02>
struct dirent entry;
struct dirhdr header;
struct tm time;
const char dir = "";
char dp; //Directory File Pointer
char err; //Error Code
char c; //Character read from Struct
char i; //Loop Index Variable
char n; //Number of Characters Read
char m[128], s[128];
char wrdlo,wrdhi;
const char drv = 0; //Drive ID (Current Drive)
const char dir = ""; //Directory Name (Current Directory)
char dp; //Directory File Pointer
char err; //Error Code
char c; //Character read from Struct
char i; //Loop Index Variable
char n; //Number of Characters Read
char m[128], s[128], t[128]; //String Buffers
int dircnt,filcnt; //Directories and File Count
char aa,ff,xx,yy,zz; //Function Arguments
/* Print Entry Time Stamp */
void prtts() {setdst(t); asctm(#FLONG|#FAMPM, entry.time); puts(t);}
/* Print Directory Entry */
void prtent() {
if (entry.attr.subdir) dircnt++; else filcnt++;
if (@entry.time > 1) {prtts(); puts(" ");}
for (i=0; i<@entry.attr; i++) {if (entry.attr[i]) putc(attrd[i]); else putspc();}
setdst(entry.size); printf(" %j "); putln(entry.name);
}
/* Print Directory Summary */
void prtsum() {
setdst(filcnt); printf(" %j FILES(S)%n");
setdst(dircnt); printf(" %j DIR(S)%n");
}
main:
filcnt = &0; dircnt = &0;
setdst(dir); printf("OPENING DIRECTORY '%s'%n");
dp, err = opndir(0, dir);
if (err) goto error;
dp, err = opndir(drv, dir); if (err) goto error;
printf(dp, "CHANNEL=%d%n");
putln("READING HEADER");
n, err = rdhdr(dp, header);
if (err) goto error;
if (n) putln(header.name);
else putln("NO HEADER");
n, err = rdhdr(dp, header); if (err) goto error;
if (n) putln(header.name); else putln("NO HEADER");
putln("READING ENTRIES");
do {
n, err = rddir(dp, entry);
if (n) putln(entry.name);
if (n) prtent();
} while (n);
if (err) goto error;
putln("END OF DIRECTORY");
prtsum();
//putln("END OF DIRECTORY");
clsdir(dp);
err = clsdir(dp); if (err) goto err;
goto exit;
error:

View File

@ -48,7 +48,7 @@ main:
sfile(0, &savfil);
fp = opnfil(#MREAD, &txtfil);
else printf(n, " READ $%x CHARACTERS%n");
else printf(n, " READ %d CHARACTERS%n");
if (fp) {
rstrng(fp);
rbnry(fp);
@ -68,13 +68,13 @@ main:
void chkerr() {
if (err) {
printf(err, " ERROR $%x%n");
printf(err, " ERROR %d%n");
goto exit;
}
}
void flshfl(aa) {
printf(aa, "FFLUSH($%x): ");
printf(aa, "FFLUSH(%d): ");
zz, err = fflush(aa); chkerr();
puts("FLUSHED, "); anykey(0);
}
@ -82,34 +82,34 @@ void flshfl(aa) {
void opnfil(aa,yy,xx) {
setdst();printf("FOPEN($%x,\"%s\"): ");
zz, err = fopen(aa,yy,xx); chkerr();
printf(zz,"CHANNEL=$%x%n");
printf(zz,"CHANNEL=%d%n");
return zz;
}
void prtpos(aa) {
printf("FTELL($%x): ");
printf("FTELL(%d): ");
err, filpos = ftell(aa); chkerr();
setdst(filpos); printf("POSITION=$%w%n");
return aa;
}
void posfil(aa) {
setdst(filpos); printf(aa, "FSEEK($%x,$%w): ");
setdst(filpos); printf(aa, "FSEEK(%d,$%w): ");
err = fseek(aa, filpos); chkerr();
putln("POSITIONED");
}
void rwdfil(aa) {
printf(aa, "REWIND($%x): ");
printf(aa, "REWIND(%d): ");
err = rewind(aa, filpos); chkerr();
putln("REWOUND");
}
void wbnry(aa) {
setdst(&bnry); printf("FWRITE($%x,\"%s\"): ");
setdst(&bnry); printf("FWRITE(%d,\"%s\"): ");
fsaddr(&bnry);
n, err = fwrite(@bnry, aa); chkerr();
printf(n, "WROTE $%x BYTES%n");
printf(n, "WROTE %d BYTES%n");
}
void wchars(aa) {
@ -119,20 +119,20 @@ void wchars(aa) {
}
void wstrng(aa) {
setdst(str1); printf(aa, "FPUTS($%x,\"%s\"): ");
setdst(str1); printf(aa, "FPUTS(%d,\"%s\"): ");
n, err = fputs(aa, str1); chkerr();
printf(n, "WROTE $%x CHARACTERS%n");
printf(n, "WROTE %d CHARACTERS%n");
setdst(str2); printf(aa, "FPUTLN(%s,\"%s\"): ");
n, err = fputln(aa, str2); chkerr();
printf(n, "WROTE $%x CHARACTERS%n");
printf(n, "WROTE %d CHARACTERS%n");
}
void sfile(aa, yy, xx) {
setdst(); printf("FSNAME(\"%s\"); ");
fsname(.,yy,xx); //Set Filename
setdst(&save); printf("FSADDR($%w); ");
fsaddr(&save); //Set Start Address
setdst(&bnry); printf(aa, "FSAVE($%x,$%w): ");
setdst(&bnry); printf(aa, "FSAVE(%d,$%w): ");
err, addr = fsave(aa, &bnry); chkerr();
putln("FILE SAVED");
}
@ -140,9 +140,9 @@ void sfile(aa, yy, xx) {
void rbnry(aa) {
setdst(&r); printf("FSADDR($%w); ");
fsaddr(&r);
printf(@bnry, "FREAD($%x,"); printf(aa,"$%x): ");
printf(@bnry, "FREAD(%d,"); printf(aa,"%d): ");
n, err = fread(@bnry, aa); chkerr();
puts(&r); printf(n, ", READ $%x BYTES%n");
puts(&r); printf(n, ", READ %d BYTES%n");
}
void lfile(aa, yy, xx) {
@ -150,7 +150,7 @@ void lfile(aa, yy, xx) {
fsname(.,yy,xx); //Set Filename
memclr(255, &l); printf("FSADDR($%w); ");
fsaddr(&l); //Set Load Address
printf(aa, "FLOAD($%x): ");
printf(aa, "FLOAD(%d): ");
err, addr = fload(aa); chkerr();
setdst(addr); printf("END=$%w, "); putln(&l);
}
@ -166,13 +166,13 @@ void rchars(aa) {
}
void rstrng(aa) {
printf("FGETS($%x, &S): ");
printf("FGETS(%d, &S): ");
n, err = fgets(aa, &s); chkerr();
puts(&s); printf(n, " READ $%x CHARACTERS%n");
puts(&s); printf(n, " READ %d CHARACTERS%n");
}
void clsfil(aa) {
printf(aa, "FCLOSE($%x): ");
printf(aa, "FCLOSE(%d): ");
err = fclose(aa); chkerr();
putln("CLOSED");
}

View File

@ -55,22 +55,21 @@ void newfil() {
}
void renfil() {
puts("RENAMING "); puts(oldnam);
puts(" TO "); puts(newnam);
puts("RENAMING "); puts(oldnam); puts(" TO "); puts(newnam);
fsname(oldnam);
r, err = rename(newnam); chkerr(r);
err = rename(0, newnam); chkerr(r);
}
void delfil() {
puts("REMOVING "); puts(newnam);
r, err = remove(newnam); chkerr(r);
err = remove(0, newnam); chkerr(r);
}
void chgdrv() {
for (i=0; i<#DRIVES; i++) {
d = drive[i];
printf(d, "CHDRV('%c') ");
r, err = chdrv(d); chkerr(r);
err = chdrv(d); chkerr(r);
}
}