Previous 15994 Revisions Next

r3553 Wednesday 19th November, 2008 at 09:07:58 UTC by Miodrag Milanović
[PECOM] Plain and simple keyboard implementation
[src/mess/machine]pecom.c

src/mess/machine/pecom.c
r3552r3553
1212#include "devices/cassette.h"
1313#include "includes/pecom.h"
1414 
15UINT8 pecom_caps_state = 4;
16UINT8 pecom_prev_caps_state = 4;
15static UINT8 pecom_caps_state = 4;
16static UINT8 pecom_prev_caps_state = 4;
1717 
18static UINT8 pecom_key_press_line;
19static UINT8 pecom_key_pressed;
20static UINT8 pecom_key_state = 0;
21static UINT8 pecom_prev_key_state = 0;
22static UINT8 pecom_key_read_line = 0;
23static UINT8 pecom_key_real = 0;
24 
25 
2618/* Driver initialization */
2719DRIVER_INIT(pecom)
2820{
r3552r3553
6052   
6153   pecom_caps_state = 4;
6254   pecom_prev_caps_state = 4;
63   
64   pecom_key_press_line = 0;
65   pecom_key_pressed = 0;
66   pecom_key_state = 0;
67   pecom_prev_key_state = 0;   
68   pecom_key_read_line = 0;
69   
55 
7056   state->cdp1802_mode = CDP1802_MODE_RESET;
7157   state->dma = 0;
7258   timer_adjust_oneshot(state->reset_timer, ATTOTIME_IN_MSEC(5), 0);
r3552r3553
9783READ8_HANDLER (pecom_keyboard_r)
9884{
9985   static const char *keynames[] = {    "LINE0", "LINE1", "LINE2", "LINE3", "LINE4", "LINE5", "LINE6", "LINE7",
100                           "LINE8", "LINE9", "LINE10", "LINE11", "LINE12", "LINE13", "LINE14", "LINE15", "LINE16",
101                           "LINE17", "LINE18", "LINE19", "LINE20", "LINE21", "LINE22", "LINE23", "LINE24","LINE25" };   
102   pecom_key_state =  input_port_read(machine, keynames[pecom_key_read_line]) & 0x03;   
103   // If key has been clicked
104   if ((pecom_key_pressed==0) &&(pecom_key_state!=0) && ((pecom_prev_key_state & pecom_key_state)==0)) {
105      // key is pressed 
106      pecom_key_press_line = pecom_key_read_line;
107      pecom_key_read_line  = 0;
108      pecom_key_pressed = 1; 
109      pecom_key_real = 0;
110   } else 
111   if (pecom_key_pressed==1 && pecom_key_read_line==pecom_key_press_line) {
112      // key is released
113      if ((pecom_key_state==0) && (pecom_key_real==0)) {
114         // if first read value is 0 then we act as button is already released
115         // so move to next as usual but mark as it is released
116         pecom_key_read_line++;
117         pecom_key_pressed = 0;
118         pecom_key_press_line = 0;   
119         pecom_key_real = 0;       
120      } else {       
121         // If button is not yet released then we need to give 
122         // read value until it became 0
123         if (pecom_key_real==0) { 
124            pecom_key_real = pecom_key_state; // Take first value while it is pressed         
125         }
126         
127         if ((pecom_key_state & pecom_key_real)!=pecom_key_real) {
128            // If key is released clear all counters
129            pecom_key_pressed = 0;
130            pecom_key_read_line = 0;
131            pecom_key_press_line = 0;   
132            pecom_key_real = 0;       
133         }
134      }
135   } 
136   else
137   {   
138      // Else just increment counter   
139      pecom_key_read_line++;
140      pecom_key_state = 0;
141   }     
142   if (pecom_key_read_line>25) {
143      pecom_key_read_line=0;
144   }
145   pecom_prev_key_state = pecom_key_state;
146   return pecom_key_state;
147   
86                              "LINE8", "LINE9", "LINE10", "LINE11", "LINE12", "LINE13", "LINE14", "LINE15", "LINE16",
87                              "LINE17", "LINE18", "LINE19", "LINE20", "LINE21", "LINE22", "LINE23", "LINE24","LINE25" };
88   /* 
89      INP command BUS -> M(R(X)) BUS -> D 
90      so on each input, address is also set, 8 lower bits are used as input for keyboard 
91      Address is available on address bus during reading of value from port, and that is 
92      used to determine keyboard line reading
93   */
94   UINT16 addr = cpunum_get_reg(0,CDP1802_R0 + cpunum_get_reg(0,CDP1802_X)) & 0xff;
95   /* just in case somone is reading non existing ports */
96   if (addr<0xca || addr>0xe3) return 0; 
97   return input_port_read(machine, keynames[addr - 0xca]) & 0x03;
14898}
14999 
150100/* CDP1802 Interface */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team