1 // license:BSD-3-Clause
2 // copyright-holders:Hans Ostermeyer, R. Belmont
3 /*
4  * apollo.h - APOLLO DN3500/DN3000 driver includes
5  *
6  *  Created on: May 12, 2010
7  *      Author: Hans Ostermeyer
8  *
9  */
10 
11 #ifndef MAME_INCLUDES_APOLLO_H
12 #define MAME_INCLUDES_APOLLO_H
13 
14 #pragma once
15 
16 
17 #include "machine/apollo_kbd.h"
18 
19 #include "cpu/m68000/m68000.h"
20 
21 #include "machine/6840ptm.h"
22 #include "machine/am9517a.h"
23 #include "machine/clock.h"
24 #include "machine/mc146818.h"
25 #include "machine/mc68681.h"
26 #include "machine/pic8259.h"
27 #include "machine/ram.h"
28 #include "machine/terminal.h"
29 
30 #include "bus/isa/isa.h"
31 #include "bus/isa/isa_cards.h"
32 #include "bus/isa/3c505.h"
33 #include "bus/isa/omti8621.h"
34 
35 #include "bus/rs232/rs232.h"
36 
37 #include "diserial.h"
38 #include "screen.h"
39 
40 #ifndef VERBOSE
41 #define VERBOSE 0
42 #endif
43 
44 #define LOG(x)  { logerror x; logerror ("\n"); apollo_check_log(); }
45 #define LOG1(x) { if (VERBOSE > 0) LOG(x) }
46 #define LOG2(x) { if (VERBOSE > 1) LOG(x) }
47 #define CLOG(x) { machine().logerror ("%s - %s: ", apollo_cpu_context(machine()), tag()); machine().logerror x; machine().logerror ("\n"); apollo_check_log(); }
48 #define CLOG1(x) { if (VERBOSE > 0) CLOG(x) }
49 #define CLOG2(x) { if (VERBOSE > 1) CLOG(x) }
50 #define DLOG(x) { device->logerror ("%s - %s: ", apollo_cpu_context(device->machine()), device->tag()); device->logerror x; device->logerror ("\n"); apollo_check_log(); }
51 #define DLOG1(x) { if (VERBOSE > 0) DLOG(x) }
52 #define DLOG2(x) { if (VERBOSE > 1) DLOG(x) }
53 #define MLOG(x)  { machine().logerror ("%s: ", apollo_cpu_context(machine())); machine().logerror x; machine().logerror ("\n"); apollo_check_log(); }
54 #define MLOG1(x) { if (VERBOSE > 0) MLOG(x) }
55 #define MLOG2(x) { if (VERBOSE > 1) MLOG(x) }
56 #define SLOG(x)  { machine().logerror ("%s: ", apollo_cpu_context(machine()));machine().logerror x; machine().logerror ("\n"); apollo_check_log(); }
57 #define SLOG1(x) { if (VERBOSE > 0) SLOG(x) }
58 #define SLOG2(x) { if (VERBOSE > 1) SLOG(x) }
59 
60 #define  MAINCPU "maincpu"
61 
62 // Enabling this is >NOT< supported by MESSdev
63 // Do *not* report any issues on Mametesters if this is enabled!
64 // #define APOLLO_XXL
65 
66 /*----------- drivers/apollo.cpp -----------*/
67 
68 // return the current CPU context for log file entries
69 std::string apollo_cpu_context(running_machine &machine);
70 
71 // enable/disable the FPU
72 void apollo_set_cpu_has_fpu(m68000_base_device *device, int onoff);
73 
74 // check for excessive logging
75 void apollo_check_log();
76 
77 // return 1 if node is DN3000 or DSP3000, 0 otherwise
78 int apollo_is_dn3000(void);
79 
80 // return 1 if node is DN5500 or DSP5500, 0 otherwise
81 int apollo_is_dn5500(void);
82 
83 // return 1 if node is DSP3000 or DSP3500, 0 otherwise
84 int apollo_is_dsp3x00(void);
85 
86 // get the ram configuration byte
87 uint8_t apollo_get_ram_config_byte(void);
88 
89 //apollo_get_node_id - get the node id
90 uint32_t apollo_get_node_id(void);
91 
92 void apollo_set_cache_status_register(device_t *device,uint8_t mask, uint8_t data);
93 
94 /*----------- machine/apollo.cpp -----------*/
95 
96 #define APOLLO_CONF_TAG "conf"
97 #define APOLLO_DMA1_TAG "dma8237_1"
98 #define APOLLO_DMA2_TAG "dma8237_2"
99 #define APOLLO_STDIO_TAG "stdio"
100 #define APOLLO_PIC1_TAG "pic8259_master"
101 #define APOLLO_PIC2_TAG "pic8259_slave"
102 #define APOLLO_PTM_TAG  "ptm"
103 #define APOLLO_RTC_TAG  "rtc"
104 #define APOLLO_SIO_TAG  "sio"
105 #define APOLLO_SIO2_TAG "sio2"
106 #define APOLLO_ETH_TAG  "3c505"
107 #define APOLLO_NI_TAG  "node_id"
108 #define APOLLO_ISA_TAG "isabus"
109 #define APOLLO_SCREEN_TAG "apollo_screen"
110 #define APOLLO_KBD_TAG  "kbd"
111 
112 
113 // forward declaration
114 class apollo_sio;
115 class apollo_ni;
116 class apollo_graphics_15i;
117 class apollo_kbd_device;
118 
119 class apollo_state : public driver_device
120 {
121 public:
apollo_state(const machine_config & mconfig,device_type type,const char * tag)122 	apollo_state(const machine_config &mconfig, device_type type, const char *tag) :
123 		driver_device(mconfig, type, tag),
124 		m_maincpu(*this, MAINCPU),
125 		m_ram(*this, RAM_TAG),
126 		m_messram_ptr(*this, RAM_TAG),
127 		m_dma8237_1(*this, APOLLO_DMA1_TAG),
128 		m_dma8237_2(*this, APOLLO_DMA2_TAG),
129 		m_pic8259_master(*this, APOLLO_PIC1_TAG),
130 		m_pic8259_slave(*this, APOLLO_PIC2_TAG),
131 		m_ptm(*this, APOLLO_PTM_TAG),
132 		m_sio(*this, APOLLO_SIO_TAG),
133 		m_sio2(*this, APOLLO_SIO2_TAG),
134 		m_rtc(*this, APOLLO_RTC_TAG),
135 		m_node_id(*this, APOLLO_NI_TAG),
136 		m_isa(*this, APOLLO_ISA_TAG),
137 		m_graphics(*this, APOLLO_SCREEN_TAG),
138 		m_keyboard(*this, APOLLO_KBD_TAG),
139 		m_internal_leds(*this, "internal_led_%u", 1U),
140 		m_external_leds(*this, "external_led_%c", unsigned('a'))
141 	{ }
142 
143 	void dn3500(machine_config &config);
144 	void dn5500_19i(machine_config &config);
145 	void dn3000(machine_config &config);
146 	void dn3000_15i(machine_config &config);
147 	void dn3000_19i(machine_config &config);
148 	void dn3500_15i(machine_config &config);
149 	void dsp3000(machine_config &config);
150 	void dsp3500(machine_config &config);
151 	void dsp5500(machine_config &config);
152 	void dn5500(machine_config &config);
153 	void dn5500_15i(machine_config &config);
154 	void dn3500_19i(machine_config &config);
155 
156 	void init_dsp3000();
157 	void init_dsp5500();
158 	void init_dn3500();
159 	void init_dn3000();
160 	void init_dsp3500();
161 	void init_dn5500();
162 	void init_apollo();
163 
164 protected:
165 	virtual void machine_start() override;
166 	virtual void machine_reset() override;
167 
168 private:
169 	required_device<m68000_base_device> m_maincpu;
170 	required_device<ram_device> m_ram;
171 	required_shared_ptr<uint32_t> m_messram_ptr;
172 
173 	required_device<am9517a_device> m_dma8237_1;
174 	required_device<am9517a_device> m_dma8237_2;
175 	required_device<pic8259_device> m_pic8259_master;
176 	required_device<pic8259_device> m_pic8259_slave;
177 	required_device<ptm6840_device> m_ptm;
178 	required_device<apollo_sio> m_sio;
179 	optional_device<apollo_sio> m_sio2;
180 	required_device<mc146818_device> m_rtc;
181 	required_device<apollo_ni> m_node_id;
182 	required_device<isa16_device> m_isa;
183 	optional_device<apollo_graphics_15i> m_graphics;
184 	optional_device<apollo_kbd_device> m_keyboard;
185 	output_finder<4> m_internal_leds;
186 	output_finder<4> m_external_leds;
187 
188 	void apollo_csr_status_register_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
189 	uint16_t apollo_csr_status_register_r(offs_t offset, uint16_t mem_mask = ~0);
190 	void apollo_csr_control_register_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
191 	uint16_t apollo_csr_control_register_r(offs_t offset, uint16_t mem_mask = ~0);
192 	void apollo_dma_1_w(offs_t offset, uint8_t data);
193 	uint8_t apollo_dma_1_r(offs_t offset);
194 	void apollo_dma_2_w(offs_t offset, uint8_t data);
195 	uint8_t apollo_dma_2_r(offs_t offset);
196 	void apollo_dma_page_register_w(offs_t offset, uint8_t data);
197 	uint8_t apollo_dma_page_register_r(offs_t offset);
198 	void apollo_address_translation_map_w(offs_t offset, uint16_t data);
199 	uint16_t apollo_address_translation_map_r(offs_t offset);
200 	uint8_t apollo_dma_read_byte(offs_t offset);
201 	void apollo_dma_write_byte(offs_t offset, uint8_t data);
202 	uint8_t apollo_dma_read_word(offs_t offset);
203 	void apollo_dma_write_word(offs_t offset, uint8_t data);
204 	void apollo_rtc_w(offs_t offset, uint8_t data);
205 	uint8_t apollo_rtc_r(offs_t offset);
206 	void cache_control_register_w(offs_t offset, uint8_t data);
207 	uint8_t cache_status_register_r(offs_t offset);
208 	void task_alias_register_w(offs_t offset, uint8_t data);
209 	uint8_t task_alias_register_r(offs_t offset);
210 	void latch_page_on_parity_error_register_w(offs_t offset, uint16_t data);
211 	uint16_t latch_page_on_parity_error_register_r(offs_t offset);
212 	void master_req_register_w(offs_t offset, uint8_t data);
213 	uint8_t master_req_register_r(offs_t offset);
214 	void selective_clear_locations_w(offs_t offset, uint16_t data);
215 	uint16_t selective_clear_locations_r(offs_t offset);
216 	uint32_t ram_with_parity_r(offs_t offset, uint32_t mem_mask = ~0);
217 	void ram_with_parity_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
218 	uint32_t apollo_unmapped_r(offs_t offset, uint32_t mem_mask = ~0);
219 	void apollo_unmapped_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
220 	void apollo_rom_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
221 	uint16_t apollo_atbus_io_r(offs_t offset, uint16_t mem_mask = ~0);
222 	void apollo_atbus_io_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
223 	uint16_t apollo_atbus_memory_r(offs_t offset, uint16_t mem_mask = ~0);
224 	void apollo_atbus_memory_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
225 	uint16_t apollo_atbus_unmap_io_r(offs_t offset, uint16_t mem_mask = ~0);
226 	void apollo_atbus_unmap_io_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
227 	uint8_t apollo_atbus_unmap_r(offs_t offset, uint8_t mem_mask = ~0);
228 	void apollo_atbus_unmap_w(offs_t offset, uint8_t data, uint8_t mem_mask = ~0);
229 	void dn5500_memory_present_register_w(offs_t offset, uint8_t data);
230 	uint8_t dn5500_memory_present_register_r(offs_t offset);
231 	void dn5500_11500_w(offs_t offset, uint8_t data);
232 	uint8_t dn5500_11500_r(offs_t offset);
233 	void dn5500_io_protection_map_w(offs_t offset, uint8_t data);
234 	uint8_t dn5500_io_protection_map_r(offs_t offset);
235 
236 	DECLARE_MACHINE_RESET(apollo);
237 	DECLARE_MACHINE_START(apollo);
238 
239 	void cpu_space_map(address_map &map);
240 	u16 apollo_irq_acknowledge(offs_t offset);
241 	u16 apollo_pic_get_vector();
242 	void apollo_bus_error();
243 	DECLARE_READ_LINE_MEMBER( apollo_kbd_is_german );
244 	DECLARE_WRITE_LINE_MEMBER( apollo_dma8237_out_eop );
245 	DECLARE_WRITE_LINE_MEMBER( apollo_dma_1_hrq_changed );
246 	DECLARE_WRITE_LINE_MEMBER( apollo_dma_2_hrq_changed );
247 	DECLARE_WRITE_LINE_MEMBER( apollo_pic8259_master_set_int_line );
248 	DECLARE_WRITE_LINE_MEMBER( apollo_pic8259_slave_set_int_line );
249 	DECLARE_WRITE_LINE_MEMBER( sio_irq_handler );
250 	void sio_output(uint8_t data);
251 	DECLARE_WRITE_LINE_MEMBER( sio2_irq_handler );
252 	DECLARE_WRITE_LINE_MEMBER( apollo_ptm_irq_function );
253 	DECLARE_WRITE_LINE_MEMBER( apollo_ptm_timer_tick );
254 	uint8_t apollo_pic8259_get_slave_ack(offs_t offset);
255 	DECLARE_WRITE_LINE_MEMBER( apollo_rtc_irq_function );
256 
257 	uint8_t pc_dma8237_0_dack_r();
258 	uint8_t pc_dma8237_1_dack_r();
259 	uint8_t pc_dma8237_2_dack_r();
260 	uint8_t pc_dma8237_3_dack_r();
261 	uint8_t pc_dma8237_5_dack_r();
262 	uint8_t pc_dma8237_6_dack_r();
263 	uint8_t pc_dma8237_7_dack_r();
264 	void pc_dma8237_0_dack_w(uint8_t data);
265 	void pc_dma8237_1_dack_w(uint8_t data);
266 	void pc_dma8237_2_dack_w(uint8_t data);
267 	void pc_dma8237_3_dack_w(uint8_t data);
268 	void pc_dma8237_5_dack_w(uint8_t data);
269 	void pc_dma8237_6_dack_w(uint8_t data);
270 	void pc_dma8237_7_dack_w(uint8_t data);
271 	DECLARE_WRITE_LINE_MEMBER(pc_dack0_w);
272 	DECLARE_WRITE_LINE_MEMBER(pc_dack1_w);
273 	DECLARE_WRITE_LINE_MEMBER(pc_dack2_w);
274 	DECLARE_WRITE_LINE_MEMBER(pc_dack3_w);
275 	DECLARE_WRITE_LINE_MEMBER(pc_dack4_w);
276 	DECLARE_WRITE_LINE_MEMBER(pc_dack5_w);
277 	DECLARE_WRITE_LINE_MEMBER(pc_dack6_w);
278 	DECLARE_WRITE_LINE_MEMBER(pc_dack7_w);
279 
280 	void apollo_pic_set_irq_line(int irq, int state);
281 	void select_dma_channel(int channel, bool state);
282 
283 	DECLARE_WRITE_LINE_MEMBER(apollo_reset_instr_callback);
284 
285 	void common(machine_config &config);
286 	void apollo(machine_config &config);
287 	void apollo_terminal(machine_config &config);
288 
289 	void dn3000_map(address_map &map);
290 	void dn3500_map(address_map &map);
291 	void dn5500_map(address_map &map);
292 	void dsp3000_map(address_map &map);
293 	void dsp3500_map(address_map &map);
294 	void dsp5500_map(address_map &map);
295 
296 	uint32_t ptm_counter;
297 	uint8_t sio_output_data;
298 	int m_dma_channel;
299 	bool m_cur_eop;
300 };
301 
302 /*----------- machine/apollo_config.cpp -----------*/
303 
304 // configuration bit definitions
305 
306 #define APOLLO_CONF_SERVICE_MODE 0x0001
307 #define APOLLO_CONF_DISPLAY      0x001e
308 #define APOLLO_CONF_8_PLANES     0x0002
309 #define APOLLO_CONF_4_PLANES     0x0004
310 #define APOLLO_CONF_MONO_15I     0x0008
311 #define APOLLO_CONF_MONO_19I     0x0010
312 #define APOLLO_CONF_GERMAN_KBD   0x0020
313 #define APOLLO_CONF_30_YEARS_AGO 0x0040
314 #define APOLLO_CONF_25_YEARS_AGO 0x0080
315 #define APOLLO_CONF_NODE_ID      0x0100
316 #define APOLLO_CONF_IDLE_SLEEP   0x0200
317 #define APOLLO_CONF_TRAP_TRACE   0x0400
318 #define APOLLO_CONF_FPU_TRACE    0x0800
319 #define APOLLO_CONF_DISK_TRACE   0x1000
320 #define APOLLO_CONF_NET_TRACE    0x2000
321 
322 // check configuration setting
323 int apollo_config(int mask);
324 
325 INPUT_PORTS_EXTERN(apollo_config);
326 
327 /*----------- machine/apollo_csr.cpp -----------*/
328 
329 #define APOLLO_CSR_SR_SERVICE            0x0001
330 #define APOLLO_CSR_SR_ATBUS_IO_TIMEOUT   0x0002
331 #define APOLLO_CSR_SR_FP_TRAP            0x0004
332 #define APOLLO_CSR_SR_INTERRUPT_PENDING  0x0008 // DN3000 only
333 #define APOLLO_CSR_SR_PARITY_BYTE_MASK   0x00f0
334 #define APOLLO_CSR_SR_CPU_TIMEOUT        0x0100
335 #define APOLLO_CSR_SR_ATBUS_MEM_TIMEOUT  0x2000
336 #define APOLLO_CSR_SR_BIT15              0x8000
337 #define APOLLO_CSR_SR_CLEAR_ALL          0x3ffe
338 
339 #define APOLLO_CSR_CR_INTERRUPT_ENABLE   0x0001
340 #define APOLLO_CSR_CR_RESET_DEVICES       0x0002
341 #define APOLLO_CSR_CR_FPU_TRAP_ENABLE    0x0004
342 #define APOLLO_CSR_CR_FORCE_BAD_PARITY   0x0008
343 #define APOLLO_CSR_CR_PARITY_BYTE_MASK   0x00f0
344 
345 uint16_t apollo_csr_get_control_register(void);
346 uint16_t apollo_csr_get_status_register(void);
347 void apollo_csr_set_status_register(uint16_t mask, uint16_t data);
348 
349 /*----------- machine/apollo_sio.cpp -----------*/
350 
351 class apollo_sio: public duart_base_device
352 {
353 public:
354 	apollo_sio(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
355 
356 	virtual uint8_t read(offs_t offset) override;
357 	virtual void write(offs_t offset, uint8_t data) override;
358 
359 protected:
360 	virtual void device_reset() override;
361 
362 private:
363 	uint8_t m_csrb;
364 };
365 
DECLARE_DEVICE_TYPE(APOLLO_SIO,apollo_sio)366 DECLARE_DEVICE_TYPE(APOLLO_SIO, apollo_sio)
367 
368 /*----------- machine/apollo_ni.cpp -----------*/
369 
370 
371 /*** Apollo Node ID device ***/
372 
373 class apollo_ni: public device_t, public device_image_interface
374 {
375 public:
376 	// construction/destruction
377 	apollo_ni(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
378 	virtual ~apollo_ni();
379 
380 	// image-level overrides
381 	virtual iodevice_t image_type() const noexcept override { return IO_ROM; }
382 
383 	virtual bool is_readable()  const noexcept override { return true; }
384 	virtual bool is_writeable() const noexcept override { return true; }
385 	virtual bool is_creatable() const noexcept override { return true; }
386 	virtual bool must_be_loaded() const noexcept override { return false; }
387 	virtual bool is_reset_on_load() const noexcept override { return false; }
388 	virtual bool support_command_line_image_creation() const noexcept override { return true; }
389 	virtual const char *file_extensions() const noexcept override { return "ani,bin"; }
390 
391 	virtual image_init_result call_load() override;
392 	virtual image_init_result call_create(int format_type, util::option_resolution *format_options) override;
393 	virtual void call_unload() override;
394 	virtual const char *custom_instance_name() const noexcept override { return "node_id"; }
395 	virtual const char *custom_brief_instance_name() const noexcept override { return "ni"; }
396 
397 	void write(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
398 	uint16_t read(offs_t offset, uint16_t mem_mask = ~0);
399 
400 	void set_node_id_from_disk();
401 
402 protected:
403 	// device-level overrides
404 	virtual void device_start() override;
405 	virtual void device_reset() override;
406 
407 private:
408 	optional_device<omti8621_apollo_device> m_wdc;
409 	void set_node_id(uint32_t node_id);
410 	uint32_t m_node_id;
411 };
412 
413 // device type definition
DECLARE_DEVICE_TYPE(APOLLO_NI,apollo_ni)414 DECLARE_DEVICE_TYPE(APOLLO_NI, apollo_ni)
415 
416 /*----------- video/apollo.cpp -----------*/
417 
418 class apollo_graphics_15i : public device_t
419 {
420 public:
421 	apollo_graphics_15i(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
422 	~apollo_graphics_15i();
423 
424 	uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
425 
426 	// monochrome control
427 	uint8_t  apollo_mcr_r(offs_t offset);
428 	void apollo_mcr_w(offs_t offset, uint8_t data);
429 
430 	// monochrome and color memory
431 	uint16_t apollo_mem_r(offs_t offset, uint16_t mem_mask = ~0);
432 	void apollo_mem_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
433 
434 	// color control
435 	uint8_t  apollo_ccr_r(offs_t offset);
436 	void apollo_ccr_w(offs_t offset, uint8_t data);
437 
438 	uint16_t apollo_mgm_r(offs_t offset, uint16_t mem_mask = ~0);
439 	void apollo_mgm_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
440 
441 	uint16_t apollo_cgm_r(offs_t offset, uint16_t mem_mask = ~0);
442 	void apollo_cgm_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
443 
444 	void vblank_state_changed(screen_device &screen, bool vblank_state);
445 
446 	int is_mono() { return m_n_planes == 1; }
447 
448 protected:
449 	required_device<screen_device> m_screen;
450 
451 	apollo_graphics_15i(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
452 
453 	// device-level overrides
454 	virtual void device_start() override;
455 	virtual void device_reset() override;
456 	virtual void device_add_mconfig(machine_config &config) override;
457 
458 protected:
459 	class lut_fifo;
460 	class bt458;
461 
462 	const char *cr_text(offs_t offset, uint8_t data, uint8_t rw);
463 
464 	void increment_h_clock();
465 	void increment_v_clock();
466 	void increment_p_clock();
467 
468 	void log_cr1(const char * text);
469 	void set_cr1(uint8_t data);
470 	void set_cr3a(uint8_t data);
471 	void set_cr3b(uint8_t data);
472 	void set_lut_cr(uint8_t data);
473 
474 	void register_vblank_callback();
475 
476 	uint32_t set_msb0(uint32_t value, uint8_t data)
477 	{
478 		return (value & 0xffffff00) | data;
479 	}
480 	uint32_t set_lsb0(uint32_t value, uint8_t data)
481 	{
482 		return (value & 0xffff00ff) | (data << 8);
483 	}
484 	uint32_t set_msb1(uint32_t value, uint8_t data)
485 	{
486 		return (value & 0xff00ffff) | (data << 16);
487 	}
488 	uint32_t set_lsb1(uint32_t value, uint8_t data)
489 	{
490 		return (value & 0x00ffffff) | (data << 24);
491 	}
492 	uint8_t get_msb1(uint32_t value)
493 	{
494 		return (value >> 16) & 0xff;
495 	}
496 	uint8_t get_lsb1(uint32_t value)
497 	{
498 		return (value >> 24) & 0xff;
499 	}
500 
501 	void set_status_rmw();
502 	uint16_t rop(uint16_t dest_data, uint16_t src_data, uint8_t plane);
503 	void set_source_data(uint32_t offset);
504 	uint32_t get_source_data(uint8_t plane);
505 	void blt(uint32_t dest_addr, uint16_t mem_mask);
506 
507 	uint8_t get_pixel(uint32_t offset, uint16_t mask);
508 	uint8_t c4p_read_adc(uint8_t data);
509 	uint8_t c8p_read_adc(uint8_t data);
510 
511 	void screen_update1(bitmap_rgb32 &bitmap, const rectangle &cliprect);
512 protected:
513 	uint16_t m_n_planes;
514 	uint16_t m_width;
515 	uint16_t m_height;
516 	uint16_t m_buffer_width;
517 	uint16_t m_buffer_height;
518 
519 	uint8_t m_sr;
520 	uint8_t m_device_id;
521 	uint16_t m_write_enable_register;
522 	uint32_t m_rop_register;
523 	uint16_t m_diag_mem_request;
524 	uint8_t m_cr0;
525 	uint8_t m_cr1;
526 	uint8_t m_cr2;
527 	uint8_t m_cr2b;
528 	uint8_t m_cr2_s_data;
529 	uint8_t m_cr2_s_plane;
530 	uint8_t m_cr2_d_plane;
531 	uint8_t m_cr3a;
532 	uint8_t m_cr3b;
533 	uint8_t m_ad_result;
534 	uint8_t m_ad_pending;
535 
536 	uint8_t m_lut_control;
537 	uint8_t m_lut_data;
538 
539 	uint8_t m_update_flag;
540 	uint8_t m_update_pending;
541 
542 	uint8_t m_blt_cycle_count;
543 	uint32_t m_image_offset;
544 	uint32_t m_guard_latch[8];
545 
546 	int m_h_clock;
547 	int m_v_clock;
548 	int m_p_clock;
549 	int m_data_clock;
550 
551 	std::unique_ptr<uint16_t[]> m_image_memory;
552 	int m_image_plane_size;
553 	int m_image_memory_size;
554 
555 	uint32_t m_color_lookup_table[16];
556 
557 	std::unique_ptr<lut_fifo> m_lut_fifo;
558 	std::unique_ptr<bt458> m_bt458;
559 };
560 
561 
562 #define LUT_FIFO_SIZE   1024
563 
564 
565 //**************************************************************************
566 // class LUT Fifo
567 //**************************************************************************
568 
569 class apollo_graphics_15i::lut_fifo
570 {
571 public:
lut_fifo()572 	lut_fifo()
573 	{
574 		reset();
575 	}
576 
reset()577 	void reset()
578 	{
579 		m_size = LUT_FIFO_SIZE;
580 		m_get_index = 0;
581 		m_put_index = 0;
582 	}
583 
put(const uint8_t data)584 	void put(const uint8_t data)
585 	{
586 		if (!is_full())
587 		{
588 			m_data[m_put_index] = data;
589 			m_put_index = (m_put_index + 1) % m_size;
590 		}
591 	}
592 
get()593 	uint8_t get()
594 	{
595 		uint8_t data = is_empty() ? 0xff : m_data[m_get_index];
596 		m_get_index = (m_get_index + 1) % m_size;
597 		return data;
598 	}
599 
is_empty()600 	int is_empty()
601 	{
602 		return m_get_index == m_put_index;
603 	}
604 
is_full()605 	int is_full()
606 	{
607 		return ((m_put_index + 1) % m_size) == m_get_index;
608 	}
609 
610 private:
611 	uint16_t m_size;
612 	uint16_t m_get_index;
613 	uint16_t m_put_index;
614 	uint8_t m_data[LUT_FIFO_SIZE];
615 };
616 
617 //**************************************************************************
618 //  class Brooktree Bt458
619 //**************************************************************************
620 
621 class apollo_graphics_15i::bt458
622 {
623 public:
624 	bt458(running_machine &running_machine);
625 	void start();
626 	void reset();
627 	uint8_t read(uint8_t c10);
628 	void write(uint8_t data, uint8_t c10);
629 	uint32_t get_rgb(uint8_t index);
630 
631 private:
machine()632 	running_machine &machine() const
633 	{
634 		assert(m_machine != nullptr);
635 		return *m_machine;
636 	}
637 
638 	uint8_t m_color_counter;
639 	uint8_t m_red;
640 	uint8_t m_green;
641 
642 	uint8_t m_address_register;
643 	uint32_t m_color_palette_RAM[256];
644 	uint32_t m_overlay_color[4];
645 	uint8_t m_read_mask_register;
646 	uint8_t m_blink_mask_register;
647 	uint8_t m_command_register;
648 	uint8_t m_control_test_register;
649 
650 	running_machine *m_machine;
651 };
652 
DECLARE_DEVICE_TYPE(APOLLO_GRAPHICS,apollo_graphics_15i)653 DECLARE_DEVICE_TYPE(APOLLO_GRAPHICS, apollo_graphics_15i)
654 
655 
656 class apollo_graphics_19i : public apollo_graphics_15i
657 {
658 public:
659 	apollo_graphics_19i(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
660 protected:
661 	// device-level overrides
662 	virtual void device_start() override;
663 	virtual void device_reset() override;
664 	virtual void device_add_mconfig(machine_config &config) override;
665 
666 private:
667 	// internal state
668 };
669 
DECLARE_DEVICE_TYPE(APOLLO_MONO19I,apollo_graphics_19i)670 DECLARE_DEVICE_TYPE(APOLLO_MONO19I, apollo_graphics_19i)
671 
672 #ifdef APOLLO_XXL
673 
674 /*----------- machine/apollo_stdio.cpp -----------*/
675 
676 
677 //**************************************************************************
678 //  TYPE DEFINITIONS
679 //**************************************************************************
680 
681 // ======================> apollo_stdio_device
682 
683 class apollo_stdio_device: public device_t, public device_serial_interface
684 {
685 public:
686 	// construction/destruction
687 	apollo_stdio_device(const machine_config &mconfig, const char *tag,
688 			device_t *owner, uint32_t clock);
689 
690 	auto tx_cb() { return m_tx_w.bind(); }
691 
692 private:
693 	// device-level overrides
694 	virtual void device_start() override;
695 	virtual void device_reset() override;
696 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
697 
698 	// serial overrides
699 	virtual void rcv_complete() override; // Rx completed receiving byte
700 	virtual void tra_complete() override; // Tx completed sending byte
701 	virtual void tra_callback() override; // Tx send bit
702 
703 	TIMER_CALLBACK_MEMBER( poll_timer );
704 	void xmit_char(uint8_t data);
705 
706 	static const int XMIT_RING_SIZE = 64;
707 
708 	uint8_t m_xmitring[XMIT_RING_SIZE];
709 	int m_xmit_read, m_xmit_write;
710 	bool m_tx_busy;
711 
712 	emu_timer* m_poll_timer;
713 
714 	devcb_write_line m_tx_w;
715 };
716 
717 // device type definition
718 DECLARE_DEVICE_TYPE(APOLLO_STDIO, apollo_stdio_device)
719 #endif /* APOLLO_XXL */
720 
721 #endif // MAME_INCLUDES_APOLLO_H
722