1 // license:BSD-3-Clause
2 // copyright-holders:Philip Bennett
3 /***************************************************************************
4 
5     Turret Tower hardware
6 
7 ****************************************************************************/
8 #ifndef MAME_INCLUDES_TURRETT_H
9 #define MAME_INCLUDES_TURRETT_H
10 
11 #pragma once
12 
13 #include "cpu/mips/mips1.h"
14 #include "bus/ata/ataintf.h"
15 #include "emupal.h"
16 #include "speaker.h"
17 #include "screen.h"
18 
19 
20 class turrett_state : public driver_device
21 {
22 public:
turrett_state(const machine_config & mconfig,device_type type,const char * tag)23 	turrett_state(const machine_config &mconfig, device_type type, const char *tag)
24 		: driver_device(mconfig, type, tag)
25 		, m_maincpu(*this, "maincpu")
26 		, m_ata(*this, "ata")
27 		, m_bank_a(*this, "bank_a")
28 		, m_bank_b(*this, "bank_b")
29 		, m_screen(*this, "screen")
30 	{
31 	}
32 
33 	void turrett(machine_config &config);
34 
35 	INPUT_CHANGED_MEMBER(ipt_change);
36 
37 private:
38 	// constants
39 	static const uint32_t X_VISIBLE = 336;
40 	static const uint32_t Y_VISIBLE = 244;
41 	static const uint32_t DIMM_BANK_WORDS = 128 * 1024 * 1024 / 2;
42 	static const uint32_t DIMM_BANK_MASK  = DIMM_BANK_WORDS - 1;
43 	static const uint32_t VRAM_BANK_WORDS = 256 * 1024;
44 
45 	// devices
46 	required_device<r3041_device> m_maincpu;
47 	required_device<ata_interface_device> m_ata;
48 	required_shared_ptr<uint16_t> m_bank_a;
49 	required_shared_ptr<uint16_t> m_bank_b;
50 	required_device<screen_device> m_screen;
51 
52 	// handlers
53 	void dma_w(offs_t offset, uint32_t data);
54 	uint32_t video_r(offs_t offset, uint32_t mem_mask = ~0);
55 	void video_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
56 	uint32_t int_r();
57 	void int_w(uint32_t data);
58 	DECLARE_READ_LINE_MEMBER(sbrc2_r);
59 	DECLARE_READ_LINE_MEMBER(sbrc3_r);
60 
61 	TIMER_CALLBACK_MEMBER(dma_complete);
62 	INTERRUPT_GEN_MEMBER(vblank);
63 	INTERRUPT_GEN_MEMBER(adc);
64 
65 	// functions
66 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
67 	uint32_t write_video_ram(uint16_t data);
68 	void update_video_addr(void);
69 	uint32_t update_inputs(void);
70 
71 	// members
72 	emu_timer *m_dma_timer;
73 	uint32_t  m_inputs_active;
74 	std::unique_ptr<uint16_t[]>  m_video_ram[2];
75 	uint16_t  m_last_pixel;
76 	int32_t   m_video_ctrl;
77 	uint16_t  m_video_fade;
78 	int16_t   m_x_pos;
79 	int16_t   m_x_start;
80 	int16_t   m_x_mod;
81 	int16_t   m_dx;
82 	int16_t   m_y_pos;
83 	int16_t   m_scale_cnt_y;
84 	int16_t   m_scale_cnt_x;
85 	bool    m_skip_x;
86 	bool    m_skip_y;
87 	int16_t   m_scale;
88 	int16_t   m_hotspot_x;
89 	int16_t   m_hotspot_y;
90 	bool    m_dma_idle;
91 	uint32_t  m_dma_addr[2];
92 	uint32_t  m_ipt_val;
93 	uint8_t   m_frame;
94 	uint8_t   m_adc;
95 
96 	void cpu_map(address_map &map);
97 	void turrett_sound_map(address_map &map);
98 
99 	// driver_device overrides
100 	virtual void machine_reset() override;
101 	virtual void machine_start() override;
102 };
103 
104 
105 class turrett_device : public device_t,
106 						public device_sound_interface,
107 						public device_memory_interface
108 {
109 	static const uint32_t SOUND_CHANNELS = 32;
110 
111 public:
112 	// construction/destruction
113 	turrett_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
114 
115 	uint32_t read(offs_t offset);
116 	void write(offs_t offset, uint32_t data);
117 
118 protected:
119 	// device-level overrides
120 	virtual void device_start() override;
121 	virtual void device_reset() override;
122 
123 	// device_sound_interface overrides
124 	virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
125 
126 	// device_memory_interface overrides
127 	virtual space_config_vector memory_space_config() const override;
128 
129 	const address_space_config  m_space_config;
130 
131 private:
132 	memory_access<28, 1, 0, ENDIANNESS_LITTLE>::cache m_cache;
133 	sound_stream *m_stream;
134 
135 	struct
136 	{
137 		uint32_t  m_address;
138 		uint32_t  m_volume;
139 		bool    m_playing;
140 	} m_channels[SOUND_CHANNELS];
141 
142 	int32_t m_volume_table[0x50];
143 };
144 
145 // device type definition
146 DECLARE_DEVICE_TYPE(TURRETT, turrett_device)
147 
148 #endif // MAME_INCLUDES_TURRETT_H
149