diff --git a/src/mame/drivers/cave.c b/src/mame/drivers/cave.c index 9c8e7e9f546..d0afca6aeb0 100644 --- a/src/mame/drivers/cave.c +++ b/src/mame/drivers/cave.c @@ -87,52 +87,50 @@ Versions known to exist but not dumped: ***************************************************************************/ -static int time_vblank_irq; -static UINT8 irq_level; -static UINT8 vblank_irq; -static UINT8 sound_irq; -static UINT8 unknown_irq; -static UINT8 agallet_vblank_irq; - /* Update the IRQ state based on all possible causes */ -static void update_irq_state(running_machine *machine) +static void update_irq_state( running_machine *machine ) { - if (vblank_irq || sound_irq || unknown_irq) - cputag_set_input_line(machine, "maincpu", irq_level, ASSERT_LINE); + cave_state *state = (cave_state *)machine->driver_data; + if (state->vblank_irq || state->sound_irq || state->unknown_irq) + cpu_set_input_line(state->maincpu, state->irq_level, ASSERT_LINE); else - cputag_set_input_line(machine, "maincpu", irq_level, CLEAR_LINE); + cpu_set_input_line(state->maincpu, state->irq_level, CLEAR_LINE); } static TIMER_CALLBACK( cave_vblank_start ) { - vblank_irq = 1; + cave_state *state = (cave_state *)machine->driver_data; + state->vblank_irq = 1; update_irq_state(machine); cave_get_sprite_info(machine); - agallet_vblank_irq = 1; + state->agallet_vblank_irq = 1; } static TIMER_CALLBACK( cave_vblank_end ) { - if(cave_kludge == 3) /* mazinger metmqstr */ + cave_state *state = (cave_state *)machine->driver_data; + if (state->kludge == 3) /* mazinger metmqstr */ { - unknown_irq = 1; + state->unknown_irq = 1; update_irq_state(machine); } - agallet_vblank_irq = 0; + state->agallet_vblank_irq = 0; } /* Called once/frame to generate the VBLANK interrupt */ static INTERRUPT_GEN( cave_interrupt ) { - timer_set(device->machine, ATTOTIME_IN_USEC(17376-time_vblank_irq), NULL, 0, cave_vblank_start); - timer_set(device->machine, ATTOTIME_IN_USEC(17376-time_vblank_irq + 2000), NULL, 0, cave_vblank_end); + cave_state *state = (cave_state *)device->machine->driver_data; + timer_set(device->machine, ATTOTIME_IN_USEC(17376 - state->time_vblank_irq), NULL, 0, cave_vblank_start); + timer_set(device->machine, ATTOTIME_IN_USEC(17376 - state->time_vblank_irq + 2000), NULL, 0, cave_vblank_end); } /* Called by the YMZ280B to set the IRQ state */ -static void sound_irq_gen(const device_config *device, int state) +static void sound_irq_gen( const device_config *device, int state ) { - sound_irq = (state != 0); + cave_state *cave = (cave_state *)device->machine->driver_data; + cave->sound_irq = (state != 0); update_irq_state(device->machine); } @@ -155,13 +153,18 @@ static void sound_irq_gen(const device_config *device, int state) static READ16_HANDLER( cave_irq_cause_r ) { + cave_state *state = (cave_state *)space->machine->driver_data; int result = 0x0003; - if (vblank_irq) result ^= 0x01; - if (unknown_irq) result ^= 0x02; + if (state->vblank_irq) + result ^= 0x01; + if (state->unknown_irq) + result ^= 0x02; - if (offset == 4/2) vblank_irq = 0; - if (offset == 6/2) unknown_irq = 0; + if (offset == 4/2) + state->vblank_irq = 0; + if (offset == 6/2) + state->unknown_irq = 0; update_irq_state(space->machine); @@ -173,7 +176,7 @@ static READ16_HANDLER( cave_irq_cause_r ) if (offset == 0) { result &= ~4; - result |= (agallet_vblank_irq?0:4); + result |= (state->agallet_vblank_irq ? 0 : 4); } return result; @@ -190,20 +193,14 @@ static READ16_HANDLER( cave_irq_cause_r ) /* We need a FIFO buffer for sailormn, where the inter-CPUs communication is *really* tight */ -static struct -{ - int len; - UINT8 data[32]; -} soundbuf; - -//static UINT8 sound_flag1, sound_flag2; static READ8_HANDLER( soundflags_r ) { // bit 2 is low: can read command (lo) // bit 3 is low: can read command (hi) -// return (sound_flag1 ? 0 : 4) | -// (sound_flag2 ? 0 : 8) ; +// cave_state *state = (cave_state *)space->machine->driver_data; +// return (state->sound_flag1 ? 0 : 4) | +// (state->sound_flag2 ? 0 : 8) ; return 0; } @@ -211,49 +208,54 @@ static READ16_HANDLER( soundflags_ack_r ) { // bit 0 is low: can write command // bit 1 is low: can read answer -// return ((sound_flag1 | sound_flag2) ? 1 : 0) | -// ((soundbuf.len>0 ) ? 0 : 2) ; + cave_state *state = (cave_state *)space->machine->driver_data; +// return ((state->sound_flag1 | state->sound_flag2) ? 1 : 0) | +// ((state->soundbuf_len > 0) ? 0 : 2) ; -return ((soundbuf.len>0 ) ? 0 : 2) ; + return ((state->soundbuf_len > 0) ? 0 : 2) ; } /* Main CPU: write a 16 bit sound latch and generate a NMI on the sound CPU */ static WRITE16_HANDLER( sound_cmd_w ) { -// sound_flag1 = 1; -// sound_flag2 = 1; - soundlatch_word_w(space,offset,data,mem_mask); - cputag_set_input_line(space->machine, "audiocpu", INPUT_LINE_NMI, PULSE_LINE); + cave_state *state = (cave_state *)space->machine->driver_data; +// state->sound_flag1 = 1; +// state->sound_flag2 = 1; + soundlatch_word_w(space, offset, data, mem_mask); + cpu_set_input_line(state->audiocpu, INPUT_LINE_NMI, PULSE_LINE); cpu_spinuntil_time(space->cpu, ATTOTIME_IN_USEC(50)); // Allow the other cpu to reply } /* Sound CPU: read the low 8 bits of the 16 bit sound latch */ static READ8_HANDLER( soundlatch_lo_r ) { -// sound_flag1 = 0; - return soundlatch_word_r(space,offset,0x00ff) & 0xff; +// cave_state *state = (cave_state *)space->machine->driver_data; +// state->sound_flag1 = 0; + return soundlatch_word_r(space, offset, 0x00ff) & 0xff; } /* Sound CPU: read the high 8 bits of the 16 bit sound latch */ static READ8_HANDLER( soundlatch_hi_r ) { -// sound_flag2 = 0; - return soundlatch_word_r(space,offset,0xff00) >> 8; +// cave_state *state = (cave_state *)space->machine->driver_data; +// state->sound_flag2 = 0; + return soundlatch_word_r(space, offset, 0xff00) >> 8; } /* Main CPU: read the latch written by the sound CPU (acknowledge) */ static READ16_HANDLER( soundlatch_ack_r ) { - if (soundbuf.len>0) + cave_state *state = (cave_state *)space->machine->driver_data; + if (state->soundbuf_len > 0) { - UINT8 data = soundbuf.data[0]; - memmove(soundbuf.data,soundbuf.data+1,(32-1)*sizeof(soundbuf.data[0])); - soundbuf.len--; + UINT8 data = state->soundbuf_data[0]; + memmove(state->soundbuf_data, state->soundbuf_data + 1, (32 - 1) * sizeof(state->soundbuf_data[0])); + state->soundbuf_len--; return data; } else { - logerror("CPU #1 - PC %04X: Sound Buffer 2 Underflow Error\n",cpu_get_pc(space->cpu)); + logerror("CPU #1 - PC %04X: Sound Buffer 2 Underflow Error\n", cpu_get_pc(space->cpu)); return 0xff; } } @@ -262,11 +264,12 @@ static READ16_HANDLER( soundlatch_ack_r ) /* Sound CPU: write latch for the main CPU (acknowledge) */ static WRITE8_HANDLER( soundlatch_ack_w ) { - soundbuf.data[soundbuf.len] = data; - if (soundbuf.len<32) - soundbuf.len++; + cave_state *state = (cave_state *)space->machine->driver_data; + state->soundbuf_data[state->soundbuf_len] = data; + if (state->soundbuf_len < 32) + state->soundbuf_len++; else - logerror("CPU #1 - PC %04X: Sound Buffer 2 Overflow Error\n",cpu_get_pc(space->cpu)); + logerror("CPU #1 - PC %04X: Sound Buffer 2 Overflow Error\n", cpu_get_pc(space->cpu)); } @@ -279,14 +282,12 @@ static WRITE8_HANDLER( soundlatch_ack_w ) ***************************************************************************/ -static int cave_region_byte; - static WRITE16_DEVICE_HANDLER( cave_eeprom_msb_w ) { if (data & ~0xfe00) - logerror("%s: Unknown EEPROM bit written %04X\n",cpuexec_describe_context(device->machine),data); + logerror("%s: Unknown EEPROM bit written %04X\n", cpuexec_describe_context(device->machine), data); - if ( ACCESSING_BITS_8_15 ) // even address + if (ACCESSING_BITS_8_15) // even address { coin_lockout_w(device->machine, 1,~data & 0x8000); coin_lockout_w(device->machine, 0,~data & 0x4000); @@ -297,31 +298,31 @@ static WRITE16_DEVICE_HANDLER( cave_eeprom_msb_w ) eeprom_write_bit(device, data & 0x0800); // reset line asserted: reset. - eeprom_set_cs_line(device, (data & 0x0200) ? CLEAR_LINE : ASSERT_LINE ); + eeprom_set_cs_line(device, (data & 0x0200) ? CLEAR_LINE : ASSERT_LINE); // clock line asserted: write latch or select next bit to read - eeprom_set_clock_line(device, (data & 0x0400) ? ASSERT_LINE : CLEAR_LINE ); + eeprom_set_clock_line(device, (data & 0x0400) ? ASSERT_LINE : CLEAR_LINE); } } static WRITE16_DEVICE_HANDLER( sailormn_eeprom_msb_w ) { - sailormn_tilebank_w ( data & 0x0100 ); - cave_eeprom_msb_w(device,offset,data & ~0x0100,mem_mask); + sailormn_tilebank_w(device->machine, data & 0x0100); + cave_eeprom_msb_w(device, offset, data & ~0x0100, mem_mask); } static WRITE16_DEVICE_HANDLER( hotdogst_eeprom_msb_w ) { - if ( ACCESSING_BITS_8_15 ) // even address + if (ACCESSING_BITS_8_15) // even address { // latch the bit eeprom_write_bit(device, data & 0x0800); // reset line asserted: reset. - eeprom_set_cs_line(device, (data & 0x0200) ? CLEAR_LINE : ASSERT_LINE ); + eeprom_set_cs_line(device, (data & 0x0200) ? CLEAR_LINE : ASSERT_LINE); // clock line asserted: write latch or select next bit to read - eeprom_set_clock_line(device, (data & 0x0400) ? CLEAR_LINE: ASSERT_LINE ); + eeprom_set_clock_line(device, (data & 0x0400) ? CLEAR_LINE: ASSERT_LINE); } } @@ -330,28 +331,28 @@ static WRITE16_DEVICE_HANDLER( cave_eeprom_lsb_w ) if (data & ~0x00ef) logerror("%s: Unknown EEPROM bit written %04X\n",cpuexec_describe_context(device->machine),data); - if ( ACCESSING_BITS_0_7 ) // odd address + if (ACCESSING_BITS_0_7) // odd address { - coin_lockout_w(device->machine, 1,~data & 0x0008); - coin_lockout_w(device->machine, 0,~data & 0x0004); - coin_counter_w(device->machine, 1, data & 0x0002); - coin_counter_w(device->machine, 0, data & 0x0001); + coin_lockout_w(device->machine, 1, ~data & 0x0008); + coin_lockout_w(device->machine, 0, ~data & 0x0004); + coin_counter_w(device->machine, 1, data & 0x0002); + coin_counter_w(device->machine, 0, data & 0x0001); // latch the bit eeprom_write_bit(device, data & 0x80); // reset line asserted: reset. - eeprom_set_cs_line(device, (data & 0x20) ? CLEAR_LINE : ASSERT_LINE ); + eeprom_set_cs_line(device, (data & 0x20) ? CLEAR_LINE : ASSERT_LINE); // clock line asserted: write latch or select next bit to read - eeprom_set_clock_line(device, (data & 0x40) ? ASSERT_LINE : CLEAR_LINE ); + eeprom_set_clock_line(device, (data & 0x40) ? ASSERT_LINE : CLEAR_LINE); } } /* - No eeprom or lockouts */ static WRITE16_HANDLER( gaia_coin_lsb_w ) { - if ( ACCESSING_BITS_0_7 ) // odd address + if (ACCESSING_BITS_0_7) // odd address { coin_counter_w(space->machine, 1, data & 0x0002); coin_counter_w(space->machine, 0, data & 0x0001); @@ -363,9 +364,9 @@ static WRITE16_HANDLER( gaia_coin_lsb_w ) static WRITE16_DEVICE_HANDLER( metmqstr_eeprom_msb_w ) { if (data & ~0xff00) - logerror("%s: Unknown EEPROM bit written %04X\n",cpuexec_describe_context(device->machine),data); + logerror("%s: Unknown EEPROM bit written %04X\n", cpuexec_describe_context(device->machine), data); - if ( ACCESSING_BITS_8_15 ) // even address + if (ACCESSING_BITS_8_15) // even address { coin_counter_w(device->machine, 1, data & 0x2000); coin_counter_w(device->machine, 0, data & 0x1000); @@ -376,10 +377,10 @@ static WRITE16_DEVICE_HANDLER( metmqstr_eeprom_msb_w ) eeprom_write_bit(device, data & 0x0800); // reset line asserted: reset. - eeprom_set_cs_line(device, (data & 0x0200) ? CLEAR_LINE : ASSERT_LINE ); + eeprom_set_cs_line(device, (data & 0x0200) ? CLEAR_LINE : ASSERT_LINE); // clock line asserted: write latch or select next bit to read - eeprom_set_clock_line(device, (data & 0x0400) ? ASSERT_LINE : CLEAR_LINE ); + eeprom_set_clock_line(device, (data & 0x0400) ? ASSERT_LINE : CLEAR_LINE); } } } @@ -420,17 +421,17 @@ static ADDRESS_MAP_START( dfeveron_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x0fffff) AM_ROM // ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM // RAM AM_RANGE(0x300000, 0x300003) AM_DEVREADWRITE8("ymz", ymz280b_r, ymz280b_w, 0x00ff) // YMZ280 -/**/AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites -/**/AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprites? -/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 -/**/AM_RANGE(0x600000, 0x607fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE(&cave_vram_1) // Layer 1 -/**/AM_RANGE(0x708000, 0x708fff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette +/**/AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites +/**/AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprites? +/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 +/**/AM_RANGE(0x600000, 0x607fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 +/**/AM_RANGE(0x708000, 0x708fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette /**/AM_RANGE(0x710000, 0x710bff) AM_READONLY // ? AM_RANGE(0x710c00, 0x710fff) AM_RAM // ? AM_RANGE(0x800000, 0x800007) AM_READ(cave_irq_cause_r) // IRQ Cause - AM_RANGE(0x800000, 0x80007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs -/**/AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control -/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE(&cave_vctrl_1) // Layer 1 Control + AM_RANGE(0x800000, 0x80007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs +/**/AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control +/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control AM_RANGE(0xb00000, 0xb00001) AM_READ_PORT("IN0") // Inputs AM_RANGE(0xb00002, 0xb00003) AM_READ_PORT("IN1") // Inputs + EEPROM AM_RANGE(0xc00000, 0xc00001) AM_DEVWRITE("eeprom", cave_eeprom_msb_w) // EEPROM @@ -445,19 +446,19 @@ static ADDRESS_MAP_START( ddonpach_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x0fffff) AM_ROM // ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM // RAM AM_RANGE(0x300000, 0x300003) AM_DEVREADWRITE8("ymz", ymz280b_r, ymz280b_w, 0x00ff) // YMZ280 -/**/AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites -/**/AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprites? -/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 -/**/AM_RANGE(0x600000, 0x607fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE(&cave_vram_1) // Layer 1 -/**/AM_RANGE(0x700000, 0x70ffff) AM_RAM_WRITE(cave_vram_2_8x8_w) AM_BASE(&cave_vram_2) // Layer 2 +/**/AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites +/**/AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprites? +/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 +/**/AM_RANGE(0x600000, 0x607fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 +/**/AM_RANGE(0x700000, 0x70ffff) AM_RAM_WRITE(cave_vram_2_8x8_w) AM_BASE_MEMBER(cave_state, vram_2) // Layer 2 AM_RANGE(0x800000, 0x800007) AM_READ(cave_irq_cause_r) // IRQ Cause - AM_RANGE(0x800000, 0x80007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs -/**/AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control -/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE(&cave_vctrl_1) // Layer 1 Control -/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE(&cave_vctrl_2) // Layer 2 Control -/**/AM_RANGE(0xc00000, 0xc0ffff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette - AM_RANGE(0xd00000, 0xd00001) AM_READ_PORT("IN0" ) // Inputs - AM_RANGE(0xd00002, 0xd00003) AM_READ_PORT("IN1" ) // Inputs + EEPROM + AM_RANGE(0x800000, 0x80007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs +/**/AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control +/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control +/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_2) // Layer 2 Control +/**/AM_RANGE(0xc00000, 0xc0ffff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette + AM_RANGE(0xd00000, 0xd00001) AM_READ_PORT("IN0") // Inputs + AM_RANGE(0xd00002, 0xd00003) AM_READ_PORT("IN1") // Inputs + EEPROM AM_RANGE(0xe00000, 0xe00001) AM_DEVWRITE("eeprom", cave_eeprom_msb_w) // EEPROM ADDRESS_MAP_END @@ -468,12 +469,12 @@ ADDRESS_MAP_END static READ16_HANDLER( donpachi_videoregs_r ) { - switch( offset ) + switch (offset) { case 0: case 1: case 2: - case 3: return cave_irq_cause_r(space,offset,0xffff); + case 3: return cave_irq_cause_r(space, offset, 0xffff); default: return 0x0000; } @@ -482,11 +483,12 @@ static READ16_HANDLER( donpachi_videoregs_r ) #if 0 WRITE16_HANDLER( donpachi_videoregs_w ) { - COMBINE_DATA(&cave_videoregs[offset]); + cave_state *state = (cave_state *)space->machine->driver_data; + COMBINE_DATA(&state->videoregs[offset]); - switch( offset ) + switch (offset) { -// case 0x78/2: watchdog_reset16_w(0,0); break; +// case 0x78/2: watchdog_reset16_w(0, 0); break; } } #endif @@ -494,16 +496,16 @@ WRITE16_HANDLER( donpachi_videoregs_w ) static ADDRESS_MAP_START( donpachi_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x07ffff) AM_ROM // ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM // RAM - AM_RANGE(0x200000, 0x207fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE(&cave_vram_1) // Layer 1 - AM_RANGE(0x300000, 0x307fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 - AM_RANGE(0x400000, 0x407fff) AM_RAM_WRITE(cave_vram_2_8x8_w) AM_BASE(&cave_vram_2) // Layer 2 - AM_RANGE(0x500000, 0x507fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites - AM_RANGE(0x508000, 0x50ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprites? -/**/AM_RANGE(0x600000, 0x600005) AM_RAM AM_BASE(&cave_vctrl_1) // Layer 1 Control -/**/AM_RANGE(0x700000, 0x700005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control -/**/AM_RANGE(0x800000, 0x800005) AM_RAM AM_BASE(&cave_vctrl_2) // Layer 2 Control - AM_RANGE(0x900000, 0x90007f) AM_RAM_READ(donpachi_videoregs_r) AM_BASE(&cave_videoregs) // Video Regs -/**/AM_RANGE(0xa08000, 0xa08fff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette + AM_RANGE(0x200000, 0x207fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 + AM_RANGE(0x300000, 0x307fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 + AM_RANGE(0x400000, 0x407fff) AM_RAM_WRITE(cave_vram_2_8x8_w) AM_BASE_MEMBER(cave_state, vram_2) // Layer 2 + AM_RANGE(0x500000, 0x507fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites + AM_RANGE(0x508000, 0x50ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprites? +/**/AM_RANGE(0x600000, 0x600005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control +/**/AM_RANGE(0x700000, 0x700005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control +/**/AM_RANGE(0x800000, 0x800005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_2) // Layer 2 Control + AM_RANGE(0x900000, 0x90007f) AM_RAM_READ(donpachi_videoregs_r) AM_BASE_MEMBER(cave_state, videoregs) // Video Regs +/**/AM_RANGE(0xa08000, 0xa08fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette AM_RANGE(0xb00000, 0xb00003) AM_DEVREADWRITE8("oki1", okim6295_r, okim6295_w, 0x00ff) // M6295 AM_RANGE(0xb00010, 0xb00013) AM_DEVREADWRITE8("oki2", okim6295_r, okim6295_w, 0x00ff) // AM_RANGE(0xb00020, 0xb0002f) AM_DEVWRITE("nmk112", nmk112_okibank_lsb_w) // @@ -521,17 +523,17 @@ static ADDRESS_MAP_START( esprade_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x0fffff) AM_ROM // ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM // RAM AM_RANGE(0x300000, 0x300003) AM_DEVREADWRITE8("ymz", ymz280b_r, ymz280b_w, 0x00ff) // YMZ280 -/**/AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites -/**/AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprites? -/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 -/**/AM_RANGE(0x600000, 0x607fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE(&cave_vram_1) // Layer 1 -/**/AM_RANGE(0x700000, 0x707fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE(&cave_vram_2) // Layer 2 +/**/AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites +/**/AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprites? +/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 +/**/AM_RANGE(0x600000, 0x607fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 +/**/AM_RANGE(0x700000, 0x707fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE_MEMBER(cave_state, vram_2) // Layer 2 AM_RANGE(0x800000, 0x800007) AM_READ(cave_irq_cause_r) // IRQ Cause - AM_RANGE(0x800000, 0x80007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs -/**/AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control -/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE(&cave_vctrl_1) // Layer 1 Control -/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE(&cave_vctrl_2) // Layer 2 Control -/**/AM_RANGE(0xc00000, 0xc0ffff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette + AM_RANGE(0x800000, 0x80007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs +/**/AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control +/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control +/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_2) // Layer 2 Control +/**/AM_RANGE(0xc00000, 0xc0ffff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette AM_RANGE(0xd00000, 0xd00001) AM_READ_PORT("IN0" ) // Inputs AM_RANGE(0xd00002, 0xd00003) AM_READ_PORT("IN1" ) // Inputs + EEPROM AM_RANGE(0xe00000, 0xe00001) AM_DEVWRITE("eeprom", cave_eeprom_msb_w) // EEPROM @@ -546,20 +548,20 @@ static ADDRESS_MAP_START( gaia_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x0fffff) AM_ROM // ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM // RAM AM_RANGE(0x300000, 0x300003) AM_DEVREADWRITE8("ymz", ymz280b_r, ymz280b_w, 0x00ff) // YMZ280 - AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprite bank 1 - AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprite bank 2 - AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 + AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprite bank 1 + AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprite bank 2 + AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 AM_RANGE(0x508000, 0x50ffff) AM_RAM // More Layer 0, Tested but not used? - AM_RANGE(0x600000, 0x607fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE(&cave_vram_1) // Layer 1 + AM_RANGE(0x600000, 0x607fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 AM_RANGE(0x608000, 0x60ffff) AM_RAM // More Layer 1, Tested but not used? - AM_RANGE(0x700000, 0x707fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE(&cave_vram_2) // Layer 2 + AM_RANGE(0x700000, 0x707fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE_MEMBER(cave_state, vram_2) // Layer 2 AM_RANGE(0x708000, 0x70ffff) AM_RAM // More Layer 2, Tested but not used? AM_RANGE(0x800000, 0x800007) AM_READ(cave_irq_cause_r) // IRQ Cause - AM_RANGE(0x800000, 0x80007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs -/**/AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control -/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE(&cave_vctrl_1) // Layer 1 Control -/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE(&cave_vctrl_2) // Layer 2 Control - AM_RANGE(0xc00000, 0xc0ffff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette + AM_RANGE(0x800000, 0x80007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs +/**/AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control +/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control +/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_2) // Layer 2 Control + AM_RANGE(0xc00000, 0xc0ffff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette AM_RANGE(0xd00010, 0xd00011) AM_READ_PORT("IN0") // Inputs AM_RANGE(0xd00010, 0xd00011) AM_WRITE(gaia_coin_lsb_w) // Coin counter only AM_RANGE(0xd00012, 0xd00013) AM_READ_PORT("IN1") // Inputs @@ -576,17 +578,17 @@ static ADDRESS_MAP_START( guwange_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x0fffff) AM_ROM // ROM AM_RANGE(0x200000, 0x20ffff) AM_RAM // RAM AM_RANGE(0x300000, 0x300007) AM_READ(cave_irq_cause_r) // IRQ Cause - AM_RANGE(0x300000, 0x30007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs -/**/AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites -/**/AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprites? -/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 -/**/AM_RANGE(0x600000, 0x607fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE(&cave_vram_1) // Layer 1 -/**/AM_RANGE(0x700000, 0x707fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE(&cave_vram_2) // Layer 2 + AM_RANGE(0x300000, 0x30007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs +/**/AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites +/**/AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprites? +/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 +/**/AM_RANGE(0x600000, 0x607fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 +/**/AM_RANGE(0x700000, 0x707fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE_MEMBER(cave_state, vram_2) // Layer 2 AM_RANGE(0x800000, 0x800003) AM_DEVREADWRITE8("ymz", ymz280b_r, ymz280b_w, 0x00ff) // YMZ280 -/**/AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control -/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE(&cave_vctrl_1) // Layer 1 Control -/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE(&cave_vctrl_2) // Layer 2 Control -/**/AM_RANGE(0xc00000, 0xc0ffff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette +/**/AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control +/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control +/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_2) // Layer 2 Control +/**/AM_RANGE(0xc00000, 0xc0ffff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette AM_RANGE(0xd00010, 0xd00011) AM_READ_PORT("IN0") // Inputs AM_RANGE(0xd00010, 0xd00011) AM_DEVWRITE("eeprom", cave_eeprom_lsb_w) // EEPROM AM_RANGE(0xd00012, 0xd00013) AM_READ_PORT("IN1") // Inputs + EEPROM @@ -602,23 +604,23 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( hotdogst_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x0fffff) AM_ROM // ROM AM_RANGE(0x300000, 0x30ffff) AM_RAM // RAM -/**/AM_RANGE(0x408000, 0x408fff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette -/**/AM_RANGE(0x880000, 0x887fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 -/**/AM_RANGE(0x900000, 0x907fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE(&cave_vram_1) // Layer 1 -/**/AM_RANGE(0x980000, 0x987fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE(&cave_vram_2) // Layer 2 +/**/AM_RANGE(0x408000, 0x408fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette +/**/AM_RANGE(0x880000, 0x887fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 +/**/AM_RANGE(0x900000, 0x907fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 +/**/AM_RANGE(0x980000, 0x987fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE_MEMBER(cave_state, vram_2) // Layer 2 AM_RANGE(0xa80000, 0xa80007) AM_READ(cave_irq_cause_r) // IRQ Cause // AM_RANGE(0xa8006e, 0xa8006f) AM_READ(soundlatch_ack_r) // From Sound CPU AM_RANGE(0xa8006e, 0xa8006f) AM_WRITE(sound_cmd_w) // To Sound CPU - AM_RANGE(0xa80000, 0xa8007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs -/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control -/**/AM_RANGE(0xb80000, 0xb80005) AM_RAM AM_BASE(&cave_vctrl_1) // Layer 1 Control -/**/AM_RANGE(0xc00000, 0xc00005) AM_RAM AM_BASE(&cave_vctrl_2) // Layer 2 Control + AM_RANGE(0xa80000, 0xa8007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs +/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control +/**/AM_RANGE(0xb80000, 0xb80005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control +/**/AM_RANGE(0xc00000, 0xc00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_2) // Layer 2 Control AM_RANGE(0xc80000, 0xc80001) AM_READ_PORT("IN0") // Inputs AM_RANGE(0xc80002, 0xc80003) AM_READ_PORT("IN1") // Inputs + EEPROM AM_RANGE(0xd00000, 0xd00001) AM_DEVWRITE("eeprom", hotdogst_eeprom_msb_w) // EEPROM AM_RANGE(0xd00002, 0xd00003) AM_WRITENOP // ??? -/**/AM_RANGE(0xf00000, 0xf07fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites -/**/AM_RANGE(0xf08000, 0xf0ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprites? +/**/AM_RANGE(0xf00000, 0xf07fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites +/**/AM_RANGE(0xf08000, 0xf0ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprites? ADDRESS_MAP_END @@ -626,25 +628,25 @@ ADDRESS_MAP_END Koro Koro Quest ***************************************************************************/ -static UINT16 leds[2]; - -static void show_leds(void) +static void show_leds(running_machine *machine) { #ifdef MAME_DEBUG -// popmessage("led %04X eep %02X",leds[0],(leds[1] >> 8) & ~0x70); +// cave_state *state = (cave_state *)machine->driver_data; +// popmessage("led %04X eep %02X", state->leds[0], (state->leds[1] >> 8) & ~0x70); #endif } static WRITE16_HANDLER( korokoro_leds_w ) { - COMBINE_DATA( &leds[0] ); + cave_state *state = (cave_state *)space->machine->driver_data; + COMBINE_DATA(&state->leds[0]); set_led_status(space->machine, 0, data & 0x8000); set_led_status(space->machine, 1, data & 0x4000); set_led_status(space->machine, 2, data & 0x1000); // square button set_led_status(space->machine, 3, data & 0x0800); // round button -// coin_lockout_w(space->machine, 1,~data & 0x0200); // coin lockouts? -// coin_lockout_w(space->machine, 0,~data & 0x0100); +// coin_lockout_w(space->machine, 1, ~data & 0x0200); // coin lockouts? +// coin_lockout_w(space->machine, 0, ~data & 0x0100); // coin_counter_w(space->machine, 2, data & 0x0080); // coin_counter_w(space->machine, 1, data & 0x0020); @@ -655,52 +657,53 @@ static WRITE16_HANDLER( korokoro_leds_w ) set_led_status(space->machine, 7, data & 0x0002); set_led_status(space->machine, 8, data & 0x0001); - show_leds(); + show_leds(space->machine); } -static int hopper; static WRITE16_DEVICE_HANDLER( korokoro_eeprom_msb_w ) { + cave_state *state = (cave_state *)device->machine->driver_data; if (data & ~0x7000) { logerror("%s: Unknown EEPROM bit written %04X\n",cpuexec_describe_context(device->machine),data); - COMBINE_DATA( &leds[1] ); - show_leds(); + COMBINE_DATA(&state->leds[1]); + show_leds(device->machine); } - if ( ACCESSING_BITS_8_15 ) // even address + if (ACCESSING_BITS_8_15) // even address { - hopper = data & 0x0100; // ??? + state->hopper = data & 0x0100; // ??? // latch the bit eeprom_write_bit(device, data & 0x4000); // reset line asserted: reset. - eeprom_set_cs_line(device, (data & 0x1000) ? CLEAR_LINE : ASSERT_LINE ); + eeprom_set_cs_line(device, (data & 0x1000) ? CLEAR_LINE : ASSERT_LINE); // clock line asserted: write latch or select next bit to read - eeprom_set_clock_line(device, (data & 0x2000) ? ASSERT_LINE : CLEAR_LINE ); + eeprom_set_clock_line(device, (data & 0x2000) ? ASSERT_LINE : CLEAR_LINE); } } static CUSTOM_INPUT( korokoro_hopper_r ) { - return hopper ? 1 : 0; + cave_state *state = (cave_state *)field->port->machine->driver_data; + return state->hopper ? 1 : 0; } static ADDRESS_MAP_START( korokoro_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x07ffff) AM_ROM // ROM // AM_RANGE(0x100000, 0x107fff) AM_READONLY // Layer 0 - AM_RANGE(0x100000, 0x107fff) AM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 + AM_RANGE(0x100000, 0x107fff) AM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 // AM_RANGE(0x140000, 0x140005) AM_READONLY // Layer 0 Control - AM_RANGE(0x140000, 0x140005) AM_WRITEONLY AM_BASE(&cave_vctrl_0) // Layer 0 Control + AM_RANGE(0x140000, 0x140005) AM_WRITEONLY AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control // AM_RANGE(0x180000, 0x187fff) AM_READONLY // Sprites - AM_RANGE(0x180000, 0x187fff) AM_WRITEONLY AM_BASE_SIZE_GENERIC(spriteram) // Sprites + AM_RANGE(0x180000, 0x187fff) AM_WRITEONLY AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites AM_RANGE(0x1c0000, 0x1c0007) AM_READ(cave_irq_cause_r) // IRQ Cause - AM_RANGE(0x1c0000, 0x1c007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs + AM_RANGE(0x1c0000, 0x1c007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs // AM_RANGE(0x200000, 0x207fff) AM_READONLY // Palette - AM_RANGE(0x200000, 0x207fff) AM_WRITEONLY AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette + AM_RANGE(0x200000, 0x207fff) AM_WRITEONLY AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette // AM_RANGE(0x240000, 0x240003) AM_DEVREAD8( "ymz", ymz280b_r, 0x00ff) // YMZ280 AM_RANGE(0x240000, 0x240003) AM_DEVWRITE8( "ymz", ymz280b_w, 0x00ff) // YMZ280 AM_RANGE(0x280000, 0x280001) AM_READ_PORT("IN0") // Inputs + ??? @@ -719,20 +722,20 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( mazinger_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x07ffff) AM_ROM // ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM // RAM -/**/AM_RANGE(0x200000, 0x207fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites -/**/AM_RANGE(0x208000, 0x20ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprites? +/**/AM_RANGE(0x200000, 0x207fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites +/**/AM_RANGE(0x208000, 0x20ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprites? AM_RANGE(0x300000, 0x300007) AM_READ(cave_irq_cause_r) // IRQ Cause AM_RANGE(0x300068, 0x300069) AM_WRITE(watchdog_reset16_w) // Watchdog AM_RANGE(0x30006e, 0x30006f) AM_READWRITE(soundlatch_ack_r, sound_cmd_w) // From Sound CPU - AM_RANGE(0x300000, 0x30007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs - AM_RANGE(0x400000, 0x407fff) AM_RAM_WRITE(cave_vram_1_8x8_w) AM_BASE(&cave_vram_1) // Layer 1 -/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_8x8_w) AM_BASE(&cave_vram_0) // Layer 0 -/**/AM_RANGE(0x600000, 0x600005) AM_RAM AM_BASE(&cave_vctrl_1) // Layer 1 Control -/**/AM_RANGE(0x700000, 0x700005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control + AM_RANGE(0x300000, 0x30007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs + AM_RANGE(0x400000, 0x407fff) AM_RAM_WRITE(cave_vram_1_8x8_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 +/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_8x8_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 +/**/AM_RANGE(0x600000, 0x600005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control +/**/AM_RANGE(0x700000, 0x700005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control AM_RANGE(0x800000, 0x800001) AM_READ_PORT("IN0") // Inputs AM_RANGE(0x800002, 0x800003) AM_READ_PORT("IN1") // Inputs + EEPROM AM_RANGE(0x900000, 0x900001) AM_DEVWRITE("eeprom", cave_eeprom_msb_w) // EEPROM -/**/AM_RANGE(0xc08000, 0xc0ffff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette +/**/AM_RANGE(0xc08000, 0xc0ffff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette AM_RANGE(0xd00000, 0xd7ffff) AM_ROMBANK("bank1") // ROM ADDRESS_MAP_END @@ -745,27 +748,27 @@ static ADDRESS_MAP_START( metmqstr_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x07ffff) AM_ROM // ROM AM_RANGE(0x100000, 0x17ffff) AM_ROM // ROM AM_RANGE(0x200000, 0x27ffff) AM_ROM // ROM - AM_RANGE(0x408000, 0x408fff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette + AM_RANGE(0x408000, 0x408fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette AM_RANGE(0x600000, 0x600001) AM_READ(watchdog_reset16_r) // Watchdog? - AM_RANGE(0x880000, 0x887fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE(&cave_vram_2) // Layer 2 + AM_RANGE(0x880000, 0x887fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE_MEMBER(cave_state, vram_2) // Layer 2 AM_RANGE(0x888000, 0x88ffff) AM_RAM // - AM_RANGE(0x900000, 0x907fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE(&cave_vram_1) // Layer 1 + AM_RANGE(0x900000, 0x907fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 AM_RANGE(0x908000, 0x90ffff) AM_RAM // - AM_RANGE(0x980000, 0x987fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 + AM_RANGE(0x980000, 0x987fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 AM_RANGE(0x988000, 0x98ffff) AM_RAM // AM_RANGE(0xa80000, 0xa80007) AM_READ(cave_irq_cause_r) // IRQ Cause AM_RANGE(0xa80068, 0xa80069) AM_WRITE(watchdog_reset16_w) // Watchdog? AM_RANGE(0xa8006c, 0xa8006d) AM_READ(soundflags_ack_r) AM_WRITENOP // Communication AM_RANGE(0xa8006e, 0xa8006f) AM_READWRITE(soundlatch_ack_r, sound_cmd_w) // From Sound CPU - AM_RANGE(0xa80000, 0xa8007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs -/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE(&cave_vctrl_2) // Layer 2 Control -/**/AM_RANGE(0xb80000, 0xb80005) AM_RAM AM_BASE(&cave_vctrl_1) // Layer 1 Control -/**/AM_RANGE(0xc00000, 0xc00005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control + AM_RANGE(0xa80000, 0xa8007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs +/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_2) // Layer 2 Control +/**/AM_RANGE(0xb80000, 0xb80005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control +/**/AM_RANGE(0xc00000, 0xc00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control AM_RANGE(0xc80000, 0xc80001) AM_READ_PORT("IN0") // Inputs AM_RANGE(0xc80002, 0xc80003) AM_READ_PORT("IN1") // Inputs + EEPROM AM_RANGE(0xd00000, 0xd00001) AM_DEVWRITE("eeprom", metmqstr_eeprom_msb_w) // EEPROM - AM_RANGE(0xf00000, 0xf07fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites - AM_RANGE(0xf08000, 0xf0ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // RAM + AM_RANGE(0xf00000, 0xf07fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites + AM_RANGE(0xf08000, 0xf0ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // RAM ADDRESS_MAP_END @@ -780,9 +783,9 @@ static READ16_DEVICE_HANDLER( pwrinst2_eeprom_r ) INLINE void vctrl_w(UINT16 *VCTRL, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask) { - if ( offset == 4/2 ) + if (offset == 4 / 2) { - switch( data & 0x000f ) + switch (data & 0x000f) { case 1: data = (data & ~0x000f) | 0; break; case 2: data = (data & ~0x000f) | 1; break; @@ -793,10 +796,10 @@ INLINE void vctrl_w(UINT16 *VCTRL, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 } COMBINE_DATA(&VCTRL[offset]); } -static WRITE16_HANDLER( pwrinst2_vctrl_0_w ) { vctrl_w(cave_vctrl_0, offset, data, mem_mask); } -static WRITE16_HANDLER( pwrinst2_vctrl_1_w ) { vctrl_w(cave_vctrl_1, offset, data, mem_mask); } -static WRITE16_HANDLER( pwrinst2_vctrl_2_w ) { vctrl_w(cave_vctrl_2, offset, data, mem_mask); } -static WRITE16_HANDLER( pwrinst2_vctrl_3_w ) { vctrl_w(cave_vctrl_3, offset, data, mem_mask); } +static WRITE16_HANDLER( pwrinst2_vctrl_0_w ) { cave_state *state = (cave_state *)space->machine->driver_data; vctrl_w(state->vctrl_0, offset, data, mem_mask); } +static WRITE16_HANDLER( pwrinst2_vctrl_1_w ) { cave_state *state = (cave_state *)space->machine->driver_data; vctrl_w(state->vctrl_1, offset, data, mem_mask); } +static WRITE16_HANDLER( pwrinst2_vctrl_2_w ) { cave_state *state = (cave_state *)space->machine->driver_data; vctrl_w(state->vctrl_2, offset, data, mem_mask); } +static WRITE16_HANDLER( pwrinst2_vctrl_3_w ) { cave_state *state = (cave_state *)space->machine->driver_data; vctrl_w(state->vctrl_3, offset, data, mem_mask); } static ADDRESS_MAP_START( pwrinst2_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x1fffff) AM_ROM // ROM @@ -805,22 +808,22 @@ static ADDRESS_MAP_START( pwrinst2_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x500002, 0x500003) AM_READ_PORT("IN1") // AM_RANGE(0x600000, 0x6fffff) AM_ROM AM_REGION("user1", 0) // extra data ROM space AM_RANGE(0x700000, 0x700001) AM_DEVWRITE("eeprom", cave_eeprom_msb_w) // EEPROM - AM_RANGE(0x800000, 0x807fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE(&cave_vram_2) // Layer 2 - AM_RANGE(0x880000, 0x887fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 - AM_RANGE(0x900000, 0x907fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE(&cave_vram_1) // Layer 1 - AM_RANGE(0x980000, 0x987fff) AM_RAM_WRITE(cave_vram_3_8x8_w) AM_BASE(&cave_vram_3) // Layer 3 - AM_RANGE(0xa00000, 0xa07fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites - AM_RANGE(0xa08000, 0xa0ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprites? + AM_RANGE(0x800000, 0x807fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE_MEMBER(cave_state, vram_2) // Layer 2 + AM_RANGE(0x880000, 0x887fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 + AM_RANGE(0x900000, 0x907fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 + AM_RANGE(0x980000, 0x987fff) AM_RAM_WRITE(cave_vram_3_8x8_w) AM_BASE_MEMBER(cave_state, vram_3) // Layer 3 + AM_RANGE(0xa00000, 0xa07fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites + AM_RANGE(0xa08000, 0xa0ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprites? AM_RANGE(0xa10000, 0xa1ffff) AM_RAM // Sprites? - AM_RANGE(0xa80000, 0xa8007f) AM_RAM_READ(donpachi_videoregs_r) AM_BASE(&cave_videoregs) // Video Regs -/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM_WRITE(pwrinst2_vctrl_2_w) AM_BASE(&cave_vctrl_2) // Layer 2 Control -/**/AM_RANGE(0xb80000, 0xb80005) AM_RAM_WRITE(pwrinst2_vctrl_0_w) AM_BASE(&cave_vctrl_0) // Layer 0 Control -/**/AM_RANGE(0xc00000, 0xc00005) AM_RAM_WRITE(pwrinst2_vctrl_1_w) AM_BASE(&cave_vctrl_1) // Layer 1 Control -/**/AM_RANGE(0xc80000, 0xc80005) AM_RAM_WRITE(pwrinst2_vctrl_3_w) AM_BASE(&cave_vctrl_3) // Layer 3 Control + AM_RANGE(0xa80000, 0xa8007f) AM_RAM_READ(donpachi_videoregs_r) AM_BASE_MEMBER(cave_state, videoregs) // Video Regs +/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM_WRITE(pwrinst2_vctrl_2_w) AM_BASE_MEMBER(cave_state, vctrl_2) // Layer 2 Control +/**/AM_RANGE(0xb80000, 0xb80005) AM_RAM_WRITE(pwrinst2_vctrl_0_w) AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control +/**/AM_RANGE(0xc00000, 0xc00005) AM_RAM_WRITE(pwrinst2_vctrl_1_w) AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control +/**/AM_RANGE(0xc80000, 0xc80005) AM_RAM_WRITE(pwrinst2_vctrl_3_w) AM_BASE_MEMBER(cave_state, vctrl_3) // Layer 3 Control AM_RANGE(0xd80000, 0xd80001) AM_READ(soundlatch_ack_r) // ? From Sound CPU AM_RANGE(0xe00000, 0xe00001) AM_WRITE(sound_cmd_w) // To Sound CPU AM_RANGE(0xe80000, 0xe80001) AM_DEVREAD("eeprom", pwrinst2_eeprom_r) // EEPROM - AM_RANGE(0xf00000, 0xf04fff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette + AM_RANGE(0xf00000, 0xf04fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette ADDRESS_MAP_END @@ -830,13 +833,13 @@ ADDRESS_MAP_END static READ16_HANDLER( sailormn_input0_r ) { -// watchdog_reset16_r(0,0); // written too rarely for mame. +// watchdog_reset16_r(0, 0); // written too rarely for mame. return input_port_read(space->machine, "IN0"); } static READ16_HANDLER( agallet_irq_cause_r ) { - UINT16 irq_cause = cave_irq_cause_r(space,offset,mem_mask); + UINT16 irq_cause = cave_irq_cause_r(space, offset, mem_mask); if (offset == 0) { @@ -854,27 +857,27 @@ static ADDRESS_MAP_START( sailormn_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x110000, 0x110001) AM_RAM // (agallet) AM_RANGE(0x200000, 0x3fffff) AM_ROM // ROM AM_RANGE(0x400000, 0x407fff) AM_RAM // (agallet) - AM_RANGE(0x408000, 0x40bfff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette + AM_RANGE(0x408000, 0x40bfff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette AM_RANGE(0x40c000, 0x40ffff) AM_RAM // (agallet) AM_RANGE(0x410000, 0x410001) AM_RAM // (agallet) - AM_RANGE(0x500000, 0x507fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites - AM_RANGE(0x508000, 0x50ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprites? + AM_RANGE(0x500000, 0x507fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites + AM_RANGE(0x508000, 0x50ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprites? AM_RANGE(0x510000, 0x510001) AM_RAM // (agallet) AM_RANGE(0x600000, 0x600001) AM_READ(sailormn_input0_r) // Inputs + Watchdog! AM_RANGE(0x600002, 0x600003) AM_READ_PORT("IN1") // Inputs + EEPROM AM_RANGE(0x700000, 0x700001) AM_DEVWRITE("eeprom", sailormn_eeprom_msb_w) // EEPROM - AM_RANGE(0x800000, 0x807fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 - AM_RANGE(0x880000, 0x887fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE(&cave_vram_1) // Layer 1 - AM_RANGE(0x900000, 0x907fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE(&cave_vram_2) // Layer 2 + AM_RANGE(0x800000, 0x807fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 + AM_RANGE(0x880000, 0x887fff) AM_RAM_WRITE(cave_vram_1_w) AM_BASE_MEMBER(cave_state, vram_1) // Layer 1 + AM_RANGE(0x900000, 0x907fff) AM_RAM_WRITE(cave_vram_2_w) AM_BASE_MEMBER(cave_state, vram_2) // Layer 2 AM_RANGE(0x908000, 0x908001) AM_RAM // (agallet) -/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control -/**/AM_RANGE(0xa80000, 0xa80005) AM_RAM AM_BASE(&cave_vctrl_1) // Layer 1 Control -/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE(&cave_vctrl_2) // Layer 2 Control +/**/AM_RANGE(0xa00000, 0xa00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control +/**/AM_RANGE(0xa80000, 0xa80005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_1) // Layer 1 Control +/**/AM_RANGE(0xb00000, 0xb00005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_2) // Layer 2 Control AM_RANGE(0xb80000, 0xb80007) AM_READ(cave_irq_cause_r) // IRQ Cause (bit 2 tested!) AM_RANGE(0xb8006c, 0xb8006d) AM_READ(soundflags_ack_r) // Communication AM_RANGE(0xb8006e, 0xb8006f) AM_READ(soundlatch_ack_r) // From Sound CPU AM_RANGE(0xb8006e, 0xb8006f) AM_WRITE(sound_cmd_w) // To Sound CPU - AM_RANGE(0xb80000, 0xb8007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs + AM_RANGE(0xb80000, 0xb8007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs ADDRESS_MAP_END @@ -886,13 +889,13 @@ static ADDRESS_MAP_START( uopoko_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x0fffff) AM_ROM // ROM AM_RANGE(0x100000, 0x10ffff) AM_RAM // RAM AM_RANGE(0x300000, 0x300003) AM_DEVREADWRITE8("ymz", ymz280b_r, ymz280b_w, 0x00ff) // YMZ280 -/**/AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) // Sprites -/**/AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE(&cave_spriteram16_2) // Sprites? -/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE(&cave_vram_0) // Layer 0 +/**/AM_RANGE(0x400000, 0x407fff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, spriteram, spriteram_size) // Sprites +/**/AM_RANGE(0x408000, 0x40ffff) AM_RAM AM_BASE_MEMBER(cave_state, spriteram_2) // Sprites? +/**/AM_RANGE(0x500000, 0x507fff) AM_RAM_WRITE(cave_vram_0_w) AM_BASE_MEMBER(cave_state, vram_0) // Layer 0 AM_RANGE(0x600000, 0x600007) AM_READ(cave_irq_cause_r) // IRQ Cause - AM_RANGE(0x600000, 0x60007f) AM_WRITEONLY AM_BASE(&cave_videoregs) // Video Regs -/**/AM_RANGE(0x700000, 0x700005) AM_RAM AM_BASE(&cave_vctrl_0) // Layer 0 Control -/**/AM_RANGE(0x800000, 0x80ffff) AM_RAM AM_BASE_GENERIC(paletteram) AM_SIZE(&cave_paletteram_size) // Palette + AM_RANGE(0x600000, 0x60007f) AM_WRITEONLY AM_BASE_MEMBER(cave_state, videoregs) // Video Regs +/**/AM_RANGE(0x700000, 0x700005) AM_RAM AM_BASE_MEMBER(cave_state, vctrl_0) // Layer 0 Control +/**/AM_RANGE(0x800000, 0x80ffff) AM_RAM AM_BASE_SIZE_MEMBER(cave_state, paletteram, paletteram_size) // Palette AM_RANGE(0x900000, 0x900001) AM_READ_PORT("IN0") // Inputs AM_RANGE(0x900002, 0x900003) AM_READ_PORT("IN1") // Inputs + EEPROM AM_RANGE(0xa00000, 0xa00001) AM_DEVWRITE("eeprom", cave_eeprom_msb_w) // EEPROM @@ -914,11 +917,10 @@ ADDRESS_MAP_END static WRITE8_HANDLER( hotdogst_rombank_w ) { - UINT8 *RAM = memory_region(space->machine, "audiocpu"); - int bank = data & 0x0f; - if ( data & ~0x0f ) logerror("CPU #1 - PC %04X: Bank %02X\n",cpu_get_pc(space->cpu),data); - if (bank > 1) bank+=2; - memory_set_bankptr(space->machine, "bank2", &RAM[ 0x4000 * bank ]); + if (data & ~0x0f) + logerror("CPU #1 - PC %04X: Bank %02X\n", cpu_get_pc(space->cpu), data); + + memory_set_bank(space->machine, "bank2", data & 0x0f); } static WRITE8_HANDLER( hotdogst_okibank_w ) @@ -953,11 +955,10 @@ ADDRESS_MAP_END static WRITE8_HANDLER( mazinger_rombank_w ) { - UINT8 *RAM = memory_region(space->machine, "audiocpu"); - int bank = data & 0x07; - if ( data & ~0x07 ) logerror("CPU #1 - PC %04X: Bank %02X\n",cpu_get_pc(space->cpu),data); - if (bank > 1) bank+=2; - memory_set_bankptr(space->machine, "bank2", &RAM[ 0x4000 * bank ]); + if (data & ~0x07) + logerror("CPU #1 - PC %04X: Bank %02X\n", cpu_get_pc(space->cpu), data); + + memory_set_bank(space->machine, "bank2", data & 0x07); } static ADDRESS_MAP_START( mazinger_sound_map, ADDRESS_SPACE_PROGRAM, 8 ) @@ -985,11 +986,10 @@ ADDRESS_MAP_END static WRITE8_HANDLER( metmqstr_rombank_w ) { - UINT8 *ROM = memory_region(space->machine, "audiocpu"); - int bank = data & 0xf; - if ( bank != data ) logerror("CPU #1 - PC %04X: Bank %02X\n",cpu_get_pc(space->cpu),data); - if (bank >= 2) bank += 2; - memory_set_bankptr(space->machine, "bank1", &ROM[ 0x4000 * bank ]); + if (data & ~0x0f) + logerror("CPU #1 - PC %04X: Bank %02X\n", cpu_get_pc(space->cpu), data); + + memory_set_bank(space->machine, "bank1", data & 0x0f); } static WRITE8_HANDLER( metmqstr_okibank0_w ) @@ -1036,11 +1036,10 @@ ADDRESS_MAP_END static WRITE8_HANDLER( pwrinst2_rombank_w ) { - UINT8 *ROM = memory_region(space->machine, "audiocpu"); - int bank = data & 0x07; - if ( data & ~0x07 ) logerror("CPU #1 - PC %04X: Bank %02X\n",cpu_get_pc(space->cpu),data); - if (bank > 2) bank+=1; - memory_set_bankptr(space->machine, "bank1", &ROM[ 0x4000 * bank ]); + if (data & ~0x07) + logerror("CPU #1 - PC %04X: Bank %02X\n", cpu_get_pc(space->cpu), data); + + memory_set_bank(space->machine, "bank1", data & 0x07); } static ADDRESS_MAP_START( pwrinst2_sound_map, ADDRESS_SPACE_PROGRAM, 8 ) @@ -1067,23 +1066,24 @@ ADDRESS_MAP_END Sailor Moon ***************************************************************************/ -static UINT8 *mirror_ram; static READ8_HANDLER( mirror_ram_r ) { - return mirror_ram[offset]; + cave_state *state = (cave_state *)space->machine->driver_data; + return state->mirror_ram[offset]; } + static WRITE8_HANDLER( mirror_ram_w ) { - mirror_ram[offset] = data; + cave_state *state = (cave_state *)space->machine->driver_data; + state->mirror_ram[offset] = data; } static WRITE8_HANDLER( sailormn_rombank_w ) { - UINT8 *RAM = memory_region(space->machine, "audiocpu"); - int bank = data & 0x1f; - if ( data & ~0x1f ) logerror("CPU #1 - PC %04X: Bank %02X\n",cpu_get_pc(space->cpu),data); - if (bank > 1) bank+=2; - memory_set_bankptr(space->machine, "bank1", &RAM[ 0x4000 * bank ]); + if (data & ~0x1f) + logerror("CPU #1 - PC %04X: Bank %02X\n", cpu_get_pc(space->cpu), data); + + memory_set_bank(space->machine, "bank1", data & 0x1f); } static WRITE8_HANDLER( sailormn_okibank0_w ) @@ -1107,7 +1107,7 @@ static WRITE8_HANDLER( sailormn_okibank1_w ) static ADDRESS_MAP_START( sailormn_sound_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x3fff) AM_ROM // ROM AM_RANGE(0x4000, 0x7fff) AM_ROMBANK("bank1") // ROM (Banked) - AM_RANGE(0xc000, 0xdfff) AM_READWRITE(mirror_ram_r, mirror_ram_w) AM_BASE(&mirror_ram) // RAM + AM_RANGE(0xc000, 0xdfff) AM_READWRITE(mirror_ram_r, mirror_ram_w) AM_BASE_MEMBER(cave_state, mirror_ram) // RAM AM_RANGE(0xe000, 0xffff) AM_READWRITE(mirror_ram_r, mirror_ram_w) // Mirrored RAM (agallet) ADDRESS_MAP_END @@ -1143,7 +1143,7 @@ ADDRESS_MAP_END /* Most games use this */ static INPUT_PORTS_START( cave ) - PORT_START("IN0") // IN0 - Player 1 + PORT_START("IN0") // Player 1 PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) @@ -1161,7 +1161,7 @@ static INPUT_PORTS_START( cave ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN ) - PORT_START("IN1") // IN1 - Player 2 + PORT_START("IN1") // Player 2 PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) @@ -1184,7 +1184,7 @@ INPUT_PORTS_END static INPUT_PORTS_START( gaia ) PORT_INCLUDE( cave ) - PORT_MODIFY("IN0") // IN0 - Player 1 + 2 + PORT_MODIFY("IN0") // Player 1 + 2 PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) @@ -1195,7 +1195,7 @@ static INPUT_PORTS_START( gaia ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) - PORT_MODIFY("IN1") // IN1 - Coins + PORT_MODIFY("IN1") // Coins PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(6) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_IMPULSE(6) PORT_SERVICE_NO_TOGGLE( 0x0004, IP_ACTIVE_LOW ) @@ -1314,16 +1314,16 @@ INPUT_PORTS_END static INPUT_PORTS_START( metmqstr ) PORT_INCLUDE( cave ) - PORT_MODIFY("IN0") // IN0 - Player 1 + PORT_MODIFY("IN0") // Player 1 PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) - PORT_MODIFY("IN1") // IN1 - Player 2 + PORT_MODIFY("IN1") // Player 2 PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) INPUT_PORTS_END /* Different layout */ static INPUT_PORTS_START( guwange ) - PORT_START("IN0") // IN0 - Player 1 & 2 + PORT_START("IN0") // Player 1 & 2 PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_START1 ) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) @@ -1341,7 +1341,7 @@ static INPUT_PORTS_START( guwange ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) - PORT_START("IN1") // IN1 - Coins + PORT_START("IN1") // Coins PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(6) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_IMPULSE(6) PORT_SERVICE_NO_TOGGLE( 0x0004, IP_ACTIVE_LOW ) @@ -1362,7 +1362,7 @@ INPUT_PORTS_END static INPUT_PORTS_START( korokoro ) - PORT_START("IN0") // IN0 + PORT_START("IN0") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(10) // bit 0x0010 of leds (coin) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_IMPULSE(10) // bit 0x0020 of leds (does coin sound) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_COIN3 ) PORT_IMPULSE(10) // bit 0x0080 of leds @@ -1380,7 +1380,7 @@ static INPUT_PORTS_START( korokoro ) PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_SERVICE1 ) // service coin PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_SPECIAL ) PORT_CUSTOM(korokoro_hopper_r, NULL) // motor / hopper status ??? - PORT_START("IN1") // IN1 + PORT_START("IN1") PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNKNOWN ) @@ -1618,14 +1618,37 @@ GFXDECODE_END ***************************************************************************/ +static MACHINE_START( cave ) +{ + cave_state *state = (cave_state *)machine->driver_data; + + state->maincpu = devtag_get_device(machine, "maincpu"); + state->audiocpu = devtag_get_device(machine, "audiocpu"); + + state_save_register_global(machine, state->soundbuf_len); + state_save_register_global_array(machine, state->soundbuf_data); + + state_save_register_global(machine, state->vblank_irq); + state_save_register_global(machine, state->sound_irq); + state_save_register_global(machine, state->unknown_irq); + state_save_register_global(machine, state->agallet_vblank_irq); +} + static MACHINE_RESET( cave ) { - soundbuf.len = 0; + cave_state *state = (cave_state *)machine->driver_data; - /* modify the eeprom on a reset with the desired region for the games that have the - region factory set in eeprom */ - if (cave_region_byte >= 0) - memory_write_byte(cputag_get_address_space(machine, "eeprom", ADDRESS_SPACE_0), cave_region_byte, input_port_read(machine, "EEPROM")); + memset(state->soundbuf_data, 0, 32); + state->soundbuf_len = 0; + + /* modify the eeprom on a reset with the desired region for the games that have the region factory set in eeprom */ + if (state->region_byte >= 0) + memory_write_byte(cputag_get_address_space(machine, "eeprom", ADDRESS_SPACE_0), state->region_byte, input_port_read(machine, "EEPROM")); + + state->vblank_irq = 0; + state->sound_irq = 0; + state->unknown_irq = 0; + state->agallet_vblank_irq = 0; } static const ymz280b_interface ymz280b_intf = @@ -1659,11 +1682,15 @@ static const ym2203_interface ym2203_config = static MACHINE_DRIVER_START( dfeveron ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(dfeveron_map) MDRV_CPU_VBLANK_INT("screen", cave_interrupt) + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) MDRV_EEPROM_93C46_ADD("eeprom") @@ -1699,11 +1726,15 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( ddonpach ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(ddonpach_map) MDRV_CPU_VBLANK_INT("screen", cave_interrupt) + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) MDRV_EEPROM_93C46_ADD("eeprom") @@ -1743,11 +1774,15 @@ static const nmk112_interface donpachi_nmk112_intf = static MACHINE_DRIVER_START( donpachi ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(donpachi_map) MDRV_CPU_VBLANK_INT("screen", cave_interrupt) + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) MDRV_EEPROM_93C46_ADD("eeprom") @@ -1789,11 +1824,15 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( esprade ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(esprade_map) MDRV_CPU_VBLANK_INT("screen", cave_interrupt) + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) MDRV_EEPROM_93C46_ADD("eeprom") @@ -1828,11 +1867,15 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( gaia ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(gaia_map) MDRV_CPU_VBLANK_INT("screen", cave_interrupt) + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) /* video hardware */ @@ -1866,11 +1909,15 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( guwange ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(guwange_map) MDRV_CPU_VBLANK_INT("screen", cave_interrupt) + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) MDRV_EEPROM_93C46_ADD("eeprom") @@ -1904,6 +1951,9 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( hotdogst ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(hotdogst_map) @@ -1913,6 +1963,7 @@ static MACHINE_DRIVER_START( hotdogst ) MDRV_CPU_PROGRAM_MAP(hotdogst_sound_map) MDRV_CPU_IO_MAP(hotdogst_sound_portmap) + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) MDRV_EEPROM_93C46_ADD("eeprom") @@ -1958,11 +2009,15 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( korokoro ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(korokoro_map) MDRV_CPU_VBLANK_INT("screen", cave_interrupt) + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) MDRV_EEPROM_ADD("eeprom", eeprom_interface_93C46_8bit) @@ -1997,6 +2052,9 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( mazinger ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(mazinger_map) @@ -2008,6 +2066,7 @@ static MACHINE_DRIVER_START( mazinger ) MDRV_WATCHDOG_TIME_INIT(SEC(3)) /* a guess, and certainly wrong */ + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) MDRV_EEPROM_93C46_ADD("eeprom") @@ -2053,6 +2112,9 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( metmqstr ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_32MHz / 2) MDRV_CPU_PROGRAM_MAP(metmqstr_map) @@ -2064,6 +2126,7 @@ static MACHINE_DRIVER_START( metmqstr ) MDRV_WATCHDOG_TIME_INIT(SEC(3)) /* a guess, and certainly wrong */ + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) /* start with the watchdog armed */ MDRV_EEPROM_93C46_ADD("eeprom") @@ -2115,6 +2178,9 @@ static const nmk112_interface pwrinst2_nmk112_intf = static MACHINE_DRIVER_START( pwrinst2 ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) /* 16 MHz */ MDRV_CPU_PROGRAM_MAP(pwrinst2_map) @@ -2124,6 +2190,7 @@ static MACHINE_DRIVER_START( pwrinst2 ) MDRV_CPU_PROGRAM_MAP(pwrinst2_sound_map) MDRV_CPU_IO_MAP(pwrinst2_sound_portmap) + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) MDRV_EEPROM_93C46_ADD("eeprom") @@ -2176,6 +2243,9 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( sailormn ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(sailormn_map) @@ -2187,6 +2257,7 @@ static MACHINE_DRIVER_START( sailormn ) // MDRV_QUANTUM_TIME(HZ(600)) + MDRV_MACHINE_START(cave) MDRV_MACHINE_RESET(cave) MDRV_EEPROM_93C46_ADD("eeprom") @@ -2230,11 +2301,15 @@ MACHINE_DRIVER_END static MACHINE_DRIVER_START( uopoko ) + /* driver data */ + MDRV_DRIVER_DATA(cave_state) + /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M68000, XTAL_16MHz) MDRV_CPU_PROGRAM_MAP(uopoko_map) MDRV_CPU_VBLANK_INT("screen", cave_interrupt) + MDRV_MACHINE_START(cave) MDRV_EEPROM_93C46_ADD("eeprom") /* video hardware */ @@ -2297,10 +2372,10 @@ static void ddonpach_unpack_sprites(running_machine *machine) while(dst > src) { - UINT8 data1= *src--; - UINT8 data2= *src--; - UINT8 data3= *src--; - UINT8 data4= *src--; + UINT8 data1 = *src--; + UINT8 data2 = *src--; + UINT8 data3 = *src--; + UINT8 data4 = *src--; /* swap even and odd pixels, and even and odd words */ *dst-- = data2 & 0xF; *dst-- = data2 >> 4; @@ -3827,81 +3902,88 @@ static void sailormn_unpack_tiles( running_machine *machine, const char *region static void init_cave(running_machine *machine) { - cave_region_byte = -1; + cave_state *state = (cave_state *)machine->driver_data; + state->region_byte = -1; - cave_spritetype = 0; // Normal sprites - cave_kludge = 0; - time_vblank_irq = 100; + state->spritetype[0] = 0; // Normal sprites + state->kludge = 0; + state->time_vblank_irq = 100; - irq_level = 1; + state->irq_level = 1; } static DRIVER_INIT( agallet ) { + cave_state *state = (cave_state *)machine->driver_data; init_cave(machine); - sailormn_unpack_tiles( machine, "gfx4" ); + sailormn_unpack_tiles(machine, "gfx4"); - cave_region_byte = 0x1f; + state->region_byte = 0x1f; unpack_sprites(machine); -// Speed Hack + // Speed Hack memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xb80000, 0xb80001, 0, 0, agallet_irq_cause_r); } static DRIVER_INIT( dfeveron ) { + cave_state *state = (cave_state *)machine->driver_data; init_cave(machine); - cave_region_byte = -1; + state->region_byte = -1; unpack_sprites(machine); - cave_kludge = 2; + state->kludge = 2; } static DRIVER_INIT( feversos ) { + cave_state *state = (cave_state *)machine->driver_data; init_cave(machine); - cave_region_byte = -1; + state->region_byte = -1; unpack_sprites(machine); - cave_kludge = 2; + state->kludge = 2; } static DRIVER_INIT( ddonpach ) { + cave_state *state = (cave_state *)machine->driver_data; init_cave(machine); - cave_region_byte = -1; + state->region_byte = -1; ddonpach_unpack_sprites(machine); - cave_spritetype = 1; // "different" sprites (no zooming?) - time_vblank_irq = 90; + state->spritetype[0] = 1; // "different" sprites (no zooming?) + state->time_vblank_irq = 90; } static DRIVER_INIT( donpachi ) { + cave_state *state = (cave_state *)machine->driver_data; init_cave(machine); - cave_region_byte = -1; + state->region_byte = -1; ddonpach_unpack_sprites(machine); - cave_spritetype = 1; // "different" sprites (no zooming?) - time_vblank_irq = 90; + state->spritetype[0] = 1; // "different" sprites (no zooming?) + state->time_vblank_irq = 90; } static DRIVER_INIT( esprade ) { + cave_state *state = (cave_state *)machine->driver_data; init_cave(machine); - cave_region_byte = -1; + state->region_byte = -1; esprade_unpack_sprites(machine); - time_vblank_irq = 2000; /**/ + state->time_vblank_irq = 2000; /**/ #if 0 //ROM PATCH { @@ -3913,60 +3995,73 @@ static DRIVER_INIT( esprade ) static DRIVER_INIT( gaia ) { + cave_state *state = (cave_state *)machine->driver_data; init_cave(machine); /* No EEPROM */ unpack_sprites(machine); - cave_spritetype = 2; // Normal sprites with different position handling - time_vblank_irq = 2000; /**/ + state->spritetype[0] = 2; // Normal sprites with different position handling + state->time_vblank_irq = 2000; /**/ } static DRIVER_INIT( guwange ) { + cave_state *state = (cave_state *)machine->driver_data; init_cave(machine); - cave_region_byte = -1; + state->region_byte = -1; esprade_unpack_sprites(machine); - time_vblank_irq = 2000; /**/ + state->time_vblank_irq = 2000; /**/ } static DRIVER_INIT( hotdogst ) { + cave_state *state = (cave_state *)machine->driver_data; + UINT8 *ROM = memory_region(machine, "audiocpu"); + init_cave(machine); - cave_region_byte = -1; + memory_configure_bank(machine, "bank2", 0, 0x2, &ROM[0x00000], 0x4000); + memory_configure_bank(machine, "bank2", 2, 0xe, &ROM[0x10000], 0x4000); + + state->region_byte = -1; unpack_sprites(machine); - cave_spritetype = 2; // Normal sprites with different position handling - time_vblank_irq = 2000; /**/ + state->spritetype[0] = 2; // Normal sprites with different position handling + state->time_vblank_irq = 2000; /**/ } static DRIVER_INIT( mazinger ) { + cave_state *state = (cave_state *)machine->driver_data; + UINT8 *ROM = memory_region(machine, "audiocpu"); UINT8 *buffer; UINT8 *src = memory_region(machine, "gfx1"); int len = memory_region_length(machine, "gfx1"); init_cave(machine); + memory_configure_bank(machine, "bank2", 0, 2, &ROM[0x00000], 0x4000); + memory_configure_bank(machine, "bank2", 2, 6, &ROM[0x10000], 0x4000); + /* decrypt sprites */ buffer = alloc_array_or_die(UINT8, len); { int i; - for (i = 0;i < len; i++) + for (i = 0; i < len; i++) buffer[i ^ 0xdf88] = src[BITSWAP24(i,23,22,21,20,19,9,7,3,15,4,17,14,18,2,16,5,11,8,6,13,1,10,12,0)]; - memcpy(src,buffer,len); + memcpy(src, buffer, len); free(buffer); } - cave_region_byte = 0x05; + state->region_byte = 0x05; unpack_sprites(machine); - cave_spritetype = 2; // Normal sprites with different position handling - cave_kludge = 3; - time_vblank_irq = 2100; + state->spritetype[0] = 2; // Normal sprites with different position handling + state->kludge = 3; + state->time_vblank_irq = 2100; /* setup extra ROM */ memory_set_bankptr(machine, "bank1",memory_region(machine, "user1")); @@ -3975,17 +4070,25 @@ static DRIVER_INIT( mazinger ) static DRIVER_INIT( metmqstr ) { + cave_state *state = (cave_state *)machine->driver_data; + UINT8 *ROM = memory_region(machine, "audiocpu"); + init_cave(machine); + memory_configure_bank(machine, "bank1", 0, 0x2, &ROM[0x00000], 0x4000); + memory_configure_bank(machine, "bank1", 2, 0xe, &ROM[0x10000], 0x4000); + unpack_sprites(machine); - cave_spritetype = 2; // Normal sprites with different position handling - cave_kludge = 3; - time_vblank_irq = 17376; + state->spritetype[0] = 2; // Normal sprites with different position handling + state->kludge = 3; + state->time_vblank_irq = 17376; } static DRIVER_INIT( pwrins2j ) { + cave_state *state = (cave_state *)machine->driver_data; + UINT8 *ROM = memory_region(machine, "audiocpu"); UINT8 *buffer; UINT8 *src = memory_region(machine, "gfx1"); int len = memory_region_length(machine, "gfx1"); @@ -3993,9 +4096,12 @@ static DRIVER_INIT( pwrins2j ) init_cave(machine); + memory_configure_bank(machine, "bank1", 0, 3, &ROM[0x00000], 0x4000); + memory_configure_bank(machine, "bank1", 3, 5, &ROM[0x10000], 0x4000); + buffer = alloc_array_or_die(UINT8, len); { - for(i=0; ispritetype[0] = 3; + state->kludge = 4; + state->time_vblank_irq = 2000; /**/ } static DRIVER_INIT( pwrinst2 ) @@ -4024,7 +4128,7 @@ static DRIVER_INIT( pwrinst2 ) #if 1 //ROM PATCH { UINT16 *rom = (UINT16 *)memory_region(machine, "maincpu"); - rom[0xD46C/2] = 0xD482; // kurara dash fix 0xd400 -> 0xd482 + rom[0xd46c / 2] = 0xd482; // kurara dash fix 0xd400 -> 0xd482 } #endif @@ -4033,51 +4137,67 @@ static DRIVER_INIT( pwrinst2 ) static DRIVER_INIT( sailormn ) { + cave_state *state = (cave_state *)machine->driver_data; + UINT8 *ROM = memory_region(machine, "audiocpu"); UINT8 *buffer; UINT8 *src = memory_region(machine, "gfx1"); int len = memory_region_length(machine, "gfx1"); init_cave(machine); + memory_configure_bank(machine, "bank1", 0, 0x02, &ROM[0x00000], 0x4000); + memory_configure_bank(machine, "bank1", 2, 0x1e, &ROM[0x10000], 0x4000); + /* decrypt sprites */ buffer = alloc_array_or_die(UINT8, len); { int i; - for (i = 0;i < len; i++) + for (i = 0; i < len; i++) buffer[i ^ 0x950c4] = src[BITSWAP24(i,23,22,21,20,15,10,12,6,11,1,13,3,16,17,2,5,14,7,18,8,4,19,9,0)]; - memcpy(src,buffer,len); + memcpy(src, buffer, len); free(buffer); } sailormn_unpack_tiles( machine, "gfx4" ); - cave_region_byte = 0x11; + state->region_byte = 0x11; unpack_sprites(machine); - cave_spritetype = 2; // Normal sprites with different position handling - cave_kludge = 1; - time_vblank_irq = 2000; + state->spritetype[0] = 2; // Normal sprites with different position handling + state->kludge = 1; + state->time_vblank_irq = 2000; + + state->sailormn_tilebank = 0; + state_save_register_global(machine, state->sailormn_tilebank); } static DRIVER_INIT( uopoko ) { + cave_state *state = (cave_state *)machine->driver_data; init_cave(machine); - cave_region_byte = -1; + state->region_byte = -1; unpack_sprites(machine); - cave_kludge = 2; - time_vblank_irq = 2000; /**/ + state->kludge = 2; + state->time_vblank_irq = 2000; /**/ } static DRIVER_INIT( korokoro ) { + cave_state *state = (cave_state *)machine->driver_data; init_cave(machine); - irq_level = 2; + state->irq_level = 2; unpack_sprites(machine); - time_vblank_irq = 2000; /**/ + state->time_vblank_irq = 2000; /**/ + + state->leds[0] = 0; + state->leds[1] = 0; + state->hopper = 0; + state_save_register_global_array(machine, state->leds); + state_save_register_global(machine, state->hopper); } /*************************************************************************** diff --git a/src/mame/includes/cave.h b/src/mame/includes/cave.h index ee15a14033a..1ece14d3497 100644 --- a/src/mame/includes/cave.h +++ b/src/mame/includes/cave.h @@ -4,21 +4,115 @@ ***************************************************************************/ +struct sprite_cave +{ + int priority, flags; + + const UINT8 *pen_data; /* points to top left corner of tile data */ + int line_offset; + + pen_t base_pen; + int tile_width, tile_height; + int total_width, total_height; /* in screen coordinates */ + int x, y, xcount0, ycount0; + int zoomx_re, zoomy_re; +}; + +#define MAX_PRIORITY 4 +#define MAX_SPRITE_NUM 0x400 + +typedef struct _cave_state cave_state; +struct _cave_state +{ + /* memory pointers */ + UINT16 * videoregs; + UINT16 * vram_0; + UINT16 * vram_1; + UINT16 * vram_2; + UINT16 * vram_3; + UINT16 * vctrl_0; + UINT16 * vctrl_1; + UINT16 * vctrl_2; + UINT16 * vctrl_3; + UINT16 * spriteram; + UINT16 * spriteram_2; + UINT16 * paletteram; + size_t spriteram_size; + size_t paletteram_size; + + /* video-related */ + struct sprite_cave *sprite; + struct sprite_cave *sprite_table[MAX_PRIORITY][MAX_SPRITE_NUM + 1]; + + struct + { + int clip_left, clip_right, clip_top, clip_bottom; + UINT8 *baseaddr; + int line_offset; + UINT8 *baseaddr_zbuf; + int line_offset_zbuf; + } blit; + + + void (*get_sprite_info)(running_machine *machine); + void (*sprite_draw)(running_machine *machine, int priority); + + tilemap_t *tilemap_0, *tilemap_1, *tilemap_2, *tilemap_3; + int tiledim_0, old_tiledim_0; + int tiledim_1, old_tiledim_1; + int tiledim_2, old_tiledim_2; + int tiledim_3, old_tiledim_3; + + bitmap_t *sprite_zbuf; + UINT16 sprite_zbuf_baseval; + + int num_sprites; + + int spriteram_bank; + int spriteram_bank_delay; + + UINT16 *palette_map; + + int layers_offs_x, layers_offs_y; + int row_effect_offs_n; + int row_effect_offs_f; + int background_color; + + int spritetype[2]; + int kludge; + + + /* misc */ + int time_vblank_irq; + UINT8 irq_level; + UINT8 vblank_irq; + UINT8 sound_irq; + UINT8 unknown_irq; + UINT8 agallet_vblank_irq; + + /* sound related */ + int soundbuf_len; + UINT8 soundbuf_data[32]; + //UINT8 sound_flag1, sound_flag2; + + /* eeprom-related */ + int region_byte; + + /* game specific */ + // sailormn + int sailormn_tilebank; + UINT8 *mirror_ram; + // korokoro + UINT16 leds[2]; + int hopper; + + /* devices */ + const device_config *maincpu; + const device_config *audiocpu; +}; + /*----------- defined in video/cave.c -----------*/ -extern UINT16 *cave_spriteram16_2; - -extern int cave_spritetype; -extern int cave_kludge; - -extern UINT16 *cave_videoregs; - -extern UINT16 *cave_vram_0, *cave_vctrl_0; -extern UINT16 *cave_vram_1, *cave_vctrl_1; -extern UINT16 *cave_vram_2, *cave_vctrl_2; -extern UINT16 *cave_vram_3, *cave_vctrl_3; -extern size_t cave_paletteram_size; - WRITE16_HANDLER( cave_vram_0_w ); WRITE16_HANDLER( cave_vram_1_w ); WRITE16_HANDLER( cave_vram_2_w ); @@ -44,9 +138,7 @@ VIDEO_START( cave_4_layers ); VIDEO_START( sailormn_3_layers ); - VIDEO_UPDATE( cave ); void cave_get_sprite_info(running_machine *machine); - -void sailormn_tilebank_w( int bank ); +void sailormn_tilebank_w(running_machine *machine, int bank); diff --git a/src/mame/video/cave.c b/src/mame/video/cave.c index 72e48b55a73..559737d961a 100644 --- a/src/mame/video/cave.c +++ b/src/mame/video/cave.c @@ -47,87 +47,22 @@ Note: if MAME_DEBUG is defined, pressing: #include "driver.h" #include "includes/cave.h" -/* Variables that driver has access to: */ -int cave_spritetype; -int cave_kludge = 0; +#define CAVE_SPRITETYPE_ZBUF 0x01 +#define CAVE_SPRITETYPE_ZOOM 0x02 -UINT16 *cave_videoregs; +#define SPRITE_FLIPX_CAVE 0x01 +#define SPRITE_FLIPY_CAVE 0x02 +#define SPRITE_VISIBLE_CAVE 0x04 -UINT16 *cave_vram_0, *cave_vctrl_0; -UINT16 *cave_vram_1, *cave_vctrl_1; -UINT16 *cave_vram_2, *cave_vctrl_2; -UINT16 *cave_vram_3, *cave_vctrl_3; -UINT16 *cave_spriteram16_2; -size_t cave_paletteram_size; - - -/* Variables only used here: */ - -static tilemap_t *tilemap_0; -static int tiledim_0, old_tiledim_0; -static tilemap_t *tilemap_1; -static int tiledim_1, old_tiledim_1; -static tilemap_t *tilemap_2; -static int tiledim_2, old_tiledim_2; -static tilemap_t *tilemap_3; -static int tiledim_3, old_tiledim_3; - - - -#define CAVE_SPRITETYPE_ZBUF 0x01 -#define CAVE_SPRITETYPE_ZOOM 0x02 -static int cave_spritetype2; - -#define SPRITE_FLIPX_CAVE 0x01 -#define SPRITE_FLIPY_CAVE 0x02 -#define SPRITE_VISIBLE_CAVE 0x04 #define SWAP(X,Y) { int temp = X; X = Y; Y = temp; } -struct sprite_cave { - int priority, flags; - - const UINT8 *pen_data; /* points to top left corner of tile data */ - int line_offset; - - pen_t base_pen; - int tile_width, tile_height; - int total_width, total_height; /* in screen coordinates */ - int x, y, xcount0, ycount0; - int zoomx_re, zoomy_re; -}; - -static int screen_width, screen_height; - -static struct { - int clip_left, clip_right, clip_top, clip_bottom; - UINT8 *baseaddr; - int line_offset; - UINT8 *baseaddr_zbuf; - int line_offset_zbuf; -} blit; - -#define MAX_PRIORITY 4 -#define MAX_SPRITE_NUM 0x400 -static int num_sprites; -static struct sprite_cave *sprite_cave; -static struct sprite_cave *sprite_table[MAX_PRIORITY][MAX_SPRITE_NUM+1]; -static bitmap_t *sprite_zbuf; -static UINT16 sprite_zbuf_baseval; - -static void (*get_sprite_info)(running_machine *machine); -static void (*cave_sprite_draw)( int priority ); - static void sprite_init_cave(running_machine *machine); -static void sprite_draw_cave( int priority ); -static void sprite_draw_cave_zbuf( int priority ); -static void sprite_draw_donpachi( int priority ); -static void sprite_draw_donpachi_zbuf( int priority ); - -static int spriteram_bank; -static int spriteram_bank_delay; - -static UINT16 *palette_map; +static void sprite_draw_cave(running_machine *machine, int priority); +static void sprite_draw_cave_zbuf(running_machine *machine, int priority); +static void sprite_draw_donpachi(running_machine *machine, int priority); +static void sprite_draw_donpachi_zbuf(running_machine *machine, int priority); +static STATE_POSTLOAD(cave_sprite_postload); /*************************************************************************** @@ -140,17 +75,20 @@ static UINT16 *palette_map; PALETTE_INIT( cave ) { - int maxpen = cave_paletteram_size / 2; + cave_state *state = (cave_state *)machine->driver_data; + int maxpen = state->paletteram_size / 2; int pen; /* create a 1:1 palette map covering everything */ - palette_map = auto_alloc_array(machine, UINT16, machine->config->total_colors); + state->palette_map = auto_alloc_array(machine, UINT16, machine->config->total_colors); + for (pen = 0; pen < machine->config->total_colors; pen++) - palette_map[pen] = pen % maxpen; + state->palette_map[pen] = pen % maxpen; } PALETTE_INIT( dfeveron ) { + cave_state *state = (cave_state *)machine->driver_data; int color, pen; /* Fill the 0-3fff range, used by sprites ($40 color codes * $100 pens) @@ -162,11 +100,12 @@ PALETTE_INIT( dfeveron ) for (color = 0; color < 0x40; color++) for (pen = 0; pen < 0x10; pen++) - palette_map[(color << 8) | pen] = (color << 4) | pen; + state->palette_map[(color << 8) | pen] = (color << 4) | pen; } PALETTE_INIT( ddonpach ) { + cave_state *state = (cave_state *)machine->driver_data; int color, pen; /* Fill the 8000-83ff range ($40 color codes * $10 pens) for @@ -178,11 +117,12 @@ PALETTE_INIT( ddonpach ) for (color = 0; color < 0x40; color++) for (pen = 0; pen < 0x10; pen++) - palette_map[0x8000 | (color << 4) | pen] = 0x4000 | (color << 8) | pen; + state->palette_map[0x8000 | (color << 4) | pen] = 0x4000 | (color << 8) | pen; } PALETTE_INIT( mazinger ) { + cave_state *state = (cave_state *)machine->driver_data; int color, pen; PALETTE_INIT_CALL(cave); @@ -190,17 +130,18 @@ PALETTE_INIT( mazinger ) /* sprites (encrypted) are 4 bit deep */ for (color = 0; color < 0x40; color++) for (pen = 0; pen < 0x100; pen++) - palette_map[(color << 8) | pen] = (color << 4) + pen; /* yes, PLUS, not OR */ + state->palette_map[(color << 8) | pen] = (color << 4) + pen; /* yes, PLUS, not OR */ /* layer 0 is 6 bit deep, there are 64 color codes but only $400 colors are actually addressable */ for (color = 0; color < 0x40; color++) for (pen = 0; pen < 0x40; pen++) - palette_map[0x4400 + ((color << 6) | pen)] = 0x400 | ((color & 0x0f) << 6) | pen; + state->palette_map[0x4400 + ((color << 6) | pen)] = 0x400 | ((color & 0x0f) << 6) | pen; } PALETTE_INIT( sailormn ) { + cave_state *state = (cave_state *)machine->driver_data; int color, pen; PALETTE_INIT_CALL(cave); @@ -208,48 +149,51 @@ PALETTE_INIT( sailormn ) /* sprites (encrypted) are 4 bit deep */ for (color = 0; color < 0x40; color++) for (pen = 0; pen < 0x100; pen++) - palette_map[(color << 8) | pen] = (color << 4) + pen; /* yes, PLUS, not OR */ + state->palette_map[(color << 8) | pen] = (color << 4) + pen; /* yes, PLUS, not OR */ /* layer 2 is 6 bit deep, there are 64 color codes but only $400 colors are actually addressable */ for (color = 0; color < 0x40; color++) for (pen = 0; pen < 0x40; pen++) - palette_map[0x4c00 | (color << 6) | pen] = 0xc00 | ((color & 0x0f) << 6) | pen; + state->palette_map[0x4c00 | (color << 6) | pen] = 0xc00 | ((color & 0x0f) << 6) | pen; } PALETTE_INIT( pwrinst2 ) { + cave_state *state = (cave_state *)machine->driver_data; int color, pen; PALETTE_INIT_CALL(cave); for (color = 0; color < 0x80; color++) for (pen = 0; pen < 0x10; pen++) - palette_map[(color << 8) | pen] = (color << 4) | pen; + state->palette_map[(color << 8) | pen] = (color << 4) | pen; for (pen = 0x8000; pen < 0xa800; pen++) - palette_map[pen] = pen - 0x8000; + state->palette_map[pen] = pen - 0x8000; } PALETTE_INIT( korokoro ) { + cave_state *state = (cave_state *)machine->driver_data; int color, pen; PALETTE_INIT_CALL(cave); for (color = 0; color < 0x40; color++) for (pen = 0; pen < 0x10; pen++) - palette_map[(color << 8) | pen] = 0x3c00 | (color << 4) | pen; + state->palette_map[(color << 8) | pen] = 0x3c00 | (color << 4) | pen; } -static void set_pens(running_machine *machine) +static void set_pens( running_machine *machine ) { + cave_state *state = (cave_state *)machine->driver_data; int pen; for (pen = 0; pen < machine->config->total_colors; pen++) { - UINT16 data = machine->generic.paletteram.u16[palette_map[pen]]; + UINT16 data = state->paletteram[state->palette_map[pen]]; rgb_t color = MAKE_RGB(pal5bit(data >> 5), pal5bit(data >> 10), pal5bit(data >> 0)); @@ -281,108 +225,99 @@ static void set_pens(running_machine *machine) ***************************************************************************/ -INLINE void get_tile_info(running_machine *machine, tile_data *tileinfo, int tile_index, int GFX, UINT16 *VRAM, int TDIM) +INLINE void get_tile_info( running_machine *machine, tile_data *tileinfo, int tile_index, int GFX, UINT16 *VRAM, int TDIM ) { UINT32 code, color, pri, tile; - if ( TDIM ) + if (TDIM) { - tile = (tile_index % (512/8))/2 + ((tile_index / (512/8))/2)*(512/16); + tile = (tile_index % (512 / 8)) / 2 + ((tile_index / (512 / 8)) / 2) * (512 / 16); + code = (VRAM[tile * 2 + 0x0000 / 2] << 16) + VRAM[tile * 2 + 0x0002 / 2]; - code = (VRAM[ tile * 2 + 0x0000/2] << 16) + - VRAM[ tile * 2 + 0x0002/2]; + color = (code & 0x3f000000) >> (32-8); + pri = (code & 0xc0000000) >> (32-2); + code = (code & 0x00ffffff) * 4; - color = (code & 0x3f000000) >> (32-8); - pri = (code & 0xc0000000) >> (32-2); - code = (code & 0x00ffffff) * 4; - - code += tile_index & 1; - code += ( (tile_index / (512/8)) & 1 ) * 2; + code += tile_index & 1; + code += ((tile_index / (512 / 8)) & 1) * 2; } else { - code = (VRAM[ tile_index * 2 + 0x4000/2] << 16) + - VRAM[ tile_index * 2 + 0x4002/2]; + code = (VRAM[tile_index * 2 + 0x4000 / 2] << 16) + VRAM[tile_index * 2 + 0x4002 / 2]; - color = (code & 0x3f000000) >> (32-8); - pri = (code & 0xc0000000) >> (32-2); - code = (code & 0x00ffffff); + color = (code & 0x3f000000) >> (32 - 8); + pri = (code & 0xc0000000) >> (32 - 2); + code = (code & 0x00ffffff); } - SET_TILE_INFO( GFX, - code, - color, - 0 ); - tileinfo->category = pri; + SET_TILE_INFO( GFX, code, color, 0 ); + tileinfo->category = pri; } + /* Sailormn: the lower 2 Megabytes of tiles banked */ -static int sailormn_tilebank; - -void sailormn_tilebank_w( int bank ) +void sailormn_tilebank_w( running_machine *machine, int bank ) { - if (sailormn_tilebank != bank) + cave_state *state = (cave_state *)machine->driver_data; + if (state->sailormn_tilebank != bank) { - sailormn_tilebank = bank; - tilemap_mark_all_tiles_dirty(tilemap_2); + state->sailormn_tilebank = bank; + tilemap_mark_all_tiles_dirty(state->tilemap_2); } } static TILE_GET_INFO( sailormn_get_tile_info_2 ) { + cave_state *state = (cave_state *)machine->driver_data; UINT32 code, color, pri; - if ( tiledim_2 ) + if (state->tiledim_2) { UINT32 tile; - tile = (tile_index % (512/8))/2 + ((tile_index / (512/8))/2)*(512/16); + tile = (tile_index % (512 / 8)) / 2 + ((tile_index / (512 / 8)) / 2) * (512 / 16); + code = (state->vram_2[tile * 2 + 0x0000 / 2] << 16) + state->vram_2[tile * 2 + 0x0002 / 2]; - code = (cave_vram_2[ tile * 2 + 0x0000/2] << 16) + - cave_vram_2[ tile * 2 + 0x0002/2]; + color = (code & 0x3f000000) >> (32 - 8); + pri = (code & 0xc0000000) >> (32 - 2); + code = (code & 0x00ffffff) * 4; - color = (code & 0x3f000000) >> (32-8); - pri = (code & 0xc0000000) >> (32-2); - code = (code & 0x00ffffff) * 4; - - code += tile_index & 1; - code += ( (tile_index / (512/8)) & 1 ) * 2; + code += tile_index & 1; + code += ((tile_index / (512 / 8)) & 1) * 2; } else { - code = (cave_vram_2[ tile_index * 2 + 0x4000/2] << 16) + - cave_vram_2[ tile_index * 2 + 0x4002/2]; + code = (state->vram_2[tile_index * 2 + 0x4000 / 2] << 16) + state->vram_2[tile_index * 2 + 0x4002 / 2]; - color = (code & 0x3f000000) >> (32-8); - pri = (code & 0xc0000000) >> (32-2); - code = (code & 0x00ffffff); - if ((code < 0x10000) && (sailormn_tilebank)) + color = (code & 0x3f000000) >> (32 - 8); + pri = (code & 0xc0000000) >> (32 - 2); + code = (code & 0x00ffffff); + if ((code < 0x10000) && (state->sailormn_tilebank)) code += 0x40000; } - SET_TILE_INFO( 2, - code, - color, - 0 ); - tileinfo->category = pri; + SET_TILE_INFO( 2, code, color, 0 ); + tileinfo->category = pri; } -INLINE void vram_w(UINT16 *VRAM, tilemap_t *TILEMAP, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask) +INLINE void vram_w( UINT16 *VRAM, tilemap_t *TILEMAP, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask ) { - if ((VRAM[offset] & mem_mask)==(data & mem_mask)) return; + if ((VRAM[offset] & mem_mask) == (data & mem_mask)) + return; + COMBINE_DATA(&VRAM[offset]); offset /= 2; - if ( offset < 0x1000/4 ) // 16x16 tilemap + if (offset < 0x1000 / 4) // 16x16 tilemap { - offset = (offset % (512/16))*2 + (offset / (512/16))*(512/8)*2; + offset = (offset % (512 / 16)) * 2 + (offset / (512 / 16)) * (512 / 8) * 2; tilemap_mark_tile_dirty(TILEMAP, offset + 0); tilemap_mark_tile_dirty(TILEMAP, offset + 1); - tilemap_mark_tile_dirty(TILEMAP, offset + 0 + 512/8); - tilemap_mark_tile_dirty(TILEMAP, offset + 1 + 512/8); + tilemap_mark_tile_dirty(TILEMAP, offset + 0 + 512 / 8); + tilemap_mark_tile_dirty(TILEMAP, offset + 1 + 512 / 8); } - else if ( offset >= 0x4000/4 ) // 8x8 tilemap - tilemap_mark_tile_dirty(TILEMAP,offset - 0x4000/4); + else if (offset >= 0x4000 / 4) // 8x8 tilemap + tilemap_mark_tile_dirty(TILEMAP, offset - 0x4000 / 4); } /* Some games, that only ever use the 8x8 tiles and no line scroll, @@ -390,31 +325,70 @@ INLINE void vram_w(UINT16 *VRAM, tilemap_t *TILEMAP, ATTR_UNUSED offs_t offset, and 408000-407fff both go to the 8x8 tilemap ram. Use this function in this cases. Note that the get_tile_info function looks in the 4000-7fff range for tiles, so we have to write the data there. */ -INLINE void vram_8x8_w(UINT16 *VRAM, tilemap_t *TILEMAP,ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask) +INLINE void vram_8x8_w( UINT16 *VRAM, tilemap_t *TILEMAP, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask ) { - offset %= 0x4000/2; - if ((VRAM[offset] & mem_mask)==(data & mem_mask)) return; - COMBINE_DATA(&VRAM[offset + 0x0000/2]); - COMBINE_DATA(&VRAM[offset + 0x4000/2]); - tilemap_mark_tile_dirty(TILEMAP,offset/2); + offset %= 0x4000 / 2; + if ((VRAM[offset] & mem_mask) == (data & mem_mask)) + return; + + COMBINE_DATA(&VRAM[offset + 0x0000 / 2]); + COMBINE_DATA(&VRAM[offset + 0x4000 / 2]); + tilemap_mark_tile_dirty(TILEMAP,offset / 2); } -static TILE_GET_INFO( get_tile_info_0 ) { get_tile_info(machine, tileinfo, tile_index, 0, cave_vram_0, tiledim_0 ); } -static TILE_GET_INFO( get_tile_info_1 ) { get_tile_info(machine, tileinfo, tile_index, 1, cave_vram_1, tiledim_1 ); } -static TILE_GET_INFO( get_tile_info_2 ) { get_tile_info(machine, tileinfo, tile_index, 2, cave_vram_2, tiledim_2 ); } -static TILE_GET_INFO( get_tile_info_3 ) { get_tile_info(machine, tileinfo, tile_index, 3, cave_vram_3, tiledim_3 ); } -WRITE16_HANDLER( cave_vram_0_w ) { vram_w (cave_vram_0, tilemap_0, offset, data, mem_mask); } -WRITE16_HANDLER( cave_vram_0_8x8_w ) { vram_8x8_w(cave_vram_0, tilemap_0, offset, data, mem_mask); } +static TILE_GET_INFO( get_tile_info_0 ) { cave_state *state = (cave_state *)machine->driver_data; get_tile_info(machine, tileinfo, tile_index, 0, state->vram_0, state->tiledim_0); } +static TILE_GET_INFO( get_tile_info_1 ) { cave_state *state = (cave_state *)machine->driver_data; get_tile_info(machine, tileinfo, tile_index, 1, state->vram_1, state->tiledim_1); } +static TILE_GET_INFO( get_tile_info_2 ) { cave_state *state = (cave_state *)machine->driver_data; get_tile_info(machine, tileinfo, tile_index, 2, state->vram_2, state->tiledim_2); } +static TILE_GET_INFO( get_tile_info_3 ) { cave_state *state = (cave_state *)machine->driver_data; get_tile_info(machine, tileinfo, tile_index, 3, state->vram_3, state->tiledim_3); } -WRITE16_HANDLER( cave_vram_1_w ) { vram_w (cave_vram_1, tilemap_1, offset, data, mem_mask); } -WRITE16_HANDLER( cave_vram_1_8x8_w ) { vram_8x8_w(cave_vram_1, tilemap_1, offset, data, mem_mask); } +WRITE16_HANDLER( cave_vram_0_w ) +{ + cave_state *state = (cave_state *)space->machine->driver_data; + vram_w(state->vram_0, state->tilemap_0, offset, data, mem_mask); +} -WRITE16_HANDLER( cave_vram_2_w ) { vram_w (cave_vram_2, tilemap_2, offset, data, mem_mask); } -WRITE16_HANDLER( cave_vram_2_8x8_w ) { vram_8x8_w(cave_vram_2, tilemap_2, offset, data, mem_mask); } +WRITE16_HANDLER( cave_vram_0_8x8_w ) +{ + cave_state *state = (cave_state *)space->machine->driver_data; + vram_8x8_w(state->vram_0, state->tilemap_0, offset, data, mem_mask); +} -WRITE16_HANDLER( cave_vram_3_w ) { vram_w (cave_vram_3, tilemap_3, offset, data, mem_mask); } -WRITE16_HANDLER( cave_vram_3_8x8_w ) { vram_8x8_w(cave_vram_3, tilemap_3, offset, data, mem_mask); } +WRITE16_HANDLER( cave_vram_1_w ) +{ + cave_state *state = (cave_state *)space->machine->driver_data; + vram_w(state->vram_1, state->tilemap_1, offset, data, mem_mask); +} + +WRITE16_HANDLER( cave_vram_1_8x8_w ) +{ + cave_state *state = (cave_state *)space->machine->driver_data; + vram_8x8_w(state->vram_1, state->tilemap_1, offset, data, mem_mask); +} + +WRITE16_HANDLER( cave_vram_2_w ) +{ + cave_state *state = (cave_state *)space->machine->driver_data; + vram_w(state->vram_2, state->tilemap_2, offset, data, mem_mask); +} + +WRITE16_HANDLER( cave_vram_2_8x8_w ) +{ + cave_state *state = (cave_state *)space->machine->driver_data; + vram_8x8_w(state->vram_2, state->tilemap_2, offset, data, mem_mask); +} + +WRITE16_HANDLER( cave_vram_3_w ) +{ + cave_state *state = (cave_state *)space->machine->driver_data; + vram_w(state->vram_3, state->tilemap_3, offset, data, mem_mask); +} + +WRITE16_HANDLER( cave_vram_3_8x8_w ) +{ + cave_state *state = (cave_state *)space->machine->driver_data; + vram_8x8_w(state->vram_3, state->tilemap_3, offset, data, mem_mask); +} /*************************************************************************** @@ -426,89 +400,95 @@ WRITE16_HANDLER( cave_vram_3_8x8_w ) { vram_8x8_w(cave_vram_3, tilemap_3, offset ***************************************************************************/ -static int cave_layers_offs_x, cave_layers_offs_y; -static int cave_row_effect_offs_n; -static int cave_row_effect_offs_f; -static int background_color; - -static void cave_vh_start(running_machine *machine, int num) +static void cave_vh_start( running_machine *machine, int num ) { - assert(palette_map != NULL); + cave_state *state = (cave_state *)machine->driver_data; - tilemap_0 = 0; - tilemap_1 = 0; - tilemap_2 = 0; - tilemap_3 = 0; + assert(state->palette_map != NULL); - tiledim_0 = 0; - tiledim_1 = 0; - tiledim_2 = 0; - tiledim_3 = 0; + state->tilemap_0 = 0; + state->tilemap_1 = 0; + state->tilemap_2 = 0; + state->tilemap_3 = 0; - old_tiledim_0 = 0; - old_tiledim_1 = 0; - old_tiledim_2 = 0; - old_tiledim_3 = 0; + state->tiledim_0 = 0; + state->tiledim_1 = 0; + state->tiledim_2 = 0; + state->tiledim_3 = 0; + + state->old_tiledim_0 = 0; + state->old_tiledim_1 = 0; + state->old_tiledim_2 = 0; + state->old_tiledim_3 = 0; assert((num >= 1) && (num <= 4)); - switch( num ) + switch (num) { case 4: - tilemap_3 = tilemap_create( machine, get_tile_info_3, tilemap_scan_rows, 8,8, 512/8,512/8 ); - tilemap_set_transparent_pen(tilemap_3, 0); - tilemap_set_scroll_rows(tilemap_3, 1); - tilemap_set_scroll_cols(tilemap_3, 1); + state->tilemap_3 = tilemap_create(machine, get_tile_info_3, tilemap_scan_rows, 8, 8, 512 / 8, 512 / 8); + tilemap_set_transparent_pen(state->tilemap_3, 0); + tilemap_set_scroll_rows(state->tilemap_3, 1); + tilemap_set_scroll_cols(state->tilemap_3, 1); + state_save_register_global(machine, state->tiledim_3); + state_save_register_global(machine, state->old_tiledim_3); case 3: - tilemap_2 = tilemap_create( machine, get_tile_info_2, tilemap_scan_rows, 8,8, 512/8,512/8 ); - tilemap_set_transparent_pen(tilemap_2, 0); - tilemap_set_scroll_rows(tilemap_2, 1); - tilemap_set_scroll_cols(tilemap_2, 1); + state->tilemap_2 = tilemap_create(machine, get_tile_info_2, tilemap_scan_rows, 8, 8, 512 / 8, 512 / 8); + tilemap_set_transparent_pen(state->tilemap_2, 0); + tilemap_set_scroll_rows(state->tilemap_2, 1); + tilemap_set_scroll_cols(state->tilemap_2, 1); + state_save_register_global(machine, state->tiledim_2); + state_save_register_global(machine, state->old_tiledim_2); case 2: - tilemap_1 = tilemap_create( machine, get_tile_info_1, tilemap_scan_rows, 8,8, 512/8,512/8 ); - tilemap_set_transparent_pen(tilemap_1, 0); - tilemap_set_scroll_rows(tilemap_1, 1); - tilemap_set_scroll_cols(tilemap_1, 1); + state->tilemap_1 = tilemap_create(machine, get_tile_info_1, tilemap_scan_rows, 8, 8, 512 / 8, 512 / 8); + tilemap_set_transparent_pen(state->tilemap_1, 0); + tilemap_set_scroll_rows(state->tilemap_1, 1); + tilemap_set_scroll_cols(state->tilemap_1, 1); + state_save_register_global(machine, state->tiledim_1); + state_save_register_global(machine, state->old_tiledim_1); case 1: - tilemap_0 = tilemap_create( machine, get_tile_info_0, tilemap_scan_rows, 8,8, 512/8,512/8 ); - tilemap_set_transparent_pen(tilemap_0, 0); - tilemap_set_scroll_rows(tilemap_0, 1); - tilemap_set_scroll_cols(tilemap_0, 1); + state->tilemap_0 = tilemap_create(machine, get_tile_info_0, tilemap_scan_rows, 8, 8, 512 / 8, 512 / 8); + tilemap_set_transparent_pen(state->tilemap_0, 0); + tilemap_set_scroll_rows(state->tilemap_0, 1); + tilemap_set_scroll_cols(state->tilemap_0, 1); + state_save_register_global(machine, state->tiledim_0); + state_save_register_global(machine, state->old_tiledim_0); break; } sprite_init_cave(machine); - cave_layers_offs_x = 0x13; - cave_layers_offs_y = -0x12; + state->layers_offs_x = 0x13; + state->layers_offs_y = -0x12; - cave_row_effect_offs_n = -1; - cave_row_effect_offs_f = 1; + state->row_effect_offs_n = -1; + state->row_effect_offs_f = 1; - background_color = machine->config->gfxdecodeinfo[0].color_codes_start + - (machine->config->gfxdecodeinfo[0].total_color_codes-1) * - machine->gfx[0]->color_granularity; + state->background_color = machine->config->gfxdecodeinfo[0].color_codes_start + + (machine->config->gfxdecodeinfo[0].total_color_codes - 1) * + machine->gfx[0]->color_granularity; - switch(cave_kludge) + switch (state->kludge) { - case 1: /* sailormn */ - cave_row_effect_offs_n = -1; - cave_row_effect_offs_f = -1; + case 1: /* sailormn */ + state->row_effect_offs_n = -1; + state->row_effect_offs_f = -1; break; - case 2: /* uopoko dfeveron */ - background_color = 0x3f00; + case 2: /* uopoko dfeveron */ + state->background_color = 0x3f00; + break; + case 4: /* pwrinst2 */ + state->background_color = 0x7f00; + state->layers_offs_y++; break; - case 4: /* pwrinst2 */ - background_color = 0x7f00; - cave_layers_offs_y++; } } -VIDEO_START( cave_1_layer ) { cave_vh_start(machine, 1); } +VIDEO_START( cave_1_layer ) { cave_vh_start(machine, 1); } VIDEO_START( cave_2_layers ) { cave_vh_start(machine, 2); } VIDEO_START( cave_3_layers ) { cave_vh_start(machine, 3); } VIDEO_START( cave_4_layers ) { cave_vh_start(machine, 4); } @@ -516,14 +496,15 @@ VIDEO_START( cave_4_layers ) { cave_vh_start(machine, 4); } VIDEO_START( sailormn_3_layers ) { + cave_state *state = (cave_state *)machine->driver_data; cave_vh_start(machine, 2); /* Layer 2 (8x8) needs to be handled differently */ - tilemap_2 = tilemap_create( machine, sailormn_get_tile_info_2, tilemap_scan_rows, - 8,8, 512/8,512/8 ); - tilemap_set_transparent_pen(tilemap_2, 0); - tilemap_set_scroll_rows(tilemap_2, 1); - tilemap_set_scroll_cols(tilemap_2, 1); + state->tilemap_2 = tilemap_create(machine, sailormn_get_tile_info_2, tilemap_scan_rows, 8, 8, 512 / 8, 512 / 8 ); + + tilemap_set_transparent_pen(state->tilemap_2, 0); + tilemap_set_scroll_rows(state->tilemap_2, 1); + tilemap_set_scroll_cols(state->tilemap_2, 1); } /*************************************************************************** @@ -558,72 +539,72 @@ VIDEO_START( sailormn_3_layers ) ***************************************************************************/ -static void get_sprite_info_cave(running_machine *machine) +static void get_sprite_info_cave( running_machine *machine ) { - pen_t base_pal = 0; - const UINT8 *base_gfx = memory_region(machine, "gfx1"); - int code_max = memory_region_length(machine, "gfx1") / (16*16); + cave_state *state = (cave_state *)machine->driver_data; + pen_t base_pal = 0; + const UINT8 *base_gfx = memory_region(machine, "gfx1"); + int code_max = memory_region_length(machine, "gfx1") / (16*16); + + UINT16 *source; + UINT16 *finish; + struct sprite_cave *sprite = state->sprite; + + int glob_flipx = state->videoregs[0] & 0x8000; + int glob_flipy = state->videoregs[1] & 0x8000; + + int max_x = video_screen_get_width(machine->primary_screen); + int max_y = video_screen_get_height(machine->primary_screen); + + source = state->spriteram + ((state->spriteram_size / 2) / 2) * state->spriteram_bank; + + if (state->videoregs[4] & 0x02) + if (state->spriteram_2) + source = state->spriteram_2 + ((state->spriteram_size / 2) / 2) * state->spriteram_bank; + + finish = source + ((state->spriteram_size / 2) / 2); - - UINT16 *source; - UINT16 *finish; - - struct sprite_cave *sprite = sprite_cave; - - int glob_flipx = cave_videoregs[ 0 ] & 0x8000; - int glob_flipy = cave_videoregs[ 1 ] & 0x8000; - - int max_x = video_screen_get_width(machine->primary_screen); - int max_y = video_screen_get_height(machine->primary_screen); - - source = machine->generic.spriteram.u16 + ((machine->generic.spriteram_size/2) / 2) * spriteram_bank; - - if (cave_videoregs[ 4 ] & 0x02) - if (cave_spriteram16_2) source = cave_spriteram16_2 + ((machine->generic.spriteram_size/2) / 2) * spriteram_bank; - - finish = source + ((machine->generic.spriteram_size/2) / 2); - - - for (; source < finish; source+=8 ) + for (; source < finish; source += 8) { - int x,y,attr,code,zoomx,zoomy,size,flipx,flipy; - int total_width_f,total_height_f; + int x, y, attr, code, zoomx, zoomy, size, flipx, flipy; + int total_width_f, total_height_f; - if (cave_spritetype == 2) /* Hot Dog Storm */ + if (state->spritetype[0] == 2) /* Hot Dog Storm */ { - x = (source[ 0 ] & 0x3ff) << 8; - y = (source[ 1 ] & 0x3ff) << 8; + x = (source[0] & 0x3ff) << 8; + y = (source[1] & 0x3ff) << 8; } else /* all others */ { - x = source[ 0 ] << 2; - y = source[ 1 ] << 2; + x = source[0] << 2; + y = source[1] << 2; } - attr = source[ 2 ]; - code = source[ 3 ] + ((attr & 3) << 16); - zoomx = source[ 4 ]; - zoomy = source[ 5 ]; - size = source[ 6 ]; + attr = source[2]; + code = source[3] + ((attr & 3) << 16); + zoomx = source[4]; + zoomy = source[5]; + size = source[6]; - sprite->tile_width = ( (size >> 8) & 0x1f ) * 16; - sprite->tile_height = ( (size >> 0) & 0x1f ) * 16; + sprite->tile_width = ((size >> 8) & 0x1f) * 16; + sprite->tile_height = ((size >> 0) & 0x1f) * 16; - if ( !sprite->tile_width || !sprite->tile_height ) continue; + if (!sprite->tile_width || !sprite->tile_height) + continue; /* Bound checking */ - code %= code_max; - sprite->pen_data = base_gfx + (16*16) * code; + code %= code_max; + sprite->pen_data = base_gfx + (16 * 16) * code; - flipx = attr & 0x0008; - flipy = attr & 0x0004; + flipx = attr & 0x0008; + flipy = attr & 0x0004; - sprite->total_width = (total_width_f = sprite->tile_width * zoomx) / 0x100; - sprite->total_height = (total_height_f = sprite->tile_height * zoomy) / 0x100; + sprite->total_width = (total_width_f = sprite->tile_width * zoomx) / 0x100; + sprite->total_height = (total_height_f = sprite->tile_height * zoomy) / 0x100; if (sprite->total_width <= 1) { - sprite->total_width = 1; + sprite->total_width = 1; sprite->zoomx_re = sprite->tile_width << 16; sprite->xcount0 = sprite->zoomx_re / 2; x -= 0x80; @@ -647,7 +628,7 @@ static void get_sprite_info_cave(running_machine *machine) sprite->ycount0 = sprite->zoomy_re - 1; } - if (cave_spritetype == 2) + if (state->spritetype[0] == 2) { x >>= 8; y >>= 8; @@ -656,183 +637,200 @@ static void get_sprite_info_cave(running_machine *machine) } else { - if (flipx && (zoomx != 0x100)) x += (sprite->tile_width<<8) - total_width_f - 0x80; - if (flipy && (zoomy != 0x100)) y += (sprite->tile_height<<8) - total_height_f - 0x80; + if (flipx && (zoomx != 0x100)) x += (sprite->tile_width << 8) - total_width_f - 0x80; + if (flipy && (zoomy != 0x100)) y += (sprite->tile_height << 8) - total_height_f - 0x80; x >>= 8; y >>= 8; } - if (x > 0x1FF) x -= 0x400; - if (y > 0x1FF) y -= 0x400; + if (x > 0x1ff) x -= 0x400; + if (y > 0x1ff) y -= 0x400; - if (x + sprite->total_width<=0 || x>=max_x || y + sprite->total_height<=0 || y>=max_y ) + if (x + sprite->total_width <= 0 || x >= max_x || y + sprite->total_height <= 0 || y >= max_y ) {continue;} - sprite->priority = (attr & 0x0030) >> 4; - sprite->flags = SPRITE_VISIBLE_CAVE; - sprite->line_offset = sprite->tile_width; - sprite->base_pen = base_pal + (attr & 0x3f00); // first 0x4000 colors + sprite->priority = (attr & 0x0030) >> 4; + sprite->flags = SPRITE_VISIBLE_CAVE; + sprite->line_offset = sprite->tile_width; + sprite->base_pen = base_pal + (attr & 0x3f00); // first 0x4000 colors if (glob_flipx) { x = max_x - x - sprite->total_width; flipx = !flipx; } if (glob_flipy) { y = max_y - y - sprite->total_height; flipy = !flipy; } - sprite->x = x; - sprite->y = y; + sprite->x = x; + sprite->y = y; if (flipx) sprite->flags |= SPRITE_FLIPX_CAVE; if (flipy) sprite->flags |= SPRITE_FLIPY_CAVE; sprite++; } - num_sprites = sprite - sprite_cave; + state->num_sprites = sprite - state->sprite; } -static void get_sprite_info_donpachi(running_machine *machine) +static void get_sprite_info_donpachi( running_machine *machine ) { - pen_t base_pal = 0; - const UINT8 *base_gfx = memory_region(machine, "gfx1"); - int code_max = memory_region_length(machine, "gfx1") / (16*16); + cave_state *state = (cave_state *)machine->driver_data; + pen_t base_pal = 0; + const UINT8 *base_gfx = memory_region(machine, "gfx1"); + int code_max = memory_region_length(machine, "gfx1") / (16*16); - UINT16 *source; - UINT16 *finish; + UINT16 *source; + UINT16 *finish; - struct sprite_cave *sprite = sprite_cave; + struct sprite_cave *sprite = state->sprite; - int glob_flipx = cave_videoregs[ 0 ] & 0x8000; - int glob_flipy = cave_videoregs[ 1 ] & 0x8000; + int glob_flipx = state->videoregs[0] & 0x8000; + int glob_flipy = state->videoregs[1] & 0x8000; - int max_x = video_screen_get_width(machine->primary_screen); - int max_y = video_screen_get_height(machine->primary_screen); + int max_x = video_screen_get_width(machine->primary_screen); + int max_y = video_screen_get_height(machine->primary_screen); - source = machine->generic.spriteram.u16 + ((machine->generic.spriteram_size/2) / 2) * spriteram_bank; + source = state->spriteram + ((state->spriteram_size / 2) / 2) * state->spriteram_bank; - if (cave_videoregs[ 4 ] & 0x02) - if (cave_spriteram16_2) source = cave_spriteram16_2 + ((machine->generic.spriteram_size/2) / 2) * spriteram_bank; + if (state->videoregs[4] & 0x02) + if (state->spriteram_2) + source = state->spriteram_2 + ((state->spriteram_size / 2) / 2) * state->spriteram_bank; - finish = source + ((machine->generic.spriteram_size/2) / 2); + finish = source + ((state->spriteram_size / 2) / 2); - for (; source < finish; source+=8 ) + for (; source < finish; source += 8) { - int x,y,attr,code,size,flipx,flipy; + int x, y, attr, code, size, flipx, flipy; - attr = source[ 0 ]; - code = source[ 1 ] + ((attr & 3) << 16); - x = source[ 2 ] & 0x3FF; + attr = source[0]; + code = source[1] + ((attr & 3) << 16); + x = source[2] & 0x3ff; - if (cave_spritetype == 3) /* pwrinst2 */ - y = (source[ 3 ]+1) & 0x3FF; + if (state->spritetype[0] == 3) /* pwrinst2 */ + y = (source[3] + 1) & 0x3ff; else - y = source[ 3 ] & 0x3FF; + y = source[3] & 0x3ff; - size = source[ 4 ]; + size = source[4]; - sprite->tile_width = sprite->total_width = ( (size >> 8) & 0x1f ) * 16; - sprite->tile_height = sprite->total_height = ( (size >> 0) & 0x1f ) * 16; + sprite->tile_width = sprite->total_width = ((size >> 8) & 0x1f) * 16; + sprite->tile_height = sprite->total_height = ((size >> 0) & 0x1f) * 16; /* Bound checking */ - code %= code_max; - sprite->pen_data = base_gfx + (16*16) * code; + code %= code_max; + sprite->pen_data = base_gfx + (16*16) * code; - if (x > 0x1FF) x -= 0x400; - if (y > 0x1FF) y -= 0x400; + if (x > 0x1ff) x -= 0x400; + if (y > 0x1ff) y -= 0x400; - if ( !sprite->tile_width || !sprite->tile_height || - x + sprite->total_width<=0 || x>=max_x || y + sprite->total_height<=0 || y>=max_y ) + if (!sprite->tile_width || !sprite->tile_height || + x + sprite->total_width <= 0 || x >= max_x || y + sprite->total_height <= 0 || y >= max_y ) {continue;} - flipx = attr & 0x0008; - flipy = attr & 0x0004; + flipx = attr & 0x0008; + flipy = attr & 0x0004; - if (cave_spritetype == 3) /* pwrinst2 */ + if (state->spritetype[0] == 3) /* pwrinst2 */ { - sprite->priority = ((attr & 0x0010) >> 4)+2; - sprite->base_pen = base_pal + (attr & 0x3f00) + 0x4000*((attr & 0x0020) >> 5); + sprite->priority = ((attr & 0x0010) >> 4) + 2; + sprite->base_pen = base_pal + (attr & 0x3f00) + 0x4000 * ((attr & 0x0020) >> 5); } else { - sprite->priority = (attr & 0x0030) >> 4; - sprite->base_pen = base_pal + (attr & 0x3f00); // first 0x4000 colors + sprite->priority = (attr & 0x0030) >> 4; + sprite->base_pen = base_pal + (attr & 0x3f00); // first 0x4000 colors } - sprite->flags = SPRITE_VISIBLE_CAVE; - sprite->line_offset = sprite->tile_width; + sprite->flags = SPRITE_VISIBLE_CAVE; + sprite->line_offset = sprite->tile_width; if (glob_flipx) { x = max_x - x - sprite->total_width; flipx = !flipx; } if (glob_flipy) { y = max_y - y - sprite->total_height; flipy = !flipy; } - sprite->x = x; - sprite->y = y; + sprite->x = x; + sprite->y = y; if (flipx) sprite->flags |= SPRITE_FLIPX_CAVE; if (flipy) sprite->flags |= SPRITE_FLIPY_CAVE; sprite++; } - num_sprites = sprite - sprite_cave; + state->num_sprites = sprite - state->sprite; } -static void sprite_init_cave(running_machine *machine) +static void sprite_init_cave( running_machine *machine ) { - screen_width = video_screen_get_width(machine->primary_screen); - screen_height = video_screen_get_height(machine->primary_screen); + cave_state *state = (cave_state *)machine->driver_data; + int screen_width = video_screen_get_width(machine->primary_screen); + int screen_height = video_screen_get_height(machine->primary_screen); - if (cave_spritetype == 0 || cave_spritetype == 2) // most of the games + if (state->spritetype[0] == 0 || state->spritetype[0] == 2) // most of the games { - get_sprite_info = get_sprite_info_cave; - cave_spritetype2 = CAVE_SPRITETYPE_ZOOM; + state->get_sprite_info = get_sprite_info_cave; + state->spritetype[1] = CAVE_SPRITETYPE_ZOOM; } else // donpachi ddonpach { - get_sprite_info = get_sprite_info_donpachi; - cave_spritetype2 = 0; + state->get_sprite_info = get_sprite_info_donpachi; + state->spritetype[1] = 0; } - sprite_zbuf_baseval = 0x10000-MAX_SPRITE_NUM; - sprite_zbuf = auto_bitmap_alloc(machine, screen_width, screen_height, BITMAP_FORMAT_INDEXED16 ); - blit.baseaddr_zbuf = (UINT8 *)sprite_zbuf->base; - blit.line_offset_zbuf = sprite_zbuf->rowpixels * sprite_zbuf->bpp / 8; + state->sprite_zbuf_baseval = 0x10000 - MAX_SPRITE_NUM; + state->sprite_zbuf = auto_bitmap_alloc(machine, screen_width, screen_height, BITMAP_FORMAT_INDEXED16); + state->blit.baseaddr_zbuf = (UINT8 *)state->sprite_zbuf->base; + state->blit.line_offset_zbuf = state->sprite_zbuf->rowpixels * state->sprite_zbuf->bpp / 8; - num_sprites = machine->generic.spriteram_size / 0x10 / 2; - sprite_cave = auto_alloc_array_clear(machine, struct sprite_cave, num_sprites); + state->num_sprites = state->spriteram_size / 0x10 / 2; + state->sprite = auto_alloc_array_clear(machine, struct sprite_cave, state->num_sprites); - memset(sprite_table,0,sizeof(sprite_table)); - cave_sprite_draw = sprite_draw_donpachi; + memset(state->sprite_table, 0, sizeof(state->sprite_table)); + state->sprite_draw = sprite_draw_donpachi; + + state_save_register_global_bitmap(machine, state->sprite_zbuf); + state_save_register_global(machine, state->sprite_zbuf_baseval); + state_save_register_global(machine, state->num_sprites); + state_save_register_global(machine, state->spriteram_bank); + state_save_register_global(machine, state->spriteram_bank_delay); + + state_save_register_global(machine, state->blit.clip_left); + state_save_register_global(machine, state->blit.clip_right); + state_save_register_global(machine, state->blit.clip_top); + state_save_register_global(machine, state->blit.clip_bottom); + + state_save_register_postload(machine, cave_sprite_postload, NULL); } - -static void cave_sprite_check(const device_config *screen, const rectangle *clip ) +static void cave_sprite_check( const device_config *screen, const rectangle *clip ) { + cave_state *state = (cave_state *)screen->machine->driver_data; + { /* set clip */ int left = clip->min_x; int top = clip->min_y; - int right = clip->max_x+1; - int bottom = clip->max_y+1; + int right = clip->max_x + 1; + int bottom = clip->max_y + 1; - blit.clip_left = left; - blit.clip_top = top; - blit.clip_right = right; - blit.clip_bottom = bottom; + state->blit.clip_left = left; + state->blit.clip_top = top; + state->blit.clip_right = right; + state->blit.clip_bottom = bottom; } { /* check priority & sprite type */ - struct sprite_cave *sprite = sprite_cave; - const struct sprite_cave *finish = &sprite[num_sprites]; - int i[4]={0,0,0,0}; + struct sprite_cave *sprite = state->sprite; + const struct sprite_cave *finish = &sprite[state->num_sprites]; + int i[4] = {0,0,0,0}; int priority_check = 0; - int spritetype = cave_spritetype2; + int spritetype = state->spritetype[1]; const rectangle *visarea = video_screen_get_visible_area(screen); - while( spritex + sprite->total_width > blit.clip_left && sprite->x < blit.clip_right && - sprite->y + sprite->total_height > blit.clip_top && sprite->y < blit.clip_bottom ) + if (sprite->x + sprite->total_width > state->blit.clip_left && sprite->x < state->blit.clip_right && + sprite->y + sprite->total_height > state->blit.clip_top && sprite->y < state->blit.clip_bottom ) { - sprite_table[sprite->priority][i[sprite->priority]++] = sprite; + state->sprite_table[sprite->priority][i[sprite->priority]++] = sprite; - if(!(spritetype&CAVE_SPRITETYPE_ZBUF)) + if(!(spritetype & CAVE_SPRITETYPE_ZBUF)) { - if(priority_check > sprite->priority) + if (priority_check > sprite->priority) spritetype |= CAVE_SPRITETYPE_ZBUF; else priority_check = sprite->priority; @@ -841,123 +839,164 @@ static void cave_sprite_check(const device_config *screen, const rectangle *clip sprite++; } - sprite_table[0][i[0]] = 0; - sprite_table[1][i[1]] = 0; - sprite_table[2][i[2]] = 0; - sprite_table[3][i[3]] = 0; + state->sprite_table[0][i[0]] = 0; + state->sprite_table[1][i[1]] = 0; + state->sprite_table[2][i[2]] = 0; + state->sprite_table[3][i[3]] = 0; switch (spritetype) { case CAVE_SPRITETYPE_ZOOM: - cave_sprite_draw = sprite_draw_cave; + state->sprite_draw = sprite_draw_cave; break; case CAVE_SPRITETYPE_ZOOM | CAVE_SPRITETYPE_ZBUF: - cave_sprite_draw = sprite_draw_cave_zbuf; + state->sprite_draw = sprite_draw_cave_zbuf; if (clip->min_y == visarea->min_y) { - if(!(sprite_zbuf_baseval += MAX_SPRITE_NUM)) - bitmap_fill(sprite_zbuf,visarea,0); + if(!(state->sprite_zbuf_baseval += MAX_SPRITE_NUM)) + bitmap_fill(state->sprite_zbuf, visarea, 0); } break; case CAVE_SPRITETYPE_ZBUF: - cave_sprite_draw = sprite_draw_donpachi_zbuf; + state->sprite_draw = sprite_draw_donpachi_zbuf; if (clip->min_y == visarea->min_y) { - if(!(sprite_zbuf_baseval += MAX_SPRITE_NUM)) - bitmap_fill(sprite_zbuf,visarea,0); + if(!(state->sprite_zbuf_baseval += MAX_SPRITE_NUM)) + bitmap_fill(state->sprite_zbuf,visarea,0); } break; default: case 0: - cave_sprite_draw = sprite_draw_donpachi; + state->sprite_draw = sprite_draw_donpachi; } } } -static void do_blit_zoom16_cave( const struct sprite_cave *sprite ){ +static void do_blit_zoom16_cave( running_machine *machine, const struct sprite_cave *sprite ) +{ /* assumes SPRITE_LIST_RAW_DATA flag is set */ - - int x1,x2, y1,y2, dx,dy; + cave_state *state = (cave_state *)machine->driver_data; + int x1, x2, y1, y2, dx, dy; int xcount0 = 0x10000 + sprite->xcount0, ycount0 = 0x10000 + sprite->ycount0; - if( sprite->flags & SPRITE_FLIPX_CAVE ){ + if (sprite->flags & SPRITE_FLIPX_CAVE) + { x2 = sprite->x; - x1 = x2+sprite->total_width; + x1 = x2 + sprite->total_width; dx = -1; - if( x2blit.clip_right ){ - xcount0 += (x1-blit.clip_right)* sprite->zoomx_re; - x1 = blit.clip_right; - while((xcount0&0xffff)>=sprite->zoomx_re){xcount0 += sprite->zoomx_re; x1--;} + if (x2 < state->blit.clip_left) + x2 = state->blit.clip_left; + + if (x1 > state->blit.clip_right) + { + xcount0 += (x1 - state->blit.clip_right) * sprite->zoomx_re; + x1 = state->blit.clip_right; + while ((xcount0 & 0xffff) >= sprite->zoomx_re) + { + xcount0 += sprite->zoomx_re; + x1--; + } } - if( x2>=x1 ) return; + + if (x2 >= x1) + return; x1--; x2--; } - else { + else + { x1 = sprite->x; - x2 = x1+sprite->total_width; + x2 = x1 + sprite->total_width; dx = 1; - if( x1zoomx_re; - x1 = blit.clip_left; - while((xcount0&0xffff)>=sprite->zoomx_re){xcount0 += sprite->zoomx_re; x1++;} + if (x1 < state->blit.clip_left) + { + xcount0 += (state->blit.clip_left - x1) * sprite->zoomx_re; + x1 = state->blit.clip_left; + while ((xcount0 & 0xffff) >= sprite->zoomx_re) + { + xcount0 += sprite->zoomx_re; + x1++; + } } - if( x2>blit.clip_right ) x2 = blit.clip_right; - if( x1>=x2 ) return; + if (x2 > state->blit.clip_right) + x2 = state->blit.clip_right; + if (x1 >= x2) + return; } - if( sprite->flags & SPRITE_FLIPY_CAVE ){ + + if (sprite->flags & SPRITE_FLIPY_CAVE ) + { y2 = sprite->y; - y1 = y2+sprite->total_height; + y1 = y2 + sprite->total_height; dy = -1; - if( y2blit.clip_bottom ){ - ycount0 += (y1-blit.clip_bottom)*sprite->zoomy_re; - y1 = blit.clip_bottom; - while((ycount0&0xffff)>=sprite->zoomy_re){ycount0 += sprite->zoomy_re; y1--;} + if (y2 < state->blit.clip_top) + y2 = state->blit.clip_top; + if (y1 > state->blit.clip_bottom) + { + ycount0 += (y1 - state->blit.clip_bottom) * sprite->zoomy_re; + y1 = state->blit.clip_bottom; + while ((ycount0 & 0xffff) >= sprite->zoomy_re) + { + ycount0 += sprite->zoomy_re; + y1--; + } } - if( y2>=y1 ) return; + if (y2 >= y1) + return; y1--; y2--; } - else { + else + { y1 = sprite->y; - y2 = y1+sprite->total_height; + y2 = y1 + sprite->total_height; dy = 1; - if( y1zoomy_re; - y1 = blit.clip_top; - while((ycount0&0xffff)>=sprite->zoomy_re){ycount0 += sprite->zoomy_re; y1++;} + if (y1 < state->blit.clip_top) + { + ycount0 += (state->blit.clip_top - y1) * sprite->zoomy_re; + y1 = state->blit.clip_top; + while ((ycount0 & 0xffff) >= sprite->zoomy_re) + { + ycount0 += sprite->zoomy_re; + y1++; + } } - if( y2>blit.clip_bottom ) y2 = blit.clip_bottom; - if( y1>=y2 ) return; + if (y2 > state->blit.clip_bottom ) + y2 = state->blit.clip_bottom; + if (y1 >= y2) + return; } { const UINT8 *pen_data = sprite->pen_data -1 -sprite->line_offset; - pen_t base_pen = sprite->base_pen; - int x,y; + pen_t base_pen = sprite->base_pen; + int x, y; UINT8 pen; - int pitch = blit.line_offset*dy/2; - UINT16 *dest = (UINT16 *)(blit.baseaddr + blit.line_offset*y1); + int pitch = state->blit.line_offset * dy / 2; + UINT16 *dest = (UINT16 *)(state->blit.baseaddr + state->blit.line_offset * y1); int ycount = ycount0; - for( y=y1; y!=y2; y+=dy ){ + for (y = y1; y != y2; y += dy) + { int xcount; const UINT8 *source; - if (ycount&0xffff0000){ + if (ycount & 0xffff0000) + { xcount = xcount0; - pen_data+=sprite->line_offset*(ycount>>16); + pen_data += sprite->line_offset * (ycount >> 16); ycount &= 0xffff; source = pen_data; - for( x=x1; x!=x2; x+=dx ){ - if (xcount&0xffff0000){ - source+=xcount>>16; + for (x = x1; x != x2; x += dx) + { + if (xcount & 0xffff0000) + { + source += xcount >> 16; xcount &= 0xffff; pen = *source; - if (pen) dest[x] = base_pen + pen; + if (pen) + dest[x] = base_pen + pen; } xcount += sprite->zoomx_re; } @@ -969,90 +1008,128 @@ static void do_blit_zoom16_cave( const struct sprite_cave *sprite ){ } -static void do_blit_zoom16_cave_zb( const struct sprite_cave *sprite ){ +static void do_blit_zoom16_cave_zb( running_machine *machine, const struct sprite_cave *sprite ) +{ /* assumes SPRITE_LIST_RAW_DATA flag is set */ - - int x1,x2, y1,y2, dx,dy; + cave_state *state = (cave_state *)machine->driver_data; + int x1, x2, y1, y2, dx, dy; int xcount0 = 0x10000 + sprite->xcount0, ycount0 = 0x10000 + sprite->ycount0; - if( sprite->flags & SPRITE_FLIPX_CAVE ){ + if (sprite->flags & SPRITE_FLIPX_CAVE) + { x2 = sprite->x; - x1 = x2+sprite->total_width; + x1 = x2 + sprite->total_width; dx = -1; - if( x2blit.clip_right ){ - xcount0 += (x1-blit.clip_right)* sprite->zoomx_re; - x1 = blit.clip_right; - while((xcount0&0xffff)>=sprite->zoomx_re){xcount0 += sprite->zoomx_re; x1--;} + if (x2 < state->blit.clip_left) + x2 = state->blit.clip_left; + if (x1 > state->blit.clip_right) + { + xcount0 += (x1 - state->blit.clip_right) * sprite->zoomx_re; + x1 = state->blit.clip_right; + while ((xcount0 & 0xffff) >= sprite->zoomx_re) + { + xcount0 += sprite->zoomx_re; + x1--; + } } - if( x2>=x1 ) return; + if (x2 >= x1) + return; x1--; x2--; } - else { + else + { x1 = sprite->x; - x2 = x1+sprite->total_width; + x2 = x1 + sprite->total_width; dx = 1; - if( x1zoomx_re; - x1 = blit.clip_left; - while((xcount0&0xffff)>=sprite->zoomx_re){xcount0 += sprite->zoomx_re; x1++;} + if (x1 < state->blit.clip_left) + { + xcount0 += (state->blit.clip_left - x1) * sprite->zoomx_re; + x1 = state->blit.clip_left; + while ((xcount0 & 0xffff) >= sprite->zoomx_re) + { + xcount0 += sprite->zoomx_re; + x1++; + } } - if( x2>blit.clip_right ) x2 = blit.clip_right; - if( x1>=x2 ) return; + if (x2 > state->blit.clip_right) + x2 = state->blit.clip_right; + if (x1 >= x2) + return; } - if( sprite->flags & SPRITE_FLIPY_CAVE ){ + if (sprite->flags & SPRITE_FLIPY_CAVE) + { y2 = sprite->y; - y1 = y2+sprite->total_height; + y1 = y2 + sprite->total_height; dy = -1; - if( y2blit.clip_bottom ){ - ycount0 += (y1-blit.clip_bottom)*sprite->zoomy_re; - y1 = blit.clip_bottom; - while((ycount0&0xffff)>=sprite->zoomy_re){ycount0 += sprite->zoomy_re; y1--;} + if (y2 < state->blit.clip_top) + y2 = state->blit.clip_top; + if (y1 > state->blit.clip_bottom) + { + ycount0 += (y1 - state->blit.clip_bottom) * sprite->zoomy_re; + y1 = state->blit.clip_bottom; + while ((ycount0 & 0xffff) >= sprite->zoomy_re) + { + ycount0 += sprite->zoomy_re; + y1--; + } } - if( y2>=y1 ) return; + if (y2 >= y1) + return; y1--; y2--; } - else { + else + { y1 = sprite->y; - y2 = y1+sprite->total_height; + y2 = y1 + sprite->total_height; dy = 1; - if( y1zoomy_re; - y1 = blit.clip_top; - while((ycount0&0xffff)>=sprite->zoomy_re){ycount0 += sprite->zoomy_re; y1++;} + if (y1 < state->blit.clip_top) + { + ycount0 += (state->blit.clip_top - y1) * sprite->zoomy_re; + y1 = state->blit.clip_top; + while ((ycount0 & 0xffff) >= sprite->zoomy_re) + { + ycount0 += sprite->zoomy_re; + y1++; + } } - if( y2>blit.clip_bottom ) y2 = blit.clip_bottom; - if( y1>=y2 ) return; + if (y2 > state->blit.clip_bottom) + y2 = state->blit.clip_bottom; + if (y1 >= y2) + return; } { - const UINT8 *pen_data = sprite->pen_data -1 -sprite->line_offset; - pen_t base_pen = sprite->base_pen; - int x,y; + const UINT8 *pen_data = sprite->pen_data - 1 - sprite->line_offset; + pen_t base_pen = sprite->base_pen; + int x, y; UINT8 pen; - int pitch = blit.line_offset*dy/2; - UINT16 *dest = (UINT16 *)(blit.baseaddr + blit.line_offset*y1); - int pitchz = blit.line_offset_zbuf*dy/2; - UINT16 *zbf = (UINT16 *)(blit.baseaddr_zbuf + blit.line_offset_zbuf*y1); - UINT16 pri_sp = (UINT16)(sprite - sprite_cave) + sprite_zbuf_baseval; + int pitch = state->blit.line_offset * dy / 2; + UINT16 *dest = (UINT16 *)(state->blit.baseaddr + state->blit.line_offset * y1); + int pitchz = state->blit.line_offset_zbuf * dy / 2; + UINT16 *zbf = (UINT16 *)(state->blit.baseaddr_zbuf + state->blit.line_offset_zbuf * y1); + UINT16 pri_sp = (UINT16)(sprite - state->sprite) + state->sprite_zbuf_baseval; int ycount = ycount0; - for( y=y1; y!=y2; y+=dy ){ + for (y = y1; y != y2; y += dy) + { int xcount; const UINT8 *source; - if (ycount&0xffff0000){ + if (ycount & 0xffff0000) + { xcount = xcount0; - pen_data+=sprite->line_offset*(ycount>>16); + pen_data += sprite->line_offset * (ycount >> 16); ycount &= 0xffff; source = pen_data; - for( x=x1; x!=x2; x+=dx ){ - if (xcount&0xffff0000){ - source+=xcount>>16; + for (x = x1; x != x2; x += dx) + { + if (xcount & 0xffff0000) + { + source += xcount >> 16; xcount &= 0xffff; pen = *source; - if (pen && (zbf[x]<=pri_sp)){ + if (pen && (zbf[x] <= pri_sp)) + { dest[x] = base_pen + pen; zbf[x] = pri_sp; } @@ -1067,74 +1144,93 @@ static void do_blit_zoom16_cave_zb( const struct sprite_cave *sprite ){ } } -static void do_blit_16_cave( const struct sprite_cave *sprite ){ +static void do_blit_16_cave( running_machine *machine, const struct sprite_cave *sprite ) +{ /* assumes SPRITE_LIST_RAW_DATA flag is set */ - - int x1,x2, y1,y2, dx,dy; + cave_state *state = (cave_state *)machine->driver_data; + int x1, x2, y1, y2, dx, dy; int xcount0 = 0, ycount0 = 0; - if( sprite->flags & SPRITE_FLIPX_CAVE ){ + if (sprite->flags & SPRITE_FLIPX_CAVE) + { x2 = sprite->x; - x1 = x2+sprite->total_width; + x1 = x2 + sprite->total_width; dx = -1; - if( x2blit.clip_right ){ - xcount0 = x1-blit.clip_right; - x1 = blit.clip_right; + if (x2 < state->blit.clip_left) + x2 = state->blit.clip_left; + if (x1 > state->blit.clip_right) + { + xcount0 = x1 - state->blit.clip_right; + x1 = state->blit.clip_right; } - if( x2>=x1 ) return; + if (x2 >= x1) + return; x1--; x2--; } - else { + else + { x1 = sprite->x; - x2 = x1+sprite->total_width; + x2 = x1 + sprite->total_width; dx = 1; - if( x1blit.clip_left) + { + xcount0 = state->blit.clip_left - x1; + x1 = state->blit.clip_left; } - if( x2>blit.clip_right ) x2 = blit.clip_right; - if( x1>=x2 ) return; + if (x2 > state->blit.clip_right) + x2 = state->blit.clip_right; + if (x1 >= x2) + return; } - if( sprite->flags & SPRITE_FLIPY_CAVE ){ + if (sprite->flags & SPRITE_FLIPY_CAVE) + { y2 = sprite->y; - y1 = y2+sprite->total_height; + y1 = y2 + sprite->total_height; dy = -1; - if( y2blit.clip_bottom ){ - ycount0 = y1-blit.clip_bottom; - y1 = blit.clip_bottom; + if (y2 < state->blit.clip_top) + y2 = state->blit.clip_top; + if (y1 > state->blit.clip_bottom) + { + ycount0 = y1 - state->blit.clip_bottom; + y1 = state->blit.clip_bottom; } - if( y2>=y1 ) return; + if (y2 >= y1) + return; y1--; y2--; } else { y1 = sprite->y; - y2 = y1+sprite->total_height; + y2 = y1 + sprite->total_height; dy = 1; - if( y1blit.clip_top ) + { + ycount0 = state->blit.clip_top - y1; + y1 = state->blit.clip_top; } - if( y2>blit.clip_bottom ) y2 = blit.clip_bottom; - if( y1>=y2 ) return; + if (y2 > state->blit.clip_bottom) + y2 = state->blit.clip_bottom; + if (y1 >= y2) + return; } { const UINT8 *pen_data = sprite->pen_data; - pen_t base_pen = sprite->base_pen; - int x,y; + pen_t base_pen = sprite->base_pen; + int x, y; UINT8 pen; - int pitch = blit.line_offset*dy/2; - UINT16 *dest = (UINT16 *)(blit.baseaddr + blit.line_offset*y1); + int pitch = state->blit.line_offset * dy / 2; + UINT16 *dest = (UINT16 *)(state->blit.baseaddr + state->blit.line_offset * y1); - pen_data+=sprite->line_offset*ycount0+xcount0; - for( y=y1; y!=y2; y+=dy ){ + pen_data += sprite->line_offset * ycount0 + xcount0; + for (y = y1; y != y2; y += dy) + { const UINT8 *source; source = pen_data; - for( x=x1; x!=x2; x+=dx ){ + for (x = x1; x != x2; x += dx) + { pen = *source; - if (pen) dest[x] = base_pen + pen; + if (pen) + dest[x] = base_pen + pen; source++; } pen_data += sprite->line_offset; @@ -1144,77 +1240,96 @@ static void do_blit_16_cave( const struct sprite_cave *sprite ){ } -static void do_blit_16_cave_zb( const struct sprite_cave *sprite ){ +static void do_blit_16_cave_zb( running_machine *machine, const struct sprite_cave *sprite ) +{ /* assumes SPRITE_LIST_RAW_DATA flag is set */ - - int x1,x2, y1,y2, dx,dy; + cave_state *state = (cave_state *)machine->driver_data; + int x1, x2, y1, y2, dx, dy; int xcount0 = 0, ycount0 = 0; - if( sprite->flags & SPRITE_FLIPX_CAVE ){ + if (sprite->flags & SPRITE_FLIPX_CAVE) + { x2 = sprite->x; - x1 = x2+sprite->total_width; + x1 = x2 + sprite->total_width; dx = -1; - if( x2blit.clip_right ){ - xcount0 = x1-blit.clip_right; - x1 = blit.clip_right; + if (x2 < state->blit.clip_left) + x2 = state->blit.clip_left; + if (x1 > state->blit.clip_right) + { + xcount0 = x1 - state->blit.clip_right; + x1 = state->blit.clip_right; } - if( x2>=x1 ) return; + if (x2 >= x1) + return; x1--; x2--; } - else { + else + { x1 = sprite->x; - x2 = x1+sprite->total_width; + x2 = x1 + sprite->total_width; dx = 1; - if( x1blit.clip_left) + { + xcount0 = state->blit.clip_left - x1; + x1 = state->blit.clip_left; } - if( x2>blit.clip_right ) x2 = blit.clip_right; - if( x1>=x2 ) return; + if (x2 > state->blit.clip_right) + x2 = state->blit.clip_right; + if (x1 >= x2) + return; } - if( sprite->flags & SPRITE_FLIPY_CAVE ){ + if (sprite->flags & SPRITE_FLIPY_CAVE) + { y2 = sprite->y; - y1 = y2+sprite->total_height; + y1 = y2 + sprite->total_height; dy = -1; - if( y2blit.clip_bottom ){ - ycount0 = y1-blit.clip_bottom; - y1 = blit.clip_bottom; + if (y2 < state->blit.clip_top) + y2 = state->blit.clip_top; + if (y1 > state->blit.clip_bottom) + { + ycount0 = y1 - state->blit.clip_bottom; + y1 = state->blit.clip_bottom; } - if( y2>=y1 ) return; + if (y2 >= y1) + return; y1--; y2--; } - else { + else + { y1 = sprite->y; - y2 = y1+sprite->total_height; + y2 = y1 + sprite->total_height; dy = 1; - if( y1blit.clip_top) + { + ycount0 = state->blit.clip_top - y1; + y1 = state->blit.clip_top; } - if( y2>blit.clip_bottom ) y2 = blit.clip_bottom; - if( y1>=y2 ) return; + if (y2 > state->blit.clip_bottom) + y2 = state->blit.clip_bottom; + if (y1 >= y2) + return; } { const UINT8 *pen_data = sprite->pen_data; - pen_t base_pen = sprite->base_pen; - int x,y; + pen_t base_pen = sprite->base_pen; + int x, y; UINT8 pen; - int pitch = blit.line_offset*dy/2; - UINT16 *dest = (UINT16 *)(blit.baseaddr + blit.line_offset*y1); - int pitchz = blit.line_offset_zbuf*dy/2; - UINT16 *zbf = (UINT16 *)(blit.baseaddr_zbuf + blit.line_offset_zbuf*y1); - UINT16 pri_sp = (UINT16)(sprite - sprite_cave) + sprite_zbuf_baseval; + int pitch = state->blit.line_offset * dy / 2; + UINT16 *dest = (UINT16 *)(state->blit.baseaddr + state->blit.line_offset * y1); + int pitchz = state->blit.line_offset_zbuf * dy / 2; + UINT16 *zbf = (UINT16 *)(state->blit.baseaddr_zbuf + state->blit.line_offset_zbuf * y1); + UINT16 pri_sp = (UINT16)(sprite - state->sprite) + state->sprite_zbuf_baseval; - pen_data+=sprite->line_offset*ycount0+xcount0; - for( y=y1; y!=y2; y+=dy ){ + pen_data += sprite->line_offset * ycount0 + xcount0; + for (y = y1; y != y2; y += dy) + { const UINT8 *source; source = pen_data; - for( x=x1; x!=x2; x+=dx ){ + for (x = x1; x != x2; x += dx) + { pen = *source; - if ( pen && (zbf[x]<=pri_sp)) + if (pen && (zbf[x] <= pri_sp)) { dest[x] = base_pen + pen; zbf[x] = pri_sp; @@ -1229,44 +1344,48 @@ static void do_blit_16_cave_zb( const struct sprite_cave *sprite ){ } -static void sprite_draw_cave( int priority ) +static void sprite_draw_cave( running_machine *machine, int priority ) { - int i=0; - while(sprite_table[priority][i]) + cave_state *state = (cave_state *)machine->driver_data; + int i = 0; + while (state->sprite_table[priority][i]) { - const struct sprite_cave *sprite = sprite_table[priority][i++]; + const struct sprite_cave *sprite = state->sprite_table[priority][i++]; if ((sprite->tile_width == sprite->total_width) && (sprite->tile_height == sprite->total_height)) - do_blit_16_cave( sprite ); + do_blit_16_cave(machine, sprite); else - do_blit_zoom16_cave( sprite ); + do_blit_zoom16_cave(machine, sprite); } } -static void sprite_draw_cave_zbuf( int priority ) +static void sprite_draw_cave_zbuf( running_machine *machine, int priority ) { - int i=0; - while(sprite_table[priority][i]) + cave_state *state = (cave_state *)machine->driver_data; + int i = 0; + while (state->sprite_table[priority][i]) { - const struct sprite_cave *sprite = sprite_table[priority][i++]; + const struct sprite_cave *sprite = state->sprite_table[priority][i++]; if ((sprite->tile_width == sprite->total_width) && (sprite->tile_height == sprite->total_height)) - do_blit_16_cave_zb( sprite ); + do_blit_16_cave_zb(machine, sprite); else - do_blit_zoom16_cave_zb( sprite ); + do_blit_zoom16_cave_zb(machine, sprite); } } -static void sprite_draw_donpachi( int priority ) +static void sprite_draw_donpachi( running_machine *machine, int priority ) { - int i=0; - while(sprite_table[priority][i]) - do_blit_16_cave( sprite_table[priority][i++] ); + cave_state *state = (cave_state *)machine->driver_data; + int i = 0; + while (state->sprite_table[priority][i]) + do_blit_16_cave(machine, state->sprite_table[priority][i++]); } -static void sprite_draw_donpachi_zbuf( int priority ) +static void sprite_draw_donpachi_zbuf( running_machine *machine, int priority ) { - int i=0; - while(sprite_table[priority][i]) - do_blit_16_cave_zb( sprite_table[priority][i++] ); + cave_state *state = (cave_state *)machine->driver_data; + int i = 0; + while (state->sprite_table[priority][i]) + do_blit_16_cave_zb(machine, state->sprite_table[priority][i++]); } @@ -1327,10 +1446,11 @@ static void sprite_draw_donpachi_zbuf( int priority ) ***************************************************************************/ INLINE void cave_tilemap_draw( - bitmap_t *bitmap, const rectangle *cliprect, + running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, tilemap_t *TILEMAP, UINT16 *VRAM, UINT16 *VCTRL, UINT32 flags, UINT32 priority, UINT32 priority2 ) { + cave_state *state = (cave_state *)machine->driver_data; int sx, sy, flipx, flipy, offs_x, offs_y, offs_row; /* Bail out if ... */ @@ -1344,21 +1464,21 @@ INLINE void cave_tilemap_draw( flipy = ~VCTRL[1] & 0x8000; tilemap_set_flip(TILEMAP, (flipx ? TILEMAP_FLIPX : 0) | (flipy ? TILEMAP_FLIPY : 0) ); - offs_x = cave_layers_offs_x; - offs_y = cave_layers_offs_y; + offs_x = state->layers_offs_x; + offs_y = state->layers_offs_y; - offs_row = flipy ? cave_row_effect_offs_f : cave_row_effect_offs_n; + offs_row = flipy ? state->row_effect_offs_f : state->row_effect_offs_n; /* An additional 8 pixel offset for layers with 8x8 tiles. Plus Layer 0 is displaced by 1 pixel wrt Layer 1, so is Layer 2 wrt Layer 1 */ - if (TILEMAP == tilemap_0) offs_x -= (tiledim_0 ? 1 : (1+8)); - else if (TILEMAP == tilemap_1) offs_x -= (tiledim_1 ? 2 : (2+8)); - else if (TILEMAP == tilemap_2) offs_x -= (tiledim_2 ? 3 : (3+8)); - else if (TILEMAP == tilemap_3) offs_x -= (tiledim_3 ? 4 : (4+8)); + if (TILEMAP == state->tilemap_0) offs_x -= (state->tiledim_0 ? 1 : (1 + 8)); + else if (TILEMAP == state->tilemap_1) offs_x -= (state->tiledim_1 ? 2 : (2 + 8)); + else if (TILEMAP == state->tilemap_2) offs_x -= (state->tiledim_2 ? 3 : (3 + 8)); + else if (TILEMAP == state->tilemap_3) offs_x -= (state->tiledim_3 ? 4 : (4 + 8)); - sx = VCTRL[0] - cave_videoregs[0] + (flipx ? (offs_x +2) : -offs_x); - sy = VCTRL[1] - cave_videoregs[1] + (flipy ? (offs_y +2) : -offs_y); + sx = VCTRL[0] - state->videoregs[0] + (flipx ? (offs_x + 2) : -offs_x); + sy = VCTRL[1] - state->videoregs[1] + (flipy ? (offs_y + 2) : -offs_y); if (VCTRL[1] & 0x4000) // row-select { @@ -1376,12 +1496,12 @@ INLINE void cave_tilemap_draw( clip.min_x = cliprect->min_x; clip.max_x = cliprect->max_x; - for(startline = cliprect->min_y; startline <= cliprect->max_y;) + for (startline = cliprect->min_y; startline <= cliprect->max_y;) { /* Find the largest slice */ - vramdata0 = (vramdata1 = VRAM[(0x1002+(((sy+offs_row+startline)*4)&0x7ff))/2]); + vramdata0 = (vramdata1 = VRAM[(0x1002 + (((sy + offs_row + startline) * 4) & 0x7ff)) / 2]); for(endline = startline + 1; endline <= cliprect->max_y; endline++) - if((++vramdata1) != VRAM[(0x1002+(((sy+offs_row+endline)*4)&0x7ff))/2]) break; + if((++vramdata1) != VRAM[(0x1002 + (((sy + offs_row + endline) * 4) & 0x7ff)) / 2]) break; tilemap_set_scrolly(TILEMAP, 0, vramdata0 - startline); @@ -1397,21 +1517,20 @@ INLINE void cave_tilemap_draw( tilemap_draw just once. */ - tilemap_set_scroll_rows(TILEMAP,512); + tilemap_set_scroll_rows(TILEMAP, 512); for(line = startline; line < endline; line++) - tilemap_set_scrollx( TILEMAP, - (vramdata0-startline+line) & 511, - sx + VRAM[(0x1000+(((sy+offs_row+line)*4)&0x7ff))/2] ); + tilemap_set_scrollx(TILEMAP, (vramdata0 - startline + line) & 511, + sx + VRAM[(0x1000 + (((sy + offs_row + line) * 4) & 0x7ff)) / 2]); } else // no row-scroll, row-select { tilemap_set_scroll_rows(TILEMAP, 1); - tilemap_set_scrollx(TILEMAP, 0, sx ); + tilemap_set_scrollx(TILEMAP, 0, sx); } - if(flipy) + if (flipy) { - clip.min_y = cliprect->max_y - (endline-1 - cliprect->min_y); + clip.min_y = cliprect->max_y - (endline - 1 - cliprect->min_y); clip.max_y = cliprect->max_y - (startline - cliprect->min_y); } else @@ -1428,12 +1547,11 @@ INLINE void cave_tilemap_draw( else if (VCTRL[0] & 0x4000) // row-scroll, no row-select { int line; - tilemap_set_scroll_rows(TILEMAP,512); + tilemap_set_scroll_rows(TILEMAP, 512); for(line = cliprect->min_y; line <= cliprect->max_y; line++) - tilemap_set_scrollx( TILEMAP, - (line + sy) & 511, - sx + VRAM[(0x1000+(((sy+offs_row+line)*4)&0x7ff))/2] ); - tilemap_set_scrolly(TILEMAP, 0, sy ); + tilemap_set_scrollx(TILEMAP, (line + sy) & 511, + sx + VRAM[(0x1000+(((sy + offs_row + line) * 4) & 0x7ff)) / 2] ); + tilemap_set_scrolly(TILEMAP, 0, sy); tilemap_draw(bitmap, cliprect, TILEMAP, flags, priority); } else @@ -1441,59 +1559,79 @@ INLINE void cave_tilemap_draw( /* DEF_STR( Normal ) scrolling */ tilemap_set_scroll_rows(TILEMAP, 1); tilemap_set_scroll_cols(TILEMAP, 1); - tilemap_set_scrollx(TILEMAP, 0, sx ); - tilemap_set_scrolly(TILEMAP, 0, sy ); + tilemap_set_scrollx(TILEMAP, 0, sx); + tilemap_set_scrolly(TILEMAP, 0, sy); tilemap_draw(bitmap, cliprect, TILEMAP, flags, priority); } } -static void cave_tilemap_0_draw( bitmap_t *bitmap, const rectangle *cliprect, UINT32 flags, UINT32 priority, UINT32 priority2 ) -{ cave_tilemap_draw( bitmap, cliprect, tilemap_0, cave_vram_0, cave_vctrl_0, flags, priority, priority2 ); } -static void cave_tilemap_1_draw( bitmap_t *bitmap, const rectangle *cliprect, UINT32 flags, UINT32 priority, UINT32 priority2 ) -{ cave_tilemap_draw( bitmap, cliprect, tilemap_1, cave_vram_1, cave_vctrl_1, flags, priority, priority2 ); } -static void cave_tilemap_2_draw( bitmap_t *bitmap, const rectangle *cliprect, UINT32 flags, UINT32 priority, UINT32 priority2 ) -{ cave_tilemap_draw( bitmap, cliprect, tilemap_2, cave_vram_2, cave_vctrl_2, flags, priority, priority2 ); } -static void cave_tilemap_3_draw( bitmap_t *bitmap, const rectangle *cliprect, UINT32 flags, UINT32 priority, UINT32 priority2 ) -{ cave_tilemap_draw( bitmap, cliprect, tilemap_3, cave_vram_3, cave_vctrl_3, flags, priority, priority2 ); } +static void cave_tilemap_0_draw( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, UINT32 flags, UINT32 priority, UINT32 priority2 ) +{ + cave_state *state = (cave_state *)machine->driver_data; + cave_tilemap_draw(machine, bitmap, cliprect, state->tilemap_0, state->vram_0, state->vctrl_0, flags, priority, priority2); +} + +static void cave_tilemap_1_draw( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, UINT32 flags, UINT32 priority, UINT32 priority2 ) +{ + cave_state *state = (cave_state *)machine->driver_data; + cave_tilemap_draw(machine, bitmap, cliprect, state->tilemap_1, state->vram_1, state->vctrl_1, flags, priority, priority2); +} + +static void cave_tilemap_2_draw( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, UINT32 flags, UINT32 priority, UINT32 priority2 ) +{ + cave_state *state = (cave_state *)machine->driver_data; + cave_tilemap_draw(machine, bitmap, cliprect, state->tilemap_2, state->vram_2, state->vctrl_2, flags, priority, priority2); +} + +static void cave_tilemap_3_draw( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, UINT32 flags, UINT32 priority, UINT32 priority2 ) +{ + cave_state *state = (cave_state *)machine->driver_data; + cave_tilemap_draw(machine, bitmap, cliprect, state->tilemap_3, state->vram_3, state->vctrl_3, flags, priority, priority2); +} VIDEO_UPDATE( cave ) { + cave_state *state = (cave_state *)screen->machine->driver_data; int pri, pri2; int layers_ctrl = -1; set_pens(screen->machine); - blit.baseaddr = (UINT8 *)bitmap->base; - blit.line_offset = bitmap->rowpixels * bitmap->bpp / 8; + state->blit.baseaddr = (UINT8 *)bitmap->base; + state->blit.line_offset = bitmap->rowpixels * bitmap->bpp / 8; /* Choose the tilemap to display (8x8 tiles or 16x16 tiles) */ - if (tilemap_0) + if (state->tilemap_0) { - tiledim_0 = cave_vctrl_0[ 1 ] & 0x2000; - if (tiledim_0 != old_tiledim_0) tilemap_mark_all_tiles_dirty(tilemap_0); - old_tiledim_0 = tiledim_0; + state->tiledim_0 = state->vctrl_0[1] & 0x2000; + if (state->tiledim_0 != state->old_tiledim_0) + tilemap_mark_all_tiles_dirty(state->tilemap_0); + state->old_tiledim_0 = state->tiledim_0; } - if (tilemap_1) + if (state->tilemap_1) { - tiledim_1 = cave_vctrl_1[ 1 ] & 0x2000; - if (tiledim_1 != old_tiledim_1) tilemap_mark_all_tiles_dirty(tilemap_1); - old_tiledim_1 = tiledim_1; + state->tiledim_1 = state->vctrl_1[1] & 0x2000; + if (state->tiledim_1 != state->old_tiledim_1) + tilemap_mark_all_tiles_dirty(state->tilemap_1); + state->old_tiledim_1 = state->tiledim_1; } - if (tilemap_2) + if (state->tilemap_2) { - tiledim_2 = cave_vctrl_2[ 1 ] & 0x2000; - if (tiledim_2 != old_tiledim_2) tilemap_mark_all_tiles_dirty(tilemap_2); - old_tiledim_2 = tiledim_2; + state->tiledim_2 = state->vctrl_2[1] & 0x2000; + if (state->tiledim_2 != state->old_tiledim_2) + tilemap_mark_all_tiles_dirty(state->tilemap_2); + state->old_tiledim_2 = state->tiledim_2; } - if (tilemap_3) + if (state->tilemap_3) { - tiledim_3 = cave_vctrl_3[ 1 ] & 0x2000; - if (tiledim_3 != old_tiledim_3) tilemap_mark_all_tiles_dirty(tilemap_3); - old_tiledim_3 = tiledim_3; + state->tiledim_3 = state->vctrl_3[1] & 0x2000; + if (state->tiledim_3 != state->old_tiledim_3) + tilemap_mark_all_tiles_dirty(state->tilemap_3); + state->old_tiledim_3 = state->tiledim_3; } @@ -1509,7 +1647,6 @@ VIDEO_UPDATE( cave ) if (input_code_pressed(screen->machine, KEYCODE_C)) val = 2; // "" 1 if (input_code_pressed(screen->machine, KEYCODE_V)) val = 4; // "" 2 if (input_code_pressed(screen->machine, KEYCODE_B)) val = 8; // "" 3 - if (input_code_pressed(screen->machine, KEYCODE_Z)) val = 1|2|4|8; // All of the above priorities if (input_code_pressed(screen->machine, KEYCODE_Q)) msk |= val << 0; // for layer 0 @@ -1522,45 +1659,45 @@ VIDEO_UPDATE( cave ) #if 1 /* Show the video registers (cave_videoregs) */ popmessage("%04X %04X %04X %04X %04X %04X %04X %04X", - cave_videoregs[0], cave_videoregs[1], cave_videoregs[2], cave_videoregs[3], - cave_videoregs[4], cave_videoregs[5], cave_videoregs[6], cave_videoregs[7] ); + state->videoregs[0], state->videoregs[1], state->videoregs[2], state->videoregs[3], + state->videoregs[4], state->videoregs[5], state->videoregs[6], state->videoregs[7] ); #endif /* Show the scroll / flags registers of the selected layer */ - if ((tilemap_0)&&(msk&0x000f)) popmessage("x:%04X y:%04X f:%04X",cave_vctrl_0[0],cave_vctrl_0[1],cave_vctrl_0[2]); - if ((tilemap_1)&&(msk&0x00f0)) popmessage("x:%04X y:%04X f:%04X",cave_vctrl_1[0],cave_vctrl_1[1],cave_vctrl_1[2]); - if ((tilemap_2)&&(msk&0x0f00)) popmessage("x:%04X y:%04X f:%04X",cave_vctrl_2[0],cave_vctrl_2[1],cave_vctrl_2[2]); - if ((tilemap_3)&&(msk&0xf000)) popmessage("x:%04X y:%04X f:%04X",cave_vctrl_3[0],cave_vctrl_3[1],cave_vctrl_3[2]); + if ((state->tilemap_0) && (msk & 0x000f)) popmessage("x:%04X y:%04X f:%04X", state->vctrl_0[0],state->vctrl_0[1],state->vctrl_0[2]); + if ((state->tilemap_1) && (msk & 0x00f0)) popmessage("x:%04X y:%04X f:%04X", state->vctrl_1[0],state->vctrl_1[1],state->vctrl_1[2]); + if ((state->tilemap_2) && (msk & 0x0f00)) popmessage("x:%04X y:%04X f:%04X", state->vctrl_2[0],state->vctrl_2[1],state->vctrl_2[2]); + if ((state->tilemap_3) && (msk & 0xf000)) popmessage("x:%04X y:%04X f:%04X", state->vctrl_3[0],state->vctrl_3[1],state->vctrl_3[2]); } /* Show the row / "column" scroll enable flags, when they change state */ rasflag = 0; - if (tilemap_0) + if (state->tilemap_0) { - rasflag |= (cave_vctrl_0[0] & 0x4000) ? 0x0001 : 0; - rasflag |= (cave_vctrl_0[1] & 0x4000) ? 0x0002 : 0; + rasflag |= (state->vctrl_0[0] & 0x4000) ? 0x0001 : 0; + rasflag |= (state->vctrl_0[1] & 0x4000) ? 0x0002 : 0; } - if (tilemap_1) + if (state->tilemap_1) { - rasflag |= (cave_vctrl_1[0] & 0x4000) ? 0x0010 : 0; - rasflag |= (cave_vctrl_1[1] & 0x4000) ? 0x0020 : 0; + rasflag |= (state->vctrl_1[0] & 0x4000) ? 0x0010 : 0; + rasflag |= (state->vctrl_1[1] & 0x4000) ? 0x0020 : 0; } - if (tilemap_2) + if (state->tilemap_2) { - rasflag |= (cave_vctrl_2[0] & 0x4000) ? 0x0100 : 0; - rasflag |= (cave_vctrl_2[1] & 0x4000) ? 0x0200 : 0; + rasflag |= (state->vctrl_2[0] & 0x4000) ? 0x0100 : 0; + rasflag |= (state->vctrl_2[1] & 0x4000) ? 0x0200 : 0; } - if (tilemap_3) + if (state->tilemap_3) { - rasflag |= (cave_vctrl_3[0] & 0x4000) ? 0x1000 : 0; - rasflag |= (cave_vctrl_3[1] & 0x4000) ? 0x2000 : 0; + rasflag |= (state->vctrl_3[0] & 0x4000) ? 0x1000 : 0; + rasflag |= (state->vctrl_3[1] & 0x4000) ? 0x2000 : 0; } if (rasflag != old_rasflag) { popmessage("Line Effect: 0:%c%c 1:%c%c 2:%c%c 3:%c%c", - (rasflag&0x0001)?'x':' ', (rasflag&0x0002)?'y':' ', - (rasflag&0x0010)?'x':' ', (rasflag&0x0020)?'y':' ', - (rasflag&0x0100)?'x':' ', (rasflag&0x0200)?'y':' ', - (rasflag&0x1000)?'x':' ', (rasflag&0x2000)?'y':' ' ); + (rasflag & 0x0001) ? 'x' : ' ', (rasflag & 0x0002) ? 'y' : ' ', + (rasflag & 0x0010) ? 'x' : ' ', (rasflag & 0x0020) ? 'y' : ' ', + (rasflag & 0x0100) ? 'x' : ' ', (rasflag & 0x0200) ? 'y' : ' ', + (rasflag & 0x1000) ? 'x' : ' ', (rasflag & 0x2000) ? 'y' : ' ' ); old_rasflag = rasflag; } } @@ -1568,7 +1705,7 @@ VIDEO_UPDATE( cave ) cave_sprite_check(screen, cliprect); - bitmap_fill(bitmap,cliprect,background_color); + bitmap_fill(bitmap, cliprect, state->background_color); /* Tiles and sprites are ordered by priority (0 back, 3 front) with @@ -1582,16 +1719,16 @@ VIDEO_UPDATE( cave ) Tiles with the same priority *and* the same priority of their layer are ordered by layer (0 back, 2 front) */ - for (pri=0;pri<=3;pri++) // tile / sprite priority + for (pri = 0; pri <= 3; pri++) // tile / sprite priority { - if (layers_ctrl&(1<<(pri+16))) (*cave_sprite_draw)( pri ); + if (layers_ctrl & (1 << (pri + 16))) (*state->sprite_draw)(screen->machine, pri); - for (pri2=0;pri2<=3;pri2++) // priority of the whole layer + for (pri2 = 0; pri2 <= 3; pri2++) // priority of the whole layer { - if (layers_ctrl&(1<<(pri+ 0))) cave_tilemap_0_draw(bitmap, cliprect, pri, 0, pri2); - if (layers_ctrl&(1<<(pri+ 4))) cave_tilemap_1_draw(bitmap, cliprect, pri, 0, pri2); - if (layers_ctrl&(1<<(pri+ 8))) cave_tilemap_2_draw(bitmap, cliprect, pri, 0, pri2); - if (layers_ctrl&(1<<(pri+12))) cave_tilemap_3_draw(bitmap, cliprect, pri, 0, pri2); + if (layers_ctrl & (1 << (pri + 0))) cave_tilemap_0_draw(screen->machine, bitmap, cliprect, pri, 0, pri2); + if (layers_ctrl & (1 << (pri + 4))) cave_tilemap_1_draw(screen->machine, bitmap, cliprect, pri, 0, pri2); + if (layers_ctrl & (1 << (pri + 8))) cave_tilemap_2_draw(screen->machine, bitmap, cliprect, pri, 0, pri2); + if (layers_ctrl & (1 << (pri + 12))) cave_tilemap_3_draw(screen->machine, bitmap, cliprect, pri, 0, pri2); } } return 0; @@ -1600,23 +1737,32 @@ VIDEO_UPDATE( cave ) /**************************************************************/ -void cave_get_sprite_info(running_machine *machine) + +void cave_get_sprite_info( running_machine *machine ) { - if(cave_kludge == 3) /* mazinger metmqstr */ + cave_state *state = (cave_state *)machine->driver_data; + if (state->kludge == 3) /* mazinger metmqstr */ { if (video_skip_this_frame() == 0) { - spriteram_bank = spriteram_bank_delay; - (*get_sprite_info)(machine); + state->spriteram_bank = state->spriteram_bank_delay; + (*state->get_sprite_info)(machine); } - spriteram_bank_delay = cave_videoregs[ 4 ] & 1; + state->spriteram_bank_delay = state->videoregs[4] & 1; } else { if (video_skip_this_frame() == 0) { - spriteram_bank = cave_videoregs[ 4 ] & 1; - (*get_sprite_info)(machine); + state->spriteram_bank = state->videoregs[4] & 1; + (*state->get_sprite_info)(machine); } } } + +static STATE_POSTLOAD( cave_sprite_postload ) +{ + /* FIXME: this is probably not enough to restore sprites, but anyway saves do not + currently work due to pending timers hence it is hard to test what is missing */ + cave_get_sprite_info(machine); +}