Previous 15994 Revisions Next

r4245 Wednesday 11th February, 2009 at 10:25:20 UTC by Dirk Best
New centronics printer interface
[docs]messnew.txt
[src/mess]mess.mak
[src/mess/machine]ctronics.c* ctronics.h*

src/mess/machine/ctronics.c
r0r4245
1/***************************************************************************
2 
3    Centronics printer interface
4 
5***************************************************************************/
6 
7#include "driver.h"
8#include "ctronics.h"
9 
10 
11/***************************************************************************
12    FUNCTION PROTOTYPES
13***************************************************************************/
14 
15static TIMER_CALLBACK( ack_callback );
16static TIMER_CALLBACK( busy_callback );
17 
18 
19/***************************************************************************
20    TYPE DEFINITIONS
21***************************************************************************/
22 
23typedef struct _centronics_state centronics_state;
24struct _centronics_state
25{
26   const device_config *printer;
27 
28   devcb_resolved_write_line out_ack_func;
29   devcb_resolved_write_line out_busy_func;
30   devcb_resolved_write_line out_not_busy_func;
31 
32   int strobe;
33   int busy;
34   int ack;
35   int auto_fd;
36 
37   UINT8 data;
38};
39 
40 
41/*****************************************************************************
42    INLINE FUNCTIONS
43*****************************************************************************/
44 
45INLINE centronics_state *get_safe_token(const device_config *device)
46{
47   assert(device != NULL);
48   assert(device->token != NULL);
49   assert(device->type == CENTRONICS);
50 
51   return (centronics_state *)device->token;
52}
53 
54 
55/*****************************************************************************
56    DEVICE INTERFACE
57*****************************************************************************/
58 
59static DEVICE_START( centronics )
60{
61   centronics_state *centronics = get_safe_token(device);
62   const centronics_interface *intf = device->static_config;
63   char printer_tag[256];
64 
65   /* validate some basic stuff */
66   assert(device->static_config != NULL);
67 
68   /* get printer device */
69   strcpy(printer_tag, device->tag);
70   strcat(printer_tag, "_p");
71   centronics->printer = devtag_get_device(device->machine, PRINTER, printer_tag);
72 
73   assert(centronics->printer != NULL);
74 
75   /* make sure it's running */
76   if (!centronics->printer->started)
77   {
78      device_delay_init(device);
79      return;
80   }
81 
82   /* resolve callbacks */
83   devcb_resolve_write_line(&centronics->out_ack_func, &intf->out_ack_func, device);
84   devcb_resolve_write_line(&centronics->out_busy_func, &intf->out_busy_func, device);
85   devcb_resolve_write_line(&centronics->out_not_busy_func, &intf->out_not_busy_func, device);
86 
87   /* register for state saving */
88   state_save_register_device_item(device, 0, centronics->auto_fd);
89   state_save_register_device_item(device, 0, centronics->strobe);
90   state_save_register_device_item(device, 0, centronics->busy);
91   state_save_register_device_item(device, 0, centronics->ack);
92   state_save_register_device_item(device, 0, centronics->data);
93}
94 
95static DEVICE_RESET( centronics )
96{
97   centronics_state *centronics = get_safe_token(device);
98   centronics->busy = printer_is_ready(centronics->printer) ? FALSE : TRUE;
99}
100 
101static DEVICE_SET_INFO( centronics )
102{
103   switch (state)
104   {
105      /* no parameters to set */
106   }
107}
108 
109DEVICE_GET_INFO( centronics )
110{
111   switch (state)
112   {
113      /* --- the following bits of info are returned as 64-bit signed integers --- */
114      case DEVINFO_INT_TOKEN_BYTES:         info->i = sizeof(centronics_state);      break;
115      case DEVINFO_INT_INLINE_CONFIG_BYTES:   info->i = 0;                     break;
116      case DEVINFO_INT_CLASS:               info->i = DEVICE_CLASS_PERIPHERAL;      break;
117 
118      /* --- the following bits of info are returned as pointers to data or functions --- */
119      case DEVINFO_FCT_SET_INFO:            info->set_info = DEVICE_SET_INFO_NAME( centronics );   break;
120      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME( centronics );         break;
121      case DEVINFO_FCT_STOP:               /* Nothing */                              break;
122      case DEVINFO_FCT_RESET:               info->reset = DEVICE_RESET_NAME( centronics );         break;
123 
124      /* --- the following bits of info are returned as NULL-terminated strings --- */
125      case DEVINFO_STR_NAME:               strcpy(info->s, "Centronics");         break;
126      case DEVINFO_STR_FAMILY:            strcpy(info->s, "Centronics");         break;
127      case DEVINFO_STR_VERSION:            strcpy(info->s, "1.0");               break;
128      case DEVINFO_STR_SOURCE_FILE:         strcpy(info->s, __FILE__);            break;
129      case DEVINFO_STR_CREDITS:            strcpy(info->s, "Copyright MESS Team");   break;
130   }
131}
132 
133 
134/***************************************************************************
135    IMPLEMENTATION
136***************************************************************************/
137 
138/*-------------------------------------------------
139    update_busy_state - check printer device
140    status and update busy state
141-------------------------------------------------*/
142 
143static int update_busy_state(const device_config *device)
144{
145   centronics_state *centronics = get_safe_token(device);
146   centronics->busy = printer_is_ready(centronics->printer) ? FALSE : TRUE;
147   return centronics->busy;
148}
149 
150 
151static TIMER_CALLBACK( ack_callback )
152{
153   centronics_state *centronics = (centronics_state *)ptr;
154 
155   /* signal change */
156   devcb_call_write_line(&centronics->out_ack_func, param);
157   centronics->ack = param;
158 
159   if (param == FALSE)
160   {
161      /* data is now ready, output it */
162      printer_output(centronics->printer, centronics->data);
163 
164      /* timer to return BUSY to low, 5us max */
165      timer_set(machine, ATTOTIME_IN_USEC(4), ptr, FALSE, busy_callback);
166   }
167}
168 
169 
170static TIMER_CALLBACK( busy_callback )
171{
172   centronics_state *centronics = (centronics_state *)ptr;
173 
174   /* signal change */
175   devcb_call_write_line(&centronics->out_busy_func, param);
176   devcb_call_write_line(&centronics->out_not_busy_func, !param);
177   centronics->busy = param;
178 
179   if (param == TRUE)
180   {
181      /* timer to turn ACK low to receive data */
182      timer_set(machine, ATTOTIME_IN_NSEC(250), ptr, FALSE, ack_callback);
183   }
184   else
185   {
186      /* timer to return ACK to high state, 5us max */
187      timer_set(machine, ATTOTIME_IN_USEC(4), ptr, TRUE, ack_callback);
188   }
189}
190 
191 
192/*-------------------------------------------------
193    centronics_data_w - write print data
194-------------------------------------------------*/
195 
196WRITE8_DEVICE_HANDLER( centronics_data_w )
197{
198   centronics_state *centronics = get_safe_token(device);
199   centronics->data = data;
200}
201 
202 
203/*-------------------------------------------------
204    centronics_strobe_w - signal that data is
205    ready
206-------------------------------------------------*/
207 
208WRITE_LINE_DEVICE_HANDLER( centronics_strobe_w )
209{
210   centronics_state *centronics = get_safe_token(device);
211 
212   /* ignore if we are busy */
213   if (state == FALSE && centronics->busy == FALSE)
214   {
215      /* STROBE has gone low, data is ready */
216      timer_set(device->machine, ATTOTIME_IN_NSEC(250), centronics, TRUE, busy_callback);
217   }
218 
219   centronics->strobe = state;
220}
221 
222 
223/*-------------------------------------------------
224    centronics_prime_w - initialize and reset
225    printer (centronics mode)
226-------------------------------------------------*/
227 
228WRITE_LINE_DEVICE_HANDLER( centronics_prime_w )
229{
230   assert(((const centronics_interface *)device->inline_config)->is_ibmpc == FALSE);
231 
232   /* reset printer if line is low */
233   if (state == FALSE)
234      device_reset_centronics(device);
235}
236 
237 
238/*-------------------------------------------------
239    centronics_init_w - initialize and reset
240    printer (ibm mode)
241-------------------------------------------------*/
242 
243WRITE_LINE_DEVICE_HANDLER( centronics_init_w )
244{
245   assert(((const centronics_interface *)device->inline_config)->is_ibmpc == TRUE);
246 
247   /* reset printer if line is low */
248   if (state == FALSE)
249      device_reset_centronics(device);
250}
251 
252 
253/*-------------------------------------------------
254    centronics_autofeed_w - auto line feed
255-------------------------------------------------*/
256 
257WRITE_LINE_DEVICE_HANDLER( centronics_autofeed_w )
258{
259   centronics_state *centronics = get_safe_token(device);
260   assert(((const centronics_interface *)device->inline_config)->is_ibmpc == TRUE);
261 
262   centronics->auto_fd = state;
263}
264 
265 
266/*-------------------------------------------------
267    centronics_ack_r - return the state of the
268    ack line
269-------------------------------------------------*/
270 
271READ_LINE_DEVICE_HANDLER( centronics_ack_r )
272{
273   centronics_state *centronics = get_safe_token(device);
274   return centronics->ack;
275}
276 
277 
278/*-------------------------------------------------
279    centronics_busy_r - return the state of the
280    busy line
281-------------------------------------------------*/
282 
283READ_LINE_DEVICE_HANDLER( centronics_busy_r )
284{
285   centronics_state *centronics = get_safe_token(device);
286   return centronics->busy;
287}
288 
289 
290/*-------------------------------------------------
291    centronics_pe_r - return the state of the
292    pe line
293-------------------------------------------------*/
294 
295READ_LINE_DEVICE_HANDLER( centronics_pe_r )
296{
297   /* use the busy line as pe line for now */
298   return !update_busy_state(device);
299}
300 
301 
302/*-------------------------------------------------
303    centronics_not_busy_r - return the state of the
304    not busy line
305-------------------------------------------------*/
306 
307READ_LINE_DEVICE_HANDLER( centronics_not_busy_r )
308{
309   centronics_state *centronics = get_safe_token(device);
310   return !centronics->busy;
311}
312 
313 
314/*-------------------------------------------------
315    centronics_not_busy_r - return the state of the
316    vcc line
317-------------------------------------------------*/
318 
319READ_LINE_DEVICE_HANDLER( centronics_vcc_r )
320{
321   /* always return high */
322   return TRUE;
323}
324 
325 
326/*-------------------------------------------------
327    centronics_fault_r - return the state of the
328    fault line
329-------------------------------------------------*/
330 
331READ_LINE_DEVICE_HANDLER( centronics_fault_r )
332{
333   /* use the busy line as fault line for now */
334   return !update_busy_state(device);
335}
src/mess/machine/ctronics.h
r0r4245
1/***************************************************************************
2 
3    Centronics printer interface
4 
5***************************************************************************/
6 
7#ifndef __CTRONICS_H__
8#define __CTRONICS_H__
9 
10#include "devcb.h"
11#include "devices/printer.h"
12 
13 
14/***************************************************************************
15    TYPE DEFINITIONS
16***************************************************************************/
17 
18typedef struct _centronics_interface centronics_interface;
19struct _centronics_interface
20{
21   int is_ibmpc;
22 
23   devcb_write_line out_ack_func;
24   devcb_write_line out_busy_func;
25   devcb_write_line out_not_busy_func;
26};
27 
28 
29/***************************************************************************
30    DEVICE CONFIGURATION MACROS
31***************************************************************************/
32 
33#define CENTRONICS DEVICE_GET_INFO_NAME(centronics)
34 
35#define MDRV_CENTRONICS_ADD(_tag, _intf) \
36   MDRV_PRINTER_ADD(_tag"_p") \
37   MDRV_DEVICE_ADD(_tag, CENTRONICS, 0) \
38   MDRV_DEVICE_CONFIG(_intf)
39 
40#define MDRV_CENTRONICS_REMOVE(_tag) \
41   MDRV_PRINTER_REMOVE(_tag"_p") \
42   MDRV_DEVICE_REMOVE(_tag, CENTRONICS)
43 
44 
45/***************************************************************************
46    FUNCTION PROTOTYPES
47***************************************************************************/
48 
49DEVICE_GET_INFO( centronics );
50 
51WRITE8_DEVICE_HANDLER( centronics_data_w );
52 
53WRITE_LINE_DEVICE_HANDLER( centronics_strobe_w );
54WRITE_LINE_DEVICE_HANDLER( centronics_prime_w );
55WRITE_LINE_DEVICE_HANDLER( centronics_init_w );
56WRITE_LINE_DEVICE_HANDLER( centronics_autofeed_w );
57 
58READ_LINE_DEVICE_HANDLER( centronics_ack_r );
59READ_LINE_DEVICE_HANDLER( centronics_busy_r );
60READ_LINE_DEVICE_HANDLER( centronics_pe_r );
61READ_LINE_DEVICE_HANDLER( centronics_not_busy_r );
62READ_LINE_DEVICE_HANDLER( centronics_vcc_r );
63READ_LINE_DEVICE_HANDLER( centronics_fault_r );
64 
65 
66/***************************************************************************
67    DEFAULT INTERFACES
68***************************************************************************/
69 
70const centronics_interface standard_centronics =
71{
72   FALSE,
73   DEVCB_NULL,
74   DEVCB_NULL,
75   DEVCB_NULL
76};
77 
78 
79#endif /* __CTRONICS_H__ */
src/mess/mess.mak
r4244r4245
521521   $(MESS_MACHINE)/ins8250.o \
522522   $(MESS_MACHINE)/pc_mouse.o \
523523   $(MESS_MACHINE)/centroni.o \
524   $(MESS_MACHINE)/ctronics.o \
524525   $(MAME_MACHINE)/pckeybrd.o \
525526   $(MESS_MACHINE)/d88.o      \
526527   $(MESS_MACHINE)/serial.o   \
docs/messnew.txt
r4244r4245
8282- Refactored the following devices to use devcb callbacks: ABC77, CDP1861,
8383  CDP1864, CDP1871, MC68901, Z80DART, ZX8301, ZX8302 [Curt Coder]
8484
85- New centronics printer interface.  [Dirk Best]
8586
8687
88
87890.129
8890
8991New System Drivers Supported (in no particular order):

Previous 15994 Revisions Next


© 1998-2018 The MESS Team