1 // license:BSD-3-Clause
2 // copyright-holders:Steve Baines, Frank Palazzolo
3 /***************************************************************************
4 
5     Atari Star Wars hardware
6 
7 ***************************************************************************/
8 #ifndef MAME_INCLUDES_STARWARS_H
9 #define MAME_INCLUDES_STARWARS_H
10 
11 #pragma once
12 
13 #include "machine/6532riot.h"
14 #include "machine/gen_latch.h"
15 #include "machine/slapstic.h"
16 #include "machine/x2212.h"
17 #include "sound/pokey.h"
18 #include "sound/tms5220.h"
19 
20 
21 class starwars_state : public driver_device
22 {
23 public:
starwars_state(const machine_config & mconfig,device_type type,const char * tag)24 	starwars_state(const machine_config &mconfig, device_type type, const char *tag) :
25 		driver_device(mconfig, type, tag),
26 		m_soundlatch(*this, "soundlatch"),
27 		m_mainlatch(*this, "mainlatch"),
28 		m_riot(*this, "riot"),
29 		m_mathram(*this, "mathram"),
30 		m_maincpu(*this, "maincpu"),
31 		m_audiocpu(*this, "audiocpu"),
32 		m_pokey(*this, "pokey%u", 1U),
33 		m_tms(*this, "tms"),
34 		m_novram(*this, "x2212"),
35 		m_slapstic_device(*this, "slapstic")
36 	{ }
37 
38 	void starwars(machine_config &config);
39 	void esb(machine_config &config);
40 
41 	void init_esb();
42 	void init_starwars();
43 
44 	DECLARE_READ_LINE_MEMBER(matrix_flag_r);
45 
46 private:
47 	required_device<generic_latch_8_device> m_soundlatch;
48 	required_device<generic_latch_8_device> m_mainlatch;
49 	required_device<riot6532_device> m_riot;
50 	required_shared_ptr<uint8_t> m_mathram;
51 	required_device<cpu_device> m_maincpu;
52 	required_device<cpu_device> m_audiocpu;
53 	required_device_array<pokey_device, 4> m_pokey;
54 	required_device<tms5220_device> m_tms;
55 	required_device<x2212_device> m_novram;
56 	optional_device<atari_slapstic_device> m_slapstic_device;
57 
58 	uint8_t *m_slapstic_source;
59 	uint8_t *m_slapstic_base;
60 	uint8_t m_slapstic_current_bank;
61 	int m_MPA;
62 	int m_BIC;
63 	uint16_t m_dvd_shift;
64 	uint16_t m_quotient_shift;
65 	uint16_t m_divisor;
66 	uint16_t m_dividend;
67 	std::unique_ptr<uint8_t[]> m_PROM_STR;
68 	std::unique_ptr<uint8_t[]> m_PROM_MAS;
69 	std::unique_ptr<uint8_t[]> m_PROM_AM;
70 	int m_math_run;
71 	emu_timer *m_math_timer;
72 	int16_t m_A;
73 	int16_t m_B;
74 	int16_t m_C;
75 	int32_t m_ACC;
76 	void irq_ack_w(uint8_t data);
77 	uint8_t esb_slapstic_r(address_space &space, offs_t offset);
78 	void esb_slapstic_w(address_space &space, offs_t offset, uint8_t data);
79 	void starwars_nstore_w(uint8_t data);
80 	DECLARE_WRITE_LINE_MEMBER(recall_w);
81 	DECLARE_WRITE_LINE_MEMBER(coin1_counter_w);
82 	DECLARE_WRITE_LINE_MEMBER(coin2_counter_w);
83 	uint8_t starwars_prng_r();
84 	DECLARE_WRITE_LINE_MEMBER(prng_reset_w);
85 	uint8_t starwars_div_reh_r();
86 	uint8_t starwars_div_rel_r();
87 	void starwars_math_w(offs_t offset, uint8_t data);
88 
89 	uint8_t starwars_main_ready_flag_r();
90 	DECLARE_WRITE_LINE_MEMBER(boost_interleave_hack);
91 	void starwars_soundrst_w(uint8_t data);
92 	void quad_pokeyn_w(offs_t offset, uint8_t data);
93 	virtual void machine_reset() override;
94 	TIMER_CALLBACK_MEMBER(math_run_clear);
95 	uint8_t r6532_porta_r();
96 	void r6532_porta_w(uint8_t data);
97 
98 	void starwars_mproc_init();
99 	void starwars_mproc_reset();
100 	void run_mproc();
101 	void esb_slapstic_tweak(address_space &space, offs_t offset);
102 
103 	void esb_main_map(address_map &map);
104 	void main_map(address_map &map);
105 	void sound_map(address_map &map);
106 };
107 
108 #endif // MAME_INCLUDES_STARWARS_H
109