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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
|
// license:BSD-3-Clause
// copyright-holders:Acho A. Tang, Nicola Salmoria
/*************************************************************************
Equites, Splendor Blast driver
functions to emulate the video hardware
*************************************************************************/
#include "emu.h"
#include "includes/equites.h"
/*************************************
*
* Palette handling
*
*************************************/
void equites_state::equites_palette(palette_device &palette) const
{
const uint8_t *color_prom = memregion("proms")->base();
for (int i = 0; i < 256; i++)
palette.set_indirect_color(i, rgb_t(pal4bit(color_prom[i]), pal4bit(color_prom[i + 0x100]), pal4bit(color_prom[i + 0x200])));
// point to the CLUT
color_prom += 0x380;
for (int i = 0; i < 256; i++)
palette.set_pen_indirect(i, i);
for (int i = 0; i < 0x80; i++)
palette.set_pen_indirect(i + 0x100, color_prom[i]);
}
void splndrbt_state::splndrbt_palette(palette_device &palette) const
{
const uint8_t *color_prom = memregion("proms")->base();
for (int i = 0; i < 0x100; i++)
palette.set_indirect_color(i, rgb_t(pal4bit(color_prom[i]), pal4bit(color_prom[i + 0x100]), pal4bit(color_prom[i + 0x200])));
for (int i = 0; i < 0x100; i++)
palette.set_pen_indirect(i, i);
// point to the bg CLUT
color_prom += 0x300;
for (int i = 0; i < 0x80; i++)
palette.set_pen_indirect(i + 0x100, color_prom[i] + 0x10);
// point to the sprite CLUT
color_prom += 0x100;
for (int i = 0; i < 0x100; i++)
palette.set_pen_indirect(i + 0x180, color_prom[i]);
}
/*************************************
*
* Callbacks for the TileMap code
*
*************************************/
TILE_GET_INFO_MEMBER(equites_state::equites_fg_info)
{
int tile = m_fg_videoram[2 * tile_index];
int color = m_fg_videoram[2 * tile_index + 1] & 0x1f;
SET_TILE_INFO_MEMBER(0, tile, color, 0);
if (color & 0x10)
tileinfo.flags |= TILE_FORCE_LAYER0;
}
TILE_GET_INFO_MEMBER(splndrbt_state::splndrbt_fg_info)
{
int tile = m_fg_videoram[2 * tile_index] + (m_fg_char_bank << 8);
int color = m_fg_videoram[2 * tile_index + 1] & 0x3f;
SET_TILE_INFO_MEMBER(0, tile, color, 0);
if (color & 0x10)
tileinfo.flags |= TILE_FORCE_LAYER0;
}
TILE_GET_INFO_MEMBER(equites_state::equites_bg_info)
{
int data = m_bg_videoram[tile_index];
int tile = data & 0x1ff;
int color = (data & 0xf000) >> 12;
int fxy = (data & 0x0600) >> 9;
SET_TILE_INFO_MEMBER(1, tile, color, TILE_FLIPXY(fxy));
}
TILE_GET_INFO_MEMBER(splndrbt_state::splndrbt_bg_info)
{
int data = m_bg_videoram[tile_index];
int tile = data & 0x1ff;
int color = (data & 0xf800) >> 11;
int fxy = (data & 0x0600) >> 9;
SET_TILE_INFO_MEMBER(1, tile, color, TILE_FLIPXY(fxy));
tileinfo.group = color;
}
/*************************************
*
* Video system start
*
*************************************/
VIDEO_START_MEMBER(equites_state,equites)
{
m_fg_videoram = std::make_unique<uint8_t[]>(0x800);
save_pointer(NAME(m_fg_videoram), 0x800);
m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(equites_state::equites_fg_info),this), TILEMAP_SCAN_COLS, 8, 8, 32, 32);
m_fg_tilemap->set_transparent_pen(0);
m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(equites_state::equites_bg_info),this), TILEMAP_SCAN_ROWS, 16, 16, 16, 16);
m_bg_tilemap->set_transparent_pen(0);
m_bg_tilemap->set_scrolldx(0, -10);
}
VIDEO_START_MEMBER(splndrbt_state,splndrbt)
{
assert(m_screen->format() == BITMAP_FORMAT_IND16);
m_fg_videoram = std::make_unique<uint8_t[]>(0x800);
save_pointer(NAME(m_fg_videoram), 0x800);
m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(splndrbt_state::splndrbt_fg_info),this), TILEMAP_SCAN_COLS, 8, 8, 32, 32);
m_fg_tilemap->set_transparent_pen(0);
m_fg_tilemap->set_scrolldx(8, -8);
m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(splndrbt_state::splndrbt_bg_info),this), TILEMAP_SCAN_ROWS, 16, 16, 32, 32);
m_bg_tilemap->configure_groups(*m_gfxdecode->gfx(1), 0x10);
}
/*************************************
*
* Memory handlers
*
*************************************/
READ8_MEMBER(equites_state::equites_fg_videoram_r)
{
// 8-bit
return m_fg_videoram[offset];
}
WRITE8_MEMBER(equites_state::equites_fg_videoram_w)
{
m_fg_videoram[offset] = data;
m_fg_tilemap->mark_tile_dirty(offset >> 1);
}
WRITE16_MEMBER(equites_state::equites_bg_videoram_w)
{
COMBINE_DATA(m_bg_videoram + offset);
m_bg_tilemap->mark_tile_dirty(offset);
}
WRITE8_MEMBER(equites_state::equites_bgcolor_w)
{
// bg color register
if (offset == 0)
m_bgcolor = data;
}
WRITE16_MEMBER(equites_state::equites_scrollreg_w)
{
if (ACCESSING_BITS_0_7)
m_bg_tilemap->set_scrolly(0, data & 0xff);
if (ACCESSING_BITS_8_15)
m_bg_tilemap->set_scrollx(0, data >> 8);
}
WRITE_LINE_MEMBER(splndrbt_state::splndrbt_selchar_w)
{
// select active char map
m_fg_char_bank = (state == 0) ? 0 : 1;
m_fg_tilemap->mark_all_dirty();
}
WRITE_LINE_MEMBER(equites_state::flip_screen_w)
{
flip_screen_set(state);
}
WRITE16_MEMBER(splndrbt_state::splndrbt_bg_scrollx_w)
{
COMBINE_DATA(&m_splndrbt_bg_scrollx);
}
WRITE16_MEMBER(splndrbt_state::splndrbt_bg_scrolly_w)
{
COMBINE_DATA(&m_splndrbt_bg_scrolly);
}
/*************************************
*
* Video update
*
*************************************/
void equites_state::equites_draw_sprites_block(bitmap_ind16 &bitmap, const rectangle &cliprect, int start, int end)
{
for (int offs = end - 2; offs >= start; offs -= 2)
{
int attr = m_spriteram[offs + 1];
if (!(attr & 0x800)) // disable or x MSB?
{
int tile = attr & 0x1ff;
int fx = ~attr & 0x400;
int fy = ~attr & 0x200;
int color = (~attr & 0xf000) >> 12;
int sx = (m_spriteram[offs] & 0xff00) >> 8;
int sy = (m_spriteram[offs] & 0x00ff);
int transmask = m_palette->transpen_mask(*m_gfxdecode->gfx(2), color, 0);
if (flip_screen())
{
sx = 240 - sx;
sy = 240 - sy;
fx = !fx;
fy = !fy;
}
// align
sx -= 4;
// sprites are 16x14 centered in a 16x16 square, so skip the first line
sy += 1;
m_gfxdecode->gfx(2)->transmask(bitmap,cliprect,
tile,
color,
fx, fy,
sx, sy, transmask);
}
}
}
void equites_state::equites_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
// note that we draw the sprites in three blocks; in each blocks, sprites at
// a lower address have priority. This gives good priorities in gekisou.
equites_draw_sprites_block(bitmap, cliprect, 0x000/2, 0x060/2);
equites_draw_sprites_block(bitmap, cliprect, 0x0e0/2, 0x100/2);
equites_draw_sprites_block(bitmap, cliprect, 0x1a4/2, 0x200/2);
}
/*
This is (probabbly) the sprite x scaling PROM.
The layout is strange. Clearly every line os for one xscale setting. However,
it seems that bytes 0-3 are handled separately from bytes 4-F.
Also, note that sprites are 30x30, not 32x32.
00020200 00000000 00000000 00000000
00020200 01000000 00000000 00000002
00020200 01000000 01000002 00000002
00020200 01000100 01000002 00020002
00020200 01000100 01010202 00020002
02020201 01000100 01010202 00020002
02020201 01010100 01010202 00020202
02020201 01010101 01010202 02020202
02020201 03010101 01010202 02020203
02020201 03010103 01010202 03020203
02020201 03010103 01030302 03020203
02020201 03010303 01030302 03030203
03020203 03010303 01030302 03030203
03020203 03030303 01030302 03030303
03020203 03030303 03030303 03030303
03020303 03030303 03030303 03030303
*/
void splndrbt_state::splndrbt_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
const uint8_t * const xrom = memregion("user2")->base();
const uint8_t * const yrom = xrom + 0x100;
gfx_element* gfx = m_gfxdecode->gfx(2);
// note that sprites are actually 30x30, contained in 32x32 squares. The outer edge is not used.
for (int offs = 0x3f; offs < 0x6f; offs += 2) // 24 sprites
{
int data = m_spriteram[offs];
int fx = (data & 0x2000) >> 13;
int fy = (data & 0x1000) >> 12;
int tile = data & 0x007f;
int scaley = (data & 0x0f00) >> 8;
int data2 = m_spriteram[offs + 1];
int color = (data2 & 0x1f00) >> 8;
int sx = data2 & 0x00ff;
int sy = m_spriteram_2[offs + 0] & 0x00ff;
int scalex = m_spriteram_2[offs + 1] & 0x000f;
int transmask = m_palette->transpen_mask(*gfx, color, 0);
// const uint8_t * const xromline = xrom + (scalex << 4);
const uint8_t * const yromline = yrom + (scaley << 4) + (15 - scaley);
const uint8_t* const srcgfx = gfx->get_data(tile);
const pen_t *paldata = &m_palette->pen(gfx->colorbase() + gfx->granularity() * color);
int x,yy;
sy += 16;
if (flip_screen())
{
// sx NOT inverted
fx = fx ^ 1;
fy = fy ^ 1;
}
else
{
sy = 256 - sy;
}
for (yy = 0; yy <= scaley; ++yy)
{
int const line = yromline[yy];
int yhalf;
for (yhalf = 0; yhalf < 2; ++yhalf) // top or bottom half
{
int const y = yhalf ? sy + 1 + yy : sy - yy;
if (y >= cliprect.top() && y <= cliprect.bottom())
{
for (x = 0; x <= (scalex << 1); ++x)
{
int bx = (sx + x) & 0xff;
if (bx >= cliprect.left() && bx <= cliprect.right())
{
int xx = scalex ? (x * 29 + scalex) / (scalex << 1) + 1 : 16; // FIXME This is wrong. Should use the PROM.
int const offset = (fx ? (31 - xx) : xx) + ((fy ^ yhalf) ? (16 + line) : (15 - line)) * gfx->rowbytes();
int pen = srcgfx[offset];
if ((transmask & (1 << pen)) == 0)
bitmap.pix16(y, bx) = paldata[pen];
}
}
}
}
}
}
}
void splndrbt_state::splndrbt_copy_bg(bitmap_ind16 &dst_bitmap, const rectangle &cliprect)
{
bitmap_ind16 &src_bitmap = m_bg_tilemap->pixmap();
bitmap_ind8 &flags_bitmap = m_bg_tilemap->flagsmap();
const uint8_t * const xrom = memregion("user1")->base();
const uint8_t * const yrom = xrom + 0x2000;
int scroll_x = m_splndrbt_bg_scrollx;
int scroll_y = m_splndrbt_bg_scrolly;
int const dinvert = flip_screen() ? 0xff : 0x00;
int src_y = 0;
int dst_y;
if (flip_screen())
{
scroll_x = -scroll_x - 8;
scroll_y = -scroll_y;
}
for (dst_y = 32; dst_y < 256-32; ++dst_y)
{
if (dst_y >= cliprect.top() && dst_y <= cliprect.bottom())
{
const uint8_t * const romline = &xrom[(dst_y ^ dinvert) << 5];
const uint16_t * const src_line = &src_bitmap.pix16((src_y + scroll_y) & 0x1ff);
const uint8_t * const flags_line = &flags_bitmap.pix8((src_y + scroll_y) & 0x1ff);
uint16_t * const dst_line = &dst_bitmap.pix16(dst_y);
int dst_x = 0;
int src_x;
for (src_x = 0; src_x < 256 && dst_x < 128; ++src_x)
{
if ((romline[31 - (src_x >> 3)] >> (src_x & 7)) & 1)
{
int sx;
sx = (256+128 + scroll_x + src_x) & 0x1ff;
if (flags_line[sx] & TILEMAP_PIXEL_LAYER0)
dst_line[128 + dst_x] = src_line[sx];
sx = (255+128 + scroll_x - src_x) & 0x1ff;
if (flags_line[sx] & TILEMAP_PIXEL_LAYER0)
dst_line[127 - dst_x] = src_line[sx];
++dst_x;
}
}
}
src_y += 1 + yrom[dst_y ^ dinvert];
}
}
uint32_t equites_state::screen_update_equites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
bitmap.fill(m_bgcolor, cliprect);
m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
equites_draw_sprites(bitmap, cliprect);
m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
return 0;
}
uint32_t splndrbt_state::screen_update_splndrbt(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
bitmap.fill(m_bgcolor, cliprect);
splndrbt_copy_bg(bitmap, cliprect);
if (m_fg_char_bank)
m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
splndrbt_draw_sprites(bitmap, cliprect);
if (!m_fg_char_bank)
m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
return 0;
}
|