1 // license:BSD-3-Clause
2 // copyright-holders:Dan Boris, Aaron Giles
3 /*************************************************************************
4 
5     Atari Return of the Jedi hardware
6 
7 *************************************************************************/
8 #ifndef MAME_INCLUDES_JEDI_H
9 #define MAME_INCLUDES_JEDI_H
10 
11 #pragma once
12 
13 #include "machine/gen_latch.h"
14 #include "machine/x2212.h"
15 #include "sound/tms5220.h"
16 #include "emupal.h"
17 #include "screen.h"
18 
19 #define DEBUG_GFXDECODE 0 // GFX layout for debug
20 
21 /* oscillators and clocks */
22 #define JEDI_MAIN_CPU_OSC       (XTAL(10'000'000))
23 #define JEDI_AUDIO_CPU_OSC      (XTAL(12'096'000))
24 #define JEDI_MAIN_CPU_CLOCK     (JEDI_MAIN_CPU_OSC / 4)
25 #define JEDI_AUDIO_CPU_CLOCK    (JEDI_AUDIO_CPU_OSC / 8)
26 #define JEDI_POKEY_CLOCK        (JEDI_AUDIO_CPU_CLOCK)
27 #define JEDI_TMS5220_CLOCK      (JEDI_AUDIO_CPU_OSC / 2 / 9) /* div by 9 is via a binary counter that counts from 7 to 16 */
28 
29 
30 class jedi_state : public driver_device
31 {
32 public:
jedi_state(const machine_config & mconfig,device_type type,const char * tag)33 	jedi_state(const machine_config &mconfig, device_type type, const char *tag) :
34 		driver_device(mconfig, type, tag),
35 		m_backgroundram(*this, "backgroundram"),
36 		m_foregroundram(*this, "foregroundram"),
37 		m_spriteram(*this, "spriteram"),
38 		m_smoothing_table(*this, "smoothing_table"),
39 		m_tx_gfx(*this, "tx_gfx"),
40 		m_bg_gfx(*this, "bg_gfx"),
41 		m_spr_gfx(*this, "spr_gfx"),
42 		m_proms(*this, "proms"),
43 		m_maincpu(*this, "maincpu"),
44 		m_audiocpu(*this, "audiocpu"),
45 		m_soundlatch(*this, "soundlatch"),
46 		m_sacklatch(*this, "sacklatch"),
47 		m_tms(*this, "tms"),
48 		m_novram(*this, "novram12%c", 'b'),
49 #ifdef DEBUG_GFXDECODE
50 		m_gfxdecode(*this, "gfxdecode"),
51 #endif
52 		m_palette(*this, "palette"),
53 		m_screen(*this, "screen"),
54 		m_mainbank(*this, "mainbank")
55 	{ }
56 
57 	DECLARE_CUSTOM_INPUT_MEMBER(jedi_audio_comm_stat_r);
58 	void jedi(machine_config &config);
59 
60 protected:
61 	virtual void machine_start() override;
62 	virtual void machine_reset() override;
63 	virtual void video_start() override;
64 
65 private:
66 	void main_irq_ack_w(u8 data);
67 	void rom_banksel_w(u8 data);
68 	DECLARE_WRITE_LINE_MEMBER(coin_counter_left_w);
69 	DECLARE_WRITE_LINE_MEMBER(coin_counter_right_w);
70 	u8 novram_data_r(address_space &space, offs_t offset);
71 	void novram_data_w(offs_t offset, u8 data);
72 	void novram_recall_w(offs_t offset, u8 data);
73 	void novram_store_w(u8 data);
74 	void vscroll_w(offs_t offset, u8 data);
75 	void hscroll_w(offs_t offset, u8 data);
76 	void irq_ack_w(u8 data);
77 	DECLARE_WRITE_LINE_MEMBER(audio_reset_w);
78 	u8 audio_comm_stat_r();
79 	void speech_strobe_w(offs_t offset, u8 data);
80 	u8 speech_ready_r();
81 	void speech_reset_w(u8 data);
82 	DECLARE_WRITE_LINE_MEMBER(foreground_bank_w);
83 	DECLARE_WRITE_LINE_MEMBER(video_off_w);
84 	u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
85 	TIMER_CALLBACK_MEMBER(generate_interrupt);
86 	static rgb_t jedi_IRGB_3333(u32 raw);
87 	void do_pen_lookup(bitmap_rgb32 &bitmap, const rectangle &cliprect);
88 	void draw_background_and_text(bitmap_rgb32 &bitmap, const rectangle &cliprect);
89 	void draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect);
90 	void jedi_audio(machine_config &config);
91 	void jedi_video(machine_config &config);
92 	void audio_map(address_map &map);
93 	void main_map(address_map &map);
94 
95 	/* machine state */
96 	emu_timer *m_interrupt_timer;
97 
98 	/* video state */
99 	required_shared_ptr<u8> m_backgroundram;
100 	required_shared_ptr<u8> m_foregroundram;
101 	required_shared_ptr<u8> m_spriteram;
102 	required_shared_ptr<u8> m_smoothing_table;
103 	required_region_ptr<u8> m_tx_gfx;
104 	required_region_ptr<u8> m_bg_gfx;
105 	required_region_ptr<u8> m_spr_gfx;
106 	required_region_ptr<u8> m_proms;
107 	u32 m_vscroll;
108 	u32 m_hscroll;
109 	bool m_foreground_bank;
110 	bool m_video_off;
111 
112 	required_device<cpu_device> m_maincpu;
113 	required_device<cpu_device> m_audiocpu;
114 	required_device<generic_latch_8_device> m_soundlatch;
115 	required_device<generic_latch_8_device> m_sacklatch;
116 	required_device<tms5220_device> m_tms;
117 	required_device_array<x2212_device, 2> m_novram;
118 #ifdef DEBUG_GFXDECODE
119 	required_device<gfxdecode_device> m_gfxdecode;
120 #endif
121 	required_device<palette_device> m_palette;
122 	required_device<screen_device> m_screen;
123 	required_memory_bank m_mainbank;
124 };
125 
126 #endif // MAME_INCLUDES_JEDI_H
127