gbasm: add test for "ld r8, r8"
This commit is contained in:
89
src/gbasm/tests/ld.c
Normal file
89
src/gbasm/tests/ld.c
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
#include "gbasm/tests/test.h"
|
||||||
|
#include "common/common.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void init_r8(void);
|
||||||
|
|
||||||
|
static char ld_r8_src[1024] = { 0 };
|
||||||
|
|
||||||
|
static uint8_t ld_r8_output[0x40];
|
||||||
|
|
||||||
|
struct gbasm_test r8 = {
|
||||||
|
.init = init_r8,
|
||||||
|
.name = "r8",
|
||||||
|
.asm_source = ld_r8_src,
|
||||||
|
.expected_output = ld_r8_output,
|
||||||
|
.expected_output_len = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct gbasm_test *tests[] = {
|
||||||
|
&r8,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gbasm_tests gbasm_ld_tests = {
|
||||||
|
.name = "ld",
|
||||||
|
.num_tests = ARRAY_SIZE(tests),
|
||||||
|
.tests = tests,
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *operands[] = {
|
||||||
|
"B",
|
||||||
|
"C",
|
||||||
|
"D",
|
||||||
|
"E",
|
||||||
|
"H",
|
||||||
|
"L",
|
||||||
|
"(HL)",
|
||||||
|
"A",
|
||||||
|
};
|
||||||
|
|
||||||
|
void gen_r8_src(void)
|
||||||
|
{
|
||||||
|
const char *src, *dst;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < ARRAY_SIZE(operands); i++) {
|
||||||
|
src = operands[i];
|
||||||
|
for (int j = 0; j < ARRAY_SIZE(operands); j++) {
|
||||||
|
dst = operands[j];
|
||||||
|
|
||||||
|
/* Special case, HALT instruction goes where
|
||||||
|
* "ld (HL), (HL)" would be
|
||||||
|
*/
|
||||||
|
if (strcmp(src, "(HL)") == 0 && strcmp(dst, "(HL)") == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
len += sprintf(ld_r8_src + len, "ld %s %s\n", src, dst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(ld_r8_src + len, "halt");
|
||||||
|
|
||||||
|
DEBUG_LOG("%s", ld_r8_src);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gen_r8_output(void)
|
||||||
|
{
|
||||||
|
int num_insts = ARRAY_SIZE(operands) * ARRAY_SIZE(operands);
|
||||||
|
int halt_code = 0x76;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (int opcode = 0x40; opcode < 0x80; opcode++) {
|
||||||
|
if (opcode == halt_code) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ld_r8_output[i++] = opcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
ld_r8_output[i] = halt_code;
|
||||||
|
r8.expected_output_len = num_insts;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_r8(void)
|
||||||
|
{
|
||||||
|
gen_r8_src();
|
||||||
|
gen_r8_output();
|
||||||
|
}
|
||||||
9
src/gbasm/tests/ld.h
Normal file
9
src/gbasm/tests/ld.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef GBASM_TEST_LD_H
|
||||||
|
#define GBASM_TEST_LD_H
|
||||||
|
|
||||||
|
#include "gbasm/tests/test.h"
|
||||||
|
#include "common/common.h"
|
||||||
|
|
||||||
|
extern const struct gbasm_tests gbasm_ld_tests;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "gbasm/tests/test.h"
|
#include "gbasm/tests/test.h"
|
||||||
#include "gbasm/tests/inc.h"
|
#include "gbasm/tests/inc.h"
|
||||||
#include "gbasm/tests/fixed.h"
|
#include "gbasm/tests/fixed.h"
|
||||||
|
#include "gbasm/tests/ld.h"
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
|
|
||||||
#include <string.h> /* memset */
|
#include <string.h> /* memset */
|
||||||
@@ -11,6 +12,7 @@
|
|||||||
const static struct gbasm_tests *tests[] = {
|
const static struct gbasm_tests *tests[] = {
|
||||||
&gbasm_fixed_tests,
|
&gbasm_fixed_tests,
|
||||||
&gbasm_inc_tests,
|
&gbasm_inc_tests,
|
||||||
|
&gbasm_ld_tests,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cmp_mem(const uint8_t *test_data, const uint8_t *expected_data, size_t len)
|
static int cmp_mem(const uint8_t *test_data, const uint8_t *expected_data, size_t len)
|
||||||
|
|||||||
Reference in New Issue
Block a user