1 // license:BSD-3-Clause
2 // copyright-holders:Luca Elia
3 
4 #include "machine/gen_latch.h"
5 #include "machine/timer.h"
6 #include "emupal.h"
7 #include "screen.h"
8 
9 class suna16_state : public driver_device
10 {
11 public:
suna16_state(const machine_config & mconfig,device_type type,const char * tag)12 	suna16_state(const machine_config &mconfig, device_type type, const char *tag)
13 		: driver_device(mconfig, type, tag)
14 		, m_maincpu(*this,"maincpu")
15 		, m_pcm1(*this,"pcm1")
16 		, m_pcm2(*this,"pcm2")
17 		, m_gfxdecode(*this, "gfxdecode")
18 		, m_screen(*this, "screen")
19 		, m_palette(*this, "palette")
20 		, m_soundlatch(*this, "soundlatch")
21 		, m_spriteram(*this, "spriteram")
22 		, m_spriteram2(*this, "spriteram2")
23 		, m_bank1(*this, "bank1")
24 		, m_bank2(*this, "bank2")
25 		, m_leds(*this, "led%u", 0U)
26 	{ }
27 
28 	void uballoon(machine_config &config);
29 	void sunaq(machine_config &config);
30 	void bssoccer(machine_config &config);
31 	void bestbest(machine_config &config);
32 
33 	void init_uballoon();
34 
35 private:
36 	// common
37 	void soundlatch_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
38 	uint16_t paletteram_r(offs_t offset);
39 	void paletteram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
40 	void flipscreen_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
41 
42 	// bestbest specific
43 	void bestbest_flipscreen_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
44 	void bestbest_coin_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
45 	uint8_t bestbest_prot_r();
46 	void bestbest_prot_w(uint8_t data);
47 	void bestbest_ay8910_port_a_w(uint8_t data);
48 
49 	// bssoccer specific
50 	void bssoccer_leds_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
51 	void bssoccer_pcm_1_bankswitch_w(uint8_t data);
52 	void bssoccer_pcm_2_bankswitch_w(uint8_t data);
53 
54 	// uballoon specific
55 	void uballoon_leds_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
56 	void uballoon_pcm_1_bankswitch_w(uint8_t data);
57 	uint8_t uballoon_prot_r(offs_t offset);
58 	void uballoon_prot_w(offs_t offset, uint8_t data);
59 
60 	TIMER_DEVICE_CALLBACK_MEMBER(bssoccer_interrupt);
61 
62 	virtual void video_start() override;
63 	DECLARE_MACHINE_START(bestbest);
64 	DECLARE_MACHINE_START(bssoccer);
65 	DECLARE_MACHINE_START(uballoon);
66 	DECLARE_MACHINE_RESET(uballoon);
67 
68 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
69 	uint32_t screen_update_bestbest(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
70 	void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, uint16_t *sprites, int gfx);
71 
72 	void bestbest_map(address_map &map);
73 	void bestbest_pcm_1_iomap(address_map &map);
74 	void bestbest_pcm_1_map(address_map &map);
75 	void bestbest_sound_map(address_map &map);
76 	void bssoccer_map(address_map &map);
77 	void bssoccer_pcm_1_io_map(address_map &map);
78 	void bssoccer_pcm_1_map(address_map &map);
79 	void bssoccer_pcm_2_io_map(address_map &map);
80 	void bssoccer_pcm_2_map(address_map &map);
81 	void bssoccer_sound_map(address_map &map);
82 	void sunaq_map(address_map &map);
83 	void sunaq_sound_map(address_map &map);
84 	void uballoon_map(address_map &map);
85 	void uballoon_pcm_1_io_map(address_map &map);
86 	void uballoon_pcm_1_map(address_map &map);
87 	void uballoon_sound_map(address_map &map);
88 
89 	required_device<cpu_device> m_maincpu;
90 	optional_device<cpu_device> m_pcm1;
91 	optional_device<cpu_device> m_pcm2;
92 	required_device<gfxdecode_device> m_gfxdecode;
93 	required_device<screen_device> m_screen;
94 	required_device<palette_device> m_palette;
95 	required_device<generic_latch_8_device> m_soundlatch;
96 
97 	required_shared_ptr<uint16_t> m_spriteram;
98 	optional_shared_ptr<uint16_t> m_spriteram2;
99 
100 	optional_memory_bank m_bank1;
101 	optional_memory_bank m_bank2;
102 
103 	output_finder<4> m_leds;
104 
105 	std::unique_ptr<uint16_t[]> m_paletteram;
106 	int m_color_bank;
107 	uint8_t m_prot;
108 };
109