1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 #ifndef MAME_INCLUDES_TMC1800_H
4 #define MAME_INCLUDES_TMC1800_H
5 
6 #pragma once
7 
8 
9 #include "cpu/cosmac/cosmac.h"
10 #include "imagedev/cassette.h"
11 #include "imagedev/snapquik.h"
12 #include "machine/ram.h"
13 #include "machine/rescap.h"
14 #include "sound/cdp1864.h"
15 #include "video/cdp1861.h"
16 #include "sound/beep.h"
17 
18 #define TMC2000_COLORRAM_SIZE   0x200
19 
20 #define SCREEN_TAG      "screen"
21 #define CDP1802_TAG     "cdp1802"
22 #define CDP1861_TAG     "cdp1861"
23 #define CDP1864_TAG     "m3"
24 
25 class tmc1800_base_state : public driver_device
26 {
27 public:
tmc1800_base_state(const machine_config & mconfig,device_type type,const char * tag)28 	tmc1800_base_state(const machine_config &mconfig, device_type type, const char *tag)
29 		: driver_device(mconfig, type, tag)
30 		, m_maincpu(*this, CDP1802_TAG)
31 		, m_cassette(*this, "cassette")
32 		, m_rom(*this, CDP1802_TAG)
33 		, m_run(*this, "RUN")
34 		, m_ram(*this, RAM_TAG)
35 		, m_beeper(*this, "beeper")
36 	{ }
37 
38 	DECLARE_QUICKLOAD_LOAD_MEMBER(quickload_cb);
39 
40 protected:
41 	required_device<cosmac_device> m_maincpu;
42 	required_device<cassette_image_device> m_cassette;
43 	required_memory_region m_rom;
44 	required_ioport m_run;
45 	required_device<ram_device> m_ram;
46 	optional_device<beep_device> m_beeper;
47 };
48 
49 class tmc1800_state : public tmc1800_base_state
50 {
51 public:
52 	enum
53 	{
54 		TIMER_SETUP_BEEP
55 	};
56 
tmc1800_state(const machine_config & mconfig,device_type type,const char * tag)57 	tmc1800_state(const machine_config &mconfig, device_type type, const char *tag)
58 		: tmc1800_base_state(mconfig, type, tag)
59 		, m_vdc(*this, CDP1861_TAG)
60 	{ }
61 
62 	void keylatch_w(uint8_t data);
63 	uint8_t dispon_r();
64 	void dispoff_w(uint8_t data);
65 	DECLARE_READ_LINE_MEMBER( clear_r );
66 	DECLARE_READ_LINE_MEMBER( ef2_r );
67 	DECLARE_READ_LINE_MEMBER( ef3_r );
68 	DECLARE_WRITE_LINE_MEMBER( q_w );
69 
70 	void init_tmc1800();
71 
72 	void tmc1800(machine_config &config);
73 	void tmc1800_video(machine_config &config);
74 	void tmc1800_io_map(address_map &map);
75 	void tmc1800_map(address_map &map);
76 
77 protected:
78 	virtual void machine_start() override;
79 	virtual void machine_reset() override;
80 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
81 
82 	required_device<cdp1861_device> m_vdc;
83 	/* keyboard state */
84 	int m_keylatch;         /* key latch */
85 };
86 
87 class osc1000b_state : public tmc1800_base_state
88 {
89 public:
osc1000b_state(const machine_config & mconfig,device_type type,const char * tag)90 	osc1000b_state(const machine_config &mconfig, device_type type, const char *tag)
91 		: tmc1800_base_state(mconfig, type, tag)
92 	{ }
93 
94 
95 	uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
96 
97 	void keylatch_w(uint8_t data);
98 	DECLARE_READ_LINE_MEMBER( clear_r );
99 	DECLARE_READ_LINE_MEMBER( ef2_r );
100 	DECLARE_READ_LINE_MEMBER( ef3_r );
101 	DECLARE_WRITE_LINE_MEMBER( q_w );
102 
103 	void osc1000b(machine_config &config);
104 	void osc1000b_video(machine_config &config);
105 	void osc1000b_io_map(address_map &map);
106 	void osc1000b_map(address_map &map);
107 
108 protected:
109 	virtual void machine_start() override;
110 	virtual void machine_reset() override;
111 
112 	/* keyboard state */
113 	int m_keylatch;
114 };
115 
116 class tmc2000_state : public tmc1800_base_state
117 {
118 public:
tmc2000_state(const machine_config & mconfig,device_type type,const char * tag)119 	tmc2000_state(const machine_config &mconfig, device_type type, const char *tag)
120 		: tmc1800_base_state(mconfig, type, tag)
121 		, m_cti(*this, CDP1864_TAG)
122 		, m_colorram(*this, "color_ram")
123 		, m_key_row(*this, {"Y0", "Y1", "Y2", "Y3", "Y4", "Y5", "Y6", "Y7"})
124 		, m_led(*this, "led1")
125 	{ }
126 
127 	void keylatch_w(uint8_t data);
128 	void bankswitch_w(uint8_t data);
129 	DECLARE_READ_LINE_MEMBER( clear_r );
130 	DECLARE_READ_LINE_MEMBER( ef2_r );
131 	DECLARE_READ_LINE_MEMBER( ef3_r );
132 	DECLARE_WRITE_LINE_MEMBER( q_w );
133 	void dma_w(offs_t offset, uint8_t data);
134 	DECLARE_READ_LINE_MEMBER( rdata_r );
135 	DECLARE_READ_LINE_MEMBER( bdata_r );
136 	DECLARE_READ_LINE_MEMBER( gdata_r );
137 	DECLARE_INPUT_CHANGED_MEMBER( run_pressed );
138 
139 	void bankswitch();
140 
141 	void tmc2000(machine_config &config);
142 	void tmc2000_video(machine_config &config);
143 	void tmc2000_io_map(address_map &map);
144 	void tmc2000_map(address_map &map);
145 
146 protected:
147 	virtual void machine_start() override;
148 	virtual void machine_reset() override;
149 
150 	required_device<cdp1864_device> m_cti;
151 	optional_shared_ptr<uint8_t> m_colorram;
152 	required_ioport_array<8> m_key_row;
153 	output_finder<> m_led;
154 
155 	// memory
156 	int m_rac;
157 	int m_roc;
158 
159 	/* video state */
160 	uint8_t m_color;
161 
162 	/* keyboard state */
163 	int m_keylatch;
164 };
165 
166 class nano_state : public tmc1800_base_state
167 {
168 public:
nano_state(const machine_config & mconfig,device_type type,const char * tag)169 	nano_state(const machine_config &mconfig, device_type type, const char *tag)
170 		: tmc1800_base_state(mconfig, type, tag)
171 		, m_cti(*this, CDP1864_TAG)
172 		, m_ny0(*this, "NY0")
173 		, m_ny1(*this, "NY1")
174 		, m_monitor(*this, "MONITOR")
175 		, m_led(*this, "led1")
176 	{ }
177 
178 	enum
179 	{
180 		TIMER_ID_EF4
181 	};
182 
183 	void keylatch_w(uint8_t data);
184 	void bankswitch_w(uint8_t data);
185 	DECLARE_READ_LINE_MEMBER( clear_r );
186 	DECLARE_READ_LINE_MEMBER( ef2_r );
187 	DECLARE_READ_LINE_MEMBER( ef3_r );
188 	DECLARE_WRITE_LINE_MEMBER( q_w );
189 	DECLARE_INPUT_CHANGED_MEMBER( run_pressed );
190 	DECLARE_INPUT_CHANGED_MEMBER( monitor_pressed );
191 
192 	void nano(machine_config &config);
193 	void nano_video(machine_config &config);
194 	void nano_io_map(address_map &map);
195 	void nano_map(address_map &map);
196 
197 protected:
198 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
199 	virtual void machine_start() override;
200 	virtual void machine_reset() override;
201 
202 	required_device<cdp1864_device> m_cti;
203 	required_ioport m_ny0;
204 	required_ioport m_ny1;
205 	required_ioport m_monitor;
206 	output_finder<> m_led;
207 	/* keyboard state */
208 	int m_keylatch;         /* key latch */
209 };
210 
211 #endif
212