summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2015-01-01 22:18:32 -0800
committerMichael Pavone <pavone@retrodev.com>2015-01-01 22:18:32 -0800
commit758586c1b7feec3c4fa3761ed17d1a6ea3cbab00 (patch)
treebf6cf42b168974487b57469c8b2c452620e963e5
parentd41ae43228509a1a67446492b844013cf1e68c36 (diff)
Add the 3 cycle delay back in to Z80 bank area access
-rw-r--r--blastem.c30
-rw-r--r--z80_to_x86.c7
-rw-r--r--z80_to_x86.h1
3 files changed, 23 insertions, 15 deletions
diff --git a/blastem.c b/blastem.c
index 1e396d7..46dbdc9 100644
--- a/blastem.c
+++ b/blastem.c
@@ -419,6 +419,7 @@ void * z80_vdp_port_write(uint32_t vdp_port, void * vcontext, uint8_t value)
{
z80_context * context = vcontext;
genesis_context * gen = context->system;
+ vdp_port &= 0xFF;
if (vdp_port & 0xE0) {
printf("machine freeze due to write to Z80 address %X\n", 0x7F00 | vdp_port);
exit(1);
@@ -761,11 +762,20 @@ uint8_t z80_read_ym(uint32_t location, void * vcontext)
uint8_t z80_read_bank(uint32_t location, void * vcontext)
{
z80_context * context = vcontext;
+ //typical delay from bus arbitration
+ context->current_cycle += 3;
+
+ location &= 0x7FFF;
+ //TODO: add cycle for an access right after a previous one
+ //TODO: block Z80 if VDP has the bus or the 68K is blocked on a VDP access
+ if (context->mem_pointers[1]) {
+ return context->mem_pointers[1][location ^ 1];
+ }
uint32_t address = context->bank_reg << 15 | location;
if (address >= 0xC00000 && address < 0xE00000) {
return z80_vdp_port_read(location & 0xFF, context);
} else {
- fprintf(stderr, "Unhandled read by Z80 from address %X through banked memory area\n", address);
+ fprintf(stderr, "Unhandled read by Z80 from address %X through banked memory area (%X)\n", address, context->bank_reg << 15);
}
return 0;
}
@@ -773,6 +783,11 @@ uint8_t z80_read_bank(uint32_t location, void * vcontext)
void *z80_write_bank(uint32_t location, void * vcontext, uint8_t value)
{
z80_context * context = vcontext;
+ //typical delay from bus arbitration
+ context->current_cycle += 3;
+ location &= 0x7FFF;
+ //TODO: add cycle for an access right after a previous one
+ //TODO: block Z80 if VDP has the bus or the 68K is blocked on a VDP access
uint32_t address = context->bank_reg << 15 | location;
if (address >= 0xE00000) {
address &= 0xFFFF;
@@ -791,7 +806,8 @@ void *z80_write_bank_reg(uint32_t location, void * vcontext, uint8_t value)
context->bank_reg = (context->bank_reg >> 1 | value << 8) & 0x1FF;
if (context->bank_reg < 0x80) {
- context->mem_pointers[1] = context->mem_pointers[2] + (context->bank_reg << 15);
+ genesis_context *gen = context->system;
+ context->mem_pointers[1] = get_native_pointer(context->bank_reg << 15, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen);
} else {
context->mem_pointers[1] = NULL;
}
@@ -1178,11 +1194,11 @@ void detect_region()
}
#ifndef NO_Z80
const memmap_chunk z80_map[] = {
- { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL },
- { 0x8000, 0x10000, 0x7FFF, 1, MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL | MMAP_BYTESWAP, NULL, NULL, NULL, z80_read_bank, z80_write_bank},
- { 0x4000, 0x6000, 0x0003, 0, 0, NULL, NULL, NULL, z80_read_ym, z80_write_ym},
- { 0x6000, 0x6100, 0xFFFF, 0, 0, NULL, NULL, NULL, NULL, z80_write_bank_reg},
- { 0x7F00, 0x8000, 0x00FF, 0, 0, NULL, NULL, NULL, z80_vdp_port_read, z80_vdp_port_write}
+ { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL },
+ { 0x8000, 0x10000, 0x7FFF, 0, 0, NULL, NULL, NULL, z80_read_bank, z80_write_bank},
+ { 0x4000, 0x6000, 0x0003, 0, 0, NULL, NULL, NULL, z80_read_ym, z80_write_ym},
+ { 0x6000, 0x6100, 0xFFFF, 0, 0, NULL, NULL, NULL, NULL, z80_write_bank_reg},
+ { 0x7F00, 0x8000, 0x00FF, 0, 0, NULL, NULL, NULL, z80_vdp_port_read, z80_vdp_port_write}
};
#endif
diff --git a/z80_to_x86.c b/z80_to_x86.c
index a30adde..5f028b6 100644
--- a/z80_to_x86.c
+++ b/z80_to_x86.c
@@ -2223,13 +2223,6 @@ void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t
jmp_rind(code, options->gen.context_reg);
}
-void * z80_gen_bank_write(uint32_t start_address, void * voptions)
-{
- z80_options * options = voptions;
- //TODO: Handle writes to bank register
- return options;
-}
-
void init_z80_context(z80_context * context, z80_options * options)
{
memset(context, 0, sizeof(*context));
diff --git a/z80_to_x86.h b/z80_to_x86.h
index 0c035c6..9b29852 100644
--- a/z80_to_x86.h
+++ b/z80_to_x86.h
@@ -93,7 +93,6 @@ void z80_run(z80_context * context);
void z80_reset(z80_context * context);
void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler);
void zremove_breakpoint(z80_context * context, uint16_t address);
-void * z80_gen_bank_write(uint32_t start_address, void * voptions);
#endif //Z80_TO_X86_H_