1 // license:BSD-3-Clause
2 // copyright-holders:smf
3 /*
4 * Beatmania DJ Main Board (GX753)
5 * emulate video hardware
6 */
7
8 #include "emu.h"
9 #include "includes/djmain.h"
10
11 #define NUM_SPRITES (0x800 / 16)
12 #define NUM_LAYERS 2
13
14
15
draw_sprites(bitmap_rgb32 & bitmap,const rectangle & cliprect)16 void djmain_state::draw_sprites( bitmap_rgb32 &bitmap, const rectangle &cliprect)
17 {
18 int offs, pri_code;
19 int sortedlist[NUM_SPRITES];
20
21 m_gfxdecode->gfx(0)->set_colorbase(m_k055555->K055555_read_register(K55_PALBASE_SUB2) * 0x400);
22
23 for (offs = 0; offs < NUM_SPRITES; offs++)
24 sortedlist[offs] = -1;
25
26 /* prebuild a sorted table */
27 for (offs = 0; offs < NUM_SPRITES * 4; offs += 4)
28 {
29 if (m_obj_ram[offs] & 0x00008000)
30 {
31 if (m_obj_ram[offs] & 0x80000000)
32 continue;
33
34 pri_code = m_obj_ram[offs] & (NUM_SPRITES - 1);
35 sortedlist[pri_code] = offs;
36 }
37 }
38
39 for (pri_code = NUM_SPRITES - 1; pri_code >= 0; pri_code--)
40 {
41 static const int xoffset[8] = { 0, 1, 4, 5, 16, 17, 20, 21 };
42 static const int yoffset[8] = { 0, 2, 8, 10, 32, 34, 40, 42 };
43 static const int sizetab[4] = { 1, 2, 4, 8 };
44 int x, y;
45 int ox, oy;
46 int flipx, flipy;
47 int xscale, yscale;
48 int code;
49 int color;
50 int size;
51
52 offs = sortedlist[pri_code];
53 if (offs == -1) continue;
54
55 code = m_obj_ram[offs] >> 16;
56 flipx = (m_obj_ram[offs] >> 10) & 1;
57 flipy = (m_obj_ram[offs] >> 11) & 1;
58 size = sizetab[(m_obj_ram[offs] >> 8) & 3];
59
60 ox = (int16_t)(m_obj_ram[offs + 1] & 0xffff);
61 oy = (int16_t)(m_obj_ram[offs + 1] >> 16);
62
63 xscale = m_obj_ram[offs + 2] >> 16;
64 yscale = m_obj_ram[offs + 2] & 0xffff;
65
66 if (!xscale || !yscale)
67 continue;
68
69 xscale = (0x40 << 16) / xscale;
70 yscale = (0x40 << 16) / yscale;
71 ox -= (size * xscale) >> 13;
72 oy -= (size * yscale) >> 13;
73
74 color = (m_obj_ram[offs + 3] >> 16) & 15;
75
76 for (x = 0; x < size; x++)
77 for (y = 0; y < size; y++)
78 {
79 int c = code;
80
81 if (flipx)
82 c += xoffset[size - x - 1];
83 else
84 c += xoffset[x];
85
86 if (flipy)
87 c += yoffset[size - y - 1];
88 else
89 c += yoffset[y];
90
91 if (xscale != 0x10000 || yscale != 0x10000)
92 {
93 int sx = ox + ((x * xscale + (1 << 11)) >> 12);
94 int sy = oy + ((y * yscale + (1 << 11)) >> 12);
95 int zw = ox + (((x + 1) * xscale + (1 << 11)) >> 12) - sx;
96 int zh = oy + (((y + 1) * yscale + (1 << 11)) >> 12) - sy;
97
98
99 m_gfxdecode->gfx(0)->zoom_transpen(bitmap,
100 cliprect,
101 c,
102 color,
103 flipx,
104 flipy,
105 sx,
106 sy,
107 (zw << 16) / 16,
108 (zh << 16) / 16,
109 0);
110 }
111 else
112 {
113 int sx = ox + (x << 4);
114 int sy = oy + (y << 4);
115
116
117 m_gfxdecode->gfx(0)->transpen(bitmap,
118 cliprect,
119 c,
120 color,
121 flipx,
122 flipy,
123 sx,
124 sy,
125 0);
126 }
127 }
128 }
129 }
130
131
K056832_CB_MEMBER(djmain_state::tile_callback)132 K056832_CB_MEMBER(djmain_state::tile_callback)
133 {
134 }
135
video_start()136 void djmain_state::video_start()
137 {
138 m_k056832->set_layer_offs(0, -92, -27);
139 // m_k056832->set_layer_offs(1, -87, -27);
140 m_k056832->set_layer_offs(1, -88, -27);
141 }
142
screen_update_djmain(screen_device & screen,bitmap_rgb32 & bitmap,const rectangle & cliprect)143 uint32_t djmain_state::screen_update_djmain(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
144 {
145 int enables = m_k055555->K055555_read_register(K55_INPUT_ENABLES);
146 int pri[NUM_LAYERS + 1];
147 int order[NUM_LAYERS + 1];
148 int i, j;
149
150 for (i = 0; i < NUM_LAYERS; i++)
151 pri[i] = m_k055555->K055555_read_register(K55_PRIINP_0 + i * 3);
152 pri[i] = m_k055555->K055555_read_register(K55_PRIINP_10);
153
154 for (i = 0; i < NUM_LAYERS + 1; i++)
155 order[i] = i;
156
157 for (i = 0; i < NUM_LAYERS; i++)
158 for (j = i + 1; j < NUM_LAYERS + 1; j++)
159 if (pri[order[i]] > pri[order[j]])
160 {
161 int temp = order[i];
162
163 order[i] = order[j];
164 order[j] = temp;
165 }
166
167 bitmap.fill(m_palette->pen(0), cliprect);
168
169 for (i = 0; i < NUM_LAYERS + 1; i++)
170 {
171 int layer = order[i];
172
173 if (layer == NUM_LAYERS)
174 {
175 if (enables & K55_INP_SUB2)
176 draw_sprites(bitmap, cliprect);
177 }
178 else
179 {
180 if (enables & (K55_INP_VRAM_A << layer))
181 m_k056832->tilemap_draw_dj(screen, bitmap, cliprect, layer, 0, 1 << i);
182 }
183 }
184 return 0;
185 }
186