Previous 15994 Revisions Next

r14932 Sunday 15th April, 2012 at 02:47:16 UTC by Robbbert
Switch i8279 over to version in emu/machine
[src/emu]emu.mak
[src/mess]mess.mak
[src/mess/machine]i8279.c i8279.h

src/emu/emu.mak
r14931r14932
186186   $(EMUMACHINE)/i8243.o      \
187187   $(EMUMACHINE)/i8251.o      \
188188   $(EMUMACHINE)/i8255.o      \
189   $(EMUMACHINE)/i8279.o      \
189190   $(EMUMACHINE)/i8355.o      \
190191   $(EMUMACHINE)/idectrl.o      \
191192   $(EMUMACHINE)/im6402.o      \
src/mess/machine/i8279.c
r14931r14932
1/**********************************************************************
2
3    i8279
4
52012-JAN-08 First draft [Robbbert]
62012-JAN-12 Implemented
7
8Notes:
9- All keys MUST be ACTIVE_LOW
10
11
12ToDo:
13- Command 5 (Nibble masking and blanking)
14- Command 7 (Error Mode)
15- Interrupts
16- BD pin
17- Sensor ram stuff
18- save state
19
20
21What has been done:
22CMD 0:
23- Display Mode
24-- Left & Right with no increment are the same thing
25-- Right with increment is not emulated yet ***
26- Keyboard Mode
27-- No particular code has been added for 2-key/N-key rollover, no need
28-- Sensor mode is not complete yet ***
29-- Encoded and Decoded are done
30-- Strobe is done
31-- Sensor and FIFO may share the same internal RAM, not sure
32CMD 1:
33- Clock Divider
34-- Value is stored, but internally a fixed value is always used
35CMD 2:
36- Read FIFO/Sensor RAM
37-- FIFO works
38-- Sensor not done yet ***
39CMD 3:
40- Read Display RAM
41-- This works
42CMD 4:
43- Write Display RAM
44-- Right with increment does nothing, the rest is working ***
45CMD 5:
46- Blank Nibble
47-- Not done ***
48- Mask Nibble
49-- Not done ***
50CMD 6:
51-- All implemented
52CMD 7:
53- Interrupt
54-- Not done
55- Error Mode
56-- No need to do.
57
58Interface:
59-- All done except BD pin ***
60
61Status word:
62- FIFO bits
63-- All done
64- Error bit
65-- Not done (no need)
66- Display unavailable
67-- Not done (no need)
68
69
70Items marked (***) can be added if a system appears
71that uses this feature.
72
73**********************************************************************/
74
75#include "i8279.h"
76
77
78//**************************************************************************
79//  LIVE DEVICE
80//**************************************************************************
81
82// device type definition
83const device_type I8279 = &device_creator<i8279_device>;
84
85//-------------------------------------------------
86//  i8279_device - constructor
87//-------------------------------------------------
88
89i8279_device::i8279_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
90    : device_t(mconfig, I8279, "Intel 8279", tag, owner, clock)
91{
92}
93
94//-------------------------------------------------
95//  device_config_complete - perform any
96//  operations now that the configuration is
97//  complete
98//-------------------------------------------------
99
100void i8279_device::device_config_complete()
101{
102   // inherit a copy of the static data
103   const i8279_interface *intf = reinterpret_cast<const i8279_interface *>(static_config());
104   if (intf != NULL)
105   {
106      *static_cast<i8279_interface *>(this) = *intf;
107   }
108
109   // or initialize to defaults if none provided
110   else
111   {
112       memset(&m_out_irq_cb, 0, sizeof(m_out_irq_cb));
113       memset(&m_out_sl_cb, 0, sizeof(m_out_sl_cb));
114       memset(&m_out_disp_cb, 0, sizeof(m_out_disp_cb));
115       memset(&m_out_bd_cb, 0, sizeof(m_out_bd_cb));
116       memset(&m_in_rl_cb, 0, sizeof(m_in_rl_cb));
117       memset(&m_in_shift_cb, 0, sizeof(m_in_shift_cb));
118       memset(&m_in_ctrl_cb, 0, sizeof(m_in_ctrl_cb));
119   }
120}
121
122
123//-------------------------------------------------
124//  device_start - device-specific startup
125//-------------------------------------------------
126
127void i8279_device::device_start()
128{
129   /* resolve callbacks */
130   m_out_irq_func.resolve(m_out_irq_cb, *this);
131   m_out_sl_func.resolve(m_out_sl_cb, *this);
132   m_out_disp_func.resolve(m_out_disp_cb, *this);
133   m_out_bd_func.resolve(m_out_bd_cb, *this);
134   m_in_rl_func.resolve(m_in_rl_cb, *this);
135   m_in_shift_func.resolve(m_in_shift_cb, *this);
136   m_in_ctrl_func.resolve(m_in_ctrl_cb, *this);
137   m_clock = clock();
138   m_timer = machine().scheduler().timer_alloc(FUNC(timerproc_callback), (void *)this);
139}
140
141
142//-------------------------------------------------
143//  device_reset - device-specific reset
144//-------------------------------------------------
145
146void i8279_device::device_reset()
147{
148   UINT8 i;
149
150   // startup values are unknown: setting to 0
151   for (i = 2; i < 8; i++) m_cmd[i] = 0;
152   for (i = 0; i < 8; i++) m_fifo[i] = 0;
153   for (i = 0; i < 8; i++) m_s_ram[i] = 0;
154   for (i = 0; i < 16; i++) m_d_ram[i] = 0;
155   m_status = 0;
156   m_autoinc = 1;
157   m_d_ram_ptr = 0;
158   m_s_ram_ptr = 0;
159   m_read_flag = 0;
160   m_scanner = 0;
161   m_ctrl_key = 1;
162   m_key_down = 0xffff;
163
164   // from here is confirmed
165   m_cmd[0] = 8;
166   m_cmd[1] = 31;
167   logerror("Initial clock = 3100kHz\n");
168   timer_adjust();
169}
170
171
172void i8279_device::timer_adjust()
173{
174// Real device runs at about 100kHz internally, clock divider is chosen so that
175// this is the case. We do not need such speed, 200Hz is enough.
176
177   //UINT8 divider = (m_cmd[1]) ? m_cmd[1] : 1;
178   //m_clock = clock() / divider;
179
180   m_clock = 200;
181   m_timer->adjust(attotime::from_hz(m_clock), 0, attotime::from_hz(m_clock));
182}
183
184
185void i8279_device::clear_display()
186{
187   // clear all digits
188   UINT8 i,patterns[4] = { 0, 0, 0x20, 0xff };
189   UINT8 data = patterns[(m_cmd[6] & 12) >> 2];
190
191   // The CD high bit (also done by CA)
192   if (m_cmd[6] & 11)
193      for (i = 0; i < 16; i++)
194         m_d_ram[i] = data;
195
196   m_status &= 0x7f; // bit 7 not emulated, but do it anyway
197   m_d_ram_ptr = 0; // not in the datasheet, but needed
198
199   // The CF bit (also done by CA)
200   if (m_cmd[6] & 3)
201   {
202      m_status &= 0xc0; // blow away fifo
203      m_s_ram_ptr = 0; // reset sensor pointer
204      set_irq(0); // reset irq
205   }
206}
207
208
209void i8279_device::set_irq(bool state)
210{
211   if ( !m_out_irq_func.isnull() )
212      m_out_irq_func( state );
213}
214
215
216void i8279_device::new_key(UINT8 data, bool skey, bool ckey)
217{
218   UINT8 i, rl, sl;
219   for (i = 0; BIT(data, i); i++);
220   rl = i;
221   if (BIT(m_cmd[0], 0))
222   {
223      for (i = 0; !BIT(data, i); i++);
224      sl = i;
225   }
226   else
227      sl = m_scanner;
228
229   new_fifo( (ckey << 7) | (skey << 6) | (sl << 3) | rl);
230}
231
232
233void i8279_device::new_fifo(UINT8 data)
234{
235   // see if already overrun
236   if (BIT(m_status, 5))
237      return;
238
239   // set overrun flag if full
240   if (BIT(m_status, 3))
241   {
242      m_status |= 0x20;
243      return;
244   }
245
246   m_fifo[m_status & 7] = data;
247
248   // bump fifo size & turn off underrun
249   UINT8 fifo_size = m_status & 7;
250   if ((fifo_size)==7)
251      m_status |= 8; // full
252   else
253      m_status = (m_status & 0xe8) + fifo_size + 1;
254
255   if (!fifo_size)
256      set_irq(1); // something just went into fifo, so int
257}
258
259
260TIMER_CALLBACK( i8279_device::timerproc_callback )
261{
262   reinterpret_cast<i8279_device*>(ptr)->timer_mainloop();
263}
264
265
266void i8279_device::timer_mainloop()
267{
268   // control byte 0
269   // bit 0 - encoded or decoded keyboard scan
270   // bits 1,2 - keyboard type
271   // bit 3 - number of digits to display
272   // bit 4 - left or right entry
273
274   UINT8 scanner_mask = BIT(m_cmd[0], 0) ? 15 : BIT(m_cmd[0], 3) ? 15 : 7;
275   bool decoded = BIT(m_cmd[0], 0);
276   UINT8 kbd_type = (m_cmd[0] & 6) >> 1;
277   bool shift_key = 1;
278   bool ctrl_key = 1;
279   bool strobe_pulse = 0;
280
281   // keyboard
282   // type 0 = kbd, 2-key lockout
283   // type 1 = kdb, n-key
284   // type 2 = sensor
285   // type 3 = strobed
286
287   // Get shift keys
288   if ( !m_in_shift_func.isnull() )
289      shift_key = m_in_shift_func();
290
291   if ( !m_in_ctrl_func.isnull() )
292      ctrl_key = m_in_ctrl_func();
293
294   if (ctrl_key && !m_ctrl_key)
295      strobe_pulse = 1; // low-to-high is a strobe
296
297   m_ctrl_key = ctrl_key;
298
299   // Read a row of keys
300
301   if ( !m_in_rl_func.isnull() )
302   {
303      UINT8 rl = m_in_rl_func(0);
304
305      // see if key still down from last time
306      UINT16 key_down = (m_scanner << 8) | rl;
307      if (key_down == m_key_down)
308         rl = 0xff;
309      else
310      if ((rl == 0xff) && (m_scanner == m_key_down >> 8))
311         m_key_down = 0xffff;
312
313      // now process new key
314      if (rl < 0xff)
315      {
316         m_key_down = key_down;
317         switch (kbd_type)
318         {
319            case 0:
320            case 1:
321               new_key(rl, shift_key, ctrl_key);
322               break;
323            case 2:
324               new_fifo(rl);
325               break;
326            case 3:
327               if (strobe_pulse) new_fifo(rl);
328               break;
329         }
330      }
331   }
332
333   // Increment scanline
334
335   if (decoded)
336   {
337      m_scanner<<= 1;
338      if ((m_scanner & 15)==0)
339         m_scanner = 1;
340   }
341   else
342      m_scanner++;
343
344   m_scanner &= scanner_mask; // 4-bit port
345
346   if ( !m_out_sl_func.isnull() )
347      m_out_sl_func(0, m_scanner);
348
349   // output a digit
350
351   if ( !m_out_disp_func.isnull() )
352      m_out_disp_func(0, m_d_ram[m_scanner] );
353}
354
355
356READ8_MEMBER( i8279_device::status_r )
357{
358   return m_status;
359}
360
361
362READ8_MEMBER( i8279_device::data_r )
363{
364   UINT8 i;
365   bool sensor_mode = ((m_cmd[0] & 6)==4);
366   UINT8 data;
367   if (m_read_flag)
368   {
369   // read the display ram
370      data = m_d_ram[m_d_ram_ptr];
371      if (m_autoinc)
372         m_d_ram_ptr++;
373   }
374   else
375   if (sensor_mode)
376   {
377   // read sensor ram
378      data = m_s_ram[m_s_ram_ptr];
379      if (m_autoinc)
380         m_s_ram_ptr++;
381   }
382   else
383   {
384   // read a key from fifo
385      data = m_fifo[0];
386      UINT8 fifo_size = m_status & 7;
387      switch (m_status & 0x38)
388      {
389         case 0x00: // no errors
390            if (!fifo_size)
391               m_status |= 0x10; // underrun
392            else
393            {
394               for (i = 1; i < 8; i++)
395                  m_fifo[i-1] = m_fifo[i];
396               fifo_size--;
397               if (!fifo_size)
398                  set_irq(0);
399            }
400            break;
401         case 0x28: // overrun
402         case 0x08: // fifo full
403            for (i = 1; i < 8; i++)
404               m_fifo[i-1] = m_fifo[i];
405            break;
406         case 0x10: // underrun
407            if (!fifo_size)
408               break;
409         default:
410            printf("Invalid status: %X\n", m_status);
411      }
412      m_status = (m_status & 0xd0) | fifo_size; // turn off overrun & full
413   }
414
415   m_d_ram_ptr &= 15;
416   m_s_ram_ptr &= 7;
417   return data;
418}
419
420
421WRITE8_MEMBER( i8279_device::cmd_w )
422{//printf("Command: %X=%X ",data>>5,data&31);
423   UINT8 cmd = data >> 5;
424   data &= 0x1f;
425   m_cmd[cmd] = data;
426   switch (cmd)
427   {
428      case 1:
429         if (data > 1)
430         {
431            logerror("Clock set to %dkHz\n",data*100);
432            timer_adjust();
433         }
434         break;
435      case 2:
436         m_read_flag = 0;
437         if ((m_cmd[0] & 6)==4) // sensor mode only
438         {
439            m_autoinc = BIT(data, 4);
440            m_s_ram_ptr = data & 7;
441         }
442         break;
443      case 3:
444         m_read_flag = 1;
445         m_d_ram_ptr = data & 15;
446         m_autoinc = BIT(data, 4);
447         break;
448      case 4:
449         m_d_ram_ptr = data & 15;
450         m_autoinc = BIT(data, 4);
451         break;
452      case 6:
453         clear_display();
454         break;
455   }
456}
457
458
459WRITE8_MEMBER( i8279_device::data_w )
460{//printf("Data: %X ",data);
461   if (BIT(m_cmd[0], 4) & m_autoinc)
462   {
463   // right-entry autoincrement not implemented yet
464   }
465   else
466   {
467      m_d_ram[m_d_ram_ptr] = data;
468      if (m_autoinc)
469         m_d_ram_ptr++;
470   }
471   m_d_ram_ptr &= 15;
472}
473
src/mess/machine/i8279.h
r14931r14932
1/***************************************************************************
2
3    Intel 8279 Programmable Keyboard/Display Interface emulation
4
5    Copyright the MESS Team 2012.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8****************************************************************************
9                            _____   _____
10                   RL2   1 |*    \_/     | 40  Vcc
11                   RL3   2 |             | 39  RL1
12                   CLK   3 |             | 38  RL0
13                   IRQ   4 |             | 37  CNTL/STB
14                   RL4   5 |             | 36  SHIFT
15                   RL5   6 |             | 35  SL3
16                   RL6   7 |             | 34  SL2
17                   RL7   8 |             | 33  SL1
18                 RESET   9 |             | 32  SL0
19                   /RD  10 |     8279    | 31  B0
20                   /WR  11 |             | 30  B1
21                   DB0  12 |             | 29  B2
22                   DB1  13 |             | 28  B3
23                   DB2  14 |             | 27  A0
24                   DB3  15 |             | 26  A1
25                   DB4  16 |             | 25  A2
26                   DB5  17 |             | 24  A3
27                   DB6  18 |             | 23  /BD
28                   DB7  19 |             | 22  /CS
29                   Vss  20 |_____________| 21  CTRL/DATA
30
31
32***************************************************************************/
33
34#pragma once
35
36#ifndef __I8279__
37#define __I8279__
38
39#include "emu.h"
40
41
42
43/***************************************************************************
44    DEVICE CONFIGURATION MACROS
45***************************************************************************/
46
47#define MCFG_I8279_ADD(_tag, _clock, _config) \
48   MCFG_DEVICE_ADD(_tag, I8279, _clock) \
49   MCFG_DEVICE_CONFIG(_config)
50
51#define I8279_INTERFACE(_name) \
52   const i8279_interface (_name) =
53
54
55/***************************************************************************
56    TYPE DEFINITIONS
57***************************************************************************/
58
59
60// ======================> i8279_interface
61
62struct i8279_interface
63{
64   devcb_write_line   m_out_irq_cb;      // IRQ
65   devcb_write8      m_out_sl_cb;      // Scanlines SL0-3
66   devcb_write8      m_out_disp_cb;      // B0-3,A0-3
67   devcb_write_line   m_out_bd_cb;      // BD
68   devcb_read8      m_in_rl_cb;      // kbd readlines RL0-7
69   devcb_read_line      m_in_shift_cb;      // Shift key
70   devcb_read_line      m_in_ctrl_cb;      // Ctrl-Strobe line
71};
72
73
74
75// ======================> i8279_device
76
77class i8279_device :  public device_t, public i8279_interface
78{
79public:
80   // construction/destruction
81   i8279_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
82
83   // read & write handlers
84   DECLARE_READ8_MEMBER(status_r);
85   DECLARE_READ8_MEMBER(data_r);
86   DECLARE_WRITE8_MEMBER(cmd_w);
87   DECLARE_WRITE8_MEMBER(data_w);
88   void timer_mainloop();
89
90protected:
91   // device-level overrides
92   virtual void device_config_complete();
93   virtual void device_start();
94   virtual void device_reset();
95   virtual void device_post_load() { }
96   virtual void device_clock_changed() { }
97
98   static TIMER_CALLBACK( timerproc_callback );
99
100private:
101
102   void timer_adjust();
103   void clear_display();
104   void new_key(UINT8 data, bool skey, bool ckey);
105   void new_fifo(UINT8 data);
106   UINT8 get_segments();
107   void set_irq(bool state);
108   void set_display_mode(UINT8 data);
109
110   devcb_resolved_write_line   m_out_irq_func;
111   devcb_resolved_write8      m_out_sl_func;
112   devcb_resolved_write8      m_out_disp_func;
113   devcb_resolved_write_line   m_out_bd_func;
114   devcb_resolved_read8      m_in_rl_func;
115   devcb_resolved_read_line   m_in_shift_func;
116   devcb_resolved_read_line   m_in_ctrl_func;
117
118   emu_timer *m_timer;
119
120   UINT8 m_d_ram[16];      // display ram
121   UINT8 m_d_ram_ptr;
122   UINT8 m_s_ram[8]; // might be same as fifo ram
123   UINT8 m_s_ram_ptr;
124   UINT8 m_fifo[8];    // queued keystrokes
125   UINT8 m_cmd[8];   // Device settings
126   UINT8 m_status;     // Returned via status_r
127   UINT32 m_clock;     // Internal scan clock
128   UINT8 m_scanner;    // next output on SL lines
129
130   bool m_autoinc;     // auto-increment flag
131   bool m_read_flag;   // read from where
132   bool m_ctrl_key;    // previous state of strobe input
133   UINT16 m_key_down;
134};
135
136
137// device type definition
138extern const device_type I8279;
139
140
141
142#endif
src/mess/mess.mak
r14931r14932
480480   $(MAME_VIDEO)/cps1.o   \
481481   $(MAME_DRIVERS)/konamim2.o \
482482
483
483484#-------------------------------------------------
484485# the following files are general components and
485486# shared across a number of drivers
r14931r14932
499500   $(MESS_MACHINE)/i82371sb.o   \
500501   $(MESS_MACHINE)/i82439tx.o   \
501502   $(MESS_MACHINE)/i8271.o      \
502   $(MESS_MACHINE)/i8279.o      \
503503   $(MESS_MACHINE)/ieee488.o   \
504504   $(MESS_MACHINE)/isa.o      \
505505   $(MESS_MACHINE)/kb3600.o   \
r14931r14932
640640   $(MESS_MACHINE)/apple2gs.o   \
641641   $(MESS_DRIVERS)/apple2gs.o   \
642642   $(MESS_MACHINE)/ay3600.o   \
643    $(MESS_MACHINE)/a2bus.o     \
643   $(MESS_MACHINE)/a2bus.o     \
644644   $(MESS_MACHINE)/a2lang.o   \
645645   $(MESS_MACHINE)/a2diskii.o   \
646646   $(MESS_MACHINE)/a2mockingboard.o   \
647647   $(MESS_MACHINE)/a2cffa.o   \
648    $(MESS_MACHINE)/a2memexp.o  \
649    $(MESS_MACHINE)/a2scsi.o    \
650    $(MESS_MACHINE)/a2thunderclock.o    \
651    $(MESS_MACHINE)/a2softcard.o \
648   $(MESS_MACHINE)/a2memexp.o  \
649   $(MESS_MACHINE)/a2scsi.o    \
650   $(MESS_MACHINE)/a2thunderclock.o    \
651   $(MESS_MACHINE)/a2softcard.o \
652652   $(MESS_MACHINE)/lisa.o      \
653653   $(MESS_DRIVERS)/lisa.o      \
654654   $(MESS_MACHINE)/nubus.o     \

Previous 15994 Revisions Next


© 1998-2018 The MESS Team