1 /***************************************************************************
2 
3 	Mustache Boy
4 	(c)1987 March Electronics
5 
6 	(there are also Seibu and Taito logos/copyrights in the ROMs)
7 
8  driver by Tomasz Slanina dox@space.pl
9 
10  The hardware similar to Knuckle Joe.
11 
12 ***************************************************************************/
13 #include "driver.h"
14 #include "sndhrdw/seibu.h" /* for seibu_sound_decrypt on the MAIN cpu (not sound)*/
15 #include "sndhrdw/t5182.h"
16 #include "vidhrdw/generic.h"
17 
18 WRITE_HANDLER( mustache_videoram_w );
19 WRITE_HANDLER( mustache_scroll_w );
20 WRITE_HANDLER ( mustache_video_control_w);
21 VIDEO_START( mustache );
22 VIDEO_UPDATE( mustache );
23 PALETTE_INIT( mustache );
24 
25 
26 static int read_coins=0;
27 
28 
READ_HANDLER(mustache_coin_hack_r)29 READ_HANDLER ( mustache_coin_hack_r )
30 {
31 	return (read_coins)?((offset&1	)?(input_port_5_r(0)<<5)|(input_port_5_r(0)<<7):(input_port_5_r(0)<<4)):0;
32 }
33 
34 
MEMORY_READ_START(readmem)35 static MEMORY_READ_START( readmem )
36     { 0x0000, 0x7fff, MRA_ROM },
37 	{ 0x8000, 0xbfff, MRA_ROM },
38 	{ 0xc000, 0xcfff, videoram_r },
39 	{ 0xd001, 0xd001, t5182_sharedram_semaphore_snd_r },
40 	{ 0xd400, 0xd4ff, t5182shared_r },
41 	{ 0xd800, 0xd800, input_port_0_r }, /* IN 0 */
42 	{ 0xd801, 0xd801, input_port_1_r }, /* IN 1 */
43 	{ 0xd802, 0xd802, input_port_2_r }, /* IN 2 */
44 	{ 0xd803, 0xd803, input_port_3_r },	/* DSW A */
45 	{ 0xd804, 0xd804, input_port_4_r },	/* DSW B */
46 	{ 0xf000, 0xffff, MRA_RAM },
47 MEMORY_END
48 
49 static MEMORY_WRITE_START( writemem )
50     { 0x0000, 0x7fff, MWA_ROM },
51 	{ 0x8000, 0xbfff, MWA_ROM },
52 	{ 0xc000, 0xcfff, mustache_videoram_w, &videoram },
53 	{ 0xd000, 0xd000, t5182_sound_irq_w },
54 	{ 0xd002, 0xd002, t5182_sharedram_semaphore_main_acquire_w },
55 	{ 0xd003, 0xd003, t5182_sharedram_semaphore_main_release_w },
56 	{ 0xd400, 0xd4ff, t5182shared_w },
57 	{ 0xd806, 0xd806, mustache_scroll_w },
58 	{ 0xd807, 0xd807, mustache_video_control_w },
59 	{ 0xe800, 0xefff, MWA_RAM, &spriteram, &spriteram_size },
60 	{ 0xf000, 0xffff, MWA_RAM },
61 MEMORY_END
62 
63 
64 /******************************************************************************/
65 
66 INPUT_PORTS_START( mustache )
67 	PORT_START	/* IN 1 */
68 
69 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP  )
70 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  )
71 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  )
72 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT )
73 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
74 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
75 
76 	PORT_START	/* IN 2 */
77 
78 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_8WAY| IPF_COCKTAIL )
79 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_8WAY| IPF_COCKTAIL )
80 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_8WAY| IPF_COCKTAIL )
81 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT| IPF_COCKTAIL )
82 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1| IPF_COCKTAIL )
83 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2| IPF_COCKTAIL )
84 
85 	PORT_START	/* IN 3 */
86 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START1  )
87 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2  )
88 	PORT_BIT( 0xf9, IP_ACTIVE_LOW, IPT_UNUSED  )
89 
90 	PORT_START	/* DSW A */
91 	PORT_DIPNAME( 0x01, 0x01, DEF_STR( Cabinet ) )
92 	PORT_DIPSETTING(    0x01, DEF_STR( Upright ) )
93 	PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
94 
95 	PORT_DIPNAME( 0x06, 0x04, DEF_STR( Difficulty ) )
96 	PORT_DIPSETTING(    0x06, "Easy" )
97 	PORT_DIPSETTING(    0x04, "Normal" )
98 	PORT_DIPSETTING(    0x02, "Hard" )
99 	PORT_DIPSETTING(    0x00, "Hardest" )
100 
101 	PORT_DIPNAME( 0x18, 0x18, DEF_STR( Lives ) )
102 	PORT_DIPSETTING(    0x08, "4" )
103 	PORT_DIPSETTING(    0x10, "1" )
104 	PORT_DIPSETTING(    0x18, "3" )
105 	PORT_DIPSETTING(    0x00, "5" )
106 
107 	PORT_DIPNAME( 0x20, 0x00, DEF_STR( Demo_Sounds ) )
108 	PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
109 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
110 
111 	PORT_START /* DSW B */
112 	PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_A ) )
113 	PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
114 	PORT_DIPSETTING(    0x04, DEF_STR( 4C_1C ) )
115 	PORT_DIPSETTING(    0x02, DEF_STR( 3C_1C ) )
116 	PORT_DIPSETTING(    0x06, DEF_STR( 2C_1C ) )
117 	PORT_DIPSETTING(    0x07, DEF_STR( 1C_1C ) )
118 	PORT_DIPSETTING(    0x03, DEF_STR( 1C_2C ) )
119 	PORT_DIPSETTING(    0x05, DEF_STR( 1C_3C ) )
120 	PORT_DIPSETTING(    0x01, DEF_STR( 1C_5C ) )
121 
122 	PORT_DIPNAME( 0x18, 0x18, DEF_STR( Coin_B ) )
123 	PORT_DIPSETTING(    0x10, DEF_STR( 2C_1C ) )
124 	PORT_DIPSETTING(    0x18, DEF_STR( 1C_1C ) )
125 	PORT_DIPSETTING(    0x00, DEF_STR( 2C_3C ) )
126 	PORT_DIPSETTING(    0x08, DEF_STR( 1C_2C ) )
127 
128 	PORT_SERVICE( 0x20, IP_ACTIVE_LOW )
129 	PORT_DIPNAME( 0x40, 0x40, DEF_STR( Free_Play ) )
130 	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
131 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
132 
133 	PORT_START
134 	PORT_BIT_IMPULSE( 0x01, IP_ACTIVE_HIGH, IPT_COIN1, 1 )
135 
136 INPUT_PORTS_END
137 
138 
139 static struct GfxLayout charlayout =
140 {
141 	8,8,
142 	RGN_FRAC(1,3),
143 	3,
144 	{ RGN_FRAC(0,3), RGN_FRAC(1,3),RGN_FRAC(2,3)},
145 	{STEP8(7,-1)},
146 	{STEP8(0,8)},
147 	8*8
148 };
149 static struct GfxLayout spritelayout =
150 {
151 	16,16,
152 	RGN_FRAC(1,4),
153 	4,
154 	{ RGN_FRAC(1,4), RGN_FRAC(3,4),RGN_FRAC(0,4),RGN_FRAC(2,4)},
155 	{STEP16(15,-1)},
156 	{STEP16(0,16)},
157 	16*16
158 };
159 
160 static struct GfxDecodeInfo gfxdecodeinfo[] =
161 {
162 	{ REGION_GFX1, 0, &charlayout,   0x00, 16 },
163 	{ REGION_GFX2, 0, &spritelayout, 0x80, 8 },
164 	{ -1 } /* end of array */
165 };
166 
167 
clear_irq_cb(int param)168 static void clear_irq_cb(int param)
169 {
170     read_coins^=1;
171 	cpu_set_irq_line(0, 0, CLEAR_LINE);
172 }
173 
assert_irq(void)174 static void assert_irq(void)
175 {
176 	cpu_set_irq_line(0, 0, ASSERT_LINE);
177 	timer_set(TIME_IN_CYCLES(14288, 0),0, clear_irq_cb);
178        /* Timing here is an educated GUESS, Z80 /INT must stay high so the irq
179           fires no less than TWICE per frame, else game doesn't work right.
180       6000000 / 56.747 = 105732.4616 cycles per frame, we'll call it A
181       screen size is 256x256, though less is visible.
182           lets assume we have 256 lines L and 40 'lines' (really line-times)
183           of vblank V:
184       So (A/(L+V))*V = the number of cycles spent in vblank.
185       (105732.4616 / (256+40)) * 40 = 14288.17049 z80 clocks in vblank
186        */
187 }
188 
189 
190 static MACHINE_DRIVER_START( mustache )
191 
192 	/* basic machine hardware */
193 	MDRV_CPU_ADD(Z80, 18432000/4)
MDRV_CPU_MEMORY(readmem,writemem)194 	MDRV_CPU_MEMORY(readmem, writemem)
195     MDRV_CPU_VBLANK_INT(assert_irq,1)
196 
197 
198 	MDRV_FRAMES_PER_SECOND(56.747)
199 	MDRV_VBLANK_DURATION(DEFAULT_60HZ_VBLANK_DURATION)
200 
201 	/* video hardware */
202 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
203 	MDRV_SCREEN_SIZE(32*8, 32*8)
204 	MDRV_VISIBLE_AREA(1*8, 31*8-1, 2*8, 31*8-1)
205 	MDRV_GFXDECODE(gfxdecodeinfo)
206 	MDRV_PALETTE_LENGTH(8*16+16*8)
207 
208 	MDRV_PALETTE_INIT(mustache)
209 	MDRV_VIDEO_START(mustache)
210 	MDRV_VIDEO_UPDATE(mustache)
211 
212 	MDRV_IMPORT_FROM(t5182_audio)
213 
214 MACHINE_DRIVER_END
215 
216 ROM_START( mustache )
217 	ROM_REGION( 0x20000, REGION_CPU1, 0 )
218 	ROM_LOAD( "mustache.h18", 0x0000, 0x8000, CRC(123bd9b8) SHA1(33a7cba5c3a54b0b1a15dd1e24d298b6f7274321) )
219 	ROM_LOAD( "mustache.h16", 0x8000, 0x4000, CRC(62552beb) SHA1(ee10991d7de0596608fa1db48805781cbfbbdb9f) )
220 
221 	ROM_REGION( 0x10000, REGION_CPU2, 0 ) /* Toshiba T5182 module */
222 	ROM_LOAD( "t5182.rom",   0x0000, 0x2000, CRC(d354c8fc) SHA1(a1c9e1ac293f107f69cc5788cf6abc3db1646e33) )
223 	ROM_LOAD( "mustache.e5", 0x8000, 0x8000, CRC(efbb1943) SHA1(3320e9eaeb776d09ed63f7dedc79e720674e6718) )
224 
225 	ROM_REGION( 0x0c000, REGION_GFX1,0)	/* BG tiles  */
226 	ROM_LOAD( "mustache.a13", 0x0000,  0x4000, CRC(9baee4a7) SHA1(31bcec838789462e67e54ebe7256db9fc4e51b69) )
227 	ROM_LOAD( "mustache.a14", 0x4000,  0x4000, CRC(8155387d) SHA1(5f0a394c7671442519a831b0eeeaba4eecd5a406) )
228 	ROM_LOAD( "mustache.a16", 0x8000,  0x4000, CRC(4db4448d) SHA1(50a94fd65c263d95fd24b4009dbb87707929fdcb) )
229 
230 	ROM_REGION( 0x20000, REGION_GFX2,0 )	/* sprites */
231 	ROM_LOAD( "mustache.a4", 0x00000,  0x8000, CRC(d5c3bbbf) SHA1(914e3feea54246476701f492c31bd094ad9cea10) )
232 	ROM_LOAD( "mustache.a7", 0x08000,  0x8000, CRC(e2a6012d) SHA1(4e4cd1a186870c8a88924d5bff917c6889da953d) )
233 	ROM_LOAD( "mustache.a5", 0x10000,  0x8000, CRC(c975fb06) SHA1(4d166bd79e19c7cae422673de3e095ad8101e013) )
234 	ROM_LOAD( "mustache.a8", 0x18000,  0x8000, CRC(2e180ee4) SHA1(a5684a25c337aeb4effeda7982164d35bc190af9) )
235 
236 	ROM_REGION( 0x1300, REGION_PROMS,0 )	/* proms */
237 	ROM_LOAD( "mustache.c3",0x0000, 0x0100, CRC(68575300) SHA1(bc93a38df91ad8c2f335f9bccc98b52376f9b483) )
238 	ROM_LOAD( "mustache.c2",0x0100, 0x0100, CRC(eb008d62) SHA1(a370fbd1affaa489210ea36eb9e365263fb4e232) )
239 	ROM_LOAD( "mustache.c1",0x0200, 0x0100, CRC(65da3604) SHA1(e4874d4152a57944d4e47306250833ea5cd0d89b) )
240 
241 	ROM_LOAD( "mustache.b6",0x0300, 0x1000, CRC(5f83fa35) SHA1(cb13e63577762d818e5dcbb52b8a53f66e284e8f) ) /* 63S281N near SEI0070BU */
242 ROM_END
243 
244 static DRIVER_INIT( mustache )
245 {
246 	int i;
247 
248 	int G1 = memory_region_length(REGION_GFX1)/3;
249 	int G2 = memory_region_length(REGION_GFX2)/2;
250 	UINT8 *gfx1 = memory_region(REGION_GFX1);
251 	UINT8 *gfx2 = memory_region(REGION_GFX2);
252 	UINT8 *buf=auto_malloc(G2*2);
253 
254 	/* BG data lines */
255 	for (i=0;i<G1; i++)
256 	{
257 		UINT16 w;
258 
259 		buf[i] = BITSWAP8(gfx1[i], 0,5,2,6,4,1,7,3);
260 
261 		w = (gfx1[i+G1] << 8) | gfx1[i+G1*2];
262 		w = BITSWAP16(w, 14,1,13,5,9,2,10,6, 3,8,4,15,0,11,12,7);
263 
264 		buf[i+G1]   = w >> 8;
265 		buf[i+G1*2] = w & 0xff;
266 	}
267 
268 	/* BG address lines */
269 	for (i = 0; i < 3*G1; i++)
270 		gfx1[i] = buf[BITSWAP16(i,15,14,13,2,1,0,12,11,10,9,8,7,6,5,4,3)];
271 
272 	/* SPR data lines */
273 	for (i=0;i<G2; i++)
274 	{
275 		UINT16 w;
276 
277 		w = (gfx2[i] << 8) | gfx2[i+G2];
278 		w = BITSWAP16(w, 5,7,11,4,15,10,3,14, 9,2,13,8,1,12,0,6 );
279 
280 		buf[i]    = w >> 8;
281 		buf[i+G2] = w & 0xff;
282 	}
283 
284 	/* SPR address lines */
285 	for (i = 0; i < 2*G2; i++)
286 		gfx2[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,12,11,10,9,8,7,6,5,4,13,14,3,2,1,0)];
287 
288 	free(buf);
289 	seibu_sound_decrypt(REGION_CPU1,0x8000);
290 
291 	install_mem_read_handler( 0, 0xd400, 0xd401, mustache_coin_hack_r);
292 }
293 
294 
295 GAME( 1987, mustache, 0, mustache, mustache, mustache, ROT90, "[Seibu Kaihatsu] (March license)", "Mustache Boy" )
296