Previous 15994 Revisions Next

r13257 Tuesday 15th November, 2011 at 11:02:09 UTC by Nathan Woods
New CoCo driver:
* Modernized codebase (fully C++/device based)
* Better MC6847/MC6883 emulation, particularly with respect to the interactions
between those two chips.
* Better separation between CoCo 1/2, CoCo 3, Dragon and Dragon Alpha emulations
* Updated all drivers to use new MC6847 emulation (VTech, MC10 etc)
* Converted RAM and Bitbanger devices to C++
[src/emu]dislot.h info.c mame.c mame.h screen.c uiimage.c
[src/emu/imagedev]bitbngr.c bitbngr.h multcart.c
[src/emu/machine]ram.c ram.h
[src/emu/sound]dac.c dac.h
[src/mess]mess.mak
[src/mess/drivers]apf.c atom.c coco.c coco12.c* coco3.c* dgnalpha.c* dragon.c* mc10.c mc1000.c pc6001.c phc25.c spc1000.c vtech1.c z80ne.c
[src/mess/formats]cocopak.c cocopak.h
[src/mess/includes]atom.h coco.h coco12.h* coco3.h* cococart.h dgnalpha.h* dragon.h* mc1000.h phc25.h z80ne.h
[src/mess/layout]coco3.lay
[src/mess/machine]6883sam.c 6883sam.h coco.c coco12.c* coco3.c* coco_pak.c coco_vhd.c coco_vhd.h dgnalpha.c* dragon.c* z80ne.c
[src/mess/video]coco.c coco3.c coco6847.c coco6847.h gime.c* gime.h* m6847.c m6847.h mc6847.c* mc6847.h*

src/emu/sound/dac.c
r13256r13257
9191}
9292
9393
94INT16 dac_output(device_t *device)
95{
96   dac_state *info = get_safe_token(device);
97   return info->output;
98}
99
100
94101static void DAC_build_voltable(dac_state *info)
95102{
96103   int i;
src/emu/sound/dac.h
r13256r13257
99void dac_signed_data_w(device_t *device, UINT8 data) ATTR_NONNULL(1);
1010void dac_data_16_w(device_t *device, UINT16 data) ATTR_NONNULL(1);
1111void dac_signed_data_16_w(device_t *device, UINT16 data) ATTR_NONNULL(1);
12INT16 dac_output(device_t *device);
1213
1314WRITE8_DEVICE_HANDLER( dac_w );
1415WRITE8_DEVICE_HANDLER( dac_signed_w );
src/emu/uiimage.c
r13256r13257
13141314
13151315static void menu_bitbanger_control_populate(running_machine &machine, ui_menu *menu, bitbanger_control_menu_state *menustate)
13161316{
1317   bitbanger_device *bitbanger = downcast<bitbanger_device *>(&menustate->device->device());
13171318   int count = bitbanger_count(machine);
13181319   UINT32 flags = 0, mode_flags = 0, baud_flags = 0, tune_flags = 0;
13191320
r13256r13257
13251326         flags |= MENU_FLAG_RIGHT_ARROW;
13261327   }
13271328
1328   if (bitbanger_inc_mode(&menustate->device->device(), TRUE))
1329   if (bitbanger->inc_mode(TRUE))
13291330      mode_flags |= MENU_FLAG_RIGHT_ARROW;
13301331
1331   if (bitbanger_dec_mode(&menustate->device->device(), TRUE))
1332   if (bitbanger->dec_mode(TRUE))
13321333      mode_flags |= MENU_FLAG_LEFT_ARROW;
13331334
1334   if (bitbanger_inc_baud(&menustate->device->device(), TRUE))
1335   if (bitbanger->inc_baud(TRUE))
13351336      baud_flags |= MENU_FLAG_RIGHT_ARROW;
13361337
1337   if (bitbanger_dec_baud(&menustate->device->device(), TRUE))
1338   if (bitbanger->dec_baud(TRUE))
13381339      baud_flags |= MENU_FLAG_LEFT_ARROW;
13391340
1340   if (bitbanger_inc_tune(&menustate->device->device(), TRUE))
1341   if (bitbanger->inc_tune(TRUE))
13411342      tune_flags |= MENU_FLAG_RIGHT_ARROW;
13421343
1343   if (bitbanger_dec_tune(&menustate->device->device(), TRUE))
1344   if (bitbanger->dec_tune(TRUE))
13441345      tune_flags |= MENU_FLAG_LEFT_ARROW;
13451346
13461347
r13256r13257
13481349   {
13491350      /* name of bitbanger file */
13501351      ui_menu_item_append(menu, menustate->device->device().name(), menustate->device->filename(), flags, BITBANGERCMD_SELECT);
1351      ui_menu_item_append(menu, "Device Mode:", bitbanger_mode_string(&menustate->device->device()), mode_flags, BITBANGERCMD_MODE);
1352      ui_menu_item_append(menu, "Baud:", bitbanger_baud_string(&menustate->device->device()), baud_flags, BITBANGERCMD_BAUD);
1353      ui_menu_item_append(menu, "Baud Tune:", bitbanger_tune_string(&menustate->device->device()), tune_flags, BITBANGERCMD_TUNE);
1352      ui_menu_item_append(menu, "Device Mode:", bitbanger->mode_string(), mode_flags, BITBANGERCMD_MODE);
1353      ui_menu_item_append(menu, "Baud:", bitbanger->baud_string(), baud_flags, BITBANGERCMD_BAUD);
1354      ui_menu_item_append(menu, "Baud Tune:", bitbanger->tune_string(), tune_flags, BITBANGERCMD_TUNE);
13541355      ui_menu_item_append(menu, "Protocol:", "8-1-N", 0, NULL);
13551356   }
13561357   else
r13256r13257
14901491      ui_menu_reset(menu, (ui_menu_reset_options)0);
14911492   }
14921493
1494   /* get the bitbanger */
1495   bitbanger_device *bitbanger = downcast<bitbanger_device *>(menustate->device);
1496
14931497   /* rebuild the menu */
14941498   ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_POSITION);
14951499   menu_bitbanger_control_populate(machine, menu, (bitbanger_control_menu_state*)state);
r13256r13257
15121516            }
15131517            else if (event->itemref==BITBANGERCMD_MODE)
15141518            {
1515               bitbanger_dec_mode(&menustate->device->device(), FALSE);
1519               bitbanger->dec_mode(FALSE);
15161520            }
15171521            else if (event->itemref==BITBANGERCMD_BAUD)
15181522            {
1519               bitbanger_dec_baud(&menustate->device->device(), FALSE);
1523               bitbanger->dec_baud(FALSE);
15201524            }
15211525            else if (event->itemref==BITBANGERCMD_TUNE)
15221526            {
1523               bitbanger_dec_tune(&menustate->device->device(), FALSE);
1527               bitbanger->dec_tune(FALSE);
15241528            }
15251529            break;
15261530
r13256r13257
15361540            }
15371541            else if (event->itemref==BITBANGERCMD_MODE)
15381542            {
1539               bitbanger_inc_mode(&menustate->device->device(), FALSE);
1543               bitbanger->inc_mode(FALSE);
15401544            }
15411545            else if (event->itemref==BITBANGERCMD_BAUD)
15421546            {
1543               bitbanger_inc_baud(&menustate->device->device(), FALSE);
1547               bitbanger->inc_baud(FALSE);
15441548            }
15451549            else if (event->itemref==BITBANGERCMD_TUNE)
15461550            {
1547               bitbanger_inc_tune(&menustate->device->device(), FALSE);
1551               bitbanger->inc_tune(FALSE);
15481552            }
15491553            break;
15501554      }
src/emu/imagedev/bitbngr.c
r13256r13257
1212
1313
1414/***************************************************************************
15    TYPE DEFINITIONS
15    IMPLEMENTATION
1616***************************************************************************/
1717
18typedef struct _bitbanger_token bitbanger_token;
19struct _bitbanger_token
20{
21   emu_timer *bitbanger_output_timer;
22   emu_timer *bitbanger_input_timer;
23   int output_value;
24   int build_count;
25   int build_byte;
26   attotime idle_delay;
27   attotime current_baud;
28   UINT32 input_buffer_size;
29   UINT32 input_buffer_cursor;
30   int mode;
31   int baud;
32   int tune;
33   UINT8 input_buffer[1000];
34};
18const device_type BITBANGER = &device_creator<bitbanger_device>;
3519
36
37
38/***************************************************************************
39    FUNCTION PROTOTYPES
40***************************************************************************/
41
42static TIMER_CALLBACK(bitbanger_output_timer);
43static TIMER_CALLBACK(bitbanger_input_timer);
44
45
46
47/***************************************************************************
48    INLINE FUNCTIONS
49***************************************************************************/
50
51
5220/*-------------------------------------------------
53    get_token - safely gets the bitbanger data
21    ctor
5422-------------------------------------------------*/
5523
56INLINE bitbanger_token *get_token(device_t *device)
24bitbanger_device::bitbanger_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
25   : device_t(mconfig, BITBANGER, "Bitbanger", tag, owner, clock),
26     device_image_interface(mconfig, *this)
5727{
58   assert(device != NULL);
59   assert(device->type() == BITBANGER);
60   return (bitbanger_token *) downcast<legacy_device_base *>(device)->token();
28   m_output_timer = NULL;
29   m_input_timer = NULL;
30   m_output_value = 0;
31   m_build_count = 0;
32   m_build_byte = 0;
33   m_idle_delay = attotime::zero;
34   m_current_baud = attotime::zero;
35   m_input_buffer_size = 0;
36   m_input_buffer_cursor = 0;
37   m_mode = 0;
38   m_baud = 0;
39   m_tune = 0;
40   m_current_input = 0;
41   memset(m_input_buffer, 0, sizeof(m_input_buffer));
6142}
6243
6344
64/*-------------------------------------------------
65    get_config - safely gets the bitbanger config
66-------------------------------------------------*/
6745
68INLINE const bitbanger_config *get_config(device_t *device)
69{
70   assert(device != NULL);
71   assert(device->type() == BITBANGER);
72   return (const bitbanger_config *) device->static_config();
73}
74
75
76
77/***************************************************************************
78    IMPLEMENTATION
79***************************************************************************/
80
81
8246/*-------------------------------------------------
8347    native_output - outputs data to a file
8448-------------------------------------------------*/
8549
86static void native_output(device_t *bitbanger, UINT8 data)
50void bitbanger_device::native_output(UINT8 data)
8751{
88   device_image_interface *image = dynamic_cast<device_image_interface *>(bitbanger);
89   if (image->exists())
52   if (exists())
9053   {
91      image->fwrite(&data, 1);
54      fwrite(&data, 1);
9255   }
9356}
9457
r13256r13257
9760    native_input - inputs data from a file
9861-------------------------------------------------*/
9962
100static UINT32 native_input(device_t *bitbanger, void *buffer, UINT32 length)
63UINT32 bitbanger_device::native_input(void *buffer, UINT32 length)
10164{
102   device_image_interface *image = dynamic_cast<device_image_interface *>(bitbanger);
103   if (image->exists())
65   if (exists())
10466   {
105      return image->fread(buffer, length);
67      return fread(buffer, length);
10668   }
107
10869   return 0;
10970}
11071
11172
73
11274/*-------------------------------------------------
113    bitbanger_mode_string
75    mode_string
11476-------------------------------------------------*/
115const char *bitbanger_mode_string(device_t *device)
77
78const char *bitbanger_device::mode_string(void)
11679{
117   bitbanger_token *bi = get_token(device);
11880   static const char *const modes[] = {"Printer", "Modem"};
119
120   return(modes[bi->mode]);
81   return modes[m_mode];
12182}
12283
12384
85
12486/*-------------------------------------------------
125    bitbanger_inc_mode
87    inc_mode
12688-------------------------------------------------*/
127bool bitbanger_inc_mode(device_t *device, bool test)
89
90bool bitbanger_device::inc_mode(bool test)
12891{
129   bitbanger_token *bi = get_token(device);
130   int adjust_mode = (int)bi->mode + 1;
92   int adjust_mode = (int)m_mode + 1;
13193
132   if( adjust_mode >= BITBANGER_MODE_MAX )
133      return FALSE;
94   if( adjust_mode >= BITBANGER_MODE_MAX )
95      return FALSE;
13496
135   if( !test)
136      bi->mode = adjust_mode;
97   if( !test)
98      m_mode = adjust_mode;
13799
138   return TRUE;
100   return TRUE;
139101}
140102
141103
104
142105/*-------------------------------------------------
143    bitbanger_dec_mode
106    dec_mode
144107-------------------------------------------------*/
145bool bitbanger_dec_mode(device_t *device, bool test)
108
109bool bitbanger_device::dec_mode(bool test)
146110{
147   bitbanger_token *bi = get_token(device);
148   int adjust_mode = bi->mode - 1;
111   int adjust_mode = m_mode - 1;
149112
150   if( adjust_mode < 0 )
151      return FALSE;
113   if( adjust_mode < 0 )
114      return FALSE;
152115
153   if( !test)
154      bi->mode = adjust_mode;
116   if( !test)
117      m_mode = adjust_mode;
155118
156   return TRUE;
119   return TRUE;
157120}
158121
159122
123
160124/*-------------------------------------------------
161    bitbanger_tune_string
125    tune_string
162126-------------------------------------------------*/
163const char *bitbanger_tune_string(device_t *device)
127
128const char *bitbanger_device::tune_string(void)
164129{
165   bitbanger_token *bi = get_token(device);
166130   static const char *const tunes[] = {"-2.0%", "-1.75%", "-1.5%", "-1.25%", "-1.0%", "-0.75%", "-0.5", "-0.25%", "\xc2\xb1""0%",
167131                                 "+0.25%",  "+0.5%", "+0.75%", "+1.0%", "+1.25%", "+1.5%", "+1.75%", "+2.0%"};
168
169   return(tunes[bi->tune]);
132   return tunes[m_tune];
170133}
171134
172135
136
173137/*-------------------------------------------------
174    bitbanger_tune_value
138    tune_value
175139-------------------------------------------------*/
176static float bitbanger_tune_value(device_t *device)
140
141float bitbanger_device::tune_value(void)
177142{
178   bitbanger_token *bi = get_token(device);
179143   static const float tunes[] = {0.97f, 0.9825f, 0.985f, 0.9875f, 0.99f, 0.9925f, 0.995f, 0.9975f, 1.0f,
180144                  1.0025f, 1.005f, 1.0075f, 1.01f, 1.0125f, 1.015f, 1.0175f, 1.02f};
181
182   return(tunes[bi->tune]);
145   return tunes[m_tune];
183146}
184147
185148
149
186150/*-------------------------------------------------
187    bitbanger_baud_value
151    baud_value
188152-------------------------------------------------*/
189153
190static UINT32 bitbanger_baud_value(device_t *device)
154UINT32 bitbanger_device::baud_value(void)
191155{
192   bitbanger_token *bi = get_token(device);
193156   static const float bauds[] = { 150.0f, 300.0f, 600.0f, 1200.0f, 2400.0f, 4800.0f, 9600.0f,
194157            14400.0f, 28800.0f, 38400.0f, 57600.0f, 115200.0f};
195   float result = bitbanger_tune_value(device) * bauds[bi->baud];
158   float result = tune_value() * bauds[m_baud];
196159   return (UINT32)result;
197160}
198161
199162
200163/*-------------------------------------------------
201    bitbanger_baud_string
164    baud_string
202165-------------------------------------------------*/
203166
204const char *bitbanger_baud_string(device_t *device)
167const char *bitbanger_device::baud_string(void)
205168{
206   bitbanger_token *bi = get_token(device);
207169   static const char *const bauds[] = { "150", "300", "600", "1200", "2400", "4800",
208170                     "9600", "14400", "28800", "38400", "57600", "115200"};
209171
210   return(bauds[bi->baud]);
172   return(bauds[m_baud]);
211173}
212174
213175
176
214177/*-------------------------------------------------
215    bitbanger_inc_baud
178    inc_baud
216179-------------------------------------------------*/
217bool bitbanger_inc_baud(device_t *device, bool test)
180
181bool bitbanger_device::inc_baud(bool test)
218182{
219   bitbanger_token *bi = get_token(device);
220   int adjust_baud = (int)bi->baud + 1;
183   int adjust_baud = (int)m_baud + 1;
221184
222   if( adjust_baud >= BITBANGER_BAUD_MAX )
223      return FALSE;
185   if( adjust_baud >= BITBANGER_BAUD_MAX )
186      return FALSE;
224187
225   if( !test)
226   {
227      bi->baud = adjust_baud;
228      bi->current_baud = attotime::from_hz(bitbanger_baud_value(device));
229   }
188   if( !test)
189   {
190      m_baud = adjust_baud;
191      m_current_baud = attotime::from_hz(baud_value());
192   }
230193
231   return TRUE;
194   return TRUE;
232195}
233196
234197
235198/*-------------------------------------------------
236    bitbanger_dec_baud
199    dec_baud
237200-------------------------------------------------*/
238bool bitbanger_dec_baud(device_t *device, bool test)
201
202bool bitbanger_device::dec_baud(bool test)
239203{
240   bitbanger_token *bi = get_token(device);
241   int adjust_baud = bi->baud - 1;
204   int adjust_baud = m_baud - 1;
242205
243   if( adjust_baud < 0 )
244      return FALSE;
206   if( adjust_baud < 0 )
207      return FALSE;
245208
246   if( !test)
247   {
248      bi->baud = adjust_baud;
249      bi->current_baud = attotime::from_hz(bitbanger_baud_value(device));
250   }
209   if( !test)
210   {
211      m_baud = adjust_baud;
212      m_current_baud = attotime::from_hz(baud_value());
213   }
251214
252   return TRUE;
215   return TRUE;
253216}
254217
255218
256219/*-------------------------------------------------
257    bitbanger_inc_tune
220    inc_tune
258221-------------------------------------------------*/
259bool bitbanger_inc_tune(device_t *device, bool test)
222
223bool bitbanger_device::inc_tune(bool test)
260224{
261   bitbanger_token *bi = get_token(device);
262   int adjust_tune = (int)bi->tune + 1;
225   int adjust_tune = (int)m_tune + 1;
263226
264   if( adjust_tune >= BITBANGER_TUNE_MAX )
265      return FALSE;
227   if( adjust_tune >= BITBANGER_TUNE_MAX )
228      return FALSE;
266229
267   if( !test)
268   {
269      bi->tune = adjust_tune;
270      bi->current_baud = attotime::from_hz(bitbanger_baud_value(device));
271   }
230   if (!test)
231   {
232      m_tune = adjust_tune;
233      m_current_baud = attotime::from_hz(baud_value());
234   }
272235
273   return TRUE;
236   return TRUE;
274237}
275238
276239
240
277241/*-------------------------------------------------
278    bitbanger_dec_tune
242    dec_tune
279243-------------------------------------------------*/
280bool bitbanger_dec_tune(device_t *device, bool test)
244
245bool bitbanger_device::dec_tune(bool test)
281246{
282   bitbanger_token *bi = get_token(device);
283   int adjust_tune = bi->tune - 1;
247   int adjust_tune = m_tune - 1;
284248
285   if( adjust_tune < 0 )
286      return FALSE;
249   if( adjust_tune < 0 )
250      return FALSE;
287251
288   if( !test)
289   {
290      bi->tune = adjust_tune;
291      bi->current_baud = attotime::from_hz(bitbanger_baud_value(device));
292   }
252   if( !test)
253   {
254      m_tune = adjust_tune;
255      m_current_baud = attotime::from_hz(baud_value());
256   }
293257
294   return TRUE;
258   return TRUE;
295259}
296260
297261
262
298263/*-------------------------------------------------
299    bitbanger_bytes_to_bits_81N
264    bytes_to_bits_81N
300265-------------------------------------------------*/
301static void bitbanger_bytes_to_bits_81N(device_t *img)
266
267void bitbanger_device::bytes_to_bits_81N(void)
302268{
303   bitbanger_token *bi = get_token(img);
304   UINT8 byte_buffer[100];
305   UINT32 byte_buffer_size, bit_buffer_size;
306   int i, j;
307   static const UINT8 bitmask[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
269   UINT8 byte_buffer[100];
270   UINT32 byte_buffer_size, bit_buffer_size;
271   int i, j;
272   static const UINT8 bitmask[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
308273
309   bit_buffer_size = 0;
310   byte_buffer_size = native_input(img, byte_buffer, sizeof(byte_buffer));
274   bit_buffer_size = 0;
275   byte_buffer_size = native_input(byte_buffer, sizeof(byte_buffer));
311276
312   /* Translate byte buffer into bit buffer using: 1 start bit, 8 data bits, 1 stop bit, no parity */
277   /* Translate byte buffer into bit buffer using: 1 start bit, 8 data bits, 1 stop bit, no parity */
313278
314   for( i=0; i<byte_buffer_size; i++ )
315   {
316      bi->input_buffer[bit_buffer_size++] = 0;
279   for( i=0; i<byte_buffer_size; i++ )
280   {
281      m_input_buffer[bit_buffer_size++] = 0;
317282
318      for( j=0; j<8; j++ )
319      {
320         if( byte_buffer[i] & bitmask[j] )
321            bi->input_buffer[bit_buffer_size++] = 1;
322         else
323            bi->input_buffer[bit_buffer_size++] = 0;
324      }
283      for( j=0; j<8; j++ )
284      {
285         if( byte_buffer[i] & bitmask[j] )
286            m_input_buffer[bit_buffer_size++] = 1;
287         else
288            m_input_buffer[bit_buffer_size++] = 0;
289      }
325290
326      bi->input_buffer[bit_buffer_size++] = 1;
327   }
291      m_input_buffer[bit_buffer_size++] = 1;
292   }
328293
329   bi->input_buffer_size = bit_buffer_size;
330   bi->input_buffer_cursor = 0;
294   m_input_buffer_size = bit_buffer_size;
295   m_input_buffer_cursor = 0;
331296}
332297
333298
299
334300/*-------------------------------------------------
335    DEVICE_START(bitbanger)
301    device_start
336302-------------------------------------------------*/
337303
338static DEVICE_START(bitbanger)
304void bitbanger_device::device_start(void)
339305{
340   bitbanger_token *bi;
341   const bitbanger_config *config = get_config(device);
306   const bitbanger_config *config = (const bitbanger_config *) static_config();
342307
343   bi = get_token(device);
344
345308   /* output config */
346   bi->build_count = 0;
347   bi->bitbanger_output_timer = device->machine().scheduler().timer_alloc(FUNC(bitbanger_output_timer), (void *) device);
309   m_build_count = 0;
310   m_output_timer = timer_alloc(TIMER_OUTPUT);
348311
349312   /* input config */
350   bi->bitbanger_input_timer = device->machine().scheduler().timer_alloc(FUNC(bitbanger_input_timer), (void *) device );
351   bi->idle_delay = attotime::from_seconds(1);
352   bi->input_buffer_size = 0;
353   bi->input_buffer_cursor = 0;
313   m_input_timer = timer_alloc(TIMER_INPUT);
314   m_idle_delay = attotime::from_seconds(1);
315   m_input_buffer_size = 0;
316   m_input_buffer_cursor = 0;
354317
355   bi->mode = config->default_mode;
356   bi->baud = config->default_baud;
357   bi->tune = config->default_tune;
358   bi->current_baud = attotime::from_hz(bitbanger_baud_value(device));
318   /* defaults */
319   m_mode = config->m_default_mode;
320   m_baud = config->m_default_baud;
321   m_tune = config->m_default_tune;
322   m_current_baud = attotime::from_hz(baud_value());
359323
360   /* test callback */
361   if(!config->input_callback)
362      fatalerror("Misconfigured bitbanger device: input_callback cannot be NULL\n");
324   /* callback */
325   m_input_callback.resolve(config->m_input_callback, *this);
363326}
364327
365328
329
366330/*-------------------------------------------------
367    TIMER_CALLBACK(bitbanger_output_timer)
331    device_config_complete
368332-------------------------------------------------*/
369333
370static TIMER_CALLBACK(bitbanger_output_timer)
334void bitbanger_device::device_config_complete(void)
371335{
372   device_t *device = (device_t *) ptr;
373   bitbanger_token *bi = get_token(device);
336   update_names();
337}
374338
375   /* this ia harded coded for 8-1-N */
376   if( bi->output_value )
377      bi->build_byte |= 0x200;
378339
379   bi->build_byte >>= 1;
380   bi->build_count--;
381340
382   if(bi->build_count == 0)
383   {
384      if( bi->output_value == 1 )
385         native_output( device, bi->build_byte );
386      else
387         logerror("Bitbanger: Output framing error.\n" );
341/*-------------------------------------------------
342    device_timer
343-------------------------------------------------*/
388344
389      bi->bitbanger_output_timer->reset();
390   }
345void bitbanger_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
346{
347   switch(id)
348   {
349      case TIMER_OUTPUT:
350         timer_output();
351         break;
352
353      case TIMER_INPUT:
354         timer_input();
355         break;
356   }
391357}
392358
393359
360
394361/*-------------------------------------------------
395    TIMER_CALLBACK(bitbanger_input_timer)
362    timer_output
396363-------------------------------------------------*/
397364
398static TIMER_CALLBACK(bitbanger_input_timer)
365void bitbanger_device::timer_output(void)
399366{
400   device_t *device = (device_t *) ptr;
401   bitbanger_token *bi = get_token(device);
402   const bitbanger_config *config = get_config(device);
367   /* this ia harded coded for 8-1-N */
368   if( m_output_value )
369      m_build_byte |= 0x200;
403370
404   if(bi->input_buffer_cursor == bi->input_buffer_size)
405   {
406      /* get more data */
407      bitbanger_bytes_to_bits_81N(device);
371   m_build_byte >>= 1;
372   m_build_count--;
408373
409      if(bi->input_buffer_size == 0)
410      {
411         /* no more data, wait and try again */
412         bi->idle_delay = min(bi->idle_delay + attotime::from_msec(100), attotime::from_seconds(1));
413         bi->bitbanger_input_timer->adjust(bi->idle_delay);
374   if(m_build_count == 0)
375   {
376      if( m_output_value == 1 )
377         native_output(m_build_byte);
378      else
379         logerror("Bitbanger: Output framing error.\n" );
414380
415
416         if( bi->mode == BITBANGER_MODEM )
417            config->input_callback(machine, 1);
418         else
419            config->input_callback(machine, 0);
420
421         return;
422      }
423      else
424      {
425         bi->idle_delay = bi->current_baud;
426         bi->bitbanger_input_timer->adjust(bi->idle_delay, 0, bi->idle_delay);
427      }
428   }
429
430   /* send bit to driver */
431   config->input_callback(machine, bi->input_buffer[(bi->input_buffer_cursor)++]);
381      m_output_timer->reset();
382   }
432383}
433384
434385
386
435387/*-------------------------------------------------
436    bitbanger_output - outputs data to a bitbanger
437    port
388    timer_input
438389-------------------------------------------------*/
439390
440void bitbanger_output(device_t *device, int value)
391void bitbanger_device::timer_input(void)
441392{
442   bitbanger_token *bi = get_token(device);
443   attotime one_point_five_baud;
393   if(m_input_buffer_cursor == m_input_buffer_size)
394   {
395      /* get more data */
396      bytes_to_bits_81N();
444397
445   if( bi->build_count == 0 && bi->output_value == 1 && value == 0 )
446   {
447      /* we found our start bit */
448      /* eight bits of data, plus one of stop */
449      bi->build_count = 9;
450      bi->build_byte = 0;
398      if(m_input_buffer_size == 0)
399      {
400         /* no more data, wait and try again */
401         m_idle_delay = min(m_idle_delay + attotime::from_msec(100), attotime::from_seconds(1));
402         m_input_timer->adjust(m_idle_delay);
451403
452      one_point_five_baud = bi->current_baud + bi->current_baud / 2;
453      bi->bitbanger_output_timer->adjust(one_point_five_baud, 0, bi->current_baud);
454   }
404         if( m_mode == BITBANGER_MODEM )
405            set_input_line(1);
406         else
407            set_input_line(0);
408         return;
409      }
410      else
411      {
412         m_idle_delay = m_current_baud;
413         m_input_timer->adjust(m_idle_delay, 0, m_idle_delay);
414      }
415   }
455416
456   //fprintf(stderr,"%s, %d\n", device->machine().time().as_string(9), value);
457   bi->output_value = value;
417   /* send bit to driver */
418   set_input_line(m_input_buffer[(m_input_buffer_cursor)++]);
458419}
459420
460421
422
461423/*-------------------------------------------------
462    DEVICE_IMAGE_LOAD( bitbanger )
424    set_input_line
463425-------------------------------------------------*/
464426
465static DEVICE_IMAGE_LOAD( bitbanger )
427void bitbanger_device::set_input_line(UINT8 line)
466428{
467   device_t *device = &image.device();
468   bitbanger_token *bi;
469   bi = get_token(device);
429   /* normalize */
430   line = line ? ASSERT_LINE : CLEAR_LINE;
470431
471   bi->bitbanger_input_timer->enable(true);
472   bi->bitbanger_input_timer->adjust(attotime::zero, 0, attotime::from_seconds(1));
473
474   /* we don't need to do anything special */
475   return IMAGE_INIT_PASS;
432   /* only act when the state changes */
433   if (m_current_input != line)
434   {
435      m_current_input = line;
436      if (!m_input_callback.isnull())
437      {
438         m_input_callback(line ? ASSERT_LINE : CLEAR_LINE);
439      }
440   }
476441}
477442
478443
444
479445/*-------------------------------------------------
480    DEVICE_IMAGE_UNLOAD( bitbanger )
446    output - outputs data to a bitbanger port
481447-------------------------------------------------*/
482448
483static DEVICE_IMAGE_UNLOAD( bitbanger )
449void bitbanger_device::output(int value)
484450{
485   device_t *device = &image.device();
486   bitbanger_token *bi;
487   bi = get_token(device);
451   attotime one_point_five_baud;
488452
489   bi->bitbanger_input_timer->enable(false);
453   if( m_build_count == 0 && m_output_value == 1 && value == 0 )
454   {
455      /* we found our start bit */
456      /* eight bits of data, plus one of stop */
457      m_build_count = 9;
458      m_build_byte = 0;
459
460      one_point_five_baud = m_current_baud + m_current_baud / 2;
461      m_output_timer->adjust(one_point_five_baud, 0, m_current_baud);
462   }
463
464   //fprintf(stderr,"%s, %d\n", device->machine().time().as_string(9), value);
465   m_output_value = value;
490466}
491467
492468
469
493470/*-------------------------------------------------
494    DEVICE_GET_INFO(bitbanger) - device getinfo
495    function
471    call_load
496472-------------------------------------------------*/
497473
498DEVICE_GET_INFO(bitbanger)
474bool bitbanger_device::call_load(void)
499475{
500   switch(state)
501   {
502      /* --- the following bits of info are returned as 64-bit signed integers --- */
503      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(bitbanger_token); break;
504      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0; break;
505      case DEVINFO_INT_IMAGE_TYPE:               info->i = IO_PRINTER; break;
506      case DEVINFO_INT_IMAGE_READABLE:            info->i = 1; break;
507      case DEVINFO_INT_IMAGE_WRITEABLE:            info->i = 1; break;
508      case DEVINFO_INT_IMAGE_CREATABLE:            info->i = 1; break;
476   m_input_timer->enable(true);
477   m_input_timer->adjust(attotime::zero, 0, attotime::from_seconds(1));
509478
510      /* --- the following bits of info are returned as pointers to data or functions --- */
511      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(bitbanger); break;
512      case DEVINFO_FCT_IMAGE_LOAD:               info->f = (genf *) DEVICE_IMAGE_LOAD_NAME(bitbanger);      break;
513      case DEVINFO_FCT_IMAGE_UNLOAD:               info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME(bitbanger);   break;
479   /* we don't need to do anything special */
480   return IMAGE_INIT_PASS;
481}
514482
515      /* --- the following bits of info are returned as NULL-terminated strings --- */
516      case DEVINFO_STR_NAME:                     strcpy(info->s, "Bitbanger"); break;
517      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Bitbanger"); break;
518      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__); break;
519      case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:         strcpy(info->s, "prn"); break;
520   }
483
484
485/*-------------------------------------------------
486    call_unload
487-------------------------------------------------*/
488
489void bitbanger_device::call_unload(void)
490{
491   m_input_timer->enable(false);
521492}
522493
523DEFINE_LEGACY_IMAGE_DEVICE(BITBANGER, bitbanger);
src/emu/imagedev/multcart.c
r13256r13257
379379      return MCERR_MISSING_RAM_LENGTH;
380380
381381   /* ...and parse it */
382   resource->length = ram_parse_string(length_string);
382   resource->length = ram_device::parse_string(length_string);
383383   if (resource->length <= 0)
384384      return MCERR_INVALID_RAM_SPEC;
385385
src/emu/imagedev/bitbngr.h
r13256r13257
5555/***************************************************************************
5656    CONSTANTS
5757***************************************************************************/
58DECLARE_LEGACY_IMAGE_DEVICE(BITBANGER, bitbanger);
5958
6059#define MCFG_BITBANGER_ADD(_tag, _intrf) \
6160   MCFG_DEVICE_ADD(_tag, BITBANGER, 0) \
r13256r13257
7069struct _bitbanger_config
7170{
7271   /* callback to driver */
73   void (*input_callback)(running_machine &machine, UINT8 bit);
74   int default_mode;                  /* emulating a printer or modem */
75   int default_baud;                  /* output bits per second */
76   int default_tune;                /* fine tune adjustment to the baud */
72   devcb_write_line      m_input_callback;
73
74   /* emulating a printer or modem */
75   int                  m_default_mode;
76
77   /* output bits per second */
78   int                  m_default_baud;                 
79
80   /* fine tune adjustment to the baud */
81   int                  m_default_tune;               
7782};
7883
7984
8085
81/***************************************************************************
82    FUNCTION PROTOTYPES
83***************************************************************************/
86class bitbanger_device :   public device_t,
87                     public device_image_interface
88{
89public:
90   // construction/destruction
91   bitbanger_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
8492
85/* outputs data to a bitbanger port */
86void bitbanger_output(device_t *device, int value);
93   // image-level overrides
94   virtual bool call_load();
95   virtual void call_unload();
8796
88/* ui functions */
89const char *bitbanger_mode_string(device_t *device);
90const char *bitbanger_baud_string(device_t *device);
91const char *bitbanger_tune_string(device_t *device);
92bool bitbanger_inc_mode(device_t *device, bool test);
93bool bitbanger_dec_mode(device_t *device, bool test);
94bool bitbanger_inc_tune(device_t *device, bool test);
95bool bitbanger_dec_tune(device_t *device, bool test);
96bool bitbanger_inc_baud(device_t *device, bool test);
97bool bitbanger_dec_baud(device_t *device, bool test);
97   // image device
98   virtual iodevice_t image_type() const { return IO_PRINTER; }
99   virtual bool is_readable()  const { return 1; }
100   virtual bool is_writeable() const { return 1; }
101   virtual bool is_creatable() const { return 1; }
102   virtual bool must_be_loaded() const { return 0; }
103   virtual bool is_reset_on_load() const { return 0; }
104   virtual const char *file_extensions() const { return "prn"; }
105   virtual const option_guide *create_option_guide() const { return NULL; }
98106
107   // outputs data to a bitbanger port
108   void output(int value);
109
110   // reads the current input value
111   int input(void) const { return m_current_input; }
112
113   // ui functions
114   const char *mode_string(void);
115   const char *baud_string(void);
116   const char *tune_string(void);
117   bool inc_mode(bool test);
118   bool dec_mode(bool test);
119   bool inc_tune(bool test);
120   bool dec_tune(bool test);
121   bool inc_baud(bool test);
122   bool dec_baud(bool test);
123
124protected:
125   // device-level overrides
126   virtual void device_start();
127   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
128   virtual void device_config_complete();
129
130private:
131   // constants
132   static const device_timer_id TIMER_OUTPUT = 0;
133   static const device_timer_id TIMER_INPUT = 1;
134
135   // methods
136   void native_output(UINT8 data);
137   UINT32 native_input(void *buffer, UINT32 length);
138   void bytes_to_bits_81N(void);
139   void timer_input(void);
140   void timer_output(void);
141   float tune_value(void);
142   UINT32 baud_value(void);
143   void set_input_line(UINT8 line);
144
145   // variables
146   emu_timer *               m_output_timer;
147   emu_timer *               m_input_timer;
148   devcb_resolved_write_line   m_input_callback;
149   int                     m_output_value;
150   int                     m_build_count;
151   int                     m_build_byte;
152   attotime               m_idle_delay;
153   attotime               m_current_baud;
154   UINT32                  m_input_buffer_size;
155   UINT32                  m_input_buffer_cursor;
156   int                     m_mode;
157   int                     m_baud;
158   int                     m_tune;
159   UINT8                  m_current_input;
160   UINT8                  m_input_buffer[1000];
161};
162
163// device type definition
164extern const device_type BITBANGER;
165
99166#endif /* __BITBNGR_H__ */
src/emu/info.c
r13256r13257
12421242{
12431243   for (const device_t *device = m_drivlist.config().devicelist().first(RAM); device != NULL; device = device->typenext())
12441244   {
1245      ram_config *ram = (ram_config *)downcast<const legacy_device_base *>(device)->inline_config();
1246      fprintf(m_output, "\t\t<ramoption default=\"1\">%u</ramoption>\n", ram_parse_string(ram->default_size));
1245      const ram_device *ram = downcast<const ram_device *>(device);
12471246
1248      if (ram->extra_options != NULL)
1247      fprintf(m_output, "\t\t<ramoption default=\"1\">%u</ramoption>\n", ram->default_size());
1248
1249      if (ram->extra_options() != NULL)
12491250      {
1250         astring options(ram->extra_options);
1251         astring options(ram->extra_options());
12511252         for (int start = 0, end = options.chr(0, ','); ; start = end + 1, end = options.chr(start, ','))
12521253         {
12531254            astring option;
12541255            option.cpysubstr(options, start, (end == -1) ? -1 : end - start);
1255            fprintf(m_output, "\t\t<ramoption>%u</ramoption>\n", ram_parse_string(option));
1256            fprintf(m_output, "\t\t<ramoption>%u</ramoption>\n", ram_device::parse_string(option));
12561257            if (end == -1)
12571258               break;
12581259         }
src/emu/dislot.h
r13256r13257
3535      { NULL, NULL }                     \
3636   };
3737
38#define SLOT_INTERFACE_EXTERN(name) extern const slot_interface slot_interface_##name[]
39
3840class device_slot_card_interface;
3941
4042class device_slot_interface : public device_interface
src/emu/mame.c
r13256r13257
428428
429429void CLIB_DECL logerror(const char *format, ...)
430430{
431   va_list arg;
432   va_start(arg, format);
433   vlogerror(format, arg);
434   va_end(arg);
435}
436
437
438/*-------------------------------------------------
439    vlogerror - log to the debugger and any other
440    OSD-defined output streams
441-------------------------------------------------*/
442
443void CLIB_DECL vlogerror(const char *format, va_list arg)
444{
431445   if (global_machine != NULL)
432   {
433      va_list arg;
434      va_start(arg, format);
435446      global_machine->vlogerror(format, arg);
436      va_end(arg);
437   }
438447}
439448
src/emu/machine/ram.c
r13256r13257
1414#include "ram.h"
1515
1616
17/***************************************************************************
18    CONSTANTS
19***************************************************************************/
20
21#define RAM_STRING_BUFLEN   16
22#define MAX_RAM_OPTIONS      16
23
24
25/***************************************************************************
26    TYPE DEFINITIONS
27***************************************************************************/
28
29typedef struct _ram_state ram_state;
30struct _ram_state
31{
32   UINT32 size; /* total amount of ram configured */
33   UINT8 *ram;  /* pointer to the start of ram */
34};
35
36
3717/*****************************************************************************
38    INLINE FUNCTIONS
18    LIVE DEVICE
3919*****************************************************************************/
4020
41INLINE ram_state *get_safe_token(device_t *device)
42{
43   assert(device != NULL);
44   assert(device->type() == RAM);
21// device type definition
22const device_type RAM = &device_creator<ram_device>;
4523
46   return (ram_state *)downcast<legacy_device_base *>(device)->token();
47}
4824
4925
50/*****************************************************************************
51    HELPER FUNCTIONS
52*****************************************************************************/
26//-------------------------------------------------
27//  ram_device - constructor
28//-------------------------------------------------
5329
54/*-------------------------------------------------
55    ram_parse_string - convert a ram string to an
56    integer value
57-------------------------------------------------*/
58
59UINT32 ram_parse_string(const char *s)
30ram_device::ram_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
31    : device_t(mconfig, RAM, "RAM", tag, owner, clock)
6032{
61   UINT32 ram;
62   char suffix = '\0';
33   m_size = 0;
34   m_pointer = NULL;
35   m_default_size = NULL;
36   m_extra_options = NULL;
37   m_default_value = 0xCD;
38}
6339
64   s += sscanf(s, "%u%c", &ram, &suffix);
6540
66   switch(tolower(suffix))
67   {
68   case 'k':
69      /* kilobytes */
70      ram *= 1024;
71      break;
7241
73   case 'm':
74      /* megabytes */
75      ram *= 1024*1024;
76      break;
42//-------------------------------------------------
43//  device_start - device-specific startup
44//-------------------------------------------------
7745
78   case '\0':
79      /* no suffix */
80      break;
81
82   default:
83      /* parse failure */
84      ram = 0;
85      break;
86   }
87
88   return ram;
89}
90
91/*****************************************************************************
92    DEVICE INTERFACE
93*****************************************************************************/
94
95static DEVICE_START( ram )
46void ram_device::device_start()
9647{
97   ram_state *ram = get_safe_token(device);
98   ram_config *config = (ram_config *)downcast<const legacy_device_base *>(device)->inline_config();
99
10048   /* the device named 'ram' can get ram options from command line */
101   if (strcmp(device->tag(), RAM_TAG) == 0)
49   m_size = 0;
50   if (strcmp(tag(), RAM_TAG) == 0)
10251   {
103      const char *ramsize_string = device->machine().options().ram_size();
104
52      const char *ramsize_string = machine().options().ram_size();
10553      if ((ramsize_string != NULL) && (ramsize_string[0] != '\0'))
106         ram->size = ram_parse_string(ramsize_string);
54         m_size = parse_string(ramsize_string);
10755   }
10856
10957   /* if we didn't get a size yet, use the default */
110   if (ram->size == 0)
111      ram->size = ram_parse_string(config->default_size);
58   if (m_size == 0)
59      m_size = default_size();
11260
11361   /* allocate space for the ram */
114   ram->ram = auto_alloc_array(device->machine(), UINT8, ram->size);
62   m_pointer = auto_alloc_array(machine(), UINT8, m_size);
11563
11664   /* reset ram to the default value */
117   memset(ram->ram, config->default_value, ram->size);
65   memset(m_pointer, m_default_value, m_size);
11866
11967   /* register for state saving */
120   device->save_item(NAME(ram->size));
121   device->save_pointer(NAME(ram->ram), ram->size);
68   save_item(NAME(m_size));
69   save_pointer(NAME(m_pointer), m_size);
12270}
12371
124static DEVICE_VALIDITY_CHECK( ram )
72
73//-------------------------------------------------
74//  device_validity_check - device-specific validity
75//   checks
76//-------------------------------------------------
77
78bool ram_device::device_validity_check(emu_options &options, const game_driver &driver) const
12579{
126   ram_config *config = (ram_config *)downcast<const legacy_device_base *>(device)->inline_config();
12780   const char *ramsize_string = NULL;
12881   int is_valid = FALSE;
12982   UINT32 specified_ram = 0;
130   int error = FALSE;
83   bool error = FALSE;
13184   const char *gamename_option = NULL;
13285
13386   /* verify default ram value */
134   if (config!=NULL && ram_parse_string(config->default_size) == 0)
87   if (default_size() == 0)
13588   {
136      mame_printf_error("%s: '%s' has an invalid default RAM option: %s\n", driver->source_file, driver->name, config->default_size);
89      mame_printf_error("%s: '%s' has an invalid default RAM option: %s\n", driver.source_file, driver.name, m_default_size);
13790      error = TRUE;
13891   }
13992
14093   /* command line options are only parsed for the device named RAM_TAG */
141   if (device->tag()!=NULL && strcmp(device->tag(), RAM_TAG) == 0)
94   if (tag() != NULL && strcmp(tag(), RAM_TAG) == 0)
14295   {
14396      /* verify command line ram option */
14497      ramsize_string = options.ram_size();
r13256r13257
14699
147100      if ((ramsize_string != NULL) && (ramsize_string[0] != '\0'))
148101      {
149         specified_ram = ram_parse_string(ramsize_string);
102         specified_ram = parse_string(ramsize_string);
150103
151104         if (specified_ram == 0)
152105         {
153            mame_printf_error("%s: '%s' cannot recognize the RAM option %s\n", driver->source_file, driver->name, ramsize_string);
106            mame_printf_error("%s: '%s' cannot recognize the RAM option %s\n", driver.source_file, driver.name, ramsize_string);
154107            error = TRUE;
155108         }
156         if (gamename_option != NULL && *gamename_option != 0 && strcmp(gamename_option, driver->name) == 0)
109         if (gamename_option != NULL && *gamename_option != 0 && strcmp(gamename_option, driver.name) == 0)
157110         {
158111            /* compare command line option to default value */
159            if (ram_parse_string(config->default_size) == specified_ram)
112            if (default_size() == specified_ram)
160113               is_valid = TRUE;
161114
162115            /* verify extra ram options */
163            if (config->extra_options != NULL)
116            if (m_extra_options != NULL)
164117            {
165118               int j;
166               int size = strlen(config->extra_options);
167               char * const s = mame_strdup(config->extra_options);
119               int size = strlen(m_extra_options);
120               char * const s = mame_strdup(m_extra_options);
168121               char * const e = s + size;
169122               char *p = s;
170123               for (j=0;j<size;j++) {
r13256r13257
174127               /* try to parse each option */
175128               while(p <= e)
176129               {
177                  UINT32 option_ram_size = ram_parse_string(p);
130                  UINT32 option_ram_size = parse_string(p);
178131
179132                  if (option_ram_size == 0)
180133                  {
181                     mame_printf_error("%s: '%s' has an invalid RAM option: %s\n", driver->source_file, driver->name, p);
134                     mame_printf_error("%s: '%s' has an invalid RAM option: %s\n", driver.source_file, driver.name, p);
182135                     error = TRUE;
183136                  }
184137
r13256r13257
210163
211164   if (!is_valid)
212165   {
213      mame_printf_error("%s: '%s' cannot recognize the RAM option %s", driver->source_file, driver->name, ramsize_string);
214      mame_printf_error(" (valid options are %s", config->default_size);
166      mame_printf_error("%s: '%s' cannot recognize the RAM option %s", driver.source_file, driver.name, ramsize_string);
167      mame_printf_error(" (valid options are %s", m_default_size);
215168
216      if (config->extra_options != NULL)
217         mame_printf_error(",%s).\n", config->extra_options);
169      if (m_extra_options != NULL)
170         mame_printf_error(",%s).\n", m_extra_options);
218171      else
219172         mame_printf_error(").\n");
220173
r13256r13257
222175   }
223176
224177   return error;
225
226178}
227179
228180
229DEVICE_GET_INFO( ram )
181
182//-------------------------------------------------
183//  parse_string - convert a ram string to an
184//   integer value
185//-------------------------------------------------
186
187UINT32 ram_device::parse_string(const char *s)
230188{
231   switch (state)
189   UINT32 ram;
190   char suffix = '\0';
191
192   s += sscanf(s, "%u%c", &ram, &suffix);
193
194   switch(tolower(suffix))
232195   {
233      /* --- the following bits of info are returned as 64-bit signed integers --- */
234      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(ram_state);         break;
235      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = sizeof(ram_config);            break;
196      case 'k':
197         /* kilobytes */
198         ram *= 1024;
199         break;
236200
237      /* --- the following bits of info are returned as pointers to data or functions --- */
238      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(ram);   break;
239      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
240      case DEVINFO_FCT_RESET:                     /* Nothing */                        break;
241      case DEVINFO_FCT_VALIDITY_CHECK:            info->p = (void*)DEVICE_VALIDITY_CHECK_NAME(ram); break;
201      case 'm':
202         /* megabytes */
203         ram *= 1024*1024;
204         break;
242205
243      /* --- the following bits of info are returned as NULL-terminated strings --- */
244      case DEVINFO_STR_NAME:                     strcpy(info->s, "RAM");            break;
245      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "RAM");                  break;
246      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.00");               break;
247      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
248      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright MESS Team");      break;
206      case '\0':
207         /* no suffix */
208         break;
209
210      default:
211         /* parse failure */
212         ram = 0;
213         break;
249214   }
215
216   return ram;
250217}
251218
252/***************************************************************************
253    IMPLEMENTATION
254***************************************************************************/
255219
256UINT32 ram_get_size(device_t *device)
257{
258   ram_state *ram = get_safe_token(device);
259   return ram->size;
260}
261220
262UINT8 *ram_get_ptr(device_t *device)
221//-------------------------------------------------
222//  default_size
223//-------------------------------------------------
224
225UINT32 ram_device::default_size(void) const
263226{
264   ram_state *ram = get_safe_token(device);
265   return ram->ram;
227   return parse_string(m_default_size);
266228}
267
268DEFINE_LEGACY_DEVICE(RAM, ram);
src/emu/machine/ram.h
r13256r13257
1414    CONSTANTS
1515***************************************************************************/
1616
17#define RAM_DEFAULT_VALUE   0xcd
1817#define RAM_TAG            "ram"
1918
20/***************************************************************************
21    TYPE DEFINITIONS
22***************************************************************************/
2319
24typedef struct _ram_config ram_config;
25struct _ram_config
26{
27   const char *default_size;
28   const char *extra_options;
29   UINT8 default_value;
30};
31
32
3320/***************************************************************************
3421    DEVICE CONFIGURATION MACROS
3522***************************************************************************/
3623
37DECLARE_LEGACY_DEVICE(RAM, ram);
38
3924#define MCFG_RAM_ADD(_tag) \
40   MCFG_DEVICE_ADD(_tag, RAM, 0) \
41   MCFG_DEVICE_CONFIG_DATA32(ram_config, default_value, RAM_DEFAULT_VALUE)
25   MCFG_DEVICE_ADD(_tag, RAM, 0)
4226
4327#define MCFG_RAM_REMOVE(_tag) \
4428   MCFG_DEVICE_REMOVE(_tag)
4529
4630#define MCFG_RAM_MODIFY(_tag) \
4731   MCFG_DEVICE_MODIFY(_tag)   \
48   MCFG_DEVICE_CONFIG_DATAPTR(ram_config, extra_options, NULL)
32   ram_device::static_set_extra_options(*device, NULL);
4933
5034#define MCFG_RAM_DEFAULT_SIZE(_default_size) \
51   MCFG_DEVICE_CONFIG_DATAPTR(ram_config, default_size, _default_size)
35   ram_device::static_set_default_size(*device, _default_size);
5236
5337#define MCFG_RAM_EXTRA_OPTIONS(_extra_options) \
54   MCFG_DEVICE_CONFIG_DATAPTR(ram_config, extra_options, _extra_options)
38   ram_device::static_set_extra_options(*device, _extra_options);
5539
5640#define MCFG_RAM_DEFAULT_VALUE(_default_value) \
57   MCFG_DEVICE_CONFIG_DATA32(ram_config, default_value, _default_value)
41   ram_device::static_set_default_value(*device, _default_value);
5842
5943
6044/***************************************************************************
61    FUNCTION PROTOTYPES
45    TYPE DEFINITIONS
6246***************************************************************************/
6347
64UINT32 ram_get_size(device_t *device);
65UINT8 *ram_get_ptr(device_t *device);
66UINT32 ram_parse_string(const char *s);
48class ram_device :  public device_t
49{
50public:
51    // construction/destruction
52    ram_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
6753
54   // accessors
55   UINT32 size(void) const { return m_size; }
56   UINT8 *pointer(void) const { return m_pointer; }
57   static UINT32 parse_string(const char *s);
58   UINT32 default_size(void) const;
59   const char *extra_options(void) const { return m_extra_options; }
60
61   // inline configuration helpers
62   static void static_set_default_size(device_t &device, const char *default_size)      { downcast<ram_device &>(device).m_default_size = default_size; }
63   static void static_set_extra_options(device_t &device, const char *extra_options)   { downcast<ram_device &>(device).m_extra_options = extra_options; }
64   static void static_set_default_value(device_t &device, UINT8 default_value)         { downcast<ram_device &>(device).m_default_value = default_value; }
65
66protected:
67   virtual void device_start(void);
68   virtual bool device_validity_check(emu_options &options, const game_driver &driver) const;
69
70private:
71   // device state
72   UINT32 m_size;
73   UINT8 *m_pointer;
74
75   // device config
76   const char *m_default_size;
77   const char *m_extra_options;
78   UINT8 m_default_value;
79};
80
81
82// device type definition
83extern const device_type RAM;
84
85
86/***************************************************************************
87    LEGACY FUNCTION PROTOTYPES
88***************************************************************************/
89
90inline UINT32 ram_get_size(device_t *device)   { return downcast<ram_device *>(device)->size(); }
91inline UINT8 *ram_get_ptr(device_t *device)   { return downcast<ram_device *>(device)->pointer(); }
92
6893#endif /* __RAM_H__ */
src/emu/mame.h
r13256r13257
161161
162162// log to the standard error.log file
163163void CLIB_DECL logerror(const char *format,...) ATTR_PRINTF(1,2);
164void CLIB_DECL vlogerror(const char *format, va_list arg);
164165
165166
166167#endif   /* __MAME_H__ */
src/emu/screen.c
r13256r13257
10731073
10741074bool screen_device::screen_update(bitmap_t &bitmap, const rectangle &cliprect)
10751075{
1076   if (m_screen_update != NULL) {
1077      return (*m_screen_update)(this, &bitmap, &cliprect);
1078   } else {
1079      machine().driver_data<driver_device>()->screen_update(*this, bitmap, cliprect);
1080   }
1081   return 0;
1076    if (m_screen_update != NULL) {
1077       return (*m_screen_update)(this, &bitmap, &cliprect);
1078    } else {
1079      return machine().driver_data<driver_device>()->screen_update(*this, bitmap, cliprect);
1080    }
10821081}
10831082
10841083//-------------------------------------------------
src/mess/machine/coco.c
r13256r13257
11/***************************************************************************
22
3  machine/coco.c
3    coco.c
44
5    TRS-80 Radio Shack Color Computer Family
6
57  Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
68  I/O ports)
79
r13256r13257
4749    research that for you if you want an exact number for scanlines before the
4850    screen starts and the scanline that the v-interrupt triggers..etc.
4951
50Dragon Alpha code added 21-Oct-2004,
51            Phill Harvey-Smith (afra@aurigae.demon.co.uk)
52
53            Added AY-8912 and FDC code 30-Oct-2004.
54
55Fixed Dragon Alpha NMI enable/disable, following circuit traces on a real machine.
56    P.Harvey-Smith, 11-Aug-2005.
57
58Re-implemented Alpha NMI enable/disable, using direct PIA reads, rather than
59keeping track of it in a variable in the driver.
60    P.Harvey-Smith, 25-Sep-2006.
61
62Radically re-wrote memory emulation code for CoCo 1/2 & Dragon machines, the
63new code emulates the memory mapping of the SAM, dependent on what size of
64RAM chips it is programed to use, including proper mirroring of the RAM.
65
66Replaced the kludged emulation of the cart line, with a timer based trigger
67this is set to toggle at 1Hz, this seems to be good enough to trigger the
68cartline, but is so slow in real terms that it should have very little
69impact on the emulation speed.
70
71Re-factored the code common to all machines, and seperated the code different,
72into callbacks/functions unique to the machines, in preperation for splitting
73the code for individual machine types into seperate files, I have preposed, that
74the CoCo 1/2 should stay in coco.c, and that the coco3 and dragon specifc code
75should go into coco3.c and dragon.c which should (hopefully) make the code
76easier to manage.
77    P.Harvey-Smith, Dec 2006-Feb 2007
78
7952Added bi-directional bitbanger support. Also fixed reading PIA 1, port A. The
8053DAC and bitbanger values written should be reflected in the read.
8154    tim lindner, October 2010
8255
8356***************************************************************************/
8457
85#include <math.h>
86#include <assert.h>
87
88#include "emu.h"
89#include "debug/debugcpu.h"
90#include "cpu/m6809/m6809.h"
91#include "machine/6821pia.h"
9258#include "includes/coco.h"
93#include "includes/cococart.h"
94#include "machine/6883sam.h"
95#include "machine/6551acia.h"
96#include "video/coco6847.h"
97#include "formats/cocopak.h"
98#include "imagedev/bitbngr.h"
99#include "imagedev/printer.h"
100#include "imagedev/cassette.h"
101#include "machine/wd17xx.h"
102#include "sound/dac.h"
103#include "sound/ay8910.h"
104#include "machine/cococart.h"
105#include "imagedev/cartslot.h"
106#include "imagedev/flopdrv.h"
107#include "machine/ram.h"
108#include "crsshair.h"
59#include "cpu/m6809/m6809.h"
60#include "formats/coco_cas.h"
61#include "debug/debugcpu.h"
10962
110/***************************************************************************
111    PARAMETERS
112***************************************************************************/
11363
114/* this MUX delay was introduced to fix bug #655, but the delay was originally
115 * 16us.  This was reduced to 8us to fix bug #1608 */
116#define JOYSTICK_MUX_DELAY            attotime::from_usec(8)
11764
65//**************************************************************************
66//  CONSTANTS
67//**************************************************************************
11868
69#define LOG_INTERRUPTS      0
11970
120/***************************************************************************
121    LOCAL VARIABLES / PROTOTYPES
122***************************************************************************/
12371
124/*common vars/calls */
12572
126static WRITE8_DEVICE_HANDLER( d_pia1_pb_w );
127static WRITE8_DEVICE_HANDLER( d_pia1_pa_w );
128static READ8_DEVICE_HANDLER( d_pia1_pa_r );
129static WRITE8_DEVICE_HANDLER( d_pia0_pa_w );
130static WRITE8_DEVICE_HANDLER( d_pia0_pb_w );
131static WRITE8_DEVICE_HANDLER( d_pia1_cb2_w );
132static WRITE8_DEVICE_HANDLER( d_pia0_cb2_w );
133static WRITE8_DEVICE_HANDLER( d_pia1_ca2_w );
134static WRITE8_DEVICE_HANDLER( d_pia0_ca2_w );
135static WRITE_LINE_DEVICE_HANDLER( d_pia0_irq_a );
136static WRITE_LINE_DEVICE_HANDLER( d_pia0_irq_b );
137static WRITE_LINE_DEVICE_HANDLER( d_pia1_firq_a );
138static WRITE_LINE_DEVICE_HANDLER( d_pia1_firq_b );
139static SAM6883_SET_PAGE_ONE_MODE( d_sam_set_pageonemode );
140static SAM6883_SET_MPU_RATE( d_sam_set_mpurate );
141static SAM6883_SET_MEMORY_SIZE( d_sam_set_memorysize );
142static SAM6883_SET_MAP_TYPE( d_sam_set_maptype );
73//**************************************************************************
74//  BODY
75//**************************************************************************
14376
144/* CoCo 1 specific */
145static READ8_DEVICE_HANDLER ( d_pia1_pb_r_coco );
77//-------------------------------------------------
78//  ctor
79//-------------------------------------------------
14680
147/* CoCo 2 specific */
148static READ8_DEVICE_HANDLER ( d_pia1_pb_r_coco2 );
81coco_state::coco_state(const machine_config &mconfig, device_type type, const char *tag)
82   : driver_device(mconfig, type, tag),
83     m_maincpu(*this, MAINCPU_TAG),
84     m_pia_0(*this, PIA0_TAG),
85     m_pia_1(*this, PIA1_TAG),
86     m_dac(*this, DAC_TAG),
87     m_wave(*this, WAVE_TAG),
88     m_cococart(*this, CARTRIDGE_TAG),
89     m_ram(*this, RAM_TAG),
90     m_cassette(*this, CASSETTE_TAG),
91     m_bitbanger(*this, BITBANGER_TAG),
92     m_vhd(*this, VHD_TAG)
93{
94}
14995
150/* CoCo 3 specific */
15196
152static WRITE_LINE_DEVICE_HANDLER( coco3_pia0_irq_a );
153static WRITE_LINE_DEVICE_HANDLER( coco3_pia0_irq_b );
154static WRITE_LINE_DEVICE_HANDLER( coco3_pia1_firq_a );
155static WRITE_LINE_DEVICE_HANDLER( coco3_pia1_firq_b );
15697
157static SAM6883_SET_MAP_TYPE( coco3_sam_set_maptype );
158static SAM6883_GET_RAMBASE( coco3_sam_get_rambase );
98//-------------------------------------------------
99//  analog_port_start
100//-------------------------------------------------
159101
160/* Dragon 32 specific */
161static READ8_DEVICE_HANDLER ( d_pia1_pb_r_dragon32 );
102void coco_state::analog_port_start(analog_input_t *analog, const char *rx_tag, const char *ry_tag, const char *lx_tag, const char *ly_tag, const char *buttons_tag)
103{
104   analog->m_input[0][0] = machine().port(rx_tag);
105   analog->m_input[0][1] = machine().port(ry_tag);
106   analog->m_input[1][0] = machine().port(lx_tag);
107   analog->m_input[1][1] = machine().port(ly_tag);
108   analog->m_buttons = machine().port(buttons_tag);
109}
162110
163/* Dragon 64 / 64 Plus / Tano (Alpha) specific */
164static WRITE8_DEVICE_HANDLER ( dragon64_pia1_pb_w );
165111
166/* Dragon 64 / Alpha shared */
167static void dragon_page_rom(running_machine &machine, int romswitch);
168112
169/* Dragon Alpha specific */
170static WRITE8_DEVICE_HANDLER ( dgnalpha_pia2_pa_w );
171static WRITE_LINE_DEVICE_HANDLER( d_pia2_firq_a );
172static WRITE_LINE_DEVICE_HANDLER( d_pia2_firq_b );
113//-------------------------------------------------
114//  device_start
115//-------------------------------------------------
173116
174/* Memory map related CoCo 1/2 and Dragons only */
175static void setup_memory_map(running_machine &machine);
117void coco_state::device_start()
118{
119   /* call base device_start */
120   driver_device::device_start();
176121
122   /* look up keyboard ports */
123   for (int i = 0; i < sizeof(m_keyboard) / sizeof(m_keyboard[0]); i++)
124   {
125      char name[32];
126      snprintf(name, sizeof(name) / sizeof(name[0]), "row%d", i);
127      m_keyboard[i] = machine().port(name);
128   }
177129
178/* These sets of defines control logging.  When MAME_DEBUG is off, all logging
179 * is off.  There is a different set of defines for when MAME_DEBUG is on so I
180 * don't have to worry abount accidently committing a version of the driver
181 * with logging enabled after doing some debugging work
182 *
183 * Logging options marked as "Sparse" are logging options that happen rarely,
184 * and should not get in the way.  As such, these options are always on
185 * (assuming MAME_DEBUG is on).  "Frequent" options are options that happen
186 * enough that they might get in the way.
187 */
188#define LOG_PAK         0   /* [Sparse]   Logging on PAK trailers */
189#define LOG_INT_MASKING   1   /* [Sparse]   Logging on changing GIME interrupt masks */
190#define LOG_INT_COCO3   0
191#define LOG_GIME      0
192#define LOG_MMU         0
193#define LOG_TIMER       0
194#define LOG_CART   1      /* Log cart type selections is_dosrom and friends */
130   /* look up analog ports */
131   analog_port_start(&m_joystick, JOYSTICK_RX_TAG, JOYSTICK_RY_TAG,
132      JOYSTICK_LX_TAG, JOYSTICK_LY_TAG, JOYSTICK_BUTTONS_TAG);
133   analog_port_start(&m_rat_mouse, RAT_MOUSE_RX_TAG, RAT_MOUSE_RY_TAG,
134      RAT_MOUSE_LX_TAG, RAT_MOUSE_LY_TAG, RAT_MOUSE_BUTTONS_TAG);
135   analog_port_start(&m_diecom_lightgun, DIECOM_LIGHTGUN_RX_TAG, DIECOM_LIGHTGUN_RY_TAG,
136      DIECOM_LIGHTGUN_LX_TAG, DIECOM_LIGHTGUN_LY_TAG, DIECOM_LIGHTGUN_BUTTONS_TAG);
195137
196#define GIME_TYPE_1987   0
138   /* look up miscellaneous controls */
139   m_joystick_type_control = machine().port(CTRL_SEL_TAG);
140   m_joystick_hires_control = machine().port(HIRES_INTF_TAG);
197141
198static offs_t coco_dasm_override(device_t &device, char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, int options);
142   /* timers */
143   m_hiresjoy_transition_timer[0] = timer_alloc(TIMER_HIRES_JOYSTICK_X);
144   m_hiresjoy_transition_timer[1] = timer_alloc(TIMER_HIRES_JOYSTICK_Y);
145   m_diecom_lightgun_timer = timer_alloc(TIMER_DIECOM_LIGHTGUN);
199146
147   /* save state support */
148   save_item(NAME(m_dac_output));
149   save_item(NAME(m_hiresjoy_ca));
150   save_item(NAME(m_dclg_previous_bit));
151   save_item(NAME(m_dclg_output_h));
152   save_item(NAME(m_dclg_output_v));
153   save_item(NAME(m_dclg_state));
154   save_item(NAME(m_dclg_timer));
200155
201/* ----------------------------------------------------------------------- */
202/* The bordertop and borderbottom return values are used for calculating
203 * field sync timing.  Unfortunately, I cannot seem to find an agreement
204 * about how exactly field sync works..
205 *
206 * What I do know is that FS goes high at the top of the screen, and goes
207 * low (forcing an VBORD interrupt) at the bottom of the visual area.
208 *
209 * Unfortunately, I cannot get a straight answer about how many rows each
210 * of the three regions (leading edge --> visible top; visible top -->
211 * visible bottom/trailing edge; visible bottom/trailing edge --> leading
212 * edge) takes up.  Adding the fact that each of the different LPR
213 * settings most likely has a different set of values.  Here is a summary
214 * of what I know from different sources:
215 *
216 * In the January 1987 issue of Rainbow Magazine, there is a program called
217 * COLOR3 that uses midframe palette rotation to show all 64 colors on the
218 * screen at once.  The first box is at line 32, but it waits for 70 HSYNC
219 * transitions before changing
220 *
221 * SockMaster email: 43/192/28, 41/199/23, 132/0/131, 26/225/12
222 * m6847 reference:  38/192/32
223 * COLOR3            38/192/32
224 *
225 * Notes of interest:  Below are some observations of key programs and what
226 * they rely on:
227 *
228 *      COLOR3:
229 *           (fs_pia_flip ? fall_scanline : rise_scanline) = border_top - 32
230 */
156   /* set up disassembly override */
157   if (m_maincpu->debug())
158   {
159      m_maincpu->debug()->set_dasm_override(dasm_override);
160   }
161}
231162
232const struct coco3_video_vars coco3_vidvars =
233{
234   /* border tops */
235   38,   36, 132, 25,
236163
237   /* gime flip (hs/fs) */
238   0, 0,
239164
240   /* pia flip (hs/fs) */
241   1, 1,
165//-------------------------------------------------
166//  device_reset
167//-------------------------------------------------
242168
243   /* rise scanline & fall scanline */
244   258, 6
245};
169void coco_state::device_reset()
170{
171   /* call base device_start */
172   driver_device::device_reset();
246173
174   /* reset state */
175   m_dac_output = 0;
176   m_hiresjoy_ca = false;
177   m_dclg_previous_bit = false;
178   m_dclg_output_h = 0;
179   m_dclg_output_v = 0;
180   m_dclg_state = 0;
181   m_dclg_timer = 0;
182}
247183
248184
249/* ----------------------------------------------------------------------- */
250185
251/* PIA 0 */
252const pia6821_interface coco_pia_intf_0 =
253{
254   /*inputs : A/B,CA/B1,CA/B2 */
255   DEVCB_NULL,
256   DEVCB_NULL,
257   DEVCB_NULL,
258   DEVCB_NULL,
259   DEVCB_NULL,
260   DEVCB_NULL,
261   /*outputs: A/B,CA/B2       */
262   DEVCB_HANDLER(d_pia0_pa_w),
263   DEVCB_HANDLER(d_pia0_pb_w),
264   DEVCB_HANDLER(d_pia0_ca2_w),
265   DEVCB_HANDLER(d_pia0_cb2_w),
266   /*irqs   : A/B             */
267   DEVCB_LINE(d_pia0_irq_a),
268   DEVCB_LINE(d_pia0_irq_b)
269};
186//-------------------------------------------------
187//  device_timer
188//-------------------------------------------------
270189
271/* PIA 1 */
272const pia6821_interface coco_pia_intf_1 =
190void coco_state::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
273191{
274   /*inputs : A/B,CA/B1,CA/B2 */
275   DEVCB_HANDLER(d_pia1_pa_r),
276   DEVCB_HANDLER(d_pia1_pb_r_coco),
277   DEVCB_NULL,
278   DEVCB_NULL,
279   DEVCB_NULL,
280   DEVCB_NULL,
281   /*outputs: A/B,CA/B2       */
282   DEVCB_HANDLER(d_pia1_pa_w),
283   DEVCB_HANDLER(d_pia1_pb_w),
284   DEVCB_HANDLER(d_pia1_ca2_w),
285   DEVCB_HANDLER(d_pia1_cb2_w),
286   /*irqs   : A/B             */
287   DEVCB_LINE(d_pia1_firq_a),
288   DEVCB_LINE(d_pia1_firq_b)
289};
192   switch(id)
193   {
194      case TIMER_HIRES_JOYSTICK_X:
195      case TIMER_HIRES_JOYSTICK_Y:
196      case TIMER_DIECOM_LIGHTGUN:
197         poll_keyboard();
198         break;
199   }
200}
290201
291/* PIA 0 */
292const pia6821_interface coco2_pia_intf_0 =
293{
294   /*inputs : A/B,CA/B1,CA/B2 */
295   DEVCB_NULL,
296   DEVCB_NULL,
297   DEVCB_NULL,
298   DEVCB_NULL,
299   DEVCB_NULL,
300   DEVCB_NULL,
301   /*outputs: A/B,CA/B2       */
302   DEVCB_HANDLER(d_pia0_pa_w),
303   DEVCB_HANDLER(d_pia0_pb_w),
304   DEVCB_HANDLER(d_pia0_ca2_w),
305   DEVCB_HANDLER(d_pia0_cb2_w),
306   /*irqs   : A/B             */
307   DEVCB_LINE(d_pia0_irq_a),
308   DEVCB_LINE(d_pia0_irq_b)
309};
310202
311/* PIA 1 */
312const pia6821_interface coco2_pia_intf_1 =
313{
314   /*inputs : A/B,CA/B1,CA/B2 */
315   DEVCB_HANDLER(d_pia1_pa_r),
316   DEVCB_HANDLER(d_pia1_pb_r_coco2),
317   DEVCB_NULL,
318   DEVCB_NULL,
319   DEVCB_NULL,
320   DEVCB_NULL,
321   /*outputs: A/B,CA/B2       */
322   DEVCB_HANDLER(d_pia1_pa_w),
323   DEVCB_HANDLER(d_pia1_pb_w),
324   DEVCB_HANDLER(d_pia1_ca2_w),
325   DEVCB_HANDLER(d_pia1_cb2_w),
326   /*irqs   : A/B             */
327   DEVCB_LINE(d_pia1_firq_a),
328   DEVCB_LINE(d_pia1_firq_b)
329};
330203
331/* PIA 0 */
332const pia6821_interface coco3_pia_intf_0 =
333{
334   /*inputs : A/B,CA/B1,CA/B2 */
335   DEVCB_NULL,
336   DEVCB_NULL,
337   DEVCB_NULL,
338   DEVCB_NULL,
339   DEVCB_NULL,
340   DEVCB_NULL,
341   /*outputs: A/B,CA/B2       */
342   DEVCB_HANDLER(d_pia0_pa_w),
343   DEVCB_HANDLER(d_pia0_pb_w),
344   DEVCB_HANDLER(d_pia0_ca2_w),
345   DEVCB_HANDLER(d_pia0_cb2_w),
346   /*irqs   : A/B             */
347   DEVCB_LINE(coco3_pia0_irq_a),
348   DEVCB_LINE(coco3_pia0_irq_b)
349};
204/***************************************************************************
205  PIA0 ($FF00-$FF1F) (Chip U8)
350206
351/* PIA 1 */
352const pia6821_interface coco3_pia_intf_1 =
353{
354   /*inputs : A/B,CA/B1,CA/B2 */
355   DEVCB_HANDLER(d_pia1_pa_r),
356   DEVCB_HANDLER(d_pia1_pb_r_coco2),
357   DEVCB_NULL,
358   DEVCB_NULL,
359   DEVCB_NULL,
360   DEVCB_NULL,
361   /*outputs: A/B,CA/B2       */
362   DEVCB_HANDLER(d_pia1_pa_w),
363   DEVCB_HANDLER(d_pia1_pb_w),
364   DEVCB_HANDLER(d_pia1_ca2_w),
365   DEVCB_HANDLER(d_pia1_cb2_w),
366   /*irqs   : A/B             */
367   DEVCB_LINE(coco3_pia1_firq_a),
368   DEVCB_LINE(coco3_pia1_firq_b)
369};
207  PIA0 PA0-PA7  - Keyboard/Joystick read
208  PIA0 PB0-PB7  - Keyboard write
209  PIA0 CA1      - MC6847 HS (Horizontal Sync)
210  PIA0 CA2      - SEL1 (Used by sound mux and joystick)
211  PIA0 CB1      - MC6847 FS (Field Sync)
212  PIA0 CB2      - SEL2 (Used by sound mux and joystick)
213***************************************************************************/
370214
371/* PIA 0 */
372const pia6821_interface dragon32_pia_intf_0 =
373{
374   /*inputs : A/B,CA/B1,CA/B2 */
375   DEVCB_NULL,
376   DEVCB_NULL,
377   DEVCB_NULL,
378   DEVCB_NULL,
379   DEVCB_NULL,
380   DEVCB_NULL,
381   /*outputs: A/B,CA/B2       */
382   DEVCB_HANDLER(d_pia0_pa_w),
383   DEVCB_HANDLER(d_pia0_pb_w),
384   DEVCB_HANDLER(d_pia0_ca2_w),
385   DEVCB_HANDLER(d_pia0_cb2_w),
386   /*irqs   : A/B             */
387   DEVCB_LINE(d_pia0_irq_a),
388   DEVCB_LINE(d_pia0_irq_b)
389};
215//-------------------------------------------------
216//  ff00_write
217//-------------------------------------------------
390218
391/* PIA 1 */
392const pia6821_interface dragon32_pia_intf_1 =
219READ8_MEMBER( coco_state::ff00_read )
393220{
394   /*inputs : A/B,CA/B1,CA/B2 */
395   DEVCB_HANDLER(d_pia1_pa_r),
396   DEVCB_HANDLER(d_pia1_pb_r_dragon32),
397   DEVCB_NULL,
398   DEVCB_NULL,
399   DEVCB_NULL,
400   DEVCB_NULL,
401   /*outputs: A/B,CA/B2       */
402   DEVCB_HANDLER(d_pia1_pa_w),
403   DEVCB_HANDLER(d_pia1_pb_w),
404   DEVCB_HANDLER(d_pia1_ca2_w),
405   DEVCB_HANDLER(d_pia1_cb2_w),
406   /*irqs   : A/B             */
407   DEVCB_LINE(d_pia1_firq_a),
408   DEVCB_LINE(d_pia1_firq_b)
409};
221   return m_pia_0->read(space, offset, mem_mask);
222}
410223
411/* PIA 0 */
412const pia6821_interface dragon64_pia_intf_0 =
413{
414   /*inputs : A/B,CA/B1,CA/B2 */
415   DEVCB_NULL,
416   DEVCB_NULL,
417   DEVCB_NULL,
418   DEVCB_NULL,
419   DEVCB_NULL,
420   DEVCB_NULL,
421   /*outputs: A/B,CA/B2       */
422   DEVCB_HANDLER(d_pia0_pa_w),
423   DEVCB_HANDLER(d_pia0_pb_w),
424   DEVCB_HANDLER(d_pia0_ca2_w),
425   DEVCB_HANDLER(d_pia0_cb2_w),
426   /*irqs   : A/B             */
427   DEVCB_LINE(d_pia0_irq_a),
428   DEVCB_LINE(d_pia0_irq_b)
429};
430224
431/* PIA 1 */
432const pia6821_interface dragon64_pia_intf_1 =
433{
434   /*inputs : A/B,CA/B1,CA/B2 */
435   DEVCB_HANDLER(d_pia1_pa_r),
436   DEVCB_HANDLER(d_pia1_pb_r_coco),
437   DEVCB_NULL,
438   DEVCB_NULL,
439   DEVCB_NULL,
440   DEVCB_NULL,
441   /*outputs: A/B,CA/B2       */
442   DEVCB_HANDLER(d_pia1_pa_w),
443   DEVCB_HANDLER(dragon64_pia1_pb_w),
444   DEVCB_HANDLER(d_pia1_ca2_w),
445   DEVCB_HANDLER(d_pia1_cb2_w),
446   /*irqs   : A/B             */
447   DEVCB_LINE(d_pia1_firq_a),
448   DEVCB_LINE(d_pia1_firq_b)
449};
450225
451/* PIA 0 and 1 as Dragon 64 */
452/* PIA 0 */
453const pia6821_interface dgnalpha_pia_intf_0 =
454{
455   /*inputs : A/B,CA/B1,CA/B2 */
456   DEVCB_NULL,
457   DEVCB_NULL,
458   DEVCB_NULL,
459   DEVCB_NULL,
460   DEVCB_NULL,
461   DEVCB_NULL,
462   /*outputs: A/B,CA/B2       */
463   DEVCB_HANDLER(d_pia0_pa_w),
464   DEVCB_HANDLER(d_pia0_pb_w),
465   DEVCB_HANDLER(d_pia0_ca2_w),
466   DEVCB_HANDLER(d_pia0_cb2_w),
467   /*irqs   : A/B             */
468   DEVCB_LINE(d_pia0_irq_a),
469   DEVCB_LINE(d_pia0_irq_b)
470};
226//-------------------------------------------------
227//  ff00_write
228//-------------------------------------------------
471229
472/* PIA 1 */
473const pia6821_interface dgnalpha_pia_intf_1 =
230WRITE8_MEMBER( coco_state::ff00_write )
474231{
475   /*inputs : A/B,CA/B1,CA/B2 */
476   DEVCB_HANDLER(d_pia1_pa_r),
477   DEVCB_HANDLER(d_pia1_pb_r_coco),
478   DEVCB_NULL,
479   DEVCB_NULL,
480   DEVCB_NULL,
481   DEVCB_NULL,
482   /*outputs: A/B,CA/B2       */
483   DEVCB_HANDLER(d_pia1_pa_w),
484   DEVCB_HANDLER(d_pia1_pb_w),
485   DEVCB_HANDLER(d_pia1_ca2_w),
486   DEVCB_HANDLER(d_pia1_cb2_w),
487   /*irqs   : A/B             */
488   DEVCB_LINE(d_pia1_firq_a),
489   DEVCB_LINE(d_pia1_firq_b)
490};
232   m_pia_0->write(space, offset, data, mem_mask);
233}
491234
492/* PIA 2 */
493const pia6821_interface dgnalpha_pia_intf_2 =
494{
495   /*inputs : A/B,CA/B1,CA/B2 */
496   DEVCB_NULL,
497   DEVCB_NULL,
498   DEVCB_NULL,
499   DEVCB_NULL,
500   DEVCB_NULL,
501   DEVCB_NULL,
502   /*outputs: A/B,CA/B2       */
503   DEVCB_HANDLER(dgnalpha_pia2_pa_w),
504   DEVCB_NULL,
505   DEVCB_NULL,
506   DEVCB_NULL,
507   /*irqs   : A/B             */
508   DEVCB_LINE(d_pia2_firq_a),
509   DEVCB_LINE(d_pia2_firq_b)
510};
511235
512const sam6883_interface coco_sam_intf =
513{
514   NULL,
515   d_sam_set_pageonemode,
516   d_sam_set_mpurate,
517   d_sam_set_memorysize,
518   d_sam_set_maptype
519};
520236
521const sam6883_interface coco3_sam_intf =
237//-------------------------------------------------
238//  pia0_pb_w
239//-------------------------------------------------
240
241WRITE8_MEMBER( coco_state::pia0_pb_w )
522242{
523   coco3_sam_get_rambase,
524   NULL,
525   d_sam_set_mpurate,
526   NULL,
527   coco3_sam_set_maptype
528};
243   poll_keyboard();
244}
529245
530246
531247
532/***************************************************************************
533    IMPLEMENTATION
534***************************************************************************/
248//-------------------------------------------------
249//  pia0_ca2_w
250//-------------------------------------------------
535251
536/***************************************************************************
537  PAK files
538
539  PAK files were originally for storing Program PAKs, but the file format has
540  evolved into a snapshot file format, with a file format so convoluted and
541  changing to make it worthy of Microsoft.
542***************************************************************************/
543
544static int load_pak_into_region(device_image_interface &image, int *pakbase, int *paklen, UINT8 *mem, int segaddr, int seglen)
252WRITE_LINE_MEMBER( coco_state::pia0_ca2_w )
545253{
546   if (*paklen)
547   {
548      if (*pakbase < segaddr)
549      {
550         /* We have to skip part of the PAK file */
551         int skiplen;
254   update_sound();
255   poll_keyboard();
256}
552257
553         skiplen = segaddr - *pakbase;
554         if (image.fseek(skiplen, SEEK_CUR))
555         {
556            if (LOG_PAK)
557               logerror("Could not fully read PAK.\n");
558            return 1;
559         }
560258
561         *pakbase += skiplen;
562         *paklen -= skiplen;
563      }
564259
565      if (*pakbase < segaddr + seglen)
566      {
567         mem += *pakbase - segaddr;
568         seglen -= *pakbase - segaddr;
260//-------------------------------------------------
261//  pia0_cb2_w
262//-------------------------------------------------
569263
570         if (seglen > *paklen)
571            seglen = *paklen;
572
573         if (image.fread( mem, seglen) < seglen)
574         {
575            if (LOG_PAK)
576               logerror("Could not fully read PAK.\n");
577            return 1;
578         }
579
580         *pakbase += seglen;
581         *paklen -= seglen;
582      }
583   }
584   return 0;
264WRITE_LINE_MEMBER( coco_state::pia0_cb2_w )
265{
266   update_sound();
267   poll_keyboard();
585268}
586269
587static void pak_load_trailer(running_machine &machine, const pak_decodedtrailer *trailer)
588{
589   coco_state *state = machine.driver_data<coco_state>();
590270
591   cpu_set_reg(machine.device("maincpu"), M6809_PC, trailer->reg_pc);
592   cpu_set_reg(machine.device("maincpu"), M6809_X, trailer->reg_x);
593   cpu_set_reg(machine.device("maincpu"), M6809_Y, trailer->reg_y);
594   cpu_set_reg(machine.device("maincpu"), M6809_U, trailer->reg_u);
595   cpu_set_reg(machine.device("maincpu"), M6809_S, trailer->reg_s);
596   cpu_set_reg(machine.device("maincpu"), M6809_DP, trailer->reg_dp);
597   cpu_set_reg(machine.device("maincpu"), M6809_B, trailer->reg_b);
598   cpu_set_reg(machine.device("maincpu"), M6809_A, trailer->reg_a);
599   cpu_set_reg(machine.device("maincpu"), M6809_CC, trailer->reg_cc);
600271
601   /* I seem to only be able to get a small amount of the PIA state from the
602     * snapshot trailers. Thus I am going to configure the PIA myself. The
603     * following PIA writes are the same thing that the CoCo ROM does on
604     * startup. I wish I had a better solution
605     */
272//-------------------------------------------------
273//  pia0_irq_a
274//-------------------------------------------------
606275
607   state->m_pia_0->write(*memory_nonspecific_space(machine), 1, 0x00);
608   state->m_pia_0->write(*memory_nonspecific_space(machine), 3, 0x00);
609   state->m_pia_0->write(*memory_nonspecific_space(machine), 0, 0x00);
610   state->m_pia_0->write(*memory_nonspecific_space(machine), 2, 0xff);
611   state->m_pia_1->write(*memory_nonspecific_space(machine), 1, 0x00);
612   state->m_pia_1->write(*memory_nonspecific_space(machine), 3, 0x00);
613   state->m_pia_1->write(*memory_nonspecific_space(machine), 0, 0xfe);
614   state->m_pia_1->write(*memory_nonspecific_space(machine), 2, 0xf8);
276WRITE_LINE_MEMBER( coco_state::pia0_irq_a )
277{
278   recalculate_irq();
279}
615280
616   state->m_pia_0->write(*memory_nonspecific_space(machine), 1, trailer->pia[1]);
617   state->m_pia_0->write(*memory_nonspecific_space(machine), 0, trailer->pia[0]);
618   state->m_pia_0->write(*memory_nonspecific_space(machine), 3, trailer->pia[3]);
619   state->m_pia_0->write(*memory_nonspecific_space(machine), 2, trailer->pia[2]);
620281
621   state->m_pia_1->write(*memory_nonspecific_space(machine), 1, trailer->pia[5]);
622   state->m_pia_1->write(*memory_nonspecific_space(machine), 0, trailer->pia[4]);
623   state->m_pia_1->write(*memory_nonspecific_space(machine), 3, trailer->pia[7]);
624   state->m_pia_1->write(*memory_nonspecific_space(machine), 2, trailer->pia[6]);
625282
626   /* For some reason, specifying use of high ram seems to screw things up;
627     * I'm not sure whether it is because I'm using the wrong method to get
628     * access that bit or or whether it is something else.  So that is why
629     * I am specifying 0x7fff instead of 0xffff here
630     */
631   sam6883_set_state(state->m_sam, trailer->sam, 0x7fff);
632}
283//-------------------------------------------------
284//  pia0_irq_b
285//-------------------------------------------------
633286
634static int generic_pak_load(device_image_interface &image, int rambase_index, int rombase_index, int pakbase_index)
287WRITE_LINE_MEMBER( coco_state::pia0_irq_b )
635288{
636   UINT8 *ROM;
637   UINT8 *rambase;
638   UINT8 *rombase;
639   UINT8 *pakbase;
640   int paklength;
641   int pakstart;
642   pak_header header;
643   int trailerlen;
644   UINT8 trailerraw[500];
645   pak_decodedtrailer trailer;
646   int trailer_load = 0;
289   recalculate_irq();
290}
647291
648   ROM = image.device().machine().region("maincpu")->base();
649   rambase = &ram_get_ptr(image.device().machine().device(RAM_TAG))[rambase_index];
650   rombase = &ROM[rombase_index];
651   pakbase = &ROM[pakbase_index];
652292
653   if (ram_get_size(image.device().machine().device(RAM_TAG)) < 0x10000)
654   {
655      if (LOG_PAK)
656         logerror("Cannot load PAK files without at least 64k.\n");
657      return IMAGE_INIT_FAIL;
658   }
659293
660   if (image.fread( &header, sizeof(header)) < sizeof(header))
661   {
662      if (LOG_PAK)
663         logerror("Could not fully read PAK.\n");
664      return IMAGE_INIT_FAIL;
665   }
294//-------------------------------------------------
295//  pia0_config
296//-------------------------------------------------
666297
667   paklength = header.length ? LITTLE_ENDIANIZE_INT16(header.length) : 0x10000;
668   pakstart = LITTLE_ENDIANIZE_INT16(header.start);
298const pia6821_interface coco_state::pia0_config =
299{
300   DEVCB_NULL,                                       /* port A input */
301   DEVCB_NULL,                                       /* port B input */
302   DEVCB_NULL,                                       /* CA1 input */
303   DEVCB_NULL,                                       /* CB1 input */
304   DEVCB_NULL,                                       /* CA2 input */
305   DEVCB_NULL,                                       /* CB2 input */
306   DEVCB_NULL,                                     /* port A output */
307   DEVCB_DRIVER_MEMBER(coco_state, pia0_pb_w),               /* port B output */
308   DEVCB_DRIVER_LINE_MEMBER(coco_state, pia0_ca2_w),         /* CA2 output */
309   DEVCB_DRIVER_LINE_MEMBER(coco_state, pia0_cb2_w),         /* CB2 output */
310   DEVCB_DRIVER_LINE_MEMBER(coco_state, pia0_irq_a),         /* IRQA output */
311   DEVCB_DRIVER_LINE_MEMBER(coco_state, pia0_irq_b)         /* IRQB output */
312};
669313
670   if (image.fseek(paklength, SEEK_CUR))
671   {
672      if (LOG_PAK)
673         logerror("Could not fully read PAK.\n");
674      return IMAGE_INIT_FAIL;
675   }
676314
677   trailerlen = image.fread( trailerraw, sizeof(trailerraw));
678   if (trailerlen)
679   {
680      if (pak_decode_trailer(trailerraw, trailerlen, &trailer))
681      {
682         if (LOG_PAK)
683            logerror("Invalid or unknown PAK trailer.\n");
684         return IMAGE_INIT_FAIL;
685      }
686315
687      trailer_load = 1;
688   }
316/***************************************************************************
317  PIA1 ($FF20-$FF3F) (Chip U4)
689318
690   if (image.fseek(sizeof(pak_header), SEEK_SET))
691   {
692      if (LOG_PAK)
693         logerror("Unexpected error while reading PAK.\n");
694      return IMAGE_INIT_FAIL;
695   }
319  PIA1 PA0      - CASSDIN
320  PIA1 PA1      - RS232 OUT (CoCo), Printer Strobe (Dragon)
321  PIA1 PA2-PA7  - DAC
322  PIA1 PB0      - RS232 IN
323  PIA1 PB1      - Single bit sound
324  PIA1 PB2      - RAMSZ (32/64K, 16K, and 4K three position switch)
325  PIA1 PB3      - M6847 CSS
326  PIA1 PB4      - M6847 INT/EXT and M6847 GM0
327  PIA1 PB5      - M6847 GM1
328  PIA1 PB6      - M6847 GM2
329  PIA1 PB7      - M6847 A/G
330  PIA1 CA1      - CD (Carrier Detect; NYI)
331  PIA1 CA2      - CASSMOT (Cassette Motor)
332  PIA1 CB1      - CART (Cartridge Detect)
333  PIA1 CB2      - SNDEN (Sound Enable)
334***************************************************************************/
696335
697   /* Now that we are done reading the trailer; we can cap the length */
698   if (paklength > 0xff00)
699      paklength = 0xff00;
336//-------------------------------------------------
337//  ff20_read
338//-------------------------------------------------
700339
701   /* PAK files reflect the fact that JeffV's emulator did not appear to
702     * differentiate between RAM and ROM memory.  So what we do when a PAK
703     * loads is to copy the ROM into RAM, load the PAK into RAM, and then
704     * copy the part of RAM corresponding to PAK ROM to the actual PAK ROM
705     * area.
706     *
707     * It is ugly, but it reflects the way that JeffV's emulator works
708     */
340READ8_MEMBER( coco_state::ff20_read )
341{
342   return m_pia_1->read(space, offset, mem_mask);
343}
709344
710   memcpy(rambase + 0x8000, rombase, 0x4000);
711   memcpy(rambase + 0xC000, pakbase, 0x3F00);
712345
713   /* Get the RAM portion */
714   if (load_pak_into_region(image, &pakstart, &paklength, rambase, 0x0000, 0xff00))
715      return IMAGE_INIT_FAIL;
716346
717   memcpy(pakbase, rambase + 0xC000, 0x3F00);
347//-------------------------------------------------
348//  ff20_write
349//-------------------------------------------------
718350
719   if (trailer_load)
720      pak_load_trailer(image.device().machine(), &trailer);
721   return IMAGE_INIT_PASS;
722}
723
724SNAPSHOT_LOAD ( coco_pak )
351WRITE8_MEMBER( coco_state::ff20_write )
725352{
726   return generic_pak_load(image, 0x0000, 0x0000, 0x4000);
727}
353   /* write to the PIA */
354   m_pia_1->write(space, offset, data, mem_mask);
728355
729SNAPSHOT_LOAD ( coco3_pak )
730{
731   return generic_pak_load(image, (0x70000 % ram_get_size(image.device().machine().device(RAM_TAG))), 0x0000, 0xc000);
356   /* we have to do this to do something that approximates the cartridge Q line behavior */
357   m_cococart->twiddle_q_lines();
732358}
733359
734/***************************************************************************
735  Quickloads
736***************************************************************************/
737360
738QUICKLOAD_LOAD ( coco )
739{
740   UINT8 preamble;
741   UINT16 block_length;
742   UINT16 block_address;
743   const UINT8 *ptr;
744   UINT32 length;
745   UINT32 position = 0;
746   UINT32 i;
747   int done = FALSE;
748361
749   /* access the pointer and the length */
750   ptr = (const UINT8*)image.ptr();
751   length = image.length();
362//-------------------------------------------------
363//  pia1_pa_r
364//-------------------------------------------------
752365
753   while(!done && (position + 5 <= length))
754   {
755      /* read this block */
756      preamble      = ptr[position + 0];
757      block_length   = ((UINT16) ptr[position + 1]) << 8 | ((UINT16) ptr[position + 2]) << 0;
758      block_address   = ((UINT16) ptr[position + 3]) << 8 | ((UINT16) ptr[position + 4]) << 0;
759      position += 5;
760
761      if (preamble != 0)
762      {
763         /* start address - just set the address and return */
764         cpu_set_reg(image.device().machine().device("maincpu"), STATE_GENPC, block_address);
765         done = TRUE;
766      }
767      else
768      {
769         address_space *space = image.device().machine().device( "maincpu")->memory().space( AS_PROGRAM );
770
771         /* data block - need to cap the maximum length of the block */
772         block_length = MIN(block_length, length - position);
773
774         /* read the block into memory */
775         for (i = 0; i < block_length; i++)
776         {
777            space->write_byte(block_address + i, ptr[position + i]);
778         }
779
780         /* and advance */
781         position += block_length;
782      }
783   }
784   return IMAGE_INIT_PASS;
366READ8_MEMBER( coco_state::pia1_pa_r )
367{
368   return (m_cassette->input() >= 0 ? 0x01 : 0x00)
369      | (dac_output() << 2);
785370}
786371
787/***************************************************************************
788  ROM files
789372
790  ROM files are simply raw dumps of cartridges.  I believe that they should
791  be used in place of PAK files, when possible
792***************************************************************************/
793373
794// These are directly handled by ROM_CART_LOAD with no custom DEVICE_IMAGE_LOAD
374//-------------------------------------------------
375//  pia1_pb_r - this handles the reading of the
376//   memory sense switch (PB2) for the CoCo 1 and
377//   serial-in (PB0)
378//-------------------------------------------------
795379
796/***************************************************************************
797  Interrupts
380READ8_MEMBER( coco_state::pia1_pb_r )
381{
382   UINT32 ram_size = m_ram->size();
798383
799  The Dragon/CoCo2 have two PIAs.  These PIAs can trigger interrupts.  PIA0
800  is set up to trigger IRQ on the CPU, and PIA1 can trigger FIRQ.  Each PIA
801  has two output lines, and an interrupt will be triggered if either of these
802  lines are asserted.
384   //   For the CoCo 1, the logic has been changed to only select 64K rams
385   //   if there is more than 16K of memory, as the Color Basic 1.0 rom
386   //   can only configure 4K or 16K ram banks (as documented in "Color
387   //   Basic Unreveled"), doing this allows this  allows the coco driver
388   //   to access 32K of ram, and also allows the cocoe driver to access
389   //   the full 64K, as this uses Color Basic 1.2, which can configure 64K rams
390   bool memory_sense = (ram_size >= 0x4000 && ram_size <= 0x7FFF)
391      || (ram_size >= 0x8000 && (m_pia_0->b_output() & 0x80));
803392
804  -----  IRQ
805  6809 |-<----------- PIA0
806       |
807       |
808       |
809       |
810       |
811       |-<----------- PIA1
812  -----
393   // serial in (PB0)
394   bool serial_in = (m_bitbanger != NULL) && (m_bitbanger->input() ? true : false);
813395
814  The CoCo 3 still supports these interrupts, but the GIME can chose whether
815  "old school" interrupts are generated, or the new ones generated by the GIME
396   // composite the results
397   return (memory_sense ? 0x04 : 0x00)
398      | (serial_in ? 0x01 : 0x00);
399}
816400
817  -----  IRQ
818  6809 |-<----------- PIA0
819       |       |                ------
820       |       -<-------<-------|    |
821       |                        |GIME|
822       |       -<-------<-------|    |
823       | FIRQ  |                ------
824       |-<----------- PIA1
825  -----
826401
827  In an email discussion with JK, he informs me that when GIME interrupts are
828  enabled, this actually does not prevent PIA interrupts.  Apparently JeffV's
829  CoCo 3 emulator did not handle this properly.
830***************************************************************************/
831402
832enum
833{
834   COCO3_INT_TMR   = 0x20,      /* Timer */
835   COCO3_INT_HBORD   = 0x10,      /* Horizontal border sync */
836   COCO3_INT_VBORD   = 0x08,      /* Vertical border sync */
837   COCO3_INT_EI2   = 0x04,      /* Serial data */
838   COCO3_INT_EI1   = 0x02,      /* Keyboard */
839   COCO3_INT_EI0   = 0x01,      /* Cartridge */
403//-------------------------------------------------
404//  pia1_pa_w
405//-------------------------------------------------
840406
841   COCO3_INT_ALL   = 0x3f
842};
843
844static void d_recalc_irq(running_machine &machine)
407WRITE8_MEMBER( coco_state::pia1_pa_w )
845408{
846   coco_state *state = machine.driver_data<coco_state>();
847   UINT8 pia0_irq_a = state->m_pia_0->irq_a_state();
848   UINT8 pia0_irq_b = state->m_pia_0->irq_b_state();
849
850   if (pia0_irq_a || pia0_irq_b)
851      cputag_set_input_line(machine, "maincpu", M6809_IRQ_LINE, ASSERT_LINE);
852   else
853      cputag_set_input_line(machine, "maincpu", M6809_IRQ_LINE, CLEAR_LINE);
409   pia1_pa_changed();
854410}
855411
856static void d_recalc_firq(running_machine &machine)
857{
858   coco_state *state = machine.driver_data<coco_state>();
859   UINT8 pia1_firq_a = state->m_pia_1->irq_a_state();
860   UINT8 pia1_firq_b = state->m_pia_1->irq_b_state();
861   UINT8 pia2_firq_a = (state->m_pia_2 != NULL) ? state->m_pia_2->irq_a_state() : 0x00;
862   UINT8 pia2_firq_b = (state->m_pia_2 != NULL) ? state->m_pia_2->irq_b_state() : 0x00;
863412
864   if (pia1_firq_a || pia1_firq_b || pia2_firq_a || pia2_firq_b)
865      cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, ASSERT_LINE);
866   else
867      cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, CLEAR_LINE);
868}
869413
870static void coco3_recalc_irq(running_machine &machine)
871{
872   coco3_state *state = machine.driver_data<coco3_state>();
873   if ((state->m_gimereg[0] & 0x20) && state->m_gime_irq)
874      cputag_set_input_line(machine, "maincpu", M6809_IRQ_LINE, ASSERT_LINE);
875   else
876      d_recalc_irq(machine);
877}
414//-------------------------------------------------
415//  pia1_pb_w
416//-------------------------------------------------
878417
879static void coco3_recalc_firq(running_machine &machine)
418WRITE8_MEMBER( coco_state::pia1_pb_w )
880419{
881   coco3_state *state = machine.driver_data<coco3_state>();
882   if ((state->m_gimereg[0] & 0x10) && state->m_gime_firq)
883      cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, ASSERT_LINE);
884   else
885      d_recalc_firq(machine);
420   pia1_pb_changed();
886421}
887422
888static WRITE_LINE_DEVICE_HANDLER( d_pia0_irq_a )
889{
890   d_recalc_irq(device->machine());
891}
892423
893static WRITE_LINE_DEVICE_HANDLER( d_pia0_irq_b )
894{
895   d_recalc_irq(device->machine());
896}
897424
898static WRITE_LINE_DEVICE_HANDLER( d_pia1_firq_a )
899{
900   d_recalc_firq(device->machine());
901}
425//-------------------------------------------------
426//  pia1_ca2_w
427//-------------------------------------------------
902428
903static WRITE_LINE_DEVICE_HANDLER( d_pia1_firq_b )
429WRITE_LINE_MEMBER( coco_state::pia1_ca2_w )
904430{
905   d_recalc_firq(device->machine());
431   m_cassette->change_state(
432      state ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED,
433      CASSETTE_MASK_MOTOR);
906434}
907435
908/* Dragon Alpha second PIA IRQ lines also cause FIRQ */
909static WRITE_LINE_DEVICE_HANDLER( d_pia2_firq_a )
910{
911   d_recalc_firq(device->machine());
912}
913436
914static WRITE_LINE_DEVICE_HANDLER( d_pia2_firq_b )
915{
916   d_recalc_firq(device->machine());
917}
918437
919static WRITE_LINE_DEVICE_HANDLER( coco3_pia0_irq_a )
920{
921   coco3_recalc_irq(device->machine());
922}
438//-------------------------------------------------
439//  pia1_cb2_w
440//-------------------------------------------------
923441
924static WRITE_LINE_DEVICE_HANDLER( coco3_pia0_irq_b )
442WRITE_LINE_MEMBER( coco_state::pia1_cb2_w )
925443{
926   coco3_recalc_irq(device->machine());
927}
444   poll_keyboard();
928445
929static WRITE_LINE_DEVICE_HANDLER( coco3_pia1_firq_a )
930{
931   coco3_recalc_firq(device->machine());
446   // Theoretically, I should be calling update_sound() here; however this seems to create
447   // a buzzing in some CoCo software (e.g. - Popcorn).  This is likely because this line
448   // drives the MC14529B MUX, and when disabled the output probably goes hi-Z.
932449}
933450
934static WRITE_LINE_DEVICE_HANDLER( coco3_pia1_firq_b )
935{
936   coco3_recalc_firq(device->machine());
937}
938451
939static void coco3_raise_interrupt(running_machine &machine, UINT8 mask, int state)
940{
941   coco3_state *drvstate = machine.driver_data<coco3_state>();
942   int lowtohigh;
943452
944   lowtohigh = state && ((drvstate->m_interupt_line & mask) == 0);
453//-------------------------------------------------
454//  pia1_firq_a
455//-------------------------------------------------
945456
946   if (state)
947      drvstate->m_interupt_line |= mask;
948   else
949      drvstate->m_interupt_line &= ~mask;
950
951   if (lowtohigh)
952   {
953      if ((drvstate->m_gimereg[0] & 0x20) && (drvstate->m_gimereg[2] & mask))
954      {
955         drvstate->m_gime_irq |= (drvstate->m_gimereg[2] & mask);
956         coco3_recalc_irq(machine);
957
958         if (LOG_INT_COCO3)
959            logerror("CoCo3 Interrupt: Raising IRQ; scanline=%i\n", machine.primary_screen->vpos());
960      }
961      if ((drvstate->m_gimereg[0] & 0x10) && (drvstate->m_gimereg[3] & mask))
962      {
963         drvstate->m_gime_firq |= (drvstate->m_gimereg[3] & mask);
964         coco3_recalc_firq(machine);
965
966         if (LOG_INT_COCO3)
967            logerror("CoCo3 Interrupt: Raising FIRQ; scanline=%i\n", machine.primary_screen->vpos());
968      }
969   }
457WRITE_LINE_MEMBER( coco_state::pia1_firq_a )
458{
459   recalculate_firq();
970460}
971461
972462
973463
974void coco3_horizontal_sync_callback(running_machine &machine,int data)
464//-------------------------------------------------
465//  pia1_firq_b
466//-------------------------------------------------
467
468WRITE_LINE_MEMBER( coco_state::pia1_firq_b )
975469{
976   coco_state *state = machine.driver_data<coco_state>();
977   state->m_pia_0->ca1_w(data);
978   coco3_raise_interrupt(machine, COCO3_INT_HBORD, data);
470   recalculate_firq();
979471}
980472
981473
982474
983void coco3_field_sync_callback(running_machine &machine,int data)
984{
985   coco_state *state = machine.driver_data<coco_state>();
986   state->m_pia_0->cb1_w(data);
987}
475//-------------------------------------------------
476//  pia1_config
477//-------------------------------------------------
988478
989void coco3_gime_field_sync_callback(running_machine &machine)
479const pia6821_interface coco_state::pia1_config =
990480{
991   /* the CoCo 3 VBORD interrupt triggers right after the display */
992   coco3_raise_interrupt(machine, COCO3_INT_VBORD, 1);
993   coco3_raise_interrupt(machine, COCO3_INT_VBORD, 0);
994}
481   DEVCB_DRIVER_MEMBER(coco_state, pia1_pa_r),               /* port A input */
482   DEVCB_DRIVER_MEMBER(coco_state, pia1_pb_r),               /* port B input */
483   DEVCB_NULL,                                       /* CA1 input */
484   DEVCB_NULL,                                       /* CB1 input */
485   DEVCB_NULL,                                       /* CA2 input */
486   DEVCB_NULL,                                       /* CB2 input */
487   DEVCB_DRIVER_MEMBER(coco_state, pia1_pa_w),               /* port A output */
488   DEVCB_DRIVER_MEMBER(coco_state, pia1_pb_w),               /* port B output */
489   DEVCB_DRIVER_LINE_MEMBER(coco_state, pia1_ca2_w),         /* CA2 output */
490   DEVCB_DRIVER_LINE_MEMBER(coco_state, pia1_cb2_w),         /* CB2 output */
491   DEVCB_DRIVER_LINE_MEMBER(coco_state, pia1_firq_a),         /* IRQA output */
492   DEVCB_DRIVER_LINE_MEMBER(coco_state, pia1_firq_b)         /* IRQB output */
493};
995494
996495
997496
998497/***************************************************************************
999  Halt line
1000***************************************************************************/
498  CPU INTERRUPTS
1001499
1002static TIMER_CALLBACK(d_recalc_interrupts)
1003{
1004   d_recalc_firq(machine);
1005   d_recalc_irq(machine);
1006}
500  The Dragon/CoCo2 have two PIAs.  These PIAs can trigger interrupts.  PIA0
501  is set up to trigger IRQ on the CPU, and PIA1 can trigger FIRQ.  Each PIA
502  has two output lines, and an interrupt will be triggered if either of these
503  lines are asserted.
1007504
1008static TIMER_CALLBACK(coco3_recalc_interrupts)
1009{
1010   coco3_recalc_firq(machine);
1011   coco3_recalc_irq(machine);
1012}
505  -----  IRQ
506  6809 |-<----------- PIA0
507       |
508       |
509       |
510       |
511       |
512       |-<----------- PIA1
513  -----
1013514
515***************************************************************************/
1014516
1015#ifdef UNUSED_FUNCTION
1016void coco_set_halt_line(running_machine &machine, int halt_line)
517//-------------------------------------------------
518//  irq_get_line - gets the value of the FIRQ line
519//   passed into the CPU
520//-------------------------------------------------
521
522bool coco_state::irq_get_line(void)
1017523{
1018   coco_state *state = machine.driver_data<coco_state>();
1019   cpunum_set_input_line(machine, 0, INPUT_LINE_HALT, halt_line);
1020   if (halt_line == CLEAR_LINE)
1021      machine.scheduler().timer_set(machine.device<cpu_device>("maincpu")->cycles_to_attotime(1), FUNC(state->m_recalc_interrupts));
524   return m_pia_0->irq_a_state() || m_pia_0->irq_b_state();
1022525}
1023#endif
1024526
1025527
1026/***************************************************************************
1027  Hires Joystick
1028***************************************************************************/
1029528
529//-------------------------------------------------
530//  recalculate_irq
531//-------------------------------------------------
1030532
1031static attotime coco_hiresjoy_computetransitiontime( running_machine &machine, UINT8 port, UINT8 axis )
533void coco_state::recalculate_irq(void)
1032534{
1033   double val;
1034   UINT8 hires = input_port_read_safe(machine, "hires_intf", 0x00);
1035   /* this function gets only called for hi-res joystick. hence, hires can only take values
1036       0x01, 0x03 (hi-res) or 0x02, 0x04 (hi-res coco3max) */
1037   UINT8 coco3max = (hires == 0x02 || hires == 0x04) ? 1 : 0;
535   bool line = irq_get_line();
536   if (LOG_INTERRUPTS)
537      logerror("recalculate_irq():  line=%d\n", line ? 1 : 0);
538   m_maincpu->set_input_line(M6809_IRQ_LINE, line ? ASSERT_LINE : CLEAR_LINE);
539}
1038540
1039   static const char *const port_tags[4] = {"joystick_rx", "joystick_ry", "joystick_lx", "joystick_ly"};
1040541
1041   val = input_port_read_safe(machine, port_tags[axis + 2 * port], 0) / 255.0;
1042542
1043   if (coco3max)
1044   {
1045      /* CoCo MAX 3 Interface */
1046      val = val * 2500.0 + 400.0;
1047   }
1048   else
1049   {
1050      /* Normal Hires Interface */
1051      val = val * 4160.0 + 592.0;
1052   }
543//-------------------------------------------------
544//  firq_get_line - gets the value of the FIRQ line
545//   passed into the CPU
546//-------------------------------------------------
1053547
1054   return (machine.time() + (COCO_CPU_SPEED * val));
1055}
1056
1057static void coco_hiresjoy_w( running_machine &machine, int data, UINT8 port )
548bool coco_state::firq_get_line(void)
1058549{
1059   coco_state *state = machine.driver_data<coco_state>();
1060   if (!data && state->m_hiresjoy_ca)
1061   {
1062      /* Hi to lo */
1063      state->m_hiresjoy_xtransitiontime = coco_hiresjoy_computetransitiontime(machine, port, 0);
1064      state->m_hiresjoy_ytransitiontime = coco_hiresjoy_computetransitiontime(machine, port, 1);
1065   }
1066   else if (data && !state->m_hiresjoy_ca)
1067   {
1068      /* Lo to hi */
1069      state->m_hiresjoy_xtransitiontime = attotime::zero;
1070      state->m_hiresjoy_ytransitiontime = attotime::zero;
1071   }
1072   state->m_hiresjoy_ca = data;
1073   (*state->update_keyboard)(machine);
550   return m_pia_1->irq_a_state() || m_pia_1->irq_b_state();
1074551}
1075552
1076static int coco_hiresjoy_readone( running_machine &machine, attotime transitiontime )
1077{
1078   return machine.time() >= transitiontime;
1079}
1080553
1081static int coco_hiresjoy_rx( running_machine &machine )
1082{
1083   coco_state *state = machine.driver_data<coco_state>();
1084   return coco_hiresjoy_readone(machine, state->m_hiresjoy_xtransitiontime);
1085}
1086554
1087static int coco_hiresjoy_ry( running_machine &machine )
555//-------------------------------------------------
556//  recalculate_firq
557//-------------------------------------------------
558
559void coco_state::recalculate_firq(void)
1088560{
1089   coco_state *state = machine.driver_data<coco_state>();
1090   return coco_hiresjoy_readone(machine, state->m_hiresjoy_ytransitiontime);
561   bool line = firq_get_line();
562   if (LOG_INTERRUPTS)
563      logerror("recalculate_firq():  line=%d\n", line ? 1 : 0);
564   m_maincpu->set_input_line(M6809_FIRQ_LINE, line ? ASSERT_LINE : CLEAR_LINE);
1091565}
1092566
567
568
1093569/***************************************************************************
1094  Sound MUX
570  SOUND / KEYBOARD / JOYSTICK
1095571
1096572  The sound MUX has 4 possible settings, depend on SELA and SELB inputs:
1097573
r13256r13257
1100576  10    - SND input from cartridge (NYI because we only support the FDC)
1101577  11    - Grounded (0)
1102578
579  Source - Tandy Color Computer Service Manual
580
1103581  Note on the Dragon Alpha state 11, selects the AY-3-8912, this is currently
1104582  un-implemented - phs.
1105583
1106  Source - Tandy Color Computer Service Manual
1107584***************************************************************************/
1108585
1109#define SOUNDMUX_STATUS_ENABLE   4
1110#define SOUNDMUX_STATUS_SEL2   2
1111#define SOUNDMUX_STATUS_SEL1   1
586//-------------------------------------------------
587//  soundmux_status
588//-------------------------------------------------
1112589
1113static cassette_image_device *cassette_device_image(running_machine &machine)
590coco_state::soundmux_status_t coco_state::soundmux_status(void)
1114591{
1115   coco_state *state = machine.driver_data<coco_state>();
1116   return state->m_cassette_device;
592   return (soundmux_status_t) (
593      (snden() ? SOUNDMUX_ENABLE : 0) |
594      (sel1()  ? SOUNDMUX_SEL1 : 0) |
595      (sel2()  ? SOUNDMUX_SEL2 : 0));
1117596}
1118597
1119static device_t *bitbanger_image(running_machine &machine)
1120{
1121   coco_state *state = machine.driver_data<coco_state>();
1122   return state->m_bitbanger_device;
1123}
1124598
1125static printer_image_device *printer_image(running_machine &machine)
1126{
1127   coco_state *state = machine.driver_data<coco_state>();
1128   return state->m_printer_device;
1129}
1130599
1131static cococart_slot_device *cococart_device(running_machine &machine)
1132{
1133   coco_state *state = machine.driver_data<coco_state>();
1134   return state->m_cococart_device;
1135}
600//-------------------------------------------------
601//  update_sound
602//-------------------------------------------------
1136603
1137static int get_soundmux_status(running_machine &machine)
604void coco_state::update_sound(void)
1138605{
1139   coco_state *state = machine.driver_data<coco_state>();
606   /* PB1 will drive the sound output.  This is a rarely
607     * used single bit sound mode. It is always connected thus
608     * cannot be disabled.
609     *
610     * Source:  Page 31 of the Tandy Color Computer Serice Manual
611     */
612   UINT8 single_bit_sound = (m_pia_1->b_output() & 0x02) ? 0x80 : 0x00;
1140613
1141   int soundmux_status = 0;
1142   if (state->m_pia_1->cb2_output())
1143      soundmux_status |= SOUNDMUX_STATUS_ENABLE;
1144   if (state->m_mux_sel1)
1145      soundmux_status |= SOUNDMUX_STATUS_SEL1;
1146   if (state->m_mux_sel2)
1147      soundmux_status |= SOUNDMUX_STATUS_SEL2;
1148   return soundmux_status;
1149}
614   /* determine the sound mux status */
615   soundmux_status_t status = soundmux_status();
1150616
1151static void soundmux_update(running_machine &machine)
1152{
1153   /* This function is called whenever the MUX (selector switch) is changed
1154     * It mainly turns on and off the cassette audio depending on the switch.
1155     * It also calls a function into the cartridges device to tell it if it is
1156     * switch on or off.
1157     */
1158   cassette_state new_state;
1159   int soundmux_status = get_soundmux_status(machine);
617   /* determine the value to send to the DAC */
618   m_dac_output = (m_pia_1->a_output() & 0xFC) >> 2;
619   UINT8 sound_output = single_bit_sound + (status == SOUNDMUX_ENABLE ? m_dac_output << 1 : 0);
620   dac_data_w(m_dac, sound_output);
1160621
1161   switch(soundmux_status) {
1162   case SOUNDMUX_STATUS_ENABLE | SOUNDMUX_STATUS_SEL1:
1163      /* CSN */
1164      new_state = CASSETTE_SPEAKER_ENABLED;
1165      break;
1166   default:
1167      new_state = CASSETTE_SPEAKER_MUTED;
1168      break;
1169   }
622   /* determine the cassette sound status */
623   cassette_state cas_sound = (status == (SOUNDMUX_ENABLE | SOUNDMUX_SEL1))
624      ? CASSETTE_SPEAKER_ENABLED
625      : CASSETTE_SPEAKER_MUTED;
626   m_cassette->change_state(cas_sound, CASSETTE_MASK_SPEAKER);
1170627
1171   cococart_device(machine)->cart_set_line(
628   /* determine the cartridge sound status */
629   m_cococart->cart_set_line(
1172630      COCOCART_LINE_SOUND_ENABLE,
1173      (soundmux_status == (SOUNDMUX_STATUS_ENABLE|SOUNDMUX_STATUS_SEL2)
1174         ? COCOCART_LINE_VALUE_ASSERT : COCOCART_LINE_VALUE_CLEAR));
1175   cassette_device_image(machine)->change_state(new_state,CASSETTE_MASK_SPEAKER);
631      (status == (SOUNDMUX_ENABLE | SOUNDMUX_SEL2)) ? COCOCART_LINE_VALUE_ASSERT : COCOCART_LINE_VALUE_CLEAR);
1176632}
1177633
1178static void coco_sound_update(running_machine &machine)
1179{
1180   coco_state *state = machine.driver_data<coco_state>();
1181634
1182   /* Call this function whenever you need to update the sound. It will
1183     * automatically mute any devices that are switched out.
1184     */
1185   UINT8 dac = state->m_pia_1->a_output() & 0xFC;
1186   UINT8 pia1_pb1 = (state->m_pia_1->b_output() & 0x02) ? 0x80 : 0x00;
1187   int soundmux_status = get_soundmux_status(machine);
1188635
1189   switch(soundmux_status)
1190   {
1191      case SOUNDMUX_STATUS_ENABLE:
1192         /* DAC */
1193         dac_data_w(state->m_dac, pia1_pb1 + (dac >> 1) );  /* Mixing the two sources */
1194         break;
1195      case SOUNDMUX_STATUS_ENABLE | SOUNDMUX_STATUS_SEL1:
1196         /* CSN */
1197         dac_data_w(state->m_dac, pia1_pb1); /* Mixing happens elsewhere */
1198         break;
1199      case SOUNDMUX_STATUS_ENABLE | SOUNDMUX_STATUS_SEL2:
1200         /* CART Sound */
1201         dac_data_w(state->m_dac, pia1_pb1); /* To do: mix in cart signal */
1202         break;
1203      default:
1204         /* This pia line is always connected to the output */
1205         dac_data_w(state->m_dac, pia1_pb1);
1206         break;
1207   }
1208}
636//-------------------------------------------------
637//  joystick_type - returns the type of joystick
638//   in the specified port
639//-------------------------------------------------
1209640
1210/*
1211    Dragon Alpha AY-3-8912
1212*/
1213
1214READ8_HANDLER ( dgnalpha_psg_porta_read )
641coco_state::joystick_type_t coco_state::joystick_type(int index)
1215642{
1216   return 0;
643   assert((index == 0) || (index == 1));
644   return (m_joystick_type_control != NULL)
645      ? (joystick_type_t) ((input_port_read_direct(m_joystick_type_control) >> (index * 4)) & 0x0F)
646      : JOYSTICK_NONE;
1217647}
1218648
1219WRITE8_HANDLER( dgnalpha_psg_porta_write )
1220{
1221   device_t *fdc = space->machine().device("wd2797");
1222   /* Bits 0..3 are the drive select lines for the internal floppy interface */
1223   /* Bit 4 is the motor on, in the real hardware these are inverted on their way to the drive */
1224   /* Bits 5,6,7 are connected to /DDEN, ENP and 5/8 on the WD2797 */
1225   switch (data & 0xF)
1226   {
1227      case(0x01) :
1228         wd17xx_set_drive(fdc,0);
1229         break;
1230      case(0x02) :
1231         wd17xx_set_drive(fdc,1);
1232         break;
1233      case(0x04) :
1234         wd17xx_set_drive(fdc,2);
1235         break;
1236      case(0x08) :
1237         wd17xx_set_drive(fdc,3);
1238         break;
1239   }
1240}
1241649
1242/***************************************************************************
1243  PIA0 ($FF00-$FF1F) (Chip U8)
1244650
1245  PIA0 PA0-PA7  - Keyboard/Joystick read
1246  PIA0 PB0-PB7  - Keyboard write
1247  PIA0 CA1      - M6847 HS (Horizontal Sync)
1248  PIA0 CA2      - SEL1 (Used by sound mux and joystick)
1249  PIA0 CB1      - M6847 FS (Field Sync)
1250  PIA0 CB2      - SEL2 (Used by sound mux and joystick)
1251***************************************************************************/
651//-------------------------------------------------
652//  hires_interface_type
653//-------------------------------------------------
1252654
1253static WRITE8_DEVICE_HANDLER( d_pia0_ca2_w )
655coco_state::hires_type_t coco_state::hires_interface_type(void)
1254656{
1255   coco_state *state = device->machine().driver_data<coco_state>();
1256   state->m_mux_sel1_timer->adjust(JOYSTICK_MUX_DELAY, data);
657   return (m_joystick_hires_control != NULL)
658      ? (hires_type_t) input_port_read_direct(m_joystick_hires_control)
659      : HIRES_NONE;
1257660}
1258661
1259static TIMER_CALLBACK( coco_update_sel1_timerproc )
1260{
1261   coco_state *state = machine.driver_data<coco_state>();
1262   state->m_mux_sel1 = param;
1263   (*state->update_keyboard)(machine);
1264   soundmux_update(machine);
1265}
1266662
1267static WRITE8_DEVICE_HANDLER( d_pia0_cb2_w )
1268{
1269   coco_state *state = device->machine().driver_data<coco_state>();
1270   state->m_mux_sel2_timer->adjust(JOYSTICK_MUX_DELAY, data);
1271}
1272663
1273static TIMER_CALLBACK( coco_update_sel2_timerproc )
664//-------------------------------------------------
665//  is_joystick_hires
666//-------------------------------------------------
667
668bool coco_state::is_joystick_hires(int joystick_index)
1274669{
1275   coco_state *state = machine.driver_data<coco_state>();
1276   state->m_mux_sel2 = param;
1277   (*state->update_keyboard)(machine);
1278   soundmux_update(machine);
1279}
670   bool result;
671   assert((joystick_index == 0) || (joystick_index == 1));
1280672
673   switch(hires_interface_type())
674   {
675      case HIRES_RIGHT:
676      case HIRES_RIGHT_COCOMAX3:
677         result = (joystick_index == 0);
678         break;
1281679
1282static attotime get_relative_time( running_machine &machine, attotime absolute_time )
1283{
1284   attotime result;
1285   attotime now = machine.time();
680      case HIRES_LEFT:
681      case HIRES_LEFT_COCOMAX3:
682         result = (joystick_index == 1);
683         break;
1286684
1287   if (absolute_time > now)
1288      result = absolute_time - now;
1289   else
1290      result = attotime::never;
685      default:
686         result = false;
687         break;
688   }
1291689   return result;
1292690}
1293691
1294692
1295693
1296static UINT8 coco_update_keyboard( running_machine &machine )
694//-------------------------------------------------
695//  poll_joystick
696//-------------------------------------------------
697
698void coco_state::poll_joystick(bool *joyin, UINT8 *buttons)
1297699{
1298   coco_state *state = machine.driver_data<coco_state>();
1299   UINT8 porta = 0x7f, port_za = 0x7f;
1300   int joyval;
700   static const analog_input_t s_empty = {};
1301701   static const int joy_rat_table[] = {15, 24, 42, 33 };
1302702   static const int dclg_table[] = {0, 14, 30, 49 };
1303   attotime dclg_time = attotime::zero;
1304   UINT8 pia0_pb;
1305   UINT8 dac = state->m_pia_1->a_output() & 0xfc;
1306   UINT8 hires = input_port_read_safe(machine, "hires_intf", 0x00);
1307   int joystick_axis, joystick, joy_mask, joy_shift, ctrl, hires_val, cc3m_val;
1308703
1309   static const char *const portnames[2][4][2] =
1310         {
1311            { {0}, {"joystick_rx", "joystick_ry"}, {"rat_mouse_rx", "rat_mouse_ry"}, {"dclg_rx", "dclg_ry"} },   /* right ports */
1312            { {0}, {"joystick_lx", "joystick_ly"}, {"rat_mouse_lx", "rat_mouse_ly"}, {"dclg_lx", "dclg_ly"} },   /* left ports */
1313         };
1314   static const char *const button_names[4] = { "empty", "joystick_buttons", "rat_mouse_buttons", "dclg_triggers" };
704   /* identify the joystick and axis */
705   int joystick_axis = sel1() ? 1 : 0;
706   int joystick = sel2() ? 1 : 0;
1315707
1316
1317
1318   pia0_pb = state->m_pia_0->b_output();
1319   joystick_axis = state->m_mux_sel1;
1320   joystick = state->m_mux_sel2;
1321
1322   /* which kind of controller is selected? */
1323   joy_mask = joystick ? 0xf0 : 0x0f;
1324   joy_shift = joystick ? 4 : 0;
1325   ctrl = (input_port_read_safe(machine, "ctrl_sel", 0x00) & joy_mask) >> joy_shift;
1326
1327   /* is any Hi-Res Interface turned on? prepare masks to check it */
1328   hires_val = joystick ? 0x03 : 0x01;
1329   cc3m_val = joystick ? 0x04 : 0x02;
1330
1331   /* poll keyboard keys */
1332   if ((input_port_read(machine, "row0") | pia0_pb) != 0xff) porta &= ~0x01;
1333   if ((input_port_read(machine, "row1") | pia0_pb) != 0xff) porta &= ~0x02;
1334   if ((input_port_read(machine, "row2") | pia0_pb) != 0xff) porta &= ~0x04;
1335   if ((input_port_read(machine, "row3") | pia0_pb) != 0xff) porta &= ~0x08;
1336   if ((input_port_read(machine, "row4") | pia0_pb) != 0xff) porta &= ~0x10;
1337   if ((input_port_read(machine, "row5") | pia0_pb) != 0xff) porta &= ~0x20;
1338   if ((input_port_read(machine, "row6") | pia0_pb) != 0xff) porta &= ~0x40;
1339
1340   if ((input_port_read(machine, "row0") | state->m_pia_0->port_b_z_mask()) != 0xff) port_za &= ~0x01;
1341   if ((input_port_read(machine, "row1") | state->m_pia_0->port_b_z_mask()) != 0xff) port_za &= ~0x02;
1342   if ((input_port_read(machine, "row2") | state->m_pia_0->port_b_z_mask()) != 0xff) port_za &= ~0x04;
1343   if ((input_port_read(machine, "row3") | state->m_pia_0->port_b_z_mask()) != 0xff) port_za &= ~0x08;
1344   if ((input_port_read(machine, "row4") | state->m_pia_0->port_b_z_mask()) != 0xff) port_za &= ~0x10;
1345   if ((input_port_read(machine, "row5") | state->m_pia_0->port_b_z_mask()) != 0xff) port_za &= ~0x20;
1346   if ((input_port_read(machine, "row6") | state->m_pia_0->port_b_z_mask()) != 0xff) port_za &= ~0x40;
1347
1348   switch (ctrl)
708   /* determine the JOYIN value */
709   const analog_input_t *analog;
710   bool joyin_value;
711   UINT8 joyval;
712   int dclg_vpos;
713   switch(joystick_type(joystick))
1349714   {
1350      case 0x01: /* Joystick */
1351         if (hires == hires_val || hires == cc3m_val)
715      case JOYSTICK_NORMAL:
716         analog = &m_joystick;
717
718         /* is any Hi-Res Interface turned on? prepare masks to check it */
719         if (is_joystick_hires(joystick))
1352720         {
1353            /* Hi-Res Joystick or Hi-Res CoCo3Max Joystick */
1354            if (joystick_axis ? coco_hiresjoy_ry(machine) : coco_hiresjoy_rx(machine))
1355               porta |= 0x80;
721            /* hi-res joystick or hi-res CoCo3Max joystick */
722            attotime remaining = m_hiresjoy_transition_timer[joystick_axis]->remaining();
723            joyin_value = remaining < attotime::zero;
1356724         }
1357725         else
1358726         {
1359            joyval = input_port_read_safe(machine, portnames[joystick][ctrl][joystick_axis], 0x00);
1360            if (dac <= joyval)
1361               porta |= 0x80;
727            /* conventional joystick */
728            joyval = analog->input(joystick, joystick_axis);
729            joyin_value = (dac_output() <= (joyval >> 2));
1362730         }
1363731         break;
1364732
1365      case 0x02: /* Rat Mouse */
1366         joyval = input_port_read_safe(machine, portnames[joystick][ctrl][joystick_axis], 0x00);
1367         if ((dac >> 2) <= joy_rat_table[joyval])
1368            porta |= 0x80;
733      case JOYSTICK_RAT_MOUSE:
734         analog = &m_rat_mouse;
735         joyval = analog->input(joystick, joystick_axis);
736         joyin_value = dac_output() <= joy_rat_table[joyval];
1369737         break;
1370738
1371      case 0x03: /* Diecom Light Gun */
1372         if ((machine.primary_screen->vpos() == input_port_read_safe(machine, portnames[joystick][ctrl][1], 0)))
739      case JOYSTICK_DIECOM_LIGHT_GUN:
740         analog = &m_diecom_lightgun;
741
742         /* get the vertical position of the lightgun */
743         dclg_vpos = analog->input(joystick, 1);
744
745         if (machine().primary_screen->vpos() == dclg_vpos)
1373746         {
1374            /* If gun is pointing at the current scan line, set hit bit and cache horizontal timer value */
1375            state->m_dclg_output_h |= 0x02;
1376            state->m_dclg_timer = input_port_read_safe(machine, portnames[joystick][ctrl][0], 0) << 1;
747            /* if gun is pointing at the current scan line, set hit bit and cache horizontal timer value */
748            m_dclg_output_h |= 0x02;
749            m_dclg_timer = analog->input(joystick, 0) << 1;
1377750         }
1378751
1379         if ((dac >> 2) <= dclg_table[(joystick_axis ? state->m_dclg_output_h : state->m_dclg_output_v) & 0x03])
1380            porta |= 0x80;
752         joyin_value = (dac_output() <= dclg_table[(joystick_axis ? m_dclg_output_h : m_dclg_output_v) & 0x03]);
1381753
1382         if (state->m_dclg_state == 7)
754         if (m_dclg_state == 7)
1383755         {
1384            /* While in state 7, prepare to chech next video frame for a hit */
1385            dclg_time = machine.primary_screen->time_until_pos(input_port_read_safe(machine, portnames[joystick][ctrl][1], 0), 0);
756            /* while in state 7, prepare to check next video frame for a hit */
757            attotime dclg_time = machine().primary_screen->time_until_pos(dclg_vpos, 0);
758            m_diecom_lightgun_timer->adjust(dclg_time);
1386759         }
1387
1388760         break;
1389761
1390      default: /* No Controller */
762      default: /* None */
763         analog = &s_empty;
764         joyin_value = false;
1391765         break;
1392766   }
1393767
1394   if (dclg_time != attotime::zero)
1395   {
1396      /* schedule lightgun events */
1397      state->m_update_keyboard_timer->reset(dclg_time);
1398   }
1399   else
1400   {
1401      /* schedule hires joystick events */
1402      attotime xtrans = get_relative_time(machine, state->m_hiresjoy_xtransitiontime);
1403      attotime ytrans = get_relative_time(machine, state->m_hiresjoy_ytransitiontime);
1404
1405      state->m_update_keyboard_timer->reset(
1406         (xtrans > ytrans) ? ytrans : xtrans);
1407   }
1408
1409   /* sample joystick buttons */
1410   porta &= ~input_port_read_safe(machine, button_names[ctrl], 0);
1411   port_za &= ~input_port_read_safe(machine, button_names[ctrl], 0);
1412
1413   state->m_pia_0->set_a_input(porta, port_za);
1414   return porta;
768   *joyin = joyin_value;
769   *buttons = analog->buttons();
1415770}
1416771
1417772
1418773
1419static UINT8 coco3_update_keyboard( running_machine &machine )
1420{
1421   /* the CoCo 3 keyboard update routine must also check for the GIME EI1 interrupt */
1422   UINT8 porta = coco_update_keyboard(machine);
1423   coco3_raise_interrupt(machine, COCO3_INT_EI1, ((porta & 0x7f) == 0x7f) ? CLEAR_LINE : ASSERT_LINE);
1424   return porta;
1425}
774//-------------------------------------------------
775//  poll_keyboard
776//-------------------------------------------------
1426777
1427
1428
1429/* three functions that update the keyboard in varying ways */
1430static WRITE8_DEVICE_HANDLER( d_pia0_pb_w )
778void coco_state::poll_keyboard(void)
1431779{
1432   coco_state *state = device->machine().driver_data<coco_state>();
1433   (*state->update_keyboard)(device->machine());
1434}
780   UINT8 pia0_pb = m_pia_0->b_output();
781   UINT8 pia0_pb_z = m_pia_0->port_b_z_mask();
1435782
1436INPUT_CHANGED( coco_keyboard_changed )
1437{
1438   coco_state *state = field.machine().driver_data<coco_state>();
1439   (*state->update_keyboard)(field.machine());
1440}
783   UINT8 pia0_pa = 0x7F;
784   UINT8 pia0_pa_z = 0x7F;
1441785
1442static TIMER_CALLBACK( coco_m_update_keyboard_timerproc )
1443{
1444   coco_state *state = machine.driver_data<coco_state>();
1445   (*state->update_keyboard)(machine);
1446}
1447
1448static WRITE8_DEVICE_HANDLER( d_pia0_pa_w )
1449{
1450   UINT8 ctrl = input_port_read_safe(device->machine(), "ctrl_sel", 0x00);
1451   UINT8 hires = input_port_read_safe(device->machine(), "hires_intf", 0x00);
1452
1453   /* Hi-Res CC3Max Joystick (either in Left or in Right Port) writes here */
1454   if ((ctrl & 0x0f) == 0x01 && hires == 0x02)
1455      coco_hiresjoy_w(device->machine(), data & 0x04, 0);
1456   else if ((ctrl & 0xf0) == 0x10 && hires == 0x04)
1457      coco_hiresjoy_w(device->machine(), data & 0x08, 1);
1458}
1459
1460
1461/***************************************************************************
1462  PIA1 ($FF20-$FF3F) (Chip U4)
1463
1464  PIA1 PA0      - CASSDIN
1465  PIA1 PA1      - RS232 OUT (CoCo), Printer Strobe (Dragon)
1466  PIA1 PA2-PA7  - DAC
1467  PIA1 PB0      - RS232 IN
1468  PIA1 PB1      - Single bit sound
1469  PIA1 PB2      - RAMSZ (32/64K, 16K, and 4K three position switch)
1470  PIA1 PB3      - M6847 CSS
1471  PIA1 PB4      - M6847 INT/EXT and M6847 GM0
1472  PIA1 PB5      - M6847 GM1
1473  PIA1 PB6      - M6847 GM2
1474  PIA1 PB7      - M6847 A/G
1475  PIA1 CA1      - CD (Carrier Detect; NYI)
1476  PIA1 CA2      - CASSMOT (Cassette Motor)
1477  PIA1 CB1      - CART (Cartridge Detect)
1478  PIA1 CB2      - SNDEN (Sound Enable)
1479***************************************************************************/
1480
1481static WRITE8_DEVICE_HANDLER ( d_pia1_cb2_w )
1482{
1483   soundmux_update(device->machine());
1484}
1485
1486/* Printer output functions used by d_pia1_pa_w */
1487
1488/* Printer output for the CoCo, output to bitbanger port */
1489static void printer_out_coco(running_machine &machine, int data)
1490{
1491   coco_state *state = machine.driver_data<coco_state>();
1492   state->m_bitbanger_output_value = (data & 2) >> 1;
1493   bitbanger_output(bitbanger_image(machine), state->m_bitbanger_output_value);
1494}
1495
1496/* Printer output for the Dragon, output to Paralel port */
1497static void printer_out_dragon(running_machine &machine, int data)
1498{
1499   coco_state *state = machine.driver_data<coco_state>();
1500
1501   /* If strobe bit is high send data from pia0 port b to dragon parallel printer */
1502   if (data & 0x02)
786   /* poll the keyboard, and update PA6-PA0 accordingly*/
787   for (int i = 0; i < sizeof(m_keyboard) / sizeof(m_keyboard[0]); i++)
1503788   {
1504      printer_image(machine)->output(state->m_pia_0->b_output());
1505   }
1506}
1507
1508static WRITE8_DEVICE_HANDLER ( d_pia1_pa_w )
1509{
1510   coco_state *state = device->machine().driver_data<coco_state>();
1511   /*
1512     *  This port appears at $FF20
1513     *
1514     *  Bits
1515     *  7-2:    DAC to speaker or cassette
1516     *    1:    Serial out (CoCo), Printer strobe (Dragon)
1517     */
1518   UINT8 dac = downcast<pia6821_device *>(device)->a_output() & 0xfc;
1519   UINT8 ctrl = input_port_read_safe(device->machine(), "ctrl_sel", 0x00);
1520   UINT8 hires = input_port_read_safe(device->machine(), "hires_intf", 0x00);
1521   state->m_dac_value = dac >> 2;
1522
1523   coco_sound_update(device->machine());
1524
1525   /* Diecom Light Gun (either in Left or in Right Port) writes here */
1526   if ((ctrl & 0x0f) == 0x03 || (ctrl & 0xf0) == 0x30)
1527   {
1528      int dclg_this_bit = ((data & 2) >> 1);
1529
1530      if (state->m_dclg_previous_bit == 1)
789      input_port_value value = input_port_read_direct(m_keyboard[i]);
790      if ((value | pia0_pb) != 0xFF)
1531791      {
1532         if (dclg_this_bit == 0)
1533         {
1534            /* Clock Diecom Light gun interface on a high to low transistion */
1535            state->m_dclg_state++;
1536            state->m_dclg_state &= 0x0f;
1537
1538            /* Clear hit bit for every transistion */
1539            state->m_dclg_output_h &= ~0x02;
1540
1541            if (state->m_dclg_state > 7)
1542            {
1543               /* Bit shift timer data on state 8 through 15 */
1544               if (((state->m_dclg_timer >> (state->m_dclg_state - 8 + 1)) & 0x01) == 1)
1545                  state->m_dclg_output_v |= 0x01;
1546               else
1547                  state->m_dclg_output_v &= ~0x01;
1548
1549               /* Bit 9 of timer is only avaiable if state == 8*/
1550               if (state->m_dclg_state == 8 && (((state->m_dclg_timer >> 9) & 0x01) == 1))
1551                  state->m_dclg_output_v |= 0x02;
1552               else
1553                  state->m_dclg_output_v &= ~0x02;
1554            }
1555
1556            /* During state 15, this bit is high. */
1557            if (state->m_dclg_state == 15)
1558               state->m_dclg_output_h |= 0x01;
1559            else
1560               state->m_dclg_output_h &= ~0x01;
1561         }
792         pia0_pa &= ~(0x01 << i);
1562793      }
1563
1564      state->m_dclg_previous_bit = dclg_this_bit;
1565
1566   }
1567   else
1568   {
1569      cassette_device_image(device->machine())->output(((int) dac - 0x80) / 128.0);
1570   }
1571
1572   (*state->update_keyboard)(device->machine());
1573
1574   /* Hi-Res Joystick (either in Left or in Right Port) writes here */
1575   if ((ctrl & 0x0f) == 0x01 && hires == 0x01)
1576      coco_hiresjoy_w(device->machine(), dac >= 0x80, 0);
1577   else if ((ctrl & 0xf0) == 0x10 && hires == 0x03)
1578      coco_hiresjoy_w(device->machine(), dac >= 0x80, 1);
1579
1580   /* Handle printer output, serial for CoCos, parallel for Dragons */
1581   (*state->printer_out)(device->machine(), data);
1582}
1583
1584/*
1585 * This port appears at $FF23
1586 *
1587 * The CoCo 1/2 and Dragon kept the gmode and vmode separate, and the CoCo
1588 * 3 tied them together.  In the process, the CoCo 3 dropped support for the
1589 * semigraphics modes
1590 */
1591
1592static WRITE8_DEVICE_HANDLER( d_pia1_pb_w )
1593{
1594   coco6847_video_changed();
1595
1596   /* PB1 will drive the sound output.  This is a rarely
1597     * used single bit sound mode. It is always connected thus
1598     * cannot be disabled.
1599     *
1600     * Source:  Page 31 of the Tandy Color Computer Serice Manual
1601     */
1602   coco_sound_update(device->machine());
1603}
1604
1605static WRITE8_DEVICE_HANDLER( dragon64_pia1_pb_w )
1606{
1607   int ddr;
1608
1609   d_pia1_pb_w(device, 0, data);
1610
1611   ddr = ~downcast<pia6821_device *>(device)->port_b_z_mask();
1612
1613   /* If bit 2 of the pia1 ddrb is 1 then this pin is an output so use it */
1614   /* to control the paging of the 32k and 64k basic roms */
1615   /* Otherwise it set as an input, with an EXTERNAL pull-up so it should */
1616   /* always be high (enabling 32k basic rom) */
1617   if (ddr & 0x04)
1618   {
1619      dragon_page_rom(device->machine(), data & 0x04);
1620   }
1621}
1622
1623/***************************************************************************
1624  PIA2 ($FF24-$FF28) on Daragon Alpha/Professional
1625
1626    PIA2 PA0        bcdir to AY-8912
1627    PIA2 PA1        bc0 to AY-8912
1628    PIA2 PA2        Rom switch, 0=basic rom, 1=boot rom.
1629    PIA2 PA3-PA7    Unknown/unused ?
1630    PIA2 PB0-PB7    connected to D0..7 of the AY8912.
1631    CB1             DRQ from WD2797 disk controler.
1632***************************************************************************/
1633
1634static WRITE8_DEVICE_HANDLER( dgnalpha_pia2_pa_w )
1635{
1636   device_t *ay8912 = device->machine().device("ay8912");
1637   int   bc_flags;      /* BCDDIR/BC1, as connected to PIA2 port a bits 0 and 1 */
1638
1639   /* If bit 2 of the pia2 ddra is 1 then this pin is an output so use it */
1640   /* to control the paging of the boot and basic roms */
1641   /* Otherwise it set as an input, with an internal pull-up so it should */
1642   /* always be high (enabling boot rom) */
1643   /* PIA FIXME if (pia_get_ddr_a(2) & 0x04) */
1644   {
1645      dragon_page_rom(device->machine(), data & 0x04);   /* bit 2 controls boot or basic rom */
1646   }
1647
1648   /* Bits 0 and 1 for pia2 port a control the BCDIR and BC1 lines of the */
1649   /* AY-8912 */
1650   bc_flags = data & 0x03;   /* mask out bits */
1651
1652   switch (bc_flags)
1653   {
1654      case 0x00   :      /* Inactive, do nothing */
1655         break;
1656      case 0x01   :      /* Write to selected port */
1657         ay8910_data_w(ay8912, 0, downcast<pia6821_device *>(device)->b_output());
1658         break;
1659      case 0x02   :      /* Read from selected port */
1660         downcast<pia6821_device *>(device)->portb_w(ay8910_r(ay8912, 0));
1661         break;
1662      case 0x03   :      /* Select port to write to */
1663         ay8910_address_w(ay8912, 0, downcast<pia6821_device *>(device)->b_output());
1664         break;
1665   }
1666}
1667
1668/* Controls rom paging in Dragon 64, and Dragon Alpha */
1669/* On 64, switches between the two versions of the basic rom mapped in at 0x8000 */
1670/* on the alpha switches between the Boot/Diagnostic rom and the basic rom */
1671static void dragon_page_rom(running_machine &machine, int romswitch)
1672{
1673   coco_state *state = machine.driver_data<coco_state>();
1674   UINT8 *bank;
1675
1676   if (romswitch)
1677      bank = state->m_rom;      /* This is the 32k mode basic(64)/boot rom(alpha)  */
1678   else
1679      bank = state->m_rom + 0x8000;   /* This is the 64k mode basic(64)/basic rom(alpha) */
1680
1681   state->m_bas_rom_bank = bank;         /* Record which rom we are using so that the irq routine */
1682                  /* uses the vectors from the correct rom ! (alpha) */
1683
1684   setup_memory_map(machine);         /* Setup memory map as needed */
1685}
1686
1687/********************************************************************************************/
1688/* Dragon Alpha onboard FDC */
1689/********************************************************************************************/
1690
1691/* The NMI line on the alphaAlpha is gated through IC16 (early PLD), and is gated by pia2 CA2  */
1692static WRITE_LINE_DEVICE_HANDLER( dgnalpha_fdc_intrq_w )
1693{
1694   coco_state *cstate = device->machine().driver_data<coco_state>();
1695
1696   if (state)
1697   {
1698      if(cstate->m_dgnalpha_just_reset)
794      if ((value | pia0_pb_z) != 0xFF)
1699795      {
1700         cstate->m_dgnalpha_just_reset = 0;
796         pia0_pa_z &= ~(0x01 << i);
1701797      }
1702      else
1703      {
1704         if (cstate->m_pia_2->ca2_output_z())
1705            cputag_set_input_line(device->machine(), "maincpu", INPUT_LINE_NMI, ASSERT_LINE);
1706        }
1707798   }
1708   else
1709      cputag_set_input_line(device->machine(), "maincpu", INPUT_LINE_NMI, CLEAR_LINE);
1710}
1711799
1712/* The DRQ line goes through pia2 cb1, in exactly the same way as DRQ from DragonDos does */
1713/* for pia1 cb1 */
1714static WRITE_LINE_DEVICE_HANDLER( dgnalpha_fdc_drq_w )
1715{
1716   coco_state *cstate = device->machine().driver_data<coco_state>();
1717   cstate->m_pia_2->cb1_w(state ? CARTLINE_ASSERTED : CARTLINE_CLEAR);
1718}
800   /* poll the joystick (*/
801   bool joyin;
802   UINT8 buttons;
803   poll_joystick(&joyin, &buttons);
1719804
1720/* The Dragon Alpha hardware reverses the order of the WD2797 registers */
1721READ8_HANDLER(dgnalpha_wd2797_r)
1722{
1723   device_t *fdc = space->machine().device("wd2797");
1724   int result = 0;
805   /* PA7 comes from JOYIN */
806   pia0_pa |= joyin ? 0x80 : 0x00;
1725807
1726   switch(offset & 0x03)
1727   {
1728      case 0:
1729         result = wd17xx_data_r(fdc, 0);
1730         break;
1731      case 1:
1732         result = wd17xx_sector_r(fdc, 0);
1733         break;
1734      case 2:
1735         result = wd17xx_track_r(fdc, 0);
1736         break;
1737      case 3:
1738         result = wd17xx_status_r(fdc, 0);
1739         break;
1740      default:
1741         break;
1742   }
808   /* mask out the buttons */
809   pia0_pa &= ~buttons;
810   pia0_pa_z &= ~buttons;
1743811
1744   return result;
1745}
812   /* and write the result to PIA0 */
813   update_keyboard_input(pia0_pa, pia0_pa_z);
1746814
1747WRITE8_HANDLER(dgnalpha_wd2797_w)
1748{
1749   device_t *fdc = space->machine().device("wd2797");
1750    switch(offset & 0x3)
1751   {
1752      case 0:
1753         wd17xx_data_w(fdc, 0, data);
1754         break;
1755      case 1:
1756         wd17xx_sector_w(fdc, 0, data);
1757         break;
1758      case 2:
1759         wd17xx_track_w(fdc, 0, data);
1760         break;
1761      case 3:
1762            wd17xx_command_w(fdc, 0, data);
1763
1764         /* disk head is encoded in the command byte */
1765         wd17xx_set_side(fdc,(data & 0x02) ? 1 : 0);
1766         break;
1767   };
815   /* hires joystick */
816   poll_hires_joystick();
1768817}
1769818
1770READ8_HANDLER(dgnalpha_modem_r)
1771{
1772   return 0xFF;
1773}
1774819
1775WRITE8_HANDLER(dgnalpha_modem_w)
1776{
1777}
1778820
1779static WRITE8_DEVICE_HANDLER ( d_pia1_ca2_w )
1780{
821//-------------------------------------------------
822//  update_keyboard_input - writes to PIA0 PA, but
823//   on the CoCo 3 controls a GIME input
824//-------------------------------------------------
1781825
1782      cassette_device_image(device->machine())->change_state(
1783      data ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED,
1784      CASSETTE_MASK_MOTOR);
1785}
1786
1787static READ8_DEVICE_HANDLER ( d_pia1_pa_r )
826void coco_state::update_keyboard_input(UINT8 value, UINT8 z)
1788827{
1789   coco_state *state = device->machine().driver_data<coco_state>();
1790   UINT8 result;
1791
1792   result = (cassette_device_image(device->machine()))->input() >= 0 ? 1 : 0;
1793   result |= state->m_bitbanger_output_value << 1;
1794   result |= state->m_dac_value << 2;
1795
1796   return result;
828   m_pia_0->set_a_input(value, z);
1797829}
1798830
1799void coco_bitbanger_callback(running_machine &machine, UINT8 bit)
1800{
1801   coco_state *state = machine.driver_data<coco_state>();
1802      state->m_bitbanger_input_value = bit;
1803}
1804831
1805void coco3_bitbanger_callback(running_machine &machine, UINT8 bit)
1806{
1807   coco_state *state = machine.driver_data<coco_state>();
1808   /* rant: this interrupt is next to useless. It would be useful information to know when a
1809            start bit (high to low) occurs, but this interrupt activates in the opposite situation.
1810   */
1811832
1812   if( state->m_bitbanger_input_value == 0 && bit == 1)
1813   {
1814      state->m_bitbanger_input_value = bit;
1815      coco3_raise_interrupt(machine, COCO3_INT_EI2, 0);
1816      coco3_raise_interrupt(machine, COCO3_INT_EI2, 1);
1817   }
1818   else
1819   {
1820      state->m_bitbanger_input_value = bit;
1821   }
1822}
833//-------------------------------------------------
834//  update_cassout - called when CASSOUT changes
835//-------------------------------------------------
1823836
1824static READ8_DEVICE_HANDLER ( d_pia1_pb_r_coco )
837void coco_state::update_cassout(int cassout)
1825838{
1826   coco_state *state = device->machine().driver_data<coco_state>();
1827
1828   /* This handles the reading of the memory sense switch (pb2) for the CoCo 1,
1829     * and serial-in (pb0). */
1830   int result;
1831
1832   /* For the CoCo 1, the logic has been changed to only select 64K rams
1833       if there is more than 16K of memory, as the Color Basic 1.0 rom
1834       can only configure 4K or 16K ram banks (as documented in "Color
1835       Basic Unreveled"), doing this allows this  allows the coco driver
1836       to access 32K of ram, and also allows the cocoe driver to access
1837       the full 64K, as this uses Color Basic 1.2, which can configure 64K rams */
1838
1839   if (ram_get_size(device->machine().device(RAM_TAG)) > 0x8000)      /* 1 bank of 64K rams */
1840      result = (state->m_pia_0->b_output() & 0x80) >> 5;
1841   else if (ram_get_size(device->machine().device(RAM_TAG)) >= 0x4000)   /* 1 or 2 banks of 16K rams */
1842      result = 0x04;
1843   else
1844      result = 0x00;         /* 4K Rams */
1845
1846   result += state->m_bitbanger_input_value;
1847
1848   return result;
839   m_cassette->output((cassout - 0x20) / 32.0);
1849840}
1850841
1851static READ8_DEVICE_HANDLER ( d_pia1_pb_r_dragon32 )
1852{
1853   /* This handles the reading of the memory sense switch (pb2) for the Dragon 32,
1854     * and pb0, is the printer /busy line. */
1855842
1856   int result;
1857843
1858   /* Of the Dragon machines, Only the Dragon 32 needs the ram select bit
1859       as both the 64 and Alpha, always have 64K rams, also the meaning of
1860       the bit is different with respect to the CoCo 1 */
844//-------------------------------------------------
845//  diecom_lightgun_clock - called the diecom
846//   lightgun undergoes a high to low transition
847//-------------------------------------------------
1861848
1862   if (ram_get_size(device->machine().device(RAM_TAG)) > 0x8000)
1863      result = 0x00;      /* 1 bank of 64K, rams */
1864   else
1865      result = 0x04;      /* 2 banks of 16K rams */
1866
1867   return result;
1868}
1869
1870static READ8_DEVICE_HANDLER ( d_pia1_pb_r_coco2 )
849void coco_state::diecom_lightgun_clock(void)
1871850{
1872   coco_state *state = device->machine().driver_data<coco_state>();
851   /* clock Diecom Light gun interface on a high to low transistion */
852   m_dclg_state++;
853   m_dclg_state &= 0x0f;
1873854
1874   /* This handles the reading of the memory sense switch (pb2) for the CoCo 2 and 3,
1875     * and serial-in (pb0).
1876     */
1877   int result;
855   /* clear hit bit for every transistion */
856   m_dclg_output_h &= ~0x02;
1878857
1879   if (ram_get_size(device->machine().device(RAM_TAG)) <= 0x1000)
1880      result = 0x00;               /* 4K: wire pia1_pb2 low */
1881   else if (ram_get_size(device->machine().device(RAM_TAG)) <= 0x4000)
1882      result = 0x04;               /* 16K: wire pia1_pb2 high */
1883   else
1884      result = (state->m_pia_0->b_output() & 0x40) >> 4;      /* 32/64K: wire output of pia0_pb6 to input pia1_pb2  */
1885
1886   result += state->m_bitbanger_input_value;
1887
1888   return result;
1889}
1890
1891
1892/*
1893    Compusense Dragon Plus Control register
1894*/
1895
1896/* The read handler will eventually return the 6845 status */
1897READ8_HANDLER ( dgnplus_reg_r )
1898{
1899   return 0;
1900}
1901
1902/*
1903    When writing the bits have the following meanings :
1904
1905    bit value   purpose
1906    0   0   First 2k of memory map determined by bits 1 & 2
1907        1   6845 display RAM mapped into first 2K of map,
1908
1909    2,1 0,0 Normal bottom 32K or ram mapped (from mainboard).
1910        0,1 First 32K of plus RAM mapped into $0000-$7FFF
1911        1,0 Second 32K of plus RAM mapped into $0000-$7FFF
1912        1,1 Undefined. I will assume that it's the same as 00.
1913    3-7     Unused.
1914*/
1915WRITE8_HANDLER ( dgnplus_reg_w )
1916{
1917   coco_state *state = space->machine().driver_data<coco_state>();
1918   int map;
1919
1920   map = (data & 0x06)>>1;
1921
1922   switch (map)
858   if (m_dclg_state > 7)
1923859   {
1924      case 0x00   : state->m_bottom_32k=&ram_get_ptr(space->machine().device(RAM_TAG))[0x00000]; break;
1925      case 0x01   : state->m_bottom_32k=&ram_get_ptr(space->machine().device(RAM_TAG))[0x10000]; break;
1926      case 0x02   : state->m_bottom_32k=&ram_get_ptr(space->machine().device(RAM_TAG))[0x18000]; break;
1927      case 0x03   : state->m_bottom_32k=&ram_get_ptr(space->machine().device(RAM_TAG))[0x00000]; break;
1928      default   : state->m_bottom_32k=&ram_get_ptr(space->machine().device(RAM_TAG))[0x00000]; break; // Just to shut the compiler up !
860      /* Bit shift timer data on state 8 thru 15 */
861      if (((m_dclg_timer >> (m_dclg_state - 8 + 1)) & 0x01) == 1)
862         m_dclg_output_v |= 0x01;
863      else
864         m_dclg_output_v &= ~0x01;
865
866      /* Bit 9 of timer is only avaiable if state == 8*/
867      if (m_dclg_state == 8 && (((m_dclg_timer >> 9) & 0x01) == 1))
868         m_dclg_output_v |= 0x02;
869      else
870         m_dclg_output_v &= ~0x02;
1929871   }
1930872
1931   setup_memory_map(space->machine());
873   /* During state 15, this bit is high. */
874   if (m_dclg_state == 15)
875      m_dclg_output_h |= 0x01;
876   else
877      m_dclg_output_h &= ~0x01;
1932878}
1933879
1934880
1935881
1936/***************************************************************************
1937  Misc
1938***************************************************************************/
882//-------------------------------------------------
883//  update_prinout - called when PRINOUT changes
884//-------------------------------------------------
1939885
1940static SAM6883_SET_MPU_RATE( d_sam_set_mpurate )
886void coco_state::update_prinout(bool prinout)
1941887{
1942   /* The infamous speed up poke.
1943     *
1944     * This was a SAM switch that occupied 4 addresses:
1945     *
1946     *      $FFD9   (set)   R1
1947     *      $FFD8   (clear) R1
1948     *      $FFD7   (set)   R0
1949     *      $FFD6   (clear) R0
1950     *
1951     * R1:R0 formed the following states:
1952     *      00  - slow          0.89 MHz
1953     *      01  - dual speed    ???
1954     *      1x  - fast          1.78 MHz
1955     *
1956     * R1 controlled whether the video addressing was speeded up and R0
1957     * did the same for the CPU.  On pre-CoCo 3 machines, setting R1 caused
1958     * the screen to display garbage because the M6847 could not display
1959     * fast enough.
1960     *
1961     * TODO:  Make the overclock more accurate.  In dual speed, ROM was a fast
1962     * access but RAM was not.  I don't know how to simulate this.
1963     */
1964    device->machine().device("maincpu")->set_clock_scale(val ? 2 : 1);
1965}
1966
1967READ8_HANDLER(dgnalpha_mapped_irq_r)
1968{
1969   coco_state *state = space->machine().driver_data<coco_state>();
1970   return state->m_bas_rom_bank[0x3ff0 + offset];
1971}
1972
1973static void setup_memory_map(running_machine &machine)
1974{
1975   /*
1976    The following table contains the RAM block mappings for the CoCo 1/2 and Dragon computers
1977    This replicates the behavior of the SAM ram size programming bits which in ther real hardware
1978    allowed the use of various sizes of RAM chips, as follows :-
1979
1980    1 or 2 banks of 4K
1981    1 or 2 banks of 16K
1982    1 bank of 64K
1983    up to 64K of static ram.
1984
1985    For the 4K and 16K chip sizes, if the second bank was empty it would be mapped to nothing.
1986    For the 4K and 16K chip sizes, the banks would be mirrored at chip size*2 intervals.
1987
1988    The following table holds the data required to implement this.
1989
1990    Note though it is technically possible to have 2 banks of 4K rams, for a total of 8K, I
1991    have never seen a machine with this configuration, so I have not implemented it.
1992    */
1993
1994   struct coco_meminfo
888   if ((joystick_type(0) == JOYSTICK_DIECOM_LIGHT_GUN) || (joystick_type(1) == JOYSTICK_DIECOM_LIGHT_GUN))
1995889   {
1996      offs_t   start;      /* start address of bank */
1997      offs_t   end;      /* End address of bank */
1998      int   wbank4;      /* Bank to map when 4K rams */
1999      int   wbank16_1;   /* Bank to map when one bank of 16K rams */
2000      int   wbank16_2;   /* Bank to map when two banks of 16K rams */
2001      int   wbank64;   /* Bank to map when 64K rams */
2002   };
2003
2004   static const struct coco_meminfo memmap[] =
2005   {
2006      { 0x0000, 0x0FFF, 1, 1, 1, 1  },
2007      { 0x1000, 0x1FFF, 0, 2, 2, 2  },
2008      { 0x2000, 0x2FFF, 1, 3, 3, 3  },
2009      { 0x3000, 0x3FFF, 0, 4, 4, 4  },
2010      { 0x4000, 0x4FFF, 1, 0, 5, 5  },
2011      { 0x5000, 0x5FFF, 0, 0, 6, 6  },
2012      { 0x6000, 0x6FFF, 1, 0, 7, 7  },
2013      { 0x7000, 0x7FFF, 0, 0, 8, 8  },
2014      { 0x8000, 0x8FFF, 1, 1, 1, 9  },
2015      { 0x9000, 0x9FFF, 0, 2, 2, 10 },
2016      { 0xA000, 0xAFFF, 1, 3, 3, 11 },
2017      { 0xB000, 0xBFFF, 0, 4, 4, 12 },
2018      { 0xC000, 0xCFFF, 1, 0, 5, 13 },
2019      { 0xD000, 0xDFFF, 0, 0, 6, 14 },
2020      { 0xE000, 0xEFFF, 1, 0, 7, 15 },
2021      { 0xF000, 0xFEFF, 0, 0, 8, 16 }
2022   };
2023
2024   /* We need to init these vars from the sam, as this may be called from outside the sam callbacks */
2025   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
2026   coco_state *state = machine.driver_data<coco_state>();
2027   UINT8 memsize   = sam6883_memorysize(state->m_sam);
2028   UINT8 maptype   = sam6883_maptype(state->m_sam);
2029   //UINT8 pagemode  = sam6883_pagemode(machine);
2030   int       last_ram_block;      /* Last block that will be RAM, dependent on maptype */
2031   int       block_index;      /* Index of block being processed */
2032   int      wbank;         /* bank no to go in this block */
2033   UINT8      *offset;      /* offset into coco rom for rom mapping */
2034   char   bank[10];
2035
2036   /* Set last RAM block dependent on map type */
2037   if (maptype)
2038      last_ram_block=15;
2039   else
2040      last_ram_block=7;
2041
2042   /* Map RAM blocks */
2043   for(block_index=0;block_index<=last_ram_block;block_index++)
2044   {
2045      sprintf(bank,"bank%d",block_index+1);
2046      /* Lookup the apropreate wbank value dependent on ram size */
2047      if (memsize==0)
2048         wbank=memmap[block_index].wbank4;
2049      else if ((memsize==1) && (ram_get_size(machine.device(RAM_TAG)) == 0x4000))   /* one bank of 16K rams */
2050         wbank=memmap[block_index].wbank16_1;
2051      else if ((memsize==1) && (ram_get_size(machine.device(RAM_TAG)) == 0x8000))   /* two banks of 16K rams */
2052         wbank=memmap[block_index].wbank16_2;
2053      else
2054         wbank=memmap[block_index].wbank64;
2055
2056      /* If wbank is 0 then there is no ram here so set it up to return 0, note this may change in the future */
2057      /* as all unmapped addresses on the CoCo/Dragon seem to always return 126 (0x7E) */
2058      /* If wbank is a positive integer, it contains the bank number to map into this block */
2059      if(wbank!=0)
890      /* printer port is connected to diecom light gun */
891      if (m_dclg_previous_bit && !prinout)
2060892      {
2061         /* This deals with the bottom 32K page switch and the Dragon Plus paged ram */
2062         if(block_index<8)
2063            memory_set_bankptr(machine, bank, &state->m_bottom_32k[memmap[wbank-1].start]);
2064         else
2065            memory_set_bankptr(machine, bank,&ram_get_ptr(machine.device(RAM_TAG))[memmap[wbank-1].start]);
2066
2067         space->install_readwrite_bank(memmap[block_index].start, memmap[block_index].end, bank);
893         diecom_lightgun_clock();
2068894      }
2069      else
2070      {
2071         space->nop_readwrite(memmap[block_index].start, memmap[block_index].end);
2072      }
895      m_dclg_previous_bit = prinout;
2073896   }
2074
2075   /* If in maptype 0 we need to map in the rom also, for now this just maps in the system and cart roms */
2076   if(!maptype)
897   else
2077898   {
2078      UINT8 *cart_rom = cococart_device(machine)->get_cart_base();
2079
2080      for(block_index=0;block_index<=7;block_index++)
899      /* output bitbanger if present (only on CoCos) */
900      if (m_bitbanger != NULL)
2081901      {
2082         sprintf(bank,"bank%d",block_index+9);
2083         /* If we are in the BASIC rom area $8000-$BFFF, then we map to the bas_rom_bank */
2084         /* as this may be in a different block of coco_rom, in the Dragon 64 and Alpha */
2085         /* as these machines have mutiple bios roms that can ocupy this area */
2086         if (block_index < 4)
2087            offset = &state->m_bas_rom_bank[0x1000*block_index];
2088         else {
2089            if (cart_rom) {
2090               offset = &cart_rom[(0x1000*(block_index-4)) % 0x4000];
2091            } else {
2092               offset = NULL;
2093            }
2094         }
2095         if (offset){
2096            memory_set_bankptr(machine, bank,offset);
2097         } else {
2098            space->unmap_read(memmap[block_index+8].start, memmap[block_index+8].end);
2099         }
2100         space->nop_write(memmap[block_index+8].start, memmap[block_index+8].end);
902         m_bitbanger->output(prinout ? 1 : 0);
2101903      }
2102904   }
2103905}
2104906
2105907
2106static SAM6883_SET_PAGE_ONE_MODE( d_sam_set_pageonemode )
2107{
2108   coco_state *state = device->machine().driver_data<coco_state>();
2109   /* Page mode - allowed switching between the low 32k and the high 32k,
2110     * assuming that 64k wasn't enabled
2111     *
2112     * TODO:  Actually implement this.  Also find out what the CoCo 3 did with
2113     * this (it probably ignored it)
2114     */
2115908
2116   if (!sam6883_maptype(device))      // Ignored in maptype 1
2117   {
2118      if((ram_get_size(device->machine().device(RAM_TAG))>0x8000) && val)
2119         state->m_bottom_32k=&ram_get_ptr(device->machine().device(RAM_TAG))[0x8000];
2120      else
2121         state->m_bottom_32k=&ram_get_ptr(device->machine().device(RAM_TAG))[0];
909//-------------------------------------------------
910//  pia1_pa_changed - called when PIA1 PA changes
911//-------------------------------------------------
2122912
2123      setup_memory_map(device->machine());
2124   }
2125}
2126
2127static SAM6883_SET_MEMORY_SIZE( d_sam_set_memorysize )
913void coco_state::pia1_pa_changed(void)
2128914{
2129   /* Memory size - allowed restricting memory accesses to something less than
2130     * 32k
2131     *
2132     * This was a SAM switch that occupied 4 addresses:
2133     *
2134     *      $FFDD   (set)   R1
2135     *      $FFDC   (clear) R1
2136     *      $FFDB   (set)   R0
2137     *      $FFDA   (clear) R0
2138     *
2139     * R1:R0 formed the following states:
2140     *      00  - 4k
2141     *      01  - 16k
2142     *      10  - 64k
2143     *      11  - static RAM (??)
2144     *
2145     * If something less than 64k was set, the low RAM would be smaller and
2146     * mirror the other parts of the RAM
2147     *
2148     * TODO:  Find out what "static RAM" is
2149     * TODO:  This should affect _all_ memory accesses, not just video ram
2150     * TODO:  Verify that the CoCo 3 ignored this
2151     */
2152
2153   setup_memory_map(device->machine());
915   update_sound();
916   poll_keyboard();
917   update_cassout(dac_output());
918   update_prinout(m_pia_1->a_output() & 0x02 ? true : false);
2154919}
2155920
2156921
2157922
2158/***************************************************************************
2159  CoCo 3 Timer
923//-------------------------------------------------
924//  pia1_pb_changed - called when PIA1 PB changes
925//-------------------------------------------------
2160926
2161  The CoCo 3 had a timer that had would activate when first written to, and
2162  would decrement over and over again until zero was reached, and at that
2163  point, would flag an interrupt.  At this point, the timer starts back up
2164  again.
2165
2166  I am deducing that the timer interrupt line was asserted if the timer was
2167  zero and unasserted if the timer was non-zero.  Since we never truly track
2168  the timer, we just use timer callback (coco3_timer_callback() asserts the
2169  line)
2170
2171  Most CoCo 3 docs, including the specs that Tandy released, say that the
2172  high speed timer is 70ns (half of the speed of the main clock crystal).
2173  However, it seems that this is in error, and the GIME timer is really a
2174  280ns timer (one eighth the speed of the main clock crystal.  Gault's
2175  FAQ agrees with this
2176***************************************************************************/
2177
2178
2179static void coco3_timer_reset(running_machine &machine)
927void coco_state::pia1_pb_changed(void)
2180928{
2181   coco3_state *state = machine.driver_data<coco3_state>();
2182   /* reset the timer; take the value stored in $FF94-5 and start the timer ticking */
2183   UINT16 timer_value;
2184   m6847_timing_type timing;
2185   attotime delay_time;
2186
2187   /* value is from 0-4095 */
2188   timer_value = ((state->m_gimereg[4] & 0x0F) * 0x100) | state->m_gimereg[5];
2189
2190   if (timer_value > 0)
2191   {
2192      /* depending on the GIME type, cannonicalize the value */
2193      if (GIME_TYPE_1987)
2194         timer_value += 1;   /* the 1987 GIME reset to the value plus one */
2195      else
2196         timer_value += 2;   /* the 1986 GIME reset to the value plus two */
2197
2198      /* choose which timing clock source */
2199      timing = (state->m_gimereg[1] & 0x20) ? M6847_CLOCK : M6847_HSYNC;
2200
2201      /* determine the delay time */
2202      delay_time = coco6847_time_delay(machine, timing, timer_value);
2203      if (LOG_TIMER)
2204         logerror("coco3_reset_timer(): delay_time=%g\n", delay_time.as_double());
2205
2206      /* and adjust the timer */
2207      state->m_gime_timer->adjust(delay_time);
2208   }
2209   else
2210   {
2211      /* timer is shut off */
2212      state->m_gime_timer->reset();
2213      if (LOG_TIMER)
2214         logerror("coco3_reset_timer(): timer is off\n");
2215   }
929   update_sound();
2216930}
2217931
2218932
2219933
2220static TIMER_CALLBACK(coco3_timer_proc)
2221{
2222   coco3_timer_reset(machine);
2223   coco3_vh_blink(machine);
2224   coco3_raise_interrupt(machine, COCO3_INT_TMR, 1);
2225   coco3_raise_interrupt(machine, COCO3_INT_TMR, 0);
2226}
934//-------------------------------------------------
935//  keyboard_changed
936//-------------------------------------------------
2227937
2228
2229
2230static void coco3_timer_init(running_machine &machine)
938INPUT_CHANGED(coco_state::keyboard_changed)
2231939{
2232   coco3_state *state = machine.driver_data<coco3_state>();
2233   state->m_gime_timer = machine.scheduler().timer_alloc(FUNC(coco3_timer_proc));
940   coco_state *state = field.machine().driver_data<coco_state>();
941   state->poll_keyboard();
2234942}
2235943
2236944
2237945
2238/***************************************************************************
2239  MMU
2240***************************************************************************/
946//-------------------------------------------------
947//  joystick_mode_changed
948//-------------------------------------------------
2241949
2242/* Dragon 64/Alpha and Tano Dragon 64 sams are now handled in exactly the same */
2243/* way as the CoCo 1/2 and Dragon 32, this now has been reduced to a call to */
2244/* setup_memory_map() - 2007-01-02 phs. */
2245
2246static SAM6883_SET_MAP_TYPE( d_sam_set_maptype )
950INPUT_CHANGED(coco_state::joystick_mode_changed)
2247951{
2248   coco_state *state = device->machine().driver_data<coco_state>();
2249   if(val)
2250      state->m_bottom_32k=ram_get_ptr(device->machine().device(RAM_TAG));   // Always reset, when in maptype 1
2251
2252   setup_memory_map(device->machine());
952   coco_state *state = field.machine().driver_data<coco_state>();
953   state->poll_keyboard();
2253954}
2254955
2255/*************************************
2256 *
2257 *  CoCo 3
2258 *
2259 *************************************/
2260956
2261957
2262/*
2263 * coco3_mmu_translate() takes a zero counted bank index and an offset and
2264 * translates it into a physical RAM address.  The following logical memory
2265 * addresses have the following bank indexes:
2266 *
2267 *  Bank 0      $0000-$1FFF
2268 *  Bank 1      $2000-$3FFF
2269 *  Bank 2      $4000-$5FFF
2270 *  Bank 3      $6000-$7FFF
2271 *  Bank 4      $8000-$9FFF
2272 *  Bank 5      $A000-$BFFF
2273 *  Bank 6      $C000-$DFFF
2274 *  Bank 7      $E000-$FDFF
2275 *  Bank 8      $FE00-$FEFF
2276 *
2277 * The result represents a physical RAM address.  Since ROM/Cartidge space is
2278 * outside of the standard RAM memory map, ROM addresses get a "physical RAM"
2279 * address that has bit 31 set.  For example, ECB would be $80000000-
2280 * $80001FFFF, CB would be $80002000-$80003FFFF etc.  It is possible to force
2281 * this function to use a RAM address, which is used for video since video can
2282 * never reference ROM.
2283 */
2284offs_t coco3_mmu_translate(running_machine &machine,int bank, int offset)
2285{
2286   coco3_state *state = machine.driver_data<coco3_state>();
2287   int forceram;
2288   UINT32 block;
2289   offs_t result;
958//-------------------------------------------------
959//  bitbanger_changed
960//-------------------------------------------------
2290961
2291   /* Bank 8 is the 0xfe00 block; and it is treated differently */
2292   if (bank == 8)
2293   {
2294      if (state->m_gimereg[0] & 8)
2295      {
2296         /* this GIME register fixes logical addresses $FExx to physical
2297             * addresses $7FExx ($1FExx if 128k */
2298         assert(offset < 0x200);
2299         return ((ram_get_size(machine.device(RAM_TAG)) - 0x200) & 0x7ffff) + offset;
2300      }
2301      bank = 7;
2302      offset += 0x1e00;
2303      forceram = 1;
2304   }
2305   else
2306   {
2307      forceram = 0;
2308   }
2309
2310   /* Perform the MMU lookup */
2311   if (state->m_gimereg[0] & 0x40)
2312   {
2313      if (state->m_gimereg[1] & 1)
2314         bank += 8;
2315      block = state->m_mmu[bank];
2316      block |= ((UINT32) ((state->m_gimereg[11] >> 4) & 0x03)) << 8;
2317   }
2318   else
2319   {
2320      block = bank + 56;
2321   }
2322
2323   /* Are we actually in ROM?
2324     *
2325     * In our world, ROM is represented by memory blocks 0x40-0x47
2326     *
2327     * 0    Extended Color Basic
2328     * 1    Color Basic
2329     * 2    Reset Initialization
2330     * 3    Super Extended Color Basic
2331     * 4-7  Cartridge ROM
2332     *
2333     * This is the level where ROM is mapped, according to Tepolt (p21)
2334     */
2335   if (((block & 0x3f) >= 0x3c) && !state->m_enable_64k && !forceram)
2336   {
2337      static const UINT8 rommap[4][4] =
2338      {
2339         { 0, 1, 6, 7 },
2340         { 0, 1, 6, 7 },
2341         { 0, 1, 2, 3 },
2342         { 4, 5, 6, 7 }
2343      };
2344      block = rommap[state->m_gimereg[0] & 3][(block & 0x3f) - 0x3c];
2345      result = (block * 0x2000 + offset) | 0x80000000;
2346   }
2347   else
2348   {
2349      result = ((block * 0x2000) + offset) % ram_get_size(machine.device(RAM_TAG));
2350   }
2351   return result;
2352}
2353
2354
2355
2356static void coco3_mmu_update(running_machine &machine, int lowblock, int hiblock)
962void coco_state::bitbanger_changed(bool newvalue)
2357963{
2358   coco_state *state = machine.driver_data<coco_state>();
2359   static const struct
2360   {
2361      offs_t start;
2362      offs_t end;
2363   }
2364   bank_info[] =
2365   {
2366      { 0x0000, 0x1fff },
2367      { 0x2000, 0x3fff },
2368      { 0x4000, 0x5fff },
2369      { 0x6000, 0x7fff },
2370      { 0x8000, 0x9fff },
2371      { 0xa000, 0xbfff },
2372      { 0xc000, 0xdfff },
2373      { 0xe000, 0xfdff },
2374      { 0xfe00, 0xfeff }
2375   };
2376
2377   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
2378   int i, offset;
2379   UINT8 *readbank = NULL;
2380   UINT8 *cart_rom = cococart_device(machine)->get_cart_base();
2381
2382   char bank[10];
2383
2384   for (i = lowblock; i <= hiblock; i++)
2385   {
2386      sprintf(bank,"bank%d",i+1);
2387
2388      offset = coco3_mmu_translate(machine, i, 0);
2389      if (offset & 0x80000000)
2390      {
2391         /* an offset into the CoCo 3 ROM */
2392         if (offset & 0x8000) {
2393            if (cart_rom) {
2394               readbank = &cart_rom[offset & ~0x80008000];
2395            }
2396         }
2397         else
2398            readbank = &state->m_rom[offset & ~0x80000000];
2399         space->unmap_write(bank_info[i].start, bank_info[i].end);
2400      }
2401      else
2402      {
2403         /* offset into normal RAM */
2404         readbank = &ram_get_ptr(machine.device(RAM_TAG))[offset];
2405         space->install_write_bank(bank_info[i].start, bank_info[i].end, bank);
2406      }
2407
2408      /* set up the banks */
2409      if (readbank) {
2410         memory_set_bankptr(machine, bank, readbank);
2411      } else {
2412         space->unmap_read(bank_info[i].start, bank_info[i].end);
2413      }
2414
2415      if (LOG_MMU)
2416      {
2417         logerror("CoCo3 GIME MMU: Logical $%04x ==> Physical $%05x\n",
2418            (i == 8) ? 0xfe00 : i * 0x2000,
2419            offset);
2420      }
2421   }
964   // do nothing
2422965}
2423966
2424967
2425968
2426READ8_HANDLER(coco3_mmu_r)
2427{
2428   coco3_state *state = space->machine().driver_data<coco3_state>();
2429   /* The high two bits are floating (high resistance).  Therefore their
2430     * value is undefined.  But we are exposing them anyways here
2431     */
2432   return state->m_mmu[offset];
2433}
969//-------------------------------------------------
970//  bitbanger_callback
971//-------------------------------------------------
2434972
2435
2436
2437WRITE8_HANDLER(coco3_mmu_w)
973WRITE_LINE_MEMBER( coco_state::bitbanger_callback )
2438974{
2439   coco3_state *state = space->machine().driver_data<coco3_state>();
2440   state->m_mmu[offset] = data;
2441
2442   /* Did we modify the live MMU bank? */
2443   if ((offset >> 3) == (state->m_gimereg[1] & 1))
2444   {
2445      offset &= 7;
2446      coco3_mmu_update(space->machine(), offset, (offset == 7) ? 8 : offset);
2447   }
975   bitbanger_changed(state ? true : false);
2448976}
2449977
2450978
2451979
2452/***************************************************************************
2453  GIME Registers (Reference: Super Extended Basic Unravelled)
2454***************************************************************************/
980//-------------------------------------------------
981//  bitbanger_config
982//-------------------------------------------------
2455983
2456READ8_HANDLER(coco3_gime_r)
984const bitbanger_config coco_state::coco_bitbanger_config =
2457985{
2458   coco3_state *state = space->machine().driver_data<coco3_state>();
2459   UINT8 result = 0;
986   DEVCB_DRIVER_LINE_MEMBER(coco_state, bitbanger_callback),   /* callback */
987   BITBANGER_PRINTER,                                 /* default mode */
988   BITBANGER_600,                                    /* default output baud */
989   BITBANGER_0PERCENT                                 /* default fine tune adjustment */
990};
2460991
2461   switch(offset) {
2462   case 2:   /* Read pending IRQs */
2463      result = state->m_gime_irq;
2464      if (result) {
2465         state->m_gime_irq = 0;
2466         coco3_recalc_irq(space->machine());
2467      }
2468      break;
2469992
2470   case 3:   /* Read pending FIRQs */
2471      result = state->m_gime_firq;
2472      if (result) {
2473         state->m_gime_firq = 0;
2474         coco3_recalc_firq(space->machine());
2475      }
2476      break;
2477993
2478   case 4:   /* Timer MSB/LSB; these arn't readable */
2479   case 5:
2480      /* JK tells me that these values are indeterminate; and $7E appears
2481         * to be the value most commonly returned
2482         */
2483      result = 0x7e;
2484      break;
994//-------------------------------------------------
995//  poll_hires_joystick
996//-------------------------------------------------
2485997
2486   default:
2487      result = state->m_gimereg[offset];
2488      break;
2489   }
2490   return result;
2491}
2492
2493
2494
2495WRITE8_HANDLER(coco3_gime_w)
998void coco_state::poll_hires_joystick(void)
2496999{
2497   coco3_state *state = space->machine().driver_data<coco3_state>();
2498   /* take note if timer was $0000; see $FF95 for details */
2499   int timer_was_off = (state->m_gimereg[4] == 0x00) && (state->m_gimereg[5] == 0x00);
2500   state->m_gimereg[offset] = data;
1000   bool newvalue;
1001   bool is_cocomax3;
1002   int joystick_index, axis;
25011003
2502   if (LOG_GIME)
2503      logerror("CoCo3 GIME: $%04x <== $%02x pc=$%04x\n", offset + 0xff90, data, cpu_get_pc(&space->device()));
2504
2505   /* Features marked with '!' are not yet implemented */
2506   switch(offset)
1004   /* we do different things based on the type of hires interface */
1005   switch(hires_interface_type())
25071006   {
2508      case 0:
2509         /*  $FF90 Initialization register 0
2510            *         Bit 7 COCO 1=CoCo compatible mode
2511            *         Bit 6 MMUEN 1=MMU enabled
2512            *         Bit 5 IEN 1 = GIME chip IRQ enabled
2513            *         Bit 4 FEN 1 = GIME chip FIRQ enabled
2514            *         Bit 3 MC3 1 = RAM at FEXX is constant
2515            *         Bit 2 MC2 1 = standard SCS (Spare Chip Select)
2516            *         Bit 1 MC1 ROM map control
2517            *         Bit 0 MC0 ROM map control
2518            */
2519         coco3_mmu_update(space->machine(), 0, 8);
2520         {
2521            if (state->m_gimereg[0] & 0x04)
2522            {
2523               space->install_read_handler (0xFF40, 0xFF5F, read8_delegate (FUNC(cococart_slot_device::read), cococart_device(space->machine())));
2524               space->install_write_handler(0xFF40, 0xFF5F, write8_delegate(FUNC(cococart_slot_device::write),cococart_device(space->machine())));
2525            }
2526            else
2527            {
2528               space->nop_readwrite(0xFF40, 0xFF5F);
2529            }
2530         }
1007      case HIRES_RIGHT:
1008         newvalue = (m_pia_0->a_output() & 0x04);
1009         joystick_index = 0;
1010         is_cocomax3 = false;
25311011         break;
25321012
2533      case 1:
2534         /*  $FF91 Initialization register 1
2535            *         Bit 7 Unused
2536            *         Bit 6 Unused
2537            *         Bit 5 TINS Timer input select; 1 = 280 nsec, 0 = 63.5 usec
2538            *         Bit 4 Unused
2539            *         Bit 3 Unused
2540            *         Bit 2 Unused
2541            *         Bit 1 Unused
2542            *         Bit 0 TR Task register select
2543            */
2544         coco3_mmu_update(space->machine(), 0, 8);
2545         coco3_timer_reset(space->machine());
1013      case HIRES_RIGHT_COCOMAX3:
1014         newvalue = (dac_output() >= 0x20);
1015         joystick_index = 0;
1016         is_cocomax3 = true;
25461017         break;
25471018
2548      case 2:
2549         /*  $FF92 Interrupt request enable register
2550            *         Bit 7 Unused
2551            *         Bit 6 Unused
2552            *         Bit 5 TMR Timer interrupt
2553            *         Bit 4 HBORD Horizontal border interrupt
2554            *         Bit 3 VBORD Vertical border interrupt
2555            *       ! Bit 2 EI2 Serial data interrupt
2556            *         Bit 1 EI1 Keyboard interrupt
2557            *         Bit 0 EI0 Cartridge interrupt
2558            */
2559         if (LOG_INT_MASKING)
2560         {
2561            logerror("CoCo3 IRQ: Interrupts { %s%s%s%s%s%s} enabled\n",
2562               (data & 0x20) ? "TMR " : "",
2563               (data & 0x10) ? "HBORD " : "",
2564               (data & 0x08) ? "VBORD " : "",
2565               (data & 0x04) ? "EI2 " : "",
2566               (data & 0x02) ? "EI1 " : "",
2567               (data & 0x01) ? "EI0 " : "");
2568         }
2569         cococart_device(space->machine())->twiddle_q_lines();
1019      case HIRES_LEFT:
1020         newvalue = (m_pia_0->a_output() & 0x08);
1021         joystick_index = 1;
1022         is_cocomax3 = false;
25701023         break;
25711024
2572      case 3:
2573         /*  $FF93 Fast interrupt request enable register
2574            *         Bit 7 Unused
2575            *         Bit 6 Unused
2576            *         Bit 5 TMR Timer interrupt
2577            *         Bit 4 HBORD Horizontal border interrupt
2578            *         Bit 3 VBORD Vertical border interrupt
2579            *       ! Bit 2 EI2 Serial border interrupt
2580            *         Bit 1 EI1 Keyboard interrupt
2581            *         Bit 0 EI0 Cartridge interrupt
2582            */
2583         if (LOG_INT_MASKING)
2584         {
2585            logerror("CoCo3 FIRQ: Interrupts { %s%s%s%s%s%s} enabled\n",
2586               (data & 0x20) ? "TMR " : "",
2587               (data & 0x10) ? "HBORD " : "",
2588               (data & 0x08) ? "VBORD " : "",
2589               (data & 0x04) ? "EI2 " : "",
2590               (data & 0x02) ? "EI1 " : "",
2591               (data & 0x01) ? "EI0 " : "");
2592         }
2593         cococart_device(space->machine())->twiddle_q_lines();
1025      case HIRES_LEFT_COCOMAX3:
1026         newvalue = (dac_output() >= 0x20);
1027         joystick_index = 1;
1028         is_cocomax3 = true;
25941029         break;
25951030
2596      case 4:
2597         /*  $FF94 Timer register MSB
2598            *         Bits 4-7 Unused
2599            *         Bits 0-3 High order four bits of the timer
2600            */
2601         coco3_timer_reset(space->machine());
1031      default:
1032         newvalue = true;
1033         joystick_index = -1;
1034         is_cocomax3 = false;
26021035         break;
1036   }
26031037
2604      case 5:
2605         /*  $FF95 Timer register LSB
2606            *         Bits 0-7 Low order eight bits of the timer
2607            */
2608         if (timer_was_off && (state->m_gimereg[5] != 0x00))
2609                   {
2610                           /* Writes to $FF95 do not cause the timer to reset, but MESS
2611                            * will invoke coco3_timer_reset() if $FF94/5 was previously
2612                            * $0000.  The reason for this is because the timer is not
2613                            * actually off when $FF94/5 are loaded with $0000; rather it
2614                            * is continuously reloading the GIME's internal countdown
2615                            * register, even if it isn't causing interrupts to be raised.
2616                            *
2617                            * Failure to do this was the cause of bug #1065.  Special
2618                            * thanks to John Kowalski for pointing me in the right
2619                            * direction
2620                */
2621            coco3_timer_reset(space->machine());
2622                   }
2623         break;
1038   /* if the joystick isn't selected, newvalue is true */
1039   newvalue = newvalue || (joystick_index < 0) || (joystick_type(joystick_index) != JOYSTICK_NORMAL);
26241040
2625      case 8:
2626         /*  $FF98 Video Mode Register
2627            *         Bit 7 BP 0 = Text modes, 1 = Graphics modes
2628            *         Bit 6 Unused
2629            *       ! Bit 5 BPI Burst Phase Invert (Color Set)
2630            *         Bit 4 MOCH 1 = Monochrome on Composite
2631            *       ! Bit 3 H50 1 = 50 Hz power, 0 = 60 Hz power
2632            *         Bits 0-2 LPR Lines per row
2633            */
2634         break;
2635
2636      case 9:
2637         /*  $FF99 Video Resolution Register
2638            *         Bit 7 Undefined
2639            *         Bits 5-6 LPF Lines per Field (Number of Rows)
2640            *         Bits 2-4 HRES Horizontal Resolution
2641            *         Bits 0-1 CRES Color Resolution
2642            */
2643         break;
2644
2645      case 10:
2646         /*  $FF9A Border Register
2647            *         Bits 6,7 Unused
2648            *         Bits 0-5 BRDR Border color
2649            */
2650         break;
2651
2652      case 12:
2653         /*  $FF9C Vertical Scroll Register
2654            *         Bits 4-7 Reserved
2655            *       ! Bits 0-3 VSC Vertical Scroll bits
2656            */
2657         break;
2658
2659      case 11:
2660      case 13:
2661      case 14:
2662         /*  $FF9B,$FF9D,$FF9E Vertical Offset Registers
2663            *
2664            *   According to JK, if an odd value is placed in $FF9E on the 1986
2665            *   GIME, the GIME crashes
2666            *
2667            *  The reason that $FF9B is not mentioned in offical documentation
2668            *  is because it is only meaninful in CoCo 3's with the 2MB upgrade
2669            */
2670         break;
2671
2672      case 15:
2673         /*
2674            *   $FF9F Horizontal Offset Register
2675            *         Bit 7 HVEN Horizontal Virtual Enable
2676            *         Bits 0-6 X0-X6 Horizontal Offset Address
2677            *
2678            *  Unline $FF9D-E, this value can be modified mid frame
2679            */
2680         break;
1041   /* make the transition */
1042   for (axis = 0; axis <= 1; axis++)
1043   {
1044      if (m_hiresjoy_ca && !newvalue)
1045      {
1046         /* hi to lo */
1047         double value = m_joystick.input(joystick_index, axis) / 255.0;
1048         value *= is_cocomax3 ? 2500.0 : 4160.0;
1049         value += is_cocomax3 ? 400.0 : 592.0;
1050         attotime duration = m_maincpu->clocks_to_attotime((UINT64) value);
1051         m_hiresjoy_transition_timer[axis]->adjust(duration);
1052      }
1053      else if (!m_hiresjoy_ca && newvalue)
1054      {
1055         /* lo to hi */
1056         m_hiresjoy_transition_timer[axis]->reset();
1057      }
26811058   }
1059   m_hiresjoy_ca = newvalue;
26821060}
26831061
26841062
26851063
2686static SAM6883_GET_RAMBASE( coco3_sam_get_rambase )
2687{
2688   UINT32 video_base;
2689   video_base = coco3_get_video_base(device->machine(), 0xE0, 0x3F);
2690   return &ram_get_ptr(device->machine().device(RAM_TAG))[video_base % ram_get_size(device->machine().device(RAM_TAG))];
2691}
2692
2693
2694
2695
2696static SAM6883_SET_MAP_TYPE( coco3_sam_set_maptype )
2697{
2698   coco3_state *state = device->machine().driver_data<coco3_state>();
2699   state->m_enable_64k = val;
2700   coco3_mmu_update(device->machine(), 4, 8);
2701}
2702
2703
2704
27051064/***************************************************************************
2706    CARTRIDGE EXPANSION SLOT
1065  VHD
1066 ***************************************************************************/
27071067
2708    The bulk of the cartridge handling is in cococart.c and related code,
2709    whereas this interfaces with the main CoCo emulation.  This code also
2710    implements the hacks required to simulate the state where a CoCo
2711    cartridge ties the CART line to Q, which cannot be emulated by
2712    conventional techniques.
1068//-------------------------------------------------
1069//  ff60_read
1070//-------------------------------------------------
27131071
2714    When the CART line is set to Q, we begin a "twiddle" session -
2715    specifically the CART line is toggled on and off twice to ensure that
2716    if the PIA is accepting an interrupt, that it will receive it.  We also
2717    start twiddle sessions when CART is set to Q and the PIA is written to,
2718    in order to pick up any interrupt enables that might happen
2719***************************************************************************/
2720
2721/*-------------------------------------------------
2722    coco_cart_w - call for CART line
2723-------------------------------------------------*/
2724
2725WRITE_LINE_DEVICE_HANDLER(coco_cart_w)
1072READ8_MEMBER( coco_state::ff60_read )
27261073{
2727   coco_state *st = device->machine().driver_data<coco_state>();
2728   st->m_pia_1->cb1_w(state ? ASSERT_LINE : CLEAR_LINE);
2729}
1074   UINT8 result = 0x00;
27301075
1076   if ((m_vhd != NULL) && (offset >= 32) && (offset <= 37))
1077   {
1078      result = m_vhd->read(offset - 32);
1079   }
27311080
2732/*-------------------------------------------------
2733    coco3_cart_w - calls coco_cart_w and
2734    in addition will raise the GIME interrupt
2735-------------------------------------------------*/
2736
2737WRITE_LINE_DEVICE_HANDLER(coco3_cart_w)
2738{
2739   coco3_raise_interrupt(device->machine(), COCO3_INT_EI0, state ? ASSERT_LINE : CLEAR_LINE);
2740   coco_cart_w(device, state);
1081   return 0;
27411082}
27421083
27431084
27441085
2745/*-------------------------------------------------
2746    coco_halt_w - sets the HALT line
2747-------------------------------------------------*/
1086//-------------------------------------------------
1087//  ff60_write
1088//-------------------------------------------------
27481089
2749WRITE_LINE_DEVICE_HANDLER(coco_halt_w)
1090WRITE8_MEMBER( coco_state::ff60_write )
27501091{
2751   cputag_set_input_line(device->machine(), "maincpu", INPUT_LINE_HALT, state ? ASSERT_LINE : CLEAR_LINE);
2752}
2753
2754
2755
2756/*-------------------------------------------------
2757    coco_nmi_w - sets the NMI
2758-------------------------------------------------*/
2759
2760WRITE_LINE_DEVICE_HANDLER(coco_nmi_w)
2761{
2762   cputag_set_input_line(device->machine(), "maincpu", INPUT_LINE_NMI, state ? ASSERT_LINE : CLEAR_LINE);
2763}
2764
2765
2766
2767/*-------------------------------------------------
2768    coco_pia_1_w - wrapper for pia_1_w() that will
2769    also call twiddle Q lines, if necessary
2770-------------------------------------------------*/
2771
2772WRITE8_DEVICE_HANDLER(coco_pia_1_w)
2773{
2774   downcast<pia6821_device *>(device)->write(*memory_nonspecific_space(device->machine()), offset, data);
2775   cococart_device(device->machine())->twiddle_q_lines();
2776}
2777
2778
2779
2780/***************************************************************************/
2781
2782/* struct to hold callbacks and initializers to pass to generic_init_machine */
2783typedef struct _machine_init_interface machine_init_interface;
2784struct _machine_init_interface
2785{
2786   timer_expired_func recalc_interrupts_;         /* recalculate inturrupts callback */
2787   void (*printer_out_)(running_machine &machine, int data);            /* printer output callback */
2788};
2789
2790
2791
2792/* New generic_init_machine, this sets up the the machine parameters common to all machines in */
2793/* the CoCo and Dragon families, it has been modified to accept a single structure of type */
2794/* machine_init_interface, which makes the init code a little clearer */
2795/* Note sam initialization has been moved to generic_coco12_dragon_init, as it is now identical */
2796/* for everything except the coco3, so it made sense not to pass it as a parameter */
2797static void generic_init_machine(running_machine &machine, const machine_init_interface *init)
2798{
2799   coco_state *state = (coco_state *) machine.driver_data<coco_state>();
2800
2801   /* locate devices */
2802   state->m_cococart_device   = machine.device<cococart_slot_device>("ext");
2803   state->m_cassette_device   = machine.device<cassette_image_device>(CASSETTE_TAG);
2804   state->m_bitbanger_device   = machine.device("bitbanger");
2805   state->m_printer_device   = machine.device<printer_image_device>("printer");
2806   state->m_dac            = machine.device("dac");
2807   state->m_sam            = machine.device("sam");
2808   state->m_pia_0         = machine.device<pia6821_device>("pia_0");
2809   state->m_pia_1         = machine.device<pia6821_device>("pia_1");
2810   state->m_pia_2         = machine.device<pia6821_device>("pia_2");
2811
2812   /* clear static variables */
2813   state->m_hiresjoy_ca = 1;
2814   state->m_hiresjoy_xtransitiontime = attotime::zero;
2815   state->m_hiresjoy_ytransitiontime = attotime::zero;
2816
2817   /* set up function pointers */
2818   state->update_keyboard = coco_update_keyboard;
2819   state->m_recalc_interrupts = init->recalc_interrupts_;
2820
2821   /* this timer is used to schedule keyboard updating */
2822   state->m_update_keyboard_timer = machine.scheduler().timer_alloc(FUNC(coco_m_update_keyboard_timerproc));
2823
2824   /* these are the timers to delay the MUX switching */
2825   state->m_mux_sel1_timer = machine.scheduler().timer_alloc(FUNC(coco_update_sel1_timerproc));
2826   state->m_mux_sel2_timer = machine.scheduler().timer_alloc(FUNC(coco_update_sel2_timerproc));
2827
2828   /* setup ROM */
2829   state->m_rom = machine.region("maincpu")->base();
2830
2831   /* setup default rom bank */
2832   state->m_bas_rom_bank = state->m_rom;
2833
2834   /* setup default pointer for botom 32K of ram */
2835   state->m_bottom_32k = ram_get_ptr(machine.device(RAM_TAG));
2836
2837   /* setup printer output callback */
2838   state->printer_out = init->printer_out_;
2839   if (machine.device<cpu_device>("maincpu")->debug()) {
2840      machine.device<cpu_device>("maincpu")->debug()->set_dasm_override(coco_dasm_override);
1092   if ((m_vhd != NULL) && (offset >= 32) && (offset <= 37))
1093   {
1094      m_vhd->write(offset - 32, data);
28411095   }
2842
2843   /* setup printer input line to "space", this is what a Tandy printer would do */
2844   state->m_bitbanger_output_value = 1;
2845   state->m_bitbanger_input_value = 0;
2846   state->m_dac_value = 0;
2847
2848   state->save_item(NAME(state->m_mux_sel1));
2849   state->save_item(NAME(state->m_mux_sel2));
28501096}
28511097
2852/* Setup for hardware common to CoCo 1/2 & Dragon machines, calls genertic_init_machine, to process */
2853/* the setup common with the CoCo3, and then does the init that is not common ! */
2854static void generic_coco12_dragon_init(running_machine &machine, const machine_init_interface *init)
2855{
2856   /* Set default RAM mapping */
2857   memory_set_bankptr(machine, "bank1", &ram_get_ptr(machine.device(RAM_TAG))[0]);
28581098
2859   /* Do generic Inits */
2860   generic_init_machine(machine, init);
2861}
28621099
2863/******* Lightgun Setup **********/
1100/***************************************************************************
1101  CARTRIDGE & CASSETTE
1102 ***************************************************************************/
28641103
2865static void update_lightgun( running_machine &machine )
2866{
2867   /* is there a Diecom Light Gun either in Left or in Right Port? */
2868   UINT8 ctrl = input_port_read_safe(machine, "ctrl_sel", 0x00);
2869   int is_lightgun = ((ctrl & 0x0f) == 0x03 || (ctrl & 0xf0) == 0x30) ? 1 :0;
1104//-------------------------------------------------
1105//  ff40_read
1106//-------------------------------------------------
28701107
2871   crosshair_set_screen(machine, 0, is_lightgun ? CROSSHAIR_SCREEN_ALL : CROSSHAIR_SCREEN_NONE);
2872}
2873
2874INPUT_CHANGED( coco_joystick_mode_changed )
1108READ8_MEMBER( coco_state::ff40_read )
28751109{
2876   update_lightgun(field.machine());
1110   return m_cococart->read(space, offset, mem_mask);
28771111}
28781112
2879static TIMER_CALLBACK( update_lightgun_timer_callback )
2880{
2881   update_lightgun(machine);
2882}
28831113
2884/******* Machine Setups Dragons **********/
28851114
2886MACHINE_START( dragon32 )
2887{
2888   machine_init_interface init;
1115//-------------------------------------------------
1116//  ff40_write
1117//-------------------------------------------------
28891118
2890   /* Setup machine initialization */
2891   memset(&init, 0, sizeof(init));
2892   init.recalc_interrupts_   = d_recalc_interrupts;
2893   init.printer_out_      = printer_out_dragon;
2894
2895   generic_coco12_dragon_init(machine, &init);
2896
2897   /* need to specify lightgun crosshairs */
2898   machine.scheduler().timer_set(attotime::zero, FUNC(update_lightgun_timer_callback));
2899}
2900
2901MACHINE_START( dragon64 )
1119WRITE8_MEMBER( coco_state::ff40_write )
29021120{
2903   machine_init_interface init;
2904
2905   /* Setup machine initialization */
2906   memset(&init, 0, sizeof(init));
2907   init.recalc_interrupts_   = d_recalc_interrupts;
2908   init.printer_out_      = printer_out_dragon;
2909
2910   generic_coco12_dragon_init(machine, &init);
2911
2912   /* need to specify lightgun crosshairs */
2913   machine.scheduler().timer_set(attotime::zero, FUNC(update_lightgun_timer_callback));
1121   m_cococart->write(space, offset, data, mem_mask);
29141122}
29151123
2916MACHINE_START( tanodr64 )
2917{
2918   machine_init_interface init;
29191124
2920   /* Setup machine initialization */
2921   memset(&init, 0, sizeof(init));
2922   init.recalc_interrupts_   = d_recalc_interrupts;
2923   init.printer_out_      = printer_out_dragon;
29241125
2925   generic_coco12_dragon_init(machine, &init);
1126//-------------------------------------------------
1127//  cart_w
1128//-------------------------------------------------
29261129
2927   /* need to specify lightgun crosshairs */
2928   machine.scheduler().timer_set(attotime::zero, FUNC(update_lightgun_timer_callback));
2929}
2930
2931MACHINE_START( dgnalpha )
1130void coco_state::cart_w(bool state)
29321131{
2933   machine_init_interface init;
2934
2935   /* Setup machine initialization */
2936   memset(&init, 0, sizeof(init));
2937   init.recalc_interrupts_   = d_recalc_interrupts;
2938   init.printer_out_      = printer_out_dragon;
2939
2940   generic_coco12_dragon_init(machine, &init);
2941
2942   /* need to specify lightgun crosshairs */
2943   machine.scheduler().timer_set(attotime::zero, FUNC(update_lightgun_timer_callback));
1132   m_pia_1->cb1_w(state);
29441133}
29451134
2946MACHINE_RESET( dgnalpha )
2947{
2948   coco_state *state = machine.driver_data<coco_state>();
2949//  device_t *fdc = machine.device("wd2797");
2950//  wd17xx_set_complete_command_delay(fdc,20);
29511135
2952   /* state->m_dgnalpha_just_reset, is here to flag that we should ignore the first irq generated */
2953   /* by the WD2797, it is reset to 0 after the first inurrupt */
2954   state->m_dgnalpha_just_reset=1;
29551136
2956   /* need to specify lightgun crosshairs */
2957   machine.scheduler().timer_set(attotime::zero, FUNC(update_lightgun_timer_callback));
2958}
1137//-------------------------------------------------
1138//  cartridge_config
1139//-------------------------------------------------
29591140
2960const wd17xx_interface dgnalpha_wd17xx_interface =
1141const cococart_interface coco_state::cartridge_config =
29611142{
2962   DEVCB_NULL,
2963   DEVCB_LINE(dgnalpha_fdc_intrq_w),
2964   DEVCB_LINE(dgnalpha_fdc_drq_w),
2965   {FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3}
1143   DEVCB_DRIVER_LINE_MEMBER(coco_state, cart_w),      // coco_cart_w,
1144   DEVCB_CPU_INPUT_LINE(MAINCPU_TAG, INPUT_LINE_NMI),   // coco_nmi_w,
1145   DEVCB_CPU_INPUT_LINE(MAINCPU_TAG, INPUT_LINE_HALT)   // coco_halt_w
29661146};
29671147
2968/******* Machine Setups CoCos **********/
29691148
2970MACHINE_START( coco )
2971{
2972   machine_init_interface init;
1149//-------------------------------------------------
1150//  coco_cassette_interface
1151//-------------------------------------------------
29731152
2974   /* Setup machine initialization */
2975   memset(&init, 0, sizeof(init));
2976   init.recalc_interrupts_   = d_recalc_interrupts;
2977   init.printer_out_      = printer_out_coco;
2978
2979   generic_coco12_dragon_init(machine, &init);
2980
2981   /* need to specify lightgun crosshairs */
2982   machine.scheduler().timer_set(attotime::zero, FUNC(update_lightgun_timer_callback));
2983}
2984
2985MACHINE_START( coco2 )
1153const cassette_interface coco_state::coco_cassette_interface =
29861154{
2987   machine_init_interface init;
1155   coco_cassette_formats,
1156   NULL,
1157   (cassette_state)(CASSETTE_PLAY | CASSETTE_MOTOR_DISABLED | CASSETTE_SPEAKER_MUTED),
1158   NULL,
1159   NULL
1160};
29881161
2989   /* Setup machine initialization */
2990   memset(&init, 0, sizeof(init));
2991   init.recalc_interrupts_   = d_recalc_interrupts;
2992   init.printer_out_      = printer_out_coco;
29931162
2994   generic_coco12_dragon_init(machine, &init);
29951163
2996   /* need to specify lightgun crosshairs */
2997   machine.scheduler().timer_set(attotime::zero, FUNC(update_lightgun_timer_callback));
2998}
2999
3000MACHINE_RESET( coco3 )
3001{
3002   coco3_state *state = machine.driver_data<coco3_state>();
3003   int i;
3004
3005   /* Tepolt verifies that the GIME registers are all cleared on initialization */
3006   state->m_enable_64k = 0;
3007   state->m_gime_irq = 0;
3008   state->m_gime_firq = 0;
3009   for (i = 0; i < 8; i++)
3010   {
3011      state->m_mmu[i] = state->m_mmu[i + 8] = 56 + i;
3012      state->m_gimereg[i] = 0;
3013   }
3014   coco3_mmu_update(machine, 0, 8);
3015}
3016
3017static void coco3_state_postload(coco3_state *state)
3018{
3019   coco3_mmu_update(state->machine(), 0, 8);
3020}
3021
3022MACHINE_START( coco3 )
3023{
3024   coco3_state *state = machine.driver_data<coco3_state>();
3025   machine_init_interface init;
3026
3027   /* Setup machine initialization */
3028   memset(&init, 0, sizeof(init));
3029   init.recalc_interrupts_   = coco3_recalc_interrupts;
3030   init.printer_out_      = printer_out_coco;
3031
3032   generic_init_machine(machine, &init);
3033
3034   /* CoCo 3 specific function pointers */
3035   state->update_keyboard = coco3_update_keyboard;
3036
3037   coco3_timer_init(machine);
3038
3039   state->m_interupt_line = 0;
3040
3041   /* set up state save variables */
3042   state->save_item(NAME(state->m_mmu));
3043   state->save_item(NAME(state->m_gimereg));
3044   state->save_item(NAME(state->m_interupt_line));
3045   state->save_item(NAME(state->m_gime_irq));
3046   state->save_item(NAME(state->m_gime_firq));
3047   machine.save().register_postload(save_prepost_delegate(FUNC(coco3_state_postload), state));
3048
3049   /* need to specify lightgun crosshairs */
3050   machine.scheduler().timer_set(attotime::zero, FUNC(update_lightgun_timer_callback));
3051}
3052
3053
3054
30551164/***************************************************************************
3056  OS9 Syscalls for disassembly
3057****************************************************************************/
1165  DISASSEMBLY OVERRIDE (OS9 syscalls)
1166 ***************************************************************************/
30581167
30591168static const char *const os9syscalls[] =
30601169{
r13256r13257
32061315};
32071316
32081317
3209static offs_t coco_dasm_override(device_t &device, char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, int options)
1318offs_t coco_state::dasm_override(device_t &device, char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, int options)
32101319{
32111320   unsigned call;
32121321   unsigned result = 0;
r13256r13257
32151324   if ((oprom[0] == 0x10) && (oprom[1] == 0x3F))
32161325   {
32171326      call = oprom[2];
3218      if ((call < ARRAY_LENGTH(os9syscalls)) && os9syscalls[call])
1327      if ((call >= 0) && (call < ARRAY_LENGTH(os9syscalls)) && os9syscalls[call])
32191328      {
32201329         sprintf(buffer, "OS9   %s", os9syscalls[call]);
32211330         result = 3;
src/mess/machine/coco_vhd.c
r13256r13257
9696   update_names();
9797}
9898
99
100
99101//-------------------------------------------------
100102//  device_start - device-specific startup
101103//-------------------------------------------------
r13256r13257
103105void coco_vhd_image_device::device_start()
104106{
105107   m_status = VHDSTATUS_NO_VHD_ATTACHED;
108   m_cpu = downcast<cpu_device *>(machine().devicelist().find(MAINCPU_TAG));
109   m_cpu_space = m_cpu->space(AS_PROGRAM);
106110}
107111
112
113
114//-------------------------------------------------
115//  call_load
116//-------------------------------------------------
117
108118bool coco_vhd_image_device::call_load()
109119{
110120   m_status = VHDSTATUS_POWER_ON_STATE;
r13256r13257
113123   return IMAGE_INIT_PASS;
114124}
115125
126
127
128//-------------------------------------------------
129//  coco_vhd_readwrite
130//-------------------------------------------------
131
116132void coco_vhd_image_device::coco_vhd_readwrite(UINT8 data)
117133{
118134   int result;
119   int phyOffset;
120   UINT32 nBA = m_buffer_address;
135   void *ptr;
121136   UINT32 bytes_to_read;
122137   UINT32 bytes_to_write;
123138   UINT64 seek_position;
r13256r13257
160175      }
161176   }
162177
163   phyOffset = coco3_mmu_translate(device().machine(), (nBA >> 12 ) / 2, nBA % 8192 );
164
165178   switch(data)
166179   {
167180      case VHDCMD_READ: /* Read sector */
168         memset(&ram_get_ptr(device().machine().device(RAM_TAG))[phyOffset], 0, 256);
181         ptr = m_cpu_space->get_write_ptr(m_buffer_address);
182         memset(ptr, 0, 256);
169183         if (total_size > seek_position)
170184         {
171185            bytes_to_read = (UINT32) MIN((UINT64) 256, total_size - seek_position);
172            result = fread(&ram_get_ptr(device().machine().device(RAM_TAG))[phyOffset], bytes_to_read);
186            result = fread(ptr, bytes_to_read);
173187            if (result != bytes_to_read)
174188            {
175189               m_status = VHDSTATUS_ACCESS_DENIED;
r13256r13257
181195         break;
182196
183197      case VHDCMD_WRITE: /* Write Sector */
184         result = fwrite((&ram_get_ptr(device().machine().device(RAM_TAG))[phyOffset]), 256);
198         ptr = m_cpu_space->get_read_ptr(m_buffer_address);
199         result = fwrite(ptr, 256);
185200
186201         if (result != 256)
187202         {
r13256r13257
204219
205220
206221
207READ8_MEMBER(coco_vhd_image_device::read)
222UINT8 coco_vhd_image_device::read(offs_t offset)
208223{
209224   UINT8 result = 0;
210225
r13256r13257
221236
222237
223238
224WRITE8_MEMBER(coco_vhd_image_device::write)
239void coco_vhd_image_device::write(offs_t offset, UINT8 data)
225240{
226241   int pos;
227242
src/mess/machine/coco_vhd.h
r13256r13257
4040   virtual const option_guide *create_option_guide() const { return NULL; }
4141
4242   // specific implementation
43   DECLARE_READ8_MEMBER(read);
44   DECLARE_WRITE8_MEMBER(write);
43   DECLARE_READ8_MEMBER(read) { return read(offset); }
44   DECLARE_WRITE8_MEMBER(write) { write(offset, data); }
45   UINT8 read(offs_t offset);
46   void write(offs_t offset, UINT8 data);
4547
4648protected:
4749   // device-level overrides
r13256r13257
5052
5153   void coco_vhd_readwrite(UINT8 data);
5254
53   UINT32 m_logical_record_number;
54   UINT32 m_buffer_address;
55   UINT8  m_status;
55private:
56   cpu_device *         m_cpu;
57   address_space *         m_cpu_space;
58   UINT32               m_logical_record_number;
59   UINT32               m_buffer_address;
60   UINT8               m_status;
5661};
5762
5863// device type definition
src/mess/machine/coco_pak.c
r13256r13257
88
99#include "emu.h"
1010#include "coco_pak.h"
11#include "includes/coco.h"
1112#include "imagedev/cartslot.h"
1213
1314#define CARTSLOT_TAG         "cart"
r13256r13257
9798   if (m_cart->exists()) {
9899      cococart_line_value cart_line;
99100
100      cart_line = input_port_read_safe(machine(), "CARTAUTO", 0x01)
101      cart_line = input_port_read_safe(machine(), CART_AUTOSTART_TAG, 0x01)
101102         ? COCOCART_LINE_VALUE_Q
102103         : COCOCART_LINE_VALUE_CLEAR;
103104
src/mess/machine/6883sam.c
r13256r13257
1/**********************************************************************
1/***************************************************************************
22
3    Motorola 6883 SAM interface and emulation
3    6883sam.c
44
5    This function emulates all the functionality of one M6883
6    synchronous address multiplexer.
5    Motorola 6883 Synchronous Address Multiplexer
76
8    Note that the real SAM chip was intimately involved in things like
9    memory and video addressing, which are things that the MAME core
10    largely handles.  Thus, this code only takes care of a small part
11    of the SAM's actual functionality; it simply tracks the SAM
12    registers and handles things like save states.  It then delegates
13    the bulk of the responsibilities back to the host.
14
157    The Motorola 6883 SAM has 16 bits worth of state, but the state is changed
168    by writing into a 32 byte address space; odd bytes set bits and even bytes
179    clear bits.  Here is the layout:
18
10
1911        31  Set     TY  Map Type            0: RAM/ROM  1: All RAM
2012        30  Clear   TY  Map Type
2113        29  Set     M1  Memory Size         00: 4K      10: 64K Dynamic
r13256r13257
4941         1  Set     V0  VDG Mode
5042         0  Clear   V0  VDG Mode
5143
52**********************************************************************/
44   All parts of the SAM are fully emulated except R1/R0 (the changes in the
45   MPU rate are approximated) and M1/M0
5346
47***************************************************************************/
48
49#define ADDRESS_MAP_MODERN
50
5451#include "machine/6883sam.h"
55#include "machine/ram.h"
5652
57#define LOG_VIDEO_POSITION   0
53const device_type SAM6883 = &device_creator<sam6883_device>;
5854
59typedef enum
55
56//-------------------------------------------------
57//  ctor
58//-------------------------------------------------
59
60sam6883_device::sam6883_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
61   : device_t(mconfig, SAM6883, "SAM6883", tag, owner, clock)
6062{
61   TYPE_SAM6883 = 0,
62   TYPE_SAM6883_GIME = 1,
63} SAM6883_VERSION;
63   memset(m_banks, '\0', sizeof(m_banks));
64}
6465
6566
66/*****************************************************************************
67 Type definitions
68*****************************************************************************/
6967
70typedef struct _sam6883_t sam6883_t;
71struct _sam6883_t
72{
73   SAM6883_VERSION type;
74   const sam6883_interface *intf;
75   UINT16 state;
76   UINT16 old_state;
77   UINT16 video_position;
78   int last_scanline;
79};
68//-------------------------------------------------
69//  device_start - device-specific startup
70//-------------------------------------------------
8071
81static const UINT8 sam_video_mode_row_heights[] =
72void sam6883_device::device_start()
8273{
83   12,   /* 0 - Text */
84   3,   /* 1 - G1C/G1R */
85   3,   /* 2 - G2C */
86   2,   /* 3 - G2R */
87   2,   /* 4 - G3C */
88   1,   /* 5 - G3R */
89   1,   /* 6 - G4C/G4R */
90   1   /* 7 - Reserved/Invalid */
91};
74   const sam6883_interface *config = (const sam6883_interface *) static_config();
9275
93static const UINT8 sam_video_mode_row_pitches[] =
76   /* find the CPU */
77   m_cpu = downcast<cpu_device *>(machine().devicelist().find(config->m_cpu_tag));
78   m_cpu_space = m_cpu->space(config->m_cpu_space);
79
80   /* resolve callbacks */
81   m_res_input_func.resolve(config->m_input_func, *this);
82
83   /* install SAM handlers */
84   m_cpu_space->install_read_handler(0xFFC0, 0xFFDF, 0, 0, read8_delegate(FUNC(sam6883_device::read), this));
85   m_cpu_space->install_write_handler(0xFFC0, 0xFFDF, 0, 0, write8_delegate(FUNC(sam6883_device::write), this));
86
87   /* save state support */
88   save_item(NAME(m_sam_state));
89   save_item(NAME(m_counter));
90   save_item(NAME(m_counter_xdiv));
91   save_item(NAME(m_counter_ydiv));
92}
93
94
95
96//-------------------------------------------------
97//  configure_bank - bank configuration
98//-------------------------------------------------
99
100void sam6883_device::configure_bank(int bank, UINT8 *memory, UINT32 memory_size, bool is_read_only)
94101{
95   32,   /* 0 - Text */
96   16,   /* 1 - Graphics CG1/RG1 */
97   32,   /* 2 - Graphics CG2 */
98   16,   /* 3 - Graphics RG2 */
99   32,   /* 4 - Graphics CG3 */
100   16,   /* 5 - Graphics RG3 */
101   32,   /* 6 - Graphics CG6/RG6 */
102   32   /* 7 - Reserved/Invalid */
103};
102   configure_bank(bank, memory, memory_size, is_read_only, read8_delegate(), write8_delegate());
103}
104104
105105
106/*****************************************************************************
107 Implementation
108*****************************************************************************/
109106
110INLINE sam6883_t *get_safe_token(device_t *device)
107//-------------------------------------------------
108//  configure_bank - bank configuration
109//-------------------------------------------------
110
111void sam6883_device::configure_bank(int bank, read8_delegate rhandler, write8_delegate whandler)
111112{
112   assert(device != NULL);
113   assert(device->type() == SAM6883 || device->type() == SAM6883_GIME);
114
115   return (sam6883_t *)downcast<legacy_device_base *>(device)->token();
113   configure_bank(bank, NULL, 0, false, rhandler, whandler);
116114}
117115
118static void update_sam(device_t *device)
116
117
118//-------------------------------------------------
119//  configure_bank - bank configuration
120//-------------------------------------------------
121
122void sam6883_device::configure_bank(int bank, UINT8 *memory, UINT32 memory_size, bool is_read_only, read8_delegate rhandler, write8_delegate whandler)
119123{
120   sam6883_t *sam = get_safe_token(device);
121   UINT16 xorval;
124   assert((bank >= 0) && (bank < sizeof(m_banks) / sizeof(m_banks[0])));
125   m_banks[bank].m_memory = memory;
126   m_banks[bank].m_memory_size = memory_size;
127   m_banks[bank].m_memory_read_only = is_read_only;
128   m_banks[bank].m_rhandler = rhandler;
129   m_banks[bank].m_whandler = whandler;
122130
123   xorval = sam->old_state ^ sam->state;
124   sam->old_state = sam->state;
131   /* if we're configuring a bank that never changes, update it now */
132   switch(bank)
133   {
134      case 4:
135         update_bank(4, 0xFF00, 0xFF1F, 0x0000);
136         break;
137      case 5:
138         update_bank(5, 0xFF20, 0xFF3F, 0x0000);
139         break;
140      case 6:
141         update_bank(6, 0xFF40, 0xFF5F, 0x0000);
142         break;
143      case 7:
144         update_bank(7, 0xFF60, 0xFFBF, 0x0000);
145         break;
146      case 2:
147         update_bank(2, 0xFFE0, 0xFFFF, 0x1FE0);
148         break;
149   }
150}
125151
126   /* Check changes in Page #1 */
127   if ((xorval & 0x0400) && sam->intf->set_pageonemode)
128      sam->intf->set_pageonemode(device,(sam->state & 0x0400) / 0x0400);
129152
130   /* Check changes in MPU Rate */
131   if ((xorval & 0x1800) && sam->intf->set_mpurate)
132      sam->intf->set_mpurate(device,(sam->state & 0x1800) / 0x0800);
133153
134   /* Check changes in Memory Size */
135   if ((xorval & 0x6000) && sam->intf->set_memorysize)
136      sam->intf->set_memorysize(device,(sam->state & 0x6000) / 0x2000);
154//-------------------------------------------------
155//  device_reset - device-specific reset
156//-------------------------------------------------
137157
138   /* Check changes in Map Type */
139   if ((xorval & 0x8000) && sam->intf->set_maptype)
140      sam->intf->set_maptype(device,(sam->state & 0x8000) / 0x8000);
158void sam6883_device::device_reset()
159{
160   m_counter = 0;
161   m_counter_xdiv = 0;
162   m_counter_ydiv = 0;
163   m_sam_state = 0x0000;
164   update_state();
141165}
142166
143167
144168
145static void update_sam_postload(device_t *device)
169//-------------------------------------------------
170//  device_post_load - device-specific post load
171//-------------------------------------------------
172
173void sam6883_device::device_post_load()
146174{
147   update_sam(device);
175   device_t::device_post_load();
176   update_state();
148177}
149178
150void sam6883_set_state(device_t *device, UINT16 state, UINT16 mask)
179
180
181//-------------------------------------------------
182//  update_state
183//-------------------------------------------------
184
185void sam6883_device::update_state(void)
151186{
152   sam6883_t *sam = get_safe_token(device);
153   sam->state &= ~mask;
154   sam->state |= (state & mask);
155   update_sam(device);
187   update_memory();
188   update_cpu_clock();
156189}
157190
158WRITE8_DEVICE_HANDLER(sam6883_w)
191
192
193//-------------------------------------------------
194//  update_memory
195//-------------------------------------------------
196
197void sam6883_device::update_memory(void)
159198{
160   UINT16 mask;
161   sam6883_t *sam = get_safe_token(device);
199   /* Memory size - allowed restricting memory accesses to something less than
200     * 32k
201     *
202     * This was a SAM switch that occupied 4 addresses:
203     *
204     *      $FFDD   (set)   R1
205     *      $FFDC   (clear) R1
206     *      $FFDB   (set)   R0
207     *      $FFDA   (clear) R0
208     *
209     * R1:R0 formed the following states:
210     *      00  - 4k
211     *      01  - 16k
212     *      10  - 64k
213     *      11  - static RAM (??)
214     *
215     * If something less than 64k was set, the low RAM would be smaller and
216     * mirror the other parts of the RAM
217     *
218     * TODO:  Find out what "static RAM" is
219     * TODO:  This should affect _all_ memory accesses, not just video ram
220     * TODO:  Verify that the CoCo 3 ignored this
221     */
162222
163   if (offset < 32)
223   /* update $0000-$7FFF */
224   update_bank(0, 0x0000, 0x7FFF, m_sam_state & SAM_STATE_P1 ? 0x8000 : 0x0000);
225
226   if (m_sam_state & SAM_STATE_TY)
164227   {
165      mask = 1 << (offset / 2);
166      if (offset & 1)
167         sam->state |= mask;
168      else
169         sam->state &= ~mask;
170      update_sam(device);
228      update_bank(0, 0x8000, 0xFEFF, 0x8000);
171229   }
230   else
231   {
232      update_bank(1, 0x8000, 0x9FFF, 0x0000);
233      update_bank(2, 0xA000, 0xBFFF, 0x0000);
234      update_bank(3, 0xC000, 0xFEFF, 0x0000);
235   }
172236}
173237
174#if 0
175WRITE_LINE_DEVICE_HANDLER( sam6883_hs_w )
176{
177   sam6883_t *sam = get_safe_token(device);
178}
179238
180WRITE8_DEVICE_HANDLER( sam6883_da_w )
181{
182   sam6883_t *sam = get_safe_token(device);
183}
184#endif
185239
186const UINT8 *sam6883_videoram(device_t *device,int scanline)
240//-------------------------------------------------
241//  install_memory
242//-------------------------------------------------
243
244void sam6883_device::install_memory(offs_t addrstart, offs_t addrend, void *memory, bool is_read_only)
187245{
188   sam6883_t *sam = get_safe_token(device);
189   const UINT8 *ram_base;
190   UINT16 video_position;
191
192   if (scanline != sam->last_scanline)
246   if (addrend >= addrstart)
193247   {
194      /* first scanline? */
195      if (scanline == 0)
196      {
197         /* reset video position */
198         sam->video_position = (sam->state & 0x03F8) << 6;
199      }
248      if (memory == NULL)
249         m_cpu_space->unmap_readwrite(addrstart, addrend);
250      else if (is_read_only)
251         m_cpu_space->install_rom(addrstart, addrend, memory);
200252      else
201      {
202         /* time to advance a row? */
203         if ((scanline % sam_video_mode_row_heights[sam->state & 0x0007]) == 0)
204            sam->video_position += sam_video_mode_row_pitches[sam->state & 0x0007];
205      }
206      sam->last_scanline = scanline;
253         m_cpu_space->install_ram(addrstart, addrend, memory);
207254   }
255}
208256
209   video_position = sam->video_position;
210257
211   if (sam->type != TYPE_SAM6883_GIME)
258
259//-------------------------------------------------
260//  update_bank
261//-------------------------------------------------
262
263void sam6883_device::update_bank(int bank, offs_t addrstart, offs_t addrend, offs_t offset)
264{
265   assert((bank >= 0) && (bank < sizeof(m_banks) / sizeof(m_banks[0])));
266
267   if (m_banks[bank].m_memory != NULL)
212268   {
213      /* mask the video position according to the SAM's settings */
214      switch(sam->state & 0x6000)
215      {
216         case 0x0000:   video_position &= 0x0FFF;   break;   /* 4k */
217         case 0x2000:   video_position &= 0x3FFF;   break;   /* 16k */
218         default:      video_position &= 0xFFFF;   break;   /* 64k/static RAM */
219      }
269      /* this bank is a memory bank */
270      install_memory(addrstart, MIN(addrend, addrstart + m_banks[bank].m_memory_size - 1), m_banks[bank].m_memory + m_banks[bank].m_memory_offset + offset, m_banks[bank].m_memory_read_only);
271      install_memory(addrstart + m_banks[bank].m_memory_size, addrend, NULL, m_banks[bank].m_memory_read_only);
220272   }
273   else
274   {
275      /* this bank uses handlers */
276      assert(offset == 0);   /* changes to the offset are not supported */
277      if (!m_banks[bank].m_rhandler.isnull())
278         m_cpu_space->install_read_handler(addrstart, addrend, 0, 0, m_banks[bank].m_rhandler);
279      if (!m_banks[bank].m_whandler.isnull())
280         m_cpu_space->install_write_handler(addrstart, addrend, 0, 0, m_banks[bank].m_whandler);
281   }
282}
221283
222   if (LOG_VIDEO_POSITION)
223      logerror("sam_m6847_get_video_ram(): scanline=%d video_position=0x%04X\n", scanline, video_position);
224284
225   /* return actual position */
226   ram_base = sam->intf->get_rambase ? sam->intf->get_rambase(device) : ram_get_ptr(device->machine().device(RAM_TAG));
227   return &ram_base[video_position];
228}
229285
230UINT8 sam6883_memorysize(device_t *device)
286//-------------------------------------------------
287//  update_cpu_clock - adjusts the speed of the CPU
288//   clock
289//-------------------------------------------------
290
291void sam6883_friend_device::update_cpu_clock(void)
231292{
232   sam6883_t *sam = get_safe_token(device);
233   return (sam->state & 0x6000) / 0x2000;
293   /* The infamous speed up poke.
294     *
295     * This was a SAM switch that occupied 4 addresses:
296     *
297     *      $FFD9   (set)   R1
298     *      $FFD8   (clear) R1
299     *      $FFD7   (set)   R0
300     *      $FFD6   (clear) R0
301     *
302     * R1:R0 formed the following states:
303     *      00  - slow          0.89 MHz
304     *      01  - dual speed    ???
305     *      1x  - fast          1.78 MHz
306     *
307     * R1 controlled whether the video addressing was speeded up and R0
308     * did the same for the CPU.  On pre-CoCo 3 machines, setting R1 caused
309     * the screen to display garbage because the M6847 could not display
310     * fast enough.
311     *
312     * TODO:  Make the overclock more accurate.  In dual speed, ROM was a fast
313     * access but RAM was not.  I don't know how to simulate this.
314     */
315   int speed = (m_sam_state & (SAM_STATE_R1|SAM_STATE_R0)) / SAM_STATE_R0;
316
317   /* the line below is weird because we are not strictly emulating the M6809E with emphasis on the 'E' */
318   m_cpu->set_clock_scale(speed ? 2 : 1);
234319}
235320
236UINT8 sam6883_pagemode(device_t *device)
321
322
323//-------------------------------------------------
324//  set_bank_offset
325//-------------------------------------------------
326
327void sam6883_device::set_bank_offset(int bank, offs_t offset)
237328{
238   sam6883_t *sam = get_safe_token(device);
239   return (sam->state & 0x0400) / 0x0400;
329   if (m_banks[bank].m_memory_offset != offset)
330   {
331      m_banks[bank].m_memory_offset = offset;
332      update_memory();
333      update_bank(2, 0xFFE0, 0xFFFF, 0x1FE0);
334   }
240335}
241336
242UINT8 sam6883_maptype(device_t *device)
337
338
339//-------------------------------------------------
340//  read
341//-------------------------------------------------
342
343READ8_MEMBER( sam6883_device::read )
243344{
244   sam6883_t *sam = get_safe_token(device);
245   return (sam->state & 0x8000) / 0x8000;
345   return 0;
246346}
247347
248/* Device Interface */
249static void common_start(device_t *device, SAM6883_VERSION device_type)
250{
251   sam6883_t *sam = get_safe_token(device);
252   // validate arguments
253   assert(device != NULL);
254   assert(device->tag() != NULL);
255   assert(device->static_config() != NULL);
256348
257   sam->intf = (const sam6883_interface*)device->static_config();
258349
259   sam->type = device_type;
350//-------------------------------------------------
351//  write
352//-------------------------------------------------
260353
261   sam->state = 0;
262   sam->old_state = ~0;
354WRITE8_MEMBER( sam6883_device::write )
355{
356   /* alter the SAM state */
357   UINT16 xorval = alter_sam_state(offset);
263358
264   /* save state registration */
265   state_save_register_item(device->machine(), "6883sam", NULL, 0, sam->state);
266   state_save_register_item(device->machine(), "6883sam", NULL, 0, sam->video_position);
267   device->machine().save().register_postload(save_prepost_delegate(FUNC(update_sam_postload), device));
359   /* based on the mask, apply effects */
360   if (xorval & (SAM_STATE_TY|SAM_STATE_M1|SAM_STATE_M0|SAM_STATE_P1))
361      update_memory();
362   if (xorval & (SAM_STATE_R1|SAM_STATE_R0))
363      update_cpu_clock();
268364}
269365
270static DEVICE_START( sam6883 )
271{
272   common_start(device, TYPE_SAM6883);
273}
274366
275static DEVICE_START( sam6883_gime )
276{
277   common_start(device, TYPE_SAM6883_GIME);
278}
279367
280static DEVICE_RESET( sam6883 )
368//-------------------------------------------------
369//  horizontal_sync
370//-------------------------------------------------
371
372void sam6883_device::horizontal_sync(void)
281373{
282   sam6883_t *sam = get_safe_token(device);
283   sam->state = 0;
284   sam->old_state = ~0;
285   update_sam(device);
286}
374   bool carry;
287375
288DEVICE_GET_INFO( sam6883 )
289{
290   switch (state)
376   // When horizontal sync occurs, bits B1-B3 or B1-B4 may be cleared (except in DMA mode).  The catch
377   // is that the SAM's counter is a chain of flip-flops.  Clearing the counter can cause carries to
378   // occur just as they can when the counter is bumped.
379   //
380   // This is critical in getting certain semigraphics modes to work correctly.  Guardian uses this
381   // mode (see bug #1153).  Special thanks to Ciaran Anscomb and Phill Harvey-Smith for figuring this
382   // out
383   switch((m_sam_state & (SAM_STATE_V2|SAM_STATE_V1|SAM_STATE_V0)) / SAM_STATE_V0)
291384   {
292      /* --- the following bits of info are returned as 64-bit signed integers --- */
293      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(sam6883_t);               break;
294      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
385      case 0x01:
386      case 0x03:
387      case 0x05:
388         /* these SAM modes clear bits B1-B3 */
389         carry = (m_counter & 0x0008) ? true : false;
390         m_counter &= ~0x000F;
391         if (carry)
392            counter_carry_bit3();
393         break;
295394
296      /* --- the following bits of info are returned as pointers to data or functions --- */
297      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(sam6883);      break;
298      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
299      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(sam6883);      break;
395      case 0x00:
396      case 0x02:
397      case 0x04:
398      case 0x06:
399         /* clear bits B1-B4 */
400         carry = (m_counter & 0x0010) ? true : false;
401         m_counter &= ~0x001F;
402         if (carry)
403            counter_carry_bit4();
404         break;
300405
301      /* --- the following bits of info are returned as NULL-terminated strings --- */
302      case DEVINFO_STR_NAME:                     strcpy(info->s, "6883 SAM");                  break;
303      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "6883 SAM");                  break;
304      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                     break;
305      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                     break;
306      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright MESS Team");         break;
406      case 0x07:
407         /* DMA mode - do nothing */
408         break;
409
410      default:
411         fatalerror("Should not get here");
412         return;
307413   }
308414}
309415
310DEVICE_GET_INFO( sam6883_gime )
416
417
418//-------------------------------------------------
419//  hs_w
420//-------------------------------------------------
421
422WRITE_LINE_MEMBER( sam6883_device::hs_w )
311423{
312   switch (state)
424   if (state)
313425   {
314      /* --- the following bits of info are returned as NULL-terminated strings --- */
315      case DEVINFO_STR_NAME:                     strcpy(info->s, "6883 SAM GIME");            break;
316
317      /* --- the following bits of info are returned as pointers to data or functions --- */
318      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(sam6883_gime);   break;
319
320      default:                              DEVICE_GET_INFO_CALL(sam6883);            break;
426      horizontal_sync();
321427   }
322428}
323
324DEFINE_LEGACY_DEVICE(SAM6883, sam6883);
325DEFINE_LEGACY_DEVICE(SAM6883_GIME, sam6883_gime);
src/mess/machine/6883sam.h
r13256r13257
1/**********************************************************************
1/***************************************************************************
22
3    Motorola 6883 SAM interface and emulation
3    6883sam.h
44
5    This function emulates all the functionality of one M6883
6    synchronous address multiplexer.
5    Motorola 6883 Synchronous Address Multiplexer
76
8    Note that the real SAM chip was intimately involved in things like
9    memory and video addressing, which are things that the MAME core
10    largely handles.  Thus, this code only takes care of a small part
11    of the SAM's actual functionality; it simply tracks the SAM
12    registers and handles things like save states.  It then delegates
13    the bulk of the responsibilities back to the host.
7***************************************************************************/
148
15**********************************************************************/
9#pragma once
1610
17#ifndef __6833SAM_H__
18#define __6833SAM_H__
11#ifndef __6883SAM__
12#define __6883SAM__
1913
2014#include "emu.h"
21#include "devcb.h"
2215
16#define MCFG_SAM6883_ADD(_tag, _clock, _config) \
17   MCFG_DEVICE_ADD(_tag, SAM6883, _clock) \
18   MCFG_DEVICE_CONFIG(_config)
2319
24/***************************************************************************
25    MACROS
26***************************************************************************/
2720
28DECLARE_LEGACY_DEVICE(SAM6883, sam6883);
29DECLARE_LEGACY_DEVICE(SAM6883_GIME, sam6883_gime);
21/* interface */
22typedef struct _sam6883_interface sam6883_interface;
23struct _sam6883_interface
24{
25   /* the CPU/space from which the SAM reads data */
26   const char *      m_cpu_tag;
27   address_spacenum   m_cpu_space;
3028
31/***************************************************************************
32    TYPE DEFINITIONS
33***************************************************************************/
34typedef UINT8 *(*sam6883_get_rambase_func)(device_t *device);
35#define SAM6883_GET_RAMBASE(name)   UINT8 *name(device_t *device )
29   /* function for reading from memory for video */
30   devcb_read8         m_input_func;
31};
3632
37typedef void (*sam6883_set_pageonemode_func)(device_t *device, int val);
38#define SAM6883_SET_PAGE_ONE_MODE(name)   void name(device_t *device, int val )
3933
40typedef void (*sam6883_set_mpurate_func)(device_t *device, int val);
41#define SAM6883_SET_MPU_RATE(name)   void name(device_t *device, int val )
34//**************************************************************************
35//  SAM6883 CORE
36//**************************************************************************
4237
43typedef void (*sam6883_set_memorysize_func)(device_t *device, int val);
44#define SAM6883_SET_MEMORY_SIZE(name)   void name(device_t *device, int val )
38// base class so that GIME emulation can use some functionality
39class sam6883_friend_device
40{
41public:
42   sam6883_friend_device() { m_cpu = NULL; m_sam_state = 0x0000; }
4543
46typedef void (*sam6883_set_map_type_func)(device_t *device, int val);
47#define SAM6883_SET_MAP_TYPE(name)   void name(device_t *device, int val )
44protected:
45   // SAM state constants
46   static const UINT16 SAM_STATE_TY = 0x8000;
47   static const UINT16 SAM_STATE_M1 = 0x4000;
48   static const UINT16 SAM_STATE_M0 = 0x2000;
49   static const UINT16 SAM_STATE_R1 = 0x1000;
50   static const UINT16 SAM_STATE_R0 = 0x0800;
51   static const UINT16 SAM_STATE_P1 = 0x0400;
52   static const UINT16 SAM_STATE_F6 = 0x0200;
53   static const UINT16 SAM_STATE_F5 = 0x0100;
54   static const UINT16 SAM_STATE_F4 = 0x0080;
55   static const UINT16 SAM_STATE_F3 = 0x0040;
56   static const UINT16 SAM_STATE_F2 = 0x0020;
57   static const UINT16 SAM_STATE_F1 = 0x0010;
58   static const UINT16 SAM_STATE_F0 = 0x0008;
59   static const UINT16 SAM_STATE_V2 = 0x0004;
60   static const UINT16 SAM_STATE_V1 = 0x0002;
61   static const UINT16 SAM_STATE_V0 = 0x0001;
4862
63   // incidentals
64   cpu_device *         m_cpu;
4965
50typedef struct _sam6883_interface sam6883_interface;
51struct _sam6883_interface
52{
53   sam6883_get_rambase_func get_rambase;
54   sam6883_set_pageonemode_func set_pageonemode;
55   sam6883_set_mpurate_func set_mpurate;
56   sam6883_set_memorysize_func set_memorysize;
57   sam6883_set_map_type_func set_maptype;
66   // device state
67   UINT16               m_sam_state;
68
69   ATTR_FORCE_INLINE UINT16 display_offset(void)
70   {
71      return ((m_sam_state & (SAM_STATE_F0|SAM_STATE_F1|SAM_STATE_F2|SAM_STATE_F3|SAM_STATE_F4|SAM_STATE_F5|SAM_STATE_F6)) / SAM_STATE_F0) << 9;
72   }
73
74   ATTR_FORCE_INLINE UINT16 alter_sam_state(offs_t offset)
75   {
76      /* determine the mask */
77      UINT16 mask = 1 << (offset >> 1);
78
79      /* determine the new state */
80      UINT16 new_state;
81      if (offset & 0x0001)
82         new_state = m_sam_state | mask;
83      else
84         new_state = m_sam_state & ~mask;
85
86      /* specify the new state */
87      UINT16 xorval = m_sam_state ^ new_state;
88      m_sam_state = new_state;
89      return xorval;
90   }
91
92   void update_cpu_clock(void);
5893};
5994
60/***************************************************************************
61    FUNCTION PROTOTYPES
62***************************************************************************/
63/* Standard handlers */
95class sam6883_device : public device_t, public sam6883_friend_device
96{
97public:
98   sam6883_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
6499
65/* write to the SAM */
66WRITE8_DEVICE_HANDLER(sam6883_w);
100   // called to configure banks
101   void configure_bank(int bank, UINT8 *memory, UINT32 memory_size, bool is_read_only);
102   void configure_bank(int bank, read8_delegate rhandler, write8_delegate whandler);
67103
68/* set the state of the SAM */
69void sam6883_set_state(device_t *device,UINT16 state, UINT16 mask);
104   // typically called by VDG
105   ATTR_FORCE_INLINE DECLARE_READ8_MEMBER( display_read )
106   {
107      if (offset == (offs_t) ~0)
108      {
109         /* the VDG is telling the counter to reset */
110         m_counter = display_offset();
111         m_counter_xdiv = 0;
112         m_counter_ydiv = 0;
113      }
114      else if ((offset & 1) != (m_counter & 0x0001))
115      {
116         /* DA0 has been toggled - first bump B0-B3 of the counter */
117         bool bit3_carry = (m_counter & 0x000F) == 0x000F;
118         m_counter = (m_counter & ~0x000F) | ((m_counter + 1) & 0x000F);
70119
71/* used by video/m6847.c to read the position of the SAM */
72const UINT8 *sam6883_videoram(device_t *device,int scanline);
120         /* and apply the carry (if applicable */
121         if (bit3_carry)
122            counter_carry_bit3();
123      }
124      return m_res_input_func(m_counter);
125   }
73126
74/* used to get memory size and pagemode independent of callbacks */
75UINT8 sam6883_memorysize(device_t *device);
76UINT8 sam6883_pagemode(device_t *device);
77UINT8 sam6883_maptype(device_t *device);
127   DECLARE_WRITE_LINE_MEMBER( hs_w );
78128
79#if 0
80WRITE_LINE_DEVICE_HANDLER( sam6883_hs_w );
81#endif
129   // typically called by machine
130   address_space *mpu_address_space(void) const { return m_cpu_space; }
131   void set_bank_offset(int bank, offs_t offset);
82132
133protected:
134    // device-level overrides
135    virtual void device_start();
136   virtual void device_reset();
137   virtual void device_post_load();
83138
84/***************************************************************************
85    DEVICE CONFIGURATION MACROS
86***************************************************************************/
139private:
140   struct sam_bank
141   {
142      UINT8 *         m_memory;
143      UINT32         m_memory_size;
144      offs_t         m_memory_offset;
145      bool         m_memory_read_only;
146      read8_delegate   m_rhandler;
147      write8_delegate   m_whandler;
148   };
87149
88#define MCFG_SAM6883_ADD(_tag, _intrf) \
89   MCFG_DEVICE_ADD(_tag, SAM6883, 0) \
90   MCFG_DEVICE_CONFIG(_intrf)
150   // incidentals
151   address_space *         m_cpu_space;
152   devcb_resolved_read8   m_res_input_func;
153   sam_bank            m_banks[8];
91154
92#define MCFG_SAM6883_GIME_ADD(_tag, _intrf) \
93   MCFG_DEVICE_ADD(_tag, SAM6883_GIME, 0) \
94   MCFG_DEVICE_CONFIG(_intrf)
155   // SAM state
156   UINT16               m_counter;
157   UINT8               m_counter_xdiv;
158   UINT8               m_counter_ydiv;
95159
160   // typically called by CPU
161    DECLARE_READ8_MEMBER( read );
162    DECLARE_WRITE8_MEMBER( write );
96163
97#endif /* __6833SAM_H__ */
164   // called when there is a carry out of bit 3 on the counter
165   ATTR_FORCE_INLINE void counter_carry_bit3(void)
166   {
167      UINT8 x_division;
168      switch((m_sam_state & (SAM_STATE_V2|SAM_STATE_V1|SAM_STATE_V0)) / SAM_STATE_V0)
169      {
170         case 0x00:   x_division = 1;   break;
171         case 0x01:   x_division = 3;   break;
172         case 0x02:   x_division = 1;   break;
173         case 0x03:   x_division = 2;   break;
174         case 0x04:   x_division = 1;   break;
175         case 0x05:   x_division = 1;   break;
176         case 0x06:   x_division = 1;   break;
177         case 0x07:   x_division = 1;   break;
178         default:
179            fatalerror("Should not get here");
180            return;
181      }
182
183      if (++m_counter_xdiv >= x_division)
184      {
185         m_counter_xdiv = 0;
186         m_counter ^= 0x0010;
187         if ((m_counter & 0x0010) == 0x0000)
188            counter_carry_bit4();
189      }
190   }
191
192   // called when there is a carry out of bit 4 on the counter
193   ATTR_FORCE_INLINE void counter_carry_bit4(void)
194   {
195      UINT8 y_division;
196      switch((m_sam_state & (SAM_STATE_V2|SAM_STATE_V1|SAM_STATE_V0)) / SAM_STATE_V0)
197      {
198         case 0x00:   y_division = 12;   break;
199         case 0x01:   y_division = 1;      break;
200         case 0x02:   y_division = 3;      break;
201         case 0x03:   y_division = 1;      break;
202         case 0x04:   y_division = 2;      break;
203         case 0x05:   y_division = 1;      break;
204         case 0x06:   y_division = 1;      break;
205         case 0x07:   y_division = 1;      break;
206         default:
207            fatalerror("Should not get here");
208            return;
209      }
210
211      if (++m_counter_ydiv >= y_division)
212      {
213         m_counter_ydiv = 0;
214         m_counter += 0x0020;
215      }
216   }
217
218   // other members
219   void configure_bank(int bank, UINT8 *memory, UINT32 memory_size, bool is_read_only, read8_delegate rhandler, write8_delegate whandler);
220   void horizontal_sync(void);
221   void update_state(void);
222   void update_memory(void);
223   void update_bank(int bank, offs_t addrstart, offs_t addrend, offs_t offset);
224   void install_memory(offs_t addrstart, offs_t addrend, void *memory, bool is_read_only);
225};
226
227extern const device_type SAM6883;
228
229#endif /* __6883SAM__ */
src/mess/machine/coco12.c
r0r13257
1/***************************************************************************
2 
3    coco12.c
4 
5    TRS-80 Radio Shack Color Computer 1/2 Family
6 
7***************************************************************************/
8 
9#include "includes/coco12.h"
10 
11//-------------------------------------------------
12//  ctor
13//-------------------------------------------------
14 
15coco12_state::coco12_state(const machine_config &mconfig, device_type type, const char *tag)
16   : coco_state(mconfig, type, tag),
17     m_sam(*this, SAM_TAG),
18     m_vdg(*this, VDG_TAG)
19{
20}
21 
22 
23 
24//-------------------------------------------------
25//  device_start
26//-------------------------------------------------
27 
28void coco12_state::device_start()
29{
30   coco_state::device_start();
31   configure_sam();
32}
33 
34 
35 
36//-------------------------------------------------
37//  configure_sam
38//-------------------------------------------------
39 
40void coco12_state::configure_sam()
41{
42   cococart_slot_device *cart = m_cococart;
43   UINT8 *ram = m_ram->pointer();
44   UINT32 ram_size = m_ram->size();
45   UINT8 *rom = machine().region(MAINCPU_TAG)->base();
46   UINT8 *cart_rom = cart->get_cart_base();
47   
48   m_sam->configure_bank(0, ram, ram_size, false);         // $0000-$7FFF
49   m_sam->configure_bank(1, &rom[0x0000], 0x2000, true);   // $8000-$9FFF
50   m_sam->configure_bank(2, &rom[0x2000], 0x2000, true);   // $A000-$BFFF
51   m_sam->configure_bank(3, cart_rom, 0x4000, true);      // $C000-$FEFF
52 
53   // $FF00-$FF1F
54   m_sam->configure_bank(4, read8_delegate(FUNC(coco12_state::ff00_read), this), write8_delegate(FUNC(coco12_state::ff00_write), this));
55 
56   // $FF20-$FF3F
57   m_sam->configure_bank(5, read8_delegate(FUNC(coco12_state::ff20_read), this), write8_delegate(FUNC(coco12_state::ff20_write), this));
58 
59   // $FF40-$FF5F
60   m_sam->configure_bank(6, read8_delegate(FUNC(coco12_state::ff40_read), this), write8_delegate(FUNC(coco12_state::ff40_write), this));
61 
62   // $FF60-$FFBF
63   m_sam->configure_bank(7, read8_delegate(FUNC(coco12_state::ff60_read), this), write8_delegate(FUNC(coco12_state::ff60_write), this));
64}
65 
66 
67//-------------------------------------------------
68//  horizontal_sync
69//-------------------------------------------------
70 
71WRITE_LINE_MEMBER( coco12_state::horizontal_sync )
72{
73   m_pia_0->ca1_w(state);
74   m_sam->hs_w(state);
75}
76 
77 
78 
79//-------------------------------------------------
80//  field_sync
81//-------------------------------------------------
82 
83WRITE_LINE_MEMBER( coco12_state::field_sync )
84{
85   m_pia_0->cb1_w(state);
86}
87 
88 
89 
90//-------------------------------------------------
91//  sam_read
92//-------------------------------------------------
93 
94READ8_MEMBER( coco12_state::sam_read )
95{
96   UINT8 data = m_sam->mpu_address_space()->read_byte(offset);
97   m_vdg->as_w(data & 0x80 ? ASSERT_LINE : CLEAR_LINE);
98   m_vdg->inv_w(data & 0x40 ? ASSERT_LINE : CLEAR_LINE);
99   return data;
100}
101 
102 
103 
104//-------------------------------------------------
105//  pia1_pb_changed
106//-------------------------------------------------
107 
108void coco12_state::pia1_pb_changed(void)
109{
110   /* call inherited function */
111   coco_state::pia1_pb_changed();
112 
113   UINT8 data = m_pia_1->b_output();
114   m_vdg->css_w(data & 0x08);
115   m_vdg->intext_w(data & 0x10);
116   m_vdg->gm0_w(data & 0x10);
117   m_vdg->gm1_w(data & 0x20);
118   m_vdg->gm2_w(data & 0x40);
119   m_vdg->ag_w(data & 0x80);
120}
121 
122 
123 
124//-------------------------------------------------
125//  screen_update
126//-------------------------------------------------
127 
128bool coco12_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
129{
130   return m_vdg->update(&bitmap, &cliprect);
131}
132 
133 
134 
135 
136//-------------------------------------------------
137//  mc6847_config
138//-------------------------------------------------
139 
140const mc6847_interface coco12_state::mc6847_config =
141{
142   SCREEN_TAG,
143   DEVCB_DEVICE_MEMBER(SAM_TAG, sam6883_device, display_read),
144   DEVCB_DRIVER_LINE_MEMBER(coco12_state, horizontal_sync),
145   DEVCB_DRIVER_LINE_MEMBER(coco12_state, field_sync)
146};
147 
148 
149 
150//-------------------------------------------------
151//  sam6883_config
152//-------------------------------------------------
153 
154const sam6883_interface coco12_state::sam6883_config =
155{
156   MAINCPU_TAG,
157   AS_PROGRAM,
158   DEVCB_DRIVER_MEMBER(coco12_state, sam_read)
159};
src/mess/machine/dgnalpha.c
r0r13257
1/***************************************************************************
2 
3    dgnalpha.c
4 
5    Dragon Alpha
6 
7    The Dragon Alpha was a prototype in development when Dragon Data went bust,
8    it is basically an enhanced Dragon 64, with built in modem, disk system, and
9    graphical boot rom.
10 
11    It has the following extra hardware :-
12    A third 6821 PIA mapped between FF24 and FF27
13        An AY-8912, connected to the PIA.
14 
15    Port A of the PIA is connected as follows :-
16 
17        b0  BDIR of AY8912
18        b1  BC1 of AY8912
19        b2  Rom select, High= boot rom, low=BASIC rom
20        b3..7 not used.
21 
22    Port B
23        b0..7 connected to D0..7 of the AY8912.
24 
25    CB1 DRQ of WD2797.
26 
27    /irqa
28    /irqb   both connected to 6809 FIRQ.
29 
30 
31    The analog outputs of the AY-8912 are connected to the standard sound multiplexer.
32    The AY8912 output port is used as follows :-
33 
34        b0..b3  /DS0../DS3 for the drive interface (through an inverter first).
35        b4      /motor for the drive interface (through an inverter first).
36        b5..b7  not used as far as I can tell.
37 
38    A 6850 for the modem.
39 
40    A WD2797, used as an internal disk interface, this is however connected in a slightly strange
41    way that I am yet to completely determine.
42    19/10/2004, WD2797 is mapped between FF2C and FF2F, however the order of the registers is
43    reversed so the command Register is at the highest address instead of the lowest. The Data
44    request pin is connected to CB1(pin 18) of PIA2, to cause an firq, the INTRQ, is connected via
45    an inverter to the 6809's NMI.
46 
47    All these are as yet un-emulated.
48 
49    29-Oct-2004, AY-8912 is now emulated.
50    30-Oct-2004, Internal disk interface now emulated, Normal DragonDos rom replaced with a re-assembled
51                version, that talks to the alpha hardware (verified on a clone of the real machine).
52 
53Dragon Alpha code added 21-Oct-2004,
54            Phill Harvey-Smith (afra@aurigae.demon.co.uk)
55 
56            Added AY-8912 and FDC code 30-Oct-2004.
57 
58Fixed Dragon Alpha NMI enable/disable, following circuit traces on a real machine.
59    P.Harvey-Smith, 11-Aug-2005.
60 
61Re-implemented Alpha NMI enable/disable, using direct PIA reads, rather than
62keeping track of it in a variable in the driver.
63    P.Harvey-Smith, 25-Sep-2006.
64 
65***************************************************************************/   
66 
67#include "includes/dgnalpha.h"
68#include "sound/ay8910.h"
69#include "imagedev/flopdrv.h"
70 
71 
72//-------------------------------------------------
73//  ctor
74//-------------------------------------------------
75 
76dragon_alpha_state::dragon_alpha_state(const machine_config &mconfig, device_type type, const char *tag)
77   : dragon64_state(mconfig, type, tag),
78     m_pia_2(*this, PIA2_TAG),
79     m_ay8912(*this, AY8912_TAG),
80     m_fdc(*this, WD2797_TAG)
81{
82}
83 
84 
85//-------------------------------------------------
86//  device_start
87//-------------------------------------------------
88 
89void dragon_alpha_state::device_start(void)
90{
91   dragon_state::device_start();
92   save_item(NAME(m_just_reset));
93}
94 
95 
96 
97//-------------------------------------------------
98//  device_reset
99//-------------------------------------------------
100 
101void dragon_alpha_state::device_reset(void)
102{
103   dragon_state::device_reset();
104   m_just_reset = 1;
105}
106 
107 
108 
109/***************************************************************************
110  MODEM
111***************************************************************************/
112 
113//-------------------------------------------------
114//  modem_r
115//-------------------------------------------------
116 
117UINT8 dragon_alpha_state::modem_r(offs_t offset)
118{
119   return 0xFF;
120}
121 
122 
123 
124//-------------------------------------------------
125//  modem_w
126//-------------------------------------------------
127 
128void dragon_alpha_state::modem_w(offs_t offset, UINT8 data)
129{
130}
131 
132 
133 
134/***************************************************************************
135  PIA1
136***************************************************************************/
137 
138//-------------------------------------------------
139//  ff20_read
140//-------------------------------------------------
141 
142READ8_MEMBER( dragon_alpha_state::ff20_read )
143{
144   UINT8 result = 0x00;
145 
146   switch(offset & 0x07)
147   {
148      case 0: case 1: case 2: case 3:
149         result = dragon_state::ff20_read(space, offset, mem_mask);
150         break;
151 
152      case 4: case 5: case 6: case 7:
153         result = m_pia_2->read(space, offset, mem_mask);
154         break;
155 
156      case 8: case 9: case 10: case 11:
157         result = modem_r(offset);
158         break;
159 
160      case 12:
161         result = wd17xx_data_r(m_fdc, 0);
162         break;
163 
164      case 13:
165         result = wd17xx_sector_r(m_fdc, 0);
166         break;
167 
168      case 14:
169         result = wd17xx_track_r(m_fdc, 0);
170         break;
171 
172      case 15:
173         result = wd17xx_status_r(m_fdc, 0);
174         break;
175   }
176   return result;
177}
178 
179 
180 
181//-------------------------------------------------
182//  ff20_write
183//-------------------------------------------------
184 
185WRITE8_MEMBER( dragon_alpha_state::ff20_write )
186{
187   switch(offset & 0x07)
188   {
189      case 0: case 1: case 2: case 3:
190         dragon_state::ff20_write(space, offset, data, mem_mask);
191         break;
192 
193      case 4: case 5: case 6: case 7:
194         m_pia_2->write(space, offset, data, mem_mask);
195         break;
196 
197      case 8: case 9: case 10: case 11:
198         modem_w(offset, data);
199         break;
200 
201      case 12:
202         wd17xx_data_w(m_fdc, 0, data);
203         break;
204      case 13:
205         wd17xx_sector_w(m_fdc, 0, data);
206         break;
207      case 14:
208         wd17xx_track_w(m_fdc, 0, data);
209         break;
210      case 15:
211            wd17xx_command_w(m_fdc, 0, data);
212 
213         /* disk head is encoded in the command byte */
214         wd17xx_set_side(m_fdc,(data & 0x02) ? 1 : 0);
215         break;
216   }
217}
218 
219 
220/***************************************************************************
221  PIA2 ($FF24-$FF28) on Dragon Alpha/Professional
222 
223    PIA2 PA0        bcdir to AY-8912
224    PIA2 PA1        bc0 to AY-8912
225    PIA2 PA2        Rom switch, 0=basic rom, 1=boot rom.
226    PIA2 PA3-PA7    Unknown/unused ?
227    PIA2 PB0-PB7    connected to D0..7 of the AY8912.
228    CB1             DRQ from WD2797 disk controler.
229***************************************************************************/
230 
231//-------------------------------------------------
232//  pia2_pa_w
233//-------------------------------------------------
234 
235WRITE8_MEMBER( dragon_alpha_state::pia2_pa_w )
236{
237   /* If bit 2 of the pia2 ddra is 1 then this pin is an output so use it */
238   /* to control the paging of the boot and basic roms */
239   /* Otherwise it set as an input, with an internal pull-up so it should */
240   /* always be high (enabling boot rom) */
241   /* PIA FIXME if (pia_get_ddr_a(2) & 0x04) */
242   {
243      page_rom(data & 0x04 ? true : false);   /* bit 2 controls boot or basic rom */
244   }
245 
246   /* Bits 0 and 1 for pia2 port a control the BCDIR and BC1 lines of the */
247   /* AY-8912 */
248   switch (data & 0x03)
249   {
250      case 0x00:      /* Inactive, do nothing */
251         break;
252      case 0x01:      /* Write to selected port */
253         ay8910_data_w(m_ay8912, 0, m_pia_2->b_output());
254         break;
255      case 0x02:      /* Read from selected port */
256         m_pia_2->portb_w(ay8910_r(m_ay8912, 0));
257         break;
258      case 0x03:      /* Select port to write to */
259         ay8910_address_w(m_ay8912, 0, m_pia_2->b_output());
260         break;
261   }
262}
263 
264 
265 
266//-------------------------------------------------
267//  pia1_firq_a
268//-------------------------------------------------
269 
270WRITE_LINE_MEMBER( dragon_alpha_state::pia2_firq_a )
271{
272   recalculate_firq();
273}
274 
275 
276 
277//-------------------------------------------------
278//  pia1_firq_b
279//-------------------------------------------------
280 
281WRITE_LINE_MEMBER( dragon_alpha_state::pia2_firq_b )
282{
283   recalculate_firq();
284}
285 
286 
287 
288//-------------------------------------------------
289//  pia2_config
290//-------------------------------------------------
291 
292const pia6821_interface dragon_alpha_state::pia2_config =
293{
294   DEVCB_NULL,                                       /* port A input */
295   DEVCB_NULL,                                       /* port B input */
296   DEVCB_NULL,                                       /* CA1 input */
297   DEVCB_NULL,                                       /* CB1 input */
298   DEVCB_NULL,                                       /* CA2 input */
299   DEVCB_NULL,                                       /* CB2 input */
300   DEVCB_DRIVER_MEMBER(dragon_alpha_state, pia2_pa_w),         /* port A output */
301   DEVCB_NULL,                                       /* port B output */
302   DEVCB_NULL,                                       /* CA2 output */
303   DEVCB_NULL,                                       /* CB2 output */
304   DEVCB_DRIVER_LINE_MEMBER(dragon_alpha_state, pia2_firq_a),   /* IRQA output */
305   DEVCB_DRIVER_LINE_MEMBER(dragon_alpha_state, pia2_firq_b)   /* IRQB output */
306};
307 
308 
309 
310/***************************************************************************
311  CPU INTERRUPTS
312***************************************************************************/
313 
314//-------------------------------------------------
315//  firq_get_line - gets the value of the FIRQ line
316//   passed into the CPU
317//-------------------------------------------------
318 
319bool dragon_alpha_state::firq_get_line(void)
320{
321   return dragon_state::firq_get_line() || m_pia_2->irq_a_state() || m_pia_2->irq_b_state();
322}
323 
324 
325 
326/***************************************************************************
327  AY8912
328***************************************************************************/
329 
330//-------------------------------------------------
331//  psg_porta_read
332//-------------------------------------------------
333 
334READ8_MEMBER( dragon_alpha_state::psg_porta_read )
335{
336   return 0;
337}
338 
339 
340 
341//-------------------------------------------------
342//  psg_porta_read
343//-------------------------------------------------
344 
345WRITE8_MEMBER( dragon_alpha_state::psg_porta_write )
346{
347   /* Bits 0..3 are the drive select lines for the internal floppy interface */
348   /* Bit 4 is the motor on, in the real hardware these are inverted on their way to the drive */
349   /* Bits 5,6,7 are connected to /DDEN, ENP and 5/8 on the WD2797 */
350   switch (data & 0xF)
351   {
352      case(0x01) :
353         wd17xx_set_drive(m_fdc, 0);
354         break;
355      case(0x02) :
356         wd17xx_set_drive(m_fdc, 1);
357         break;
358      case(0x04) :
359         wd17xx_set_drive(m_fdc, 2);
360         break;
361      case(0x08) :
362         wd17xx_set_drive(m_fdc, 3);
363         break;
364   }
365}
366 
367 
368 
369//-------------------------------------------------
370//  ay8912_interface - AY-8912 for Dragon Alpha, the
371//  AY-8912 simply an AY-8910 with only one io port.
372//-------------------------------------------------
373 
374const ay8910_interface dragon_alpha_state::ay8912_interface =
375{
376   AY8910_LEGACY_OUTPUT,
377   AY8910_DEFAULT_LOADS,
378   DEVCB_DRIVER_MEMBER(dragon_alpha_state, psg_porta_read),   /* portA read */
379   DEVCB_NULL,                                     /* portB read */
380   DEVCB_DRIVER_MEMBER(dragon_alpha_state, psg_porta_write),   /* portA write */
381   DEVCB_NULL                                       /* portB write */
382};
383 
384 
385 
386/***************************************************************************
387  FDC
388***************************************************************************/
389 
390//-------------------------------------------------
391//  fdc_intrq_w - The NMI line on the Alpha is gated
392//   through IC16 (early PLD), and is gated by pia2 CA2
393//-------------------------------------------------
394 
395WRITE_LINE_MEMBER( dragon_alpha_state::fdc_intrq_w )
396{
397   if (state)
398   {
399      if (m_just_reset)
400      {
401         m_just_reset = 0;
402      }
403      else
404      {
405         if (m_pia_2->ca2_output_z())
406            m_maincpu->set_input_line(INPUT_LINE_NMI, ASSERT_LINE);
407        }
408   }
409   else
410   {
411      m_maincpu->set_input_line(INPUT_LINE_NMI, CLEAR_LINE);
412   }
413}
414 
415 
416 
417//-------------------------------------------------
418//  fdc_drq_w - The DRQ line goes through pia2 CB1,
419//   in exactly the same way as DRQ from DragonDos
420//   does for pia1 CB1
421//-------------------------------------------------
422 
423WRITE_LINE_MEMBER( dragon_alpha_state::fdc_drq_w )
424{
425   m_pia_2->cb1_w(state ? ASSERT_LINE : CLEAR_LINE);
426}
427 
428 
429 
430//-------------------------------------------------
431//  fdc_interface
432//-------------------------------------------------
433 
434const wd17xx_interface dragon_alpha_state::fdc_interface =
435{
436   DEVCB_NULL,
437   DEVCB_DRIVER_LINE_MEMBER(dragon_alpha_state, fdc_intrq_w),
438   DEVCB_DRIVER_LINE_MEMBER(dragon_alpha_state, fdc_drq_w),
439   {FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3}
440};
src/mess/machine/z80ne.c
r13256r13257
1414/* Components */
1515#include "machine/ay31015.h"
1616#include "machine/kr2376.h"
17#include "video/m6847.h"
17#include "video/mc6847.h"
1818#include "machine/wd17xx.h"
1919
2020/* Devices */
r13256r13257
629629   int d6 = BIT(videoram[offset], 6);
630630   int d7 = BIT(videoram[offset], 7);
631631
632   mc6847_inv_w(device, d6 && d7);
633   mc6847_as_w(device, !d6 && d7);
634   mc6847_intext_w(device, !d6 && d7);
632   state->m_vdg->inv_w(d6 && d7);
633   state->m_vdg->as_w(!d6 && d7);
634   state->m_vdg->intext_w(!d6 && d7);
635635
636636   return videoram[offset];
637637}
638638
639SCREEN_UPDATE( lx388 )
639bool z80ne_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
640640{
641   device_t *mc6847 = screen->machine().device("mc6847");
642   return mc6847_update(mc6847, bitmap, cliprect);
641   if (m_vdg != NULL)
642      return m_vdg->update(&bitmap, &cliprect);
643   else
644      return 0;
643645}
644646
645647READ8_HANDLER(lx388_data_r)
r13256r13257
654656
655657READ8_HANDLER( lx388_read_field_sync )
656658{
657   device_t *mc6847 = space->machine().device("mc6847");
658   return mc6847_fs_r(mc6847) << 7;
659   z80ne_state *state = space->machine().driver_data<z80ne_state>();
660   return state->m_vdg->fs_r() << 7;
659661}
660662
661663/*
src/mess/machine/dragon.c
r0r13257
1/***************************************************************************
2 
3    dragon.h
4 
5    Dragon Family
6 
7Dragon Alpha code added 21-Oct-2004,
8            Phill Harvey-Smith (afra@aurigae.demon.co.uk)
9 
10            Added AY-8912 and FDC code 30-Oct-2004.
11 
12Fixed Dragon Alpha NMI enable/disable, following circuit traces on a real machine.
13    P.Harvey-Smith, 11-Aug-2005.
14 
15Re-implemented Alpha NMI enable/disable, using direct PIA reads, rather than
16keeping track of it in a variable in the driver.
17    P.Harvey-Smith, 25-Sep-2006.
18 
19Radically re-wrote memory emulation code for CoCo 1/2 & Dragon machines, the
20new code emulates the memory mapping of the SAM, dependent on what size of
21RAM chips it is programed to use, including proper mirroring of the RAM.
22 
23Replaced the kludged emulation of the cart line, with a timer based trigger
24this is set to toggle at 1Hz, this seems to be good enough to trigger the
25cartline, but is so slow in real terms that it should have very little
26impact on the emulation speed.
27 
28Re-factored the code common to all machines, and seperated the code different,
29into callbacks/functions unique to the machines, in preperation for splitting
30the code for individual machine types into seperate files, I have preposed, that
31the CoCo 1/2 should stay in coco.c, and that the coco3 and dragon specifc code
32should go into coco3.c and dragon.c which should (hopefully) make the code
33easier to manage.
34    P.Harvey-Smith, Dec 2006-Feb 2007
35 
36***************************************************************************/
37 
38#include "includes/dragon.h"
39 
40 
41/***************************************************************************
42  DRAGON32
43***************************************************************************/
44 
45//-------------------------------------------------
46//  ctor
47//-------------------------------------------------
48 
49dragon_state::dragon_state(const machine_config &mconfig, device_type type, const char *tag)
50   : coco12_state(mconfig, type, tag),
51     m_printer(*this, PRINTER_TAG)
52{
53}
54 
55 
56 
57//-------------------------------------------------
58//  pia1_pa_changed - called when PIA1 PA changes
59//-------------------------------------------------
60 
61void dragon_state::pia1_pa_changed(void)
62{
63   /* call inherited function */
64   coco12_state::pia1_pa_changed();
65 
66   /* if strobe bit is high send data from pia0 port b to dragon parallel printer */
67   if (m_pia_1->a_output() & 0x02)
68   {
69      UINT8 output = m_pia_1->b_output();
70      m_printer->output(output);
71   }
72}
73 
74 
75/***************************************************************************
76  DRAGON64
77***************************************************************************/
78 
79//-------------------------------------------------
80//  ctor
81//-------------------------------------------------
82 
83dragon64_state::dragon64_state(const machine_config &mconfig, device_type type, const char *tag)
84   : dragon_state(mconfig, type, tag),
85     m_acia(*this, ACIA_TAG)
86{
87}
88 
89 
90 
91//-------------------------------------------------
92//  ff00_read
93//-------------------------------------------------
94 
95READ8_MEMBER( dragon64_state::ff00_read )
96{
97   UINT8 result = 0x00;
98 
99   switch(offset & 0x07)
100   {
101      case 0: case 1: case 2: case 3:
102         result = dragon_state::ff00_read(space, offset, mem_mask);
103         break;
104 
105      case 4: case 5: case 6: case 7:
106         result = m_acia->read(space, offset, mem_mask);
107         break;
108   }
109   return result;
110}
111 
112 
113 
114//-------------------------------------------------
115//  ff00_write
116//-------------------------------------------------
117 
118WRITE8_MEMBER( dragon64_state::ff00_write )
119{
120   switch(offset & 0x07)
121   {
122      case 0: case 1: case 2: case 3:
123         dragon_state::ff00_write(space, offset, data, mem_mask);
124         break;
125 
126      case 4: case 5: case 6: case 7:
127         m_acia->write(space, offset, data, mem_mask);
128         break;
129   }
130}
131 
132 
133 
134//-------------------------------------------------
135//  pia1_pb_changed
136//-------------------------------------------------
137 
138void dragon64_state::pia1_pb_changed(void)
139{
140   dragon_state::pia1_pb_changed();
141 
142   UINT8 ddr = ~m_pia_1->port_b_z_mask();
143 
144   /* If bit 2 of the pia1 ddrb is 1 then this pin is an output so use it */
145   /* to control the paging of the 32k and 64k basic roms */
146   /* Otherwise it set as an input, with an EXTERNAL pull-up so it should */
147   /* always be high (enabling 32k basic rom) */
148   if (ddr & 0x04)
149   {
150      page_rom(m_pia_1->b_output() & 0x04 ? true : false);
151   }
152}
153 
154 
155 
156//-------------------------------------------------
157//  page_rom - Controls rom paging in Dragon 64,
158//  and Dragon Alpha.
159//
160//   On 64, switches between the two versions of the
161//   basic rom mapped in at 0x8000
162//
163//   On the alpha switches between the
164//   Boot/Diagnostic rom and the basic rom 
165//-------------------------------------------------
166 
167void dragon64_state::page_rom(bool romswitch)
168{
169   offs_t offset = romswitch
170      ? 0x0000   // This is the 32k mode basic(64)/boot rom(alpha)
171      : 0x8000;   // This is the 64k mode basic(64)/basic rom(alpha) 
172   m_sam->set_bank_offset(1, offset);
173   m_sam->set_bank_offset(2, offset);
174   m_sam->set_bank_offset(3, offset);
175}
src/mess/machine/coco3.c
r0r13257
1/***************************************************************************
2 
3    coco3.c
4 
5    TRS-80 Radio Shack Color Computer 3
6 
7  Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
8  I/O ports)
9 
10  The Dragon/CoCo2 have two PIAs.  These PIAs can trigger interrupts.  PIA0
11  is set up to trigger IRQ on the CPU, and PIA1 can trigger FIRQ.  Each PIA
12  has two output lines, and an interrupt will be triggered if either of these
13  lines are asserted.
14 
15  -----  IRQ
16  6809 |-<----------- PIA0
17       |
18       |
19       |
20       |
21       |
22       |-<----------- PIA1
23  -----
24 
25  The CoCo 3 still supports these interrupts, but the GIME can chose whether
26  "old school" interrupts are generated, or the new ones generated by the GIME
27 
28  -----  IRQ
29  6809 |-<----------- PIA0
30       |       |                ------
31       |       -<-------<-------|    |
32       |                        |GIME|
33       |       -<-------<-------|    |
34       | FIRQ  |                ------
35       |-<----------- PIA1
36  -----
37 
38  In an email discussion with JK, he informs me that when GIME interrupts are
39  enabled, this actually does not prevent PIA interrupts.  Apparently JeffV's
40  CoCo 3 emulator did not handle this properly.
41 
42***************************************************************************/
43 
44#include "includes/coco3.h"
45 
46 
47 
48//-------------------------------------------------
49//  ctor
50//-------------------------------------------------
51 
52coco3_state::coco3_state(const machine_config &mconfig, device_type type, const char *tag)
53   : coco_state(mconfig, type, tag),
54     m_gime(*this, GIME_TAG)
55{
56}
57 
58 
59 
60//-------------------------------------------------
61//  ff20_write
62//-------------------------------------------------
63 
64WRITE8_MEMBER( coco3_state::ff20_write )
65{
66   coco_state::ff20_write(space, offset, data, mem_mask);
67 
68   if (offset == 0x02)
69      m_gime->ff22_write(data);
70}
71 
72 
73 
74//-------------------------------------------------
75//  ff40_read
76//-------------------------------------------------
77 
78READ8_MEMBER( coco3_state::ff40_read )
79{
80   UINT8 result = 0x00;
81   if (m_gime->spare_chip_select_enabled())
82      result = coco_state::ff40_read(space, offset, mem_mask);
83   return result;
84}
85 
86 
87 
88//-------------------------------------------------
89//  ff40_write
90//-------------------------------------------------
91 
92WRITE8_MEMBER( coco3_state::ff40_write )
93{
94   if (m_gime->spare_chip_select_enabled())
95      coco_state::ff40_write(space, offset, data, mem_mask);
96}
97 
98 
99 
100//-------------------------------------------------
101//  firq_get_line
102//-------------------------------------------------
103 
104bool coco3_state::firq_get_line(void)
105{
106   return coco_state::firq_get_line() || m_gime->firq_r();
107}
108 
109 
110 
111//-------------------------------------------------
112//  irq_get_line
113//-------------------------------------------------
114 
115bool coco3_state::irq_get_line(void)
116{
117   return coco_state::irq_get_line() || m_gime->irq_r();
118}
119 
120 
121 
122//-------------------------------------------------
123//  update_keyboard_input 
124//-------------------------------------------------
125 
126void coco3_state::update_keyboard_input(UINT8 value, UINT8 z)
127{
128   coco_state::update_keyboard_input(value, z);
129   m_gime->set_il1(value == 0xFF);
130}
131 
132 
133 
134//-------------------------------------------------
135//  cart_w 
136//-------------------------------------------------
137 
138void coco3_state::cart_w(bool state)
139{
140   coco_state::cart_w(state);
141   m_gime->set_il0(state);
142}
143 
144 
145 
146//-------------------------------------------------
147//  screen_update
148//-------------------------------------------------
149 
150bool coco3_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
151{
152   bool result;
153   if (!strcmp(screen.tag(), COMPOSITE_SCREEN_TAG))
154   {
155      /* composite screen */
156      result = m_gime->update_composite(&bitmap, &cliprect);
157   }
158   else if (!strcmp(screen.tag(), RGB_SCREEN_TAG))
159   {
160      /* rgb screen */
161      result = m_gime->update_rgb(&bitmap, &cliprect);
162   }
163   else
164   {
165      fatalerror("Called screen_update() with invalid tag '%s'", screen.tag());
166   }
167   return result;
168}
169 
170 
src/mess/video/coco6847.c
r13256r13257
1/*********************************************************************
2
3    coco6847.c
4
5    OBSOLETE Implementation of Motorola 6847 video hardware chip
6
7    Sources:
8    M6847 data sheet
9    M6847T1 info from Rainbow magazine (10/1986-12/1986)
10
11
12    AG  AS  INTEXT  INV  GM2  GM1  GM0
13    --  --  ------  ---  ---  ---  ---
14     0   0       0    0    X    X    X  Internal Alphanumerics
15     0   0       0    1    X    X    X  Internal Alphanumerics Inverted
16     0   0       1    0    X    X    X  External Alphanumerics
17     0   0       1    1    X    X    X  External Alphanumerics Inverted
18     0   1       0    X    X    X    X  Semigraphics 4
19     0   1       1    X    X    X    X  Semigraphics 6
20     1   X       X    X    0    0    0  Graphics CG1 (64x64x4)    (16 bpr)
21     1   X       X    X    0    0    1  Graphics RG1 (128x64x2)   (16 bpr)
22     1   X       X    X    0    1    0  Graphics CG2 (128x64x4)   (32 bpr)
23     1   X       X    X    0    1    1  Graphics RG2 (128x96x2)   (16 bpr)
24     1   X       X    X    1    0    0  Graphics CG3 (128x96x4)   (32 bpr)
25     1   X       X    X    1    0    1  Graphics RG3 (128x192x2)  (16 bpr)
26     1   X       X    X    1    1    0  Graphics CG6 (128x192x4)  (32 bpr)
27     1   X       X    X    1    1    1  Graphics RG6 (256x192x2)  (32 bpr)
28
29    Note: The M6847 relies on an external source (typically a 6883 SAM chip)
30    to feed it bytes; so the BPR (bytes per row) figures are effectively
31    suggestions.  Mismatching modes is responsible for the semigraphic modes
32    on the CoCo.
33
34    Timing:
35    (source Motorola M6847 Manual)
36
37    Horizontal Sync:  Total Period: 227.5 clock cycles
38        @ CLK(0) + DHS_F            - falling edge (high to low)
39        @ CLK(16.5) + DHS_R         - rising edge (low to high)
40        @ CLK(42)                   - left border start
41        @ CLK(71.5)                 - body start
42        @ CLK(199.5)                - right border start
43        @ CLK(227.5) + DHS_F        - falling edge (high to low)
44        ...
45
46    Field Sync: Total Period 262*227.5 clock cycles
47        @ CLK(0) + DFS_F            - falling edge (high to low)
48        @ CLK(32*227.5) + DFS_R     - rising edge (low to high)
49        @ CLK(262*227.5) + DFS_F    - falling edge (high to low) (262.5 for the M6847Y)
50
51    DHS_F:  550ns
52    DHS_R:  740ns
53    DFS_F:  520ns
54    DFS_R:  500ns
55
56    The M6847T1 is a later variant of the M6847 chip that implements lower
57    case support and some other nifty features.  This chip is in the CoCo 2B.
58    I have not been able to find a pinout diagram for this chip so I am
59    assuming that the extra text modes on the CoCo 2B are activated by the
60    GM2-0 pins.  This needs to be confirmed.
61
62    TODO: Implement PAL support
63
64**********************************************************************/
65
66#include "emu.h"
67#include "coco6847.h"
68
69#include "debug/debugcpu.h"
70#include "debug/debugcon.h"
71
72
73#define LOG_FS         0
74#define LOG_HS         0
75#define LOG_STATS      0
76#define LOG_PREPARE      0
77
78typedef struct _m6847_variant m6847_variant;
79struct _m6847_variant
80{
81   const UINT8 *fontdata;
82   unsigned int has_lowercase : 1;
83   unsigned int text_offset : 1;
84
85   int frames_per_second;
86   double scanlines_per_frame;
87   double clocks_per_scanline;
88
89   double vblank_scanlines;
90   int top_border_scanlines;
91   int display_scanlines;
92   int bottom_border_scanlines;
93   int vretrace_scanlines;
94
95   double field_sync_scanlines;
96};
97
98typedef struct _m6847_pixel m6847_pixel;
99struct _m6847_pixel
100{
101   UINT8 data;
102   UINT8 attr;
103};
104
105typedef struct _m6847_vdg m6847_vdg;
106struct _m6847_vdg
107{
108   /* callbacks */
109   void (*horizontal_sync_callback)(running_machine &machine, int line);
110   void (*field_sync_callback)(running_machine &machine, int line);
111   UINT8 (*get_attributes)(running_machine &machine, UINT8 c,int scanline, int pos);
112   const UINT8 *(*get_video_ram)(running_machine &machine, int scanline);
113   int (*new_frame_callback)(running_machine &machine);   /* returns whether the M6847 is in charge of this frame */
114   void (*custom_prepare_scanline)(running_machine &machine, int scanline);
115   UINT8 (*get_char_rom)(running_machine &machine, UINT8 ch,int line);
116
117   /* timers */
118   emu_timer *fs_rise_timer;
119   emu_timer *fs_fall_timer;
120   emu_timer *hs_rise_timer;
121   emu_timer *hs_fall_timer;
122
123   /* things that vary according to chip version */
124   attoseconds_t clock_period;
125   attoseconds_t scanline_period;
126   attoseconds_t field_sync_period;
127   attoseconds_t horizontal_sync_period;
128   attoseconds_t vblank_period;
129   int top_border_scanlines;
130   int display_scanlines;
131   int bottom_border_scanlines;
132   const UINT32 *palette;
133
134   /* flags */
135   unsigned int has_lowercase : 1;         /* M6847T1 has lower case */
136   unsigned int has_custom_palette : 1;   /* needed for CoCo 3 */
137   unsigned int text_offset : 2;         /* needed for CoCo 3 */
138
139   /* video state; every scanline the video state for the scanline is copied
140     * here and only rendered in SCREEN_UPDATE */
141   int dirty;
142   int using_custom;
143   UINT32 border[384];
144   UINT8 attrs[384];
145   m6847_pixel screendata[192][32];
146
147   /* saved palette; used with CoCo 3 */
148   UINT32 saved_palette[16];
149
150   UINT32 saved_artifacting, saved_c0, saved_c1;
151   UINT32 expanded_colors[128];
152
153   /* 2^7 modes, 256/16 character groups, background/foreground */
154   UINT8 colordata[128][256/16][2];
155
156   /* 2^7 modes, 256 characters, 12 scanlines */
157   UINT8 fontdata[128][256][12];
158};
159
160
161
162static void apply_artifacts(running_machine &machine, UINT32 *line);
163
164static m6847_vdg *m6847;
165
166
167static const UINT8 pal_round_fontdata8x12[] =
168{
169   0x00, 0x00, 0x38, 0x44, 0x04, 0x34, 0x4C, 0x4C, 0x38, 0x00, 0x00, 0x00,
170   0x00, 0x00, 0x10, 0x28, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x00, 0x00, 0x00,
171   0x00, 0x00, 0x78, 0x24, 0x24, 0x38, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
172   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
173   0x00, 0x00, 0x78, 0x24, 0x24, 0x24, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
174   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
175   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
176   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x4C, 0x44, 0x38, 0x00, 0x00, 0x00,
177   0x00, 0x00, 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
178   0x00, 0x00, 0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
179   0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
180   0x00, 0x00, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
181   0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
182   0x00, 0x00, 0x44, 0x6C, 0x54, 0x54, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
183   0x00, 0x00, 0x44, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x44, 0x00, 0x00, 0x00,
184   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
185   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
186   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
187   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
188   0x00, 0x00, 0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
189   0x00, 0x00, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
190   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
191   0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x00, 0x00, 0x00,
192   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x54, 0x6C, 0x44, 0x00, 0x00, 0x00,
193   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00, 0x00, 0x00,
194   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
195   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7C, 0x00, 0x00, 0x00,
196   0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00, 0x00,
197   0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00,
198   0x00, 0x00, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x00,
199   0x00, 0x00, 0x10, 0x38, 0x54, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
200   0x00, 0x00, 0x00, 0x10, 0x20, 0x7C, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00,
201   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202   0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
203   0x00, 0x00, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
204   0x00, 0x00, 0x28, 0x28, 0x7C, 0x28, 0x7C, 0x28, 0x28, 0x00, 0x00, 0x00,
205   0x00, 0x00, 0x10, 0x3C, 0x50, 0x38, 0x14, 0x78, 0x10, 0x00, 0x00, 0x00,
206   0x00, 0x00, 0x60, 0x64, 0x08, 0x10, 0x20, 0x4C, 0x0C, 0x00, 0x00, 0x00,
207   0x00, 0x00, 0x20, 0x50, 0x50, 0x20, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
208   0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209   0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
210   0x00, 0x00, 0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
211   0x00, 0x00, 0x00, 0x10, 0x54, 0x38, 0x38, 0x54, 0x10, 0x00, 0x00, 0x00,
212   0x00, 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
213   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x40, 0x00, 0x00,
214   0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
216   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00,
217   0x00, 0x00, 0x38, 0x44, 0x4C, 0x54, 0x64, 0x44, 0x38, 0x00, 0x00, 0x00,
218   0x00, 0x00, 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
219   0x00, 0x00, 0x38, 0x44, 0x04, 0x38, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
220   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
221   0x00, 0x00, 0x08, 0x18, 0x28, 0x48, 0x7C, 0x08, 0x08, 0x00, 0x00, 0x00,
222   0x00, 0x00, 0x7C, 0x40, 0x78, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
223   0x00, 0x00, 0x38, 0x40, 0x40, 0x78, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
224   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40, 0x00, 0x00, 0x00,
225   0x00, 0x00, 0x38, 0x44, 0x44, 0x38, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
226   0x00, 0x00, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x38, 0x00, 0x00, 0x00,
227   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
228   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00,
229   0x00, 0x00, 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
230   0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00,
231   0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
232   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
233
234   /* Lower case */
235   0x00, 0x00, 0x18, 0x24, 0x20, 0x70, 0x20, 0x24, 0x78, 0x00, 0x00, 0x00,
236   0x00, 0x00, 0x00, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, 0x00, 0x00,
237   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x64, 0x58, 0x00, 0x00, 0x00,
238   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
239   0x00, 0x00, 0x04, 0x04, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
240   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00, 0x00, 0x00,
241   0x00, 0x00, 0x08, 0x14, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
242   0x00, 0x00, 0x00, 0x00, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x04, 0x38, 0x00,
243   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
244   0x00, 0x00, 0x10, 0x00, 0x30, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
245   0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00,
246   0x00, 0x00, 0x40, 0x40, 0x48, 0x50, 0x60, 0x50, 0x48, 0x00, 0x00, 0x00,
247   0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
248   0x00, 0x00, 0x00, 0x00, 0x78, 0x54, 0x54, 0x54, 0x54, 0x00, 0x00, 0x00,
249   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
250   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
251   0x00, 0x00, 0x00, 0x00, 0x78, 0x44, 0x44, 0x44, 0x78, 0x40, 0x40, 0x00,
252   0x00, 0x00, 0x00, 0x00, 0x3C, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x00,
253   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
254   0x00, 0x00, 0x00, 0x00, 0x3C, 0x40, 0x38, 0x04, 0x78, 0x00, 0x00, 0x00,
255   0x00, 0x00, 0x20, 0x20, 0x70, 0x20, 0x20, 0x24, 0x18, 0x00, 0x00, 0x00,
256   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
257   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00, 0x00, 0x00,
258   0x00, 0x00, 0x00, 0x00, 0x44, 0x54, 0x54, 0x28, 0x28, 0x00, 0x00, 0x00,
259   0x00, 0x00, 0x00, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00,
260   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x38, 0x00, 0x00,
261   0x00, 0x00, 0x00, 0x00, 0x7C, 0x08, 0x10, 0x20, 0x7C, 0x00, 0x00, 0x00,
262   0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,
263   0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
264   0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00,
265   0x00, 0x00, 0x20, 0x54, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00,
267
268   /* Semigraphics 6 */
269   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
271   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
272   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
273   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
274   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
275   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
276   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
277   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
278   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
279   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
280   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
281   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
282   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
283   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
284   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
285   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
287   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
288   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
289   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
290   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
291   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
292   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
293   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
294   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
295   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
296   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
297   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
298   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
299   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
300   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
301   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
302   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
303   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
304   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
305   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
306   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
307   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
308   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
309   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
310   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
311   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
312   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
313   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
314   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
315   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
316   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
317   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
318   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
319   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
320   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
321   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
322   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
323   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
324   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
325   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
326   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
327   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
328   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
329   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
330   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
331   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
332   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
333
334   /* Block Graphics (Semigraphics 4 Graphics ) */
335   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
336   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
337   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
338   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
339   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
340   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
341   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
342   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
343   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
344   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
345   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
346   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
347   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
348   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
349   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
350   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
351};
352
353
354
355static const UINT8 pal_square_fontdata8x12[] =
356{
357   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1A, 0x2A, 0x2A, 0x1C, 0x00, 0x00,
358   0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x00, 0x00,
359   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x1C, 0x12, 0x12, 0x3C, 0x00, 0x00,
360   0x00, 0x00, 0x00, 0x1C, 0x22, 0x20, 0x20, 0x20, 0x22, 0x1C, 0x00, 0x00,
361   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x12, 0x12, 0x12, 0x3C, 0x00, 0x00,
362   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x3C, 0x20, 0x20, 0x3E, 0x00, 0x00,
363   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00,
364   0x00, 0x00, 0x00, 0x1E, 0x20, 0x20, 0x26, 0x22, 0x22, 0x1E, 0x00, 0x00,
365   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x22, 0x00, 0x00,
366   0x00, 0x00, 0x00, 0x1C, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
367   0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x22, 0x22, 0x1C, 0x00, 0x00,
368   0x00, 0x00, 0x00, 0x22, 0x24, 0x28, 0x30, 0x28, 0x24, 0x22, 0x00, 0x00,
369   0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3E, 0x00, 0x00,
370   0x00, 0x00, 0x00, 0x22, 0x36, 0x2A, 0x2A, 0x22, 0x22, 0x22, 0x00, 0x00,
371   0x00, 0x00, 0x00, 0x22, 0x32, 0x2A, 0x26, 0x22, 0x22, 0x22, 0x00, 0x00,
372   0x00, 0x00, 0x00, 0x3E, 0x22, 0x22, 0x22, 0x22, 0x22, 0x3E, 0x00, 0x00,
373   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00,
374   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x2A, 0x24, 0x1A, 0x00, 0x00,
375   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x28, 0x24, 0x22, 0x00, 0x00,
376   0x00, 0x00, 0x00, 0x1C, 0x22, 0x10, 0x08, 0x04, 0x22, 0x1C, 0x00, 0x00,
377   0x00, 0x00, 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
378   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
379   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00,
380   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x2A, 0x2A, 0x36, 0x22, 0x00, 0x00,
381   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00, 0x00,
382   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
383   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x3E, 0x00, 0x00,
384   0x00, 0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00,
385   0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x00, 0x00,
386   0x00, 0x00, 0x00, 0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0E, 0x00, 0x00,
387   0x00, 0x00, 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
388   0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x3E, 0x10, 0x08, 0x00, 0x00, 0x00,
389   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
390   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
391   0x00, 0x00, 0x00, 0x14, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
392   0x00, 0x00, 0x00, 0x14, 0x14, 0x36, 0x00, 0x36, 0x14, 0x14, 0x00, 0x00,
393   0x00, 0x00, 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08, 0x00, 0x00,
394   0x00, 0x00, 0x00, 0x32, 0x32, 0x04, 0x08, 0x10, 0x26, 0x26, 0x00, 0x00,
395   0x00, 0x00, 0x00, 0x10, 0x28, 0x28, 0x10, 0x2A, 0x24, 0x1A, 0x00, 0x00,
396   0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
397   0x00, 0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00,
398   0x00, 0x00, 0x00, 0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08, 0x00, 0x00,
399   0x00, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x3E, 0x1C, 0x08, 0x00, 0x00, 0x00,
400   0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x00,
401   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x10, 0x20, 0x00, 0x00,
402   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
403   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00,
404   0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
405   0x00, 0x00, 0x00, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18, 0x00, 0x00,
406   0x00, 0x00, 0x00, 0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
407   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1C, 0x20, 0x20, 0x3E, 0x00, 0x00,
408   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x0C, 0x02, 0x22, 0x1C, 0x00, 0x00,
409   0x00, 0x00, 0x00, 0x04, 0x0C, 0x14, 0x3E, 0x04, 0x04, 0x04, 0x00, 0x00,
410   0x00, 0x00, 0x00, 0x3E, 0x20, 0x3C, 0x02, 0x02, 0x22, 0x1C, 0x00, 0x00,
411   0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x1C, 0x00, 0x00,
412   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
413   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1C, 0x22, 0x22, 0x1C, 0x00, 0x00,
414   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1E, 0x02, 0x02, 0x1C, 0x00, 0x00,
415   0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
416   0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00,
417   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00,
418   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00,
419   0x00, 0x00, 0x00, 0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10, 0x00, 0x00,
420   0x00, 0x00, 0x00, 0x18, 0x24, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
421
422   /* Lower case */
423   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x12, 0x3C, 0x00, 0x00,
424   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x02, 0x1E, 0x22, 0x1E, 0x00, 0x00,
425   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x00, 0x00,
426   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x20, 0x1C, 0x00, 0x00,
427   0x00, 0x00, 0x00, 0x02, 0x02, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x00, 0x00,
428   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x3E, 0x20, 0x1C, 0x00, 0x00,
429   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00,
430   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
431   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00,
432   0x00, 0x00, 0x00, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
433   0x00, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x24, 0x18,
434   0x00, 0x00, 0x00, 0x20, 0x20, 0x24, 0x28, 0x38, 0x24, 0x22, 0x00, 0x00,
435   0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
436   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x2A, 0x2A, 0x2A, 0x2A, 0x00, 0x00,
437   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x22, 0x22, 0x22, 0x00, 0x00,
438   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
439   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x20, 0x20,
440   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x03,
441   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00,
442   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x00, 0x00,
443   0x00, 0x00, 0x00, 0x10, 0x3C, 0x10, 0x10, 0x10, 0x12, 0x0C, 0x00, 0x00,
444   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x26, 0x1A, 0x00, 0x00,
445   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x14, 0x08, 0x00, 0x00,
446   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x2A, 0x2A, 0x1C, 0x14, 0x00, 0x00,
447   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00, 0x00,
448   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
449   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x04, 0x08, 0x10, 0x3E, 0x00, 0x00,
450   0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00,
451   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00,
452   0x00, 0x00, 0x00, 0x08, 0x04, 0x04, 0x02, 0x04, 0x04, 0x08, 0x00, 0x00,
453   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x00,
454   0x00, 0x00, 0x00, 0x08, 0x04, 0x3E, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00,
455
456   /* Semigraphics 6 */
457   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
458   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
459   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
460   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
461   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
462   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
463   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
464   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
465   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
466   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
467   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
468   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
469   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
470   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
471   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
472   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
473   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
474   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
475   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
476   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
477   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
478   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
479   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
480   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
481   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
482   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
483   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
484   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
485   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
486   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
487   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
488   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
489   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
490   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
491   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
492   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
493   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
494   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
495   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
496   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
497   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
498   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
499   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
500   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
501   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
502   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
503   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
504   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
505   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
506   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
507   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
508   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
509   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
510   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
511   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
512   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
513   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
514   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
515   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
516   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
517   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
518   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
519   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
520   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
521
522   /* Block Graphics (Semigraphics 4 Graphics ) */
523   0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,
524   0x00,0x00,0x00,0x00,0x00,0x00, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
525   0x00,0x00,0x00,0x00,0x00,0x00, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
526   0x00,0x00,0x00,0x00,0x00,0x00, 0xff,0xff,0xff,0xff,0xff,0xff,
527   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0x00,0x00,0x00,0x00,0x00,0x00,
528   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
529   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
530   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0xff,0xff,0xff,0xff,0xff,0xff,
531   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0x00,0x00,0x00,0x00,0x00,0x00,
532   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
533   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
534   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0xff,0xff,0xff,0xff,0xff,0xff,
535   0xff,0xff,0xff,0xff,0xff,0xff, 0x00,0x00,0x00,0x00,0x00,0x00,
536   0xff,0xff,0xff,0xff,0xff,0xff, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
537   0xff,0xff,0xff,0xff,0xff,0xff, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
538   0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff
539};
540
541
542
543static const UINT8 ntsc_round_fontdata8x12[] =
544{
545   0x00, 0x00, 0x38, 0x44, 0x04, 0x34, 0x4C, 0x4C, 0x38, 0x00, 0x00, 0x00,
546   0x00, 0x00, 0x10, 0x28, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x00, 0x00, 0x00,
547   0x00, 0x00, 0x78, 0x24, 0x24, 0x38, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
548   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
549   0x00, 0x00, 0x78, 0x24, 0x24, 0x24, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
550   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
551   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
552   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x4C, 0x44, 0x38, 0x00, 0x00, 0x00,
553   0x00, 0x00, 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
554   0x00, 0x00, 0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
555   0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
556   0x00, 0x00, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
557   0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
558   0x00, 0x00, 0x44, 0x6C, 0x54, 0x54, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
559   0x00, 0x00, 0x44, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x44, 0x00, 0x00, 0x00,
560   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
561   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
562   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
563   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
564   0x00, 0x00, 0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
565   0x00, 0x00, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
566   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
567   0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x00, 0x00, 0x00,
568   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x54, 0x6C, 0x44, 0x00, 0x00, 0x00,
569   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00, 0x00, 0x00,
570   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
571   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7C, 0x00, 0x00, 0x00,
572   0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00, 0x00,
573   0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00,
574   0x00, 0x00, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x00,
575   0x00, 0x00, 0x10, 0x38, 0x54, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
576   0x00, 0x00, 0x00, 0x10, 0x20, 0x7C, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00,
577   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
578   0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
579   0x00, 0x00, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
580   0x00, 0x00, 0x28, 0x28, 0x7C, 0x28, 0x7C, 0x28, 0x28, 0x00, 0x00, 0x00,
581   0x00, 0x00, 0x10, 0x3C, 0x50, 0x38, 0x14, 0x78, 0x10, 0x00, 0x00, 0x00,
582   0x00, 0x00, 0x60, 0x64, 0x08, 0x10, 0x20, 0x4C, 0x0C, 0x00, 0x00, 0x00,
583   0x00, 0x00, 0x20, 0x50, 0x50, 0x20, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
584   0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
585   0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
586   0x00, 0x00, 0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
587   0x00, 0x00, 0x00, 0x10, 0x54, 0x38, 0x38, 0x54, 0x10, 0x00, 0x00, 0x00,
588   0x00, 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
589   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x40, 0x00, 0x00,
590   0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
591   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
592   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00,
593   0x00, 0x00, 0x38, 0x44, 0x4C, 0x54, 0x64, 0x44, 0x38, 0x00, 0x00, 0x00,
594   0x00, 0x00, 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
595   0x00, 0x00, 0x38, 0x44, 0x04, 0x38, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
596   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
597   0x00, 0x00, 0x08, 0x18, 0x28, 0x48, 0x7C, 0x08, 0x08, 0x00, 0x00, 0x00,
598   0x00, 0x00, 0x7C, 0x40, 0x78, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
599   0x00, 0x00, 0x38, 0x40, 0x40, 0x78, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
600   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40, 0x00, 0x00, 0x00,
601   0x00, 0x00, 0x38, 0x44, 0x44, 0x38, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
602   0x00, 0x00, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x38, 0x00, 0x00, 0x00,
603   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
604   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00,
605   0x00, 0x00, 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
606   0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00,
607   0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
608   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
609
610   /* Lower case */
611   0x00, 0x00, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
612   0x00, 0x00, 0x00, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, 0x00, 0x00,
613   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x64, 0x58, 0x00, 0x00, 0x00,
614   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
615   0x00, 0x00, 0x04, 0x04, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
616   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00, 0x00, 0x00,
617   0x00, 0x00, 0x08, 0x14, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
618   0x00, 0x00, 0x00, 0x00, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x04, 0x38, 0x00,
619   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
620   0x00, 0x00, 0x10, 0x00, 0x30, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
621   0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00,
622   0x00, 0x00, 0x40, 0x40, 0x48, 0x50, 0x60, 0x50, 0x48, 0x00, 0x00, 0x00,
623   0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
624   0x00, 0x00, 0x00, 0x00, 0x78, 0x54, 0x54, 0x54, 0x54, 0x00, 0x00, 0x00,
625   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
626   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
627   0x00, 0x00, 0x00, 0x00, 0x78, 0x44, 0x44, 0x44, 0x78, 0x40, 0x40, 0x00,
628   0x00, 0x00, 0x00, 0x00, 0x3C, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x00,
629   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
630   0x00, 0x00, 0x00, 0x00, 0x3C, 0x40, 0x38, 0x04, 0x78, 0x00, 0x00, 0x00,
631   0x00, 0x00, 0x20, 0x20, 0x70, 0x20, 0x20, 0x24, 0x18, 0x00, 0x00, 0x00,
632   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
633   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00, 0x00, 0x00,
634   0x00, 0x00, 0x00, 0x00, 0x44, 0x54, 0x54, 0x28, 0x28, 0x00, 0x00, 0x00,
635   0x00, 0x00, 0x00, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00,
636   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x38, 0x00, 0x00,
637   0x00, 0x00, 0x00, 0x00, 0x7C, 0x08, 0x10, 0x20, 0x7C, 0x00, 0x00, 0x00,
638   0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,
639   0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
640   0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00,
641   0x00, 0x00, 0x20, 0x54, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
642   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00,
643
644   /* Semigraphics 6 */
645   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
646   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
647   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
648   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
649   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
650   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
651   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
652   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
653   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
654   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
655   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
656   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
657   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
658   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
659   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
660   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
661   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
662   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
663   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
664   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
665   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
666   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
667   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
668   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
669   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
670   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
671   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
672   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
673   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
674   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
675   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
676   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
677   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
678   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
679   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
680   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
681   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
682   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
683   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
684   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
685   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
686   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
687   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
688   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
689   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
690   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
691   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
692   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
693   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
694   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
695   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
696   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
697   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
698   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
699   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
700   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
701   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
702   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
703   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
704   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
705   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
706   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
707   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
708   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
709
710   /* Block Graphics (Semigraphics 4 Graphics ) */
711   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
712   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
713   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
714   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
715   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
716   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
717   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
718   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
719   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
720   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
721   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
722   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
723   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
724   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
725   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
726   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
727};
728
729
730
731static const UINT8 ntsc_square_fontdata8x12[] =
732{
733   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1A, 0x2A, 0x2A, 0x1C, 0x00, 0x00,
734   0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x00, 0x00,
735   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x1C, 0x12, 0x12, 0x3C, 0x00, 0x00,
736   0x00, 0x00, 0x00, 0x1C, 0x22, 0x20, 0x20, 0x20, 0x22, 0x1C, 0x00, 0x00,
737   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x12, 0x12, 0x12, 0x3C, 0x00, 0x00,
738   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x38, 0x20, 0x20, 0x3E, 0x00, 0x00,
739   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x38, 0x20, 0x20, 0x20, 0x00, 0x00,
740   0x00, 0x00, 0x00, 0x1E, 0x20, 0x20, 0x26, 0x22, 0x22, 0x1E, 0x00, 0x00,
741   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x22, 0x00, 0x00,
742   0x00, 0x00, 0x00, 0x1C, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
743   0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x22, 0x22, 0x1C, 0x00, 0x00,
744   0x00, 0x00, 0x00, 0x22, 0x24, 0x28, 0x30, 0x28, 0x24, 0x22, 0x00, 0x00,
745   0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3E, 0x00, 0x00,
746   0x00, 0x00, 0x00, 0x22, 0x36, 0x2A, 0x2A, 0x22, 0x22, 0x22, 0x00, 0x00,
747   0x00, 0x00, 0x00, 0x22, 0x32, 0x2A, 0x26, 0x22, 0x22, 0x22, 0x00, 0x00,
748   0x00, 0x00, 0x00, 0x3E, 0x22, 0x22, 0x22, 0x22, 0x22, 0x3E, 0x00, 0x00,
749   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00,
750   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x2A, 0x24, 0x1A, 0x00, 0x00,
751   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x28, 0x24, 0x22, 0x00, 0x00,
752   0x00, 0x00, 0x00, 0x1C, 0x22, 0x10, 0x08, 0x04, 0x22, 0x1C, 0x00, 0x00,
753   0x00, 0x00, 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
754   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
755   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00,
756   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x2A, 0x2A, 0x36, 0x22, 0x00, 0x00,
757   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00, 0x00,
758   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
759   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x3E, 0x00, 0x00,
760   0x00, 0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00,
761   0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x00, 0x00,
762   0x00, 0x00, 0x00, 0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0E, 0x00, 0x00,
763   0x00, 0x00, 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
764   0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x3E, 0x10, 0x08, 0x00, 0x00, 0x00,
765   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
766   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
767   0x00, 0x00, 0x00, 0x14, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
768   0x00, 0x00, 0x00, 0x14, 0x14, 0x36, 0x00, 0x36, 0x14, 0x14, 0x00, 0x00,
769   0x00, 0x00, 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08, 0x00, 0x00,
770   0x00, 0x00, 0x00, 0x32, 0x32, 0x04, 0x08, 0x10, 0x26, 0x26, 0x00, 0x00,
771   0x00, 0x00, 0x00, 0x10, 0x28, 0x28, 0x10, 0x2A, 0x24, 0x1A, 0x00, 0x00,
772   0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
773   0x00, 0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00,
774   0x00, 0x00, 0x00, 0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08, 0x00, 0x00,
775   0x00, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x3E, 0x1C, 0x08, 0x00, 0x00, 0x00,
776   0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x00,
777   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x10, 0x20, 0x00, 0x00,
778   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
779   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00,
780   0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
781   0x00, 0x00, 0x00, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18, 0x00, 0x00,
782   0x00, 0x00, 0x00, 0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
783   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1C, 0x20, 0x20, 0x3E, 0x00, 0x00,
784   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x04, 0x02, 0x22, 0x1C, 0x00, 0x00,
785   0x00, 0x00, 0x00, 0x04, 0x0C, 0x14, 0x3E, 0x04, 0x04, 0x04, 0x00, 0x00,
786   0x00, 0x00, 0x00, 0x3E, 0x20, 0x3C, 0x02, 0x02, 0x22, 0x1C, 0x00, 0x00,
787   0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x1C, 0x00, 0x00,
788   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
789   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1C, 0x22, 0x22, 0x1C, 0x00, 0x00,
790   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1E, 0x02, 0x02, 0x1C, 0x00, 0x00,
791   0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
792   0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00,
793   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00,
794   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00,
795   0x00, 0x00, 0x00, 0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10, 0x00, 0x00,
796   0x00, 0x00, 0x00, 0x18, 0x24, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
797
798   /* Lower case */
799   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x12, 0x3C, 0x00, 0x00,
800   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x02, 0x1E, 0x22, 0x1E, 0x00, 0x00,
801   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x00, 0x00,
802   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x20, 0x1C, 0x00, 0x00,
803   0x00, 0x00, 0x00, 0x02, 0x02, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x00, 0x00,
804   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x3E, 0x20, 0x1C, 0x00, 0x00,
805   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00,
806   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
807   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00,
808   0x00, 0x00, 0x00, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
809   0x00, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x24, 0x18,
810   0x00, 0x00, 0x00, 0x20, 0x20, 0x24, 0x28, 0x38, 0x24, 0x22, 0x00, 0x00,
811   0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
812   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x2A, 0x2A, 0x2A, 0x2A, 0x00, 0x00,
813   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x22, 0x22, 0x22, 0x00, 0x00,
814   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
815   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x20, 0x20,
816   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x03,
817   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00,
818   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x00, 0x00,
819   0x00, 0x00, 0x00, 0x10, 0x3C, 0x10, 0x10, 0x10, 0x12, 0x0C, 0x00, 0x00,
820   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x26, 0x1A, 0x00, 0x00,
821   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x14, 0x08, 0x00, 0x00,
822   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x2A, 0x2A, 0x1C, 0x14, 0x00, 0x00,
823   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00, 0x00,
824   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
825   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x04, 0x08, 0x10, 0x3E, 0x00, 0x00,
826   0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00,
827   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00,
828   0x00, 0x00, 0x00, 0x08, 0x04, 0x04, 0x02, 0x04, 0x04, 0x08, 0x00, 0x00,
829   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x00,
830   0x00, 0x00, 0x00, 0x08, 0x04, 0x3E, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00,
831
832   /* Semigraphics 6 */
833   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
834   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
835   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
836   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
837   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
838   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
839   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
840   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
841   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
842   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
843   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
844   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
845   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
846   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
847   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
848   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
849   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
850   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
851   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
852   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
853   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
854   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
855   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
856   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
857   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
858   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
859   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
860   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
861   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
862   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
863   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
864   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
865   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
866   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
867   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
868   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
869   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
870   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
871   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
872   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
873   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
874   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
875   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
876   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
877   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
878   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
879   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
880   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
881   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
882   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
883   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
884   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
885   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
886   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
887   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
888   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
889   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
890   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
891   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
892   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
893   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
894   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
895   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
896   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
897
898   /* Block Graphics (Semigraphics 4 Graphics ) */
899   0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,
900   0x00,0x00,0x00,0x00,0x00,0x00, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
901   0x00,0x00,0x00,0x00,0x00,0x00, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
902   0x00,0x00,0x00,0x00,0x00,0x00, 0xff,0xff,0xff,0xff,0xff,0xff,
903   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0x00,0x00,0x00,0x00,0x00,0x00,
904   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
905   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
906   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0xff,0xff,0xff,0xff,0xff,0xff,
907   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0x00,0x00,0x00,0x00,0x00,0x00,
908   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
909   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
910   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0xff,0xff,0xff,0xff,0xff,0xff,
911   0xff,0xff,0xff,0xff,0xff,0xff, 0x00,0x00,0x00,0x00,0x00,0x00,
912   0xff,0xff,0xff,0xff,0xff,0xff, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
913   0xff,0xff,0xff,0xff,0xff,0xff, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
914   0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff
915};
916
917
918
919enum
920{
921   GREEN, YELLOW, BLUE, RED,      /*  0 -  3 */
922   BUFF, CYAN, MAGENTA, ORANGE,   /*  4 -  7 */
923
924   BLACK,                     /*  8 */
925
926   DKGREEN = 12, LTGREEN = 13,      /* 12 - 13 */
927   DKORANGE = 14, LTORANGE = 15,   /* 14 - 15 */
928};
929
930
931
932
933#define ATTOTIME_STRING_PRECISION   9
934
935#define M6847_RGB(r,g,b)   ((r << 16) | (g << 8) | (b << 0))
936
937
938static const UINT32 palette[] =
939{
940   M6847_RGB(0x00, 0xff, 0x00),   /* GREEN */
941   M6847_RGB(0xff, 0xff, 0x00),   /* YELLOW */
942   M6847_RGB(0x00, 0x00, 0xff),   /* BLUE */
943   M6847_RGB(0xff, 0x00, 0x00),   /* RED */
944   M6847_RGB(0xff, 0xff, 0xff),   /* BUFF */
945   M6847_RGB(0x00, 0xff, 0xff),   /* CYAN */
946   M6847_RGB(0xff, 0x00, 0xff),   /* MAGENTA */
947   M6847_RGB(0xff, 0x80, 0x00),   /* ORANGE */
948
949   M6847_RGB(0x00, 0x00, 0x00),   /* BLACK */
950   M6847_RGB(0x00, 0xff, 0x00),   /* GREEN */
951   M6847_RGB(0x00, 0x00, 0x00),   /* BLACK */
952   M6847_RGB(0xff, 0xff, 0xff),   /* BUFF */
953
954   M6847_RGB(0x00, 0x40, 0x00),   /* ALPHANUMERIC DARK GREEN */
955   M6847_RGB(0x00, 0xff, 0x00),   /* ALPHANUMERIC BRIGHT GREEN */
956   M6847_RGB(0x40, 0x10, 0x00),   /* ALPHANUMERIC DARK ORANGE */
957   M6847_RGB(0xff, 0xc4, 0x18)      /* ALPHANUMERIC BRIGHT ORANGE */
958};
959
960
961
962#define FACTOR_SCANLINES_PER_FRAME   2
963#define FACTOR_CLOCKS_PER_SCANLINE   2
964
965#define GROSS_FACTOR   (FACTOR_SCANLINES_PER_FRAME * FACTOR_CLOCKS_PER_SCANLINE)
966
967static const m6847_variant variants[] =
968{
969   {
970      /* M6847_VERSION_ORIGINAL_NTSC */
971      ntsc_square_fontdata8x12,
972      FALSE, 0,
973      60, 262, 227.5,            /* frames, scanlines, clocks per scanline */
974      13, 25, 192, 26, 6,
975      13+25+192               /* field sync period */
976   },
977   {
978      /* M6847_VERSION_ORIGINAL_PAL */
979      pal_square_fontdata8x12,
980      FALSE, 0,
981      50, 262, 227.5,            /* frames, scanlines, clocks per scanline */
982      13, 25, 192, 26, 6,
983      13+25+192               /* field sync period */
984   },
985   {
986      /* M6847_VERSION_M6847Y_NTSC */
987      ntsc_square_fontdata8x12,
988      FALSE, 0,
989      60, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
990      13.5, 25, 192, 26, 6,
991      13+25+192               /* field sync period */
992   },
993   {
994      /* M6847_VERSION_M6847Y_PAL */
995      pal_square_fontdata8x12,
996      FALSE, 0,
997      50, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
998      13.5, 25, 192, 26, 6,
999      13+25+192               /* field sync period */
1000   },
1001   {
1002      /* M6847_VERSION_M6847T1_NTSC */
1003      ntsc_round_fontdata8x12,
1004      TRUE, 0,
1005      60, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
1006      13.5, 25, 192, 26, 6,
1007      13+25+192               /* field sync period */
1008   },
1009   {
1010      /* M6847_VERSION_M6847T1_PAL */
1011      pal_round_fontdata8x12,
1012      TRUE, 0,
1013      50, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
1014      13.5, 25, 192, 26, 6,
1015      13+25+192               /* field sync period */
1016   },
1017   {
1018      /* M6847_VERSION_GIME_NTSC */
1019      ntsc_round_fontdata8x12,
1020      TRUE, 1,
1021      60, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
1022      13.5, 25, 192, 26, 6,
1023      262.5 - 3               /* field sync period */
1024   },
1025   {
1026      /* M6847_VERSION_GIME_PAL */
1027      pal_round_fontdata8x12,
1028      TRUE, 1,
1029      50, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
1030      13.5, 25, 192, 26, 6,
1031      262.5 - 3               /* field sync period */
1032   }
1033};
1034
1035
1036
1037/*************************************
1038 *
1039 *  Utilities
1040 *
1041 *************************************/
1042
1043static UINT32 color(int c)
1044{
1045   return m6847->palette[c];
1046}
1047
1048
1049
1050static int attr_index_from_attribute(UINT8 attr)
1051{
1052   int result;
1053
1054   result = ((attr & (M6847_AG | M6847_AS | M6847_INTEXT | M6847_INV | M6847_CSS)) >> 3)
1055      | ((attr & (M6847_GM1 | M6847_GM0)) << 5);
1056
1057   /* sanity check */
1058   assert(result < ARRAY_LENGTH(m6847->fontdata));
1059   return result;
1060}
1061
1062
1063
1064static UINT8 attribute_from_attr_index(int attr_index)
1065{
1066   /* sanity check */
1067   assert(attr_index >= 0);
1068   assert(attr_index < ARRAY_LENGTH(m6847->fontdata));
1069
1070   return (UINT8) ((attr_index & 0x1F) << 3)
1071      | ((attr_index & 0x60) >> 5);
1072}
1073
1074
1075
1076/*************************************
1077 *
1078 *  Video modes
1079 *
1080 *************************************/
1081
1082static void graphics_color_64(UINT32 *RESTRICT line, const m6847_pixel *RESTRICT video_data)
1083{
1084   int x;
1085   UINT8 byte, attr;
1086
1087   for (x = 0; x < 16; x++)
1088   {
1089      byte = video_data[x].data;
1090      attr = video_data[x].attr;
1091
1092      line[ 0] = line[ 1] = line[ 2] = line[ 3] = color(((byte >> 6) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1093      line[ 4] = line[ 5] = line[ 6] = line[ 7] = color(((byte >> 4) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1094      line[ 8] = line[ 9] = line[10] = line[11] = color(((byte >> 2) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1095      line[12] = line[13] = line[14] = line[15] = color(((byte >> 0) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1096      line += 16;
1097   }
1098}
1099
1100
1101
1102static void graphics_color_128(UINT32 *RESTRICT line, const m6847_pixel *RESTRICT video_data)
1103{
1104   int x;
1105   UINT8 byte, attr;
1106
1107   for (x = 0; x < 32; x++)
1108   {
1109      byte = video_data[x].data;
1110      attr = video_data[x].attr;
1111
1112      line[ 0] = line[ 1] = color(((byte >> 6) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1113      line[ 2] = line[ 3] = color(((byte >> 4) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1114      line[ 4] = line[ 5] = color(((byte >> 2) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1115      line[ 6] = line[ 7] = color(((byte >> 0) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1116      line += 8;
1117   }
1118}
1119
1120
1121
1122static void graphics_bw_128(UINT32 *RESTRICT line, const m6847_pixel *RESTRICT video_data)
1123{
1124   int x;
1125   UINT8 byte, attr;
1126   UINT32 bg, fg;
1127
1128   for (x = 0; x < 16; x++)
1129   {
1130      byte = video_data[x].data;
1131      attr = video_data[x].attr;
1132
1133      bg = color(attr & M6847_CSS ? 10 :  8);
1134      fg = color(attr & M6847_CSS ? 11 :  9);
1135
1136      line[ 0] = line[ 1] = ((byte >> 7) & 0x01) ? fg : bg;
1137      line[ 2] = line[ 3] = ((byte >> 6) & 0x01) ? fg : bg;
1138      line[ 4] = line[ 5] = ((byte >> 5) & 0x01) ? fg : bg;
1139      line[ 6] = line[ 7] = ((byte >> 4) & 0x01) ? fg : bg;
1140      line[ 8] = line[ 9] = ((byte >> 3) & 0x01) ? fg : bg;
1141      line[10] = line[11] = ((byte >> 2) & 0x01) ? fg : bg;
1142      line[12] = line[13] = ((byte >> 1) & 0x01) ? fg : bg;
1143      line[14] = line[15] = ((byte >> 0) & 0x01) ? fg : bg;
1144      line += 16;
1145   }
1146}
1147
1148
1149
1150static void graphics_bw_256(UINT32 *RESTRICT line, const m6847_pixel *RESTRICT video_data)
1151{
1152   int x;
1153   UINT8 byte, attr;
1154   UINT32 bg, fg;
1155
1156   for (x = 0; x < 32; x++)
1157   {
1158      byte = video_data[x].data;
1159      attr = video_data[x].attr;
1160
1161      bg = color(attr & M6847_CSS ? 10 :  8);
1162      fg = color(attr & M6847_CSS ? 11 :  9);
1163
1164      line[0] = ((byte >> 7) & 0x01) ? fg : bg;
1165      line[1] = ((byte >> 6) & 0x01) ? fg : bg;
1166      line[2] = ((byte >> 5) & 0x01) ? fg : bg;
1167      line[3] = ((byte >> 4) & 0x01) ? fg : bg;
1168      line[4] = ((byte >> 3) & 0x01) ? fg : bg;
1169      line[5] = ((byte >> 2) & 0x01) ? fg : bg;
1170      line[6] = ((byte >> 1) & 0x01) ? fg : bg;
1171      line[7] = ((byte >> 0) & 0x01) ? fg : bg;
1172      line += 8;
1173   }
1174}
1175
1176
1177
1178static void (*const graphics_modes[8])(UINT32 *line, const m6847_pixel *video_data) =
1179{
1180   graphics_color_64,   graphics_bw_128,
1181   graphics_color_128,   graphics_bw_128,
1182   graphics_color_128,   graphics_bw_128,
1183   graphics_color_128,   graphics_bw_256
1184};
1185
1186
1187
1188static void text_mode(running_machine &machine, int scanline, UINT32 *RESTRICT line, const m6847_pixel *RESTRICT video_data)
1189{
1190   int x;
1191   UINT8 byte, attr;
1192   int attr_index;
1193   UINT32 bg_color, fg_color;
1194   UINT8 char_data;
1195
1196   for (x = 0; x < 32; x++)
1197   {
1198      byte = video_data[x].data;
1199      attr = video_data[x].attr;
1200
1201      attr_index = attr_index_from_attribute(attr);
1202
1203      bg_color = color(m6847->colordata[attr_index][byte / 16][0]);
1204      fg_color = color(m6847->colordata[attr_index][byte / 16][1]);
1205
1206      if( (!m6847->has_lowercase) && (attr & M6847_INTEXT) && !(attr & M6847_AS)) {
1207         if (m6847->get_char_rom) {
1208            char_data = m6847->get_char_rom(machine,byte,scanline % 12);
1209         } else {
1210            char_data = 0xff;
1211         }
1212      } else {
1213         if (m6847->get_char_rom)
1214            char_data = m6847->get_char_rom(machine,byte,scanline % 12);
1215         else
1216            char_data = m6847->fontdata[attr_index][byte][scanline % 12];
1217      }
1218
1219      line[x*8+0] = (char_data & 0x80) ? fg_color : bg_color;
1220      line[x*8+1] = (char_data & 0x40) ? fg_color : bg_color;
1221      line[x*8+2] = (char_data & 0x20) ? fg_color : bg_color;
1222      line[x*8+3] = (char_data & 0x10) ? fg_color : bg_color;
1223      line[x*8+4] = (char_data & 0x08) ? fg_color : bg_color;
1224      line[x*8+5] = (char_data & 0x04) ? fg_color : bg_color;
1225      line[x*8+6] = (char_data & 0x02) ? fg_color : bg_color;
1226      line[x*8+7] = (char_data & 0x01) ? fg_color : bg_color;
1227   }
1228}
1229
1230
1231
1232static void render_scanline(running_machine &machine, bitmap_t *bitmap, int scanline)
1233{
1234   UINT32 border_color;
1235   UINT32 *line;
1236   UINT8 attrs;
1237   int mode, x;
1238   const m6847_pixel *video_data;
1239
1240   /* get the scanline */
1241   line = BITMAP_ADDR32(bitmap, scanline, 0);
1242
1243   /* choose the border color */
1244   border_color = m6847->border[scanline];
1245   attrs = m6847->attrs[scanline];
1246
1247   /* is this a border scanline? */
1248   scanline -= m6847->top_border_scanlines;
1249   if ((scanline >= 0) && (scanline < m6847->display_scanlines))
1250   {
1251      video_data = m6847->screendata[scanline];
1252
1253      /* left border */
1254      for (x = 0; x < 32; x++)
1255         line[x] = border_color;
1256
1257      if (attrs & M6847_AG)
1258      {
1259         /* graphics */
1260         mode = attrs & (M6847_GM2|M6847_GM1|M6847_GM0);
1261         graphics_modes[mode](line + 32, video_data);
1262      }
1263      else
1264      {
1265         /* text/semigraphics */
1266         text_mode(machine, scanline, line + 32, video_data);
1267      }
1268
1269      /* right border */
1270      for (x = 288; x < 320; x++)
1271         line[x] = border_color;
1272
1273      /* special case for artifacting */
1274      if ((attrs & (M6847_AG|M6847_GM2|M6847_GM1|M6847_GM0))
1275         == (M6847_AG|M6847_GM2|M6847_GM1|M6847_GM0))
1276      {
1277         apply_artifacts(machine, line + 32);
1278      }
1279   }
1280   else
1281   {
1282      /* we are drawing a border */
1283      for (x = 0; x < bitmap->width; x++)
1284         line[x] = border_color;
1285   }
1286}
1287
1288
1289
1290static void set_dirty(void)
1291{
1292   m6847->dirty = TRUE;
1293}
1294
1295
1296
1297/*************************************
1298 *
1299 *  Artifacting hack; should be in core
1300 *
1301 *************************************/
1302
1303static UINT32 mix_color(double factor, UINT8 c0, UINT8 c1)
1304{
1305   return (UINT32) (UINT8) ((c0 * (1.0 - factor)) + (c1 * (0.0 + factor)) + 0.5);
1306}
1307
1308
1309
1310static void apply_artifacts(running_machine &machine, UINT32 *line)
1311{
1312   /* Boy this code sucks; this code was adapted from the old M6847
1313     * artifacting implmentation.  The only reason that it didn't look as
1314     * horrible was because the code around it sucked as well.  Now that I
1315     * have cleaned everything up, the ugliness is much more prominent.
1316     *
1317     * Hopefully we will have a generic artifacting algorithm that plugs into
1318     * the MESS/MAME core directly so we can chuck this hack */
1319   static const double artifact_colors[14*3] =
1320   {
1321      0.157, 0.000, 0.157, /* [ 1] - dk purple   (reverse  2) */
1322      0.000, 0.157, 0.000, /* [ 2] - dk green    (reverse  1) */
1323      1.000, 0.824, 1.000, /* [ 3] - lt purple   (reverse  4) */
1324      0.824, 1.000, 0.824, /* [ 4] - lt green    (reverse  3) */
1325      0.706, 0.236, 0.118, /* [ 5] - dk blue     (reverse  6) */
1326      0.000, 0.197, 0.471, /* [ 6] - dk red      (reverse  5) */
1327      1.000, 0.550, 0.393, /* [ 7] - lt blue     (reverse  8) */
1328      0.275, 0.785, 1.000, /* [ 8] - lt red      (reverse  7) */
1329      0.000, 0.500, 1.000, /* [ 9] - red         (reverse 10) */
1330      1.000, 0.500, 0.000, /* [10] - blue        (reverse  9) */
1331      1.000, 0.942, 0.785, /* [11] - cyan        (reverse 12) */
1332      0.393, 0.942, 1.000, /* [12] - yellow      (reverse 11) */
1333      0.236, 0.000, 0.000, /* [13] - black-blue  (reverse 14) */
1334      0.000, 0.000, 0.236  /* [14] - black-red   (reverse 13) */
1335   };
1336
1337   static const UINT8 artifactcorrection[128] =
1338   {
1339      0,  0,       0,    0,       0,  6,       0,    2,
1340      5,  7,       5,    7,       1,  3,       1, 11,
1341      8,  6,       8, 14,       8,  9,       8,    9,
1342      4,  4,       4, 15,      12, 12,      12, 15,
1343
1344      5, 13,       5, 13,      13,  0,      13,    2,
1345      10, 10,      10, 10,      10, 15,      10, 11,
1346      3,  1,       3,    1,      15,  9,      15,    9,
1347      11, 11,      11, 11,      15, 15,      15, 15,
1348
1349      14,  0,      14,    0,      14,  6,      14,    2,
1350      0,  7,       0,    7,       1,  3,       1, 11,
1351      9,  6,       9, 14,       9,  9,       9,    9,
1352      15,  4,      15, 15,      12, 12,      12, 15,
1353
1354      2, 13,       2, 13,       2,  0,       2,    2,
1355      10, 10,      10, 10,      10, 15,      10, 11,
1356      12,  1,      12,    1,      12,  9,      12,    9,
1357      15, 11,      15, 11,      15, 15,      15, 15
1358   };
1359
1360   UINT32 artifacting, c0, c1;
1361   UINT32 colors[16];
1362   const double *factors;
1363   UINT8 val;
1364   UINT32 new_line[256];
1365   int i;
1366
1367   /* are we artifacting? */
1368   artifacting = input_port_read_safe(machine, "artifacting", 0x00) & 0x03;
1369   if (artifacting == 0x00)
1370      return;
1371   artifacting &= 0x01;
1372
1373   /* determine the base artifact colors */
1374   c1 = line[-1];
1375   for (i = 0; i < 256; i++)
1376   {
1377      if (line[i] != c1)
1378         break;
1379   }
1380   if (i >= 256)
1381      return;   /* if everything is the same color as the border, no need for anything */
1382   c0 = line[i];
1383
1384   /* do we need to update our artifact colors table? */
1385   if ((artifacting != m6847->saved_artifacting) || (c0 != m6847->saved_c0) || (c1 != m6847->saved_c1))
1386   {
1387      m6847->saved_artifacting = artifacting;
1388      m6847->saved_c0 = colors[0] = c0;
1389      m6847->saved_c1 = colors[15] = c1;
1390
1391      /* mix the other colors */
1392      for (i = 1; i <= 14; i++)
1393      {
1394         factors = &artifact_colors[((i - 1) ^ artifacting) * 3];
1395
1396         colors[i] =   (mix_color(factors[0], c0 >> 16, c1 >> 16) << 16)
1397               |   (mix_color(factors[1], c0 >>  8, c1 >>  8) <<  8)
1398               |   (mix_color(factors[2], c0 >>  0, c1 >>  0) <<  0);
1399      }
1400      for (i = 0; i < 128; i++)
1401         m6847->expanded_colors[i] = colors[artifactcorrection[i]];
1402   }
1403
1404   /* artifact the line */
1405   for (i = 0; i < 256; i += 2)
1406   {
1407      val =   ((line[i - 2] == c1) ? 0x20 : 0x00)
1408         |   ((line[i - 1] == c1) ? 0x10 : 0x00)
1409         |   ((line[i + 0] == c1) ? 0x08 : 0x00)
1410         |   ((line[i + 1] == c1) ? 0x04 : 0x00)
1411         |   ((line[i + 2] == c1) ? 0x02 : 0x00)
1412         |   ((line[i + 3] == c1) ? 0x01 : 0x00);
1413
1414      new_line[i + 0] = m6847->expanded_colors[val * 2 + 0];
1415      new_line[i + 1] = m6847->expanded_colors[val * 2 + 1];
1416   }
1417
1418   /* and copy the results back */
1419   memcpy(line, new_line, sizeof(*line) * 256);
1420}
1421
1422
1423
1424static INPUT_CHANGED( artifacting_changed )
1425{
1426   set_dirty();
1427}
1428
1429
1430
1431INPUT_PORTS_START( coco6847_artifacting )
1432   PORT_START("artifacting")
1433   PORT_CONFNAME( 0x03, 0x01, "Artifacting" ) PORT_CHANGED(artifacting_changed, NULL)
1434   PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
1435   PORT_CONFSETTING(    0x01, DEF_STR( Standard ) )
1436   PORT_CONFSETTING(    0x02, DEF_STR( Reverse ) )
1437INPUT_PORTS_END
1438
1439
1440
1441/*************************************
1442 *
1443 *  Scanline operations
1444 *
1445 *************************************/
1446
1447static int get_scanline(void)
1448{
1449   int result;
1450   attotime duration;
1451
1452   /* get the time since last field sync */
1453   duration = m6847->hs_rise_timer->start() - m6847->fs_rise_timer->start();
1454   assert_always(duration.seconds == 0, "get_scanline(): duration exceeds one second");
1455
1456   if (duration.attoseconds < m6847->vblank_period)
1457   {
1458      result = -1;   /* vblank */
1459   }
1460   else
1461   {
1462      result = (duration.attoseconds - m6847->vblank_period)
1463         / m6847->scanline_period;
1464   }
1465   return result;
1466}
1467
1468
1469static int get_beamx(void)
1470{
1471   attotime scanline_time;
1472   int result;
1473
1474   scanline_time = m6847->hs_rise_timer->elapsed();
1475   if (scanline_time.seconds != 0)
1476      return 0;
1477   assert(scanline_time.as_attoseconds() < m6847->scanline_period);
1478
1479   if (scanline_time.as_attoseconds() < (m6847->clock_period * 42))
1480   {
1481      /* hsync */
1482      result = 0;
1483   }
1484   else if (scanline_time.as_attoseconds() < (m6847->clock_period * 95 / 2))
1485   {
1486      /* left border */
1487      result = 0;
1488   }
1489   else if (scanline_time.as_attoseconds() < (m6847->clock_period * 351 / 2))
1490   {
1491      /* body */
1492      result = (scanline_time.as_attoseconds() - (m6847->clock_period * 95 / 2))
1493         / m6847->clock_period * 2;
1494   }
1495   else
1496   {
1497      /* right border */
1498      result = 256;
1499   }
1500   return result;
1501}
1502
1503
1504INLINE void prepare_scanline(running_machine &machine, int xpos)
1505{
1506   UINT8 attrs, data, attr;
1507   int scanline;
1508   int i, border_color;
1509   int dirty;
1510   const UINT8 *RESTRICT video_ram;
1511   m6847_pixel *scanline_data;
1512
1513   scanline = get_scanline();
1514
1515   if (LOG_PREPARE)
1516      logerror("m6847_prepare_scanline(): scanline=%d xpos=%d\n", scanline, xpos);
1517
1518   if ((scanline >= 0) && (scanline < (m6847->top_border_scanlines
1519      + m6847->display_scanlines + m6847->bottom_border_scanlines)))
1520   {
1521      if (m6847->using_custom)
1522      {
1523         m6847->custom_prepare_scanline(machine, scanline);
1524      }
1525      else
1526      {
1527         /* has the border color changed? */
1528         attrs = (*m6847->get_attributes)(machine, 0, 0, 0);
1529         if (attrs != m6847->attrs[scanline])
1530         {
1531            m6847->dirty = TRUE;
1532            m6847->attrs[scanline] = attrs;
1533
1534            /* choose the border color */
1535            if (attrs & M6847_AG)
1536               border_color = (attrs & M6847_CSS) ? BUFF : GREEN;
1537            else if (m6847->has_lowercase && (attrs & M6847_GM2))
1538               border_color = (attrs & M6847_CSS) ? LTORANGE : LTGREEN;
1539            else
1540               border_color = BLACK;
1541
1542            /* need to use palette table directly; border colors are constant */
1543            m6847->border[scanline] = m6847->palette[border_color];
1544         }
1545
1546         /* is this a display scanline? */
1547         scanline -= m6847->top_border_scanlines;
1548         if ((scanline >= 0) && (scanline < m6847->display_scanlines))
1549         {
1550            video_ram = m6847->get_video_ram(machine,scanline);
1551            dirty = m6847->dirty;
1552            scanline_data = m6847->screendata[scanline];
1553
1554            for (i = xpos; i < 32; i++)
1555            {
1556               data = video_ram[i];
1557               attr = (*m6847->get_attributes)(machine, data, scanline, i);
1558
1559               if ((data != scanline_data[i].data)   || (attr != scanline_data[i].attr))
1560               {
1561                  dirty = TRUE;
1562                  scanline_data[i].data = data;
1563                  scanline_data[i].attr = attr;
1564               }
1565            }
1566            m6847->dirty = dirty;
1567         }
1568      }
1569   }
1570}
1571
1572
1573
1574void coco6847_video_changed(void)
1575{
1576   /* NPW 2-May-2006 - Commenting this out until we properly fix bug #878 */
1577   /* prepare_scanline(get_beamx() / 8); */
1578}
1579
1580
1581
1582/*************************************
1583 *
1584 *  Sync callbacks
1585 *
1586 *************************************/
1587
1588int m6847_get_horizontal_sync(running_machine &machine)
1589{
1590   attotime fire_time = m6847->hs_fall_timer->expire();
1591   return fire_time > machine.time();
1592}
1593
1594
1595
1596static void set_horizontal_sync(running_machine &machine)
1597{
1598   attotime fire_time = m6847->hs_fall_timer->expire();
1599   int horizontal_sync = fire_time >  machine.time();
1600   if (m6847->horizontal_sync_callback)
1601      m6847->horizontal_sync_callback(machine, !horizontal_sync);
1602}
1603
1604
1605
1606int m6847_get_field_sync(running_machine &machine)
1607{
1608   attotime fire_time = m6847->fs_fall_timer->expire();
1609   return fire_time > machine.time();
1610}
1611
1612
1613
1614static void set_field_sync(running_machine &machine)
1615{
1616   attotime fire_time = m6847->fs_fall_timer->expire();
1617   int field_sync = fire_time > machine.time();
1618   if (m6847->field_sync_callback)
1619      m6847->field_sync_callback(machine,field_sync);
1620}
1621
1622
1623
1624/*************************************
1625 *
1626 *  Field sync/Horizontal sync timers
1627 *
1628 *************************************/
1629
1630static TIMER_CALLBACK(hs_fall)
1631{
1632   if (LOG_HS)
1633      logerror("hs_fall(): time=%s\n", machine.time().as_string(ATTOTIME_STRING_PRECISION));
1634
1635   set_horizontal_sync(machine);
1636}
1637
1638static TIMER_CALLBACK(hs_rise)
1639{
1640   if (LOG_HS)
1641      logerror("hs_rise(): time=%s\n", machine.time().as_string(ATTOTIME_STRING_PRECISION));
1642
1643   m6847->hs_rise_timer->adjust(
1644      attotime(0, m6847->scanline_period), 0);
1645   m6847->hs_fall_timer->adjust(
1646      attotime(0, m6847->horizontal_sync_period), 0);
1647
1648   set_horizontal_sync(machine);
1649   prepare_scanline(machine,0);
1650}
1651
1652static TIMER_CALLBACK(fs_fall)
1653{
1654   if (LOG_FS)
1655      logerror("fs_fall(): time=%s scanline=%d\n", machine.time().as_string(ATTOTIME_STRING_PRECISION), get_scanline());
1656
1657   set_field_sync(machine);
1658}
1659
1660static TIMER_CALLBACK(fs_rise)
1661{
1662   if (LOG_FS)
1663      logerror("fs_rise(): time=%s scanline=%d\n", machine.time().as_string(ATTOTIME_STRING_PRECISION), get_scanline());
1664
1665   /* adjust field sync falling edge timer */
1666   m6847->fs_fall_timer->adjust(
1667      attotime(0, m6847->field_sync_period), 0);
1668
1669   /* adjust horizontal sync rising timer */
1670   m6847->hs_rise_timer->adjust(attotime::zero);
1671
1672   /* this is a hook for the CoCo 3 code to extend this stuff */
1673   if (m6847->new_frame_callback)
1674      m6847->using_custom = !m6847->new_frame_callback(machine);
1675
1676   set_field_sync(machine);
1677}
1678
1679
1680
1681/*************************************
1682 *
1683 *  Debugging
1684 *
1685 *************************************/
1686
1687
1688static void execute_m6847_dumpscanline(running_machine &machine, int ref, int params, const char **param)
1689{
1690   int i;
1691   int beamx = get_beamx() / 8;
1692   int scanline = get_scanline();
1693   const m6847_pixel *pixel = m6847->screendata[scanline];
1694
1695   for (i = 0; i < beamx; i++)
1696   {
1697      debug_console_printf(machine, "[%02d]: 0x%02X (", i, pixel[i].data);
1698
1699      if (pixel[i].attr & M6847_AG)      debug_console_printf(machine, " AG");
1700      if (pixel[i].attr & M6847_AS)      debug_console_printf(machine, " AS");
1701      if (pixel[i].attr & M6847_INTEXT)   debug_console_printf(machine, " INTEXT");
1702      if (pixel[i].attr & M6847_INV)      debug_console_printf(machine, " INV");
1703      if (pixel[i].attr & M6847_CSS)      debug_console_printf(machine, " CSS");
1704      if (pixel[i].attr & M6847_GM2)      debug_console_printf(machine, " GM2");
1705      if (pixel[i].attr & M6847_GM1)      debug_console_printf(machine, " GM1");
1706      if (pixel[i].attr & M6847_GM0)      debug_console_printf(machine, " GM0");
1707
1708      debug_console_printf(machine, " )\n");
1709   }
1710}
1711
1712
1713
1714
1715/*************************************
1716 *
1717 *  Initialization
1718 *
1719 *************************************/
1720
1721static const UINT8 *find_char(const m6847_variant *v,
1722   UINT8 byte, UINT8 attr, int *fg, int *bg)
1723{
1724   int ch;
1725   size_t offset = 0;
1726
1727   if (attr & M6847_AS)
1728   {
1729      /* semigraphics */
1730      *bg = BLACK;
1731
1732      if (!v->has_lowercase && (attr & M6847_INTEXT))
1733      {
1734         /* semigraphics 6 */
1735         ch = (byte & 0x3F) + 0x60;
1736         *fg = ((byte >> 6) & 0x03) + ((attr & M6847_CSS) ? BUFF : GREEN);
1737      }
1738      else
1739      {
1740         /* semigraphics 4 */
1741         ch = (byte & 0x0F) + 0xA0;
1742         *fg = ((byte >> 4) & 0x07) + GREEN;
1743      }
1744   }
1745   else
1746   {
1747      /* text */
1748      ch = (byte & 0x3F) + 0x00;
1749
1750      if (v->has_lowercase)
1751      {
1752         if ((ch < 0x20) && (attr & M6847_GM0) && !(attr & M6847_INV))
1753         {
1754            /* this is a lowercase character */
1755            attr |= M6847_INV;
1756            ch += 0x40;
1757         }
1758
1759         if ((ch > 0x20) && (attr & M6847_GM0) && !(attr & M6847_INV)) {
1760            ch += 0x20;
1761         }
1762
1763         if (attr & M6847_GM1)
1764            attr ^= M6847_INV;
1765
1766      }
1767
1768      if (attr & M6847_INV)
1769      {
1770         /* dark foreground, light background */
1771         *fg = (attr & M6847_CSS) ? DKORANGE : DKGREEN;
1772         *bg = (attr & M6847_CSS) ? LTORANGE : LTGREEN;
1773      }
1774      else
1775      {
1776         /* light foreground, dark background */
1777         *fg = (attr & M6847_CSS) ? LTORANGE : LTGREEN;
1778         *bg = (attr & M6847_CSS) ? DKORANGE : DKGREEN;
1779      }
1780
1781      offset = v->text_offset;
1782   }
1783
1784   return &v->fontdata[ch * 12] + offset;
1785}
1786
1787
1788
1789static void build_fontdata(const m6847_variant *v)
1790{
1791   int attr_index, row;
1792   int fg, bg;
1793   int byte;
1794   const UINT8 *char_data;
1795
1796   for (attr_index = 0; attr_index < ARRAY_LENGTH(m6847->fontdata); attr_index++)
1797   {
1798      UINT8 attr = attribute_from_attr_index(attr_index);
1799
1800      for (byte = 0; byte < 256; byte++)
1801      {
1802         char_data = find_char(v, byte, attr, &fg, &bg);
1803
1804         /* specify colors */
1805         m6847->colordata[attr_index][byte / 16][0] = bg;
1806         m6847->colordata[attr_index][byte / 16][1] = fg;
1807
1808         for (row = 0; row < 12; row++)
1809         {
1810            m6847->fontdata[attr_index][byte][row] = char_data[row];
1811         }
1812      }
1813   }
1814}
1815
1816
1817
1818static void m6847_postload(running_machine *machine)
1819{
1820   set_field_sync(*machine);
1821   set_horizontal_sync(*machine);
1822   set_dirty();
1823}
1824
1825
1826
1827void m6847_init(running_machine &machine, const m6847_config *cfg)
1828{
1829   const m6847_variant *v;
1830   UINT32 frequency;
1831   attoseconds_t period, frame_period, cpu0_clock_period = 0;
1832   double total_scanlines;
1833
1834   /* identify proper M6847 variant */
1835   assert(cfg->type < ARRAY_LENGTH(variants));
1836   v = &variants[cfg->type];
1837
1838   /* allocate instance */
1839   m6847 = auto_alloc_clear(machine, m6847_vdg);
1840   set_dirty();
1841
1842   /* copy configuration */
1843   m6847->get_attributes = cfg->get_attributes;
1844   m6847->get_video_ram = cfg->get_video_ram;
1845   m6847->horizontal_sync_callback = cfg->horizontal_sync_callback;
1846   m6847->field_sync_callback = cfg->field_sync_callback;
1847   m6847->new_frame_callback = cfg->new_frame_callback;
1848   m6847->custom_prepare_scanline = cfg->custom_prepare_scanline;
1849   m6847->has_lowercase = v->has_lowercase;
1850   m6847->get_char_rom = cfg->get_char_rom;
1851
1852   /* assert our assumptions */
1853   assert((v->scanlines_per_frame * FACTOR_SCANLINES_PER_FRAME)
1854      == (UINT32) (v->scanlines_per_frame * FACTOR_SCANLINES_PER_FRAME));
1855   assert((v->clocks_per_scanline * FACTOR_CLOCKS_PER_SCANLINE)
1856      == (UINT32) (v->clocks_per_scanline * FACTOR_CLOCKS_PER_SCANLINE));
1857   assert((v->scanlines_per_frame * v->clocks_per_scanline * GROSS_FACTOR)
1858      == (UINT32) (v->scanlines_per_frame * v->clocks_per_scanline * GROSS_FACTOR));
1859
1860   /* choose palette */
1861   if (cfg->custom_palette)
1862   {
1863      m6847->has_custom_palette = 1;
1864      m6847->palette = cfg->custom_palette;
1865   }
1866   else
1867   {
1868      m6847->palette = palette;
1869   }
1870
1871   /* allocate timers */
1872   m6847->fs_rise_timer = machine.scheduler().timer_alloc(FUNC(fs_rise));
1873   m6847->fs_fall_timer = machine.scheduler().timer_alloc(FUNC(fs_fall));
1874   m6847->hs_rise_timer = machine.scheduler().timer_alloc(FUNC(hs_rise));
1875   m6847->hs_fall_timer = machine.scheduler().timer_alloc(FUNC(hs_fall));
1876
1877   /* setup dimensions */
1878   m6847->top_border_scanlines = v->top_border_scanlines;
1879   m6847->display_scanlines = v->display_scanlines;
1880   m6847->bottom_border_scanlines = v->bottom_border_scanlines;
1881
1882   /* compute frequency and period */
1883   frequency = v->frames_per_second
1884      * ((UINT32) (v->scanlines_per_frame * FACTOR_SCANLINES_PER_FRAME))
1885      * ((UINT32) (v->clocks_per_scanline * FACTOR_CLOCKS_PER_SCANLINE));
1886   period = ATTOSECONDS_PER_SECOND / frequency;
1887
1888   /* choose CPU clock, if specified */
1889   if (cfg->cpu0_timing_factor > 0)
1890   {
1891      cpu0_clock_period = period * 1 * GROSS_FACTOR;
1892      machine.firstcpu->set_unscaled_clock( ATTOSECONDS_PER_SECOND / cpu0_clock_period);
1893   }
1894
1895   /* calculate timing */
1896   total_scanlines = v->vblank_scanlines
1897      + v->top_border_scanlines
1898      + v->display_scanlines
1899      + v->bottom_border_scanlines
1900      + v->vretrace_scanlines;
1901   m6847->clock_period = period * GROSS_FACTOR;
1902   m6847->scanline_period = period * (UINT32) (v->clocks_per_scanline * GROSS_FACTOR);
1903   m6847->field_sync_period = period * (UINT32) (v->clocks_per_scanline * v->field_sync_scanlines * GROSS_FACTOR);
1904   m6847->horizontal_sync_period = period * GROSS_FACTOR * 33 / 2;
1905   m6847->vblank_period = period * (UINT32) (v->clocks_per_scanline * v->vblank_scanlines * GROSS_FACTOR);
1906
1907   /* setup timing */
1908   frame_period = period *
1909      (UINT32) (v->clocks_per_scanline * total_scanlines * GROSS_FACTOR);
1910   m6847->fs_rise_timer->adjust(attotime::zero, 0, attotime(0, frame_period));
1911
1912   /* setup save states */
1913   machine.save().register_postload(save_prepost_delegate(FUNC(m6847_postload), &machine));
1914
1915   /* build font */
1916   build_fontdata(v);
1917
1918   /* dump stats */
1919   if (LOG_STATS)
1920   {
1921      logerror("m6847_init():\n");
1922      logerror("\tclock:      %30s sec\n", attotime(0, period * GROSS_FACTOR).as_string(ATTOTIME_STRING_PRECISION));
1923      if (cpu0_clock_period > 0)
1924         logerror("\tCPU0 clock: %30s sec\n", attotime(0, cpu0_clock_period).as_string(ATTOTIME_STRING_PRECISION));
1925      logerror("\tscanline:   %30s sec\n", attotime(0, m6847->scanline_period).as_string(ATTOTIME_STRING_PRECISION));
1926      logerror("\tfield sync: %30s sec\n", attotime(0, m6847->field_sync_period).as_string(ATTOTIME_STRING_PRECISION));
1927      logerror("\thorz sync:  %30s sec\n", attotime(0, m6847->horizontal_sync_period).as_string(ATTOTIME_STRING_PRECISION));
1928      logerror("\tvblank:     %30s sec\n", attotime(0, m6847->vblank_period).as_string(ATTOTIME_STRING_PRECISION));
1929      logerror("\tframe:      %30s sec\n", attotime(0, frame_period).as_string(ATTOTIME_STRING_PRECISION));
1930      logerror("\n");
1931   }
1932
1933   /* setup debug commands */
1934   if (machine.debug_flags & DEBUG_FLAG_ENABLED)
1935      debug_console_register_command(machine, "m6847_dumpscanline", CMDFLAG_NONE, 0, 0, 0, execute_m6847_dumpscanline);
1936}
1937
1938
1939
1940SCREEN_UPDATE(m6847)
1941{
1942   int row, i;
1943   UINT32 rc = 0;
1944
1945   /* if we have a custom palette, check to see if it has changed */
1946   if (!m6847->dirty && m6847->has_custom_palette)
1947   {
1948      for (i = 0; i < 16; i++)
1949      {
1950         if (m6847->palette[i] != m6847->saved_palette[i])
1951         {
1952            m6847->dirty = TRUE;
1953            break;
1954         }
1955      }
1956   }
1957
1958   if (m6847->dirty)
1959   {
1960      /* this frame is dirty; render it */
1961      m6847->dirty = FALSE;
1962
1963      /* copy palette if we have a custom palete */
1964      if (m6847->has_custom_palette)
1965      {
1966         for (i = 0; i < 16; i++)
1967            m6847->saved_palette[i] = m6847->palette[i];
1968      }
1969
1970      /* the video RAM has been dirtied; need to draw */
1971      for (row = cliprect->min_y; row <= cliprect->max_y; row++)
1972         render_scanline(screen->machine(), bitmap, row);
1973   }
1974   else
1975   {
1976      /* skip this frame */
1977      rc = UPDATE_HAS_NOT_CHANGED;
1978   }
1979   return rc;
1980}
1981
1982
1983
1984/*************************************
1985 *
1986 *  Timing calculations
1987 *
1988 *************************************/
1989
1990static attotime interval(m6847_timing_type timing)
1991{
1992   attotime result;
1993
1994   switch(timing)
1995   {
1996      case M6847_CLOCK:
1997         result = attotime(0, m6847->clock_period);
1998         break;
1999      case M6847_HSYNC:
2000         result = attotime(0, m6847->scanline_period);
2001         break;
2002      default:
2003         fatalerror("invalid timing type");
2004         break;
2005   }
2006   return result;
2007}
2008
2009
2010
2011attotime coco6847_time_delay(running_machine &machine, m6847_timing_type timing, UINT64 time_delay)
2012{
2013   return interval(timing) * time_delay;
2014}
2015
2016
2017
2018attotime coco6847_scanline_time(int scanline)
2019{
2020   return attotime(0, m6847->scanline_period *
2021         (13 /* FIXME */ + scanline));
2022}
src/mess/video/coco6847.h
r13256r13257
1/*********************************************************************
2
3    coco6847.h
4
5    OBSOLETE Implementation of Motorola 6847 video hardware chip
6
7**********************************************************************/
8
9#ifndef __COCO6847_H__
10#define __COCO6847_H__
11
12
13/* for now, the MAME core forces us to use these */
14#define M6847_NTSC_FRAMES_PER_SECOND   60
15#define M6847_PAL_FRAMES_PER_SECOND      50
16
17typedef enum
18{
19   M6847_VERSION_ORIGINAL_NTSC,
20   M6847_VERSION_ORIGINAL_PAL,
21   M6847_VERSION_M6847Y_NTSC,
22   M6847_VERSION_M6847Y_PAL,
23   M6847_VERSION_M6847T1_NTSC,
24   M6847_VERSION_M6847T1_PAL,
25   M6847_VERSION_GIME_NTSC,
26   M6847_VERSION_GIME_PAL
27} m6847_type;
28
29enum
30{
31   M6847_AG      = 0x80,
32   M6847_AS      = 0x40,
33   M6847_INTEXT   = 0x20,
34   M6847_INV      = 0x10,
35   M6847_CSS      = 0x08,
36   M6847_GM2      = 0x04,
37   M6847_GM1      = 0x02,
38   M6847_GM0      = 0x01
39};
40
41typedef enum
42{
43   M6847_CLOCK,
44   M6847_HSYNC
45} m6847_timing_type;
46
47typedef struct _m6847_config m6847_config;
48struct _m6847_config
49{
50   m6847_type type;
51   int cpu0_timing_factor;
52
53   /* callbacks */
54   void (*horizontal_sync_callback)(running_machine &machine, int line);
55   void (*field_sync_callback)(running_machine &machine,int line);
56   UINT8 (*get_attributes)(running_machine &machine, UINT8 c, int scanline, int pos) ATTR_CONST;
57   const UINT8 *(*get_video_ram)(running_machine &machine, int scanline);
58   UINT8 (*get_char_rom)(running_machine &machine, UINT8 ch, int line);
59
60   /* needed for the CoCo 3 */
61   int (*new_frame_callback)(running_machine &machine);   /* returns whether the M6847 is in charge of this frame */
62   void (*custom_prepare_scanline)(running_machine &machine, int scanline);
63
64   const UINT32 *custom_palette;
65};
66
67/* creates a new M6847 instance */
68void m6847_init(running_machine &machine, const m6847_config *cfg);
69
70/* video update proc */
71SCREEN_UPDATE(m6847);
72void coco6847_video_changed(void);
73
74/* sync */
75int m6847_get_horizontal_sync(running_machine &machine);
76int m6847_get_field_sync(running_machine &machine);
77
78/* timing functions */
79attotime coco6847_time_delay(running_machine &machine, m6847_timing_type timing, UINT64 target_time);
80
81/* CoCo 3 hooks */
82attotime coco6847_scanline_time(int scanline);
83
84INPUT_PORTS_EXTERN( coco6847_artifacting );
85
86
87#endif /* __COCO6847_H__ */
src/mess/video/m6847.c
r13256r13257
1/*********************************************************************
2
3    m6847.c
4
5    Implementation of Motorola 6847 video hardware chip
6
7    Sources:
8    M6847 data sheet
9    M6847T1 info from Rainbow magazine (10/1986-12/1986)
10
11
12    AG  AS  INTEXT  INV  GM2  GM1  GM0
13    --  --  ------  ---  ---  ---  ---
14     0   0       0    0    X    X    X  Internal Alphanumerics
15     0   0       0    1    X    X    X  Internal Alphanumerics Inverted
16     0   0       1    0    X    X    X  External Alphanumerics
17     0   0       1    1    X    X    X  External Alphanumerics Inverted
18     0   1       0    X    X    X    X  Semigraphics 4
19     0   1       1    X    X    X    X  Semigraphics 6
20     1   X       X    X    0    0    0  Graphics CG1 (64x64x4)    (16 bpr)
21     1   X       X    X    0    0    1  Graphics RG1 (128x64x2)   (16 bpr)
22     1   X       X    X    0    1    0  Graphics CG2 (128x64x4)   (32 bpr)
23     1   X       X    X    0    1    1  Graphics RG2 (128x96x2)   (16 bpr)
24     1   X       X    X    1    0    0  Graphics CG3 (128x96x4)   (32 bpr)
25     1   X       X    X    1    0    1  Graphics RG3 (128x192x2)  (16 bpr)
26     1   X       X    X    1    1    0  Graphics CG6 (128x192x4)  (32 bpr)
27     1   X       X    X    1    1    1  Graphics RG6 (256x192x2)  (32 bpr)
28
29    Note: The M6847 relies on an external source (typically a 6883 SAM chip)
30    to feed it bytes; so the BPR (bytes per row) figures are effectively
31    suggestions.  Mismatching modes is responsible for the semigraphic modes
32    on the CoCo.
33
34    Timing:
35    (source Motorola M6847 Manual)
36
37    Horizontal Sync:  Total Period: 227.5 clock cycles
38        @ CLK(0) + DHS_F            - falling edge (high to low)
39        @ CLK(16.5) + DHS_R         - rising edge (low to high)
40        @ CLK(42)                   - left border start
41        @ CLK(71.5)                 - body start
42        @ CLK(199.5)                - right border start
43        @ CLK(227.5) + DHS_F        - falling edge (high to low)
44        ...
45
46    Field Sync: Total Period 262*227.5 clock cycles
47        @ CLK(0) + DFS_F            - falling edge (high to low)
48        @ CLK(32*227.5) + DFS_R     - rising edge (low to high)
49        @ CLK(262*227.5) + DFS_F    - falling edge (high to low) (262.5 for the M6847Y)
50
51    DHS_F:  550ns
52    DHS_R:  740ns
53    DFS_F:  520ns
54    DFS_R:  500ns
55
56    The M6847T1 is a later variant of the M6847 chip that implements lower
57    case support and some other nifty features.  This chip is in the CoCo 2B.
58    I have not been able to find a pinout diagram for this chip so I am
59    assuming that the extra text modes on the CoCo 2B are activated by the
60    GM2-0 pins.  This needs to be confirmed.
61
62    TODO: Implement PAL support
63
64**********************************************************************/
65
66#include "emu.h"
67#include "m6847.h"
68
69#include "debug/debugcpu.h"
70#include "debug/debugcon.h"
71
72enum
73{
74   M6847_AG      = 0x80,
75   M6847_AS      = 0x40,
76   M6847_INTEXT   = 0x20,
77   M6847_INV      = 0x10,
78   M6847_CSS      = 0x08,
79   M6847_GM2      = 0x04,
80   M6847_GM1      = 0x02,
81   M6847_GM0      = 0x01
82};
83
84
85
86#define LOG_FS         0
87#define LOG_HS         0
88#define LOG_STATS      0
89#define LOG_PREPARE      0
90
91typedef struct _m6847_variant m6847_variant;
92struct _m6847_variant
93{
94   const UINT8 *fontdata;
95   unsigned int has_lowercase : 1;
96   unsigned int text_offset : 1;
97
98   int frames_per_second;
99   double scanlines_per_frame;
100   double clocks_per_scanline;
101
102   double vblank_scanlines;
103   int top_border_scanlines;
104   int display_scanlines;
105   int bottom_border_scanlines;
106   int vretrace_scanlines;
107
108   double field_sync_scanlines;
109};
110
111typedef struct _m6847_pixel m6847_pixel;
112struct _m6847_pixel
113{
114   UINT8 data;
115   UINT8 attr;
116};
117
118typedef struct _mc6847_state mc6847_state;
119struct _mc6847_state
120{
121   /* callbacks */
122   devcb_resolved_read8 in_dd_func;
123
124   devcb_resolved_read_line in_gm2_func;
125   devcb_resolved_read_line in_gm1_func;
126   devcb_resolved_read_line in_gm0_func;
127   devcb_resolved_read_line in_intext_func;
128   devcb_resolved_read_line in_inv_func;
129   devcb_resolved_read_line in_as_func;
130   devcb_resolved_read_line in_ag_func;
131   devcb_resolved_read_line in_css_func;
132
133   devcb_resolved_write_line out_fs_func;
134   devcb_resolved_write_line out_hs_func;
135   devcb_resolved_write_line out_rs_func;
136
137   /* state of mode control lines */
138   unsigned int gm2 : 1;
139   unsigned int gm1 : 1;
140   unsigned int gm0 : 1;
141   unsigned int intext : 1;
142   unsigned int inv : 1;
143   unsigned int as : 1;
144   unsigned int ag : 1;
145   unsigned int css : 1;
146
147   /* sync control line status */
148   unsigned int fs : 1;
149   unsigned int hs : 1;
150
151   /* to be cleaned up... */
152   int (*new_frame_callback)(running_machine &machine);   /* returns whether the M6847 is in charge of this frame */
153   void (*custom_prepare_scanline)(int scanline);
154   UINT8 (*get_char_rom)(running_machine &machine, UINT8 ch,int line);
155
156   /* timers */
157   emu_timer *fs_rise_timer;
158   emu_timer *fs_fall_timer;
159   emu_timer *hs_rise_timer;
160   emu_timer *hs_fall_timer;
161
162   /* things that vary according to chip version */
163   attoseconds_t clock_period;
164   attoseconds_t scanline_period;
165   attoseconds_t field_sync_period;
166   attoseconds_t horizontal_sync_period;
167   attoseconds_t vblank_period;
168   int top_border_scanlines;
169   int display_scanlines;
170   int bottom_border_scanlines;
171   const UINT32 *palette;
172
173   /* flags */
174   unsigned int has_lowercase : 1;         /* M6847T1 has lower case */
175   unsigned int has_custom_palette : 1;   /* needed for CoCo 3 */
176   unsigned int text_offset : 2;         /* needed for CoCo 3 */
177
178   /* video state; every scanline the video state for the scanline is copied
179     * here and only rendered in SCREEN_UPDATE */
180   int dirty;
181   int using_custom;
182   UINT32 border[384];
183   UINT8 attrs[384];
184   m6847_pixel screendata[192][32];
185
186   UINT32 saved_artifacting, saved_c0, saved_c1;
187   UINT32 expanded_colors[128];
188
189   /* saved palette; used with CoCo 3 */
190   UINT32 saved_palette[16];
191
192   /* 2^7 modes, 256/16 character groups, background/foreground */
193   UINT8 colordata[128][256/16][2];
194
195   /* 2^7 modes, 256 characters, 12 scanlines */
196   UINT8 fontdata[128][256][12];
197};
198
199
200
201static void apply_artifacts(device_t *device, UINT32 *line);
202
203
204static const UINT8 pal_round_fontdata8x12[] =
205{
206   0x00, 0x00, 0x38, 0x44, 0x04, 0x34, 0x4C, 0x4C, 0x38, 0x00, 0x00, 0x00,
207   0x00, 0x00, 0x10, 0x28, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x00, 0x00, 0x00,
208   0x00, 0x00, 0x78, 0x24, 0x24, 0x38, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
209   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
210   0x00, 0x00, 0x78, 0x24, 0x24, 0x24, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
211   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
212   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
213   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x4C, 0x44, 0x38, 0x00, 0x00, 0x00,
214   0x00, 0x00, 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
215   0x00, 0x00, 0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
216   0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
217   0x00, 0x00, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
218   0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
219   0x00, 0x00, 0x44, 0x6C, 0x54, 0x54, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
220   0x00, 0x00, 0x44, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x44, 0x00, 0x00, 0x00,
221   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
222   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
223   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
224   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
225   0x00, 0x00, 0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
226   0x00, 0x00, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
227   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
228   0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x00, 0x00, 0x00,
229   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x54, 0x6C, 0x44, 0x00, 0x00, 0x00,
230   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00, 0x00, 0x00,
231   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
232   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7C, 0x00, 0x00, 0x00,
233   0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00, 0x00,
234   0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00,
235   0x00, 0x00, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x00,
236   0x00, 0x00, 0x10, 0x38, 0x54, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
237   0x00, 0x00, 0x00, 0x10, 0x20, 0x7C, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00,
238   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239   0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
240   0x00, 0x00, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241   0x00, 0x00, 0x28, 0x28, 0x7C, 0x28, 0x7C, 0x28, 0x28, 0x00, 0x00, 0x00,
242   0x00, 0x00, 0x10, 0x3C, 0x50, 0x38, 0x14, 0x78, 0x10, 0x00, 0x00, 0x00,
243   0x00, 0x00, 0x60, 0x64, 0x08, 0x10, 0x20, 0x4C, 0x0C, 0x00, 0x00, 0x00,
244   0x00, 0x00, 0x20, 0x50, 0x50, 0x20, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
245   0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246   0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
247   0x00, 0x00, 0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
248   0x00, 0x00, 0x00, 0x10, 0x54, 0x38, 0x38, 0x54, 0x10, 0x00, 0x00, 0x00,
249   0x00, 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
250   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x40, 0x00, 0x00,
251   0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
253   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00,
254   0x00, 0x00, 0x38, 0x44, 0x4C, 0x54, 0x64, 0x44, 0x38, 0x00, 0x00, 0x00,
255   0x00, 0x00, 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
256   0x00, 0x00, 0x38, 0x44, 0x04, 0x38, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
257   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
258   0x00, 0x00, 0x08, 0x18, 0x28, 0x48, 0x7C, 0x08, 0x08, 0x00, 0x00, 0x00,
259   0x00, 0x00, 0x7C, 0x40, 0x78, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
260   0x00, 0x00, 0x38, 0x40, 0x40, 0x78, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
261   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40, 0x00, 0x00, 0x00,
262   0x00, 0x00, 0x38, 0x44, 0x44, 0x38, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
263   0x00, 0x00, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x38, 0x00, 0x00, 0x00,
264   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
265   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00,
266   0x00, 0x00, 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
267   0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00,
268   0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
269   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
270
271   /* Lower case */
272   0x00, 0x00, 0x18, 0x24, 0x20, 0x70, 0x20, 0x24, 0x78, 0x00, 0x00, 0x00,
273   0x00, 0x00, 0x00, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, 0x00, 0x00,
274   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x64, 0x58, 0x00, 0x00, 0x00,
275   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
276   0x00, 0x00, 0x04, 0x04, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
277   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00, 0x00, 0x00,
278   0x00, 0x00, 0x08, 0x14, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
279   0x00, 0x00, 0x00, 0x00, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x04, 0x38, 0x00,
280   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
281   0x00, 0x00, 0x10, 0x00, 0x30, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
282   0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00,
283   0x00, 0x00, 0x40, 0x40, 0x48, 0x50, 0x60, 0x50, 0x48, 0x00, 0x00, 0x00,
284   0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
285   0x00, 0x00, 0x00, 0x00, 0x78, 0x54, 0x54, 0x54, 0x54, 0x00, 0x00, 0x00,
286   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
287   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
288   0x00, 0x00, 0x00, 0x00, 0x78, 0x44, 0x44, 0x44, 0x78, 0x40, 0x40, 0x00,
289   0x00, 0x00, 0x00, 0x00, 0x3C, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x00,
290   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
291   0x00, 0x00, 0x00, 0x00, 0x3C, 0x40, 0x38, 0x04, 0x78, 0x00, 0x00, 0x00,
292   0x00, 0x00, 0x20, 0x20, 0x70, 0x20, 0x20, 0x24, 0x18, 0x00, 0x00, 0x00,
293   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
294   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00, 0x00, 0x00,
295   0x00, 0x00, 0x00, 0x00, 0x44, 0x54, 0x54, 0x28, 0x28, 0x00, 0x00, 0x00,
296   0x00, 0x00, 0x00, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00,
297   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x38, 0x00, 0x00,
298   0x00, 0x00, 0x00, 0x00, 0x7C, 0x08, 0x10, 0x20, 0x7C, 0x00, 0x00, 0x00,
299   0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,
300   0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
301   0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00,
302   0x00, 0x00, 0x20, 0x54, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
303   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00,
304
305   /* Semigraphics 6 */
306   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
308   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
309   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
310   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
311   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
312   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
313   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
314   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
315   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
316   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
317   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
318   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
319   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
320   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
321   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
322   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
324   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
325   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
326   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
327   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
328   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
329   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
330   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
331   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
332   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
333   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
334   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
335   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
336   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
337   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
338   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
339   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
340   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
341   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
342   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
343   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
344   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
345   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
346   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
347   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
348   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
349   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
350   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
351   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
352   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
353   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
354   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
355   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
356   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
357   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
358   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
359   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
360   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
361   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
362   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
363   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
364   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
365   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
366   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
367   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
368   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
369   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
370
371   /* Block Graphics (Semigraphics 4 Graphics ) */
372   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
373   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
374   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
375   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
376   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
377   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
378   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
379   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
380   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
381   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
382   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
383   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
384   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
385   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
386   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
387   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
388};
389
390
391
392static const UINT8 pal_square_fontdata8x12[] =
393{
394   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1A, 0x2A, 0x2A, 0x1C, 0x00, 0x00,
395   0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x00, 0x00,
396   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x1C, 0x12, 0x12, 0x3C, 0x00, 0x00,
397   0x00, 0x00, 0x00, 0x1C, 0x22, 0x20, 0x20, 0x20, 0x22, 0x1C, 0x00, 0x00,
398   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x12, 0x12, 0x12, 0x3C, 0x00, 0x00,
399   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x3C, 0x20, 0x20, 0x3E, 0x00, 0x00,
400   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00,
401   0x00, 0x00, 0x00, 0x1E, 0x20, 0x20, 0x26, 0x22, 0x22, 0x1E, 0x00, 0x00,
402   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x22, 0x00, 0x00,
403   0x00, 0x00, 0x00, 0x1C, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
404   0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x22, 0x22, 0x1C, 0x00, 0x00,
405   0x00, 0x00, 0x00, 0x22, 0x24, 0x28, 0x30, 0x28, 0x24, 0x22, 0x00, 0x00,
406   0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3E, 0x00, 0x00,
407   0x00, 0x00, 0x00, 0x22, 0x36, 0x2A, 0x2A, 0x22, 0x22, 0x22, 0x00, 0x00,
408   0x00, 0x00, 0x00, 0x22, 0x32, 0x2A, 0x26, 0x22, 0x22, 0x22, 0x00, 0x00,
409   0x00, 0x00, 0x00, 0x3E, 0x22, 0x22, 0x22, 0x22, 0x22, 0x3E, 0x00, 0x00,
410   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00,
411   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x2A, 0x24, 0x1A, 0x00, 0x00,
412   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x28, 0x24, 0x22, 0x00, 0x00,
413   0x00, 0x00, 0x00, 0x1C, 0x22, 0x10, 0x08, 0x04, 0x22, 0x1C, 0x00, 0x00,
414   0x00, 0x00, 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
415   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
416   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00,
417   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x2A, 0x2A, 0x36, 0x22, 0x00, 0x00,
418   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00, 0x00,
419   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
420   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x3E, 0x00, 0x00,
421   0x00, 0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00,
422   0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x00, 0x00,
423   0x00, 0x00, 0x00, 0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0E, 0x00, 0x00,
424   0x00, 0x00, 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
425   0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x3E, 0x10, 0x08, 0x00, 0x00, 0x00,
426   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
427   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
428   0x00, 0x00, 0x00, 0x14, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
429   0x00, 0x00, 0x00, 0x14, 0x14, 0x36, 0x00, 0x36, 0x14, 0x14, 0x00, 0x00,
430   0x00, 0x00, 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08, 0x00, 0x00,
431   0x00, 0x00, 0x00, 0x32, 0x32, 0x04, 0x08, 0x10, 0x26, 0x26, 0x00, 0x00,
432   0x00, 0x00, 0x00, 0x10, 0x28, 0x28, 0x10, 0x2A, 0x24, 0x1A, 0x00, 0x00,
433   0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
434   0x00, 0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00,
435   0x00, 0x00, 0x00, 0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08, 0x00, 0x00,
436   0x00, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x3E, 0x1C, 0x08, 0x00, 0x00, 0x00,
437   0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x00,
438   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x10, 0x20, 0x00, 0x00,
439   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
440   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00,
441   0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
442   0x00, 0x00, 0x00, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18, 0x00, 0x00,
443   0x00, 0x00, 0x00, 0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
444   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1C, 0x20, 0x20, 0x3E, 0x00, 0x00,
445   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x0C, 0x02, 0x22, 0x1C, 0x00, 0x00,
446   0x00, 0x00, 0x00, 0x04, 0x0C, 0x14, 0x3E, 0x04, 0x04, 0x04, 0x00, 0x00,
447   0x00, 0x00, 0x00, 0x3E, 0x20, 0x3C, 0x02, 0x02, 0x22, 0x1C, 0x00, 0x00,
448   0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x1C, 0x00, 0x00,
449   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
450   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1C, 0x22, 0x22, 0x1C, 0x00, 0x00,
451   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1E, 0x02, 0x02, 0x1C, 0x00, 0x00,
452   0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
453   0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00,
454   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00,
455   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00,
456   0x00, 0x00, 0x00, 0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10, 0x00, 0x00,
457   0x00, 0x00, 0x00, 0x18, 0x24, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
458
459   /* Lower case */
460   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x12, 0x3C, 0x00, 0x00,
461   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x02, 0x1E, 0x22, 0x1E, 0x00, 0x00,
462   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x00, 0x00,
463   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x20, 0x1C, 0x00, 0x00,
464   0x00, 0x00, 0x00, 0x02, 0x02, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x00, 0x00,
465   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x3E, 0x20, 0x1C, 0x00, 0x00,
466   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00,
467   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
468   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00,
469   0x00, 0x00, 0x00, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
470   0x00, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x24, 0x18,
471   0x00, 0x00, 0x00, 0x20, 0x20, 0x24, 0x28, 0x38, 0x24, 0x22, 0x00, 0x00,
472   0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
473   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x2A, 0x2A, 0x2A, 0x2A, 0x00, 0x00,
474   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x22, 0x22, 0x22, 0x00, 0x00,
475   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
476   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x20, 0x20,
477   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x03,
478   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00,
479   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x00, 0x00,
480   0x00, 0x00, 0x00, 0x10, 0x3C, 0x10, 0x10, 0x10, 0x12, 0x0C, 0x00, 0x00,
481   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x26, 0x1A, 0x00, 0x00,
482   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x14, 0x08, 0x00, 0x00,
483   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x2A, 0x2A, 0x1C, 0x14, 0x00, 0x00,
484   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00, 0x00,
485   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
486   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x04, 0x08, 0x10, 0x3E, 0x00, 0x00,
487   0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00,
488   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00,
489   0x00, 0x00, 0x00, 0x08, 0x04, 0x04, 0x02, 0x04, 0x04, 0x08, 0x00, 0x00,
490   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x00,
491   0x00, 0x00, 0x00, 0x08, 0x04, 0x3E, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00,
492
493   /* Semigraphics 6 */
494   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
495   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
496   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
497   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
498   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
499   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
500   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
501   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
502   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
503   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
504   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
505   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
506   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
507   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
508   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
509   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
510   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
511   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
512   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
513   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
514   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
515   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
516   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
517   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
518   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
519   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
520   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
521   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
522   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
523   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
524   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
525   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
526   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
527   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
528   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
529   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
530   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
531   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
532   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
533   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
534   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
535   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
536   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
537   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
538   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
539   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
540   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
541   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
542   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
543   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
544   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
545   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
546   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
547   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
548   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
549   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
550   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
551   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
552   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
553   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
554   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
555   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
556   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
557   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
558
559   /* Block Graphics (Semigraphics 4 Graphics ) */
560   0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,
561   0x00,0x00,0x00,0x00,0x00,0x00, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
562   0x00,0x00,0x00,0x00,0x00,0x00, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
563   0x00,0x00,0x00,0x00,0x00,0x00, 0xff,0xff,0xff,0xff,0xff,0xff,
564   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0x00,0x00,0x00,0x00,0x00,0x00,
565   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
566   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
567   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0xff,0xff,0xff,0xff,0xff,0xff,
568   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0x00,0x00,0x00,0x00,0x00,0x00,
569   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
570   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
571   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0xff,0xff,0xff,0xff,0xff,0xff,
572   0xff,0xff,0xff,0xff,0xff,0xff, 0x00,0x00,0x00,0x00,0x00,0x00,
573   0xff,0xff,0xff,0xff,0xff,0xff, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
574   0xff,0xff,0xff,0xff,0xff,0xff, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
575   0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff
576};
577
578
579
580static const UINT8 ntsc_round_fontdata8x12[] =
581{
582   0x00, 0x00, 0x38, 0x44, 0x04, 0x34, 0x4C, 0x4C, 0x38, 0x00, 0x00, 0x00,
583   0x00, 0x00, 0x10, 0x28, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x00, 0x00, 0x00,
584   0x00, 0x00, 0x78, 0x24, 0x24, 0x38, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
585   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
586   0x00, 0x00, 0x78, 0x24, 0x24, 0x24, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
587   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
588   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
589   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x4C, 0x44, 0x38, 0x00, 0x00, 0x00,
590   0x00, 0x00, 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
591   0x00, 0x00, 0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
592   0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
593   0x00, 0x00, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
594   0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
595   0x00, 0x00, 0x44, 0x6C, 0x54, 0x54, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
596   0x00, 0x00, 0x44, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x44, 0x00, 0x00, 0x00,
597   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
598   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
599   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
600   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
601   0x00, 0x00, 0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
602   0x00, 0x00, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
603   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
604   0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x00, 0x00, 0x00,
605   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x54, 0x6C, 0x44, 0x00, 0x00, 0x00,
606   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00, 0x00, 0x00,
607   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
608   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7C, 0x00, 0x00, 0x00,
609   0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00, 0x00,
610   0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00,
611   0x00, 0x00, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x00,
612   0x00, 0x00, 0x10, 0x38, 0x54, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
613   0x00, 0x00, 0x00, 0x10, 0x20, 0x7C, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00,
614   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
615   0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
616   0x00, 0x00, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
617   0x00, 0x00, 0x28, 0x28, 0x7C, 0x28, 0x7C, 0x28, 0x28, 0x00, 0x00, 0x00,
618   0x00, 0x00, 0x10, 0x3C, 0x50, 0x38, 0x14, 0x78, 0x10, 0x00, 0x00, 0x00,
619   0x00, 0x00, 0x60, 0x64, 0x08, 0x10, 0x20, 0x4C, 0x0C, 0x00, 0x00, 0x00,
620   0x00, 0x00, 0x20, 0x50, 0x50, 0x20, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
621   0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
622   0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
623   0x00, 0x00, 0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
624   0x00, 0x00, 0x00, 0x10, 0x54, 0x38, 0x38, 0x54, 0x10, 0x00, 0x00, 0x00,
625   0x00, 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
626   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x40, 0x00, 0x00,
627   0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
628   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
629   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00,
630   0x00, 0x00, 0x38, 0x44, 0x4C, 0x54, 0x64, 0x44, 0x38, 0x00, 0x00, 0x00,
631   0x00, 0x00, 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
632   0x00, 0x00, 0x38, 0x44, 0x04, 0x38, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
633   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
634   0x00, 0x00, 0x08, 0x18, 0x28, 0x48, 0x7C, 0x08, 0x08, 0x00, 0x00, 0x00,
635   0x00, 0x00, 0x7C, 0x40, 0x78, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
636   0x00, 0x00, 0x38, 0x40, 0x40, 0x78, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
637   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40, 0x00, 0x00, 0x00,
638   0x00, 0x00, 0x38, 0x44, 0x44, 0x38, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
639   0x00, 0x00, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x38, 0x00, 0x00, 0x00,
640   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
641   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00,
642   0x00, 0x00, 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
643   0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00,
644   0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
645   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
646
647   /* Lower case */
648   0x00, 0x00, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
649   0x00, 0x00, 0x00, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, 0x00, 0x00,
650   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x64, 0x58, 0x00, 0x00, 0x00,
651   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
652   0x00, 0x00, 0x04, 0x04, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
653   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00, 0x00, 0x00,
654   0x00, 0x00, 0x08, 0x14, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
655   0x00, 0x00, 0x00, 0x00, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x04, 0x38, 0x00,
656   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
657   0x00, 0x00, 0x10, 0x00, 0x30, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
658   0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00,
659   0x00, 0x00, 0x40, 0x40, 0x48, 0x50, 0x60, 0x50, 0x48, 0x00, 0x00, 0x00,
660   0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
661   0x00, 0x00, 0x00, 0x00, 0x78, 0x54, 0x54, 0x54, 0x54, 0x00, 0x00, 0x00,
662   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
663   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
664   0x00, 0x00, 0x00, 0x00, 0x78, 0x44, 0x44, 0x44, 0x78, 0x40, 0x40, 0x00,
665   0x00, 0x00, 0x00, 0x00, 0x3C, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x00,
666   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
667   0x00, 0x00, 0x00, 0x00, 0x3C, 0x40, 0x38, 0x04, 0x78, 0x00, 0x00, 0x00,
668   0x00, 0x00, 0x20, 0x20, 0x70, 0x20, 0x20, 0x24, 0x18, 0x00, 0x00, 0x00,
669   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
670   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00, 0x00, 0x00,
671   0x00, 0x00, 0x00, 0x00, 0x44, 0x54, 0x54, 0x28, 0x28, 0x00, 0x00, 0x00,
672   0x00, 0x00, 0x00, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00,
673   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x38, 0x00, 0x00,
674   0x00, 0x00, 0x00, 0x00, 0x7C, 0x08, 0x10, 0x20, 0x7C, 0x00, 0x00, 0x00,
675   0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,
676   0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
677   0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00,
678   0x00, 0x00, 0x20, 0x54, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
679   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00,
680
681   /* Semigraphics 6 */
682   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
683   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
684   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
685   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
686   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
687   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
688   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
689   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
690   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
691   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
692   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
693   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
694   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
695   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
696   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
697   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
698   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
699   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
700   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
701   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
702   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
703   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
704   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
705   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
706   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
707   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
708   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
709   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
710   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
711   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
712   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
713   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
714   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
715   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
716   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
717   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
718   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
719   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
720   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
721   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
722   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
723   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
724   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
725   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
726   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
727   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
728   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
729   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
730   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
731   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
732   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
733   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
734   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
735   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
736   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
737   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
738   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
739   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
740   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
741   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
742   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
743   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
744   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
745   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
746
747   /* Block Graphics (Semigraphics 4 Graphics ) */
748   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
749   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
750   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
751   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
752   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
753   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
754   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
755   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
756   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
757   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
758   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
759   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
760   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
761   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
762   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
763   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
764};
765
766
767
768static const UINT8 ntsc_square_fontdata8x12[] =
769{
770   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1A, 0x2A, 0x2A, 0x1C, 0x00, 0x00,
771   0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x00, 0x00,
772   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x1C, 0x12, 0x12, 0x3C, 0x00, 0x00,
773   0x00, 0x00, 0x00, 0x1C, 0x22, 0x20, 0x20, 0x20, 0x22, 0x1C, 0x00, 0x00,
774   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x12, 0x12, 0x12, 0x3C, 0x00, 0x00,
775   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x38, 0x20, 0x20, 0x3E, 0x00, 0x00,
776   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x38, 0x20, 0x20, 0x20, 0x00, 0x00,
777   0x00, 0x00, 0x00, 0x1E, 0x20, 0x20, 0x26, 0x22, 0x22, 0x1E, 0x00, 0x00,
778   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x22, 0x00, 0x00,
779   0x00, 0x00, 0x00, 0x1C, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
780   0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x22, 0x22, 0x1C, 0x00, 0x00,
781   0x00, 0x00, 0x00, 0x22, 0x24, 0x28, 0x30, 0x28, 0x24, 0x22, 0x00, 0x00,
782   0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3E, 0x00, 0x00,
783   0x00, 0x00, 0x00, 0x22, 0x36, 0x2A, 0x2A, 0x22, 0x22, 0x22, 0x00, 0x00,
784   0x00, 0x00, 0x00, 0x22, 0x32, 0x2A, 0x26, 0x22, 0x22, 0x22, 0x00, 0x00,
785   0x00, 0x00, 0x00, 0x3E, 0x22, 0x22, 0x22, 0x22, 0x22, 0x3E, 0x00, 0x00,
786   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00,
787   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x2A, 0x24, 0x1A, 0x00, 0x00,
788   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x28, 0x24, 0x22, 0x00, 0x00,
789   0x00, 0x00, 0x00, 0x1C, 0x22, 0x10, 0x08, 0x04, 0x22, 0x1C, 0x00, 0x00,
790   0x00, 0x00, 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
791   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
792   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00,
793   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x2A, 0x2A, 0x36, 0x22, 0x00, 0x00,
794   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00, 0x00,
795   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
796   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x3E, 0x00, 0x00,
797   0x00, 0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00,
798   0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x00, 0x00,
799   0x00, 0x00, 0x00, 0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0E, 0x00, 0x00,
800   0x00, 0x00, 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
801   0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x3E, 0x10, 0x08, 0x00, 0x00, 0x00,
802   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
803   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
804   0x00, 0x00, 0x00, 0x14, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
805   0x00, 0x00, 0x00, 0x14, 0x14, 0x36, 0x00, 0x36, 0x14, 0x14, 0x00, 0x00,
806   0x00, 0x00, 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08, 0x00, 0x00,
807   0x00, 0x00, 0x00, 0x32, 0x32, 0x04, 0x08, 0x10, 0x26, 0x26, 0x00, 0x00,
808   0x00, 0x00, 0x00, 0x10, 0x28, 0x28, 0x10, 0x2A, 0x24, 0x1A, 0x00, 0x00,
809   0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
810   0x00, 0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00,
811   0x00, 0x00, 0x00, 0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08, 0x00, 0x00,
812   0x00, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x3E, 0x1C, 0x08, 0x00, 0x00, 0x00,
813   0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x00,
814   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x10, 0x20, 0x00, 0x00,
815   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
816   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00,
817   0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
818   0x00, 0x00, 0x00, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18, 0x00, 0x00,
819   0x00, 0x00, 0x00, 0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
820   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1C, 0x20, 0x20, 0x3E, 0x00, 0x00,
821   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x04, 0x02, 0x22, 0x1C, 0x00, 0x00,
822   0x00, 0x00, 0x00, 0x04, 0x0C, 0x14, 0x3E, 0x04, 0x04, 0x04, 0x00, 0x00,
823   0x00, 0x00, 0x00, 0x3E, 0x20, 0x3C, 0x02, 0x02, 0x22, 0x1C, 0x00, 0x00,
824   0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x1C, 0x00, 0x00,
825   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
826   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1C, 0x22, 0x22, 0x1C, 0x00, 0x00,
827   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1E, 0x02, 0x02, 0x1C, 0x00, 0x00,
828   0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
829   0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00,
830   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00,
831   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00,
832   0x00, 0x00, 0x00, 0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10, 0x00, 0x00,
833   0x00, 0x00, 0x00, 0x18, 0x24, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
834
835   /* Lower case */
836   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x12, 0x3C, 0x00, 0x00,
837   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x02, 0x1E, 0x22, 0x1E, 0x00, 0x00,
838   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x00, 0x00,
839   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x20, 0x1C, 0x00, 0x00,
840   0x00, 0x00, 0x00, 0x02, 0x02, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x00, 0x00,
841   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x3E, 0x20, 0x1C, 0x00, 0x00,
842   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00,
843   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
844   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00,
845   0x00, 0x00, 0x00, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
846   0x00, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x24, 0x18,
847   0x00, 0x00, 0x00, 0x20, 0x20, 0x24, 0x28, 0x38, 0x24, 0x22, 0x00, 0x00,
848   0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
849   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x2A, 0x2A, 0x2A, 0x2A, 0x00, 0x00,
850   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x22, 0x22, 0x22, 0x00, 0x00,
851   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
852   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x20, 0x20,
853   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x03,
854   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00,
855   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x00, 0x00,
856   0x00, 0x00, 0x00, 0x10, 0x3C, 0x10, 0x10, 0x10, 0x12, 0x0C, 0x00, 0x00,
857   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x26, 0x1A, 0x00, 0x00,
858   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x14, 0x08, 0x00, 0x00,
859   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x2A, 0x2A, 0x1C, 0x14, 0x00, 0x00,
860   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00, 0x00,
861   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
862   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x04, 0x08, 0x10, 0x3E, 0x00, 0x00,
863   0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00,
864   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00,
865   0x00, 0x00, 0x00, 0x08, 0x04, 0x04, 0x02, 0x04, 0x04, 0x08, 0x00, 0x00,
866   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x00,
867   0x00, 0x00, 0x00, 0x08, 0x04, 0x3E, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00,
868
869   /* Semigraphics 6 */
870   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
871   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
872   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
873   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
874   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
875   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
876   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
877   0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
878   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
879   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
880   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
881   0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
882   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
883   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
884   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
885   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
886   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
887   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
888   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
889   0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
890   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
891   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
892   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
893   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
894   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
895   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
896   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
897   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
898   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
899   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
900   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
901   0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
902   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
903   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
904   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
905   0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
906   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
907   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
908   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
909   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
910   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
911   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
912   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
913   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
914   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
915   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
916   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
917   0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
918   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
919   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f,
920   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0,
921   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
922   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
923   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
924   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
925   0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff,
926   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00,
927   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
928   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
929   0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff,
930   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
931   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
932   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
933   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
934
935   /* Block Graphics (Semigraphics 4 Graphics ) */
936   0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,
937   0x00,0x00,0x00,0x00,0x00,0x00, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
938   0x00,0x00,0x00,0x00,0x00,0x00, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
939   0x00,0x00,0x00,0x00,0x00,0x00, 0xff,0xff,0xff,0xff,0xff,0xff,
940   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0x00,0x00,0x00,0x00,0x00,0x00,
941   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
942   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
943   0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0xff,0xff,0xff,0xff,0xff,0xff,
944   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0x00,0x00,0x00,0x00,0x00,0x00,
945   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
946   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
947   0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, 0xff,0xff,0xff,0xff,0xff,0xff,
948   0xff,0xff,0xff,0xff,0xff,0xff, 0x00,0x00,0x00,0x00,0x00,0x00,
949   0xff,0xff,0xff,0xff,0xff,0xff, 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
950   0xff,0xff,0xff,0xff,0xff,0xff, 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
951   0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff
952};
953
954
955
956enum
957{
958   GREEN, YELLOW, BLUE, RED,      /*  0 -  3 */
959   BUFF, CYAN, MAGENTA, ORANGE,   /*  4 -  7 */
960
961   BLACK = 10,                  /* 10 */
962
963   DKGREEN = 12, LTGREEN = 13,      /* 12 - 13 */
964   DKORANGE = 14, LTORANGE = 15,   /* 14 - 15 */
965};
966
967
968
969
970#define ATTOTIME_STRING_PRECISION   9
971
972/* MC6847 video output pins: Y, phiA, phiB (Y'UV color space).
973 *
974 * Y voltage levels:
975 * VB ("Black") = 0.72V; VWL ("White Low") = 0.65V; VWM ("White Medium") = 0.54V;
976 * VWH ("White High") = 0.42V.
977 *
978 * phiA and phiB voltage levels:
979 * VOL ("Output Low") = 1.0V; VR ("Reference"?) = 1.5V; VIH ("Input High") = 2.0V.
980 *
981 * Color composition:
982 *
983 * COLOR       |  Y  | phiA | phiB
984 * ------------+-----+------+------
985 * GREEN       | VWM | VOL  | VOL
986 * YELLOW      | VWH | VOL  | VR
987 * BLUE        | VWL | VIH  | VR
988 * RED         | VWL | VR   | VIH
989 * WHITE       | VWH | VR   | VR
990 * CYAN        | VWM | VR   | VOL
991 * MAGENTA     | VWM | VIH  | VIH
992 * ORANGE      | VWM | VOL  | VIH
993 * BLACK       | VB  | VR   | VR
994 * DARK GREEN  | VB  | VOL  | VOL
995 * DARK ORANGE | VB  | VOL  | VIH
996 *
997 *
998 * Mapping voltages to a 0~255 range:
999 *
1000 * Y values:
1001 * VB = 0; VWL = 59; VWM = 153; VWH = 255.
1002 *
1003 * phiA and phiB values:
1004 * VOL = -128; VR = 0; VIH = +128.
1005 *
1006 *
1007 * Y'UV to RGB convertion:
1008 * R = Y' + 1.13983 x U
1009 * G = Y' - 0.39465 x U - 0.58060 x V
1010 * B = Y' + 2.03211 x V
1011 *
1012 * So we get:
1013 * GREEN = Y'UV(153,-128,-128) = RGB(7,277,-107) --> #07ff00
1014 * YELLOW = Y'UV(255,-128,0) = RGB(255,305,-5) --> #ffff00
1015 * BLUE = Y'UV(59,+128,0) = RGB(59,8,319) --> #3b08ff
1016 * RED: Y'UV(59,0,+128) = RGB(204,-15,59) --> #cc003b
1017 * WHITE: Y'UV(255,0,0) = RGB(255,255,255) --> #ffffff
1018 * CYAN: Y'UV(153,0,-128) = RGB(7,227,153) --> #07e399
1019 * MAGENTA: Y'UV(153,+128,+128) = RGB(298,28,413) --> #ff1cff
1020 * ORANGE: Y'UV(153,-128,+128) = RGB(298,129,-107) --> #ff8100
1021 * BLACK: Y'UV(0,0,0) = RGB(0,0,0) --> #000000
1022 * DARK GREEN: Y'UV(0,-128,-128) = RGB(-145,124,-260) --> #007c00
1023 * DARK ORANGE: Y'UV(0,-128,+128) = RGB(145,-23,-260) --> #910000
1024 */
1025
1026#define M6847_RGB(r,g,b)   ((r << 16) | (g << 8) | (b << 0))
1027
1028
1029static const UINT32 default_palette[] =
1030{
1031   M6847_RGB(0x07, 0xff, 0x00),   /* GREEN */
1032   M6847_RGB(0xff, 0xff, 0x00),   /* YELLOW */
1033   M6847_RGB(0x3b, 0x08, 0xff),   /* BLUE */
1034   M6847_RGB(0xcc, 0x00, 0x3b),   /* RED */
1035   M6847_RGB(0xff, 0xff, 0xff),   /* BUFF */
1036   M6847_RGB(0x07, 0xe3, 0x99),   /* CYAN */
1037   M6847_RGB(0xff, 0x1c, 0xff),   /* MAGENTA */
1038   M6847_RGB(0xff, 0x81, 0x00),   /* ORANGE */
1039
1040   M6847_RGB(0x00, 0x7c, 0x00),   /* DARK GREEN */
1041   M6847_RGB(0x07, 0xff, 0x00),   /* GREEN */
1042   M6847_RGB(0x00, 0x00, 0x00),   /* BLACK */
1043   M6847_RGB(0xff, 0xff, 0xff),   /* BUFF */
1044
1045   M6847_RGB(0x00, 0x7c, 0x00),   /* ALPHANUMERIC DARK GREEN */
1046   M6847_RGB(0x07, 0xff, 0x00),   /* ALPHANUMERIC BRIGHT GREEN */
1047   M6847_RGB(0x91, 0x00, 0x00),   /* ALPHANUMERIC DARK ORANGE */
1048   M6847_RGB(0xff, 0x81, 0x00)      /* ALPHANUMERIC BRIGHT ORANGE */
1049};
1050
1051
1052
1053#define FACTOR_SCANLINES_PER_FRAME   2
1054#define FACTOR_CLOCKS_PER_SCANLINE   2
1055
1056#define GROSS_FACTOR   (FACTOR_SCANLINES_PER_FRAME * FACTOR_CLOCKS_PER_SCANLINE)
1057
1058static const m6847_variant variants[] =
1059{
1060   {
1061      /* M6847_VERSION_ORIGINAL_NTSC */
1062      ntsc_square_fontdata8x12,
1063      FALSE, 0,
1064      60, 262, 227.5,            /* frames, scanlines, clocks per scanline */
1065      13, 25, 192, 26, 6,
1066      13+25+192               /* field sync period */
1067   },
1068   {
1069      /* M6847_VERSION_ORIGINAL_PAL */
1070      pal_square_fontdata8x12,
1071      FALSE, 0,
1072      50, 262, 227.5,            /* frames, scanlines, clocks per scanline */
1073      13, 25, 192, 26, 6,
1074      13+25+192               /* field sync period */
1075   },
1076   {
1077      /* M6847_VERSION_M6847Y_NTSC */
1078      ntsc_square_fontdata8x12,
1079      FALSE, 0,
1080      60, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
1081      13.5, 25, 192, 26, 6,
1082      13+25+192               /* field sync period */
1083   },
1084   {
1085      /* M6847_VERSION_M6847Y_PAL */
1086      pal_square_fontdata8x12,
1087      FALSE, 0,
1088      50, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
1089      13.5, 25, 192, 26, 6,
1090      13+25+192               /* field sync period */
1091   },
1092   {
1093      /* M6847_VERSION_M6847T1_NTSC */
1094      ntsc_round_fontdata8x12,
1095      TRUE, 0,
1096      60, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
1097      13.5, 25, 192, 26, 6,
1098      13+25+192               /* field sync period */
1099   },
1100   {
1101      /* M6847_VERSION_M6847T1_PAL */
1102      pal_round_fontdata8x12,
1103      TRUE, 0,
1104      50, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
1105      13.5, 25, 192, 26, 6,
1106      13+25+192               /* field sync period */
1107   },
1108   {
1109      /* M6847_VERSION_GIME_NTSC */
1110      ntsc_round_fontdata8x12,
1111      TRUE, 1,
1112      60, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
1113      13.5, 25, 192, 26, 6,
1114      262.5 - 3               /* field sync period */
1115   },
1116   {
1117      /* M6847_VERSION_GIME_PAL */
1118      pal_round_fontdata8x12,
1119      TRUE, 1,
1120      50, 262.5, 227.5,         /* frames, scanlines, clocks per scanline */
1121      13.5, 25, 192, 26, 6,
1122      262.5 - 3               /* field sync period */
1123   }
1124};
1125
1126
1127
1128/*****************************************************************************
1129    INLINE FUNCTIONS
1130*****************************************************************************/
1131
1132INLINE mc6847_state *get_safe_token(device_t *device)
1133{
1134   assert(device != NULL);
1135   assert(device->type() == MC6847);
1136
1137   return (mc6847_state *)downcast<legacy_device_base *>(device)->token();
1138}
1139
1140
1141/*************************************
1142 *
1143 *  Utilities
1144 *
1145 *************************************/
1146
1147static UINT32 color(device_t *device, int c)
1148{
1149   mc6847_state *mc6847 = get_safe_token(device);
1150   return mc6847->palette[c];
1151}
1152
1153static int attr_index_from_attribute(device_t *device, UINT8 attr)
1154{
1155   int result;
1156
1157   result = ((attr & (M6847_AG | M6847_AS | M6847_INTEXT | M6847_INV | M6847_CSS)) >> 3)
1158      | ((attr & (M6847_GM1 | M6847_GM0)) << 5);
1159
1160   /* sanity check */
1161   assert(result < ARRAY_LENGTH(get_safe_token(device)->fontdata));
1162   return result;
1163}
1164
1165static UINT8 attribute_from_attr_index(device_t *device, int attr_index)
1166{
1167   /* sanity check */
1168   assert(attr_index >= 0);
1169   assert(attr_index < ARRAY_LENGTH(get_safe_token(device)->fontdata));
1170
1171   return (UINT8) ((attr_index & 0x1F) << 3)
1172      | ((attr_index & 0x60) >> 5);
1173}
1174
1175
1176
1177/*************************************
1178 *
1179 *  Scanline operations
1180 *
1181 *************************************/
1182
1183static int get_scanline(mc6847_state *mc6847)
1184{
1185   int result;
1186   attotime duration;
1187
1188   /* get the time since last field sync */
1189   duration = mc6847->hs_rise_timer->start() - mc6847->fs_rise_timer->start();
1190   assert_always(duration.seconds == 0, "get_scanline(): duration exceeds one second");
1191
1192   if (duration.attoseconds < mc6847->vblank_period)
1193   {
1194      result = -1;   /* vblank */
1195   }
1196   else
1197   {
1198      result = (duration.attoseconds - mc6847->vblank_period)
1199         / mc6847->scanline_period;
1200   }
1201   return result;
1202}
1203
1204
1205
1206static offs_t scanline_to_address(mc6847_state *mc6847, int scanline)
1207{
1208   if (mc6847->ag)
1209   {
1210      /* graphics */
1211      int gm = (mc6847->gm2 << 2) | (mc6847->gm1 << 1) | mc6847->gm0;
1212
1213      switch (gm)
1214      {
1215      case 0: return (scanline / 3) * 0x10;
1216      case 1: return (scanline / 3) * 0x10;
1217      case 2: return (scanline / 3) * 0x20;
1218      case 3: return (scanline / 2) * 0x20;
1219      case 4: return (scanline / 2) * 0x20;
1220      case 5: return (scanline / 1) * 0x10;
1221      case 6: return (scanline / 1) * 0x20;
1222      case 7: return (scanline / 1) * 0x20;
1223      }
1224   }
1225   else
1226   {
1227      /* text, semi-graphics */
1228      return (scanline / 12) * 0x20;
1229   }
1230
1231   /* we never get here */
1232   return 0;
1233}
1234
1235
1236/* TODO: attributes should be read on demand rather then all at once */
1237static UINT8 update_attributes(mc6847_state *mc6847)
1238{
1239   if (!mc6847->in_gm0_func.isnull())
1240      mc6847->gm0 = mc6847->in_gm0_func();
1241   if (!mc6847->in_gm1_func.isnull())
1242      mc6847->gm1 = mc6847->in_gm1_func();
1243   if (!mc6847->in_gm2_func.isnull())
1244      mc6847->gm2 = mc6847->in_gm2_func();
1245   if (!mc6847->in_css_func.isnull())
1246      mc6847->css = mc6847->in_css_func();
1247   if (!mc6847->in_inv_func.isnull())
1248      mc6847->inv = mc6847->in_inv_func();
1249   if (!mc6847->in_intext_func.isnull())
1250      mc6847->intext = mc6847->in_intext_func();
1251   if (!mc6847->in_as_func.isnull())
1252      mc6847->as = mc6847->in_as_func();
1253   if (!mc6847->in_ag_func.isnull())
1254      mc6847->ag = mc6847->in_ag_func();
1255
1256   return (mc6847->ag << 7) | (mc6847->as << 6) | (mc6847->intext << 5) | (mc6847->inv << 4) |
1257          (mc6847->css << 3) | (mc6847->gm2 << 2) | (mc6847->gm1 << 1) | mc6847->gm0;
1258}
1259
1260
1261INLINE void prepare_scanline(running_machine &machine, mc6847_state *mc6847, int xpos)
1262{
1263   UINT8 attrs, data, attr;
1264   int scanline;
1265   int i, border_color;
1266   int dirty;
1267   m6847_pixel *scanline_data;
1268
1269   scanline = get_scanline(mc6847);
1270
1271   if (LOG_PREPARE)
1272      logerror("m6847_prepare_scanline(): scanline=%d xpos=%d\n", scanline, xpos);
1273
1274   if ((scanline >= 0) && (scanline < (mc6847->top_border_scanlines
1275      + mc6847->display_scanlines + mc6847->bottom_border_scanlines)))
1276   {
1277      if (mc6847->using_custom)
1278      {
1279         mc6847->custom_prepare_scanline(scanline);
1280      }
1281      else
1282      {
1283         /* has the border color changed? */
1284         attrs = update_attributes(mc6847);
1285
1286         /* commenting out cause it breaks the coco3 border,
1287             * the whole 'attr' handling needs to be rewritten anyway
1288            if (attrs != mc6847->attrs[scanline]) */
1289         {
1290            mc6847->dirty = TRUE;
1291            mc6847->attrs[scanline] = attrs;
1292
1293            /* choose the border color */
1294            if (attrs & M6847_AG)
1295               border_color = (attrs & M6847_CSS) ? BUFF : GREEN;
1296            else if (mc6847->has_lowercase && (attrs & M6847_GM2))
1297               border_color = (attrs & M6847_CSS) ? LTORANGE : LTGREEN;
1298            else
1299               border_color = BLACK;
1300
1301            /* need to use palette table directly; border colors are constant */
1302            mc6847->border[scanline] = mc6847->palette[border_color];
1303         }
1304
1305         /* is this a display scanline? */
1306         scanline -= mc6847->top_border_scanlines;
1307         if ((scanline >= 0) && (scanline < mc6847->display_scanlines))
1308         {
1309            offs_t addr = scanline_to_address(mc6847, scanline);
1310            dirty = mc6847->dirty;
1311            scanline_data = mc6847->screendata[scanline];
1312
1313            for (i = xpos; i < 32; i++)
1314            {
1315               data = mc6847->in_dd_func(addr + i);
1316               attr = update_attributes(mc6847);
1317
1318               if ((data != scanline_data[i].data)   || (attr != scanline_data[i].attr))
1319               {
1320                  dirty = TRUE;
1321                  scanline_data[i].data = data;
1322                  scanline_data[i].attr = attr;
1323               }
1324            }
1325            mc6847->dirty = dirty;
1326         }
1327      }
1328   }
1329}
1330
1331
1332
1333void m6847_video_changed(void)
1334{
1335   /* NPW 2-May-2006 - Commenting this out until we properly fix bug #878 */
1336   /* prepare_scanline(get_beamx() / 8); */
1337}
1338
1339
1340
1341/*************************************
1342 *
1343 *  Field sync/Horizontal sync timers
1344 *
1345 *************************************/
1346
1347static TIMER_CALLBACK( hs_fall )
1348{
1349   mc6847_state *mc6847 = (mc6847_state *) ptr;
1350
1351   if (LOG_HS)
1352      logerror("hs_fall(): time=%s\n", machine.time().as_string(ATTOTIME_STRING_PRECISION));
1353
1354   mc6847->hs = ASSERT_LINE;
1355   mc6847->out_hs_func(mc6847->hs);
1356}
1357
1358static TIMER_CALLBACK( hs_rise )
1359{
1360   mc6847_state *mc6847 = (mc6847_state *) ptr;
1361
1362   if (LOG_HS)
1363      logerror("hs_rise(): time=%s\n", machine.time().as_string(ATTOTIME_STRING_PRECISION));
1364
1365   mc6847->hs_rise_timer->adjust(
1366      attotime(0, mc6847->scanline_period), 0);
1367   mc6847->hs_fall_timer->adjust(
1368      attotime(0, mc6847->horizontal_sync_period), 0);
1369
1370   mc6847->hs = CLEAR_LINE;
1371   mc6847->out_hs_func(mc6847->hs);
1372
1373   prepare_scanline(machine, mc6847, 0);
1374}
1375
1376static TIMER_CALLBACK( fs_fall )
1377{
1378   mc6847_state *mc6847 = (mc6847_state *) ptr;
1379
1380   if (LOG_FS)
1381      logerror("fs_fall(): time=%s scanline=%d\n", machine.time().as_string(ATTOTIME_STRING_PRECISION), get_scanline(mc6847));
1382
1383   mc6847->fs = ASSERT_LINE;
1384   mc6847->out_fs_func(mc6847->fs);
1385}
1386
1387static TIMER_CALLBACK( fs_rise )
1388{
1389   mc6847_state *mc6847 = (mc6847_state *) ptr;
1390
1391   if (LOG_FS)
1392      logerror("fs_rise(): time=%s scanline=%d\n", machine.time().as_string(ATTOTIME_STRING_PRECISION), get_scanline(mc6847));
1393
1394   /* adjust field sync falling edge timer */
1395   mc6847->fs_fall_timer->adjust(
1396      attotime(0, mc6847->field_sync_period), 0);
1397
1398   /* adjust horizontal sync rising timer */
1399   mc6847->hs_rise_timer->adjust(attotime::zero);
1400
1401   /* this is a hook for the CoCo 3 code to extend this stuff */
1402   if (mc6847->new_frame_callback)
1403      mc6847->using_custom = !mc6847->new_frame_callback(machine);
1404
1405   mc6847->fs = CLEAR_LINE;
1406   mc6847->out_fs_func(mc6847->fs);
1407}
1408
1409
1410
1411#if 0
1412/*************************************
1413 *
1414 *  Debugging
1415 *
1416 *************************************/
1417
1418
1419static int get_beamx(mc6847_state *mc6847)
1420{
1421   attotime scanline_time;
1422   int result;
1423
1424   scanline_time = mc6847->hs_rise_timer->elapsed();
1425   if (scanline_time.seconds != 0)
1426      return 0;
1427   assert(scanline.as_attoseconds() < mc6847->scanline_period);
1428
1429   if (scanline.as_attoseconds() < (mc6847->clock_period * 42))
1430   {
1431      /* hsync */
1432      result = 0;
1433   }
1434   else if (scanline.as_attoseconds() < (mc6847->clock_period * 95 / 2))
1435   {
1436      /* left border */
1437      result = 0;
1438   }
1439   else if (scanline.as_attoseconds() < (mc6847->clock_period * 351 / 2))
1440   {
1441      /* body */
1442      result = (scanline.as_attoseconds() - (mc6847->clock_period * 95 / 2))
1443         / mc6847->clock_period * 2;
1444   }
1445   else
1446   {
1447      /* right border */
1448      result = 256;
1449   }
1450   return result;
1451}
1452
1453
1454static void execute_m6847_dumpscanline(device_t *device, int ref, int params, const char **param)
1455{
1456   mc6847_state *mc6847 = get_safe_token(device);
1457
1458   int i;
1459   int beamx = get_beamx(mc6847) / 8;
1460   int scanline = get_scanline(mc6847);
1461   const m6847_pixel *pixel = mc6847->screendata[scanline];
1462
1463   for (i = 0; i < beamx; i++)
1464   {
1465      debug_console_printf(device->machine(), "[%02d]: 0x%02X (", i, pixel[i].data);
1466
1467      if (pixel[i].attr & M6847_AG)      debug_console_printf(device->machine(), " AG");
1468      if (pixel[i].attr & M6847_AS)      debug_console_printf(device->machine(), " AS");
1469      if (pixel[i].attr & M6847_INTEXT)   debug_console_printf(device->machine(), " INTEXT");
1470      if (pixel[i].attr & M6847_INV)      debug_console_printf(device->machine(), " INV");
1471      if (pixel[i].attr & M6847_CSS)      debug_console_printf(device->machine(), " CSS");
1472      if (pixel[i].attr & M6847_GM2)      debug_console_printf(device->machine(), " GM2");
1473      if (pixel[i].attr & M6847_GM1)      debug_console_printf(device->machine(), " GM1");
1474      if (pixel[i].attr & M6847_GM0)      debug_console_printf(device->machine(), " GM0");
1475
1476      debug_console_printf(device->machine(), " )\n");
1477   }
1478}
1479#endif
1480
1481
1482
1483/*************************************
1484 *
1485 *  Initialization
1486 *
1487 *************************************/
1488
1489static const UINT8 *find_char(const m6847_variant *v,
1490   UINT8 byte, UINT8 attr, int *fg, int *bg)
1491{
1492   int ch;
1493   size_t offset = 0;
1494
1495   if (attr & M6847_AS)
1496   {
1497      /* semigraphics */
1498      *bg = BLACK;
1499
1500      if (!v->has_lowercase && (attr & M6847_INTEXT))
1501      {
1502         /* semigraphics 6 */
1503         ch = (byte & 0x3F) + 0x60;
1504         *fg = ((byte >> 6) & 0x03) + ((attr & M6847_CSS) ? BUFF : GREEN);
1505      }
1506      else
1507      {
1508         /* semigraphics 4 */
1509         ch = (byte & 0x0F) + 0xA0;
1510         *fg = ((byte >> 4) & 0x07) + GREEN;
1511      }
1512   }
1513   else
1514   {
1515      /* text */
1516      ch = (byte & 0x3F) + 0x00;
1517
1518      if (v->has_lowercase)
1519      {
1520         if ((ch < 0x20) && (attr & M6847_GM0) && !(attr & M6847_INV))
1521         {
1522            /* this is a lowercase character */
1523            attr |= M6847_INV;
1524            ch += 0x40;
1525         }
1526
1527         if ((ch > 0x20) && (attr & M6847_GM0) && !(attr & M6847_INV)) {
1528            ch += 0x20;
1529         }
1530
1531         if (attr & M6847_GM1)
1532            attr ^= M6847_INV;
1533
1534      }
1535
1536      if (attr & M6847_INV)
1537      {
1538         /* dark foreground, light background */
1539         *fg = (attr & M6847_CSS) ? DKORANGE : DKGREEN;
1540         *bg = (attr & M6847_CSS) ? LTORANGE : LTGREEN;
1541      }
1542      else
1543      {
1544         /* light foreground, dark background */
1545         *fg = (attr & M6847_CSS) ? LTORANGE : LTGREEN;
1546         *bg = (attr & M6847_CSS) ? DKORANGE : DKGREEN;
1547      }
1548
1549      offset = v->text_offset;
1550   }
1551
1552   return &v->fontdata[ch * 12] + offset;
1553}
1554
1555
1556
1557static void build_fontdata(device_t *device, const m6847_variant *v)
1558{
1559   mc6847_state *mc6847 = get_safe_token(device);
1560
1561   int attr_index, row;
1562   int fg, bg;
1563   int byte;
1564   const UINT8 *char_data;
1565
1566   for (attr_index = 0; attr_index < ARRAY_LENGTH(mc6847->fontdata); attr_index++)
1567   {
1568      UINT8 attr = attribute_from_attr_index(device, attr_index);
1569
1570      for (byte = 0; byte < 256; byte++)
1571      {
1572         char_data = find_char(v, byte, attr, &fg, &bg);
1573
1574         /* specify colors */
1575         mc6847->colordata[attr_index][byte / 16][0] = bg;
1576         mc6847->colordata[attr_index][byte / 16][1] = fg;
1577
1578         for (row = 0; row < 12; row++)
1579         {
1580            mc6847->fontdata[attr_index][byte][row] = char_data[row];
1581         }
1582      }
1583   }
1584}
1585
1586
1587
1588/*************************************
1589 *
1590 *  Video modes
1591 *
1592 *************************************/
1593
1594static void graphics_color_64(device_t *device, UINT32 *RESTRICT line, const m6847_pixel *RESTRICT video_data)
1595{
1596   int x;
1597   UINT8 byte, attr;
1598
1599   for (x = 0; x < 16; x++)
1600   {
1601      byte = video_data[x].data;
1602      attr = video_data[x].attr;
1603
1604      line[ 0] = line[ 1] = line[ 2] = line[ 3] = color(device, ((byte >> 6) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1605      line[ 4] = line[ 5] = line[ 6] = line[ 7] = color(device, ((byte >> 4) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1606      line[ 8] = line[ 9] = line[10] = line[11] = color(device, ((byte >> 2) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1607      line[12] = line[13] = line[14] = line[15] = color(device, ((byte >> 0) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1608      line += 16;
1609   }
1610}
1611
1612
1613
1614static void graphics_color_128(device_t *device, UINT32 *RESTRICT line, const m6847_pixel *RESTRICT video_data)
1615{
1616   int x;
1617   UINT8 byte, attr;
1618
1619   for (x = 0; x < 32; x++)
1620   {
1621      byte = video_data[x].data;
1622      attr = video_data[x].attr;
1623
1624      line[ 0] = line[ 1] = color(device, ((byte >> 6) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1625      line[ 2] = line[ 3] = color(device, ((byte >> 4) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1626      line[ 4] = line[ 5] = color(device, ((byte >> 2) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1627      line[ 6] = line[ 7] = color(device, ((byte >> 0) & 0x03) + (attr & M6847_CSS ? BUFF : GREEN));
1628      line += 8;
1629   }
1630}
1631
1632
1633
1634static void graphics_bw_128(device_t *device, UINT32 *RESTRICT line, const m6847_pixel *RESTRICT video_data)
1635{
1636   int x;
1637   UINT8 byte, attr;
1638   UINT32 bg, fg;
1639
1640   for (x = 0; x < 16; x++)
1641   {
1642      byte = video_data[x].data;
1643      attr = video_data[x].attr;
1644
1645      bg = color(device, attr & M6847_CSS ? 10 :  8);
1646      fg = color(device, attr & M6847_CSS ? 11 :  9);
1647
1648      line[ 0] = line[ 1] = ((byte >> 7) & 0x01) ? fg : bg;
1649      line[ 2] = line[ 3] = ((byte >> 6) & 0x01) ? fg : bg;
1650      line[ 4] = line[ 5] = ((byte >> 5) & 0x01) ? fg : bg;
1651      line[ 6] = line[ 7] = ((byte >> 4) & 0x01) ? fg : bg;
1652      line[ 8] = line[ 9] = ((byte >> 3) & 0x01) ? fg : bg;
1653      line[10] = line[11] = ((byte >> 2) & 0x01) ? fg : bg;
1654      line[12] = line[13] = ((byte >> 1) & 0x01) ? fg : bg;
1655      line[14] = line[15] = ((byte >> 0) & 0x01) ? fg : bg;
1656      line += 16;
1657   }
1658}
1659
1660
1661
1662static void graphics_bw_256(device_t *device, UINT32 *RESTRICT line, const m6847_pixel *RESTRICT video_data)
1663{
1664   int x;
1665   UINT8 byte, attr;
1666   UINT32 bg, fg;
1667
1668   for (x = 0; x < 32; x++)
1669   {
1670      byte = video_data[x].data;
1671      attr = video_data[x].attr;
1672
1673      bg = color(device, attr & M6847_CSS ? 10 :  8);
1674      fg = color(device, attr & M6847_CSS ? 11 :  9);
1675
1676      line[0] = ((byte >> 7) & 0x01) ? fg : bg;
1677      line[1] = ((byte >> 6) & 0x01) ? fg : bg;
1678      line[2] = ((byte >> 5) & 0x01) ? fg : bg;
1679      line[3] = ((byte >> 4) & 0x01) ? fg : bg;
1680      line[4] = ((byte >> 3) & 0x01) ? fg : bg;
1681      line[5] = ((byte >> 2) & 0x01) ? fg : bg;
1682      line[6] = ((byte >> 1) & 0x01) ? fg : bg;
1683      line[7] = ((byte >> 0) & 0x01) ? fg : bg;
1684      line += 8;
1685   }
1686}
1687
1688
1689
1690static void (*const graphics_modes[8])(device_t *device, UINT32 *line, const m6847_pixel *video_data) =
1691{
1692   graphics_color_64,   graphics_bw_128,
1693   graphics_color_128,   graphics_bw_128,
1694   graphics_color_128,   graphics_bw_128,
1695   graphics_color_128,   graphics_bw_256
1696};
1697
1698
1699
1700static void text_mode(device_t *device, int scanline, UINT32 *RESTRICT line, const m6847_pixel *RESTRICT video_data)
1701{
1702   mc6847_state *mc6847 = get_safe_token(device);
1703   int x;
1704   UINT8 byte, attr;
1705   int attr_index;
1706   UINT32 bg_color, fg_color;
1707   UINT8 char_data;
1708
1709   for (x = 0; x < 32; x++)
1710   {
1711      byte = video_data[x].data;
1712      attr = video_data[x].attr;
1713
1714      attr_index = attr_index_from_attribute(device, attr);
1715
1716      bg_color = color(device, mc6847->colordata[attr_index][byte / 16][0]);
1717      fg_color = color(device, mc6847->colordata[attr_index][byte / 16][1]);
1718
1719      if( (!mc6847->has_lowercase) && (attr & M6847_INTEXT) && !(attr & M6847_AS)) {
1720         if (mc6847->get_char_rom) {
1721            char_data = mc6847->get_char_rom(device->machine(),byte,scanline % 12);
1722         } else {
1723            char_data = 0xff;
1724         }
1725      } else {
1726         if ((attr & M6847_INTEXT) && !(attr & M6847_AS) && mc6847->get_char_rom)
1727            char_data = mc6847->get_char_rom(device->machine(),byte,scanline % 12);
1728         else
1729            char_data = mc6847->fontdata[attr_index][byte][scanline % 12];
1730      }
1731
1732      line[x*8+0] = (char_data & 0x80) ? fg_color : bg_color;
1733      line[x*8+1] = (char_data & 0x40) ? fg_color : bg_color;
1734      line[x*8+2] = (char_data & 0x20) ? fg_color : bg_color;
1735      line[x*8+3] = (char_data & 0x10) ? fg_color : bg_color;
1736      line[x*8+4] = (char_data & 0x08) ? fg_color : bg_color;
1737      line[x*8+5] = (char_data & 0x04) ? fg_color : bg_color;
1738      line[x*8+6] = (char_data & 0x02) ? fg_color : bg_color;
1739      line[x*8+7] = (char_data & 0x01) ? fg_color : bg_color;
1740   }
1741}
1742
1743
1744
1745static void render_scanline(device_t *device, bitmap_t *bitmap, int scanline)
1746{
1747   mc6847_state *mc6847 = get_safe_token(device);
1748   UINT32 border_color;
1749   UINT32 *line;
1750   UINT8 attrs;
1751   int mode, x;
1752   const m6847_pixel *video_data;
1753
1754   /* get the scanline */
1755   line = BITMAP_ADDR32(bitmap, scanline, 0);
1756
1757   /* choose the border color */
1758   border_color = mc6847->border[scanline];
1759   attrs = mc6847->attrs[scanline];
1760
1761   /* is this a border scanline? */
1762   scanline -= mc6847->top_border_scanlines;
1763   if ((scanline >= 0) && (scanline < mc6847->display_scanlines))
1764   {
1765      video_data = mc6847->screendata[scanline];
1766
1767      /* left border */
1768      for (x = 0; x < 32; x++)
1769         line[x] = border_color;
1770
1771      if (attrs & M6847_AG)
1772      {
1773         /* graphics */
1774         mode = attrs & (M6847_GM2|M6847_GM1|M6847_GM0);
1775         graphics_modes[mode](device, line + 32, video_data);
1776      }
1777      else
1778      {
1779         /* text/semigraphics */
1780         text_mode(device, scanline, line + 32, video_data);
1781      }
1782
1783      /* right border */
1784      for (x = 288; x < 320; x++)
1785         line[x] = border_color;
1786
1787      /* special case for artifacting */
1788      if ((attrs & (M6847_AG|M6847_GM2|M6847_GM1|M6847_GM0))
1789         == (M6847_AG|M6847_GM2|M6847_GM1|M6847_GM0))
1790      {
1791         apply_artifacts(device, line + 32);
1792      }
1793   }
1794   else
1795   {
1796      /* we are drawing a border */
1797      for (x = 0; x < bitmap->width; x++)
1798         line[x] = border_color;
1799   }
1800}
1801
1802
1803
1804static void set_dirty(mc6847_state *mc6847)
1805{
1806   mc6847->dirty = TRUE;
1807}
1808
1809
1810
1811/*****************************************************************************
1812    DEVICE INTERFACE
1813*****************************************************************************/
1814
1815static void mc6847_postload(mc6847_state *state)
1816{
1817   set_dirty(state);
1818}
1819
1820static DEVICE_START( mc6847 )
1821{
1822   mc6847_state *mc6847 = get_safe_token(device);
1823   const mc6847_interface *intf = (mc6847_interface *)device->static_config();
1824   const mc6847_config *cfg = (mc6847_config *)downcast<const legacy_device_base *>(device)->inline_config();
1825
1826   const m6847_variant *v;
1827   UINT32 frequency;
1828   attoseconds_t period, frame_period;
1829   double total_scanlines;
1830
1831   /* validate some basic stuff */
1832   assert(device->static_config() != NULL);
1833   assert(downcast<const legacy_device_base *>(device)->inline_config() != NULL);
1834
1835   /* identify proper M6847 variant */
1836   assert(cfg->type < ARRAY_LENGTH(variants));
1837   v = &variants[cfg->type];
1838
1839   /* allocate instance */
1840   set_dirty(mc6847);
1841
1842   /* copy configuration */
1843   mc6847->new_frame_callback = cfg->new_frame_callback;
1844   mc6847->custom_prepare_scanline = cfg->custom_prepare_scanline;
1845   mc6847->has_lowercase = v->has_lowercase;
1846   mc6847->get_char_rom = cfg->get_char_rom;
1847
1848   /* assert our assumptions */
1849   assert((v->scanlines_per_frame * FACTOR_SCANLINES_PER_FRAME)
1850      == (UINT32) (v->scanlines_per_frame * FACTOR_SCANLINES_PER_FRAME));
1851   assert((v->clocks_per_scanline * FACTOR_CLOCKS_PER_SCANLINE)
1852      == (UINT32) (v->clocks_per_scanline * FACTOR_CLOCKS_PER_SCANLINE));
1853   assert((v->scanlines_per_frame * v->clocks_per_scanline * GROSS_FACTOR)
1854      == (UINT32) (v->scanlines_per_frame * v->clocks_per_scanline * GROSS_FACTOR));
1855
1856   /* choose palette */
1857   if (cfg->custom_palette)
1858   {
1859      mc6847->has_custom_palette = 1;
1860      mc6847->palette = cfg->custom_palette;
1861   }
1862   else
1863   {
1864      mc6847->palette = default_palette;
1865   }
1866
1867   /* allocate timers */
1868   mc6847->fs_rise_timer = device->machine().scheduler().timer_alloc(FUNC(fs_rise), mc6847);
1869   mc6847->fs_fall_timer = device->machine().scheduler().timer_alloc(FUNC(fs_fall), mc6847);
1870   mc6847->hs_rise_timer = device->machine().scheduler().timer_alloc(FUNC(hs_rise), mc6847);
1871   mc6847->hs_fall_timer = device->machine().scheduler().timer_alloc(FUNC(hs_fall), mc6847);
1872
1873   /* setup dimensions */
1874   mc6847->top_border_scanlines = v->top_border_scanlines;
1875   mc6847->display_scanlines = v->display_scanlines;
1876   mc6847->bottom_border_scanlines = v->bottom_border_scanlines;
1877
1878   /* compute frequency and period */
1879   frequency = v->frames_per_second
1880      * ((UINT32) (v->scanlines_per_frame * FACTOR_SCANLINES_PER_FRAME))
1881      * ((UINT32) (v->clocks_per_scanline * FACTOR_CLOCKS_PER_SCANLINE));
1882   period = ATTOSECONDS_PER_SECOND / frequency;
1883
1884   /* calculate timing */
1885   total_scanlines = v->vblank_scanlines
1886      + v->top_border_scanlines
1887      + v->display_scanlines
1888      + v->bottom_border_scanlines
1889      + v->vretrace_scanlines;
1890   mc6847->clock_period = period * GROSS_FACTOR;
1891   mc6847->scanline_period = period * (UINT32) (v->clocks_per_scanline * GROSS_FACTOR);
1892   mc6847->field_sync_period = period * (UINT32) (v->clocks_per_scanline * v->field_sync_scanlines * GROSS_FACTOR);
1893   mc6847->horizontal_sync_period = period * GROSS_FACTOR * 33 / 2;
1894   mc6847->vblank_period = period * (UINT32) (v->clocks_per_scanline * v->vblank_scanlines * GROSS_FACTOR);
1895
1896   /* setup timing */
1897   frame_period = period *
1898      (UINT32) (v->clocks_per_scanline * total_scanlines * GROSS_FACTOR);
1899   mc6847->fs_rise_timer->adjust(attotime::zero, 0, attotime(0, frame_period));
1900
1901   /* build font */
1902   build_fontdata(device, v);
1903
1904   /* dump stats */
1905   if (LOG_STATS)
1906   {
1907      logerror("m6847_init():\n");
1908      logerror("\tclock:      %30s sec\n", attotime(0, period * GROSS_FACTOR).as_string(ATTOTIME_STRING_PRECISION));
1909      logerror("\tscanline:   %30s sec\n", attotime(0, mc6847->scanline_period).as_string(ATTOTIME_STRING_PRECISION));
1910      logerror("\tfield sync: %30s sec\n", attotime(0, mc6847->field_sync_period).as_string(ATTOTIME_STRING_PRECISION));
1911      logerror("\thorz sync:  %30s sec\n", attotime(0, mc6847->horizontal_sync_period).as_string(ATTOTIME_STRING_PRECISION));
1912      logerror("\tvblank:     %30s sec\n", attotime(0, mc6847->vblank_period).as_string(ATTOTIME_STRING_PRECISION));
1913      logerror("\tframe:      %30s sec\n", attotime(0, frame_period).as_string(ATTOTIME_STRING_PRECISION));
1914      logerror("\n");
1915   }
1916
1917#if 0
1918   /* setup debug commands */
1919   if (device->machine().debug_flags & DEBUG_FLAG_ENABLED)
1920      debug_console_register_command(device->machine(), "m6847_dumpscanline", CMDFLAG_NONE, 0, 0, 0, execute_m6847_dumpscanline);
1921#endif
1922
1923
1924   /* resolve callbacks */
1925   mc6847->in_dd_func.resolve(intf->in_dd_func, *device);
1926   mc6847->in_gm2_func.resolve(intf->in_gm2_func, *device);
1927   mc6847->in_gm1_func.resolve(intf->in_gm1_func, *device);
1928   mc6847->in_gm0_func.resolve(intf->in_gm0_func, *device);
1929   mc6847->in_intext_func.resolve(intf->in_intext_func, *device);
1930   mc6847->in_inv_func.resolve(intf->in_inv_func, *device);
1931   mc6847->in_as_func.resolve(intf->in_as_func, *device);
1932   mc6847->in_ag_func.resolve(intf->in_ag_func, *device);
1933   mc6847->out_fs_func.resolve(intf->out_fs_func, *device);
1934   mc6847->out_hs_func.resolve(intf->out_hs_func, *device);
1935   mc6847->in_css_func.resolve(intf->in_css_func, *device);
1936
1937   /* setup save states */
1938   device->machine().save().register_postload(save_prepost_delegate(FUNC(mc6847_postload), mc6847));
1939}
1940
1941static DEVICE_RESET( mc6847 )
1942{
1943   mc6847_state *mc6847 = get_safe_token(device);
1944
1945   mc6847->gm2 = 0;
1946   mc6847->gm1 = 0;
1947   mc6847->gm0 = 0;
1948   mc6847->intext = 0;
1949   mc6847->inv = 0;
1950   mc6847->as = 0;
1951   mc6847->ag = 0;
1952   mc6847->css = 0;
1953}
1954
1955DEVICE_GET_INFO( mc6847 )
1956{
1957   switch (state)
1958   {
1959      /* --- the following bits of info are returned as 64-bit signed integers --- */
1960      case DEVINFO_INT_TOKEN_BYTES:         info->i = sizeof(mc6847_state);               break;
1961      case DEVINFO_INT_INLINE_CONFIG_BYTES:   info->i = sizeof(mc6847_config);            break;
1962
1963      /* --- the following bits of info are returned as pointers to data or functions --- */
1964      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME(mc6847);      break;
1965      case DEVINFO_FCT_STOP:               /* Nothing */                           break;
1966      case DEVINFO_FCT_RESET:               info->reset = DEVICE_RESET_NAME(mc6847);      break;
1967
1968      /* --- the following bits of info are returned as NULL-terminated strings --- */
1969      case DEVINFO_STR_NAME:               strcpy(info->s, "Motorola 6847");            break;
1970      case DEVINFO_STR_FAMILY:            strcpy(info->s, "MC6847 VDG");               break;
1971      case DEVINFO_STR_VERSION:            strcpy(info->s, "1.0");                     break;
1972      case DEVINFO_STR_SOURCE_FILE:         strcpy(info->s, __FILE__);                  break;
1973      case DEVINFO_STR_CREDITS:            strcpy(info->s, "Copyright MESS Team");         break;
1974   }
1975}
1976
1977
1978/***************************************************************************
1979    IMPLEMENTATION
1980***************************************************************************/
1981
1982WRITE_LINE_DEVICE_HANDLER( mc6847_gm2_w )
1983{
1984   mc6847_state *mc6847 = get_safe_token(device);
1985   mc6847->gm2 = state;
1986}
1987
1988WRITE_LINE_DEVICE_HANDLER( mc6847_gm1_w )
1989{
1990   mc6847_state *mc6847 = get_safe_token(device);
1991   mc6847->gm1 = state;
1992}
1993
1994WRITE_LINE_DEVICE_HANDLER( mc6847_gm0_w )
1995{
1996   mc6847_state *mc6847 = get_safe_token(device);
1997   mc6847->gm0 = state;
1998}
1999
2000WRITE_LINE_DEVICE_HANDLER( mc6847_intext_w )
2001{
2002   mc6847_state *mc6847 = get_safe_token(device);
2003   mc6847->intext = state;
2004}
2005
2006WRITE_LINE_DEVICE_HANDLER( mc6847_inv_w )
2007{
2008   mc6847_state *mc6847 = get_safe_token(device);
2009   mc6847->inv = state;
2010}
2011
2012WRITE_LINE_DEVICE_HANDLER( mc6847_as_w )
2013{
2014   mc6847_state *mc6847 = get_safe_token(device);
2015   mc6847->as = state;
2016}
2017
2018WRITE_LINE_DEVICE_HANDLER( mc6847_ag_w )
2019{
2020   mc6847_state *mc6847 = get_safe_token(device);
2021   mc6847->ag = state;
2022}
2023
2024WRITE_LINE_DEVICE_HANDLER( mc6847_css_w )
2025{
2026   mc6847_state *mc6847 = get_safe_token(device);
2027   mc6847->css = state;
2028}
2029
2030READ_LINE_DEVICE_HANDLER( mc6847_fs_r )
2031{
2032   mc6847_state *mc6847 = get_safe_token(device);
2033   return mc6847->fs;
2034}
2035
2036READ_LINE_DEVICE_HANDLER( mc6847_hs_r )
2037{
2038   mc6847_state *mc6847 = get_safe_token(device);
2039   return mc6847->hs;
2040}
2041
2042
2043void mc6847_set_palette(device_t *device, UINT32 *palette)
2044{
2045   mc6847_state *mc6847 = get_safe_token(device);
2046   mc6847->has_custom_palette = 1;
2047   mc6847->palette = palette;
2048}
2049
2050
2051/*************************************
2052 *
2053 *  Artifacting hack; should be in core
2054 *
2055 *************************************/
2056
2057static UINT32 mix_color(double factor, UINT8 c0, UINT8 c1)
2058{
2059   return (UINT32) (UINT8) ((c0 * (1.0 - factor)) + (c1 * (0.0 + factor)) + 0.5);
2060}
2061
2062
2063
2064static void apply_artifacts(device_t *device, UINT32 *line)
2065{
2066   /* Boy this code sucks; this code was adapted from the old M6847
2067     * artifacting implmentation.  The only reason that it didn't look as
2068     * horrible was because the code around it sucked as well.  Now that I
2069     * have cleaned everything up, the ugliness is much more prominent.
2070     *
2071     * Hopefully we will have a generic artifacting algorithm that plugs into
2072     * the MESS/MAME core directly so we can chuck this hack */
2073   static const double artifact_colors[14*3] =
2074   {
2075      0.157, 0.000, 0.157, /* [ 1] - dk purple   (reverse  2) */
2076      0.000, 0.157, 0.000, /* [ 2] - dk green    (reverse  1) */
2077      1.000, 0.824, 1.000, /* [ 3] - lt purple   (reverse  4) */
2078      0.824, 1.000, 0.824, /* [ 4] - lt green    (reverse  3) */
2079      0.706, 0.236, 0.118, /* [ 5] - dk blue     (reverse  6) */
2080      0.000, 0.197, 0.471, /* [ 6] - dk red      (reverse  5) */
2081      1.000, 0.550, 0.393, /* [ 7] - lt blue     (reverse  8) */
2082      0.275, 0.785, 1.000, /* [ 8] - lt red      (reverse  7) */
2083      0.000, 0.500, 1.000, /* [ 9] - red         (reverse 10) */
2084      1.000, 0.500, 0.000, /* [10] - blue        (reverse  9) */
2085      1.000, 0.942, 0.785, /* [11] - cyan        (reverse 12) */
2086      0.393, 0.942, 1.000, /* [12] - yellow      (reverse 11) */
2087      0.236, 0.000, 0.000, /* [13] - black-blue  (reverse 14) */
2088      0.000, 0.000, 0.236  /* [14] - black-red   (reverse 13) */
2089   };
2090
2091   static const UINT8 artifactcorrection[128] =
2092   {
2093      0,  0,       0,    0,       0,  6,       0,    2,
2094      5,  7,       5,    7,       1,  3,       1, 11,
2095      8,  6,       8, 14,       8,  9,       8,    9,
2096      4,  4,       4, 15,      12, 12,      12, 15,
2097
2098      5, 13,       5, 13,      13,  0,      13,    2,
2099      10, 10,      10, 10,      10, 15,      10, 11,
2100      3,  1,       3,    1,      15,  9,      15,    9,
2101      11, 11,      11, 11,      15, 15,      15, 15,
2102
2103      14,  0,      14,    0,      14,  6,      14,    2,
2104      0,  7,       0,    7,       1,  3,       1, 11,
2105      9,  6,       9, 14,       9,  9,       9,    9,
2106      15,  4,      15, 15,      12, 12,      12, 15,
2107
2108      2, 13,       2, 13,       2,  0,       2,    2,
2109      10, 10,      10, 10,      10, 15,      10, 11,
2110      12,  1,      12,    1,      12,  9,      12,    9,
2111      15, 11,      15, 11,      15, 15,      15, 15
2112   };
2113
2114   mc6847_state *mc6847 = get_safe_token(device);
2115   UINT32 artifacting, c0, c1;
2116   UINT32 colors[16];
2117   const double *factors;
2118   UINT8 val;
2119   UINT32 new_line[256];
2120   int i;
2121
2122   /* are we artifacting? */
2123   artifacting = input_port_read_safe(device->machine(), "artifacting", 0x00) & 0x03;
2124   if (artifacting == 0x00)
2125      return;
2126   artifacting &= 0x01;
2127
2128   /* determine the base artifact colors */
2129   c1 = line[-1];
2130   for (i = 0; i < 256; i++)
2131   {
2132      if (line[i] != c1)
2133         break;
2134   }
2135   if (i >= 256)
2136      return;   /* if everything is the same color as the border, no need for anything */
2137   c0 = line[i];
2138
2139   /* do we need to update our artifact colors table? */
2140   if ((artifacting != mc6847->saved_artifacting) || (c0 != mc6847->saved_c0) || (c1 != mc6847->saved_c1))
2141   {
2142      mc6847->saved_artifacting = artifacting;
2143      mc6847->saved_c0 = colors[0] = c0;
2144      mc6847->saved_c1 = colors[15] = c1;
2145
2146      /* mix the other colors */
2147      for (i = 1; i <= 14; i++)
2148      {
2149         factors = &artifact_colors[((i - 1) ^ artifacting) * 3];
2150
2151         colors[i] =   (mix_color(factors[0], c0 >> 16, c1 >> 16) << 16)
2152               |   (mix_color(factors[1], c0 >>  8, c1 >>  8) <<  8)
2153               |   (mix_color(factors[2], c0 >>  0, c1 >>  0) <<  0);
2154      }
2155      for (i = 0; i < 128; i++)
2156         mc6847->expanded_colors[i] = colors[artifactcorrection[i]];
2157   }
2158
2159   /* artifact the line */
2160   for (i = 0; i < 256; i += 2)
2161   {
2162      val =   ((line[i - 2] == c1) ? 0x20 : 0x00)
2163         |   ((line[i - 1] == c1) ? 0x10 : 0x00)
2164         |   ((line[i + 0] == c1) ? 0x08 : 0x00)
2165         |   ((line[i + 1] == c1) ? 0x04 : 0x00)
2166         |   ((line[i + 2] == c1) ? 0x02 : 0x00)
2167         |   ((line[i + 3] == c1) ? 0x01 : 0x00);
2168
2169      new_line[i + 0] = mc6847->expanded_colors[val * 2 + 0];
2170      new_line[i + 1] = mc6847->expanded_colors[val * 2 + 1];
2171   }
2172
2173   /* and copy the results back */
2174   memcpy(line, new_line, sizeof(*line) * 256);
2175}
2176
2177
2178
2179static INPUT_CHANGED( artifacting_changed )
2180{
2181   /* TODO: not sure how to do this with a device... */
2182//  set_dirty();
2183}
2184
2185
2186
2187INPUT_PORTS_START( m6847_artifacting )
2188   PORT_START("artifacting")
2189   PORT_CONFNAME( 0x03, 0x01, "Artifacting" ) PORT_CHANGED(artifacting_changed, NULL)
2190   PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
2191   PORT_CONFSETTING(    0x01, DEF_STR( Standard ) )
2192   PORT_CONFSETTING(    0x02, DEF_STR( Reverse ) )
2193INPUT_PORTS_END
2194
2195
2196
2197
2198UINT32 mc6847_update(device_t *device, bitmap_t *bitmap, const rectangle *cliprect)
2199{
2200   mc6847_state *mc6847 = get_safe_token(device);
2201   int row, i;
2202   UINT32 rc = 0;
2203
2204   /* if we have a custom palette, check to see if it has changed */
2205   if (!mc6847->dirty && mc6847->has_custom_palette)
2206   {
2207      for (i = 0; i < 16; i++)
2208      {
2209         if (mc6847->palette[i] != mc6847->saved_palette[i])
2210         {
2211            mc6847->dirty = TRUE;
2212            break;
2213         }
2214      }
2215   }
2216
2217   if (mc6847->dirty)
2218   {
2219      /* this frame is dirty; render it */
2220      mc6847->dirty = FALSE;
2221
2222      /* copy palette if we have a custom palete */
2223      if (mc6847->has_custom_palette)
2224      {
2225         for (i = 0; i < 16; i++)
2226            mc6847->saved_palette[i] = mc6847->palette[i];
2227      }
2228
2229      /* the video RAM has been dirtied; need to draw */
2230      for (row = cliprect->min_y; row <= cliprect->max_y; row++)
2231         render_scanline(device, bitmap, row);
2232   }
2233   else
2234   {
2235      /* skip this frame */
2236      rc = UPDATE_HAS_NOT_CHANGED;
2237   }
2238   return rc;
2239}
2240
2241DEFINE_LEGACY_DEVICE(MC6847, mc6847);
src/mess/video/m6847.h
r13256r13257
1/*********************************************************************
2
3    m6847.h
4
5    Implementation of Motorola 6847 video hardware chip
6
7**********************************************************************/
8
9#ifndef __M6847_H__
10#define __M6847_H__
11
12#include "devcb.h"
13
14
15/***************************************************************************
16    CONSTANTS
17***************************************************************************/
18
19typedef enum
20{
21   M6847_VERSION_ORIGINAL_NTSC,
22   M6847_VERSION_ORIGINAL_PAL,
23   M6847_VERSION_M6847Y_NTSC,
24   M6847_VERSION_M6847Y_PAL,
25   M6847_VERSION_M6847T1_NTSC,
26   M6847_VERSION_M6847T1_PAL,
27   M6847_VERSION_GIME_NTSC,
28   M6847_VERSION_GIME_PAL
29} m6847_type;
30
31/* for now, the MAME core forces us to use these */
32#define M6847_NTSC_FRAMES_PER_SECOND   60
33#define M6847_PAL_FRAMES_PER_SECOND      50
34
35typedef enum
36{
37   M6847_CLOCK,
38   M6847_HSYNC
39} m6847_timing_type;
40
41
42/***************************************************************************
43    TYPE DEFINITIONS
44***************************************************************************/
45
46typedef struct _mc6847_interface mc6847_interface;
47struct _mc6847_interface
48{
49   /* data fetch */
50   devcb_read8 in_dd_func;
51
52   /* mode control lines input */
53   devcb_read_line in_gm2_func;
54   devcb_read_line in_gm1_func;
55   devcb_read_line in_gm0_func;
56   devcb_read_line in_intext_func;
57   devcb_read_line in_inv_func;
58   devcb_read_line in_as_func;
59   devcb_read_line in_ag_func;
60   devcb_read_line in_css_func;
61
62   /* synchronizing outputs */
63   devcb_write_line out_fs_func;
64   devcb_write_line out_hs_func;
65   devcb_write_line out_rs_func;
66};
67
68typedef struct _mc6847_config mc6847_config;
69struct _mc6847_config
70{
71   m6847_type type;
72
73   UINT8 (*get_char_rom)(running_machine &machine, UINT8 ch, int line);
74
75   /* needed for the CoCo 3 */
76   int (*new_frame_callback)(running_machine &machine);   /* returns whether the M6847 is in charge of this frame */
77   void (*custom_prepare_scanline)(int scanline);
78
79   const UINT32 *custom_palette;
80};
81
82/***************************************************************************
83    DEVICE CONFIGURATION MACROS
84***************************************************************************/
85
86DECLARE_LEGACY_DEVICE(MC6847, mc6847);
87
88#define MCFG_MC6847_ADD(_tag, _interface) \
89   MCFG_DEVICE_ADD(_tag, MC6847, 0) \
90   MCFG_DEVICE_CONFIG(_interface)
91
92#define MCFG_MC6847_TYPE(_type) \
93   MCFG_DEVICE_CONFIG_DATA32(mc6847_config, type, _type)
94
95#define MCFG_MC6847_CHAR_ROM(_get_char_rom) \
96   MCFG_DEVICE_CONFIG_DATAPTR(mc6847_config, get_char_rom, _get_char_rom)
97
98#define MCFG_MC6847_FRAME_CALLBACK(_new_frame_callback) \
99   MCFG_DEVICE_CONFIG_DATAPTR(mc6847_config, new_frame_callback, _new_frame_callback)
100
101#define MCFG_MC6847_PREPARE_SCANLINE(_prepare_scanline) \
102   MCFG_DEVICE_CONFIG_DATAPTR(mc6847_config, custom_prepare_scanline, _prepare_scanline)
103
104#define MCFG_MC6847_PALETTE(_palette) \
105   MCFG_DEVICE_CONFIG_DATAPTR(mc6847_config, custom_palette, _palette)
106
107
108/***************************************************************************
109    DEVICE I/O FUNCTIONS
110***************************************************************************/
111
112/* mode control input lines */
113WRITE_LINE_DEVICE_HANDLER( mc6847_gm2_w );
114WRITE_LINE_DEVICE_HANDLER( mc6847_gm1_w );
115WRITE_LINE_DEVICE_HANDLER( mc6847_gm0_w );
116WRITE_LINE_DEVICE_HANDLER( mc6847_intext_w );
117WRITE_LINE_DEVICE_HANDLER( mc6847_inv_w );
118WRITE_LINE_DEVICE_HANDLER( mc6847_as_w );
119WRITE_LINE_DEVICE_HANDLER( mc6847_ag_w );
120WRITE_LINE_DEVICE_HANDLER( mc6847_css_w );
121
122/* synchronizing outputs */
123READ_LINE_DEVICE_HANDLER( mc6847_fs_r );
124READ_LINE_DEVICE_HANDLER( mc6847_hs_r );
125
126
127
128/* video update proc */
129UINT32 mc6847_update(device_t *device, bitmap_t *bitmap, const rectangle *cliprect);
130
131void mc6847_set_palette(device_t *device, UINT32 *palette);
132
133void m6847_video_changed(void);
134
135INPUT_PORTS_EXTERN( m6847_artifacting );
136
137
138#endif /* __M6847_H__ */
src/mess/video/coco.c
r13256r13257
1/***************************************************************************
2
3    Video hardware for CoCo/Dragon family
4
5    driver by Nathan Woods
6
7    See mess/machine/coco.c for references
8
9    TODO: Determine how the CoCo 2B (which used the M6847T1 was hooked up
10    to the M6847T1 chip to generate its text video modes.  My best guess is as
11    follows:
12
13        GM0 would enable lowercase if INV is off, and force INV on by default
14        GM1 would toggle INV
15        GM2 enables an alternate border
16
17***************************************************************************/
18
19#include "emu.h"
20#include "machine/6821pia.h"
21#include "machine/6883sam.h"
22#include "video/coco6847.h"
23#include "includes/coco.h"
24
25
26/*************************************
27 *
28 *  Code
29 *
30 *************************************/
31
32static ATTR_CONST UINT8 coco_get_attributes_2(running_machine &machine, UINT8 c, int scanline, int pos)
33{
34   coco_state *state = machine.driver_data<coco_state>();
35   UINT8 result = 0x00;
36   UINT8 pia1_pb = state->m_pia_1->b_output();
37
38   if (c & 0x40)      result |= M6847_INV;
39   if (c & 0x80)      result |= M6847_AS;
40   if (pia1_pb & 0x08)   result |= M6847_CSS;
41   if (pia1_pb & 0x10)   result |= M6847_GM0;
42   if (pia1_pb & 0x20)   result |= M6847_GM1;
43   if (pia1_pb & 0x40)   result |= M6847_GM2;
44   if (pia1_pb & 0x80)   result |= M6847_AG;
45   return result;
46}
47
48ATTR_CONST UINT8 coco_get_attributes(running_machine &machine, UINT8 c, int scanline, int pos)
49{
50   coco_state *state = machine.driver_data<coco_state>();
51   UINT8 result = 0x00;
52   UINT8 pia1_pb = state->m_pia_1->b_output();
53
54   if (c & 0x40)      result |= M6847_INV;
55   if (c & 0x80)      result |= M6847_AS;
56   if (pia1_pb & 0x08)   result |= M6847_CSS;
57   if (pia1_pb & 0x10)   result |= M6847_GM0 | M6847_INTEXT;
58   if (pia1_pb & 0x20)   result |= M6847_GM1;
59   if (pia1_pb & 0x40)   result |= M6847_GM2;
60   if (pia1_pb & 0x80)   result |= M6847_AG;
61   return result;
62}
63
64
65static void coco_horizontal_sync_callback(running_machine &machine, int data)
66{
67   coco_state *state = machine.driver_data<coco_state>();
68   state->m_pia_0->ca1_w(data);
69}
70
71
72
73static void coco_field_sync_callback(running_machine &machine, int data)
74{
75   coco_state *state = machine.driver_data<coco_state>();
76   state->m_pia_0->cb1_w(data);
77}
78
79static const UINT8 *get_video_ram_coco(running_machine &machine,int scanline)
80{
81   coco_state *state = machine.driver_data<coco_state>();
82   return sam6883_videoram(state->m_sam, scanline);
83}
84
85static void internal_video_start_coco(running_machine &machine, m6847_type type)
86{
87   m6847_config cfg;
88
89   memset(&cfg, 0, sizeof(cfg));
90   cfg.type = type;
91
92   /* NPW 14-May-2006 - Ugly hack; using CPU timing factor seems to break some
93     * Dragon games */
94   if (machine.system().name[0] == 'c')
95      cfg.cpu0_timing_factor = 4;
96
97   if (type==M6847_VERSION_M6847T1_NTSC) {
98      cfg.get_attributes = coco_get_attributes;
99   } else {
100      cfg.get_attributes = coco_get_attributes_2;
101   }
102   cfg.get_video_ram = get_video_ram_coco;
103   cfg.horizontal_sync_callback = coco_horizontal_sync_callback;
104   cfg.field_sync_callback = coco_field_sync_callback;
105
106   m6847_init(machine, &cfg);
107}
108
109
110
111VIDEO_START( dragon )
112{
113   internal_video_start_coco(machine, M6847_VERSION_ORIGINAL_PAL);
114}
115
116VIDEO_START( coco )
117{
118   internal_video_start_coco(machine, M6847_VERSION_ORIGINAL_NTSC);
119}
120
121VIDEO_START( coco2b )
122{
123   internal_video_start_coco(machine, M6847_VERSION_M6847T1_NTSC);
124}
125
src/mess/video/mc6847.c
r0r13257
1/*********************************************************************
2 
3    mc6847.c
4 
5    Implementation of Motorola 6847 video hardware chip
6 
7    Sources:
8    M6847 data sheet
9    M6847T1 info from Rainbow magazine (10/1986-12/1986)
10 
11 
12    AG  AS  INTEXT  INV  GM2  GM1  GM0
13    --  --  ------  ---  ---  ---  ---
14     0   0       0    0    X    X    X  Internal Alphanumerics
15     0   0       0    1    X    X    X  Internal Alphanumerics Inverted
16     0   0       1    0    X    X    X  External Alphanumerics
17     0   0       1    1    X    X    X  External Alphanumerics Inverted
18     0   1       0    X    X    X    X  Semigraphics 4
19     0   1       1    X    X    X    X  Semigraphics 6
20     1   X       X    X    0    0    0  Graphics CG1 (64x64x4)    (16 bpr)
21     1   X       X    X    0    0    1  Graphics RG1 (128x64x2)   (16 bpr)
22     1   X       X    X    0    1    0  Graphics CG2 (128x64x4)   (32 bpr)
23     1   X       X    X    0    1    1  Graphics RG2 (128x96x2)   (16 bpr)
24     1   X       X    X    1    0    0  Graphics CG3 (128x96x4)   (32 bpr)
25     1   X       X    X    1    0    1  Graphics RG3 (128x192x2)  (16 bpr)
26     1   X       X    X    1    1    0  Graphics CG6 (128x192x4)  (32 bpr)
27     1   X       X    X    1    1    1  Graphics RG6 (256x192x2)  (32 bpr)
28 
29    Note: The M6847 relies on an external source (typically a 6883 SAM chip)
30    to feed it bytes; so the BPR (bytes per row) figures are effectively
31    suggestions.  Mismatching modes is responsible for the semigraphic modes
32    on the CoCo.
33 
34    Timing:
35    (source Motorola M6847 Manual)
36 
37    Horizontal Sync:  Total Period: 227.5 clock cycles
38        @ CLK(0) + DHS_F            - falling edge (high to low)
39        @ CLK(16.5) + DHS_R         - rising edge (low to high)
40        @ CLK(42)                   - left border start
41        @ CLK(71.5)                 - body start
42        @ CLK(199.5)                - right border start
43        @ CLK(227.5) + DHS_F        - falling edge (high to low)
44        ...
45 
46    Field Sync: Total Period 262*227.5 clock cycles
47        @ CLK(0) + DFS_F            - falling edge (high to low)
48        @ CLK(32*227.5) + DFS_R     - rising edge (low to high)
49        @ CLK(262*227.5) + DFS_F    - falling edge (high to low) (262.5 for the M6847Y)
50 
51    DHS_F:  550ns
52    DHS_R:  740ns
53    DFS_F:  520ns
54    DFS_R:  500ns
55 
56    The M6847T1 is a later variant of the M6847 chip that implements lower
57    case support and some other nifty features.  This chip is in the CoCo 2B.
58    I have not been able to find a pinout diagram for this chip so I am
59    assuming that the extra text modes on the CoCo 2B are activated by the
60    GM2-0 pins.  This needs to be confirmed.
61 
62**********************************************************************/
63 
64#define ADDRESS_MAP_MODERN
65 
66#include "emu.h"
67#include "video/mc6847.h"
68 
69 
70//**************************************************************************
71//  CONSTANTS
72//**************************************************************************
73 
74#define TOP_BORDER            25
75#define   USE_HORIZONTAL_CLIP      false
76 
77#define TIMER_HSYNC_PERIOD      (227.5)
78#define TIMER_HSYNC_OFF_TIME   (10.0)
79#define TIMER_HSYNC_ON_TIME      (TIMER_HSYNC_OFF_TIME + 16.5)
80#define TIMER_FSYNC_OFF_TIME   (TIMER_HSYNC_PERIOD * TOP_BORDER + TIMER_HSYNC_ON_TIME)
81#define TIMER_FSYNC_ON_TIME      (TIMER_HSYNC_PERIOD * (TOP_BORDER + 192) + TIMER_HSYNC_ON_TIME)
82 
83#define LOG_SCANLINE         0
84#define LOG_HSYNC            0
85#define LOG_FSYNC            0
86 
87 
88const UINT32 mc6847_base_device::s_palette[mc6847_base_device::PALETTE_LENGTH] =
89{
90   MAKE_RGB(0x07, 0xff, 0x00),   /* GREEN */
91   MAKE_RGB(0xff, 0xff, 0x00),   /* YELLOW */
92   MAKE_RGB(0x3b, 0x08, 0xff),   /* BLUE */
93   MAKE_RGB(0xcc, 0x00, 0x3b),   /* RED */
94   MAKE_RGB(0xff, 0xff, 0xff),   /* BUFF */
95   MAKE_RGB(0x07, 0xe3, 0x99),   /* CYAN */
96   MAKE_RGB(0xff, 0x1c, 0xff),   /* MAGENTA */
97   MAKE_RGB(0xff, 0x81, 0x00),   /* ORANGE */
98 
99   MAKE_RGB(0x00, 0x00, 0x00),   /* BLACK */
100   MAKE_RGB(0x07, 0xff, 0x00),   /* GREEN */
101   MAKE_RGB(0x00, 0x00, 0x00),   /* BLACK */
102   MAKE_RGB(0xff, 0xff, 0xff),   /* BUFF */
103 
104   MAKE_RGB(0x00, 0x7c, 0x00),   /* ALPHANUMERIC DARK GREEN */
105   MAKE_RGB(0x07, 0xff, 0x00),   /* ALPHANUMERIC BRIGHT GREEN */
106   MAKE_RGB(0x91, 0x00, 0x00),   /* ALPHANUMERIC DARK ORANGE */
107   MAKE_RGB(0xff, 0x81, 0x00)   /* ALPHANUMERIC BRIGHT ORANGE */
108};
109 
110 
111 
112//**************************************************************************
113//  FRIEND DEVICE
114//**************************************************************************
115 
116//-------------------------------------------------
117//  ctor
118//-------------------------------------------------
119 
120mc6847_friend_device::mc6847_friend_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock,
121      const UINT8 *fontdata, bool is_mc6847t1, double tpfs, int field_sync_falling_edge_scanline)
122   : device_t(mconfig, type, name, tag, owner, clock),
123     m_character_map(fontdata, is_mc6847t1)
124{
125   m_tpfs = tpfs;
126 
127   // The MC6847 and the GIME apply field sync on different scanlines
128   m_field_sync_falling_edge_scanline = field_sync_falling_edge_scanline;
129}
130 
131 
132 
133//-------------------------------------------------
134//  setup_timer - sets up a single timer relative
135//   to the clock
136//-------------------------------------------------
137 
138ATTR_FORCE_INLINE emu_timer *mc6847_friend_device::setup_timer(device_timer_id id, double offset, double period)
139{   
140   emu_timer *timer = timer_alloc(id);
141   timer->adjust(
142      attotime::from_ticks(offset * 4, m_clock * 4),
143      0,
144      attotime::from_ticks(period * 4, m_clock * 4));
145   return timer;
146}
147 
148 
149 
150//-------------------------------------------------
151//  device_start - device-specific startup
152//-------------------------------------------------
153 
154void mc6847_friend_device::device_start(void)
155{
156   /* create the timers */
157   m_frame_timer = setup_timer(   TIMER_FRAME,      0,                  m_tpfs * TIMER_HSYNC_PERIOD);
158   m_hsync_on_timer = setup_timer(   TIMER_HSYNC_ON,      TIMER_HSYNC_ON_TIME,   TIMER_HSYNC_PERIOD);
159   m_hsync_off_timer = setup_timer(TIMER_HSYNC_OFF,   TIMER_HSYNC_OFF_TIME,   TIMER_HSYNC_PERIOD);
160   m_fsync_timer = timer_alloc(TIMER_FSYNC);
161 
162   m_top_border_scanlines = 0;
163   m_body_scanlines = 0;
164   m_wide = false;
165   set_geometry(25, 192, false);
166 
167   /* save states */
168   save_item(NAME(m_physical_scanline));
169   save_item(NAME(m_logical_scanline));
170   save_item(NAME(m_logical_scanline_zone));
171   save_item(NAME(m_horizontal_sync));
172   save_item(NAME(m_field_sync));
173 
174   /* artifacting */
175   m_artifacter.setup_config(this);
176}
177 
178 
179 
180//-------------------------------------------------
181//  device_start - device-specific reset
182//-------------------------------------------------
183 
184void mc6847_friend_device::device_reset(void)
185{
186   device_t::device_reset();
187   m_video_changed = true;
188}
189 
190 
191 
192//-------------------------------------------------
193//  device_post_load - device-specific post load
194//-------------------------------------------------
195 
196void mc6847_friend_device::device_post_load(void)
197{
198   device_t::device_post_load();
199   m_video_changed = true;
200}
201 
202 
203 
204//-------------------------------------------------
205//  update_field_sync_timer
206//-------------------------------------------------
207 
208void mc6847_friend_device::update_field_sync_timer(void)
209{
210   /* are we expecting field sync? */
211   bool expected_field_sync = (m_physical_scanline < m_field_sync_falling_edge_scanline)
212      || (m_logical_scanline_zone == SCANLINE_ZONE_VBLANK);
213 
214   /* determine the duration */
215   attotime duration = (expected_field_sync != m_field_sync) ? attotime::from_ticks(160, m_clock) : attotime::never;
216 
217   /* and reset the timer */
218   m_fsync_timer->adjust(duration, expected_field_sync ? 1 : 0);
219}
220 
221 
222 
223//-------------------------------------------------
224//  device_timer
225//-------------------------------------------------
226 
227void mc6847_friend_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
228{
229   switch(id)
230   {
231      case TIMER_FRAME:      new_frame();               break;
232      case TIMER_HSYNC_ON:   change_horizontal_sync(true);   break;
233      case TIMER_HSYNC_OFF:   change_horizontal_sync(false);   break;
234      case TIMER_FSYNC:      change_field_sync(param != 0);   break;
235   }
236}
237 
238 
239 
240//-------------------------------------------------
241//  new_frame
242//-------------------------------------------------
243 
244ATTR_FORCE_INLINE void mc6847_friend_device::new_frame(void)
245{
246   m_physical_scanline = 0;
247   m_logical_scanline = 0;
248   m_logical_scanline_zone = SCANLINE_ZONE_FRAME_END;
249}
250 
251 
252 
253//-------------------------------------------------
254//  scanline_zone_string
255//-------------------------------------------------
256 
257const char *mc6847_friend_device::scanline_zone_string(scanline_zone zone)
258{
259   const char *result;
260   switch(zone)
261   {
262      case SCANLINE_ZONE_TOP_BORDER:      result = "SCANLINE_ZONE_TOP_BORDER";   break;
263      case SCANLINE_ZONE_BODY:         result = "SCANLINE_ZONE_BODY";         break;
264      case SCANLINE_ZONE_BOTTOM_BORDER:   result = "SCANLINE_ZONE_BOTTOM_BORDER";   break;
265      case SCANLINE_ZONE_RETRACE:         result = "SCANLINE_ZONE_RETRACE";      break;
266      case SCANLINE_ZONE_VBLANK:         result = "SCANLINE_ZONE_VBLANK";      break;
267      case SCANLINE_ZONE_FRAME_END:      result = "SCANLINE_ZONE_FRAME_END";      break;
268      default:
269         fatalerror("Should not get here");
270         break;
271   }
272   return result;
273}
274 
275 
276 
277//-------------------------------------------------
278//  change_horizontal_sync
279//-------------------------------------------------
280 
281ATTR_FORCE_INLINE void mc6847_friend_device::change_horizontal_sync(bool line)
282{
283   g_profiler.start(PROFILER_USER1);
284   if (line && !m_horizontal_sync)
285   {
286      if (LOG_SCANLINE)
287         logerror("%s: change_horizontal_sync():  Recording scanline\n", describe_context());
288 
289      /* first store the scanline */
290      g_profiler.start(PROFILER_USER2);
291      switch((scanline_zone) m_logical_scanline_zone)
292      {
293         case SCANLINE_ZONE_TOP_BORDER:
294         case SCANLINE_ZONE_BOTTOM_BORDER:
295            record_border_scanline(m_physical_scanline);
296            break;
297 
298         case SCANLINE_ZONE_BODY:
299            record_body_scanline(m_physical_scanline, m_logical_scanline);
300            break;
301 
302         case SCANLINE_ZONE_RETRACE:
303         case SCANLINE_ZONE_VBLANK:
304         case SCANLINE_ZONE_FRAME_END:
305            /* do nothing */
306            break;
307      }
308      g_profiler.stop();
309 
310      /* advance to next scanline */
311      next_scanline();
312   }
313 
314   /* finally output horizontal sync */
315   if (line != m_horizontal_sync)
316   {
317      m_horizontal_sync = line;
318 
319      /* log if apprpriate */
320      if (LOG_HSYNC)
321         logerror("%s: change_horizontal_sync(): line=%d\n", describe_context(), line ? 1 : 0);
322 
323      /* invoke callback */
324      if (!m_res_out_hsync_func.isnull())
325         m_res_out_hsync_func(line);
326 
327      /* call virtual function */
328      horizontal_sync_changed(m_horizontal_sync);
329   }
330 
331   /* and update the field sync timer */
332   update_field_sync_timer();
333   g_profiler.stop();
334}
335 
336 
337 
338//-------------------------------------------------
339//  change_field_sync
340//-------------------------------------------------
341 
342ATTR_FORCE_INLINE void mc6847_friend_device::change_field_sync(bool line)
343{
344   /* output field sync */
345   if (line != m_field_sync)
346   {
347      m_field_sync = line;
348 
349      /* log if apprpriate */
350      if (LOG_FSYNC)
351         logerror("%s: change_field_sync(): line=%d\n", describe_context(), line ? 1 : 0);
352 
353      /* invoke callback */
354      if (!m_res_out_fsync_func.isnull())
355         m_res_out_fsync_func(line);
356 
357      /* call virtual function */
358      field_sync_changed(m_field_sync);
359   }
360}
361 
362 
363 
364//-------------------------------------------------
365//  next_scanline
366//-------------------------------------------------
367 
368ATTR_FORCE_INLINE void mc6847_friend_device::next_scanline(void)
369{
370   /* advance to next scanline */
371   m_physical_scanline++;
372   m_logical_scanline++;
373 
374   /* check for movement into the next "zone" */
375   if (m_logical_scanline_zone == SCANLINE_ZONE_FRAME_END)
376   {
377      /* we're now in the top border */
378      m_logical_scanline = 0;
379      m_logical_scanline_zone = SCANLINE_ZONE_TOP_BORDER;
380   }
381   else if ((m_logical_scanline_zone < SCANLINE_ZONE_VBLANK) && (m_physical_scanline >= 25+192+26+6))
382   {
383      /* we're now into vblank */
384      m_logical_scanline = 0;
385      m_logical_scanline_zone = SCANLINE_ZONE_VBLANK;
386   }
387   else if ((m_logical_scanline_zone < SCANLINE_ZONE_RETRACE) && (m_physical_scanline >= 25+192+26))
388   {
389      /* we're now into retrace */
390      m_logical_scanline = 0;
391      m_logical_scanline_zone = SCANLINE_ZONE_RETRACE;
392   }
393   else if ((m_logical_scanline_zone == SCANLINE_ZONE_TOP_BORDER) && (m_logical_scanline >= m_top_border_scanlines))
394   {
395      /* we're now into the body */
396      m_logical_scanline = 0;
397      m_logical_scanline_zone = SCANLINE_ZONE_BODY;
398   }
399   else if ((m_logical_scanline_zone == SCANLINE_ZONE_BODY) && (m_logical_scanline >= m_body_scanlines))
400   {
401      /* we're now into the bottom border */
402      m_logical_scanline = 0;
403      m_logical_scanline_zone = SCANLINE_ZONE_BOTTOM_BORDER;
404      enter_bottom_border();
405   }
406}
407 
408 
409 
410//-------------------------------------------------
411//  horizontal_sync_changed
412//-------------------------------------------------
413 
414void mc6847_friend_device::horizontal_sync_changed(bool line)
415{
416}
417 
418 
419 
420//-------------------------------------------------
421//  field_sync_changed
422//-------------------------------------------------
423 
424void mc6847_friend_device::field_sync_changed(bool line)
425{
426}
427 
428 
429 
430//-------------------------------------------------
431//  enter_bottom_border
432//-------------------------------------------------
433 
434void mc6847_friend_device::enter_bottom_border(void)
435{
436}
437 
438 
439 
440//-------------------------------------------------
441//  record_border_scanline
442//-------------------------------------------------
443 
444void mc6847_friend_device::record_border_scanline(UINT16 physical_scanline)
445{
446}
447 
448 
449 
450//-------------------------------------------------
451//  video_flush
452//-------------------------------------------------
453 
454void mc6847_friend_device::video_flush(void)
455{
456}
457 
458 
459 
460//-------------------------------------------------
461//  describe_context
462//-------------------------------------------------
463 
464const char *mc6847_friend_device::describe_context(void)
465{
466   static char buffer[128];
467   snprintf(buffer, ARRAY_LENGTH(buffer), "%s (scanline %s:%d)",
468      machine().describe_context(),
469      scanline_zone_string((scanline_zone) m_logical_scanline_zone),
470      m_logical_scanline);
471   return buffer;
472}
473 
474 
475 
476//**************************************************************************
477//  BASE DEVICE
478//**************************************************************************
479 
480//-------------------------------------------------
481//  ctor
482//-------------------------------------------------
483 
484mc6847_base_device::mc6847_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const UINT8 *fontdata, double tpfs)
485   :   mc6847_friend_device(mconfig, type, name, tag, owner, clock, fontdata, (type == MC6847T1_NTSC) || (type == MC6847T1_PAL), tpfs, 25+191)
486{
487   m_palette = s_palette;
488 
489   for (int i = 0; i < ARRAY_LENGTH(s_palette); i++)
490   {
491      m_bw_palette[i] = black_and_white(s_palette[i]);
492   }
493}
494 
495 
496 
497//-------------------------------------------------
498//  setup_fixed_mode - sets up a particular video
499//   mode bit with a decb callback
500//-------------------------------------------------
501 
502void mc6847_base_device::setup_fixed_mode(struct devcb_read_line callback, UINT8 mode)
503{
504   if (callback.type == DEVCB_TYPE_NULL)
505   {
506      // do nothing
507   }
508   else if (callback.type == DEVCB_TYPE_CONSTANT && (callback.index == 0 || callback.index == 1))
509   {
510      // this mode is fixed
511      m_fixed_mode |= (callback.index ? mode : 0x00);
512      m_fixed_mode_mask |= mode;
513   }
514   else
515   {
516      // for reasons of performance, we currently only support DEVCB_NULL,
517      // DEVCB_LINE_GND and DEVCB_LINE_VCC
518      emu_fatalerror("mc6847 does not support this callback type for mode bits");
519   }
520}
521 
522 
523 
524//-------------------------------------------------
525//  device_start - device-specific startup
526//-------------------------------------------------
527 
528void mc6847_base_device::device_start()
529{
530   const mc6847_interface *config = (const mc6847_interface *) static_config();
531   assert(config);
532 
533   /* inherited function */
534   mc6847_friend_device::device_start();
535 
536   /* setup */
537   memset(m_data, 0, sizeof(m_data));
538 
539   /* resolve callbacks */
540   m_res_input_func.resolve(config->m_input_func, *this);
541   m_res_out_hsync_func.resolve(config->m_out_hsync_func, *this);
542   m_res_out_fsync_func.resolve(config->m_out_fsync_func, *this);
543   m_get_char_rom = config->m_get_char_rom;
544 
545   /* set up fixed mode */
546   m_fixed_mode = 0x00;
547   m_fixed_mode_mask = 0x00;
548   setup_fixed_mode(config->m_in_gm2_func,      MODE_GM2);
549   setup_fixed_mode(config->m_in_gm1_func,      MODE_GM1);
550   setup_fixed_mode(config->m_in_gm0_func,      MODE_GM0);
551   setup_fixed_mode(config->m_in_intext_func,   MODE_INTEXT);
552   setup_fixed_mode(config->m_in_inv_func,      MODE_INV);
553   setup_fixed_mode(config->m_in_as_func,      MODE_AS);
554   setup_fixed_mode(config->m_in_ag_func,      MODE_AG);
555   setup_fixed_mode(config->m_in_css_func,      MODE_CSS);
556 
557   /* state save */
558   save_item(NAME(m_dirty));
559   save_item(NAME(m_mode));
560 
561   /* colors */
562   m_palette = config->m_black_and_white ? m_bw_palette : s_palette;
563}
564 
565 
566 
567//-------------------------------------------------
568//  device_reset - device-specific reset
569//-------------------------------------------------
570 
571void mc6847_base_device::device_reset()
572{
573   mc6847_friend_device::device_reset();
574   m_mode = m_fixed_mode;
575}
576 
577 
578 
579//-------------------------------------------------
580//  record_scanline_res
581//-------------------------------------------------
582 
583template<int sample_count, int yres>
584void mc6847_base_device::record_scanline_res(int scanline)
585{
586   int i, column;
587   UINT8 data;
588 
589   /* calculate offset */
590   offs_t offset = scanline / (192 / yres) * sample_count;
591 
592   /* main loop */
593   for (column = 0; column < sample_count; column++)
594   {
595      /* input data */
596      data = m_res_input_func(offset++);
597 
598      /* update values */
599      update_value(&m_data[scanline].m_mode[column], simplify_mode(data, m_mode));
600      update_value(&m_data[scanline].m_data[column], data);
601   }
602 
603   /* several more inputs occur after hblank */
604   for (i = 0; i < sample_count * 5 / 16; i++)
605   {
606      data = m_res_input_func(offset++);
607   }
608 
609   /* update sample count */
610   update_value(&m_data[scanline].m_sample_count, (UINT8) sample_count);
611}
612 
613 
614 
615//-------------------------------------------------
616//  record_body_scanline
617//-------------------------------------------------
618 
619void mc6847_base_device::record_body_scanline(UINT16 physical_scanline, UINT16 scanline)
620{
621   // sanity checks
622   assert(scanline >= 0 && scanline < 192);
623 
624   if (m_mode & MODE_AG)
625   {
626      switch(m_mode & (MODE_GM2|MODE_GM1|MODE_GM0))
627      {
628         case 0:
629         case MODE_GM0:
630            record_scanline_res<16, 64>(scanline);
631            break;
632 
633         case MODE_GM1:
634            record_scanline_res<32, 64>(scanline);
635            break;
636 
637         case MODE_GM1|MODE_GM0:
638            record_scanline_res<16, 96>(scanline);
639            break;
640 
641         case MODE_GM2:
642            record_scanline_res<32, 96>(scanline);
643            break;
644 
645         case MODE_GM2|MODE_GM0:
646            record_scanline_res<16, 192>(scanline);
647            break;
648 
649         case MODE_GM2|MODE_GM1:
650         case MODE_GM2|MODE_GM1|MODE_GM0:
651            record_scanline_res<32, 192>(scanline);
652            break;
653 
654         default:
655            /* should not get here */
656            fatalerror("should not get here");
657            break;
658      }
659   }
660   else
661   {
662      record_scanline_res<32, 16>(scanline);
663   }
664}
665 
666 
667 
668//-------------------------------------------------
669//  field_sync_changed
670//-------------------------------------------------
671 
672void mc6847_base_device::field_sync_changed(bool line)
673{
674   /* when field sync is on, the DA* enter the Hi-Z state */
675   if (line && !m_res_input_func.isnull())
676      m_res_input_func(~0);
677}
678 
679 
680 
681//-------------------------------------------------
682//  border_value
683//-------------------------------------------------
684 
685ATTR_FORCE_INLINE mc6847_base_device::pixel_t mc6847_base_device::border_value(UINT8 mode, const pixel_t *palette, bool is_mc6847t1)
686{
687   pixel_t result;
688   switch(mc6847_friend_device::border_value(mode, is_mc6847t1))
689   {
690      case BORDER_COLOR_BLACK:
691         result = palette[8];
692         break;
693      case BORDER_COLOR_GREEN:
694         result = palette[0];
695         break;
696      case BORDER_COLOR_WHITE:
697         result = palette[4];
698         break;
699      case BORDER_COLOR_ORANGE:
700         result = palette[7];
701         break;
702      default:
703         fatalerror("Should not get here");
704         break;
705   }
706   return result;
707}
708 
709 
710 
711//-------------------------------------------------
712//  update
713//-------------------------------------------------
714 
715bool mc6847_base_device::update(bitmap_t *bitmap, const rectangle *cliprect)
716{
717   int base_x = 32;
718   int base_y = 25;
719   int x, x2, y;
720   bool is_mc6847t1 = (type() == MC6847T1_NTSC) || (type() == MC6847T1_PAL);
721   int min_x = USE_HORIZONTAL_CLIP ? cliprect->min_x : 0;
722   int max_x = USE_HORIZONTAL_CLIP ? cliprect->max_x : (base_x * 2 + 256 - 1);
723   int min_y = cliprect->min_y;
724   int max_y = cliprect->max_y;
725   const pixel_t *palette = m_palette;
726 
727   /* if the video didn't change, indicate as much */
728   if (!has_video_changed())
729      return UPDATE_HAS_NOT_CHANGED;
730 
731   /* top border */
732   for (y = min_y; y < base_y; y++)
733   {
734      for (x = min_x; x <= max_x; x++)
735      {
736         *bitmap_addr(bitmap, y, x) = border_value(m_data[0].m_mode[0], palette, is_mc6847t1);
737      }
738   }
739 
740   for (y = MAX(0, min_y - base_y); y <= MIN(192, max_y - base_y); y++)
741   {
742      /* left border */
743      for (x = min_x; x < base_x; x++)
744      {
745         *bitmap_addr(bitmap, y + base_y, x) = border_value(m_data[y].m_mode[0], palette, is_mc6847t1);
746      }
747 
748      /* body */
749      x = 0;
750      int width = m_data[y].m_sample_count;
751      pixel_t *RESTRICT pixels = bitmap_addr(bitmap, base_y + y, base_x);
752      while(x < width)
753      {
754         /* determine how many bytes exist for which the mode is identical */
755         for (x2 = x + 1; (x2 < width) && (m_data[y].m_mode[x] == m_data[y].m_mode[x2]); x2++)
756            ;
757 
758         /* emit the samples */
759         pixels += emit_mc6847_samples<1>(
760            m_data[y].m_mode[x],
761            &m_data[y].m_data[x],
762            x2 - x,
763            pixels,
764            m_palette,
765            m_get_char_rom,
766            x,
767            y);
768 
769         /* update x */
770         x = x2;
771      }
772 
773      /* right border */
774      for (x = base_x + 256; x <= max_x; x++)
775      {
776         *bitmap_addr(bitmap, y + base_y, x) = border_value(m_data[y].m_mode[width - 1], palette, is_mc6847t1);
777      }
778 
779      /* artifacting */
780      m_artifacter.process_artifacts<1>(bitmap_addr(bitmap, y + base_y, base_x), m_data[y].m_mode[0], palette);
781   }
782 
783   /* bottom border */
784   for (y = base_y + 192; y <= max_y; y++)
785   {
786      for (x = min_x; x <= max_x; x++)
787      {
788         int width = m_data[191].m_sample_count;
789         *bitmap_addr(bitmap, y, x) = border_value(m_data[191].m_mode[width - 1], palette, is_mc6847t1);
790      }
791   }
792   return 0;
793}
794 
795 
796 
797//**************************************************************************
798//  CHARACTER MAP
799//**************************************************************************
800 
801mc6847_friend_device::character_map::character_map(const UINT8 *text_fontdata, bool is_mc6847t1)
802{
803   int mode, i;
804 
805   // set up font data
806   for (i = 0; i < 64*12; i++)
807   {
808      m_text_fontdata_inverse[i]            = text_fontdata[i] ^ 0xFF;
809      m_text_fontdata_lower_case[i]         = text_fontdata[i + (i < 32*12 ? 64*12 : 0)] ^ (i < 32*12 ? 0xFF : 0x00);
810      m_text_fontdata_lower_case_inverse[i]   = m_text_fontdata_lower_case[i] ^ 0xFF;
811   }
812 
813   // loop through all modes
814   for (mode = 0; mode < sizeof(m_entries) / sizeof(m_entries[0]); mode++)
815   {
816      const UINT8 *fontdata;
817      UINT8 character_mask;
818      UINT8 color_shift_0 = 0;
819      UINT8 color_shift_1 = 0;
820      UINT8 color_mask_0 = 0x00;
821      UINT8 color_mask_1 = 0x00;
822      UINT16 color_base_0;
823      UINT16 color_base_1;
824 
825      if ((mode & MODE_INTEXT) && !is_mc6847t1)
826      {
827         // semigraphics 6
828         fontdata         = semigraphics6_fontdata8x12;
829         character_mask      = 0x3F;
830         color_base_0      = 8;
831         color_base_1      = mode & MODE_CSS ? 4 : 0;
832         color_shift_1      = 6;
833         color_mask_1      = 0x03;
834      }
835      else if (mode & MODE_AS)
836      {
837         // semigraphics 4
838         fontdata         = semigraphics4_fontdata8x12;
839         character_mask      = 0x0F;
840         color_base_0      = 8;
841         color_base_1      = 0;
842         color_shift_1      = 4;
843         color_mask_1      = 0x07;
844      }
845      else
846      {
847         // text
848         bool is_lower_case   = is_mc6847t1 && ((mode & MODE_INV) == 0) && (mode & MODE_GM0);
849         bool is_inverse1   = (mode & MODE_INV) ? true : false;
850         bool is_inverse2   = is_mc6847t1 && (mode & MODE_GM1);
851         bool is_inverse      = (is_inverse1 && !is_inverse2) || (!is_inverse1 && is_inverse2);
852         fontdata         = is_inverse
853                           ? (is_lower_case ? m_text_fontdata_lower_case_inverse : m_text_fontdata_inverse)
854                           : (is_lower_case ? m_text_fontdata_lower_case : text_fontdata);
855         character_mask      = 0x3F;
856         color_base_0      = (mode & MODE_CSS ? 14 : 12);
857         color_base_1      = (mode & MODE_CSS ? 15 : 13);
858      }
859 
860      // populate the entry
861      memset(&m_entries[mode], 0, sizeof(m_entries[mode]));
862      m_entries[mode].m_fontdata         = fontdata;
863      m_entries[mode].m_character_mask   = character_mask;
864      m_entries[mode].m_color_shift_0      = color_shift_0;
865      m_entries[mode].m_color_shift_1      = color_shift_1;
866      m_entries[mode].m_color_mask_0      = color_mask_0;
867      m_entries[mode].m_color_mask_1      = color_mask_1;
868      m_entries[mode].m_color_base_0      = color_base_0;
869      m_entries[mode].m_color_base_1      = color_base_1;
870   }
871}
872 
873 
874 
875//-------------------------------------------------
876//  pal_round_fontdata8x12
877//-------------------------------------------------
878 
879const UINT8 mc6847_friend_device::pal_round_fontdata8x12[] =
880{
881   0x00, 0x00, 0x38, 0x44, 0x04, 0x34, 0x4C, 0x4C, 0x38, 0x00, 0x00, 0x00,
882   0x00, 0x00, 0x10, 0x28, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x00, 0x00, 0x00,
883   0x00, 0x00, 0x78, 0x24, 0x24, 0x38, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
884   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
885   0x00, 0x00, 0x78, 0x24, 0x24, 0x24, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
886   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
887   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
888   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x4C, 0x44, 0x38, 0x00, 0x00, 0x00,
889   0x00, 0x00, 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
890   0x00, 0x00, 0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
891   0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
892   0x00, 0x00, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
893   0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
894   0x00, 0x00, 0x44, 0x6C, 0x54, 0x54, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
895   0x00, 0x00, 0x44, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x44, 0x00, 0x00, 0x00,
896   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
897   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
898   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
899   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
900   0x00, 0x00, 0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
901   0x00, 0x00, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
902   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
903   0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x00, 0x00, 0x00,
904   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x54, 0x6C, 0x44, 0x00, 0x00, 0x00,
905   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00, 0x00, 0x00,
906   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
907   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7C, 0x00, 0x00, 0x00,
908   0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00, 0x00,
909   0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00,
910   0x00, 0x00, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x00,
911   0x00, 0x00, 0x10, 0x38, 0x54, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
912   0x00, 0x00, 0x00, 0x10, 0x20, 0x7C, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00,
913   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
914   0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
915   0x00, 0x00, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
916   0x00, 0x00, 0x28, 0x28, 0x7C, 0x28, 0x7C, 0x28, 0x28, 0x00, 0x00, 0x00,
917   0x00, 0x00, 0x10, 0x3C, 0x50, 0x38, 0x14, 0x78, 0x10, 0x00, 0x00, 0x00,
918   0x00, 0x00, 0x60, 0x64, 0x08, 0x10, 0x20, 0x4C, 0x0C, 0x00, 0x00, 0x00,
919   0x00, 0x00, 0x20, 0x50, 0x50, 0x20, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
920   0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
921   0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
922   0x00, 0x00, 0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
923   0x00, 0x00, 0x00, 0x10, 0x54, 0x38, 0x38, 0x54, 0x10, 0x00, 0x00, 0x00,
924   0x00, 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
925   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x40, 0x00, 0x00,
926   0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
927   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
928   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00,
929   0x00, 0x00, 0x38, 0x44, 0x4C, 0x54, 0x64, 0x44, 0x38, 0x00, 0x00, 0x00,
930   0x00, 0x00, 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
931   0x00, 0x00, 0x38, 0x44, 0x04, 0x38, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
932   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
933   0x00, 0x00, 0x08, 0x18, 0x28, 0x48, 0x7C, 0x08, 0x08, 0x00, 0x00, 0x00,
934   0x00, 0x00, 0x7C, 0x40, 0x78, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
935   0x00, 0x00, 0x38, 0x40, 0x40, 0x78, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
936   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40, 0x00, 0x00, 0x00,
937   0x00, 0x00, 0x38, 0x44, 0x44, 0x38, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
938   0x00, 0x00, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x38, 0x00, 0x00, 0x00,
939   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
940   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00,
941   0x00, 0x00, 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
942   0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00,
943   0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
944   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
945 
946   /* Lower case */
947   0x00, 0x00, 0x18, 0x24, 0x20, 0x70, 0x20, 0x24, 0x78, 0x00, 0x00, 0x00,
948   0x00, 0x00, 0x00, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, 0x00, 0x00,
949   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x64, 0x58, 0x00, 0x00, 0x00,
950   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
951   0x00, 0x00, 0x04, 0x04, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
952   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00, 0x00, 0x00,
953   0x00, 0x00, 0x08, 0x14, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
954   0x00, 0x00, 0x00, 0x00, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x04, 0x38, 0x00,
955   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
956   0x00, 0x00, 0x10, 0x00, 0x30, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
957   0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00,
958   0x00, 0x00, 0x40, 0x40, 0x48, 0x50, 0x60, 0x50, 0x48, 0x00, 0x00, 0x00,
959   0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
960   0x00, 0x00, 0x00, 0x00, 0x78, 0x54, 0x54, 0x54, 0x54, 0x00, 0x00, 0x00,
961   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
962   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
963   0x00, 0x00, 0x00, 0x00, 0x78, 0x44, 0x44, 0x44, 0x78, 0x40, 0x40, 0x00,
964   0x00, 0x00, 0x00, 0x00, 0x3C, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x00,
965   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
966   0x00, 0x00, 0x00, 0x00, 0x3C, 0x40, 0x38, 0x04, 0x78, 0x00, 0x00, 0x00,
967   0x00, 0x00, 0x20, 0x20, 0x70, 0x20, 0x20, 0x24, 0x18, 0x00, 0x00, 0x00,
968   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
969   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00, 0x00, 0x00,
970   0x00, 0x00, 0x00, 0x00, 0x44, 0x54, 0x54, 0x28, 0x28, 0x00, 0x00, 0x00,
971   0x00, 0x00, 0x00, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00,
972   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x38, 0x00, 0x00,
973   0x00, 0x00, 0x00, 0x00, 0x7C, 0x08, 0x10, 0x20, 0x7C, 0x00, 0x00, 0x00,
974   0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,
975   0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
976   0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00,
977   0x00, 0x00, 0x20, 0x54, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
978   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00
979};
980 
981 
982 
983//-------------------------------------------------
984//  pal_square_fontdata8x12
985//-------------------------------------------------
986 
987const UINT8 mc6847_friend_device::pal_square_fontdata8x12[] =
988{
989   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1A, 0x2A, 0x2A, 0x1C, 0x00, 0x00,
990   0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x00, 0x00,
991   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x1C, 0x12, 0x12, 0x3C, 0x00, 0x00,
992   0x00, 0x00, 0x00, 0x1C, 0x22, 0x20, 0x20, 0x20, 0x22, 0x1C, 0x00, 0x00,
993   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x12, 0x12, 0x12, 0x3C, 0x00, 0x00,
994   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x3C, 0x20, 0x20, 0x3E, 0x00, 0x00,
995   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00,
996   0x00, 0x00, 0x00, 0x1E, 0x20, 0x20, 0x26, 0x22, 0x22, 0x1E, 0x00, 0x00,
997   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x22, 0x00, 0x00,
998   0x00, 0x00, 0x00, 0x1C, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
999   0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x22, 0x22, 0x1C, 0x00, 0x00,
1000   0x00, 0x00, 0x00, 0x22, 0x24, 0x28, 0x30, 0x28, 0x24, 0x22, 0x00, 0x00,
1001   0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3E, 0x00, 0x00,
1002   0x00, 0x00, 0x00, 0x22, 0x36, 0x2A, 0x2A, 0x22, 0x22, 0x22, 0x00, 0x00,
1003   0x00, 0x00, 0x00, 0x22, 0x32, 0x2A, 0x26, 0x22, 0x22, 0x22, 0x00, 0x00,
1004   0x00, 0x00, 0x00, 0x3E, 0x22, 0x22, 0x22, 0x22, 0x22, 0x3E, 0x00, 0x00,
1005   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00,
1006   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x2A, 0x24, 0x1A, 0x00, 0x00,
1007   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x28, 0x24, 0x22, 0x00, 0x00,
1008   0x00, 0x00, 0x00, 0x1C, 0x22, 0x10, 0x08, 0x04, 0x22, 0x1C, 0x00, 0x00,
1009   0x00, 0x00, 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1010   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
1011   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00,
1012   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x2A, 0x2A, 0x36, 0x22, 0x00, 0x00,
1013   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00, 0x00,
1014   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1015   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x3E, 0x00, 0x00,
1016   0x00, 0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00,
1017   0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x00, 0x00,
1018   0x00, 0x00, 0x00, 0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0E, 0x00, 0x00,
1019   0x00, 0x00, 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1020   0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x3E, 0x10, 0x08, 0x00, 0x00, 0x00,
1021   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1022   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
1023   0x00, 0x00, 0x00, 0x14, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1024   0x00, 0x00, 0x00, 0x14, 0x14, 0x36, 0x00, 0x36, 0x14, 0x14, 0x00, 0x00,
1025   0x00, 0x00, 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08, 0x00, 0x00,
1026   0x00, 0x00, 0x00, 0x32, 0x32, 0x04, 0x08, 0x10, 0x26, 0x26, 0x00, 0x00,
1027   0x00, 0x00, 0x00, 0x10, 0x28, 0x28, 0x10, 0x2A, 0x24, 0x1A, 0x00, 0x00,
1028   0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1029   0x00, 0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00,
1030   0x00, 0x00, 0x00, 0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08, 0x00, 0x00,
1031   0x00, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x3E, 0x1C, 0x08, 0x00, 0x00, 0x00,
1032   0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x00,
1033   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x10, 0x20, 0x00, 0x00,
1034   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
1035   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00,
1036   0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
1037   0x00, 0x00, 0x00, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18, 0x00, 0x00,
1038   0x00, 0x00, 0x00, 0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
1039   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1C, 0x20, 0x20, 0x3E, 0x00, 0x00,
1040   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x0C, 0x02, 0x22, 0x1C, 0x00, 0x00,
1041   0x00, 0x00, 0x00, 0x04, 0x0C, 0x14, 0x3E, 0x04, 0x04, 0x04, 0x00, 0x00,
1042   0x00, 0x00, 0x00, 0x3E, 0x20, 0x3C, 0x02, 0x02, 0x22, 0x1C, 0x00, 0x00,
1043   0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x1C, 0x00, 0x00,
1044   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
1045   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1C, 0x22, 0x22, 0x1C, 0x00, 0x00,
1046   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1E, 0x02, 0x02, 0x1C, 0x00, 0x00,
1047   0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
1048   0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00,
1049   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00,
1050   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00,
1051   0x00, 0x00, 0x00, 0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10, 0x00, 0x00,
1052   0x00, 0x00, 0x00, 0x18, 0x24, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
1053 
1054   /* Lower case */
1055   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x12, 0x3C, 0x00, 0x00,
1056   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x02, 0x1E, 0x22, 0x1E, 0x00, 0x00,
1057   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x00, 0x00,
1058   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x20, 0x1C, 0x00, 0x00,
1059   0x00, 0x00, 0x00, 0x02, 0x02, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x00, 0x00,
1060   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x3E, 0x20, 0x1C, 0x00, 0x00,
1061   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00,
1062   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
1063   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00,
1064   0x00, 0x00, 0x00, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
1065   0x00, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x24, 0x18,
1066   0x00, 0x00, 0x00, 0x20, 0x20, 0x24, 0x28, 0x38, 0x24, 0x22, 0x00, 0x00,
1067   0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
1068   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x2A, 0x2A, 0x2A, 0x2A, 0x00, 0x00,
1069   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x22, 0x22, 0x22, 0x00, 0x00,
1070   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
1071   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x20, 0x20,
1072   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x03,
1073   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00,
1074   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x00, 0x00,
1075   0x00, 0x00, 0x00, 0x10, 0x3C, 0x10, 0x10, 0x10, 0x12, 0x0C, 0x00, 0x00,
1076   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x26, 0x1A, 0x00, 0x00,
1077   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x14, 0x08, 0x00, 0x00,
1078   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x2A, 0x2A, 0x1C, 0x14, 0x00, 0x00,
1079   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00, 0x00,
1080   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
1081   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x04, 0x08, 0x10, 0x3E, 0x00, 0x00,
1082   0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00,
1083   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00,
1084   0x00, 0x00, 0x00, 0x08, 0x04, 0x04, 0x02, 0x04, 0x04, 0x08, 0x00, 0x00,
1085   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x00,
1086   0x00, 0x00, 0x00, 0x08, 0x04, 0x3E, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00,
1087};
1088 
1089 
1090 
1091//-------------------------------------------------
1092//  ntsc_round_fontdata8x12
1093//-------------------------------------------------
1094 
1095const UINT8 mc6847_friend_device::ntsc_round_fontdata8x12[] =
1096{
1097   0x00, 0x00, 0x38, 0x44, 0x04, 0x34, 0x4C, 0x4C, 0x38, 0x00, 0x00, 0x00,
1098   0x00, 0x00, 0x10, 0x28, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x00, 0x00, 0x00,
1099   0x00, 0x00, 0x78, 0x24, 0x24, 0x38, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
1100   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
1101   0x00, 0x00, 0x78, 0x24, 0x24, 0x24, 0x24, 0x24, 0x78, 0x00, 0x00, 0x00,
1102   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
1103   0x00, 0x00, 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
1104   0x00, 0x00, 0x38, 0x44, 0x40, 0x40, 0x4C, 0x44, 0x38, 0x00, 0x00, 0x00,
1105   0x00, 0x00, 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
1106   0x00, 0x00, 0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
1107   0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
1108   0x00, 0x00, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
1109   0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
1110   0x00, 0x00, 0x44, 0x6C, 0x54, 0x54, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
1111   0x00, 0x00, 0x44, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x44, 0x00, 0x00, 0x00,
1112   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
1113   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
1114   0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
1115   0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44, 0x00, 0x00, 0x00,
1116   0x00, 0x00, 0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
1117   0x00, 0x00, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
1118   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
1119   0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x00, 0x00, 0x00,
1120   0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x54, 0x6C, 0x44, 0x00, 0x00, 0x00,
1121   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00, 0x00, 0x00,
1122   0x00, 0x00, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
1123   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7C, 0x00, 0x00, 0x00,
1124   0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00, 0x00,
1125   0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00,
1126   0x00, 0x00, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x00,
1127   0x00, 0x00, 0x10, 0x38, 0x54, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
1128   0x00, 0x00, 0x00, 0x10, 0x20, 0x7C, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00,
1129   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1130   0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
1131   0x00, 0x00, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1132   0x00, 0x00, 0x28, 0x28, 0x7C, 0x28, 0x7C, 0x28, 0x28, 0x00, 0x00, 0x00,
1133   0x00, 0x00, 0x10, 0x3C, 0x50, 0x38, 0x14, 0x78, 0x10, 0x00, 0x00, 0x00,
1134   0x00, 0x00, 0x60, 0x64, 0x08, 0x10, 0x20, 0x4C, 0x0C, 0x00, 0x00, 0x00,
1135   0x00, 0x00, 0x20, 0x50, 0x50, 0x20, 0x54, 0x48, 0x34, 0x00, 0x00, 0x00,
1136   0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1137   0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
1138   0x00, 0x00, 0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
1139   0x00, 0x00, 0x00, 0x10, 0x54, 0x38, 0x38, 0x54, 0x10, 0x00, 0x00, 0x00,
1140   0x00, 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
1141   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x40, 0x00, 0x00,
1142   0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1143   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
1144   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00,
1145   0x00, 0x00, 0x38, 0x44, 0x4C, 0x54, 0x64, 0x44, 0x38, 0x00, 0x00, 0x00,
1146   0x00, 0x00, 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
1147   0x00, 0x00, 0x38, 0x44, 0x04, 0x38, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00,
1148   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
1149   0x00, 0x00, 0x08, 0x18, 0x28, 0x48, 0x7C, 0x08, 0x08, 0x00, 0x00, 0x00,
1150   0x00, 0x00, 0x7C, 0x40, 0x78, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00, 0x00,
1151   0x00, 0x00, 0x38, 0x40, 0x40, 0x78, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
1152   0x00, 0x00, 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40, 0x00, 0x00, 0x00,
1153   0x00, 0x00, 0x38, 0x44, 0x44, 0x38, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
1154   0x00, 0x00, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x38, 0x00, 0x00, 0x00,
1155   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
1156   0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x20, 0x00, 0x00,
1157   0x00, 0x00, 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00,
1158   0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00,
1159   0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00,
1160   0x00, 0x00, 0x38, 0x44, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
1161 
1162   /* Lower case */
1163   0x00, 0x00, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1164   0x00, 0x00, 0x00, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, 0x00, 0x00,
1165   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x64, 0x58, 0x00, 0x00, 0x00,
1166   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x00, 0x00, 0x00,
1167   0x00, 0x00, 0x04, 0x04, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
1168   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00, 0x00, 0x00,
1169   0x00, 0x00, 0x08, 0x14, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
1170   0x00, 0x00, 0x00, 0x00, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x04, 0x38, 0x00,
1171   0x00, 0x00, 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
1172   0x00, 0x00, 0x10, 0x00, 0x30, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
1173   0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00, 0x00,
1174   0x00, 0x00, 0x40, 0x40, 0x48, 0x50, 0x60, 0x50, 0x48, 0x00, 0x00, 0x00,
1175   0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00,
1176   0x00, 0x00, 0x00, 0x00, 0x78, 0x54, 0x54, 0x54, 0x54, 0x00, 0x00, 0x00,
1177   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00,
1178   0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00,
1179   0x00, 0x00, 0x00, 0x00, 0x78, 0x44, 0x44, 0x44, 0x78, 0x40, 0x40, 0x00,
1180   0x00, 0x00, 0x00, 0x00, 0x3C, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x04, 0x00,
1181   0x00, 0x00, 0x00, 0x00, 0x58, 0x64, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00,
1182   0x00, 0x00, 0x00, 0x00, 0x3C, 0x40, 0x38, 0x04, 0x78, 0x00, 0x00, 0x00,
1183   0x00, 0x00, 0x20, 0x20, 0x70, 0x20, 0x20, 0x24, 0x18, 0x00, 0x00, 0x00,
1184   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x4C, 0x34, 0x00, 0x00, 0x00,
1185   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00, 0x00, 0x00,
1186   0x00, 0x00, 0x00, 0x00, 0x44, 0x54, 0x54, 0x28, 0x28, 0x00, 0x00, 0x00,
1187   0x00, 0x00, 0x00, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00,
1188   0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x38, 0x00, 0x00,
1189   0x00, 0x00, 0x00, 0x00, 0x7C, 0x08, 0x10, 0x20, 0x7C, 0x00, 0x00, 0x00,
1190   0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00,
1191   0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00,
1192   0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00,
1193   0x00, 0x00, 0x20, 0x54, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1194   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00,
1195};
1196 
1197 
1198 
1199//-------------------------------------------------
1200//  ntsc_square_fontdata8x12
1201//-------------------------------------------------
1202 
1203const UINT8 mc6847_friend_device::ntsc_square_fontdata8x12[] =
1204{
1205   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1A, 0x2A, 0x2A, 0x1C, 0x00, 0x00,
1206   0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x00, 0x00,
1207   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x1C, 0x12, 0x12, 0x3C, 0x00, 0x00,
1208   0x00, 0x00, 0x00, 0x1C, 0x22, 0x20, 0x20, 0x20, 0x22, 0x1C, 0x00, 0x00,
1209   0x00, 0x00, 0x00, 0x3C, 0x12, 0x12, 0x12, 0x12, 0x12, 0x3C, 0x00, 0x00,
1210   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x38, 0x20, 0x20, 0x3E, 0x00, 0x00,
1211   0x00, 0x00, 0x00, 0x3E, 0x20, 0x20, 0x38, 0x20, 0x20, 0x20, 0x00, 0x00,
1212   0x00, 0x00, 0x00, 0x1E, 0x20, 0x20, 0x26, 0x22, 0x22, 0x1E, 0x00, 0x00,
1213   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x22, 0x00, 0x00,
1214   0x00, 0x00, 0x00, 0x1C, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
1215   0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x22, 0x22, 0x1C, 0x00, 0x00,
1216   0x00, 0x00, 0x00, 0x22, 0x24, 0x28, 0x30, 0x28, 0x24, 0x22, 0x00, 0x00,
1217   0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3E, 0x00, 0x00,
1218   0x00, 0x00, 0x00, 0x22, 0x36, 0x2A, 0x2A, 0x22, 0x22, 0x22, 0x00, 0x00,
1219   0x00, 0x00, 0x00, 0x22, 0x32, 0x2A, 0x26, 0x22, 0x22, 0x22, 0x00, 0x00,
1220   0x00, 0x00, 0x00, 0x3E, 0x22, 0x22, 0x22, 0x22, 0x22, 0x3E, 0x00, 0x00,
1221   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00,
1222   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x2A, 0x24, 0x1A, 0x00, 0x00,
1223   0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x3C, 0x28, 0x24, 0x22, 0x00, 0x00,
1224   0x00, 0x00, 0x00, 0x1C, 0x22, 0x10, 0x08, 0x04, 0x22, 0x1C, 0x00, 0x00,
1225   0x00, 0x00, 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1226   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
1227   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00,
1228   0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x2A, 0x2A, 0x36, 0x22, 0x00, 0x00,
1229   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00, 0x00,
1230   0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1231   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x3E, 0x00, 0x00,
1232   0x00, 0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, 0x00,
1233   0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x00, 0x00,
1234   0x00, 0x00, 0x00, 0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0E, 0x00, 0x00,
1235   0x00, 0x00, 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1236   0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x3E, 0x10, 0x08, 0x00, 0x00, 0x00,
1237   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1238   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
1239   0x00, 0x00, 0x00, 0x14, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1240   0x00, 0x00, 0x00, 0x14, 0x14, 0x36, 0x00, 0x36, 0x14, 0x14, 0x00, 0x00,
1241   0x00, 0x00, 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08, 0x00, 0x00,
1242   0x00, 0x00, 0x00, 0x32, 0x32, 0x04, 0x08, 0x10, 0x26, 0x26, 0x00, 0x00,
1243   0x00, 0x00, 0x00, 0x10, 0x28, 0x28, 0x10, 0x2A, 0x24, 0x1A, 0x00, 0x00,
1244   0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1245   0x00, 0x00, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, 0x00,
1246   0x00, 0x00, 0x00, 0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08, 0x00, 0x00,
1247   0x00, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x3E, 0x1C, 0x08, 0x00, 0x00, 0x00,
1248   0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x00,
1249   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x10, 0x20, 0x00, 0x00,
1250   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
1251   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00,
1252   0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
1253   0x00, 0x00, 0x00, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18, 0x00, 0x00,
1254   0x00, 0x00, 0x00, 0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
1255   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x1C, 0x20, 0x20, 0x3E, 0x00, 0x00,
1256   0x00, 0x00, 0x00, 0x1C, 0x22, 0x02, 0x04, 0x02, 0x22, 0x1C, 0x00, 0x00,
1257   0x00, 0x00, 0x00, 0x04, 0x0C, 0x14, 0x3E, 0x04, 0x04, 0x04, 0x00, 0x00,
1258   0x00, 0x00, 0x00, 0x3E, 0x20, 0x3C, 0x02, 0x02, 0x22, 0x1C, 0x00, 0x00,
1259   0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x1C, 0x00, 0x00,
1260   0x00, 0x00, 0x00, 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00, 0x00,
1261   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1C, 0x22, 0x22, 0x1C, 0x00, 0x00,
1262   0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x1E, 0x02, 0x02, 0x1C, 0x00, 0x00,
1263   0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
1264   0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00,
1265   0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00,
1266   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00,
1267   0x00, 0x00, 0x00, 0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10, 0x00, 0x00,
1268   0x00, 0x00, 0x00, 0x18, 0x24, 0x04, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00,
1269 
1270   /* Lower case */
1271   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x12, 0x3C, 0x00, 0x00,
1272   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x02, 0x1E, 0x22, 0x1E, 0x00, 0x00,
1273   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x00, 0x00,
1274   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x20, 0x20, 0x20, 0x1C, 0x00, 0x00,
1275   0x00, 0x00, 0x00, 0x02, 0x02, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x00, 0x00,
1276   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x3E, 0x20, 0x1C, 0x00, 0x00,
1277   0x00, 0x00, 0x00, 0x0C, 0x12, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00, 0x00,
1278   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
1279   0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00,
1280   0x00, 0x00, 0x00, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
1281   0x00, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x24, 0x18,
1282   0x00, 0x00, 0x00, 0x20, 0x20, 0x24, 0x28, 0x38, 0x24, 0x22, 0x00, 0x00,
1283   0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x00, 0x00,
1284   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x2A, 0x2A, 0x2A, 0x2A, 0x00, 0x00,
1285   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x22, 0x22, 0x22, 0x00, 0x00,
1286   0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x00,
1287   0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x22, 0x22, 0x22, 0x3C, 0x20, 0x20,
1288   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x03,
1289   0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00,
1290   0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x00, 0x00,
1291   0x00, 0x00, 0x00, 0x10, 0x3C, 0x10, 0x10, 0x10, 0x12, 0x0C, 0x00, 0x00,
1292   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x26, 0x1A, 0x00, 0x00,
1293   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x14, 0x08, 0x00, 0x00,
1294   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x2A, 0x2A, 0x1C, 0x14, 0x00, 0x00,
1295   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00, 0x00,
1296   0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1E, 0x02, 0x1C,
1297   0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x04, 0x08, 0x10, 0x3E, 0x00, 0x00,
1298   0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00, 0x00,
1299   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00,
1300   0x00, 0x00, 0x00, 0x08, 0x04, 0x04, 0x02, 0x04, 0x04, 0x08, 0x00, 0x00,
1301   0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x00,
1302   0x00, 0x00, 0x00, 0x08, 0x04, 0x3E, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00
1303};
1304 
1305 
1306 
1307//-------------------------------------------------
1308//  semigraphics4_fontdata8x12
1309//-------------------------------------------------
1310 
1311const UINT8 mc6847_friend_device::semigraphics4_fontdata8x12[] =
1312{
1313   /* Block Graphics (Semigraphics 4 Graphics ) */
1314   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1315   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
1316   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
1317   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1318   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1319   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
1320   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
1321   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1322   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1323   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
1324   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
1325   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1326   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1327   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
1328   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
1329   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
1330};
1331 
1332 
1333 
1334//-------------------------------------------------
1335//  semigraphics6_fontdata8x12
1336//-------------------------------------------------
1337 
1338const UINT8 mc6847_friend_device::semigraphics6_fontdata8x12[] =
1339{
1340   /* Semigraphics 6 */
1341   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1342   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
1343   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
1344   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
1345   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
1346   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
1347   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
1348   0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
1349   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
1350   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
1351   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
1352   0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
1353   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
1354   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
1355   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
1356   0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1357   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1358   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
1359   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
1360   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
1361   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
1362   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
1363   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
1364   0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
1365   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
1366   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
1367   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
1368   0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
1369   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
1370   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
1371   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
1372   0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1373   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1374   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
1375   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
1376   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
1377   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
1378   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
1379   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
1380   0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
1381   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
1382   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
1383   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
1384   0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
1385   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
1386   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
1387   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
1388   0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1389   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1390   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
1391   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0,
1392   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
1393   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00,
1394   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
1395   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,
1396   0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF,
1397   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00,
1398   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F,
1399   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
1400   0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
1401   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
1402   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F,
1403   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
1404   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
1405};
1406 
1407 
1408 
1409//**************************************************************************
1410//  ARTIFACTING
1411//**************************************************************************
1412 
1413INPUT_PORTS_START(mc6847_artifacting)
1414   PORT_START(ARTIFACTING_TAG)
1415   PORT_CONFNAME( 0x03, 0x01, "Artifacting" )
1416   PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
1417   PORT_CONFSETTING(    0x01, DEF_STR( Standard ) )
1418   PORT_CONFSETTING(    0x02, DEF_STR( Reverse ) )
1419INPUT_PORTS_END
1420 
1421ioport_constructor mc6847_base_device::device_input_ports() const
1422{
1423   return INPUT_PORTS_NAME(mc6847_artifacting);
1424}
1425 
1426 
1427 
1428//-------------------------------------------------
1429//  ctor
1430//-------------------------------------------------
1431 
1432mc6847_base_device::artifacter::artifacter()
1433{
1434   m_config = NULL;
1435   m_artifacting = 0;
1436   m_saved_artifacting = 0;
1437   m_saved_c0 = 0;
1438   m_saved_c1 = 0;
1439   memset(m_expanded_colors, 0, sizeof(m_expanded_colors));
1440}
1441 
1442 
1443 
1444//-------------------------------------------------
1445//  artifacter::setup_config
1446//-------------------------------------------------
1447 
1448void mc6847_base_device::artifacter::setup_config(device_t *device)
1449{
1450   char port_name[32];
1451   snprintf(port_name, ARRAY_LENGTH(port_name), "%s:%s", device->tag(), ARTIFACTING_TAG);
1452   m_config = device->machine().port(port_name);
1453}
1454 
1455 
1456 
1457//-------------------------------------------------
1458//  artifacter::update_colors
1459//-------------------------------------------------
1460 
1461void mc6847_base_device::artifacter::update_colors(pixel_t c0, pixel_t c1)
1462{
1463   /* Boy this code sucks; this code was adapted from the old M6847
1464     * artifacting implmentation.  The only reason that it didn't look as
1465     * horrible was because the code around it sucked as well.  Now that I
1466     * have cleaned everything up, the ugliness is much more prominent.
1467     *
1468     * Hopefully we will have a generic artifacting algorithm that plugs into
1469     * the MESS/MAME core directly so we can chuck this hack */
1470   static const double artifact_colors[14*3] =
1471   {
1472      0.157, 0.000, 0.157, /* [ 1] - dk purple   (reverse  2) */
1473      0.000, 0.157, 0.000, /* [ 2] - dk green    (reverse  1) */
1474      1.000, 0.824, 1.000, /* [ 3] - lt purple   (reverse  4) */
1475      0.824, 1.000, 0.824, /* [ 4] - lt green    (reverse  3) */
1476      0.706, 0.236, 0.118, /* [ 5] - dk blue     (reverse  6) */
1477      0.000, 0.197, 0.471, /* [ 6] - dk red      (reverse  5) */
1478      1.000, 0.550, 0.393, /* [ 7] - lt blue     (reverse  8) */
1479      0.275, 0.785, 1.000, /* [ 8] - lt red      (reverse  7) */
1480      0.000, 0.500, 1.000, /* [ 9] - red         (reverse 10) */
1481      1.000, 0.500, 0.000, /* [10] - blue        (reverse  9) */
1482      1.000, 0.942, 0.785, /* [11] - cyan        (reverse 12) */
1483      0.393, 0.942, 1.000, /* [12] - yellow      (reverse 11) */
1484      0.236, 0.000, 0.000, /* [13] - black-blue  (reverse 14) */
1485      0.000, 0.000, 0.236  /* [14] - black-red   (reverse 13) */
1486   };
1487 
1488   static const UINT8 artifact_correction[128] =
1489   {
1490      0,  0,       0,    0,       0,  6,       0,    2,
1491      5,  7,       5,    7,       1,  3,       1, 11,
1492      8,  6,       8, 14,       8,  9,       8,    9,
1493      4,  4,       4, 15,      12, 12,      12, 15,
1494 
1495      5, 13,       5, 13,      13,  0,      13,    2,
1496      10, 10,      10, 10,      10, 15,      10, 11,
1497      3,  1,       3,    1,      15,  9,      15,    9,
1498      11, 11,      11, 11,      15, 15,      15, 15,
1499 
1500      14,  0,      14,    0,      14,  6,      14,    2,
1501      0,  7,       0,    7,       1,  3,       1, 11,
1502      9,  6,       9, 14,       9,  9,       9,    9,
1503      15,  4,      15, 15,      12, 12,      12, 15,
1504 
1505      2, 13,       2, 13,       2,  0,       2,    2,
1506      10, 10,      10, 10,      10, 15,      10, 11,
1507      12,  1,      12,    1,      12,  9,      12,    9,
1508      15, 11,      15, 11,      15, 15,      15, 15
1509   };
1510 
1511   pixel_t colors[16];
1512   int i;
1513 
1514   /* do we need to update our artifact colors table? */
1515   if ((m_artifacting != m_saved_artifacting) || (c0 != m_saved_c0) || (c1 != m_saved_c1))
1516   {
1517      m_saved_artifacting = m_artifacting;
1518      m_saved_c0 = colors[0] = c0;
1519      m_saved_c1 = colors[15] = c1;
1520 
1521      /* mix the other colors */
1522      for (i = 1; i <= 14; i++)
1523      {
1524         const double *factors = &artifact_colors[((i - 1) ^ (m_artifacting & 0x01)) * 3];
1525 
1526         colors[i] =   (mix_color(factors[0], c0 >> 16, c1 >> 16) << 16)
1527               |   (mix_color(factors[1], c0 >>  8, c1 >>  8) <<  8)
1528               |   (mix_color(factors[2], c0 >>  0, c1 >>  0) <<  0);
1529      }
1530      for (i = 0; i < 128; i++)
1531      {
1532         m_expanded_colors[i] = colors[artifact_correction[i]];
1533      }
1534   }
1535}
1536 
1537 
1538 
1539//-------------------------------------------------
1540//  artifacter::update
1541//-------------------------------------------------
1542 
1543mc6847_base_device::pixel_t mc6847_base_device::artifacter::mix_color(double factor, UINT8 c0, UINT8 c1)
1544{
1545   return (UINT32) (UINT8) ((c0 * (1.0 - factor)) + (c1 * (0.0 + factor)) + 0.5);
1546}
1547 
1548 
1549 
1550//**************************************************************************
1551//  VARIATIONS
1552//**************************************************************************
1553 
1554const device_type MC6847_NTSC = &device_creator<mc6847_ntsc_device>;
1555const device_type MC6847_PAL = &device_creator<mc6847_pal_device>;
1556const device_type MC6847Y_NTSC = &device_creator<mc6847y_ntsc_device>;
1557const device_type MC6847Y_PAL = &device_creator<mc6847y_pal_device>;
1558const device_type MC6847T1_NTSC = &device_creator<mc6847t1_ntsc_device>;
1559const device_type MC6847T1_PAL = &device_creator<mc6847t1_pal_device>;
1560 
1561 
1562 
1563//-------------------------------------------------
1564//  mc6847_ntsc_device
1565//-------------------------------------------------
1566 
1567mc6847_ntsc_device::mc6847_ntsc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1568   : mc6847_base_device(mconfig, MC6847_NTSC, "MC6847_NTSC", tag, owner, clock, ntsc_square_fontdata8x12, 227.0)
1569{
1570}
1571 
1572 
1573 
1574//-------------------------------------------------
1575//  mc6847_pal_device
1576//-------------------------------------------------
1577 
1578mc6847_pal_device::mc6847_pal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1579   : mc6847_base_device(mconfig, MC6847_PAL, "MC6847_PAL", tag, owner, clock, pal_square_fontdata8x12, 227.0)
1580{
1581}
1582 
1583 
1584 
1585//-------------------------------------------------
1586//  mc6847y_ntsc_device
1587//-------------------------------------------------
1588 
1589mc6847y_ntsc_device::mc6847y_ntsc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1590   : mc6847_base_device(mconfig, MC6847Y_NTSC, "MC6847Y_NTSC", tag, owner, clock, ntsc_square_fontdata8x12, 227.5)
1591{
1592}
1593 
1594 
1595 
1596//-------------------------------------------------
1597//  mc6847y_pal_device
1598//-------------------------------------------------
1599 
1600mc6847y_pal_device::mc6847y_pal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1601   : mc6847_base_device(mconfig, MC6847Y_PAL, "MC6847Y_PAL", tag, owner, clock, pal_square_fontdata8x12, 227.5)
1602{
1603}
1604 
1605 
1606 
1607//-------------------------------------------------
1608//  mc6847t1_ntsc_device
1609//-------------------------------------------------
1610 
1611mc6847t1_ntsc_device::mc6847t1_ntsc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1612   : mc6847_base_device(mconfig, MC6847T1_NTSC, "MC6847T1_NTSC", tag, owner, clock, ntsc_round_fontdata8x12, 227.0)
1613{
1614}
1615 
1616 
1617 
1618//-------------------------------------------------
1619//  mc6847t1_pal_device
1620//-------------------------------------------------
1621 
1622mc6847t1_pal_device::mc6847t1_pal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1623   : mc6847_base_device(mconfig, MC6847T1_PAL, "MC6847T1_PAL", tag, owner, clock, pal_round_fontdata8x12, 227.0)
1624{
1625}
1626 
1627 
1628 
src/mess/video/mc6847.h
r0r13257
1/*********************************************************************
2 
3    mc6847.h
4 
5    Implementation of Motorola 6847 video hardware chip
6 
7***************************************************************************/
8 
9#pragma once
10 
11#ifndef __MC6847__
12#define __MC6847__
13 
14 
15//**************************************************************************
16//  MC6847 CONFIGURATION / INTERFACE
17//**************************************************************************
18 
19#define MCFG_MC6847_REMOVE(_tag) \
20   MCFG_DEVICE_REMOVE(_tag)
21 
22#define MCFG_MC6847_ADD(_tag, _variant, _clock, _config)      \
23   MCFG_DEVICE_ADD(_tag, _variant, _clock)                  \
24   MCFG_DEVICE_CONFIG(_config)
25 
26#define MCFG_SCREEN_MC6847_NTSC_ADD(_tag) \
27   MCFG_SCREEN_ADD(_tag, RASTER)                        \
28   MCFG_SCREEN_REFRESH_RATE(60)                        \
29   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)                  \
30   MCFG_SCREEN_SIZE(320, 243)                           \
31   MCFG_SCREEN_VISIBLE_AREA(0, 320-1, 1, 241-1)            \
32   MCFG_SCREEN_VBLANK_TIME(0)                           \
33 
34#define MCFG_SCREEN_MC6847_PAL_ADD(_tag) \
35   MCFG_SCREEN_ADD(_tag, RASTER)                        \
36   MCFG_SCREEN_REFRESH_RATE(50)                        \
37   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)                  \
38   MCFG_SCREEN_SIZE(320, 243)                           \
39   MCFG_SCREEN_VISIBLE_AREA(0, 320-1, 1, 241-1)            \
40   MCFG_SCREEN_VBLANK_TIME(0)                           \
41 
42/* interface */
43typedef struct _mc6847_interface mc6847_interface;
44struct _mc6847_interface
45{
46   /* screen we are acting on */
47   const char *m_screen_tag;
48 
49   /* if specified, this gets called whenever reading a byte (offs_t ~0 specifies DA* entering the tristate mode) */
50   devcb_read8               m_input_func;
51 
52   /* if specified, this gets called for every change of the HS pin (pin 38) */
53   devcb_write_line         m_out_hsync_func;
54 
55   /* if specified, this gets called for every change of the FS pin (pin 37) */
56   devcb_write_line         m_out_fsync_func;
57 
58   /* mode control lines input */
59   devcb_read_line          m_in_ag_func;
60   devcb_read_line            m_in_gm2_func;
61   devcb_read_line            m_in_gm1_func;
62   devcb_read_line          m_in_gm0_func;
63   devcb_read_line          m_in_css_func;
64   devcb_read_line          m_in_as_func;
65   devcb_read_line          m_in_intext_func;
66   devcb_read_line          m_in_inv_func;
67 
68   /* if specified, this reads the external char rom off of the driver state */
69   UINT8 (*m_get_char_rom)(running_machine &machine, UINT8 ch, int line);
70 
71   /* if true, this is black and white */
72   bool                  m_black_and_white;
73};
74 
75#define   ARTIFACTING_TAG      "artifacting"
76 
77INPUT_PORTS_EXTERN(mc6847_artifacting);
78 
79 
80//**************************************************************************
81//  MC6847 CORE
82//**************************************************************************
83 
84PALETTE_INIT( mc6847 );
85PALETTE_INIT( mc6847_bw );
86 
87// base class so that the GIME emulation can access mc6847 stuff
88class mc6847_friend_device : public device_t
89{
90public:
91   // inlines
92   bool hs_r(void)               { return m_horizontal_sync; }
93   bool fs_r(void)               { return m_field_sync; }
94 
95protected:
96   mc6847_friend_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock,
97      const UINT8 *fontdata, bool is_mc6847t1, double tpfs, int field_sync_falling_edge_scanline);
98 
99   // video mode constants
100   static const UINT8 MODE_AG      = 0x80;
101   static const UINT8 MODE_GM2      = 0x40;
102   static const UINT8 MODE_GM1      = 0x20;
103   static const UINT8 MODE_GM0      = 0x10;
104   static const UINT8 MODE_CSS      = 0x08;
105   static const UINT8 MODE_AS      = 0x04;
106   static const UINT8 MODE_INTEXT   = 0x02;
107   static const UINT8 MODE_INV      = 0x01;
108 
109   // timer constants
110   static const device_timer_id TIMER_FRAME = 0;
111   static const device_timer_id TIMER_HSYNC_OFF = 1;
112   static const device_timer_id TIMER_HSYNC_ON = 2;
113   static const device_timer_id TIMER_FSYNC = 3;
114 
115   // fonts
116   static const UINT8 pal_round_fontdata8x12[];
117   static const UINT8 pal_square_fontdata8x12[];
118   static const UINT8 ntsc_round_fontdata8x12[];
119   static const UINT8 ntsc_square_fontdata8x12[];
120   static const UINT8 semigraphics4_fontdata8x12[];
121   static const UINT8 semigraphics6_fontdata8x12[];
122 
123   // pixel definitions
124   typedef UINT32 pixel_t;
125 
126   pixel_t *bitmap_addr(bitmap_t *bitmap, int y, int x)
127   {
128      return BITMAP_ADDR32(bitmap, y, x);
129   }
130 
131   static UINT8 simplify_mode(UINT8 data, UINT8 mode)
132   {
133      // simplifies MC6847 modes to drop mode flags that are not significant
134      return mode & ~((mode & MODE_AG) ? (MODE_AS | MODE_INV) : 0);
135   }
136 
137   // internal class that represents a MC6847 character map
138   class character_map
139   {
140   public:
141      // constructor that sets up the font data
142      character_map(const UINT8 *fontdata, bool is_mc6847t1);
143 
144      // optimized template function that emits a single character
145      template<int xscale>
146      ATTR_FORCE_INLINE void emit_character(UINT8 mode, const UINT8 *data, int length, pixel_t *RESTRICT pixels, int y, const pixel_t *palette)
147      {
148         for (int i = 0; i < length; i++)
149         {
150            // get the character
151            UINT8 character = data[i];
152 
153            // based on the mode, determine which entry to use
154            const entry *e = &m_entries[mode % (sizeof(m_entries) / sizeof(m_entries[0]))];
155 
156            // identify the character in the font data
157            const UINT8 *font_character = e->m_fontdata + (character & e->m_character_mask) * 12;
158 
159            // get the particular slice out
160            UINT8 font_character_slice = font_character[y % 12];
161 
162            // get the two colors
163            UINT16 color_base_0 = e->m_color_base_0 + ((character >> e->m_color_shift_0) & e->m_color_mask_0);
164            UINT16 color_base_1 = e->m_color_base_1 + ((character >> e->m_color_shift_1) & e->m_color_mask_1);
165            pixel_t color_0 = palette[color_base_0];
166            pixel_t color_1 = palette[color_base_1];
167 
168            // emit the bits
169            for (int j = 0; j < 8; j++)
170            {
171               for (int k = 0; k < xscale; k++)
172               {
173                  pixels[(i * 8 + j) * xscale + k] = bit_test(font_character_slice, j, color_0, color_1);
174               }
175            }
176         }
177      };
178 
179   private:
180      struct entry
181      {
182         const UINT8 *m_fontdata;
183         UINT8 m_character_mask;
184         UINT8 m_color_shift_0;
185         UINT8 m_color_shift_1;
186         UINT8 m_color_mask_0;
187         UINT8 m_color_mask_1;
188         UINT16 m_color_base_0;
189         UINT16 m_color_base_1;
190      };
191 
192      // lookup table for MC6847 modes to determine font data and color
193      entry m_entries[128];
194 
195      // text font data calculated on startup
196      UINT8 m_text_fontdata_inverse[64*12];
197      UINT8 m_text_fontdata_lower_case[64*12];
198      UINT8 m_text_fontdata_lower_case_inverse[64*12];
199 
200      // optimized function that tests a single bit
201      ATTR_FORCE_INLINE pixel_t bit_test(UINT8 data, int shift, pixel_t color_0, pixel_t color_1)
202      {
203         return data & (0x80 >> shift) ? color_1 : color_0;
204      }
205   };
206 
207   // artficater internal class
208   class artifacter
209   {
210   public:
211      artifacter();
212 
213      // artifacting config
214      void setup_config(device_t *device);
215      void poll_config(void) { m_artifacting = m_config ? input_port_read_direct(m_config) : 0; }
216 
217      // artifacting application
218      template<int xscale>
219      ATTR_FORCE_INLINE void process_artifacts(pixel_t *pixels, UINT8 mode, const pixel_t *palette)
220      {
221         if (((mode & (MODE_AG|MODE_GM2|MODE_GM1|MODE_GM0)) == (MODE_AG|MODE_GM2|MODE_GM1|MODE_GM0))
222            && (m_artifacting != 0))
223         {
224            // identify the new colors and update
225            pixel_t c0 = palette[(mode & MODE_CSS) ? 10 : 8];
226            pixel_t c1 = palette[(mode & MODE_CSS) ? 11 : 9];
227            update_colors(c0, c1);
228 
229            // generate the new line
230            pixel_t new_line[256];
231            int x, i;
232            for (x = 0; x < 256; x += 2)
233            {
234               UINT8 val =   ((pixels[(x - 2) * xscale] == c1) ? 0x20 : 0x00)
235                  |   ((pixels[(x - 1) * xscale] == c1) ? 0x10 : 0x00)
236                  |   ((pixels[(x + 0) * xscale] == c1) ? 0x08 : 0x00)
237                  |   ((pixels[(x + 1) * xscale] == c1) ? 0x04 : 0x00)
238                  |   ((pixels[(x + 2) * xscale] == c1) ? 0x02 : 0x00)
239                  |   ((pixels[(x + 3) * xscale] == c1) ? 0x01 : 0x00);
240               
241               new_line[x + 0] = m_expanded_colors[val * 2 + 0];
242               new_line[x + 1] = m_expanded_colors[val * 2 + 1];
243            }
244 
245            // and copy it in
246            for (x = 0; x < 256; x++)
247            {
248               for (i = 0; i < xscale; i++)
249                  pixels[x * xscale + i] = new_line[x];
250            }
251         }
252      }
253 
254   private:
255      const input_port_config *m_config;
256      input_port_value m_artifacting;
257      input_port_value m_saved_artifacting;
258      pixel_t m_saved_c0, m_saved_c1;
259      pixel_t m_expanded_colors[128];
260 
261      void update_colors(pixel_t c0, pixel_t c1);
262      static pixel_t mix_color(double factor, UINT8 c0, UINT8 c1);
263   };
264 
265   typedef enum
266   {
267      BORDER_COLOR_BLACK,
268      BORDER_COLOR_GREEN,
269      BORDER_COLOR_WHITE,
270      BORDER_COLOR_ORANGE
271   } border_color_t;
272 
273   // callbacks
274   devcb_resolved_write_line m_res_out_hsync_func;
275   devcb_resolved_write_line m_res_out_fsync_func;
276 
277   // incidentals
278   character_map m_character_map;
279   artifacter m_artifacter;
280 
281    // device-level overrides
282    virtual void device_start(void);
283   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
284   virtual void device_reset(void);
285   virtual void device_post_load(void);
286 
287   // other overridables
288   virtual void new_frame(void);
289   virtual void horizontal_sync_changed(bool line);
290   virtual void field_sync_changed(bool line);
291   virtual void enter_bottom_border(void);
292   virtual void record_border_scanline(UINT16 physical_scanline);
293   virtual void record_body_scanline(UINT16 physical_scanline, UINT16 logical_scanline) = 0;
294 
295   // miscellaneous
296   void video_flush(void);
297   const char *describe_context(void);
298 
299   // setup functions
300   emu_timer *setup_timer(device_timer_id id, double offset, double period);
301 
302   // converts to B&W
303   static pixel_t black_and_white(pixel_t color)
304   {
305      UINT8 average_color = (RGB_RED(color) + RGB_GREEN(color) + RGB_BLUE(color)) / 3;
306      return MAKE_RGB(average_color, average_color, average_color);
307   }
308 
309   // changes the geometry
310   ATTR_FORCE_INLINE void set_geometry(UINT16 top_border_scanlines, UINT16 body_scanlines, bool wide)
311   {
312      if (UNEXPECTED((m_top_border_scanlines != top_border_scanlines)
313         || (m_body_scanlines != body_scanlines)
314         || (m_wide != wide)))
315      {
316         m_top_border_scanlines = top_border_scanlines;
317         m_body_scanlines = body_scanlines;
318         m_wide = wide;
319         update_field_sync_timer();
320      }
321   }
322 
323   // calculates the border color
324   static ATTR_FORCE_INLINE border_color_t border_value(UINT8 mode, bool is_mc6847t1)
325   {
326      border_color_t result;
327 
328      if (mode & MODE_AG)
329      {
330         // graphics
331         result = mode & MODE_CSS ? BORDER_COLOR_WHITE : BORDER_COLOR_GREEN;
332      }
333      else if (!is_mc6847t1 || ((mode & MODE_GM2) == 0))
334      {
335         // text, black border
336         result = BORDER_COLOR_BLACK;
337      }
338      else
339      {
340         // text, green or orange border
341         result = mode & MODE_CSS ? BORDER_COLOR_ORANGE : BORDER_COLOR_GREEN;
342      }
343      return result;
344   }
345 
346   // checks to see if the video has changed
347   ATTR_FORCE_INLINE bool has_video_changed(void)
348   {
349      /* poll the artifacting config */
350      m_artifacter.poll_config();
351 
352      /* if the video didn't change, indicate as much */
353      bool video_changed = m_video_changed;
354      m_video_changed = false;
355      return video_changed;
356   }
357 
358   // updates a byte in the video state
359   template<class T>
360   ATTR_FORCE_INLINE bool update_value(T *ptr, T byte)
361   {
362      bool result = false;
363      if (*ptr != byte)
364      {
365         *ptr = byte;
366         m_video_changed = true;
367         result = true;
368      }
369      return result;
370   };
371 
372   // template function for emitting graphics bytes
373   template<int bits_per_pixel, int xscale>
374   ATTR_FORCE_INLINE void emit_graphics(const UINT8 *data, int length, pixel_t *RESTRICT pixels, UINT16 color_base, const pixel_t *RESTRICT palette)
375   {
376      for (int i = 0; i < length; i++)
377      {
378         for (int j = 0; j < (8 / bits_per_pixel); j++)
379         {
380            for (int k = 0; k < xscale; k++)
381            {
382               UINT16 color = color_base + ((data[i] >> (8 - (j + 1) * bits_per_pixel)) & ((1 << bits_per_pixel) - 1));
383               pixels[(i * (8 / bits_per_pixel) + j) * xscale + k] = palette[color];
384            }
385         }
386      }
387   }
388 
389   // template function for emitting samples
390   template<int xscale>
391   UINT32 emit_mc6847_samples(UINT8 mode, const UINT8 *data, int length, pixel_t *RESTRICT pixels, const pixel_t *RESTRICT palette,
392      UINT8 (*get_char_rom)(running_machine &machine, UINT8 ch, int line), int x, int y)
393   {
394      UINT32 result = 0;
395      if (mode & MODE_AG)
396      {
397         /* graphics */
398         switch(mode & (MODE_GM2|MODE_GM1|MODE_GM0))
399         {
400            case 0:
401               emit_graphics<2, xscale * 4>(data, length, pixels, (mode & MODE_CSS) ? 4 : 0, palette);
402               result = length * 8 * xscale * 2;
403               break;
404 
405            case MODE_GM0:
406            case MODE_GM1|MODE_GM0:
407            case MODE_GM2|MODE_GM0:
408               emit_graphics<1, xscale * 2>(data, length, pixels, (mode & MODE_CSS) ? 10 : 8, palette);
409               result = length * 8 * xscale * 2;
410               break;
411 
412            case MODE_GM1:
413            case MODE_GM2:
414            case MODE_GM2|MODE_GM1:
415               emit_graphics<2, xscale * 2>(data, length, pixels, (mode & MODE_CSS) ? 4 : 0, palette);
416               result = length * 8 * xscale;
417               break;
418 
419            case MODE_GM2|MODE_GM1|MODE_GM0:
420               emit_graphics<1, xscale * 1>(data, length, pixels, (mode & MODE_CSS) ? 10 : 8, palette);
421               result = length * 8 * xscale;
422               break;
423 
424            default:
425               /* should not get here */
426               fatalerror("Should not get here");
427               break;
428         }
429      }
430      else if ((get_char_rom != NULL) && ((mode & (MODE_AG|MODE_AS|MODE_INTEXT)) == MODE_INTEXT))
431      {
432         /* external ROM */
433         for (int i = 0; i < length; i++)
434         {
435            UINT8 byte = get_char_rom(machine(), data[i], y % 12) ^ (mode & MODE_INV ? 0xFF : 0x00);
436            emit_graphics<2, xscale * 2>(&byte, 1, &pixels[i * 8], (mode & MODE_CSS) ? 14 : 12, palette);
437         }
438         result = length * 8 * xscale;
439      }
440      else
441      {
442         /* text/semigraphics */
443         m_character_map.emit_character<xscale>(mode, data, length, pixels, y, palette);
444         result = length * 8 * xscale;
445      }
446      return result;
447   }
448 
449 
450private:
451   enum scanline_zone
452   {
453      SCANLINE_ZONE_TOP_BORDER,
454      SCANLINE_ZONE_BODY,
455      SCANLINE_ZONE_BOTTOM_BORDER,
456      SCANLINE_ZONE_RETRACE,
457      SCANLINE_ZONE_VBLANK,
458      SCANLINE_ZONE_FRAME_END
459   };
460 
461   // timers
462   emu_timer *m_frame_timer;
463   emu_timer *m_hsync_on_timer;
464   emu_timer *m_hsync_off_timer;
465   emu_timer *m_fsync_timer;
466 
467   // incidentals
468   double m_tpfs;
469   int m_field_sync_falling_edge_scanline;
470   bool m_wide;
471   bool m_video_changed;
472   UINT16 m_top_border_scanlines;
473   UINT16 m_body_scanlines;
474 
475   // video state
476   UINT16 m_physical_scanline;
477   UINT16 m_logical_scanline;
478   UINT16 m_logical_scanline_zone;
479   bool m_horizontal_sync;
480   bool m_field_sync;
481 
482   // functions
483   void change_horizontal_sync(bool line);
484   void change_field_sync(bool line);
485   void update_field_sync_timer(void);
486   void next_scanline(void);
487 
488   // debugging
489   const char *scanline_zone_string(scanline_zone zone);
490};
491 
492// actual base class for MC6847 family of devices
493class mc6847_base_device : public mc6847_friend_device
494{
495public:
496   /* updates the screen -- this will call begin_update(),
497       followed by update_row() reapeatedly and after all row
498       updating is complete, end_update() */
499   bool update(bitmap_t *bitmap, const rectangle *cliprect);
500 
501   // mode changing operations
502   DECLARE_WRITE_LINE_MEMBER( ag_w )      { change_mode(MODE_AG, state); }
503   DECLARE_WRITE_LINE_MEMBER( gm2_w )      { change_mode(MODE_GM2, state); }
504   DECLARE_WRITE_LINE_MEMBER( gm1_w )      { change_mode(MODE_GM1, state); }
505   DECLARE_WRITE_LINE_MEMBER( gm0_w )      { change_mode(MODE_GM0, state); }
506   DECLARE_WRITE_LINE_MEMBER( as_w )      { change_mode(MODE_AS, state); }
507   DECLARE_WRITE_LINE_MEMBER( css_w )      { change_mode(MODE_CSS, state); }
508   DECLARE_WRITE_LINE_MEMBER( intext_w )   { change_mode(MODE_INTEXT, state); }
509   DECLARE_WRITE_LINE_MEMBER( inv_w )      { change_mode(MODE_INV, state); }
510 
511protected:
512   mc6847_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const UINT8 *fontdata, double tpfs);
513 
514    // device-level overrides
515    virtual void device_start();
516   virtual void device_reset();
517   virtual ioport_constructor device_input_ports() const;
518 
519   // other overrides
520   virtual void field_sync_changed(bool line);
521 
522private:
523   struct video_scanline
524   {
525      UINT8 m_sample_count;
526      UINT8 m_mode[32];
527      UINT8 m_data[32];
528   };
529 
530   // palette
531   static const int PALETTE_LENGTH = 16;
532   static const UINT32 s_palette[PALETTE_LENGTH];
533 
534   // callbacks
535   devcb_resolved_read8 m_res_input_func;
536   UINT8 (*m_get_char_rom)(running_machine &machine, UINT8 ch, int line);
537 
538   // incidentals
539   UINT8 m_fixed_mode;
540   UINT8 m_fixed_mode_mask;
541   const pixel_t *m_palette;
542   pixel_t m_bw_palette[PALETTE_LENGTH];
543 
544   // state
545   UINT8 m_mode;
546   video_scanline m_data[192];
547   bool m_dirty;
548 
549   void change_mode(UINT8 mode, int state)
550   {
551      /* sanity check, to ensure that we're not changing fixed modes */
552      assert((mode & m_fixed_mode_mask) == 0);
553 
554      if (!m_dirty)
555      {
556         video_flush();
557         m_dirty = true;
558      }
559 
560      if (state)
561         m_mode |= mode;
562      else
563         m_mode &= ~mode;
564   }
565 
566   // setup functions
567   void setup_fixed_mode(struct devcb_read_line callback, UINT8 mode);
568 
569   // runtime functions
570   virtual void record_body_scanline(UINT16 physical_scanline, UINT16 scanline);
571   pixel_t border_value(UINT8 mode, const pixel_t *palette, bool is_mc6847t1);
572 
573   template<int xscale>
574   void emit_samples(UINT8 mode, const UINT8 *data, int length, pixel_t *pixels, int x, int y);
575 
576   // template function for doing video update collection
577   template<int sample_count, int yres>
578   void record_scanline_res(int scanline);
579};
580 
581 
582//**************************************************************************
583//  VARIATIONS
584//**************************************************************************
585 
586class mc6847_ntsc_device : public mc6847_base_device
587{
588public:
589   mc6847_ntsc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
590};
591 
592class mc6847_pal_device : public mc6847_base_device
593{
594public:
595   mc6847_pal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
596};
597 
598class mc6847y_ntsc_device : public mc6847_base_device
599{
600public:
601   mc6847y_ntsc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
602};
603 
604class mc6847y_pal_device : public mc6847_base_device
605{
606public:
607   mc6847y_pal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
608};
609 
610class mc6847t1_ntsc_device : public mc6847_base_device
611{
612public:
613   mc6847t1_ntsc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
614};
615 
616class mc6847t1_pal_device : public mc6847_base_device
617{
618public:
619   mc6847t1_pal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
620};
621 
622 
623extern const device_type MC6847_NTSC;
624extern const device_type MC6847_PAL;
625extern const device_type MC6847Y_NTSC;
626extern const device_type MC6847Y_PAL;
627extern const device_type MC6847T1_NTSC;
628extern const device_type MC6847T1_PAL;
629 
630#endif /* __MC6847__ */
631 
src/mess/video/coco3.c
r13256r13257
1/***************************************************************************
2
3    CoCo 3 Video Hardware
4
5    TODO:
6        - Implement "burst phase invert" (it switches the artifact colors)
7        - Figure out what Bit 3 of $FF98 is and implement it
8        - Learn more about the "mystery" CoCo 3 video modes
9        - Support the VSC register
10
11
12    Mid frame raster effects (source John Kowalski)
13        Here are the things that get changed mid-frame:
14            -palette registers ($ffb0-$ffbf)
15            -horizontal resolution (switches between 256 and 320 pixels, $ff99)
16            -horizontal scroll position (bits 0-6 $ff9f)
17            -horizontal virtual screen (bit 7 $ff9f)
18            -pixel height (bits 0-2 $ff98)
19            -border color ($ff9a)
20        On the positive side, you don't have to worry about registers
21        $ff9d/ff9e being changed mid-frame.  Even if they are changed
22        mid-frame, they have no effect on the displayed image.  The video
23        address only gets latched at the top of the frame.
24
25***************************************************************************/
26
27#include <assert.h>
28#include <math.h>
29
30#include "emu.h"
31#include "machine/6883sam.h"
32#include "video/coco6847.h"
33#include "includes/coco.h"
34#include "machine/ram.h"
35
36#if defined(__GNUC__) && (__GNUC__ >= 3)
37#define RESTRICT   __restrict__
38#else /* !__GNUC__ */
39#define RESTRICT
40#endif /* __GNUC__ */
41
42/*************************************
43 *
44 *  Global variables
45 *
46 *************************************/
47
48
49
50/*************************************
51 *
52 *  Parameters
53 *
54 *************************************/
55
56#define LOG_PALETTE   0
57#define LOG_PREPARE 0
58
59
60
61/*************************************
62 *
63 *  Video rendering
64 *
65 *************************************/
66
67static void color_batch(coco3_state *state, UINT32 *results, const UINT8 *indexes, int count)
68{
69   coco3_video *video = state->m_video;
70   UINT32 c;
71   const UINT32 *current_palette;
72   int is_black_white;
73   int i;
74
75   if (video->video_type)
76   {
77      /* RGB */
78      current_palette = video->rgb_palette;
79      is_black_white = FALSE;
80   }
81   else
82   {
83      /* Composite/TV */
84      current_palette = video->composite_palette;
85      is_black_white = (state->m_gimereg[8] & 0x10) ? TRUE : FALSE;
86   }
87
88   for (i = 0; i < count; i++)
89   {
90      c = current_palette[indexes[i] & 0x3F];
91
92      if (is_black_white)
93      {
94         /* We are on a composite monitor/TV and the monochrome phase invert
95             * flag is on in the GIME.  This means we have to average out all
96             * colors
97             */
98         UINT32 red   = ((c & 0xFF0000) >> 16);
99         UINT32 green = ((c & 0x00FF00) >>  8);
100         UINT32 blue  = ((c & 0x0000FF) >>  0);
101         c = ((red + green + blue) / 3) * 0x010101;
102      }
103
104      results[i] = c;
105   }
106}
107
108
109
110static UINT32 color(coco3_state *state, UINT8 index)
111{
112   UINT32 c;
113   color_batch(state, &c, &index, 1);
114   return c;
115}
116
117
118
119INLINE UINT8 get_char_info(coco3_video *video, const coco3_scanline_record *scanline_record,
120   int i, int has_attrs, UINT32 *bg, UINT32 *fg)
121{
122   UINT8 byte, attr, char_data = 0x00;
123
124   /* determine the basics */
125   byte = scanline_record->data[i * (has_attrs ? 2 : 1)];
126   if (scanline_record->index < 8)
127      char_data = video->fontdata[(byte & 0x7F)][scanline_record->index];
128
129   if (has_attrs)
130   {
131      /* has attributes */
132      attr = scanline_record->data[i * (has_attrs ? 2 : 1) + 1];
133
134      /* colors */
135      *bg = video->palette_colors[((attr >> 0) & 0x07) + 0x00];
136      *fg = video->palette_colors[((attr >> 3) & 0x07) + 0x08];
137
138      /* underline attribute */
139      if (attr & 0x40)
140      {
141         /* to quote SockMaster:
142            *
143            * The underline attribute will light up the bottom scan line of the character
144            * if the lines are set to 8 or 9.  Not appear at all when less, or appear on
145            * the 2nd to bottom scan line if set higher than 9.  Further exception being
146            * the $x7 setting where the whole screen is filled with only one line of data
147            * - but it's glitched - the line repeats over and over again every 16 scan
148            * lines..  Nobody will use this mode, but that's what happens if you want to
149            * make things really authentic :)
150            */
151         switch(scanline_record->ff98 & 0x07)
152         {
153            case 0x03:   /* 8 scanlines per row */
154               if (scanline_record->index == 7)
155                  char_data = 0xFF;
156               break;
157
158            case 0x04:   /* 9 scanlines per row */
159            case 0x05:   /* 10 scanlines per row */
160               if (scanline_record->index == 8)
161                  char_data = 0xFF;
162               break;
163
164            case 0x06:   /* 11 scanlines per row */
165               if (scanline_record->index == 9)
166                  char_data = 0xFF;
167               break;
168         }
169      }
170
171      /* blink attribute */
172      if ((attr & 0x80) && video->blink)
173         char_data = 0x00;
174   }
175   else
176   {
177      /* no attributes */
178      *bg = video->palette_colors[0];
179      *fg = video->palette_colors[1];
180   }
181   return char_data;
182}
183
184
185
186static void wide_text_mode(coco3_video *video, UINT32 *line, const coco3_scanline_record *scanline_record,
187   int char_count, int has_attrs)
188{
189   int i;
190   UINT8 char_data;
191   UINT32 bg, fg;
192
193   for (i = 0; i < char_count; i++)
194   {
195      char_data = get_char_info(video, scanline_record, i, has_attrs, &bg, &fg);
196
197      line[i * 16 +  0] = line[i * 16 +  1] = (char_data & 0x80) ? fg : bg;
198      line[i * 16 +  2] = line[i * 16 +  3] = (char_data & 0x40) ? fg : bg;
199      line[i * 16 +  4] = line[i * 16 +  5] = (char_data & 0x20) ? fg : bg;
200      line[i * 16 +  6] = line[i * 16 +  7] = (char_data & 0x10) ? fg : bg;
201      line[i * 16 +  8] = line[i * 16 +  9] = (char_data & 0x08) ? fg : bg;
202      line[i * 16 + 10] = line[i * 16 + 11] = (char_data & 0x04) ? fg : bg;
203      line[i * 16 + 12] = line[i * 16 + 13] = (char_data & 0x02) ? fg : bg;
204      line[i * 16 + 14] = line[i * 16 + 15] = (char_data & 0x01) ? fg : bg;
205   }
206}
207
208
209
210static void narrow_text_mode(coco3_video *video, UINT32 *line, const coco3_scanline_record *scanline_record,
211   int char_count, int has_attrs)
212{
213   int i;
214   UINT8 char_data;
215   UINT32 bg, fg;
216
217   for (i = 0; i < char_count; i++)
218   {
219      char_data = get_char_info(video, scanline_record, i, has_attrs, &bg, &fg);
220
221      line[i * 8 + 0] = (char_data & 0x80) ? fg : bg;
222      line[i * 8 + 1] = (char_data & 0x40) ? fg : bg;
223      line[i * 8 + 2] = (char_data & 0x20) ? fg : bg;
224      line[i * 8 + 3] = (char_data & 0x10) ? fg : bg;
225      line[i * 8 + 4] = (char_data & 0x08) ? fg : bg;
226      line[i * 8 + 5] = (char_data & 0x04) ? fg : bg;
227      line[i * 8 + 6] = (char_data & 0x02) ? fg : bg;
228      line[i * 8 + 7] = (char_data & 0x01) ? fg : bg;
229   }
230}
231
232
233
234INLINE void graphics_mode(coco3_state *state, UINT32 *RESTRICT line, const coco3_scanline_record *scanline_record,
235   int byte_count, int bpp, int pixel_width)
236{
237   int i, j, k;
238   UINT8 byte;
239   UINT32 c;
240   UINT32 colors[16];
241
242   color_batch(state, colors, scanline_record->palette, 1 << bpp);
243
244   for (i = 0; i < byte_count; i++)
245   {
246      byte = scanline_record->data[i];
247      for (j = 0; j < 8; j += bpp)
248      {
249         c = colors[(byte >> (8 - bpp - j)) & ((1 << bpp) - 1)];
250
251         for (k = 0; k < pixel_width; k++)
252            *(line++) = c;
253      }
254   }
255}
256
257
258
259static void graphics_none(UINT32 *line, int width)
260{
261   memset(line, 0, width * sizeof(*line));
262}
263
264
265
266static void coco3_render_scanline(running_machine &machine, bitmap_t *bitmap, int scanline)
267{
268   coco3_state *state = machine.driver_data<coco3_state>();
269   coco3_video *video = state->m_video;
270   const coco3_scanline_record *scanline_record;
271   UINT32 *line;
272   UINT32 border_color;
273   int i;
274
275   /* get the basics */
276   line = BITMAP_ADDR32(bitmap, scanline, 0);
277   scanline_record = &video->scanlines[scanline];
278   border_color = color(state, scanline_record->ff9a);
279
280   scanline -= video->top_border_scanlines;
281   if ((scanline >= 0) && (scanline < video->display_scanlines))
282   {
283      /* display scanline */
284      if (scanline_record->ff98 & 0x80)
285      {
286         /* graphics */
287         switch(scanline_record->ff99 & 0x1F)
288         {
289            case 0x00:   graphics_mode(state, &line[64], scanline_record,  16, 1,  4);      break;
290            case 0x01:   graphics_mode(state, &line[64], scanline_record,  16, 2,  8);      break;
291            case 0x02:   graphics_mode(state, &line[64], scanline_record,  16, 4, 16);      break;
292            case 0x03:   graphics_none(&line[64], 512);                        break;
293            case 0x04:   graphics_mode(state, &line[ 0], scanline_record,  20, 1,  4);      break;
294            case 0x05:   graphics_mode(state, &line[ 0], scanline_record,  20, 2,  8);      break;
295            case 0x06:   graphics_mode(state, &line[ 0], scanline_record,  20, 4, 16);      break;
296            case 0x07:   graphics_none(&line[ 0], 640);                        break;
297            case 0x08:   graphics_mode(state, &line[64], scanline_record,  32, 1,  2);      break;
298            case 0x09:   graphics_mode(state, &line[64], scanline_record,  32, 2,  4);      break;
299            case 0x0A:   graphics_mode(state, &line[64], scanline_record,  32, 4,  8);      break;
300            case 0x0B:   graphics_none(&line[64], 512);                        break;
301            case 0x0C:   graphics_mode(state, &line[ 0], scanline_record,  40, 1,  2);      break;
302            case 0x0D:   graphics_mode(state, &line[ 0], scanline_record,  40, 2,  4);      break;
303            case 0x0E:   graphics_mode(state, &line[ 0], scanline_record,  40, 4,  8);      break;
304            case 0x0F:   graphics_none(&line[ 0], 640);                        break;
305            case 0x10:   graphics_mode(state, &line[64], scanline_record,  64, 1,  1);      break;
306            case 0x11:   graphics_mode(state, &line[64], scanline_record,  64, 2,  2);      break;
307            case 0x12:   graphics_mode(state, &line[64], scanline_record,  64, 4,  4);      break;
308            case 0x13:   graphics_none(&line[64], 512);                        break;
309            case 0x14:   graphics_mode(state, &line[ 0], scanline_record,  80, 1,  1);      break;
310            case 0x15:   graphics_mode(state, &line[ 0], scanline_record,  80, 2,  2);      break;
311            case 0x16:   graphics_mode(state, &line[ 0], scanline_record,  80, 4,  4);      break;
312            case 0x17:   graphics_none(&line[ 0], 640);                        break;
313            case 0x18:   graphics_none(&line[64], 512);                        break;
314            case 0x19:   graphics_mode(state, &line[64], scanline_record, 128, 2,  1);      break;
315            case 0x1A:   graphics_mode(state, &line[64], scanline_record, 128, 4,  2);      break;
316            case 0x1B:   graphics_none(&line[64], 512);                        break;
317            case 0x1C:   graphics_none(&line[ 0], 640);                        break;
318            case 0x1D:   graphics_mode(state, &line[ 0], scanline_record, 160, 2,  1);      break;
319            case 0x1E:   graphics_mode(state, &line[ 0], scanline_record, 160, 4,  2);      break;
320            case 0x1F:   graphics_none(&line[ 0], 640);                        break;
321         }
322      }
323      else
324      {
325         /* text */
326         switch(scanline_record->ff99 & 0x15)
327         {
328            case 0x00:   wide_text_mode(video, &line[64], scanline_record, 32, FALSE);      break;
329            case 0x01:   wide_text_mode(video, &line[64], scanline_record, 32, TRUE);      break;
330            case 0x04:   wide_text_mode(video, &line[ 0], scanline_record, 40, FALSE);      break;
331            case 0x05:   wide_text_mode(video, &line[ 0], scanline_record, 40, TRUE);      break;
332            case 0x10:   narrow_text_mode(video, &line[64], scanline_record, 64, FALSE);   break;
333            case 0x11:   narrow_text_mode(video, &line[64], scanline_record, 64, TRUE);      break;
334            case 0x14:   narrow_text_mode(video, &line[ 0], scanline_record, 80, FALSE);   break;
335            case 0x15:   narrow_text_mode(video, &line[ 0], scanline_record, 80, TRUE);      break;
336         }
337      }
338
339      if (!(scanline_record->ff99 & 0x04))
340      {
341         /* side borders */
342         for (i = 0; i < 64; i++)
343            line[i] = border_color;
344         for (i = 576; i < 640; i++)
345            line[i] = border_color;
346      }
347   }
348   else
349   {
350      /* border scanline */
351      for (i = 0; i < 640; i++)
352         line[i] = border_color;
353   }
354}
355
356
357
358SCREEN_UPDATE( coco3 )
359{
360   coco3_state *state = screen->machine().driver_data<coco3_state>();
361   coco3_video *video = state->m_video;
362   int i, row;
363   UINT32 *line;
364   UINT32 rc = 0;
365
366   /* bad screen */
367   if (!strcmp(screen->tag(), "composite"))
368   {
369      video->video_type = 0;
370   }
371   else if (!strcmp(screen->tag(), "rgb"))
372   {
373      video->video_type = 1;
374   }
375   else
376   {
377      fatalerror("Bad screen");
378   }
379
380   /* set all of the palette colors */
381   for (i = 0; i < 16; i++)
382      video->palette_colors[i] = color(state, video->palette_ram[i]);
383
384   if (video->legacy_video)
385   {
386      /* legacy CoCo 1/2 graphics */
387      rc = SCREEN_UPDATE_CALL(m6847);
388
389      if ((rc & UPDATE_HAS_NOT_CHANGED) == 0)
390      {
391         /* need to double up all pixels */
392         for (row = cliprect->min_y; row <= cliprect->max_y; row++)
393         {
394            line = BITMAP_ADDR32(bitmap, row, 0);
395            for (i = 319; i >= 0; i--)
396               line[i * 2 + 0] = line[i * 2 + 1] = line[i];
397         }
398      }
399   }
400   else
401   {
402      /* CoCo 3 graphics */
403      if (video->dirty[video->video_type])
404      {
405         for (row = cliprect->min_y; row <= cliprect->max_y; row++)
406            coco3_render_scanline(screen->machine(), bitmap, row);
407         video->dirty[video->video_type] = FALSE;
408      }
409      else
410      {
411         rc = UPDATE_HAS_NOT_CHANGED;
412      }
413   }
414   return rc;
415}
416
417
418
419/*************************************
420 *
421 *  Miscellaneous
422 *
423 *************************************/
424
425static void coco3_set_dirty(running_machine &machine)
426{
427   coco3_state *state = machine.driver_data<coco3_state>();
428   coco3_video *video = state->m_video;
429   int i;
430   for (i = 0; i < ARRAY_LENGTH(video->dirty); i++)
431      video->dirty[i] = TRUE;
432}
433
434
435
436static int coco3_new_frame(running_machine &machine)
437{
438   coco3_state *state = machine.driver_data<coco3_state>();
439   coco3_video *video = state->m_video;
440   int gime_field_sync = 0;
441
442   /* changing from non-legacy to legacy video? */
443   if (!video->legacy_video && (state->m_gimereg[0] & 0x80))
444      coco3_set_dirty(machine);
445
446   video->legacy_video = (state->m_gimereg[0] & 0x80) ? TRUE : FALSE;
447   video->line_in_row = (state->m_gimereg[12] & 0x0F);
448
449   if (!video->legacy_video)
450   {
451      /* CoCo 3 video */
452      switch(state->m_gimereg[9] & 0x60)
453      {
454         case 0x00:      /* 192 lines */
455            video->top_border_scanlines = 26;
456            video->display_scanlines = 192;
457            gime_field_sync = video->top_border_scanlines + video->display_scanlines;
458            break;
459
460         case 0x20:      /* 200 lines */
461            video->top_border_scanlines = 24;
462            video->display_scanlines = 200;
463            gime_field_sync = video->top_border_scanlines + video->display_scanlines - 1;
464            break;
465
466         case 0x40:      /* zero/infinite lines */
467            video->top_border_scanlines = 0;
468            video->display_scanlines = 0;
469            gime_field_sync = video->top_border_scanlines + video->display_scanlines;
470            break;
471
472         case 0x60:      /* 225 lines */
473            video->top_border_scanlines = 9;
474            video->display_scanlines = 225;
475            gime_field_sync = video->top_border_scanlines + video->display_scanlines;
476            break;
477      }
478      video->video_position = coco3_get_video_base(machine, 0xFF, 0xFF);
479   }
480   else
481   {
482      /* legacy video; some of these are just filled in for fun */
483      video->top_border_scanlines = 25;
484      video->display_scanlines = 192;
485      video->video_position = 0;
486   }
487
488   /* set up GIME field sync */
489   video->gime_fs_timer->adjust(
490      coco6847_scanline_time(gime_field_sync), 0);
491
492   return video->legacy_video;
493}
494
495
496
497INLINE void memcpy_dirty(int *dirty, void *RESTRICT dest, const void *RESTRICT src, size_t len)
498{
499   if (!*dirty)
500      *dirty = memcmp(dest, src, len) != 0;
501   if (*dirty)
502      memcpy(dest, src, len);
503}
504
505
506
507static void coco3_prepare_scanline(running_machine &machine, int scanline)
508{
509   coco3_state *state = machine.driver_data<coco3_state>();
510   coco3_video *video = state->m_video;
511   static const UINT32 lines_per_row[] = { 1, 1, 2, 8, 9, 10, 11, ~0 };
512   static const UINT32 gfx_bytes_per_row[] = { 16, 20, 32, 40, 64, 80, 128, 160 };
513   UINT32 video_offset, video_data_size;
514   UINT32 bytes_per_row, segment_length;
515   coco3_scanline_record *scanline_record;
516   const UINT8 *video_data;
517   int dirty;
518
519   if (LOG_PREPARE)
520      logerror("coco3_prepare_scanline(): scanline=%d video_position=0x%06X\n", scanline, video->video_position);
521   dirty = video->dirty ? TRUE : FALSE;
522
523   /* copy the basics */
524   scanline_record = &video->scanlines[scanline];
525   memcpy_dirty(&dirty, &scanline_record->ff98, &state->m_gimereg[8], 1);
526   memcpy_dirty(&dirty, &scanline_record->ff99, &state->m_gimereg[9], 1);
527   memcpy_dirty(&dirty, &scanline_record->ff9a, &state->m_gimereg[10], 1);
528
529   /* is this a display scanline? */
530   scanline -= video->top_border_scanlines;
531   if ((scanline >= 0) && (scanline <= video->display_scanlines))
532   {
533      /* yes, this is indeed a display scanline; copy the palette */
534      memcpy_dirty(&dirty, scanline_record->palette, video->palette_ram, 16);
535
536      /* get ready to copy the video memory; get position and offsets */
537      video_data = &ram_get_ptr(machine.device(RAM_TAG))[video->video_position % ram_get_size(machine.device(RAM_TAG))];
538      video_offset = (state->m_gimereg[15] & 0x7F) * 2;
539      video_data_size = sizeof(scanline_record->data);
540
541      /* FF9F offsets wrap around every 256 bytes, even if bit 7 is not set.
542         * Therefore, we must split things up into two separate segments */
543      segment_length = MIN(video_data_size, 256 - video_offset);
544      memcpy_dirty(&dirty, scanline_record->data, video_data + video_offset, segment_length);
545      memcpy_dirty(&dirty, scanline_record->data + segment_length, video_data, video_data_size - segment_length);
546
547      /* next line */
548      memcpy_dirty(&dirty, &scanline_record->index, &video->line_in_row, sizeof(video->line_in_row));
549      video->line_in_row++;
550
551      /* do we have to advance to the next row? */
552      if (video->line_in_row >= lines_per_row[state->m_gimereg[8] & 0x07])
553      {
554         /* on to the next row */
555         video->line_in_row = 0;
556
557         if (state->m_gimereg[15] & 0x80)
558         {
559            /* FF9F scrolling mode */
560            bytes_per_row = 256;
561         }
562         else if (state->m_gimereg[8] & 0x80)
563         {
564            /* calc bytes per row for graphics */
565            bytes_per_row = gfx_bytes_per_row[(state->m_gimereg[9] & 0x1C) >> 2];
566         }
567         else
568         {
569            /* calc bytes per row for text */
570            bytes_per_row = 32;
571            if (state->m_gimereg[9] & 0x04)
572               bytes_per_row += 8;
573            if (state->m_gimereg[9] & 0x10)
574               bytes_per_row *= 2;
575            if (state->m_gimereg[9] & 0x01)
576               bytes_per_row *= 2;
577         }
578
579         video->video_position += bytes_per_row;
580      }
581   }
582   else
583   {
584      if (scanline_record->index != 0)
585      {
586         scanline_record->index = 0;
587         dirty = TRUE;
588      }
589   }
590   if (dirty)
591      coco3_set_dirty(machine);
592}
593
594
595
596WRITE8_HANDLER(coco3_palette_w)
597{
598   data &= 0x3f;
599
600   if (space->machine().generic.paletteram.u8[offset] != data)
601   {
602      space->machine().generic.paletteram.u8[offset] = data;
603      if (LOG_PALETTE)
604         logerror("CoCo3 Palette: %i <== $%02x\n", offset, data);
605   }
606}
607
608
609
610UINT32 coco3_get_video_base(running_machine &machine, UINT8 ff9d_mask, UINT8 ff9e_mask)
611{
612   coco3_state *state = machine.driver_data<coco3_state>();
613   /* The purpose of the ff9d_mask and ff9e_mask is to mask out bits that are
614     * ignored in lo-res mode.  Specifically, $FF9D is masked with $E0, and
615     * $FF9E is masked with $3F
616     *
617     * John Kowalski confirms this behavior
618     */
619   return   ((offs_t) (state->m_gimereg[14] & ff9e_mask)   * 0x00008)
620      |   ((offs_t) (state->m_gimereg[13] & ff9d_mask)   * 0x00800)
621      |   ((offs_t) (state->m_gimereg[11] & 0x0F)      * 0x80000);
622}
623
624
625
626static TIMER_CALLBACK(gime_fs)
627{
628   coco3_gime_field_sync_callback(machine);
629}
630
631
632
633/*************************************
634 *
635 *  Initialization
636 *
637 *************************************/
638
639static UINT32 get_composite_color(int color)
640{
641   /* CMP colors
642     *
643     * These colors are of the format IICCCC, where II is the intensity and
644     * CCCC is the base color.  There is some weirdness because intensity
645     * is often different for each base color.
646     *
647     * The code below is based on an algorithm specified in the following
648     * CoCo BASIC program was used to approximate composite colors.
649     * (Program by SockMaster):
650     *
651     * 10 POKE65497,0:DIMR(63),G(63),B(63):WIDTH80:PALETTE0,0:PALETTE8,54:CLS1
652     * 20 SAT=92:CON=70:BRI=-50:L(0)=0:L(1)=47:L(2)=120:L(3)=255
653     * 30 W=.4195456981879*1.01:A=W*9.2:S=A+W*5:D=S+W*5:P=0:FORH=0TO3:P=P+1
654     * 40 BRI=BRI+CON:FORG=1TO15:R(P)=COS(A)*SAT+BRI
655     * 50 G(P)=(COS(S)*SAT)*1+BRI:B(P)=(COS(D)*SAT)*1+BRI:P=P+1
656     * 55 A=A+W:S=S+W:D=D+W:NEXT:R(P-16)=L(H):G(P-16)=L(H):B(P-16)=L(H)
657     * 60 NEXT:R(63)=R(48):G(63)=G(48):B(63)=B(48)
658     * 70 FORH=0TO63STEP1:R=INT(R(H)):G=INT(G(H)):B=INT(B(H)):IFR<0THENR=0
659     * 80 IFG<0THENG=0
660     * 90 IFB<0THENB=0
661     * 91 IFR>255THENR=255
662     * 92 IFG>255THENG=255
663     * 93 IFB>255THENB=255
664     * 100 PRINTRIGHT$(STR$(H),2);" $";:R=R+256:G=G+256:B=B+256
665     * 110 PRINTRIGHT$(HEX$(R),2);",$";RIGHT$(HEX$(G),2);",$";RIGHT$(HEX$(B),2)
666     * 115 IF(H AND15)=15 THENIFINKEY$=""THEN115ELSEPRINT
667     * 120 NEXT
668     *
669     *  At one point, we used a different SockMaster program, but the colors
670     *  produced were too dark for people's taste
671     *
672     *  10 POKE65497,0:DIMR(63),G(63),B(63):WIDTH80:PALETTE0,0:PALETTE8,54:CLS1
673     *  20 SAT=92:CON=53:BRI=-16:L(0)=0:L(1)=47:L(2)=120:L(3)=255
674     *  30 W=.4195456981879*1.01:A=W*9.2:S=A+W*5:D=S+W*5:P=0:FORH=0TO3:P=P+1
675     *  40 BRI=BRI+CON:FORG=1TO15:R(P)=COS(A)*SAT+BRI
676     *  50 G(P)=(COS(S)*SAT)*.50+BRI:B(P)=(COS(D)*SAT)*1.9+BRI:P=P+1
677     *  55 A=A+W:S=S+W:D=D+W:NEXT:R(P-16)=L(H):G(P-16)=L(H):B(P-16)=L(H)
678     *  60 NEXT:R(63)=R(48):G(63)=G(48):B(63)=B(48)
679     *  70 FORH=0TO63STEP1:R=INT(R(H)):G=INT(G(H)):B=INT(B(H)):IFR<0THENR=0
680     *  80 IFG<0THENG=0
681     *  90 IFB<0THENB=0
682     *  91 IFR>255THENR=255
683     *  92 IFG>255THENG=255
684     *  93 IFB>255THENB=255
685     *  100 PRINTRIGHT$(STR$(H),2);" $";:R=R+256:G=G+256:B=B+256
686     *  110 PRINTRIGHT$(HEX$(R),2);",$";RIGHT$(HEX$(G),2);",$";RIGHT$(HEX$(B),2)
687     *  115 IF(H AND15)=15 THENIFINKEY$=""THEN115ELSEPRINT
688     *  120 NEXT
689     */
690
691   double saturation, brightness, contrast;
692   int offset;
693   double w;
694   int r, g, b;
695
696   switch(color) {
697   case 0:
698      r = g = b = 0;
699      break;
700
701   case 16:
702      r = g = b = 47;
703      break;
704
705   case 32:
706      r = g = b = 120;
707      break;
708
709   case 48:
710   case 63:
711      r = g = b = 255;
712      break;
713
714   default:
715      w = .4195456981879*1.01;
716      contrast = 70;
717      saturation = 92;
718      brightness = -50;
719      brightness += ((color / 16) + 1) * contrast;
720      offset = (color % 16) - 1 + (color / 16)*15;
721      r = cos(w*(offset +  9.2)) * saturation + brightness;
722      g = cos(w*(offset + 14.2)) * saturation + brightness;
723      b = cos(w*(offset + 19.2)) * saturation + brightness;
724
725      if (r < 0)
726         r = 0;
727      else if (r > 255)
728         r = 255;
729
730      if (g < 0)
731         g = 0;
732      else if (g > 255)
733         g = 255;
734
735      if (b < 0)
736         b = 0;
737      else if (b > 255)
738         b = 255;
739      break;
740   }
741   return (UINT32) ((r << 16) | (g << 8) | (b << 0));
742}
743
744
745
746static UINT32 get_rgb_color(int color)
747{
748   return   (((color >> 4) & 2) | ((color >> 2) & 1)) * 0x550000
749      |   (((color >> 3) & 2) | ((color >> 1) & 1)) * 0x005500
750      |   (((color >> 2) & 2) | ((color >> 0) & 1)) * 0x000055;
751}
752
753
754
755static void coco3_video_postload(coco3_state *state)
756{
757   coco3_set_dirty(state->machine());
758}
759
760
761static const UINT8 *get_video_ram_coco3(running_machine &machine,int scanline)
762{
763   device_t *sam = machine.device("sam");
764   return sam6883_videoram(sam,scanline);
765}
766
767static void internal_video_start_coco3(running_machine &machine, m6847_type type)
768{
769   coco3_state *state = machine.driver_data<coco3_state>();
770   coco3_video *video;
771   int i;
772   m6847_config cfg;
773   const UINT8 *rom;
774
775   /* allocate video */
776   state->m_video = video = auto_alloc_clear(machine, coco3_video);
777   coco3_set_dirty(machine);
778
779   /* initialize palette */
780   for (i = 0; i < 64; i++)
781   {
782      video->composite_palette[i] = get_composite_color(i);
783      video->rgb_palette[i] = get_rgb_color(i);
784   }
785
786   /* incidentals */
787   machine.generic.paletteram.u8 = video->palette_ram;
788   memory_set_bankptr(machine, "bank10", machine.generic.paletteram.u8);
789
790   /* font */
791   rom = machine.region("maincpu")->base();
792   for (i = 0; i < 32; i++)
793   {
794      /* characters 0-31 are at $FA10 - $FB0F */
795      memcpy(video->fontdata[i], &rom[0xFA10 - 0x8000 + (i * 8)], 8);
796   }
797   for (i = 32; i < 128; i++)
798   {
799      /* characters 32-127 are at $F09D - $F39C */
800      memcpy(video->fontdata[i], &rom[0xF09D - 0x8000 + ((i - 32) * 8)], 8);
801   }
802
803   /* GIME field sync timer */
804   video->gime_fs_timer = machine.scheduler().timer_alloc(FUNC(gime_fs));
805
806   /* initialize the CoCo video code */
807   memset(&cfg, 0, sizeof(cfg));
808   cfg.type = type;
809   cfg.cpu0_timing_factor = 4;
810   cfg.get_attributes = coco_get_attributes;
811   cfg.get_video_ram = get_video_ram_coco3;
812   cfg.horizontal_sync_callback = coco3_horizontal_sync_callback;
813   cfg.field_sync_callback = coco3_field_sync_callback;
814   cfg.custom_palette = video->palette_colors;
815   cfg.new_frame_callback = coco3_new_frame;
816   cfg.custom_prepare_scanline = coco3_prepare_scanline;
817   m6847_init(machine, &cfg);
818
819   /* save state stuff */
820   state_save_register_global_array(machine, video->palette_ram);
821   state_save_register_global(machine, video->legacy_video);
822   state_save_register_global(machine, video->top_border_scanlines);
823   state_save_register_global(machine, video->display_scanlines);
824   machine.save().register_postload(save_prepost_delegate(FUNC(coco3_video_postload), state));
825}
826
827
828
829VIDEO_START( coco3 )
830{
831   internal_video_start_coco3(machine, M6847_VERSION_GIME_NTSC);
832}
833
834VIDEO_START( coco3p )
835{
836   internal_video_start_coco3(machine, M6847_VERSION_GIME_PAL);
837}
838
839
840
841void coco3_vh_blink(running_machine &machine)
842{
843   coco3_state *state = machine.driver_data<coco3_state>();
844   coco3_video *video = state->m_video;
845   video->blink = !video->blink;
846   coco3_set_dirty(machine);
847}
src/mess/video/gime.c
r0r13257
1/*********************************************************************
2 
3    gime.c
4 
5    Implementation of CoCo GIME (Graphics Interrupt Memory Enhancement)
6   video chip.   
7 
8    Mid frame raster effects (source John Kowalski)
9 
10        Here are the things that get changed mid-frame:
11 
12            - Palette registers ($FFB0-$FFBF)
13            - Horizontal resolution (switches between 256 and 320 pixels, $FF99)
14            - Horizontal scroll position (bits 0-6 $FF9F)
15            - Horizontal virtual screen (bit 7 $FF9F)
16            - Pixel height (bits 0-2 $FF98)
17            - Border color ($FF9A)
18 
19        On the positive side, you don't have to worry about registers
20        $FF9D/$FF9E being changed mid-frame.  Even if they are changed
21        mid-frame, they have no effect on the displayed image.  The video
22        address only gets latched at the top of the frame.
23 
24 
25   TIMING
26 
27   We divide a single frame into five regions
28 
29   Region            Scanlines (on 192)   Field Sync (before right border)
30   ------            ------------------   --------------------------------
31   Top Border         25               1
32   Body            192               1
33   Bottom Border      26               1
34   Vertical Retrace   6               0
35   Vertical Blanking   13 (or 13.5)      1
36 
37   Horizontal sync appears to be low only during retrace/blanking but
38   field sync switches as soon as the last body pixel is displayed
39 
40   Note that the GIME trailing edges field sync after the bottom
41   border; this is different than the MC6847
42 
43**********************************************************************
44 
45   SOFTWARE FOR TIMING TESTING
46 
47   Various CoCo 3 programs can "stress test" timing in various ways
48 
49   COLOR3: This program was in Rainbow January 1987.  It will synchronize
50   with field sync by polling bit 7 of $FF03 (PIA0) (specifically, it polls
51   until the rising edge of writes to PIA0 CB1).  This causes the loop to
52   be broken out at the top of vblank.  COLOR3 also synchronizes on
53   horizontal sync through PIA0; it counts 70 hsyncs to get to a point 32
54   scanlines into the body.
55 
56   DEMO: This SockMaster demo has a main loop that adjusts GIME registers
57   and shuffles some graphics bytes.  From a timing perspective, the
58   critical piece is a SYNC with PIA field sync (specifically, it SYNCs
59   with the trailing edge of writes to PIA0 CB1).  DEMO does not attempt
60   to synchronize on horizontal sync; it relies on CPU timing.
61 
62   MOON: SockMaster demo.  Uses GIME interrupts; FIRQ gets TMR interrupts
63   and IRQ gets VBORD interrupts.  Since it does not use the PIA field
64   sync, it can be used to demonstrate how the GIME's VBORD interrupt
65   is distinct.
66 
67   BOINK: SockMaster demo.  Like DEMO, it SYNCs on the trailing edge
68   of PIA field sync.  Also uses non standard $FF99 LPF mode.  If
69   BOINK "wobbles vertically", it suggests that the main loop is not
70   executing within a single field sync.  BOINK also makes extensive
71   use of $FF9F scrolling with bit 7 cleared.
72 
73   CRYSTAL CITY: Jeremy Spiller game.  The intro uses an attribute-less
74   GIME text mode
75 
76**********************************************************************/
77 
78#define ADDRESS_MAP_MODERN
79 
80#include "emu.h"
81#include "devcpu.h"
82#include "video/gime.h"
83#include "machine/6883sam.h"
84#include "machine/cococart.h"
85#include "machine/ram.h"
86 
87 
88 
89//**************************************************************************
90//  CONSTANTS
91//**************************************************************************
92 
93#define   USE_HORIZONTAL_CLIP      false
94#define GIME_TYPE_1987         0
95#define NO_ATTRIBUTE         0x80
96 
97#define LOG_INT_MASKING         0
98#define LOG_GIME            0
99#define LOG_TIMER            0
100 
101 
102 
103//**************************************************************************
104//  DEVICE SETUP
105//**************************************************************************
106 
107//-------------------------------------------------
108//  ctor
109//-------------------------------------------------
110 
111gime_base_device::gime_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const UINT8 *fontdata)
112   :   mc6847_friend_device(mconfig, type, name, tag, owner, clock, fontdata, true, 263, 25+192+26+3)
113{
114}
115 
116 
117 
118//-------------------------------------------------
119//  device_start - device-specific startup
120//-------------------------------------------------
121 
122void gime_base_device::device_start(void)
123{
124   /* get the config */
125   const gime_interface *config = (const gime_interface *) static_config();
126   assert(config);
127 
128   /* find the RAM device - make sure that it is started */
129   m_ram = machine().device<ram_device>(config->m_ram_tag);
130   if (!m_ram->started())
131      throw device_missing_dependencies();
132 
133   /* find the CART device - make sure that it is started */
134   cococart_slot_device *cart_device = machine().device<cococart_slot_device>(config->m_ext_tag);
135   if (!cart_device->started())
136      throw device_missing_dependencies();
137 
138   /* find the CPU device - make sure that it is started */
139   m_cpu = machine().device<cpu_device>(config->m_maincpu_tag);
140   if (!m_cpu->started())
141      throw device_missing_dependencies();
142 
143   /* inherited device_start - need to do this after checking dependencies */
144   super::device_start();
145 
146   /* initialize variables */
147   memset(m_scanlines, 0, sizeof(m_scanlines));
148   m_interrupt_value = 0x00;
149   m_irq = 0x00;
150   m_firq = 0x00;
151 
152   /* allocate timer */
153   m_gime_clock_timer = timer_alloc(TIMER_GIME_CLOCK);
154 
155   /* resolve callbacks */
156   m_res_out_hsync_func.resolve(config->m_out_hsync_func, *this);
157   m_res_out_fsync_func.resolve(config->m_out_fsync_func, *this);
158   m_res_out_irq_func.resolve(config->m_out_irq_func, *this);
159   m_res_out_firq_func.resolve(config->m_out_firq_func, *this);
160 
161   /* set up ROM/RAM pointers */
162   m_rom = machine().region(config->m_maincpu_tag)->base();
163   m_cart_rom = cart_device->get_cart_base();
164 
165   /* populate palettes */
166   for (int color = 0; color < 64; color++)
167   {
168      m_composite_palette[color] = get_composite_color(color);
169      m_composite_bw_palette[color] = black_and_white(m_composite_palette[color]);
170      m_rgb_palette[color] = get_rgb_color(color);
171   }
172 
173   /* set up save states */
174   save_pointer(NAME(m_gime_registers), ARRAY_LENGTH(m_gime_registers));
175   save_pointer(NAME(m_mmu), ARRAY_LENGTH(m_mmu));
176   save_item(NAME(m_sam_state));
177   save_item(NAME(m_ff22_value));
178   save_item(NAME(m_interrupt_value));
179   save_item(NAME(m_irq));
180   save_item(NAME(m_firq));
181   save_item(NAME(m_timer_value));
182   save_item(NAME(m_is_blinking));
183}
184 
185 
186 
187//-------------------------------------------------
188//  get_composite_color
189//-------------------------------------------------
190 
191ATTR_FORCE_INLINE gime_base_device::pixel_t gime_base_device::get_composite_color(int color)
192{
193   /* CMP colors
194     *
195     * These colors are of the format IICCCC, where II is the intensity and
196     * CCCC is the base color.  There is some weirdness because intensity
197     * is often different for each base color.
198     *
199     * The code below is based on an algorithm specified in the following
200     * CoCo BASIC program was used to approximate composite colors.
201     * (Program by SockMaster):
202     *
203     * 10 POKE65497,0:DIMR(63),G(63),B(63):WIDTH80:PALETTE0,0:PALETTE8,54:CLS1
204     * 20 SAT=92:CON=70:BRI=-50:L(0)=0:L(1)=47:L(2)=120:L(3)=255
205     * 30 W=.4195456981879*1.01:A=W*9.2:S=A+W*5:D=S+W*5:P=0:FORH=0TO3:P=P+1
206     * 40 BRI=BRI+CON:FORG=1TO15:R(P)=COS(A)*SAT+BRI
207     * 50 G(P)=(COS(S)*SAT)*1+BRI:B(P)=(COS(D)*SAT)*1+BRI:P=P+1
208     * 55 A=A+W:S=S+W:D=D+W:NEXT:R(P-16)=L(H):G(P-16)=L(H):B(P-16)=L(H)
209     * 60 NEXT:R(63)=R(48):G(63)=G(48):B(63)=B(48)
210     * 70 FORH=0TO63STEP1:R=INT(R(H)):G=INT(G(H)):B=INT(B(H)):IFR<0THENR=0
211     * 80 IFG<0THENG=0
212     * 90 IFB<0THENB=0
213     * 91 IFR>255THENR=255
214     * 92 IFG>255THENG=255
215     * 93 IFB>255THENB=255
216     * 100 PRINTRIGHT$(STR$(H),2);" $";:R=R+256:G=G+256:B=B+256
217     * 110 PRINTRIGHT$(HEX$(R),2);",$";RIGHT$(HEX$(G),2);",$";RIGHT$(HEX$(B),2)
218     * 115 IF(H AND15)=15 THENIFINKEY$=""THEN115ELSEPRINT
219     * 120 NEXT
220     *
221     *  At one point, we used a different SockMaster program, but the colors
222     *  produced were too dark for people's taste
223     *
224     *  10 POKE65497,0:DIMR(63),G(63),B(63):WIDTH80:PALETTE0,0:PALETTE8,54:CLS1
225     *  20 SAT=92:CON=53:BRI=-16:L(0)=0:L(1)=47:L(2)=120:L(3)=255
226     *  30 W=.4195456981879*1.01:A=W*9.2:S=A+W*5:D=S+W*5:P=0:FORH=0TO3:P=P+1
227     *  40 BRI=BRI+CON:FORG=1TO15:R(P)=COS(A)*SAT+BRI
228     *  50 G(P)=(COS(S)*SAT)*.50+BRI:B(P)=(COS(D)*SAT)*1.9+BRI:P=P+1
229     *  55 A=A+W:S=S+W:D=D+W:NEXT:R(P-16)=L(H):G(P-16)=L(H):B(P-16)=L(H)
230     *  60 NEXT:R(63)=R(48):G(63)=G(48):B(63)=B(48)
231     *  70 FORH=0TO63STEP1:R=INT(R(H)):G=INT(G(H)):B=INT(B(H)):IFR<0THENR=0
232     *  80 IFG<0THENG=0
233     *  90 IFB<0THENB=0
234     *  91 IFR>255THENR=255
235     *  92 IFG>255THENG=255
236     *  93 IFB>255THENB=255
237     *  100 PRINTRIGHT$(STR$(H),2);" $";:R=R+256:G=G+256:B=B+256
238     *  110 PRINTRIGHT$(HEX$(R),2);",$";RIGHT$(HEX$(G),2);",$";RIGHT$(HEX$(B),2)
239     *  115 IF(H AND15)=15 THENIFINKEY$=""THEN115ELSEPRINT
240     *  120 NEXT
241     */
242 
243   double saturation, brightness, contrast;
244   int offset;
245   double w;
246   int r, g, b;
247 
248   switch(color)
249   {
250      case 0:
251         r = g = b = 0;
252         break;
253 
254      case 16:
255         r = g = b = 47;
256         break;
257 
258      case 32:
259         r = g = b = 120;
260         break;
261 
262      case 48:
263      case 63:
264         r = g = b = 255;
265         break;
266 
267      default:
268         w = .4195456981879*1.01;
269         contrast = 70;
270         saturation = 92;
271         brightness = -50;
272         brightness += ((color / 16) + 1) * contrast;
273         offset = (color % 16) - 1 + (color / 16)*15;
274         r = cos(w*(offset +  9.2)) * saturation + brightness;
275         g = cos(w*(offset + 14.2)) * saturation + brightness;
276         b = cos(w*(offset + 19.2)) * saturation + brightness;
277 
278         if (r < 0)
279            r = 0;
280         else if (r > 255)
281            r = 255;
282 
283         if (g < 0)
284            g = 0;
285         else if (g > 255)
286            g = 255;
287 
288         if (b < 0)
289            b = 0;
290         else if (b > 255)
291            b = 255;
292         break;
293   }
294   return (pixel_t) ((r << 16) | (g << 8) | (b << 0));
295}
296 
297 
298 
299//-------------------------------------------------
300//  get_rgb_color
301//-------------------------------------------------
302 
303ATTR_FORCE_INLINE gime_base_device::pixel_t gime_base_device::get_rgb_color(int color)
304{
305   return   (((color >> 4) & 2) | ((color >> 2) & 1)) * 0x550000
306      |   (((color >> 3) & 2) | ((color >> 1) & 1)) * 0x005500
307      |   (((color >> 2) & 2) | ((color >> 0) & 1)) * 0x000055;
308}
309 
310 
311 
312//-------------------------------------------------
313//  device_reset - device-specific reset
314//-------------------------------------------------
315 
316void gime_base_device::device_reset(void)
317{
318   /* Tepolt verifies that the GIME registers are all cleared on initialization */
319   memset(m_gime_registers, 0, sizeof(m_gime_registers));
320 
321   /* initialize MMU */
322   for (int i = 0; i < 8; i++)
323      m_mmu[i] = m_mmu[i + 8] = 56 + i;
324 
325   /* initialize palette */
326   memset(m_palette_rotated, 0, sizeof(m_palette_rotated));
327   m_palette_rotated_position = 0;
328   m_palette_rotated_position_used = false;
329 
330   /* clear SAM state */
331   m_sam_state = 0x0000;
332 
333   /* clear interrupts */
334   m_interrupt_value = 0x00;
335   m_irq = 0x00;
336   m_firq = 0x00;
337   m_is_blinking = false;
338 
339   update_memory();
340   reset_timer();
341}
342 
343 
344 
345//-------------------------------------------------
346//  device_pre_save - device-specific pre save
347//-------------------------------------------------
348 
349void gime_base_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
350{
351   switch(id)
352   {
353      case TIMER_GIME_CLOCK:
354         timer_elapsed();
355         break;
356 
357      default:
358         super::device_timer(timer, id, param, ptr);
359         break;
360   }
361}
362 
363 
364 
365//-------------------------------------------------
366//  device_post_load - device-specific post load
367//-------------------------------------------------
368 
369void gime_base_device::device_post_load()
370{
371   super::device_post_load();
372   update_memory();
373}
374 
375 
376 
377//-------------------------------------------------
378//  device_input_ports
379//-------------------------------------------------
380 
381ioport_constructor gime_base_device::device_input_ports() const
382{
383   return INPUT_PORTS_NAME(mc6847_artifacting);
384}
385 
386 
387 
388//**************************************************************************
389//  TIMER
390// 
391//   The CoCo 3 had a timer that had would activate when first written to, and
392//   would decrement over and over again until zero was reached, and at that
393//   point, would flag an interrupt.  At this point, the timer starts back up
394//   again.
395//
396//   I am deducing that the timer interrupt line was asserted if the timer was
397//   zero and unasserted if the timer was non-zero.  Since we never truly track
398//   the timer, we just use timer callback (coco3_timer_callback() asserts the
399//   line)
400//
401//   Most CoCo 3 docs, including the specs that Tandy released, say that the
402//   high speed timer is 70ns (half of the speed of the main clock crystal).
403//   However, it seems that this is in error, and the GIME timer is really a
404//   280ns timer (one eighth the speed of the main clock crystal.  Gault's
405//   FAQ agrees with this
406//
407//**************************************************************************
408 
409//-------------------------------------------------
410//  timer_type
411//-------------------------------------------------
412 
413gime_base_device::timer_type_t gime_base_device::timer_type(void)
414{
415   // wraps the GIME register access and returns an enumeration
416   return (m_gime_registers[0x01] & 0x20) ? GIME_TIMER_CLOCK : GIME_TIMER_HBORD;
417}
418 
419 
420 
421//-------------------------------------------------
422//  timer_type_string
423//-------------------------------------------------
424 
425const char *gime_base_device::timer_type_string(void)
426{
427   const char *result;
428   switch(timer_type())
429   {
430      case GIME_TIMER_CLOCK:
431         result = "CLOCK";
432         break;
433      case GIME_TIMER_HBORD:
434         result = "HBORD";
435         break;
436      default:
437         fatalerror("Should not get here");
438         break;
439   }
440   return result;
441}
442 
443 
444 
445//-------------------------------------------------
446//  timer_elapsed
447//-------------------------------------------------
448 
449void gime_base_device::timer_elapsed(void)
450{
451   /* reset the timer; give her another run! */
452   reset_timer();
453 
454   /* change the blinking value - note that we don't have to use update_value() */
455   m_is_blinking = !m_is_blinking;
456 
457   /* twiddle the timer interrupt */
458   set_interrupt_value(INTERRUPT_TMR, true);
459   set_interrupt_value(INTERRUPT_TMR, false);
460}
461 
462 
463 
464//-------------------------------------------------
465//  reset_timer
466//-------------------------------------------------
467 
468void gime_base_device::reset_timer(void)
469{
470   /* value is from 0-4095 */
471   m_timer_value = ((m_gime_registers[0x04] & 0x0F) * 0x100) | m_gime_registers[0x05];
472 
473   /* depending on the GIME type, cannonicalize the value */
474   if (m_timer_value > 0)
475   {
476      if (GIME_TYPE_1987)
477         m_timer_value += 1;   /* the 1987 GIME reset to the value plus one */
478      else
479         m_timer_value += 2;   /* the 1986 GIME reset to the value plus two */
480   }
481 
482   attotime duration;
483   if ((timer_type() == GIME_TIMER_CLOCK) && (m_timer_value > 0))
484   {
485      /* we're starting a countdown on the GIME clock timer */
486      attotime current_time = machine().time();
487      UINT64 current_tick = current_time.as_ticks(m_clock);
488      duration = attotime::from_ticks(current_tick + m_timer_value, m_clock) - current_time;
489   }
490   else
491   {
492      /* either the timer is off, or were not using the GIME clock timer */
493      duration = attotime::never;
494   }
495   m_gime_clock_timer->adjust(duration);
496 
497   if (LOG_TIMER)
498      logerror("%s: reset_timer(): timer_type=%s value=%d\n", describe_context(), timer_type_string(), m_timer_value);
499}
500 
501 
502 
503//**************************************************************************
504//  MEMORY AND REGISTERS
505//**************************************************************************
506 
507//-------------------------------------------------
508//  update_memory
509//-------------------------------------------------
510 
511ATTR_FORCE_INLINE void gime_base_device::update_memory(void)
512{
513   for (int bank = 0; bank <= 8; bank++)
514   {
515      update_memory(bank);
516   }
517}
518 
519 
520 
521//-------------------------------------------------
522//  update_memory
523//-------------------------------------------------
524 
525void gime_base_device::update_memory(int bank)
526{
527   static const char *rbanks[] = { "rbank0", "rbank1", "rbank2", "rbank3", "rbank4", "rbank5", "rbank6", "rbank7", "rbank8" };
528   static const char *wbanks[] = { "wbank0", "wbank1", "wbank2", "wbank3", "wbank4", "wbank5", "wbank6", "wbank7", "wbank8" };
529 
530   /* look up the bank tags */
531   assert((bank >= 0) && (bank < ARRAY_LENGTH(rbanks)) && (bank < ARRAY_LENGTH(wbanks)));
532   const char *rbank = rbanks[bank];
533   const char *wbank = wbanks[bank];
534 
535   /* bank 8 is really $FE00-$FEFF; it is weird so adjust for it */
536   offs_t offset;
537   bool force_ram;
538   bool enable_mmu = (m_gime_registers[0] & 0x40) ? true : false;
539   if (bank == 8)
540   {
541      bank = 7;
542      offset = 0x1E00;
543      force_ram = true;
544      enable_mmu = enable_mmu && !(m_gime_registers[0] & 0x08);
545   }
546   else
547   {
548      offset = 0x0000;
549      force_ram = false;
550   }
551 
552   /* is the MMU enabled at $FF90? */
553   int block;
554   if (enable_mmu)
555   {
556      /* check TR register at $FF91 */
557      bank += (m_gime_registers[1] & 0x01) ? 8 : 0;
558 
559      /* perform the MMU lookup */
560      block = m_mmu[bank];
561 
562      /* also check $FF9B - relevant for the 2 MB upgrade */
563      block |= ((UINT32) ((m_gime_registers[11] >> 4) & 0x03)) << 8;
564   }
565   else
566   {
567      /* the MMU is not enabled */
568      block = bank + 56;
569   }
570 
571   /* are we actually in ROM? */
572   UINT8 *memory;
573   bool is_read_only;
574   if (((block & 0x3F) >= 0x3C) && !(m_sam_state & SAM_STATE_TY) && !force_ram)
575   {
576      /* we're in ROM */
577      static const UINT8 rom_map[4][4] =
578      {
579         { 0, 1, 6, 7 },
580         { 0, 1, 6, 7 },
581         { 0, 1, 2, 3 },
582         { 4, 5, 6, 7 }
583      };
584 
585      /* look up the block in the ROM map */
586      block = rom_map[m_gime_registers[0] & 3][(block & 0x3F) - 0x3C];
587 
588      /* are we in onboard ROM or cart ROM? */
589      UINT8 *rom_ptr = (block & 4) ? m_cart_rom : m_rom;
590 
591      /* perform the look up */
592      memory = &rom_ptr[(block & 3) * 0x2000];
593      is_read_only = true;
594   }
595   else
596   {
597      /* we're in RAM */
598      memory = memory_pointer(block * 0x2000);
599      is_read_only = false;
600   }
601 
602   /* compensate for offset */
603   memory += offset;
604 
605   /* set the banks */
606   memory_set_bankptr(machine(), rbank, memory);
607   memory_set_bankptr(machine(), wbank, is_read_only ? m_dummy_bank : memory);
608}
609 
610 
611 
612//-------------------------------------------------
613//  memory_pointer
614//-------------------------------------------------
615 
616UINT8 *gime_base_device::memory_pointer(UINT32 address)
617{
618   return &m_ram->pointer()[address % m_ram->size()];
619}
620 
621 
622 
623//-------------------------------------------------
624//  read
625//-------------------------------------------------
626 
627UINT8 gime_base_device::read(offs_t offset)
628{
629   UINT8 data = 0x00;
630 
631   switch(offset & 0xF0)
632   {
633      case 0x00:
634         data = read_gime_register(offset);
635         break;
636 
637      case 0x10:
638         data = read_mmu_register(offset);
639         break;
640 
641      case 0x20:
642         data = read_palette_register(offset);
643         break;
644   }
645 
646   return data;
647}
648 
649 
650 
651//-------------------------------------------------
652//  read_gime_register
653//-------------------------------------------------
654 
655ATTR_FORCE_INLINE UINT8 gime_base_device::read_gime_register(offs_t offset)
656{
657   offset &= 0x0F;
658 
659   UINT8 result;
660   switch(offset)
661   {
662      case 2:   /* Read pending IRQs */
663         result = m_irq;
664         if (result != 0x00)
665         {
666            m_irq = 0x00;
667            recalculate_irq();
668         }
669         break;
670 
671      case 3:   /* Read pending FIRQs */
672         result = m_firq;
673         if (result != 0x00)
674         {
675            m_firq = 0x00;
676            recalculate_firq();
677         }
678         break;
679 
680      case 4:   /* Timer MSB/LSB; these arn't readable */
681      case 5:
682         /* JK tells me that these values are indeterminate; and $7E appears
683          * to be the value most commonly returned
684          */
685         result = 0x7E;
686         break;
687 
688      default:
689         result = m_gime_registers[offset];
690         break;
691   }
692   return result;
693}
694 
695 
696 
697//-------------------------------------------------
698//  read_mmu_register
699//-------------------------------------------------
700 
701ATTR_FORCE_INLINE UINT8 gime_base_device::read_mmu_register(offs_t offset)
702{
703   return m_mmu[offset & 0x0F];
704}
705 
706 
707 
708//-------------------------------------------------
709//  read_palette_register
710//-------------------------------------------------
711 
712ATTR_FORCE_INLINE UINT8 gime_base_device::read_palette_register(offs_t offset)
713{
714   return m_palette_rotated[m_palette_rotated_position][offset & 0x0F] | 0x40;
715}
716 
717 
718 
719//-------------------------------------------------
720//  write
721//-------------------------------------------------
722 
723void gime_base_device::write(offs_t offset, UINT8 data)
724{
725   switch(offset & 0xF0)
726   {
727      case 0x00:
728         write_gime_register(offset & 0x0F, data);
729         break;
730 
731      case 0x10:
732         write_mmu_register(offset & 0x0F, data & 0x3F);
733         break;
734 
735      case 0x20:
736         write_palette_register(offset & 0x0F, data & 0x3F);
737         break;
738 
739      case 0x30:
740      case 0x40:
741         write_sam_register(offset - 0x30);
742         break;
743   }
744}
745 
746 
747 
748//-------------------------------------------------
749//  write_gime_register
750//-------------------------------------------------
751 
752ATTR_FORCE_INLINE void gime_base_device::write_gime_register(offs_t offset, UINT8 data)
753{
754   // this is needed for writes to FF95
755   bool timer_was_off = (m_gime_registers[0x04] == 0x00) && (m_gime_registers[0x05] == 0x00);
756 
757   // sanity check input
758   offset &= 0x0F;
759 
760   // perform logging
761   if (LOG_GIME)
762      logerror("%s: CoCo3 GIME: $%04x <== $%02x\n", describe_context(), offset + 0xff90, data);
763 
764   // make the change, and track the difference
765   UINT8 xorval = m_gime_registers[offset] ^ data;
766   m_gime_registers[offset] = data;
767 
768   switch(offset)
769   {
770      case 0x00:
771         // $FF90 Initialization register 0
772            //        Bit 7 COCO 1=CoCo compatible mode
773            //        Bit 6 MMUEN 1=MMU enabled
774            //        Bit 5 IEN 1 = GIME chip IRQ enabled
775            //        Bit 4 FEN 1 = GIME chip FIRQ enabled
776            //        Bit 3 MC3 1 = RAM at FEXX is constant
777            //        Bit 2 MC2 1 = standard SCS (Spare Chip Select)
778            //        Bit 1 MC1 ROM map control
779            //        Bit 0 MC0 ROM map control
780         if (xorval & 0x4B)
781            update_memory();
782            break;
783 
784      case 0x01:
785         //  $FF91 Initialization register 1
786            //        Bit 7 Unused
787            //        Bit 6 Unused
788            //        Bit 5 TINS Timer input select; 1 = 280 nsec, 0 = 63.5 usec
789            //        Bit 4 Unused
790            //        Bit 3 Unused
791            //        Bit 2 Unused
792            //        Bit 1 Unused
793            //        Bit 0 TR Task register select
794         if (xorval & 0x01)
795            update_memory();
796 
797         // I'm not sure about this one; as written this code will reset the timer
798         // with the _original_ value.  This is probably not correct.
799         if (xorval & 0x20)
800            reset_timer();
801            break;
802 
803      case 0x02:
804         //  $FF92 Interrupt request enable register
805            //        Bit 7 Unused
806            //        Bit 6 Unused
807            //        Bit 5 TMR Timer interrupt
808            //        Bit 4 HBORD Horizontal border interrupt
809            //        Bit 3 VBORD Vertical border interrupt
810            //      ! Bit 2 EI2 Serial data interrupt
811            //        Bit 1 EI1 Keyboard interrupt
812            //        Bit 0 EI0 Cartridge interrupt
813         if (LOG_INT_MASKING)
814         {
815            logerror("%s: GIME IRQ: Interrupts { %s%s%s%s%s%s} enabled\n",
816               describe_context(), 
817               (data & 0x20) ? "TMR " : "",
818               (data & 0x10) ? "HBORD " : "",
819               (data & 0x08) ? "VBORD " : "",
820               (data & 0x04) ? "EI2 " : "",
821               (data & 0x02) ? "EI1 " : "",
822               (data & 0x01) ? "EI0 " : "");
823         }
824            break;
825 
826      case 0x03:
827         //  $FF93 Fast interrupt request enable register
828            //        Bit 7 Unused
829            //        Bit 6 Unused
830            //        Bit 5 TMR Timer interrupt
831            //        Bit 4 HBORD Horizontal border interrupt
832            //        Bit 3 VBORD Vertical border interrupt
833            //      ! Bit 2 EI2 Serial data interrupt
834            //        Bit 1 EI1 Keyboard interrupt
835            //        Bit 0 EI0 Cartridge interrupt
836         if (LOG_INT_MASKING)
837         {
838            logerror("%s: GIME FIRQ: Interrupts { %s%s%s%s%s%s} enabled\n",
839               describe_context(),
840               (data & 0x20) ? "TMR " : "",
841               (data & 0x10) ? "HBORD " : "",
842               (data & 0x08) ? "VBORD " : "",
843               (data & 0x04) ? "EI2 " : "",
844               (data & 0x02) ? "EI1 " : "",
845               (data & 0x01) ? "EI0 " : "");
846         }
847            break;
848 
849      case 0x04:
850         //  $FF94 Timer register MSB
851            //        Bits 4-7 Unused
852            //        Bits 0-3 High order four bits of the timer
853         reset_timer();
854         break;
855 
856      case 0x05:
857         //  $FF95 Timer register LSB
858         //        Bits 0-7 Low order eight bits of the timer
859         if (timer_was_off && (m_gime_registers[0x05] != 0x00))
860         {
861            // Writes to $FF95 do not cause the timer to reset, but MESS
862            // will invoke coco3_timer_reset() if $FF94/5 was previously
863            // $0000.  The reason for this is because the timer is not
864            // actually off when $FF94/5 are loaded with $0000; rather it
865            // is continuously reloading the GIME's internal countdown
866            // register, even if it isn't causing interrupts to be raised.
867            //
868            // Failure to do this was the cause of bug #1065.  Special
869            // thanks to John Kowalski for pointing me in the right
870            // direction
871            reset_timer();
872         }
873         break;
874 
875      case 0x08:
876         //  $FF98 Video Mode Register
877            //        Bit 7 BP 0 = Text modes, 1 = Graphics modes
878            //        Bit 6 Unused
879            //      ! Bit 5 BPI Burst Phase Invert (Color Set)
880            //        Bit 4 MOCH 1 = Monochrome on Composite
881            //      ! Bit 3 H50 1 = 50 Hz power, 0 = 60 Hz power
882            //        Bits 0-2 LPR Lines per row
883         break;
884 
885      case 0x09:
886         //  $FF99 Video Resolution Register
887            //        Bit 7 Undefined
888            //        Bits 5-6 LPF Lines per Field (Number of Rows)
889            //        Bits 2-4 HRES Horizontal Resolution
890            //                     000=16 bytes per row
891            //                     001=20 bytes per row
892            //                     010=32 bytes per row
893            //                     011=40 bytes per row
894            //                     100=64 bytes per row
895            //                     101=80 bytes per row
896            //                     110=128 bytes per row
897            //                     111=160 bytes per row
898            //        Bits 0-1 CRES Color Resolution
899         if (xorval & 0x60)
900            update_geometry();
901         break;
902 
903      case 0x0A:
904         //  $FF9A Border Register
905            //        Bits 6,7 Unused
906            //        Bits 0-5 BRDR Border color
907         break;
908 
909      case 0x0C:
910         //  $FF9C Vertical Scroll Register
911            //        Bits 4-7 Reserved
912            //        Bits 0-3 VSC Vertical Scroll bits
913         break;
914 
915      case 0x0B:
916      case 0x0D:
917      case 0x0E:
918         //  $FF9B,$FF9D,$FF9E Vertical Offset Registers
919         //
920            //  According to JK, if an odd value is placed in $FF9E on the 1986
921            //  GIME, the GIME crashes
922            //
923            // The reason that $FF9B is not mentioned in offical documentation
924            // is because it is only meaninful in CoCo 3's with the 2MB upgrade
925            break;
926 
927      case 0x0F:
928            //  $FF9F Horizontal Offset Register
929            //       Bit 7 HVEN Horizontal Virtual Enable
930            //       Bits 0-6 X0-X6 Horizontal Offset Address
931         //
932            //  Unline $FF9D-E, this value can be modified mid frame
933         //
934         //   Note that the FF9F offset is shifted by one bit (e.g. - $FF9F=$03 will
935         //   be a six byte offset).  Also note that scanlines wrap at 256 byte boundaries
936         //   without regard to bit 7.
937         break;
938   }
939}
940 
941 
942 
943//-------------------------------------------------
944//  write_mmu_register
945//-------------------------------------------------
946 
947ATTR_FORCE_INLINE void gime_base_device::write_mmu_register(offs_t offset, UINT8 data)
948{
949   offset &= 0x0F;
950   if (m_mmu[offset] != data)
951   {
952      m_mmu[offset] = data;
953      update_memory(offset & 0x07);
954   }
955}
956 
957 
958 
959//-------------------------------------------------
960//  write_palette_register
961//-------------------------------------------------
962 
963ATTR_FORCE_INLINE void gime_base_device::write_palette_register(offs_t offset, UINT8 data)
964{
965   offset &= 0x0F;
966 
967   /* has this entry changed? */
968   if (m_palette_rotated[m_palette_rotated_position][offset] != data)
969   {
970      /* do we need to rotate the palette? */
971      if (m_palette_rotated_position_used)
972      {
973         /* identify the new position */
974         UINT16 new_palette_rotated_position = (m_palette_rotated_position + 1) % ARRAY_LENGTH(m_palette_rotated);
975 
976         /* copy the palette */
977         for (int i = 0; i < ARRAY_LENGTH(m_palette_rotated[0]); i++)
978            m_palette_rotated[new_palette_rotated_position][i] = m_palette_rotated[m_palette_rotated_position][i];
979 
980         /* and advance */
981         m_palette_rotated_position = new_palette_rotated_position;
982         m_palette_rotated_position_used = false;
983      }
984 
985      /* record the change */;
986      m_palette_rotated[m_palette_rotated_position][offset] = data;
987   }
988}
989 
990 
991 
992//-------------------------------------------------
993//  write_sam_register
994//-------------------------------------------------
995 
996ATTR_FORCE_INLINE void gime_base_device::write_sam_register(offs_t offset)
997{
998   /* change the SAM state */
999   UINT16 xorval = alter_sam_state(offset);
1000 
1001   /* $FFDE-F can trigger a memory update */
1002   if (xorval & SAM_STATE_TY)
1003      update_memory();
1004 
1005   if (xorval & (SAM_STATE_R1|SAM_STATE_R0))
1006      update_cpu_clock();
1007}
1008 
1009 
1010 
1011//-------------------------------------------------
1012//  interrupt_rising_edge
1013//-------------------------------------------------
1014 
1015void gime_base_device::interrupt_rising_edge(UINT8 interrupt)
1016{
1017   /* evaluate IRQ */
1018   if ((m_gime_registers[0x00] & 0x20) && (m_gime_registers[0x02] & interrupt))
1019   {
1020      m_irq |= interrupt;
1021      recalculate_irq();
1022   }
1023 
1024   /* evaluate FIRQ */
1025   if ((m_gime_registers[0x00] & 0x10) && (m_gime_registers[0x03] & interrupt))
1026   {
1027      m_firq |= interrupt;
1028      recalculate_firq();
1029   }
1030}
1031 
1032 
1033 
1034//-------------------------------------------------
1035//  recalculate_irq
1036//-------------------------------------------------
1037 
1038void gime_base_device::recalculate_irq(void)
1039{
1040   if (!m_res_out_irq_func.isnull())
1041      m_res_out_irq_func(irq_r());
1042}
1043 
1044 
1045 
1046//-------------------------------------------------
1047//  recalculate_firq
1048//-------------------------------------------------
1049 
1050void gime_base_device::recalculate_firq(void)
1051{
1052   if (!m_res_out_firq_func.isnull())
1053      m_res_out_firq_func(firq_r());
1054}
1055 
1056 
1057 
1058//**************************************************************************
1059//  VIDEO STATE
1060//**************************************************************************
1061 
1062//-------------------------------------------------
1063//  get_video_base
1064//
1065//   The purpose of the ff9d_mask and ff9e_mask is to mask out bits that are
1066//   ignored in lo-res mode.  Specifically, $FF9D is masked with $E0, and
1067//   $FF9E is masked with $3F
1068//
1069//   John Kowalski confirms this behavior
1070//-------------------------------------------------
1071 
1072ATTR_FORCE_INLINE offs_t gime_base_device::get_video_base(void)
1073{
1074   offs_t result;
1075   UINT8 ff9d_mask, ff9e_mask;
1076 
1077   if (m_legacy_video)
1078   {
1079      /* legacy video gets the base address from the SAM addresses, and masks out GIME variables */
1080      result = display_offset();
1081      ff9d_mask = 0xE0;
1082      ff9e_mask = 0x3F;
1083   }
1084   else
1085   {
1086      /* GIME video ignores the SAM addresses, relying on the GIME variables exclusively */
1087      result = 0;
1088      ff9d_mask = 0xFF;
1089      ff9e_mask = 0xFF;
1090   }
1091 
1092   result += ((offs_t) (m_gime_registers[0x0E] & ff9e_mask)   * 0x00008)
1093         | ((offs_t) (m_gime_registers[0x0D] & ff9d_mask)   * 0x00800)
1094         | ((offs_t) (m_gime_registers[0x0B] & 0x0F)         * 0x80000);
1095   return result;
1096}
1097 
1098 
1099 
1100//-------------------------------------------------
1101//  new_frame
1102//-------------------------------------------------
1103 
1104void gime_base_device::new_frame(void)
1105{
1106   /* call inherited function */
1107   super::new_frame();
1108 
1109   /* latch in legacy video value */
1110   bool legacy_video_changed = update_value(&m_legacy_video, m_gime_registers[0] & 0x80 ? true : false);
1111 
1112   /* latch in the video position */
1113   m_video_position = get_video_base();
1114   m_line_in_row = m_gime_registers[0x0C] & 0x0F;
1115 
1116   /* update the geometry, as appropriate */
1117   if (legacy_video_changed)
1118      update_geometry();
1119}
1120 
1121 
1122 
1123//-------------------------------------------------
1124//  horizontal_sync_changed
1125//-------------------------------------------------
1126 
1127void gime_base_device::horizontal_sync_changed(bool line)
1128{
1129   set_interrupt_value(INTERRUPT_HBORD, line);
1130 
1131   /* decrement timer if appropriate */
1132   if ((timer_type() == GIME_TIMER_HBORD) && (m_timer_value > 0) && line)
1133   {
1134      if (--m_timer_value == 0)
1135         timer_elapsed();
1136   }
1137 
1138}
1139 
1140 
1141 
1142//-------------------------------------------------
1143//  enter_bottom_border
1144//-------------------------------------------------
1145 
1146void gime_base_device::enter_bottom_border(void)
1147{
1148   set_interrupt_value(INTERRUPT_VBORD, true);
1149   set_interrupt_value(INTERRUPT_VBORD, false);
1150}
1151 
1152 
1153 
1154//-------------------------------------------------
1155//  update_border
1156//-------------------------------------------------
1157 
1158void gime_base_device::update_border(UINT16 physical_scanline)
1159{
1160   UINT8 border;
1161   if (m_legacy_video)
1162   {
1163      /* legacy video */
1164      switch(border_value(m_ff22_value, true))
1165      {
1166         case BORDER_COLOR_GREEN:
1167            border = 0x12;      /* green */
1168            break;
1169         case BORDER_COLOR_WHITE:
1170            border = 0x3F;      /* white */
1171            break;
1172         case BORDER_COLOR_BLACK:
1173            border = 0x00;      /* black */
1174            break;
1175         case BORDER_COLOR_ORANGE:         
1176            border = 0x26;      /* orange */
1177            break;
1178         default:
1179            fatalerror("Should not get here");
1180            break;
1181      }
1182   }
1183   else
1184   {
1185      /* get the border value from $FF9A */
1186      border = m_gime_registers[0x0A] & 0x3F;
1187   }
1188   update_value(&m_scanlines[physical_scanline].m_border, border);
1189}
1190 
1191 
1192 
1193//-------------------------------------------------
1194//  record_border_scanline
1195//-------------------------------------------------
1196 
1197void gime_base_device::record_border_scanline(UINT16 physical_scanline)
1198{
1199   m_line_in_row = 0;
1200   update_border(physical_scanline);
1201   update_value(&m_scanlines[physical_scanline].m_line_in_row, (UINT8) ~0);
1202}
1203 
1204 
1205 
1206//-------------------------------------------------
1207//  get_lines_per_row
1208//-------------------------------------------------
1209 
1210ATTR_FORCE_INLINE UINT16 gime_base_device::get_lines_per_row(void)
1211{
1212   UINT16 lines_per_row;
1213   if (m_legacy_video)
1214   {
1215      switch(m_ff22_value & (MODE_AG|MODE_GM2|MODE_GM1|MODE_GM0))
1216      {
1217         case 0:
1218         case MODE_GM0:
1219         case MODE_GM1:
1220         case MODE_GM1|MODE_GM0:
1221         case MODE_GM2:
1222         case MODE_GM2|MODE_GM0:
1223         case MODE_GM2|MODE_GM1:
1224         case MODE_GM2|MODE_GM1|MODE_GM0:
1225            lines_per_row = 12;
1226            break;
1227 
1228         case MODE_AG:
1229         case MODE_AG|MODE_GM0:
1230         case MODE_AG|MODE_GM1:
1231            lines_per_row = 3;
1232            break;
1233 
1234         case MODE_AG|MODE_GM1|MODE_GM0:
1235         case MODE_AG|MODE_GM2:
1236            lines_per_row = 2;
1237            break;
1238 
1239         case MODE_AG|MODE_GM2|MODE_GM0:
1240         case MODE_AG|MODE_GM2|MODE_GM1:
1241         case MODE_AG|MODE_GM2|MODE_GM1|MODE_GM0:
1242            lines_per_row = 1;
1243            break;
1244 
1245         default:
1246            fatalerror("Should not get here");
1247            break;
1248      }
1249   }
1250   else
1251   {
1252      switch(m_gime_registers[0x08] & 0x07)
1253      {
1254         case 0x00:
1255         case 0x01:
1256            lines_per_row = 1;
1257            break;
1258         case 0x02:
1259            lines_per_row = 2;
1260            break;
1261         case 0x03:
1262            lines_per_row = 8;
1263            break;
1264         case 0x04:
1265            lines_per_row = 9;
1266            break;
1267         case 0x05:
1268            lines_per_row = 10;
1269            break;
1270         case 0x06:
1271            lines_per_row = 11;
1272            break;
1273         case 0x07:
1274            lines_per_row = 0xFFFF;
1275            break;
1276         default:
1277            fatalerror("Should not get here");
1278            break;
1279      }
1280   }
1281   return lines_per_row;
1282}
1283 
1284 
1285 
1286//-------------------------------------------------
1287//  record_scanline_res
1288//-------------------------------------------------
1289 
1290template<UINT8 xres, gime_base_device::get_data_func get_data, bool record_mode>
1291ATTR_FORCE_INLINE UINT32 gime_base_device::record_scanline_res(int scanline)
1292{
1293   int column;
1294   UINT32 base_offset = m_legacy_video ? 0 : (m_gime_registers[0x0F] & 0x7F) * 2;
1295   UINT32 offset = 0;
1296 
1297   /* main loop */
1298   for (column = 0; column < xres; column++)
1299   {
1300      /* input data */
1301      UINT8 data, mode;
1302      offset += ((*this).*(get_data))(m_video_position + ((base_offset + offset) & 0xFF), &data, &mode);
1303 
1304      /* and record the pertinent values */
1305      if (record_mode)
1306         update_value(&m_scanlines[scanline].m_mode[column], mode);
1307      update_value(&m_scanlines[scanline].m_data[column], data);
1308      update_value(&m_scanlines[scanline].m_palette[column], m_palette_rotated_position);
1309   }
1310 
1311   return offset;
1312}
1313 
1314 
1315 
1316//-------------------------------------------------
1317//  get_data_mc6847 - used for retrieving data/mode
1318//   in legacy video modes
1319//-------------------------------------------------
1320 
1321UINT32 gime_base_device::get_data_mc6847(UINT32 video_position, UINT8 *data, UINT8 *mode)
1322{
1323   *data = *memory_pointer(video_position);
1324   *mode = (m_ff22_value & (MODE_AG|MODE_GM2|MODE_GM1|MODE_GM0|MODE_CSS))
1325      | ((*data & 0x80) == 0x80 ? MODE_AS : 0)
1326      | ((*data & 0xC0) == 0x40 ? MODE_INV : 0);
1327 
1328   // postprocess the mode to remove unnecessary flags
1329   *mode = mc6847_friend_device::simplify_mode(*data, *mode);
1330   return 1;
1331}
1332 
1333 
1334 
1335//-------------------------------------------------
1336//  get_data_without_attributes - used for
1337//  retrieving data/mode in GIME graphics or GIME
1338//   text modes without attributes
1339//-------------------------------------------------
1340 
1341UINT32 gime_base_device::get_data_without_attributes(UINT32 video_position, UINT8 *data, UINT8 *mode)
1342{
1343   *data = *memory_pointer(video_position);
1344   *mode = NO_ATTRIBUTE;
1345   return 1;
1346}
1347 
1348 
1349 
1350//-------------------------------------------------
1351//  get_data_with_attributes - used for retrieving
1352//   data/mode in GIME text modes with attributes
1353//-------------------------------------------------
1354 
1355UINT32 gime_base_device::get_data_with_attributes(UINT32 video_position, UINT8 *data, UINT8 *mode)
1356{
1357   *data = *memory_pointer(video_position + 0);
1358   *mode = *memory_pointer(video_position + 1);
1359 
1360   /* is the blink attribute specified? */
1361   if (UNEXPECTED(*mode) & 0x80)
1362   {
1363      /* if so - and we're blinking - then clear the character */
1364      if (m_is_blinking)
1365      {
1366         *data = 0x20;
1367         *mode &= ~0x40;
1368      }
1369 
1370      /* clear the blink bit */
1371      *mode &= ~0x80;
1372   }
1373   return 2;
1374}
1375 
1376 
1377 
1378//-------------------------------------------------
1379//  record_body_scanline
1380//-------------------------------------------------
1381 
1382void gime_base_device::record_body_scanline(UINT16 physical_scanline, UINT16 logical_scanline)
1383{
1384   /* update the border first */
1385   update_border(physical_scanline);
1386 
1387   /* set the line in row */
1388   update_value(&m_scanlines[physical_scanline].m_line_in_row, m_line_in_row);
1389 
1390   /* we're using this palette rotation */
1391   m_palette_rotated_position_used = true;
1392 
1393   UINT32 pitch = 0;
1394   if (m_legacy_video)
1395   {
1396      /* legacy video */
1397      update_value(&m_scanlines[physical_scanline].m_ff22_value, m_ff22_value);
1398 
1399      switch(m_ff22_value & (MODE_AG|MODE_GM2|MODE_GM1|MODE_GM0))
1400      {
1401         case MODE_AG:
1402         case MODE_AG|MODE_GM0:
1403         case MODE_AG|MODE_GM1|MODE_GM0:
1404         case MODE_AG|MODE_GM2|MODE_GM0:
1405            pitch = record_scanline_res<16, &gime_base_device::get_data_mc6847, true>(physical_scanline);
1406            break;
1407 
1408         case 0:
1409         case MODE_GM0:
1410         case MODE_GM1:
1411         case MODE_GM1|MODE_GM0:
1412         case MODE_GM2:
1413         case MODE_GM2|MODE_GM0:
1414         case MODE_GM2|MODE_GM1:
1415         case MODE_GM2|MODE_GM1|MODE_GM0:
1416         case MODE_AG|MODE_GM1:
1417         case MODE_AG|MODE_GM2:
1418         case MODE_AG|MODE_GM2|MODE_GM1:
1419         case MODE_AG|MODE_GM2|MODE_GM1|MODE_GM0:
1420            pitch = record_scanline_res<32, &gime_base_device::get_data_mc6847, true>(physical_scanline);
1421            break;
1422 
1423         default:
1424            /* should not get here */
1425            fatalerror("Should not get here");
1426            return;
1427      }
1428   }
1429   else
1430   {
1431      /* CoCo 3 video */
1432      update_value(&m_scanlines[physical_scanline].m_ff98_value, m_gime_registers[0x08]);
1433      update_value(&m_scanlines[physical_scanline].m_ff99_value, m_gime_registers[0x09]);
1434 
1435      /* is this graphics or text? */
1436      if (m_gime_registers[0x08] & 0x80)
1437      {
1438         /* graphics */
1439         switch(m_gime_registers[0x09] & 0x1C)
1440         {
1441            case 0x00:   pitch = record_scanline_res< 16, &gime_base_device::get_data_without_attributes, false>(physical_scanline);   break;
1442            case 0x04:   pitch = record_scanline_res< 20, &gime_base_device::get_data_without_attributes, false>(physical_scanline);   break;
1443            case 0x08:   pitch = record_scanline_res< 32, &gime_base_device::get_data_without_attributes, false>(physical_scanline);   break;
1444            case 0x0C:   pitch = record_scanline_res< 40, &gime_base_device::get_data_without_attributes, false>(physical_scanline);   break;
1445            case 0x10:   pitch = record_scanline_res< 64, &gime_base_device::get_data_without_attributes, false>(physical_scanline);   break;
1446            case 0x14:   pitch = record_scanline_res< 80, &gime_base_device::get_data_without_attributes, false>(physical_scanline);   break;
1447            case 0x18:   pitch = record_scanline_res<128, &gime_base_device::get_data_without_attributes, false>(physical_scanline);   break;
1448            case 0x1C:   pitch = record_scanline_res<160, &gime_base_device::get_data_without_attributes, false>(physical_scanline);   break;
1449            default:
1450               fatalerror("Should not get here");
1451               return;
1452         }
1453      }
1454      else
1455      {
1456         /* text */
1457         switch(m_gime_registers[0x09] & 0x15)
1458         {
1459            case 0x00:   pitch = record_scanline_res< 32, &gime_base_device::get_data_without_attributes, true>(physical_scanline);   break;
1460            case 0x01:   pitch = record_scanline_res< 32, &gime_base_device::get_data_with_attributes,    true>(physical_scanline);   break;
1461            case 0x04:   pitch = record_scanline_res< 40, &gime_base_device::get_data_without_attributes, true>(physical_scanline);   break;
1462            case 0x05:   pitch = record_scanline_res< 40, &gime_base_device::get_data_with_attributes,    true>(physical_scanline);   break;
1463            case 0x10:   pitch = record_scanline_res< 64, &gime_base_device::get_data_without_attributes, true>(physical_scanline);   break;
1464            case 0x11:   pitch = record_scanline_res< 64, &gime_base_device::get_data_with_attributes,    true>(physical_scanline);   break;
1465            case 0x14:   pitch = record_scanline_res< 80, &gime_base_device::get_data_without_attributes, true>(physical_scanline);   break;
1466            case 0x15:   pitch = record_scanline_res< 80, &gime_base_device::get_data_with_attributes,    true>(physical_scanline);   break;
1467            default:
1468               fatalerror("Should not get here");
1469               return;
1470         }
1471      }
1472 
1473      /* is the GIME hoizontal virtual screen enabled? */
1474      if (m_gime_registers[0x0F] & 0x80)
1475      {
1476         pitch = 256;
1477      }
1478   }
1479 
1480   /* sanity checks */
1481   assert(pitch > 0);
1482 
1483   /* are we moving on to the next line? */
1484   if (++m_line_in_row >= get_lines_per_row())
1485   {
1486      /* next row */
1487      m_line_in_row = 0;
1488      m_video_position += pitch;
1489   }
1490}
1491 
1492 
1493 
1494//-------------------------------------------------
1495//  update_geometry
1496//-------------------------------------------------
1497 
1498void gime_base_device::update_geometry(void)
1499{
1500   UINT16 top_border_scanlines, body_scanlines;
1501 
1502   switch(m_legacy_video ? 0x00 : (m_gime_registers[9] & 0x60))
1503   {
1504      case 0x00:
1505         // 192 lines (and legacy video)
1506         top_border_scanlines = 25;
1507         body_scanlines = 192;
1508         break;
1509 
1510      case 0x20:
1511         // 200 lines
1512         top_border_scanlines = 23;
1513         body_scanlines = 200;
1514         break;
1515 
1516      case 0x40:
1517         // zero/infinite lines
1518         //
1519         // If specified within the border, the border will go forever.  If specified within the body, the body will go forever.  This
1520         // suggests that there is a counter that counts scanlines, and we switch border <=> body when we hit some maximum count             
1521         top_border_scanlines = ~0;
1522         body_scanlines = ~0;
1523         break;
1524 
1525      case 0x60:
1526         // 225 lines
1527         top_border_scanlines = 8;
1528         body_scanlines = 225;
1529         break;
1530 
1531      default:
1532         fatalerror("Should not get here");
1533         break;
1534   }
1535 
1536   // bit 3 of $FF99 controls "wideness"
1537   bool wide = !m_legacy_video && (m_gime_registers[9] & 0x08);
1538 
1539   // set the geometry
1540   set_geometry(top_border_scanlines, body_scanlines, wide);
1541}
1542 
1543 
1544 
1545//**************************************************************************
1546//  VIDEO BLITTING
1547//**************************************************************************
1548 
1549//-------------------------------------------------
1550//  emit_dummy_samples
1551//-------------------------------------------------
1552 
1553UINT32 gime_base_device::emit_dummy_samples(const scanline_record *scanline, int sample_start, int sample_count, pixel_t *pixels, const pixel_t *palette)
1554{
1555   fatalerror("Should not get here");
1556   return 0;
1557}
1558 
1559 
1560 
1561//-------------------------------------------------
1562//  emit_mc6847_samples
1563//-------------------------------------------------
1564 
1565ATTR_FORCE_INLINE UINT32 gime_base_device::emit_mc6847_samples(const scanline_record *scanline, int sample_start, int sample_count, pixel_t *pixels, const pixel_t *palette)
1566{
1567   return super::emit_mc6847_samples<2>(
1568      scanline->m_mode[sample_start],
1569      &scanline->m_data[sample_start],
1570      sample_count,
1571      pixels,
1572      palette,
1573      NULL,
1574      sample_start,
1575      scanline->m_line_in_row);
1576}
1577 
1578 
1579 
1580//-------------------------------------------------
1581//  emit_gime_graphics_samples
1582//-------------------------------------------------
1583 
1584template<int xscale, int bits_per_pixel>
1585ATTR_FORCE_INLINE UINT32 gime_base_device::emit_gime_graphics_samples(const scanline_record *scanline, int sample_start, int sample_count, pixel_t *pixels, const pixel_t *palette)
1586{
1587   const UINT8 *data = &scanline->m_data[sample_start];
1588   mc6847_friend_device::emit_graphics<bits_per_pixel, xscale>(data, sample_count, pixels, 0, palette);
1589   return sample_count * (8 / bits_per_pixel) * xscale;
1590}
1591 
1592 
1593 
1594//-------------------------------------------------
1595//  emit_gime_text_samples
1596//-------------------------------------------------
1597 
1598template<int xscale>
1599ATTR_FORCE_INLINE UINT32 gime_base_device::emit_gime_text_samples(const scanline_record *scanline, int sample_start, int sample_count, pixel_t *pixels, const pixel_t *palette)
1600{
1601   UINT8 attribute = scanline->m_mode[sample_start];
1602   const UINT8 *data = &scanline->m_data[sample_start];
1603 
1604   /* determine the background/foreground colors */
1605   UINT8 bg = (attribute == NO_ATTRIBUTE) ? 0 : ((attribute >> 0) & 0x07) + 0x00;
1606   UINT8 fg = (attribute == NO_ATTRIBUTE) ? 1 : ((attribute >> 3) & 0x07) + 0x08;
1607 
1608   /* underline attribute */
1609   int underline_line = -1;
1610   if ((attribute != NO_ATTRIBUTE) && (attribute & 0x40))
1611   {
1612      /* to quote SockMaster:
1613        *
1614        * The underline attribute will light up the bottom scan line of the character
1615        * if the lines are set to 8 or 9.  Not appear at all when less, or appear on
1616        * the 2nd to bottom scan line if set higher than 9.  Further exception being
1617        * the $x7 setting where the whole screen is filled with only one line of data
1618        * - but it's glitched - the line repeats over and over again every 16 scan
1619        * lines..  Nobody will use this mode, but that's what happens if you want to
1620        * make things really authentic :)
1621        */
1622      switch(scanline->m_ff98_value & 0x07)
1623      {
1624         case 0x03:
1625            underline_line = 7;
1626            break;
1627         case 0x04:
1628         case 0x05:
1629            underline_line = 8;
1630            break;
1631         case 0x06:
1632            underline_line = 9;
1633            break;
1634      }
1635   }
1636 
1637   for (int i = 0; i < sample_count; i++)
1638   {
1639      for (int j = 0; j < 8; j++)
1640      {
1641         for (int k = 0; k < xscale; k++)
1642         {
1643            UINT8 font_byte = hires_font[data[i] & 0x7F][scanline->m_line_in_row];
1644            bool bit = (scanline->m_line_in_row == underline_line) || ((font_byte >> (7 - j)) & 0x01);
1645            pixels[(i * 8 + j) * xscale + k] = bit ? palette[fg] : palette[bg];
1646         }
1647      }
1648   }
1649   return sample_count * 8 * xscale;
1650}
1651 
1652 
1653 
1654//-------------------------------------------------
1655//  render_scanline
1656//-------------------------------------------------
1657 
1658template<int sample_count, gime_base_device::emit_samples_proc emit_samples>
1659ATTR_FORCE_INLINE void gime_base_device::render_scanline(const scanline_record *scanline, pixel_t *pixels, int min_x, int max_x, palette_resolver *resolver)
1660{
1661   int left_border, right_border;
1662   int x, x2;
1663   pixel_t border_color = resolver->lookup(scanline->m_border);
1664   const pixel_t *resolved_palette = NULL;
1665 
1666   /* is this a wide video mode? */
1667   bool wide = !m_legacy_video && (scanline->m_ff99_value & 0x04);
1668 
1669   /* size up the borders */
1670   if (sample_count > 0)
1671   {
1672      left_border = wide ? 0 : 64;
1673      right_border = wide ? 640 : 512;
1674   }
1675   else
1676   {
1677      left_border = 640;
1678      right_border = 640;
1679   }
1680 
1681   /* left border */
1682   for (x = min_x; x < left_border; x++)
1683   {
1684      pixels[x] = border_color;
1685   }
1686 
1687   /* right border */
1688   for (x = right_border; x <= max_x; x++)
1689   {
1690      pixels[x] = border_color;
1691   }
1692 
1693   /* offset the pixel counts depending on wide */
1694   pixels += wide ? 0 : 64;
1695 
1696   /* body */
1697   x = 0;
1698   while(x < sample_count)
1699   {
1700      /* determine how many bytes exist for which the mode is identical */
1701      for (x2 = x + 1; (x2 < sample_count) && (scanline->m_mode[x] == scanline->m_mode[x2]) && (scanline->m_palette[x] == scanline->m_palette[x2]); x2++)
1702         ;
1703 
1704      /* resolve the palette */
1705      resolved_palette = resolver->get_palette(scanline->m_palette[x]);
1706 
1707      /* emit the samples, with a (hopefully) aggressively inlined function */
1708      pixels += ((*this).*(emit_samples))(scanline, x, x2 - x, pixels, resolved_palette);
1709 
1710      /* update x */
1711      x = x2;
1712   }
1713 
1714   /* artifacting */
1715   if (m_legacy_video && (sample_count > 0))
1716   {
1717      m_artifacter.process_artifacts<2>(pixels, scanline->m_mode[0], resolved_palette);
1718   }
1719}
1720 
1721 
1722 
1723//-------------------------------------------------
1724//  update_screen
1725//-------------------------------------------------
1726 
1727bool gime_base_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect, const pixel_t *RESTRICT palette)
1728{
1729   int base_x = 64;
1730   int min_x = USE_HORIZONTAL_CLIP ? cliprect->min_x : 0;
1731   int max_x = USE_HORIZONTAL_CLIP ? cliprect->max_x : (base_x * 2 + 512 - 1);
1732   int min_y = cliprect->min_y;
1733   int max_y = cliprect->max_y;
1734   palette_resolver resolver(this, palette);
1735 
1736   /* if the video didn't change, indicate as much */
1737   if (!has_video_changed())
1738      return UPDATE_HAS_NOT_CHANGED;
1739 
1740   for (int y = min_y; y <= max_y; y++)
1741   {
1742      const scanline_record *scanline = &m_scanlines[y];
1743      pixel_t *RESTRICT pixels = bitmap_addr(bitmap, y, 0);
1744 
1745      /* render the scanline */
1746      if (m_scanlines[y].m_line_in_row == (UINT8) ~0)
1747      {
1748         /* this is a border scanline */
1749         render_scanline<0, &gime_base_device::emit_dummy_samples>(scanline, pixels, min_x, max_x, &resolver);
1750      }
1751      else if (m_legacy_video)
1752      {
1753         /* this is a legacy body scanline */
1754         switch(scanline->m_ff22_value & (MODE_AG|MODE_GM2|MODE_GM1|MODE_GM0))
1755         {
1756            case MODE_AG:
1757            case MODE_AG|MODE_GM0:
1758            case MODE_AG|MODE_GM1|MODE_GM0:
1759            case MODE_AG|MODE_GM2|MODE_GM0:
1760               render_scanline<16, &gime_base_device::emit_mc6847_samples>(scanline, pixels, min_x, max_x, &resolver);
1761               break;
1762 
1763            default:
1764               render_scanline<32, &gime_base_device::emit_mc6847_samples>(scanline, pixels, min_x, max_x, &resolver);
1765               break;
1766         }
1767      }
1768      else if (scanline->m_ff98_value & 0x80)
1769      {
1770         /* GIME graphics */
1771         switch(scanline->m_ff99_value & 0x1F)
1772         {
1773            case 0x00:   render_scanline< 16, &gime_base_device::emit_gime_graphics_samples< 4, 1> >(scanline, pixels, min_x, max_x, &resolver);   break;
1774            case 0x01:   render_scanline< 16, &gime_base_device::emit_gime_graphics_samples< 8, 2> >(scanline, pixels, min_x, max_x, &resolver);   break;
1775            case 0x02:
1776            case 0x03:   render_scanline< 16, &gime_base_device::emit_gime_graphics_samples<16, 4> >(scanline, pixels, min_x, max_x, &resolver);   break;
1777            case 0x04:   render_scanline< 20, &gime_base_device::emit_gime_graphics_samples< 4, 1> >(scanline, pixels, min_x, max_x, &resolver);   break;
1778            case 0x05:   render_scanline< 20, &gime_base_device::emit_gime_graphics_samples< 8, 2> >(scanline, pixels, min_x, max_x, &resolver);   break;
1779            case 0x06:
1780            case 0x07:   render_scanline< 20, &gime_base_device::emit_gime_graphics_samples<16, 4> >(scanline, pixels, min_x, max_x, &resolver);   break;
1781            case 0x08:   render_scanline< 32, &gime_base_device::emit_gime_graphics_samples< 2, 1> >(scanline, pixels, min_x, max_x, &resolver);   break;
1782            case 0x09:   render_scanline< 32, &gime_base_device::emit_gime_graphics_samples< 4, 2> >(scanline, pixels, min_x, max_x, &resolver);   break;
1783            case 0x0A:
1784            case 0x0B:   render_scanline< 32, &gime_base_device::emit_gime_graphics_samples< 8, 4> >(scanline, pixels, min_x, max_x, &resolver);   break;
1785            case 0x0C:   render_scanline< 40, &gime_base_device::emit_gime_graphics_samples< 2, 1> >(scanline, pixels, min_x, max_x, &resolver);   break;
1786            case 0x0D:   render_scanline< 40, &gime_base_device::emit_gime_graphics_samples< 4, 2> >(scanline, pixels, min_x, max_x, &resolver);   break;
1787            case 0x0E:
1788            case 0x0F:   render_scanline< 40, &gime_base_device::emit_gime_graphics_samples< 8, 4> >(scanline, pixels, min_x, max_x, &resolver);   break;
1789            case 0x10:   render_scanline< 64, &gime_base_device::emit_gime_graphics_samples< 1, 1> >(scanline, pixels, min_x, max_x, &resolver);   break;
1790            case 0x11:   render_scanline< 64, &gime_base_device::emit_gime_graphics_samples< 2, 2> >(scanline, pixels, min_x, max_x, &resolver);   break;
1791            case 0x12:
1792            case 0x13:   render_scanline< 64, &gime_base_device::emit_gime_graphics_samples< 4, 4> >(scanline, pixels, min_x, max_x, &resolver);   break;
1793            case 0x14:   render_scanline< 80, &gime_base_device::emit_gime_graphics_samples< 1, 1> >(scanline, pixels, min_x, max_x, &resolver);   break;
1794            case 0x15:   render_scanline< 80, &gime_base_device::emit_gime_graphics_samples< 2, 2> >(scanline, pixels, min_x, max_x, &resolver);   break;
1795            case 0x16:
1796            case 0x17:   render_scanline< 80, &gime_base_device::emit_gime_graphics_samples< 4, 4> >(scanline, pixels, min_x, max_x, &resolver);   break;
1797            case 0x18:
1798            case 0x19:   render_scanline<128, &gime_base_device::emit_gime_graphics_samples< 1, 2> >(scanline, pixels, min_x, max_x, &resolver);   break;
1799            case 0x1A:
1800            case 0x1B:   render_scanline<128, &gime_base_device::emit_gime_graphics_samples< 2, 4> >(scanline, pixels, min_x, max_x, &resolver);   break;
1801            case 0x1C:
1802            case 0x1D:   render_scanline<160, &gime_base_device::emit_gime_graphics_samples< 1, 2> >(scanline, pixels, min_x, max_x, &resolver);   break;
1803            case 0x1E:
1804            case 0x1F:   render_scanline<160, &gime_base_device::emit_gime_graphics_samples< 2, 4> >(scanline, pixels, min_x, max_x, &resolver);   break;
1805         }
1806      }
1807      else
1808      {
1809         /* GIME text */
1810         switch(scanline->m_ff99_value & 0x14)
1811         {
1812            case 0x00:   render_scanline<32, &gime_base_device::emit_gime_text_samples<2> >(scanline, pixels, min_x, max_x, &resolver);   break;
1813            case 0x04:   render_scanline<40, &gime_base_device::emit_gime_text_samples<2> >(scanline, pixels, min_x, max_x, &resolver);   break;
1814            case 0x10:   render_scanline<64, &gime_base_device::emit_gime_text_samples<1> >(scanline, pixels, min_x, max_x, &resolver);   break;
1815            case 0x14:   render_scanline<80, &gime_base_device::emit_gime_text_samples<1> >(scanline, pixels, min_x, max_x, &resolver);   break;
1816         }
1817      }
1818   }
1819   return 0;
1820}
1821 
1822 
1823 
1824//-------------------------------------------------
1825//  update_composite
1826//-------------------------------------------------
1827 
1828bool gime_base_device::update_composite(bitmap_t *bitmap, const rectangle *cliprect)
1829{
1830   update_value(&m_displayed_rgb, false);
1831   const pixel_t *palette = (m_gime_registers[0x08] & 0x10)
1832      ? m_composite_bw_palette
1833      : m_composite_palette;
1834   return update_screen(bitmap, cliprect, palette);
1835}
1836 
1837 
1838 
1839//-------------------------------------------------
1840//  update_rgb
1841//-------------------------------------------------
1842 
1843bool gime_base_device::update_rgb(bitmap_t *bitmap, const rectangle *cliprect)
1844{
1845   update_value(&m_displayed_rgb, true);
1846   return update_screen(bitmap, cliprect, m_rgb_palette);
1847}
1848 
1849 
1850 
1851//**************************************************************************
1852//  PALETTE RESOLVER MEMBER CLASS
1853//**************************************************************************
1854 
1855//-------------------------------------------------
1856//  palette_resolver::palette_resolver
1857//-------------------------------------------------
1858 
1859ATTR_FORCE_INLINE gime_base_device::palette_resolver::palette_resolver(gime_base_device *gime, const pixel_t *palette)
1860{
1861   m_gime = gime;
1862   m_palette = palette;
1863   memset(m_resolved_palette, 0, sizeof(m_resolved_palette));
1864   m_current_resolved_palette = -1;
1865}
1866 
1867 
1868 
1869//-------------------------------------------------
1870//  palette_resolver::get_palette
1871//-------------------------------------------------
1872 
1873ATTR_FORCE_INLINE const gime_base_device::pixel_t *gime_base_device::palette_resolver::get_palette(UINT16 palette_rotation)
1874{
1875   if (UNEXPECTED(m_current_resolved_palette != palette_rotation))
1876   {
1877      for (int i = 0; i < 16; i++)
1878         m_resolved_palette[i] = lookup(m_gime->m_palette_rotated[palette_rotation][i]);
1879      m_current_resolved_palette = palette_rotation;
1880   }
1881   return m_resolved_palette;
1882}
1883 
1884 
1885 
1886//-------------------------------------------------
1887//  palette_resolver::lookup
1888//-------------------------------------------------
1889 
1890ATTR_FORCE_INLINE gime_base_device::pixel_t gime_base_device::palette_resolver::lookup(UINT8 color)
1891{
1892   assert((color >= 0) && (color <= 63));
1893   return m_palette[color];
1894}
1895 
1896 
1897 
1898//-------------------------------------------------
1899//  hires_font
1900//-------------------------------------------------
1901 
1902const UINT8 gime_base_device::hires_font[128][12] =
1903{
1904   { 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x10}, { 0x44, 0x00, 0x44, 0x44, 0x44, 0x4C, 0x34, 0x00}, 
1905   { 0x08, 0x10, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00}, { 0x10, 0x28, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00}, 
1906   { 0x28, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00}, { 0x20, 0x10, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00}, 
1907   { 0x10, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00}, { 0x00, 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x10}, 
1908   { 0x10, 0x28, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00}, { 0x28, 0x00, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00}, 
1909   { 0x20, 0x10, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00}, { 0x28, 0x00, 0x30, 0x10, 0x10, 0x10, 0x38, 0x00}, 
1910   { 0x10, 0x28, 0x00, 0x30, 0x10, 0x10, 0x38, 0x00}, { 0x00, 0x18, 0x24, 0x38, 0x24, 0x24, 0x38, 0x40}, 
1911   { 0x44, 0x10, 0x28, 0x44, 0x7C, 0x44, 0x44, 0x00}, { 0x10, 0x10, 0x28, 0x44, 0x7C, 0x44, 0x44, 0x00}, 
1912   { 0x08, 0x10, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00}, { 0x00, 0x00, 0x68, 0x14, 0x3C, 0x50, 0x3C, 0x00}, 
1913   { 0x3C, 0x50, 0x50, 0x78, 0x50, 0x50, 0x5C, 0x00}, { 0x10, 0x28, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00}, 
1914   { 0x28, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00}, { 0x00, 0x00, 0x38, 0x4C, 0x54, 0x64, 0x38, 0x00}, 
1915   { 0x10, 0x28, 0x00, 0x44, 0x44, 0x4C, 0x34, 0x00}, { 0x20, 0x10, 0x44, 0x44, 0x44, 0x4C, 0x34, 0x00}, 
1916   { 0x38, 0x4C, 0x54, 0x54, 0x54, 0x64, 0x38, 0x00}, { 0x44, 0x38, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00}, 
1917   { 0x28, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00}, { 0x38, 0x40, 0x38, 0x44, 0x38, 0x04, 0x38, 0x00}, 
1918   { 0x08, 0x14, 0x10, 0x38, 0x10, 0x50, 0x3C, 0x00}, { 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x7C, 0x00}, 
1919   { 0x10, 0x28, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, { 0x08, 0x14, 0x10, 0x38, 0x10, 0x10, 0x20, 0x40}, 
1920   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, { 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00}, 
1921   { 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00}, { 0x28, 0x28, 0x7C, 0x28, 0x7C, 0x28, 0x28, 0x00}, 
1922   { 0x10, 0x3C, 0x50, 0x38, 0x14, 0x78, 0x10, 0x00}, { 0x60, 0x64, 0x08, 0x10, 0x20, 0x4C, 0x0C, 0x00}, 
1923   { 0x20, 0x50, 0x50, 0x20, 0x54, 0x48, 0x34, 0x00}, { 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00}, 
1924   { 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00}, { 0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00}, 
1925   { 0x00, 0x10, 0x54, 0x38, 0x38, 0x54, 0x10, 0x00}, { 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00}, 
1926   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x20}, { 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00}, 
1927   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00}, { 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00}, 
1928   { 0x38, 0x44, 0x4C, 0x54, 0x64, 0x44, 0x38, 0x00}, { 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00}, 
1929   { 0x38, 0x44, 0x04, 0x38, 0x40, 0x40, 0x7C, 0x00}, { 0x38, 0x44, 0x04, 0x08, 0x04, 0x44, 0x38, 0x00}, 
1930   { 0x08, 0x18, 0x28, 0x48, 0x7C, 0x08, 0x08, 0x00}, { 0x7C, 0x40, 0x78, 0x04, 0x04, 0x44, 0x38, 0x00}, 
1931   { 0x38, 0x40, 0x40, 0x78, 0x44, 0x44, 0x38, 0x00}, { 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40, 0x00}, 
1932   { 0x38, 0x44, 0x44, 0x38, 0x44, 0x44, 0x38, 0x00}, { 0x38, 0x44, 0x44, 0x38, 0x04, 0x04, 0x38, 0x00}, 
1933   { 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00}, { 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x20}, 
1934   { 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x00}, { 0x00, 0x00, 0x7C, 0x00, 0x7C, 0x00, 0x00, 0x00}, 
1935   { 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x00}, { 0x38, 0x44, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00}, 
1936   { 0x38, 0x44, 0x04, 0x34, 0x4C, 0x4C, 0x38, 0x00}, { 0x10, 0x28, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x00}, 
1937   { 0x78, 0x24, 0x24, 0x38, 0x24, 0x24, 0x78, 0x00}, { 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00}, 
1938   { 0x78, 0x24, 0x24, 0x24, 0x24, 0x24, 0x78, 0x00}, { 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x7C, 0x00}, 
1939   { 0x7C, 0x40, 0x40, 0x70, 0x40, 0x40, 0x40, 0x00}, { 0x38, 0x44, 0x40, 0x40, 0x4C, 0x44, 0x38, 0x00}, 
1940   { 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x44, 0x00}, { 0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00}, 
1941   { 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0x00}, { 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00}, 
1942   { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7C, 0x00}, { 0x44, 0x6C, 0x54, 0x54, 0x44, 0x44, 0x44, 0x00}, 
1943   { 0x44, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x44, 0x00}, { 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00}, 
1944   { 0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00}, { 0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00}, 
1945   { 0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44, 0x00}, { 0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x38, 0x00}, 
1946   { 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}, { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00}, 
1947   { 0x44, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x00}, { 0x44, 0x44, 0x44, 0x44, 0x54, 0x6C, 0x44, 0x00}, 
1948   { 0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00}, { 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10, 0x00}, 
1949   { 0x7C, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7C, 0x00}, { 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00}, 
1950   { 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00}, { 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00}, 
1951   { 0x10, 0x38, 0x54, 0x10, 0x10, 0x10, 0x10, 0x00}, { 0x00, 0x10, 0x20, 0x7C, 0x20, 0x10, 0x00, 0x00}, 
1952   { 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, { 0x00, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00}, 
1953   { 0x40, 0x40, 0x58, 0x64, 0x44, 0x64, 0x58, 0x00}, { 0x00, 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x00}, 
1954   { 0x04, 0x04, 0x34, 0x4C, 0x44, 0x4C, 0x34, 0x00}, { 0x00, 0x00, 0x38, 0x44, 0x7C, 0x40, 0x38, 0x00}, 
1955   { 0x08, 0x14, 0x10, 0x38, 0x10, 0x10, 0x10, 0x00}, { 0x00, 0x00, 0x34, 0x4C, 0x4C, 0x34, 0x04, 0x38}, 
1956   { 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00}, { 0x00, 0x10, 0x00, 0x30, 0x10, 0x10, 0x38, 0x00}, 
1957   { 0x00, 0x04, 0x00, 0x04, 0x04, 0x04, 0x44, 0x38}, { 0x40, 0x40, 0x48, 0x50, 0x60, 0x50, 0x48, 0x00}, 
1958   { 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00}, { 0x00, 0x00, 0x68, 0x54, 0x54, 0x54, 0x54, 0x00}, 
1959   { 0x00, 0x00, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00}, { 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00}, 
1960   { 0x00, 0x00, 0x78, 0x44, 0x44, 0x78, 0x40, 0x40}, { 0x00, 0x00, 0x3C, 0x44, 0x44, 0x3C, 0x04, 0x04}, 
1961   { 0x00, 0x00, 0x58, 0x64, 0x40, 0x40, 0x40, 0x00}, { 0x00, 0x00, 0x3C, 0x40, 0x38, 0x04, 0x78, 0x00}, 
1962   { 0x20, 0x20, 0x70, 0x20, 0x20, 0x24, 0x18, 0x00}, { 0x00, 0x00, 0x44, 0x44, 0x44, 0x4C, 0x34, 0x00}, 
1963   { 0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00}, { 0x00, 0x00, 0x44, 0x54, 0x54, 0x28, 0x28, 0x00}, 
1964   { 0x00, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00}, { 0x00, 0x00, 0x44, 0x44, 0x44, 0x3C, 0x04, 0x38}, 
1965   { 0x00, 0x00, 0x7C, 0x08, 0x10, 0x20, 0x7C, 0x00}, { 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08, 0x00}, 
1966   { 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x00}, { 0x20, 0x10, 0x10, 0x08, 0x10, 0x10, 0x20, 0x00}, 
1967   { 0x20, 0x54, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00}, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00}
1968};
1969 
1970 
1971 
1972//**************************************************************************
1973//  VARIATIONS
1974//**************************************************************************
1975 
1976const device_type GIME_NTSC = &device_creator<gime_ntsc_device>;
1977const device_type GIME_PAL = &device_creator<gime_pal_device>;
1978 
1979 
1980 
1981//-------------------------------------------------
1982//  gime_ntsc_device
1983//-------------------------------------------------
1984 
1985gime_ntsc_device::gime_ntsc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1986   : gime_base_device(mconfig, GIME_NTSC, "GIME_NTSC", tag, owner, clock, ntsc_round_fontdata8x12)
1987{
1988}
1989 
1990 
1991 
1992//-------------------------------------------------
1993//  gime_pal_device
1994//-------------------------------------------------
1995 
1996gime_pal_device::gime_pal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1997   : gime_base_device(mconfig, GIME_PAL, "GIME_PAL", tag, owner, clock, pal_round_fontdata8x12)
1998{
1999}
src/mess/video/gime.h
r0r13257
1/*********************************************************************
2 
3    mc6847.h
4 
5    Implementation of Motorola 6847 video hardware chip
6 
7***************************************************************************/
8 
9#pragma once
10 
11#ifndef __GIME__
12#define __GIME__
13 
14#include "video/mc6847.h"
15#include "machine/6883sam.h"
16#include "machine/ram.h"
17 
18 
19//**************************************************************************
20//  GIME CONFIG/INTERFACE
21//**************************************************************************
22 
23/* interface */
24typedef struct _gime_interface gime_interface;
25struct _gime_interface
26{
27   const char *m_screen_tag;   /* screen we are acting on */
28   const char *m_maincpu_tag;   /* tag of main CPU */
29   const char *m_ram_tag;      /* tag of RAM device */
30   const char *m_ext_tag;      /* tag of expansion device */
31 
32   /* if specified, this gets called for every change of the HSYNC pin */
33   devcb_write_line         m_out_hsync_func;
34 
35   /* if specified, this gets called for every change of the FSYNC pin */
36   devcb_write_line         m_out_fsync_func;
37 
38   /* if specified, this gets called for every change of the IRQ pin */
39   devcb_write_line         m_out_irq_func;
40 
41   /* if specified, this gets called for every change of the FIRQ pin */
42   devcb_write_line         m_out_firq_func;
43};
44 
45 
46 
47//**************************************************************************
48//  GIME CORE
49//**************************************************************************
50 
51class gime_base_device : public mc6847_friend_device, public sam6883_friend_device
52{
53public:
54   // read/write
55   DECLARE_READ8_MEMBER( read ) { return read(offset); }
56   DECLARE_WRITE8_MEMBER( write ) { write(offset, data); }
57 
58   // used to turn on/off reading/writing to $FF40-$FF5F
59   bool spare_chip_select_enabled(void) { return m_gime_registers[0] & 0x04 ? true : false; }
60 
61   // the GIME seems to intercept writes to $FF22 (not precisely sure how)
62   void ff22_write(UINT8 data) { m_ff22_value = data; }
63 
64   /* updates the screen -- this will call begin_update(),
65       followed by update_row() reapeatedly and after all row
66       updating is complete, end_update() */
67   bool update_composite(bitmap_t *bitmap, const rectangle *cliprect);
68   bool update_rgb(bitmap_t *bitmap, const rectangle *cliprect);
69 
70   /* interrupt outputs */
71   bool firq_r(void) { return m_firq != 0x00; }
72   bool irq_r(void) { return m_irq != 0x00; }
73 
74   /* interrupt inputs */
75   void set_il0(bool value) { set_interrupt_value(INTERRUPT_EI0, value); }
76   void set_il1(bool value) { set_interrupt_value(INTERRUPT_EI1, value); }
77   void set_il2(bool value) { set_interrupt_value(INTERRUPT_EI2, value); }
78 
79protected:
80   gime_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const UINT8 *fontdata);
81 
82    // device-level overrides
83    virtual void device_start(void);
84   virtual void device_reset(void);
85   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
86   virtual void device_post_load(void);
87   virtual ioport_constructor device_input_ports() const;
88 
89   // other overrides
90   virtual void new_frame(void);
91   virtual void horizontal_sync_changed(bool line);
92   virtual void enter_bottom_border(void);
93   virtual void record_border_scanline(UINT16 physical_scanline);
94   virtual void record_body_scanline(UINT16 physical_scanline, UINT16 logical_scanline);
95 
96private:
97   typedef mc6847_friend_device super;
98 
99   struct scanline_record
100   {
101      UINT8 m_border;
102      UINT8 m_line_in_row;
103      UINT8 m_ff22_value;
104      UINT8 m_ff98_value;
105      UINT8 m_ff99_value;
106      UINT8 m_mode[160];
107      UINT8 m_data[160];
108      UINT16 m_palette[160];
109   };
110 
111   typedef UINT32 (gime_base_device::*get_data_func)(UINT32, UINT8 *, UINT8 *);
112 
113   class palette_resolver
114   {
115   public:
116      palette_resolver(gime_base_device *gime, const pixel_t *palette);
117      const pixel_t *get_palette(UINT16 palette_rotation);
118      pixel_t lookup(UINT8 color);
119 
120   private:
121      gime_base_device *m_gime;
122      const pixel_t *m_palette;
123      pixel_t m_resolved_palette[16];
124      int m_current_resolved_palette;
125   };
126 
127   enum
128   {
129      INTERRUPT_TMR      = 0x20,
130      INTERRUPT_HBORD      = 0x10,
131      INTERRUPT_VBORD      = 0x08,
132      INTERRUPT_EI2      = 0x04,
133      INTERRUPT_EI1      = 0x02,
134      INTERRUPT_EI0      = 0x01
135   };
136 
137   typedef enum
138   {
139      GIME_TIMER_HBORD,
140      GIME_TIMER_CLOCK
141   } timer_type_t;
142 
143   // timer constants
144   static const device_timer_id TIMER_GIME_CLOCK = 4;
145 
146   // statics
147   static const UINT8 hires_font[128][12];
148 
149   // callbacks
150   devcb_resolved_write_line m_res_out_irq_func;
151   devcb_resolved_write_line m_res_out_firq_func;
152 
153   // device state
154   UINT8 m_gime_registers[16];
155   UINT8 m_mmu[16];
156   UINT8 m_ff22_value;
157   UINT8 m_interrupt_value;
158   UINT8 m_irq;
159   UINT8 m_firq;
160   UINT16 m_timer_value;
161   bool m_is_blinking;
162 
163   // video state
164   bool m_legacy_video;
165   UINT32 m_video_position;
166   UINT8 m_line_in_row;
167   scanline_record m_scanlines[25+192+26];
168   bool m_displayed_rgb;
169 
170   // palette state
171   UINT8 m_palette_rotated[1024][16];
172   UINT16 m_palette_rotated_position;
173   bool m_palette_rotated_position_used;
174 
175   // incidentals
176   ram_device *m_ram;
177   emu_timer *m_gime_clock_timer;
178   UINT8 *m_rom;
179   UINT8 *m_cart_rom;
180   pixel_t m_composite_palette[64];
181   pixel_t m_composite_bw_palette[64];
182   pixel_t m_rgb_palette[64];
183   UINT8 m_dummy_bank[0x2000];
184 
185   // timer constants
186   static const device_timer_id TIMER_FRAME = 0;
187   static const device_timer_id TIMER_HSYNC_OFF = 1;
188   static const device_timer_id TIMER_HSYNC_ON = 2;
189   static const device_timer_id TIMER_FSYNC_OFF = 3;
190   static const device_timer_id TIMER_FSYNC_ON = 4;
191 
192   // read/write
193   UINT8 read(offs_t offset);
194   UINT8 read_gime_register(offs_t offset);
195   UINT8 read_mmu_register(offs_t offset);
196   UINT8 read_palette_register(offs_t offset);
197   void write(offs_t offset, UINT8 data);
198   void write_gime_register(offs_t offset, UINT8 data);
199   void write_mmu_register(offs_t offset, UINT8 data);
200   void write_palette_register(offs_t offset, UINT8 data);
201   void write_sam_register(offs_t offset);
202 
203   // memory
204   void update_memory(void);
205   void update_memory(int bank);
206   UINT8 *memory_pointer(UINT32 address);
207 
208   // interrupts
209   void interrupt_rising_edge(UINT8 interrupt);
210   void recalculate_irq(void);
211   void recalculate_firq(void);
212 
213   ATTR_FORCE_INLINE void set_interrupt_value(UINT8 interrupt, bool value)
214   {
215      /* save the old interrupt value */
216      UINT8 old_interrupt_value = m_interrupt_value;
217 
218      /* update the interrupt value */
219      if (value)
220         m_interrupt_value |= interrupt;
221      else
222         m_interrupt_value &= ~interrupt;
223 
224      /* was this a rising edge? */
225      if (value && ((old_interrupt_value & interrupt) == 0))
226      {
227         interrupt_rising_edge(interrupt);
228      }
229   }
230 
231   // timer
232   timer_type_t timer_type(void);
233   const char *timer_type_string(void);
234   void reset_timer(void);
235   void timer_elapsed(void);
236 
237   // video
238   bool update_screen(bitmap_t *bitmap, const rectangle *cliprect, const pixel_t *palette);
239   void update_geometry(void);
240   void update_border(UINT16 physical_scanline);
241   pixel_t get_composite_color(int color);
242   pixel_t get_rgb_color(int color);
243   offs_t get_video_base(void);
244   UINT16 get_lines_per_row(void);
245   UINT32 get_data_mc6847(UINT32 video_position, UINT8 *data, UINT8 *mode);
246   UINT32 get_data_without_attributes(UINT32 video_position, UINT8 *data, UINT8 *mode);
247   UINT32 get_data_with_attributes(UINT32 video_position, UINT8 *data, UINT8 *mode);
248   bool is_blinking(void);
249 
250   // template function for doing video update collection
251   template<UINT8 xres, get_data_func get_data, bool record_mode>
252   UINT32 record_scanline_res(int scanline);
253 
254   // rendering sampled graphics
255   typedef UINT32 (gime_base_device::*emit_samples_proc)(const scanline_record *scanline, int sample_start, int sample_count, pixel_t *pixels, const pixel_t *palette);
256   UINT32 emit_dummy_samples(const scanline_record *scanline, int sample_start, int sample_count, pixel_t *pixels, const pixel_t *palette);
257   UINT32 emit_mc6847_samples(const scanline_record *scanline, int sample_start, int sample_count, pixel_t *pixels, const pixel_t *palette);
258   template<int xscale>
259   UINT32 emit_gime_text_samples(const scanline_record *scanline, int sample_start, int sample_count, pixel_t *pixels, const pixel_t *palette);
260   template<int xscale, int bits_per_pixel>
261   UINT32 emit_gime_graphics_samples(const scanline_record *scanline, int sample_start, int sample_count, pixel_t *pixels, const pixel_t *palette);
262   template<int sample_count, emit_samples_proc emit_samples>
263   void render_scanline(const scanline_record *scanline, pixel_t *pixels, int min_x, int max_x, palette_resolver *resolver);
264};
265 
266 
267//**************************************************************************
268//  VARIATIONS
269//**************************************************************************
270 
271class gime_ntsc_device : public gime_base_device
272{
273public:
274   gime_ntsc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
275};
276 
277class gime_pal_device : public gime_base_device
278{
279public:
280   gime_pal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
281};
282 
283extern const device_type GIME_NTSC;
284extern const device_type GIME_PAL;
285 
286#endif /* __GIME__ */
src/mess/includes/cococart.h
r13256r13257
1/*****************************************************************************
2 *
3 * includes/cococart.h
4 *
5 ****************************************************************************/
6
7#ifndef COCOCART_H_
8#define COCOCART_H_
9
10
11enum
12{
13   CARTLINE_CLEAR,
14   CARTLINE_ASSERTED,
15   CARTLINE_Q
16};
17
18#if 0
19struct cartridge_callback
20{
21   void (*setcartline)(int data);
22   void (*setbank)(int bank);
23};
24
25struct cartridge_slot
26{
27   void (*init)(const struct cartridge_callback *callbacks);
28   void (*term)(void);
29   read8_machine_func m_io_r;
30   write8_machine_func m_io_w;
31   void (*enablesound)(int enable);
32};
33
34extern const struct cartridge_slot cartridge_fdc_coco;
35extern const struct cartridge_slot cartridge_fdc_dragon;
36extern const struct cartridge_slot cartridge_fdc_dragon_delta;
37extern const struct cartridge_slot cartridge_standard;
38extern const struct cartridge_slot cartridge_banks;
39extern const struct cartridge_slot cartridge_banks_mega;
40extern const struct cartridge_slot cartridge_Orch90;
41#endif
42
43
44#endif /* COCOCART_H_ */
src/mess/includes/z80ne.h
r13256r13257
1111#ifndef Z80NE_H_
1212#define Z80NE_H_
1313
14#include "video/mc6847.h"
1415
16
1517/***************************************************************************
1618    CONSTANTS
1719***************************************************************************/
r13256r13257
6163{
6264public:
6365   z80ne_state(const machine_config &mconfig, device_type type, const char *tag)
64      : driver_device(mconfig, type, tag) { }
66      : driver_device(mconfig, type, tag),
67        m_vdg(*this, "mc6847")
68   {}
6569
70   optional_device<mc6847_base_device> m_vdg;
6671   UINT8 *m_videoram;
6772   UINT8 m_lx383_scan_counter;
6873   UINT8 m_lx383_key[LX383_KEYS];
r13256r13257
7580   emu_timer *m_cassette_timer;
7681   cass_data_t m_cass_data;
7782   wd17xx_state_t m_wd17xx_state;
83
84protected:
85   virtual bool screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect);
7886};
7987
8088
src/mess/includes/dragon.h
r0r13257
1/***************************************************************************
2 
3    dragon.h
4 
5    Dragon Family
6 
7***************************************************************************/
8 
9#pragma once
10 
11#ifndef __DRAGON__
12#define __DRAGON__
13 
14#define ADDRESS_MAP_MODERN
15 
16#include "includes/coco12.h"
17#include "imagedev/printer.h"
18#include "machine/6551acia.h"
19 
20 
21 
22//**************************************************************************
23//  MACROS / CONSTANTS
24//**************************************************************************
25 
26#define PRINTER_TAG      "printer"
27#define ACIA_TAG      "acia"
28 
29 
30 
31//**************************************************************************
32//  TYPE DEFINITIONS
33//**************************************************************************
34 
35class dragon_state : public coco12_state
36{
37public:
38   dragon_state(const machine_config &mconfig, device_type type, const char *tag);
39 
40   required_device<printer_image_device> m_printer;
41 
42protected:
43   virtual void pia1_pa_changed(void);
44};
45 
46 
47/* dragon64 has an ACIA chip */
48class dragon64_state : public dragon_state
49{
50public:
51   dragon64_state(const machine_config &mconfig, device_type type, const char *tag);
52 
53   required_device<acia6551_device> m_acia;
54 
55protected:
56   virtual DECLARE_READ8_MEMBER( ff00_read );
57   virtual DECLARE_WRITE8_MEMBER( ff00_write );
58 
59   virtual void pia1_pb_changed(void);
60   void page_rom(bool romswitch);
61};
62 
63#endif /* __DRAGON__ */
src/mess/includes/mc1000.h
r13256r13257
66#include "emu.h"
77#include "cpu/z80/z80.h"
88#include "imagedev/cassette.h"
9#include "video/m6847.h"
9#include "video/mc6847.h"
1010#include "sound/ay8910.h"
1111#include "machine/ctronics.h"
1212#include "machine/rescap.h"
r13256r13257
3636   { }
3737
3838   required_device<cpu_device> m_maincpu;
39   required_device<device_t> m_vdg;
39   required_device<mc6847_base_device> m_vdg;
4040   optional_device<device_t> m_crtc;
4141   required_device<device_t> m_centronics;
4242   required_device<cassette_image_device> m_cassette;
src/mess/includes/coco.h
r13256r13257
1/*****************************************************************************
1/***************************************************************************
22
3    includes/coco.h
3    coco.h
44
5    CoCo/Dragon
5    TRS-80 Radio Shack Color Computer Family
66
7****************************************************************************/
7***************************************************************************/
88
9#ifndef __COCO_H__
10#define __COCO_H__
9#pragma once
1110
12#include "imagedev/snapquik.h"
11#ifndef __COCO__
12#define __COCO__
13
14#define ADDRESS_MAP_MODERN
15
16#include "emu.h"
1317#include "imagedev/cassette.h"
14#include "machine/wd17xx.h"
15#include "machine/6883sam.h"
18#include "imagedev/bitbngr.h"
1619#include "machine/6821pia.h"
1720#include "machine/cococart.h"
18#include "imagedev/printer.h"
21#include "machine/coco_vhd.h"
22#include "machine/ram.h"
23#include "sound/dac.h"
24#include "sound/wave.h"
1925
2026
21/***************************************************************************
22    CONSTANTS
23***************************************************************************/
2427
25#define COCO_CPU_SPEED_HZ      894886   /* 0.894886 MHz */
26#define COCO_FRAMES_PER_SECOND   (COCO_CPU_SPEED_HZ / 57.0 / 263)
27#define COCO_CPU_SPEED         (attotime::from_hz(COCO_CPU_SPEED_HZ))
28#define COCO_TIMER_CMPCARRIER   (COCO_CPU_SPEED * 0.25)
28//**************************************************************************
29//  MACROS / CONSTANTS
30//**************************************************************************
2931
32INPUT_PORTS_EXTERN( coco_analog_control );
33INPUT_PORTS_EXTERN( coco_cart_autostart );
3034
31/***************************************************************************
32    TYPE DEFINITIONS
33***************************************************************************/
35SLOT_INTERFACE_EXTERN( coco_cart );
3436
35typedef struct _coco3_scanline_record coco3_scanline_record;
36struct _coco3_scanline_record
37{
38   UINT8 ff98;
39   UINT8 ff99;
40   UINT8 ff9a;
41   UINT8 index;
37/* constants */
38#define JOYSTICK_DELTA         10
39#define JOYSTICK_SENSITIVITY   100
4240
43   UINT8 palette[16];
41/* devices */
42#define MAINCPU_TAG               "maincpu"
43#define PIA0_TAG               "pia0"
44#define PIA1_TAG               "pia1"
45#define SAM_TAG                  "sam"
46#define VDG_TAG                  "vdg"
47#define SCREEN_TAG               "screen"
48#define DAC_TAG                  "dac"
49#define CARTRIDGE_TAG            "ext"
50#define BITBANGER_TAG            "bitbanger"
51#define VHD_TAG                  "vhd"
4452
45   UINT8 data[160];
46};
53/* inputs */
54#define CTRL_SEL_TAG            "ctrl_sel"
55#define HIRES_INTF_TAG            "hires_intf"
56#define CART_AUTOSTART_TAG         "cart_autostart"
57#define JOYSTICK_RX_TAG            "joystick_rx"
58#define JOYSTICK_RY_TAG            "joystick_ry"
59#define JOYSTICK_LX_TAG            "joystick_lx"
60#define JOYSTICK_LY_TAG            "joystick_ly"
61#define JOYSTICK_BUTTONS_TAG      "joystick_buttons"
62#define RAT_MOUSE_RX_TAG         "rat_mouse_rx"
63#define RAT_MOUSE_RY_TAG         "rat_mouse_ry"
64#define RAT_MOUSE_LX_TAG         "rat_mouse_lx"
65#define RAT_MOUSE_LY_TAG         "rat_mouse_ly"
66#define RAT_MOUSE_BUTTONS_TAG      "rat_mouse_buttons"
67#define DIECOM_LIGHTGUN_RX_TAG      "dclg_rx"
68#define DIECOM_LIGHTGUN_RY_TAG      "dclg_ry"
69#define DIECOM_LIGHTGUN_LX_TAG      "dclg_lx"
70#define DIECOM_LIGHTGUN_LY_TAG      "dclg_ly"
71#define DIECOM_LIGHTGUN_BUTTONS_TAG   "dclg_triggers"
4772
48typedef struct _coco3_video coco3_video;
49struct _coco3_video
50{
51   /* Info set up on initialization */
52   UINT32 composite_palette[64];
53   UINT32 rgb_palette[64];
54   UINT8 fontdata[128][8];
55   emu_timer *gime_fs_timer;
73MACHINE_CONFIG_EXTERN( coco_sound );
5674
57   /* CoCo 3 palette status */
58   UINT8 palette_ram[16];
59   UINT32 palette_colors[16];
6075
61   /* Incidentals */
62   UINT32 legacy_video;
63   UINT32 top_border_scanlines;
64   UINT32 display_scanlines;
65   UINT32 video_position;
66   UINT8 line_in_row;
67   UINT8 blink;
68   UINT8 dirty[2];
69   UINT8 video_type;
7076
71   /* video state; every scanline the video state for the scanline is copied
72     * here and only rendered in SCREEN_UPDATE */
73   coco3_scanline_record scanlines[384];
74};
77//**************************************************************************
78//  TYPE DEFINITIONS
79//**************************************************************************
7580
76
7781class coco_state : public driver_device
7882{
7983public:
80   coco_state(const machine_config &mconfig, device_type type, const char *tag)
81      : driver_device(mconfig, type, tag) { }
84   coco_state(const machine_config &mconfig, device_type type, const char *tag);
8285
83   cococart_slot_device *m_cococart_device;
84   cassette_image_device *m_cassette_device;
85   device_t *m_bitbanger_device;
86   printer_image_device *m_printer_device;
87   device_t *m_dac;
88   device_t *m_sam;
89   pia6821_device *m_pia_0;
90   pia6821_device *m_pia_1;
91   pia6821_device *m_pia_2;
92   UINT8 *m_rom;
93   int m_dclg_state;
94   int m_dclg_output_h;
95   int m_dclg_output_v;
96   int m_dclg_timer;
97   UINT8 (*update_keyboard)(running_machine &machine);
98   emu_timer *m_update_keyboard_timer;
99   emu_timer *m_mux_sel1_timer;
100   emu_timer *m_mux_sel2_timer;
101   UINT8 m_mux_sel1;
102   UINT8 m_mux_sel2;
103   UINT8 m_bitbanger_output_value;
104   UINT8 m_bitbanger_input_value;
105   UINT8 m_dac_value;
106   int m_dgnalpha_just_reset;
107   UINT8 *m_bas_rom_bank;
108   UINT8 *m_bottom_32k;
109   timer_expired_func m_recalc_interrupts;
110   int m_hiresjoy_ca;
111   attotime m_hiresjoy_xtransitiontime;
112   attotime m_hiresjoy_ytransitiontime;
113   int m_dclg_previous_bit;
114   void (*printer_out)(running_machine &machine, int data);
115};
86   required_device<cpu_device> m_maincpu;
87   required_device<pia6821_device> m_pia_0;
88   required_device<pia6821_device> m_pia_1;
89   required_device<device_t> m_dac;
90   required_device<device_t> m_wave;
91   required_device<cococart_slot_device> m_cococart;
92   required_device<ram_device> m_ram;
93   required_device<cassette_image_device> m_cassette;
94   optional_device<bitbanger_device> m_bitbanger;
95   optional_device<coco_vhd_image_device> m_vhd;
11696
117class coco3_state : public coco_state
118{
119public:
120   coco3_state(const machine_config &mconfig, device_type type, const char *tag)
121      : coco_state(mconfig, type, tag) { }
97   static const pia6821_interface pia0_config;
98   static const pia6821_interface pia1_config;
99   static const cococart_interface cartridge_config;
100   static const bitbanger_config coco_bitbanger_config;
101   static const cassette_interface coco_cassette_interface;
122102
123   int m_enable_64k;
124   UINT8 m_mmu[16];
125   UINT8 m_interupt_line;
126   emu_timer *m_gime_timer;
127   UINT8 m_gimereg[16];
128   UINT8 m_gime_firq;
129   UINT8 m_gime_irq;
130   coco3_video *m_video;
131};
103   /* driver update handlers */
104   static INPUT_CHANGED(keyboard_changed);
105   static INPUT_CHANGED(joystick_mode_changed);
106   static void bitbanger_callback(running_machine &machine, UINT8 bit);
132107
108   /* IO */
109   virtual DECLARE_READ8_MEMBER( ff00_read );
110   virtual DECLARE_WRITE8_MEMBER( ff00_write );
111   virtual DECLARE_READ8_MEMBER( ff20_read );
112   virtual DECLARE_WRITE8_MEMBER( ff20_write );
113   virtual DECLARE_READ8_MEMBER( ff40_read );
114   virtual DECLARE_WRITE8_MEMBER( ff40_write );
115   DECLARE_READ8_MEMBER( ff60_read );
116   DECLARE_WRITE8_MEMBER( ff60_write );
133117
134/***************************************************************************
135    PROTOTYPES
136***************************************************************************/
118protected:
119   /* device-level overrides */
120   virtual void device_start();
121   virtual void device_reset();
122   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
137123
138/*----------- defined in video/coco.c -----------*/
124   /* interrupts */
125   virtual bool firq_get_line(void);
126   virtual bool irq_get_line(void);
127   void recalculate_irq(void);
128   void recalculate_firq(void);
139129
140ATTR_CONST UINT8 coco_get_attributes(running_machine &machine, UINT8 c,int scanline, int pos);
130   /* changed handlers */
131   virtual void pia1_pa_changed(void);
132   virtual void pia1_pb_changed(void);
133   virtual void bitbanger_changed(bool newvalue);
141134
142VIDEO_START( dragon );
143VIDEO_START( coco );
144VIDEO_START( coco2b );
135   /* miscellaneous */
136   virtual void update_keyboard_input(UINT8 value, UINT8 z);
137   virtual void cart_w(bool state);
138   DECLARE_WRITE_LINE_MEMBER( cart_w ) { cart_w((bool) state); }
145139
140   /* PIA0 */
141   DECLARE_WRITE8_MEMBER( pia0_pb_w );
142   DECLARE_WRITE_LINE_MEMBER( pia0_ca2_w );
143   DECLARE_WRITE_LINE_MEMBER( pia0_cb2_w );
144   DECLARE_WRITE_LINE_MEMBER( pia0_irq_a );
145   DECLARE_WRITE_LINE_MEMBER( pia0_irq_b );
146146
147/*----------- defined in video/coco3.c -----------*/
147   /* PIA1 */
148   DECLARE_READ8_MEMBER( pia1_pa_r );
149   DECLARE_READ8_MEMBER( pia1_pb_r );
150   DECLARE_WRITE8_MEMBER( pia1_pa_w );
151   DECLARE_WRITE8_MEMBER( pia1_pb_w );
152   DECLARE_WRITE_LINE_MEMBER( pia1_ca2_w );
153   DECLARE_WRITE_LINE_MEMBER( pia1_cb2_w );
154   DECLARE_WRITE_LINE_MEMBER( pia1_firq_a );
155   DECLARE_WRITE_LINE_MEMBER( pia1_firq_b );
148156
149VIDEO_START( coco3 );
150VIDEO_START( coco3p );
151SCREEN_UPDATE( coco3 );
152WRITE8_HANDLER ( coco3_palette_w );
153UINT32 coco3_get_video_base(running_machine &machine, UINT8 ff9d_mask, UINT8 ff9e_mask);
154void coco3_vh_blink(running_machine &machine);
157private:
158   // timer constants
159   static const device_timer_id TIMER_HIRES_JOYSTICK_X = 0;
160   static const device_timer_id TIMER_HIRES_JOYSTICK_Y = 1;
161   static const device_timer_id TIMER_DIECOM_LIGHTGUN = 2;
155162
163   typedef enum
164   {
165      SOUNDMUX_SEL1 = 1,
166      SOUNDMUX_SEL2 = 2,
167      SOUNDMUX_ENABLE = 4
168   } soundmux_status_t;
156169
157/*----------- defined in machine/coco.c -----------*/
158extern const wd17xx_interface dgnalpha_wd17xx_interface;
159extern const pia6821_interface coco_pia_intf_0;
160extern const pia6821_interface coco_pia_intf_1;
161extern const pia6821_interface coco2_pia_intf_0;
162extern const pia6821_interface coco2_pia_intf_1;
163extern const pia6821_interface coco3_pia_intf_0;
164extern const pia6821_interface coco3_pia_intf_1;
165extern const pia6821_interface dragon32_pia_intf_0;
166extern const pia6821_interface dragon32_pia_intf_1;
167extern const pia6821_interface dragon64_pia_intf_0;
168extern const pia6821_interface dragon64_pia_intf_1;
169extern const pia6821_interface dgnalpha_pia_intf_0;
170extern const pia6821_interface dgnalpha_pia_intf_1;
171extern const pia6821_interface dgnalpha_pia_intf_2;
172extern const sam6883_interface coco_sam_intf;
173extern const sam6883_interface coco3_sam_intf;
170   typedef enum
171   {
172      JOYSTICK_NONE = 0x00,
173      JOYSTICK_NORMAL = 0x01,
174      JOYSTICK_RAT_MOUSE = 0x02,
175      JOYSTICK_DIECOM_LIGHT_GUN = 0x03
176   } joystick_type_t;
174177
175MACHINE_START( dragon32 );
176MACHINE_START( dragon64 );
177MACHINE_START( tanodr64 );
178MACHINE_START( dgnalpha );
179MACHINE_RESET( dgnalpha );
180MACHINE_START( coco );
181MACHINE_START( coco2 );
182MACHINE_START( coco3 );
183MACHINE_RESET( coco3 );
178   typedef enum
179   {
180      HIRES_NONE = 0x00,
181      HIRES_RIGHT = 0x01,
182      HIRES_RIGHT_COCOMAX3 = 0x02,
183      HIRES_LEFT = 0x03,
184      HIRES_LEFT_COCOMAX3 = 0x04,
185   } hires_type_t;
184186
185INPUT_CHANGED(coco_keyboard_changed);
186INPUT_CHANGED(coco_joystick_mode_changed);
187   typedef struct
188   {
189      const input_port_config *m_input[2][2];
190      const input_port_config *m_buttons;
187191
188SNAPSHOT_LOAD ( coco_pak );
189SNAPSHOT_LOAD ( coco3_pak );
190QUICKLOAD_LOAD ( coco );
191READ8_HANDLER ( coco3_mmu_r );
192WRITE8_HANDLER ( coco3_mmu_w );
193READ8_HANDLER ( coco3_gime_r );
194WRITE8_HANDLER ( coco3_gime_w );
195offs_t coco3_mmu_translate(running_machine &machine,int bank, int offset);
196WRITE8_DEVICE_HANDLER( coco_pia_1_w );
197void coco3_horizontal_sync_callback(running_machine &machine,int data);
198void coco3_field_sync_callback(running_machine &machine,int data);
199void coco3_gime_field_sync_callback(running_machine &machine);
192      UINT8 input(int joystick, int axis) const { return m_input[joystick][axis] ? input_port_read_direct(m_input[joystick][axis]) : 0x00; }
193      UINT8 buttons(void) const { return m_buttons ? input_port_read_direct(m_buttons) : 0x00; }
194   } analog_input_t;
200195
201WRITE_LINE_DEVICE_HANDLER(coco_cart_w);
202WRITE_LINE_DEVICE_HANDLER(coco3_cart_w);
203WRITE_LINE_DEVICE_HANDLER(coco_nmi_w);
204WRITE_LINE_DEVICE_HANDLER(coco_halt_w);
196   void analog_port_start(analog_input_t *analog, const char *rx_tag, const char *ry_tag, const char *lx_tag, const char *ly_tag, const char *buttons_tag);
205197
206/* Compusense Dragon Plus board */
207READ8_HANDLER ( dgnplus_reg_r );
208WRITE8_HANDLER ( dgnplus_reg_w );
198   /* wrappers for configuration */
199   joystick_type_t joystick_type(int index);
200   hires_type_t hires_interface_type(void);
201   bool is_joystick_hires(int joystick_index);
209202
210READ8_HANDLER( dgnalpha_mapped_irq_r );
203   soundmux_status_t soundmux_status(void);
204   UINT8 sound_value(void);
205   void update_sound(void);
206   bool joyin(void);
207   void poll_joystick(bool *joyin, UINT8 *buttons);
208   void poll_keyboard(void);
209   void poll_hires_joystick(void);
210   void update_cassout(int cassout);
211   void update_prinout(bool prinout);
212   DECLARE_WRITE_LINE_MEMBER( bitbanger_callback );
213   void diecom_lightgun_clock(void);
211214
212/* Dragon Alpha AY-8912 */
213READ8_HANDLER ( dgnalpha_psg_porta_read );
214WRITE8_HANDLER ( dgnalpha_psg_porta_write );
215   /* thin wrappers for PIA output */
216   UINT8 dac_output(void)   { return m_dac_output; }   /* PA drives the DAC */
217   bool sel1(void)         { return m_pia_0->ca2_output() ? true : false; }
218   bool sel2(void)         { return m_pia_0->cb2_output() ? true : false; }
219   bool snden(void)      { return m_pia_1->cb2_output() ? true : false; }
215220
216/* Dragon Alpha WD2797 FDC */
217READ8_HANDLER(dgnalpha_wd2797_r);
218WRITE8_HANDLER(dgnalpha_wd2797_w);
221   /* disassembly override */
222   static offs_t dasm_override(device_t &device, char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, int options);
219223
220/* Dragon Alpha Modem, just dummy funcs at the mo */
221READ8_HANDLER(dgnalpha_modem_r);
222WRITE8_HANDLER(dgnalpha_modem_w);
224   /* input ports */
225   const input_port_config *m_keyboard[7];
226   const input_port_config *m_joystick_type_control;
227   const input_port_config *m_joystick_hires_control;
228   analog_input_t m_joystick;
229   analog_input_t m_rat_mouse;
230   analog_input_t m_diecom_lightgun;
223231
224#ifdef UNUSED_FUNCTION
225void coco_set_halt_line(running_machine &machine, int halt_line);
226#endif
232   /* DAC output */
233   UINT8 m_dac_output;
227234
228/* CoCo 3 video vars; controlling key aspects of the emulation */
229struct coco3_video_vars
230{
231   UINT8 m_bordertop_192;
232   UINT8 m_bordertop_199;
233   UINT8 m_bordertop_0;
234   UINT8 m_bordertop_225;
235   unsigned int hs_gime_flip : 1;
236   unsigned int fs_gime_flip : 1;
237   unsigned int hs_pia_flip : 1;
238   unsigned int fs_pia_flip : 1;
239   UINT16 m_rise_scanline;
240   UINT16 m_fall_scanline;
235   /* hires interface */
236   emu_timer *m_hiresjoy_transition_timer[2];
237   bool m_hiresjoy_ca;
238
239   /* diecom lightgun */
240   emu_timer *m_diecom_lightgun_timer;
241   bool m_dclg_previous_bit;
242   UINT8 m_dclg_output_h;
243   UINT8 m_dclg_output_v;
244   UINT8 m_dclg_state;
245   UINT16 m_dclg_timer;
241246};
242247
243extern const struct coco3_video_vars coco3_vidvars;
244
245/* Setting it bitbanger bit */
246void coco_bitbanger_callback(running_machine &machine, UINT8 bit);
247void coco3_bitbanger_callback(running_machine &machine, UINT8 bit);
248
249#endif /* __COCO_H__ */
248#endif /* __COCO__ */
src/mess/includes/phc25.h
r13256r13257
1010#include "imagedev/cassette.h"
1111#include "machine/ram.h"
1212#include "machine/ctronics.h"
13#include "video/m6847.h"
13#include "video/mc6847.h"
1414#include "sound/ay8910.h"
1515
1616#define SCREEN_TAG      "screen"
r13256r13257
3333   { }
3434
3535   required_device<cpu_device> m_maincpu;
36   required_device<device_t> m_vdg;
36   required_device<mc6847_base_device> m_vdg;
3737   required_device<device_t> m_centronics;
3838   required_device<cassette_image_device> m_cassette;
3939
r13256r13257
4444   DECLARE_WRITE8_MEMBER( port40_w );
4545   DECLARE_READ8_MEMBER( video_ram_r );
4646
47   static UINT8 ntsc_char_rom_r(running_machine &machine, UINT8 ch, int line);
48   static UINT8 pal_char_rom_r(running_machine &machine, UINT8 ch, int line);
49
4750   /* video state */
4851   UINT8 *m_video_ram;
4952   UINT8 *m_char_rom;
src/mess/includes/coco12.h
r0r13257
1/***************************************************************************
2 
3    coco12.h
4 
5    TRS-80 Radio Shack Color Computer 1/2 Family
6 
7***************************************************************************/
8 
9#pragma once
10 
11#ifndef __COCO12__
12#define __COCO12__
13 
14#define ADDRESS_MAP_MODERN
15 
16#include "includes/coco.h"
17#include "machine/6883sam.h"
18#include "video/mc6847.h"
19 
20 
21 
22//**************************************************************************
23//  MACROS / CONSTANTS
24//**************************************************************************
25 
26#define SAM_TAG         "sam"
27#define VDG_TAG         "vdg"
28 
29 
30 
31//**************************************************************************
32//  TYPE DEFINITIONS
33//**************************************************************************
34 
35class coco12_state : public coco_state
36{
37public:
38   coco12_state(const machine_config &mconfig, device_type type, const char *tag);
39 
40   required_device<sam6883_device> m_sam;
41   required_device<mc6847_base_device> m_vdg;
42 
43   static const mc6847_interface mc6847_config;
44   static const sam6883_interface sam6883_config;
45 
46protected:
47   virtual void device_start();
48   virtual bool screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect);
49 
50   /* PIA1 */
51   virtual void pia1_pb_changed(void);
52 
53private:
54   DECLARE_WRITE_LINE_MEMBER( horizontal_sync );
55   DECLARE_WRITE_LINE_MEMBER( field_sync );
56 
57   DECLARE_READ8_MEMBER( sam_read );
58 
59   void configure_sam(void);
60};
61 
62 
63#endif /* __COCO12__ */
src/mess/includes/atom.h
r13256r13257
2121#include "machine/i8255.h"
2222#include "machine/i8271.h"
2323#include "sound/speaker.h"
24#include "video/m6847.h"
24#include "video/mc6847.h"
2525
2626#define SY6502_TAG      "ic22"
2727#define INS8255_TAG      "ic25"
r13256r13257
5252   { }
5353
5454   required_device<cpu_device> m_maincpu;
55   required_device<device_t> m_vdg;
55   required_device<mc6847_base_device> m_vdg;
5656   required_device<cassette_image_device> m_cassette;
5757   required_device<device_t> m_centronics;
5858   required_device<device_t> m_speaker;
src/mess/includes/coco3.h
r0r13257
1/***************************************************************************
2 
3    coco3.h
4 
5    TRS-80 Radio Shack Color Computer 1/2 Family
6 
7***************************************************************************/
8 
9#pragma once
10 
11#ifndef __COCO3__
12#define __COCO3__
13 
14#define ADDRESS_MAP_MODERN
15 
16#include "includes/coco.h"
17#include "video/gime.h"
18 
19 
20 
21//**************************************************************************
22//  MACROS / CONSTANTS
23//**************************************************************************
24 
25#define GIME_TAG            "gime"
26#define VDG_TAG               "vdg"
27#define COMPOSITE_SCREEN_TAG   "composite"
28#define RGB_SCREEN_TAG         "rgb"
29 
30 
31 
32//**************************************************************************
33//  TYPE DEFINITIONS
34//**************************************************************************
35 
36class coco3_state : public coco_state
37{
38public:
39   coco3_state(const machine_config &mconfig, device_type type, const char *tag);
40 
41   required_device<gime_base_device> m_gime;
42 
43   virtual DECLARE_WRITE8_MEMBER( ff20_write );
44   virtual DECLARE_READ8_MEMBER( ff40_read );
45   virtual DECLARE_WRITE8_MEMBER( ff40_write );
46 
47   DECLARE_WRITE_LINE_MEMBER(gime_firq_w) { recalculate_firq(); }
48   DECLARE_WRITE_LINE_MEMBER(gime_irq_w) { recalculate_irq(); }
49 
50protected:
51   virtual bool screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect);
52 
53   /* interrupts */
54   virtual bool firq_get_line(void);
55   virtual bool irq_get_line(void);
56 
57   /* miscellaneous */
58   virtual void update_keyboard_input(UINT8 value, UINT8 z);
59   virtual void cart_w(bool line);
60};
61 
62#endif // __COCO3__
src/mess/includes/dgnalpha.h
r0r13257
1/***************************************************************************
2 
3    dgnalpha.h
4 
5    Dragon Alpha
6 
7***************************************************************************/
8 
9#pragma once
10 
11#ifndef __DGNALPHA__
12#define __DGNALPHA__
13 
14#define ADDRESS_MAP_MODERN
15 
16#include "includes/dragon.h"
17#include "sound/ay8910.h"
18#include "machine/wd17xx.h"
19 
20 
21 
22//**************************************************************************
23//  MACROS / CONSTANTS
24//**************************************************************************
25 
26/* devices */
27#define PIA2_TAG               "pia2"
28#define AY8912_TAG               "ay8912"
29#define WD2797_TAG               "wd2797"
30 
31 
32 
33//**************************************************************************
34//  TYPE DEFINITIONS
35//**************************************************************************
36 
37class dragon_alpha_state : public dragon64_state
38{
39public:
40   dragon_alpha_state(const machine_config &mconfig, device_type type, const char *tag);
41 
42   required_device<pia6821_device> m_pia_2;
43   required_device<device_t> m_ay8912;
44   required_device<device_t> m_fdc;
45 
46   static const pia6821_interface pia2_config;
47   static const ay8910_interface ay8912_interface;
48   static const wd17xx_interface fdc_interface;
49 
50protected:
51   /* driver overrides */
52   virtual void device_start(void);
53   virtual void device_reset(void);
54 
55   /* interrupts */
56   virtual bool firq_get_line(void);
57 
58   /* PIA1 */
59   virtual DECLARE_READ8_MEMBER( ff20_read );
60   virtual DECLARE_WRITE8_MEMBER( ff20_write );
61 
62private:
63   UINT8 m_just_reset;
64 
65   /* pia2 */
66   DECLARE_WRITE8_MEMBER( pia2_pa_w );
67   DECLARE_WRITE_LINE_MEMBER( pia2_firq_a );
68   DECLARE_WRITE_LINE_MEMBER( pia2_firq_b );
69 
70   /* psg */
71   DECLARE_READ8_MEMBER( psg_porta_read );
72   DECLARE_WRITE8_MEMBER( psg_porta_write );
73 
74   /* fdc */
75   DECLARE_WRITE_LINE_MEMBER( fdc_intrq_w );
76   DECLARE_WRITE_LINE_MEMBER( fdc_drq_w );
77   
78   /* modem */
79   UINT8 modem_r(offs_t offset);
80   void modem_w(offs_t offset, UINT8 data);
81};
82 
83#endif /* __DGNALPHA__ */
src/mess/formats/cocopak.c
r13256r13257
1/* PAK file loader
2 *
3 * TODO: Support .PAK files generated by PC-Dragon
4 */
5
6#include "formats/cocopak.h"
7
8/*  PAK files have the following format:
9 *
10 *  length      (two bytes, little endian)
11 *  base address (two bytes, little endian, typically 0xc000)
12 *  ...data... (size is length)
13 *  optional trailer
14 *
15 *  The format for PAK files just plain bites - the extra info is snapshot info
16 *  and it is loaded with internal state specific to Jeff's emulator. What ever
17 *  happened to desiging clean file formats that don't need to be changed with
18 *  every version of ones program?
19 *
20 *  For alignment purposes, some 16 bit values are divided into two UINT8s
21 *
22 *  The PAK file format's trailer defines the state of the machine other then
23 *  the core memory.  This trailer comes in many variations.  I have labeled
24 *  them in the following way (trailer sizes are in parentheses):
25 *
26 *      V12     - The version in JeffV's emulator version 1.2
27 *      V14     - The version in JeffV's emulator version 1.4   (457)
28 *      VOTHER  - From some "other" version of JeffV's emulator
29 *      VLITE   - From yet another version of JeffV's emulator  (35)
30 *
31 *  The following table shows what segments appear in each trailer variant:
32 *
33 *  Trailer Segment     V12     V14     VOTHER  VLITE
34 *  ---------------     ---     ---     ------  -----
35 *  pak_trailer1        1       1       1       1
36 *  pak_trailer2        2
37 *  pak_trailer3        3       2       2       2
38 *  pak_trailer4        4       3       3
39 *  pak_trailer5        5
40 *  pak_trailer6        6       5       4
41 *  pak_trailer7        7               5
42 *  pak_trailer8                6
43 *  pak_trailer9        8       7       6
44 *  pak_trailer10       9       4       7
45 *  pak_trailer11       10      8       8
46 *  pak_trailer12               9
47 *  pak_trailer13       11              9
48 */
49
50/* All versions */
51typedef struct {
52   char name[33];
53} pak_trailer1;
54
55/* Only version 1.2 */
56typedef struct {
57   UINT8 debug_dumpflag;
58   UINT8 debug_disassembleflag;
59   UINT16 debug_disassembleaddr;
60} pak_trailer2;
61
62/* All versions */
63typedef struct {
64   UINT16 reg_pc;
65} pak_trailer3;
66
67/* All versions except lite */
68typedef struct {
69   UINT16 reg_x;
70   UINT16 reg_y;
71   UINT16 reg_u;
72   UINT16 reg_s;
73   UINT8 dummy_zero1;
74   UINT8 reg_dp;
75   UINT8 reg_b;
76   UINT8 reg_a;
77} pak_trailer4;
78
79/* Only version 1.2 */
80typedef struct {
81   UINT16 debug_unknown;
82} pak_trailer5;
83
84/* All versions except lite */
85typedef struct {
86   UINT8 flags_8086_lsb; /* ?!? */
87   UINT8 flags_8086_msb; /* ?!? */
88   UINT8 reg_cc;
89} pak_trailer6;
90
91/* All versions except 1.4 and lite*/
92typedef struct {
93   UINT16 lowmem_readseg;
94   UINT16 lowmem_writeseg;
95   UINT16 himem_readseg;
96   UINT16 himem_writeseg;
97} pak_trailer7;
98
99/* Only version 1.4 */
100typedef struct {
101   UINT8 page_status;
102   UINT8 rom_status;
103   UINT8 io_ff02;
104   UINT8 io_ff03;
105   UINT8 io_ff22;
106} pak_trailer8;
107
108/* All versions except lite */
109typedef struct {
110   UINT16 video_base;
111   UINT16 video_end;
112} pak_trailer9;
113
114/* All versions except lite; come before pak_trailer6 in 1.4 */
115typedef struct {
116   UINT8 dummy_zero2[6];
117} pak_trailer10;
118
119/* Used by PC-Dragon; UINT16's are little endian */
120typedef struct {
121   /* Info */
122   UINT8 data1[2];
123   UINT8 magic1[2];
124   UINT8 checksum;
125   UINT8 pak_version;
126   UINT8 ext_version;
127   UINT8 emu_version;
128   UINT8 state_only;
129   UINT8 architecture;
130   UINT8 rom_start;
131
132   /* Machine state */
133   UINT8 irq_cycles_lsb;
134   UINT8 irq_cycles_msb;
135   UINT8 screen_size;
136   UINT8 pia[9];
137   UINT8 last_shift;
138   UINT8 filemem[8];
139
140   /* Debugger */
141   UINT16 last_text_base;
142   UINT16 breakpoints[6];
143   UINT16 break_operation;
144   UINT16 dasm_pcr;
145   UINT16 fill_start;
146   UINT16 fill_end;
147   UINT8 fill_value;
148   UINT8 left_window;
149   UINT16 temp_break;
150   UINT16 break_value;
151   UINT8 break_control;
152   UINT8 break_type;
153   UINT16 internal;
154   UINT16 dumpaddr;
155} pcd_info1;
156
157/* Used by PC-Dragon; UINT16's are little endian */
158typedef struct {
159   UINT8 pakdata[65];
160   UINT8 dummy1;
161   UINT8 background;
162   UINT8 foreground;
163   UINT8 vmode[2][2][6];
164   UINT8 border[2][2];
165   UINT8 dummy2;
166   UINT16 irq_rate;
167   UINT8 servicemem[16];
168   UINT8 speed;
169   UINT8 lpt_and_swapping;
170   UINT8 hardjoy_resol;
171} pcd_info2;
172
173/* All versions except lite */
174typedef struct {
175   UINT8 writeprotect;
176   char disk_directory[66];   /* Or could be a pcd_info1 */
177   char disk_name[4][32];      /* Or could be a pcd_info2 */
178   char pak_directory[66];
179   UINT8 crlf;
180   UINT8 keyboard_mode;
181   UINT8 speed_lsb;
182   UINT8 speed_msb;
183   UINT8 left_joystick;
184   UINT8 right_joystick;
185   UINT8 lowercase_lsb;
186   UINT8 lowercase_msb;
187   UINT8 sound;
188   UINT8 artifact;
189   UINT8 dragon_rom;
190} pak_trailer11;
191
192/* Only version 1.4 */
193typedef struct {
194   UINT16 joystick_limits[8];
195   UINT16 clock;
196   UINT8 drive_mode;
197   UINT8 volume;
198   UINT8 cassette_mode;
199   char cassette_directory[66];
200   char cassette_name[33];
201} pak_trailer12;
202
203/* All versions except 1.4 and lite */
204typedef struct {
205   UINT8 dummy_zero3[4];
206   UINT16 video_base2;
207   UINT16 video_end2;
208   UINT16 dummy_zero4;
209   UINT8 io_ff22;
210   UINT8 io_ff02;
211   UINT8 io_ff03;
212} pak_trailer13;
213
214#define PAK_V12_SIZE   (sizeof(pak_trailer1) + sizeof(pak_trailer2) + \
215   sizeof(pak_trailer3) + sizeof(pak_trailer4) + sizeof(pak_trailer5) + \
216   sizeof(pak_trailer6) + sizeof(pak_trailer7) + sizeof(pak_trailer9) + \
217   sizeof(pak_trailer10) + sizeof(pak_trailer11) + sizeof(pak_trailer13))
218
219#define PAK_V14_SIZE   (sizeof(pak_trailer1) + sizeof(pak_trailer3) + \
220   sizeof(pak_trailer4) + sizeof(pak_trailer10) + sizeof(pak_trailer6) + \
221   sizeof(pak_trailer8) + sizeof(pak_trailer9) + sizeof(pak_trailer11) + \
222   sizeof(pak_trailer12))
223
224#define PAK_VOTHER_SIZE   (sizeof(pak_trailer1) + sizeof(pak_trailer3) + \
225   sizeof(pak_trailer4) + sizeof(pak_trailer6) + sizeof(pak_trailer7) + \
226   sizeof(pak_trailer9) + sizeof(pak_trailer10) + sizeof(pak_trailer11) + \
227   sizeof(pak_trailer13))
228
229#define PAK_VLITE_SIZE (sizeof(pak_trailer1) + sizeof(pak_trailer3))
230
231static UINT16 calculate_sam_video(pak_trailer9 *p9)
232{
233   UINT16 sam;
234   UINT16 video_base;
235   UINT16 video_end;
236
237   video_base = LITTLE_ENDIANIZE_INT16(p9->video_base);
238   video_end = LITTLE_ENDIANIZE_INT16(p9->video_end);
239
240   sam = (video_base >> 6) & 0x3f8;
241
242   switch(video_end - video_base) {
243   case 512:
244      sam |= 0;
245      break;
246   case 1024:
247      sam |= 1;
248      break;
249   case 1536:
250   case 2048:
251      sam |= 2;
252      break;
253   case 3072:
254      sam |= 4;
255      break;
256   case 6144:
257   default:
258      sam |= 6;
259      break;
260   }
261
262   return sam;
263}
264
265int pak_decode_trailer(UINT8 *rawtrailer, int rawtrailerlen, pak_decodedtrailer *trailer)
266{
267   pak_trailer3 p3;
268   pak_trailer4 p4;
269   pak_trailer6 p6;
270   pak_trailer9 p9;
271   pak_trailer11 p11;
272   pcd_info1 *pcd1 = NULL;
273   //pcd_info2 *pcd2 = NULL;
274
275   union {
276      pak_trailer8 p8;
277      struct {
278         pak_trailer7 p7;
279         pak_trailer13 p13;
280      } s;
281   } u1;
282
283   switch(rawtrailerlen) {
284   case PAK_V12_SIZE:
285   case PAK_V14_SIZE:
286   case PAK_VOTHER_SIZE:
287   case PAK_VLITE_SIZE:
288      break;
289   default:
290      return 1;
291   }
292
293   memset(&p3, 0, sizeof(p3));
294   memset(&p4, 0, sizeof(p4));
295   memset(&p6, 0, sizeof(p6));
296   memset(&p9, 0, sizeof(p9));
297   memset(&u1, 0, sizeof(u1));
298
299   rawtrailer += sizeof(pak_trailer1);
300
301   if (rawtrailerlen == PAK_V12_SIZE) {
302      rawtrailer += sizeof(pak_trailer2);
303   }
304
305   memcpy(&p3, rawtrailer, sizeof(pak_trailer3));
306   rawtrailer += sizeof(pak_trailer3);
307
308   if (rawtrailerlen != PAK_VLITE_SIZE) {
309      memcpy(&p4, rawtrailer, sizeof(pak_trailer4));
310      rawtrailer += sizeof(pak_trailer4);
311   }
312
313   if (rawtrailerlen == PAK_V14_SIZE) {
314      rawtrailer += sizeof(pak_trailer10);
315   }
316   else if (rawtrailerlen == PAK_V12_SIZE) {
317      rawtrailer += sizeof(pak_trailer5);
318   }
319
320   if (rawtrailerlen != PAK_VLITE_SIZE) {
321      memcpy(&p6, rawtrailer, sizeof(pak_trailer6));
322      rawtrailer += sizeof(pak_trailer6);
323   }
324
325   if (rawtrailerlen == PAK_V14_SIZE) {
326      memcpy(&u1.p8, rawtrailer, sizeof(pak_trailer8));
327      rawtrailer += sizeof(pak_trailer8);
328   }
329   else if (rawtrailerlen != PAK_VLITE_SIZE) {
330      memcpy(&u1.s.p7, rawtrailer, sizeof(pak_trailer7));
331      rawtrailer += sizeof(pak_trailer7);
332   }
333
334   if (rawtrailerlen != PAK_VLITE_SIZE) {
335      memcpy(&p9, rawtrailer, sizeof(pak_trailer9));
336      rawtrailer += sizeof(pak_trailer9);
337   }
338
339   if ((rawtrailerlen != PAK_V14_SIZE) && (rawtrailerlen != PAK_VLITE_SIZE)) {
340      rawtrailer += sizeof(pak_trailer10);
341   }
342
343   if (rawtrailerlen != PAK_VLITE_SIZE) {
344      memcpy(&p11, rawtrailer, sizeof(pak_trailer11));
345      rawtrailer += sizeof(pak_trailer11);
346
347      /* Is this a fancy image with PC-Dragon Info in it? */
348      pcd1 = (pcd_info1 *) p11.disk_directory;
349      if ((pcd1->magic1[0] == 0xAB) && (pcd1->magic1[1] == 0xBA)) {
350         /* Yes it is! */
351         /* Note! I should be checking the checksum */
352         //pcd2 = (pcd_info2 *) p11.disk_name;
353      }
354      else {
355         /* No it is not */
356         pcd1 = NULL;
357      }
358   }
359
360   if (rawtrailerlen == PAK_V14_SIZE) {
361      rawtrailer += sizeof(pak_trailer12);
362   }
363   else if (rawtrailerlen != PAK_VLITE_SIZE) {
364      memcpy(&u1.s.p13, rawtrailer, sizeof(pak_trailer13));
365      rawtrailer += sizeof(pak_trailer13);
366   }
367
368   trailer->reg_pc = LITTLE_ENDIANIZE_INT16(p3.reg_pc);
369   trailer->reg_x = LITTLE_ENDIANIZE_INT16(p4.reg_x);
370   trailer->reg_y = LITTLE_ENDIANIZE_INT16(p4.reg_y);
371   trailer->reg_u = LITTLE_ENDIANIZE_INT16(p4.reg_u);
372   trailer->reg_s = LITTLE_ENDIANIZE_INT16(p4.reg_s);
373   trailer->reg_dp = p4.reg_dp;
374   trailer->reg_b = p4.reg_b;
375   trailer->reg_a = p4.reg_a;
376   trailer->reg_cc = p6.reg_cc;
377
378   trailer->pia[0] = 0x00;
379   trailer->pia[1] = 0x34;
380   trailer->pia[4] = 0x02;
381   trailer->pia[5] = 0x34;
382   trailer->pia[7] = 0x3c;
383
384   switch(rawtrailerlen) {
385   case PAK_V14_SIZE:
386      trailer->pia[2] = u1.p8.io_ff02;
387      trailer->pia[3] = u1.p8.io_ff03;
388      trailer->pia[6] = u1.p8.io_ff22;
389      trailer->sam = (u1.p8.rom_status == 0xdf) ? 0xE000 : 0x6000;
390      trailer->sam |= calculate_sam_video(&p9);
391      break;
392
393   case PAK_VLITE_SIZE:
394      /* This is a "lite" format that gives no trailer information except
395         * for the program counter... I have to set everything up as default
396         * including the stack pointer... arg this sucks...
397         */
398      trailer->pia[2] = 0xff;
399      trailer->pia[3] = 0x34;
400      trailer->pia[6] = 0x00;
401      trailer->sam = 0x6008;
402      trailer->reg_s = 0x3d7;
403      break;
404
405   default:
406      trailer->pia[2] = u1.s.p13.io_ff02;
407      trailer->pia[3] = u1.s.p13.io_ff03;
408      trailer->pia[6] = u1.s.p13.io_ff22;
409      trailer->sam = (u1.s.p7.himem_readseg == 0) ? 0xE000 : 0x6000;
410      trailer->sam |= calculate_sam_video(&p9);
411      break;
412   }
413   return 0;
414}
415
src/mess/formats/cocopak.h
r13256r13257
1#ifndef COCOPAK_H
2#define COCOPAK_H
3
4#include "emu.h"
5
6typedef struct {
7   UINT16 length;
8   UINT16 start;
9} pak_header;
10
11typedef struct {
12   UINT16 reg_pc;
13   UINT16 reg_x;
14   UINT16 reg_y;
15   UINT16 reg_u;
16   UINT16 reg_s;
17   UINT8 reg_dp;
18   UINT8 reg_b;
19   UINT8 reg_a;
20   UINT8 reg_cc;
21   UINT8 pia[8];
22   UINT16 sam;
23} pak_decodedtrailer;
24
25/* This function takes a set of bytes, interprets a PAK trailer and
26 * extracts the interesting information
27 */
28int pak_decode_trailer(UINT8 *rawtrailer, int rawtrailerlen, pak_decodedtrailer *trailer);
29
30#endif /* COCOPAK_H */
src/mess/layout/coco3.lay
r13256r13257
22<mamelayout version="2">
33   <view name="Composite">
44      <screen index="0">
5         <bounds left="0" top="0" right="4" bottom="3" />
6      </screen>
7   </view>
5      <bounds left="0" top="0" right="4" bottom="3" />
6    </screen>
7  </view>
88
9   <view name="RGB">
10      <screen index="1">
9  <view name="RGB">
10    <screen index="1">
1111         <bounds left="0" top="0" right="4" bottom="3" />
1212      </screen>
1313   </view>
src/mess/mess.mak
r13256r13257
557557   $(MESS_VIDEO)/dl1416.o      \
558558   $(MESS_VIDEO)/hd44780.o      \
559559   $(MESS_VIDEO)/hd66421.o      \
560   $(MESS_VIDEO)/m6847.o      \
560   $(MESS_VIDEO)/mc6847.o      \
561561   $(MESS_VIDEO)/saa505x.o      \
562562   $(MESS_VIDEO)/tms3556.o      \
563563   $(MESS_VIDEO)/upd7220.o      \
r13256r13257
16541654   $(MESS_MACHINE)/6883sam.o   \
16551655   $(MESS_MACHINE)/ds1315.o   \
16561656   $(MESS_MACHINE)/coco.o      \
1657   $(MESS_VIDEO)/coco.o      \
1658   $(MESS_DRIVERS)/coco.o      \
1659   $(MESS_VIDEO)/coco3.o      \
1660   $(MESS_FORMATS)/cocopak.o   \
1661   $(MESS_MACHINE)/coco_vhd.o   \
1662   $(MESS_MACHINE)/cococart.o   \
1663   $(MESS_MACHINE)/coco_232.o   \
1657   $(MESS_MACHINE)/coco12.o      \
1658   $(MESS_DRIVERS)/coco12.o      \
1659   $(MESS_MACHINE)/coco3.o      \
1660   $(MESS_DRIVERS)/coco3.o      \
1661   $(MESS_VIDEO)/gime.o         \
1662   $(MESS_MACHINE)/dragon.o      \
1663   $(MESS_DRIVERS)/dragon.o      \
1664   $(MESS_MACHINE)/dgnalpha.o      \
1665   $(MESS_DRIVERS)/dgnalpha.o      \
1666   $(MESS_FORMATS)/cocopak.o       \
1667   $(MESS_MACHINE)/coco_vhd.o      \
1668   $(MESS_MACHINE)/cococart.o      \
1669   $(MESS_MACHINE)/coco_232.o      \
16641670   $(MESS_MACHINE)/coco_orch90.o\
1665   $(MESS_MACHINE)/coco_pak.o   \
1666   $(MESS_MACHINE)/coco_fdc.o   \
1667   $(MESS_MACHINE)/coco_multi.o   \
1671   $(MESS_MACHINE)/coco_pak.o      \
1672   $(MESS_MACHINE)/coco_fdc.o      \
1673   $(MESS_MACHINE)/coco_multi.o    \
16681674   $(MESS_DRIVERS)/mc10.o      \
16691675   $(MESS_MACHINE)/trs80.o      \
16701676   $(MESS_VIDEO)/trs80.o      \
16711677   $(MESS_FORMATS)/trs_cmd.o   \
16721678   $(MESS_DRIVERS)/trs80.o      \
16731679   $(MESS_DRIVERS)/trs80m2.o   \
1674   $(MESS_VIDEO)/coco6847.o   \
16751680   $(MESS_DRIVERS)/tandy2k.o   \
16761681
16771682$(MESSOBJ)/unisys.a:         \
r13256r13257
18891894$(MESS_DRIVERS)/chessmst.o:   $(MESS_LAYOUT)/chessmst.lh
18901895$(MESS_DRIVERS)/cvicny.o:   $(MESS_LAYOUT)/cvicny.lh
18911896$(MESS_DRIVERS)/coco.o:      $(MESS_LAYOUT)/coco3.lh
1897$(MESS_DRIVERS)/coco3.o:   $(MESS_LAYOUT)/coco3.lh
18921898$(MESS_DRIVERS)/cosmicos.o:   $(MESS_LAYOUT)/cosmicos.lh
18931899$(MESS_DRIVERS)/c80.o:      $(MESS_LAYOUT)/c80.lh
18941900$(MESS_DRIVERS)/dectalk.o:   $(MESS_LAYOUT)/dectalk.lh
src/mess/drivers/coco.c
r13256r13257
1/***************************************************************************
2
3    coco.c
4
5    TRS-80 Radio Shack Color Computer Family
6
7    Mathis Rosenhauer (original driver)
8    Nate Woods (current maintainer)
9    Tim Lindner (VHD and other work)
10
11    Version information:
12
13    Basic   Extended Basic  Disk Extended
14    coco    1.0 -           -
15    cocoe   1.1 1.0         1.0
16    coco2   1.2 1.1         1.1
17    coco2b  1.3 1.1         1.1
18    coco3   1.2 2.0         1.1
19    coco3p  1.2 2.0         1.1
20    coco3h  1.2 2.0         1.1
21
22***************************************************************************/
23
24#include "emu.h"
25#include "cpu/m6809/m6809.h"
26#include "cpu/hd6309/hd6309.h"
27#include "sound/wave.h"
28#include "machine/6821pia.h"
29#include "video/coco6847.h"
30#include "machine/msm6242.h"
31#include "machine/ds1315.h"
32#include "machine/6883sam.h"
33#include "includes/coco.h"
34#include "machine/wd17xx.h"
35#include "machine/6551acia.h"
36#include "formats/coco_dsk.h"
37#include "formats/coco_cas.h"
38#include "imagedev/printer.h"
39#include "imagedev/flopdrv.h"
40#include "imagedev/cassette.h"
41#include "imagedev/bitbngr.h"
42#include "imagedev/snapquik.h"
43#include "imagedev/cartslot.h"
44#include "machine/cococart.h"
45#include "machine/coco_vhd.h"
46#include "machine/coco_232.h"
47#include "machine/coco_orch90.h"
48#include "machine/coco_pak.h"
49#include "machine/coco_fdc.h"
50#include "machine/coco_multi.h"
51#include "sound/ay8910.h"
52#include "sound/dac.h"
53#include "machine/ram.h"
54#include "coco3.lh"
55
56#define SHOW_FULL_AREA         0
57#define JOYSTICK_DELTA         10
58#define JOYSTICK_SENSITIVITY   100
59
60static ADDRESS_MAP_START( coco_map, AS_PROGRAM, 8 )
61   AM_RANGE(0x0000, 0x0FFF) AM_RAMBANK("bank1")
62   AM_RANGE(0x1000, 0x1FFF) AM_RAMBANK("bank2")
63   AM_RANGE(0x2000, 0x2FFF) AM_RAMBANK("bank3")
64   AM_RANGE(0x3000, 0x3FFF) AM_RAMBANK("bank4")
65   AM_RANGE(0x4000, 0x4FFF) AM_RAMBANK("bank5")
66   AM_RANGE(0x5000, 0x5FFF) AM_RAMBANK("bank6")
67   AM_RANGE(0x6000, 0x6FFF) AM_RAMBANK("bank7")
68   AM_RANGE(0x7000, 0x7FFF) AM_RAMBANK("bank8")
69   AM_RANGE(0x8000, 0x8FFF) AM_RAMBANK("bank9")
70   AM_RANGE(0x9000, 0x9FFF) AM_RAMBANK("bank10")
71   AM_RANGE(0xA000, 0xAFFF) AM_RAMBANK("bank11")
72   AM_RANGE(0xB000, 0xBFFF) AM_RAMBANK("bank12")
73   AM_RANGE(0xC000, 0xCFFF) AM_RAMBANK("bank13")
74   AM_RANGE(0xD000, 0xDFFF) AM_RAMBANK("bank14")
75   AM_RANGE(0xE000, 0xEFFF) AM_RAMBANK("bank15")
76   AM_RANGE(0xF000, 0xFEFF) AM_RAMBANK("bank16")
77   AM_RANGE(0xff00, 0xff1f) AM_DEVREADWRITE_MODERN("pia_0", pia6821_device, read, write)
78   AM_RANGE(0xff20, 0xff3f) AM_DEVREAD_MODERN("pia_1", pia6821_device, read) AM_DEVWRITE("pia_1", coco_pia_1_w)
79   AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE_MODERN("ext", cococart_slot_device, read, write)
80   AM_RANGE(0xff90, 0xffbf) AM_NOP
81   AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w)
82   AM_RANGE(0xffe0, 0xffef) AM_NOP
83   AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0x3ff0)
84ADDRESS_MAP_END
85
86
87static ADDRESS_MAP_START( dragon_map, AS_PROGRAM, 8 )
88   AM_RANGE(0x0000, 0x0FFF) AM_RAMBANK("bank1")
89   AM_RANGE(0x1000, 0x1FFF) AM_RAMBANK("bank2")
90   AM_RANGE(0x2000, 0x2FFF) AM_RAMBANK("bank3")
91   AM_RANGE(0x3000, 0x3FFF) AM_RAMBANK("bank4")
92   AM_RANGE(0x4000, 0x4FFF) AM_RAMBANK("bank5")
93   AM_RANGE(0x5000, 0x5FFF) AM_RAMBANK("bank6")
94   AM_RANGE(0x6000, 0x6FFF) AM_RAMBANK("bank7")
95   AM_RANGE(0x7000, 0x7FFF) AM_RAMBANK("bank8")
96   AM_RANGE(0x8000, 0x8FFF) AM_RAMBANK("bank9")
97   AM_RANGE(0x9000, 0x9FFF) AM_RAMBANK("bank10")
98   AM_RANGE(0xA000, 0xAFFF) AM_RAMBANK("bank11")
99   AM_RANGE(0xB000, 0xBFFF) AM_RAMBANK("bank12")
100   AM_RANGE(0xC000, 0xCFFF) AM_RAMBANK("bank13")
101   AM_RANGE(0xD000, 0xDFFF) AM_RAMBANK("bank14")
102   AM_RANGE(0xE000, 0xEFFF) AM_RAMBANK("bank15")
103   AM_RANGE(0xF000, 0xFEFF) AM_RAMBANK("bank16")
104   AM_RANGE(0xff00, 0xff1f) AM_DEVREADWRITE_MODERN("pia_0", pia6821_device, read, write)
105   AM_RANGE(0xff20, 0xff3f) AM_DEVREAD_MODERN("pia_1", pia6821_device, read) AM_DEVWRITE("pia_1", coco_pia_1_w)
106   AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE_MODERN("ext", cococart_slot_device, read, write)
107   AM_RANGE(0xff90, 0xffbf) AM_NOP
108   AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w)
109   AM_RANGE(0xffe0, 0xffef) AM_NOP
110   AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0x3ff0)
111ADDRESS_MAP_END
112
113
114/* Note that the CoCo 3 doesn't use the SAM VDG mode registers
115 *
116 * Also, there might be other SAM registers that are ignored in the CoCo 3;
117 * I am not sure which ones are...
118 *
119 * Tepolt implies that $FFD4-$FFD7 and $FFDA-$FFDD are ignored on the CoCo 3,
120 * which would make sense, but I'm not sure.
121 */
122static ADDRESS_MAP_START( coco3_map, AS_PROGRAM, 8 )
123   AM_RANGE(0x0000, 0x1fff) AM_RAMBANK("bank1")
124   AM_RANGE(0x2000, 0x3fff) AM_RAMBANK("bank2")
125   AM_RANGE(0x4000, 0x5fff) AM_RAMBANK("bank3")
126   AM_RANGE(0x6000, 0x7fff) AM_RAMBANK("bank4")
127   AM_RANGE(0x8000, 0x9fff) AM_RAMBANK("bank5")
128   AM_RANGE(0xa000, 0xbfff) AM_RAMBANK("bank6")
129   AM_RANGE(0xc000, 0xdfff) AM_RAMBANK("bank7")
130   AM_RANGE(0xe000, 0xfdff) AM_RAMBANK("bank8")
131   AM_RANGE(0xfe00, 0xfeff) AM_RAMBANK("bank9")
132   AM_RANGE(0xff00, 0xff1f) AM_DEVREADWRITE_MODERN("pia_0", pia6821_device, read, write)
133   AM_RANGE(0xff20, 0xff3f) AM_DEVREAD_MODERN("pia_1", pia6821_device, read) AM_DEVWRITE("pia_1", coco_pia_1_w)
134   AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE_MODERN("ext", cococart_slot_device, read, write)
135   AM_RANGE(0xff80, 0xff85) AM_DEVREADWRITE_MODERN("vhd", coco_vhd_image_device, read, write)
136   AM_RANGE(0xff90, 0xff9f) AM_READWRITE(coco3_gime_r, coco3_gime_w)
137   AM_RANGE(0xffa0, 0xffaf) AM_READWRITE(coco3_mmu_r, coco3_mmu_w)
138   AM_RANGE(0xffb0, 0xffbf) AM_READ_BANK("bank10") AM_WRITE(coco3_palette_w)
139   AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w)
140   AM_RANGE(0xffe0, 0xffef) AM_NOP
141   AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0x7ff0)
142ADDRESS_MAP_END
143
144
145
146static ADDRESS_MAP_START( d64_map, AS_PROGRAM, 8 )
147   AM_RANGE(0x0000, 0x0FFF) AM_RAMBANK("bank1")
148   AM_RANGE(0x1000, 0x1FFF) AM_RAMBANK("bank2")
149   AM_RANGE(0x2000, 0x2FFF) AM_RAMBANK("bank3")
150   AM_RANGE(0x3000, 0x3FFF) AM_RAMBANK("bank4")
151   AM_RANGE(0x4000, 0x4FFF) AM_RAMBANK("bank5")
152   AM_RANGE(0x5000, 0x5FFF) AM_RAMBANK("bank6")
153   AM_RANGE(0x6000, 0x6FFF) AM_RAMBANK("bank7")
154   AM_RANGE(0x7000, 0x7FFF) AM_RAMBANK("bank8")
155   AM_RANGE(0x8000, 0x8FFF) AM_RAMBANK("bank9")
156   AM_RANGE(0x9000, 0x9FFF) AM_RAMBANK("bank10")
157   AM_RANGE(0xA000, 0xAFFF) AM_RAMBANK("bank11")
158   AM_RANGE(0xB000, 0xBFFF) AM_RAMBANK("bank12")
159   AM_RANGE(0xC000, 0xCFFF) AM_RAMBANK("bank13")
160   AM_RANGE(0xD000, 0xDFFF) AM_RAMBANK("bank14")
161   AM_RANGE(0xE000, 0xEFFF) AM_RAMBANK("bank15")
162   AM_RANGE(0xF000, 0xFEFF) AM_RAMBANK("bank16")
163   AM_RANGE(0xff00, 0xff03) AM_DEVREADWRITE_MODERN("pia_0", pia6821_device, read, write) AM_MIRROR(0x0018)
164   AM_RANGE(0xff04, 0xff07) AM_DEVREADWRITE_MODERN("acia", acia6551_device, read, write)   AM_MIRROR(0x0018)
165   AM_RANGE(0xff20, 0xff3f) AM_DEVREAD_MODERN("pia_1", pia6821_device, read) AM_DEVWRITE("pia_1", coco_pia_1_w)
166   AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE_MODERN("ext", cococart_slot_device, read, write)
167   AM_RANGE(0xff90, 0xffbf) AM_NOP
168   AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w)
169   AM_RANGE(0xffe0, 0xffef) AM_NOP
170   AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0x3ff0)
171ADDRESS_MAP_END
172
173/*
174    Dragon 64 with compusense Plus addon, this provided an extra 64K of memory
175    and an 80x25 column text display, provided by a motorola 6845.
176
177    Currently only the memory is emulated.
178*/
179
180static ADDRESS_MAP_START( d64_plus_map, AS_PROGRAM, 8 )
181   AM_RANGE(0x0000, 0x0FFF) AM_RAMBANK("bank1")
182   AM_RANGE(0x1000, 0x1FFF) AM_RAMBANK("bank2")
183   AM_RANGE(0x2000, 0x2FFF) AM_RAMBANK("bank3")
184   AM_RANGE(0x3000, 0x3FFF) AM_RAMBANK("bank4")
185   AM_RANGE(0x4000, 0x4FFF) AM_RAMBANK("bank5")
186   AM_RANGE(0x5000, 0x5FFF) AM_RAMBANK("bank6")
187   AM_RANGE(0x6000, 0x6FFF) AM_RAMBANK("bank7")
188   AM_RANGE(0x7000, 0x7FFF) AM_RAMBANK("bank8")
189   AM_RANGE(0x8000, 0x8FFF) AM_RAMBANK("bank9")
190   AM_RANGE(0x9000, 0x9FFF) AM_RAMBANK("bank10")
191   AM_RANGE(0xA000, 0xAFFF) AM_RAMBANK("bank11")
192   AM_RANGE(0xB000, 0xBFFF) AM_RAMBANK("bank12")
193   AM_RANGE(0xC000, 0xCFFF) AM_RAMBANK("bank13")
194   AM_RANGE(0xD000, 0xDFFF) AM_RAMBANK("bank14")
195   AM_RANGE(0xE000, 0xEFFF) AM_RAMBANK("bank15")
196   AM_RANGE(0xF000, 0xFEFF) AM_RAMBANK("bank16")
197   AM_RANGE(0xff00, 0xff03) AM_DEVREADWRITE_MODERN("pia_0", pia6821_device, read, write) AM_MIRROR(0x0018)
198   AM_RANGE(0xff04, 0xff07) AM_DEVREADWRITE_MODERN("acia", acia6551_device, read, write)   AM_MIRROR(0x0018)
199   AM_RANGE(0xff20, 0xff3f) AM_DEVREAD_MODERN("pia_1", pia6821_device, read) AM_DEVWRITE("pia_1", coco_pia_1_w)
200   AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE_MODERN("ext", cococart_slot_device, read, write)
201   AM_RANGE(0xff90, 0xffbf) AM_NOP
202   AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w)
203   AM_RANGE(0xffe0, 0xffe1) AM_NOP
204   AM_RANGE(0xffe2, 0xffe2) AM_READWRITE(dgnplus_reg_r,dgnplus_reg_w)   /* Dragon plus control / status reg */
205   AM_RANGE(0xffe3, 0xffef) AM_NOP
206   AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0x3ff0)
207ADDRESS_MAP_END
208
209/*
210    The Dragon Alpha was a prototype in development when Dragon Data went bust,
211    it is basically an enhanced Dragon 64, with built in modem, disk system, and
212    graphical boot rom.
213
214    It has the following extra hardware :-
215    A third 6821 PIA mapped between FF24 and FF27
216        An AY-8912, connected to the PIA.
217
218    Port A of the PIA is connected as follows :-
219
220        b0  BDIR of AY8912
221        b1  BC1 of AY8912
222        b2  Rom select, High= boot rom, low=BASIC rom
223        b3..7 not used.
224
225    Port B
226        b0..7 connected to D0..7 of the AY8912.
227
228    CB1 DRQ of WD2797.
229
230    /irqa
231    /irqb   both connected to 6809 FIRQ.
232
233
234    The analog outputs of the AY-8912 are connected to the standard sound multiplexer.
235    The AY8912 output port is used as follows :-
236
237        b0..b3  /DS0../DS3 for the drive interface (through an inverter first).
238        b4      /motor for the drive interface (through an inverter first).
239        b5..b7  not used as far as I can tell.
240
241    A 6850 for the modem.
242
243    A WD2797, used as an internal disk interface, this is however connected in a slightly strange
244    way that I am yet to completely determine.
245    19/10/2004, WD2797 is mapped between FF2C and FF2F, however the order of the registers is
246    reversed so the command Register is at the highest address instead of the lowest. The Data
247    request pin is connected to CB1(pin 18) of PIA2, to cause an firq, the INTRQ, is connected via
248    an inverter to the 6809's NMI.
249
250    All these are as yet un-emulated.
251
252    29-Oct-2004, AY-8912 is now emulated.
253    30-Oct-2004, Internal disk interface now emulated, Normal DragonDos rom replaced with a re-assembled
254                version, that talks to the alpha hardware (verified on a clone of the real machine).
255*/
256
257
258static ADDRESS_MAP_START( dgnalpha_map, AS_PROGRAM, 8 )
259   AM_RANGE(0x0000, 0x0FFF) AM_RAMBANK("bank1")
260   AM_RANGE(0x1000, 0x1FFF) AM_RAMBANK("bank2")
261   AM_RANGE(0x2000, 0x2FFF) AM_RAMBANK("bank3")
262   AM_RANGE(0x3000, 0x3FFF) AM_RAMBANK("bank4")
263   AM_RANGE(0x4000, 0x4FFF) AM_RAMBANK("bank5")
264   AM_RANGE(0x5000, 0x5FFF) AM_RAMBANK("bank6")
265   AM_RANGE(0x6000, 0x6FFF) AM_RAMBANK("bank7")
266   AM_RANGE(0x7000, 0x7FFF) AM_RAMBANK("bank8")
267   AM_RANGE(0x8000, 0x8FFF) AM_RAMBANK("bank9")
268   AM_RANGE(0x9000, 0x9FFF) AM_RAMBANK("bank10")
269   AM_RANGE(0xA000, 0xAFFF) AM_RAMBANK("bank11")
270   AM_RANGE(0xB000, 0xBFFF) AM_RAMBANK("bank12")
271   AM_RANGE(0xC000, 0xCFFF) AM_RAMBANK("bank13")
272   AM_RANGE(0xD000, 0xDFFF) AM_RAMBANK("bank14")
273   AM_RANGE(0xE000, 0xEFFF) AM_RAMBANK("bank15")
274   AM_RANGE(0xF000, 0xFEFF) AM_RAMBANK("bank16")
275   AM_RANGE(0xff00, 0xff03) AM_DEVREADWRITE_MODERN("pia_0", pia6821_device, read, write)
276   AM_RANGE(0xff04, 0xff07) AM_DEVREADWRITE_MODERN("acia", acia6551_device, read, write)
277   AM_RANGE(0xff20, 0xff23) AM_DEVREAD_MODERN("pia_1", pia6821_device, read) AM_DEVWRITE("pia_1", coco_pia_1_w)
278   AM_RANGE(0xff24, 0xff27) AM_DEVREADWRITE_MODERN("pia_2", pia6821_device, read, write)       /* Third PIA on Dragon Alpha */
279   AM_RANGE(0Xff28, 0xff2b) AM_READWRITE(dgnalpha_modem_r, dgnalpha_modem_w)      /* Modem, dummy to stop eror log ! */
280   AM_RANGE(0xff2c, 0xff2f) AM_READWRITE(dgnalpha_wd2797_r, dgnalpha_wd2797_w)   /* Alpha onboard disk interface */
281   AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE_MODERN("ext", cococart_slot_device, read, write)
282   AM_RANGE(0xff90, 0xffbf) AM_NOP
283   AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w)
284   AM_RANGE(0xffe0, 0xffef) AM_NOP
285   AM_RANGE(0xfff0, 0xffff) AM_READ(dgnalpha_mapped_irq_r)
286ADDRESS_MAP_END
287
288
289static INPUT_PORTS_START( coco_joystick )
290   PORT_START("joystick_rx")
291   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_4_PAD) PORT_CODE_INC(KEYCODE_6_PAD) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
292   PORT_START("joystick_ry")
293   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_8_PAD) PORT_CODE_INC(KEYCODE_2_PAD) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH)   PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
294   PORT_START("joystick_lx")
295   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_4_PAD) PORT_CODE_INC(KEYCODE_6_PAD) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
296   PORT_START("joystick_ly")
297   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_8_PAD) PORT_CODE_INC(KEYCODE_2_PAD) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH)   PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
298   PORT_START("joystick_buttons")
299   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Right Button") PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
300   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Left Button")  PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
301INPUT_PORTS_END
302
303static INPUT_PORTS_START( coco3_joystick )
304   PORT_START("joystick_rx")
305   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_4_PAD) PORT_CODE_INC(KEYCODE_6_PAD) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
306   PORT_START("joystick_ry")
307   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_8_PAD) PORT_CODE_INC(KEYCODE_2_PAD) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH)   PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
308   PORT_START("joystick_lx")
309   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_4_PAD) PORT_CODE_INC(KEYCODE_6_PAD) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
310   PORT_START("joystick_ly")
311   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_8_PAD) PORT_CODE_INC(KEYCODE_2_PAD) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH)   PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
312   PORT_START("joystick_buttons")
313   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Right Button 1") PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
314   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Right Button 2") PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
315   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Left Button 1")  PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
316   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Left Button 2")  PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
317INPUT_PORTS_END
318
319static INPUT_PORTS_START( coco_rat_mouse )
320   PORT_START("rat_mouse_rx")
321   PORT_BIT( 0x03, 0x00,  IPT_MOUSE_X) PORT_NAME("Rat Mouse X (Right Port)") PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x02)
322   PORT_START("rat_mouse_ry")
323   PORT_BIT( 0x03, 0x00,  IPT_MOUSE_Y) PORT_NAME("Rat Mouse Y (Right Port)") PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x02)
324   PORT_START("rat_mouse_lx")
325   PORT_BIT( 0x03, 0x00,  IPT_MOUSE_X) PORT_NAME("Rat Mouse X (Left Port)") PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x20)
326   PORT_START("rat_mouse_ly")
327   PORT_BIT( 0x03, 0x00,  IPT_MOUSE_Y) PORT_NAME("Rat Mouse Y (Left Port)") PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH) PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x20)
328   PORT_START("rat_mouse_buttons")
329   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Rat Mouse Button 1 (Right Port)") PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x02)
330   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Rat Mouse Button 2 (Right Port)") PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x02)
331   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Rat Mouse Button 1 (Left Port)")  PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x20)
332   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Rat Mouse Button 2 (Left Port)")  PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x20)
333INPUT_PORTS_END
334
335static INPUT_PORTS_START( coco_lightgun )
336   PORT_START("dclg_rx")
337   PORT_BIT( 0x1ff, 266, IPT_LIGHTGUN_X ) PORT_NAME("Lightgun X (Right Port)") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_MINMAX(116,416) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x03)
338   PORT_START("dclg_ry")
339   PORT_BIT( 0xff, 121, IPT_LIGHTGUN_Y ) PORT_NAME("Lightgun Y (Right Port)") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_MINMAX(0,242) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x03)
340   PORT_START("dclg_lx")
341   PORT_BIT( 0x1ff, 266, IPT_LIGHTGUN_X ) PORT_NAME("Lightgun X (Left Port)") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_MINMAX(116,416) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x30)
342   PORT_START("dclg_ly")
343   PORT_BIT( 0xff, 121, IPT_LIGHTGUN_Y ) PORT_NAME("Lightgun Y (Left Port)") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_MINMAX(0,242) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x30)
344   PORT_START("dclg_triggers")
345   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Lightgun Trigger (Right Port)") PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(1) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x03)
346   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Lightgun Trigger (Left Port)")  PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(2) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x30)
347INPUT_PORTS_END
348
349
350static INPUT_PORTS_START( cart_autostart )
351   PORT_START("CARTAUTO")
352   PORT_CONFNAME( 0x01, 0x01, "Cart Auto-Start" )
353   PORT_CONFSETTING(    0x00, DEF_STR( Off ))
354   PORT_CONFSETTING(    0x01, DEF_STR( On ))
355INPUT_PORTS_END
356
357/* Dragon keyboard
358
359       PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7
360  PA6: Ent Clr Brk N/c N/c N/c N/c Shift
361  PA5: X   Y   Z   Up  Dwn Lft Rgt Space
362  PA4: P   Q   R   S   T   U   V   W
363  PA3: H   I   J   K   L   M   N   O
364  PA2: @   A   B   C   D   E   F   G
365  PA1: 8   9   :   ;   ,   -   .   /
366  PA0: 0   1   2   3   4   5   6   7
367 */
368static INPUT_PORTS_START( dragon32 )
369   PORT_START("row0")
370   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0) PORT_CHAR('0')
371   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')
372   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('\"')
373   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')
374   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')
375   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')
376   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')
377   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
378
379   PORT_START("row1")
380   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('(')
381   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR(')')
382   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_COLON) PORT_CHAR(':') PORT_CHAR('*')
383   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR(';') PORT_CHAR('+')
384   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<')
385   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('=')
386   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>')
387   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')
388
389   PORT_START("row2")
390   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_ASTERISK) PORT_CHAR('@')
391   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_A) PORT_CHAR('A')
392   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_B) PORT_CHAR('B')
393   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_C) PORT_CHAR('C')
394   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_D) PORT_CHAR('D')
395   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_E) PORT_CHAR('E')
396   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_F) PORT_CHAR('F')
397   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_G) PORT_CHAR('G')
398
399   PORT_START("row3")
400   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_H) PORT_CHAR('H')
401   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_I) PORT_CHAR('I')
402   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_J) PORT_CHAR('J')
403   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_K) PORT_CHAR('K')
404   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_L) PORT_CHAR('L')
405   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_M) PORT_CHAR('M')
406   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_N) PORT_CHAR('N')
407   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_O) PORT_CHAR('O')
408
409   PORT_START("row4")
410   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_P) PORT_CHAR('P')
411   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_Q) PORT_CHAR('Q')
412   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_R) PORT_CHAR('R')
413   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_S) PORT_CHAR('S')
414   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_T) PORT_CHAR('T')
415   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_U) PORT_CHAR('U')
416   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_V) PORT_CHAR('V')
417   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_W) PORT_CHAR('W')
418
419   PORT_START("row5")
420   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_X) PORT_CHAR('X')
421   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_Y) PORT_CHAR('Y')
422   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_Z) PORT_CHAR('Z')
423   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("UP") PORT_CODE(KEYCODE_UP) PORT_CHAR('^')
424   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("DOWN") PORT_CODE(KEYCODE_DOWN) PORT_CHAR(10)
425   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("LEFT") PORT_CODE(KEYCODE_LEFT) PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8)
426   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("RIGHT") PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(9)
427   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("SPACE") PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')
428
429   PORT_START("row6")
430   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("ENTER") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
431   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("CLEAR") PORT_CODE(KEYCODE_HOME) PORT_CHAR(12)
432   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("BREAK") PORT_CODE(KEYCODE_END) PORT_CODE(KEYCODE_ESC) PORT_CHAR(27)
433   PORT_BIT(0x78, IP_ACTIVE_LOW, IPT_UNUSED)
434   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("SHIFT") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
435
436   /* Other CoCo controllers were compatible with the Dragon, even if no software is known to make use of them */
437   /* We add them here, based on this compatibility, in case anyone wants to use them in homebrew software */
438   PORT_START("ctrl_sel")  /* Select Controller Type */
439   PORT_CONFNAME( 0x0f, 0x01, "Right Controller Port (P1)") PORT_CHANGED( coco_joystick_mode_changed, 0 )
440   PORT_CONFSETTING(  0x00, "Unconnected" )
441   PORT_CONFSETTING(  0x01, "Joystick" )
442   PORT_CONFSETTING(  0x02, "The Rat Graphics Mouse" ) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_NOTEQUALS, 0x20)
443   PORT_CONFSETTING(  0x03, "Diecom Light Gun Adaptor" ) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_NOTEQUALS, 0x30)
444   PORT_CONFNAME( 0xf0, 0x10, "Left Controller Port (P2)") PORT_CHANGED( coco_joystick_mode_changed, 0 )
445   PORT_CONFSETTING(  0x00, "Unconnected" )
446   PORT_CONFSETTING(  0x10, "Joystick" )
447   PORT_CONFSETTING(  0x20, "The Rat Graphics Mouse" ) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_NOTEQUALS, 0x02)
448   PORT_CONFSETTING(  0x30, "Diecom Light Gun Adaptor" ) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_NOTEQUALS, 0x03)
449
450   PORT_START("hires_intf")
451   PORT_CONFNAME( 0x07, 0x00, "Hi-Res Joystick Interfaces" )
452   PORT_CONFSETTING(    0x00, "None" )
453   PORT_CONFSETTING(    0x01, "Hi-Res in Right Port" )                     PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
454   PORT_CONFSETTING(    0x02, "Hi-Res CoCoMax 3 Style in Right Port" )     PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
455   PORT_CONFSETTING(    0x03, "Hi-Res in Left Port" )                      PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
456   PORT_CONFSETTING(    0x04, "Hi-Res CoCoMax 3 Style in Left Port" )      PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
457
458   PORT_INCLUDE( coco_joystick )
459   PORT_INCLUDE( coco_rat_mouse )
460   PORT_INCLUDE( coco_lightgun )
461
462   PORT_INCLUDE( coco6847_artifacting )
463
464   PORT_INCLUDE( cart_autostart )
465INPUT_PORTS_END
466
467/* CoCo keyboard
468
469       PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7
470  PA6: Ent Clr Brk N/c N/c N/c N/c Shift
471  PA5: 8   9   :   ;   ,   -   .   /
472  PA4: 0   1   2   3   4   5   6   7
473  PA3: X   Y   Z   Up  Dwn Lft Rgt Space
474  PA2: P   Q   R   S   T   U   V   W
475  PA1: H   I   J   K   L   M   N   O
476  PA0: @   A   B   C   D   E   F   G
477 */
478static INPUT_PORTS_START( coco )
479   PORT_START("row0")
480   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_ASTERISK) PORT_CHAR('@')
481   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_A) PORT_CHAR('A')
482   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_B) PORT_CHAR('B')
483   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_C) PORT_CHAR('C')
484   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_D) PORT_CHAR('D')
485   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_E) PORT_CHAR('E')
486   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_F) PORT_CHAR('F')
487   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_G) PORT_CHAR('G')
488
489   PORT_START("row1")
490   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_H) PORT_CHAR('H')
491   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_I) PORT_CHAR('I')
492   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_J) PORT_CHAR('J')
493   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_K) PORT_CHAR('K')
494   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_L) PORT_CHAR('L')
495   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_M) PORT_CHAR('M')
496   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_N) PORT_CHAR('N')
497   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_O) PORT_CHAR('O')
498
499   PORT_START("row2")
500   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_P) PORT_CHAR('P')
501   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_Q) PORT_CHAR('Q')
502   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_R) PORT_CHAR('R')
503   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_S) PORT_CHAR('S')
504   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_T) PORT_CHAR('T')
505   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_U) PORT_CHAR('U')
506   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_V) PORT_CHAR('V')
507   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_W) PORT_CHAR('W')
508
509   PORT_START("row3")
510   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_X) PORT_CHAR('X')
511   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_Y) PORT_CHAR('Y')
512   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_Z) PORT_CHAR('Z')
513   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("UP") PORT_CODE(KEYCODE_UP) PORT_CHAR('^')
514   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("DOWN") PORT_CODE(KEYCODE_DOWN) PORT_CHAR(10)
515   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("LEFT") PORT_CODE(KEYCODE_LEFT) PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8)
516   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("RIGHT") PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(9)
517   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("SPACE") PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')
518
519   PORT_START("row4")
520   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0) PORT_CHAR('0')
521   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')
522   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('\"')
523   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')
524   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')
525   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')
526   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')
527   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
528
529   PORT_START("row5")
530   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('(')
531   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR(')')
532   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_COLON) PORT_CHAR(':') PORT_CHAR('*')
533   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR(';') PORT_CHAR('+')
534   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<')
535   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('=')
536   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>')
537   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')
538
539   PORT_START("row6")
540   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("ENTER") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
541   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("CLEAR") PORT_CODE(KEYCODE_HOME) PORT_CHAR(12)
542   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("BREAK") PORT_CODE(KEYCODE_END) PORT_CODE(KEYCODE_ESC) PORT_CHAR(27)
543   PORT_BIT(0x78, IP_ACTIVE_LOW, IPT_UNUSED)
544   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("SHIFT") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
545
546   PORT_INCLUDE( coco6847_artifacting )
547
548   PORT_START("real_time_clock")
549   PORT_CONFNAME( 0x03, 0x00, "Real Time Clock" )
550   PORT_CONFSETTING(    0x00, "Disto" )
551   PORT_CONFSETTING(    0x01, "Cloud-9" )
552
553   /* Port Condition is used because you can plug Hi-Res joystick, Rat Mouse and Lightgun in either ports, but not both */
554   PORT_START("ctrl_sel")  /* Select Controller Type */
555   PORT_CONFNAME( 0x0f, 0x01, "Right Controller Port (P1)") PORT_CHANGED( coco_joystick_mode_changed, 0 )
556   PORT_CONFSETTING(  0x00, "Unconnected" )
557   PORT_CONFSETTING(  0x01, "Joystick" )
558   PORT_CONFSETTING(  0x02, "The Rat Graphics Mouse" ) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_NOTEQUALS, 0x20)
559   PORT_CONFSETTING(  0x03, "Diecom Light Gun Adaptor" ) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_NOTEQUALS, 0x30)
560   PORT_CONFNAME( 0xf0, 0x10, "Left Controller Port (P2)") PORT_CHANGED( coco_joystick_mode_changed, 0 )
561   PORT_CONFSETTING(  0x00, "Unconnected" )
562   PORT_CONFSETTING(  0x10, "Joystick" )
563   PORT_CONFSETTING(  0x20, "The Rat Graphics Mouse" ) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_NOTEQUALS, 0x02)
564   PORT_CONFSETTING(  0x30, "Diecom Light Gun Adaptor" ) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_NOTEQUALS, 0x03)
565
566   PORT_START("hires_intf")
567   PORT_CONFNAME( 0x07, 0x00, "Hi-Res Joystick Interfaces" )
568   PORT_CONFSETTING(    0x00, "None" )
569   PORT_CONFSETTING(    0x01, "Hi-Res in Right Port" )                     PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
570   PORT_CONFSETTING(    0x02, "Hi-Res CoCoMax 3 Style in Right Port" )     PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
571   PORT_CONFSETTING(    0x03, "Hi-Res in Left Port" )                      PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
572   PORT_CONFSETTING(    0x04, "Hi-Res CoCoMax 3 Style in Left Port" )      PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
573
574   PORT_INCLUDE( coco_joystick )
575   PORT_INCLUDE( coco_rat_mouse )
576   PORT_INCLUDE( coco_lightgun )
577
578   PORT_INCLUDE( cart_autostart )
579INPUT_PORTS_END
580
581/* CoCo 3 keyboard
582
583       PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7
584  PA6: Ent Clr Brk Alt Ctr F1  F2 Shift
585  PA5: 8   9   :   ;   ,   -   .   /
586  PA4: 0   1   2   3   4   5   6   7
587  PA3: X   Y   Z   Up  Dwn Lft Rgt Space
588  PA2: P   Q   R   S   T   U   V   W
589  PA1: H   I   J   K   L   M   N   O
590  PA0: @   A   B   C   D   E   F   G
591 */
592static INPUT_PORTS_START( coco3 )
593   PORT_START("row0")
594   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_ASTERISK) PORT_CHAR('@')
595   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_A) PORT_CHAR('A')
596   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_B) PORT_CHAR('B')
597   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_C) PORT_CHAR('C')
598   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_D) PORT_CHAR('D')
599   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_E) PORT_CHAR('E')
600   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_F) PORT_CHAR('F')
601   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_G) PORT_CHAR('G')
602
603   PORT_START("row1")
604   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_H) PORT_CHAR('H')
605   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_I) PORT_CHAR('I')
606   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_J) PORT_CHAR('J')
607   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_K) PORT_CHAR('K')
608   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_L) PORT_CHAR('L')
609   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_M) PORT_CHAR('M')
610   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_N) PORT_CHAR('N')
611   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_O) PORT_CHAR('O')
612
613   PORT_START("row2")
614   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_P) PORT_CHAR('P')
615   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_Q) PORT_CHAR('Q')
616   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_R) PORT_CHAR('R')
617   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_S) PORT_CHAR('S')
618   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_T) PORT_CHAR('T')
619   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_U) PORT_CHAR('U')
620   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_V) PORT_CHAR('V')
621   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_W) PORT_CHAR('W')
622
623   PORT_START("row3")
624   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_X) PORT_CHAR('X')
625   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_Y) PORT_CHAR('Y')
626   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_Z) PORT_CHAR('Z')
627   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("UP") PORT_CODE(KEYCODE_UP) PORT_CHAR('^')
628   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("DOWN") PORT_CODE(KEYCODE_DOWN) PORT_CHAR(10)
629   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("LEFT") PORT_CODE(KEYCODE_LEFT) PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8)
630   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("RIGHT") PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(9)
631   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("SPACE") PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')
632
633   PORT_START("row4")
634   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_0) PORT_CHAR('0')
635   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')
636   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('\"')
637   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')
638   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')
639   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')
640   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')
641   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
642
643   PORT_START("row5")
644   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('(')
645   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR(')')
646   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_COLON) PORT_CHAR(':') PORT_CHAR('*')
647   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR(';') PORT_CHAR('+')
648   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<')
649   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('=') PORT_CHAR('_')
650   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>')
651   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')
652
653   PORT_START("row6")
654   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("ENTER") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
655   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("CLEAR") PORT_CODE(KEYCODE_HOME) PORT_CHAR(12)
656   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("BREAK") PORT_CODE(KEYCODE_END) PORT_CODE(KEYCODE_ESC) PORT_CHAR(27)
657   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("ALT") PORT_CODE(KEYCODE_LALT)
658   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("CTRL") PORT_CODE(KEYCODE_LCONTROL) PORT_CHAR(UCHAR_SHIFT_2)
659   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1))
660   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F2))
661   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_keyboard_changed, NULL) PORT_NAME("SHIFT") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
662
663   PORT_INCLUDE( coco6847_artifacting )
664
665   PORT_START("real_time_clock")
666   PORT_CONFNAME( 0x03, 0x00, "Real Time Clock" )
667   PORT_CONFSETTING(    0x00, "Disto" )
668   PORT_CONFSETTING(    0x01, "Cloud-9" )
669
670   /* Port Condition is used because you can plug Hi-Res joystick, Rat Mouse and Lightgun in either ports, but not both */
671   PORT_START("ctrl_sel")  /* Select Controller Type */
672   PORT_CONFNAME( 0x0f, 0x01, "Right Controller Port (P1)") PORT_CHANGED( coco_joystick_mode_changed, 0 )
673   PORT_CONFSETTING(  0x00, "Unconnected" )
674   PORT_CONFSETTING(  0x01, "Joystick" )
675   PORT_CONFSETTING(  0x02, "The Rat Graphics Mouse" ) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_NOTEQUALS, 0x20)
676   PORT_CONFSETTING(  0x03, "Diecom Light Gun Adaptor" ) PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_NOTEQUALS, 0x30)
677   PORT_CONFNAME( 0xf0, 0x10, "Left Controller Port (P2)") PORT_CHANGED( coco_joystick_mode_changed, 0 )
678   PORT_CONFSETTING(  0x00, "Unconnected" )
679   PORT_CONFSETTING(  0x10, "Joystick" )
680   PORT_CONFSETTING(  0x20, "The Rat Graphics Mouse" ) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_NOTEQUALS, 0x02)
681   PORT_CONFSETTING(  0x30, "Diecom Light Gun Adaptor" ) PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_NOTEQUALS, 0x03)
682
683   PORT_START("hires_intf")
684   PORT_CONFNAME( 0x07, 0x00, "Hi-Res Joystick Interfaces" )
685   PORT_CONFSETTING(    0x00, "None" )
686   PORT_CONFSETTING(    0x01, "Hi-Res in Right Port" )                     PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
687   PORT_CONFSETTING(    0x02, "Hi-Res CoCoMax 3 Style in Right Port" )     PORT_CONDITION("ctrl_sel", 0x0f, PORTCOND_EQUALS, 0x01)
688   PORT_CONFSETTING(    0x03, "Hi-Res in Left Port" )                      PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
689   PORT_CONFSETTING(    0x04, "Hi-Res CoCoMax 3 Style in Left Port" )      PORT_CONDITION("ctrl_sel", 0xf0, PORTCOND_EQUALS, 0x10)
690
691   PORT_INCLUDE( coco3_joystick )
692   PORT_INCLUDE( coco_rat_mouse )
693   PORT_INCLUDE( coco_lightgun )
694
695   PORT_INCLUDE( cart_autostart )
696INPUT_PORTS_END
697
698/***************************************************************************
699  Bitbanger port
700***************************************************************************/
701
702static const bitbanger_config coco_bitbanger_config =
703{
704   coco_bitbanger_callback,
705   BITBANGER_PRINTER,   /* default mode */
706   BITBANGER_600,       /* default output baud */
707   BITBANGER_0PERCENT   /* default fine tune adjustment */
708};
709
710static const bitbanger_config coco3_bitbanger_config =
711{
712   coco3_bitbanger_callback,
713   BITBANGER_PRINTER,   /* default mode */
714   BITBANGER_600,       /* dafault output baud */
715   BITBANGER_0PERCENT   /* default fine tune adjustment */
716};
717
718
719
720/* ----------------------------------------------------------------------- */
721
722/* AY-8912 for Dragon Alpha, the AY-8912 simply an AY-8910 with only one io port. */
723static const ay8910_interface ay8912_interface =
724{
725   AY8910_LEGACY_OUTPUT,
726   AY8910_DEFAULT_LOADS,
727   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, dgnalpha_psg_porta_read),   /* portA read */
728   DEVCB_NULL,                /* portB read */
729   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, dgnalpha_psg_porta_write),   /* portA write */
730   DEVCB_NULL                  /* portB write */
731};
732
733
734static MACHINE_CONFIG_FRAGMENT( coco_sound )
735   MCFG_SPEAKER_STANDARD_MONO("mono")
736   MCFG_SOUND_ADD("dac", DAC, 0)
737   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
738   MCFG_SOUND_WAVE_ADD(WAVE_TAG, CASSETTE_TAG)
739   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
740MACHINE_CONFIG_END
741
742static const cassette_interface coco_cassette_interface =
743{
744   coco_cassette_formats,
745   NULL,
746   (cassette_state)(CASSETTE_PLAY | CASSETTE_MOTOR_DISABLED | CASSETTE_SPEAKER_MUTED),
747   NULL,
748   NULL
749};
750
751static const floppy_interface coco_floppy_interface =
752{
753   DEVCB_NULL,
754   DEVCB_NULL,
755   DEVCB_NULL,
756   DEVCB_NULL,
757   DEVCB_NULL,
758   FLOPPY_STANDARD_5_25_DSHD,
759   LEGACY_FLOPPY_OPTIONS_NAME(coco),
760   NULL,
761   NULL
762};
763
764static const cococart_interface coco_cococart_interface =
765{
766   DEVCB_LINE(coco_cart_w),
767   DEVCB_LINE(coco_nmi_w),
768   DEVCB_LINE(coco_halt_w)
769};
770
771static const cococart_interface coco3_cococart_interface =
772{
773   DEVCB_LINE(coco3_cart_w),
774   DEVCB_LINE(coco_nmi_w),
775   DEVCB_LINE(coco_halt_w)
776};
777
778static SLOT_INTERFACE_START(dragon_cart)
779   SLOT_INTERFACE("dragon_fdc", DRAGON_FDC)
780   SLOT_INTERFACE("sdtandy_fdc", SDTANDY_FDC)
781   SLOT_INTERFACE("pak", COCO_PAK)
782SLOT_INTERFACE_END
783
784static SLOT_INTERFACE_START(coco_cart)
785   SLOT_INTERFACE("fdc", COCO_FDC)
786   SLOT_INTERFACE("fdcv11", COCO_FDC_V11)
787   SLOT_INTERFACE("cp400_fdc", CP400_FDC)
788   SLOT_INTERFACE("rs232", COCO_232)
789   SLOT_INTERFACE("orch90", COCO_ORCH90)
790   SLOT_INTERFACE("banked_16k", COCO_PAK_BANKED)
791   SLOT_INTERFACE("pak", COCO_PAK)
792   SLOT_INTERFACE("multi", COCO_MULTIPAK)
793SLOT_INTERFACE_END
794
795static MACHINE_CONFIG_START( dragon32, coco_state )
796   /* basic machine hardware */
797   MCFG_CPU_ADD("maincpu", M6809E, COCO_CPU_SPEED_HZ * 4)        /* 0,894886 MHz */
798   MCFG_CPU_PROGRAM_MAP(dragon_map)
799
800   MCFG_MACHINE_START( dragon32 )
801
802   /* video hardware */
803   MCFG_SCREEN_ADD("screen", RASTER)
804   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
805   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
806   MCFG_SCREEN_SIZE(320, 25+192+26)
807   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
808   MCFG_SCREEN_UPDATE(m6847)
809
810   MCFG_VIDEO_START(dragon)
811
812   /* sound hardware */
813   MCFG_FRAGMENT_ADD( coco_sound )
814
815   /* printer */
816   MCFG_PRINTER_ADD("printer")
817
818   /* snapshot/quickload */
819   MCFG_SNAPSHOT_ADD("snapshot", coco_pak, "pak", 0)
820
821   MCFG_CASSETTE_ADD( CASSETTE_TAG, coco_cassette_interface )
822
823   MCFG_PIA6821_ADD( "pia_0", dragon32_pia_intf_0 )
824   MCFG_PIA6821_ADD( "pia_1", dragon32_pia_intf_1 )
825
826   MCFG_SAM6883_ADD("sam", coco_sam_intf)
827
828   MCFG_COCO_CARTRIDGE_ADD("ext", coco_cococart_interface, dragon_cart, "dragon_fdc", NULL)
829
830   /* internal ram */
831   MCFG_RAM_ADD(RAM_TAG)
832   MCFG_RAM_DEFAULT_SIZE("32K")
833   MCFG_RAM_EXTRA_OPTIONS("64K")
834
835   /* Software lists */
836   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
837MACHINE_CONFIG_END
838
839static MACHINE_CONFIG_START( dragon64, coco_state )
840   /* basic machine hardware */
841   MCFG_CPU_ADD("maincpu", M6809E, COCO_CPU_SPEED_HZ * 4)        /* 0,894886 MHz */
842   MCFG_CPU_PROGRAM_MAP(d64_map)
843
844   MCFG_MACHINE_START( dragon64 )
845
846   /* video hardware */
847   MCFG_VIDEO_START(dragon)
848   MCFG_SCREEN_ADD("screen", RASTER)
849   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
850   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
851   MCFG_SCREEN_SIZE(320, 25+192+26)
852   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
853   MCFG_SCREEN_UPDATE(m6847)
854
855   /* sound hardware */
856   MCFG_FRAGMENT_ADD( coco_sound )
857
858   /* printer */
859   MCFG_PRINTER_ADD("printer")
860
861   /* snapshot/quickload */
862   MCFG_SNAPSHOT_ADD("snapshot", coco_pak, "pak", 0)
863
864   /* cassette */
865   MCFG_CASSETTE_ADD( CASSETTE_TAG, coco_cassette_interface )
866
867   /* acia */
868   MCFG_ACIA6551_ADD("acia")
869
870   MCFG_PIA6821_ADD( "pia_0", dragon64_pia_intf_0 )
871   MCFG_PIA6821_ADD( "pia_1", dragon64_pia_intf_1 )
872
873   MCFG_SAM6883_ADD("sam", coco_sam_intf)
874
875   MCFG_COCO_CARTRIDGE_ADD("ext", coco_cococart_interface, dragon_cart, "dragon_fdc", NULL)
876
877   /* internal ram */
878   MCFG_RAM_ADD(RAM_TAG)
879   MCFG_RAM_DEFAULT_SIZE("64K")
880
881   /* Software lists */
882   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
883MACHINE_CONFIG_END
884
885static MACHINE_CONFIG_START( d64plus, coco_state )
886   /* basic machine hardware */
887   MCFG_CPU_ADD("maincpu", M6809E, COCO_CPU_SPEED_HZ * 4)        /* 0,894886 MHz */
888   MCFG_CPU_PROGRAM_MAP(d64_plus_map)
889
890   MCFG_MACHINE_START( dragon64 )
891
892   /* video hardware */
893   MCFG_SCREEN_ADD("screen", RASTER)
894   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
895   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
896   MCFG_SCREEN_SIZE(320, 25+192+26)
897   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
898   MCFG_SCREEN_UPDATE(m6847)
899
900   MCFG_VIDEO_START(dragon)
901
902   /* sound hardware */
903   MCFG_FRAGMENT_ADD( coco_sound )
904
905   /* printer */
906   MCFG_PRINTER_ADD("printer")
907
908   /* snapshot/quickload */
909   MCFG_SNAPSHOT_ADD("snapshot", coco_pak, "pak", 0)
910
911   /* cassette */
912   MCFG_CASSETTE_ADD( CASSETTE_TAG, coco_cassette_interface )
913
914   /* acia */
915   MCFG_ACIA6551_ADD("acia")
916
917   MCFG_PIA6821_ADD( "pia_0", dragon64_pia_intf_0 )
918   MCFG_PIA6821_ADD( "pia_1", dragon64_pia_intf_1 )
919
920   MCFG_SAM6883_ADD("sam", coco_sam_intf)
921
922   MCFG_COCO_CARTRIDGE_ADD("ext", coco_cococart_interface, dragon_cart, "dragon_fdc", NULL)
923
924   /* internal ram */
925   MCFG_RAM_ADD(RAM_TAG)
926   MCFG_RAM_DEFAULT_SIZE("128K")
927
928   /* Software lists */
929   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
930MACHINE_CONFIG_END
931
932static MACHINE_CONFIG_START( dgnalpha, coco_state )
933   /* basic machine hardware */
934   MCFG_CPU_ADD("maincpu", M6809E, COCO_CPU_SPEED_HZ * 4)        /* 0,894886 MHz */
935   MCFG_CPU_PROGRAM_MAP(dgnalpha_map)
936
937   MCFG_MACHINE_START( dgnalpha )
938    MCFG_MACHINE_RESET( dgnalpha )
939
940   /* video hardware */
941   MCFG_SCREEN_ADD("screen", RASTER)
942   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
943   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
944   MCFG_SCREEN_SIZE(320, 25+192+26)
945   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
946   MCFG_SCREEN_UPDATE(m6847)
947
948   MCFG_VIDEO_START(dragon)
949
950   /* sound hardware */
951   MCFG_FRAGMENT_ADD( coco_sound )
952   MCFG_SOUND_ADD("ay8912", AY8912, 1000000)
953   MCFG_SOUND_CONFIG(ay8912_interface)
954   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.75)
955
956   /* onboard fdc */
957   MCFG_WD2797_ADD("wd2797", dgnalpha_wd17xx_interface)
958
959   /* printer */
960   MCFG_PRINTER_ADD("printer")
961
962   /* snapshot/quickload */
963   MCFG_SNAPSHOT_ADD("snapshot", coco_pak, "pak", 0)
964
965   /* cassette */
966   MCFG_CASSETTE_ADD( CASSETTE_TAG, coco_cassette_interface )
967
968   /* acia */
969   MCFG_ACIA6551_ADD("acia")
970
971   MCFG_PIA6821_ADD( "pia_0", dgnalpha_pia_intf_0 )
972   MCFG_PIA6821_ADD( "pia_1", dgnalpha_pia_intf_1 )
973   MCFG_PIA6821_ADD( "pia_2", dgnalpha_pia_intf_2 )
974
975   MCFG_SAM6883_ADD("sam", coco_sam_intf)
976
977   MCFG_COCO_CARTRIDGE_ADD("ext", coco_cococart_interface, dragon_cart, NULL, NULL)
978
979   MCFG_LEGACY_FLOPPY_4_DRIVES_ADD(coco_floppy_interface)
980
981   /* internal ram */
982   MCFG_RAM_ADD(RAM_TAG)
983   MCFG_RAM_DEFAULT_SIZE("64K")
984
985   /* Software lists */
986   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
987MACHINE_CONFIG_END
988
989static MACHINE_CONFIG_START( tanodr64, coco_state )
990   /* basic machine hardware */
991   MCFG_CPU_ADD("maincpu", M6809E, COCO_CPU_SPEED_HZ * 4)        /* 0,894886 MHz */
992   MCFG_CPU_PROGRAM_MAP(d64_map)
993
994   MCFG_MACHINE_START( tanodr64 )
995
996   /* video hardware */
997   MCFG_SCREEN_ADD("screen", RASTER)
998   MCFG_SCREEN_REFRESH_RATE(COCO_FRAMES_PER_SECOND)         /* Tano Dragon 64 is NTSC */
999   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
1000   MCFG_SCREEN_SIZE(320, 25+192+26)
1001   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
1002   MCFG_SCREEN_UPDATE(m6847)
1003
1004   MCFG_VIDEO_START(dragon)
1005
1006   /* sound hardware */
1007   MCFG_FRAGMENT_ADD( coco_sound )
1008
1009   /* printer */
1010   MCFG_PRINTER_ADD("printer")
1011
1012   /* snapshot/quickload */
1013   MCFG_SNAPSHOT_ADD("snapshot", coco_pak, "pak", 0)
1014
1015   /* cassette */
1016   MCFG_CASSETTE_ADD( CASSETTE_TAG, coco_cassette_interface )
1017
1018   /* acia */
1019   MCFG_ACIA6551_ADD("acia")
1020
1021   MCFG_PIA6821_ADD( "pia_0", dragon64_pia_intf_0 )
1022   MCFG_PIA6821_ADD( "pia_1", dragon64_pia_intf_1 )
1023
1024   MCFG_SAM6883_ADD("sam", coco_sam_intf)
1025
1026   MCFG_COCO_CARTRIDGE_ADD("ext", coco_cococart_interface, dragon_cart, "sdtandy_fdc", NULL)
1027
1028   /* internal ram */
1029   MCFG_RAM_ADD(RAM_TAG)
1030   MCFG_RAM_DEFAULT_SIZE("64K")
1031
1032   /* Software lists */
1033   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
1034MACHINE_CONFIG_END
1035
1036static MACHINE_CONFIG_START( coco, coco_state )
1037   /* basic machine hardware */
1038   MCFG_CPU_ADD("maincpu", M6809E, COCO_CPU_SPEED_HZ * 4)        /* 0,894886 MHz */
1039   MCFG_CPU_PROGRAM_MAP(coco_map)
1040
1041   MCFG_MACHINE_START( coco )
1042
1043   /* video hardware */
1044   MCFG_SCREEN_ADD("screen", RASTER)
1045   MCFG_SCREEN_REFRESH_RATE(M6847_NTSC_FRAMES_PER_SECOND)
1046   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
1047   MCFG_SCREEN_SIZE(320, 25+192+26)
1048   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
1049   MCFG_SCREEN_UPDATE(m6847)
1050
1051   MCFG_VIDEO_START(coco)
1052
1053   /* sound hardware */
1054   MCFG_FRAGMENT_ADD( coco_sound )
1055
1056   /* bitbanger/printer */
1057   MCFG_BITBANGER_ADD("bitbanger", coco_bitbanger_config)
1058
1059   /* snapshot/quickload */
1060   MCFG_SNAPSHOT_ADD("snapshot", coco_pak, "pak", 0)
1061   MCFG_QUICKLOAD_ADD("quickload", coco, "bin", 0.5)
1062
1063   /* cassette */
1064   MCFG_CASSETTE_ADD( CASSETTE_TAG, coco_cassette_interface )
1065
1066   MCFG_PIA6821_ADD( "pia_0", coco_pia_intf_0 )
1067   MCFG_PIA6821_ADD( "pia_1", coco_pia_intf_1 )
1068
1069   MCFG_SAM6883_ADD("sam", coco_sam_intf)
1070
1071   MCFG_COCO_CARTRIDGE_ADD("ext", coco_cococart_interface, coco_cart, "pak", NULL)
1072
1073   /* internal ram */
1074   MCFG_RAM_ADD(RAM_TAG)
1075   MCFG_RAM_DEFAULT_SIZE("16K")
1076   MCFG_RAM_EXTRA_OPTIONS("4K,32K,64K")
1077
1078   /* Software lists */
1079   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
1080MACHINE_CONFIG_END
1081
1082static MACHINE_CONFIG_START( coco2, coco_state )
1083   /* basic machine hardware */
1084   MCFG_CPU_ADD("maincpu", M6809E, COCO_CPU_SPEED_HZ * 4)        /* 0,894886 MHz */
1085   MCFG_CPU_PROGRAM_MAP(coco_map)
1086
1087   MCFG_MACHINE_START( coco2 )
1088
1089   /* video hardware */
1090   MCFG_SCREEN_ADD("screen", RASTER)
1091   MCFG_SCREEN_REFRESH_RATE(M6847_NTSC_FRAMES_PER_SECOND)
1092   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
1093   MCFG_SCREEN_SIZE(320, 25+192+26)
1094   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
1095   MCFG_SCREEN_UPDATE(m6847)
1096
1097   MCFG_VIDEO_START(coco)
1098
1099   /* sound hardware */
1100   MCFG_FRAGMENT_ADD( coco_sound )
1101
1102   /* bitbanger/printer */
1103   MCFG_BITBANGER_ADD("bitbanger", coco_bitbanger_config)
1104
1105   /* snapshot/quickload */
1106   MCFG_SNAPSHOT_ADD("snapshot", coco_pak, "pak", 0)
1107   MCFG_QUICKLOAD_ADD("quickload", coco, "bin", 0.5)
1108
1109   /* cassette */
1110   MCFG_CASSETTE_ADD( CASSETTE_TAG, coco_cassette_interface )
1111
1112   MCFG_PIA6821_ADD( "pia_0", coco2_pia_intf_0 )
1113   MCFG_PIA6821_ADD( "pia_1", coco2_pia_intf_1 )
1114
1115   MCFG_SAM6883_ADD("sam", coco_sam_intf)
1116
1117   MCFG_COCO_CARTRIDGE_ADD("ext", coco_cococart_interface, coco_cart, "fdcv11", NULL)
1118
1119   /* internal ram */
1120   MCFG_RAM_ADD(RAM_TAG)
1121   MCFG_RAM_DEFAULT_SIZE("64K")
1122   MCFG_RAM_EXTRA_OPTIONS("16K")
1123
1124   /* Software lists */
1125   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
1126MACHINE_CONFIG_END
1127
1128static MACHINE_CONFIG_START( coco2b, coco_state )
1129   /* basic machine hardware */
1130   MCFG_CPU_ADD("maincpu", M6809E, COCO_CPU_SPEED_HZ * 4)        /* 0,894886 MHz */
1131   MCFG_CPU_PROGRAM_MAP(coco_map)
1132
1133   MCFG_MACHINE_START( coco2 )
1134
1135   /* video hardware */
1136   MCFG_SCREEN_ADD("screen", RASTER)
1137   MCFG_SCREEN_REFRESH_RATE(M6847_NTSC_FRAMES_PER_SECOND)
1138   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
1139   MCFG_SCREEN_SIZE(320, 25+192+26)
1140   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
1141   MCFG_SCREEN_UPDATE(m6847)
1142
1143   MCFG_VIDEO_START(coco2b)
1144
1145   /* sound hardware */
1146   MCFG_FRAGMENT_ADD( coco_sound )
1147
1148   /* bitbanger/printer */
1149   MCFG_BITBANGER_ADD("bitbanger", coco_bitbanger_config)
1150
1151   /* snapshot/quickload */
1152   MCFG_SNAPSHOT_ADD("snapshot", coco_pak, "pak", 0)
1153   MCFG_QUICKLOAD_ADD("quickload", coco, "bin", 0.5)
1154
1155   /* cassette */
1156   MCFG_CASSETTE_ADD( CASSETTE_TAG, coco_cassette_interface )
1157
1158   MCFG_PIA6821_ADD( "pia_0", coco2_pia_intf_0 )
1159   MCFG_PIA6821_ADD( "pia_1", coco2_pia_intf_1 )
1160
1161   MCFG_SAM6883_ADD("sam", coco_sam_intf)
1162
1163   MCFG_COCO_CARTRIDGE_ADD("ext", coco_cococart_interface, coco_cart, "fdcv11", NULL)
1164
1165   /* internal ram */
1166   MCFG_RAM_ADD(RAM_TAG)
1167   MCFG_RAM_DEFAULT_SIZE("64K")
1168   MCFG_RAM_EXTRA_OPTIONS("16K")
1169
1170   /* Software lists */
1171   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
1172MACHINE_CONFIG_END
1173
1174static MACHINE_CONFIG_START( coco3, coco3_state )
1175   /* basic machine hardware */
1176   MCFG_CPU_ADD("maincpu", M6809E, COCO_CPU_SPEED_HZ * 4)        /* 0,894886 MHz */
1177   MCFG_CPU_PROGRAM_MAP(coco3_map)
1178
1179   MCFG_MACHINE_START( coco3 )
1180   MCFG_MACHINE_RESET( coco3 )
1181
1182   /* video hardware */
1183   MCFG_VIDEO_START(coco3)
1184   MCFG_DEFAULT_LAYOUT(layout_coco3)
1185
1186   MCFG_SCREEN_ADD("composite", RASTER)
1187   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
1188   MCFG_SCREEN_REFRESH_RATE(M6847_NTSC_FRAMES_PER_SECOND)
1189   MCFG_SCREEN_SIZE(640, 25+192+26)
1190   MCFG_SCREEN_VISIBLE_AREA(0, 639, 0, 239)
1191   MCFG_SCREEN_UPDATE(coco3)
1192
1193   MCFG_SCREEN_ADD("rgb", RASTER)
1194   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
1195   MCFG_SCREEN_REFRESH_RATE(M6847_NTSC_FRAMES_PER_SECOND)
1196   MCFG_SCREEN_SIZE(640, 25+192+26)
1197   MCFG_SCREEN_VISIBLE_AREA(0, 639, 0, 239)
1198   MCFG_SCREEN_UPDATE(coco3)
1199
1200   MCFG_PIA6821_ADD( "pia_0", coco3_pia_intf_0 )
1201   MCFG_PIA6821_ADD( "pia_1", coco3_pia_intf_1 )
1202
1203   /* sound hardware */
1204   MCFG_FRAGMENT_ADD( coco_sound )
1205
1206   /* bitbanger/printer */
1207   MCFG_BITBANGER_ADD("bitbanger", coco3_bitbanger_config)
1208
1209   /* snapshot/quickload */
1210   MCFG_SNAPSHOT_ADD("snapshot", coco3_pak, "pak", 0)
1211   MCFG_QUICKLOAD_ADD("quickload", coco, "bin", 0.5)
1212
1213   /* devices */
1214   MCFG_COCO_VHD_ADD("vhd")
1215
1216   /* cassette */
1217   MCFG_CASSETTE_ADD( CASSETTE_TAG, coco_cassette_interface )
1218
1219   MCFG_SAM6883_GIME_ADD("sam", coco3_sam_intf)
1220
1221   MCFG_COCO_CARTRIDGE_ADD("ext", coco3_cococart_interface, coco_cart, "fdcv11", NULL)
1222
1223   /* internal ram */
1224   MCFG_RAM_ADD(RAM_TAG)
1225   MCFG_RAM_DEFAULT_SIZE("512K")
1226   MCFG_RAM_EXTRA_OPTIONS("128K,2M,8M")
1227
1228   /* Software lists */
1229   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
1230MACHINE_CONFIG_END
1231
1232static MACHINE_CONFIG_DERIVED( coco3p, coco3 )
1233
1234   /* video hardware */
1235   MCFG_VIDEO_START(coco3p)
1236   MCFG_SCREEN_MODIFY("composite")
1237   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
1238   MCFG_SCREEN_UPDATE(coco3)
1239   MCFG_SCREEN_MODIFY("rgb")
1240   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
1241   MCFG_SCREEN_UPDATE(coco3)
1242MACHINE_CONFIG_END
1243
1244static MACHINE_CONFIG_DERIVED( coco3h, coco3 )
1245   MCFG_CPU_REPLACE( "maincpu", HD6309, COCO_CPU_SPEED_HZ * 4)
1246   MCFG_CPU_PROGRAM_MAP(coco3_map)
1247MACHINE_CONFIG_END
1248
1249static MACHINE_CONFIG_DERIVED( cocoe, coco )
1250   MCFG_COCO_CARTRIDGE_REMOVE("ext")
1251   MCFG_COCO_CARTRIDGE_ADD("ext", coco_cococart_interface, coco_cart, "fdc", NULL)
1252   /* internal ram */
1253   MCFG_RAM_MODIFY(RAM_TAG)
1254   MCFG_RAM_DEFAULT_SIZE("64K")
1255   MCFG_RAM_EXTRA_OPTIONS("4K,16K,32K")
1256MACHINE_CONFIG_END
1257
1258static MACHINE_CONFIG_DERIVED( cp400, coco )
1259   MCFG_COCO_CARTRIDGE_REMOVE("ext")
1260   MCFG_COCO_CARTRIDGE_ADD("ext", coco_cococart_interface, coco_cart, "cp400_fdc", NULL)
1261MACHINE_CONFIG_END
1262
1263/***************************************************************************
1264
1265  Game driver(s)
1266
1267***************************************************************************/
1268
1269ROM_START(dragon32)
1270   ROM_REGION(0xC000, "maincpu",0)
1271   ROM_LOAD("d32.rom",      0x0000,  0x4000, CRC(e3879310) SHA1(f2dab125673e653995a83bf6b793e3390ec7f65a))
1272ROM_END
1273
1274ROM_START(dragon64)
1275   ROM_REGION(0x10000,"maincpu",0)
1276   ROM_LOAD("d64_1.rom",    0x0000,  0x4000, CRC(60a4634c) SHA1(f119506eaa3b4b70b9aa0dd83761e8cbe043d042))
1277   ROM_LOAD("d64_2.rom",    0x8000,  0x4000, CRC(17893a42) SHA1(e3c8986bb1d44269c4587b04f1ca27a70b0aaa2e))
1278ROM_END
1279
1280ROM_START(d64plus)
1281   ROM_REGION(0x10000,"maincpu",0)
1282   ROM_LOAD("d64_1.rom",    0x0000,  0x4000, CRC(60a4634c) SHA1(f119506eaa3b4b70b9aa0dd83761e8cbe043d042))
1283   ROM_LOAD("d64_2.rom",    0x8000,  0x4000, CRC(17893a42) SHA1(e3c8986bb1d44269c4587b04f1ca27a70b0aaa2e))
1284ROM_END
1285
1286ROM_START(tanodr64)
1287   ROM_REGION(0x10000,"maincpu",0)
1288   ROM_LOAD("d64_1.rom",    0x0000,  0x4000, CRC(60a4634c) SHA1(f119506eaa3b4b70b9aa0dd83761e8cbe043d042))
1289   ROM_LOAD("d64_2.rom",    0x8000,  0x4000, CRC(17893a42) SHA1(e3c8986bb1d44269c4587b04f1ca27a70b0aaa2e))
1290ROM_END
1291
1292ROM_START(dgnalpha)
1293   ROM_REGION(0xC000,"maincpu",1)
1294   ROM_LOAD("alpha_bt.rom",    0x2000,  0x2000, CRC(c3dab585) SHA1(4a5851aa66eb426e9bb0bba196f1e02d48156068))
1295   ROM_LOAD("alpha_ba.rom",    0x8000,  0x4000, CRC(84f68bf9) SHA1(1983b4fb398e3dd9668d424c666c5a0b3f1e2b69))
1296ROM_END
1297
1298ROM_START(coco)
1299   ROM_REGION(0x8000,"maincpu",0)
1300   ROM_LOAD("bas10.rom",   0x2000, 0x2000, CRC(00b50aaa) SHA1(1f08455cd48ce6a06132aea15c4778f264e19539))
1301ROM_END
1302
1303ROM_START(cocoe)
1304   ROM_REGION(0x8000,"maincpu",0)
1305   ROM_LOAD("bas11.rom",   0x2000, 0x2000, CRC(6270955a) SHA1(cecb7c24ff1e0ab5836e4a7a8eb1b8e01f1fded3))
1306   ROM_LOAD("extbas10.rom",   0x0000, 0x2000, CRC(6111a086) SHA1(8aa58f2eb3e8bcfd5470e3e35e2b359e9a72848e))
1307ROM_END
1308
1309ROM_START(coco2)
1310   ROM_REGION(0x8000,"maincpu",0)
1311   ROM_LOAD("bas12.rom",   0x2000, 0x2000, CRC(54368805) SHA1(0f14dc46c647510eb0b7bd3f53e33da07907d04f))
1312   ROM_LOAD("extbas11.rom",   0x0000, 0x2000, CRC(a82a6254) SHA1(ad927fb4f30746d820cb8b860ebb585e7f095dea))
1313ROM_END
1314
1315ROM_START(coco2b)
1316   ROM_REGION(0x8000,"maincpu",0)
1317   ROM_LOAD("bas13.rom",   0x2000, 0x2000, CRC(d8f4d15e) SHA1(28b92bebe35fa4f026a084416d6ea3b1552b63d3))
1318   ROM_LOAD("extbas11.rom",   0x0000, 0x2000, CRC(a82a6254) SHA1(ad927fb4f30746d820cb8b860ebb585e7f095dea))
1319ROM_END
1320
1321ROM_START(coco3)
1322   ROM_REGION(0x8000,"maincpu",0)
1323   ROM_LOAD("coco3.rom",   0x0000, 0x8000, CRC(b4c88d6c) SHA1(e0d82953fb6fd03768604933df1ce8bc51fc427d))
1324ROM_END
1325
1326ROM_START(coco3p)
1327   ROM_REGION(0x8000,"maincpu",0)
1328   ROM_LOAD("coco3p.rom",   0x0000, 0x8000, CRC(ff050d80) SHA1(631e383068b1f52a8f419f4114b69501b21cf379))
1329ROM_END
1330
1331ROM_START(cp400)
1332   ROM_REGION(0x8000,"maincpu",0)
1333   ROM_LOAD("cp400bas.rom",  0x0000, 0x4000, CRC(878396a5) SHA1(292c545da3c77978e043b00a3dbc317201d18c3b))
1334ROM_END
1335
1336#define rom_coco3h   rom_coco3
1337
1338/* I have split up coco and cocoe, as the basic rom in the coco, cannot    */
1339/* use 64K rams, and will boot with 4k, if this is selected, so I have     */
1340/* split these to avoid confusion -- PHS                                   */
1341
1342/*     YEAR     NAME        PARENT  COMPAT  MACHINE    INPUT      INIT    COMPANY                 FULLNAME */
1343COMP(  1980,    coco,       0,      0,      coco,      coco,      0,      "Tandy Radio Shack",            "Color Computer", 0)
1344COMP(  1981,    cocoe,      coco,   0,      cocoe,     coco,      0,      "Tandy Radio Shack",            "Color Computer (Extended BASIC 1.0)", 0)
1345COMP(  1983,    coco2,      coco,   0,      coco2,     coco,      0,      "Tandy Radio Shack",            "Color Computer 2", 0)
1346COMP(  1985?,   coco2b,     coco,   0,      coco2b,    coco,      0,      "Tandy Radio Shack",            "Color Computer 2B", 0)
1347COMP(  1986,    coco3,      coco,   0,      coco3,     coco3,     0,      "Tandy Radio Shack",            "Color Computer 3 (NTSC)", 0)
1348COMP(  1986,    coco3p,     coco,   0,      coco3p,    coco3,     0,      "Tandy Radio Shack",            "Color Computer 3 (PAL)", 0)
1349COMP(  19??,    coco3h,     coco,   0,      coco3h,    coco3,     0,      "Tandy Radio Shack",            "Color Computer 3 (NTSC; HD6309)", GAME_UNOFFICIAL)
1350COMP(  1982,    dragon32,   coco,   0,      dragon32,  dragon32,  0,      "Dragon Data Ltd",            "Dragon 32", 0)
1351COMP(  1983,    dragon64,   coco,   0,      dragon64,  dragon32,  0,      "Dragon Data Ltd",            "Dragon 64", 0)
1352COMP(  1983,    d64plus,    coco,   0,      d64plus,   dragon32,  0,      "Dragon Data Ltd",            "Dragon 64 Plus", 0)
1353COMP(  1983,    tanodr64,   coco,   0,      tanodr64,  dragon32,  0,      "Dragon Data Ltd / Tano Ltd", "Tano Dragon 64 (NTSC)", 0)
1354COMP(  1984,    dgnalpha,   coco,   0,      dgnalpha,  dragon32,  0,      "Dragon Data Ltd",            "Dragon Alpha Prototype", 0)
1355COMP(  1984,    cp400,      coco,   0,      cp400,     coco,      0,      "Prologica",                  "CP400", 0)
src/mess/drivers/mc1000.c
r13256r13257
108108    */
109109
110110   m_mc6847_bank = BIT(data, 0);
111   mc6847_css_w(m_vdg, BIT(data, 1));
112   mc6847_gm0_w(m_vdg, BIT(data, 2));
113   mc6847_gm1_w(m_vdg, BIT(data, 3));
114   mc6847_gm2_w(m_vdg, BIT(data, 4));
115   mc6847_intext_w(m_vdg, BIT(data, 5));
116   mc6847_as_w(m_vdg, BIT(data, 6));
117   mc6847_ag_w(m_vdg, BIT(data, 7));
111   m_vdg->css_w(BIT(data, 1));
112   m_vdg->gm0_w(BIT(data, 2));
113   m_vdg->gm1_w(BIT(data, 3));
114   m_vdg->gm2_w(BIT(data, 4));
115   m_vdg->intext_w(BIT(data, 5));
116   m_vdg->as_w(BIT(data, 6));
117   m_vdg->ag_w(BIT(data, 7));
118118
119119   bankswitch();
120120}
r13256r13257
249249   PORT_CONFNAME( 0x01, 0x00, "JOYSTICK B (P2) keyboard mapping" )
250250   PORT_CONFSETTING( 0x00, DEF_STR( Off ) )
251251   PORT_CONFSETTING( 0x01, DEF_STR( On ) )
252
253   PORT_INCLUDE( m6847_artifacting )
254252INPUT_PORTS_END
255253
256254/* Video */
r13256r13257
267265
268266READ8_MEMBER( mc1000_state::videoram_r )
269267{
270   mc6847_inv_w(m_vdg, BIT(m_mc6847_video_ram[offset], 7));
268   m_vdg->inv_w(BIT(m_mc6847_video_ram[offset], 7));
271269
272270   return m_mc6847_video_ram[offset];
273271}
274272
275273bool mc1000_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
276274{
277   return mc6847_update(m_vdg, &bitmap, &cliprect);
275   return m_vdg->update(&bitmap, &cliprect);
278276}
279277
280static UINT8 mc1000_get_char_rom(running_machine &machine, UINT8 ch, int line)
281{
282   return ch;
283}
284
285278/* AY-3-8910 Interface */
286279
287280WRITE8_MEMBER( mc1000_state::keylatch_w )
r13256r13257
440433
441434static const mc6847_interface mc1000_mc6847_intf =
442435{
436   SCREEN_TAG,
443437   DEVCB_DRIVER_MEMBER(mc1000_state, videoram_r),
444   DEVCB_NULL,
445   DEVCB_NULL,
446   DEVCB_NULL,
447   DEVCB_NULL,
448   DEVCB_NULL,
449   DEVCB_NULL,
450   DEVCB_NULL,
451   DEVCB_NULL,
452   DEVCB_DRIVER_LINE_MEMBER(mc1000_state, fs_w),
453438   DEVCB_DRIVER_LINE_MEMBER(mc1000_state, hs_w),
454   DEVCB_NULL
439   DEVCB_DRIVER_LINE_MEMBER(mc1000_state, fs_w),
455440};
456441
457442static MACHINE_CONFIG_START( mc1000, mc1000_state )
r13256r13257
470455   MCFG_TIMER_PARAM(ASSERT_LINE)
471456
472457   /* video hardware */
473   MCFG_SCREEN_ADD(SCREEN_TAG, RASTER)
474   MCFG_SCREEN_REFRESH_RATE(M6847_NTSC_FRAMES_PER_SECOND)
475   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
476   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
477   MCFG_SCREEN_SIZE(320, 25+192+26)
478   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
458    MCFG_SCREEN_MC6847_PAL_ADD(SCREEN_TAG)
459   MCFG_MC6847_ADD(MC6847_TAG, MC6847_NTSC, XTAL_3_579545MHz, mc1000_mc6847_intf)
479460
480   MCFG_PALETTE_LENGTH(16)
481
482   MCFG_MC6847_ADD(MC6847_TAG, mc1000_mc6847_intf)
483   MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_NTSC)
484   MCFG_MC6847_CHAR_ROM(mc1000_get_char_rom)
485
486461   /* sound hardware */
487462   MCFG_SPEAKER_STANDARD_MONO("mono")
488463   MCFG_SOUND_ADD(AY8910_TAG, AY8910, 3579545/2)
src/mess/drivers/pc6001.c
r13256r13257
125125#include "cpu/z80/z80.h"
126126#include "machine/i8255.h"
127127#include "machine/i8251.h"
128#include "video/m6847.h"
128#include "video/mc6847.h"
129129#include "sound/ay8910.h"
130130#include "sound/wave.h"
131131
src/mess/drivers/spc1000.c
r13256r13257
99
1010#include "emu.h"
1111#include "cpu/z80/z80.h"
12#include "video/m6847.h"
12#include "video/mc6847.h"
1313#include "sound/ay8910.h"
1414#include "sound/wave.h"
1515#include "imagedev/cassette.h"
r13256r13257
2020{
2121public:
2222   spc1000_state(const machine_config &mconfig, device_type type, const char *tag)
23      : driver_device(mconfig, type, tag) { }
23      : driver_device(mconfig, type, tag),
24        m_vdg(*this, "mc6847") {}
2425
26   required_device<mc6847_base_device> m_vdg;
2527   UINT8 m_IPLK;
26   UINT8 *m_video_ram;
2728   UINT8 m_GMODE;
29   UINT8 m_video_ram[0x2000];
30
31   static UINT8 get_char_rom(running_machine &machine, UINT8 ch, int line)
32   {
33      spc1000_state *state = machine.driver_data<spc1000_state>();
34      return state->m_video_ram[0x1000+(ch&0x7F)*16+line];
35   }
36
37protected:
38   virtual bool screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect);
2839};
2940
3041
r13256r13257
95106
96107   // state->m_GMODE layout: CSS|NA|PS2|PS1|~A/G|GM0|GM1|NA
97108   //  [PS2,PS1] is used to set screen 0/1 pages
98   mc6847_gm1_w(device, BIT(data, 1));
99   mc6847_gm0_w(device, BIT(data, 2));
100   mc6847_ag_w(device, BIT(data, 3));
101   mc6847_css_w(device, BIT(data, 7));
109   state->m_vdg->gm1_w(BIT(data, 1));
110   state->m_vdg->gm0_w(BIT(data, 2));
111   state->m_vdg->ag_w(BIT(data, 3));
112   state->m_vdg->css_w(BIT(data, 7));
102113}
103114
104115static READ8_DEVICE_HANDLER(spc1000_gmode_r)
r13256r13257
240251   //  [PS2,PS1] is used to set screen 0/1 pages
241252   if ( !BIT(state->m_GMODE, 3) ) {   // text mode (~A/G set to A)
242253      unsigned int page = (BIT(state->m_GMODE, 5) << 1) | BIT(state->m_GMODE, 4);
243      mc6847_inv_w(device, BIT(state->m_video_ram[offset+page*0x200+0x800], 0));
244      mc6847_css_w(device, BIT(state->m_video_ram[offset+page*0x200+0x800], 1));
245      mc6847_as_w(device, BIT(state->m_video_ram[offset+page*0x200+0x800], 2));
246      mc6847_intext_w(device, BIT(state->m_video_ram[offset+page*0x200+0x800], 3));
254      state->m_vdg->inv_w(BIT(state->m_video_ram[offset+page*0x200+0x800], 0));
255      state->m_vdg->css_w(BIT(state->m_video_ram[offset+page*0x200+0x800], 1));
256      state->m_vdg->as_w(BIT(state->m_video_ram[offset+page*0x200+0x800], 2));
257      state->m_vdg->intext_w(BIT(state->m_video_ram[offset+page*0x200+0x800], 3));
247258      return state->m_video_ram[offset+page*0x200];
248259   } else {   // graphics mode: uses full 6KB of VRAM
249260      return state->m_video_ram[offset];
250261   }
251262}
252263
253
254static UINT8 spc1000_get_char_rom(running_machine &machine, UINT8 ch, int line)
264bool spc1000_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
255265{
256   spc1000_state *state = machine.driver_data<spc1000_state>();
257   return state->m_video_ram[0x1000+(ch&0x7F)*16+line];
266   return m_vdg->update(&bitmap, &cliprect);
258267}
259268
260static VIDEO_START( spc1000 )
261{
262   spc1000_state *state = machine.driver_data<spc1000_state>();
263   state->m_video_ram = auto_alloc_array(machine, UINT8, 0x2000);
264}
265
266static SCREEN_UPDATE( spc1000 )
267{
268   device_t *mc6847 = screen->machine().device("mc6847");
269   return mc6847_update(mc6847, bitmap, cliprect);
270}
271
272269static const ay8910_interface spc1000_ay_interface =
273270{
274271   AY8910_LEGACY_OUTPUT,
r13256r13257
287284
288285static const mc6847_interface spc1000_mc6847_intf =
289286{
287   "screen",
290288   DEVCB_HANDLER(spc1000_mc6847_videoram_r),   // data fetch
291   DEVCB_LINE_VCC,                        // GM2 [hardwired to 1]
292   DEVCB_NULL,                           // GM1
293   DEVCB_NULL,                           // GM0
294   DEVCB_NULL,                           // INVEXT
295   DEVCB_NULL,                           // INV
296   DEVCB_NULL,                           // ~A/S
297   DEVCB_NULL,                           // ~A/G
298   DEVCB_NULL,                           // CSS
299   DEVCB_NULL,                           // FS (output)
300   DEVCB_NULL,                           // HS (output)
301   DEVCB_NULL                           // RS (output)
289   DEVCB_NULL,
290   DEVCB_NULL,
291
292   DEVCB_NULL,               /* AG */
293   DEVCB_LINE_VCC,            /* GM2 */
294   DEVCB_NULL,               /* GM1 */
295   DEVCB_NULL,               /* GM0 */
296   DEVCB_NULL,               /* CSS */
297   DEVCB_NULL,               /* AS */
298   DEVCB_NULL,               /* INTEXT */
299   DEVCB_NULL,               /* INV */
300
301   &spc1000_state::get_char_rom
302302};
303303
304304static MACHINE_CONFIG_START( spc1000, spc1000_state )
r13256r13257
310310   MCFG_MACHINE_RESET(spc1000)
311311
312312    /* video hardware */
313   MCFG_SCREEN_ADD("screen", RASTER)
314   MCFG_SCREEN_REFRESH_RATE(M6847_NTSC_FRAMES_PER_SECOND)
315   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
316   MCFG_SCREEN_SIZE(320, 25+192+26)
317   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
318   MCFG_SCREEN_UPDATE(spc1000)
313    MCFG_SCREEN_MC6847_NTSC_ADD("screen")
314   MCFG_MC6847_ADD("mc6847", MC6847_NTSC, XTAL_3_579545MHz, spc1000_mc6847_intf)
319315
320   MCFG_VIDEO_START(spc1000)
321
322   MCFG_MC6847_ADD("mc6847", spc1000_mc6847_intf)
323   MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_NTSC)
324   MCFG_MC6847_CHAR_ROM(spc1000_get_char_rom)
325
326316   /* sound hardware */
327317   MCFG_SPEAKER_STANDARD_MONO("mono")
328318   MCFG_SOUND_ADD("ay8910", AY8910, XTAL_4MHz / 1)
src/mess/drivers/phc25.c
r13256r13257
6565   UINT8 data = 0;
6666
6767   /* vertical sync */
68   data |= !mc6847_fs_r(m_vdg) << 4;
68   data |= !m_vdg->fs_r() << 4;
6969
7070   /* cassette read */
7171   data |= ((m_cassette)->input() < +0.3) << 5;
r13256r13257
7474   data |= centronics_busy_r(m_centronics) << 6;
7575
7676   /* horizontal sync */
77   data |= !mc6847_hs_r(m_vdg) << 7;
77   data |= !m_vdg->hs_r() << 7;
7878
7979   return data;
8080}
r13256r13257
106106   centronics_strobe_w(m_centronics, BIT(data, 3));
107107
108108   /* MC6847 */
109   mc6847_intext_w(m_vdg, BIT(data, 2));
110   mc6847_gm0_w(m_vdg, BIT(data, 5));
111   mc6847_gm1_w(m_vdg, BIT(data, 6));
112   mc6847_ag_w(m_vdg, BIT(data, 7));
109   m_vdg->intext_w(BIT(data, 2));
110   m_vdg->gm0_w(BIT(data, 5));
111   m_vdg->gm1_w(BIT(data, 6));
112   m_vdg->ag_w(BIT(data, 7));
113113}
114114
115115/* Memory Maps */
r13256r13257
264264   return m_video_ram[offset & 0x17ff];
265265}
266266
267static UINT8 pal_char_rom_r(running_machine &machine, UINT8 ch, int line)
267UINT8 phc25_state::pal_char_rom_r(running_machine &machine, UINT8 ch, int line)
268268{
269269   phc25_state *state = machine.driver_data<phc25_state>();
270270
271271   return state->m_char_rom[((ch - 2) * 12) + line + 4];
272272}
273273
274static UINT8 ntsc_char_rom_r(running_machine &machine, UINT8 ch, int line)
274UINT8 phc25_state::ntsc_char_rom_r(running_machine &machine, UINT8 ch, int line)
275275{
276276   phc25_state *state = machine.driver_data<phc25_state>();
277277
278278   return state->m_char_rom[(ch * 16) + line];
279279}
280280
281static const mc6847_interface vdg_intf =
281static const mc6847_interface ntsc_vdg_intf =
282282{
283   SCREEN_TAG,
283284   DEVCB_DRIVER_MEMBER(phc25_state, video_ram_r),
284   DEVCB_NULL,
285   DEVCB_NULL,
286   DEVCB_NULL,
287   DEVCB_NULL,
288   DEVCB_NULL,
289   DEVCB_NULL,
290   DEVCB_NULL,
291   DEVCB_NULL,
292   DEVCB_CPU_INPUT_LINE(Z80_TAG, INPUT_LINE_IRQ0),
293   DEVCB_NULL,
294   DEVCB_NULL
285
286   DEVCB_NULL,                                 /* horizontal sync */
287   DEVCB_CPU_INPUT_LINE(Z80_TAG, INPUT_LINE_IRQ0),      /* field sync */
288
289   DEVCB_NULL,                                 /* AG */
290   DEVCB_NULL,                                 /* GM2 */
291   DEVCB_NULL,                                 /* GM1 */
292   DEVCB_NULL,                                 /* GM0 */
293   DEVCB_NULL,                                 /* CSS */
294   DEVCB_NULL,                                 /* AS */
295   DEVCB_NULL,                                 /* INTEXT */
296   DEVCB_NULL,                                 /* INV */
297
298   &phc25_state::ntsc_char_rom_r
295299};
296300
301static const mc6847_interface pal_vdg_intf =
302{
303   SCREEN_TAG,
304   DEVCB_DRIVER_MEMBER(phc25_state, video_ram_r),
305
306   DEVCB_NULL,                                 /* horizontal sync */
307   DEVCB_CPU_INPUT_LINE(Z80_TAG, INPUT_LINE_IRQ0),      /* field sync */
308
309   DEVCB_NULL,                                 /* AG */
310   DEVCB_NULL,                                 /* GM2 */
311   DEVCB_NULL,                                 /* GM1 */
312   DEVCB_NULL,                                 /* GM0 */
313   DEVCB_NULL,                                 /* CSS */
314   DEVCB_NULL,                                 /* AS */
315   DEVCB_NULL,                                 /* INTEXT */
316   DEVCB_NULL,                                 /* INV */
317
318   &phc25_state::pal_char_rom_r
319};
320
321
297322void phc25_state::video_start()
298323{
299324   /* find memory regions */
r13256r13257
302327
303328bool phc25_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
304329{
305   return mc6847_update(m_vdg, &bitmap, &cliprect);
330   return m_vdg->update(&bitmap, &cliprect);
306331}
307332
308333/* AY-3-8910 Interface */
r13256r13257
353378
354379static MACHINE_CONFIG_DERIVED( pal, phc25 )
355380    /* video hardware */
356    MCFG_SCREEN_ADD(SCREEN_TAG, RASTER)
357    MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
358    MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
359    MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
360   MCFG_SCREEN_SIZE(320, 25+192+26)
361   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
362
363    MCFG_PALETTE_LENGTH(16)
364
365   MCFG_MC6847_ADD(MC6847_TAG, vdg_intf)
366    MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_PAL)
367   MCFG_MC6847_CHAR_ROM(pal_char_rom_r)
381   MCFG_SCREEN_MC6847_PAL_ADD(SCREEN_TAG)
382   MCFG_MC6847_ADD(MC6847_TAG, MC6847_PAL, XTAL_4_433619MHz, pal_vdg_intf)
368383MACHINE_CONFIG_END
369384
370385static MACHINE_CONFIG_DERIVED( ntsc, phc25 )
371386    /* video hardware */
372    MCFG_SCREEN_ADD(SCREEN_TAG, RASTER)
373    MCFG_SCREEN_REFRESH_RATE(M6847_NTSC_FRAMES_PER_SECOND)
374    MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
375    MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
376   MCFG_SCREEN_SIZE(320, 25+192+26)
377   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
378
379    MCFG_PALETTE_LENGTH(16)
380
381   MCFG_MC6847_ADD(MC6847_TAG, vdg_intf)
382    MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_NTSC) // actually M5C6847P-1
383   MCFG_MC6847_CHAR_ROM(ntsc_char_rom_r)
387   MCFG_SCREEN_MC6847_NTSC_ADD(SCREEN_TAG)
388   MCFG_MC6847_ADD(MC6847_TAG, MC6847_NTSC, XTAL_3_579545MHz, ntsc_vdg_intf)
384389MACHINE_CONFIG_END
385390
386391/* ROMs */
src/mess/drivers/coco12.c
r0r13257
1/***************************************************************************
2 
3    coco12.c
4 
5    TRS-80 Radio Shack Color Computer 1/2
6 
7    Mathis Rosenhauer (original driver)
8    Nate Woods (current maintainer)
9    Tim Lindner (VHD and other work)
10 
11    Version information:
12 
13    Basic   Extended Basic  Disk Extended
14    coco    1.0 -           -
15    cocoe   1.1 1.0         1.0
16    coco2   1.2 1.1         1.1
17    coco2b  1.3 1.1         1.1
18    coco3   1.2 2.0         1.1
19    coco3p  1.2 2.0         1.1
20    coco3h  1.2 2.0         1.1
21 
22***************************************************************************/
23 
24#include "includes/coco12.h"
25#include "imagedev/cassette.h"
26#include "cpu/m6809/m6809.h"
27#include "machine/coco_232.h"
28#include "machine/coco_orch90.h"
29#include "machine/coco_pak.h"
30#include "machine/coco_fdc.h"
31#include "machine/coco_multi.h"
32 
33 
34//**************************************************************************
35//  ADDRESS MAPS
36//**************************************************************************
37 
38//-------------------------------------------------
39//  ADDRESS_MAP( coco_mem )
40//-------------------------------------------------
41 
42static ADDRESS_MAP_START( coco_mem, AS_PROGRAM, 8, coco_state )
43ADDRESS_MAP_END
44 
45 
46 
47//**************************************************************************
48//  INPUT PORTS
49//**************************************************************************
50 
51//--------------------------------------------------------------------------
52//  INPUT_PORTS( coco_analog_control )
53//
54//   Other CoCo controllers were compatible with the Dragon, even if no
55//   software is known to make use of them We add them here, based on this
56//   compatibility, in case anyone wants to use them in homebrew software
57//--------------------------------------------------------------------------
58 
59INPUT_PORTS_START( coco_analog_control )
60   PORT_START(CTRL_SEL_TAG)  /* Select Controller Type */
61   PORT_CONFNAME( 0x0f, 0x01, "Right Controller Port (P1)")         PORT_CHANGED( coco_state::joystick_mode_changed, 0 )
62   PORT_CONFSETTING(  0x00, "Unconnected" )
63   PORT_CONFSETTING(  0x01, "Joystick" )
64   PORT_CONFSETTING(  0x02, "The Rat Graphics Mouse" )               PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_NOTEQUALS, 0x20)
65   PORT_CONFSETTING(  0x03, "Diecom Light Gun Adaptor" )            PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_NOTEQUALS, 0x30)
66   PORT_CONFNAME( 0xf0, 0x10, "Left Controller Port (P2)")            PORT_CHANGED( coco_state::joystick_mode_changed, 0 )
67   PORT_CONFSETTING(  0x00, "Unconnected" )
68   PORT_CONFSETTING(  0x10, "Joystick" )
69   PORT_CONFSETTING(  0x20, "The Rat Graphics Mouse" )               PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_NOTEQUALS, 0x02)
70   PORT_CONFSETTING(  0x30, "Diecom Light Gun Adaptor" )            PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_NOTEQUALS, 0x03)
71 
72   PORT_START(HIRES_INTF_TAG)
73   PORT_CONFNAME( 0x07, 0x00, "Hi-Res Joystick Interfaces" )
74   PORT_CONFSETTING(    0x00, "None" )
75   PORT_CONFSETTING(    0x01, "Hi-Res in Right Port" )                 PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x01)
76   PORT_CONFSETTING(    0x02, "Hi-Res CoCoMax 3 Style in Right Port" ) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x01)
77   PORT_CONFSETTING(    0x03, "Hi-Res in Left Port" )                  PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x10)
78   PORT_CONFSETTING(    0x04, "Hi-Res CoCoMax 3 Style in Left Port" )  PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x10)
79INPUT_PORTS_END
80 
81 
82 
83//-------------------------------------------------
84//  INPUT_PORTS( coco_joystick )
85//-------------------------------------------------
86 
87static INPUT_PORTS_START( coco_joystick )
88   PORT_START(JOYSTICK_RX_TAG)
89   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_4_PAD) PORT_CODE_INC(KEYCODE_6_PAD) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x01)
90   PORT_START(JOYSTICK_RY_TAG)
91   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_8_PAD) PORT_CODE_INC(KEYCODE_2_PAD) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH)   PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x01)
92   PORT_START(JOYSTICK_LX_TAG)
93   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_4_PAD) PORT_CODE_INC(KEYCODE_6_PAD) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x10)
94   PORT_START(JOYSTICK_LY_TAG)
95   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_8_PAD) PORT_CODE_INC(KEYCODE_2_PAD) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH)   PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x10)
96   PORT_START(JOYSTICK_BUTTONS_TAG)
97   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Right Button") PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x01)
98   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Left Button")  PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x10)
99INPUT_PORTS_END
100 
101 
102 
103//-------------------------------------------------
104//  INPUT_PORTS( coco_cart_autostart )
105//-------------------------------------------------
106 
107INPUT_PORTS_START( coco_cart_autostart )
108   PORT_START(CART_AUTOSTART_TAG)
109   PORT_CONFNAME( 0x01, 0x01, "Cart Auto-Start" )
110   PORT_CONFSETTING(    0x00, DEF_STR( Off ))
111   PORT_CONFSETTING(    0x01, DEF_STR( On ))
112INPUT_PORTS_END
113 
114 
115 
116//-------------------------------------------------
117//  INPUT_PORTS( coco_keyboard )
118//-------------------------------------------------
119//
120//   CoCo keyboard
121//
122//          PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7
123//     PA6: Ent Clr Brk N/c N/c N/c N/c Shift
124//     PA5: 8   9   :   ;   ,   -   .   /
125//     PA4: 0   1   2   3   4   5   6   7
126//     PA3: X   Y   Z   Up  Dwn Lft Rgt Space
127//     PA2: P   Q   R   S   T   U   V   W
128//     PA1: H   I   J   K   L   M   N   O
129//     PA0: @   A   B   C   D   E   F   G
130//-------------------------------------------------
131 
132static INPUT_PORTS_START( coco_keyboard )
133   PORT_START("row0")
134   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_ASTERISK) PORT_CHAR('@')
135   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_A) PORT_CHAR('A')
136   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_B) PORT_CHAR('B')
137   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_C) PORT_CHAR('C')
138   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_D) PORT_CHAR('D')
139   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_E) PORT_CHAR('E')
140   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_F) PORT_CHAR('F')
141   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_G) PORT_CHAR('G')
142 
143   PORT_START("row1")
144   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_H) PORT_CHAR('H')
145   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_I) PORT_CHAR('I')
146   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_J) PORT_CHAR('J')
147   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_K) PORT_CHAR('K')
148   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_L) PORT_CHAR('L')
149   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_M) PORT_CHAR('M')
150   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_N) PORT_CHAR('N')
151   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_O) PORT_CHAR('O')
152 
153   PORT_START("row2")
154   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_P) PORT_CHAR('P')
155   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_Q) PORT_CHAR('Q')
156   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_R) PORT_CHAR('R')
157   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_S) PORT_CHAR('S')
158   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_T) PORT_CHAR('T')
159   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_U) PORT_CHAR('U')
160   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_V) PORT_CHAR('V')
161   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_W) PORT_CHAR('W')
162 
163   PORT_START("row3")
164   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_X) PORT_CHAR('X')
165   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_Y) PORT_CHAR('Y')
166   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_Z) PORT_CHAR('Z')
167   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("UP") PORT_CODE(KEYCODE_UP) PORT_CHAR('^')
168   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("DOWN") PORT_CODE(KEYCODE_DOWN) PORT_CHAR(10)
169   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("LEFT") PORT_CODE(KEYCODE_LEFT) PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8)
170   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("RIGHT") PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(9)
171   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("SPACE") PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')
172 
173   PORT_START("row4")
174   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0) PORT_CHAR('0')
175   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')
176   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('\"')
177   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')
178   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')
179   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')
180   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')
181   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
182 
183   PORT_START("row5")
184   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('(')
185   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR(')')
186   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_COLON) PORT_CHAR(':') PORT_CHAR('*')
187   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR(';') PORT_CHAR('+')
188   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<')
189   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('=')
190   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>')
191   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')
192 
193   PORT_START("row6")
194   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("ENTER") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
195   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("CLEAR") PORT_CODE(KEYCODE_HOME) PORT_CHAR(12)
196   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("BREAK") PORT_CODE(KEYCODE_END) PORT_CODE(KEYCODE_ESC) PORT_CHAR(27)
197   PORT_BIT(0x78, IP_ACTIVE_LOW, IPT_UNUSED)
198   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("SHIFT") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
199INPUT_PORTS_END
200 
201 
202 
203//-------------------------------------------------
204//  INPUT_PORTS( coco )
205//-------------------------------------------------
206 
207static INPUT_PORTS_START( coco )
208   PORT_INCLUDE( coco_keyboard )
209   PORT_INCLUDE( coco_joystick )
210   PORT_INCLUDE( coco_analog_control )
211   PORT_INCLUDE( coco_cart_autostart )
212INPUT_PORTS_END
213 
214 
215 
216//**************************************************************************
217//  MACHINE CONFIGURATION
218//**************************************************************************
219 
220//-------------------------------------------------
221//  SLOT_INTERFACE_START(coco_cart)
222//-------------------------------------------------
223 
224SLOT_INTERFACE_START( coco_cart )
225   SLOT_INTERFACE("fdc", COCO_FDC)
226   SLOT_INTERFACE("fdcv11", COCO_FDC_V11)
227   SLOT_INTERFACE("cp400_fdc", CP400_FDC)   
228   SLOT_INTERFACE("rs232", COCO_232)
229   SLOT_INTERFACE("orch90", COCO_ORCH90)
230   SLOT_INTERFACE("banked_16k", COCO_PAK_BANKED)
231   SLOT_INTERFACE("pak", COCO_PAK)
232   SLOT_INTERFACE("multi", COCO_MULTIPAK)
233SLOT_INTERFACE_END
234 
235 
236 
237//-------------------------------------------------
238//  MACHINE_CONFIG_FRAGMENT( coco_sound )
239//-------------------------------------------------
240 
241MACHINE_CONFIG_FRAGMENT( coco_sound )
242   MCFG_SPEAKER_STANDARD_MONO("mono")
243   MCFG_SOUND_ADD(DAC_TAG, DAC, 0)
244   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
245   MCFG_SOUND_WAVE_ADD(WAVE_TAG, CASSETTE_TAG)
246   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
247MACHINE_CONFIG_END
248 
249 
250 
251//-------------------------------------------------
252//  MACHINE_CONFIG
253//-------------------------------------------------
254 
255static MACHINE_CONFIG_START( coco, coco12_state )
256   // basic machine hardware
257   MCFG_CPU_ADD(MAINCPU_TAG, M6809E, XTAL_3_579545MHz)
258   MCFG_CPU_PROGRAM_MAP(coco_mem)
259 
260   // devices
261   MCFG_PIA6821_ADD(PIA0_TAG, coco_state::pia0_config)
262   MCFG_PIA6821_ADD(PIA1_TAG, coco_state::pia1_config)
263   MCFG_SAM6883_ADD(SAM_TAG, XTAL_3_579545MHz, coco12_state::sam6883_config)
264   MCFG_CASSETTE_ADD(CASSETTE_TAG, coco_state::coco_cassette_interface)
265   MCFG_BITBANGER_ADD(BITBANGER_TAG, coco_state::coco_bitbanger_config)
266   MCFG_COCO_CARTRIDGE_ADD(CARTRIDGE_TAG, coco_state::cartridge_config, coco_cart, "pak", NULL)
267   MCFG_COCO_VHD_ADD(VHD_TAG)
268 
269   // video hardware
270    MCFG_SCREEN_MC6847_NTSC_ADD(SCREEN_TAG)
271   MCFG_MC6847_ADD(VDG_TAG, MC6847_NTSC, XTAL_3_579545MHz, coco12_state::mc6847_config)
272 
273   // sound hardware
274   MCFG_FRAGMENT_ADD( coco_sound )
275 
276   // internal ram
277   MCFG_RAM_ADD(RAM_TAG)
278   MCFG_RAM_DEFAULT_SIZE("64K")
279   MCFG_RAM_EXTRA_OPTIONS("4K,16K,32K")
280 
281   // software lists
282   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
283MACHINE_CONFIG_END
284 
285static MACHINE_CONFIG_DERIVED( cocoe, coco )
286   MCFG_COCO_CARTRIDGE_REMOVE(CARTRIDGE_TAG)
287   MCFG_COCO_CARTRIDGE_ADD(CARTRIDGE_TAG, coco12_state::cartridge_config, coco_cart, "fdc", NULL)
288MACHINE_CONFIG_END
289 
290static MACHINE_CONFIG_DERIVED( coco2, coco )
291   MCFG_COCO_CARTRIDGE_REMOVE(CARTRIDGE_TAG)
292   MCFG_COCO_CARTRIDGE_ADD(CARTRIDGE_TAG, coco12_state::cartridge_config, coco_cart, "fdcv11", NULL)
293MACHINE_CONFIG_END
294 
295static MACHINE_CONFIG_DERIVED( coco2b, coco2 )
296   MCFG_MC6847_REMOVE(VDG_TAG)
297   MCFG_MC6847_ADD(VDG_TAG, MC6847T1_NTSC, XTAL_3_579545MHz, coco12_state::mc6847_config)
298MACHINE_CONFIG_END
299 
300static MACHINE_CONFIG_DERIVED( cp400, coco )
301   MCFG_COCO_CARTRIDGE_REMOVE(CARTRIDGE_TAG)
302   MCFG_COCO_CARTRIDGE_ADD(CARTRIDGE_TAG, coco12_state::cartridge_config, coco_cart, "cp400_fdc", NULL)
303MACHINE_CONFIG_END
304 
305 
306//**************************************************************************
307//  ROMS
308//**************************************************************************
309 
310ROM_START(coco)
311   ROM_REGION(0x8000,MAINCPU_TAG,0)
312   ROM_LOAD("bas10.rom",   0x2000, 0x2000, CRC(00b50aaa) SHA1(1f08455cd48ce6a06132aea15c4778f264e19539))
313ROM_END
314 
315ROM_START(cocoe)
316   ROM_REGION(0x8000,MAINCPU_TAG,0)
317   ROM_LOAD("bas11.rom",   0x2000, 0x2000, CRC(6270955a) SHA1(cecb7c24ff1e0ab5836e4a7a8eb1b8e01f1fded3))
318   ROM_LOAD("extbas10.rom",   0x0000, 0x2000, CRC(6111a086) SHA1(8aa58f2eb3e8bcfd5470e3e35e2b359e9a72848e))
319ROM_END
320 
321ROM_START(coco2)
322   ROM_REGION(0x8000,MAINCPU_TAG,0)
323   ROM_LOAD("bas12.rom",   0x2000, 0x2000, CRC(54368805) SHA1(0f14dc46c647510eb0b7bd3f53e33da07907d04f))
324   ROM_LOAD("extbas11.rom",   0x0000, 0x2000, CRC(a82a6254) SHA1(ad927fb4f30746d820cb8b860ebb585e7f095dea))
325ROM_END
326 
327ROM_START(coco2b)
328   ROM_REGION(0x8000,MAINCPU_TAG,0)
329   ROM_LOAD("bas13.rom",   0x2000, 0x2000, CRC(d8f4d15e) SHA1(28b92bebe35fa4f026a084416d6ea3b1552b63d3))
330   ROM_LOAD("extbas11.rom",   0x0000, 0x2000, CRC(a82a6254) SHA1(ad927fb4f30746d820cb8b860ebb585e7f095dea))
331ROM_END
332 
333ROM_START(cp400)
334   ROM_REGION(0x8000,MAINCPU_TAG,0)
335   ROM_LOAD("cp400bas.rom",  0x0000, 0x4000, CRC(878396a5) SHA1(292c545da3c77978e043b00a3dbc317201d18c3b))
336ROM_END
337 
338 
339 
340//**************************************************************************
341//  SYSTEM DRIVERS
342//**************************************************************************
343 
344/*     YEAR     NAME        PARENT  COMPAT  MACHINE    INPUT      INIT    COMPANY                 FULLNAME */
345COMP(  1980,    coco,       0,      0,      coco,      coco,      0,      "Tandy Radio Shack",    "Color Computer", 0)
346COMP(  1981,    cocoe,      coco,   0,      cocoe,     coco,      0,      "Tandy Radio Shack",    "Color Computer (Extended BASIC 1.0)", 0)
347COMP(  1983,    coco2,      coco,   0,      coco2,     coco,      0,      "Tandy Radio Shack",     "Color Computer 2", 0)
348COMP(  1985?,   coco2b,     coco,   0,      coco2b,    coco,      0,      "Tandy Radio Shack",     "Color Computer 2B", 0)
349COMP(  1984,    cp400,      coco,   0,      cp400,     coco,      0,      "Prologica",            "CP400", 0)
src/mess/drivers/vtech1.c
r13256r13257
114114#include "emu.h"
115115#include "formats/imageutl.h"
116116#include "cpu/z80/z80.h"
117#include "video/m6847.h"
117#include "video/mc6847.h"
118118#include "machine/ctronics.h"
119119#include "sound/wave.h"
120120#include "sound/speaker.h"
r13256r13257
156156{
157157public:
158158   vtech1_state(const machine_config &mconfig, device_type type, const char *tag)
159      : driver_device(mconfig, type, tag) { }
159      : driver_device(mconfig, type, tag),
160        m_mc6847(*this, "mc6847"),
161        m_speaker(*this, SPEAKER_TAG),
162        m_cassette(*this, CASSETTE_TAG),
163        m_printer(*this, "printer")
164   { }
160165
161166   /* devices */
162   device_t *m_mc6847;
163   device_t *m_speaker;
164   cassette_image_device *m_cassette;
165   device_t *m_printer;
167   required_device<mc6847_base_device> m_mc6847;
168   optional_device<device_t> m_speaker;
169   optional_device<cassette_image_device> m_cassette;
170   optional_device<device_t> m_printer;
166171
167172   UINT8 *m_ram;
168173   UINT32 m_ram_size;
r13256r13257
182187   int m_fdc_write;
183188   int m_fdc_offs;
184189   int m_fdc_latch;
190
191protected:
192   virtual bool screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect);
185193};
186194
187195
r13256r13257
535543   result |= ((vtech1->m_cassette->input()) > 0 ? 1 : 0) << 6;
536544
537545   /* bit 7, field sync */
538   result |= mc6847_fs_r(vtech1->m_mc6847) << 7;
546   result |= vtech1->m_mc6847->fs_r() << 7;
539547
540548   return result;
541549}
r13256r13257
555563   /* bit 1, SHRG mod (if installed) */
556564   if (vtech1->m_videoram_size == 0x2000)
557565   {
558      mc6847_gm0_w(vtech1->m_mc6847, BIT(data, 1));
559      mc6847_gm2_w(vtech1->m_mc6847, BIT(data, 1));
566      vtech1->m_mc6847->gm0_w(BIT(data, 1));
567      vtech1->m_mc6847->gm2_w(BIT(data, 1));
560568   }
561569
562570   /* bit 2, cassette out */
563571   vtech1->m_cassette->output( BIT(data, 2) ? +1.0 : -1.0);
564572
565573   /* bit 3 and 4, vdc mode control lines */
566   mc6847_ag_w(vtech1->m_mc6847, BIT(data, 3));
567   mc6847_css_w(vtech1->m_mc6847, BIT(data, 4));
574   vtech1->m_mc6847->ag_w(BIT(data, 3));
575   vtech1->m_mc6847->css_w(BIT(data, 4));
568576
569577   /* bit 0 and 5, speaker */
570578   speaker_level_w(vtech1->m_speaker, (BIT(data, 5) << 1) | BIT(data, 0));
r13256r13257
600608static READ8_DEVICE_HANDLER( vtech1_mc6847_videoram_r )
601609{
602610   vtech1_state *vtech1 = device->machine().driver_data<vtech1_state>();
603   mc6847_inv_w(device, BIT(vtech1->m_videoram[offset], 6));
604   mc6847_as_w(device, BIT(vtech1->m_videoram[offset], 7));
611   vtech1->m_mc6847->inv_w(BIT(vtech1->m_videoram[offset], 6));
612   vtech1->m_mc6847->as_w(BIT(vtech1->m_videoram[offset], 7));
605613
606614   return vtech1->m_videoram[offset];
607615}
608616
609static SCREEN_UPDATE( vtech1 )
617bool vtech1_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
610618{
611   vtech1_state *vtech1 = screen->machine().driver_data<vtech1_state>();
612   return mc6847_update(vtech1->m_mc6847, bitmap, cliprect);
619   return m_mc6847->update(&bitmap, &cliprect);
613620}
614621
615622
r13256r13257
623630   address_space *prg = machine.device("maincpu")->memory().space(AS_PROGRAM);
624631   int id;
625632
626   /* find devices */
627   vtech1->m_mc6847 = machine.device("mc6847");
628   vtech1->m_speaker = machine.device(SPEAKER_TAG);
629   vtech1->m_cassette = machine.device<cassette_image_device>(CASSETTE_TAG);
630   vtech1->m_printer = machine.device("printer");
631
632633   /* ram */
633634   vtech1->m_ram = ram_get_ptr(machine.device(RAM_TAG));
634635   vtech1->m_ram_size = ram_get_size(machine.device(RAM_TAG));
r13256r13257
910911
911912static const mc6847_interface vtech1_mc6847_intf =
912913{
914   "screen",
913915   DEVCB_HANDLER(vtech1_mc6847_videoram_r),
914   DEVCB_LINE_GND,
915   DEVCB_LINE_VCC,
916   DEVCB_LINE_GND,
917   DEVCB_LINE_GND,
918   DEVCB_NULL,
919   DEVCB_NULL,
920   DEVCB_NULL,
921   DEVCB_NULL,
922   DEVCB_CPU_INPUT_LINE("maincpu", 0),
923   DEVCB_NULL,
924   DEVCB_NULL,
916   DEVCB_NULL,                           /* horz sync */
917   DEVCB_CPU_INPUT_LINE("maincpu", 0),         /* field sync */
918
919   DEVCB_NULL,                           /* AG */
920   DEVCB_LINE_GND,                        /* GM2 */
921   DEVCB_LINE_VCC,                        /* GM1 */
922   DEVCB_LINE_GND,                        /* GM0 */
923   DEVCB_NULL,                           /* CSS */
924   DEVCB_NULL,                           /* AS */
925   DEVCB_LINE_GND,                        /* INTEXT */
926   DEVCB_NULL,                           /* INV */
927
928   NULL,                              /* m_get_char_rom */
929   true                              /* m_black_and_white */
925930};
926931
927932static const mc6847_interface vtech1_shrg_mc6847_intf =
928933{
934   "screen",
929935   DEVCB_HANDLER(vtech1_mc6847_videoram_r),
930   DEVCB_NULL,
931   DEVCB_LINE_VCC,
932   DEVCB_NULL,
933   DEVCB_LINE_GND,
934   DEVCB_NULL,
935   DEVCB_NULL,
936   DEVCB_NULL,
937   DEVCB_NULL,
938   DEVCB_CPU_INPUT_LINE("maincpu", 0),
939   DEVCB_NULL,
940   DEVCB_NULL,
936   DEVCB_NULL,                           /* horz sync */
937   DEVCB_CPU_INPUT_LINE("maincpu", 0),         /* field sync */
938
939   DEVCB_NULL,                           /* AG */
940   DEVCB_NULL,                           /* GM2 */
941   DEVCB_LINE_VCC,                        /* GM1 */
942   DEVCB_NULL,                           /* GM0 */
943   DEVCB_NULL,                           /* CSS */
944   DEVCB_NULL,                           /* AS */
945   DEVCB_LINE_GND,                        /* INTEXT */
946   DEVCB_NULL,                           /* INV */
941947};
942948
943949static MACHINE_CONFIG_START( laser110, vtech1_state )
r13256r13257
948954   MCFG_CPU_IO_MAP(vtech1_io)
949955
950956   /* video hardware */
951   MCFG_SCREEN_ADD("screen", RASTER)
952   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
953   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
954   MCFG_SCREEN_SIZE(320, 25+192+26)
955   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
956   MCFG_SCREEN_UPDATE(vtech1)
957   MCFG_SCREEN_MC6847_PAL_ADD("screen")
958   MCFG_MC6847_ADD("mc6847", MC6847_PAL, XTAL_4_433619MHz, vtech1_mc6847_intf)
957959
958   MCFG_MC6847_ADD("mc6847", vtech1_mc6847_intf)
959   MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_PAL)
960   MCFG_MC6847_PALETTE(vtech1_palette_mono)
961
962960   /* sound hardware */
963961   MCFG_SPEAKER_STANDARD_MONO("mono")
964962   MCFG_SOUND_WAVE_ADD(WAVE_TAG, CASSETTE_TAG)
r13256r13257
989987
990988static MACHINE_CONFIG_DERIVED( laser200, laser110 )
991989   MCFG_DEVICE_MODIFY("mc6847")
992   MCFG_MC6847_PALETTE(NULL)
993990MACHINE_CONFIG_END
994991
995992static MACHINE_CONFIG_DERIVED( laser210, laser200 )
r13256r13257
10171014   MCFG_CPU_IO_MAP(vtech1_shrg_io)
10181015
10191016   MCFG_DEVICE_REMOVE("mc6847")
1020   MCFG_MC6847_ADD("mc6847", vtech1_shrg_mc6847_intf)
1021   MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_PAL)
1017   MCFG_MC6847_ADD("mc6847", MC6847_PAL, XTAL_4_433619MHz, vtech1_shrg_mc6847_intf)
10221018MACHINE_CONFIG_END
10231019
10241020
src/mess/drivers/dgnalpha.c
rsrc/mess/drivers/dgnalpha.crsrc/mess/drivers/dgnalpha.c
100100/* peripheral chips */
101101#include "machine/ay31015.h"
102102#include "machine/kr2376.h"
103#include "video/m6847.h"
103#include "video/mc6847.h"
104104#include "machine/wd17xx.h"
105105
106106/* Layout */
rsrc/mess/drivers/dgnalpha.crsrc/mess/drivers/dgnalpha.c
454454
455455static const mc6847_interface z80net_mc6847_intf =
456456{
457   "lx388",
457458   DEVCB_HANDLER(lx388_mc6847_videoram_r),
458   DEVCB_LINE_GND,
459   DEVCB_LINE_GND,
460   DEVCB_LINE_GND,
461459   DEVCB_NULL,
462460   DEVCB_NULL,
463   DEVCB_NULL,
464   DEVCB_LINE_GND,
465   DEVCB_LINE_GND,
466   DEVCB_NULL,
467   DEVCB_NULL,
468   DEVCB_NULL
461
462   DEVCB_LINE_GND,            /* AG */
463   DEVCB_LINE_GND,            /* GM2 */
464   DEVCB_LINE_GND,            /* GM1 */
465   DEVCB_LINE_GND,            /* GM0 */
466   DEVCB_LINE_GND,            /* CSS */
467   DEVCB_NULL,               /* AS */
468   DEVCB_NULL,               /* INTEXT */
469   DEVCB_NULL,               /* INV */
469470};
470471
471472static MACHINE_CONFIG_START( z80ne, z80ne_state )
rsrc/mess/drivers/dgnalpha.crsrc/mess/drivers/dgnalpha.c
501502   MCFG_KR2376_ADD( "lx388_kr2376", lx388_kr2376_interface)
502503
503504   /* video hardware */
504   MCFG_SCREEN_ADD("lx388", RASTER)
505   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
506   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
507   MCFG_SCREEN_SIZE(320, 25+192+26)
508   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
509   MCFG_SCREEN_UPDATE(lx388)
505    MCFG_SCREEN_MC6847_PAL_ADD("lx388")
506   MCFG_MC6847_ADD("mc6847", MC6847_PAL, XTAL_4_433619MHz, z80net_mc6847_intf)
510507
511   MCFG_MC6847_ADD("mc6847", z80net_mc6847_intf)
512   MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_PAL)
513   MCFG_MC6847_PALETTE(lx388palette)
514
515508   MCFG_DEFAULT_LAYOUT(layout_z80net)
516509
517510   /* internal ram */
rsrc/mess/drivers/dgnalpha.crsrc/mess/drivers/dgnalpha.c
537530   MCFG_KR2376_ADD( "lx388_kr2376", lx388_kr2376_interface)
538531
539532   /* video hardware */
540   MCFG_SCREEN_ADD("lx388", RASTER)
541   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
542   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
543   MCFG_SCREEN_SIZE(320, 25+192+26)
544   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
545   MCFG_SCREEN_UPDATE(lx388)
533    MCFG_SCREEN_MC6847_PAL_ADD("lx388")
534   MCFG_MC6847_ADD("mc6847", MC6847_PAL, XTAL_4_433619MHz, z80net_mc6847_intf)
546535
547536   MCFG_DEFAULT_LAYOUT(layout_z80netb)
548537
549   MCFG_MC6847_ADD("mc6847", z80net_mc6847_intf)
550   MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_PAL)
551   MCFG_MC6847_PALETTE(lx388palette)
552
553538   /* internal ram */
554539   MCFG_RAM_ADD(RAM_TAG)
555540   MCFG_RAM_DEFAULT_SIZE("32K")
rsrc/mess/drivers/dgnalpha.crsrc/mess/drivers/dgnalpha.c
573558   MCFG_KR2376_ADD( "lx388_kr2376", lx388_kr2376_interface)
574559
575560   /* video hardware */
576   MCFG_SCREEN_ADD("lx388", RASTER)
577   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
578   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
579   MCFG_SCREEN_SIZE(320, 25+192+26)
580   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
581   MCFG_SCREEN_UPDATE(lx388)
561    MCFG_SCREEN_MC6847_PAL_ADD("lx388")
562   MCFG_MC6847_ADD("mc6847", MC6847_PAL, XTAL_4_433619MHz, z80net_mc6847_intf)
582563
583   MCFG_MC6847_ADD("mc6847", z80net_mc6847_intf)
584   MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_PAL)
585   MCFG_MC6847_PALETTE(lx388palette)
586
587564   MCFG_FD1771_ADD("wd1771", default_wd17xx_interface)
588565   MCFG_LEGACY_FLOPPY_4_DRIVES_ADD(z80netf_floppy_interface)
589566
src/mess/drivers/dragon.c
r0r13257
1/***************************************************************************
2 
3   dragon.c
4 
5   Dragon
6 
7***************************************************************************/
8 
9#include "includes/dragon.h"
10#include "includes/dgnalpha.h"
11#include "imagedev/cassette.h"
12#include "cpu/m6809/m6809.h"
13#include "machine/coco_232.h"
14#include "machine/coco_orch90.h"
15#include "machine/coco_pak.h"
16#include "machine/coco_fdc.h"
17#include "machine/coco_multi.h"
18#include "formats/coco_dsk.h"
19#include "imagedev/flopdrv.h"
20 
21 
22//**************************************************************************
23//  ADDRESS MAPS
24//**************************************************************************
25 
26//-------------------------------------------------
27//  ADDRESS_MAP( dragon_mem )
28//-------------------------------------------------
29 
30static ADDRESS_MAP_START( dragon_mem, AS_PROGRAM, 8, dragon_state )
31ADDRESS_MAP_END
32 
33 
34 
35//**************************************************************************
36//  INPUT PORTS
37//**************************************************************************
38 
39/* Dragon keyboard
40 
41       PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7
42  PA6: Ent Clr Brk N/c N/c N/c N/c Shift
43  PA5: X   Y   Z   Up  Dwn Lft Rgt Space
44  PA4: P   Q   R   S   T   U   V   W
45  PA3: H   I   J   K   L   M   N   O
46  PA2: @   A   B   C   D   E   F   G
47  PA1: 8   9   :   ;   ,   -   .   /
48  PA0: 0   1   2   3   4   5   6   7
49 */
50static INPUT_PORTS_START( dragon32 )
51   PORT_START("row0")
52   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0) PORT_CHAR('0')
53   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')
54   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('\"')
55   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')
56   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')
57   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')
58   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')
59   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
60 
61   PORT_START("row1")
62   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('(')
63   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR(')')
64   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_COLON) PORT_CHAR(':') PORT_CHAR('*')
65   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR(';') PORT_CHAR('+')
66   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<')
67   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('=')
68   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>')
69   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')
70 
71   PORT_START("row2")
72   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_ASTERISK) PORT_CHAR('@')
73   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_A) PORT_CHAR('A')
74   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_B) PORT_CHAR('B')
75   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_C) PORT_CHAR('C')
76   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_D) PORT_CHAR('D')
77   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_E) PORT_CHAR('E')
78   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_F) PORT_CHAR('F')
79   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_G) PORT_CHAR('G')
80 
81   PORT_START("row3")
82   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_H) PORT_CHAR('H')
83   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_I) PORT_CHAR('I')
84   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_J) PORT_CHAR('J')
85   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_K) PORT_CHAR('K')
86   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_L) PORT_CHAR('L')
87   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_M) PORT_CHAR('M')
88   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_N) PORT_CHAR('N')
89   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_O) PORT_CHAR('O')
90 
91   PORT_START("row4")
92   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_P) PORT_CHAR('P')
93   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_Q) PORT_CHAR('Q')
94   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_R) PORT_CHAR('R')
95   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_S) PORT_CHAR('S')
96   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_T) PORT_CHAR('T')
97   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_U) PORT_CHAR('U')
98   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_V) PORT_CHAR('V')
99   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_W) PORT_CHAR('W')
100 
101   PORT_START("row5")
102   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_X) PORT_CHAR('X')
103   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_Y) PORT_CHAR('Y')
104   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_Z) PORT_CHAR('Z')
105   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_NAME("UP") PORT_CODE(KEYCODE_UP) PORT_CHAR('^')
106   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_NAME("DOWN") PORT_CODE(KEYCODE_DOWN) PORT_CHAR(10)
107   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_NAME("LEFT") PORT_CODE(KEYCODE_LEFT) PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8)
108   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_NAME("RIGHT") PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(9)
109   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_NAME("SPACE") PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')
110 
111   PORT_START("row6")
112   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_NAME("ENTER") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
113   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_NAME("CLEAR") PORT_CODE(KEYCODE_HOME) PORT_CHAR(12)
114   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_NAME("BREAK") PORT_CODE(KEYCODE_END) PORT_CODE(KEYCODE_ESC) PORT_CHAR(27)
115   PORT_BIT(0x78, IP_ACTIVE_LOW, IPT_UNUSED)
116   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(dragon_state::keyboard_changed, NULL) PORT_NAME("SHIFT") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
117INPUT_PORTS_END
118 
119static SLOT_INTERFACE_START(dragon_cart)
120   SLOT_INTERFACE("dragon_fdc", DRAGON_FDC)
121   SLOT_INTERFACE("sdtandy_fdc", SDTANDY_FDC)   
122   SLOT_INTERFACE("pak", COCO_PAK)
123SLOT_INTERFACE_END
124 
125static const floppy_interface coco_floppy_interface =
126{
127   DEVCB_NULL,
128   DEVCB_NULL,
129   DEVCB_NULL,
130   DEVCB_NULL,
131   DEVCB_NULL,
132   FLOPPY_STANDARD_5_25_DSHD,
133   LEGACY_FLOPPY_OPTIONS_NAME(coco),
134   NULL,
135   NULL
136};
137 
138static MACHINE_CONFIG_START( dragon_base, dragon_state )
139   // basic machine hardware
140   MCFG_CPU_ADD("maincpu", M6809E, XTAL_4_433619MHz)
141   MCFG_CPU_PROGRAM_MAP(dragon_mem)
142 
143   // devices
144   MCFG_PIA6821_ADD(PIA0_TAG, dragon_state::pia0_config)
145   MCFG_PIA6821_ADD(PIA1_TAG, dragon_state::pia1_config)
146   MCFG_SAM6883_ADD(SAM_TAG, XTAL_4_433619MHz, dragon_state::sam6883_config)
147   MCFG_CASSETTE_ADD(CASSETTE_TAG, dragon_state::coco_cassette_interface)
148   MCFG_PRINTER_ADD(PRINTER_TAG)
149 
150   // video hardware
151   MCFG_SCREEN_MC6847_PAL_ADD(SCREEN_TAG)
152   MCFG_MC6847_ADD(VDG_TAG, MC6847_PAL, XTAL_4_433619MHz, dragon_state::mc6847_config)
153 
154   // sound hardware
155   MCFG_FRAGMENT_ADD( coco_sound )
156MACHINE_CONFIG_END
157 
158static MACHINE_CONFIG_DERIVED( dragon32, dragon_base )
159   // internal ram
160   MCFG_RAM_ADD(RAM_TAG)
161   MCFG_RAM_DEFAULT_SIZE("32K")
162   MCFG_RAM_EXTRA_OPTIONS("64K")
163 
164   // cartridge
165   MCFG_COCO_CARTRIDGE_ADD(CARTRIDGE_TAG, dragon_state::cartridge_config, dragon_cart, "dragon_fdc", NULL)
166MACHINE_CONFIG_END
167 
168static MACHINE_CONFIG_DERIVED_CLASS( dragon64, dragon_base, dragon64_state )
169   // internal ram
170   MCFG_RAM_ADD(RAM_TAG)
171   MCFG_RAM_DEFAULT_SIZE("64K")
172 
173   // cartridge
174   MCFG_COCO_CARTRIDGE_ADD(CARTRIDGE_TAG, dragon_state::cartridge_config, dragon_cart, "dragon_fdc", NULL)
175 
176   // acia
177   MCFG_ACIA6551_ADD("acia")
178MACHINE_CONFIG_END
179 
180static MACHINE_CONFIG_DERIVED_CLASS( d64plus, dragon_base, dragon64_state )
181   // internal ram
182   MCFG_RAM_ADD(RAM_TAG)
183   MCFG_RAM_DEFAULT_SIZE("128K")
184 
185   // cartridge
186   MCFG_COCO_CARTRIDGE_ADD(CARTRIDGE_TAG, dragon_state::cartridge_config, dragon_cart, "dragon_fdc", NULL)
187 
188   // acia
189   MCFG_ACIA6551_ADD("acia")
190MACHINE_CONFIG_END
191 
192static MACHINE_CONFIG_DERIVED_CLASS( dgnalpha, dragon_base, dragon_alpha_state )
193   // internal ram
194   MCFG_RAM_ADD(RAM_TAG)
195   MCFG_RAM_DEFAULT_SIZE("64K")
196 
197   // cartridge
198   MCFG_COCO_CARTRIDGE_ADD(CARTRIDGE_TAG, dragon_alpha_state::cartridge_config, dragon_cart, NULL, NULL)
199 
200   // acia
201   MCFG_ACIA6551_ADD("acia")
202 
203   // floppy
204   MCFG_LEGACY_FLOPPY_4_DRIVES_ADD(coco_floppy_interface)
205   MCFG_WD2797_ADD(WD2797_TAG, dragon_alpha_state::fdc_interface)
206 
207   // sound hardware
208   MCFG_SOUND_ADD(AY8912_TAG, AY8912, 1000000)
209   MCFG_SOUND_CONFIG(dragon_alpha_state::ay8912_interface)
210   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.75)
211 
212   // pia 2
213   MCFG_PIA6821_ADD( PIA2_TAG, dragon_alpha_state::pia2_config )
214MACHINE_CONFIG_END
215 
216static MACHINE_CONFIG_DERIVED( tanodr64, dragon_base )
217   // internal ram
218   MCFG_RAM_ADD(RAM_TAG)
219   MCFG_RAM_DEFAULT_SIZE("64K")
220 
221   // cartridge
222   MCFG_COCO_CARTRIDGE_ADD(CARTRIDGE_TAG, dragon_state::cartridge_config, dragon_cart, "sdtandy_fdc", NULL)
223MACHINE_CONFIG_END
224 
225 
226 
227/***************************************************************************
228 
229  Game driver(s)
230 
231***************************************************************************/
232 
233ROM_START(dragon32)
234   ROM_REGION(0xC000, "maincpu",0)
235   ROM_LOAD("d32.rom",      0x0000,  0x4000, CRC(e3879310) SHA1(f2dab125673e653995a83bf6b793e3390ec7f65a))
236ROM_END
237 
238ROM_START(dragon64)
239   ROM_REGION(0x10000,"maincpu",0)
240   ROM_LOAD("d64_1.rom",    0x0000,  0x4000, CRC(60a4634c) SHA1(f119506eaa3b4b70b9aa0dd83761e8cbe043d042))
241   ROM_LOAD("d64_2.rom",    0x8000,  0x4000, CRC(17893a42) SHA1(e3c8986bb1d44269c4587b04f1ca27a70b0aaa2e))
242ROM_END
243 
244ROM_START(d64plus)
245   ROM_REGION(0x10000,"maincpu",0)
246   ROM_LOAD("d64_1.rom",    0x0000,  0x4000, CRC(60a4634c) SHA1(f119506eaa3b4b70b9aa0dd83761e8cbe043d042))
247   ROM_LOAD("d64_2.rom",    0x8000,  0x4000, CRC(17893a42) SHA1(e3c8986bb1d44269c4587b04f1ca27a70b0aaa2e))
248ROM_END
249 
250ROM_START(tanodr64)
251   ROM_REGION(0x10000,"maincpu",0)
252   ROM_LOAD("d64_1.rom",    0x0000,  0x4000, CRC(60a4634c) SHA1(f119506eaa3b4b70b9aa0dd83761e8cbe043d042))
253   ROM_LOAD("d64_2.rom",    0x8000,  0x4000, CRC(17893a42) SHA1(e3c8986bb1d44269c4587b04f1ca27a70b0aaa2e))   
254ROM_END
255 
256ROM_START(dgnalpha)
257   ROM_REGION(0xC000,"maincpu",1)
258   ROM_LOAD("alpha_bt.rom",    0x2000,  0x2000, CRC(c3dab585) SHA1(4a5851aa66eb426e9bb0bba196f1e02d48156068))
259   ROM_LOAD("alpha_ba.rom",    0x8000,  0x4000, CRC(84f68bf9) SHA1(1983b4fb398e3dd9668d424c666c5a0b3f1e2b69))
260ROM_END
261 
262 
263COMP(  1982,    dragon32,   coco,   0,      dragon32,  dragon32,  0,      "Dragon Data Ltd",            "Dragon 32", 0)
264COMP(  1983,    dragon64,   coco,   0,      dragon64,  dragon32,  0,      "Dragon Data Ltd",            "Dragon 64", 0)
265COMP(  1983,    d64plus,    coco,   0,      d64plus,   dragon32,  0,      "Dragon Data Ltd",            "Dragon 64 Plus", 0)
266COMP(  1983,    tanodr64,   coco,   0,      tanodr64,  dragon32,  0,      "Dragon Data Ltd / Tano Ltd", "Tano Dragon 64 (NTSC)", 0)
267COMP(  1984,    dgnalpha,   coco,   0,      dgnalpha,  dragon32,  0,      "Dragon Data Ltd",            "Dragon Alpha Prototype", 0)
No newline at end of file
src/mess/drivers/mc10.c
r13256r13257
1313#include "emu.h"
1414#include "cpu/m6800/m6800.h"
1515#include "sound/dac.h"
16#include "video/m6847.h"
16#include "video/mc6847.h"
1717#include "video/ef9345.h"
1818#include "imagedev/cassette.h"
1919#include "imagedev/printer.h"
r13256r13257
4949   { }
5050
5151   required_device<cpu_device> m_maincpu;
52   optional_device<device_t> m_mc6847;
52   required_device<mc6847_base_device> m_mc6847;
5353   optional_device<ef9345_device> m_ef9345;
5454   required_device<device_t> m_dac;
55   required_device<device_t> m_ram;
55   required_device<ram_device> m_ram;
5656   required_device<cassette_image_device> m_cassette;
5757   required_device<printer_image_device> m_printer;
5858
r13256r13257
126126WRITE8_MEMBER( mc10_state::mc10_bfff_w )
127127{
128128   /* bit 2 to 6, mc6847 mode lines */
129   mc6847_gm2_w(m_mc6847, BIT(data, 2));
130   mc6847_intext_w(m_mc6847, BIT(data, 2));
131   mc6847_gm1_w(m_mc6847, BIT(data, 3));
132   mc6847_gm0_w(m_mc6847, BIT(data, 4));
133   mc6847_ag_w(m_mc6847, BIT(data, 5));
134   mc6847_css_w(m_mc6847, BIT(data, 6));
129   m_mc6847->gm2_w(BIT(data, 2));
130   m_mc6847->intext_w(BIT(data, 2));
131   m_mc6847->gm1_w(BIT(data, 3));
132   m_mc6847->gm0_w(BIT(data, 4));
133   m_mc6847->ag_w(BIT(data, 5));
134   m_mc6847->css_w(BIT(data, 6));
135135
136136   /* bit 7, dac output */
137137   dac_data_w(m_dac, BIT(data, 7));
r13256r13257
218218
219219READ8_MEMBER( mc10_state::mc10_mc6847_videoram_r )
220220{
221   mc6847_inv_w(m_mc6847, BIT(m_ram_base[offset], 6));
222   mc6847_as_w(m_mc6847, BIT(m_ram_base[offset], 7));
221   m_mc6847->inv_w(BIT(m_ram_base[offset], 6));
222   m_mc6847->as_w(BIT(m_ram_base[offset], 7));
223223
224224   return m_ram_base[offset];
225225}
r13256r13257
227227bool mc10_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
228228{
229229   if (m_mc6847)      //mc10, alice
230      return mc6847_update(m_mc6847, &bitmap, &cliprect);
230      return m_mc6847->update(&bitmap, &cliprect);
231231   else if (m_ef9345)   //alice32
232232      m_ef9345->video_update(&bitmap, &cliprect);
233233
r13256r13257
254254   mc10->m_keyboard_strobe = 0x00;
255255
256256   /* initialize memory */
257   mc10->m_ram_base = ram_get_ptr(mc10->m_ram);
258   mc10->m_ram_size = ram_get_size(mc10->m_ram);
257   mc10->m_ram_base = mc10->m_ram->pointer();
258   mc10->m_ram_size = mc10->m_ram->size();
259259   mc10->m_pr_state = PRINTER_WAIT;
260260
261261   memory_set_bankptr(machine, "bank1", mc10->m_ram_base);
r13256r13257
405405   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("/  ?  SQR")          PORT_CODE(KEYCODE_SLASH)      PORT_CHAR('/')  PORT_CHAR('?')
406406   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("SHIFT")              PORT_CODE(KEYCODE_RSHIFT)     PORT_CHAR(UCHAR_SHIFT_1)
407407   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_UNUSED)
408
409   PORT_INCLUDE( m6847_artifacting )
410408INPUT_PORTS_END
411409
412410/* Alice uses an AZERTY keyboard */
r13256r13257
486484   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME(";  +  POKE")         PORT_CODE(KEYCODE_COLON)      PORT_CHAR(';')  PORT_CHAR('+')
487485   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("SHIFT")              PORT_CODE(KEYCODE_RSHIFT)     PORT_CHAR(UCHAR_SHIFT_1)
488486   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_UNUSED)
489
490   PORT_INCLUDE( m6847_artifacting )
491487INPUT_PORTS_END
492488
493489
r13256r13257
515511
516512static const mc6847_interface mc10_mc6847_intf =
517513{
518   DEVCB_DRIVER_MEMBER(mc10_state, mc10_mc6847_videoram_r),
519   DEVCB_NULL,
520   DEVCB_NULL,
521   DEVCB_NULL,
522   DEVCB_NULL,
523   DEVCB_NULL,
524   DEVCB_NULL,
525   DEVCB_NULL,
526   DEVCB_NULL,
527   DEVCB_NULL,
528   DEVCB_NULL,
529   DEVCB_NULL
514   "screen",
515   DEVCB_DRIVER_MEMBER(mc10_state, mc10_mc6847_videoram_r)
530516};
531517
532518static MACHINE_CONFIG_START( mc10, mc10_state )
r13256r13257
535521   MCFG_CPU_ADD("maincpu", M6803, XTAL_3_579545MHz)  /* 0,894886 MHz */
536522   MCFG_CPU_PROGRAM_MAP(mc10_mem)
537523   MCFG_CPU_IO_MAP(mc10_io)
538   MCFG_SCREEN_ADD("screen", RASTER)
539   MCFG_SCREEN_REFRESH_RATE(60)
540524
541525   /* video hardware */
542   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
543   MCFG_SCREEN_SIZE(320, 25+192+26)
544   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
526   MCFG_SCREEN_MC6847_NTSC_ADD("screen")
527   MCFG_MC6847_ADD("mc6847", MC6847_NTSC, XTAL_3_579545MHz, mc10_mc6847_intf)
545528
546   MCFG_MC6847_ADD("mc6847", mc10_mc6847_intf)
547   MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_NTSC)
548
549529   /* sound hardware */
550530   MCFG_SPEAKER_STANDARD_MONO("mono")
551531   MCFG_SOUND_ADD("dac", DAC, 0)
src/mess/drivers/atom.c
r13256r13257
348348
349349bool atom_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
350350{
351   return mc6847_update(m_vdg, &bitmap, &cliprect);
351   return m_vdg->update(&bitmap, &cliprect);
352352}
353353
354354/***************************************************************************
r13256r13257
380380   m_keylatch = data & 0x0f;
381381
382382   /* MC6847 */
383   mc6847_ag_w(m_vdg, BIT(data, 4));
384   mc6847_gm0_w(m_vdg, BIT(data, 5));
385   mc6847_gm1_w(m_vdg, BIT(data, 6));
386   mc6847_gm2_w(m_vdg, BIT(data, 7));
383   m_vdg->ag_w(BIT(data, 4));
384   m_vdg->gm0_w(BIT(data, 5));
385   m_vdg->gm1_w(BIT(data, 6));
386   m_vdg->gm2_w(BIT(data, 7));
387387}
388388
389389READ8_MEMBER( atom_state::ppi_pb_r )
r13256r13257
453453   data |= BIT(input_port_read(machine(), "RPT"), 0) << 6;
454454
455455   /* MC6847 FS */
456   data |= mc6847_fs_r(m_vdg) << 7;
456   data |= (m_vdg->fs_r() ? 1 : 0) << 7;
457457
458458   return data;
459459}
r13256r13257
483483   speaker_level_w(m_speaker, BIT(data, 2));
484484
485485   /* MC6847 CSS */
486   mc6847_css_w(m_vdg, BIT(data, 3));
486   m_vdg->css_w(BIT(data, 3));
487487}
488488
489489static I8255_INTERFACE( ppi_intf )
r13256r13257
632632
633633READ8_MEMBER( atom_state::vdg_videoram_r )
634634{
635   mc6847_as_w(m_vdg, BIT(m_video_ram[offset], 6));
636   mc6847_intext_w(m_vdg, BIT(m_video_ram[offset], 6));
637   mc6847_inv_w(m_vdg, BIT(m_video_ram[offset], 7));
635   m_vdg->as_w(BIT(m_video_ram[offset], 6));
636   m_vdg->intext_w(BIT(m_video_ram[offset], 6));
637   m_vdg->inv_w(BIT(m_video_ram[offset], 7));
638638
639639   return m_video_ram[offset];
640640}
641641
642642static const mc6847_interface vdg_intf =
643643{
644   DEVCB_DRIVER_MEMBER(atom_state, vdg_videoram_r),
645   DEVCB_NULL,
646   DEVCB_NULL,
647   DEVCB_NULL,
648   DEVCB_NULL,
649   DEVCB_NULL,
650   DEVCB_NULL,
651   DEVCB_NULL,
652   DEVCB_NULL,
653   DEVCB_NULL,
654   DEVCB_NULL,
655   DEVCB_NULL
644   SCREEN_TAG,
645   DEVCB_DRIVER_MEMBER(atom_state, vdg_videoram_r)
656646};
657647
658648/***************************************************************************
r13256r13257
797787   MCFG_CPU_PROGRAM_MAP(atom_mem)
798788
799789   /* video hardware */
800   MCFG_SCREEN_ADD(SCREEN_TAG, RASTER)
801   MCFG_SCREEN_REFRESH_RATE(M6847_PAL_FRAMES_PER_SECOND)
802   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
803   MCFG_SCREEN_SIZE(320, 25+192+26)
804   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
790    MCFG_SCREEN_MC6847_PAL_ADD(SCREEN_TAG)
791   MCFG_MC6847_ADD(MC6847_TAG, MC6847_PAL, XTAL_4_433619MHz, vdg_intf)
805792
806   MCFG_MC6847_ADD(MC6847_TAG, vdg_intf)
807   MCFG_MC6847_TYPE(M6847_VERSION_ORIGINAL_PAL)
808
809793   /* sound hardware */
810794   MCFG_SPEAKER_STANDARD_MONO("mono")
811795   MCFG_SOUND_ADD(SPEAKER_TAG, SPEAKER_SOUND, 0)
src/mess/drivers/apf.c
r13256r13257
5151
5252#include "emu.h"
5353#include "cpu/m6800/m6800.h"
54#include "video/m6847.h"
54#include "video/mc6847.h"
5555#include "sound/speaker.h"
5656#include "sound/wave.h"
5757#include "machine/6821pia.h"
r13256r13257
7878   { }
7979
8080   required_device<cpu_device> m_maincpu;
81   required_device<device_t> m_crtc;
81   required_device<mc6847_base_device> m_crtc;
8282   required_device<device_t> m_speaker;
8383   required_device<device_t> m_pia0;
8484   optional_device<device_t> m_pia1;
r13256r13257
127127   UINT8 *m_p_videoram;
128128   UINT8 m_apf_ints;
129129   void apf_update_ints(UINT8 intnum);
130
131protected:
132   virtual bool screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect);
130133};
131134
132135
133
134136READ8_MEMBER( apf_state::apf_mc6847_videoram_r )
135137{
136   mc6847_css_w(m_crtc, m_mc6847_css && BIT(m_p_videoram[offset + 0x200], 6));
137   mc6847_inv_w(m_crtc, BIT(m_p_videoram[offset + 0x200], 6));
138   mc6847_as_w(m_crtc, BIT(m_p_videoram[offset + 0x200], 7));
138   m_crtc->css_w(m_mc6847_css && BIT(m_p_videoram[offset + 0x200], 6));
139   m_crtc->inv_w(BIT(m_p_videoram[offset + 0x200], 6));
140   m_crtc->as_w(BIT(m_p_videoram[offset + 0x200], 7));
139141
140142   return m_p_videoram[offset + 0x200];
141143}
r13256r13257
145147   apf_update_ints(0x10);
146148}
147149
148static SCREEN_UPDATE( apf )
150bool apf_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
149151{
150   device_t *mc6847 = screen->machine().device("mc6847");
151   return mc6847_update(mc6847, bitmap, cliprect);
152   return m_crtc->update(&bitmap, &cliprect);
152153}
153154
154155READ8_MEMBER( apf_state::apf_m1000_pia_in_a_func)
r13256r13257
202203WRITE8_MEMBER( apf_state::apf_m1000_pia_out_b_func )
203204{
204205   /* bit 7..4 video control -- TODO: bit 5 and 4? */
205   mc6847_ag_w(m_crtc, BIT(data, 7));
206   mc6847_gm0_w(m_crtc, BIT(data, 6));
206   m_crtc->ag_w(BIT(data, 7));
207   m_crtc->gm0_w(BIT(data, 6));
207208
208209   /* bit 3..0 keypad line select */
209210   m_pad_data = data;
r13256r13257
232233   else
233234      m_apf_ints &= ~intnum;
234235
235   cputag_set_input_line(machine(), "maincpu", 0, m_apf_ints ? HOLD_LINE : CLEAR_LINE);
236   m_maincpu->set_input_line(0, m_apf_ints ? HOLD_LINE : CLEAR_LINE);
236237}
237238
238239WRITE_LINE_MEMBER( apf_state::apf_m1000_irq_a_func )
r13256r13257
691692
692693static const mc6847_interface apf_mc6847_intf =
693694{
695   "screen",
694696   DEVCB_DRIVER_MEMBER(apf_state, apf_mc6847_videoram_r),
695   DEVCB_LINE_VCC,
696   DEVCB_LINE_VCC,
697697   DEVCB_NULL,
698   DEVCB_NULL,
699   DEVCB_NULL,
700   DEVCB_NULL,
701   DEVCB_NULL,
702   DEVCB_NULL,
703   DEVCB_DRIVER_LINE_MEMBER(apf_state, apf_mc6847_fs_w),
704   DEVCB_NULL,
705   DEVCB_NULL
698   DEVCB_DRIVER_LINE_MEMBER(apf_state, apf_mc6847_fs_w)
706699};
707700
708701static MACHINE_CONFIG_START( apf_imagination, apf_state )
r13256r13257
715708   MCFG_MACHINE_START( apf_imagination )
716709
717710   /* video hardware */
718   MCFG_SCREEN_ADD("screen", RASTER)
719   MCFG_SCREEN_REFRESH_RATE(M6847_NTSC_FRAMES_PER_SECOND)
720   MCFG_SCREEN_UPDATE(apf)
721   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
722   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
723   MCFG_SCREEN_SIZE(320, 25+192+26)
724   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
711   MCFG_SCREEN_MC6847_NTSC_ADD("screen")
712   MCFG_MC6847_ADD("mc6847", MC6847_NTSC, XTAL_3_579545MHz, apf_mc6847_intf)
725713
726714   /* sound hardware */
727715   MCFG_SPEAKER_STANDARD_MONO("mono")
r13256r13257
731719   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
732720
733721   /* Devices */
734   MCFG_MC6847_ADD("mc6847", apf_mc6847_intf)
735722   MCFG_PIA6821_ADD( "pia_0", apf_m1000_pia_interface )
736723   MCFG_PIA6821_ADD( "pia_1", apf_imagination_pia_interface )
737724   MCFG_CASSETTE_ADD( CASSETTE_TAG, apf_cassette_interface )
src/mess/drivers/coco3.c
r0r13257
1/***************************************************************************
2 
3    coco3.c
4 
5    TRS-80 Radio Shack Color Computer 3
6 
7    Mathis Rosenhauer (original driver)
8    Nate Woods (current maintainer)
9    Tim Lindner (VHD and other work)
10 
11***************************************************************************/
12 
13#include "includes/coco3.h"
14#include "cpu/m6809/m6809.h"
15#include "cpu/hd6309/hd6309.h"
16#include "coco3.lh"
17 
18 
19 
20//**************************************************************************
21//  ADDRESS MAPS
22//**************************************************************************
23 
24//-------------------------------------------------
25//  ADDRESS_MAP( coco3_mem )
26//-------------------------------------------------
27 
28static ADDRESS_MAP_START( coco3_mem, AS_PROGRAM, 8, coco3_state )
29   AM_RANGE(0x0000, 0x1FFF) AM_READ_BANK("rbank0") AM_WRITE_BANK("wbank0")
30   AM_RANGE(0x2000, 0x3FFF) AM_READ_BANK("rbank1") AM_WRITE_BANK("wbank1")
31   AM_RANGE(0x4000, 0x5FFF) AM_READ_BANK("rbank2") AM_WRITE_BANK("wbank2")
32   AM_RANGE(0x6000, 0x7FFF) AM_READ_BANK("rbank3") AM_WRITE_BANK("wbank3")
33   AM_RANGE(0x8000, 0x9FFF) AM_READ_BANK("rbank4") AM_WRITE_BANK("wbank4")
34   AM_RANGE(0xA000, 0xBFFF) AM_READ_BANK("rbank5") AM_WRITE_BANK("wbank5")
35   AM_RANGE(0xC000, 0xDFFF) AM_READ_BANK("rbank6") AM_WRITE_BANK("wbank6")
36   AM_RANGE(0xE000, 0xFDFF) AM_READ_BANK("rbank7") AM_WRITE_BANK("wbank7")
37   AM_RANGE(0xFE00, 0xFEFF) AM_READ_BANK("rbank8") AM_WRITE_BANK("wbank8")
38   AM_RANGE(0xFF00, 0xFF1F) AM_READWRITE(ff00_read, ff00_write)
39   AM_RANGE(0xFF20, 0xFF3F) AM_READWRITE(ff20_read, ff20_write)
40   AM_RANGE(0xFF40, 0xFF5F) AM_READWRITE(ff40_read, ff40_write)
41   AM_RANGE(0xFF60, 0xFF8F) AM_READWRITE(ff60_read, ff60_write)
42   AM_RANGE(0xFF90, 0xFFDF) AM_DEVREADWRITE(GIME_TAG, gime_base_device, read, write)
43   AM_RANGE(0xFFE0, 0xFFFF) AM_ROM AM_REGION(MAINCPU_TAG, 0x3FE0)
44ADDRESS_MAP_END
45 
46 
47 
48//**************************************************************************
49//  INPUT PORTS
50//**************************************************************************
51 
52//-------------------------------------------------
53//  INPUT_PORTS( coco3_keyboard )
54//-------------------------------------------------
55//
56//   CoCo 3 keyboard
57//   
58//          PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7
59//     PA6: Ent Clr Brk Alt Ctr F1  F2 Shift
60//     PA5: 8   9   :   ;   ,   -   .   /
61//     PA4: 0   1   2   3   4   5   6   7
62//     PA3: X   Y   Z   Up  Dwn Lft Rgt Space
63//     PA2: P   Q   R   S   T   U   V   W
64//     PA1: H   I   J   K   L   M   N   O
65//     PA0: @   A   B   C   D   E   F   G
66//-------------------------------------------------
67 
68static INPUT_PORTS_START( coco3_keyboard )
69   PORT_START("row0")
70   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_ASTERISK) PORT_CHAR('@')
71   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_A) PORT_CHAR('A')
72   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_B) PORT_CHAR('B')
73   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_C) PORT_CHAR('C')
74   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_D) PORT_CHAR('D')
75   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_E) PORT_CHAR('E')
76   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_F) PORT_CHAR('F')
77   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_G) PORT_CHAR('G')
78 
79   PORT_START("row1")
80   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_H) PORT_CHAR('H')
81   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_I) PORT_CHAR('I')
82   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_J) PORT_CHAR('J')
83   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_K) PORT_CHAR('K')
84   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_L) PORT_CHAR('L')
85   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_M) PORT_CHAR('M')
86   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_N) PORT_CHAR('N')
87   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_O) PORT_CHAR('O')
88 
89   PORT_START("row2")
90   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_P) PORT_CHAR('P')
91   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_Q) PORT_CHAR('Q')
92   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_R) PORT_CHAR('R')
93   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_S) PORT_CHAR('S')
94   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_T) PORT_CHAR('T')
95   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_U) PORT_CHAR('U')
96   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_V) PORT_CHAR('V')
97   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_W) PORT_CHAR('W')
98 
99   PORT_START("row3")
100   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_X) PORT_CHAR('X')
101   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_Y) PORT_CHAR('Y')
102   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_Z) PORT_CHAR('Z')
103   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("UP") PORT_CODE(KEYCODE_UP) PORT_CHAR('^')
104   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("DOWN") PORT_CODE(KEYCODE_DOWN) PORT_CHAR(10)
105   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("LEFT") PORT_CODE(KEYCODE_LEFT) PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8)
106   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("RIGHT") PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(9)
107   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("SPACE") PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')
108 
109   PORT_START("row4")
110   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0) PORT_CHAR('0')
111   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')
112   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('\"')
113   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')
114   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')
115   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')
116   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')
117   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
118 
119   PORT_START("row5")
120   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('(')
121   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR(')')
122   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_COLON) PORT_CHAR(':') PORT_CHAR('*')
123   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR(';') PORT_CHAR('+')
124   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<')
125   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('=') PORT_CHAR('_')
126   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>')
127   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')
128 
129   PORT_START("row6")
130   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("ENTER") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
131   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("CLEAR") PORT_CODE(KEYCODE_HOME) PORT_CHAR(12)
132   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("BREAK") PORT_CODE(KEYCODE_END) PORT_CODE(KEYCODE_ESC) PORT_CHAR(27)
133   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("ALT") PORT_CODE(KEYCODE_LALT)
134   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("CTRL") PORT_CODE(KEYCODE_LCONTROL) PORT_CHAR(UCHAR_SHIFT_2)
135   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1))
136   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F2))
137   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_NAME("SHIFT") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
138INPUT_PORTS_END
139 
140 
141 
142//-------------------------------------------------
143//  INPUT_PORTS( coco3_joystick )
144//-------------------------------------------------
145 
146static INPUT_PORTS_START( coco3_joystick )
147   PORT_START(JOYSTICK_RX_TAG)
148   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_4_PAD) PORT_CODE_INC(KEYCODE_6_PAD) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x01)
149   PORT_START(JOYSTICK_RY_TAG)
150   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_8_PAD) PORT_CODE_INC(KEYCODE_2_PAD) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH)   PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x01)
151   PORT_START(JOYSTICK_LX_TAG)
152   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_4_PAD) PORT_CODE_INC(KEYCODE_6_PAD) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x10)
153   PORT_START(JOYSTICK_LY_TAG)
154   PORT_BIT( 0xff, 0x80,  IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xFF) PORT_CODE_DEC(KEYCODE_8_PAD) PORT_CODE_INC(KEYCODE_2_PAD) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH)   PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x10)
155   PORT_START(JOYSTICK_BUTTONS_TAG)
156   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Right Button 1") PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x01)
157   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Right Button 1") PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x01)
158   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Left Button 1")  PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x10)
159   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Left Button 1")  PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x10)
160INPUT_PORTS_END
161 
162 
163 
164//-------------------------------------------------
165//  INPUT_PORTS( coco_rat_mouse )
166//-------------------------------------------------
167 
168static INPUT_PORTS_START( coco_rat_mouse )
169   PORT_START(RAT_MOUSE_RX_TAG)
170   PORT_BIT( 0x03, 0x00,  IPT_MOUSE_X) PORT_NAME("Rat Mouse X (Right Port)") PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1)  PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x02)
171   PORT_START(RAT_MOUSE_RY_TAG)
172   PORT_BIT( 0x03, 0x00,  IPT_MOUSE_Y) PORT_NAME("Rat Mouse Y (Right Port)") PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x02)
173   PORT_START(RAT_MOUSE_LX_TAG)
174   PORT_BIT( 0x03, 0x00,  IPT_MOUSE_X) PORT_NAME("Rat Mouse X (Left Port)") PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2)  PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x20)
175   PORT_START(RAT_MOUSE_LY_TAG)
176   PORT_BIT( 0x03, 0x00,  IPT_MOUSE_Y) PORT_NAME("Rat Mouse Y (Left Port)") PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH) PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x20)
177   PORT_START(RAT_MOUSE_BUTTONS_TAG)
178   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Rat Mouse Button 1 (Right Port)") PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x02)
179   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Rat Mouse Button 2 (Right Port)") PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x02)
180   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Rat Mouse Button 1 (Left Port)")  PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x20)
181   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Rat Mouse Button 2 (Left Port)")  PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x20)
182INPUT_PORTS_END
183 
184 
185 
186//-------------------------------------------------
187//  INPUT_PORTS( coco_lightgun )
188//-------------------------------------------------
189 
190static INPUT_PORTS_START( coco_lightgun )
191   PORT_START(DIECOM_LIGHTGUN_RX_TAG)
192   PORT_BIT( 0x1ff, 266, IPT_LIGHTGUN_X ) PORT_NAME("Lightgun X (Right Port)") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_MINMAX(116,416) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x03)
193   PORT_START(DIECOM_LIGHTGUN_RY_TAG)
194   PORT_BIT( 0xff, 121, IPT_LIGHTGUN_Y ) PORT_NAME("Lightgun Y (Right Port)") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_MINMAX(0,242) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x03)
195   PORT_START(DIECOM_LIGHTGUN_LX_TAG)
196   PORT_BIT( 0x1ff, 266, IPT_LIGHTGUN_X ) PORT_NAME("Lightgun X (Left Port)") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_MINMAX(116,416) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x30)
197   PORT_START(DIECOM_LIGHTGUN_LY_TAG)
198   PORT_BIT( 0xff, 121, IPT_LIGHTGUN_Y ) PORT_NAME("Lightgun Y (Left Port)") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_MINMAX(0,242) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x30)
199   PORT_START(DIECOM_LIGHTGUN_BUTTONS_TAG)
200   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Lightgun Trigger (Right Port)") PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(1) PORT_CONDITION(CTRL_SEL_TAG, 0x0f, PORTCOND_EQUALS, 0x03)
201   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Lightgun Trigger (Left Port)")  PORT_CHANGED(coco_state::keyboard_changed, NULL) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_PLAYER(2) PORT_CONDITION(CTRL_SEL_TAG, 0xf0, PORTCOND_EQUALS, 0x30)
202INPUT_PORTS_END
203 
204 
205 
206//-------------------------------------------------
207//  INPUT_PORTS( coco_rtc )
208//-------------------------------------------------
209 
210static INPUT_PORTS_START( coco_rtc )
211   PORT_START("real_time_clock")
212   PORT_CONFNAME( 0x03, 0x00, "Real Time Clock" )
213   PORT_CONFSETTING(    0x00, "Disto" )
214   PORT_CONFSETTING(    0x01, "Cloud-9" )
215INPUT_PORTS_END
216 
217 
218 
219//-------------------------------------------------
220//  INPUT_PORTS( coco3 )
221//-------------------------------------------------
222 
223static INPUT_PORTS_START( coco3 )
224   PORT_INCLUDE( coco3_keyboard )
225   PORT_INCLUDE( coco3_joystick )
226   PORT_INCLUDE( coco_analog_control )
227   PORT_INCLUDE( coco_cart_autostart )
228   PORT_INCLUDE( coco_rat_mouse )
229   PORT_INCLUDE( coco_lightgun )
230   PORT_INCLUDE( coco_rtc )
231INPUT_PORTS_END
232 
233 
234//**************************************************************************
235//  MACHINE CONFIGURATION
236//**************************************************************************
237 
238static const gime_interface coco_gime_config =
239{
240   /* device tags */
241   SCREEN_TAG,
242   MAINCPU_TAG,
243   RAM_TAG,
244   CARTRIDGE_TAG,
245 
246   DEVCB_DEVICE_LINE_MEMBER(PIA0_TAG, pia6821_device, ca1_w),   /* horizontal sync */
247   DEVCB_DEVICE_LINE_MEMBER(PIA0_TAG, pia6821_device, cb1_w),   /* field sync */
248   DEVCB_DRIVER_LINE_MEMBER(coco3_state, gime_irq_w),
249   DEVCB_DRIVER_LINE_MEMBER(coco3_state, gime_firq_w)
250};
251 
252static MACHINE_CONFIG_START( coco3, coco3_state )
253   // basic machine hardware
254   MCFG_CPU_ADD(MAINCPU_TAG, M6809E, XTAL_3_579545MHz)
255   MCFG_CPU_PROGRAM_MAP(coco3_mem)
256 
257   // devices
258   MCFG_PIA6821_ADD(PIA0_TAG, coco_state::pia0_config)
259   MCFG_PIA6821_ADD(PIA1_TAG, coco_state::pia1_config)
260   MCFG_CASSETTE_ADD(CASSETTE_TAG, coco_state::coco_cassette_interface)
261   MCFG_BITBANGER_ADD(BITBANGER_TAG, coco_state::coco_bitbanger_config)
262   MCFG_COCO_CARTRIDGE_ADD(CARTRIDGE_TAG, coco_state::cartridge_config, coco_cart, "fdcv11", NULL)
263   MCFG_COCO_VHD_ADD(VHD_TAG)
264 
265   // video hardware
266   MCFG_DEVICE_ADD(GIME_TAG, GIME_NTSC, XTAL_3_579545MHz)
267   MCFG_DEVICE_CONFIG(coco_gime_config)
268   MCFG_DEFAULT_LAYOUT(layout_coco3)
269 
270   // composite monitor
271   MCFG_SCREEN_ADD(COMPOSITE_SCREEN_TAG, RASTER)
272   MCFG_SCREEN_REFRESH_RATE(60)
273   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
274   MCFG_SCREEN_SIZE(640, 243)
275   MCFG_SCREEN_VISIBLE_AREA(0, 640-1, 1, 241-1)
276   MCFG_SCREEN_VBLANK_TIME(0)
277 
278   // RGB monitor
279   MCFG_SCREEN_ADD(RGB_SCREEN_TAG, RASTER)
280   MCFG_SCREEN_REFRESH_RATE(60)
281   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
282   MCFG_SCREEN_SIZE(640, 243)
283   MCFG_SCREEN_VISIBLE_AREA(0, 640-1, 1, 241-1)
284   MCFG_SCREEN_VBLANK_TIME(0)
285 
286   // sound hardware
287   MCFG_FRAGMENT_ADD( coco_sound )
288 
289   // internal ram
290   MCFG_RAM_ADD(RAM_TAG)
291   MCFG_RAM_DEFAULT_SIZE("512K")
292   MCFG_RAM_EXTRA_OPTIONS("128K,2M,8M")
293 
294   // software lists
295   MCFG_SOFTWARE_LIST_ADD("cart_list","coco_cart")
296MACHINE_CONFIG_END
297 
298static MACHINE_CONFIG_DERIVED( coco3p, coco3 )
299   MCFG_CPU_REPLACE(MAINCPU_TAG, HD6309, XTAL_4_433619MHz)
300   MCFG_DEVICE_REPLACE(GIME_TAG, GIME_PAL, XTAL_4_433619MHz)
301MACHINE_CONFIG_END
302 
303static MACHINE_CONFIG_DERIVED( coco3h, coco3 )
304   MCFG_CPU_REPLACE(MAINCPU_TAG, HD6309, XTAL_3_579545MHz)
305   MCFG_CPU_PROGRAM_MAP(coco3_mem)
306MACHINE_CONFIG_END
307 
308 
309 
310//**************************************************************************
311//  ROMS
312//**************************************************************************
313 
314ROM_START(coco3)
315   ROM_REGION(0x8000,MAINCPU_TAG,0)
316   ROM_LOAD("coco3.rom",   0x0000, 0x8000, CRC(b4c88d6c) SHA1(e0d82953fb6fd03768604933df1ce8bc51fc427d))
317ROM_END
318 
319ROM_START(coco3p)
320   ROM_REGION(0x8000,MAINCPU_TAG,0)
321   ROM_LOAD("coco3p.rom",   0x0000, 0x8000, CRC(ff050d80) SHA1(631e383068b1f52a8f419f4114b69501b21cf379))
322ROM_END
323 
324#define rom_coco3h   rom_coco3
325 
326 
327 
328//**************************************************************************
329//  SYSTEM DRIVERS
330//**************************************************************************
331 
332COMP(  1986,    coco3,      coco,   0,      coco3,     coco3,     0,      "Tandy Radio Shack",            "Color Computer 3 (NTSC)", 0)
333COMP(  1986,    coco3p,     coco,   0,      coco3p,    coco3,     0,      "Tandy Radio Shack",            "Color Computer 3 (PAL)", 0)
334COMP(  19??,    coco3h,     coco,   0,      coco3h,    coco3,     0,      "Tandy Radio Shack",            "Color Computer 3 (NTSC; HD6309)", GAME_UNOFFICIAL)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team