1 // license:BSD-3-Clause
2 // copyright-holders:Luca Elia
3 /*************************************************************************
4 
5                       -= IGS Lord Of Gun =-
6 
7 *************************************************************************/
8 #include "sound/okim6295.h"
9 #include "machine/eepromser.h"
10 #include "machine/gen_latch.h"
11 #include "emupal.h"
12 #include "screen.h"
13 #include "tilemap.h"
14 
15 struct lordgun_gun_data
16 {
17 	int     scr_x,  scr_y;
18 	uint16_t  hw_x,   hw_y;
19 };
20 
21 class lordgun_state : public driver_device
22 {
23 public:
lordgun_state(const machine_config & mconfig,device_type type,const char * tag)24 	lordgun_state(const machine_config &mconfig, device_type type, const char *tag) :
25 		driver_device(mconfig, type, tag),
26 		m_maincpu(*this, "maincpu"),
27 		m_soundcpu(*this, "soundcpu"),
28 		m_oki(*this, "oki"),
29 		m_eeprom(*this, "eeprom"),
30 		m_gfxdecode(*this, "gfxdecode"),
31 		m_screen(*this, "screen"),
32 		m_palette(*this, "palette"),
33 		m_soundlatch(*this, "soundlatch"),
34 		m_soundlatch2(*this, "soundlatch2"),
35 		m_priority_ram(*this, "priority_ram"),
36 		m_scrollram(*this, "scrollram"),
37 		m_spriteram(*this, "spriteram"),
38 		m_vram(*this, "vram.%u", 0),
39 		m_scroll_x(*this, "scroll_x.%u", 0),
40 		m_scroll_y(*this, "scroll_y.%u", 0) { }
41 
42 	void aliencha(machine_config &config);
43 	void lordgun(machine_config &config);
44 
45 	void init_aliencha();
46 	void init_lordgun();
47 
48 private:
49 	required_device<cpu_device> m_maincpu;
50 	required_device<cpu_device> m_soundcpu;
51 	required_device<okim6295_device> m_oki;
52 	required_device<eeprom_serial_93cxx_device> m_eeprom;
53 	required_device<gfxdecode_device> m_gfxdecode;
54 	required_device<screen_device> m_screen;
55 	required_device<palette_device> m_palette;
56 	required_device<generic_latch_8_device> m_soundlatch;
57 	required_device<generic_latch_8_device> m_soundlatch2;
58 
59 	required_shared_ptr<uint16_t> m_priority_ram;
60 	required_shared_ptr<uint16_t> m_scrollram;
61 	required_shared_ptr<uint16_t> m_spriteram;
62 	required_shared_ptr_array<uint16_t, 4> m_vram;
63 	required_shared_ptr_array<uint16_t, 4> m_scroll_x;
64 	required_shared_ptr_array<uint16_t, 4> m_scroll_y;
65 
66 	uint8_t m_old;
67 	uint8_t m_aliencha_dip_sel;
68 	uint16_t m_priority;
69 	int m_whitescreen;
70 	lordgun_gun_data m_gun[2];
71 	tilemap_t *m_tilemap[4];
72 	std::unique_ptr<bitmap_ind16> m_bitmaps[5];
73 
74 	uint16_t m_protection_data;
75 	void lordgun_protection_w(offs_t offset, uint16_t data);
76 	uint16_t lordgun_protection_r(offs_t offset);
77 	void aliencha_protection_w(offs_t offset, uint16_t data);
78 	uint16_t aliencha_protection_r(offs_t offset);
79 
80 	void priority_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
81 	uint16_t lordgun_gun_0_x_r();
82 	uint16_t lordgun_gun_0_y_r();
83 	uint16_t lordgun_gun_1_x_r();
84 	uint16_t lordgun_gun_1_y_r();
85 	void soundlatch_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
86 	template<int Layer> void vram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
87 	void fake_w(uint8_t data);
88 	void fake2_w(uint8_t data);
89 	void lordgun_eeprom_w(uint8_t data);
90 	void aliencha_eeprom_w(uint8_t data);
91 	uint8_t aliencha_dip_r();
92 	void aliencha_dip_w(uint8_t data);
93 	void lordgun_okibank_w(uint8_t data);
94 
95 	template<int Layer> TILE_GET_INFO_MEMBER(get_tile_info);
96 
97 	virtual void machine_start() override;
98 	virtual void video_start() override;
99 
100 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
101 	void lorddgun_calc_gun_scr(int i);
102 	void lordgun_update_gun(int i);
103 	void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
104 	void aliencha_map(address_map &map);
105 	void aliencha_soundio_map(address_map &map);
106 	void common_map(address_map &map);
107 	void lordgun_map(address_map &map);
108 	void lordgun_soundio_map(address_map &map);
109 	void soundmem_map(address_map &map);
110 	void ymf278_map(address_map &map);
111 };
112 
113 /*----------- defined in video/lordgun.c -----------*/
114 float lordgun_crosshair_mapper(const ioport_field *field, float linear_value);
115