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

Subversion Repositories tv80

[/] [tv80/] [branches/] [restruc1/] [tests/] [blk_mem_inst.c] - Diff between revs 46 and 84

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 46 Rev 84
/*
/*
 * This test covers the four block move instructions LDI,
 * This test covers the four block move instructions LDI,
 * LDIR, LDD, and LDDR.
 * LDIR, LDD, and LDDR.
 *
 *
 * The test creates a buffer full of random data, copies
 * The test creates a buffer full of random data, copies
 * the buffer using one of the move instructions, then
 * the buffer using one of the move instructions, then
 * checks the target buffer to make sure it contains the
 * checks the target buffer to make sure it contains the
 * same data as the source buffer.
 * same data as the source buffer.
 */
 */
 
 
#include "tv80_env.h"
#include "tv80_env.h"
 
 
#define BUF_SIZE 128
#define BUF_SIZE 128
 
 
char bufa[BUF_SIZE];
char bufa[BUF_SIZE];
char bufb[BUF_SIZE];
char bufb[BUF_SIZE];
 
 
void rand_buf (char *buf) {
void rand_buf (char *buf) {
  int i;
  int i;
 
 
  for (i=0; i<BUF_SIZE; i++) {
  for (i=0; i<BUF_SIZE; i++) {
    buf[i] = randval;
    buf[i] = randval;
  }
  }
}
}
 
 
char test_ldi () {
char test_ldi () {
  int  i;
  int  i;
  char rv;
  char rv;
 
 
  rand_buf (bufa);
  rand_buf (bufa);
 
 
  _asm
  _asm
    ld  de, #_bufb
    ld  de, #_bufb
    ld  hl, #_bufa
    ld  hl, #_bufa
    ld  bc, #128
    ld  bc, #128
 
 
test_ldi_loop:
test_ldi_loop:
    ldi
    ldi
    ld  a, #0x00
    ld  a, #0x00
    cp  c
    cp  c
    jp  nz, test_ldi_loop
    jp  nz, test_ldi_loop
    cp  b
    cp  b
    jp  nz, test_ldi_loop
    jp  nz, test_ldi_loop
 
 
  _endasm;
  _endasm;
 
 
  rv = 1;
  rv = 1;
  for (i=0; i<BUF_SIZE; i++) {
  for (i=0; i<BUF_SIZE; i++) {
    if (bufa[i] != bufb[i]) rv = 0;
    if (bufa[i] != bufb[i]) rv = 0;
  }
  }
 
 
  return rv;
  return rv;
}
}
 
 
char test_ldir () {
char test_ldir () {
  int  i;
  int  i;
  char rv;
  char rv;
 
 
  rand_buf (bufa);
  rand_buf (bufa);
 
 
  _asm
  _asm
    ld  de, #_bufb
    ld  de, #_bufb
    ld  hl, #_bufa
    ld  hl, #_bufa
    ld  bc, #128
    ld  bc, #128
 
 
    ldir
    ldir
 
 
  _endasm;
  _endasm;
 
 
  rv = 1;
  rv = 1;
  for (i=0; i<BUF_SIZE; i++) {
  for (i=0; i<BUF_SIZE; i++) {
    if (bufa[i] != bufb[i]) rv = 0;
    if (bufa[i] != bufb[i]) rv = 0;
  }
  }
 
 
  return rv;
  return rv;
}
}
 
 
char test_ldd () {
char test_ldd () {
  int  i;
  int  i;
  char rv;
  char rv;
 
 
  rand_buf (bufa);
  rand_buf (bufa);
 
 
  _asm
  _asm
    ld  hl, #_bufb
    ld  hl, #_bufb
    ld  bc, #127
    ld  bc, #127
    add hl, bc
    add hl, bc
    ex  de, hl
    ex  de, hl
    ld  hl, #_bufa
    ld  hl, #_bufa
    add hl, bc
    add hl, bc
    inc bc
    inc bc
 
 
test_ldd_loop:
test_ldd_loop:
    ldd
    ldd
    ld  a, #0x00
    ld  a, #0x00
    cp  c
    cp  c
    jp  nz, test_ldd_loop
    jp  nz, test_ldd_loop
    cp  b
    cp  b
    jp  nz, test_ldd_loop
    jp  nz, test_ldd_loop
 
 
  _endasm;
  _endasm;
 
 
  rv = 1;
  rv = 1;
  for (i=0; i<BUF_SIZE; i++) {
  for (i=0; i<BUF_SIZE; i++) {
    if (bufa[i] != bufb[i]) rv = 0;
    if (bufa[i] != bufb[i]) rv = 0;
  }
  }
 
 
  return rv;
  return rv;
}
}
 
 
char test_lddr () {
char test_lddr () {
  int  i;
  int  i;
  char rv;
  char rv;
 
 
  rand_buf (bufa);
  rand_buf (bufa);
 
 
  _asm
  _asm
    ld  hl, #_bufb
    ld  hl, #_bufb
    ld  bc, #127
    ld  bc, #127
    add hl, bc
    add hl, bc
    ex  de, hl
    ex  de, hl
    ld  hl, #_bufa
    ld  hl, #_bufa
    add hl, bc
    add hl, bc
    inc bc
    inc bc
 
 
    lddr
    lddr
 
 
  _endasm;
  _endasm;
 
 
  rv = 1;
  rv = 1;
  for (i=0; i<BUF_SIZE; i++) {
  for (i=0; i<BUF_SIZE; i++) {
    if (bufa[i] != bufb[i]) rv = 0;
    if (bufa[i] != bufb[i]) rv = 0;
  }
  }
 
 
  return rv;
  return rv;
}
}
 
 
int main ()
int main ()
{
{
  max_timeout_high = 0xff;
  max_timeout_high = 0xff;
 
 
  // initialize source buffer
  // initialize source buffer
  print ("Checking LDI\n");
  print ("Checking LDI\n");
  if (!test_ldi())
  if (!test_ldi())
    sim_ctl (SC_TEST_FAILED);
    sim_ctl (SC_TEST_FAILED);
 
 
  print ("Checking LDIR\n");
  print ("Checking LDIR\n");
  if (!test_ldir())
  if (!test_ldir())
    sim_ctl (SC_TEST_FAILED);
    sim_ctl (SC_TEST_FAILED);
 
 
  print ("Checking LDD\n");
  print ("Checking LDD\n");
  if (!test_ldd())
  if (!test_ldd())
    sim_ctl (SC_TEST_FAILED);
    sim_ctl (SC_TEST_FAILED);
 
 
  print ("Checking LDDR\n");
  print ("Checking LDDR\n");
  if (!test_lddr())
  if (!test_lddr())
    sim_ctl (SC_TEST_FAILED);
    sim_ctl (SC_TEST_FAILED);
  else
  else
    sim_ctl (SC_TEST_PASSED);
    sim_ctl (SC_TEST_PASSED);
 
 
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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