comparison genesis.c @ 1117:928a65750345

Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
author Michael Pavone <pavone@retrodev.com>
date Thu, 22 Dec 2016 19:51:25 -0800
parents fe8c79f82c22
children 8f14767661fa
comparison
equal deleted inserted replaced
1116:fe8c79f82c22 1117:928a65750345
37 } 37 }
38 //TODO: Figure out what happens when you try to DMA from weird adresses like IO or banked Z80 area 38 //TODO: Figure out what happens when you try to DMA from weird adresses like IO or banked Z80 area
39 return 0; 39 return 0;
40 } 40 }
41 41
42 uint16_t get_open_bus_value() 42 static uint16_t get_open_bus_value(system_header *system)
43 { 43 {
44 genesis_context *genesis = (genesis_context *)current_system; 44 genesis_context *genesis = (genesis_context *)system;
45 return read_dma_value(genesis->m68k->last_prefetch_address/2); 45 return read_dma_value(genesis->m68k->last_prefetch_address/2);
46 } 46 }
47 47
48 static void adjust_int_cycle(m68k_context * context, vdp_context * v_context) 48 static void adjust_int_cycle(m68k_context * context, vdp_context * v_context)
49 { 49 {
99 #else 99 #else
100 #define dprintf 100 #define dprintf
101 #define dputs 101 #define dputs
102 #endif 102 #endif
103 103
104 void z80_next_int_pulse(z80_context * z_context) 104 static void z80_next_int_pulse(z80_context * z_context)
105 { 105 {
106 genesis_context * gen = z_context->system; 106 genesis_context * gen = z_context->system;
107 z_context->int_pulse_start = vdp_next_vint_z80(gen->vdp); 107 z_context->int_pulse_start = vdp_next_vint_z80(gen->vdp);
108 //Notes in the Genesis Plus GX code suggest this is asserted for one line 108 //Notes in the Genesis Plus GX code suggest this is asserted for one line
109 z_context->int_pulse_end = z_context->int_pulse_start + MCLKS_LINE; 109 z_context->int_pulse_end = z_context->int_pulse_start + MCLKS_LINE;
624 value = 0xFF; 624 value = 0xFF;
625 } 625 }
626 } else { 626 } else {
627 if (location == 0x1100) { 627 if (location == 0x1100) {
628 value = z80_enabled ? !z80_get_busack(gen->z80, context->current_cycle) : !gen->z80->busack; 628 value = z80_enabled ? !z80_get_busack(gen->z80, context->current_cycle) : !gen->z80->busack;
629 value |= (get_open_bus_value() >> 8) & 0xFE; 629 value |= (get_open_bus_value(&gen->header) >> 8) & 0xFE;
630 dprintf("Byte read of BUSREQ returned %d @ %d (reset: %d)\n", value, context->current_cycle, gen->z80->reset); 630 dprintf("Byte read of BUSREQ returned %d @ %d (reset: %d)\n", value, context->current_cycle, gen->z80->reset);
631 } else if (location == 0x1200) { 631 } else if (location == 0x1200) {
632 value = !gen->z80->reset; 632 value = !gen->z80->reset;
633 } else { 633 } else {
634 value = 0xFF; 634 value = 0xFF;
639 return value; 639 return value;
640 } 640 }
641 641
642 static uint16_t io_read_w(uint32_t location, m68k_context * context) 642 static uint16_t io_read_w(uint32_t location, m68k_context * context)
643 { 643 {
644 genesis_context *gen = context->system;
644 uint16_t value = io_read(location, context); 645 uint16_t value = io_read(location, context);
645 if (location < 0x10000 || (location & 0x1FFF) < 0x100) { 646 if (location < 0x10000 || (location & 0x1FFF) < 0x100) {
646 value = value | (value << 8); 647 value = value | (value << 8);
647 } else { 648 } else {
648 value <<= 8; 649 value <<= 8;
649 value |= get_open_bus_value() & 0xFF; 650 value |= get_open_bus_value(&gen->header) & 0xFF;
650 } 651 }
651 return value; 652 return value;
652 } 653 }
653 654
654 static void * z80_write_ym(uint32_t location, void * vcontext, uint8_t value) 655 static void * z80_write_ym(uint32_t location, void * vcontext, uint8_t value)
900 gen->header.start_context = start_genesis; 901 gen->header.start_context = start_genesis;
901 gen->header.resume_context = resume_genesis; 902 gen->header.resume_context = resume_genesis;
902 gen->header.load_save = load_save; 903 gen->header.load_save = load_save;
903 gen->header.persist_save = persist_save; 904 gen->header.persist_save = persist_save;
904 gen->header.free_context = free_genesis; 905 gen->header.free_context = free_genesis;
906 gen->header.get_open_bus_value = get_open_bus_value;
905 gen->header.request_exit = request_exit; 907 gen->header.request_exit = request_exit;
906 gen->header.inc_debug_mode = inc_debug_mode; 908 gen->header.inc_debug_mode = inc_debug_mode;
907 gen->header.inc_debug_pal = inc_debug_pal; 909 gen->header.inc_debug_pal = inc_debug_pal;
908 set_region(gen, rom, force_region); 910 set_region(gen, rom, force_region);
909 911
910 gen->vdp = malloc(sizeof(vdp_context)); 912 gen->vdp = malloc(sizeof(vdp_context));
911 init_vdp_context(gen->vdp, gen->version_reg & 0x40); 913 init_vdp_context(gen->vdp, gen->version_reg & 0x40);
914 gen->vdp->system = &gen->header;
912 gen->frame_end = vdp_cycles_to_frame_end(gen->vdp); 915 gen->frame_end = vdp_cycles_to_frame_end(gen->vdp);
913 char * config_cycles = tern_find_path(config, "clocks\0max_cycles\0").ptrval; 916 char * config_cycles = tern_find_path(config, "clocks\0max_cycles\0").ptrval;
914 gen->max_cycles = config_cycles ? atoi(config_cycles) : DEFAULT_SYNC_INTERVAL; 917 gen->max_cycles = config_cycles ? atoi(config_cycles) : DEFAULT_SYNC_INTERVAL;
915 918
916 char * lowpass_cutoff_str = tern_find_path(config, "audio\0lowpass_cutoff\0").ptrval; 919 char * lowpass_cutoff_str = tern_find_path(config, "audio\0lowpass_cutoff\0").ptrval;
927 z80_map[0].buffer = gen->zram = calloc(1, Z80_RAM_BYTES); 930 z80_map[0].buffer = gen->zram = calloc(1, Z80_RAM_BYTES);
928 #ifndef NO_Z80 931 #ifndef NO_Z80
929 z80_options *z_opts = malloc(sizeof(z80_options)); 932 z80_options *z_opts = malloc(sizeof(z80_options));
930 init_z80_opts(z_opts, z80_map, 5, NULL, 0, MCLKS_PER_Z80, 0xFFFF); 933 init_z80_opts(z_opts, z80_map, 5, NULL, 0, MCLKS_PER_Z80, 0xFFFF);
931 init_z80_context(gen->z80, z_opts); 934 init_z80_context(gen->z80, z_opts);
935 gen->z80->next_int_pulse = z80_next_int_pulse;
932 z80_assert_reset(gen->z80, 0); 936 z80_assert_reset(gen->z80, 0);
933 #endif 937 #endif
934 938
935 gen->z80->system = gen; 939 gen->z80->system = gen;
936 gen->z80->mem_pointers[0] = gen->zram; 940 gen->z80->mem_pointers[0] = gen->zram;