Previous 15994 Revisions Next

r5689 Friday 11th September, 2009 at 13:42:52 UTC by Curt Coder
[CDP1862] Cleanup.
[src/mess/drivers]vip.c
[src/mess/includes]vip.h
[src/mess/video]cdp1862.c cdp1862.h

src/mess/video/cdp1862.c
r5688r5689
1/**********************************************************************
2
3    RCA CDP1862 COS/MOS Color Generator Controller emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
110/*
211
312    TODO:
r5688r5689
211
3   - NTSC output, currently using RGB
12   - calculate colors from luminance/chrominance resistors
13   - refactor DMA write to WRITE8_DEVICE_HANDLER and add callbacks for RD/BD/GD
414
r5688r5689
919#include "driver.h"
1020#include "cdp1862.h"
1121
22/***************************************************************************
23    PARAMETERS
24***************************************************************************/
25
26static const int CDP1862_BACKGROUND_COLOR_SEQUENCE[] = { 2, 0, 1, 4 };
27
28/***************************************************************************
29    TYPE DEFINITIONS
30***************************************************************************/
31
1232typedef struct _cdp1862_t cdp1862_t;
1333struct _cdp1862_t
1434{
15   const cdp1862_interface *intf;
16
1735   const device_config *screen;   /* screen */
1836   bitmap_t *bitmap;            /* bitmap */
1937
r5688r5689
2139   int con;                  /* color on */
2240};
2341
24static const int CDP1862_BACKGROUND_COLOR_SEQUENCE[] = { 2, 0, 1, 4 };
42/***************************************************************************
43    INLINE FUNCTIONS
44***************************************************************************/
2545
2646INLINE cdp1862_t *get_safe_token(const device_config *device)
2747{
2848   assert(device != NULL);
2949   assert(device->token != NULL);
30
50   assert(device->type == CDP1862);
3151   return (cdp1862_t *)device->token;
3252}
3353
34/* Palette Initialization */
54/***************************************************************************
55    IMPLEMENTATION
56***************************************************************************/
3557
36static void cdp1862_init_palette(const device_config *device)
58/*-------------------------------------------------
59    initialize_palette - palette initialization
60-------------------------------------------------*/
61
62static void initialize_palette(const device_config *device)
3763{
38   cdp1862_t *cdp1862 = get_safe_token(device);
64   const cdp1862_interface *intf = device->static_config;
3965   int i;
4066
41   double res_total = cdp1862->intf->res_r + cdp1862->intf->res_g + cdp1862->intf->res_b + cdp1862->intf->res_bkg;
67   double res_total = intf->chr_r + intf->chr_g + intf->chr_b + intf->chr_bkg;
4268
43   int weight_r = (cdp1862->intf->res_r / res_total) * 100;
44   int weight_g = (cdp1862->intf->res_g / res_total) * 100;
45   int weight_b = (cdp1862->intf->res_b / res_total) * 100;
46   int weight_bkg = (cdp1862->intf->res_bkg / res_total) * 100;
69   int weight_r = (intf->chr_r / res_total) * 100;
70   int weight_g = (intf->chr_g / res_total) * 100;
71   int weight_b = (intf->chr_b / res_total) * 100;
72   int weight_bkg = (intf->chr_bkg / res_total) * 100;
4773
4874   for (i = 0; i < 16; i++)
4975   {
r5688r5689
6086      g = (i & 1) ? luma : 0;
6187      b = (i & 2) ? luma : 0;
6288
63      palette_set_color_rgb( device->machine, i, r, g, b );
89      palette_set_color_rgb(device->machine, i, r, g, b);
6490   }
6591}
6692
67/* Step Background Color */
93/*-------------------------------------------------
94    cdp1862_bkg_w - background step write
95-------------------------------------------------*/
6896
6997WRITE8_DEVICE_HANDLER( cdp1862_bkg_w )
7098{
r5688r5689
73101   if (++cdp1862->bgcolor > 3) cdp1862->bgcolor = 0;
74102}
75103
76/* DMA write */
104/*-------------------------------------------------
105    cdp1862_dma_w - DMA byte write
106-------------------------------------------------*/
77107
78void cdp1862_dma_w(const device_config *device, UINT8 data, int color_on, int rdata, int gdata, int bdata)
108void cdp1862_dma_w(const device_config *device, UINT8 data, int rd, int bd, int gd)
79109{
80110   cdp1862_t *cdp1862 = get_safe_token(device);
81111
r5688r5689
83113   int y = video_screen_get_vpos(cdp1862->screen);
84114   int x;
85115
86   if (color_on == ASSERT_LINE)
116   if (cdp1862->con)
87117   {
88      /* enable color data input latch */
89      cdp1862->con = ASSERT_LINE;
90   }
91
92   if (cdp1862->con == CLEAR_LINE)
93   {
94118      /* latch white dot color */
95      rdata = 1;
96      gdata = 1;
97      bdata = 1;
119      rd = 1;
120      gd = 1;
121      bd = 1;
98122   }
99123
100124   for (x = 0; x < 8; x++)
r5688r5689
103127
104128      if (BIT(data, 7))
105129      {
106         color = (gdata << 2) | (bdata << 1) | rdata;
130         color = (gd << 2) | (bd << 1) | rd;
107131      }
108132
109133      *BITMAP_ADDR16(cdp1862->bitmap, y, sx + x) = color;
r5688r5689
112136   }
113137}
114138
115/* Screen Update */
139/*-------------------------------------------------
140    cdp1862_con_w - color on write
141-------------------------------------------------*/
116142
143WRITE_LINE_DEVICE_HANDLER( cdp1862_con_w )
144{
145   cdp1862_t *cdp1862 = get_safe_token(device);
146
147   if (!state)
148   {
149      cdp1862->con = 0;
150   }
151}
152
153/*-------------------------------------------------
154    cdp1862_update - screen update
155-------------------------------------------------*/
156
117157void cdp1862_update(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect)
118158{
119159   cdp1862_t *cdp1862 = get_safe_token(device);
r5688r5689
122162   bitmap_fill(cdp1862->bitmap, cliprect, CDP1862_BACKGROUND_COLOR_SEQUENCE[cdp1862->bgcolor] + 8);
123163}
124164
125/* Device Interface */
165/*-------------------------------------------------
166    DEVICE_START( cdp1862 )
167-------------------------------------------------*/
126168
127169static DEVICE_START( cdp1862 )
128170{
129171   cdp1862_t *cdp1862 = get_safe_token(device);
172   const cdp1862_interface *intf = device->static_config;
130173
131   /* validate arguments */
132   assert(device != NULL);
133   assert(device->tag != NULL);
134   assert(device->clock > 0);
135
136   cdp1862->intf = device->static_config;
137
138   assert(cdp1862->intf != NULL);
139
140174   /* get the screen device */
141   cdp1862->screen = devtag_get_device(device->machine, cdp1862->intf->screen_tag);
175   cdp1862->screen = devtag_get_device(device->machine, intf->screen_tag);
142176   assert(cdp1862->screen != NULL);
143177
144178   /* allocate the temporary bitmap */
145179   cdp1862->bitmap = auto_bitmap_alloc(device->machine, video_screen_get_width(cdp1862->screen), video_screen_get_height(cdp1862->screen), video_screen_get_format(cdp1862->screen));
146180
147181   /* initialize the palette */
148   cdp1862_init_palette(device);
182   initialize_palette(device);
149183
150184   /* register for state saving */
151185   state_save_register_device_item(device, 0, cdp1862->bgcolor);
r5688r5689
153187   state_save_register_device_item_bitmap(device, 0, cdp1862->bitmap);
154188}
155189
190/*-------------------------------------------------
191    DEVICE_RESET( cdp1862 )
192-------------------------------------------------*/
193
156194static DEVICE_RESET( cdp1862 )
157195{
158196   cdp1862_t *cdp1862 = get_safe_token(device);
159197
160198   cdp1862->bgcolor = 0;
161   cdp1862->con = CLEAR_LINE;
199   cdp1862->con = 1;
162200}
163201
202/*-------------------------------------------------
203    DEVICE_GET_INFO( cdp1862 )
204-------------------------------------------------*/
205
164206DEVICE_GET_INFO( cdp1862 )
165207{
166208   switch (state)
r5688r5689
176218      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(cdp1862);   break;
177219
178220      /* --- the following bits of info are returned as NULL-terminated strings --- */
179      case DEVINFO_STR_NAME:                     strcpy(info->s, "RCA CDP1862");               break;
180      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "RCA CDP1800");               break;
181      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                     break;
182      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                     break;
183      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright MESS Team");         break;
221      case DEVINFO_STR_NAME:                     strcpy(info->s, "RCA CDP1862");            break;
222      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "RCA CDP1800");            break;
223      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
224      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
225      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright MESS Team");      break;
184226   }
185227}
src/mess/video/cdp1862.h
r5688r5689
1/*
1/**********************************************************************
22
3            RCA CDP1862 COS/MOS Color Generator Controller
3    RCA CDP1862 COS/MOS Color Generator Controller emulation
44
5                        _______  _______
6               RD    1   ---|      \/      |---  24  Vdd
7             _RESET    2   ---|            |---  23  R LUM
8               _CON    3   ---|            |---  22  G LUM
9             B CHR    4   ---|            |---  21  GD
10             B LUM    5   ---|            |---  20  BLG LUM
11               BKG    6   ---|   CDP1862C   |---  19  G CHR
12            _LD CLK    7   ---|   top view   |---  18  R CHR
13               STP    8   ---|            |---  17  BKG CHR
14            CLK OUT    9   ---|            |---  16  BD
15              _SYNC   10   ---|             |---  15  BURST
16             LUM IN   11   ---|            |---  14  _XTAL
17               Vss   12   ---|________________|---  13  XTAL
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
187
8**********************************************************************
9                     _______  _______
10            RD    1   ---|      \/      |---  24  Vdd
11          _RESET    2   ---|            |---  23  R LUM
12            _CON    3   ---|            |---  22  G LUM
13          B CHR    4   ---|            |---  21  GD
14          B LUM    5   ---|            |---  20  BLG LUM
15            BKG    6   ---|   CDP1862C   |---  19  G CHR
16         _LD CLK    7   ---|   top view   |---  18  R CHR
17            STP    8   ---|            |---  17  BKG CHR
18         CLK OUT    9   ---|            |---  16  BD
19           _SYNC   10   ---|             |---  15  BURST
20          LUM IN   11   ---|            |---  14  _XTAL
21            Vss   12   ---|________________|---  13  XTAL
1922
20            http://homepage.mac.com/ruske/cosmacelf/cdp1862.pdf
2123
22*/
24         http://homepage.mac.com/ruske/cosmacelf/cdp1862.pdf
2325
26**********************************************************************/
27
2428#ifndef __CDP1862__
2529#define __CDP1862__
2630
31#include "devcb.h"
32
33/***************************************************************************
34    MACROS / CONSTANTS
35***************************************************************************/
36
2737#define CPD1862_CLOCK   XTAL_7_15909MHz
2838
2939#define CDP1862      DEVICE_GET_INFO_NAME(cdp1862)
r5688r5689
3242   MDRV_DEVICE_ADD(_tag, CDP1862, _clock) \
3343   MDRV_DEVICE_CONFIG(_config)
3444
35/* interface */
45#define CDP1862_INTERFACE(name) \
46   const cdp1862_interface (name)=
47
48/***************************************************************************
49    TYPE DEFINITIONS
50***************************************************************************/
51
3652typedef struct _cdp1862_interface cdp1862_interface;
3753struct _cdp1862_interface
3854{
3955   const char *screen_tag;      /* screen we are acting on */
4056
41   double res_r;            /* red output resistor value */
42   double res_g;            /* green output resistor value */
43   double res_b;            /* blue output resistor value */
44   double res_bkg;            /* background output resistor value */
57   double lum_r;            /* red luminance resistor value */
58   double lum_b;            /* blue luminance resistor value */
59   double lum_g;            /* green luminance resistor value */
60   double lum_bkg;            /* background luminance resistor value */
61   
62   double chr_r;            /* red chrominance resistor value */
63   double chr_b;            /* blue chrominance resistor value */
64   double chr_g;            /* green chrominance resistor value */
65   double chr_bkg;            /* background chrominance resistor value */
4566};
46#define CDP1862_INTERFACE(name) const cdp1862_interface (name)=
4767
68/***************************************************************************
69    PROTOTYPES
70***************************************************************************/
71
4872/* device interface */
4973DEVICE_GET_INFO( cdp1862 );
5074
5175/* step background color */
5276WRITE8_DEVICE_HANDLER( cdp1862_bkg_w );
5377
78/* color on */
79WRITE_LINE_DEVICE_HANDLER( cdp1862_con_w );
80
5481/* DMA write */
55void cdp1862_dma_w(const device_config *device, UINT8 data, int color_on, int rdata, int gdata, int bdata);
82void cdp1862_dma_w(const device_config *device, UINT8 data, int rd, int bd, int gd) ATTR_NONNULL(1);
5683
5784/* screen update */
58void cdp1862_update(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect);
85void cdp1862_update(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect) ATTR_NONNULL(1) ATTR_NONNULL(2) ATTR_NONNULL(3);
5986
6087#endif
src/mess/includes/vip.h
r5688r5689
4040   /* video state */
4141   int cdp1861_efx;            /* EFx */
4242   int a12;                  /* latched address line 12 */
43   int colorram_mwr;            /* color RAM write */
4443   UINT8 *colorram;            /* CDP1862 color RAM */
4544
4645   /* sound state */
src/mess/drivers/vip.c
r5688r5689
400400{
401401   SCREEN_TAG,
402402   510,         /* R3 */
403   360,         /* R4 */
403404   RES_K(1),      /* R5 */
404   360,         /* R4 */
405   RES_K(1.5)      /* R6 */
405   RES_K(1.5),      /* R6 */
406   RES_K(3.9),      /* R7 */
407   RES_K(10),      /* R8 */
408   RES_K(2),      /* R9 */
409   RES_K(3.3)      /* R10 */
406410};
407411
408412static WRITE8_HANDLER( vip_colorram_w )
r5688r5689
418422      mask = 0xe7;
419423   }
420424
421//   logerror("COLOR RAM (%04x) %02x = %02x\n", offset, offset & mask, data);
422
423425   /* write to CDP1822 */
424426   state->colorram[offset & mask] = data << 1;
425   state->colorram_mwr = ASSERT_LINE;
427
428   cdp1862_con_w(state->cdp1862, 0);
426429}
427430
428431static VIDEO_UPDATE( vip )
r5688r5689
569572         bd = BIT(color, 2);
570573         gd = BIT(color, 3);
571574
572         cdp1862_dma_w(state->cdp1862, data, state->colorram_mwr, rd, gd, bd);
575         cdp1862_dma_w(state->cdp1862, data, rd, bd, gd);
573576      }
574577      break;
575578   }
r5688r5689
632635
633636   state_save_register_global(machine, state->reset);
634637   state_save_register_global(machine, state->cdp1861_efx);
635   state_save_register_global(machine, state->colorram_mwr);
636638   state_save_register_global(machine, state->keylatch);
637639}
638640
r5688r5689
651653   device_reset(state->vp550);
652654   device_reset(state->vp595);
653655
654   state->colorram_mwr = CLEAR_LINE;
655
656656   /* configure video */
657657   switch (input_port_read(machine, "VIDEO"))
658658   {
r5688r5689
819819/* System Drivers */
820820
821821/*     YEAR  NAME    PARENT  COMPAT  MACHINE     INPUT   INIT    CONFIG  COMPANY FULLNAME            FLAGS */
822COMP( 1977, vip,   0,      0,      vip,      vip,   0,      vp711,   "RCA",   "Cosmac VIP (VP-711)",   GAME_SUPPORTS_SAVE )
823COMP( 1977, vp111,   vip,   0,      vip,      vip,   0,      vp111,   "RCA",   "Cosmac VIP (VP-111)",   GAME_SUPPORTS_SAVE )
822COMP( 1977, vip,   0,      0,      vip,      vip,   0,      vp711,   "RCA",   "Cosmac VIP (VP-711)",   GAME_SUPPORTS_SAVE | GAME_IMPERFECT_COLORS )
823COMP( 1977, vp111,   vip,   0,      vip,      vip,   0,      vp111,   "RCA",   "Cosmac VIP (VP-111)",   GAME_SUPPORTS_SAVE | GAME_IMPERFECT_COLORS )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team