1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /*****************************************************************************
4  *
5  * includes/abc80.h
6  *
7  ****************************************************************************/
8 
9 #ifndef MAME_INCLUDES_ABC80_H
10 #define MAME_INCLUDES_ABC80_H
11 
12 #pragma once
13 
14 #include "bus/abcbus/abcbus.h"
15 #include "bus/rs232/rs232.h"
16 #include "cpu/z80/z80.h"
17 #include "machine/z80daisy.h"
18 #include "imagedev/cassette.h"
19 #include "imagedev/snapquik.h"
20 #include "machine/abc80kb.h"
21 #include "machine/keyboard.h"
22 #include "machine/ram.h"
23 #include "machine/z80pio.h"
24 #include "sound/sn76477.h"
25 #include "emupal.h"
26 
27 #define ABC80_HTOTAL    384
28 #define ABC80_HBEND     30
29 #define ABC80_HBSTART   384
30 #define ABC80_VTOTAL    313
31 #define ABC80_VBEND     15
32 #define ABC80_VBSTART   313
33 
34 #define ABC80_K5_HSYNC          0x01
35 #define ABC80_K5_DH             0x02
36 #define ABC80_K5_LINE_END       0x04
37 #define ABC80_K5_ROW_START      0x08
38 
39 #define ABC80_K2_VSYNC          0x01
40 #define ABC80_K2_DV             0x02
41 #define ABC80_K2_FRAME_END      0x04
42 #define ABC80_K2_FRAME_RESET    0x08
43 
44 #define ABC80_J3_BLANK          0x01
45 #define ABC80_J3_TEXT           0x02
46 #define ABC80_J3_GRAPHICS       0x04
47 #define ABC80_J3_VERSAL         0x08
48 
49 #define ABC80_E7_VIDEO_RAM      0x01
50 #define ABC80_E7_INT_RAM        0x02
51 #define ABC80_E7_31K_EXT_RAM    0x04
52 #define ABC80_E7_16K_INT_RAM    0x08
53 
54 #define ABC80_CHAR_CURSOR       0x80
55 
56 #define SCREEN_TAG          "screen"
57 #define Z80_TAG             "ab67"
58 #define Z80PIO_TAG          "cd67"
59 #define SN76477_TAG         "g8"
60 #define RS232_TAG           "ser"
61 #define CASSETTE_TAG        "cassette"
62 #define KEYBOARD_TAG        "keyboard"
63 #define TIMER_CASSETTE_TAG  "cass"
64 
65 class abc80_state : public driver_device
66 {
67 public:
abc80_state(const machine_config & mconfig,device_type type,const char * tag)68 	abc80_state(const machine_config &mconfig, device_type type, const char *tag) :
69 		driver_device(mconfig, type, tag),
70 		m_maincpu(*this, Z80_TAG),
71 		m_pio(*this, Z80PIO_TAG),
72 		m_csg(*this, SN76477_TAG),
73 		m_cassette(*this, "cassette"),
74 		m_bus(*this, "bus"),
75 		m_kb(*this, ABC80_KEYBOARD_TAG),
76 		m_ram(*this, RAM_TAG),
77 		m_rs232(*this, RS232_TAG),
78 		m_palette(*this, "palette"),
79 		m_screen(*this, SCREEN_TAG),
80 		m_rom(*this, Z80_TAG),
81 		m_mmu_rom(*this, "mmu"),
82 		m_char_rom(*this, "chargen"),
83 		m_hsync_prom(*this, "hsync"),
84 		m_vsync_prom(*this, "vsync"),
85 		m_line_prom(*this, "line"),
86 		m_attr_prom(*this, "attr"),
87 		m_video_ram(*this, "video_ram"),
88 		m_motor(false),
89 		m_tape_in(1),
90 		m_tape_in_latch(1)
91 	{ }
92 
imperfect_features()93 	static constexpr feature_type imperfect_features() { return feature::KEYBOARD; }
94 
95 	required_device<z80_device> m_maincpu;
96 	required_device<z80pio_device> m_pio;
97 	required_device<sn76477_device> m_csg;
98 	required_device<cassette_image_device> m_cassette;
99 	required_device<abcbus_slot_device> m_bus;
100 	required_device<abc80_keyboard_device> m_kb;
101 	required_device<ram_device> m_ram;
102 	required_device<rs232_port_device> m_rs232;
103 	required_device<palette_device> m_palette;
104 	required_device<screen_device> m_screen;
105 	required_memory_region m_rom;
106 	required_memory_region m_mmu_rom;
107 	required_memory_region m_char_rom;
108 	required_memory_region m_hsync_prom;
109 	required_memory_region m_vsync_prom;
110 	required_memory_region m_line_prom;
111 	required_memory_region m_attr_prom;
112 	optional_shared_ptr<u8> m_video_ram;
113 
114 	enum
115 	{
116 		TIMER_ID_SCANLINE,
117 		TIMER_ID_CASSETTE,
118 		TIMER_ID_BLINK,
119 		TIMER_ID_VSYNC_ON,
120 		TIMER_ID_VSYNC_OFF,
121 		TIMER_ID_FAKE_KEYBOARD_CLEAR
122 	};
123 
124 	enum
125 	{
126 		BOFA = 0xfe1c,
127 		EOFA = 0xfe1e,
128 		HEAD = 0xfe20
129 	};
130 
131 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
132 
133 	virtual void machine_start() override;
134 
135 	virtual void video_start() override;
136 	u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
137 
138 	void draw_scanline(bitmap_rgb32 &bitmap, int y);
139 
140 	u8 read(offs_t offset);
141 	void write(offs_t offset, u8 data);
142 
143 	DECLARE_WRITE_LINE_MEMBER( vco_voltage_w );
144 
145 	u8 pio_pa_r();
146 	u8 pio_pb_r();
147 	void pio_pb_w(u8 data);
148 
149 	DECLARE_WRITE_LINE_MEMBER( keydown_w );
150 	void kbd_w(u8 data);
151 	void csg_w(u8 data);
152 
153 	DECLARE_QUICKLOAD_LOAD_MEMBER(quickload_cb);
154 
155 	enum
156 	{
157 		MMU_XM      = 0x01,
158 		MMU_ROM     = 0x02,
159 		MMU_VRAMS   = 0x04,
160 		MMU_RAM     = 0x08
161 	};
162 
163 	// keyboard state
164 	int m_key_data;
165 	int m_key_strobe;
166 	int m_pio_astb;
167 
168 	// video state
169 	bitmap_rgb32 m_bitmap;
170 	u8 m_latch;
171 	int m_blink;
172 	int m_c;
173 	int m_r;
174 	int m_mode;
175 
176 	// cassette state
177 	bool m_motor;
178 	int m_tape_in;
179 	int m_tape_in_latch;
180 
181 	// timers
182 	emu_timer *m_scanline_timer;
183 	emu_timer *m_cassette_timer;
184 	emu_timer *m_blink_timer;
185 	emu_timer *m_vsync_on_timer;
186 	emu_timer *m_vsync_off_timer;
187 	void abc80(machine_config &config);
188 	void abc80_video(machine_config &config);
189 	void abc80_io(address_map &map);
190 	void abc80_mem(address_map &map);
191 };
192 
193 #endif // MAME_INCLUDES_ABC80_H
194