diff --git a/doc/header.txt b/doc/header.txt index df174e9..7d32315 100644 --- a/doc/header.txt +++ b/doc/header.txt @@ -51,11 +51,6 @@ functions must be defined: Note: Does any needed ACSII conversions, then calls 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) 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 - temp0 Temporary variables used by stdlib.asm - temp1 - temp2 + temp0, temp1 Temporary variables used by stdlib.asm + temp2, temp3 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) NULKEY Returned if no Key was Pressed RTNKEY ASCII code for Return/Enter key (usually CR) - diff --git a/doc/stddef.txt b/doc/stddef.txt new file mode 100644 index 0000000..6c9080b --- /dev/null +++ b/doc/stddef.txt @@ -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 + +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 + + diff --git a/include/header.a02 b/include/header.a02 index d6d4f20..20eaba6 100644 --- a/include/header.a02 +++ b/include/header.a02 @@ -103,19 +103,3 @@ PRHEX: AND #$0F ;Strip High Nybble ADC #$06 ; Convert ':' to 'A'... PRHEXC: ADC #$30 ;Convert to ASCII Character 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 - diff --git a/include/header.h02 b/include/header.h02 index 82e8c30..8416ca7 100644 --- a/include/header.h02 +++ b/include/header.h02 @@ -34,4 +34,3 @@ 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 - diff --git a/include/stddef.a02 b/include/stddef.a02 new file mode 100644 index 0000000..4ea901c --- /dev/null +++ b/include/stddef.a02 @@ -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 diff --git a/include/stddef.h02 b/include/stddef.h02 new file mode 100644 index 0000000..9495f8e --- /dev/null +++ b/include/stddef.h02 @@ -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();