src/mess/drivers/ng_aes.c
| r6779 | r6780 | |
| 36 | 36 | #include "sound/2610intf.h" |
| 37 | 37 | #include "devices/aescart.h" |
| 38 | 38 | |
| 39 | #include "neogeo.lh" |
| 39 | 40 | |
| 41 | |
| 40 | 42 | #define LOG_VIDEO_SYSTEM (0) |
| 41 | 43 | #define LOG_CPU_COMM (0) |
| 42 | 44 | #define LOG_MAIN_CPU_BANKING (0) |
| r6779 | r6780 | |
| 50 | 52 | * |
| 51 | 53 | *************************************/ |
| 52 | 54 | |
| 53 | | static UINT8 display_position_interrupt_control; |
| 54 | | static UINT32 display_counter; |
| 55 | | static UINT32 vblank_interrupt_pending; |
| 56 | | static UINT32 display_position_interrupt_pending; |
| 57 | | static UINT32 irq3_pending; |
| 58 | | static emu_timer *display_position_interrupt_timer; |
| 59 | | static emu_timer *display_position_vblank_timer; |
| 60 | | static emu_timer *vblank_interrupt_timer; |
| 61 | | |
| 62 | | static UINT8 controller_select; |
| 63 | | |
| 64 | 55 | static UINT8 *memcard_data; |
| 65 | | |
| 66 | | static UINT32 main_cpu_bank_address; |
| 67 | | static UINT8 main_cpu_vector_table_source; |
| 68 | | |
| 69 | | static UINT8 audio_result; |
| 70 | | static UINT8 audio_cpu_banks[4]; |
| 71 | | static UINT8 audio_cpu_rom_source; |
| 72 | | static UINT8 audio_cpu_rom_source_last; |
| 73 | | |
| 74 | 56 | static UINT16 *save_ram; |
| 75 | | static UINT8 save_ram_unlocked; |
| 76 | 57 | |
| 77 | | static UINT8 output_data; |
| 78 | | static UINT8 output_latch; |
| 79 | | static UINT8 el_value; |
| 80 | 58 | |
| 81 | | |
| 82 | | |
| 83 | 59 | /************************************* |
| 84 | 60 | * |
| 85 | | * Forward declerations |
| 61 | * Forward declarations |
| 86 | 62 | * |
| 87 | 63 | *************************************/ |
| 88 | 64 | |
| 89 | | //static void calendar_clock(void); |
| 65 | //static void set_output_latch(running_machine *machine, UINT8 data); |
| 66 | //static void set_output_data(running_machine *machine, UINT8 data); |
| 90 | 67 | |
| 91 | 68 | |
| 92 | | |
| 93 | 69 | /************************************* |
| 94 | 70 | * |
| 95 | 71 | * Main CPU interrupt generation |
| r6779 | r6780 | |
| 102 | 78 | #define IRQ2CTRL_AUTOLOAD_REPEAT (0x80) |
| 103 | 79 | |
| 104 | 80 | |
| 105 | | static void adjust_display_position_interrupt_timer(running_machine *machine) |
| 81 | static void adjust_display_position_interrupt_timer( running_machine *machine ) |
| 106 | 82 | { |
| 107 | | if ((display_counter + 1) != 0) |
| 83 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 84 | |
| 85 | if ((state->display_counter + 1) != 0) |
| 108 | 86 | { |
| 109 | | attotime period = attotime_mul(ATTOTIME_IN_HZ(NEOGEO_PIXEL_CLOCK), display_counter + 1); |
| 110 | | if (LOG_VIDEO_SYSTEM) logerror("adjust_display_position_interrupt_timer current y: %02x current x: %02x target y: %x target x: %x\n", video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen), (display_counter + 1) / NEOGEO_HTOTAL, (display_counter + 1) % NEOGEO_HTOTAL); |
| 87 | attotime period = attotime_mul(ATTOTIME_IN_HZ(NEOGEO_PIXEL_CLOCK), state->display_counter + 1); |
| 88 | if (LOG_VIDEO_SYSTEM) logerror("adjust_display_position_interrupt_timer current y: %02x current x: %02x target y: %x target x: %x\n", video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen), (state->display_counter + 1) / NEOGEO_HTOTAL, (state->display_counter + 1) % NEOGEO_HTOTAL); |
| 111 | 89 | |
| 112 | | timer_adjust_oneshot(display_position_interrupt_timer, period, 0); |
| 90 | timer_adjust_oneshot(state->display_position_interrupt_timer, period, 0); |
| 113 | 91 | } |
| 114 | 92 | } |
| 115 | 93 | |
| 116 | 94 | |
| 117 | | void neogeo_set_display_position_interrupt_control(running_machine *machine,UINT16 data) |
| 95 | void neogeo_set_display_position_interrupt_control( running_machine *machine, UINT16 data ) |
| 118 | 96 | { |
| 119 | | display_position_interrupt_control = data; |
| 97 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 98 | state->display_position_interrupt_control = data; |
| 120 | 99 | } |
| 121 | 100 | |
| 122 | 101 | |
| 123 | | void neogeo_set_display_counter_msb(const address_space *space, UINT16 data) |
| 102 | void neogeo_set_display_counter_msb( const address_space *space, UINT16 data ) |
| 124 | 103 | { |
| 125 | | display_counter = (display_counter & 0x0000ffff) | ((UINT32)data << 16); |
| 104 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 126 | 105 | |
| 127 | | if (LOG_VIDEO_SYSTEM) logerror("PC %06x: set_display_counter %08x\n", cpu_get_pc(space->cpu), display_counter); |
| 106 | state->display_counter = (state->display_counter & 0x0000ffff) | ((UINT32)data << 16); |
| 107 | |
| 108 | if (LOG_VIDEO_SYSTEM) logerror("PC %06x: set_display_counter %08x\n", cpu_get_pc(space->cpu), state->display_counter); |
| 128 | 109 | } |
| 129 | 110 | |
| 130 | 111 | |
| 131 | | void neogeo_set_display_counter_lsb(const address_space *space, UINT16 data) |
| 112 | void neogeo_set_display_counter_lsb( const address_space *space, UINT16 data ) |
| 132 | 113 | { |
| 133 | | display_counter = (display_counter & 0xffff0000) | data; |
| 114 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 134 | 115 | |
| 135 | | if (LOG_VIDEO_SYSTEM) logerror("PC %06x: set_display_counter %08x\n", cpu_get_pc(space->cpu), display_counter); |
| 116 | state->display_counter = (state->display_counter & 0xffff0000) | data; |
| 136 | 117 | |
| 137 | | if (display_position_interrupt_control & IRQ2CTRL_LOAD_RELATIVE) |
| 118 | if (LOG_VIDEO_SYSTEM) logerror("PC %06x: set_display_counter %08x\n", cpu_get_pc(space->cpu), state->display_counter); |
| 119 | |
| 120 | if (state->display_position_interrupt_control & IRQ2CTRL_LOAD_RELATIVE) |
| 138 | 121 | { |
| 139 | 122 | if (LOG_VIDEO_SYSTEM) logerror("AUTOLOAD_RELATIVE "); |
| 140 | 123 | adjust_display_position_interrupt_timer(space->machine); |
| r6779 | r6780 | |
| 142 | 125 | } |
| 143 | 126 | |
| 144 | 127 | |
| 145 | | static void update_interrupts(running_machine *machine) |
| 128 | static void update_interrupts( running_machine *machine ) |
| 146 | 129 | { |
| 147 | | cputag_set_input_line(machine, "maincpu", 1, vblank_interrupt_pending ? ASSERT_LINE : CLEAR_LINE); |
| 148 | | cputag_set_input_line(machine, "maincpu", 2, display_position_interrupt_pending ? ASSERT_LINE : CLEAR_LINE); |
| 149 | | cputag_set_input_line(machine, "maincpu", 3, irq3_pending ? ASSERT_LINE : CLEAR_LINE); |
| 130 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 131 | |
| 132 | cputag_set_input_line(machine, "maincpu", 1, state->vblank_interrupt_pending ? ASSERT_LINE : CLEAR_LINE); |
| 133 | cputag_set_input_line(machine, "maincpu", 2, state->display_position_interrupt_pending ? ASSERT_LINE : CLEAR_LINE); |
| 134 | cputag_set_input_line(machine, "maincpu", 3, state->irq3_pending ? ASSERT_LINE : CLEAR_LINE); |
| 150 | 135 | } |
| 151 | 136 | |
| 152 | 137 | |
| 153 | | void neogeo_acknowledge_interrupt(running_machine *machine, UINT16 data) |
| 138 | void neogeo_acknowledge_interrupt( running_machine *machine, UINT16 data ) |
| 154 | 139 | { |
| 155 | | if (data & 0x01) irq3_pending = 0; |
| 156 | | if (data & 0x02) display_position_interrupt_pending = 0; |
| 157 | | if (data & 0x04) vblank_interrupt_pending = 0; |
| 140 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 158 | 141 | |
| 142 | if (data & 0x01) |
| 143 | state->irq3_pending = 0; |
| 144 | if (data & 0x02) |
| 145 | state->display_position_interrupt_pending = 0; |
| 146 | if (data & 0x04) |
| 147 | state->vblank_interrupt_pending = 0; |
| 148 | |
| 159 | 149 | update_interrupts(machine); |
| 160 | 150 | } |
| 161 | 151 | |
| 162 | 152 | |
| 163 | 153 | static TIMER_CALLBACK( display_position_interrupt_callback ) |
| 164 | 154 | { |
| 155 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 156 | |
| 165 | 157 | if (LOG_VIDEO_SYSTEM) logerror("--- Scanline @ %d,%d\n", video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen)); |
| 166 | | if (display_position_interrupt_control & IRQ2CTRL_ENABLE) |
| 158 | |
| 159 | if (state->display_position_interrupt_control & IRQ2CTRL_ENABLE) |
| 167 | 160 | { |
| 168 | 161 | if (LOG_VIDEO_SYSTEM) logerror("*** Scanline interrupt (IRQ2) *** y: %02x x: %02x\n", video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen)); |
| 169 | | display_position_interrupt_pending = 1; |
| 162 | state->display_position_interrupt_pending = 1; |
| 170 | 163 | |
| 171 | 164 | update_interrupts(machine); |
| 172 | 165 | } |
| 173 | 166 | |
| 174 | | if (display_position_interrupt_control & IRQ2CTRL_AUTOLOAD_REPEAT) |
| 167 | if (state->display_position_interrupt_control & IRQ2CTRL_AUTOLOAD_REPEAT) |
| 175 | 168 | { |
| 176 | 169 | if (LOG_VIDEO_SYSTEM) logerror("AUTOLOAD_REPEAT "); |
| 177 | 170 | adjust_display_position_interrupt_timer(machine); |
| r6779 | r6780 | |
| 181 | 174 | |
| 182 | 175 | static TIMER_CALLBACK( display_position_vblank_callback ) |
| 183 | 176 | { |
| 184 | | if (display_position_interrupt_control & IRQ2CTRL_AUTOLOAD_VBLANK) |
| 177 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 178 | |
| 179 | if (state->display_position_interrupt_control & IRQ2CTRL_AUTOLOAD_VBLANK) |
| 185 | 180 | { |
| 186 | 181 | if (LOG_VIDEO_SYSTEM) logerror("AUTOLOAD_VBLANK "); |
| 187 | 182 | adjust_display_position_interrupt_timer(machine); |
| 188 | 183 | } |
| 189 | 184 | |
| 190 | 185 | /* set timer for next screen */ |
| 191 | | timer_adjust_oneshot(display_position_vblank_timer, video_screen_get_time_until_pos(machine->primary_screen, NEOGEO_VBSTART, NEOGEO_VBLANK_RELOAD_HPOS), 0); |
| 186 | timer_adjust_oneshot(state->display_position_vblank_timer, video_screen_get_time_until_pos(machine->primary_screen, NEOGEO_VBSTART, NEOGEO_VBLANK_RELOAD_HPOS), 0); |
| 192 | 187 | } |
| 193 | 188 | |
| 194 | 189 | |
| 195 | 190 | static TIMER_CALLBACK( vblank_interrupt_callback ) |
| 196 | 191 | { |
| 197 | | const device_config *upd4990a = devtag_get_device(machine, "upd4990a"); |
| 192 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 198 | 193 | |
| 199 | 194 | if (LOG_VIDEO_SYSTEM) logerror("+++ VBLANK @ %d,%d\n", video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen)); |
| 200 | 195 | |
| 201 | 196 | /* add a timer tick to the pd4990a */ |
| 202 | | upd4990a_addretrace(upd4990a); |
| 197 | upd4990a_addretrace(state->upd4990a); |
| 203 | 198 | |
| 204 | | vblank_interrupt_pending = 1; |
| 199 | state->vblank_interrupt_pending = 1; |
| 205 | 200 | |
| 206 | 201 | update_interrupts(machine); |
| 207 | 202 | |
| 208 | 203 | /* set timer for next screen */ |
| 209 | | timer_adjust_oneshot(vblank_interrupt_timer, video_screen_get_time_until_pos(machine->primary_screen, NEOGEO_VBSTART, 0), 0); |
| 204 | timer_adjust_oneshot(state->vblank_interrupt_timer, video_screen_get_time_until_pos(machine->primary_screen, NEOGEO_VBSTART, 0), 0); |
| 210 | 205 | } |
| 211 | 206 | |
| 212 | 207 | |
| 213 | | static void create_interrupt_timers(running_machine *machine) |
| 208 | static void create_interrupt_timers( running_machine *machine ) |
| 214 | 209 | { |
| 215 | | display_position_interrupt_timer = timer_alloc(machine, display_position_interrupt_callback, NULL); |
| 216 | | display_position_vblank_timer = timer_alloc(machine, display_position_vblank_callback, NULL); |
| 217 | | vblank_interrupt_timer = timer_alloc(machine, vblank_interrupt_callback, NULL); |
| 210 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 211 | state->display_position_interrupt_timer = timer_alloc(machine, display_position_interrupt_callback, NULL); |
| 212 | state->display_position_vblank_timer = timer_alloc(machine, display_position_vblank_callback, NULL); |
| 213 | state->vblank_interrupt_timer = timer_alloc(machine, vblank_interrupt_callback, NULL); |
| 218 | 214 | } |
| 219 | 215 | |
| 220 | 216 | |
| 221 | | static void start_interrupt_timers(running_machine *machine) |
| 217 | static void start_interrupt_timers( running_machine *machine ) |
| 222 | 218 | { |
| 223 | | timer_adjust_oneshot(vblank_interrupt_timer, video_screen_get_time_until_pos(machine->primary_screen, NEOGEO_VBSTART, 0), 0); |
| 224 | | timer_adjust_oneshot(display_position_vblank_timer, video_screen_get_time_until_pos(machine->primary_screen, NEOGEO_VBSTART, NEOGEO_VBLANK_RELOAD_HPOS), 0); |
| 219 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 220 | timer_adjust_oneshot(state->vblank_interrupt_timer, video_screen_get_time_until_pos(machine->primary_screen, NEOGEO_VBSTART, 0), 0); |
| 221 | timer_adjust_oneshot(state->display_position_vblank_timer, video_screen_get_time_until_pos(machine->primary_screen, NEOGEO_VBSTART, NEOGEO_VBLANK_RELOAD_HPOS), 0); |
| 225 | 222 | } |
| 226 | 223 | |
| 227 | 224 | |
| r6779 | r6780 | |
| 234 | 231 | |
| 235 | 232 | static void audio_cpu_irq(const device_config *device, int assert) |
| 236 | 233 | { |
| 237 | | cputag_set_input_line(device->machine, "audiocpu", 0, assert ? ASSERT_LINE : CLEAR_LINE); |
| 234 | neogeo_state *state = (neogeo_state *)device->machine->driver_data; |
| 235 | cpu_set_input_line(state->audiocpu, 0, assert ? ASSERT_LINE : CLEAR_LINE); |
| 238 | 236 | } |
| 239 | 237 | |
| 240 | 238 | |
| 241 | 239 | static void audio_cpu_assert_nmi(running_machine *machine) |
| 242 | 240 | { |
| 243 | | cputag_set_input_line(machine, "audiocpu", INPUT_LINE_NMI, ASSERT_LINE); |
| 241 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 242 | cpu_set_input_line(state->audiocpu, INPUT_LINE_NMI, ASSERT_LINE); |
| 244 | 243 | } |
| 245 | 244 | |
| 246 | 245 | |
| 247 | 246 | static WRITE8_HANDLER( audio_cpu_clear_nmi_w ) |
| 248 | 247 | { |
| 249 | | cputag_set_input_line(space->machine, "audiocpu", INPUT_LINE_NMI, CLEAR_LINE); |
| 248 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 249 | cpu_set_input_line(state->audiocpu, INPUT_LINE_NMI, CLEAR_LINE); |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
| r6779 | r6780 | |
| 257 | 257 | * |
| 258 | 258 | *************************************/ |
| 259 | 259 | |
| 260 | | static void select_controller(UINT8 data) |
| 260 | static void select_controller( running_machine *machine, UINT8 data ) |
| 261 | 261 | { |
| 262 | | controller_select = data; |
| 262 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 263 | state->controller_select = data; |
| 263 | 264 | } |
| 264 | 265 | |
| 265 | 266 | |
| r6779 | r6780 | |
| 305 | 306 | |
| 306 | 307 | static WRITE16_HANDLER( io_control_w ) |
| 307 | 308 | { |
| 308 | | const device_config *upd4990a = devtag_get_device(space->machine, "upd4990a"); |
| 309 | | |
| 309 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 310 | 310 | switch (offset) |
| 311 | 311 | { |
| 312 | | case 0x00: select_controller(data & 0x00ff); break; |
| 313 | | // case 0x18: set_output_latch(space->machine, data & 0x00ff); break; |
| 314 | | // case 0x20: set_output_data(data & 0x00ff); break; |
| 315 | | case 0x28: upd4990a_control_16_w(upd4990a, 0, data, mem_mask); break; |
| 312 | case 0x00: select_controller(space->machine, data & 0x00ff); break; |
| 313 | // case 0x18: set_output_latch(space->machine, data & 0x00ff); break; |
| 314 | // case 0x20: set_output_data(space->machine, data & 0x00ff); break; |
| 315 | case 0x28: upd4990a_control_16_w(state->upd4990a, 0, data, mem_mask); break; |
| 316 | 316 | // case 0x30: break; // coin counters |
| 317 | 317 | // case 0x31: break; // coin counters |
| 318 | 318 | // case 0x32: break; // coin lockout |
| r6779 | r6780 | |
| 334 | 334 | |
| 335 | 335 | READ16_HANDLER( neogeo_unmapped_r ) |
| 336 | 336 | { |
| 337 | | static UINT8 recurse = 0; |
| 337 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 338 | 338 | UINT16 ret; |
| 339 | 339 | |
| 340 | 340 | /* unmapped memory returns the last word on the data bus, which is almost always the opcode |
| 341 | 341 | of the next instruction due to prefetch */ |
| 342 | 342 | |
| 343 | 343 | /* prevent recursion */ |
| 344 | | if (recurse) |
| 344 | if (state->recurse) |
| 345 | 345 | ret = 0xffff; |
| 346 | 346 | else |
| 347 | 347 | { |
| 348 | | recurse = 1; |
| 348 | state->recurse = 1; |
| 349 | 349 | ret = memory_read_word(space, cpu_get_pc(space->cpu)); |
| 350 | | recurse = 0; |
| 350 | state->recurse = 0; |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | return ret; |
| r6779 | r6780 | |
| 355 | 355 | |
| 356 | 356 | |
| 357 | 357 | |
| 358 | |
| 358 | 359 | /************************************* |
| 359 | 360 | * |
| 360 | 361 | * uPD4990A calendar chip |
| r6779 | r6780 | |
| 388 | 389 | |
| 389 | 390 | static CUSTOM_INPUT( get_calendar_status ) |
| 390 | 391 | { |
| 391 | | const device_config *upd4990a = devtag_get_device(field->port->machine, "upd4990a"); |
| 392 | | return (upd4990a_databit_r(upd4990a, 0) << 1) | upd4990a_testbit_r(upd4990a, 0); |
| 392 | neogeo_state *state = (neogeo_state *)field->port->machine->driver_data; |
| 393 | return (upd4990a_databit_r(state->upd4990a, 0) << 1) | upd4990a_testbit_r(state->upd4990a, 0); |
| 393 | 394 | } |
| 394 | 395 | |
| 395 | 396 | |
| r6779 | r6780 | |
| 416 | 417 | } |
| 417 | 418 | |
| 418 | 419 | |
| 419 | | static void set_save_ram_unlock(UINT8 data) |
| 420 | static void set_save_ram_unlock( running_machine *machine, UINT8 data ) |
| 420 | 421 | { |
| 421 | | save_ram_unlocked = data; |
| 422 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 423 | state->save_ram_unlocked = data; |
| 422 | 424 | } |
| 423 | 425 | |
| 424 | 426 | |
| 425 | 427 | static WRITE16_HANDLER( save_ram_w ) |
| 426 | 428 | { |
| 427 | | if (save_ram_unlocked) |
| 429 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 430 | |
| 431 | if (state->save_ram_unlocked) |
| 428 | 432 | COMBINE_DATA(&save_ram[offset]); |
| 429 | 433 | } |
| 430 | 434 | |
| r6779 | r6780 | |
| 529 | 533 | |
| 530 | 534 | static WRITE8_HANDLER( audio_result_w ) |
| 531 | 535 | { |
| 532 | | if (LOG_CPU_COMM && (audio_result != data)) logerror(" AUD CPU PC %04x: audio_result_w %02x\n", cpu_get_pc(space->cpu), data); |
| 536 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 533 | 537 | |
| 534 | | audio_result = data; |
| 538 | if (LOG_CPU_COMM && (state->audio_result != data)) logerror(" AUD CPU PC %04x: audio_result_w %02x\n", cpu_get_pc(space->cpu), data); |
| 539 | |
| 540 | state->audio_result = data; |
| 535 | 541 | } |
| 536 | 542 | |
| 537 | 543 | |
| 538 | 544 | static CUSTOM_INPUT( get_audio_result ) |
| 539 | 545 | { |
| 540 | | UINT32 ret = audio_result; |
| 546 | neogeo_state *state = (neogeo_state *)field->port->machine->driver_data; |
| 547 | UINT32 ret = state->audio_result; |
| 541 | 548 | |
| 542 | 549 | // if (LOG_CPU_COMM) logerror("MAIN CPU PC %06x: audio_result_r %02x\n", cpu_get_pc(cputag_get_cpu(field->port->machine, "maincpu")), ret); |
| 543 | 550 | |
| r6779 | r6780 | |
| 552 | 559 | * |
| 553 | 560 | *************************************/ |
| 554 | 561 | |
| 555 | | static void _set_main_cpu_vector_table_source(running_machine *machine) |
| 562 | static void _set_main_cpu_vector_table_source( running_machine *machine ) |
| 556 | 563 | { |
| 557 | | memory_set_bank(machine, NEOGEO_BANK_VECTORS, main_cpu_vector_table_source); |
| 564 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 565 | memory_set_bank(machine, NEOGEO_BANK_VECTORS, state->main_cpu_vector_table_source); |
| 558 | 566 | } |
| 559 | 567 | |
| 560 | 568 | |
| 561 | | static void set_main_cpu_vector_table_source(running_machine *machine, UINT8 data) |
| 569 | static void set_main_cpu_vector_table_source( running_machine *machine, UINT8 data ) |
| 562 | 570 | { |
| 563 | | main_cpu_vector_table_source = data; |
| 571 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 572 | state->main_cpu_vector_table_source = data; |
| 564 | 573 | |
| 565 | 574 | _set_main_cpu_vector_table_source(machine); |
| 566 | 575 | } |
| 567 | 576 | |
| 568 | 577 | |
| 569 | | static void _set_main_cpu_bank_address(running_machine *machine) |
| 578 | static void _set_main_cpu_bank_address( running_machine *machine ) |
| 570 | 579 | { |
| 571 | | memory_set_bankptr(machine, NEOGEO_BANK_CARTRIDGE, &memory_region(machine, "maincpu")[main_cpu_bank_address]); |
| 580 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 581 | memory_set_bankptr(machine, NEOGEO_BANK_CARTRIDGE, &memory_region(machine, "maincpu")[state->main_cpu_bank_address]); |
| 572 | 582 | } |
| 573 | 583 | |
| 574 | 584 | |
| 575 | | void neogeo_set_main_cpu_bank_address(const address_space *space, UINT32 bank_address) |
| 585 | void neogeo_set_main_cpu_bank_address( const address_space *space, UINT32 bank_address ) |
| 576 | 586 | { |
| 587 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 588 | |
| 577 | 589 | if (LOG_MAIN_CPU_BANKING) logerror("MAIN CPU PC %06x: neogeo_set_main_cpu_bank_address %06x\n", cpu_get_pc(space->cpu), bank_address); |
| 578 | 590 | |
| 579 | | main_cpu_bank_address = bank_address; |
| 591 | state->main_cpu_bank_address = bank_address; |
| 580 | 592 | |
| 581 | 593 | _set_main_cpu_bank_address(space->machine); |
| 582 | 594 | } |
| r6779 | r6780 | |
| 604 | 616 | } |
| 605 | 617 | |
| 606 | 618 | |
| 607 | | static void main_cpu_banking_init(running_machine *machine) |
| 619 | static void main_cpu_banking_init( running_machine *machine ) |
| 608 | 620 | { |
| 609 | 621 | const address_space *mainspace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 610 | 622 | |
| r6779 | r6780 | |
| 627 | 639 | * |
| 628 | 640 | *************************************/ |
| 629 | 641 | |
| 630 | | static void set_audio_cpu_banking(running_machine *machine) |
| 642 | static void set_audio_cpu_banking( running_machine *machine ) |
| 631 | 643 | { |
| 644 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 632 | 645 | int region; |
| 633 | 646 | |
| 634 | 647 | for (region = 0; region < 4; region++) |
| 635 | | memory_set_bank(machine, NEOGEO_BANK_AUDIO_CPU_CART_BANK + region, audio_cpu_banks[region]); |
| 648 | memory_set_bank(machine, NEOGEO_BANK_AUDIO_CPU_CART_BANK + region, state->audio_cpu_banks[region]); |
| 636 | 649 | } |
| 637 | 650 | |
| 638 | 651 | |
| 639 | | static void audio_cpu_bank_select(const address_space *space, int region, UINT8 bank) |
| 652 | static void audio_cpu_bank_select( const address_space *space, int region, UINT8 bank ) |
| 640 | 653 | { |
| 654 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 655 | |
| 641 | 656 | if (LOG_AUDIO_CPU_BANKING) logerror("Audio CPU PC %03x: audio_cpu_bank_select: Region: %d Bank: %02x\n", cpu_get_pc(space->cpu), region, bank); |
| 642 | 657 | |
| 643 | | audio_cpu_banks[region] = bank; |
| 658 | state->audio_cpu_banks[region] = bank; |
| 644 | 659 | |
| 645 | 660 | set_audio_cpu_banking(space->machine); |
| 646 | 661 | } |
| r6779 | r6780 | |
| 678 | 693 | } |
| 679 | 694 | |
| 680 | 695 | |
| 681 | | static void _set_audio_cpu_rom_source(const address_space *space) |
| 696 | static void _set_audio_cpu_rom_source( const address_space *space ) |
| 682 | 697 | { |
| 698 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 699 | |
| 683 | 700 | /* if (!memory_region(machine, "audiobios")) */ |
| 684 | | audio_cpu_rom_source = 1; |
| 701 | state->audio_cpu_rom_source = 1; |
| 685 | 702 | |
| 686 | | memory_set_bank(space->machine, NEOGEO_BANK_AUDIO_CPU_MAIN_BANK, audio_cpu_rom_source); |
| 703 | memory_set_bank(space->machine, NEOGEO_BANK_AUDIO_CPU_MAIN_BANK, state->audio_cpu_rom_source); |
| 687 | 704 | |
| 688 | 705 | /* reset CPU if the source changed -- this is a guess */ |
| 689 | | if (audio_cpu_rom_source != audio_cpu_rom_source_last) |
| 706 | if (state->audio_cpu_rom_source != state->audio_cpu_rom_source_last) |
| 690 | 707 | { |
| 691 | | audio_cpu_rom_source_last = audio_cpu_rom_source; |
| 708 | state->audio_cpu_rom_source_last = state->audio_cpu_rom_source; |
| 692 | 709 | |
| 693 | 710 | cputag_set_input_line(space->machine, "audiocpu", INPUT_LINE_RESET, PULSE_LINE); |
| 694 | 711 | |
| 695 | | if (LOG_AUDIO_CPU_BANKING) logerror("Audio CPU PC %03x: selectign %s ROM\n", cpu_get_pc(space->cpu), audio_cpu_rom_source ? "CARTRIDGE" : "BIOS"); |
| 712 | if (LOG_AUDIO_CPU_BANKING) logerror("Audio CPU PC %03x: selectign %s ROM\n", cpu_get_pc(space->cpu), state->audio_cpu_rom_source ? "CARTRIDGE" : "BIOS"); |
| 696 | 713 | } |
| 697 | 714 | } |
| 698 | 715 | |
| 699 | 716 | |
| 700 | | static void set_audio_cpu_rom_source(const address_space *space, UINT8 data) |
| 717 | static void set_audio_cpu_rom_source( const address_space *space, UINT8 data ) |
| 701 | 718 | { |
| 702 | | audio_cpu_rom_source = data; |
| 719 | neogeo_state *state = (neogeo_state *)space->machine->driver_data; |
| 720 | state->audio_cpu_rom_source = data; |
| 703 | 721 | |
| 704 | 722 | _set_audio_cpu_rom_source(space); |
| 705 | 723 | } |
| 706 | 724 | |
| 707 | 725 | |
| 708 | | static void audio_cpu_banking_init(running_machine *machine) |
| 726 | static void audio_cpu_banking_init( running_machine *machine ) |
| 709 | 727 | { |
| 728 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 710 | 729 | int region; |
| 711 | 730 | int bank; |
| 712 | 731 | UINT8 *rgn; |
| r6779 | r6780 | |
| 732 | 751 | |
| 733 | 752 | /* set initial audio banks -- |
| 734 | 753 | how does this really work, or is it even neccessary? */ |
| 735 | | audio_cpu_banks[0] = 0x1e; |
| 736 | | audio_cpu_banks[1] = 0x0e; |
| 737 | | audio_cpu_banks[2] = 0x06; |
| 738 | | audio_cpu_banks[3] = 0x02; |
| 754 | state->audio_cpu_banks[0] = 0x1e; |
| 755 | state->audio_cpu_banks[1] = 0x0e; |
| 756 | state->audio_cpu_banks[2] = 0x06; |
| 757 | state->audio_cpu_banks[3] = 0x02; |
| 739 | 758 | |
| 740 | 759 | set_audio_cpu_banking(machine); |
| 741 | 760 | |
| 742 | | audio_cpu_rom_source_last = 0; |
| 761 | state->audio_cpu_rom_source_last = 0; |
| 743 | 762 | set_audio_cpu_rom_source(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0); |
| 744 | 763 | } |
| 745 | 764 | |
| r6779 | r6780 | |
| 764 | 783 | case 0x01: set_main_cpu_vector_table_source(space->machine, bit); |
| 765 | 784 | set_audio_cpu_rom_source(space, bit); /* this is a guess */ |
| 766 | 785 | break; |
| 767 | | case 0x05: neogeo_set_fixed_layer_source(space->machine,bit); break; |
| 768 | | case 0x06: set_save_ram_unlock(bit); break; |
| 786 | case 0x05: neogeo_set_fixed_layer_source(space->machine, bit); break; |
| 787 | case 0x06: set_save_ram_unlock(space->machine, bit); break; |
| 769 | 788 | case 0x07: neogeo_set_palette_bank(space->machine, bit); break; |
| 770 | 789 | |
| 771 | 790 | case 0x02: /* unknown - HC32 middle pin 1 */ |
| r6779 | r6780 | |
| 795 | 814 | |
| 796 | 815 | static MACHINE_START( neogeo ) |
| 797 | 816 | { |
| 817 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 818 | |
| 798 | 819 | /* set the BIOS bank */ |
| 799 | 820 | memory_set_bankptr(machine, NEOGEO_BANK_BIOS, memory_region(machine, "mainbios")); |
| 800 | 821 | |
| r6779 | r6780 | |
| 806 | 827 | |
| 807 | 828 | create_interrupt_timers(machine); |
| 808 | 829 | |
| 809 | | /* initialize the celander IC to 'right now' */ |
| 810 | | // calendar_init(machine); |
| 811 | | |
| 812 | 830 | /* initialize the memcard data structure */ |
| 813 | 831 | memcard_data = auto_alloc_array_clear(machine, UINT8, MEMCARD_SIZE); |
| 814 | 832 | |
| 815 | 833 | /* start with an IRQ3 - but NOT on a reset */ |
| 816 | | irq3_pending = 1; |
| 834 | state->irq3_pending = 1; |
| 817 | 835 | |
| 836 | /* get devices */ |
| 837 | state->maincpu = devtag_get_device(machine, "maincpu"); |
| 838 | state->audiocpu = devtag_get_device(machine, "audiocpu"); |
| 839 | state->upd4990a = devtag_get_device(machine, "upd4990a"); |
| 840 | |
| 818 | 841 | /* register state save */ |
| 819 | | state_save_register_global(machine, display_position_interrupt_control); |
| 820 | | state_save_register_global(machine, display_counter); |
| 821 | | state_save_register_global(machine, vblank_interrupt_pending); |
| 822 | | state_save_register_global(machine, display_position_interrupt_pending); |
| 823 | | state_save_register_global(machine, irq3_pending); |
| 824 | | state_save_register_global(machine, audio_result); |
| 825 | | state_save_register_global(machine, controller_select); |
| 826 | | state_save_register_global(machine, main_cpu_bank_address); |
| 827 | | state_save_register_global(machine, main_cpu_vector_table_source); |
| 828 | | state_save_register_global_array(machine, audio_cpu_banks); |
| 829 | | state_save_register_global(machine, audio_cpu_rom_source); |
| 830 | | state_save_register_global(machine, audio_cpu_rom_source_last); |
| 831 | | state_save_register_global(machine, save_ram_unlocked); |
| 842 | state_save_register_global(machine, state->display_position_interrupt_control); |
| 843 | state_save_register_global(machine, state->display_counter); |
| 844 | state_save_register_global(machine, state->vblank_interrupt_pending); |
| 845 | state_save_register_global(machine, state->display_position_interrupt_pending); |
| 846 | state_save_register_global(machine, state->irq3_pending); |
| 847 | state_save_register_global(machine, state->audio_result); |
| 848 | state_save_register_global(machine, state->controller_select); |
| 849 | state_save_register_global(machine, state->main_cpu_bank_address); |
| 850 | state_save_register_global(machine, state->main_cpu_vector_table_source); |
| 851 | state_save_register_global_array(machine, state->audio_cpu_banks); |
| 852 | state_save_register_global(machine, state->audio_cpu_rom_source); |
| 853 | state_save_register_global(machine, state->audio_cpu_rom_source_last); |
| 854 | state_save_register_global(machine, state->save_ram_unlocked); |
| 832 | 855 | state_save_register_global_pointer(machine, memcard_data, 0x800); |
| 833 | | state_save_register_global(machine, output_data); |
| 834 | | state_save_register_global(machine, output_latch); |
| 835 | | state_save_register_global(machine, el_value); |
| 856 | state_save_register_global(machine, state->output_data); |
| 857 | state_save_register_global(machine, state->output_latch); |
| 858 | state_save_register_global(machine, state->el_value); |
| 859 | state_save_register_global(machine, state->led1_value); |
| 860 | state_save_register_global(machine, state->led2_value); |
| 861 | state_save_register_global(machine, state->recurse); |
| 836 | 862 | |
| 837 | 863 | state_save_register_postload(machine, aes_postload, NULL); |
| 838 | 864 | } |
| r6779 | r6780 | |
| 847 | 873 | |
| 848 | 874 | static MACHINE_RESET( neogeo ) |
| 849 | 875 | { |
| 876 | neogeo_state *state = (neogeo_state *)machine->driver_data; |
| 850 | 877 | offs_t offs; |
| 851 | 878 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 852 | 879 | |
| 853 | 880 | /* reset system control registers */ |
| 854 | 881 | for (offs = 0; offs < 8; offs++) |
| 855 | 882 | system_control_w(space, offs, 0, 0x00ff); |
| 883 | |
| 856 | 884 | device_reset(cputag_get_cpu(machine, "maincpu")); |
| 857 | 885 | |
| 858 | 886 | neogeo_reset_rng(machine); |
| r6779 | r6780 | |
| 862 | 890 | /* trigger the IRQ3 that was set by MACHINE_START */ |
| 863 | 891 | update_interrupts(machine); |
| 864 | 892 | |
| 893 | state->recurse = 0; |
| 894 | |
| 865 | 895 | /* AES apparently always uses the cartridge's fixed bank mode */ |
| 866 | 896 | neogeo_set_fixed_layer_source(machine,1); |
| 867 | 897 | } |
| r6779 | r6780 | |
| 1196 | 1226 | |
| 1197 | 1227 | static MACHINE_DRIVER_START( neogeo ) |
| 1198 | 1228 | |
| 1229 | /* driver data */ |
| 1230 | MDRV_DRIVER_DATA(neogeo_state) |
| 1231 | |
| 1199 | 1232 | /* basic machine hardware */ |
| 1200 | 1233 | MDRV_CPU_ADD("maincpu", M68000, NEOGEO_MAIN_CPU_CLOCK) |
| 1201 | 1234 | MDRV_CPU_PROGRAM_MAP(main_map) |
| r6779 | r6780 | |
| 1213 | 1246 | MDRV_VIDEO_START(neogeo) |
| 1214 | 1247 | MDRV_VIDEO_RESET(neogeo) |
| 1215 | 1248 | MDRV_VIDEO_UPDATE(neogeo) |
| 1249 | MDRV_DEFAULT_LAYOUT(layout_neogeo) |
| 1216 | 1250 | |
| 1217 | 1251 | MDRV_SCREEN_ADD("screen", RASTER) |
| 1218 | 1252 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| r6779 | r6780 | |
| 1241 | 1275 | * |
| 1242 | 1276 | * Driver initalization |
| 1243 | 1277 | * |
| 1244 | | ? *************************************/ |
| 1278 | *************************************/ |
| 1245 | 1279 | |
| 1246 | 1280 | static DRIVER_INIT( neogeo ) |
| 1247 | 1281 | { |