Previous 15994 Revisions Next

r9430 Thursday 21st October, 2010 at 16:11:04 UTC by Tim Lindner
Changed bitbanger to be bi-directional. Added UI to change bitbanger options. Connected new bitbanger to CoCo drivers. Fixed reading on pia1, port a to reflect what was previously written. [tim lindner]
[docs]messnew.txt
[src/mess]uimess.c uimess.h
[src/mess/devices]bitbngr.c bitbngr.h
[src/mess/drivers]coco.c
[src/mess/includes]coco.h
[src/mess/machine]coco.c

src/mess/devices/bitbngr.c
r9429r9430
66
77*********************************************************************/
88
9#include <math.h>
10
119#include "emu.h"
1210#include "bitbngr.h"
13#include "printer.h"
1411
1512
1613
r9429r9430
2118typedef struct _bitbanger_token bitbanger_token;
2219struct _bitbanger_token
2320{
24   double last_pulse_time;
25   double *pulses;
26   int *factored_pulses;
27   int recorded_pulses;
28   int value;
29   emu_timer *timeout_timer;
30   int over_threshhold;
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   UINT8 *input_buffer;
29   UINT32 input_buffer_size;
30   UINT32 input_buffer_cursor;
31   int mode;
32   int baud;
33   int tune;
3134};
3235
3336
r9429r9430
3639    FUNCTION PROTOTYPES
3740***************************************************************************/
3841
39static TIMER_CALLBACK(bitbanger_overthreshhold);
42static TIMER_CALLBACK(bitbanger_output_timer);
43static TIMER_CALLBACK(bitbanger_input_timer);
4044
4145
4246
r9429r9430
4448    INLINE FUNCTIONS
4549***************************************************************************/
4650
51
4752/*-------------------------------------------------
4853    get_token - safely gets the bitbanger data
4954-------------------------------------------------*/
r9429r9430
5661}
5762
5863
59
6064/*-------------------------------------------------
6165    get_config - safely gets the bitbanger config
6266-------------------------------------------------*/
r9429r9430
7478    IMPLEMENTATION
7579***************************************************************************/
7680
81
7782/*-------------------------------------------------
78    DEVICE_START(bitbanger)
83    native_output - outputs data to a file
7984-------------------------------------------------*/
8085
81static DEVICE_START(bitbanger)
86void native_output(running_device *bitbanger, UINT8 data)
8287{
83   bitbanger_token *bi;
84   const bitbanger_config *config = get_config(device);
88   device_image_interface *image = dynamic_cast<device_image_interface *>(bitbanger);
89   if (image->exists())
90   {
91      image->fwrite(&data, 1);
92   }
93}
8594
86   bi = get_token(device);
87   bi->pulses = auto_alloc_array(device->machine, double, config->maximum_pulses);
88   bi->factored_pulses = auto_alloc_array(device->machine, int, config->maximum_pulses);
89   bi->last_pulse_time = 0.0;
90   bi->recorded_pulses = 0;
91   bi->value = config->initial_value;
92   bi->timeout_timer = timer_alloc(device->machine, bitbanger_overthreshhold, (void *) device);
93   bi->over_threshhold = 1;
95
96/*-------------------------------------------------
97    native_input - inputs data from a file
98-------------------------------------------------*/
99
100UINT32 native_input(running_device *bitbanger, void *buffer, UINT32 length)
101{
102   device_image_interface *image = dynamic_cast<device_image_interface *>(bitbanger);
103   if (image->exists())
104   {
105      return image->fread(buffer, length);
106   }
107
108   return 0;
94109}
95110
96111
112/*-------------------------------------------------
113    bitbanger_mode_string
114-------------------------------------------------*/
115const char *bitbanger_mode_string(running_device *device)
116{
117   bitbanger_token *bi = get_token(device);
118   static const char *modes[] = {"Printer", "Modem"};
97119
120   return(modes[bi->mode]);
121}
122
123
98124/*-------------------------------------------------
99    bitbanger_analyze
125    bitbanger_inc_mode
100126-------------------------------------------------*/
127bool bitbanger_inc_mode(running_device *device, bool test)
128{
129   bitbanger_token *bi = get_token(device);
130   int adjust_mode = (int)bi->mode + 1;
101131
102static void bitbanger_analyze(running_device *device)
132   if( adjust_mode >= BITBANGER_MODE_MAX )
133      return FALSE;
134
135   if( !test)
136      bi->mode = adjust_mode;
137
138   return TRUE;
139}
140
141
142/*-------------------------------------------------
143    bitbanger_dec_mode
144-------------------------------------------------*/
145bool bitbanger_dec_mode(running_device *device, bool test)
103146{
104   int i, factor, total_duration;
105   double smallest_pulse;
106   double d;
107147   bitbanger_token *bi = get_token(device);
108   const bitbanger_config *config = get_config(device);
148   int adjust_mode = bi->mode - 1;
109149
110   /* compute the smallest pulse */
111   smallest_pulse = config->pulse_threshhold;
112   for (i = 0; i < bi->recorded_pulses; i++)
113      if (smallest_pulse > bi->pulses[i])
114         smallest_pulse = bi->pulses[i];
150   if( adjust_mode < 0 )
151      return FALSE;
115152
116   /* figure out what factor the smallest pulse was */
117   factor = 0;
118   do
119   {
120      factor++;
121      total_duration = 0;
153   if( !test)
154      bi->mode = adjust_mode;
122155
123      for (i = 0; i < bi->recorded_pulses; i++)
124      {
125         d = bi->pulses[i] / smallest_pulse * factor + config->pulse_tolerance;
126         if ((i < (bi->recorded_pulses-1)) && (d - floor(d)) >= (config->pulse_tolerance * 2))
127         {
128            i = -1;
129            break;
130         }
131         bi->factored_pulses[i] = (int) d;
132         total_duration += (int) d;
133      }
134   }
135   while((i == -1) && (factor < config->maximum_pulses));
136   if (i == -1)
137      return;
156   return TRUE;
157}
138158
139   /* filter the output */
140   if (config->filter(device, bi->factored_pulses, bi->recorded_pulses, total_duration))
141      bi->recorded_pulses = 0;
159
160/*-------------------------------------------------
161    bitbanger_tune_string
162-------------------------------------------------*/
163const char *bitbanger_tune_string(running_device *device)
164{
165   bitbanger_token *bi = get_token(device);
166   static const char *tunes[] = {"-2.0%", "-1.75%", "-1.5%", "-1.25%", "-1.0%", "-0.75%", "-0.5", "-0.25%", "\xc2\xb1""0%",
167                                 "+0.25%",  "+0.5%", "+0.75%", "+1.0%", "+1.25%", "+1.5%", "+1.75%", "+2.0%"};
168
169   return(tunes[bi->tune]);
142170}
143171
144172
173/*-------------------------------------------------
174    bitbanger_tune_value
175-------------------------------------------------*/
176float bitbanger_tune_value(running_device *device)
177{
178   bitbanger_token *bi = get_token(device);
179   float tunes[] = {0.97, 0.9825, 0.985, 0.9875, 0.99, 0.9925, 0.995, 0.9975, 1.0,
180                  1.0025, 1.005, 1.0075, 1.01, 1.0125, 1.015, 1.0175, 1.02};
145181
182   return(tunes[bi->tune]);
183}
184
185
146186/*-------------------------------------------------
147    bitbanger_addpulse
187    bitbanger_baud_value
148188-------------------------------------------------*/
149189
150static void bitbanger_addpulse(running_device *device, double pulse_width)
190UINT32 bitbanger_baud_value(running_device *device)
151191{
152192   bitbanger_token *bi = get_token(device);
193   float bauds[] = { 150.0, 300.0, 600.0, 1200.0, 2400.0, 4800.0, 9600.0,
194            14400.0, 28800.0, 38400.0, 57600.0, 115200.0};
195   float result = bitbanger_tune_value(device) * bauds[bi->baud];
196   return (UINT32)result;
197}
198
199
200/*-------------------------------------------------
201    bitbanger_baud_string
202-------------------------------------------------*/
203
204const char *bitbanger_baud_string(running_device *device)
205{
206   bitbanger_token *bi = get_token(device);
207   static const char *bauds[] = { "150", "300", "600", "1200", "2400", "4800",
208                     "9600", "14400", "28800", "38400", "57600", "115200"};
209
210   return(bauds[bi->baud]);
211}
212
213
214/*-------------------------------------------------
215    bitbanger_inc_baud
216-------------------------------------------------*/
217bool bitbanger_inc_baud(running_device *device, bool test)
218{
219   bitbanger_token *bi = get_token(device);
220   int adjust_baud = (int)bi->baud + 1;
221
222   if( adjust_baud >= BITBANGER_BAUD_MAX )
223      return FALSE;
224
225   if( !test)
226   {
227      bi->baud = adjust_baud;
228      bi->current_baud = ATTOTIME_IN_HZ(bitbanger_baud_value(device));
229   }
230
231   return TRUE;
232}
233
234
235/*-------------------------------------------------
236    bitbanger_dec_baud
237-------------------------------------------------*/
238bool bitbanger_dec_baud(running_device *device, bool test)
239{
240   bitbanger_token *bi = get_token(device);
241   int adjust_baud = bi->baud - 1;
242
243   if( adjust_baud < 0 )
244      return FALSE;
245
246   if( !test)
247   {
248      bi->baud = adjust_baud;
249      bi->current_baud = ATTOTIME_IN_HZ(bitbanger_baud_value(device));
250   }
251
252   return TRUE;
253}
254
255
256/*-------------------------------------------------
257    bitbanger_inc_tune
258-------------------------------------------------*/
259bool bitbanger_inc_tune(running_device *device, bool test)
260{
261   bitbanger_token *bi = get_token(device);
262   int adjust_tune = (int)bi->tune + 1;
263
264   if( adjust_tune >= BITBANGER_TUNE_MAX )
265      return FALSE;
266
267   if( !test)
268   {
269      bi->tune = adjust_tune;
270      bi->current_baud = ATTOTIME_IN_HZ(bitbanger_baud_value(device));
271   }
272
273   return TRUE;
274}
275
276
277/*-------------------------------------------------
278    bitbanger_dec_tune
279-------------------------------------------------*/
280bool bitbanger_dec_tune(running_device *device, bool test)
281{
282   bitbanger_token *bi = get_token(device);
283   int adjust_tune = bi->tune - 1;
284
285   if( adjust_tune < 0 )
286      return FALSE;
287
288   if( !test)
289   {
290      bi->tune = adjust_tune;
291      bi->current_baud = ATTOTIME_IN_HZ(bitbanger_baud_value(device));
292   }
293
294   return TRUE;
295}
296
297
298/*-------------------------------------------------
299    bitbanger_bytes_to_bits_81N
300-------------------------------------------------*/
301static void bitbanger_bytes_to_bits_81N(running_device *img, UINT8 **buffer, UINT32 *size)
302{
303   UINT8 byte_buffer[100];
304   static UINT8 bit_buffer[1000];
305   UINT32 byte_buffer_size, bit_buffer_size;
306   int i, j;
307   const UINT8 bitmask[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
308
309   bit_buffer_size = 0;
310   byte_buffer_size = 100;
311   byte_buffer_size = native_input(img, &byte_buffer, byte_buffer_size);
312
313   /* Translate byte buffer into bit buffer using: 1 start bit, 8 data bits, 1 stop bit, no parity */
314
315   for( i=0; i<byte_buffer_size; i++ )
316   {
317      bit_buffer[bit_buffer_size++] = 0;
318
319      for( j=0; j<8; j++ )
320      {
321         if( byte_buffer[i] & bitmask[j] )
322            bit_buffer[bit_buffer_size++] = 1;
323         else
324            bit_buffer[bit_buffer_size++] = 0;
325      }
326
327      bit_buffer[bit_buffer_size++] = 1;
328   }
329
330   *buffer = bit_buffer;
331   *size = bit_buffer_size;
332}
333
334
335/*-------------------------------------------------
336    DEVICE_START(bitbanger)
337-------------------------------------------------*/
338
339static DEVICE_START(bitbanger)
340{
341   bitbanger_token *bi;
153342   const bitbanger_config *config = get_config(device);
154343
155   /* exceeded total countable pulses? */
156   if (bi->recorded_pulses == config->maximum_pulses)
157      memmove(bi->pulses, bi->pulses + 1, (--bi->recorded_pulses) * sizeof(double));
344   bi = get_token(device);
158345
159   /* record the pulse */
160   bi->pulses[bi->recorded_pulses++] = pulse_width;
346   /* output config */
347   bi->build_count = 0;
348   bi->bitbanger_output_timer = timer_alloc(device->machine, bitbanger_output_timer, (void *) device);
161349
162   /* analyze, if necessary */
163   if (bi->recorded_pulses >= config->minimum_pulses)
164      bitbanger_analyze(device);
350   /* input config */
351   bi->bitbanger_input_timer = timer_alloc(device->machine, bitbanger_input_timer, (void *) device );
352   bi->idle_delay = ATTOTIME_IN_SEC(1);
353   bi->input_buffer = 0;
354   bi->input_buffer_size = 0;
355   bi->input_buffer_cursor = 0;
356
357   bi->mode = config->default_mode;
358   bi->baud = config->default_baud;
359   bi->tune = config->default_tune;
360   bi->current_baud = ATTOTIME_IN_HZ(bitbanger_baud_value(device));
361
362   /* test callback */
363   if(!config->input_callback)
364      fatalerror("Misconfigured bitbanger device: input_callback cannot be NULL\n");
165365}
166366
167367
368/*-------------------------------------------------
369    TIMER_CALLBACK(bitbanger_output_timer)
370-------------------------------------------------*/
168371
372static TIMER_CALLBACK(bitbanger_output_timer)
373{
374   running_device *device = (running_device *) ptr;
375   bitbanger_token *bi = get_token(device);
376
377   /* this ia harded coded for 8-1-N */
378   if( bi->output_value )
379      bi->build_byte |= 0x200;
380
381   bi->build_byte >>= 1;
382   bi->build_count--;
383
384   if(bi->build_count == 0)
385   {
386      if( bi->output_value == 1 )
387         native_output( device, bi->build_byte );
388      else
389         logerror("Bitbanger: Output framing error.\n" );
390
391      timer_reset(bi->bitbanger_output_timer, attotime_never);
392   }
393}
394
395
169396/*-------------------------------------------------
170    TIMER_CALLBACK(bitbanger_overthreshhold)
397    TIMER_CALLBACK(bitbanger_input_timer)
171398-------------------------------------------------*/
172399
173static TIMER_CALLBACK(bitbanger_overthreshhold)
400static TIMER_CALLBACK(bitbanger_input_timer)
174401{
175402   running_device *device = (running_device *) ptr;
176403   bitbanger_token *bi = get_token(device);
404   const bitbanger_config *config = get_config(device);
177405
178   bitbanger_addpulse(device, attotime_to_double(timer_get_time(machine)) - bi->last_pulse_time);
179   bi->over_threshhold = 1;
180   bi->recorded_pulses = 0;
406   if(bi->input_buffer_cursor == bi->input_buffer_size)
407   {
408      /* get more data */
409      bitbanger_bytes_to_bits_81N(device, &(bi->input_buffer), &(bi->input_buffer_size));
410      bi->input_buffer_cursor = 0;
411
412      if(bi->input_buffer_size == 0)
413      {
414         /* no more data, wait and try again */
415         bi->idle_delay = attotime_min(attotime_add(bi->idle_delay, ATTOTIME_IN_MSEC(100)), ATTOTIME_IN_SEC(1));
416         timer_adjust_oneshot(bi->bitbanger_input_timer, bi->idle_delay, 0);
417
418
419         if( bi->mode == BITBANGER_MODEM )
420            config->input_callback(machine, 1);
421         else
422            config->input_callback(machine, 0);
423
424         return;
425      }
426      else
427      {
428         bi->idle_delay = bi->current_baud;
429         timer_adjust_periodic(bi->bitbanger_input_timer, bi->idle_delay, 0, bi->idle_delay);
430      }
431   }
432
433   /* send bit to driver */
434   config->input_callback(machine, bi->input_buffer[(bi->input_buffer_cursor)++]);
181435}
182436
183437
184
185438/*-------------------------------------------------
186439    bitbanger_output - outputs data to a bitbanger
187440    port
r9429r9430
190443void bitbanger_output(running_device *device, int value)
191444{
192445   bitbanger_token *bi = get_token(device);
193   const bitbanger_config *config = get_config(device);
446   attotime one_point_five_baud;
194447
195   double current_time;
196   double pulse_width;
448   if( bi->build_count == 0 && bi->output_value == 1 && value == 0 )
449   {
450      /* we found our start bit */
451      /* eight bits of data, plus one of stop */
452      bi->build_count = 9;
453      bi->build_byte = 0;
197454
198   /* normalize input */
199   value = value ? 1 : 0;
455      one_point_five_baud = attotime_add(bi->current_baud, attotime_div(bi->current_baud,2));
456      timer_adjust_periodic(bi->bitbanger_output_timer, one_point_five_baud, 0, bi->current_baud);
457    }
200458
201   /* only meaningful if we change */
202   if (bi->value != value)
203   {
204      current_time = attotime_to_double(timer_get_time(device->machine));
205      pulse_width = current_time - bi->last_pulse_time;
459   //fprintf(stderr,"%s, %d\n", attotime_string(timer_get_time(device->machine),9), value);
460   bi->output_value = value;
461}
206462
207      assert(pulse_width >= 0);
208463
209      if (!bi->over_threshhold && ((bi->recorded_pulses > 0) || (bi->value == config->initial_value)))
210         bitbanger_addpulse(device, pulse_width);
464/*-------------------------------------------------
465    DEVICE_IMAGE_LOAD( bitbanger )
466-------------------------------------------------*/
211467
212      /* update state */
213      bi->value = value;
214      bi->last_pulse_time = current_time;
215      bi->over_threshhold = 0;
468static DEVICE_IMAGE_LOAD( bitbanger )
469{
470   device_t *device = &image.device();
471   bitbanger_token *bi;
472   bi = get_token(device);
216473
217      /* update timeout timer */
218      timer_reset(bi->timeout_timer, double_to_attotime(config->pulse_threshhold));
219   }
474   timer_enable(bi->bitbanger_input_timer, TRUE);
475   timer_adjust_periodic(bi->bitbanger_input_timer, attotime_zero, 0, ATTOTIME_IN_SEC(1));
476
477   /* we don't need to do anything special */
478   return IMAGE_INIT_PASS;
220479}
221480
222481
482/*-------------------------------------------------
483    DEVICE_IMAGE_UNLOAD( bitbanger )
484-------------------------------------------------*/
223485
486static DEVICE_IMAGE_UNLOAD( bitbanger )
487{
488   device_t *device = &image.device();
489   bitbanger_token *bi;
490   bi = get_token(device);
491
492   timer_enable(bi->bitbanger_input_timer, FALSE);
493}
494
495
224496/*-------------------------------------------------
225497    DEVICE_GET_INFO(bitbanger) - device getinfo
226498    function
r9429r9430
234506      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(bitbanger_token); break;
235507      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0; break;
236508      case DEVINFO_INT_IMAGE_TYPE:               info->i = IO_PRINTER; break;
237      case DEVINFO_INT_IMAGE_READABLE:            info->i = 0; break;
509      case DEVINFO_INT_IMAGE_READABLE:            info->i = 1; break;
238510      case DEVINFO_INT_IMAGE_WRITEABLE:            info->i = 1; break;
239511      case DEVINFO_INT_IMAGE_CREATABLE:            info->i = 1; break;
240512
241513      /* --- the following bits of info are returned as pointers to data or functions --- */
242514      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(bitbanger); break;
515      case DEVINFO_FCT_IMAGE_LOAD:               info->f = (genf *) DEVICE_IMAGE_LOAD_NAME(bitbanger);      break;
516      case DEVINFO_FCT_IMAGE_UNLOAD:               info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME(bitbanger);   break;
243517
244518      /* --- the following bits of info are returned as NULL-terminated strings --- */
245519      case DEVINFO_STR_NAME:                     strcpy(info->s, "Bitbanger"); break;
src/mess/devices/bitbngr.h
r9429r9430
1212#include "image.h"
1313
1414
15enum
16{
17   BITBANGER_PRINTER         = 0,
18   BITBANGER_MODEM,
19   BITBANGER_MODE_MAX,
1520
21   BITBANGER_150            = 0,
22   BITBANGER_300,
23   BITBANGER_600,
24   BITBANGER_1200,
25   BITBANGER_2400,
26   BITBANGER_4800,
27   BITBANGER_9600,
28   BITBANGER_14400,
29   BITBANGER_28800,
30   BITBANGER_38400,
31   BITBANGER_57600,
32   BITBANGER_115200,
33   BITBANGER_BAUD_MAX,
34
35   BITBANGER_NEG40PERCENT  = 0,
36   BITBANGER_NEG35PERCENT,
37   BITBANGER_NEG30PERCENT,
38   BITBANGER_NEG25PERCENT,
39   BITBANGER_NEG20PERCENT,
40   BITBANGER_NEG15PERCENT,
41   BITBANGER_NEG10PERCENT,
42   BITBANGER_NEG5PERCENT,
43   BITBANGER_0PERCENT,
44   BITBANGER_POS5PERCENT,
45   BITBANGER_POS10PERCENT,
46   BITBANGER_POS15PERCENT,
47   BITBANGER_POS20PERCENT,
48   BITBANGER_POS25PERCENT,
49   BITBANGER_POS30PERCENT,
50   BITBANGER_POS35PERCENT,
51   BITBANGER_POS40PERCENT,
52   BITBANGER_TUNE_MAX
53};
54
1655/***************************************************************************
1756    CONSTANTS
1857***************************************************************************/
r9429r9430
3069typedef struct _bitbanger_config bitbanger_config;
3170struct _bitbanger_config
3271{
33   /* filter function; returns non-zero if input accepted */
34   int (*filter)(running_device *device, const int *pulses, int total_pulses, int total_duration);
35   double pulse_threshhold;         /* the maximum duration pulse that we will consider */
36   double pulse_tolerance;            /* deviation tolerance for pulses */
37   int minimum_pulses;               /* the minimum amount of pulses before we start analyzing */
38   int maximum_pulses;               /* the maximum amount of pulses that we will track */
39   int begin_pulse_value;            /* the begining value of a pulse */
40   int initial_value;               /* the initial value of the bitbanger line */
72   /* 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 */
4177};
4278
4379
r9429r9430
4985/* outputs data to a bitbanger port */
5086void bitbanger_output(running_device *device, int value);
5187
88void bitbanger_online_func(running_device *device, int state);
5289
90/* ui functions */
91const char *bitbanger_mode_string(running_device *device);
92const char *bitbanger_baud_string(running_device *device);
93const char *bitbanger_tune_string(running_device *device);
94bool bitbanger_inc_mode(running_device *device, bool test);
95bool bitbanger_dec_mode(running_device *device, bool test);
96bool bitbanger_inc_tune(running_device *device, bool test);
97bool bitbanger_dec_tune(running_device *device, bool test);
98bool bitbanger_inc_baud(running_device *device, bool test);
99bool bitbanger_dec_baud(running_device *device, bool test);
100
53101#endif /* __BITBNGR_H__ */
src/mess/uimess.c
r9429r9430
1212#include "uiinput.h"
1313#include "input.h"
1414#include "devices/cassette.h"
15#include "devices/bitbngr.h"
1516
1617
1718/***************************************************************************
r9429r9430
2627#define TAPECMD_SLIDER         ((void *) 0x0006)
2728#define TAPECMD_SELECT         ((void *) 0x0007)
2829
30#define BITBANGERCMD_SELECT         ((void *) 0x0000)
31#define BITBANGERCMD_MODE         ((void *) 0x0001)
32#define BITBANGERCMD_BAUD         ((void *) 0x0002)
33#define BITBANGERCMD_TUNE         ((void *) 0x0003)
2934
3035
3136typedef struct _tape_control_menu_state tape_control_menu_state;
r9429r9430
3742
3843
3944
45typedef struct _bitbanger_control_menu_state bitbanger_control_menu_state;
46struct _bitbanger_control_menu_state
47{
48   int index;
49   device_image_interface *device;
50};
51
52
53
4054/***************************************************************************
4155    IMPLEMENTATION
4256***************************************************************************/
r9429r9430
5064   /* add tape control menu */
5165   if (machine->m_devicelist.first(CASSETTE))
5266      ui_menu_item_append(menu, "Tape Control", NULL, 0, (void*)ui_mess_menu_tape_control);
67
68   /* add bitbanger control menu */
69   if (machine->m_devicelist.first(BITBANGER))
70      ui_menu_item_append(menu, "Bitbanger Control", NULL, 0, (void*)ui_mess_menu_bitbanger_control);
5371}
5472
5573
r9429r9430
6179INLINE int cassette_count( running_machine *machine )
6280{
6381   int count = 0;
64   running_device *device = machine->m_devicelist.first(CASSETTE );
82   running_device *device = machine->m_devicelist.first(CASSETTE);
6583
6684   while ( device )
6785   {
r9429r9430
7290}
7391
7492/*-------------------------------------------------
93    bitbanger_count - returns the number of bitbanger
94    devices in the machine
95-------------------------------------------------*/
96
97INLINE int bitbanger_count( running_machine *machine )
98{
99   int count = 0;
100   running_device *device = machine->m_devicelist.first(BITBANGER);
101
102   while ( device )
103   {
104      count++;
105      device = device->typenext();
106   }
107   return count;
108}
109
110/*-------------------------------------------------
75111    tapecontrol_gettime - returns a textual
76112    representation of the time
77113-------------------------------------------------*/
r9429r9430
176212
177213
178214/*-------------------------------------------------
215    menu_bitbanger_control_populate - populates the
216    main bitbanger control menu
217-------------------------------------------------*/
218
219static void menu_bitbanger_control_populate(running_machine *machine, ui_menu *menu, bitbanger_control_menu_state *menustate)
220{
221   int count = bitbanger_count(machine);
222   UINT32 flags = 0, mode_flags = 0, baud_flags = 0, tune_flags = 0;
223
224   if( count > 0 )
225   {
226      if( menustate->index == (count-1) )
227         flags |= MENU_FLAG_LEFT_ARROW;
228      else
229         flags |= MENU_FLAG_RIGHT_ARROW;
230   }
231
232   if (bitbanger_inc_mode(&menustate->device->device(), TRUE))
233      mode_flags |= MENU_FLAG_RIGHT_ARROW;
234
235   if (bitbanger_dec_mode(&menustate->device->device(), TRUE))
236      mode_flags |= MENU_FLAG_LEFT_ARROW;
237
238   if (bitbanger_inc_baud(&menustate->device->device(), TRUE))
239      baud_flags |= MENU_FLAG_RIGHT_ARROW;
240
241   if (bitbanger_dec_baud(&menustate->device->device(), TRUE))
242      baud_flags |= MENU_FLAG_LEFT_ARROW;
243
244   if (bitbanger_inc_tune(&menustate->device->device(), TRUE))
245      tune_flags |= MENU_FLAG_RIGHT_ARROW;
246
247   if (bitbanger_dec_tune(&menustate->device->device(), TRUE))
248      tune_flags |= MENU_FLAG_LEFT_ARROW;
249
250
251   if (menustate->device->exists())
252   {
253      /* name of bitbanger file */
254      ui_menu_item_append(menu, menustate->device->image_config().devconfig().name(), menustate->device->filename(), flags, BITBANGERCMD_SELECT);
255      ui_menu_item_append(menu, "Device Mode:", bitbanger_mode_string(&menustate->device->device()), mode_flags, BITBANGERCMD_MODE);
256      ui_menu_item_append(menu, "Baud:", bitbanger_baud_string(&menustate->device->device()), baud_flags, BITBANGERCMD_BAUD);
257      ui_menu_item_append(menu, "Baud Tune:", bitbanger_tune_string(&menustate->device->device()), tune_flags, BITBANGERCMD_TUNE);
258      ui_menu_item_append(menu, "Protocol:", "8-1-N", 0, NULL);
259   }
260   else
261   {
262      /* no tape loaded */
263      ui_menu_item_append(menu, "No Bitbanger Image loaded", NULL, flags, NULL);
264   }
265}
266
267
268/*-------------------------------------------------
179269    menu_tape_control - main tape control menu
180270-------------------------------------------------*/
181271
r9429r9430
269359      }
270360   }
271361}
362
363
364/*-------------------------------------------------
365    menu_bitbanger_control - main bitbanger
366    control menu
367-------------------------------------------------*/
368
369void ui_mess_menu_bitbanger_control(running_machine *machine, ui_menu *menu, void *parameter, void *state)
370{
371   bitbanger_control_menu_state *menustate;
372   const ui_menu_event *event;
373
374   /* if no state, allocate some */
375   if (state == NULL)
376      state = ui_menu_alloc_state(menu, sizeof(*menustate), NULL);
377   menustate = (bitbanger_control_menu_state *) state;
378
379   /* do we have to load the device? */
380   if (menustate->device == NULL)
381   {
382      int index = menustate->index;
383      device_image_interface *device = NULL;
384      for (bool gotone = machine->m_devicelist.first(device); gotone; gotone = device->next(device))
385      {
386         if(device->device().type() == BITBANGER) {
387            if (index==0) break;
388            index--;
389         }
390      }
391      menustate->device = device;
392      ui_menu_reset(menu, (ui_menu_reset_options)0);
393   }
394
395   /* rebuild the menu */
396   ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_POSITION);
397   menu_bitbanger_control_populate(machine, menu, (bitbanger_control_menu_state*)state);
398
399   /* process the menu */
400   event = ui_menu_process(machine, menu, UI_MENU_PROCESS_LR_REPEAT);
401   if (event != NULL)
402   {
403      switch(event->iptkey)
404      {
405         case IPT_UI_LEFT:
406            if (event->itemref==BITBANGERCMD_SELECT)
407            {
408               /* left arrow - rotate left through cassette devices */
409               if (menustate->index > 0)
410                  menustate->index--;
411               else
412                  menustate->index = bitbanger_count(machine) - 1;
413               menustate->device = NULL;
414            }
415            else if (event->itemref==BITBANGERCMD_MODE)
416            {
417               bitbanger_dec_mode(&menustate->device->device(), FALSE);
418            }
419            else if (event->itemref==BITBANGERCMD_BAUD)
420            {
421               bitbanger_dec_baud(&menustate->device->device(), FALSE);
422            }
423            else if (event->itemref==BITBANGERCMD_TUNE)
424            {
425               bitbanger_dec_tune(&menustate->device->device(), FALSE);
426            }
427            break;
428
429         case IPT_UI_RIGHT:
430            if (event->itemref==BITBANGERCMD_SELECT)
431            {
432               /* right arrow - rotate right through cassette devices */
433               if (menustate->index < bitbanger_count(machine) - 1)
434                  menustate->index++;
435               else
436                  menustate->index = 0;
437               menustate->device = NULL;
438            }
439            else if (event->itemref==BITBANGERCMD_MODE)
440            {
441               bitbanger_inc_mode(&menustate->device->device(), FALSE);
442            }
443            else if (event->itemref==BITBANGERCMD_BAUD)
444            {
445               bitbanger_inc_baud(&menustate->device->device(), FALSE);
446            }
447            else if (event->itemref==BITBANGERCMD_TUNE)
448            {
449               bitbanger_inc_tune(&menustate->device->device(), FALSE);
450            }
451            break;
452      }
453   }
454}
455
src/mess/uimess.h
r9429r9430
1515/***************************************************************************
1616    PROTOTYPES
1717***************************************************************************/
18/* bitbanger control */
19void ui_mess_menu_bitbanger_control(running_machine *machine, ui_menu *menu, void *parameter, void *state);
20
1821/* tape control */
1922void ui_mess_menu_tape_control(running_machine *machine, ui_menu *menu, void *parameter, void *state);
2023astring *tapecontrol_gettime(astring *dest, running_device *device, int *curpos, int *endpos);
src/mess/machine/coco.c
r9429r9430
2020
2121  TODO:
2222        - Implement unimplemented SAM registers
23        - Implement unimplemented interrupts (serial)
2423        - Choose and implement more appropriate ratios for the speed up poke
2524        - Handle resets correctly
2625
r9429r9430
7675should go into coco3.c and dragon.c which should (hopefully) make the code
7776easier to manage.
7877    P.Harvey-Smith, Dec 2006-Feb 2007
78   
79Added bi-directional bitbanger support. Also fixed reading PIA 1, port A. The
80DAC and bitbanger values written should be reflected in the read.
81    tim lindner, October 2010
82
7983***************************************************************************/
8084
8185#include <math.h>
r9429r9430
125129static emu_timer *mux_sel1_timer;
126130static emu_timer *mux_sel2_timer;
127131static UINT8 mux_sel1, mux_sel2;
132static UINT8 bitbanger_output_value;
133static UINT8 bitbanger_input_value;
134static UINT8 dac_value;
128135
129136static WRITE8_DEVICE_HANDLER ( d_pia1_pb_w );
130137static WRITE8_DEVICE_HANDLER ( d_pia1_pa_w );
r9429r9430
15361543/* Printer output for the CoCo, output to bitbanger port */
15371544static void printer_out_coco(running_machine *machine, int data)
15381545{
1539   bitbanger_output(bitbanger_image(machine), (data & 2) >> 1);
1546   bitbanger_output_value = (data & 2) >> 1;
1547   bitbanger_output(bitbanger_image(machine), bitbanger_output_value);
15401548}
15411549
15421550/* Printer output for the Dragon, output to Paralel port */
r9429r9430
15641572   static int dclg_previous_bit;
15651573   UINT8 ctrl = input_port_read_safe(device->machine, "ctrl_sel", 0x00);
15661574   UINT8 hires = input_port_read_safe(device->machine, "hires_intf", 0x00);
1575   dac_value = dac >> 2;
15671576
15681577   coco_sound_update(device->machine);
15691578
r9429r9430
18281837      CASSETTE_MASK_MOTOR);
18291838}
18301839
1840static READ8_DEVICE_HANDLER ( d_pia1_pa_r )
1841{
1842   UINT8 result;
18311843
1844   result = cassette_input(cassette_device_image(device->machine)) >= 0 ? 1 : 0;
1845   result |= bitbanger_output_value << 1;
1846   result |= dac_value << 2;
18321847
1833static READ8_DEVICE_HANDLER ( d_pia1_pa_r )
1848   return result;
1849}
1850
1851void coco_bitbanger_callback(running_machine *machine, UINT8 bit)
18341852{
1835   return (cassette_input(cassette_device_image(device->machine)) >= 0) ? 1 : 0;
1853      bitbanger_input_value = bit;
18361854}
18371855
1856void coco3_bitbanger_callback(running_machine *machine, UINT8 bit)
1857{
1858   /* rant: this interrupt is next to useless. It would be useful information to know when a
1859            start bit (high to low) occurs, but this interrupt activates in the opposite situation.
1860   */
18381861
1862   if( bitbanger_input_value == 0 && bit == 1)
1863   {
1864      bitbanger_input_value = bit;
1865      coco3_raise_interrupt(machine, COCO3_INT_EI2, 0);
1866      coco3_raise_interrupt(machine, COCO3_INT_EI2, 1);
1867   }
1868   else
1869   {
1870      bitbanger_input_value = bit;
1871   }
1872}
18391873
18401874static READ8_DEVICE_HANDLER ( d_pia1_pb_r_coco )
18411875{
18421876   coco_state *state = device->machine->driver_data<coco_state>();
18431877
18441878   /* This handles the reading of the memory sense switch (pb2) for the CoCo 1,
1845     * and serial-in (pb0). Serial-in not yet implemented. */
1879     * and serial-in (pb0). */
18461880   int result;
18471881
18481882   /* For the CoCo 1, the logic has been changed to only select 64K rams
r9429r9430
18591893   else
18601894      result = 0x00;         /* 4K Rams */
18611895
1896   result += bitbanger_input_value;
1897
18621898   return result;
18631899}
18641900
r9429r9430
18861922   coco_state *state = device->machine->driver_data<coco_state>();
18871923
18881924   /* This handles the reading of the memory sense switch (pb2) for the CoCo 2 and 3,
1889     * and serial-in (pb0). Serial-in not yet implemented.
1925     * and serial-in (pb0).
18901926     */
18911927   int result;
18921928
r9429r9430
18961932      result = 0x04;               /* 16K: wire pia1_pb2 high */
18971933   else
18981934      result = (pia6821_get_output_b(state->pia_0) & 0x40) >> 4;      /* 32/64K: wire output of pia0_pb6 to input pia1_pb2  */
1935
1936   result += bitbanger_input_value;
1937
18991938   return result;
19001939}
19011940
r9429r9430
28272866      machine->device<cpu_device>("maincpu")->debug()->set_dasm_override(coco_dasm_override);
28282867   }
28292868
2869   /* setup printer input line to "space", this is what a Tandy printer would do */
2870   bitbanger_output_value = 1;
2871   bitbanger_input_value = 0;
2872   dac_value = 0;
2873
28302874   state_save_register_global(machine, mux_sel1);
28312875   state_save_register_global(machine, mux_sel2);
28322876}
src/mess/includes/coco.h
r9429r9430
162162
163163extern const struct coco3_video_vars coco3_vidvars;
164164
165/* Setting it bitbanger bit */
166void coco_bitbanger_callback(running_machine *machine, UINT8 bit);
167void coco3_bitbanger_callback(running_machine *machine, UINT8 bit);
168
165169#endif /* __COCO_H__ */
src/mess/drivers/coco.c
r9429r9430
694694  Bitbanger port
695695***************************************************************************/
696696
697static int coco_bitbanger_filter(running_device *img, const int *pulses, int total_pulses, int total_duration)
697static const bitbanger_config coco_bitbanger_config =
698698{
699   int i;
700   int result = 0;
701   int word;
702   int pos;
703   int pulse_type;
704   int c;
699   coco_bitbanger_callback,
700   BITBANGER_PRINTER,   /* default mode */
701   BITBANGER_600,       /* default output baud */
702   BITBANGER_0PERCENT   /* default fine tune adjustment */
703};
705704
706   if (total_duration >= 11)
707   {
708      word = 0;
709      pos = 0;
710      pulse_type = 0;
711      result = 1;
712
713      for (i = 0; i < total_pulses; i++)
714      {
715         if (pulse_type)
716            word |= ((1 << pulses[i]) - 1) << pos;
717         pulse_type ^= 1;
718         pos += pulses[i];
719      }
720
721      c = (word >> 1) & 0xff;
722      printer_output(img, c);
723   }
724   return result;
725}
726
727static const bitbanger_config coco_bitbanger_config =
705static const bitbanger_config coco3_bitbanger_config =
728706{
729   coco_bitbanger_filter,
730   1.0 / 10.0,
731   0.2,
732   2,
733   10,
734   0,
735   0
707   coco3_bitbanger_callback,
708   BITBANGER_PRINTER,   /* default mode */
709   BITBANGER_600,       /* dafault output baud */
710   BITBANGER_0PERCENT   /* default fine tune adjustment */
736711};
737712
713
714
738715/* ----------------------------------------------------------------------- */
739716
740717/* AY-8912 for Dragon Alpha, the AY-8912 simply an AY-8910 with only one io port. */
r9429r9430
11991176   MDRV_FRAGMENT_ADD( coco_sound )
12001177
12011178   /* bitbanger/printer */
1202   MDRV_BITBANGER_ADD("bitbanger", coco_bitbanger_config)
1179   MDRV_BITBANGER_ADD("bitbanger", coco3_bitbanger_config)
12031180
12041181   /* snapshot/quickload */
12051182   MDRV_SNAPSHOT_ADD("snapshot", coco3_pak, "pak", 0)
docs/messnew.txt
r9429r9430
8888- [MEPHISTO] to reduce the artwork files glasgow, amsterd and mm4
8989  are defined as PARENTS. [Ralf Schaefer]
9090
91- [COCO] Added bi-directional bitbanger support. Needs further core
92  changes to be fully implemented. [tim lindner]
93
94
95
9196Imgtool Changes:
9297----------------
9398

Previous 15994 Revisions Next


© 1998-2018 The MESS Team