1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /*************************************************************************
4 
5     Driver for Gaelco 3D games
6 
7     driver by Aaron Giles
8 
9 **************************************************************************/
10 #ifndef MAME_INCLUDES_GAELCO3D_H
11 #define MAME_INCLUDES_GAELCO3D_H
12 
13 #pragma once
14 
15 #include "cpu/adsp2100/adsp2100.h"
16 #include "cpu/tms32031/tms32031.h"
17 #include "machine/74259.h"
18 #include "machine/eepromser.h"
19 #include "machine/gaelco3d.h"
20 #include "machine/gen_latch.h"
21 #include "machine/timer.h"
22 #include "sound/dmadac.h"
23 #include "video/poly.h"
24 #include "screen.h"
25 
26 #define SOUND_CHANNELS  4
27 
28 
29 class gaelco3d_state : public driver_device
30 {
31 public:
gaelco3d_state(const machine_config & mconfig,device_type type,const char * tag)32 	gaelco3d_state(const machine_config &mconfig, device_type type, const char *tag)
33 		: driver_device(mconfig, type, tag)
34 		, m_adsp_ram_base(*this, "adsp_ram_base")
35 		, m_m68k_ram_base(*this, "m68k_ram_base", 0)
36 		, m_adsp_control_regs(*this, "adsp_regs")
37 		, m_adsp_fastram_base(*this, "adsp_fastram")
38 		, m_maincpu(*this, "maincpu")
39 		, m_adsp(*this, "adsp")
40 		, m_eeprom(*this, "eeprom")
41 		, m_tms(*this, "tms")
42 		, m_dmadac(*this, "dac%u", 0U)
43 		, m_serial(*this, "serial")
44 		, m_screen(*this, "screen")
45 		, m_soundlatch(*this, "soundlatch")
46 		, m_mainlatch(*this, "mainlatch")
47 		, m_outlatch(*this, "outlatch")
48 		, m_adsp_autobuffer_timer(*this, "adsp_timer")
49 		, m_paletteram16(*this, "paletteram")
50 		, m_paletteram32(*this, "paletteram")
51 		, m_analog(*this, "ANALOG%u", 0U)
52 		, m_adsp_bank(*this, "adspbank")
53 	{ }
54 
55 	void footbpow(machine_config &config);
56 	void gaelco3d2(machine_config &config);
57 	void gaelco3d(machine_config &config);
58 
59 	template <int N> DECLARE_READ_LINE_MEMBER(analog_bit_r);
60 	template <int N> DECLARE_READ_LINE_MEMBER(fp_analog_bit_r);
61 
62 private:
63 	virtual void machine_start() override;
64 	virtual void machine_reset() override;
65 	virtual void video_start() override;
66 
67 	struct gaelco3d_object_data
68 	{
69 		uint32_t tex, color;
70 		float ooz_dx, ooz_dy, ooz_base;
71 		float uoz_dx, uoz_dy, uoz_base;
72 		float voz_dx, voz_dy, voz_base;
73 		float z0;
74 	};
75 
76 	class gaelco3d_renderer : public poly_manager<float, gaelco3d_object_data, 1, 2000>
77 	{
78 	public:
79 		gaelco3d_renderer(gaelco3d_state &state);
~gaelco3d_renderer()80 		~gaelco3d_renderer() {}
81 
screenbits()82 		bitmap_ind16 &screenbits() { return m_screenbits; }
polygons()83 		uint32_t polygons() { uint32_t result = m_polygons; m_polygons = 0; return result; }
84 
85 		void render_poly(screen_device &screen, uint32_t *polydata);
86 
87 	protected:
88 		gaelco3d_state &m_state;
89 
90 	private:
91 		bitmap_ind16 m_screenbits;
92 		bitmap_ind16 m_zbuffer;
93 		uint32_t m_polygons;
94 		offs_t m_texture_size;
95 		offs_t m_texmask_size;
96 		std::unique_ptr<uint8_t[]> m_texture;
97 		std::unique_ptr<uint8_t[]> m_texmask;
98 
99 		void render_noz_noperspective(int32_t scanline, const extent_t &extent, const gaelco3d_object_data &extra, int threadid);
100 		void render_normal(int32_t scanline, const extent_t &extent, const gaelco3d_object_data &extra, int threadid);
101 		void render_alphablend(int32_t scanline, const extent_t &extent, const gaelco3d_object_data &extra, int threadid);
102 	};
103 
104 	required_shared_ptr<uint32_t> m_adsp_ram_base;
105 	required_shared_ptr<uint16_t> m_m68k_ram_base;
106 	required_shared_ptr<uint16_t> m_adsp_control_regs;
107 	required_shared_ptr<uint16_t> m_adsp_fastram_base;
108 	required_device<cpu_device> m_maincpu;
109 	required_device<adsp21xx_device> m_adsp;
110 	required_device<eeprom_serial_93cxx_device> m_eeprom;
111 	required_device<tms32031_device> m_tms;
112 	required_device_array<dmadac_sound_device, SOUND_CHANNELS> m_dmadac;
113 	required_device<gaelco_serial_device> m_serial;
114 	required_device<screen_device> m_screen;
115 	required_device<generic_latch_8_device> m_soundlatch;
116 	required_device<ls259_device> m_mainlatch;
117 	required_device<ls259_device> m_outlatch;
118 	required_device<timer_device> m_adsp_autobuffer_timer;
119 
120 	optional_shared_ptr<uint16_t> m_paletteram16;
121 	optional_shared_ptr<uint32_t> m_paletteram32;
122 	optional_ioport_array<4> m_analog;
123 	required_memory_bank m_adsp_bank;
124 
125 	uint8_t m_sound_status;
126 	offs_t m_tms_offset_xor;
127 	uint8_t m_analog_ports[4];
128 	uint32_t m_fp_analog_ports[2];
129 	uint32_t m_fp_lenght[2];
130 	uint8_t m_fp_clock;
131 	uint8_t m_fp_state;
132 	uint8_t m_framenum;
133 	uint8_t m_adsp_ireg;
134 	offs_t m_adsp_ireg_base;
135 	offs_t m_adsp_incs;
136 	offs_t m_adsp_size;
137 	std::unique_ptr<rgb_t[]> m_palette;
138 	std::unique_ptr<uint32_t[]> m_polydata_buffer;
139 	uint32_t m_polydata_count;
140 	int m_lastscan;
141 	int m_video_changed;
142 	std::unique_ptr<gaelco3d_renderer> m_poly;
143 
144 	void irq_ack_w(uint16_t data);
145 	uint16_t sound_status_r(offs_t offset, uint16_t mem_mask = ~0);
146 	void sound_status_w(uint16_t data);
147 	DECLARE_WRITE_LINE_MEMBER(analog_port_clock_w);
148 	DECLARE_WRITE_LINE_MEMBER(analog_port_latch_w);
149 	uint32_t tms_m68k_ram_r(offs_t offset);
150 	void tms_m68k_ram_w(offs_t offset, uint32_t data);
151 	void tms_iack_w(offs_t offset, uint8_t data);
152 	DECLARE_WRITE_LINE_MEMBER(tms_reset_w);
153 	DECLARE_WRITE_LINE_MEMBER(tms_irq_w);
154 	DECLARE_WRITE_LINE_MEMBER(tms_control3_w);
155 	void adsp_control_w(offs_t offset, uint16_t data);
156 	void adsp_rombank_w(offs_t offset, uint16_t data);
157 	DECLARE_WRITE_LINE_MEMBER(radikalb_lamp_w);
158 	DECLARE_WRITE_LINE_MEMBER(unknown_137_w);
159 	DECLARE_WRITE_LINE_MEMBER(unknown_13a_w);
160 	void gaelco3d_render_w(uint32_t data);
161 	void gaelco3d_paletteram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
162 	void gaelco3d_paletteram_020_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
163 	DECLARE_WRITE_LINE_MEMBER(ser_irq);
164 	uint16_t eeprom_data_r(offs_t offset, uint16_t mem_mask = ~0);
165 
166 	DECLARE_MACHINE_RESET(gaelco3d2);
167 	DECLARE_MACHINE_RESET(common);
168 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
169 	INTERRUPT_GEN_MEMBER(vblank_gen);
170 	TIMER_DEVICE_CALLBACK_MEMBER(adsp_autobuffer_irq);
171 	void gaelco3d_render(screen_device &screen);
172 	void adsp_tx_callback(offs_t offset, uint32_t data);
173 	DECLARE_WRITE_LINE_MEMBER(fp_analog_clock_w);
174 
175 	void adsp_data_map(address_map &map);
176 	void adsp_program_map(address_map &map);
177 	void main020_map(address_map &map);
178 	void main_map(address_map &map);
179 	void tms_map(address_map &map);
180 };
181 
182 #endif // MAME_INCLUDES_GAELCO3D_H
183