mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-22 01:31:33 +00:00
Updated and tested module 'memory'
This commit is contained in:
parent
1090e1e96a
commit
27b3636901
@ -112,7 +112,7 @@ MEMSEX: RTS
|
||||
;Sets: TEMP0 = Number of bytes to swap
|
||||
;Affects: A,X,Y,C,N,Z
|
||||
MEMSWP: JSR MEMSRC ;Initialize Source, Index, and Count
|
||||
MEMSWL: lDA (DSTLO),Y ;Get Character from Destination Array
|
||||
MEMSWL: LDA (DSTLO),Y ;Get Character from Destination Array
|
||||
TAX ;Save in X Register
|
||||
LDA (SRCLO),Y ;Get Character from Source Array
|
||||
STA (DSTLO),Y ;Copy to Destination Array
|
||||
|
@ -3,7 +3,7 @@
|
||||
*********************************************/
|
||||
|
||||
/* Sets Destination Array for subsequent function calls *
|
||||
* Args: &s - Destination string */
|
||||
* Args: &a - Destination array */
|
||||
void memdst();
|
||||
|
||||
/* Find Character in Destination Array *
|
||||
|
@ -93,47 +93,3 @@ PRHEX: AND #$0F ;Strip High Nybb
|
||||
ADC #$40 ;Convert to $30-$39,$41-$46
|
||||
CLD ;Clear Decimal Flag
|
||||
JMP PRCHR ;Print Hex Digit and Return
|
||||
|
||||
|
||||
;savdst() - Save Destination Pointer
|
||||
SAVDST: JSR GETDST ;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: STX TEMP1 ;Load X Index
|
||||
STY 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
|
||||
|
||||
;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
|
||||
|
@ -1,10 +1,15 @@
|
||||
/* py65mon Header File */
|
||||
|
||||
//Platform Specific Constants
|
||||
const #delkey = $08; //Backspace Key
|
||||
const #esckey = $1B; //Escape Key
|
||||
const #rtnkey = $0D; //Enter Key
|
||||
|
||||
//System Pointer Variables
|
||||
char srclo,srchi; //Source String Pointer for Library Functions
|
||||
char dstlo,dsthi; //Destination String Pointer for Library Functions
|
||||
char blklo,blkhi; //Block Segment Pointer
|
||||
char stklo,stkhi; //Stack Pointer
|
||||
char srclo,srchi; //Source String Pointer for Library Functions
|
||||
char dstlo,dsthi; //Destination String Pointer for Library Functions
|
||||
char blklo,blkhi; //Block Segment Pointer
|
||||
char stklo,stkhi; //Stack Pointer
|
||||
|
||||
//System Variables
|
||||
char blkslo, blkshi; //Block Start Address
|
||||
@ -12,8 +17,8 @@ char blkelo, blkehi; //Block End Address
|
||||
char blklen; //Block Segment Length
|
||||
char stkslo, stkshi; //Stack Start Address
|
||||
char stkelo, stkehi; //Stsck End Address
|
||||
|
||||
char temp0, temp1, temp2, temp3; //Temporary Variables
|
||||
char temp0, temp1; //Temporary Variables
|
||||
char temp2, temp3;
|
||||
|
||||
//Memory Mapped I/O
|
||||
char putcon; //Write Character to Console
|
||||
@ -27,8 +32,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
|
||||
void savdst(); //Save Deatination Pointer
|
||||
void savreg(); //Save Registers
|
||||
void setdst(); //Set Destination Pointer
|
||||
void setsrc(); //Set Source Pointer
|
||||
void setsrd(); //Set Source Pointer to Destination Pointer
|
||||
|
@ -30,7 +30,6 @@ Defined functions:
|
||||
Note: Writes carriage return and line feed
|
||||
via prchr($0D) and prchr($0A).
|
||||
|
||||
|
||||
c = rdkey(); Waits for keypress and returns ASCII code of
|
||||
key that was pressed.
|
||||
|
||||
@ -41,3 +40,23 @@ Defined functions:
|
||||
|
||||
Note: Writes argument to memory location putc.
|
||||
|
||||
resdst(); Restores the destination pointer from temp1 and
|
||||
temp2, respectively.
|
||||
|
||||
resreg(); Restores the A, X, and Y registers from temp1,
|
||||
temp1, and temp2, respectively.
|
||||
|
||||
resrxy(); Restores the X and Y registers from temp1 and
|
||||
temp2, respectively.
|
||||
|
||||
savdst(); Saves the destination pointer in temp1 and temp2,
|
||||
respectively.
|
||||
|
||||
Note: Calls getdst() and savrxy().
|
||||
|
||||
savreg(); Saves the A, X, and Y registers in temp0, temp1,
|
||||
and temp2, respectively.
|
||||
|
||||
savrxy(); Saves the X and Y registers in temp1 and temp2,
|
||||
respectively.
|
||||
|
||||
|
122
py65/testmem.c02
122
py65/testmem.c02
@ -1,8 +1,122 @@
|
||||
/****************************************
|
||||
* TESTMIO - Test Memory File Functions *
|
||||
****************************************/
|
||||
/*******************************************
|
||||
* TESTMEM - Test Array Handling Functions *
|
||||
*******************************************/
|
||||
|
||||
#include <py65.h02>
|
||||
#include <stddef.h02>
|
||||
#include <stdio.h02>
|
||||
#include <mio.h02>
|
||||
#include <memory.h02>
|
||||
|
||||
char c, d, f, i, n, p;
|
||||
char rlen, rcmp, rpos;
|
||||
char byts[255];
|
||||
char lttr[255];
|
||||
char nmbr[255];
|
||||
char temp[255];
|
||||
char dest[255];
|
||||
char less = "less";
|
||||
char more = "more";
|
||||
char most = "most";
|
||||
char fail = " Fail ";
|
||||
char pass = " Pass ";
|
||||
|
||||
void prtemp() {
|
||||
puts("temp: ");
|
||||
for (i=0; i<255; i++) {
|
||||
prbyte(temp[i]);
|
||||
//putchr(' ');
|
||||
}
|
||||
}
|
||||
|
||||
main:
|
||||
|
||||
//Populate arrays
|
||||
i = 0; c = 'a'; d = '0';
|
||||
do {
|
||||
byts[i] = i;
|
||||
lttr[i] = c;
|
||||
c++; if (c>'z') c = 'a';
|
||||
nmbr[i] = d;
|
||||
d++; if (d>'9') d = '0';
|
||||
i++;
|
||||
} while (i>0);
|
||||
|
||||
//Test memchr()
|
||||
putln("memdst(&byts);"); memdst(&byts);
|
||||
puts("memchr(i, 255);");
|
||||
p = #TRUE;
|
||||
for (i=0; i<255; i++) {
|
||||
//prbyte(i); prchr('='); prbyte(byts[i]); prchr(',');
|
||||
c = memchr(i,255);
|
||||
//prbyte(c); prchr(' '); prchr(' ');
|
||||
if (c <> i) p = #FALSE;
|
||||
}
|
||||
if (p) putln(&pass); else putln(&fail);
|
||||
newlin();
|
||||
|
||||
//Test memcmp()
|
||||
puts("less="); puts(&less);
|
||||
puts(" more="); puts(&more);
|
||||
puts(" most="); putln(&most);
|
||||
|
||||
putln("memdst(&more);");
|
||||
memdst(&more);
|
||||
|
||||
puts("memcmp(2, &most):");
|
||||
rcmp = memcmp(2, &most);
|
||||
if (!rcmp) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("memcmp(4, &most):");
|
||||
rcmp = memcmp(4, &most);
|
||||
if (rcmp :-) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("memcmp(3, &more):");
|
||||
rcmp = memcmp(3, &more);
|
||||
if (!rcmp) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("memcmp(3, &less):");
|
||||
rcmp = memcmp(3, &less);
|
||||
if (rcmp > 0) putln(&pass); else putln(&fail);
|
||||
newlin();
|
||||
|
||||
//Test memset() and memcpy()
|
||||
putln("memdst(&temp);");
|
||||
memdst(&temp);
|
||||
|
||||
puts("memset(0,20); ");
|
||||
memset(0,20);
|
||||
|
||||
puts("temp=");
|
||||
putln(&temp);
|
||||
|
||||
puts("memset('@',20); ");
|
||||
memset('@',20);
|
||||
|
||||
puts("temp=");
|
||||
putln(&temp);
|
||||
|
||||
puts("memcpy(10, <tr); ");
|
||||
memcpy(10, <tr);
|
||||
|
||||
puts("temp=");
|
||||
putln(&temp);
|
||||
|
||||
puts("memcmp(10, <tr);");
|
||||
rcmp = memcmp(10, <tr);
|
||||
if (!rcmp) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("memcmp(11, <tr);");
|
||||
rcmp = memcmp(11, <tr);
|
||||
if (rcmp > 0) putln(&pass); else putln(&fail);
|
||||
newlin();
|
||||
|
||||
memdst(&temp); memcpy("ABCDEF");
|
||||
memdst(&dest); memcpy("123456");
|
||||
puts("memdst(&dest);memswp(3,&temp);");
|
||||
memswp(3,&temp);
|
||||
rcmp = memcmp(6,"ABC456");
|
||||
memdst(&temp); rcmp = memcmp(6,"123DEF") | rcmp;
|
||||
if (rcmp) putln(&fail); else putln(&pass);
|
||||
goto exit;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user