Added module 'test'

This commit is contained in:
Curtis F Kaylor 2018-07-29 21:25:33 -04:00
parent 0ec3d860e2
commit ba8d6e7ded
4 changed files with 317 additions and 0 deletions

107
doc/test.txt Normal file
View File

@ -0,0 +1,107 @@
Test Functions for C02 Programs
This module includes functions useful for writing testing and diagnostic programs.
At the beginning of the program use the directives
#include <stddef.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <test.h02>
The following strings are defined:
char pass = " Pass";
char fail = " Fail";
along with the following functions:
putadr(&d); Prints the string "address=$" followed by the
address of d as a four byte hexadecimal number.
The alternate calling syntax putadr(*,hi,lo);
may be used when an address is held in two
separate variables.
For use when testing and/or debugging functions
that get, set, or change addresses and pointers.
Note: Calls puts() with the harcoded string
"address=$" and putwrd().
trufls(b); Returns the constant #TRUE unless byte b is 0,
in which case #FALSE is returned.
For use when using bitwise and operator (&) and/or
exclusive-or operator (^) to combine multiple
results into a single pass or fail.
passed(); Prints the string " Pass" to the screen.
Note: Calls puts() with the string variable pass.
passln(); Prints the string " Pass" to the screen, followed
by a New Line.
Note: Calls passed() and newlin().
failed(); Prints the string " Fail" to the screen.
Note: Calls puts() with the string variable fail.
passln(); Prints the string " Fail" to the screen, followed
by a New Line.
Note: Calls failed() and newlin().
psorfl(b); Prints the string " Pass" if b is non-zero, or the
string " Fail" if b is zero.
For use when testing functions that return a
non-zero result on success and a zero result on
failure.
Note: Calls trufls(), then passed() or failed()
depending on the result.
psflln(b); Prints the string " Pass" and a New Line if b is
non-zero, or the string " Fail" and a New Line if
b is zero.
Note: Calls trufls(), then passln() or failln()
depending on the result.
florps(b); Prints the string " Fail" if b is non-zero, or the
string " Pass" if b is zero.
For use when testing functions that return a
zero result on success and a non-zero result on
failure.
Note: Calls trufls(), then passed() or failed()
depending on the result.
flpsln(b); Prints the string " Fail" and a New Line if b is
non-zero, or the string " Pass" and a New Line if
b is zero.
Note: Calls trufls(), then failln() or passln()
depending on the result.
Note: This library expects the following functions to be defined:
newlin(); Print New Line
puts(&s); Put String to Screen
savrxy(); Save X and Y Registers
along with the zero page variables
srclo,srchi: Source Address Pointer
the external variables
temp1,temp2: Temporary Variables
and the constants
#TRUE, #FALSE True and False

91
include/test.a02 Normal file
View File

@ -0,0 +1,91 @@
; C02 library test.h02 assembly language subroutines
; Requires external routines NEWLIN, PRBYTE and PUTS
; external zero page locations SRCLO and srchi
; and external locations TEMP0, TEMP1, and TEMP2.
; and external constants #TRUE and #FALSE
;Predefined Strings
PASS DC " Pass",0
FAIL DC " Fail",0
;putadr(&addr) - PUT ADdRess to screen
;Args: Y = Address MSB
; X = Address LSB
;Calls: PUTS = Put String
; PRBYTE = Print Byte
; SAVRXY = Save X and Y Registers
;Affects: A,Y,X,N,Z,C
PUTADR: JSR SAVRXY ;Save Address
LDY #>PUTADS ;Load String MSB
LDX #<PUTADS ;Load String LSB
JSR PUTS ;Print String
JMP PUTWRA ;Print MSB & LSB
PUTADS DC "address=$",0
;trufls(val) - convert value to TRUe or FaLSe
;Args: A = Value to Convert
;Returns: A=#TRUE,N=1,Z=0 if value is not zeto
; #FALSE,N=0,Z=1 if value is 0
TRUFLS: ORA #0 ;Evaluate Argument
BEQ TRUFLX ;If Not 0
LDA #TRUE ; Return TRUE
TRUFLX: RTS ;Else Return FALSE
;psorfl(val) - PaSs if true OR FaiL if false
;Args: A = Value to evaluate
;Calls: PASSED or FAILED
;Affects: A,X,Y,N,Z,C
PSORFL: ORA #0 ;Evaluate Argument
BEQ FAILED ;If 0, execute FAILED
;Else fall into PASSED
;passed() - print PASSED message
;Calls: PUTS = Put String
;Affects: A,X,Y,N,Z,C
PASSED: LDY #>PASS ;Load Pass Message MSB
LDX #<PASS ;Load Pass Message LSB
JMP PUTS ;Print Pass Message
;psflln(val) - print PaSs or FaiL and newLiNe
;Args: A = Value to evaluate
;Calls: PASSED or FAILED
;Affects: A,X,Y,N,Z,C
PSFLLN: ORA #0 ;Evaluate Argument
BEQ FAILLN ;If 0, execute FAILLN
;Else fall into PASSLN
;passln() - print PASSED message and newline
;Calls: PASSED and NEWLIN - Print Newline
;Affects: A,X,Y,N,Z,C
PASSLN: JSR PASSED ;Print Passed Message
JMP NEWLIN ;Print Newline and Return
;florps(val) - FaiL if true OR PaSs if false
;Args: A = Value to evaluate
;Calls: PASSED or FAILED
;Affects: A,X,Y,N,Z,C
FLORPS: ORA #0 ;Evaluate Argument
BEQ PASSED ;If 0, execute PASSED
;Else fall into FAILED
;passed() - print FAILED message
;Calls: PUTS = Put String
;Affects: A,X,Y,N,Z,C
FAILED: LDY #>FAIL ;Load Fail Message MSB
LDX #<FAIL ;Load Fail Message LSB
JMP PUTS ;Print Fail Message
;flpsln(val) - print FaiL or PaSs and newLiNe
;Args: A = Value to evaluate
;Calls: PASSED or FAILED
;Affects: A,X,Y,N,Z,C
FLPSLN: ORA #0 ;Evaluate Argument
BEQ PASSLN ;If 0, execute PASSLN
;Else fall into FAILLN
;failln() - print PASSED message and newline
;Calls: PASSED and NEWLIN - Print Newline
;Affects: A,X,Y,N,Z,C
FAILLN: JSR FAILED ;Print Passed Message
JMP NEWLIN ;Print Newline and Return

