/*
|
/*
|
* This test covers the four block OUT instructions OUTI, OUTD,
|
* This test covers the four block OUT instructions OUTI, OUTD,
|
* OTIR, and OTDR. The test works by first creating a buffer
|
* OTIR, and OTDR. The test works by first creating a buffer
|
* of data, then doing a block-out instruction from the buffer
|
* of data, then doing a block-out instruction from the buffer
|
* to a special checksum output port.
|
* to a special checksum output port.
|
*
|
*
|
* The test self-checks by performing a checksum of the buffer
|
* The test self-checks by performing a checksum of the buffer
|
* and comparing it with the result read out of the checksum
|
* and comparing it with the result read out of the checksum
|
* port.
|
* port.
|
*/
|
*/
|
|
|
#include "tv80_env.h"
|
#include "tv80_env.h"
|
|
|
#define BUF_SIZE 128
|
#define BUF_SIZE 128
|
|
|
char buf[BUF_SIZE];
|
char buf[BUF_SIZE];
|
|
|
char cksum_up (char *buf, char len) {
|
char cksum_up (char *buf, char len) {
|
// pointer should be in 4(ix) and 5(ix), length in 6(ix)
|
// pointer should be in 4(ix) and 5(ix), length in 6(ix)
|
cksum_value = 0;
|
cksum_value = 0;
|
_asm
|
_asm
|
ld l, 4(ix)
|
ld l, 4(ix)
|
ld h, 5(ix)
|
ld h, 5(ix)
|
ld b, 6(ix)
|
ld b, 6(ix)
|
ld c, #_cksum_accum
|
ld c, #_cksum_accum
|
otir
|
otir
|
in a, (_cksum_value)
|
in a, (_cksum_value)
|
ld l, a
|
ld l, a
|
_endasm;
|
_endasm;
|
}
|
}
|
|
|
char cksum_dn (char *buf, char len) {
|
char cksum_dn (char *buf, char len) {
|
// pointer should be in 4(ix) and 5(ix), length in 6(ix)
|
// pointer should be in 4(ix) and 5(ix), length in 6(ix)
|
cksum_value = 0;
|
cksum_value = 0;
|
//buf += BUF_SIZE-1;
|
//buf += BUF_SIZE-1;
|
_asm
|
_asm
|
ld de, #127
|
ld de, #127
|
ld l, 4(ix)
|
ld l, 4(ix)
|
ld h, 5(ix)
|
ld h, 5(ix)
|
add hl, de
|
add hl, de
|
ld b, 6(ix)
|
ld b, 6(ix)
|
ld c, #_cksum_accum
|
ld c, #_cksum_accum
|
otdr
|
otdr
|
in a, (_cksum_value)
|
in a, (_cksum_value)
|
ld l, a
|
ld l, a
|
_endasm;
|
_endasm;
|
}
|
}
|
|
|
char cksum_up_sn (char *buf, char len) {
|
char cksum_up_sn (char *buf, char len) {
|
// pointer should be in 4(ix) and 5(ix), length in 6(ix)
|
// pointer should be in 4(ix) and 5(ix), length in 6(ix)
|
cksum_value = 0;
|
cksum_value = 0;
|
|
|
_asm
|
_asm
|
ld l, 4(ix)
|
ld l, 4(ix)
|
ld h, 5(ix)
|
ld h, 5(ix)
|
ld b, 6(ix)
|
ld b, 6(ix)
|
ld c, #_cksum_accum
|
ld c, #_cksum_accum
|
ld a, #0
|
ld a, #0
|
|
|
cksum_up_sn_loop:
|
cksum_up_sn_loop:
|
outi
|
outi
|
cp b
|
cp b
|
jp nz, cksum_up_sn_loop
|
jp nz, cksum_up_sn_loop
|
|
|
in a, (_cksum_value)
|
in a, (_cksum_value)
|
ld l, a
|
ld l, a
|
_endasm;
|
_endasm;
|
}
|
}
|
|
|
char cksum_dn_sn (char *buf, char len) {
|
char cksum_dn_sn (char *buf, char len) {
|
// pointer should be in 4(ix) and 5(ix), length in 6(ix)
|
// pointer should be in 4(ix) and 5(ix), length in 6(ix)
|
cksum_value = 0;
|
cksum_value = 0;
|
|
|
_asm
|
_asm
|
ld de, #127
|
ld de, #127
|
ld l, 4(ix)
|
ld l, 4(ix)
|
ld h, 5(ix)
|
ld h, 5(ix)
|
add hl, de
|
add hl, de
|
ld b, 6(ix)
|
ld b, 6(ix)
|
ld c, #_cksum_accum
|
ld c, #_cksum_accum
|
ld a, #0
|
ld a, #0
|
|
|
cksum_dn_sn_loop:
|
cksum_dn_sn_loop:
|
outd
|
outd
|
cp b
|
cp b
|
jp nz, cksum_dn_sn_loop
|
jp nz, cksum_dn_sn_loop
|
|
|
in a, (_cksum_value)
|
in a, (_cksum_value)
|
ld l, a
|
ld l, a
|
_endasm;
|
_endasm;
|
}
|
}
|
|
|
char cksum_asm (char *buf, char len) {
|
char cksum_asm (char *buf, char len) {
|
_asm
|
_asm
|
ld l, 4(ix)
|
ld l, 4(ix)
|
ld h, 5(ix)
|
ld h, 5(ix)
|
ld b, 6(ix)
|
ld b, 6(ix)
|
ld c, #0
|
ld c, #0
|
cksum_asm_loop:
|
cksum_asm_loop:
|
ld a, c
|
ld a, c
|
add a, (hl)
|
add a, (hl)
|
ld c, a
|
ld c, a
|
inc hl
|
inc hl
|
djnz cksum_asm_loop
|
djnz cksum_asm_loop
|
ld l, c
|
ld l, c
|
_endasm;
|
_endasm;
|
}
|
}
|
|
|
char cksum_sw (char *buf, char len) {
|
char cksum_sw (char *buf, char len) {
|
char rv, i;
|
char rv, i;
|
|
|
rv = 0;
|
rv = 0;
|
for (i=0; i<len; i++) {
|
for (i=0; i<len; i++) {
|
rv += buf[i];
|
rv += buf[i];
|
}
|
}
|
|
|
return rv;
|
return rv;
|
}
|
}
|
|
|
int main ()
|
int main ()
|
{
|
{
|
char i, cs_a, cs_b;
|
char i, cs_a, cs_b;
|
|
|
max_timeout_high = 0xff;
|
max_timeout_high = 0xff;
|
|
|
for (i=0; i<BUF_SIZE; i=i+1) {
|
for (i=0; i<BUF_SIZE; i=i+1) {
|
buf[i] = i+1;
|
buf[i] = i+1;
|
}
|
}
|
|
|
print ("Checking OTIR\n");
|
print ("Checking OTIR\n");
|
cs_a = cksum_asm (buf, BUF_SIZE);
|
cs_a = cksum_asm (buf, BUF_SIZE);
|
cs_b = cksum_up (buf, BUF_SIZE);
|
cs_b = cksum_up (buf, BUF_SIZE);
|
|
|
if (cs_a != cs_b)
|
if (cs_a != cs_b)
|
sim_ctl (SC_TEST_FAILED);
|
sim_ctl (SC_TEST_FAILED);
|
|
|
print ("Checking OTDR\n");
|
print ("Checking OTDR\n");
|
cs_b = cksum_dn (buf, BUF_SIZE);
|
cs_b = cksum_dn (buf, BUF_SIZE);
|
|
|
if (cs_a != cs_b)
|
if (cs_a != cs_b)
|
sim_ctl (SC_TEST_FAILED);
|
sim_ctl (SC_TEST_FAILED);
|
|
|
print ("Checking OUTI\n");
|
print ("Checking OUTI\n");
|
|
|
cs_b = cksum_up_sn (buf, BUF_SIZE);
|
cs_b = cksum_up_sn (buf, BUF_SIZE);
|
if (cs_a != cs_b)
|
if (cs_a != cs_b)
|
sim_ctl (SC_TEST_FAILED);
|
sim_ctl (SC_TEST_FAILED);
|
|
|
print ("Checking OUTD\n");
|
print ("Checking OUTD\n");
|
|
|
cs_b = cksum_dn_sn (buf, BUF_SIZE);
|
cs_b = cksum_dn_sn (buf, BUF_SIZE);
|
if (cs_a == cs_b)
|
if (cs_a == cs_b)
|
sim_ctl (SC_TEST_PASSED);
|
sim_ctl (SC_TEST_PASSED);
|
else
|
else
|
sim_ctl (SC_TEST_FAILED);
|
sim_ctl (SC_TEST_FAILED);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|