Mercurial > repos > blastem
comparison z80_to_x86.c @ 659:759c38bf97f8
Minor Z80 core cleanup
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 01 Jan 2015 20:26:22 -0800 |
parents | 92ce5ea5ffc9 |
children | e7cae6d9aaa6 |
comparison
equal
deleted
inserted
replaced
658:6aa29ac33f1a | 659:759c38bf97f8 |
---|---|
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <stddef.h> | 12 #include <stddef.h> |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #define MODE_UNUSED (MODE_IMMED-1) | 15 #define MODE_UNUSED (MODE_IMMED-1) |
16 | |
17 #define ZCYCLES RBP | |
18 #define ZLIMIT RDI | |
19 #define SCRATCH1 R13 | |
20 #define SCRATCH2 R14 | |
21 #define CONTEXT RSI | |
22 | 16 |
23 //#define DO_DEBUG_PRINT | 17 //#define DO_DEBUG_PRINT |
24 | 18 |
25 #ifdef DO_DEBUG_PRINT | 19 #ifdef DO_DEBUG_PRINT |
26 #define dprintf printf | 20 #define dprintf printf |
136 ror_ir(code, 8, ea->base, SZ_W); | 130 ror_ir(code, 8, ea->base, SZ_W); |
137 } | 131 } |
138 } | 132 } |
139 } else { | 133 } else { |
140 ea->mode = MODE_REG_DISPLACE8; | 134 ea->mode = MODE_REG_DISPLACE8; |
141 ea->base = CONTEXT; | 135 ea->base = opts->gen.context_reg; |
142 ea->disp = offsetof(z80_context, regs) + inst->ea_reg; | 136 ea->disp = offsetof(z80_context, regs) + inst->ea_reg; |
143 } | 137 } |
144 break; | 138 break; |
145 case Z80_REG_INDIRECT: | 139 case Z80_REG_INDIRECT: |
146 mov_rr(code, opts->regs[inst->ea_reg], areg, SZ_W); | 140 mov_rr(code, opts->regs[inst->ea_reg], areg, SZ_W); |
366 //TODO: Implement half-carry flag | 360 //TODO: Implement half-carry flag |
367 cmp_ir(code, 0, dst_op.base, SZ_B); | 361 cmp_ir(code, 0, dst_op.base, SZ_B); |
368 setcc_rdisp(code, CC_Z, opts->gen.context_reg, zf_off(ZF_Z)); | 362 setcc_rdisp(code, CC_Z, opts->gen.context_reg, zf_off(ZF_Z)); |
369 setcc_rdisp(code, CC_S, opts->gen.context_reg, zf_off(ZF_S)); | 363 setcc_rdisp(code, CC_S, opts->gen.context_reg, zf_off(ZF_S)); |
370 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B);; | 364 mov_irdisp(code, 0, opts->gen.context_reg, zf_off(ZF_N), SZ_B);; |
371 mov_rdispr(code, opts->gen.context_reg, offsetof(z80_context, iff2), SCRATCH1, SZ_B); | 365 mov_rdispr(code, opts->gen.context_reg, offsetof(z80_context, iff2), opts->gen.scratch1, SZ_B); |
372 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, zf_off(ZF_PV), SZ_B); | 366 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, zf_off(ZF_PV), SZ_B); |
373 } | 367 } |
374 z80_save_reg(inst, opts); | 368 z80_save_reg(inst, opts); |
375 z80_save_ea(code, inst, opts); | 369 z80_save_ea(code, inst, opts); |
376 if (inst->addr_mode & Z80_DIR) { | 370 if (inst->addr_mode & Z80_DIR) { |
1924 dprintf("defferred address: %X\n", address); | 1918 dprintf("defferred address: %X\n", address); |
1925 } | 1919 } |
1926 } while (opts->gen.deferred); | 1920 } while (opts->gen.deferred); |
1927 } | 1921 } |
1928 | 1922 |
1929 void init_x86_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks) | 1923 void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks) |
1930 { | 1924 { |
1931 memset(options, 0, sizeof(*options)); | 1925 memset(options, 0, sizeof(*options)); |
1932 | 1926 |
1933 options->gen.memmap = chunks; | 1927 options->gen.memmap = chunks; |
1934 options->gen.memmap_chunks = num_chunks; | 1928 options->gen.memmap_chunks = num_chunks; |
2261 } | 2255 } |
2262 | 2256 |
2263 uint32_t zbreakpoint_patch(z80_context * context, uint16_t address, code_ptr dst) | 2257 uint32_t zbreakpoint_patch(z80_context * context, uint16_t address, code_ptr dst) |
2264 { | 2258 { |
2265 code_info code = {dst, dst+16}; | 2259 code_info code = {dst, dst+16}; |
2266 mov_ir(&code, address, SCRATCH1, SZ_W); | 2260 mov_ir(&code, address, context->options->gen.scratch1, SZ_W); |
2267 call(&code, context->bp_stub); | 2261 call(&code, context->bp_stub); |
2268 return code.cur-dst; | 2262 return code.cur-dst; |
2269 } | 2263 } |
2270 | 2264 |
2271 void zcreate_stub(z80_context * context) | 2265 void zcreate_stub(z80_context * context) |