From 5b09345f3c80a8be3cedde4e7f4b18bf3a741f21 Mon Sep 17 00:00:00 2001 From: Curtis F Kaylor Date: Mon, 30 Jul 2018 17:20:16 -0400 Subject: [PATCH] Added function clrmem() to module 'memory' --- doc/memory.txt | 8 +++++- include/memory.a02 | 5 ++++ include/memory.h02 | 15 +++++++---- py65/testmem.c02 | 65 +++++++++++++++++++++------------------------- 4 files changed, 51 insertions(+), 42 deletions(-) diff --git a/doc/memory.txt b/doc/memory.txt index f073345..80013e6 100644 --- a/doc/memory.txt +++ b/doc/memory.txt @@ -23,12 +23,18 @@ The following functions are defined: Note: Aliased to the setdst() routine which sets variables dstlo and dsthi as a pointer to the array. - memset(c, n); Fills first n bytes of the destination array set + memset(c, n); Fills first n bytes of the destination array set by a a prior memdst() call with character c. Note: dstlo and dsthi are left pointing to the destination array. + memclr(n, &s); Memory Clear: Fills first n bytes of array s with + the byte $00. + + Note: Calls memdst(&d) and memset(n,$00), leaving + dstlo and dsthi pointing to s. + p = memchr(c, n); Searches for character c in the first n bytes of the destination array set by a a prior memdst() call. diff --git a/include/memory.a02 b/include/memory.a02 index 0431695..535b97f 100644 --- a/include/memory.a02 +++ b/include/memory.a02 @@ -89,6 +89,11 @@ MEMCPL: LDA (SRCLO),Y ;Get Character from Source Array TYA ;Copy Index to Accumulater RTS ;Else Return +MEMCLR: JSR SETDST ;Set Destination Address + TAY ;Transer Count to Y + LDA #0 ;Set Fill Character to Null + ;and Fall into MEMSET + ;memset(c, n) - Fill Destination Array ;Args: A = Character to fill with ; Y = Number of bytes to fill diff --git a/include/memory.h02 b/include/memory.h02 index 192de7a..5f8a39d 100644 --- a/include/memory.h02 +++ b/include/memory.h02 @@ -14,6 +14,12 @@ void memdst(); * $FF if not found */ char memchr(); +/* Clear Array (Fill with $00) * + * Args: n - Number of bytes to fill * + * &s - Array to fill * + * Returns: Number of bytes filled */ +char memclr(); + /* Compare Destination Array against Source Array * * Args: n - Number of bytes to compare * * &s - Source array * @@ -26,14 +32,13 @@ char memcmp(); /* Copy Source Array to Destination Array * * Args: n - Number of bytes to copy * - * &s - Source array * + * &s - Source array * * Sets: Destination string specified by memdst() */ char memcpy(); -/* Fill Destination Array with Character * - * Args: c - Character to fill array with * +/* Fill Destination Array with Byte * + * Args: b - Character to fill array with * * n - Number of bytes to fill * * Uses: Destination array specified by memdst() * - * Returns: Number of characters copied */ + * Returns: Number of bytes copied */ char memset(); - diff --git a/py65/testmem.c02 b/py65/testmem.c02 index a9bca37..0f9d63f 100644 --- a/py65/testmem.c02 +++ b/py65/testmem.c02 @@ -4,7 +4,9 @@ #include #include +#include #include +#include #include char c, d, f, i, n, p; @@ -55,53 +57,43 @@ if (p) putln(&pass); else putln(&fail); newlin(); //Test memcmp() -puts("less="); puts(&less); -puts(" more="); puts(&more); -puts(" most="); putln(&most); +setdst(&less); printf("less=\"%s\", "); +setdst(&more); printf("more=\"%s\", "); +setdst(&most); printf("most=\"%s\"\n"); putln("memdst(&more);"); memdst(&more); -puts("memcmp(2, &most):"); -rcmp = memcmp(2, &most); +rcmp = memcmp(2, &most); +printf(rcmp,"memcmp(2, &most)=$%h:"); if (!rcmp) puts(&pass); else puts(&fail); -puts("memcmp(4, &most):"); rcmp = memcmp(4, &most); +printf(rcmp,"memcmp(4, &most)=$%h:"); if (rcmp :-) putln(&pass); else putln(&fail); -puts("memcmp(3, &more):"); -rcmp = memcmp(3, &more); +rcmp = memcmp(4, &more); +printf("memcmp(4, &more)=$%h:"); if (!rcmp) puts(&pass); else puts(&fail); -puts("memcmp(3, &less):"); -rcmp = memcmp(3, &less); +rcmp = memcmp(4, &less); +printf("memcmp(4, &less)=$%h:"); if (rcmp > 0) putln(&pass); else putln(&fail); newlin(); //Test memset() and memcpy() -putln("memdst(&temp);"); -memdst(&temp); +putln("memdst(&temp);"); memdst(&temp); -puts("memset(0,20); "); -memset(0,20); +puts("memset(0,20); "); memset(0,20); +puts("temp="); putln(&temp); -puts("temp="); -putln(&temp); +puts("memset('@',20); "); memset('@',20); +puts("temp="); putln(&temp); -puts("memset('@',20); "); -memset('@',20); +puts("memcpy(10, <tr); "); memcpy(10, <tr); +puts("temp="); putln(&temp); -puts("temp="); -putln(&temp); - -puts("memcpy(10, <tr); "); -memcpy(10, <tr); - -puts("temp="); -putln(&temp); - -puts("memcmp(10, <tr);"); +puts("memcmp(10, <tr);"); rcmp = memcmp(10, <tr); if (!rcmp) putln(&pass); else putln(&fail); @@ -110,13 +102,14 @@ 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); +memdst(&temp); memcpy(7,"ABCDEF"); printf("temp=\"%s\", "); +memdst(&dest); memcpy(7,"123456"); printf("dest=\"%s\"\n"); +putln("memdst(&dest);memswp(3,&temp);"); +memdst(&dest); memswp(3,&temp); +memdst(&temp); printf("temp=\"%s\":"); florps(memcmp(7,"123DEF")); +memdst(&dest); printf("dest=\"%s\":"); florps(memcmp(7,"ABC456")); +newlin(); + goto exit; - +void florps(rcmp) {if (rcmp) putln(&fail); else putln(&pass);} \ No newline at end of file