diff --git a/src/emu/sound/psx.c b/src/emu/sound/psx.c index 676782910dc..50b71c13e83 100644 --- a/src/emu/sound/psx.c +++ b/src/emu/sound/psx.c @@ -39,7 +39,7 @@ struct psxinfo const psx_spu_interface *intf; running_device *device; - UINT32 *g_p_n_psxram; + UINT32 *m_p_n_psxram; UINT16 m_n_mainvolumeleft; UINT16 m_n_mainvolumeright; UINT16 m_n_reverberationdepthleft; @@ -82,6 +82,7 @@ struct psxinfo sound_stream *stream; int installHack; + UINT32 m_n_spu_delay; }; INLINE struct psxinfo *get_safe_token(running_device *device) @@ -241,7 +242,7 @@ static void spu_read( running_machine *machine, UINT32 n_address, INT32 n_size ) while( n_size > 0 ) { - chip->g_p_n_psxram[ n_address / 4 ] = + chip->m_p_n_psxram[ n_address / 4 ] = ( chip->m_p_n_spuram[ chip->m_n_spuoffset + 0 ] << 0 ) | ( chip->m_p_n_spuram[ chip->m_n_spuoffset + 1 ] << 16 ); verboselog( machine, 2, "%08x > %04x\n", chip->m_n_spuoffset + 0, chip->m_p_n_spuram[ chip->m_n_spuoffset + 0 ] ); @@ -260,8 +261,8 @@ static void spu_write( running_machine *machine, UINT32 n_address, INT32 n_size while( n_size > 0 ) { - chip->m_p_n_spuram[ chip->m_n_spuoffset + 0 ] = ( chip->g_p_n_psxram[ n_address / 4 ] >> 0 ); - chip->m_p_n_spuram[ chip->m_n_spuoffset + 1 ] = ( chip->g_p_n_psxram[ n_address / 4 ] >> 16 ); + chip->m_p_n_spuram[ chip->m_n_spuoffset + 0 ] = ( chip->m_p_n_psxram[ n_address / 4 ] >> 0 ); + chip->m_p_n_spuram[ chip->m_n_spuoffset + 1 ] = ( chip->m_p_n_psxram[ n_address / 4 ] >> 16 ); verboselog( machine, 2, "%08x < %04x\n", chip->m_n_spuoffset + 0, chip->m_p_n_spuram[ chip->m_n_spuoffset + 0 ] ); verboselog( machine, 2, "%08x < %04x\n", chip->m_n_spuoffset + 1, chip->m_p_n_spuram[ chip->m_n_spuoffset + 1 ] ); chip->m_n_spuoffset += 2; @@ -279,7 +280,7 @@ static DEVICE_START( psxspu ) chip->intf = (const psx_spu_interface *)device->baseconfig().static_config(); chip->device = device; - chip->g_p_n_psxram = *(chip->intf->p_psxram); + chip->m_p_n_psxram = (UINT32 *)memory_get_shared(*device->machine, "share1"); chip->m_n_mainvolumeleft = 0; chip->m_n_mainvolumeright = 0; @@ -373,18 +374,20 @@ static DEVICE_START( psxspu ) } -static UINT32 psx_spu_delay = 0; - WRITE32_DEVICE_HANDLER( psx_spu_delay_w ) { - COMBINE_DATA( &psx_spu_delay ); + struct psxinfo *chip = get_safe_token(device); + + COMBINE_DATA( &chip->m_n_spu_delay ); verboselog( device->machine, 1, "psx_spu_delay_w( %08x %08x )\n", data, mem_mask ); } READ32_DEVICE_HANDLER( psx_spu_delay_r ) { + struct psxinfo *chip = get_safe_token(device); + verboselog( device->machine, 1, "psx_spu_delay_r( %08x )\n", mem_mask ); - return psx_spu_delay; + return chip->m_n_spu_delay; } READ32_DEVICE_HANDLER( psx_spu_r ) @@ -466,8 +469,8 @@ WRITE32_DEVICE_HANDLER( psx_spu_w ) if( !chip->installHack ) { - chip->intf->spu_install_read_handler( 4, spu_read ); - chip->intf->spu_install_write_handler( 4, spu_write ); + chip->intf->spu_install_read_handler( device->machine, 4, spu_read ); + chip->intf->spu_install_write_handler( device->machine, 4, spu_write ); chip->installHack = 1; } diff --git a/src/emu/sound/psx.h b/src/emu/sound/psx.h index ff69fd43fd7..828a27ac295 100644 --- a/src/emu/sound/psx.h +++ b/src/emu/sound/psx.h @@ -23,10 +23,9 @@ typedef void ( *spu_handler )( running_machine *, UINT32, INT32 ); typedef struct _psx_spu_interface psx_spu_interface; struct _psx_spu_interface { - UINT32 **p_psxram; void (*irq_set)(running_device *,UINT32); - void (*spu_install_read_handler)(int,spu_handler); - void (*spu_install_write_handler)(int,spu_handler); + void (*spu_install_read_handler)(running_machine *,int,spu_handler); + void (*spu_install_write_handler)(running_machine *,int,spu_handler); }; DECLARE_LEGACY_SOUND_DEVICE(PSXSPU, psxspu); diff --git a/src/mame/drivers/konamigq.c b/src/mame/drivers/konamigq.c index 616602c55cd..4c1ea179970 100644 --- a/src/mame/drivers/konamigq.c +++ b/src/mame/drivers/konamigq.c @@ -55,16 +55,27 @@ #include "harddisk.h" #include "sound/k054539.h" -/* Sound */ +class konamigq_state : public psx_state +{ +public: + konamigq_state(running_machine &machine, const driver_device_config_base &config) + : psx_state(machine, config) { } -static UINT8 sndto000[ 16 ]; -static UINT8 sndtor3k[ 16 ]; + UINT8 sndto000[ 16 ]; + UINT8 sndtor3k[ 16 ]; + UINT8 *p_n_pcmram; + UINT8 sector_buffer[ 512 ]; +}; + +/* Sound */ static WRITE32_HANDLER( soundr3k_w ) { + konamigq_state *state = space->machine->driver_data(); + if( ACCESSING_BITS_16_31 ) { - sndto000[ ( offset << 1 ) + 1 ] = data >> 16; + state->sndto000[ ( offset << 1 ) + 1 ] = data >> 16; if( offset == 3 ) { cputag_set_input_line(space->machine, "soundcpu", 1, HOLD_LINE ); @@ -72,15 +83,16 @@ static WRITE32_HANDLER( soundr3k_w ) } if( ACCESSING_BITS_0_15 ) { - sndto000[ offset << 1 ] = data; + state->sndto000[ offset << 1 ] = data; } } static READ32_HANDLER( soundr3k_r ) { + konamigq_state *state = space->machine->driver_data(); UINT32 data; - data = ( sndtor3k[ ( offset << 1 ) + 1 ] << 16 ) | sndtor3k[ offset << 1 ]; + data = ( state->sndtor3k[ ( offset << 1 ) + 1 ] << 16 ) | state->sndtor3k[ offset << 1 ]; /* hack to help the main program start up */ if( offset == 1 ) @@ -125,29 +137,31 @@ static WRITE32_HANDLER( eeprom_w ) /* PCM RAM */ -static UINT8 *m_p_n_pcmram; - static WRITE32_HANDLER( pcmram_w ) { + konamigq_state *state = space->machine->driver_data(); + if( ACCESSING_BITS_0_7 ) { - m_p_n_pcmram[ offset << 1 ] = data; + state->p_n_pcmram[ offset << 1 ] = data; } if( ACCESSING_BITS_16_23 ) { - m_p_n_pcmram[ ( offset << 1 ) + 1 ] = data >> 16; + state->p_n_pcmram[ ( offset << 1 ) + 1 ] = data >> 16; } } static READ32_HANDLER( pcmram_r ) { - return ( m_p_n_pcmram[ ( offset << 1 ) + 1 ] << 16 ) | m_p_n_pcmram[ offset << 1 ]; + konamigq_state *state = space->machine->driver_data(); + + return ( state->p_n_pcmram[ ( offset << 1 ) + 1 ] << 16 ) | state->p_n_pcmram[ offset << 1 ]; } /* Video */ static ADDRESS_MAP_START( konamigq_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") AM_BASE(&g_p_n_psxram) AM_SIZE(&g_n_psxramsize) /* ram */ + AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") /* ram */ AM_RANGE(0x1f000000, 0x1f00001f) AM_READWRITE(am53cf96_r, am53cf96_w) AM_RANGE(0x1f100000, 0x1f10000f) AM_WRITE(soundr3k_w) AM_RANGE(0x1f100010, 0x1f10001f) AM_READ(soundr3k_r) @@ -222,12 +236,16 @@ static WRITE16_HANDLER( dual539_w ) static READ16_HANDLER( sndcomm68k_r ) { - return sndto000[ offset ]; + konamigq_state *state = space->machine->driver_data(); + + return state->sndto000[ offset ]; } static WRITE16_HANDLER( sndcomm68k_w ) { - sndtor3k[ offset ] = data; + konamigq_state *state = space->machine->driver_data(); + + state->sndtor3k[ offset ] = data; } static READ16_HANDLER(tms57002_data_word_r) @@ -268,18 +286,19 @@ static const k054539_interface k054539_config = /* SCSI */ -static UINT8 sector_buffer[ 512 ]; - static void scsi_dma_read( running_machine *machine, UINT32 n_address, INT32 n_size ) { + konamigq_state *state = machine->driver_data(); + UINT32 *p_n_psxram = state->p_n_psxram; + UINT8 *sector_buffer = state->sector_buffer; int i; int n_this; while( n_size > 0 ) { - if( n_size > sizeof( sector_buffer ) / 4 ) + if( n_size > sizeof( state->sector_buffer ) / 4 ) { - n_this = sizeof( sector_buffer ) / 4; + n_this = sizeof( state->sector_buffer ) / 4; } else { @@ -291,7 +310,7 @@ static void scsi_dma_read( running_machine *machine, UINT32 n_address, INT32 n_s i = 0; while( n_this > 0 ) { - g_p_n_psxram[ n_address / 4 ] = + p_n_psxram[ n_address / 4 ] = ( sector_buffer[ i + 0 ] << 0 ) | ( sector_buffer[ i + 1 ] << 8 ) | ( sector_buffer[ i + 2 ] << 16 ) | @@ -328,9 +347,11 @@ static const struct AM53CF96interface scsi_intf = static DRIVER_INIT( konamigq ) { + konamigq_state *state = machine->driver_data(); + psx_driver_init(machine); - m_p_n_pcmram = memory_region( machine, "shared" ) + 0x80000; + state->p_n_pcmram = memory_region( machine, "shared" ) + 0x80000; } static void konamigq_exit(running_machine &machine) @@ -340,16 +361,18 @@ static void konamigq_exit(running_machine &machine) static MACHINE_START( konamigq ) { + konamigq_state *state = machine->driver_data(); + /* init the scsi controller and hook up it's DMA */ am53cf96_init(machine, &scsi_intf); machine->add_notifier(MACHINE_NOTIFY_EXIT, konamigq_exit); - psx_dma_install_read_handler(5, scsi_dma_read); - psx_dma_install_write_handler(5, scsi_dma_write); + psx_dma_install_read_handler(machine, 5, scsi_dma_read); + psx_dma_install_write_handler(machine, 5, scsi_dma_write); - state_save_register_global_pointer(machine, m_p_n_pcmram, 0x380000); - state_save_register_global_array(machine, sndto000); - state_save_register_global_array(machine, sndtor3k); - state_save_register_global_array(machine, sector_buffer); + state_save_register_global_pointer(machine, state->p_n_pcmram, 0x380000); + state_save_register_global_array(machine, state->sndto000); + state_save_register_global_array(machine, state->sndtor3k); + state_save_register_global_array(machine, state->sector_buffer); } static MACHINE_RESET( konamigq ) @@ -357,9 +380,9 @@ static MACHINE_RESET( konamigq ) psx_machine_init(machine); } -static MACHINE_CONFIG_START( konamigq, driver_device ) +static MACHINE_CONFIG_START( konamigq, konamigq_state ) /* basic machine hardware */ - MDRV_CPU_ADD("maincpu", PSXCPU, XTAL_67_7376MHz ) + MDRV_CPU_ADD( "maincpu", PSXCPU, XTAL_67_7376MHz ) MDRV_CPU_PROGRAM_MAP( konamigq_map) MDRV_CPU_VBLANK_INT("screen", psx_vblank) diff --git a/src/mame/drivers/konamigv.c b/src/mame/drivers/konamigv.c index 16459967219..4582d5d93a4 100644 --- a/src/mame/drivers/konamigv.c +++ b/src/mame/drivers/konamigv.c @@ -122,18 +122,24 @@ Notes: #include "sound/psx.h" #include "sound/cdda.h" -/* static variables */ +class konamigv_state : public psx_state +{ +public: + konamigv_state(running_machine &machine, const driver_device_config_base &config) + : psx_state(machine, config) { } -static UINT8 sector_buffer[ 4096 ]; -static UINT32 flash_address; + UINT32 flash_address; -static UINT16 trackball_prev[ 2 ]; -static UINT32 trackball_data[ 2 ]; -static UINT16 btc_trackball_prev[ 4 ]; -static UINT32 btc_trackball_data[ 4 ]; + UINT16 trackball_prev[ 2 ]; + UINT32 trackball_data[ 2 ]; + UINT16 btc_trackball_prev[ 4 ]; + UINT32 btc_trackball_data[ 4 ]; -static fujitsu_29f016a_device *flash8[4]; -static sharp_lh28f400_device *flash16[4]; + fujitsu_29f016a_device *flash8[4]; + sharp_lh28f400_device *flash16[4]; + + UINT8 sector_buffer[ 4096 ]; +}; /* EEPROM handlers */ @@ -154,7 +160,7 @@ static READ32_HANDLER( mb89371_r ) } static ADDRESS_MAP_START( konamigv_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x001fffff) AM_RAM AM_SHARE("share1") AM_BASE(&g_p_n_psxram) AM_SIZE(&g_n_psxramsize) /* ram */ + AM_RANGE(0x00000000, 0x001fffff) AM_RAM AM_SHARE("share1") /* ram */ AM_RANGE(0x1f000000, 0x1f00001f) AM_READWRITE(am53cf96_r, am53cf96_w) AM_RANGE(0x1f100000, 0x1f100003) AM_READ_PORT("P1") AM_RANGE(0x1f100004, 0x1f100007) AM_READ_PORT("P2") @@ -190,14 +196,17 @@ ADDRESS_MAP_END static void scsi_dma_read( running_machine *machine, UINT32 n_address, INT32 n_size ) { + konamigv_state *state = machine->driver_data(); + UINT32 *p_n_psxram = state->p_n_psxram; + UINT8 *sector_buffer = state->sector_buffer; int i; int n_this; while( n_size > 0 ) { - if( n_size > sizeof( sector_buffer ) / 4 ) + if( n_size > sizeof( state->sector_buffer ) / 4 ) { - n_this = sizeof( sector_buffer ) / 4; + n_this = sizeof( state->sector_buffer ) / 4; } else { @@ -219,7 +228,7 @@ static void scsi_dma_read( running_machine *machine, UINT32 n_address, INT32 n_s i = 0; while( n_this > 0 ) { - g_p_n_psxram[ n_address / 4 ] = + p_n_psxram[ n_address / 4 ] = ( sector_buffer[ i + 0 ] << 0 ) | ( sector_buffer[ i + 1 ] << 8 ) | ( sector_buffer[ i + 2 ] << 16 ) | @@ -233,14 +242,17 @@ static void scsi_dma_read( running_machine *machine, UINT32 n_address, INT32 n_s static void scsi_dma_write( running_machine *machine, UINT32 n_address, INT32 n_size ) { + konamigv_state *state = machine->driver_data(); + UINT32 *p_n_psxram = state->p_n_psxram; + UINT8 *sector_buffer = state->sector_buffer; int i; int n_this; while( n_size > 0 ) { - if( n_size > sizeof( sector_buffer ) / 4 ) + if( n_size > sizeof( state->sector_buffer ) / 4 ) { - n_this = sizeof( sector_buffer ) / 4; + n_this = sizeof( state->sector_buffer ) / 4; } else { @@ -251,10 +263,10 @@ static void scsi_dma_write( running_machine *machine, UINT32 n_address, INT32 n_ i = 0; while( n_this > 0 ) { - sector_buffer[ i + 0 ] = ( g_p_n_psxram[ n_address / 4 ] >> 0 ) & 0xff; - sector_buffer[ i + 1 ] = ( g_p_n_psxram[ n_address / 4 ] >> 8 ) & 0xff; - sector_buffer[ i + 2 ] = ( g_p_n_psxram[ n_address / 4 ] >> 16 ) & 0xff; - sector_buffer[ i + 3 ] = ( g_p_n_psxram[ n_address / 4 ] >> 24 ) & 0xff; + sector_buffer[ i + 0 ] = ( p_n_psxram[ n_address / 4 ] >> 0 ) & 0xff; + sector_buffer[ i + 1 ] = ( p_n_psxram[ n_address / 4 ] >> 8 ) & 0xff; + sector_buffer[ i + 2 ] = ( p_n_psxram[ n_address / 4 ] >> 16 ) & 0xff; + sector_buffer[ i + 3 ] = ( p_n_psxram[ n_address / 4 ] >> 24 ) & 0xff; n_address += 4; i += 4; n_this--; @@ -295,18 +307,20 @@ static DRIVER_INIT( konamigv ) /* init the scsi controller and hook up it's DMA */ am53cf96_init(machine, &scsi_intf); machine->add_notifier(MACHINE_NOTIFY_EXIT, konamigv_exit); - psx_dma_install_read_handler(5, scsi_dma_read); - psx_dma_install_write_handler(5, scsi_dma_write); + psx_dma_install_read_handler(machine, 5, scsi_dma_read); + psx_dma_install_write_handler(machine, 5, scsi_dma_write); } static MACHINE_START( konamigv ) { - state_save_register_global_array(machine, sector_buffer); - state_save_register_global(machine, flash_address); - state_save_register_global_array(machine, trackball_prev); - state_save_register_global_array(machine, trackball_data); - state_save_register_global_array(machine, btc_trackball_prev); - state_save_register_global_array(machine, btc_trackball_data); + konamigv_state *state = machine->driver_data(); + + state_save_register_global_array(machine, state->sector_buffer); + state_save_register_global(machine, state->flash_address); + state_save_register_global_array(machine, state->trackball_prev); + state_save_register_global_array(machine, state->trackball_data); + state_save_register_global_array(machine, state->btc_trackball_prev); + state_save_register_global_array(machine, state->btc_trackball_data); } static MACHINE_RESET( konamigv ) @@ -324,15 +338,14 @@ static void spu_irq(running_device *device, UINT32 data) static const psx_spu_interface konamigv_psxspu_interface = { - &g_p_n_psxram, spu_irq, psx_dma_install_read_handler, psx_dma_install_write_handler }; -static MACHINE_CONFIG_START( konamigv, driver_device ) +static MACHINE_CONFIG_START( konamigv, konamigv_state ) /* basic machine hardware */ - MDRV_CPU_ADD("maincpu", PSXCPU, XTAL_67_7376MHz ) + MDRV_CPU_ADD( "maincpu", PSXCPU, XTAL_67_7376MHz ) MDRV_CPU_PROGRAM_MAP( konamigv_map) MDRV_CPU_VBLANK_INT("screen", psx_vblank) @@ -432,6 +445,7 @@ INPUT_PORTS_END static READ32_HANDLER( flash_r ) { + konamigv_state *state = space->machine->driver_data(); int reg = offset*2; //int shift = 0; @@ -443,17 +457,17 @@ static READ32_HANDLER( flash_r ) if (reg == 4) // set odd address { - flash_address |= 1; + state->flash_address |= 1; } if (reg == 0) { - int chip = (flash_address >= 0x200000) ? 2 : 0; + int chip = (state->flash_address >= 0x200000) ? 2 : 0; int ret; - ret = flash8[chip]->read(flash_address & 0x1fffff) & 0xff; - ret |= flash8[chip+1]->read(flash_address & 0x1fffff)<<8; - flash_address++; + ret = state->flash8[chip]->read(state->flash_address & 0x1fffff) & 0xff; + ret |= state->flash8[chip+1]->read(state->flash_address & 0x1fffff)<<8; + state->flash_address++; return ret; } @@ -462,6 +476,7 @@ static READ32_HANDLER( flash_r ) static WRITE32_HANDLER( flash_w ) { + konamigv_state *state = space->machine->driver_data(); int reg = offset*2; int chip; @@ -474,28 +489,30 @@ static WRITE32_HANDLER( flash_w ) switch (reg) { case 0: - chip = (flash_address >= 0x200000) ? 2 : 0; - flash8[chip]->write(flash_address & 0x1fffff, data&0xff); - flash8[chip+1]->write(flash_address & 0x1fffff, (data>>8)&0xff); + chip = (state->flash_address >= 0x200000) ? 2 : 0; + state->flash8[chip]->write(state->flash_address & 0x1fffff, data&0xff); + state->flash8[chip+1]->write(state->flash_address & 0x1fffff, (data>>8)&0xff); break; case 1: - flash_address = 0; - flash_address |= (data<<1); + state->flash_address = 0; + state->flash_address |= (data<<1); break; case 2: - flash_address &= 0xff00ff; - flash_address |= (data<<8); + state->flash_address &= 0xff00ff; + state->flash_address |= (data<<8); break; case 3: - flash_address &= 0x00ffff; - flash_address |= (data<<15); + state->flash_address &= 0x00ffff; + state->flash_address |= (data<<15); break; } } static READ32_HANDLER( trackball_r ) { + konamigv_state *state = space->machine->driver_data(); + if( offset == 0 && mem_mask == 0x0000ffff ) { int axis; @@ -506,12 +523,12 @@ static READ32_HANDLER( trackball_r ) for( axis = 0; axis < 2; axis++ ) { value = input_port_read(space->machine, axisnames[axis]); - diff = value - trackball_prev[ axis ]; - trackball_prev[ axis ] = value; - trackball_data[ axis ] = ( ( diff & 0xf00 ) << 16 ) | ( ( diff & 0xff ) << 8 ); + diff = value - state->trackball_prev[ axis ]; + state->trackball_prev[ axis ] = value; + state->trackball_data[ axis ] = ( ( diff & 0xf00 ) << 16 ) | ( ( diff & 0xff ) << 8 ); } } - return trackball_data[ offset ]; + return state->trackball_data[ offset ]; } static READ32_HANDLER( unknown_r ) @@ -521,10 +538,12 @@ static READ32_HANDLER( unknown_r ) static DRIVER_INIT( simpbowl ) { - flash8[0] = machine->device("flash0"); - flash8[1] = machine->device("flash1"); - flash8[2] = machine->device("flash2"); - flash8[3] = machine->device("flash3"); + konamigv_state *state = machine->driver_data(); + + state->flash8[0] = machine->device("flash0"); + state->flash8[1] = machine->device("flash1"); + state->flash8[2] = machine->device("flash2"); + state->flash8[3] = machine->device("flash3"); memory_install_readwrite32_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f680080, 0x1f68008f, 0, 0, flash_r, flash_w ); memory_install_read32_handler ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f6800c0, 0x1f6800c7, 0, 0, trackball_r ); @@ -555,13 +574,15 @@ INPUT_PORTS_END static READ32_HANDLER( btcflash_r ) { + konamigv_state *state = space->machine->driver_data(); + if (mem_mask == 0x0000ffff) { - return flash16[0]->read(offset*2); + return state->flash16[0]->read(offset*2); } else if (mem_mask == 0xffff0000) { - return flash16[0]->read((offset*2)+1)<<16; + return state->flash16[0]->read((offset*2)+1)<<16; } return 0; @@ -569,18 +590,22 @@ static READ32_HANDLER( btcflash_r ) static WRITE32_HANDLER( btcflash_w ) { + konamigv_state *state = space->machine->driver_data(); + if (mem_mask == 0x0000ffff) { - flash16[0]->write(offset*2, data&0xffff); + state->flash16[0]->write(offset*2, data&0xffff); } else if (mem_mask == 0xffff0000) { - flash16[0]->write((offset*2)+1, (data>>16)&0xffff); + state->flash16[0]->write((offset*2)+1, (data>>16)&0xffff); } } static READ32_HANDLER( btc_trackball_r ) { + konamigv_state *state = space->machine->driver_data(); + // mame_printf_debug( "r %08x %08x %08x\n", cpu_get_pc(space->cpu), offset, mem_mask ); if( offset == 1 && mem_mask == 0xffff0000 ) @@ -593,12 +618,13 @@ static READ32_HANDLER( btc_trackball_r ) for( axis = 0; axis < 4; axis++ ) { value = input_port_read(space->machine, axisnames[axis]); - diff = value - btc_trackball_prev[ axis ]; - btc_trackball_prev[ axis ] = value; - btc_trackball_data[ axis ] = ( ( diff & 0xf00 ) << 16 ) | ( ( diff & 0xff ) << 8 ); + diff = value - state->btc_trackball_prev[ axis ]; + state->btc_trackball_prev[ axis ] = value; + state->btc_trackball_data[ axis ] = ( ( diff & 0xf00 ) << 16 ) | ( ( diff & 0xff ) << 8 ); } } - return btc_trackball_data[ offset ] | ( btc_trackball_data[ offset + 2 ] >> 8 ); + + return state->btc_trackball_data[ offset ] | ( state->btc_trackball_data[ offset + 2 ] >> 8 ); } static WRITE32_HANDLER( btc_trackball_w ) @@ -608,7 +634,9 @@ static WRITE32_HANDLER( btc_trackball_w ) static DRIVER_INIT( btchamp ) { - flash16[0] = machine->device("flash"); + konamigv_state *state = machine->driver_data(); + + state->flash16[0] = machine->device("flash"); memory_install_readwrite32_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f680080, 0x1f68008f, 0, 0, btc_trackball_r, btc_trackball_w ); memory_nop_write ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f6800e0, 0x1f6800e3, 0, 0 ); @@ -694,7 +722,9 @@ static WRITE32_HANDLER( kdeadeye_0_w ) static DRIVER_INIT( kdeadeye ) { - flash16[0] = machine->device("flash"); + konamigv_state *state = machine->driver_data(); + + state->flash16[0] = machine->device("flash"); memory_install_read_port ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f680080, 0x1f680083, 0, 0, "GUNX1" ); memory_install_read_port ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f680090, 0x1f680093, 0, 0, "GUNY1" ); diff --git a/src/mame/drivers/ksys573.c b/src/mame/drivers/ksys573.c index 72dd3101c1c..bcc61b54ff3 100644 --- a/src/mame/drivers/ksys573.c +++ b/src/mame/drivers/ksys573.c @@ -352,6 +352,74 @@ G: gun mania only, drives air soft gun (this game uses real BB bullet) #define VERBOSE_LEVEL ( 0 ) +class ksys573_state : public psx_state +{ +public: + ksys573_state(running_machine &machine, const driver_device_config_base &config) + : psx_state(machine, config) { } + + int flash_bank; + fujitsu_29f016a_device *flash_device[5][16]; + int security_cart_number; + + int chiptype[ 2 ]; + int has_ds2401[ 2 ]; + + nvram_handler_func nvram_handler_security_cart_0; + nvram_handler_func nvram_handler_security_cart_1; + + UINT32 control; + + UINT8 *atapi_regs; + emu_timer *atapi_timer; + SCSIInstance *inserted_cdrom; + SCSIInstance *available_cdroms[ 2 ]; + UINT8 *atapi_data; + int atapi_data_ptr; + int atapi_data_len; + int atapi_xferlen; + int atapi_xferbase; + int atapi_cdata_wait; + int atapi_xfermod; + + UINT32 m_n_security_control; + void (*security_callback)( running_machine *machine, int data ); + + emu_timer *m_p_timer_root[ 3 ]; + UINT16 m_p_n_root_count[ 3 ]; + UINT16 m_p_n_root_mode[ 3 ]; + UINT16 m_p_n_root_target[ 3 ]; + UINT64 m_p_n_root_start[ 3 ]; + + UINT8 gx700pwbf_output_data[ 4 ]; + void (*gx700pwfbf_output_callback)( running_machine *machine, int offset, int data ); + UINT16 gx894pwbba_output_data[ 8 ]; + void (*gx894pwbba_output_callback)( running_machine *machine, int offset, int data ); + + UINT32 stage_mask; + struct + { + int DO; + int clk; + int shift; + int state; + int bit; + } stage[ 2 ]; + + UINT32 gx894_ram_write_offset; + UINT32 gx894_ram_read_offset; + UINT16 *gx894_ram; + int f, o, s; + UINT32 a,b,c,d; + + int salarymc_lamp_bits; + int salarymc_lamp_shift; + int salarymc_lamp_clk; + + int hyperbbc_lamp_strobe1; + int hyperbbc_lamp_strobe2; +}; + INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, const char *s_fmt, ... ) { if( VERBOSE_LEVEL >= n_level ) @@ -365,30 +433,22 @@ INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, } } -static int flash_bank; -static fujitsu_29f016a_device *flash_device[5][16]; -static int security_cart_number = 0; - -static int chiptype[ 2 ]; -static int has_ds2401[ 2 ]; - static const char *const diskregions[] = { "cdrom0", "cdrom1" }; /* EEPROM handlers */ -static nvram_handler_func nvram_handler_security_cart_0; -static nvram_handler_func nvram_handler_security_cart_1; - static NVRAM_HANDLER( konami573 ) { - if( nvram_handler_security_cart_0 != NULL ) + ksys573_state *state = machine->driver_data(); + + if( state->nvram_handler_security_cart_0 != NULL ) { - NVRAM_HANDLER_CALL(security_cart_0); + state->nvram_handler_security_cart_0(machine, file, read_or_write); } - if( nvram_handler_security_cart_1 != NULL ) + if( state->nvram_handler_security_cart_1 != NULL ) { - NVRAM_HANDLER_CALL(security_cart_1); + state->nvram_handler_security_cart_1(machine, file, read_or_write); } } @@ -406,16 +466,18 @@ static READ32_HANDLER( mb89371_r ) static READ32_HANDLER( jamma_r ) { + ksys573_state *state = space->machine->driver_data(); running_machine *machine = space->machine; + int security_cart_number = state->security_cart_number; UINT32 data = input_port_read(machine, "IN1"); data |= 0x000000c0; - if( has_ds2401[ security_cart_number ] ) + if( state->has_ds2401[ security_cart_number ] ) { data |= ds2401_read( machine, security_cart_number ) << 14; } - switch( chiptype[ security_cart_number ] ) + switch( state->chiptype[ security_cart_number ] ) { case 1: data |= x76f041_sda_read( machine, security_cart_number ) << 18; @@ -430,11 +492,11 @@ static READ32_HANDLER( jamma_r ) break; } - if( flash_device[1][0] == NULL ) + if( state->flash_device[1][0] == NULL ) { data |= ( 1 << 26 ); } - if( flash_device[2][0] == NULL ) + if( state->flash_device[2][0] == NULL ) { data |= ( 1 << 27 ); } @@ -444,55 +506,59 @@ static READ32_HANDLER( jamma_r ) return data; } -static UINT32 control; - static READ32_HANDLER( control_r ) { - verboselog( space->machine, 2, "control_r( %08x, %08x ) %08x\n", offset, mem_mask, control ); + ksys573_state *state = space->machine->driver_data(); - return control; + verboselog( space->machine, 2, "control_r( %08x, %08x ) %08x\n", offset, mem_mask, state->control ); + + return state->control; } static WRITE32_HANDLER( control_w ) { + ksys573_state *state = space->machine->driver_data(); + UINT32 control; // int old_bank = flash_bank; - COMBINE_DATA(&control); + + COMBINE_DATA(&state->control); + control = state->control; verboselog( space->machine, 2, "control_w( %08x, %08x, %08x )\n", offset, mem_mask, data ); - flash_bank = -1; + state->flash_bank = -1; - switch( chiptype[ security_cart_number ] ) + switch( state->chiptype[ state->security_cart_number ] ) { case 3: - zs01_sda_write( space->machine, security_cart_number, !( ( control >> 6 ) & 1 ) ); /* 0x40 */ + zs01_sda_write( space->machine, state->security_cart_number, !( ( control >> 6 ) & 1 ) ); /* 0x40 */ break; } - if( flash_device[0][0] != NULL && ( control & ~0x43 ) == 0x00 ) + if( state->flash_device[0][0] != NULL && ( control & ~0x43 ) == 0x00 ) { - flash_bank = (0 << 8) + ( ( control & 3 ) * 2 ); -// if( flash_bank != old_bank ) mame_printf_debug( "onboard %d\r", control & 3 ); + state->flash_bank = (0 << 8) + ( ( control & 3 ) * 2 ); +// if( state->flash_bank != old_bank ) mame_printf_debug( "onboard %d\r", control & 3 ); } - else if( flash_device[1][0] != NULL && ( control & ~0x47 ) == 0x10 ) + else if( state->flash_device[1][0] != NULL && ( control & ~0x47 ) == 0x10 ) { - flash_bank = (1 << 8) + ( ( control & 7 ) * 2 ); -// if( flash_bank != old_bank ) mame_printf_debug( "pccard1 %d\r", control & 7 ); + state->flash_bank = (1 << 8) + ( ( control & 7 ) * 2 ); +// if( state->flash_bank != old_bank ) mame_printf_debug( "pccard1 %d\r", control & 7 ); } - else if( flash_device[2][0] != NULL && ( control & ~0x47 ) == 0x20 ) + else if( state->flash_device[2][0] != NULL && ( control & ~0x47 ) == 0x20 ) { - flash_bank = (2 << 8) + ( ( control & 7 ) * 2 ); -// if( flash_bank != old_bank ) mame_printf_debug( "pccard2 %d\r", control & 7 ); + state->flash_bank = (2 << 8) + ( ( control & 7 ) * 2 ); +// if( state->flash_bank != old_bank ) mame_printf_debug( "pccard2 %d\r", control & 7 ); } - else if( flash_device[3][0] != NULL && ( control & ~0x47 ) == 0x20 ) + else if( state->flash_device[3][0] != NULL && ( control & ~0x47 ) == 0x20 ) { - flash_bank = (3 << 8) + ( ( control & 7 ) * 2 ); -// if( flash_bank != old_bank ) mame_printf_debug( "pccard3 %d\r", control & 7 ); + state->flash_bank = (3 << 8) + ( ( control & 7 ) * 2 ); +// if( state->flash_bank != old_bank ) mame_printf_debug( "pccard3 %d\r", control & 7 ); } - else if( flash_device[4][0] != NULL && ( control & ~0x47 ) == 0x28 ) + else if( state->flash_device[4][0] != NULL && ( control & ~0x47 ) == 0x28 ) { - flash_bank = (4 << 8) + ( ( control & 7 ) * 2 ); -// if( flash_bank != old_bank ) mame_printf_debug( "pccard4 %d\r", control & 7 ); + state->flash_bank = (4 << 8) + ( ( control & 7 ) * 2 ); +// if( state->flash_bank != old_bank ) mame_printf_debug( "pccard4 %d\r", control & 7 ); } } @@ -522,66 +588,63 @@ static WRITE32_HANDLER( control_w ) #define ATAPI_DATA_SIZE ( 64 * 1024 ) -static UINT8 *atapi_regs; -static emu_timer *atapi_timer; -static SCSIInstance *inserted_cdrom; -static SCSIInstance *available_cdroms[ 2 ]; -static UINT8 *atapi_data; -static int atapi_data_ptr, atapi_data_len, atapi_xferlen, atapi_xferbase, atapi_cdata_wait, atapi_xfermod; - #define MAX_TRANSFER_SIZE ( 63488 ) static TIMER_CALLBACK( atapi_xfer_end ) { + ksys573_state *state = machine->driver_data(); + UINT32 *p_n_psxram = state->p_n_psxram; + UINT8 *atapi_regs = state->atapi_regs; int i, n_this; UINT8 sector_buffer[ 4096 ]; - timer_adjust_oneshot(atapi_timer, attotime_never, 0); + timer_adjust_oneshot(state->atapi_timer, attotime_never, 0); // verboselog( machine, 2, "atapi_xfer_end( %d ) atapi_xferlen = %d, atapi_xfermod=%d\n", x, atapi_xfermod, atapi_xferlen ); // mame_printf_debug("ATAPI: xfer_end. xferlen = %d, atapi_xfermod = %d\n", atapi_xferlen, atapi_xfermod); - while (atapi_xferlen > 0 ) + while( state->atapi_xferlen > 0 ) { // get a sector from the SCSI device - SCSIReadData( inserted_cdrom, sector_buffer, 2048 ); + SCSIReadData( state->inserted_cdrom, sector_buffer, 2048 ); - atapi_xferlen -= 2048; + state->atapi_xferlen -= 2048; i = 0; n_this = 2048 / 4; while( n_this > 0 ) { - g_p_n_psxram[ atapi_xferbase / 4 ] = + p_n_psxram[ state->atapi_xferbase / 4 ] = ( sector_buffer[ i + 0 ] << 0 ) | ( sector_buffer[ i + 1 ] << 8 ) | ( sector_buffer[ i + 2 ] << 16 ) | ( sector_buffer[ i + 3 ] << 24 ); - atapi_xferbase += 4; + state->atapi_xferbase += 4; i += 4; n_this--; } } - if (atapi_xfermod > MAX_TRANSFER_SIZE) + if (state->atapi_xfermod > MAX_TRANSFER_SIZE) { - atapi_xferlen = MAX_TRANSFER_SIZE; - atapi_xfermod = atapi_xfermod - MAX_TRANSFER_SIZE; + state->atapi_xferlen = MAX_TRANSFER_SIZE; + state->atapi_xfermod = state->atapi_xfermod - MAX_TRANSFER_SIZE; } else { - atapi_xferlen = atapi_xfermod; - atapi_xfermod = 0; + state->atapi_xferlen = state->atapi_xfermod; + state->atapi_xfermod = 0; } - if (atapi_xferlen > 0) + + if (state->atapi_xferlen > 0) { //mame_printf_debug("ATAPI: starting next piece of multi-part transfer\n"); - atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff; - atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff; + atapi_regs[ATAPI_REG_COUNTLOW] = state->atapi_xferlen & 0xff; + atapi_regs[ATAPI_REG_COUNTHIGH] = (state->atapi_xferlen>>8)&0xff; - timer_adjust_oneshot(atapi_timer, machine->device("maincpu")->cycles_to_attotime((ATAPI_CYCLES_PER_SECTOR * (atapi_xferlen/2048))), 0); + timer_adjust_oneshot(state->atapi_timer, machine->device("maincpu")->cycles_to_attotime((ATAPI_CYCLES_PER_SECTOR * (state->atapi_xferlen/2048))), 0); } else { @@ -592,11 +655,13 @@ static TIMER_CALLBACK( atapi_xfer_end ) psx_irq_set(machine, 0x400); - verboselog( machine, 2, "atapi_xfer_end: %d %d\n", atapi_xferlen, atapi_xfermod ); + verboselog( machine, 2, "atapi_xfer_end: %d %d\n", state->atapi_xferlen, state->atapi_xfermod ); } static READ32_HANDLER( atapi_r ) { + ksys573_state *state = space->machine->driver_data(); + UINT8 *atapi_regs = state->atapi_regs; running_machine *machine = space->machine; int reg, data; @@ -605,28 +670,28 @@ static READ32_HANDLER( atapi_r ) // mame_printf_debug("ATAPI: packet read = %04x\n", atapi_data[atapi_data_ptr]); // assert IRQ and drop DRQ - if (atapi_data_ptr == 0 && atapi_data_len == 0) + if (state->atapi_data_ptr == 0 && state->atapi_data_len == 0) { // get the data from the device - if( atapi_xferlen > 0 ) + if( state->atapi_xferlen > 0 ) { - SCSIReadData( inserted_cdrom, atapi_data, atapi_xferlen ); - atapi_data_len = atapi_xferlen; + SCSIReadData( state->inserted_cdrom, state->atapi_data, state->atapi_xferlen ); + state->atapi_data_len = state->atapi_xferlen; } - if (atapi_xfermod > MAX_TRANSFER_SIZE) + if (state->atapi_xfermod > MAX_TRANSFER_SIZE) { - atapi_xferlen = MAX_TRANSFER_SIZE; - atapi_xfermod = atapi_xfermod - MAX_TRANSFER_SIZE; + state->atapi_xferlen = MAX_TRANSFER_SIZE; + state->atapi_xfermod = state->atapi_xfermod - MAX_TRANSFER_SIZE; } else { - atapi_xferlen = atapi_xfermod; - atapi_xfermod = 0; + state->atapi_xferlen = state->atapi_xfermod; + state->atapi_xfermod = 0; } - verboselog( machine, 2, "atapi_r: atapi_xferlen=%d\n", atapi_xferlen ); - if( atapi_xferlen != 0 ) + verboselog( machine, 2, "atapi_r: atapi_xferlen=%d\n", state->atapi_xferlen ); + if( state->atapi_xferlen != 0 ) { atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC; atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO; @@ -638,23 +703,23 @@ static READ32_HANDLER( atapi_r ) atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO; } - atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff; - atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff; + atapi_regs[ATAPI_REG_COUNTLOW] = state->atapi_xferlen & 0xff; + atapi_regs[ATAPI_REG_COUNTHIGH] = (state->atapi_xferlen>>8)&0xff; psx_irq_set(space->machine, 0x400); } - if( atapi_data_ptr < atapi_data_len ) + if( state->atapi_data_ptr < state->atapi_data_len ) { - data = atapi_data[atapi_data_ptr++]; - data |= ( atapi_data[atapi_data_ptr++] << 8 ); - if( atapi_data_ptr >= atapi_data_len ) + data = state->atapi_data[state->atapi_data_ptr++]; + data |= ( state->atapi_data[state->atapi_data_ptr++] << 8 ); + if( state->atapi_data_ptr >= state->atapi_data_len ) { // verboselog( machine, 2, "atapi_r: read all bytes\n" ); - atapi_data_ptr = 0; - atapi_data_len = 0; + state->atapi_data_ptr = 0; + state->atapi_data_len = 0; - if( atapi_xferlen == 0 ) + if( state->atapi_xferlen == 0 ) { atapi_regs[ATAPI_REG_CMDSTATUS] = 0; atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO; @@ -719,6 +784,9 @@ static READ32_HANDLER( atapi_r ) static WRITE32_HANDLER( atapi_w ) { + ksys573_state *state = space->machine->driver_data(); + UINT8 *atapi_regs = state->atapi_regs; + UINT8 *atapi_data = state->atapi_data; running_machine *machine = space->machine; int reg; @@ -729,16 +797,16 @@ static WRITE32_HANDLER( atapi_w ) verboselog( machine, 2, "atapi_w: data=%04x\n", data ); // mame_printf_debug("ATAPI: packet write %04x\n", data); - atapi_data[atapi_data_ptr++] = data & 0xff; - atapi_data[atapi_data_ptr++] = data >> 8; + atapi_data[state->atapi_data_ptr++] = data & 0xff; + atapi_data[state->atapi_data_ptr++] = data >> 8; - if (atapi_cdata_wait) + if (state->atapi_cdata_wait) { -// mame_printf_debug("ATAPI: waiting, ptr %d wait %d\n", atapi_data_ptr, atapi_cdata_wait); - if (atapi_data_ptr == atapi_cdata_wait) +// mame_printf_debug("ATAPI: waiting, ptr %d wait %d\n", state->atapi_data_ptr, state->atapi_cdata_wait); + if (state->atapi_data_ptr == state->atapi_cdata_wait) { // send it to the device - SCSIWriteData( inserted_cdrom, atapi_data, atapi_cdata_wait ); + SCSIWriteData( state->inserted_cdrom, atapi_data, state->atapi_cdata_wait ); // assert IRQ psx_irq_set(space->machine, 0x400); @@ -748,38 +816,38 @@ static WRITE32_HANDLER( atapi_w ) } } - else if ( atapi_data_ptr == 12 ) + else if ( state->atapi_data_ptr == 12 ) { int phase; verboselog( machine, 2, "atapi_w: command %02x\n", atapi_data[0]&0xff ); // reset data pointer for reading SCSI results - atapi_data_ptr = 0; - atapi_data_len = 0; + state->atapi_data_ptr = 0; + state->atapi_data_len = 0; // send it to the SCSI device - SCSISetCommand( inserted_cdrom, atapi_data, 12 ); - SCSIExecCommand( inserted_cdrom, &atapi_xferlen ); - SCSIGetPhase( inserted_cdrom, &phase ); + SCSISetCommand( state->inserted_cdrom, state->atapi_data, 12 ); + SCSIExecCommand( state->inserted_cdrom, &state->atapi_xferlen ); + SCSIGetPhase( state->inserted_cdrom, &phase ); - if (atapi_xferlen != -1) + if (state->atapi_xferlen != -1) { -// mame_printf_debug("ATAPI: SCSI command %02x returned %d bytes from the device\n", atapi_data[0]&0xff, atapi_xferlen); +// mame_printf_debug("ATAPI: SCSI command %02x returned %d bytes from the device\n", atapi_data[0]&0xff, state->atapi_xferlen); // store the returned command length in the ATAPI regs, splitting into // multiple transfers if necessary - atapi_xfermod = 0; - if (atapi_xferlen > MAX_TRANSFER_SIZE) + state->atapi_xfermod = 0; + if (state->atapi_xferlen > MAX_TRANSFER_SIZE) { - atapi_xfermod = atapi_xferlen - MAX_TRANSFER_SIZE; - atapi_xferlen = MAX_TRANSFER_SIZE; + state->atapi_xfermod = state->atapi_xferlen - MAX_TRANSFER_SIZE; + state->atapi_xferlen = MAX_TRANSFER_SIZE; } - atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff; - atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff; + atapi_regs[ATAPI_REG_COUNTLOW] = state->atapi_xferlen & 0xff; + atapi_regs[ATAPI_REG_COUNTHIGH] = (state->atapi_xferlen>>8)&0xff; - if (atapi_xferlen == 0) + if (state->atapi_xferlen == 0) { // if no data to return, set the registers properly atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRDY; @@ -795,7 +863,7 @@ static WRITE32_HANDLER( atapi_w ) switch( phase ) { case SCSI_PHASE_DATAOUT: - atapi_cdata_wait = atapi_xferlen; + state->atapi_cdata_wait = state->atapi_xferlen; break; } @@ -809,7 +877,7 @@ static WRITE32_HANDLER( atapi_w ) case 0x45: // PLAY atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY; - timer_adjust_oneshot( atapi_timer, downcast(space->cpu)->cycles_to_attotime( ATAPI_CYCLES_PER_SECTOR ), 0 ); + timer_adjust_oneshot( state->atapi_timer, downcast(space->cpu)->cycles_to_attotime( ATAPI_CYCLES_PER_SECTOR ), 0 ); break; } @@ -877,27 +945,27 @@ static WRITE32_HANDLER( atapi_w ) atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ; atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_COMMAND; - atapi_data_ptr = 0; - atapi_data_len = 0; + state->atapi_data_ptr = 0; + state->atapi_data_len = 0; /* we have no data */ - atapi_xferlen = 0; - atapi_xfermod = 0; + state->atapi_xferlen = 0; + state->atapi_xfermod = 0; - atapi_cdata_wait = 0; + state->atapi_cdata_wait = 0; break; case 0xa1: // IDENTIFY PACKET DEVICE atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ; - atapi_data_ptr = 0; - atapi_data_len = 512; + state->atapi_data_ptr = 0; + state->atapi_data_len = 512; /* we have no data */ - atapi_xferlen = 0; - atapi_xfermod = 0; + state->atapi_xferlen = 0; + state->atapi_xfermod = 0; - memset( atapi_data, 0, atapi_data_len ); + memset( atapi_data, 0, state->atapi_data_len ); atapi_data[ 0 ^ 1 ] = 0x85; // ATAPI device, cmd set 5 compliant, DRQ within 3 ms of PACKET command atapi_data[ 1 ^ 1 ] = 0x00; @@ -937,8 +1005,8 @@ static WRITE32_HANDLER( atapi_w ) case 0xef: // SET FEATURES atapi_regs[ATAPI_REG_CMDSTATUS] = 0; - atapi_data_ptr = 0; - atapi_data_len = 0; + state->atapi_data_ptr = 0; + state->atapi_data_len = 0; psx_irq_set(space->machine, 0x400); break; @@ -953,63 +1021,68 @@ static WRITE32_HANDLER( atapi_w ) static void atapi_exit(running_machine& machine) { + ksys573_state *state = machine.driver_data(); int i; for( i = 0; i < 2; i++ ) { if( get_disk_handle( &machine, diskregions[i] ) != NULL ) { - SCSIDeleteInstance( available_cdroms[ i ] ); + SCSIDeleteInstance( state->available_cdroms[ i ] ); } } } static void atapi_init(running_machine *machine) { + ksys573_state *state = machine->driver_data(); + UINT8 *atapi_regs; int i; - atapi_regs = auto_alloc_array(machine, UINT8, ATAPI_REG_MAX ); - memset(atapi_regs, 0, sizeof(atapi_regs)); + atapi_regs = state->atapi_regs = auto_alloc_array( machine, UINT8, ATAPI_REG_MAX ); atapi_regs[ATAPI_REG_CMDSTATUS] = 0; atapi_regs[ATAPI_REG_ERRFEAT] = 1; atapi_regs[ATAPI_REG_COUNTLOW] = 0x14; atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb; - atapi_data_ptr = 0; - atapi_data_len = 0; - atapi_cdata_wait = 0; + state->atapi_data_ptr = 0; + state->atapi_data_len = 0; + state->atapi_cdata_wait = 0; - atapi_timer = timer_alloc(machine, atapi_xfer_end , NULL); - timer_adjust_oneshot(atapi_timer, attotime_never, 0); + state->atapi_timer = timer_alloc(machine, atapi_xfer_end, NULL); + timer_adjust_oneshot(state->atapi_timer, attotime_never, 0); for( i = 0; i < 2; i++ ) { if( get_disk_handle( machine, diskregions[i] ) != NULL ) { - SCSIAllocInstance( machine, &SCSIClassCr589, &available_cdroms[ i ], diskregions[i] ); + SCSIAllocInstance( machine, &SCSIClassCr589, &state->available_cdroms[ i ], diskregions[i] ); } else { - available_cdroms[ i ] = NULL; + state->available_cdroms[ i ] = NULL; } } machine->add_notifier(MACHINE_NOTIFY_EXIT, atapi_exit); - atapi_data = auto_alloc_array(machine, UINT8, ATAPI_DATA_SIZE ); + state->atapi_data = auto_alloc_array( machine, UINT8, ATAPI_DATA_SIZE ); - state_save_register_global_pointer(machine, atapi_regs, ATAPI_REG_MAX ); - state_save_register_global_pointer(machine, atapi_data, ATAPI_DATA_SIZE / 2 ); - state_save_register_global(machine, atapi_data_ptr ); - state_save_register_global(machine, atapi_data_len ); - state_save_register_global(machine, atapi_xferlen ); - state_save_register_global(machine, atapi_xferbase ); - state_save_register_global(machine, atapi_cdata_wait ); - state_save_register_global(machine, atapi_xfermod ); + state_save_register_global_pointer( machine, state->atapi_regs, ATAPI_REG_MAX ); + state_save_register_global_pointer( machine, state->atapi_data, ATAPI_DATA_SIZE / 2 ); + state_save_register_global( machine, state->atapi_data_ptr ); + state_save_register_global( machine, state->atapi_data_len ); + state_save_register_global( machine, state->atapi_xferlen ); + state_save_register_global( machine, state->atapi_xferbase ); + state_save_register_global( machine, state->atapi_cdata_wait ); + state_save_register_global( machine, state->atapi_xfermod ); } static WRITE32_HANDLER( atapi_reset_w ) { + ksys573_state *state = space->machine->driver_data(); + UINT8 *atapi_regs = state->atapi_regs; + verboselog( space->machine, 2, "atapi_reset_w( %08x, %08x, %08x )\n", offset, mem_mask, data ); if (data) @@ -1023,12 +1096,12 @@ static WRITE32_HANDLER( atapi_reset_w ) atapi_regs[ATAPI_REG_COUNTLOW] = 0x14; atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb; - atapi_data_ptr = 0; - atapi_data_len = 0; - atapi_cdata_wait = 0; + state->atapi_data_ptr = 0; + state->atapi_data_len = 0; + state->atapi_cdata_wait = 0; - atapi_xferlen = 0; - atapi_xfermod = 0; + state->atapi_xferlen = 0; + state->atapi_xfermod = 0; } } @@ -1040,30 +1113,31 @@ static void cdrom_dma_read( running_machine *machine, UINT32 n_address, INT32 n_ static void cdrom_dma_write( running_machine *machine, UINT32 n_address, INT32 n_size ) { + ksys573_state *state = machine->driver_data(); + verboselog( machine, 2, "cdrom_dma_write( %08x, %08x )\n", n_address, n_size ); // mame_printf_debug("DMA write: address %08x size %08x\n", n_address, n_size); - atapi_xferbase = n_address; + state->atapi_xferbase = n_address; - verboselog( machine, 2, "atapi_xfer_end: %d %d\n", atapi_xferlen, atapi_xfermod ); + verboselog( machine, 2, "atapi_xfer_end: %d %d\n", state->atapi_xferlen, state->atapi_xfermod ); // set a transfer complete timer (Note: CYCLES_PER_SECTOR can't be lower than 2000 or the BIOS ends up "out of order") - timer_adjust_oneshot(atapi_timer, machine->device("maincpu")->cycles_to_attotime((ATAPI_CYCLES_PER_SECTOR * (atapi_xferlen/2048))), 0); + timer_adjust_oneshot(state->atapi_timer, machine->device("maincpu")->cycles_to_attotime((ATAPI_CYCLES_PER_SECTOR * (state->atapi_xferlen/2048))), 0); } -static UINT32 m_n_security_control; -static void (*security_callback)( running_machine *machine, int data ); - static WRITE32_HANDLER( security_w ) { + ksys573_state *state = space->machine->driver_data(); + int security_cart_number = state->security_cart_number; running_machine *machine = space->machine; - COMBINE_DATA( &m_n_security_control ); + COMBINE_DATA( &state->m_n_security_control ); verboselog( space->machine, 2, "security_w( %08x, %08x, %08x )\n", offset, mem_mask, data ); if( ACCESSING_BITS_0_15 ) { - switch( chiptype[ security_cart_number ] ) + switch( state->chiptype[ security_cart_number ] ) { case 1: x76f041_sda_write( machine, security_cart_number, ( data >> 0 ) & 1 ); @@ -1086,37 +1160,40 @@ static WRITE32_HANDLER( security_w ) break; } - if( has_ds2401[ security_cart_number ] ) + if( state->has_ds2401[ security_cart_number ] ) { ds2401_write( machine, security_cart_number, !( ( data >> 4 ) & 1 ) ); } - if( security_callback != NULL ) + if( state->security_callback != NULL ) { - security_callback( machine, data & 0xff ); + (*state->security_callback)( machine, data & 0xff ); } } } static READ32_HANDLER( security_r ) { - UINT32 data = m_n_security_control; + ksys573_state *state = space->machine->driver_data(); + + UINT32 data = state->m_n_security_control; verboselog( space->machine, 2, "security_r( %08x, %08x ) %08x\n", offset, mem_mask, data ); return data; } static READ32_HANDLER( flash_r ) { + ksys573_state *state = space->machine->driver_data(); UINT32 data = 0; - if( flash_bank < 0 ) + if( state->flash_bank < 0 ) { - mame_printf_debug( "%08x: flash_r( %08x, %08x ) no bank selected %08x\n", cpu_get_pc(space->cpu), offset, mem_mask, control ); + mame_printf_debug( "%08x: flash_r( %08x, %08x ) no bank selected %08x\n", cpu_get_pc(space->cpu), offset, mem_mask, state->control ); data = 0xffffffff; } else { - fujitsu_29f016a_device **flash_base = &flash_device[flash_bank >> 8][flash_bank & 0xff]; + fujitsu_29f016a_device **flash_base = &state->flash_device[state->flash_bank >> 8][state->flash_bank & 0xff]; int adr = offset * 2; if( ACCESSING_BITS_0_7 ) @@ -1144,15 +1221,17 @@ static READ32_HANDLER( flash_r ) static WRITE32_HANDLER( flash_w ) { + ksys573_state *state = space->machine->driver_data(); + verboselog( space->machine, 2, "flash_w( %08x, %08x, %08x\n", offset, mem_mask, data ); - if( flash_bank < 0 ) + if( state->flash_bank < 0 ) { - mame_printf_debug( "%08x: flash_w( %08x, %08x, %08x ) no bank selected %08x\n", cpu_get_pc(space->cpu), offset, mem_mask, data, control ); + mame_printf_debug( "%08x: flash_w( %08x, %08x, %08x ) no bank selected %08x\n", cpu_get_pc(space->cpu), offset, mem_mask, data, state->control ); } else { - fujitsu_29f016a_device **flash_base = &flash_device[flash_bank >> 8][flash_bank & 0xff]; + fujitsu_29f016a_device **flash_base = &state->flash_device[state->flash_bank >> 8][state->flash_bank & 0xff]; int adr = offset * 2; if( ACCESSING_BITS_0_7 ) @@ -1176,39 +1255,26 @@ static WRITE32_HANDLER( flash_w ) /* Root Counters */ -static emu_timer *m_p_timer_root[ 3 ]; -static UINT16 m_p_n_root_count[ 3 ]; -static UINT16 m_p_n_root_mode[ 3 ]; -static UINT16 m_p_n_root_target[ 3 ]; -static UINT64 m_p_n_root_start[ 3 ]; - -#define RC_STOP ( 0x01 ) -#define RC_RESET ( 0x04 ) /* guess */ -#define RC_COUNTTARGET ( 0x08 ) -#define RC_IRQTARGET ( 0x10 ) -#define RC_IRQOVERFLOW ( 0x20 ) -#define RC_REPEAT ( 0x40 ) -#define RC_CLC ( 0x100 ) -#define RC_DIV ( 0x200 ) - static UINT64 psxcpu_gettotalcycles( running_machine *machine ) { /* TODO: should return the start of the current tick. */ return machine->firstcpu->total_cycles() * 2; } -static int root_divider( int n_counter ) +static int root_divider( running_machine *machine, int n_counter ) { - if( n_counter == 0 && ( m_p_n_root_mode[ n_counter ] & RC_CLC ) != 0 ) + ksys573_state *state = machine->driver_data(); + + if( n_counter == 0 && ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_CLC ) != 0 ) { /* TODO: pixel clock, probably based on resolution */ return 5; } - else if( n_counter == 1 && ( m_p_n_root_mode[ n_counter ] & RC_CLC ) != 0 ) + else if( n_counter == 1 && ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_CLC ) != 0 ) { return 2150; } - else if( n_counter == 2 && ( m_p_n_root_mode[ n_counter ] & RC_DIV ) != 0 ) + else if( n_counter == 2 && ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_DIV ) != 0 ) { return 8; } @@ -1217,74 +1283,81 @@ static int root_divider( int n_counter ) static UINT16 root_current( running_machine *machine, int n_counter ) { - if( ( m_p_n_root_mode[ n_counter ] & RC_STOP ) != 0 ) + ksys573_state *state = machine->driver_data(); + + if( ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_STOP ) != 0 ) { - return m_p_n_root_count[ n_counter ]; + return state->m_p_n_root_count[ n_counter ]; } else { UINT64 n_current; - n_current = psxcpu_gettotalcycles(machine) - m_p_n_root_start[ n_counter ]; - n_current /= root_divider( n_counter ); - n_current += m_p_n_root_count[ n_counter ]; + n_current = psxcpu_gettotalcycles(machine) - state->m_p_n_root_start[ n_counter ]; + n_current /= root_divider( machine, n_counter ); + n_current += state->m_p_n_root_count[ n_counter ]; if( n_current > 0xffff ) { /* TODO: use timer for wrap on 0x10000. */ - m_p_n_root_count[ n_counter ] = n_current; - m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(machine); + state->m_p_n_root_count[ n_counter ] = n_current; + state->m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(machine); } return n_current; } } -static int root_target( int n_counter ) +static int root_target( running_machine *machine, int n_counter ) { - if( ( m_p_n_root_mode[ n_counter ] & RC_COUNTTARGET ) != 0 || - ( m_p_n_root_mode[ n_counter ] & RC_IRQTARGET ) != 0 ) + ksys573_state *state = machine->driver_data(); + + if( ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_COUNTTARGET ) != 0 || + ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_IRQTARGET ) != 0 ) { - return m_p_n_root_target[ n_counter ]; + return state->m_p_n_root_target[ n_counter ]; } return 0x10000; } static void root_timer_adjust( running_machine *machine, int n_counter ) { - if( ( m_p_n_root_mode[ n_counter ] & RC_STOP ) != 0 ) + ksys573_state *state = machine->driver_data(); + + if( ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_STOP ) != 0 ) { - timer_adjust_oneshot( m_p_timer_root[ n_counter ], attotime_never, n_counter); + timer_adjust_oneshot( state->m_p_timer_root[ n_counter ], attotime_never, n_counter); } else { int n_duration; - n_duration = root_target( n_counter ) - root_current( machine, n_counter ); + n_duration = root_target( machine, n_counter ) - root_current( machine, n_counter ); if( n_duration < 1 ) { n_duration += 0x10000; } - n_duration *= root_divider( n_counter ); + n_duration *= root_divider( machine, n_counter ); - timer_adjust_oneshot( m_p_timer_root[ n_counter ], attotime_mul(ATTOTIME_IN_HZ(33868800), n_duration), n_counter); + timer_adjust_oneshot( state->m_p_timer_root[ n_counter ], attotime_mul(ATTOTIME_IN_HZ(33868800), n_duration), n_counter); } } static TIMER_CALLBACK( root_finished ) { + ksys573_state *state = machine->driver_data(); int n_counter = param; -// if( ( m_p_n_root_mode[ n_counter ] & RC_COUNTTARGET ) != 0 ) +// if( ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_COUNTTARGET ) != 0 ) { - /* TODO: wrap should be handled differently as RC_COUNTTARGET & RC_IRQTARGET don't have to be the same. */ - m_p_n_root_count[ n_counter ] = 0; - m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(machine); + /* TODO: wrap should be handled differently as PSX_RC_COUNTTARGET & PSX_RC_IRQTARGET don't have to be the same. */ + state->m_p_n_root_count[ n_counter ] = 0; + state->m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(machine); } - if( ( m_p_n_root_mode[ n_counter ] & RC_REPEAT ) != 0 ) + if( ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_REPEAT ) != 0 ) { root_timer_adjust( machine, n_counter ); } - if( ( m_p_n_root_mode[ n_counter ] & RC_IRQOVERFLOW ) != 0 || - ( m_p_n_root_mode[ n_counter ] & RC_IRQTARGET ) != 0 ) + if( ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_IRQOVERFLOW ) != 0 || + ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_IRQTARGET ) != 0 ) { psx_irq_set( machine, 0x10 << n_counter ); } @@ -1292,6 +1365,7 @@ static TIMER_CALLBACK( root_finished ) static WRITE32_HANDLER( k573_counter_w ) { + ksys573_state *state = space->machine->driver_data(); int n_counter; n_counter = offset / 4; @@ -1299,29 +1373,31 @@ static WRITE32_HANDLER( k573_counter_w ) switch( offset % 4 ) { case 0: - m_p_n_root_count[ n_counter ] = data; - m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(space->machine); + state->m_p_n_root_count[ n_counter ] = data; + state->m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(space->machine); break; case 1: - m_p_n_root_count[ n_counter ] = root_current( space->machine, n_counter ); - m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(space->machine); - m_p_n_root_mode[ n_counter ] = data; + state->m_p_n_root_count[ n_counter ] = root_current( space->machine, n_counter ); + state->m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(space->machine); + state->m_p_n_root_mode[ n_counter ] = data; - if( ( m_p_n_root_mode[ n_counter ] & RC_RESET ) != 0 ) + if( ( state->m_p_n_root_mode[ n_counter ] & PSX_RC_RESET ) != 0 ) { /* todo: check this is correct */ - m_p_n_root_count[ n_counter ] = 0; - m_p_n_root_mode[ n_counter ] &= ~( RC_STOP | RC_RESET ); + state->m_p_n_root_count[ n_counter ] = 0; + state->m_p_n_root_mode[ n_counter ] &= ~( PSX_RC_STOP | PSX_RC_RESET ); } -// if( ( data & 0xfca6 ) != 0 || -// ( ( data & 0x0100 ) != 0 && n_counter != 0 && n_counter != 1 ) || -// ( ( data & 0x0200 ) != 0 && n_counter != 2 ) ) -// { -// printf( "mode %d 0x%04x\n", n_counter, data & 0xfca6 ); -// } +#if 0 + if( ( data & 0xfca6 ) != 0 || + ( ( data & 0x0100 ) != 0 && n_counter != 0 && n_counter != 1 ) || + ( ( data & 0x0200 ) != 0 && n_counter != 2 ) ) + { + printf( "mode %d 0x%04x\n", n_counter, data & 0xfca6 ); + } +#endif break; case 2: - m_p_n_root_target[ n_counter ] = data; + state->m_p_n_root_target[ n_counter ] = data; break; default: return; @@ -1332,6 +1408,7 @@ static WRITE32_HANDLER( k573_counter_w ) static READ32_HANDLER( k573_counter_r ) { + ksys573_state *state = space->machine->driver_data(); int n_counter; UINT32 data; @@ -1343,10 +1420,10 @@ static READ32_HANDLER( k573_counter_r ) data = root_current( space->machine, n_counter ); break; case 1: - data = m_p_n_root_mode[ n_counter ]; + data = state->m_p_n_root_mode[ n_counter ]; break; case 2: - data = m_p_n_root_target[ n_counter ]; + data = state->m_p_n_root_target[ n_counter ]; break; default: return 0; @@ -1355,7 +1432,7 @@ static READ32_HANDLER( k573_counter_r ) } static ADDRESS_MAP_START( konami573_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") AM_BASE(&g_p_n_psxram) AM_SIZE(&g_n_psxramsize) /* ram */ + AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") /* ram */ AM_RANGE(0x1f000000, 0x1f3fffff) AM_READWRITE( flash_r, flash_w ) AM_RANGE(0x1f400000, 0x1f400003) AM_READ_PORT( "IN0" ) AM_WRITE_PORT( "OUT0" ) AM_RANGE(0x1f400004, 0x1f400007) AM_READ( jamma_r ) @@ -1397,28 +1474,31 @@ ADDRESS_MAP_END static void flash_init( running_machine *machine ) { // find onboard flash devices + ksys573_state *state = machine->driver_data(); astring tempstr; for (int index = 0; index < 8; index++) - flash_device[0][index] = machine->device(tempstr.format("onboard.%d", index)); + state->flash_device[0][index] = machine->device(tempstr.format("onboard.%d", index)); // find pccard flash devices for (int card = 1; card <= 4; card++) for (int index = 0; index < 16; index++) - flash_device[card][index] = machine->device(tempstr.format("pccard%d.%d", card, index)); + state->flash_device[card][index] = machine->device(tempstr.format("pccard%d.%d", card, index)); - state_save_register_global(machine, flash_bank ); - state_save_register_global(machine, control ); + state_save_register_global( machine, state->flash_bank ); + state_save_register_global( machine, state->control ); } -static void *atapi_get_device(void) +static void *atapi_get_device(running_machine *machine) { + ksys573_state *state = machine->driver_data(); void *ret; - SCSIGetDevice( inserted_cdrom, &ret ); + SCSIGetDevice( state->inserted_cdrom, &ret ); return ret; } static void security_cart_init( running_machine *machine, int cart, const char *eeprom_region, const char *ds2401_region ) { + ksys573_state *state = machine->driver_data(); UINT8 *eeprom_rom = memory_region( machine, eeprom_region ); int eeprom_length = memory_region_length( machine, eeprom_region ); UINT8 *ds2401_rom = memory_region( machine, ds2401_region ); @@ -1429,15 +1509,15 @@ static void security_cart_init( running_machine *machine, int cart, const char * { case 0x224: x76f041_init( machine, cart, eeprom_rom ); - chiptype[ cart ] = 1; + state->chiptype[ cart ] = 1; switch( cart ) { case 0: - nvram_handler_security_cart_0 = NVRAM_HANDLER_NAME(x76f041_0); + state->nvram_handler_security_cart_0 = NVRAM_HANDLER_NAME(x76f041_0); break; case 1: - nvram_handler_security_cart_1 = NVRAM_HANDLER_NAME(x76f041_1); + state->nvram_handler_security_cart_1 = NVRAM_HANDLER_NAME(x76f041_1); break; } @@ -1445,15 +1525,15 @@ static void security_cart_init( running_machine *machine, int cart, const char * case 0x84: x76f100_init( machine, cart, eeprom_rom ); - chiptype[ cart ] = 2; + state->chiptype[ cart ] = 2; switch( cart ) { case 0: - nvram_handler_security_cart_0 = NVRAM_HANDLER_NAME(x76f100_0); + state->nvram_handler_security_cart_0 = NVRAM_HANDLER_NAME(x76f100_0); break; case 1: - nvram_handler_security_cart_1 = NVRAM_HANDLER_NAME(x76f100_1); + state->nvram_handler_security_cart_1 = NVRAM_HANDLER_NAME(x76f100_1); break; } @@ -1461,15 +1541,15 @@ static void security_cart_init( running_machine *machine, int cart, const char * case 0x1014: zs01_init( machine, cart, eeprom_rom, NULL, NULL, ds2401_rom ); - chiptype[ cart ] = 3; + state->chiptype[ cart ] = 3; switch( cart ) { case 0: - nvram_handler_security_cart_0 = NVRAM_HANDLER_NAME(zs01_0); + state->nvram_handler_security_cart_0 = NVRAM_HANDLER_NAME(zs01_0); break; case 1: - nvram_handler_security_cart_1 = NVRAM_HANDLER_NAME(zs01_1); + state->nvram_handler_security_cart_1 = NVRAM_HANDLER_NAME(zs01_1); break; } @@ -1482,58 +1562,61 @@ static void security_cart_init( running_machine *machine, int cart, const char * } else { - chiptype[ cart ] = 0; + state->chiptype[ cart ] = 0; } - if( chiptype[ cart ] != 3 && ds2401_rom != NULL ) + if( state->chiptype[ cart ] != 3 && ds2401_rom != NULL ) { ds2401_init( machine, cart, ds2401_rom ); - has_ds2401[ cart ] = 1; + state->has_ds2401[ cart ] = 1; } else { - has_ds2401[ cart ] = 0; + state->has_ds2401[ cart ] = 0; } } static DRIVER_INIT( konami573 ) { + ksys573_state *state = machine->driver_data(); int i; psx_driver_init(machine); atapi_init(machine); - psx_dma_install_read_handler(5, cdrom_dma_read); - psx_dma_install_write_handler(5, cdrom_dma_write); + psx_dma_install_read_handler(machine, 5, cdrom_dma_read); + psx_dma_install_write_handler(machine, 5, cdrom_dma_write); for (i = 0; i < 3; i++) { - m_p_timer_root[i] = timer_alloc(machine, root_finished, NULL); + state->m_p_timer_root[i] = timer_alloc(machine, root_finished, NULL); } - state_save_register_global(machine, m_n_security_control ); + state_save_register_global( machine, state->m_n_security_control ); security_cart_init( machine, 0, "user2", "user9" ); security_cart_init( machine, 1, "user8", "user10" ); - state_save_register_item_array( machine, "KSYS573", NULL, 0, m_p_n_root_count ); - state_save_register_item_array( machine, "KSYS573", NULL, 0, m_p_n_root_mode ); - state_save_register_item_array( machine, "KSYS573", NULL, 0, m_p_n_root_target ); - state_save_register_item_array( machine, "KSYS573", NULL, 0, m_p_n_root_start ); + state_save_register_item_array( machine, "KSYS573", NULL, 0, state->m_p_n_root_count ); + state_save_register_item_array( machine, "KSYS573", NULL, 0, state->m_p_n_root_mode ); + state_save_register_item_array( machine, "KSYS573", NULL, 0, state->m_p_n_root_target ); + state_save_register_item_array( machine, "KSYS573", NULL, 0, state->m_p_n_root_start ); flash_init(machine); } static MACHINE_RESET( konami573 ) { + ksys573_state *state = machine->driver_data(); + psx_machine_init(machine); - if( chiptype[ 0 ] != 0 ) + if( state->chiptype[ 0 ] != 0 ) { /* security cart */ psx_sio_input( machine, 1, PSX_SIO_IN_DSR, PSX_SIO_IN_DSR ); } - flash_bank = -1; + state->flash_bank = -1; } static void spu_irq(running_device *device, UINT32 data) @@ -1543,7 +1626,6 @@ static void spu_irq(running_device *device, UINT32 data) static const psx_spu_interface konami573_psxspu_interface = { - &g_p_n_psxram, spu_irq, psx_dma_install_read_handler, psx_dma_install_write_handler @@ -1551,37 +1633,41 @@ static const psx_spu_interface konami573_psxspu_interface = static void update_mode( running_machine *machine ) { - int cart = input_port_read(machine, "CART" ); - int cd = input_port_read(machine, "CD" ); - static SCSIInstance *new_cdrom; + ksys573_state *state = machine->driver_data(); + int cart = input_port_read(machine, "CART"); + int cd = input_port_read( machine, "CD" ); + SCSIInstance *new_cdrom; - if( chiptype[ 1 ] != 0 ) + if( state->chiptype[ 1 ] != 0 ) { - security_cart_number = cart; + state->security_cart_number = cart; } else { - security_cart_number = 0; + state->security_cart_number = 0; } - if( available_cdroms[ 1 ] != NULL ) + if( state->available_cdroms[ 1 ] != NULL ) { - new_cdrom = available_cdroms[ cd ]; + new_cdrom = state->available_cdroms[ cd ]; } else { - new_cdrom = available_cdroms[ 0 ]; + new_cdrom = state->available_cdroms[ 0 ]; } - if( inserted_cdrom != new_cdrom ) + if( state->inserted_cdrom != new_cdrom ) { - inserted_cdrom = new_cdrom; - cdda_set_cdrom(machine->device("cdda"), atapi_get_device()); + state->inserted_cdrom = new_cdrom; + cdda_set_cdrom(machine->device("cdda"), atapi_get_device(machine)); } } static INTERRUPT_GEN( sys573_vblank ) { + ksys573_state *state = device->machine->driver_data(); + UINT32 *p_n_psxram = state->p_n_psxram; + update_mode(device->machine); if( strcmp( device->machine->gamedrv->name, "ddr2ml" ) == 0 ) @@ -1589,10 +1675,10 @@ static INTERRUPT_GEN( sys573_vblank ) /* patch out security-plate error */ /* 8001f850: jal $8003221c */ - if( g_p_n_psxram[ 0x1f850 / 4 ] == 0x0c00c887 ) + if( p_n_psxram[ 0x1f850 / 4 ] == 0x0c00c887 ) { /* 8001f850: j $8001f888 */ - g_p_n_psxram[ 0x1f850 / 4 ] = 0x08007e22; + p_n_psxram[ 0x1f850 / 4 ] = 0x08007e22; } } @@ -1699,9 +1785,6 @@ Analogue I/O board */ -static UINT8 gx700pwbf_output_data[ 4 ]; -static void (*gx700pwfbf_output_callback)( running_machine *machine, int offset, int data ); - static READ32_HANDLER( gx700pwbf_io_r ) { UINT32 data = 0; @@ -1735,21 +1818,23 @@ static READ32_HANDLER( gx700pwbf_io_r ) static void gx700pwbf_output( running_machine *machine, int offset, UINT8 data ) { - if( gx700pwfbf_output_callback != NULL ) + ksys573_state *state = machine->driver_data(); + + if( state->gx700pwfbf_output_callback != NULL ) { int i; static const int shift[] = { 7, 6, 1, 0, 5, 4, 3, 2 }; for( i = 0; i < 8; i++ ) { - int oldbit = ( gx700pwbf_output_data[ offset ] >> shift[ i ] ) & 1; + int oldbit = ( state->gx700pwbf_output_data[ offset ] >> shift[ i ] ) & 1; int newbit = ( data >> shift[ i ] ) & 1; if( oldbit != newbit ) { - gx700pwfbf_output_callback( machine, ( offset * 8 ) + i, newbit ); + (*state->gx700pwfbf_output_callback)( machine, ( offset * 8 ) + i, newbit ); } } } - gx700pwbf_output_data[ offset ] = data; + state->gx700pwbf_output_data[ offset ] = data; } static WRITE32_HANDLER( gx700pwbf_io_w ) @@ -1795,13 +1880,15 @@ static WRITE32_HANDLER( gx700pwbf_io_w ) static void gx700pwfbf_init( running_machine *machine, void (*output_callback_func)( running_machine *machine, int offset, int data ) ) { - memset( gx700pwbf_output_data, 0, sizeof( gx700pwbf_output_data ) ); + ksys573_state *state = machine->driver_data(); - gx700pwfbf_output_callback = output_callback_func; + memset( state->gx700pwbf_output_data, 0, sizeof( state->gx700pwbf_output_data ) ); + + state->gx700pwfbf_output_callback = output_callback_func; memory_install_readwrite32_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f640000, 0x1f6400ff, 0, 0, gx700pwbf_io_r, gx700pwbf_io_w ); - state_save_register_global_array(machine, gx700pwbf_output_data ); + state_save_register_global_array( machine, state->gx700pwbf_output_data ); } /* @@ -1812,20 +1899,9 @@ DDR Stage Multiplexor */ -static UINT32 stage_mask; - #define DDR_STAGE_IDLE ( 0 ) #define DDR_STAGE_INIT ( 1 ) -static struct -{ - int DO; - int clk; - int shift; - int state; - int bit; -} stage[ 2 ]; - static const int mask[] = { 0, 6, 2, 4, @@ -1836,61 +1912,67 @@ static const int mask[] = 0, 4, 0, 6 }; -static void gn845pwbb_do_w( int offset, int data ) +static void gn845pwbb_do_w( running_machine *machine, int offset, int data ) { - stage[ offset ].DO = !data; + ksys573_state *state = machine->driver_data(); + + state->stage[ offset ].DO = !data; } static void gn845pwbb_clk_w( running_machine *machine, int offset, int data ) { + ksys573_state *state = machine->driver_data(); int clk = !data; - if( clk != stage[ offset ].clk ) + if( clk != state->stage[ offset ].clk ) { - stage[ offset ].clk = clk; + state->stage[ offset ].clk = clk; if( clk ) { - stage[ offset ].shift = ( stage[ offset ].shift >> 1 ) | ( stage[ offset ].DO << 12 ); + state->stage[ offset ].shift = ( state->stage[ offset ].shift >> 1 ) | ( state->stage[ offset ].DO << 12 ); - switch( stage[ offset ].state ) + switch( state->stage[ offset ].state ) { case DDR_STAGE_IDLE: - if( stage[ offset ].shift == 0xc90 ) + if( state->stage[ offset ].shift == 0xc90 ) { - stage[ offset ].state = DDR_STAGE_INIT; - stage[ offset ].bit = 0; - stage_mask = 0xfffff9f9; + state->stage[ offset ].state = DDR_STAGE_INIT; + state->stage[ offset ].bit = 0; + state->stage_mask = 0xfffff9f9; } break; case DDR_STAGE_INIT: - stage[ offset ].bit++; - if( stage[ offset ].bit < 22 ) + state->stage[ offset ].bit++; + if( state->stage[ offset ].bit < 22 ) { - int a = ( ( ( ( ~0x06 ) | mask[ stage[ 0 ].bit ] ) & 0xff ) << 8 ); - int b = ( ( ( ( ~0x06 ) | mask[ stage[ 1 ].bit ] ) & 0xff ) << 0 ); + int a = ( ( ( ( ~0x06 ) | mask[ state->stage[ 0 ].bit ] ) & 0xff ) << 8 ); + int b = ( ( ( ( ~0x06 ) | mask[ state->stage[ 1 ].bit ] ) & 0xff ) << 0 ); - stage_mask = 0xffff0000 | a | b; + state->stage_mask = 0xffff0000 | a | b; } else { - stage[ offset ].bit = 0; - stage[ offset ].state = DDR_STAGE_IDLE; + state->stage[ offset ].bit = 0; + state->stage[ offset ].state = DDR_STAGE_IDLE; - stage_mask = 0xffffffff; + state->stage_mask = 0xffffffff; } break; } } } - verboselog( machine, 2, "stage: %dp data clk=%d state=%d d0=%d shift=%08x bit=%d stage_mask=%08x\n", offset + 1, clk, stage[ offset ].state, stage[ offset ].DO, stage[ offset ].shift, stage[ offset ].bit, stage_mask ); + verboselog( machine, 2, "stage: %dp data clk=%d state=%d d0=%d shift=%08x bit=%d stage_mask=%08x\n", offset + 1, clk, + state->stage[ offset ].state, state->stage[ offset ].DO, state->stage[ offset ].shift, state->stage[ offset ].bit, state->stage_mask ); } static CUSTOM_INPUT( gn845pwbb_read ) { - return input_port_read(field->port->machine, "STAGE" ) & stage_mask; + ksys573_state *state = field->port->machine->driver_data(); + + return input_port_read(field->port->machine, "STAGE") & state->stage_mask; } static void gn845pwbb_output_callback( running_machine *machine, int offset, int data ) @@ -1914,7 +1996,7 @@ static void gn845pwbb_output_callback( running_machine *machine, int offset, int break; case 4: - gn845pwbb_do_w( 0, !data ); + gn845pwbb_do_w( machine, 0, !data ); break; case 7: @@ -1938,7 +2020,7 @@ static void gn845pwbb_output_callback( running_machine *machine, int offset, int break; case 12: - gn845pwbb_do_w( 1, !data ); + gn845pwbb_do_w( machine, 1, !data ); break; case 15: @@ -1982,12 +2064,14 @@ static void gn845pwbb_output_callback( running_machine *machine, int offset, int static DRIVER_INIT( ddr ) { + ksys573_state *state = machine->driver_data(); + DRIVER_INIT_CALL(konami573); - stage_mask = 0xffffffff; + state->stage_mask = 0xffffffff; gx700pwfbf_init( machine, gn845pwbb_output_callback ); - state_save_register_global(machine, stage_mask ); + state_save_register_global( machine, state->stage_mask ); } /* @@ -2053,13 +2137,11 @@ static const UINT8 ds2401_xid[] = 0x3d, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x01 }; -static UINT32 gx894_ram_write_offset; -static UINT32 gx894_ram_read_offset; -static UINT16 *gx894_ram; - static READ32_HANDLER( gx894pwbba_r ) { + ksys573_state *state = space->machine->driver_data(); UINT32 data = 0; + switch( offset ) { case 0x00: @@ -2086,9 +2168,9 @@ static READ32_HANDLER( gx894pwbba_r ) case 0x2d: if( ACCESSING_BITS_0_15 ) { - data |= gx894_ram[ gx894_ram_read_offset / 2 ]; -// printf( "reading %08x %04x\r", gx894_ram_read_offset, gx894_ram[ gx894_ram_read_offset / 2 ] ); - gx894_ram_read_offset += 2; + data |= state->gx894_ram[ state->gx894_ram_read_offset / 2 ]; +// printf( "reading %08x %04x\r", state->gx894_ram_read_offset, state->gx894_ram[ state->gx894_ram_read_offset / 2 ] ); + state->gx894_ram_read_offset += 2; } if( ACCESSING_BITS_16_31 ) { @@ -2159,9 +2241,8 @@ static READ32_HANDLER( gx894pwbba_r ) return data; } -static char *binary( UINT32 data ) +static char *binary( char *s, UINT32 data ) { - static char s[ 33 ]; int i; for( i = 0; i < 32; i++ ) { @@ -2171,33 +2252,32 @@ static char *binary( UINT32 data ) return s; } -static UINT32 a,b,c,d; - -static UINT16 gx894pwbba_output_data[ 8 ]; -static void (*gx894pwbba_output_callback)( running_machine *machine, int offset, int data ); - static void gx894pwbba_output( running_machine *machine, int offset, UINT8 data ) { - if( gx894pwbba_output_callback != NULL ) + ksys573_state *state = machine->driver_data(); + + if( state->gx894pwbba_output_callback != NULL ) { int i; static const int shift[] = { 0, 2, 3, 1 }; for( i = 0; i < 4; i++ ) { - int oldbit = ( gx894pwbba_output_data[ offset ] >> shift[ i ] ) & 1; + int oldbit = ( state->gx894pwbba_output_data[ offset ] >> shift[ i ] ) & 1; int newbit = ( data >> shift[ i ] ) & 1; if( oldbit != newbit ) { - gx894pwbba_output_callback( machine, ( offset * 4 ) + i, newbit ); + (*state->gx894pwbba_output_callback)( machine, ( offset * 4 ) + i, newbit ); } } } - gx894pwbba_output_data[ offset ] = data; + state->gx894pwbba_output_data[ offset ] = data; } static WRITE32_HANDLER( gx894pwbba_w ) { - UINT32 olda=a,oldb=b,oldc=c,oldd=d; + ksys573_state *state = space->machine->driver_data(); + char buff[33]; + UINT32 olda=state->a,oldb=state->b,oldc=state->c,oldd=state->d; // printf( "gx894pwbba_w( %08x, %08x, %08x )\n", offset, mem_mask, data ); @@ -2206,7 +2286,7 @@ static WRITE32_HANDLER( gx894pwbba_w ) return; } - verboselog( space->machine, 2, "gx894pwbba_w( %08x, %08x, %08x) %s\n", offset, mem_mask, data, binary( data ) ); + verboselog( space->machine, 2, "gx894pwbba_w( %08x, %08x, %08x) %s\n", offset, mem_mask, data, binary( buff, data ) ); switch( offset ) { @@ -2216,33 +2296,33 @@ static WRITE32_HANDLER( gx894pwbba_w ) case 0x2c: if( ACCESSING_BITS_0_15 ) { - gx894_ram_write_offset &= 0x0000ffff; - gx894_ram_write_offset |= ( data & 0x0000ffff ) << 16; + state->gx894_ram_write_offset &= 0x0000ffff; + state->gx894_ram_write_offset |= ( data & 0x0000ffff ) << 16; } if( ACCESSING_BITS_16_31 ) { - gx894_ram_write_offset &= 0xffff0000; - gx894_ram_write_offset |= ( data & 0xffff0000 ) >> 16; + state->gx894_ram_write_offset &= 0xffff0000; + state->gx894_ram_write_offset |= ( data & 0xffff0000 ) >> 16; } break; case 0x2d: if( ACCESSING_BITS_0_15 ) { - gx894_ram[ gx894_ram_write_offset / 2 ] = data & 0xffff; -// printf( "writing %08x %04x\r", gx894_ram_write_offset, gx894_ram[ gx894_ram_write_offset / 2 ] ); - gx894_ram_write_offset += 2; + state->gx894_ram[ state->gx894_ram_write_offset / 2 ] = data & 0xffff; +// printf( "writing %08x %04x\r", state->gx894_ram_write_offset, state->gx894_ram[ state->gx894_ram_write_offset / 2 ] ); + state->gx894_ram_write_offset += 2; } if( ACCESSING_BITS_16_31 ) { - gx894_ram_read_offset &= 0x0000ffff; - gx894_ram_read_offset |= ( data & 0xffff0000 ) << 0; + state->gx894_ram_read_offset &= 0x0000ffff; + state->gx894_ram_read_offset |= ( data & 0xffff0000 ) << 0; } break; case 0x2e: if( ACCESSING_BITS_0_15 ) { - gx894_ram_read_offset &= 0xffff0000; - gx894_ram_read_offset |= ( data & 0x0000ffff ) >> 0; + state->gx894_ram_read_offset &= 0xffff0000; + state->gx894_ram_read_offset |= ( data & 0x0000ffff ) >> 0; } if( ACCESSING_BITS_16_31 ) { @@ -2258,7 +2338,7 @@ static WRITE32_HANDLER( gx894pwbba_w ) { gx894pwbba_output( space->machine, 1, ( data >> 12 ) & 0xf ); } - COMBINE_DATA( &a ); + COMBINE_DATA( &state->a ); break; case 0x39: if( ACCESSING_BITS_16_31 ) @@ -2269,7 +2349,7 @@ static WRITE32_HANDLER( gx894pwbba_w ) { gx894pwbba_output( space->machine, 3, ( data >> 12 ) & 0xf ); } - COMBINE_DATA( &b ); + COMBINE_DATA( &state->b ); break; case 0x3b: if( ACCESSING_BITS_16_31 ) @@ -2285,19 +2365,15 @@ static WRITE32_HANDLER( gx894pwbba_w ) /* 14 */ /* 15 */ - static int s = 0; - static int b = 0; - static int o = 0; - /* fpga */ - s = ( s >> 1 ) | ( ( data & 0x8000 ) >> 8 ); - b++; - if( b == 8 ) + state->s = ( state->s >> 1 ) | ( ( data & 0x8000 ) >> 8 ); + state->f++; + if( state->f == 8 ) { // printf( "%04x %02x\n", o, s ); - c = 0; - b = 0; - o++; + state->c = 0; + state->f = 0; + state->o++; } } @@ -2305,7 +2381,7 @@ static WRITE32_HANDLER( gx894pwbba_w ) { gx894pwbba_output( space->machine, 4, ( data >> 28 ) & 0xf ); } - COMBINE_DATA( &c ); + COMBINE_DATA( &state->c ); break; case 0x3f: if( ACCESSING_BITS_16_31 ) @@ -2316,13 +2392,13 @@ static WRITE32_HANDLER( gx894pwbba_w ) { gx894pwbba_output( space->machine, 5, ( data >> 12 ) & 0xf ); } - COMBINE_DATA( &d ); + COMBINE_DATA( &state->d ); break; default: // printf( "write offset %08x\n", offset ); break; } - if( a != olda || b != oldb || c != oldc || d != oldd ) + if( state->a != olda || state->b != oldb || state->c != oldc || state->d != oldd ) { // printf( "%08x %08x %08x %08x\n", a, b, c, d ); } @@ -2330,20 +2406,21 @@ static WRITE32_HANDLER( gx894pwbba_w ) static void gx894pwbba_init( running_machine *machine, void (*output_callback_func)( running_machine *machine, int offset, int data ) ) { + ksys573_state *state = machine->driver_data(); int gx894_ram_size = 24 * 1024 * 1024; - gx894pwbba_output_callback = output_callback_func; + state->gx894pwbba_output_callback = output_callback_func; memory_install_readwrite32_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f640000, 0x1f6400ff, 0, 0, gx894pwbba_r, gx894pwbba_w ); - gx894_ram_write_offset = 0; - gx894_ram_read_offset = 0; - gx894_ram = auto_alloc_array(machine, UINT16, gx894_ram_size/2); + state->gx894_ram_write_offset = 0; + state->gx894_ram_read_offset = 0; + state->gx894_ram = auto_alloc_array( machine, UINT16, gx894_ram_size/2 ); ds2401_init( machine, 2, ds2401_xid ); /* todo: load this from roms */ - state_save_register_global_array(machine, gx894pwbba_output_data ); - state_save_register_global_pointer(machine, gx894_ram, gx894_ram_size / 4 ); + state_save_register_global_array( machine, state->gx894pwbba_output_data ); + state_save_register_global_pointer( machine, state->gx894_ram, gx894_ram_size / 4 ); } /* ddr digital */ @@ -2661,50 +2738,47 @@ static DRIVER_INIT( dmx ) /* salary man champ */ -static int salarymc_lamp_bits; -static int salarymc_lamp_shift; -static int salarymc_lamp_clk; - static void salarymc_lamp_callback( running_machine *machine, int data ) { + ksys573_state *state = machine->driver_data(); int d = ( data >> 7 ) & 1; int rst = ( data >> 6 ) & 1; int clk = ( data >> 5 ) & 1; if( rst ) { - salarymc_lamp_bits = 0; - salarymc_lamp_shift = 0; + state->salarymc_lamp_bits = 0; + state->salarymc_lamp_shift = 0; } - if( salarymc_lamp_clk != clk ) + if( state->salarymc_lamp_clk != clk ) { - salarymc_lamp_clk = clk; + state->salarymc_lamp_clk = clk; - if( salarymc_lamp_clk ) + if( state->salarymc_lamp_clk ) { - salarymc_lamp_shift <<= 1; + state->salarymc_lamp_shift <<= 1; - salarymc_lamp_shift |= d; + state->salarymc_lamp_shift |= d; - salarymc_lamp_bits++; - if( salarymc_lamp_bits == 16 ) + state->salarymc_lamp_bits++; + if( state->salarymc_lamp_bits == 16 ) { - if( ( salarymc_lamp_shift & ~0xe38 ) != 0 ) + if( ( state->salarymc_lamp_shift & ~0xe38 ) != 0 ) { - verboselog( machine, 0, "unknown bits in salarymc_lamp_shift %08x\n", salarymc_lamp_shift & ~0xe38 ); + verboselog( machine, 0, "unknown bits in salarymc_lamp_shift %08x\n", state->salarymc_lamp_shift & ~0xe38 ); } - output_set_value( "player 1 red", ( salarymc_lamp_shift >> 11 ) & 1 ); - output_set_value( "player 1 green", ( salarymc_lamp_shift >> 10 ) & 1 ); - output_set_value( "player 1 blue", ( salarymc_lamp_shift >> 9 ) & 1 ); + output_set_value( "player 1 red", ( state->salarymc_lamp_shift >> 11 ) & 1 ); + output_set_value( "player 1 green", ( state->salarymc_lamp_shift >> 10 ) & 1 ); + output_set_value( "player 1 blue", ( state->salarymc_lamp_shift >> 9 ) & 1 ); - output_set_value( "player 2 red", ( salarymc_lamp_shift >> 5 ) & 1 ); - output_set_value( "player 2 green", ( salarymc_lamp_shift >> 4 ) & 1 ); - output_set_value( "player 2 blue", ( salarymc_lamp_shift >> 3 ) & 1 ); + output_set_value( "player 2 red", ( state->salarymc_lamp_shift >> 5 ) & 1 ); + output_set_value( "player 2 green", ( state->salarymc_lamp_shift >> 4 ) & 1 ); + output_set_value( "player 2 blue", ( state->salarymc_lamp_shift >> 3 ) & 1 ); - salarymc_lamp_bits = 0; - salarymc_lamp_shift = 0; + state->salarymc_lamp_bits = 0; + state->salarymc_lamp_shift = 0; } } } @@ -2712,55 +2786,57 @@ static void salarymc_lamp_callback( running_machine *machine, int data ) static DRIVER_INIT( salarymc ) { + ksys573_state *state = machine->driver_data(); + DRIVER_INIT_CALL(konami573); - security_callback = salarymc_lamp_callback; + state->security_callback = salarymc_lamp_callback; - state_save_register_global(machine, salarymc_lamp_bits ); - state_save_register_global(machine, salarymc_lamp_shift ); - state_save_register_global(machine, salarymc_lamp_clk ); + state_save_register_global( machine, state->salarymc_lamp_bits ); + state_save_register_global( machine, state->salarymc_lamp_shift ); + state_save_register_global( machine, state->salarymc_lamp_clk ); } /* Hyper Bishi Bashi Champ */ -static int hyperbbc_lamp_strobe1; -static int hyperbbc_lamp_strobe2; - static void hyperbbc_lamp_callback( running_machine *machine, int data ) { + ksys573_state *state = machine->driver_data(); int red = ( data >> 6 ) & 1; int blue = ( data >> 5 ) & 1; int green = ( data >> 4 ) & 1; int strobe1 = ( data >> 3 ) & 1; int strobe2 = ( data >> 0 ) & 1; - if( strobe1 && !hyperbbc_lamp_strobe1 ) + if( strobe1 && !state->hyperbbc_lamp_strobe1 ) { output_set_value( "player 1 red", red ); output_set_value( "player 1 green", green ); output_set_value( "player 1 blue", blue ); } - hyperbbc_lamp_strobe1 = strobe1; + state->hyperbbc_lamp_strobe1 = strobe1; - if( strobe2 && !hyperbbc_lamp_strobe2 ) + if( strobe2 && !state->hyperbbc_lamp_strobe2 ) { output_set_value( "player 2 red", red ); output_set_value( "player 2 green", green ); output_set_value( "player 2 blue", blue ); } - hyperbbc_lamp_strobe2 = strobe2; + state->hyperbbc_lamp_strobe2 = strobe2; } static DRIVER_INIT( hyperbbc ) { + ksys573_state *state = machine->driver_data(); + DRIVER_INIT_CALL(konami573); - security_callback = hyperbbc_lamp_callback; + state->security_callback = hyperbbc_lamp_callback; - state_save_register_global(machine, hyperbbc_lamp_strobe1 ); - state_save_register_global(machine, hyperbbc_lamp_strobe2 ); + state_save_register_global( machine, state->hyperbbc_lamp_strobe1 ); + state_save_register_global( machine, state->hyperbbc_lamp_strobe2 ); } @@ -2771,13 +2847,13 @@ static double analogue_inputs_callback( running_device *device, UINT8 input ) switch (input) { case ADC083X_CH0: - return (double)(5 * input_port_read_safe(device->machine, "analog0", 0)) / 255.0; + return (double)(5 * input_port_read_safe( device->machine, "analog0", 0 )) / 255.0; case ADC083X_CH1: - return (double)(5 * input_port_read_safe(device->machine, "analog1", 0)) / 255.0; + return (double)(5 * input_port_read_safe( device->machine, "analog1", 0 )) / 255.0; case ADC083X_CH2: - return (double)(5 * input_port_read_safe(device->machine, "analog2", 0)) / 255.0; + return (double)(5 * input_port_read_safe( device->machine, "analog2", 0 )) / 255.0; case ADC083X_CH3: - return (double)(5 * input_port_read_safe(device->machine, "analog3", 0)) / 255.0; + return (double)(5 * input_port_read_safe( device->machine, "analog3", 0 )) / 255.0; case ADC083X_AGND: return 0; case ADC083X_VREF: @@ -2791,9 +2867,9 @@ static const adc083x_interface konami573_adc_interface = { analogue_inputs_callback }; -static MACHINE_CONFIG_START( konami573, driver_device ) +static MACHINE_CONFIG_START( konami573, ksys573_state ) /* basic machine hardware */ - MDRV_CPU_ADD("maincpu", PSXCPU, XTAL_67_7376MHz ) + MDRV_CPU_ADD( "maincpu", PSXCPU, XTAL_67_7376MHz ) MDRV_CPU_PROGRAM_MAP( konami573_map) MDRV_CPU_VBLANK_INT("screen", sys573_vblank) diff --git a/src/mame/drivers/namcos10.c b/src/mame/drivers/namcos10.c index 69ccd09fd22..574c4d415b9 100644 --- a/src/mame/drivers/namcos10.c +++ b/src/mame/drivers/namcos10.c @@ -267,8 +267,15 @@ Utyuu Daisakusen Chocovader Contactee CVC1 Ver.A KC022A #include "cpu/mips/psx.h" #include "includes/psx.h" +class namcos10_state : public psx_state +{ +public: + namcos10_state(running_machine &machine, const driver_device_config_base &config) + : psx_state(machine, config) { } +}; + static ADDRESS_MAP_START( namcos10_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") AM_BASE(&g_p_n_psxram) AM_SIZE(&g_n_psxramsize) /* ram */ + AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") /* ram */ AM_RANGE(0x1f800000, 0x1f8003ff) AM_RAM /* scratchpad */ AM_RANGE(0x1f801000, 0x1f801007) AM_WRITENOP AM_RANGE(0x1f801008, 0x1f80100b) AM_RAM /* ?? */ @@ -375,9 +382,9 @@ static MACHINE_RESET( namcos10 ) psx_machine_init(machine); } -static MACHINE_CONFIG_START( namcos10, driver_device ) +static MACHINE_CONFIG_START( namcos10, namcos10_state ) /* basic machine hardware */ - MDRV_CPU_ADD("maincpu", PSXCPU, XTAL_101_4912MHz ) + MDRV_CPU_ADD( "maincpu", PSXCPU, XTAL_101_4912MHz ) MDRV_CPU_PROGRAM_MAP( namcos10_map) MDRV_CPU_VBLANK_INT("screen", psx_vblank) diff --git a/src/mame/drivers/namcos11.c b/src/mame/drivers/namcos11.c index 48d56f6d88e..24d878aff08 100644 --- a/src/mame/drivers/namcos11.c +++ b/src/mame/drivers/namcos11.c @@ -273,6 +273,20 @@ Notes: #define VERBOSE_LEVEL ( 0 ) +class namcos11_state : public psx_state +{ +public: + namcos11_state(running_machine &machine, const driver_device_config_base &config) + : psx_state(machine, config) { } + + UINT32 *sharedram; + UINT32 *keycus; + size_t keycus_size; + UINT8 su_83; + + UINT32 m_n_bankoffset; +}; + INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, const char *s_fmt, ... ) { if( VERBOSE_LEVEL >= n_level ) @@ -286,20 +300,20 @@ INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, } } -static UINT32 *namcos11_sharedram; -static UINT32 *namcos11_keycus; -static size_t namcos11_keycus_size; - static WRITE32_HANDLER( keycus_w ) { + namcos11_state *state = space->machine->driver_data(); + verboselog( space->machine, 1, "keycus_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); - COMBINE_DATA( &namcos11_keycus[ offset ] ); + COMBINE_DATA( &state->keycus[ offset ] ); } /* tekken 2 */ static READ32_HANDLER( keycus_c406_r ) { /* todo: verify behaviour */ + namcos11_state *state = space->machine->driver_data(); + UINT32 *namcos11_keycus = state->keycus; UINT32 data; data = namcos11_keycus[ offset ]; @@ -321,9 +335,10 @@ static READ32_HANDLER( keycus_c406_r ) static READ32_HANDLER( keycus_c409_r ) { /* todo: verify behaviour */ + namcos11_state *state = space->machine->driver_data(); UINT32 data; - data = namcos11_keycus[ offset ]; + data = state->keycus[ offset ]; switch( offset ) { case 3: @@ -337,6 +352,8 @@ static READ32_HANDLER( keycus_c409_r ) /* dunk mania */ static READ32_HANDLER( keycus_c410_r ) { + namcos11_state *state = space->machine->driver_data(); + UINT32 *namcos11_keycus = state->keycus; UINT32 data; UINT32 n_value; @@ -371,6 +388,8 @@ static READ32_HANDLER( keycus_c410_r ) /* prime goal ex */ static READ32_HANDLER( keycus_c411_r ) { + namcos11_state *state = space->machine->driver_data(); + UINT32 *namcos11_keycus = state->keycus; UINT32 data; UINT32 n_value; @@ -404,6 +423,8 @@ static READ32_HANDLER( keycus_c411_r ) /* xevious 3d/g */ static READ32_HANDLER( keycus_c430_r ) { + namcos11_state *state = space->machine->driver_data(); + UINT32 *namcos11_keycus = state->keycus; UINT32 data; UINT16 n_value; @@ -438,6 +459,8 @@ static READ32_HANDLER( keycus_c430_r ) /* dancing eyes */ static READ32_HANDLER( keycus_c431_r ) { + namcos11_state *state = space->machine->driver_data(); + UINT32 *namcos11_keycus = state->keycus; UINT32 data; UINT16 n_value; @@ -470,6 +493,8 @@ static READ32_HANDLER( keycus_c431_r ) /* pocket racer */ static READ32_HANDLER( keycus_c432_r ) { + namcos11_state *state = space->machine->driver_data(); + UINT32 *namcos11_keycus = state->keycus; UINT32 data; UINT16 n_value; @@ -504,9 +529,10 @@ static READ32_HANDLER( keycus_c432_r ) static READ32_HANDLER( keycus_c442_r ) { /* todo: verify behaviour */ + namcos11_state *state = space->machine->driver_data(); UINT32 data; - data = namcos11_keycus[ offset ]; + data = state->keycus[ offset ]; switch( offset ) { @@ -525,9 +551,10 @@ static READ32_HANDLER( keycus_c442_r ) static READ32_HANDLER( keycus_c443_r ) { /* todo: verify behaviour */ + namcos11_state *state = space->machine->driver_data(); UINT32 data; - data = namcos11_keycus[ offset ]; + data = state->keycus[ offset ]; switch( offset ) { @@ -556,23 +583,24 @@ static READ32_HANDLER( keycus_c443_r ) static INTERRUPT_GEN( namcos11_vblank ) { + namcos11_state *state = device->machine->driver_data(); + UINT32 *p_n_psxram = state->p_n_psxram; + if( strcmp( device->machine->gamedrv->name, "pocketrc" ) == 0 ) { - if( g_p_n_psxram[ 0x12c74 / 4 ] == 0x1440fff9 ) + if( p_n_psxram[ 0x12c74 / 4 ] == 0x1440fff9 ) { - g_p_n_psxram[ 0x12c74 / 4 ] = 0; + p_n_psxram[ 0x12c74 / 4 ] = 0; } - if( g_p_n_psxram[ 0x64694 / 4 ] == 0x1443000c ) + if( p_n_psxram[ 0x64694 / 4 ] == 0x1443000c ) { - g_p_n_psxram[ 0x64694 / 4 ] = 0; + p_n_psxram[ 0x64694 / 4 ] = 0; } } psx_vblank(device); } -static UINT32 m_n_bankoffset; - INLINE void bankswitch_rom8( address_space *space, const char *bank, int n_data ) { memory_set_bank( space->machine, bank, ( ( n_data & 0xc0 ) >> 4 ) + ( n_data & 0x03 ) ); @@ -596,22 +624,26 @@ static WRITE32_HANDLER( bankswitch_rom32_w ) static WRITE32_HANDLER( bankswitch_rom64_upper_w ) { + namcos11_state *state = space->machine->driver_data(); + verboselog( space->machine, 2, "bankswitch_rom64_upper_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); if( ACCESSING_BITS_0_15 ) { - m_n_bankoffset = 0; + state->m_n_bankoffset = 0; } if( ACCESSING_BITS_16_31 ) { - m_n_bankoffset = 16; + state->m_n_bankoffset = 16; } } INLINE void bankswitch_rom64( address_space *space, const char *bank, int n_data ) { + namcos11_state *state = space->machine->driver_data(); + /* todo: verify behaviour */ - memory_set_bank( space->machine, bank, ( ( ( ( n_data & 0xc0 ) >> 3 ) + ( n_data & 0x07 ) ) ^ m_n_bankoffset ) ); + memory_set_bank( space->machine, bank, ( ( ( ( n_data & 0xc0 ) >> 3 ) + ( n_data & 0x07 ) ) ^ state->m_n_bankoffset ) ); } static WRITE32_HANDLER( bankswitch_rom64_w ) @@ -651,16 +683,16 @@ static READ32_HANDLER( lightgun_r ) switch( offset ) { case 0: - data = input_port_read(space->machine, "GUN1X" ); + data = input_port_read( space->machine, "GUN1X" ); break; case 1: - data = ( input_port_read(space->machine, "GUN1Y" ) ) | ( ( input_port_read(space->machine, "GUN1Y" ) + 1 ) << 16 ); + data = ( input_port_read( space->machine, "GUN1Y" ) ) | ( ( input_port_read( space->machine, "GUN1Y" ) + 1 ) << 16 ); break; case 2: - data = input_port_read(space->machine, "GUN2X" ); + data = input_port_read( space->machine, "GUN2X" ); break; case 3: - data = ( input_port_read(space->machine, "GUN2Y" ) ) | ( ( input_port_read(space->machine, "GUN2Y" ) + 1 ) << 16 ); + data = ( input_port_read( space->machine, "GUN2Y" ) ) | ( ( input_port_read( space->machine, "GUN2Y" ) + 1 ) << 16 ); break; } verboselog( space->machine, 2, "lightgun_r( %08x, %08x ) %08x\n", offset, mem_mask, data ); @@ -668,7 +700,7 @@ static READ32_HANDLER( lightgun_r ) } static ADDRESS_MAP_START( namcos11_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") AM_BASE(&g_p_n_psxram) AM_SIZE(&g_n_psxramsize) /* ram */ + AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") /* ram */ AM_RANGE(0x1f800000, 0x1f8003ff) AM_RAM /* scratchpad */ AM_RANGE(0x1f801000, 0x1f801007) AM_WRITENOP AM_RANGE(0x1f801008, 0x1f80100b) AM_RAM /* ?? */ @@ -685,8 +717,8 @@ static ADDRESS_MAP_START( namcos11_map, ADDRESS_SPACE_PROGRAM, 32 ) AM_RANGE(0x1f801c00, 0x1f801dff) AM_NOP AM_RANGE(0x1f802020, 0x1f802033) AM_RAM /* ?? */ AM_RANGE(0x1f802040, 0x1f802043) AM_WRITENOP - AM_RANGE(0x1fa04000, 0x1fa0ffff) AM_RAM AM_BASE(&namcos11_sharedram) /* shared ram with C76 */ - AM_RANGE(0x1fa20000, 0x1fa2ffff) AM_WRITE(keycus_w) AM_BASE(&namcos11_keycus) AM_SIZE(&namcos11_keycus_size) /* keycus */ + AM_RANGE(0x1fa04000, 0x1fa0ffff) AM_RAM AM_BASE_MEMBER(namcos11_state, sharedram) /* shared ram with C76 */ + AM_RANGE(0x1fa20000, 0x1fa2ffff) AM_WRITE(keycus_w) AM_BASE_SIZE_MEMBER(namcos11_state, keycus, keycus_size) /* keycus */ AM_RANGE(0x1fa30000, 0x1fa30fff) AM_DEVREADWRITE8("at28c16", at28c16_r, at28c16_w, 0x00ff00ff) /* eeprom */ AM_RANGE(0x1fb00000, 0x1fb00003) AM_WRITENOP /* ?? */ AM_RANGE(0x1fbf6000, 0x1fbf6003) AM_WRITENOP /* ?? */ @@ -700,33 +732,37 @@ ADDRESS_MAP_END static READ16_HANDLER( c76_shared_r ) { - UINT16 *share16 = (UINT16 *)namcos11_sharedram; + namcos11_state *state = space->machine->driver_data(); + UINT16 *share16 = (UINT16 *)state->sharedram; return share16[offset]; } static WRITE16_HANDLER( c76_shared_w ) { - UINT16 *share16 = (UINT16 *)namcos11_sharedram; + namcos11_state *state = space->machine->driver_data(); + UINT16 *share16 = (UINT16 *)state->sharedram; COMBINE_DATA(&share16[offset]); } -static UINT8 su_83; - static READ16_HANDLER( c76_speedup_r ) { - if ((cpu_get_pc(space->cpu) == 0xc153) && (!(su_83 & 0xff00))) + namcos11_state *state = space->machine->driver_data(); + + if ((cpu_get_pc(space->cpu) == 0xc153) && (!(state->su_83 & 0xff00))) { cpu_spinuntil_int(space->cpu); } - return su_83; + return state->su_83; } static WRITE16_HANDLER( c76_speedup_w ) { - COMBINE_DATA(&su_83); + namcos11_state *state = space->machine->driver_data(); + + COMBINE_DATA(&state->su_83); } static READ16_HANDLER( c76_inputs_r ) @@ -876,6 +912,7 @@ static const struct static DRIVER_INIT( namcos11 ) { + namcos11_state *state = machine->driver_data(); int n_game; memory_install_readwrite16_handler(cputag_get_address_space(machine, "c76", ADDRESS_SPACE_PROGRAM), 0x82, 0x83, 0, 0, c76_speedup_r, c76_speedup_w); @@ -924,11 +961,11 @@ static DRIVER_INIT( namcos11 ) } if( namcos11_config_table[ n_game ].n_daughterboard == 64 ) { - m_n_bankoffset = 0; + state->m_n_bankoffset = 0; memory_install_write32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f080000, 0x1f080003, 0, 0, bankswitch_rom64_upper_w ); memory_nop_read(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fa10020, 0x1fa1002f, 0, 0 ); memory_install_write32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fa10020, 0x1fa1002f, 0, 0, bankswitch_rom64_w ); - state_save_register_global(machine, m_n_bankoffset ); + state_save_register_global( machine, state->m_n_bankoffset ); } } else @@ -949,13 +986,15 @@ static DRIVER_INIT( namcos11 ) static MACHINE_RESET( namcos11 ) { - memset( namcos11_keycus, 0, namcos11_keycus_size ); + namcos11_state *state = machine->driver_data(); + + memset( state->keycus, 0, state->keycus_size ); psx_machine_init(machine); } -static MACHINE_CONFIG_START( coh100, driver_device ) +static MACHINE_CONFIG_START( coh100, namcos11_state ) /* basic machine hardware */ - MDRV_CPU_ADD("maincpu", PSXCPU, XTAL_67_7376MHz ) + MDRV_CPU_ADD( "maincpu", PSXCPU, XTAL_67_7376MHz ) MDRV_CPU_PROGRAM_MAP( namcos11_map) MDRV_CPU_VBLANK_INT("screen", namcos11_vblank) diff --git a/src/mame/drivers/namcos12.c b/src/mame/drivers/namcos12.c index b2a49496276..2ebf9b2449d 100644 --- a/src/mame/drivers/namcos12.c +++ b/src/mame/drivers/namcos12.c @@ -937,6 +937,33 @@ Notes: #define VERBOSE_LEVEL ( 0 ) +class namcos12_state : public psx_state +{ +public: + namcos12_state(running_machine &machine, const driver_device_config_base &config) + : psx_state(machine, config) { } + + UINT32 *sharedram; + UINT32 m_n_bankoffset; + + UINT32 m_n_dmaoffset; + UINT32 m_n_dmabias; + UINT32 m_n_tektagdmaoffset; + int has_tektagt_dma; + + UINT8 kcram[ 12 ]; + + int ttt_cnt; + UINT32 ttt_val[2]; + + int s12_porta; + int s12_rtcstate; + int s12_lastpB; + int s12_setstate; + int s12_setnum; + int s12_settings[8]; +}; + INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, const char *s_fmt, ... ) { if( VERBOSE_LEVEL >= n_level ) @@ -950,81 +977,85 @@ INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, } } -static UINT32 *namcos12_sharedram; - static WRITE32_HANDLER( sharedram_w ) { + namcos12_state *state = space->machine->driver_data(); + verboselog( space->machine, 1, "sharedram_w( %08x, %08x, %08x )\n", ( offset * 4 ), data, mem_mask ); - COMBINE_DATA( &namcos12_sharedram[ offset ] ); + COMBINE_DATA( &state->sharedram[ offset ] ); } static READ32_HANDLER( sharedram_r ) { - verboselog( space->machine, 1, "sharedram_r( %08x, %08x ) %08x\n", ( offset * 4 ), mem_mask, namcos12_sharedram[ offset ] ); - return namcos12_sharedram[ offset ]; + namcos12_state *state = space->machine->driver_data(); + + verboselog( space->machine, 1, "sharedram_r( %08x, %08x ) %08x\n", ( offset * 4 ), mem_mask, state->sharedram[ offset ] ); + return state->sharedram[ offset ]; } static WRITE16_HANDLER( sharedram_sub_w ) { - UINT16 *shared16 = (UINT16 *)namcos12_sharedram; + namcos12_state *state = space->machine->driver_data(); + + UINT16 *shared16 = (UINT16 *)state->sharedram; COMBINE_DATA(&shared16[BYTE_XOR_LE(offset)]); } static READ16_HANDLER( sharedram_sub_r ) { - UINT16 *shared16 = (UINT16 *)namcos12_sharedram; + namcos12_state *state = space->machine->driver_data(); + + UINT16 *shared16 = (UINT16 *)state->sharedram; return shared16[BYTE_XOR_LE(offset)]; } -static UINT32 m_n_bankoffset; - static WRITE32_HANDLER( bankoffset_w ) { + namcos12_state *state = space->machine->driver_data(); + // Golgo 13 has different banking (maybe the keycus controls it?) if( strcmp( space->machine->gamedrv->name, "golgo13" ) == 0 || strcmp( space->machine->gamedrv->name, "g13knd" ) == 0 ) { if( ( data & 8 ) != 0 ) { - m_n_bankoffset = ( data & 0x6 ) << 2; + state->m_n_bankoffset = ( data & 0x6 ) << 2; } else { - m_n_bankoffset = ( m_n_bankoffset & ~0x7 ) | ( data & 0x7 ); + state->m_n_bankoffset = ( state->m_n_bankoffset & ~0x7 ) | ( data & 0x7 ); } } else { - m_n_bankoffset = data; + state->m_n_bankoffset = data; } - memory_set_bank(space->machine, "bank1", m_n_bankoffset ); + memory_set_bank( space->machine, "bank1", state->m_n_bankoffset ); - verboselog( space->machine, 1, "bankoffset_w( %08x, %08x, %08x ) %08x\n", offset, data, mem_mask, m_n_bankoffset ); + verboselog( space->machine, 1, "bankoffset_w( %08x, %08x, %08x ) %08x\n", offset, data, mem_mask, state->m_n_bankoffset ); } -static UINT32 m_n_dmaoffset; -static UINT32 m_n_dmabias; -static UINT32 m_n_tektagdmaoffset; -static int has_tektagt_dma; - static WRITE32_HANDLER( dmaoffset_w ) { + namcos12_state *state = space->machine->driver_data(); + if( ACCESSING_BITS_0_15 ) { - m_n_dmaoffset = ( offset * 4 ) | ( data << 16 ); + state->m_n_dmaoffset = ( offset * 4 ) | ( data << 16 ); } if( ACCESSING_BITS_16_31 ) { - m_n_dmaoffset = ( ( offset * 4 ) + 2 ) | ( data & 0xffff0000 ); + state->m_n_dmaoffset = ( ( offset * 4 ) + 2 ) | ( data & 0xffff0000 ); } - verboselog( space->machine, 1, "dmaoffset_w( %08x, %08x, %08x ) %08x\n", offset, data, mem_mask, m_n_dmaoffset ); + verboselog( space->machine, 1, "dmaoffset_w( %08x, %08x, %08x ) %08x\n", offset, data, mem_mask, state->m_n_dmaoffset ); } static void namcos12_rom_read( running_machine *machine, UINT32 n_address, INT32 n_size ) { + namcos12_state *state = machine->driver_data(); const char *n_region; int n_offset; @@ -1034,22 +1065,22 @@ static void namcos12_rom_read( running_machine *machine, UINT32 n_address, INT32 UINT16 *source; UINT16 *destination; - if(has_tektagt_dma && !m_n_dmaoffset) + if(state->has_tektagt_dma && !state->m_n_dmaoffset) { n_region = "user2"; - n_offset = m_n_tektagdmaoffset & 0x7fffffff; + n_offset = state->m_n_tektagdmaoffset & 0x7fffffff; verboselog( machine, 1, "namcos12_rom_read( %08x, %08x ) tektagt %08x\n", n_address, n_size, n_offset ); } - else if( ( m_n_dmaoffset >= 0x80000000 ) || ( m_n_dmabias == 0x1f300000 ) ) + else if( ( state->m_n_dmaoffset >= 0x80000000 ) || ( state->m_n_dmabias == 0x1f300000 ) ) { n_region = "user1"; - n_offset = m_n_dmaoffset & 0x003fffff; + n_offset = state->m_n_dmaoffset & 0x003fffff; verboselog( machine, 1, "namcos12_rom_read( %08x, %08x ) boot %08x\n", n_address, n_size, n_offset ); } else { n_region = "user2"; - n_offset = m_n_dmaoffset & 0x7fffffff; + n_offset = state->m_n_dmaoffset & 0x7fffffff; verboselog( machine, 1, "namcos12_rom_read( %08x, %08x ) game %08x\n", n_address, n_size, n_offset ); } @@ -1061,8 +1092,8 @@ static void namcos12_rom_read( running_machine *machine, UINT32 n_address, INT32 n_size = n_romleft; } - destination = (UINT16 *) g_p_n_psxram; - n_ramleft = ( g_n_psxramsize - n_address ) / 4; + destination = (UINT16 *)state->p_n_psxram; + n_ramleft = ( state->n_psxramsize - n_address ) / 4; if( n_size > n_ramleft ) { verboselog( machine, 1, "namcos12_rom_read dma truncated %d to %d passed end of ram\n", n_size, n_ramleft ); @@ -1084,13 +1115,15 @@ static void namcos12_rom_read( running_machine *machine, UINT32 n_address, INT32 static WRITE32_HANDLER( s12_dma_bias_w ) { - m_n_dmabias = data; + namcos12_state *state = space->machine->driver_data(); + + state->m_n_dmabias = data; } static ADDRESS_MAP_START( namcos12_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") AM_BASE(&g_p_n_psxram) AM_SIZE(&g_n_psxramsize) /* ram */ + AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") /* ram */ AM_RANGE(0x1f000000, 0x1f000003) AM_READNOP AM_WRITE(bankoffset_w) /* banking */ - AM_RANGE(0x1f080000, 0x1f083fff) AM_READWRITE(sharedram_r, sharedram_w) AM_BASE(&namcos12_sharedram) /* shared ram?? */ + AM_RANGE(0x1f080000, 0x1f083fff) AM_READWRITE(sharedram_r, sharedram_w) AM_BASE_MEMBER(namcos12_state, sharedram) /* shared ram?? */ AM_RANGE(0x1f140000, 0x1f140fff) AM_DEVREADWRITE8("at28c16", at28c16_r, at28c16_w, 0x00ff00ff) /* eeprom */ AM_RANGE(0x1f1bff08, 0x1f1bff0f) AM_WRITENOP /* ?? */ AM_RANGE(0x1f700000, 0x1f70ffff) AM_WRITE(dmaoffset_w) /* dma */ @@ -1173,27 +1206,26 @@ static void system11gun_install( running_machine *machine ) memory_install_read32_handler (cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f780000, 0x1f78000f, 0, 0, system11gun_r ); } -static UINT8 kcram[ 12 ]; - static WRITE32_HANDLER( kcoff_w ) { - memory_set_bankptr(space->machine, "bank2", memory_region( space->machine, "user1" ) + 0x20280 ); + memory_set_bankptr( space->machine, "bank2", memory_region( space->machine, "user1" ) + 0x20280 ); } static WRITE32_HANDLER( kcon_w ) { - memory_set_bankptr(space->machine, "bank2", kcram ); -} + namcos12_state *state = space->machine->driver_data(); -static int ttt_cnt; -static UINT32 ttt_val[2]; + memory_set_bankptr( space->machine, "bank2", state->kcram ); +} static WRITE32_HANDLER( tektagt_protection_1_w ) { + namcos12_state *state = space->machine->driver_data(); + // Second dma offset or protection ref values write - m_n_tektagdmaoffset = data; - if(ttt_cnt != 2) - ttt_val[ttt_cnt++] = data; + state->m_n_tektagdmaoffset = data; + if(state->ttt_cnt != 2) + state->ttt_val[state->ttt_cnt++] = data; } static READ32_HANDLER( tektagt_protection_1_r ) @@ -1204,12 +1236,16 @@ static READ32_HANDLER( tektagt_protection_1_r ) static WRITE32_HANDLER( tektagt_protection_2_w ) { + namcos12_state *state = space->machine->driver_data(); + // Writes are 0 or rand(), only used as a "start prot value write" trigger - ttt_cnt = 0; + state->ttt_cnt = 0; } static READ32_HANDLER( tektagt_protection_2_r ) { + namcos12_state *state = space->machine->driver_data(); + UINT32 *ttt_val = state->ttt_val; UINT32 data = 0; if(((ttt_val[0] >> 16) & 0xff) == 0x6d) @@ -1238,17 +1274,18 @@ static READ32_HANDLER( tektagt_protection_3_r ) static MACHINE_RESET( namcos12 ) { + namcos12_state *state = machine->driver_data(); address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); psx_machine_init(machine); bankoffset_w(space,0,0,0xffffffff); - has_tektagt_dma = 0; + state->has_tektagt_dma = 0; if( strcmp( machine->gamedrv->name, "tektagt" ) == 0 || strcmp( machine->gamedrv->name, "tektagta" ) == 0 || strcmp( machine->gamedrv->name, "tektagtb" ) == 0 || strcmp( machine->gamedrv->name, "tektagtc" ) == 0 ) { - has_tektagt_dma = 1; + state->has_tektagt_dma = 1; memory_install_readwrite32_handler(space, 0x1fb00000, 0x1fb00003, 0, 0, tektagt_protection_1_r, tektagt_protection_1_w ); memory_install_readwrite32_handler(space, 0x1fb80000, 0x1fb80003, 0, 0, tektagt_protection_2_r, tektagt_protection_2_w ); memory_install_read32_handler(space, 0x1f700000, 0x1f700003, 0, 0, tektagt_protection_3_r ); @@ -1277,8 +1314,8 @@ static MACHINE_RESET( namcos12 ) memory_install_write32_handler(space, 0x1f008000, 0x1f008003, 0, 0, kcon_w ); memory_install_write32_handler(space, 0x1f018000, 0x1f018003, 0, 0, kcoff_w ); - memset( kcram, 0, sizeof( kcram ) ); - memory_set_bankptr(space->machine, "bank2", kcram ); + memset( state->kcram, 0, sizeof( state->kcram ) ); + memory_set_bankptr( space->machine, "bank2", state->kcram ); } } @@ -1302,23 +1339,25 @@ static READ8_HANDLER( s12_mcu_p8_r ) // in System 12, bit 0 of H8/3002 port A is connected to it's chip enable // the actual I/O takes place through the H8/3002's serial port B. -static int s12_porta = 0, s12_rtcstate = 0; - static READ8_HANDLER( s12_mcu_pa_r ) { - return s12_porta; + namcos12_state *state = space->machine->driver_data(); + + return state->s12_porta; } static WRITE8_HANDLER( s12_mcu_pa_w ) { + namcos12_state *state = space->machine->driver_data(); + // bit 0 = chip enable for the RTC // reset the state on the rising edge of the bit - if ((!(s12_porta & 1)) && (data & 1)) + if ((!(state->s12_porta & 1)) && (data & 1)) { - s12_rtcstate = 0; + state->s12_rtcstate = 0; } - s12_porta = data; + state->s12_porta = data; } INLINE UINT8 make_bcd(UINT8 data) @@ -1328,13 +1367,14 @@ INLINE UINT8 make_bcd(UINT8 data) static READ8_HANDLER( s12_mcu_rtc_r ) { + namcos12_state *state = space->machine->driver_data(); UINT8 ret = 0; system_time systime; static const int weekday[7] = { 7, 1, 2, 3, 4, 5, 6 }; space->machine->current_datetime(systime); - switch (s12_rtcstate) + switch (state->s12_rtcstate) { case 0: ret = make_bcd(systime.local_time.second); // seconds (BCD, 0-59) in bits 0-6, bit 7 = battery low @@ -1362,39 +1402,44 @@ static READ8_HANDLER( s12_mcu_rtc_r ) break; } - s12_rtcstate++; + state->s12_rtcstate++; return ret; } -static int s12_lastpB, s12_setstate, s12_setnum, s12_settings[8]; - static READ8_HANDLER( s12_mcu_portB_r ) { + namcos12_state *state = space->machine->driver_data(); + // golgo13 won't boot if this doesn't toggle every read - s12_lastpB ^= 0x80; - return s12_lastpB; + state->s12_lastpB ^= 0x80; + return state->s12_lastpB; } static WRITE8_HANDLER( s12_mcu_portB_w ) { + namcos12_state *state = space->machine->driver_data(); + // bit 7 = chip enable for the video settings controller if (data & 0x80) { - s12_setstate = 0; + state->s12_setstate = 0; } - s12_lastpB = data; + state->s12_lastpB = data; } static WRITE8_HANDLER( s12_mcu_settings_w ) { - if (s12_setstate) + namcos12_state *state = space->machine->driver_data(); + int *s12_settings = state->s12_settings; + + if (state->s12_setstate) { // data - s12_settings[s12_setnum] = data; + s12_settings[state->s12_setnum] = data; - if (s12_setnum == 7) + if (state->s12_setnum == 7) { logerror("S12 video settings: Contrast: %02x R: %02x G: %02x B: %02x\n", BITSWAP8(s12_settings[0], 0, 1, 2, 3, 4, 5, 6, 7), @@ -1405,10 +1450,10 @@ static WRITE8_HANDLER( s12_mcu_settings_w ) } else { // setting number - s12_setnum = (data >> 4)-1; + state->s12_setnum = (data >> 4)-1; } - s12_setstate ^= 1; + state->s12_setstate ^= 1; } /* Golgo 13 lightgun inputs @@ -1470,28 +1515,30 @@ ADDRESS_MAP_END static DRIVER_INIT( namcos12 ) { + namcos12_state *state = machine->driver_data(); + psx_driver_init(machine); - psx_dma_install_read_handler( 5, namcos12_rom_read ); + psx_dma_install_read_handler( machine, 5, namcos12_rom_read ); - memory_configure_bank(machine, "bank1", 0, memory_region_length( machine, "user2" ) / 0x200000, memory_region( machine, "user2" ), 0x200000 ); + memory_configure_bank(machine, "bank1", 0, memory_region_length( machine, "user2" ) / 0x200000, memory_region( machine, "user2" ), 0x200000 ); - s12_porta = 0; - s12_rtcstate = 0; - s12_lastpB = 0x50; - s12_setstate = 0; - s12_setnum = 0; - memset(s12_settings, 0, sizeof(s12_settings)); + state->s12_porta = 0; + state->s12_rtcstate = 0; + state->s12_lastpB = 0x50; + state->s12_setstate = 0; + state->s12_setnum = 0; + memset(state->s12_settings, 0, sizeof(state->s12_settings)); - m_n_tektagdmaoffset = 0; - m_n_dmaoffset = 0; - m_n_dmabias = 0; - m_n_bankoffset = 0; - memory_set_bank(machine, "bank1", 0 ); + state->m_n_tektagdmaoffset = 0; + state->m_n_dmaoffset = 0; + state->m_n_dmabias = 0; + state->m_n_bankoffset = 0; + memory_set_bank( machine, "bank1", 0 ); - state_save_register_global(machine, m_n_dmaoffset ); - state_save_register_global(machine, m_n_dmabias ); - state_save_register_global(machine, m_n_bankoffset ); + state_save_register_global( machine, state->m_n_dmaoffset ); + state_save_register_global( machine, state->m_n_dmabias ); + state_save_register_global( machine, state->m_n_bankoffset ); } static DRIVER_INIT( ptblank2 ) @@ -1511,9 +1558,9 @@ static DRIVER_INIT( ghlpanic ) system11gun_install(machine); } -static MACHINE_CONFIG_START( coh700, driver_device ) +static MACHINE_CONFIG_START( coh700, namcos12_state ) /* basic machine hardware */ - MDRV_CPU_ADD("maincpu", CXD8661R, XTAL_100MHz ) + MDRV_CPU_ADD( "maincpu", CXD8661R, XTAL_100MHz ) MDRV_CPU_PROGRAM_MAP( namcos12_map) MDRV_CPU_VBLANK_INT("screen", psx_vblank) diff --git a/src/mame/drivers/taitogn.c b/src/mame/drivers/taitogn.c index d78715acc55..5f4ee765368 100644 --- a/src/mame/drivers/taitogn.c +++ b/src/mame/drivers/taitogn.c @@ -328,19 +328,40 @@ Type 3 (PCMCIA Compact Flash Adaptor + Compact Flash card, sealed together with #include "sound/psx.h" #include "audio/taito_zm.h" -static intel_te28f160_device *biosflash; -static intel_e28f400_device *pgmflash; -static intel_te28f160_device *sndflash[3]; +class taitogn_state : public psx_state +{ +public: + taitogn_state(running_machine &machine, const driver_device_config_base &config) + : psx_state(machine, config) { } + + intel_te28f160_device *biosflash; + intel_e28f400_device *pgmflash; + intel_te28f160_device *sndflash[3]; + + unsigned char cis[512]; + int locked; + + unsigned char rf5c296_reg; + + UINT32 control, control2, control3; + int v; + + UINT32 m_n_znsecsel; + UINT32 m_b_znsecport; + int m_n_dip_bit; + int m_b_lastclock; + emu_timer *dip_timer; + + UINT32 coin_info; + UINT32 mux_data; +}; -static unsigned char cis[512]; -static int locked; // rf5c296 is very inaccurate at that point, it hardcodes the gnet config -static unsigned char rf5c296_reg = 0; - static void rf5c296_reg_w(ATTR_UNUSED running_machine *machine, UINT8 reg, UINT8 data) { + taitogn_state *state = machine->driver_data(); // fprintf(stderr, "rf5c296_reg_w %02x, %02x (%s)\n", reg, data, cpuexec_describe_context(machine)); switch (reg) { @@ -350,7 +371,7 @@ static void rf5c296_reg_w(ATTR_UNUSED running_machine *machine, UINT8 reg, UINT8 if (!(data & 0x40)) { devtag_reset(machine, "card"); - locked = 0x1ff; + state->locked = 0x1ff; ide_set_gnet_readlock (machine->device("card"), 1); } break; @@ -368,6 +389,8 @@ static UINT8 rf5c296_reg_r(ATTR_UNUSED running_machine *machine, UINT8 reg) static WRITE32_HANDLER(rf5c296_io_w) { + taitogn_state *state = space->machine->driver_data(); + if(offset < 2) { ide_controller32_pcmcia_w(space->machine->device("card"), offset, data, mem_mask); return; @@ -375,14 +398,16 @@ static WRITE32_HANDLER(rf5c296_io_w) if(offset == 0x3e0/4) { if(ACCESSING_BITS_0_7) - rf5c296_reg = data; + state->rf5c296_reg = data; if(ACCESSING_BITS_8_15) - rf5c296_reg_w(space->machine, rf5c296_reg, data >> 8); + rf5c296_reg_w(space->machine, state->rf5c296_reg, data >> 8); } } static READ32_HANDLER(rf5c296_io_r) { + taitogn_state *state = space->machine->driver_data(); + if(offset < 2) return ide_controller32_pcmcia_r(space->machine->device("card"), offset, mem_mask); @@ -391,9 +416,9 @@ static READ32_HANDLER(rf5c296_io_r) if(offset == 0x3e0/4) { UINT32 res = 0xffff0000; if(ACCESSING_BITS_0_7) - res |= rf5c296_reg; + res |= state->rf5c296_reg; if(ACCESSING_BITS_8_15) - res |= rf5c296_reg_r(space->machine, rf5c296_reg) << 8; + res |= rf5c296_reg_r(space->machine, state->rf5c296_reg) << 8; return res; } @@ -404,13 +429,15 @@ static READ32_HANDLER(rf5c296_io_r) static READ32_HANDLER(rf5c296_mem_r) { + taitogn_state *state = space->machine->driver_data(); + if(offset < 0x80) - return (cis[offset*2+1] << 16) | cis[offset*2]; + return (state->cis[offset*2+1] << 16) | state->cis[offset*2]; switch(offset) { case 0x080: return 0x00800041; case 0x081: return 0x0000002e; - case 0x100: return locked ? 0x00010000 : 0; + case 0x100: return state->locked ? 0x00010000 : 0; default: return 0; } @@ -418,6 +445,8 @@ static READ32_HANDLER(rf5c296_mem_r) static WRITE32_HANDLER(rf5c296_mem_w) { + taitogn_state *state = space->machine->driver_data(); + if(offset >= 0x140 && offset <= 0x144) { UINT8 key[5]; int pos = (offset - 0x140)*2; @@ -430,10 +459,10 @@ static WRITE32_HANDLER(rf5c296_mem_w) chd_get_metadata(get_disk_handle(space->machine, "card"), HARD_DISK_KEY_METADATA_TAG, 0, key, 5, 0, 0, 0); k = pos < 5 ? key[pos] : 0; if(v == k) - locked &= ~(1 << pos); + state->locked &= ~(1 << pos); else - locked |= 1 << pos; - if (!locked) { + state->locked |= 1 << pos; + if (!state->locked) { ide_set_gnet_readlock (space->machine->device("card"), 0); } } @@ -465,56 +494,74 @@ static void gen_flash_w(intelfsh16_device *device, offs_t offset, UINT32 data, U static READ32_HANDLER(flash_subbios_r) { - return gen_flash_r(biosflash, offset, mem_mask); + taitogn_state *state = space->machine->driver_data(); + + return gen_flash_r(state->biosflash, offset, mem_mask); } static WRITE32_HANDLER(flash_subbios_w) { - gen_flash_w(biosflash, offset, data, mem_mask); + taitogn_state *state = space->machine->driver_data(); + + gen_flash_w(state->biosflash, offset, data, mem_mask); } static READ32_HANDLER(flash_mn102_r) { - return gen_flash_r(pgmflash, offset, mem_mask); + taitogn_state *state = space->machine->driver_data(); + + return gen_flash_r(state->pgmflash, offset, mem_mask); } static WRITE32_HANDLER(flash_mn102_w) { - gen_flash_w(pgmflash, offset, data, mem_mask); + taitogn_state *state = space->machine->driver_data(); + + gen_flash_w(state->pgmflash, offset, data, mem_mask); } static READ32_HANDLER(flash_s1_r) { - return gen_flash_r(sndflash[0], offset, mem_mask); + taitogn_state *state = space->machine->driver_data(); + + return gen_flash_r(state->sndflash[0], offset, mem_mask); } static WRITE32_HANDLER(flash_s1_w) { - gen_flash_w(sndflash[0], offset, data, mem_mask); + taitogn_state *state = space->machine->driver_data(); + + gen_flash_w(state->sndflash[0], offset, data, mem_mask); } static READ32_HANDLER(flash_s2_r) { - return gen_flash_r(sndflash[1], offset, mem_mask); + taitogn_state *state = space->machine->driver_data(); + + return gen_flash_r(state->sndflash[1], offset, mem_mask); } static WRITE32_HANDLER(flash_s2_w) { - gen_flash_w(sndflash[1], offset, data, mem_mask); + taitogn_state *state = space->machine->driver_data(); + + gen_flash_w(state->sndflash[1], offset, data, mem_mask); } static READ32_HANDLER(flash_s3_r) { - return gen_flash_r(sndflash[2], offset, mem_mask); + taitogn_state *state = space->machine->driver_data(); + + return gen_flash_r(state->sndflash[2], offset, mem_mask); } static WRITE32_HANDLER(flash_s3_w) { - gen_flash_w(sndflash[2], offset, data, mem_mask); + taitogn_state *state = space->machine->driver_data(); + + gen_flash_w(state->sndflash[2], offset, data, mem_mask); } - - static void install_handlers(running_machine *machine, int mode) { address_space *a = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); @@ -535,28 +582,30 @@ static void install_handlers(running_machine *machine, int mode) // Misc. controls -static UINT32 control = 0, control2 = 0, control3; - static READ32_HANDLER(control_r) { + taitogn_state *state = space->machine->driver_data(); + // fprintf(stderr, "gn_r %08x @ %08x (%s)\n", 0x1fb00000+4*offset, mem_mask, cpuexec_describe_context(space->machine)); - return control; + return state->control; } static WRITE32_HANDLER(control_w) { + taitogn_state *state = space->machine->driver_data(); + // 20 = watchdog // 04 = select bank // According to the rom code, bits 1-0 may be part of the bank // selection too, but they're always 0. - UINT32 p = control; + UINT32 p = state->control; running_device *mb3773 = space->machine->device("mb3773"); - COMBINE_DATA(&control); + COMBINE_DATA(&state->control); - mb3773_set_ck(mb3773, (control & 0x20) >> 5); + mb3773_set_ck(mb3773, (state->control & 0x20) >> 5); #if 0 if((p ^ control) & ~0x20) @@ -571,23 +620,29 @@ static WRITE32_HANDLER(control_w) cpuexec_describe_context(space->machine)); #endif - if((p ^ control) & 0x04) - install_handlers(space->machine, control & 4 ? 1 : 0); + if((p ^ state->control) & 0x04) + install_handlers(space->machine, state->control & 4 ? 1 : 0); } static WRITE32_HANDLER(control2_w) { - COMBINE_DATA(&control2); + taitogn_state *state = space->machine->driver_data(); + + COMBINE_DATA(&state->control2); } static READ32_HANDLER(control3_r) { - return control3; + taitogn_state *state = space->machine->driver_data(); + + return state->control3; } static WRITE32_HANDLER(control3_w) { - COMBINE_DATA(&control3); + taitogn_state *state = space->machine->driver_data(); + + COMBINE_DATA(&state->control3); } static READ32_HANDLER(gn_1fb70000_r) @@ -610,10 +665,11 @@ static WRITE32_HANDLER(gn_1fb70000_w) static READ32_HANDLER(hack1_r) { - static int v = 0; - v = v ^ 8; + taitogn_state *state = space->machine->driver_data(); + + state->v = state->v ^ 8; // Probably something to do with sound - return v; + return state->v; } @@ -623,54 +679,56 @@ static READ32_HANDLER(hack1_r) static const UINT8 tt10[ 8 ] = { 0x80, 0x20, 0x38, 0x08, 0xf1, 0x03, 0xfe, 0xfc }; static const UINT8 tt16[ 8 ] = { 0xc0, 0x04, 0xf9, 0xe1, 0x60, 0x70, 0xf2, 0x02 }; -static UINT32 m_n_znsecsel; -static UINT32 m_b_znsecport; -static int m_n_dip_bit; -static int m_b_lastclock; -static emu_timer *dip_timer; - static READ32_HANDLER( znsecsel_r ) { - return m_n_znsecsel; + taitogn_state *state = space->machine->driver_data(); + + return state->m_n_znsecsel; } static void sio_znsec0_handler( running_machine *machine, int n_data ) { + taitogn_state *state = machine->driver_data(); + if( ( n_data & PSX_SIO_OUT_CLOCK ) == 0 ) { - if( m_b_lastclock ) + if( state->m_b_lastclock ) psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( znsec_step( 0, ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA ); - m_b_lastclock = 0; + state->m_b_lastclock = 0; } else { - m_b_lastclock = 1; + state->m_b_lastclock = 1; } } static void sio_znsec1_handler( running_machine *machine, int n_data ) { + taitogn_state *state = machine->driver_data(); + if( ( n_data & PSX_SIO_OUT_CLOCK ) == 0 ) { - if( m_b_lastclock ) + if( state->m_b_lastclock ) psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( znsec_step( 1, ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA ); - m_b_lastclock = 0; + state->m_b_lastclock = 0; } else { - m_b_lastclock = 1; + state->m_b_lastclock = 1; } } static void sio_pad_handler( running_machine *machine, int n_data ) { + taitogn_state *state = machine->driver_data(); + if( ( n_data & PSX_SIO_OUT_DTR ) != 0 ) { - m_b_znsecport = 1; + state->m_b_znsecport = 1; } else { - m_b_znsecport = 0; + state->m_b_znsecport = 0; } psx_sio_input( machine, 0, PSX_SIO_IN_DATA | PSX_SIO_IN_DSR, PSX_SIO_IN_DATA | PSX_SIO_IN_DSR ); @@ -678,63 +736,69 @@ static void sio_pad_handler( running_machine *machine, int n_data ) static void sio_dip_handler( running_machine *machine, int n_data ) { + taitogn_state *state = machine->driver_data(); + if( ( n_data & PSX_SIO_OUT_CLOCK ) == 0 ) { - if( m_b_lastclock ) + if( state->m_b_lastclock ) { - int bit = ( ( input_port_read(machine, "DSW") >> m_n_dip_bit ) & 1 ); + int bit = ( ( input_port_read(machine, "DSW") >> state->m_n_dip_bit ) & 1 ); psx_sio_input( machine, 0, PSX_SIO_IN_DATA, bit * PSX_SIO_IN_DATA ); - m_n_dip_bit++; - m_n_dip_bit &= 7; + state->m_n_dip_bit++; + state->m_n_dip_bit &= 7; } - m_b_lastclock = 0; + state->m_b_lastclock = 0; } else { - m_b_lastclock = 1; + state->m_b_lastclock = 1; } } static WRITE32_HANDLER( znsecsel_w ) { - COMBINE_DATA( &m_n_znsecsel ); + taitogn_state *state = space->machine->driver_data(); - if( ( m_n_znsecsel & 0x80 ) == 0 ) + COMBINE_DATA( &state->m_n_znsecsel ); + + if( ( state->m_n_znsecsel & 0x80 ) == 0 ) { - psx_sio_install_handler( 0, sio_pad_handler ); + psx_sio_install_handler( space->machine, 0, sio_pad_handler ); psx_sio_input( space->machine, 0, PSX_SIO_IN_DSR, 0 ); } - else if( ( m_n_znsecsel & 0x08 ) == 0 ) + else if( ( state->m_n_znsecsel & 0x08 ) == 0 ) { znsec_start( 1 ); - psx_sio_install_handler( 0, sio_znsec1_handler ); + psx_sio_install_handler( space->machine, 0, sio_znsec1_handler ); psx_sio_input( space->machine, 0, PSX_SIO_IN_DSR, 0 ); } - else if( ( m_n_znsecsel & 0x04 ) == 0 ) + else if( ( state->m_n_znsecsel & 0x04 ) == 0 ) { znsec_start( 0 ); - psx_sio_install_handler( 0, sio_znsec0_handler ); + psx_sio_install_handler( space->machine, 0, sio_znsec0_handler ); psx_sio_input( space->machine, 0, PSX_SIO_IN_DSR, 0 ); } else { - m_n_dip_bit = 0; - m_b_lastclock = 1; + state->m_n_dip_bit = 0; + state->m_b_lastclock = 1; - psx_sio_install_handler( 0, sio_dip_handler ); + psx_sio_install_handler( space->machine, 0, sio_dip_handler ); psx_sio_input( space->machine, 0, PSX_SIO_IN_DSR, 0 ); - timer_adjust_oneshot( dip_timer, downcast(space->cpu)->cycles_to_attotime( 100 ), 1 ); + timer_adjust_oneshot( state->dip_timer, downcast(space->cpu)->cycles_to_attotime( 100 ), 1 ); } } static TIMER_CALLBACK( dip_timer_fired ) { + taitogn_state *state = machine->driver_data(); + psx_sio_input( machine, 0, PSX_SIO_IN_DSR, param * PSX_SIO_IN_DSR ); if( param ) { - timer_adjust_oneshot(dip_timer, machine->device("maincpu")->cycles_to_attotime(50), 0); + timer_adjust_oneshot(state->dip_timer, machine->device("maincpu")->cycles_to_attotime(50), 0); } } @@ -764,33 +828,35 @@ static READ32_HANDLER( boardconfig_r ) } -static UINT32 coin_info; - static WRITE32_HANDLER( coin_w ) { + taitogn_state *state = space->machine->driver_data(); + /* 0x01=counter 0x02=coin lock 1 0x08=?? 0x20=coin lock 2 0x80=?? */ - COMBINE_DATA (&coin_info); + COMBINE_DATA (&state->coin_info); } static READ32_HANDLER( coin_r ) { - return coin_info; + taitogn_state *state = space->machine->driver_data(); + + return state->coin_info; } /* mahjong panel handler (for Usagi & Mahjong Oh) */ static READ32_HANDLER( gnet_mahjong_panel_r ) { - static UINT32 mux_data; + taitogn_state *state = space->machine->driver_data(); - mux_data = coin_info; - mux_data &= 0xcc; + state->mux_data = state->coin_info; + state->mux_data &= 0xcc; - switch(mux_data) + switch(state->mux_data) { case 0x04: return input_port_read(space->machine, "KEY0"); case 0x08: return input_port_read(space->machine, "KEY1"); @@ -806,21 +872,23 @@ static READ32_HANDLER( gnet_mahjong_panel_r ) static DRIVER_INIT( coh3002t ) { - biosflash = machine->device("biosflash"); - pgmflash = machine->device("pgmflash"); - sndflash[0] = machine->device("sndflash0"); - sndflash[1] = machine->device("sndflash1"); - sndflash[2] = machine->device("sndflash2"); + taitogn_state *state = machine->driver_data(); + + state->biosflash = machine->device("biosflash"); + state->pgmflash = machine->device("pgmflash"); + state->sndflash[0] = machine->device("sndflash0"); + state->sndflash[1] = machine->device("sndflash1"); + state->sndflash[2] = machine->device("sndflash2"); psx_driver_init(machine); znsec_init(0, tt10); znsec_init(1, tt16); - psx_sio_install_handler(0, sio_pad_handler); - dip_timer = timer_alloc(machine, dip_timer_fired, NULL ); + psx_sio_install_handler(machine, 0, sio_pad_handler); + state->dip_timer = timer_alloc( machine, dip_timer_fired, NULL ); - memset(cis, 0xff, 512); + memset(state->cis, 0xff, 512); if (get_disk_handle(machine, "card") != NULL) - chd_get_metadata(get_disk_handle(machine, "card"), PCMCIA_CIS_METADATA_TAG, 0, cis, 512, 0, 0, 0); + chd_get_metadata(get_disk_handle(machine, "card"), PCMCIA_CIS_METADATA_TAG, 0, state->cis, 512, 0, 0, 0); } static DRIVER_INIT( coh3002t_mp ) @@ -831,10 +899,12 @@ static DRIVER_INIT( coh3002t_mp ) static MACHINE_RESET( coh3002t ) { - m_b_lastclock = 1; - locked = 0x1ff; + taitogn_state *state = machine->driver_data(); + + state->m_b_lastclock = 1; + state->locked = 0x1ff; install_handlers(machine, 0); - control = 0; + state->control = 0; psx_machine_init(machine); devtag_reset(machine, "card"); ide_set_gnet_readlock(machine->device("card"), 1); @@ -844,7 +914,7 @@ static MACHINE_RESET( coh3002t ) } static ADDRESS_MAP_START( zn_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") AM_BASE(&g_p_n_psxram) AM_SIZE(&g_n_psxramsize) /* ram */ + AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") /* ram */ AM_RANGE(0x00400000, 0x007fffff) AM_RAM AM_SHARE("share1") /* ram mirror */ AM_RANGE(0x1f000000, 0x1f1fffff) AM_READWRITE(flash_s1_r, flash_s1_w) AM_RANGE(0x1f200000, 0x1f3fffff) AM_READWRITE(flash_s2_r, flash_s2_w) @@ -895,13 +965,12 @@ static void psx_spu_irq(running_device *device, UINT32 data) static const psx_spu_interface psxspu_interface = { - &g_p_n_psxram, psx_spu_irq, psx_dma_install_read_handler, psx_dma_install_write_handler }; -static MACHINE_CONFIG_START( coh3002t, driver_device ) +static MACHINE_CONFIG_START( coh3002t, taitogn_state ) /* basic machine hardware */ MDRV_CPU_ADD( "maincpu", PSXCPU, XTAL_100MHz ) MDRV_CPU_PROGRAM_MAP( zn_map) diff --git a/src/mame/drivers/twinkle.c b/src/mame/drivers/twinkle.c index 4e0c5d877eb..306b3f6d402 100644 --- a/src/mame/drivers/twinkle.c +++ b/src/mame/drivers/twinkle.c @@ -236,33 +236,43 @@ Notes: #include "sound/cdda.h" #include "sound/rf5c400.h" -static UINT16 twinkle_spu_ctrl; // SPU board control register -static UINT8 twinkle_spu_shared[0x400]; // SPU/PSX shared dual-ported RAM +class twinkle_state : public psx_state +{ +public: + twinkle_state(running_machine &machine, const driver_device_config_base &config) + : psx_state(machine, config) { } + + UINT16 spu_ctrl; // SPU board control register + UINT8 spu_shared[0x400]; // SPU/PSX shared dual-ported RAM + UINT32 unknown; + + int io_offset; + int output_last[ 0x100 ]; + int last_io_offset; + UINT8 sector_buffer[ 4096 ]; +}; /* RTC */ -static UINT32 twinkle_unknown; - static WRITE32_HANDLER( twinkle_unknown_w ) { + twinkle_state *state = space->machine->driver_data(); + /* printf( "set unknown data=%08x\n", data ); */ - twinkle_unknown = data; + state->unknown = data; } static READ32_HANDLER( twinkle_unknown_r ) { - UINT32 data = twinkle_unknown; + twinkle_state *state = space->machine->driver_data(); + UINT32 data = state->unknown; /* printf( "get unknown data=%08x\n", data ); */ return data; } -static int io_offset; -static int output_last[ 0x100 ]; -static int last_io_offset; - #define LED_A1 0x0001 #define LED_A2 0x0002 #define LED_B 0x0004 @@ -425,17 +435,19 @@ static const UINT16 asciicharset[]= static WRITE32_HANDLER( twinkle_io_w ) { + twinkle_state *state = space->machine->driver_data(); + if( ACCESSING_BITS_16_23 ) { - io_offset = ( data >> 16 ) & 0xff; + state->io_offset = ( data >> 16 ) & 0xff; } if( ACCESSING_BITS_0_7 ) { - if( output_last[ io_offset ] != ( data & 0xff ) ) + if( state->output_last[ state->io_offset ] != ( data & 0xff ) ) { - output_last[ io_offset ] = ( data & 0xff ); + state->output_last[ state->io_offset ] = ( data & 0xff ); - switch( io_offset ) + switch( state->io_offset ) { /* ? */ case 0x07: @@ -456,7 +468,7 @@ static WRITE32_HANDLER( twinkle_io_w ) case 0x6f: case 0x77: case 0x7f: - output_set_indexed_value( "led", ( io_offset - 7 ) / 8, asciicharset[ ( data ^ 0xff ) & 0x7f ] ); + output_set_indexed_value( "led", ( state->io_offset - 7 ) / 8, asciicharset[ ( data ^ 0xff ) & 0x7f ] ); break; case 0x87: @@ -475,12 +487,12 @@ static WRITE32_HANDLER( twinkle_io_w ) if( ( data & 0xfe ) != 0xfe ) { - printf("%02x = %02x\n", io_offset, data & 0xff ); + printf("%02x = %02x\n", state->io_offset, data & 0xff ); } break; default: - printf( "unknown io %02x = %02x\n", io_offset, data & 0xff ); + printf( "unknown io %02x = %02x\n", state->io_offset, data & 0xff ); break; } } @@ -489,11 +501,12 @@ static WRITE32_HANDLER( twinkle_io_w ) static READ32_HANDLER(twinkle_io_r) { + twinkle_state *state = space->machine->driver_data(); UINT32 data = 0; if( ACCESSING_BITS_0_7 ) { - switch( io_offset ) + switch( state->io_offset ) { case 0x07: data |= input_port_read( space->machine, "IN0" ); @@ -520,9 +533,9 @@ static READ32_HANDLER(twinkle_io_r) break; default: - if( last_io_offset != io_offset ) + if( state->last_io_offset != state->io_offset ) { - last_io_offset = io_offset; + state->last_io_offset = state->io_offset; } break; @@ -580,14 +593,16 @@ static WRITE32_HANDLER(serial_w) static WRITE32_HANDLER(shared_psx_w) { + twinkle_state *state = space->machine->driver_data(); + if (mem_mask == 0xff) { - twinkle_spu_shared[offset*2] = data; + state->spu_shared[offset*2] = data; // printf("shared_psx_w: %x to %x (%x), mask %x (PC=%x)\n", data, offset, offset*2, mem_mask, cpu_get_pc(space->cpu)); } else if (mem_mask == 0xff0000) { - twinkle_spu_shared[(offset*2)+1] = data; + state->spu_shared[(offset*2)+1] = data; // printf("shared_psx_w: %x to %x (%x), mask %x (PC=%x)\n", data, offset, (offset*2)+1, mem_mask, cpu_get_pc(space->cpu)); } else @@ -598,9 +613,10 @@ static WRITE32_HANDLER(shared_psx_w) static READ32_HANDLER(shared_psx_r) { + twinkle_state *state = space->machine->driver_data(); UINT32 result; - result = twinkle_spu_shared[offset*2] | twinkle_spu_shared[(offset*2)+1]<<16; + result = state->spu_shared[offset*2] | state->spu_shared[(offset*2)+1]<<16; // printf("shared_psx_r: @ %x (%x %x), mask %x = %x (PC=%x)\n", offset, offset*2, (offset*2)+1, mem_mask, result, cpu_get_pc(space->cpu)); @@ -610,7 +626,7 @@ static READ32_HANDLER(shared_psx_r) } static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") AM_BASE(&g_p_n_psxram) AM_SIZE(&g_n_psxramsize) /* ram */ + AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") /* ram */ AM_RANGE(0x1f000000, 0x1f0007ff) AM_READWRITE(shared_psx_r, shared_psx_w) AM_RANGE(0x1f200000, 0x1f20001f) AM_READWRITE(am53cf96_r, am53cf96_w) AM_RANGE(0x1f20a01c, 0x1f20a01f) AM_WRITENOP /* scsi? */ @@ -656,9 +672,11 @@ ADDRESS_MAP_END /* SPU board */ -static void ide_interrupt(running_device *device, int state) +static void ide_interrupt(running_device *device, int state_) { - if ((state) && (twinkle_spu_ctrl & 0x0400)) + twinkle_state *state = device->machine->driver_data(); + + if ((state_) && (state->spu_ctrl & 0x0400)) { cputag_set_input_line(device->machine, "audiocpu", M68K_IRQ_6, ASSERT_LINE); } @@ -694,24 +712,26 @@ static WRITE16_DEVICE_HANDLER( twinkle_ide_w ) */ static WRITE16_HANDLER( twinkle_spu_ctrl_w ) { - if ((!(data & 0x0080)) && (twinkle_spu_ctrl & 0x0080)) + twinkle_state *state = space->machine->driver_data(); + + if ((!(data & 0x0080)) && (state->spu_ctrl & 0x0080)) { cpu_set_input_line(space->cpu, M68K_IRQ_1, CLEAR_LINE); } - else if ((!(data & 0x0100)) && (twinkle_spu_ctrl & 0x0100)) + else if ((!(data & 0x0100)) && (state->spu_ctrl & 0x0100)) { cpu_set_input_line(space->cpu, M68K_IRQ_2, CLEAR_LINE); } - else if ((!(data & 0x0200)) && (twinkle_spu_ctrl & 0x0200)) + else if ((!(data & 0x0200)) && (state->spu_ctrl & 0x0200)) { cpu_set_input_line(space->cpu, M68K_IRQ_4, CLEAR_LINE); } - else if ((!(data & 0x0400)) && (twinkle_spu_ctrl & 0x0400)) + else if ((!(data & 0x0400)) && (state->spu_ctrl & 0x0400)) { cpu_set_input_line(space->cpu, M68K_IRQ_6, CLEAR_LINE); } - twinkle_spu_ctrl = data; + state->spu_ctrl = data; } static READ16_HANDLER( twinkle_waveram_r ) @@ -730,16 +750,20 @@ static WRITE16_HANDLER( twinkle_waveram_w ) static READ16_HANDLER( shared_68k_r ) { + twinkle_state *state = space->machine->driver_data(); + // printf("shared_68k_r: @ %x, mask %x\n", offset, mem_mask); - return twinkle_spu_shared[offset]; + return state->spu_shared[offset]; } static WRITE16_HANDLER( shared_68k_w ) { + twinkle_state *state = space->machine->driver_data(); + // printf("shared_68k_w: %x to %x, mask %x\n", data, offset, mem_mask); - twinkle_spu_shared[offset] = data & 0xff; + state->spu_shared[offset] = data & 0xff; } static ADDRESS_MAP_START( sound_map, ADDRESS_SPACE_PROGRAM, 16 ) @@ -759,18 +783,18 @@ ADDRESS_MAP_END /* SCSI */ -static UINT8 sector_buffer[ 4096 ]; - static void scsi_dma_read( running_machine *machine, UINT32 n_address, INT32 n_size ) { + twinkle_state *state = machine->driver_data(); + UINT32 *p_n_psxram = state->p_n_psxram; int i; int n_this; while( n_size > 0 ) { - if( n_size > sizeof( sector_buffer ) / 4 ) + if( n_size > sizeof( state->sector_buffer ) / 4 ) { - n_this = sizeof( sector_buffer ) / 4; + n_this = sizeof( state->sector_buffer ) / 4; } else { @@ -779,12 +803,12 @@ static void scsi_dma_read( running_machine *machine, UINT32 n_address, INT32 n_s if( n_this < 2048 / 4 ) { /* non-READ commands */ - am53cf96_read_data( n_this * 4, sector_buffer ); + am53cf96_read_data( n_this * 4, state->sector_buffer ); } else { /* assume normal 2048 byte data for now */ - am53cf96_read_data( 2048, sector_buffer ); + am53cf96_read_data( 2048, state->sector_buffer ); n_this = 2048 / 4; } n_size -= n_this; @@ -792,11 +816,11 @@ static void scsi_dma_read( running_machine *machine, UINT32 n_address, INT32 n_s i = 0; while( n_this > 0 ) { - g_p_n_psxram[ n_address / 4 ] = - ( sector_buffer[ i + 0 ] << 0 ) | - ( sector_buffer[ i + 1 ] << 8 ) | - ( sector_buffer[ i + 2 ] << 16 ) | - ( sector_buffer[ i + 3 ] << 24 ); + p_n_psxram[ n_address / 4 ] = + ( state->sector_buffer[ i + 0 ] << 0 ) | + ( state->sector_buffer[ i + 1 ] << 8 ) | + ( state->sector_buffer[ i + 2 ] << 16 ) | + ( state->sector_buffer[ i + 3 ] << 24 ); n_address += 4; i += 4; n_this--; @@ -806,14 +830,16 @@ static void scsi_dma_read( running_machine *machine, UINT32 n_address, INT32 n_s static void scsi_dma_write( running_machine *machine, UINT32 n_address, INT32 n_size ) { + twinkle_state *state = machine->driver_data(); + UINT32 *p_n_psxram = state->p_n_psxram; int i; int n_this; while( n_size > 0 ) { - if( n_size > sizeof( sector_buffer ) / 4 ) + if( n_size > sizeof( state->sector_buffer ) / 4 ) { - n_this = sizeof( sector_buffer ) / 4; + n_this = sizeof( state->sector_buffer ) / 4; } else { @@ -824,16 +850,16 @@ static void scsi_dma_write( running_machine *machine, UINT32 n_address, INT32 n_ i = 0; while( n_this > 0 ) { - sector_buffer[ i + 0 ] = ( g_p_n_psxram[ n_address / 4 ] >> 0 ) & 0xff; - sector_buffer[ i + 1 ] = ( g_p_n_psxram[ n_address / 4 ] >> 8 ) & 0xff; - sector_buffer[ i + 2 ] = ( g_p_n_psxram[ n_address / 4 ] >> 16 ) & 0xff; - sector_buffer[ i + 3 ] = ( g_p_n_psxram[ n_address / 4 ] >> 24 ) & 0xff; + state->sector_buffer[ i + 0 ] = ( p_n_psxram[ n_address / 4 ] >> 0 ) & 0xff; + state->sector_buffer[ i + 1 ] = ( p_n_psxram[ n_address / 4 ] >> 8 ) & 0xff; + state->sector_buffer[ i + 2 ] = ( p_n_psxram[ n_address / 4 ] >> 16 ) & 0xff; + state->sector_buffer[ i + 3 ] = ( p_n_psxram[ n_address / 4 ] >> 24 ) & 0xff; n_address += 4; i += 4; n_this--; } - am53cf96_write_data( n_this * 4, sector_buffer ); + am53cf96_write_data( n_this * 4, state->sector_buffer ); } } @@ -860,8 +886,8 @@ static DRIVER_INIT( twinkle ) { psx_driver_init(machine); am53cf96_init(machine, &scsi_intf); - psx_dma_install_read_handler(5, scsi_dma_read); - psx_dma_install_write_handler(5, scsi_dma_write); + psx_dma_install_read_handler(machine, 5, scsi_dma_read); + psx_dma_install_write_handler(machine, 5, scsi_dma_write); running_device *i2cmem = machine->device("security"); i2cmem_e0_write( i2cmem, 0 ); @@ -885,7 +911,6 @@ static void spu_irq(running_device *device, UINT32 data) static const psx_spu_interface twinkle_psxspu_interface = { - &g_p_n_psxram, spu_irq, psx_dma_install_read_handler, psx_dma_install_write_handler @@ -896,9 +921,9 @@ static const i2cmem_interface i2cmem_interface = I2CMEM_SLAVE_ADDRESS, 0, 0x100 }; -static MACHINE_CONFIG_START( twinkle, driver_device ) +static MACHINE_CONFIG_START( twinkle, twinkle_state ) /* basic machine hardware */ - MDRV_CPU_ADD("maincpu", PSXCPU, XTAL_67_7376MHz ) + MDRV_CPU_ADD( "maincpu", PSXCPU, XTAL_67_7376MHz ) MDRV_CPU_PROGRAM_MAP( main_map ) MDRV_CPU_VBLANK_INT( "mainscreen", psx_vblank ) diff --git a/src/mame/drivers/zn.c b/src/mame/drivers/zn.c index 34e1090a936..1da61e76361 100644 --- a/src/mame/drivers/zn.c +++ b/src/mame/drivers/zn.c @@ -29,6 +29,34 @@ #define VERBOSE_LEVEL ( 0 ) +class zn_state : public psx_state +{ +public: + zn_state(running_machine &machine, const driver_device_config_base &config) + : psx_state(machine, config) { } + + UINT32 m_n_znsecsel; + UINT32 m_b_znsecport; + int m_n_dip_bit; + int m_b_lastclock; + emu_timer *dip_timer; + + size_t taitofx1_eeprom_size1; + UINT8 *taitofx1_eeprom1; + size_t taitofx1_eeprom_size2; + UINT8 *taitofx1_eeprom2; + + UINT32 bam2_mcu_command; + int jdredd_gun_mux; + + size_t nbajamex_eeprom_size; + UINT8 *nbajamex_eeprom; + + int cbaj_to_z80; + int cbaj_to_r3k; + int latch_to_z80; +}; + INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, const char *s_fmt, ... ) { if( VERBOSE_LEVEL >= n_level ) @@ -42,14 +70,16 @@ INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, } } -INLINE UINT8 psxreadbyte( UINT32 n_address ) +#ifdef UNUSED_FUNCTION +INLINE UINT8 psxreadbyte( UINT32 *p_n_psxram, UINT32 n_address ) { - return *( (UINT8 *)g_p_n_psxram + BYTE4_XOR_LE( n_address ) ); + return *( (UINT8 *)p_n_psxram + BYTE4_XOR_LE( n_address ) ); } +#endif -INLINE void psxwritebyte( UINT32 n_address, UINT8 n_data ) +INLINE void psxwritebyte( UINT32 *p_n_psxram, UINT32 n_address, UINT8 n_data ) { - *( (UINT8 *)g_p_n_psxram + BYTE4_XOR_LE( n_address ) ) = n_data; + *( (UINT8 *)p_n_psxram + BYTE4_XOR_LE( n_address ) ) = n_data; } static const UINT8 ac01[ 8 ] = { 0x80, 0x1c, 0xe2, 0xfa, 0xf9, 0xf1, 0x30, 0xc0 }; @@ -204,115 +234,121 @@ static const struct { NULL, NULL, NULL } }; -static UINT32 m_n_znsecsel; -static UINT32 m_b_znsecport; -static int m_n_dip_bit; -static int m_b_lastclock; -static emu_timer *dip_timer; - static READ32_HANDLER( znsecsel_r ) { + zn_state *state = space->machine->driver_data(); + verboselog( space->machine, 2, "znsecsel_r( %08x, %08x )\n", offset, mem_mask ); - return m_n_znsecsel; + return state->m_n_znsecsel; } static void sio_znsec0_handler( running_machine *machine, int n_data ) { + zn_state *state = machine->driver_data(); + if( ( n_data & PSX_SIO_OUT_CLOCK ) == 0 ) { - if( m_b_lastclock ) + if( state->m_b_lastclock ) { psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( znsec_step( 0, ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA ); } - m_b_lastclock = 0; + state->m_b_lastclock = 0; } else { - m_b_lastclock = 1; + state->m_b_lastclock = 1; } } static void sio_znsec1_handler( running_machine *machine, int n_data ) { + zn_state *state = machine->driver_data(); + if( ( n_data & PSX_SIO_OUT_CLOCK ) == 0 ) { - if( m_b_lastclock ) + if( state->m_b_lastclock ) { psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( znsec_step( 1, ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA ); } - m_b_lastclock = 0; + state->m_b_lastclock = 0; } else { - m_b_lastclock = 1; + state->m_b_lastclock = 1; } } static void sio_pad_handler( running_machine *machine, int n_data ) { + zn_state *state = machine->driver_data(); + if( ( n_data & PSX_SIO_OUT_DTR ) != 0 ) { - m_b_znsecport = 1; + state->m_b_znsecport = 1; } else { - m_b_znsecport = 0; + state->m_b_znsecport = 0; } - verboselog( machine, 2, "read pad %04x %04x %02x\n", m_n_znsecsel, m_b_znsecport, n_data ); + verboselog( machine, 2, "read pad %04x %04x %02x\n", state->m_n_znsecsel, state->m_b_znsecport, n_data ); psx_sio_input( machine, 0, PSX_SIO_IN_DATA | PSX_SIO_IN_DSR, PSX_SIO_IN_DATA | PSX_SIO_IN_DSR ); } static void sio_dip_handler( running_machine *machine, int n_data ) { + zn_state *state = machine->driver_data(); + if( ( n_data & PSX_SIO_OUT_CLOCK ) == 0 ) { - if( m_b_lastclock ) + if( state->m_b_lastclock ) { - int bit = ( ( input_port_read(machine, "DSW") >> m_n_dip_bit ) & 1 ); + int bit = ( ( input_port_read(machine, "DSW") >> state->m_n_dip_bit ) & 1 ); verboselog( machine, 2, "read dip %02x -> %02x\n", n_data, bit * PSX_SIO_IN_DATA ); psx_sio_input( machine, 0, PSX_SIO_IN_DATA, bit * PSX_SIO_IN_DATA ); - m_n_dip_bit++; - m_n_dip_bit &= 7; + state->m_n_dip_bit++; + state->m_n_dip_bit &= 7; } - m_b_lastclock = 0; + state->m_b_lastclock = 0; } else { - m_b_lastclock = 1; + state->m_b_lastclock = 1; } } static WRITE32_HANDLER( znsecsel_w ) { - COMBINE_DATA( &m_n_znsecsel ); + zn_state *state = space->machine->driver_data(); - if( ( m_n_znsecsel & 0x80 ) == 0 ) + COMBINE_DATA( &state->m_n_znsecsel ); + + if( ( state->m_n_znsecsel & 0x80 ) == 0 ) { - psx_sio_install_handler( 0, sio_pad_handler ); + psx_sio_install_handler( space->machine, 0, sio_pad_handler ); psx_sio_input( space->machine, 0, PSX_SIO_IN_DSR, 0 ); } - else if( ( m_n_znsecsel & 0x08 ) == 0 ) + else if( ( state->m_n_znsecsel & 0x08 ) == 0 ) { znsec_start( 1 ); - psx_sio_install_handler( 0, sio_znsec1_handler ); + psx_sio_install_handler( space->machine, 0, sio_znsec1_handler ); psx_sio_input( space->machine, 0, PSX_SIO_IN_DSR, 0 ); } - else if( ( m_n_znsecsel & 0x04 ) == 0 ) + else if( ( state->m_n_znsecsel & 0x04 ) == 0 ) { znsec_start( 0 ); - psx_sio_install_handler( 0, sio_znsec0_handler ); + psx_sio_install_handler( space->machine, 0, sio_znsec0_handler ); psx_sio_input( space->machine, 0, PSX_SIO_IN_DSR, 0 ); } else { - m_n_dip_bit = 0; - m_b_lastclock = 1; + state->m_n_dip_bit = 0; + state->m_b_lastclock = 1; - psx_sio_install_handler( 0, sio_dip_handler ); + psx_sio_install_handler( space->machine, 0, sio_dip_handler ); psx_sio_input( space->machine, 0, PSX_SIO_IN_DSR, 0 ); - timer_adjust_oneshot( dip_timer, downcast(space->cpu)->cycles_to_attotime( 100 ), 1 ); + timer_adjust_oneshot( state->dip_timer, downcast(space->cpu)->cycles_to_attotime( 100 ), 1 ); } verboselog( space->machine, 2, "znsecsel_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); @@ -320,11 +356,12 @@ static WRITE32_HANDLER( znsecsel_w ) static TIMER_CALLBACK( dip_timer_fired ) { + zn_state *state = machine->driver_data(); psx_sio_input( machine, 0, PSX_SIO_IN_DSR, param * PSX_SIO_IN_DSR ); if( param ) { - timer_adjust_oneshot( dip_timer, machine->device( "maincpu" )->cycles_to_attotime(50 ), 0 ); + timer_adjust_oneshot( state->dip_timer, machine->device( "maincpu" )->cycles_to_attotime(50 ), 0 ); } } @@ -380,7 +417,7 @@ static WRITE32_HANDLER( coin_w ) } static ADDRESS_MAP_START( zn_map, ADDRESS_SPACE_PROGRAM, 32 ) - AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") AM_BASE(&g_p_n_psxram) AM_SIZE(&g_n_psxramsize) /* ram */ + AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_SHARE("share1") /* ram */ AM_RANGE(0x00400000, 0x007fffff) AM_RAM AM_SHARE("share1") /* ram mirror */ AM_RANGE(0x1f800000, 0x1f8003ff) AM_RAM /* scratchpad */ AM_RANGE(0x1f801000, 0x1f80100f) AM_RAM /* ?? */ @@ -427,6 +464,7 @@ ADDRESS_MAP_END static void zn_driver_init( running_machine *machine ) { + zn_state *state = machine->driver_data(); int n_game; psx_driver_init(machine); @@ -438,13 +476,13 @@ static void zn_driver_init( running_machine *machine ) { znsec_init( 0, zn_config_table[ n_game ].p_n_mainsec ); znsec_init( 1, zn_config_table[ n_game ].p_n_gamesec ); - psx_sio_install_handler( 0, sio_pad_handler ); + psx_sio_install_handler( machine, 0, sio_pad_handler ); break; } n_game++; } - dip_timer = timer_alloc(machine, dip_timer_fired, NULL ); + state->dip_timer = timer_alloc( machine, dip_timer_fired, NULL ); } static void psx_spu_irq(running_device *device, UINT32 data) @@ -454,7 +492,6 @@ static void psx_spu_irq(running_device *device, UINT32 data) static const psx_spu_interface psxspu_interface = { - &g_p_n_psxram, psx_spu_irq, psx_dma_install_read_handler, psx_dma_install_write_handler @@ -462,12 +499,14 @@ static const psx_spu_interface psxspu_interface = static void zn_machine_init( running_machine *machine ) { - m_n_dip_bit = 0; - m_b_lastclock = 1; + zn_state *state = machine->driver_data(); + + state->m_n_dip_bit = 0; + state->m_b_lastclock = 1; psx_machine_init(machine); } -static MACHINE_CONFIG_START( zn1_1mb_vram, driver_device ) +static MACHINE_CONFIG_START( zn1_1mb_vram, zn_state ) /* basic machine hardware */ MDRV_CPU_ADD( "maincpu", PSXCPU, XTAL_67_7376MHz ) MDRV_CPU_PROGRAM_MAP( zn_map) @@ -504,7 +543,7 @@ static MACHINE_CONFIG_DERIVED( zn1_2mb_vram, zn1_1mb_vram ) MDRV_SCREEN_SIZE( 1024, 1024 ) MACHINE_CONFIG_END -static MACHINE_CONFIG_START( zn2, driver_device ) +static MACHINE_CONFIG_START( zn2, zn_state ) /* basic machine hardware */ MDRV_CPU_ADD( "maincpu", PSXCPU, XTAL_100MHz ) MDRV_CPU_PROGRAM_MAP( zn_map) @@ -657,12 +696,12 @@ static READ32_HANDLER( capcom_kickharness_r ) static WRITE32_HANDLER( bank_coh1000c_w ) { - memory_set_bankptr(space->machine, "bank2", memory_region( space->machine, "user2" ) + 0x400000 + ( data * 0x400000 ) ); + memory_set_bankptr( space->machine, "bank2", memory_region( space->machine, "user2" ) + 0x400000 + ( data * 0x400000 ) ); } static WRITE8_HANDLER( qsound_bankswitch_w ) { - memory_set_bankptr(space->machine, "bank10", memory_region( space->machine, "audiocpu" ) + 0x10000 + ( ( data & 0x0f ) * 0x4000 ) ); + memory_set_bankptr( space->machine, "bank10", memory_region( space->machine, "audiocpu" ) + 0x10000 + ( ( data & 0x0f ) * 0x4000 ) ); } static INTERRUPT_GEN( qsound_interrupt ) @@ -700,9 +739,9 @@ static DRIVER_INIT( coh1000c ) static MACHINE_RESET( coh1000c ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ - memory_set_bankptr(machine, "bank2", memory_region( machine, "user2" ) + 0x400000 ); /* banked game rom */ - memory_set_bankptr(machine, "bank3", memory_region( machine, "user3" ) ); /* country rom */ + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ + memory_set_bankptr( machine, "bank2", memory_region( machine, "user2" ) + 0x400000 ); /* banked game rom */ + memory_set_bankptr( machine, "bank3", memory_region( machine, "user3" ) ); /* country rom */ zn_machine_init(machine); } @@ -722,7 +761,7 @@ ADDRESS_MAP_END static MACHINE_CONFIG_DERIVED( coh1000c, zn1_1mb_vram ) - MDRV_CPU_ADD("audiocpu", Z80, 8000000 ) /* 8MHz ?? */ + MDRV_CPU_ADD( "audiocpu", Z80, 8000000 ) /* 8MHz ?? */ MDRV_CPU_PROGRAM_MAP( qsound_map) MDRV_CPU_IO_MAP( qsound_portmap) MDRV_CPU_VBLANK_INT_HACK( qsound_interrupt, 4 ) /* 4 interrupts per frame ?? */ @@ -736,7 +775,7 @@ MACHINE_CONFIG_END static MACHINE_CONFIG_DERIVED( coh1002c, zn1_2mb_vram ) - MDRV_CPU_ADD("audiocpu", Z80, 8000000 ) /* 8MHz ?? */ + MDRV_CPU_ADD( "audiocpu", Z80, 8000000 ) /* 8MHz ?? */ MDRV_CPU_PROGRAM_MAP( qsound_map) MDRV_CPU_IO_MAP( qsound_portmap) MDRV_CPU_VBLANK_INT_HACK( qsound_interrupt, 4 ) /* 4 interrupts per frame ?? */ @@ -890,7 +929,7 @@ Notes: static WRITE32_HANDLER( bank_coh3002c_w ) { - memory_set_bankptr(space->machine, "bank2", memory_region( space->machine, "user2" ) + 0x400000 + ( data * 0x400000 ) ); + memory_set_bankptr( space->machine, "bank2", memory_region( space->machine, "user2" ) + 0x400000 + ( data * 0x400000 ) ); } static DRIVER_INIT( coh3002c ) @@ -908,9 +947,9 @@ static DRIVER_INIT( coh3002c ) static MACHINE_RESET( coh3002c ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ - memory_set_bankptr(machine, "bank2", memory_region( machine, "user2" ) + 0x400000 ); /* banked game rom */ - memory_set_bankptr(machine, "bank3", memory_region( machine, "user3" ) ); /* country rom */ + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ + memory_set_bankptr( machine, "bank2", memory_region( machine, "user2" ) + 0x400000 ); /* banked game rom */ + memory_set_bankptr( machine, "bank3", memory_region( machine, "user3" ) ); /* country rom */ zn_machine_init(machine); } @@ -1146,22 +1185,17 @@ Notes: FM1208S - RAMTRON 4096bit Nonvolatile Ferroelectric RAM (512w x 8b) */ -static size_t taitofx1_eeprom_size1 = 0; -static UINT8 *taitofx1_eeprom1 = NULL; -static size_t taitofx1_eeprom_size2 = 0; -static UINT8 *taitofx1_eeprom2 = NULL; - static WRITE32_HANDLER( bank_coh1000t_w ) { running_device *mb3773 = space->machine->device("mb3773"); mb3773_set_ck(mb3773, (data & 0x20) >> 5); verboselog( space->machine, 1, "bank_coh1000t_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); - memory_set_bankptr(space->machine, "bank1", memory_region( space->machine, "user2" ) + ( ( data & 3 ) * 0x800000 ) ); + memory_set_bankptr( space->machine, "bank1", memory_region( space->machine, "user2" ) + ( ( data & 3 ) * 0x800000 ) ); } static WRITE8_HANDLER( fx1a_sound_bankswitch_w ) { - memory_set_bankptr(space->machine, "bank10", memory_region( space->machine, "audiocpu" ) + 0x10000 + ( ( ( data - 1 ) & 0x07 ) * 0x4000 ) ); + memory_set_bankptr( space->machine, "bank10", memory_region( space->machine, "audiocpu" ) + 0x10000 + ( ( ( data - 1 ) & 0x07 ) * 0x4000 ) ); } static READ32_HANDLER( taitofx1a_ymsound_r ) @@ -1186,21 +1220,23 @@ static WRITE32_HANDLER( taitofx1a_ymsound_w ) static DRIVER_INIT( coh1000ta ) { - taitofx1_eeprom_size1 = 0x200; taitofx1_eeprom1 = auto_alloc_array(machine, UINT8, taitofx1_eeprom_size1 ); - machine->device("eeprom1")->set_base(taitofx1_eeprom1, taitofx1_eeprom_size1); + zn_state *state = machine->driver_data(); + state->taitofx1_eeprom_size1 = 0x200; state->taitofx1_eeprom1 = auto_alloc_array( machine, UINT8, state->taitofx1_eeprom_size1 ); + machine->device("eeprom1")->set_base(state->taitofx1_eeprom1, state->taitofx1_eeprom_size1); memory_install_read_bank ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f000000, 0x1f7fffff, 0, 0, "bank1" ); /* banked game rom */ memory_install_write32_handler ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb40000, 0x1fb40003, 0, 0, bank_coh1000t_w ); /* bankswitch */ memory_install_readwrite32_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb80000, 0x1fb80003, 0, 0, taitofx1a_ymsound_r, taitofx1a_ymsound_w ); - memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbe0000, 0x1fbe0000 + ( taitofx1_eeprom_size1 - 1 ), 0, 0, "bank2" ); + memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbe0000, 0x1fbe0000 + ( state->taitofx1_eeprom_size1 - 1 ), 0, 0, "bank2" ); zn_driver_init(machine); } static MACHINE_RESET( coh1000ta ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); /* banked game rom */ - memory_set_bankptr(machine, "bank2", taitofx1_eeprom1 ); + zn_state *state = machine->driver_data(); + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); /* banked game rom */ + memory_set_bankptr( machine, "bank2", state->taitofx1_eeprom1 ); zn_machine_init(machine); } @@ -1242,9 +1278,9 @@ static MACHINE_CONFIG_DERIVED( coh1000ta, zn1_1mb_vram ) MDRV_SOUND_ADD("ymsnd", YM2610B, 16000000/2) MDRV_SOUND_CONFIG(ym2610_config) - MDRV_SOUND_ROUTE(0, "lspeaker", 0.25) + MDRV_SOUND_ROUTE(0, "lspeaker", 0.25) MDRV_SOUND_ROUTE(0, "rspeaker", 0.25) - MDRV_SOUND_ROUTE(1, "lspeaker", 1.0) + MDRV_SOUND_ROUTE(1, "lspeaker", 1.0) MDRV_SOUND_ROUTE(2, "rspeaker", 1.0) MDRV_MB3773_ADD("mb3773") @@ -1271,28 +1307,32 @@ static READ32_HANDLER( taitofx1b_sound_r ) static DRIVER_INIT( coh1000tb ) { - taitofx1_eeprom_size1 = 0x400; taitofx1_eeprom1 = auto_alloc_array(machine, UINT8, taitofx1_eeprom_size1 ); - taitofx1_eeprom_size2 = 0x200; taitofx1_eeprom2 = auto_alloc_array(machine, UINT8, taitofx1_eeprom_size2 ); + zn_state *state = machine->driver_data(); - machine->device("eeprom1")->set_base(taitofx1_eeprom1, taitofx1_eeprom_size1); - machine->device("eeprom2")->set_base(taitofx1_eeprom2, taitofx1_eeprom_size2); + state->taitofx1_eeprom_size1 = 0x400; state->taitofx1_eeprom1 = auto_alloc_array( machine, UINT8, state->taitofx1_eeprom_size1 ); + state->taitofx1_eeprom_size2 = 0x200; state->taitofx1_eeprom2 = auto_alloc_array( machine, UINT8, state->taitofx1_eeprom_size2 ); + + machine->device("eeprom1")->set_base(state->taitofx1_eeprom1, state->taitofx1_eeprom_size1); + machine->device("eeprom2")->set_base(state->taitofx1_eeprom2, state->taitofx1_eeprom_size2); memory_install_read_bank ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f000000, 0x1f7fffff, 0, 0, "bank1" ); /* banked game rom */ - memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb00000, 0x1fb00000 + ( taitofx1_eeprom_size1 - 1 ), 0, 0, "bank2" ); + memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb00000, 0x1fb00000 + ( state->taitofx1_eeprom_size1 - 1 ), 0, 0, "bank2" ); memory_install_write32_handler ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb40000, 0x1fb40003, 0, 0, bank_coh1000t_w ); /* bankswitch */ memory_install_write32_handler ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb80000, 0x1fb80003, 0, 0, taitofx1b_volume_w ); memory_install_write32_handler ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fba0000, 0x1fba0003, 0, 0, taitofx1b_sound_w ); memory_install_read32_handler ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbc0000, 0x1fbc0003, 0, 0, taitofx1b_sound_r ); - memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbe0000, 0x1fbe0000 + ( taitofx1_eeprom_size2 - 1 ), 0, 0, "bank3" ); + memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbe0000, 0x1fbe0000 + ( state->taitofx1_eeprom_size2 - 1 ), 0, 0, "bank3" ); zn_driver_init(machine); } static MACHINE_RESET( coh1000tb ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); /* banked game rom */ - memory_set_bankptr(machine, "bank2", taitofx1_eeprom1 ); - memory_set_bankptr(machine, "bank3", taitofx1_eeprom2 ); + zn_state *state = machine->driver_data(); + + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); /* banked game rom */ + memory_set_bankptr( machine, "bank2", state->taitofx1_eeprom1 ); + memory_set_bankptr( machine, "bank3", state->taitofx1_eeprom2 ); zn_machine_init(machine); } @@ -1433,6 +1473,8 @@ static void atpsx_interrupt(running_device *device, int state) static void atpsx_dma_read( running_machine *machine, UINT32 n_address, INT32 n_size ) { + zn_state *state = machine->driver_data(); + UINT32 *p_n_psxram = state->p_n_psxram; running_device *ide = machine->device("ide"); logerror("DMA read: %d bytes (%d words) to %08x\n", n_size<<2, n_size, n_address); @@ -1448,7 +1490,7 @@ static void atpsx_dma_read( running_machine *machine, UINT32 n_address, INT32 n_ n_size <<= 2; while( n_size > 0 ) { - psxwritebyte( n_address, ide_controller32_r( ide, 0x1f0 / 4, 0x000000ff ) ); + psxwritebyte( p_n_psxram, n_address, ide_controller32_r( ide, 0x1f0 / 4, 0x000000ff ) ); n_address++; n_size--; } @@ -1474,12 +1516,12 @@ static DRIVER_INIT( coh1000w ) static MACHINE_RESET( coh1000w ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ zn_machine_init(machine); devtag_reset(machine, "ide"); - psx_dma_install_read_handler(5, atpsx_dma_read); - psx_dma_install_write_handler(5, atpsx_dma_write); + psx_dma_install_read_handler(machine, 5, atpsx_dma_read); + psx_dma_install_write_handler(machine, 5, atpsx_dma_write); } static MACHINE_CONFIG_DERIVED( coh1000w, zn1_2mb_vram ) @@ -1640,7 +1682,7 @@ static WRITE32_HANDLER( coh1002e_bank_w ) { znsecsel_w( space, offset, data, mem_mask ); - memory_set_bankptr(space->machine, "bank1", memory_region( space->machine, "user2" ) + ( ( data & 3 ) * 0x800000 ) ); + memory_set_bankptr( space->machine, "bank1", memory_region( space->machine, "user2" ) + ( ( data & 3 ) * 0x800000 ) ); } static WRITE32_HANDLER( coh1002e_latch_w ) @@ -1662,7 +1704,7 @@ static DRIVER_INIT( coh1002e ) static MACHINE_RESET( coh1002e ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); /* banked game rom */ + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); /* banked game rom */ zn_machine_init(machine); } @@ -1745,26 +1787,29 @@ static WRITE32_HANDLER( bam2_sec_w ) 8007f538 = detected device type. 0 = CDROM, 1 = HDD. */ -static UINT32 bam2_mcu_command; static WRITE32_HANDLER( bam2_mcu_w ) { + zn_state *state = space->machine->driver_data(); + if (offset == 0) { if (ACCESSING_BITS_0_15) { - memory_set_bankptr(space->machine, "bank2", memory_region( space->machine, "user2" ) + ( ( data & 0xf ) * 0x400000 ) ); + memory_set_bankptr( space->machine, "bank2", memory_region( space->machine, "user2" ) + ( ( data & 0xf ) * 0x400000 ) ); } else if (ACCESSING_BITS_16_31) { - bam2_mcu_command = data>>16; - logerror("MCU command: %04x (PC %08x)\n", bam2_mcu_command, cpu_get_pc(space->cpu)); + state->bam2_mcu_command = data>>16; + logerror("MCU command: %04x (PC %08x)\n", state->bam2_mcu_command, cpu_get_pc(space->cpu)); } } } static READ32_HANDLER( bam2_mcu_r ) { + zn_state *state = space->machine->driver_data(); + switch (offset) { case 0: @@ -1774,7 +1819,7 @@ static READ32_HANDLER( bam2_mcu_r ) case 1: logerror("MCU status read @ PC %08x mask %08x\n", cpu_get_pc(space->cpu), mem_mask); - switch (bam2_mcu_command) + switch (state->bam2_mcu_command) { case 0x7f: // first drive check case 0x1c: // second drive check (causes HDD detected) @@ -1806,8 +1851,8 @@ static DRIVER_INIT( bam2 ) static MACHINE_RESET( bam2 ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ - memory_set_bankptr(machine, "bank2", memory_region( machine, "user2" ) + 0x400000 ); /* banked game rom */ + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ + memory_set_bankptr( machine, "bank2", memory_region( machine, "user2" ) + 0x400000 ); /* banked game rom */ zn_machine_init(machine); } @@ -2044,21 +2089,22 @@ static WRITE32_DEVICE_HANDLER( jdredd_ide_w ) } } -static int jdredd_gun_mux = 0; - static CUSTOM_INPUT( jdredd_gun_mux_read ) { - return jdredd_gun_mux; + zn_state *state = field->port->machine->driver_data(); + + return state->jdredd_gun_mux; } static INTERRUPT_GEN( jdredd_vblank ) { + zn_state *state = device->machine->driver_data(); int x; int y; - jdredd_gun_mux = !jdredd_gun_mux; + state->jdredd_gun_mux = !state->jdredd_gun_mux; - if( jdredd_gun_mux == 0 ) + if( state->jdredd_gun_mux == 0 ) { x = input_port_read(device->machine, "GUN1X"); y = input_port_read(device->machine, "GUN1Y"); @@ -2072,15 +2118,12 @@ static INTERRUPT_GEN( jdredd_vblank ) if( x > 0x393 && x < 0xcb2 && y > 0x02d && y < 0x217 ) { - psx_lightgun_set( x, y ); + psx_lightgun_set( device->machine, x, y ); } psx_vblank( device ); } -static size_t nbajamex_eeprom_size; -static UINT8 *nbajamex_eeprom; - static WRITE32_HANDLER( acpsx_00_w ) { verboselog( space->machine, 0, "acpsx_00_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); @@ -2113,19 +2156,22 @@ static READ32_HANDLER( nbajamex_80_r ) static DRIVER_INIT( coh1000a ) { + zn_state *state = machine->driver_data(); + memory_install_read_bank ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f000000, 0x1f1fffff, 0, 0, "bank1" ); memory_install_write32_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbfff00, 0x1fbfff03, 0, 0, acpsx_00_w ); memory_install_write32_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbfff10, 0x1fbfff13, 0, 0, acpsx_10_w ); if( strcmp( machine->gamedrv->name, "nbajamex" ) == 0 ) { - nbajamex_eeprom_size = 0x8000; nbajamex_eeprom = auto_alloc_array(machine, UINT8, nbajamex_eeprom_size ); + state->nbajamex_eeprom_size = 0x8000; + state->nbajamex_eeprom = auto_alloc_array( machine, UINT8, state->nbajamex_eeprom_size ); - memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f200000, 0x1f200000 + ( nbajamex_eeprom_size - 1 ), 0, 0, "bank2" ); + memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f200000, 0x1f200000 + ( state->nbajamex_eeprom_size - 1 ), 0, 0, "bank2" ); memory_install_read32_handler ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbfff08, 0x1fbfff0b, 0, 0, nbajamex_08_r ); memory_install_readwrite32_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbfff80, 0x1fbfff83, 0, 0, nbajamex_80_r, nbajamex_80_w ); - memory_set_bankptr(machine, "bank2", nbajamex_eeprom ); /* ram/eeprom/?? */ + memory_set_bankptr( machine, "bank2", state->nbajamex_eeprom ); /* ram/eeprom/?? */ } if( ( !strcmp( machine->gamedrv->name, "jdredd" ) ) || @@ -2143,7 +2189,7 @@ static DRIVER_INIT( coh1000a ) static MACHINE_RESET( coh1000a ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ zn_machine_init(machine); if( ( !strcmp( machine->gamedrv->name, "jdredd" ) ) || ( !strcmp( machine->gamedrv->name, "jdreddb" ) ) ) @@ -2285,7 +2331,7 @@ Notes: static WRITE32_HANDLER( coh1001l_bnk_w ) { - memory_set_bankptr(space->machine, "bank1", memory_region( space->machine, "user2" ) + ( ( ( data >> 16 ) & 3 ) * 0x800000 ) ); + memory_set_bankptr( space->machine, "bank1", memory_region( space->machine, "user2" ) + ( ( ( data >> 16 ) & 3 ) * 0x800000 ) ); } static DRIVER_INIT( coh1001l ) @@ -2298,7 +2344,7 @@ static DRIVER_INIT( coh1001l ) static MACHINE_RESET( coh1001l ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); /* banked rom */ + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); /* banked rom */ zn_machine_init(machine); } @@ -2327,7 +2373,7 @@ Key: Mother KN01 static WRITE32_HANDLER( coh1002v_bnk_w ) { - memory_set_bankptr(space->machine, "bank2", memory_region( space->machine, "user3" ) + ( data * 0x100000 ) ); + memory_set_bankptr( space->machine, "bank2", memory_region( space->machine, "user3" ) + ( data * 0x100000 ) ); } static DRIVER_INIT( coh1002v ) @@ -2341,8 +2387,8 @@ static DRIVER_INIT( coh1002v ) static MACHINE_RESET( coh1002v ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ - memory_set_bankptr(machine, "bank2", memory_region( machine, "user3" ) ); /* banked rom */ + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); /* fixed game rom */ + memory_set_bankptr( machine, "bank2", memory_region( machine, "user3" ) ); /* banked rom */ zn_machine_init(machine); } @@ -2511,25 +2557,25 @@ Notes: static WRITE32_HANDLER( coh1002m_bank_w ) { verboselog( space->machine, 1, "coh1002m_bank_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); - memory_set_bankptr(space->machine, "bank1", memory_region( space->machine, "user2" ) + ((data>>16) * 0x800000)); + memory_set_bankptr( space->machine, "bank1", memory_region( space->machine, "user2" ) + ((data>>16) * 0x800000) ); } -static int cbaj_to_z80 = 0, cbaj_to_r3k = 0; -static int latch_to_z80; - static READ32_HANDLER( cbaj_z80_r ) { - int ready = cbaj_to_r3k; + zn_state *state = space->machine->driver_data(); + int ready = state->cbaj_to_r3k; - cbaj_to_r3k &= ~2; + state->cbaj_to_r3k &= ~2; return soundlatch2_r(space,0) | ready<<24; } static WRITE32_HANDLER( cbaj_z80_w ) { - cbaj_to_z80 |= 2; - latch_to_z80 = data; + zn_state *state = space->machine->driver_data(); + + state->cbaj_to_z80 |= 2; + state->latch_to_z80 = data; } static DRIVER_INIT( coh1002m ) @@ -2543,27 +2589,33 @@ static DRIVER_INIT( coh1002m ) static MACHINE_RESET( coh1002m ) { - memory_set_bankptr(machine, "bank1", memory_region( machine, "user2" ) ); + memory_set_bankptr( machine, "bank1", memory_region( machine, "user2" ) ); zn_machine_init(machine); } static READ8_HANDLER( cbaj_z80_latch_r ) { - cbaj_to_z80 &= ~2; - return latch_to_z80; + zn_state *state = space->machine->driver_data(); + + state->cbaj_to_z80 &= ~2; + return state->latch_to_z80; } static WRITE8_HANDLER( cbaj_z80_latch_w ) { - cbaj_to_r3k |= 2; + zn_state *state = space->machine->driver_data(); + + state->cbaj_to_r3k |= 2; soundlatch2_w(space, 0, data); } static READ8_HANDLER( cbaj_z80_ready_r ) { - int ret = cbaj_to_z80; + zn_state *state = space->machine->driver_data(); - cbaj_to_z80 &= ~2; + int ret = state->cbaj_to_z80; + + state->cbaj_to_z80 &= ~2; return ret; } diff --git a/src/mame/includes/psx.h b/src/mame/includes/psx.h index 26d64c4363d..dcf1592cf30 100644 --- a/src/mame/includes/psx.h +++ b/src/mame/includes/psx.h @@ -6,21 +6,14 @@ #if !defined( PSX_H ) -/*----------- defined in video/psx.c -----------*/ - -PALETTE_INIT( psx ); -VIDEO_START( psx_type1 ); -VIDEO_START( psx_type2 ); -VIDEO_UPDATE( psx ); -INTERRUPT_GEN( psx_vblank ); -extern void psx_gpu_reset( running_machine *machine ); -extern void psx_gpu_read( running_machine *, UINT32 *p_ram, INT32 n_size ); -extern void psx_gpu_write( running_machine *, UINT32 *p_ram, INT32 n_size ); -READ32_HANDLER( psx_gpu_r ); -WRITE32_HANDLER( psx_gpu_w ); -extern void psx_lightgun_set( int, int ); - -/*----------- defined in machine/psx.c -----------*/ +#define PSX_RC_STOP ( 0x01 ) +#define PSX_RC_RESET ( 0x04 ) /* guess */ +#define PSX_RC_COUNTTARGET ( 0x08 ) +#define PSX_RC_IRQTARGET ( 0x10 ) +#define PSX_RC_IRQOVERFLOW ( 0x20 ) +#define PSX_RC_REPEAT ( 0x40 ) +#define PSX_RC_CLC ( 0x100 ) +#define PSX_RC_DIV ( 0x200 ) #define PSX_IRQ_ROOTCOUNTER3 0x0001 #define PSX_IRQ_CDROM 0x0004 @@ -34,27 +27,6 @@ extern void psx_lightgun_set( int, int ); #define PSX_IRQ_EXTCD 0x0400 #define PSX_IRQ_MASK (PSX_IRQ_ROOTCOUNTER3 | PSX_IRQ_CDROM | PSX_IRQ_DMA | PSX_IRQ_ROOTCOUNTER2 | PSX_IRQ_ROOTCOUNTER1 | PSX_IRQ_ROOTCOUNTER0 | PSX_IRQ_SIO0 | PSX_IRQ_SIO1 | PSX_IRQ_SPU | PSX_IRQ_EXTCD) -extern UINT32 *g_p_n_psxram; -extern size_t g_n_psxramsize; -typedef void ( *psx_dma_read_handler )( running_machine *, UINT32, INT32 ); -typedef void ( *psx_dma_write_handler )( running_machine *, UINT32, INT32 ); -WRITE32_HANDLER( psx_com_delay_w ); -READ32_HANDLER( psx_com_delay_r ); -WRITE32_HANDLER( psx_irq_w ); -READ32_HANDLER( psx_irq_r ); -extern void psx_irq_set( running_machine *, UINT32 ); -extern void psx_dma_install_read_handler( int, psx_dma_read_handler ); -extern void psx_dma_install_write_handler( int, psx_dma_read_handler ); -WRITE32_HANDLER( psx_dma_w ); -READ32_HANDLER( psx_dma_r ); -WRITE32_HANDLER( psx_counter_w ); -READ32_HANDLER( psx_counter_r ); -WRITE32_HANDLER( psx_sio_w ); -READ32_HANDLER( psx_sio_r ); -typedef void ( *psx_sio_handler )( running_machine *, int ); -extern void psx_sio_install_handler( int, psx_sio_handler ); -extern void psx_sio_input( running_machine *, int, int, int ); - #define PSX_SIO_OUT_DATA ( 1 ) /* COMMAND */ #define PSX_SIO_OUT_DTR ( 2 ) /* ATT */ #define PSX_SIO_OUT_RTS ( 4 ) @@ -63,6 +35,59 @@ extern void psx_sio_input( running_machine *, int, int, int ); #define PSX_SIO_IN_DSR ( 2 ) /* ACK */ #define PSX_SIO_IN_CTS ( 4 ) +typedef void ( *psx_dma_read_handler )( running_machine *, UINT32, INT32 ); +typedef void ( *psx_dma_write_handler )( running_machine *, UINT32, INT32 ); +typedef void ( *psx_sio_handler )( running_machine *, int ); + +typedef struct _psx_machine psx_machine; +typedef struct _psx_gpu psx_gpu; + +class psx_state : public driver_device +{ +public: + psx_state(running_machine &machine, const driver_device_config_base &config) + : driver_device(machine, config) { } + + psx_machine *p_psx; + psx_gpu *p_psxgpu; + + UINT32 *p_n_psxram; + size_t n_psxramsize; +}; + + +/*----------- defined in video/psx.c -----------*/ + +PALETTE_INIT( psx ); +VIDEO_START( psx_type1 ); +VIDEO_START( psx_type2 ); +VIDEO_UPDATE( psx ); +INTERRUPT_GEN( psx_vblank ); +extern void psx_gpu_reset( running_machine *machine ); +extern void psx_gpu_read( running_machine *, UINT32 *p_ram, INT32 n_size ); +extern void psx_gpu_write( running_machine *, UINT32 *p_ram, INT32 n_size ); +READ32_HANDLER( psx_gpu_r ); +WRITE32_HANDLER( psx_gpu_w ); +extern void psx_lightgun_set( running_machine *, int, int ); + +/*----------- defined in machine/psx.c -----------*/ + +WRITE32_HANDLER( psx_com_delay_w ); +READ32_HANDLER( psx_com_delay_r ); +WRITE32_HANDLER( psx_irq_w ); +READ32_HANDLER( psx_irq_r ); +extern void psx_irq_set( running_machine *, UINT32 ); +extern void psx_dma_install_read_handler( running_machine *, int, psx_dma_read_handler ); +extern void psx_dma_install_write_handler( running_machine *, int, psx_dma_read_handler ); +WRITE32_HANDLER( psx_dma_w ); +READ32_HANDLER( psx_dma_r ); +WRITE32_HANDLER( psx_counter_w ); +READ32_HANDLER( psx_counter_r ); +WRITE32_HANDLER( psx_sio_w ); +READ32_HANDLER( psx_sio_r ); +extern void psx_sio_install_handler( running_machine *, int, psx_sio_handler ); +extern void psx_sio_input( running_machine *, int, int, int ); + WRITE32_HANDLER( psx_mdec_w ); READ32_HANDLER( psx_mdec_r ); extern void psx_machine_init( running_machine *machine ); diff --git a/src/mame/machine/psx.c b/src/mame/machine/psx.c index b563eaf1bb9..4808a951da1 100644 --- a/src/mame/machine/psx.c +++ b/src/mame/machine/psx.c @@ -12,665 +12,11 @@ #define VERBOSE_LEVEL ( 0 ) -INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, const char *s_fmt, ... ) -{ - if( VERBOSE_LEVEL >= n_level ) - { - va_list v; - char buf[ 32768 ]; - va_start( v, s_fmt ); - vsprintf( buf, s_fmt, v ); - va_end( v ); - logerror( "%s: %s", cpuexec_describe_context(machine), buf ); - } -} - -UINT32 *g_p_n_psxram; -size_t g_n_psxramsize; - -#ifdef UNUSED_FUNCTION -INLINE void psxwriteword( UINT32 n_address, UINT16 n_data ) -{ - *( (UINT16 *)( (UINT8 *)g_p_n_psxram + WORD_XOR_LE( n_address ) ) ) = n_data; -} -#endif - -INLINE UINT16 psxreadword( UINT32 n_address ) -{ - return *( (UINT16 *)( (UINT8 *)g_p_n_psxram + WORD_XOR_LE( n_address ) ) ); -} - -static UINT32 psx_com_delay = 0; - -WRITE32_HANDLER( psx_com_delay_w ) -{ - COMBINE_DATA( &psx_com_delay ); - verboselog( space->machine, 1, "psx_com_delay_w( %08x %08x )\n", data, mem_mask ); -} - -READ32_HANDLER( psx_com_delay_r ) -{ - verboselog( space->machine, 1, "psx_com_delay_r( %08x )\n", mem_mask ); - return psx_com_delay; -} - -/* IRQ */ - -static UINT32 m_n_irqdata; -static UINT32 m_n_irqmask; - -static void psx_irq_update( running_machine *machine ) -{ - if( ( m_n_irqdata & m_n_irqmask ) != 0 ) - { - verboselog( machine, 2, "psx irq assert\n" ); - cputag_set_input_line(machine, "maincpu", PSXCPU_IRQ0, ASSERT_LINE ); - } - else - { - verboselog( machine, 2, "psx irq clear\n" ); - cputag_set_input_line(machine, "maincpu", PSXCPU_IRQ0, CLEAR_LINE ); - } -} - -WRITE32_HANDLER( psx_irq_w ) -{ - running_machine *machine = space->machine; - - switch( offset ) - { - case 0x00: - verboselog( machine, 2, "psx irq data ( %08x, %08x ) %08x -> %08x\n", data, mem_mask, m_n_irqdata, ( m_n_irqdata & ~mem_mask ) | ( m_n_irqdata & m_n_irqmask & data ) ); - m_n_irqdata = ( m_n_irqdata & ~mem_mask ) | ( m_n_irqdata & m_n_irqmask & data ); - psx_irq_update(space->machine); - break; - case 0x01: - verboselog( machine, 2, "psx irq mask ( %08x, %08x ) %08x -> %08x\n", data, mem_mask, m_n_irqmask, ( m_n_irqmask & ~mem_mask ) | data ); - m_n_irqmask = ( m_n_irqmask & ~mem_mask ) | data; - if( ( m_n_irqmask &~ PSX_IRQ_MASK ) != 0 ) - { - verboselog( machine, 0, "psx_irq_w( %08x, %08x, %08x ) unknown irq\n", offset, data, mem_mask ); - } - psx_irq_update(space->machine); - break; - default: - verboselog( machine, 0, "psx_irq_w( %08x, %08x, %08x ) unknown register\n", offset, data, mem_mask ); - break; - } -} - -READ32_HANDLER( psx_irq_r ) -{ - running_machine *machine = space->machine; - - switch( offset ) - { - case 0x00: - verboselog( machine, 1, "psx_irq_r irq data %08x\n", m_n_irqdata ); - return m_n_irqdata; - case 0x01: - verboselog( machine, 1, "psx_irq_r irq mask %08x\n", m_n_irqmask ); - return m_n_irqmask; - default: - verboselog( machine, 0, "psx_irq_r unknown register %d\n", offset ); - break; - } - return 0; -} - -void psx_irq_set( running_machine *machine, UINT32 data ) -{ - verboselog( machine, 2, "psx_irq_set %08x\n", data ); - m_n_irqdata |= data; - psx_irq_update(machine); -} - -/* DMA */ - -static UINT32 m_p_n_dmabase[ 7 ]; -static UINT32 m_p_n_dmablockcontrol[ 7 ]; -static UINT32 m_p_n_dmachannelcontrol[ 7 ]; -static emu_timer *m_p_timer_dma[ 7 ]; -static psx_dma_read_handler m_p_fn_dma_read[ 7 ]; -static psx_dma_write_handler m_p_fn_dma_write[ 7 ]; -static UINT32 m_p_n_dma_ticks[ 7 ]; -static UINT32 m_p_b_dma_running[ 7 ]; -static UINT32 m_n_dpcp; -static UINT32 m_n_dicr; - -static void dma_start_timer( int n_channel, UINT32 n_ticks ) -{ - timer_adjust_oneshot( m_p_timer_dma[ n_channel ], attotime_mul(ATTOTIME_IN_HZ(33868800), n_ticks), n_channel); - m_p_n_dma_ticks[ n_channel ] = n_ticks; - m_p_b_dma_running[ n_channel ] = 1; -} - -static void dma_stop_timer( int n_channel ) -{ - timer_adjust_oneshot( m_p_timer_dma[ n_channel ], attotime_never, 0); - m_p_b_dma_running[ n_channel ] = 0; -} - -static void dma_timer_adjust( int n_channel ) -{ - if( m_p_b_dma_running[ n_channel ] ) - { - dma_start_timer( n_channel, m_p_n_dma_ticks[ n_channel ] ); - } - else - { - dma_stop_timer( n_channel ); - } -} - -static void dma_interrupt_update( running_machine *machine ) -{ - int n_int; - int n_mask; - - n_int = ( m_n_dicr >> 24 ) & 0x7f; - n_mask = ( m_n_dicr >> 16 ) & 0xff; - - if( ( n_mask & 0x80 ) != 0 && ( n_int & n_mask ) != 0 ) - { - verboselog( machine, 2, "dma_interrupt_update( %02x, %02x ) interrupt triggered\n", n_int, n_mask ); - m_n_dicr |= 0x80000000; - psx_irq_set( machine, PSX_IRQ_DMA ); - } - else if( ( m_n_dicr & 0x80000000 ) != 0 ) - { - verboselog( machine, 2, "dma_interrupt_update( %02x, %02x ) interrupt cleared\n", n_int, n_mask ); - m_n_dicr &= ~0x80000000; - } - else if( n_int != 0 ) - { - verboselog( machine, 2, "dma_interrupt_update( %02x, %02x ) interrupt not enabled\n", n_int, n_mask ); - } - - m_n_dicr &= 0x00ffffff | ( m_n_dicr << 8 ); -} - -static void dma_finished(running_machine *machine, int n_channel) -{ - if( m_p_n_dmachannelcontrol[ n_channel ] == 0x01000401 && n_channel == 2 ) - { - UINT32 n_size; - UINT32 n_total; - UINT32 n_address = ( m_p_n_dmabase[ n_channel ] & 0xffffff ); - UINT32 n_adrmask = g_n_psxramsize - 1; - UINT32 n_nextaddress; - - if( n_address != 0xffffff ) - { - n_total = 0; - for( ;; ) - { - if( n_address == 0xffffff ) - { - m_p_n_dmabase[ n_channel ] = n_address; - dma_start_timer( n_channel, 19000 ); - return; - } - if( n_total > 65535 ) - { - m_p_n_dmabase[ n_channel ] = n_address; - //FIXME: - // 16000 below is based on try and error. - // Mametesters.org: sfex20103red - //dma_start_timer( n_channel, 16 ); - dma_start_timer( n_channel, 16000 ); - return; - } - n_address &= n_adrmask; - n_nextaddress = g_p_n_psxram[ n_address / 4 ]; - n_size = n_nextaddress >> 24; - m_p_fn_dma_write[ n_channel ]( machine, n_address + 4, n_size ); - //FIXME: - // The following conditions will cause an endless loop. - // If stopping the transfer is correct I cannot judge - // The patch is meant as a hint for somebody who knows - // the hardware. - // Mametesters.org: psyforce0105u5red, raystorm0111u1red - if ((n_nextaddress & 0xffffff) != 0xffffff) - if (n_address == g_p_n_psxram[ (n_nextaddress & 0xffffff) / 4]) - break; - if (n_address == (n_nextaddress & 0xffffff) ) - break; - n_address = ( n_nextaddress & 0xffffff ); - - n_total += ( n_size + 1 ); - } - } - } - - m_p_n_dmachannelcontrol[ n_channel ] &= ~( ( 1L << 0x18 ) | ( 1L << 0x1c ) ); - - m_n_dicr |= 1 << ( 24 + n_channel ); - dma_interrupt_update(machine); - dma_stop_timer( n_channel ); -} - -static TIMER_CALLBACK( dma_finished_callback ) -{ - dma_finished(machine, param); -} - -void psx_dma_install_read_handler( int n_channel, psx_dma_read_handler p_fn_dma_read ) -{ - m_p_fn_dma_read[ n_channel ] = p_fn_dma_read; -} - -void psx_dma_install_write_handler( int n_channel, psx_dma_read_handler p_fn_dma_write ) -{ - m_p_fn_dma_write[ n_channel ] = p_fn_dma_write; -} - -WRITE32_HANDLER( psx_dma_w ) -{ - running_machine *machine = space->machine; - static int n_channel; - n_channel = offset / 4; - if( n_channel < 7 ) - { - switch( offset % 4 ) - { - case 0: - verboselog( machine, 2, "dmabase( %d ) = %08x\n", n_channel, data ); - m_p_n_dmabase[ n_channel ] = data; - break; - case 1: - verboselog( machine, 2, "dmablockcontrol( %d ) = %08x\n", n_channel, data ); - m_p_n_dmablockcontrol[ n_channel ] = data; - break; - case 2: - verboselog( machine, 2, "dmachannelcontrol( %d ) = %08x\n", n_channel, data ); - m_p_n_dmachannelcontrol[ n_channel ] = data; - if( ( m_p_n_dmachannelcontrol[ n_channel ] & ( 1L << 0x18 ) ) != 0 && ( m_n_dpcp & ( 1 << ( 3 + ( n_channel * 4 ) ) ) ) != 0 ) - { - INT32 n_size; - UINT32 n_address; - UINT32 n_nextaddress; - UINT32 n_adrmask; - - n_adrmask = g_n_psxramsize - 1; - - n_address = ( m_p_n_dmabase[ n_channel ] & n_adrmask ); - n_size = m_p_n_dmablockcontrol[ n_channel ]; - if( ( m_p_n_dmachannelcontrol[ n_channel ] & 0x200 ) != 0 ) - { - UINT32 n_ba; - n_ba = m_p_n_dmablockcontrol[ n_channel ] >> 16; - if( n_ba == 0 ) - { - n_ba = 0x10000; - } - n_size = ( n_size & 0xffff ) * n_ba; - } - - if( m_p_n_dmachannelcontrol[ n_channel ] == 0x01000000 && - m_p_fn_dma_read[ n_channel ] != NULL ) - { - verboselog( machine, 1, "dma %d read block %08x %08x\n", n_channel, n_address, n_size ); - m_p_fn_dma_read[ n_channel ]( space->machine, n_address, n_size ); - dma_finished( machine, n_channel ); - } - else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x01000200 && - m_p_fn_dma_read[ n_channel ] != NULL ) - { - verboselog( machine, 1, "dma %d read block %08x %08x\n", n_channel, n_address, n_size ); - m_p_fn_dma_read[ n_channel ]( space->machine, n_address, n_size ); - if( n_channel == 1 ) - { - dma_start_timer( n_channel, 26000 ); - } - else - { - dma_finished( machine, n_channel ); - } - } - else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x01000201 && - m_p_fn_dma_write[ n_channel ] != NULL ) - { - verboselog( machine, 1, "dma %d write block %08x %08x\n", n_channel, n_address, n_size ); - m_p_fn_dma_write[ n_channel ]( space->machine, n_address, n_size ); - dma_finished( machine, n_channel ); - } - else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x11050100 && - m_p_fn_dma_write[ n_channel ] != NULL ) - { - /* todo: check this is a write not a read... */ - verboselog( machine, 1, "dma %d write block %08x %08x\n", n_channel, n_address, n_size ); - m_p_fn_dma_write[ n_channel ]( space->machine, n_address, n_size ); - dma_finished( machine, n_channel ); - } - else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x11150100 && - m_p_fn_dma_write[ n_channel ] != NULL ) - { - /* todo: check this is a write not a read... */ - verboselog( machine, 1, "dma %d write block %08x %08x\n", n_channel, n_address, n_size ); - m_p_fn_dma_write[ n_channel ]( space->machine, n_address, n_size ); - dma_finished( machine, n_channel ); - } - else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x01000401 && - n_channel == 2 && - m_p_fn_dma_write[ n_channel ] != NULL ) - { - verboselog( machine, 1, "dma %d write linked list %08x\n", - n_channel, m_p_n_dmabase[ n_channel ] ); - - dma_finished( machine, n_channel ); - } - else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x11000002 && - n_channel == 6 ) - { - verboselog( machine, 1, "dma 6 reverse clear %08x %08x\n", - m_p_n_dmabase[ n_channel ], m_p_n_dmablockcontrol[ n_channel ] ); - if( n_size > 0 ) - { - n_size--; - while( n_size > 0 ) - { - n_nextaddress = ( n_address - 4 ) & 0xffffff; - g_p_n_psxram[ n_address / 4 ] = n_nextaddress; - n_address = n_nextaddress; - n_size--; - } - g_p_n_psxram[ n_address / 4 ] = 0xffffff; - } - dma_start_timer( n_channel, 2150 ); - } - else - { - verboselog( machine, 0, "dma %d unknown mode %08x\n", n_channel, m_p_n_dmachannelcontrol[ n_channel ] ); - } - } - else if( m_p_n_dmachannelcontrol[ n_channel ] != 0 ) - { - verboselog( machine, 1, "psx_dma_w( %04x, %08x, %08x ) channel not enabled\n", offset, m_p_n_dmachannelcontrol[ n_channel ], mem_mask ); - } - break; - default: - verboselog( machine, 1, "psx_dma_w( %04x, %08x, %08x ) Unknown dma channel register\n", offset, data, mem_mask ); - break; - } - } - else - { - switch( offset % 4 ) - { - case 0x0: - verboselog( machine, 1, "psx_dma_w( %04x, %08x, %08x ) dpcp\n", offset, data, mem_mask ); - m_n_dpcp = ( m_n_dpcp & ~mem_mask ) | data; - break; - case 0x1: - m_n_dicr = ( m_n_dicr & ~mem_mask ) | - ( mem_mask & 0x80000000 & m_n_dicr ) | - ( ~data & mem_mask & 0x7f000000 & m_n_dicr ) | - ( data & mem_mask & 0x00ffffff ); -/* todo: find out whether to do this instead of dma_interrupt_update() - - if( ( m_n_dicr & 0x7f000000 ) != 0 ) - { - m_n_dicr &= ~0x80000000; - } -*/ - verboselog( machine, 1, "psx_dma_w( %04x, %08x, %08x ) dicr -> %08x\n", offset, data, mem_mask, m_n_dicr ); - dma_interrupt_update(space->machine); - break; - default: - verboselog( machine, 0, "psx_dma_w( %04x, %08x, %08x ) Unknown dma control register\n", offset, data, mem_mask ); - break; - } - } -} - -READ32_HANDLER( psx_dma_r ) -{ - running_machine *machine = space->machine; - static int n_channel; - n_channel = offset / 4; - if( n_channel < 7 ) - { - switch( offset % 4 ) - { - case 0: - verboselog( machine, 1, "psx_dma_r dmabase[ %d ] ( %08x )\n", n_channel, m_p_n_dmabase[ n_channel ] ); - return m_p_n_dmabase[ n_channel ]; - case 1: - verboselog( machine, 1, "psx_dma_r dmablockcontrol[ %d ] ( %08x )\n", n_channel, m_p_n_dmablockcontrol[ n_channel ] ); - return m_p_n_dmablockcontrol[ n_channel ]; - case 2: - verboselog( machine, 1, "psx_dma_r dmachannelcontrol[ %d ] ( %08x )\n", n_channel, m_p_n_dmachannelcontrol[ n_channel ] ); - return m_p_n_dmachannelcontrol[ n_channel ]; - default: - verboselog( machine, 0, "psx_dma_r( %08x, %08x ) Unknown dma channel register\n", offset, mem_mask ); - break; - } - } - else - { - switch( offset % 4 ) - { - case 0x0: - verboselog( machine, 1, "psx_dma_r dpcp ( %08x )\n", m_n_dpcp ); - return m_n_dpcp; - case 0x1: - verboselog( machine, 1, "psx_dma_r dicr ( %08x )\n", m_n_dicr ); - return m_n_dicr; - default: - verboselog( machine, 0, "psx_dma_r( %08x, %08x ) Unknown dma control register\n", offset, mem_mask ); - break; - } - } - return 0; -} - -/* Root Counters */ - -static emu_timer *m_p_timer_root[ 3 ]; -static UINT16 m_p_n_root_count[ 3 ]; -static UINT16 m_p_n_root_mode[ 3 ]; -static UINT16 m_p_n_root_target[ 3 ]; -static UINT64 m_p_n_root_start[ 3 ]; - -#define RC_STOP ( 0x01 ) -#define RC_RESET ( 0x04 ) /* guess */ -#define RC_COUNTTARGET ( 0x08 ) -#define RC_IRQTARGET ( 0x10 ) -#define RC_IRQOVERFLOW ( 0x20 ) -#define RC_REPEAT ( 0x40 ) -#define RC_CLC ( 0x100 ) -#define RC_DIV ( 0x200 ) - -static UINT64 psxcpu_gettotalcycles( running_machine *machine ) -{ - /* TODO: should return the start of the current tick. */ - return machine->firstcpu->total_cycles() * 2; -} - -static int root_divider( int n_counter ) -{ - if( n_counter == 0 && ( m_p_n_root_mode[ n_counter ] & RC_CLC ) != 0 ) - { - /* TODO: pixel clock, probably based on resolution */ - return 5; - } - else if( n_counter == 1 && ( m_p_n_root_mode[ n_counter ] & RC_CLC ) != 0 ) - { - return 2150; - } - else if( n_counter == 2 && ( m_p_n_root_mode[ n_counter ] & RC_DIV ) != 0 ) - { - return 8; - } - return 1; -} - -static UINT16 root_current( running_machine *machine, int n_counter ) -{ - if( ( m_p_n_root_mode[ n_counter ] & RC_STOP ) != 0 ) - { - return m_p_n_root_count[ n_counter ]; - } - else - { - UINT64 n_current; - n_current = psxcpu_gettotalcycles(machine) - m_p_n_root_start[ n_counter ]; - n_current /= root_divider( n_counter ); - n_current += m_p_n_root_count[ n_counter ]; - if( n_current > 0xffff ) - { - /* TODO: use timer for wrap on 0x10000. */ - m_p_n_root_count[ n_counter ] = n_current; - m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(machine); - } - return n_current; - } -} - -static int root_target( int n_counter ) -{ - if( ( m_p_n_root_mode[ n_counter ] & RC_COUNTTARGET ) != 0 || - ( m_p_n_root_mode[ n_counter ] & RC_IRQTARGET ) != 0 ) - { - return m_p_n_root_target[ n_counter ]; - } - return 0x10000; -} - -static void root_timer_adjust( running_machine *machine, int n_counter ) -{ - if( ( m_p_n_root_mode[ n_counter ] & RC_STOP ) != 0 ) - { - timer_adjust_oneshot( m_p_timer_root[ n_counter ], attotime_never, n_counter); - } - else - { - int n_duration; - - n_duration = root_target( n_counter ) - root_current( machine, n_counter ); - if( n_duration < 1 ) - { - n_duration += 0x10000; - } - - n_duration *= root_divider( n_counter ); - - timer_adjust_oneshot( m_p_timer_root[ n_counter ], attotime_mul(ATTOTIME_IN_HZ(33868800), n_duration), n_counter); - } -} - -static TIMER_CALLBACK( root_finished ) -{ - int n_counter = param; - - verboselog( machine, 2, "root_finished( %d ) %04x\n", n_counter, root_current( machine, n_counter ) ); -// if( ( m_p_n_root_mode[ n_counter ] & RC_COUNTTARGET ) != 0 ) - { - /* TODO: wrap should be handled differently as RC_COUNTTARGET & RC_IRQTARGET don't have to be the same. */ - m_p_n_root_count[ n_counter ] = 0; - m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(machine); - } - if( ( m_p_n_root_mode[ n_counter ] & RC_REPEAT ) != 0 ) - { - root_timer_adjust( machine, n_counter ); - } - if( ( m_p_n_root_mode[ n_counter ] & RC_IRQOVERFLOW ) != 0 || - ( m_p_n_root_mode[ n_counter ] & RC_IRQTARGET ) != 0 ) - { - psx_irq_set( machine, (n_counter == 3) ? PSX_IRQ_ROOTCOUNTER3 : (PSX_IRQ_ROOTCOUNTER0 << n_counter) ); - } -} - -WRITE32_HANDLER( psx_counter_w ) -{ - int n_counter; - - verboselog( space->machine, 1, "psx_counter_w ( %08x, %08x, %08x )\n", offset, data, mem_mask ); - - n_counter = offset / 4; - - switch( offset % 4 ) - { - case 0: - m_p_n_root_count[ n_counter ] = data; - m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(space->machine); - break; - case 1: - m_p_n_root_count[ n_counter ] = root_current( space->machine, n_counter ); - m_p_n_root_start[ n_counter ] = psxcpu_gettotalcycles(space->machine); - m_p_n_root_mode[ n_counter ] = data; - - if( ( m_p_n_root_mode[ n_counter ] & RC_RESET ) != 0 ) - { - m_p_n_root_count[ n_counter ] = 0; - } -// if( ( data & 0xfca6 ) != 0 || -// ( ( data & 0x0100 ) != 0 && n_counter != 0 && n_counter != 1 ) || -// ( ( data & 0x0200 ) != 0 && n_counter != 2 ) ) -// { -// mame_printf_debug( "mode %d 0x%04x\n", n_counter, data & 0xfca6 ); -// } - break; - case 2: - m_p_n_root_target[ n_counter ] = data; - break; - default: - verboselog( space->machine, 0, "psx_counter_w( %08x, %08x, %08x ) unknown register\n", offset, mem_mask, data ); - return; - } - - root_timer_adjust( space->machine, n_counter ); -} - -READ32_HANDLER( psx_counter_r ) -{ - int n_counter; - UINT32 data; - - n_counter = offset / 4; - - switch( offset % 4 ) - { - case 0: - data = root_current( space->machine, n_counter ); - break; - case 1: - data = m_p_n_root_mode[ n_counter ]; - break; - case 2: - data = m_p_n_root_target[ n_counter ]; - break; - default: - verboselog( space->machine, 0, "psx_counter_r( %08x, %08x ) unknown register\n", offset, mem_mask ); - return 0; - } - verboselog( space->machine, 1, "psx_counter_r ( %08x, %08x ) %08x\n", offset, mem_mask, data ); - return data; -} - -/* SIO */ +#define DCTSIZE ( 8 ) +#define DCTSIZE2 ( DCTSIZE * DCTSIZE ) #define SIO_BUF_SIZE ( 8 ) -static UINT32 m_p_n_sio_status[ 2 ]; -static UINT32 m_p_n_sio_mode[ 2 ]; -static UINT32 m_p_n_sio_control[ 2 ]; -static UINT32 m_p_n_sio_baud[ 2 ]; -static UINT32 m_p_n_sio_tx[ 2 ]; -static UINT32 m_p_n_sio_rx[ 2 ]; -static UINT32 m_p_n_sio_tx_prev[ 2 ]; -static UINT32 m_p_n_sio_rx_prev[ 2 ]; -static UINT32 m_p_n_sio_tx_data[ 2 ]; -static UINT32 m_p_n_sio_rx_data[ 2 ]; -static UINT32 m_p_n_sio_tx_shift[ 2 ]; -static UINT32 m_p_n_sio_rx_shift[ 2 ]; -static UINT32 m_p_n_sio_tx_bits[ 2 ]; -static UINT32 m_p_n_sio_rx_bits[ 2 ]; - -static emu_timer *m_p_timer_sio[ 2 ]; -static psx_sio_handler m_p_f_sio_handler[ 2 ]; - #define SIO_STATUS_TX_RDY ( 1 << 0 ) #define SIO_STATUS_RX_RDY ( 1 << 1 ) #define SIO_STATUS_TX_EMPTY ( 1 << 2 ) @@ -686,28 +32,770 @@ static psx_sio_handler m_p_f_sio_handler[ 2 ]; #define SIO_CONTROL_DSR_IENA ( 1 << 12 ) #define SIO_CONTROL_DTR ( 1 << 13 ) -static void sio_interrupt( running_machine *machine, int n_port ) +#define MDEC_COS_PRECALC_BITS ( 21 ) + + +typedef struct _psx_dma_channel psx_dma_channel; +struct _psx_dma_channel { - verboselog( machine, 1, "sio_interrupt( %d )\n", n_port ); - m_p_n_sio_status[ n_port ] |= SIO_STATUS_IRQ; - if( n_port == 0 ) + UINT32 n_base; + UINT32 n_blockcontrol; + UINT32 n_channelcontrol; + emu_timer *timer; + psx_dma_read_handler fn_read; + psx_dma_write_handler fn_write; + UINT32 n_ticks; + UINT32 b_running; +}; + +typedef struct _psx_root psx_root; +struct _psx_root +{ + emu_timer *timer; + UINT16 n_count; + UINT16 n_mode; + UINT16 n_target; + UINT64 n_start; +}; + +typedef struct _psx_sio psx_sio; +struct _psx_sio +{ + UINT32 n_status; + UINT32 n_mode; + UINT32 n_control; + UINT32 n_baud; + UINT32 n_tx; + UINT32 n_rx; + UINT32 n_tx_prev; + UINT32 n_rx_prev; + UINT32 n_tx_data; + UINT32 n_rx_data; + UINT32 n_tx_shift; + UINT32 n_rx_shift; + UINT32 n_tx_bits; + UINT32 n_rx_bits; + + emu_timer *timer; + psx_sio_handler fn_handler; +}; + +typedef struct _psx_mdec psx_mdec; +struct _psx_mdec +{ + UINT32 n_decoded; + UINT32 n_offset; + UINT16 p_n_output[ 24 * 16 ]; + + INT32 p_n_quantize_y[ DCTSIZE2 ]; + INT32 p_n_quantize_uv[ DCTSIZE2 ]; + INT32 p_n_cos[ DCTSIZE2 ]; + INT32 p_n_cos_precalc[ DCTSIZE2 * DCTSIZE2 ]; + + UINT32 n_0_command; + UINT32 n_0_address; + UINT32 n_0_size; + UINT32 n_1_command; + UINT32 n_1_status; + + UINT16 p_n_clamp8[ 256 * 3 ]; + UINT16 p_n_r5[ 256 * 3 ]; + UINT16 p_n_g5[ 256 * 3 ]; + UINT16 p_n_b5[ 256 * 3 ]; + + INT32 p_n_unpacked[ DCTSIZE2 * 6 * 2 ]; +}; + +struct _psx_machine +{ + running_machine *machine; + UINT32 *p_n_psxram; + size_t n_psxramsize; + + UINT32 n_com_delay; + UINT32 n_irqdata; + UINT32 n_irqmask; + + UINT32 n_dpcp; + UINT32 n_dicr; + psx_dma_channel channel[7]; + + psx_root root[3]; + + psx_sio sio[2]; + + psx_mdec mdec; +}; + + +INLINE void ATTR_PRINTF(3,4) verboselog( psx_machine *p_psx, int n_level, const char *s_fmt, ... ) +{ + if( VERBOSE_LEVEL >= n_level ) { - psx_irq_set( machine, PSX_IRQ_SIO0 ); - } - else - { - psx_irq_set( machine, PSX_IRQ_SIO1 ); + va_list v; + char buf[ 32768 ]; + va_start( v, s_fmt ); + vsprintf( buf, s_fmt, v ); + va_end( v ); + logerror( "%s: %s", cpuexec_describe_context(p_psx->machine), buf ); } } -static void sio_timer_adjust( running_machine *machine, int n_port ) +#ifdef UNUSED_FUNCTION +INLINE void psxwriteword( UINT32 *p_n_psxram, UINT32 n_address, UINT16 n_data ) { + *( (UINT16 *)( (UINT8 *)p_n_psxram + WORD_XOR_LE( n_address ) ) ) = n_data; +} +#endif + +INLINE UINT16 psxreadword( UINT32 *p_n_psxram, UINT32 n_address ) +{ + return *( (UINT16 *)( (UINT8 *)p_n_psxram + WORD_XOR_LE( n_address ) ) ); +} + +WRITE32_HANDLER( psx_com_delay_w ) +{ + psx_machine *p_psx = space->machine->driver_data()->p_psx; + + COMBINE_DATA( &p_psx->n_com_delay ); + verboselog( p_psx, 1, "psx_com_delay_w( %08x %08x )\n", data, mem_mask ); +} + +READ32_HANDLER( psx_com_delay_r ) +{ + psx_machine *p_psx = space->machine->driver_data()->p_psx; + + verboselog( p_psx, 1, "psx_com_delay_r( %08x )\n", mem_mask ); + return p_psx->n_com_delay; +} + +/* IRQ */ + +static void psx_irq_update( psx_machine *p_psx ) +{ + if( ( p_psx->n_irqdata & p_psx->n_irqmask ) != 0 ) + { + verboselog( p_psx, 2, "psx irq assert\n" ); + cputag_set_input_line( p_psx->machine, "maincpu", PSXCPU_IRQ0, ASSERT_LINE ); + } + else + { + verboselog( p_psx, 2, "psx irq clear\n" ); + cputag_set_input_line( p_psx->machine, "maincpu", PSXCPU_IRQ0, CLEAR_LINE ); + } +} + +WRITE32_HANDLER( psx_irq_w ) +{ + psx_machine *p_psx = space->machine->driver_data()->p_psx; + + switch( offset ) + { + case 0x00: + verboselog( p_psx, 2, "psx irq data ( %08x, %08x ) %08x -> %08x\n", data, mem_mask, p_psx->n_irqdata, ( p_psx->n_irqdata & ~mem_mask ) | ( p_psx->n_irqdata & p_psx->n_irqmask & data ) ); + p_psx->n_irqdata = ( p_psx->n_irqdata & ~mem_mask ) | ( p_psx->n_irqdata & p_psx->n_irqmask & data ); + psx_irq_update(p_psx); + break; + case 0x01: + verboselog( p_psx, 2, "psx irq mask ( %08x, %08x ) %08x -> %08x\n", data, mem_mask, p_psx->n_irqmask, ( p_psx->n_irqmask & ~mem_mask ) | data ); + p_psx->n_irqmask = ( p_psx->n_irqmask & ~mem_mask ) | data; + if( ( p_psx->n_irqmask &~ PSX_IRQ_MASK ) != 0 ) + { + verboselog( p_psx, 0, "psx_irq_w( %08x, %08x, %08x ) unknown irq\n", offset, data, mem_mask ); + } + psx_irq_update(p_psx); + break; + default: + verboselog( p_psx, 0, "psx_irq_w( %08x, %08x, %08x ) unknown register\n", offset, data, mem_mask ); + break; + } +} + +READ32_HANDLER( psx_irq_r ) +{ + psx_machine *p_psx = space->machine->driver_data()->p_psx; + + switch( offset ) + { + case 0x00: + verboselog( p_psx, 1, "psx_irq_r irq data %08x\n", p_psx->n_irqdata ); + return p_psx->n_irqdata; + case 0x01: + verboselog( p_psx, 1, "psx_irq_r irq mask %08x\n", p_psx->n_irqmask ); + return p_psx->n_irqmask; + default: + verboselog( p_psx, 0, "psx_irq_r unknown register %d\n", offset ); + break; + } + return 0; +} + +void psx_irq_set( running_machine *machine, UINT32 data ) +{ + psx_machine *p_psx = machine->driver_data()->p_psx; + + verboselog( p_psx, 2, "psx_irq_set %08x\n", data ); + p_psx->n_irqdata |= data; + psx_irq_update(p_psx); +} + +/* DMA */ + +static void dma_start_timer( psx_machine *p_psx, int n_channel, UINT32 n_ticks ) +{ + psx_dma_channel *dma = &p_psx->channel[ n_channel ]; + + timer_adjust_oneshot( dma->timer, attotime_mul(ATTOTIME_IN_HZ(33868800), n_ticks), n_channel); + dma->n_ticks = n_ticks; + dma->b_running = 1; +} + +static void dma_stop_timer( psx_machine *p_psx, int n_channel ) +{ + psx_dma_channel *dma = &p_psx->channel[ n_channel ]; + + timer_adjust_oneshot( dma->timer, attotime_never, 0); + dma->b_running = 0; +} + +static void dma_timer_adjust( psx_machine *p_psx, int n_channel ) +{ + psx_dma_channel *dma = &p_psx->channel[ n_channel ]; + + if( dma->b_running ) + { + dma_start_timer( p_psx, n_channel, dma->n_ticks ); + } + else + { + dma_stop_timer( p_psx, n_channel ); + } +} + +static void dma_interrupt_update( psx_machine *p_psx ) +{ + int n_int; + int n_mask; + + n_int = ( p_psx->n_dicr >> 24 ) & 0x7f; + n_mask = ( p_psx->n_dicr >> 16 ) & 0xff; + + if( ( n_mask & 0x80 ) != 0 && ( n_int & n_mask ) != 0 ) + { + verboselog( p_psx, 2, "dma_interrupt_update( %02x, %02x ) interrupt triggered\n", n_int, n_mask ); + p_psx->n_dicr |= 0x80000000; + psx_irq_set( p_psx->machine, PSX_IRQ_DMA ); + } + else if( ( p_psx->n_dicr & 0x80000000 ) != 0 ) + { + verboselog( p_psx, 2, "dma_interrupt_update( %02x, %02x ) interrupt cleared\n", n_int, n_mask ); + p_psx->n_dicr &= ~0x80000000; + } + else if( n_int != 0 ) + { + verboselog( p_psx, 2, "dma_interrupt_update( %02x, %02x ) interrupt not enabled\n", n_int, n_mask ); + } + + p_psx->n_dicr &= 0x00ffffff | ( p_psx->n_dicr << 8 ); +} + +static void dma_finished(psx_machine *p_psx, int n_channel) +{ + UINT32 *p_n_psxram = p_psx->p_n_psxram; + psx_dma_channel *dma = &p_psx->channel[ n_channel ]; + + if( dma->n_channelcontrol == 0x01000401 && n_channel == 2 ) + { + UINT32 n_size; + UINT32 n_total; + UINT32 n_address = ( dma->n_base & 0xffffff ); + UINT32 n_adrmask = p_psx->n_psxramsize - 1; + UINT32 n_nextaddress; + + if( n_address != 0xffffff ) + { + n_total = 0; + for( ;; ) + { + if( n_address == 0xffffff ) + { + dma->n_base = n_address; + dma_start_timer( p_psx, n_channel, 19000 ); + return; + } + if( n_total > 65535 ) + { + dma->n_base = n_address; + //FIXME: + // 16000 below is based on try and error. + // Mametesters.org: sfex20103red + //dma_start_timer( p_psx, n_channel, 16 ); + dma_start_timer( p_psx, n_channel, 16000 ); + return; + } + n_address &= n_adrmask; + n_nextaddress = p_n_psxram[ n_address / 4 ]; + n_size = n_nextaddress >> 24; + (*dma->fn_write)( p_psx->machine, n_address + 4, n_size ); + //FIXME: + // The following conditions will cause an endless loop. + // If stopping the transfer is correct I cannot judge + // The patch is meant as a hint for somebody who knows + // the hardware. + // Mametesters.org: psyforce0105u5red, raystorm0111u1red + if ((n_nextaddress & 0xffffff) != 0xffffff) + if (n_address == p_n_psxram[ (n_nextaddress & 0xffffff) / 4]) + break; + if (n_address == (n_nextaddress & 0xffffff) ) + break; + n_address = ( n_nextaddress & 0xffffff ); + + n_total += ( n_size + 1 ); + } + } + } + + dma->n_channelcontrol &= ~( ( 1L << 0x18 ) | ( 1L << 0x1c ) ); + + p_psx->n_dicr |= 1 << ( 24 + n_channel ); + dma_interrupt_update(p_psx); + dma_stop_timer( p_psx, n_channel ); +} + +static TIMER_CALLBACK( dma_finished_callback ) +{ + psx_machine *p_psx = machine->driver_data()->p_psx; + + dma_finished(p_psx, param); +} + +void psx_dma_install_read_handler( running_machine *machine, int n_channel, psx_dma_read_handler p_fn_dma_read ) +{ + psx_machine *p_psx = machine->driver_data()->p_psx; + + p_psx->channel[ n_channel ].fn_read = p_fn_dma_read; +} + +void psx_dma_install_write_handler( running_machine *machine, int n_channel, psx_dma_read_handler p_fn_dma_write ) +{ + psx_machine *p_psx = machine->driver_data()->p_psx; + + p_psx->channel[ n_channel ].fn_write = p_fn_dma_write; +} + +WRITE32_HANDLER( psx_dma_w ) +{ + psx_machine *p_psx = space->machine->driver_data()->p_psx; + UINT32 *p_n_psxram = p_psx->p_n_psxram; + int n_channel = offset / 4; + psx_dma_channel *dma = &p_psx->channel[ n_channel ]; + + if( n_channel < 7 ) + { + switch( offset % 4 ) + { + case 0: + verboselog( p_psx, 2, "dmabase( %d ) = %08x\n", n_channel, data ); + dma->n_base = data; + break; + case 1: + verboselog( p_psx, 2, "dmablockcontrol( %d ) = %08x\n", n_channel, data ); + dma->n_blockcontrol = data; + break; + case 2: + verboselog( p_psx, 2, "dmachannelcontrol( %d ) = %08x\n", n_channel, data ); + dma->n_channelcontrol = data; + if( ( dma->n_channelcontrol & ( 1L << 0x18 ) ) != 0 && ( p_psx->n_dpcp & ( 1 << ( 3 + ( n_channel * 4 ) ) ) ) != 0 ) + { + INT32 n_size; + UINT32 n_address; + UINT32 n_nextaddress; + UINT32 n_adrmask; + + n_adrmask = p_psx->n_psxramsize - 1; + + n_address = ( dma->n_base & n_adrmask ); + n_size = dma->n_blockcontrol; + if( ( dma->n_channelcontrol & 0x200 ) != 0 ) + { + UINT32 n_ba; + n_ba = dma->n_blockcontrol >> 16; + if( n_ba == 0 ) + { + n_ba = 0x10000; + } + n_size = ( n_size & 0xffff ) * n_ba; + } + + if( dma->n_channelcontrol == 0x01000000 && + dma->fn_read != NULL ) + { + verboselog( p_psx, 1, "dma %d read block %08x %08x\n", n_channel, n_address, n_size ); + (*dma->fn_read)( space->machine, n_address, n_size ); + dma_finished( p_psx, n_channel ); + } + else if( dma->n_channelcontrol == 0x01000200 && + dma->fn_read != NULL ) + { + verboselog( p_psx, 1, "dma %d read block %08x %08x\n", n_channel, n_address, n_size ); + (*dma->fn_read)( space->machine, n_address, n_size ); + if( n_channel == 1 ) + { + dma_start_timer( p_psx, n_channel, 26000 ); + } + else + { + dma_finished( p_psx, n_channel ); + } + } + else if( dma->n_channelcontrol == 0x01000201 && + dma->fn_write != NULL ) + { + verboselog( p_psx, 1, "dma %d write block %08x %08x\n", n_channel, n_address, n_size ); + (*dma->fn_write)( space->machine, n_address, n_size ); + dma_finished( p_psx, n_channel ); + } + else if( dma->n_channelcontrol == 0x11050100 && + dma->fn_write != NULL ) + { + /* todo: check this is a write not a read... */ + verboselog( p_psx, 1, "dma %d write block %08x %08x\n", n_channel, n_address, n_size ); + (*dma->fn_write)( space->machine, n_address, n_size ); + dma_finished( p_psx, n_channel ); + } + else if( dma->n_channelcontrol == 0x11150100 && + dma->fn_write != NULL ) + { + /* todo: check this is a write not a read... */ + verboselog( p_psx, 1, "dma %d write block %08x %08x\n", n_channel, n_address, n_size ); + (*dma->fn_write)( space->machine, n_address, n_size ); + dma_finished( p_psx, n_channel ); + } + else if( dma->n_channelcontrol == 0x01000401 && + n_channel == 2 && + dma->fn_write != NULL ) + { + verboselog( p_psx, 1, "dma %d write linked list %08x\n", + n_channel, dma->n_base ); + + dma_finished( p_psx, n_channel ); + } + else if( dma->n_channelcontrol == 0x11000002 && + n_channel == 6 ) + { + verboselog( p_psx, 1, "dma 6 reverse clear %08x %08x\n", + dma->n_base, dma->n_blockcontrol ); + if( n_size > 0 ) + { + n_size--; + while( n_size > 0 ) + { + n_nextaddress = ( n_address - 4 ) & 0xffffff; + p_n_psxram[ n_address / 4 ] = n_nextaddress; + n_address = n_nextaddress; + n_size--; + } + p_n_psxram[ n_address / 4 ] = 0xffffff; + } + dma_start_timer( p_psx, n_channel, 2150 ); + } + else + { + verboselog( p_psx, 0, "dma %d unknown mode %08x\n", n_channel, dma->n_channelcontrol ); + } + } + else if( dma->n_channelcontrol != 0 ) + { + verboselog( p_psx, 1, "psx_dma_w( %04x, %08x, %08x ) channel not enabled\n", offset, dma->n_channelcontrol, mem_mask ); + } + break; + default: + verboselog( p_psx, 1, "psx_dma_w( %04x, %08x, %08x ) Unknown dma channel register\n", offset, data, mem_mask ); + break; + } + } + else + { + switch( offset % 4 ) + { + case 0x0: + verboselog( p_psx, 1, "psx_dma_w( %04x, %08x, %08x ) dpcp\n", offset, data, mem_mask ); + p_psx->n_dpcp = ( p_psx->n_dpcp & ~mem_mask ) | data; + break; + case 0x1: + p_psx->n_dicr = ( p_psx->n_dicr & ~mem_mask ) | + ( mem_mask & 0x80000000 & p_psx->n_dicr ) | + ( ~data & mem_mask & 0x7f000000 & p_psx->n_dicr ) | + ( data & mem_mask & 0x00ffffff ); +#if 0 + /* todo: find out whether to do this instead of dma_interrupt_update() */ + if( ( p_psx->n_dicr & 0x7f000000 ) != 0 ) + { + p_psx->n_dicr &= ~0x80000000; + } +#endif + verboselog( p_psx, 1, "psx_dma_w( %04x, %08x, %08x ) dicr -> %08x\n", offset, data, mem_mask, p_psx->n_dicr ); + dma_interrupt_update(p_psx); + break; + default: + verboselog( p_psx, 0, "psx_dma_w( %04x, %08x, %08x ) Unknown dma control register\n", offset, data, mem_mask ); + break; + } + } +} + +READ32_HANDLER( psx_dma_r ) +{ + psx_machine *p_psx = space->machine->driver_data()->p_psx; + int n_channel = offset / 4; + psx_dma_channel *dma = &p_psx->channel[ n_channel ]; + + if( n_channel < 7 ) + { + switch( offset % 4 ) + { + case 0: + verboselog( p_psx, 1, "psx_dma_r dmabase[ %d ] ( %08x )\n", n_channel, dma->n_base ); + return dma->n_base; + case 1: + verboselog( p_psx, 1, "psx_dma_r dmablockcontrol[ %d ] ( %08x )\n", n_channel, dma->n_blockcontrol ); + return dma->n_blockcontrol; + case 2: + verboselog( p_psx, 1, "psx_dma_r dmachannelcontrol[ %d ] ( %08x )\n", n_channel, dma->n_channelcontrol ); + return dma->n_channelcontrol; + default: + verboselog( p_psx, 0, "psx_dma_r( %08x, %08x ) Unknown dma channel register\n", offset, mem_mask ); + break; + } + } + else + { + switch( offset % 4 ) + { + case 0x0: + verboselog( p_psx, 1, "psx_dma_r dpcp ( %08x )\n", p_psx->n_dpcp ); + return p_psx->n_dpcp; + case 0x1: + verboselog( p_psx, 1, "psx_dma_r dicr ( %08x )\n", p_psx->n_dicr ); + return p_psx->n_dicr; + default: + verboselog( p_psx, 0, "psx_dma_r( %08x, %08x ) Unknown dma control register\n", offset, mem_mask ); + break; + } + } + return 0; +} + +/* Root Counters */ + +static UINT64 psxcpu_gettotalcycles( psx_machine *p_psx ) +{ + /* TODO: should return the start of the current tick. */ + return p_psx->machine->firstcpu->total_cycles() * 2; +} + +static int root_divider( psx_machine *p_psx, int n_counter ) +{ + psx_root *root = &p_psx->root[ n_counter ]; + + if( n_counter == 0 && ( root->n_mode & PSX_RC_CLC ) != 0 ) + { + /* TODO: pixel clock, probably based on resolution */ + return 5; + } + else if( n_counter == 1 && ( root->n_mode & PSX_RC_CLC ) != 0 ) + { + return 2150; + } + else if( n_counter == 2 && ( root->n_mode & PSX_RC_DIV ) != 0 ) + { + return 8; + } + return 1; +} + +static UINT16 root_current( psx_machine *p_psx, int n_counter ) +{ + psx_root *root = &p_psx->root[ n_counter ]; + + if( ( root->n_mode & PSX_RC_STOP ) != 0 ) + { + return root->n_count; + } + else + { + UINT64 n_current; + n_current = psxcpu_gettotalcycles(p_psx) - root->n_start; + n_current /= root_divider( p_psx, n_counter ); + n_current += root->n_count; + if( n_current > 0xffff ) + { + /* TODO: use timer for wrap on 0x10000. */ + root->n_count = n_current; + root->n_start = psxcpu_gettotalcycles(p_psx); + } + return n_current; + } +} + +static int root_target( psx_machine *p_psx, int n_counter ) +{ + psx_root *root = &p_psx->root[ n_counter ]; + + if( ( root->n_mode & PSX_RC_COUNTTARGET ) != 0 || + ( root->n_mode & PSX_RC_IRQTARGET ) != 0 ) + { + return root->n_target; + } + return 0x10000; +} + +static void root_timer_adjust( psx_machine *p_psx, int n_counter ) +{ + psx_root *root = &p_psx->root[ n_counter ]; + + if( ( root->n_mode & PSX_RC_STOP ) != 0 ) + { + timer_adjust_oneshot( root->timer, attotime_never, n_counter); + } + else + { + int n_duration; + + n_duration = root_target( p_psx, n_counter ) - root_current( p_psx, n_counter ); + if( n_duration < 1 ) + { + n_duration += 0x10000; + } + + n_duration *= root_divider( p_psx, n_counter ); + + timer_adjust_oneshot( root->timer, attotime_mul(ATTOTIME_IN_HZ(33868800), n_duration), n_counter); + } +} + +static TIMER_CALLBACK( root_finished ) +{ + psx_machine *p_psx = machine->driver_data()->p_psx; + int n_counter = param; + psx_root *root = &p_psx->root[ n_counter ]; + + verboselog( p_psx, 2, "root_finished( %d ) %04x\n", n_counter, root_current( p_psx, n_counter ) ); + //if( ( root->n_mode & PSX_RC_COUNTTARGET ) != 0 ) + { + /* TODO: wrap should be handled differently as PSX_RC_COUNTTARGET & PSX_RC_IRQTARGET don't have to be the same. */ + root->n_count = 0; + root->n_start = psxcpu_gettotalcycles(p_psx); + } + if( ( root->n_mode & PSX_RC_REPEAT ) != 0 ) + { + root_timer_adjust( p_psx, n_counter ); + } + if( ( root->n_mode & PSX_RC_IRQOVERFLOW ) != 0 || + ( root->n_mode & PSX_RC_IRQTARGET ) != 0 ) + { + psx_irq_set( machine, (n_counter == 3) ? PSX_IRQ_ROOTCOUNTER3 : (PSX_IRQ_ROOTCOUNTER0 << n_counter) ); + } +} + +WRITE32_HANDLER( psx_counter_w ) +{ + psx_machine *p_psx = space->machine->driver_data()->p_psx; + int n_counter = offset / 4; + psx_root *root = &p_psx->root[ n_counter ]; + + verboselog( p_psx, 1, "psx_counter_w ( %08x, %08x, %08x )\n", offset, data, mem_mask ); + + switch( offset % 4 ) + { + case 0: + root->n_count = data; + root->n_start = psxcpu_gettotalcycles(p_psx); + break; + case 1: + root->n_count = root_current( p_psx, n_counter ); + root->n_start = psxcpu_gettotalcycles(p_psx); + root->n_mode = data; + + if( ( root->n_mode & PSX_RC_RESET ) != 0 ) + { + root->n_count = 0; + } + +#if 0 + if( ( data & 0xfca6 ) != 0 || + ( ( data & 0x0100 ) != 0 && n_counter != 0 && n_counter != 1 ) || + ( ( data & 0x0200 ) != 0 && n_counter != 2 ) ) + { + mame_printf_debug( "mode %d 0x%04x\n", n_counter, data & 0xfca6 ); + } +#endif + break; + case 2: + root->n_target = data; + break; + default: + verboselog( p_psx, 0, "psx_counter_w( %08x, %08x, %08x ) unknown register\n", offset, mem_mask, data ); + return; + } + + root_timer_adjust( p_psx, n_counter ); +} + +READ32_HANDLER( psx_counter_r ) +{ + psx_machine *p_psx = space->machine->driver_data()->p_psx; + int n_counter = offset / 4; + psx_root *root = &p_psx->root[ n_counter ]; + UINT32 data; + + switch( offset % 4 ) + { + case 0: + data = root_current( p_psx, n_counter ); + break; + case 1: + data = root->n_mode; + break; + case 2: + data = root->n_target; + break; + default: + verboselog( p_psx, 0, "psx_counter_r( %08x, %08x ) unknown register\n", offset, mem_mask ); + return 0; + } + verboselog( p_psx, 1, "psx_counter_r ( %08x, %08x ) %08x\n", offset, mem_mask, data ); + return data; +} + +/* SIO */ + +static void sio_interrupt( psx_machine *p_psx, int n_port ) +{ + psx_sio *sio = &p_psx->sio[ n_port ]; + + verboselog( p_psx, 1, "sio_interrupt( %d )\n", n_port ); + sio->n_status |= SIO_STATUS_IRQ; + if( n_port == 0 ) + { + psx_irq_set( p_psx->machine, PSX_IRQ_SIO0 ); + } + else + { + psx_irq_set( p_psx->machine, PSX_IRQ_SIO1 ); + } +} + +static void sio_timer_adjust( psx_machine *p_psx, int n_port ) +{ + psx_sio *sio = &p_psx->sio[ n_port ]; attotime n_time; - if( ( m_p_n_sio_status[ n_port ] & SIO_STATUS_TX_EMPTY ) == 0 || m_p_n_sio_tx_bits[ n_port ] != 0 ) + + if( ( sio->n_status & SIO_STATUS_TX_EMPTY ) == 0 || sio->n_tx_bits != 0 ) { int n_prescaler; - switch( m_p_n_sio_mode[ n_port ] & 3 ) + switch( sio->n_mode & 3 ) { case 1: n_prescaler = 1; @@ -723,282 +811,263 @@ static void sio_timer_adjust( running_machine *machine, int n_port ) break; } - if( m_p_n_sio_baud[ n_port ] != 0 && n_prescaler != 0 ) + if( sio->n_baud != 0 && n_prescaler != 0 ) { - n_time = attotime_mul(ATTOTIME_IN_HZ(33868800), n_prescaler * m_p_n_sio_baud[n_port]); - verboselog( machine, 2, "sio_timer_adjust( %d ) = %s ( %d x %d )\n", n_port, attotime_string(n_time, 9), n_prescaler, m_p_n_sio_baud[ n_port ] ); + n_time = attotime_mul(ATTOTIME_IN_HZ(33868800), n_prescaler * sio->n_baud); + verboselog( p_psx, 2, "sio_timer_adjust( %d ) = %s ( %d x %d )\n", n_port, attotime_string(n_time, 9), n_prescaler, sio->n_baud ); } else { n_time = attotime_never; - verboselog( machine, 0, "sio_timer_adjust( %d ) invalid baud rate ( %d x %d )\n", n_port, n_prescaler, m_p_n_sio_baud[ n_port ] ); + verboselog( p_psx, 0, "sio_timer_adjust( %d ) invalid baud rate ( %d x %d )\n", n_port, n_prescaler, sio->n_baud ); } } else { n_time = attotime_never; - verboselog( machine, 2, "sio_timer_adjust( %d ) finished\n", n_port ); + verboselog( p_psx, 2, "sio_timer_adjust( %d ) finished\n", n_port ); } - timer_adjust_oneshot( m_p_timer_sio[ n_port ], n_time, n_port); + timer_adjust_oneshot( sio->timer, n_time, n_port); } static TIMER_CALLBACK( sio_clock ) { + psx_machine *p_psx = machine->driver_data()->p_psx; int n_port = param; - verboselog( machine, 2, "sio tick\n" ); + psx_sio *sio = &p_psx->sio[ n_port ]; + verboselog( p_psx, 2, "sio tick\n" ); - if( m_p_n_sio_tx_bits[ n_port ] == 0 && - ( m_p_n_sio_control[ n_port ] & SIO_CONTROL_TX_ENA ) != 0 && - ( m_p_n_sio_status[ n_port ] & SIO_STATUS_TX_EMPTY ) == 0 ) + if( sio->n_tx_bits == 0 && + ( sio->n_control & SIO_CONTROL_TX_ENA ) != 0 && + ( sio->n_status & SIO_STATUS_TX_EMPTY ) == 0 ) { - m_p_n_sio_tx_bits[ n_port ] = 8; - m_p_n_sio_tx_shift[ n_port ] = m_p_n_sio_tx_data[ n_port ]; + sio->n_tx_bits = 8; + sio->n_tx_shift = sio->n_tx_data; if( n_port == 0 ) { - m_p_n_sio_rx_bits[ n_port ] = 8; - m_p_n_sio_rx_shift[ n_port ] = 0; + sio->n_rx_bits = 8; + sio->n_rx_shift = 0; } - m_p_n_sio_status[ n_port ] |= SIO_STATUS_TX_EMPTY; - m_p_n_sio_status[ n_port ] |= SIO_STATUS_TX_RDY; + sio->n_status |= SIO_STATUS_TX_EMPTY; + sio->n_status |= SIO_STATUS_TX_RDY; } - if( m_p_n_sio_tx_bits[ n_port ] != 0 ) + if( sio->n_tx_bits != 0 ) { - m_p_n_sio_tx[ n_port ] = ( m_p_n_sio_tx[ n_port ] & ~PSX_SIO_OUT_DATA ) | ( ( m_p_n_sio_tx_shift[ n_port ] & 1 ) * PSX_SIO_OUT_DATA ); - m_p_n_sio_tx_shift[ n_port ] >>= 1; - m_p_n_sio_tx_bits[ n_port ]--; + sio->n_tx = ( sio->n_tx & ~PSX_SIO_OUT_DATA ) | ( ( sio->n_tx_shift & 1 ) * PSX_SIO_OUT_DATA ); + sio->n_tx_shift >>= 1; + sio->n_tx_bits--; - if( m_p_f_sio_handler[ n_port ] != NULL ) + if( sio->fn_handler != NULL ) { if( n_port == 0 ) { - m_p_n_sio_tx[ n_port ] &= ~PSX_SIO_OUT_CLOCK; - m_p_f_sio_handler[ n_port ]( machine, m_p_n_sio_tx[ n_port ] ); - m_p_n_sio_tx[ n_port ] |= PSX_SIO_OUT_CLOCK; + sio->n_tx &= ~PSX_SIO_OUT_CLOCK; + (*sio->fn_handler)( machine, sio->n_tx ); + sio->n_tx |= PSX_SIO_OUT_CLOCK; } - m_p_f_sio_handler[ n_port ]( machine, m_p_n_sio_tx[ n_port ] ); + (*sio->fn_handler)( machine, sio->n_tx ); } - if( m_p_n_sio_tx_bits[ n_port ] == 0 && - ( m_p_n_sio_control[ n_port ] & SIO_CONTROL_TX_IENA ) != 0 ) + if( sio->n_tx_bits == 0 && + ( sio->n_control & SIO_CONTROL_TX_IENA ) != 0 ) { - sio_interrupt( machine, n_port ); + sio_interrupt( p_psx, n_port ); } } - if( m_p_n_sio_rx_bits[ n_port ] != 0 ) + if( sio->n_rx_bits != 0 ) { - m_p_n_sio_rx_shift[ n_port ] = ( m_p_n_sio_rx_shift[ n_port ] >> 1 ) | ( ( ( m_p_n_sio_rx[ n_port ] & PSX_SIO_IN_DATA ) / PSX_SIO_IN_DATA ) << 7 ); - m_p_n_sio_rx_bits[ n_port ]--; + sio->n_rx_shift = ( sio->n_rx_shift >> 1 ) | ( ( ( sio->n_rx & PSX_SIO_IN_DATA ) / PSX_SIO_IN_DATA ) << 7 ); + sio->n_rx_bits--; - if( m_p_n_sio_rx_bits[ n_port ] == 0 ) + if( sio->n_rx_bits == 0 ) { - if( ( m_p_n_sio_status[ n_port ] & SIO_STATUS_RX_RDY ) != 0 ) + if( ( sio->n_status & SIO_STATUS_RX_RDY ) != 0 ) { - m_p_n_sio_status[ n_port ] |= SIO_STATUS_OVERRUN; + sio->n_status |= SIO_STATUS_OVERRUN; } else { - m_p_n_sio_rx_data[ n_port ] = m_p_n_sio_rx_shift[ n_port ]; - m_p_n_sio_status[ n_port ] |= SIO_STATUS_RX_RDY; + sio->n_rx_data = sio->n_rx_shift; + sio->n_status |= SIO_STATUS_RX_RDY; } - if( ( m_p_n_sio_control[ n_port ] & SIO_CONTROL_RX_IENA ) != 0 ) + if( ( sio->n_control & SIO_CONTROL_RX_IENA ) != 0 ) { - sio_interrupt( machine, n_port ); + sio_interrupt( p_psx, n_port ); } } } - sio_timer_adjust( machine, n_port ); + sio_timer_adjust( p_psx, n_port ); } void psx_sio_input( running_machine *machine, int n_port, int n_mask, int n_data ) { - verboselog( machine, 1, "psx_sio_input( %d, %02x, %02x )\n", n_port, n_mask, n_data ); - m_p_n_sio_rx[ n_port ] = ( m_p_n_sio_rx[ n_port ] & ~n_mask ) | ( n_data & n_mask ); + psx_machine *p_psx = machine->driver_data()->p_psx; + psx_sio *sio = &p_psx->sio[ n_port ]; + verboselog( p_psx, 1, "psx_sio_input( %d, %02x, %02x )\n", n_port, n_mask, n_data ); + sio->n_rx = ( sio->n_rx & ~n_mask ) | ( n_data & n_mask ); - if( ( m_p_n_sio_rx[ n_port ] & PSX_SIO_IN_DSR ) != 0 ) + if( ( sio->n_rx & PSX_SIO_IN_DSR ) != 0 ) { - m_p_n_sio_status[ n_port ] |= SIO_STATUS_DSR; - if( ( m_p_n_sio_rx_prev[ n_port ] & PSX_SIO_IN_DSR ) == 0 && - ( m_p_n_sio_control[ n_port ] & SIO_CONTROL_DSR_IENA ) != 0 ) + sio->n_status |= SIO_STATUS_DSR; + if( ( sio->n_rx_prev & PSX_SIO_IN_DSR ) == 0 && + ( sio->n_control & SIO_CONTROL_DSR_IENA ) != 0 ) { - sio_interrupt( machine, n_port ); + sio_interrupt( p_psx, n_port ); } } else { - m_p_n_sio_status[ n_port ] &= ~SIO_STATUS_DSR; + sio->n_status &= ~SIO_STATUS_DSR; } - m_p_n_sio_rx_prev[ n_port ] = m_p_n_sio_rx[ n_port ]; + sio->n_rx_prev = sio->n_rx; } WRITE32_HANDLER( psx_sio_w ) { - running_machine *machine = space->machine; - int n_port; - - n_port = offset / 4; + psx_machine *p_psx = space->machine->driver_data()->p_psx; + int n_port = offset / 4; + psx_sio *sio = &p_psx->sio[ n_port ]; switch( offset % 4 ) { case 0: - verboselog( machine, 1, "psx_sio_w %d data %02x (%08x)\n", n_port, data, mem_mask ); - m_p_n_sio_tx_data[ n_port ] = data; - m_p_n_sio_status[ n_port ] &= ~( SIO_STATUS_TX_RDY ); - m_p_n_sio_status[ n_port ] &= ~( SIO_STATUS_TX_EMPTY ); - sio_timer_adjust( machine, n_port ); + verboselog( p_psx, 1, "psx_sio_w %d data %02x (%08x)\n", n_port, data, mem_mask ); + sio->n_tx_data = data; + sio->n_status &= ~( SIO_STATUS_TX_RDY ); + sio->n_status &= ~( SIO_STATUS_TX_EMPTY ); + sio_timer_adjust( p_psx, n_port ); break; case 1: - verboselog( machine, 0, "psx_sio_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); + verboselog( p_psx, 0, "psx_sio_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); break; case 2: if( ACCESSING_BITS_0_15 ) { - m_p_n_sio_mode[ n_port ] = data & 0xffff; - verboselog( machine, 1, "psx_sio_w %d mode %04x\n", n_port, data & 0xffff ); + sio->n_mode = data & 0xffff; + verboselog( p_psx, 1, "psx_sio_w %d mode %04x\n", n_port, data & 0xffff ); } if( ACCESSING_BITS_16_31 ) { - verboselog( machine, 1, "psx_sio_w %d control %04x\n", n_port, data >> 16 ); - m_p_n_sio_control[ n_port ] = data >> 16; + verboselog( p_psx, 1, "psx_sio_w %d control %04x\n", n_port, data >> 16 ); + sio->n_control = data >> 16; - if( ( m_p_n_sio_control[ n_port ] & SIO_CONTROL_RESET ) != 0 ) + if( ( sio->n_control & SIO_CONTROL_RESET ) != 0 ) { - verboselog( machine, 1, "psx_sio_w reset\n" ); - m_p_n_sio_status[ n_port ] |= SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY; - m_p_n_sio_status[ n_port ] &= ~( SIO_STATUS_RX_RDY | SIO_STATUS_OVERRUN | SIO_STATUS_IRQ ); + verboselog( p_psx, 1, "psx_sio_w reset\n" ); + sio->n_status |= SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY; + sio->n_status &= ~( SIO_STATUS_RX_RDY | SIO_STATUS_OVERRUN | SIO_STATUS_IRQ ); } - if( ( m_p_n_sio_control[ n_port ] & SIO_CONTROL_IACK ) != 0 ) + if( ( sio->n_control & SIO_CONTROL_IACK ) != 0 ) { - verboselog( machine, 1, "psx_sio_w iack\n" ); - m_p_n_sio_status[ n_port ] &= ~( SIO_STATUS_IRQ ); - m_p_n_sio_control[ n_port ] &= ~( SIO_CONTROL_IACK ); + verboselog( p_psx, 1, "psx_sio_w iack\n" ); + sio->n_status &= ~( SIO_STATUS_IRQ ); + sio->n_control &= ~( SIO_CONTROL_IACK ); } - if( ( m_p_n_sio_control[ n_port ] & SIO_CONTROL_DTR ) != 0 ) + if( ( sio->n_control & SIO_CONTROL_DTR ) != 0 ) { - m_p_n_sio_tx[ n_port ] |= PSX_SIO_OUT_DTR; + sio->n_tx |= PSX_SIO_OUT_DTR; } else { - m_p_n_sio_tx[ n_port ] &= ~PSX_SIO_OUT_DTR; + sio->n_tx &= ~PSX_SIO_OUT_DTR; } - if( ( ( m_p_n_sio_tx[ n_port ] ^ m_p_n_sio_tx_prev[ n_port ] ) & PSX_SIO_OUT_DTR ) != 0 ) + if( ( ( sio->n_tx ^ sio->n_tx_prev ) & PSX_SIO_OUT_DTR ) != 0 ) { - if( m_p_f_sio_handler[ n_port ] != NULL ) + if( sio->fn_handler != NULL ) { - m_p_f_sio_handler[ n_port ]( space->machine, m_p_n_sio_tx[ n_port ] ); + (*sio->fn_handler)( space->machine, sio->n_tx ); } } - m_p_n_sio_tx_prev[ n_port ] = m_p_n_sio_tx[ n_port ]; + sio->n_tx_prev = sio->n_tx; } break; case 3: if( ACCESSING_BITS_0_15 ) { - verboselog( machine, 0, "psx_sio_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); + verboselog( p_psx, 0, "psx_sio_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); } if( ACCESSING_BITS_16_31 ) { - m_p_n_sio_baud[ n_port ] = data >> 16; - verboselog( machine, 1, "psx_sio_w %d baud %04x\n", n_port, data >> 16 ); + sio->n_baud = data >> 16; + verboselog( p_psx, 1, "psx_sio_w %d baud %04x\n", n_port, data >> 16 ); } break; default: - verboselog( machine, 0, "psx_sio_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); + verboselog( p_psx, 0, "psx_sio_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); break; } } READ32_HANDLER( psx_sio_r ) { - running_machine *machine = space->machine; + psx_machine *p_psx = space->machine->driver_data()->p_psx; + int n_port = offset / 4; + psx_sio *sio = &p_psx->sio[ n_port ]; UINT32 data; - int n_port; - - n_port = offset / 4; switch( offset % 4 ) { case 0: - data = m_p_n_sio_rx_data[ n_port ]; - m_p_n_sio_status[ n_port ] &= ~( SIO_STATUS_RX_RDY ); - m_p_n_sio_rx_data[ n_port ] = 0xff; - verboselog( machine, 1, "psx_sio_r %d data %02x (%08x)\n", n_port, data, mem_mask ); + data = sio->n_rx_data; + sio->n_status &= ~( SIO_STATUS_RX_RDY ); + sio->n_rx_data = 0xff; + verboselog( p_psx, 1, "psx_sio_r %d data %02x (%08x)\n", n_port, data, mem_mask ); break; case 1: - data = m_p_n_sio_status[ n_port ]; + data = sio->n_status; if( ACCESSING_BITS_0_15 ) { - verboselog( machine, 1, "psx_sio_r %d status %04x\n", n_port, data & 0xffff ); + verboselog( p_psx, 1, "psx_sio_r %d status %04x\n", n_port, data & 0xffff ); } if( ACCESSING_BITS_16_31 ) { - verboselog( machine, 0, "psx_sio_r( %08x, %08x ) %08x\n", offset, mem_mask, data ); + verboselog( p_psx, 0, "psx_sio_r( %08x, %08x ) %08x\n", offset, mem_mask, data ); } break; case 2: - data = ( m_p_n_sio_control[ n_port ] << 16 ) | m_p_n_sio_mode[ n_port ]; + data = ( sio->n_control << 16 ) | sio->n_mode; if( ACCESSING_BITS_0_15 ) { - verboselog( machine, 1, "psx_sio_r %d mode %04x\n", n_port, data & 0xffff ); + verboselog( p_psx, 1, "psx_sio_r %d mode %04x\n", n_port, data & 0xffff ); } if( ACCESSING_BITS_16_31 ) { - verboselog( machine, 1, "psx_sio_r %d control %04x\n", n_port, data >> 16 ); + verboselog( p_psx, 1, "psx_sio_r %d control %04x\n", n_port, data >> 16 ); } break; case 3: - data = m_p_n_sio_baud[ n_port ] << 16; + data = sio->n_baud << 16; if( ACCESSING_BITS_0_15 ) { - verboselog( machine, 0, "psx_sio_r( %08x, %08x ) %08x\n", offset, mem_mask, data ); + verboselog( p_psx, 0, "psx_sio_r( %08x, %08x ) %08x\n", offset, mem_mask, data ); } if( ACCESSING_BITS_16_31 ) { - verboselog( machine, 1, "psx_sio_r %d baud %04x\n", n_port, data >> 16 ); + verboselog( p_psx, 1, "psx_sio_r %d baud %04x\n", n_port, data >> 16 ); } break; default: data = 0; - verboselog( machine, 0, "psx_sio_r( %08x, %08x ) %08x\n", offset, mem_mask, data ); + verboselog( p_psx, 0, "psx_sio_r( %08x, %08x ) %08x\n", offset, mem_mask, data ); break; } return data; } -void psx_sio_install_handler( int n_port, psx_sio_handler p_f_sio_handler ) +void psx_sio_install_handler( running_machine *machine, int n_port, psx_sio_handler p_f_sio_handler ) { - m_p_f_sio_handler[ n_port ] = p_f_sio_handler; + psx_machine *p_psx = machine->driver_data()->p_psx; + + p_psx->sio[ n_port ].fn_handler = p_f_sio_handler; } /* MDEC */ -static int mdec_decoded = 0; -static int mdec_offset = 0; -static UINT16 mdec_output[ 24 * 16 ]; - -#define DCTSIZE ( 8 ) -#define DCTSIZE2 ( DCTSIZE * DCTSIZE ) - -static INT32 m_p_n_mdec_quantize_y[ DCTSIZE2 ]; -static INT32 m_p_n_mdec_quantize_uv[ DCTSIZE2 ]; -static INT32 m_p_n_mdec_cos[ DCTSIZE2 ]; -static INT32 m_p_n_mdec_cos_precalc[ DCTSIZE2 * DCTSIZE2 ]; - -static UINT32 m_n_mdec0_command; -static UINT32 m_n_mdec0_address; -static UINT32 m_n_mdec0_size; -static UINT32 m_n_mdec1_command; -static UINT32 m_n_mdec1_status; - -static UINT16 m_p_n_mdec_clamp8[ 256 * 3 ]; -static UINT16 m_p_n_mdec_r5[ 256 * 3 ]; -static UINT16 m_p_n_mdec_g5[ 256 * 3 ]; -static UINT16 m_p_n_mdec_b5[ 256 * 3 ]; - static const UINT32 m_p_n_mdec_zigzag[ DCTSIZE2 ] = { 0, 1, 8, 16, 9, 2, 3, 10, @@ -1011,19 +1080,16 @@ static const UINT32 m_p_n_mdec_zigzag[ DCTSIZE2 ] = 53, 60, 61, 54, 47, 55, 62, 63 }; -static INT32 m_p_n_mdec_unpacked[ DCTSIZE2 * 6 * 2 ]; - -#define MDEC_COS_PRECALC_BITS ( 21 ) - -static void mdec_cos_precalc( void ) +static void mdec_cos_precalc( psx_machine *p_psx ) { + psx_mdec *p_mdec = &p_psx->mdec; UINT32 n_x; UINT32 n_y; UINT32 n_u; UINT32 n_v; INT32 *p_n_precalc; - p_n_precalc = m_p_n_mdec_cos_precalc; + p_n_precalc = p_mdec->p_n_cos_precalc; for( n_y = 0; n_y < 8; n_y++ ) { @@ -1034,23 +1100,24 @@ static void mdec_cos_precalc( void ) for( n_u = 0; n_u < 8; n_u++ ) { *( p_n_precalc++ ) = - ( ( m_p_n_mdec_cos[ ( n_u * 8 ) + n_x ] * - m_p_n_mdec_cos[ ( n_v * 8 ) + n_y ] ) >> ( 30 - MDEC_COS_PRECALC_BITS ) ); + ( ( p_mdec->p_n_cos[ ( n_u * 8 ) + n_x ] * + p_mdec->p_n_cos[ ( n_v * 8 ) + n_y ] ) >> ( 30 - MDEC_COS_PRECALC_BITS ) ); } } } } } -static void mdec_idct( INT32 *p_n_src, INT32 *p_n_dst ) +static void mdec_idct( psx_machine *p_psx, INT32 *p_n_src, INT32 *p_n_dst ) { + psx_mdec *p_mdec = &p_psx->mdec; UINT32 n_yx; UINT32 n_vu; INT32 p_n_z[ 8 ]; INT32 *p_n_data; INT32 *p_n_precalc; - p_n_precalc = m_p_n_mdec_cos_precalc; + p_n_precalc = p_mdec->p_n_cos_precalc; for( n_yx = 0; n_yx < DCTSIZE2; n_yx++ ) { @@ -1087,8 +1154,10 @@ INLINE INT32 mdec_unpack_val( UINT16 n_packed ) return ( ( (INT32)n_packed ) << 22 ) >> 22; } -static UINT32 mdec_unpack( UINT32 n_address ) +static UINT32 mdec_unpack( psx_machine *p_psx, UINT32 n_address ) { + UINT32 *p_n_psxram = p_psx->p_n_psxram; + psx_mdec *p_mdec = &p_psx->mdec; UINT8 n_z; INT32 n_qscale; UINT16 n_packed; @@ -1097,8 +1166,8 @@ static UINT32 mdec_unpack( UINT32 n_address ) INT32 p_n_unpacked[ 64 ]; INT32 *p_n_q; - p_n_q = m_p_n_mdec_quantize_uv; - p_n_block = m_p_n_mdec_unpacked; + p_n_q = p_mdec->p_n_quantize_uv; + p_n_block = p_mdec->p_n_unpacked; for( n_block = 0; n_block < 6; n_block++ ) { @@ -1106,9 +1175,9 @@ static UINT32 mdec_unpack( UINT32 n_address ) if( n_block == 2 ) { - p_n_q = m_p_n_mdec_quantize_y; + p_n_q = p_mdec->p_n_quantize_y; } - n_packed = psxreadword( n_address ); + n_packed = psxreadword( p_n_psxram, n_address ); n_address += 2; if( n_packed == 0xfe00 ) { @@ -1121,7 +1190,7 @@ static UINT32 mdec_unpack( UINT32 n_address ) n_z = 0; for( ;; ) { - n_packed = psxreadword( n_address ); + n_packed = psxreadword( p_n_psxram, n_address ); n_address += 2; if( n_packed == 0xfe00 ) @@ -1135,7 +1204,7 @@ static UINT32 mdec_unpack( UINT32 n_address ) } p_n_unpacked[ m_p_n_mdec_zigzag[ n_z ] ] = ( mdec_unpack_val( n_packed ) * p_n_q[ n_z ] * n_qscale ) / 8; } - mdec_idct( p_n_unpacked, p_n_block ); + mdec_idct( p_psx, p_n_unpacked, p_n_block ); p_n_block += DCTSIZE2; } return n_address; @@ -1161,36 +1230,37 @@ INLINE INT32 mdec_cb_to_b( INT32 n_cb ) return ( 1814 * n_cb ) >> 10; } -INLINE UINT16 mdec_clamp_r5( INT32 n_r ) +INLINE UINT16 mdec_clamp_r5( psx_mdec *p_mdec, INT32 n_r ) { - return m_p_n_mdec_r5[ n_r + 128 + 256 ]; + return p_mdec->p_n_r5[ n_r + 128 + 256 ]; } -INLINE UINT16 mdec_clamp_g5( INT32 n_g ) +INLINE UINT16 mdec_clamp_g5( psx_mdec *p_mdec, INT32 n_g ) { - return m_p_n_mdec_g5[ n_g + 128 + 256 ]; + return p_mdec->p_n_g5[ n_g + 128 + 256 ]; } -INLINE UINT16 mdec_clamp_b5( INT32 n_b ) +INLINE UINT16 mdec_clamp_b5( psx_mdec *p_mdec, INT32 n_b ) { - return m_p_n_mdec_b5[ n_b + 128 + 256 ]; + return p_mdec->p_n_b5[ n_b + 128 + 256 ]; } -INLINE void mdec_makergb15( UINT32 n_address, INT32 n_r, INT32 n_g, INT32 n_b, INT32 *p_n_y, UINT16 n_stp ) +INLINE void mdec_makergb15( psx_mdec *p_mdec, UINT32 n_address, INT32 n_r, INT32 n_g, INT32 n_b, INT32 *p_n_y, UINT16 n_stp ) { - mdec_output[ WORD_XOR_LE( n_address + 0 ) / 2 ] = n_stp | - mdec_clamp_r5( p_n_y[ 0 ] + n_r ) | - mdec_clamp_g5( p_n_y[ 0 ] + n_g ) | - mdec_clamp_b5( p_n_y[ 0 ] + n_b ); + p_mdec->p_n_output[ WORD_XOR_LE( n_address + 0 ) / 2 ] = n_stp | + mdec_clamp_r5( p_mdec, p_n_y[ 0 ] + n_r ) | + mdec_clamp_g5( p_mdec, p_n_y[ 0 ] + n_g ) | + mdec_clamp_b5( p_mdec, p_n_y[ 0 ] + n_b ); - mdec_output[ WORD_XOR_LE( n_address + 2 ) / 2 ] = n_stp | - mdec_clamp_r5( p_n_y[ 1 ] + n_r ) | - mdec_clamp_g5( p_n_y[ 1 ] + n_g ) | - mdec_clamp_b5( p_n_y[ 1 ] + n_b ); + p_mdec->p_n_output[ WORD_XOR_LE( n_address + 2 ) / 2 ] = n_stp | + mdec_clamp_r5( p_mdec, p_n_y[ 1 ] + n_r ) | + mdec_clamp_g5( p_mdec, p_n_y[ 1 ] + n_g ) | + mdec_clamp_b5( p_mdec, p_n_y[ 1 ] + n_b ); } -static void mdec_yuv2_to_rgb15( void ) +static void mdec_yuv2_to_rgb15( psx_machine *p_psx ) { + psx_mdec *p_mdec = &p_psx->mdec; INT32 n_r; INT32 n_g; INT32 n_b; @@ -1205,7 +1275,7 @@ static void mdec_yuv2_to_rgb15( void ) UINT16 n_stp; int n_address = 0; - if( ( m_n_mdec0_command & ( 1L << 25 ) ) != 0 ) + if( ( p_mdec->n_0_command & ( 1L << 25 ) ) != 0 ) { n_stp = 0x8000; } @@ -1214,9 +1284,9 @@ static void mdec_yuv2_to_rgb15( void ) n_stp = 0x0000; } - p_n_cr = &m_p_n_mdec_unpacked[ 0 ]; - p_n_cb = &m_p_n_mdec_unpacked[ DCTSIZE2 ]; - p_n_y = &m_p_n_mdec_unpacked[ DCTSIZE2 * 2 ]; + p_n_cr = &p_mdec->p_n_unpacked[ 0 ]; + p_n_cb = &p_mdec->p_n_unpacked[ DCTSIZE2 ]; + p_n_y = &p_mdec->p_n_unpacked[ DCTSIZE2 * 2 ]; for( n_z = 0; n_z < 2; n_z++ ) { @@ -1230,8 +1300,8 @@ static void mdec_yuv2_to_rgb15( void ) n_g = mdec_cr_to_g( n_cr ) + mdec_cb_to_g( n_cb ); n_b = mdec_cb_to_b( n_cb ); - mdec_makergb15( ( n_address + 0 ), n_r, n_g, n_b, p_n_y, n_stp ); - mdec_makergb15( ( n_address + 32 ), n_r, n_g, n_b, p_n_y + 8, n_stp ); + mdec_makergb15( p_mdec, ( n_address + 0 ), n_r, n_g, n_b, p_n_y, n_stp ); + mdec_makergb15( p_mdec, ( n_address + 32 ), n_r, n_g, n_b, p_n_y + 8, n_stp ); n_cr = *( p_n_cr + 4 ); n_cb = *( p_n_cb + 4 ); @@ -1239,8 +1309,8 @@ static void mdec_yuv2_to_rgb15( void ) n_g = mdec_cr_to_g( n_cr ) + mdec_cb_to_g( n_cb ); n_b = mdec_cb_to_b( n_cb ); - mdec_makergb15( ( n_address + 16 ), n_r, n_g, n_b, p_n_y + DCTSIZE2, n_stp ); - mdec_makergb15( ( n_address + 48 ), n_r, n_g, n_b, p_n_y + DCTSIZE2 + 8, n_stp ); + mdec_makergb15( p_mdec, ( n_address + 16 ), n_r, n_g, n_b, p_n_y + DCTSIZE2, n_stp ); + mdec_makergb15( p_mdec, ( n_address + 48 ), n_r, n_g, n_b, p_n_y + DCTSIZE2 + 8, n_stp ); p_n_cr++; p_n_cb++; @@ -1254,23 +1324,24 @@ static void mdec_yuv2_to_rgb15( void ) } p_n_y += DCTSIZE2; } - mdec_decoded = ( 16 * 16 ) / 2; + p_mdec->n_decoded = ( 16 * 16 ) / 2; } -INLINE UINT16 mdec_clamp8( INT32 n_r ) +INLINE UINT16 mdec_clamp8( psx_mdec *p_mdec, INT32 n_r ) { - return m_p_n_mdec_clamp8[ n_r + 128 + 256 ]; + return p_mdec->p_n_clamp8[ n_r + 128 + 256 ]; } -INLINE void mdec_makergb24( UINT32 n_address, INT32 n_r, INT32 n_g, INT32 n_b, INT32 *p_n_y, UINT32 n_stp ) +INLINE void mdec_makergb24( psx_mdec *p_mdec, UINT32 n_address, INT32 n_r, INT32 n_g, INT32 n_b, INT32 *p_n_y, UINT32 n_stp ) { - mdec_output[ WORD_XOR_LE( n_address + 0 ) / 2 ] = ( mdec_clamp8( p_n_y[ 0 ] + n_g ) << 8 ) | mdec_clamp8( p_n_y[ 0 ] + n_r ); - mdec_output[ WORD_XOR_LE( n_address + 2 ) / 2 ] = ( mdec_clamp8( p_n_y[ 1 ] + n_r ) << 8 ) | mdec_clamp8( p_n_y[ 0 ] + n_b ); - mdec_output[ WORD_XOR_LE( n_address + 4 ) / 2 ] = ( mdec_clamp8( p_n_y[ 1 ] + n_b ) << 8 ) | mdec_clamp8( p_n_y[ 1 ] + n_g ); + p_mdec->p_n_output[ WORD_XOR_LE( n_address + 0 ) / 2 ] = ( mdec_clamp8( p_mdec, p_n_y[ 0 ] + n_g ) << 8 ) | mdec_clamp8( p_mdec, p_n_y[ 0 ] + n_r ); + p_mdec->p_n_output[ WORD_XOR_LE( n_address + 2 ) / 2 ] = ( mdec_clamp8( p_mdec, p_n_y[ 1 ] + n_r ) << 8 ) | mdec_clamp8( p_mdec, p_n_y[ 0 ] + n_b ); + p_mdec->p_n_output[ WORD_XOR_LE( n_address + 4 ) / 2 ] = ( mdec_clamp8( p_mdec, p_n_y[ 1 ] + n_b ) << 8 ) | mdec_clamp8( p_mdec, p_n_y[ 1 ] + n_g ); } -static void mdec_yuv2_to_rgb24( void ) +static void mdec_yuv2_to_rgb24( psx_machine *p_psx ) { + psx_mdec *p_mdec = &p_psx->mdec; INT32 n_r; INT32 n_g; INT32 n_b; @@ -1285,7 +1356,7 @@ static void mdec_yuv2_to_rgb24( void ) UINT32 n_stp; int n_address = 0; - if( ( m_n_mdec0_command & ( 1L << 25 ) ) != 0 ) + if( ( p_psx->mdec.n_0_command & ( 1L << 25 ) ) != 0 ) { n_stp = 0x80008000; } @@ -1294,9 +1365,9 @@ static void mdec_yuv2_to_rgb24( void ) n_stp = 0x00000000; } - p_n_cr = &m_p_n_mdec_unpacked[ 0 ]; - p_n_cb = &m_p_n_mdec_unpacked[ DCTSIZE2 ]; - p_n_y = &m_p_n_mdec_unpacked[ DCTSIZE2 * 2 ]; + p_n_cr = &p_psx->mdec.p_n_unpacked[ 0 ]; + p_n_cb = &p_psx->mdec.p_n_unpacked[ DCTSIZE2 ]; + p_n_y = &p_psx->mdec.p_n_unpacked[ DCTSIZE2 * 2 ]; for( n_z = 0; n_z < 2; n_z++ ) { @@ -1310,8 +1381,8 @@ static void mdec_yuv2_to_rgb24( void ) n_g = mdec_cr_to_g( n_cr ) + mdec_cb_to_g( n_cb ); n_b = mdec_cb_to_b( n_cb ); - mdec_makergb24( ( n_address + 0 ), n_r, n_g, n_b, p_n_y, n_stp ); - mdec_makergb24( ( n_address + 48 ), n_r, n_g, n_b, p_n_y + 8, n_stp ); + mdec_makergb24( p_mdec, ( n_address + 0 ), n_r, n_g, n_b, p_n_y, n_stp ); + mdec_makergb24( p_mdec, ( n_address + 48 ), n_r, n_g, n_b, p_n_y + 8, n_stp ); n_cr = *( p_n_cr + 4 ); n_cb = *( p_n_cb + 4 ); @@ -1319,8 +1390,8 @@ static void mdec_yuv2_to_rgb24( void ) n_g = mdec_cr_to_g( n_cr ) + mdec_cb_to_g( n_cb ); n_b = mdec_cb_to_b( n_cb ); - mdec_makergb24( ( n_address + 24 ), n_r, n_g, n_b, p_n_y + DCTSIZE2, n_stp ); - mdec_makergb24( ( n_address + 72 ), n_r, n_g, n_b, p_n_y + DCTSIZE2 + 8, n_stp ); + mdec_makergb24( p_mdec, ( n_address + 24 ), n_r, n_g, n_b, p_n_y + DCTSIZE2, n_stp ); + mdec_makergb24( p_mdec, ( n_address + 72 ), n_r, n_g, n_b, p_n_y + DCTSIZE2 + 8, n_stp ); p_n_cr++; p_n_cb++; @@ -1334,40 +1405,42 @@ static void mdec_yuv2_to_rgb24( void ) } p_n_y += DCTSIZE2; } - mdec_decoded = ( 24 * 16 ) / 2; + p_psx->mdec.n_decoded = ( 24 * 16 ) / 2; } static void mdec0_write( running_machine *machine, UINT32 n_address, INT32 n_size ) { + psx_machine *p_psx = machine->driver_data()->p_psx; + UINT32 *p_n_psxram = p_psx->p_n_psxram; int n_index; - verboselog( machine, 2, "mdec0_write( %08x, %08x )\n", n_address, n_size ); - switch( m_n_mdec0_command >> 28 ) + verboselog( p_psx, 2, "mdec0_write( %08x, %08x )\n", n_address, n_size ); + switch( p_psx->mdec.n_0_command >> 28 ) { case 0x3: - verboselog( machine, 1, "mdec decode %08x %08x %08x\n", m_n_mdec0_command, n_address, n_size ); - m_n_mdec0_address = n_address; - m_n_mdec0_size = n_size * 4; - m_n_mdec1_status |= ( 1L << 29 ); + verboselog( p_psx, 1, "mdec decode %08x %08x %08x\n", p_psx->mdec.n_0_command, n_address, n_size ); + p_psx->mdec.n_0_address = n_address; + p_psx->mdec.n_0_size = n_size * 4; + p_psx->mdec.n_1_status |= ( 1L << 29 ); break; case 0x4: - verboselog( machine, 1, "mdec quantize table %08x %08x %08x\n", m_n_mdec0_command, n_address, n_size ); + verboselog( p_psx, 1, "mdec quantize table %08x %08x %08x\n", p_psx->mdec.n_0_command, n_address, n_size ); n_index = 0; while( n_size > 0 ) { if( n_index < DCTSIZE2 ) { - m_p_n_mdec_quantize_y[ n_index + 0 ] = ( g_p_n_psxram[ n_address / 4 ] >> 0 ) & 0xff; - m_p_n_mdec_quantize_y[ n_index + 1 ] = ( g_p_n_psxram[ n_address / 4 ] >> 8 ) & 0xff; - m_p_n_mdec_quantize_y[ n_index + 2 ] = ( g_p_n_psxram[ n_address / 4 ] >> 16 ) & 0xff; - m_p_n_mdec_quantize_y[ n_index + 3 ] = ( g_p_n_psxram[ n_address / 4 ] >> 24 ) & 0xff; + p_psx->mdec.p_n_quantize_y[ n_index + 0 ] = ( p_n_psxram[ n_address / 4 ] >> 0 ) & 0xff; + p_psx->mdec.p_n_quantize_y[ n_index + 1 ] = ( p_n_psxram[ n_address / 4 ] >> 8 ) & 0xff; + p_psx->mdec.p_n_quantize_y[ n_index + 2 ] = ( p_n_psxram[ n_address / 4 ] >> 16 ) & 0xff; + p_psx->mdec.p_n_quantize_y[ n_index + 3 ] = ( p_n_psxram[ n_address / 4 ] >> 24 ) & 0xff; } else if( n_index < DCTSIZE2 * 2 ) { - m_p_n_mdec_quantize_uv[ n_index + 0 - DCTSIZE2 ] = ( g_p_n_psxram[ n_address / 4 ] >> 0 ) & 0xff; - m_p_n_mdec_quantize_uv[ n_index + 1 - DCTSIZE2 ] = ( g_p_n_psxram[ n_address / 4 ] >> 8 ) & 0xff; - m_p_n_mdec_quantize_uv[ n_index + 2 - DCTSIZE2 ] = ( g_p_n_psxram[ n_address / 4 ] >> 16 ) & 0xff; - m_p_n_mdec_quantize_uv[ n_index + 3 - DCTSIZE2 ] = ( g_p_n_psxram[ n_address / 4 ] >> 24 ) & 0xff; + p_psx->mdec.p_n_quantize_uv[ n_index + 0 - DCTSIZE2 ] = ( p_n_psxram[ n_address / 4 ] >> 0 ) & 0xff; + p_psx->mdec.p_n_quantize_uv[ n_index + 1 - DCTSIZE2 ] = ( p_n_psxram[ n_address / 4 ] >> 8 ) & 0xff; + p_psx->mdec.p_n_quantize_uv[ n_index + 2 - DCTSIZE2 ] = ( p_n_psxram[ n_address / 4 ] >> 16 ) & 0xff; + p_psx->mdec.p_n_quantize_uv[ n_index + 3 - DCTSIZE2 ] = ( p_n_psxram[ n_address / 4 ] >> 24 ) & 0xff; } n_index += 4; n_address += 4; @@ -1375,161 +1448,174 @@ static void mdec0_write( running_machine *machine, UINT32 n_address, INT32 n_siz } break; case 0x6: - verboselog( machine, 1, "mdec cosine table %08x %08x %08x\n", m_n_mdec0_command, n_address, n_size ); + verboselog( p_psx, 1, "mdec cosine table %08x %08x %08x\n", p_psx->mdec.n_0_command, n_address, n_size ); n_index = 0; while( n_size > 0 ) { - m_p_n_mdec_cos[ n_index + 0 ] = (INT16)( ( g_p_n_psxram[ n_address / 4 ] >> 0 ) & 0xffff ); - m_p_n_mdec_cos[ n_index + 1 ] = (INT16)( ( g_p_n_psxram[ n_address / 4 ] >> 16 ) & 0xffff ); + p_psx->mdec.p_n_cos[ n_index + 0 ] = (INT16)( ( p_n_psxram[ n_address / 4 ] >> 0 ) & 0xffff ); + p_psx->mdec.p_n_cos[ n_index + 1 ] = (INT16)( ( p_n_psxram[ n_address / 4 ] >> 16 ) & 0xffff ); n_index += 2; n_address += 4; n_size--; } - mdec_cos_precalc(); + mdec_cos_precalc(p_psx); break; default: - verboselog( machine, 0, "mdec unknown command %08x %08x %08x\n", m_n_mdec0_command, n_address, n_size ); + verboselog( p_psx, 0, "mdec unknown command %08x %08x %08x\n", p_psx->mdec.n_0_command, n_address, n_size ); break; } } static void mdec1_read( running_machine *machine, UINT32 n_address, INT32 n_size ) { + psx_machine *p_psx = machine->driver_data()->p_psx; + UINT32 *p_n_psxram = p_psx->p_n_psxram; UINT32 n_this; UINT32 n_nextaddress; - verboselog( machine, 2, "mdec1_read( %08x, %08x )\n", n_address, n_size ); - if( ( m_n_mdec0_command & ( 1L << 29 ) ) != 0 && m_n_mdec0_size != 0 ) + verboselog( p_psx, 2, "mdec1_read( %08x, %08x )\n", n_address, n_size ); + if( ( p_psx->mdec.n_0_command & ( 1L << 29 ) ) != 0 && p_psx->mdec.n_0_size != 0 ) { while( n_size > 0 ) { - if( mdec_decoded == 0 ) + if( p_psx->mdec.n_decoded == 0 ) { - if( (int)m_n_mdec0_size <= 0 ) + if( (int)p_psx->mdec.n_0_size <= 0 ) { mame_printf_debug( "ran out of data %08x\n", n_size ); - m_n_mdec0_size = 0; + p_psx->mdec.n_0_size = 0; break; } - n_nextaddress = mdec_unpack( m_n_mdec0_address ); - m_n_mdec0_size -= n_nextaddress - m_n_mdec0_address; - m_n_mdec0_address = n_nextaddress; + n_nextaddress = mdec_unpack( p_psx, p_psx->mdec.n_0_address ); + p_psx->mdec.n_0_size -= n_nextaddress - p_psx->mdec.n_0_address; + p_psx->mdec.n_0_address = n_nextaddress; - if( ( m_n_mdec0_command & ( 1L << 27 ) ) != 0 ) + if( ( p_psx->mdec.n_0_command & ( 1L << 27 ) ) != 0 ) { - mdec_yuv2_to_rgb15(); + mdec_yuv2_to_rgb15(p_psx); } else { - mdec_yuv2_to_rgb24(); + mdec_yuv2_to_rgb24(p_psx); } - mdec_offset = 0; + p_psx->mdec.n_offset = 0; } - n_this = mdec_decoded; + n_this = p_psx->mdec.n_decoded; if( n_this > n_size ) { n_this = n_size; } - mdec_decoded -= n_this; + p_psx->mdec.n_decoded -= n_this; - memcpy( (UINT8 *)g_p_n_psxram + n_address, (UINT8 *)mdec_output + mdec_offset, n_this * 4 ); - mdec_offset += n_this * 4; + memcpy( (UINT8 *)p_n_psxram + n_address, (UINT8 *)p_psx->mdec.p_n_output + p_psx->mdec.n_offset, n_this * 4 ); + p_psx->mdec.n_offset += n_this * 4; n_address += n_this * 4; n_size -= n_this; } - if( (int)m_n_mdec0_size < 0 ) + if( (int)p_psx->mdec.n_0_size < 0 ) { - mame_printf_debug( "ran out of data %d\n", m_n_mdec0_size ); + mame_printf_debug( "ran out of data %d\n", p_psx->mdec.n_0_size ); } } else { - mame_printf_debug( "mdec1_read no conversion :%08x:%08x:\n", m_n_mdec0_command, m_n_mdec0_size ); + mame_printf_debug( "mdec1_read no conversion :%08x:%08x:\n", p_psx->mdec.n_0_command, p_psx->mdec.n_0_size ); } - m_n_mdec1_status &= ~( 1L << 29 ); + p_psx->mdec.n_1_status &= ~( 1L << 29 ); } WRITE32_HANDLER( psx_mdec_w ) { + psx_machine *p_psx = space->machine->driver_data()->p_psx; + switch( offset ) { case 0: - verboselog( space->machine, 2, "mdec 0 command %08x\n", data ); - m_n_mdec0_command = data; + verboselog( p_psx, 2, "mdec 0 command %08x\n", data ); + p_psx->mdec.n_0_command = data; break; case 1: - verboselog( space->machine, 2, "mdec 1 command %08x\n", data ); - m_n_mdec1_command = data; + verboselog( p_psx, 2, "mdec 1 command %08x\n", data ); + p_psx->mdec.n_1_command = data; break; } } READ32_HANDLER( psx_mdec_r ) { + psx_machine *p_psx = space->machine->driver_data()->p_psx; + switch( offset ) { case 0: - verboselog( space->machine, 2, "mdec 0 status %08x\n", 0 ); + verboselog( p_psx, 2, "mdec 0 status %08x\n", 0 ); return 0; case 1: - verboselog( space->machine, 2, "mdec 1 status %08x\n", m_n_mdec1_status ); - return m_n_mdec1_status; + verboselog( p_psx, 2, "mdec 1 status %08x\n", p_psx->mdec.n_1_status ); + return p_psx->mdec.n_1_status; } return 0; } static void gpu_read( running_machine *machine, UINT32 n_address, INT32 n_size ) { - psx_gpu_read( machine, &g_p_n_psxram[ n_address / 4 ], n_size ); + psx_machine *p_psx = machine->driver_data()->p_psx; + UINT32 *p_n_psxram = p_psx->p_n_psxram; + + psx_gpu_read( machine, &p_n_psxram[ n_address / 4 ], n_size ); } static void gpu_write( running_machine *machine, UINT32 n_address, INT32 n_size ) { - psx_gpu_write( machine, &g_p_n_psxram[ n_address / 4 ], n_size ); + psx_machine *p_psx = machine->driver_data()->p_psx; + UINT32 *p_n_psxram = p_psx->p_n_psxram; + + psx_gpu_write( machine, &p_n_psxram[ n_address / 4 ], n_size ); } void psx_machine_init( running_machine *machine ) { + psx_machine *p_psx = machine->driver_data()->p_psx; int n; /* irq */ - m_n_irqdata = 0; - m_n_irqmask = 0; + p_psx->n_irqdata = 0; + p_psx->n_irqmask = 0; /* dma */ - m_n_dpcp = 0; - m_n_dicr = 0; + p_psx->n_dpcp = 0; + p_psx->n_dicr = 0; - m_n_mdec0_command = 0; - m_n_mdec0_address = 0; - m_n_mdec0_size = 0; - m_n_mdec1_command = 0; - m_n_mdec1_status = 0; + p_psx->mdec.n_0_command = 0; + p_psx->mdec.n_0_address = 0; + p_psx->mdec.n_0_size = 0; + p_psx->mdec.n_1_command = 0; + p_psx->mdec.n_1_status = 0; for( n = 0; n < 7; n++ ) { - dma_stop_timer( n ); + dma_stop_timer( p_psx, n ); } for( n = 0; n < 2; n++ ) { - m_p_n_sio_status[ n ] = SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY; - m_p_n_sio_mode[ n ] = 0; - m_p_n_sio_control[ n ] = 0; - m_p_n_sio_baud[ n ] = 0; - m_p_n_sio_tx[ n ] = 0; - m_p_n_sio_rx[ n ] = 0; - m_p_n_sio_tx_prev[ n ] = 0; - m_p_n_sio_rx_prev[ n ] = 0; - m_p_n_sio_rx_data[ n ] = 0; - m_p_n_sio_tx_data[ n ] = 0; - m_p_n_sio_rx_shift[ n ] = 0; - m_p_n_sio_tx_shift[ n ] = 0; - m_p_n_sio_rx_bits[ n ] = 0; - m_p_n_sio_tx_bits[ n ] = 0; + p_psx->sio[ n ].n_status = SIO_STATUS_TX_EMPTY | SIO_STATUS_TX_RDY; + p_psx->sio[ n ].n_mode = 0; + p_psx->sio[ n ].n_control = 0; + p_psx->sio[ n ].n_baud = 0; + p_psx->sio[ n ].n_tx = 0; + p_psx->sio[ n ].n_rx = 0; + p_psx->sio[ n ].n_tx_prev = 0; + p_psx->sio[ n ].n_rx_prev = 0; + p_psx->sio[ n ].n_rx_data = 0; + p_psx->sio[ n ].n_tx_data = 0; + p_psx->sio[ n ].n_rx_shift = 0; + p_psx->sio[ n ].n_tx_shift = 0; + p_psx->sio[ n ].n_rx_bits = 0; + p_psx->sio[ n ].n_tx_bits = 0; } psx_gpu_reset(machine); @@ -1537,116 +1623,131 @@ void psx_machine_init( running_machine *machine ) static STATE_POSTLOAD( psx_postload ) { + psx_machine *p_psx = machine->driver_data()->p_psx; int n; - psx_irq_update(machine); + psx_irq_update(p_psx); for( n = 0; n < 7; n++ ) { - dma_timer_adjust( n ); + dma_timer_adjust( p_psx, n ); } for( n = 0; n < 3; n++ ) { - root_timer_adjust( machine, n ); + root_timer_adjust( p_psx, n ); } for( n = 0; n < 2; n++ ) { - sio_timer_adjust( machine, n ); + sio_timer_adjust( p_psx, n ); } - mdec_cos_precalc(); + mdec_cos_precalc(p_psx); } void psx_driver_init( running_machine *machine ) { + psx_state *state = machine->driver_data(); + psx_machine *p_psx = auto_alloc_clear(machine, psx_machine); int n; + state->p_psx = p_psx; + state->p_n_psxram = (UINT32 *)memory_get_shared(*machine, "share1", state->n_psxramsize); + + p_psx->machine = machine; + p_psx->p_n_psxram = state->p_n_psxram; + p_psx->n_psxramsize = state->n_psxramsize; + for( n = 0; n < 7; n++ ) { - m_p_timer_dma[ n ] = timer_alloc( machine, dma_finished_callback, machine ); - m_p_fn_dma_read[ n ] = NULL; - m_p_fn_dma_write[ n ] = NULL; + p_psx->channel[ n ].timer = timer_alloc( machine, dma_finished_callback, machine ); + p_psx->channel[ n ].fn_read = NULL; + p_psx->channel[ n ].fn_write = NULL; } for( n = 0; n < 3; n++ ) { - m_p_timer_root[ n ] = timer_alloc( machine, root_finished , NULL); + p_psx->root[ n ].timer = timer_alloc( machine, root_finished , NULL); } for( n = 0; n < 2; n++ ) { - m_p_timer_sio[ n ] = timer_alloc( machine, sio_clock , NULL); + p_psx->sio[ n ].timer = timer_alloc( machine, sio_clock , NULL); + p_psx->sio[ n ].fn_handler = NULL; } for( n = 0; n < 256; n++ ) { - m_p_n_mdec_clamp8[ n ] = 0; - m_p_n_mdec_clamp8[ n + 256 ] = n; - m_p_n_mdec_clamp8[ n + 512 ] = 255; + p_psx->mdec.p_n_clamp8[ n ] = 0; + p_psx->mdec.p_n_clamp8[ n + 256 ] = n; + p_psx->mdec.p_n_clamp8[ n + 512 ] = 255; - m_p_n_mdec_r5[ n ] = 0; - m_p_n_mdec_r5[ n + 256 ] = ( n >> 3 ); - m_p_n_mdec_r5[ n + 512 ] = ( 255 >> 3 ); + p_psx->mdec.p_n_r5[ n ] = 0; + p_psx->mdec.p_n_r5[ n + 256 ] = ( n >> 3 ); + p_psx->mdec.p_n_r5[ n + 512 ] = ( 255 >> 3 ); - m_p_n_mdec_g5[ n ] = 0; - m_p_n_mdec_g5[ n + 256 ] = ( n >> 3 ) << 5; - m_p_n_mdec_g5[ n + 512 ] = ( 255 >> 3 ) << 5; + p_psx->mdec.p_n_g5[ n ] = 0; + p_psx->mdec.p_n_g5[ n + 256 ] = ( n >> 3 ) << 5; + p_psx->mdec.p_n_g5[ n + 512 ] = ( 255 >> 3 ) << 5; - m_p_n_mdec_b5[ n ] = 0; - m_p_n_mdec_b5[ n + 256 ] = ( n >> 3 ) << 10; - m_p_n_mdec_b5[ n + 512 ] = ( 255 >> 3 ) << 10; + p_psx->mdec.p_n_b5[ n ] = 0; + p_psx->mdec.p_n_b5[ n + 256 ] = ( n >> 3 ) << 10; + p_psx->mdec.p_n_b5[ n + 512 ] = ( 255 >> 3 ) << 10; } + psx_dma_install_read_handler( machine, 1, mdec1_read ); + psx_dma_install_read_handler( machine, 2, gpu_read ); + + psx_dma_install_write_handler( machine, 0, mdec0_write ); + psx_dma_install_write_handler( machine, 2, gpu_write ); + + state_save_register_global( machine, p_psx->n_irqdata ); + state_save_register_global( machine, p_psx->n_irqmask ); + for (n = 0; n < 7; n++ ) + { + state_save_register_item( machine, "psxdma", NULL, n, p_psx->channel[n].n_base ); + state_save_register_item( machine, "psxdma", NULL, n, p_psx->channel[n].n_blockcontrol ); + state_save_register_item( machine, "psxdma", NULL, n, p_psx->channel[n].n_channelcontrol ); + state_save_register_item( machine, "psxdma", NULL, n, p_psx->channel[n].n_ticks ); + state_save_register_item( machine, "psxdma", NULL, n, p_psx->channel[n].b_running ); + } + + state_save_register_global( machine, p_psx->n_dpcp ); + state_save_register_global( machine, p_psx->n_dicr ); + for ( n = 0; n < 3; n++ ) + { + state_save_register_item( machine, "psxroot", NULL, n, p_psx->root[n].n_count ); + state_save_register_item( machine, "psxroot", NULL, n, p_psx->root[n].n_mode ); + state_save_register_item( machine, "psxroot", NULL, n, p_psx->root[n].n_target ); + state_save_register_item( machine, "psxroot", NULL, n, p_psx->root[n].n_start ); + } for( n = 0; n < 2; n++ ) { - m_p_f_sio_handler[ n ] = NULL; + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_status ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_mode ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_control ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_baud ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_tx ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_rx ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_tx_prev ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_rx_prev ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_rx_data ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_tx_data ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_rx_shift ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_tx_shift ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_rx_bits ); + state_save_register_item( machine, "psxsio", NULL, n, p_psx->sio[n].n_tx_bits ); } - psx_dma_install_read_handler( 1, mdec1_read ); - psx_dma_install_read_handler( 2, gpu_read ); - - psx_dma_install_write_handler( 0, mdec0_write ); - psx_dma_install_write_handler( 2, gpu_write ); - - state_save_register_global(machine, m_n_irqdata ); - state_save_register_global(machine, m_n_irqmask ); - state_save_register_global_array(machine, m_p_n_dmabase ); - state_save_register_global_array(machine, m_p_n_dmablockcontrol ); - state_save_register_global_array(machine, m_p_n_dmachannelcontrol ); - state_save_register_global_array(machine, m_p_n_dma_ticks ); - state_save_register_global_array(machine, m_p_b_dma_running ); - state_save_register_global(machine, m_n_dpcp ); - state_save_register_global(machine, m_n_dicr ); - state_save_register_global_array(machine, m_p_n_root_count ); - state_save_register_global_array(machine, m_p_n_root_mode ); - state_save_register_global_array(machine, m_p_n_root_target ); - state_save_register_global_array(machine, m_p_n_root_start ); - - state_save_register_global_array(machine, m_p_n_sio_status ); - state_save_register_global_array(machine, m_p_n_sio_mode ); - state_save_register_global_array(machine, m_p_n_sio_control ); - state_save_register_global_array(machine, m_p_n_sio_baud ); - state_save_register_global_array(machine, m_p_n_sio_tx ); - state_save_register_global_array(machine, m_p_n_sio_rx ); - state_save_register_global_array(machine, m_p_n_sio_tx_prev ); - state_save_register_global_array(machine, m_p_n_sio_rx_prev ); - state_save_register_global_array(machine, m_p_n_sio_rx_data ); - state_save_register_global_array(machine, m_p_n_sio_tx_data ); - state_save_register_global_array(machine, m_p_n_sio_rx_shift ); - state_save_register_global_array(machine, m_p_n_sio_tx_shift ); - state_save_register_global_array(machine, m_p_n_sio_rx_bits ); - state_save_register_global_array(machine, m_p_n_sio_tx_bits ); - - state_save_register_global(machine, m_n_mdec0_command ); - state_save_register_global(machine, m_n_mdec0_address ); - state_save_register_global(machine, m_n_mdec0_size ); - state_save_register_global(machine, m_n_mdec1_command ); - state_save_register_global(machine, m_n_mdec1_status ); - state_save_register_global_array(machine, m_p_n_mdec_quantize_y ); - state_save_register_global_array(machine, m_p_n_mdec_quantize_uv ); - state_save_register_global_array(machine, m_p_n_mdec_cos ); + state_save_register_global( machine, p_psx->mdec.n_0_command ); + state_save_register_global( machine, p_psx->mdec.n_0_address ); + state_save_register_global( machine, p_psx->mdec.n_0_size ); + state_save_register_global( machine, p_psx->mdec.n_1_command ); + state_save_register_global( machine, p_psx->mdec.n_1_status ); + state_save_register_global_array( machine, p_psx->mdec.p_n_quantize_y ); + state_save_register_global_array( machine, p_psx->mdec.p_n_quantize_uv ); + state_save_register_global_array( machine, p_psx->mdec.p_n_cos ); state_save_register_postload( machine, psx_postload, NULL ); } diff --git a/src/mame/video/psx.c b/src/mame/video/psx.c index 95fdd15b25d..bdcf0b747c4 100644 --- a/src/mame/video/psx.c +++ b/src/mame/video/psx.c @@ -24,18 +24,13 @@ #define VERBOSE_LEVEL ( 0 ) -INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, const char *s_fmt, ... ) -{ - if( VERBOSE_LEVEL >= n_level ) - { - va_list v; - char buf[ 32768 ]; - va_start( v, s_fmt ); - vsprintf( buf, s_fmt, v ); - va_end( v ); - logerror( "%s: %s", cpuexec_describe_context(machine), buf ); - } -} +#define MAX_LEVEL ( 32 ) +#define MID_LEVEL ( ( MAX_LEVEL / 2 ) << 8 ) +#define MAX_SHADE ( 0x100 ) +#define MID_SHADE ( 0x80 ) + +#define DEBUG_COORDS ( 10 ) +#define DEBUG_MAX ( 512 ) struct FLATVERTEX { @@ -61,7 +56,7 @@ struct GOURAUDTEXTUREDVERTEX PAIR n_texture; }; -static union +union PACKET { UINT32 n_entry[ 16 ]; @@ -151,10 +146,25 @@ static union PAIR n_bgr; struct FLATVERTEX vertex; } Dot; -} m_packet; +}; -static struct PSXGPU +typedef struct _psx_gpu_debug psx_gpu_debug; +struct _psx_gpu_debug { + bitmap_t *mesh; + int b_clear; + int b_mesh; + int n_skip; + int b_texture; + int n_interleave; + int n_coord; + int n_coordx[ DEBUG_COORDS ]; + int n_coordy[ DEBUG_COORDS ]; +}; + +struct _psx_gpu +{ + running_machine *machine; INT32 n_tx; INT32 n_ty; INT32 n_abr; @@ -162,85 +172,83 @@ static struct PSXGPU INT32 n_ix; INT32 n_iy; INT32 n_ti; -} psxgpu; -static UINT16 *m_p_vram; -static UINT32 m_n_vram_size; -static UINT32 m_n_gpu_buffer_offset; -static UINT32 m_n_vramx; -static UINT32 m_n_vramy; -static UINT32 m_n_twy; -static UINT32 m_n_twx; -static UINT32 m_n_twh; -static UINT32 m_n_tww; -static UINT32 m_n_drawarea_x1; -static UINT32 m_n_drawarea_y1; -static UINT32 m_n_drawarea_x2; -static UINT32 m_n_drawarea_y2; -static UINT32 m_n_horiz_disstart; -static UINT32 m_n_horiz_disend; -static UINT32 m_n_vert_disstart; -static UINT32 m_n_vert_disend; -static UINT32 m_b_reverseflag; -static INT32 m_n_drawoffset_x; -static INT32 m_n_drawoffset_y; -static UINT32 m_n_displaystartx; -static UINT32 m_n_displaystarty; -static UINT32 m_n_gpustatus; -static UINT32 m_n_gpuinfo; -static UINT32 m_n_lightgun_x; -static UINT32 m_n_lightgun_y; -static UINT32 m_n_screenwidth; -static UINT32 m_n_screenheight; + UINT16 *p_vram; + UINT32 n_vram_size; + UINT32 n_vramx; + UINT32 n_vramy; + UINT32 n_twy; + UINT32 n_twx; + UINT32 n_twh; + UINT32 n_tww; + UINT32 n_drawarea_x1; + UINT32 n_drawarea_y1; + UINT32 n_drawarea_x2; + UINT32 n_drawarea_y2; + UINT32 n_horiz_disstart; + UINT32 n_horiz_disend; + UINT32 n_vert_disstart; + UINT32 n_vert_disend; + UINT32 b_reverseflag; + INT32 n_drawoffset_x; + INT32 n_drawoffset_y; + UINT32 n_displaystartx; + UINT32 n_displaystarty; + int n_gputype; + UINT32 n_gpustatus; + UINT32 n_gpuinfo; + UINT32 n_gpu_buffer_offset; + UINT32 n_lightgun_x; + UINT32 n_lightgun_y; + UINT32 n_screenwidth; + UINT32 n_screenheight; -#define MAX_LEVEL ( 32 ) -#define MID_LEVEL ( ( MAX_LEVEL / 2 ) << 8 ) -#define MAX_SHADE ( 0x100 ) -#define MID_SHADE ( 0x80 ) + int b_need_sianniv_vblank_hack; + PACKET m_packet; -static int m_n_gputype; + psx_gpu_debug m_debug; -static UINT16 *m_p_p_vram[ 1024 ]; + UINT16 *p_p_vram[ 1024 ]; -static UINT16 m_p_n_redshade[ MAX_LEVEL * MAX_SHADE ]; -static UINT16 m_p_n_greenshade[ MAX_LEVEL * MAX_SHADE ]; -static UINT16 m_p_n_blueshade[ MAX_LEVEL * MAX_SHADE ]; -static UINT16 m_p_n_redlevel[ 0x10000 ]; -static UINT16 m_p_n_greenlevel[ 0x10000 ]; -static UINT16 m_p_n_bluelevel[ 0x10000 ]; + UINT16 p_n_redshade[ MAX_LEVEL * MAX_SHADE ]; + UINT16 p_n_greenshade[ MAX_LEVEL * MAX_SHADE ]; + UINT16 p_n_blueshade[ MAX_LEVEL * MAX_SHADE ]; + UINT16 p_n_redlevel[ 0x10000 ]; + UINT16 p_n_greenlevel[ 0x10000 ]; + UINT16 p_n_bluelevel[ 0x10000 ]; + + UINT16 p_n_f025[ MAX_LEVEL * MAX_SHADE ]; + UINT16 p_n_f05[ MAX_LEVEL * MAX_SHADE ]; + UINT16 p_n_f1[ MAX_LEVEL * MAX_SHADE ]; + UINT16 p_n_redb05[ 0x10000 ]; + UINT16 p_n_greenb05[ 0x10000 ]; + UINT16 p_n_blueb05[ 0x10000 ]; + UINT16 p_n_redb1[ 0x10000 ]; + UINT16 p_n_greenb1[ 0x10000 ]; + UINT16 p_n_blueb1[ 0x10000 ]; + UINT16 p_n_redaddtrans[ MAX_LEVEL * MAX_LEVEL ]; + UINT16 p_n_greenaddtrans[ MAX_LEVEL * MAX_LEVEL ]; + UINT16 p_n_blueaddtrans[ MAX_LEVEL * MAX_LEVEL ]; + UINT16 p_n_redsubtrans[ MAX_LEVEL * MAX_LEVEL ]; + UINT16 p_n_greensubtrans[ MAX_LEVEL * MAX_LEVEL ]; + UINT16 p_n_bluesubtrans[ MAX_LEVEL * MAX_LEVEL ]; + + UINT16 p_n_g0r0[ 0x10000 ]; + UINT16 p_n_b0[ 0x10000 ]; + UINT16 p_n_r1[ 0x10000 ]; + UINT16 p_n_b1g1[ 0x10000 ]; +}; -static UINT16 m_p_n_f025[ MAX_LEVEL * MAX_SHADE ]; -static UINT16 m_p_n_f05[ MAX_LEVEL * MAX_SHADE ]; -static UINT16 m_p_n_f1[ MAX_LEVEL * MAX_SHADE ]; -static UINT16 m_p_n_redb05[ 0x10000 ]; -static UINT16 m_p_n_greenb05[ 0x10000 ]; -static UINT16 m_p_n_blueb05[ 0x10000 ]; -static UINT16 m_p_n_redb1[ 0x10000 ]; -static UINT16 m_p_n_greenb1[ 0x10000 ]; -static UINT16 m_p_n_blueb1[ 0x10000 ]; -static UINT16 m_p_n_redaddtrans[ MAX_LEVEL * MAX_LEVEL ]; -static UINT16 m_p_n_greenaddtrans[ MAX_LEVEL * MAX_LEVEL ]; -static UINT16 m_p_n_blueaddtrans[ MAX_LEVEL * MAX_LEVEL ]; -static UINT16 m_p_n_redsubtrans[ MAX_LEVEL * MAX_LEVEL ]; -static UINT16 m_p_n_greensubtrans[ MAX_LEVEL * MAX_LEVEL ]; -static UINT16 m_p_n_bluesubtrans[ MAX_LEVEL * MAX_LEVEL ]; static const UINT16 m_p_n_nextpointlist4[] = { 1, 3, 0, 2 }; static const UINT16 m_p_n_prevpointlist4[] = { 2, 0, 3, 1 }; static const UINT16 m_p_n_nextpointlist3[] = { 1, 2, 0 }; static const UINT16 m_p_n_prevpointlist3[] = { 2, 0, 1 }; -static UINT16 m_p_n_g0r0[ 0x10000 ]; -static UINT16 m_p_n_b0[ 0x10000 ]; -static UINT16 m_p_n_r1[ 0x10000 ]; -static UINT16 m_p_n_b1g1[ 0x10000 ]; - -static int need_sianniv_vblank_hack; - #define SINT11( x ) ( ( (INT32)( x ) << 21 ) >> 21 ) #define ADJUST_COORD( a ) \ - a.w.l = COORD_X( a ) + m_n_drawoffset_x; \ - a.w.h = COORD_Y( a ) + m_n_drawoffset_y; + a.w.l = COORD_X( a ) + p_psxgpu->n_drawoffset_x; \ + a.w.h = COORD_Y( a ) + p_psxgpu->n_drawoffset_y; #define COORD_X( a ) ( (INT16)a.w.l ) #define COORD_Y( a ) ( (INT16)a.w.h ) @@ -253,6 +261,19 @@ static int need_sianniv_vblank_hack; #define TEXTURE_V( a ) ( (UINT8)a.b.h ) #define TEXTURE_U( a ) ( (UINT8)a.b.l ) +INLINE void ATTR_PRINTF(3,4) verboselog( psx_gpu *p_psxgpu, int n_level, const char *s_fmt, ... ) +{ + if( VERBOSE_LEVEL >= n_level ) + { + va_list v; + char buf[ 32768 ]; + va_start( v, s_fmt ); + vsprintf( buf, s_fmt, v ); + va_end( v ); + logerror( "%s: %s", cpuexec_describe_context(p_psxgpu->machine), buf ); + } +} + PALETTE_INIT( psx ) { UINT32 n_colour; @@ -265,56 +286,39 @@ PALETTE_INIT( psx ) #if defined( MAME_DEBUG ) -#define DEBUG_COORDS ( 10 ) -static struct +static void DebugMeshInit( psx_gpu *p_psxgpu ) { - running_machine *machine; - bitmap_t *mesh; - int b_clear; - int b_mesh; - int n_skip; - int b_texture; - int n_interleave; - int n_coord; - int n_coordx[ DEBUG_COORDS ]; - int n_coordy[ DEBUG_COORDS ]; -} m_debug; + screen_device *screen = p_psxgpu->machine->primary_screen; + int width = screen->width(); + int height = screen->height(); -#define DEBUG_MAX ( 512 ) - -static void DebugMeshInit( running_machine *machine ) -{ - int width = machine->primary_screen->width(); - int height = machine->primary_screen->height(); - - m_debug.b_mesh = 0; - m_debug.b_texture = 0; - m_debug.n_interleave = -1; - m_debug.b_clear = 1; - m_debug.n_coord = 0; - m_debug.n_skip = 0; - m_debug.mesh = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 ); - m_debug.machine = machine; + p_psxgpu->m_debug.b_mesh = 0; + p_psxgpu->m_debug.b_texture = 0; + p_psxgpu->m_debug.n_interleave = -1; + p_psxgpu->m_debug.b_clear = 1; + p_psxgpu->m_debug.n_coord = 0; + p_psxgpu->m_debug.n_skip = 0; + p_psxgpu->m_debug.mesh = auto_bitmap_alloc( p_psxgpu->machine, width, height, BITMAP_FORMAT_INDEXED16 ); } -static void DebugMesh( int n_coordx, int n_coordy ) +static void DebugMesh( psx_gpu *p_psxgpu, int n_coordx, int n_coordy ) { - running_machine *machine = m_debug.machine; int n_coord; int n_colour; - int width = machine->primary_screen->width(); - int height = machine->primary_screen->height(); + screen_device *screen = p_psxgpu->machine->primary_screen; + int width = screen->width(); + int height = screen->height(); - if( m_debug.b_clear ) + if( p_psxgpu->m_debug.b_clear ) { - bitmap_fill( m_debug.mesh, NULL , 0x0000); - m_debug.b_clear = 0; + bitmap_fill( p_psxgpu->m_debug.mesh, NULL , 0x0000); + p_psxgpu->m_debug.b_clear = 0; } - if( m_debug.n_coord < DEBUG_COORDS ) + if( p_psxgpu->m_debug.n_coord < DEBUG_COORDS ) { - n_coordx += m_n_displaystartx; - n_coordy += m_n_displaystarty; + n_coordx += p_psxgpu->n_displaystartx; + n_coordy += p_psxgpu->n_displaystarty; n_coordx *= 511; n_coordx /= DEBUG_MAX - 1; @@ -323,25 +327,25 @@ static void DebugMesh( int n_coordx, int n_coordy ) n_coordy /= DEBUG_MAX - 1; n_coordy += 256; - m_debug.n_coordx[ m_debug.n_coord ] = n_coordx; - m_debug.n_coordy[ m_debug.n_coord ] = n_coordy; - m_debug.n_coord++; + p_psxgpu->m_debug.n_coordx[ p_psxgpu->m_debug.n_coord ] = n_coordx; + p_psxgpu->m_debug.n_coordy[ p_psxgpu->m_debug.n_coord ] = n_coordy; + p_psxgpu->m_debug.n_coord++; } n_colour = 0x1f; - for( n_coord = 0; n_coord < m_debug.n_coord; n_coord++ ) + for( n_coord = 0; n_coord < p_psxgpu->m_debug.n_coord; n_coord++ ) { - if( n_coordx != m_debug.n_coordx[ n_coord ] || - n_coordy != m_debug.n_coordy[ n_coord ] ) + if( n_coordx != p_psxgpu->m_debug.n_coordx[ n_coord ] || + n_coordy != p_psxgpu->m_debug.n_coordy[ n_coord ] ) { break; } } - if( n_coord == m_debug.n_coord && m_debug.n_coord > 1 ) + if( n_coord == p_psxgpu->m_debug.n_coord && p_psxgpu->m_debug.n_coord > 1 ) { n_colour = 0xffff; } - for( n_coord = 0; n_coord < m_debug.n_coord; n_coord++ ) + for( n_coord = 0; n_coord < p_psxgpu->m_debug.n_coord; n_coord++ ) { PAIR n_x; PAIR n_y; @@ -355,7 +359,7 @@ static void DebugMesh( int n_coordx, int n_coordy ) INT32 n_dx; INT32 n_dy; - n_xstart = m_debug.n_coordx[ n_coord ]; + n_xstart = p_psxgpu->m_debug.n_coordx[ n_coord ]; n_xend = n_coordx; if( n_xend > n_xstart ) { @@ -366,7 +370,7 @@ static void DebugMesh( int n_coordx, int n_coordy ) n_xlen = n_xstart - n_xend; } - n_ystart = m_debug.n_coordy[ n_coord ]; + n_ystart = p_psxgpu->m_debug.n_coordy[ n_coord ]; n_yend = n_coordy; if( n_yend > n_ystart ) { @@ -403,8 +407,8 @@ static void DebugMesh( int n_coordx, int n_coordy ) (INT16)n_x.w.h <= width - 1 && (INT16)n_y.w.h <= height - 1 ) { - if( *BITMAP_ADDR16(m_debug.mesh, n_y.w.h, n_x.w.h) != 0xffff ) - *BITMAP_ADDR16(m_debug.mesh, n_y.w.h, n_x.w.h) = n_colour; + if( *BITMAP_ADDR16(p_psxgpu->m_debug.mesh, n_y.w.h, n_x.w.h) != 0xffff ) + *BITMAP_ADDR16(p_psxgpu->m_debug.mesh, n_y.w.h, n_x.w.h) = n_colour; } n_x.d += n_dx; n_y.d += n_dy; @@ -413,105 +417,107 @@ static void DebugMesh( int n_coordx, int n_coordy ) } } -static void DebugMeshEnd( void ) +static void DebugMeshEnd( psx_gpu *p_psxgpu ) { - m_debug.n_coord = 0; + p_psxgpu->m_debug.n_coord = 0; } -static void DebugCheckKeys( running_machine *machine ) +static void DebugCheckKeys( psx_gpu *p_psxgpu ) { - if( input_code_pressed_once( machine, KEYCODE_M ) ) - m_debug.b_mesh = !m_debug.b_mesh; + if( input_code_pressed_once( p_psxgpu->machine, KEYCODE_M ) ) + p_psxgpu->m_debug.b_mesh = !p_psxgpu->m_debug.b_mesh; - if( input_code_pressed_once( machine, KEYCODE_V ) ) - m_debug.b_texture = !m_debug.b_texture; + if( input_code_pressed_once( p_psxgpu->machine, KEYCODE_V ) ) + p_psxgpu->m_debug.b_texture = !p_psxgpu->m_debug.b_texture; - if( m_debug.b_mesh || m_debug.b_texture ) + if( p_psxgpu->m_debug.b_mesh || p_psxgpu->m_debug.b_texture ) { - int width = machine->primary_screen->width(); - int height = machine->primary_screen->height(); - machine->primary_screen->set_visible_area( 0, width - 1, 0, height - 1 ); + screen_device *screen = p_psxgpu->machine->primary_screen; + int width = screen->width(); + int height = screen->height(); + p_psxgpu->machine->primary_screen->set_visible_area( 0, width - 1, 0, height - 1 ); } else - machine->primary_screen->set_visible_area( 0, m_n_screenwidth - 1, 0, m_n_screenheight - 1 ); + p_psxgpu->machine->primary_screen->set_visible_area( 0, p_psxgpu->n_screenwidth - 1, 0, p_psxgpu->n_screenheight - 1 ); - if( input_code_pressed_once( machine, KEYCODE_I ) ) + if( input_code_pressed_once( p_psxgpu->machine, KEYCODE_I ) ) { - if( m_debug.b_texture ) + if( p_psxgpu->m_debug.b_texture ) { - m_debug.n_interleave++; + p_psxgpu->m_debug.n_interleave++; - if( m_debug.n_interleave == 2 ) - m_debug.n_interleave = -1; + if( p_psxgpu->m_debug.n_interleave == 2 ) + p_psxgpu->m_debug.n_interleave = -1; - if( m_debug.n_interleave == -1 ) + if( p_psxgpu->m_debug.n_interleave == -1 ) popmessage( "interleave off" ); - else if( m_debug.n_interleave == 0 ) + else if( p_psxgpu->m_debug.n_interleave == 0 ) popmessage( "4 bit interleave" ); - else if( m_debug.n_interleave == 1 ) + else if( p_psxgpu->m_debug.n_interleave == 1 ) popmessage( "8 bit interleave" ); } else { - m_debug.n_skip++; + p_psxgpu->m_debug.n_skip++; - if( m_debug.n_skip > 15 ) - m_debug.n_skip = 0; + if( p_psxgpu->m_debug.n_skip > 15 ) + p_psxgpu->m_debug.n_skip = 0; - popmessage( "debug skip %d", m_debug.n_skip ); + popmessage( "debug skip %d", p_psxgpu->m_debug.n_skip ); } } #if 0 - if( input_code_pressed_once( machine, KEYCODE_D ) ) + if( input_code_pressed_once( p_psxgpu->machine, KEYCODE_D ) ) { FILE *f; int n_x; f = fopen( "dump.txt", "w" ); for( n_y = 256; n_y < 512; n_y++ ) for( n_x = 640; n_x < 1024; n_x++ ) - fprintf( f, "%04u,%04u = %04x\n", n_y, n_x, m_p_p_vram[ n_y ][ n_x ] ); + fprintf( f, "%04u,%04u = %04x\n", n_y, n_x, p_psxgpu->p_p_vram[ n_y ][ n_x ] ); fclose( f ); } - if( input_code_pressed_once( machine, KEYCODE_S ) ) + if( input_code_pressed_once( p_psxgpu->machine, KEYCODE_S ) ) { FILE *f; popmessage( "saving..." ); f = fopen( "VRAM.BIN", "wb" ); for( n_y = 0; n_y < 1024; n_y++ ) - fwrite( m_p_p_vram[ n_y ], 1024 * 2, 1, f ); + fwrite( p_psxgpu->p_p_vram[ n_y ], 1024 * 2, 1, f ); fclose( f ); } - if( input_code_pressed_once( machine, KEYCODE_L ) ) + if( input_code_pressed_once( p_psxgpu->machine, KEYCODE_L ) ) { FILE *f; popmessage( "loading..." ); f = fopen( "VRAM.BIN", "rb" ); for( n_y = 0; n_y < 1024; n_y++ ) - fread( m_p_p_vram[ n_y ], 1024 * 2, 1, f ); + fread( p_psxgpu->p_p_vram[ n_y ], 1024 * 2, 1, f ); fclose( f ); } #endif } -static int DebugMeshDisplay( bitmap_t *bitmap, const rectangle *cliprect ) +static int DebugMeshDisplay( psx_gpu *p_psxgpu, bitmap_t *bitmap, const rectangle *cliprect ) { - if( m_debug.mesh ) + if( p_psxgpu->m_debug.mesh ) { - copybitmap( bitmap, m_debug.mesh, 0, 0, 0, 0, cliprect ); + copybitmap( bitmap, p_psxgpu->m_debug.mesh, 0, 0, 0, 0, cliprect ); } - m_debug.b_clear = 1; - return m_debug.b_mesh; + p_psxgpu->m_debug.b_clear = 1; + return p_psxgpu->m_debug.b_mesh; } -static int DebugTextureDisplay( running_machine *machine, bitmap_t *bitmap ) +static int DebugTextureDisplay( psx_gpu *p_psxgpu, bitmap_t *bitmap ) { UINT32 n_y; - if( m_debug.b_texture ) + if( p_psxgpu->m_debug.b_texture ) { - int width = machine->primary_screen->width(); - int height = machine->primary_screen->height(); + screen_device *screen = p_psxgpu->machine->primary_screen; + int width = screen->width(); + int height = screen->height(); for( n_y = 0; n_y < height; n_y++ ) { @@ -522,12 +528,12 @@ static int DebugTextureDisplay( running_machine *machine, bitmap_t *bitmap ) for( n_x = 0; n_x < width; n_x++ ) { - if( m_debug.n_interleave == 0 ) + if( p_psxgpu->m_debug.n_interleave == 0 ) { n_xi = ( n_x & ~0x3c ) + ( ( n_y << 2 ) & 0x3c ); n_yi = ( n_y & ~0xf ) + ( ( n_x >> 2 ) & 0xf ); } - else if( m_debug.n_interleave == 1 ) + else if( p_psxgpu->m_debug.n_interleave == 1 ) { n_xi = ( n_x & ~0x78 ) + ( ( n_x << 3 ) & 0x40 ) + ( ( n_y << 3 ) & 0x38 ); n_yi = ( n_y & ~0x7 ) + ( ( n_x >> 4 ) & 0x7 ); @@ -537,32 +543,33 @@ static int DebugTextureDisplay( running_machine *machine, bitmap_t *bitmap ) n_xi = n_x; n_yi = n_y; } - p_n_interleave[ n_x ] = m_p_p_vram[ n_yi ][ n_xi ]; + p_n_interleave[ n_x ] = p_psxgpu->p_p_vram[ n_yi ][ n_xi ]; } - draw_scanline16( bitmap, 0, n_y, width, p_n_interleave, machine->pens ); + draw_scanline16( bitmap, 0, n_y, width, p_n_interleave, p_psxgpu->machine->pens ); } } - return m_debug.b_texture; + return p_psxgpu->m_debug.b_texture; } #endif static STATE_POSTLOAD( updatevisiblearea ) { + psx_gpu *p_psxgpu = machine->driver_data()->p_psxgpu; rectangle visarea; float refresh; - if( ( m_n_gpustatus & ( 1 << 0x14 ) ) != 0 ) + if( ( p_psxgpu->n_gpustatus & ( 1 << 0x14 ) ) != 0 ) { /* pal */ refresh = 50; - switch( ( m_n_gpustatus >> 0x13 ) & 1 ) + switch( ( p_psxgpu->n_gpustatus >> 0x13 ) & 1 ) { case 0: - m_n_screenheight = 256; + p_psxgpu->n_screenheight = 256; break; case 1: - m_n_screenheight = 512; + p_psxgpu->n_screenheight = 512; break; } } @@ -570,55 +577,56 @@ static STATE_POSTLOAD( updatevisiblearea ) { /* ntsc */ refresh = 60; - switch( ( m_n_gpustatus >> 0x13 ) & 1 ) + switch( ( p_psxgpu->n_gpustatus >> 0x13 ) & 1 ) { case 0: - m_n_screenheight = 240; + p_psxgpu->n_screenheight = 240; break; case 1: - m_n_screenheight = 480; + p_psxgpu->n_screenheight = 480; break; } } - switch( ( m_n_gpustatus >> 0x11 ) & 3 ) + switch( ( p_psxgpu->n_gpustatus >> 0x11 ) & 3 ) { case 0: - switch( ( m_n_gpustatus >> 0x10 ) & 1 ) + switch( ( p_psxgpu->n_gpustatus >> 0x10 ) & 1 ) { case 0: - m_n_screenwidth = 256; + p_psxgpu->n_screenwidth = 256; break; case 1: - m_n_screenwidth = 368; + p_psxgpu->n_screenwidth = 368; break; } break; case 1: - switch( ( m_n_gpustatus >> 0x10 ) & 1 ) + switch( ( p_psxgpu->n_gpustatus >> 0x10 ) & 1 ) { case 0: - m_n_screenwidth = 320; + p_psxgpu->n_screenwidth = 320; break; case 1: - m_n_screenwidth = 384; + p_psxgpu->n_screenwidth = 384; break; } break; case 2: - m_n_screenwidth = 512; + p_psxgpu->n_screenwidth = 512; break; case 3: - m_n_screenwidth = 640; + p_psxgpu->n_screenwidth = 640; break; } visarea.min_x = visarea.min_y = 0; - visarea.max_x = m_n_screenwidth - 1; - visarea.max_y = m_n_screenheight - 1; - machine->primary_screen->configure(m_n_screenwidth, m_n_screenheight, visarea, HZ_TO_ATTOSECONDS(refresh)); + visarea.max_x = p_psxgpu->n_screenwidth - 1; + visarea.max_y = p_psxgpu->n_screenheight - 1; + machine->primary_screen->configure(p_psxgpu->n_screenwidth, p_psxgpu->n_screenheight, visarea, HZ_TO_ATTOSECONDS(refresh)); } -static void psx_gpu_init( running_machine *machine ) +static void psx_gpu_init( running_machine *machine, int n_gputype ) { + psx_gpu *p_psxgpu = auto_alloc_clear(machine, psx_gpu); int n_line; int n_level; int n_level2; @@ -627,24 +635,26 @@ static void psx_gpu_init( running_machine *machine ) int width = machine->primary_screen->width(); int height = machine->primary_screen->height(); - need_sianniv_vblank_hack = !strcmp(machine->gamedrv->name, "sianniv"); + p_psxgpu->machine = machine; + p_psxgpu->n_gputype = n_gputype; + p_psxgpu->b_need_sianniv_vblank_hack = !strcmp(machine->gamedrv->name, "sianniv"); #if defined( MAME_DEBUG ) - DebugMeshInit(machine); + DebugMeshInit(p_psxgpu); #endif - m_n_gpustatus = 0x14802000; - m_n_gpuinfo = 0; - m_n_gpu_buffer_offset = 0; - m_n_lightgun_x = 0; - m_n_lightgun_y = 0; + p_psxgpu->n_gpustatus = 0x14802000; + p_psxgpu->n_gpuinfo = 0; + p_psxgpu->n_gpu_buffer_offset = 0; + p_psxgpu->n_lightgun_x = 0; + p_psxgpu->n_lightgun_y = 0; - m_n_vram_size = width * height; - m_p_vram = auto_alloc_array_clear(machine, UINT16, m_n_vram_size ); + p_psxgpu->n_vram_size = width * height; + p_psxgpu->p_vram = auto_alloc_array_clear( machine, UINT16, p_psxgpu->n_vram_size ); for( n_line = 0; n_line < 1024; n_line++ ) { - m_p_p_vram[ n_line ] = &m_p_vram[ ( n_line % height ) * width ]; + p_psxgpu->p_p_vram[ n_line ] = &p_psxgpu->p_vram[ ( n_line % height ) * width ]; } for( n_level = 0; n_level < MAX_LEVEL; n_level++ ) @@ -657,9 +667,9 @@ static void psx_gpu_init( running_machine *machine ) { n_shaded = MAX_LEVEL - 1; } - m_p_n_redshade[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded; - m_p_n_greenshade[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded << 5; - m_p_n_blueshade[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded << 10; + p_psxgpu->p_n_redshade[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded; + p_psxgpu->p_n_greenshade[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded << 5; + p_psxgpu->p_n_blueshade[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded << 10; /* 1/4 x transparency */ n_shaded = ( n_level * n_shade ) / MID_SHADE; @@ -668,7 +678,7 @@ static void psx_gpu_init( running_machine *machine ) { n_shaded = MAX_LEVEL - 1; } - m_p_n_f025[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded; + p_psxgpu->p_n_f025[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded; /* 1/2 x transparency */ n_shaded = ( n_level * n_shade ) / MID_SHADE; @@ -677,7 +687,7 @@ static void psx_gpu_init( running_machine *machine ) { n_shaded = MAX_LEVEL - 1; } - m_p_n_f05[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded; + p_psxgpu->p_n_f05[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded; /* 1 x transparency */ n_shaded = ( n_level * n_shade ) / MID_SHADE; @@ -685,31 +695,31 @@ static void psx_gpu_init( running_machine *machine ) { n_shaded = MAX_LEVEL - 1; } - m_p_n_f1[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded; + p_psxgpu->p_n_f1[ ( n_level * MAX_SHADE ) | n_shade ] = n_shaded; } } for( n_level = 0; n_level < 0x10000; n_level++ ) { - m_p_n_redlevel[ n_level ] = ( n_level & ( MAX_LEVEL - 1 ) ) * MAX_SHADE; - m_p_n_greenlevel[ n_level ] = ( ( n_level >> 5 ) & ( MAX_LEVEL - 1 ) ) * MAX_SHADE; - m_p_n_bluelevel[ n_level ] = ( ( n_level >> 10 ) & ( MAX_LEVEL - 1 ) ) * MAX_SHADE; + p_psxgpu->p_n_redlevel[ n_level ] = ( n_level & ( MAX_LEVEL - 1 ) ) * MAX_SHADE; + p_psxgpu->p_n_greenlevel[ n_level ] = ( ( n_level >> 5 ) & ( MAX_LEVEL - 1 ) ) * MAX_SHADE; + p_psxgpu->p_n_bluelevel[ n_level ] = ( ( n_level >> 10 ) & ( MAX_LEVEL - 1 ) ) * MAX_SHADE; /* 0.5 * background */ - m_p_n_redb05[ n_level ] = ( ( n_level & ( MAX_LEVEL - 1 ) ) / 2 ) * MAX_LEVEL; - m_p_n_greenb05[ n_level ] = ( ( ( n_level >> 5 ) & ( MAX_LEVEL - 1 ) ) / 2 ) * MAX_LEVEL; - m_p_n_blueb05[ n_level ] = ( ( ( n_level >> 10 ) & ( MAX_LEVEL - 1 ) ) / 2 ) * MAX_LEVEL; + p_psxgpu->p_n_redb05[ n_level ] = ( ( n_level & ( MAX_LEVEL - 1 ) ) / 2 ) * MAX_LEVEL; + p_psxgpu->p_n_greenb05[ n_level ] = ( ( ( n_level >> 5 ) & ( MAX_LEVEL - 1 ) ) / 2 ) * MAX_LEVEL; + p_psxgpu->p_n_blueb05[ n_level ] = ( ( ( n_level >> 10 ) & ( MAX_LEVEL - 1 ) ) / 2 ) * MAX_LEVEL; /* 1 * background */ - m_p_n_redb1[ n_level ] = ( n_level & ( MAX_LEVEL - 1 ) ) * MAX_LEVEL; - m_p_n_greenb1[ n_level ] = ( ( n_level >> 5 ) & ( MAX_LEVEL - 1 ) ) * MAX_LEVEL; - m_p_n_blueb1[ n_level ] = ( ( n_level >> 10 ) & ( MAX_LEVEL - 1 ) ) * MAX_LEVEL; + p_psxgpu->p_n_redb1[ n_level ] = ( n_level & ( MAX_LEVEL - 1 ) ) * MAX_LEVEL; + p_psxgpu->p_n_greenb1[ n_level ] = ( ( n_level >> 5 ) & ( MAX_LEVEL - 1 ) ) * MAX_LEVEL; + p_psxgpu->p_n_blueb1[ n_level ] = ( ( n_level >> 10 ) & ( MAX_LEVEL - 1 ) ) * MAX_LEVEL; /* 24bit to 15 bit conversion */ - m_p_n_g0r0[ n_level ] = ( ( ( n_level >> 11 ) & ( MAX_LEVEL - 1 ) ) << 5 ) | ( ( ( n_level >> 3 ) & ( MAX_LEVEL - 1 ) ) << 0 ); - m_p_n_b0[ n_level ] = ( ( n_level >> 3 ) & ( MAX_LEVEL - 1 ) ) << 10; - m_p_n_r1[ n_level ] = ( ( n_level >> 11 ) & ( MAX_LEVEL - 1 ) ) << 0; - m_p_n_b1g1[ n_level ] = ( ( ( n_level >> 11 ) & ( MAX_LEVEL - 1 ) ) << 10 ) | ( ( ( n_level >> 3 ) & ( MAX_LEVEL - 1 ) ) << 5 ); + p_psxgpu->p_n_g0r0[ n_level ] = ( ( ( n_level >> 11 ) & ( MAX_LEVEL - 1 ) ) << 5 ) | ( ( ( n_level >> 3 ) & ( MAX_LEVEL - 1 ) ) << 0 ); + p_psxgpu->p_n_b0[ n_level ] = ( ( n_level >> 3 ) & ( MAX_LEVEL - 1 ) ) << 10; + p_psxgpu->p_n_r1[ n_level ] = ( ( n_level >> 11 ) & ( MAX_LEVEL - 1 ) ) << 0; + p_psxgpu->p_n_b1g1[ n_level ] = ( ( ( n_level >> 11 ) & ( MAX_LEVEL - 1 ) ) << 10 ) | ( ( ( n_level >> 3 ) & ( MAX_LEVEL - 1 ) ) << 5 ); } for( n_level = 0; n_level < MAX_LEVEL; n_level++ ) @@ -722,9 +732,9 @@ static void psx_gpu_init( running_machine *machine ) { n_shaded = MAX_LEVEL - 1; } - m_p_n_redaddtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded; - m_p_n_greenaddtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded << 5; - m_p_n_blueaddtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded << 10; + p_psxgpu->p_n_redaddtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded; + p_psxgpu->p_n_greenaddtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded << 5; + p_psxgpu->p_n_blueaddtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded << 10; /* sub transparency */ n_shaded = ( n_level - n_level2 ); @@ -732,64 +742,64 @@ static void psx_gpu_init( running_machine *machine ) { n_shaded = 0; } - m_p_n_redsubtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded; - m_p_n_greensubtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded << 5; - m_p_n_bluesubtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded << 10; + p_psxgpu->p_n_redsubtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded; + p_psxgpu->p_n_greensubtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded << 5; + p_psxgpu->p_n_bluesubtrans[ ( n_level * MAX_LEVEL ) | n_level2 ] = n_shaded << 10; } } // icky!!! - state_save_register_memory( machine, "globals", NULL, 0, "m_packet", (UINT8 *)&m_packet, 1, sizeof( m_packet ), __FILE__, __LINE__ ); + state_save_register_memory( machine, "globals", NULL, 0, "m_packet", (UINT8 *)&p_psxgpu->m_packet, 1, sizeof( p_psxgpu->m_packet ), __FILE__, __LINE__ ); - state_save_register_global_pointer(machine, m_p_vram, m_n_vram_size ); - state_save_register_global(machine, m_n_gpu_buffer_offset ); - state_save_register_global(machine, m_n_vramx ); - state_save_register_global(machine, m_n_vramy ); - state_save_register_global(machine, m_n_twy ); - state_save_register_global(machine, m_n_twx ); - state_save_register_global(machine, m_n_tww ); - state_save_register_global(machine, m_n_drawarea_x1 ); - state_save_register_global(machine, m_n_drawarea_y1 ); - state_save_register_global(machine, m_n_drawarea_x2 ); - state_save_register_global(machine, m_n_drawarea_y2 ); - state_save_register_global(machine, m_n_horiz_disstart ); - state_save_register_global(machine, m_n_horiz_disend ); - state_save_register_global(machine, m_n_vert_disstart ); - state_save_register_global(machine, m_n_vert_disend ); - state_save_register_global(machine, m_b_reverseflag ); - state_save_register_global(machine, m_n_drawoffset_x ); - state_save_register_global(machine, m_n_drawoffset_y ); - state_save_register_global(machine, m_n_displaystartx ); - state_save_register_global(machine, m_n_displaystarty ); - state_save_register_global(machine, m_n_gpustatus ); - state_save_register_global(machine, m_n_gpuinfo ); - state_save_register_global(machine, m_n_lightgun_x ); - state_save_register_global(machine, m_n_lightgun_y ); - state_save_register_global(machine, psxgpu.n_tx ); - state_save_register_global(machine, psxgpu.n_ty ); - state_save_register_global(machine, psxgpu.n_abr ); - state_save_register_global(machine, psxgpu.n_tp ); - state_save_register_global(machine, psxgpu.n_ix ); - state_save_register_global(machine, psxgpu.n_iy ); - state_save_register_global(machine, psxgpu.n_ti ); + state_save_register_global_pointer( machine, p_psxgpu->p_vram, p_psxgpu->n_vram_size ); + state_save_register_global( machine, p_psxgpu->n_gpu_buffer_offset ); + state_save_register_global( machine, p_psxgpu->n_vramx ); + state_save_register_global( machine, p_psxgpu->n_vramy ); + state_save_register_global( machine, p_psxgpu->n_twy ); + state_save_register_global( machine, p_psxgpu->n_twx ); + state_save_register_global( machine, p_psxgpu->n_tww ); + state_save_register_global( machine, p_psxgpu->n_drawarea_x1 ); + state_save_register_global( machine, p_psxgpu->n_drawarea_y1 ); + state_save_register_global( machine, p_psxgpu->n_drawarea_x2 ); + state_save_register_global( machine, p_psxgpu->n_drawarea_y2 ); + state_save_register_global( machine, p_psxgpu->n_horiz_disstart ); + state_save_register_global( machine, p_psxgpu->n_horiz_disend ); + state_save_register_global( machine, p_psxgpu->n_vert_disstart ); + state_save_register_global( machine, p_psxgpu->n_vert_disend ); + state_save_register_global( machine, p_psxgpu->b_reverseflag ); + state_save_register_global( machine, p_psxgpu->n_drawoffset_x ); + state_save_register_global( machine, p_psxgpu->n_drawoffset_y ); + state_save_register_global( machine, p_psxgpu->n_displaystartx ); + state_save_register_global( machine, p_psxgpu->n_displaystarty ); + state_save_register_global( machine, p_psxgpu->n_gpustatus ); + state_save_register_global( machine, p_psxgpu->n_gpuinfo ); + state_save_register_global( machine, p_psxgpu->n_lightgun_x ); + state_save_register_global( machine, p_psxgpu->n_lightgun_y ); + state_save_register_global( machine, p_psxgpu->n_tx ); + state_save_register_global( machine, p_psxgpu->n_ty ); + state_save_register_global( machine, p_psxgpu->n_abr ); + state_save_register_global( machine, p_psxgpu->n_tp ); + state_save_register_global( machine, p_psxgpu->n_ix ); + state_save_register_global( machine, p_psxgpu->n_iy ); + state_save_register_global( machine, p_psxgpu->n_ti ); state_save_register_postload( machine, updatevisiblearea, NULL ); + machine->driver_data()->p_psxgpu = p_psxgpu; } VIDEO_START( psx_type1 ) { - m_n_gputype = 1; - psx_gpu_init(machine); + psx_gpu_init(machine, 1); } VIDEO_START( psx_type2 ) { - m_n_gputype = 2; - psx_gpu_init(machine); + psx_gpu_init(machine, 2); } VIDEO_UPDATE( psx ) { + psx_gpu *p_psxgpu = screen->machine->driver_data()->p_psxgpu; UINT32 n_x; UINT32 n_y; int n_top; @@ -803,35 +813,35 @@ VIDEO_UPDATE( psx ) int n_overscanleft; #if defined( MAME_DEBUG ) - if( DebugMeshDisplay( bitmap, cliprect ) ) + if( DebugMeshDisplay( p_psxgpu, bitmap, cliprect ) ) { return 0; } - if( DebugTextureDisplay( screen->machine, bitmap ) ) + if( DebugTextureDisplay( p_psxgpu, bitmap ) ) { return 0; } #endif - if( ( m_n_gpustatus & ( 1 << 0x17 ) ) != 0 ) + if( ( p_psxgpu->n_gpustatus & ( 1 << 0x17 ) ) != 0 ) { /* todo: only draw to necessary area */ bitmap_fill( bitmap, cliprect , 0); } else { - if( m_b_reverseflag ) + if( p_psxgpu->b_reverseflag ) { - n_displaystartx = ( 1023 - m_n_displaystartx ); + n_displaystartx = ( 1023 - p_psxgpu->n_displaystartx ); /* todo: make this flip the screen, in the meantime.. */ - n_displaystartx -= ( m_n_screenwidth - 1 ); + n_displaystartx -= ( p_psxgpu->n_screenwidth - 1 ); } else { - n_displaystartx = m_n_displaystartx; + n_displaystartx = p_psxgpu->n_displaystartx; } - if( ( m_n_gpustatus & ( 1 << 0x14 ) ) != 0 ) + if( ( p_psxgpu->n_gpustatus & ( 1 << 0x14 ) ) != 0 ) { /* pal */ n_overscantop = 0x23; @@ -844,8 +854,8 @@ VIDEO_UPDATE( psx ) n_overscanleft = 0x260; } - n_top = (INT32)m_n_vert_disstart - n_overscantop; - n_lines = (INT32)m_n_vert_disend - (INT32)m_n_vert_disstart; + n_top = (INT32)p_psxgpu->n_vert_disstart - n_overscantop; + n_lines = (INT32)p_psxgpu->n_vert_disend - (INT32)p_psxgpu->n_vert_disstart; if( n_top < 0 ) { n_y = -n_top; @@ -856,22 +866,22 @@ VIDEO_UPDATE( psx ) /* todo: draw top border */ n_y = 0; } - if( ( m_n_gpustatus & ( 1 << 0x16 ) ) != 0 ) + if( ( p_psxgpu->n_gpustatus & ( 1 << 0x16 ) ) != 0 ) { /* interlaced */ n_lines *= 2; } - if( n_lines > m_n_screenheight - ( n_y + n_top ) ) + if( n_lines > p_psxgpu->n_screenheight - ( n_y + n_top ) ) { - n_lines = m_n_screenheight - ( n_y + n_top ); + n_lines = p_psxgpu->n_screenheight - ( n_y + n_top ); } else { /* todo: draw bottom border */ } - n_left = ( ( (INT32)m_n_horiz_disstart - n_overscanleft ) * (INT32)m_n_screenwidth ) / 2560; - n_columns = ( ( ( (INT32)m_n_horiz_disend - m_n_horiz_disstart ) * (INT32)m_n_screenwidth ) / 2560 ); + n_left = ( ( (INT32)p_psxgpu->n_horiz_disstart - n_overscanleft ) * (INT32)p_psxgpu->n_screenwidth ) / 2560; + n_columns = ( ( ( (INT32)p_psxgpu->n_horiz_disend - p_psxgpu->n_horiz_disstart ) * (INT32)p_psxgpu->n_screenwidth ) / 2560 ); if( n_left < 0 ) { n_x = -n_left; @@ -882,22 +892,22 @@ VIDEO_UPDATE( psx ) /* todo: draw left border */ n_x = 0; } - if( n_columns > m_n_screenwidth - ( n_x + n_left ) ) + if( n_columns > p_psxgpu->n_screenwidth - ( n_x + n_left ) ) { - n_columns = m_n_screenwidth - ( n_x + n_left ); + n_columns = p_psxgpu->n_screenwidth - ( n_x + n_left ); } else { /* todo: draw right border */ } - if( ( m_n_gpustatus & ( 1 << 0x15 ) ) != 0 ) + if( ( p_psxgpu->n_gpustatus & ( 1 << 0x15 ) ) != 0 ) { /* 24bit */ n_line = n_lines; while( n_line > 0 ) { - UINT16 *p_n_src = m_p_p_vram[ n_y + m_n_displaystarty ] + n_x + n_displaystartx; + UINT16 *p_n_src = p_psxgpu->p_p_vram[ n_y + p_psxgpu->n_displaystarty ] + n_x + n_displaystartx; UINT16 *p_n_dest = BITMAP_ADDR16(bitmap, n_y + n_top, n_x + n_left); n_column = n_columns; @@ -907,11 +917,11 @@ VIDEO_UPDATE( psx ) UINT32 n_r1b0 = *( p_n_src++ ); UINT32 n_b1g1 = *( p_n_src++ ); - *( p_n_dest++ ) = m_p_n_g0r0[ n_g0r0 ] | m_p_n_b0[ n_r1b0 ]; + *( p_n_dest++ ) = p_psxgpu->p_n_g0r0[ n_g0r0 ] | p_psxgpu->p_n_b0[ n_r1b0 ]; n_column--; if( n_column > 0 ) { - *( p_n_dest++ ) = m_p_n_r1[ n_r1b0 ] | m_p_n_b1g1[ n_b1g1 ]; + *( p_n_dest++ ) = p_psxgpu->p_n_r1[ n_r1b0 ] | p_psxgpu->p_n_b1g1[ n_b1g1 ]; n_column--; } } @@ -925,7 +935,7 @@ VIDEO_UPDATE( psx ) n_line = n_lines; while( n_line > 0 ) { - draw_scanline16( bitmap, n_x + n_left, n_y + n_top, n_columns, m_p_p_vram[ n_y + m_n_displaystarty ] + n_x + n_displaystartx, NULL ); + draw_scanline16( bitmap, n_x + n_left, n_y + n_top, n_columns, p_psxgpu->p_p_vram[ n_y + p_psxgpu->n_displaystarty ] + n_x + n_displaystartx, NULL ); n_y++; n_line--; } @@ -948,11 +958,11 @@ f e| d c| b| a 9| 8 7| 6 5| 4| 3 2 1 0 |iy|ix|ty| | tp| abr|ty| tx */ -INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UINT32 tpage ) +INLINE void decode_tpage( psx_gpu *p_psxgpu, UINT32 tpage ) { - if( m_n_gputype == 2 ) + if( p_psxgpu->n_gputype == 2 ) { - m_n_gpustatus = ( m_n_gpustatus & 0xfffff800 ) | ( tpage & 0x7ff ); + p_psxgpu->n_gpustatus = ( p_psxgpu->n_gpustatus & 0xfffff800 ) | ( tpage & 0x7ff ); p_psxgpu->n_tx = ( tpage & 0x0f ) << 6; p_psxgpu->n_ty = ( ( tpage & 0x10 ) << 4 ) | ( ( tpage & 0x800 ) >> 2 ); @@ -963,16 +973,16 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN p_psxgpu->n_ti = 0; if( ( tpage & ~0x39ff ) != 0 ) { - verboselog( machine, 1, "not handled: draw mode %08x\n", tpage & ~0x39ff ); + verboselog( p_psxgpu, 1, "not handled: draw mode %08x\n", tpage & ~0x39ff ); } if( p_psxgpu->n_tp == 3 ) { - verboselog( machine, 0, "not handled: tp == 3\n" ); + verboselog( p_psxgpu, 0, "not handled: tp == 3\n" ); } } else { - m_n_gpustatus = ( m_n_gpustatus & 0xffffe000 ) | ( tpage & 0x1fff ); + p_psxgpu->n_gpustatus = ( p_psxgpu->n_gpustatus & 0xffffe000 ) | ( tpage & 0x1fff ); p_psxgpu->n_tx = ( tpage & 0x0f ) << 6; p_psxgpu->n_ty = ( ( tpage & 0x60 ) << 3 ); @@ -983,21 +993,21 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN p_psxgpu->n_iy = 0; if( ( tpage & ~0x27ef ) != 0 ) { - verboselog( machine, 1, "not handled: draw mode %08x\n", tpage & ~0x27ef ); + verboselog( p_psxgpu, 1, "not handled: draw mode %08x\n", tpage & ~0x27ef ); } if( p_psxgpu->n_tp == 3 ) { - verboselog( machine, 0, "not handled: tp == 3\n" ); + verboselog( p_psxgpu, 0, "not handled: tp == 3\n" ); } else if( p_psxgpu->n_tp == 2 && p_psxgpu->n_ti != 0 ) { - verboselog( machine, 0, "not handled: interleaved 15 bit texture\n" ); + verboselog( p_psxgpu, 0, "not handled: interleaved 15 bit texture\n" ); } } } #define SPRITESETUP \ - if( psxgpu.n_iy != 0 ) \ + if( p_psxgpu->n_iy != 0 ) \ { \ n_dv = -1; \ } \ @@ -1005,7 +1015,7 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN { \ n_dv = 1; \ } \ - if( psxgpu.n_ix != 0 ) \ + if( p_psxgpu->n_ix != 0 ) \ { \ n_du = -1; \ } \ @@ -1015,58 +1025,58 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN } #define TRANSPARENCYSETUP \ - p_n_f = m_p_n_f1; \ - p_n_redb = m_p_n_redb1; \ - p_n_greenb = m_p_n_greenb1; \ - p_n_blueb = m_p_n_blueb1; \ - p_n_redtrans = m_p_n_redaddtrans; \ - p_n_greentrans = m_p_n_greenaddtrans; \ - p_n_bluetrans = m_p_n_blueaddtrans; \ + p_n_f = p_psxgpu->p_n_f1; \ + p_n_redb = p_psxgpu->p_n_redb1; \ + p_n_greenb = p_psxgpu->p_n_greenb1; \ + p_n_blueb = p_psxgpu->p_n_blueb1; \ + p_n_redtrans = p_psxgpu->p_n_redaddtrans; \ + p_n_greentrans = p_psxgpu->p_n_greenaddtrans; \ + p_n_bluetrans = p_psxgpu->p_n_blueaddtrans; \ \ switch( n_cmd & 0x02 ) \ { \ case 0x02: \ - switch( psxgpu.n_abr ) \ + switch( p_psxgpu->n_abr ) \ { \ case 0x00: \ - p_n_f = m_p_n_f05; \ - p_n_redb = m_p_n_redb05; \ - p_n_greenb = m_p_n_greenb05; \ - p_n_blueb = m_p_n_blueb05; \ - p_n_redtrans = m_p_n_redaddtrans; \ - p_n_greentrans = m_p_n_greenaddtrans; \ - p_n_bluetrans = m_p_n_blueaddtrans; \ - verboselog( machine, 2, "Transparency Mode: 0.5*B + 0.5*F\n" ); \ + p_n_f = p_psxgpu->p_n_f05; \ + p_n_redb = p_psxgpu->p_n_redb05; \ + p_n_greenb = p_psxgpu->p_n_greenb05; \ + p_n_blueb = p_psxgpu->p_n_blueb05; \ + p_n_redtrans = p_psxgpu->p_n_redaddtrans; \ + p_n_greentrans = p_psxgpu->p_n_greenaddtrans; \ + p_n_bluetrans = p_psxgpu->p_n_blueaddtrans; \ + verboselog( p_psxgpu, 2, "Transparency Mode: 0.5*B + 0.5*F\n" ); \ break; \ case 0x01: \ - p_n_f = m_p_n_f1; \ - p_n_redb = m_p_n_redb1; \ - p_n_greenb = m_p_n_greenb1; \ - p_n_blueb = m_p_n_blueb1; \ - p_n_redtrans = m_p_n_redaddtrans; \ - p_n_greentrans = m_p_n_greenaddtrans; \ - p_n_bluetrans = m_p_n_blueaddtrans; \ - verboselog( machine, 2, "Transparency Mode: 1.0*B + 1.0*F\n" ); \ + p_n_f = p_psxgpu->p_n_f1; \ + p_n_redb = p_psxgpu->p_n_redb1; \ + p_n_greenb = p_psxgpu->p_n_greenb1; \ + p_n_blueb = p_psxgpu->p_n_blueb1; \ + p_n_redtrans = p_psxgpu->p_n_redaddtrans; \ + p_n_greentrans = p_psxgpu->p_n_greenaddtrans; \ + p_n_bluetrans = p_psxgpu->p_n_blueaddtrans; \ + verboselog( p_psxgpu, 2, "Transparency Mode: 1.0*B + 1.0*F\n" ); \ break; \ case 0x02: \ - p_n_f = m_p_n_f1; \ - p_n_redb = m_p_n_redb1; \ - p_n_greenb = m_p_n_greenb1; \ - p_n_blueb = m_p_n_blueb1; \ - p_n_redtrans = m_p_n_redsubtrans; \ - p_n_greentrans = m_p_n_greensubtrans; \ - p_n_bluetrans = m_p_n_bluesubtrans; \ - verboselog( machine, 2, "Transparency Mode: 1.0*B - 1.0*F\n" ); \ + p_n_f = p_psxgpu->p_n_f1; \ + p_n_redb = p_psxgpu->p_n_redb1; \ + p_n_greenb = p_psxgpu->p_n_greenb1; \ + p_n_blueb = p_psxgpu->p_n_blueb1; \ + p_n_redtrans = p_psxgpu->p_n_redsubtrans; \ + p_n_greentrans = p_psxgpu->p_n_greensubtrans; \ + p_n_bluetrans = p_psxgpu->p_n_bluesubtrans; \ + verboselog( p_psxgpu, 2, "Transparency Mode: 1.0*B - 1.0*F\n" ); \ break; \ case 0x03: \ - p_n_f = m_p_n_f025; \ - p_n_redb = m_p_n_redb1; \ - p_n_greenb = m_p_n_greenb1; \ - p_n_blueb = m_p_n_blueb1; \ - p_n_redtrans = m_p_n_redaddtrans; \ - p_n_greentrans = m_p_n_greenaddtrans; \ - p_n_bluetrans = m_p_n_blueaddtrans; \ - verboselog( machine, 2, "Transparency Mode: 1.0*B + 0.25*F\n" ); \ + p_n_f = p_psxgpu->p_n_f025; \ + p_n_redb = p_psxgpu->p_n_redb1; \ + p_n_greenb = p_psxgpu->p_n_greenb1; \ + p_n_blueb = p_psxgpu->p_n_blueb1; \ + p_n_redtrans = p_psxgpu->p_n_redaddtrans; \ + p_n_greentrans = p_psxgpu->p_n_greenaddtrans; \ + p_n_bluetrans = p_psxgpu->p_n_blueaddtrans; \ + verboselog( p_psxgpu, 2, "Transparency Mode: 1.0*B + 0.25*F\n" ); \ break; \ } \ break; \ @@ -1076,22 +1086,22 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN TRANSPARENCYSETUP #define TEXTURESETUP \ - n_tx = psxgpu.n_tx; \ - n_ty = psxgpu.n_ty; \ - p_clut = m_p_p_vram[ n_cluty ] + n_clutx; \ - switch( psxgpu.n_tp ) \ + n_tx = p_psxgpu->n_tx; \ + n_ty = p_psxgpu->n_ty; \ + p_clut = p_psxgpu->p_p_vram[ n_cluty ] + n_clutx; \ + switch( p_psxgpu->n_tp ) \ { \ case 0: \ - n_tx += m_n_twx >> 2; \ - n_ty += m_n_twy; \ + n_tx += p_psxgpu->n_twx >> 2; \ + n_ty += p_psxgpu->n_twy; \ break; \ case 1: \ - n_tx += m_n_twx >> 1; \ - n_ty += m_n_twy; \ + n_tx += p_psxgpu->n_twx >> 1; \ + n_ty += p_psxgpu->n_twy; \ break; \ case 2: \ - n_tx += m_n_twx >> 0; \ - n_ty += m_n_twy; \ + n_tx += p_psxgpu->n_twx >> 0; \ + n_ty += p_psxgpu->n_twy; \ break; \ } \ TRANSPARENCYSETUP @@ -1104,11 +1114,11 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN n_b.d += n_db; #define SOLIDFILL( PIXELUPDATE ) \ - if( n_distance > ( (INT32)m_n_drawarea_x2 - n_x ) + 1 ) \ + if( n_distance > ( (INT32)p_psxgpu->n_drawarea_x2 - n_x ) + 1 ) \ { \ - n_distance = ( m_n_drawarea_x2 - n_x ) + 1; \ + n_distance = ( p_psxgpu->n_drawarea_x2 - n_x ) + 1; \ } \ - p_vram = m_p_p_vram[ n_y ] + n_x; \ + p_vram = p_psxgpu->p_p_vram[ n_y ] + n_x; \ \ switch( n_cmd & 0x02 ) \ { \ @@ -1117,9 +1127,9 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN while( n_distance > 0 ) \ { \ WRITE_PIXEL( \ - m_p_n_redshade[ MID_LEVEL | n_r.w.h ] | \ - m_p_n_greenshade[ MID_LEVEL | n_g.w.h ] | \ - m_p_n_blueshade[ MID_LEVEL | n_b.w.h ] ); \ + p_psxgpu->p_n_redshade[ MID_LEVEL | n_r.w.h ] | \ + p_psxgpu->p_n_greenshade[ MID_LEVEL | n_g.w.h ] | \ + p_psxgpu->p_n_blueshade[ MID_LEVEL | n_b.w.h ] ); \ p_vram++; \ PIXELUPDATE \ n_distance--; \ @@ -1163,49 +1173,49 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN #define TEXTURE4BIT( TXV, TXU ) \ TEXTURE_LOOP \ - n_bgr = p_clut[ ( *( m_p_p_vram[ n_ty + TXV ] + n_tx + ( TXU >> 2 ) ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ]; + n_bgr = p_clut[ ( *( p_psxgpu->p_p_vram[ n_ty + TXV ] + n_tx + ( TXU >> 2 ) ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ]; #define TEXTURE8BIT( TXV, TXU ) \ TEXTURE_LOOP \ - n_bgr = p_clut[ ( *( m_p_p_vram[ n_ty + TXV ] + n_tx + ( TXU >> 1 ) ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff ]; + n_bgr = p_clut[ ( *( p_psxgpu->p_p_vram[ n_ty + TXV ] + n_tx + ( TXU >> 1 ) ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff ]; #define TEXTURE15BIT( TXV, TXU ) \ TEXTURE_LOOP \ - n_bgr = *( m_p_p_vram[ n_ty + TXV ] + n_tx + TXU ); + n_bgr = *( p_psxgpu->p_p_vram[ n_ty + TXV ] + n_tx + TXU ); -#define TEXTUREWINDOW4BIT( TXV, TXU ) TEXTURE4BIT( ( TXV & m_n_twh ), ( TXU & m_n_tww ) ) -#define TEXTUREWINDOW8BIT( TXV, TXU ) TEXTURE8BIT( ( TXV & m_n_twh ), ( TXU & m_n_tww ) ) -#define TEXTUREWINDOW15BIT( TXV, TXU ) TEXTURE15BIT( ( TXV & m_n_twh ), ( TXU & m_n_tww ) ) +#define TEXTUREWINDOW4BIT( TXV, TXU ) TEXTURE4BIT( ( TXV & p_psxgpu->n_twh ), ( TXU & p_psxgpu->n_tww ) ) +#define TEXTUREWINDOW8BIT( TXV, TXU ) TEXTURE8BIT( ( TXV & p_psxgpu->n_twh ), ( TXU & p_psxgpu->n_tww ) ) +#define TEXTUREWINDOW15BIT( TXV, TXU ) TEXTURE15BIT( ( TXV & p_psxgpu->n_twh ), ( TXU & p_psxgpu->n_tww ) ) #define TEXTUREINTERLEAVED4BIT( TXV, TXU ) \ TEXTURE_LOOP \ int n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c ); \ int n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf ); \ - n_bgr = p_clut[ ( *( m_p_p_vram[ n_ty + n_yi ] + n_tx + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ]; + n_bgr = p_clut[ ( *( p_psxgpu->p_p_vram[ n_ty + n_yi ] + n_tx + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ]; #define TEXTUREINTERLEAVED8BIT( TXV, TXU ) \ TEXTURE_LOOP \ int n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 ); \ int n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 ); \ - n_bgr = p_clut[ ( *( m_p_p_vram[ n_ty + n_yi ] + n_tx + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff ]; + n_bgr = p_clut[ ( *( p_psxgpu->p_p_vram[ n_ty + n_yi ] + n_tx + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff ]; #define TEXTUREINTERLEAVED15BIT( TXV, TXU ) \ TEXTURE_LOOP \ int n_xi = TXU; \ int n_yi = TXV; \ - n_bgr = *( m_p_p_vram[ n_ty + n_yi ] + n_tx + n_xi ); + n_bgr = *( p_psxgpu->p_p_vram[ n_ty + n_yi ] + n_tx + n_xi ); -#define TEXTUREWINDOWINTERLEAVED4BIT( TXV, TXU ) TEXTUREINTERLEAVED4BIT( ( TXV & m_n_twh ), ( TXU & m_n_tww ) ) -#define TEXTUREWINDOWINTERLEAVED8BIT( TXV, TXU ) TEXTUREINTERLEAVED8BIT( ( TXV & m_n_twh ), ( TXU & m_n_tww ) ) -#define TEXTUREWINDOWINTERLEAVED15BIT( TXV, TXU ) TEXTUREINTERLEAVED15BIT( ( TXV & m_n_twh ), ( TXU & m_n_tww ) ) +#define TEXTUREWINDOWINTERLEAVED4BIT( TXV, TXU ) TEXTUREINTERLEAVED4BIT( ( TXV & p_psxgpu->n_twh ), ( TXU & p_psxgpu->n_tww ) ) +#define TEXTUREWINDOWINTERLEAVED8BIT( TXV, TXU ) TEXTUREINTERLEAVED8BIT( ( TXV & p_psxgpu->n_twh ), ( TXU & p_psxgpu->n_tww ) ) +#define TEXTUREWINDOWINTERLEAVED15BIT( TXV, TXU ) TEXTUREINTERLEAVED15BIT( ( TXV & p_psxgpu->n_twh ), ( TXU & p_psxgpu->n_tww ) ) #define SHADEDPIXEL( PIXELUPDATE ) \ if( n_bgr != 0 ) \ { \ WRITE_PIXEL( \ - m_p_n_redshade[ m_p_n_redlevel[ n_bgr ] | n_r.w.h ] | \ - m_p_n_greenshade[ m_p_n_greenlevel[ n_bgr ] | n_g.w.h ] | \ - m_p_n_blueshade[ m_p_n_bluelevel[ n_bgr ] | n_b.w.h ] ); \ + p_psxgpu->p_n_redshade[ p_psxgpu->p_n_redlevel[ n_bgr ] | n_r.w.h ] | \ + p_psxgpu->p_n_greenshade[ p_psxgpu->p_n_greenlevel[ n_bgr ] | n_g.w.h ] | \ + p_psxgpu->p_n_blueshade[ p_psxgpu->p_n_bluelevel[ n_bgr ] | n_b.w.h ] ); \ } \ p_vram++; \ PIXELUPDATE \ @@ -1218,16 +1228,16 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN if( ( n_bgr & 0x8000 ) != 0 ) \ { \ WRITE_PIXEL( \ - p_n_redtrans[ p_n_f[ m_p_n_redlevel[ n_bgr ] | n_r.w.h ] | p_n_redb[ *( p_vram ) ] ] | \ - p_n_greentrans[ p_n_f[ m_p_n_greenlevel[ n_bgr ] | n_g.w.h ] | p_n_greenb[ *( p_vram ) ] ] | \ - p_n_bluetrans[ p_n_f[ m_p_n_bluelevel[ n_bgr ] | n_b.w.h ] | p_n_blueb[ *( p_vram ) ] ] ); \ + p_n_redtrans[ p_n_f[ p_psxgpu->p_n_redlevel[ n_bgr ] | n_r.w.h ] | p_n_redb[ *( p_vram ) ] ] | \ + p_n_greentrans[ p_n_f[ p_psxgpu->p_n_greenlevel[ n_bgr ] | n_g.w.h ] | p_n_greenb[ *( p_vram ) ] ] | \ + p_n_bluetrans[ p_n_f[ p_psxgpu->p_n_bluelevel[ n_bgr ] | n_b.w.h ] | p_n_blueb[ *( p_vram ) ] ] ); \ } \ else \ { \ WRITE_PIXEL( \ - m_p_n_redshade[ m_p_n_redlevel[ n_bgr ] | n_r.w.h ] | \ - m_p_n_greenshade[ m_p_n_greenlevel[ n_bgr ] | n_g.w.h ] | \ - m_p_n_blueshade[ m_p_n_bluelevel[ n_bgr ] | n_b.w.h ] ); \ + p_psxgpu->p_n_redshade[ p_psxgpu->p_n_redlevel[ n_bgr ] | n_r.w.h ] | \ + p_psxgpu->p_n_greenshade[ p_psxgpu->p_n_greenlevel[ n_bgr ] | n_g.w.h ] | \ + p_psxgpu->p_n_blueshade[ p_psxgpu->p_n_bluelevel[ n_bgr ] | n_b.w.h ] ); \ } \ } \ p_vram++; \ @@ -1236,26 +1246,26 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN TEXTURE_ENDLOOP #define TEXTUREFILL( PIXELUPDATE, TXU, TXV ) \ - if( n_distance > ( (INT32)m_n_drawarea_x2 - n_x ) + 1 ) \ + if( n_distance > ( (INT32)p_psxgpu->n_drawarea_x2 - n_x ) + 1 ) \ { \ - n_distance = ( m_n_drawarea_x2 - n_x ) + 1; \ + n_distance = ( p_psxgpu->n_drawarea_x2 - n_x ) + 1; \ } \ - p_vram = m_p_p_vram[ n_y ] + n_x; \ + p_vram = p_psxgpu->p_p_vram[ n_y ] + n_x; \ \ - if( psxgpu.n_ti != 0 ) \ + if( p_psxgpu->n_ti != 0 ) \ { \ /* interleaved texture */ \ - if( m_n_twh != 255 || \ - m_n_tww != 255 || \ - m_n_twx != 0 || \ - m_n_twy != 0 ) \ + if( p_psxgpu->n_twh != 255 || \ + p_psxgpu->n_tww != 255 || \ + p_psxgpu->n_twx != 0 || \ + p_psxgpu->n_twy != 0 ) \ { \ /* texture window */ \ switch( n_cmd & 0x02 ) \ { \ case 0x00: \ /* shading */ \ - switch( psxgpu.n_tp ) \ + switch( p_psxgpu->n_tp ) \ { \ case 0: \ /* 4 bit clut */ \ @@ -1276,7 +1286,7 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN break; \ case 0x02: \ /* semi transparency */ \ - switch( psxgpu.n_tp ) \ + switch( p_psxgpu->n_tp ) \ { \ case 0: \ /* 4 bit clut */ \ @@ -1304,7 +1314,7 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN { \ case 0x00: \ /* shading */ \ - switch( psxgpu.n_tp ) \ + switch( p_psxgpu->n_tp ) \ { \ case 0: \ /* 4 bit clut */ \ @@ -1325,7 +1335,7 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN break; \ case 0x02: \ /* semi transparency */ \ - switch( psxgpu.n_tp ) \ + switch( p_psxgpu->n_tp ) \ { \ case 0: \ /* 4 bit clut */ \ @@ -1350,17 +1360,17 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN else \ { \ /* standard texture */ \ - if( m_n_twh != 255 || \ - m_n_tww != 255 || \ - m_n_twx != 0 || \ - m_n_twy != 0 ) \ + if( p_psxgpu->n_twh != 255 || \ + p_psxgpu->n_tww != 255 || \ + p_psxgpu->n_twx != 0 || \ + p_psxgpu->n_twy != 0 ) \ { \ /* texture window */ \ switch( n_cmd & 0x02 ) \ { \ case 0x00: \ /* shading */ \ - switch( psxgpu.n_tp ) \ + switch( p_psxgpu->n_tp ) \ { \ case 0: \ /* 4 bit clut */ \ @@ -1381,7 +1391,7 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN break; \ case 0x02: \ /* semi transparency */ \ - switch( psxgpu.n_tp ) \ + switch( p_psxgpu->n_tp ) \ { \ case 0: \ /* 4 bit clut */ \ @@ -1409,7 +1419,7 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN { \ case 0x00: \ /* shading */ \ - switch( psxgpu.n_tp ) \ + switch( p_psxgpu->n_tp ) \ { \ case 0: \ TEXTURE4BIT( TXV, TXU ) \ @@ -1429,7 +1439,7 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN break; \ case 0x02: \ /* semi transparency */ \ - switch( psxgpu.n_tp ) \ + switch( p_psxgpu->n_tp ) \ { \ case 0: \ /* 4 bit clut */ \ @@ -1452,7 +1462,7 @@ INLINE void decode_tpage( running_machine *machine, struct PSXGPU *p_psxgpu, UIN } \ } -static void FlatPolygon( running_machine *machine, int n_points ) +static void FlatPolygon( psx_gpu *p_psxgpu, int n_points ) { INT16 n_y; INT16 n_x; @@ -1486,27 +1496,27 @@ static void FlatPolygon( running_machine *machine, int n_points ) UINT16 *p_vram; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 1 ) + if( p_psxgpu->m_debug.n_skip == 1 ) { return; } for( n_point = 0; n_point < n_points; n_point++ ) { - DebugMesh( COORD_X( m_packet.FlatPolygon.vertex[ n_point ].n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.FlatPolygon.vertex[ n_point ].n_coord ) + m_n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatPolygon.vertex[ n_point ].n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ n_point ].n_coord ) + p_psxgpu->n_drawoffset_y ); } - DebugMeshEnd(); + DebugMeshEnd(p_psxgpu); #endif - n_cmd = BGR_C( m_packet.FlatPolygon.n_bgr ); + n_cmd = BGR_C( p_psxgpu->m_packet.FlatPolygon.n_bgr ); n_cx1.d = 0; n_cx2.d = 0; SOLIDSETUP - n_r.w.h = BGR_R( m_packet.FlatPolygon.n_bgr ); n_r.w.l = 0; - n_g.w.h = BGR_G( m_packet.FlatPolygon.n_bgr ); n_g.w.l = 0; - n_b.w.h = BGR_B( m_packet.FlatPolygon.n_bgr ); n_b.w.l = 0; + n_r.w.h = BGR_R( p_psxgpu->m_packet.FlatPolygon.n_bgr ); n_r.w.l = 0; + n_g.w.h = BGR_G( p_psxgpu->m_packet.FlatPolygon.n_bgr ); n_g.w.l = 0; + n_b.w.h = BGR_B( p_psxgpu->m_packet.FlatPolygon.n_bgr ); n_b.w.l = 0; if( n_points == 4 ) { @@ -1521,15 +1531,15 @@ static void FlatPolygon( running_machine *machine, int n_points ) for( n_point = 0; n_point < n_points; n_point++ ) { - ADJUST_COORD( m_packet.FlatPolygon.vertex[ n_point ].n_coord ); + ADJUST_COORD( p_psxgpu->m_packet.FlatPolygon.vertex[ n_point ].n_coord ); } n_leftpoint = 0; for( n_point = 1; n_point < n_points; n_point++ ) { - if( COORD_Y( m_packet.FlatPolygon.vertex[ n_point ].n_coord ) < COORD_Y( m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) || - ( COORD_Y( m_packet.FlatPolygon.vertex[ n_point ].n_coord ) == COORD_Y( m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) && - COORD_X( m_packet.FlatPolygon.vertex[ n_point ].n_coord ) < COORD_X( m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) ) ) + if( COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ n_point ].n_coord ) < COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) || + ( COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ n_point ].n_coord ) == COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) && + COORD_X( p_psxgpu->m_packet.FlatPolygon.vertex[ n_point ].n_coord ) < COORD_X( p_psxgpu->m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) ) ) { n_leftpoint = n_point; } @@ -1539,13 +1549,13 @@ static void FlatPolygon( running_machine *machine, int n_points ) n_dx1 = 0; n_dx2 = 0; - n_y = COORD_Y( m_packet.FlatPolygon.vertex[ n_rightpoint ].n_coord ); + n_y = COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ n_rightpoint ].n_coord ); for( ;; ) { - if( n_y == COORD_Y( m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) ) + if( n_y == COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) ) { - while( n_y == COORD_Y( m_packet.FlatPolygon.vertex[ p_n_leftpointlist[ n_leftpoint ] ].n_coord ) ) + while( n_y == COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ p_n_leftpointlist[ n_leftpoint ] ].n_coord ) ) { n_leftpoint = p_n_leftpointlist[ n_leftpoint ]; if( n_leftpoint == n_rightpoint ) @@ -1553,18 +1563,18 @@ static void FlatPolygon( running_machine *machine, int n_points ) break; } } - n_cx1.w.h = COORD_X( m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ); n_cx1.w.l = 0; + n_cx1.w.h = COORD_X( p_psxgpu->m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ); n_cx1.w.l = 0; n_leftpoint = p_n_leftpointlist[ n_leftpoint ]; - n_distance = COORD_Y( m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) - n_y; + n_distance = COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) - n_y; if( n_distance < 1 ) { break; } - n_dx1 = (INT32)( ( COORD_X( m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) << 16 ) - n_cx1.d ) / n_distance; + n_dx1 = (INT32)( ( COORD_X( p_psxgpu->m_packet.FlatPolygon.vertex[ n_leftpoint ].n_coord ) << 16 ) - n_cx1.d ) / n_distance; } - if( n_y == COORD_Y( m_packet.FlatPolygon.vertex[ n_rightpoint ].n_coord ) ) + if( n_y == COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ n_rightpoint ].n_coord ) ) { - while( n_y == COORD_Y( m_packet.FlatPolygon.vertex[ p_n_rightpointlist[ n_rightpoint ] ].n_coord ) ) + while( n_y == COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ p_n_rightpointlist[ n_rightpoint ] ].n_coord ) ) { n_rightpoint = p_n_rightpointlist[ n_rightpoint ]; if( n_rightpoint == n_leftpoint ) @@ -1572,16 +1582,16 @@ static void FlatPolygon( running_machine *machine, int n_points ) break; } } - n_cx2.w.h = COORD_X( m_packet.FlatPolygon.vertex[ n_rightpoint ].n_coord ); n_cx2.w.l = 0; + n_cx2.w.h = COORD_X( p_psxgpu->m_packet.FlatPolygon.vertex[ n_rightpoint ].n_coord ); n_cx2.w.l = 0; n_rightpoint = p_n_rightpointlist[ n_rightpoint ]; - n_distance = COORD_Y( m_packet.FlatPolygon.vertex[ n_rightpoint ].n_coord ) - n_y; + n_distance = COORD_Y( p_psxgpu->m_packet.FlatPolygon.vertex[ n_rightpoint ].n_coord ) - n_y; if( n_distance < 1 ) { break; } - n_dx2 = (INT32)( ( COORD_X( m_packet.FlatPolygon.vertex[ n_rightpoint ].n_coord ) << 16 ) - n_cx2.d ) / n_distance; + n_dx2 = (INT32)( ( COORD_X( p_psxgpu->m_packet.FlatPolygon.vertex[ n_rightpoint ].n_coord ) << 16 ) - n_cx2.d ) / n_distance; } - if( (INT16)n_cx1.w.h != (INT16)n_cx2.w.h && n_y >= (INT32)m_n_drawarea_y1 && n_y <= (INT32)m_n_drawarea_y2 ) + if( (INT16)n_cx1.w.h != (INT16)n_cx2.w.h && n_y >= (INT32)p_psxgpu->n_drawarea_y1 && n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { if( (INT16)n_cx1.w.h < (INT16)n_cx2.w.h ) { @@ -1594,10 +1604,10 @@ static void FlatPolygon( running_machine *machine, int n_points ) n_distance = (INT16)n_cx1.w.h - n_x; } - if( ( (INT32)m_n_drawarea_x1 - n_x ) > 0 ) + if( ( (INT32)p_psxgpu->n_drawarea_x1 - n_x ) > 0 ) { - n_distance -= ( m_n_drawarea_x1 - n_x ); - n_x = m_n_drawarea_x1; + n_distance -= ( p_psxgpu->n_drawarea_x1 - n_x ); + n_x = p_psxgpu->n_drawarea_x1; } SOLIDFILL( FLATPOLYGONUPDATE ) } @@ -1607,7 +1617,7 @@ static void FlatPolygon( running_machine *machine, int n_points ) } } -static void FlatTexturedPolygon( running_machine *machine, int n_points ) +static void FlatTexturedPolygon( psx_gpu *p_psxgpu, int n_points ) { INT16 n_y; INT16 n_x; @@ -1659,21 +1669,21 @@ static void FlatTexturedPolygon( running_machine *machine, int n_points ) UINT32 n_bgr; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 2 ) + if( p_psxgpu->m_debug.n_skip == 2 ) { return; } for( n_point = 0; n_point < n_points; n_point++ ) { - DebugMesh( COORD_X( m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) + m_n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) + p_psxgpu->n_drawoffset_y ); } - DebugMeshEnd(); + DebugMeshEnd(p_psxgpu); #endif - n_cmd = BGR_C( m_packet.FlatTexturedPolygon.n_bgr ); + n_cmd = BGR_C( p_psxgpu->m_packet.FlatTexturedPolygon.n_bgr ); - n_clutx = ( m_packet.FlatTexturedPolygon.vertex[ 0 ].n_texture.w.h & 0x3f ) << 4; - n_cluty = ( m_packet.FlatTexturedPolygon.vertex[ 0 ].n_texture.w.h >> 6 ) & 0x3ff; + n_clutx = ( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ 0 ].n_texture.w.h & 0x3f ) << 4; + n_cluty = ( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ 0 ].n_texture.w.h >> 6 ) & 0x3ff; n_r.d = 0; n_g.d = 0; @@ -1685,15 +1695,15 @@ static void FlatTexturedPolygon( running_machine *machine, int n_points ) n_cu2.d = 0; n_cv2.d = 0; - decode_tpage( machine, &psxgpu, m_packet.FlatTexturedPolygon.vertex[ 1 ].n_texture.w.h ); + decode_tpage( p_psxgpu, p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ 1 ].n_texture.w.h ); TEXTURESETUP switch( n_cmd & 0x01 ) { case 0: - n_r.w.h = BGR_R( m_packet.FlatTexturedPolygon.n_bgr ); n_r.w.l = 0; - n_g.w.h = BGR_G( m_packet.FlatTexturedPolygon.n_bgr ); n_g.w.l = 0; - n_b.w.h = BGR_B( m_packet.FlatTexturedPolygon.n_bgr ); n_b.w.l = 0; + n_r.w.h = BGR_R( p_psxgpu->m_packet.FlatTexturedPolygon.n_bgr ); n_r.w.l = 0; + n_g.w.h = BGR_G( p_psxgpu->m_packet.FlatTexturedPolygon.n_bgr ); n_g.w.l = 0; + n_b.w.h = BGR_B( p_psxgpu->m_packet.FlatTexturedPolygon.n_bgr ); n_b.w.l = 0; break; case 1: n_r.w.h = 0x80; n_r.w.l = 0; @@ -1715,15 +1725,15 @@ static void FlatTexturedPolygon( running_machine *machine, int n_points ) for( n_point = 0; n_point < n_points; n_point++ ) { - ADJUST_COORD( m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ); + ADJUST_COORD( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ); } n_leftpoint = 0; for( n_point = 1; n_point < n_points; n_point++ ) { - if( COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) || - ( COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) == COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) && - COORD_X( m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_X( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) ) ) + if( COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) || + ( COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) == COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) && + COORD_X( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_X( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) ) ) { n_leftpoint = n_point; } @@ -1737,13 +1747,13 @@ static void FlatTexturedPolygon( running_machine *machine, int n_points ) n_dv1 = 0; n_dv2 = 0; - n_y = COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_coord ); + n_y = COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_coord ); for( ;; ) { - if( n_y == COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) ) + if( n_y == COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) ) { - while( n_y == COORD_Y( m_packet.FlatTexturedPolygon.vertex[ p_n_leftpointlist[ n_leftpoint ] ].n_coord ) ) + while( n_y == COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ p_n_leftpointlist[ n_leftpoint ] ].n_coord ) ) { n_leftpoint = p_n_leftpointlist[ n_leftpoint ]; if( n_leftpoint == n_rightpoint ) @@ -1751,22 +1761,22 @@ static void FlatTexturedPolygon( running_machine *machine, int n_points ) break; } } - n_cx1.w.h = COORD_X( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ); n_cx1.w.l = 0; - n_cu1.w.h = TEXTURE_U( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_texture ); n_cu1.w.l = 0; - n_cv1.w.h = TEXTURE_V( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_texture ); n_cv1.w.l = 0; + n_cx1.w.h = COORD_X( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ); n_cx1.w.l = 0; + n_cu1.w.h = TEXTURE_U( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_texture ); n_cu1.w.l = 0; + n_cv1.w.h = TEXTURE_V( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_texture ); n_cv1.w.l = 0; n_leftpoint = p_n_leftpointlist[ n_leftpoint ]; - n_distance = COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) - n_y; + n_distance = COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) - n_y; if( n_distance < 1 ) { break; } - n_dx1 = (INT32)( ( COORD_X( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) << 16 ) - n_cx1.d ) / n_distance; - n_du1 = (INT32)( ( TEXTURE_U( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_texture ) << 16 ) - n_cu1.d ) / n_distance; - n_dv1 = (INT32)( ( TEXTURE_V( m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_texture ) << 16 ) - n_cv1.d ) / n_distance; + n_dx1 = (INT32)( ( COORD_X( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_coord ) << 16 ) - n_cx1.d ) / n_distance; + n_du1 = (INT32)( ( TEXTURE_U( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_texture ) << 16 ) - n_cu1.d ) / n_distance; + n_dv1 = (INT32)( ( TEXTURE_V( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_leftpoint ].n_texture ) << 16 ) - n_cv1.d ) / n_distance; } - if( n_y == COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_coord ) ) + if( n_y == COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_coord ) ) { - while( n_y == COORD_Y( m_packet.FlatTexturedPolygon.vertex[ p_n_rightpointlist[ n_rightpoint ] ].n_coord ) ) + while( n_y == COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ p_n_rightpointlist[ n_rightpoint ] ].n_coord ) ) { n_rightpoint = p_n_rightpointlist[ n_rightpoint ]; if( n_rightpoint == n_leftpoint ) @@ -1774,20 +1784,20 @@ static void FlatTexturedPolygon( running_machine *machine, int n_points ) break; } } - n_cx2.w.h = COORD_X( m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_coord ); n_cx2.w.l = 0; - n_cu2.w.h = TEXTURE_U( m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_texture ); n_cu2.w.l = 0; - n_cv2.w.h = TEXTURE_V( m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_texture ); n_cv2.w.l = 0; + n_cx2.w.h = COORD_X( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_coord ); n_cx2.w.l = 0; + n_cu2.w.h = TEXTURE_U( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_texture ); n_cu2.w.l = 0; + n_cv2.w.h = TEXTURE_V( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_texture ); n_cv2.w.l = 0; n_rightpoint = p_n_rightpointlist[ n_rightpoint ]; - n_distance = COORD_Y( m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_coord ) - n_y; + n_distance = COORD_Y( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_coord ) - n_y; if( n_distance < 1 ) { break; } - n_dx2 = (INT32)( ( COORD_X( m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_coord ) << 16 ) - n_cx2.d ) / n_distance; - n_du2 = (INT32)( ( TEXTURE_U( m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_texture ) << 16 ) - n_cu2.d ) / n_distance; - n_dv2 = (INT32)( ( TEXTURE_V( m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_texture ) << 16 ) - n_cv2.d ) / n_distance; + n_dx2 = (INT32)( ( COORD_X( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_coord ) << 16 ) - n_cx2.d ) / n_distance; + n_du2 = (INT32)( ( TEXTURE_U( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_texture ) << 16 ) - n_cu2.d ) / n_distance; + n_dv2 = (INT32)( ( TEXTURE_V( p_psxgpu->m_packet.FlatTexturedPolygon.vertex[ n_rightpoint ].n_texture ) << 16 ) - n_cv2.d ) / n_distance; } - if( (INT16)n_cx1.w.h != (INT16)n_cx2.w.h && n_y >= (INT32)m_n_drawarea_y1 && n_y <= (INT32)m_n_drawarea_y2 ) + if( (INT16)n_cx1.w.h != (INT16)n_cx2.w.h && n_y >= (INT32)p_psxgpu->n_drawarea_y1 && n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { if( (INT16)n_cx1.w.h < (INT16)n_cx2.w.h ) { @@ -1810,12 +1820,12 @@ static void FlatTexturedPolygon( running_machine *machine, int n_points ) n_dv = (INT32)( n_cv1.d - n_cv2.d ) / n_distance; } - if( ( (INT32)m_n_drawarea_x1 - n_x ) > 0 ) + if( ( (INT32)p_psxgpu->n_drawarea_x1 - n_x ) > 0 ) { - n_u.d += n_du * ( m_n_drawarea_x1 - n_x ); - n_v.d += n_dv * ( m_n_drawarea_x1 - n_x ); - n_distance -= ( m_n_drawarea_x1 - n_x ); - n_x = m_n_drawarea_x1; + n_u.d += n_du * ( p_psxgpu->n_drawarea_x1 - n_x ); + n_v.d += n_dv * ( p_psxgpu->n_drawarea_x1 - n_x ); + n_distance -= ( p_psxgpu->n_drawarea_x1 - n_x ); + n_x = p_psxgpu->n_drawarea_x1; } TEXTUREFILL( FLATTEXTUREDPOLYGONUPDATE, n_u.w.h, n_v.w.h ); } @@ -1829,7 +1839,7 @@ static void FlatTexturedPolygon( running_machine *machine, int n_points ) } } -static void GouraudPolygon( running_machine *machine, int n_points ) +static void GouraudPolygon( psx_gpu *p_psxgpu, int n_points ) { INT16 n_y; INT16 n_x; @@ -1878,18 +1888,18 @@ static void GouraudPolygon( running_machine *machine, int n_points ) UINT16 *p_vram; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 3 ) + if( p_psxgpu->m_debug.n_skip == 3 ) { return; } for( n_point = 0; n_point < n_points; n_point++ ) { - DebugMesh( COORD_X( m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) + m_n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) + p_psxgpu->n_drawoffset_y ); } - DebugMeshEnd(); + DebugMeshEnd(p_psxgpu); #endif - n_cmd = BGR_C( m_packet.GouraudPolygon.vertex[ 0 ].n_bgr ); + n_cmd = BGR_C( p_psxgpu->m_packet.GouraudPolygon.vertex[ 0 ].n_bgr ); n_cx1.d = 0; n_cr1.d = 0; @@ -1915,15 +1925,15 @@ static void GouraudPolygon( running_machine *machine, int n_points ) for( n_point = 0; n_point < n_points; n_point++ ) { - ADJUST_COORD( m_packet.GouraudPolygon.vertex[ n_point ].n_coord ); + ADJUST_COORD( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_point ].n_coord ); } n_leftpoint = 0; for( n_point = 1; n_point < n_points; n_point++ ) { - if( COORD_Y( m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) < COORD_Y( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) || - ( COORD_Y( m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) == COORD_Y( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) && - COORD_X( m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) < COORD_X( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) ) ) + if( COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) < COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) || + ( COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) == COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) && + COORD_X( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_point ].n_coord ) < COORD_X( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) ) ) { n_leftpoint = n_point; } @@ -1939,13 +1949,13 @@ static void GouraudPolygon( running_machine *machine, int n_points ) n_db1 = 0; n_db2 = 0; - n_y = COORD_Y( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_coord ); + n_y = COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_coord ); for( ;; ) { - if( n_y == COORD_Y( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) ) + if( n_y == COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) ) { - while( n_y == COORD_Y( m_packet.GouraudPolygon.vertex[ p_n_leftpointlist[ n_leftpoint ] ].n_coord ) ) + while( n_y == COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ p_n_leftpointlist[ n_leftpoint ] ].n_coord ) ) { n_leftpoint = p_n_leftpointlist[ n_leftpoint ]; if( n_leftpoint == n_rightpoint ) @@ -1953,24 +1963,24 @@ static void GouraudPolygon( running_machine *machine, int n_points ) break; } } - n_cx1.w.h = COORD_X( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ); n_cx1.w.l = 0; - n_cr1.w.h = BGR_R( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ); n_cr1.w.l = 0; - n_cg1.w.h = BGR_G( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ); n_cg1.w.l = 0; - n_cb1.w.h = BGR_B( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ); n_cb1.w.l = 0; + n_cx1.w.h = COORD_X( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ); n_cx1.w.l = 0; + n_cr1.w.h = BGR_R( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ); n_cr1.w.l = 0; + n_cg1.w.h = BGR_G( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ); n_cg1.w.l = 0; + n_cb1.w.h = BGR_B( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ); n_cb1.w.l = 0; n_leftpoint = p_n_leftpointlist[ n_leftpoint ]; - n_distance = COORD_Y( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) - n_y; + n_distance = COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) - n_y; if( n_distance < 1 ) { break; } - n_dx1 = (INT32)( ( COORD_X( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) << 16 ) - n_cx1.d ) / n_distance; - n_dr1 = (INT32)( ( BGR_R( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cr1.d ) / n_distance; - n_dg1 = (INT32)( ( BGR_G( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cg1.d ) / n_distance; - n_db1 = (INT32)( ( BGR_B( m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cb1.d ) / n_distance; + n_dx1 = (INT32)( ( COORD_X( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_coord ) << 16 ) - n_cx1.d ) / n_distance; + n_dr1 = (INT32)( ( BGR_R( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cr1.d ) / n_distance; + n_dg1 = (INT32)( ( BGR_G( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cg1.d ) / n_distance; + n_db1 = (INT32)( ( BGR_B( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cb1.d ) / n_distance; } - if( n_y == COORD_Y( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_coord ) ) + if( n_y == COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_coord ) ) { - while( n_y == COORD_Y( m_packet.GouraudPolygon.vertex[ p_n_rightpointlist[ n_rightpoint ] ].n_coord ) ) + while( n_y == COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ p_n_rightpointlist[ n_rightpoint ] ].n_coord ) ) { n_rightpoint = p_n_rightpointlist[ n_rightpoint ]; if( n_rightpoint == n_leftpoint ) @@ -1978,22 +1988,22 @@ static void GouraudPolygon( running_machine *machine, int n_points ) break; } } - n_cx2.w.h = COORD_X( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_coord ); n_cx2.w.l = 0; - n_cr2.w.h = BGR_R( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ); n_cr2.w.l = 0; - n_cg2.w.h = BGR_G( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ); n_cg2.w.l = 0; - n_cb2.w.h = BGR_B( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ); n_cb2.w.l = 0; + n_cx2.w.h = COORD_X( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_coord ); n_cx2.w.l = 0; + n_cr2.w.h = BGR_R( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ); n_cr2.w.l = 0; + n_cg2.w.h = BGR_G( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ); n_cg2.w.l = 0; + n_cb2.w.h = BGR_B( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ); n_cb2.w.l = 0; n_rightpoint = p_n_rightpointlist[ n_rightpoint ]; - n_distance = COORD_Y( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_coord ) - n_y; + n_distance = COORD_Y( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_coord ) - n_y; if( n_distance < 1 ) { break; } - n_dx2 = (INT32)( ( COORD_X( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_coord ) << 16 ) - n_cx2.d ) / n_distance; - n_dr2 = (INT32)( ( BGR_R( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cr2.d ) / n_distance; - n_dg2 = (INT32)( ( BGR_G( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cg2.d ) / n_distance; - n_db2 = (INT32)( ( BGR_B( m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cb2.d ) / n_distance; + n_dx2 = (INT32)( ( COORD_X( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_coord ) << 16 ) - n_cx2.d ) / n_distance; + n_dr2 = (INT32)( ( BGR_R( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cr2.d ) / n_distance; + n_dg2 = (INT32)( ( BGR_G( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cg2.d ) / n_distance; + n_db2 = (INT32)( ( BGR_B( p_psxgpu->m_packet.GouraudPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cb2.d ) / n_distance; } - if( (INT16)n_cx1.w.h != (INT16)n_cx2.w.h && n_y >= (INT32)m_n_drawarea_y1 && n_y <= (INT32)m_n_drawarea_y2 ) + if( (INT16)n_cx1.w.h != (INT16)n_cx2.w.h && n_y >= (INT32)p_psxgpu->n_drawarea_y1 && n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { if( (INT16)n_cx1.w.h < (INT16)n_cx2.w.h ) { @@ -2020,13 +2030,13 @@ static void GouraudPolygon( running_machine *machine, int n_points ) n_db = (INT32)( n_cb1.d - n_cb2.d ) / n_distance; } - if( ( (INT32)m_n_drawarea_x1 - n_x ) > 0 ) + if( ( (INT32)p_psxgpu->n_drawarea_x1 - n_x ) > 0 ) { - n_r.d += n_dr * ( m_n_drawarea_x1 - n_x ); - n_g.d += n_dg * ( m_n_drawarea_x1 - n_x ); - n_b.d += n_db * ( m_n_drawarea_x1 - n_x ); - n_distance -= ( m_n_drawarea_x1 - n_x ); - n_x = m_n_drawarea_x1; + n_r.d += n_dr * ( p_psxgpu->n_drawarea_x1 - n_x ); + n_g.d += n_dg * ( p_psxgpu->n_drawarea_x1 - n_x ); + n_b.d += n_db * ( p_psxgpu->n_drawarea_x1 - n_x ); + n_distance -= ( p_psxgpu->n_drawarea_x1 - n_x ); + n_x = p_psxgpu->n_drawarea_x1; } SOLIDFILL( GOURAUDPOLYGONUPDATE ) } @@ -2042,7 +2052,7 @@ static void GouraudPolygon( running_machine *machine, int n_points ) } } -static void GouraudTexturedPolygon( running_machine *machine, int n_points ) +static void GouraudTexturedPolygon( psx_gpu *p_psxgpu, int n_points ) { INT16 n_y; INT16 n_x; @@ -2109,21 +2119,21 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) UINT32 n_bgr; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 4 ) + if( p_psxgpu->m_debug.n_skip == 4 ) { return; } for( n_point = 0; n_point < n_points; n_point++ ) { - DebugMesh( COORD_X( m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) + m_n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) + p_psxgpu->n_drawoffset_y ); } - DebugMeshEnd(); + DebugMeshEnd(p_psxgpu); #endif - n_cmd = BGR_C( m_packet.GouraudTexturedPolygon.vertex[ 0 ].n_bgr ); + n_cmd = BGR_C( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ 0 ].n_bgr ); - n_clutx = ( m_packet.GouraudTexturedPolygon.vertex[ 0 ].n_texture.w.h & 0x3f ) << 4; - n_cluty = ( m_packet.GouraudTexturedPolygon.vertex[ 0 ].n_texture.w.h >> 6 ) & 0x3ff; + n_clutx = ( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ 0 ].n_texture.w.h & 0x3f ) << 4; + n_cluty = ( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ 0 ].n_texture.w.h >> 6 ) & 0x3ff; n_cx1.d = 0; n_cr1.d = 0; @@ -2138,7 +2148,7 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) n_cu2.d = 0; n_cv2.d = 0; - decode_tpage( machine, &psxgpu, m_packet.GouraudTexturedPolygon.vertex[ 1 ].n_texture.w.h ); + decode_tpage( p_psxgpu, p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ 1 ].n_texture.w.h ); TEXTURESETUP if( n_points == 4 ) @@ -2154,15 +2164,15 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) for( n_point = 0; n_point < n_points; n_point++ ) { - ADJUST_COORD( m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ); + ADJUST_COORD( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ); } n_leftpoint = 0; for( n_point = 1; n_point < n_points; n_point++ ) { - if( COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) || - ( COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) == COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) && - COORD_X( m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_X( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) ) ) + if( COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) || + ( COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) == COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) && + COORD_X( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_point ].n_coord ) < COORD_X( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) ) ) { n_leftpoint = n_point; } @@ -2182,13 +2192,13 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) n_dv1 = 0; n_dv2 = 0; - n_y = COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_coord ); + n_y = COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_coord ); for( ;; ) { - if( n_y == COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) ) + if( n_y == COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) ) { - while( n_y == COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ p_n_leftpointlist[ n_leftpoint ] ].n_coord ) ) + while( n_y == COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ p_n_leftpointlist[ n_leftpoint ] ].n_coord ) ) { n_leftpoint = p_n_leftpointlist[ n_leftpoint ]; if( n_leftpoint == n_rightpoint ) @@ -2196,13 +2206,13 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) break; } } - n_cx1.w.h = COORD_X( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ); n_cx1.w.l = 0; + n_cx1.w.h = COORD_X( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ); n_cx1.w.l = 0; switch( n_cmd & 0x01 ) { case 0x00: - n_cr1.w.h = BGR_R( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ); n_cr1.w.l = 0; - n_cg1.w.h = BGR_G( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ); n_cg1.w.l = 0; - n_cb1.w.h = BGR_B( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ); n_cb1.w.l = 0; + n_cr1.w.h = BGR_R( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ); n_cr1.w.l = 0; + n_cg1.w.h = BGR_G( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ); n_cg1.w.l = 0; + n_cb1.w.h = BGR_B( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ); n_cb1.w.l = 0; break; case 0x01: n_cr1.w.h = 0x80; n_cr1.w.l = 0; @@ -2210,21 +2220,21 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) n_cb1.w.h = 0x80; n_cb1.w.l = 0; break; } - n_cu1.w.h = TEXTURE_U( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_texture ); n_cu1.w.l = 0; - n_cv1.w.h = TEXTURE_V( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_texture ); n_cv1.w.l = 0; + n_cu1.w.h = TEXTURE_U( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_texture ); n_cu1.w.l = 0; + n_cv1.w.h = TEXTURE_V( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_texture ); n_cv1.w.l = 0; n_leftpoint = p_n_leftpointlist[ n_leftpoint ]; - n_distance = COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) - n_y; + n_distance = COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) - n_y; if( n_distance < 1 ) { break; } - n_dx1 = (INT32)( ( COORD_X( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) << 16 ) - n_cx1.d ) / n_distance; + n_dx1 = (INT32)( ( COORD_X( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_coord ) << 16 ) - n_cx1.d ) / n_distance; switch( n_cmd & 0x01 ) { case 0x00: - n_dr1 = (INT32)( ( BGR_R( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cr1.d ) / n_distance; - n_dg1 = (INT32)( ( BGR_G( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cg1.d ) / n_distance; - n_db1 = (INT32)( ( BGR_B( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cb1.d ) / n_distance; + n_dr1 = (INT32)( ( BGR_R( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cr1.d ) / n_distance; + n_dg1 = (INT32)( ( BGR_G( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cg1.d ) / n_distance; + n_db1 = (INT32)( ( BGR_B( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_bgr ) << 16 ) - n_cb1.d ) / n_distance; break; case 0x01: n_dr1 = 0; @@ -2232,12 +2242,12 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) n_db1 = 0; break; } - n_du1 = (INT32)( ( TEXTURE_U( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_texture ) << 16 ) - n_cu1.d ) / n_distance; - n_dv1 = (INT32)( ( TEXTURE_V( m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_texture ) << 16 ) - n_cv1.d ) / n_distance; + n_du1 = (INT32)( ( TEXTURE_U( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_texture ) << 16 ) - n_cu1.d ) / n_distance; + n_dv1 = (INT32)( ( TEXTURE_V( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_leftpoint ].n_texture ) << 16 ) - n_cv1.d ) / n_distance; } - if( n_y == COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_coord ) ) + if( n_y == COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_coord ) ) { - while( n_y == COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ p_n_rightpointlist[ n_rightpoint ] ].n_coord ) ) + while( n_y == COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ p_n_rightpointlist[ n_rightpoint ] ].n_coord ) ) { n_rightpoint = p_n_rightpointlist[ n_rightpoint ]; if( n_rightpoint == n_leftpoint ) @@ -2245,13 +2255,13 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) break; } } - n_cx2.w.h = COORD_X( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_coord ); n_cx2.w.l = 0; + n_cx2.w.h = COORD_X( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_coord ); n_cx2.w.l = 0; switch( n_cmd & 0x01 ) { case 0x00: - n_cr2.w.h = BGR_R( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ); n_cr2.w.l = 0; - n_cg2.w.h = BGR_G( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ); n_cg2.w.l = 0; - n_cb2.w.h = BGR_B( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ); n_cb2.w.l = 0; + n_cr2.w.h = BGR_R( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ); n_cr2.w.l = 0; + n_cg2.w.h = BGR_G( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ); n_cg2.w.l = 0; + n_cb2.w.h = BGR_B( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ); n_cb2.w.l = 0; break; case 0x01: n_cr2.w.h = 0x80; n_cr2.w.l = 0; @@ -2259,21 +2269,21 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) n_cb2.w.h = 0x80; n_cb2.w.l = 0; break; } - n_cu2.w.h = TEXTURE_U( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_texture ); n_cu2.w.l = 0; - n_cv2.w.h = TEXTURE_V( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_texture ); n_cv2.w.l = 0; + n_cu2.w.h = TEXTURE_U( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_texture ); n_cu2.w.l = 0; + n_cv2.w.h = TEXTURE_V( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_texture ); n_cv2.w.l = 0; n_rightpoint = p_n_rightpointlist[ n_rightpoint ]; - n_distance = COORD_Y( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_coord ) - n_y; + n_distance = COORD_Y( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_coord ) - n_y; if( n_distance < 1 ) { break; } - n_dx2 = (INT32)( ( COORD_X( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_coord ) << 16 ) - n_cx2.d ) / n_distance; + n_dx2 = (INT32)( ( COORD_X( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_coord ) << 16 ) - n_cx2.d ) / n_distance; switch( n_cmd & 0x01 ) { case 0x00: - n_dr2 = (INT32)( ( BGR_R( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cr2.d ) / n_distance; - n_dg2 = (INT32)( ( BGR_G( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cg2.d ) / n_distance; - n_db2 = (INT32)( ( BGR_B( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cb2.d ) / n_distance; + n_dr2 = (INT32)( ( BGR_R( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cr2.d ) / n_distance; + n_dg2 = (INT32)( ( BGR_G( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cg2.d ) / n_distance; + n_db2 = (INT32)( ( BGR_B( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_bgr ) << 16 ) - n_cb2.d ) / n_distance; break; case 0x01: n_dr2 = 0; @@ -2281,10 +2291,10 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) n_db2 = 0; break; } - n_du2 = (INT32)( ( TEXTURE_U( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_texture ) << 16 ) - n_cu2.d ) / n_distance; - n_dv2 = (INT32)( ( TEXTURE_V( m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_texture ) << 16 ) - n_cv2.d ) / n_distance; + n_du2 = (INT32)( ( TEXTURE_U( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_texture ) << 16 ) - n_cu2.d ) / n_distance; + n_dv2 = (INT32)( ( TEXTURE_V( p_psxgpu->m_packet.GouraudTexturedPolygon.vertex[ n_rightpoint ].n_texture ) << 16 ) - n_cv2.d ) / n_distance; } - if( (INT16)n_cx1.w.h != (INT16)n_cx2.w.h && n_y >= (INT32)m_n_drawarea_y1 && n_y <= (INT32)m_n_drawarea_y2 ) + if( (INT16)n_cx1.w.h != (INT16)n_cx2.w.h && n_y >= (INT32)p_psxgpu->n_drawarea_y1 && n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { if( (INT16)n_cx1.w.h < (INT16)n_cx2.w.h ) { @@ -2319,15 +2329,15 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) n_dv = (INT32)( n_cv1.d - n_cv2.d ) / n_distance; } - if( ( (INT32)m_n_drawarea_x1 - n_x ) > 0 ) + if( ( (INT32)p_psxgpu->n_drawarea_x1 - n_x ) > 0 ) { - n_r.d += n_dr * ( m_n_drawarea_x1 - n_x ); - n_g.d += n_dg * ( m_n_drawarea_x1 - n_x ); - n_b.d += n_db * ( m_n_drawarea_x1 - n_x ); - n_u.d += n_du * ( m_n_drawarea_x1 - n_x ); - n_v.d += n_dv * ( m_n_drawarea_x1 - n_x ); - n_distance -= ( m_n_drawarea_x1 - n_x ); - n_x = m_n_drawarea_x1; + n_r.d += n_dr * ( p_psxgpu->n_drawarea_x1 - n_x ); + n_g.d += n_dg * ( p_psxgpu->n_drawarea_x1 - n_x ); + n_b.d += n_db * ( p_psxgpu->n_drawarea_x1 - n_x ); + n_u.d += n_du * ( p_psxgpu->n_drawarea_x1 - n_x ); + n_v.d += n_dv * ( p_psxgpu->n_drawarea_x1 - n_x ); + n_distance -= ( p_psxgpu->n_drawarea_x1 - n_x ); + n_x = p_psxgpu->n_drawarea_x1; } TEXTUREFILL( GOURAUDTEXTUREDPOLYGONUPDATE, n_u.w.h, n_v.w.h ); } @@ -2347,7 +2357,7 @@ static void GouraudTexturedPolygon( running_machine *machine, int n_points ) } } -static void MonochromeLine( void ) +static void MonochromeLine( psx_gpu *p_psxgpu ) { PAIR n_x; PAIR n_y; @@ -2369,23 +2379,23 @@ static void MonochromeLine( void ) UINT16 *p_vram; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 5 ) + if( p_psxgpu->m_debug.n_skip == 5 ) { return; } - DebugMesh( COORD_X( m_packet.MonochromeLine.vertex[ 0 ].n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.MonochromeLine.vertex[ 0 ].n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.MonochromeLine.vertex[ 1 ].n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.MonochromeLine.vertex[ 1 ].n_coord ) + m_n_drawoffset_y ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.MonochromeLine.vertex[ 0 ].n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.MonochromeLine.vertex[ 0 ].n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.MonochromeLine.vertex[ 1 ].n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.MonochromeLine.vertex[ 1 ].n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMeshEnd(p_psxgpu); #endif - n_xstart = COORD_X( m_packet.MonochromeLine.vertex[ 0 ].n_coord ) + m_n_drawoffset_x; - n_xend = COORD_X( m_packet.MonochromeLine.vertex[ 1 ].n_coord ) + m_n_drawoffset_x; - n_ystart = COORD_Y( m_packet.MonochromeLine.vertex[ 0 ].n_coord ) + m_n_drawoffset_y; - n_yend = COORD_Y( m_packet.MonochromeLine.vertex[ 1 ].n_coord ) + m_n_drawoffset_y; + n_xstart = COORD_X( p_psxgpu->m_packet.MonochromeLine.vertex[ 0 ].n_coord ) + p_psxgpu->n_drawoffset_x; + n_xend = COORD_X( p_psxgpu->m_packet.MonochromeLine.vertex[ 1 ].n_coord ) + p_psxgpu->n_drawoffset_x; + n_ystart = COORD_Y( p_psxgpu->m_packet.MonochromeLine.vertex[ 0 ].n_coord ) + p_psxgpu->n_drawoffset_y; + n_yend = COORD_Y( p_psxgpu->m_packet.MonochromeLine.vertex[ 1 ].n_coord ) + p_psxgpu->n_drawoffset_y; - n_r = BGR_R( m_packet.MonochromeLine.n_bgr ); - n_g = BGR_G( m_packet.MonochromeLine.n_bgr ); - n_b = BGR_B( m_packet.MonochromeLine.n_bgr ); + n_r = BGR_R( p_psxgpu->m_packet.MonochromeLine.n_bgr ); + n_g = BGR_G( p_psxgpu->m_packet.MonochromeLine.n_bgr ); + n_b = BGR_B( p_psxgpu->m_packet.MonochromeLine.n_bgr ); if( n_xend > n_xstart ) { @@ -2430,16 +2440,16 @@ static void MonochromeLine( void ) while( n_len > 0 ) { - if( (INT16)n_x.w.h >= (INT32)m_n_drawarea_x1 && - (INT16)n_y.w.h >= (INT32)m_n_drawarea_y1 && - (INT16)n_x.w.h <= (INT32)m_n_drawarea_x2 && - (INT16)n_y.w.h <= (INT32)m_n_drawarea_y2 ) + if( (INT16)n_x.w.h >= (INT32)p_psxgpu->n_drawarea_x1 && + (INT16)n_y.w.h >= (INT32)p_psxgpu->n_drawarea_y1 && + (INT16)n_x.w.h <= (INT32)p_psxgpu->n_drawarea_x2 && + (INT16)n_y.w.h <= (INT32)p_psxgpu->n_drawarea_y2 ) { - p_vram = m_p_p_vram[ n_y.w.h ] + n_x.w.h; + p_vram = p_psxgpu->p_p_vram[ n_y.w.h ] + n_x.w.h; WRITE_PIXEL( - m_p_n_redshade[ MID_LEVEL | n_r ] | - m_p_n_greenshade[ MID_LEVEL | n_g ] | - m_p_n_blueshade[ MID_LEVEL | n_b ] ); + p_psxgpu->p_n_redshade[ MID_LEVEL | n_r ] | + p_psxgpu->p_n_greenshade[ MID_LEVEL | n_g ] | + p_psxgpu->p_n_blueshade[ MID_LEVEL | n_b ] ); } n_x.d += n_dx; n_y.d += n_dy; @@ -2447,7 +2457,7 @@ static void MonochromeLine( void ) } } -static void GouraudLine( void ) +static void GouraudLine( psx_gpu *p_psxgpu ) { PAIR n_x; PAIR n_y; @@ -2475,26 +2485,26 @@ static void GouraudLine( void ) UINT16 *p_vram; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 6 ) + if( p_psxgpu->m_debug.n_skip == 6 ) { return; } - DebugMesh( COORD_X( m_packet.GouraudLine.vertex[ 0 ].n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.GouraudLine.vertex[ 0 ].n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.GouraudLine.vertex[ 1 ].n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.GouraudLine.vertex[ 1 ].n_coord ) + m_n_drawoffset_y ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.GouraudLine.vertex[ 0 ].n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.GouraudLine.vertex[ 0 ].n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.GouraudLine.vertex[ 1 ].n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.GouraudLine.vertex[ 1 ].n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMeshEnd(p_psxgpu); #endif - n_xstart = COORD_X( m_packet.GouraudLine.vertex[ 0 ].n_coord ) + m_n_drawoffset_x; - n_ystart = COORD_Y( m_packet.GouraudLine.vertex[ 0 ].n_coord ) + m_n_drawoffset_y; - n_cr1.w.h = BGR_R( m_packet.GouraudLine.vertex[ 0 ].n_bgr ); n_cr1.w.l = 0; - n_cg1.w.h = BGR_G( m_packet.GouraudLine.vertex[ 0 ].n_bgr ); n_cg1.w.l = 0; - n_cb1.w.h = BGR_B( m_packet.GouraudLine.vertex[ 0 ].n_bgr ); n_cb1.w.l = 0; + n_xstart = COORD_X( p_psxgpu->m_packet.GouraudLine.vertex[ 0 ].n_coord ) + p_psxgpu->n_drawoffset_x; + n_ystart = COORD_Y( p_psxgpu->m_packet.GouraudLine.vertex[ 0 ].n_coord ) + p_psxgpu->n_drawoffset_y; + n_cr1.w.h = BGR_R( p_psxgpu->m_packet.GouraudLine.vertex[ 0 ].n_bgr ); n_cr1.w.l = 0; + n_cg1.w.h = BGR_G( p_psxgpu->m_packet.GouraudLine.vertex[ 0 ].n_bgr ); n_cg1.w.l = 0; + n_cb1.w.h = BGR_B( p_psxgpu->m_packet.GouraudLine.vertex[ 0 ].n_bgr ); n_cb1.w.l = 0; - n_xend = COORD_X( m_packet.GouraudLine.vertex[ 1 ].n_coord ) + m_n_drawoffset_x; - n_yend = COORD_Y( m_packet.GouraudLine.vertex[ 1 ].n_coord ) + m_n_drawoffset_y; - n_cr2.w.h = BGR_R( m_packet.GouraudLine.vertex[ 1 ].n_bgr ); n_cr1.w.l = 0; - n_cg2.w.h = BGR_G( m_packet.GouraudLine.vertex[ 1 ].n_bgr ); n_cg1.w.l = 0; - n_cb2.w.h = BGR_B( m_packet.GouraudLine.vertex[ 1 ].n_bgr ); n_cb1.w.l = 0; + n_xend = COORD_X( p_psxgpu->m_packet.GouraudLine.vertex[ 1 ].n_coord ) + p_psxgpu->n_drawoffset_x; + n_yend = COORD_Y( p_psxgpu->m_packet.GouraudLine.vertex[ 1 ].n_coord ) + p_psxgpu->n_drawoffset_y; + n_cr2.w.h = BGR_R( p_psxgpu->m_packet.GouraudLine.vertex[ 1 ].n_bgr ); n_cr1.w.l = 0; + n_cg2.w.h = BGR_G( p_psxgpu->m_packet.GouraudLine.vertex[ 1 ].n_bgr ); n_cg1.w.l = 0; + n_cb2.w.h = BGR_B( p_psxgpu->m_packet.GouraudLine.vertex[ 1 ].n_bgr ); n_cb1.w.l = 0; n_x.w.h = n_xstart; n_x.w.l = 0; n_y.w.h = n_ystart; n_y.w.l = 0; @@ -2542,16 +2552,16 @@ static void GouraudLine( void ) while( n_distance > 0 ) { - if( (INT16)n_x.w.h >= (INT32)m_n_drawarea_x1 && - (INT16)n_y.w.h >= (INT32)m_n_drawarea_y1 && - (INT16)n_x.w.h <= (INT32)m_n_drawarea_x2 && - (INT16)n_y.w.h <= (INT32)m_n_drawarea_y2 ) + if( (INT16)n_x.w.h >= (INT32)p_psxgpu->n_drawarea_x1 && + (INT16)n_y.w.h >= (INT32)p_psxgpu->n_drawarea_y1 && + (INT16)n_x.w.h <= (INT32)p_psxgpu->n_drawarea_x2 && + (INT16)n_y.w.h <= (INT32)p_psxgpu->n_drawarea_y2 ) { - p_vram = m_p_p_vram[ n_y.w.h ] + n_x.w.h; + p_vram = p_psxgpu->p_p_vram[ n_y.w.h ] + n_x.w.h; WRITE_PIXEL( - m_p_n_redshade[ MID_LEVEL | n_r.w.h ] | - m_p_n_greenshade[ MID_LEVEL | n_g.w.h ] | - m_p_n_blueshade[ MID_LEVEL | n_b.w.h ] ); + p_psxgpu->p_n_redshade[ MID_LEVEL | n_r.w.h ] | + p_psxgpu->p_n_greenshade[ MID_LEVEL | n_g.w.h ] | + p_psxgpu->p_n_blueshade[ MID_LEVEL | n_b.w.h ] ); } n_x.d += n_dx; n_y.d += n_dy; @@ -2562,7 +2572,7 @@ static void GouraudLine( void ) } } -static void FrameBufferRectangleDraw( void ) +static void FrameBufferRectangleDraw( psx_gpu *p_psxgpu ) { PAIR n_r; PAIR n_g; @@ -2574,36 +2584,36 @@ static void FrameBufferRectangleDraw( void ) UINT16 *p_vram; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 7 ) + if( p_psxgpu->m_debug.n_skip == 7 ) { return; } - DebugMesh( COORD_X( m_packet.FlatRectangle.n_coord ), COORD_Y( m_packet.FlatRectangle.n_coord ) ); - DebugMesh( COORD_X( m_packet.FlatRectangle.n_coord ) + SIZE_W( m_packet.FlatRectangle.n_size ), COORD_Y( m_packet.FlatRectangle.n_coord ) ); - DebugMesh( COORD_X( m_packet.FlatRectangle.n_coord ), COORD_Y( m_packet.FlatRectangle.n_coord ) + SIZE_H( m_packet.FlatRectangle.n_size ) ); - DebugMesh( COORD_X( m_packet.FlatRectangle.n_coord ) + SIZE_W( m_packet.FlatRectangle.n_size ), COORD_Y( m_packet.FlatRectangle.n_coord ) + SIZE_H( m_packet.FlatRectangle.n_size ) ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle.n_coord ), COORD_Y( p_psxgpu->m_packet.FlatRectangle.n_coord ) ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle.n_coord ) + SIZE_W( p_psxgpu->m_packet.FlatRectangle.n_size ), COORD_Y( p_psxgpu->m_packet.FlatRectangle.n_coord ) ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle.n_coord ), COORD_Y( p_psxgpu->m_packet.FlatRectangle.n_coord ) + SIZE_H( p_psxgpu->m_packet.FlatRectangle.n_size ) ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle.n_coord ) + SIZE_W( p_psxgpu->m_packet.FlatRectangle.n_size ), COORD_Y( p_psxgpu->m_packet.FlatRectangle.n_coord ) + SIZE_H( p_psxgpu->m_packet.FlatRectangle.n_size ) ); + DebugMeshEnd(p_psxgpu); #endif - n_r.w.h = BGR_R( m_packet.FlatRectangle.n_bgr ); n_r.w.l = 0; - n_g.w.h = BGR_G( m_packet.FlatRectangle.n_bgr ); n_g.w.l = 0; - n_b.w.h = BGR_B( m_packet.FlatRectangle.n_bgr ); n_b.w.l = 0; + n_r.w.h = BGR_R( p_psxgpu->m_packet.FlatRectangle.n_bgr ); n_r.w.l = 0; + n_g.w.h = BGR_G( p_psxgpu->m_packet.FlatRectangle.n_bgr ); n_g.w.l = 0; + n_b.w.h = BGR_B( p_psxgpu->m_packet.FlatRectangle.n_bgr ); n_b.w.l = 0; - n_y = COORD_Y( m_packet.FlatRectangle.n_coord ); - n_h = SIZE_H( m_packet.FlatRectangle.n_size ); + n_y = COORD_Y( p_psxgpu->m_packet.FlatRectangle.n_coord ); + n_h = SIZE_H( p_psxgpu->m_packet.FlatRectangle.n_size ); while( n_h > 0 ) { - n_x = COORD_X( m_packet.FlatRectangle.n_coord ); + n_x = COORD_X( p_psxgpu->m_packet.FlatRectangle.n_coord ); - n_distance = SIZE_W( m_packet.FlatRectangle.n_size ); + n_distance = SIZE_W( p_psxgpu->m_packet.FlatRectangle.n_size ); while( n_distance > 0 ) { - p_vram = m_p_p_vram[ n_y & 1023 ] + ( n_x & 1023 ); + p_vram = p_psxgpu->p_p_vram[ n_y & 1023 ] + ( n_x & 1023 ); WRITE_PIXEL( - m_p_n_redshade[ MID_LEVEL | n_r.w.h ] | - m_p_n_greenshade[ MID_LEVEL | n_g.w.h ] | - m_p_n_blueshade[ MID_LEVEL | n_b.w.h ] ); + p_psxgpu->p_n_redshade[ MID_LEVEL | n_r.w.h ] | + p_psxgpu->p_n_greenshade[ MID_LEVEL | n_g.w.h ] | + p_psxgpu->p_n_blueshade[ MID_LEVEL | n_b.w.h ] ); n_x++; n_distance--; } @@ -2612,7 +2622,7 @@ static void FrameBufferRectangleDraw( void ) } } -static void FlatRectangle( running_machine *machine ) +static void FlatRectangle( psx_gpu *p_psxgpu ) { INT16 n_y; INT16 n_x; @@ -2636,39 +2646,39 @@ static void FlatRectangle( running_machine *machine ) UINT16 *p_vram; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 8 ) + if( p_psxgpu->m_debug.n_skip == 8 ) { return; } - DebugMesh( COORD_X( m_packet.FlatRectangle.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.FlatRectangle.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.FlatRectangle.n_coord ) + m_n_drawoffset_x + SIZE_W( m_packet.FlatRectangle.n_size ), COORD_Y( m_packet.FlatRectangle.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.FlatRectangle.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.FlatRectangle.n_coord ) + m_n_drawoffset_y + SIZE_H( m_packet.FlatRectangle.n_size ) ); - DebugMesh( COORD_X( m_packet.FlatRectangle.n_coord ) + m_n_drawoffset_x + SIZE_W( m_packet.FlatRectangle.n_size ), COORD_Y( m_packet.FlatRectangle.n_coord ) + m_n_drawoffset_y + SIZE_H( m_packet.FlatRectangle.n_size ) ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.FlatRectangle.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle.n_coord ) + p_psxgpu->n_drawoffset_x + SIZE_W( p_psxgpu->m_packet.FlatRectangle.n_size ), COORD_Y( p_psxgpu->m_packet.FlatRectangle.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.FlatRectangle.n_coord ) + p_psxgpu->n_drawoffset_y + SIZE_H( p_psxgpu->m_packet.FlatRectangle.n_size ) ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle.n_coord ) + p_psxgpu->n_drawoffset_x + SIZE_W( p_psxgpu->m_packet.FlatRectangle.n_size ), COORD_Y( p_psxgpu->m_packet.FlatRectangle.n_coord ) + p_psxgpu->n_drawoffset_y + SIZE_H( p_psxgpu->m_packet.FlatRectangle.n_size ) ); + DebugMeshEnd(p_psxgpu); #endif - n_cmd = BGR_C( m_packet.FlatRectangle.n_bgr ); + n_cmd = BGR_C( p_psxgpu->m_packet.FlatRectangle.n_bgr ); SOLIDSETUP - n_r.w.h = BGR_R( m_packet.FlatRectangle.n_bgr ); n_r.w.l = 0; - n_g.w.h = BGR_G( m_packet.FlatRectangle.n_bgr ); n_g.w.l = 0; - n_b.w.h = BGR_B( m_packet.FlatRectangle.n_bgr ); n_b.w.l = 0; + n_r.w.h = BGR_R( p_psxgpu->m_packet.FlatRectangle.n_bgr ); n_r.w.l = 0; + n_g.w.h = BGR_G( p_psxgpu->m_packet.FlatRectangle.n_bgr ); n_g.w.l = 0; + n_b.w.h = BGR_B( p_psxgpu->m_packet.FlatRectangle.n_bgr ); n_b.w.l = 0; - n_y = COORD_Y( m_packet.FlatRectangle.n_coord ) + m_n_drawoffset_y; - n_h = SIZE_H( m_packet.FlatRectangle.n_size ); + n_y = COORD_Y( p_psxgpu->m_packet.FlatRectangle.n_coord ) + p_psxgpu->n_drawoffset_y; + n_h = SIZE_H( p_psxgpu->m_packet.FlatRectangle.n_size ); while( n_h > 0 ) { - n_x = COORD_X( m_packet.FlatRectangle.n_coord ) + m_n_drawoffset_x; + n_x = COORD_X( p_psxgpu->m_packet.FlatRectangle.n_coord ) + p_psxgpu->n_drawoffset_x; - n_distance = SIZE_W( m_packet.FlatRectangle.n_size ); - if( n_distance > 0 && n_y >= (INT32)m_n_drawarea_y1 && n_y <= (INT32)m_n_drawarea_y2 ) + n_distance = SIZE_W( p_psxgpu->m_packet.FlatRectangle.n_size ); + if( n_distance > 0 && n_y >= (INT32)p_psxgpu->n_drawarea_y1 && n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { - if( ( (INT32)m_n_drawarea_x1 - n_x ) > 0 ) + if( ( (INT32)p_psxgpu->n_drawarea_x1 - n_x ) > 0 ) { - n_distance -= ( m_n_drawarea_x1 - n_x ); - n_x = m_n_drawarea_x1; + n_distance -= ( p_psxgpu->n_drawarea_x1 - n_x ); + n_x = p_psxgpu->n_drawarea_x1; } SOLIDFILL( FLATRECTANGEUPDATE ) } @@ -2677,7 +2687,7 @@ static void FlatRectangle( running_machine *machine ) } } -static void FlatRectangle8x8( running_machine *machine ) +static void FlatRectangle8x8( psx_gpu *p_psxgpu ) { INT16 n_y; INT16 n_x; @@ -2701,39 +2711,39 @@ static void FlatRectangle8x8( running_machine *machine ) UINT16 *p_vram; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 9 ) + if( p_psxgpu->m_debug.n_skip == 9 ) { return; } - DebugMesh( COORD_X( m_packet.FlatRectangle8x8.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.FlatRectangle8x8.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.FlatRectangle8x8.n_coord ) + m_n_drawoffset_x + 8, COORD_Y( m_packet.FlatRectangle8x8.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.FlatRectangle8x8.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.FlatRectangle8x8.n_coord ) + m_n_drawoffset_y + 8 ); - DebugMesh( COORD_X( m_packet.FlatRectangle8x8.n_coord ) + m_n_drawoffset_x + 8, COORD_Y( m_packet.FlatRectangle8x8.n_coord ) + m_n_drawoffset_y + 8 ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle8x8.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.FlatRectangle8x8.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle8x8.n_coord ) + p_psxgpu->n_drawoffset_x + 8, COORD_Y( p_psxgpu->m_packet.FlatRectangle8x8.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle8x8.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.FlatRectangle8x8.n_coord ) + p_psxgpu->n_drawoffset_y + 8 ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle8x8.n_coord ) + p_psxgpu->n_drawoffset_x + 8, COORD_Y( p_psxgpu->m_packet.FlatRectangle8x8.n_coord ) + p_psxgpu->n_drawoffset_y + 8 ); + DebugMeshEnd(p_psxgpu); #endif - n_cmd = BGR_C( m_packet.FlatRectangle8x8.n_bgr ); + n_cmd = BGR_C( p_psxgpu->m_packet.FlatRectangle8x8.n_bgr ); SOLIDSETUP - n_r.w.h = BGR_R( m_packet.FlatRectangle8x8.n_bgr ); n_r.w.l = 0; - n_g.w.h = BGR_G( m_packet.FlatRectangle8x8.n_bgr ); n_g.w.l = 0; - n_b.w.h = BGR_B( m_packet.FlatRectangle8x8.n_bgr ); n_b.w.l = 0; + n_r.w.h = BGR_R( p_psxgpu->m_packet.FlatRectangle8x8.n_bgr ); n_r.w.l = 0; + n_g.w.h = BGR_G( p_psxgpu->m_packet.FlatRectangle8x8.n_bgr ); n_g.w.l = 0; + n_b.w.h = BGR_B( p_psxgpu->m_packet.FlatRectangle8x8.n_bgr ); n_b.w.l = 0; - n_y = COORD_Y( m_packet.FlatRectangle8x8.n_coord ) + m_n_drawoffset_y; + n_y = COORD_Y( p_psxgpu->m_packet.FlatRectangle8x8.n_coord ) + p_psxgpu->n_drawoffset_y; n_h = 8; while( n_h > 0 ) { - n_x = COORD_X( m_packet.FlatRectangle8x8.n_coord ) + m_n_drawoffset_x; + n_x = COORD_X( p_psxgpu->m_packet.FlatRectangle8x8.n_coord ) + p_psxgpu->n_drawoffset_x; n_distance = 8; - if( n_distance > 0 && n_y >= (INT32)m_n_drawarea_y1 && n_y <= (INT32)m_n_drawarea_y2 ) + if( n_distance > 0 && n_y >= (INT32)p_psxgpu->n_drawarea_y1 && n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { - if( ( (INT32)m_n_drawarea_x1 - n_x ) > 0 ) + if( ( (INT32)p_psxgpu->n_drawarea_x1 - n_x ) > 0 ) { - n_distance -= ( m_n_drawarea_x1 - n_x ); - n_x = m_n_drawarea_x1; + n_distance -= ( p_psxgpu->n_drawarea_x1 - n_x ); + n_x = p_psxgpu->n_drawarea_x1; } SOLIDFILL( FLATRECTANGEUPDATE ) } @@ -2742,7 +2752,7 @@ static void FlatRectangle8x8( running_machine *machine ) } } -static void FlatRectangle16x16( running_machine *machine ) +static void FlatRectangle16x16( psx_gpu *p_psxgpu ) { INT16 n_y; INT16 n_x; @@ -2766,39 +2776,39 @@ static void FlatRectangle16x16( running_machine *machine ) UINT16 *p_vram; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 10 ) + if( p_psxgpu->m_debug.n_skip == 10 ) { return; } - DebugMesh( COORD_X( m_packet.FlatRectangle16x16.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.FlatRectangle16x16.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.FlatRectangle16x16.n_coord ) + m_n_drawoffset_x + 16, COORD_Y( m_packet.FlatRectangle16x16.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.FlatRectangle16x16.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.FlatRectangle16x16.n_coord ) + m_n_drawoffset_y + 16 ); - DebugMesh( COORD_X( m_packet.FlatRectangle16x16.n_coord ) + m_n_drawoffset_x + 16, COORD_Y( m_packet.FlatRectangle16x16.n_coord ) + m_n_drawoffset_y + 16 ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle16x16.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.FlatRectangle16x16.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle16x16.n_coord ) + p_psxgpu->n_drawoffset_x + 16, COORD_Y( p_psxgpu->m_packet.FlatRectangle16x16.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle16x16.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.FlatRectangle16x16.n_coord ) + p_psxgpu->n_drawoffset_y + 16 ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatRectangle16x16.n_coord ) + p_psxgpu->n_drawoffset_x + 16, COORD_Y( p_psxgpu->m_packet.FlatRectangle16x16.n_coord ) + p_psxgpu->n_drawoffset_y + 16 ); + DebugMeshEnd(p_psxgpu); #endif - n_cmd = BGR_C( m_packet.FlatRectangle16x16.n_bgr ); + n_cmd = BGR_C( p_psxgpu->m_packet.FlatRectangle16x16.n_bgr ); SOLIDSETUP - n_r.w.h = BGR_R( m_packet.FlatRectangle16x16.n_bgr ); n_r.w.l = 0; - n_g.w.h = BGR_G( m_packet.FlatRectangle16x16.n_bgr ); n_g.w.l = 0; - n_b.w.h = BGR_B( m_packet.FlatRectangle16x16.n_bgr ); n_b.w.l = 0; + n_r.w.h = BGR_R( p_psxgpu->m_packet.FlatRectangle16x16.n_bgr ); n_r.w.l = 0; + n_g.w.h = BGR_G( p_psxgpu->m_packet.FlatRectangle16x16.n_bgr ); n_g.w.l = 0; + n_b.w.h = BGR_B( p_psxgpu->m_packet.FlatRectangle16x16.n_bgr ); n_b.w.l = 0; - n_y = COORD_Y( m_packet.FlatRectangle16x16.n_coord ) + m_n_drawoffset_y; + n_y = COORD_Y( p_psxgpu->m_packet.FlatRectangle16x16.n_coord ) + p_psxgpu->n_drawoffset_y; n_h = 16; while( n_h > 0 ) { - n_x = COORD_X( m_packet.FlatRectangle16x16.n_coord ) + m_n_drawoffset_x; + n_x = COORD_X( p_psxgpu->m_packet.FlatRectangle16x16.n_coord ) + p_psxgpu->n_drawoffset_x; n_distance = 16; - if( n_distance > 0 && n_y >= (INT32)m_n_drawarea_y1 && n_y <= (INT32)m_n_drawarea_y2 ) + if( n_distance > 0 && n_y >= (INT32)p_psxgpu->n_drawarea_y1 && n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { - if( ( (INT32)m_n_drawarea_x1 - n_x ) > 0 ) + if( ( (INT32)p_psxgpu->n_drawarea_x1 - n_x ) > 0 ) { - n_distance -= ( m_n_drawarea_x1 - n_x ); - n_x = m_n_drawarea_x1; + n_distance -= ( p_psxgpu->n_drawarea_x1 - n_x ); + n_x = p_psxgpu->n_drawarea_x1; } SOLIDFILL( FLATRECTANGEUPDATE ) } @@ -2807,7 +2817,7 @@ static void FlatRectangle16x16( running_machine *machine ) } } -static void FlatTexturedRectangle( running_machine *machine ) +static void FlatTexturedRectangle( psx_gpu *p_psxgpu ) { INT16 n_y; INT16 n_x; @@ -2842,21 +2852,21 @@ static void FlatTexturedRectangle( running_machine *machine ) UINT16 n_bgr; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 11 ) + if( p_psxgpu->m_debug.n_skip == 11 ) { return; } - DebugMesh( COORD_X( m_packet.FlatTexturedRectangle.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.FlatTexturedRectangle.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.FlatTexturedRectangle.n_coord ) + m_n_drawoffset_x + SIZE_W( m_packet.FlatTexturedRectangle.n_size ), COORD_Y( m_packet.FlatTexturedRectangle.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.FlatTexturedRectangle.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.FlatTexturedRectangle.n_coord ) + m_n_drawoffset_y + SIZE_H( m_packet.FlatTexturedRectangle.n_size ) ); - DebugMesh( COORD_X( m_packet.FlatTexturedRectangle.n_coord ) + m_n_drawoffset_x + SIZE_W( m_packet.FlatTexturedRectangle.n_size ), COORD_Y( m_packet.FlatTexturedRectangle.n_coord ) + m_n_drawoffset_y + SIZE_H( m_packet.FlatTexturedRectangle.n_size ) ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatTexturedRectangle.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.FlatTexturedRectangle.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatTexturedRectangle.n_coord ) + p_psxgpu->n_drawoffset_x + SIZE_W( p_psxgpu->m_packet.FlatTexturedRectangle.n_size ), COORD_Y( p_psxgpu->m_packet.FlatTexturedRectangle.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatTexturedRectangle.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.FlatTexturedRectangle.n_coord ) + p_psxgpu->n_drawoffset_y + SIZE_H( p_psxgpu->m_packet.FlatTexturedRectangle.n_size ) ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.FlatTexturedRectangle.n_coord ) + p_psxgpu->n_drawoffset_x + SIZE_W( p_psxgpu->m_packet.FlatTexturedRectangle.n_size ), COORD_Y( p_psxgpu->m_packet.FlatTexturedRectangle.n_coord ) + p_psxgpu->n_drawoffset_y + SIZE_H( p_psxgpu->m_packet.FlatTexturedRectangle.n_size ) ); + DebugMeshEnd(p_psxgpu); #endif - n_cmd = BGR_C( m_packet.FlatTexturedRectangle.n_bgr ); + n_cmd = BGR_C( p_psxgpu->m_packet.FlatTexturedRectangle.n_bgr ); - n_clutx = ( m_packet.FlatTexturedRectangle.n_texture.w.h & 0x3f ) << 4; - n_cluty = ( m_packet.FlatTexturedRectangle.n_texture.w.h >> 6 ) & 0x3ff; + n_clutx = ( p_psxgpu->m_packet.FlatTexturedRectangle.n_texture.w.h & 0x3f ) << 4; + n_cluty = ( p_psxgpu->m_packet.FlatTexturedRectangle.n_texture.w.h >> 6 ) & 0x3ff; n_r.d = 0; n_g.d = 0; @@ -2868,9 +2878,9 @@ static void FlatTexturedRectangle( running_machine *machine ) switch( n_cmd & 0x01 ) { case 0: - n_r.w.h = BGR_R( m_packet.FlatTexturedRectangle.n_bgr ); n_r.w.l = 0; - n_g.w.h = BGR_G( m_packet.FlatTexturedRectangle.n_bgr ); n_g.w.l = 0; - n_b.w.h = BGR_B( m_packet.FlatTexturedRectangle.n_bgr ); n_b.w.l = 0; + n_r.w.h = BGR_R( p_psxgpu->m_packet.FlatTexturedRectangle.n_bgr ); n_r.w.l = 0; + n_g.w.h = BGR_G( p_psxgpu->m_packet.FlatTexturedRectangle.n_bgr ); n_g.w.l = 0; + n_b.w.h = BGR_B( p_psxgpu->m_packet.FlatTexturedRectangle.n_bgr ); n_b.w.l = 0; break; case 1: n_r.w.h = 0x80; n_r.w.l = 0; @@ -2879,23 +2889,23 @@ static void FlatTexturedRectangle( running_machine *machine ) break; } - n_v = TEXTURE_V( m_packet.FlatTexturedRectangle.n_texture ); - n_y = COORD_Y( m_packet.FlatTexturedRectangle.n_coord ) + m_n_drawoffset_y; - n_h = SIZE_H( m_packet.FlatTexturedRectangle.n_size ); + n_v = TEXTURE_V( p_psxgpu->m_packet.FlatTexturedRectangle.n_texture ); + n_y = COORD_Y( p_psxgpu->m_packet.FlatTexturedRectangle.n_coord ) + p_psxgpu->n_drawoffset_y; + n_h = SIZE_H( p_psxgpu->m_packet.FlatTexturedRectangle.n_size ); while( n_h > 0 ) { - n_x = COORD_X( m_packet.FlatTexturedRectangle.n_coord ) + m_n_drawoffset_x; - n_u = TEXTURE_U( m_packet.FlatTexturedRectangle.n_texture ); + n_x = COORD_X( p_psxgpu->m_packet.FlatTexturedRectangle.n_coord ) + p_psxgpu->n_drawoffset_x; + n_u = TEXTURE_U( p_psxgpu->m_packet.FlatTexturedRectangle.n_texture ); - n_distance = SIZE_W( m_packet.FlatTexturedRectangle.n_size ); - if( n_distance > 0 && n_y >= (INT32)m_n_drawarea_y1 && n_y <= (INT32)m_n_drawarea_y2 ) + n_distance = SIZE_W( p_psxgpu->m_packet.FlatTexturedRectangle.n_size ); + if( n_distance > 0 && n_y >= (INT32)p_psxgpu->n_drawarea_y1 && n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { - if( ( (INT32)m_n_drawarea_x1 - n_x ) > 0 ) + if( ( (INT32)p_psxgpu->n_drawarea_x1 - n_x ) > 0 ) { - n_u += ( m_n_drawarea_x1 - n_x ) * n_du; - n_distance -= ( m_n_drawarea_x1 - n_x ); - n_x = m_n_drawarea_x1; + n_u += ( p_psxgpu->n_drawarea_x1 - n_x ) * n_du; + n_distance -= ( p_psxgpu->n_drawarea_x1 - n_x ); + n_x = p_psxgpu->n_drawarea_x1; } TEXTUREFILL( FLATTEXTUREDRECTANGLEUPDATE, n_u, n_v ); } @@ -2905,7 +2915,7 @@ static void FlatTexturedRectangle( running_machine *machine ) } } -static void Sprite8x8( running_machine *machine ) +static void Sprite8x8( psx_gpu *p_psxgpu ) { INT16 n_y; INT16 n_x; @@ -2940,21 +2950,21 @@ static void Sprite8x8( running_machine *machine ) UINT16 n_bgr; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 12 ) + if( p_psxgpu->m_debug.n_skip == 12 ) { return; } - DebugMesh( COORD_X( m_packet.Sprite8x8.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.Sprite8x8.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.Sprite8x8.n_coord ) + m_n_drawoffset_x + 7, COORD_Y( m_packet.Sprite8x8.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.Sprite8x8.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.Sprite8x8.n_coord ) + m_n_drawoffset_y + 7 ); - DebugMesh( COORD_X( m_packet.Sprite8x8.n_coord ) + m_n_drawoffset_x + 7, COORD_Y( m_packet.Sprite8x8.n_coord ) + m_n_drawoffset_y + 7 ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.Sprite8x8.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.Sprite8x8.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.Sprite8x8.n_coord ) + p_psxgpu->n_drawoffset_x + 7, COORD_Y( p_psxgpu->m_packet.Sprite8x8.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.Sprite8x8.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.Sprite8x8.n_coord ) + p_psxgpu->n_drawoffset_y + 7 ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.Sprite8x8.n_coord ) + p_psxgpu->n_drawoffset_x + 7, COORD_Y( p_psxgpu->m_packet.Sprite8x8.n_coord ) + p_psxgpu->n_drawoffset_y + 7 ); + DebugMeshEnd(p_psxgpu); #endif - n_cmd = BGR_C( m_packet.Sprite8x8.n_bgr ); + n_cmd = BGR_C( p_psxgpu->m_packet.Sprite8x8.n_bgr ); - n_clutx = ( m_packet.Sprite8x8.n_texture.w.h & 0x3f ) << 4; - n_cluty = ( m_packet.Sprite8x8.n_texture.w.h >> 6 ) & 0x3ff; + n_clutx = ( p_psxgpu->m_packet.Sprite8x8.n_texture.w.h & 0x3f ) << 4; + n_cluty = ( p_psxgpu->m_packet.Sprite8x8.n_texture.w.h >> 6 ) & 0x3ff; n_r.d = 0; n_g.d = 0; @@ -2966,9 +2976,9 @@ static void Sprite8x8( running_machine *machine ) switch( n_cmd & 0x01 ) { case 0: - n_r.w.h = BGR_R( m_packet.Sprite8x8.n_bgr ); n_r.w.l = 0; - n_g.w.h = BGR_G( m_packet.Sprite8x8.n_bgr ); n_g.w.l = 0; - n_b.w.h = BGR_B( m_packet.Sprite8x8.n_bgr ); n_b.w.l = 0; + n_r.w.h = BGR_R( p_psxgpu->m_packet.Sprite8x8.n_bgr ); n_r.w.l = 0; + n_g.w.h = BGR_G( p_psxgpu->m_packet.Sprite8x8.n_bgr ); n_g.w.l = 0; + n_b.w.h = BGR_B( p_psxgpu->m_packet.Sprite8x8.n_bgr ); n_b.w.l = 0; break; case 1: n_r.w.h = 0x80; n_r.w.l = 0; @@ -2977,23 +2987,23 @@ static void Sprite8x8( running_machine *machine ) break; } - n_v = TEXTURE_V( m_packet.Sprite8x8.n_texture ); - n_y = COORD_Y( m_packet.Sprite8x8.n_coord ) + m_n_drawoffset_y; + n_v = TEXTURE_V( p_psxgpu->m_packet.Sprite8x8.n_texture ); + n_y = COORD_Y( p_psxgpu->m_packet.Sprite8x8.n_coord ) + p_psxgpu->n_drawoffset_y; n_h = 8; while( n_h > 0 ) { - n_x = COORD_X( m_packet.Sprite8x8.n_coord ) + m_n_drawoffset_x; - n_u = TEXTURE_U( m_packet.Sprite8x8.n_texture ); + n_x = COORD_X( p_psxgpu->m_packet.Sprite8x8.n_coord ) + p_psxgpu->n_drawoffset_x; + n_u = TEXTURE_U( p_psxgpu->m_packet.Sprite8x8.n_texture ); n_distance = 8; - if( n_distance > 0 && n_y >= (INT32)m_n_drawarea_y1 && n_y <= (INT32)m_n_drawarea_y2 ) + if( n_distance > 0 && n_y >= (INT32)p_psxgpu->n_drawarea_y1 && n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { - if( ( (INT32)m_n_drawarea_x1 - n_x ) > 0 ) + if( ( (INT32)p_psxgpu->n_drawarea_x1 - n_x ) > 0 ) { - n_u += ( m_n_drawarea_x1 - n_x ) * n_du; - n_distance -= ( m_n_drawarea_x1 - n_x ); - n_x = m_n_drawarea_x1; + n_u += ( p_psxgpu->n_drawarea_x1 - n_x ) * n_du; + n_distance -= ( p_psxgpu->n_drawarea_x1 - n_x ); + n_x = p_psxgpu->n_drawarea_x1; } TEXTUREFILL( FLATTEXTUREDRECTANGLEUPDATE, n_u, n_v ); } @@ -3003,7 +3013,7 @@ static void Sprite8x8( running_machine *machine ) } } -static void Sprite16x16( running_machine *machine ) +static void Sprite16x16( psx_gpu *p_psxgpu ) { INT16 n_y; INT16 n_x; @@ -3038,21 +3048,21 @@ static void Sprite16x16( running_machine *machine ) UINT16 n_bgr; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 13 ) + if( p_psxgpu->m_debug.n_skip == 13 ) { return; } - DebugMesh( COORD_X( m_packet.Sprite16x16.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.Sprite16x16.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.Sprite16x16.n_coord ) + m_n_drawoffset_x + 7, COORD_Y( m_packet.Sprite16x16.n_coord ) + m_n_drawoffset_y ); - DebugMesh( COORD_X( m_packet.Sprite16x16.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.Sprite16x16.n_coord ) + m_n_drawoffset_y + 7 ); - DebugMesh( COORD_X( m_packet.Sprite16x16.n_coord ) + m_n_drawoffset_x + 7, COORD_Y( m_packet.Sprite16x16.n_coord ) + m_n_drawoffset_y + 7 ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.Sprite16x16.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.Sprite16x16.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.Sprite16x16.n_coord ) + p_psxgpu->n_drawoffset_x + 7, COORD_Y( p_psxgpu->m_packet.Sprite16x16.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.Sprite16x16.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.Sprite16x16.n_coord ) + p_psxgpu->n_drawoffset_y + 7 ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.Sprite16x16.n_coord ) + p_psxgpu->n_drawoffset_x + 7, COORD_Y( p_psxgpu->m_packet.Sprite16x16.n_coord ) + p_psxgpu->n_drawoffset_y + 7 ); + DebugMeshEnd(p_psxgpu); #endif - n_cmd = BGR_C( m_packet.Sprite16x16.n_bgr ); + n_cmd = BGR_C( p_psxgpu->m_packet.Sprite16x16.n_bgr ); - n_clutx = ( m_packet.Sprite16x16.n_texture.w.h & 0x3f ) << 4; - n_cluty = ( m_packet.Sprite16x16.n_texture.w.h >> 6 ) & 0x3ff; + n_clutx = ( p_psxgpu->m_packet.Sprite16x16.n_texture.w.h & 0x3f ) << 4; + n_cluty = ( p_psxgpu->m_packet.Sprite16x16.n_texture.w.h >> 6 ) & 0x3ff; n_r.d = 0; n_g.d = 0; @@ -3064,9 +3074,9 @@ static void Sprite16x16( running_machine *machine ) switch( n_cmd & 0x01 ) { case 0: - n_r.w.h = BGR_R( m_packet.Sprite16x16.n_bgr ); n_r.w.l = 0; - n_g.w.h = BGR_G( m_packet.Sprite16x16.n_bgr ); n_g.w.l = 0; - n_b.w.h = BGR_B( m_packet.Sprite16x16.n_bgr ); n_b.w.l = 0; + n_r.w.h = BGR_R( p_psxgpu->m_packet.Sprite16x16.n_bgr ); n_r.w.l = 0; + n_g.w.h = BGR_G( p_psxgpu->m_packet.Sprite16x16.n_bgr ); n_g.w.l = 0; + n_b.w.h = BGR_B( p_psxgpu->m_packet.Sprite16x16.n_bgr ); n_b.w.l = 0; break; case 1: n_r.w.h = 0x80; n_r.w.l = 0; @@ -3075,23 +3085,23 @@ static void Sprite16x16( running_machine *machine ) break; } - n_v = TEXTURE_V( m_packet.Sprite16x16.n_texture ); - n_y = COORD_Y( m_packet.Sprite16x16.n_coord ) + m_n_drawoffset_y; + n_v = TEXTURE_V( p_psxgpu->m_packet.Sprite16x16.n_texture ); + n_y = COORD_Y( p_psxgpu->m_packet.Sprite16x16.n_coord ) + p_psxgpu->n_drawoffset_y; n_h = 16; while( n_h > 0 ) { - n_x = COORD_X( m_packet.Sprite16x16.n_coord ) + m_n_drawoffset_x; - n_u = TEXTURE_U( m_packet.Sprite16x16.n_texture ); + n_x = COORD_X( p_psxgpu->m_packet.Sprite16x16.n_coord ) + p_psxgpu->n_drawoffset_x; + n_u = TEXTURE_U( p_psxgpu->m_packet.Sprite16x16.n_texture ); n_distance = 16; - if( n_distance > 0 && n_y >= (INT32)m_n_drawarea_y1 && n_y <= (INT32)m_n_drawarea_y2 ) + if( n_distance > 0 && n_y >= (INT32)p_psxgpu->n_drawarea_y1 && n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { - if( ( (INT32)m_n_drawarea_x1 - n_x ) > 0 ) + if( ( (INT32)p_psxgpu->n_drawarea_x1 - n_x ) > 0 ) { - n_u += ( m_n_drawarea_x1 - n_x ) * n_du; - n_distance -= ( m_n_drawarea_x1 - n_x ); - n_x = m_n_drawarea_x1; + n_u += ( p_psxgpu->n_drawarea_x1 - n_x ) * n_du; + n_distance -= ( p_psxgpu->n_drawarea_x1 - n_x ); + n_x = p_psxgpu->n_drawarea_x1; } TEXTUREFILL( FLATTEXTUREDRECTANGLEUPDATE, n_u, n_v ); } @@ -3101,7 +3111,7 @@ static void Sprite16x16( running_machine *machine ) } } -static void Dot( void ) +static void Dot( psx_gpu *p_psxgpu ) { INT32 n_x; INT32 n_y; @@ -3111,34 +3121,34 @@ static void Dot( void ) UINT16 *p_vram; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 14 ) + if( p_psxgpu->m_debug.n_skip == 14 ) { return; } - DebugMesh( COORD_X( m_packet.Dot.vertex.n_coord ) + m_n_drawoffset_x, COORD_Y( m_packet.Dot.vertex.n_coord ) + m_n_drawoffset_y ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.Dot.vertex.n_coord ) + p_psxgpu->n_drawoffset_x, COORD_Y( p_psxgpu->m_packet.Dot.vertex.n_coord ) + p_psxgpu->n_drawoffset_y ); + DebugMeshEnd(p_psxgpu); #endif - n_r = BGR_R( m_packet.Dot.n_bgr ); - n_g = BGR_G( m_packet.Dot.n_bgr ); - n_b = BGR_B( m_packet.Dot.n_bgr ); - n_x = COORD_X( m_packet.Dot.vertex.n_coord ) + m_n_drawoffset_x; - n_y = COORD_Y( m_packet.Dot.vertex.n_coord ) + m_n_drawoffset_y; + n_r = BGR_R( p_psxgpu->m_packet.Dot.n_bgr ); + n_g = BGR_G( p_psxgpu->m_packet.Dot.n_bgr ); + n_b = BGR_B( p_psxgpu->m_packet.Dot.n_bgr ); + n_x = COORD_X( p_psxgpu->m_packet.Dot.vertex.n_coord ) + p_psxgpu->n_drawoffset_x; + n_y = COORD_Y( p_psxgpu->m_packet.Dot.vertex.n_coord ) + p_psxgpu->n_drawoffset_y; - if( (INT16)n_x >= (INT32)m_n_drawarea_x1 && - (INT16)n_y >= (INT32)m_n_drawarea_y1 && - (INT16)n_x <= (INT32)m_n_drawarea_x2 && - (INT16)n_y <= (INT32)m_n_drawarea_y2 ) + if( (INT16)n_x >= (INT32)p_psxgpu->n_drawarea_x1 && + (INT16)n_y >= (INT32)p_psxgpu->n_drawarea_y1 && + (INT16)n_x <= (INT32)p_psxgpu->n_drawarea_x2 && + (INT16)n_y <= (INT32)p_psxgpu->n_drawarea_y2 ) { - p_vram = m_p_p_vram[ n_y ] + n_x; + p_vram = p_psxgpu->p_p_vram[ n_y ] + n_x; WRITE_PIXEL( - m_p_n_redshade[ MID_LEVEL | n_r ] | - m_p_n_greenshade[ MID_LEVEL | n_g ] | - m_p_n_blueshade[ MID_LEVEL | n_b ] ); + p_psxgpu->p_n_redshade[ MID_LEVEL | n_r ] | + p_psxgpu->p_n_greenshade[ MID_LEVEL | n_g ] | + p_psxgpu->p_n_blueshade[ MID_LEVEL | n_b ] ); } } -static void MoveImage( void ) +static void MoveImage( psx_gpu *p_psxgpu ) { INT16 n_w; INT16 n_h; @@ -3149,30 +3159,30 @@ static void MoveImage( void ) UINT16 *p_vram; #if defined( MAME_DEBUG ) - if( m_debug.n_skip == 15 ) + if( p_psxgpu->m_debug.n_skip == 15 ) { return; } - DebugMesh( COORD_X( m_packet.MoveImage.vertex[ 1 ].n_coord ), COORD_Y( m_packet.MoveImage.vertex[ 1 ].n_coord ) ); - DebugMesh( COORD_X( m_packet.MoveImage.vertex[ 1 ].n_coord ) + SIZE_W( m_packet.MoveImage.n_size ), COORD_Y( m_packet.MoveImage.vertex[ 1 ].n_coord ) ); - DebugMesh( COORD_X( m_packet.MoveImage.vertex[ 1 ].n_coord ), COORD_Y( m_packet.MoveImage.vertex[ 1 ].n_coord ) + SIZE_H( m_packet.MoveImage.n_size ) ); - DebugMesh( COORD_X( m_packet.MoveImage.vertex[ 1 ].n_coord ) + SIZE_W( m_packet.MoveImage.n_size ), COORD_Y( m_packet.MoveImage.vertex[ 1 ].n_coord ) + SIZE_H( m_packet.MoveImage.n_size ) ); - DebugMeshEnd(); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.MoveImage.vertex[ 1 ].n_coord ), COORD_Y( p_psxgpu->m_packet.MoveImage.vertex[ 1 ].n_coord ) ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.MoveImage.vertex[ 1 ].n_coord ) + SIZE_W( p_psxgpu->m_packet.MoveImage.n_size ), COORD_Y( p_psxgpu->m_packet.MoveImage.vertex[ 1 ].n_coord ) ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.MoveImage.vertex[ 1 ].n_coord ), COORD_Y( p_psxgpu->m_packet.MoveImage.vertex[ 1 ].n_coord ) + SIZE_H( p_psxgpu->m_packet.MoveImage.n_size ) ); + DebugMesh( p_psxgpu, COORD_X( p_psxgpu->m_packet.MoveImage.vertex[ 1 ].n_coord ) + SIZE_W( p_psxgpu->m_packet.MoveImage.n_size ), COORD_Y( p_psxgpu->m_packet.MoveImage.vertex[ 1 ].n_coord ) + SIZE_H( p_psxgpu->m_packet.MoveImage.n_size ) ); + DebugMeshEnd(p_psxgpu); #endif - n_srcy = COORD_Y( m_packet.MoveImage.vertex[ 0 ].n_coord ); - n_dsty = COORD_Y( m_packet.MoveImage.vertex[ 1 ].n_coord ); - n_h = SIZE_H( m_packet.MoveImage.n_size ); + n_srcy = COORD_Y( p_psxgpu->m_packet.MoveImage.vertex[ 0 ].n_coord ); + n_dsty = COORD_Y( p_psxgpu->m_packet.MoveImage.vertex[ 1 ].n_coord ); + n_h = SIZE_H( p_psxgpu->m_packet.MoveImage.n_size ); while( n_h > 0 ) { - n_srcx = COORD_X( m_packet.MoveImage.vertex[ 0 ].n_coord ); - n_dstx = COORD_X( m_packet.MoveImage.vertex[ 1 ].n_coord ); - n_w = SIZE_W( m_packet.MoveImage.n_size ); + n_srcx = COORD_X( p_psxgpu->m_packet.MoveImage.vertex[ 0 ].n_coord ); + n_dstx = COORD_X( p_psxgpu->m_packet.MoveImage.vertex[ 1 ].n_coord ); + n_w = SIZE_W( p_psxgpu->m_packet.MoveImage.n_size ); while( n_w > 0 ) { - p_vram = m_p_p_vram[ n_dsty & 1023 ] + ( n_dstx & 1023 ); - WRITE_PIXEL( *( m_p_p_vram[ n_srcy & 1023 ] + ( n_srcx & 1023 ) ) ); + p_vram = p_psxgpu->p_p_vram[ n_dsty & 1023 ] + ( n_dstx & 1023 ); + WRITE_PIXEL( *( p_psxgpu->p_p_vram[ n_srcy & 1023 ] + ( n_srcx & 1023 ) ) ); n_srcx++; n_dstx++; n_w--; @@ -3185,229 +3195,231 @@ static void MoveImage( void ) void psx_gpu_write( running_machine *machine, UINT32 *p_ram, INT32 n_size ) { + psx_gpu *p_psxgpu = machine->driver_data()->p_psxgpu; + while( n_size > 0 ) { UINT32 data = *( p_ram ); - verboselog( machine, 2, "PSX Packet #%u %08x\n", m_n_gpu_buffer_offset, data ); - m_packet.n_entry[ m_n_gpu_buffer_offset ] = data; - switch( m_packet.n_entry[ 0 ] >> 24 ) + verboselog( p_psxgpu, 2, "PSX Packet #%u %08x\n", p_psxgpu->n_gpu_buffer_offset, data ); + p_psxgpu->m_packet.n_entry[ p_psxgpu->n_gpu_buffer_offset ] = data; + switch( p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ) { case 0x00: - verboselog( machine, 1, "not handled: GPU Command 0x00: (%08x)\n", data ); + verboselog( p_psxgpu, 1, "not handled: GPU Command 0x00: (%08x)\n", data ); break; case 0x01: - verboselog( machine, 1, "not handled: clear cache\n" ); + verboselog( p_psxgpu, 1, "not handled: clear cache\n" ); break; case 0x02: - if( m_n_gpu_buffer_offset < 2 ) + if( p_psxgpu->n_gpu_buffer_offset < 2 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: frame buffer rectangle %u,%u %u,%u\n", m_packet.n_entry[ 0 ] >> 24, - m_packet.n_entry[ 1 ] & 0xffff, m_packet.n_entry[ 1 ] >> 16, m_packet.n_entry[ 2 ] & 0xffff, m_packet.n_entry[ 2 ] >> 16 ); - FrameBufferRectangleDraw(); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: frame buffer rectangle %u,%u %u,%u\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->m_packet.n_entry[ 1 ] & 0xffff, p_psxgpu->m_packet.n_entry[ 1 ] >> 16, p_psxgpu->m_packet.n_entry[ 2 ] & 0xffff, p_psxgpu->m_packet.n_entry[ 2 ] >> 16 ); + FrameBufferRectangleDraw( p_psxgpu ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x20: case 0x21: case 0x22: case 0x23: - if( m_n_gpu_buffer_offset < 3 ) + if( p_psxgpu->n_gpu_buffer_offset < 3 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: monochrome 3 point polygon\n", m_packet.n_entry[ 0 ] >> 24 ); - FlatPolygon( machine, 3 ); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: monochrome 3 point polygon\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + FlatPolygon( p_psxgpu, 3 ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x24: case 0x25: case 0x26: case 0x27: - if( m_n_gpu_buffer_offset < 6 ) + if( p_psxgpu->n_gpu_buffer_offset < 6 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: textured 3 point polygon\n", m_packet.n_entry[ 0 ] >> 24 ); - FlatTexturedPolygon( machine, 3 ); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: textured 3 point polygon\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + FlatTexturedPolygon( p_psxgpu, 3 ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x28: case 0x29: case 0x2a: case 0x2b: - if( m_n_gpu_buffer_offset < 4 ) + if( p_psxgpu->n_gpu_buffer_offset < 4 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: monochrome 4 point polygon\n", m_packet.n_entry[ 0 ] >> 24 ); - FlatPolygon( machine, 4 ); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: monochrome 4 point polygon\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + FlatPolygon( p_psxgpu, 4 ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x2c: case 0x2d: case 0x2e: case 0x2f: - if( m_n_gpu_buffer_offset < 8 ) + if( p_psxgpu->n_gpu_buffer_offset < 8 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: textured 4 point polygon\n", m_packet.n_entry[ 0 ] >> 24 ); - FlatTexturedPolygon( machine, 4 ); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: textured 4 point polygon\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + FlatTexturedPolygon( p_psxgpu, 4 ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x30: case 0x31: case 0x32: case 0x33: - if( m_n_gpu_buffer_offset < 5 ) + if( p_psxgpu->n_gpu_buffer_offset < 5 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: gouraud 3 point polygon\n", m_packet.n_entry[ 0 ] >> 24 ); - GouraudPolygon( machine, 3 ); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: gouraud 3 point polygon\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + GouraudPolygon( p_psxgpu, 3 ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x34: case 0x35: case 0x36: case 0x37: - if( m_n_gpu_buffer_offset < 8 ) + if( p_psxgpu->n_gpu_buffer_offset < 8 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: gouraud textured 3 point polygon\n", m_packet.n_entry[ 0 ] >> 24 ); - GouraudTexturedPolygon( machine, 3 ); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: gouraud textured 3 point polygon\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + GouraudTexturedPolygon( p_psxgpu, 3 ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x38: case 0x39: case 0x3a: case 0x3b: - if( m_n_gpu_buffer_offset < 7 ) + if( p_psxgpu->n_gpu_buffer_offset < 7 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: gouraud 4 point polygon\n", m_packet.n_entry[ 0 ] >> 24 ); - GouraudPolygon( machine, 4 ); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: gouraud 4 point polygon\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + GouraudPolygon( p_psxgpu, 4 ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x3c: case 0x3d: case 0x3e: case 0x3f: - if( m_n_gpu_buffer_offset < 11 ) + if( p_psxgpu->n_gpu_buffer_offset < 11 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: gouraud textured 4 point polygon\n", m_packet.n_entry[ 0 ] >> 24 ); - GouraudTexturedPolygon( machine, 4 ); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: gouraud textured 4 point polygon\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + GouraudTexturedPolygon( p_psxgpu, 4 ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x40: case 0x41: case 0x42: - if( m_n_gpu_buffer_offset < 2 ) + if( p_psxgpu->n_gpu_buffer_offset < 2 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: monochrome line\n", m_packet.n_entry[ 0 ] >> 24 ); - MonochromeLine(); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: monochrome line\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + MonochromeLine( p_psxgpu ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x48: case 0x4a: case 0x4c: case 0x4e: - if( m_n_gpu_buffer_offset < 3 ) + if( p_psxgpu->n_gpu_buffer_offset < 3 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: monochrome polyline\n", m_packet.n_entry[ 0 ] >> 24 ); - MonochromeLine(); - if( ( m_packet.n_entry[ 3 ] & 0xf000f000 ) != 0x50005000 ) + verboselog( p_psxgpu, 1, "%02x: monochrome polyline\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + MonochromeLine( p_psxgpu ); + if( ( p_psxgpu->m_packet.n_entry[ 3 ] & 0xf000f000 ) != 0x50005000 ) { - m_packet.n_entry[ 1 ] = m_packet.n_entry[ 2 ]; - m_packet.n_entry[ 2 ] = m_packet.n_entry[ 3 ]; - m_n_gpu_buffer_offset = 3; + p_psxgpu->m_packet.n_entry[ 1 ] = p_psxgpu->m_packet.n_entry[ 2 ]; + p_psxgpu->m_packet.n_entry[ 2 ] = p_psxgpu->m_packet.n_entry[ 3 ]; + p_psxgpu->n_gpu_buffer_offset = 3; } else { - m_n_gpu_buffer_offset = 0; + p_psxgpu->n_gpu_buffer_offset = 0; } } break; case 0x50: case 0x52: - if( m_n_gpu_buffer_offset < 3 ) + if( p_psxgpu->n_gpu_buffer_offset < 3 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: gouraud line\n", m_packet.n_entry[ 0 ] >> 24 ); - GouraudLine(); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: gouraud line\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + GouraudLine( p_psxgpu ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x58: case 0x5a: case 0x5c: case 0x5e: - if( m_n_gpu_buffer_offset < 5 && - ( m_n_gpu_buffer_offset != 4 || ( m_packet.n_entry[ 4 ] & 0xf000f000 ) != 0x50005000 ) ) + if( p_psxgpu->n_gpu_buffer_offset < 5 && + ( p_psxgpu->n_gpu_buffer_offset != 4 || ( p_psxgpu->m_packet.n_entry[ 4 ] & 0xf000f000 ) != 0x50005000 ) ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: gouraud polyline\n", m_packet.n_entry[ 0 ] >> 24 ); - GouraudLine(); - if( ( m_packet.n_entry[ 4 ] & 0xf000f000 ) != 0x50005000 ) + verboselog( p_psxgpu, 1, "%02x: gouraud polyline\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + GouraudLine( p_psxgpu ); + if( ( p_psxgpu->m_packet.n_entry[ 4 ] & 0xf000f000 ) != 0x50005000 ) { - m_packet.n_entry[ 0 ] = ( m_packet.n_entry[ 0 ] & 0xff000000 ) | ( m_packet.n_entry[ 2 ] & 0x00ffffff ); - m_packet.n_entry[ 1 ] = m_packet.n_entry[ 3 ]; - m_packet.n_entry[ 2 ] = m_packet.n_entry[ 4 ]; - m_packet.n_entry[ 3 ] = m_packet.n_entry[ 5 ]; - m_n_gpu_buffer_offset = 4; + p_psxgpu->m_packet.n_entry[ 0 ] = ( p_psxgpu->m_packet.n_entry[ 0 ] & 0xff000000 ) | ( p_psxgpu->m_packet.n_entry[ 2 ] & 0x00ffffff ); + p_psxgpu->m_packet.n_entry[ 1 ] = p_psxgpu->m_packet.n_entry[ 3 ]; + p_psxgpu->m_packet.n_entry[ 2 ] = p_psxgpu->m_packet.n_entry[ 4 ]; + p_psxgpu->m_packet.n_entry[ 3 ] = p_psxgpu->m_packet.n_entry[ 5 ]; + p_psxgpu->n_gpu_buffer_offset = 4; } else { - m_n_gpu_buffer_offset = 0; + p_psxgpu->n_gpu_buffer_offset = 0; } } break; @@ -3415,133 +3427,133 @@ void psx_gpu_write( running_machine *machine, UINT32 *p_ram, INT32 n_size ) case 0x61: case 0x62: case 0x63: - if( m_n_gpu_buffer_offset < 2 ) + if( p_psxgpu->n_gpu_buffer_offset < 2 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: rectangle %d,%d %d,%d\n", - m_packet.n_entry[ 0 ] >> 24, - (INT16)( m_packet.n_entry[ 1 ] & 0xffff ), (INT16)( m_packet.n_entry[ 1 ] >> 16 ), - (INT16)( m_packet.n_entry[ 2 ] & 0xffff ), (INT16)( m_packet.n_entry[ 2 ] >> 16 ) ); - FlatRectangle(machine); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: rectangle %d,%d %d,%d\n", + p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + (INT16)( p_psxgpu->m_packet.n_entry[ 1 ] & 0xffff ), (INT16)( p_psxgpu->m_packet.n_entry[ 1 ] >> 16 ), + (INT16)( p_psxgpu->m_packet.n_entry[ 2 ] & 0xffff ), (INT16)( p_psxgpu->m_packet.n_entry[ 2 ] >> 16 ) ); + FlatRectangle(p_psxgpu); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x64: case 0x65: case 0x66: case 0x67: - if( m_n_gpu_buffer_offset < 3 ) + if( p_psxgpu->n_gpu_buffer_offset < 3 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: sprite %d,%d %u,%u %08x, %08x\n", - m_packet.n_entry[ 0 ] >> 24, - (INT16)( m_packet.n_entry[ 1 ] & 0xffff ), (INT16)( m_packet.n_entry[ 1 ] >> 16 ), - m_packet.n_entry[ 3 ] & 0xffff, m_packet.n_entry[ 3 ] >> 16, - m_packet.n_entry[ 0 ], m_packet.n_entry[ 2 ] ); - FlatTexturedRectangle(machine); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: sprite %d,%d %u,%u %08x, %08x\n", + p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + (INT16)( p_psxgpu->m_packet.n_entry[ 1 ] & 0xffff ), (INT16)( p_psxgpu->m_packet.n_entry[ 1 ] >> 16 ), + p_psxgpu->m_packet.n_entry[ 3 ] & 0xffff, p_psxgpu->m_packet.n_entry[ 3 ] >> 16, + p_psxgpu->m_packet.n_entry[ 0 ], p_psxgpu->m_packet.n_entry[ 2 ] ); + FlatTexturedRectangle(p_psxgpu); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x68: case 0x6a: - if( m_n_gpu_buffer_offset < 1 ) + if( p_psxgpu->n_gpu_buffer_offset < 1 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: dot %d,%d %08x\n", - m_packet.n_entry[ 0 ] >> 24, - (INT16)( m_packet.n_entry[ 1 ] & 0xffff ), (INT16)( m_packet.n_entry[ 1 ] >> 16 ), - m_packet.n_entry[ 0 ] & 0xffffff ); - Dot(); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: dot %d,%d %08x\n", + p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + (INT16)( p_psxgpu->m_packet.n_entry[ 1 ] & 0xffff ), (INT16)( p_psxgpu->m_packet.n_entry[ 1 ] >> 16 ), + p_psxgpu->m_packet.n_entry[ 0 ] & 0xffffff ); + Dot( p_psxgpu ); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x70: case 0x71: /* 8*8 rectangle */ - if( m_n_gpu_buffer_offset < 1 ) + if( p_psxgpu->n_gpu_buffer_offset < 1 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: 16x16 rectangle %08x %08x\n", m_packet.n_entry[ 0 ] >> 24, - m_packet.n_entry[ 0 ], m_packet.n_entry[ 1 ] ); - FlatRectangle8x8(machine); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: 16x16 rectangle %08x %08x\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->m_packet.n_entry[ 0 ], p_psxgpu->m_packet.n_entry[ 1 ] ); + FlatRectangle8x8(p_psxgpu); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x74: case 0x75: case 0x76: case 0x77: - if( m_n_gpu_buffer_offset < 2 ) + if( p_psxgpu->n_gpu_buffer_offset < 2 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: 8x8 sprite %08x %08x %08x\n", m_packet.n_entry[ 0 ] >> 24, - m_packet.n_entry[ 0 ], m_packet.n_entry[ 1 ], m_packet.n_entry[ 2 ] ); - Sprite8x8(machine); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: 8x8 sprite %08x %08x %08x\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->m_packet.n_entry[ 0 ], p_psxgpu->m_packet.n_entry[ 1 ], p_psxgpu->m_packet.n_entry[ 2 ] ); + Sprite8x8(p_psxgpu); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x78: case 0x79: /* 16*16 rectangle */ - if( m_n_gpu_buffer_offset < 1 ) + if( p_psxgpu->n_gpu_buffer_offset < 1 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: 16x16 rectangle %08x %08x\n", m_packet.n_entry[ 0 ] >> 24, - m_packet.n_entry[ 0 ], m_packet.n_entry[ 1 ] ); - FlatRectangle16x16(machine); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: 16x16 rectangle %08x %08x\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->m_packet.n_entry[ 0 ], p_psxgpu->m_packet.n_entry[ 1 ] ); + FlatRectangle16x16(p_psxgpu); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x7c: case 0x7d: case 0x7e: case 0x7f: - if( m_n_gpu_buffer_offset < 2 ) + if( p_psxgpu->n_gpu_buffer_offset < 2 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: 16x16 sprite %08x %08x %08x\n", m_packet.n_entry[ 0 ] >> 24, - m_packet.n_entry[ 0 ], m_packet.n_entry[ 1 ], m_packet.n_entry[ 2 ] ); - Sprite16x16(machine); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "%02x: 16x16 sprite %08x %08x %08x\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->m_packet.n_entry[ 0 ], p_psxgpu->m_packet.n_entry[ 1 ], p_psxgpu->m_packet.n_entry[ 2 ] ); + Sprite16x16(p_psxgpu); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0x80: - if( m_n_gpu_buffer_offset < 3 ) + if( p_psxgpu->n_gpu_buffer_offset < 3 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "move image in frame buffer %08x %08x %08x %08x\n", m_packet.n_entry[ 0 ], m_packet.n_entry[ 1 ], m_packet.n_entry[ 2 ], m_packet.n_entry[ 3 ] ); - MoveImage(); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "move image in frame buffer %08x %08x %08x %08x\n", p_psxgpu->m_packet.n_entry[ 0 ], p_psxgpu->m_packet.n_entry[ 1 ], p_psxgpu->m_packet.n_entry[ 2 ], p_psxgpu->m_packet.n_entry[ 3 ] ); + MoveImage(p_psxgpu); + p_psxgpu->n_gpu_buffer_offset = 0; } break; case 0xa0: - if( m_n_gpu_buffer_offset < 3 ) + if( p_psxgpu->n_gpu_buffer_offset < 3 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { @@ -3550,26 +3562,26 @@ void psx_gpu_write( running_machine *machine, UINT32 *p_ram, INT32 n_size ) { UINT16 *p_vram; - verboselog( machine, 2, "send image to framebuffer ( pixel %u,%u = %u )\n", - ( m_n_vramx + m_packet.n_entry[ 1 ] ) & 1023, - ( m_n_vramy + ( m_packet.n_entry[ 1 ] >> 16 ) ) & 1023, + verboselog( p_psxgpu, 2, "send image to framebuffer ( pixel %u,%u = %u )\n", + ( p_psxgpu->n_vramx + p_psxgpu->m_packet.n_entry[ 1 ] ) & 1023, + ( p_psxgpu->n_vramy + ( p_psxgpu->m_packet.n_entry[ 1 ] >> 16 ) ) & 1023, data & 0xffff ); - p_vram = m_p_p_vram[ ( m_n_vramy + ( m_packet.n_entry[ 1 ] >> 16 ) ) & 1023 ] + ( ( m_n_vramx + m_packet.n_entry[ 1 ] ) & 1023 ); + p_vram = p_psxgpu->p_p_vram[ ( p_psxgpu->n_vramy + ( p_psxgpu->m_packet.n_entry[ 1 ] >> 16 ) ) & 1023 ] + ( ( p_psxgpu->n_vramx + p_psxgpu->m_packet.n_entry[ 1 ] ) & 1023 ); WRITE_PIXEL( data & 0xffff ); - m_n_vramx++; - if( m_n_vramx >= ( m_packet.n_entry[ 2 ] & 0xffff ) ) + p_psxgpu->n_vramx++; + if( p_psxgpu->n_vramx >= ( p_psxgpu->m_packet.n_entry[ 2 ] & 0xffff ) ) { - m_n_vramx = 0; - m_n_vramy++; - if( m_n_vramy >= ( m_packet.n_entry[ 2 ] >> 16 ) ) + p_psxgpu->n_vramx = 0; + p_psxgpu->n_vramy++; + if( p_psxgpu->n_vramy >= ( p_psxgpu->m_packet.n_entry[ 2 ] >> 16 ) ) { - verboselog( machine, 1, "%02x: send image to framebuffer %u,%u %u,%u\n", m_packet.n_entry[ 0 ] >> 24, - m_packet.n_entry[ 1 ] & 0xffff, ( m_packet.n_entry[ 1 ] >> 16 ), - m_packet.n_entry[ 2 ] & 0xffff, ( m_packet.n_entry[ 2 ] >> 16 ) ); - m_n_gpu_buffer_offset = 0; - m_n_vramx = 0; - m_n_vramy = 0; + verboselog( p_psxgpu, 1, "%02x: send image to framebuffer %u,%u %u,%u\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->m_packet.n_entry[ 1 ] & 0xffff, ( p_psxgpu->m_packet.n_entry[ 1 ] >> 16 ), + p_psxgpu->m_packet.n_entry[ 2 ] & 0xffff, ( p_psxgpu->m_packet.n_entry[ 2 ] >> 16 ) ); + p_psxgpu->n_gpu_buffer_offset = 0; + p_psxgpu->n_vramx = 0; + p_psxgpu->n_vramy = 0; break; } } @@ -3578,87 +3590,87 @@ void psx_gpu_write( running_machine *machine, UINT32 *p_ram, INT32 n_size ) } break; case 0xc0: - if( m_n_gpu_buffer_offset < 2 ) + if( p_psxgpu->n_gpu_buffer_offset < 2 ) { - m_n_gpu_buffer_offset++; + p_psxgpu->n_gpu_buffer_offset++; } else { - verboselog( machine, 1, "%02x: copy image from frame buffer\n", m_packet.n_entry[ 0 ] >> 24 ); - m_n_gpustatus |= ( 1L << 0x1b ); + verboselog( p_psxgpu, 1, "%02x: copy image from frame buffer\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24 ); + p_psxgpu->n_gpustatus |= ( 1L << 0x1b ); } break; case 0xe1: - verboselog( machine, 1, "%02x: draw mode %06x\n", m_packet.n_entry[ 0 ] >> 24, - m_packet.n_entry[ 0 ] & 0xffffff ); - decode_tpage( machine, &psxgpu, m_packet.n_entry[ 0 ] & 0xffffff ); + verboselog( p_psxgpu, 1, "%02x: draw mode %06x\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->m_packet.n_entry[ 0 ] & 0xffffff ); + decode_tpage( p_psxgpu, p_psxgpu->m_packet.n_entry[ 0 ] & 0xffffff ); break; case 0xe2: - m_n_twy = ( ( ( m_packet.n_entry[ 0 ] >> 15 ) & 0x1f ) << 3 ); - m_n_twx = ( ( ( m_packet.n_entry[ 0 ] >> 10 ) & 0x1f ) << 3 ); - m_n_twh = 255 - ( ( ( m_packet.n_entry[ 0 ] >> 5 ) & 0x1f ) << 3 ); - m_n_tww = 255 - ( ( m_packet.n_entry[ 0 ] & 0x1f ) << 3 ); - verboselog( machine, 1, "%02x: texture window %u,%u %u,%u\n", m_packet.n_entry[ 0 ] >> 24, - m_n_twx, m_n_twy, m_n_tww, m_n_twh ); + p_psxgpu->n_twy = ( ( ( p_psxgpu->m_packet.n_entry[ 0 ] >> 15 ) & 0x1f ) << 3 ); + p_psxgpu->n_twx = ( ( ( p_psxgpu->m_packet.n_entry[ 0 ] >> 10 ) & 0x1f ) << 3 ); + p_psxgpu->n_twh = 255 - ( ( ( p_psxgpu->m_packet.n_entry[ 0 ] >> 5 ) & 0x1f ) << 3 ); + p_psxgpu->n_tww = 255 - ( ( p_psxgpu->m_packet.n_entry[ 0 ] & 0x1f ) << 3 ); + verboselog( p_psxgpu, 1, "%02x: texture window %u,%u %u,%u\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->n_twx, p_psxgpu->n_twy, p_psxgpu->n_tww, p_psxgpu->n_twh ); break; case 0xe3: - m_n_drawarea_x1 = m_packet.n_entry[ 0 ] & 1023; - if( m_n_gputype == 2 ) + p_psxgpu->n_drawarea_x1 = p_psxgpu->m_packet.n_entry[ 0 ] & 1023; + if( p_psxgpu->n_gputype == 2 ) { - m_n_drawarea_y1 = ( m_packet.n_entry[ 0 ] >> 10 ) & 1023; + p_psxgpu->n_drawarea_y1 = ( p_psxgpu->m_packet.n_entry[ 0 ] >> 10 ) & 1023; } else { - m_n_drawarea_y1 = ( m_packet.n_entry[ 0 ] >> 12 ) & 1023; + p_psxgpu->n_drawarea_y1 = ( p_psxgpu->m_packet.n_entry[ 0 ] >> 12 ) & 1023; } - verboselog( machine, 1, "%02x: drawing area top left %d,%d\n", m_packet.n_entry[ 0 ] >> 24, - m_n_drawarea_x1, m_n_drawarea_y1 ); + verboselog( p_psxgpu, 1, "%02x: drawing area top left %d,%d\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->n_drawarea_x1, p_psxgpu->n_drawarea_y1 ); break; case 0xe4: - m_n_drawarea_x2 = m_packet.n_entry[ 0 ] & 1023; - if( m_n_gputype == 2 ) + p_psxgpu->n_drawarea_x2 = p_psxgpu->m_packet.n_entry[ 0 ] & 1023; + if( p_psxgpu->n_gputype == 2 ) { - m_n_drawarea_y2 = ( m_packet.n_entry[ 0 ] >> 10 ) & 1023; + p_psxgpu->n_drawarea_y2 = ( p_psxgpu->m_packet.n_entry[ 0 ] >> 10 ) & 1023; } else { - m_n_drawarea_y2 = ( m_packet.n_entry[ 0 ] >> 12 ) & 1023; + p_psxgpu->n_drawarea_y2 = ( p_psxgpu->m_packet.n_entry[ 0 ] >> 12 ) & 1023; } - verboselog( machine, 1, "%02x: drawing area bottom right %d,%d\n", m_packet.n_entry[ 0 ] >> 24, - m_n_drawarea_x2, m_n_drawarea_y2 ); + verboselog( p_psxgpu, 1, "%02x: drawing area bottom right %d,%d\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->n_drawarea_x2, p_psxgpu->n_drawarea_y2 ); break; case 0xe5: - m_n_drawoffset_x = SINT11( m_packet.n_entry[ 0 ] & 2047 ); - if( m_n_gputype == 2 ) + p_psxgpu->n_drawoffset_x = SINT11( p_psxgpu->m_packet.n_entry[ 0 ] & 2047 ); + if( p_psxgpu->n_gputype == 2 ) { - m_n_drawoffset_y = SINT11( ( m_packet.n_entry[ 0 ] >> 11 ) & 2047 ); + p_psxgpu->n_drawoffset_y = SINT11( ( p_psxgpu->m_packet.n_entry[ 0 ] >> 11 ) & 2047 ); } else { - m_n_drawoffset_y = SINT11( ( m_packet.n_entry[ 0 ] >> 12 ) & 2047 ); + p_psxgpu->n_drawoffset_y = SINT11( ( p_psxgpu->m_packet.n_entry[ 0 ] >> 12 ) & 2047 ); } - verboselog( machine, 1, "%02x: drawing offset %d,%d\n", m_packet.n_entry[ 0 ] >> 24, - m_n_drawoffset_x, m_n_drawoffset_y ); + verboselog( p_psxgpu, 1, "%02x: drawing offset %d,%d\n", p_psxgpu->m_packet.n_entry[ 0 ] >> 24, + p_psxgpu->n_drawoffset_x, p_psxgpu->n_drawoffset_y ); break; case 0xe6: - m_n_gpustatus &= ~( 3L << 0xb ); - m_n_gpustatus |= ( data & 0x03 ) << 0xb; - if( ( m_packet.n_entry[ 0 ] & 3 ) != 0 ) + p_psxgpu->n_gpustatus &= ~( 3L << 0xb ); + p_psxgpu->n_gpustatus |= ( data & 0x03 ) << 0xb; + if( ( p_psxgpu->m_packet.n_entry[ 0 ] & 3 ) != 0 ) { - verboselog( machine, 1, "not handled: mask setting %d\n", m_packet.n_entry[ 0 ] & 3 ); + verboselog( p_psxgpu, 1, "not handled: mask setting %d\n", p_psxgpu->m_packet.n_entry[ 0 ] & 3 ); } else { - verboselog( machine, 1, "mask setting %d\n", m_packet.n_entry[ 0 ] & 3 ); + verboselog( p_psxgpu, 1, "mask setting %d\n", p_psxgpu->m_packet.n_entry[ 0 ] & 3 ); } break; default: #if defined( MAME_DEBUG ) - popmessage( "unknown GPU packet %08x", m_packet.n_entry[ 0 ] ); + popmessage( "unknown GPU packet %08x", p_psxgpu->m_packet.n_entry[ 0 ] ); #endif - verboselog( machine, 0, "unknown GPU packet %08x (%08x)\n", m_packet.n_entry[ 0 ], data ); + verboselog( p_psxgpu, 0, "unknown GPU packet %08x (%08x)\n", p_psxgpu->m_packet.n_entry[ 0 ], data ); #if ( STOP_ON_ERROR ) - m_n_gpu_buffer_offset = 1; + p_psxgpu->n_gpu_buffer_offset = 1; #endif break; } @@ -3669,165 +3681,165 @@ void psx_gpu_write( running_machine *machine, UINT32 *p_ram, INT32 n_size ) WRITE32_HANDLER( psx_gpu_w ) { - running_machine *machine = space->machine; + psx_gpu *p_psxgpu = space->machine->driver_data()->p_psxgpu; switch( offset ) { case 0x00: - psx_gpu_write( machine, &data, 1 ); + psx_gpu_write( space->machine, &data, 1 ); break; case 0x01: switch( data >> 24 ) { case 0x00: - verboselog( machine, 1, "reset gpu\n" ); - m_n_gpu_buffer_offset = 0; - m_n_gpustatus = 0x14802000; - m_n_drawarea_x1 = 0; - m_n_drawarea_y1 = 0; - m_n_drawarea_x2 = 1023; - m_n_drawarea_y2 = 1023; - m_n_drawoffset_x = 0; - m_n_drawoffset_y = 0; - m_n_displaystartx = 0; - m_n_displaystarty = 0; - m_n_horiz_disstart = 0x260; - m_n_horiz_disend = 0xc60; - m_n_vert_disstart = 0x010; - m_n_vert_disend = 0x100; - m_n_vramx = 0; - m_n_vramy = 0; - m_n_twx = 0; - m_n_twy = 0; - m_n_twh = 255; - m_n_tww = 255; + verboselog( p_psxgpu, 1, "reset gpu\n" ); + p_psxgpu->n_gpu_buffer_offset = 0; + p_psxgpu->n_gpustatus = 0x14802000; + p_psxgpu->n_drawarea_x1 = 0; + p_psxgpu->n_drawarea_y1 = 0; + p_psxgpu->n_drawarea_x2 = 1023; + p_psxgpu->n_drawarea_y2 = 1023; + p_psxgpu->n_drawoffset_x = 0; + p_psxgpu->n_drawoffset_y = 0; + p_psxgpu->n_displaystartx = 0; + p_psxgpu->n_displaystarty = 0; + p_psxgpu->n_horiz_disstart = 0x260; + p_psxgpu->n_horiz_disend = 0xc60; + p_psxgpu->n_vert_disstart = 0x010; + p_psxgpu->n_vert_disend = 0x100; + p_psxgpu->n_vramx = 0; + p_psxgpu->n_vramy = 0; + p_psxgpu->n_twx = 0; + p_psxgpu->n_twy = 0; + p_psxgpu->n_twh = 255; + p_psxgpu->n_tww = 255; updatevisiblearea(space->machine, NULL); break; case 0x01: - verboselog( machine, 1, "not handled: reset command buffer\n" ); - m_n_gpu_buffer_offset = 0; + verboselog( p_psxgpu, 1, "not handled: reset command buffer\n" ); + p_psxgpu->n_gpu_buffer_offset = 0; break; case 0x02: - verboselog( machine, 1, "not handled: reset irq\n" ); + verboselog( p_psxgpu, 1, "not handled: reset irq\n" ); break; case 0x03: - m_n_gpustatus &= ~( 1L << 0x17 ); - m_n_gpustatus |= ( data & 0x01 ) << 0x17; + p_psxgpu->n_gpustatus &= ~( 1L << 0x17 ); + p_psxgpu->n_gpustatus |= ( data & 0x01 ) << 0x17; break; case 0x04: - verboselog( machine, 1, "dma setup %d\n", data & 3 ); - m_n_gpustatus &= ~( 3L << 0x1d ); - m_n_gpustatus |= ( data & 0x03 ) << 0x1d; - m_n_gpustatus &= ~( 1L << 0x19 ); + verboselog( p_psxgpu, 1, "dma setup %d\n", data & 3 ); + p_psxgpu->n_gpustatus &= ~( 3L << 0x1d ); + p_psxgpu->n_gpustatus |= ( data & 0x03 ) << 0x1d; + p_psxgpu->n_gpustatus &= ~( 1L << 0x19 ); if( ( data & 3 ) == 1 || ( data & 3 ) == 2 ) { - m_n_gpustatus |= ( 1L << 0x19 ); + p_psxgpu->n_gpustatus |= ( 1L << 0x19 ); } break; case 0x05: - m_n_displaystartx = data & 1023; - if( m_n_gputype == 2 ) + p_psxgpu->n_displaystartx = data & 1023; + if( p_psxgpu->n_gputype == 2 ) { - m_n_displaystarty = ( data >> 10 ) & 1023; + p_psxgpu->n_displaystarty = ( data >> 10 ) & 1023; } else { - m_n_displaystarty = ( data >> 12 ) & 1023; + p_psxgpu->n_displaystarty = ( data >> 12 ) & 1023; } - verboselog( machine, 1, "start of display area %d %d\n", m_n_displaystartx, m_n_displaystarty ); + verboselog( p_psxgpu, 1, "start of display area %d %d\n", p_psxgpu->n_displaystartx, p_psxgpu->n_displaystarty ); break; case 0x06: - m_n_horiz_disstart = data & 4095; - m_n_horiz_disend = ( data >> 12 ) & 4095; - verboselog( machine, 1, "horizontal display range %d %d\n", m_n_horiz_disstart, m_n_horiz_disend ); + p_psxgpu->n_horiz_disstart = data & 4095; + p_psxgpu->n_horiz_disend = ( data >> 12 ) & 4095; + verboselog( p_psxgpu, 1, "horizontal display range %d %d\n", p_psxgpu->n_horiz_disstart, p_psxgpu->n_horiz_disend ); break; case 0x07: - m_n_vert_disstart = data & 1023; - m_n_vert_disend = ( data >> 10 ) & 2047; - verboselog( machine, 1, "vertical display range %d %d\n", m_n_vert_disstart, m_n_vert_disend ); + p_psxgpu->n_vert_disstart = data & 1023; + p_psxgpu->n_vert_disend = ( data >> 10 ) & 2047; + verboselog( p_psxgpu, 1, "vertical display range %d %d\n", p_psxgpu->n_vert_disstart, p_psxgpu->n_vert_disend ); break; case 0x08: - verboselog( machine, 1, "display mode %02x\n", data & 0xff ); - m_n_gpustatus &= ~( 127L << 0x10 ); - m_n_gpustatus |= ( data & 0x3f ) << 0x11; /* width 0 + height + videmode + isrgb24 + isinter */ - m_n_gpustatus |= ( ( data & 0x40 ) >> 0x06 ) << 0x10; /* width 1 */ - if( m_n_gputype == 1 ) + verboselog( p_psxgpu, 1, "display mode %02x\n", data & 0xff ); + p_psxgpu->n_gpustatus &= ~( 127L << 0x10 ); + p_psxgpu->n_gpustatus |= ( data & 0x3f ) << 0x11; /* width 0 + height + videmode + isrgb24 + isinter */ + p_psxgpu->n_gpustatus |= ( ( data & 0x40 ) >> 0x06 ) << 0x10; /* width 1 */ + if( p_psxgpu->n_gputype == 1 ) { - m_b_reverseflag = ( data >> 7 ) & 1; + p_psxgpu->b_reverseflag = ( data >> 7 ) & 1; } updatevisiblearea(space->machine, NULL); break; case 0x09: - verboselog( machine, 1, "not handled: GPU Control 0x09: %08x\n", data ); + verboselog( p_psxgpu, 1, "not handled: GPU Control 0x09: %08x\n", data ); break; case 0x0d: - verboselog( machine, 1, "reset lightgun coordinates %08x\n", data ); - m_n_lightgun_x = 0; - m_n_lightgun_y = 0; + verboselog( p_psxgpu, 1, "reset lightgun coordinates %08x\n", data ); + p_psxgpu->n_lightgun_x = 0; + p_psxgpu->n_lightgun_y = 0; break; case 0x10: switch( data & 0xff ) { case 0x03: - if( m_n_gputype == 2 ) + if( p_psxgpu->n_gputype == 2 ) { - m_n_gpuinfo = m_n_drawarea_x1 | ( m_n_drawarea_y1 << 10 ); + p_psxgpu->n_gpuinfo = p_psxgpu->n_drawarea_x1 | ( p_psxgpu->n_drawarea_y1 << 10 ); } else { - m_n_gpuinfo = m_n_drawarea_x1 | ( m_n_drawarea_y1 << 12 ); + p_psxgpu->n_gpuinfo = p_psxgpu->n_drawarea_x1 | ( p_psxgpu->n_drawarea_y1 << 12 ); } - verboselog( machine, 1, "GPU Info - Draw area top left %08x\n", m_n_gpuinfo ); + verboselog( p_psxgpu, 1, "GPU Info - Draw area top left %08x\n", p_psxgpu->n_gpuinfo ); break; case 0x04: - if( m_n_gputype == 2 ) + if( p_psxgpu->n_gputype == 2 ) { - m_n_gpuinfo = m_n_drawarea_x2 | ( m_n_drawarea_y2 << 10 ); + p_psxgpu->n_gpuinfo = p_psxgpu->n_drawarea_x2 | ( p_psxgpu->n_drawarea_y2 << 10 ); } else { - m_n_gpuinfo = m_n_drawarea_x2 | ( m_n_drawarea_y2 << 12 ); + p_psxgpu->n_gpuinfo = p_psxgpu->n_drawarea_x2 | ( p_psxgpu->n_drawarea_y2 << 12 ); } - verboselog( machine, 1, "GPU Info - Draw area bottom right %08x\n", m_n_gpuinfo ); + verboselog( p_psxgpu, 1, "GPU Info - Draw area bottom right %08x\n", p_psxgpu->n_gpuinfo ); break; case 0x05: - if( m_n_gputype == 2 ) + if( p_psxgpu->n_gputype == 2 ) { - m_n_gpuinfo = ( m_n_drawoffset_x & 2047 ) | ( ( m_n_drawoffset_y & 2047 ) << 11 ); + p_psxgpu->n_gpuinfo = ( p_psxgpu->n_drawoffset_x & 2047 ) | ( ( p_psxgpu->n_drawoffset_y & 2047 ) << 11 ); } else { - m_n_gpuinfo = ( m_n_drawoffset_x & 2047 ) | ( ( m_n_drawoffset_y & 2047 ) << 12 ); + p_psxgpu->n_gpuinfo = ( p_psxgpu->n_drawoffset_x & 2047 ) | ( ( p_psxgpu->n_drawoffset_y & 2047 ) << 12 ); } - verboselog( machine, 1, "GPU Info - Draw offset %08x\n", m_n_gpuinfo ); + verboselog( p_psxgpu, 1, "GPU Info - Draw offset %08x\n", p_psxgpu->n_gpuinfo ); break; case 0x07: - m_n_gpuinfo = m_n_gputype; - verboselog( machine, 1, "GPU Info - GPU Type %08x\n", m_n_gpuinfo ); + p_psxgpu->n_gpuinfo = p_psxgpu->n_gputype; + verboselog( p_psxgpu, 1, "GPU Info - GPU Type %08x\n", p_psxgpu->n_gpuinfo ); break; case 0x08: - m_n_gpuinfo = m_n_lightgun_x | ( m_n_lightgun_y << 16 ); - verboselog( machine, 1, "GPU Info - lightgun coordinates %08x\n", m_n_gpuinfo ); + p_psxgpu->n_gpuinfo = p_psxgpu->n_lightgun_x | ( p_psxgpu->n_lightgun_y << 16 ); + verboselog( p_psxgpu, 1, "GPU Info - lightgun coordinates %08x\n", p_psxgpu->n_gpuinfo ); break; default: - verboselog( machine, 0, "GPU Info - unknown request (%08x)\n", data ); - m_n_gpuinfo = 0; + verboselog( p_psxgpu, 0, "GPU Info - unknown request (%08x)\n", data ); + p_psxgpu->n_gpuinfo = 0; break; } break; case 0x20: - verboselog( machine, 1, "not handled: GPU Control 0x20: %08x\n", data ); + verboselog( p_psxgpu, 1, "not handled: GPU Control 0x20: %08x\n", data ); break; default: #if defined( MAME_DEBUG ) popmessage( "unknown GPU command %08x", data ); #endif - verboselog( machine, 0, "gpu_w( %08x ) unknown GPU command\n", data ); + verboselog( p_psxgpu, 0, "gpu_w( %08x ) unknown GPU command\n", data ); break; } break; default: - verboselog( machine, 0, "gpu_w( %08x, %08x, %08x ) unknown register\n", offset, data, mem_mask ); + verboselog( p_psxgpu, 0, "gpu_w( %08x, %08x, %08x ) unknown register\n", offset, data, mem_mask ); break; } } @@ -3835,31 +3847,33 @@ WRITE32_HANDLER( psx_gpu_w ) void psx_gpu_read( running_machine *machine, UINT32 *p_ram, INT32 n_size ) { + psx_gpu *p_psxgpu = machine->driver_data()->p_psxgpu; + while( n_size > 0 ) { - if( ( m_n_gpustatus & ( 1L << 0x1b ) ) != 0 ) + if( ( p_psxgpu->n_gpustatus & ( 1L << 0x1b ) ) != 0 ) { UINT32 n_pixel; PAIR data; - verboselog( machine, 2, "copy image from frame buffer ( %d, %d )\n", m_n_vramx, m_n_vramy ); + verboselog( p_psxgpu, 2, "copy image from frame buffer ( %d, %d )\n", p_psxgpu->n_vramx, p_psxgpu->n_vramy ); data.d = 0; for( n_pixel = 0; n_pixel < 2; n_pixel++ ) { data.w.l = data.w.h; - data.w.h = *( m_p_p_vram[ m_n_vramy + ( m_packet.n_entry[ 1 ] >> 16 ) ] + m_n_vramx + ( m_packet.n_entry[ 1 ] & 0xffff ) ); - m_n_vramx++; - if( m_n_vramx >= ( m_packet.n_entry[ 2 ] & 0xffff ) ) + data.w.h = *( p_psxgpu->p_p_vram[ p_psxgpu->n_vramy + ( p_psxgpu->m_packet.n_entry[ 1 ] >> 16 ) ] + p_psxgpu->n_vramx + ( p_psxgpu->m_packet.n_entry[ 1 ] & 0xffff ) ); + p_psxgpu->n_vramx++; + if( p_psxgpu->n_vramx >= ( p_psxgpu->m_packet.n_entry[ 2 ] & 0xffff ) ) { - m_n_vramx = 0; - m_n_vramy++; - if( m_n_vramy >= ( m_packet.n_entry[ 2 ] >> 16 ) ) + p_psxgpu->n_vramx = 0; + p_psxgpu->n_vramy++; + if( p_psxgpu->n_vramy >= ( p_psxgpu->m_packet.n_entry[ 2 ] >> 16 ) ) { - verboselog( machine, 1, "copy image from frame buffer end\n" ); - m_n_gpustatus &= ~( 1L << 0x1b ); - m_n_gpu_buffer_offset = 0; - m_n_vramx = 0; - m_n_vramy = 0; + verboselog( p_psxgpu, 1, "copy image from frame buffer end\n" ); + p_psxgpu->n_gpustatus &= ~( 1L << 0x1b ); + p_psxgpu->n_gpu_buffer_offset = 0; + p_psxgpu->n_vramx = 0; + p_psxgpu->n_vramy = 0; if( n_pixel == 0 ) { data.w.l = data.w.h; @@ -3873,8 +3887,8 @@ void psx_gpu_read( running_machine *machine, UINT32 *p_ram, INT32 n_size ) } else { - verboselog( machine, 2, "read GPU info (%08x)\n", m_n_gpuinfo ); - *( p_ram ) = m_n_gpuinfo; + verboselog( p_psxgpu, 2, "read GPU info (%08x)\n", p_psxgpu->n_gpuinfo ); + *( p_ram ) = p_psxgpu->n_gpuinfo; } p_ram++; n_size--; @@ -3883,6 +3897,7 @@ void psx_gpu_read( running_machine *machine, UINT32 *p_ram, INT32 n_size ) READ32_HANDLER( psx_gpu_r ) { + psx_gpu *p_psxgpu = space->machine->driver_data()->p_psxgpu; UINT32 data; switch( offset ) @@ -3891,11 +3906,11 @@ READ32_HANDLER( psx_gpu_r ) psx_gpu_read( space->machine, &data, 1 ); break; case 0x01: - verboselog( space->machine, 1, "read GPU status (%08x)\n", m_n_gpustatus ); - data = m_n_gpustatus; + data = p_psxgpu->n_gpustatus; + verboselog( p_psxgpu, 1, "read GPU status (%08x)\n", data ); break; default: - verboselog( space->machine, 0, "gpu_r( %08x, %08x ) unknown register\n", offset, mem_mask ); + verboselog( p_psxgpu, 0, "gpu_r( %08x, %08x ) unknown register\n", offset, mem_mask ); data = 0; break; } @@ -3904,13 +3919,15 @@ READ32_HANDLER( psx_gpu_r ) INTERRUPT_GEN( psx_vblank ) { + psx_gpu *p_psxgpu = device->machine->driver_data()->p_psxgpu; + #if defined( MAME_DEBUG ) - DebugCheckKeys(device->machine); + DebugCheckKeys(p_psxgpu); #endif - m_n_gpustatus ^= ( 1L << 31 ); + p_psxgpu->n_gpustatus ^= ( 1L << 31 ); - if(need_sianniv_vblank_hack) + if(p_psxgpu->b_need_sianniv_vblank_hack) { UINT32 pc = cpu_get_pc(device); if((pc >= 0x80010018 && pc <= 0x80010028) || pc == 0x8002a4f0) @@ -3927,8 +3944,10 @@ void psx_gpu_reset( running_machine *machine ) psx_gpu_w(space, 1, 0, 0xffffffff ); } -void psx_lightgun_set( int n_x, int n_y ) +void psx_lightgun_set( running_machine *machine, int n_x, int n_y ) { - m_n_lightgun_x = n_x; - m_n_lightgun_y = n_y; + psx_gpu *p_psxgpu = machine->driver_data()->p_psxgpu; + + p_psxgpu->n_lightgun_x = n_x; + p_psxgpu->n_lightgun_y = n_y; }