src/mess/machine/sms.c
| r3671 | r3672 | |
| 76 | 76 | static WRITE8_HANDLER( sms_input_write ) { |
| 77 | 77 | switch( offset ) { |
| 78 | 78 | case 0: |
| 79 | | switch( input_port_read(machine, "CTRLSEL") & 0x0F ) { |
| 79 | switch( input_port_read(space->machine, "CTRLSEL") & 0x0F ) { |
| 80 | 80 | case 0x03: /* Sports Pad */ |
| 81 | 81 | if ( data != sports_pad_last_data_1 ) { |
| 82 | | UINT32 cpu_cycles = activecpu_gettotalcycles(); |
| 82 | UINT32 cpu_cycles = cpu_get_total_cycles(space->cpu); |
| 83 | 83 | |
| 84 | 84 | sports_pad_last_data_1 = data; |
| 85 | 85 | if ( cpu_cycles - last_sports_pad_time_1 > 512 ) { |
| 86 | 86 | sports_pad_state_1 = 3; |
| 87 | | sports_pad_1_x = input_port_read(machine, "SPORT0"); |
| 88 | | sports_pad_1_y = input_port_read(machine, "SPORT1"); |
| 87 | sports_pad_1_x = input_port_read(space->machine, "SPORT0"); |
| 88 | sports_pad_1_y = input_port_read(space->machine, "SPORT1"); |
| 89 | 89 | } |
| 90 | 90 | last_sports_pad_time_1 = cpu_cycles; |
| 91 | 91 | sports_pad_state_1 = ( sports_pad_state_1 + 1 ) & 3; |
| r3671 | r3672 | |
| 94 | 94 | } |
| 95 | 95 | break; |
| 96 | 96 | case 1: |
| 97 | | switch( input_port_read(machine, "CTRLSEL") >> 4 ) { |
| 97 | switch( input_port_read(space->machine, "CTRLSEL") >> 4 ) { |
| 98 | 98 | case 0x03: /* Sports Pad */ |
| 99 | 99 | if ( data != sports_pad_last_data_2 ) { |
| 100 | | UINT32 cpu_cycles = activecpu_gettotalcycles(); |
| 100 | UINT32 cpu_cycles = cpu_get_total_cycles(space->cpu); |
| 101 | 101 | |
| 102 | 102 | sports_pad_last_data_2 = data; |
| 103 | 103 | if ( cpu_cycles - last_sports_pad_time_2 > 2048 ) { |
| 104 | 104 | sports_pad_state_2 = 3; |
| 105 | | sports_pad_2_x = input_port_read(machine, "SPORT2"); |
| 106 | | sports_pad_2_y = input_port_read(machine, "SPORT3"); |
| 105 | sports_pad_2_x = input_port_read(space->machine, "SPORT2"); |
| 106 | sports_pad_2_y = input_port_read(space->machine, "SPORT3"); |
| 107 | 107 | } |
| 108 | 108 | last_sports_pad_time_2 = cpu_cycles; |
| 109 | 109 | sports_pad_state_2 = ( sports_pad_state_2 + 1 ) & 3; |
| r3671 | r3672 | |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | | static void sms_get_inputs(running_machine *machine) { |
| 117 | static void sms_get_inputs(const address_space *space) { |
| 118 | 118 | UINT8 data = 0x00; |
| 119 | | UINT32 cpu_cycles = activecpu_gettotalcycles(); |
| 119 | UINT32 cpu_cycles = cpu_get_total_cycles(space->cpu); |
| 120 | running_machine *machine = space->machine; |
| 120 | 121 | |
| 121 | 122 | sms_input_port0 = 0xFF; |
| 122 | 123 | sms_input_port1 = 0xFF; |
| r3671 | r3672 | |
| 229 | 230 | if ( biosPort & IO_CHIP ) { |
| 230 | 231 | return 0xFF; |
| 231 | 232 | } else { |
| 232 | | sms_get_inputs(machine); |
| 233 | sms_get_inputs(space); |
| 233 | 234 | return sms_input_port0; |
| 234 | 235 | } |
| 235 | 236 | } |
| r3671 | r3672 | |
| 240 | 241 | smsVersion = (data & 0xA0); |
| 241 | 242 | } |
| 242 | 243 | if ( data & 0x08 ) { |
| 243 | | sms_input_write( machine, 0, ( data & 0x20 ) >> 5 ); |
| 244 | sms_input_write( space, 0, ( data & 0x20 ) >> 5 ); |
| 244 | 245 | } |
| 245 | 246 | if ( data & 0x02 ) { |
| 246 | | sms_input_write( machine, 1, ( data & 0x80 ) >> 7 ); |
| 247 | sms_input_write( space, 1, ( data & 0x80 ) >> 7 ); |
| 247 | 248 | } |
| 248 | 249 | } |
| 249 | 250 | |
| r3671 | r3672 | |
| 263 | 264 | } |
| 264 | 265 | |
| 265 | 266 | /* Merge version data with input port #2 data */ |
| 266 | | sms_get_inputs(machine); |
| 267 | sms_get_inputs(space); |
| 267 | 268 | temp = (temp & 0xC0) | (sms_input_port1 & 0x3F); |
| 268 | 269 | |
| 269 | 270 | return (temp); |
| r3671 | r3672 | |
| 271 | 272 | |
| 272 | 273 | READ8_HANDLER(sms_count_r) { |
| 273 | 274 | if ( offset & 0x01 ) { |
| 274 | | return sms_vdp_hcount_r(machine, offset); |
| 275 | return sms_vdp_hcount_r(space, offset); |
| 275 | 276 | } else { |
| 276 | 277 | /* VCount read */ |
| 277 | | return sms_vdp_vcount_r(machine, offset); |
| 278 | return sms_vdp_vcount_r(space, offset); |
| 278 | 279 | } |
| 279 | 280 | } |
| 280 | 281 | |
| 281 | | void sms_check_pause_button( running_machine *machine ) { |
| 282 | void sms_check_pause_button(const address_space *space) { |
| 282 | 283 | if ( ! IS_GAMEGEAR ) { |
| 283 | | if ( ! (input_port_read(machine, "PAUSE") & 0x80) ) { |
| 284 | if ( ! (input_port_read(space->machine, "PAUSE") & 0x80) ) { |
| 284 | 285 | if ( ! smsPaused ) { |
| 285 | | cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, ASSERT_LINE ); |
| 286 | | cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, CLEAR_LINE ); |
| 286 | cpu_set_input_line(space->machine->cpu[0], INPUT_LINE_NMI, ASSERT_LINE ); |
| 287 | cpu_set_input_line(space->machine->cpu[0], INPUT_LINE_NMI, CLEAR_LINE ); |
| 287 | 288 | } |
| 288 | 289 | smsPaused = 1; |
| 289 | 290 | } else { |
| r3671 | r3672 | |
| 296 | 297 | if (biosPort & IO_CHIP) { |
| 297 | 298 | return (0xFF); |
| 298 | 299 | } else { |
| 299 | | sms_get_inputs(machine); |
| 300 | sms_get_inputs(space); |
| 300 | 301 | return sms_input_port0; |
| 301 | 302 | } |
| 302 | 303 | } |
| 303 | 304 | |
| 304 | 305 | WRITE8_HANDLER(sms_ym2413_register_port_0_w) { |
| 305 | 306 | if ( HAS_FM ) { |
| 306 | | ym2413_register_port_0_w(machine, offset, (data & 0x3F)); |
| 307 | ym2413_register_port_0_w(space, offset, (data & 0x3F)); |
| 307 | 308 | } |
| 308 | 309 | } |
| 309 | 310 | |
| 310 | 311 | WRITE8_HANDLER(sms_ym2413_data_port_0_w) { |
| 311 | 312 | if ( HAS_FM ) { |
| 312 | 313 | logerror("data_port_0_w %x %x\n", offset, data); |
| 313 | | ym2413_data_port_0_w(machine, offset, data); |
| 314 | ym2413_data_port_0_w(space, offset, data); |
| 314 | 315 | } |
| 315 | 316 | } |
| 316 | 317 | |
| 317 | 318 | READ8_HANDLER(gg_input_port_2_r) { |
| 318 | 319 | //logerror("joy 2 read, val: %02x, pc: %04x\n", (( IS_REGION_JAPAN ? 0x00 : 0x40) | (input_port_read(machine, "START") & 0x80)), activecpu_get_pc()); |
| 319 | | return (( IS_REGION_JAPAN ? 0x00 : 0x40 ) | (input_port_read(machine, "START") & 0x80)); |
| 320 | return (( IS_REGION_JAPAN ? 0x00 : 0x40 ) | (input_port_read(space->machine, "START") & 0x80)); |
| 320 | 321 | } |
| 321 | 322 | |
| 322 | 323 | READ8_HANDLER(sms_mapper_r) |
| r3671 | r3672 | |
| 383 | 384 | LOG(("ram 0 paged.\n")); |
| 384 | 385 | SOURCE = sms_cartridge[sms_current_cartridge].cartSRAM; |
| 385 | 386 | } |
| 386 | | memory_set_bankptr( 4, SOURCE ); |
| 387 | | memory_set_bankptr( 5, SOURCE + 0x2000 ); |
| 387 | memory_set_bankptr(space->machine, 4, SOURCE ); |
| 388 | memory_set_bankptr(space->machine, 5, SOURCE + 0x2000 ); |
| 388 | 389 | } else { /* it's rom */ |
| 389 | 390 | if ( biosPort & IO_BIOS_ROM || ! HAS_BIOS ) { |
| 390 | 391 | page = ( rom_page_count > 0) ? sms_mapper[3] % rom_page_count : 0; |
| r3671 | r3672 | |
| 394 | 395 | SOURCE = sms_banking_bios[4]; |
| 395 | 396 | } |
| 396 | 397 | LOG(("rom 2 paged in %x.\n", page)); |
| 397 | | memory_set_bankptr( 4, SOURCE ); |
| 398 | | memory_set_bankptr( 5, SOURCE + 0x2000 ); |
| 398 | memory_set_bankptr(space->machine, 4, SOURCE ); |
| 399 | memory_set_bankptr(space->machine, 5, SOURCE + 0x2000 ); |
| 399 | 400 | } |
| 400 | 401 | break; |
| 401 | 402 | case 1: /* Select 16k ROM bank for 0400-3FFF */ |
| r3671 | r3672 | |
| 405 | 406 | if ( IS_GAMEGEAR ) { |
| 406 | 407 | SOURCE = SOURCE_CART; |
| 407 | 408 | } |
| 408 | | memory_set_bankptr( 2, SOURCE + 0x0400 ); |
| 409 | memory_set_bankptr(space->machine, 2, SOURCE + 0x0400 ); |
| 409 | 410 | break; |
| 410 | 411 | case 2: /* Select 16k ROM bank for 4000-7FFF */ |
| 411 | 412 | LOG(("rom 1 paged in %x.\n", page)); |
| r3671 | r3672 | |
| 414 | 415 | if ( IS_GAMEGEAR ) { |
| 415 | 416 | SOURCE = SOURCE_CART; |
| 416 | 417 | } |
| 417 | | memory_set_bankptr( 3, SOURCE ); |
| 418 | memory_set_bankptr(space->machine, 3, SOURCE ); |
| 418 | 419 | break; |
| 419 | 420 | case 3: /* Select 16k ROM bank for 8000-BFFF */ |
| 420 | 421 | sms_banking_bios[4] = SOURCE_BIOS; |
| r3671 | r3672 | |
| 430 | 431 | } |
| 431 | 432 | if ( ! ( sms_mapper[0] & 0x08 ) ) { /* is RAM disabled? */ |
| 432 | 433 | LOG(("rom 2 paged in %x.\n", page)); |
| 433 | | memory_set_bankptr( 4, SOURCE ); |
| 434 | | memory_set_bankptr( 5, SOURCE + 0x2000 ); |
| 434 | memory_set_bankptr(space->machine, 4, SOURCE ); |
| 435 | memory_set_bankptr(space->machine, 5, SOURCE + 0x2000 ); |
| 435 | 436 | } |
| 436 | 437 | break; |
| 437 | 438 | } |
| r3671 | r3672 | |
| 442 | 443 | UINT8 rom_page_count = sms_cartridge[sms_current_cartridge].size / 0x4000; |
| 443 | 444 | sms_banking_cart[1] = sms_cartridge[sms_current_cartridge].ROM + ( ( rom_page_count > 0) ? data % rom_page_count : 0 ) * 0x4000; |
| 444 | 445 | sms_banking_cart[2] = sms_banking_cart[1] + 0x0400; |
| 445 | | memory_set_bankptr( 1, sms_banking_cart[1] ); |
| 446 | | memory_set_bankptr( 2, sms_banking_cart[2] ); |
| 446 | memory_set_bankptr(space->machine, 1, sms_banking_cart[1] ); |
| 447 | memory_set_bankptr(space->machine, 2, sms_banking_cart[2] ); |
| 447 | 448 | } |
| 448 | 449 | } |
| 449 | 450 | |
| r3671 | r3672 | |
| 452 | 453 | /* Check if we need to switch in some RAM */ |
| 453 | 454 | if ( data & 0x80 ) { |
| 454 | 455 | sms_cartridge[sms_current_cartridge].ram_page = data & 0x07; |
| 455 | | memory_set_bankptr( 5, sms_cartridge[sms_current_cartridge].cartRAM + sms_cartridge[sms_current_cartridge].ram_page * 0x2000 ); |
| 456 | memory_set_bankptr(space->machine, 5, sms_cartridge[sms_current_cartridge].cartRAM + sms_cartridge[sms_current_cartridge].ram_page * 0x2000 ); |
| 456 | 457 | } else { |
| 457 | 458 | UINT8 rom_page_count = sms_cartridge[sms_current_cartridge].size / 0x4000; |
| 458 | 459 | sms_banking_cart[3] = sms_cartridge[sms_current_cartridge].ROM + ( ( rom_page_count > 0) ? data % rom_page_count : 0 ) * 0x4000; |
| 459 | | memory_set_bankptr( 3, sms_banking_cart[3] ); |
| 460 | | memory_set_bankptr( 5, sms_banking_cart[4] + 0x2000 ); |
| 460 | memory_set_bankptr(space->machine, 3, sms_banking_cart[3] ); |
| 461 | memory_set_bankptr(space->machine, 5, sms_banking_cart[4] + 0x2000 ); |
| 461 | 462 | } |
| 462 | 463 | } |
| 463 | 464 | } |
| r3671 | r3672 | |
| 465 | 466 | WRITE8_HANDLER(sms_bios_w) { |
| 466 | 467 | biosPort = data; |
| 467 | 468 | |
| 468 | | logerror("bios write %02x, pc: %04x\n", data, activecpu_get_pc()); |
| 469 | logerror("bios write %02x, pc: %04x\n", data, cpu_get_pc(space->cpu)); |
| 469 | 470 | |
| 470 | | setup_rom(machine); |
| 471 | setup_rom(space); |
| 471 | 472 | } |
| 472 | 473 | |
| 473 | 474 | WRITE8_HANDLER(sms_cartram2_w) { |
| r3671 | r3672 | |
| 488 | 489 | if ( ! sms_cartridge[sms_current_cartridge].ROM ) |
| 489 | 490 | return; |
| 490 | 491 | sms_banking_cart[4] = sms_cartridge[sms_current_cartridge].ROM + page * 0x4000; |
| 491 | | memory_set_bankptr( 4, sms_banking_cart[4] ); |
| 492 | | memory_set_bankptr( 5, sms_banking_cart[4] + 0x2000 ); |
| 492 | memory_set_bankptr(space->machine, 4, sms_banking_cart[4] ); |
| 493 | memory_set_bankptr(space->machine, 5, sms_banking_cart[4] + 0x2000 ); |
| 493 | 494 | LOG(("rom 2 paged in %x dodgeball king.\n", page)); |
| 494 | 495 | } |
| 495 | 496 | } |
| r3671 | r3672 | |
| 511 | 512 | if ( ! sms_cartridge[sms_current_cartridge].ROM ) |
| 512 | 513 | return; |
| 513 | 514 | sms_banking_cart[4] = sms_cartridge[sms_current_cartridge].ROM + page * 0x4000; |
| 514 | | memory_set_bankptr( 4, sms_banking_cart[4] ); |
| 515 | | memory_set_bankptr( 5, sms_banking_cart[4] + 0x2000 ); |
| 515 | memory_set_bankptr(space->machine, 4, sms_banking_cart[4] ); |
| 516 | memory_set_bankptr(space->machine, 5, sms_banking_cart[4] + 0x2000 ); |
| 516 | 517 | LOG(("rom 2 paged in %x codemasters.\n", page)); |
| 517 | 518 | } else if ( sms_cartridge[sms_current_cartridge].features & CF_ONCART_RAM ) { |
| 518 | 519 | sms_cartridge[sms_current_cartridge].cartRAM[offset & ( sms_cartridge[sms_current_cartridge].ram_size - 1 ) ] = data; |
| r3671 | r3672 | |
| 584 | 585 | } |
| 585 | 586 | } |
| 586 | 587 | |
| 587 | | void setup_rom(running_machine *machine) |
| 588 | void setup_rom(const address_space *space) |
| 588 | 589 | { |
| 590 | running_machine *machine = space->machine; |
| 591 | |
| 589 | 592 | /* 1. set up bank pointers to point to nothing */ |
| 590 | | memory_set_bankptr( 1, sms_banking_none[1] ); |
| 591 | | memory_set_bankptr( 2, sms_banking_none[2] ); |
| 592 | | memory_set_bankptr( 3, sms_banking_none[3] ); |
| 593 | | memory_set_bankptr( 4, sms_banking_none[4] ); |
| 594 | | memory_set_bankptr( 5, sms_banking_none[4] + 0x2000 ); |
| 593 | memory_set_bankptr(machine, 1, sms_banking_none[1] ); |
| 594 | memory_set_bankptr(machine, 2, sms_banking_none[2] ); |
| 595 | memory_set_bankptr(machine, 3, sms_banking_none[3] ); |
| 596 | memory_set_bankptr(machine, 4, sms_banking_none[4] ); |
| 597 | memory_set_bankptr(machine, 5, sms_banking_none[4] + 0x2000 ); |
| 595 | 598 | |
| 596 | 599 | /* 2. check and set up expansion port */ |
| 597 | 600 | if (!(biosPort & IO_EXPANSION) && (biosPort & IO_CARTRIDGE) && (biosPort & IO_CARD)) { |
| r3671 | r3672 | |
| 609 | 612 | /* if ( ( !(biosPort & IO_CARTRIDGE) && (biosPort & IO_EXPANSION) && (biosPort & IO_CARD) ) || IS_GAMEGEAR ) { */ |
| 610 | 613 | /* Out Run Europa initially writes a value to port 3E where IO_CARTRIDGE, IO_EXPANSION and IO_CARD are reset */ |
| 611 | 614 | if ( ( ! ( biosPort & IO_CARTRIDGE ) ) || IS_GAMEGEAR ) { |
| 612 | | memory_set_bankptr( 1, sms_banking_cart[1] ); |
| 613 | | memory_set_bankptr( 2, sms_banking_cart[2] ); |
| 614 | | memory_set_bankptr( 3, sms_banking_cart[3] ); |
| 615 | | memory_set_bankptr( 4, sms_banking_cart[4] ); |
| 616 | | memory_set_bankptr( 5, sms_banking_cart[4] + 0x2000 ); |
| 615 | memory_set_bankptr(machine, 1, sms_banking_cart[1] ); |
| 616 | memory_set_bankptr(machine, 2, sms_banking_cart[2] ); |
| 617 | memory_set_bankptr(machine, 3, sms_banking_cart[3] ); |
| 618 | memory_set_bankptr(machine, 4, sms_banking_cart[4] ); |
| 619 | memory_set_bankptr(machine, 5, sms_banking_cart[4] + 0x2000 ); |
| 617 | 620 | logerror( "Switched in cartridge rom.\n" ); |
| 618 | 621 | } |
| 619 | 622 | |
| r3671 | r3672 | |
| 621 | 624 | if ( !(biosPort & IO_BIOS_ROM) ) { |
| 622 | 625 | /* 0x0400 bioses */ |
| 623 | 626 | if ( HAS_BIOS_0400 ) { |
| 624 | | memory_set_bankptr( 1, sms_banking_bios[1] ); |
| 627 | memory_set_bankptr(machine, 1, sms_banking_bios[1] ); |
| 625 | 628 | logerror( "Switched in 0x0400 bios.\n" ); |
| 626 | 629 | } |
| 627 | 630 | /* 0x2000 bioses */ |
| 628 | 631 | if ( HAS_BIOS_2000 ) { |
| 629 | | memory_set_bankptr( 1, sms_banking_bios[1] ); |
| 630 | | memory_set_bankptr( 2, sms_banking_bios[2] ); |
| 632 | memory_set_bankptr(machine, 1, sms_banking_bios[1] ); |
| 633 | memory_set_bankptr(machine, 2, sms_banking_bios[2] ); |
| 631 | 634 | logerror( "Switched in 0x2000 bios.\n" ); |
| 632 | 635 | } |
| 633 | 636 | if ( HAS_BIOS_FULL ) { |
| 634 | | memory_set_bankptr( 1, sms_banking_bios[1] ); |
| 635 | | memory_set_bankptr( 2, sms_banking_bios[2] ); |
| 636 | | memory_set_bankptr( 3, sms_banking_bios[3] ); |
| 637 | | memory_set_bankptr( 4, sms_banking_bios[4] ); |
| 638 | | memory_set_bankptr( 5, sms_banking_bios[4] + 0x2000 ); |
| 637 | memory_set_bankptr(machine, 1, sms_banking_bios[1] ); |
| 638 | memory_set_bankptr(machine, 2, sms_banking_bios[2] ); |
| 639 | memory_set_bankptr(machine, 3, sms_banking_bios[3] ); |
| 640 | memory_set_bankptr(machine, 4, sms_banking_bios[4] ); |
| 641 | memory_set_bankptr(machine, 5, sms_banking_bios[4] + 0x2000 ); |
| 639 | 642 | logerror( "Switched in full bios.\n" ); |
| 640 | 643 | } |
| 641 | 644 | } |
| 642 | 645 | |
| 643 | 646 | if ( sms_cartridge[sms_current_cartridge].features & CF_ONCART_RAM ) { |
| 644 | | memory_set_bankptr( 4, sms_cartridge[sms_current_cartridge].cartRAM ); |
| 645 | | memory_set_bankptr( 5, sms_cartridge[sms_current_cartridge].cartRAM ); |
| 647 | memory_set_bankptr(machine, 4, sms_cartridge[sms_current_cartridge].cartRAM ); |
| 648 | memory_set_bankptr(machine, 5, sms_cartridge[sms_current_cartridge].cartRAM ); |
| 646 | 649 | } |
| 647 | 650 | } |
| 648 | 651 | |
| r3671 | r3672 | |
| 737 | 740 | |
| 738 | 741 | DEVICE_START( sms_cart ) { |
| 739 | 742 | running_machine *machine = device->machine; |
| 743 | const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); |
| 740 | 744 | int i; |
| 741 | 745 | |
| 742 | 746 | for ( i = 0; i < MAX_CARTRIDGES; i++ ) { |
| r3671 | r3672 | |
| 770 | 774 | const char *fname = image_filename( image ); |
| 771 | 775 | int fname_len = fname ? strlen( fname ) : 0; |
| 772 | 776 | const char *extrainfo = image_extrainfo( image ); |
| 777 | const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); |
| 773 | 778 | |
| 774 | 779 | /* Check for 512-byte header */ |
| 775 | 780 | if ((size / 512) & 1) |
| r3671 | r3672 | |
| 915 | 920 | |
| 916 | 921 | MACHINE_RESET(sms) |
| 917 | 922 | { |
| 923 | const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); |
| 924 | |
| 918 | 925 | smsVersion = 0x00; |
| 919 | 926 | if ( HAS_FM ) { |
| 920 | 927 | smsFMDetect = 0x01; |
| 921 | 928 | } |
| 922 | 929 | |
| 923 | | sms_mapper_ram = memory_get_write_ptr( 0, ADDRESS_SPACE_PROGRAM, 0xDFFC ); |
| 930 | sms_mapper_ram = memory_get_write_ptr( space, 0xDFFC ); |
| 924 | 931 | |
| 925 | 932 | if ( sms_cartridge[sms_current_cartridge].features & CF_CODEMASTERS_MAPPER ) { |
| 926 | 933 | /* Install special memory handlers */ |
| 927 | | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x0000, 0, 0, sms_codemasters_page0_w ); |
| 928 | | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x4000, 0, 0, sms_codemasters_page1_w ); |
| 934 | memory_install_write8_handler(space, 0x0000, 0x0000, 0, 0, sms_codemasters_page0_w ); |
| 935 | memory_install_write8_handler(space, 0x4000, 0x4000, 0, 0, sms_codemasters_page1_w ); |
| 929 | 936 | } |
| 930 | 937 | |
| 931 | 938 | /* Initialize SIO stuff for GG */ |
| r3671 | r3672 | |
| 939 | 946 | |
| 940 | 947 | setup_banks(machine); |
| 941 | 948 | |
| 942 | | setup_rom(machine); |
| 949 | setup_rom(space); |
| 943 | 950 | |
| 944 | 951 | rapid_fire_state_1 = 0; |
| 945 | 952 | rapid_fire_state_2 = 0; |
| r3671 | r3672 | |
| 975 | 982 | sms_current_cartridge = slot; |
| 976 | 983 | } |
| 977 | 984 | setup_cart_banks(); |
| 978 | | memory_set_bankptr( 10, sms_banking_cart[3] + 0x2000 ); |
| 979 | | setup_rom(machine); |
| 985 | memory_set_bankptr(space->machine, 10, sms_banking_cart[3] + 0x2000 ); |
| 986 | setup_rom(space); |
| 980 | 987 | } |
| 981 | 988 | |
| 982 | 989 | READ8_HANDLER(sms_store_select1) { |
| r3671 | r3672 | |
| 992 | 999 | } |
| 993 | 1000 | |
| 994 | 1001 | WRITE8_HANDLER(sms_store_control_w) { |
| 995 | | logerror( "0x%04X: sms_store_control write 0x%02X\n", activecpu_get_pc(), data ); |
| 1002 | logerror( "0x%04X: sms_store_control write 0x%02X\n", cpu_get_pc(space->cpu), data ); |
| 996 | 1003 | if ( data & 0x02 ) { |
| 997 | | cpunum_resume( 0, SUSPEND_REASON_HALT ); |
| 1004 | cpu_resume( space->machine->cpu[0], SUSPEND_REASON_HALT ); |
| 998 | 1005 | } else { |
| 999 | 1006 | /* Pull reset line of CPU #0 low */ |
| 1000 | | cpunum_suspend( 0, SUSPEND_REASON_HALT, 1 ); |
| 1001 | | cpu_reset(machine->cpu[0]); |
| 1007 | cpu_suspend( space->machine->cpu[0], SUSPEND_REASON_HALT, 1 ); |
| 1008 | cpu_reset(space->machine->cpu[0]); |
| 1002 | 1009 | } |
| 1003 | 1010 | sms_store_control = data; |
| 1004 | 1011 | } |
| r3671 | r3672 | |
| 1008 | 1015 | } |
| 1009 | 1016 | |
| 1010 | 1017 | void sms_store_int_callback( running_machine *machine, int state ) { |
| 1011 | | cpunum_set_input_line(machine, sms_store_control & 0x01 ? 1 : 0, 0, state ); |
| 1018 | cpu_set_input_line(machine->cpu[0], sms_store_control & 0x01 ? 1 : 0, state ); |
| 1012 | 1019 | } |
| 1013 | 1020 | |
src/mess/drivers/saturn.c
| r3671 | r3672 | |
| 203 | 203 | |
| 204 | 204 | static int saturn_region; |
| 205 | 205 | |
| 206 | | int stv_vblank,stv_hblank; |
| 206 | extern int stv_vblank,stv_hblank; |
| 207 | 207 | int stv_enable_slave_sh2; |
| 208 | 208 | /*SMPC stuff*/ |
| 209 | 209 | static UINT8 NMI_reset; |
| r3671 | r3672 | |
| 229 | 229 | scu_size_1, /* lv 1*/ |
| 230 | 230 | scu_size_2; /* lv 2*/ |
| 231 | 231 | |
| 232 | | static void dma_direct_lv0(running_machine *machine); /*DMA level 0 direct transfer function*/ |
| 233 | | static void dma_direct_lv1(running_machine *machine); /*DMA level 1 direct transfer function*/ |
| 234 | | static void dma_direct_lv2(running_machine *machine); /*DMA level 2 direct transfer function*/ |
| 235 | | static void dma_indirect_lv0(running_machine *machine); /*DMA level 0 indirect transfer function*/ |
| 236 | | static void dma_indirect_lv1(running_machine *machine); /*DMA level 1 indirect transfer function*/ |
| 237 | | static void dma_indirect_lv2(running_machine *machine); /*DMA level 2 indirect transfer function*/ |
| 232 | struct |
| 233 | { |
| 234 | UINT8 vblank_out; |
| 235 | UINT8 vblank_in; |
| 236 | UINT8 hblank_in; |
| 237 | UINT8 timer_0; |
| 238 | UINT8 timer_1; |
| 239 | UINT8 dsp_end; |
| 240 | UINT8 sound_req; |
| 241 | UINT8 smpc; |
| 242 | UINT8 pad; |
| 243 | UINT8 dma_end[3]; |
| 244 | UINT8 dma_ill; |
| 245 | UINT8 vdp1_end; |
| 246 | UINT8 abus; |
| 247 | }stv_irq; |
| 238 | 248 | |
| 249 | static void dma_direct_lv0(const address_space *space); /*DMA level 0 direct transfer function*/ |
| 250 | static void dma_direct_lv1(const address_space *space); /*DMA level 1 direct transfer function*/ |
| 251 | static void dma_direct_lv2(const address_space *space); /*DMA level 2 direct transfer function*/ |
| 252 | static void dma_indirect_lv0(const address_space *space); /*DMA level 0 indirect transfer function*/ |
| 253 | static void dma_indirect_lv1(const address_space *space); /*DMA level 1 indirect transfer function*/ |
| 254 | static void dma_indirect_lv2(const address_space *space); /*DMA level 2 indirect transfer function*/ |
| 239 | 255 | |
| 256 | |
| 240 | 257 | int minit_boost,sinit_boost; |
| 241 | 258 | attotime minit_boost_timeslice, sinit_boost_timeslice; |
| 242 | 259 | |
| r3671 | r3672 | |
| 490 | 507 | intback_stage++; |
| 491 | 508 | } |
| 492 | 509 | |
| 493 | | static UINT8 stv_SMPC_r8 (int offset) |
| 510 | static UINT8 stv_SMPC_r8(const address_space *space, int offset) |
| 494 | 511 | { |
| 495 | 512 | int return_data; |
| 496 | 513 | |
| r3671 | r3672 | |
| 541 | 558 | |
| 542 | 559 | if (offset == 0x33) return_data = saturn_region; |
| 543 | 560 | |
| 544 | | if (LOG_SMPC) logerror ("cpu #%d (PC=%08X) SMPC: Read from Byte Offset %02x (%d) Returns %02x\n", cpu_getactivecpu(), cpu_get_pc(space->cpu), offset, offset>>1, return_data); |
| 561 | if (LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: Read from Byte Offset %02x (%d) Returns %02x\n", space->cpu->tag, cpu_get_pc(space->cpu), offset, offset>>1, return_data); |
| 545 | 562 | |
| 546 | 563 | |
| 547 | 564 | return return_data; |
| 548 | 565 | } |
| 549 | 566 | |
| 550 | | static void stv_SMPC_w8 (running_machine *machine, int offset, UINT8 data) |
| 567 | static void stv_SMPC_w8(const address_space *space, int offset, UINT8 data) |
| 551 | 568 | { |
| 552 | 569 | mame_system_time systime; |
| 553 | 570 | UINT8 last; |
| 571 | running_machine *machine = space->machine; |
| 554 | 572 | |
| 555 | 573 | /* get the current date/time from the core */ |
| 556 | 574 | mame_get_current_datetime(machine, &systime); |
| r3671 | r3672 | |
| 635 | 653 | if(LOG_SMPC) logerror ("SMPC: Slave OFF\n"); |
| 636 | 654 | smpc_ram[0x5f]=0x03; |
| 637 | 655 | stv_enable_slave_sh2 = 0; |
| 638 | | cpu_trigger(machine, 1000); |
| 656 | cpuexec_trigger(machine, 1000); |
| 639 | 657 | cpu_set_input_line(machine->cpu[1], INPUT_LINE_RESET, ASSERT_LINE); |
| 640 | 658 | break; |
| 641 | 659 | case 0x06: |
| 642 | 660 | if(LOG_SMPC) logerror ("SMPC: Sound ON\n"); |
| 643 | 661 | /* wrong? */ |
| 644 | 662 | smpc_ram[0x5f]=0x06; |
| 645 | | cpunum_set_input_line(machine, 2, INPUT_LINE_RESET, CLEAR_LINE); |
| 663 | cpu_set_input_line(machine->cpu[2], INPUT_LINE_RESET, CLEAR_LINE); |
| 646 | 664 | en_68k = 1; |
| 647 | 665 | break; |
| 648 | 666 | case 0x07: |
| 649 | 667 | if(LOG_SMPC) logerror ("SMPC: Sound OFF\n"); |
| 650 | | cpunum_set_input_line(machine, 2, INPUT_LINE_RESET, ASSERT_LINE); |
| 668 | cpu_set_input_line(machine->cpu[2], INPUT_LINE_RESET, ASSERT_LINE); |
| 651 | 669 | en_68k = 0; |
| 652 | 670 | smpc_ram[0x5f]=0x07; |
| 653 | 671 | break; |
| r3671 | r3672 | |
| 663 | 681 | case 0x0e: |
| 664 | 682 | if(LOG_SMPC) logerror ("SMPC: Change Clock to 352\n"); |
| 665 | 683 | smpc_ram[0x5f]=0x0e; |
| 666 | | cpunum_set_clock(machine, 0, MASTER_CLOCK_352/2); |
| 667 | | cpunum_set_clock(machine, 1, MASTER_CLOCK_352/2); |
| 668 | | cpunum_set_clock(machine, 2, MASTER_CLOCK_352/5); |
| 684 | cpu_set_clock(machine->cpu[0], MASTER_CLOCK_352/2); |
| 685 | cpu_set_clock(machine->cpu[1], MASTER_CLOCK_352/2); |
| 686 | cpu_set_clock(machine->cpu[2], MASTER_CLOCK_352/5); |
| 669 | 687 | cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi? |
| 670 | 688 | break; |
| 671 | 689 | case 0x0f: |
| 672 | 690 | if(LOG_SMPC) logerror ("SMPC: Change Clock to 320\n"); |
| 673 | 691 | smpc_ram[0x5f]=0x0f; |
| 674 | | cpunum_set_clock(machine, 0, MASTER_CLOCK_320/2); |
| 675 | | cpunum_set_clock(machine, 1, MASTER_CLOCK_320/2); |
| 676 | | cpunum_set_clock(machine, 2, MASTER_CLOCK_320/5); |
| 692 | cpu_set_clock(machine->cpu[0], MASTER_CLOCK_320/2); |
| 693 | cpu_set_clock(machine->cpu[1], MASTER_CLOCK_320/2); |
| 694 | cpu_set_clock(machine->cpu[2], MASTER_CLOCK_320/5); |
| 677 | 695 | cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi? |
| 678 | 696 | break; |
| 679 | 697 | /*"Interrupt Back"*/ |
| r3671 | r3672 | |
| 771 | 789 | |
| 772 | 790 | break; |
| 773 | 791 | default: |
| 774 | | if(LOG_SMPC) logerror ("cpu #%d (PC=%08X) SMPC: undocumented Command %02x\n", cpu_getactivecpu(), cpu_get_pc(space->cpu), data); |
| 792 | if(LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: undocumented Command %02x\n", space->cpu->tag, cpu_get_pc(space->cpu), data); |
| 775 | 793 | } |
| 776 | 794 | |
| 777 | 795 | // we've processed the command, clear status flag |
| r3671 | r3672 | |
| 788 | 806 | /* registers are all byte accesses, convert here */ |
| 789 | 807 | offset = offset << 2; // multiply offset by 4 |
| 790 | 808 | |
| 791 | | if (!(~mem_mask & 0xff000000)) { byte = 0; readdata = stv_SMPC_r8(offset+byte) << 24; } |
| 792 | | if (!(~mem_mask & 0x00ff0000)) { byte = 1; readdata = stv_SMPC_r8(offset+byte) << 16; } |
| 793 | | if (!(~mem_mask & 0x0000ff00)) { byte = 2; readdata = stv_SMPC_r8(offset+byte) << 8; } |
| 794 | | if (!(~mem_mask & 0x000000ff)) { byte = 3; readdata = stv_SMPC_r8(offset+byte) << 0; } |
| 809 | if (!(~mem_mask & 0xff000000)) { byte = 0; readdata = stv_SMPC_r8(space, offset+byte) << 24; } |
| 810 | if (!(~mem_mask & 0x00ff0000)) { byte = 1; readdata = stv_SMPC_r8(space, offset+byte) << 16; } |
| 811 | if (!(~mem_mask & 0x0000ff00)) { byte = 2; readdata = stv_SMPC_r8(space, offset+byte) << 8; } |
| 812 | if (!(~mem_mask & 0x000000ff)) { byte = 3; readdata = stv_SMPC_r8(space, offset+byte) << 0; } |
| 795 | 813 | |
| 796 | 814 | return readdata; |
| 797 | 815 | } |
| r3671 | r3672 | |
| 813 | 831 | |
| 814 | 832 | offset += byte; |
| 815 | 833 | |
| 816 | | stv_SMPC_w8(machine, offset,writedata); |
| 834 | stv_SMPC_w8(space, offset,writedata); |
| 817 | 835 | } |
| 818 | 836 | |
| 819 | 837 | |
| r3671 | r3672 | |
| 838 | 856 | |
| 839 | 857 | /* to do, update bios idle skips so they work better with this arrangement.. */ |
| 840 | 858 | |
| 859 | static emu_timer *vblank_in_timer,*scan_timer,*t1_timer; |
| 860 | static int h_sync,v_sync; |
| 861 | static int cur_scan; |
| 841 | 862 | |
| 842 | | static INTERRUPT_GEN( stv_interrupt ) |
| 863 | #define VBLANK_OUT_IRQ \ |
| 864 | timer_0 = 0; \ |
| 865 | { \ |
| 866 | /*if(LOG_IRQ) logerror ("Interrupt: VBlank-OUT Vector 0x41 Level 0x0e\n");*/ \ |
| 867 | cpu_set_input_line_and_vector(device->machine->cpu[0], 0xe, (stv_irq.vblank_out) ? HOLD_LINE : CLEAR_LINE , 0x41); \ |
| 868 | } \ |
| 869 | |
| 870 | #define VBLANK_IN_IRQ \ |
| 871 | { \ |
| 872 | /*if(LOG_IRQ) logerror ("Interrupt: VBlank IN Vector 0x40 Level 0x0f\n");*/ \ |
| 873 | cpu_set_input_line_and_vector(machine->cpu[0], 0xf, (stv_irq.vblank_in) ? HOLD_LINE : CLEAR_LINE , 0x40); \ |
| 874 | } \ |
| 875 | |
| 876 | #define HBLANK_IN_IRQ \ |
| 877 | timer_1 = stv_scu[37] & 0x1ff; \ |
| 878 | { \ |
| 879 | /*if(LOG_IRQ) logerror ("Interrupt: HBlank-In at scanline %04x, Vector 0x42 Level 0x0d\n",scanline);*/ \ |
| 880 | cpu_set_input_line_and_vector(machine->cpu[0], 0xd, (stv_irq.hblank_in) ? HOLD_LINE : CLEAR_LINE, 0x42); \ |
| 881 | } \ |
| 882 | |
| 883 | #define TIMER_0_IRQ \ |
| 884 | if(timer_0 == (stv_scu[36] & 0x3ff)) \ |
| 885 | { \ |
| 886 | /*if(LOG_IRQ) logerror ("Interrupt: Timer 0 at scanline %04x, Vector 0x43 Level 0x0c\n",scanline);*/ \ |
| 887 | cpu_set_input_line_and_vector(machine->cpu[0], 0xc, (stv_irq.timer_0) ? HOLD_LINE : CLEAR_LINE, 0x43 ); \ |
| 888 | } \ |
| 889 | |
| 890 | #define TIMER_1_IRQ \ |
| 891 | if((stv_scu[38] & 1)) \ |
| 892 | { \ |
| 893 | if(!(stv_scu[38] & 0x80)) \ |
| 894 | { \ |
| 895 | /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \ |
| 896 | cpu_set_input_line_and_vector(machine->cpu[0], 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \ |
| 897 | } \ |
| 898 | else \ |
| 899 | { \ |
| 900 | if((timer_0) == (stv_scu[36] & 0x3ff)) \ |
| 901 | { \ |
| 902 | /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \ |
| 903 | cpu_set_input_line_and_vector(machine->cpu[0], 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \ |
| 904 | } \ |
| 905 | } \ |
| 906 | } \ |
| 907 | |
| 908 | #define VDP1_IRQ \ |
| 909 | { \ |
| 910 | cpu_set_input_line_and_vector(machine->cpu[0], 2, (stv_irq.vdp1_end) ? HOLD_LINE : CLEAR_LINE, 0x4d); \ |
| 911 | } \ |
| 912 | |
| 913 | static TIMER_CALLBACK( hblank_in_irq ) |
| 843 | 914 | { |
| 844 | | scanline = 261-cpu_getiloops(); |
| 915 | int scanline = param; |
| 845 | 916 | |
| 846 | | stv_hblank = 0; |
| 917 | // h = video_screen_get_height(machine->primary_screen); |
| 918 | // w = video_screen_get_width(machine->primary_screen); |
| 847 | 919 | |
| 848 | | if(scanline == 0) |
| 920 | TIMER_0_IRQ; |
| 921 | HBLANK_IN_IRQ; |
| 922 | |
| 923 | if((scanline+1) < v_sync) |
| 849 | 924 | { |
| 850 | | if(!(stv_scu[40] & 2))/*VBLANK-OUT*/ |
| 851 | | { |
| 852 | | if(LOG_IRQ) logerror ("Interrupt: VBlank-OUT at scanline %04x, Vector 0x41 Level 0x0e\n",scanline); |
| 853 | | cpu_set_input_line_and_vector(machine->cpu[0], 0xe, HOLD_LINE , 0x41); |
| 854 | | } |
| 855 | | stv_vblank = 0; |
| 925 | timer_adjust_oneshot(scan_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline+1, h_sync), scanline+1); |
| 926 | /*set the first Timer-1 event*/ |
| 927 | cur_scan = scanline+1; |
| 928 | timer_adjust_oneshot(t1_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline+1, 0), 0); |
| 856 | 929 | } |
| 857 | | else if(scanline <= 223 && scanline >= 1)/*Correct?*/ |
| 858 | | { |
| 859 | | timer_0++; |
| 860 | | timer_1++; |
| 861 | | stv_hblank = 1; |
| 862 | | /*TODO: check this...*/ |
| 863 | | /*Timer 1 handling*/ |
| 864 | | if((stv_scu[38] & 1)) |
| 865 | | { |
| 866 | | if((!(stv_scu[40] & 0x10)) && (!(stv_scu[38] & 0x80))) |
| 867 | | { |
| 868 | | if(LOG_IRQ) logerror ("Interrupt: Timer 1 at scanline %04x, Vector 0x44 Level 0x0b\n",scanline); |
| 869 | | cpu_set_input_line_and_vector(machine->cpu[0], 0xb, HOLD_LINE, 0x44 ); |
| 870 | | } |
| 871 | | else if((!(stv_scu[40] & 0x10)) && (stv_scu[38] & 0x80)) |
| 872 | | { |
| 873 | | if(timer_1 == (stv_scu[36] & 0x1ff)) |
| 874 | | { |
| 875 | | if(LOG_IRQ) logerror ("Interrupt: Timer 1 at scanline %04x, Vector 0x44 Level 0x0b\n",scanline); |
| 876 | | cpu_set_input_line_and_vector(machine->cpu[0], 0xb, HOLD_LINE, 0x44 ); |
| 877 | | } |
| 878 | | } |
| 879 | | } |
| 880 | | if(timer_0 == (stv_scu[36] & 0x1ff)) |
| 881 | | { |
| 882 | | if(!(stv_scu[40] & 8))/*Timer 0*/ |
| 883 | | { |
| 884 | | if(LOG_IRQ) logerror ("Interrupt: Timer 0 at scanline %04x, Vector 0x43 Level 0x0c\n",scanline); |
| 885 | | cpu_set_input_line_and_vector(machine->cpu[0], 0xc, HOLD_LINE, 0x43 ); |
| 886 | | } |
| 887 | | } |
| 888 | 930 | |
| 889 | | /*TODO:use this *at the end* of the draw line.*/ |
| 890 | | if(!(stv_scu[40] & 4))/*HBLANK-IN*/ |
| 891 | | { |
| 892 | | if(LOG_IRQ) logerror ("Interrupt: HBlank-In at scanline %04x, Vector 0x42 Level 0x0d\n",scanline); |
| 893 | | cpu_set_input_line_and_vector(machine->cpu[0], 0xd, HOLD_LINE , 0x42); |
| 894 | | } |
| 895 | | } |
| 896 | | else if(scanline == 224) |
| 897 | | { |
| 898 | | timer_0 = 0; |
| 899 | | timer_1 = 0; |
| 931 | timer_0++; |
| 932 | } |
| 900 | 933 | |
| 901 | | if(!(stv_scu[40] & 1))/*VBLANK-IN*/ |
| 902 | | { |
| 903 | | if(LOG_IRQ) logerror ("Interrupt: VBlank IN at scanline %04x, Vector 0x40 Level 0x0f\n",scanline); |
| 904 | | cpu_set_input_line_and_vector(machine->cpu[0], 0xf, HOLD_LINE , 0x40); |
| 905 | | } |
| 906 | | stv_vblank = 1; |
| 934 | static TIMER_CALLBACK( timer1_irq ) |
| 935 | { |
| 936 | int cur_point = param; |
| 907 | 937 | |
| 908 | | if(timer_0 == (stv_scu[36] & 0x1ff)) |
| 909 | | { |
| 910 | | if(!(stv_scu[40] & 8))/*Timer 0*/ |
| 911 | | { |
| 912 | | if(LOG_IRQ) logerror ("Interrupt: Timer 0 at scanline %04x, Vector 0x43 Level 0x0c\n",scanline); |
| 913 | | cpu_set_input_line_and_vector(machine->cpu[0], 0xc, HOLD_LINE, 0x43 ); |
| 914 | | } |
| 915 | | } |
| 916 | | if(!(stv_scu[40] & 0x2000)) /*Sprite draw end irq*/ |
| 917 | | cpu_set_input_line_and_vector(machine->cpu[0], 2, HOLD_LINE , 0x4d); |
| 938 | TIMER_1_IRQ; |
| 939 | |
| 940 | if((cur_point+1) < h_sync) |
| 941 | { |
| 942 | timer_adjust_oneshot(t1_timer, video_screen_get_time_until_pos(machine->primary_screen, cur_scan, cur_point+1), cur_point+1); |
| 918 | 943 | } |
| 944 | |
| 945 | if(timer_1 > 0) timer_1--; |
| 919 | 946 | } |
| 920 | 947 | |
| 948 | static TIMER_CALLBACK( vdp1_irq ) |
| 949 | { |
| 950 | VDP1_IRQ; |
| 951 | } |
| 952 | |
| 953 | static TIMER_CALLBACK( vblank_in_irq ) |
| 954 | { |
| 955 | VBLANK_IN_IRQ; |
| 956 | } |
| 957 | |
| 958 | /*V-Blank-OUT event*/ |
| 959 | static INTERRUPT_GEN( stv_interrupt ) |
| 960 | { |
| 961 | // scanline = 0; |
| 962 | h_sync = video_screen_get_height(device->machine->primary_screen)/2;//horz |
| 963 | v_sync = video_screen_get_width(device->machine->primary_screen)-2;//vert |
| 964 | |
| 965 | VBLANK_OUT_IRQ; |
| 966 | |
| 967 | /*Next V-Blank-IN event*/ |
| 968 | timer_adjust_oneshot(vblank_in_timer,video_screen_get_time_until_pos(device->machine->primary_screen, 0, 0), 0); |
| 969 | /*Set the first Hblank-IN event*/ |
| 970 | timer_adjust_oneshot(scan_timer, video_screen_get_time_until_pos(device->machine->primary_screen, 0, h_sync), 0); |
| 971 | |
| 972 | /*TODO: timing of this one (related to the VDP1 speed)*/ |
| 973 | /* (NOTE: value shouldn't be at h_sync/v_sync position (will break shienryu))*/ |
| 974 | timer_set(video_screen_get_time_until_pos(device->machine->primary_screen,0,0), NULL, 0, vdp1_irq); |
| 975 | } |
| 976 | |
| 921 | 977 | static UINT8 port_sel,mux_data; |
| 922 | 978 | |
| 923 | 979 | #define HI_WORD_ACCESS (~mem_mask & 0x00ff0000) == 0 |
| r3671 | r3672 | |
| 1052 | 1108 | //{ |
| 1053 | 1109 | //Super Major League reads here??? |
| 1054 | 1110 | //} |
| 1055 | | |
| 1056 | | // Saturn BIOS needs this (need to investigate further) |
| 1057 | | if (offset == 32) |
| 1058 | | { |
| 1059 | | return 0x00100000; |
| 1060 | | } |
| 1061 | | |
| 1062 | 1111 | if (offset == 31) |
| 1063 | 1112 | { |
| 1064 | 1113 | if(LOG_SCU) logerror("(PC=%08x) DMA status reg read\n",cpu_get_pc(space->cpu)); |
| 1065 | | return stv_scu[offset]; |
| 1114 | return stv_scu[offset]; |
| 1066 | 1115 | } |
| 1067 | 1116 | else if ( offset == 35 ) |
| 1068 | 1117 | { |
| 1069 | 1118 | if(LOG_SCU) logerror( "DSP mem read at %08X\n", stv_scu[34]); |
| 1070 | 1119 | return dsp_ram_addr_r(); |
| 1071 | 1120 | } |
| 1072 | | else if( offset == 41) |
| 1121 | else if( offset == 41) /*IRQ reg status read*/ |
| 1073 | 1122 | { |
| 1074 | | logerror("(PC=%08x) IRQ status reg read\n",cpu_get_pc(space->cpu)); |
| 1075 | | /*TODO:for now we're activating everything here,but we need to return the proper active irqs*/ |
| 1076 | | return 0xffffffff; |
| 1123 | if(LOG_SCU) logerror("(PC=%08x) IRQ status reg read %08x\n",cpu_get_pc(space->cpu),mem_mask); |
| 1124 | |
| 1125 | stv_scu[41] = (stv_irq.vblank_in & 1)<<0; |
| 1126 | stv_scu[41]|= (stv_irq.vblank_out & 1)<<1; |
| 1127 | stv_scu[41]|= (stv_irq.hblank_in & 1)<<2; |
| 1128 | stv_scu[41]|= (stv_irq.timer_0 & 1)<<3; |
| 1129 | stv_scu[41]|= (stv_irq.timer_1 & 1)<<4; |
| 1130 | stv_scu[41]|= (stv_irq.dsp_end & 1)<<5; |
| 1131 | stv_scu[41]|= (stv_irq.sound_req & 1)<<6; |
| 1132 | stv_scu[41]|= (stv_irq.smpc & 1)<<7; |
| 1133 | stv_scu[41]|= (stv_irq.pad & 1)<<8; |
| 1134 | stv_scu[41]|= (stv_irq.dma_end[0] & 1)<<9; |
| 1135 | stv_scu[41]|= (stv_irq.dma_end[1] & 1)<<10; |
| 1136 | stv_scu[41]|= (stv_irq.dma_end[2] & 1)<<11; |
| 1137 | stv_scu[41]|= (stv_irq.dma_ill & 1)<<12; |
| 1138 | stv_scu[41]|= (stv_irq.vdp1_end & 1)<<13; |
| 1139 | stv_scu[41]|= (stv_irq.abus & 1)<<15; |
| 1140 | |
| 1141 | return stv_scu[41] ^ 0xffffffff; |
| 1077 | 1142 | } |
| 1078 | 1143 | else if( offset == 50 ) |
| 1079 | 1144 | { |
| r3671 | r3672 | |
| 1129 | 1194 | */ |
| 1130 | 1195 | if(stv_scu[4] & 1 && ((stv_scu[5] & 7) == 7) && stv_scu[4] & 0x100) |
| 1131 | 1196 | { |
| 1132 | | if(DIRECT_MODE(0)) { dma_direct_lv0(machine); } |
| 1133 | | else { dma_indirect_lv0(machine); } |
| 1197 | if(DIRECT_MODE(0)) { dma_direct_lv0(space); } |
| 1198 | else { dma_indirect_lv0(space); } |
| 1134 | 1199 | |
| 1135 | 1200 | stv_scu[4]^=1;//disable starting bit. |
| 1136 | 1201 | |
| 1137 | 1202 | /*Sound IRQ*/ |
| 1138 | 1203 | if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1) |
| 1139 | 1204 | { |
| 1140 | | //cpu_set_input_line_and_vector(machine->cpu[0], 9, HOLD_LINE , 0x46); |
| 1205 | //cpu_set_input_line_and_vector(space->machine->cpu[0], 9, HOLD_LINE , 0x46); |
| 1141 | 1206 | logerror("SCSP: Main CPU interrupt\n"); |
| 1142 | 1207 | #if 0 |
| 1143 | 1208 | if((scu_dst_0 & 0x7ffffff) != 0x05a00000) |
| 1144 | 1209 | { |
| 1145 | 1210 | if(!(stv_scu[40] & 0x1000)) |
| 1146 | 1211 | { |
| 1147 | | cpu_set_input_line_and_vector(machine->cpu[0], 3, HOLD_LINE, 0x4c); |
| 1212 | cpu_set_input_line_and_vector(space->machine->cpu[0], 3, HOLD_LINE, 0x4c); |
| 1148 | 1213 | logerror("SCU: Illegal DMA interrupt\n"); |
| 1149 | 1214 | } |
| 1150 | 1215 | } |
| r3671 | r3672 | |
| 1190 | 1255 | case 12: |
| 1191 | 1256 | if(stv_scu[12] & 1 && ((stv_scu[13] & 7) == 7) && stv_scu[12] & 0x100) |
| 1192 | 1257 | { |
| 1193 | | if(DIRECT_MODE(1)) { dma_direct_lv1(machine); } |
| 1194 | | else { dma_indirect_lv1(machine); } |
| 1258 | if(DIRECT_MODE(1)) { dma_direct_lv1(space); } |
| 1259 | else { dma_indirect_lv1(space); } |
| 1195 | 1260 | |
| 1196 | 1261 | stv_scu[12]^=1; |
| 1197 | 1262 | |
| 1198 | 1263 | /*Sound IRQ*/ |
| 1199 | 1264 | if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1) |
| 1200 | 1265 | { |
| 1201 | | //cpu_set_input_line_and_vector(machine->cpu[0], 9, HOLD_LINE , 0x46); |
| 1266 | //cpu_set_input_line_and_vector(space->machine->cpu[0], 9, HOLD_LINE , 0x46); |
| 1202 | 1267 | logerror("SCSP: Main CPU interrupt\n"); |
| 1203 | 1268 | } |
| 1204 | 1269 | } |
| r3671 | r3672 | |
| 1240 | 1305 | case 20: |
| 1241 | 1306 | if(stv_scu[20] & 1 && ((stv_scu[21] & 7) == 7) && stv_scu[20] & 0x100) |
| 1242 | 1307 | { |
| 1243 | | if(DIRECT_MODE(2)) { dma_direct_lv2(machine); } |
| 1244 | | else { dma_indirect_lv2(machine); } |
| 1308 | if(DIRECT_MODE(2)) { dma_direct_lv2(space); } |
| 1309 | else { dma_indirect_lv2(space); } |
| 1245 | 1310 | |
| 1246 | 1311 | stv_scu[20]^=1; |
| 1247 | 1312 | |
| 1248 | 1313 | /*Sound IRQ*/ |
| 1249 | 1314 | if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1) |
| 1250 | 1315 | { |
| 1251 | | //cpu_set_input_line_and_vector(machine->cpu[0], 9, HOLD_LINE , 0x46); |
| 1316 | //cpu_set_input_line_and_vector(space->machine->cpu[0], 9, HOLD_LINE , 0x46); |
| 1252 | 1317 | logerror("SCSP: Main CPU interrupt\n"); |
| 1253 | 1318 | } |
| 1254 | 1319 | } |
| r3671 | r3672 | |
| 1270 | 1335 | /*DSP section*/ |
| 1271 | 1336 | /*Use functions so it is easier to work out*/ |
| 1272 | 1337 | case 32: |
| 1273 | | dsp_prg_ctrl(machine, data); |
| 1338 | dsp_prg_ctrl(space, data); |
| 1274 | 1339 | if(LOG_SCU) logerror("SCU DSP: Program Control Port Access %08x\n",data); |
| 1275 | 1340 | break; |
| 1276 | 1341 | case 33: |
| r3671 | r3672 | |
| 1291 | 1356 | case 40: |
| 1292 | 1357 | /*An interrupt is masked when his specific bit is 1.*/ |
| 1293 | 1358 | /*Are bit 16-bit 31 for External A-Bus irq mask like the status register?*/ |
| 1294 | | /*What is 0x00000080 setting?Is it valid?*/ |
| 1295 | 1359 | |
| 1360 | stv_irq.vblank_in = (((stv_scu[40] & 0x0001)>>0) ^ 1); |
| 1361 | stv_irq.vblank_out = (((stv_scu[40] & 0x0002)>>1) ^ 1); |
| 1362 | stv_irq.hblank_in = (((stv_scu[40] & 0x0004)>>2) ^ 1); |
| 1363 | stv_irq.timer_0 = (((stv_scu[40] & 0x0008)>>3) ^ 1); |
| 1364 | stv_irq.timer_1 = (((stv_scu[40] & 0x0010)>>4) ^ 1); |
| 1365 | stv_irq.dsp_end = (((stv_scu[40] & 0x0020)>>5) ^ 1); |
| 1366 | stv_irq.sound_req = (((stv_scu[40] & 0x0040)>>6) ^ 1); |
| 1367 | stv_irq.smpc = (((stv_scu[40] & 0x0080)>>7)); //NOTE: SCU bug |
| 1368 | stv_irq.pad = (((stv_scu[40] & 0x0100)>>8) ^ 1); |
| 1369 | stv_irq.dma_end[0] = (((stv_scu[40] & 0x0200)>>9) ^ 1); |
| 1370 | stv_irq.dma_end[1] = (((stv_scu[40] & 0x0400)>>10) ^ 1); |
| 1371 | stv_irq.dma_end[2] = (((stv_scu[40] & 0x0800)>>11) ^ 1); |
| 1372 | stv_irq.dma_ill = (((stv_scu[40] & 0x1000)>>12) ^ 1); |
| 1373 | stv_irq.vdp1_end = (((stv_scu[40] & 0x2000)>>13) ^ 1); |
| 1374 | stv_irq.abus = (((stv_scu[40] & 0x8000)>>15) ^ 1); |
| 1375 | |
| 1296 | 1376 | /*Take out the common settings to keep logging quiet.*/ |
| 1297 | 1377 | if(stv_scu[40] != 0xfffffffe && |
| 1298 | 1378 | stv_scu[40] != 0xfffffffc && |
| 1299 | 1379 | stv_scu[40] != 0xffffffff) |
| 1300 | 1380 | { |
| 1301 | | if(LOG_SCU) logerror("cpu #%d (PC=%08X) IRQ mask reg set %08x = %d%d%d%d|%d%d%d%d|%d%d%d%d|%d%d%d%d\n", |
| 1302 | | cpu_getactivecpu(), cpu_get_pc(space->cpu), |
| 1381 | if(LOG_SCU) logerror("cpu %s (PC=%08X) IRQ mask reg set %08x = %d%d%d%d|%d%d%d%d|%d%d%d%d|%d%d%d%d\n", |
| 1382 | space->cpu->tag, cpu_get_pc(space->cpu), |
| 1303 | 1383 | stv_scu[offset], |
| 1304 | 1384 | stv_scu[offset] & 0x8000 ? 1 : 0, /*A-Bus irq*/ |
| 1305 | 1385 | stv_scu[offset] & 0x4000 ? 1 : 0, /*<reserved>*/ |
| r3671 | r3672 | |
| 1319 | 1399 | stv_scu[offset] & 0x0001 ? 1 : 0);/*VBlank-IN*/ |
| 1320 | 1400 | } |
| 1321 | 1401 | break; |
| 1402 | /*Interrupt Control reg Set*/ |
| 1322 | 1403 | case 41: |
| 1323 | 1404 | /*This is r/w by introdon...*/ |
| 1324 | | if(LOG_SCU) logerror("IRQ status reg set:%08x\n",stv_scu[41]); |
| 1405 | if(LOG_SCU) logerror("IRQ status reg set:%08x %08x\n",stv_scu[41],mem_mask); |
| 1406 | |
| 1407 | stv_irq.vblank_in = ((stv_scu[41] & 0x0001)>>0); |
| 1408 | stv_irq.vblank_out = ((stv_scu[41] & 0x0002)>>1); |
| 1409 | stv_irq.hblank_in = ((stv_scu[41] & 0x0004)>>2); |
| 1410 | stv_irq.timer_0 = ((stv_scu[41] & 0x0008)>>3); |
| 1411 | stv_irq.timer_1 = ((stv_scu[41] & 0x0010)>>4); |
| 1412 | stv_irq.dsp_end = ((stv_scu[41] & 0x0020)>>5); |
| 1413 | stv_irq.sound_req = ((stv_scu[41] & 0x0040)>>6); |
| 1414 | stv_irq.smpc = ((stv_scu[41] & 0x0080)>>7); |
| 1415 | stv_irq.pad = ((stv_scu[41] & 0x0100)>>8); |
| 1416 | stv_irq.dma_end[0] = ((stv_scu[41] & 0x0200)>>9); |
| 1417 | stv_irq.dma_end[1] = ((stv_scu[41] & 0x0400)>>10); |
| 1418 | stv_irq.dma_end[2] = ((stv_scu[41] & 0x0800)>>11); |
| 1419 | stv_irq.dma_ill = ((stv_scu[41] & 0x1000)>>12); |
| 1420 | stv_irq.vdp1_end = ((stv_scu[41] & 0x2000)>>13); |
| 1421 | stv_irq.abus = ((stv_scu[41] & 0x8000)>>15); |
| 1422 | |
| 1325 | 1423 | break; |
| 1326 | 1424 | case 42: if(LOG_SCU) logerror("A-Bus IRQ ACK %08x\n",stv_scu[42]); break; |
| 1327 | 1425 | case 49: if(LOG_SCU) logerror("SCU SDRAM set: %02x\n",stv_scu[49]); break; |
| r3671 | r3672 | |
| 1329 | 1427 | } |
| 1330 | 1428 | } |
| 1331 | 1429 | |
| 1332 | | static void dma_direct_lv0(running_machine *machine) |
| 1430 | /*Lv 0 DMA end irq*/ |
| 1431 | static TIMER_CALLBACK( dma_lv0_ended ) |
| 1333 | 1432 | { |
| 1433 | cpu_set_input_line_and_vector(machine->cpu[0], 5, (stv_irq.dma_end[0]) ? HOLD_LINE : CLEAR_LINE, 0x4b); |
| 1434 | |
| 1435 | D0MV_0; |
| 1436 | } |
| 1437 | |
| 1438 | /*Lv 1 DMA end irq*/ |
| 1439 | static TIMER_CALLBACK( dma_lv1_ended ) |
| 1440 | { |
| 1441 | cpu_set_input_line_and_vector(machine->cpu[0], 6, (stv_irq.dma_end[1]) ? HOLD_LINE : CLEAR_LINE, 0x4a); |
| 1442 | |
| 1443 | D1MV_0; |
| 1444 | } |
| 1445 | |
| 1446 | /*Lv 2 DMA end irq*/ |
| 1447 | static TIMER_CALLBACK( dma_lv2_ended ) |
| 1448 | { |
| 1449 | cpu_set_input_line_and_vector(machine->cpu[0], 6, (stv_irq.dma_end[2]) ? HOLD_LINE : CLEAR_LINE, 0x49); |
| 1450 | |
| 1451 | D2MV_0; |
| 1452 | } |
| 1453 | |
| 1454 | static void dma_direct_lv0(const address_space *space) |
| 1455 | { |
| 1334 | 1456 | static UINT32 tmp_src,tmp_dst,tmp_size; |
| 1335 | 1457 | if(LOG_SCU) logerror("DMA lv 0 transfer START\n" |
| 1336 | 1458 | "Start %08x End %08x Size %04x\n",scu_src_0,scu_dst_0,scu_size_0); |
| r3671 | r3672 | |
| 1403 | 1525 | for (; scu_size_0 > 0; scu_size_0-=scu_dst_add_0) |
| 1404 | 1526 | { |
| 1405 | 1527 | if(scu_dst_add_0 == 2) |
| 1406 | | program_write_word(scu_dst_0,program_read_word(scu_src_0)); |
| 1528 | memory_write_word(space,scu_dst_0,memory_read_word(space,scu_src_0)); |
| 1407 | 1529 | else if(scu_dst_add_0 == 8) |
| 1408 | 1530 | { |
| 1409 | | program_write_word(scu_dst_0,program_read_word(scu_src_0)); |
| 1410 | | program_write_word(scu_dst_0+2,program_read_word(scu_src_0)); |
| 1411 | | program_write_word(scu_dst_0+4,program_read_word(scu_src_0+2)); |
| 1412 | | program_write_word(scu_dst_0+6,program_read_word(scu_src_0+2)); |
| 1531 | memory_write_word(space,scu_dst_0,memory_read_word(space,scu_src_0)); |
| 1532 | memory_write_word(space,scu_dst_0+2,memory_read_word(space,scu_src_0)); |
| 1533 | memory_write_word(space,scu_dst_0+4,memory_read_word(space,scu_src_0+2)); |
| 1534 | memory_write_word(space,scu_dst_0+6,memory_read_word(space,scu_src_0+2)); |
| 1413 | 1535 | } |
| 1414 | 1536 | else |
| 1415 | 1537 | { |
| 1416 | | program_write_word(scu_dst_0,program_read_word(scu_src_0)); |
| 1417 | | program_write_word(scu_dst_0+2,program_read_word(scu_src_0+2)); |
| 1538 | memory_write_word(space,scu_dst_0,memory_read_word(space,scu_src_0)); |
| 1539 | memory_write_word(space,scu_dst_0+2,memory_read_word(space,scu_src_0+2)); |
| 1418 | 1540 | } |
| 1419 | 1541 | |
| 1420 | 1542 | scu_dst_0+=scu_dst_add_0; |
| r3671 | r3672 | |
| 1426 | 1548 | if(!(DWUP(0))) scu_dst_0 = tmp_dst; |
| 1427 | 1549 | |
| 1428 | 1550 | if(LOG_SCU) logerror("DMA transfer END\n"); |
| 1429 | | if(!(stv_scu[40] & 0x800))/*Lv 0 DMA end irq*/ |
| 1430 | | cpu_set_input_line_and_vector(machine->cpu[0], 5, HOLD_LINE , 0x4b); |
| 1431 | 1551 | |
| 1552 | /*TODO: timing of this*/ |
| 1553 | timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv0_ended); |
| 1554 | |
| 1432 | 1555 | if(scu_add_tmp & 0x80000000) |
| 1433 | 1556 | { |
| 1434 | 1557 | scu_dst_add_0 = (scu_add_tmp & 0xff00) >> 8; |
| 1435 | 1558 | scu_src_add_0 = (scu_add_tmp & 0x00ff) >> 0; |
| 1436 | 1559 | scu_add_tmp^=0x80000000; |
| 1437 | 1560 | } |
| 1438 | | |
| 1439 | | D0MV_0; |
| 1440 | 1561 | } |
| 1441 | 1562 | |
| 1442 | | static void dma_direct_lv1(running_machine *machine) |
| 1563 | static void dma_direct_lv1(const address_space *space) |
| 1443 | 1564 | { |
| 1444 | 1565 | static UINT32 tmp_src,tmp_dst,tmp_size; |
| 1445 | 1566 | if(LOG_SCU) logerror("DMA lv 1 transfer START\n" |
| r3671 | r3672 | |
| 1513 | 1634 | for (; scu_size_1 > 0; scu_size_1-=scu_dst_add_1) |
| 1514 | 1635 | { |
| 1515 | 1636 | if(scu_dst_add_1 == 2) |
| 1516 | | program_write_word(scu_dst_1,program_read_word(scu_src_1)); |
| 1637 | memory_write_word(space,scu_dst_1,memory_read_word(space,scu_src_1)); |
| 1517 | 1638 | else |
| 1518 | 1639 | { |
| 1519 | | program_write_word(scu_dst_1,program_read_word(scu_src_1)); |
| 1520 | | program_write_word(scu_dst_1+2,program_read_word(scu_src_1+2)); |
| 1640 | memory_write_word(space,scu_dst_1,memory_read_word(space,scu_src_1)); |
| 1641 | memory_write_word(space,scu_dst_1+2,memory_read_word(space,scu_src_1+2)); |
| 1521 | 1642 | } |
| 1522 | 1643 | |
| 1523 | 1644 | scu_dst_1+=scu_dst_add_1; |
| r3671 | r3672 | |
| 1529 | 1650 | if(!(DWUP(1))) scu_dst_1 = tmp_dst; |
| 1530 | 1651 | |
| 1531 | 1652 | if(LOG_SCU) logerror("DMA transfer END\n"); |
| 1532 | | if(!(stv_scu[40] & 0x400))/*Lv 1 DMA end irq*/ |
| 1533 | | cpu_set_input_line_and_vector(machine->cpu[0], 6, HOLD_LINE , 0x4a); |
| 1534 | 1653 | |
| 1654 | timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv1_ended); |
| 1655 | |
| 1535 | 1656 | if(scu_add_tmp & 0x80000000) |
| 1536 | 1657 | { |
| 1537 | 1658 | scu_dst_add_1 = (scu_add_tmp & 0xff00) >> 8; |
| 1538 | 1659 | scu_src_add_1 = (scu_add_tmp & 0x00ff) >> 0; |
| 1539 | 1660 | scu_add_tmp^=0x80000000; |
| 1540 | 1661 | } |
| 1541 | | |
| 1542 | | D1MV_0; |
| 1543 | 1662 | } |
| 1544 | 1663 | |
| 1545 | | static void dma_direct_lv2(running_machine *machine) |
| 1664 | static void dma_direct_lv2(const address_space *space) |
| 1546 | 1665 | { |
| 1547 | 1666 | static UINT32 tmp_src,tmp_dst,tmp_size; |
| 1548 | 1667 | if(LOG_SCU) logerror("DMA lv 2 transfer START\n" |
| r3671 | r3672 | |
| 1616 | 1735 | for (; scu_size_2 > 0; scu_size_2-=scu_dst_add_2) |
| 1617 | 1736 | { |
| 1618 | 1737 | if(scu_dst_add_2 == 2) |
| 1619 | | program_write_word(scu_dst_2,program_read_word(scu_src_2)); |
| 1738 | memory_write_word(space,scu_dst_2,memory_read_word(space,scu_src_2)); |
| 1620 | 1739 | else |
| 1621 | 1740 | { |
| 1622 | | program_write_word(scu_dst_2,program_read_word(scu_src_2)); |
| 1623 | | program_write_word(scu_dst_2+2,program_read_word(scu_src_2+2)); |
| 1741 | memory_write_word(space,scu_dst_2,memory_read_word(space,scu_src_2)); |
| 1742 | memory_write_word(space,scu_dst_2+2,memory_read_word(space,scu_src_2+2)); |
| 1624 | 1743 | } |
| 1625 | 1744 | |
| 1626 | 1745 | scu_dst_2+=scu_dst_add_2; |
| r3671 | r3672 | |
| 1632 | 1751 | if(!(DWUP(2))) scu_dst_2 = tmp_dst; |
| 1633 | 1752 | |
| 1634 | 1753 | if(LOG_SCU) logerror("DMA transfer END\n"); |
| 1635 | | if(!(stv_scu[40] & 0x200))/*Lv 2 DMA end irq*/ |
| 1636 | | cpu_set_input_line_and_vector(machine->cpu[0], 6, HOLD_LINE , 0x49); |
| 1637 | 1754 | |
| 1755 | timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv2_ended); |
| 1756 | |
| 1638 | 1757 | if(scu_add_tmp & 0x80000000) |
| 1639 | 1758 | { |
| 1640 | 1759 | scu_dst_add_2 = (scu_add_tmp & 0xff00) >> 8; |
| 1641 | 1760 | scu_src_add_2 = (scu_add_tmp & 0x00ff) >> 0; |
| 1642 | 1761 | scu_add_tmp^=0x80000000; |
| 1643 | 1762 | } |
| 1644 | | |
| 1645 | | D2MV_0; |
| 1646 | 1763 | } |
| 1647 | 1764 | |
| 1648 | | static void dma_indirect_lv0(running_machine *machine) |
| 1765 | static void dma_indirect_lv0(const address_space *space) |
| 1649 | 1766 | { |
| 1650 | 1767 | /*Helper to get out of the cycle*/ |
| 1651 | 1768 | UINT8 job_done = 0; |
| r3671 | r3672 | |
| 1662 | 1779 | tmp_src = scu_index_0; |
| 1663 | 1780 | |
| 1664 | 1781 | /*Thanks for Runik of Saturnin for pointing this out...*/ |
| 1665 | | scu_size_0 = program_read_dword(scu_index_0); |
| 1666 | | scu_src_0 = program_read_dword(scu_index_0+8); |
| 1667 | | scu_dst_0 = program_read_dword(scu_index_0+4); |
| 1782 | scu_size_0 = memory_read_dword(space,scu_index_0); |
| 1783 | scu_src_0 = memory_read_dword(space,scu_index_0+8); |
| 1784 | scu_dst_0 = memory_read_dword(space,scu_index_0+4); |
| 1668 | 1785 | |
| 1669 | 1786 | /*Indirect Mode end factor*/ |
| 1670 | 1787 | if(scu_src_0 & 0x80000000) |
| r3671 | r3672 | |
| 1688 | 1805 | for (; scu_size_0 > 0; scu_size_0-=scu_dst_add_0) |
| 1689 | 1806 | { |
| 1690 | 1807 | if(scu_dst_add_0 == 2) |
| 1691 | | program_write_word(scu_dst_0,program_read_word(scu_src_0)); |
| 1808 | memory_write_word(space,scu_dst_0,memory_read_word(space,scu_src_0)); |
| 1692 | 1809 | else |
| 1693 | 1810 | { |
| 1694 | 1811 | /* some games, eg columns97 are a bit weird, I'm not sure this is correct |
| r3671 | r3672 | |
| 1696 | 1813 | can't access 2 byte boundaries, and the end of the sprite list never gets marked, |
| 1697 | 1814 | the length of the transfer is also set to a 2 byte boundary, maybe the add values |
| 1698 | 1815 | should be different, I don't know */ |
| 1699 | | program_write_word(scu_dst_0,program_read_word(scu_src_0)); |
| 1700 | | program_write_word(scu_dst_0+2,program_read_word(scu_src_0+2)); |
| 1816 | memory_write_word(space,scu_dst_0,memory_read_word(space,scu_src_0)); |
| 1817 | memory_write_word(space,scu_dst_0+2,memory_read_word(space,scu_src_0+2)); |
| 1701 | 1818 | } |
| 1702 | 1819 | scu_dst_0+=scu_dst_add_0; |
| 1703 | 1820 | scu_src_0+=scu_src_add_0; |
| 1704 | 1821 | } |
| 1705 | 1822 | |
| 1706 | | //if(DRUP(0)) program_write_dword(tmp_src+8,scu_src_0|job_done ? 0x80000000 : 0); |
| 1707 | | //if(DWUP(0)) program_write_dword(tmp_src+4,scu_dst_0); |
| 1823 | //if(DRUP(0)) memory_write_dword(space,tmp_src+8,scu_src_0|job_done ? 0x80000000 : 0); |
| 1824 | //if(DWUP(0)) memory_write_dword(space,tmp_src+4,scu_dst_0); |
| 1708 | 1825 | |
| 1709 | 1826 | scu_index_0 = tmp_src+0xc; |
| 1710 | 1827 | |
| 1711 | 1828 | }while(job_done == 0); |
| 1712 | 1829 | |
| 1713 | | if(!(stv_scu[40] & 0x800))/*Lv 0 DMA end irq*/ |
| 1714 | | cpu_set_input_line_and_vector(machine->cpu[0], 5, HOLD_LINE , 0x4b); |
| 1715 | | |
| 1716 | | D0MV_0; |
| 1830 | timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv0_ended); |
| 1717 | 1831 | } |
| 1718 | 1832 | |
| 1719 | | static void dma_indirect_lv1(running_machine *machine) |
| 1833 | static void dma_indirect_lv1(const address_space *space) |
| 1720 | 1834 | { |
| 1721 | 1835 | /*Helper to get out of the cycle*/ |
| 1722 | 1836 | UINT8 job_done = 0; |
| r3671 | r3672 | |
| 1732 | 1846 | do{ |
| 1733 | 1847 | tmp_src = scu_index_1; |
| 1734 | 1848 | |
| 1735 | | scu_size_1 = program_read_dword(scu_index_1); |
| 1736 | | scu_src_1 = program_read_dword(scu_index_1+8); |
| 1737 | | scu_dst_1 = program_read_dword(scu_index_1+4); |
| 1849 | scu_size_1 = memory_read_dword(space,scu_index_1); |
| 1850 | scu_src_1 = memory_read_dword(space,scu_index_1+8); |
| 1851 | scu_dst_1 = memory_read_dword(space,scu_index_1+4); |
| 1738 | 1852 | |
| 1739 | 1853 | /*Indirect Mode end factor*/ |
| 1740 | 1854 | if(scu_src_1 & 0x80000000) |
| r3671 | r3672 | |
| 1760 | 1874 | { |
| 1761 | 1875 | |
| 1762 | 1876 | if(scu_dst_add_1 == 2) |
| 1763 | | program_write_word(scu_dst_1,program_read_word(scu_src_1)); |
| 1877 | memory_write_word(space,scu_dst_1,memory_read_word(space,scu_src_1)); |
| 1764 | 1878 | else |
| 1765 | 1879 | { |
| 1766 | 1880 | /* some games, eg columns97 are a bit weird, I'm not sure this is correct |
| r3671 | r3672 | |
| 1768 | 1882 | can't access 2 byte boundaries, and the end of the sprite list never gets marked, |
| 1769 | 1883 | the length of the transfer is also set to a 2 byte boundary, maybe the add values |
| 1770 | 1884 | should be different, I don't know */ |
| 1771 | | program_write_word(scu_dst_1,program_read_word(scu_src_1)); |
| 1772 | | program_write_word(scu_dst_1+2,program_read_word(scu_src_1+2)); |
| 1885 | memory_write_word(space,scu_dst_1,memory_read_word(space,scu_src_1)); |
| 1886 | memory_write_word(space,scu_dst_1+2,memory_read_word(space,scu_src_1+2)); |
| 1773 | 1887 | } |
| 1774 | 1888 | scu_dst_1+=scu_dst_add_1; |
| 1775 | 1889 | scu_src_1+=scu_src_add_1; |
| 1776 | 1890 | } |
| 1777 | 1891 | |
| 1778 | | //if(DRUP(1)) program_write_dword(tmp_src+8,scu_src_1|job_done ? 0x80000000 : 0); |
| 1779 | | //if(DWUP(1)) program_write_dword(tmp_src+4,scu_dst_1); |
| 1892 | //if(DRUP(1)) memory_write_dword(space,tmp_src+8,scu_src_1|job_done ? 0x80000000 : 0); |
| 1893 | //if(DWUP(1)) memory_write_dword(space,tmp_src+4,scu_dst_1); |
| 1780 | 1894 | |
| 1781 | 1895 | scu_index_1 = tmp_src+0xc; |
| 1782 | 1896 | |
| 1783 | 1897 | }while(job_done == 0); |
| 1784 | 1898 | |
| 1785 | | if(!(stv_scu[40] & 0x400))/*Lv 1 DMA end irq*/ |
| 1786 | | cpu_set_input_line_and_vector(machine->cpu[0], 6, HOLD_LINE , 0x4a); |
| 1787 | | |
| 1788 | | D1MV_0; |
| 1899 | timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv1_ended); |
| 1789 | 1900 | } |
| 1790 | 1901 | |
| 1791 | | static void dma_indirect_lv2(running_machine *machine) |
| 1902 | static void dma_indirect_lv2(const address_space *space) |
| 1792 | 1903 | { |
| 1793 | 1904 | /*Helper to get out of the cycle*/ |
| 1794 | 1905 | UINT8 job_done = 0; |
| r3671 | r3672 | |
| 1804 | 1915 | do{ |
| 1805 | 1916 | tmp_src = scu_index_2; |
| 1806 | 1917 | |
| 1807 | | scu_size_2 = program_read_dword(scu_index_2); |
| 1808 | | scu_src_2 = program_read_dword(scu_index_2+8); |
| 1809 | | scu_dst_2 = program_read_dword(scu_index_2+4); |
| 1918 | scu_size_2 = memory_read_dword(space,scu_index_2); |
| 1919 | scu_src_2 = memory_read_dword(space,scu_index_2+8); |
| 1920 | scu_dst_2 = memory_read_dword(space,scu_index_2+4); |
| 1810 | 1921 | |
| 1811 | 1922 | /*Indirect Mode end factor*/ |
| 1812 | 1923 | if(scu_src_2 & 0x80000000) |
| r3671 | r3672 | |
| 1830 | 1941 | for (; scu_size_2 > 0; scu_size_2-=scu_dst_add_2) |
| 1831 | 1942 | { |
| 1832 | 1943 | if(scu_dst_add_2 == 2) |
| 1833 | | program_write_word(scu_dst_2,program_read_word(scu_src_2)); |
| 1944 | memory_write_word(space,scu_dst_2,memory_read_word(space,scu_src_2)); |
| 1834 | 1945 | else |
| 1835 | 1946 | { |
| 1836 | 1947 | /* some games, eg columns97 are a bit weird, I'm not sure this is correct |
| r3671 | r3672 | |
| 1838 | 1949 | can't access 2 byte boundaries, and the end of the sprite list never gets marked, |
| 1839 | 1950 | the length of the transfer is also set to a 2 byte boundary, maybe the add values |
| 1840 | 1951 | should be different, I don't know */ |
| 1841 | | program_write_word(scu_dst_2,program_read_word(scu_src_2)); |
| 1842 | | program_write_word(scu_dst_2+2,program_read_word(scu_src_2+2)); |
| 1952 | memory_write_word(space,scu_dst_2,memory_read_word(space,scu_src_2)); |
| 1953 | memory_write_word(space,scu_dst_2+2,memory_read_word(space,scu_src_2+2)); |
| 1843 | 1954 | } |
| 1844 | 1955 | |
| 1845 | 1956 | scu_dst_2+=scu_dst_add_2; |
| 1846 | 1957 | scu_src_2+=scu_src_add_2; |
| 1847 | 1958 | } |
| 1848 | 1959 | |
| 1849 | | //if(DRUP(2)) program_write_dword(tmp_src+8,scu_src_2|job_done ? 0x80000000 : 0); |
| 1850 | | //if(DWUP(2)) program_write_dword(tmp_src+4,scu_dst_2); |
| 1960 | //if(DRUP(2)) memory_write_dword(space,tmp_src+8,scu_src_2|job_done ? 0x80000000 : 0); |
| 1961 | //if(DWUP(2)) memory_write_dword(space,tmp_src+4,scu_dst_2); |
| 1851 | 1962 | |
| 1852 | 1963 | scu_index_2 = tmp_src+0xc; |
| 1853 | 1964 | |
| 1854 | 1965 | }while(job_done == 0); |
| 1855 | 1966 | |
| 1856 | | if(!(stv_scu[40] & 0x200))/*Lv 2 DMA end irq*/ |
| 1857 | | cpu_set_input_line_and_vector(machine->cpu[0], 6, HOLD_LINE , 0x49); |
| 1858 | | |
| 1859 | | D2MV_0; |
| 1967 | timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv2_ended); |
| 1860 | 1968 | } |
| 1861 | 1969 | |
| 1862 | 1970 | |
| r3671 | r3672 | |
| 1878 | 1986 | static READ32_HANDLER( stv_scsp_regs_r32 ) |
| 1879 | 1987 | { |
| 1880 | 1988 | offset <<= 1; |
| 1881 | | return (scsp_0_r(machine, offset+1, 0xffff) | (scsp_0_r(machine, offset, 0xffff)<<16)); |
| 1989 | return (scsp_0_r(space, offset+1, 0xffff) | (scsp_0_r(space, offset, 0xffff)<<16)); |
| 1882 | 1990 | } |
| 1883 | 1991 | |
| 1884 | 1992 | static WRITE32_HANDLER( stv_scsp_regs_w32 ) |
| 1885 | 1993 | { |
| 1886 | 1994 | offset <<= 1; |
| 1887 | | scsp_0_w(machine, offset + 0, data >> 16, mem_mask >> 16); |
| 1888 | | scsp_0_w(machine, offset + 1, data >> 0, mem_mask); |
| 1995 | scsp_0_w(space, offset, data>>16, mem_mask >> 16); |
| 1996 | scsp_0_w(space, offset+1, data, mem_mask); |
| 1889 | 1997 | } |
| 1890 | 1998 | |
| 1891 | 1999 | /* communication,SLAVE CPU acquires data from the MASTER CPU and triggers an irq. * |
| 1892 | 2000 | * Enter into Radiant Silver Gun specific menu for a test... */ |
| 1893 | 2001 | static WRITE32_HANDLER( minit_w ) |
| 1894 | 2002 | { |
| 1895 | | logerror("cpu #%d (PC=%08X) MINIT write = %08x\n",cpu_getactivecpu(), cpu_get_pc(space->cpu),data); |
| 1896 | | cpu_boost_interleave(machine, minit_boost_timeslice, ATTOTIME_IN_USEC(minit_boost)); |
| 1897 | | cpu_trigger(machine, 1000); |
| 1898 | | cpunum_set_info_int(1, CPUINFO_INT_SH2_FRT_INPUT, PULSE_LINE); |
| 2003 | logerror("cpu %s (PC=%08X) MINIT write = %08x\n", space->cpu->tag, cpu_get_pc(space->cpu),data); |
| 2004 | cpuexec_boost_interleave(space->machine, minit_boost_timeslice, ATTOTIME_IN_USEC(minit_boost)); |
| 2005 | cpuexec_trigger(space->machine, 1000); |
| 2006 | cpu_set_info_int(space->machine->cpu[1], CPUINFO_INT_SH2_FRT_INPUT, PULSE_LINE); |
| 1899 | 2007 | } |
| 1900 | 2008 | |
| 1901 | 2009 | static WRITE32_HANDLER( sinit_w ) |
| 1902 | 2010 | { |
| 1903 | | logerror("cpu #%d (PC=%08X) SINIT write = %08x\n",cpu_getactivecpu(), cpu_get_pc(space->cpu),data); |
| 1904 | | cpu_boost_interleave(machine, sinit_boost_timeslice, ATTOTIME_IN_USEC(sinit_boost)); |
| 1905 | | cpunum_set_info_int(0, CPUINFO_INT_SH2_FRT_INPUT, PULSE_LINE); |
| 2011 | logerror("cpu %s (PC=%08X) SINIT write = %08x\n", space->cpu->tag, cpu_get_pc(space->cpu),data); |
| 2012 | cpuexec_boost_interleave(space->machine, sinit_boost_timeslice, ATTOTIME_IN_USEC(sinit_boost)); |
| 2013 | cpu_set_info_int(space->machine->cpu[0], CPUINFO_INT_SH2_FRT_INPUT, PULSE_LINE); |
| 1906 | 2014 | } |
| 1907 | 2015 | |
| 1908 | 2016 | static UINT32 backup[64*1024/4]; |
| r3671 | r3672 | |
| 2073 | 2181 | saturn_region = rgn; |
| 2074 | 2182 | |
| 2075 | 2183 | // set compatible options |
| 2076 | | cpunum_set_info_int(0, CPUINFO_INT_SH2_DRC_OPTIONS, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL); |
| 2077 | | cpunum_set_info_int(1, CPUINFO_INT_SH2_DRC_OPTIONS, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL); |
| 2184 | cpu_set_info_int(machine->cpu[0], CPUINFO_INT_SH2_DRC_OPTIONS, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL); |
| 2185 | cpu_set_info_int(machine->cpu[1], CPUINFO_INT_SH2_DRC_OPTIONS, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL); |
| 2078 | 2186 | |
| 2079 | 2187 | /* get the current date/time from the core */ |
| 2080 | 2188 | mame_get_current_datetime(machine, &systime); |
| r3671 | r3672 | |
| 2089 | 2197 | stv_scu = auto_malloc (0x100); |
| 2090 | 2198 | scsp_regs = auto_malloc (0x1000); |
| 2091 | 2199 | |
| 2092 | | smpc_ram[0x23] = DectoBCD(systime.local_time.year / 100); |
| 2093 | | smpc_ram[0x25] = DectoBCD(systime.local_time.year % 100); |
| 2094 | | smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1); |
| 2095 | | smpc_ram[0x29] = DectoBCD(systime.local_time.mday); |
| 2096 | | smpc_ram[0x2b] = DectoBCD(systime.local_time.hour); |
| 2097 | | smpc_ram[0x2d] = DectoBCD(systime.local_time.minute); |
| 2098 | | smpc_ram[0x2f] = DectoBCD(systime.local_time.second); |
| 2099 | | smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??) |
| 2100 | | // smpc_ram[0x33] = input_port_read(machine, "???"); |
| 2200 | smpc_ram[0x23] = DectoBCD(systime.local_time.year / 100); |
| 2201 | smpc_ram[0x25] = DectoBCD(systime.local_time.year % 100); |
| 2202 | smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1); |
| 2203 | smpc_ram[0x29] = DectoBCD(systime.local_time.mday); |
| 2204 | smpc_ram[0x2b] = DectoBCD(systime.local_time.hour); |
| 2205 | smpc_ram[0x2d] = DectoBCD(systime.local_time.minute); |
| 2206 | smpc_ram[0x2f] = DectoBCD(systime.local_time.second); |
| 2207 | smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??) |
| 2208 | // smpc_ram[0x33] = input_port_read(machine, "???"); |
| 2101 | 2209 | smpc_ram[0x5f] = 0x10; |
| 2102 | 2210 | } |
| 2103 | 2211 | |
| 2104 | | #ifdef UNUSED_FUNCTION |
| 2105 | | DRIVER_INIT( saturn ) |
| 2106 | | { |
| 2107 | | saturn_init_driver(machine, 0); |
| 2108 | | } |
| 2109 | | #endif |
| 2110 | | |
| 2111 | 2212 | static DRIVER_INIT( saturnus ) |
| 2112 | 2213 | { |
| 2113 | 2214 | saturn_init_driver(machine, 4); |
| r3671 | r3672 | |
| 2164 | 2265 | // don't let the slave cpu and the 68k go anywhere |
| 2165 | 2266 | cpu_set_input_line(machine->cpu[1], INPUT_LINE_RESET, ASSERT_LINE); |
| 2166 | 2267 | stv_enable_slave_sh2 = 0; |
| 2167 | | cpunum_set_input_line(machine, 2, INPUT_LINE_RESET, ASSERT_LINE); |
| 2268 | cpu_set_input_line(machine->cpu[2], INPUT_LINE_RESET, ASSERT_LINE); |
| 2168 | 2269 | |
| 2169 | 2270 | smpcSR = 0x40; // this bit is always on according to docs |
| 2170 | 2271 | |
| r3671 | r3672 | |
| 2179 | 2280 | memset(stv_workram_l, 0, 0x100000); |
| 2180 | 2281 | memset(stv_workram_h, 0, 0x100000); |
| 2181 | 2282 | |
| 2182 | | cpunum_set_clock(machine, 0, MASTER_CLOCK_320/2); |
| 2183 | | cpunum_set_clock(machine, 1, MASTER_CLOCK_320/2); |
| 2184 | | cpunum_set_clock(machine, 2, MASTER_CLOCK_320/5); |
| 2283 | cpu_set_clock(machine->cpu[0], MASTER_CLOCK_320/2); |
| 2284 | cpu_set_clock(machine->cpu[1], MASTER_CLOCK_320/2); |
| 2285 | cpu_set_clock(machine->cpu[2], MASTER_CLOCK_320/5); |
| 2185 | 2286 | |
| 2186 | 2287 | stvcd_reset( machine ); |
| 2288 | |
| 2289 | /* set the first scanline 0 timer to go off */ |
| 2290 | scan_timer = timer_alloc(hblank_in_irq, NULL); |
| 2291 | t1_timer = timer_alloc(timer1_irq,NULL); |
| 2292 | vblank_in_timer = timer_alloc(vblank_in_irq,NULL); |
| 2293 | timer_adjust_oneshot(vblank_in_timer,video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0); |
| 2294 | timer_adjust_oneshot(scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 224, 352), 0); |
| 2187 | 2295 | } |
| 2188 | 2296 | |
| 2189 | 2297 | static const gfx_layout tiles8x8x4_layout = |
| r3671 | r3672 | |
| 2271 | 2379 | if (irq > 0) |
| 2272 | 2380 | { |
| 2273 | 2381 | scsp_last_line = irq; |
| 2274 | | cpunum_set_input_line(machine, 2, irq, ASSERT_LINE); |
| 2382 | cpu_set_input_line(machine->cpu[2], irq, ASSERT_LINE); |
| 2275 | 2383 | } |
| 2276 | 2384 | else if (irq < 0) |
| 2277 | 2385 | { |
| 2278 | | cpunum_set_input_line(machine, 2, -irq, CLEAR_LINE); |
| 2386 | cpu_set_input_line(machine->cpu[2], -irq, CLEAR_LINE); |
| 2279 | 2387 | } |
| 2280 | 2388 | else |
| 2281 | 2389 | { |
| 2282 | | cpunum_set_input_line(machine, 2, scsp_last_line, CLEAR_LINE); |
| 2390 | cpu_set_input_line(machine->cpu[2], scsp_last_line, CLEAR_LINE); |
| 2283 | 2391 | } |
| 2284 | 2392 | } |
| 2285 | 2393 | |