Previous 15994 Revisions Next

r2361 Friday 11th April, 2008 at 12:59:20 UTC by Nathan Woods
[COCO] Transitioned the Bitbanger device to MAME's core device system
[docs]messnew.txt
[src/mess/devices]bitbngr.c bitbngr.h printer.c printer.h
[src/mess/drivers]coco.c
[src/mess/machine]coco.c

src/mess/devices/printer.c
r2360r2361
1111
1212
1313
14/***************************************************************************
15    IMPLEMENTATION
16***************************************************************************/
17
1418/*-------------------------------------------------
1519   printer_is_ready - checks to see if a printer
1620   is ready
src/mess/devices/bitbngr.c
r2360r2361
1313#include "printer.h"
1414
1515
16static TIMER_CALLBACK(bitbanger_overthreshhold);
1716
18struct bitbanger_info
17/***************************************************************************
18    TYPE DEFINITIONS
19***************************************************************************/
20
21typedef struct _bitbanger_token bitbanger_token;
22struct _bitbanger_token
1923{
20   const struct bitbanger_config *config;
2124   double last_pulse_time;
2225   double *pulses;
2326   int *factored_pulses;
2427   int recorded_pulses;
2528   int value;
26   void *timeout_timer;
29   emu_timer *timeout_timer;
2730   int over_threshhold;
2831};
2932
30static struct bitbanger_info *bitbangers[MAX_PRINTER];
3133
34
35/***************************************************************************
36    FUNCTION PROTOTYPES
37***************************************************************************/
38
39static TIMER_CALLBACK(bitbanger_overthreshhold);
40
41
42
43/***************************************************************************
44    INLINE FUNCTIONS
45***************************************************************************/
46
47/*-------------------------------------------------
48    get_token - safely gets the bitbanger data
49-------------------------------------------------*/
50
51INLINE bitbanger_token *get_token(const device_config *device)
52{
53   assert(device != NULL);
54   assert(device->token != NULL);
55   assert(device->type == BITBANGER);
56   return (bitbanger_token *) device->token;
57}
58
59
60
61/*-------------------------------------------------
62    get_config - safely gets the bitbanger config
63-------------------------------------------------*/
64
65INLINE const bitbanger_config *get_config(const device_config *device)
66{
67   assert(device != NULL);
68   assert(device->token != NULL);
69   assert(device->type == BITBANGER);
70   return (const bitbanger_config *) device->static_config;
71}
72
73
74
75/***************************************************************************
76    IMPLEMENTATION
77***************************************************************************/
78
79/*-------------------------------------------------
80    DEVICE_START(bitbanger)
81-------------------------------------------------*/
82
3283static DEVICE_START(bitbanger)
3384{
34   int id = image_index_in_device(device);
35   struct bitbanger_info *bi;
36   const struct bitbanger_config *config;
37   const struct IODevice *dev;
85   bitbanger_token *bi;
86   const bitbanger_config *config = get_config(device);
3887
39   dev = mess_device_from_core_device(device);
40   config = (const struct bitbanger_config *) mess_device_get_info_ptr(&dev->devclass, MESS_DEVINFO_PTR_BITBANGER_CONFIG);
41
42   bi = (struct bitbanger_info *) auto_malloc(sizeof(struct bitbanger_info));
88   bi = get_token(device);
4389   bi->pulses = (double *) auto_malloc(config->maximum_pulses * sizeof(double));
4490   bi->factored_pulses = (int *) auto_malloc(config->maximum_pulses * sizeof(int));
45   bi->config = config;
4691   bi->last_pulse_time = 0.0;
4792   bi->recorded_pulses = 0;
4893   bi->value = config->initial_value;
49   bi->timeout_timer = timer_alloc(bitbanger_overthreshhold, NULL);
94   bi->timeout_timer = timer_alloc(bitbanger_overthreshhold, (void *) device);
5095   bi->over_threshhold = 1;
51
52   bitbangers[id] = bi;
5396}
5497
5598
5699
57static void bitbanger_analyze(int id, struct bitbanger_info *bi)
100/*-------------------------------------------------
101    bitbanger_analyze
102-------------------------------------------------*/
103
104static void bitbanger_analyze(const device_config *device)
58105{
59106   int i, factor, total_duration;
60107   double smallest_pulse;
61108   double d;
109   bitbanger_token *bi = get_token(device);
110   const bitbanger_config *config = get_config(device);
62111
63112   /* compute the smallest pulse */
64   smallest_pulse = bi->config->pulse_threshhold;
113   smallest_pulse = config->pulse_threshhold;
65114   for (i = 0; i < bi->recorded_pulses; i++)
66115      if (smallest_pulse > bi->pulses[i])
67116         smallest_pulse = bi->pulses[i];
r2360r2361
75124
76125      for (i = 0; i < bi->recorded_pulses; i++)
77126      {
78         d = bi->pulses[i] / smallest_pulse * factor + bi->config->pulse_tolerance;
79         if ((i < (bi->recorded_pulses-1)) && (d - floor(d)) >= (bi->config->pulse_tolerance * 2))
127         d = bi->pulses[i] / smallest_pulse * factor + config->pulse_tolerance;
128         if ((i < (bi->recorded_pulses-1)) && (d - floor(d)) >= (config->pulse_tolerance * 2))
80129         {
81130            i = -1;
82131            break;
r2360r2361
85134         total_duration += (int) d;
86135      }
87136   }
88   while((i == -1) && (factor < bi->config->maximum_pulses));
137   while((i == -1) && (factor < config->maximum_pulses));
89138   if (i == -1)
90139      return;
91140
92141   /* filter the output */
93   if (bi->config->filter(image_from_devtype_and_index(IO_BITBANGER, id), bi->factored_pulses, bi->recorded_pulses, total_duration))
142   if (config->filter(device, bi->factored_pulses, bi->recorded_pulses, total_duration))
94143      bi->recorded_pulses = 0;
95144}
96145
97146
98147
99static void bitbanger_addpulse(int id, struct bitbanger_info *bi, double pulse_width)
148/*-------------------------------------------------
149    bitbanger_addpulse
150-------------------------------------------------*/
151
152static void bitbanger_addpulse(const device_config *device, double pulse_width)
100153{
154   bitbanger_token *bi = get_token(device);
155   const bitbanger_config *config = get_config(device);
156
101157   /* exceeded total countable pulses? */
102   if (bi->recorded_pulses == bi->config->maximum_pulses)
158   if (bi->recorded_pulses == config->maximum_pulses)
103159      memmove(bi->pulses, bi->pulses + 1, (--bi->recorded_pulses) * sizeof(double));
104160
105161   /* record the pulse */
106162   bi->pulses[bi->recorded_pulses++] = pulse_width;
107163
108164   /* analyze, if necessary */
109   if (bi->recorded_pulses >= bi->config->minimum_pulses)
110      bitbanger_analyze(id, bi);
165   if (bi->recorded_pulses >= config->minimum_pulses)
166      bitbanger_analyze(device);
111167}
112168
113169
114170
171/*-------------------------------------------------
172    TIMER_CALLBACK(bitbanger_overthreshhold)
173-------------------------------------------------*/
174
115175static TIMER_CALLBACK(bitbanger_overthreshhold)
116176{
117   int id = param;
118   struct bitbanger_info *bi = bitbangers[id];
119   bitbanger_addpulse(id, bi, attotime_to_double(timer_get_time()) - bi->last_pulse_time);
177   const device_config *device = (const device_config *) ptr;
178   bitbanger_token *bi = get_token(device);
179
180   bitbanger_addpulse(device, attotime_to_double(timer_get_time()) - bi->last_pulse_time);
120181   bi->over_threshhold = 1;
121182   bi->recorded_pulses = 0;
122183}
123184
124185
125186
126void bitbanger_output(const device_config *img, int value)
187/*-------------------------------------------------
188    bitbanger_output - outputs data to a bitbanger
189   port
190-------------------------------------------------*/
191
192void bitbanger_output(const device_config *device, int value)
127193{
128   int id = image_index_in_device(img);
129   struct bitbanger_info *bi = bitbangers[id];
194   bitbanger_token *bi = get_token(device);
195   const bitbanger_config *config = get_config(device);
196
130197   double current_time;
131198   double pulse_width;
132199
r2360r2361
141208
142209      assert(pulse_width >= 0);
143210
144      if (!bi->over_threshhold && ((bi->recorded_pulses > 0) || (bi->value == bi->config->initial_value)))
145         bitbanger_addpulse(id, bi, pulse_width);
211      if (!bi->over_threshhold && ((bi->recorded_pulses > 0) || (bi->value == config->initial_value)))
212         bitbanger_addpulse(device, pulse_width);
146213
147214      /* update state */
148215      bi->value = value;
r2360r2361
150217      bi->over_threshhold = 0;
151218
152219      /* update timeout timer */
153      timer_reset(bi->timeout_timer, double_to_attotime(bi->config->pulse_threshhold));
220      timer_reset(bi->timeout_timer, double_to_attotime(config->pulse_threshhold));
154221   }
155222}
156223
157224
158225
159void bitbanger_device_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
226/*-------------------------------------------------
227    DEVICE_GET_INFO(bitbanger) - device getinfo
228   function
229-------------------------------------------------*/
230
231DEVICE_GET_INFO(bitbanger)
160232{
161233   switch(state)
162234   {
163235      /* --- the following bits of info are returned as 64-bit signed integers --- */
164      case MESS_DEVINFO_INT_TYPE:                  info->i = IO_BITBANGER; break;
165      case MESS_DEVINFO_INT_READABLE:               info->i = 1; break;
166      case MESS_DEVINFO_INT_WRITEABLE:            info->i = 1; break;
167      case MESS_DEVINFO_INT_CREATABLE:            info->i = 1; break;
236      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(bitbanger_token); break;
237      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0; break;
238      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL; break;
239      case DEVINFO_INT_IMAGE_TYPE:               info->i = IO_PRINTER; break;
240      case DEVINFO_INT_IMAGE_READABLE:            info->i = 0; break;
241      case DEVINFO_INT_IMAGE_WRITEABLE:            info->i = 1; break;
242      case DEVINFO_INT_IMAGE_CREATABLE:            info->i = 1; break;
168243
169244      /* --- the following bits of info are returned as pointers to data or functions --- */
170      case MESS_DEVINFO_PTR_START:               info->start = DEVICE_START_NAME(bitbanger); break;
245      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(bitbanger); break;
171246
172247      /* --- the following bits of info are returned as NULL-terminated strings --- */
173      case MESS_DEVINFO_STR_DEV_FILE:               strcpy(info->s = device_temp_str(), __FILE__); break;
174      case MESS_DEVINFO_STR_FILE_EXTENSIONS:         strcpy(info->s = device_temp_str(), "prn"); break;
248      case DEVINFO_STR_NAME:                     info->s = "Bitbanger"; break;
249      case DEVINFO_STR_FAMILY:                  info->s = "Bitbanger"; break;
250      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__; break;
251      case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:         info->s = "prn"; break;
175252   }
176253}
src/mess/devices/printer.h
r2360r2361
1313
1414
1515/***************************************************************************
16    CONSTANTS
17***************************************************************************/
18
19/* please remove me eventually! */
20#define MAX_PRINTER   4
21
22
23
24/***************************************************************************
2516    TYPE DEFINITIONS
2617***************************************************************************/
2718
src/mess/devices/bitbngr.h
r2360r2361
66
77*********************************************************************/
88
9#ifndef BITBNGR_H
10#define BITBNGR_H
9#ifndef __BITBNGR_H__
10#define __BITBNGR_H__
1111
12#include "device.h"
1312#include "image.h"
1413
1514
16struct bitbanger_config
15
16/***************************************************************************
17    TYPE DEFINITIONS
18***************************************************************************/
19
20#define BITBANGER   DEVICE_GET_INFO_NAME(bitbanger)
21
22typedef struct _bitbanger_config bitbanger_config;
23struct _bitbanger_config
1724{
1825   /* filter function; returns non-zero if input accepted */
19   int (*filter)(const device_config *img, const int *pulses, int total_pulses, int total_duration);
26   int (*filter)(const device_config *device, const int *pulses, int total_pulses, int total_duration);
2027   double pulse_threshhold;         /* the maximum duration pulse that we will consider */
2128   double pulse_tolerance;            /* deviation tolerance for pulses */
2229   int minimum_pulses;               /* the minimum amount of pulses before we start analyzing */
r2360r2361
2532   int initial_value;               /* the initial value of the bitbanger line */
2633};
2734
28#define IO_BITBANGER IO_PRINTER
2935
30enum
31{
32   MESS_DEVINFO_PTR_BITBANGER_CONFIG = MESS_DEVINFO_PTR_DEV_SPECIFIC
33};
3436
35void bitbanger_device_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info);
36void bitbanger_output(const device_config *img, int value);
37/***************************************************************************
38    FUNCTION PROTOTYPES
39***************************************************************************/
3740
41/* outputs data to a bitbanger port */
42void bitbanger_output(const device_config *device, int value);
3843
39#endif /* BITBNGR_H */
44/* device getinfo function */
45DEVICE_GET_INFO(bitbanger);
46
47
48#endif /* __BITBNGR_H__ */
src/mess/machine/coco.c
r2360r2361
11221122
11231123static const device_config *bitbanger_image(void)
11241124{
1125   return image_from_devtype_and_index(IO_BITBANGER, 0);
1125   return device_list_find_by_tag(Machine->config->devicelist, BITBANGER, "bitbanger");
11261126}
11271127
11281128static const device_config *printer_image(void)
src/mess/drivers/coco.c
r2360r2361
563563   PORT_INCLUDE( cart_autostart )
564564INPUT_PORTS_END
565565
566/***************************************************************************
567  Bitbanger port
568***************************************************************************/
569
570static int coco_bitbanger_filter(const device_config *img, const int *pulses, int total_pulses, int total_duration)
571{
572   int i;
573   int result = 0;
574   int word;
575   int pos;
576   int pulse_type;
577   int c;
578
579   if (total_duration >= 11)
580   {
581      word = 0;
582      pos = 0;
583      pulse_type = 0;
584      result = 1;
585
586      for (i = 0; i < total_pulses; i++)
587      {
588         if (pulse_type)
589            word |= ((1 << pulses[i]) - 1) << pos;
590         pulse_type ^= 1;
591         pos += pulses[i];
592      }
593
594      c = (word >> 1) & 0xff;
595      printer_output(img, c);
596   }
597   return result;
598}
599
600static const bitbanger_config coco_bitbanger_config =
601{
602   coco_bitbanger_filter,
603   1.0 / 10.0,
604   0.2,
605   2,
606   10,
607   0,
608   0
609};
610
611static MACHINE_DRIVER_START( coco_bitbanger )
612   MDRV_DEVICE_ADD("bitbanger", BITBANGER)
613   MDRV_DEVICE_CONFIG(coco_bitbanger_config)
614MACHINE_DRIVER_END
615
616/* ----------------------------------------------------------------------- */
617
566618/* AY-8912 for Dragon Alpha, the AY-8912 simply an AY-8910 with only one io port. */
567619static const struct AY8910interface ay8912_interface =
568620{
r2360r2361
717769
718770   /* sound hardware */
719771   MDRV_IMPORT_FROM( coco_sound )
772
773   /* bitbanger/printer */
774   MDRV_IMPORT_FROM( coco_bitbanger )
720775MACHINE_DRIVER_END
721776
722777static MACHINE_DRIVER_START( coco2 )
r2360r2361
737792
738793   /* sound hardware */
739794   MDRV_IMPORT_FROM( coco_sound )
795
796   /* bitbanger/printer */
797   MDRV_IMPORT_FROM( coco_bitbanger )
740798MACHINE_DRIVER_END
741799
742800static MACHINE_DRIVER_START( coco2b )
r2360r2361
757815
758816   /* sound hardware */
759817   MDRV_IMPORT_FROM( coco_sound )
818
819   /* bitbanger/printer */
820   MDRV_IMPORT_FROM( coco_bitbanger )
760821MACHINE_DRIVER_END
761822
762823static MACHINE_DRIVER_START( coco3 )
r2360r2361
787848   /* sound hardware */
788849   MDRV_IMPORT_FROM( coco_sound )
789850
851   /* bitbanger/printer */
852   MDRV_IMPORT_FROM( coco_bitbanger )
853
790854   /* devices */
791855   MDRV_DEVICE_ADD("vhd", COCO_VHD)
792856MACHINE_DRIVER_END
r2360r2361
895959
896960#define rom_coco3h   rom_coco3
897961
898/***************************************************************************
899  Bitbanger port
900***************************************************************************/
901
902static int coco_bitbanger_filter(const device_config *img, const int *pulses, int total_pulses, int total_duration)
903{
904   int i;
905   int result = 0;
906   int word;
907   int pos;
908   int pulse_type;
909   int c;
910
911   if (total_duration >= 11)
912   {
913      word = 0;
914      pos = 0;
915      pulse_type = 0;
916      result = 1;
917
918      for (i = 0; i < total_pulses; i++)
919      {
920         if (pulse_type)
921            word |= ((1 << pulses[i]) - 1) << pos;
922         pulse_type ^= 1;
923         pos += pulses[i];
924      }
925
926      c = (word >> 1) & 0xff;
927      printer_output(img, c);
928   }
929   return result;
930}
931
932static const struct bitbanger_config coco_bitbanger_config =
933{
934   coco_bitbanger_filter,
935   1.0 / 10.0,
936   0.2,
937   2,
938   10,
939   0,
940   0
941};
942
943/* ----------------------------------------------------------------------- */
944
945962/*************************************
946963 *
947964 *  CoCo device getinfo functions
948965 *
949966 *************************************/
950967
951static void coco_bitbanger_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
952{
953   /* bitbanger port */
954   switch(state)
955   {
956      /* --- the following bits of info are returned as 64-bit signed integers --- */
957      case MESS_DEVINFO_INT_COUNT:                     info->i = 1; break;
958
959      /* --- the following bits of info are returned as pointers to data or functions --- */
960      case MESS_DEVINFO_PTR_BITBANGER_CONFIG:            info->p = (void *) &coco_bitbanger_config; break;
961
962      default:                              bitbanger_device_getinfo(devclass, state, info); break;
963   }
964}
965
966
967
968968static void coco_cassette_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
969969{
970970   /* cassette */
r2360r2361
11141114
11151115
11161116SYSTEM_CONFIG_START( generic_coco )
1117   CONFIG_DEVICE( coco_bitbanger_getinfo )
11181117   CONFIG_DEVICE( coco_cassette_getinfo )
11191118   CONFIG_DEVICE( coco_floppy_getinfo )
11201119   CONFIG_DEVICE( coco_quickload_getinfo )
docs/messnew.txt
r2360r2361
1717
1818- [CBM, C16] Simplified keyboard and interrupt handling code.  [Fabio Priuli]
1919
20- [COCO3] Transitioned VHD support to use MAME's core device system.  [Nate
21  Woods]
20- [COCO/COCO3] Transitioned Bitbanger and VHD support to use MAME's core
21  device system.  [Nate Woods]
2222
2323- [COUPE] Rewrote interrupt handling and screen handling, fixes line
2424  interrupts.  [Dirk Best]

Previous 15994 Revisions Next


© 1998-2018 The MESS Team