diff options
author | Paul Duncan <pabs@pablotron.org> | 2018-06-25 16:59:47 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2018-06-25 16:59:47 -0400 |
commit | f8012322fc758990f47a1ac469cd713d636861c3 (patch) | |
tree | 14a7ab84b8a81c92d5b781f78e18086a4dd874ff | |
parent | c9340928075f9558bbb4817f6c89298ed15ad77f (diff) | |
download | gb-c-f8012322fc758990f47a1ac469cd713d636861c3.tar.bz2 gb-c-f8012322fc758990f47a1ac469cd713d636861c3.zip |
simplify INC/DEC
-rw-r--r-- | ops.yaml | 75 |
1 files changed, 33 insertions, 42 deletions
@@ -9201,55 +9201,46 @@ templates: } } - static void - inc_rb( + static uint8_t + inc( gb_t * const ctx, - const rb_t reg + const uint8_t o ) { - // get old and new value - const uint8_t o = cpu_rb(ctx, reg), - n = o + 1; - - // set new value - cpu_wb(ctx, reg, n); + const uint8_t n = o + 1; // set flags cpu_wf(ctx, F_Z | F_N | F_H, ( (n ? F_Z : 0) | (((o & 0x0F) == 0x0F) ? F_H : 0) )); + + // return new value + return n; + } + + static void + inc_rb( + gb_t * const ctx, + const rb_t reg + ) { + cpu_wb(ctx, reg, inc(ctx, cpu_rb(ctx, reg))); } static void inc_hl_ptr( gb_t * const ctx ) { - // write flags const uint16_t addr = cpu_rw(ctx, RW_HL); - const uint8_t o = mmu_rb(ctx, addr), - n = o + 1; - - // write value - mmu_wb(ctx, addr, n); - - // write flags - cpu_wf(ctx, F_Z | F_N | F_H, ( - (n ? 0 : F_Z) | - (((o & 0x0F) == 0x0F) ? F_H : 0) - )); + mmu_wb(ctx, addr, inc(ctx, mmu_rb(ctx, addr))); } - static void - dec_rb( + static uint8_t + dec( gb_t * const ctx, - const rb_t reg + const uint8_t o ) { - // get old and new value - const uint8_t o = cpu_rb(ctx, reg), - n = o - 1; - - // set new value - cpu_wb(ctx, reg, n); + // cal new value + const uint8_t n = o - 1; // set flags cpu_wf(ctx, F_Z | F_N | F_H, ( @@ -9257,6 +9248,17 @@ templates: F_N | (((o ^ n) & 0x10) ? F_H : 0) )); + + // return new value + return n; + } + + static void + dec_rb( + gb_t * const ctx, + const rb_t reg + ) { + cpu_wb(ctx, reg, dec(ctx, cpu_rb(ctx, reg))); } static void @@ -9265,18 +9267,7 @@ templates: ) { // write flags const uint16_t addr = cpu_rw(ctx, RW_HL); - const uint8_t o = mmu_rb(ctx, addr), - n = o - 1; - - // write value - mmu_wb(ctx, addr, n); - - // write flags - cpu_wf(ctx, F_Z | F_N | F_H, ( - (n ? 0 : F_Z) | - F_N | - (((o & 0x0F) == 0x00) ? F_H : 0) - )); + mmu_wb(ctx, addr, dec(ctx, mmu_rb(ctx, addr))); } static void |