1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /*************************************************************************
4 
5     Exidy 6502 hardware
6 
7 *************************************************************************/
8 
9 #include "sound/dac.h"
10 #include "sound/samples.h"
11 #include "emupal.h"
12 #include "screen.h"
13 
14 #define EXIDY_MASTER_CLOCK              (XTAL(11'289'000))
15 #define EXIDY_CPU_CLOCK                 (EXIDY_MASTER_CLOCK / 16)
16 #define EXIDY_PIXEL_CLOCK               (EXIDY_MASTER_CLOCK / 2)
17 #define EXIDY_HTOTAL                    (0x150)
18 #define EXIDY_HBEND                     (0x000)
19 #define EXIDY_HBSTART                   (0x100)
20 #define EXIDY_HSEND                     (0x140)
21 #define EXIDY_HSSTART                   (0x120)
22 #define EXIDY_VTOTAL                    (0x118)
23 #define EXIDY_VBEND                     (0x000)
24 #define EXIDY_VBSTART                   (0x100)
25 #define EXIDY_VSEND                     (0x108)
26 #define EXIDY_VSSTART                   (0x100)
27 
28 
29 class exidy_state : public driver_device
30 {
31 public:
32 	enum
33 	{
34 		TIMER_COLLISION_IRQ
35 	};
36 
exidy_state(const machine_config & mconfig,device_type type,const char * tag)37 	exidy_state(const machine_config &mconfig, device_type type, const char *tag)
38 		: driver_device(mconfig, type, tag),
39 		m_maincpu(*this, "maincpu"),
40 		m_dac(*this, "dac"),
41 		m_samples(*this, "samples"),
42 		m_gfxdecode(*this, "gfxdecode"),
43 		m_screen(*this, "screen"),
44 		m_palette(*this, "palette"),
45 		m_videoram(*this, "videoram"),
46 		m_sprite1_xpos(*this, "sprite1_xpos"),
47 		m_sprite1_ypos(*this, "sprite1_ypos"),
48 		m_sprite2_xpos(*this, "sprite2_xpos"),
49 		m_sprite2_ypos(*this, "sprite2_ypos"),
50 		m_spriteno(*this, "spriteno"),
51 		m_sprite_enable(*this, "sprite_enable"),
52 		m_color_latch(*this, "color_latch"),
53 		m_characterram(*this, "characterram") { }
54 
55 	void base(machine_config &config);
56 	void mtrap(machine_config &config);
57 	void venture(machine_config &config);
58 	void fax(machine_config &config);
59 	void teetert(machine_config &config);
60 	void sidetrac(machine_config &config);
61 	void spectar(machine_config &config);
62 	void spectar_audio(machine_config &config);
63 	void rallys(machine_config &config);
64 	void pepper2(machine_config &config);
65 	void targ(machine_config &config);
66 	void targ_audio(machine_config &config);
67 
68 	void init_fax();
69 	void init_sidetrac();
70 	void init_pepper2();
71 	void init_targ();
72 	void init_rallys();
73 	void init_mtrap();
74 	void init_teetert();
75 	void init_venture();
76 	void init_spectar();
77 	void init_phantoma();
78 
79 	DECLARE_CUSTOM_INPUT_MEMBER(teetert_input_r);
80 
81 private:
82 	required_device<cpu_device> m_maincpu;
83 	optional_device<dac_bit_interface> m_dac;
84 	optional_device<samples_device> m_samples;
85 	required_device<gfxdecode_device> m_gfxdecode;
86 	required_device<screen_device> m_screen;
87 	required_device<palette_device> m_palette;
88 
89 	required_shared_ptr<uint8_t> m_videoram;
90 	required_shared_ptr<uint8_t> m_sprite1_xpos;
91 	required_shared_ptr<uint8_t> m_sprite1_ypos;
92 	required_shared_ptr<uint8_t> m_sprite2_xpos;
93 	required_shared_ptr<uint8_t> m_sprite2_ypos;
94 	required_shared_ptr<uint8_t> m_spriteno;
95 	required_shared_ptr<uint8_t> m_sprite_enable;
96 	required_shared_ptr<uint8_t> m_color_latch;
97 	required_shared_ptr<uint8_t> m_characterram;
98 
99 	uint8_t m_last_dial;
100 	uint8_t m_collision_mask;
101 	uint8_t m_collision_invert;
102 	int m_is_2bpp;
103 	uint8_t m_int_condition;
104 	bitmap_ind16 m_background_bitmap;
105 	bitmap_ind16 m_motion_object_1_vid;
106 	bitmap_ind16 m_motion_object_2_vid;
107 	bitmap_ind16 m_motion_object_2_clip;
108 
109 	void fax_bank_select_w(uint8_t data);
110 	uint8_t exidy_interrupt_r();
111 	void mtrap_ocl_w(uint8_t data);
112 
113 	virtual void video_start() override;
114 	DECLARE_MACHINE_START(teetert);
115 
116 	uint32_t screen_update_exidy(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
117 
118 	INTERRUPT_GEN_MEMBER(exidy_vblank_interrupt);
119 
120 	void exidy_video_config(uint8_t _collision_mask, uint8_t _collision_invert, int _is_2bpp);
121 	inline void latch_condition(int collision);
122 	inline void set_1_color(int index, int which);
123 	void set_colors();
124 	void draw_background();
125 	inline int sprite_1_enabled();
126 	void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
127 	void check_collision();
128 
129 	/* Targ and Spectar samples */
130 	int m_max_freq;
131 	uint8_t m_port_1_last;
132 	uint8_t m_port_2_last;
133 	uint8_t m_tone_freq;
134 	uint8_t m_tone_active;
135 	uint8_t m_tone_pointer;
136 	void targ_audio_1_w(uint8_t data);
137 	void targ_audio_2_w(uint8_t data);
138 	void spectar_audio_2_w(uint8_t data);
139 	void adjust_sample(uint8_t freq);
140 	void common_audio_start(int freq);
141 	SAMPLES_START_CB_MEMBER(spectar_audio_start);
142 	SAMPLES_START_CB_MEMBER(targ_audio_start);
143 
144 	void exidy_map(address_map &map);
145 	void fax_map(address_map &map);
146 	void mtrap_map(address_map &map);
147 	void pepper2_map(address_map &map);
148 	void rallys_map(address_map &map);
149 	void sidetrac_map(address_map &map);
150 	void spectar_map(address_map &map);
151 	void targ_map(address_map &map);
152 	void venture_map(address_map &map);
153 
154 protected:
155 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
156 };
157