summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/yunsun16.c
blob: b4052554b008d443214ff767b6a585ea89bb74bc (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/***************************************************************************

                          -= Yun Sung 16 Bit Games =-

                    driver by   Luca Elia (l.elia@tin.it)


    [ 2 Scrolling Layers ]

    Tiles are 16 x 16 x 8. The layout of the tilemap is a bit weird:
    16 consecutive tile codes define a vertical column.
    16 columns form a page (256 x 256).
    The tilemap is made of 4 x 4 pages (1024 x 1024)

    [ 512? Sprites ]

    Sprites are 16 x 16 x 4 in size. There's RAM for 512, but
    the game just copies 384 entries.


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

#include "driver.h"
#include "yunsun16.h"


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


                                    Tilemaps


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

#define TMAP_GFX			(0)
#define TILES_PER_PAGE_X	(0x10)
#define TILES_PER_PAGE_Y	(0x10)
#define PAGES_PER_TMAP_X	(0x4)
#define PAGES_PER_TMAP_Y	(0x4)

static TILEMAP_MAPPER( yunsun16_tilemap_scan_pages )
{
	return	(row / TILES_PER_PAGE_Y) * TILES_PER_PAGE_X * TILES_PER_PAGE_Y * PAGES_PER_TMAP_X +
			(row % TILES_PER_PAGE_Y) +

			(col / TILES_PER_PAGE_X) * TILES_PER_PAGE_X * TILES_PER_PAGE_Y +
			(col % TILES_PER_PAGE_X) * TILES_PER_PAGE_Y;
}

static TILE_GET_INFO( get_tile_info_0 )
{
	yunsun16_state *state = (yunsun16_state *)machine->driver_data;
	UINT16 code = state->vram_0[2 * tile_index + 0];
	UINT16 attr = state->vram_0[2 * tile_index + 1];
	SET_TILE_INFO(
			TMAP_GFX,
			code,
			attr & 0xf,
			(attr & 0x20) ? TILE_FLIPX : 0);
}

static TILE_GET_INFO( get_tile_info_1 )
{
	yunsun16_state *state = (yunsun16_state *)machine->driver_data;
	UINT16 code = state->vram_1[2 * tile_index + 0];
	UINT16 attr = state->vram_1[2 * tile_index + 1];
	SET_TILE_INFO(
			TMAP_GFX,
			code,
			attr & 0xf,
			(attr & 0x20) ? TILE_FLIPX : 0);
}

WRITE16_HANDLER( yunsun16_vram_0_w )
{
	yunsun16_state *state = (yunsun16_state *)space->machine->driver_data;

	COMBINE_DATA(&state->vram_0[offset]);
	tilemap_mark_tile_dirty(state->tilemap_0, offset / 2);
}

WRITE16_HANDLER( yunsun16_vram_1_w )
{
	yunsun16_state *state = (yunsun16_state *)space->machine->driver_data;

	COMBINE_DATA(&state->vram_1[offset]);
	tilemap_mark_tile_dirty(state->tilemap_1, offset / 2);
}


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


                            Video Hardware Init


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

VIDEO_START( yunsun16 )
{
	yunsun16_state *state = (yunsun16_state *)machine->driver_data;

	state->tilemap_0 = tilemap_create(machine, get_tile_info_0,yunsun16_tilemap_scan_pages,
								16,16, TILES_PER_PAGE_X*PAGES_PER_TMAP_X,TILES_PER_PAGE_Y*PAGES_PER_TMAP_Y);
	state->tilemap_1 = tilemap_create(machine, get_tile_info_1,yunsun16_tilemap_scan_pages,
								16,16, TILES_PER_PAGE_X*PAGES_PER_TMAP_X,TILES_PER_PAGE_Y*PAGES_PER_TMAP_Y);

	tilemap_set_scrolldx(state->tilemap_0, -0x34, 0);
	tilemap_set_scrolldx(state->tilemap_1, -0x38, 0);

	tilemap_set_scrolldy(state->tilemap_0, -0x10, 0);
	tilemap_set_scrolldy(state->tilemap_1, -0x10, 0);

	tilemap_set_transparent_pen(state->tilemap_0, 0xff);
	tilemap_set_transparent_pen(state->tilemap_1, 0xff);
}


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


                                Sprites Drawing


        0.w                             X

        2.w                             Y

        4.w                             Code

        6.w     fedc ba98 7--- ----
                ---- ---- -6-- ----     Flip Y
                ---- ---- --5- ----     Flip X
                ---- ---- ---4 3210     Color


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

static void draw_sprites( running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect )
{
	yunsun16_state *state = (yunsun16_state *)machine->driver_data;
	int offs;
	const rectangle *visarea = video_screen_get_visible_area(machine->primary_screen);

	int max_x = visarea->max_x + 1;
	int max_y = visarea->max_y + 1;

	int pri = *state->priorityram & 3;
	int pri_mask;

	switch (pri)
	{
		case 1:
			pri_mask = (1 << 1) | (1 << 2) | (1 << 3);
			break;
		case 2:
			pri_mask = (1 << 2) | (1 << 3);
			break;
		case 3:
		default:
			pri_mask = 0;
			break;
	}

	for (offs = (state->spriteram_size - 8) / 2 ; offs >= 0; offs -= 8 / 2)
	{
		int x = state->spriteram[offs + 0];
		int y = state->spriteram[offs + 1];
		int code = state->spriteram[offs + 2];
		int attr = state->spriteram[offs + 3];
		int flipx = attr & 0x20;
		int flipy = attr & 0x40;

		x += state->sprites_scrolldx;
		y += state->sprites_scrolldy;

		if (flip_screen_get(machine))	// not used?
		{
			flipx = !flipx;		x = max_x - x - 16;
			flipy = !flipy;		y = max_y - y - 16;
		}

		pdrawgfx_transpen(bitmap,cliprect,machine->gfx[1],
					code,
					attr & 0x1f,
					flipx, flipy,
					x,y,
					machine->priority_bitmap,
					pri_mask,15);
	}
}


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


                                Screen Drawing


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


VIDEO_UPDATE( yunsun16 )
{
	yunsun16_state *state = (yunsun16_state *)screen->machine->driver_data;

	tilemap_set_scrollx(state->tilemap_0, 0, state->scrollram_0[0]);
	tilemap_set_scrolly(state->tilemap_0, 0, state->scrollram_0[1]);

	tilemap_set_scrollx(state->tilemap_1, 0, state->scrollram_1[0]);
	tilemap_set_scrolly(state->tilemap_1, 0, state->scrollram_1[1]);

	//popmessage("%04X", *state->priorityram);

	bitmap_fill(screen->machine->priority_bitmap, cliprect, 0);

	if ((*state->priorityram & 0x0c) == 4)
	{
		/* The color of the this layer's transparent pen goes below everything */
		tilemap_draw(bitmap, cliprect, state->tilemap_0, TILEMAP_DRAW_OPAQUE, 0);
		tilemap_draw(bitmap, cliprect, state->tilemap_0, 0, 1);
		tilemap_draw(bitmap, cliprect, state->tilemap_1, 0, 2);
	}
	else if ((*state->priorityram & 0x0c) == 8)
	{
		/* The color of the this layer's transparent pen goes below everything */
		tilemap_draw(bitmap, cliprect, state->tilemap_1, TILEMAP_DRAW_OPAQUE, 0);
		tilemap_draw(bitmap, cliprect, state->tilemap_1, 0, 1);
		tilemap_draw(bitmap, cliprect, state->tilemap_0, 0, 2);
	}

	draw_sprites(screen->machine, bitmap, cliprect);
	return 0;
}