LD, LDH, WRAM, and HRAM
This commit is contained in:
@ -1,17 +1,9 @@
|
||||
#include <cpu.h>
|
||||
#include <emu.h>
|
||||
#include <bus.h>
|
||||
|
||||
//process CPU instructions...
|
||||
|
||||
static void proc_none(cpu_context *ctx) {
|
||||
printf("INVALID INSTRUCTION!\n");
|
||||
exit(-7);
|
||||
}
|
||||
|
||||
static void proc_nop(cpu_context *ctx) {
|
||||
|
||||
}
|
||||
|
||||
void cpu_set_flags(cpu_context *ctx, u8 z, u8 n, u8 h, u8 c){
|
||||
if (z != -1){
|
||||
BIT_SET(ctx->regs.f, 7, z)
|
||||
@ -27,6 +19,24 @@ void cpu_set_flags(cpu_context *ctx, u8 z, u8 n, u8 h, u8 c){
|
||||
}
|
||||
}
|
||||
|
||||
static void proc_none(cpu_context *ctx) {
|
||||
printf("INVALID INSTRUCTION!\n");
|
||||
exit(-7);
|
||||
}
|
||||
|
||||
static void proc_nop(cpu_context *ctx) {
|
||||
|
||||
}
|
||||
|
||||
static void proc_ldh(cpu_context *ctx) {
|
||||
if (!ctx->dest_is_mem) {
|
||||
cpu_set_reg(ctx->cur_inst->reg_1, bus_read(0XFF00 | ctx->fetched_data));
|
||||
} else {
|
||||
bus_write(0xFF00 | ctx->mem_dest, ctx->cur_inst->reg_2);
|
||||
}
|
||||
emu_cycles(1);
|
||||
}
|
||||
|
||||
static void proc_xor(cpu_context *ctx) {
|
||||
ctx->regs.a ^= ctx->fetched_data & 0XFF;
|
||||
cpu_set_flags(ctx, ctx->regs.a == 0, 0, 0, 0);
|
||||
@ -37,7 +47,25 @@ static void proc_di(cpu_context *ctx) {
|
||||
}
|
||||
|
||||
static void proc_ld(cpu_context *ctx) {
|
||||
//TODO
|
||||
if(ctx->dest_is_mem) {
|
||||
if(ctx->cur_inst->reg_2 >= RT_AF) {
|
||||
bus_write16(ctx->mem_dest, ctx->fetched_data);
|
||||
emu_cycles(1);
|
||||
} else {
|
||||
bus_write(ctx->mem_dest, ctx->fetched_data);
|
||||
emu_cycles(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->cur_inst->mode == AM_HL_SPR) {
|
||||
u8 hflag = (cpu_read_reg(ctx->cur_inst->reg_2) & 0xF) + (ctx->fetched_data & 0xF) >= 0x10;
|
||||
u8 cflag = (cpu_read_reg(ctx->cur_inst->reg_2) & 0xFF) + (ctx->fetched_data & 0xFF) >= 0x100;
|
||||
cpu_set_flags(ctx, 0, 0, hflag, cflag);
|
||||
cpu_set_reg(ctx->cur_inst->reg_1, cpu_read_reg(ctx->cur_inst->reg_2) + (char)ctx->fetched_data);
|
||||
}
|
||||
|
||||
cpu_set_reg(ctx->cur_inst->reg_1, ctx->fetched_data);
|
||||
}
|
||||
|
||||
static bool check_condition(cpu_context *ctx) {
|
||||
@ -68,7 +96,8 @@ IN_PROC processors[] = {
|
||||
[IN_LD] = proc_ld,
|
||||
[IN_JP] = proc_jp,
|
||||
[IN_DI] = proc_di,
|
||||
[IN_XOR] = proc_xor
|
||||
[IN_XOR] = proc_xor,
|
||||
[IN_LDH] = proc_ldh
|
||||
};
|
||||
|
||||
IN_PROC inst_get_processor(in_type type) {
|
||||
|
Reference in New Issue
Block a user