1 // license:BSD-3-Clause
2 // copyright-holders:Chris Moore
3 /***************************************************************************
4 
5 GAME PLAN driver
6 
7 driver by Chris Moore
8 
9 ***************************************************************************/
10 
11 #include "machine/6522via.h"
12 #include "machine/6532riot.h"
13 #include "machine/gen_latch.h"
14 #include "screen.h"
15 
16 #define GAMEPLAN_MAIN_MASTER_CLOCK       (XTAL(3'579'545))
17 #define GAMEPLAN_AUDIO_MASTER_CLOCK      (XTAL(3'579'545))
18 #define GAMEPLAN_MAIN_CPU_CLOCK          (GAMEPLAN_MAIN_MASTER_CLOCK / 4)
19 #define GAMEPLAN_AUDIO_CPU_CLOCK         (GAMEPLAN_AUDIO_MASTER_CLOCK / 4)
20 #define GAMEPLAN_AY8910_CLOCK            (GAMEPLAN_AUDIO_MASTER_CLOCK / 2)
21 #define GAMEPLAN_PIXEL_CLOCK             (XTAL(11'668'800) / 2)
22 
23 /* Used Leprechaun/Pot of Gold (and Pirate Treasure) - as stated in manual for Pot Of Gold */
24 
25 #define LEPRECHAUN_MAIN_MASTER_CLOCK     (XTAL(4'000'000))
26 #define LEPRECHAUN_MAIN_CPU_CLOCK        (LEPRECHAUN_MAIN_MASTER_CLOCK / 4)
27 
28 
29 class gameplan_state : public driver_device
30 {
31 public:
32 	enum
33 	{
34 		TIMER_CLEAR_SCREEN_DONE,
35 		TIMER_VIA_IRQ_DELAYED,
36 		TIMER_VIA_0_CAL
37 	};
38 
gameplan_state(const machine_config & mconfig,device_type type,const char * tag)39 	gameplan_state(const machine_config &mconfig, device_type type, const char *tag)
40 		: driver_device(mconfig, type, tag),
41 			m_trvquest_question(*this, "trvquest_q"),
42 			m_maincpu(*this, "maincpu"),
43 			m_audiocpu(*this, "audiocpu"),
44 			m_riot(*this, "riot"),
45 			m_via_0(*this, "via6522_0"),
46 			m_via_1(*this, "via6522_1"),
47 			m_via_2(*this, "via6522_2"),
48 			m_screen(*this, "screen"),
49 			m_soundlatch(*this, "soundlatch") { }
50 
51 	void gameplan(machine_config &config);
52 	void gameplan_video(machine_config &config);
53 	void leprechn(machine_config &config);
54 	void leprechn_video(machine_config &config);
55 	void trvquest(machine_config &config);
56 	void trvquest_video(machine_config &config);
57 
58 protected:
59 	virtual void video_start() override;
60 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
61 
62 private:
63 	/* machine state */
64 	uint8_t   m_current_port;
65 	optional_shared_ptr<uint8_t> m_trvquest_question;
66 
67 	/* video state */
68 	std::unique_ptr<uint8_t[]>   m_videoram;
69 	size_t   m_videoram_size;
70 	uint8_t    m_video_x;
71 	uint8_t    m_video_y;
72 	uint8_t    m_video_command;
73 	uint8_t    m_video_data;
74 
75 	/* devices */
76 	required_device<cpu_device> m_maincpu;
77 	optional_device<cpu_device> m_audiocpu;
78 	optional_device<riot6532_device> m_riot;
79 	required_device<via6522_device> m_via_0;
80 	required_device<via6522_device> m_via_1;
81 	required_device<via6522_device> m_via_2;
82 	required_device<screen_device> m_screen;
83 	optional_device<generic_latch_8_device> m_soundlatch;
84 
85 
86 	void io_select_w(uint8_t data);
87 	uint8_t io_port_r();
88 	DECLARE_WRITE_LINE_MEMBER(coin_w);
89 	DECLARE_WRITE_LINE_MEMBER(audio_reset_w);
90 	void audio_cmd_w(uint8_t data);
91 	DECLARE_WRITE_LINE_MEMBER(audio_trigger_w);
92 	DECLARE_WRITE_LINE_MEMBER(r6532_irq);
93 	DECLARE_MACHINE_START(gameplan);
94 	DECLARE_MACHINE_RESET(gameplan);
95 	DECLARE_MACHINE_START(trvquest);
96 	DECLARE_MACHINE_RESET(trvquest);
97 	uint32_t screen_update_gameplan(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
98 	uint32_t screen_update_leprechn(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
99 	TIMER_CALLBACK_MEMBER(clear_screen_done_callback);
100 	TIMER_CALLBACK_MEMBER(via_irq_delayed);
101 	void video_data_w(uint8_t data);
102 	void gameplan_video_command_w(uint8_t data);
103 	void leprechn_video_command_w(uint8_t data);
104 	uint8_t leprechn_videoram_r();
105 	DECLARE_WRITE_LINE_MEMBER(video_command_trigger_w);
106 	void gameplan_get_pens( pen_t *pens );
107 	void leprechn_get_pens( pen_t *pens );
108 	DECLARE_WRITE_LINE_MEMBER(via_irq);
109 	uint8_t trvquest_question_r(offs_t offset);
110 	DECLARE_WRITE_LINE_MEMBER(trvquest_coin_w);
111 	DECLARE_WRITE_LINE_MEMBER(trvquest_misc_w);
112 
113 	void cpu_map(address_map &map);
114 	void gameplan_audio_map(address_map &map);
115 	void gameplan_main_map(address_map &map);
116 	void leprechn_audio_map(address_map &map);
117 };
118