1 /***************************************************************************
2 
3 XOR WORLD (c) 1990 Gaelco
4 
5 Driver by Manuel Abadia <manu@teleline.es>
6 
7 Memory Map:
8 -----------
9 0x000000-0x01ffff	ROM
10 0x200000-0x200001	Input #1
11 0x400000-0x400001	Input #2
12 0x600000-0x600001	DIPSW #1 + EEPROM read
13 0x800000-0x800001	Philips SAA1099P write register
14 0x800002-0x800003	Philips SAA1099P control register
15 0xa00008-0xa0000d	EEPROM write/ctrl
16 0xffc000-0xffc7ff	Screen		(8x8 tiles	32x32		(256x256))
17 0xffc800-0xffc87f	Sprite RAM
18 0xffc884-0xffffff	Work RAM
19 
20 Interrupts:
21 	Level 2 INT updates the timer
22 	Level 6 INT drives the game
23 
24 Unmapped addresses in the driver:
25 
26 0xffc800-0xffc801	INT 2 ACK\Watchdog timer
27 0xffc802-0xffc803	INT 6 ACK/Watchdog timer
28 
29 EEPROM chip: 93C46
30 
31 ***************************************************************************/
32 
33 #include "driver.h"
34 #include "machine/eeprom.h"
35 #include "vidhrdw/generic.h"
36 #include "cpu/m68000/m68000.h"
37 
38 extern data16_t *xorworld_videoram;
39 extern data16_t *xorworld_spriteram;
40 
41 /* from vidhrdw/xorworld.c */
42 READ16_HANDLER(xorworld_vram_r);
43 WRITE16_HANDLER(xorworld_vram_w);
44 VIDEO_START( xorworld );
45 VIDEO_UPDATE( xorworld );
46 PALETTE_INIT( xorworld );
47 
48 /****************************************************************
49 				NVRAM load/save/init
50 ****************************************************************/
NVRAM_HANDLER(xorworld)51 static NVRAM_HANDLER( xorworld )
52 {
53 	if (read_or_write){
54 		EEPROM_save(file);
55 	} else {
56 		EEPROM_init(&eeprom_interface_93C46);
57 
58 		if (file) {
59 			EEPROM_load(file);
60 		}
61 	}
62 }
63 
64 /****************************************************************
65 				Init machine
66 ****************************************************************/
67 
68 #define PATCH(data) *rom = data; rom++
69 
70 /*	patch some strange protection (without this, strange characters appear
71 	after level 5 and some pieces don't rotate properly some times) */
DRIVER_INIT(xorworld)72 static DRIVER_INIT( xorworld )
73 {
74 	data16_t *rom = (data16_t *)(memory_region(REGION_CPU1) + 0x1390);
75 
76 	PATCH(0x4239); PATCH(0x00ff); PATCH(0xe196);	/* clr.b $ffe196 */
77 	PATCH(0x4239); PATCH(0x00ff); PATCH(0xe197);	/* clr.b $ffe197 */
78 	PATCH(0x4239); PATCH(0x00ff); PATCH(0xe0bc);	/* clr.b $ffe0bc */
79 	PATCH(0x41f9); PATCH(0x00ff); PATCH(0xcfce);	/* lea $ffcfce,A0 */
80 	PATCH(0x3e3c); PATCH(0x000f);					/* move #$f,D7 */
81 	PATCH(0x4218);									/* clr.b (A0)+ */
82 	PATCH(0x51cf); PATCH(0xfffc);					/* dbra D7,$13ac */
83 	PATCH(0x4e75);									/* rts */
84 
85 	PATCH(0x31ff);									/* adjust checksum */
86 }
87 
88 
89 /****************************************************************
90 				EEPROM read/write/control
91 ****************************************************************/
92 
93 /* the EEPROM is read thru bit 4 */
READ16_HANDLER(xorworld_input_r)94 static READ16_HANDLER( xorworld_input_r )
95 {
96 	return readinputport(0) | ((EEPROM_read_bit() & 0x01) << 4);
97 	return rand() & 0x10;
98 }
99 
WRITE16_HANDLER(eeprom_cs_w)100 static WRITE16_HANDLER( eeprom_cs_w )
101 {
102 	/* bit 0 is CS (active low) */
103 	EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
104 }
105 
WRITE16_HANDLER(eeprom_sk_w)106 static WRITE16_HANDLER( eeprom_sk_w )
107 {
108 	/* bit 0 is SK (active high) */
109 	EEPROM_set_clock_line((data & 0x01) ? ASSERT_LINE : CLEAR_LINE);
110 }
111 
WRITE16_HANDLER(eeprom_data_w)112 static WRITE16_HANDLER( eeprom_data_w )
113 {
114 	/* bit 0 is EEPROM data (DIN) */
115 	EEPROM_write_bit(data & 0x01);
116 }
117 
118 
INTERRUPT_GEN(xorworld_interrupt)119 static INTERRUPT_GEN( xorworld_interrupt )
120 {
121 	if (cpu_getiloops() == 0){
122 		cpu_set_irq_line(0, 2, HOLD_LINE);
123 	}
124 	else if (cpu_getiloops() % 2){
125 		cpu_set_irq_line(0, 6, HOLD_LINE);
126 	}
127 }
128 
MEMORY_READ16_START(xorworld_readmem)129 static MEMORY_READ16_START( xorworld_readmem )
130 	{ 0x000000, 0x01ffff, MRA16_ROM },						/* ROM */
131 	{ 0x200000, 0x200001, input_port_1_word_r },			/* INPUT #1 */
132 	{ 0x400000, 0x400001, input_port_2_word_r },			/* INPUT #2 */
133 	{ 0x600000, 0x600001, xorworld_input_r },				/* DIPSW #1 + EEPROM data */
134 	{ 0xffc000, 0xffc7ff, xorworld_vram_r },				/* Video RAM */
135 	{ 0xffc800, 0xffc87f, MRA16_RAM },						/* Sprite RAM */
136 	{ 0xffc884, 0xffffff, MRA16_RAM },						/* Work RAM */
137 	{ -1 }
138 };
139 
140 static MEMORY_WRITE16_START( xorworld_writemem )
141 	{ 0x000000, 0x01ffff, MWA16_ROM },							/* ROM */
142 	{ 0x800000, 0x800001, saa1099_write_port_0_lsb_w },			/* SAA1099 write port */
143 	{ 0x800002, 0x800003, saa1099_control_port_0_lsb_w },		/* SAA1099 control port */
144 	{ 0xa00008, 0xa00009, eeprom_cs_w },						/* EEPROM chip select */
145 	{ 0xa0000a, 0xa0000b, eeprom_sk_w },						/* EEPROM serial clock */
146 	{ 0xa0000c, 0xa0000d, eeprom_data_w },						/* EEPROM data */
147 	{ 0xffc000, 0xffc7ff, xorworld_vram_w, &xorworld_videoram },/* Video RAM */
148 	{ 0xffc800, 0xffc87f, MWA16_RAM, &xorworld_spriteram },		/* Sprite RAM */
149 	{ 0xffc880, 0xffc883, MWA16_NOP },							/* INTs ACKs? */
150 	{ 0xffc884, 0xffffff, MWA16_RAM },							/* Work RAM */
151 	{ -1 }
152 };
153 
154 static struct GfxLayout xorworld_tilelayout =
155 {
156 	8,8,															/* 8x8 tiles */
157 	0x10000/16,														/* 4096 tiles */
158 	4,																/* 4 bpp */
159 	{ 1*0x10000*8, 1*0x10000*8+4, 0, 4 },							/* plane offsets */
160 	{ 0*8, 0*8+1, 0*8+2, 0*8+3, 1*8+0, 1*8+1, 1*8+2, 1*8+3 },
161 	{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
162 	16*8
163 };
164 
165 
166 static struct GfxLayout xorworld_spritelayout =
167 {
168 	16,16,																/* 16x16 sprites */
169 	0x10000/64,															/* 1024 sprites */
170 	4,																	/* 4 bpp */
171 	{ 1*0x10000*8, 1*0x10000*8+4, 0, 4 },								/* plane offsets */
172 	{ 0*8, 0*8+1, 0*8+2, 0*8+3, 1*8+0, 1*8+1, 1*8+2, 1*8+3,
173 		32*8+0, 32*8+1, 32*8+2, 32*8+3, 33*8+0, 33*8+1, 33*8+2, 33*8+3},
174 	{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
175 		8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16 },
176 	64*8
177 };
178 
179 static struct GfxDecodeInfo xorworld_gfxdecodeinfo[] =
180 {
181 	{ REGION_GFX1, 0x000000, &xorworld_tilelayout,	0,64 },
182 	{ REGION_GFX1, 0x000000, &xorworld_spritelayout,0,64 },
183 	{ -1 }
184 };
185 
186 
187 INPUT_PORTS_START( xorworld )
188 
189 PORT_START	/* DSW #1 */
190 	PORT_DIPNAME( 0x07, 0x07, "Coin A & B" )
191 	PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) )
192 	PORT_DIPSETTING(    0x01, DEF_STR( 2C_2C ) )
193 	PORT_DIPSETTING(    0x07, DEF_STR( 1C_1C ) )
194 	PORT_DIPSETTING(    0x06, DEF_STR( 1C_2C ) )
195 	PORT_DIPSETTING(    0x05, DEF_STR( 1C_3C ) )
196 	PORT_DIPSETTING(    0x04, DEF_STR( 1C_4C ) )
197 	PORT_DIPSETTING(    0x03, DEF_STR( 1C_5C ) )
198 	PORT_DIPSETTING(    0x02, DEF_STR( 1C_6C ) )
199 	PORT_DIPNAME( 0x08, 0x00, DEF_STR( Demo_Sounds ) )
200 	PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
201 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
202 	/* 0x10 is used for accessing the NVRAM */
203 	PORT_DIPNAME( 0x60, 0x40, DEF_STR( Difficulty ) )
204 	PORT_DIPSETTING(    0x40, "Easy" )
205 	PORT_DIPSETTING(    0x60, "Normal" )
206 	PORT_DIPSETTING(    0x20, "Hard" )
207 	PORT_DIPSETTING(    0x00, "Hardest" )
208 	PORT_SERVICE( 0x80, IP_ACTIVE_LOW )
209 
210 PORT_START	/* 1P INPUTS & COINSW */
211 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER1 )
212 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER1 )
213 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER1 )
214 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER1 )
215 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
216 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
217 	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
218 	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
219 
220 PORT_START	/* 2P INPUTS & STARTSW */
221 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
222 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
223 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
224 	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
225 	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
226 	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
227 	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_START1 )
228 	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )
229 INPUT_PORTS_END
230 
231 static struct SAA1099_interface	xorworld_saa1099_interface =
232 {
233 	1,					/* number of chips */
234 	{ { 100, 100 } }	/* volume (left, right) */
235 };
236 
237 
238 static MACHINE_DRIVER_START( xorworld )
239 
240 	/* basic machine hardware */
241 	MDRV_CPU_ADD(M68000, 10000000)	/* 10 MHz */
242 	MDRV_CPU_MEMORY(xorworld_readmem, xorworld_writemem)
243 	MDRV_CPU_VBLANK_INT(xorworld_interrupt, 4) /* 1 IRQ2 + 1 IRQ4 + 1 IRQ6 */
244 
245 	MDRV_FRAMES_PER_SECOND(60)
246 	MDRV_VBLANK_DURATION(DEFAULT_REAL_60HZ_VBLANK_DURATION)
247 	MDRV_INTERLEAVE(1)
248 
249 	MDRV_NVRAM_HANDLER(xorworld)
250 
251 	/* video hardware */
252 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
253 	MDRV_SCREEN_SIZE(32*8, 32*8)
254 	MDRV_VISIBLE_AREA(0*8, 32*8-1, 2*8, 30*8-1)
255 	MDRV_GFXDECODE(xorworld_gfxdecodeinfo)
256 	MDRV_PALETTE_LENGTH(256)
257 	MDRV_COLORTABLE_LENGTH(64*4)
258 
259 	MDRV_PALETTE_INIT(xorworld)
260 	MDRV_VIDEO_START(xorworld)
261 	MDRV_VIDEO_UPDATE(xorworld)
262 
263 	/* sound hardware */
264 	MDRV_SOUND_ADD(SAA1099, xorworld_saa1099_interface)
265 MACHINE_DRIVER_END
266 
267 
268 ROM_START( xorworld )
269 	ROM_REGION( 0x100000, REGION_CPU1, 0 )	/* 68000 code */
270 	ROM_LOAD16_BYTE( "c13.bin", 0x000000, 0x010000, CRC(615a864d) SHA1(db07eef19d26a4daa0bcc17ac24d237483f93bf6) )
271 	ROM_LOAD16_BYTE( "b13.bin", 0x000001, 0x010000, CRC(632e8ee5) SHA1(ec53e632c762f72ad1fe3fab85111bdcc1e818ae) )
272 
273 	ROM_REGION( 0x020000, REGION_GFX1, ROMREGION_DISPOSE )
274 	ROM_LOAD( "d9.bin",	0x000000, 0x010000, CRC(da8d4d65) SHA1(41bcc15f26066bd820b44c0f258e70d0102953c9) )
275 	ROM_LOAD( "d10.bin",	0x010000, 0x010000, CRC(3b1d6f24) SHA1(bedf60a4cbf20492b8a846b6a7b578f8fe8dbde9) )
276 
277 	ROM_REGION( 0x0300, REGION_PROMS, 0 )
278 	ROM_LOAD( "b4.bin",   0x0000, 0x0100, CRC(75e468af) SHA1(b5fd1a086c27ca2e837cbbf1b7e57dfdd369b0d0) )  /* Red palette ROM (4 bits) */
279 	ROM_LOAD( "b7.bin",   0x0100, 0x0100, CRC(7e1cd146) SHA1(fd26a28f90c50ffcb0fe7718820c81eb9fe79e66) )  /* Green palette ROM (4 bits) */
280 	ROM_LOAD( "b5.bin",   0x0200, 0x0100, CRC(c1b9d9f9) SHA1(c4b02bf60db449fb308a5eb3e41c43299ad8e3e3) )  /* Blue palette ROM (4 bits) */
281 ROM_END
282 
283 
284 
285 GAME( 1990, xorworld, 0, xorworld, xorworld, xorworld, ROT0, "Gaelco", "Xor World (prototype)" )
286