1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-06-26 05:29:32 +00:00
C02/doc/stdlib.txt
2018-01-28 14:00:23 -05:00

101 lines
4.1 KiB
Plaintext

Standard Library Functions for C02 Programs
At the beginning of the program use the directives
#include <stdlib.h02>
The following functions are defined:
c = abs(b); Returns the absolute value of the two's-complement
byte b.
In two's-complement arithmetic, the unsigned values
0 - 127 are considered positive, while the unsigned
values 128 - 255 are considered negative.
c = atoc(&s); Returns the numeric value of the string in array s.
Does not skip leading white-space characters and
stops when first non-digit character is encountered.
Overflows are ignored, so numbers greater than 255
will be returned modulo 256.
ctoa(c, &s); Stores the ASCII representation of usigned byte c
as a null-terminated string in array s.
The array must be dimensioned to at least 4 bytes.
c = max(b, d); Returns the greater of the two unsigned bytes b and d.
c = min(b, d); Returns the lesser of the two unsigned bytes b and d.
c = mult(d, r); Returns the product of byte d times byte r.
Overflows are ignored, so results greater than 255
will be returned modulo 256.
c = div(n, d); Returns the quotient of byte n divided by byte d.
Remainders are discarded and division by 0 returns ??.
c = rand(); Returns pseudo-random number. Sequence repeats
after 255 repeated calls. The generator must be
seeded using the rands() function before the first
call to rand().
rands(n); Seeds the pseudo-random number generator.
If n is 0, the generator is seeded with a system
seed value. This should be used for normal operation.
If n is not 0. then it is used as the seed. This can
be used for program testing or when a predictable
pattern is needed.
Note: The system seed is generated by a counter or
timer. On systems that don't use a timer, the counter
is cycled by the keyboard routines, so the getkey()
or getchr() function must called at least once before
a rands(0) call.
c = shiftl(b, n); Returns byte b shifted n bits to the left, filling
with 0's from the right.
If n is greater than 8, all bits will be shifted out,
and a value of 0 is treated as 256.
c = shiftr(b, n); Returns byte b shifted n bits to the right, filling
with 0's from the left.
If n is greater than 8, all bits will be shifted out,
and a value of 0 is treated as 256.
Note: Using the shiftl() or shiftr() functions with
an asignment generates 9 to 12 bytes of code, whereas
the << and >> post-operators generate either 2 or 3
bytes each. So for a constant number of shifts, the
post-operators will generate smaller code for less
than 5 shifts and will always be faster.
Note: This library expects the following function to be defined
setsrc(&s); Set source string pointer and initialize index
along with the zero page variables
srclo,srchi: Source string pointer
as well as the transient variables
temp0 Temporary storage
temp1
temp2
and the static variables
random Psuedo-random number generator seed Value
rdseed System generated initial seed (counter or timer)