From e9d5c04f8772c12c517305e079f89d2911f95f4f Mon Sep 17 00:00:00 2001 From: Curtis F Kaylor Date: Mon, 21 Sep 2020 12:10:29 -0400 Subject: [PATCH] Implemented File I/O, Directory, and File System modules for run6592 emulator --- include/direct.a02 | 30 +++++ include/direct.h02 | 37 ++++++ include/dirent.a02 | 34 +++++ include/dirent.h02 | 50 +++++++ include/fileio.a02 | 189 +++++++++++++-------------- include/fileio.h02 | 254 ++++++++++++++++++++---------------- include/filesys.a02 | 43 ++++++ include/filesys.h02 | 42 ++++++ include/run6502.h02 | 1 + include/run6502/direct.a02 | 49 +++++++ include/run6502/direct.h02 | 34 +++++ include/run6502/dirent.a02 | 49 +++++++ include/run6502/dirent.h02 | 42 ++++++ include/run6502/fileio.a02 | 241 ++++++++++++++++++++++++++++++++++ include/run6502/fileio.h02 | 154 ++++++++++++++++++++++ include/run6502/filesys.a02 | 60 +++++++++ include/run6502/filesys.h02 | 37 ++++++ test/dirtest.c02 | 60 +++++++++ test/diskdir.c02 | 55 ++++++++ test/filetest.c02 | 133 +++++++++++++++++++ test/fstest.c02 | 80 ++++++++++++ 21 files changed, 1466 insertions(+), 208 deletions(-) create mode 100644 include/direct.a02 create mode 100644 include/direct.h02 create mode 100644 include/dirent.a02 create mode 100644 include/dirent.h02 create mode 100644 include/filesys.a02 create mode 100644 include/filesys.h02 create mode 100644 include/run6502/direct.a02 create mode 100644 include/run6502/direct.h02 create mode 100644 include/run6502/dirent.a02 create mode 100644 include/run6502/dirent.h02 create mode 100644 include/run6502/fileio.a02 create mode 100644 include/run6502/fileio.h02 create mode 100644 include/run6502/filesys.a02 create mode 100644 include/run6502/filesys.h02 create mode 100644 test/dirtest.c02 create mode 100644 test/diskdir.c02 create mode 100644 test/filetest.c02 create mode 100644 test/fstest.c02 diff --git a/include/direct.a02 b/include/direct.a02 new file mode 100644 index 0000000..e48afb3 --- /dev/null +++ b/include/direct.a02 @@ -0,0 +1,30 @@ +; C02 Module direct Assembly Language Routines + + SUBROUTINE DIRECT + +;getcwd(drv, &dir) - Get Current Directory +;Args: A = Drive Identifier +; Y,X = Pointer to String +;Returns: A = Result (0 = Success, $FF = Failure) +; Y = Error Code (0 = None) +GETCWD: ;Return Error - Not Implemented (Fall Through) + +;chdir(drv, &dir) - Get Current Directory +;Args: A = Drive Identifier +; Y,X = Pointer to String +;Returns: A = Result (0 = Success, $FF = Failure) +; Y = Error Code (0 = None) +CHDIR: ;Return Error - Not Implemented (Fall Through) + +;rmdir(drv, &dir) - Create Directory +;Args: A = Drive Identifier +; Y,X = Address of Directory Name String +;Returns: A = Error Code (0 = None) +RMDIR: ;Return Error - Not Implemented (Fall Through) + +;mkdir(drv, &dir) - Create Directory +;Args: A = Drive Identifier +; Y,X = Address of Directory Name String +;Returns: A = Error Code (0 = None) +MKDIR: LDA #$FF ;Return Result = Failure + TAY ;and Error - Not Implemented diff --git a/include/direct.h02 b/include/direct.h02 new file mode 100644 index 0000000..2327223 --- /dev/null +++ b/include/direct.h02 @@ -0,0 +1,37 @@ +/****************************************** + * direct - Directory Manipulation Module * + * Requires fileio.h02 * + ******************************************/ + +/* Change Directory * + * Args: drv - Drive/Disk Identifier * + * &dir - Directory Name * + * Returns: char r - Result, 0=Success * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char chdir(); + +/* Get Current Working Directory * + * Args: drv - Drive/Disk Identifier * + * &dir - Directory Name * + * Returns: char n - Length of Name * + * 0 = None or Error * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char getcwd(); + +/* Make Directory * + * Args: drv - Drive/Disk Identifier * + * &dir - Directory Name * + * Returns: char r - Result, 0=Success * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char mkdir(); + +/* Remove Directory * + * Args: drv - Drive/Disk Identifier * + * &dir - Directory Name * + * Returns: char r - Result, 0=Success * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char rmdir(); diff --git a/include/dirent.a02 b/include/dirent.a02 new file mode 100644 index 0000000..8f7be83 --- /dev/null +++ b/include/dirent.a02 @@ -0,0 +1,34 @@ +; C02 dirent.h02 Assembly Language Subroutines +; Requires external functions ... +; external zero page locations ... +; and external locations ... + +;opndir() - Open Directory for Reading +;Args: A = Drive Identifier +; Y,X = Pointer to Directory Name +;Returns: A = File Pointer (0 = Not Opened) +; Y = Error Code (0 = None) +OPNDIR: ;Return Error - Not Implemented (fall through) + +;rdhdr() - Read Directory Header +;Note: Call once before first readdir +;Args: A = Directory File Pointer +; Y,X = Pointer to HDRENT buffer +;Returns: A = Length of Header (0=None) +; Y = Error Code (0=None) +RDHDR: ;Return Error - Not Implemented (fall through) + +;rddir() - Read Directory Entry +;Args: A = Directory File Pointer +; Y,X = Pointer to dirent structure +;Returns: A = Length of Entry (0=None) +; Y = Error Cooe (0=None) +RDDIR: LDA #$00 ;Return Result - None + LDY #$FF ;and Error - Not Implemented + RTS + +;clsdir() - Close Directory File +;Args: A = Directory File Pointer +;Returns: A = Error Code (0 = Success) +CLSDIR: LDA #$FF ;Return Error - Not Implemented + RTS diff --git a/include/dirent.h02 b/include/dirent.h02 new file mode 100644 index 0000000..7e10577 --- /dev/null +++ b/include/dirent.h02 @@ -0,0 +1,50 @@ +/********************************************************** + * dirent - Directory Entries Module for run6502 emulator * + * Requires fileio.h * + **********************************************************/ + +/* Sample Directory Entry * + * The only required field is name */ +struct dirent { + char name[128]; //Entry Filename +}; + +/* Sample Directory Header * + * The only required field is name */ +/* Directory Header */ +struct dirhdr { + char name[128]; //Header Name +}; + +/* Open Directory for Reading * + * Args: char d - Drive | Disk * + * int &n - Directory Name * + * Returns: char f - Channel * + * 0 = Not Opened * + * char e - Error, 0=None * + * 255 = Not Implemented */ +cchar opndir(); + +/* Read Disk/Directory Header * + * Args: char f - Directory Channel * + * int &s - dirhdr Struct * + * Returns: char n - Length of Header * + * 0 = N/A or Error * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char rdhdr(); + +/* Read Directory Entry * + * Args: char f - Directory Channel * + * int &s - dirent Struct * + * Returns: char n - Length of Entry * + * 0 = EOF or Error * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char rddir(); + +/* Close Directory Channel * + * Args: char f - Directory Channel * + * Returns: char e - Error, 0=None * + * 255 = Not Implemented */ +char clsdir(); diff --git a/include/fileio.a02 b/include/fileio.a02 index a296175..f3c5f94 100644 --- a/include/fileio.a02 +++ b/include/fileio.a02 @@ -1,65 +1,99 @@ ;C02 Module file.h02 Assembly Lamnguage ;Template Code -;Sample Device Numbers -CASST1 EQU 0 -MODEM1 EQU 2 -PRNTR1 EQU 3 -PRNTR2 EQU 4 -DRIVE1 EQU 5 -DRIVE2 EQU 6 -DRIVE3 EQU 7 -DRIVE4 EQU 8 +DRIVES EQU 0 ;Number of Disk Drives (None) +DRIVE BYTE 0 ;List of Drive Device Numbers -;Disk Numbers (Within Drive) -DISK0 EQU $00 -DISK1 EQU $40 +DISKS EQU 0 ;Number of Disks in Drive (None) +DISK BYTE 0 ;List of Disk IDs ;File Open Modes MWRITE EQU $80 MREAD EQU $00 - -;fflush(chan) - Flush Write Buffer to File -;Args: A = Mode + Drive ID -;Returns: A = File Channel (0=File Not Opened) -FFLUSH: ;Return Success (fall through) - -;fopen(args, &name) - Open File -;Args: A = Mode + Drive ID -; Y,X = Pointer to File Name -;Returns: A = File Channel (0=File Not Opened) -FOPEN: LDA $00 ;Return File Not Opened (fall through) +; File Load Modes +MRELCT EQU $00 ;Relocate (Load at Specified Address) +MABSLT EQU $80 ;Absolute (Load at Address in File Header) ;fclose(chan) - Close File ;Args: A = Channel Number -FCLOSE: RTS ;No Action +;Returns: A = Error (0=None) +FCLOSE: ;Return Error (Fall through) + +;feof(chan) - Check for End of File +;Args: A = Channel Number +;Returns: A = $00 - Not End of File +; $FF - End of File +; Otherwise, Error Code +FEOF: ;Return Error - Not Implemented + +;fflush(chan) - Flush Write Buffer to File +;Args: A = Channel +;Returns: A = Error (0=None) +FFLUSH: ;Return Error - Not Implemented + +;fputc(chan, char) - Write Character to File +;Args: A = Character to Write +; Y = Channel Number +;Returns: A = Error Code ($00 - Success) +FPUTC: ;Return Error - Not Implemented + +;fload(name) - Load File into Memory +;Setup: Call FSNAME with filename address +; Call FSADDR with start address +;Args: A = Option + DriveID +; Y,X = End Address +;Returns: A = Error Code ($00 - Success) +; X,Y = Load Address +FLOAD: ;Return Error - Not Implemented (fall through) + +;fsave(name) - Save File from Memory +;Setup: Call FSNAME with filename address +; Call FSADDR with start address +;Args: A = Option + DriveID +; Y,X = End Address +;Returns: A = Error Code ($00 - Success) +FSAVE: LDA $FF ;Return Error - Not Implemented + RTS + +;fopen(mode, &name) - Open File +;Args: A = Mode + Drive ID + Disk # +; Y,X = Pointer to File Name +;Returns: A = File Channel (0=File Not Opened) +; Y = Error (0=None) +FOPEN: ;Return Error - Not Implemented ;fgetc(chan) - Read Character from File ;Args: A = Channel Number ;Returns: A = Character -; Y = Error Code -; $00 - Success -; $FF - Not Implemented -FGETC: ;Return Error - Not Implemented (fall through) +; Y = Error Code ($00 - Success) +FGETC: ;Return Error - Not Implemented ;fgets(chan, &s) - Read String from File ;Args: A = Channel Number -; Y,X = Pointer to String Array +; Y,X = Address of String ;Returns: A = Number of Bytes Read -; Y = Error Code -; $00 - Success -; $FF - Not Implemented -FGETS: ;Return Error - Not Implemented (fall through) +; Y = Error Code ($00 - Success) +FGETS: ;Return Error - Not Implemented + +;fputln(chan, &s) - Write String to File with Newline +;Args: A = Channel Number +; Y,X = Address of String +;Returns: A = Error Code ($00 - Success) +FPUTLN: ;Return Error - Not Implemented + +;fputs(chan, &s) - Write String to File +;Args: A = Channel Number +; Y,X = Address of String +;Returns: A = Error Code ($00 - Success) +FPUTS: ;Return Error - Not Implemented ;fread(chan, count) - Read Bytes from File -;Args: A = Channel Number -; Y = Number of Bytes to Read -;Uses: DSTLO,DSTHI - Pointer Destination Array +;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 -; $FF - Not Implemented +; Y = Error Code ($00 - Success) FREAD: ;Return Error - Not Implemented (fall through) ;fwrite(chan, count) - Write Bytes to File @@ -74,67 +108,24 @@ FWRITE: LDA $00 ;Return 0 Bytes Read/Written LDY $FF ;and Error - Not Implemented RTS -;feof(chan) - Check for End of File +;ferror(chan, &msg) - Check for Error ;Args: A = Channel Number -;Returns: A = Platform Specific EOF Value -; $00 - Not End of File -; $FF - Not Implemented -FEOF: ;Return Error - Not Implemented (fall through) - -;ferror(chan) - Check for Error -;Args: A = Channel Number -;Returns: A = Error Code -; $00 - Success -; $FF - Not Implemented -FERROR: ;Return Error - Not Implemented (fall through) - -;fputc(chan, char) - Write Character to File -;Args: A = Channel Number -; Y = Character to Write -;Returns: A = Error Code -; $00 - Success -; $FF - Not Implemented -FPUTC: ;Return Error - Not Implemented (fall through) - -;fputs(chan, &s) - Write String from File -;Args: A = Channel Number -; Y,X = Pointer to String Array -;Returns: A = Error Code -; $00 - Success -; $FF - Not Implemented -FPUTS: ;Return Error - Not Implemented (fall through) - -;fload(name) - Load File into Memory -;Args: A = Option + DriveID -; Y,X = Pointer to File Name -;Uses: SRCLO,SRCHI = Start Address -; DSTLO,DSTHI = End Address -;Returns: A = Error Code -; $00 - Success -; $FF - Not Implemented -; X,Y = Load Address -FLOAD: ;Return Error - Not Implemented (fall through) - -;fsave(name) - Save File from Memory -;Args: A = Option + DriveID -;Args: Y,X = Pointer to File Name -;Uses: SRCLO,SRCHI = Start Address -; DSTLO,DSTHI = End Address -;Returns: A = Error Code -; $00 - Success -; $FF - Not Implemented -FSAVE: LDA $FF ;Return Error - Not Implemented +; Y,X = String Address +;Returns: A = Last Error ($FF - Invalid Channel) +; Y = Error (0=None) +FERROR: LDA #$FF ;Return Invalid Channel + TAY ;and Error - Not Implemented RTS -;Internal routines are all prefixed with FS - -;fsetup() - Set Parameters for File Open -;Platform Specific - -;fsinit() - Initialize Control Block -;For platforms that use File or Parameter Control Blocks - -;fname(&name) - Set File Name -;If a seperate OS Call to set the File Name -;or a terminator other than NUL is required +;fsinit() - Initialize File System +FSINIT: ;No Action (Fall Through) +;fsaddr(&array) - Set File Buffer Address +;Emulation: sets internal variable filebuff +;Args: Y,X = Address of String or Array +FSADDR: ;No Action (Fall Through) + +;fsname(&name) - Set File Name +;Emulation: sets internal variable filename +;Args: Y,X = Address of Filename +FSNAME: RTS ;No Action diff --git a/include/fileio.h02 b/include/fileio.h02 index 57bb7a2..551d5b4 100644 --- a/include/fileio.h02 +++ b/include/fileio.h02 @@ -1,10 +1,13 @@ -/****************************************** - * file - Standard File Functions for C02 * - ******************************************/ +/*************************************** + * fileio - File I/O Functions for C02 * + * Non-Functional Template Header * + ***************************************/ -/* Device List */ -enum {CASST1, MODEM1, PRNTR1, PRNTR2, - DRIVE1, DRIVE2, DRIVE3, DRIVE4}; +#define DRIVES 0 //Number of Disk Drives +const char drive[]; //Disk Drives + +#define DISKS 0 //Number of Drives in Disk +const char disk[]; /* File Open Modes */ #define MWRITE $80 //Open File for Write @@ -14,34 +17,147 @@ enum {CASST1, MODEM1, PRNTR1, PRNTR2, #define MRELCT $00 //Relocate (Load at Specified Address) #define MABSLT $80 //Absolute (Load at Address in File Header) +/* File Close * + * Closes File Opened on Channel * + * Args: char f - File Channel * + * Returns: char e - Error, 0=None * + * 255 = Not Implemented */ +char fclose(); -/* File Load * - * Loads File into Memory * - * Args: d - Options | DeviceID * - ^ &n - Filename * - * Returns: Error Code (0=None) * - * Load Address */ +/* End of File * + * Check for End of File Condition * + * Args: char f - File Channel * + * Returns: char e = EOF Indicator * + * (0 if not at end of file * + * 255 if at end of file * + * or non-zero Error code) */ +char feof(); + +/* File Error * + * Check File Error Indicator * + * Args: char c - channel * + * int &s - error msg buffer * + * Returns: char l - Last Error * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char ferror(); + +/* File Flush * + * Flush File Output Buffer * + * Args: char f - File Channel * + * Returns: char e - Error, 0=None * + * 255 = Not Implemented */ +char fflush(); + +/* File Get Character * + * Args: char f - File Channel * + * Read Character from Fie * + * Returns: char c - Character * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char fgetc(); + +/* File Get String * + * Read line of up to 128 * + * characters from file * + * Args: char f - File Channel * + * int &s - String to Read * + * Returns: char n - Characters Read * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char fgets(); + +/* File Load * + * Loads File into Memory * + * Setup: fsname(&filename) * + * fsaddr(address) * + * Args: char d - Options | Device * + * Returns: char e - Error, 0=None * + * 255 = Not Implemented * + * int la - Load Address */ char fload(); -/* File Save * - * Save File from Memory * - * Args: d - Options | DeviceID * - ^ &n - Filename * - * Returns: Error Code (0=None) */ -char fsave(); - -/* File Open * - * Opens File Specified by Name * - * Args: d - Options | DeviceID * - ^ &n - Filename * - * Returns: File Pointer (0=Error) * - Error Code (0=None) */ +/* File Open * + * Open Specified File * + * Args: char d - Options | Device * + ^ int &n - Filename * + * Returns: char c - Channel (0=Error) * + * char e - Error, 0=None * + * 255 = Not Implemented */ char fopen(); -/* File Close * - * Closes File Opened to File Pointer * - * Args: fp - file pointer */ -char fclose(); +/* File Put Character * + * Write Character to File * + * Args: char c - Character * + * char f - File Channel * + * Returns: char e - Error, 0=None * + * 255 = Not Implemented */ +char fputc(); + +/* File Put Line * + * Write string followed by * + * newline to file * + * Args: char f - File Channel * + * int &s - String to Write * + * Returns: char n - Characters Written * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char fputln(); + +/* File Put String * + * Writes up to 128 characters * + * of string to file * + * Args: char f - File Channel * + * int &s - String to Write * + * Returns: char n - Characters Written * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char fputs(); + +/* File Read * + * Read up to n bytes from file * + * Setup: fsaddr(&array) * + * Args: char f - File Channel * + * char n - Number of Bytes * + * Returns: char r - Bytes Read * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char fread(); + +/* File Set Address * + * Set Buffer or Start Address * + * Args: int addr - Address */ + char fsaddr(); + +/* File Save * + * Save File from Memory * + * Setup: fsname(&filename) * + * fsaddr(start) * + * Args: char d - Options | Device * + * int end - End Address * + * Returns: char e - Error, 0=None * + * 255 = Not Implemented */ +char fsave(); + +/* File System Init * + * Initialize File System */ +char fsinit(); + +/* File Set Name * + * Set Filename Address * + * Args: int &name - Filename */ + char fsname(); + +/* File Write * + * Write n nytes to file * + * Setup: fsaddr(&array) * + * Args: char n - Number of Bytes * + * char f - File Channel * + * Returns: char n - Bytes Written * + * Returns: char e - Error, 0=None * + * 255 = Not Implemented */ +char fwrite(); + /* End of File * * Check for End of File Condition * @@ -51,83 +167,3 @@ char fclose(); * 255 if not implemented * * or non-zero EOF value) */ char feof(); - -/* File Error * - * Check File Error Indicator * - * Args: fp - file pointer * - * &s - string for error text * - * Returns: platform specific error number * - * (0 if no error * - * 255 if not implemented) */ -char ferror(); - -/* Flush File Buffer * - * Flush File Output Buffer * - * Args: fp - file pointer * - * Returns: platform specific error number * - * (0 if no error) */ -char fflush(); - -/* Read Character from File * - * Args: fp - file pointer * - * Returns: ASCII value of character, * - * platform specific error number * - * (0 if no error * - * 255 if not implemented) */ -char fgetc(); - -/* Write Character to File * - * Args: fp - file pointer * - * c - ASCII character to write * - * Returns: platform specific error * - * (0 if no error * - * 255 if not implemented) */ -char fputc(); - -/* Read String from File * - * Buffers up to 128 characters * - * until C/R is pressed * - * Args: fp - file pointer * - * &s - string read from file * - * Returns: number of characters read, * - * platform specific error * - * (0 if no error * - * 255 if not implemented) */ -char fgets(); - -/* Write String to File * - * Writes up to 128 characters of a * - * null terminated string * - * Args: fp - file pointer * - * &s - string to print from * - * Returns: platform specific error * - * (0 if no error * - * 255 if not implemented) */ -char fputs(); - -/* Write Line to File * - * Write String to File followed by C/R * - * Args: fp - file pointer * - * &s - string to print from * - * Returns: ending position in string * - * 255 if error during write */ -char fputln(); - -/* Read Bytes from File * - * Reads until EOF is reached * - * Args: fp - file pointer * - * n - number of bytes to read * - * Returns: number of bytes read, * - * platform specific error * - * (0 if no error * - * 255 if not implemented) */ -char fread(); - -/* Write Bytes to File * - * Args: fp - file pointer * - * n - number of bytes to write * - * Returns: number of bytes written, * - * platform specific error * - * (0 if no error * - * 255 if not implemented) */ -char fwrite(); diff --git a/include/filesys.a02 b/include/filesys.a02 new file mode 100644 index 0000000..e76d44f --- /dev/null +++ b/include/filesys.a02 @@ -0,0 +1,43 @@ +; C02 filesys.h02 assembly language subroutines +; Requires external functions ... +; external zero page locations ... +; and external locations ... + +;remove(drv, &filnam) - Remove File filnam +;Args: A = Drive Identifier +; Y,X = Address of Directory Name String +;Returns: A = Error Code (0 = None) +REMOVE: ;Return Error - Not Implemented (Fall Through) + +;rename(drv, &filnam) - Rename File to filnam +;Setup: Call FSNAME with Address of Old Name +;Args: A = Drive Identifier +; Y,X = Address of Directory Name String +;Returns: A = Error Code (0 = None) +RENAME: ;Return Error - Not Implemented (Fall Through) + +;inidrv(drv) - Initialize Disk Drive +;Args: A = Drive Identifier +;Returns: A = Error Code (0 = None) +INIDRV: ;Return Error - Not Implemented (Fall Through) + +;chdrv() - Set Current Drive/Disk +;Args: A = Drive# | Disk# +;Returns: A = Result (0 - Success) +; Y = Error Code (0 = None) +CHDRV: LDA #$FF ;Return Result - Failure + TAY ;and Error - Not Implemented + RTS + +;getdrv() - Get Current Drive/Disk +;Returns: A = Drive# | Disk# (0=Failure) +; Y = Error Code (0 = None) +GETDRV: ;Return Error - Not Implemented (Fall Through) + +;drvnam(drv) - Get Drive Name +;Args: A = Drive Number +;Returns: A = Drive Name (0=Failure) +; Y = Error (0=None) +DRVNAM: LDA #$00 ;Return Result (None) + LDY #$FF ;and Error - Not Implemented + RTS \ No newline at end of file diff --git a/include/filesys.h02 b/include/filesys.h02 new file mode 100644 index 0000000..cbc71ba --- /dev/null +++ b/include/filesys.h02 @@ -0,0 +1,42 @@ +/************************************************** + * filesys - File System Module Template for C02 * + **************************************************/ + +/* Change Drive * + * Args: char d - Drive ID | Disk # * + * Returns: char r - Result, 0=Success * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char chdrv(); + +/* Drive Name * + * Args: char d - Drive ID | Disk # * + * Returns: char n - Drive Name * + * 0 = Invalid Device * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char drvnam(); + +/* Get Drive * + * Returns: char d - Current Drive/Disk * + * 0 = None or Error * + * char e - Error, 0=None * + * 255 = Not Implemented */ +char getdrv(); + +/* Remove File * + * Args: char d - Drive ID | Disk # * + * int &name - File Name * + * Returns: char r - Result, 0=Success * + * char e - Error, 0=None * + * 255 = Not Implemented */ +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 * + * 255 = Not Implemented */ +char rename(); diff --git a/include/run6502.h02 b/include/run6502.h02 index 0c18ced..59deaf6 100644 --- a/include/run6502.h02 +++ b/include/run6502.h02 @@ -39,3 +39,4 @@ void prhex(); //Print Low Nybble of Accumulator as Hex Digit //System Labels start: //Start of Code exit: //Return to Operating System + diff --git a/include/run6502/direct.a02 b/include/run6502/direct.a02 new file mode 100644 index 0000000..bdf530f --- /dev/null +++ b/include/run6502/direct.a02 @@ -0,0 +1,49 @@ +; C02 Module direct Assembly Language Routines for run6502 emulator +; This is the reference implementation of the direct module +; Requires external function FSCMD and FSVDRV (fileio.h02) + + SUBROUTINE DIRECT + +;getcwd(drv, &dir) - Get Current Directory +;Args: A = Drive Identifier +; Y,X = Pointer to String +;Returns: A = Result (0 = Succes, $FF = Failure) +; Y = Error Code (0 = None) +GETCWD: JSR FSVDRV ;Validate Drive Number + BCS .DRVERR ;If Invalid Return Error + LDA #'T' ;Set Command to GETCWD +.FSCMDX JSR FSCMD ;Execute Command + TXA ;Return Length of Name +.DRVERR RTS + +;chdir(drv, &dir) - Get 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 FSVDRV ;Validate Drive Number + BCS .DRVERR ;If Invalid Return Error + LDA #'U' ;Set Command to GETCWD + BNE .FSCMDX ;Execute Command and Return Result + +;rmdir(drv, &dir) - Create Directory +;Args: A = Drive Identifier +; Y,X = Address of Directory Name String +;Returns: A = Error Code (0 = None) +RMDIR: SEC ;Set Mode to RMDIR + BCS .MRDIR ;Execute MKRMDIR and Return Result + +;mkdir(drv, &dir) - Create Directory +;Args: A = Drive Identifier +; 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 FSVDRV ;Validate Drive Number + BCS .DRVERR ;If Invalid Return Error + PLP ;Restore Status Register + LDA #'X' ;Set Command to MKRMDIR + BNE .FSCMDX ;Execute Command and Return Result + +.PLAERR PLP ;Restore Status Register + RTS ;and Return diff --git a/include/run6502/direct.h02 b/include/run6502/direct.h02 new file mode 100644 index 0000000..d120b9a --- /dev/null +++ b/include/run6502/direct.h02 @@ -0,0 +1,34 @@ +/****************************************** + * direct - Directory Manipulation Module * + * for run6502 emulator * + * Requires fileio.h02 * + ******************************************/ + +/* Change Directory * + * Args: drv - Drive/Disk Identifier * + * &dir - Directory Name * + * Returns: char r - Result, 0=Success * + * char e - Error, 0=None */ +char chdir(); + +/* Get Current Working Directory * + * Args: drv - Drive/Disk Identifier * + * &dir - Directory Name * + * Returns: char n - Length of Name * + * 0 = None or Error * + * char e - Error, 0=None */ +char getcwd(); + +/* Make Directory * + * Args: drv - Drive/Disk Identifier * + * &dir - Directory Name * + * Returns: char r - Result, 0=Success * + * char e - Error, 0=None */ +char mkdir(); + +/* Remove Directory * + * Args: drv - Drive/Disk Identifier * + * &dir - Directory Name * + * Returns: char r - Result, 0=Success * + * char e - Error, 0=None */ +char rmdir(); diff --git a/include/run6502/dirent.a02 b/include/run6502/dirent.a02 new file mode 100644 index 0000000..685734b --- /dev/null +++ b/include/run6502/dirent.a02 @@ -0,0 +1,49 @@ +; C02 Module dirent Assembly Language Eoutines for run6502 emulator +; This is the reference implementation of the dirent module +; Requires external functions FSADDR, FSCMD, and FSVDRV (fileio.h02) + + SUBROUTINE DIRENT + +;opndir() - Open Directory for Reading +;Args: A = Drive Identifier +; Y,X = Pointer to Directory Name +;Returns: A = File Pointer (0 = Not Opened) +; Y = Error Code (0 = None) +OPNDIR: JSR FSVDRV ;Validate Drive Number + BCS .OPNERR ;If Invalid Return Error + LDA #'D' ;Set Command to OPENDIR +.FSCMDX JSR FSCMD ;Execute Command + TXA ;Return Channel + RTS + +.OPNERR LDA #0 ;Directory Not Opened + RTS + +;rdhdr() - Read Directory Header +;Note: Call once before first readdir +;Args: A = Directory File Pointer +; Y,X = Pointer to HDRENT buffer +;Returns: A = Length of Header (0=None) +; Y = Error Code (0=None) +RDHDR: SEC ;Set Mode to HEADER + BCS .RDDIR ;Execute READDIR + +;rddir() - Read Directory Entry +;Args: A = Directory File Pointer +; Y,X = Pointer to dirent structure +;Returns: A = Length of Entry (0=None) +; Y = Error Cooe (0=None) +RDDIR: CLC ;Set Mode to ENTRY +.RDDIR JSR FSADDR ;Save Address + TAY ;Set Channel + LDA #'J' ;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 + JSR FSCMD ;Execute Command + TYA ;and Return Error Code + RTS diff --git a/include/run6502/dirent.h02 b/include/run6502/dirent.h02 new file mode 100644 index 0000000..a91b21a --- /dev/null +++ b/include/run6502/dirent.h02 @@ -0,0 +1,42 @@ +/********************************************************** + * dirent - Directory Entries Module for run6502 emulator * + **********************************************************/ + +/* Directory Entry */ +struct dirent { + char name[128]; //Entry Filename +}; + +/* Directory Header */ +struct dirhdr { + char name[128]; //Header Name +}; + +/* Open Directory for Reading * + * Args: char d - Drive | Disk * + * int &n - Directory Name * + * Returns: char f - Channel * + * 0 = Not Opened * + * char e - Error, 0=None */ +char opndir(); + +/* Read Disk/Directory Header * + * Args: char f - Directory Channel * + * int &s - dirhdr Struct * + * Returns: char n - Length of Header * + * 0 = N/A or Error * + * char e - Error, 0=None */ +char rdhdr(); + +/* Read Directory Entry * + * Args: char f - Directory Channel * + * int &s - dirent Struct * + * Returns: char n - Length of Entry * + * 0 = EOF or Error * + * char e - Error, 0=None */ +char rddir(); + +/* Close Directory Channel * + * Args: char f - Directory Channel * + * Returns: char e - Error, 0=None */ +char clsdir(); diff --git a/include/run6502/fileio.a02 b/include/run6502/fileio.a02 new file mode 100644 index 0000000..46a56a2 --- /dev/null +++ b/include/run6502/fileio.a02 @@ -0,0 +1,241 @@ +; 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. + + SUBROUTINE FILEIO + +DRIVES EQU 26 ;Number of Disk Drives +DRIVE BYTE 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26 + +DISKS EQU 1 ;Number of Disks in Drive +DISK BYTE 0 + +;File Open Modes +MREAD EQU $00 +MWRITE EQU $80 + +; File Load Modes +MRELCT EQU $00 ;Relocate (Load at Specified Address) +MABSLT EQU $80 ;Absolute (Load at Address in File Header) + +;fflush(chan) - Flush Write Buffer to File +;Args: A = Channel +;Returns: A = 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 +; Y,X = Pointer to File Name +;Returns: A = File Channel (0=File Not Opened) +; Y = Error (0=None) +FOPEN: JSR FSVDRV ;Validate Drive Number + BCS .DRVERR + JSR FSNAME ;Set Filename + TAY ;and Pass in Y + LDA #'O' ;Set Command to OPEN +.FEXECX JSR FSCMD ;Execute Command + TXA ;Return Channel in A +.DRVERR RTS + +;fclose(chan) - Close File +;Args: A = Channel Number +;Returns: A = Error (0=None) +FCLOSE: TAY ;Set Channel + LDA #'C' ;Set Command to CLOSE + BNE .FEXEC ;Execute and Return Error in A + +;feof(chan) - Check for End of File +;Args: A = Channel Number +;Returns: A = $00 - Not End of File +; $FF - End of File +; Otherwise, Error Code +FEOF: TAY ;Set Channel + LDA #'E' ;Set Command to EOF + BNE .FEXEC ;Execute and Return Error in A + +;fgetc(chan) - Read Character from File +;Args: A = Channel Number +;Returns: A = Character +; Y = Error Code ($00 - Success) +FGETC: TAY ;Set Channel + LDA #'G' ;Set Command to GET + BNE .FEXECX ;Execute and Return Result in A + +;fgets(chan, &s) - Read String from File +;Args: A = Channel Number +; Y,X = Address of String +;Returns: A = Number of Bytes Read +; Y = Error Code ($00 - Success) +FGETS: JSR FSADDR ;Set String Address + TAY ;Set Channel Number + LDA #'H' ;Set Command to GETS + BNE .FEXECX ;Execute and Return Result in A + +;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 + +;fputln(chan, &s) - Write String to File with Newline +;Args: A = Channel Number +; Y,X = Address of String +;Returns: A = Number of Characters Written +; Y = Error Code ($00 - Success) +FPUTLN: SEC ;Append Newline + BCS .FPUTSA ;Write String to File + +;fputs(chan, &s) - Write String to File +;Args: A = Channel Number +; Y,X = Address of String +;Returns: A = Number of Characters Written +; Y = Error Code ($00 - Success) +FPUTS: CLC ;Do Not Append Newline +.FPUTSA JSR FSADDR ;Set File Buffer Address + TAY ;Set Channel + LDA #'Q' ;Set Command to PUTS + BNE .FEXECX ;Execute and Return Result in A + +;fread(chan, count) - 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 + +;fwrite(chan, count) - Write Bytes to File +;Setup: Call FSADDR with array address +;Args: A = Number of Bytes to Write +; Y = Channel Number +;Returns: A = Number of Bytes Written +; Y = Error Code ($00 - Success) +FWRITE: TAX ;Set Number of Bytes to Write + LDA #'W' ;Set Command to WRITE + BNE .FEXECX ;Execute and Return Result in A + +;fload(name) - Load File into Memory +;Setup: Call FSNAME with filename address +; Call FSADDR with start address +;Args: A = Option + DriveID +; Y,X = End Address +;Returns: A = Error Code ($00 - Success) +; X,Y = Load Address +FLOAD: CMP #MABSLT ;Check Load Mode + BNE .ERR22 ;If Invalid, Return Error + LDA #'L' ;Set Command to LOAD + JMP FSCMD ;Execute Command and Return +.ERR22 LDA #22 + RTS + +;fsave(name) - Save File from Memory +;Setup: Call FSNAME with filename address +; Call FSADDR with start address +;Args: A = Option + DriveID +; Y,X = End Address +;Returns: A = Error Code ($00 - Success) +FSAVE: ORA $0 ;If Not Drive 0 + BNE .ERR22 ;Return Error + 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 + +;Check fot Valid Drive Number +;Args: A = Drive Number +;Returns: A = Index into Drives +; Carry Clear = Valid Drive Number +; Carry Set = Invalid Drive Number +FSVDRV: PHA + AND #$1F ;Isolate Drive Number + CMP #DRIVES+2 ;Compare against Number of Drives + PLA + BCS .FSVERR + RTS + +.FSVERR LDA #$FF ;Return Operation Failed + LDY #1 ;Error - Invalid Argument + RTS + +;fsinit() - Initialize File System +FSINIT: LDA #'I' ;Set Command to INITFS +.FSCMD JMP FSCMD ;Execute Command and Return + +;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 + PLA ;Restore Accumulator + 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 + +; 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 + + +; # Requires call to FSADDR +; + Requires call to FSNAMR +; * Requires calls to FSADDR and FSNAME diff --git a/include/run6502/fileio.h02 b/include/run6502/fileio.h02 new file mode 100644 index 0000000..2e1ebe3 --- /dev/null +++ b/include/run6502/fileio.h02 @@ -0,0 +1,154 @@ +/********************************************************* + * fileio - Standard File Functions for run6502 emulator * + *********************************************************/ + +#define DRIVES 26 //Number of Disk Drives +const char drive[]; //Disk Drives + +#define DISKS 1 //Number of Drives in Disk +const char disk[]; + +/* File Open Modes */ +#define MREAD $00 //Open File for Read +#define MWRITE $80 //Open File for Write + +/* File Load Modes */ +#define MRELCT $00 //Relocate (Load at Specified Address) +#define MABSLT $80 //Absolute (Load at Address in File Header) + +/* File Close * + * Closes File Opened on Channel * + * Args: char f - File Channel * + * Returns: char e - Error (0=None) */ +char fclose(); + +/* End of File * + * Check for End of File Condition * + * Args: char f - File Channel * + * Returns: char e = EOF Indicator * + * (0 if not at end of file * + * 255 if at end of file * + * or non-zero Error code) */ +char feof(); + +/* File Error * + * Check File Error Indicator * + * Args: char c - channel * + * int &s - error msg buffer * + * Returns: char l - Last Error * + * char e - Error (0=None) */ +char ferror(); + +/* File Flush * + * Flush File Output Buffer * + * Args: char f - File Channel * + * Returns: char e - Error (0=None) */ +char fflush(); + +/* File Get Character * + * Args: char f - File Channel * + * Read Character from Fie * + * Returns: char c - Character * + * char e - Error (0=None) */ +char fgetc(); + +/* File Get String * + * Read line of up to 128 * + * characters from file * + * Args: char f - File Channel * + * int &s - String to Read * + * Returns: char n - Characters Read * + * char e - Error (0=None) */ +char fgets(); + +/* File Load * + * Loads File into Memory * + * Setup: fsname(&filename) * + * fsaddr(address) * + * Args: char d - Options | Device * + * Returns: char e - Error (0=None) * + * int la - Load Address */ +char fload(); + +/* File Open * + * Open Specified File * + * Args: char d - Options | Device * + ^ int &n - Filename * + * Returns: char c - Channel (0=Error) * + 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) */ +char fputc(); + +/* File Put Line * + * Write string followed by * + * newline to file * + * Args: char f - File Channel * + * int &s - String to Write * + * Returns: char n - Characters Written * + * char e - Error (0=None) */ +char fputln(); + +/* File Put String * + * Writes up to 128 characters * + * of string to file * + * Args: char f - File Channel * + * int &s - String to Write * + * Returns: char n - Characters Written * + * char e - Error (0=None) */ +char fputs(); + +/* File Read * + * Read up to n bytes from file * + * Setup: fsaddr(&array) * + * Args: char f - File Channel * + * char n - Number of Bytes * + * Returns: char r - Bytes Read * + * char e - Error (0=None) */ +char fread(); + +/* File Set Address * + * Set Buffer or Start Address * + * Args: int addr - Address */ + char fsaddr(); + +/* File Save * + * Save File from Memory * + * Setup: fsname(&filename) * + * fsaddr(start) * + * Args: char d - Options | Device * + * int end - End Address * + * Returns: char e - Error (0=None) */ +char fsave(); + +/* File System Command * + * Execute File Operation * + * Args: char cmd - Command Code * + * params - Parameter(s) * + * Returns: char cmd - Command * + * char err - Error * + * char res - Result */ +char fscmd(); + +/* File System Init * + * Initialize File System */ +char fsinit(); + +/* File Set Name * + * Set Filename Address * + * Args: int &name - Filename */ + char fsname(); + +/* File Write * + * Write n nytes to file * + * Setup: fsaddr(&array) * + * Args: char n - Number of Bytes * + * char f - File Channel * + * Returns: char n - Bytes Written * + * char e - Error (0=None) */ +char fwrite(); diff --git a/include/run6502/filesys.a02 b/include/run6502/filesys.a02 new file mode 100644 index 0000000..98302a6 --- /dev/null +++ b/include/run6502/filesys.a02 @@ -0,0 +1,60 @@ +; C02 Module filesys Assembly Language Eoutines for run6502 emulator +; This is the reference implementation of the filesys module +; Requires external functions FSCMD and FSVDRV (fileio.h02) + + + SUBROUTINE FILESYS + +;remove(drv, &filnam) - Remove File filnam +;Args: A = Drive Identifier +; Y,X = Address of Directory Name String +;Returns: A = Error Code (0 = None) +REMOVE: JSR FSVDRV ;Validate Drive Number + BCS .DRVERR ;If Invalid Return Error + LDA #'K' ;Set Command to KILL (REMOVE) +.FSCMDX JSR FSCMD ;Execute Command + TXA ;Return Result + RTS + +;rename(drv, &filnam) - Rename File to filnam +;Setup: Call FSNAME with Address of Old Name +;Args: A = Drive Identifier +; Y,X = Address of Directory Name String +;Returns: A = Error Code (0 = None) +RENAME: JSR FSVDRV ;Validate Drive Number + BCS .DRVERR ;If Invalid Return Error + LDA #'M' ;Set Command to KILL (REMOVE) + BNE .FSCMDX ;Execute Command and Return Result + +;inidrv(drv) - Initialize Disk Drive +;Args: A = Drive Identifier +;Returns: A = Error Code (0 = None) +INIDRV: LDA #$FF ;Return Error - Not Implemented + RTS + +;chdrv() - Set Current Drive/Disk +;Args: A = Drive# | Disk# +;Returns: A = Result (0 - Success) +; Y = Error Code (0 = None) +CHDRV: JSR FSVDRV ;Validate Drive Number + BCS .DRVERR ;If Invalid Return Error + TAY ;Set Drive Number + SEC ;Set Mode to Change + BCS .GETDRV ;Execute DRIVE Command and Return Result + +;getdrv() - Get Current Drive/Disk +;Returns: A = Drive# | Disk# (0=Failure) +; Y = Error Code (0 = None) +GETDRV: CLC ;Set Mode to Get +.GETDRV LDA #'V' ;Set Command to DRIVE + BNE .FSCMDX ;Execute and Return Result + +;drvnam(drv) - Get Drive Name +;Args: A = Drive Number +;Returns: A = Drive Name (0=Failure) +; Y = Error (0=None) +DRVNAM: JSR FSVDRV ;Validate Drive Number + BCS .DRVERR ;If Valid + LDY #0 ; Set Error to None + ADC #'@' ; Return Drive Letter +.DRVERR RTS diff --git a/include/run6502/filesys.h02 b/include/run6502/filesys.h02 new file mode 100644 index 0000000..2b23792 --- /dev/null +++ b/include/run6502/filesys.h02 @@ -0,0 +1,37 @@ +/***************************************************** + * filesys - FIle System Module for run6502 emulator * + *****************************************************/ + +/* Change Drive * + * Args: char d - Drive ID | Disk # * + * Returns: char r - Result, 0=Success * + * char e - Error, 0=None */ +char chdrv(); + +/* Drive Name * + * Args: char d - Drive ID | Disk # * + * Returns: char n - Drive Name * + * 0 = Invalid Device * + * char e - Error, 0=None */ +char drvnam(); + +/* Get Drive * + * Returns: char d - Current Drive/Disk * + * 0 = None or Error * + * char e - Error, 0=None */ +char getdrv(); + +/* Remove File * + * Args: char d - Drive ID | Disk # * + * int &name - File Name * + * Returns: char r - Result, 0=Success * + * char e - Error, 0=None */ +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 */ +char rename(); diff --git a/test/dirtest.c02 b/test/dirtest.c02 new file mode 100644 index 0000000..68fcdcc --- /dev/null +++ b/test/dirtest.c02 @@ -0,0 +1,60 @@ +/***************************************** + * TESTDIR - Test/Demo Module direct.h02 * + *****************************************/ + +//Specify System Header using -H option +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +const char dir = "TEMPDIR"; +char d, err, i, n, r; +char m[128], s[128]; +char aa,xx,yy; +main: + prtcwd(); + mrdir(); + goto exit; + +void prtcwd() { + puts("GETCWD: "); + n, err = getcwd(0, &s); + if (err) goto error; + putln(&s); +} + +void chkerr() { + if (err) { + printf(err, "ERROR %d - "); + ferror(0, m); putln(m); + } + else if (r) putln("FAILED"); + else putln("SUCCESS"); +} + +void chgdir(aa, yy, xx) { + setdst(); printf("CHDIR '%s': "); + n, err = chdir(0,yy,xx); chkerr(); + prtcwd(); +} + +void mrdir() { + setdst(&dir); printf("MKDIR(\"%s\"): "); + r,err = mkdir(&dir); chkerr(); + chgdir(&dir); + anykey(); + chgdir(".."); + setdst(&dir); printf("RMDIR(\"%s\"): "); + r,err = rmdir(&dir); chkerr(); +} + +error: + printf(err, "ERROR %d%n"); + goto exit; diff --git a/test/diskdir.c02 b/test/diskdir.c02 new file mode 100644 index 0000000..33d5417 --- /dev/null +++ b/test/diskdir.c02 @@ -0,0 +1,55 @@ +/********************************* + * DISKDIR - Read Disk Directory * + *********************************/ + +//Specify System Header using -H option +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct dirent entry; +struct dirhdr header; + +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; +char aa,ff,xx,yy,zz; //Function Arguments + +main: + setdst(dir); printf("OPENING DIRECTORY '%s'%n"); + dp, err = opndir(0, 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"); + + putln("READING ENTRIES"); + do { + n, err = rddir(dp, entry); + if (n) putln(entry.name); + } while (n); + if (err) goto error; + putln("END OF DIRECTORY"); + + clsdir(dp); + goto exit; + +error: + printf(err, "ERROR %d%n"); + goto exit; diff --git a/test/filetest.c02 b/test/filetest.c02 new file mode 100644 index 0000000..9c154d7 --- /dev/null +++ b/test/filetest.c02 @@ -0,0 +1,133 @@ +/***********(((************************ + * FILETEST - Test/Demo Module fileio * + **************************************/ + +//Specify System Header using -H option +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char txtfil = "TESTFILE.TXT"; +const char savfil = "SAVEFILE.TXT"; +char fp; //Text File Pointer +char err; //Error Code +char c; //Character Read from File +char i; //Loop Index Variable +char n; //Number of Characters to Write +int addr; //End Address for load() +char l[255]; //Array for load() +char r[255]; //Array for fread() +char s[128]; //String for fgets() +const char save = "ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210"; +const char bnry = "ZYW1XVU2TS3RQ4PO5NM6LKJI7HG8FED9CBA0"; +char aa,xx,yy,zz; //Function Arguments + +main: + clrscr(); + fsinit(); //Initialize File System + fp = opnfil(#MWRITE, &txtfil); + if (fp) { + printf(fp, "WRITING TO CHANNEL %d%n"); + wstrng(fp); //Test fputs() + wbnry(fp); //Test fwrite() + wchars(fp); //Test fputc() + } + sfile(0, &savfil); + clsfil(fp); + + fp = opnfil(#MREAD, &txtfil); + if (fp) { + printf(fp, "READING CHANNEL %d%n"); + rstrng(fp); + rbnry(fp); + rchars(fp); + } + clsfil(fp); + lfile(#MABSLT, &savfil); //Test fload() + + goto exit; + +void error(aa, yy, xx) { + printf(); + goto exit; +} + +void opnfil(aa,yy,xx) { + puts("OPENING "); puts(.,yy,xx); + printf(aa, " WITH OPTIONS $%h%n"); + aa, yy = fopen(aa,yy,xx); + if (aa) printf(aa,"OPENED ON CHANNEL %d%n"); + else error(yy, "ERROR %d OPENING FILE%n"); + return aa; +} + +void wbnry(aa) { + fsaddr(&bnry); + n, err = fwrite(@bnry, aa); + if (err) printf(err, "ERROR %d%n"); +} + +void wchars(aa) { + for (i='0'; i<='Z'; i++) {fputc(i, aa);} +} + +void wstrng(aa) { + fputs(aa, "THE QUICK BROWN FOX "); + fputln(aa, "JUMPED OVER THE LAZY DOG"); +} + +void sfile(aa, yy, xx) { + setdst(); printf("SAVING FILE %s%n"); + setdst(&save); printf("START ADDRESS %w%n"); + setdst(&bnry); printf("END ADDRESS %w%n"); + fsname(.,yy,xx); //Set Filename + fsaddr(&save); //Set Start Address + err, addr = fsave(aa, &bnry); + if (err) printf(err, "ERROR %d%n"); + else putln("FILE SAVED"); +} + +void rbnry(aa) { + fsaddr(&r); + n, err = fread(@bnry, aa); + if (err) printf(err, "ERROR %d%n"); + else putln(&r); +} + +void lfile(aa, yy, xx) { + setdst(); printf("LOADING FILE %s%n"); + memclr(255, &l); printf("START ADDRESS %w%n"); + fsname(.,yy,xx); //Set Filename + fsaddr(&l); //Set Load Address + err, addr = fload(aa); + if (err) printf(err, "ERROR %d%n"); + else { + setdst(addr); printf("END ADDRESS %w%n"); + putln(&l); + } +} + +void rchars(aa) { + while(!feof(aa)) { + c, err = fgetc(aa); if (err) break; + putc(c); + } + newlin(); +} + +void rstrng(aa) { + n, err = fgets(aa, &s); + if (err) printf(err, "ERROR %d%n"); + else puts(&s); +} + +void clsfil(aa) { + printf(aa, "CLOSING CHANNEL %d%n"); + fclose(aa); +} diff --git a/test/fstest.c02 b/test/fstest.c02 new file mode 100644 index 0000000..3cea21b --- /dev/null +++ b/test/fstest.c02 @@ -0,0 +1,80 @@ +/***************************************** + * FSTEST - Test/Demo Module filesys.h02 * + *****************************************/ + +//Specify System Header using -H option +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +const char dir = "TEMPDIR"; +const char oldnam = "OLDFILE.TMP"; +const char newnam = "NEWFILE.TMP"; + +char d, e, err, f, i, n, r; +char m[128]; +char aa,xx,yy; +main: + newfil(); + renfil(); + delfil(); + prtdrv(); + chgdrv(); + goto exit; + +void chkerr() { + puts(": "); + if (err) { + e = ferror(0, &m); + printf(e, "ERROR %d - "); + putln(&m); + } + else if (r) putln("FAILED"); + else putln("SUCCESS"); +} + +void prtdrv() { + d, err = getdrv(); printf(d,"GETDRV: %d "); chkerr(); + printf(drvnam(d), "DRVNAM: '%c'"); chkerr(); +} + +void newfil() { + puts("CREATING FILE "); puts(oldnam); + f, err = fopen(#MWRITE, oldnam); chkerr(); + puts("WRITING TO FILE "); + n, err = fputln(f, "FILE CONTENTS"); chkerr(); + puts("CLOSING FILE "); + err = fclose(f); chkerr(); +} + +void renfil() { + puts("RENAMING "); puts(oldnam); + puts(" TO "); puts(newnam); + fsname(oldnam); + r, err = rename(newnam); chkerr(); +} + +void delfil() { + puts("REMOVING "); puts(newnam); + r, err = remove(newnam); chkerr(); +} + +void chgdrv() { + for (i=0; i<#DRIVES; i++) { + d = drive[i]; + printf(d, "CHDRV(%d) "); + printf(drvnam(d), "'%c'"); + r, err = chdrv(d); chkerr(); + } +} + +error: + printf(err, "ERROR %d%n"); + goto exit;