1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 #include "emu.h"
4 #include "includes/cgc7900.h"
5 #include "screen.h"
6 
7 /***************************************************************************
8     PARAMETERS
9 ***************************************************************************/
10 
11 #define OVERLAY_CUR                 BIT(cell, 31)   /* places a cursor in the cell if SET */
12 #define OVERLAY_BLK                 BIT(cell, 30)   /* blinks the foreground character in the cell if SET */
13 #define OVERLAY_VF                  BIT(cell, 28)   /* makes the foreground visible if SET (else transparent) */
14 #define OVERLAY_VB                  BIT(cell, 27)   /* makes the background visible if SET (else transparent) */
15 #define OVERLAY_PL                  BIT(cell, 24)   /* uses bits 0-7 as PLOT DOT descriptor if SET (else ASCII) */
16 #define OVERLAY_BR                  BIT(cell, 18)   /* turns on Red in background if SET */
17 #define OVERLAY_BG                  BIT(cell, 17)   /* turns on Green in background if SET */
18 #define OVERLAY_BB                  BIT(cell, 16)   /* turns on Blue in background if SET */
19 #define OVERLAY_FR                  BIT(cell, 10)   /* turns on Red in foreground if SET */
20 #define OVERLAY_FG                  BIT(cell, 9)    /* turns on Green in foreground if SET */
21 #define OVERLAY_FB                  BIT(cell, 8)    /* turns on Blue in background if SET */
22 #define OVERLAY_DATA                (cell & 0xff)   /* ASCII or Plot Dot character */
23 
24 #define IMAGE_SELECT                BIT(m_roll_overlay[0], 13)
25 #define OVERLAY_CURSOR_BLINK        BIT(m_roll_overlay[0], 14)
26 #define OVERLAY_CHARACTER_BLINK     BIT(m_roll_overlay[0], 15)
27 
cgc7900_palette(palette_device & palette) const28 void cgc7900_state::cgc7900_palette(palette_device &palette) const
29 {
30 	palette.set_pen_color(0, rgb_t::black());
31 	palette.set_pen_color(1, rgb_t(0x00, 0x00, 0xff));
32 	palette.set_pen_color(2, rgb_t(0x00, 0xff, 0x00));
33 	palette.set_pen_color(3, rgb_t(0x00, 0xff, 0xff));
34 	palette.set_pen_color(4, rgb_t(0xff, 0x00, 0x00));
35 	palette.set_pen_color(5, rgb_t(0xff, 0x00, 0xff));
36 	palette.set_pen_color(6, rgb_t(0xff, 0xff, 0x00));
37 	palette.set_pen_color(7, rgb_t::white());
38 }
39 
40 /***************************************************************************
41     READ/WRITE HANDLERS
42 ***************************************************************************/
43 
44 /*-------------------------------------------------
45     cgc7900_z_mode_r - Z mode read
46 -------------------------------------------------*/
47 
z_mode_r()48 u16 cgc7900_state::z_mode_r()
49 {
50 	return 0;
51 }
52 
53 /*-------------------------------------------------
54     cgc7900_z_mode_w - Z mode write
55 -------------------------------------------------*/
56 
z_mode_w(u16 data)57 void cgc7900_state::z_mode_w(u16 data)
58 {
59 }
60 
61 /*-------------------------------------------------
62     cgc7900_color_status_w - color status write
63 -------------------------------------------------*/
64 
color_status_w(u16 data)65 void cgc7900_state::color_status_w(u16 data)
66 {
67 }
68 
69 /*-------------------------------------------------
70     cgc7900_sync_r - sync information read
71 -------------------------------------------------*/
72 
sync_r()73 u16 cgc7900_state::sync_r()
74 {
75 	u16 data = 0xffff;
76 
77 	/*
78 
79 	    bit     signal      description
80 
81 	     0      _VERT       vertical retrace (0=vblank)
82 	     1                  interlace (1=first field, 0=second field)
83 	     2      _HG         horizontal retrace (0=hblank)
84 	     3      1
85 	     4      1
86 	     5      1
87 	     6      1
88 	     7      1
89 	     8      1
90 	     9      1
91 	    10      1
92 	    11      1
93 	    12      1
94 	    13      1
95 	    14      1
96 	    15      1
97 
98 	*/
99 
100 	if (m_screen->vblank()) data &= 1;
101 	if (m_screen->hblank()) data &= 4;
102 
103 	return data;
104 }
105 
106 /***************************************************************************
107     VIDEO
108 ***************************************************************************/
109 
110 /*-------------------------------------------------
111     update_clut - update color lookup table
112 -------------------------------------------------*/
113 
update_clut()114 void cgc7900_state::update_clut()
115 {
116 	for (int i = 0; i < 256; i++)
117 	{
118 		u16 addr = i * 2;
119 		u32 data = (m_clut_ram[addr + 1] << 16) | m_clut_ram[addr];
120 		u8 b = data & 0xff;
121 		u8 g = (data >> 8) & 0xff;
122 		u8 r = (data >> 16) & 0xff;
123 
124 		m_clut[i] = rgb_t(r, g, b);
125 	}
126 }
127 
128 /*-------------------------------------------------
129     draw_bitmap - draw bitmap image
130 -------------------------------------------------*/
131 
draw_bitmap(screen_device * screen,bitmap_rgb32 & bitmap)132 void cgc7900_state::draw_bitmap(screen_device *screen, bitmap_rgb32 &bitmap)
133 {
134 }
135 
136 /*-------------------------------------------------
137     draw_overlay - draw text overlay
138 -------------------------------------------------*/
139 
draw_overlay(screen_device * screen,bitmap_rgb32 & bitmap)140 void cgc7900_state::draw_overlay(screen_device *screen, bitmap_rgb32 &bitmap)
141 {
142 	const pen_t *pen = m_palette->pens();
143 	for (int y = 0; y < 48 * 8; y++)
144 	{
145 		int sy = y / 8;
146 		int line = y % 8;
147 
148 		for (int sx = 0; sx < 85; sx++)
149 		{
150 			u16 addr = (sy * 170) + (sx * 2);
151 			u32 cell = (m_overlay_ram[addr] << 16) | m_overlay_ram[addr + 1];
152 			u8 data = m_char_rom->base()[(OVERLAY_DATA << 3) | line];
153 			int fg = (cell >> 8) & 0x07;
154 			int bg = (cell >> 16) & 0x07;
155 
156 			for (int x = 0; x < 8; x++)
157 			{
158 				if (OVERLAY_CUR)
159 				{
160 					if (!OVERLAY_CURSOR_BLINK || m_blink)
161 					{
162 						bitmap.pix(y, (sx * 8) + x) = pen[7];
163 					}
164 				}
165 				else
166 				{
167 					if (!BIT(data, x) || (OVERLAY_BLK && OVERLAY_CHARACTER_BLINK && !m_blink))
168 					{
169 						if (OVERLAY_VB) bitmap.pix(y, (sx * 8) + x) = pen[bg];
170 					}
171 					else
172 					{
173 						if (OVERLAY_VF) bitmap.pix(y, (sx * 8) + x) = pen[fg];
174 					}
175 				}
176 			}
177 		}
178 	}
179 }
180 
181 /*-------------------------------------------------
182     TIMER_DEVICE_CALLBACK_MEMBER( blink_tick )
183 -------------------------------------------------*/
184 
TIMER_DEVICE_CALLBACK_MEMBER(cgc7900_state::blink_tick)185 TIMER_DEVICE_CALLBACK_MEMBER(cgc7900_state::blink_tick)
186 {
187 	m_blink = !m_blink;
188 }
189 
screen_update(screen_device & screen,bitmap_rgb32 & bitmap,const rectangle & cliprect)190 u32 cgc7900_state::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
191 {
192 	update_clut();
193 	draw_bitmap(&screen, bitmap);
194 	draw_overlay(&screen, bitmap);
195 
196 	return 0;
197 }
198 
199 /*-------------------------------------------------
200     gfx_layout cgc7900_charlayout
201 -------------------------------------------------*/
202 
203 static const gfx_layout cgc7900_charlayout =
204 {
205 	8,8,
206 	RGN_FRAC(1,1),
207 	1,
208 	{ RGN_FRAC(0,1) },
209 	{ STEP8(7,-1) },
210 	{ STEP8(0,8) },
211 	8*8
212 };
213 
214 /*-------------------------------------------------
215     GFXDECODE( cgc7900 )
216 -------------------------------------------------*/
217 
218 static GFXDECODE_START( gfx_cgc7900 )
219 	GFXDECODE_ENTRY( "gfx1", 0x0000, cgc7900_charlayout, 0, 1 )
220 GFXDECODE_END
221 
222 /***************************************************************************
223     MACHINE DRIVERS
224 ***************************************************************************/
225 
226 /*-------------------------------------------------
227     MACHINE_DRIVER( cgc7900_video )
228 -------------------------------------------------*/
229 
cgc7900_video(machine_config & config)230 void cgc7900_state::cgc7900_video(machine_config &config)
231 {
232 	screen_device &screen(SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER));
233 	screen.set_refresh_hz(60);
234 	screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500)); /* not accurate */
235 	screen.set_screen_update(FUNC(cgc7900_state::screen_update));
236 	screen.set_size(1024, 768);
237 	screen.set_visarea(0, 1024-1, 0, 768-1);
238 	screen.screen_vblank().set(FUNC(cgc7900_state::irq<0xc>));
239 
240 	GFXDECODE(config, "gfxdecode", m_palette, gfx_cgc7900);
241 	PALETTE(config, m_palette, FUNC(cgc7900_state::cgc7900_palette), 8);
242 
243 	TIMER(config, "blink").configure_periodic(FUNC(cgc7900_state::blink_tick), attotime::from_hz(XTAL(28'480'000)/7500000));
244 }
245