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

Subversion Repositories tv80

[/] [tv80/] [branches/] [restruc2/] [tests/] [blk_mem_inst.c] - Blame information for rev 40

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

Line No. Rev Author Line
1 40 ghutchis
/*
2
 * This test covers the four block move instructions LDI,
3
 * LDIR, LDD, and LDDR.
4
 *
5
 * The test creates a buffer full of random data, copies
6
 * the buffer using one of the move instructions, then
7
 * checks the target buffer to make sure it contains the
8
 * same data as the source buffer.
9
 */
10
 
11
#include "tv80_env.h"
12
 
13
#define BUF_SIZE 128
14
 
15
char bufa[BUF_SIZE];
16
char bufb[BUF_SIZE];
17
 
18
void rand_buf (char *buf) {
19
  int i;
20
 
21
  for (i=0; i<BUF_SIZE; i++) {
22
    buf[i] = randval;
23
  }
24
}
25
 
26
char test_ldi () {
27
  int  i;
28
  char rv;
29
 
30
  rand_buf (bufa);
31
 
32
  _asm
33
    ld  de, #_bufb
34
    ld  hl, #_bufa
35
    ld  bc, #128
36
 
37
test_ldi_loop:
38
    ldi
39
    ld  a, #0x00
40
    cp  c
41
    jp  z, test_ldi_loop_exit
42
    cp  b
43
    jp  nz, test_ldi_loop
44
 
45
    test_ldi_loop_exit:
46
  _endasm;
47
 
48
  rv = 1;
49
  for (i=0; i<BUF_SIZE; i++) {
50
    if (bufa[i] != bufb[i]) rv = 0;
51
  }
52
 
53
  return rv;
54
}
55
 
56
char test_ldir () {
57
  int  i;
58
  char rv;
59
 
60
  rand_buf (bufa);
61
 
62
  _asm
63
    ld  de, #_bufb
64
    ld  hl, #_bufa
65
    ld  bc, #128
66
    dec bc
67
 
68
    ldir
69
 
70
  _endasm;
71
 
72
  rv = 1;
73
  for (i=0; i<BUF_SIZE; i++) {
74
    if (bufa[i] != bufb[i]) rv = 0;
75
  }
76
 
77
  return rv;
78
}
79
 
80
char test_ldd () {
81
  int  i;
82
  char rv;
83
 
84
  rand_buf (bufa);
85
 
86
  _asm
87
    ld  hl, #_bufb
88
    ld  bc, #127
89
    add hl, bc
90
    ex  de, hl
91
    ld  hl, #_bufa
92
    add hl, bc
93
    inc bc
94
 
95
test_ldd_loop:
96
    ldd
97
    ld  a, #0x00
98
    cp  c
99
    jp  z, test_ldd_loop_exit
100
    cp  b
101
    jp  nz, test_ldd_loop
102
 
103
    test_ldd_loop_exit:
104
  _endasm;
105
 
106
  rv = 1;
107
  for (i=0; i<BUF_SIZE; i++) {
108
    if (bufa[i] != bufb[i]) rv = 0;
109
  }
110
 
111
  return rv;
112
}
113
 
114
char test_lddr () {
115
  int  i;
116
  char rv;
117
 
118
  rand_buf (bufa);
119
 
120
  _asm
121
    ld  hl, #_bufb
122
    ld  bc, #127
123
    add hl, bc
124
    ex  de, hl
125
    ld  hl, #_bufa
126
    add hl, bc
127
 
128
    lddr
129
 
130
  _endasm;
131
 
132
  rv = 1;
133
  for (i=0; i<BUF_SIZE; i++) {
134
    if (bufa[i] != bufb[i]) rv = 0;
135
  }
136
 
137
  return rv;
138
}
139
 
140
int main ()
141
{
142
  max_timeout_high = 0xff;
143
 
144
  // initialize source buffer
145
  print ("Checking LDI\n");
146
  if (!test_ldi())
147
    sim_ctl (SC_TEST_FAILED);
148
 
149
  print ("Checking LDIR\n");
150
  if (!test_ldir())
151
    sim_ctl (SC_TEST_FAILED);
152
 
153
  print ("Checking LDD\n");
154
  if (!test_ldd())
155
    sim_ctl (SC_TEST_FAILED);
156
 
157
  print ("Checking LDDR\n");
158
  if (!test_lddr())
159
    sim_ctl (SC_TEST_FAILED);
160
  else
161
    sim_ctl (SC_TEST_PASSED);
162
 
163
  return 0;
164
}

powered by: WebSVN 2.1.0

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