Mercurial > repos > blastem
comparison blastem.c @ 660:e7cae6d9aaa6
Add the 3 cycle delay back in to Z80 bank area access
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 01 Jan 2015 22:18:32 -0800 |
parents | 759c38bf97f8 |
children | 01c51f397db2 |
comparison
equal
deleted
inserted
replaced
659:759c38bf97f8 | 660:e7cae6d9aaa6 |
---|---|
417 | 417 |
418 void * z80_vdp_port_write(uint32_t vdp_port, void * vcontext, uint8_t value) | 418 void * z80_vdp_port_write(uint32_t vdp_port, void * vcontext, uint8_t value) |
419 { | 419 { |
420 z80_context * context = vcontext; | 420 z80_context * context = vcontext; |
421 genesis_context * gen = context->system; | 421 genesis_context * gen = context->system; |
422 vdp_port &= 0xFF; | |
422 if (vdp_port & 0xE0) { | 423 if (vdp_port & 0xE0) { |
423 printf("machine freeze due to write to Z80 address %X\n", 0x7F00 | vdp_port); | 424 printf("machine freeze due to write to Z80 address %X\n", 0x7F00 | vdp_port); |
424 exit(1); | 425 exit(1); |
425 } | 426 } |
426 if (vdp_port < 0x10) { | 427 if (vdp_port < 0x10) { |
759 } | 760 } |
760 | 761 |
761 uint8_t z80_read_bank(uint32_t location, void * vcontext) | 762 uint8_t z80_read_bank(uint32_t location, void * vcontext) |
762 { | 763 { |
763 z80_context * context = vcontext; | 764 z80_context * context = vcontext; |
765 //typical delay from bus arbitration | |
766 context->current_cycle += 3; | |
767 | |
768 location &= 0x7FFF; | |
769 //TODO: add cycle for an access right after a previous one | |
770 //TODO: block Z80 if VDP has the bus or the 68K is blocked on a VDP access | |
771 if (context->mem_pointers[1]) { | |
772 return context->mem_pointers[1][location ^ 1]; | |
773 } | |
764 uint32_t address = context->bank_reg << 15 | location; | 774 uint32_t address = context->bank_reg << 15 | location; |
765 if (address >= 0xC00000 && address < 0xE00000) { | 775 if (address >= 0xC00000 && address < 0xE00000) { |
766 return z80_vdp_port_read(location & 0xFF, context); | 776 return z80_vdp_port_read(location & 0xFF, context); |
767 } else { | 777 } else { |
768 fprintf(stderr, "Unhandled read by Z80 from address %X through banked memory area\n", address); | 778 fprintf(stderr, "Unhandled read by Z80 from address %X through banked memory area (%X)\n", address, context->bank_reg << 15); |
769 } | 779 } |
770 return 0; | 780 return 0; |
771 } | 781 } |
772 | 782 |
773 void *z80_write_bank(uint32_t location, void * vcontext, uint8_t value) | 783 void *z80_write_bank(uint32_t location, void * vcontext, uint8_t value) |
774 { | 784 { |
775 z80_context * context = vcontext; | 785 z80_context * context = vcontext; |
786 //typical delay from bus arbitration | |
787 context->current_cycle += 3; | |
788 location &= 0x7FFF; | |
789 //TODO: add cycle for an access right after a previous one | |
790 //TODO: block Z80 if VDP has the bus or the 68K is blocked on a VDP access | |
776 uint32_t address = context->bank_reg << 15 | location; | 791 uint32_t address = context->bank_reg << 15 | location; |
777 if (address >= 0xE00000) { | 792 if (address >= 0xE00000) { |
778 address &= 0xFFFF; | 793 address &= 0xFFFF; |
779 ((uint8_t *)ram)[address ^ 1] = value; | 794 ((uint8_t *)ram)[address ^ 1] = value; |
780 } else if (address >= 0xC00000) { | 795 } else if (address >= 0xC00000) { |
789 { | 804 { |
790 z80_context * context = vcontext; | 805 z80_context * context = vcontext; |
791 | 806 |
792 context->bank_reg = (context->bank_reg >> 1 | value << 8) & 0x1FF; | 807 context->bank_reg = (context->bank_reg >> 1 | value << 8) & 0x1FF; |
793 if (context->bank_reg < 0x80) { | 808 if (context->bank_reg < 0x80) { |
794 context->mem_pointers[1] = context->mem_pointers[2] + (context->bank_reg << 15); | 809 genesis_context *gen = context->system; |
810 context->mem_pointers[1] = get_native_pointer(context->bank_reg << 15, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen); | |
795 } else { | 811 } else { |
796 context->mem_pointers[1] = NULL; | 812 context->mem_pointers[1] = NULL; |
797 } | 813 } |
798 | 814 |
799 return context; | 815 return context; |
1176 } | 1192 } |
1177 } | 1193 } |
1178 } | 1194 } |
1179 #ifndef NO_Z80 | 1195 #ifndef NO_Z80 |
1180 const memmap_chunk z80_map[] = { | 1196 const memmap_chunk z80_map[] = { |
1181 { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL }, | 1197 { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL }, |
1182 { 0x8000, 0x10000, 0x7FFF, 1, MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL | MMAP_BYTESWAP, NULL, NULL, NULL, z80_read_bank, z80_write_bank}, | 1198 { 0x8000, 0x10000, 0x7FFF, 0, 0, NULL, NULL, NULL, z80_read_bank, z80_write_bank}, |
1183 { 0x4000, 0x6000, 0x0003, 0, 0, NULL, NULL, NULL, z80_read_ym, z80_write_ym}, | 1199 { 0x4000, 0x6000, 0x0003, 0, 0, NULL, NULL, NULL, z80_read_ym, z80_write_ym}, |
1184 { 0x6000, 0x6100, 0xFFFF, 0, 0, NULL, NULL, NULL, NULL, z80_write_bank_reg}, | 1200 { 0x6000, 0x6100, 0xFFFF, 0, 0, NULL, NULL, NULL, NULL, z80_write_bank_reg}, |
1185 { 0x7F00, 0x8000, 0x00FF, 0, 0, NULL, NULL, NULL, z80_vdp_port_read, z80_vdp_port_write} | 1201 { 0x7F00, 0x8000, 0x00FF, 0, 0, NULL, NULL, NULL, z80_vdp_port_read, z80_vdp_port_write} |
1186 }; | 1202 }; |
1187 #endif | 1203 #endif |
1188 | 1204 |
1189 int main(int argc, char ** argv) | 1205 int main(int argc, char ** argv) |
1190 { | 1206 { |