1 // license:BSD-3-Clause
2 // copyright-holders:Robbbert
3 /*****************************************************************************
4  *
5  * includes/mbee.h
6  *
7  ****************************************************************************/
8 #ifndef MAME_INCLUDES_MBEE_H
9 #define MAME_INCLUDES_MBEE_H
10 
11 #pragma once
12 
13 #include "bus/centronics/ctronics.h"
14 
15 #include "cpu/z80/z80.h"
16 #include "machine/z80daisy.h"
17 
18 #include "imagedev/cassette.h"
19 #include "imagedev/floppy.h"
20 #include "imagedev/snapquik.h"
21 
22 #include "machine/8530scc.h"
23 #include "machine/buffer.h"
24 #include "machine/mc146818.h"
25 #include "machine/wd_fdc.h"
26 #include "machine/z80pio.h"
27 
28 #include "sound/spkrdev.h"
29 
30 #include "video/mc6845.h"
31 
32 #include "machine/timer.h"
33 #include "emupal.h"
34 #include "screen.h"
35 
36 
37 class mbee_state : public driver_device
38 {
39 public:
mbee_state(const machine_config & mconfig,device_type type,const char * tag)40 	mbee_state(const machine_config &mconfig, device_type type, const char *tag)
41 		: driver_device(mconfig, type, tag)
42 		, m_palette(*this, "palette")
43 		, m_maincpu(*this, "maincpu")
44 		, m_pio(*this, "z80pio")
45 		, m_cassette(*this, "cassette")
46 		, m_speaker(*this, "speaker")
47 		, m_centronics(*this, "centronics")
48 		, m_cent_data_out(*this, "cent_data_out")
49 		, m_crtc(*this, "crtc")
50 		, m_fdc(*this, "fdc")
51 		, m_floppy0(*this, "fdc:0")
52 		, m_floppy1(*this, "fdc:1")
53 		, m_rtc(*this, "rtc")
54 		, m_pak(*this, "pak")
55 		, m_telcom(*this, "telcom")
56 		, m_basic(*this, "basic")
57 		, m_io_x7(*this, "X.7")
58 		, m_io_oldkb(*this, "X.%u", 0)
59 		, m_io_newkb(*this, "Y.%u", 0)
60 		, m_io_config(*this, "CONFIG")
61 		, m_screen(*this, "screen")
62 		, m_bankr(*this, "bankr%d", 0)
63 		, m_bankw(*this, "bankw%d", 0)
64 		{ }
65 
66 	void mbee56(machine_config &config);
67 	void mbeeppc(machine_config &config);
68 	void mbee128(machine_config &config);
69 	void mbee256(machine_config &config);
70 	void mbee(machine_config &config);
71 	void mbeett(machine_config &config);
72 	void mbeeic(machine_config &config);
73 	void mbeepc(machine_config &config);
74 	void mbee128p(machine_config &config);
75 
init_mbee()76 	void init_mbee()     { m_features = 0x00; };
init_mbeett()77 	void init_mbeett()   { m_features = 0x0d; };
init_mbeeppc()78 	void init_mbeeppc()  { m_features = 0x09; };
init_mbeepp()79 	void init_mbeepp()   { m_features = 0x39; };
init_mbeeic()80 	void init_mbeeic()   { m_features = 0x01; };
init_mbee56()81 	void init_mbee56()   { m_features = 0x03; };
init_mbee128()82 	void init_mbee128()  { m_features = 0x11; };
init_mbee128p()83 	void init_mbee128p() { m_features = 0x19; };
init_mbee256()84 	void init_mbee256()  { m_features = 0x2d; };
85 
86 private:
87 	void port04_w(uint8_t data);
88 	void port06_w(uint8_t data);
89 	uint8_t port07_r();
90 	uint8_t port08_r();
91 	void port08_w(uint8_t data);
92 	void port0a_w(uint8_t data);
93 	void port0b_w(uint8_t data);
94 	uint8_t port18_r();
95 	uint8_t port1c_r();
96 	void port1c_w(uint8_t data);
97 	void port50_w(uint8_t data);
98 	uint8_t telcom_low_r();
99 	uint8_t telcom_high_r();
100 	uint8_t speed_low_r();
101 	uint8_t speed_high_r();
102 	void m6545_index_w(uint8_t data);
103 	void m6545_data_w(uint8_t data);
104 	uint8_t video_low_r(offs_t offset);
105 	uint8_t video_high_r(offs_t offset);
106 	void video_low_w(offs_t offset, uint8_t data);
107 	void video_high_w(offs_t offset, uint8_t data);
108 	void pio_port_b_w(uint8_t data);
109 	uint8_t pio_port_b_r();
110 	DECLARE_WRITE_LINE_MEMBER(pio_ardy);
111 	DECLARE_WRITE_LINE_MEMBER(crtc_vs);
112 	uint8_t fdc_status_r();
113 	void fdc_motor_w(uint8_t data);
114 	void standard_palette(palette_device &palette) const;
115 	void premium_palette(palette_device &palette) const;
116 	uint32_t screen_update_mbee(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
117 	TIMER_DEVICE_CALLBACK_MEMBER(newkb_timer);
118 	DECLARE_QUICKLOAD_LOAD_MEMBER(quickload_bee);
119 	DECLARE_QUICKLOAD_LOAD_MEMBER(quickload_bin);
120 	WRITE_LINE_MEMBER(rtc_irq_w);
121 	WRITE_LINE_MEMBER(fdc_intrq_w);
122 	WRITE_LINE_MEMBER(fdc_drq_w);
123 	MC6845_UPDATE_ROW(crtc_update_row);
124 	MC6845_ON_UPDATE_ADDR_CHANGED(crtc_update_addr);
125 	void machine_start() override;
126 	void machine_reset() override;
127 
128 	required_device<palette_device> m_palette;
129 	void mbee128_io(address_map &map);
130 	void mbee256_io(address_map &map);
131 	void mbee256_mem(address_map &map);
132 	void mbee56_io(address_map &map);
133 	void mbee56_mem(address_map &map);
134 	void mbee_io(address_map &map);
135 	void mbee_mem(address_map &map);
136 	void mbeeic_io(address_map &map);
137 	void mbeeic_mem(address_map &map);
138 	void mbeepc_io(address_map &map);
139 	void mbeepc_mem(address_map &map);
140 	void mbeeppc_io(address_map &map);
141 	void mbeeppc_mem(address_map &map);
142 	void mbeett_io(address_map &map);
143 	void mbeett_mem(address_map &map);
144 
145 	u8 m_features;
146 	u16 m_size;
147 	u32 m_ramsize;
148 	bool m_b7_rtc;
149 	bool m_b7_vs;
150 	bool m_b2;
151 	uint8_t m_framecnt;
152 	uint8_t m_08;
153 	uint8_t m_0a;
154 	uint8_t m_0b;
155 	uint8_t m_1c;
156 	uint8_t m_newkb_was_pressed[15];
157 	uint8_t m_newkb_q[20];
158 	uint8_t m_newkb_q_pos;
159 	uint8_t m_sy6545_reg[32];
160 	uint8_t m_sy6545_ind;
161 	uint8_t m_fdc_rq;
162 	uint8_t m_bank_array[33];
163 	std::unique_ptr<u8[]> m_dummy; // black hole for writes to rom
164 	std::unique_ptr<u8[]> m_ram;   // main banked-switch ram, 128/256/pp
165 	std::unique_ptr<u8[]> m_vram;  // video ram, all models
166 	std::unique_ptr<u8[]> m_pram;  // pcg ram, all models
167 	std::unique_ptr<u8[]> m_cram;  // colour ram, all except mbee
168 	std::unique_ptr<u8[]> m_aram;  // attribute ram, ppc/128/256/pp/tt
169 	void setup_banks(uint8_t data, bool first_time, uint8_t b_mask);
170 	void oldkb_scan(uint16_t param);
171 	void oldkb_matrix_r(uint16_t offs);
172 	required_device<z80_device> m_maincpu;
173 	required_device<z80pio_device> m_pio;
174 	required_device<cassette_image_device> m_cassette;
175 	required_device<speaker_sound_device> m_speaker;
176 	required_device<centronics_device> m_centronics;
177 	required_device<output_latch_device> m_cent_data_out;
178 	required_device<mc6845_device> m_crtc;
179 	optional_device<wd2793_device> m_fdc;
180 	optional_device<floppy_connector> m_floppy0;
181 	optional_device<floppy_connector> m_floppy1;
182 	optional_device<mc146818_device> m_rtc;
183 	optional_memory_bank m_pak;
184 	optional_memory_bank m_telcom;
185 	optional_memory_bank m_basic;
186 	optional_ioport m_io_x7;
187 	optional_ioport_array<8> m_io_oldkb;
188 	optional_ioport_array<15> m_io_newkb;
189 	required_ioport m_io_config;
190 	required_device<screen_device> m_screen;
191 	optional_memory_bank_array<16> m_bankr;
192 	optional_memory_bank_array<16> m_bankw;
193 };
194 
195 #endif // MAME_INCLUDES_MBEE_H
196