1 // license:GPL-2.0+
2 // copyright-holders:Raphael Nabet, Robbbert
3 #ifndef MAME_INCLUDES_APEXC
4 #define MAME_INCLUDES_APEXC
5 
6 #pragma once
7 
8 #include "cpu/apexc/apexc.h"
9 #include "machine/apexc.h"
10 #include "emupal.h"
11 #include "screen.h"
12 
13 class apexc_state : public driver_device
14 {
15 public:
apexc_state(const machine_config & mconfig,device_type type,const char * tag)16 	apexc_state(const machine_config &mconfig, device_type type, const char *tag)
17 		: driver_device(mconfig, type, tag)
18 		, m_maincpu(*this, "maincpu")
19 		, m_screen(*this, "screen")
20 		, m_gfxdecode(*this, "gfxdecode")
21 		, m_palette(*this, "palette")
22 		, m_chargen_region(*this, "chargen")
23 		, m_cylinder(*this, "cylinder")
24 		, m_tape_puncher(*this, "tape_puncher")
25 		, m_tape_reader(*this, "tape_reader")
26 		, m_panel_port(*this, "panel")
27 		, m_data_port(*this, "data")
28 		, m_input_timer(nullptr)
29 	{ }
30 
31 	void init_apexc();
32 
33 	void apexc(machine_config &config);
34 
35 protected:
36 	virtual void machine_start() override;
37 	virtual void video_start() override;
38 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
39 
40 	void check_inputs();
41 
42 private:
43 	void apexc_palette(palette_device &palette) const;
44 	uint32_t screen_update_apexc(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
45 	INTERRUPT_GEN_MEMBER(apexc_interrupt);
46 	void tape_write(uint8_t data);
47 	void draw_led(bitmap_ind16 &bitmap, int x, int y, int state);
48 	void draw_char(bitmap_ind16 &bitmap, char character, int x, int y, int color);
49 	void draw_string(bitmap_ind16 &bitmap, const char *buf, int x, int y, int color);
50 	void teletyper_init();
51 	void teletyper_linefeed();
52 	void teletyper_putchar(int character);
53 
54 	void mem(address_map &map);
55 
56 	uint32_t m_panel_data_reg;    /* value of a data register on the control panel which can
57 	                            be edited - the existence of this register is a personnal
58 	                            guess */
59 
60 	std::unique_ptr<bitmap_ind16> m_bitmap;
61 
62 	uint32_t m_old_edit_keys;
63 	int m_old_control_keys;
64 
65 	int m_letters;
66 	int m_pos;
67 
68 	required_device<apexc_cpu_device> m_maincpu;
69 	required_device<screen_device> m_screen;
70 	required_device<gfxdecode_device> m_gfxdecode;
71 	required_device<palette_device> m_palette;
72 	required_memory_region m_chargen_region;
73 	required_device<apexc_cylinder_image_device> m_cylinder;
74 	required_device<apexc_tape_puncher_image_device> m_tape_puncher;
75 	required_device<apexc_tape_reader_image_device> m_tape_reader;
76 	required_ioport m_panel_port;
77 	required_ioport m_data_port;
78 
79 	emu_timer *m_input_timer;
80 
81 	static const device_timer_id TIMER_POLL_INPUTS;
82 	static const rgb_t palette_table[4];
83 };
84 
85 #endif // MAME_INCLUDES_APEXC
86