summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/includes/gaelco3d.h
blob: 472bff096f3fc18bd996297839a7dce1a1422221 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/*************************************************************************

    Driver for Gaelco 3D games

    driver by Aaron Giles

**************************************************************************/

#include "sound/dmadac.h"
#include "video/poly.h"
#include "machine/eepromser.h"
#include "machine/gaelco3d.h"
#include "machine/gen_latch.h"
#include "machine/timer.h"
#include "cpu/adsp2100/adsp2100.h"
#include "screen.h"

#define SOUND_CHANNELS  4

struct gaelco3d_object_data
{
	uint32_t tex, color;
	float ooz_dx, ooz_dy, ooz_base;
	float uoz_dx, uoz_dy, uoz_base;
	float voz_dx, voz_dy, voz_base;
	float z0;
};

class gaelco3d_state;

class gaelco3d_renderer : public poly_manager<float, gaelco3d_object_data, 1, 2000>
{
public:
	gaelco3d_renderer(gaelco3d_state &state);

	bitmap_ind16 &screenbits() { return m_screenbits; }
	uint32_t polygons() { uint32_t result = m_polygons; m_polygons = 0; return result; }

	void render_poly(screen_device &screen, uint32_t *polydata);

private:
	gaelco3d_state &m_state;
	bitmap_ind16 m_screenbits;
	bitmap_ind16 m_zbuffer;
	uint32_t m_polygons;
	offs_t m_texture_size;
	offs_t m_texmask_size;
	std::unique_ptr<uint8_t[]> m_texture;
	std::unique_ptr<uint8_t[]> m_texmask;

	void render_noz_noperspective(int32_t scanline, const extent_t &extent, const gaelco3d_object_data &extra, int threadid);
	void render_normal(int32_t scanline, const extent_t &extent, const gaelco3d_object_data &extra, int threadid);
	void render_alphablend(int32_t scanline, const extent_t &extent, const gaelco3d_object_data &extra, int threadid);
};

class gaelco3d_state : public driver_device
{
public:
	gaelco3d_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag),
			m_adsp_ram_base(*this,"adsp_ram_base"),
			m_m68k_ram_base(*this,"m68k_ram_base",0),
			m_tms_comm_base(*this,"tms_comm_base",0),
			m_adsp_control_regs(*this,"adsp_regs"),
			m_adsp_fastram_base(*this,"adsp_fastram") ,
		m_maincpu(*this, "maincpu"),
		m_adsp(*this, "adsp"),
		m_eeprom(*this, "eeprom"),
		m_tms(*this, "tms"),
		m_serial(*this, "serial"),
		m_screen(*this, "screen"),
		m_soundlatch(*this, "soundlatch"),
		m_paletteram16(*this, "paletteram"),
		m_paletteram32(*this, "paletteram"),
		m_analog(*this, {"ANALOG0", "ANALOG1", "ANALOG2", "ANALOG3"})
		{ }

	required_shared_ptr<uint32_t> m_adsp_ram_base;
	required_shared_ptr<uint16_t> m_m68k_ram_base;
	required_shared_ptr<uint16_t> m_tms_comm_base;
	required_shared_ptr<uint16_t> m_adsp_control_regs;
	required_shared_ptr<uint16_t> m_adsp_fastram_base;
	required_device<cpu_device> m_maincpu;
	required_device<adsp21xx_device> m_adsp;
	required_device<eeprom_serial_93cxx_device> m_eeprom;
	required_device<cpu_device> m_tms;
	required_device<gaelco_serial_device> m_serial;
	required_device<screen_device> m_screen;
	required_device<generic_latch_8_device> m_soundlatch;

	optional_shared_ptr<uint16_t> m_paletteram16;
	optional_shared_ptr<uint32_t> m_paletteram32;
	optional_ioport_array<4> m_analog;

	uint8_t m_sound_status;
	offs_t m_tms_offset_xor;
	uint8_t m_analog_ports[4];
	uint32_t m_fp_analog_ports[2];
	uint32_t m_fp_lenght[2];
	uint8_t m_fp_clock;
	uint8_t m_fp_state;
	uint8_t m_framenum;
	timer_device *m_adsp_autobuffer_timer;
	uint8_t m_adsp_ireg;
	offs_t m_adsp_ireg_base;
	offs_t m_adsp_incs;
	offs_t m_adsp_size;
	dmadac_sound_device *m_dmadac[SOUND_CHANNELS];
	std::unique_ptr<rgb_t[]> m_palette;
	std::unique_ptr<uint32_t[]> m_polydata_buffer;
	uint32_t m_polydata_count;
	int m_lastscan;
	int m_video_changed;
	std::unique_ptr<gaelco3d_renderer> m_poly;
	DECLARE_WRITE16_MEMBER(irq_ack_w);
	DECLARE_READ16_MEMBER(sound_status_r);
	DECLARE_WRITE16_MEMBER(sound_status_w);
	DECLARE_WRITE_LINE_MEMBER(analog_port_clock_w);
	DECLARE_WRITE_LINE_MEMBER(analog_port_latch_w);
	DECLARE_READ32_MEMBER(tms_m68k_ram_r);
	DECLARE_WRITE32_MEMBER(tms_m68k_ram_w);
	DECLARE_WRITE8_MEMBER(tms_iack_w);
	DECLARE_WRITE_LINE_MEMBER(tms_reset_w);
	DECLARE_WRITE_LINE_MEMBER(tms_irq_w);
	DECLARE_WRITE_LINE_MEMBER(tms_control3_w);
	DECLARE_WRITE16_MEMBER(tms_comm_w);
	DECLARE_WRITE16_MEMBER(adsp_control_w);
	DECLARE_WRITE16_MEMBER(adsp_rombank_w);
	DECLARE_WRITE_LINE_MEMBER(radikalb_lamp_w);
	DECLARE_WRITE_LINE_MEMBER(unknown_137_w);
	DECLARE_WRITE_LINE_MEMBER(unknown_13a_w);
	DECLARE_WRITE32_MEMBER(gaelco3d_render_w);
	DECLARE_WRITE16_MEMBER(gaelco3d_paletteram_w);
	DECLARE_WRITE32_MEMBER(gaelco3d_paletteram_020_w);
	DECLARE_CUSTOM_INPUT_MEMBER(analog_bit_r);
	DECLARE_WRITE_LINE_MEMBER(ser_irq);
	DECLARE_READ16_MEMBER(eeprom_data_r);
	DECLARE_DRIVER_INIT(gaelco3d);
	virtual void machine_start() override;
	virtual void machine_reset() override;
	virtual void video_start() override;
	DECLARE_MACHINE_RESET(gaelco3d2);
	DECLARE_MACHINE_RESET(common);
	uint32_t screen_update_gaelco3d(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
	INTERRUPT_GEN_MEMBER(vblank_gen);
	TIMER_DEVICE_CALLBACK_MEMBER(adsp_autobuffer_irq);
	void gaelco3d_render(screen_device &screen);
	DECLARE_WRITE32_MEMBER(adsp_tx_callback);
	DECLARE_WRITE_LINE_MEMBER(fp_analog_clock_w);
	DECLARE_CUSTOM_INPUT_MEMBER(fp_analog_bit_r);
};