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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
// license:BSD-3-Clause
// copyright-holders:Luca Elia
/**************************************************************************
Ginga NinkyouDen
(C) 1987 Jaleco
driver by Luca Elia (l.elia@tin.it)
Note: if MAME_DEBUG is defined, pressing Z with:
Q shows background
W shows foreground
E shows frontmost (text) layer
A shows sprites
Keys can be used togheter!
[Screen]
Visible Size: 256H x 240V
Dynamic Colors: 256 x 4
Color Space: 16R x 16G x 16B
[Scrolling layers]
Format (all layers): Offset: 0x400 0x000
Bit: fedc---- -------- Color
----ba98 76543210 Code
[Background]
Size: 8192 x 512 (static: stored in ROM)
Scrolling: X,Y (registers: $60006.w, $60004.w)
Tiles Size: 16 x 16
Tiles Number: $400
Colors: $300-$3ff
[Foreground]
Size: 4096 x 512
Scrolling: X,Y (registers: $60002.w, $60000.w)
Tiles Size: 16 x 16
Tiles Number: $400
Colors: $200-$2ff
[Frontmost]
Size: 256 x 256
Scrolling: -
Tiles Size: 8 x 8
Tiles Number: $200
Colors: $000-$0ff
[Sprites]
On Screen: 256
In ROM: $a00
Colors: $100-$1ff
Format: See Below
**************************************************************************/
#include "emu.h"
#include "includes/ginganin.h"
/***************************************************************************
Callbacks for the TileMap code
***************************************************************************/
/* Background - Resides in ROM */
#define BG_GFX (0)
#define BG_NX (16*32)
#define BG_NY (16*2)
TILE_GET_INFO_MEMBER(ginganin_state::get_bg_tile_info)
{
const u32 code = m_bgrom[2 * tile_index + 0] * 256 + m_bgrom[2 * tile_index + 1];
SET_TILE_INFO_MEMBER(BG_GFX,
code,
code >> 12,
0);
}
/* Foreground - Resides in RAM */
#define FG_GFX (1)
#define FG_NX (16*16)
#define FG_NY (16*2)
TILE_GET_INFO_MEMBER(ginganin_state::get_fg_tile_info)
{
const u16 code = m_fgram[tile_index];
SET_TILE_INFO_MEMBER(FG_GFX,
code,
code >> 12,
0);
}
void ginganin_state::fgram_w(offs_t offset, u16 data, u16 mem_mask)
{
COMBINE_DATA(&m_fgram[offset]);
m_fg_tilemap->mark_tile_dirty(offset);
}
/* Frontmost (text) Layer - Resides in RAM */
#define TXT_GFX (2)
#define TXT_NX (32)
#define TXT_NY (32)
TILE_GET_INFO_MEMBER(ginganin_state::get_txt_tile_info)
{
const u16 code = m_txtram[tile_index];
SET_TILE_INFO_MEMBER(TXT_GFX,
code,
code >> 12,
0);
}
void ginganin_state::txtram_w(offs_t offset, u16 data, u16 mem_mask)
{
COMBINE_DATA(&m_txtram[offset]);
m_tx_tilemap->mark_tile_dirty(offset);
}
void ginganin_state::video_start()
{
m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(ginganin_state::get_bg_tile_info),this), TILEMAP_SCAN_COLS, 16, 16, BG_NX, BG_NY);
m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(ginganin_state::get_fg_tile_info),this), TILEMAP_SCAN_COLS, 16, 16, FG_NX, FG_NY);
m_tx_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(ginganin_state::get_txt_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, TXT_NX, TXT_NY);
m_fg_tilemap->set_transparent_pen(15);
m_tx_tilemap->set_transparent_pen(15);
}
void ginganin_state::vregs_w(offs_t offset, u16 data, u16 mem_mask)
{
COMBINE_DATA(&m_vregs[offset]);
data = m_vregs[offset];
switch (offset)
{
case 0:
m_fg_tilemap->set_scrolly(0, data);
break;
case 1:
m_fg_tilemap->set_scrollx(0, data);
break;
case 2:
m_bg_tilemap->set_scrolly(0, data);
break;
case 3:
m_bg_tilemap->set_scrollx(0, data);
break;
case 4:
m_layers_ctrl = data;
break;
/* case 5:
* break;
*/
case 6:
m_flipscreen = !(data & 1);
machine().tilemap().set_flip_all(m_flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
break;
case 7:
m_soundlatch->write(data);
m_audiocpu->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
break;
default:
logerror("CPU #0 PC %06X : Warning, videoreg %04X <- %04X\n", m_maincpu->pc(), offset, data);
}
}
/* --------------------------[ Sprites Format ]----------------------------
Offset: Values: Format:
0000.w y position fedc ba9- ---- ---- unused
---- ---8 ---- ---- subtract 256
---- ---- 7654 3210 position
0002.w x position See above
0004.w code f--- ---- ---- ---- y flip
-e-- ---- ---- ---- x flip
--dc ---- ---- ---- unused?
---- ba98 7654 3210 code
0006.w colour fedc ---- ---- ---- colour code
---- ba98 7654 3210 unused?
------------------------------------------------------------------------ */
void ginganin_state::draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect)
{
for (int offs = 0; offs < (m_spriteram.bytes() >> 1); offs += 4)
{
int y = m_spriteram[offs + 0];
int x = m_spriteram[offs + 1];
const u32 code = m_spriteram[offs + 2];
const u16 attr = m_spriteram[offs + 3];
int flipx = code & 0x4000;
int flipy = code & 0x8000;
x = (x & 0xff) - (x & 0x100);
y = (y & 0xff) - (y & 0x100);
if (m_flipscreen)
{
x = 240 - x;
y = 240 - y;
flipx = !flipx;
flipy = !flipy;
}
m_gfxdecode->gfx(3)->transpen(bitmap,cliprect,
code & 0x3fff,
attr >> 12,
flipx, flipy,
x,y,15);
}
}
u32 ginganin_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
int layers_ctrl1 = m_layers_ctrl;
#ifdef MAME_DEBUG
if (machine().input().code_pressed(KEYCODE_Z))
{
int msk = 0;
if (machine().input().code_pressed(KEYCODE_Q)) { msk |= 0xfff1;}
if (machine().input().code_pressed(KEYCODE_W)) { msk |= 0xfff2;}
if (machine().input().code_pressed(KEYCODE_E)) { msk |= 0xfff4;}
if (machine().input().code_pressed(KEYCODE_A)) { msk |= 0xfff8;}
if (msk != 0) layers_ctrl1 &= msk;
#define SETSCROLL \
m_bg_tilemap->set_scrollx(0, m_posx); \
m_bg_tilemap->set_scrolly(0, m_posy); \
m_fg_tilemap->set_scrollx(0, m_posx); \
m_fg_tilemap->set_scrolly(0, m_posy); \
popmessage("B>%04X:%04X F>%04X:%04X",m_posx%(BG_NX*16),m_posy%(BG_NY*16),m_posx%(FG_NX*16),m_posy%(FG_NY*16));
if (machine().input().code_pressed(KEYCODE_L)) { m_posx +=8; SETSCROLL }
if (machine().input().code_pressed(KEYCODE_J)) { m_posx -=8; SETSCROLL }
if (machine().input().code_pressed(KEYCODE_K)) { m_posy +=8; SETSCROLL }
if (machine().input().code_pressed(KEYCODE_I)) { m_posy -=8; SETSCROLL }
if (machine().input().code_pressed(KEYCODE_H)) { m_posx = m_posy = 0; SETSCROLL }
}
#endif
if (layers_ctrl1 & 1)
m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
else
bitmap.fill(0, cliprect);
if (layers_ctrl1 & 2)
m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
if (layers_ctrl1 & 8)
draw_sprites(bitmap, cliprect);
if (layers_ctrl1 & 4)
m_tx_tilemap->draw(screen, bitmap, cliprect, 0, 0);
return 0;
}
|