Moved block test program from py65/ to test/

This commit is contained in:
Curtis F Kaylor 2020-10-15 20:19:20 -04:00
parent 4c27db63ee
commit 1797d376db
2 changed files with 51 additions and 46 deletions

View File

@ -2,12 +2,14 @@
;C02 library block.h02 assembly language subroutines ;C02 library block.h02 assembly language subroutines
;Requires External Zero Page Variables ;Requires External Zero Page Variables
;BLKLO, BLKHI, DSTLO, DSTHI, SRCLO, SRCHI ;BLKLO, BLKHI, DSTPTR, SRCPTR
;External Variables ;External Variables
;BLKSLO, BLKSHI, BLKELO, BLKEHI, BLKLEN, TEMP0, TEMP1, TEMP2 ;BLKSLO, BLKSHI, BLKELO, BLKEHI, BLKLEN, TEMP0, TEMP1, TEMP2
;External Routines ;External Routines
;MEMCMP, MEMCPY, MEMSRC, RESDST, SAVDST, SETDST, SETSRC, SETSRD ;MEMCMP, MEMCPY, MEMSRC, RESDST, SAVDST, SETDST, SETSRC, SETSRD
SUBROUTINE BLOCK
;blkbgn(&b) - Set Block Start Address ;blkbgn(&b) - Set Block Start Address
;Args: X,Y = Address ;Args: X,Y = Address
;Sets: BLKSLO, BLKSHI = Block Start Address ;Sets: BLKSLO, BLKSHI = Block Start Address
@ -80,8 +82,8 @@ BLKSEX: JMP BLKRST ;Reset Block Pointer and Return
;Args: n = Number of Bytes to Append ;Args: n = Number of Bytes to Append
; m = Array of Bytes to Append ; m = Array of Bytes to Append
;Uses: BLKELO, BLKEHI - Block End Address ;Uses: BLKELO, BLKEHI - Block End Address
;Sets: DSTLO, DSTHI = Pointer to Bytes in Block ;Sets: DSTPTR = Pointer to Bytes in Block
; SRCHI, SRCLO = Pointer to m ; SRCPTR = Pointer to m
; TEMP0 = Number of Bytes to Append ; TEMP0 = Number of Bytes to Append
;Updates: BLKLO, BLKHI = Block Pointer ;Updates: BLKLO, BLKHI = Block Pointer
;Returns: A=$FF - Append Successful ;Returns: A=$FF - Append Successful
@ -94,8 +96,8 @@ BLKPUT: JSR MEMSRC ;Set Source Address & Number of Bytes
;Args: A = Number of Bytes to Read ;Args: A = Number of Bytes to Read
; Y,X = Address of Array ; Y,X = Address of Array
;Uses: BLKELO, BLKEHI = Block End Address ;Uses: BLKELO, BLKEHI = Block End Address
;Sets: DSTLO, DSTHI = Address of Array ;Sets: DSTPTR = Address of Array
; SRCHI, SRCLO = Current Pointer in Block ; SRCPTR = Current Pointer in Block
; TEMP0 = Number of Bytes to Append ; TEMP0 = Number of Bytes to Append
;Updates: BLKLO, BLKHI = Next Segment in Block ;Updates: BLKLO, BLKHI = Next Segment in Block
;Returns: A=$FF - Append Successful ;Returns: A=$FF - Append Successful
@ -113,14 +115,14 @@ BLKCPY: LDY #0 ;Copy Source To Destination
;blkmem(n, &m) - Search for n Bytes of m in Block ;blkmem(n, &m) - Search for n Bytes of m in Block
;Args: n = Number of Bytes to Compare ;Args: n = Number of Bytes to Compare
; m = Array of Bytes to Search For ; m = Array of Bytes to Search For
;Sets: DSTLO, DSTHI = Pointer to Segment in Block ;Sets: DSTPTR = Pointer to Segment in Block
; SRCHI, SRCLO = Pointer to m ; SRCPTR = Pointer to m
; TEMP0 = Number of Bytes to Compare ; TEMP0 = Number of Bytes to Compare
;Returns: A=$FF - Bytes found ;Returns: A=$FF - Bytes found
; A=$00 - Bytes not found ; A=$00 - Bytes not found
BLKMEM: JSR MEMSRC ;Initialize Source, Index, and Count BLKMEM: JSR MEMSRC ;Initialize Source, Index, and Count
JSR BLKDSS ;Set Destination Pointer To Block Start JSR BLKDSS ;Set Destination Pointer To Block Start
LDX #DSTLO ;Set BLKNXX Pointer to SRCLO,SRCHI LDX #DSTPTR ;Set BLKNXX Pointer to DSTPTR
BLKMEL: LDY #0 ;Initialize Index BLKMEL: LDY #0 ;Initialize Index
JSR MEMCML ;Compare Source to Destination JSR MEMCML ;Compare Source to Destination
BEQ BLKTRU ;If Equal, Exit TRUE BEQ BLKTRU ;If Equal, Exit TRUE
@ -142,17 +144,17 @@ BLKRTS: RTS
;BLKNXD() - Move Destination Pointer to Next Segment ;BLKNXD() - Move Destination Pointer to Next Segment
;Uses: BLKLEN - Block Segment Length ;Uses: BLKLEN - Block Segment Length
;Updates: DSTLO, DSTHI = Block Pointer ;Updates: DSTPTR, DSTPTR+1 = Block Pointer
;Affects: C,N,Z ;Affects: C,N,Z
;Returns: A=$FF - Destination Pointer Moved ;Returns: A=$FF - Destination Pointer Moved
; A=$00 - Error: Pointer Overflow or Length 0 ; A=$00 - Error: Pointer Overflow or Length 0
BLKNXD: LDX #DSTLO ;Set X to Destination Pointer BLKNXD: LDX #DSTPTR ;Set X to Destination Pointer
JMP BLKNXX ;and Move to Next Segment JMP BLKNXX ;and Move to Next Segment
;blknxx() - Move Pointer to Next Segment ;blknxx() - Move Pointer to Next Segment
;Args: X = Zero Page Address of Pointer ;Args: X = Zero Page Address of Pointer
;Uses: BLKLEN - Block Segment Length ;Uses: BLKLEN - Block Segment Length
;Updates: DSTLO, DSTHI = Block Pointer ;Updates: DSTPTR, DSTPTR+1 = Block Pointer
;Affects: C,N,Z ;Affects: C,N,Z
;Returns: A=$FF - Destination Pointer Moved ;Returns: A=$FF - Destination Pointer Moved
; A=$00 - Error: Pointer Overflow or Length 0 ; A=$00 - Error: Pointer Overflow or Length 0
@ -218,8 +220,8 @@ BLKPRL: CMP BLKELO ; >= Block End LSB
; BLKSLO, BLKSHI = Block Start Address ; BLKSLO, BLKSHI = Block Start Address
; BLKELO, BLKEHI = Block End Address ; BLKELO, BLKEHI = Block End Address
; BLKLEN = Block Segment Size ; BLKLEN = Block Segment Size
; DSTLO, DSTHI = Pointer to Segment in Block ; DSTPTR = Pointer to Segment in Block
; SRCHI, SRCLO = Pointer to Segment in Block ; SRCPTR = Pointer to Segment in Block
;Affects: A,Y,C,N,Z ;Affects: A,Y,C,N,Z
BLKSRT: LDA BLKLEN ;Get Segment Length BLKSRT: LDA BLKLEN ;Get Segment Length
BEQ BLKRTS ;If 0 Return BEQ BLKRTS ;If 0 Return
@ -233,16 +235,16 @@ BLKSRP: LDY #0 ;If First Byte of
BLKSRD: JSR BLKNXD ;Move Destination Pointer BLKSRD: JSR BLKNXD ;Move Destination Pointer
BCS BLKSRE ;If Not Past Block End BCS BLKSRE ;If Not Past Block End
LDY #0 ; LDY #0 ;
LDA (DSTLO),Y ;and Destination String Populated LDA (DSTPTR),Y ;and Destination String Populated
BEQ BLKSRE ; BEQ BLKSRE ;
JSR STRCML ; Compare Destination String with Source String JSR STRCML ; Compare Destination String with Source String
BPL BLKSRD ; If Destination < Source BPL BLKSRD ; If Destination < Source
JSR SETSRD ; Set Source Pointer to Destination Pointer JSR SETSRD ; Set Source Pointer to Destination Pointer
JMP BLKSRD ; Check Next Destination Segment JMP BLKSRD ; Check Next Destination Segment
BLKSRE: LDA SRCHI ;If Source Pointer BLKSRE: LDA SRCPTR+1 ;If Source Pointer
CMP BLKHI ; <> Block Pointer CMP BLKHI ; <> Block Pointer
BNE BLKSRS BNE BLKSRS
LDA SRCLO LDA SRCPTR
CMP BLKLO CMP BLKLO
BEQ BLKSRN BEQ BLKSRN
BLKSRS: JSR BLKSWL ; Swap Source and Pointer BLKSRS: JSR BLKSWL ; Swap Source and Pointer
@ -253,8 +255,8 @@ BLKSRN: JSR BLKNXT ;Move Block Pointer
;blkstr(&s) - Search for String s in Block and ;blkstr(&s) - Search for String s in Block and
; Copy Segment to Destination Array if Found ; Copy Segment to Destination Array if Found
;Args: Y,X = Address of Search String ;Args: Y,X = Address of Search String
;Uses: DSTLO.DSTHI = Address of Destination Array ;Uses: DSTPTR = Address of Destination Array
;Sets: SRCLO,SRCHI = Pointer to Segment in Block (if found) ;Sets: SRCPTR = Pointer to Segment in Block (if found)
; TEMP0 = Index within segment ; TEMP0 = Index within segment
; TEMP1,TEMP2 = Destination String Pointer ; TEMP1,TEMP2 = Destination String Pointer
;Affects: Y,C ;Affects: Y,C
@ -269,7 +271,7 @@ BLKSTR: JSR SETSRC ;Set Source Pointer to Search String
LDX BLKSLO ;Set Source Pointer To Block Start LDX BLKSLO ;Set Source Pointer To Block Start
LDY BLKSHI LDY BLKSHI
JSR SETSRC JSR SETSRC
LDX #SRCLO ;Set BLKNXX Pointer to SRCLO,SRCHI LDX #SRCPTR ;Set BLKNXX Pointer to SRCPTR
BLKSTL: LDY #0 ;Initialize Index BLKSTL: LDY #0 ;Initialize Index
JSR STRCML ;Compare Source to Destination JSR STRCML ;Compare Source to Destination
BEQ BLKSTS ;If Not Equal BEQ BLKSTS ;If Not Equal
@ -286,7 +288,7 @@ BLKSTS: JSR RESDST ; Restore Destination Pointer
; m = Array to swap bytes from ; m = Array to swap bytes from
;Sets: TEMP0 = Number of Bytes to Swap ;Sets: TEMP0 = Number of Bytes to Swap
;Uses: BLKLO, BLKHI = Block Pointer ;Uses: BLKLO, BLKHI = Block Pointer
; DSTLO, DSTHI = Pointer to Temporary Storage Array ; DSTPTR, DSTPTR+1 = Pointer to Temporary Storage Array
;Affects: A,Y,C,N,Z ;Affects: A,Y,C,N,Z
BLKSWP: JSR MEMSRC ;Set Source Address and Index BLKSWP: JSR MEMSRC ;Set Source Address and Index
BLKSWL: JSR BLKDST ;Set Destination Pointer to Block Pointer BLKSWL: JSR BLKDST ;Set Destination Pointer to Block Pointer
@ -295,7 +297,7 @@ BLKSWL: JSR BLKDST ;Set Destination Pointer to Block Pointer
;blksrc() - Set Source Pointer to Block Pointer ;blksrc() - Set Source Pointer to Block Pointer
;Uses: BLKLO,BLKHI = Block Segment Pointer ;Uses: BLKLO,BLKHI = Block Segment Pointer
;Sets: SRCLO,SRCHI = Source Array Pointer ;Sets: SRCPTR = Source Array Pointer
;Affects: X,N,Z ;Affects: X,N,Z
;Returns: Y = 0 ;Returns: Y = 0
BLKSRC: LDX BLKLO BLKSRC: LDX BLKLO
@ -304,7 +306,7 @@ BLKSRC: LDX BLKLO
;blkdst() - Set Destination Pointer to Block Pointer ;blkdst() - Set Destination Pointer to Block Pointer
;Uses: BLKLO,BLKHI = Block Segment Pointer ;Uses: BLKLO,BLKHI = Block Segment Pointer
;Sets: DSTLO,DSTHI = Destination Array Pointer ;Sets: DSTPTR,DSTPTR+1 = Destination Array Pointer
;Affects: N,Z ;Affects: N,Z
;Returns: X = Block Pointer LSB ;Returns: X = Block Pointer LSB
; Y = Block Pointer MSB ; Y = Block Pointer MSB
@ -314,7 +316,7 @@ BLKDST: LDX BLKLO
;blkdst() - Set Destination Pointer to Block Start ;blkdst() - Set Destination Pointer to Block Start
;Uses: BLKSLO,BLKSHI = Block Start Address ;Uses: BLKSLO,BLKSHI = Block Start Address
;Sets: DSTLO,DSTHI = Destination Array Pointer ;Sets: DSTPTR,DSTPTR+1 = Destination Array Pointer
;Affects: N,Z ;Affects: N,Z
;Returns: X = Block Start LSB ;Returns: X = Block Start LSB
; Y = Block Start MSB ; Y = Block Start MSB
@ -323,25 +325,27 @@ BLKDSS: LDX BLKSLO
JMP SETDST ;Set Destination and Return JMP SETDST ;Set Destination and Return
;Block Debug Routine ;Block Debug Routine
BLKDBG: LDA DSTHI BLKDBG: LDA DSTPTR+1
CMP #$43 CMP #$43
BNE BLKDBX BNE BLKDBX
LDA DSTLO LDA DSTPTR
CMP #$57 CMP #$57
BNE BLKDBX BNE BLKDBX
NOP ;Break Point NOP ;Break Point
BLKDBX: RTS BLKDBX: RTS
;Print Destination Address ;Print Destination Address
BLKPDA LDA DSTHI ;Print Destination MSB BLKPDA LDA DSTPTR+1 ;Print Destination MSB
JSR PRBYTE JSR PRBYTE
LDA DSTLO ;Print Destination LSB LDA DSTPTR ;Print Destination LSB
JSR PRBYTE JSR PRBYTE
JMP PUTSPC ;Print Space JMP PUTSPC ;Print Space
;Print Destination Address ;Print Destination Address
BLKPSA LDA SRCHI ;Print Source MSB BLKPSA LDA SRCPTR+1 ;Print Source MSB
JSR PRBYTE JSR PRBYTE
LDA SRCLO ;Print Source LSB LDA SRCPTR ;Print Source LSB
JSR PRBYTE JSR PRBYTE
JMP PUTSPC ;Print Space JMP PUTSPC ;Print Space
ENDSUBROUTINE

