not to be credited: some steps towards tnzs.c save states

all statics are stored in struct, memory_set_bankptrs have been replaced by memory_configure_banks... yet save states do not work.

either I'm blind and I can't see some typo of mine, or all the memcpys in VIDEO_EOF do not work well with save states.

suggestions are welcome ;)
This commit is contained in:
Fabio Priuli 2009-11-21 01:08:47 +00:00
parent 715bbec027
commit 3d1b4b6fdd
4 changed files with 412 additions and 293 deletions

View File

@ -629,19 +629,10 @@ Driver by Takahiro Nogi (nogi@kt.rim.or.jp) 1999/11/06
#include "includes/tnzs.h"
#include "sound/2151intf.h"
UINT8 *tnzs_objram;
UINT8 *tnzs_vdcram, *tnzs_scrollram, *tnzs_objctrl, *tnzs_bg_flag;
/* max samples */
#define MAX_SAMPLES 0x2f
static INT16 *sampledata[MAX_SAMPLES];
static int samplesize[MAX_SAMPLES];
static SAMPLES_START( kageki_init_samples )
{
running_machine *machine = device->machine;
tnzs_state *state = (tnzs_state *)machine->driver_data;
UINT8 *scan, *src;
INT16 *dest;
int start, size;
@ -658,19 +649,21 @@ static SAMPLES_START( kageki_init_samples )
while (1)
{
if (*scan++ == 0x00)
{
break;
} else {
else
size++;
}
}
sampledata[i] = auto_alloc_array(machine, INT16, size);
samplesize[i] = size;
if (start < 0x100) start = size = 0;
/* 2009-11 FP: should these be saved? */
state->sampledata[i] = auto_alloc_array(machine, INT16, size);
state->samplesize[i] = size;
if (start < 0x100)
start = size = 0;
// signed 8-bit sample to unsigned 8-bit sample convert
dest = sampledata[i];
dest = state->sampledata[i];
scan = &src[start];
for (n = 0; n < size; n++)
{
@ -681,15 +674,15 @@ static SAMPLES_START( kageki_init_samples )
}
static int kageki_csport_sel = 0;
static READ8_DEVICE_HANDLER( kageki_csport_r )
{
int dsw, dsw1, dsw2;
tnzs_state *state = (tnzs_state *)device->machine->driver_data;
int dsw, dsw1, dsw2;
dsw1 = input_port_read(device->machine, "DSWA");
dsw2 = input_port_read(device->machine, "DSWB");
switch (kageki_csport_sel)
switch (state->kageki_csport_sel)
{
case 0x00: // DSW2 5,1 / DSW1 5,1
dsw = (((dsw2 & 0x10) >> 1) | ((dsw2 & 0x01) << 2) | ((dsw1 & 0x10) >> 3) | ((dsw1 & 0x01) >> 0));
@ -705,7 +698,7 @@ static READ8_DEVICE_HANDLER( kageki_csport_r )
break;
default:
dsw = 0x00;
// logerror("kageki_csport_sel error !! (0x%08X)\n", kageki_csport_sel);
// logerror("kageki_csport_sel error !! (0x%08X)\n", state->kageki_csport_sel);
}
return (dsw & 0xff);
@ -713,21 +706,26 @@ static READ8_DEVICE_HANDLER( kageki_csport_r )
static WRITE8_DEVICE_HANDLER( kageki_csport_w )
{
tnzs_state *state = (tnzs_state *)device->machine->driver_data;
char mess[80];
if (data > 0x3f)
{
// read dipsw port
kageki_csport_sel = (data & 0x03);
} else {
state->kageki_csport_sel = (data & 0x03);
}
else
{
if (data > MAX_SAMPLES)
{
// stop samples
sample_stop(device, 0);
sprintf(mess, "VOICE:%02X STOP", data);
} else {
}
else
{
// play samples
sample_start_raw(device, 0, sampledata[data], samplesize[data], 7000, 0);
sample_start_raw(device, 0, state->sampledata[data], state->samplesize[data], 7000, 0);
sprintf(mess, "VOICE:%02X PLAY", data);
}
// popmessage(mess);
@ -737,29 +735,26 @@ static WRITE8_DEVICE_HANDLER( kageki_csport_w )
static WRITE8_DEVICE_HANDLER( kabukiz_sound_bank_w )
{
// to avoid the write when the sound chip is initialized
if(data != 0xff)
{
UINT8 *ROM = memory_region(device->machine, "audiocpu");
memory_set_bankptr(device->machine, 3, &ROM[0x10000 + 0x4000 * (data & 0x07)]);
}
if (data != 0xff)
memory_set_bank(device->machine, 3, data & 0x07);
}
static WRITE8_DEVICE_HANDLER( kabukiz_sample_w )
{
// to avoid the write when the sound chip is initialized
if(data != 0xff)
if (data != 0xff)
dac_data_w(device, data);
}
static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 )
AM_RANGE(0x0000, 0x7fff) AM_ROM
AM_RANGE(0x8000, 0xbfff) AM_RAMBANK(1) /* ROM + RAM */
AM_RANGE(0xc000, 0xdfff) AM_RAM AM_BASE(&tnzs_objram)
AM_RANGE(0xc000, 0xdfff) AM_RAM AM_BASE_MEMBER(tnzs_state, objram)
AM_RANGE(0xe000, 0xefff) AM_RAM AM_SHARE(1)
AM_RANGE(0xf000, 0xf1ff) AM_RAM AM_BASE(&tnzs_vdcram)
AM_RANGE(0xf200, 0xf2ff) AM_WRITEONLY AM_BASE(&tnzs_scrollram) /* scrolling info */
AM_RANGE(0xf300, 0xf303) AM_MIRROR(0xfc) AM_WRITEONLY AM_BASE(&tnzs_objctrl) /* control registers (0x80 mirror used by Arkanoid 2) */
AM_RANGE(0xf400, 0xf400) AM_WRITEONLY AM_BASE(&tnzs_bg_flag) /* enable / disable background transparency */
AM_RANGE(0xf000, 0xf1ff) AM_RAM AM_BASE_MEMBER(tnzs_state, vdcram)
AM_RANGE(0xf200, 0xf2ff) AM_WRITEONLY AM_BASE_MEMBER(tnzs_state, scrollram) /* scrolling info */
AM_RANGE(0xf300, 0xf303) AM_MIRROR(0xfc) AM_WRITEONLY AM_BASE_MEMBER(tnzs_state, objctrl) /* control registers (0x80 mirror used by Arkanoid 2) */
AM_RANGE(0xf400, 0xf400) AM_WRITEONLY AM_BASE_MEMBER(tnzs_state, bg_flag) /* enable / disable background transparency */
AM_RANGE(0xf600, 0xf600) AM_READNOP AM_WRITE(tnzs_bankswitch_w)
/* arknoid2, extrmatn, plumppop and drtoppel have PROMs instead of RAM */
/* drtoppel writes here anyway! (maybe leftover from tests during development) */
@ -770,12 +765,12 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START( cpu0_type2, ADDRESS_SPACE_PROGRAM, 8 )
AM_RANGE(0x0000, 0x7fff) AM_ROM
AM_RANGE(0x8000, 0xbfff) AM_RAMBANK(1) /* ROM + RAM */
AM_RANGE(0xc000, 0xdfff) AM_RAM AM_BASE(&tnzs_objram)
AM_RANGE(0xc000, 0xdfff) AM_RAM AM_BASE_MEMBER(tnzs_state, objram)
AM_RANGE(0xe000, 0xefff) AM_RAM AM_SHARE(1)
AM_RANGE(0xf000, 0xf1ff) AM_RAM AM_BASE(&tnzs_vdcram)
AM_RANGE(0xf200, 0xf2ff) AM_WRITEONLY AM_BASE(&tnzs_scrollram) /* scrolling info */
AM_RANGE(0xf300, 0xf303) AM_MIRROR(0xfc) AM_WRITEONLY AM_BASE(&tnzs_objctrl) /* control registers (0x80 mirror used by Arkanoid 2) */
AM_RANGE(0xf400, 0xf400) AM_WRITEONLY AM_BASE(&tnzs_bg_flag) /* enable / disable background transparency */
AM_RANGE(0xf000, 0xf1ff) AM_RAM AM_BASE_MEMBER(tnzs_state, vdcram)
AM_RANGE(0xf200, 0xf2ff) AM_WRITEONLY AM_BASE_MEMBER(tnzs_state, scrollram) /* scrolling info */
AM_RANGE(0xf300, 0xf303) AM_MIRROR(0xfc) AM_WRITEONLY AM_BASE_MEMBER(tnzs_state, objctrl) /* control registers (0x80 mirror used by Arkanoid 2) */
AM_RANGE(0xf400, 0xf400) AM_WRITEONLY AM_BASE_MEMBER(tnzs_state, bg_flag) /* enable / disable background transparency */
AM_RANGE(0xf600, 0xf600) AM_WRITE(tnzs_bankswitch_w)
/* kabukiz still writes here but it's not used (it's paletteram in type1 map) */
AM_RANGE(0xf800, 0xfbff) AM_WRITENOP
@ -872,41 +867,39 @@ ADDRESS_MAP_END
static WRITE8_HANDLER( jpopnics_palette_w )
{
int r,g,b;
int r, g, b;
UINT16 paldata;
paletteram[offset] = data;
offset = offset >> 1;
paldata = (paletteram[offset*2]<<8) | paletteram[(offset*2+1)];
paldata = (paletteram[offset * 2] << 8) | paletteram[(offset * 2 + 1)];
g = (paldata >> 12) & 0x000f;
r = (paldata >> 4) & 0x000f;
b = (paldata >> 8) & 0x000f;
// the other bits seem to be used, and the colours are wrong..
palette_set_color_rgb(space->machine,offset,r<<4, g<<4, b<<4);
palette_set_color_rgb(space->machine, offset, r << 4, g << 4, b << 4);
}
static ADDRESS_MAP_START( jpopnics_main_map, ADDRESS_SPACE_PROGRAM, 8 )
AM_RANGE(0x0000, 0x7fff) AM_ROM
AM_RANGE(0x8000, 0xbfff) AM_READWRITE(SMH_BANK(1), SMH_ROM)
AM_RANGE(0xc000, 0xdfff) AM_RAM AM_BASE(&tnzs_objram)
AM_RANGE(0xc000, 0xdfff) AM_RAM AM_BASE_MEMBER(tnzs_state, objram)
AM_RANGE(0xe000, 0xefff) AM_RAM AM_SHARE(1) /* WORK RAM (shared by the 2 z80's) */
AM_RANGE(0xf000, 0xf1ff) AM_RAM AM_BASE(&tnzs_vdcram) /* VDC RAM */
AM_RANGE(0xf200, 0xf2ff) AM_RAM AM_BASE(&tnzs_scrollram) /* scrolling info */
AM_RANGE(0xf300, 0xf303) AM_MIRROR(0xfc) AM_WRITE(SMH_RAM) AM_BASE(&tnzs_objctrl) /* control registers (0x80 mirror used by Arkanoid 2) */
AM_RANGE(0xf400, 0xf400) AM_WRITE(SMH_RAM) AM_BASE(&tnzs_bg_flag) /* enable / disable background transparency */
AM_RANGE(0xf000, 0xf1ff) AM_RAM AM_BASE_MEMBER(tnzs_state, vdcram) /* VDC RAM */
AM_RANGE(0xf200, 0xf2ff) AM_RAM AM_BASE_MEMBER(tnzs_state, scrollram) /* scrolling info */
AM_RANGE(0xf300, 0xf303) AM_MIRROR(0xfc) AM_WRITE(SMH_RAM) AM_BASE_MEMBER(tnzs_state, objctrl) /* control registers (0x80 mirror used by Arkanoid 2) */
AM_RANGE(0xf400, 0xf400) AM_WRITE(SMH_RAM) AM_BASE_MEMBER(tnzs_state, bg_flag) /* enable / disable background transparency */
AM_RANGE(0xf600, 0xf600) AM_READWRITE(SMH_NOP, tnzs_bankswitch_w)
AM_RANGE(0xf800, 0xffff) AM_RAM_WRITE(jpopnics_palette_w) AM_BASE(&paletteram)
ADDRESS_MAP_END
static WRITE8_HANDLER( jpopnics_subbankswitch_w )
{
UINT8 *RAM = memory_region(space->machine, "sub");
/* bits 0-1 select ROM bank */
memory_set_bankptr (space->machine, 2, &RAM[0x10000 + 0x2000 * (data & 3)]);
memory_set_bank(space->machine, 2, data & 0x03);
}
static ADDRESS_MAP_START( jpopnics_sub_map, ADDRESS_SPACE_PROGRAM, 8 )
@ -1607,6 +1600,9 @@ static const samples_interface tnzs_samples_interface =
static MACHINE_DRIVER_START( arknoid2 )
/* driver data */
MDRV_DRIVER_DATA(tnzs_state)
/* basic machine hardware */
MDRV_CPU_ADD("maincpu", Z80, XTAL_12MHz/2) /* verified on pcb */
MDRV_CPU_PROGRAM_MAP(main_map)
@ -1618,6 +1614,7 @@ static MACHINE_DRIVER_START( arknoid2 )
MDRV_QUANTUM_PERFECT_CPU("maincpu")
MDRV_MACHINE_START(tnzs)
MDRV_MACHINE_RESET(tnzs)
/* video hardware */
@ -1646,6 +1643,9 @@ MACHINE_DRIVER_END
static MACHINE_DRIVER_START( drtoppel )
/* driver data */
MDRV_DRIVER_DATA(tnzs_state)
/* basic machine hardware */
MDRV_CPU_ADD("maincpu", Z80,XTAL_12MHz/2) /* 6.0 MHz ??? - Main board Crystal is 12MHz */
MDRV_CPU_PROGRAM_MAP(main_map)
@ -1657,6 +1657,7 @@ static MACHINE_DRIVER_START( drtoppel )
MDRV_QUANTUM_PERFECT_CPU("maincpu")
MDRV_MACHINE_START(tnzs)
MDRV_MACHINE_RESET(tnzs)
/* video hardware */
@ -1685,6 +1686,9 @@ MACHINE_DRIVER_END
static MACHINE_DRIVER_START( tnzs )
/* driver data */
MDRV_DRIVER_DATA(tnzs_state)
/* basic machine hardware */
MDRV_CPU_ADD("maincpu", Z80,XTAL_12MHz/2) /* 6.0 MHz ??? - Main board Crystal is 12MHz */
MDRV_CPU_PROGRAM_MAP(main_map)
@ -1699,6 +1703,7 @@ static MACHINE_DRIVER_START( tnzs )
MDRV_QUANTUM_PERFECT_CPU("maincpu")
MDRV_MACHINE_START(tnzs)
MDRV_MACHINE_RESET(tnzs)
/* video hardware */
@ -1726,6 +1731,9 @@ MACHINE_DRIVER_END
static MACHINE_DRIVER_START( insectx )
/* driver data */
MDRV_DRIVER_DATA(tnzs_state)
/* basic machine hardware */
MDRV_CPU_ADD("maincpu", Z80, XTAL_12MHz/2) /* verified on pcb */
MDRV_CPU_PROGRAM_MAP(main_map)
@ -1737,6 +1745,7 @@ static MACHINE_DRIVER_START( insectx )
MDRV_QUANTUM_PERFECT_CPU("maincpu")
MDRV_MACHINE_START(tnzs)
MDRV_MACHINE_RESET(tnzs)
/* video hardware */
@ -1764,6 +1773,9 @@ MACHINE_DRIVER_END
static MACHINE_DRIVER_START( kageki )
/* driver data */
MDRV_DRIVER_DATA(tnzs_state)
/* basic machine hardware */
MDRV_CPU_ADD("maincpu", Z80, XTAL_12MHz/2) /* verified on pcb */
MDRV_CPU_PROGRAM_MAP(main_map)
@ -1775,6 +1787,7 @@ static MACHINE_DRIVER_START( kageki )
MDRV_QUANTUM_PERFECT_CPU("maincpu")
MDRV_MACHINE_START(tnzs)
MDRV_MACHINE_RESET(tnzs)
/* video hardware */
@ -1809,6 +1822,9 @@ MACHINE_DRIVER_END
static MACHINE_DRIVER_START( tnzsb )
/* driver data */
MDRV_DRIVER_DATA(tnzs_state)
/* basic machine hardware */
MDRV_CPU_ADD("maincpu", Z80, XTAL_12MHz/2) /* verified on pcb */
MDRV_CPU_PROGRAM_MAP(cpu0_type2)
@ -1824,6 +1840,7 @@ static MACHINE_DRIVER_START( tnzsb )
MDRV_QUANTUM_PERFECT_CPU("maincpu")
MDRV_MACHINE_START(tnzs)
MDRV_MACHINE_RESET(tnzs)
/* video hardware */
@ -1877,6 +1894,9 @@ MACHINE_DRIVER_END
static MACHINE_DRIVER_START( jpopnics )
/* driver data */
MDRV_DRIVER_DATA(tnzs_state)
/* basic machine hardware */
MDRV_CPU_ADD("maincpu", Z80,XTAL_12MHz/2) /* Not verified - Main board Crystal is 12MHz */
MDRV_CPU_PROGRAM_MAP(jpopnics_main_map)
@ -1888,6 +1908,9 @@ static MACHINE_DRIVER_START( jpopnics )
MDRV_QUANTUM_PERFECT_CPU("maincpu")
MDRV_MACHINE_START(jpopnics)
MDRV_MACHINE_RESET(jpopnics)
/* video hardware */
MDRV_SCREEN_ADD("screen", RASTER)
MDRV_SCREEN_REFRESH_RATE(60)

View File

@ -1,7 +1,59 @@
/*----------- defined in drivers/tnzs.c -----------*/
extern UINT8 *tnzs_objram;
extern UINT8 *tnzs_vdcram, *tnzs_scrollram, *tnzs_objctrl, *tnzs_bg_flag;
#define MAX_SAMPLES 0x2f /* max samples */
enum
{
MCU_NONE_INSECTX = 0,
MCU_NONE_KAGEKI,
MCU_NONE_TNZSB,
MCU_NONE_KABUKIZ,
MCU_EXTRMATN,
MCU_ARKANOID,
MCU_PLUMPOP,
MCU_DRTOPPEL,
MCU_CHUKATAI,
MCU_TNZS
};
typedef struct _tnzs_state tnzs_state;
struct _tnzs_state
{
/* memory pointers */
UINT8 * objram;
UINT8 * vdcram;
UINT8 * scrollram;
UINT8 * objctrl;
UINT8 * bg_flag;
// UINT8 * paletteram; // currently this uses generic palette handling
/* video-related */
int screenflip;
/* sound-related */
INT16 *sampledata[MAX_SAMPLES];
int samplesize[MAX_SAMPLES];
/* misc / mcu */
int kageki_csport_sel;
int input_select;
int mcu_type;
int mcu_initializing, mcu_coinage_init, mcu_command, mcu_readcredits;
int mcu_reportcoin;
int insertcoin;
UINT8 mcu_coinage[4];
UINT8 mcu_coins_a, mcu_coins_b, mcu_credits;
/* game-specific */
// champbwl
UINT8 last_trackball_val[2];
// UINT8 * nvram; // currently this uses generic_nvram
// cchance
UINT8 hop_io, bell_io;
/* devices */
const device_config *mcu;
};
/*----------- defined in machine/tnzs.c -----------*/
@ -10,6 +62,11 @@ READ8_HANDLER( tnzs_port1_r );
READ8_HANDLER( tnzs_port2_r );
WRITE8_HANDLER( tnzs_port2_w );
READ8_HANDLER( arknoid2_sh_f000_r );
READ8_HANDLER( tnzs_mcu_r );
WRITE8_HANDLER( tnzs_mcu_w );
WRITE8_HANDLER( tnzs_bankswitch_w );
WRITE8_HANDLER( tnzs_bankswitch1_w );
INTERRUPT_GEN( arknoid2_interrupt );
DRIVER_INIT( plumpop );
DRIVER_INIT( extrmatn );
@ -22,12 +79,10 @@ DRIVER_INIT( kabukiz );
DRIVER_INIT( insectx );
DRIVER_INIT( kageki );
READ8_HANDLER( tnzs_mcu_r );
WRITE8_HANDLER( tnzs_mcu_w );
INTERRUPT_GEN( arknoid2_interrupt );
MACHINE_START( tnzs );
MACHINE_RESET( tnzs );
WRITE8_HANDLER( tnzs_bankswitch_w );
WRITE8_HANDLER( tnzs_bankswitch1_w );
MACHINE_RESET( jpopnics );
MACHINE_START( jpopnics );
/*----------- defined in video/tnzs.c -----------*/

View File

@ -16,35 +16,13 @@
#include "cpu/mcs48/mcs48.h"
#include "includes/tnzs.h"
static int mcu_type;
static int tnzs_input_select;
enum
{
MCU_NONE_INSECTX,
MCU_NONE_KAGEKI,
MCU_NONE_TNZSB,
MCU_NONE_KABUKIZ,
MCU_EXTRMATN,
MCU_ARKANOID,
MCU_PLUMPOP,
MCU_DRTOPPEL,
MCU_CHUKATAI,
MCU_TNZS
};
static int mcu_initializing,mcu_coinage_init,mcu_command,mcu_readcredits;
static int mcu_reportcoin;
static UINT8 mcu_coinage[4];
static UINT8 mcu_coinsA,mcu_coinsB,mcu_credits;
static READ8_HANDLER( mcu_tnzs_r )
{
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
UINT8 data;
data = upi41_master_r(cputag_get_cpu(space->machine, "mcu"), offset & 1);
data = upi41_master_r(state->mcu, offset & 1);
cpu_yield(space->cpu);
// logerror("PC %04x: read %02x from mcu $c00%01x\n", cpu_get_previouspc(space->cpu), data, offset);
@ -54,17 +32,19 @@ static READ8_HANDLER( mcu_tnzs_r )
static WRITE8_HANDLER( mcu_tnzs_w )
{
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
// logerror("PC %04x: write %02x to mcu $c00%01x\n", cpu_get_previouspc(space->cpu), data, offset);
upi41_master_w(cputag_get_cpu(space->machine, "mcu"), offset & 1, data);
upi41_master_w(state->mcu, offset & 1, data);
}
READ8_HANDLER( tnzs_port1_r )
{
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
int data = 0;
switch (tnzs_input_select & 0x0f)
switch (state->input_select & 0x0f)
{
case 0x0a: data = input_port_read(space->machine, "IN2"); break;
case 0x0c: data = input_port_read(space->machine, "IN0"); break;
@ -88,14 +68,15 @@ READ8_HANDLER( tnzs_port2_r )
WRITE8_HANDLER( tnzs_port2_w )
{
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
// logerror("I8742:%04x Write %02x to port 2\n", cpu_get_previouspc(space->cpu), data);
coin_lockout_w( 0, (data & 0x40) );
coin_lockout_w( 1, (data & 0x80) );
coin_counter_w( 0, (~data & 0x10) );
coin_counter_w( 1, (~data & 0x20) );
coin_lockout_w(0, (data & 0x40));
coin_lockout_w(1, (data & 0x80));
coin_counter_w(0, (~data & 0x10));
coin_counter_w(1, (~data & 0x20));
tnzs_input_select = data;
state->input_select = data;
}
@ -106,36 +87,34 @@ READ8_HANDLER( arknoid2_sh_f000_r )
// logerror("PC %04x: read input %04x\n", cpu_get_pc(space->cpu), 0xf000 + offset);
val = input_port_read_safe(space->machine, (offset/2) ? "AN2" : "AN1", 0);
val = input_port_read_safe(space->machine, (offset / 2) ? "AN2" : "AN1", 0);
if (offset & 1)
{
return ((val >> 8) & 0xff);
}
else
{
return val & 0xff;
}
}
static void mcu_reset(void)
static void mcu_reset( running_machine *machine )
{
mcu_initializing = 3;
mcu_coinage_init = 0;
mcu_coinage[0] = 1;
mcu_coinage[1] = 1;
mcu_coinage[2] = 1;
mcu_coinage[3] = 1;
mcu_coinsA = 0;
mcu_coinsB = 0;
mcu_credits = 0;
mcu_reportcoin = 0;
mcu_command = 0;
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->mcu_initializing = 3;
state->mcu_coinage_init = 0;
state->mcu_coinage[0] = 1;
state->mcu_coinage[1] = 1;
state->mcu_coinage[2] = 1;
state->mcu_coinage[3] = 1;
state->mcu_coins_a = 0;
state->mcu_coins_b = 0;
state->mcu_credits = 0;
state->mcu_reportcoin = 0;
state->mcu_command = 0;
}
static void mcu_handle_coins(int coin)
static void mcu_handle_coins( running_machine *machine, int coin )
{
static int insertcoin;
tnzs_state *state = (tnzs_state *)machine->driver_data;
/* The coin inputs and coin counters are managed by the i8742 mcu. */
/* Here we simulate it. */
@ -143,21 +122,21 @@ static void mcu_handle_coins(int coin)
/* Coin/Play settings must also be taken into consideration */
if (coin & 0x08) /* tilt */
mcu_reportcoin = coin;
else if (coin && coin != insertcoin)
state->mcu_reportcoin = coin;
else if (coin && coin != state->insertcoin)
{
if (coin & 0x01) /* coin A */
{
// logerror("Coin dropped into slot A\n");
coin_counter_w(0,1); coin_counter_w(0,0); /* Count slot A */
mcu_coinsA++;
if (mcu_coinsA >= mcu_coinage[0])
state->mcu_coins_a++;
if (state->mcu_coins_a >= state->mcu_coinage[0])
{
mcu_coinsA -= mcu_coinage[0];
mcu_credits += mcu_coinage[1];
if (mcu_credits >= 9)
state->mcu_coins_a -= state->mcu_coinage[0];
state->mcu_credits += state->mcu_coinage[1];
if (state->mcu_credits >= 9)
{
mcu_credits = 9;
state->mcu_credits = 9;
coin_lockout_global_w(1); /* Lock all coin slots */
}
else
@ -166,18 +145,19 @@ static void mcu_handle_coins(int coin)
}
}
}
if (coin & 0x02) /* coin B */
{
// logerror("Coin dropped into slot B\n");
coin_counter_w(1,1); coin_counter_w(1,0); /* Count slot B */
mcu_coinsB++;
if (mcu_coinsB >= mcu_coinage[2])
state->mcu_coins_b++;
if (state->mcu_coins_b >= state->mcu_coinage[2])
{
mcu_coinsB -= mcu_coinage[2];
mcu_credits += mcu_coinage[3];
if (mcu_credits >= 9)
state->mcu_coins_b -= state->mcu_coinage[2];
state->mcu_credits += state->mcu_coinage[3];
if (state->mcu_credits >= 9)
{
mcu_credits = 9;
state->mcu_credits = 9;
coin_lockout_global_w(1); /* Lock all coin slots */
}
else
@ -186,55 +166,58 @@ static void mcu_handle_coins(int coin)
}
}
}
if (coin & 0x04) /* service */
{
// logerror("Coin dropped into service slot C\n");
mcu_credits++;
state->mcu_credits++;
}
mcu_reportcoin = coin;
state->mcu_reportcoin = coin;
}
else
{
if (mcu_credits < 9)
if (state->mcu_credits < 9)
coin_lockout_global_w(0); /* Unlock all coin slots */
mcu_reportcoin = 0;
}
insertcoin = coin;
}
state->mcu_reportcoin = 0;
}
state->insertcoin = coin;
}
static READ8_HANDLER( mcu_arknoid2_r )
{
static const char mcu_startup[] = "\x55\xaa\x5a";
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
// logerror("PC %04x: read mcu %04x\n", cpu_get_pc(space->cpu), 0xc000 + offset);
if (offset == 0)
{
/* if the mcu has just been reset, return startup code */
if (mcu_initializing)
if (state->mcu_initializing)
{
mcu_initializing--;
return mcu_startup[2 - mcu_initializing];
state->mcu_initializing--;
return mcu_startup[2 - state->mcu_initializing];
}
switch (mcu_command)
switch (state->mcu_command)
{
case 0x41:
return mcu_credits;
return state->mcu_credits;
case 0xc1:
/* Read the credit counter or the inputs */
if (mcu_readcredits == 0)
if (state->mcu_readcredits == 0)
{
mcu_readcredits = 1;
if (mcu_reportcoin & 0x08)
state->mcu_readcredits = 1;
if (state->mcu_reportcoin & 0x08)
{
mcu_initializing = 3;
state->mcu_initializing = 3;
return 0xee; /* tilt */
}
else return mcu_credits;
else return state->mcu_credits;
}
else return input_port_read(space->machine, "IN0"); /* buttons */
@ -257,22 +240,23 @@ static READ8_HANDLER( mcu_arknoid2_r )
1,2,3 = coin switch pressed
e = tilt
*/
if (mcu_reportcoin & 0x08) return 0xe1; /* tilt */
if (mcu_reportcoin & 0x01) return 0x11; /* coin 1 (will trigger "coin inserted" sound) */
if (mcu_reportcoin & 0x02) return 0x21; /* coin 2 (will trigger "coin inserted" sound) */
if (mcu_reportcoin & 0x04) return 0x31; /* coin 3 (will trigger "coin inserted" sound) */
if (state->mcu_reportcoin & 0x08) return 0xe1; /* tilt */
if (state->mcu_reportcoin & 0x01) return 0x11; /* coin 1 (will trigger "coin inserted" sound) */
if (state->mcu_reportcoin & 0x02) return 0x21; /* coin 2 (will trigger "coin inserted" sound) */
if (state->mcu_reportcoin & 0x04) return 0x31; /* coin 3 (will trigger "coin inserted" sound) */
return 0x01;
}
}
static WRITE8_HANDLER( mcu_arknoid2_w )
{
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
if (offset == 0)
{
// logerror("PC %04x: write %02x to mcu %04x\n", cpu_get_pc(space->cpu), data, 0xc000 + offset);
if (mcu_command == 0x41)
if (state->mcu_command == 0x41)
{
mcu_credits = (mcu_credits + data) & 0xff;
state->mcu_credits = (state->mcu_credits + data) & 0xff;
}
}
else
@ -288,28 +272,31 @@ static WRITE8_HANDLER( mcu_arknoid2_w )
*/
// logerror("PC %04x: write %02x to mcu %04x\n", cpu_get_pc(space->cpu), data, 0xc000 + offset);
if (mcu_initializing)
if (state->mcu_initializing)
{
/* set up coin/credit settings */
mcu_coinage[mcu_coinage_init++] = data;
if (mcu_coinage_init == 4) mcu_coinage_init = 0; /* must not happen */
state->mcu_coinage[state->mcu_coinage_init++] = data;
if (state->mcu_coinage_init == 4)
state->mcu_coinage_init = 0; /* must not happen */
}
if (data == 0xc1)
mcu_readcredits = 0; /* reset input port number */
state->mcu_readcredits = 0; /* reset input port number */
if (data == 0x15)
{
mcu_credits = (mcu_credits - 1) & 0xff;
if (mcu_credits == 0xff) mcu_credits = 0;
state->mcu_credits = (state->mcu_credits - 1) & 0xff;
if (state->mcu_credits == 0xff)
state->mcu_credits = 0;
}
mcu_command = data;
state->mcu_command = data;
}
}
static READ8_HANDLER( mcu_extrmatn_r )
{
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
static const char mcu_startup[] = "\x5a\xa5\x55";
// logerror("PC %04x: read mcu %04x\n", cpu_get_pc(space->cpu), 0xc000 + offset);
@ -317,13 +304,13 @@ static READ8_HANDLER( mcu_extrmatn_r )
if (offset == 0)
{
/* if the mcu has just been reset, return startup code */
if (mcu_initializing)
if (state->mcu_initializing)
{
mcu_initializing--;
return mcu_startup[2 - mcu_initializing];
state->mcu_initializing--;
return mcu_startup[2 - state->mcu_initializing];
}
switch (mcu_command)
switch (state->mcu_command)
{
case 0x01:
return input_port_read(space->machine, "IN0") ^ 0xff; /* player 1 joystick + buttons */
@ -338,29 +325,29 @@ static READ8_HANDLER( mcu_extrmatn_r )
return input_port_read(space->machine, "IN2") & 0x0f;
case 0x41:
return mcu_credits;
return state->mcu_credits;
case 0xa0:
/* Read the credit counter */
if (mcu_reportcoin & 0x08)
if (state->mcu_reportcoin & 0x08)
{
mcu_initializing = 3;
state->mcu_initializing = 3;
return 0xee; /* tilt */
}
else return mcu_credits;
else return state->mcu_credits;
case 0xa1:
/* Read the credit counter or the inputs */
if (mcu_readcredits == 0)
if (state->mcu_readcredits == 0)
{
mcu_readcredits = 1;
if (mcu_reportcoin & 0x08)
state->mcu_readcredits = 1;
if (state->mcu_reportcoin & 0x08)
{
mcu_initializing = 3;
state->mcu_initializing = 3;
return 0xee; /* tilt */
// return 0x64; /* theres a reset input somewhere */
}
else return mcu_credits;
else return state->mcu_credits;
}
/* buttons */
else return ((input_port_read(space->machine, "IN0") & 0xf0) | (input_port_read(space->machine, "IN1") >> 4)) ^ 0xff;
@ -384,22 +371,23 @@ static READ8_HANDLER( mcu_extrmatn_r )
1,2,3 = coin switch pressed
e = tilt
*/
if (mcu_reportcoin & 0x08) return 0xe1; /* tilt */
if (mcu_reportcoin & 0x01) return 0x11; /* coin 1 (will trigger "coin inserted" sound) */
if (mcu_reportcoin & 0x02) return 0x21; /* coin 2 (will trigger "coin inserted" sound) */
if (mcu_reportcoin & 0x04) return 0x31; /* coin 3 (will trigger "coin inserted" sound) */
if (state->mcu_reportcoin & 0x08) return 0xe1; /* tilt */
if (state->mcu_reportcoin & 0x01) return 0x11; /* coin 1 (will trigger "coin inserted" sound) */
if (state->mcu_reportcoin & 0x02) return 0x21; /* coin 2 (will trigger "coin inserted" sound) */
if (state->mcu_reportcoin & 0x04) return 0x31; /* coin 3 (will trigger "coin inserted" sound) */
return 0x01;
}
}
static WRITE8_HANDLER( mcu_extrmatn_w )
{
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
if (offset == 0)
{
// logerror("PC %04x: write %02x to mcu %04x\n", cpu_get_pc(space->cpu), data, 0xc000 + offset);
if (mcu_command == 0x41)
if (state->mcu_command == 0x41)
{
mcu_credits = (mcu_credits + data) & 0xff;
state->mcu_credits = (state->mcu_credits + data) & 0xff;
}
}
else
@ -420,23 +408,24 @@ static WRITE8_HANDLER( mcu_extrmatn_w )
// logerror("PC %04x: write %02x to mcu %04x\n", cpu_get_pc(space->cpu), data, 0xc000 + offset);
if (mcu_initializing)
if (state->mcu_initializing)
{
/* set up coin/credit settings */
mcu_coinage[mcu_coinage_init++] = data;
if (mcu_coinage_init == 4) mcu_coinage_init = 0; /* must not happen */
state->mcu_coinage[state->mcu_coinage_init++] = data;
if (state->mcu_coinage_init == 4)
state->mcu_coinage_init = 0; /* must not happen */
}
if (data == 0xa1)
mcu_readcredits = 0; /* reset input port number */
state->mcu_readcredits = 0; /* reset input port number */
/* Dr Toppel decrements credits differently. So handle it */
if ((data == 0x09) && (mcu_type == MCU_DRTOPPEL || mcu_type == MCU_PLUMPOP))
mcu_credits = (mcu_credits - 1) & 0xff; /* Player 1 start */
if ((data == 0x18) && (mcu_type == MCU_DRTOPPEL || mcu_type == MCU_PLUMPOP))
mcu_credits = (mcu_credits - 2) & 0xff; /* Player 2 start */
if ((data == 0x09) && (state->mcu_type == MCU_DRTOPPEL || state->mcu_type == MCU_PLUMPOP))
state->mcu_credits = (state->mcu_credits - 1) & 0xff; /* Player 1 start */
if ((data == 0x18) && (state->mcu_type == MCU_DRTOPPEL || state->mcu_type == MCU_PLUMPOP))
state->mcu_credits = (state->mcu_credits - 2) & 0xff; /* Player 2 start */
mcu_command = data;
state->mcu_command = data;
}
}
@ -503,22 +492,26 @@ static WRITE8_HANDLER( tnzs_sync_kludge_w )
DRIVER_INIT( plumpop )
{
mcu_type = MCU_PLUMPOP;
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->mcu_type = MCU_PLUMPOP;
}
DRIVER_INIT( extrmatn )
{
mcu_type = MCU_EXTRMATN;
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->mcu_type = MCU_EXTRMATN;
}
DRIVER_INIT( arknoid2 )
{
mcu_type = MCU_ARKANOID;
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->mcu_type = MCU_ARKANOID;
}
DRIVER_INIT( drtoppel )
{
mcu_type = MCU_DRTOPPEL;
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->mcu_type = MCU_DRTOPPEL;
/* drtoppel writes to the palette RAM area even if it has PROMs! We have to patch it out. */
memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xf800, 0xfbff, 0, 0, (write8_space_func)SMH_NOP);
@ -526,19 +519,22 @@ DRIVER_INIT( drtoppel )
DRIVER_INIT( chukatai )
{
mcu_type = MCU_CHUKATAI;
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->mcu_type = MCU_CHUKATAI;
}
DRIVER_INIT( tnzs )
{
mcu_type = MCU_TNZS;
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->mcu_type = MCU_TNZS;
/* we need to install a kludge to avoid problems with a bug in the original code */
// memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xef10, 0xef10, 0, 0, tnzs_sync_kludge_w);
}
DRIVER_INIT( tnzsb )
{
mcu_type = MCU_NONE_TNZSB;
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->mcu_type = MCU_NONE_TNZSB;
/* we need to install a kludge to avoid problems with a bug in the original code */
// memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xef10, 0xef10, 0, 0, tnzs_sync_kludge_w);
@ -546,12 +542,17 @@ DRIVER_INIT( tnzsb )
DRIVER_INIT( kabukiz )
{
mcu_type = MCU_NONE_KABUKIZ;
tnzs_state *state = (tnzs_state *)machine->driver_data;
UINT8 *SOUND = memory_region(machine, "audiocpu");
state->mcu_type = MCU_NONE_KABUKIZ;
memory_configure_bank(machine, 3, 0, 8, &SOUND[0x10000], 0x4000);
}
DRIVER_INIT( insectx )
{
mcu_type = MCU_NONE_INSECTX;
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->mcu_type = MCU_NONE_INSECTX;
/* this game has no mcu, replace the handler with plain input port handlers */
memory_install_read_port_handler(cputag_get_address_space(machine, "sub", ADDRESS_SPACE_PROGRAM), 0xc000, 0xc000, 0, 0, "IN0" );
@ -561,23 +562,25 @@ DRIVER_INIT( insectx )
DRIVER_INIT( kageki )
{
mcu_type = MCU_NONE_KAGEKI;
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->mcu_type = MCU_NONE_KAGEKI;
}
READ8_HANDLER( tnzs_mcu_r )
{
switch (mcu_type)
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
switch (state->mcu_type)
{
case MCU_TNZS:
case MCU_CHUKATAI:
return mcu_tnzs_r(space,offset);
return mcu_tnzs_r(space, offset);
case MCU_ARKANOID:
return mcu_arknoid2_r(space,offset);
return mcu_arknoid2_r(space, offset);
case MCU_EXTRMATN:
case MCU_DRTOPPEL:
case MCU_PLUMPOP:
return mcu_extrmatn_r(space,offset);
return mcu_extrmatn_r(space, offset);
default:
return 0xff;
}
@ -585,19 +588,20 @@ READ8_HANDLER( tnzs_mcu_r )
WRITE8_HANDLER( tnzs_mcu_w )
{
switch (mcu_type)
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
switch (state->mcu_type)
{
case MCU_TNZS:
case MCU_CHUKATAI:
mcu_tnzs_w(space,offset,data);
mcu_tnzs_w(space, offset, data);
break;
case MCU_ARKANOID:
mcu_arknoid2_w(space,offset,data);
mcu_arknoid2_w(space, offset, data);
break;
case MCU_EXTRMATN:
case MCU_DRTOPPEL:
case MCU_PLUMPOP:
mcu_extrmatn_w(space,offset,data);
mcu_extrmatn_w(space, offset, data);
break;
default:
break;
@ -606,9 +610,10 @@ WRITE8_HANDLER( tnzs_mcu_w )
INTERRUPT_GEN( arknoid2_interrupt )
{
tnzs_state *state = (tnzs_state *)device->machine->driver_data;
int coin;
switch (mcu_type)
switch (state->mcu_type)
{
case MCU_ARKANOID:
case MCU_EXTRMATN:
@ -619,7 +624,7 @@ INTERRUPT_GEN( arknoid2_interrupt )
coin |= ((input_port_read(device->machine, "COIN2") & 1) << 1);
coin |= ((input_port_read(device->machine, "IN2") & 3) << 2);
coin ^= 0x0c;
mcu_handle_coins(coin);
mcu_handle_coins(device->machine, coin);
break;
default:
break;
@ -630,37 +635,81 @@ INTERRUPT_GEN( arknoid2_interrupt )
MACHINE_RESET( tnzs )
{
tnzs_state *state = (tnzs_state *)machine->driver_data;
/* initialize the mcu simulation */
switch (mcu_type)
switch (state->mcu_type)
{
case MCU_ARKANOID:
case MCU_EXTRMATN:
case MCU_DRTOPPEL:
case MCU_PLUMPOP:
mcu_reset();
mcu_reset(machine);
break;
default:
break;
}
/* preset the banks */
{
UINT8 *RAM;
RAM = memory_region(machine, "maincpu");
memory_set_bankptr(machine, 1,&RAM[0x18000]);
RAM = memory_region(machine, "sub");
memory_set_bankptr(machine, 2,&RAM[0x10000]);
}
state->screenflip = 0;
state->kageki_csport_sel = 0;
state->input_select = 0;
state->mcu_readcredits = 0; // this might belong to mcu_reset
state->insertcoin = 0; // this might belong to mcu_reset
}
MACHINE_RESET( jpopnics )
{
tnzs_state *state = (tnzs_state *)machine->driver_data;
state->screenflip = 0;
state->mcu_type = -1;
}
MACHINE_START( tnzs )
{
tnzs_state *state = (tnzs_state *)machine->driver_data;
UINT8 *ROM = memory_region(machine, "maincpu");
UINT8 *SUB = memory_region(machine, "sub");
memory_configure_bank(machine, 1, 0, 8, &ROM[0x10000], 0x4000);
memory_configure_bank(machine, 2, 0, 4, &SUB[0x10000], 0x2000);
memory_set_bank(machine, 1, 2);
memory_set_bank(machine, 2, 0);
state->mcu = cputag_get_cpu(machine, "mcu");
state_save_register_global(machine, state->screenflip);
state_save_register_global(machine, state->kageki_csport_sel);
state_save_register_global(machine, state->input_select);
state_save_register_global(machine, state->mcu_readcredits);
state_save_register_global(machine, state->insertcoin);
state_save_register_global(machine, state->mcu_initializing);
state_save_register_global(machine, state->mcu_coinage_init);
state_save_register_global_array(machine, state->mcu_coinage);
state_save_register_global(machine, state->mcu_coins_a);
state_save_register_global(machine, state->mcu_coins_b);
state_save_register_global(machine, state->mcu_credits);
state_save_register_global(machine, state->mcu_reportcoin);
state_save_register_global(machine, state->mcu_command);
}
MACHINE_START( jpopnics )
{
tnzs_state *state = (tnzs_state *)machine->driver_data;
UINT8 *ROM = memory_region(machine, "maincpu");
UINT8 *SUB = memory_region(machine, "sub");
memory_configure_bank(machine, 1, 0, 8, &ROM[0x10000], 0x4000);
memory_configure_bank(machine, 2, 0, 4, &SUB[0x10000], 0x2000);
state->mcu = NULL;
state_save_register_global(machine, state->screenflip);
}
WRITE8_HANDLER( tnzs_bankswitch_w )
{
UINT8 *RAM = memory_region(space->machine, "maincpu");
// logerror("PC %04x: writing %02x to bankswitch\n", cpu_get_pc(space->cpu),data);
/* bit 4 resets the second CPU */
@ -670,44 +719,43 @@ WRITE8_HANDLER( tnzs_bankswitch_w )
cputag_set_input_line(space->machine, "sub", INPUT_LINE_RESET, ASSERT_LINE);
/* bits 0-2 select RAM/ROM bank */
memory_set_bankptr (space->machine, 1, &RAM[0x10000 + 0x4000 * (data & 0x07)]);
memory_set_bank(space->machine, 1, data & 0x07);
}
WRITE8_HANDLER( tnzs_bankswitch1_w )
{
UINT8 *RAM = memory_region(space->machine, "sub");
tnzs_state *state = (tnzs_state *)space->machine->driver_data;
// logerror("PC %04x: writing %02x to bankswitch 1\n", cpu_get_pc(space->cpu),data);
switch (mcu_type)
switch (state->mcu_type)
{
case MCU_TNZS:
case MCU_CHUKATAI:
/* bit 2 resets the mcu */
if (data & 0x04)
{
if (cputag_get_cpu(space->machine, "mcu") != NULL && cpu_get_type(cputag_get_cpu(space->machine, "mcu")) == CPU_I8742)
if (state->mcu != NULL && cpu_get_type(state->mcu) == CPU_I8742)
cputag_set_input_line(space->machine, "mcu", INPUT_LINE_RESET, PULSE_LINE);
}
/* Coin count and lockout is handled by the i8742 */
break;
case MCU_NONE_INSECTX:
coin_lockout_w( 0, (~data & 0x04) );
coin_lockout_w( 1, (~data & 0x08) );
coin_counter_w( 0, (data & 0x10) );
coin_counter_w( 1, (data & 0x20) );
coin_lockout_w(0, (~data & 0x04));
coin_lockout_w(1, (~data & 0x08));
coin_counter_w(0, (data & 0x10));
coin_counter_w(1, (data & 0x20));
break;
case MCU_NONE_TNZSB:
case MCU_NONE_KABUKIZ:
coin_lockout_w( 0, (~data & 0x10) );
coin_lockout_w( 1, (~data & 0x20) );
coin_counter_w( 0, (data & 0x04) );
coin_counter_w( 1, (data & 0x08) );
coin_lockout_w(0, (~data & 0x10));
coin_lockout_w(1, (~data & 0x20));
coin_counter_w(0, (data & 0x04));
coin_counter_w(1, (data & 0x08));
break;
case MCU_NONE_KAGEKI:
coin_lockout_global_w( (~data & 0x20) );
coin_counter_w( 0, (data & 0x04) );
coin_counter_w( 1, (data & 0x08) );
coin_lockout_global_w((~data & 0x20));
coin_counter_w(0, (data & 0x04));
coin_counter_w(1, (data & 0x08));
break;
case MCU_ARKANOID:
case MCU_EXTRMATN:
@ -715,12 +763,12 @@ WRITE8_HANDLER( tnzs_bankswitch1_w )
case MCU_PLUMPOP:
/* bit 2 resets the mcu */
if (data & 0x04)
mcu_reset();
mcu_reset(space->machine);
break;
default:
break;
}
/* bits 0-1 select ROM bank */
memory_set_bankptr (space->machine, 2, &RAM[0x10000 + 0x2000 * (data & 3)]);
memory_set_bank(space->machine, 2, data & 0x03);
}

View File

@ -5,14 +5,11 @@
Functions to emulate the video hardware of the machine.
***************************************************************************/
#include "driver.h"
#include "includes/tnzs.h"
#include <ctype.h>
static int tnzs_screenflip;
/***************************************************************************
The New Zealand Story doesn't have a color PROM. It uses 1024 bytes of RAM
@ -32,33 +29,33 @@ static int tnzs_screenflip;
form 512 xRRRRRGGGGGBBBBB color values.
***************************************************************************/
PALETTE_INIT( arknoid2 )
{
int i,col;
int i, col;
for (i = 0;i < machine->config->total_colors;i++)
for (i = 0; i < machine->config->total_colors; i++)
{
col = (color_prom[i]<<8)+color_prom[i+512];
palette_set_color_rgb(machine,i,pal5bit(col >> 10),pal5bit(col >> 5),pal5bit(col >> 0));
col = (color_prom[i] << 8) + color_prom[i + 512];
palette_set_color_rgb(machine, i, pal5bit(col >> 10), pal5bit(col >> 5), pal5bit(col >> 0));
}
}
static void draw_background(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, UINT8 *m)
static void draw_background( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, UINT8 *m )
{
int x,y,column,tot,transpen;
tnzs_state *state = (tnzs_state *)machine->driver_data;
int x, y, column, tot, transpen;
int scrollx, scrolly;
UINT32 upperbits;
int ctrl2 = tnzs_objctrl[1];
int ctrl2 = state->objctrl[1];
if ((ctrl2 ^ (~ctrl2<<1)) & 0x40)
{
if ((ctrl2 ^ (~ctrl2 << 1)) & 0x40)
m += 0x800;
}
if(tnzs_bg_flag[0] & 0x80)
if (state->bg_flag[0] & 0x80)
transpen = -1;
else
transpen = 0;
@ -73,34 +70,34 @@ static void draw_background(running_machine *machine, bitmap_t *bitmap, const re
at f302-f303 */
/* f301 controls how many columns are drawn. */
tot = tnzs_objctrl[1] & 0x1f;
if (tot == 1) tot = 16;
tot = state->objctrl[1] & 0x1f;
if (tot == 1)
tot = 16;
upperbits = tnzs_objctrl[2] + tnzs_objctrl[3] * 256;
upperbits = state->objctrl[2] + state->objctrl[3] * 256;
for (column = 0;column < tot;column++)
for (column = 0; column < tot; column++)
{
scrollx = tnzs_scrollram[column*16+4] - ((upperbits & 0x01) * 256);
if (tnzs_screenflip)
scrolly = tnzs_scrollram[column*16] + 1 - 256;
scrollx = state->scrollram[column * 16 + 4] - ((upperbits & 0x01) * 256);
if (state->screenflip)
scrolly = state->scrollram[column * 16] + 1 - 256;
else
scrolly = -tnzs_scrollram[column*16] + 1;
scrolly = -state->scrollram[column * 16] + 1;
for (y=0;y<16;y++)
for (y = 0; y < 16; y++)
{
for (x=0;x<2;x++)
for (x = 0; x < 2; x++)
{
int code,color,flipx,flipy,sx,sy;
int i = 32*(column^8) + 2*y + x;
int code, color, flipx, flipy, sx, sy;
int i = 32 * (column ^ 8) + 2 * y + x;
code = m[i] + ((m[i + 0x1000] & 0x3f) << 8);
color = (m[i + 0x1200] & 0xf8) >> 3; /* colours at d600-d7ff */
sx = x*16;
sy = y*16;
sx = x * 16;
sy = y * 16;
flipx = m[i + 0x1000] & 0x80;
flipy = m[i + 0x1000] & 0x40;
if (tnzs_screenflip)
if (state->screenflip)
{
sy = 240 - sy;
flipx = !flipx;
@ -124,26 +121,20 @@ static void draw_background(running_machine *machine, bitmap_t *bitmap, const re
}
}
upperbits >>= 1;
}
}
static void draw_foreground(running_machine *machine,
bitmap_t *bitmap,
const rectangle *cliprect,
UINT8 *char_pointer,
UINT8 *x_pointer,
UINT8 *y_pointer,
UINT8 *ctrl_pointer,
UINT8 *color_pointer)
static void draw_foreground( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect,
UINT8 *char_pointer, UINT8 *x_pointer, UINT8 *y_pointer, UINT8 *ctrl_pointer, UINT8 *color_pointer)
{
tnzs_state *state = (tnzs_state *)machine->driver_data;
int i;
int ctrl2 = tnzs_objctrl[1];
int ctrl2 = state->objctrl[1];
if ((ctrl2 ^ (~ctrl2<<1)) & 0x40)
if ((ctrl2 ^ (~ctrl2 << 1)) & 0x40)
{
char_pointer += 0x800;
x_pointer += 0x800;
@ -153,9 +144,9 @@ static void draw_foreground(running_machine *machine,
/* Draw all 512 sprites */
for (i=0x1ff;i >= 0;i--)
for (i = 0x1ff; i >= 0; i--)
{
int code,color,sx,sy,flipx,flipy;
int code, color, sx, sy, flipx, flipy;
code = char_pointer[i] + ((ctrl_pointer[i] & 0x3f) << 8);
color = (color_pointer[i] & 0xf8) >> 3;
@ -163,7 +154,7 @@ static void draw_foreground(running_machine *machine,
sy = 240 - y_pointer[i];
flipx = ctrl_pointer[i] & 0x80;
flipy = ctrl_pointer[i] & 0x40;
if (tnzs_screenflip)
if (state->screenflip)
{
sy = 240 - sy;
flipx = !flipx;
@ -189,46 +180,48 @@ static void draw_foreground(running_machine *machine,
VIDEO_UPDATE( tnzs )
{
tnzs_state *state = (tnzs_state *)screen->machine->driver_data;
/* If the byte at f300 has bit 6 set, flip the screen
(I'm not 100% sure about this) */
tnzs_screenflip = (tnzs_objctrl[0] & 0x40) >> 6;
state->screenflip = (state->objctrl[0] & 0x40) >> 6;
/* Fill the background */
bitmap_fill(bitmap, cliprect, 0x1f0);
/* Redraw the background tiles (c400-c5ff) */
draw_background(screen->machine, bitmap, cliprect, tnzs_objram + 0x400);
draw_background(screen->machine, bitmap, cliprect, state->objram + 0x400);
/* Draw the sprites on top */
draw_foreground(screen->machine, bitmap, cliprect,
tnzs_objram + 0x0000, /* chars : c000 */
tnzs_objram + 0x0200, /* x : c200 */
tnzs_vdcram + 0x0000, /* y : f000 */
tnzs_objram + 0x1000, /* ctrl : d000 */
tnzs_objram + 0x1200); /* color : d200 */
state->objram + 0x0000, /* chars : c000 */
state->objram + 0x0200, /* x : c200 */
state->vdcram + 0x0000, /* y : f000 */
state->objram + 0x1000, /* ctrl : d000 */
state->objram + 0x1200); /* color : d200 */
return 0;
}
VIDEO_EOF( tnzs )
{
int ctrl2 = tnzs_objctrl[1];
tnzs_state *state = (tnzs_state *)machine->driver_data;
int ctrl2 = state->objctrl[1];
if (~ctrl2 & 0x20)
{
// note I copy sprites only. seta.c also copies the "floating tilemap"
if (ctrl2 & 0x40)
{
memcpy(&tnzs_objram[0x0000],&tnzs_objram[0x0800],0x0400);
memcpy(&tnzs_objram[0x1000],&tnzs_objram[0x1800],0x0400);
memcpy(&state->objram[0x0000], &state->objram[0x0800], 0x0400);
memcpy(&state->objram[0x1000], &state->objram[0x1800], 0x0400);
}
else
{
memcpy(&tnzs_objram[0x0800],&tnzs_objram[0x0000],0x0400);
memcpy(&tnzs_objram[0x1800],&tnzs_objram[0x1000],0x0400);
memcpy(&state->objram[0x0800], &state->objram[0x0000], 0x0400);
memcpy(&state->objram[0x1800], &state->objram[0x1000], 0x0400);
}
// and I copy the "floating tilemap" BACKWARDS - this fixes kabukiz
memcpy(&tnzs_objram[0x0400],&tnzs_objram[0x0c00],0x0400);
memcpy(&tnzs_objram[0x1400],&tnzs_objram[0x1c00],0x0400);
memcpy(&state->objram[0x0400], &state->objram[0x0c00], 0x0400);
memcpy(&state->objram[0x1400], &state->objram[0x1c00], 0x0400);
}
}