mirror of
https://github.com/RevCurtisP/C02.git
synced 2025-02-19 19:31:04 +00:00
Implemented File I/O, Directory, and File System modules for run6592 emulator
This commit is contained in:
parent
88fd3c7dda
commit
e9d5c04f87
30
include/direct.a02
Normal file
30
include/direct.a02
Normal file
@ -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
|
37
include/direct.h02
Normal file
37
include/direct.h02
Normal file
@ -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();
|
34
include/dirent.a02
Normal file
34
include/dirent.a02
Normal file
@ -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
|
50
include/dirent.h02
Normal file
50
include/dirent.h02
Normal file
@ -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();
|
@ -1,65 +1,99 @@
|
|||||||
;C02 Module file.h02 Assembly Lamnguage
|
;C02 Module file.h02 Assembly Lamnguage
|
||||||
;Template Code
|
;Template Code
|
||||||
|
|
||||||
;Sample Device Numbers
|
DRIVES EQU 0 ;Number of Disk Drives (None)
|
||||||
CASST1 EQU 0
|
DRIVE BYTE 0 ;List of Drive Device Numbers
|
||||||
MODEM1 EQU 2
|
|
||||||
PRNTR1 EQU 3
|
|
||||||
PRNTR2 EQU 4
|
|
||||||
DRIVE1 EQU 5
|
|
||||||
DRIVE2 EQU 6
|
|
||||||
DRIVE3 EQU 7
|
|
||||||
DRIVE4 EQU 8
|
|
||||||
|
|
||||||
;Disk Numbers (Within Drive)
|
DISKS EQU 0 ;Number of Disks in Drive (None)
|
||||||
DISK0 EQU $00
|
DISK BYTE 0 ;List of Disk IDs
|
||||||
DISK1 EQU $40
|
|
||||||
|
|
||||||
;File Open Modes
|
;File Open Modes
|
||||||
MWRITE EQU $80
|
MWRITE EQU $80
|
||||||
MREAD EQU $00
|
MREAD EQU $00
|
||||||
|
|
||||||
|
; File Load Modes
|
||||||
;fflush(chan) - Flush Write Buffer to File
|
MRELCT EQU $00 ;Relocate (Load at Specified Address)
|
||||||
;Args: A = Mode + Drive ID
|
MABSLT EQU $80 ;Absolute (Load at Address in File Header)
|
||||||
;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)
|
|
||||||
|
|
||||||
;fclose(chan) - Close File
|
;fclose(chan) - Close File
|
||||||
;Args: A = Channel Number
|
;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
|
;fgetc(chan) - Read Character from File
|
||||||
;Args: A = Channel Number
|
;Args: A = Channel Number
|
||||||
;Returns: A = Character
|
;Returns: A = Character
|
||||||
; Y = Error Code
|
; Y = Error Code ($00 - Success)
|
||||||
; $00 - Success
|
FGETC: ;Return Error - Not Implemented
|
||||||
; $FF - Not Implemented
|
|
||||||
FGETC: ;Return Error - Not Implemented (fall through)
|
|
||||||
|
|
||||||
;fgets(chan, &s) - Read String from File
|
;fgets(chan, &s) - Read String from File
|
||||||
;Args: A = Channel Number
|
;Args: A = Channel Number
|
||||||
; Y,X = Pointer to String Array
|
; Y,X = Address of String
|
||||||
;Returns: A = Number of Bytes Read
|
;Returns: A = Number of Bytes Read
|
||||||
; Y = Error Code
|
; Y = Error Code ($00 - Success)
|
||||||
; $00 - Success
|
FGETS: ;Return Error - Not Implemented
|
||||||
; $FF - Not Implemented
|
|
||||||
FGETS: ;Return Error - Not Implemented (fall through)
|
;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
|
;fread(chan, count) - Read Bytes from File
|
||||||
;Args: A = Channel Number
|
;Setup: Call FSADDR with array address
|
||||||
; Y = Number of Bytes to Read
|
;Args: A = Number of Bytes to Read
|
||||||
;Uses: DSTLO,DSTHI - Pointer Destination Array
|
; Y = Channel Number
|
||||||
;Returns: A = Number of Bytes Read
|
;Returns: A = Number of Bytes Read
|
||||||
; Y = Error Code
|
; Y = Error Code ($00 - Success)
|
||||||
; $00 - Success
|
|
||||||
; $FF - Not Implemented
|
|
||||||
FREAD: ;Return Error - Not Implemented (fall through)
|
FREAD: ;Return Error - Not Implemented (fall through)
|
||||||
|
|
||||||
;fwrite(chan, count) - Write Bytes to File
|
;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
|
LDY $FF ;and Error - Not Implemented
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
;feof(chan) - Check for End of File
|
;ferror(chan, &msg) - Check for Error
|
||||||
;Args: A = Channel Number
|
;Args: A = Channel Number
|
||||||
;Returns: A = Platform Specific EOF Value
|
; Y,X = String Address
|
||||||
; $00 - Not End of File
|
;Returns: A = Last Error ($FF - Invalid Channel)
|
||||||
; $FF - Not Implemented
|
; Y = Error (0=None)
|
||||||
FEOF: ;Return Error - Not Implemented (fall through)
|
FERROR: LDA #$FF ;Return Invalid Channel
|
||||||
|
TAY ;and Error - Not Implemented
|
||||||
;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
|
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
;Internal routines are all prefixed with FS
|
;fsinit() - Initialize File System
|
||||||
|
FSINIT: ;No Action (Fall Through)
|
||||||
;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
|
|
||||||
|
|
||||||
|
;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
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
/******************************************
|
/***************************************
|
||||||
* file - Standard File Functions for C02 *
|
* fileio - File I/O Functions for C02 *
|
||||||
******************************************/
|
* Non-Functional Template Header *
|
||||||
|
***************************************/
|
||||||
|
|
||||||
/* Device List */
|
#define DRIVES 0 //Number of Disk Drives
|
||||||
enum {CASST1, MODEM1, PRNTR1, PRNTR2,
|
const char drive[]; //Disk Drives
|
||||||
DRIVE1, DRIVE2, DRIVE3, DRIVE4};
|
|
||||||
|
#define DISKS 0 //Number of Drives in Disk
|
||||||
|
const char disk[];
|
||||||
|
|
||||||
/* File Open Modes */
|
/* File Open Modes */
|
||||||
#define MWRITE $80 //Open File for Write
|
#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 MRELCT $00 //Relocate (Load at Specified Address)
|
||||||
#define MABSLT $80 //Absolute (Load at Address in File Header)
|
#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 *
|
/* End of File *
|
||||||
* Loads File into Memory *
|
* Check for End of File Condition *
|
||||||
* Args: d - Options | DeviceID *
|
* Args: char f - File Channel *
|
||||||
^ &n - Filename *
|
* Returns: char e = EOF Indicator *
|
||||||
* Returns: Error Code (0=None) *
|
* (0 if not at end of file *
|
||||||
* Load Address */
|
* 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();
|
char fload();
|
||||||
|
|
||||||
/* File Save *
|
/* File Open *
|
||||||
* Save File from Memory *
|
* Open Specified File *
|
||||||
* Args: d - Options | DeviceID *
|
* Args: char d - Options | Device *
|
||||||
^ &n - Filename *
|
^ int &n - Filename *
|
||||||
* Returns: Error Code (0=None) */
|
* Returns: char c - Channel (0=Error) *
|
||||||
char fsave();
|
* char e - Error, 0=None *
|
||||||
|
* 255 = Not Implemented */
|
||||||
/* File Open *
|
|
||||||
* Opens File Specified by Name *
|
|
||||||
* Args: d - Options | DeviceID *
|
|
||||||
^ &n - Filename *
|
|
||||||
* Returns: File Pointer (0=Error) *
|
|
||||||
Error Code (0=None) */
|
|
||||||
char fopen();
|
char fopen();
|
||||||
|
|
||||||
/* File Close *
|
/* File Put Character *
|
||||||
* Closes File Opened to File Pointer *
|
* Write Character to File *
|
||||||
* Args: fp - file pointer */
|
* Args: char c - Character *
|
||||||
char fclose();
|
* 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 *
|
/* End of File *
|
||||||
* Check for End of File Condition *
|
* Check for End of File Condition *
|
||||||
@ -51,83 +167,3 @@ char fclose();
|
|||||||
* 255 if not implemented *
|
* 255 if not implemented *
|
||||||
* or non-zero EOF value) */
|
* or non-zero EOF value) */
|
||||||
char feof();
|
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();
|
|
||||||
|
43
include/filesys.a02
Normal file
43
include/filesys.a02
Normal file
@ -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
|
42
include/filesys.h02
Normal file
42
include/filesys.h02
Normal file
@ -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();
|
@ -39,3 +39,4 @@ void prhex(); //Print Low Nybble of Accumulator as Hex Digit
|
|||||||
//System Labels
|
//System Labels
|
||||||
start: //Start of Code
|
start: //Start of Code
|
||||||
exit: //Return to Operating System
|
exit: //Return to Operating System
|
||||||
|
|
||||||
|
49
include/run6502/direct.a02
Normal file
49
include/run6502/direct.a02
Normal file
@ -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
|
34
include/run6502/direct.h02
Normal file
34
include/run6502/direct.h02
Normal file
@ -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();
|
49
include/run6502/dirent.a02
Normal file
49
include/run6502/dirent.a02
Normal file
@ -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
|
42
include/run6502/dirent.h02
Normal file
42
include/run6502/dirent.h02
Normal file
@ -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();
|
241
include/run6502/fileio.a02
Normal file
241
include/run6502/fileio.a02
Normal file
@ -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
|
154
include/run6502/fileio.h02
Normal file
154
include/run6502/fileio.h02
Normal file
@ -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();
|
60
include/run6502/filesys.a02
Normal file
60
include/run6502/filesys.a02
Normal file
@ -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
|
37
include/run6502/filesys.h02
Normal file
37
include/run6502/filesys.h02
Normal file
@ -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();
|
60
test/dirtest.c02
Normal file
60
test/dirtest.c02
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*****************************************
|
||||||
|
* TESTDIR - Test/Demo Module direct.h02 *
|
||||||
|
*****************************************/
|
||||||
|
|
||||||
|
//Specify System Header using -H option
|
||||||
|
#include <screen.h02>
|
||||||
|
#include <stddef.h02>
|
||||||
|
#include <stdlib.h02>
|
||||||
|
#include <intlib.h02>
|
||||||
|
#include <stdio.h02>
|
||||||
|
#include <stdiox.h02>
|
||||||
|
#include <string.h02>
|
||||||
|
#include <fileio.h02>
|
||||||
|
#include <direct.h02>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
55
test/diskdir.c02
Normal file
55
test/diskdir.c02
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*********************************
|
||||||
|
* DISKDIR - Read Disk Directory *
|
||||||
|
*********************************/
|
||||||
|
|
||||||
|
//Specify System Header using -H option
|
||||||
|
#include <screen.h02>
|
||||||
|
#include <stddef.h02>
|
||||||
|
#include <stdlib.h02>
|
||||||
|
#include <intlib.h02>
|
||||||
|
#include <stdio.h02>
|
||||||
|
#include <stdiox.h02>
|
||||||
|
#include <memory.h02>
|
||||||
|
#include <string.h02>
|
||||||
|
#include <fileio.h02>
|
||||||
|
#include <dirent.h02>
|
||||||
|
|
||||||
|
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;
|
133
test/filetest.c02
Normal file
133
test/filetest.c02
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/***********(((************************
|
||||||
|
* FILETEST - Test/Demo Module fileio *
|
||||||
|
**************************************/
|
||||||
|
|
||||||
|
//Specify System Header using -H option
|
||||||
|
#include <screen.h02>
|
||||||
|
#include <stddef.h02>
|
||||||
|
#include <stdlib.h02>
|
||||||
|
#include <intlib.h02>
|
||||||
|
#include <stdio.h02>
|
||||||
|
#include <stdiox.h02>
|
||||||
|
#include <string.h02>
|
||||||
|
#include <memory.h02>
|
||||||
|
#include <fileio.h02>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
80
test/fstest.c02
Normal file
80
test/fstest.c02
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*****************************************
|
||||||
|
* FSTEST - Test/Demo Module filesys.h02 *
|
||||||
|
*****************************************/
|
||||||
|
|
||||||
|
//Specify System Header using -H option
|
||||||
|
#include <screen.h02>
|
||||||
|
#include <stddef.h02>
|
||||||
|
#include <stdlib.h02>
|
||||||
|
#include <intlib.h02>
|
||||||
|
#include <stdio.h02>
|
||||||
|
#include <stdiox.h02>
|
||||||
|
#include <string.h02>
|
||||||
|
#include <fileio.h02>
|
||||||
|
#include <filesys.h02>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
Loading…
x
Reference in New Issue
Block a user