src/mame/drivers/sigmab98.c
| r10330 | r10331 | |
| 1 | 1 | /************************************************************************************************************* |
| 2 | 2 | |
| 3 | | -= Sigma B-98 Hardware =- |
| 3 | -= Sigma B-98 Hardware / Sammy Medal Games =- |
| 4 | 4 | |
| 5 | 5 | driver by Luca Elia |
| 6 | 6 | |
| r10330 | r10331 | |
| 13 | 13 | Each sprite is composed of X x Y tiles and can be zoomed / shrunk. |
| 14 | 14 | Tiles can be 16x16x4 or 16x16x8. |
| 15 | 15 | |
| 16 | ---------------------------------------------------------------- |
| 17 | |
| 18 | Sammy Kids Medal Series |
| 19 | |
| 20 | Cartridge based system. Carts contain just some flash roms. |
| 21 | The main board is not available yet. Hardware unknown, but |
| 22 | it the graphics chip and ROM/RAM banking is the same. |
| 23 | The sound chip is different, an OKI MSM981x ? |
| 24 | |
| 25 | Info from Tatsuya Fujita: |
| 26 | |
| 27 | According to some news articles for the AOU show 2002 and 2003 the correct system name |
| 28 | is "Treasure Fall" (despite the cart label is "Treasure Hall"). |
| 29 | |
| 30 | Dumped games: |
| 31 | |
| 32 | Animal Catch |
| 33 | Itazura Monkey |
| 34 | Taihou de Doboon |
| 35 | Pye-nage Taikai |
| 36 | Hae Hae Ka Ka Ka |
| 37 | |
| 38 | Games with the same cabinet which might be on the same hardware: |
| 39 | |
| 40 | 1999 Shatekids |
| 41 | 1999 Otakara Locomo |
| 42 | 1999 Dokidoki Kingyosukui |
| 43 | 2000 Taihou de Doboon |
| 44 | 2000 Pye-nage Taikai |
| 45 | 2000 Animal Catch |
| 46 | 2000 Itazura Monkey |
| 47 | 2000 Otoshicha Ottotto |
| 48 | 2000 Go Go Cowboy |
| 49 | 2001 Mushitori Meijin |
| 50 | 2001 Morino Dodgeball Senshuken |
| 51 | 2001 Waiwai Wanage |
| 52 | 2001 Hae Hae Ka Ka Ka |
| 53 | 2001 Zarigani Tsuri |
| 54 | 2001 Kotekitai Slot |
| 55 | 2002 Shateki Yokochou |
| 56 | 2002 Ipponzuri Slot |
| 57 | 2002 Karateman |
| 58 | 2002 One-touchable |
| 59 | 2003 Gun Kids |
| 60 | 2003 Kurukuru Train |
| 61 | 2003 Zakuzaku Kaizokudan |
| 62 | 2004 Animal Punch |
| 63 | 2004 Dotabata Zaurus |
| 64 | 2004 Ninchuu Densetsu |
| 65 | |
| 66 | from: |
| 67 | http://www.tsc-acnet.com/index.php?sort=8&action=cataloglist&s=1&mode=3&genre_id=40&freeword=%25A5%25B5%25A5%25DF%25A1%25BC |
| 68 | |
| 16 | 69 | To Do: |
| 17 | 70 | |
| 18 | 71 | - Remove ROM patches from gegege |
| r10330 | r10331 | |
| 24 | 77 | *************************************************************************************************************/ |
| 25 | 78 | |
| 26 | 79 | #include "emu.h" |
| 80 | #include "deprecat.h" |
| 27 | 81 | #include "cpu/z80/z80.h" |
| 28 | 82 | #include "sound/ymz280b.h" |
| 29 | 83 | #include "machine/eeprom.h" |
| r10330 | r10331 | |
| 47 | 101 | 1 7--- ---- |
| 48 | 102 | -6-- ---- 256 Color Sprite |
| 49 | 103 | --5- ---- |
| 50 | | ---4 ---- ? |
| 104 | ---4 ---- Flip X |
| 51 | 105 | ---- 3--- |
| 52 | 106 | ---- -2-- Draw Sprite |
| 53 | | ---- --10 |
| 107 | ---- --10 Priority (0 = Front .. 3 = Back) |
| 54 | 108 | 2 Tile Code (High) |
| 55 | 109 | 3 Tile Code (Low) |
| 56 | 110 | 4 7654 3--- Number of X Tiles - 1 |
| r10330 | r10331 | |
| 59 | 113 | 6 7654 3--- Number of Y Tiles - 1 |
| 60 | 114 | ---- -210 Y (High) |
| 61 | 115 | 7 Y (Low) |
| 62 | | 8 Zoom Factor (<< 8, High) |
| 63 | | 9 Zoom Factor (<< 8, Low) |
| 116 | 8 Shrink Factor (<< 8, High) |
| 117 | 9 Shrink Factor (<< 8, Low) |
| 64 | 118 | a |
| 65 | 119 | b |
| 66 | 120 | c 7654 3--- |
| r10330 | r10331 | |
| 72 | 126 | |
| 73 | 127 | ***************************************************************************/ |
| 74 | 128 | |
| 75 | | static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) |
| 129 | static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int pri_mask) |
| 76 | 130 | { |
| 77 | 131 | UINT8 *end = machine->generic.spriteram.u8 - 0x10; |
| 78 | 132 | UINT8 *s = end + machine->generic.spriteram_size; |
| r10330 | r10331 | |
| 86 | 140 | if ( (s[ 0x01 ] & 0x04) == 0) |
| 87 | 141 | continue; |
| 88 | 142 | |
| 143 | if ( ((1 << (s[ 0x01 ] & 0x03)) & pri_mask) == 0 ) |
| 144 | continue; |
| 145 | |
| 89 | 146 | color = s[ 0x00 ] & 0xf; |
| 90 | 147 | |
| 91 | 148 | gfx = (s[ 0x01 ] & 0x40 ) ? 1 : 0; |
| r10330 | r10331 | |
| 119 | 176 | sx <<= 16; |
| 120 | 177 | sy <<= 16; |
| 121 | 178 | |
| 179 | zoom = (1 << 16) / (zoom ? zoom : 1); |
| 122 | 180 | dim = (0x10 << 8) * zoom; |
| 123 | 181 | scale = dim / 0x10; |
| 124 | 182 | |
| r10330 | r10331 | |
| 126 | 184 | // to avoid holes in between tiles |
| 127 | 185 | if (scale & 0xffff) scale += (1<<16) / 0x10; |
| 128 | 186 | |
| 129 | | flipx = 0; // ? |
| 187 | flipx = s[ 0x01 ] & 0x10; |
| 130 | 188 | flipy = 0; // ? |
| 131 | 189 | |
| 132 | 190 | if ( flipx ) { x0 = nx - 1; x1 = -1; dx = -1; } |
| r10330 | r10331 | |
| 151 | 209 | |
| 152 | 210 | static VIDEO_UPDATE(sigmab98) |
| 153 | 211 | { |
| 212 | int layers_ctrl = -1; |
| 213 | |
| 214 | #ifdef MAME_DEBUG |
| 215 | if (input_code_pressed(screen->machine, KEYCODE_Z)) |
| 216 | { |
| 217 | int msk = 0; |
| 218 | if (input_code_pressed(screen->machine, KEYCODE_Q)) msk |= 1; |
| 219 | if (input_code_pressed(screen->machine, KEYCODE_W)) msk |= 2; |
| 220 | if (input_code_pressed(screen->machine, KEYCODE_E)) msk |= 4; |
| 221 | if (input_code_pressed(screen->machine, KEYCODE_R)) msk |= 8; |
| 222 | if (msk != 0) layers_ctrl &= msk; |
| 223 | } |
| 224 | #endif |
| 225 | |
| 154 | 226 | bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine)); |
| 155 | | draw_sprites(screen->machine, bitmap, cliprect); |
| 227 | |
| 228 | // Draw from priority 3 (bottom, converted to a bitmask) to priority 0 (top) |
| 229 | draw_sprites(screen->machine, bitmap, cliprect, layers_ctrl & 8); |
| 230 | draw_sprites(screen->machine, bitmap, cliprect, layers_ctrl & 4); |
| 231 | draw_sprites(screen->machine, bitmap, cliprect, layers_ctrl & 2); |
| 232 | draw_sprites(screen->machine, bitmap, cliprect, layers_ctrl & 1); |
| 233 | |
| 156 | 234 | return 0; |
| 157 | 235 | } |
| 158 | 236 | |
| r10330 | r10331 | |
| 166 | 244 | static UINT8 reg, rombank; |
| 167 | 245 | static UINT8 reg2, rambank; |
| 168 | 246 | |
| 247 | /*************************************************************************** |
| 248 | GeGeGe no Kitarou Youkai Slot |
| 249 | ***************************************************************************/ |
| 250 | |
| 169 | 251 | // rombank |
| 170 | 252 | static WRITE8_HANDLER( regs_w ) |
| 171 | 253 | { |
| r10330 | r10331 | |
| 364 | 446 | |
| 365 | 447 | |
| 366 | 448 | /*************************************************************************** |
| 449 | Animal Catch |
| 450 | ***************************************************************************/ |
| 367 | 451 | |
| 452 | // rombank |
| 453 | static WRITE8_HANDLER( animalc_rombank_w ) |
| 454 | { |
| 455 | if (offset == 0) |
| 456 | { |
| 457 | reg = data; |
| 458 | return; |
| 459 | } |
| 460 | |
| 461 | UINT8 *rom = space->machine->region("maincpu")->base(); |
| 462 | switch ( reg ) |
| 463 | { |
| 464 | case 0x0f: |
| 465 | rombank = data; |
| 466 | switch (data) |
| 467 | { |
| 468 | case 0x10: memory_set_bankptr(space->machine, "rombank", rom + 0x400 + 0x4000); break; |
| 469 | case 0x14: memory_set_bankptr(space->machine, "rombank", rom + 0x400 + 0x8000); break; |
| 470 | case 0x18: memory_set_bankptr(space->machine, "rombank", rom + 0x400 + 0xc000); break; |
| 471 | default: |
| 472 | logerror("%s: unknown rom bank = %02x, reg = %02x\n", space->machine->describe_context(), data, reg); |
| 473 | } |
| 474 | break; |
| 475 | |
| 476 | default: |
| 477 | logerror("%s: unknown reg written: %02x = %02x\n", space->machine->describe_context(), reg, data); |
| 478 | } |
| 479 | } |
| 480 | static READ8_HANDLER( animalc_rombank_r ) |
| 481 | { |
| 482 | if (offset == 0) |
| 483 | return reg; |
| 484 | |
| 485 | switch ( reg ) |
| 486 | { |
| 487 | case 0x0f: |
| 488 | return rombank; |
| 489 | |
| 490 | default: |
| 491 | logerror("%s: unknown reg read: %02x\n", space->machine->describe_context(), reg); |
| 492 | return 0x00; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | // rambank |
| 497 | static WRITE8_HANDLER( animalc_rambank_w ) |
| 498 | { |
| 499 | if (offset == 0) |
| 500 | { |
| 501 | reg2 = data; |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | int bank = 0; |
| 506 | switch ( reg2 ) |
| 507 | { |
| 508 | case 0x1f: |
| 509 | rambank = data; |
| 510 | switch (data) |
| 511 | { |
| 512 | case 0x58: bank = 0; break; |
| 513 | case 0x62: bank = 1; break; |
| 514 | case 0x63: bank = 2; break; |
| 515 | case 0x64: bank = 3; break; |
| 516 | case 0x65: bank = 4; break; |
| 517 | default: |
| 518 | logerror("%s: unknown ram bank = %02x, reg2 = %02x\n", space->machine->describe_context(), data, reg2); |
| 519 | return; |
| 520 | } |
| 521 | memory_set_bank(space->machine, "rambank", bank); |
| 522 | if ( (bank == 1) || (bank == 2) || (bank == 3) ) |
| 523 | memory_set_bank(space->machine, "sprbank", bank-1); |
| 524 | break; |
| 525 | |
| 526 | default: |
| 527 | logerror("%s: unknown reg2 written: %02x = %02x\n", space->machine->describe_context(), reg2, data); |
| 528 | } |
| 529 | } |
| 530 | static READ8_HANDLER( animalc_rambank_r ) |
| 531 | { |
| 532 | if (offset == 0) |
| 533 | return reg2; |
| 534 | |
| 535 | switch ( reg2 ) |
| 536 | { |
| 537 | case 0x1f: |
| 538 | return rambank; |
| 539 | |
| 540 | default: |
| 541 | logerror("%s: unknown reg2 read: %02x\n", space->machine->describe_context(), reg2); |
| 542 | return 0x00; |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | |
| 547 | static READ8_DEVICE_HANDLER( sammymdl_eeprom_r ) |
| 548 | { |
| 549 | return eeprom_read_bit(device) ? 0x80 : 0; |
| 550 | } |
| 551 | |
| 552 | static WRITE8_DEVICE_HANDLER( sammymdl_eeprom_w ) |
| 553 | { |
| 554 | // latch the bit |
| 555 | eeprom_write_bit(device, data & 0x40); |
| 556 | |
| 557 | // reset line asserted: reset. |
| 558 | eeprom_set_cs_line(device, (data & 0x20) ? CLEAR_LINE : ASSERT_LINE); |
| 559 | |
| 560 | // clock line asserted: write latch or select next bit to read |
| 561 | eeprom_set_clock_line(device, (data & 0x10) ? ASSERT_LINE : CLEAR_LINE); |
| 562 | |
| 563 | if (data & 0x8f) |
| 564 | logerror("%s: unknown eeeprom bits written %02x\n", device->machine->describe_context(), data); |
| 565 | } |
| 566 | |
| 567 | static READ8_HANDLER( unk_34_r ) |
| 568 | { |
| 569 | // mask 0x01? |
| 570 | return 0x01; |
| 571 | } |
| 572 | |
| 573 | static UINT8 vblank; |
| 574 | |
| 575 | static READ8_HANDLER( vblank_r ) |
| 576 | { |
| 577 | // mask 0x04 must be set before writing sprite list |
| 578 | // mask 0x10 must be set or irq/00 hangs? |
| 579 | return vblank | 0x14; |
| 580 | } |
| 581 | |
| 582 | static WRITE8_HANDLER( vblank_w ) |
| 583 | { |
| 584 | vblank = (vblank & ~0x03) | (data & 0x03); |
| 585 | } |
| 586 | |
| 587 | static VIDEO_EOF( sammymdl ) |
| 588 | { |
| 589 | vblank &= ~0x01; |
| 590 | } |
| 591 | |
| 592 | static UINT8 out[3]; |
| 593 | static void show_3_outputs() |
| 594 | { |
| 595 | #ifdef MAME_DEBUG |
| 596 | popmessage("COIN: %02X LED: %02X HOP: %02X", out[0], out[1], out[2]); |
| 597 | #endif |
| 598 | } |
| 599 | // Port 31 |
| 600 | static WRITE8_HANDLER( sammymdl_coin_w ) |
| 601 | { |
| 602 | coin_counter_w(space->machine, 0, data & 0x01 ); // coin1 in |
| 603 | coin_counter_w(space->machine, 1, data & 0x02 ); // coin2 in |
| 604 | coin_counter_w(space->machine, 2, data & 0x04 ); // medal in |
| 605 | |
| 606 | coin_lockout_w(space->machine, 1, (~data) & 0x08 ); // coin2 lockout? |
| 607 | coin_lockout_w(space->machine, 0, (~data) & 0x10 ); // coin1 lockout |
| 608 | coin_lockout_w(space->machine, 2, (~data) & 0x20 ); // medal lockout? |
| 609 | |
| 610 | out[0] = data; |
| 611 | show_3_outputs(); |
| 612 | } |
| 613 | |
| 614 | // Port 32 |
| 615 | static WRITE8_HANDLER( sammymdl_leds_w ) |
| 616 | { |
| 617 | set_led_status(space->machine, 0, data & 0x01); // button |
| 618 | |
| 619 | out[1] = data; |
| 620 | show_3_outputs(); |
| 621 | } |
| 622 | |
| 623 | // Port b0 |
| 624 | // 02 hopper enable? |
| 625 | // 01 hopper motor on (active low)? |
| 626 | static WRITE8_HANDLER( sammymdl_hopper_w ) |
| 627 | { |
| 628 | ticket_dispenser_w(space->machine->device("hopper"), 0, (!(data & 0x01) && (data & 0x02)) ? 0x00 : 0x80); |
| 629 | |
| 630 | out[2] = data; |
| 631 | show_3_outputs(); |
| 632 | } |
| 633 | |
| 634 | static WRITE8_HANDLER( sammymdl_sound_w ) |
| 635 | { |
| 636 | } |
| 637 | |
| 638 | static READ8_HANDLER( sammymdl_coin_hopper_r ) |
| 639 | { |
| 640 | UINT8 ret = input_port_read(space->machine, "COIN"); |
| 641 | |
| 642 | // if ( !ticket_dispenser_r(space->machine->device("hopper"), 0) ) |
| 643 | // ret &= ~0x01; |
| 644 | |
| 645 | return ret; |
| 646 | } |
| 647 | |
| 648 | static UINT8 *nvram; |
| 649 | static ADDRESS_MAP_START( animalc_map, ADDRESS_SPACE_PROGRAM, 8 ) |
| 650 | AM_RANGE( 0x0000, 0x3fff ) AM_ROM |
| 651 | AM_RANGE( 0x4000, 0x7fff ) AM_ROMBANK( "rombank" ) |
| 652 | AM_RANGE( 0x8000, 0x8fff ) AM_RAMBANK( "rambank" ) AM_SHARE( "nvram" ) AM_BASE( &nvram ) |
| 653 | |
| 654 | AM_RANGE( 0x9000, 0x9fff ) AM_RAM |
| 655 | AM_RANGE( 0xa000, 0xafff ) AM_RAM |
| 656 | AM_RANGE( 0xb000, 0xbfff ) AM_RAMBANK("sprbank") |
| 657 | |
| 658 | AM_RANGE( 0xd000, 0xd1ff ) AM_RAM_WRITE( paletteram_xRRRRRGGGGGBBBBB_be_w ) AM_BASE_GENERIC( paletteram ) |
| 659 | AM_RANGE( 0xd800, 0xd87f ) AM_RAM // ? |
| 660 | |
| 661 | AM_RANGE( 0xe011, 0xe011 ) AM_WRITENOP // IRQ Enable? Screen disable? |
| 662 | AM_RANGE( 0xe013, 0xe013 ) AM_READWRITE( vblank_r, vblank_w ) // IRQ Ack? |
| 663 | |
| 664 | AM_RANGE( 0xfe00, 0xffff ) AM_RAM |
| 665 | ADDRESS_MAP_END |
| 666 | |
| 667 | static ADDRESS_MAP_START( animalc_io, ADDRESS_SPACE_IO, 8 ) |
| 668 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 669 | AM_RANGE( 0x02, 0x03 ) AM_READWRITE( animalc_rombank_r, animalc_rombank_w ) |
| 670 | AM_RANGE( 0x04, 0x05 ) AM_READWRITE( animalc_rambank_r, animalc_rambank_w ) |
| 671 | |
| 672 | AM_RANGE( 0x2c, 0x2c ) AM_DEVREADWRITE( "eeprom", sammymdl_eeprom_r, sammymdl_eeprom_w ) |
| 673 | AM_RANGE( 0x2e, 0x2e ) AM_READ( sammymdl_coin_hopper_r ) |
| 674 | AM_RANGE( 0x30, 0x30 ) AM_READ_PORT( "BUTTON" ) |
| 675 | AM_RANGE( 0x31, 0x31 ) AM_WRITE( sammymdl_coin_w ) |
| 676 | AM_RANGE( 0x32, 0x32 ) AM_WRITE( sammymdl_leds_w ) |
| 677 | AM_RANGE( 0x34, 0x34 ) AM_READ( unk_34_r ) |
| 678 | AM_RANGE( 0x90, 0x91 ) AM_WRITE( sammymdl_sound_w ) |
| 679 | AM_RANGE( 0xb0, 0xb0 ) AM_WRITE( sammymdl_hopper_w ) |
| 680 | AM_RANGE( 0xc0, 0xc0 ) AM_WRITE( watchdog_reset_w ) // 1 |
| 681 | ADDRESS_MAP_END |
| 682 | |
| 683 | /*************************************************************************** |
| 684 | Itazura Monkey |
| 685 | ***************************************************************************/ |
| 686 | |
| 687 | // rombank |
| 688 | static WRITE8_HANDLER( itazuram_rombank_w ) |
| 689 | { |
| 690 | if (offset == 0) |
| 691 | { |
| 692 | reg = data; |
| 693 | return; |
| 694 | } |
| 695 | |
| 696 | UINT8 *rom = space->machine->region("maincpu")->base(); |
| 697 | switch ( reg ) |
| 698 | { |
| 699 | case 0x0d: |
| 700 | rombank = data; |
| 701 | switch (data) |
| 702 | { |
| 703 | case 0x11: // 3800 IS ROM |
| 704 | memory_set_bankptr(space->machine, "rombank0", rom + 0x4c00); |
| 705 | memory_set_bankptr(space->machine, "rombank1", rom + 0x5c00); |
| 706 | memory_set_bankptr(space->machine, "sprbank0", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 707 | memory_set_bankptr(space->machine, "sprbank1", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 708 | break; |
| 709 | |
| 710 | default: |
| 711 | logerror("%s: unknown rom bank = %02x, reg = %02x\n", space->machine->describe_context(), data, reg); |
| 712 | } |
| 713 | break; |
| 714 | |
| 715 | case 0x4d: |
| 716 | rombank = data; |
| 717 | switch (data) |
| 718 | { |
| 719 | case 0x14: // 3800 IS ROM |
| 720 | memory_set_bankptr(space->machine, "rombank0", rom + 0x8000); |
| 721 | memory_set_bankptr(space->machine, "rombank1", rom + 0x9000); |
| 722 | memory_set_bankptr(space->machine, "sprbank0", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 723 | memory_set_bankptr(space->machine, "sprbank1", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 724 | break; |
| 725 | |
| 726 | default: |
| 727 | logerror("%s: unknown rom bank = %02x, reg = %02x\n", space->machine->describe_context(), data, reg); |
| 728 | } |
| 729 | break; |
| 730 | |
| 731 | case 0x8d: |
| 732 | rombank = data; |
| 733 | switch (data) |
| 734 | { |
| 735 | case 0x0f: // 3800 IS ROM |
| 736 | memory_set_bankptr(space->machine, "rombank0", rom + 0x3400); |
| 737 | memory_set_bankptr(space->machine, "rombank1", rom + 0x4400); |
| 738 | memory_set_bankptr(space->machine, "sprbank0", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 739 | memory_set_bankptr(space->machine, "sprbank1", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 740 | break; |
| 741 | |
| 742 | case 0x12: // 3800 IS ROM |
| 743 | memory_set_bankptr(space->machine, "rombank0", rom + 0x6400); |
| 744 | memory_set_bankptr(space->machine, "rombank1", rom + 0x7400); |
| 745 | memory_set_bankptr(space->machine, "sprbank0", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 746 | memory_set_bankptr(space->machine, "sprbank1", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 747 | break; |
| 748 | |
| 749 | // used in test mode: |
| 750 | // case 0x5c: memory_set_bankptr(space->machine, "rombank", rom + 0x400 + 0x0000); break; // 3800 IS RAM! (8000 bytes) |
| 751 | |
| 752 | case 0x5e: // 3800 IS RAM! (1404 bytes) |
| 753 | memory_set_bankptr(space->machine, "rombank0", space->machine->generic.spriteram.u8 + 0x1000*1); |
| 754 | memory_set_bankptr(space->machine, "sprbank0", space->machine->generic.spriteram.u8 + 0x1000*1); |
| 755 | memory_set_bankptr(space->machine, "rombank1", space->machine->generic.spriteram.u8 + 0x1000*2); |
| 756 | memory_set_bankptr(space->machine, "sprbank1", space->machine->generic.spriteram.u8 + 0x1000*2); |
| 757 | break; |
| 758 | |
| 759 | case 0x6c: // 3800 IS RAM! (1000 bytes) - SPRITERAM |
| 760 | memory_set_bankptr(space->machine, "rombank0", space->machine->generic.spriteram.u8); |
| 761 | memory_set_bankptr(space->machine, "sprbank0", space->machine->generic.spriteram.u8); |
| 762 | // memory_set_bankptr(space->machine, "sprbank1", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 763 | break; |
| 764 | |
| 765 | default: |
| 766 | logerror("%s: unknown rom bank = %02x, reg = %02x\n", space->machine->describe_context(), data, reg); |
| 767 | } |
| 768 | break; |
| 769 | |
| 770 | case 0xcd: |
| 771 | rombank = data; |
| 772 | switch (data) |
| 773 | { |
| 774 | case 0x14: // 3800 IS ROM |
| 775 | memory_set_bankptr(space->machine, "rombank0", rom + 0x8800); |
| 776 | memory_set_bankptr(space->machine, "rombank1", rom + 0x9800); |
| 777 | memory_set_bankptr(space->machine, "sprbank0", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 778 | memory_set_bankptr(space->machine, "sprbank1", space->machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 779 | break; |
| 780 | |
| 781 | default: |
| 782 | logerror("%s: unknown rom bank = %02x, reg = %02x\n", space->machine->describe_context(), data, reg); |
| 783 | } |
| 784 | break; |
| 785 | |
| 786 | default: |
| 787 | logerror("%s: unknown reg written: %02x = %02x\n", space->machine->describe_context(), reg, data); |
| 788 | } |
| 789 | } |
| 790 | static READ8_HANDLER( itazuram_rombank_r ) |
| 791 | { |
| 792 | if (offset == 0) |
| 793 | return reg; |
| 794 | |
| 795 | switch ( reg ) |
| 796 | { |
| 797 | // FIXME different registers |
| 798 | case 0x0d: |
| 799 | case 0x4d: |
| 800 | case 0x8d: |
| 801 | case 0xcd: |
| 802 | return rombank; |
| 803 | |
| 804 | default: |
| 805 | logerror("%s: unknown reg read: %02x\n", space->machine->describe_context(), reg); |
| 806 | return 0x00; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | // rambank |
| 811 | static WRITE8_HANDLER( itazuram_rambank_w ) |
| 812 | { |
| 813 | if (offset == 0) |
| 814 | { |
| 815 | reg2 = data; |
| 816 | return; |
| 817 | } |
| 818 | |
| 819 | switch ( reg2 ) |
| 820 | { |
| 821 | case 0x76: |
| 822 | rambank = data; |
| 823 | switch (data) |
| 824 | { |
| 825 | case 0x52: memory_set_bankptr(space->machine, "palbank", nvram); break; |
| 826 | case 0x64: memory_set_bankptr(space->machine, "palbank", space->machine->generic.paletteram.u8); break; |
| 827 | default: |
| 828 | logerror("%s: unknown ram bank = %02x, reg2 = %02x\n", space->machine->describe_context(), data, reg2); |
| 829 | return; |
| 830 | } |
| 831 | break; |
| 832 | |
| 833 | default: |
| 834 | logerror("%s: unknown reg2 written: %02x = %02x\n", space->machine->describe_context(), reg2, data); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | static READ8_HANDLER( itazuram_rambank_r ) |
| 839 | { |
| 840 | if (offset == 0) |
| 841 | return reg2; |
| 842 | |
| 843 | switch ( reg2 ) |
| 844 | { |
| 845 | case 0x76: |
| 846 | return rambank; |
| 847 | |
| 848 | default: |
| 849 | logerror("%s: unknown reg2 read: %02x\n", space->machine->describe_context(), reg2); |
| 850 | return 0x00; |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | static WRITE8_HANDLER( itazuram_nvram_palette_w ) |
| 855 | { |
| 856 | if (rambank == 0x64) |
| 857 | { |
| 858 | paletteram_xRRRRRGGGGGBBBBB_be_w(space, offset, data); |
| 859 | // space->machine->generic.paletteram.u8[offset] = data; |
| 860 | } |
| 861 | else if (rambank == 0x52) |
| 862 | { |
| 863 | nvram[offset] = data; |
| 864 | } |
| 865 | else |
| 866 | { |
| 867 | logerror("%s: itazuram_nvram_palette_w offset = %03x with unknown bank = %02x\n", space->machine->describe_context(), offset, rambank); |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | static WRITE8_HANDLER( itazuram_palette_w ) |
| 872 | { |
| 873 | if (rombank == 0x6c) |
| 874 | { |
| 875 | if (offset < 0x200) |
| 876 | paletteram_xRRRRRGGGGGBBBBB_be_w(space, offset, data); |
| 877 | // space->machine->generic.paletteram.u8[offset] = data; |
| 878 | } |
| 879 | else |
| 880 | { |
| 881 | logerror("%s: itazuram_palette_w offset = %03x with unknown bank = %02x\n", space->machine->describe_context(), offset, rombank); |
| 882 | } |
| 883 | } |
| 884 | static READ8_HANDLER( itazuram_palette_r ) |
| 885 | { |
| 886 | return space->machine->generic.paletteram.u8[offset]; |
| 887 | } |
| 888 | |
| 889 | static ADDRESS_MAP_START( itazuram_map, ADDRESS_SPACE_PROGRAM, 8 ) |
| 890 | AM_RANGE( 0x0000, 0x37ff ) AM_ROM |
| 891 | AM_RANGE( 0x3800, 0x47ff ) AM_READ_BANK( "rombank0" ) AM_WRITE_BANK( "sprbank0" ) |
| 892 | AM_RANGE( 0x4800, 0x57ff ) AM_READ_BANK( "rombank1" ) AM_WRITE_BANK( "sprbank1" ) |
| 893 | |
| 894 | AM_RANGE( 0x5800, 0x59ff ) AM_READWRITE( itazuram_palette_r, itazuram_palette_w ) |
| 895 | AM_RANGE( 0x6000, 0x607f ) AM_RAM // ? |
| 896 | |
| 897 | AM_RANGE( 0x6811, 0x6811 ) AM_WRITENOP // IRQ Enable? Screen disable? |
| 898 | AM_RANGE( 0x6813, 0x6813 ) AM_WRITENOP // IRQ Ack? |
| 899 | AM_RANGE( 0xdc00, 0xfdff ) AM_READ_BANK( "palbank" ) AM_WRITE( itazuram_nvram_palette_w ) AM_SHARE( "nvram" ) AM_BASE( &nvram ) // nvram | paletteram |
| 900 | |
| 901 | AM_RANGE( 0xfe00, 0xffff ) AM_RAM |
| 902 | ADDRESS_MAP_END |
| 903 | |
| 904 | static ADDRESS_MAP_START( itazuram_io, ADDRESS_SPACE_IO, 8 ) |
| 905 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 906 | AM_RANGE( 0x02, 0x03 ) AM_READWRITE( itazuram_rombank_r, itazuram_rombank_w ) |
| 907 | AM_RANGE( 0x04, 0x05 ) AM_READWRITE( itazuram_rambank_r, itazuram_rambank_w ) |
| 908 | |
| 909 | AM_RANGE( 0x2c, 0x2c ) AM_DEVREADWRITE( "eeprom", sammymdl_eeprom_r, sammymdl_eeprom_w ) |
| 910 | AM_RANGE( 0x2e, 0x2e ) AM_READ( sammymdl_coin_hopper_r ) |
| 911 | AM_RANGE( 0x30, 0x30 ) AM_READ_PORT( "BUTTON" ) |
| 912 | AM_RANGE( 0x31, 0x31 ) AM_WRITE( sammymdl_coin_w ) |
| 913 | AM_RANGE( 0x32, 0x32 ) AM_WRITE( sammymdl_leds_w ) |
| 914 | AM_RANGE( 0x90, 0x91 ) AM_WRITE( sammymdl_sound_w ) // sound |
| 915 | AM_RANGE( 0xb0, 0xb0 ) AM_WRITE( sammymdl_hopper_w ) |
| 916 | AM_RANGE( 0xc0, 0xc0 ) AM_WRITE( watchdog_reset_w ) // 1 |
| 917 | ADDRESS_MAP_END |
| 918 | |
| 919 | /*************************************************************************** |
| 920 | |
| 368 | 921 | Graphics Layout |
| 369 | 922 | |
| 370 | 923 | ***************************************************************************/ |
| r10330 | r10331 | |
| 393 | 946 | |
| 394 | 947 | static GFXDECODE_START( sigmab98 ) |
| 395 | 948 | GFXDECODE_ENTRY( "sprites", 0, sigmab98_16x16x4_layout, 0, 0x100/16 ) |
| 396 | | GFXDECODE_ENTRY( "sprites", 0, sigmab98_16x16x8_layout, 0, 0x100/256 ) |
| 949 | GFXDECODE_ENTRY( "sprites", 0, sigmab98_16x16x8_layout, 0, 0x100/256 ) |
| 397 | 950 | GFXDECODE_END |
| 398 | 951 | |
| 399 | 952 | |
| r10330 | r10331 | |
| 403 | 956 | |
| 404 | 957 | ***************************************************************************/ |
| 405 | 958 | |
| 959 | /*************************************************************************** |
| 960 | GeGeGe no Kitarou Youkai Slot |
| 961 | ***************************************************************************/ |
| 962 | |
| 406 | 963 | static INPUT_PORTS_START( gegege ) |
| 407 | 964 | |
| 408 | 965 | PORT_START("EEPROM") |
| r10330 | r10331 | |
| 437 | 994 | |
| 438 | 995 | INPUT_PORTS_END |
| 439 | 996 | |
| 997 | /*************************************************************************** |
| 998 | Sammy Medal Games |
| 999 | ***************************************************************************/ |
| 440 | 1000 | |
| 1001 | static INPUT_PORTS_START( sammymdl ) |
| 1002 | PORT_START("BUTTON") |
| 1003 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) // shot |
| 1004 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) // freeze (itazuram) |
| 1005 | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1006 | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1007 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1008 | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1009 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1010 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1011 | |
| 1012 | PORT_START("COIN") |
| 1013 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(5) // coin1 in |
| 1014 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_IMPULSE(5) // coin2 in |
| 1015 | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 ) PORT_IMPULSE(5) // medal in |
| 1016 | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE ) // test sw |
| 1017 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1018 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_READ_LINE_DEVICE("hopper", ticket_dispenser_line_r) |
| 1019 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1020 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1021 | INPUT_PORTS_END |
| 1022 | |
| 1023 | |
| 441 | 1024 | /*************************************************************************** |
| 442 | 1025 | |
| 443 | 1026 | Machine Drivers |
| 444 | 1027 | |
| 445 | 1028 | ***************************************************************************/ |
| 446 | 1029 | |
| 1030 | /*************************************************************************** |
| 1031 | GeGeGe no Kitarou Youkai Slot |
| 1032 | ***************************************************************************/ |
| 1033 | |
| 447 | 1034 | const eeprom_interface eeprom_intf = |
| 448 | 1035 | { |
| 449 | 1036 | 6, // address bits 6 |
| r10330 | r10331 | |
| 475 | 1062 | |
| 476 | 1063 | MCFG_SCREEN_ADD("screen", RASTER) |
| 477 | 1064 | MCFG_SCREEN_REFRESH_RATE(60) // ? |
| 478 | | MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) |
| 1065 | MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */) // game reads vblank state |
| 479 | 1066 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 480 | 1067 | MCFG_SCREEN_SIZE(0x200, 0x200) |
| 481 | 1068 | MCFG_SCREEN_VISIBLE_AREA(0,0x140-1, 0,0xf0-1) |
| r10330 | r10331 | |
| 493 | 1080 | MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) |
| 494 | 1081 | MACHINE_CONFIG_END |
| 495 | 1082 | |
| 1083 | /*************************************************************************** |
| 1084 | Animal Catch |
| 1085 | ***************************************************************************/ |
| 496 | 1086 | |
| 1087 | static const eeprom_interface eeprom_interface_93C46_8bit = |
| 1088 | { |
| 1089 | 7, // address bits 6 |
| 1090 | 8, // data bits 8 |
| 1091 | "*110", // read 1 10 aaaaaa |
| 1092 | "*101", // write 1 01 aaaaaa dddddddd |
| 1093 | "*111", // erase 1 11 aaaaaa |
| 1094 | "*10000xxxx", // lock 1 00 00xxxx |
| 1095 | "*10011xxxx", // unlock 1 00 11xxxx |
| 1096 | 0, // enable_multi_read |
| 1097 | 1 // reset_delay (needed by animalc) |
| 1098 | // "*10001xxxx" // write all 1 00 01xxxx dddddddd |
| 1099 | // "*10010xxxx" // erase all 1 00 10xxxx |
| 1100 | }; |
| 1101 | |
| 1102 | static MACHINE_RESET( sammymdl ) |
| 1103 | { |
| 1104 | cpu_set_reg(machine->device("maincpu"), Z80_PC, 0x400); // code starts at 400 ??? (000 = cart header) |
| 1105 | } |
| 1106 | |
| 1107 | static INTERRUPT_GEN( animalc ) |
| 1108 | { |
| 1109 | switch (cpu_getiloops(device)) |
| 1110 | { |
| 1111 | case 0: |
| 1112 | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x00); // increment counter |
| 1113 | break; |
| 1114 | |
| 1115 | case 1: |
| 1116 | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x1c); // read hopper state |
| 1117 | break; |
| 1118 | |
| 1119 | case 2: |
| 1120 | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x1e); // drive hopper motor |
| 1121 | break; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | // Everything here is a guess: |
| 1126 | static MACHINE_CONFIG_START( animalc, driver_device ) |
| 1127 | MCFG_CPU_ADD("maincpu", Z80, 8000000) // ??? |
| 1128 | MCFG_CPU_PROGRAM_MAP( animalc_map ) |
| 1129 | MCFG_CPU_IO_MAP( animalc_io ) |
| 1130 | MCFG_CPU_VBLANK_INT_HACK(animalc, 3) // IM 2 needs a vector on the data bus |
| 1131 | |
| 1132 | MCFG_MACHINE_RESET( sammymdl ) |
| 1133 | |
| 1134 | MCFG_NVRAM_ADD_0FILL("nvram") // battery |
| 1135 | MCFG_EEPROM_ADD("eeprom", eeprom_interface_93C46_8bit) |
| 1136 | |
| 1137 | MCFG_TICKET_DISPENSER_ADD("hopper", 200, TICKET_MOTOR_ACTIVE_LOW, TICKET_STATUS_ACTIVE_LOW ) |
| 1138 | |
| 1139 | // video hardware |
| 1140 | MCFG_SCREEN_ADD("screen", RASTER) |
| 1141 | MCFG_SCREEN_REFRESH_RATE(60) |
| 1142 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 1143 | MCFG_SCREEN_SIZE(0x140, 0x100) |
| 1144 | MCFG_SCREEN_VISIBLE_AREA(0, 0x140-1, 0, 0xf0-1) |
| 1145 | |
| 1146 | MCFG_GFXDECODE(sigmab98) |
| 1147 | MCFG_PALETTE_LENGTH(0x100) |
| 1148 | |
| 1149 | MCFG_VIDEO_UPDATE(sigmab98) |
| 1150 | MCFG_VIDEO_EOF(sammymdl) |
| 1151 | |
| 1152 | // sound hardware |
| 1153 | // OKI MSM981x ? |
| 1154 | MACHINE_CONFIG_END |
| 1155 | |
| 497 | 1156 | /*************************************************************************** |
| 1157 | Itazura Monkey |
| 1158 | ***************************************************************************/ |
| 498 | 1159 | |
| 1160 | static INTERRUPT_GEN( itazuram ) |
| 1161 | { |
| 1162 | switch (cpu_getiloops(device)) |
| 1163 | { |
| 1164 | case 0: |
| 1165 | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x00); // sprites |
| 1166 | break; |
| 1167 | |
| 1168 | case 1: |
| 1169 | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x02); // copy palette |
| 1170 | break; |
| 1171 | |
| 1172 | case 2: |
| 1173 | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x16); // hopper, i/o |
| 1174 | break; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | // Everything here is a guess: |
| 1179 | static MACHINE_CONFIG_START( itazuram, driver_device ) |
| 1180 | MCFG_CPU_ADD("maincpu", Z80, 8000000) // ??? |
| 1181 | MCFG_CPU_PROGRAM_MAP( itazuram_map ) |
| 1182 | MCFG_CPU_IO_MAP( itazuram_io ) |
| 1183 | MCFG_CPU_VBLANK_INT_HACK(itazuram, 3) // IM 2 needs a vector on the data bus |
| 1184 | |
| 1185 | MCFG_MACHINE_RESET( sammymdl ) |
| 1186 | |
| 1187 | MCFG_NVRAM_ADD_0FILL("nvram") // battery |
| 1188 | MCFG_EEPROM_ADD("eeprom", eeprom_interface_93C46_8bit) |
| 1189 | |
| 1190 | MCFG_TICKET_DISPENSER_ADD("hopper", 200, TICKET_MOTOR_ACTIVE_LOW, TICKET_STATUS_ACTIVE_LOW ) |
| 1191 | |
| 1192 | // video hardware |
| 1193 | MCFG_SCREEN_ADD("screen", RASTER) |
| 1194 | MCFG_SCREEN_REFRESH_RATE(60) |
| 1195 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 1196 | MCFG_SCREEN_SIZE(0x140, 0x100) |
| 1197 | MCFG_SCREEN_VISIBLE_AREA(0, 0x140-1, 0, 0xf0-1) |
| 1198 | |
| 1199 | MCFG_GFXDECODE(sigmab98) |
| 1200 | MCFG_PALETTE_LENGTH(0x100) |
| 1201 | |
| 1202 | MCFG_VIDEO_UPDATE(sigmab98) |
| 1203 | // MCFG_VIDEO_EOF(sammymdl) |
| 1204 | |
| 1205 | // sound hardware |
| 1206 | // OKI MSM981x ? |
| 1207 | MACHINE_CONFIG_END |
| 1208 | |
| 1209 | |
| 1210 | /*************************************************************************** |
| 1211 | |
| 499 | 1212 | ROMs Loading |
| 500 | 1213 | |
| 501 | 1214 | ***************************************************************************/ |
| r10330 | r10331 | |
| 576 | 1289 | |
| 577 | 1290 | /*************************************************************************** |
| 578 | 1291 | |
| 1292 | Animal Catch ( VX2002L02 ANIMALCAT 200011211536 SAMMY CORP. AM ) |
| 1293 | |
| 1294 | Sammy AM3ADT-01 Memory Card Type 3: |
| 1295 | 1 x MX29F1610ATC-12 (@U021) |
| 1296 | 1 x MX29F1610TC-12 (@U016) |
| 1297 | |
| 1298 | ***************************************************************************/ |
| 1299 | |
| 1300 | ROM_START( animalc ) |
| 1301 | ROM_REGION( 0x200000, "samples", 0 ) |
| 1302 | ROM_LOAD( "vx2302l01.u021", 0x00000, 0x200000, CRC(84cf123b) SHA1(d8b425c93ff1a560e3f92c70d7eb93a05c3581af) ) |
| 1303 | |
| 1304 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 1305 | ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 ) |
| 1306 | |
| 1307 | ROM_REGION( 0x200000, "sprites", 0 ) |
| 1308 | // tiles end abruptly at 1A00, but a few tiles above that are needed |
| 1309 | ROM_LOAD( "vx2301l01.u016", 0x00000, 0x200000, BAD_DUMP CRC(c3a9ca47) SHA1(812bbcfe3b789eadb5adb4c8141303fc046d52c9) ) // 1xxxxxxxxxxxxxxxxxxxx = 0x00 |
| 1310 | ROM_END |
| 1311 | |
| 1312 | static DRIVER_INIT( animalc ) |
| 1313 | { |
| 1314 | // RAM banks |
| 1315 | UINT8 *bankedram = auto_alloc_array(machine, UINT8, 0x1000 * 5); |
| 1316 | memory_configure_bank(machine, "rambank", 0, 1, nvram, 0x1000); |
| 1317 | memory_configure_bank(machine, "rambank", 1, 4, bankedram, 0x1000); |
| 1318 | memory_set_bank(machine, "rambank", 0); |
| 1319 | |
| 1320 | machine->generic.spriteram.u8 = auto_alloc_array(machine, UINT8, 0x1000 * 5); |
| 1321 | memset(machine->generic.spriteram.u8, 0, 0x1000 * 5); |
| 1322 | machine->generic.spriteram_size = 0x1000; |
| 1323 | memory_configure_bank(machine, "sprbank", 0, 5, machine->generic.spriteram.u8, 0x1000); |
| 1324 | memory_set_bank(machine, "sprbank", 0); |
| 1325 | |
| 1326 | #if 0 |
| 1327 | // uncomment to show used tiles missing from the dump |
| 1328 | UINT8 *gfx = machine->region("sprites")->base(); |
| 1329 | for (int i = 0x1a00*(16*16*4/8); i < 0x100000; i++) |
| 1330 | gfx[i] = i*7; |
| 1331 | #endif |
| 1332 | } |
| 1333 | |
| 1334 | /*************************************************************************** |
| 1335 | |
| 1336 | Itazura Monkey ( VX1902L02 ITZRMONKY 200011211639 SAMMY CORP. AM ) |
| 1337 | |
| 1338 | Sammy AM3ADT-01 Memory Card Type 3: |
| 1339 | 2 x MX29F1610ATC-12 |
| 1340 | |
| 1341 | ***************************************************************************/ |
| 1342 | |
| 1343 | ROM_START( itazuram ) |
| 1344 | ROM_REGION( 0x200000, "samples", 0 ) |
| 1345 | ROM_LOAD( "vx2002l01.u021", 0x00000, 0x200000, CRC(ddbdd2f3) SHA1(91f67a938929be0261442e066e3d2c03b5e9f06a) ) |
| 1346 | |
| 1347 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 1348 | ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 ) |
| 1349 | |
| 1350 | ROM_REGION( 0x200000, "sprites", 0 ) |
| 1351 | ROM_LOAD( "vx2001l01.u016", 0x00000, 0x200000, CRC(9ee95222) SHA1(7154d43ef312a48a882207ca37e1c61e8b215a9b) ) |
| 1352 | ROM_END |
| 1353 | |
| 1354 | static DRIVER_INIT( itazuram ) |
| 1355 | { |
| 1356 | // ROM banks |
| 1357 | UINT8 *rom = machine->region("maincpu")->base(); |
| 1358 | memory_set_bankptr(machine, "rombank0", rom + 0x3400); |
| 1359 | memory_set_bankptr(machine, "rombank1", rom + 0x4400); |
| 1360 | rombank = 0x0f; |
| 1361 | |
| 1362 | // RAM banks |
| 1363 | machine->generic.paletteram.u8 = auto_alloc_array(machine, UINT8, 0x3000); |
| 1364 | memset(machine->generic.paletteram.u8, 0, 0x3000); |
| 1365 | memory_set_bankptr(machine, "palbank", machine->generic.paletteram.u8); |
| 1366 | rambank = 0x64; |
| 1367 | |
| 1368 | machine->generic.spriteram.u8 = auto_alloc_array(machine, UINT8, 0x1000 * 5); |
| 1369 | memset(machine->generic.spriteram.u8, 0, 0x1000 * 5); |
| 1370 | machine->generic.spriteram_size = 0x1000; |
| 1371 | memory_set_bankptr(machine, "sprbank0", machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 1372 | memory_set_bankptr(machine, "sprbank1", machine->generic.spriteram.u8 + 0x1000*4); // scratch |
| 1373 | } |
| 1374 | |
| 1375 | /*************************************************************************** |
| 1376 | |
| 1377 | Taihou de Doboon ( EM4210L01 PUSHERDBN 200203151028 SAMMY CORP. AM ) |
| 1378 | |
| 1379 | Sammy AM3ADT-01 Memory Card Type 3: |
| 1380 | 2 x MX29F1610ATC-12 |
| 1381 | |
| 1382 | The flash roms found in the cart are labeled: |
| 1383 | |
| 1384 | vx1801l01.u016 |
| 1385 | vx1802l01.u021 |
| 1386 | |
| 1387 | which correspond to "Pye-nage Taikai". But they were reflashed with the |
| 1388 | software noted in the sticker on the back of the cart (rom names reflect that): |
| 1389 | |
| 1390 | System: Treasure Hall |
| 1391 | Soft: Taihou de Doboon |
| 1392 | 2003.02.14 |
| 1393 | Char Rev: EM4209L01 |
| 1394 | Pro Rev: EM4210L01 |
| 1395 | |
| 1396 | ***************************************************************************/ |
| 1397 | |
| 1398 | ROM_START( tdoboon ) |
| 1399 | ROM_REGION( 0x200000, "samples", 0 ) |
| 1400 | ROM_LOAD( "em4210l01.u021.bin", 0x00000, 0x200000, CRC(3523e314) SHA1(d07c5d17d3f285be4cde810547f427e84f98968f) ) |
| 1401 | |
| 1402 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 1403 | ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 ) |
| 1404 | |
| 1405 | ROM_REGION( 0x200000, "sprites", 0 ) |
| 1406 | ROM_LOAD( "em4209l01.u016.bin", 0x00000, 0x200000, CRC(aca220fa) SHA1(7db441add16af554700e597fd9926b6ccd19d628) ) // 1xxxxxxxxxxxxxxxxxxxx = 0xFF |
| 1407 | ROM_END |
| 1408 | |
| 1409 | /*************************************************************************** |
| 1410 | |
| 1411 | Pye-nage Taikai ( VX1802L01 PAINAGETK 200011021216 SAMMY CORP. AM. ) |
| 1412 | |
| 1413 | Sammy AM3ADT-01 Memory Card Type 3: |
| 1414 | 2 x MX29F1610ATC-12 |
| 1415 | |
| 1416 | ***************************************************************************/ |
| 1417 | |
| 1418 | ROM_START( pyenaget ) |
| 1419 | ROM_REGION( 0x200000, "samples", 0 ) |
| 1420 | ROM_LOAD( "vx1802l01.u021", 0x00000, 0x200000, CRC(7a22a657) SHA1(2a98085862fd958209253c5401e41eae4f7c06ea) ) |
| 1421 | |
| 1422 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 1423 | ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 ) |
| 1424 | |
| 1425 | ROM_REGION( 0x200000, "sprites", 0 ) |
| 1426 | ROM_LOAD( "vx1801l01.u016", 0x00000, 0x200000, CRC(c4607403) SHA1(f4f4699442afccc5ed4354447f91b1bee36ae3e5) ) |
| 1427 | ROM_END |
| 1428 | |
| 1429 | /*************************************************************************** |
| 1430 | |
| 1431 | Hae Hae Ka Ka Ka ( EM4208L01 PUSHERHAEHAE 200203151032 SAMMY CORP. AM ) |
| 1432 | |
| 1433 | Sammy AM3ADT-01 Memory Card Type 3: |
| 1434 | 2 x MX29F1610ATC-12 |
| 1435 | |
| 1436 | The flash roms found in the cart are labeled: |
| 1437 | |
| 1438 | vx1801l01.u016 |
| 1439 | vx1802l01.u021 |
| 1440 | |
| 1441 | which correspond to "Pye-nage Taikai". But they were reflashed with the |
| 1442 | software noted in the sticker on the back of the cart (rom names reflect that): |
| 1443 | |
| 1444 | System: Treasure Hall |
| 1445 | Soft: Hae Hae Ka Ka Ka |
| 1446 | 2003.02.14 |
| 1447 | Char Rev: EM4207L01 |
| 1448 | Pro Rev: EM4208L01 |
| 1449 | |
| 1450 | ***************************************************************************/ |
| 1451 | |
| 1452 | ROM_START( haekaka ) |
| 1453 | ROM_REGION( 0x200000, "samples", 0 ) |
| 1454 | ROM_LOAD( "em4208l01.u021.bin", 0x00000, 0x200000, CRC(d23bb748) SHA1(38d5b6c4b2cd470b3a68574aeca3f9fa9032245e) ) |
| 1455 | |
| 1456 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 1457 | ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 ) |
| 1458 | |
| 1459 | ROM_REGION( 0x200000, "sprites", 0 ) |
| 1460 | ROM_LOAD( "em4207l01.u016.bin", 0x00000, 0x200000, CRC(3876961c) SHA1(3d842c1f63ea5aa7e799967928b86c5fabb4e65e) ) |
| 1461 | ROM_END |
| 1462 | |
| 1463 | /*************************************************************************** |
| 1464 | |
| 579 | 1465 | Game Drivers |
| 580 | 1466 | |
| 581 | 1467 | ***************************************************************************/ |
| 582 | 1468 | |
| 583 | | GAME( 1997, gegege, 0, gegege, gegege, gegege, ROT0, "Banpresto / Sigma", "GeGeGe no Kitarou Youkai Slot", 0 ) |
| 1469 | GAME( 1997, gegege, 0, gegege, gegege, gegege, ROT0, "Banpresto / Sigma", "GeGeGe no Kitarou Youkai Slot", 0 ) |
| 1470 | // Sammy Medal Games: |
| 1471 | GAME( 2000, animalc, 0, animalc, sammymdl, animalc, ROT0, "Sammy", "Animal Catch", GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS ) |
| 1472 | GAME( 2000, itazuram, 0, itazuram, sammymdl, itazuram, ROT0, "Sammy", "Itazura Monkey", GAME_NO_SOUND ) |
| 1473 | GAME( 2000, pyenaget, 0, animalc, sammymdl, 0, ROT0, "Sammy", "Pye-nage Taikai", GAME_NO_SOUND | GAME_NOT_WORKING ) |
| 1474 | GAME( 2002, haekaka, 0, animalc, sammymdl, 0, ROT0, "Sammy", "Hae Hae Ka Ka Ka", GAME_NO_SOUND | GAME_NOT_WORKING ) |
| 1475 | GAME( 2002, tdoboon, 0, animalc, sammymdl, 0, ROT0, "Sammy", "Taihou de Doboon", GAME_NO_SOUND | GAME_NOT_WORKING ) |
src/emu/state.c
| r10330 | r10331 | |
| 4 | 4 | |
| 5 | 5 | Save state management functions. |
| 6 | 6 | |
| 7 | | Copyright Nicola Salmoria and the MAME Team. |
| 8 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | **************************************************************************** |
| 9 | 8 | |
| 9 | Copyright Aaron Giles |
| 10 | All rights reserved. |
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions are |
| 14 | met: |
| 15 | |
| 16 | * Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | * Redistributions in binary form must reproduce the above copyright |
| 19 | notice, this list of conditions and the following disclaimer in |
| 20 | the documentation and/or other materials provided with the |
| 21 | distribution. |
| 22 | * Neither the name 'MAME' nor the names of its contributors may be |
| 23 | used to endorse or promote products derived from this software |
| 24 | without specific prior written permission. |
| 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR |
| 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 30 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 33 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 35 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | POSSIBILITY OF SUCH DAMAGE. |
| 37 | |
| 10 | 38 | **************************************************************************** |
| 11 | 39 | |
| 12 | 40 | Save state file format: |
| r10330 | r10331 | |
| 28 | 56 | #include <zlib.h> |
| 29 | 57 | |
| 30 | 58 | |
| 59 | //************************************************************************** |
| 60 | // DEBUGGING |
| 61 | //************************************************************************** |
| 31 | 62 | |
| 32 | | /*************************************************************************** |
| 33 | | DEBUGGING |
| 34 | | ***************************************************************************/ |
| 63 | #define VERBOSE 1 |
| 35 | 64 | |
| 36 | | #define VERBOSE 0 |
| 37 | | |
| 38 | 65 | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 39 | 66 | |
| 40 | 67 | |
| 41 | 68 | |
| 42 | | /*************************************************************************** |
| 43 | | CONSTANTS |
| 44 | | ***************************************************************************/ |
| 69 | //************************************************************************** |
| 70 | // CONSTANTS |
| 71 | //************************************************************************** |
| 45 | 72 | |
| 46 | | #define SAVE_VERSION 2 |
| 47 | | #define HEADER_SIZE 32 |
| 73 | const int SAVE_VERSION = 2; |
| 74 | const int HEADER_SIZE = 32; |
| 48 | 75 | |
| 49 | | /* Available flags */ |
| 76 | // Available flags |
| 50 | 77 | enum |
| 51 | 78 | { |
| 52 | 79 | SS_MSB_FIRST = 0x02 |
| r10330 | r10331 | |
| 54 | 81 | |
| 55 | 82 | |
| 56 | 83 | |
| 57 | | /*************************************************************************** |
| 58 | | TYPE DEFINITIONS |
| 59 | | ***************************************************************************/ |
| 84 | //************************************************************************** |
| 85 | // GLOBAL VARIABLES |
| 86 | //************************************************************************** |
| 60 | 87 | |
| 61 | | typedef struct _state_entry state_entry; |
| 62 | | struct _state_entry |
| 63 | | { |
| 64 | | state_entry * next; /* pointer to next entry */ |
| 65 | | running_machine * machine; /* pointer back to the owning machine */ |
| 66 | | void * data; /* pointer to the memory to save/restore */ |
| 67 | | astring name; /* full name */ |
| 68 | | UINT8 typesize; /* size of the raw data type */ |
| 69 | | UINT32 typecount; /* number of items */ |
| 70 | | UINT32 offset; /* offset within the final structure */ |
| 71 | | }; |
| 72 | | |
| 73 | | |
| 74 | | typedef struct _state_callback state_callback; |
| 75 | | struct _state_callback |
| 76 | | { |
| 77 | | state_callback * next; /* pointer to next entry */ |
| 78 | | running_machine * machine; /* pointer back to the owning machine */ |
| 79 | | void * param; /* function parameter */ |
| 80 | | union |
| 81 | | { |
| 82 | | state_presave_func presave; /* presave callback */ |
| 83 | | state_postload_func postload; /* postload callback */ |
| 84 | | } func; /* function pointers */ |
| 85 | | }; |
| 86 | | |
| 87 | | |
| 88 | | /* In mame.h: typedef struct _state_private state_private; */ |
| 89 | | struct _state_private |
| 90 | | { |
| 91 | | UINT8 reg_allowed; /* are registrations allowed? */ |
| 92 | | int illegal_regs; /* number of illegal registrations */ |
| 93 | | |
| 94 | | state_entry * entrylist; /* list of live entries */ |
| 95 | | state_callback * prefunclist; /* presave function list */ |
| 96 | | state_callback * postfunclist; /* postsave function list */ |
| 97 | | |
| 98 | | UINT8 * ioarray; /* array where we accumulate all the data */ |
| 99 | | UINT32 ioarraysize; /* size of the array */ |
| 100 | | mame_file * iofile; /* file currently in use */ |
| 101 | | }; |
| 102 | | |
| 103 | | |
| 104 | | |
| 105 | | /*************************************************************************** |
| 106 | | GLOBAL VARIABLES |
| 107 | | ***************************************************************************/ |
| 108 | | |
| 109 | 88 | #ifdef MESS |
| 110 | | static const char ss_magic_num[8] = { 'M', 'E', 'S', 'S', 'S', 'A', 'V', 'E' }; |
| 89 | const char state_manager::s_magic_num[8] = { 'M', 'E', 'S', 'S', 'S', 'A', 'V', 'E' }; |
| 111 | 90 | #else |
| 112 | | static const char ss_magic_num[8] = { 'M', 'A', 'M', 'E', 'S', 'A', 'V', 'E' }; |
| 91 | const char state_manager::s_magic_num[8] = { 'M', 'A', 'M', 'E', 'S', 'A', 'V', 'E' }; |
| 113 | 92 | #endif |
| 114 | 93 | |
| 115 | 94 | |
| 116 | 95 | |
| 117 | | /*************************************************************************** |
| 118 | | INLINE FUNCTIONS |
| 119 | | ***************************************************************************/ |
| 96 | //************************************************************************** |
| 97 | // INITIALIZATION |
| 98 | //************************************************************************** |
| 120 | 99 | |
| 121 | | /*------------------------------------------------- |
| 122 | | flip_data - reverse the endianness of a |
| 123 | | block of data |
| 124 | | -------------------------------------------------*/ |
| 100 | //------------------------------------------------- |
| 101 | // state_manager - constructor |
| 102 | //------------------------------------------------- |
| 125 | 103 | |
| 126 | | INLINE void flip_data(state_entry *entry) |
| 104 | state_manager::state_manager(running_machine &machine) |
| 105 | : m_machine(machine), |
| 106 | m_reg_allowed(true), |
| 107 | m_illegal_regs(0), |
| 108 | m_entry_list(machine.m_respool), |
| 109 | m_presave_list(machine.m_respool), |
| 110 | m_postload_list(machine.m_respool) |
| 127 | 111 | { |
| 128 | | UINT16 *data16; |
| 129 | | UINT32 *data32; |
| 130 | | UINT64 *data64; |
| 131 | | int count; |
| 112 | } |
| 132 | 113 | |
| 133 | | switch (entry->typesize) |
| 134 | | { |
| 135 | | case 2: |
| 136 | | data16 = (UINT16 *)entry->data; |
| 137 | | for (count = 0; count < entry->typecount; count++) |
| 138 | | data16[count] = FLIPENDIAN_INT16(data16[count]); |
| 139 | | break; |
| 140 | 114 | |
| 141 | | case 4: |
| 142 | | data32 = (UINT32 *)entry->data; |
| 143 | | for (count = 0; count < entry->typecount; count++) |
| 144 | | data32[count] = FLIPENDIAN_INT32(data32[count]); |
| 145 | | break; |
| 115 | //------------------------------------------------- |
| 116 | // allow_registration - allow/disallow |
| 117 | // registrations to happen |
| 118 | //------------------------------------------------- |
| 146 | 119 | |
| 147 | | case 8: |
| 148 | | data64 = (UINT64 *)entry->data; |
| 149 | | for (count = 0; count < entry->typecount; count++) |
| 150 | | data64[count] = FLIPENDIAN_INT64(data64[count]); |
| 151 | | break; |
| 152 | | } |
| 120 | void state_manager::allow_registration(bool allowed) |
| 121 | { |
| 122 | // allow/deny registration |
| 123 | m_reg_allowed = allowed; |
| 124 | if (!allowed) |
| 125 | dump_registry(); |
| 153 | 126 | } |
| 154 | 127 | |
| 155 | 128 | |
| 129 | //------------------------------------------------- |
| 130 | // indexed_item - return an item with the given |
| 131 | // index |
| 132 | //------------------------------------------------- |
| 156 | 133 | |
| 157 | | /*************************************************************************** |
| 158 | | INITIALIZATION |
| 159 | | ***************************************************************************/ |
| 160 | | |
| 161 | | /*------------------------------------------------- |
| 162 | | state_init - initialize the system and reset |
| 163 | | all registrations |
| 164 | | -------------------------------------------------*/ |
| 165 | | |
| 166 | | enum test_enum_type { test_val }; |
| 167 | | |
| 168 | | class test_class_type { public: int dummy; }; |
| 169 | | |
| 170 | | void state_init(running_machine *machine) |
| 134 | const char *state_manager::indexed_item(int index, void *&base, UINT32 &valsize, UINT32 &valcount) const |
| 171 | 135 | { |
| 172 | | bool test_bool = false; |
| 173 | | INT8 test_INT8 = 0; |
| 174 | | UINT8 test_UINT8 = 0; |
| 175 | | INT16 test_INT16 = 0; |
| 176 | | UINT16 test_UINT16 = 0; |
| 177 | | INT32 test_INT32 = 0; |
| 178 | | UINT32 test_UINT32 = 0; |
| 179 | | INT64 test_INT64 = 0; |
| 180 | | UINT64 test_UINT64 = 0; |
| 181 | | float test_float = 0.0f; |
| 182 | | double test_double = 0.0; |
| 183 | | test_enum_type test_enum = test_val; |
| 184 | | #ifdef __GNUC__ |
| 185 | | test_class_type test_class; |
| 186 | | #endif |
| 187 | | |
| 188 | | assert_always(IS_VALID_SAVE_TYPE(test_bool), "bool is not a valid type for save"); |
| 189 | | assert_always(IS_VALID_SAVE_TYPE(test_INT8), "INT8 is not a valid type for save"); |
| 190 | | assert_always(IS_VALID_SAVE_TYPE(test_UINT8), "UINT8 is not a valid type for save"); |
| 191 | | assert_always(IS_VALID_SAVE_TYPE(test_INT16), "INT16 is not a valid type for save"); |
| 192 | | assert_always(IS_VALID_SAVE_TYPE(test_UINT16), "UINT16 is not a valid type for save"); |
| 193 | | assert_always(IS_VALID_SAVE_TYPE(test_INT32), "INT32 is not a valid type for save"); |
| 194 | | assert_always(IS_VALID_SAVE_TYPE(test_UINT32), "UINT32 is not a valid type for save"); |
| 195 | | assert_always(IS_VALID_SAVE_TYPE(test_INT64), "INT64 is not a valid type for save"); |
| 196 | | assert_always(IS_VALID_SAVE_TYPE(test_UINT64), "UINT64 is not a valid type for save"); |
| 197 | | assert_always(IS_VALID_SAVE_TYPE(test_float), "float is not a valid type for save"); |
| 198 | | assert_always(IS_VALID_SAVE_TYPE(test_double), "double is not a valid type for save"); |
| 199 | | assert_always(IS_VALID_SAVE_TYPE(test_enum), "enums are not a valid type for save"); |
| 200 | | #ifdef __GNUC__ |
| 201 | | assert_always(!IS_VALID_SAVE_TYPE(test_class), "classes are a valid type for save"); |
| 202 | | #endif |
| 203 | | |
| 204 | | machine->state_data = auto_alloc_clear(machine, state_private); |
| 136 | state_entry *entry = m_entry_list.find(index); |
| 137 | if (entry == NULL) |
| 138 | return NULL; |
| 139 | |
| 140 | base = entry->m_data; |
| 141 | valsize = entry->m_typesize; |
| 142 | valcount = entry->m_typecount; |
| 143 | |
| 144 | return entry->m_name; |
| 205 | 145 | } |
| 206 | 146 | |
| 207 | 147 | |
| 208 | | /*------------------------------------------------- |
| 209 | | state_save_get_reg_count - return the number |
| 210 | | of total registrations so far |
| 211 | | -------------------------------------------------*/ |
| 148 | //------------------------------------------------- |
| 149 | // register_presave - register a pre-save |
| 150 | // function callback |
| 151 | //------------------------------------------------- |
| 212 | 152 | |
| 213 | | int state_save_get_reg_count(running_machine *machine) |
| 153 | void state_manager::register_presave(prepost_func func, void *param) |
| 214 | 154 | { |
| 215 | | state_private *global = machine->state_data; |
| 216 | | state_entry *entry; |
| 217 | | int count = 0; |
| 155 | // check for invalid timing |
| 156 | if (!m_reg_allowed) |
| 157 | fatalerror("Attempt to register callback function after state registration is closed!"); |
| 218 | 158 | |
| 219 | | /* count entries */ |
| 220 | | for (entry = global->entrylist; entry != NULL; entry = entry->next) |
| 221 | | count++; |
| 159 | // scan for duplicates and push through to the end |
| 160 | for (state_callback *cb = m_presave_list.first(); cb != NULL; cb = cb->next()) |
| 161 | if (cb->m_func == func && cb->m_param == param) |
| 162 | fatalerror("Duplicate save state function (%p, %p)", param, func); |
| 222 | 163 | |
| 223 | | return count; |
| 164 | // allocate a new entry |
| 165 | m_presave_list.append(*auto_alloc(&m_machine, state_callback(func, param))); |
| 224 | 166 | } |
| 225 | 167 | |
| 226 | 168 | |
| 169 | //------------------------------------------------- |
| 170 | // state_save_register_postload - |
| 171 | // register a post-load function callback |
| 172 | //------------------------------------------------- |
| 227 | 173 | |
| 228 | | /*************************************************************************** |
| 229 | | REGISTRATION HANDLING |
| 230 | | ***************************************************************************/ |
| 231 | | |
| 232 | | /*------------------------------------------------- |
| 233 | | state_save_allow_registration - allow/disallow |
| 234 | | registrations to happen |
| 235 | | -------------------------------------------------*/ |
| 236 | | |
| 237 | | void state_save_allow_registration(running_machine *machine, int allowed) |
| 174 | void state_manager::register_postload(prepost_func func, void *param) |
| 238 | 175 | { |
| 239 | | /* allow/deny registration */ |
| 240 | | machine->state_data->reg_allowed = allowed; |
| 241 | | if (!allowed) |
| 242 | | state_save_dump_registry(machine); |
| 243 | | } |
| 176 | // check for invalid timing |
| 177 | if (!m_reg_allowed) |
| 178 | fatalerror("Attempt to register callback function after state registration is closed!"); |
| 244 | 179 | |
| 180 | // scan for duplicates and push through to the end |
| 181 | for (state_callback *cb = m_postload_list.first(); cb != NULL; cb = cb->next()) |
| 182 | if (cb->m_func == func && cb->m_param == param) |
| 183 | fatalerror("Duplicate save state function (%p, %p)", param, func); |
| 245 | 184 | |
| 246 | | /*------------------------------------------------- |
| 247 | | state_save_registration_allowed - query |
| 248 | | whether or not registrations are allowed |
| 249 | | -------------------------------------------------*/ |
| 250 | | |
| 251 | | int state_save_registration_allowed(running_machine *machine) |
| 252 | | { |
| 253 | | return machine->state_data->reg_allowed; |
| 185 | // allocate a new entry |
| 186 | m_postload_list.append(*auto_alloc(&m_machine, state_callback(func, param))); |
| 254 | 187 | } |
| 255 | 188 | |
| 256 | 189 | |
| 257 | | /*------------------------------------------------- |
| 258 | | state_save_register_memory - register an |
| 259 | | array of data in memory |
| 260 | | -------------------------------------------------*/ |
| 190 | //------------------------------------------------- |
| 191 | // save_memory - register an array of data in |
| 192 | // memory |
| 193 | //------------------------------------------------- |
| 261 | 194 | |
| 262 | | void state_save_register_memory(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount, const char *file, int line) |
| 195 | void state_manager::save_memory(const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount) |
| 263 | 196 | { |
| 264 | | state_private *global = machine->state_data; |
| 265 | | state_entry **entryptr, *next; |
| 266 | | astring totalname; |
| 267 | | |
| 268 | 197 | assert(valsize == 1 || valsize == 2 || valsize == 4 || valsize == 8); |
| 269 | 198 | |
| 270 | | /* check for invalid timing */ |
| 271 | | if (!global->reg_allowed) |
| 199 | // check for invalid timing |
| 200 | if (!m_reg_allowed) |
| 272 | 201 | { |
| 273 | | logerror("Attempt to register save state entry after state registration is closed!\nFile: %s, line %d, module %s tag %s name %s\n", file, line, module, tag, name); |
| 274 | | if (machine->gamedrv->flags & GAME_SUPPORTS_SAVE) |
| 275 | | fatalerror("Attempt to register save state entry after state registration is closed!\nFile: %s, line %d, module %s tag %s name %s\n", file, line, module, tag, name); |
| 276 | | global->illegal_regs++; |
| 202 | logerror("Attempt to register save state entry after state registration is closed!\nModule %s tag %s name %s\n", module, tag, name); |
| 203 | if (m_machine.gamedrv->flags & GAME_SUPPORTS_SAVE) |
| 204 | fatalerror("Attempt to register save state entry after state registration is closed!\nModule %s tag %s name %s\n", module, tag, name); |
| 205 | m_illegal_regs++; |
| 277 | 206 | return; |
| 278 | 207 | } |
| 279 | 208 | |
| 280 | | /* create the full name */ |
| 209 | // create the full name |
| 210 | astring totalname; |
| 281 | 211 | if (tag != NULL) |
| 282 | 212 | totalname.printf("%s/%s/%X/%s", module, tag, index, name); |
| 283 | 213 | else |
| 284 | 214 | totalname.printf("%s/%X/%s", module, index, name); |
| 285 | 215 | |
| 286 | | /* look for duplicates and an entry to insert in front of */ |
| 287 | | for (entryptr = &global->entrylist; *entryptr != NULL; entryptr = &(*entryptr)->next) |
| 216 | // look for duplicates and an entry to insert in front of |
| 217 | state_entry *insert_after = NULL; |
| 218 | for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next()) |
| 288 | 219 | { |
| 289 | | /* stop if the next guy's string is greater than ours */ |
| 290 | | int cmpval = (*entryptr)->name.cmp(totalname); |
| 291 | | if (cmpval > 0) |
| 220 | // stop when we find an entry whose name is after ours |
| 221 | if (entry->m_name > totalname) |
| 292 | 222 | break; |
| 223 | insert_after = entry; |
| 293 | 224 | |
| 294 | | /* error if we are equal */ |
| 295 | | if (cmpval == 0) |
| 225 | // error if we are equal |
| 226 | if (entry->m_name == totalname) |
| 296 | 227 | fatalerror("Duplicate save state registration entry (%s)", totalname.cstr()); |
| 297 | 228 | } |
| 298 | 229 | |
| 299 | | /* didn't find one; allocate a new one */ |
| 300 | | next = *entryptr; |
| 301 | | *entryptr = auto_alloc_clear(machine, state_entry); |
| 302 | | |
| 303 | | /* fill in the rest */ |
| 304 | | (*entryptr)->next = next; |
| 305 | | (*entryptr)->machine = machine; |
| 306 | | (*entryptr)->data = val; |
| 307 | | (*entryptr)->name = totalname; |
| 308 | | (*entryptr)->typesize = valsize; |
| 309 | | (*entryptr)->typecount = valcount; |
| 230 | // insert us into the list |
| 231 | m_entry_list.insert_after(*auto_alloc(&m_machine, state_entry(val, totalname, valsize, valcount)), insert_after); |
| 310 | 232 | } |
| 311 | 233 | |
| 312 | 234 | |
| 313 | | /*------------------------------------------------- |
| 314 | | state_save_register_bitmap - register a |
| 315 | | bitmap to be saved |
| 316 | | -------------------------------------------------*/ |
| 235 | //------------------------------------------------- |
| 236 | // check_file - check if a file is a valid save |
| 237 | // state |
| 238 | //------------------------------------------------- |
| 317 | 239 | |
| 318 | | void state_save_register_bitmap(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, bitmap_t *val, const char *file, int line) |
| 240 | state_save_error state_manager::check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...)) |
| 319 | 241 | { |
| 320 | | state_save_register_memory(machine, module, tag, index, name, val->base, val->bpp / 8, val->rowpixels * val->height, file, line); |
| 321 | | } |
| 242 | // if we want to validate the signature, compute it |
| 243 | UINT32 sig = 0; |
| 244 | if (machine != NULL) |
| 245 | sig = machine->state().signature(); |
| 322 | 246 | |
| 247 | // seek to the beginning and read the header |
| 248 | mame_fcompress(file, FCOMPRESS_NONE); |
| 249 | mame_fseek(file, 0, SEEK_SET); |
| 250 | UINT8 header[HEADER_SIZE]; |
| 251 | if (mame_fread(file, header, sizeof(header)) != sizeof(header)) |
| 252 | { |
| 253 | if (errormsg != NULL) |
| 254 | (*errormsg)("Could not read " APPNAME " save file header"); |
| 255 | return STATERR_READ_ERROR; |
| 256 | } |
| 323 | 257 | |
| 258 | // let the generic header check work out the rest |
| 259 | return validate_header(header, gamename, sig, errormsg, ""); |
| 260 | } |
| 324 | 261 | |
| 325 | | /*************************************************************************** |
| 326 | | CALLBACK FUNCTION REGISTRATION |
| 327 | | ***************************************************************************/ |
| 328 | 262 | |
| 329 | | /*------------------------------------------------- |
| 330 | | state_save_register_presave - |
| 331 | | register a pre-save function callback |
| 332 | | -------------------------------------------------*/ |
| 263 | //------------------------------------------------- |
| 264 | // read_file - read the data from a file |
| 265 | //------------------------------------------------- |
| 333 | 266 | |
| 334 | | void state_save_register_presave(running_machine *machine, state_presave_func func, void *param) |
| 267 | state_save_error state_manager::read_file(mame_file *file) |
| 335 | 268 | { |
| 336 | | state_private *global = machine->state_data; |
| 337 | | state_callback **cbptr; |
| 269 | // if we have illegal registrations, return an error |
| 270 | if (m_illegal_regs > 0) |
| 271 | return STATERR_ILLEGAL_REGISTRATIONS; |
| 338 | 272 | |
| 339 | | /* check for invalid timing */ |
| 340 | | if (!global->reg_allowed) |
| 341 | | fatalerror("Attempt to register callback function after state registration is closed!"); |
| 273 | // read the header and turn on compression for the rest of the file |
| 274 | mame_fcompress(file, FCOMPRESS_NONE); |
| 275 | mame_fseek(file, 0, SEEK_SET); |
| 276 | UINT8 header[HEADER_SIZE]; |
| 277 | if (mame_fread(file, header, sizeof(header)) != sizeof(header)) |
| 278 | return STATERR_READ_ERROR; |
| 279 | mame_fcompress(file, FCOMPRESS_MEDIUM); |
| 342 | 280 | |
| 343 | | /* scan for duplicates and push through to the end */ |
| 344 | | for (cbptr = &global->prefunclist; *cbptr != NULL; cbptr = &(*cbptr)->next) |
| 345 | | if ((*cbptr)->func.presave == func && (*cbptr)->param == param) |
| 346 | | fatalerror("Duplicate save state function (%p, %p)", param, func); |
| 281 | // verify the header and report an error if it doesn't match |
| 282 | UINT32 sig = signature(); |
| 283 | if (validate_header(header, m_machine.gamedrv->name, sig, popmessage, "Error: ") != STATERR_NONE) |
| 284 | return STATERR_INVALID_HEADER; |
| 347 | 285 | |
| 348 | | /* allocate a new entry */ |
| 349 | | *cbptr = auto_alloc(machine, state_callback); |
| 286 | // determine whether or not to flip the data when done |
| 287 | bool flip = NATIVE_ENDIAN_VALUE_LE_BE((header[9] & SS_MSB_FIRST) != 0, (header[9] & SS_MSB_FIRST) == 0); |
| 350 | 288 | |
| 351 | | /* fill it in */ |
| 352 | | (*cbptr)->next = NULL; |
| 353 | | (*cbptr)->machine = machine; |
| 354 | | (*cbptr)->func.presave = func; |
| 355 | | (*cbptr)->param = param; |
| 289 | // read all the data, flipping if necessary |
| 290 | for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next()) |
| 291 | { |
| 292 | UINT32 totalsize = entry->m_typesize * entry->m_typecount; |
| 293 | if (mame_fread(file, entry->m_data, totalsize) != totalsize) |
| 294 | return STATERR_READ_ERROR; |
| 295 | |
| 296 | // handle flipping |
| 297 | if (flip) |
| 298 | entry->flip_data(); |
| 299 | } |
| 300 | |
| 301 | // call the post-load functions |
| 302 | for (state_callback *func = m_postload_list.first(); func != NULL; func = func->next()) |
| 303 | (*func->m_func)(&m_machine, func->m_param); |
| 304 | |
| 305 | return STATERR_NONE; |
| 356 | 306 | } |
| 357 | 307 | |
| 358 | 308 | |
| 359 | | /*------------------------------------------------- |
| 360 | | state_save_register_postload - |
| 361 | | register a post-load function callback |
| 362 | | -------------------------------------------------*/ |
| 309 | //------------------------------------------------- |
| 310 | // write_file - writes the data to a file |
| 311 | //------------------------------------------------- |
| 363 | 312 | |
| 364 | | void state_save_register_postload(running_machine *machine, state_postload_func func, void *param) |
| 313 | state_save_error state_manager::write_file(mame_file *file) |
| 365 | 314 | { |
| 366 | | state_private *global = machine->state_data; |
| 367 | | state_callback **cbptr; |
| 315 | // if we have illegal registrations, return an error |
| 316 | if (m_illegal_regs > 0) |
| 317 | return STATERR_ILLEGAL_REGISTRATIONS; |
| 368 | 318 | |
| 369 | | /* check for invalid timing */ |
| 370 | | if (!global->reg_allowed) |
| 371 | | fatalerror("Attempt to register callback function after state registration is closed!"); |
| 319 | // generate the header |
| 320 | UINT8 header[HEADER_SIZE]; |
| 321 | memcpy(&header[0], s_magic_num, 8); |
| 322 | header[8] = SAVE_VERSION; |
| 323 | header[9] = NATIVE_ENDIAN_VALUE_LE_BE(0, SS_MSB_FIRST); |
| 324 | strncpy((char *)&header[0x0a], m_machine.gamedrv->name, 0x1c - 0x0a); |
| 325 | UINT32 sig = signature(); |
| 326 | *(UINT32 *)&header[0x1c] = LITTLE_ENDIANIZE_INT32(sig); |
| 372 | 327 | |
| 373 | | /* scan for duplicates and push through to the end */ |
| 374 | | for (cbptr = &global->postfunclist; *cbptr != NULL; cbptr = &(*cbptr)->next) |
| 375 | | if ((*cbptr)->func.postload == func && (*cbptr)->param == param) |
| 376 | | fatalerror("Duplicate save state function (%p, %p)", param, func); |
| 328 | // write the header and turn on compression for the rest of the file |
| 329 | mame_fcompress(file, FCOMPRESS_NONE); |
| 330 | mame_fseek(file, 0, SEEK_SET); |
| 331 | if (mame_fwrite(file, header, sizeof(header)) != sizeof(header)) |
| 332 | return STATERR_WRITE_ERROR; |
| 333 | mame_fcompress(file, FCOMPRESS_MEDIUM); |
| 377 | 334 | |
| 378 | | /* allocate a new entry */ |
| 379 | | *cbptr = auto_alloc(machine, state_callback); |
| 335 | // call the pre-save functions |
| 336 | for (state_callback *func = m_presave_list.first(); func != NULL; func = func->next()) |
| 337 | (*func->m_func)(&m_machine, func->m_param); |
| 380 | 338 | |
| 381 | | /* fill it in */ |
| 382 | | (*cbptr)->next = NULL; |
| 383 | | (*cbptr)->machine = machine; |
| 384 | | (*cbptr)->func.postload = func; |
| 385 | | (*cbptr)->param = param; |
| 339 | // then write all the data |
| 340 | for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next()) |
| 341 | { |
| 342 | UINT32 totalsize = entry->m_typesize * entry->m_typecount; |
| 343 | if (mame_fwrite(file, entry->m_data, totalsize) != totalsize) |
| 344 | return STATERR_WRITE_ERROR; |
| 345 | } |
| 346 | return STATERR_NONE; |
| 386 | 347 | } |
| 387 | 348 | |
| 388 | 349 | |
| 350 | //------------------------------------------------- |
| 351 | // signature - compute the signature, which |
| 352 | // is a CRC over the structure of the data |
| 353 | //------------------------------------------------- |
| 389 | 354 | |
| 390 | | /*************************************************************************** |
| 391 | | PROCESSING HELPERS |
| 392 | | ***************************************************************************/ |
| 393 | | |
| 394 | | /*------------------------------------------------- |
| 395 | | get_signature - compute the signature, which |
| 396 | | is a CRC over the structure of the data |
| 397 | | -------------------------------------------------*/ |
| 398 | | |
| 399 | | static UINT32 get_signature(running_machine *machine) |
| 355 | UINT32 state_manager::signature() const |
| 400 | 356 | { |
| 401 | | state_private *global = machine->state_data; |
| 402 | | state_entry *entry; |
| 357 | // iterate over entries |
| 403 | 358 | UINT32 crc = 0; |
| 404 | | |
| 405 | | /* iterate over entries */ |
| 406 | | for (entry = global->entrylist; entry != NULL; entry = entry->next) |
| 359 | for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next()) |
| 407 | 360 | { |
| 408 | | UINT32 temp[2]; |
| 361 | // add the entry name to the CRC |
| 362 | crc = crc32(crc, (UINT8 *)entry->m_name.cstr(), entry->m_name.len()); |
| 409 | 363 | |
| 410 | | /* add the entry name to the CRC */ |
| 411 | | crc = crc32(crc, (UINT8 *)entry->name.cstr(), entry->name.len()); |
| 412 | | |
| 413 | | /* add the type and size to the CRC */ |
| 414 | | temp[0] = LITTLE_ENDIANIZE_INT32(entry->typecount); |
| 415 | | temp[1] = LITTLE_ENDIANIZE_INT32(entry->typesize); |
| 364 | // add the type and size to the CRC |
| 365 | UINT32 temp[2]; |
| 366 | temp[0] = LITTLE_ENDIANIZE_INT32(entry->m_typecount); |
| 367 | temp[1] = LITTLE_ENDIANIZE_INT32(entry->m_typesize); |
| 416 | 368 | crc = crc32(crc, (UINT8 *)&temp[0], sizeof(temp)); |
| 417 | 369 | } |
| 418 | | |
| 419 | 370 | return crc; |
| 420 | 371 | } |
| 421 | 372 | |
| 422 | 373 | |
| 374 | //------------------------------------------------- |
| 375 | // dump_registry - dump the registry to the |
| 376 | // logfile |
| 377 | //------------------------------------------------- |
| 423 | 378 | |
| 424 | | /*************************************************************************** |
| 425 | | SAVE STATE FILE PROCESSING |
| 426 | | ***************************************************************************/ |
| 379 | void state_manager::dump_registry() const |
| 380 | { |
| 381 | for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next()) |
| 382 | LOG(("%s: %d x %d\n", entry->m_name.cstr(), entry->m_typesize, entry->m_typecount)); |
| 383 | } |
| 427 | 384 | |
| 428 | | /*------------------------------------------------- |
| 429 | | validate_header - validate the data in the |
| 430 | | header |
| 431 | | -------------------------------------------------*/ |
| 432 | 385 | |
| 433 | | static state_save_error validate_header(const UINT8 *header, const char *gamename, UINT32 signature, |
| 386 | //------------------------------------------------- |
| 387 | // validate_header - validate the data in the |
| 388 | // header |
| 389 | //------------------------------------------------- |
| 390 | |
| 391 | state_save_error state_manager::validate_header(const UINT8 *header, const char *gamename, UINT32 signature, |
| 434 | 392 | void (CLIB_DECL *errormsg)(const char *fmt, ...), const char *error_prefix) |
| 435 | 393 | { |
| 436 | | /* check magic number */ |
| 437 | | if (memcmp(header, ss_magic_num, 8)) |
| 394 | // check magic number |
| 395 | if (memcmp(header, s_magic_num, 8)) |
| 438 | 396 | { |
| 439 | 397 | if (errormsg != NULL) |
| 440 | 398 | (*errormsg)("%sThis is not a " APPNAME " save file", error_prefix); |
| 441 | 399 | return STATERR_INVALID_HEADER; |
| 442 | 400 | } |
| 443 | 401 | |
| 444 | | /* check save state version */ |
| 402 | // check save state version |
| 445 | 403 | if (header[8] != SAVE_VERSION) |
| 446 | 404 | { |
| 447 | 405 | if (errormsg != NULL) |
| r10330 | r10331 | |
| 449 | 407 | return STATERR_INVALID_HEADER; |
| 450 | 408 | } |
| 451 | 409 | |
| 452 | | /* check gamename, if we were asked to */ |
| 410 | // check gamename, if we were asked to |
| 453 | 411 | if (gamename != NULL && strncmp(gamename, (const char *)&header[0x0a], 0x1c - 0x0a)) |
| 454 | 412 | { |
| 455 | 413 | if (errormsg != NULL) |
| r10330 | r10331 | |
| 457 | 415 | return STATERR_INVALID_HEADER; |
| 458 | 416 | } |
| 459 | 417 | |
| 460 | | /* check signature, if we were asked to */ |
| 418 | // check signature, if we were asked to |
| 461 | 419 | if (signature != 0) |
| 462 | 420 | { |
| 463 | 421 | UINT32 rawsig = *(UINT32 *)&header[0x1c]; |
| r10330 | r10331 | |
| 472 | 430 | } |
| 473 | 431 | |
| 474 | 432 | |
| 475 | | /*------------------------------------------------- |
| 476 | | state_save_check_file - check if a file is |
| 477 | | a valid save state |
| 478 | | -------------------------------------------------*/ |
| 433 | //------------------------------------------------- |
| 434 | // state_callback - constructor |
| 435 | //------------------------------------------------- |
| 479 | 436 | |
| 480 | | state_save_error state_save_check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...)) |
| 437 | state_manager::state_callback::state_callback(prepost_func callback, void *param) |
| 438 | : m_next(NULL), |
| 439 | m_param(param), |
| 440 | m_func(callback) |
| 481 | 441 | { |
| 482 | | UINT8 header[HEADER_SIZE]; |
| 483 | | UINT32 signature = 0; |
| 484 | | |
| 485 | | /* if we want to validate the signature, compute it */ |
| 486 | | if (machine != NULL) |
| 487 | | signature = get_signature(machine); |
| 488 | | |
| 489 | | /* seek to the beginning and read the header */ |
| 490 | | mame_fcompress(file, FCOMPRESS_NONE); |
| 491 | | mame_fseek(file, 0, SEEK_SET); |
| 492 | | if (mame_fread(file, header, sizeof(header)) != sizeof(header)) |
| 493 | | { |
| 494 | | if (errormsg != NULL) |
| 495 | | (*errormsg)("Could not read " APPNAME " save file header"); |
| 496 | | return STATERR_READ_ERROR; |
| 497 | | } |
| 498 | | |
| 499 | | /* let the generic header check work out the rest */ |
| 500 | | return validate_header(header, gamename, signature, errormsg, ""); |
| 501 | 442 | } |
| 502 | 443 | |
| 503 | 444 | |
| 504 | | /*------------------------------------------------- |
| 505 | | state_save_write_file - writes the data to |
| 506 | | a file |
| 507 | | -------------------------------------------------*/ |
| 445 | //------------------------------------------------- |
| 446 | // state_entry - constructor |
| 447 | //------------------------------------------------- |
| 508 | 448 | |
| 509 | | state_save_error state_save_write_file(running_machine *machine, mame_file *file) |
| 449 | state_manager::state_entry::state_entry(void *data, const char *name, UINT8 size, UINT32 count) |
| 450 | : m_next(NULL), |
| 451 | m_data(data), |
| 452 | m_name(name), |
| 453 | m_typesize(size), |
| 454 | m_typecount(count), |
| 455 | m_offset(0) |
| 510 | 456 | { |
| 511 | | state_private *global = machine->state_data; |
| 512 | | UINT32 signature = get_signature(machine); |
| 513 | | UINT8 header[HEADER_SIZE]; |
| 514 | | state_callback *func; |
| 515 | | state_entry *entry; |
| 516 | | |
| 517 | | /* if we have illegal registrations, return an error */ |
| 518 | | if (global->illegal_regs > 0) |
| 519 | | return STATERR_ILLEGAL_REGISTRATIONS; |
| 520 | | |
| 521 | | /* generate the header */ |
| 522 | | memcpy(&header[0], ss_magic_num, 8); |
| 523 | | header[8] = SAVE_VERSION; |
| 524 | | header[9] = NATIVE_ENDIAN_VALUE_LE_BE(0, SS_MSB_FIRST); |
| 525 | | strncpy((char *)&header[0x0a], machine->gamedrv->name, 0x1c - 0x0a); |
| 526 | | *(UINT32 *)&header[0x1c] = LITTLE_ENDIANIZE_INT32(signature); |
| 527 | | |
| 528 | | /* write the header and turn on compression for the rest of the file */ |
| 529 | | mame_fcompress(file, FCOMPRESS_NONE); |
| 530 | | mame_fseek(file, 0, SEEK_SET); |
| 531 | | if (mame_fwrite(file, header, sizeof(header)) != sizeof(header)) |
| 532 | | return STATERR_WRITE_ERROR; |
| 533 | | mame_fcompress(file, FCOMPRESS_MEDIUM); |
| 534 | | |
| 535 | | /* call the pre-save functions */ |
| 536 | | for (func = global->prefunclist; func != NULL; func = func->next) |
| 537 | | (*func->func.presave)(machine, func->param); |
| 538 | | |
| 539 | | /* then write all the data */ |
| 540 | | for (entry = global->entrylist; entry != NULL; entry = entry->next) |
| 541 | | { |
| 542 | | UINT32 totalsize = entry->typesize * entry->typecount; |
| 543 | | if (mame_fwrite(file, entry->data, totalsize) != totalsize) |
| 544 | | return STATERR_WRITE_ERROR; |
| 545 | | } |
| 546 | | return STATERR_NONE; |
| 547 | 457 | } |
| 548 | 458 | |
| 549 | 459 | |
| 550 | | /*------------------------------------------------- |
| 551 | | state_save_read_file - read the data from a |
| 552 | | file |
| 553 | | -------------------------------------------------*/ |
| 460 | //------------------------------------------------- |
| 461 | // flip_data - reverse the endianness of a |
| 462 | // block of data |
| 463 | //------------------------------------------------- |
| 554 | 464 | |
| 555 | | state_save_error state_save_read_file(running_machine *machine, mame_file *file) |
| 465 | void state_manager::state_entry::flip_data() |
| 556 | 466 | { |
| 557 | | state_private *global = machine->state_data; |
| 558 | | UINT32 signature = get_signature(machine); |
| 559 | | UINT8 header[HEADER_SIZE]; |
| 560 | | state_callback *func; |
| 561 | | state_entry *entry; |
| 562 | | int flip; |
| 467 | UINT16 *data16; |
| 468 | UINT32 *data32; |
| 469 | UINT64 *data64; |
| 470 | int count; |
| 563 | 471 | |
| 564 | | /* if we have illegal registrations, return an error */ |
| 565 | | if (global->illegal_regs > 0) |
| 566 | | return STATERR_ILLEGAL_REGISTRATIONS; |
| 567 | | |
| 568 | | /* read the header and turn on compression for the rest of the file */ |
| 569 | | mame_fcompress(file, FCOMPRESS_NONE); |
| 570 | | mame_fseek(file, 0, SEEK_SET); |
| 571 | | if (mame_fread(file, header, sizeof(header)) != sizeof(header)) |
| 572 | | return STATERR_READ_ERROR; |
| 573 | | mame_fcompress(file, FCOMPRESS_MEDIUM); |
| 574 | | |
| 575 | | /* verify the header and report an error if it doesn't match */ |
| 576 | | if (validate_header(header, machine->gamedrv->name, signature, popmessage, "Error: ") != STATERR_NONE) |
| 577 | | return STATERR_INVALID_HEADER; |
| 578 | | |
| 579 | | /* determine whether or not to flip the data when done */ |
| 580 | | flip = NATIVE_ENDIAN_VALUE_LE_BE((header[9] & SS_MSB_FIRST) != 0, (header[9] & SS_MSB_FIRST) == 0); |
| 581 | | |
| 582 | | /* read all the data, flipping if necessary */ |
| 583 | | for (entry = global->entrylist; entry != NULL; entry = entry->next) |
| 472 | switch (m_typesize) |
| 584 | 473 | { |
| 585 | | UINT32 totalsize = entry->typesize * entry->typecount; |
| 586 | | if (mame_fread(file, entry->data, totalsize) != totalsize) |
| 587 | | return STATERR_READ_ERROR; |
| 474 | case 2: |
| 475 | data16 = (UINT16 *)m_data; |
| 476 | for (count = 0; count < m_typecount; count++) |
| 477 | data16[count] = FLIPENDIAN_INT16(data16[count]); |
| 478 | break; |
| 588 | 479 | |
| 589 | | /* handle flipping */ |
| 590 | | if (flip) |
| 591 | | flip_data(entry); |
| 592 | | } |
| 480 | case 4: |
| 481 | data32 = (UINT32 *)m_data; |
| 482 | for (count = 0; count < m_typecount; count++) |
| 483 | data32[count] = FLIPENDIAN_INT32(data32[count]); |
| 484 | break; |
| 593 | 485 | |
| 594 | | /* call the post-load functions */ |
| 595 | | for (func = global->postfunclist; func != NULL; func = func->next) |
| 596 | | (*func->func.postload)(machine, func->param); |
| 597 | | |
| 598 | | return STATERR_NONE; |
| 486 | case 8: |
| 487 | data64 = (UINT64 *)m_data; |
| 488 | for (count = 0; count < m_typecount; count++) |
| 489 | data64[count] = FLIPENDIAN_INT64(data64[count]); |
| 490 | break; |
| 491 | } |
| 599 | 492 | } |
| 600 | | |
| 601 | | |
| 602 | | |
| 603 | | /*************************************************************************** |
| 604 | | DEBUGGING |
| 605 | | ***************************************************************************/ |
| 606 | | |
| 607 | | /*------------------------------------------------- |
| 608 | | state_save_get_indexed_item - return an item |
| 609 | | with the given index |
| 610 | | -------------------------------------------------*/ |
| 611 | | |
| 612 | | const char *state_save_get_indexed_item(running_machine *machine, int index, void **base, UINT32 *valsize, UINT32 *valcount) |
| 613 | | { |
| 614 | | state_private *global = machine->state_data; |
| 615 | | state_entry *ss; |
| 616 | | |
| 617 | | for (ss = global->entrylist; ss != NULL; ss = ss->next) |
| 618 | | if (index-- == 0) |
| 619 | | { |
| 620 | | if (base != NULL) |
| 621 | | *base = ss->data; |
| 622 | | if (valsize != NULL) |
| 623 | | *valsize = ss->typesize; |
| 624 | | if (valcount != NULL) |
| 625 | | *valcount = ss->typecount; |
| 626 | | return ss->name; |
| 627 | | } |
| 628 | | |
| 629 | | return NULL; |
| 630 | | } |
| 631 | | |
| 632 | | |
| 633 | | /*------------------------------------------------- |
| 634 | | state_save_dump_registry - dump the registry |
| 635 | | to the logfile |
| 636 | | -------------------------------------------------*/ |
| 637 | | |
| 638 | | void state_save_dump_registry(running_machine *machine) |
| 639 | | { |
| 640 | | state_private *global = machine->state_data; |
| 641 | | state_entry *entry; |
| 642 | | |
| 643 | | for (entry = global->entrylist; entry; entry=entry->next) |
| 644 | | LOG(("%s: %d x %d\n", entry->name.cstr(), entry->typesize, entry->typecount)); |
| 645 | | } |
| 646 | | |
src/emu/state.h
| r10330 | r10331 | |
| 4 | 4 | |
| 5 | 5 | Save state management functions. |
| 6 | 6 | |
| 7 | | Copyright Nicola Salmoria and the MAME Team. |
| 8 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | **************************************************************************** |
| 9 | 8 | |
| 9 | Copyright Aaron Giles |
| 10 | All rights reserved. |
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions are |
| 14 | met: |
| 15 | |
| 16 | * Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | * Redistributions in binary form must reproduce the above copyright |
| 19 | notice, this list of conditions and the following disclaimer in |
| 20 | the documentation and/or other materials provided with the |
| 21 | distribution. |
| 22 | * Neither the name 'MAME' nor the names of its contributors may be |
| 23 | used to endorse or promote products derived from this software |
| 24 | without specific prior written permission. |
| 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR |
| 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 30 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 33 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 35 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | POSSIBILITY OF SUCH DAMAGE. |
| 37 | |
| 10 | 38 | ***************************************************************************/ |
| 11 | 39 | |
| 12 | 40 | #pragma once |
| r10330 | r10331 | |
| 18 | 46 | #ifndef __STATE_H__ |
| 19 | 47 | #define __STATE_H__ |
| 20 | 48 | |
| 21 | | #ifdef __GNUC__ |
| 22 | | #include <tr1/type_traits> |
| 23 | | #endif |
| 24 | 49 | |
| 25 | 50 | |
| 26 | | /*************************************************************************** |
| 27 | | TYPE DEFINTIONS |
| 28 | | ***************************************************************************/ |
| 51 | //************************************************************************** |
| 52 | // CONSTANTS |
| 53 | //************************************************************************** |
| 29 | 54 | |
| 30 | | typedef void (*state_presave_func)(running_machine *machine, void *param); |
| 31 | | typedef void (*state_postload_func)(running_machine *machine, void *param); |
| 32 | | |
| 33 | | |
| 34 | | |
| 35 | | /*************************************************************************** |
| 36 | | CONSTANTS |
| 37 | | ***************************************************************************/ |
| 38 | | |
| 39 | | enum _state_save_error |
| 55 | enum state_save_error |
| 40 | 56 | { |
| 41 | 57 | STATERR_NONE, |
| 42 | 58 | STATERR_ILLEGAL_REGISTRATIONS, |
| r10330 | r10331 | |
| 44 | 60 | STATERR_READ_ERROR, |
| 45 | 61 | STATERR_WRITE_ERROR |
| 46 | 62 | }; |
| 47 | | typedef enum _state_save_error state_save_error; |
| 48 | 63 | |
| 49 | 64 | |
| 50 | 65 | |
| 51 | | /*************************************************************************** |
| 52 | | MACROS |
| 53 | | ***************************************************************************/ |
| 66 | //************************************************************************** |
| 67 | // MACROS |
| 68 | //************************************************************************** |
| 54 | 69 | |
| 55 | 70 | #define STATE_PRESAVE(name) void name(running_machine *machine, void *param) |
| 56 | 71 | #define STATE_POSTLOAD(name) void name(running_machine *machine, void *param) |
| r10330 | r10331 | |
| 71 | 86 | } |
| 72 | 87 | |
| 73 | 88 | |
| 74 | | #ifdef __GNUC__ |
| 75 | | #define IS_VALID_SAVE_TYPE(_var) \ |
| 76 | | (std::tr1::is_arithmetic<typeof(_var)>::value || std::tr1::is_enum<typeof(_var)>::value || \ |
| 77 | | std::tr1::is_same<typeof(_var), PAIR>::value || std::tr1::is_same<typeof(_var), PAIR64>::value) |
| 78 | | #else |
| 79 | | #define IS_VALID_SAVE_TYPE(_var) \ |
| 80 | | (sizeof(_var) == 1 || sizeof(_var) == 2 || sizeof(_var) == 4 || sizeof(_var) == 8) |
| 81 | | #endif |
| 82 | | |
| 83 | | |
| 84 | | /* generic registration; all further registrations are based on this */ |
| 85 | | #define state_save_register_generic(_mach, _mod, _tag, _index, _name, _val, _valsize, _count) \ |
| 86 | | do { \ |
| 87 | | assert_always(IS_VALID_SAVE_TYPE(_valsize), "Invalid data type supplied for state saving."); \ |
| 88 | | state_save_register_memory(_mach, _mod, _tag, _index, _name, _val, sizeof(_valsize), _count, __FILE__, __LINE__); \ |
| 89 | | } while (0) |
| 90 | | |
| 91 | | |
| 92 | | /* register items with explicit tags */ |
| 89 | // register items with explicit tags |
| 93 | 90 | #define state_save_register_item(_mach, _mod, _tag, _index, _val) \ |
| 94 | | state_save_register_generic(_mach, _mod, _tag, _index, #_val, &_val, _val, 1) |
| 91 | (_mach)->state().save_item(_mod, _tag, _index, _val, #_val) |
| 95 | 92 | |
| 96 | 93 | #define state_save_register_item_pointer(_mach, _mod, _tag, _index, _val, _count) \ |
| 97 | | state_save_register_generic(_mach, _mod, _tag, _index, #_val, &_val[0], _val[0], _count) |
| 94 | (_mach)->state().save_pointer(_mod, _tag, _index, _val, #_val, _count) |
| 98 | 95 | |
| 99 | 96 | #define state_save_register_item_array(_mach, _mod, _tag, _index, _val) \ |
| 100 | | state_save_register_item_pointer(_mach, _mod, _tag, _index, _val, sizeof(_val)/sizeof(_val[0])) |
| 97 | (_mach)->state().save_item(_mod, _tag, _index, _val, #_val) |
| 101 | 98 | |
| 102 | 99 | #define state_save_register_item_2d_array(_mach, _mod, _tag, _index, _val) \ |
| 103 | | state_save_register_item_pointer(_mach, _mod, _tag, _index, _val[0], sizeof(_val)/sizeof(_val[0][0])) |
| 100 | (_mach)->state().save_item(_mod, _tag, _index, _val, #_val) |
| 104 | 101 | |
| 105 | | #define state_save_register_item_bitmap(_mach, _mod, _tag, _index, _val) \ |
| 106 | | state_save_register_bitmap(_mach, _mod, _tag, _index, #_val, _val, __FILE__, __LINE__) |
| 102 | #define state_save_register_item_bitmap(_mach, _mod, _tag, _index, _val) \ |
| 103 | (_mach)->state().save_item(_mod, _tag, _index, *(_val), #_val) |
| 107 | 104 | |
| 108 | 105 | |
| 109 | 106 | |
| 110 | | /* register device items */ |
| 107 | // register device items |
| 111 | 108 | #define state_save_register_device_item(_dev, _index, _val) \ |
| 112 | | state_save_register_generic((_dev)->machine, (_dev)->name(), (_dev)->tag(), _index, #_val, &_val, _val, 1) |
| 109 | (_dev)->machine->state().save_item((_dev)->name(), (_dev)->tag(), _index, _val, #_val) |
| 113 | 110 | |
| 114 | 111 | #define state_save_register_device_item_pointer(_dev, _index, _val, _count) \ |
| 115 | | state_save_register_generic((_dev)->machine, (_dev)->name(), (_dev)->tag(), _index, #_val, &_val[0], _val[0], _count) |
| 112 | (_dev)->machine->state().save_pointer((_dev)->name(), (_dev)->tag(), _index, _val, #_val, _count) |
| 116 | 113 | |
| 117 | 114 | #define state_save_register_device_item_array(_dev, _index, _val) \ |
| 118 | | state_save_register_item_pointer((_dev)->machine, (_dev)->name(), (_dev)->tag(), _index, _val, sizeof(_val)/sizeof(_val[0])) |
| 115 | (_dev)->machine->state().save_item((_dev)->name(), (_dev)->tag(), _index, _val, #_val) |
| 119 | 116 | |
| 120 | 117 | #define state_save_register_device_item_2d_array(_dev, _index, _val) \ |
| 121 | | state_save_register_item_pointer((_dev)->machine, (_dev)->name(), (_dev)->tag(), _index, _val[0], sizeof(_val)/sizeof(_val[0][0])) |
| 118 | (_dev)->machine->state().save_item((_dev)->name(), (_dev)->tag(), _index, _val, #_val) |
| 122 | 119 | |
| 123 | | #define state_save_register_device_item_bitmap(_dev, _index, _val) \ |
| 124 | | state_save_register_bitmap((_dev)->machine, (_dev)->name(), (_dev)->tag(), _index, #_val, _val, __FILE__, __LINE__) |
| 120 | #define state_save_register_device_item_bitmap(_dev, _index, _val) \ |
| 121 | (_dev)->machine->state().save_item((_dev)->name(), (_dev)->tag(), _index, *(_val), #_val) |
| 125 | 122 | |
| 126 | 123 | |
| 127 | 124 | |
| 128 | | /* register global items */ |
| 125 | // register global items |
| 129 | 126 | #define state_save_register_global(_mach, _val) \ |
| 130 | | state_save_register_item(_mach, "globals", NULL, 0, _val) |
| 127 | (_mach)->state().save_item(_val, #_val) |
| 131 | 128 | |
| 132 | 129 | #define state_save_register_global_pointer(_mach, _val, _count) \ |
| 133 | | state_save_register_item_pointer(_mach, "globals", NULL, 0, _val, _count) |
| 130 | (_mach)->state().save_pointer(_val, #_val, _count) |
| 134 | 131 | |
| 135 | 132 | #define state_save_register_global_array(_mach, _val) \ |
| 136 | | state_save_register_item_array(_mach, "globals", NULL, 0, _val) |
| 133 | (_mach)->state().save_item(_val, #_val) |
| 137 | 134 | |
| 138 | 135 | #define state_save_register_global_2d_array(_mach, _val) \ |
| 139 | | state_save_register_item_2d_array(_mach, "globals", NULL, 0, _val) |
| 136 | (_mach)->state().save_item(_val, #_val) |
| 140 | 137 | |
| 141 | 138 | #define state_save_register_global_bitmap(_mach, _val) \ |
| 142 | | state_save_register_bitmap(_mach, "globals", NULL, 0, #_val, _val, __FILE__, __LINE__) |
| 139 | (_mach)->state().save_item(*(_val), #_val) |
| 143 | 140 | |
| 144 | 141 | |
| 145 | 142 | |
| 146 | | /*************************************************************************** |
| 147 | | FUNCTION PROTOTYPES |
| 148 | | ***************************************************************************/ |
| 143 | //************************************************************************** |
| 144 | // TYPE DEFINITIONS |
| 145 | //************************************************************************** |
| 149 | 146 | |
| 147 | class state_manager |
| 148 | { |
| 149 | // type_checker is a set of templates to identify valid save types |
| 150 | template<typename T> struct type_checker { static const bool is_atom = false; static const bool is_pointer = false; }; |
| 151 | template<typename T> struct type_checker<T*> { static const bool is_atom = false; static const bool is_pointer = true; }; |
| 150 | 152 | |
| 151 | | /* ----- core system operations ----- */ |
| 153 | public: |
| 154 | typedef void (*prepost_func)(running_machine *machine, void *param); |
| 152 | 155 | |
| 153 | | /* initialize the system and reset all registrations */ |
| 154 | | void state_init(running_machine *machine); |
| 156 | // construction/destruction |
| 157 | state_manager(running_machine &machine); |
| 155 | 158 | |
| 156 | | /* return the number of total registrations so far */ |
| 157 | | int state_save_get_reg_count(running_machine *machine); |
| 159 | // getters |
| 160 | int registration_count() const { return m_entry_list.count(); } |
| 161 | bool registration_allowed() const { return m_reg_allowed; } |
| 162 | |
| 163 | // registration control |
| 164 | void allow_registration(bool allowed = true); |
| 165 | const char *indexed_item(int index, void *&base, UINT32 &valsize, UINT32 &valcount) const; |
| 158 | 166 | |
| 167 | // function registration |
| 168 | void register_presave(prepost_func func, void *param); |
| 169 | void register_postload(prepost_func func, void *param); |
| 159 | 170 | |
| 171 | // generic memory registration |
| 172 | void save_memory(const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount = 1); |
| 173 | |
| 174 | // templatized wrapper for general objects |
| 175 | template<typename T> |
| 176 | void save_item(const char *module, const char *tag, int index, T &value, const char *valname) |
| 177 | { |
| 178 | if (type_checker<T>::is_pointer) throw emu_fatalerror("Called save_item on a pointer with no count!"); |
| 179 | if (!type_checker<T>::is_atom) throw emu_fatalerror("Called save_item on a non-fundamental type!"); |
| 180 | save_memory(module, tag, index, valname, &value, sizeof(value)); |
| 181 | } |
| 182 | |
| 183 | // templatized wrapper for 1-dimensional arrays |
| 184 | template<typename T, std::size_t N> |
| 185 | void save_item(const char *module, const char *tag, int index, T (&value)[N], const char *valname) |
| 186 | { |
| 187 | if (!type_checker<T>::is_atom) throw emu_fatalerror("Called save_item on a non-fundamental type!"); |
| 188 | save_memory(module, tag, index, valname, &value[0], sizeof(value[0]), N); |
| 189 | } |
| 190 | |
| 191 | // templatized wrapper for 2-dimensional arrays |
| 192 | template<typename T, std::size_t M, std::size_t N> |
| 193 | void save_item(const char *module, const char *tag, int index, T (&value)[M][N], const char *valname) |
| 194 | { |
| 195 | if (!type_checker<T>::is_atom) throw emu_fatalerror("Called save_item on a non-fundamental type!"); |
| 196 | save_memory(module, tag, index, valname, &value[0][0], sizeof(value[0][0]), M * N); |
| 197 | } |
| 198 | |
| 199 | // templatized wrapper for pointers |
| 200 | template<typename T> |
| 201 | void save_pointer(const char *module, const char *tag, int index, T *value, const char *valname, UINT32 count) |
| 202 | { |
| 203 | if (!type_checker<T>::is_atom) throw emu_fatalerror("Called save_item on a non-fundamental type!"); |
| 204 | save_memory(module, tag, index, valname, value, sizeof(*value), count); |
| 205 | } |
| 206 | |
| 207 | // global memory registration |
| 208 | template<typename T> |
| 209 | void save_item(T &value, const char *valname, int index = 0) { save_item("global", NULL, index, value, valname); } |
| 210 | template<typename T> |
| 211 | void save_pointer(T *value, const char *valname, UINT32 count, int index = 0) { save_pointer("global", NULL, index, value, valname, count); } |
| 212 | |
| 213 | // file processing |
| 214 | static state_save_error check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...)); |
| 215 | state_save_error write_file(mame_file *file); |
| 216 | state_save_error read_file(mame_file *file); |
| 217 | |
| 218 | private: |
| 219 | // internal helpers |
| 220 | UINT32 signature() const; |
| 221 | void dump_registry() const; |
| 222 | static state_save_error validate_header(const UINT8 *header, const char *gamename, UINT32 signature, void (CLIB_DECL *errormsg)(const char *fmt, ...), const char *error_prefix); |
| 160 | 223 | |
| 161 | | /* ----- registration handling ----- */ |
| 224 | // state callback item |
| 225 | class state_callback |
| 226 | { |
| 227 | public: |
| 228 | // construction/destruction |
| 229 | state_callback(prepost_func callback, void *param); |
| 162 | 230 | |
| 163 | | /* allow/disallow registrations to happen (called by the core) */ |
| 164 | | void state_save_allow_registration(running_machine *machine, int allowed); |
| 231 | // getters |
| 232 | state_callback *next() const { return m_next; } |
| 165 | 233 | |
| 166 | | /* query whether or not registrations are allowed */ |
| 167 | | int state_save_registration_allowed(running_machine *machine); |
| 234 | // state |
| 235 | state_callback * m_next; // pointer to next entry |
| 236 | void * m_param; // function parameter |
| 237 | prepost_func m_func; // pointer to the function |
| 238 | }; |
| 168 | 239 | |
| 169 | | /* register an array of data in memory */ |
| 170 | | void state_save_register_memory(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount, const char *file, int line); |
| 240 | class state_entry |
| 241 | { |
| 242 | public: |
| 243 | // construction/destruction |
| 244 | state_entry(void *data, const char *name, UINT8 size, UINT32 count); |
| 171 | 245 | |
| 172 | | /* register a bitmap to be saved */ |
| 173 | | void state_save_register_bitmap(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, bitmap_t *val, const char *file, int line); |
| 246 | // getters |
| 247 | state_entry *next() const { return m_next; } |
| 248 | |
| 249 | // helpers |
| 250 | void flip_data(); |
| 174 | 251 | |
| 252 | // state |
| 253 | state_entry * m_next; // pointer to next entry |
| 254 | void * m_data; // pointer to the memory to save/restore |
| 255 | astring m_name; // full name |
| 256 | UINT8 m_typesize; // size of the raw data type |
| 257 | UINT32 m_typecount; // number of items |
| 258 | UINT32 m_offset; // offset within the final structure |
| 259 | }; |
| 175 | 260 | |
| 261 | // internal state |
| 262 | running_machine & m_machine; // reference to our machine |
| 263 | bool m_reg_allowed; // are registrations allowed? |
| 264 | int m_illegal_regs; // number of illegal registrations |
| 176 | 265 | |
| 177 | | /* ----- callback function registraton ----- */ |
| 266 | simple_list<state_entry> m_entry_list; // list of reigstered entries |
| 267 | simple_list<state_callback> m_presave_list; // list of pre-save functions |
| 268 | simple_list<state_callback> m_postload_list; // list of post-load functions |
| 178 | 269 | |
| 179 | | /* register a pre-save function callback */ |
| 180 | | void state_save_register_presave(running_machine *machine, state_presave_func func, void *param); |
| 270 | static const char s_magic_num[8]; // magic number for header |
| 271 | }; |
| 181 | 272 | |
| 182 | | /* register a post-load function callback */ |
| 183 | | void state_save_register_postload(running_machine *machine, state_postload_func func, void *param); |
| 184 | 273 | |
| 274 | // template specializations to enumerate the fundamental atomic types you are allowed to save |
| 275 | template<> struct state_manager::type_checker<bool> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 276 | template<> struct state_manager::type_checker<INT8> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 277 | template<> struct state_manager::type_checker<UINT8> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 278 | template<> struct state_manager::type_checker<INT16> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 279 | template<> struct state_manager::type_checker<UINT16> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 280 | template<> struct state_manager::type_checker<INT32> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 281 | template<> struct state_manager::type_checker<UINT32> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 282 | template<> struct state_manager::type_checker<INT64> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 283 | template<> struct state_manager::type_checker<UINT64> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 284 | template<> struct state_manager::type_checker<PAIR> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 285 | template<> struct state_manager::type_checker<PAIR64> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 286 | template<> struct state_manager::type_checker<float> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 287 | template<> struct state_manager::type_checker<double> { static const bool is_atom = true; static const bool is_pointer = false; }; |
| 185 | 288 | |
| 186 | 289 | |
| 187 | | /* ----- save state file processing ----- */ |
| 188 | 290 | |
| 189 | | /* check if a file is a valid save state */ |
| 190 | | state_save_error state_save_check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...)); |
| 291 | //************************************************************************** |
| 292 | // INLINE FUNCTIONS |
| 293 | //************************************************************************** |
| 191 | 294 | |
| 192 | | /* write out the save state file */ |
| 193 | | state_save_error state_save_write_file(running_machine *machine, mame_file *file); |
| 295 | //------------------------------------------------- |
| 296 | // save_item - specialized save_item for bitmaps |
| 297 | //------------------------------------------------- |
| 194 | 298 | |
| 195 | | /* read in a save state file */ |
| 196 | | state_save_error state_save_read_file(running_machine *machine, mame_file *file); |
| 299 | template<> |
| 300 | inline void state_manager::save_item(const char *module, const char *tag, int index, bitmap_t &value, const char *name) |
| 301 | { |
| 302 | save_memory(module, tag, index, name, value.base, value.bpp / 8, value.rowpixels * value.height); |
| 303 | } |
| 197 | 304 | |
| 198 | 305 | |
| 306 | //------------------------------------------------- |
| 307 | // save_item - specialized save_item for attotimes |
| 308 | //------------------------------------------------- |
| 199 | 309 | |
| 200 | | /* ----- debugging ----- */ |
| 310 | template<> |
| 311 | inline void state_manager::save_item(const char *module, const char *tag, int index, attotime &value, const char *name) |
| 312 | { |
| 313 | astring tempstr(name, ".attoseconds"); |
| 314 | save_memory(module, tag, index, tempstr, &value.attoseconds, sizeof(value.attoseconds)); |
| 315 | tempstr.cpy(name).cat(".seconds"); |
| 316 | save_memory(module, tag, index, tempstr, &value.seconds, sizeof(value.seconds)); |
| 317 | } |
| 201 | 318 | |
| 202 | | /* return an item with the given index */ |
| 203 | | const char *state_save_get_indexed_item(running_machine *machine, int index, void **base, UINT32 *valsize, UINT32 *valcount); |
| 204 | 319 | |
| 205 | | /* dump the registry to the logfile */ |
| 206 | | void state_save_dump_registry(running_machine *machine); |
| 207 | | |
| 208 | | |
| 209 | 320 | #endif /* __STATE_H__ */ |