mirror of
https://github.com/RevCurtisP/C02.git
synced 2025-02-20 12:29:04 +00:00
Added module stddef to standard library
This commit is contained in:
parent
bcac483b88
commit
37842aa306
@ -51,11 +51,6 @@ functions must be defined:
|
|||||||
Note: Does any needed ACSII conversions, then calls
|
Note: Does any needed ACSII conversions, then calls
|
||||||
echo().
|
echo().
|
||||||
|
|
||||||
setdst(&s): Stores pointer to &s in dstlo and dsthi.
|
|
||||||
|
|
||||||
setsrc(&s): Stores pointer to &s in srclo and srchi and
|
|
||||||
initializes Y register to 0.
|
|
||||||
|
|
||||||
along with the Zero Page locations (each pair of which must be sequential)
|
along with the Zero Page locations (each pair of which must be sequential)
|
||||||
|
|
||||||
srclo, srchi Spurce String Pointer
|
srclo, srchi Spurce String Pointer
|
||||||
@ -63,9 +58,8 @@ along with the Zero Page locations (each pair of which must be sequential)
|
|||||||
|
|
||||||
the following locations that may be Zero Page, but don't have to before
|
the following locations that may be Zero Page, but don't have to before
|
||||||
|
|
||||||
temp0 Temporary variables used by stdlib.asm
|
temp0, temp1 Temporary variables used by stdlib.asm
|
||||||
temp1
|
temp2, temp3
|
||||||
temp2
|
|
||||||
|
|
||||||
and the following locations that must be preserved between function calls
|
and the following locations that must be preserved between function calls
|
||||||
|
|
||||||
@ -86,4 +80,3 @@ and the constants
|
|||||||
ESCKEY ASCII code for Escape/Abort key (usually ESC)
|
ESCKEY ASCII code for Escape/Abort key (usually ESC)
|
||||||
NULKEY Returned if no Key was Pressed
|
NULKEY Returned if no Key was Pressed
|
||||||
RTNKEY ASCII code for Return/Enter key (usually CR)
|
RTNKEY ASCII code for Return/Enter key (usually CR)
|
||||||
|
|
||||||
|
114
doc/stddef.txt
Normal file
114
doc/stddef.txt
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
Standard Definitions for C02 Library Functions
|
||||||
|
|
||||||
|
This module includes constant and function definitions common to the
|
||||||
|
entire standard library.
|
||||||
|
|
||||||
|
At the beginning of the program use the directives
|
||||||
|
|
||||||
|
#include <stddef.h02>
|
||||||
|
|
||||||
|
The following constants are defined:
|
||||||
|
|
||||||
|
#TRUE The byte 255, $FF, or %11111111, representing
|
||||||
|
the true condition.
|
||||||
|
|
||||||
|
#FALSE The byte 0, $00 or %00000000, representing the
|
||||||
|
false condition.
|
||||||
|
|
||||||
|
The following functions are defined:
|
||||||
|
|
||||||
|
savreg(); Saves the A, X, and Y registers.
|
||||||
|
|
||||||
|
Note: Stores A, X, and Y in temp0, temp1, and
|
||||||
|
temp2, respectively.
|
||||||
|
|
||||||
|
savrxy(); Saves only the X and Y registers.
|
||||||
|
|
||||||
|
Note: This is an alternate entry point into
|
||||||
|
the savreg function, which stores X and Y in
|
||||||
|
temp1 and temp2, respectively.
|
||||||
|
|
||||||
|
resreg(); Restore the A, X, and Y registers.
|
||||||
|
|
||||||
|
Note: Loads A, X, and Y from temp0, temp1, and
|
||||||
|
temp2, respectively.
|
||||||
|
|
||||||
|
resrxy(); Resrtores only the X and Y registers.
|
||||||
|
|
||||||
|
Note: This is an alternate entry point into
|
||||||
|
the resreg function, which loads X and Y from
|
||||||
|
temp1 and temp2, respectively.
|
||||||
|
|
||||||
|
setsrc(&d); Sets the source pointer to address d.
|
||||||
|
|
||||||
|
Note: Stores the least significant byte,
|
||||||
|
passed in the X register, in srclo, and the
|
||||||
|
most significant byte, passed in the Y
|
||||||
|
register, to srchi.
|
||||||
|
|
||||||
|
setdst(&d); Sets the destination pointer to address d.
|
||||||
|
|
||||||
|
Note: Stores the least significant byte,
|
||||||
|
passed in the X register, in destlo, and the
|
||||||
|
most significant byte, passed in the Y
|
||||||
|
register, to desthi.
|
||||||
|
|
||||||
|
setsrd(); Sets the source pointer to the destination
|
||||||
|
pointer.
|
||||||
|
|
||||||
|
Note: Calls the getdst function, followed by
|
||||||
|
the setsrc function, copying dstlo and dsthi
|
||||||
|
to srclo and srchi, respectively.
|
||||||
|
|
||||||
|
*,hi,lo=getsrc(); Gets the address in the source pointer,
|
||||||
|
returning the least significant byte in lo
|
||||||
|
and the most significant byte in hi.
|
||||||
|
|
||||||
|
Note: Loads the srclo into the X register and
|
||||||
|
srchi into the Y.
|
||||||
|
|
||||||
|
*,hi,lo=getdst(); Gets the address in the destination pointer,
|
||||||
|
returning the least significant byte in lo
|
||||||
|
and the most significant byte in hi.
|
||||||
|
|
||||||
|
Note: Loads the dstlo into the X register and
|
||||||
|
dsthi into the Y.
|
||||||
|
|
||||||
|
savsrc(); Saves the destination pointer.
|
||||||
|
|
||||||
|
Note: Calls the getsrc function, followed by
|
||||||
|
the savrxy function, copying srclo and srchi
|
||||||
|
to temp1 and temp2, respectively.
|
||||||
|
|
||||||
|
savdst(); Saves the destination pointer.
|
||||||
|
|
||||||
|
Note: Calls the getdst function, followed by
|
||||||
|
the savrxy function, copying dstlo and dsthi
|
||||||
|
to temp1 and temp2, respectively.
|
||||||
|
|
||||||
|
ressrc(); Restores the source pointer.
|
||||||
|
|
||||||
|
Note: Calls the resrxy function, followed by
|
||||||
|
the setsrc function, copying temp1 and temp2
|
||||||
|
to srclo and srchi, respectively.
|
||||||
|
|
||||||
|
resdst(); Restores the destination pointer.
|
||||||
|
|
||||||
|
Note: Calls the resrxy function, followed by
|
||||||
|
the setdst function, copying temp1 and temp2
|
||||||
|
to dstlo and dsthi, respectively.
|
||||||
|
|
||||||
|
Note: This library expects the following to be defined:
|
||||||
|
|
||||||
|
the zero page variables
|
||||||
|
|
||||||
|
srclo,srchi: Source pointer
|
||||||
|
dstlo,dsthi: Destination pointer
|
||||||
|
|
||||||
|
and the transient variables
|
||||||
|
|
||||||
|
temp0 Temporary storage
|
||||||
|
temp1
|
||||||
|
temp2
|
||||||
|
|
||||||
|
|
@ -103,19 +103,3 @@ PRHEX: AND #$0F ;Strip High Nybble
|
|||||||
ADC #$06 ; Convert ':' to 'A'...
|
ADC #$06 ; Convert ':' to 'A'...
|
||||||
PRHEXC: ADC #$30 ;Convert to ASCII Character
|
PRHEXC: ADC #$30 ;Convert to ASCII Character
|
||||||
JMP PRCHR ;Print Hex Digit and Return
|
JMP PRCHR ;Print Hex Digit and Return
|
||||||
|
|
||||||
|
|
||||||
;Functions to set String Pointers
|
|
||||||
;Used by memory, stdio, stdlin, string, and stringx libraries
|
|
||||||
|
|
||||||
;Initialize Destination String Pointer
|
|
||||||
SETDST: STX DSTLO ;Save Destination String Pointer
|
|
||||||
STY DSTHI
|
|
||||||
RTS
|
|
||||||
|
|
||||||
;Initialize Source String Pointer and Index
|
|
||||||
SETSRC: STX SRCLO ;Save Source String Pointer
|
|
||||||
STY SRCHI
|
|
||||||
LDY #$00 ;Initialize Index Into String
|
|
||||||
RTS
|
|
||||||
|
|
||||||
|
@ -34,4 +34,3 @@ void newlin(); //Advance cursor to beginning of next line
|
|||||||
void prchr(); //Print ASCII character to Console
|
void prchr(); //Print ASCII character to Console
|
||||||
void prbyte(); //Print Accumulator as Hexadadecimal number
|
void prbyte(); //Print Accumulator as Hexadadecimal number
|
||||||
void prhex(); //Print Low Nybble of Accumulator as Hex Digit
|
void prhex(); //Print Low Nybble of Accumulator as Hex Digit
|
||||||
|
|
||||||
|
60
include/stddef.a02
Normal file
60
include/stddef.a02
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
;c02 library stddef.h02 assembly language subroutines
|
||||||
|
;Requires External Zero Page Variables
|
||||||
|
;DSTLO, DSTHI, SRCLO, SRCHI
|
||||||
|
;External Variables
|
||||||
|
;TEMP0, TEMP1, TEMP2
|
||||||
|
|
||||||
|
;Standard Constant Definitions
|
||||||
|
TRUE EQU $FF ;Returned for Success or Failure
|
||||||
|
FALSE EQU $00 ;by some Library Routines
|
||||||
|
|
||||||
|
;savdst() - Save Destination Pointer
|
||||||
|
SAVDST: JSR GETDST ;Load Destination Pointer
|
||||||
|
JMP SAVRXY ;Save X & Y Registers
|
||||||
|
|
||||||
|
;savdst() - Save Destination Pointer
|
||||||
|
SAVSRC: JSR GETSRC ;Load Destination Pointer
|
||||||
|
JMP SAVRXY ;Save X & Y Registers
|
||||||
|
|
||||||
|
;Save Registers
|
||||||
|
SAVREG: STA TEMP0 ;Save Accumulater
|
||||||
|
SAVRXY: STX TEMP1 ;Save X Index
|
||||||
|
STY TEMP2 ;Save Y Index
|
||||||
|
RTS
|
||||||
|
|
||||||
|
;Restore Registers
|
||||||
|
RESREG: LDA TEMP0 ;Load Accumlator
|
||||||
|
RESRXY: LDX TEMP1 ;Load X Index
|
||||||
|
LDY TEMP2 ;Load Y Index
|
||||||
|
RTS
|
||||||
|
|
||||||
|
;Restore Destination Pointer
|
||||||
|
RESDST: JSR RESRXY ;Load Address and Drop into SETDST
|
||||||
|
|
||||||
|
;Initialize Destination Pointer
|
||||||
|
SETDST: STX DSTLO ;Store Destination Pointer
|
||||||
|
STY DSTHI
|
||||||
|
RTS
|
||||||
|
|
||||||
|
;Restore Source Pointer
|
||||||
|
RESSRC: JSR RESRXY ;Load Saved Address
|
||||||
|
JMP SETSRC ;Set Source Pointer
|
||||||
|
|
||||||
|
;Set Source Pointer to Destination Pointer
|
||||||
|
SETSRD: JSR GETDST ;Get Destination Point and fall into SETSRC
|
||||||
|
|
||||||
|
;Initialize Source Pointer and Index
|
||||||
|
SETSRC: STX SRCLO ;Store Source Pointer
|
||||||
|
STY SRCHI
|
||||||
|
LDY #$00 ;Initialize Index Into String
|
||||||
|
RTS
|
||||||
|
|
||||||
|
;Retrieve Source String Pointer
|
||||||
|
GETDST: LDX DSTLO
|
||||||
|
LDY DSTHI
|
||||||
|
RTS
|
||||||
|
|
||||||
|
;Retrieve Source String Pointer
|
||||||
|
GETSRC: LDX SRCLO
|
||||||
|
LDY SRCHI
|
||||||
|
RTS
|
49
include/stddef.h02
Normal file
49
include/stddef.h02
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* C02 Standard Definitions File *
|
||||||
|
* Contains common constants and *
|
||||||
|
* functions used in libraries. */
|
||||||
|
|
||||||
|
/* Constant Definitions */
|
||||||
|
const #TRUE = $FF, #FALSE = 0;
|
||||||
|
|
||||||
|
/* Get Destination Pointer *
|
||||||
|
* Returns: Y,X=Destination address */
|
||||||
|
void getdst();
|
||||||
|
|
||||||
|
/* Get Source Pointer *
|
||||||
|
* Returns: Y,X=Source address */
|
||||||
|
void getsrc();
|
||||||
|
|
||||||
|
/* Retore Destination Pointer */
|
||||||
|
void resdst();
|
||||||
|
|
||||||
|
/* Restore A, X, and Y Registers */
|
||||||
|
void resreg();
|
||||||
|
|
||||||
|
/* Restore X, and Y Registers */
|
||||||
|
void resrxy();
|
||||||
|
|
||||||
|
/* Retore Source Pointer */
|
||||||
|
void ressrc();
|
||||||
|
|
||||||
|
/* Save Destination Pointer */
|
||||||
|
void savdst();
|
||||||
|
|
||||||
|
/* Save A, X, and Y Registers */
|
||||||
|
void savreg();
|
||||||
|
|
||||||
|
/* Save X, and Y Registers */
|
||||||
|
void savrxy();
|
||||||
|
|
||||||
|
/* Save Source Pointer */
|
||||||
|
void savsrc();
|
||||||
|
|
||||||
|
/* Set Destination Pointer *
|
||||||
|
* Args: &d - Destination address */
|
||||||
|
void setdst();
|
||||||
|
|
||||||
|
/* Set Source Pointer *
|
||||||
|
* Args: &d - Source address */
|
||||||
|
void setsrc();
|
||||||
|
|
||||||
|
/* Set Source Pointer to Destination Pointer */
|
||||||
|
void setsrd();
|
Loading…
x
Reference in New Issue
Block a user