Previous 15994 Revisions Next

r6353 Tuesday 10th November, 2009 at 21:40:23 UTC by Curt Coder
[UPD3301] Added basic commands and screen geometry, no display yet.
[src/mess/drivers]pc8001.c
[src/mess/video]upd3301.c upd3301.h

src/mess/video/upd3301.c
r6352r6353
77 
88**********************************************************************/
99 
10/*
11 
12   TODO:
13 
14   - FIFO
15   - screen display
16   - set_drq
17   - dack_w
18   - interrupts
19   - light pen
20   - reset counters
21 
22*/
23 
1024#include "driver.h"
1125#include "upd3301.h"
1226 
r6352r6353
1428    PARAMETERS
1529***************************************************************************/
1630 
17#define LOG 0
31#define LOG 1
1832 
33#define UPD3301_COMMAND_MASK               0xe0
34#define UPD3301_COMMAND_RESET               0x00
35#define UPD3301_COMMAND_START_DISPLAY         0x20
36#define UPD3301_COMMAND_SET_INTERRUPT_MASK      0x40
37#define UPD3301_COMMAND_READ_LIGHT_PEN         0x60
38#define UPD3301_COMMAND_LOAD_CURSOR_POSITION   0x80
39#define UPD3301_COMMAND_RESET_INTERRUPT         0xa0
40#define UPD3301_COMMAND_RESET_COUNTERS         0xc0
41 
42#define UPD3301_STATUS_VE                  0x10
43#define UPD3301_STATUS_U                  0x08   /* not supported */
44#define UPD3301_STATUS_N                  0x04   /* not supported */
45#define UPD3301_STATUS_E                  0x02   /* not supported */
46#define UPD3301_STATUS_LP                  0x01   /* not supported */
47 
48enum
49{
50   MODE_NONE,
51   MODE_RESET,
52   MODE_READ_LIGHT_PEN,
53   MODE_LOAD_CURSOR_POSITION
54};
55 
1956/***************************************************************************
2057    TYPE DEFINITIONS
2158***************************************************************************/
r6352r6353
3067 
3168   const device_config *screen;   /* screen */
3269 
70   int disp;
71   int mode;
72   UINT8 status;
73   int param_count;
74 
75   UINT8 row_buffer[80][2];      /* row buffer */
76   UINT8 fifo[20][2];            /* FIFO */
77 
78   int dma_mode;               /* DMA mode */
79   int h;                     /* characters per line */
80   int b;                     /* cursor blink time */
81   int l;                     /* lines per screen */
82   int s;                     /* display every other line */
83   int c;                     /* cursor mode */
84   int r;                     /* lines per character */
85   int v;                     /* vertical blanking height */
86   int z;                     /* horizontal blanking width */
87   int at1;                  /*  */
88   int at0;                  /*  */
89   int sc;                     /*  */
90   int a;                     /* attributes per row */
91   int mn;                     /* disable special character interrupt */
92   int me;                     /* disable end of screen interrupt */
93   int cm;                     /* cursor visible */
94   int cx;                     /* cursor column */
95   int cy;                     /* cursor row */
96 
3397   /* timers */
3498   emu_timer *vrtc_timer;         /* vertical sync timer */
3599   emu_timer *hrtc_timer;         /* horizontal sync timer */
r6352r6353
59123***************************************************************************/
60124 
61125/*-------------------------------------------------
126    set_interrupt - set interrupt line state
127-------------------------------------------------*/
128 
129static void set_interrupt(const device_config *device, int state)
130{
131   upd3301_t *upd3301 = get_safe_token(device);
132 
133   if (LOG) logerror("UPD3301 '%s' Interrupt: %u\n", device->tag, state);
134 
135   devcb_call_write_line(&upd3301->out_int_func, state);
136}
137 
138/*-------------------------------------------------
139    set_display - set display state
140-------------------------------------------------*/
141 
142static void set_display(const device_config *device, int state)
143{
144   upd3301_t *upd3301 = get_safe_token(device);
145 
146   if (state)
147   {
148      upd3301->status |= UPD3301_STATUS_VE;
149   }
150   else
151   {
152      upd3301->status &= ~UPD3301_STATUS_VE;
153   }
154 
155   upd3301->disp = state;
156}
157 
158/*-------------------------------------------------
159    reset_counters - reset screen counters
160-------------------------------------------------*/
161 
162static void reset_counters(const device_config *device)
163{
164   set_interrupt(device, 0);
165}
166 
167/*-------------------------------------------------
168    update_hrtc_timer -
169-------------------------------------------------*/
170 
171static void update_hrtc_timer(upd3301_t *upd3301, int state)
172{
173   int y = video_screen_get_vpos(upd3301->screen);
174 
175   int next_x = state ? upd3301->h : 0;
176   int next_y = state ? y : ((y + 1) % ((upd3301->l + upd3301->v) * 8));
177 
178   attotime duration = video_screen_get_time_until_pos(upd3301->screen, next_y, next_x);
179 
180   timer_adjust_oneshot(upd3301->hrtc_timer, duration, !state);
181}
182 
183/*-------------------------------------------------
184    update_vrtc_timer -
185-------------------------------------------------*/
186 
187static void update_vrtc_timer(upd3301_t *upd3301, int state)
188{
189   int next_y = state ? (upd3301->l * upd3301->r) : 0;
190 
191   attotime duration = video_screen_get_time_until_pos(upd3301->screen, next_y, 0);
192 
193   timer_adjust_oneshot(upd3301->vrtc_timer, duration, !state);
194}
195 
196/*-------------------------------------------------
197    recompute_parameters -
198-------------------------------------------------*/
199 
200static void recompute_parameters(const device_config *device)
201{
202   upd3301_t *upd3301 = get_safe_token(device);
203 
204   int horiz_pix_total = (upd3301->h + upd3301->z) * 8;
205   int vert_pix_total = (upd3301->l + upd3301->v) * upd3301->r;
206 
207   attoseconds_t refresh = HZ_TO_ATTOSECONDS(device->clock) * horiz_pix_total * vert_pix_total;
208   
209   rectangle visarea;
210 
211   visarea.min_x = 0;
212   visarea.min_y = 0;
213   visarea.max_x = (upd3301->h * 8) - 1;
214   visarea.max_y = (upd3301->l * upd3301->r) - 1;
215 
216   if (LOG)
217   {
218      if (LOG) logerror("UPD3301 '%s' Screen: %u x %u @ %f Hz\n", device->tag, horiz_pix_total, vert_pix_total, 1 / ATTOSECONDS_TO_DOUBLE(refresh));
219      if (LOG) logerror("UPD3301 '%s' Visible Area: (%u, %u) - (%u, %u)\n", device->tag, visarea.min_x, visarea.min_y, visarea.max_x, visarea.max_y);
220   }
221 
222   video_screen_configure(upd3301->screen, horiz_pix_total, vert_pix_total, &visarea, refresh);
223   
224   update_hrtc_timer(upd3301, 0);
225   update_vrtc_timer(upd3301, 0);
226}
227 
228/*-------------------------------------------------
62229    TIMER_CALLBACK( vrtc_tick )
63230-------------------------------------------------*/
64231 
65232static TIMER_CALLBACK( vrtc_tick )
66233{
67//   const device_config *device = ptr;
68//   upd3301_t *upd3301 = get_safe_token(device);
234   const device_config *device = ptr;
235   upd3301_t *upd3301 = get_safe_token(device);
236 
237   //if (LOG) logerror("UPD3301 '%s' VRTC: %u\n", device->tag, param);
238 
239   devcb_call_write_line(&upd3301->out_vrtc_func, param);
240 
241   update_vrtc_timer(upd3301, param);
69242}
70243 
71244/*-------------------------------------------------
r6352r6353
74247 
75248static TIMER_CALLBACK( hrtc_tick )
76249{
77//   const device_config *device = ptr;
78//   upd3301_t *upd3301 = get_safe_token(device);
250   const device_config *device = ptr;
251   upd3301_t *upd3301 = get_safe_token(device);
252 
253   //if (LOG) logerror("UPD3301 '%s' HRTC: %u\n", device->tag, param);
254 
255   devcb_call_write_line(&upd3301->out_hrtc_func, param);
256 
257   update_hrtc_timer(upd3301, param);
79258}
80259 
81260/*-------------------------------------------------
r6352r6353
84263 
85264READ8_DEVICE_HANDLER( upd3301_r )
86265{
87   return 0;
266   upd3301_t *upd3301 = get_safe_token(device);
267   UINT8 data = 0;
268 
269   switch (offset & 0x01)
270   {
271   case 0: /* data */
272      break;
273 
274   case 1: /* status */
275      data = upd3301->status;
276      break;
277   }
278 
279   return data;
88280}
89281 
90282/*-------------------------------------------------
r6352r6353
93285 
94286WRITE8_DEVICE_HANDLER( upd3301_w )
95287{
288   upd3301_t *upd3301 = get_safe_token(device);
289 
290   switch (offset & 0x01)
291   {
292   case 0: /* data */
293      switch (upd3301->mode)
294      {
295      case MODE_RESET:
296         switch (upd3301->param_count)
297         {
298         case 0:
299            upd3301->dma_mode = BIT(data, 7);
300            upd3301->h = (data & 0x7f) + 2;
301            if (LOG) logerror("UPD3301 '%s' DMA Mode: %s\n", device->tag, upd3301->dma_mode ? "character" : "burst");
302            if (LOG) logerror("UPD3301 '%s' H: %u\n", device->tag, upd3301->h);
303            break;
304 
305         case 1:
306            upd3301->b = ((data >> 6) + 1) * 16;
307            upd3301->l = (data & 0x3f) + 1;
308            if (LOG) logerror("UPD3301 '%s' B: %u\n", device->tag, upd3301->b);
309            if (LOG) logerror("UPD3301 '%s' L: %u\n", device->tag, upd3301->l);
310            break;
311 
312         case 2:
313            upd3301->s = BIT(data, 7);
314            upd3301->c = (data >> 4) & 0x03;
315            upd3301->r = (data & 0x1f) + 1;
316            if (LOG) logerror("UPD3301 '%s' S: %u\n", device->tag, upd3301->s);
317            if (LOG) logerror("UPD3301 '%s' C: %u\n", device->tag, upd3301->c);
318            if (LOG) logerror("UPD3301 '%s' R: %u\n", device->tag, upd3301->r);
319            break;
320 
321         case 3:
322            upd3301->v = (data >> 5) + 1;
323            upd3301->z = (data & 0x1f) + 2;
324            if (LOG) logerror("UPD3301 '%s' V: %u\n", device->tag, upd3301->v);
325            if (LOG) logerror("UPD3301 '%s' Z: %u\n", device->tag, upd3301->z);
326            recompute_parameters(device);
327            break;
328 
329         case 4:
330            upd3301->at1 = BIT(data, 7);
331            upd3301->at0 = BIT(data, 6);
332            upd3301->sc = BIT(data, 5);
333            upd3301->a = (data & 0x1f) + 1;
334            if (LOG) logerror("UPD3301 '%s' AT1: %u\n", device->tag, upd3301->at1);
335            if (LOG) logerror("UPD3301 '%s' AT0: %u\n", device->tag, upd3301->at0);
336            if (LOG) logerror("UPD3301 '%s' SC: %u\n", device->tag, upd3301->sc);
337            if (LOG) logerror("UPD3301 '%s' A: %u\n", device->tag, upd3301->a);
338 
339            upd3301->mode = MODE_NONE;
340            break;
341         }
342 
343         upd3301->param_count++;
344         break;
345 
346      case MODE_LOAD_CURSOR_POSITION:
347         switch (upd3301->param_count)
348         {
349         case 0:
350            upd3301->cx = data & 0x7f;
351            if (LOG) logerror("UPD3301 '%s' CX: %u\n", device->tag, upd3301->cx);
352            break;
353 
354         case 1:
355            upd3301->cy = data & 0x3f;
356            if (LOG) logerror("UPD3301 '%s' CY: %u\n", device->tag, upd3301->cy);
357 
358            upd3301->mode = MODE_NONE;
359            break;
360         }
361 
362         upd3301->param_count++;
363         break;
364       
365      default:
366         if (LOG) logerror("UPD3301 '%s' Invalid Parameter Byte %02x!\n", device->tag, data);
367      }
368      break;
369 
370   case 1: /* command */
371      upd3301->mode = MODE_NONE;
372      upd3301->param_count = 0;
373 
374      switch (data & 0xe0)
375      {
376      case UPD3301_COMMAND_RESET:
377         if (LOG) logerror("UPD3301 '%s' Reset\n", device->tag);
378         upd3301->mode = MODE_RESET;
379         set_display(device, 0);
380         set_interrupt(device, 0);
381         break;
382 
383      case UPD3301_COMMAND_START_DISPLAY:
384         if (LOG) logerror("UPD3301 '%s' Start Display\n", device->tag);
385         set_display(device, 1);
386         reset_counters(device);
387         break;
388 
389      case UPD3301_COMMAND_SET_INTERRUPT_MASK:
390         if (LOG) logerror("UPD3301 '%s' Set Interrupt Mask\n", device->tag);
391         upd3301->me = BIT(data, 0);
392         upd3301->mn = BIT(data, 1);
393         if (LOG) logerror("UPD3301 '%s' ME: %u\n", device->tag, upd3301->me);
394         if (LOG) logerror("UPD3301 '%s' MN: %u\n", device->tag, upd3301->mn);
395         break;
396 
397      case UPD3301_COMMAND_READ_LIGHT_PEN:
398         if (LOG) logerror("UPD3301 '%s' Read Light Pen\n", device->tag);
399         upd3301->mode = MODE_READ_LIGHT_PEN;
400         break;
401 
402      case UPD3301_COMMAND_LOAD_CURSOR_POSITION:
403         if (LOG) logerror("UPD3301 '%s' Load Cursor Position\n", device->tag);
404         upd3301->mode = MODE_LOAD_CURSOR_POSITION;
405         upd3301->cm = BIT(data, 0);
406         if (LOG) logerror("UPD3301 '%s' CM: %u\n", device->tag, upd3301->cm);
407         break;
408 
409      case UPD3301_COMMAND_RESET_INTERRUPT:
410         if (LOG) logerror("UPD3301 '%s' Reset Interrupt\n", device->tag);
411         set_interrupt(device, 0);
412         break;
413 
414      case UPD3301_COMMAND_RESET_COUNTERS:
415         if (LOG) logerror("UPD3301 '%s' Reset Counters\n", device->tag);
416         reset_counters(device);
417         break;
418      }
419      break;
420   }
96421}
97422 
98423/*-------------------------------------------------
src/mess/video/upd3301.h
r6352r6353
5959struct _upd3301_interface
6060{
6161   const char *screen_tag;      /* screen we are acting on */
62   int width;               /* char width in pixels */
6263 
6364   upd3301_display_pixels_func   display_func;
6465 
src/mess/drivers/pc8001.c
r6352r6353
370370static UPD3301_INTERFACE( pc8001_upd3301_intf )
371371{
372372   SCREEN_TAG,
373   8,
373374   pc8001_display_pixels,
374375   DEVCB_NULL,
375376   DEVCB_DEVICE_LINE(I8257_TAG, i8257_drq2_w),
r6352r6353
529530   MDRV_I8255A_ADD(I8255A_TAG, pc8001_8255_intf)
530531   MDRV_I8257_ADD(I8257_TAG, 4000000, pc8001_8257_intf)
531532   MDRV_UPD1990A_ADD(UPD1990A_TAG, XTAL_32_768kHz, pc8001_upd1990a_intf)
532   MDRV_UPD3301_ADD(UPD3301_TAG, 8000000, pc8001_upd3301_intf)
533   MDRV_UPD3301_ADD(UPD3301_TAG, 14318180, pc8001_upd3301_intf)
533534 
534535   MDRV_CENTRONICS_ADD(CENTRONICS_TAG, standard_centronics)
535536   MDRV_CASSETTE_ADD(CASSETTE_TAG, pc8001_cassette_config)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team