Previous 15994 Revisions Next

r11222 Sunday 17th April, 2011 at 20:30:18 UTC by Curt Coder
Refactored UPD7220 into a C++ device. (no whatsnew)
[src/mess/drivers]a5105.c compis.c mikromik.c pc9801.c qx10.c
[src/mess/includes]compis.h mikromik.h
[src/mess/video]upd7220.c upd7220.h

src/mess/video/upd7220.c
r11221r11222
3838#include "emu.h"
3939#include "upd7220.h"
4040
41/***************************************************************************
42    PARAMETERS
43***************************************************************************/
4441
42
43//**************************************************************************
44//  MACROS / CONSTANTS
45//**************************************************************************
46
4547#define LOG 1
4648
49
4750// todo typedef
4851enum
4952{
r11221r11222
125128#define UPD7220_MODE_DISPLAY_CHARACTER   0x20
126129#define UPD7220_MODE_DISPLAY_INVALID   0x22
127130
128/***************************************************************************
129    TYPE DEFINITIONS
130***************************************************************************/
131static const int x_dir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
132static const int y_dir[8] = { 1, 1, 0,-1,-1,-1, 0, 1};
133static const int x_dir_dot[8] = { 1, 1, 0,-1,-1,-1, 0, 1};
134static const int y_dir_dot[8] = { 0,-1,-1,-1, 0, 1, 1, 1};
131135
132typedef void (*upd7220_command) (device_t *device);
133136
134typedef struct _upd7220_t upd7220_t;
135struct _upd7220_t
136{
137   devcb_resolved_write_line   out_drq_func;
138   devcb_resolved_write_line   out_hsync_func;
139   devcb_resolved_write_line   out_vsync_func;
140   devcb_resolved_write_line   out_blank_func;
141   upd7220_display_pixels_func display_func;
142   upd7220_draw_text_line       draw_text_func;
143137
144   screen_device *screen;   /* screen */
138//**************************************************************************
139//  GLOBAL VARIABLES
140//**************************************************************************
145141
146   int clock;                  /* device clock */
142// devices
143const device_type UPD7220 = upd7220_device_config::static_alloc_device_config;
147144
148   UINT16 mask;               /* mask register */
149   UINT8 pitch;               /* number of word addresses in display memory in the horizontal direction */
150   UINT32 ead;                  /* execute word address */
151   UINT16 dad;                  /* dot address within the word */
152   UINT32 lad;                  /* light pen address */
153145
154   UINT8 ra[16];               /* parameter RAM */
155   int ra_addr;               /* parameter RAM address */
146// default address map
147static ADDRESS_MAP_START( upd7220_vram, AS_0, 8 )
148   AM_RANGE(0x00000, 0x3ffff) AM_RAM
149ADDRESS_MAP_END
156150
157   UINT8 sr;                  /* status register */
158   UINT8 cr;                  /* command register */
159   UINT8 pr[17];               /* parameter byte register */
160   int param_ptr;               /* parameter pointer */
161151
162   UINT8 fifo[16];               /* FIFO data queue */
163   int fifo_flag[16];            /* FIFO flag queue */
164   int fifo_ptr;               /* FIFO pointer */
165   int fifo_dir;               /* FIFO direction */
152// internal 128x14 control ROM
153ROM_START( upd7220 )
154   ROM_REGION( 0x100, "upd7220", 0 )
155   ROM_LOAD( "upd7220.bin", 0x000, 0x100, NO_DUMP )
156ROM_END
166157
167   UINT8 mode;                  /* mode of operation */
168   UINT8 draw_mode;            /* mode of drawing */
169158
170   int de;                     /* display enabled */
171   int m;                     /* 0 = accept external vertical sync (slave mode) / 1 = generate & output vertical sync (master mode) */
172   int aw;                     /* active display words per line - 2 (must be even number with bit 0 = 0) */
173   int al;                     /* active display lines per video field */
174   int vs;                     /* vertical sync width - 1 */
175   int vfp;                  /* vertical front porch width - 1 */
176   int vbp;                  /* vertical back porch width - 1 */
177   int hs;                     /* horizontal sync width - 1 */
178   int hfp;                  /* horizontal front porch width - 1 */
179   int hbp;                  /* horizontal back porch width - 1 */
180159
181   int dc;                     /* display cursor */
182   int sc;                     /* 0 = blinking cursor / 1 = steady cursor */
183   int br;                     /* blink rate */
184   int ctop;                  /* cursor top line number in the row */
185   int cbot;                  /* cursor bottom line number in the row (CBOT < LR) */
186   int lr;                     /* lines per character row - 1 */
160//**************************************************************************
161//  DEVICE CONFIGURATION
162//**************************************************************************
187163
188   int disp;                  /* display zoom factor */
189   int gchr;                  /* zoom factor for graphics character writing and area filling */
164//-------------------------------------------------
165//  upd7220_device_config - constructor
166//-------------------------------------------------
190167
191   struct {
192      UINT8 dir;               /* figs param 0: drawing direction */
193      UINT8 figure_type;         /* figs param 1: figure type */
194      UINT16 dc;               /* figs param 2: */
195      UINT16 d;               /* figs param 3: */
196      UINT16 d1;               /* figs param 4: */
197      UINT16 d2;               /* figs param 5: */
198      UINT16 dm;               /* figs param 6: */
199   }figs;
168upd7220_device_config::upd7220_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
169   : device_config(mconfig, static_alloc_device_config, "uPD7220", tag, owner, clock),
170     device_config_memory_interface(mconfig, *this),
171     m_space_config("videoram", ENDIANNESS_LITTLE, 8, 16, 0, NULL, *ADDRESS_MAP_NAME(upd7220_vram))
172{
173   m_shortname = "upd7220";
174}
200175
201   /* timers */
202   emu_timer *vsync_timer;         /* vertical sync timer */
203   emu_timer *hsync_timer;         /* horizontal sync timer */
204   emu_timer *blank_timer;         /* CRT blanking timer */
205176
206   UINT8 vram[0x40000];
207   UINT32 vram_bank;
177//-------------------------------------------------
178//  static_alloc_device_config - allocate a new
179//  configuration object
180//-------------------------------------------------
208181
209   UINT8 bitmap_mod;
210};
182device_config *upd7220_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
183{
184   return global_alloc(upd7220_device_config(mconfig, tag, owner, clock));
185}
211186
212static const int x_dir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
213static const int y_dir[8] = { 1, 1, 0,-1,-1,-1, 0, 1};
214static const int x_dir_dot[8] = { 1, 1, 0,-1,-1,-1, 0, 1};
215static const int y_dir_dot[8] = { 0,-1,-1,-1, 0, 1, 1, 1};
216187
217/***************************************************************************
218    INLINE FUNCTIONS
219***************************************************************************/
188//-------------------------------------------------
189//  alloc_device - allocate a new device object
190//-------------------------------------------------
220191
221INLINE upd7220_t *get_safe_token(device_t *device)
192device_t *upd7220_device_config::alloc_device(running_machine &machine) const
222193{
223   assert(device != NULL);
224   assert((device->type() == UPD7220));
225   return (upd7220_t *)downcast<legacy_device_base *>(device)->token();
194   return auto_alloc(machine, upd7220_device(machine, *this));
226195}
227196
228INLINE const upd7220_interface *get_interface(device_t *device)
197
198//-------------------------------------------------
199//  memory_space_config - return a description of
200//  any address spaces owned by this device
201//-------------------------------------------------
202
203const address_space_config *upd7220_device_config::memory_space_config(address_spacenum spacenum) const
229204{
230   assert(device != NULL);
231   assert((device->type() == UPD7220));
232   return (const upd7220_interface *) device->baseconfig().static_config();
205   return (spacenum == AS_0) ? &m_space_config : NULL;
233206}
234207
235INLINE void fifo_clear(upd7220_t *upd7220)
208
209//-------------------------------------------------
210//  rom_region - device-specific ROM region
211//-------------------------------------------------
212
213const rom_entry *upd7220_device_config::device_rom_region() const
236214{
237   int i;
215   return ROM_NAME( upd7220 );
216}
238217
239   for (i = 0; i < 16; i++)
218
219//-------------------------------------------------
220//  device_config_complete - perform any
221//  operations now that the configuration is
222//  complete
223//-------------------------------------------------
224
225void upd7220_device_config::device_config_complete()
226{
227   // inherit a copy of the static data
228   const upd7220_interface *intf = reinterpret_cast<const upd7220_interface *>(static_config());
229   if (intf != NULL)
230      *static_cast<upd7220_interface *>(this) = *intf;
231
232   // or initialize to defaults if none provided
233   else
240234   {
241      upd7220->fifo[i] = 0;
242      upd7220->fifo_flag[i] = FIFO_EMPTY;
235      memset(&m_out_drq_func, 0, sizeof(m_out_drq_func));
236      memset(&m_out_hsync_func, 0, sizeof(m_out_hsync_func));
237      memset(&m_out_vsync_func, 0, sizeof(m_out_vsync_func));
238      memset(&m_out_blank_func, 0, sizeof(m_out_blank_func));
243239   }
240}
244241
245   upd7220->fifo_ptr = -1;
246242
247   upd7220->sr &= ~UPD7220_SR_DATA_READY;
248   upd7220->sr |= UPD7220_SR_FIFO_EMPTY;
249   upd7220->sr &= ~UPD7220_SR_FIFO_FULL;
243
244//**************************************************************************
245//  INLINE HELPERS
246//**************************************************************************
247
248//-------------------------------------------------
249//  fifo_clear -
250//-------------------------------------------------
251
252inline void upd7220_device::fifo_clear()
253{
254   for (int i = 0; i < 16; i++)
255   {
256      m_fifo[i] = 0;
257      m_fifo_flag[i] = FIFO_EMPTY;
258   }
259
260   m_fifo_ptr = -1;
261
262   m_sr &= ~UPD7220_SR_DATA_READY;
263   m_sr |= UPD7220_SR_FIFO_EMPTY;
264   m_sr &= ~UPD7220_SR_FIFO_FULL;
250265}
251266
252INLINE int fifo_param_count(upd7220_t *upd7220)
267
268//-------------------------------------------------
269//  fifo_param_count -
270//-------------------------------------------------
271
272inline int upd7220_device::fifo_param_count()
253273{
254274   int i;
255275
256276   for (i = 0; i < 16; i++)
257277   {
258      if (upd7220->fifo_flag[i] != FIFO_PARAMETER) break;
278      if (m_fifo_flag[i] != FIFO_PARAMETER) break;
259279   }
260280
261281   return i;
262282}
263283
264INLINE void fifo_set_direction(upd7220_t *upd7220, int dir)
284
285//-------------------------------------------------
286//  fifo_set_direction -
287//-------------------------------------------------
288
289inline void upd7220_device::fifo_set_direction(int dir)
265290{
266   if (upd7220->fifo_dir != dir)
291   if (m_fifo_dir != dir)
267292   {
268      fifo_clear(upd7220);
293      fifo_clear();
269294   }
270295
271   upd7220->fifo_dir = dir;
296   m_fifo_dir = dir;
272297}
273298
274INLINE void queue(upd7220_t *upd7220, UINT8 data, int flag)
299
300//-------------------------------------------------
301//  queue -
302//-------------------------------------------------
303
304inline void upd7220_device::queue(UINT8 data, int flag)
275305{
276   if (upd7220->fifo_ptr < 15)
306   if (m_fifo_ptr < 15)
277307   {
278      upd7220->fifo_ptr++;
308      m_fifo_ptr++;
279309
280      upd7220->fifo[upd7220->fifo_ptr] = data;
281      upd7220->fifo_flag[upd7220->fifo_ptr] = flag;
310      m_fifo[m_fifo_ptr] = data;
311      m_fifo_flag[m_fifo_ptr] = flag;
282312
283      if (upd7220->fifo_ptr == 16)
313      if (m_fifo_ptr == 16)
284314      {
285         upd7220->sr |= UPD7220_SR_FIFO_FULL;
315         m_sr |= UPD7220_SR_FIFO_FULL;
286316      }
287317
288      upd7220->sr &= ~UPD7220_SR_FIFO_EMPTY;
318      m_sr &= ~UPD7220_SR_FIFO_EMPTY;
289319   }
290320   else
291321   {
r11221r11222
294324   }
295325}
296326
297INLINE void dequeue(upd7220_t *upd7220, UINT8 *data, int *flag)
327
328//-------------------------------------------------
329//  dequeue -
330//-------------------------------------------------
331
332inline void upd7220_device::dequeue(UINT8 *data, int *flag)
298333{
299   int i;
334   *data = m_fifo[0];
335   *flag = m_fifo_flag[0];
300336
301   *data = upd7220->fifo[0];
302   *flag = upd7220->fifo_flag[0];
303
304   if (upd7220->fifo_ptr > -1)
337   if (m_fifo_ptr > -1)
305338   {
306      for (i = 0; i < 15; i++)
339      for (int i = 0; i < 15; i++)
307340      {
308         upd7220->fifo[i] = upd7220->fifo[i + 1];
309         upd7220->fifo_flag[i] = upd7220->fifo_flag[i + 1];
341         m_fifo[i] = m_fifo[i + 1];
342         m_fifo_flag[i] = m_fifo_flag[i + 1];
310343      }
311344
312      upd7220->fifo[15] = 0;
313      upd7220->fifo_flag[15] = 0;
345      m_fifo[15] = 0;
346      m_fifo_flag[15] = 0;
314347
315      upd7220->fifo_ptr--;
348      m_fifo_ptr--;
316349
317      if (upd7220->fifo_ptr == -1)
350      if (m_fifo_ptr == -1)
318351      {
319         upd7220->sr &= ~UPD7220_SR_DATA_READY;
320         upd7220->sr |= UPD7220_SR_FIFO_EMPTY;
352         m_sr &= ~UPD7220_SR_DATA_READY;
353         m_sr |= UPD7220_SR_FIFO_EMPTY;
321354      }
322355   }
323356}
324357
325/***************************************************************************
326    IMPLEMENTATION
327***************************************************************************/
328358
329/*-------------------------------------------------
330    update_vsync_timer -
331-------------------------------------------------*/
359//-------------------------------------------------
360//  update_vsync_timer -
361//-------------------------------------------------
332362
333static void update_vsync_timer(upd7220_t *upd7220, int state)
363inline void upd7220_device::update_vsync_timer(int state)
334364{
335   int next_y = state ? upd7220->vs : 0;
365   int next_y = state ? m_vs : 0;
336366
337   attotime duration = upd7220->screen->time_until_pos(next_y, 0);
367   attotime duration = m_screen->time_until_pos(next_y, 0);
338368
339   upd7220->vsync_timer->adjust(duration, !state);
369   m_vsync_timer->adjust(duration, !state);
340370}
341371
342/*-------------------------------------------------
343    TIMER_CALLBACK( vsync_tick )
344-------------------------------------------------*/
345372
346static TIMER_CALLBACK( vsync_tick )
347{
348   device_t *device = (device_t *)ptr;
349   upd7220_t *upd7220 = get_safe_token(device);
373//-------------------------------------------------
374//  update_hsync_timer -
375//-------------------------------------------------
350376
351   if (param)
352   {
353      upd7220->sr |= UPD7220_SR_VSYNC_ACTIVE;
354   }
355   else
356   {
357      upd7220->sr &= ~UPD7220_SR_VSYNC_ACTIVE;
358   }
359
360   devcb_call_write_line(&upd7220->out_vsync_func, param);
361
362   update_vsync_timer(upd7220, param);
363}
364
365/*-------------------------------------------------
366    update_hsync_timer -
367-------------------------------------------------*/
368
369static void update_hsync_timer(upd7220_t *upd7220, int state)
377inline void upd7220_device::update_hsync_timer(int state)
370378{
371   int y = upd7220->screen->vpos();
379   int y = m_screen->vpos();
372380
373   int next_x = state ? upd7220->hs : 0;
374   int next_y = state ? y : ((y + 1) % upd7220->al);
381   int next_x = state ? m_hs : 0;
382   int next_y = state ? y : ((y + 1) % m_al);
375383
376   attotime duration = upd7220->screen->time_until_pos(next_y, next_x);
384   attotime duration = m_screen->time_until_pos(next_y, next_x);
377385
378   upd7220->hsync_timer->adjust(duration, !state);
386   m_hsync_timer->adjust(duration, !state);
379387}
380388
381/*-------------------------------------------------
382    TIMER_CALLBACK( hsync_tick )
383-------------------------------------------------*/
384389
385static TIMER_CALLBACK( hsync_tick )
386{
387   device_t *device = (device_t *)ptr;
388   upd7220_t *upd7220 = get_safe_token(device);
390//-------------------------------------------------
391//  update_blank_timer -
392//-------------------------------------------------
389393
390   if (param)
391   {
392      upd7220->sr |= UPD7220_SR_HBLANK_ACTIVE;
393   }
394   else
395   {
396      upd7220->sr &= ~UPD7220_SR_HBLANK_ACTIVE;
397   }
398
399   devcb_call_write_line(&upd7220->out_hsync_func, param);
400
401   update_hsync_timer(upd7220, param);
402}
403
404/*-------------------------------------------------
405    update_blank_timer -
406-------------------------------------------------*/
407
408static void update_blank_timer(upd7220_t *upd7220, int state)
394inline void upd7220_device::update_blank_timer(int state)
409395{
410   int y = upd7220->screen->vpos();
396   int y = m_screen->vpos();
411397
412   int next_x = state ? (upd7220->hs + upd7220->hbp) : (upd7220->hs + upd7220->hbp + (upd7220->aw << 3));
413   int next_y = state ? ((y + 1) % (upd7220->vs + upd7220->vbp + upd7220->al + upd7220->vfp - 1)) : y;
398   int next_x = state ? (m_hs + m_hbp) : (m_hs + m_hbp + (m_aw << 3));
399   int next_y = state ? ((y + 1) % (m_vs + m_vbp + m_al + m_vfp - 1)) : y;
414400
415   attotime duration = upd7220->screen->time_until_pos(next_y, next_x);
401   attotime duration = m_screen->time_until_pos(next_y, next_x);
416402
417   upd7220->hsync_timer->adjust(duration, !state);
403   m_hsync_timer->adjust(duration, !state);
418404}
419405
420/*-------------------------------------------------
421    TIMER_CALLBACK( blank_tick )
422-------------------------------------------------*/
423406
424static TIMER_CALLBACK( blank_tick )
425{
426   device_t *device = (device_t *)ptr;
427   upd7220_t *upd7220 = get_safe_token(device);
407//-------------------------------------------------
408//  recompute_parameters -
409//-------------------------------------------------
428410
429   if (param)
430   {
431      upd7220->sr |= UPD7220_SR_HBLANK_ACTIVE;
432   }
433   else
434   {
435      upd7220->sr &= ~UPD7220_SR_HBLANK_ACTIVE;
436   }
437
438   devcb_call_write_line(&upd7220->out_blank_func, param);
439
440   update_blank_timer(upd7220, param);
441}
442
443/*-------------------------------------------------
444    recompute_parameters -
445-------------------------------------------------*/
446
447static void recompute_parameters(device_t *device)
411inline void upd7220_device::recompute_parameters()
448412{
449   upd7220_t *upd7220 = get_safe_token(device);
413   int horiz_pix_total = (m_hs + m_hbp + m_aw + m_hfp) * 8;
414   int vert_pix_total = m_vs + m_vbp + m_al + m_vfp;
450415
451   int horiz_pix_total = (upd7220->hs + upd7220->hbp + upd7220->aw + upd7220->hfp) * 8;
452   int vert_pix_total = upd7220->vs + upd7220->vbp + upd7220->al + upd7220->vfp;
416   //printf("%d %d %d %d\n",m_hs,m_hbp,m_aw,m_hfp);
417   //printf("%d %d\n",m_aw * 8,m_pitch * 8);
453418
454   //printf("%d %d %d %d\n",upd7220->hs,upd7220->hbp,upd7220->aw,upd7220->hfp);
455   //printf("%d %d\n",upd7220->aw * 8,upd7220->pitch * 8);
456
457   if(horiz_pix_total == 0 || vert_pix_total == 0) //bail out if screen params aren't valid
419   if (horiz_pix_total == 0 || vert_pix_total == 0) //bail out if screen params aren't valid
458420      return;
459421
460   attoseconds_t refresh = HZ_TO_ATTOSECONDS(60); //HZ_TO_ATTOSECONDS(device->clock() * 8) * horiz_pix_total * vert_pix_total;
422   attoseconds_t refresh = HZ_TO_ATTOSECONDS(60); //HZ_TO_ATTOSECONDS(clock() * 8) * horiz_pix_total * vert_pix_total;
461423
462424   rectangle visarea;
463425
464   visarea.min_x = 0; //(upd7220->hs + upd7220->hbp) * 8;
465   visarea.min_y = 0; //upd7220->vs + upd7220->vbp;
466   visarea.max_x = upd7220->aw * 8 - 1;//horiz_pix_total - (upd7220->hfp * 8) - 1;
467   visarea.max_y = upd7220->al - 1;//vert_pix_total - upd7220->vfp - 1;
426   visarea.min_x = 0; //(m_hs + m_hbp) * 8;
427   visarea.min_y = 0; //m_vs + m_vbp;
428   visarea.max_x = m_aw * 8 - 1;//horiz_pix_total - (m_hfp * 8) - 1;
429   visarea.max_y = m_al - 1;//vert_pix_total - m_vfp - 1;
468430
469431
470432   if (LOG)
471433   {
472      logerror("uPD7220 '%s' Screen: %u x %u @ %f Hz\n", device->tag(), horiz_pix_total, vert_pix_total, 1 / ATTOSECONDS_TO_DOUBLE(refresh));
473      logerror("uPD7220 '%s' Visible Area: (%u, %u) - (%u, %u)\n", device->tag(), visarea.min_x, visarea.min_y, visarea.max_x, visarea.max_y);
434      logerror("uPD7220 '%s' Screen: %u x %u @ %f Hz\n", tag(), horiz_pix_total, vert_pix_total, 1 / ATTOSECONDS_TO_DOUBLE(refresh));
435      logerror("uPD7220 '%s' Visible Area: (%u, %u) - (%u, %u)\n", tag(), visarea.min_x, visarea.min_y, visarea.max_x, visarea.max_y);
474436   }
475437
476   if (upd7220->m)
438   if (m_m)
477439   {
478      upd7220->screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh);
440      m_screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh);
479441
480      update_hsync_timer(upd7220, 0);
481      update_vsync_timer(upd7220, 0);
442      update_hsync_timer(0);
443      update_vsync_timer(0);
482444   }
483445   else
484446   {
485      upd7220->hsync_timer->enable(0);
486      upd7220->vsync_timer->enable(0);
447      m_hsync_timer->enable(0);
448      m_vsync_timer->enable(0);
487449   }
488450
489   update_blank_timer(upd7220, 0);
451   update_blank_timer(0);
490452}
491453
492/*-----------------------------------------------------
493    reset_figs_param - reset figs after each vram rmw
494-----------------------------------------------------*/
495454
496static void reset_figs_param(upd7220_t *upd7220)
455//-------------------------------------------------
456//  reset_figs_param -
457//-------------------------------------------------
458
459inline void upd7220_device::reset_figs_param()
497460{
498   upd7220->figs.dc = 0x0000;
499   upd7220->figs.d = 0x0008;
500   upd7220->figs.d1 = 0x0008;
501   upd7220->figs.d2 = 0x0000;
502   upd7220->figs.dm = 0x0000;
461   m_figs.m_dc = 0x0000;
462   m_figs.m_d = 0x0008;
463   m_figs.m_d1 = 0x0008;
464   m_figs.m_d2 = 0x0000;
465   m_figs.m_dm = 0x0000;
503466}
504467
505/*-------------------------------------------------
506    advance_ead - advance EAD pointer
507-------------------------------------------------*/
508468
509#define EAD         upd7220->ead
510#define DAD         upd7220->dad
511#define P         x_dir[upd7220->figs.dir] + (y_dir[upd7220->figs.dir] * upd7220->pitch)
512#define MSB(value)   (BIT(value, 15))
513#define LSB(value)   (BIT(value, 0))
514#define LR(value)   ((value << 1) | MSB(value))
515#define RR(value)   ((LSB(value) << 15) | (value >> 1))
469//-------------------------------------------------
470//  advance_ead -
471//-------------------------------------------------
516472
517static void advance_ead(upd7220_t *upd7220)
473inline void upd7220_device::advance_ead()
518474{
519   switch (upd7220->draw_mode & 0x07)
475   #define EAD         m_ead
476   #define DAD         m_dad
477   #define P         x_dir[m_figs.m_dir] + (y_dir[m_figs.m_dir] * m_pitch)
478   #define MSB(value)   (BIT(value, 15))
479   #define LSB(value)   (BIT(value, 0))
480   #define LR(value)   ((value << 1) | MSB(value))
481   #define RR(value)   ((LSB(value) << 15) | (value >> 1))
482
483   switch (m_draw_mode & 0x07)
520484   {
521485   case 0:
522486      EAD += P;
r11221r11222
564528   EAD &= 0x3ffff;
565529}
566530
567/*-------------------------------------------------
568    read_vram - read in the device memory space
569-------------------------------------------------*/
570531
571static void read_vram(upd7220_t *upd7220,UINT8 type, UINT8 mod)
532//-------------------------------------------------
533//  read_vram -
534//-------------------------------------------------
535
536inline void upd7220_device::read_vram(UINT8 type, UINT8 mod)
572537{
573   int i;
574
575   if(type == 1)
538   if (type == 1)
576539   {
577540      logerror("uPD7220 invalid type 1 RDAT parameter\n");
578541      return;
579542   }
580543
581   if(mod)
544   if (mod)
582545      logerror("uPD7220 RDAT used with mod = %02x?\n",mod);
583546
584   for(i=0;i<upd7220->figs.dc;i++)
547   for (int i = 0; i < m_figs.m_dc; i++)
585548   {
586549      switch(type)
587550      {
588551         case 0:
589            queue(upd7220, upd7220->vram[upd7220->ead*2], 0);
590            queue(upd7220, upd7220->vram[upd7220->ead*2+1], 0);
552            queue(m_vram[m_ead*2], 0);
553            queue(m_vram[m_ead*2+1], 0);
591554            break;
592555         case 2:
593            queue(upd7220, upd7220->vram[upd7220->ead*2], 0);
556            queue(m_vram[m_ead*2], 0);
594557            break;
595558         case 3:
596            queue(upd7220, upd7220->vram[upd7220->ead*2+1], 0);
559            queue(m_vram[m_ead*2+1], 0);
597560            break;
598561      }
599562
600      advance_ead(upd7220);
563      advance_ead();
601564   }
602565}
603566
604/*-------------------------------------------------
605    write_vram - write in the device memory space
606-------------------------------------------------*/
607567
608static void write_vram(upd7220_t *upd7220,UINT8 type, UINT8 mod)
568//-------------------------------------------------
569//  write_vram -
570//-------------------------------------------------
571
572inline void upd7220_device::write_vram(UINT8 type, UINT8 mod)
609573{
610   int i;
611574   UINT16 result;
612   if(type == 1)
575
576   if (type == 1)
613577   {
614578      printf("uPD7220 invalid type 1 WDAT parameter\n");
615579      return;
r11221r11222
620584   switch(type)
621585   {
622586      case 0:
623         result = (upd7220->pr[1] & 0xff);
624         result |= (upd7220->pr[2] << 8);
625         result &= upd7220->mask;
587         result = (m_pr[1] & 0xff);
588         result |= (m_pr[2] << 8);
589         result &= m_mask;
626590         break;
627591      case 2:
628         result = (upd7220->pr[1] & 0xff);
629         result &= (upd7220->mask & 0xff);
592         result = (m_pr[1] & 0xff);
593         result &= (m_mask & 0xff);
630594         break;
631595      case 3:
632         result = (upd7220->pr[1] << 8);
633         result &= (upd7220->mask & 0xff00);
596         result = (m_pr[1] << 8);
597         result &= (m_mask & 0xff00);
634598         break;
635599   }
636600
637601   //if(result)
638602   {
639      //printf("%04x %02x %02x %04x %02x %02x\n",upd7220->vram[upd7220->ead],upd7220->pr[1],upd7220->pr[2],upd7220->mask,type,mod);
640      //printf("%04x %02x %02x\n",upd7220->ead,upd7220->figs.dir,upd7220->pitch);
641      //printf("%04x %04x %02x %04x\n",upd7220->ead,result,mod,upd7220->figs.dc);
603      //printf("%04x %02x %02x %04x %02x %02x\n",m_vram[m_ead],m_pr[1],m_pr[2],m_mask,type,mod);
604      //printf("%04x %02x %02x\n",m_ead,m_figs.m_dir,m_pitch);
605      //printf("%04x %04x %02x %04x\n",m_ead,result,mod,m_figs.m_dc);
642606   }
643607
644   for(i=0;i<upd7220->figs.dc + 1;i++)
608   for(int i = 0; i < m_figs.m_dc + 1; i++)
645609   {
646610      switch(mod & 3)
647611      {
648612         case 0x00: //replace
649613            if(type == 0 || type == 2)
650               upd7220->vram[upd7220->ead*2+0] = result & 0xff;
614               m_vram[m_ead*2+0] = result & 0xff;
651615            if(type == 0 || type == 3)
652               upd7220->vram[upd7220->ead*2+1] = result >> 8;
616               m_vram[m_ead*2+1] = result >> 8;
653617            break;
654618         case 0x01: //complement
655619            if(type == 0 || type == 2)
656               upd7220->vram[upd7220->ead*2+0] ^= result & 0xff;
620               m_vram[m_ead*2+0] ^= result & 0xff;
657621            if(type == 0 || type == 3)
658               upd7220->vram[upd7220->ead*2+1] ^= result >> 8;
622               m_vram[m_ead*2+1] ^= result >> 8;
659623            break;
660624         case 0x02: //reset to zero
661625            if(type == 0 || type == 2)
662               upd7220->vram[upd7220->ead*2+0] &= ~result;
626               m_vram[m_ead*2+0] &= ~result;
663627            if(type == 0 || type == 3)
664               upd7220->vram[upd7220->ead*2+1] &= ~(result >> 8);
628               m_vram[m_ead*2+1] &= ~(result >> 8);
665629            break;
666630         case 0x03: //set to one
667631            if(type == 0 || type == 2)
668               upd7220->vram[upd7220->ead*2+0] |= result;
632               m_vram[m_ead*2+0] |= result;
669633            if(type == 0 || type == 3)
670               upd7220->vram[upd7220->ead*2+1] |= (result >> 8);
634               m_vram[m_ead*2+1] |= (result >> 8);
671635            break;
672636      }
673637
674      advance_ead(upd7220);
638      advance_ead();
675639   }
676640}
677641
678static UINT16 check_pattern(upd7220_t *upd7220, UINT16 pattern)
642
643//-------------------------------------------------
644//  check_pattern -
645//-------------------------------------------------
646
647inline UINT16 upd7220_device::check_pattern(UINT16 pattern)
679648{
680   UINT16 res;
649   UINT16 res = 0;
681650
682   res = 0;
683
684   switch(upd7220->bitmap_mod & 3)
651   switch (m_bitmap_mod & 3)
685652   {
686653      case 0: res = pattern; break; //replace
687654      case 1: res = pattern; break; //complement
r11221r11222
692659   return res;
693660}
694661
695static void draw_pixel(upd7220_t *upd7220,int x,int y,UINT16 tile_data)
662
663//-------------------------------------------------
664//  get_text_partition -
665//-------------------------------------------------
666
667inline void upd7220_device::get_text_partition(int index, UINT32 *sad, UINT16 *len, int *im, int *wd)
696668{
697   UINT32 addr = (y * upd7220->pitch * 2 + (x >> 3)) & 0x3ffff;
698   int dad;
669   *sad = ((m_ra[(index * 4) + 1] & 0x1f) << 8) | m_ra[(index * 4) + 0];
670   *len = ((m_ra[(index * 4) + 3] & 0x3f) << 4) | (m_ra[(index * 4) + 2] >> 4);
671   *im = BIT(m_ra[(index * 4) + 3], 6);
672   *wd = BIT(m_ra[(index * 4) + 3], 7);
673}
699674
700   dad = x & 0x7;
701675
702   if((upd7220->bitmap_mod & 3) == 1)
676//-------------------------------------------------
677//  get_graphics_partition -
678//-------------------------------------------------
679
680inline void upd7220_device::get_graphics_partition(int index, UINT32 *sad, UINT16 *len, int *im, int *wd)
681{
682   *sad = ((m_ra[(index * 4) + 2] & 0x03) << 16) | (m_ra[(index * 4) + 1] << 8) | m_ra[(index * 4) + 0];
683   *len = ((m_ra[(index * 4) + 3] & 0x3f) << 4) | (m_ra[(index * 4) + 2] >> 4);
684   *im = BIT(m_ra[(index * 4) + 3], 6);
685   *wd = BIT(m_ra[(index * 4) + 3], 7);
686}
687
688
689
690//**************************************************************************
691//  LIVE DEVICE
692//**************************************************************************
693
694//-------------------------------------------------
695//  upd7220_device - constructor
696//-------------------------------------------------
697
698upd7220_device::upd7220_device(running_machine &_machine, const upd7220_device_config &config)
699    : device_t(_machine, config),
700     device_memory_interface(_machine, config, *this),
701     m_mask(0),
702     m_pitch(0),
703     m_ead(0),
704     m_dad(0),
705     m_lad(0),
706     m_ra_addr(0),
707     m_sr(UPD7220_SR_FIFO_EMPTY),
708     m_cr(0),
709     m_param_ptr(0),
710     m_fifo_ptr(-1),
711     m_fifo_dir(0),
712     m_mode(0),
713     m_draw_mode(0),
714     m_de(0),
715     m_m(0),
716     m_aw(0),
717     m_al(0),
718     m_vs(0),
719     m_vfp(0),
720     m_vbp(0),
721     m_hs(0),
722     m_hfp(0),
723     m_hbp(0),
724     m_dc(0),
725     m_sc(0),
726     m_br(0),
727     m_ctop(0),
728     m_cbot(0),
729     m_lr(0),
730     m_disp(0),
731     m_gchr(0),
732     m_vram_bank(0),
733     m_bitmap_mod(0),
734      m_config(config)
735{
736   for (int i = 0; i < 16; i++)
703737   {
704      upd7220->vram[addr + upd7220->vram_bank] ^= ((tile_data) & (0x80 >> (dad)));
738      m_fifo[i] = 0;
739      m_fifo_flag[i] = FIFO_EMPTY;
740
741      m_ra[i] = 0;
705742   }
743
744   for (int i = 0; i < 17; i++)
745   {
746      m_pr[i] = 0;
747   }
748
749   m_figs.m_dir = 0;
750   m_figs.m_figure_type = 0;
751   m_figs.m_dc = 0;
752   m_figs.m_d = 0;
753   m_figs.m_d1 = 0;
754   m_figs.m_d2 = 0;
755   m_figs.m_dm = 0;
756}
757
758
759//-------------------------------------------------
760//  device_start - device-specific startup
761//-------------------------------------------------
762
763void upd7220_device::device_start()
764{
765   // allocate timers
766   m_vsync_timer = timer_alloc(TIMER_VSYNC);
767   m_hsync_timer = timer_alloc(TIMER_HSYNC);
768   m_blank_timer = timer_alloc(TIMER_BLANK);
769
770   // resolve callbacks
771    devcb_resolve_write_line(&m_out_drq_func, &m_config.m_out_drq_func, this);
772    devcb_resolve_write_line(&m_out_hsync_func, &m_config.m_out_hsync_func, this);
773    devcb_resolve_write_line(&m_out_vsync_func, &m_config.m_out_vsync_func, this);
774    devcb_resolve_write_line(&m_out_blank_func, &m_config.m_out_blank_func, this);
775
776   // find screen
777   m_screen = m_machine.device<screen_device>(m_config.m_screen_tag);
778
779   // register for state saving
780   save_item(NAME(m_ra));
781   save_item(NAME(m_sr));
782   save_item(NAME(m_mode));
783   save_item(NAME(m_de));
784   save_item(NAME(m_aw));
785   save_item(NAME(m_al));
786   save_item(NAME(m_vs));
787   save_item(NAME(m_vfp));
788   save_item(NAME(m_vbp));
789   save_item(NAME(m_hs));
790   save_item(NAME(m_hfp));
791   save_item(NAME(m_hbp));
792   save_item(NAME(m_m));
793   save_item(NAME(m_dc));
794   save_item(NAME(m_sc));
795   save_item(NAME(m_br));
796   save_item(NAME(m_lr));
797   save_item(NAME(m_ctop));
798   save_item(NAME(m_cbot));
799   save_item(NAME(m_ead));
800   save_item(NAME(m_dad));
801   save_item(NAME(m_lad));
802   save_item(NAME(m_disp));
803   save_item(NAME(m_gchr));
804   save_item(NAME(m_mask));
805   save_item(NAME(m_pitch));
806}
807
808
809//-------------------------------------------------
810//  device_reset - device-specific reset
811//-------------------------------------------------
812
813void upd7220_device::device_reset()
814{
815   devcb_call_write_line(&m_out_drq_func, CLEAR_LINE);
816}
817
818
819//-------------------------------------------------
820//  device_timer - handler timer events
821//-------------------------------------------------
822
823void upd7220_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
824{
825   switch (id)
826   {
827   case TIMER_HSYNC:
828      if (param)
829      {
830         m_sr |= UPD7220_SR_HBLANK_ACTIVE;
831      }
832      else
833      {
834         m_sr &= ~UPD7220_SR_HBLANK_ACTIVE;
835      }
836
837      devcb_call_write_line(&m_out_hsync_func, param);
838
839      update_hsync_timer(param);
840      break;
841
842   case TIMER_VSYNC:
843      if (param)
844      {
845         m_sr |= UPD7220_SR_VSYNC_ACTIVE;
846      }
847      else
848      {
849         m_sr &= ~UPD7220_SR_VSYNC_ACTIVE;
850      }
851
852      devcb_call_write_line(&m_out_vsync_func, param);
853
854      update_vsync_timer(param);
855      break;
856
857   case TIMER_BLANK:
858      if (param)
859      {
860         m_sr |= UPD7220_SR_HBLANK_ACTIVE;
861      }
862      else
863      {
864         m_sr &= ~UPD7220_SR_HBLANK_ACTIVE;
865      }
866
867      devcb_call_write_line(&m_out_blank_func, param);
868
869      update_blank_timer(param);
870      break;
871   }
872}
873
874
875//-------------------------------------------------
876//  draw_pixel -
877//-------------------------------------------------
878
879void upd7220_device::draw_pixel(int x, int y, UINT16 tile_data)
880{
881   UINT32 addr = (y * m_pitch * 2 + (x >> 3)) & 0x3ffff;
882
883   int dad = x & 0x7;
884
885   if((m_bitmap_mod & 3) == 1)
886   {
887      m_vram[addr + m_vram_bank] ^= ((tile_data) & (0x80 >> (dad)));
888   }
706889   else
707890   {
708      upd7220->vram[addr + upd7220->vram_bank] &= ~(0x80 >> (dad));
709      upd7220->vram[addr + upd7220->vram_bank] |= ((tile_data) & (0x80 >> (dad)));
891      m_vram[addr + m_vram_bank] &= ~(0x80 >> (dad));
892      m_vram[addr + m_vram_bank] |= ((tile_data) & (0x80 >> (dad)));
710893   }
711894}
712895
713static void draw_line(upd7220_t *upd7220,int x,int y)
896
897//-------------------------------------------------
898//  draw_line -
899//-------------------------------------------------
900
901void upd7220_device::draw_line(int x, int y)
714902{
715903   int line_size,i;
716904   const int line_x_dir[8] = { 0, 1, 1, 0, 0,-1,-1, 0};
r11221r11222
721909   int line_step = 0;
722910   UINT8 dot;
723911
724   line_size = upd7220->figs.dc + 1;
725   line_pattern = check_pattern(upd7220,(upd7220->ra[8]) | (upd7220->ra[9]<<8));
912   line_size = m_figs.m_dc + 1;
913   line_pattern = check_pattern((m_ra[8]) | (m_ra[9]<<8));
726914
727915   for(i = 0;i<line_size;i++)
728916   {
729      line_step = (upd7220->figs.d1 * i);
730      line_step/= (upd7220->figs.dc + 1);
917      line_step = (m_figs.m_d1 * i);
918      line_step/= (m_figs.m_dc + 1);
731919      line_step >>= 1;
732920      dot = ((line_pattern >> (i & 0xf)) & 1) << 7;
733      draw_pixel(upd7220,x + (line_step*line_x_step[upd7220->figs.dir]),y + (line_step*line_y_step[upd7220->figs.dir]),dot >> ((x + line_step*line_x_step[upd7220->figs.dir]) & 0x7));
734      x += line_x_dir[upd7220->figs.dir];
735      y += line_y_dir[upd7220->figs.dir];
921      draw_pixel(x + (line_step*line_x_step[m_figs.m_dir]),y + (line_step*line_y_step[m_figs.m_dir]),dot >> ((x + line_step*line_x_step[m_figs.m_dir]) & 0x7));
922      x += line_x_dir[m_figs.m_dir];
923      y += line_y_dir[m_figs.m_dir];
736924   }
737925
738926   /* TODO: check me*/
739   x += (line_step*line_x_step[upd7220->figs.dir]);
740   y += (line_step*line_y_step[upd7220->figs.dir]);
927   x += (line_step*line_x_step[m_figs.m_dir]);
928   y += (line_step*line_y_step[m_figs.m_dir]);
741929
742   upd7220->ead = (x >> 4) + (y * upd7220->pitch);
743   upd7220->dad = x & 0x0f;
930   m_ead = (x >> 4) + (y * m_pitch);
931   m_dad = x & 0x0f;
744932}
745933
746static void draw_rectangle(upd7220_t *upd7220,int x,int y)
934
935//-------------------------------------------------
936//  draw_rectangle -
937//-------------------------------------------------
938
939void upd7220_device::draw_rectangle(int x, int y)
747940{
748941   int i;
749942   const int rect_x_dir[8] = { 0, 1, 0,-1, 1, 1,-1,-1 };
r11221r11222
752945   UINT16 line_pattern;
753946   UINT8 dot;
754947
755   printf("uPD7220 rectangle check: %d %d %02x %08x\n",x,y,upd7220->figs.dir,upd7220->ead);
948   logerror("uPD7220 rectangle check: %d %d %02x %08x\n",x,y,m_figs.m_dir,m_ead);
756949
757   line_pattern = check_pattern(upd7220,(upd7220->ra[8]) | (upd7220->ra[9]<<8));
758   rect_type = (upd7220->figs.dir & 1) << 2;
759   rect_dir = rect_type | (((upd7220->figs.dir >> 1) + 0) & 3);
950   line_pattern = check_pattern((m_ra[8]) | (m_ra[9]<<8));
951   rect_type = (m_figs.m_dir & 1) << 2;
952   rect_dir = rect_type | (((m_figs.m_dir >> 1) + 0) & 3);
760953
761   for(i = 0;i < upd7220->figs.d;i++)
954   for(i = 0;i < m_figs.m_d;i++)
762955   {
763      dot = ((line_pattern >> ((i+upd7220->dad) & 0xf)) & 1) << 7;
764      draw_pixel(upd7220,x,y,dot >> (x & 0x7));
956      dot = ((line_pattern >> ((i+m_dad) & 0xf)) & 1) << 7;
957      draw_pixel(x,y,dot >> (x & 0x7));
765958      x+=rect_x_dir[rect_dir];
766959      y+=rect_y_dir[rect_dir];
767960   }
768961
769   rect_dir = rect_type | (((upd7220->figs.dir >> 1) + 1) & 3);
962   rect_dir = rect_type | (((m_figs.m_dir >> 1) + 1) & 3);
770963
771   for(i = 0;i < upd7220->figs.d2;i++)
964   for(i = 0;i < m_figs.m_d2;i++)
772965   {
773      dot = ((line_pattern >> ((i+upd7220->dad) & 0xf)) & 1) << 7;
774      draw_pixel(upd7220,x,y,dot >> (x & 0x7));
966      dot = ((line_pattern >> ((i+m_dad) & 0xf)) & 1) << 7;
967      draw_pixel(x,y,dot >> (x & 0x7));
775968      x+=rect_x_dir[rect_dir];
776969      y+=rect_y_dir[rect_dir];
777970   }
778971
779   rect_dir = rect_type | (((upd7220->figs.dir >> 1) + 2) & 3);
972   rect_dir = rect_type | (((m_figs.m_dir >> 1) + 2) & 3);
780973
781   for(i = 0;i < upd7220->figs.d;i++)
974   for(i = 0;i < m_figs.m_d;i++)
782975   {
783      dot = ((line_pattern >> ((i+upd7220->dad) & 0xf)) & 1) << 7;
784      draw_pixel(upd7220,x,y,dot >> (x & 0x7));
976      dot = ((line_pattern >> ((i+m_dad) & 0xf)) & 1) << 7;
977      draw_pixel(x,y,dot >> (x & 0x7));
785978      x+=rect_x_dir[rect_dir];
786979      y+=rect_y_dir[rect_dir];
787980   }
788981
789   rect_dir = rect_type | (((upd7220->figs.dir >> 1) + 3) & 3);
982   rect_dir = rect_type | (((m_figs.m_dir >> 1) + 3) & 3);
790983
791   for(i = 0;i < upd7220->figs.d2;i++)
984   for(i = 0;i < m_figs.m_d2;i++)
792985   {
793      dot = ((line_pattern >> ((i+upd7220->dad) & 0xf)) & 1) << 7;
794      draw_pixel(upd7220,x,y,dot >> (x & 0x7));
986      dot = ((line_pattern >> ((i+m_dad) & 0xf)) & 1) << 7;
987      draw_pixel(x,y,dot >> (x & 0x7));
795988      x+=rect_x_dir[rect_dir];
796989      y+=rect_y_dir[rect_dir];
797990   }
798991
799   upd7220->ead = (x >> 4) + (y * upd7220->pitch);
800   upd7220->dad = x & 0x0f;
992   m_ead = (x >> 4) + (y * m_pitch);
993   m_dad = x & 0x0f;
801994
802995}
803996
804/*-------------------------------------------------
805    draw_char - put per-pixel VRAM data (charset)
806-------------------------------------------------*/
807997
808static void draw_char(upd7220_t *upd7220,int x,int y)
998//-------------------------------------------------
999//  draw_char -
1000//-------------------------------------------------
1001
1002void upd7220_device::draw_char(int x, int y)
8091003{
8101004   int xi,yi;
8111005   int xsize,ysize;
r11221r11222
8171011   {
8181012      for(xi=0;xi<8;xi++)
8191013      {
820         printf("%d",(upd7220->ra[(yi & 7) | 8] >> xi) & 1);
1014         printf("%d",(m_ra[(yi & 7) | 8] >> xi) & 1);
8211015      }
8221016      printf("\n");
8231017   }
8241018   #endif
8251019
826   xsize = upd7220->figs.d & 0x3ff;
1020   xsize = m_figs.m_d & 0x3ff;
8271021   /* Guess: D has presumably upper bits for ysize, QX-10 relies on this (TODO: check this on any real HW) */
828   ysize = ((upd7220->figs.d & 0x400) + upd7220->figs.dc) + 1;
1022   ysize = ((m_figs.m_d & 0x400) + m_figs.m_dc) + 1;
8291023
8301024   /* TODO: internal direction, zooming, size stuff bigger than 8, rewrite using draw_pixel function */
8311025   for(yi=0;yi<ysize;yi++)
8321026   {
833      switch(upd7220->figs.dir & 7)
1027      switch(m_figs.m_dir & 7)
8341028      {
835         case 0: tile_data = BITSWAP8(upd7220->ra[((yi) & 7) | 8],0,1,2,3,4,5,6,7); break; // TODO
836         case 2:   tile_data = BITSWAP8(upd7220->ra[((yi) & 7) | 8],0,1,2,3,4,5,6,7); break;
837         case 6:   tile_data = BITSWAP8(upd7220->ra[((ysize-1-yi) & 7) | 8],7,6,5,4,3,2,1,0); break;
838         default: tile_data = BITSWAP8(upd7220->ra[((yi) & 7) | 8],7,6,5,4,3,2,1,0);
839                printf("%d %d %d\n",upd7220->figs.dir,xsize,ysize);
1029         case 0: tile_data = BITSWAP8(m_ra[((yi) & 7) | 8],0,1,2,3,4,5,6,7); break; // TODO
1030         case 2:   tile_data = BITSWAP8(m_ra[((yi) & 7) | 8],0,1,2,3,4,5,6,7); break;
1031         case 6:   tile_data = BITSWAP8(m_ra[((ysize-1-yi) & 7) | 8],7,6,5,4,3,2,1,0); break;
1032         default: tile_data = BITSWAP8(m_ra[((yi) & 7) | 8],7,6,5,4,3,2,1,0);
1033                printf("%d %d %d\n",m_figs.m_dir,xsize,ysize);
8401034                break;
8411035      }
8421036
8431037      for(xi=0;xi<xsize;xi++)
8441038      {
845         UINT32 addr = ((y+yi) * upd7220->pitch * 2) + ((x+xi) >> 3);
1039         UINT32 addr = ((y+yi) * m_pitch * 2) + ((x+xi) >> 3);
8461040
847         upd7220->vram[(addr + upd7220->vram_bank) & 0x3ffff] &= ~(1 << (xi & 7));
848         upd7220->vram[(addr + upd7220->vram_bank) & 0x3ffff] |= ((tile_data) & (1 << (xi & 7)));
1041         m_vram[(addr + m_vram_bank) & 0x3ffff] &= ~(1 << (xi & 7));
1042         m_vram[(addr + m_vram_bank) & 0x3ffff] |= ((tile_data) & (1 << (xi & 7)));
8491043      }
8501044   }
8511045
852   upd7220->ead = ((x+8*x_dir_dot[upd7220->figs.dir]) >> 4) + ((y+8*y_dir_dot[upd7220->figs.dir]) * upd7220->pitch);
853   upd7220->dad = ((x+8*x_dir_dot[upd7220->figs.dir]) & 0xf);
1046   m_ead = ((x+8*x_dir_dot[m_figs.m_dir]) >> 4) + ((y+8*y_dir_dot[m_figs.m_dir]) * m_pitch);
1047   m_dad = ((x+8*x_dir_dot[m_figs.m_dir]) & 0xf);
8541048}
8551049
856/*-------------------------------------------------
857    translate_command - translate command byte
858-------------------------------------------------*/
8591050
860static int translate_command(UINT8 data)
1051//-------------------------------------------------
1052//  translate_command -
1053//-------------------------------------------------
1054
1055int upd7220_device::translate_command(UINT8 data)
8611056{
8621057   int command = COMMAND_INVALID;
8631058
r11221r11222
9011096   return command;
9021097}
9031098
904/*-------------------------------------------------
905    process_fifo - process a single byte in FIFO
906-------------------------------------------------*/
9071099
908static void process_fifo(device_t *device)
1100//-------------------------------------------------
1101//  process_fifo -
1102//-------------------------------------------------
1103
1104void upd7220_device::process_fifo()
9091105{
910   upd7220_t *upd7220 = get_safe_token(device);
9111106   UINT8 data;
9121107   int flag;
9131108
914   dequeue(upd7220, &data, &flag);
1109   dequeue(&data, &flag);
9151110
9161111   if (flag == FIFO_COMMAND)
9171112   {
918      upd7220->cr = data;
919      upd7220->param_ptr = 1;
1113      m_cr = data;
1114      m_param_ptr = 1;
9201115   }
9211116   else
9221117   {
923      upd7220->pr[upd7220->param_ptr] = data;
924      upd7220->param_ptr++;
1118      m_pr[m_param_ptr] = data;
1119      m_param_ptr++;
9251120   }
9261121
927   switch (translate_command(upd7220->cr))
1122   switch (translate_command(m_cr))
9281123   {
9291124   case COMMAND_INVALID:
930      printf("uPD7220 '%s' Invalid Command Byte %02x\n", device->tag(), upd7220->cr);
1125      printf("uPD7220 '%s' Invalid Command Byte %02x\n", tag(), m_cr);
9311126      break;
9321127
9331128   case COMMAND_5A:
934      if (upd7220->param_ptr == 4)
935         printf("uPD7220 '%s' Undocumented Command 0x5A Executed %02x %02x %02x\n", device->tag(),upd7220->pr[1],upd7220->pr[2],upd7220->pr[3] );
1129      if (m_param_ptr == 4)
1130         printf("uPD7220 '%s' Undocumented Command 0x5A Executed %02x %02x %02x\n", tag(),m_pr[1],m_pr[2],m_pr[3] );
9361131      break;
9371132
9381133   case COMMAND_RESET: /* reset */
939      switch (upd7220->param_ptr)
1134      switch (m_param_ptr)
9401135      {
9411136      case 0:
942         if (LOG) logerror("uPD7220 '%s' RESET\n", device->tag());
1137         if (LOG) logerror("uPD7220 '%s' RESET\n", tag());
9431138
944         upd7220->de = 0;
945         upd7220->ra[0] = upd7220->ra[1] = upd7220->ra[2] = 0;
946         upd7220->ra[3] = 0x19;
947         upd7220->ead = 0;
948         upd7220->dad = 0;
949         upd7220->mask = 0;
1139         m_de = 0;
1140         m_ra[0] = m_ra[1] = m_ra[2] = 0;
1141         m_ra[3] = 0x19;
1142         m_ead = 0;
1143         m_dad = 0;
1144         m_mask = 0;
9501145         break;
9511146
9521147      case 9:
953         upd7220->mode = upd7220->pr[1];
954         upd7220->aw = upd7220->pr[2] + 2;
955         upd7220->hs = (upd7220->pr[3] & 0x1f) + 1;
956         upd7220->vs = ((upd7220->pr[4] & 0x03) << 3) | (upd7220->pr[3] >> 5);
957         upd7220->hfp = (upd7220->pr[4] >> 2) + 1;
958         upd7220->hbp = (upd7220->pr[5] & 0x3f) + 1;
959         upd7220->vfp = upd7220->pr[6] & 0x3f;
960         upd7220->al = ((upd7220->pr[8] & 0x03) << 8) | upd7220->pr[7];
961         upd7220->vbp = upd7220->pr[8] >> 2;
1148         m_mode = m_pr[1];
1149         m_aw = m_pr[2] + 2;
1150         m_hs = (m_pr[3] & 0x1f) + 1;
1151         m_vs = ((m_pr[4] & 0x03) << 3) | (m_pr[3] >> 5);
1152         m_hfp = (m_pr[4] >> 2) + 1;
1153         m_hbp = (m_pr[5] & 0x3f) + 1;
1154         m_vfp = m_pr[6] & 0x3f;
1155         m_al = ((m_pr[8] & 0x03) << 8) | m_pr[7];
1156         m_vbp = m_pr[8] >> 2;
9621157
963         upd7220->pitch = upd7220->aw;
1158         m_pitch = m_aw;
9641159
9651160         if (LOG)
9661161         {
967            logerror("uPD7220 '%s' Mode: %02x\n", device->tag(), upd7220->mode);
968            logerror("uPD7220 '%s' AW: %u\n", device->tag(), upd7220->aw);
969            logerror("uPD7220 '%s' HS: %u\n", device->tag(), upd7220->hs);
970            logerror("uPD7220 '%s' VS: %u\n", device->tag(), upd7220->vs);
971            logerror("uPD7220 '%s' HFP: %u\n", device->tag(), upd7220->hfp);
972            logerror("uPD7220 '%s' HBP: %u\n", device->tag(), upd7220->hbp);
973            logerror("uPD7220 '%s' VFP: %u\n", device->tag(), upd7220->vfp);
974            logerror("uPD7220 '%s' AL: %u\n", device->tag(), upd7220->al);
975            logerror("uPD7220 '%s' VBP: %u\n", device->tag(), upd7220->vbp);
976            logerror("uPD7220 '%s' PITCH: %u\n", device->tag(), upd7220->pitch);
1162            logerror("uPD7220 '%s' Mode: %02x\n", tag(), m_mode);
1163            logerror("uPD7220 '%s' AW: %u\n", tag(), m_aw);
1164            logerror("uPD7220 '%s' HS: %u\n", tag(), m_hs);
1165            logerror("uPD7220 '%s' VS: %u\n", tag(), m_vs);
1166            logerror("uPD7220 '%s' HFP: %u\n", tag(), m_hfp);
1167            logerror("uPD7220 '%s' HBP: %u\n", tag(), m_hbp);
1168            logerror("uPD7220 '%s' VFP: %u\n", tag(), m_vfp);
1169            logerror("uPD7220 '%s' AL: %u\n", tag(), m_al);
1170            logerror("uPD7220 '%s' VBP: %u\n", tag(), m_vbp);
1171            logerror("uPD7220 '%s' PITCH: %u\n", tag(), m_pitch);
9771172         }
9781173
979         recompute_parameters(device);
1174         recompute_parameters();
9801175         break;
9811176      }
9821177      break;
9831178
9841179   case COMMAND_SYNC: /* sync format specify */
985      if (upd7220->param_ptr == 9)
1180      if (m_param_ptr == 9)
9861181      {
987         upd7220->mode = upd7220->pr[1];
988         upd7220->aw = upd7220->pr[2] + 2;
989         upd7220->hs = (upd7220->pr[3] & 0x1f) + 1;
990         upd7220->vs = ((upd7220->pr[4] & 0x03) << 3) | (upd7220->pr[3] >> 5);
991         upd7220->hfp = (upd7220->pr[4] >> 2) + 1;
992         upd7220->hbp = (upd7220->pr[5] & 0x3f) + 1;
993         upd7220->vfp = upd7220->pr[6] & 0x3f;
994         upd7220->al = ((upd7220->pr[8] & 0x03) << 8) | upd7220->pr[7];
995         upd7220->vbp = upd7220->pr[8] >> 2;
1182         m_mode = m_pr[1];
1183         m_aw = m_pr[2] + 2;
1184         m_hs = (m_pr[3] & 0x1f) + 1;
1185         m_vs = ((m_pr[4] & 0x03) << 3) | (m_pr[3] >> 5);
1186         m_hfp = (m_pr[4] >> 2) + 1;
1187         m_hbp = (m_pr[5] & 0x3f) + 1;
1188         m_vfp = m_pr[6] & 0x3f;
1189         m_al = ((m_pr[8] & 0x03) << 8) | m_pr[7];
1190         m_vbp = m_pr[8] >> 2;
9961191
997         upd7220->pitch = upd7220->aw;
1192         m_pitch = m_aw;
9981193
9991194         if (LOG)
10001195         {
1001            logerror("uPD7220 '%s' Mode: %02x\n", device->tag(), upd7220->mode);
1002            logerror("uPD7220 '%s' AW: %u\n", device->tag(), upd7220->aw);
1003            logerror("uPD7220 '%s' HS: %u\n", device->tag(), upd7220->hs);
1004            logerror("uPD7220 '%s' VS: %u\n", device->tag(), upd7220->vs);
1005            logerror("uPD7220 '%s' HFP: %u\n", device->tag(), upd7220->hfp);
1006            logerror("uPD7220 '%s' HBP: %u\n", device->tag(), upd7220->hbp);
1007            logerror("uPD7220 '%s' VFP: %u\n", device->tag(), upd7220->vfp);
1008            logerror("uPD7220 '%s' AL: %u\n", device->tag(), upd7220->al);
1009            logerror("uPD7220 '%s' VBP: %u\n", device->tag(), upd7220->vbp);
1010            logerror("uPD7220 '%s' PITCH: %u\n", device->tag(), upd7220->pitch);
1196            logerror("uPD7220 '%s' Mode: %02x\n", tag(), m_mode);
1197            logerror("uPD7220 '%s' AW: %u\n", tag(), m_aw);
1198            logerror("uPD7220 '%s' HS: %u\n", tag(), m_hs);
1199            logerror("uPD7220 '%s' VS: %u\n", tag(), m_vs);
1200            logerror("uPD7220 '%s' HFP: %u\n", tag(), m_hfp);
1201            logerror("uPD7220 '%s' HBP: %u\n", tag(), m_hbp);
1202            logerror("uPD7220 '%s' VFP: %u\n", tag(), m_vfp);
1203            logerror("uPD7220 '%s' AL: %u\n", tag(), m_al);
1204            logerror("uPD7220 '%s' VBP: %u\n", tag(), m_vbp);
1205            logerror("uPD7220 '%s' PITCH: %u\n", tag(), m_pitch);
10111206         }
10121207
1013         recompute_parameters(device);
1208         recompute_parameters();
10141209      }
10151210      break;
10161211
10171212   case COMMAND_VSYNC: /* vertical sync mode */
1018      upd7220->m = upd7220->cr & 0x01;
1213      m_m = m_cr & 0x01;
10191214
1020      if (LOG) logerror("uPD7220 '%s' M: %u\n", device->tag(), upd7220->m);
1215      if (LOG) logerror("uPD7220 '%s' M: %u\n", tag(), m_m);
10211216
1022      recompute_parameters(device);
1217      recompute_parameters();
10231218      break;
10241219
10251220   case COMMAND_CCHAR: /* cursor & character characteristics */
1026      if(upd7220->param_ptr == 2)
1221      if(m_param_ptr == 2)
10271222      {
1028         upd7220->lr = (upd7220->pr[1] & 0x1f) + 1;
1029         upd7220->dc = BIT(upd7220->pr[1], 7);
1223         m_lr = (m_pr[1] & 0x1f) + 1;
1224         m_dc = BIT(m_pr[1], 7);
1225
1226         if (LOG)
1227         {
1228            logerror("uPD7220 '%s' LR: %u\n", tag(), m_lr);
1229            logerror("uPD7220 '%s' DC: %u\n", tag(), m_dc);
1230         }
10301231      }
10311232
1032      if(upd7220->param_ptr == 3)
1233      if(m_param_ptr == 3)
10331234      {
1034         upd7220->ctop = upd7220->pr[2] & 0x1f;
1035         upd7220->sc = BIT(upd7220->pr[2], 5);
1235         m_ctop = m_pr[2] & 0x1f;
1236         m_sc = BIT(m_pr[2], 5);
1237
1238         if (LOG)
1239         {
1240            logerror("uPD7220 '%s' CTOP: %u\n", tag(), m_ctop);
1241            logerror("uPD7220 '%s' SC: %u\n", tag(), m_sc);
1242         }
10361243      }
10371244
1038      if(upd7220->param_ptr == 4)
1245      if(m_param_ptr == 4)
10391246      {
1040         upd7220->br = ((upd7220->pr[3] & 0x07) << 2) | (upd7220->pr[2] >> 6);
1041         upd7220->cbot = upd7220->pr[3] >> 3;
1042      }
1247         m_br = ((m_pr[3] & 0x07) << 2) | (m_pr[2] >> 6);
1248         m_cbot = m_pr[3] >> 3;
10431249
1044      if (0)
1045      {
1046         logerror("uPD7220 '%s' LR: %u\n", device->tag(), upd7220->lr);
1047         logerror("uPD7220 '%s' DC: %u\n", device->tag(), upd7220->dc);
1048         logerror("uPD7220 '%s' CTOP: %u\n", device->tag(), upd7220->ctop);
1049         logerror("uPD7220 '%s' SC: %u\n", device->tag(), upd7220->sc);
1050         logerror("uPD7220 '%s' BR: %u\n", device->tag(), upd7220->br);
1051         logerror("uPD7220 '%s' CBOT: %u\n", device->tag(), upd7220->cbot);
1250         if (LOG)
1251         {
1252            logerror("uPD7220 '%s' BR: %u\n", tag(), m_br);
1253            logerror("uPD7220 '%s' CBOT: %u\n", tag(), m_cbot);
1254         }
10521255      }
10531256      break;
10541257
10551258   case COMMAND_START: /* start display & end idle mode */
1056      upd7220->de = 1;
1259      m_de = 1;
10571260
1058      if (LOG) logerror("uPD7220 '%s' DE: 1\n", device->tag());
1261      if (LOG) logerror("uPD7220 '%s' DE: 1\n", tag());
10591262      break;
10601263
10611264   case COMMAND_BCTRL: /* display blanking control */
1062      upd7220->de = upd7220->cr & 0x01;
1265      m_de = m_cr & 0x01;
10631266
1064      if (LOG) logerror("uPD7220 '%s' DE: %u\n", device->tag(), upd7220->de);
1267      if (LOG) logerror("uPD7220 '%s' DE: %u\n", tag(), m_de);
10651268      break;
10661269
10671270   case COMMAND_ZOOM: /* zoom factors specify */
10681271      if (flag == FIFO_PARAMETER)
10691272      {
1070         upd7220->gchr = upd7220->pr[1] & 0x0f;
1071         upd7220->disp = upd7220->pr[1] >> 4;
1273         m_gchr = m_pr[1] & 0x0f;
1274         m_disp = m_pr[1] >> 4;
10721275
1073         if (LOG) logerror("uPD7220 '%s' GCHR: %01x\n", device->tag(), upd7220->gchr);
1074         if (LOG) logerror("uPD7220 '%s' DISP: %01x\n", device->tag(), upd7220->disp);
1276         if (LOG) logerror("uPD7220 '%s' GCHR: %01x\n", tag(), m_gchr);
1277         if (LOG) logerror("uPD7220 '%s' DISP: %01x\n", tag(), m_disp);
10751278      }
10761279      break;
10771280
10781281   case COMMAND_CURS: /* cursor position specify */
1079      if (upd7220->param_ptr >= 3)
1282      if (m_param_ptr >= 3)
10801283      {
1081         UINT8 upper_addr;
1284         UINT8 upper_addr = (m_param_ptr == 3) ? 0 : (m_pr[3] & 0x03);
10821285
1083         upper_addr = (upd7220->param_ptr == 3) ? 0 : (upd7220->pr[3] & 0x03);
1286         m_ead = (upper_addr << 16) | (m_pr[2] << 8) | m_pr[1];
10841287
1085         upd7220->ead = (upper_addr << 16) | (upd7220->pr[2] << 8) | upd7220->pr[1];
1288         if (LOG) logerror("uPD7220 '%s' EAD: %06x\n", tag(), m_ead);
10861289
1087         if (LOG) logerror("uPD7220 '%s' EAD: %06x\n", device->tag(), upd7220->ead);
1088
1089         if(upd7220->param_ptr == 4)
1290         if(m_param_ptr == 4)
10901291         {
1091            upd7220->dad = upd7220->pr[3] >> 4;
1092            if (LOG) logerror("uPD7220 '%s' DAD: %01x\n", device->tag(), upd7220->dad);
1292            m_dad = m_pr[3] >> 4;
1293            if (LOG) logerror("uPD7220 '%s' DAD: %01x\n", tag(), m_dad);
10931294         }
10941295      }
10951296      break;
r11221r11222
10971298   case COMMAND_PRAM: /* parameter RAM load */
10981299      if (flag == FIFO_COMMAND)
10991300      {
1100         upd7220->ra_addr = upd7220->cr & 0x0f;
1301         m_ra_addr = m_cr & 0x0f;
11011302      }
11021303      else
11031304      {
1104         if (upd7220->ra_addr < 16)
1305         if (m_ra_addr < 16)
11051306         {
1106            if (LOG) logerror("uPD7220 '%s' RA%u: %02x\n", device->tag(), upd7220->ra_addr, data);
1307            if (LOG) logerror("uPD7220 '%s' RA%u: %02x\n", tag(), m_ra_addr, data);
11071308
1108            upd7220->ra[upd7220->ra_addr] = data;
1109            upd7220->ra_addr++;
1309            m_ra[m_ra_addr] = data;
1310            m_ra_addr++;
11101311         }
11111312
1112         upd7220->param_ptr = 0;
1313         m_param_ptr = 0;
11131314      }
11141315      break;
11151316
11161317   case COMMAND_PITCH: /* pitch specification */
11171318      if (flag == FIFO_PARAMETER)
11181319      {
1119         upd7220->pitch = data;
1320         m_pitch = data;
11201321
1121         if (LOG) logerror("uPD7220 '%s' PITCH: %u\n", device->tag(), upd7220->pitch);
1322         if (LOG) logerror("uPD7220 '%s' PITCH: %u\n", tag(), m_pitch);
11221323      }
11231324      break;
11241325
11251326   case COMMAND_WDAT: /* write data into display memory */
1126      upd7220->bitmap_mod = upd7220->cr & 3;
1327      m_bitmap_mod = m_cr & 3;
11271328
1128      if (upd7220->param_ptr == 3 || (upd7220->param_ptr == 2 && upd7220->cr & 0x10))
1329      if (m_param_ptr == 3 || (m_param_ptr == 2 && m_cr & 0x10))
11291330      {
1130         //printf("%02x = %02x %02x (%c) %04x\n",upd7220->cr,upd7220->pr[2],upd7220->pr[1],upd7220->pr[1],EAD);
1131         fifo_set_direction(upd7220, FIFO_WRITE);
1331         //printf("%02x = %02x %02x (%c) %04x\n",m_cr,m_pr[2],m_pr[1],m_pr[1],EAD);
1332         fifo_set_direction(FIFO_WRITE);
11321333
1133         write_vram(upd7220,(upd7220->cr & 0x18) >> 3,upd7220->cr & 3);
1134         reset_figs_param(upd7220);
1135         upd7220->param_ptr = 1;
1334         write_vram((m_cr & 0x18) >> 3,m_cr & 3);
1335         reset_figs_param();
1336         m_param_ptr = 1;
11361337      }
11371338      break;
11381339
11391340   case COMMAND_MASK: /* mask register load */
1140      if (upd7220->param_ptr == 3)
1341      if (m_param_ptr == 3)
11411342      {
1142         upd7220->mask = (upd7220->pr[2] << 8) | upd7220->pr[1];
1343         m_mask = (m_pr[2] << 8) | m_pr[1];
11431344
1144         if (LOG) logerror("uPD7220 '%s' MASK: %04x\n", device->tag(), upd7220->mask);
1345         if (LOG) logerror("uPD7220 '%s' MASK: %04x\n", tag(), m_mask);
11451346      }
11461347      break;
11471348
11481349   case COMMAND_FIGS: /* figure drawing parameters specify */
1149      if (upd7220->param_ptr == 2)
1350      if (m_param_ptr == 2)
11501351      {
1151         upd7220->figs.dir = upd7220->pr[1] & 0x7;
1152         upd7220->figs.figure_type = (upd7220->pr[1] & 0xf8) >> 3;
1352         m_figs.m_dir = m_pr[1] & 0x7;
1353         m_figs.m_figure_type = (m_pr[1] & 0xf8) >> 3;
11531354
1154         //if(upd7220->figs.dir != 2)
1155         //   printf("DIR %02x\n",upd7220->pr[1]);
1355         //if(m_figs.m_dir != 2)
1356         //   printf("DIR %02x\n",m_pr[1]);
11561357      }
11571358
1158      if (upd7220->param_ptr == 4)
1159         upd7220->figs.dc = (upd7220->pr[2]) | ((upd7220->pr[3] & 0x3f) << 8);
1359      if (m_param_ptr == 4)
1360         m_figs.m_dc = (m_pr[2]) | ((m_pr[3] & 0x3f) << 8);
11601361
1161      if (upd7220->param_ptr == 6)
1162         upd7220->figs.d = (upd7220->pr[4]) | ((upd7220->pr[5] & 0x3f) << 8);
1362      if (m_param_ptr == 6)
1363         m_figs.m_d = (m_pr[4]) | ((m_pr[5] & 0x3f) << 8);
11631364
1164      if (upd7220->param_ptr == 8)
1165         upd7220->figs.d2 = (upd7220->pr[6]) | ((upd7220->pr[7] & 0x3f) << 8);
1365      if (m_param_ptr == 8)
1366         m_figs.m_d2 = (m_pr[6]) | ((m_pr[7] & 0x3f) << 8);
11661367
1167      if (upd7220->param_ptr == 10)
1168         upd7220->figs.d1 = (upd7220->pr[8]) | ((upd7220->pr[9] & 0x3f) << 8);
1368      if (m_param_ptr == 10)
1369         m_figs.m_d1 = (m_pr[8]) | ((m_pr[9] & 0x3f) << 8);
11691370
1170      if (upd7220->param_ptr == 12)
1171         upd7220->figs.dm = (upd7220->pr[10]) | ((upd7220->pr[11] & 0x3f) << 8);
1371      if (m_param_ptr == 12)
1372         m_figs.m_dm = (m_pr[10]) | ((m_pr[11] & 0x3f) << 8);
11721373
11731374      break;
11741375
11751376   case COMMAND_FIGD: /* figure draw start */
1176      if(upd7220->figs.figure_type == 0)
1377      if(m_figs.m_figure_type == 0)
11771378      {
1178         UINT16 line_pattern = check_pattern(upd7220,(upd7220->ra[8]) | (upd7220->ra[9]<<8));
1379         UINT16 line_pattern = check_pattern((m_ra[8]) | (m_ra[9]<<8));
11791380         UINT8 dot = ((line_pattern >> (0 & 0xf)) & 1) << 7;
11801381
1181         draw_pixel(upd7220,((upd7220->ead % upd7220->pitch) << 4) | (upd7220->dad & 0xf),(upd7220->ead / upd7220->pitch),dot);
1382         draw_pixel(((m_ead % m_pitch) << 4) | (m_dad & 0xf),(m_ead / m_pitch),dot);
11821383      }
1183      else if(upd7220->figs.figure_type == 1)
1184         draw_line(upd7220,((upd7220->ead % upd7220->pitch) << 4) | (upd7220->dad & 0xf),(upd7220->ead / upd7220->pitch));
1185      else if(upd7220->figs.figure_type == 8)
1186         draw_rectangle(upd7220,((upd7220->ead % upd7220->pitch) << 4) | (upd7220->dad & 0xf),(upd7220->ead / upd7220->pitch));
1384      else if(m_figs.m_figure_type == 1)
1385         draw_line(((m_ead % m_pitch) << 4) | (m_dad & 0xf),(m_ead / m_pitch));
1386      else if(m_figs.m_figure_type == 8)
1387         draw_rectangle(((m_ead % m_pitch) << 4) | (m_dad & 0xf),(m_ead / m_pitch));
11871388      else
1188         printf("uPD7220 '%s' Unimplemented command FIGD %02x\n", device->tag(),upd7220->figs.figure_type);
1389         printf("uPD7220 '%s' Unimplemented command FIGD %02x\n", tag(),m_figs.m_figure_type);
11891390
1190      reset_figs_param(upd7220);
1191      upd7220->sr |= UPD7220_SR_DRAWING_IN_PROGRESS;
1391      reset_figs_param();
1392      m_sr |= UPD7220_SR_DRAWING_IN_PROGRESS;
11921393      break;
11931394
11941395   case COMMAND_GCHRD: /* graphics character draw and area filling start */
1195      if(upd7220->figs.figure_type == 2)
1196         draw_char(upd7220,((upd7220->ead % upd7220->pitch) << 4) | (upd7220->dad & 0xf),(upd7220->ead / upd7220->pitch));
1396      if(m_figs.m_figure_type == 2)
1397         draw_char(((m_ead % m_pitch) << 4) | (m_dad & 0xf),(m_ead / m_pitch));
11971398      else
1198         printf("uPD7220 '%s' Unimplemented command GCHRD %02x\n", device->tag(),upd7220->figs.figure_type);
1399         printf("uPD7220 '%s' Unimplemented command GCHRD %02x\n", tag(),m_figs.m_figure_type);
11991400
1200      reset_figs_param(upd7220);
1201      upd7220->sr |= UPD7220_SR_DRAWING_IN_PROGRESS;
1401      reset_figs_param();
1402      m_sr |= UPD7220_SR_DRAWING_IN_PROGRESS;
12021403      break;
12031404
12041405   case COMMAND_RDAT: /* read data from display memory */
1205      fifo_set_direction(upd7220, FIFO_READ);
1406      fifo_set_direction(FIFO_READ);
12061407
1207      read_vram(upd7220,(upd7220->cr & 0x18) >> 3,upd7220->cr & 3);
1208      reset_figs_param(upd7220);
1408      read_vram((m_cr & 0x18) >> 3,m_cr & 3);
1409      reset_figs_param();
12091410
1210      upd7220->sr |= UPD7220_SR_DATA_READY;
1411      m_sr |= UPD7220_SR_DATA_READY;
12111412      break;
12121413
12131414   case COMMAND_CURD: /* cursor address read */
1214      fifo_set_direction(upd7220, FIFO_READ);
1415      fifo_set_direction(FIFO_READ);
12151416
1216      queue(upd7220, upd7220->ead & 0xff, 0);
1217      queue(upd7220, (upd7220->ead >> 8) & 0xff, 0);
1218      queue(upd7220, upd7220->ead >> 16, 0);
1219      queue(upd7220, upd7220->dad & 0xff, 0);
1220      queue(upd7220, upd7220->dad >> 8, 0);
1417      queue(m_ead & 0xff, 0);
1418      queue((m_ead >> 8) & 0xff, 0);
1419      queue(m_ead >> 16, 0);
1420      queue(m_dad & 0xff, 0);
1421      queue(m_dad >> 8, 0);
12211422
1222      upd7220->sr |= UPD7220_SR_DATA_READY;
1423      m_sr |= UPD7220_SR_DATA_READY;
12231424      break;
12241425
12251426   case COMMAND_LPRD: /* light pen address read */
1226      fifo_set_direction(upd7220, FIFO_READ);
1427      fifo_set_direction(FIFO_READ);
12271428
1228      queue(upd7220, upd7220->lad & 0xff, 0);
1229      queue(upd7220, (upd7220->lad >> 8) & 0xff, 0);
1230      queue(upd7220, upd7220->lad >> 16, 0);
1429      queue(m_lad & 0xff, 0);
1430      queue((m_lad >> 8) & 0xff, 0);
1431      queue(m_lad >> 16, 0);
12311432
1232      upd7220->sr |= UPD7220_SR_DATA_READY;
1233      upd7220->sr &= ~UPD7220_SR_LIGHT_PEN_DETECT;
1433      m_sr |= UPD7220_SR_DATA_READY;
1434      m_sr &= ~UPD7220_SR_LIGHT_PEN_DETECT;
12341435      break;
12351436
12361437   case COMMAND_DMAR: /* DMA read request */
1237      printf("uPD7220 '%s' Unimplemented command DMAR\n", device->tag());
1438      printf("uPD7220 '%s' Unimplemented command DMAR\n", tag());
12381439      break;
12391440
12401441   case COMMAND_DMAW: /* DMA write request */
1241      printf("uPD7220 '%s' Unimplemented command DMAW\n", device->tag());
1442      printf("uPD7220 '%s' Unimplemented command DMAW\n", tag());
12421443      break;
12431444   }
12441445}
12451446
1246/*-------------------------------------------------
1247    upd7220_r - register read
1248-------------------------------------------------*/
12491447
1250READ8_DEVICE_HANDLER( upd7220_r )
1448//-------------------------------------------------
1449//  read -
1450//-------------------------------------------------
1451
1452READ8_MEMBER( upd7220_device::read )
12511453{
1252   upd7220_t *upd7220 = get_safe_token(device);
1253
12541454   UINT8 data;
12551455
12561456   if (offset & 1)
12571457   {
12581458      /* FIFO read */
12591459      int flag;
1260      fifo_set_direction(upd7220, FIFO_READ);
1261      dequeue(upd7220, &data, &flag);
1460      fifo_set_direction(FIFO_READ);
1461      dequeue(&data, &flag);
12621462   }
12631463   else
12641464   {
12651465      /* status register */
1266      data = upd7220->sr;
1466      data = m_sr;
12671467
12681468      /* TODO: timing of these */
1269      upd7220->sr &= ~UPD7220_SR_DRAWING_IN_PROGRESS;
1270      upd7220->sr &= ~UPD7220_SR_DMA_EXECUTE;
1469      m_sr &= ~UPD7220_SR_DRAWING_IN_PROGRESS;
1470      m_sr &= ~UPD7220_SR_DMA_EXECUTE;
12711471   }
12721472
12731473   return data;
12741474}
12751475
1276/*-------------------------------------------------
1277    upd7220_w - register write
1278-------------------------------------------------*/
12791476
1280WRITE8_DEVICE_HANDLER( upd7220_w )
1477//-------------------------------------------------
1478//  write -
1479//-------------------------------------------------
1480
1481WRITE8_MEMBER( upd7220_device::write )
12811482{
1282   upd7220_t *upd7220 = get_safe_token(device);
1283
12841483   if (offset & 1)
12851484   {
12861485      /* command into FIFO */
1287      fifo_set_direction(upd7220, FIFO_WRITE);
1288      queue(upd7220, data, 1);
1486      fifo_set_direction(FIFO_WRITE);
1487      queue(data, 1);
12891488   }
12901489   else
12911490   {
12921491      /* parameter into FIFO */
1293//      fifo_set_direction(upd7220, FIFO_WRITE);
1294      queue(upd7220, data, 0);
1492//      fifo_set_direction(FIFO_WRITE);
1493      queue(data, 0);
12951494   }
12961495
1297   process_fifo(device);
1496   process_fifo();
12981497}
12991498
1300WRITE8_DEVICE_HANDLER( upd7220_bank_w )
1301{
1302   upd7220_t *upd7220 = get_safe_token(device);
13031499
1304   upd7220->vram_bank = 0x8000 * (data & 7);
1305}
1500//-------------------------------------------------
1501//  dack_r -
1502//-------------------------------------------------
13061503
1307/*-------------------------------------------------
1308    upd7220_dack_w - DMA acknowledge read
1309-------------------------------------------------*/
1310
1311READ8_DEVICE_HANDLER( upd7220_dack_r )
1504READ8_MEMBER( upd7220_device::dack_r )
13121505{
13131506   return 0;
13141507}
13151508
1316/*-------------------------------------------------
1317    upd7220_dack_w - DMA acknowledge write
1318-------------------------------------------------*/
13191509
1320WRITE8_DEVICE_HANDLER( upd7220_dack_w )
1510//-------------------------------------------------
1511//  dack_w -
1512//-------------------------------------------------
1513
1514WRITE8_MEMBER( upd7220_device::dack_w )
13211515{
13221516}
13231517
1324/*-------------------------------------------------
1325    upd7220_ext_sync_w - external synchronization
1326-------------------------------------------------*/
13271518
1328WRITE_LINE_DEVICE_HANDLER( upd7220_ext_sync_w )
1519//-------------------------------------------------
1520//  ext_sync_w -
1521//-------------------------------------------------
1522
1523WRITE_LINE_MEMBER( upd7220_device::ext_sync_w )
13291524{
1330   upd7220_t *upd7220 = get_safe_token(device);
1525   //if (LOG) logerror("uPD7220 '%s' External Synchronization: %u\n", tag(), state);
13311526
1332   //if (LOG) logerror("uPD7220 '%s' External Synchronization: %u\n", device->tag(), state);
1333
13341527   if (state)
13351528   {
1336      upd7220->sr |= UPD7220_SR_VSYNC_ACTIVE;
1529      m_sr |= UPD7220_SR_VSYNC_ACTIVE;
13371530   }
13381531   else
13391532   {
1340      upd7220->sr &= ~UPD7220_SR_VSYNC_ACTIVE;
1533      m_sr &= ~UPD7220_SR_VSYNC_ACTIVE;
13411534   }
13421535}
13431536
1344/*-------------------------------------------------
1345    upd7220_lpen_w - light pen strobe
1346-------------------------------------------------*/
13471537
1348WRITE_LINE_DEVICE_HANDLER( upd7220_lpen_w )
1538//-------------------------------------------------
1539//  ext_sync_w -
1540//-------------------------------------------------
1541
1542WRITE_LINE_MEMBER( upd7220_device::lpen_w )
13491543{
13501544   /* only if 2 rising edges on the lpen input occur at the same
13511545       point during successive video fields are the pulses accepted */
r11221r11222
13601554    */
13611555}
13621556
1363INLINE void get_text_partition(upd7220_t *upd7220, int index, UINT32 *sad, UINT16 *len, int *im, int *wd)
1364{
1365   *sad = ((upd7220->ra[(index * 4) + 1] & 0x1f) << 8) | upd7220->ra[(index * 4) + 0];
1366   *len = ((upd7220->ra[(index * 4) + 3] & 0x3f) << 4) | (upd7220->ra[(index * 4) + 2] >> 4);
1367   *im = BIT(upd7220->ra[(index * 4) + 3], 6);
1368   *wd = BIT(upd7220->ra[(index * 4) + 3], 7);
1369}
13701557
1371/*-------------------------------------------------
1372    update_text - update text mode screen
1373-------------------------------------------------*/
1558//-------------------------------------------------
1559//  update_text -
1560//-------------------------------------------------
13741561
1375static void update_text(device_t *device, bitmap_t *bitmap, const rectangle *cliprect)
1562void upd7220_device::update_text(bitmap_t *bitmap, const rectangle *cliprect)
13761563{
1377   upd7220_t *upd7220 = get_safe_token(device);
1378
13791564   UINT32 addr, sad;
13801565   UINT16 len;
1381   int im, wd, area;
1566   int im, wd;
13821567   int y, sy = 0;
13831568
1384   for (area = 0; area < 4; area++)
1569   for (int area = 0; area < 4; area++)
13851570   {
1386      get_text_partition(upd7220, area, &sad, &len, &im, &wd);
1571      get_text_partition(area, &sad, &len, &im, &wd);
13871572
13881573      for (y = sy; y < sy + len; y++)
13891574      {
1390         addr = sad + (y * upd7220->pitch);
1391         if (upd7220->draw_text_func) upd7220->draw_text_func(device, bitmap, upd7220->vram, addr, y, wd, upd7220->pitch,0,0,upd7220->aw * 8 - 1,upd7220->al - 1, upd7220->lr, upd7220->dc, upd7220->ead);
1575         addr = sad + (y * m_pitch);
1576
1577         if (m_config.m_draw_text_func)
1578            m_config.m_draw_text_func(this, bitmap, m_vram, addr, y, wd, m_pitch, 0, 0, m_aw * 8 - 1, m_al - 1, m_lr, m_dc, m_ead);
13921579      }
13931580
13941581      sy = y + 1;
13951582   }
13961583}
13971584
1398/*-------------------------------------------------
1399    draw_graphics_line - draw graphics scanline
1400-------------------------------------------------*/
14011585
1402static void draw_graphics_line(device_t *device, bitmap_t *bitmap, UINT32 addr, int y, int wd)
1586//-------------------------------------------------
1587//  draw_graphics_line -
1588//-------------------------------------------------
1589
1590void upd7220_device::draw_graphics_line(bitmap_t *bitmap, UINT32 addr, int y, int wd)
14031591{
1404   upd7220_t *upd7220 = get_safe_token(device);
1405   address_space *space = device->machine().device("maincpu")->memory().space(AS_PROGRAM);
1592   address_space *space = m_machine.device("maincpu")->memory().space(AS_PROGRAM);
14061593   int sx;
14071594
1408   for (sx = 0; sx < upd7220->pitch * 2; sx++)
1595   for (sx = 0; sx < m_pitch * 2; sx++)
14091596   {
14101597      UINT16 data = space->direct().read_raw_word(addr & 0x3ffff); //TODO: remove me
14111598
1412      if((sx << 3) < upd7220->aw * 16 && y < upd7220->al)
1413         upd7220->display_func(device, bitmap, y, sx << 3, addr, data, upd7220->vram);
1599      if((sx << 3) < m_aw * 16 && y < m_al)
1600         m_config.m_display_func(this, bitmap, y, sx << 3, addr, data, m_vram);
14141601
14151602      if (wd) addr += 2; else addr++;
14161603   }
14171604}
14181605
1419INLINE void get_graphics_partition(upd7220_t *upd7220, int index, UINT32 *sad, UINT16 *len, int *im, int *wd)
1420{
1421   *sad = ((upd7220->ra[(index * 4) + 2] & 0x03) << 16) | (upd7220->ra[(index * 4) + 1] << 8) | upd7220->ra[(index * 4) + 0];
1422   *len = ((upd7220->ra[(index * 4) + 3] & 0x3f) << 4) | (upd7220->ra[(index * 4) + 2] >> 4);
1423   *im = BIT(upd7220->ra[(index * 4) + 3], 6);
1424   *wd = BIT(upd7220->ra[(index * 4) + 3], 7);
1425}
14261606
1427/*-------------------------------------------------
1428    update_graphics - update graphics mode screen
1429-------------------------------------------------*/
1607//-------------------------------------------------
1608//  update_graphics -
1609//-------------------------------------------------
14301610
1431static void update_graphics(device_t *device, bitmap_t *bitmap, const rectangle *cliprect, int force_bitmap)
1611void upd7220_device::update_graphics(bitmap_t *bitmap, const rectangle *cliprect, int force_bitmap)
14321612{
1433   upd7220_t *upd7220 = get_safe_token(device);
1434
14351613   UINT32 addr, sad;
14361614   UINT16 len;
14371615   int im, wd, area;
r11221r11222
14391617
14401618   for (area = 0; area < 2; area++)
14411619   {
1442      get_graphics_partition(upd7220, area, &sad, &len, &im, &wd);
1620      get_graphics_partition(area, &sad, &len, &im, &wd);
14431621
14441622      for (y = 0; y < len; y++)
14451623      {
14461624         if (im || force_bitmap)
14471625         {
1448            addr = (sad & 0x3ffff) + (y * upd7220->pitch * 2);
1626            addr = (sad & 0x3ffff) + (y * m_pitch * 2);
14491627
1450            if(upd7220->display_func)
1451               draw_graphics_line(device, bitmap, addr, y + bsy, wd);
1628            if (m_config.m_display_func)
1629               draw_graphics_line(bitmap, addr, y + bsy, wd);
14521630         }
14531631         else
14541632         {
14551633            /* TODO: text params are more limited compared to graphics */
1456            addr = (sad & 0x3ffff) + (y * upd7220->pitch);
1634            addr = (sad & 0x3ffff) + (y * m_pitch);
14571635
1458            if (upd7220->draw_text_func)
1459               upd7220->draw_text_func(device, bitmap, upd7220->vram, addr, y + tsy, wd, upd7220->pitch,0,0,upd7220->aw * 8 - 1,len + bsy - 1,upd7220->lr, upd7220->dc, upd7220->ead);
1636            if (m_config.m_draw_text_func)
1637               m_config.m_draw_text_func(this, bitmap, m_vram, addr, y + tsy, wd, m_pitch, 0, 0, m_aw * 8 - 1, len + bsy - 1, m_lr, m_dc, m_ead);
14601638         }
14611639      }
14621640
1463      if(upd7220->lr)
1464         tsy += (y / upd7220->lr);
1641      if (m_lr)
1642         tsy += (y / m_lr);
14651643      bsy += y;
14661644   }
14671645}
14681646
1469/*-------------------------------------------------
1470    upd7220_update - update screen
1471-------------------------------------------------*/
14721647
1473void upd7220_update(device_t *device, bitmap_t *bitmap, const rectangle *cliprect)
1648//-------------------------------------------------
1649//  update_screen -
1650//-------------------------------------------------
1651
1652void upd7220_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect)
14741653{
1475   upd7220_t *upd7220 = get_safe_token(device);
1476
1477   if (upd7220->de)
1654   if (m_de)
14781655   {
1479      switch (upd7220->mode & UPD7220_MODE_DISPLAY_MASK)
1656      switch (m_mode & UPD7220_MODE_DISPLAY_MASK)
14801657      {
14811658      case UPD7220_MODE_DISPLAY_MIXED:
1482         update_graphics(device, bitmap, cliprect,0);
1659         update_graphics(bitmap, cliprect, 0);
14831660         break;
14841661
14851662      case UPD7220_MODE_DISPLAY_GRAPHICS:
1486         update_graphics(device, bitmap, cliprect,1);
1663         update_graphics(bitmap, cliprect, 1);
14871664         break;
14881665
14891666      case UPD7220_MODE_DISPLAY_CHARACTER:
1490         update_text(device, bitmap, cliprect);
1667         update_text(bitmap, cliprect);
14911668         break;
14921669
14931670      case UPD7220_MODE_DISPLAY_INVALID:
1494         logerror("uPD7220 '%s' Invalid Display Mode!\n", device->tag());
1671         logerror("uPD7220 '%s' Invalid Display Mode!\n", tag());
14951672      }
14961673   }
14971674}
14981675
1499/*-------------------------------------------------
1500    ROM( upd7220 )
1501-------------------------------------------------*/
1502
1503ROM_START( upd7220 )
1504   ROM_REGION( 0x100, "upd7220", ROMREGION_LOADBYNAME )
1505   ROM_LOAD( "upd7220.bin", 0x000, 0x100, NO_DUMP ) /* internal 128x14 control ROM */
1506ROM_END
1507
1508/*-------------------------------------------------
1509    ADDRESS_MAP( upd7220 )
1510-------------------------------------------------*/
1511
1512READ8_DEVICE_HANDLER( upd7220_vram_r )
1676WRITE8_MEMBER( upd7220_device::bank_w )
15131677{
1514   upd7220_t *upd7220 = get_safe_token(device);
1515
1516   return upd7220->vram[offset];
1678   m_vram_bank = 0x8000 * (data & 7);
15171679}
15181680
1519WRITE8_DEVICE_HANDLER( upd7220_vram_w )
1681READ8_MEMBER( upd7220_device::vram_r )
15201682{
1521   upd7220_t *upd7220 = get_safe_token(device);
1522
1523   upd7220->vram[offset] = data;
1683   return m_vram[offset];
15241684}
15251685
1526/*-------------------------------------------------
1527    DEVICE_START( upd7220 )
1528-------------------------------------------------*/
1529
1530static DEVICE_START( upd7220 )
1686WRITE8_MEMBER( upd7220_device::vram_w )
15311687{
1532   upd7220_t *upd7220 = get_safe_token(device);
1533   const upd7220_interface *intf = get_interface(device);
1534   int i;
1535
1536   /* resolve callbacks */
1537   devcb_resolve_write_line(&upd7220->out_drq_func, &intf->out_drq_func, device);
1538   devcb_resolve_write_line(&upd7220->out_hsync_func, &intf->out_hsync_func, device);
1539   devcb_resolve_write_line(&upd7220->out_vsync_func, &intf->out_vsync_func, device);
1540   upd7220->display_func = intf->display_func;
1541   upd7220->draw_text_func = intf->draw_text_func;
1542
1543   /* get the screen device */
1544   upd7220->screen = device->machine().device<screen_device>(intf->screen_tag);
1545   assert(upd7220->screen != NULL);
1546
1547   /* create the timers */
1548   upd7220->vsync_timer = device->machine().scheduler().timer_alloc(FUNC(vsync_tick), (void *)device);
1549   upd7220->hsync_timer = device->machine().scheduler().timer_alloc(FUNC(hsync_tick), (void *)device);
1550   upd7220->blank_timer = device->machine().scheduler().timer_alloc(FUNC(blank_tick), (void *)device);
1551
1552   /* set initial values */
1553   upd7220->fifo_ptr = -1;
1554   upd7220->sr = UPD7220_SR_FIFO_EMPTY;
1555
1556   for (i = 0; i < 16; i++)
1557   {
1558      upd7220->fifo[i] = 0;
1559      upd7220->fifo_flag[i] = FIFO_EMPTY;
1560   }
1561
1562   /* register for state saving */
1563   device->save_item(NAME(upd7220->ra));
1564   device->save_item(NAME(upd7220->sr));
1565   device->save_item(NAME(upd7220->mode));
1566   device->save_item(NAME(upd7220->de));
1567   device->save_item(NAME(upd7220->aw));
1568   device->save_item(NAME(upd7220->al));
1569   device->save_item(NAME(upd7220->vs));
1570   device->save_item(NAME(upd7220->vfp));
1571   device->save_item(NAME(upd7220->vbp));
1572   device->save_item(NAME(upd7220->hs));
1573   device->save_item(NAME(upd7220->hfp));
1574   device->save_item(NAME(upd7220->hbp));
1575   device->save_item(NAME(upd7220->m));
1576   device->save_item(NAME(upd7220->dc));
1577   device->save_item(NAME(upd7220->sc));
1578   device->save_item(NAME(upd7220->br));
1579   device->save_item(NAME(upd7220->lr));
1580   device->save_item(NAME(upd7220->ctop));
1581   device->save_item(NAME(upd7220->cbot));
1582   device->save_item(NAME(upd7220->ead));
1583   device->save_item(NAME(upd7220->dad));
1584   device->save_item(NAME(upd7220->lad));
1585   device->save_item(NAME(upd7220->disp));
1586   device->save_item(NAME(upd7220->gchr));
1587   device->save_item(NAME(upd7220->mask));
1588   device->save_item(NAME(upd7220->pitch));
1688   m_vram[offset] = data;
15891689}
1590
1591/*-------------------------------------------------
1592    DEVICE_RESET( upd7220 )
1593-------------------------------------------------*/
1594
1595static DEVICE_RESET( upd7220 )
1596{
1597   upd7220_t *upd7220 = get_safe_token(device);
1598
1599   devcb_call_write_line(&upd7220->out_drq_func, CLEAR_LINE);
1600}
1601
1602/*-------------------------------------------------
1603    DEVICE_GET_INFO( upd7220 )
1604-------------------------------------------------*/
1605
1606DEVICE_GET_INFO( upd7220 )
1607{
1608   switch (state)
1609   {
1610      /* --- the following bits of info are returned as 64-bit signed integers --- */
1611      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(upd7220_t);                  break;
1612      case DEVINFO_INT_DATABUS_WIDTH_0:            info->i = 8;                              break;
1613      case DEVINFO_INT_ADDRBUS_WIDTH_0:            info->i = 18;                              break;
1614      case DEVINFO_INT_ADDRBUS_SHIFT_0:            info->i = -1;                              break;
1615
1616      /* --- the following bits of info are returned as pointers --- */
1617      case DEVINFO_PTR_ROM_REGION:               info->romregion = ROM_NAME(upd7220);            break;
1618
1619      /* --- the following bits of info are returned as pointers to data --- */
1620      case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0:         info->default_map8 = NULL;                      break;
1621
1622      /* --- the following bits of info are returned as pointers to functions --- */
1623      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(upd7220);         break;
1624      case DEVINFO_FCT_STOP:                     /* Nothing */                              break;
1625      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(upd7220);         break;
1626
1627      /* --- the following bits of info are returned as NULL-terminated strings --- */
1628      case DEVINFO_STR_NAME:                     strcpy(info->s, "NEC uPD7220");                  break;
1629      case DEVINFO_STR_SHORTNAME:                  strcpy(info->s, "upd7220");                     break;
1630      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "NEC uPD7220");                  break;
1631      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                        break;
1632      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                     break;
1633      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright MESS Team");            break;
1634   }
1635}
1636
1637DEFINE_LEGACY_MEMORY_DEVICE(UPD7220, upd7220);
src/mess/video/upd7220.h
r11221r11222
3030
3131**********************************************************************/
3232
33#pragma once
34
3335#ifndef __UPD7220__
3436#define __UPD7220__
3537
36#include "devcb.h"
38#include "emu.h"
3739
38/***************************************************************************
39    MACROS / CONSTANTS
40***************************************************************************/
4140
42DECLARE_LEGACY_MEMORY_DEVICE(UPD7220, upd7220);
43//ADDRESS_MAP_EXTERN( upd7220_map,16 );
4441
42//**************************************************************************
43//  MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
4553#define MCFG_UPD7220_ADD(_tag, _clock, _config, _map) \
4654   MCFG_DEVICE_ADD(_tag, UPD7220, _clock) \
4755   MCFG_DEVICE_CONFIG(_config) \
r11221r11222
5058#define UPD7220_INTERFACE(name) \
5159   const upd7220_interface (name) =
5260
53/***************************************************************************
54    TYPE DEFINITIONS
55***************************************************************************/
5661
62
63//**************************************************************************
64//  TYPE DEFINITIONS
65//**************************************************************************
66
5767typedef void (*upd7220_display_pixels_func)(device_t *device, bitmap_t *bitmap, int y, int x, UINT32 address, UINT16 data, UINT8 *vram);
5868#define UPD7220_DISPLAY_PIXELS(name) void name(device_t *device, bitmap_t *bitmap, int y, int x, UINT32 address, UINT16 data, UINT8 *vram)
5969
6070typedef void (*upd7220_draw_text_line)(device_t *device, bitmap_t *bitmap, UINT8 *vram, UINT32 addr, int y, int wd, int pitch,int screen_min_x,int screen_min_y,int screen_max_x, int screen_max_y,int lr, int cursor_on, int cursor_addr);
6171#define UPD7220_DRAW_TEXT_LINE(name) void name(device_t *device, bitmap_t *bitmap, UINT8 *vram, UINT32 addr, int y, int wd, int pitch,int screen_min_x,int screen_min_y,int screen_max_x, int screen_max_y,int lr, int cursor_on, int cursor_addr)
6272
63typedef struct _upd7220_interface upd7220_interface;
64struct _upd7220_interface
73
74// ======================> upd7220_interface
75
76struct upd7220_interface
6577{
66   const char *screen_tag;      /* screen we are acting on */
78   const char *m_screen_tag;
6779
68   upd7220_display_pixels_func   display_func;
69   upd7220_draw_text_line draw_text_func;
80   upd7220_display_pixels_func   m_display_func;
81   upd7220_draw_text_line m_draw_text_func;
7082
71   /* this gets called for every change of the DRQ pin (pin 7) */
72   devcb_write_line      out_drq_func;
83   devcb_write_line      m_out_drq_func;
84   devcb_write_line      m_out_hsync_func;
85   devcb_write_line      m_out_vsync_func;
86   devcb_write_line      m_out_blank_func;
87};
7388
74   /* this gets called for every change of the HSYNC pin (pin 3) */
75   devcb_write_line      out_hsync_func;
7689
77   /* this gets called for every change of the VSYNC pin (pin 4) */
78   devcb_write_line      out_vsync_func;
90// ======================> upd7220_device_config
7991
80   /* this gets called for every change of the BLANK pin (pin 5) */
81   devcb_write_line      out_blank_func;
92class upd7220_device_config :   public device_config,
93                        public device_config_memory_interface,
94                                public upd7220_interface
95{
96    friend class upd7220_device;
97
98    // construction/destruction
99    upd7220_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
100
101public:
102    // allocators
103    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
104    virtual device_t *alloc_device(running_machine &machine) const;
105
106protected:
107   // device_config overrides
108   virtual void device_config_complete();
109
110   // optional information overrides
111   virtual const rom_entry *device_rom_region() const;
112
113   // device_config_memory_interface overrides
114   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
115
116    // address space configurations
117   const address_space_config      m_space_config;
82118};
83119
84/***************************************************************************
85    PROTOTYPES
86***************************************************************************/
87120
88/* register read */
89READ8_DEVICE_HANDLER( upd7220_r );
121// ======================> upd7220_device
90122
91/* register write */
92WRITE8_DEVICE_HANDLER( upd7220_w );
93WRITE8_DEVICE_HANDLER( upd7220_bank_w );
94READ8_DEVICE_HANDLER( upd7220_vram_r );
95WRITE8_DEVICE_HANDLER( upd7220_vram_w );
123class upd7220_device :   public device_t,
124                  public device_memory_interface
125{
126    friend class upd7220_device_config;
96127
97/* dma acknowledge */
98READ8_DEVICE_HANDLER( upd7220_dack_r );
99WRITE8_DEVICE_HANDLER( upd7220_dack_w );
128    // construction/destruction
129    upd7220_device(running_machine &_machine, const upd7220_device_config &_config);
100130
101/* external synchronization */
102WRITE_LINE_DEVICE_HANDLER( upd7220_ext_sync_w );
131public:
132    DECLARE_READ8_MEMBER( read );
133    DECLARE_WRITE8_MEMBER( write );
103134
104/* light pen strobe */
105WRITE_LINE_DEVICE_HANDLER( upd7220_lpen_w );
135    DECLARE_READ8_MEMBER( dack_r );
136    DECLARE_WRITE8_MEMBER( dack_w );
106137
107/* screen update */
108void upd7220_update(device_t *device, bitmap_t *bitmap, const rectangle *cliprect);
138   DECLARE_WRITE_LINE_MEMBER( ext_sync_w );
139   DECLARE_WRITE_LINE_MEMBER( lpen_w );
109140
141    DECLARE_WRITE8_MEMBER( bank_w );
142    DECLARE_READ8_MEMBER( vram_r );
143    DECLARE_WRITE8_MEMBER( vram_w );
144
145   void update_screen(bitmap_t *bitmap, const rectangle *cliprect);
146
147protected:
148    // device-level overrides
149    virtual void device_start();
150    virtual void device_reset();
151   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
152
153   inline UINT8 readbyte(offs_t address);
154   inline void writebyte(offs_t address, UINT8 data);
155
156private:
157   static const device_timer_id TIMER_VSYNC = 0;
158   static const device_timer_id TIMER_HSYNC = 1;
159   static const device_timer_id TIMER_BLANK = 2;
160
161   inline void fifo_clear();
162   inline int fifo_param_count();
163   inline void fifo_set_direction(int dir);
164   inline void queue(UINT8 data, int flag);
165   inline void dequeue(UINT8 *data, int *flag);
166   inline void update_vsync_timer(int state);
167   inline void update_hsync_timer(int state);
168   inline void update_blank_timer(int state);
169   inline void recompute_parameters();
170   inline void reset_figs_param();
171   inline void advance_ead();
172   inline void read_vram(UINT8 type, UINT8 mod);
173   inline void write_vram(UINT8 type, UINT8 mod);
174   inline UINT16 check_pattern(UINT16 pattern);
175   inline void get_text_partition(int index, UINT32 *sad, UINT16 *len, int *im, int *wd);
176   inline void get_graphics_partition(int index, UINT32 *sad, UINT16 *len, int *im, int *wd);
177
178   void draw_pixel(int x, int y, UINT16 tile_data);
179   void draw_line(int x, int y);
180   void draw_rectangle(int x, int y);
181   void draw_char(int x, int y);
182   int translate_command(UINT8 data);
183   void process_fifo();
184   void update_text(bitmap_t *bitmap, const rectangle *cliprect);
185   void draw_graphics_line(bitmap_t *bitmap, UINT32 addr, int y, int wd);
186   void update_graphics(bitmap_t *bitmap, const rectangle *cliprect, int force_bitmap);
187
188   devcb_resolved_write_line   m_out_drq_func;
189   devcb_resolved_write_line   m_out_hsync_func;
190   devcb_resolved_write_line   m_out_vsync_func;
191   devcb_resolved_write_line   m_out_blank_func;
192
193   screen_device *m_screen;
194
195   UINT16 m_mask;               // mask register
196   UINT8 m_pitch;               // number of word addresses in display memory in the horizontal direction
197   UINT32 m_ead;               // execute word address
198   UINT16 m_dad;               // dot address within the word
199   UINT32 m_lad;               // light pen address
200
201   UINT8 m_ra[16];               // parameter RAM
202   int m_ra_addr;               // parameter RAM address
203
204   UINT8 m_sr;                  // status register
205   UINT8 m_cr;                  // command register
206   UINT8 m_pr[17];               // parameter byte register
207   int m_param_ptr;            // parameter pointer
208
209   UINT8 m_fifo[16];            // FIFO data queue
210   int m_fifo_flag[16];         // FIFO flag queue
211   int m_fifo_ptr;               // FIFO pointer
212   int m_fifo_dir;               // FIFO direction
213
214   UINT8 m_mode;               // mode of operation
215   UINT8 m_draw_mode;            // mode of drawing
216
217   int m_de;                  // display enabled
218   int m_m;                  // 0 = accept external vertical sync (slave mode) / 1 = generate & output vertical sync (master mode)
219   int m_aw;                  // active display words per line - 2 (must be even number with bit 0 = 0)
220   int m_al;                  // active display lines per video field
221   int m_vs;                  // vertical sync width - 1
222   int m_vfp;                  // vertical front porch width - 1
223   int m_vbp;                  // vertical back porch width - 1
224   int m_hs;                  // horizontal sync width - 1
225   int m_hfp;                  // horizontal front porch width - 1
226   int m_hbp;                  // horizontal back porch width - 1
227
228   int m_dc;                  // display cursor
229   int m_sc;                  // 0 = blinking cursor / 1 = steady cursor
230   int m_br;                  // blink rate
231   int m_ctop;                  // cursor top line number in the row
232   int m_cbot;                  // cursor bottom line number in the row (CBOT < LR)
233   int m_lr;                  // lines per character row - 1
234
235   int m_disp;                  // display zoom factor
236   int m_gchr;                  // zoom factor for graphics character writing and area filling
237
238   struct {
239      UINT8 m_dir;            // figs param 0: drawing direction
240      UINT8 m_figure_type;      // figs param 1: figure type
241      UINT16 m_dc;            // figs param 2:
242      UINT16 m_d;               // figs param 3:
243      UINT16 m_d1;            // figs param 4:
244      UINT16 m_d2;            // figs param 5:
245      UINT16 m_dm;            // figs param 6:
246   } m_figs;
247
248   // timers
249   emu_timer *m_vsync_timer;      // vertical sync timer
250   emu_timer *m_hsync_timer;      // horizontal sync timer
251   emu_timer *m_blank_timer;      // CRT blanking timer
252
253   UINT8 m_vram[0x40000];
254   UINT32 m_vram_bank;
255
256   UINT8 m_bitmap_mod;
257
258   const upd7220_device_config &m_config;
259};
260
261
262// device type definition
263extern const device_type UPD7220;
264
265
266
110267#endif
src/mess/includes/compis.h
r11221r11222
1515#include "emu.h"
1616#include "machine/msm8251.h"
1717#include "machine/upd765.h"
18#include "video/upd7220.h"
1819
1920
2021struct mem_state
r11221r11222
127128        m_hgdc(*this, "upd7220")
128129         { }
129130
130   required_device<device_t> m_hgdc;
131   required_device<upd7220_device> m_hgdc;
131132
132133   virtual void video_start();
133134   virtual bool screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect);
src/mess/includes/mikromik.h
r11221r11222
5353   required_device<device_t> m_crtc;
5454   required_device<device_t> m_fdc;
5555   required_device<upd7201_device> m_mpsc;
56   required_device<device_t> m_hgdc;
56   required_device<upd7220_device> m_hgdc;
5757   required_device<device_t> m_speaker;
5858   required_device<device_t> m_floppy0;
5959   required_device<device_t> m_floppy1;
src/mess/drivers/pc9801.c
r11221r11222
250250   { }
251251
252252   required_device<upd1990a_device> m_rtc;
253   required_device<device_t> m_hgdc1;
254   required_device<device_t> m_hgdc2;
253   required_device<upd7220_device> m_hgdc1;
254   required_device<upd7220_device> m_hgdc2;
255255
256256   virtual void video_start();
257257   virtual bool screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect);
r11221r11222
322322   bitmap_fill(&bitmap, &cliprect, 0);
323323
324324   /* graphics */
325   upd7220_update(m_hgdc2, &bitmap, &cliprect);
326   upd7220_update(m_hgdc1, &bitmap, &cliprect);
325   m_hgdc2->update_screen(&bitmap, &cliprect);
326   m_hgdc1->update_screen(&bitmap, &cliprect);
327327
328328   return 0;
329329}
r11221r11222
442442   NULL,
443443   hgdc_draw_text,
444444   DEVCB_NULL,
445   DEVCB_DEVICE_LINE("upd7220_btm", upd7220_ext_sync_w),
445   DEVCB_DEVICE_LINE_MEMBER("upd7220_btm", upd7220_device, ext_sync_w),
446446   DEVCB_NULL
447447};
448448
r11221r11222
680680
681681static READ8_HANDLER( pc9801_60_r )
682682{
683   pc9801_state *state = space->machine().driver_data<pc9801_state>();
684
683685   if((offset & 1) == 0)
684686   {
685      return upd7220_r(space->machine().device("upd7220_chr"),(offset & 2) >> 1); // upd7220 character port
687      return state->m_hgdc1->read(*space, (offset & 2) >> 1); // upd7220 character port
686688   }
687689   else // odd
688690   {
r11221r11222
693695
694696static WRITE8_HANDLER( pc9801_60_w )
695697{
698   pc9801_state *state = space->machine().driver_data<pc9801_state>();
699
696700   if((offset & 1) == 0)
697701   {
698      upd7220_w(space->machine().device("upd7220_chr"),(offset & 2) >> 1,data); // upd7220 character port
702      state->m_hgdc1->write(*space, (offset & 2) >> 1,data); // upd7220 character port
699703   }
700704   else // odd
701705   {
r11221r11222
821825      {
822826         case 0x00:
823827         case 0x02:
824            return upd7220_r(space->machine().device("upd7220_btm"),(offset & 2) >> 1);
828            return state->m_hgdc2->read(*space, (offset & 2) >> 1);
825829         /* bitmap palette clut read */
826830         case 0x04:
827831            return state->m_vram_disp & 1;
r11221r11222
863867      {
864868         case 0x00:
865869         case 0x02:
866            upd7220_w(space->machine().device("upd7220_btm"),(offset & 2) >> 1,data);
870            state->m_hgdc2->write(*space, (offset & 2) >> 1,data);
867871            return;
868872         case 0x04: state->m_vram_disp = data & 1; return;
869873         case 0x06:
870874            state->m_vram_bank = data & 1;
871            upd7220_bank_w(space->machine().device("upd7220_btm"),0,(data & 1) << 2); //TODO: check me
875            state->m_hgdc2->bank_w(*space, 0,(data & 1) << 2); //TODO: check me
872876            return;
873877         /* bitmap palette clut write */
874878         case 0x08:
r11221r11222
994998   if(offset < (0x3fe2) || state->m_video_ff[MEMSW_REG])
995999      state->m_tvram[offset] = data;
9961000
997   upd7220_vram_w(space->machine().device("upd7220_chr"),offset,data); //TODO: check me
1001   state->m_hgdc1->vram_w(*space, offset,data); //TODO: check me
9981002}
9991003
10001004static READ8_HANDLER( pc9801_gvram_r )
10011005{
10021006   pc9801_state *state = space->machine().driver_data<pc9801_state>();
10031007
1004   return upd7220_vram_r(space->machine().device("upd7220_btm"),offset+0x8000+state->m_vram_bank*0x20000);
1008   return state->m_hgdc2->vram_r(*space, offset+0x8000+state->m_vram_bank*0x20000);
10051009}
10061010
10071011static WRITE8_HANDLER( pc9801_gvram_w )
10081012{
10091013   pc9801_state *state = space->machine().driver_data<pc9801_state>();
10101014
1011   upd7220_vram_w(space->machine().device("upd7220_btm"),offset+0x8000+state->m_vram_bank*0x20000, data);
1015   state->m_hgdc2->vram_w(*space, offset+0x8000+state->m_vram_bank*0x20000, data);
10121016}
10131017
10141018static READ8_HANDLER( pc9801_opn_r )
r11221r11222
15321536ADDRESS_MAP_END
15331537
15341538static ADDRESS_MAP_START( upd7220_1_map, AS_0, 8 )
1535   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE("upd7220_chr",upd7220_vram_r,upd7220_vram_w)
1539   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE_MODERN("upd7220_chr", upd7220_device, vram_r, vram_w)
15361540ADDRESS_MAP_END
15371541
15381542static ADDRESS_MAP_START( upd7220_2_map, AS_0, 8 )
1539   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE("upd7220_btm",upd7220_vram_r,upd7220_vram_w)
1543   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE_MODERN("upd7220_btm", upd7220_device, vram_r, vram_w)
15401544ADDRESS_MAP_END
15411545
15421546/* keyboard code */
src/mess/drivers/mikromik.c
r11221r11222
132132
133133static ADDRESS_MAP_START( mm1m6_map, AS_PROGRAM, 8, mm1_state )
134134   AM_IMPORT_FROM(mm1_map)
135   AM_RANGE(0xff70, 0xff71) AM_MIRROR(0x8e) AM_DEVREADWRITE_LEGACY(UPD7220_TAG, upd7220_r, upd7220_w)
135   AM_RANGE(0xff70, 0xff71) AM_MIRROR(0x8e) AM_DEVREADWRITE(UPD7220_TAG, upd7220_device, read, write)
136136ADDRESS_MAP_END
137137
138138static ADDRESS_MAP_START( mm1_upd7220_map, AS_0, 8, mm1_state )
139   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE_LEGACY(UPD7220_TAG,upd7220_vram_r,upd7220_vram_w)
139   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE(UPD7220_TAG, upd7220_device, vram_r, vram_w)
140140ADDRESS_MAP_END
141141
142142/* Input Ports */
r11221r11222
335335   copybitmap(&bitmap, screen.machine().generic.tmpbitmap, 0, 0, 0, 0, &cliprect);
336336
337337   /* graphics */
338   upd7220_update(m_hgdc, &bitmap, &cliprect);
338   m_hgdc->update_screen(&bitmap, &cliprect);
339339
340340   return 0;
341341}
src/mess/drivers/qx10.c
r11221r11222
5555         m_hgdc(*this, "upd7220")
5656      { }
5757
58   required_device<device_t> m_hgdc;
58   required_device<upd7220_device> m_hgdc;
5959
6060   virtual void video_start();
6161   virtual bool screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect);
r11221r11222
624624      if(data != 1 && data != 2 && data != 4)
625625         printf("%02x\n",data);
626626
627      if(data & 1)      { upd7220_bank_w(space->machine().device("upd7220"),0,0); } // B
628      else if(data & 2) { upd7220_bank_w(space->machine().device("upd7220"),0,2); } // G
629      else if(data & 4) { upd7220_bank_w(space->machine().device("upd7220"),0,4); } // R
627      if(data & 1)      { state->m_hgdc->bank_w(*space, 0, 0); } // B
628      else if(data & 2) { state->m_hgdc->bank_w(*space, 0, 2); } // G
629      else if(data & 4) { state->m_hgdc->bank_w(*space, 0, 4); } // R
630630   }
631631}
632632
r11221r11222
654654   AM_RANGE(0x30, 0x33) AM_READWRITE(qx10_30_r, fdd_motor_w)
655655   AM_RANGE(0x34, 0x34) AM_DEVREAD("upd765", upd765_status_r)
656656   AM_RANGE(0x35, 0x35) AM_DEVREADWRITE("upd765", upd765_data_r, upd765_data_w)
657   AM_RANGE(0x38, 0x39) AM_DEVREADWRITE("upd7220", upd7220_r, upd7220_w)
657   AM_RANGE(0x38, 0x39) AM_DEVREADWRITE_MODERN("upd7220", upd7220_device, read, write)
658658//   AM_RANGE(0x3a, 0x3a) GDC zoom
659659//   AM_RANGE(0x3b, 0x3b) GDC light pen req
660660   AM_RANGE(0x3c, 0x3c) AM_READWRITE(mc146818_data_r, mc146818_data_w)
r11221r11222
957957   bitmap_fill(&bitmap, &cliprect, 0);
958958
959959   /* graphics */
960   upd7220_update(m_hgdc, &bitmap, &cliprect);
960   m_hgdc->update_screen(&bitmap, &cliprect);
961961
962962   return 0;
963963}
r11221r11222
978978}
979979
980980static ADDRESS_MAP_START( upd7220_map, AS_0, 8 )
981   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE("upd7220",upd7220_vram_r,upd7220_vram_w)
981   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE_MODERN("upd7220", upd7220_device, vram_r, vram_w)
982982ADDRESS_MAP_END
983983
984984
src/mess/drivers/compis.c
r11221r11222
8686bool compis_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
8787{
8888   /* graphics */
89   upd7220_update(m_hgdc, &bitmap, &cliprect);
89   m_hgdc->update_screen(&bitmap, &cliprect);
9090
9191   return 0;
9292}
r11221r11222
143143   AM_RANGE( 0x0280, 0x0283) AM_DEVREADWRITE8("pic8259_master", pic8259_r, pic8259_w, 0xffff) /* 80150/80130 */
144144//  AM_RANGE( 0x0288, 0x028e) AM_DEVREADWRITE("pit8254", compis_osp_pit_r, compis_osp_pit_w ) /* PIT 8254 (80150/80130)  */
145145   AM_RANGE( 0x0310, 0x031f) AM_READWRITE( compis_usart_r, compis_usart_w )   /* USART 8251 Keyboard      */
146   AM_RANGE( 0x0330, 0x0333) AM_DEVREADWRITE8("upd7220", upd7220_r, upd7220_w,0x00ff)//AM_READWRITE( compis_gdc_16_r, compis_gdc_16_w )   /* GDC 82720 PCS6:6     */
146   AM_RANGE( 0x0330, 0x0333) AM_DEVREADWRITE8_MODERN("upd7220", upd7220_device, read, write, 0x00ff) /* GDC 82720 PCS6:6     */
147147   AM_RANGE( 0x0340, 0x0343) AM_READWRITE8( compis_fdc_r, compis_fdc_w, 0xffff )   /* iSBX0 (J8) FDC 8272      */
148148   AM_RANGE( 0x0350, 0x0351) AM_READ(compis_fdc_dack_r)   /* iSBX0 (J8) DMA ACK       */
149149   AM_RANGE( 0xff00, 0xffff) AM_READWRITE( compis_i186_internal_port_r, compis_i186_internal_port_w)/* CPU 80186         */
r11221r11222
352352GFXDECODE_END
353353
354354static ADDRESS_MAP_START( upd7220_map, AS_0, 8 )
355   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE("upd7220",upd7220_vram_r,upd7220_vram_w)
355   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE_MODERN("upd7220", upd7220_device, vram_r, vram_w)
356356ADDRESS_MAP_END
357357
358358static MACHINE_CONFIG_START( compis, compis_state )
src/mess/drivers/a5105.c
r11221r11222
2828        m_beep(*this, "beep")
2929      { }
3030
31   required_device<device_t> m_hgdc;
31   required_device<upd7220_device> m_hgdc;
3232   required_device<device_t> m_cass;
3333   required_device<device_t> m_beep;
3434
r11221r11222
7575
7676      for( yi = 0; yi < lr; yi++)
7777      {
78         tile_data = state->m_char_rom[tile*8+yi];
78         tile_data = state->m_char_rom[(tile*8+yi) & 0x7ff];
7979
8080         if(cursor_on && cursor_addr == addr+x) //TODO
8181            tile_data^=0xff;
r11221r11222
220220//   AM_RANGE(0x40, 0x4b) fdc, upd765?
221221//   AM_RANGE(0x80, 0x83) z80ctc
222222//   AM_RANGE(0x90, 0x93) ppi8255?
223   AM_RANGE(0x98, 0x99) AM_DEVREADWRITE("upd7220", upd7220_r, upd7220_w)
223   AM_RANGE(0x98, 0x99) AM_DEVREADWRITE_MODERN("upd7220", upd7220_device, read, write)
224224
225225   AM_RANGE(0x9c, 0x9c) AM_WRITE(pcg_val_w)
226226//   AM_RANGE(0x9d, 0x9d) crtc area (ff-based), palette routes here
r11221r11222
410410bool a5105_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
411411{
412412   /* graphics */
413   upd7220_update(m_hgdc, &bitmap, &cliprect);
413   m_hgdc->update_screen(&bitmap, &cliprect);
414414
415415   return 0;
416416}
r11221r11222
426426};
427427
428428static ADDRESS_MAP_START( upd7220_map, AS_0, 8 )
429   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE("upd7220",upd7220_vram_r,upd7220_vram_w)
429   AM_RANGE(0x00000, 0x3ffff) AM_DEVREADWRITE_MODERN("upd7220", upd7220_device, vram_r, vram_w)
430430ADDRESS_MAP_END
431431
432432static MACHINE_CONFIG_START( a5105, a5105_state )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team