summaryrefslogtreecommitdiff
path: root/ops.yaml
diff options
context:
space:
mode:
Diffstat (limited to 'ops.yaml')
-rw-r--r--ops.yaml61
1 files changed, 25 insertions, 36 deletions
diff --git a/ops.yaml b/ops.yaml
index 4d82cce..1a14607 100644
--- a/ops.yaml
+++ b/ops.yaml
@@ -266,8 +266,7 @@ ops:
h:
c:
code: |
- ctx->cpu.state = STATE_STOP;
- cpu_ww(ctx, RW_PC, old_pc); // FIXME?
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_STOP);
- id: LD DE, d16
hex: 0x11
cat: "16-bit load/store/move"
@@ -1900,7 +1899,7 @@ ops:
h:
c:
code: |
- ctx->cpu.state = STATE_HALT;
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_HALT);
- id: LD (HL), A
hex: 0x77
cat: "8-bit load/store/move"
@@ -3402,7 +3401,7 @@ ops:
cat: "invalid"
op: XX
code: |
- invalid(ctx, old_pc);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_INVALID);
- id: CALL NC, a16
hex: 0xD4
cat: "jumps/calls"
@@ -3543,7 +3542,7 @@ ops:
cat: "invalid"
op: XX
code: |
- invalid(ctx, old_pc);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_INVALID);
- id: CALL C, a16
hex: 0xDC
cat: "jumps/calls"
@@ -3586,7 +3585,7 @@ ops:
h: H
c: C
code: |
- invalid(ctx, old_pc);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_INVALID);
- id: RST 18H
hex: 0xDF
cat: "jumps/calls"
@@ -3661,7 +3660,7 @@ ops:
cat: "invalid"
op: XX
code: |
- invalid(ctx, old_pc);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_INVALID);
- id: PUSH HL
hex: 0xE5
cat: "16-bit load/store/move"
@@ -3759,7 +3758,7 @@ ops:
cat: "invalid"
op: XX
code: |
- invalid(ctx, old_pc);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_INVALID);
- id: XX
hex: 0xEC
cat: "invalid"
@@ -3769,7 +3768,7 @@ ops:
cat: "invalid"
op: XX
code: |
- invalid(ctx, old_pc);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_INVALID);
- id: XOR d8
hex: 0xEE
cat: "8-bit math"
@@ -3869,7 +3868,7 @@ ops:
cat: "invalid"
op: XX
code: |
- invalid(ctx, old_pc);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_INVALID);
- id: PUSH AF
hex: 0xF5
cat: "16-bit load/store/move"
@@ -3985,13 +3984,13 @@ ops:
cat: "invalid"
op: XX
code: |
- invalid(ctx, old_pc);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_INVALID);
- id: XX
hex: 0xFD
cat: "invalid"
op: XX
code: |
- invalid(ctx, old_pc);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_INVALID);
- id: CP d8
hex: 0xFE
cat: "8-bit math"
@@ -9142,23 +9141,13 @@ templates:
}
static void
- invalid(
- gb_t * const ctx,
- const uint16_t pc
- ) {
- ctx->cpu.state = STATE_INVALID;
- cpu_ww(ctx, RW_PC, pc); // FIXME?
- }
-
- static void
- not_implemented(
+ cpu_set_state(
gb_t * const ctx,
const uint16_t pc,
- const uint16_t op
+ const gb_cpu_state_t state
) {
- UNUSED(op);
- ctx->cpu.state = STATE_NOT_IMPLEMENTED;
- cpu_ww(ctx, RW_PC, pc); // FIXME?
+ ctx->cpu.state = state;
+ UNUSED(pc);
}
static void
@@ -10219,7 +10208,7 @@ templates:
cpu_step(
gb_t * const ctx
) {
- if (ctx->cpu.state == STATE_RUN) {
+ if (ctx->cpu.state == GB_CPU_STATE_RUN) {
// get pc, and current op
const uint16_t old_pc = cpu_rw(ctx, RW_PC),
op = mmu_rb(ctx, old_pc);
@@ -10232,12 +10221,12 @@ templates:
switch (mmu_rb(ctx, old_pc + 1)) {
<%= switches['cb'] %>
default:
- not_implemented(ctx, old_pc, op);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_NOT_IMPLEMENTED);
}
break;
default:
- not_implemented(ctx, old_pc, op);
+ cpu_set_state(ctx, old_pc, GB_CPU_STATE_NOT_IMPLEMENTED);
}
// increment cpu clock
@@ -10245,7 +10234,7 @@ templates:
// return clock
return clock;
- } else if (ctx->cpu.state == STATE_HALT || ctx->cpu.state == STATE_STOP) {
+ } else if (ctx->cpu.state == GB_CPU_STATE_HALT || ctx->cpu.state == GB_CPU_STATE_STOP) {
// return 4 clock step
return 4;
} else {
@@ -10258,7 +10247,7 @@ templates:
cpu_handle_interrupts(
gb_t * const ctx
) {
- if (ctx->cpu.state == STATE_RUN) {
+ if (ctx->cpu.state == GB_CPU_STATE_RUN) {
if (ctx->cpu.ime) {
// get interrupt vector (masked against enabled interrupts)
const uint8_t iv = mmu_rb(ctx, PORT_IE) & mmu_rb(ctx, PORT_IF);
@@ -10286,7 +10275,7 @@ templates:
}
}
}
- } else if (ctx->cpu.state == STATE_HALT) {
+ } else if (ctx->cpu.state == GB_CPU_STATE_HALT) {
// get interrupt vector (masked against enabled interrupts)
const uint8_t iv = mmu_rb(ctx, PORT_IE) & mmu_rb(ctx, PORT_IF);
bool done = false;
@@ -10302,7 +10291,7 @@ templates:
// (TCAGBD.pdf, 4.9)
// wake cpu
- ctx->cpu.state = STATE_RUN;
+ cpu_set_state(ctx, 0, GB_CPU_STATE_RUN);
// FIXME: according to url below, this should take 5 cycles
// (src: http://gbdev.gg8.se/wiki/articles/Interrupts)
@@ -10322,8 +10311,8 @@ templates:
}
}
}
- } else if (ctx->cpu.state == STATE_STOP) {
- // TODO: handle STATE_STOP
+ } else if (ctx->cpu.state == GB_CPU_STATE_STOP) {
+ // TODO: handle GB_CPU_STATE_STOP
} else {
}
}
@@ -10384,7 +10373,7 @@ templates:
gb_t * const ctx
) {
// set cpu state
- ctx->cpu.state = STATE_RUN;
+ cpu_set_state(ctx, 0, GB_CPU_STATE_RUN);
// init cpu registers
// (src: TCAGBD.pdf, 3.2)