jump and nop instructions.
This commit is contained in:
50
lib/cpu_proc.c
Normal file
50
lib/cpu_proc.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include <cpu.h>
|
||||
#include <emu.h>
|
||||
|
||||
//process CPU instructions...
|
||||
|
||||
static void proc_none(cpu_context *ctx) {
|
||||
printf("INVALID INSTRUCTION!\n");
|
||||
exit(-7);
|
||||
}
|
||||
|
||||
static void proc_nop(cpu_context *ctx) {
|
||||
|
||||
}
|
||||
|
||||
static void proc_ld(cpu_context *ctx) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
static bool check_condition(cpu_context *ctx) {
|
||||
bool z = CPU_FLAG_Z;
|
||||
bool c = CPU_FLAG_C;
|
||||
|
||||
switch(ctx->cur_inst->cond) {
|
||||
case CT_NONE: return true;
|
||||
case CT_C: return c;
|
||||
case CT_NC: return !c;
|
||||
case CT_Z: return z;
|
||||
case CT_NZ: return !z;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void proc_jp(cpu_context *ctx) {
|
||||
if (check_condition(ctx)) {
|
||||
ctx->regs.pc = ctx->fetched_data;
|
||||
emu_cycles(1);
|
||||
}
|
||||
}
|
||||
|
||||
IN_PROC processors[] = {
|
||||
[IN_NONE] = proc_none,
|
||||
[IN_NOP] = proc_nop,
|
||||
[IN_LD] = proc_ld,
|
||||
[IN_JP] = proc_jp,
|
||||
};
|
||||
|
||||
IN_PROC inst_get_processor(in_type type) {
|
||||
return processors[type];
|
||||
}
|
Reference in New Issue
Block a user