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

Subversion Repositories tv80

[/] [tv80/] [trunk/] [tests/] [blk_out_inst.c] - Blame information for rev 111

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 111 ghutchis
char cksum_sw (char *buf, int len) {
110
  char rv; int i;
111 39 ghutchis
 
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 111 ghutchis
  unsigned char cs_a, cs_b;
123
  int  i;
124 39 ghutchis
 
125
  max_timeout_high = 0xff;
126
 
127 111 ghutchis
  for (i=0; i<BUF_SIZE; i++) {
128 39 ghutchis
    buf[i] = i+1;
129 111 ghutchis
    //timeout_port = 3;
130 39 ghutchis
  }
131
 
132
  print ("Checking OTIR\n");
133 111 ghutchis
  cs_a = cksum_sw (buf, BUF_SIZE);
134
  cs_b = cksum_up (buf, BUF_SIZE);
135 39 ghutchis
 
136
  if (cs_a != cs_b)
137
    sim_ctl (SC_TEST_FAILED);
138
 
139
  print ("Checking OTDR\n");
140
  cs_b = cksum_dn  (buf, BUF_SIZE);
141
 
142
  if (cs_a != cs_b)
143
    sim_ctl (SC_TEST_FAILED);
144
 
145
  print ("Checking OUTI\n");
146
 
147
  cs_b = cksum_up_sn (buf, BUF_SIZE);
148
  if (cs_a != cs_b)
149
    sim_ctl (SC_TEST_FAILED);
150
 
151
  print ("Checking OUTD\n");
152
 
153
  cs_b = cksum_dn_sn (buf, BUF_SIZE);
154
  if (cs_a == cs_b)
155
    sim_ctl (SC_TEST_PASSED);
156
  else
157
    sim_ctl (SC_TEST_FAILED);
158
 
159
  return 0;
160
}

powered by: WebSVN 2.1.0

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