1 // license:BSD-3-Clause
2 // copyright-holders:Bryan McPhail, Acho A. Tang, Nicola Salmoria
3 
4 #include "machine/gen_latch.h"
5 #include "sound/upd7759.h"
6 #include "video/snk68_spr.h"
7 #include "video/alpha68k_palette.h"
8 #include "screen.h"
9 #include "tilemap.h"
10 
11 class snk68_state : public driver_device
12 {
13 public:
snk68_state(const machine_config & mconfig,device_type type,const char * tag)14 	snk68_state(const machine_config &mconfig, device_type type, const char *tag) :
15 		driver_device(mconfig, type, tag),
16 		m_maincpu(*this, "maincpu"),
17 		m_soundcpu(*this, "soundcpu"),
18 		m_upd7759(*this, "upd"),
19 		m_gfxdecode(*this, "gfxdecode"),
20 		m_screen(*this, "screen"),
21 		m_sprites(*this, "sprites"),
22 		m_palette(*this, "palette"),
23 		m_soundlatch(*this, "soundlatch"),
24 		m_fg_videoram(*this, "fg_videoram"),
25 		m_spriteram(*this, "spriteram"),
26 		m_p1_io(*this, "P1"),
27 		m_p2_io(*this, "P2"),
28 		m_system_io(*this, "SYSTEM")
29 	{
30 	}
31 
32 	void streetsm(machine_config &config);
33 	void pow(machine_config &config);
34 	void powb(machine_config &config);
35 
36 	void init_powb();
37 
38 protected:
39 	required_device<cpu_device> m_maincpu;
40 	required_device<cpu_device> m_soundcpu;
41 	optional_device<upd7759_device> m_upd7759;
42 	required_device<gfxdecode_device> m_gfxdecode;
43 	required_device<screen_device> m_screen;
44 	required_device<snk68_spr_device> m_sprites;
45 	required_device<alpha68k_palette_device> m_palette;
46 	required_device<generic_latch_8_device> m_soundlatch;
47 
48 	required_shared_ptr<uint16_t> m_fg_videoram;
49 	required_shared_ptr<uint16_t> m_spriteram;
50 
51 	optional_ioport m_p1_io;
52 	optional_ioport m_p2_io;
53 	optional_ioport m_system_io;
54 
55 	bool m_sprite_flip_axis;
56 	tilemap_t *m_fg_tilemap;
57 
58 	// common
59 	void sound_w(uint8_t data);
60 	void D7759_write_port_0_w(uint8_t data);
61 
62 	virtual void video_start() override;
63 	void common_video_start();
64 
65 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
66 
67 	void tile_callback_notpow(int &tile, int& fx, int& fy, int& region);
68 
69 	void sound_io_map(address_map &map);
70 	void sound_map(address_map &map);
71 
72 private:
73 	uint32_t m_fg_tile_offset;
74 
75 	// pow and streetsm
76 	uint16_t fg_videoram_r(offs_t offset);
77 	void fg_videoram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
78 	void flipscreen_w(uint8_t data);
79 
80 	TILE_GET_INFO_MEMBER(get_tile_info);
81 
82 	void tile_callback_pow(int &tile, int& fx, int& fy, int& region);
83 
84 	void pow_map(address_map &map);
85 	void powb_sound_io_map(address_map &map);
86 };
87 
88 class searchar_state : public snk68_state
89 {
90 public:
searchar_state(const machine_config & mconfig,device_type type,const char * tag)91 	searchar_state(const machine_config &mconfig, device_type type, const char *tag) :
92 		snk68_state(mconfig, type, tag),
93 		m_rotary_io(*this, "ROT%u", 1U)
94 	{
95 	}
96 
97 	void searchar(machine_config &config);
98 
99 protected:
100 	virtual void machine_start() override;
101 	virtual void video_start() override;
102 
103 private:
104 	optional_ioport_array<2> m_rotary_io;
105 
106 	uint8_t m_invert_controls;
107 
108 	// searchar and ikari3
109 	void fg_videoram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
110 	void flipscreen_w(uint8_t data);
111 	uint16_t rotary_1_r();
112 	uint16_t rotary_2_r();
113 	uint16_t rotary_lsb_r();
114 
115 	TILE_GET_INFO_MEMBER(get_tile_info);
116 
117 	void searchar_map(address_map &map);
118 };
119