1 // license:BSD-3-Clause
2 // copyright-holders:David Haywood
3 /********************************************************************
4 
5     G-Stream (c)2002 Oriental Soft Japan
6     X2222 (prototype) (c)2000 Oriental Soft
7 
8     ---
9     X2222 has corrupt boss graphics because the program roms we use don't match the sprite roms.
10     --
11 
12     Hyperstone based hardware
13 
14     Simple Sprites (16x16x8bpp tiles)
15     3 Simple Tilemaps (32x32x8bpp tiles)
16 
17     X2222 uses raw 16bpp palette data instead of 8bpp indexed colours.
18 
19     todo: sprite lag (sprites need buffering?)
20           sprite wraparound is imperfect
21 
22     The following is confirmed on G-Stream only
23     ---
24 
25     CPU:  E1-32XT
26     Sound: 2x AD-65 (OKIM6295 clone)
27 
28     Xtals: 1.000Mhz (near AD-65a)
29            16.000Mhz (near E1-32XT / u56.bin)
30 
31            27.000Mhz (near GFX Section & 54.000Mhz)
32            54.000Mhz (near GFX Section & 27.000Mhz)
33 
34     notes:
35 
36     cpu #0 (PC=00002C34): unmapped program memory dword read from 515ECE48 & FFFFFFFF
37      what is this, buggy code?
38 
39     Is there a problem with the OKI status reads for the AD-65 clone? the game reads
40     the status register all the time, causing severe slowdown etc, might be related to
41     bad OKI banking tho.
42 
43     ---
44 
45     Dump Notes:::
46 
47     G-Stream 2020, 2002 Oriental Soft Japan
48 
49     Shooter from Oriental soft, heavy influence from XII Stag
50     as well as Trizeal. Three weapons may be carried and their
51     power controlled by picking up capsules of a specific colour.
52 
53     Three capsule types:
54     . Red   - Vulcan
55     . Green - Missiles
56     . Blue  - Laser
57 
58     Points are awarded by picking up medals which are released
59     from shot down enemies. The medal value and appearance is
60     increased as long as you don't miss any.
61 
62     When enough medals have been picked up a "void" bomb becomes
63     available which when released (hold down main shot) will create
64     a circular "void". Enemy bullets which hit this "void" are transformed
65     into medals. If you place your ship inside this "void" it becomes
66     invulnerable like in XII Stag.
67 
68     The game is powered by a HyperStone E1-32XT. A battery on the PCB
69     saves hi-scores. Hi-Scores can be reset by toggling switch S2.
70 
71     Documentation:
72 
73     Name                 Size     CRC32
74     ----------------------------------------
75     g-stream_demo.jpg     195939  0x37984e02
76     g-stream_title.jpg    152672  0xf7b9bfd3
77     g-stream_pcb.jpg     2563664  0x5ec864f3
78 
79     Name           Size     CRC32        Chip Type
80     ----------------------------------------------
81     gs_prg_02.u197 2097152  0x2f8a6bea    27C160
82     gs_gr_01.u120  2097152  0xb82cfab8    27C160
83     gs_gr_02.u121  2097152  0x37e19cbd    27C160
84     gs_gr_03.u125  2097152  0x1a3b2b11    27C160
85     gs_gr_04.u126  2097152  0xa4e8906c    27C160
86     gs_gr_05.u174  2097152  0xef283a73    27C160
87     gs_gr_06.u175  2097152  0xd4e3a2b2    27C160
88     gs_gr_07.u107  2097152  0x84e66fe1    27C160
89     gs_gr_08.u109  2097152  0xabd0d6aa    27C160
90     gs_gr_09.u180  2097152  0xf2c4fd77    27C160
91     gs_gr_10.u182  2097152  0xd696d15d    27C160
92     gs_gr_11.u108  2097152  0x946d71d1    27C160
93     gs_gr_12.u110  2097152  0x94b56e4e    27C160
94     gs_gr_13.u181  2097152  0x7daaeff0    27C160
95     gs_gr_14.u183  2097152  0x6bd2a1e1    27C160
96     gs_snd_01.u192  524288  0x79b64d3f    27C040
97     gs_snd_02.u194  524288  0xe49ed92c    27C040
98     gs_snd_03.u191  524288  0x2bfff4ac    27C040
99     gs_snd_04.u193  524288  0xb259de3b    27C040
100     gs_prg_01.u56   524288  0x0d0c6a38    27C040
101 
102     . Board supplied by Tormod
103     . Board dumped by Tormod
104 
105 +------------------------------------------------+
106 |        GS_SND_01   RAM4  16MHz     RAM1 S2 BT1 |
107 |  AD-65 GS_SND_02 GS_PRG_01 E1-32XT RAM1        |
108 | VOL    GS_SND_03                               |
109 |J AD-65 GS_SND_04                      GS_GR_07 |
110 |A    1MHz     GS_PRG_02 XC95288   RAM2 GS_GR_08 |
111 |M             GS_GR_01  RAM2           GS_GR_09 |
112 |M      RAM4   GS_GR_02   XC95288 27MHz GS_GR_10 |
113 |A      RAM4   GS_GR_03           54MHz GS_GR_11 |
114 |              GS_GR_04       S3        GS_GR_12 |
115 |    GAL       GS_GR_05       RAM3 RAM3 GS_GR_13 |
116 |    GAL       GS_GR_06       RAM3 RAM3 GS_GR_13 |
117 +------------------------------------------------+
118 
119   CPU: Hyperstone E1-32XT
120 Sound: OKI 6295 x 2 (rebaged as AD-65)
121   OSC: 54.000MHz, 27.000MHz, 16.000MHz & 1.000MHz
122 Other: Sigma Xilinx XC95255 x 2
123 
124 S2 is Toggle switch to reset high scores.
125 S3 is a 2 position dipswitch bank.
126 BT1 is 3.6V battery for high scores backup.
127 
128 RAM1 is SEC KM416C1204CJ-6
129 RAM2 is SEC KM416C1002CJ-12
130 RAM3 is EliteMT LP621024DM-70LL
131 RAM4 is HMC HM6264LP-70
132 
133 *********************************************************************/
134 
135 #include "emu.h"
136 #include "cpu/e132xs/e132xs.h"
137 #include "sound/okim6295.h"
138 #include "machine/nvram.h"
139 #include "emupal.h"
140 #include "screen.h"
141 #include "speaker.h"
142 
143 class gstream_state : public driver_device
144 {
145 public:
gstream_state(const machine_config & mconfig,device_type type,const char * tag)146 	gstream_state(const machine_config &mconfig, device_type type, const char *tag)
147 		: driver_device(mconfig, type, tag)
148 		, m_maincpu(*this, "maincpu")
149 		, m_oki(*this, "oki%u", 1)
150 		, m_workram(*this, "workram")
151 		, m_vram(*this, "vram")
152 		, m_gfxdecode(*this, "gfxdecode")
153 		, m_palette(*this, "palette")
154 	{
155 		m_toggle = 0;
156 	}
157 
158 	void x2222(machine_config &config);
159 	void gstream(machine_config &config);
160 
161 	void init_gstream();
162 	void init_x2222();
163 
164 	DECLARE_READ_LINE_MEMBER(mirror_service_r);
165 	DECLARE_CUSTOM_INPUT_MEMBER(gstream_mirror_r);
166 	DECLARE_READ_LINE_MEMBER(x2222_toggle_r);
167 
168 private:
169 	/* devices */
170 	required_device<e132xt_device> m_maincpu;
171 	optional_device_array<okim6295_device, 2> m_oki;
172 
173 	/* memory pointers */
174 	required_shared_ptr<uint32_t> m_workram;
175 	required_shared_ptr<uint32_t> m_vram;
176 //  uint32_t *  m_nvram;    // currently this uses generic nvram handling
177 
178 	/* video-related */
179 	uint32_t    m_scrollx[3];
180 	uint32_t    m_scrolly[3];
181 
182 	/* misc */
183 	int       m_oki_bank[2];
184 	int       m_toggle;
185 	int       m_xoffset;
186 
187 	void vram_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
188 	template<int Layer> void scrollx_w(uint16_t data);
189 	template<int Layer> void scrolly_w(uint16_t data);
190 	void gstream_oki_banking_w(uint32_t data);
191 	void gstream_oki_4040_w(uint32_t data);
192 	void x2222_sound_w(uint32_t data);
193 	uint32_t gstream_speedup_r();
194 	uint32_t x2222_speedup_r();
195 	uint32_t x2222_speedup2_r();
196 	virtual void machine_start() override;
197 	virtual void machine_reset() override;
198 	virtual void video_start() override;
199 	uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
200 	void draw_bg(bitmap_rgb32 &bitmap, const rectangle &cliprect, int map, uint32_t* ram);
201 	void drawgfx_transpen_x2222(bitmap_rgb32 &dest, const rectangle &cliprect, gfx_element *gfx,gfx_element *gfx2,
202 	uint32_t code, int flipx, int flipy, int32_t destx, int32_t desty);
203 
204 	void rearrange_sprite_data(uint8_t* ROM, uint32_t* NEW, uint32_t* NEW2);
205 	void rearrange_tile_data(uint8_t* ROM, uint32_t* NEW, uint32_t* NEW2);
206 
207 	required_device<gfxdecode_device> m_gfxdecode;
208 	required_device<palette_device> m_palette;
209 	void gstream_32bit_map(address_map &map);
210 	void gstream_io(address_map &map);
211 	void x2222_32bit_map(address_map &map);
212 	void x2222_io(address_map &map);
213 };
214 
READ_LINE_MEMBER(gstream_state::x2222_toggle_r)215 READ_LINE_MEMBER(gstream_state::x2222_toggle_r) // or the game hangs when starting, might be a status flag for the sound?
216 {
217 	m_toggle ^= 0xffff;
218 	return m_toggle;
219 }
220 
221 
READ_LINE_MEMBER(gstream_state::mirror_service_r)222 READ_LINE_MEMBER(gstream_state::mirror_service_r)
223 {
224 	int result;
225 
226 	/* PORT_SERVICE_NO_TOGGLE */
227 	result = (ioport("IN0")->read() & 0x8000) >> 15;
228 
229 	return ~result;
230 }
231 
CUSTOM_INPUT_MEMBER(gstream_state::gstream_mirror_r)232 CUSTOM_INPUT_MEMBER(gstream_state::gstream_mirror_r)
233 {
234 	int result;
235 
236 	/* IPT_COIN1 */
237 	result  = ((ioport("IN0")->read() & 0x200) >>  9) << 0;
238 	/* IPT_COIN2 */
239 	result |= ((ioport("IN1")->read() & 0x200) >>  9) << 1;
240 	/* IPT_START1 */
241 	result |= ((ioport("IN0")->read() & 0x400) >> 10) << 2;
242 	/* IPT_START2 */
243 	result |= ((ioport("IN1")->read() & 0x400) >> 10) << 3;
244 	/* PORT_SERVICE_NO_TOGGLE */
245 	result |= ((ioport("IN0")->read() & 0x8000) >> 15) << 6;
246 
247 	return ~result;
248 }
249 
250 
251 
vram_w(offs_t offset,uint32_t data,uint32_t mem_mask)252 void gstream_state::vram_w(offs_t offset, uint32_t data, uint32_t mem_mask)
253 {
254 	COMBINE_DATA(&m_vram[offset]);
255 }
256 
257 template<int Layer>
scrollx_w(uint16_t data)258 void gstream_state::scrollx_w(uint16_t data)
259 {
260 	m_scrollx[Layer] = data;
261 }
262 
263 template<int Layer>
scrolly_w(uint16_t data)264 void gstream_state::scrolly_w(uint16_t data)
265 {
266 	m_scrolly[Layer] = data;
267 }
268 
gstream_32bit_map(address_map & map)269 void gstream_state::gstream_32bit_map(address_map &map)
270 {
271 	map(0x00000000, 0x003fffff).ram().share("workram"); // work ram
272 //  map(0x40000000, 0x40ffffff).ram(); // ?? lots of data gets copied here if present, but game runs without it??
273 	map(0x80000000, 0x80003fff).ram().w(FUNC(gstream_state::vram_w)).share("vram"); // video ram
274 	map(0x4E000000, 0x4e1fffff).rom().region("maindata", 0); // main game rom
275 	map(0x4f000000, 0x4f000003).w(FUNC(gstream_state::scrollx_w<2>)).umask32(0xffff0000).cswidth(32);
276 	map(0x4f200000, 0x4f200003).w(FUNC(gstream_state::scrolly_w<2>)).umask32(0xffff0000).cswidth(32);
277 	map(0x4f400000, 0x4f406fff).ram().w(m_palette, FUNC(palette_device::write32)).share("palette");
278 	map(0x4f800000, 0x4f800003).w(FUNC(gstream_state::scrollx_w<0>)).umask32(0xffff0000).cswidth(32);
279 	map(0x4fa00000, 0x4fa00003).w(FUNC(gstream_state::scrolly_w<0>)).umask32(0xffff0000).cswidth(32);
280 	map(0x4fc00000, 0x4fc00003).w(FUNC(gstream_state::scrollx_w<1>)).umask32(0xffff0000).cswidth(32);
281 	map(0x4fe00000, 0x4fe00003).w(FUNC(gstream_state::scrolly_w<1>)).umask32(0xffff0000).cswidth(32);
282 	map(0xffc00000, 0xffc01fff).ram().share("nvram"); // Backup RAM
283 	map(0xfff80000, 0xffffffff).rom().region("maincpu", 0); // boot rom
284 }
285 
gstream_oki_banking_w(uint32_t data)286 void gstream_state::gstream_oki_banking_w(uint32_t data)
287 {
288 /*
289     ****OKI BANKING****
290     Possibly perfect? works perfectly in-game, may not cover all possibilities.
291     Needs code testing on PCB.
292 
293     The two OKIs can independently play music or samples, and have half of the
294     sound ROMs to themselves. Sometimes the first OKI will play music, and some
295     times it will play samples. The second OKI is the same way. The banks for
296     both OKIs are laid out like so:
297 
298     BANK MUSIC SAMPLES
299      0            X
300      1     X
301      2     X
302      3     X
303 
304     Bank 0 is the same in both ROMs.
305 
306     The banking seems to be concerned with half-nibbles in the data byte. For
307     OKI1, the half-nibbles are bits 76 and 32. For OKI2, 54 and 10.
308     The bank's '2' bit is the first half-nibble's bottom bit bitwise AND with
309     the inverse of its top bit. The bank's '1' bit is the second half-nibble's
310     bottom bit bitwise AND with the top bit.
311 
312     This may or may not be correct, but further PCB tests are required, and it
313     certainly sounds perfect in-game, without using any "hacks". */
314 
315 /*
316 7654 3210
317 1010 1010 needs oki2 to be bank 0
318 1010 1011 needs oki2 to be bank 1
319 1010 1011 needs oki1 to be bank 0
320 
321 7654 3210
322 1010 1111 needs oki1 to be bank 1
323 1010 1110 needs oki1 to be bank 1
324 1010 1110 needs oki2 to be bank 0
325 
326 7654 3210
327 0110 0110 needs oki1 to be bank 2
328 0110 0110 needs oki2 to be bank 0
329 
330 6and!7 & 2and3
331 
332 4and!5 & 0and1
333 
334 */
335 
336 	m_oki_bank[0] = ((BIT(data, 6) & ~BIT(data, 7)) << 1) | (BIT(data, 2) & BIT(data, 3));
337 	m_oki_bank[1] = ((BIT(data, 4) & ~BIT(data, 5)) << 1) | (BIT(data, 0) & BIT(data, 1));
338 
339 	//popmessage("oki bank = %X\noki_1 = %X\noki_2 = %X\n",data, m_oki_bank[0], m_oki_bank[1]);
340 
341 	m_oki[0]->set_rom_bank(m_oki_bank[0]);
342 	m_oki[1]->set_rom_bank(m_oki_bank[1]);
343 }
344 
345 // Some clocking?
gstream_oki_4040_w(uint32_t data)346 void gstream_state::gstream_oki_4040_w(uint32_t data)
347 {
348 	// data == 0 or data == 0x81
349 }
350 
gstream_io(address_map & map)351 void gstream_state::gstream_io(address_map &map)
352 {
353 	map(0x4000, 0x4003).portr("IN0");
354 	map(0x4010, 0x4013).portr("IN1");
355 	map(0x4020, 0x4023).portr("IN2");    // extra coin switches etc
356 	map(0x4030, 0x4033).w(FUNC(gstream_state::gstream_oki_banking_w));    // oki banking
357 	map(0x4040, 0x4043).w(FUNC(gstream_state::gstream_oki_4040_w));   // some clocking?
358 	map(0x4053, 0x4053).rw(m_oki[0], FUNC(okim6295_device::read), FUNC(okim6295_device::write)); // music and samples
359 	map(0x4063, 0x4063).rw(m_oki[1], FUNC(okim6295_device::read), FUNC(okim6295_device::write)); // music and samples
360 }
361 
362 
x2222_32bit_map(address_map & map)363 void gstream_state::x2222_32bit_map(address_map &map)
364 {
365 	map(0x00000000, 0x003fffff).ram().share("workram"); // work ram
366 	map(0x40000000, 0x403fffff).ram(); // ?? data gets copied here if present, but game runs without it??
367 	map(0x80000000, 0x80003fff).ram().w(FUNC(gstream_state::vram_w)).share("vram"); // video ram
368 
369 	map(0x4fc00000, 0x4fc00003).w(FUNC(gstream_state::scrolly_w<1>)).umask32(0xffff0000).cswidth(32);
370 	map(0x4fd00000, 0x4fd00003).w(FUNC(gstream_state::scrollx_w<1>)).umask32(0xffff0000).cswidth(32);
371 
372 	map(0x4fa00000, 0x4fa00003).w(FUNC(gstream_state::scrolly_w<2>)).umask32(0xffff0000).cswidth(32);
373 	map(0x4fb00000, 0x4fb00003).w(FUNC(gstream_state::scrollx_w<2>)).umask32(0xffff0000).cswidth(32);
374 
375 	map(0x4fe00000, 0x4fe00003).w(FUNC(gstream_state::scrolly_w<0>)).umask32(0xffff0000).cswidth(32);
376 	map(0x4ff00000, 0x4ff00003).w(FUNC(gstream_state::scrollx_w<0>)).umask32(0xffff0000).cswidth(32);
377 
378 	map(0xffc00000, 0xffc01fff).ram().share("nvram"); // Backup RAM (maybe)
379 	map(0xfff00000, 0xffffffff).rom().region("maincpu", 0); // boot rom
380 }
381 
x2222_sound_w(uint32_t data)382 void gstream_state::x2222_sound_w(uint32_t data)
383 {
384 	// maybe sound in low 8-bits? but we have no samples anyway assuming it's an OKI
385 	if (data & 0xffffff00)
386 		printf("x2222_sound_w unk %08x\n", data);
387 }
388 
x2222_io(address_map & map)389 void gstream_state::x2222_io(address_map &map)
390 {
391 	map(0x4000, 0x4003).portr("P1");
392 	map(0x4004, 0x4007).portr("P2");
393 	map(0x4008, 0x400b).portr("SYS");
394 	map(0x4010, 0x4013).portr("DSW");
395 	map(0x4028, 0x402b).w(FUNC(gstream_state::x2222_sound_w));
396 	map(0x4034, 0x4037).portr("IN4");
397 }
398 
399 static INPUT_PORTS_START( gstream )
400 	PORT_START("IN0")
401 	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
402 	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
403 	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
404 	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
405 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
406 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
407 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1)
408 	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1)
409 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
410 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_COIN1 )
411 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START1 )
412 	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_SERVICE1 )
413 	PORT_BIT( 0x7000, IP_ACTIVE_LOW, IPT_UNUSED )
414 	PORT_SERVICE_NO_TOGGLE( 0x8000, IP_ACTIVE_LOW )
415 
416 	PORT_START("IN1")
417 	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
418 	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
419 	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
420 	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
421 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
422 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
423 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2)
424 	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2)
425 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
426 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_COIN2 )
427 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START2 )
428 	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_SERVICE2 )
429 	PORT_BIT( 0x7000, IP_ACTIVE_LOW, IPT_UNUSED )
430 	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_READ_LINE_MEMBER(gstream_state, mirror_service_r)
431 
432 	PORT_START("IN2")
433 	PORT_BIT( 0x004f, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_CUSTOM_MEMBER(gstream_state, gstream_mirror_r)
434 	PORT_BIT( 0xffb0, IP_ACTIVE_LOW, IPT_UNUSED )
435 INPUT_PORTS_END
436 
437 
438 static INPUT_PORTS_START( x2222 )
439 	PORT_START("P1")
440 	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
441 	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
442 	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
443 	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
444 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
445 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
446 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNUSED )
447 	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED )
448 
449 	PORT_START("P2")
450 	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
451 	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
452 	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
453 	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
454 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
455 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
456 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNUSED )
457 	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED )
458 
459 	PORT_START("SYS")
460 	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_COIN1 )
461 	PORT_DIPNAME( 0x0002, 0x0002, "IN1" )
462 	PORT_DIPSETTING(      0x0002, DEF_STR( Off ) )
463 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
464 	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_START1 )
465 	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START2 )
466 	PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Unknown ) )
467 	PORT_DIPSETTING(      0x0010, DEF_STR( Off ) )
468 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
469 	PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Unknown ) )
470 	PORT_DIPSETTING(      0x0020, DEF_STR( Off ) )
471 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
472 	PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Unknown ) )
473 	PORT_DIPSETTING(      0x0040, DEF_STR( Off ) )
474 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
475 	PORT_DIPNAME( 0x0080, 0x0080, DEF_STR( Unknown ) )
476 	PORT_DIPSETTING(      0x0080, DEF_STR( Off ) )
477 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
478 
479 	PORT_START("DSW")
480 	PORT_DIPNAME( 0x0001, 0x0001, DEF_STR( Free_Play ) ) // always 99 credits
481 	PORT_DIPSETTING(      0x0001, DEF_STR( Off ) )
482 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
483 	PORT_DIPNAME( 0x0006, 0x0004, DEF_STR( Difficulty ) )
484 	PORT_DIPSETTING(      0x0000, DEF_STR( Easy ) )
485 	PORT_DIPSETTING(      0x0004, DEF_STR( Normal ) )
486 	PORT_DIPSETTING(      0x0002, DEF_STR( Hard ) )
487 	PORT_DIPSETTING(      0x0006, DEF_STR( Very_Hard ) )
488 	PORT_DIPNAME( 0x0018, 0x0008, DEF_STR( Lives ) )
489 	PORT_DIPSETTING(      0x0000, "1" )
490 	PORT_DIPSETTING(      0x0008, "2" )
491 	PORT_DIPSETTING(      0x0010, "3" )
492 	PORT_DIPSETTING(      0x0018, "4" )
493 	PORT_DIPNAME( 0x00e0, 0x0000, DEF_STR( Coin_A ) )
494 	PORT_DIPSETTING(      0x0020, DEF_STR( 2C_1C ) )
495 	PORT_DIPSETTING(      0x0000, DEF_STR( 1C_1C ) )
496 	PORT_DIPSETTING(      0x0040, "2" )
497 	PORT_DIPSETTING(      0x0060, "3" )
498 	PORT_DIPSETTING(      0x0080, "4" )
499 	PORT_DIPSETTING(      0x00a0, "5" )
500 	PORT_DIPSETTING(      0x00c0, "6" )
501 	PORT_DIPSETTING(      0x00e0, "7" )
502 
503 	PORT_START("IN4")
504 	PORT_DIPNAME( 0x0001, 0x0001, "IN4" )
505 	PORT_DIPSETTING(      0x0001, DEF_STR( Off ) )
506 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
507 	PORT_DIPNAME( 0x0002, 0x0002, DEF_STR( Unknown ) )
508 	PORT_DIPSETTING(      0x0002, DEF_STR( Off ) )
509 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
510 	PORT_DIPNAME( 0x0004, 0x0004, DEF_STR( Unknown ) )
511 	PORT_DIPSETTING(      0x0004, DEF_STR( Off ) )
512 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
513 	PORT_DIPNAME( 0x0008, 0x0008, DEF_STR( Unknown ) )
514 	PORT_DIPSETTING(      0x0008, DEF_STR( Off ) )
515 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
516 	PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Unknown ) )
517 	PORT_DIPSETTING(      0x0010, DEF_STR( Off ) )
518 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
519 	PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Unknown ) )
520 	PORT_DIPSETTING(      0x0020, DEF_STR( Off ) )
521 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
522 	PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Unknown ) )
523 	PORT_DIPSETTING(      0x0040, DEF_STR( Off ) )
524 	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
525 	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_READ_LINE_MEMBER(gstream_state, x2222_toggle_r)
526 INPUT_PORTS_END
527 
528 
529 static const gfx_layout layout16x16 =
530 {
531 	16,16,
532 	RGN_FRAC(1,1),
533 	8,
534 	{ STEP8(0,1) },
535 	{ STEP16(0,8) },
536 	{ STEP16(0,8*16) },
537 	16*16*8,
538 };
539 
540 
541 static const gfx_layout layout32x32 =
542 {
543 	32,32,
544 	RGN_FRAC(1,1),
545 	8,
546 	{ STEP8(0,1) },
547 	{ STEP32(0,8) },
548 	{ STEP32(0,8*32) },
549 	32*32*8,
550 };
551 
552 static GFXDECODE_START( gfx_gstream )
553 	GFXDECODE_ENTRY( "gfx2", 0, layout32x32, 0x1000, 4 )
554 	GFXDECODE_ENTRY( "gfx3", 0, layout32x32, 0x1400, 4 )
555 	GFXDECODE_ENTRY( "gfx4", 0, layout32x32, 0x1800, 4 )
556 	GFXDECODE_ENTRY( "gfx1", 0, layout16x16, 0,      32 )
557 GFXDECODE_END
558 
559 
GFXDECODE_START(gfx_x2222)560 static GFXDECODE_START( gfx_x2222 )
561 	GFXDECODE_ENTRY( "gfx2", 0, layout32x32, 0, 0x80 )
562 	GFXDECODE_ENTRY( "gfx3", 0, layout32x32, 0, 0x80 )
563 	GFXDECODE_ENTRY( "gfx4", 0, layout32x32, 0, 0x80 )
564 	GFXDECODE_ENTRY( "gfx1", 0, layout16x16, 0, 0x80 )
565 	GFXDECODE_ENTRY( "gfx1_lower", 0, layout16x16, 0, 0x80 )
566 	GFXDECODE_ENTRY( "gfx2_lower", 0, layout32x32, 0, 0x80 )
567 	GFXDECODE_ENTRY( "gfx3_lower", 0, layout32x32, 0, 0x80 )
568 	GFXDECODE_ENTRY( "gfx4_lower", 0, layout32x32, 0, 0x80 )
569 GFXDECODE_END
570 
571 
572 void gstream_state::video_start()
573 {
574 }
575 
576 
577 // custom drawgfx function for x2222 to draw RGB data instead of indexed data, needed because our regular drawgfx and tilemap code don't support that
drawgfx_transpen_x2222(bitmap_rgb32 & dest,const rectangle & cliprect,gfx_element * gfx,gfx_element * gfx2,uint32_t code,int flipx,int flipy,int32_t destx,int32_t desty)578 void gstream_state::drawgfx_transpen_x2222(bitmap_rgb32 &dest, const rectangle &cliprect, gfx_element *gfx,gfx_element *gfx2,
579 		uint32_t code, int flipx, int flipy, int32_t destx, int32_t desty)
580 {
581 	// use pen usage to optimize
582 	code %= gfx->elements();
583 	const pen_t *rgb = m_palette->pens(); // 16 bit BGR
584 
585 	// render
586 
587 	do {
588 		g_profiler.start(PROFILER_DRAWGFX);
589 		do {
590 			int32_t destendx, destendy;
591 			int32_t srcx, srcy;
592 			int32_t dy;
593 
594 			assert(dest.valid());
595 			assert(gfx != nullptr);
596 			assert(dest.cliprect().contains(cliprect));
597 			assert(code < gfx->elements());
598 
599 			/* ignore empty/invalid cliprects */
600 			if (cliprect.empty())
601 				break;
602 
603 			/* compute final pixel in X and exit if we are entirely clipped */
604 			destendx = destx + gfx->width() - 1;
605 			if (destx > cliprect.max_x || destendx < cliprect.min_x)
606 				break;
607 
608 			/* apply left clip */
609 			srcx = 0;
610 			if (destx < cliprect.min_x)
611 			{
612 				srcx = cliprect.min_x - destx;
613 				destx = cliprect.min_x;
614 			}
615 
616 			/* apply right clip */
617 			if (destendx > cliprect.max_x)
618 				destendx = cliprect.max_x;
619 
620 			/* compute final pixel in Y and exit if we are entirely clipped */
621 			destendy = desty + gfx->height() - 1;
622 			if (desty > cliprect.max_y || destendy < cliprect.min_y)
623 				break;
624 
625 			/* apply top clip */
626 			srcy = 0;
627 			if (desty < cliprect.min_y)
628 			{
629 				srcy = cliprect.min_y - desty;
630 				desty = cliprect.min_y;
631 			}
632 
633 			/* apply bottom clip */
634 			if (destendy > cliprect.max_y)
635 				destendy = cliprect.max_y;
636 
637 			/* apply X flipping */
638 			if (flipx)
639 				srcx = gfx->width() - 1 - srcx;
640 
641 			/* apply Y flipping */
642 			dy = gfx->rowbytes();
643 			if (flipy)
644 			{
645 				srcy = gfx->height() - 1 - srcy;
646 				dy = -dy;
647 			}
648 
649 			/* fetch the source data */
650 			const uint8_t *srcdata = gfx->get_data(code);
651 			const uint8_t *srcdata2 = gfx2->get_data(code);
652 
653 			/* compute how many blocks of 4 pixels we have */
654 			uint32_t leftovers = (destendx + 1 - destx);
655 
656 			/* adjust srcdata to point to the first source pixel of the row */
657 			srcdata += srcy * gfx->rowbytes() + srcx;
658 			srcdata2 += srcy * gfx->rowbytes() + srcx;
659 
660 			/* non-flipped 16bpp case */
661 			if (!flipx)
662 			{
663 				/* iterate over pixels in Y */
664 				for (int32_t cury = desty; cury <= destendy; cury++)
665 				{
666 					uint32_t *destptr = &dest.pix(cury, destx);
667 					const uint8_t *srcptr = srcdata;
668 					const uint8_t *srcptr2 = srcdata2;
669 					srcdata += dy;
670 					srcdata2 += dy;
671 
672 					/* iterate over leftover pixels */
673 					for (int32_t curx = 0; curx < leftovers; curx++)
674 					{
675 						uint32_t srcdata = (srcptr[0]);
676 						uint32_t srcdata2 = (srcptr2[0]);
677 
678 						uint16_t full = (srcdata | (srcdata2 << 8));
679 						if (full != 0)
680 							destptr[0] = rgb[full];
681 
682 						srcptr++;
683 						srcptr2++;
684 						destptr++;
685 					}
686 				}
687 			}
688 
689 			/* flipped 16bpp case */
690 			else
691 			{
692 				/* iterate over pixels in Y */
693 				for (int32_t cury = desty; cury <= destendy; cury++)
694 				{
695 					uint32_t *destptr = &dest.pix(cury, destx);
696 					const uint8_t *srcptr = srcdata;
697 					const uint8_t *srcptr2 = srcdata2;
698 
699 					srcdata += dy;
700 					srcdata2 += dy;
701 
702 					/* iterate over leftover pixels */
703 					for (int32_t curx = 0; curx < leftovers; curx++)
704 					{
705 						uint32_t srcdata = (srcptr[0]);
706 						uint32_t srcdata2 = (srcptr2[0]);
707 
708 						uint16_t full = (srcdata | (srcdata2 << 8));
709 						if (full != 0)
710 							destptr[0] = rgb[full];
711 
712 						srcptr--;
713 						srcptr2--;
714 						destptr++;
715 					}
716 				}
717 			}
718 		} while (0);
719 		g_profiler.stop();
720 	} while (0);
721 }
722 
draw_bg(bitmap_rgb32 & bitmap,const rectangle & cliprect,int map,uint32_t * ram)723 void gstream_state::draw_bg(bitmap_rgb32 &bitmap, const rectangle &cliprect, int map, uint32_t* ram )
724 {
725 	int scrollx;
726 	int scrolly;
727 
728 	scrollx = m_scrollx[map]&0x1ff;
729 	scrolly = m_scrolly[map]&0x1ff;
730 
731 	uint16_t basey = scrolly>>5;
732 	for (int y=0;y<13;y++)
733 	{
734 		uint16_t basex = scrollx>>5;
735 		for (int x=0;x<16;x++)
736 		{
737 			int vram_data = (ram[(basex&0x0f)+((basey&0x0f)*0x10)]) >> 16;
738 			int pal = (vram_data & 0xc000) >> 14;
739 			int code = (vram_data & 0x0fff);
740 
741 			if (m_gfxdecode->gfx(map+5))
742 				drawgfx_transpen_x2222(bitmap,cliprect,m_gfxdecode->gfx(map),m_gfxdecode->gfx(map+5),code,0,0,(x*32)-(scrollx&0x1f)-m_xoffset,(y*32)-(scrolly&0x1f));
743 			else
744 				m_gfxdecode->gfx(map)->transpen(bitmap,cliprect,code,pal,0,0,(x*32)-(scrollx&0x1f)-m_xoffset,(y*32)-(scrolly&0x1f),0);
745 
746 			basex++;
747 		}
748 		basey++;
749 	}
750 }
751 
screen_update(screen_device & screen,bitmap_rgb32 & bitmap,const rectangle & cliprect)752 uint32_t gstream_state::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
753 {
754 	/* The tilemaps and sprite are interleaved together.
755 	   Even Words are tilemap tiles
756 	   Odd Words are sprite data
757 
758 	   Sprites start at the top of memory, tilemaps at
759 	   the bottom, but the areas can overlap
760 
761 	   *What seems an actual game bug*
762 	   when a sprite ends up with a negative co-ordinate
763 	   a value of 0xfffffffe gets set in the sprite list.
764 	   this could corrupt the tile value as both words
765 	   are being set ?!
766 
767 	   x2222 seems to set none of these bits but has other wraparound issues
768 
769 	*/
770 
771 	int i;
772 
773 	//popmessage("(1) %08x %08x (2) %08x %08x (3) %08x %08x", m_scrollx[0], m_scrolly[0], m_scrollx[1], m_scrolly[1], m_scrollx[2], m_scrolly[2] );
774 	bitmap.fill(0,cliprect);
775 
776 
777 	draw_bg(bitmap, cliprect, 2, m_vram + 0x800/4);
778 	draw_bg(bitmap, cliprect, 1, m_vram + 0x400/4);
779 	draw_bg(bitmap, cliprect, 0, m_vram + 0x000/4); // move on top for x2222 , check
780 
781 	int clk = 0;
782 	int clk_max = 432 * 262; // total usable cycle count for sprites; TODO : measure screen size, related to that?
783 	for (i = 0x0000 / 4; i < 0x4000 / 4; i += 4) // can't be drawable everything
784 	{
785 		clk += 8+128; // uses 8 cycle per RAM, 128 cycle per drawing tile
786 		if (clk >= clk_max)
787 			break;
788 
789 		/* Upper bits are used by the tilemaps */
790 		int code = m_vram[i + 0] & 0xffff;
791 		int x = m_vram[i + 1] & 0x1ff;
792 		int y = m_vram[i + 2] & 0xff;
793 		int col = m_vram[i + 3] & 0x1f;
794 
795 		if (m_gfxdecode->gfx(4))
796 		{
797 			drawgfx_transpen_x2222(bitmap, cliprect, m_gfxdecode->gfx(3), m_gfxdecode->gfx(4), code, 0, 0, x - m_xoffset, y);
798 			drawgfx_transpen_x2222(bitmap, cliprect, m_gfxdecode->gfx(3), m_gfxdecode->gfx(4), code, 0, 0, x - m_xoffset, y-0x100);
799 			drawgfx_transpen_x2222(bitmap, cliprect, m_gfxdecode->gfx(3), m_gfxdecode->gfx(4), code, 0, 0, x - m_xoffset - 0x200, y);
800 			drawgfx_transpen_x2222(bitmap, cliprect, m_gfxdecode->gfx(3), m_gfxdecode->gfx(4), code, 0, 0, x - m_xoffset - 0x200 , y-0x100);
801 
802 		}
803 		else
804 		{
805 			m_gfxdecode->gfx(3)->transpen(bitmap, cliprect, code, col, 0, 0, x - m_xoffset, y, 0);
806 			m_gfxdecode->gfx(3)->transpen(bitmap, cliprect, code, col, 0, 0, x - m_xoffset, y-0x100, 0);
807 			m_gfxdecode->gfx(3)->transpen(bitmap, cliprect, code, col, 0, 0, x - m_xoffset - 0x200, y, 0);
808 			m_gfxdecode->gfx(3)->transpen(bitmap, cliprect, code, col, 0, 0, x - m_xoffset - 0x200, y-0x100, 0);
809 
810 		}
811 	}
812 	return 0;
813 }
814 
815 
machine_start()816 void gstream_state::machine_start()
817 {
818 	save_item(NAME(m_scrollx));
819 	save_item(NAME(m_scrolly));
820 	save_item(NAME(m_oki_bank));
821 }
822 
machine_reset()823 void gstream_state::machine_reset()
824 {
825 	m_scrollx[0] = 0;
826 	m_scrollx[1] = 0;
827 	m_scrollx[2] = 0;
828 	m_scrolly[0] = 0;
829 	m_scrolly[1] = 0;
830 	m_scrolly[2] = 0;
831 	m_oki_bank[0] = m_oki_bank[1] = 0;
832 }
833 
gstream(machine_config & config)834 void gstream_state::gstream(machine_config &config)
835 {
836 	/* basic machine hardware */
837 	E132XT(config, m_maincpu, 16000000*4); /* 4x internal multiplier */
838 	m_maincpu->set_addrmap(AS_PROGRAM, &gstream_state::gstream_32bit_map);
839 	m_maincpu->set_addrmap(AS_IO, &gstream_state::gstream_io);
840 	m_maincpu->set_vblank_int("screen", FUNC(gstream_state::irq0_line_hold));
841 
842 	NVRAM(config, "nvram", nvram_device::DEFAULT_ALL_1);
843 
844 	/* video hardware */
845 	screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
846 	screen.set_refresh_hz(60);
847 	screen.set_vblank_time(ATTOSECONDS_IN_USEC(0));
848 	screen.set_size(320, 240);
849 	screen.set_visarea_full();
850 	screen.set_screen_update(FUNC(gstream_state::screen_update));
851 
852 	PALETTE(config, m_palette).set_format(palette_device::BGR_565, 0x1000 + 0x400 + 0x400 + 0x400); // sprites + 3 bg layers
853 
854 	GFXDECODE(config, m_gfxdecode, m_palette, gfx_gstream);
855 
856 	SPEAKER(config, "mono").front_center();
857 
858 	OKIM6295(config, m_oki[0], 1000000, okim6295_device::PIN7_HIGH).add_route(ALL_OUTPUTS, "mono", 1.00); /* 1 Mhz? */
859 
860 	OKIM6295(config, m_oki[1], 1000000, okim6295_device::PIN7_HIGH).add_route(ALL_OUTPUTS, "mono", 1.00); /* 1 Mhz? */
861 }
862 
x2222(machine_config & config)863 void gstream_state::x2222(machine_config &config)
864 {
865 	/* basic machine hardware */
866 	E132XT(config, m_maincpu, 16000000*4); /* 4x internal multiplier */
867 	m_maincpu->set_addrmap(AS_PROGRAM, &gstream_state::x2222_32bit_map);
868 	m_maincpu->set_addrmap(AS_IO, &gstream_state::x2222_io);
869 	m_maincpu->set_vblank_int("screen", FUNC(gstream_state::irq0_line_hold));
870 
871 //  NVRAM(config, "nvram", nvram_device::DEFAULT_ALL_1);
872 
873 	/* video hardware */
874 	screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
875 	screen.set_refresh_hz(60);
876 	screen.set_vblank_time(ATTOSECONDS_IN_USEC(0));
877 	screen.set_size(320, 240);
878 	screen.set_visarea_full();
879 	screen.set_screen_update(FUNC(gstream_state::screen_update));
880 
881 	PALETTE(config, m_palette, palette_device::BGR_565);
882 
883 	GFXDECODE(config, m_gfxdecode, m_palette, gfx_x2222);
884 
885 	// unknown sound hw (no sound roms dumped)
886 
887 	SPEAKER(config, "mono").front_center();
888 
889 	OKIM6295(config, m_oki[0], 1000000, okim6295_device::PIN7_HIGH).add_route(ALL_OUTPUTS, "mono", 1.00); /* 1 Mhz? */
890 }
891 
892 
893 ROM_START( gstream )
894 	ROM_REGION32_BE( 0x80000, "maincpu", 0 ) /* Hyperstone CPU Code */
895 	ROM_LOAD( "gs_prg_01.u56", 0x000000, 0x080000, CRC(0d0c6a38) SHA1(a810bfc1c9158cccc37710d0ea7268e26e520cc2) )
896 
897 	ROM_REGION32_BE( 0x200000, "maindata", 0 ) /* Hyperstone CPU Code */
898 	ROM_LOAD16_WORD_SWAP( "gs_prg_02.u197", 0x000000, 0x200000, CRC(2f8a6bea) SHA1(c0a32838f4bd8599f09002139f87562db625c1c5) )
899 
900 	ROM_REGION( 0x1000000, "gfx1", 0 )  /* sprite tiles (16x16x8) */
901 	ROM_LOAD32_WORD( "gs_gr_07.u107", 0x000000, 0x200000, CRC(84e66fe1) SHA1(73d828714f9ed9baffdc06998f5bf3298396fe9c) )
902 	ROM_LOAD32_WORD( "gs_gr_11.u108", 0x000002, 0x200000, CRC(946d71d1) SHA1(516bd3f4d7f5bce59f0593ed6565114dbd5a4ef0) )
CRC(abd0d6aa)903 	ROM_LOAD32_WORD( "gs_gr_08.u109", 0x400000, 0x200000, CRC(abd0d6aa) SHA1(dd294bbdda05697df84247257f735ab51bc26ca3) )
904 	ROM_LOAD32_WORD( "gs_gr_12.u110", 0x400002, 0x200000, CRC(94b56e4e) SHA1(7c3877f993e575326dbd4c2e5d7570747277b20d) )
905 	ROM_LOAD32_WORD( "gs_gr_09.u180", 0x800000, 0x200000, CRC(f2c4fd77) SHA1(284c850688e3c0fd292a91a53e24fe3436dc4076) )
906 	ROM_LOAD32_WORD( "gs_gr_13.u181", 0x800002, 0x200000, CRC(7daaeff0) SHA1(5766d9a3a8c0931305424e0089108ce8df7dfe41) )
907 	ROM_LOAD32_WORD( "gs_gr_10.u182", 0xc00000, 0x200000, CRC(d696d15d) SHA1(85aaa5cdb35f3a8d3266bb8debec0558c860cb53) )
908 	ROM_LOAD32_WORD( "gs_gr_14.u183", 0xc00002, 0x200000, CRC(6bd2a1e1) SHA1(aedca91643f14ececc101a7708255ce9b1d70f68) )
909 
910 	ROM_REGION( 0x400000, "gfx2", 0 )  /* bg tiles (32x32x8) */
911 	ROM_LOAD( "gs_gr_01.u120", 0x000000, 0x200000, CRC(b82cfab8) SHA1(08f0eaef5c927fb056c6cc9342e39f445aae9062) )
912 	ROM_LOAD( "gs_gr_02.u121", 0x200000, 0x200000, CRC(37e19cbd) SHA1(490ebb037fce09100ec4bba3f73ecdf101526641) )
913 
914 	ROM_REGION( 0x400000, "gfx3", 0 )  /* bg tiles (32x32x8) */
915 	ROM_LOAD( "gs_gr_03.u125", 0x000000, 0x200000, CRC(1a3b2b11) SHA1(a4b1dc1a9709f8f8f2ab2190d7badc246caa540f) )
916 	ROM_LOAD( "gs_gr_04.u126", 0x200000, 0x200000, CRC(a4e8906c) SHA1(b285d7697cdaa62014cf65d09a19fcbd6a95bb98) )
917 
918 	ROM_REGION( 0x400000, "gfx4", 0 )  /* bg tiles (32x32x8) */
919 	ROM_LOAD( "gs_gr_05.u174", 0x000000, 0x200000, CRC(ef283a73) SHA1(8b598facb344eac33138611abc141a2acb375983) )
920 	ROM_LOAD( "gs_gr_06.u175", 0x200000, 0x200000, CRC(d4e3a2b2) SHA1(4577c007172c718bf7ca55a8ccee5455c281026c) )
921 
922 	ROM_REGION( 0x100000, "oki1", 0 )
923 	ROM_LOAD( "gs_snd_01.u192", 0x000000, 0x080000, CRC(79b64d3f) SHA1(b2166210d3a3b85b9ace90749a444c881f69d551) )
924 	ROM_LOAD( "gs_snd_02.u194", 0x080000, 0x080000, CRC(e49ed92c) SHA1(a3d7b3fe93a786a246acf2657d9056398c793078) )
925 
926 	ROM_REGION( 0x100000, "oki2", 0 )
927 	ROM_LOAD( "gs_snd_03.u191", 0x000000, 0x080000, CRC(2bfff4ac) SHA1(cce1bb3c78b86722c926854c737f9589806012ba) )
928 	ROM_LOAD( "gs_snd_04.u193", 0x080000, 0x080000, CRC(b259de3b) SHA1(1a64f41d4344fefad5832332f1a7655e23f6b017) )
929 
930 	ROM_REGION( 0x2000, "nvram", 0 )
931 	ROM_LOAD( "gstream.nv", 0x000000, 0x2000, CRC(895d724b) SHA1(97941102f94923220d9beb270939f0ad9a40fe0e) )
932 ROM_END
933 
934 
935 
936 
937 ROM_START( x2222 )
938 	ROM_REGION32_BE( 0x100000, "maincpu", 0 ) /* Hyperstone CPU Code */
939 	ROM_LOAD( "test.bin", 0x000000, 0x100000, CRC(6260421e) SHA1(095e955d029e98e024d4ec5c7f93a6d4845a92a0) ) // final version - but debug enabled, values on screen, maybe there's a flag in the ROM we can turn off?
940 
941 	ROM_REGION32_BE( 0x0200000, "misc", 0 ) /* other code */
942 	ROM_LOAD( "test.hye", 0x000000, 0x0112dda, CRC(c1142b2f) SHA1(5807930820a53604013a6ac66e4d4ebe3628e1fc) ) // the above binary was built from this
943 
944 	/* x2222 uses raw rgb16 data rather than 8bpp indexed, in order to use the same gfx decodes with a custom draw routine we arrange the data into 2 8bpp regions on init */
945 	ROM_REGION( 0x800000, "gfx1", ROMREGION_ERASE00 )  /* sprite tiles (16x16x8) */
946 	/* filled in at init*/
947 
948 	ROM_REGION( 0x200000, "gfx2", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
949 	/* filled in at init*/
950 
951 	ROM_REGION( 0x200000, "gfx3", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
952 	/* filled in at init*/
953 
954 	ROM_REGION( 0x200000, "gfx4", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
955 	/* filled in at init*/
956 
957 	/* 2nd 8-bits */
958 	ROM_REGION( 0x800000, "gfx1_lower", ROMREGION_ERASE00 )  /* sprite tiles (16x16x8) */
959 	/* filled in at init*/
960 
961 	ROM_REGION( 0x200000, "gfx2_lower", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
962 	/* filled in at init*/
963 
964 	ROM_REGION( 0x200000, "gfx3_lower", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
965 	/* filled in at init*/
966 
967 	ROM_REGION( 0x200000, "gfx4_lower", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
968 	/* filled in at init*/
969 
970 	ROM_REGION( 0x1000000, "sprites", 0 )  /* sprite tiles (16x16x16) */
971 	ROM_LOAD( "spr11.bin", 0x000000, 0x200000, CRC(1d15b444) SHA1(27ace509a7e4ec2e62453636acf444a861bb85ce) )
972 	ROM_LOAD( "spr21.bin", 0x200000, 0x1b8b00, CRC(1c392be2) SHA1(775882f588a8bef33a79fa4f25754a47dc82cb30) )
973 	ROM_LOAD( "spr12.bin", 0x400000, 0x200000, CRC(73225936) SHA1(50507c52b932198659e08d22d3c0a92e7c69e5ba) )
974 	ROM_LOAD( "spr22.bin", 0x600000, 0x1b8b00, CRC(cf7ebfa1) SHA1(c968dcf768e5598240f5a131414a5607899b4bef) )
975 	ROM_LOAD( "spr13.bin", 0x800000, 0x200000, CRC(52595c51) SHA1(a161a5f433aa7aa2f7824ea6b9b70d73ca63b62d) )
976 	ROM_LOAD( "spr23.bin", 0xa00000, 0x1b8b00, CRC(d894461e) SHA1(14dccfa8c762d928eaea0ac4cfff7d1272b69fdd) )
977 	ROM_LOAD( "spr14.bin", 0xc00000, 0x200000, CRC(f6cd6599) SHA1(170ea7a9a26fd8038df53fb333357766dabbe7c2) )
978 	ROM_LOAD( "spr24.bin", 0xe00000, 0x1b8b00, CRC(9542cb08) SHA1(d40c1f0b7d3e9deb12284c2f2c2df0ac43cb6cd2) )
979 
980 	ROM_REGION( 0x400000, "bg1", 0 )  /* bg tiles (32x32x16) */
981 	ROM_LOAD16_BYTE( "bg31.bin", 0x000000, 0x11ac00, CRC(12e67bc2) SHA1(18618a8931af3b3aeab34fd50424a7ffb3da6458) )
982 	ROM_LOAD16_BYTE( "bg32.bin", 0x000001, 0x11ac00, CRC(95afa0da) SHA1(e534bc0874329475ce7efa836000fe29fc76c44c) )
983 
984 	ROM_REGION( 0x400000, "bg2", 0 )  /* bg tiles (32x32x16) */
985 	ROM_LOAD16_BYTE( "bg21.bin", 0x000000, 0x1c8400, CRC(a10220f8) SHA1(9aa43a8e23cdf55d8623d2694b04971eaced9ba9) )
986 	ROM_LOAD16_BYTE( "bg22.bin", 0x000001, 0x1c8400, CRC(966f7c1d) SHA1(4699a3014c7e66d0dabd8d7982f43114b71181b7) )
987 
988 	ROM_REGION( 0x400000, "bg3", 0 )  /* bg tiles (32x32x16) */
989 	ROM_LOAD16_BYTE( "bg11.bin", 0x000000, 0x1bc800, CRC(68975462) SHA1(7a2458a3d2465b727f4f5bf45685f35eb4885975) )
990 	ROM_LOAD16_BYTE( "bg12.bin", 0x000001, 0x1bc800, CRC(feef1240) SHA1(9eb123a19ade74d8b3ce4df0b04ca97c03fb9fdc) )
991 
992 	// no idea what the sound hw is?
993 	ROM_REGION( 0x100000, "oki1", ROMREGION_ERASE00 )
994 	ROM_LOAD( "x2222_sound", 0x000000, 0x080000,NO_DUMP ) // probably an oki.. is there a sound cpu too?
995 ROM_END
996 
997 
998 
999 ROM_START( x2222o )
1000 	ROM_REGION32_BE( 0x100000, "maincpu", 0 ) /* Hyperstone CPU Code */
1001 	ROM_LOAD( "older.bin", 0x080000, 0x080000, CRC(d12817bc) SHA1(2458f9d9020598a1646dfc848fddd323eebc5120) )
1002 
1003 	ROM_REGION32_BE( 0x0200000, "misc", 0 ) /* other code */
1004 	ROM_LOAD( "older.hye", 0x000000, 0x010892f, CRC(cf3a004e) SHA1(1cba64cfa235b9540f33a5ee0cc02dfd267e00fc) ) // this corresponds to the older.bin we're using, for reference
1005 
1006 	/* x2222 uses raw rgb16 data rather than 8bpp indexed, in order to use the same gfx decodes with a custom draw routine we arrange the data into 2 8bpp regions on init */
1007 	ROM_REGION( 0x800000, "gfx1", ROMREGION_ERASE00 )  /* sprite tiles (16x16x8) */
1008 	/* filled in at init*/
1009 
1010 	ROM_REGION( 0x200000, "gfx2", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
1011 	/* filled in at init*/
1012 
1013 	ROM_REGION( 0x200000, "gfx3", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
1014 	/* filled in at init*/
1015 
1016 	ROM_REGION( 0x200000, "gfx4", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
1017 	/* filled in at init*/
1018 
1019 	/* 2nd 8-bits */
1020 	ROM_REGION( 0x800000, "gfx1_lower", ROMREGION_ERASE00 )  /* sprite tiles (16x16x8) */
1021 	/* filled in at init*/
1022 
1023 	ROM_REGION( 0x200000, "gfx2_lower", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
1024 	/* filled in at init*/
1025 
1026 	ROM_REGION( 0x200000, "gfx3_lower", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
1027 	/* filled in at init*/
1028 
1029 	ROM_REGION( 0x200000, "gfx4_lower", ROMREGION_ERASE00 )  /* bg tiles (32x32x8) */
1030 	/* filled in at init*/
1031 
1032 	ROM_REGION( 0x1000000, "sprites", 0 )  /* sprite tiles (16x16x16) */ // these sprite ROMs have the Boss tiles in the wrong location for the prototype program rom
1033 	ROM_LOAD( "spr11.bin", 0x000000, 0x200000, BAD_DUMP CRC(1d15b444) SHA1(27ace509a7e4ec2e62453636acf444a861bb85ce) )
1034 	ROM_LOAD( "spr21.bin", 0x200000, 0x1b8b00, BAD_DUMP CRC(1c392be2) SHA1(775882f588a8bef33a79fa4f25754a47dc82cb30) )
1035 	ROM_LOAD( "spr12.bin", 0x400000, 0x200000, BAD_DUMP CRC(73225936) SHA1(50507c52b932198659e08d22d3c0a92e7c69e5ba) )
1036 	ROM_LOAD( "spr22.bin", 0x600000, 0x1b8b00, BAD_DUMP CRC(cf7ebfa1) SHA1(c968dcf768e5598240f5a131414a5607899b4bef) )
1037 	ROM_LOAD( "spr13.bin", 0x800000, 0x200000, BAD_DUMP CRC(52595c51) SHA1(a161a5f433aa7aa2f7824ea6b9b70d73ca63b62d) )
1038 	ROM_LOAD( "spr23.bin", 0xa00000, 0x1b8b00, BAD_DUMP CRC(d894461e) SHA1(14dccfa8c762d928eaea0ac4cfff7d1272b69fdd) )
1039 	ROM_LOAD( "spr14.bin", 0xc00000, 0x200000, BAD_DUMP CRC(f6cd6599) SHA1(170ea7a9a26fd8038df53fb333357766dabbe7c2) )
1040 	ROM_LOAD( "spr24.bin", 0xe00000, 0x1b8b00, BAD_DUMP CRC(9542cb08) SHA1(d40c1f0b7d3e9deb12284c2f2c2df0ac43cb6cd2) )
1041 
1042 	ROM_REGION( 0x400000, "bg1", 0 )  /* bg tiles (32x32x16) */
1043 	ROM_LOAD16_BYTE( "bg31.bin", 0x000000, 0x11ac00, CRC(12e67bc2) SHA1(18618a8931af3b3aeab34fd50424a7ffb3da6458) )
1044 	ROM_LOAD16_BYTE( "bg32.bin", 0x000001, 0x11ac00, CRC(95afa0da) SHA1(e534bc0874329475ce7efa836000fe29fc76c44c) )
1045 
1046 	ROM_REGION( 0x400000, "bg2", 0 )  /* bg tiles (32x32x16) */
1047 	ROM_LOAD16_BYTE( "bg21.bin", 0x000000, 0x1c8400, CRC(a10220f8) SHA1(9aa43a8e23cdf55d8623d2694b04971eaced9ba9) )
1048 	ROM_LOAD16_BYTE( "bg22.bin", 0x000001, 0x1c8400, CRC(966f7c1d) SHA1(4699a3014c7e66d0dabd8d7982f43114b71181b7) )
1049 
1050 	ROM_REGION( 0x400000, "bg3", 0 )  /* bg tiles (32x32x16) */
1051 	ROM_LOAD16_BYTE( "bg11.bin", 0x000000, 0x1bc800, CRC(68975462) SHA1(7a2458a3d2465b727f4f5bf45685f35eb4885975) )
1052 	ROM_LOAD16_BYTE( "bg12.bin", 0x000001, 0x1bc800, CRC(feef1240) SHA1(9eb123a19ade74d8b3ce4df0b04ca97c03fb9fdc) )
1053 
1054 	// no idea what the sound hw is?
1055 	ROM_REGION( 0x100000, "oki1", ROMREGION_ERASE00 )
1056 	ROM_LOAD( "x2222_sound", 0x000000, 0x080000,NO_DUMP ) // probably an oki.. is there a sound cpu too?
1057 ROM_END
1058 
1059 
1060 uint32_t gstream_state::gstream_speedup_r()
1061 {
1062 	if (m_maincpu->pc() == 0xc0001592)
1063 	{
1064 		m_maincpu->eat_cycles(50);
1065 	}
1066 
1067 	return m_workram[0xd1ee0 / 4];
1068 }
1069 
1070 
x2222_speedup_r()1071 uint32_t gstream_state::x2222_speedup_r()
1072 {
1073 	if (m_maincpu->pc() == 0x22064)
1074 	{
1075 		m_maincpu->eat_cycles(50);
1076 	}
1077 
1078 	return m_workram[0x7ffac / 4];
1079 }
1080 
x2222_speedup2_r()1081 uint32_t gstream_state::x2222_speedup2_r()
1082 {
1083 	if (m_maincpu->pc() == 0x23f44)
1084 	{
1085 		m_maincpu->eat_cycles(50);
1086 	}
1087 
1088 	return m_workram[0x84e3c / 4];
1089 }
1090 
1091 
init_gstream()1092 void gstream_state::init_gstream()
1093 {
1094 	m_maincpu->space(AS_PROGRAM).install_read_handler(0xd1ee0, 0xd1ee3, read32smo_delegate(*this, FUNC(gstream_state::gstream_speedup_r)));
1095 
1096 	m_xoffset = 2;
1097 }
1098 
1099 
rearrange_tile_data(uint8_t * ROM,uint32_t * NEW,uint32_t * NEW2)1100 void gstream_state::rearrange_tile_data(uint8_t* ROM, uint32_t* NEW, uint32_t* NEW2)
1101 {
1102 	int i;
1103 	for (i = 0; i < 0x80000; i++)
1104 	{
1105 		NEW[i]  = (ROM[(i * 8) + 0x000000] << 0) | (ROM[(i * 8) + 0x000001] << 8) | (ROM[(i * 8) + 0x000004] << 16) | (ROM[(i * 8) + 0x000005] << 24);
1106 		NEW2[i] = (ROM[(i * 8) + 0x000002] << 0) | (ROM[(i * 8) + 0x000003] << 8) | (ROM[(i * 8) + 0x000006] << 16) | (ROM[(i * 8) + 0x000007] << 24);
1107 	}
1108 }
1109 
rearrange_sprite_data(uint8_t * ROM,uint32_t * NEW,uint32_t * NEW2)1110 void gstream_state::rearrange_sprite_data(uint8_t* ROM, uint32_t* NEW, uint32_t* NEW2)
1111 {
1112 	int i;
1113 	for (i = 0; i < 0x200000; i++)
1114 	{
1115 		NEW[i]  = (ROM[(i * 2) + 0xc00000] << 24) | (ROM[(i * 2) + 0x800000] << 16) | (ROM[(i * 2) + 0x400000] << 8) | (ROM[(i * 2) + 0x000000] << 0);
1116 		NEW2[i] = (ROM[(i * 2) + 0xc00001] << 24) | (ROM[(i * 2) + 0x800001] << 16) | (ROM[(i * 2) + 0x400001] << 8) | (ROM[(i * 2) + 0x000001] << 0);
1117 	}
1118 }
1119 
init_x2222()1120 void gstream_state::init_x2222()
1121 {
1122 	m_maincpu->space(AS_PROGRAM).install_read_handler(0x7ffac, 0x7ffaf, read32smo_delegate(*this, FUNC(gstream_state::x2222_speedup_r))); // older
1123 	m_maincpu->space(AS_PROGRAM).install_read_handler(0x84e3c, 0x84e3f, read32smo_delegate(*this, FUNC(gstream_state::x2222_speedup2_r))); // newer
1124 
1125 	rearrange_sprite_data(memregion("sprites")->base(), (uint32_t*)memregion("gfx1")->base(), (uint32_t*)memregion("gfx1_lower")->base()  );
1126 	rearrange_tile_data(memregion("bg1")->base(), (uint32_t*)memregion("gfx2")->base(), (uint32_t*)memregion("gfx2_lower")->base());
1127 	rearrange_tile_data(memregion("bg2")->base(), (uint32_t*)memregion("gfx3")->base(), (uint32_t*)memregion("gfx3_lower")->base());
1128 	rearrange_tile_data(memregion("bg3")->base(), (uint32_t*)memregion("gfx4")->base(), (uint32_t*)memregion("gfx4_lower")->base());
1129 
1130 	m_xoffset = 0;
1131 }
1132 
1133 
1134 GAME( 2002, gstream, 0,     gstream, gstream, gstream_state, init_gstream, ROT270, "Oriental Soft Japan",    "G-Stream G2020",            MACHINE_SUPPORTS_SAVE )
1135 GAME( 2000, x2222,   0,     x2222,   x2222,   gstream_state, init_x2222,   ROT270, "Oriental Soft / Promat", "X2222 (final debug?)",      MACHINE_SUPPORTS_SAVE | MACHINE_NO_SOUND )
1136 GAME( 2000, x2222o,  x2222, x2222,   x2222,   gstream_state, init_x2222,   ROT270, "Oriental Soft / Promat", "X2222 (5-level prototype)", MACHINE_SUPPORTS_SAVE | MACHINE_IMPERFECT_GRAPHICS | MACHINE_NO_SOUND )
1137