diff --git a/doc/func-idx.txt b/doc/func-idx.txt index f0a380c..999c6f2 100644 --- a/doc/func-idx.txt +++ b/doc/func-idx.txt @@ -32,7 +32,8 @@ fsptr file File System Pointer Get unused file pointer. fssrc file File Set Source Set source array for fwrite. fstat file File System Status Get file pointer status. fwrite file File Write Write bytes to file. -getchr stdio Get Character Read character from keyboard. +getc stdio Get Character Read character from keyboard. +gets stdio Get String Read string from keyboard. isalnm ctype Is Alphanumeric Return TRUE if character is A-Z, a-z, or 0-9. isalph ctype Is Alphabetic Return TRUE if character is A-Z or a-z. isbdgt ctype Is Binary Digit Return TRUE if character is 0 or 1. @@ -64,11 +65,10 @@ ptrsub pointer Pointer Subtract Subtract value from pointer. ptrcmp pointer Pointer Compare Compare pointer against address. ptrsav pointer Pointer Save Save pointer into two-byte array. ptrrst pointer Pointer Restore Restore pointer from two-byte array. -putchr stdio Put Character Write character to screen. -getstr stdio Get String Read string from keyboard. -outstr stdio Output String Write string to screen. -outsub stdio Output Substring Write substring to screen. -putstr stdio Put String Write string plus newline to screen. +putc stdio Put Character Write character to screen. +puts stdio Output String Write string to screen. +putsub stdio Output Substring Write substring to screen. +putln stdio Put String Write string plus newline to screen. rand stdlib Random Generate pseudorandom number. rands stdlib Random Seed Seed random number generator. shiftl stdlib Shift Left Shift byte left specified number of bits. diff --git a/doc/stdio.txt b/doc/stdio.txt index 002ed01..045be56 100644 --- a/doc/stdio.txt +++ b/doc/stdio.txt @@ -6,16 +6,16 @@ At the beginning of the program use the directives The following functions are defined: - c = getchr(); Waits for a keypress and returns the cleaned + c = getc(); Waits for a keypress and returns the cleaned ASCII value corresponding to the pressed key. Note: Aliased to getkey() from system library. - putchr(c); Writes character c to the screen. + putc(c); Writes character c to the screen. Note: Aliased to prchr() from system library. - r = getstr(&s); Reads a maximum of 128 characters from keyboard + r = gets(&s); Reads a maximum of 128 characters from keyboard until the Return/Enter key is pressed, storing the entered characters as null-terminated string s. @@ -30,21 +30,21 @@ The following functions are defined: Note: Calls getchr() in a loop and uses constants DELKEY, RTNKEY, and ESCKEY from the system library. - r = outstr(&s): Writes up to 128 characters of null-terminated + r = puts(&s): Writes up to 128 characters of null-terminated string s to the screen. Returns position of null terminator in string. Note: Calls outsub(0, &s). - r = outsub(n, &s): Writes up to 128 characters of null-terminated + r = putsub(n, &s): Writes up to 128 characters of null-terminated string s to the screen, starting at position n. Returns position of null terminator in string. Note: Calls putchr() in a loop. - r = putstr(&s): Writes up to 128 characters of null-terminated + r = putln(&s): Writes up to 128 characters of null-terminated string s to the screen and advances the cursor to the beginning of the next line. @@ -69,4 +69,3 @@ and the assembler constants DELKEY Delete/Backspace key ASCII code (usually DEL or BS) ESCKEY Escape/Abort key ASCII code (usually ESC) RTNKEY Return/Enter key ASCII code (usually CR) - diff --git a/include/py65.a02 b/include/py65.a02 index 5f2da9a..fee6c9d 100644 --- a/include/py65.a02 +++ b/include/py65.a02 @@ -1,7 +1,7 @@ ; py65mon program initialization code for c02 programs ;System Specific ASCII Key Mappings -DELKEY EQU $7F ;Delete/Backspace Key (Delete) +DELKEY EQU $08 ;Delete/Backspace Key (Backspace) ESCKEY EQU $1B ;Escape/Stop Key (Escape) RTNKEY EQU $0D ;Return/Enter Key (Carriage Return) @@ -30,8 +30,8 @@ BLKEHI EQU $4D BLKLEN EQU $4E ;Block Segment Length ;Memory Mapped I/O -PUTC EQU $F001 ;Write Character to Console -GETC EQU $F004 ;Read Character from Console +PUTCON EQU $F001 ;Write Character to Console +GETCON EQU $F004 ;Read Character from Console ORG $0200 ;START Directly Above Stack @@ -39,7 +39,7 @@ START: JMP MAIN ;Execute Program ;Poll Character from Keyboard PLKEY: INC RDSEED ;Cycle the RANDOM Seed (if not provided by system) - LDA GETC ;Read Character from Console + LDA GETCON ;Read Character from Console RTS ;Read Character from Console @@ -65,7 +65,7 @@ NEWLIN: LDA #$0D ;Load C/R into Accumulator ; and fall into PRCHR ;Print Character to Console -PRCHR: STA PUTC ;Write Character to Console +PRCHR: STA PUTCON ;Write Character to Console RTS EXIT: BRK ;Return to Monitor diff --git a/include/py65.h02 b/include/py65.h02 index 5b4a688..161c533 100644 --- a/include/py65.h02 +++ b/include/py65.h02 @@ -1,26 +1,30 @@ /* py65mon Header File */ //System Pointer Variables -char srclo,srchi; //Source String Pointer for Library Functions -char dstlo,dsthi; //Destination String Pointer for Library Functions -char blklo,blkhi; //Block Segment Pointer +char srclo,srchi; //Source String Pointer for Library Functions +char dstlo,dsthi; //Destination String Pointer for Library Functions +char blklo,blkhi; //Block Segment Pointer +char ptrlo,ptrhi; //System Pointer //System Variables -char blkslo, blkshi; //Block Start Address -char blkelo, blkehi; //Block End Address -char blklen; //Block Segment Length -char temp0, temp1, temp2; //Temporary Variables +char blkslo, blkshi; //Block Start Address +char blkelo, blkehi; //Block End Address +char blklen; //Block Segment Length + +char temp0, temp1, temp2, temp3; //Temporary Variables //Memory Mapped I/O -char putc; //Write Character to Console -char getc; //Read Character from Console +char putcon; //Write Character to Console +char getcomn; //Read Character from Console //System Subroutines -char plkey(); //Poll Console for character -char rdkey(); //Wait for character from Console -char getkey(); //Read ASCII character from Console -void newlin(); //Advance cursor to beginning of next line -void prchr(); //Print ASCII character to Console -void prbyte(); //Print Accumulator as Hexadadecimal number -void prhex(); //Print Low Nybble of Accumulator as Hex Digit +char plkey(); //Poll Console for character +char rdkey(); //Wait for character from Console +char getkey(); //Read ASCII character from Console +void newlin(); //Advance cursor to beginning of next line +void prchr(); //Print ASCII character to Console +void prbyte(); //Print Accumulator as Hexadadecimal number +void prhex(); //Print Low Nybble of Accumulator as Hex Digit +void setdst(); //Set Destination Pointer +void setsrc(); //Set Source Pointer diff --git a/include/stdio.a02 b/include/stdio.a02 index 0b28573..85cd0a7 100644 --- a/include/stdio.a02 +++ b/include/stdio.a02 @@ -2,53 +2,52 @@ ; Requires external routines GETKEY, prchr, delchr, and NEWLIN ; external zero page locations SRCLO and SRCHI ; and external constants DELKEY, ESCKEY, and RTNKEY -;char getchr() -GETCHR EQU GETKEY ;Alias to external GETKEY routine +;char getc() +GETC EQU GETKEY ;Alias to external GETKEY routine -;void putchr(c) -PUTCHR EQU PRCHR ;Alias to external PRCHR Routine +;void putc(c) +PUTC EQU PRCHR ;Alias to external PRCHR Routine -;char getstr(&s) -GETSTR: JSR SETSRC ;Initialize Source String -GETSTL: JSR GETCHR ;Get Keypress -GETSTD: CMP #DELKEY ;If Delete - BNE GETSTE ;Then +;char gets(&s) +GETS: JSR SETSRC ;Initialize Source String +GETSL: JSR GETC ;Get Keypress + CMP #DELKEY ;If Delete + BNE GETSE ;Then TYA ; If Offset is Zero - BEQ GETSTL ; Get Next Character + BEQ GETSL ; Get Next Character DEY ; Else Decrement Offset JSR DELCHR ; Delete Previous Character - JMP GETSTL ; and Get Next Character -GETSTE: CMP #ESCKEY ;Else If Escape - BNE GETSTC ;Then + JMP GETSL ; and Get Next Character +GETSE: CMP #ESCKEY ;Else If Escape + BNE GETSC ;Then LDY #$FF ; Return -1 - BNE GETSTY -GETSTC: CMP #RTNKEY ;Else If Not Carriage Return - BEQ GETSTX - JSR PUTCHR ; Echo Character + BNE GETSY +GETSC: CMP #RTNKEY ;Else If Not Carriage Return + BEQ GETSX + JSR PUTC ; Echo Character STA (SRCLO),Y ; Store Character at offset INY ; increment offset and - BPL GETSTL ; loop if less than 128 -GETSTX: JSR NEWLIN ;Else Advance Cursor to Next Line + BPL GETSL ; loop if less than 128 +GETSX: JSR NEWLIN ;Else Advance Cursor to Next Line LDA #$00 ; Terminate String STA (SRCLO),Y ; and -GETSTY: TYA ; Return String Length +GETSY: TYA ; Return String Length RTS -;char outstr(n, &s) -OUTSTR: LDA #$00 ;Set Start Position to 0 - ;and fall into outsub -;char outsub(n, &s) -OUTSUB: JSR SETSRC ;Initialize Source String +;char puts(n, &s) +PUTS: LDA #$00 ;Set Start Position to 0 + ;and fall into putsub +;char putsub(n, &s) +PUTSUB: JSR SETSRC ;Initialize Source String TAY ;Initialize character offset -OUTSUL: LDA (SRCLO),Y ;Read next character in string - BEQ OUTSUX ;If Not 0 - JSR PUTCHR ; Print character at offset, +PUTSUL: LDA (SRCLO),Y ;Read next character in string + BEQ PUTSUX ;If Not 0 + JSR PUTC ; Print character at offset, INY ; increment offset, and - BPL OUTSUL ; loop if less than 128 -OUTSUX: TAY ;Return number of + BPL PUTSUL ; loop if less than 128 +PUTSUX: TAY ;Return number of RTS ; characters printed -;char putstr(*s) -PUTSTR: JSR OUTSTR ;Write string to screen +;char putln(&s) +PUTLN: JSR PUTS ;Write string to screen JMP NEWLIN ;Call external NEWLINe routine and return - diff --git a/include/stdio.h02 b/include/stdio.h02 index a4dee45..c8f81aa 100644 --- a/include/stdio.h02 +++ b/include/stdio.h02 @@ -5,32 +5,31 @@ /* Read Character from Keyboard * * Waits for Keypress * * Returns: ASCII value of Key */ -char getchr(); +char getc(); /* Write Character to Screen * * Args: c - ASCII character to write */ -void putchr(); +void putc(); /* Read String from Keyboard * * Buffers string until C/R is pressed * * Args: &s - string read from keyboard * * Returns: length of string */ -char getstr(); +char gets(); /* Write String to Screen * * Args: &s - string to print from * * Returns: ending position in string */ -char outstr(); +char puts(); /* Write Partial String to Screen * * Args: n - starting position in string * * &s - string to print from * * Returns: ending position in string */ -char outsub(); +char putsub(); /* Write String to Screen and Move * * Cursor to Beginning of Next Line * * Args: &s - string to print to screen * * Returns: number of characters printed */ -char putstr(); - +char putln(); diff --git a/py65/testio.c02 b/py65/testio.c02 new file mode 100644 index 0000000..9acb532 --- /dev/null +++ b/py65/testio.c02 @@ -0,0 +1,30 @@ +/********************************************** + * TESTIO - Test Library stdio.h for py65mon * + **********************************************/ + +#include +#include + +char key; //Key read from keyboard +char len; //Length of input output string +char str[128]; //String to read/write + +main: + putln("Press any key to continue"); + key = getc(); //Wait for key press + newlin(); //Advance cursor to next line + + putln("Type lines followed by carriage-return"); + putln("press Escape key to end"); + +while () { + putc('>'); + len = gets(&str); //Read string from keybaord + if (len == $FF) //If entry was aborted + break ; // return to monitor + puts("You typed: "); //Print without newline + putln(&str); //print with newline +} + +done: + goto exit;