CPU testing

This commit is contained in:
2025-01-31 17:07:09 -07:00
parent 9a6dc67c3e
commit 5206c3871e
11 changed files with 212 additions and 14 deletions

View File

@ -242,12 +242,12 @@ instruction instructions[0x100] = {
[0xE1] = {IN_POP, AM_IMP, RT_HL},
[0xE2] = {IN_LD, AM_MR_R, RT_C, RT_A},
[0xE5] = {IN_PUSH, AM_IMP, RT_HL},
[0xE6] = {IN_AND, AM_D8},
[0xE6] = {IN_AND, AM_R_D8, RT_A},
[0xE7] = {IN_RST, AM_IMP, RT_NONE, RT_NONE, CT_NONE, 0x20},
[0xE8] = {IN_ADD, AM_R_D8, RT_SP},
[0xE9] = {IN_JP, AM_MR, RT_HL},
[0xE9] = {IN_JP, AM_R, RT_HL},
[0xEA] = {IN_LD, AM_A16_R, RT_NONE, RT_A},
[0xEE] = {IN_XOR, AM_D8},
[0xEE] = {IN_XOR, AM_R_D8, RT_A},
[0xEF] = {IN_RST, AM_IMP, RT_NONE, RT_NONE, CT_NONE, 0x28},
//0xFX
[0xF0] = {IN_LDH, AM_R_A8, RT_A},
@ -255,13 +255,13 @@ instruction instructions[0x100] = {
[0xF2] = {IN_LD, AM_R_MR, RT_A, RT_C},
[0xF3] = {IN_DI},
[0xF5] = {IN_PUSH, AM_IMP, RT_AF},
[0xF6] = {IN_OR, AM_D8},
[0xF6] = {IN_OR, AM_R_D8, RT_A},
[0xF7] = {IN_RST, AM_IMP, RT_NONE, RT_NONE, CT_NONE, 0x30},
[0xF8] = {IN_LD, AM_HL_SPR, RT_HL, RT_SP},
[0xF9] = {IN_LD, AM_R_R, RT_HL, RT_SP},
[0xFA] = {IN_LD, AM_R_A16, RT_A},
[0xFB] = {IN_EI},
[0xFE] = {IN_CP, AM_D8},
[0xFE] = {IN_CP, AM_R_D8, RT_A},
[0xFF] = {IN_RST, AM_IMP, RT_NONE, RT_NONE, CT_NONE, 0x38}
};
@ -322,4 +322,124 @@ char *inst_lookup[] = {
char *inst_name(in_type t) {
return inst_lookup[t];
}
static char *rt_lookup[] = {
"<NONE>",
"A",
"F",
"B",
"C",
"D",
"E",
"H",
"L",
"AF",
"BC",
"DE",
"HL",
"SP",
"PC"
};
void inst_to_str(cpu_context *ctx, char *str) {
instruction *inst = ctx->cur_inst;
sprintf(str, "%s ", inst_name(inst->type));
switch(inst->mode) {
case AM_IMP:
return;
case AM_R_D16:
case AM_R_A16:
sprintf(str, "%s %s,$%04X", inst_name(inst->type),
rt_lookup[inst->reg_1], ctx->fetched_data);
return;
case AM_R:
sprintf(str, "%s %s", inst_name(inst->type),
rt_lookup[inst->reg_1]);
return;
case AM_R_R:
sprintf(str, "%s %s,%s", inst_name(inst->type),
rt_lookup[inst->reg_1], rt_lookup[inst->reg_2]);
return;
case AM_MR_R:
sprintf(str, "%s (%s),%s", inst_name(inst->type),
rt_lookup[inst->reg_1], rt_lookup[inst->reg_2]);
return;
case AM_MR:
sprintf(str, "%s (%s)", inst_name(inst->type),
rt_lookup[inst->reg_1]);
return;
case AM_R_MR:
sprintf(str, "%s %s,(%s)", inst_name(inst->type),
rt_lookup[inst->reg_1], rt_lookup[inst->reg_2]);
return;
case AM_R_D8:
case AM_R_A8:
sprintf(str, "%s %s,$%02X", inst_name(inst->type),
rt_lookup[inst->reg_1], ctx->fetched_data & 0xFF);
return;
case AM_R_HLI:
sprintf(str, "%s %s,(%s+)", inst_name(inst->type),
rt_lookup[inst->reg_1], rt_lookup[inst->reg_2]);
return;
case AM_R_HLD:
sprintf(str, "%s %s,(%s-)", inst_name(inst->type),
rt_lookup[inst->reg_1], rt_lookup[inst->reg_2]);
return;
case AM_HLI_R:
sprintf(str, "%s (%s+),%s", inst_name(inst->type),
rt_lookup[inst->reg_1], rt_lookup[inst->reg_2]);
return;
case AM_HLD_R:
sprintf(str, "%s (%s-),%s", inst_name(inst->type),
rt_lookup[inst->reg_1], rt_lookup[inst->reg_2]);
return;
case AM_A8_R:
sprintf(str, "%s $%02X,%s", inst_name(inst->type),
bus_read(ctx->regs.pc - 1), rt_lookup[inst->reg_2]);
return;
case AM_HL_SPR:
sprintf(str, "%s (%s),SP+%d", inst_name(inst->type),
rt_lookup[inst->reg_1], ctx->fetched_data & 0xFF);
return;
case AM_D8:
sprintf(str, "%s $%02X", inst_name(inst->type),
ctx->fetched_data & 0xFF);
return;
case AM_D16:
sprintf(str, "%s $%04X", inst_name(inst->type),
ctx->fetched_data);
return;
case AM_MR_D8:
sprintf(str, "%s (%s),$%02X", inst_name(inst->type),
rt_lookup[inst->reg_1], ctx->fetched_data & 0xFF);
return;
case AM_A16_R:
sprintf(str, "%s ($%04X),%s", inst_name(inst->type),
ctx->fetched_data, rt_lookup[inst->reg_2]);
return;
default:
fprintf(stderr, "INVALID AM: %d\n", inst->mode);
NO_IMPL
}
}