summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/citycon.c
blob: e37b0c8be7e80b91803c8fc073f69d5df55790bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/***************************************************************************

  video.c

  Functions to emulate the video hardware of the machine.

***************************************************************************/

#include "driver.h"



UINT8 *citycon_videoram;
UINT8 *citycon_linecolor;
UINT8 *citycon_scroll;

static int bg_image;
static tilemap *bg_tilemap,*fg_tilemap;


/***************************************************************************

  Callbacks for the TileMap code

***************************************************************************/

static TILEMAP_MAPPER( citycon_scan )
{
	/* logical (col,row) -> memory offset */
	return (col & 0x1f) + ((row & 0x1f) << 5) + ((col & 0x60) << 5);
}

static TILE_GET_INFO( get_fg_tile_info )
{
	SET_TILE_INFO(
			0,
			citycon_videoram[tile_index],
			(tile_index & 0x03e0) >> 5,	/* color depends on scanline only */
			0);
}

static TILE_GET_INFO( get_bg_tile_info )
{
	UINT8 *rom = memory_region(REGION_GFX4);
	int code = rom[0x1000 * bg_image + tile_index];
	SET_TILE_INFO(
			3 + bg_image,
			code,
			rom[0xc000 + 0x100 * bg_image + code],
			0);
}



/***************************************************************************

  Start the video hardware emulation.

***************************************************************************/

VIDEO_START( citycon )
{
	fg_tilemap = tilemap_create(get_fg_tile_info,citycon_scan,TILEMAP_TYPE_PEN,8,8,128,32);
	bg_tilemap = tilemap_create(get_bg_tile_info,citycon_scan,TILEMAP_TYPE_PEN,     8,8,128,32);

	tilemap_set_transparent_pen(fg_tilemap,0);
	tilemap_set_scroll_rows(fg_tilemap,32);
}



/***************************************************************************

  Memory handlers

***************************************************************************/

WRITE8_HANDLER( citycon_videoram_w )
{
	citycon_videoram[offset] = data;
	tilemap_mark_tile_dirty(fg_tilemap,offset);
}


WRITE8_HANDLER( citycon_linecolor_w )
{
	citycon_linecolor[offset] = data;
}


WRITE8_HANDLER( citycon_background_w )
{
	/* bits 4-7 control the background image */
	if (bg_image != (data >> 4))
	{
		bg_image = (data >> 4);
		tilemap_mark_all_tiles_dirty(bg_tilemap);
	}

	/* bit 0 flips screen */
	/* it is also used to multiplex player 1 and player 2 controls */
	flip_screen_set(data & 0x01);

	/* bits 1-3 are unknown */
//  if ((data & 0x0e) != 0) logerror("background register = %02x\n",data);
}



static void draw_sprites(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect)
{
	int offs;

	for (offs = spriteram_size-4;offs >= 0;offs -= 4)
	{
		int sx,sy,flipx;


		sx = spriteram[offs + 3];
		sy = 239 - spriteram[offs];
		flipx = ~spriteram[offs + 2] & 0x10;
		if (flip_screen)
		{
			sx = 240 - sx;
			sy = 238 - sy;
			flipx = !flipx;
		}

		drawgfx(bitmap,machine->gfx[spriteram[offs + 1] & 0x80 ? 2 : 1],
				spriteram[offs + 1] & 0x7f,
				spriteram[offs + 2] & 0x0f,
				flipx,flip_screen,
				sx,sy,
				cliprect,TRANSPARENCY_PEN,0);
	}
}


INLINE void changecolor_RRRRGGGGBBBBxxxx(int color,int indx)
{
	int data = paletteram[2*indx | 1] | (paletteram[2*indx] << 8);
	palette_set_color_rgb(Machine,color,pal4bit(data >> 12),pal4bit(data >> 8),pal4bit(data >> 4));
}

VIDEO_UPDATE( citycon )
{
	int offs,scroll;


	/* Update the virtual palette to support text color code changing on every scanline. */
	for (offs = 0;offs < 256;offs++)
	{
		int indx = citycon_linecolor[offs];
		int i;

		for (i = 0;i < 4;i++)
			changecolor_RRRRGGGGBBBBxxxx(640 + 4*offs + i,512 + 4*indx + i);
	}


	scroll = citycon_scroll[0]*256 + citycon_scroll[1];
	tilemap_set_scrollx(bg_tilemap,0,scroll >> 1);
	for (offs = 6;offs < 32;offs++)
		tilemap_set_scrollx(fg_tilemap,offs,scroll);

	tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
	tilemap_draw(bitmap,cliprect,fg_tilemap,0,0);
	draw_sprites(machine,bitmap,cliprect);
	return 0;
}