summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/galpani2.c
blob: 4cac46443dc5e195dd7915b649847d69fb5bf34b (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
/***************************************************************************

                            -= Gal's Panic II =-

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


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

#include "emu.h"
#include "includes/kaneko16.h"
#include "includes/galpani2.h"

/*
304000:0040 0000 0100 0000-0000 0000 0000 0000      (Sprites regs)
304010:16C0 0200 16C0 0200-16C0 0200 16C0 0200
*/

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


                        Palettized Background Layers


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


#ifdef UNUSED_DEFINITION
INLINE UINT16 galpani2_bg8_regs_r(address_space *space, offs_t offset, int n)
{
	galpani2_state *state = space->machine().driver_data<galpani2_state>();
	switch (offset * 2)
	{
		case 0x16:	return space->machine().rand() & 1;
		default:
			logerror("CPU #0 PC %06X : Warning, bg8 #%d screen reg %04X read\n",cpu_get_pc(space->cpu),_n_,offset*2);
	}
	return state->m_bg8_regs[_n_][offset];
}

/*
    000-3ff     row? scroll
    400         ?
    800-bff     col? scroll
    c04         0003 flip, 0300 flip?
    c1c/e       01ff scroll, 3000 ?
*/
INLINE void galpani2_bg8_regs_w(address_space *space, offs_t offset, UINT16 data, UINT16 mem_mask, int _n_)
{
	galpani2_state *state = space->machine().driver_data<galpani2_state>();
	COMBINE_DATA(&state->m_bg8_regs[_n_][offset]);
}

READ16_HANDLER( galpani2_bg8_regs_0_r ) { return galpani2_bg8_regs_r(space, offset, 0); }
READ16_HANDLER( galpani2_bg8_regs_1_r ) { return galpani2_bg8_regs_r(space, offset, 1); }

WRITE16_HANDLER( galpani2_bg8_regs_0_w ) { galpani2_bg8_regs_w(space, offset, data, mem_mask, 0); }
WRITE16_HANDLER( galpani2_bg8_regs_1_w ) { galpani2_bg8_regs_w(space, offset, data, mem_mask, 1); }
#endif

INLINE void galpani2_bg8_w(address_space *space, offs_t offset, UINT16 data, UINT16 mem_mask, int _n_)
{
	galpani2_state *state = space->machine().driver_data<galpani2_state>();
	int x,y,pen;
	UINT16 newword = COMBINE_DATA(&state->m_bg8[_n_][offset]);
	pen	=	newword & 0xff;
	x	=	(offset % 512);	/* 512 x 256 */
	y	=	(offset / 512);
	*BITMAP_ADDR16(state->m_bg8_bitmap[_n_], y, x) = 0x4000 + pen;
}

WRITE16_HANDLER( galpani2_bg8_0_w ) { galpani2_bg8_w(space, offset, data, mem_mask, 0); }
WRITE16_HANDLER( galpani2_bg8_1_w ) { galpani2_bg8_w(space, offset, data, mem_mask, 1); }

INLINE void galpani2_palette_w(address_space *space, offs_t offset, UINT16 data, UINT16 mem_mask, int _n_)
{
	galpani2_state *state = space->machine().driver_data<galpani2_state>();
	UINT16 newword = COMBINE_DATA(&state->m_palette[_n_][offset]);
	palette_set_color_rgb( space->machine(), offset + 0x4000 + _n_ * 0x100, pal5bit(newword >> 5), pal5bit(newword >> 10), pal5bit(newword >> 0) );
}

WRITE16_HANDLER( galpani2_palette_0_w ) { galpani2_palette_w(space, offset, data, mem_mask, 0); }
WRITE16_HANDLER( galpani2_palette_1_w ) { galpani2_palette_w(space, offset, data, mem_mask, 1); }


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


                            xRGB  Background Layer


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

/* 8 horizontal pages of 256x256 pixels? */
WRITE16_HANDLER( galpani2_bg15_w )
{
	galpani2_state *state = space->machine().driver_data<galpani2_state>();
	UINT16 newword = COMBINE_DATA(&state->m_bg15[offset]);

	int x = (offset % 256) + (offset / (256*256)) * 256 ;
	int y = (offset / 256) % 256;

	*BITMAP_ADDR16(state->m_bg15_bitmap, y, x) = 0x4200 + (newword & 0x7fff);
}


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


                            Video Init Functions


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

PALETTE_INIT( galpani2 )
{
	int i;
	/* first $4200 colors are dynamic */

	/* initialize 555 RGB lookup */
	for (i = 0; i < 0x8000; i++)
		palette_set_color_rgb(machine,0x4200+i,pal5bit(i >> 5),pal5bit(i >> 10),pal5bit(i >> 0));
}

VIDEO_START( galpani2 )
{
	galpani2_state *state = machine.driver_data<galpani2_state>();
	state->m_bg15_bitmap  = auto_bitmap_alloc(machine, 256*8, 256, BITMAP_FORMAT_INDEXED16);
	state->m_bg8_bitmap[0] = auto_bitmap_alloc(machine, 512, 256, BITMAP_FORMAT_INDEXED16);
	state->m_bg8_bitmap[1] = auto_bitmap_alloc(machine, 512, 256, BITMAP_FORMAT_INDEXED16);

	VIDEO_START_CALL(kaneko16_sprites);
}


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


                                Screen Drawing


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

SCREEN_UPDATE( galpani2 )
{
	galpani2_state *state = screen->machine().driver_data<galpani2_state>();
	int layers_ctrl = -1;

#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 (screen->machine().input().code_pressed(KEYCODE_E))	msk |= 4;
	if (screen->machine().input().code_pressed(KEYCODE_A))	msk |= 8;
	if (msk != 0) layers_ctrl &= msk;
}
#endif

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

	if (layers_ctrl & 0x1)
	{
		int x = 0;
		int y = 0;
		copyscrollbitmap_trans(bitmap, state->m_bg15_bitmap,
							   1, &x, 1, &y,
							   cliprect,0x4200 + 0);
	}

/*  test mode:
    304000:0040 0000 0100 0000-0000 0000 0000 0000      (Sprite regs)
    304010:16C0 0200 16C0 0200-16C0 0200 16C0 0200
    16c0/40 = 5b        200/40 = 8
    scrollx = f5, on screen x should be 0 (f5+5b = 150) */

	if (layers_ctrl & 0x2)
	{
		int x = - ( *state->m_bg8_scrollx[0] + 0x200 - 0x0f5 );
		int y = - ( *state->m_bg8_scrolly[0] + 0x200 - 0x1be );
		copyscrollbitmap_trans(bitmap, state->m_bg8_bitmap[0],
							   1, &x, 1, &y,
							   cliprect,0x4000 + 0);
	}

	if (layers_ctrl & 0x4)
	{
		int x = - ( *state->m_bg8_scrollx[1] + 0x200 - 0x0f5 );
		int y = - ( *state->m_bg8_scrolly[1] + 0x200 - 0x1be );
		copyscrollbitmap_trans(bitmap, state->m_bg8_bitmap[1],
							   1, &x, 1, &y,
							   cliprect,0x4000 + 0);
	}

	if (layers_ctrl & 0x8)	kaneko16_draw_sprites(screen->machine(), bitmap, cliprect);
	return 0;
}