OpenCores
URL https://opencores.org/ocsvn/tv80/tv80/trunk

Subversion Repositories tv80

[/] [tv80/] [branches/] [restruc2/] [tests/] [blk_out_inst.c] - Blame information for rev 109

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 ghutchis
/*
2
 * This test covers the four block OUT instructions OUTI, OUTD,
3
 * OTIR, and OTDR.  The test works by first creating a buffer
4
 * of data, then doing a block-out instruction from the buffer
5
 * to a special checksum output port.
6
 *
7
 * The test self-checks by performing a checksum of the buffer
8
 * and comparing it with the result read out of the checksum
9
 * port.
10
 */
11
 
12
#include "tv80_env.h"
13
 
14
#define BUF_SIZE 128
15
 
16
char buf[BUF_SIZE];
17
 
18
char cksum_up (char *buf, char len) {
19
  // pointer should be in 4(ix) and 5(ix), length in 6(ix)
20
  cksum_value = 0;
21
  _asm
22
    ld   l, 4(ix)
23
    ld   h, 5(ix)
24
    ld   b, 6(ix)
25
    ld   c, #_cksum_accum
26
    otir
27
    in   a, (_cksum_value)
28
    ld   l, a
29
  _endasm;
30
}
31
 
32
char cksum_dn (char *buf, char len) {
33
  // pointer should be in 4(ix) and 5(ix), length in 6(ix)
34
  cksum_value = 0;
35
  //buf += BUF_SIZE-1;
36
  _asm
37
    ld   de, #127
38
    ld   l, 4(ix)
39
    ld   h, 5(ix)
40
    add  hl, de
41
    ld   b, 6(ix)
42
    ld   c, #_cksum_accum
43
    otdr
44
    in   a, (_cksum_value)
45
    ld   l, a
46
  _endasm;
47
}
48
 
49
char cksum_up_sn (char *buf, char len) {
50
  // pointer should be in 4(ix) and 5(ix), length in 6(ix)
51
  cksum_value = 0;
52
 
53
  _asm
54
    ld   l, 4(ix)
55
    ld   h, 5(ix)
56
    ld   b, 6(ix)
57
    ld   c, #_cksum_accum
58
    ld   a, #0
59
 
60
cksum_up_sn_loop:
61
    outi
62
    cp   b
63
    jp   nz, cksum_up_sn_loop
64
 
65
    in   a, (_cksum_value)
66
    ld   l, a
67
  _endasm;
68
}
69
 
70
char cksum_dn_sn (char *buf, char len) {
71
  // pointer should be in 4(ix) and 5(ix), length in 6(ix)
72
  cksum_value = 0;
73
 
74
  _asm
75
    ld   de, #127
76
    ld   l, 4(ix)
77
    ld   h, 5(ix)
78
    add  hl, de
79
    ld   b, 6(ix)
80
    ld   c, #_cksum_accum
81
    ld   a, #0
82
 
83
cksum_dn_sn_loop:
84
    outd
85
    cp   b
86
    jp   nz, cksum_dn_sn_loop
87
 
88
    in   a, (_cksum_value)
89
    ld   l, a
90
  _endasm;
91
}
92
 
93
char cksum_asm (char *buf, char len) {
94
  _asm
95
    ld   l, 4(ix)
96
    ld   h, 5(ix)
97
    ld   b, 6(ix)
98
    ld   c, #0
99
    cksum_asm_loop:
100
    ld   a, c
101
    add  a, (hl)
102
    ld   c, a
103
    inc  hl
104
    djnz cksum_asm_loop
105
    ld   l, c
106
  _endasm;
107
}
108
 
109
char cksum_sw (char *buf, char len) {
110
  char rv, i;
111
 
112
  rv = 0;
113
  for (i=0; i<len; i++) {
114
    rv += buf[i];
115
  }
116
 
117
  return rv;
118
}
119
 
120
int main ()
121
{
122
  char i, cs_a, cs_b;
123
 
124
  max_timeout_high = 0xff;
125
 
126
  for (i=0; i<BUF_SIZE; i=i+1) {
127
    buf[i] = i+1;
128
  }
129
 
130
  print ("Checking OTIR\n");
131
  cs_a = cksum_asm (buf, BUF_SIZE);
132
  cs_b = cksum_up  (buf, BUF_SIZE);
133
 
134
  if (cs_a != cs_b)
135
    sim_ctl (SC_TEST_FAILED);
136
 
137
  print ("Checking OTDR\n");
138
  cs_b = cksum_dn  (buf, BUF_SIZE);
139
 
140
  if (cs_a != cs_b)
141
    sim_ctl (SC_TEST_FAILED);
142
 
143
  print ("Checking OUTI\n");
144
 
145
  cs_b = cksum_up_sn (buf, BUF_SIZE);
146
  if (cs_a != cs_b)
147
    sim_ctl (SC_TEST_FAILED);
148
 
149
  print ("Checking OUTD\n");
150
 
151
  cs_b = cksum_dn_sn (buf, BUF_SIZE);
152
  if (cs_a == cs_b)
153
    sim_ctl (SC_TEST_PASSED);
154
  else
155
    sim_ctl (SC_TEST_FAILED);
156
 
157
  return 0;
158
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.