summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/yunsung8.c
blob: 375697100beb7d60f17862142a756ead74828631 (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
/***************************************************************************

                          -= Yun Sung 8 Bit Games =-

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


Note:   if MAME_DEBUG is defined, pressing Z with:

        Q       shows the background layer
        W       shows the foreground layer

        [ 2 Fixed Layers ]

            [ Background ]

            Layer Size:             512 x 256
            Tiles:                  8 x 8 x 8

            [ Foreground ]

            Layer Size:             512 x 256
            Tiles:                  8 x 8 x 4


        There are no sprites.

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

#include "emu.h"
#include "includes/yunsung8.h"


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

                                Memory Handlers

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

WRITE8_HANDLER( yunsung8_videobank_w )
{
	yunsung8_state *state = space->machine().driver_data<yunsung8_state>();
	state->m_videobank = data;
}


READ8_HANDLER( yunsung8_videoram_r )
{
	yunsung8_state *state = space->machine().driver_data<yunsung8_state>();
	int bank;

	/*  Bit 1 of the bankswitching register contols the c000-c7ff
        area (Palette). Bit 0 controls the c800-dfff area (Tiles) */

	if (offset < 0x0800)
		bank = state->m_videobank & 2;
	else
		bank = state->m_videobank & 1;

	if (bank)
		return state->m_videoram_0[offset];
	else
		return state->m_videoram_1[offset];
}


WRITE8_HANDLER( yunsung8_videoram_w )
{
	yunsung8_state *state = space->machine().driver_data<yunsung8_state>();

	if (offset < 0x0800)		// c000-c7ff    Banked Palette RAM
	{
		int bank = state->m_videobank & 2;
		UINT8 *RAM;
		int color;

		if (bank)
			RAM = state->m_videoram_0;
		else
			RAM = state->m_videoram_1;

		RAM[offset] = data;
		color = RAM[offset & ~1] | (RAM[offset | 1] << 8);

		/* BBBBBGGGGGRRRRRx */
		palette_set_color_rgb(space->machine(), offset / 2 + (bank ? 0x400 : 0), pal5bit(color >> 0), pal5bit(color >> 5), pal5bit(color >> 10));
	}
	else
	{
		int tile;
		int bank = state->m_videobank & 1;

		if (offset < 0x1000)
			tile = (offset - 0x0800);		// c800-cfff: Banked Color RAM
		else
			tile = (offset - 0x1000) / 2;	// d000-dfff: Banked Tiles RAM

		if (bank)
		{
			state->m_videoram_0[offset] = data;
			tilemap_mark_tile_dirty(state->m_tilemap_0, tile);
		}
		else
		{
			state->m_videoram_1[offset] = data;
			tilemap_mark_tile_dirty(state->m_tilemap_1, tile);
		}
	}
}


WRITE8_HANDLER( yunsung8_flipscreen_w )
{
	tilemap_set_flip_all(space->machine(), (data & 1) ? (TILEMAP_FLIPX | TILEMAP_FLIPY) : 0);
}


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

                              [ Tiles Format ]

    Offset:

    Video RAM + 0000.b      Code (Low  Bits)
    Video RAM + 0001.b      Code (High Bits)

    Color RAM + 0000.b      Color


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

/* Background */

#define DIM_NX_0			(0x40)
#define DIM_NY_0			(0x20)

static TILE_GET_INFO( get_tile_info_0 )
{
	yunsung8_state *state = machine.driver_data<yunsung8_state>();
	int code  =  state->m_videoram_0[0x1000 + tile_index * 2 + 0] + state->m_videoram_0[0x1000 + tile_index * 2 + 1] * 256;
	int color =  state->m_videoram_0[0x0800 + tile_index] & 0x07;
	SET_TILE_INFO(
			0,
			code,
			color,
			0);
}

/* Text Plane */

#define DIM_NX_1			(0x40)
#define DIM_NY_1			(0x20)

static TILE_GET_INFO( get_tile_info_1 )
{
	yunsung8_state *state = machine.driver_data<yunsung8_state>();
	int code  =  state->m_videoram_1[0x1000 + tile_index * 2 + 0] + state->m_videoram_1[0x1000 + tile_index * 2 + 1] * 256;
	int color =  state->m_videoram_1[0x0800 + tile_index] & 0x3f;
	SET_TILE_INFO(
			1,
			code,
			color,
			0);
}




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


                            Vide Hardware Init


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

VIDEO_START( yunsung8 )
{
	yunsung8_state *state = machine.driver_data<yunsung8_state>();

	state->m_tilemap_0 = tilemap_create(machine, get_tile_info_0, tilemap_scan_rows, 8, 8, DIM_NX_0, DIM_NY_0 );
	state->m_tilemap_1 = tilemap_create(machine, get_tile_info_1, tilemap_scan_rows, 8, 8, DIM_NX_1, DIM_NY_1 );

	tilemap_set_transparent_pen(state->m_tilemap_1, 0);
}



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


                                Screen Drawing


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

SCREEN_UPDATE( yunsung8 )
{
	yunsung8_state *state = screen->machine().driver_data<yunsung8_state>();
	int layers_ctrl = (~state->m_layers_ctrl) >> 4;

#ifdef MAME_DEBUG
if (screen->machine().input().code_pressed(KEYCODE_Z))
{
	int msk = 0;
	if (screen->machine().input().code_pressed(KEYCODE_Q))	msk |= 1;
	if (screen->machine().input().code_pressed(KEYCODE_W))	msk |= 2;
	if (msk != 0) layers_ctrl &= msk;
}
#endif

	if (layers_ctrl & 1)
		tilemap_draw(bitmap, cliprect, state->m_tilemap_0, 0, 0);
	else
		bitmap_fill(bitmap, cliprect, 0);

	if (layers_ctrl & 2)
		tilemap_draw(bitmap, cliprect, state->m_tilemap_1, 0, 0);

	return 0;
}