53
include/test.h02 Normal file
View File

@ -0,0 +1,53 @@
/*********************************************
* stdlib - Template Library Routines for C02 *
*********************************************/
char fail[]; //" Fail" - Failed Message
char pass[]; //" Pass" - Passed Message
/* Print Failed Message */
char failed();
/* Print Failed Message *
* followed by a New Line */
char failln();
/* Print Failed Message if True *
* or Passed Message if False *
* Args: b - Value to evaluate */
void florps();
/* Print Failed Message if True *
* or Passed Message if False *
* followed by a New Line *
* Args: b - Value to evaluate */
void flpsln();
/* Print Passed Message */
char passed();
/* Print Passed Message *
* followed by a New Line */
char passln();
/* Print Passed Message if True *
* or Failed Message if False *
* followed by a New Line *
* Args: b - Value to evaluate */
void psflln();
/* Print Passed Message if True *
* or Failed Message if False *
* Args: b - Value to evaluate */
void psorfl();
/* Print Address in format *
* "address=$HHHH" *
* Args: &d - Address */
char putadr();
/* Convert Value to TRUE or FALSE *
* Args: v - Value to convert *
* Returns: #FALSE if value is 0, *
* otherwise #TRUE */
char trufls();

66
py65/testtst.c02 Normal file
View File

@ -0,0 +1,66 @@
/**********************************************
* TESTTST - Test the Test Module for py65mon *
**********************************************/
#include <py65.h02>
#include <stddef.h02>
#include <stdlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <test.h02>
char tstvar; //Test Variable
main:
//Print Predefined Strings
setdst(&pass);printf("pass=\"%s\", ");
setdst(&fail);printf("fail=\"%s\"\n");
newlin();
//Test putadr()
puts("putadr(*,1,0); "); putadr(*,1,0); puts("\n");
puts("putadr(&$1234); "); putadr(&$1234); puts("\n");
puts("putadr(&tstvar); "); putadr(&tstvar); puts("\n");
newlin();
//Test passed() and failed()
puts("passed();"); passed(); puts(", ");
puts("failed();"); failed(); puts("\n");
newlin();
//Test passln() and failln()
puts("passln();"); passln();
puts("failln();"); failln();
newlin();
//Test trufls()
printf(trufls($00),"trufls($00)=$%h\n");
printf(trufls($01),"trufls($01)=$%h\n");
printf(trufls($FF),"trufls($FF)=$%h\n");
newlin();
//Test psorfl()
puts("psorfl($00);"); psorfl($00); puts(", ");
puts("psorfl($01);"); psorfl($01); puts(", ");
puts("psorfl($FF);"); psorfl($FF); puts("\n");
//Test psorfl()
puts("florps($00);"); florps($00); puts(", ");
puts("florps($01);"); florps($01); puts(", ");
puts("florps($FF);"); florps($FF); puts("\n");
newlin();
//Test psflln()
puts("psflln($00);"); psflln($00);
puts("psflln($01);"); psflln($01);
puts("psflln($FF);"); psflln($FF);
newlin();
//Test flpsln()
puts("flpsln($00);"); flpsln($00);
puts("flpsln($01);"); flpsln($01);
puts("flpsln($FF);"); flpsln($FF);
anykey();
goto exit;