Previous 15994 Revisions Next

r5261 Friday 17th July, 2009 at 06:19:15 UTC by Curt Coder
[ELF] Added MM74C922/3 keyboard encoder device.
[src/mess]mess.mak
[src/mess/drivers]elf.c
[src/mess/includes]elf.h
[src/mess/machine]mm74c922.c* mm74c922.h*

src/mess/includes/elf.h
r5260r5261
44#define SCREEN_TAG      "screen"
55#define CDP1802_TAG      "a6"
66#define CDP1861_TAG      "a14"
7#define _74C923_TAG      "a10"
7#define MM74C923_TAG   "a10"
88#define DM9368_L_TAG   "a12"
99#define DM9368_H_TAG   "a8"
1010#define CASSETTE_TAG   "cassette"
r5260r5261
2020
2121   /* devices */
2222   const device_config *cdp1861;
23   const device_config *_74c923;
23   const device_config *mm74c923;
2424   const device_config *dm9368_l;
2525   const device_config *dm9368_h;
2626   const device_config *cassette;
src/mess/machine/mm74c922.c
r0r5261
1/**********************************************************************
2
3    Fairchild MM74C922/MM74C923 16/20-Key Encoder emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "driver.h"
11#include "mm74c922.h"
12
13/***************************************************************************
14    PARAMETERS
15***************************************************************************/
16
17#define LOG 1
18
19/***************************************************************************
20    TYPE DEFINITIONS
21***************************************************************************/
22
23typedef struct _mm74c922_t mm74c922_t;
24struct _mm74c922_t
25{
26   devcb_resolved_read8      in_x_func[5];
27   devcb_resolved_write_line   out_da_func;
28
29   int inhibit;               /* scan counter clock inhibit */
30   int x;                     /* currently scanned column */
31   int y;                     /* latched row */
32   int max_y;                  /* number of rows */
33
34   UINT8 data;                  /* data latch */
35
36   int da;                     /* data available flag */
37   int next_da;               /* next value of data available flag */
38
39   /* timers */
40   emu_timer *scan_timer;         /* keyboard scan timer */
41};
42
43/***************************************************************************
44    INLINE FUNCTIONS
45***************************************************************************/
46
47INLINE mm74c922_t *get_safe_token(const device_config *device)
48{
49   assert(device != NULL);
50   assert(device->token != NULL);
51   return (mm74c922_t *)device->token;
52}
53
54INLINE const mm74c922_interface *get_interface(const device_config *device)
55{
56   assert(device != NULL);
57   assert((device->type == MM74C922) || (device->type == MM74C923));
58   return (const mm74c922_interface *) device->static_config;
59}
60
61/***************************************************************************
62    IMPLEMENTATION
63***************************************************************************/
64
65/*-------------------------------------------------
66    change_output_lines - change output line
67   state
68-------------------------------------------------*/
69
70static void change_output_lines(const device_config *device)
71{
72   mm74c922_t *mm74c922 = get_safe_token(device);
73
74   if (mm74c922->next_da != mm74c922->da)
75   {
76      mm74c922->da = mm74c922->next_da;
77
78      if (LOG) logerror("MM74C922 '%s' Data Available: %u\n", device->tag, mm74c922->da);
79
80      devcb_call_write_line(&mm74c922->out_da_func, mm74c922->da);
81   }
82}
83
84/*-------------------------------------------------
85    clock_scan_counters - clock the keyboard
86   scan counters
87-------------------------------------------------*/
88
89static void clock_scan_counters(const device_config *device)
90{
91   mm74c922_t *mm74c922 = get_safe_token(device);
92
93   if (!mm74c922->inhibit)
94   {
95      mm74c922->x++;
96      mm74c922->x &= 0x03;
97   }
98}
99
100/*-------------------------------------------------
101    detect_keypress - detect key press
102-------------------------------------------------*/
103
104static void detect_keypress(const device_config *device)
105{
106   mm74c922_t *mm74c922 = get_safe_token(device);
107
108   if (mm74c922->inhibit)
109   {
110      UINT8 data = devcb_call_read8(&mm74c922->in_x_func[mm74c922->x], 0);
111
112      if (BIT(data, mm74c922->y))
113      {
114         /* key released */
115         mm74c922->inhibit = 0;
116         mm74c922->next_da = 0;
117         mm74c922->data = 0xff; // high-Z
118
119         if (LOG) logerror("MM74C922 '%s' Key Released\n", device->tag);
120      }
121   }
122   else
123   {
124      UINT8 data = devcb_call_read8(&mm74c922->in_x_func[mm74c922->x], 0);
125      int y;
126
127      for (y = 0; y < mm74c922->max_y; y++)
128      {
129         if (!BIT(data, y))
130         {
131            /* key depressed */
132            mm74c922->inhibit = 1;
133            mm74c922->next_da = 1;
134            mm74c922->y = y;
135
136            mm74c922->data = (y << 2) | mm74c922->x;
137
138            if (LOG) logerror("MM74C922 '%s' Key Depressed: X %u Y %u = %02x\n", device->tag, mm74c922->x, y, mm74c922->data);
139            return;
140         }
141      }
142   }
143}
144
145/*-------------------------------------------------
146    TIMER_CALLBACK( mm74c922_scan_tick )
147-------------------------------------------------*/
148
149static TIMER_CALLBACK( mm74c922_scan_tick )
150{
151   const device_config *device = ptr;
152
153   change_output_lines(device);
154   clock_scan_counters(device);
155   detect_keypress(device);
156}
157
158/*-------------------------------------------------
159    mm74c922_data_r - interface retrieving
160    keyboard data
161-------------------------------------------------*/
162
163READ8_DEVICE_HANDLER( mm74c922_r )
164{
165   mm74c922_t *mm74c922 = get_safe_token(device);
166
167   if (LOG) logerror("MM74C922 '%s' Data Read: %02x\n", device->tag, mm74c922->data);
168
169   return mm74c922->data;
170}
171
172/*-------------------------------------------------
173    DEVICE_START( mm74c922 )
174-------------------------------------------------*/
175
176static DEVICE_START( mm74c922 )
177{
178   mm74c922_t *mm74c922 = get_safe_token(device);
179   const mm74c922_interface *intf = get_interface(device);
180
181   /* resolve callbacks */
182   devcb_resolve_read8(&mm74c922->in_x_func[0], &intf->in_x1_func, device);
183   devcb_resolve_read8(&mm74c922->in_x_func[1], &intf->in_x2_func, device);
184   devcb_resolve_read8(&mm74c922->in_x_func[2], &intf->in_x3_func, device);
185   devcb_resolve_read8(&mm74c922->in_x_func[3], &intf->in_x4_func, device);
186   devcb_resolve_read8(&mm74c922->in_x_func[4], &intf->in_x5_func, device);
187   devcb_resolve_write_line(&mm74c922->out_da_func, &intf->out_da_func, device);
188
189   /* set initial values */
190   mm74c922->next_da = 0;
191   change_output_lines(device);
192
193   if (device->type == MM74C922)
194   {
195      mm74c922->max_y = 4;
196   }
197   else
198   {
199      mm74c922->max_y = 5;
200   }
201
202   /* create the timers */
203   mm74c922->scan_timer = timer_alloc(device->machine, mm74c922_scan_tick, (void *)device);
204   timer_adjust_periodic(mm74c922->scan_timer, attotime_zero, 0, ATTOTIME_IN_HZ(50));
205
206   /* register for state saving */
207   state_save_register_device_item(device, 0, mm74c922->inhibit);
208   state_save_register_device_item(device, 0, mm74c922->x);
209   state_save_register_device_item(device, 0, mm74c922->y);
210   state_save_register_device_item(device, 0, mm74c922->max_y);
211   state_save_register_device_item(device, 0, mm74c922->data);
212   state_save_register_device_item(device, 0, mm74c922->da);
213   state_save_register_device_item(device, 0, mm74c922->next_da);
214}
215
216/*-------------------------------------------------
217    DEVICE_GET_INFO( mm74c922 )
218-------------------------------------------------*/
219
220DEVICE_GET_INFO( mm74c922 )
221{
222   switch (state)
223   {
224      /* --- the following bits of info are returned as 64-bit signed integers --- */
225      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(mm74c922_t);            break;
226      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
227      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
228
229      /* --- the following bits of info are returned as pointers to data or functions --- */
230      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(mm74c922);   break;
231      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
232      case DEVINFO_FCT_RESET:                     /* Nothing */                        break;
233
234      /* --- the following bits of info are returned as NULL-terminated strings --- */
235      case DEVINFO_STR_NAME:                     strcpy(info->s, "Fairchild MM74C922");      break;
236      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Fairchild MM74C922");      break;
237      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
238      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
239      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright MESS Team");      break;
240   }
241}
242
243/*-------------------------------------------------
244    DEVICE_GET_INFO( mm74c923 )
245-------------------------------------------------*/
246
247DEVICE_GET_INFO( mm74c923 )
248{
249   switch (state)
250   {
251      /* --- the following bits of info are returned as 64-bit signed integers --- */
252      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(mm74c922_t);            break;
253      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
254      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
255
256      /* --- the following bits of info are returned as pointers to data or functions --- */
257      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(mm74c922);   break;
258      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
259      case DEVINFO_FCT_RESET:                     /* Nothing */                        break;
260
261      /* --- the following bits of info are returned as NULL-terminated strings --- */
262      case DEVINFO_STR_NAME:                     strcpy(info->s, "Fairchild MM74C923");      break;
263      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Fairchild MM74C922");      break;
264      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
265      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
266      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright MESS Team");      break;
267   }
268}
src/mess/machine/mm74c922.h
r0r5261
1/**********************************************************************
2
3    Fairchild MM74C922/MM74C923 16/20-Key Encoder emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                     _____   _____
10            ROW Y1   1 |*    \_/     | 18  Vcc
11            ROW Y2   2 |          | 17  DATA OUT A
12            ROW Y3   3 |          | 16  DATA OUT B
13             ROW Y4   4 |          | 15  DATA OUT C
14         OSCILLATOR   5 |  MM74C922    | 14  DATA OUT D
15      KEYBOUNCE MASK   6 |          | 13  _OUTPUT ENABLE
16          COLUMN X4   7 |          | 12  DATA AVAILABLE
17          COLUMN X3   8 |          | 11  COLUMN X1
18               GND   9 |_____________| 10  COLUMN X2
19
20                     _____   _____
21            ROW Y1    1 |*    \_/     | 20  Vcc
22            ROW Y2    2 |          | 19  DATA OUT A
23            ROW Y3   3 |          | 18  DATA OUT B
24             ROW Y4    4 |          | 17  DATA OUT C
25             ROW Y5    5 |  MM74C923    | 16  DATA OUT D
26         OSCILLATOR   6 |          | 15  DATA OUT E
27      KEYBOUNCE MASK   7 |          | 14  _OUTPUT ENABLE
28          COLUMN X4   8 |          | 13  DATA AVAILABLE
29          COLUMN X3   9 |          | 12  COLUMN X1
30               GND  10 |_____________| 11  COLUMN X2
31
32**********************************************************************/
33
34#ifndef __MM74C922__
35#define __MM74C922__
36
37#include "driver.h"
38#include "devcb.h"
39
40/***************************************************************************
41    MACROS / CONSTANTS
42***************************************************************************/
43
44#define MM74C922 DEVICE_GET_INFO_NAME( mm74c922 )
45#define MM74C923 DEVICE_GET_INFO_NAME( mm74c923 )
46
47#define MDRV_MM74C922_ADD(_tag, _intrf) \
48   MDRV_DEVICE_ADD(_tag, MM74C922, 0) \
49   MDRV_DEVICE_CONFIG(_intrf)
50
51#define MDRV_MM74C923_ADD(_tag, _intrf) \
52   MDRV_DEVICE_ADD(_tag, MM74C923, 0) \
53   MDRV_DEVICE_CONFIG(_intrf)
54
55#define MM74C922_INTERFACE(name) \
56   const mm74c922_interface (name)=
57
58#define MM74C923_INTERFACE(name) \
59   const mm74c922_interface (name)=
60
61/***************************************************************************
62    TYPE DEFINITIONS
63***************************************************************************/
64
65typedef struct _mm74c922_interface mm74c922_interface;
66struct _mm74c922_interface
67{
68   devcb_read8         in_x1_func;
69   devcb_read8         in_x2_func;
70   devcb_read8         in_x3_func;
71   devcb_read8         in_x4_func;
72   devcb_read8         in_x5_func;
73
74   devcb_write_line   out_da_func;
75
76   double            cap_osc;
77   double            cap_debounce;
78};
79
80/***************************************************************************
81    PROTOTYPES
82***************************************************************************/
83
84/* device interface */
85DEVICE_GET_INFO( mm74c922 );
86DEVICE_GET_INFO( mm74c923 );
87
88/* data read */
89READ8_DEVICE_HANDLER( mm74c922_r );
90
91#endif
src/mess/mess.mak
r5260r5261
438438   $(MESS_MACHINE)/mc6846.o   \
439439   $(MESS_MACHINE)/mc6854.o   \
440440   $(MESS_MACHINE)/mm58274c.o   \
441   $(MESS_MACHINE)/mm74c922.o   \
441442   $(MESS_MACHINE)/mpc105.o   \
442443   $(MESS_MACHINE)/msm58321.o   \
443444   $(MESS_MACHINE)/msm8251.o   \
src/mess/drivers/elf.c
r5260r5261
88
99   TODO:
1010
11   - TTL74C923
1211   - keyboard
1312   - Q led
1413   - DMAIN
r5260r5261
2019#include "driver.h"
2120#include "includes/elf.h"
2221#include "cpu/cdp1802/cdp1802.h"
22#include "devices/cassette.h"
23#include "machine/mm74c922.h"
2324#include "video/cdp1861.h"
2425#include "video/dm9368.h"
25#include "devices/cassette.h"
26#include "machine/rescap.h"
2627#include "elf2.lh"
2728
2829/* Read/Write Handlers */
r5260r5261
174175   DEVCB_HANDLER(elf2_dma_w)
175176};
176177
178/* MM74C923 Interface */
179
180static WRITE_LINE_DEVICE_HANDLER( mm74c923_da_w )
181{
182}
183
184static MM74C922_INTERFACE( keyboard_intf )
185{
186   DEVCB_INPUT_PORT("X1"),
187   DEVCB_INPUT_PORT("X2"),
188   DEVCB_INPUT_PORT("X3"),
189   DEVCB_INPUT_PORT("X4"),
190   DEVCB_NULL,
191   DEVCB_LINE(mm74c923_da_w),
192   CAP_U(0.15),
193   CAP_U(1)
194};
195
177196/* CDP1861 Interface */
178197
179198static VIDEO_UPDATE( elf2 )
r5260r5261
209228
210229   /* find devices */
211230   state->cdp1861 = devtag_get_device(machine, CDP1861_TAG);
212   state->_74c923 = devtag_get_device(machine, _74C923_TAG);
231   state->mm74c923 = devtag_get_device(machine, MM74C923_TAG);
213232   state->dm9368_l = devtag_get_device(machine, DM9368_L_TAG);
214233   state->dm9368_h = devtag_get_device(machine, DM9368_H_TAG);
215234   state->cassette = devtag_get_device(machine, CASSETTE_TAG);
r5260r5261
248267   MDRV_PALETTE_INIT(black_and_white)
249268   MDRV_VIDEO_UPDATE(elf2)
250269
270   MDRV_MM74C923_ADD(MM74C923_TAG, keyboard_intf)
251271   MDRV_DM9368_ADD(DM9368_H_TAG, 0, NULL)
252272   MDRV_DM9368_ADD(DM9368_L_TAG, 1, NULL)
253273   MDRV_CDP1861_ADD(CDP1861_TAG, XTAL_3_579545MHz/2, elf2_cdp1861_intf)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team