mirror of https://github.com/RevCurtisP/C02.git
Added c02 module args
This commit is contained in:
parent
142fe13749
commit
8e9beb39dc
|
@ -0,0 +1,60 @@
|
|||
Command Line Argument parsing module for C02 Programs
|
||||
|
||||
This is module provides functions for parsing command line arguments
|
||||
passed into a program.
|
||||
|
||||
Although 6502 based computers rarely use a shell interface, this module
|
||||
allows arguments to be specified when executing a program on several
|
||||
popular systems.
|
||||
|
||||
On the Apple I, the syntax is
|
||||
|
||||
0300R arg1 arg2 arg3 ...
|
||||
|
||||
and on Commodore computers, the syntax is
|
||||
|
||||
RUN:"arg1 arg2 arg3 ...
|
||||
|
||||
At the beginning of the program use the directives
|
||||
|
||||
#include <stddef.h02>
|
||||
#include <args.h02>
|
||||
|
||||
The following functions are defined:
|
||||
|
||||
r = argset(); Sets up argument list for parsing. This function
|
||||
must be called only once and before any calls to
|
||||
the argget() function.
|
||||
|
||||
Returns 0 if successful, or 255 if no argument
|
||||
list was specified or argument parsing is not
|
||||
supported.
|
||||
|
||||
A result of success does not necessarily mean that
|
||||
any arguments were passed, only that the program
|
||||
was executed using the appropriate syntax.
|
||||
|
||||
n = argget(&s); Reads the next argument into string s.
|
||||
|
||||
Returns the length of the argument. After the
|
||||
last argument, sets s to an empty string and
|
||||
returns 0.
|
||||
|
||||
Note: Sets dstptr to the address of s.
|
||||
|
||||
Note: This library expects the following functions to be defined:
|
||||
|
||||
setdst(); Set destination pointer.
|
||||
|
||||
along with the zero page variable
|
||||
|
||||
dstptr Destination pointer.
|
||||
|
||||
the variables
|
||||
|
||||
sysbfr System buffer
|
||||
sysbfp System buffer position.
|
||||
|
||||
and the constant
|
||||
|
||||
#SYSBFL System buffer length.
|
|
@ -0,0 +1,18 @@
|
|||
;Module arg,h02 Assembly Language Routines for Apple 1 Computer
|
||||
|
||||
;Command Line Arguments are specified in the form:
|
||||
; 0300R arg1 arg2 arg3...
|
||||
;Arguments are separated by one or more spaces
|
||||
|
||||
SUBROUTINE ARGS
|
||||
|
||||
;Argument Parser Constants
|
||||
ARGFLG EQU $00 ;Command Arguments Supported
|
||||
ARGDLM EQU $A0 ;Argument Separator (Sapce)
|
||||
ARGTRM EQU $8D ;Argument Terminator (C/R)
|
||||
ARGMSK EQU $7F ;Mask: Strip High Bit
|
||||
|
||||
INCLUDE "argset.a02" ;Generic ARGSET Routine
|
||||
INCLUDE "argget.a02" ;Generic ARGGET Routine
|
||||
|
||||
ENDSUBROUTINE
|
|
@ -0,0 +1,20 @@
|
|||
/*************************************
|
||||
* Command Line Parameters Processor *
|
||||
*************************************/
|
||||
|
||||
#define ARGFLG $00 //Argument Parser Flag
|
||||
#define ARGSEP $20 //Argument Delimiter
|
||||
#define ARGEND $8D //Argument Terminator
|
||||
#define ARGMSK $7F //Argument Mask
|
||||
|
||||
/* Set up Argument List *
|
||||
* Returns: char $00 = Success *
|
||||
* $FF = No Args */
|
||||
void argset();
|
||||
|
||||
/* Get Next Argument *
|
||||
* Setup: argset() Before First Call *
|
||||
* Args: &s - String to Populate *
|
||||
* Returns: char Length of String *
|
||||
* 0 = End of List */
|
||||
void argget();
|
|
@ -0,0 +1,37 @@
|
|||
;Module ARGS generic ARGGET routinr
|
||||
|
||||
;argget(s) - Read Next Argument into String s
|
||||
;Args: X,Y - Address of String
|
||||
;Uses: SYSBFR - System Buffer
|
||||
; SYSBFL - System Buffer Length
|
||||
;Sets: DSTPTR - Address of String
|
||||
;Updates: SYSBFP - System Buffer Position
|
||||
;Returns: A,Y = Argument Length
|
||||
; X = New System Buffer Position
|
||||
ARGGET: JSR SETDST ;Set Destination Pointer
|
||||
LDY #0 ;Initialize Destination Index
|
||||
LDX SYSBFP ;Get System Buffer Position
|
||||
.GLOOP: LDA SYSBFR,X ;Get Next Character
|
||||
BEQ .GDONE ;If String Terminator
|
||||
CMP #ARGTRM ;or Argument Terminator
|
||||
BEQ .GDONE ; Terminate String and Return
|
||||
CMP #ARGDLM ;Else If Argument Delimiter
|
||||
BNE .GSKIP ;
|
||||
INX ; Bump Buffer Index Past Delimiter
|
||||
CPY #0 ; If Leading Space
|
||||
BEQ .GLOOP ; Check Next Character
|
||||
BNE .GDONE ; Terminate String and Returns
|
||||
.GSKIP LDA SYSBFR,X ;Else Get Character from Buffer
|
||||
AND #ARGMSK ; Apply Bit Mask
|
||||
STA (DSTPTR),Y ; Copy to Destination String
|
||||
INY ; Increment Destination Index
|
||||
BMI .GDONE ; If > 128, Return as Length
|
||||
INX ; Increment Buffer Index
|
||||
CPX #SYSBFL ; If Less Than Buffer Length
|
||||
BCC .GLOOP ; Loop
|
||||
.GDONE LDA #0 ;
|
||||
STA (DSTPTR),Y ;Terminate Destination String
|
||||
.GRTRN STX SYSBFP ;Set System Buffer Position
|
||||
TYA ;Return Argument Length
|
||||
RTS
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
;Module arg,h02 Assembly Language Routines
|
||||
;Command Line Arguments Not Supported
|
||||
|
||||
SUBROUTINE ARGS
|
||||
|
||||
;Argument Parser Constants
|
||||
ARGFLG EQU $FF ;Command Arguments Not Supported
|
||||
ARGDLM EQU $00 ;Argument Separator (NUL)
|
||||
ARGTRM EQU $00 ;Argument Terminator (NUL)
|
||||
|
||||
;argset() - Set Up Argument List
|
||||
;Returns: A = $FF - No Arguments Found
|
||||
ARGSET: LDA #$FF ;Return No Arguments Found
|
||||
|
||||
;argget(s) - Read Next Argument
|
||||
;Args: X,Y - Pointer to String
|
||||
;Sets: DSTPTR - Destination Pointer
|
||||
; (DSTPTR) to Empty String
|
||||
;Returns: A = 0 - No More Arguments
|
||||
ARGGET: JSR SETDST ;Set Destination Pointer0[
|
||||
LDY #0 ;Set String Length to Zero
|
||||
TAY ;
|
||||
STA (DSTPTR),Y ;Make String Empty
|
||||
RTS ;and Return Length Zero
|
||||
|
||||
ENDSUBROUTINE
|
|
@ -0,0 +1,19 @@
|
|||
/*************************************
|
||||
* Command Line Parameters Processor *
|
||||
*************************************/
|
||||
|
||||
#define ARGFLG $00 //Argument Parser Flag
|
||||
#define ARGSEP $20 //Argument Delimiter
|
||||
#define ARGEND $8D //Argument Terminator
|
||||
|
||||
/* Set up Argument List *
|
||||
* Returns: char $00 = Success *
|
||||
* $FF = No Args */
|
||||
void argset();
|
||||
|
||||
/* Get Next Argument *
|
||||
* Setup: argset() Before First Call *
|
||||
* Args: &s - String to Populate *
|
||||
* Returns: char Length of String *
|
||||
* 0 = End of List */
|
||||
void argget();
|
|
@ -0,0 +1,12 @@
|
|||
;Module ARGS generic ARGGET routinr
|
||||
|
||||
;argset() - Set Up Argument List
|
||||
;Skips Spaces Between 'R' and First Argument
|
||||
;Returns: A = $FF - No Arguments Found
|
||||
ARGSET: LDX SYSBFP ;Get Buffer Position
|
||||
LDA SYSBFR,X ;Get Character At Position
|
||||
BEQ .SNOPE ;If Not NUL
|
||||
LDA #$FF ; Return Success
|
||||
.SNOPE EOR #$FF ;Else Return No Arguments
|
||||
RTS
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
;Module arg,h02 common functions for Commodore 8-bit computers
|
||||
|
||||
;Command Line Arguments are specified in the form:
|
||||
; RUN:"arg1 arg2 arg3..
|
||||
;The colon terminates the RUN statement
|
||||
;The quote ensures that the arguments are not tokenized
|
||||
;The list may optionally be terminated with a quote
|
||||
|
||||
SUBROUTINE ARGS
|
||||
|
||||
;Argument Parser Constants
|
||||
ARGFLG EQU $00 ;Command Arguments Supported
|
||||
ARGDLM EQU $20 ;Argument Separator (Space)
|
||||
ARGTRM EQU $22 ;Argument Terminator (Quotes)
|
||||
ARGMSK EQU $FF ;Mask: No Change
|
||||
|
||||
;argset() - Set Up Argument List for argget() calls
|
||||
;Uses: SYSBFR - System Buffer
|
||||
; SYSBFP - System Buffer Position
|
||||
;Sets: SYSBFP - New Buffer Position
|
||||
;Affects: X,C
|
||||
;Returns: A = $00 - Success
|
||||
; $FF - No Arguments Specified
|
||||
ARGSET: LDX SYSBFP ;Set Index to System Buffer Position
|
||||
LDA SYSBFR,X ;
|
||||
CMP #':' ;If First Character is a Colon
|
||||
BNE .NOARGS ;
|
||||
INX ;
|
||||
LDA SYSBFR,X ;
|
||||
CMP #$22 ;and Second Character is a Quote
|
||||
BNE .NOARGS ;
|
||||
INX ; Increment Index Past Quote
|
||||
LDA #$FF ; and Return Success
|
||||
BNE .SDONE ;Else
|
||||
.NOARGS LDA #0 ; Terminate Argument List
|
||||
STA SYSBFR,X ; Set Buffer Position
|
||||
.SDONE STX SYSBFP ; and Return Failure
|
||||
EOR #$FF ;Invert Result
|
||||
RTS ;
|
||||
|
||||
INCLUDE "argget.a02" ;Generic ARGGET Routine
|
||||
|
||||
ENDSUBROUTINE
|
|
@ -0,0 +1,19 @@
|
|||
/*************************************
|
||||
* Command Line Parameters Processor *
|
||||
*************************************/
|
||||
|
||||
#define ARGFLG $00 //Argument Parser Flag
|
||||
#define ARGSEP $20 //Argument Delimiter
|
||||
#define ARGEND $8D //Argument Terminator
|
||||
|
||||
/* Set up Argument List *
|
||||
* Returns: char $00 = Success *
|
||||
* $FF = No Args */
|
||||
void argset();
|
||||
|
||||
/* Get Next Argument *
|
||||
* Setup: argset() Before First Call *
|
||||
* Args: &s - String to Populate *
|
||||
* Returns: char Length of String *
|
||||
* 0 = End of List */
|
||||
void argget();
|
|
@ -0,0 +1,18 @@
|
|||
;Module arg,h02 Assembly Language Routines for Apple 1 Computer
|
||||
|
||||
;Command Line Arguments are specified in the form:
|
||||
; 0300R arg1 arg2 arg3...
|
||||
;Arguments are separated by one or more spaces
|
||||
|
||||
SUBROUTINE ARGS
|
||||
|
||||
;Argument Parser Constants
|
||||
ARGFLG EQU $00 ;Command Arguments Supported
|
||||
ARGDLM EQU $20 ;Argument Separator (Sapce)
|
||||
ARGTRM EQU $00 ;Argument Terminator (NUL)
|
||||
ARGMSK EQU $FF ;Mask: No Change
|
||||
|
||||
INCLUDE "argset.a02" ;Generic ARGGET Routine
|
||||
INCLUDE "argget.a02" ;Generic ARGGET Routine
|
||||
|
||||
ENDSUBROUTINE
|
|
@ -0,0 +1,20 @@
|
|||
/*************************************
|
||||
* Command Line Parameters Processor *
|
||||
*************************************/
|
||||
|
||||
#define ARGFLG $00 //Argument Parser Flag
|
||||
#define ARGSEP $20 //Argument Delimiter
|
||||
#define ARGEND $00 //Argument Terminator
|
||||
#define ARGMSK $FF //Argument Mask
|
||||
|
||||
/* Set up Argument List *
|
||||
* Returns: char $00 = Success *
|
||||
* $FF = No Args */
|
||||
void argset();
|
||||
|
||||
/* Get Next Argument *
|
||||
* Setup: argset() Before First Call *
|
||||
* Args: &s - String to Populate *
|
||||
* Returns: char Length of String *
|
||||
* 0 = End of List */
|
||||
void argget();
|
|
@ -13,35 +13,21 @@
|
|||
#include <stdiox.h02>
|
||||
#include <string.h02>
|
||||
#include <stringl.h02>
|
||||
#include <stringm.h02>
|
||||
|
||||
char c,n,r;
|
||||
char c,n,p,r;
|
||||
char arg[128];
|
||||
int p;
|
||||
|
||||
void prtbfr() {
|
||||
for (n=0; n<#SYSBFL; n++) {
|
||||
c = sysbfr[n];
|
||||
select (c) {
|
||||
case 0: putc('@');
|
||||
default: if (c < ' ') putc('.');
|
||||
else putc(c);}
|
||||
}
|
||||
newlin();
|
||||
}
|
||||
|
||||
main:
|
||||
r,p = setarg();
|
||||
if (r) {putln("NO ARGS"); goto exit;}
|
||||
|
||||
putln("ARGS");
|
||||
n = 0;
|
||||
while () {
|
||||
setsrc(p); p = strget(arg);
|
||||
if (arg[0] == 0) break;
|
||||
setdst(arg); printf(n, "%d %s%n");
|
||||
n++;
|
||||
}
|
||||
|
||||
if (#ARGFLG) putln("ARGS NOT SUPPORTED");
|
||||
|
||||
p = argset(); printf(p, "ARGSET() = %d%n");
|
||||
if (p) putln("NO ARGS SPECIFIED");
|
||||
|
||||
do {
|
||||
r = argget(arg);
|
||||
printf(r, "ARGGET() = %d, ARG = %s%n");
|
||||
} while (r);
|
||||
|
||||
goto exit;
|
||||
|
||||
|
|
Loading…
Reference in New Issue