diff options
author | Zsolt Vasvari <zsoltvas@mamedev.org> | 2008-03-06 03:45:15 +0000 |
---|---|---|
committer | Zsolt Vasvari <zsoltvas@mamedev.org> | 2008-03-06 03:45:15 +0000 |
commit | c537f056f5639c7c5a5f59fe5f6d001761a06f85 (patch) | |
tree | 5802b05970bebe911f21076c5a4aa2abfd5b3f9f | |
parent | 19331ed13497c5ee138316a1502af58d976c54e8 (diff) |
Mysterious Stones gets the "full treatment"
-rw-r--r-- | .gitattributes | 1 | ||||
-rw-r--r-- | src/mame/drivers/mystston.c | 287 | ||||
-rw-r--r-- | src/mame/includes/mystston.h | 41 | ||||
-rw-r--r-- | src/mame/video/mystston.c | 337 |
4 files changed, 420 insertions, 246 deletions
diff --git a/.gitattributes b/.gitattributes index b13192ccde2..0169d61b638 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2237,6 +2237,7 @@ src/mame/includes/midwunit.h svneol=native#text/plain src/mame/includes/midyunit.h svneol=native#text/plain src/mame/includes/midzeus.h svneol=native#text/plain src/mame/includes/mw8080bw.h svneol=native#text/plain +src/mame/includes/mystston.h svneol=native#text/plain src/mame/includes/n64.h svneol=native#text/plain src/mame/includes/n8080.h svneol=native#text/plain src/mame/includes/nam_cust.h svneol=native#text/plain diff --git a/src/mame/drivers/mystston.c b/src/mame/drivers/mystston.c index 1d46c7246ad..69480c3ccba 100644 --- a/src/mame/drivers/mystston.c +++ b/src/mame/drivers/mystston.c @@ -1,124 +1,145 @@ /*************************************************************************** -Mysterious Stones + Technos Mysterious Stones hardware -driver by Nicola Salmoria + driver by Nicola Salmoria -Notes: -- The subtitle of the two sets is slightly different: - "dr john s adventure" vs. "dr kick in adventure". - The Dr John's is a bug fix. See the routine at 4376/4384 for example. The - old set thrashes the Y register, the new one saves in on the stack. The - newer set also resets the sound chips more often. + Notes: + * The subtitle of the two sets is slightly different: + "Dr. John's Adventure" vs. "Dr. Kick in Adventure". + The Dr John's is a bug fix. See the routine at 4376/4384 for example. + The old set thrashes the Y register, the new one saves in on + the stack. The newer set also resets the audio chips more often. ***************************************************************************/ #include "driver.h" -#include "deprecat.h" #include "sound/ay8910.h" +#include "mystston.h" -extern UINT8 *mystston_videoram2; -extern WRITE8_HANDLER( mystston_videoram_w ); -extern WRITE8_HANDLER( mystston_videoram2_w ); -extern WRITE8_HANDLER( mystston_scroll_w ); -extern WRITE8_HANDLER( mystston_control_w ); +/************************************* + * + * Clocks + * + *************************************/ -extern PALETTE_INIT( mystston ); -extern VIDEO_START( mystston ); -extern VIDEO_UPDATE( mystston ); +#define CPU_CLOCK (MYSTSTON_MASTER_CLOCK / 8) +#define AY8910_CLOCK (MYSTSTON_MASTER_CLOCK / 8) -static int VBLK = 0x80; -static int soundlatch; +/************************************* + * + * Interrupt system + * + *************************************/ -static WRITE8_HANDLER( mystston_soundlatch_w ) +void mystston_on_scanline_interrupt(running_machine *machine) { - soundlatch = data; + cpunum_set_input_line(machine, 0, 0, ASSERT_LINE); } -static WRITE8_HANDLER( mystston_soundcontrol_w ) + +static WRITE8_HANDLER( irq_clear_w ) +{ + cpunum_set_input_line(machine, 0, 0, CLEAR_LINE); +} + + + +/************************************* + * + * Coin handling + * + *************************************/ + +static INPUT_CHANGED( coin_inserted ) +{ + /* coin insertion causes an NMI */ + cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE); +} + + + +/************************************* + * + * AY-8910 memory interface + * + *************************************/ + +static WRITE8_HANDLER( mystston_ay8910_select_w ) { - static int last; + mystston_state *state = machine->driver_data; - /* bit 5 goes to 8910 #0 BDIR pin */ - if ((last & 0x20) == 0x20 && (data & 0x20) == 0x00) + /* bit 5 goes to 8910 #0 BDIR pin */ + if (((*state->ay8910_select & 0x20) == 0x20) && ((data & 0x20) == 0x00)) { /* bit 4 goes to the 8910 #0 BC1 pin */ - if (last & 0x10) - AY8910_control_port_0_w(machine,0,soundlatch); + if (*state->ay8910_select & 0x10) + AY8910_control_port_0_w(machine, 0, *state->ay8910_data); else - AY8910_write_port_0_w(machine,0,soundlatch); + AY8910_write_port_0_w(machine, 0, *state->ay8910_data); } - /* bit 7 goes to 8910 #1 BDIR pin */ - if ((last & 0x80) == 0x80 && (data & 0x80) == 0x00) + + /* bit 7 goes to 8910 #1 BDIR pin */ + if (((*state->ay8910_select & 0x80) == 0x80) && ((data & 0x80) == 0x00)) { /* bit 6 goes to the 8910 #1 BC1 pin */ - if (last & 0x40) - AY8910_control_port_1_w(machine,0,soundlatch); + if (*state->ay8910_select & 0x40) + AY8910_control_port_1_w(machine, 0, *state->ay8910_data); else - AY8910_write_port_1_w(machine,0,soundlatch); + AY8910_write_port_1_w(machine, 0, *state->ay8910_data); } - last = data; -} - -static READ8_HANDLER( port3_r ) -{ - int port = readinputport(3); - - return port | VBLK; + *state->ay8910_select = data; } -static WRITE8_HANDLER( mystston_irq_reset_w ) -{ - cpunum_set_input_line(Machine, 0, 0, CLEAR_LINE); -} -static ADDRESS_MAP_START( readmem, ADDRESS_SPACE_PROGRAM, 8 ) - AM_RANGE(0x0000, 0x077f) AM_READ(MRA8_RAM) - AM_RANGE(0x0800, 0x0fff) AM_READ(MRA8_RAM) /* work RAM? */ - AM_RANGE(0x1000, 0x1fff) AM_READ(MRA8_RAM) - AM_RANGE(0x2000, 0x2000) AM_READ(input_port_0_r) - AM_RANGE(0x2010, 0x2010) AM_READ(input_port_1_r) - AM_RANGE(0x2020, 0x2020) AM_READ(input_port_2_r) - AM_RANGE(0x2030, 0x2030) AM_READ(port3_r) - AM_RANGE(0x4000, 0xffff) AM_READ(MRA8_ROM) +/************************************* + * + * Memory map + * + *************************************/ + +static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 ) + AM_RANGE(0x0000, 0x077f) AM_RAM + AM_RANGE(0x0780, 0x07df) AM_RAM AM_BASE_MEMBER(mystston_state, spriteram) + AM_RANGE(0x07e0, 0x0fff) AM_RAM + AM_RANGE(0x1000, 0x17ff) AM_RAM AM_BASE_MEMBER(mystston_state, fg_videoram) + AM_RANGE(0x1800, 0x1fff) AM_RAM AM_BASE_MEMBER(mystston_state, bg_videoram) + AM_RANGE(0x2000, 0x2000) AM_MIRROR(0x1f8f) AM_READWRITE(port_tag_to_handler8("IN0"), mystston_video_control_w) AM_BASE_MEMBER(mystston_state, video_control) + AM_RANGE(0x2010, 0x2010) AM_MIRROR(0x1f8f) AM_READWRITE(port_tag_to_handler8("IN1"), irq_clear_w) + AM_RANGE(0x2020, 0x2020) AM_MIRROR(0x1f8f) AM_READWRITE(port_tag_to_handler8("DSW0"), MWA8_RAM) AM_BASE_MEMBER(mystston_state, scroll) + AM_RANGE(0x2030, 0x2030) AM_MIRROR(0x1f8f) AM_READWRITE(port_tag_to_handler8("DSW1"), MWA8_RAM) AM_BASE_MEMBER(mystston_state, ay8910_data) + AM_RANGE(0x2040, 0x2040) AM_MIRROR(0x1f8f) AM_READWRITE(MRA8_NOP, mystston_ay8910_select_w) AM_BASE_MEMBER(mystston_state, ay8910_select) + AM_RANGE(0x2050, 0x2050) AM_MIRROR(0x1f8f) AM_NOP + AM_RANGE(0x2060, 0x207f) AM_MIRROR(0x1f80) AM_RAM AM_BASE_MEMBER(mystston_state, paletteram) + AM_RANGE(0x4000, 0xffff) AM_ROM ADDRESS_MAP_END -static ADDRESS_MAP_START( writemem, ADDRESS_SPACE_PROGRAM, 8 ) - AM_RANGE(0x0000, 0x077f) AM_WRITE(MWA8_RAM) - AM_RANGE(0x0780, 0x07df) AM_WRITE(MWA8_RAM) AM_BASE(&spriteram) AM_SIZE(&spriteram_size) - AM_RANGE(0x07e0, 0x07ff) AM_WRITE(MWA8_RAM) - AM_RANGE(0x0800, 0x0fff) AM_WRITE(MWA8_RAM) /* work RAM? */ - AM_RANGE(0x1000, 0x17ff) AM_WRITE(mystston_videoram_w) AM_BASE(&videoram) - AM_RANGE(0x1800, 0x1bff) AM_WRITE(mystston_videoram2_w) AM_BASE(&mystston_videoram2) - AM_RANGE(0x1c00, 0x1fff) AM_WRITE(MWA8_RAM) /* work RAM? This gets copied to videoram */ - AM_RANGE(0x2000, 0x2000) AM_WRITE(mystston_control_w) /* text color, flip screen & coin counters */ - AM_RANGE(0x2010, 0x2010) AM_WRITE(mystston_irq_reset_w) - AM_RANGE(0x2020, 0x2020) AM_WRITE(mystston_scroll_w) - AM_RANGE(0x2030, 0x2030) AM_WRITE(mystston_soundlatch_w) - AM_RANGE(0x2040, 0x2040) AM_WRITE(mystston_soundcontrol_w) - AM_RANGE(0x2060, 0x2077) AM_WRITE(paletteram_BBGGGRRR_w) AM_BASE(&paletteram) - AM_RANGE(0x4000, 0xffff) AM_WRITE(MWA8_ROM) -ADDRESS_MAP_END +/************************************* + * + * Input ports + * + *************************************/ + static INPUT_PORTS_START( mystston ) - PORT_START /* IN0 */ + PORT_START_TAG("IN0") PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) - PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(1) - PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_IMPULSE(1) + PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_CHANGED(coin_inserted, 0) + PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_CHANGED(coin_inserted, 0) - PORT_START /* IN1 */ + PORT_START_TAG("IN1") PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY PORT_COCKTAIL PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY PORT_COCKTAIL PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY PORT_COCKTAIL @@ -128,7 +149,7 @@ static INPUT_PORTS_START( mystston ) PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 ) PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START2 ) - PORT_START /* DSW1 */ + PORT_START_TAG("DSW0") PORT_DIPNAME(0x01, 0x01, DEF_STR( Lives ) ) PORT_DIPSETTING( 0x01, "3" ) PORT_DIPSETTING( 0x00, "5" ) @@ -154,7 +175,7 @@ static INPUT_PORTS_START( mystston ) PORT_DIPSETTING( 0x80, DEF_STR( Off ) ) PORT_DIPSETTING( 0x00, DEF_STR( On ) ) - PORT_START /* DSW2 */ + PORT_START_TAG("DSW1") PORT_DIPNAME(0x03, 0x03, DEF_STR( Coin_A ) ) PORT_DIPSETTING( 0x00, DEF_STR( 2C_1C ) ) PORT_DIPSETTING( 0x03, DEF_STR( 1C_1C ) ) @@ -174,106 +195,46 @@ static INPUT_PORTS_START( mystston ) PORT_DIPNAME(0x40, 0x00, DEF_STR( Cabinet ) ) PORT_DIPSETTING( 0x00, DEF_STR( Upright ) ) PORT_DIPSETTING( 0x40, DEF_STR( Cocktail ) ) - PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SPECIAL ) // VBLANK + PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_VBLANK ) INPUT_PORTS_END -static const gfx_layout charlayout = -{ - 8,8, - RGN_FRAC(1,3), - 3, - { RGN_FRAC(2,3), RGN_FRAC(1,3), RGN_FRAC(0,3) }, - { 0, 1, 2, 3, 4, 5, 6, 7 }, - { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 }, - 8*8 -}; - -static const gfx_layout spritelayout = -{ - 16,16, - RGN_FRAC(1,3), - 3, - { RGN_FRAC(2,3), RGN_FRAC(1,3), RGN_FRAC(0,3) }, - { 16*8+0, 16*8+1, 16*8+2, 16*8+3, 16*8+4, 16*8+5, 16*8+6, 16*8+7, - 0, 1, 2, 3, 4, 5, 6, 7 }, - { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, - 8*8, 9*8, 10*8, 11*8, 12*8, 13*8, 14*8, 15*8 }, - 32*8 -}; - -static GFXDECODE_START( mystston ) - GFXDECODE_ENTRY( REGION_GFX1, 0, charlayout, 3*8, 4 ) - GFXDECODE_ENTRY( REGION_GFX2, 0, spritelayout, 2*8, 1 ) - GFXDECODE_ENTRY( REGION_GFX1, 0, spritelayout, 0*8, 2 ) -GFXDECODE_END - - -static INTERRUPT_GEN( mystston_interrupt ) -{ - int scanline = 271 - cpu_getiloops(); - static int coin; - - /* Inserting a coin triggers an NMI */ - if ((readinputport(0) & 0xc0) != 0xc0) - { - if (coin == 0) - { - coin = 1; - nmi_line_pulse(machine, cpunum); - return; - } - } - else coin = 0; - - /* VBLK is lowered on scanline 8 */ - if (scanline == 8) - VBLK = 0; - - /* VBLK is raised on scanline 248 */ - if (scanline == 248) - VBLK = 0x80; - - /* IMS is triggered every time VLOC line 3 is raised, - as VLOC counter starts at 16, effectively every 16 scanlines */ - if ((scanline % 16) == 0) - cpunum_set_input_line(machine, 0, 0, ASSERT_LINE); -} +/************************************* + * + * Machine driver + * + *************************************/ static MACHINE_DRIVER_START( mystston ) + MDRV_DRIVER_DATA(mystston_state) + /* basic machine hardware */ - MDRV_CPU_ADD(M6502, 12000000/8) // 1.5 MHz - MDRV_CPU_PROGRAM_MAP(readmem, writemem) - MDRV_CPU_VBLANK_INT_HACK(mystston_interrupt, 272) + MDRV_CPU_ADD(M6502, CPU_CLOCK) + MDRV_CPU_PROGRAM_MAP(main_map,0) /* video hardware */ - MDRV_SCREEN_ADD("main", RASTER) - MDRV_SCREEN_REFRESH_RATE(((12000000.0 / 256.0) / 3.0) / 272.0) - MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) - MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) - MDRV_SCREEN_SIZE(32*8, 32*8) - MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 1*8, 31*8-1) - - MDRV_GFXDECODE(mystston) - MDRV_PALETTE_LENGTH(24+32) - - MDRV_PALETTE_INIT(mystston) - MDRV_VIDEO_START(mystston) - MDRV_VIDEO_UPDATE(mystston) + MDRV_IMPORT_FROM(mystston_video) - /* sound hardware */ + /* audio hardware */ MDRV_SPEAKER_STANDARD_MONO("mono") - MDRV_SOUND_ADD(AY8910, 12000000/8) + MDRV_SOUND_ADD(AY8910, AY8910_CLOCK) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30) - MDRV_SOUND_ADD(AY8910, 12000000/8) + MDRV_SOUND_ADD(AY8910, AY8910_CLOCK) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30) MACHINE_DRIVER_END + +/************************************* + * + * ROM definitions + * + *************************************/ + ROM_START( mystston ) ROM_REGION( 0x10000, REGION_CPU1, 0 ) ROM_LOAD( "rom6.bin", 0x4000, 0x2000, CRC(7bd9c6cd) SHA1(4d14edc783ba1a6c01d2fb9ea29ec85b8fec3c3b) ) @@ -303,6 +264,7 @@ ROM_START( mystston ) ROM_LOAD( "ic61", 0x0000, 0x0020, CRC(e802d6cf) SHA1(233ceb9e3a91939e1925766a696bc65ab0dffa50) ) ROM_END + ROM_START( myststno ) ROM_REGION( 0x10000, REGION_CPU1, 0 ) ROM_LOAD( "ms0", 0x4000, 0x2000, CRC(6dacc05f) SHA1(43054199901639516205c7ea145462d0abea8fb1) ) @@ -333,5 +295,12 @@ ROM_START( myststno ) ROM_END -GAME( 1984, mystston, 0, mystston, mystston, 0, ROT270, "Technos", "Mysterious Stones - Dr. John's Adventure", 0 ) -GAME( 1984, myststno, mystston, mystston, mystston, 0, ROT270, "Technos", "Mysterious Stones - Dr. Kick in Adventure", 0 ) + +/************************************* + * + * Game drivers + * + *************************************/ + +GAME( 1984, mystston, 0, mystston, mystston, 0, ROT270, "Technos", "Mysterious Stones - Dr. John's Adventure", GAME_SUPPORTS_SAVE ) +GAME( 1984, myststno, mystston, mystston, mystston, 0, ROT270, "Technos", "Mysterious Stones - Dr. Kick in Adventure", GAME_SUPPORTS_SAVE ) diff --git a/src/mame/includes/mystston.h b/src/mame/includes/mystston.h new file mode 100644 index 00000000000..0afe1e2a18a --- /dev/null +++ b/src/mame/includes/mystston.h @@ -0,0 +1,41 @@ +/*************************************************************************** + + Technos Mysterious Stones hardware + + driver by Nicola Salmoria + +***************************************************************************/ + + +#define MYSTSTON_MASTER_CLOCK (XTAL_12MHz) + + +typedef struct _mystston_state mystston_state; +struct _mystston_state +{ + /* machine state */ + UINT8 *ay8910_data; + UINT8 *ay8910_select; + + /* video state */ + tilemap *fg_tilemap; + tilemap *bg_tilemap; + emu_timer *interrupt_timer; + UINT8 *bg_videoram; + UINT8 *fg_videoram; + UINT8 *spriteram; + UINT8 *paletteram; + UINT8 *scroll; + UINT8 *video_control; +}; + + +/*----------- defined in drivers/mystston.c -----------*/ + +void mystston_on_scanline_interrupt(running_machine *machine); + + +/*----------- defined in video/mystston.c -----------*/ + +MACHINE_DRIVER_EXTERN( mystston_video ); +WRITE8_HANDLER( mystston_video_control_w ); diff --git a/src/mame/video/mystston.c b/src/mame/video/mystston.c index 0a602539490..60c17393407 100644 --- a/src/mame/video/mystston.c +++ b/src/mame/video/mystston.c @@ -1,8 +1,8 @@ /*************************************************************************** - video.c + Technos Mysterious Stones hardware - Functions to emulate the video hardware of the machine. + driver by Nicola Salmoria There are only a few differences between the video hardware of Mysterious Stones and Mat Mania. The tile bank select bit is different and the sprite @@ -13,160 +13,323 @@ ***************************************************************************/ #include "driver.h" +#include "video/resnet.h" +#include "mystston.h" -UINT8 *mystston_videoram2; -static int mystston_fgcolor, mystston_bgpage; +/************************************* + * + * Video timing constants + * + *************************************/ -static tilemap *fg_tilemap, *bg_tilemap; +#define PIXEL_CLOCK (MYSTSTON_MASTER_CLOCK / 2) +#define HTOTAL (0x140) +#define HBEND (0x000) +#define HBSTART (0x100) +#define VTOTAL (0x110) /* counts from 0x08-0xff, then from 0xe8-0xff */ +#define VBEND (0x008) +#define VBSTART (0x0f8) +#define FIRST_INT_VPOS (0x008) +#define INT_HPOS (0x100) -/*************************************************************************** - - Convert the color PROMs into a more useable format. - Mysterious Stones has both palette RAM and a PROM. The PROM is used for - text. -***************************************************************************/ +/************************************* + * + * Scanline interrupt system + * + * There is an interrupt every 16 + * scanlines, starting with 8. + * + *************************************/ -PALETTE_INIT( mystston ) +static TIMER_CALLBACK( interrupt_callback ) { - int i; + mystston_state *state = machine->driver_data; + int scanline = param; - for (i = 0; i < 32; i++) - { - int bit0, bit1, bit2, r, g, b; + mystston_on_scanline_interrupt(machine); - // red component + scanline = scanline + 16; + if (scanline >= VTOTAL) + scanline = FIRST_INT_VPOS; - bit0 = (*color_prom >> 0) & 0x01; - bit1 = (*color_prom >> 1) & 0x01; - bit2 = (*color_prom >> 2) & 0x01; - - r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - - // green component + /* the vertical synch chain is clocked by H256 -- this is probably not important, but oh well */ + timer_adjust_oneshot(state->interrupt_timer, video_screen_get_time_until_pos(0, scanline - 1, INT_HPOS), scanline); +} - bit0 = (*color_prom >> 3) & 0x01; - bit1 = (*color_prom >> 4) & 0x01; - bit2 = (*color_prom >> 5) & 0x01; - g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - // blue component +/************************************* + * + * Palette handling + * + *************************************/ - bit0 = 0; - bit1 = (*color_prom >> 6) & 0x01; - bit2 = (*color_prom >> 7) & 0x01; +static void set_palette(running_machine *machine, mystston_state *state) +{ + int i; + static const int resistances_rg[3] = { 4700, 3300, 1500 }; + static const int resistances_b [2] = { 3300, 1500 }; + double weights_rg[3], weights_b[2]; - b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; + UINT8 *color_prom = memory_region(REGION_PROMS); - palette_set_color(machine, i + 24, MAKE_RGB(r, g, b)); // first 24 colors are from RAM + compute_resistor_weights(0, 255, -1.0, + 3, resistances_rg, weights_rg, 0, 1000, + 2, resistances_b, weights_b, 0, 1000, + 0, 0, 0, 0, 0); - color_prom++; + for (i = 0; i < 0x40; i++) + { + UINT8 data; + int r, g, b; + int bit0, bit1, bit2; + + /* first half is dynamic, second half is from the PROM */ + if (i & 0x20) + data = color_prom[i & 0x1f]; + else + data = state->paletteram[i]; + + /* red component */ + bit0 = (data >> 0) & 0x01; + bit1 = (data >> 1) & 0x01; + bit2 = (data >> 2) & 0x01; + r = combine_3_weights(weights_rg, bit0, bit1, bit2); + + /* green component */ + bit0 = (data >> 3) & 0x01; + bit1 = (data >> 4) & 0x01; + bit2 = (data >> 5) & 0x01; + g = combine_3_weights(weights_rg, bit0, bit1, bit2); + + /* blue component */ + bit0 = (data >> 6) & 0x01; + bit1 = (data >> 7) & 0x01; + b = combine_2_weights(weights_b, bit0, bit1); + + palette_set_color(machine, i, MAKE_RGB(r, g, b)); } } -WRITE8_HANDLER( mystston_videoram_w ) -{ - videoram[offset] = data; - tilemap_mark_tile_dirty(fg_tilemap, offset & 0x3ff); -} -WRITE8_HANDLER( mystston_videoram2_w ) -{ - mystston_videoram2[offset] = data; - tilemap_mark_tile_dirty(bg_tilemap, offset & 0x1ff); -} -WRITE8_HANDLER( mystston_scroll_w ) -{ - tilemap_set_scrolly(bg_tilemap, 0, data); -} +/************************************* + * + * Video control register + * + *************************************/ -WRITE8_HANDLER( mystston_control_w ) +WRITE8_HANDLER( mystston_video_control_w ) { - // bits 0 and 1 are foreground text color - if (mystston_fgcolor != ((data & 0x01) << 1) + ((data & 0x02) >> 1)) - { - mystston_fgcolor = ((data & 0x01) << 1) + ((data & 0x02) >> 1); - tilemap_mark_all_tiles_dirty(fg_tilemap); - } + mystston_state *state = machine->driver_data; + + *state->video_control = data; - // bit 2 is background page select - mystston_bgpage = (data & 0x04) ? 1:0; + /* D0-D1 - foreground text color */ + /* D2 - background page select */ + /* D3 - unused */ - // bits 4 and 5 are coin counters in flipped order + /* D4-D5 - coin counters in flipped order */ coin_counter_w(0, data & 0x20); coin_counter_w(1, data & 0x10); - // bit 7 is screen flip - flip_screen_set((data & 0x80) ^ ((readinputport(3) & 0x20) ? 0x80:0)); + /* D6 - unused */ + /* D7 - screen flip */ } + + +/************************************* + * + * Tilemap callbacks + * + *************************************/ + static TILE_GET_INFO( get_bg_tile_info ) { - int code = mystston_videoram2[tile_index] + ((mystston_videoram2[tile_index + 0x200] & 0x01) << 8); + mystston_state *state = machine->driver_data; + + int page = (*state->video_control & 0x04) << 8; + int code = ((state->bg_videoram[page | 0x200 | tile_index] & 0x01) << 8) | state->bg_videoram[page | tile_index]; int flags = (tile_index & 0x10) ? TILE_FLIPY : 0; SET_TILE_INFO(1, code, 0, flags); } + static TILE_GET_INFO( get_fg_tile_info ) { - int code = videoram[tile_index] + ((videoram[tile_index + 0x400] & 0x07) << 8); - int color = mystston_fgcolor; + mystston_state *state = machine->driver_data; + + int code = ((state->fg_videoram[0x400 | tile_index] & 0x07) << 8) | state->fg_videoram[tile_index]; + int color = ((*state->video_control & 0x01) << 1) | ((*state->video_control & 0x02) >> 1); SET_TILE_INFO(0, code, color, 0); } -VIDEO_START( mystston ) -{ - bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_cols_flip_x, - 16, 16, 16, 32); - fg_tilemap = tilemap_create(get_fg_tile_info, tilemap_scan_cols_flip_x, - 8, 8, 32, 32); - tilemap_set_transparent_pen(fg_tilemap, 0); -} +/************************************* + * + * Sprite drawing + * + *************************************/ -static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect ) +static void draw_sprites(mystston_state *state, gfx_element **gfx, bitmap_t *bitmap, const rectangle *cliprect, int flip) { int offs; - for (offs = 0; offs < spriteram_size; offs += 4) + for (offs = 0; offs < 0x60; offs += 4) { - int attr = spriteram[offs]; + int attr = state->spriteram[offs]; if (attr & 0x01) { - int code = spriteram[offs + 1] + ((attr & 0x10) << 4); + int code = ((attr & 0x10) << 4) | state->spriteram[offs + 1]; int color = (attr & 0x08) >> 3; int flipx = attr & 0x04; int flipy = attr & 0x02; - int sx = 240 - spriteram[offs + 3]; - int sy = (240 - spriteram[offs + 2]) & 0xff; + int x = 240 - state->spriteram[offs + 3]; + int y = (240 - state->spriteram[offs + 2]) & 0xff; - if (flip_screen_get()) + if (flip) { - sx = 240 - sx; - sy = 240 - sy; + x = 240 - x; + y = 240 - y; flipx = !flipx; flipy = !flipy; } - drawgfx(bitmap,machine->gfx[2], code, color, flipx, flipy, - sx, sy, cliprect, TRANSPARENCY_PEN, 0); + drawgfx(bitmap, gfx[2], code, color, flipx, flipy, x, y, cliprect, TRANSPARENCY_PEN, 0); } } } -VIDEO_UPDATE( mystston ) + + +/************************************* + * + * Start + * + *************************************/ + +static VIDEO_START( mystston ) { - tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0); - draw_sprites(machine, bitmap, cliprect); - tilemap_draw(bitmap, cliprect, fg_tilemap, 0, 0); + mystston_state *state = machine->driver_data; + + state->bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_cols_flip_x, 16, 16, 16, 32); + + state->fg_tilemap = tilemap_create(get_fg_tile_info, tilemap_scan_cols_flip_x, 8, 8, 32, 32); + tilemap_set_transparent_pen(state->fg_tilemap, 0); + + /* create the interrupt timer */ + state->interrupt_timer = timer_alloc(interrupt_callback, NULL); +} + + + +/************************************* + * + * Reset + * + *************************************/ + +static VIDEO_RESET( mystston ) +{ + mystston_state *state = machine->driver_data; + + timer_adjust_oneshot(state->interrupt_timer, video_screen_get_time_until_pos(0, FIRST_INT_VPOS - 1, INT_HPOS), FIRST_INT_VPOS); +} + + + +/************************************* + * + * Update + * + *************************************/ + +static VIDEO_UPDATE( mystston ) +{ + mystston_state *state = machine->driver_data; + + int flip = (*state->video_control & 0x80) ^ ((readinputportbytag("DSW1") & 0x20) << 2); + + set_palette(machine, state); + + tilemap_mark_all_tiles_dirty(ALL_TILEMAPS); + tilemap_set_scrolly(state->bg_tilemap, 0, *state->scroll); + tilemap_set_flip(ALL_TILEMAPS, flip ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0); + + tilemap_draw(bitmap, cliprect, state->bg_tilemap, 0, 0); + draw_sprites(state, machine->gfx, bitmap, cliprect, flip); + tilemap_draw(bitmap, cliprect, state->fg_tilemap, 0, 0); + return 0; } + + + +/************************************* + * + * Graphics decoding + * + *************************************/ + +static const gfx_layout charlayout = +{ + 8,8, + RGN_FRAC(1,3), + 3, + { RGN_FRAC(2,3), RGN_FRAC(1,3), RGN_FRAC(0,3) }, + { 0, 1, 2, 3, 4, 5, 6, 7 }, + { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 }, + 8*8 +}; + + +static const gfx_layout spritelayout = +{ + 16,16, + RGN_FRAC(1,3), + 3, + { RGN_FRAC(2,3), RGN_FRAC(1,3), RGN_FRAC(0,3) }, + { 16*8+0, 16*8+1, 16*8+2, 16*8+3, 16*8+4, 16*8+5, 16*8+6, 16*8+7, + 16*0+0, 16*0+1, 16*0+2, 16*0+3, 16*0+4, 16*0+5, 16*0+6, 16*0+7 }, + { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, + 8*8, 9*8, 10*8, 11*8, 12*8, 13*8, 14*8, 15*8 }, + 32*8 +}; + + +static GFXDECODE_START( mystston ) + GFXDECODE_ENTRY( REGION_GFX1, 0, charlayout, 4*8, 4 ) + GFXDECODE_ENTRY( REGION_GFX2, 0, spritelayout, 2*8, 1 ) + GFXDECODE_ENTRY( REGION_GFX1, 0, spritelayout, 0*8, 2 ) +GFXDECODE_END + + + +/************************************* + * + * Machine driver + * + *************************************/ + +MACHINE_DRIVER_START( mystston_video ) + + MDRV_VIDEO_START(mystston) + MDRV_VIDEO_RESET(mystston) + MDRV_VIDEO_UPDATE(mystston) + + MDRV_GFXDECODE(mystston) + MDRV_PALETTE_LENGTH(0x40) + + MDRV_SCREEN_ADD("main", RASTER) + MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) + MDRV_SCREEN_RAW_PARAMS(PIXEL_CLOCK, HTOTAL, HBEND, HBSTART, VTOTAL, VBEND, VBSTART) +MACHINE_DRIVER_END |