1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-25 21:33:44 +00:00

Added functions to module 'stdiox'

This commit is contained in:
Curtis F Kaylor 2018-07-27 14:11:39 -04:00
parent 27b3636901
commit ca3723e2a9
6 changed files with 65 additions and 27 deletions

View File

@ -2,16 +2,36 @@ Extended Input/Output Functions for C02 Programs
At the beginning of the program use the directives At the beginning of the program use the directives
#include <stddef.h02>
#include <stdlib.h02> #include <stdlib.h02>
#include <stdiox.h02> #include <stdiox.h02>
The following functions are defined: The following functions are defined:
c = getprc(&s); Writes the string s, followed by a blank line,
to the screen, then waits for a key to be pressed.
Returns the ASCII value of the key that was
pressed.
Note: Calls the puts function, the newlin
function twice, then the getc function.
c = getprc(&s); Writes the string "Press any key to continue...",
followed by a blank line, to the screen, then waits
for a key to be pressed.
Returns the ASCII value of the key that was
pressed.
Note: Calls the getprc function, with a hard
coded string.
putdec(b); Writes the decimal representation of byte b to the putdec(b); Writes the decimal representation of byte b to the
screen. The output will be between one and three screen. The output will be between one and three
digits with no leading spaces. digits with no leading spaces.
Note: Calls part of the ctoa() routine from stdlib Note: Calls part of the ctoa routine from stdlib
which leaves the binary values of the ones, tens, which leaves the binary values of the ones, tens,
and hundreds digits in variables temp0, temp1, and and hundreds digits in variables temp0, temp1, and
temp2, respectively. temp2, respectively.
@ -21,7 +41,7 @@ The following functions are defined:
with 1 space if b is between 10 and 99, or two spaces with 1 space if b is between 10 and 99, or two spaces
if b is less than 10. if b is less than 10.
Note: Calls putdec() and putspc(). Leaves the value Note: Calls putdec and putspc. Leaves the value
of b in varible temp3. of b in varible temp3.
putder(b); Writes the decimal representation of byte b to the putder(b); Writes the decimal representation of byte b to the
@ -29,22 +49,22 @@ The following functions are defined:
with 1 space if b is between 10 and 99, or two spaces with 1 space if b is between 10 and 99, or two spaces
if b is less than 10. if b is less than 10.
Note: Calls putdec() and putspc(). Leaves the value Note: Calls putdec and putspc. Leaves the value
of b in varible temp3. of b in varible temp3.
putdst(); Prints the destination string set by the setdst() or putdst(); Prints the destination string set by the setdst or
setstr() functions. setstr functions.
This can be used to print the results of any function This can be used to print the results of any function
call that stores it's result in the destination string, call that stores it's result in the destination string,
such as strcat(), strcpy(), and strcut() in string, such as strcat, strcpy, and strcut in string,
Note: calls putc() and is called by printf() when Note: calls putc and is called by printf when
processing a %S formatting tag. processing a %S formatting tag.
putspc(b); Writes a space character to the screen. putspc(b); Writes a space character to the screen.
Note: Used by the putdel() and putder() functions. Note: Used by the putdel and putder functions.
r = printf(b, &s): Writes the value of byte b to screen, formatting r = printf(b, &s): Writes the value of byte b to screen, formatting
the output according the contents of string s. the output according the contents of string s.
@ -61,16 +81,16 @@ The following functions are defined:
%R - output b as a right justified decimal number %R - output b as a right justified decimal number
%% - output a single % character %% - output a single % character
Unlike the printf() function in standard C, only Unlike the printf function in standard C, only
one value argument may be passed and that value is one value argument may be passed and that value is
used for each formatting tag in the format string. used for each formatting tag in the format string.
One additional formatting tag is supported: One additional formatting tag is supported:
%S - output the destination string %S - output the destination string
The destination string is set using the setdst() or The destination string is set using the setdst or
strdst() functions (from the "string" library) before strdst functions (from the "string" library) before
calling printf(). Multiple occurances of the %S tag calling printf. Multiple occurances of the %S tag
will cause the destination string to be repeated. will cause the destination string to be repeated.
When tag types are mixed, the %S tag will output the When tag types are mixed, the %S tag will output the
@ -82,8 +102,8 @@ The following functions are defined:
lower case with either a 0 or 1 in the high bit. lower case with either a 0 or 1 in the high bit.
Unrecognized formatting tags are interpreted as %C. Unrecognized formatting tags are interpreted as %C.
Note: Calls putdec(), putdel(), putder(), prbyte(), or Note: Calls putdec, putdel, putder, prbyte, or
putdst() depending on which formatting tags are used. putdst depending on which formatting tags are used.
The value of b is left in variable temp3. The value of b is left in variable temp3.
Note: This library expects the following functions to be defined: Note: This library expects the following functions to be defined:

