1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /*************************************************************************
4 
5     Sega G-80 raster hardware
6 
7 *************************************************************************/
8 #ifndef MAME_INCLUDES_SEGAG80R_H
9 #define MAME_INCLUDES_SEGAG80R_H
10 
11 #pragma once
12 
13 #include "audio/segag80.h"
14 #include "audio/segag80r.h"
15 #include "audio/segaspeech.h"
16 #include "audio/segausb.h"
17 #include "machine/i8255.h"
18 #include "machine/segag80.h"
19 #include "sound/samples.h"
20 #include "sound/sn76496.h"
21 #include "emupal.h"
22 #include "screen.h"
23 #include "tilemap.h"
24 
25 
26 class sega005_sound_device;
27 
28 class segag80r_state : public driver_device
29 {
30 public:
segag80r_state(const machine_config & mconfig,device_type type,const char * tag)31 	segag80r_state(const machine_config &mconfig, device_type type, const char *tag) :
32 		driver_device(mconfig, type, tag),
33 		m_mainram(*this, "mainram"),
34 		m_videoram(*this, "videoram"),
35 		m_sn1(*this, "sn1"),
36 		m_sn2(*this, "sn2"),
37 		m_maincpu(*this, "maincpu"),
38 		m_audiocpu(*this, "audiocpu"),
39 		m_soundbrd(*this, "soundbrd"),
40 		m_samples(*this, "samples"),
41 		m_speech(*this, "speech"),
42 		m_g80_audio(*this, "g80sound"),
43 		m_usbsnd(*this, "usbsnd"),
44 		m_005snd(*this, "005"),
45 		m_gfxdecode(*this, "gfxdecode"),
46 		m_screen(*this, "screen"),
47 		m_palette(*this, "palette"),
48 		m_decrypted_opcodes(*this, "decrypted_opcodes")
49 	{ }
50 
51 	void g80r_base(machine_config &config);
52 	void monsterb(machine_config &config);
53 	void sindbadm(machine_config &config);
54 	void astrob(machine_config &config);
55 	void pignewt(machine_config &config);
56 	void monster2(machine_config &config);
57 	void sega005(machine_config &config);
58 	void spaceod(machine_config &config);
59 	void sega005_sound_board(machine_config &config);
60 	void spaceod_sound_board(machine_config &config);
61 	void monsterb_sound_board(machine_config &config);
62 
63 	void init_waitstates();
64 	void init_spaceod();
65 	void init_sindbadm();
66 	void init_pignewt();
67 	void init_monsterb();
68 	void init_005();
69 	void init_monster2();
70 	void init_astrob();
71 
72 	DECLARE_INPUT_CHANGED_MEMBER(service_switch);
73 
74 	uint8_t m_sound_state[2];
75 	uint8_t m_sound_rate;
76 	uint16_t m_sound_addr;
77 	uint8_t m_sound_data;
78 	uint8_t m_square_state;
79 	uint8_t m_square_count;
80 	inline void sega005_update_sound_data();
81 
82 private:
83 	enum
84 	{
85 		TIMER_VBLANK_LATCH_CLEAR
86 	};
87 
88 	required_shared_ptr<uint8_t> m_mainram;
89 	required_shared_ptr<uint8_t> m_videoram;
90 
91 	optional_device<sn76496_device> m_sn1;
92 	optional_device<sn76496_device> m_sn2;
93 	required_device<cpu_device> m_maincpu;
94 	optional_device<cpu_device> m_audiocpu;
95 	optional_device<monsterb_sound_device> m_soundbrd;
96 	optional_device<samples_device> m_samples;
97 	optional_device<sega_speech_device> m_speech;
98 	optional_device<segag80_audio_device_base> m_g80_audio;
99 	optional_device<usb_sound_device> m_usbsnd;
100 	optional_device<sega005_sound_device> m_005snd;
101 	required_device<gfxdecode_device> m_gfxdecode;
102 	required_device<screen_device> m_screen;
103 	required_device<palette_device> m_palette;
104 	optional_shared_ptr<uint8_t> m_decrypted_opcodes;
105 
106 	std::vector<uint8_t> m_paletteram;
107 
108 	offs_t m_scrambled_write_pc;
109 
110 	segag80_decrypt_func m_decrypt;
111 	uint8_t m_background_pcb;
112 	double m_rweights[3];
113 	double m_gweights[3];
114 	double m_bweights[2];
115 	uint8_t m_video_control;
116 	uint8_t m_video_flip;
117 	uint8_t m_vblank_latch;
118 	tilemap_t *m_spaceod_bg_htilemap;
119 	tilemap_t *m_spaceod_bg_vtilemap;
120 	uint16_t m_spaceod_hcounter;
121 	uint16_t m_spaceod_vcounter;
122 	uint8_t m_spaceod_fixed_color;
123 	uint8_t m_spaceod_bg_control;
124 	uint8_t m_spaceod_bg_detect;
125 	tilemap_t *m_bg_tilemap;
126 	uint8_t m_bg_enable;
127 	uint8_t m_bg_char_bank;
128 	uint16_t m_bg_scrollx;
129 	uint16_t m_bg_scrolly;
130 	uint8_t m_pignewt_bg_color_offset;
131 
132 	uint8_t g80r_opcode_r(offs_t offset);
133 	void mainram_w(offs_t offset, uint8_t data);
134 	void vidram_w(offs_t offset, uint8_t data);
135 	void monsterb_vidram_w(offs_t offset, uint8_t data);
136 	void pignewt_vidram_w(offs_t offset, uint8_t data);
137 	void sindbadm_vidram_w(offs_t offset, uint8_t data);
138 	uint8_t mangled_ports_r(offs_t offset);
139 	uint8_t spaceod_mangled_ports_r(offs_t offset);
140 	uint8_t spaceod_port_fc_r();
141 	void coin_count_w(uint8_t data);
142 	void segag80r_videoram_w(offs_t offset, uint8_t data);
143 	uint8_t segag80r_video_port_r(offs_t offset);
144 	void segag80r_video_port_w(offs_t offset, uint8_t data);
145 	uint8_t spaceod_back_port_r(offs_t offset);
146 	void spaceod_back_port_w(offs_t offset, uint8_t data);
147 	void monsterb_videoram_w(offs_t offset, uint8_t data);
148 	void monsterb_back_port_w(offs_t offset, uint8_t data);
149 	void pignewt_videoram_w(offs_t offset, uint8_t data);
150 	void pignewt_back_color_w(offs_t offset, uint8_t data);
151 	void pignewt_back_port_w(offs_t offset, uint8_t data);
152 	void sindbadm_videoram_w(offs_t offset, uint8_t data);
153 	void sindbadm_back_port_w(offs_t offset, uint8_t data);
154 	void spaceod_sound_w(offs_t offset, uint8_t data);
155 
156 	void usb_ram_w(offs_t offset, uint8_t data);
157 	void sindbadm_misc_w(uint8_t data);
158 	void sindbadm_sn1_SN76496_w(uint8_t data);
159 	void sindbadm_sn2_SN76496_w(uint8_t data);
160 
161 	TILE_GET_INFO_MEMBER(spaceod_get_tile_info);
162 	TILEMAP_MAPPER_MEMBER(spaceod_scan_rows);
163 	TILE_GET_INFO_MEMBER(bg_get_tile_info);
164 	virtual void machine_start() override;
165 	virtual void video_start() override;
166 	uint32_t screen_update_segag80r(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
167 	INTERRUPT_GEN_MEMBER(segag80r_vblank_start);
168 	IRQ_CALLBACK_MEMBER(segag80r_irq_ack);
169 	INTERRUPT_GEN_MEMBER(sindbadm_vblank_start);
170 	void sega005_sound_a_w(uint8_t data);
171 	void sega005_sound_b_w(uint8_t data);
172 
173 	void vblank_latch_set();
174 	void g80_set_palette_entry(int entry, uint8_t data);
175 	void spaceod_bg_init_palette();
176 	void draw_videoram(bitmap_ind16 &bitmap, const rectangle &cliprect, const uint8_t *transparent_pens);
177 	void draw_background_spaceod(bitmap_ind16 &bitmap, const rectangle &cliprect);
178 	void draw_background_page_scroll(bitmap_ind16 &bitmap, const rectangle &cliprect);
179 	void draw_background_full_scroll(bitmap_ind16 &bitmap, const rectangle &cliprect);
180 	offs_t decrypt_offset(offs_t offset);
181 	inline uint8_t demangle(uint8_t d7d6, uint8_t d5d4, uint8_t d3d2, uint8_t d1d0);
182 	void monsterb_expand_gfx(const char *region);
183 
184 	void g80r_opcodes_map(address_map &map);
185 	void main_map(address_map &map);
186 	void main_portmap(address_map &map);
187 	void main_ppi8255_portmap(address_map &map);
188 	void sega_315_opcodes_map(address_map &map);
189 	void sindbadm_portmap(address_map &map);
190 	void sindbadm_sound_map(address_map &map);
191 
192 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
193 	emu_timer *m_vblank_latch_clear_timer;
194 };
195 
196 
197 /*----------- defined in audio/segag80r.c -----------*/
198 
199 
200 class sega005_sound_device : public device_t,
201 									public device_sound_interface
202 {
203 public:
204 	sega005_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
205 
206 	emu_timer *m_sega005_sound_timer;
207 	sound_stream *m_sega005_stream;
208 
209 protected:
210 	// device-level overrides
211 	virtual void device_start() override;
212 
213 	// sound stream update overrides
214 	virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
215 
216 private:
217 	// internal state
218 	TIMER_CALLBACK_MEMBER( sega005_auto_timer );
219 };
220 
221 DECLARE_DEVICE_TYPE(SEGA005, sega005_sound_device)
222 
223 /*----------- defined in video/segag80r.c -----------*/
224 
225 #define G80_BACKGROUND_NONE         0
226 #define G80_BACKGROUND_SPACEOD      1
227 #define G80_BACKGROUND_MONSTERB     2
228 #define G80_BACKGROUND_PIGNEWT      3
229 #define G80_BACKGROUND_SINDBADM     4
230 
231 #endif // MAME_INCLUDES_SEGAG80R_H
232