2018-07-19 03:44:42 +00:00
|
|
|
Extended Input/Output Functions for C02 Programs
|
|
|
|
|
|
|
|
At the beginning of the program use the directives
|
|
|
|
|
2018-07-27 18:11:39 +00:00
|
|
|
#include <stddef.h02>
|
2018-07-19 03:44:42 +00:00
|
|
|
#include <stdlib.h02>
|
2020-10-14 02:22:34 +00:00
|
|
|
#include <intlib.h02>
|
2018-07-19 03:44:42 +00:00
|
|
|
#include <stdiox.h02>
|
2018-07-30 00:40:31 +00:00
|
|
|
|
2018-07-19 03:44:42 +00:00
|
|
|
The following functions are defined:
|
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
c = getcpr(s); Writes the string s to the screen, waits for a key
|
|
|
|
to be pressed, then writes a blank line line.
|
2018-07-30 00:40:31 +00:00
|
|
|
|
|
|
|
Returns the ASCII value of the key that was
|
|
|
|
pressed.
|
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
Note: Calls the puts() function, the newlin()
|
2018-07-30 00:40:31 +00:00
|
|
|
function twice, then the getc function.
|
|
|
|
|
|
|
|
c = anykey(); Writes the string "Press any key to continue...",
|
2020-10-14 02:22:34 +00:00
|
|
|
followed by a blank line to the screen, then waits
|
2018-07-30 00:40:31 +00:00
|
|
|
for a key to be pressed.
|
|
|
|
|
|
|
|
Returns the ASCII value of the key that was
|
|
|
|
pressed.
|
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
Note: Calls the getprc() function, with a hard
|
2018-07-30 00:40:31 +00:00
|
|
|
coded string.
|
|
|
|
|
|
|
|
putspc(b); Writes a space character to the screen.
|
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
Note: Used by the putdel(), putder(), and putinj()
|
|
|
|
functions.
|
|
|
|
|
|
|
|
putrpt(c,n); Writes character c to the screen n times.
|
|
|
|
|
|
|
|
Note: Repeatedly calls putc().
|
|
|
|
|
|
|
|
putrps(n); Writes a space to the screen n times.
|
|
|
|
|
|
|
|
Note: Calls putrpt() with a space character.
|
2018-07-30 00:40:31 +00:00
|
|
|
|
|
|
|
putdec(b); Writes the decimal representation of byte b to the
|
|
|
|
screen. The output will be between one and three
|
|
|
|
digits with no leading spaces.
|
|
|
|
|
|
|
|
Note: Calls part of the ctoa routine from stdlib
|
|
|
|
which leaves the binary values of the ones, tens,
|
|
|
|
and hundreds digits in variables temp0, temp1, and
|
2020-10-14 02:22:34 +00:00
|
|
|
temp2, respectively. Called by printf() when
|
|
|
|
processing the %D formatting tag.
|
2018-07-30 00:40:31 +00:00
|
|
|
|
|
|
|
putdel(b); Writes the decimal representation of byte b to the
|
|
|
|
screen. The output is left justified by appending it
|
|
|
|
with 1 space if b is between 10 and 99, or two spaces
|
|
|
|
if b is less than 10.
|
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
Note: Calls putdec() and putspc(). Leaves the value
|
|
|
|
of b in variable temp3. Called by printf() when
|
|
|
|
processing the %L formatting tag.
|
2018-07-30 00:40:31 +00:00
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
putder(b); Writes the decimal representation of byte b to
|
|
|
|
the screen. The output is right justified by left
|
|
|
|
padding it with 1 space if b is between 10 and 99,
|
|
|
|
or two spaces if b is less than 10.
|
|
|
|
|
|
|
|
Note: Calls putdec() and putspc(). Leaves the value
|
|
|
|
of b in variable temp3. Called by printf() when
|
|
|
|
processing the %R formatting tag.
|
|
|
|
|
|
|
|
putdez(b); Writes the decimal representation of byte b to the
|
|
|
|
screen. The output is always three digits, including
|
|
|
|
leading zeros.
|
|
|
|
|
|
|
|
Note: Calls part of the ctoa() routine from stdlib
|
|
|
|
which leaves the binary values of the ones, tens,
|
|
|
|
and hundreds digits in variables temp0, temp1, and
|
|
|
|
temp2, respectively. Called by printf() when
|
|
|
|
processing the %Z formatting tag.
|
|
|
|
|
|
|
|
putdeh(b); Writes the decimal representation of byte b, modulo
|
|
|
|
100, to the screen. The output is always two digits,
|
|
|
|
the ten's digit and the one's digit.
|
|
|
|
|
|
|
|
Note: Calls part of the ctoa routine from stdlib
|
|
|
|
which leaves the binary values of the ones, tens,
|
|
|
|
and hundreds digits in variables temp0, temp1, and
|
|
|
|
temp2, respectively. Called by printf() when
|
|
|
|
processing the %H formatting tag.
|
|
|
|
|
|
|
|
putbin(b); Writes the binary representation of byte b to the
|
|
|
|
screen. The output is always eight binary digits
|
|
|
|
(0 or 1).
|
2018-07-30 00:40:31 +00:00
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
Note: Calls putmsk() with a mask of $FF. Called
|
|
|
|
by printf() when processing the %B formatting tag.
|
|
|
|
|
|
|
|
putexh(b,i); Writes the hexadecimal representation of a 24-bit
|
|
|
|
number to the screen, where b is the high byte and
|
|
|
|
i is the middle and low bytes. The output is always
|
|
|
|
six hex digits, with leading zeros if b is less than
|
|
|
|
$10.
|
|
|
|
|
|
|
|
Note: Calls savrxy(), saving the X and Y registers
|
|
|
|
to temp1 and temp2, respectively, then calls puthex()
|
|
|
|
to print the highest byte and putwrd() to print the
|
|
|
|
middle and low bytes.
|
2018-07-30 00:40:31 +00:00
|
|
|
|
|
|
|
puthex(b); Writes the hexadecimal representation of byte b to the
|
|
|
|
screen. The output is always two hex digits, the first
|
2020-10-14 02:22:34 +00:00
|
|
|
being a leading 0 if b is less than 16. Called by
|
|
|
|
printf() when processing the %X formatting tag.
|
|
|
|
|
|
|
|
Note: Aliased to the prbyte() routine.
|
|
|
|
|
|
|
|
putint(i); Writes the decimal representation of integer i to the
|
|
|
|
screen. The output will be one to five decimal digits,
|
|
|
|
with no leading zeros or padding.
|
|
|
|
|
|
|
|
Note: Calls cvibcd, then calls upbcdi for each digit
|
|
|
|
to be printed. Called by printf() when processing
|
|
|
|
the %I formatting tag.
|
|
|
|
|
|
|
|
putinr(i); Writes the decimal representation of integer i to the
|
|
|
|
screen. The output is always five charactes. right
|
|
|
|
justified by left padding it with spaces.
|
|
|
|
|
|
|
|
Note: Calls putint(). Called by printf() when
|
|
|
|
processing the %J formatting tag.
|
|
|
|
|
|
|
|
putnyb(b); Writes the hexadecimal representation of the low
|
|
|
|
nybble of byte b to the screen. The output is always
|
|
|
|
one hex digit (0-F).
|
2018-07-30 00:40:31 +00:00
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
Note: Aliased to the prhex() routine. Called by
|
|
|
|
printf() when processing the %W formatting tag.
|
2018-07-30 00:40:31 +00:00
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
putmsk(b,m); Writes the binary representation of each of the bits
|
|
|
|
in byte b for which the corresponding bit of m is set.
|
|
|
|
The output will be between 0 and 8 binary digits,
|
|
|
|
depending on how many bits of m are set.
|
|
|
|
|
|
|
|
putmsk(b,$0F); //Print Low Nybble as Binary Number
|
|
|
|
putmsk(b,$81); //Print Highest and Lowest Bits
|
|
|
|
|
|
|
|
putsqb(i); Writes the hexadecimal representation of the twelve
|
|
|
|
lowest bits of i (a sesquibyte) to the screen. The
|
|
|
|
output is always three hex digits, with leading
|
|
|
|
zeros if i is less than $0100.
|
|
|
|
|
|
|
|
Note: Calls savrxy(), saving the X and Y registers to
|
|
|
|
temp1 and temp2, respectively, then calls putnyb for
|
|
|
|
the most significant byte and puthex() for the least
|
|
|
|
significant byte. Called by printf() when processing
|
|
|
|
the %Q formatting tag.
|
|
|
|
|
|
|
|
putwrd(i); Writes the hexadecimal representation of integer i to
|
2018-07-30 00:40:31 +00:00
|
|
|
the screen. The output is always four hex digits, with
|
2020-10-14 02:22:34 +00:00
|
|
|
leading zeros if i is less than $1000.
|
2018-07-30 00:40:31 +00:00
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
Note: Calls savrxy(), saving the X and Y registers to
|
2018-07-30 00:40:31 +00:00
|
|
|
temp1 and temp2, respectively, then calls puthex, once
|
|
|
|
for the most significant byte and again for the least
|
2020-10-14 02:22:34 +00:00
|
|
|
significant byte. Called by printf() when processing
|
|
|
|
the %W formatting tag.
|
2018-07-30 00:40:31 +00:00
|
|
|
|
|
|
|
putdst(); Prints the destination string set by the setdst or
|
|
|
|
setstr functions.
|
|
|
|
|
|
|
|
This can be used to print the results of any function
|
|
|
|
call that stores it's result in the destination string,
|
|
|
|
such as strcat, strcpy, and strcut in string,
|
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
Note: calls putc. Called by printf() when processing
|
|
|
|
the %S formatting tag.
|
2018-07-30 00:40:31 +00:00
|
|
|
|
|
|
|
r = printf(b, &s): Writes the value of byte b to screen, formatting
|
|
|
|
the output according the contents of string s.
|
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
The output consists of the characters in s, but
|
|
|
|
with any formatting tags (which may be upper or
|
|
|
|
lower case) replaced with an ASCII representation
|
|
|
|
of the value of b.
|
2018-07-30 00:40:31 +00:00
|
|
|
|
|
|
|
The recognized formatting tags are:
|
2020-10-14 02:22:34 +00:00
|
|
|
%B - output b as an eight-digit binary number
|
2018-07-30 00:40:31 +00:00
|
|
|
%C - output the ASCII character represented by b
|
|
|
|
%D - output b as a an unjustified decimal number
|
2020-10-14 02:22:34 +00:00
|
|
|
%H - output b as a modulo-100 decimal number
|
2018-07-30 00:40:31 +00:00
|
|
|
%L - output b as a left justified decimal number
|
|
|
|
%R - output b as a right justified decimal number
|
2020-10-14 02:22:34 +00:00
|
|
|
%X - output b as a two-digit hexadecimal number
|
|
|
|
%Y - output low nybble of b as a hexadecimal digit
|
|
|
|
%Z - output b as a zero-filled decimal number
|
|
|
|
|
|
|
|
Unlike the printf() function in standard C, only
|
2018-07-30 00:40:31 +00:00
|
|
|
one value argument may be passed and that value is
|
|
|
|
used for each formatting tag in the format string.
|
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
Two special function tags are supported:
|
|
|
|
%% - output a single % character
|
|
|
|
%N - generate a newline
|
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
Additional formatting tags operate on the
|
2020-10-14 02:22:34 +00:00
|
|
|
destination pointer:
|
2021-12-05 00:14:41 +00:00
|
|
|
%S - output destination string
|
|
|
|
%P - output destination string padded with
|
|
|
|
spaces to length b
|
|
|
|
%I - output destination address as one to
|
|
|
|
five digit decimal number
|
|
|
|
%J - output destination address as right
|
|
|
|
justified decimal number
|
|
|
|
%Q - output destination address as
|
|
|
|
three-digit hexadecimal number
|
|
|
|
%W - output destination address as
|
|
|
|
four-digit hexadecimal number
|
|
|
|
%E - output b and destination address as
|
|
|
|
six-digit hexadecimal number
|
2018-07-30 00:40:31 +00:00
|
|
|
|
|
|
|
The destination string and/or address is set using
|
|
|
|
the setdst or strdst function (from the "string"
|
2020-10-14 02:22:34 +00:00
|
|
|
library) before calling printf. Multiple occurrences
|
2018-07-30 00:40:31 +00:00
|
|
|
of the %S or %w tag will cause the destination string
|
|
|
|
and/or address to be repeated.
|
|
|
|
|
|
|
|
When tag types are mixed, the %S and/or %W tags will
|
|
|
|
output the destination string and/or address, while
|
|
|
|
the other tags will output the formatted byte. If
|
|
|
|
only the %S and/or %W tags are used, then the byte
|
|
|
|
argument may be excluded from the call.
|
|
|
|
|
|
|
|
The letter in the formatting tag may be upper or
|
|
|
|
lower case with either a 0 or 1 in the high bit.
|
|
|
|
Unrecognized formatting tags are interpreted as %C.
|
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
Note: Calls putdec, putdel, putder, puthex, putint,
|
|
|
|
putwrd, or putdst depending on which formatting tags
|
|
|
|
are used. The value of b is left in variable temp3.
|
2018-07-19 03:44:42 +00:00
|
|
|
|
|
|
|
Note: This library expects the following functions to be defined:
|
|
|
|
|
|
|
|
cubcd(); Convert byte to BCD and unpack into three bytes
|
2020-10-14 02:22:34 +00:00
|
|
|
cvibcd(); Convert Integer to Binary Coded Decimal
|
2018-07-19 03:44:42 +00:00
|
|
|
prbyte(); Print byte to screen as hexadecimal number
|
2020-10-14 02:22:34 +00:00
|
|
|
prchr(); Print ASCII character to screen
|
|
|
|
savrxy()(); Save X and Y registers.
|
|
|
|
setsrc(); Set source string pointer and initialize index
|
|
|
|
upbcdi(); Unpack digit from Binary Coded Decimal Integer
|
2018-07-19 03:44:42 +00:00
|
|
|
|
|
|
|
along with the zero page variable pairs:
|
2018-07-30 00:40:31 +00:00
|
|
|
|
2020-10-14 02:22:34 +00:00
|
|
|
srclo,srchi: Source Pointer
|
|
|
|
dstlo,dsthi: Destination Pointer
|
2018-07-19 03:44:42 +00:00
|
|
|
|
|
|
|
and the temporary variables
|
|
|
|
|
|
|
|
temp0,temp1,temp2,temp3
|