# HG changeset patch # User Mike Pavone # Date 1367379375 25200 # Node ID 2989ed7b8608522783a6e7dd5e98b408769fae21 # Parent d97c9eca49f4ff4a440e354cd6d3a91f5d8c3f98 Add a second context pointer to m68k_context so that try_fifo_write can still have easy access to the VDP. Handle writes to Z80 code addresses from the 68K. diff -r d97c9eca49f4 -r 2989ed7b8608 blastem.c --- a/blastem.c Tue Apr 30 20:33:30 2013 -0700 +++ b/blastem.c Tue Apr 30 20:36:15 2013 -0700 @@ -136,8 +136,8 @@ m68k_context * sync_components(m68k_context * context, uint32_t address) { //TODO: Handle sync targets smaller than a single frame - z80_context * z_context = context->next_context; - vdp_context * v_context = z_context->next_context; + z80_context * z_context = context->next_cpu; + vdp_context * v_context = context->video_context; uint32_t mclks = context->current_cycle * MCLKS_PER_68K; if (!reset && !busreq) { if (need_reset) { @@ -150,7 +150,10 @@ z_context->int_cycle = ZVINT_CYCLE; } z_context->target_cycle = z_context->sync_cycle < z_context->int_cycle ? z_context->sync_cycle : z_context->int_cycle; + printf("Running Z80 from cycle %d to cycle %d\n", z_context->current_cycle, z_context->sync_cycle); + printf("HL: %X, Native PC: %p\n", (z_context->regs[Z80_H] << 8) | z_context->regs[Z80_L], z_context->native_pc); z80_run(z_context); + printf("Z80 returned at cycle %d\n", z_context->current_cycle); } } if (mclks >= MCLKS_PER_FRAME) { @@ -188,8 +191,7 @@ { //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle); sync_components(context, 0); - z80_context * z_context = context->next_context; - vdp_context * v_context = z_context->next_context; + vdp_context * v_context = context->video_context; if (vdp_port < 0x10) { int blocked; if (vdp_port < 4) { @@ -248,8 +250,7 @@ m68k_context * vdp_port_read(uint32_t vdp_port, m68k_context * context) { sync_components(context, 0); - z80_context * z_context = context->next_context; - vdp_context * v_context = z_context->next_context; + vdp_context * v_context = context->video_context; if (vdp_port < 0x10) { if (vdp_port < 4) { context->value = vdp_data_port_read(v_context); @@ -347,6 +348,7 @@ location &= 0x7FFF; if (location < 0x4000) { z80_ram[location & 0x1FFF] = value; + z80_handle_code_write(location & 0x1FFF, context->next_cpu); } } } else { @@ -383,7 +385,7 @@ } } else { if (busreq) { - z80_context * z_context = context->next_context; + z80_context * z_context = context->next_cpu; //TODO: Add necessary delay between release of busreq and resumption of execution z_context->current_cycle = (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80; } @@ -399,7 +401,7 @@ } //TODO: Deal with the scenario in which reset is not asserted long enough if (reset) { - z80_context * z_context = context->next_context; + z80_context * z_context = context->next_cpu; need_reset = 1; //TODO: Add necessary delay between release of reset and start of execution z_context->current_cycle = (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80; @@ -425,6 +427,7 @@ location &= 0x7FFF; if (location < 0x4000) { z80_ram[location & 0x1FFE] = value >> 8; + z80_handle_code_write(location & 0x1FFE, context->next_cpu); } } } else { @@ -462,7 +465,7 @@ } } else { if (busreq) { - z80_context * z_context = context->next_context; + z80_context * z_context = context->next_cpu; //TODO: Add necessary delay between release of busreq and resumption of execution z_context->current_cycle = (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80; } @@ -478,7 +481,7 @@ } //TODO: Deal with the scenario in which reset is not asserted long enough if (reset) { - z80_context * z_context = context->next_context; + z80_context * z_context = context->next_cpu; need_reset = 1; //TODO: Add necessary delay between release of reset and start of execution z_context->current_cycle = (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80; @@ -854,7 +857,7 @@ return context; } -void init_run_cpu(z80_context * zcontext, int debug, FILE * address_log) +void init_run_cpu(vdp_context * vcontext, z80_context * zcontext, int debug, FILE * address_log) { m68k_context context; x86_68k_options opts; @@ -862,7 +865,8 @@ opts.address_log = address_log; init_68k_context(&context, opts.native_code_map, &opts); - context.next_context = zcontext; + context.video_context = vcontext; + context.next_cpu = zcontext; //cartridge ROM context.mem_pointers[0] = cart; context.target_cycle = context.sync_cycle = MCLKS_PER_FRAME/MCLKS_PER_68K; @@ -938,6 +942,6 @@ z_context.int_cycle = CYCLE_NEVER; z_context.mem_pointers[1] = z_context.mem_pointers[2] = (uint8_t *)cart; - init_run_cpu(&z_context, debug, address_log); + init_run_cpu(&v_context, &z_context, debug, address_log); return 0; } diff -r d97c9eca49f4 -r 2989ed7b8608 m68k_to_x86.h --- a/m68k_to_x86.h Tue Apr 30 20:33:30 2013 -0700 +++ b/m68k_to_x86.h Tue Apr 30 20:36:15 2013 -0700 @@ -37,12 +37,13 @@ uint32_t int_cycle; uint32_t int_num; uint16_t *mem_pointers[NUM_MEM_AREAS]; - void *next_context; + void *video_context; uint16_t value; native_map_slot *native_code_map; void *options; uint8_t ram_code_flags[32/8]; + void *next_cpu; } m68k_context; uint8_t * translate_m68k(uint8_t * dst, struct m68kinst * inst, x86_68k_options * opts); diff -r d97c9eca49f4 -r 2989ed7b8608 z80_to_x86.h --- a/z80_to_x86.h Tue Apr 30 20:33:30 2013 -0700 +++ b/z80_to_x86.h Tue Apr 30 20:36:15 2013 -0700 @@ -55,6 +55,7 @@ void init_x86_z80_opts(x86_z80_options * options); void init_z80_context(z80_context * context, x86_z80_options * options); uint8_t * z80_get_native_address(z80_context * context, uint32_t address); +z80_context * z80_handle_code_write(uint32_t address, z80_context * context); void z80_run(z80_context * context); void z80_reset(z80_context * context);