Previous 15994 Revisions Next

r4648 Friday 8th May, 2009 at 10:45:56 UTC by Curt Coder
[KYOCERA] Cleaned up RTC interface, separated video code.
[src/mess]mess.mak
[src/mess/drivers]kyocera.c
[src/mess/includes]kyocera.h*
[src/mess/machine]upd1990a.c upd1990a.h
[src/mess/video]kyocera.c*

src/mess/video/kyocera.c
r0r4648
1#include "driver.h"
2#include "includes/kyocera.h"
3
4static bitmap_t *tmpbitmap;
5static int bank;
6static UINT8 lcd[11][256];
7static UINT8 lcd_addr[10];
8
9void kyo85_set_lcd_bank(UINT16 data)
10{
11   switch (data)
12   {
13      case 0x000:   bank = 0; break;
14      case 0x001:   bank = 1; break;
15      case 0x002:   bank = 2; break;
16      case 0x004:   bank = 3; break;
17      case 0x008:   bank = 4; break;
18      case 0x010:   bank = 5; break;
19      case 0x020:   bank = 6; break;
20      case 0x040:   bank = 7; break;
21      case 0x080:   bank = 8; break;
22      case 0x100:   bank = 9; break;
23      case 0x200:   bank = 10; break;
24      default: /*logerror("pc8201: bank update with unk bank = %d\n", bank);*/ break;
25   }
26}
27
28static void increase(void) {
29   UINT8 addr = lcd_addr[bank];
30   int col = addr & 0x3f;
31   int row = addr >> 6;
32
33   col++;
34
35   if (bank == 5 || bank == 10)
36   {
37      if (col == 40)
38      {
39         col = 0;
40         row++;
41      }
42   }
43   else
44   {
45      if (col == 50)
46      {
47         col = 0;
48         row++;
49      }
50   }
51
52   lcd_addr[bank] = (row << 6) | col;
53}
54
55READ8_HANDLER( kyo85_lcd_status_r )
56{
57   return 0; // always ready
58}
59
60READ8_HANDLER( kyo85_lcd_data_r )
61{
62   UINT8 addr = lcd_addr[bank];
63
64   //logerror("LCD driver %u column %u row %u data read %02x\n", bank, addr & 0x3f, addr >> 6, lcd[bank][addr]);
65
66   increase();
67
68   return lcd[bank][addr];
69}
70
71WRITE8_HANDLER( kyo85_lcd_command_w )
72{
73   /*
74
75      bit      description
76
77      0      column bit 0
78      1      column bit 1
79      2      column bit 2
80      3      column bit 3
81      4      column bit 4
82      5      column bit 5
83      6      row bit 0
84      7      row bit 1
85
86   */
87
88   lcd_addr[bank] = data;
89
90   //logerror("LCD driver %u column %u row %u\n", bank, data & 0x3f, data >> 6);
91}
92
93WRITE8_HANDLER( kyo85_lcd_data_w )
94{
95   UINT8 addr = lcd_addr[bank];
96
97   int col = addr & 0x3f;
98   int row = addr >> 6;
99   int sx, sy, y;
100   
101   if (bank > 5)
102   {
103      sx = (bank - 6) * 50;
104      sy = 32;
105   }
106   else
107   {
108      sx = (bank - 1) * 50;
109      sy = 0;
110   }
111
112   sx += col;
113   sy += row * 8;
114
115   lcd[bank][addr] = data;
116   
117   for (y = 0; y < 8; y++)
118   {
119      int color = BIT(data, y);
120      *BITMAP_ADDR16(tmpbitmap, sy + y, sx) = color;
121   }
122
123   //logerror("LCD driver %u column %u row %u data write %02x\n", bank, addr & 0x3f, addr >> 6, data);
124
125   increase();
126}
127
128PALETTE_INIT( kyo85 )
129{
130   palette_set_color(machine, 0, MAKE_RGB(138, 146, 148));
131   palette_set_color(machine, 1, MAKE_RGB(92, 83, 88));
132}
133
134VIDEO_START( kyo85 )
135{
136   /* allocate the temporary bitmap */
137   tmpbitmap = auto_bitmap_alloc(240, 64, BITMAP_FORMAT_INDEXED16);
138}
139
140VIDEO_UPDATE( kyo85 )
141{
142   copybitmap(bitmap, tmpbitmap, 0, 0, 0, 0, cliprect);
143
144   return 0;
145}
src/mess/includes/kyocera.h
r0r4648
1#ifndef __KYOCERA__
2#define __KYOCERA__
3
4/* ---------- defined in video/kyocera.c ---------- */
5
6void kyo85_set_lcd_bank(UINT16 data);
7
8READ8_HANDLER( kyo85_lcd_status_r );
9READ8_HANDLER( kyo85_lcd_data_r );
10WRITE8_HANDLER( kyo85_lcd_command_w );
11WRITE8_HANDLER( kyo85_lcd_data_w );
12
13PALETTE_INIT( kyo85 );
14VIDEO_START( kyo85 );
15VIDEO_UPDATE( kyo85 );
16
17#endif
src/mess/machine/upd1990a.c
r4647r4648
55   NEC uPD1990AC CMOS Digital Integrated Circuit
66   Serial I/O Calendar & Clock
77   CMOS LSI
8   
9   Very preliminary emulation
10   
11   TODO:
12      - implement Set Clock mode
13      - implement TEST Mode
14      - what about data_in?
158
169*********************************************************************/
1710
11/*
12
13   TODO:
14
15   - set clock mode
16   - test mode
17   - clock advance (currently it just reads the system time)
18
19*/
20
1821#include "driver.h"
1922#include "upd1990a.h"
2023
21#define UPD1990AC_XTAL 32768
24/***************************************************************************
25    PARAMETERS
26***************************************************************************/
2227
28#define LOG 0
29
30enum
31{
32   UPD1990A_MODE_REGISTER_HOLD = 0,
33   UPD1990A_MODE_SHIFT,
34   UPD1990A_MODE_TIME_SET,
35   UPD1990A_MODE_TIME_READ,
36   UPD1990A_MODE_TP_64HZ_SET,
37   UPD1990A_MODE_TP_256HZ_SET,
38   UPD1990A_MODE_TP_2048HZ_SET,
39   UPD1990A_MODE_TEST,
40};
41
2342/***************************************************************************
2443    TYPE DEFINITIONS
2544***************************************************************************/
r4647r4648
2746typedef struct _upd1990a_t upd1990a_t;
2847struct _upd1990a_t
2948{
49   devcb_resolved_write_line   out_data_func;
3050   devcb_resolved_write_line   out_tp_func;
3151
32   UINT8 shift_reg[5];   /* 40 Bit Shift Register */
33   UINT8 data_in;
34   UINT8 data_out;
35   UINT8 shift_mode;
36   UINT16 freq_divider;
52   UINT8 time_counter[5];      /* time counter */
53   UINT8 shift_reg[5];         /* shift register */
54
55   int oe;                  /* output enable */
56   int cs;                  /* chip select */
57   int stb;               /* strobe */
58   int data_in;            /* data in */
59   int data_out;            /* data out */
60   int c;                  /* command */
61   int clk;               /* shift clock */
62   int tp;                  /* time pulse */
3763   
64   /* timers */
65   emu_timer *clock_timer;
66   emu_timer *data_out_timer;
3867   emu_timer *tp_timer;
3968};
4069
r4647r4648
4776   assert(device != NULL);
4877   assert(device->token != NULL);
4978   assert(device->type == UPD1990A);
50
5179   return (upd1990a_t *)device->token;
5280}
5381
r4647r4648
5886   return (const upd1990a_interface *) device->static_config;
5987}
6088
89INLINE UINT8 convert_to_bcd(int val)
90{
91   return ((val / 10) << 4) | (val % 10);
92}
93
6194/***************************************************************************
6295    IMPLEMENTATION
6396***************************************************************************/
6497
65static UINT8 upd1990a_bcd( UINT8 val )
98/*-------------------------------------------------
99    upd1990a_oe_w - output enable write
100-------------------------------------------------*/
101
102WRITE_LINE_DEVICE_HANDLER( upd1990a_oe_w )
66103{
67   return ((val / 10) << 4) | (val % 10);
104   upd1990a_t *upd1990a = get_safe_token(device);
105
106   upd1990a->oe = state;
107
108   if (LOG) logerror("UPD1990A OE %u\n", state);
68109}
69110
70WRITE8_DEVICE_HANDLER( upd1990a_w )
111/*-------------------------------------------------
112    upd1990a_oe_w - output enable write
113-------------------------------------------------*/
114
115WRITE_LINE_DEVICE_HANDLER( upd1990a_cs_w )
71116{
72   UINT8 command = data & 0x07;
73117   upd1990a_t *upd1990a = get_safe_token(device);
74   mame_system_time curtime, *systime = &curtime;
75   int i;
76118
77   if (data & ~0x07)
78      logerror("uPD1990AC expects only 3 bits data, found %d > 7\n", data);
119   upd1990a->cs = state;
79120
80   mame_get_current_datetime(device->machine, &curtime);
121   if (LOG) logerror("UPD1990A CS %u\n", state);
122}
81123
82   /*
83       c0 = command bit 0
84       c1 = command bit 1
85       c2 = command bit 2
124/*-------------------------------------------------
125    upd1990a_stb_w - strobe write
126-------------------------------------------------*/
86127
87       c2   c1   c0  |  Function
88      ----------------------------
89        0    0    0  |  Register Hold (TEST Mode released)
90        0    0    1  |  Register Shift
91        0    1    0  |  Timer Set & Counter Hold
92        0    1    1  |  Timer Read
93        1    0    0  |  TP = 64Hz Set (TEST Mode released)
94        1    0    1  |  TP = 256Hz Set (TEST Mode released)
95        1    1    0  |  TP = 2048z Set (TEST Mode released)
96        1    1    1  |  TEST Mode Set
97   */
128WRITE_LINE_DEVICE_HANDLER( upd1990a_stb_w )
129{
130   upd1990a_t *upd1990a = get_safe_token(device);
98131
99   switch (command)
132   if (LOG) logerror("UPD1990A STB %u\n", state);
133
134   upd1990a->stb = state;
135
136   if (upd1990a->cs && upd1990a->stb && !upd1990a->clk)
100137   {
101      case 0x00:
102         upd1990a->shift_mode = 0;
138      switch (upd1990a->c)
139      {
140      case UPD1990A_MODE_REGISTER_HOLD:
141         if (LOG) logerror("UPD1990A Register Hold Mode\n");
142
143         /* enable time counter */
144         timer_enable(upd1990a->clock_timer, 1);
145
146         /* 1 Hz data out pulse */
147         upd1990a->data_out = 1;
148         timer_adjust_periodic(upd1990a->data_out_timer, attotime_zero, 0, ATTOTIME_IN_HZ(1*2));
149
150         /* 64 Hz time pulse */
151         timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(64*2));
103152         break;
104      case 0x01:
105         upd1990a->shift_mode = 1;
106         upd1990a->data_out = upd1990a->shift_reg[0] & 0x01;
153
154      case UPD1990A_MODE_SHIFT:
155         if (LOG) logerror("UPD1990A Shift Mode\n");
156         /* enable time counter */
157         timer_enable(upd1990a->clock_timer, 1);
158
159         /* 32 Hz time pulse */
160         timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(32*2));
107161         break;
108      case 0x02:   /* Set Clock */
109         upd1990a->shift_mode = 0;
110         logerror("RTC Set Clock attempt\n");
111         /* Not implemented yet */
112      case 0x03:   /* Read Clock */
113         upd1990a->shift_mode = 0;
114         upd1990a->shift_reg[0] = upd1990a_bcd(systime->local_time.second);
115         upd1990a->shift_reg[1] = upd1990a_bcd(systime->local_time.minute);
116         upd1990a->shift_reg[2] = upd1990a_bcd(systime->local_time.hour);
117         upd1990a->shift_reg[3] = upd1990a_bcd(systime->local_time.mday);
118         upd1990a->shift_reg[4] = systime->local_time.weekday;
119         upd1990a->shift_reg[4] |= systime->local_time.month << 4;
120         for(i=0; i<5; i++)
121            logerror("%d     ", (upd1990a->shift_reg[i] & 0x0f) + ((upd1990a->shift_reg[i] & 0xf0)>>4)*10);
122         logerror("\n");
162
163      case UPD1990A_MODE_TIME_SET:
164         {
165         int i;
166
167         if (LOG) logerror("UPD1990A Time Set Mode not supported!\n");
168         if (LOG) logerror("UPD1990A Shift Register %02x%02x%02x%02x%02x\n", upd1990a->shift_reg[4], upd1990a->shift_reg[3], upd1990a->shift_reg[2], upd1990a->shift_reg[1], upd1990a->shift_reg[0]);
169
170         /* disable time counter */
171         timer_enable(upd1990a->clock_timer, 0);
172
173         /* load shift register data into time counter */
174         for (i = 0; i < 5; i++)
175         {
176            upd1990a->time_counter[i] = upd1990a->shift_reg[i];
177         }
178
179         /* 32 Hz time pulse */
180         timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(32*2));
181         }
123182         break;
124      case 0x04:
125         upd1990a->freq_divider = 512;
126         logerror("RTC Set TP 64Hz attempt\n");
183
184      case UPD1990A_MODE_TIME_READ:
185         {
186         mame_system_time curtime, *systime = &curtime;
187         int i;
188         
189         if (LOG) logerror("UPD1990A Time Read Mode\n");
190
191         /* enable time counter */
192         timer_enable(upd1990a->clock_timer, 1);
193
194         /* HACK: load time counter from system time */
195         mame_get_current_datetime(device->machine, &curtime);
196
197         upd1990a->time_counter[0] = convert_to_bcd(systime->local_time.second);
198         upd1990a->time_counter[1] = convert_to_bcd(systime->local_time.minute);
199         upd1990a->time_counter[2] = convert_to_bcd(systime->local_time.hour);
200         upd1990a->time_counter[3] = convert_to_bcd(systime->local_time.mday);
201         upd1990a->time_counter[4] = systime->local_time.weekday;
202         upd1990a->time_counter[4] |= systime->local_time.month << 4;
203
204         /* load time counter data into shift register */
205         for (i = 0; i < 5; i++)
206         {
207            upd1990a->shift_reg[i] = upd1990a->time_counter[i];
208         }
209
210         if (LOG) logerror("UPD1990A Shift Register %02x%02x%02x%02x%02x\n", upd1990a->shift_reg[4], upd1990a->shift_reg[3], upd1990a->shift_reg[2], upd1990a->shift_reg[1], upd1990a->shift_reg[0]);
211
212         /* 512 Hz data out pulse */
213         upd1990a->data_out = 1;
214         timer_adjust_periodic(upd1990a->data_out_timer, attotime_zero, 0, ATTOTIME_IN_HZ(512*2));
215
216         /* 32 Hz time pulse */
217         timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(32*2));
218         }
127219         break;
128      case 0x05:
129         upd1990a->freq_divider = 128;
130         logerror("RTC Set TP 256Hz attempt\n");
220
221      case UPD1990A_MODE_TP_64HZ_SET:
222         if (LOG) logerror("UPD1990A TP = 64 Hz Set Mode\n");
223         
224         /* 64 Hz time pulse */
225         timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(64*2));
131226         break;
132      case 0x06:
133         upd1990a->freq_divider = 16;
134         logerror("RTC Set TP 2048Hz attempt\n");
227
228      case UPD1990A_MODE_TP_256HZ_SET:
229         if (LOG) logerror("UPD1990A TP = 256 Hz Set Mode\n");
230         
231         /* 256 Hz time pulse */
232         timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(256*2));
135233         break;
136      case 0x07:
137         logerror("RTC TEST Mode attempt\n");
138         /* Not implemented yet */
139         break;
140   }
141234
142   if (command & 0x04 )
143   {   
144      UINT16 frequency = UPD1990AC_XTAL / upd1990a->freq_divider;
235      case UPD1990A_MODE_TP_2048HZ_SET:
236         if (LOG) logerror("UPD1990A TP = 2048 Hz Set Mode\n");
145237
146      logerror("TP freq %d \n", frequency);
238         /* 2048 Hz time pulse */
239         timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(2048*2));
240         break;
147241
148      timer_adjust_periodic(upd1990a->tp_timer, attotime_zero, 0, ATTOTIME_IN_HZ(frequency));
242      case UPD1990A_MODE_TEST:
243         if (LOG) logerror("UPD1990A Test Mode not supported!\n");
244         break;
245      }
149246   }
150247}
151248
249/*-------------------------------------------------
250    upd1990a_clk_w - shift clock write
251-------------------------------------------------*/
152252
153WRITE8_DEVICE_HANDLER( upd1990a_clk_w )
253WRITE_LINE_DEVICE_HANDLER( upd1990a_clk_w )
154254{
155255   upd1990a_t *upd1990a = get_safe_token(device);
156256
157   if (upd1990a->shift_mode)
257   if (LOG) logerror("UPD1990A CLK %u\n", state);
258
259   if (!upd1990a->clk && state) // rising edge
158260   {
159   /* Shift Register */
160      upd1990a->shift_reg[0] >>= 1;
161      upd1990a->shift_reg[0] |= upd1990a->shift_reg[1] & 1 ? 0x80 : 0;
162      upd1990a->shift_reg[1] >>= 1;
163      upd1990a->shift_reg[1] |= upd1990a->shift_reg[2] & 1 ? 0x80 : 0;
164      upd1990a->shift_reg[2] >>= 1;
165      upd1990a->shift_reg[2] |= upd1990a->shift_reg[3] & 1 ? 0x80 : 0;
166      upd1990a->shift_reg[3] >>= 1;
167      upd1990a->shift_reg[3] |= upd1990a->shift_reg[4] & 1 ? 0x80 : 0;
168      upd1990a->shift_reg[4] >>= 1;
169      upd1990a->shift_reg[4] |= data & 0x10 ? 0x80 : 0;
170      upd1990a->data_out = upd1990a->shift_reg[0] & 1;
261      if (upd1990a->c == UPD1990A_MODE_SHIFT)
262      {
263         if (upd1990a->oe)
264         {
265            upd1990a->data_out = BIT(upd1990a->shift_reg[0], 0);
266
267            devcb_call_write_line(&upd1990a->out_data_func, upd1990a->data_out);
268
269            if (LOG) logerror("UPD1990A DATA OUT %u\n", upd1990a->data_out);
270         }
271
272         upd1990a->shift_reg[0] >>= 1;
273         upd1990a->shift_reg[0] |= (BIT(upd1990a->shift_reg[1], 0) << 7);
274
275         upd1990a->shift_reg[1] >>= 1;
276         upd1990a->shift_reg[1] |= (BIT(upd1990a->shift_reg[2], 0) << 7);
277
278         upd1990a->shift_reg[2] >>= 1;
279         upd1990a->shift_reg[2] |= (BIT(upd1990a->shift_reg[3], 0) << 7);
280
281         upd1990a->shift_reg[3] >>= 1;
282         upd1990a->shift_reg[3] |= (BIT(upd1990a->shift_reg[4], 0) << 7);
283
284         upd1990a->shift_reg[4] >>= 1;
285         upd1990a->shift_reg[4] |= (upd1990a->data_in << 7);
286      }
171287   }
288
289   upd1990a->clk = state;
172290}
173291
174READ8_DEVICE_HANDLER( upd1990a_data_out_r )
292/*-------------------------------------------------
293    upd1990a_c0_w - command bit 0 write
294-------------------------------------------------*/
295
296WRITE_LINE_DEVICE_HANDLER( upd1990a_c0_w )
175297{
176298   upd1990a_t *upd1990a = get_safe_token(device);
177299
178   return upd1990a->data_out;
300   if (LOG) logerror("UPD1990A C0 %u\n", state);
301   upd1990a->c = (upd1990a->c & 0x06) | state;
179302}
180303
304/*-------------------------------------------------
305    upd1990a_c1_w - command bit 1 write
306-------------------------------------------------*/
307
308WRITE_LINE_DEVICE_HANDLER( upd1990a_c1_w )
309{
310   upd1990a_t *upd1990a = get_safe_token(device);
311
312   if (LOG) logerror("UPD1990A C1 %u\n", state);
313   upd1990a->c = (upd1990a->c & 0x05) | (state << 1);
314}
315
316/*-------------------------------------------------
317    upd1990a_c2_w - command bit 2 write
318-------------------------------------------------*/
319
320WRITE_LINE_DEVICE_HANDLER( upd1990a_c2_w )
321{
322   upd1990a_t *upd1990a = get_safe_token(device);
323
324   if (LOG) logerror("UPD1990A C2 %u\n", state);
325   upd1990a->c = (upd1990a->c & 0x03) | (state << 2);
326}
327
328/*-------------------------------------------------
329    upd1990a_data_w - data input write
330-------------------------------------------------*/
331
332WRITE_LINE_DEVICE_HANDLER( upd1990a_data_w )
333{
334   upd1990a_t *upd1990a = get_safe_token(device);
335
336   if (LOG) logerror("UPD1990A DATA IN %u\n", state);
337   upd1990a->data_in = state;
338}
339
340/*-------------------------------------------------
341    TIMER_CALLBACK( clock_tick )
342-------------------------------------------------*/
343
344static TIMER_CALLBACK( clock_tick )
345{
346   const device_config *device = ptr;
347   upd1990a_t *upd1990a = get_safe_token(device);
348
349   // TODO: advance clock
350}
351
352/*-------------------------------------------------
353    TIMER_CALLBACK( tp_tick )
354-------------------------------------------------*/
355
181356static TIMER_CALLBACK( tp_tick )
182357{
183358   const device_config *device = ptr;
184359   upd1990a_t *upd1990a = get_safe_token(device);
185360
186   devcb_call_write_line(&upd1990a->out_tp_func, ASSERT_LINE);
187   devcb_call_write_line(&upd1990a->out_tp_func, CLEAR_LINE);
361   if (LOG) logerror("UPD1990A TP %u\n", upd1990a->tp);
362
363   devcb_call_write_line(&upd1990a->out_tp_func, upd1990a->tp);
364
365   upd1990a->tp = !upd1990a->tp;
188366}
189367
190/* Untested save state support */
191static void upd1990a_register_state_save(const device_config *device)
368/*-------------------------------------------------
369    TIMER_CALLBACK( data_out_tick )
370-------------------------------------------------*/
371
372static TIMER_CALLBACK( data_out_tick )
192373{
193    upd1990a_t* upd1990a = get_safe_token( device );
374   const device_config *device = ptr;
375   upd1990a_t *upd1990a = get_safe_token(device);
194376
195    state_save_register_global_array(device->machine, upd1990a->shift_reg);
196    state_save_register_global(device->machine, upd1990a->data_in);
197    state_save_register_global(device->machine, upd1990a->data_out);
198    state_save_register_global(device->machine, upd1990a->shift_mode);
199    state_save_register_global(device->machine, upd1990a->freq_divider);
377   if (LOG) logerror("UPD1990A DATA OUT %u\n", upd1990a->data_out);
378
379   devcb_call_write_line(&upd1990a->out_data_func, upd1990a->data_out);
380
381   upd1990a->data_out = !upd1990a->data_out;
200382}
201383
384/*-------------------------------------------------
385    DEVICE_START( upd1990a )
386-------------------------------------------------*/
387
202388static DEVICE_START( upd1990a )
203389{
204390   upd1990a_t *upd1990a = get_safe_token(device);
205391   const upd1990a_interface *intf = get_interface(device);
206392
207393   /* resolve callbacks */
394   devcb_resolve_write_line(&upd1990a->out_data_func, &intf->out_data_func, device);
208395   devcb_resolve_write_line(&upd1990a->out_tp_func, &intf->out_tp_func, device);
209396
210397   /* create the timers */
398   upd1990a->clock_timer = timer_alloc(device->machine, clock_tick, (void *)device);
399   timer_adjust_periodic(upd1990a->clock_timer, attotime_zero, 0, ATTOTIME_IN_HZ(device->clock / 32768));
400
211401   upd1990a->tp_timer = timer_alloc(device->machine, tp_tick, (void *)device);
212402
403   upd1990a->data_out_timer = timer_alloc(device->machine, data_out_tick, (void *)device);
404
213405   /* register for state saving */
214   upd1990a_register_state_save(device);
406    state_save_register_global_array(device->machine, upd1990a->time_counter);
407    state_save_register_global_array(device->machine, upd1990a->shift_reg);
408    state_save_register_global(device->machine, upd1990a->oe);
409    state_save_register_global(device->machine, upd1990a->cs);
410    state_save_register_global(device->machine, upd1990a->stb);
411   state_save_register_global(device->machine, upd1990a->data_in);
412    state_save_register_global(device->machine, upd1990a->data_out);
413    state_save_register_global(device->machine, upd1990a->c);
414    state_save_register_global(device->machine, upd1990a->clk);
415    state_save_register_global(device->machine, upd1990a->tp);
215416}
216417
217static DEVICE_RESET( upd1990a )
218{
219   upd1990a_t *upd1990a = get_safe_token(device);
418/*-------------------------------------------------
419    DEVICE_GET_INFO( upd1990a )
420-------------------------------------------------*/
220421
221   upd1990a->shift_reg[0] = 0x00;
222   upd1990a->shift_reg[1] = 0x00;
223   upd1990a->shift_reg[2] = 0x00;
224   upd1990a->shift_reg[3] = 0x00;
225   upd1990a->shift_reg[4] = 0x00;
226   upd1990a->data_in = 0;
227   upd1990a->data_out = 0;
228   upd1990a->shift_mode = 0;
229   upd1990a->freq_divider = 0;
230}
231
232422DEVICE_GET_INFO( upd1990a )
233423{
234424   switch (state)
r4647r4648
236426      /* --- the following bits of info are returned as 64-bit signed integers --- */
237427      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(upd1990a_t);            break;
238428      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
239      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_TIMER;            break;
429      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
240430
241431      /* --- the following bits of info are returned as pointers to data or functions --- */
242432      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(upd1990a);   break;
243433      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
244      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(upd1990a);   break;
434      case DEVINFO_FCT_RESET:                     /* Nothing */                        break;
245435
246436      /* --- the following bits of info are returned as NULL-terminated strings --- */
247437      case DEVINFO_STR_NAME:                     strcpy(info->s, "NEC uPD1990AC");         break;
src/mess/machine/upd1990a.h
r4647r4648
3434typedef struct _upd1990a_interface upd1990a_interface;
3535struct _upd1990a_interface
3636{
37   /* this gets called for every change of the DATA OUT pin (pin 9) */
38   devcb_write_line      out_data_func;
39
3740   /* this gets called for every change of the TP pin (pin 10) */
3841   devcb_write_line      out_tp_func;
3942};
r4647r4648
4548/* device interface */
4649DEVICE_GET_INFO( upd1990a );
4750
48READ8_DEVICE_HANDLER( upd1990a_data_out_r );
49WRITE8_DEVICE_HANDLER( upd1990a_w );
50WRITE8_DEVICE_HANDLER( upd1990a_clk_w );
51/* output enable */
52WRITE_LINE_DEVICE_HANDLER( upd1990a_oe_w );
5153
54/* chip select */
55WRITE_LINE_DEVICE_HANDLER( upd1990a_cs_w );
56
57/* strobe */
58WRITE_LINE_DEVICE_HANDLER( upd1990a_stb_w );
59
60/* clock */
61WRITE_LINE_DEVICE_HANDLER( upd1990a_clk_w );
62
63/* command select */
64WRITE_LINE_DEVICE_HANDLER( upd1990a_c0_w );
65WRITE_LINE_DEVICE_HANDLER( upd1990a_c1_w );
66WRITE_LINE_DEVICE_HANDLER( upd1990a_c2_w );
67
68/* data in */
69WRITE_LINE_DEVICE_HANDLER( upd1990a_data_w );
70
5271#endif /* __UPD1990A_H__ */
src/mess/mess.mak
r4647r4648
13221322
13231323$(MESSOBJ)/kyocera.a: \
13241324   $(MESS_DRIVERS)/kyocera.o \
1325   $(MESS_VIDEO)/kyocera.o \
13251326   $(MESS_MACHINE)/upd1990a.o \
13261327   $(MESS_MACHINE)/8155pio.o \
13271328
src/mess/drivers/kyocera.c
r4647r4648
1717   
1818   To Do:
1919     - Basically everything:
20       * rtc (which also controls input reads)
2120      * inputs (keyboards are different)
2221      * sound
2322      * cassettes
r4647r4648
2625      * what are the differences between available BIOSes for trsm100 and olivm10?
2726      * Tandy Model 200 support (video emulation completely different, but also
2827        memory map & IO have to be adapted)
29      * clean up driver and split machine & video parts
28      * clean up driver and split machine part
3029
3130     - Find dumps of systems which could easily be added:
3231      * Olivetti M10 US (diff BIOS than the European version, it might be the alt BIOS)
r4647r4648
4039
4140/* Core includes */
4241#include "driver.h"
42#include "includes/kyocera.h"
4343#include "cpu/i8085/i8085.h"
4444#include "machine/upd1990a.h"
4545#include "machine/8155pio.h"
4646
4747static UINT8 rom_page, ram_page;
48static UINT8 port_a, port_b, port_c;
48static UINT8 port_a, port_b;
4949static UINT8 timer_lsb, timer_msb;
5050static UINT8 io_E8, io_A1, io_90, io_D0;
5151
52int pc8201_lcd_bank = 0;
53
54void lcd_bank_update( UINT16 bank )
55{
56   switch ( bank )
57   {
58         case 0x000:   pc8201_lcd_bank = 0; break;
59         case 0x001:   pc8201_lcd_bank = 1; break;
60         case 0x002:   pc8201_lcd_bank = 2; break;
61         case 0x004:   pc8201_lcd_bank = 3; break;
62         case 0x008:   pc8201_lcd_bank = 4; break;
63         case 0x010:   pc8201_lcd_bank = 5; break;
64         case 0x020:   pc8201_lcd_bank = 6; break;
65         case 0x040:   pc8201_lcd_bank = 7; break;
66         case 0x080:   pc8201_lcd_bank = 8; break;
67         case 0x100:   pc8201_lcd_bank = 9; break;
68         case 0x200:   pc8201_lcd_bank = 10; break;
69         default: /*logerror("pc8201: bank update with unk bank = %d\n", bank);*/ break;
70   }
71
72//   logerror("pc8201: _lcd_bank = %i\n",pc8201_lcd_bank);
73}
74
7552/*  WRITE HANDLERS  */
7653
7754// 0x90 PC-8201 only
7855static WRITE8_HANDLER( pc8201_io90_write )
7956{
80   if ((data & 0x10) != (io_90 & 0x10))
81   {
82      const device_config *rtc = devtag_get_device(space->machine, "rtc");
83      upd1990a_w(rtc, offset, port_a);
84      logerror("RTC write: %d\n", port_a);
85   }
57   const device_config *rtc = devtag_get_device(space->machine, "rtc");
8658
59   upd1990a_stb_w(rtc, BIT(data, 5));
60     
61
8762   /* printer */
8863//   if ((data & 0x20) != (io_90 & 0x20))
8964//      WRITE port_a;
r4647r4648
243218             3 - Remote plug control signal */
244219static WRITE8_HANDLER( ioE8_write )
245220{
246   /* Check for Clock Chip strobe */
247   if ((data & 0x04) != (io_E8 & 0x04))
248   {
249      const device_config *rtc = devtag_get_device(space->machine, "rtc");
250      upd1990a_w(rtc, offset, port_a);
251      logerror("RTC write: %d\n", port_a);
252   }
221   const device_config *rtc = devtag_get_device(space->machine, "rtc");
253222
223   upd1990a_stb_w(rtc, BIT(data, 2));
224
254225   /* printer */
255226//   if ((data & 0x02) != (io_E8 & 0x02))
256227//      WRITE port_a;
r4647r4648
269240//   io_E8 = data;
270241//}
271242
272
273UINT8 pc8201_lcd[11][256];
274UINT8 pc8201_lcd_addr[10];
275
276// 0xF0...
277static WRITE8_HANDLER( lcd_command_write )
278{
279   pc8201_lcd_addr[pc8201_lcd_bank] = data;
280   /* logerror("pc8201: LCDCM = 0x%02x\n",data); */
281}
282
283// 0xFF
284static WRITE8_HANDLER( lcd_data_write )
285{
286   UINT8 addr = pc8201_lcd_addr[pc8201_lcd_bank]++;
287   pc8201_lcd[pc8201_lcd_bank][addr] = data;
288   /* logerror("pc8201: LCD [%i][%02x] = 0x%02x\n",pc8201_lcd_bank,addr,data); */
289}
290
291243static WRITE8_HANDLER( unk_write )
292244{
293245   logerror("pc8201 IO port w: %04x %02x\n", offset, data);
r4647r4648
375327   return data;
376328}
377329
378// 0xF0...
379static READ8_HANDLER( lcd_status_read )
380{
381   /* logerror("pc8201: LCDST = 0\n"); */
382   return 0;   /* currently we are always ready */
383}
384
385// 0xFF
386static READ8_HANDLER( lcd_data_read )
387{
388   UINT8 addr = pc8201_lcd_addr[pc8201_lcd_bank]++;
389   return pc8201_lcd[pc8201_lcd_bank][addr];
390}
391
392330static READ8_HANDLER( unk_read )
393331{
394332   logerror("pc8201 IO port r: %04x\n", offset);
r4647r4648
421359   AM_RANGE(0xd8, 0xd8) AM_READ( uart_read )
422360   AM_RANGE(0xe0, 0xe8) AM_READ( keyboard_read )
423361   AM_RANGE(0xe0, 0xe8) AM_READWRITE( keyboard_read, ioE8_write )
424   AM_RANGE(0xfe, 0xfe) AM_READWRITE( lcd_status_read, lcd_command_write ) /* LCD status / command */
425   AM_RANGE(0xff, 0xff) AM_READWRITE( lcd_data_read, lcd_data_write )      /* LCD data */
362   AM_RANGE(0xfe, 0xfe) AM_READWRITE( kyo85_lcd_status_r, kyo85_lcd_command_w )
363   AM_RANGE(0xff, 0xff) AM_READWRITE( kyo85_lcd_data_r, kyo85_lcd_data_w )
426364ADDRESS_MAP_END
427365
428366static ADDRESS_MAP_START( pc8201_io, ADDRESS_SPACE_IO, 8 )
r4647r4648
434372   AM_RANGE(0xd8, 0xd8) AM_READ( uart_read )
435373   AM_RANGE(0xe0, 0xe8) AM_READ( keyboard_read )
436374//   AM_RANGE(0xe0, 0xe8) AM_READWRITE( keyboard_read, ioE8_write )
437   AM_RANGE(0xfe, 0xfe) AM_READWRITE( lcd_status_read, lcd_command_write ) /* LCD status / command */
438   AM_RANGE(0xff, 0xff) AM_READWRITE( lcd_data_read, lcd_data_write )      /* LCD data */
375   AM_RANGE(0xfe, 0xfe) AM_READWRITE( kyo85_lcd_status_r, kyo85_lcd_command_w )
376   AM_RANGE(0xff, 0xff) AM_READWRITE( kyo85_lcd_data_r, kyo85_lcd_data_w )
439377ADDRESS_MAP_END
440378
441379static ADDRESS_MAP_START( trs200_io, ADDRESS_SPACE_IO, 8 )
r4647r4648
449387   AM_RANGE(0xd0, 0xdf) AM_READWRITE( trs200_bank_read, trs200_bank_write )
450388   AM_RANGE(0xe0, 0xe8) AM_READ( keyboard_read )
451389//   AM_RANGE(0xe0, 0xe8) AM_READWRITE( keyboard_read, ioE8_write )
452   AM_RANGE(0xfe, 0xfe) AM_READWRITE( lcd_status_read, lcd_command_write ) /* LCD status / command */
453   AM_RANGE(0xff, 0xff) AM_READWRITE( lcd_data_read, lcd_data_write )      /* LCD data */
390   AM_RANGE(0xfe, 0xfe) AM_READWRITE( kyo85_lcd_status_r, kyo85_lcd_command_w )
391   AM_RANGE(0xff, 0xff) AM_READWRITE( kyo85_lcd_data_r, kyo85_lcd_data_w )
454392ADDRESS_MAP_END
455393
456
457// pasted from PX-4. to be fixed!!
458static PALETTE_INIT( kyo85 )
459{
460   palette_set_color(machine, 0, MAKE_RGB(138, 146, 148));
461   palette_set_color(machine, 1, MAKE_RGB(92, 83, 88));
462}
463
464static VIDEO_UPDATE( kyo85 )
465{
466   int x,y;
467   int bank;
468   int row,col;
469   int addr;
470   int yoff;
471   unsigned char b;
472
473   int pen1,pen0;
474
475   pen0 = screen->machine->pens[0];
476   pen1 = screen->machine->pens[1];
477
478   for (y=0;y<64;y+=8)
479   {
480      for (x=0;x<240;x++)
481      {
482         bank = x/50;
483         row = x%50;
484         col = y/8;
485         if (col>3)
486         {
487            col -= 4;
488            bank+= 5;
489         }
490
491      addr = col*64 + row;
492
493      b = pc8201_lcd[bank+1][addr];
494
495      /*logerror("pc8201: vid [%i][%02x] = 0x%02x (%i,%i)\n",bank,addr,b,x,y); */
496
497   for (yoff = 0; yoff < 8; yoff++)
498   {
499      *BITMAP_ADDR16(bitmap, y+yoff, x ) = ((b & (1 << yoff)) == (1 << yoff)) ? pen0 : pen1;
500   }
501   
502      }
503   }
504
505   return 0;
506}
507
508
509394/**************************************************************************
510395
511396   Keyboard
r4647r4648
715600
716601static MACHINE_START( kyo85 )
717602{
603   const device_config *rtc = devtag_get_device(machine, "rtc");
604
605   upd1990a_cs_w(rtc, 1);
606   upd1990a_oe_w(rtc, 1);
718607}
719608
720609static MACHINE_RESET( kyo85 )
r4647r4648
723612   ram_page = -1;
724613   port_a = 0;
725614   port_b = 0;
726   port_c = 0;
727615   timer_lsb = 0;
728616   timer_msb = 0;
729617   io_E8 = 0;
r4647r4648
732620   io_90 = 0;
733621}
734622
623static int upd1990a_data;
624
625static WRITE_LINE_DEVICE_HANDLER( kyocera_upd1990a_data_w )
626{
627   upd1990a_data = state;
628}
629
735630static UPD1990A_INTERFACE( kyocera_upd1990a_intf )
736631{
632   DEVCB_LINE(kyocera_upd1990a_data_w),
737633   DEVCB_CPU_INPUT_LINE("maincpu", I8085_RST75_LINE)
738634};
739635
740636static READ8_DEVICE_HANDLER( kyocera_8155_port_c_r )
741637{
742   const device_config *rtc = devtag_get_device(device->machine, "rtc");
743   port_c = (port_c & ~0x01) | upd1990a_data_out_r(rtc, offset);
638   /*
639   
640      bit      description
744641
745   return port_c;
746         /*
747         Bits:
748             0 - Serial data input from clock chip
749             1 - Busy (not) signal from printer
750             2 - Busy signal from printer
751             3 - Data from BCR
752             4 - CTS (not) line from RS232
753             5 - DSR (not) line from RS232
754             6-7 - Not avaiable on 8155 */
642      0      serial data input from clock chip
643      1      _BUSY signal from printer
644      2      BUSY signal from printer
645      3      data from BCR
646      4      _CTS from RS232
647      5      _DSR from RS232
648
649   */
650   UINT8 data = 0;
651
652   data |= upd1990a_data;
653//   data |= centronics_not_busy_r(centronics) << 1;
654//   data |= centronics_busy_r(centronics) << 2;
655
656   return data;
755657}
756658
757659static WRITE8_DEVICE_HANDLER( kyocera_8155_port_a_w )
758660{
661   const device_config *rtc = devtag_get_device(device->machine, "rtc");
662
759663   port_a = data;
760   lcd_bank_update( port_a | ((port_b & 3) << 8) );
664   kyo85_set_lcd_bank( port_a | ((port_b & 3) << 8) );
761665
762666         /*
763667         The first 5 bits of this port is used to control the 1990 real time clock chip. 
r4647r4648
768672             2 -  C2
769673             3 -  Clock
770674             4 -  Serial data into clock chip */
771   if ((data & 0x08) != (port_a & 0x08))
772   {
773      const device_config *rtc = devtag_get_device(device->machine, "rtc");
774      upd1990a_clk_w(rtc, offset, data);
775      logerror("CLK write %d\n", data);
776   }
675
676   upd1990a_c0_w(rtc, BIT(data, 0));
677   upd1990a_c1_w(rtc, BIT(data, 1));
678   upd1990a_c2_w(rtc, BIT(data, 2));
679   upd1990a_clk_w(rtc, BIT(data, 3));
680   upd1990a_data_w(rtc, BIT(data, 4));
777681}
778682
779683static WRITE8_DEVICE_HANDLER( kyocera_8155_port_b_w )
r4647r4648
791695             6 - DTR (not) line for RS232
792696             7 - RTS (not) line for RS232 */
793697   port_b = data;
794   lcd_bank_update( port_a | ((port_b & 3) << 8) );
698   kyo85_set_lcd_bank( port_a | ((port_b & 3) << 8) );
795699}
796700
797701static PIO8155_INTERFACE( kyocera_8155_intf )
r4647r4648
826730   MDRV_PALETTE_LENGTH(2)
827731   MDRV_PALETTE_INIT(kyo85)
828732
733   MDRV_VIDEO_START(kyo85)
829734   MDRV_VIDEO_UPDATE(kyo85)
830735
831736   /* sound hardware */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team