1 // license:BSD-3-Clause
2 // copyright-holders:Luca Elia
3 #ifndef MAME_INCLUDES_FANTLAND_H
4 #define MAME_INCLUDES_FANTLAND_H
5 
6 #pragma once
7 
8 #include "machine/gen_latch.h"
9 #include "sound/msm5205.h"
10 #include "emupal.h"
11 #include "screen.h"
12 
13 class fantland_state : public driver_device
14 {
15 public:
fantland_state(const machine_config & mconfig,device_type type,const char * tag)16 	fantland_state(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_screen(*this, "screen"),
22 		m_palette(*this, "palette"),
23 		m_soundlatch(*this, "soundlatch"),
24 		m_spriteram(*this, "spriteram", 0),
25 		m_spriteram2(*this, "spriteram2", 0),
26 		m_wheel(*this, "WHEEL%u", 0U)
27 	{ }
28 
29 	void fantland(machine_config &config);
30 	void wheelrun(machine_config &config);
31 	void galaxygn(machine_config &config);
32 
33 	template <int Player> DECLARE_CUSTOM_INPUT_MEMBER(wheelrun_wheel_r);
34 
35 protected:
36 	/* misc */
37 	uint8_t    m_nmi_enable;
38 
39 	/* devices */
40 	required_device<cpu_device> m_maincpu;
41 	required_device<cpu_device> m_audiocpu;
42 	required_device<gfxdecode_device> m_gfxdecode;
43 	required_device<screen_device> m_screen;
44 	required_device<palette_device> m_palette;
45 	required_device<generic_latch_8_device> m_soundlatch;
46 
47 	/* memory pointers */
48 	required_shared_ptr<uint8_t> m_spriteram;
49 	required_shared_ptr<uint8_t> m_spriteram2;
50 
51 	optional_ioport_array<2> m_wheel;
52 
53 	void nmi_enable_w(uint8_t data);
54 	void soundlatch_w(uint8_t data);
55 	virtual void machine_start() override;
56 	virtual void machine_reset() override;
57 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
58 	DECLARE_WRITE_LINE_MEMBER(vblank_irq);
59 	void draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect);
60 
61 private:
62 	uint8_t spriteram_r(offs_t offset);
63 	uint8_t spriteram2_r(offs_t offset);
64 	void spriteram_w(offs_t offset, uint8_t data, uint8_t mem_mask = ~0);
65 	void spriteram2_w(offs_t offset, uint8_t data, uint8_t mem_mask = ~0);
66 	DECLARE_WRITE_LINE_MEMBER(galaxygn_sound_irq);
67 	INTERRUPT_GEN_MEMBER(fantland_sound_irq);
68 	void fantland_map(address_map &map);
69 	void fantland_sound_iomap(address_map &map);
70 	void fantland_sound_map(address_map &map);
71 	void galaxygn_map(address_map &map);
72 	void galaxygn_sound_iomap(address_map &map);
73 	void wheelrun_map(address_map &map);
74 	void wheelrun_sound_map(address_map &map);
75 };
76 
77 class borntofi_state : public fantland_state
78 {
79 public:
borntofi_state(const machine_config & mconfig,device_type type,const char * tag)80 	borntofi_state(const machine_config &mconfig, device_type type, const char *tag) :
81 		fantland_state(mconfig, type, tag),
82 		m_msm(*this, "msm%u", 1U),
83 		m_adpcm_rom(*this, "adpcm")
84 	{
85 	}
86 
87 	void borntofi(machine_config &config);
88 
89 private:
90 	/* misc */
91 	int        m_old_x[2];
92 	int        m_old_y[2];
93 	int        m_old_f[2];
94 	uint8_t    m_input_ret[2];
95 	int        m_adpcm_playing[4];
96 	int        m_adpcm_addr[2][4];
97 	int        m_adpcm_nibble[4];
98 
99 	/* devices */
100 	required_device_array<msm5205_device, 4> m_msm;
101 	required_region_ptr<uint8_t> m_adpcm_rom;
102 
103 	uint8_t inputs_r(offs_t offset);
104 	void msm5205_w(offs_t offset, uint8_t data);
105 	virtual void machine_start() override;
106 	virtual void machine_reset() override;
107 	template<int Voice> DECLARE_WRITE_LINE_MEMBER(adpcm_int);
108 	void adpcm_start(int voice);
109 	void adpcm_stop(int voice);
110 	void main_map(address_map &map);
111 	void sound_map(address_map &map);
112 };
113 
114 #endif // MAME_INCLUDES_FANTLAND_H
115