1 // license:BSD-3-Clause
2 // copyright-holders:Bryan McPhail
3 #ifndef MAME_INCLUDES_BBUSTERS_H
4 #define MAME_INCLUDES_BBUSTERS_H
5 
6 #pragma once
7 
8 #include "machine/gen_latch.h"
9 #include "video/bufsprite.h"
10 #include "screen.h"
11 #include "tilemap.h"
12 
13 class bbusters_state_base : public driver_device
14 {
15 protected:
bbusters_state_base(const machine_config & mconfig,device_type type,const char * tag)16 	bbusters_state_base(const machine_config &mconfig, device_type type, const char *tag) :
17 		driver_device(mconfig, type, tag),
18 		m_maincpu(*this, "maincpu"),
19 		m_audiocpu(*this, "audiocpu"),
20 		m_gfxdecode(*this, "gfxdecode"),
21 		m_spriteram(*this, "spriteram%u", 1U),
22 		m_soundlatch(*this, "soundlatch%u", 1U),
23 		m_videoram(*this, "videoram"),
24 		m_pf_data(*this, "pf%u_data", 1U),
25 		m_pf_scroll_data(*this, "pf%u_scroll_data", 1U),
26 		m_scale_table(*this, "scale_table"),
27 		m_gun_io(*this, { "GUNX1", "GUNY1", "GUNX2", "GUNY2", "GUNX3", "GUNY3" }),
28 		m_gun_recoil(*this, "Player%u_Gun_Recoil", 1U)
29 	{ }
30 
31 	required_device<cpu_device> m_maincpu;
32 	required_device<cpu_device> m_audiocpu;
33 	required_device<gfxdecode_device> m_gfxdecode;
34 	optional_device_array<buffered_spriteram16_device, 2> m_spriteram;
35 	required_device_array<generic_latch_8_device, 2> m_soundlatch;
36 
37 	required_shared_ptr<uint16_t> m_videoram;
38 	required_shared_ptr_array<uint16_t, 2> m_pf_data;
39 	required_shared_ptr_array<uint16_t, 2> m_pf_scroll_data;
40 
41 	required_region_ptr<uint8_t> m_scale_table;
42 
43 	optional_ioport_array<6> m_gun_io;
44 	output_finder<3> m_gun_recoil;
45 
46 	tilemap_t *m_fix_tilemap;
47 	tilemap_t *m_pf_tilemap[2];
48 	const uint8_t *m_scale_table_ptr;
49 	uint8_t m_scale_line_count;
50 
51 	virtual void machine_start() override;
52 	virtual void video_start() override;
53 
54 	TILE_GET_INFO_MEMBER(get_tile_info);
55 	template<int Layer, int Gfx> TILE_GET_INFO_MEMBER(get_pf_tile_info);
56 
57 	void sound_cpu_w(uint8_t data);
58 	void video_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
59 	template<int Layer> void pf_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
60 	void coin_counter_w(uint8_t data);
61 
62 	const uint8_t *get_source_ptr(gfx_element *gfx, uint32_t sprite, int dx, int dy, int block);
63 	void draw_block(screen_device &screen, bitmap_ind16 &dest,int x,int y,int size,int flipx,int flipy,uint32_t sprite,int color,int bank,int block,int priority);
64 	void draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const uint16_t *source, int bank);
65 
66 	void sound_map(address_map &map);
67 };
68 
69 class bbusters_state : public bbusters_state_base
70 {
71 public:
bbusters_state(const machine_config & mconfig,device_type type,const char * tag)72 	bbusters_state(const machine_config &mconfig, device_type type, const char *tag) :
73 		bbusters_state_base(mconfig, type, tag),
74 		m_eprom_data(*this, "eeprom")
75 	{ }
76 
77 	void bbusters(machine_config &config);
78 
79 protected:
80 	virtual void machine_start() override;
81 	virtual void video_start() override;
82 
83 private:
84 	required_shared_ptr<uint16_t> m_eprom_data;
85 
86 	uint16_t eprom_r(offs_t offset);
87 	void three_gun_output_w(uint16_t data);
88 
89 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
90 	void bbusters_map(address_map &map);
91 	void sound_portmap(address_map &map);
92 };
93 
94 class mechatt_state : public bbusters_state_base
95 {
96 public:
mechatt_state(const machine_config & mconfig,device_type type,const char * tag)97 	mechatt_state(const machine_config &mconfig, device_type type, const char *tag) :
98 		bbusters_state_base(mconfig, type, tag)
99 	{ }
100 
101 	void mechatt(machine_config &config);
102 
103 protected:
104 	virtual void video_start() override;
105 
106 private:
107 	void two_gun_output_w(uint16_t data);
108 	uint16_t mechatt_gun_r(offs_t offset);
109 
110 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
111 	void mechatt_map(address_map &map);
112 	void sounda_portmap(address_map &map);
113 };
114 
115 #endif // MAME_INCLUDES_BBUSTERS_H
116