1 // license:BSD-3-Clause
2 // copyright-holders:R. Belmont
3 /**************************************************************************
4     Pirate Ship
5 
6  PWB(A)354460B
7 
8  MC68HC00FN16
9 
10  054539  - 8-Channel ADPCM sound generator. Clock input 18.432MHz. Clock outputs 18.432/4 & 18.432/8
11  053250  - LVC road generator
12  053246A - Sprite generator
13  055673  - Sprite generator
14  055555  - Mixer/Priority encoder
15  056832  - Tilemap generator
16  054156  - Tilemap generator
17  053252  - CRTC
18 
19 
20  053250 config:
21 
22  SELC (69)  GND
23  SEL1 (83)  GND
24  SEL0 (82)  GND
25  MODE (68)  GND
26 
27  TODO: Music stops if a coin is inserted. MAME or BTNAB?
28 
29 **************************************************************************/
30 
31 #include "emu.h"
32 
33 #include "includes/konamigx.h" // TODO: WHY?
34 
35 #include "cpu/m68000/m68000.h"
36 #include "machine/gen_latch.h"
37 #include "machine/k053252.h"
38 #include "machine/nvram.h"
39 #include "machine/ticket.h"
40 #include "machine/timer.h"
41 #include "sound/k054539.h"
42 #include "video/k053246_k053247_k055673.h"
43 #include "video/k053250_ps.h"
44 #include "video/k054000.h"
45 #include "video/k055555.h"
46 #include "video/konami_helper.h"
47 
48 #include "speaker.h"
49 
50 
51 class piratesh_state : public driver_device
52 {
53 public:
piratesh_state(const machine_config & mconfig,device_type type,const char * tag)54 	piratesh_state(const machine_config &mconfig, device_type type, const char *tag) :
55 		driver_device(mconfig, type, tag),
56 		m_maincpu(*this,"maincpu"),
57 		m_k053250(*this, "k053250"),
58 		m_k053252(*this, "k053252"),
59 		m_k056832(*this, "k056832"),
60 		m_k055673(*this, "k055673"),
61 		m_k055555(*this, "k055555"),
62 		//m_k053246(*this, "k053246"),
63 		m_k054539(*this, "k054539"),
64 		m_tickets(*this, "ticket"),
65 		m_hopper(*this, "hopper"),
66 		m_spriteram(*this,"spriteram")
67 	{ }
68 
69 	void piratesh(machine_config &config);
70 
71 	DECLARE_CUSTOM_INPUT_MEMBER(helm_r);
72 	DECLARE_CUSTOM_INPUT_MEMBER(battery_r);
73 
74 protected:
75 	virtual void machine_start() override;
76 	virtual void machine_reset() override;
77 	virtual void video_start() override;
78 
79 private:
80 	required_device<cpu_device> m_maincpu;
81 
82 	required_device<k053250ps_device> m_k053250;
83 	required_device<k053252_device> m_k053252;
84 	required_device<k056832_device> m_k056832;
85 	required_device<k055673_device> m_k055673;
86 	required_device<k055555_device> m_k055555;
87 	required_device<k054539_device> m_k054539;
88 //  required_device<k053247_device> m_k053246;
89 
90 	required_device<ticket_dispenser_device> m_tickets;
91 	required_device<ticket_dispenser_device> m_hopper;
92 
93 	optional_shared_ptr<uint16_t> m_spriteram;
94 
95 	int m_layer_colorbase[6];
96 	int m_sprite_colorbase;
97 	int m_lvc_colorbase;
98 
99 	uint8_t m_int_enable;
100 	uint8_t m_int_status;
101 	uint8_t m_sound_ctrl;
102 	uint8_t m_sound_nmi_clk;
103 	uint16_t m_control;
104 
105 	void update_interrupts();
106 
107 	uint16_t K056832_rom_r(offs_t offset);
108 	void control1_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
109 	void control2_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
110 	void control3_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
111 
112 	uint32_t screen_update_piratesh(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
113 	DECLARE_WRITE_LINE_MEMBER(k054539_nmi_gen);
114 	TIMER_DEVICE_CALLBACK_MEMBER(piratesh_interrupt);
115 	K056832_CB_MEMBER(piratesh_tile_callback);
116 	K055673_CB_MEMBER(piratesh_sprite_callback);
117 	void piratesh_map(address_map &map);
118 };
119 
120 
update_interrupts()121 void piratesh_state::update_interrupts()
122 {
123 	m_maincpu->set_input_line(M68K_IRQ_2, m_int_status & 2 ? ASSERT_LINE : CLEAR_LINE); // INT 1
124 	m_maincpu->set_input_line(M68K_IRQ_4, m_int_status & 1 ? ASSERT_LINE : CLEAR_LINE);
125 	m_maincpu->set_input_line(M68K_IRQ_5, m_int_status & 4 ? ASSERT_LINE : CLEAR_LINE);
126 }
127 
128 /*
129  Priority issues:
130 
131  1. On title screen, stars should be behind the helm
132  2. The Konami logo is a square transition
133  3.
134 
135 */
136 
K056832_CB_MEMBER(piratesh_state::piratesh_tile_callback)137 K056832_CB_MEMBER(piratesh_state::piratesh_tile_callback)
138 {
139 	// Layer
140 	// Code
141 	// Color
142 	// Flags
143 //  if (*color != 0)
144 //      logerror("%x %x %x\n", layer, *code, *color >> 2);
145 
146 	*color = (m_layer_colorbase[layer] << 4) + ((*color >> 2));// & 0x0f);
147 }
148 
K055673_CB_MEMBER(piratesh_state::piratesh_sprite_callback)149 K055673_CB_MEMBER(piratesh_state::piratesh_sprite_callback)
150 {
151 	int c = *color;
152 
153 	*color = (c & 0x001f);
154 	//int pri = (c >> 5) & 7;
155 	// .... .... ...x xxxx - Color
156 	// .... .... xxx. .... - Priority?
157 	// .... ..x. .... .... - ?
158 	// ..x. .... .... .... - ?
159 
160 #if 0
161 	int layerpri[4];
162 	static const int pris[4] = { K55_PRIINP_0, K55_PRIINP_3, K55_PRIINP_6, K55_PRIINP_7 };
163 
164 	for (uint32_t i = 0; i < 4; i++)
165 	{
166 		layerpri[i] = m_k055555->K055555_read_register(pris[i]);
167 	}
168 
169 	// TODO: THIS IS ALL WRONG
170 	if (pri <= layerpri[0])
171 		*priority_mask = 0;
172 	else if (pri <= layerpri[1])
173 		*priority_mask = 0xf0;
174 	else if (pri <= layerpri[2])
175 		*priority_mask = 0xf0|0xcc;
176 	else
177 		*priority_mask = 0xf0|0xcc|0xaa;
178 #endif
179 
180 	*priority_mask = 0;
181 
182 	// 0 - Sprites over everything
183 	// f0 -
184 	// f0 cc -
185 	// f0 cc aa -
186 
187 	// 1111 0000
188 	// 1100 1100
189 	// 1010 1010
190 }
191 
192 
193 
video_start()194 void piratesh_state::video_start()
195 {
196 	// TODO: These come from the 055555
197 	m_layer_colorbase[0] = 0;
198 	m_layer_colorbase[1] = 2;
199 	m_layer_colorbase[2] = 4;
200 	m_layer_colorbase[3] = 6;
201 	m_sprite_colorbase = 1;
202 	m_lvc_colorbase = 3;
203 #if 0
204 	konamigx_mixer_init(*m_screen, 0);
205 
206 	m_k056832->set_layer_offs(0, -2+2-1, 0-1);
207 	m_k056832->set_layer_offs(1,  0+2, 0);
208 	m_k056832->set_layer_offs(2,  2+2, 0);
209 	m_k056832->set_layer_offs(3,  3+2, 0);
210 #endif
211 }
212 
213 
screen_update_piratesh(screen_device & screen,bitmap_rgb32 & bitmap,const rectangle & cliprect)214 uint32_t piratesh_state::screen_update_piratesh(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
215 {
216 	bitmap.fill(0, cliprect);
217 #if 1
218 
219 	int layers[4], layerpri[4];
220 	static const int pris[4] = { K55_PRIINP_0, K55_PRIINP_3, K55_PRIINP_6, K55_PRIINP_7 };
221 	static const int enables[4] = { K55_INP_VRAM_A, K55_INP_VRAM_B, K55_INP_VRAM_C, K55_INP_VRAM_D };
222 
223 	for (uint32_t i = 0; i < 4; i++)
224 	{
225 		layers[i] = i;
226 		layerpri[i] = m_k055555->K055555_read_register(pris[i]);
227 	}
228 
229 	konami_sortlayers4(layers, layerpri);
230 
231 	screen.priority().fill(0, cliprect);
232 
233 	const uint32_t input_enables = m_k055555->K055555_read_register(K55_INPUT_ENABLES);
234 
235 	// TODO: FIX COLORBASES
236 	if (input_enables & K55_INP_SUB3)
237 		m_k053250->draw(bitmap, cliprect, 0x20, 0, screen.priority(), 2);
238 	for (uint32_t i = 0; i < 4; i++)
239 	{
240 		if (input_enables & enables[layers[i]])
241 		{
242 			m_k056832->tilemap_draw(screen, bitmap, cliprect, layers[i], 0, 1 << i);
243 		}
244 	}
245 
246 	if (input_enables & K55_INP_SUB2)
247 		m_k055673->k053247_sprites_draw(bitmap, cliprect);
248 
249 #if 0
250 #define K55_INP_VRAM_A      0x01
251 #define K55_INP_VRAM_B      0x02
252 #define K55_INP_VRAM_C      0x04
253 #define K55_INP_VRAM_D      0x08
254 #define K55_INP_OBJ         0x10
255 #define K55_INP_SUB1        0x20
256 #define K55_INP_SUB2        0x40
257 #define K55_INP_SUB3        0x80
258 #endif
259 
260 	//055555: 4 to reg 7 (A PRI 0)
261 	//055555: 0 to reg 8 (A PRI 1)
262 	//055555: 0 to reg 9 (A COLPRI)
263 	//055555: 6 to reg a (B PRI 0)
264 	//055555: 0 to reg b (B PRI 1)
265 	//055555: 0 to reg c (B COLPRI)
266 	//055555: 16 to reg d (C PRI)
267 	//055555: 18 to reg e (D PRI)
268 	//055555: 0 to reg 11 (SUB2 PRI)
269 	//055555: 0 to reg 12 (SUB3 PRI)
270 
271 	//055555: 0 to reg 17 (A PAL)
272 	//055555: 2 to reg 18 (B PAL)
273 	//055555: 4 to reg 19 (C PAL)
274 	//055555: 6 to reg 1a (D PAL)
275 	//055555: 3 to reg 1d (SUB2 PAL)
276 	//055555: 1 to reg 1e (SUB3 PAL)
277 
278 
279 #else
280 	// LAYER, FLAGS, PRIORITY
281 	m_k056832->tilemap_draw(screen, bitmap, cliprect, 3, K056832_DRAW_FLAG_MIRROR, 1);
282 
283 	m_k056832->tilemap_draw(screen, bitmap, cliprect, 2, K056832_DRAW_FLAG_MIRROR, 2);
284 
285 	// TODO: Fix priority
286 	m_k053250->draw(bitmap, cliprect, 0x20, 0, screen.priority(), 8);
287 
288 	m_k055673->k053247_sprites_draw(bitmap, cliprect);
289 
290 	m_k056832->tilemap_draw(screen, bitmap, cliprect, 1, K056832_DRAW_FLAG_MIRROR, 4);
291 	m_k056832->tilemap_draw(screen, bitmap, cliprect, 0, K056832_DRAW_FLAG_MIRROR, 0);
292 #endif
293 	return 0;
294 }
295 
296 
297 
298 
299 /**********************************************************************************/
300 /* IRQ controllers */
301 
TIMER_DEVICE_CALLBACK_MEMBER(piratesh_state::piratesh_interrupt)302 TIMER_DEVICE_CALLBACK_MEMBER(piratesh_state::piratesh_interrupt)
303 {
304 	int scanline = param;
305 
306 	// IRQ2 - CCUINT1 (VBL START)
307 	// IRQ4 - Sound
308 	// IRQ5 - CCUINT2 (VBL END)
309 
310 	if (scanline == 240)
311 	{
312 		m_k053250->vblank_w(1);
313 
314 		if (m_int_enable & 2)
315 		{
316 			m_int_status |= 2;
317 			update_interrupts();
318 		}
319 	}
320 
321 	if (scanline == 0)
322 	{
323 		m_k053250->vblank_w(0);
324 
325 		if (m_int_enable & 4)
326 		{
327 			m_int_status |= 4;
328 			update_interrupts();
329 		}
330 	}
331 }
332 
333 
334 
K056832_rom_r(offs_t offset)335 uint16_t piratesh_state::K056832_rom_r(offs_t offset)
336 {
337 	uint16_t offs;
338 
339 	offs = (m_control & 2 ? 0x1000 : 0) + offset;
340 	return m_k056832->piratesh_rom_r(offs);
341 }
342 
343 
344 
control1_w(offs_t offset,uint16_t data,uint16_t mem_mask)345 void piratesh_state::control1_w(offs_t offset, uint16_t data, uint16_t mem_mask)
346 {
347 	// .... ..xx .... ....      - Unknown
348 	// .... .x.. .... ....      - Unknown - Active during attract, clear during game
349 	// .... x... .... ....      - Lamp? (active when waiting to start game)
350 
351 	if (data & ~0x0f00)
352 		logerror("CTRL3: %x %x %x\n", offset, data, mem_mask);
353 }
354 
control2_w(offs_t offset,uint16_t data,uint16_t mem_mask)355 void piratesh_state::control2_w(offs_t offset, uint16_t data, uint16_t mem_mask)
356 {
357 	// .... .... ...x ....      - Unknown (always 1?)
358 	// .... .... ..x. ....      - Unknown
359 	// .... .... .x.. ....      - Counter out
360 	// .... .... x... ....      - Counter in
361 	// .... ...x .... ....      - 053246A OBJCRBK (Pin 9)
362 	// .... ..x. .... ....      - LV related
363 	// .... x... .... ....      - INT4/SND control (0=clear 1=enable)
364 	// ...x .... .... ....      - INT2/CCUINT1 control (0=clear 1=enable)
365 	// ..x. .... .... ....      - INT5/CCUINT2 control (0=clear 1=enable)
366 	// .x.. .... .... ....      - Unknown
367 	// x... .... .... ....      - Unknown
368 
369 	m_int_enable = (data >> 11) & 7;
370 	m_int_status &= m_int_enable;
371 	update_interrupts();
372 
373 	if (data & ~0xfbf0)
374 		logerror("CTRL2: %x %x %x\n", offset, data, mem_mask);
375 }
376 
control3_w(offs_t offset,uint16_t data,uint16_t mem_mask)377 void piratesh_state::control3_w(offs_t offset, uint16_t data, uint16_t mem_mask)
378 {
379 	// .... .... .... ...x      - Watchdog? (051550?)
380 	// .... .... .... ..x.      - 056832 ROM bank control
381 	// .... .... ...x ....      - Ticket dispenser enable (active high)
382 	// .... .... ..x. ....      - Hopper enable (active high)
383 	// .... ...x .... ....      - Unknown (always 1?)
384 
385 	if ((data & ~0x0133) || (~data & 0x100))
386 		logerror("CTRL1 W: %x %x %x\n", offset, data, mem_mask);
387 
388 //  logerror("CTRL 1: %x\n", data & 0x0010);
389 	m_tickets->motor_w(data & 0x0010 ? 1 : 0);
390 	m_hopper->motor_w(data & 0x0020 ? 1 : 0);
391 
392 	m_control = data;
393 }
394 
395 
piratesh_map(address_map & map)396 void piratesh_state::piratesh_map(address_map &map)
397 {
398 	map(0x000000, 0x07ffff).rom();
399 	map(0x080000, 0x083fff).ram().share("nvram");
400 	map(0x084000, 0x087fff).ram();
401 	map(0x100000, 0x10001f).rw(m_k053252, FUNC(k053252_device::read), FUNC(k053252_device::write)).umask16(0x00ff); // CRTC
402 	map(0x180000, 0x18003f).w(m_k056832, FUNC(k056832_device::word_w)); // TILEMAP
403 	map(0x280000, 0x280007).w(m_k055673, FUNC(k055673_device::k053246_w)); // SPRITES
404 	map(0x290000, 0x29000f).r(m_k055673, FUNC(k055673_device::k055673_ps_rom_word_r)); // SPRITES
405 	map(0x290010, 0x29001f).w(m_k055673, FUNC(k055673_device::k055673_reg_word_w)); // SPRITES
406 	map(0x2a0000, 0x2a0fff).rw(m_k055673, FUNC(k055673_device::k053247_word_r), FUNC(k055673_device::k053247_word_w)); // SPRITES
407 	map(0x2a1000, 0x2a3fff).nopw();
408 	map(0x2b0000, 0x2b000f).rw(m_k053250, FUNC(k053250ps_device::reg_r), FUNC(k053250ps_device::reg_w)); // LVC
409 	map(0x300000, 0x3000ff).w(m_k055555, FUNC(k055555_device::K055555_word_w));
410 	map(0x380000, 0x381fff).ram().w("palette", FUNC(palette_device::write16)).share("palette");
411 	map(0x400000, 0x400001).portr("IN0");
412 	map(0x400002, 0x400003).portr("IN1");
413 	map(0x400004, 0x400005).portr("DSW1");
414 	map(0x400006, 0x400007).portr("DSW2");
415 	map(0x400008, 0x400009).portr("SPECIAL");
416 	map(0x40000c, 0x40000d).w(FUNC(piratesh_state::control1_w));
417 	map(0x400010, 0x400011).w(FUNC(piratesh_state::control2_w));
418 	map(0x400014, 0x400015).w(FUNC(piratesh_state::control3_w));
419 	map(0x500000, 0x50ffff).r(FUNC(piratesh_state::K056832_rom_r)); // VRAM ROM
420 	map(0x580000, 0x581fff).r(m_k053250, FUNC(k053250ps_device::rom_r)); // LVC ROM access
421 	map(0x600000, 0x6004ff).rw("k054539", FUNC(k054539_device::read), FUNC(k054539_device::write)).umask16(0xff00); // SOUND
422 	map(0x680000, 0x681fff).rw(m_k056832, FUNC(k056832_device::ram_word_r), FUNC(k056832_device::ram_word_w)); // TILEMAP
423 	map(0x700000, 0x703fff).rw(m_k053250, FUNC(k053250ps_device::ram_r), FUNC(k053250ps_device::ram_w)); // LVC
424 }
425 
426 
WRITE_LINE_MEMBER(piratesh_state::k054539_nmi_gen)427 WRITE_LINE_MEMBER(piratesh_state::k054539_nmi_gen)
428 {
429 	static int m_sound_intck = 0; // TODO: KILL ME
430 
431 	// Trigger an interrupt on the rising edge
432 	if (!m_sound_intck && state)
433 	{
434 		if (m_int_enable & 1)
435 		{
436 			m_int_status |= 1;
437 			update_interrupts();
438 		}
439 	}
440 
441 	m_sound_intck = state;
442 }
443 
CUSTOM_INPUT_MEMBER(piratesh_state::helm_r)444 CUSTOM_INPUT_MEMBER(piratesh_state::helm_r)
445 {
446 	// Appears to be a quadrature encoder
447 	uint8_t xa, xb;
448 	uint16_t dx = ioport("HELM")->read();
449 
450 	xa = ((dx + 1) & 7) <= 3;
451 	xb = (dx & 7) <= 3;
452 
453 	return (xb << 1) | xa;
454 }
455 
CUSTOM_INPUT_MEMBER(piratesh_state::battery_r)456 CUSTOM_INPUT_MEMBER(piratesh_state::battery_r)
457 {
458 	// .x MB3790 /ALARM1
459 	// x. MB3790 /ALARM2
460 
461 	return 0x3;
462 }
463 
464 /**********************************************************************************/
465 
466 static INPUT_PORTS_START( piratesh )
467 	PORT_START("IN0")
468 	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNKNOWN )
469 	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNKNOWN )
470 	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNKNOWN )
471 	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNKNOWN )
472 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN )
473 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN )
474 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN )
475 	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON3 ) // 7f60  btst $7,$40000
476 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNKNOWN )
477 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_UNKNOWN )
478 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) // HELM?
479 	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )   // HELM?
480 	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_SERVICE2 ) PORT_NAME("Reset")
481 	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_START )
482 	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_COIN1 )
PORT_NAME(DEF_STR (Test))483 	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME(DEF_STR( Test )) PORT_CODE(KEYCODE_F2)
484 
485 	PORT_START("SPECIAL")
486 	PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("k053250", k053250ps_device, dmairq_r)
487 	PORT_BIT( 0x0200, IP_ACTIVE_HIGH, IPT_UNKNOWN ) // FIXME: NCPU from 053246 (DMA)
488 	PORT_BIT( 0x0c00, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_CUSTOM_MEMBER(piratesh_state, battery_r)
489 
490 	PORT_START("HELM")
491 	PORT_BIT( 0xff, 0x00, IPT_DIAL ) PORT_SENSITIVITY(25) PORT_KEYDELTA(1)
492 
493 	PORT_START("IN1")
494 	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNKNOWN )
495 	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNKNOWN )
496 	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNKNOWN )
497 	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNKNOWN )
498 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_NAME("Service")
499 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN )
500 	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN )
501 	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN )
502 	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNKNOWN )
503 	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("ticket", ticket_dispenser_device, line_r)
504 	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("hopper", ticket_dispenser_device, line_r)
505 	PORT_BIT( 0x1800, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_CUSTOM_MEMBER(piratesh_state, helm_r)
506 	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN )
507 	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN )
508 	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
509 
510 	PORT_START("DSW1") // TODO: DIP switches are used for settings when battery failure has occurred
511 	PORT_DIPNAME( 0x0100, 0x0100, "DSW1:0" ) PORT_DIPLOCATION("DSW1:1")
512 	PORT_DIPSETTING(    0x0100, DEF_STR( Off ) )
513 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
514 	PORT_DIPNAME( 0x0200, 0x0200, "DSW1:1" ) PORT_DIPLOCATION("DSW1:2")
515 	PORT_DIPSETTING(    0x0200, DEF_STR( Off ) )
516 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
517 	PORT_DIPNAME( 0x0400, 0x0400, "DSW1:2" ) PORT_DIPLOCATION("DSW1:3")
518 	PORT_DIPSETTING(    0x0400, DEF_STR( Off ) )
519 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
520 	PORT_DIPNAME( 0x0800, 0x0800, "DSW1:3" ) PORT_DIPLOCATION("DSW1:4")
521 	PORT_DIPSETTING(    0x0800, DEF_STR( Off ) )
522 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
523 	PORT_DIPNAME( 0x3000, 0x1000, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("DSW1:5,6")
524 	PORT_DIPSETTING(    0x0000, "A" )
525 	PORT_DIPSETTING(    0x1000, "B" )
526 	PORT_DIPSETTING(    0x2000, "C" )
527 	PORT_DIPSETTING(    0x3000, "D" )
528 	PORT_DIPNAME( 0x4000, 0x4000, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("DSW1:7")
529 	PORT_DIPSETTING(    0x0000, DEF_STR( Off ) )
530 	PORT_DIPSETTING(    0x4000, DEF_STR( On ) )
531 	PORT_DIPNAME( 0x8000, 0x8000, DEF_STR( Free_Play ) ) PORT_DIPLOCATION("DSW1:8")
532 	PORT_DIPSETTING(    0x8000, DEF_STR( Off ) )
533 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
534 
535 	PORT_START("DSW2") // TODO: Finish me
536 	PORT_DIPNAME( 0x0100, 0x0100, "DSW2:0" ) PORT_DIPLOCATION("DSW2:1")
537 	PORT_DIPSETTING(    0x0100, DEF_STR( Off ) )
538 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
539 	PORT_DIPNAME( 0x0200, 0x0200, "DSW2:1" ) PORT_DIPLOCATION("DSW2:2")
540 	PORT_DIPSETTING(    0x0200, DEF_STR( Off ) )
541 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
542 	PORT_DIPNAME( 0x0400, 0x0400, "DSW2:2" ) PORT_DIPLOCATION("DSW2:3")
543 	PORT_DIPSETTING(    0x0400, DEF_STR( Off ) )
544 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
545 	PORT_DIPNAME( 0x0800, 0x0800, "DSW2:3" ) PORT_DIPLOCATION("DSW2:4")
546 	PORT_DIPSETTING(    0x0800, DEF_STR( Off ) )
547 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
548 	PORT_DIPNAME( 0x1000, 0x1000, "DSW2:4" ) PORT_DIPLOCATION("DSW2:5")
549 	PORT_DIPSETTING(    0x1000, DEF_STR( Off ) )
550 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
551 	PORT_DIPNAME( 0x2000, 0x2000, "DSW2:5" ) PORT_DIPLOCATION("DSW2:6")
552 	PORT_DIPSETTING(    0x2000, DEF_STR( Off ) )
553 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
554 	PORT_DIPNAME( 0x4000, 0x4000, "DSW2:6" ) PORT_DIPLOCATION("DSW2:7")
555 	PORT_DIPSETTING(    0x4000, DEF_STR( Off ) )
556 	PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
557 	PORT_DIPNAME( 0x8000, 0x8000, "Redemption Type" ) PORT_DIPLOCATION("DSW2:8")
558 	PORT_DIPSETTING(    0x8000, "Ticket" )
559 	PORT_DIPSETTING(    0x0000, "Capsule" )
560 INPUT_PORTS_END
561 
562 /**********************************************************************************/
563 
564 void piratesh_state::machine_start()
565 {
566 #if 0
567 	m_sound_ctrl = 2;
568 	m_mw_irq_control = 0;
569 
570 	/* konamigx_mixer uses this, so better initialize it */
571 	m_gx_wrport1_0 = 0;
572 
573 	save_item(NAME(m_mw_irq_control));
574 	save_item(NAME(m_sound_ctrl));
575 	save_item(NAME(m_sound_nmi_clk));
576 #else
577 	(void)m_sound_ctrl;
578 	(void)m_sound_nmi_clk;
579 #endif
580 }
581 
machine_reset()582 void piratesh_state::machine_reset()
583 {
584 	m_int_status = 0;
585 
586 	int i;
587 
588 	// soften chorus(chip 0 channel 0-3), boost voice(chip 0 channel 4-7)
589 	for (i=0; i<=7; i++)
590 	{
591 	//  m_k054539->set_gain(i, 0.5);
592 	}
593 
594 //  // soften percussions(chip 1 channel 0-7)
595 //  for (i=0; i<=7; i++) m_k054539_2->set_gain(i, 0.5);
596 
597 }
598 
piratesh(machine_config & config)599 void piratesh_state::piratesh(machine_config &config)
600 {
601 	/* basic machine hardware */
602 	M68000(config, m_maincpu, XTAL(32'000'000)/2);
603 	m_maincpu->set_addrmap(AS_PROGRAM, &piratesh_state::piratesh_map);
604 	TIMER(config, "scantimer").configure_scanline(FUNC(piratesh_state::piratesh_interrupt), "screen", 0, 1);
605 
606 	NVRAM(config, "nvram", nvram_device::DEFAULT_ALL_0);
607 
608 	K053252(config, m_k053252, XTAL(32'000'000)/4);
609 	m_k053252->set_offsets(40, 16); // TODO
610 
611 	TICKET_DISPENSER(config, "ticket", attotime::from_msec(200), TICKET_MOTOR_ACTIVE_HIGH, TICKET_STATUS_ACTIVE_HIGH);
612 	HOPPER(config, "hopper", attotime::from_msec(200), TICKET_MOTOR_ACTIVE_HIGH, TICKET_STATUS_ACTIVE_HIGH);
613 
614 	/* video hardware */
615 	screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
616 	screen.set_video_attributes(VIDEO_UPDATE_AFTER_VBLANK);
617 //  screen.set_refresh_hz(60);
618 	screen.set_raw(6000000, 288+16+32+48, 0, 287, 224+16+8+16, 0, 223); // TODO
619 	screen.set_vblank_time(ATTOSECONDS_IN_USEC(600));
620 	screen.set_size(64*8, 32*8);
621 	screen.set_visarea(24, 24+288-1, 16, 16+224-1);
622 	screen.set_screen_update(FUNC(piratesh_state::screen_update_piratesh));
623 
624 	PALETTE(config, "palette").set_format(palette_device::BGRx_888, 2048).enable_shadows().enable_hilights();
625 
626 	K056832(config, m_k056832, 0);
627 	m_k056832->set_tile_callback(FUNC(piratesh_state::piratesh_tile_callback));
628 	m_k056832->set_config(K056832_BPP_4PIRATESH, 1, 0);
629 	m_k056832->set_palette("palette");
630 
631 	K055555(config, m_k055555, 0);
632 
633 	K053250PS(config, m_k053250, 12000000, "palette", "screen", -16, 0);
634 
635 	K055673(config, m_k055673, 0);
636 	m_k055673->set_sprite_callback(FUNC(piratesh_state::piratesh_sprite_callback));
637 	m_k055673->set_config(K055673_LAYOUT_PS, -60, 24);
638 	m_k055673->set_palette("palette");
639 
640 	// ????
641 	//K053246(config, m_k053246, 0);
642 	//m_k053246->set_sprite_callback(FUNC(moo_state::sprite_callback));
643 	//m_k053246->set_config("k053246", NORMAL_PLANE_ORDER, -48+1, 23);
644 	//m_k053246->set_palette(m_palette);
645 
646 	K054338(config, "k054338", 0, m_k055555).set_alpha_invert(1);
647 
648 	/* sound hardware */
649 	SPEAKER(config, "lspeaker").front_left();
650 	SPEAKER(config, "rspeaker").front_right();
651 
652 	K054539(config, m_k054539, XTAL(18'432'000));
653 	m_k054539->timer_handler().set(FUNC(piratesh_state::k054539_nmi_gen));
654 	m_k054539->add_route(0, "lspeaker", 0.2);
655 	m_k054539->add_route(1, "rspeaker", 0.2);
656 }
657 
658 
659 
660 ROM_START( piratesh )
661 	ROM_REGION( 0x80000, "maincpu", 0 )
662 	ROM_LOAD16_WORD_SWAP( "360ua-c04.4p", 0x000000, 0x80000, CRC(6d69dd90) SHA1(ccbdbfea406d9cbc3f242211290ba82ccbbe3795) )
663 
664 	/* tiles */
665 	ROM_REGION( 0x80000, "k056832", ROMREGION_ERASE00 ) // 27C4096
666 	ROM_LOAD( "360ua-a01.17g", 0x000000, 0x80000, CRC(e39153f5) SHA1(5da9132a2c24a15b55c3f65c26e2ad0467411a88) )
667 
668 	/* sprites */
669 	ROM_REGION( 0x80000*8, "k055673", ROMREGION_ERASE00 ) // 27C4096
670 	ROM_LOAD16_BYTE( "360ua-a02.21l", 0x000000, 0x80000, CRC(82207997) SHA1(fe143285a12fab5227e883113d798acad7bf4c97) )
671 	ROM_LOAD16_BYTE( "360ua-a03.23l", 0x000001, 0x80000, CRC(a9e36d51) SHA1(1a8de8d8d2abfee5ac0f0822e203846f7f5f1767) )
672 
673 	/* road generator */
674 	ROM_REGION( 0x080000, "k053250", ROMREGION_ERASE00 ) // 27C040
675 	ROM_LOAD( "360ua-a05.26p", 0x000000, 0x80000, CRC(dab7f439) SHA1(2372612c0b04c77a85ccbadc100cb741b85f0481) )
676 
677 	/* sound data */
678 	ROM_REGION( 0x100000, "k054539", 0 ) // 27C040
679 	ROM_LOAD( "360ua-a06.15t", 0x000000, 0x80000, CRC(6816a493) SHA1(4fc4cfbc164d84bbf8d75ccd78c9f40f3273d852) )
680 	ROM_LOAD( "360ua-a07.17t", 0x080000, 0x80000, CRC(af7127c5) SHA1(b525f3c6b831e3354eba46016d414bedcb3ae8dc) )
681 
682 //  ROM_REGION( 0x80, "eeprom", 0 ) // default eeprom to prevent game booting upside down with error
683 //  ROM_LOAD( "piratesh.nv", 0x0000, 0x080, CRC(28df2269) SHA1(3f071c97662745a199f96964e2e79f795bd5a391) )
684 ROM_END
685 
686 //    year  name        parent    machine   input     state           init
687 GAME( 1995, piratesh,   0,        piratesh, piratesh, piratesh_state, empty_init, ROT90,  "Konami", "Pirate Ship (ver UAA)", MACHINE_IMPERFECT_GRAPHICS )
688