1 /***************************************************************************
2 
3   Capcom Baseball
4 
5 
6   Somewhat similar to the "Mitchell hardware", but different enough to
7   deserve its own driver.
8 
9 TODO:
10 - understand what bit 6 of input port 0x12 is
11 - unknown bit 5 of bankswitch register
12 
13 ***************************************************************************/
14 
15 #include "driver.h"
16 #include "vidhrdw/generic.h"
17 #include "machine/eeprom.h"
18 
19 
20 /* in machine/kabuki.c */
21 void pang_decode(void);
22 
23 
24 VIDEO_START( cbasebal );
25 WRITE_HANDLER( cbasebal_textram_w );
26 READ_HANDLER( cbasebal_textram_r );
27 WRITE_HANDLER( cbasebal_scrollram_w );
28 READ_HANDLER( cbasebal_scrollram_r );
29 WRITE_HANDLER( cbasebal_gfxctrl_w );
30 WRITE_HANDLER( cbasebal_scrollx_w );
31 WRITE_HANDLER( cbasebal_scrolly_w );
32 VIDEO_UPDATE( cbasebal );
33 
34 
35 static int rambank;
36 
WRITE_HANDLER(cbasebal_bankswitch_w)37 static WRITE_HANDLER( cbasebal_bankswitch_w )
38 {
39 	int bankaddress;
40 	unsigned char *RAM = memory_region(REGION_CPU1);
41 
42 	/* bits 0-4 select ROM bank */
43 /*logerror("%04x: bankswitch %02x\n",activecpu_get_pc(),data);*/
44 	bankaddress = 0x10000 + (data & 0x1f) * 0x4000;
45 	cpu_setbank(1,&RAM[bankaddress]);
46 
47 	/* bit 5 used but unknown */
48 
49 	/* bits 6-7 select RAM bank */
50 	rambank = (data & 0xc0) >> 6;
51 }
52 
53 
READ_HANDLER(bankedram_r)54 static READ_HANDLER( bankedram_r )
55 {
56 	if (rambank == 2)
57 		return cbasebal_textram_r(offset);	/* VRAM */
58 	else if (rambank == 1)
59 	{
60 		if (offset < 0x800)
61 			return paletteram_r(offset);
62 		else return 0;
63 	}
64 	else
65 	{
66 		return cbasebal_scrollram_r(offset);	/* SCROLL */
67 	}
68 }
69 
WRITE_HANDLER(bankedram_w)70 static WRITE_HANDLER( bankedram_w )
71 {
72 	if (rambank == 2)
73 		cbasebal_textram_w(offset,data);
74 	else if (rambank == 1)
75 	{
76 		if (offset < 0x800)
77 			paletteram_xxxxBBBBRRRRGGGG_w(offset,data);
78 	}
79 	else
80 		cbasebal_scrollram_w(offset,data);
81 }
82 
WRITE_HANDLER(cbasebal_coinctrl_w)83 static WRITE_HANDLER( cbasebal_coinctrl_w )
84 {
85 	coin_lockout_w(0,~data & 0x04);
86 	coin_lockout_w(1,~data & 0x08);
87 	coin_counter_w(0,data & 0x01);
88 	coin_counter_w(1,data & 0x02);
89 }
90 
91 
92 
93 /***************************************************************************
94 
95   EEPROM
96 
97 ***************************************************************************/
98 
99 static struct EEPROM_interface eeprom_interface =
100 {
101 	6,		/* address bits */
102 	16,		/* data bits */
103 	"0110",	/*  read command */
104 	"0101",	/* write command */
105 	"0111"	/* erase command */
106 };
107 
108 
NVRAM_HANDLER(cbasebal)109 static NVRAM_HANDLER( cbasebal )
110 {
111 	if (read_or_write)
112 		EEPROM_save(file);
113 	else
114 	{
115 		EEPROM_init(&eeprom_interface);
116 
117 		if (file)
118 			EEPROM_load(file);
119 	}
120 }
121 
READ_HANDLER(eeprom_r)122 static READ_HANDLER( eeprom_r )
123 {
124 	int bit;
125 
126 	bit = EEPROM_read_bit() << 7;
127 
128 	return (input_port_2_r(0) & 0x7f) | bit;
129 }
130 
WRITE_HANDLER(eeprom_cs_w)131 static WRITE_HANDLER( eeprom_cs_w )
132 {
133 	EEPROM_set_cs_line(data ? CLEAR_LINE : ASSERT_LINE);
134 }
135 
WRITE_HANDLER(eeprom_clock_w)136 static WRITE_HANDLER( eeprom_clock_w )
137 {
138 	EEPROM_set_clock_line(data ? CLEAR_LINE : ASSERT_LINE);
139 }
140 
WRITE_HANDLER(eeprom_serial_w)141 static WRITE_HANDLER( eeprom_serial_w )
142 {
143 	EEPROM_write_bit(data);
144 }
145 
146 
147 
MEMORY_READ_START(cbasebal_readmem)148 static MEMORY_READ_START( cbasebal_readmem )
149 	{ 0x0000, 0x7fff, MRA_ROM },
150 	{ 0x8000, 0xbfff, MRA_BANK1 },
151 	{ 0xc000, 0xcfff, bankedram_r },
152 	{ 0xe000, 0xffff, MRA_RAM },
153 MEMORY_END
154 
155 static MEMORY_WRITE_START( cbasebal_writemem )
156 	{ 0x0000, 0xbfff, MWA_ROM },
157 	{ 0xc000, 0xcfff, bankedram_w, &paletteram },	/* palette + vram + scrollram */
158 	{ 0xe000, 0xfdff, MWA_RAM },			/* work RAM */
159 	{ 0xfe00, 0xffff, MWA_RAM, &spriteram, &spriteram_size },
160 MEMORY_END
161 
162 static PORT_READ_START( cbasebal_readport )
163 	{ 0x10, 0x10, input_port_0_r },
164 	{ 0x11, 0x11, input_port_1_r },
165 	{ 0x12, 0x12, eeprom_r },
166 PORT_END
167 
168 static PORT_WRITE_START( cbasebal_writeport )
169 	{ 0x00, 0x00, cbasebal_bankswitch_w },
170 	{ 0x01, 0x01, eeprom_cs_w },
171 	{ 0x02, 0x02, eeprom_clock_w },
172 	{ 0x03, 0x03, eeprom_serial_w },
173 	{ 0x05, 0x05, OKIM6295_data_0_w },
174 	{ 0x06, 0x06, YM2413_register_port_0_w },
175 	{ 0x07, 0x07, YM2413_data_port_0_w },
176 	{ 0x08, 0x09, cbasebal_scrollx_w },
177 	{ 0x0a, 0x0b, cbasebal_scrolly_w },
178 	{ 0x13, 0x13, cbasebal_gfxctrl_w },
179 	{ 0x14, 0x14, cbasebal_coinctrl_w },
180 PORT_END
181 
182 
183 INPUT_PORTS_START( cbasebal )
184 	PORT_START
185 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNKNOWN )
186 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 )
187 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON2 )
188 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON1 )
189 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY )
190 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY )
191 	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY )
192 	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY )
193 
194 	PORT_START      /* IN2 */
195 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNKNOWN )
196 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER2 )
197 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
198 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
199 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
200 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
201 	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
202 	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
203 
204 	PORT_START      /* IN0 */
205 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
206 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
207 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 )
208 	PORT_SERVICE( 0x08, IP_ACTIVE_LOW )
209 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START2 )
210 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
211 	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_VBLANK )		/* ? */
212 	PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN )	/* EEPROM data */
213 INPUT_PORTS_END
214 
215 
216 
217 
218 static struct GfxLayout cbasebal_textlayout =
219 {
220 	8,8,	/* 8*8 characters */
221 	4096,	/* 4096 characters */
222 	2,		/* 2 bits per pixel */
223 	{ 0, 4 },
224 	{ 8+3, 8+2, 8+1, 8+0, 3, 2, 1, 0 },
225 	{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
226 	16*8    /* every char takes 16 consecutive bytes */
227 };
228 
229 static struct GfxLayout cbasebal_tilelayout =
230 {
231 	16,16,	/* 16*16 tiles */
232 	4096,	/* 4096 tiles */
233 	4,		/* 4 bits per pixel */
234 	{ 4096*64*8+4, 4096*64*8+0,4, 0 },
235 	{ 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3,
236 			16*16+0, 16*16+1, 16*16+2, 16*16+3, 16*16+8+0, 16*16+8+1, 16*16+8+2, 16*16+8+3 },
237 	{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
238 			8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16 },
239 	64*8    /* every tile takes 64 consecutive bytes */
240 };
241 
242 static struct GfxLayout cbasebal_spritelayout =
243 {
244 	16,16,  /* 16*16 sprites */
245 	4096,   /* 2048 sprites */
246 	4,      /* 4 bits per pixel */
247 	{ 4096*64*8+4, 4096*64*8+0, 4, 0 },
248 	{ 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3,
249 			32*8+0, 32*8+1, 32*8+2, 32*8+3, 33*8+0, 33*8+1, 33*8+2, 33*8+3 },
250 	{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
251 			8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16 },
252 	64*8    /* every sprite takes 64 consecutive bytes */
253 };
254 
255 static struct GfxDecodeInfo cbasebal_gfxdecodeinfo[] =
256 {
257 	{ REGION_GFX1, 0, &cbasebal_textlayout,   256,  8 }, /* colors 256- 287 */
258 	{ REGION_GFX2, 0, &cbasebal_tilelayout,   768, 16 }, /* colors 768-1023 */
259 	{ REGION_GFX3, 0, &cbasebal_spritelayout, 512,  8 }, /* colors 512- 639 */
260 	{ -1 } /* end of array */
261 };
262 
263 
264 
265 static struct YM2413interface ym2413_interface=
266 {
267 	1,	/* 1 chip */
268 	3579545,	/* ???? */
269 	{ YM2413_VOL(100,MIXER_PAN_CENTER,100,MIXER_PAN_CENTER) }
270 };
271 
272 static struct OKIM6295interface okim6295_interface =
273 {
274 	1,			/* 1 chip */
275 	{ 8000 },	/* 8000Hz ??? */
276 	{ REGION_SOUND1 },	/* memory region */
277 	{ 50 }
278 };
279 
280 
281 
282 static MACHINE_DRIVER_START( cbasebal )
283 
284 	/* basic machine hardware */
285 	MDRV_CPU_ADD(Z80, 6000000)	/* ??? */
MDRV_CPU_MEMORY(cbasebal_readmem,cbasebal_writemem)286 	MDRV_CPU_MEMORY(cbasebal_readmem,cbasebal_writemem)
287 	MDRV_CPU_PORTS(cbasebal_readport,cbasebal_writeport)
288 	MDRV_CPU_VBLANK_INT(irq0_line_hold,1)	/* ??? */
289 
290 	MDRV_FRAMES_PER_SECOND(60)
291 	MDRV_VBLANK_DURATION(DEFAULT_REAL_60HZ_VBLANK_DURATION)
292 
293 	MDRV_NVRAM_HANDLER(cbasebal)
294 
295 	/* video hardware */
296 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER | VIDEO_UPDATE_BEFORE_VBLANK)
297 	MDRV_SCREEN_SIZE(64*8, 32*8)
298 	MDRV_VISIBLE_AREA(8*8, (64-8)*8-1, 2*8, 30*8-1 )
299 	MDRV_GFXDECODE(cbasebal_gfxdecodeinfo)
300 	MDRV_PALETTE_LENGTH(1024)
301 
302 	MDRV_VIDEO_START(cbasebal)
303 	MDRV_VIDEO_UPDATE(cbasebal)
304 
305 	/* sound hardware */
306 	MDRV_SOUND_ADD(OKIM6295, okim6295_interface)
307 	MDRV_SOUND_ADD(YM2413, ym2413_interface)
308 MACHINE_DRIVER_END
309 
310 
311 
312 ROM_START( cbasebal )
313 	ROM_REGION( 2*0x90000, REGION_CPU1, 0 )	/* 576k for code + 576k for decrypted opcodes */
314 	ROM_LOAD( "cbj10.11j",    0x00000, 0x08000, CRC(bbff0acc) SHA1(db9e2c89e030255851789caaf85f24dc73609d9b) )
315 	ROM_LOAD( "cbj07.16f",    0x10000, 0x20000, CRC(8111d13f) SHA1(264e21e824c87f55da326440c6ed71e1c287a63e) )
316 	ROM_LOAD( "cbj06.14f",    0x30000, 0x20000, CRC(9aaa0e37) SHA1(1a7b96b44c66b58f06707aafb1806520747b8c76) )
317 	ROM_LOAD( "cbj05.13f",    0x50000, 0x20000, CRC(d0089f37) SHA1(32354c3f4693a65e297791c4d8faac3aa9cff5a1) )
318 	/* 0x70000-0x8ffff empty (space for 04) */
319 
320 	ROM_REGION( 0x10000, REGION_GFX1, ROMREGION_DISPOSE )
321 	ROM_LOAD( "cbj13.16m",    0x00000, 0x10000, CRC(2359fa0a) SHA1(3a37532ea43dd4b150c53a240d35a57a9b76d23d) )	/* text */
322 
323 	ROM_REGION( 0x80000, REGION_GFX2, ROMREGION_DISPOSE )
324 	ROM_LOAD( "cbj02.1f",     0x00000, 0x20000, CRC(d6740535) SHA1(2ece885525718fd5fe52b8fa4c07930695b89659) )	/* tiles */
325 	ROM_LOAD( "cbj03.2f",     0x20000, 0x20000, CRC(88098dcd) SHA1(caddebeea581129d6a62fc9f7f354d61eef175c7) )
326 	ROM_LOAD( "cbj08.1j",     0x40000, 0x20000, CRC(5f3344bf) SHA1(1d3193078108e86e31bbfce15a8d2443cfbf2ff6) )
327 	ROM_LOAD( "cbj09.2j",     0x60000, 0x20000, CRC(aafffdae) SHA1(26e76b55fff49811df8e5b1f165be20ec8dd196a) )
328 
329 	ROM_REGION( 0x80000, REGION_GFX3, ROMREGION_DISPOSE )
330 	ROM_LOAD( "cbj11.1m",     0x00000, 0x20000, CRC(bdc1507d) SHA1(efeaf3066acfb7186d73ad8e5b291d6e61965de2) )	/* sprites */
331 	ROM_LOAD( "cbj12.2m",     0x20000, 0x20000, CRC(973f3efe) SHA1(d776499d5ac4bc23eb5d1f28b88447cc07d8ac99) )
332 	ROM_LOAD( "cbj14.1n",     0x40000, 0x20000, CRC(765dabaa) SHA1(742d1c50b65f649f23eac7976fe26c2d7400e4e1) )
333 	ROM_LOAD( "cbj15.2n",     0x60000, 0x20000, CRC(74756de5) SHA1(791d6620cdb563f0b3a717432aa4647981b0a10e) )
334 
335 	ROM_REGION( 0x80000, REGION_SOUND1, 0 )	/* OKIM */
336 	ROM_LOAD( "cbj01.1e",     0x00000, 0x20000, CRC(1d8968bd) SHA1(813e475d1d0c343e7dad516f1fe564d00c9c27fb) )
337 ROM_END
338 
339 
340 DRIVER_INIT( cbasebal )
341 {
342 	pang_decode();
343 }
344 
345 
346 GAME( 1989, cbasebal, 0, cbasebal, cbasebal, cbasebal, ROT0, "Capcom", "Capcom Baseball (Japan)" )
347