1 // license:BSD-3-Clause
2 // copyright-holders:Antoine Mine
3 /**********************************************************************
4 
5   Copyright (C) Antoine Mine' 2006
6 
7   Thomson 8-bit computers
8 
9 **********************************************************************/
10 
11 #ifndef MAME_INCLUDES_THOMSON_H
12 #define MAME_INCLUDES_THOMSON_H
13 
14 #pragma once
15 
16 #include "cpu/m6809/m6809.h"
17 #include "formats/thom_cas.h"
18 #include "formats/thom_dsk.h"
19 #include "imagedev/cassette.h"
20 #include "imagedev/floppy.h"
21 #include "machine/6821pia.h"
22 #include "machine/6850acia.h"
23 #include "machine/input_merger.h"
24 #include "machine/mc6843.h"
25 #include "machine/mc6846.h"
26 #include "machine/mc6846.h"
27 #include "machine/mc6854.h"
28 #include "machine/mos6551.h"
29 #include "machine/ram.h"
30 #include "machine/thomflop.h"
31 #include "machine/wd_fdc.h"
32 #include "sound/dac.h"
33 #include "sound/mea8000.h"
34 
35 #include "bus/centronics/ctronics.h"
36 #include "bus/generic/slot.h"
37 #include "bus/generic/carts.h"
38 #include "bus/rs232/rs232.h"
39 
40 #include "emupal.h"
41 #include "screen.h"
42 
43 
44 /* 6821 PIAs */
45 #define THOM_PIA_SYS    "pia_0"  /* system PIA */
46 #define THOM_PIA_GAME   "pia_1"  /* music & game PIA (joypad + sound) */
47 #define THOM_PIA_IO     "pia_2"  /* CC 90-232 I/O extension (parallel & RS-232) */
48 #define THOM_PIA_MODEM  "pia_3"  /* MD 90-120 MODEM extension */
49 
50 /* sound ports */
51 #define THOM_SOUND_BUZ    0 /* 1-bit buzzer */
52 #define THOM_SOUND_GAME   1 /* 6-bit game port DAC */
53 #define THOM_SOUND_SPEECH 2 /* speech synthesis */
54 
55 /* bank-switching */
56 #define THOM_CART_BANK  "bank2" /* cartridge ROM */
57 #define THOM_RAM_BANK   "bank3" /* data RAM */
58 #define THOM_FLOP_BANK  "bank4" /* external floppy controller ROM */
59 #define THOM_BASE_BANK  "bank5" /* system RAM */
60 
61 /* bank-switching */
62 #define TO8_SYS_LO      "bank5" /* system RAM low 2 Kb */
63 #define TO8_SYS_HI      "bank6" /* system RAM hi 2 Kb */
64 #define TO8_DATA_LO     "bank7" /* data RAM low 2 Kb */
65 #define TO8_DATA_HI     "bank8" /* data RAM hi 2 Kb */
66 #define TO8_BIOS_BANK   "bank9" /* BIOS ROM */
67 #define MO6_CART_LO     "bank10"
68 #define MO6_CART_HI     "bank11"
69 
70 
71 /* original screen dimension (may be different from emulated screen!) */
72 #define THOM_ACTIVE_WIDTH  320
73 #define THOM_BORDER_WIDTH   56
74 #define THOM_ACTIVE_HEIGHT 200
75 #define THOM_BORDER_HEIGHT  47
76 #define THOM_TOTAL_WIDTH   432
77 #define THOM_TOTAL_HEIGHT  294
78 
79 /* Emulated screen dimension may be doubled to allow hi-res 640x200 mode.
80    Emulated screen can have smaller borders.
81  */
82 
83 /* maximum number of video pages:
84    1 for TO7 generation (including MO5)
85    4 for TO8 generation (including TO9, MO6)
86  */
87 #define THOM_NB_PAGES 4
88 
89 /* page 0 is banked */
90 #define THOM_VRAM_BANK "bank1"
91 
92 
93 struct thom_vsignal {
94 	unsigned count;  /* pixel counter */
95 	unsigned init;   /* 1 -> active vertical windos, 0 -> border/VBLANK */
96 	unsigned inil;   /* 1 -> active horizontal window, 0 -> border/HBLANK */
97 	unsigned lt3;    /* bit 3 of us counter */
98 	unsigned line;   /* line counter */
99 };
100 
101 
102 class thomson_state : public driver_device
103 {
104 public:
thomson_state(const machine_config & mconfig,device_type type,const char * tag)105 	thomson_state(const machine_config &mconfig, device_type type, const char *tag) :
106 		driver_device(mconfig, type, tag),
107 		m_mc6854(*this, "mc6854"),
108 		m_maincpu(*this, "maincpu"),
109 		m_cassette(*this, "cassette"),
110 		m_dac(*this, "dac"),
111 		m_centronics(*this, "centronics"),
112 		m_cent_data_out(*this, "cent_data_out"),
113 		m_pia_sys(*this, THOM_PIA_SYS),
114 		m_pia_game(*this, THOM_PIA_GAME),
115 		m_acia(*this, "acia6850"),
116 		m_mea8000(*this, "mea8000"),
117 		m_ram(*this, RAM_TAG),
118 		m_mc6846(*this, "mc6846"),
119 		m_mc6843(*this, "mc6843"),
120 		m_wd2793_fdc(*this, "wd2793"),
121 		m_screen(*this, "screen"),
122 		m_mainirq(*this, "mainirq"),
123 		m_mainfirq(*this, "mainfirq"),
124 		m_io_game_port_directions(*this, "game_port_directions"),
125 		m_io_game_port_buttons(*this, "game_port_buttons"),
126 		m_io_mouse_x(*this, "mouse_x"),
127 		m_io_mouse_y(*this, "mouse_y"),
128 		m_io_mouse_button(*this, "mouse_button"),
129 		m_io_lightpen_x(*this, "lightpen_x"),
130 		m_io_lightpen_y(*this, "lightpen_y"),
131 		m_io_lightpen_button(*this, "lightpen_button"),
132 		m_io_config(*this, "config"),
133 		m_io_vconfig(*this, "vconfig"),
134 		m_io_mconfig(*this, "mconfig"),
135 		m_io_fconfig(*this, "fconfig"),
136 		m_io_keyboard(*this, "keyboard.%u", 0),
137 		m_vrambank(*this, THOM_VRAM_BANK),
138 		m_cartbank(*this, THOM_CART_BANK),
139 		m_rambank(*this, THOM_RAM_BANK),
140 		m_flopbank(*this, THOM_FLOP_BANK),
141 		m_basebank(*this, THOM_BASE_BANK),
142 		m_syslobank(*this, TO8_SYS_LO),
143 		m_syshibank(*this, TO8_SYS_HI),
144 		m_datalobank(*this, TO8_DATA_LO),
145 		m_datahibank(*this, TO8_DATA_HI),
146 		m_biosbank(*this, TO8_BIOS_BANK),
147 		m_cartlobank(*this, MO6_CART_LO),
148 		m_carthibank(*this, MO6_CART_HI),
149 		m_cart_rom(*this, "cartridge"),
150 		m_to7qdd(*this, "to7qdd"),
151 		m_thmfc(*this, "thmfc"),
152 		m_floppy_led(*this, "floppy"),
153 		m_floppy_image(*this, "floppy%u", 0U),
154 		m_caps_led(*this, "led0")
155 	{
156 	}
157 
158 	void to9(machine_config &config);
159 	void to7_base(machine_config &config);
160 	void to7(machine_config &config);
161 	void mo5e(machine_config &config);
162 	void to770a(machine_config &config);
163 	void t9000(machine_config &config);
164 	void to8(machine_config &config);
165 	void pro128(machine_config &config);
166 	void mo6(machine_config &config);
167 	void mo5(machine_config &config);
168 	void to9p(machine_config &config);
169 	void mo5nr(machine_config &config);
170 	void to770(machine_config &config);
171 	void to8d(machine_config &config);
172 
173 	void to770_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
174 	void mo5_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
175 	void mo5alt_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
176 	void to9_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
177 	void bitmap4_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
178 	void bitmap4alt_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
179 	void bitmap4althalf_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
180 	void bitmap16_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
181 	void mode80_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
182 	void mode80_to9_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
183 	void page1_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
184 	void page2_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
185 	void overlay_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
186 	void overlayhalf_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
187 	void overlay3_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
188 	void bitmap16alt_scandraw_16( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
189 	void to770_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
190 	void mo5_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
191 	void mo5alt_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
192 	void to9_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
193 	void bitmap4_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
194 	void bitmap4alt_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
195 	void bitmap4althalf_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
196 	void bitmap16_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
197 	void mode80_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
198 	void mode80_to9_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
199 	void page1_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
200 	void page2_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
201 	void overlay_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
202 	void overlayhalf_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
203 	void overlay3_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
204 	void bitmap16alt_scandraw_8( uint8_t* vram, uint16_t* dst, uint16_t* pal, int org, int len );
205 
206 private:
207 	DECLARE_FLOPPY_FORMATS(cd90_640_formats);
208 
209 	DECLARE_DEVICE_IMAGE_LOAD_MEMBER( to7_cartridge );
210 	DECLARE_DEVICE_IMAGE_LOAD_MEMBER( mo5_cartridge );
211 
212 	DECLARE_WRITE_LINE_MEMBER( to7_set_cassette_motor );
213 	DECLARE_WRITE_LINE_MEMBER( mo5_set_cassette_motor );
214 	DECLARE_WRITE_LINE_MEMBER( thom_dev_irq_0 );
215 	void to7_cartridge_w(offs_t offset, uint8_t data);
216 	uint8_t to7_cartridge_r(offs_t offset);
217 	void to7_timer_port_out(uint8_t data);
218 	uint8_t to7_timer_port_in();
219 	DECLARE_WRITE_LINE_MEMBER( to7_set_cassette );
220 	DECLARE_WRITE_LINE_MEMBER( to7_sys_cb2_out );
221 	void to7_sys_portb_out(uint8_t data);
222 	uint8_t to7_sys_porta_in();
223 	uint8_t to7_sys_portb_in();
224 	DECLARE_WRITE_LINE_MEMBER( to7_modem_cb );
225 	DECLARE_WRITE_LINE_MEMBER( to7_modem_tx_w);
226 	DECLARE_WRITE_LINE_MEMBER( write_acia_clock );
227 	uint8_t to7_modem_mea8000_r(offs_t offset);
228 	void to7_modem_mea8000_w(offs_t offset, uint8_t data);
229 	uint8_t to7_game_porta_in();
230 	uint8_t to7_game_portb_in();
231 	void to7_game_portb_out(uint8_t data);
232 	DECLARE_WRITE_LINE_MEMBER( to7_game_cb2_out );
233 	TIMER_CALLBACK_MEMBER( to7_game_update_cb );
234 	uint8_t to7_midi_r();
235 	void to7_midi_w(uint8_t data);
236 	DECLARE_MACHINE_RESET( to7 );
237 	DECLARE_MACHINE_START( to7 );
238 	DECLARE_WRITE_LINE_MEMBER( to770_sys_cb2_out );
239 	uint8_t to770_sys_porta_in();
240 	void to7_update_cart_bank_postload();
241 	void to770_update_ram_bank_postload();
242 	void to770_sys_portb_out(uint8_t data);
243 	void to770_timer_port_out(uint8_t data);
244 	uint8_t to770_gatearray_r(offs_t offset);
245 	void to770_gatearray_w(offs_t offset, uint8_t data);
246 	DECLARE_MACHINE_RESET( to770 );
247 	DECLARE_MACHINE_START( to770 );
248 	void to7_lightpen_cb( int step );
249 	void mo5_lightpen_cb( int step );
250 	TIMER_CALLBACK_MEMBER( mo5_periodic_cb );
251 	void mo5_sys_porta_out(uint8_t data);
252 	uint8_t mo5_sys_porta_in();
253 	uint8_t mo5_sys_portb_in();
254 	uint8_t mo5_gatearray_r(offs_t offset);
255 	void mo5_gatearray_w(offs_t offset, uint8_t data);
256 	void mo5_update_cart_bank_postload();
257 	void mo5_cartridge_w(offs_t offset, uint8_t data);
258 	uint8_t mo5_cartridge_r(offs_t offset);
259 	void mo5_ext_w(uint8_t data);
260 	DECLARE_MACHINE_RESET( mo5 );
261 	DECLARE_MACHINE_START( mo5 );
262 	void to9_ieee_w(offs_t offset, uint8_t data);
263 	uint8_t to9_ieee_r(offs_t offset);
264 	uint8_t to9_gatearray_r(offs_t offset);
265 	void to9_gatearray_w(offs_t offset, uint8_t data);
266 	uint8_t to9_vreg_r(offs_t offset);
267 	void to9_vreg_w(offs_t offset, uint8_t data);
268 	void to9_update_cart_bank_postload();
269 	void to9_cartridge_w(offs_t offset, uint8_t data);
270 	uint8_t to9_cartridge_r(offs_t offset);
271 	void to9_update_ram_bank_postload();
272 	uint8_t to9_kbd_r(offs_t offset);
273 	void to9_kbd_w(offs_t offset, uint8_t data);
274 	TIMER_CALLBACK_MEMBER( to9_kbd_timer_cb );
275 	uint8_t to9_sys_porta_in();
276 	void to9_sys_porta_out(uint8_t data);
277 	void to9_sys_portb_out(uint8_t data);
278 	void to9_timer_port_out(uint8_t data);
279 	DECLARE_MACHINE_RESET( to9 );
280 	DECLARE_MACHINE_START( to9 );
281 	TIMER_CALLBACK_MEMBER( to8_kbd_timer_cb );
282 	void to8_update_floppy_bank_postload();
283 	void to8_update_ram_bank_postload();
284 	void to8_update_cart_bank_postload();
285 	void to8_cartridge_w(offs_t offset, uint8_t data);
286 	uint8_t to8_cartridge_r(offs_t offset);
287 	uint8_t to8_floppy_r(offs_t offset);
288 	void to8_floppy_w(offs_t offset, uint8_t data);
289 	uint8_t to8_gatearray_r(offs_t offset);
290 	void to8_gatearray_w(offs_t offset, uint8_t data);
291 	uint8_t to8_vreg_r(offs_t offset);
292 	void to8_vreg_w(offs_t offset, uint8_t data);
293 	uint8_t to8_sys_porta_in();
294 	void to8_sys_portb_out(uint8_t data);
295 	uint8_t to8_timer_port_in();
296 	void to8_timer_port_out(uint8_t data);
297 	DECLARE_WRITE_LINE_MEMBER( to8_timer_cp2_out );
298 	void to8_lightpen_cb( int step );
299 	DECLARE_MACHINE_RESET( to8 );
300 	DECLARE_MACHINE_START( to8 );
301 	uint8_t to9p_timer_port_in();
302 	void to9p_timer_port_out(uint8_t data);
303 	DECLARE_MACHINE_RESET( to9p );
304 	DECLARE_MACHINE_START( to9p );
305 	void mo6_update_ram_bank_postload();
306 	void mo6_update_cart_bank_postload();
307 	void mo6_cartridge_w(offs_t offset, uint8_t data);
308 	uint8_t mo6_cartridge_r(offs_t offset);
309 	void mo6_ext_w(uint8_t data);
310 	DECLARE_WRITE_LINE_MEMBER( mo6_centronics_busy );
311 	void mo6_game_porta_out(uint8_t data);
312 	DECLARE_WRITE_LINE_MEMBER( mo6_game_cb2_out );
313 	TIMER_CALLBACK_MEMBER( mo6_game_update_cb );
314 	uint8_t mo6_sys_porta_in();
315 	uint8_t mo6_sys_portb_in();
316 	void mo6_sys_porta_out(uint8_t data);
317 	DECLARE_WRITE_LINE_MEMBER( mo6_sys_cb2_out );
318 	uint8_t mo6_gatearray_r(offs_t offset);
319 	void mo6_gatearray_w(offs_t offset, uint8_t data);
320 	uint8_t mo6_vreg_r(offs_t offset);
321 	void mo6_vreg_w(offs_t offset, uint8_t data);
322 	DECLARE_MACHINE_RESET( mo6 );
323 	DECLARE_MACHINE_START( mo6 );
324 	uint8_t mo5nr_net_r(offs_t offset);
325 	void mo5nr_net_w(offs_t offset, uint8_t data);
326 	uint8_t mo5nr_prn_r();
327 	void mo5nr_prn_w(uint8_t data);
328 	uint8_t mo5nr_sys_portb_in();
329 	void mo5nr_sys_porta_out(uint8_t data);
330 	DECLARE_MACHINE_RESET( mo5nr );
331 	DECLARE_MACHINE_START( mo5nr );
332 
333 	TIMER_CALLBACK_MEMBER( thom_lightpen_step );
334 	TIMER_CALLBACK_MEMBER( thom_scanline_start );
335 	uint32_t screen_update_thom(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
336 	void to7_vram_w(offs_t offset, uint8_t data);
337 	void to770_vram_w(offs_t offset, uint8_t data);
338 	void to8_sys_lo_w(offs_t offset, uint8_t data);
339 	void to8_sys_hi_w(offs_t offset, uint8_t data);
340 	void to8_data_lo_w(offs_t offset, uint8_t data);
341 	void to8_data_hi_w(offs_t offset, uint8_t data);
342 	void to8_vcart_w(offs_t offset, uint8_t data);
343 	void mo6_vcart_lo_w(offs_t offset, uint8_t data);
344 	void mo6_vcart_hi_w(offs_t offset, uint8_t data);
345 	TIMER_CALLBACK_MEMBER( thom_set_init );
346 
347 	DECLARE_WRITE_LINE_MEMBER(thom_vblank);
348 	DECLARE_VIDEO_START( thom );
349 
350 	uint8_t to7_5p14_r(offs_t offset);
351 	void to7_5p14_w(offs_t offset, uint8_t data);
352 	uint8_t to7_5p14sd_r(offs_t offset);
353 	void to7_5p14sd_w(offs_t offset, uint8_t data);
354 	TIMER_CALLBACK_MEMBER( ans4 );
355 	TIMER_CALLBACK_MEMBER( ans3 );
356 	TIMER_CALLBACK_MEMBER( ans2 );
357 	TIMER_CALLBACK_MEMBER( ans );
358 	uint8_t to7_network_r(offs_t offset);
359 	void to7_network_w(offs_t offset, uint8_t data);
360 	uint8_t to7_floppy_r(offs_t offset);
361 	void to7_floppy_w(offs_t offset, uint8_t data);
362 	uint8_t to9_floppy_r(offs_t offset);
363 	void to9_floppy_w(offs_t offset, uint8_t data);
364 	WRITE_LINE_MEMBER( fdc_index_0_w);
365 	WRITE_LINE_MEMBER( fdc_index_1_w);
366 	WRITE_LINE_MEMBER( fdc_index_2_w);
367 	WRITE_LINE_MEMBER( fdc_index_3_w);
368 	void thomson_index_callback(int index, int state);
369 	void thom_palette(palette_device &palette);
370 	void mo5_palette(palette_device &palette);
371 
372 	optional_device<mc6854_device> m_mc6854;
373 
374 	DECLARE_WRITE_LINE_MEMBER(write_centronics_busy);
375 
376 	int m_centronics_busy;
377 	int m_centronics_perror;
378 
379 	void to7_network_got_frame(uint8_t *data, int length);
380 
381 	void mo5_map(address_map &map);
382 	void mo5nr_map(address_map &map);
383 	void mo6_map(address_map &map);
384 	void to7_map(address_map &map);
385 	void to770_map(address_map &map);
386 	void to8_map(address_map &map);
387 	void to9_map(address_map &map);
388 	void to9p_map(address_map &map);
389 
390 	required_device<cpu_device> m_maincpu;
391 	required_device<cassette_image_device> m_cassette;
392 	required_device<dac_byte_interface> m_dac;
393 	optional_device<centronics_device> m_centronics;
394 	optional_device<output_latch_device> m_cent_data_out;
395 	required_device<pia6821_device> m_pia_sys;
396 	required_device<pia6821_device> m_pia_game;
397 	required_device<acia6850_device> m_acia;
398 	required_device<mea8000_device> m_mea8000;
399 	required_device<ram_device> m_ram;
400 	optional_device<mc6846_device> m_mc6846;
401 	optional_device<mc6843_device> m_mc6843;
402 	required_device<wd2793_device> m_wd2793_fdc;
403 	required_device<screen_device> m_screen;
404 	required_device<input_merger_device> m_mainirq;
405 	required_device<input_merger_device> m_mainfirq;
406 	required_ioport m_io_game_port_directions;
407 	required_ioport m_io_game_port_buttons;
408 	required_ioport m_io_mouse_x;
409 	required_ioport m_io_mouse_y;
410 	required_ioport m_io_mouse_button;
411 	required_ioport m_io_lightpen_x;
412 	required_ioport m_io_lightpen_y;
413 	required_ioport m_io_lightpen_button;
414 	required_ioport m_io_config;
415 	required_ioport m_io_vconfig;
416 	optional_ioport m_io_mconfig;
417 	required_ioport m_io_fconfig;
418 	required_ioport_array<10> m_io_keyboard;
419 	required_memory_bank m_vrambank;
420 	optional_memory_bank m_cartbank;
421 	optional_memory_bank m_rambank;
422 	required_memory_bank m_flopbank;
423 	required_memory_bank m_basebank;
424 	required_memory_bank m_syslobank;
425 	optional_memory_bank m_syshibank;
426 	optional_memory_bank m_datalobank;
427 	optional_memory_bank m_datahibank;
428 	optional_memory_bank m_biosbank;
429 	optional_memory_bank m_cartlobank;
430 	optional_memory_bank m_carthibank;
431 	required_region_ptr<uint8_t> m_cart_rom;
432 
433 	required_device<cq90_028_device> m_to7qdd;
434 	required_device<thmfc1_device> m_thmfc;
435 	output_finder<> m_floppy_led;
436 	required_device_array<legacy_floppy_image_device, 4> m_floppy_image;
437 
438 	output_finder<> m_caps_led;
439 
440 	/* bank logging and optimisations */
441 	int m_old_cart_bank;
442 	int m_old_cart_bank_was_read_only;
443 	int m_old_ram_bank;
444 	int m_old_floppy_bank;
445 	/* buffer storing demodulated bits, only for k7 and with speed hack */
446 	uint32_t m_to7_k7_bitsize;
447 	uint8_t* m_to7_k7_bits;
448 	/* ------------ cartridge ------------ */
449 	uint8_t m_thom_cart_nb_banks; /* number of 16 KB banks (up to 4) */
450 	uint8_t m_thom_cart_bank;     /* current bank */
451 	uint8_t m_to7_lightpen_step;
452 	uint8_t m_to7_lightpen;
453 	uint8_t m_to7_modem_tx;
454 	/* calls to7_game_update_cb periodically */
455 	emu_timer* m_to7_game_timer;
456 	uint8_t m_to7_game_sound;
457 	uint8_t m_to7_game_mute;
458 	emu_timer* m_mo5_periodic_timer;
459 	uint8_t m_mo5_reg_cart; /* 0xa7cb bank switch */
460 	uint8_t m_to9_palette_data[32];
461 	uint8_t m_to9_palette_idx;
462 	uint8_t m_to9_soft_bank;
463 	uint8_t  m_to9_kbd_parity;  /* 0=even, 1=odd, 2=no parity */
464 	uint8_t  m_to9_kbd_intr;    /* interrupt mode */
465 	uint8_t  m_to9_kbd_in;      /* data from keyboard */
466 	uint8_t  m_to9_kbd_status;  /* status */
467 	uint8_t  m_to9_kbd_overrun; /* character lost */
468 	uint8_t  m_to9_kbd_periph;     /* peripheral mode */
469 	uint8_t  m_to9_kbd_byte_count; /* byte-count in peripheral mode */
470 	uint16_t m_to9_mouse_x;
471 	uint16_t m_to9_mouse_y;
472 	uint8_t  m_to9_kbd_last_key;  /* for key repetition */
473 	uint16_t m_to9_kbd_key_count;
474 	uint8_t  m_to9_kbd_caps;  /* caps-lock */
475 	uint8_t  m_to9_kbd_pad;   /* keypad outputs special codes */
476 	emu_timer* m_to9_kbd_timer;
477 	uint8_t  m_to8_kbd_ack;       /* 1 = cpu inits / accepts transfers */
478 	uint16_t m_to8_kbd_data;      /* data to transmit */
479 	uint16_t m_to8_kbd_step;      /* transmission automaton state */
480 	uint8_t  m_to8_kbd_last_key;  /* last key (for repetition) */
481 	uint32_t m_to8_kbd_key_count; /* keypress time (for repetition)  */
482 	uint8_t  m_to8_kbd_caps;      /* caps lock */
483 	emu_timer* m_to8_kbd_timer;   /* bit-send */
484 	emu_timer* m_to8_kbd_signal;  /* signal from CPU */
485 	uint8_t m_to8_data_vpage;
486 	uint8_t m_to8_cart_vpage;
487 	uint8_t  m_to8_reg_ram;
488 	uint8_t  m_to8_reg_cart;
489 	uint8_t  m_to8_reg_sys1;
490 	uint8_t  m_to8_reg_sys2;
491 	uint8_t  m_to8_lightpen_intr;
492 	uint8_t  m_to8_soft_select;
493 	uint8_t  m_to8_soft_bank;
494 	uint8_t  m_to8_bios_bank;
495 
496 	/* We allow choosing dynamically:
497 	   - the border size
498 	   - whether we use 640 pixels or 320 pixels in an active row
499 	   (now this is automatically chosen by default for each frame)
500 	*/
501 	uint16_t m_thom_bwidth;
502 	uint16_t m_thom_bheight;
503 	/* border size */
504 	uint8_t  m_thom_hires;
505 	/* 0 = low res: 320x200 active area (faster)
506 	   1 = hi res:  640x200 active area (can represent all video modes)
507 	*/
508 	uint8_t m_thom_hires_better;
509 	/* 1 = a 640 mode was used in the last frame */
510 	/* we use our own video timing to precisely cope with VBLANK and HBLANK */
511 	emu_timer* m_thom_video_timer; /* time elapsed from beginning of frame */
512 	/* number of lightpen call-backs per frame */
513 	int m_thom_lightpen_nb;
514 	/* called thom_lightpen_nb times */
515 	emu_timer *m_thom_lightpen_timer;
516 	/* lightpen callback function to call from timer */
517 	void (thomson_state::*m_thom_lightpen_cb)(int step);
518 	uint8_t* m_thom_vram; /* pointer to video memory */
519 	emu_timer* m_thom_scanline_timer; /* scan-line update */
520 	uint16_t m_thom_last_pal[16];   /* palette at last scanline start */
521 	uint16_t m_thom_pal[16];        /* current palette */
522 	uint8_t  m_thom_pal_changed;    /* whether pal != old_pal */
523 	uint8_t  m_thom_border_index;   /* current border color index */
524 	/* the left and right border color for each row (including top and bottom
525 	   border rows); -1 means unchanged wrt last scanline
526 	*/
527 	int16_t m_thom_border_l[THOM_TOTAL_HEIGHT+1];
528 	int16_t m_thom_border_r[THOM_TOTAL_HEIGHT+1];
529 	/* active area, updated one scan-line at a time every 64us,
530 	   then blitted in screen_update
531 	*/
532 	uint16_t m_thom_vbody[640*200];
533 	uint8_t m_thom_vmode; /* current vide mode */
534 	uint8_t m_thom_vpage; /* current video page */
535 	/* this stores the video mode & page at each GPL in the current line
536 	   (-1 means unchanged)
537 	*/
538 	int16_t m_thom_vmodepage[41];
539 	uint8_t m_thom_vmodepage_changed;
540 	/* one dirty flag for each video memory line */
541 	uint8_t m_thom_vmem_dirty[205];
542 	/* set to 1 if undirty scanlines need to be redrawn due to other video state
543 	   changes */
544 	uint8_t m_thom_vstate_dirty;
545 	uint8_t m_thom_vstate_last_dirty;
546 	uint32_t m_thom_mode_point;
547 	uint32_t m_thom_floppy_wcount;
548 	uint32_t m_thom_floppy_rcount;
549 	emu_timer *m_thom_init_timer;
550 	void (thomson_state::*m_thom_init_cb)( int init );
551 
552 	uint8_t m_to7_controller_type;
553 	uint8_t m_to7_floppy_bank;
554 	uint8_t m_to7_5p14_select;
555 	uint8_t m_to7_5p14sd_select;
556 
557 	int to7_get_cassette();
558 	int mo5_get_cassette();
559 	void mo5_set_cassette( int data );
560 	void thom_irq_reset();
561 	void to7_update_cart_bank();
562 	void to7_set_init( int init );
563 	void to7_modem_reset();
564 	void to7_modem_init();
565 	uint8_t to7_get_mouse_signal();
566 	void to7_game_sound_update();
567 	void to7_game_init();
568 	void to7_game_reset();
569 	void to7_midi_reset();
570 	void to7_midi_init();
571 	void to770_update_ram_bank();
572 	void mo5_init_timer();
573 	void mo5_update_cart_bank();
574 	void to9_set_video_mode( uint8_t data, int style );
575 	void to9_palette_init();
576 	void to9_update_cart_bank();
577 	void to9_update_ram_bank();
578 	int to9_kbd_ktest();
579 	void to9_kbd_update_irq();
580 	void to9_kbd_send( uint8_t data, int parity );
581 	int to9_kbd_get_key();
582 	void to9_kbd_reset();
583 	void to9_kbd_init();
584 	int to8_kbd_ktest();
585 	int to8_kbd_get_key();
586 	void to8_kbd_timer_func();
587 	void to8_kbd_set_ack( int data );
588 	void to8_kbd_reset();
589 	void to8_kbd_init();
590 	void to8_update_floppy_bank();
591 	void to8_update_ram_bank();
592 	void to8_update_cart_bank();
593 	void to8_floppy_init();
594 	void to8_floppy_reset();
595 	void mo6_update_ram_bank();
596 	void mo6_update_cart_bank();
597 	void mo6_game_init();
598 	void mo6_game_reset();
599 	void mo5nr_game_init();
600 	void mo5nr_game_reset();
601 
602 	int thom_update_screen_size();
603 	unsigned thom_video_elapsed();
604 	struct thom_vsignal thom_get_vsignal();
605 	void thom_get_lightpen_pos( int*x, int* y );
606 	struct thom_vsignal thom_get_lightpen_vsignal( int xdec, int ydec, int xdec2 );
607 	void thom_set_lightpen_callback( int nb );
608 	int thom_mode_is_hires( int mode );
609 	void thom_border_changed();
610 	void thom_gplinfo_changed();
611 	void thom_set_border_color( unsigned index );
612 	void thom_set_palette( unsigned index, uint16_t color );
613 	void thom_set_video_mode( unsigned mode );
614 	void thom_set_video_page( unsigned page );
615 	void thom_set_mode_point( int point );
616 	void thom_floppy_active( int write );
617 	unsigned to7_lightpen_gpl( int decx, int decy );
618 	void thom_configure_palette( double gamma, const uint16_t* pal, palette_device& palette );
619 
620 	void to7_5p14_reset();
621 	void to7_5p14_init();
622 	void to7_5p14_index_pulse_callback( int state );
623 	void to7_5p14sd_reset();
624 	void to7_5p14sd_init();
625 	void to7_network_init();
626 	void to7_network_reset();
627 	void to7_floppy_init();
628 	void to7_floppy_reset();
629 	void to9_floppy_init(void* int_base);
630 	void to9_floppy_reset();
631 };
632 
633 /*----------- defined in video/thomson.cpp -----------*/
634 
635 /*
636    TO7 video:
637    one line (64 us) =
638       56 left border pixels ( 7 us)
639    + 320 active pixels (40 us)
640    +  56 right border pixels ( 7 us)
641    +     horizontal retrace (10 us)
642 
643    one image (20 ms) =
644       47 top border lines (~3 ms)
645    + 200 active lines (12.8 ms)
646    +  47 bottom border lines (~3 ms)
647    +     vertical retrace (~1 ms)
648 
649    TO9 and up introduced a half (160 pixels) and double (640 pixels)
650    horizontal mode, but still in 40 us (no change in refresh rate).
651 */
652 
653 
654 /***************************** dimensions **************************/
655 
656 
657 /*********************** video signals *****************************/
658 
659 /***************************** commons *****************************/
660 
661 
662 /* video modes */
663 #define THOM_VMODE_TO770       0
664 #define THOM_VMODE_MO5         1
665 #define THOM_VMODE_BITMAP4     2
666 #define THOM_VMODE_BITMAP4_ALT 3
667 #define THOM_VMODE_80          4
668 #define THOM_VMODE_BITMAP16    5
669 #define THOM_VMODE_PAGE1       6
670 #define THOM_VMODE_PAGE2       7
671 #define THOM_VMODE_OVERLAY     8
672 #define THOM_VMODE_OVERLAY3    9
673 #define THOM_VMODE_TO9        10
674 #define THOM_VMODE_80_TO9     11
675 #define THOM_VMODE_BITMAP4_ALT_HALF 12
676 #define THOM_VMODE_MO5_ALT    13
677 #define THOM_VMODE_OVERLAY_HALF     14
678 #define THOM_VMODE_BITMAP16_ALT 15
679 #define THOM_VMODE_NB         16
680 
681 
682 class to7_io_line_device : public device_t
683 {
684 public:
685 	// construction/destruction
686 	to7_io_line_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
687 
688 protected:
689 	// device-level overrides
690 	virtual void device_start() override;
691 	virtual void device_add_mconfig(machine_config &config) override;
692 
693 private:
694 	required_device<pia6821_device> m_pia_io;
695 	required_device<rs232_port_device> m_rs232;
696 	int m_last_low;
697 	int m_centronics_busy;
698 	int m_rxd;
699 	int m_cts;
700 	int m_dsr;
701 
702 	/* read data register */
703 	uint8_t porta_in();
704 
705 	/* write data register */
706 	void porta_out(uint8_t data);
707 
708 	DECLARE_WRITE_LINE_MEMBER(write_rxd);
709 	DECLARE_WRITE_LINE_MEMBER(write_cts);
710 	DECLARE_WRITE_LINE_MEMBER(write_dsr);
711 	DECLARE_WRITE_LINE_MEMBER(write_centronics_busy);
712 };
713 
714 DECLARE_DEVICE_TYPE(TO7_IO_LINE, to7_io_line_device)
715 
716 #endif // MAME_INCLUDES_THOMSON_H
717