View File

@ -1,12 +1,13 @@
/******************************************* /*****************************************
* TESTBLK - Test Array Handling Functions * * TESTBLK - Test Module block Functions *
*******************************************/ *****************************************/
//todo: Test blknxt() and blkprv() //todo: Test blknxt() and blkprv()
#include <py65.h02> //Specify System Header using -H option
#include <stddef.h02> #include <stddef.h02>
#include <stdlib.h02> #include <stdlib.h02>
#include <intlib.h02>
#include <stdio.h02> #include <stdio.h02>
#include <stdiox.h02> #include <stdiox.h02>
#include <string.h02> #include <string.h02>
@ -66,7 +67,7 @@ setchk(&$4321); chkadr(blkhi,blklo);
puts("blkset('@'); "); puts("blkset('@'); ");
blkset('@'); r=chkptr(&$4321); blkset('@'); r=chkptr(&$4321);
while (blkget(1,&sgmt)) {if (sgmt<>'@') r=#FALSE;} psflln(r); while (blkget(1,&sgmt)) {if (sgmt[0]<>'@') r=#FALSE;} psflln(r);
newlin();//if (anykey()==#ESCKEY) goto exit; newlin();//if (anykey()==#ESCKEY) goto exit;
@ -99,15 +100,15 @@ puts("blkput(@sgmt, &sgmt);\n"); blkset(0); blkrst(); r = #TRUE;
for (i=0; i<10; i++) { for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(i,&sgmt); savlo=blklo;savhi=blkhi; printf(i,"%d: "); nsgmt(i,&sgmt); savlo=blklo;savhi=blkhi;
blkput(@sgmt,&sgmt); seglo[i]=savlo; seghi[i]=savhi; blkput(@sgmt,&sgmt); seglo[i]=savlo; seghi[i]=savhi;
putadr(*,savhi,savlo); puts(" _blk="); prtseg(*,savhi,savlo); putadr(.,savhi,savlo); puts(" _blk="); prtseg(.,savhi,savlo);
setdst(*,savhi,savlo); if (memcmp(@sgmt,&sgmt)) r = #FALSE; setdst(.,savhi,savlo); if (memcmp(@sgmt,&sgmt)) r = #FALSE;
} }
puts("blkput:"); psflln(r); newlin(); puts("blkput:"); psflln(r); newlin();
puts("blkget(@temp, &temp);\n"); blkrst(); r = #TRUE; puts("blkget(@temp, &temp);\n"); blkrst(); r = #TRUE;
for (i=0; i<10; i++) { for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(i,&sgmt); memclr(@temp, &temp); printf(i,"%d: "); nsgmt(i,&sgmt); memclr(@temp, &temp);
putadr(*,blkhi,blklo); r = blkget(@temp, &temp); putadr(.,blkhi,blklo); r = blkget(@temp, &temp);
setdst(&temp); if (memcmp(@sgmt, &sgmt)) r = #FALSE; setdst(&temp); if (memcmp(@sgmt, &sgmt)) r = #FALSE;
puts(" temp="); prtseg(&temp); puts(" temp="); prtseg(&temp);
} }
@ -119,7 +120,7 @@ for (i=9; i:+; i--) {
blkmem(@sgmt,&sgmt); blkmem(@sgmt,&sgmt);
if (dstlo<>seglo[i]) r = #FALSE; if (dstlo<>seglo[i]) r = #FALSE;
if (dsthi<>seghi[i]) r = #FALSE; if (dsthi<>seghi[i]) r = #FALSE;
putadr(*,dsthi,dstlo); puts(" _blk="); prtseg(*,dsthi,dstlo); putadr(.,dsthi,dstlo); puts(" _blk="); prtseg(.,dsthi,dstlo);
} }
puts("blkmem:"); psflln(r); newlin(); puts("blkmem:"); psflln(r); newlin();
@ -130,7 +131,7 @@ for (i=0; i<10; i++) {
setdst(&temp); blkstr(&sgmt.key); setdst(&temp); blkstr(&sgmt.key);
if (srclo<>seglo[i]) r = #FALSE; if (srclo<>seglo[i]) r = #FALSE;
if (srchi<>seghi[i]) r = #FALSE; if (srchi<>seghi[i]) r = #FALSE;
putadr(*,srchi,srclo); puts(" temp="); prtseg(&temp); putadr(.,srchi,srclo); puts(" temp="); prtseg(&temp);
if (memcmp(@sgmt, &sgmt)) r = #FALSE; if (memcmp(@sgmt, &sgmt)) r = #FALSE;
i++; if (i=9) i=0; //evens then odds i++; if (i=9) i=0; //evens then odds
} }
@ -139,7 +140,7 @@ puts("blkstr:"); psflln(r); anykey();
puts("blksrt(&temp);\n"); r = #TRUE; blksrt(&temp);blkrst(); puts("blksrt(&temp);\n"); r = #TRUE; blksrt(&temp);blkrst();
for (i=0; i<10; i++) { for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(sorted[i],&sgmt); memclr(@temp, &temp); printf(i,"%d: "); nsgmt(sorted[i],&sgmt); memclr(@temp, &temp);
putadr(*,blkhi,blklo); r = blkget(@temp, &temp); putadr(.,blkhi,blklo); r = blkget(@temp, &temp);
setdst(&temp); if (memcmp(@sgmt, &sgmt)) r = #FALSE; setdst(&temp); if (memcmp(@sgmt, &sgmt)) r = #FALSE;
puts(" temp="); prtseg(&temp); puts(" temp="); prtseg(&temp);
} }
@ -151,16 +152,16 @@ goto exit;
char chkptr() { char chkptr() {
setchk(); //pass through args setchk(); //pass through args
putadr(*,blkhi,blklo); putadr(.,blkhi,blklo);
return cmpadr(*,blkhi,blklo); return cmpadr(.,blkhi,blklo);
} }
void setchk() { void setchk() {
chklo=X; chkhi=Y; chklo=X; chkhi=Y;
} }
void chkadr(tmphi,tmplo) { void chkadr(tmphi,tmplo) {
putadr(*,tmphi,tmplo); putadr(.,tmphi,tmplo);
cmpadr(*,tmphi,tmplo); cmpadr(.,tmphi,tmplo);
psflln(tmplo & tmphi); psflln(tmplo & tmphi);
} }
@ -192,7 +193,7 @@ void numstr(n,yy,xx) {
strdst(&temp); strcut(mult(n,5),&numbrs); //Copy Representation strdst(&temp); strcut(mult(n,5),&numbrs); //Copy Representation
temp[5] = 0; //Cut off remainder of String temp[5] = 0; //Cut off remainder of String
z=strchr(' ', &temp); if (z:+) temp[z]=0; //and terminate at space z=strchr(' ', &temp); if (z:+) temp[z]=0; //and terminate at space
setdst(*,yy,xx); strcpy(&temp); setdst(.,yy,xx); strcpy(&temp);
} }
//Build String Segment in Temp //Build String Segment in Temp
@ -201,7 +202,7 @@ void nsgmt(n,tmphi,tmplo) {
numstr(n,&tseg.key); numstr(n,&tseg.key);
tseg.flag = trufls(n); tseg.flag = trufls(n);
tseg.value = n; tseg.value = n;
setdst(*,tmphi,tmplo); memcpy(@tseg,&tseg); setdst(.,tmphi,tmplo); memcpy(@tseg,&tseg);
} }
//Print Addresses //Print Addresses