View File

@ -4,7 +4,7 @@
;External Variables ;External Variables
;TEMP0, TEMP1, TEMP2 ;TEMP0, TEMP1, TEMP2
;Standard Constant Definitions ;Constant Definitions
TRUE EQU $FF ;Returned for Success or Failure TRUE EQU $FF ;Returned for Success or Failure
FALSE EQU $00 ;by some Library Routines FALSE EQU $00 ;by some Library Routines

View File

@ -1,5 +1,17 @@
; C02 library stdiox.h02 assembly language subroutines ; C02 library stdiox.h02 assembly language subroutines
ANYKEP: DC "Press any key to continue...",0
ANYKEY: JSR NEWLIN ;Start at Beginning of Next Line
LDY #>ANYKEP ;Load Prompt High Byte
LDX #<ANYKEP ;Load Prompt Low Byte
;Drop into GETCPR
;Display Prompt and Wait for Character
GETCPR: JSR PUTLN ;Print Prompt
JSR NEWLIN ;Generate Blank Line
JMP GETC ;Wait for and Return Keypress
;Print Byte as Left Justified Decimal Number ;Print Byte as Left Justified Decimal Number
;void putdel(b) ;void putdel(b)
;Args: A = number to print ;Args: A = number to print

View File

@ -2,6 +2,21 @@
* stdiox - Extended I/O Routines for C02 * * stdiox - Extended I/O Routines for C02 *
******************************************/ ******************************************/
/* Display "Press any key to continue" *
* prompt and wait fo keypress *
* Returns: ASCII value of key pressed */
void anykey();
/* Display prompt and wait for keypress *
* Args: &s - string to display *
* Returns: ASCII value of key pressed */
void getcpr();
/* Print Formatted Byte to Screen *
* Args: b - byte to format *
* &s - formatting string */
void printf();
/* Print Byte as Decimal Number * /* Print Byte as Decimal Number *
* Args: b - Number to print */ * Args: b - Number to print */
void putdec(); void putdec();
@ -20,7 +35,3 @@ void putdst();
/* Print a Space Character */ /* Print a Space Character */
void putspc(); void putspc();
/* Print Formatted Byte to Screen *
* Args: b - byte to format *
* &s - formatting string */
void printf();

View File

@ -199,7 +199,6 @@ UPBCD: LDA TEMP1 ;Get Low Byte
STA TEMP1 ;Save in Tens STA TEMP1 ;Save in Tens
RTS RTS
;ConVert number to packed Binary Coded Decimal ;ConVert number to packed Binary Coded Decimal
;Args: A - Number to Convert ;Args: A - Number to Convert
;Destroys: TEMP0 ;Destroys: TEMP0

View File

@ -3,6 +3,7 @@
***********************************************/ ***********************************************/
#include <py65.h02> #include <py65.h02>
#include <stddef.h02>
#include <stdlib.h02> #include <stdlib.h02>
#include <stdio.h02> #include <stdio.h02>
#include <stdiox.h02> #include <stdiox.h02>
@ -12,6 +13,8 @@ char s = "string";
main: main:
getcpr("Press any key to begin...");
i = 0; i = 0;
putln("prtdec()"); putln("prtdec()");
@ -55,10 +58,3 @@ newlin();
done: done:
goto exit; goto exit;
void anykey() {
newlin();
putln("Press any key...");
c = getc();
newlin();
}