summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ops.yaml596
1 files changed, 68 insertions, 528 deletions
diff --git a/ops.yaml b/ops.yaml
index 79ddc77..496e701 100644
--- a/ops.yaml
+++ b/ops.yaml
@@ -1,6 +1,10 @@
---
# src: http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html
# src: http://www.devrs.com/gb/files/opcodes.html
+# TODO: DAA, see
+# http://datasheets.chipdb.org/Zilog/Z80/z80-documented-0.90.pdf
+# http://forums.nesdev.com/viewtopic.php?t=9088
+
ops:
main:
- id: NOP
@@ -488,7 +492,7 @@ ops:
c:
code: |
{
- if (!(cpu_rb(ctx, RB_F) & F_Z)) {
+ if (!FLAG(ctx, Z)) {
// get offset
const int8_t ofs = (int8_t) mmu_rb(ctx, old_pc + 1);
@@ -615,7 +619,7 @@ ops:
c: C
code: |
{
- if (cpu_rb(ctx, RB_F) & F_Z) {
+ if (FLAG(ctx, Z)) {
// get offset
const int8_t ofs = (int8_t) mmu_rb(ctx, old_pc + 1);
@@ -1021,7 +1025,7 @@ ops:
c: C
code: |
cpu_wf(ctx, F_N | F_H | F_C, (
- (cpu_rb(ctx, RB_F) & F_C ? 0 : F_C)
+ (FLAG(ctx, C) ? 0 : F_C)
));
- id: LD B, B
hex: 0x40
@@ -2225,7 +2229,7 @@ ops:
// get old and new value
const uint8_t o = cpu_rb(ctx, RB_A),
n = cpu_rb(ctx, mmu_rb(ctx, cpu_rw(ctx, RW_HL))),
- c = (cpu_rb(ctx, RB_F) & F_C) ? 1 : 0;
+ c = FLAG(ctx, C) ? 1 : 0;
const uint16_t v = o + n + c;
// write value
@@ -2495,7 +2499,7 @@ ops:
// get old and new value
const uint8_t o = cpu_rb(ctx, RB_A),
n = mmu_rb(ctx, cpu_rw(ctx, RW_HL)),
- c = (cpu_rb(ctx, RB_F) & F_C) ? 1 : 0,
+ c = FLAG(ctx, C) ? 1 : 0,
v = o - (n + c);
// write value
@@ -3044,7 +3048,7 @@ ops:
h:
c:
code: |
- if (~cpu_rb(ctx, RB_F) & F_Z) {
+ if (!FLAG(ctx, Z)) {
pop_rw(ctx, RW_PC);
ctx->cpu.clock += 12;
@@ -3081,7 +3085,7 @@ ops:
h:
c:
code: |
- if (~cpu_rb(ctx, RB_F) & F_Z) {
+ if (!FLAG(ctx, Z)) {
// jump
cpu_ww(ctx, RW_PC, mmu_rw(ctx, old_pc + 1));
@@ -3120,7 +3124,7 @@ ops:
h:
c:
code: |
- if (~cpu_rb(ctx, RB_F) & F_Z) {
+ if (!FLAG(ctx, Z)) {
// push pc
push_rw(ctx, RW_PC);
@@ -3205,7 +3209,7 @@ ops:
h:
c:
code: |
- if (cpu_rb(ctx, RB_F) & F_Z) {
+ if (FLAG(ctx, Z)) {
// pop pc
pop_rw(ctx, RW_PC);
@@ -3245,7 +3249,7 @@ ops:
h:
c:
code: |
- if (cpu_rb(ctx, RB_F) & F_Z) {
+ if (FLAG(ctx, Z)) {
// jump
cpu_ww(ctx, RW_PC, mmu_rw(ctx, old_pc + 1));
@@ -3277,7 +3281,7 @@ ops:
h:
c:
code: |
- if (cpu_rb(ctx, RB_F) & F_Z) {
+ if (FLAG(ctx, Z)) {
// push pc
push_rw(ctx, RW_PC);
@@ -3340,7 +3344,7 @@ ops:
t: 20
f: 8
code: |
- if (~cpu_rb(ctx, RB_F) & F_C) {
+ if (!FLAG(ctx, C)) {
// pop pc
pop_rw(ctx, RW_PC);
@@ -3385,7 +3389,7 @@ ops:
h:
c:
code: |
- if (~cpu_rb(ctx, RB_F) & F_C) {
+ if (!FLAG(ctx, C)) {
// jump
cpu_ww(ctx, RW_PC, mmu_rw(ctx, old_pc + 1));
@@ -3442,23 +3446,7 @@ ops:
h: H
c: C
code: |
- {
- // get old and new value
- const uint8_t o = cpu_rb(ctx, RB_A),
- n = mmu_rb(ctx, old_pc + 1),
- v = o - n;
-
- // write value
- cpu_wb(ctx, RB_A, v);
-
- // set flags
- cpu_wf(ctx, F_Z | F_N | F_H | F_C, (
- (v ? 0 : F_Z) |
- F_N |
- ((((o & 0x0F) - (n & 0x0F)) & 0xF0) ? F_H : 0) |
- ((n > o) ? F_C : 0)
- ));
- }
+ sub_d8(ctx, old_pc + 1);
- id: RST 10H
hex: 0xD7
cat: "jumps/calls"
@@ -3488,7 +3476,7 @@ ops:
h:
c:
code: |
- if (cpu_rb(ctx, RB_F) & F_C) {
+ if (FLAG(ctx, C)) {
// pop pc
pop_rw(ctx, RW_PC);
@@ -3531,7 +3519,7 @@ ops:
h:
c:
code: |
- if (cpu_rb(ctx, RB_F) & F_C) {
+ if (FLAG(ctx, C)) {
// jump
cpu_ww(ctx, RW_PC, mmu_rw(ctx, old_pc + 1));
@@ -3561,7 +3549,7 @@ ops:
h:
c:
code: |
- if (cpu_rb(ctx, RB_F) & F_C) {
+ if (FLAG(ctx, C)) {
// push pc
push_rw(ctx, RW_PC);
@@ -4105,21 +4093,7 @@ ops:
h: "0"
c: C
code: |
- {
- // get old value, carry bit, and new value
- const uint16_t addr = cpu_rw(ctx, RW_HL);
- const uint8_t o = mmu_rb(ctx, addr),
- c = (o & 0x80) ? 1 : 0,
- n = ((o & 0x7F) << 1) + c;
- // set value
- mmu_wb(ctx, addr, n);
-
- // set flags
- cpu_wf(ctx, F_Z | F_N | F_H | F_C, (
- (n ? 0 : F_Z) |
- (c ? F_C : 0)
- ));
- }
+ rlc_hl(ctx);
- id: RLC A
hex: 0x07
cat: "8-bit rotations/shifts"
@@ -7791,6 +7765,7 @@ templates:
#define UNUSED(a) ((void) (a))
+ #define FLAG(ctx, f) (cpu_rb(ctx, RB_F) & (F_##f))
#define F_Z (1 << 7)
#define F_N (1 << 6)
#define F_H (1 << 5)
@@ -8091,7 +8066,7 @@ templates:
// get old and new value
const uint8_t o = cpu_rb(ctx, RB_A),
n = cpu_rb(ctx, reg),
- c = (cpu_rb(ctx, RB_F) & F_C) ? 1 : 0;
+ c = FLAG(ctx, C) ? 1 : 0;
const uint16_t v = o + n + c;
// write value
@@ -8128,6 +8103,28 @@ templates:
}
static void
+ sub_d8(
+ gb_t * const ctx,
+ const uint16_t addr
+ ) {
+ // get old and new value
+ const uint8_t o = cpu_rb(ctx, RB_A),
+ n = mmu_rb(ctx, addr),
+ v = o - n;
+
+ // write value
+ cpu_wb(ctx, RB_A, v);
+
+ // set flags
+ cpu_wf(ctx, F_Z | F_N | F_H | F_C, (
+ (v ? 0 : F_Z) |
+ F_N |
+ ((((o & 0x0F) - (n & 0x0F)) & 0xF0) ? F_H : 0) |
+ ((n > o) ? F_C : 0)
+ ));
+ }
+
+ static void
sbc_rb(
gb_t * const ctx,
const rb_t reg
@@ -8135,7 +8132,7 @@ templates:
// get old and new value
const uint8_t o = cpu_rb(ctx, RB_A),
n = cpu_rb(ctx, reg),
- c = (cpu_rb(ctx, RB_F) & F_C) ? 1 : 0,
+ c = FLAG(ctx, C) ? 1 : 0,
v = o - (n + c);
// write value
@@ -8269,6 +8266,25 @@ templates:
}
static void
+ rlc_hl(
+ gb_t * const ctx
+ ) {
+ // get old value, carry bit, and new value
+ const uint16_t addr = cpu_rw(ctx, RW_HL);
+ const uint8_t o = mmu_rb(ctx, addr),
+ c = (o & 0x80) ? 1 : 0,
+ n = ((o & 0x7F) << 1) + c;
+ // set value
+ mmu_wb(ctx, addr, n);
+
+ // set flags
+ cpu_wf(ctx, F_Z | F_N | F_H | F_C, (
+ (n ? 0 : F_Z) |
+ (c ? F_C : 0)
+ ));
+ }
+
+ static void
rrc_rb(
gb_t * const ctx,
const rb_t reg
@@ -8294,7 +8310,7 @@ templates:
) {
// get old value and new value
const uint8_t o = cpu_rb(ctx, reg),
- n = (o << 1) + (cpu_rb(ctx, RB_F) & F_C ? 1 : 0);
+ n = (o << 1) + (FLAG(ctx, C) ? 1 : 0);
// set value
cpu_wb(ctx, reg, n);
@@ -8312,7 +8328,7 @@ templates:
) {
// get old value and new value
const uint8_t o = cpu_rb(ctx, reg),
- n = (cpu_rb(ctx, RB_F) & F_C ? 0x80 : 0) | (o >> 1);
+ n = (FLAG(ctx, C) ? 0x80 : 0) | (o >> 1);
// set value
cpu_wb(ctx, reg, n);
@@ -8411,7 +8427,6 @@ templates:
));
}
-
static void
set_rb(
gb_t * const ctx,
@@ -8485,478 +8500,3 @@ templates:
not_implemented(ctx, old_pc, op);
}
}
-
- sla_r8: |
- let b = ctx.cpu.r.<%= dst.downcase %>,
- c = (b & 0x80),
- v = (b << 1) & 0xFF;
-
- ctx.cpu.r.f = (
- (v ? 0 : 0x80) |
- (c ? 0x10 : 0)
- );
- ctx.cpu.r.<%= dst.downcase %> = v;
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- sla_rp16: |
- let addr = (
- ((ctx.cpu.r.<%= dst.downcase[1] %> & 0xFF) << 8) +
- (ctx.cpu.r.<%= dst.downcase[2] %> & 0xFF)
- ),
- b = ctx.mmu.rb(addr),
- c = (b & 0x80),
- v = (b << 1) & 0xFF;
-
- ctx.cpu.r.f = (
- (v ? 0 : 0x80) |
- (c ? 0x10 : 0)
- );
- ctx.mmu.wb(addr, v);
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- sra_r8: |
- let b = ctx.cpu.r.<%= dst.downcase %>,
- c = (b & 0x01),
- v = ((b & 0x80) | (b >> 1)) & 0xFF;
-
- ctx.cpu.r.f = (
- (v ? 0 : 0x80) |
- (c ? 0x10 : 0)
- );
- ctx.cpu.r.<%= dst.downcase %> = v;
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- sra_rp16: |
- let addr = (
- ((ctx.cpu.r.<%= dst.downcase[1] %> & 0xFF) << 8) +
- (ctx.cpu.r.<%= dst.downcase[2] %> & 0xFF)
- ),
- b = ctx.mmu.rb(addr),
- c = (b & 0x01),
- v = ((b & 0x80) | (b >> 1)) & 0xFF;
-
- ctx.cpu.r.f = (
- (v ? 0 : 0x80) |
- (c ? 0x10 : 0)
- );
- ctx.mmu.wb(addr, v);
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- srl_r8: |
- let b = ctx.cpu.r.<%= dst.downcase %>,
- c = (b & 0x01),
- v = (b >> 1) & 0x7F;
-
- ctx.cpu.r.f = (
- (v ? 0 : 0x80) |
- (c ? 0x10 : 0)
- );
- ctx.cpu.r.<%= dst.downcase %> = v;
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- srl_rp16: |
- let addr = (
- ((ctx.cpu.r.<%= dst.downcase[1] %> & 0xFF) << 8) +
- (ctx.cpu.r.<%= dst.downcase[2] %> & 0xFF)
- ),
- b = ctx.mmu.rb(addr),
- c = (b & 0x01),
- v = (b >> 1) & 0x7F;
-
- ctx.cpu.r.f = (
- (v ? 0 : 0x80) |
- (c ? 0x10 : 0)
- );
- ctx.mmu.wb(addr, v);
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- swap_r8: |
- let b = ctx.cpu.r.<%= dst.downcase %>,
- v = ((b & 0x0F) << 4) | (b >> 4);
-
- ctx.cpu.r.f = (
- (v ? 0 : 0x80);
- );
- ctx.cpu.r.<%= dst.downcase %> = v;
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- swap_rp16: |
- let addr = (
- ((ctx.cpu.r.<%= dst.downcase[1] %> & 0xFF) << 8) +
- (ctx.cpu.r.<%= dst.downcase[2] %> & 0xFF)
- ),
- b = ctx.mmu.rb(addr),
- v = ((b & 0x0F) << 4) | (b >> 4);
-
- ctx.cpu.r.f = (
- (v ? 0 : 0x80) |
- );
- ctx.mmu.wb(addr, v);
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- cp_r8: |
- let v = (
- ctx.cpu.r.<%= dst.downcase %> -
- ctx.cpu.r.<%= src.downcase %>
- ), hc = (
- // FIXME: probably wrong
- (ctx.cpu.r.<%= dst.downcase %> & 0xF) <
- (v & 0xF)
- );
-
- ctx.cpu.r.f = (
- ((v & 0xFF) ? 0 : 0x80) |
- 0x40 |
- (hc ? 0x20 : 0) |
- ((v < 0) ? 0 : 0x10)
- ) 0xFF;
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- cp_d8: |
- let v = (
- ctx.cpu.r.<%= dst.downcase %> -
- ctx.mmu.rb(ctx.cpu.r.pc + 1)
- ), hc = (
- // FIXME: probably wrong
- (ctx.cpu.r.<%= dst.downcase %> & 0xF) <
- (v & 0xF)
- );
-
- ctx.cpu.r.f = (
- ((v & 0xFF) ? 0 : 0x80) |
- 0x40 |
- (hc ? 0x20 : 0) |
- ((v < 0) ? 0 : 0x10)
- ) 0xFF;
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- cp_rp16: |
- let v = (
- ctx.cpu.r.<%= dst.downcase %> -
- ctx.mmu.rb(
- ((ctx.cpu.r.<%= src.downcase[1] %> & 0xFF) << 8) +
- (ctx.cpu.r.<%= src.downcase[2] %> & 0xFF)
- )
- ), hc = (
- // FIXME: probably wrong
- (ctx.cpu.r.<%= dst.downcase %> & 0xF) <
- (v & 0xF)
- );
-
- ctx.cpu.r.f = (
- ((v & 0xFF) ? 0 : 0x80) |
- 0x40 |
- (hc ? 0x20 : 0) |
- ((v < 0) ? 0 : 0x10)
- ) 0xFF;
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- nop: |
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- halt: |
- ctx.cpu.r.halt = true;
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- stop: |
- ctx.cpu.r.stop = true;
- // ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- rst: |
- // increment pc
- // FIXME: is this correct before sp push?
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
-
- // push pc
- ctx.cpu.r.sp = (ctx.cpu.r.sp - 2) & 0xFFFF;
- ctx.mmu.ww(ctx.cpu.r.sp, ctx.cpu.r.pc);
-
- // set pc
- ctx.cpu.r.pc = <%= addr %>;
- t += <%= time %>;
-
- push: |
- // push hi
- ctx.cpu.r.sp = (ctx.cpu.r.sp - 1) & 0xFFFF;
- ctx.mmu.wb(ctx.cpu.r.sp, ctx.cpu.r.<%= src.downcase[0] %>);
-
- // push lo
- ctx.cpu.r.sp = (ctx.cpu.r.sp - 1) & 0xFFFF;
- ctx.mmu.wb(ctx.cpu.r.sp, ctx.cpu.r.<%= src.downcase[1] %>);
-
- // set pc
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- pop: |
- // pop lo
- ctx.cpu.r.<%= dst.downcase[1] %> = ctx.mmu.rb(ctx.cpu.r.sp) & 0xFF;
- ctx.cpu.r.sp = (ctx.cpu.r.sp + 1) & 0xFFFF;
-
- // pop hi
- ctx.cpu.r.<%= dst.downcase[0] %> = ctx.mmu.rb(ctx.cpu.r.sp) & 0xFF;
- ctx.cpu.r.sp = (ctx.cpu.r.sp + 1) & 0xFFFF;
-
- // set pc
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- cond_Z: |
- ctx.cpu.r.f & 0x80
-
- cond_NZ: |
- !(ctx.cpu.r.f ^ 0x80)
-
- cond_C: |
- ctx.cpu.r.f & 0x10
-
- cond_NC: |
- !(ctx.cpu.r.f & 0x10)
-
- jp_addr: |
- (
- (ctx.cpu.r.<%= src.downcase[1] %> & 0xFF) << 8 |
- (ctx.cpu.r.<%= src.downcase[2] %> & 0xFF)
- )
-
- jp_test: |
- if (<%= cond %>) {
- ctx.cpu.r.pc = ctx.mmu.rw(<%= addr %>) & 0xFFFF;
- t += <%= time['t'] %>;
- } else {
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time['f'] %>;
- }
-
- jp: |
- ctx.cpu.r.pc = ctx.mmu.rw(<%= addr %>) & 0xFFFF;
- t += <%= time %>;
-
- jr_test: |
- if (<%= cond %>) {
- // treat byte as signed offset
- let byte = ctx.mmu.rb(ctx.cpu.pc + 1),
- ofs = (byte & 0x08) ? -((~byte + 1) & 0xFF) : byte;
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + ofs) & 0xFFFF;
- t += <%= time['t'] %>;
- } else {
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time['f'] %>;
- }
-
- jr: |
- // treat byte as signed offset
- let byte = ctx.mmu.rb(ctx.cpu.pc + 1),
- ofs = (byte & 0x08) ? -((~byte + 1) & 0xFF) : byte;
-
- ctx.cpu.r.pc = (ctx.cpu.r.pc + ofs) & 0xFFFF;
- t += <%= time %>;
-
- call_test: |
- // calc next instruction
- let next_inst = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
-
- if (<%= cond %>) {
- // calc addr
- let addr = (
- ((ctx.mmu.rb(ctx.cpu.r.pc + 1) & 0xFF) << 8) & |
- (ctx.mmu.rb(ctx.cpu.r.pc + 2) & 0xFF)
- );
-
- // push hi pc byte
- ctx.cpu.r.sp = (ctx.cpu.r.sp - 1) & 0xFFFF;
- ctx.mmu.wb(ctx.cpu.r.sp, (next_inst >> 8) & 0xFF);
-
- // push lo pc byte
- ctx.cpu.r.sp = (ctx.cpu.r.sp - 1) & 0xFFFF;
- ctx.mmu.wb(ctx.cpu.r.sp, next_inst & 0xFF);
-
- // set pc, inc time
- ctx.cpu.r.pc = addr;
- t += <%= time['t'] %>;
- } else {
- // set pc, inc time
- ctx.cpu.r.pc = next_inst;
- t += <%= time['f'] %>;
- }
-
- call: |
- // calc next instruction
- let next_inst = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
-
- // calc addr
- let addr = (
- ((ctx.mmu.rb(ctx.cpu.r.pc + 1) & 0xFF) << 8) & |
- (ctx.mmu.rb(ctx.cpu.r.pc + 2) & 0xFF)
- );
-
- // push hi pc byte
- ctx.cpu.r.sp = (ctx.cpu.r.sp - 1) & 0xFFFF;
- ctx.mmu.wb(ctx.cpu.r.sp, (next_inst >> 8) & 0xFF);
-
- // push lo pc byte
- ctx.cpu.r.sp = (ctx.cpu.r.sp - 1) & 0xFFFF;
- ctx.mmu.wb(ctx.cpu.r.sp, next_inst & 0xFF);
-
- // set pc, inc time
- ctx.cpu.r.pc = addr;
- t += <%= time %>;
-
- ret_test: |
- if (<%= cond %>) {
- // pop lo
- let lo = ctx.mmu.rb(ctx.cpu.r.sp);
- ctx.cpu.r.sp = (ctx.cpu.r.sp + 1) & 0xFFFF;
-
- // pop hi
- let hi = ctx.mmu.rb(ctx.cpu.r.sp);
- ctx.cpu.r.sp = (ctx.cpu.r.sp + 1) & 0xFFFF;
-
- // set pc, inc time
- ctx.cpu.r.pc = ((hi & 0xFF) << 8) | (lo & 0xFF);
- t += <%= time['t'] %>;
- } else {
- // set pc, inc time
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time['f'] %>;
- }
-
- ret: |
- // pop lo
- let lo = ctx.mmu.rb(ctx.cpu.r.sp);
- ctx.cpu.r.sp = (ctx.cpu.r.sp + 1) & 0xFFFF;
-
- // pop hi
- let hi = ctx.mmu.rb(ctx.cpu.r.sp);
- ctx.cpu.r.sp = (ctx.cpu.r.sp + 1) & 0xFFFF;
-
- // set pc, inc time
- ctx.cpu.r.pc = ((hi & 0xFF) << 8) | (lo & 0xFF);
- t += <%= time %>;
-
- reti: |
- // enable interrupts
- ctx.cpu.r.i = true;
-
- /// rest is ret
-
- ei: |
- // enable interrupts
- ctx.cpu.r.i = true;
-
- // set pc, inc time
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- di: |
- // disable interrupts
- ctx.cpu.r.i = false;
-
- // set pc, inc time
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- scf: |
- ctx.cpu.r.f = (
- (ctx.cpu.r.f & 0x80) |
- 0x10
- );
-
- // set pc, inc time
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- ccf: |
- ctx.cpu.r.f = (
- (ctx.cpu.r.f & 0x80) |
- (ctx.cpu.r.f & 0x10 ? 0 : 0x10)
- );
-
- // set pc, inc time
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- cpl: |
- // complement a
- ctx.cpu.r.a = (~ctx.cpu.r.a) & 0xFF;
-
- // set flags
- ctx.cpu.r.f = (
- (ctx.cpu.r.f & 0x80) |
- 0x40 |
- 0x20 |
- (ctx.cpu.r.f & 0x10)
- );
-
- // set pc, inc time
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- ldh_a_a8: |
- ctx.cpu.r.a = ctx.mmu.rb(0xFF00 | ctx.mmu.rb(ctx.cpu.r.pc + 1));
-
- // set pc, inc time
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- ldh_a8_a: |
- ctx.mmu.wb(0xFF00 | ctx.mmu.rb(ctx.cpu.r.pc + 1), ctx.cpu.r.a);
-
- // set pc, inc time
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;
-
- daa: |
- // from http://datasheets.chipdb.org/Zilog/Z80/z80-documented-0.90.pdf
- // and http://forums.nesdev.com/viewtopic.php?t=9088
- let v = ctx.cpu.r.a;
- let ofs = (
- (((ctx.cpu.r.f & 0x10) || ((ctx.cpu.r.a >> 4) > 9)) ? 0x60 : 0) +
- (((ctx.cpu.r.f & 0x20) || ((ctx.cpu.r.a & 0xF) > 9)) ? 0x06 : 0)
- );
-
- if (ctx.cpu.r.f & 0x40) {
- v -= ofs;
- } else {
- v += ofs;
- }
-
- // set flags
- ctx.cpu.r.f = (
- (v & 0xFF ? 0 : 0x80) |
- (ctx.cpu.r.f & 0x40) |
- (cf ? 0x10 : 0)
- );
-
- // update a
- ctx.cpu.r.a = v & 0xFF;
-
- // set pc, inc time
- ctx.cpu.r.pc = (ctx.cpu.r.pc + <%= len %>) & 0xFFFF;
- t += <%= time %>;