1 // license:LGPL-2.1+
2 // copyright-holders:David Haywood, Angelo Salese, Olivier Galibert, Mariusz Wojcieszek, R. Belmont
3 /* Sega Saturn VDP2 */
4
5 /*
6
7 -------------------------- WARNING WARNING WARNING --------------------------
8 This is a legacy core, all game based notes are for a future device rewrite.
9 Please don't remove them if for no reason you truly want to mess with this.
10 -------------------------- WARNING WARNING WARNING --------------------------
11
12 the dirty marking stuff and tile decoding will probably be removed in the end anyway as we'll need custom
13 rendering code since mame's drawgfx / tilesytem don't offer everything st-v needs
14
15 this system seems far too complex to use Mame's tilemap system
16
17 4 'scroll' planes (scroll screens)
18
19 the scroll planes have slightly different capabilities
20
21 NBG0
22 NBG1
23 NBG2
24 NBG3
25
26 2 'rotate' planes
27
28 RBG0
29 RBG1
30
31 -- other crap
32 EXBG (external)
33
34 -----------------------------------------------------------------------------------------------------------
35
36 Video emulation TODO:
37 -all games:
38 \-priorities (check myfairld,thunt)
39 \-complete windows effects
40 \-mosaic effect
41 \-ODD bit/H/V Counter not yet emulated properly
42 \-Reduction enable bits (zooming limiters)
43 \-Check if there are any remaining video registers that are yet to be macroized & added to the rumble.
44 -batmanfr:
45 \-If you reset the game after the character selection screen,when you get again to it there's garbage
46 floating behind Batman.
47 -elandore:
48 \-(BTANB) priorities at the VS. screen apparently is wrong,but it's like this on the Saturn version too.
49 -hanagumi:
50 \-ending screens have corrupt graphics. (*untested*)
51 -kiwames:
52 \-(fixed) incorrect color emulation for the alpha blended flames on the title screen,it's caused by a schizoid
53 linescroll emulation quirk.
54 \-the VDP1 sprites refresh is too slow,causing the "Draw by request" mode to
55 flicker. Moved back to default ATM.
56 -pblbeach:
57 \-Sprites are offset, because it doesn't clear vdp1 local coordinates set by bios,
58 I guess that they are cleared when some vdp1 register is written (kludged for now)
59 -prikura:
60 \-Attract mode presentation has corrupted graphics in various places,probably caused by incomplete
61 framebuffer data delete.
62 -seabass:
63 \-(fixed) Player sprite is corrupt/missing during movements,caused by incomplete framebuffer switching.
64 -shienryu:
65 \-level 2 background colors on statues, caused by special color calculation usage (per dot);
66 (Saturn games)
67 - scud the disposable assassin:
68 \- when zooming on melee attack background gets pink, color calculation issue?
69 - virtual hydlide:
70 \- transparent pens usage on most vdp1 items should be black instead.
71 \- likewise "press start button" is the other way around, i.e. black pen where it should be transparent instead.
72
73 Notes of Interest & Unclear features:
74
75 -the test mode / bios is drawn with layer NBG3;
76 -hanagumi puts a 'RED' dragon logo in tileram (base 0x64000, 4bpp, 8x8 tiles) but
77 its not displayed because its priority value is 0.Left-over?
78
79 -scrolling is screen display wise,meaning that a scrolling value is masked with the
80 screen resolution size values;
81
82 -H-Blank bit is INDIPENDENT of the V-Blank bit...trying to fix enable/disable it during V-Blank period
83 causes wrong gameplay speed in Golden Axe:The Duel.
84
85 -Bitmaps uses transparency pens,examples are:
86 \-elandore's energy bars;
87 \-mausuke's foreground(the one used on the playfield)
88 \-shanhigw's tile-based sprites;
89 The transparency pen table is like this:
90
91 |------------------|---------------------|
92 | Character count | Transparency code |
93 |------------------|---------------------|
94 | 16 colors |=0x0 (4 bits) |
95 | 256 colors |=0x00 (8 bits) |
96 | 2048 colors |=0x000 (11 bits) |
97 | 32,768 colors |MSB=0 (bit 15) |
98 | 16,770,000 colors|MSB=0 (bit 31) |
99 |------------------|---------------------|
100 In other words,the first three types uses the offset and not the color allocated.
101
102 -double density interlace setting (LSMD == 3) apparently does a lot of fancy stuff in the graphics sizes.
103
104 -Debug key list(only if you enable the debug mode on top of this file):
105 \-T: NBG3 layer toggle
106 \-Y: NBG2 layer toggle
107 \-U: NBG1 layer toggle
108 \-I: NBG0 layer toggle
109 \-O: SPRITE toggle
110 \-K: RBG0 layer toggle
111 \-W Decodes the graphics for F4 menu.
112 \-M Stores VDP1 ram contents from a file.
113 \-N Stores VDP1 ram contents into a file.
114 */
115
116 #include "emu.h"
117 #include "includes/saturn.h" // FIXME: this is a dependency from devices on MAME
118
119
120 #define DEBUG_MODE 0
121 #define TEST_FUNCTIONS 0
122 #define POPMESSAGE_DEBUG 0
123
124
125 enum
126 {
127 STV_TRANSPARENCY_PEN = 0x0,
128 STV_TRANSPARENCY_NONE = 0x1,
129 STV_TRANSPARENCY_ADD_BLEND = 0x2,
130 STV_TRANSPARENCY_ALPHA = 0x4
131 };
132
133 #if DEBUG_MODE
134 #define LOG_VDP2 1
135 #define LOG_ROZ 0
136 #else
137 #define LOG_VDP2 0
138 #define LOG_ROZ 0
139 #endif
140
141 /*
142
143 -------------------------------------------------|-----------------------------|------------------------------
144 | Function | Normal Scroll Screen | Rotation Scroll Screen |
145 | |-----------------------------|-----------------------------|------------------------------
146 | | NBG0 | NBG1 | NBG2 | NBG3 | RBG0 | RBG1 |
147 -------------------------------------------------|-----------------------------|------------------------------
148 | Character Colour | 16 colours | 16 colours | 16 colours | 16 colours | 16 colours | 16 colours |
149 | Count | 256 " " | 256 " " | 256 " " | 256 " " | 256 " " | 256 " " |
150 | | 2048 " " | 2048 " " | | | 2048 " " | 2048 " " |
151 | | 32768 " " | 32768 " " | | | 32768 " " | 32768 " " |
152 | | 16770000 " " | | | | 16770000 " " | 16770000 " " |
153 -------------------------------------------------|-----------------------------|------------------------------
154 | Character Size | 1x1 Cells , 2x2 Cells |
155 -------------------------------------------------|-----------------------------|------------------------------
156 | Pattern Name | 1 word , 2 words |
157 | Data Size | |
158 -------------------------------------------------|-----------------------------|------------------------------
159 | Plane Size | 1 H x 1 V 1 Pages ; 2 H x 1 V 1 Pages ; 2 H x 2 V Pages |
160 -------------------------------------------------|-----------------------------|------------------------------
161 | Plane Count | 4 | 16 |
162 -------------------------------------------------|-----------------------------|------------------------------
163 | Bitmap Possible | Yes | No | Yes | No |
164 -------------------------------------------------|-----------------------------|------------------------------
165 | Bitmap Size | 512 x 256 | N/A | 512x256 | N/A |
166 | | 512 x 512 | | 512x512 | |
167 | | 1024 x 256 | | | |
168 | | 1024 x 512 | | | |
169 -------------------------------------------------|-----------------------------|------------------------------
170 | Scale | 0.25 x - 256 x | None | Any ? |
171 -------------------------------------------------|-----------------------------|------------------------------
172 | Rotation | No | Yes |
173 -------------------------------------------------|-----------------------------|-----------------------------|
174 | Linescroll | Yes | No |
175 -------------------------------------------------|-----------------------------|------------------------------
176 | Column Scroll | Yes | No |
177 -------------------------------------------------|-----------------------------|------------------------------
178 | Mosaic | Yes | Horizontal Only |
179 -------------------------------------------------|-----------------------------|------------------------------
180
181 */
182
183 /* 180000 - r/w - TVMD - TV Screen Mode
184 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
185 | DISP | -- | -- | -- | -- | -- | -- | BDCLMD |
186 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
187 | LSMD1 | LSMD0 | VRESO1 | VRESO0 | -- | HRESO2 | HRESO1 | HRESO0 |
188 \----------|----------|----------|----------|----------|----------|----------|---------*/
189
190 #define STV_VDP2_TVMD (m_vdp2_regs[0x000/2])
191
192 #define STV_VDP2_DISP ((STV_VDP2_TVMD & 0x8000) >> 15)
193 #define STV_VDP2_BDCLMD ((STV_VDP2_TVMD & 0x0100) >> 8)
194 #define STV_VDP2_LSMD ((STV_VDP2_TVMD & 0x00c0) >> 6)
195 #define STV_VDP2_VRES ((STV_VDP2_TVMD & 0x0030) >> 4)
196 #define STV_VDP2_HRES ((STV_VDP2_TVMD & 0x0007) >> 0)
197
198 /* 180002 - r/w - EXTEN - External Signal Enable Register
199 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
200 | -- | -- | -- | -- | -- | -- | EXLTEN | EXSYEN |
201 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
202 | -- | -- | -- | -- | -- | -- | DASEL | EXBGEN |
203 \----------|----------|----------|----------|----------|----------|----------|---------*/
204
205 #define STV_VDP2_EXTEN (m_vdp2_regs[0x002/2])
206
207 #define STV_VDP2_EXLTEN ((STV_VDP2_EXTEN & 0x0200) >> 9)
208
209 /* 180004 - r/o - TVSTAT - Screen Status
210 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
211 | -- | -- | -- | -- | -- | -- | EXLTFG | EXSYFG |
212 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
213 | -- | -- | -- | -- | VBLANK | HBLANK | ODD | PAL |
214 \----------|----------|----------|----------|----------|----------|----------|---------*/
215
216 /* 180006 - r/w - VRSIZE - VRAM Size
217 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
218 | VRAMSZ | -- | -- | -- | -- | -- | -- | -- |
219 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
220 | -- | -- | -- | -- | VER3 | VER2 | VER1 | VER0 |
221 \----------|----------|----------|----------|----------|----------|----------|---------*/
222
223 #define STV_VDP2_VRSIZE (m_vdp2_regs[0x006/2])
224
225 #define STV_VDP2_VRAMSZ ((STV_VDP2_VRSIZE & 0x8000) >> 15)
226
227 /* 180008 - r/o - HCNT - H-Counter
228 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
229 | -- | -- | -- | -- | -- | -- | HCT9 | HCT8 |
230 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
231 | HCT7 | HCT6 | HCT5 | HCT4 | HCT3 | HCT2 | HCT1 | HCT0 |
232 \----------|----------|----------|----------|----------|----------|----------|---------*/
233
234 #define STV_VDP2_HCNT (m_vdp2_regs[0x008/2])
235
236 /* 18000A - r/o - VCNT - V-Counter
237 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
238 | -- | -- | -- | -- | -- | -- | VCT9 | VCT8 |
239 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
240 | VCT7 | VCT6 | VCT5 | VCT4 | VCT3 | VCT2 | VCT1 | VCT0 |
241 \----------|----------|----------|----------|----------|----------|----------|---------*/
242
243 #define STV_VDP2_VCNT (m_vdp2_regs[0x00a/2])
244
245 /* 18000C - RESERVED
246 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
247 | -- | -- | -- | -- | -- | -- | -- | -- |
248 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
249 | -- | -- | -- | -- | -- | -- | -- | -- |
250 \----------|----------|----------|----------|----------|----------|----------|---------*/
251
252 /* 18000E - r/w - RAMCTL - RAM Control
253 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
254 | CRKTE | -- | CRMD1 | CRMD0 | -- | -- | VRBMD | VRAMD |
255 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
256 | RDBSB11 | RDBSB10 | RDBSB01 | RDBSB00 | RDBSA11 | RDBSA10 | RDBSA01 | RDBSA00 |
257 \----------|----------|----------|----------|----------|----------|----------|---------*/
258
259 #define STV_VDP2_RAMCTL (m_vdp2_regs[0x00e/2])
260
261 #define STV_VDP2_CRKTE ((STV_VDP2_RAMCTL & 0x8000) >> 15)
262 #define STV_VDP2_CRMD ((STV_VDP2_RAMCTL & 0x3000) >> 12)
263 #define STV_VDP2_RDBSB1 ((STV_VDP2_RAMCTL & 0x00c0) >> 6)
264 #define STV_VDP2_RDBSB0 ((STV_VDP2_RAMCTL & 0x0030) >> 4)
265 #define STV_VDP2_RDBSA1 ((STV_VDP2_RAMCTL & 0x000c) >> 2)
266 #define STV_VDP2_RDBSA0 ((STV_VDP2_RAMCTL & 0x0003) >> 0)
267
268
269 /* 180010 - r/w - -CYCA0L - VRAM CYCLE PATTERN (BANK A0)
270 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
271 | VCP0A03 | VCP0A02 | VCP0A01 | VCP0A00 | VCP1A03 | VCP1A02 | VCP1A01 | VCP1A00 |
272 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
273 | VCP2A03 | VCP2A02 | VCP2A01 | VCP2A00 | VCP3A03 | VCP3A02 | VCP3A01 | VCP3A00 |
274 \----------|----------|----------|----------|----------|----------|----------|---------*/
275
276 #define STV_VDP2_CYCA0L (m_vdp2_regs[0x010/2])
277
278 /* 180012 - r/w - -CYCA0U - VRAM CYCLE PATTERN (BANK A0)
279 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
280 | VCP4A03 | VCP4A02 | VCP4A01 | VCP4A00 | VCP5A03 | VCP5A02 | VCP5A01 | VCP5A00 |
281 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
282 | VCP6A03 | VCP6A02 | VCP6A01 | VCP6A00 | VCP7A03 | VCP7A02 | VCP7A01 | VCP7A00 |
283 \----------|----------|----------|----------|----------|----------|----------|---------*/
284
285 #define STV_VDP2_CYCA0U (m_vdp2_regs[0x012/2])
286
287 /* 180014 - r/w - -CYCA1L - VRAM CYCLE PATTERN (BANK A1)
288 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
289 | VCP0A13 | VCP0A12 | VCP0A11 | VCP0A10 | VCP1A13 | VCP1A12 | VCP1A11 | VCP1A10 |
290 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
291 | VCP2A13 | VCP2A12 | VCP2A11 | VCP2A10 | VCP3A13 | VCP3A12 | VCP3A11 | VCP3A10 |
292 \----------|----------|----------|----------|----------|----------|----------|---------*/
293
294 #define STV_VDP2_CYCA1L (m_vdp2_regs[0x014/2])
295
296 /* 180016 - r/w - -CYCA1U - VRAM CYCLE PATTERN (BANK A1)
297 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
298 | VCP4A13 | VCP4A12 | VCP4A11 | VCP4A10 | VCP5A13 | VCP5A12 | VCP5A11 | VCP5A10 |
299 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
300 | VCP6A13 | VCP6A12 | VCP6A11 | VCP6A10 | VCP7A13 | VCP7A12 | VCP7A11 | VCP7A10 |
301 \----------|----------|----------|----------|----------|----------|----------|---------*/
302
303 #define STV_VDP2_CYCA1U (m_vdp2_regs[0x016/2])
304
305 /* 180018 - r/w - -CYCB0L - VRAM CYCLE PATTERN (BANK B0)
306 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
307 | VCP0B03 | VCP0B02 | VCP0B01 | VCP0B00 | VCP1B03 | VCP1B02 | VCP1B01 | VCP1B00 |
308 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
309 | VCP2B03 | VCP2B02 | VCP2B01 | VCP2B00 | VCP3B03 | VCP3B02 | VCP3B01 | VCP3B00 |
310 \----------|----------|----------|----------|----------|----------|----------|---------*/
311
312 #define STV_VDP2_CYCA2L (m_vdp2_regs[0x018/2])
313
314 /* 18001A - r/w - -CYCB0U - VRAM CYCLE PATTERN (BANK B0)
315 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
316 | VCP4B03 | VCP4B02 | VCP4B01 | VCP4B00 | VCP5B03 | VCP5B02 | VCP5B01 | VCP5B00 |
317 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
318 | VCP6B03 | VCP6B02 | VCP6B01 | VCP6B00 | VCP7B03 | VCP7B02 | VCP7B01 | VCP7B00 |
319 \----------|----------|----------|----------|----------|----------|----------|---------*/
320
321 #define STV_VDP2_CYCA2U (m_vdp2_regs[0x01a/2])
322
323 /* 18001C - r/w - -CYCB1L - VRAM CYCLE PATTERN (BANK B1)
324 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
325 | VCP0B13 | VCP0B12 | VCP0B11 | VCP0B10 | VCP1B13 | VCP1B12 | VCP1B11 | VCP1B10 |
326 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
327 | VCP2B13 | VCP2B12 | VCP2B11 | VCP2B10 | VCP3B13 | VCP3B12 | VCP3B11 | VCP3B10 |
328 \----------|----------|----------|----------|----------|----------|----------|---------*/
329
330 #define STV_VDP2_CYCA3L (m_vdp2_regs[0x01c/2])
331
332 /* 18001E - r/w - -CYCB1U - VRAM CYCLE PATTERN (BANK B1)
333 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
334 | VCP4B13 | VCP4B12 | VCP4B11 | VCP4B10 | VCP5B13 | VCP5B12 | VCP5B11 | VCP5B10 |
335 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
336 | VCP6B13 | VCP6B12 | VCP6B11 | VCP6B10 | VCP7B13 | VCP7B12 | VCP7B11 | VCP7B10 |
337 \----------|----------|----------|----------|----------|----------|----------|---------*/
338
339 #define STV_VDP2_CYCA3U (m_vdp2_regs[0x01e/2])
340
341 /* 180020 - r/w - BGON - SCREEN DISPLAY ENABLE
342
343 this register allows each tilemap to be enabled or disabled and also which layers are solid
344
345 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
346 | -- | -- | -- | R0TPON | N3TPON | N2TPON | N1TPON | N0TPON |
347 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
348 | -- | -- | R1ON | R0ON | N3ON | N2ON | N1ON | N0ON |
349 \----------|----------|----------|----------|----------|----------|----------|---------*/
350
351 #define STV_VDP2_BGON (m_vdp2_regs[0x020/2])
352
353 // NxOn - Layer Enable Register
354 #define STV_VDP2_xxON ((STV_VDP2_BGON & 0x001f) >> 0) /* to see if anything is enabled */
355
356 #define STV_VDP2_N0ON ((STV_VDP2_BGON & 0x0001) >> 0) /* N0On = NBG0 Enable */
357 #define STV_VDP2_N1ON ((STV_VDP2_BGON & 0x0002) >> 1) /* N1On = NBG1 Enable */
358 #define STV_VDP2_N2ON ((STV_VDP2_BGON & 0x0004) >> 2) /* N2On = NBG2 Enable */
359 #define STV_VDP2_N3ON ((STV_VDP2_BGON & 0x0008) >> 3) /* N3On = NBG3 Enable */
360 #define STV_VDP2_R0ON ((STV_VDP2_BGON & 0x0010) >> 4) /* R0On = RBG0 Enable */
361 #define STV_VDP2_R1ON ((STV_VDP2_BGON & 0x0020) >> 5) /* R1On = RBG1 Enable */
362
363 // NxTPON - Transparency Pen Enable Registers
364 #define STV_VDP2_N0TPON ((STV_VDP2_BGON & 0x0100) >> 8) /* N0TPON = NBG0 Draw Transparent Pen (as solid) /or/ RBG1 Draw Transparent Pen */
365 #define STV_VDP2_N1TPON ((STV_VDP2_BGON & 0x0200) >> 9) /* N1TPON = NBG1 Draw Transparent Pen (as solid) /or/ EXBG Draw Transparent Pen */
366 #define STV_VDP2_N2TPON ((STV_VDP2_BGON & 0x0400) >> 10)/* N2TPON = NBG2 Draw Transparent Pen (as solid) */
367 #define STV_VDP2_N3TPON ((STV_VDP2_BGON & 0x0800) >> 11)/* N3TPON = NBG3 Draw Transparent Pen (as solid) */
368 #define STV_VDP2_R0TPON ((STV_VDP2_BGON & 0x1000) >> 12)/* R0TPON = RBG0 Draw Transparent Pen (as solid) */
369
370 /*
371 180022 - MZCTL - Mosaic Control
372 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
373 | -- | -- | -- | -- | -- | -- | -- | -- |
374 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
375 | -- | -- | -- | -- | -- | -- | -- | -- |
376 \----------|----------|----------|----------|----------|----------|----------|---------*/
377
378 #define STV_VDP2_MZCTL (m_vdp2_regs[0x022/2])
379
380 #define STV_VDP2_MZSZV ((STV_VDP2_MZCTL & 0xf000) >> 12)
381 #define STV_VDP2_MZSZH ((STV_VDP2_MZCTL & 0x0f00) >> 8)
382 #define STV_VDP2_R0MZE ((STV_VDP2_MZCTL & 0x0010) >> 4)
383 #define STV_VDP2_N3MZE ((STV_VDP2_MZCTL & 0x0008) >> 3)
384 #define STV_VDP2_N2MZE ((STV_VDP2_MZCTL & 0x0004) >> 2)
385 #define STV_VDP2_N1MZE ((STV_VDP2_MZCTL & 0x0002) >> 1)
386 #define STV_VDP2_N0MZE ((STV_VDP2_MZCTL & 0x0001) >> 0)
387
388 /*180024 - Special Function Code Select
389
390 */
391
392 #define STV_VDP2_SFSEL (m_vdp2_regs[0x024/2])
393
394 /*180026 - Special Function Code
395
396 */
397
398 #define STV_VDP2_SFCODE (m_vdp2_regs[0x026/2])
399
400
401 /*
402 180028 - CHCTLA - Character Control (NBG0, NBG1)
403 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
404 | -- | -- | N1CHCN1 | N1CHCN0 | N1BMSZ1 | N1BMSZ0 | N1BMEN | N1CHSZ |
405 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
406 | -- | N0CHCN2 | N0CHCN1 | N0CHCN0 | N0BMSZ1 | N0BMSZ0 | N0BMEN | N0CHSZ |
407 \----------|----------|----------|----------|----------|----------|----------|---------*/
408
409 #define STV_VDP2_CHCTLA (m_vdp2_regs[0x028/2])
410
411 /* -------------------------- NBG0 Character Control Registers -------------------------- */
412
413 /* N0CHCNx NBG0 (or RGB1) Colour Depth
414 000 - 16 Colours
415 001 - 256 Colours
416 010 - 2048 Colours
417 011 - 32768 Colours (RGB5)
418 100 - 16770000 Colours (RGB8)
419 101 - invalid
420 110 - invalid
421 111 - invalid */
422 #define STV_VDP2_N0CHCN ((STV_VDP2_CHCTLA & 0x0070) >> 4)
423
424 /* N0BMSZx - NBG0 Bitmap Size *guessed*
425 00 - 512 x 256
426 01 - 512 x 512
427 10 - 1024 x 256
428 11 - 1024 x 512 */
429 #define STV_VDP2_N0BMSZ ((STV_VDP2_CHCTLA & 0x000c) >> 2)
430
431 /* N0BMEN - NBG0 Bitmap Enable
432 0 - use cell mode
433 1 - use bitmap mode */
434 #define STV_VDP2_N0BMEN ((STV_VDP2_CHCTLA & 0x0002) >> 1)
435
436 /* N0CHSZ - NBG0 Character (Tile) Size
437 0 - 1 cell x 1 cell (8x8)
438 1 - 2 cells x 2 cells (16x16) */
439 #define STV_VDP2_N0CHSZ ((STV_VDP2_CHCTLA & 0x0001) >> 0)
440
441 /* -------------------------- NBG1 Character Control Registers -------------------------- */
442
443 /* N1CHCNx - NBG1 (or EXB1) Colour Depth
444 00 - 16 Colours
445 01 - 256 Colours
446 10 - 2048 Colours
447 11 - 32768 Colours (RGB5) */
448 #define STV_VDP2_N1CHCN ((STV_VDP2_CHCTLA & 0x3000) >> 12)
449
450 /* N1BMSZx - NBG1 Bitmap Size *guessed*
451 00 - 512 x 256
452 01 - 512 x 512
453 10 - 1024 x 256
454 11 - 1024 x 512 */
455 #define STV_VDP2_N1BMSZ ((STV_VDP2_CHCTLA & 0x0c00) >> 10)
456
457 /* N1BMEN - NBG1 Bitmap Enable
458 0 - use cell mode
459 1 - use bitmap mode */
460 #define STV_VDP2_N1BMEN ((STV_VDP2_CHCTLA & 0x0200) >> 9)
461
462 /* N1CHSZ - NBG1 Character (Tile) Size
463 0 - 1 cell x 1 cell (8x8)
464 1 - 2 cells x 2 cells (16x16) */
465 #define STV_VDP2_N1CHSZ ((STV_VDP2_CHCTLA & 0x0100) >> 8)
466
467 /*
468 18002A - CHCTLB - Character Control (NBG2, NBG1, RBG0)
469 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
470 | -- | R0CHCN2 | R0CHCN1 | R0CHCN0 | -- | R0BMSZ | R0BMEN | R0CHSZ |
471 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
472 | -- | -- | N3CHCN | N3CHSZ | -- | -- | N2CHCN | N2CHSZ |
473 \----------|----------|----------|----------|----------|----------|----------|---------*/
474
475 #define STV_VDP2_CHCTLB (m_vdp2_regs[0x02a/2])
476
477 /* -------------------------- RBG0 Character Control Registers -------------------------- */
478
479
480 /* R0CHCNx RBG0 Colour Depth
481 000 - 16 Colours
482 001 - 256 Colours
483 010 - 2048 Colours
484 011 - 32768 Colours (RGB5)
485 100 - 16770000 Colours (RGB8)
486 101 - invalid
487 110 - invalid
488 111 - invalid */
489 #define STV_VDP2_R0CHCN ((STV_VDP2_CHCTLB & 0x7000) >> 12)
490
491 /* R0BMSZx - RBG0 Bitmap Size *guessed*
492 00 - 512 x 256
493 01 - 512 x 512 */
494 #define STV_VDP2_R0BMSZ ((STV_VDP2_CHCTLB & 0x0400) >> 10)
495
496 /* R0BMEN - RBG0 Bitmap Enable
497 0 - use cell mode
498 1 - use bitmap mode */
499 #define STV_VDP2_R0BMEN ((STV_VDP2_CHCTLB & 0x0200) >> 9)
500
501 /* R0CHSZ - RBG0 Character (Tile) Size
502 0 - 1 cell x 1 cell (8x8)
503 1 - 2 cells x 2 cells (16x16) */
504 #define STV_VDP2_R0CHSZ ((STV_VDP2_CHCTLB & 0x0100) >> 8)
505
506 #define STV_VDP2_N3CHCN ((STV_VDP2_CHCTLB & 0x0020) >> 5)
507 #define STV_VDP2_N3CHSZ ((STV_VDP2_CHCTLB & 0x0010) >> 4)
508 #define STV_VDP2_N2CHCN ((STV_VDP2_CHCTLB & 0x0002) >> 1)
509 #define STV_VDP2_N2CHSZ ((STV_VDP2_CHCTLB & 0x0001) >> 0)
510
511
512 /*
513 18002C - BMPNA - Bitmap Palette Number (NBG0, NBG1)
514 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
515 | -- | -- | -- | -- | -- | -- | -- | -- |
516 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
517 | -- | -- | -- | -- | -- | -- | -- | -- |
518 \----------|----------|----------|----------|----------|----------|----------|---------*/
519
520 #define STV_VDP2_BMPNA (m_vdp2_regs[0x02c/2])
521
522 #define STV_VDP2_N1BMP ((STV_VDP2_BMPNA & 0x0700) >> 8)
523 #define STV_VDP2_N0BMP ((STV_VDP2_BMPNA & 0x0007) >> 0)
524
525 /* 18002E - Bitmap Palette Number (RBG0)
526 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
527 | -- | -- | -- | -- | -- | -- | -- | -- |
528 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
529 | -- | -- | -- | -- | -- | -- | -- | -- |
530 \----------|----------|----------|----------|----------|----------|----------|---------*/
531
532 #define STV_VDP2_BMPNB (m_vdp2_regs[0x02e/2])
533
534 #define STV_VDP2_R0BMP ((STV_VDP2_BMPNB & 0x0007) >> 0)
535
536 /* 180030 - PNCN0 - Pattern Name Control (NBG0)
537 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
538 | N0PNB | N0CNSM | -- | -- | -- | -- | N0SPR | N0SCC |
539 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
540 | N0SPLT6 | N0SPLT5 | N0SPLT4 | N0SPCN4 | N0SPCN3 | N0SPCN2 | N0SPCN1 | N0SPCN0 |
541 \----------|----------|----------|----------|----------|----------|----------|---------*/
542
543 #define STV_VDP2_PNCN0 (m_vdp2_regs[0x030/2])
544
545 /* Pattern Data Size
546 0 = 2 bytes
547 1 = 1 byte */
548 #define STV_VDP2_N0PNB ((STV_VDP2_PNCN0 & 0x8000) >> 15)
549
550 /* Character Number Supplement (in 1 byte mode)
551 0 = Character Number = 10bits + 2bits for flip
552 1 = Character Number = 12 bits, no flip */
553 #define STV_VDP2_N0CNSM ((STV_VDP2_PNCN0 & 0x4000) >> 14)
554
555 /* NBG0 Special Priority Register (in 1 byte mode) */
556 #define STV_VDP2_N0SPR ((STV_VDP2_PNCN0 & 0x0200) >> 9)
557
558 /* NBG0 Special Colour Control Register (in 1 byte mode) */
559 #define STV_VDP2_N0SCC ((STV_VDP2_PNCN0 & 0x0100) >> 8)
560
561 /* Supplementary Palette Bits (in 1 byte mode) */
562 #define STV_VDP2_N0SPLT ((STV_VDP2_PNCN0 & 0x00e0) >> 5)
563
564 /* Supplementary Character Bits (in 1 byte mode) */
565 #define STV_VDP2_N0SPCN ((STV_VDP2_PNCN0 & 0x001f) >> 0)
566
567 /* 180032 - Pattern Name Control (NBG1)
568 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
569 | -- | -- | -- | -- | -- | -- | -- | -- |
570 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
571 | -- | -- | -- | -- | -- | -- | -- | -- |
572 \----------|----------|----------|----------|----------|----------|----------|---------*/
573
574 #define STV_VDP2_PNCN1 (m_vdp2_regs[0x032/2])
575
576 /* Pattern Data Size
577 0 = 2 bytes
578 1 = 1 byte */
579 #define STV_VDP2_N1PNB ((STV_VDP2_PNCN1 & 0x8000) >> 15)
580
581 /* Character Number Supplement (in 1 byte mode)
582 0 = Character Number = 10bits + 2bits for flip
583 1 = Character Number = 12 bits, no flip */
584 #define STV_VDP2_N1CNSM ((STV_VDP2_PNCN1 & 0x4000) >> 14)
585
586 /* NBG0 Special Priority Register (in 1 byte mode) */
587 #define STV_VDP2_N1SPR ((STV_VDP2_PNCN1 & 0x0200) >> 9)
588
589 /* NBG0 Special Colour Control Register (in 1 byte mode) */
590 #define STV_VDP2_N1SCC ((STV_VDP2_PNCN1 & 0x0100) >> 8)
591
592 /* Supplementary Palette Bits (in 1 byte mode) */
593 #define STV_VDP2_N1SPLT ((STV_VDP2_PNCN1 & 0x00e0) >> 5)
594
595 /* Supplementary Character Bits (in 1 byte mode) */
596 #define STV_VDP2_N1SPCN ((STV_VDP2_PNCN1 & 0x001f) >> 0)
597
598
599 /* 180034 - Pattern Name Control (NBG2)
600 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
601 | -- | -- | -- | -- | -- | -- | -- | -- |
602 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
603 | -- | -- | -- | -- | -- | -- | -- | -- |
604 \----------|----------|----------|----------|----------|----------|----------|---------*/
605
606 #define STV_VDP2_PNCN2 (m_vdp2_regs[0x034/2])
607
608 /* Pattern Data Size
609 0 = 2 bytes
610 1 = 1 byte */
611 #define STV_VDP2_N2PNB ((STV_VDP2_PNCN2 & 0x8000) >> 15)
612
613 /* Character Number Supplement (in 1 byte mode)
614 0 = Character Number = 10bits + 2bits for flip
615 1 = Character Number = 12 bits, no flip */
616 #define STV_VDP2_N2CNSM ((STV_VDP2_PNCN2 & 0x4000) >> 14)
617
618 /* NBG0 Special Priority Register (in 1 byte mode) */
619 #define STV_VDP2_N2SPR ((STV_VDP2_PNCN2 & 0x0200) >> 9)
620
621 /* NBG0 Special Colour Control Register (in 1 byte mode) */
622 #define STV_VDP2_N2SCC ((STV_VDP2_PNCN2 & 0x0100) >> 8)
623
624 /* Supplementary Palette Bits (in 1 byte mode) */
625 #define STV_VDP2_N2SPLT ((STV_VDP2_PNCN2 & 0x00e0) >> 5)
626
627 /* Supplementary Character Bits (in 1 byte mode) */
628 #define STV_VDP2_N2SPCN ((STV_VDP2_PNCN2 & 0x001f) >> 0)
629
630
631 /* 180036 - Pattern Name Control (NBG3)
632 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
633 | N3PNB | N3CNSM | -- | -- | -- | -- | N3SPR | N3SCC |
634 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
635 | N3SPLT6 | N3SPLT5 | N3SPLT4 | N3SPCN4 | N3SPCN3 | N3SPCN2 | N3SPCN1 | N3SPCN0 |
636 \----------|----------|----------|----------|----------|----------|----------|---------*/
637
638 #define STV_VDP2_PNCN3 (m_vdp2_regs[0x036/2])
639
640 /* Pattern Data Size
641 0 = 2 bytes
642 1 = 1 byte */
643 #define STV_VDP2_N3PNB ((STV_VDP2_PNCN3 & 0x8000) >> 15)
644
645 /* Character Number Supplement (in 1 byte mode)
646 0 = Character Number = 10bits + 2bits for flip
647 1 = Character Number = 12 bits, no flip */
648 #define STV_VDP2_N3CNSM ((STV_VDP2_PNCN3 & 0x4000) >> 14)
649
650 /* NBG0 Special Priority Register (in 1 byte mode) */
651 #define STV_VDP2_N3SPR ((STV_VDP2_PNCN3 & 0x0200) >> 9)
652
653 /* NBG0 Special Colour Control Register (in 1 byte mode) */
654 #define STV_VDP2_N3SCC ((STV_VDP2_PNCN3 & 0x0100) >> 8)
655
656 /* Supplementary Palette Bits (in 1 byte mode) */
657 #define STV_VDP2_N3SPLT ((STV_VDP2_PNCN3 & 0x00e0) >> 5)
658
659 /* Supplementary Character Bits (in 1 byte mode) */
660 #define STV_VDP2_N3SPCN ((STV_VDP2_PNCN3 & 0x001f) >> 0)
661
662
663 /* 180038 - Pattern Name Control (RBG0)
664 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
665 | -- | -- | -- | -- | -- | -- | -- | -- |
666 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
667 | -- | -- | -- | -- | -- | -- | -- | -- |
668 \----------|----------|----------|----------|----------|----------|----------|---------*/
669
670 #define STV_VDP2_PNCR (m_vdp2_regs[0x038/2])
671
672 /* Pattern Data Size
673 0 = 2 bytes
674 1 = 1 byte */
675 #define STV_VDP2_R0PNB ((STV_VDP2_PNCR & 0x8000) >> 15)
676
677 /* Character Number Supplement (in 1 byte mode)
678 0 = Character Number = 10bits + 2bits for flip
679 1 = Character Number = 12 bits, no flip */
680 #define STV_VDP2_R0CNSM ((STV_VDP2_PNCR & 0x4000) >> 14)
681
682 /* NBG0 Special Priority Register (in 1 byte mode) */
683 #define STV_VDP2_R0SPR ((STV_VDP2_PNCR & 0x0200) >> 9)
684
685 /* NBG0 Special Colour Control Register (in 1 byte mode) */
686 #define STV_VDP2_R0SCC ((STV_VDP2_PNCR & 0x0100) >> 8)
687
688 /* Supplementary Palette Bits (in 1 byte mode) */
689 #define STV_VDP2_R0SPLT ((STV_VDP2_PNCR & 0x00e0) >> 5)
690
691 /* Supplementary Character Bits (in 1 byte mode) */
692 #define STV_VDP2_R0SPCN ((STV_VDP2_PNCR & 0x001f) >> 0)
693
694 /* 18003A - PLSZ - Plane Size
695 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
696 | -- | -- | -- | -- | -- | -- | -- | -- |
697 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
698 | N3PLSZ1 | N3PLSZ0 | -- | -- | N1PLSZ1 | N1PLSZ0 | N0PLSZ1 | N0PLSZ0 |
699 \----------|----------|----------|----------|----------|----------|----------|---------*/
700
701 #define STV_VDP2_PLSZ (m_vdp2_regs[0x03a/2])
702
703 /* NBG0 Plane Size
704 00 1H Page x 1V Page
705 01 2H Pages x 1V Page
706 10 invalid
707 11 2H Pages x 2V Pages */
708 #define STV_VDP2_RBOVR ((STV_VDP2_PLSZ & 0xc000) >> 14)
709 #define STV_VDP2_RBPLSZ ((STV_VDP2_PLSZ & 0x3000) >> 12)
710 #define STV_VDP2_RAOVR ((STV_VDP2_PLSZ & 0x0c00) >> 10)
711 #define STV_VDP2_RAPLSZ ((STV_VDP2_PLSZ & 0x0300) >> 8)
712 #define STV_VDP2_N3PLSZ ((STV_VDP2_PLSZ & 0x00c0) >> 6)
713 #define STV_VDP2_N2PLSZ ((STV_VDP2_PLSZ & 0x0030) >> 4)
714 #define STV_VDP2_N1PLSZ ((STV_VDP2_PLSZ & 0x000c) >> 2)
715 #define STV_VDP2_N0PLSZ ((STV_VDP2_PLSZ & 0x0003) >> 0)
716
717 /* 18003C - MPOFN - Map Offset (NBG0, NBG1, NBG2, NBG3)
718 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
719 | -- | N3MP8 | N3MP7 | N3MP6 | -- | N2MP8 | N2MP7 | N2MP6 |
720 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
721 | -- | N1MP8 | N1MP7 | N1MP6 | -- | N0MP8 | N0MP7 | N0MP6 |
722 \----------|----------|----------|----------|----------|----------|----------|---------*/
723
724 #define STV_VDP2_MPOFN_ (m_vdp2_regs[0x03c/2])
725
726 /* Higher 3 bits of the map offset for each layer */
727 #define STV_VDP2_N3MP_ ((STV_VDP2_MPOFN_ & 0x3000) >> 12)
728 #define STV_VDP2_N2MP_ ((STV_VDP2_MPOFN_ & 0x0300) >> 8)
729 #define STV_VDP2_N1MP_ ((STV_VDP2_MPOFN_ & 0x0030) >> 4)
730 #define STV_VDP2_N0MP_ ((STV_VDP2_MPOFN_ & 0x0003) >> 0)
731
732
733
734
735 /* 18003E - Map Offset (Rotation Parameter A,B)
736 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
737 | -- | -- | -- | -- | -- | -- | -- | -- |
738 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
739 | -- | -- | -- | -- | -- | -- | -- | -- |
740 \----------|----------|----------|----------|----------|----------|----------|---------*/
741
742 #define STV_VDP2_MPOFR_ (m_vdp2_regs[0x03e/2])
743
744 #define STV_VDP2_RBMP_ ((STV_VDP2_MPOFR_ & 0x0030) >> 4)
745 #define STV_VDP2_RAMP_ ((STV_VDP2_MPOFR_ & 0x0003) >> 0)
746
747 /* 180040 - MPABN0 - Map (NBG0, Plane A,B)
748 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
749 | -- | -- | N0MPB5 | N0MPB4 | N0MPB3 | N0MPB2 | N0MPB1 | N0MPB0 |
750 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
751 | -- | -- | N0MPA5 | N0MPA4 | N0MPA3 | N0MPA2 | N0MPA1 | N0MPA0 |
752 \----------|----------|----------|----------|----------|----------|----------|---------*/
753
754 #define STV_VDP2_MPABN0 (m_vdp2_regs[0x040/2])
755
756 /* N0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap NBG0 */
757 #define STV_VDP2_N0MPB ((STV_VDP2_MPABN0 & 0x3f00) >> 8)
758
759 /* N0MPA5 = lower 6 bits of Map Address of Plane A of Tilemap NBG0 */
760 #define STV_VDP2_N0MPA ((STV_VDP2_MPABN0 & 0x003f) >> 0)
761
762
763 /* 180042 - MPCDN0 - (NBG0, Plane C,D)
764 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
765 | -- | -- | N0MPD5 | N0MPD4 | N0MPD3 | N0MPD2 | N0MPD1 | N0MPD0 |
766 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
767 | -- | -- | N0MPC5 | N0MPC4 | N0MPC3 | N0MPC2 | N0MPC1 | N0MPC0 |
768 \----------|----------|----------|----------|----------|----------|----------|---------*/
769
770 #define STV_VDP2_MPCDN0 (m_vdp2_regs[0x042/2])
771
772 /* N0MPB5 = lower 6 bits of Map Address of Plane D of Tilemap NBG0 */
773 #define STV_VDP2_N0MPD ((STV_VDP2_MPCDN0 & 0x3f00) >> 8)
774
775 /* N0MPA5 = lower 6 bits of Map Address of Plane C of Tilemap NBG0 */
776 #define STV_VDP2_N0MPC ((STV_VDP2_MPCDN0 & 0x003f) >> 0)
777
778
779 /* 180044 - Map (NBG1, Plane A,B)
780 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
781 | -- | -- | -- | -- | -- | -- | -- | -- |
782 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
783 | -- | -- | -- | -- | -- | -- | -- | -- |
784 \----------|----------|----------|----------|----------|----------|----------|---------*/
785
786 #define STV_VDP2_MPABN1 (m_vdp2_regs[0x044/2])
787
788 /* N0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap NBG1 */
789 #define STV_VDP2_N1MPB ((STV_VDP2_MPABN1 & 0x3f00) >> 8)
790
791 /* N0MPA5 = lower 6 bits of Map Address of Plane A of Tilemap NBG1 */
792 #define STV_VDP2_N1MPA ((STV_VDP2_MPABN1 & 0x003f) >> 0)
793
794 /* 180046 - Map (NBG1, Plane C,D)
795 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
796 | -- | -- | -- | -- | -- | -- | -- | -- |
797 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
798 | -- | -- | -- | -- | -- | -- | -- | -- |
799 \----------|----------|----------|----------|----------|----------|----------|---------*/
800
801 #define STV_VDP2_MPCDN1 (m_vdp2_regs[0x046/2])
802
803 /* N0MPB5 = lower 6 bits of Map Address of Plane D of Tilemap NBG0 */
804 #define STV_VDP2_N1MPD ((STV_VDP2_MPCDN1 & 0x3f00) >> 8)
805
806 /* N0MPA5 = lower 6 bits of Map Address of Plane C of Tilemap NBG0 */
807 #define STV_VDP2_N1MPC ((STV_VDP2_MPCDN1 & 0x003f) >> 0)
808
809
810 /* 180048 - Map (NBG2, Plane A,B)
811 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
812 | -- | -- | -- | -- | -- | -- | -- | -- |
813 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
814 | -- | -- | -- | -- | -- | -- | -- | -- |
815 \----------|----------|----------|----------|----------|----------|----------|---------*/
816
817 #define STV_VDP2_MPABN2 (m_vdp2_regs[0x048/2])
818
819 /* N0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap NBG2 */
820 #define STV_VDP2_N2MPB ((STV_VDP2_MPABN2 & 0x3f00) >> 8)
821
822 /* N0MPA5 = lower 6 bits of Map Address of Plane A of Tilemap NBG2 */
823 #define STV_VDP2_N2MPA ((STV_VDP2_MPABN2 & 0x003f) >> 0)
824
825 /* 18004a - Map (NBG2, Plane C,D)
826 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
827 | -- | -- | -- | -- | -- | -- | -- | -- |
828 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
829 | -- | -- | -- | -- | -- | -- | -- | -- |
830 \----------|----------|----------|----------|----------|----------|----------|---------*/
831
832 #define STV_VDP2_MPCDN2 (m_vdp2_regs[0x04a/2])
833
834 /* N0MPB5 = lower 6 bits of Map Address of Plane D of Tilemap NBG2 */
835 #define STV_VDP2_N2MPD ((STV_VDP2_MPCDN2 & 0x3f00) >> 8)
836
837 /* N0MPA5 = lower 6 bits of Map Address of Plane C of Tilemap NBG2 */
838 #define STV_VDP2_N2MPC ((STV_VDP2_MPCDN2 & 0x003f) >> 0)
839
840 /* 18004c - Map (NBG3, Plane A,B)
841 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
842 | -- | -- | -- | -- | -- | -- | -- | -- |
843 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
844 | -- | -- | -- | -- | -- | -- | -- | -- |
845 \----------|----------|----------|----------|----------|----------|----------|---------*/
846
847 #define STV_VDP2_MPABN3 (m_vdp2_regs[0x04c/2])
848
849 /* N0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap NBG1 */
850 #define STV_VDP2_N3MPB ((STV_VDP2_MPABN3 & 0x3f00) >> 8)
851
852 /* N0MPA5 = lower 6 bits of Map Address of Plane A of Tilemap NBG1 */
853 #define STV_VDP2_N3MPA ((STV_VDP2_MPABN3 & 0x003f) >> 0)
854
855
856 /* 18004e - Map (NBG3, Plane C,D)
857 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
858 | -- | -- | -- | -- | -- | -- | -- | -- |
859 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
860 | -- | -- | -- | -- | -- | -- | -- | -- |
861 \----------|----------|----------|----------|----------|----------|----------|---------*/
862
863 #define STV_VDP2_MPCDN3 (m_vdp2_regs[0x04e/2])
864
865 /* N0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap NBG0 */
866 #define STV_VDP2_N3MPD ((STV_VDP2_MPCDN3 & 0x3f00) >> 8)
867
868 /* N0MPA5 = lower 6 bits of Map Address of Plane A of Tilemap NBG0 */
869 #define STV_VDP2_N3MPC ((STV_VDP2_MPCDN3 & 0x003f) >> 0)
870
871 /* 180050 - Map (Rotation Parameter A, Plane A,B)
872 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
873 | -- | -- | -- | -- | -- | -- | -- | -- |
874 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
875 | -- | -- | -- | -- | -- | -- | -- | -- |
876 \----------|----------|----------|----------|----------|----------|----------|---------*/
877
878 #define STV_VDP2_MPABRA (m_vdp2_regs[0x050/2])
879
880 /* R0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap RBG0 */
881 #define STV_VDP2_RAMPB ((STV_VDP2_MPABRA & 0x3f00) >> 8)
882
883 /* R0MPA5 = lower 6 bits of Map Address of Plane A of Tilemap RBG0 */
884 #define STV_VDP2_RAMPA ((STV_VDP2_MPABRA & 0x003f) >> 0)
885
886
887
888 /* 180052 - Map (Rotation Parameter A, Plane C,D)
889 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
890 | -- | -- | -- | -- | -- | -- | -- | -- |
891 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
892 | -- | -- | -- | -- | -- | -- | -- | -- |
893 \----------|----------|----------|----------|----------|----------|----------|---------*/
894 #define STV_VDP2_MPCDRA (m_vdp2_regs[0x052/2])
895
896 /* R0MPB5 = lower 6 bits of Map Address of Plane D of Tilemap RBG0 */
897 #define STV_VDP2_RAMPD ((STV_VDP2_MPCDRA & 0x3f00) >> 8)
898
899 /* R0MPA5 = lower 6 bits of Map Address of Plane C of Tilemap RBG0 */
900 #define STV_VDP2_RAMPC ((STV_VDP2_MPCDRA & 0x003f) >> 0)
901
902 /* 180054 - Map (Rotation Parameter A, Plane E,F)
903 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
904 | -- | -- | -- | -- | -- | -- | -- | -- |
905 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
906 | -- | -- | -- | -- | -- | -- | -- | -- |
907 \----------|----------|----------|----------|----------|----------|----------|---------*/
908 #define STV_VDP2_MPEFRA (m_vdp2_regs[0x054/2])
909
910 /* R0MPB5 = lower 6 bits of Map Address of Plane F of Tilemap RBG0 */
911 #define STV_VDP2_RAMPF ((STV_VDP2_MPEFRA & 0x3f00) >> 8)
912
913 /* R0MPA5 = lower 6 bits of Map Address of Plane E of Tilemap RBG0 */
914 #define STV_VDP2_RAMPE ((STV_VDP2_MPEFRA & 0x003f) >> 0)
915
916 /* 180056 - Map (Rotation Parameter A, Plane G,H)
917 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
918 | -- | -- | -- | -- | -- | -- | -- | -- |
919 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
920 | -- | -- | -- | -- | -- | -- | -- | -- |
921 \----------|----------|----------|----------|----------|----------|----------|---------*/
922 #define STV_VDP2_MPGHRA (m_vdp2_regs[0x056/2])
923
924 /* R0MPB5 = lower 6 bits of Map Address of Plane H of Tilemap RBG0 */
925 #define STV_VDP2_RAMPH ((STV_VDP2_MPGHRA & 0x3f00) >> 8)
926
927 /* R0MPA5 = lower 6 bits of Map Address of Plane G of Tilemap RBG0 */
928 #define STV_VDP2_RAMPG ((STV_VDP2_MPGHRA & 0x003f) >> 0)
929
930 /* 180058 - Map (Rotation Parameter A, Plane I,J)
931 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
932 | -- | -- | -- | -- | -- | -- | -- | -- |
933 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
934 | -- | -- | -- | -- | -- | -- | -- | -- |
935 \----------|----------|----------|----------|----------|----------|----------|---------*/
936 #define STV_VDP2_MPIJRA (m_vdp2_regs[0x058/2])
937
938 /* R0MPB5 = lower 6 bits of Map Address of Plane J of Tilemap RBG0 */
939 #define STV_VDP2_RAMPJ ((STV_VDP2_MPIJRA & 0x3f00) >> 8)
940
941 /* R0MPA5 = lower 6 bits of Map Address of Plane I of Tilemap RBG0 */
942 #define STV_VDP2_RAMPI ((STV_VDP2_MPIJRA & 0x003f) >> 0)
943
944 /* 18005a - Map (Rotation Parameter A, Plane K,L)
945 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
946 | -- | -- | -- | -- | -- | -- | -- | -- |
947 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
948 | -- | -- | -- | -- | -- | -- | -- | -- |
949 \----------|----------|----------|----------|----------|----------|----------|---------*/
950 #define STV_VDP2_MPKLRA (m_vdp2_regs[0x05a/2])
951
952 /* R0MPB5 = lower 6 bits of Map Address of Plane L of Tilemap RBG0 */
953 #define STV_VDP2_RAMPL ((STV_VDP2_MPKLRA & 0x3f00) >> 8)
954
955 /* R0MPA5 = lower 6 bits of Map Address of Plane K of Tilemap RBG0 */
956 #define STV_VDP2_RAMPK ((STV_VDP2_MPKLRA & 0x003f) >> 0)
957
958 /* 18005c - Map (Rotation Parameter A, Plane M,N)
959 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
960 | -- | -- | -- | -- | -- | -- | -- | -- |
961 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
962 | -- | -- | -- | -- | -- | -- | -- | -- |
963 \----------|----------|----------|----------|----------|----------|----------|---------*/
964 #define STV_VDP2_MPMNRA (m_vdp2_regs[0x05c/2])
965
966 /* R0MPB5 = lower 6 bits of Map Address of Plane N of Tilemap RBG0 */
967 #define STV_VDP2_RAMPN ((STV_VDP2_MPMNRA & 0x3f00) >> 8)
968
969 /* R0MPA5 = lower 6 bits of Map Address of Plane M of Tilemap RBG0 */
970 #define STV_VDP2_RAMPM ((STV_VDP2_MPMNRA & 0x003f) >> 0)
971
972 /* 18005e - Map (Rotation Parameter A, Plane O,P)
973 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
974 | -- | -- | -- | -- | -- | -- | -- | -- |
975 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
976 | -- | -- | -- | -- | -- | -- | -- | -- |
977 \----------|----------|----------|----------|----------|----------|----------|---------*/
978 #define STV_VDP2_MPOPRA (m_vdp2_regs[0x05e/2])
979
980 /* R0MPB5 = lower 6 bits of Map Address of Plane P of Tilemap RBG0 */
981 #define STV_VDP2_RAMPP ((STV_VDP2_MPOPRA & 0x3f00) >> 8)
982
983 /* R0MPA5 = lower 6 bits of Map Address of Plane O of Tilemap RBG0 */
984 #define STV_VDP2_RAMPO ((STV_VDP2_MPOPRA & 0x003f) >> 0)
985
986 /* 180060 - Map (Rotation Parameter B, Plane A,B)
987 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
988 | -- | -- | -- | -- | -- | -- | -- | -- |
989 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
990 | -- | -- | -- | -- | -- | -- | -- | -- |
991 \----------|----------|----------|----------|----------|----------|----------|---------*/
992
993 #define STV_VDP2_MPABRB (m_vdp2_regs[0x060/2])
994
995 /* R0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap RBG0 */
996 #define STV_VDP2_RBMPB ((STV_VDP2_MPABRB & 0x3f00) >> 8)
997
998 /* R0MPA5 = lower 6 bits of Map Address of Plane A of Tilemap RBG0 */
999 #define STV_VDP2_RBMPA ((STV_VDP2_MPABRB & 0x003f) >> 0)
1000
1001
1002 /* 180062 - Map (Rotation Parameter B, Plane C,D)
1003 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1004 | -- | -- | -- | -- | -- | -- | -- | -- |
1005 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1006 | -- | -- | -- | -- | -- | -- | -- | -- |
1007 \----------|----------|----------|----------|----------|----------|----------|---------*/
1008
1009 #define STV_VDP2_MPCDRB (m_vdp2_regs[0x062/2])
1010
1011 /* R0MPD5 = lower 6 bits of Map Address of Plane D of Tilemap RBG0 */
1012 #define STV_VDP2_RBMPD ((STV_VDP2_MPCDRB & 0x3f00) >> 8)
1013
1014 /* R0MPc5 = lower 6 bits of Map Address of Plane C of Tilemap RBG0 */
1015 #define STV_VDP2_RBMPC ((STV_VDP2_MPCDRB & 0x003f) >> 0)
1016
1017 /* 180064 - Map (Rotation Parameter B, Plane E,F)
1018 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1019 | -- | -- | -- | -- | -- | -- | -- | -- |
1020 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1021 | -- | -- | -- | -- | -- | -- | -- | -- |
1022 \----------|----------|----------|----------|----------|----------|----------|---------*/
1023
1024 #define STV_VDP2_MPEFRB (m_vdp2_regs[0x064/2])
1025
1026 /* R0MPF5 = lower 6 bits of Map Address of Plane F of Tilemap RBG0 */
1027 #define STV_VDP2_RBMPF ((STV_VDP2_MPEFRB & 0x3f00) >> 8)
1028
1029 /* R0MPE5 = lower 6 bits of Map Address of Plane E of Tilemap RBG0 */
1030 #define STV_VDP2_RBMPE ((STV_VDP2_MPEFRB & 0x003f) >> 0)
1031
1032 /* 180066 - Map (Rotation Parameter B, Plane G,H)
1033 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1034 | -- | -- | -- | -- | -- | -- | -- | -- |
1035 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1036 | -- | -- | -- | -- | -- | -- | -- | -- |
1037 \----------|----------|----------|----------|----------|----------|----------|---------*/
1038
1039 #define STV_VDP2_MPGHRB (m_vdp2_regs[0x066/2])
1040
1041 /* R0MPH5 = lower 6 bits of Map Address of Plane H of Tilemap RBG0 */
1042 #define STV_VDP2_RBMPH ((STV_VDP2_MPGHRB & 0x3f00) >> 8)
1043
1044 /* R0MPG5 = lower 6 bits of Map Address of Plane G of Tilemap RBG0 */
1045 #define STV_VDP2_RBMPG ((STV_VDP2_MPGHRB & 0x003f) >> 0)
1046
1047 /* 180068 - Map (Rotation Parameter B, Plane I,J)
1048 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1049 | -- | -- | -- | -- | -- | -- | -- | -- |
1050 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1051 | -- | -- | -- | -- | -- | -- | -- | -- |
1052 \----------|----------|----------|----------|----------|----------|----------|---------*/
1053
1054 #define STV_VDP2_MPIJRB (m_vdp2_regs[0x068/2])
1055
1056 /* R0MPJ5 = lower 6 bits of Map Address of Plane J of Tilemap RBG0 */
1057 #define STV_VDP2_RBMPJ ((STV_VDP2_MPIJRB & 0x3f00) >> 8)
1058
1059 /* R0MPI5 = lower 6 bits of Map Address of Plane E of Tilemap RBG0 */
1060 #define STV_VDP2_RBMPI ((STV_VDP2_MPIJRB & 0x003f) >> 0)
1061
1062 /* 18006a - Map (Rotation Parameter B, Plane K,L)
1063 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1064 | -- | -- | -- | -- | -- | -- | -- | -- |
1065 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1066 | -- | -- | -- | -- | -- | -- | -- | -- |
1067 \----------|----------|----------|----------|----------|----------|----------|---------*/
1068
1069 #define STV_VDP2_MPKLRB (m_vdp2_regs[0x06a/2])
1070
1071 /* R0MPL5 = lower 6 bits of Map Address of Plane L of Tilemap RBG0 */
1072 #define STV_VDP2_RBMPL ((STV_VDP2_MPKLRB & 0x3f00) >> 8)
1073
1074 /* R0MPK5 = lower 6 bits of Map Address of Plane K of Tilemap RBG0 */
1075 #define STV_VDP2_RBMPK ((STV_VDP2_MPKLRB & 0x003f) >> 0)
1076
1077 /* 18006c - Map (Rotation Parameter B, Plane M,N)
1078 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1079 | -- | -- | -- | -- | -- | -- | -- | -- |
1080 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1081 | -- | -- | -- | -- | -- | -- | -- | -- |
1082 \----------|----------|----------|----------|----------|----------|----------|---------*/
1083
1084 #define STV_VDP2_MPMNRB (m_vdp2_regs[0x06c/2])
1085
1086 /* R0MPN5 = lower 6 bits of Map Address of Plane N of Tilemap RBG0 */
1087 #define STV_VDP2_RBMPN ((STV_VDP2_MPMNRB & 0x3f00) >> 8)
1088
1089 /* R0MPM5 = lower 6 bits of Map Address of Plane M of Tilemap RBG0 */
1090 #define STV_VDP2_RBMPM ((STV_VDP2_MPMNRB & 0x003f) >> 0)
1091
1092 /* 18006e - Map (Rotation Parameter B, Plane O,P)
1093 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1094 | -- | -- | -- | -- | -- | -- | -- | -- |
1095 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1096 | -- | -- | -- | -- | -- | -- | -- | -- |
1097 \----------|----------|----------|----------|----------|----------|----------|---------*/
1098
1099 #define STV_VDP2_MPOPRB (m_vdp2_regs[0x06e/2])
1100
1101 /* R0MPP5 = lower 6 bits of Map Address of Plane P of Tilemap RBG0 */
1102 #define STV_VDP2_RBMPP ((STV_VDP2_MPOPRB & 0x3f00) >> 8)
1103
1104 /* R0MPO5 = lower 6 bits of Map Address of Plane O of Tilemap RBG0 */
1105 #define STV_VDP2_RBMPO ((STV_VDP2_MPOPRB & 0x003f) >> 0)
1106
1107 /* 180070 - SCXIN0 - Screen Scroll (NBG0, Horizontal Integer Part)
1108 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1109 | -- | -- | -- | -- | -- | -- | -- | -- |
1110 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1111 | -- | -- | -- | -- | -- | -- | -- | -- |
1112 \----------|----------|----------|----------|----------|----------|----------|---------*/
1113
1114 #define STV_VDP2_SCXIN0 (m_vdp2_regs[0x070/2])
1115
1116
1117 /* 180072 - Screen Scroll (NBG0, Horizontal Fractional Part)
1118 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1119 | -- | -- | -- | -- | -- | -- | -- | -- |
1120 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1121 | -- | -- | -- | -- | -- | -- | -- | -- |
1122 \----------|----------|----------|----------|----------|----------|----------|---------*/
1123
1124 #define STV_VDP2_SCXDN0 (m_vdp2_regs[0x072/2])
1125
1126 /* 180074 - SCYIN0 - Screen Scroll (NBG0, Vertical Integer Part)
1127 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1128 | -- | -- | -- | -- | -- | -- | -- | -- |
1129 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1130 | -- | -- | -- | -- | -- | -- | -- | -- |
1131 \----------|----------|----------|----------|----------|----------|----------|---------*/
1132 #define STV_VDP2_SCYIN0 (m_vdp2_regs[0x074/2])
1133
1134
1135 /* 180076 - Screen Scroll (NBG0, Vertical Fractional Part)
1136 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1137 | -- | -- | -- | -- | -- | -- | -- | -- |
1138 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1139 | -- | -- | -- | -- | -- | -- | -- | -- |
1140 \----------|----------|----------|----------|----------|----------|----------|---------*/
1141
1142 #define STV_VDP2_SCYDN0 (m_vdp2_regs[0x076/2])
1143
1144 /* 180078 - Coordinate Inc (NBG0, Horizontal Integer Part)
1145 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1146 | -- | -- | -- | -- | -- | -- | -- | -- |
1147 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1148 | -- | -- | -- | -- | -- | -- | -- | -- |
1149 \----------|----------|----------|----------|----------|----------|----------|---------*/
1150
1151 #define STV_VDP2_ZMXIN0 (m_vdp2_regs[0x078/2])
1152
1153 #define STV_VDP2_N0ZMXI ((STV_VDP2_ZMXIN0 & 0x0007) >> 0)
1154
1155 /* 18007a - Coordinate Inc (NBG0, Horizontal Fractional Part)
1156 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1157 | -- | -- | -- | -- | -- | -- | -- | -- |
1158 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1159 | -- | -- | -- | -- | -- | -- | -- | -- |
1160 \----------|----------|----------|----------|----------|----------|----------|---------*/
1161
1162 #define STV_VDP2_ZMXDN0 (m_vdp2_regs[0x07a/2])
1163
1164 #define STV_VDP2_N0ZMXD ((STV_VDP2_ZMXDN0 >> 8)& 0xff)
1165 #define STV_VDP2_ZMXN0 (((STV_VDP2_N0ZMXI<<16) | (STV_VDP2_N0ZMXD<<8)) & 0x0007ff00)
1166
1167
1168 /* 18007c - Coordinate Inc (NBG0, Vertical Integer Part)
1169 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1170 | -- | -- | -- | -- | -- | -- | -- | -- |
1171 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1172 | -- | -- | -- | -- | -- | -- | -- | -- |
1173 \----------|----------|----------|----------|----------|----------|----------|---------*/
1174
1175 #define STV_VDP2_ZMYIN0 (m_vdp2_regs[0x07c/2])
1176
1177 #define STV_VDP2_N0ZMYI ((STV_VDP2_ZMYIN0 & 0x0007) >> 0)
1178
1179 /* 18007e - Coordinate Inc (NBG0, Vertical Fractional Part)
1180 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1181 | -- | -- | -- | -- | -- | -- | -- | -- |
1182 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1183 | -- | -- | -- | -- | -- | -- | -- | -- |
1184 \----------|----------|----------|----------|----------|----------|----------|---------*/
1185
1186 #define STV_VDP2_ZMYDN0 (m_vdp2_regs[0x07e/2])
1187
1188 #define STV_VDP2_N0ZMYD ((STV_VDP2_ZMYDN0 >> 8)& 0xff)
1189 #define STV_VDP2_ZMYN0 (((STV_VDP2_N0ZMYI<<16) | (STV_VDP2_N0ZMYD<<8)) & 0x0007ff00)
1190
1191 /* 180080 - SCXIN1 - Screen Scroll (NBG1, Horizontal Integer Part)
1192 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1193 | -- | -- | -- | -- | -- | -- | -- | -- |
1194 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1195 | -- | -- | -- | -- | -- | -- | -- | -- |
1196 \----------|----------|----------|----------|----------|----------|----------|---------*/
1197
1198 #define STV_VDP2_SCXIN1 (m_vdp2_regs[0x080/2])
1199
1200 /* 180082 - Screen Scroll (NBG1, Horizontal Fractional Part)
1201 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1202 | -- | -- | -- | -- | -- | -- | -- | -- |
1203 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1204 | -- | -- | -- | -- | -- | -- | -- | -- |
1205 \----------|----------|----------|----------|----------|----------|----------|---------*/
1206
1207 #define STV_VDP2_SCXDN1 (m_vdp2_regs[0x082/2])
1208
1209 /* 180084 - SCYIN1 - Screen Scroll (NBG1, Vertical Integer Part)
1210 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1211 | -- | -- | -- | -- | -- | -- | -- | -- |
1212 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1213 | -- | -- | -- | -- | -- | -- | -- | -- |
1214 \----------|----------|----------|----------|----------|----------|----------|---------*/
1215
1216 #define STV_VDP2_SCYIN1 (m_vdp2_regs[0x084/2])
1217
1218 /* 180086 - Screen Scroll (NBG1, Vertical Fractional Part)
1219 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1220 | -- | -- | -- | -- | -- | -- | -- | -- |
1221 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1222 | -- | -- | -- | -- | -- | -- | -- | -- |
1223 \----------|----------|----------|----------|----------|----------|----------|---------*/
1224
1225 #define STV_VDP2_SCYDN1 (m_vdp2_regs[0x086/2])
1226
1227 /* 180088 - Coordinate Inc (NBG1, Horizontal Integer Part)
1228 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1229 | -- | -- | -- | -- | -- | -- | -- | -- |
1230 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1231 | -- | -- | -- | -- | -- | -- | -- | -- |
1232 \----------|----------|----------|----------|----------|----------|----------|---------*/
1233
1234 #define STV_VDP2_ZMXIN1 (m_vdp2_regs[0x088/2])
1235
1236 #define STV_VDP2_N1ZMXI ((STV_VDP2_ZMXIN1 & 0x0007) >> 0)
1237
1238 /* 18008a - Coordinate Inc (NBG1, Horizontal Fractional Part)
1239 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1240 | -- | -- | -- | -- | -- | -- | -- | -- |
1241 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1242 | -- | -- | -- | -- | -- | -- | -- | -- |
1243 \----------|----------|----------|----------|----------|----------|----------|---------*/
1244
1245 #define STV_VDP2_ZMXDN1 (m_vdp2_regs[0x08a/2])
1246
1247 #define STV_VDP2_N1ZMXD ((STV_VDP2_ZMXDN1 >> 8)& 0xff)
1248 #define STV_VDP2_ZMXN1 (((STV_VDP2_N1ZMXI<<16) | (STV_VDP2_N1ZMXD<<8)) & 0x0007ff00)
1249
1250 /* 18008c - Coordinate Inc (NBG1, Vertical Integer Part)
1251 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1252 | -- | -- | -- | -- | -- | -- | -- | -- |
1253 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1254 | -- | -- | -- | -- | -- | -- | -- | -- |
1255 \----------|----------|----------|----------|----------|----------|----------|---------*/
1256
1257 #define STV_VDP2_ZMYIN1 (m_vdp2_regs[0x08c/2])
1258
1259 #define STV_VDP2_N1ZMYI ((STV_VDP2_ZMYIN1 & 0x0007) >> 0)
1260
1261 /* 18008e - Coordinate Inc (NBG1, Vertical Fractional Part)
1262 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1263 | -- | -- | -- | -- | -- | -- | -- | -- |
1264 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1265 | -- | -- | -- | -- | -- | -- | -- | -- |
1266 \----------|----------|----------|----------|----------|----------|----------|---------*/
1267
1268 #define STV_VDP2_ZMYDN1 (m_vdp2_regs[0x08e/2])
1269
1270 #define STV_VDP2_N1ZMYD ((STV_VDP2_ZMYDN1 >> 8)& 0xff)
1271 #define STV_VDP2_ZMYN1 (((STV_VDP2_N1ZMYI<<16) | (STV_VDP2_N1ZMYD<<8)) & 0x007ff00)
1272
1273 /* 180090 - SCXN2 - Screen Scroll (NBG2, Horizontal)
1274 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1275 | -- | -- | -- | -- | -- | -- | -- | -- |
1276 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1277 | -- | -- | -- | -- | -- | -- | -- | -- |
1278 \----------|----------|----------|----------|----------|----------|----------|---------*/
1279
1280 #define STV_VDP2_SCXN2 (m_vdp2_regs[0x090/2])
1281
1282 /* 180092 - SCYN2 - Screen Scroll (NBG2, Vertical)
1283 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1284 | -- | -- | -- | -- | -- | -- | -- | -- |
1285 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1286 | -- | -- | -- | -- | -- | -- | -- | -- |
1287 \----------|----------|----------|----------|----------|----------|----------|---------*/
1288
1289 #define STV_VDP2_SCYN2 (m_vdp2_regs[0x092/2])
1290
1291 /* 180094 - SCXN3 - Screen Scroll (NBG3, Horizontal)
1292 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1293 | -- | -- | -- | -- | -- | -- | -- | -- |
1294 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1295 | -- | -- | -- | -- | -- | -- | -- | -- |
1296 \----------|----------|----------|----------|----------|----------|----------|---------*/
1297
1298 #define STV_VDP2_SCXN3 (m_vdp2_regs[0x094/2])
1299
1300 /* 180096 - SCYN3 - Screen Scroll (NBG3, Vertical)
1301 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1302 | -- | -- | -- | -- | -- | -- | -- | -- |
1303 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1304 | -- | -- | -- | -- | -- | -- | -- | -- |
1305 \----------|----------|----------|----------|----------|----------|----------|---------*/
1306
1307 #define STV_VDP2_SCYN3 (m_vdp2_regs[0x096/2])
1308
1309 /* 180098 - Reduction Enable
1310 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1311 | -- | -- | -- | -- | -- | -- | N1ZMQT | N1ZMHF |
1312 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1313 | -- | -- | -- | -- | -- | -- | N0ZMQT | N0ZMHF |
1314 \----------|----------|----------|----------|----------|----------|----------|---------*/
1315
1316 #define STV_VDP2_ZMCTL (m_vdp2_regs[0x098/2])
1317
1318 #define STV_VDP2_N1ZMQT ((STV_VDP2_ZMCTL & 0x0200) >> 9)
1319 #define STV_VDP2_N1ZMHF ((STV_VDP2_ZMCTL & 0x0100) >> 8)
1320 #define STV_VDP2_N0ZMQT ((STV_VDP2_ZMCTL & 0x0002) >> 1)
1321 #define STV_VDP2_N0ZMHF ((STV_VDP2_ZMCTL & 0x0001) >> 0)
1322
1323 /* 18009a - Line and Vertical Cell Scroll Control (NBG0, NBG1)
1324 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1325 | -- | -- | -- | -- | -- | -- | -- | -- |
1326 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1327 | -- | -- | -- | -- | -- | -- | -- | -- |
1328 \----------|----------|----------|----------|----------|----------|----------|---------*/
1329
1330 #define STV_VDP2_SCRCTL (m_vdp2_regs[0x09a/2])
1331
1332 #define STV_VDP2_N1LSS ((STV_VDP2_SCRCTL & 0x3000) >> 12)
1333 #define STV_VDP2_N1LZMX ((STV_VDP2_SCRCTL & 0x0800) >> 11)
1334 #define STV_VDP2_N1LSCY ((STV_VDP2_SCRCTL & 0x0400) >> 10)
1335 #define STV_VDP2_N1LSCX ((STV_VDP2_SCRCTL & 0x0200) >> 9)
1336 #define STV_VDP2_N1VCSC ((STV_VDP2_SCRCTL & 0x0100) >> 8)
1337 #define STV_VDP2_N0LSS ((STV_VDP2_SCRCTL & 0x0030) >> 4)
1338 #define STV_VDP2_N0LZMX ((STV_VDP2_SCRCTL & 0x0008) >> 3)
1339 #define STV_VDP2_N0LSCY ((STV_VDP2_SCRCTL & 0x0004) >> 2)
1340 #define STV_VDP2_N0LSCX ((STV_VDP2_SCRCTL & 0x0002) >> 1)
1341 #define STV_VDP2_N0VCSC ((STV_VDP2_SCRCTL & 0x0001) >> 0)
1342
1343 /* 18009c - Vertical Cell Table Address (NBG0, NBG1)
1344 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1345 | -- | -- | -- | -- | -- | -- | -- | -- |
1346 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1347 | -- | -- | -- | -- | -- | -- | -- | -- |
1348 \----------|----------|----------|----------|----------|----------|----------|---------*/
1349
1350 #define STV_VDP2_VCSTAU (m_vdp2_regs[0x09c/2] & 7)
1351
1352
1353 /* 18009e - Vertical Cell Table Address (NBG0, NBG1)
1354 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1355 | -- | -- | -- | -- | -- | -- | -- | -- |
1356 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1357 | -- | -- | -- | -- | -- | -- | -- | -- |
1358 \----------|----------|----------|----------|----------|----------|----------|---------*/
1359
1360 #define STV_VDP2_VCSTAL (m_vdp2_regs[0x09e/2])
1361
1362 /* 1800a0 - LSTA0U - Line Scroll Table Address (NBG0)
1363 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1364 | -- | -- | -- | -- | -- | -- | -- | -- |
1365 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1366 | -- | -- | -- | -- | -- | -- | -- | -- |
1367 \----------|----------|----------|----------|----------|----------|----------|---------*/
1368
1369 /*bit 2 unused when VRAM = 4 Mbits*/
1370 #define STV_VDP2_LSTA0U (m_vdp2_regs[0x0a0/2] & 7)
1371
1372 /* 1800a2 - LSTA0L - Line Scroll Table Address (NBG0)
1373 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1374 | -- | -- | -- | -- | -- | -- | -- | -- |
1375 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1376 | -- | -- | -- | -- | -- | -- | -- | -- |
1377 \----------|----------|----------|----------|----------|----------|----------|---------*/
1378
1379 #define STV_VDP2_LSTA0L (m_vdp2_regs[0x0a2/2])
1380
1381 /* 1800a4 - LSTA1U - Line Scroll Table Address (NBG1)
1382 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1383 | -- | -- | -- | -- | -- | -- | -- | -- |
1384 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1385 | -- | -- | -- | -- | -- | -- | -- | -- |
1386 \----------|----------|----------|----------|----------|----------|----------|---------*/
1387
1388 /*bit 2 unused when VRAM = 4 Mbits*/
1389 #define STV_VDP2_LSTA1U (m_vdp2_regs[0x0a4/2] & 7)
1390
1391 /* 1800a6 - LSTA1L - Line Scroll Table Address (NBG1)
1392 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1393 | -- | -- | -- | -- | -- | -- | -- | -- |
1394 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1395 | -- | -- | -- | -- | -- | -- | -- | -- |
1396 \----------|----------|----------|----------|----------|----------|----------|---------*/
1397
1398 #define STV_VDP2_LSTA1L (m_vdp2_regs[0x0a6/2])
1399
1400 /* 1800a8 - LCTAU - Line Colour Screen Table Address
1401 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1402 | -- | -- | -- | -- | -- | -- | -- | -- |
1403 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1404 | -- | -- | -- | -- | -- | -- | -- | -- |
1405 \----------|----------|----------|----------|----------|----------|----------|---------*/
1406
1407 #define STV_VDP2_LCTAU (m_vdp2_regs[0x0a8/2])
1408 #define STV_VDP2_LCCLMD ((STV_VDP2_LCTAU & 0x8000) >> 15)
1409
1410 /* 1800aa - LCTAL - Line Colour Screen Table Address
1411 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1412 | -- | -- | -- | -- | -- | -- | -- | -- |
1413 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1414 | -- | -- | -- | -- | -- | -- | -- | -- |
1415 \----------|----------|----------|----------|----------|----------|----------|---------*/
1416 #define STV_VDP2_LCTAL (m_vdp2_regs[0x0aa/2])
1417
1418 #define STV_VDP2_LCTA (((STV_VDP2_LCTAU & 0x0007) << 16) | (STV_VDP2_LCTAL & 0xffff))
1419
1420 /* 1800ac - Back Screen Table Address
1421 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1422 | BKCLMD | -- | -- | -- | -- | -- | -- | -- |
1423 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1424 | -- | -- | -- | -- | -- | BKTA18 | BKTA17 | BKTA16 |
1425 \----------|----------|----------|----------|----------|----------|----------|---------*/
1426
1427 #define STV_VDP2_BKTAU (m_vdp2_regs[0x0ac/2])
1428
1429 #define STV_VDP2_BKCLMD ((STV_VDP2_BKTAU & 0x8000) >> 15)
1430
1431
1432 /* 1800ae - Back Screen Table Address
1433 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1434 | BKTA15 | BKTA14 | BKTA13 | BKTA12 | BKTA11 | BKTA10 | BKTA9 | BKTA8 |
1435 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1436 | BKTA7 | BKTA7 | BKTA6 | BKTA5 | BKTA4 | BKTA3 | BKTA2 | BKTA0 |
1437 \----------|----------|----------|----------|----------|----------|----------|---------*/
1438
1439 #define STV_VDP2_BKTAL (m_vdp2_regs[0x0ae/2])
1440
1441 #define STV_VDP2_BKTA (((STV_VDP2_BKTAU & 0x0007) << 16) | (STV_VDP2_BKTAL & 0xffff))
1442
1443 /* 1800b0 - RPMD - Rotation Parameter Mode
1444 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1445 | -- | -- | -- | -- | -- | -- | -- | -- |
1446 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1447 | -- | -- | -- | -- | -- | -- | -- | -- |
1448 \----------|----------|----------|----------|----------|----------|----------|---------*/
1449
1450 #define STV_VDP2_RPMD ((m_vdp2_regs[0x0b0/2]) & 0x0003)
1451
1452 /* 1800b2 - RPRCTL - Rotation Parameter Read Control
1453 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1454 | -- | -- | -- | -- | -- | RBKASTRE | RBYSTRE | RBXSTRE |
1455 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1456 | -- | -- | -- | -- | -- | RAKASTRE | RAYSTRE | RBXSTRE |
1457 \----------|----------|----------|----------|----------|----------|----------|---------*/
1458
1459 #define STV_VDP2_RPRCTL (m_vdp2_regs[0x0b2/2])
1460 #define STV_VDP2_RBKASTRE ((STV_VDP2_RPRCTL & 0x0400) >> 10)
1461 #define STV_VDP2_RBYSTRE ((STV_VDP2_RPRCTL & 0x0200) >> 9)
1462 #define STV_VDP2_RBXSTRE ((STV_VDP2_RPRCTL & 0x0100) >> 8)
1463 #define STV_VDP2_RAKASTRE ((STV_VDP2_RPRCTL & 0x0004) >> 2)
1464 #define STV_VDP2_RAYSTRE ((STV_VDP2_RPRCTL & 0x0002) >> 1)
1465 #define STV_VDP2_RAXSTRE ((STV_VDP2_RPRCTL & 0x0001) >> 0)
1466
1467 /* 1800b4 - KTCTL - Coefficient Table Control
1468 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1469 | -- | -- | -- | RBKLCE | RBKMD1 | RBKMD0 | RBKDBS | RBKTE |
1470 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1471 | -- | -- | -- | RAKLCE | RAKMD1 | RAKMD0 | RAKDBS | RAKTE |
1472 \----------|----------|----------|----------|----------|----------|----------|---------*/
1473
1474 #define STV_VDP2_KTCTL (m_vdp2_regs[0x0b4/2])
1475 #define STV_VDP2_RBUNK ((STV_VDP2_KTCTL & 0x6000) >> 13)
1476 #define STV_VDP2_RBKLCE ((STV_VDP2_KTCTL & 0x1000) >> 12)
1477 #define STV_VDP2_RBKMD ((STV_VDP2_KTCTL & 0x0c00) >> 10)
1478 #define STV_VDP2_RBKDBS ((STV_VDP2_KTCTL & 0x0200) >> 9)
1479 #define STV_VDP2_RBKTE ((STV_VDP2_KTCTL & 0x0100) >> 8)
1480 #define STV_VDP2_RAUNK ((STV_VDP2_KTCTL & 0x0060) >> 5)
1481 #define STV_VDP2_RAKLCE ((STV_VDP2_KTCTL & 0x0010) >> 4)
1482 #define STV_VDP2_RAKMD ((STV_VDP2_KTCTL & 0x000c) >> 2)
1483 #define STV_VDP2_RAKDBS ((STV_VDP2_KTCTL & 0x0002) >> 1)
1484 #define STV_VDP2_RAKTE ((STV_VDP2_KTCTL & 0x0001) >> 0)
1485
1486 /* 1800b6 - KTAOF - Coefficient Table Address Offset (Rotation Parameter A,B)
1487 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1488 | -- | -- | -- | -- | -- | RBKTAOS2 | RBKTAOS1 | RBKTAOS0 |
1489 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1490 | -- | -- | -- | -- | -- | RAKTAOS2 | RAKTAOS1 | RAKTAOS0 |
1491 \----------|----------|----------|----------|----------|----------|----------|---------*/
1492
1493 #define STV_VDP2_KTAOF (m_vdp2_regs[0x0b6/2])
1494 #define STV_VDP2_RBKTAOS ((STV_VDP2_KTAOF & 0x0700) >> 8)
1495 #define STV_VDP2_RAKTAOS ((STV_VDP2_KTAOF & 0x0007) >> 0)
1496
1497 /* 1800b8 - OVPNRA - Screen Over Pattern Name (Rotation Parameter A)
1498 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1499 | -- | -- | -- | -- | -- | -- | -- | -- |
1500 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1501 | -- | -- | -- | -- | -- | -- | -- | -- |
1502 \----------|----------|----------|----------|----------|----------|----------|---------*/
1503
1504 #define STV_VDP2_OVPNRA (m_vdp2_regs[0x0b8/2])
1505
1506 /* 1800ba - Screen Over Pattern Name (Rotation Parameter B)
1507 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1508 | -- | -- | -- | -- | -- | -- | -- | -- |
1509 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1510 | -- | -- | -- | -- | -- | -- | -- | -- |
1511 \----------|----------|----------|----------|----------|----------|----------|---------*/
1512
1513 #define STV_VDP2_OVPNRB (m_vdp2_regs[0x0ba/2])
1514
1515 /* 1800bc - RPTAU - Rotation Parameter Table Address (Rotation Parameter A,B)
1516 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1517 | -- | -- | -- | -- | -- | -- | -- | -- |
1518 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1519 | -- | -- | -- | -- | -- | RPTA18 | RPTA17 | RPTA16 |
1520 \----------|----------|----------|----------|----------|----------|----------|---------*/
1521 #define STV_VDP2_RPTAU (m_vdp2_regs[0x0bc/2] & 7)
1522
1523 /* 1800be - RPTAL - Rotation Parameter Table Address (Rotation Parameter A,B)
1524 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1525 | RPTA15 | RPTA14 | RPTA13 | RPTA12 | RPTA11 | RPTA10 | RPTA9 | RPTA8 |
1526 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1527 | RPTA7 | RPTA6 | RPTA5 | RPTA4 | RPTA3 | RPTA2 | RPTA1 | -- |
1528 \----------|----------|----------|----------|----------|----------|----------|---------*/
1529
1530 #define STV_VDP2_RPTAL (m_vdp2_regs[0x0be/2] & 0x0000ffff)
1531
1532 /* 1800c0 - Window Position (W0, Horizontal Start Point)
1533 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1534 | -- | -- | -- | -- | -- | -- | -- | -- |
1535 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1536 | -- | -- | -- | -- | -- | -- | -- | -- |
1537 \----------|----------|----------|----------|----------|----------|----------|---------*/
1538
1539 #define STV_VDP2_WPSX0 (m_vdp2_regs[0x0c0/2])
1540
1541 #define STV_VDP2_W0SX ((STV_VDP2_WPSX0 & 0x03ff) >> 0)
1542
1543 /* 1800c2 - Window Position (W0, Vertical Start Point)
1544 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1545 | -- | -- | -- | -- | -- | -- | -- | -- |
1546 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1547 | -- | -- | -- | -- | -- | -- | -- | -- |
1548 \----------|----------|----------|----------|----------|----------|----------|---------*/
1549
1550 #define STV_VDP2_WPSY0 (m_vdp2_regs[0x0c2/2])
1551
1552 #define STV_VDP2_W0SY ((STV_VDP2_WPSY0 & 0x07ff) >> 0)
1553
1554 /* 1800c4 - Window Position (W0, Horizontal End Point)
1555 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1556 | -- | -- | -- | -- | -- | -- | -- | -- |
1557 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1558 | -- | -- | -- | -- | -- | -- | -- | -- |
1559 \----------|----------|----------|----------|----------|----------|----------|---------*/
1560
1561 #define STV_VDP2_WPEX0 (m_vdp2_regs[0x0c4/2])
1562
1563 #define STV_VDP2_W0EX ((STV_VDP2_WPEX0 & 0x03ff) >> 0)
1564
1565 /* 1800c6 - Window Position (W0, Vertical End Point)
1566 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1567 | -- | -- | -- | -- | -- | -- | -- | -- |
1568 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1569 | -- | -- | -- | -- | -- | -- | -- | -- |
1570 \----------|----------|----------|----------|----------|----------|----------|---------*/
1571
1572 #define STV_VDP2_WPEY0 (m_vdp2_regs[0x0c6/2])
1573
1574 #define STV_VDP2_W0EY ((STV_VDP2_WPEY0 & 0x07ff) >> 0)
1575
1576 /* 1800c8 - Window Position (W1, Horizontal Start Point)
1577 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1578 | -- | -- | -- | -- | -- | -- | -- | -- |
1579 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1580 | -- | -- | -- | -- | -- | -- | -- | -- |
1581 \----------|----------|----------|----------|----------|----------|----------|---------*/
1582
1583 #define STV_VDP2_WPSX1 (m_vdp2_regs[0x0c8/2])
1584
1585 #define STV_VDP2_W1SX ((STV_VDP2_WPSX1 & 0x03ff) >> 0)
1586
1587 /* 1800ca - Window Position (W1, Vertical Start Point)
1588 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1589 | -- | -- | -- | -- | -- | -- | -- | -- |
1590 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1591 | -- | -- | -- | -- | -- | -- | -- | -- |
1592 \----------|----------|----------|----------|----------|----------|----------|---------*/
1593
1594 #define STV_VDP2_WPSY1 (m_vdp2_regs[0x0ca/2])
1595
1596 #define STV_VDP2_W1SY ((STV_VDP2_WPSY1 & 0x07ff) >> 0)
1597
1598 /* 1800cc - Window Position (W1, Horizontal End Point)
1599 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1600 | -- | -- | -- | -- | -- | -- | -- | -- |
1601 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1602 | -- | -- | -- | -- | -- | -- | -- | -- |
1603 \----------|----------|----------|----------|----------|----------|----------|---------*/
1604
1605 #define STV_VDP2_WPEX1 (m_vdp2_regs[0x0cc/2])
1606
1607 #define STV_VDP2_W1EX ((STV_VDP2_WPEX1 & 0x03ff) >> 0)
1608
1609 /* 1800ce - Window Position (W1, Vertical End Point)
1610 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1611 | -- | -- | -- | -- | -- | -- | -- | -- |
1612 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1613 | -- | -- | -- | -- | -- | -- | -- | -- |
1614 \----------|----------|----------|----------|----------|----------|----------|---------*/
1615
1616 #define STV_VDP2_WPEY1 (m_vdp2_regs[0x0ce/2])
1617
1618 #define STV_VDP2_W1EY ((STV_VDP2_WPEY1 & 0x07ff) >> 0)
1619
1620 /* 1800d0 - Window Control (NBG0, NBG1)
1621 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1622 | -- | -- | -- | -- | -- | -- | -- | -- |
1623 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1624 | -- | -- | -- | -- | -- | -- | -- | -- |
1625 \----------|----------|----------|----------|----------|----------|----------|---------*/
1626
1627 #define STV_VDP2_WCTLA (m_vdp2_regs[0x0d0/2])
1628 #define STV_VDP2_N1LOG ((STV_VDP2_WCTLA & 0x8000) >> 15)
1629 #define STV_VDP2_N1SWE ((STV_VDP2_WCTLA & 0x2000) >> 13)
1630 #define STV_VDP2_N1SWA ((STV_VDP2_WCTLA & 0x1000) >> 12)
1631 #define STV_VDP2_N1W1E ((STV_VDP2_WCTLA & 0x0800) >> 11)
1632 #define STV_VDP2_N1W1A ((STV_VDP2_WCTLA & 0x0400) >> 10)
1633 #define STV_VDP2_N1W0E ((STV_VDP2_WCTLA & 0x0200) >> 9)
1634 #define STV_VDP2_N1W0A ((STV_VDP2_WCTLA & 0x0100) >> 8)
1635 #define STV_VDP2_N0LOG ((STV_VDP2_WCTLA & 0x0080) >> 7)
1636 #define STV_VDP2_N0SWE ((STV_VDP2_WCTLA & 0x0020) >> 5)
1637 #define STV_VDP2_N0SWA ((STV_VDP2_WCTLA & 0x0010) >> 4)
1638 #define STV_VDP2_N0W1E ((STV_VDP2_WCTLA & 0x0008) >> 3)
1639 #define STV_VDP2_N0W1A ((STV_VDP2_WCTLA & 0x0004) >> 2)
1640 #define STV_VDP2_N0W0E ((STV_VDP2_WCTLA & 0x0002) >> 1)
1641 #define STV_VDP2_N0W0A ((STV_VDP2_WCTLA & 0x0001) >> 0)
1642
1643 /* 1800d2 - Window Control (NBG2, NBG3)
1644 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1645 | -- | -- | -- | -- | -- | -- | -- | -- |
1646 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1647 | -- | -- | -- | -- | -- | -- | -- | -- |
1648 \----------|----------|----------|----------|----------|----------|----------|---------*/
1649
1650 #define STV_VDP2_WCTLB (m_vdp2_regs[0x0d2/2])
1651 #define STV_VDP2_N3LOG ((STV_VDP2_WCTLB & 0x8000) >> 15)
1652 #define STV_VDP2_N3SWE ((STV_VDP2_WCTLB & 0x2000) >> 13)
1653 #define STV_VDP2_N3SWA ((STV_VDP2_WCTLB & 0x1000) >> 12)
1654 #define STV_VDP2_N3W1E ((STV_VDP2_WCTLB & 0x0800) >> 11)
1655 #define STV_VDP2_N3W1A ((STV_VDP2_WCTLB & 0x0400) >> 10)
1656 #define STV_VDP2_N3W0E ((STV_VDP2_WCTLB & 0x0200) >> 9)
1657 #define STV_VDP2_N3W0A ((STV_VDP2_WCTLB & 0x0100) >> 8)
1658 #define STV_VDP2_N2LOG ((STV_VDP2_WCTLB & 0x0080) >> 7)
1659 #define STV_VDP2_N2SWE ((STV_VDP2_WCTLB & 0x0020) >> 5)
1660 #define STV_VDP2_N2SWA ((STV_VDP2_WCTLB & 0x0010) >> 4)
1661 #define STV_VDP2_N2W1E ((STV_VDP2_WCTLB & 0x0008) >> 3)
1662 #define STV_VDP2_N2W1A ((STV_VDP2_WCTLB & 0x0004) >> 2)
1663 #define STV_VDP2_N2W0E ((STV_VDP2_WCTLB & 0x0002) >> 1)
1664 #define STV_VDP2_N2W0A ((STV_VDP2_WCTLB & 0x0001) >> 0)
1665
1666 /* 1800d4 - Window Control (RBG0, Sprite)
1667 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1668 | -- | -- | -- | -- | -- | -- | -- | -- |
1669 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1670 | -- | -- | -- | -- | -- | -- | -- | -- |
1671 \----------|----------|----------|----------|----------|----------|----------|---------*/
1672
1673 #define STV_VDP2_WCTLC (m_vdp2_regs[0x0d4/2])
1674 #define STV_VDP2_SPLOG ((STV_VDP2_WCTLC & 0x8000) >> 15)
1675 #define STV_VDP2_SPSWE ((STV_VDP2_WCTLC & 0x2000) >> 13)
1676 #define STV_VDP2_SPSWA ((STV_VDP2_WCTLC & 0x1000) >> 12)
1677 #define STV_VDP2_SPW1E ((STV_VDP2_WCTLC & 0x0800) >> 11)
1678 #define STV_VDP2_SPW1A ((STV_VDP2_WCTLC & 0x0400) >> 10)
1679 #define STV_VDP2_SPW0E ((STV_VDP2_WCTLC & 0x0200) >> 9)
1680 #define STV_VDP2_SPW0A ((STV_VDP2_WCTLC & 0x0100) >> 8)
1681 #define STV_VDP2_R0LOG ((STV_VDP2_WCTLC & 0x0080) >> 7)
1682 #define STV_VDP2_R0SWE ((STV_VDP2_WCTLC & 0x0020) >> 5)
1683 #define STV_VDP2_R0SWA ((STV_VDP2_WCTLC & 0x0010) >> 4)
1684 #define STV_VDP2_R0W1E ((STV_VDP2_WCTLC & 0x0008) >> 3)
1685 #define STV_VDP2_R0W1A ((STV_VDP2_WCTLC & 0x0004) >> 2)
1686 #define STV_VDP2_R0W0E ((STV_VDP2_WCTLC & 0x0002) >> 1)
1687 #define STV_VDP2_R0W0A ((STV_VDP2_WCTLC & 0x0001) >> 0)
1688
1689 /* 1800d6 - Window Control (Parameter Window, Colour Calc. Window)
1690 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1691 | -- | -- | -- | -- | -- | -- | -- | -- |
1692 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1693 | -- | -- | -- | -- | -- | -- | -- | -- |
1694 \----------|----------|----------|----------|----------|----------|----------|---------*/
1695
1696 #define STV_VDP2_WCTLD (m_vdp2_regs[0x0d6/2])
1697 #define STV_VDP2_CCLOG ((STV_VDP2_WCTLD & 0x8000) >> 15)
1698 #define STV_VDP2_CCSWE ((STV_VDP2_WCTLD & 0x2000) >> 13)
1699 #define STV_VDP2_CCSWA ((STV_VDP2_WCTLD & 0x1000) >> 12)
1700 #define STV_VDP2_CCW1E ((STV_VDP2_WCTLD & 0x0800) >> 11)
1701 #define STV_VDP2_CCW1A ((STV_VDP2_WCTLD & 0x0400) >> 10)
1702 #define STV_VDP2_CCW0E ((STV_VDP2_WCTLD & 0x0200) >> 9)
1703 #define STV_VDP2_CCW0A ((STV_VDP2_WCTLD & 0x0100) >> 8)
1704 #define STV_VDP2_RPLOG ((STV_VDP2_WCTLD & 0x0080) >> 7)
1705 #define STV_VDP2_RPW1E ((STV_VDP2_WCTLD & 0x0008) >> 3)
1706 #define STV_VDP2_RPW1A ((STV_VDP2_WCTLD & 0x0004) >> 2)
1707 #define STV_VDP2_RPW0E ((STV_VDP2_WCTLD & 0x0002) >> 1)
1708 #define STV_VDP2_RPW0A ((STV_VDP2_WCTLD & 0x0001) >> 0)
1709
1710 /* 1800d8 - Line Window Table Address (W0)
1711 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1712 | -- | -- | -- | -- | -- | -- | -- | -- |
1713 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1714 | -- | -- | -- | -- | -- | -- | -- | -- |
1715 \----------|----------|----------|----------|----------|----------|----------|---------*/
1716
1717 #define STV_VDP2_LWTA0U (m_vdp2_regs[0x0d8/2])
1718
1719 #define STV_VDP2_W0LWE ((STV_VDP2_LWTA0U & 0x8000) >> 15)
1720
1721 /* 1800da - Line Window Table Address (W0)
1722 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1723 | -- | -- | -- | -- | -- | -- | -- | -- |
1724 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1725 | -- | -- | -- | -- | -- | -- | -- | -- |
1726 \----------|----------|----------|----------|----------|----------|----------|---------*/
1727
1728 #define STV_VDP2_LWTA0L (m_vdp2_regs[0x0da/2])
1729
1730 /* bit 19 isn't used when VRAM = 4 Mbit */
1731 #define STV_VDP2_W0LWTA (((STV_VDP2_LWTA0U & 0x0007) << 16) | (STV_VDP2_LWTA0L & 0xfffe))
1732
1733
1734 /* 1800dc - Line Window Table Address (W1)
1735 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1736 | -- | -- | -- | -- | -- | -- | -- | -- |
1737 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1738 | -- | -- | -- | -- | -- | -- | -- | -- |
1739 \----------|----------|----------|----------|----------|----------|----------|---------*/
1740
1741 #define STV_VDP2_LWTA1U (m_vdp2_regs[0x0dc/2])
1742
1743 #define STV_VDP2_W1LWE ((STV_VDP2_LWTA1U & 0x8000) >> 15)
1744
1745
1746 /* 1800de - Line Window Table Address (W1)
1747 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1748 | -- | -- | -- | -- | -- | -- | -- | -- |
1749 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1750 | -- | -- | -- | -- | -- | -- | -- | -- |
1751 \----------|----------|----------|----------|----------|----------|----------|---------*/
1752
1753 #define STV_VDP2_LWTA1L (m_vdp2_regs[0x0de/2])
1754
1755 /* bit 19 isn't used when VRAM = 4 Mbit */
1756 #define STV_VDP2_W1LWTA (((STV_VDP2_LWTA1U & 0x0007) << 16) | (STV_VDP2_LWTA1L & 0xfffe))
1757
1758
1759 /* 1800e0 - Sprite Control
1760 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1761 | -- | -- | SPCCCS1 | SPCCCS0 | -- | SPCCN2 | SPCCN1 | SPCCN0 |
1762 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1763 | -- | -- | SPCLMD | SPWINEN | SPTYPE3 | SPTYPE2 | SPTYPE1 | SPTYPE0 |
1764 \----------|----------|----------|----------|----------|----------|----------|---------*/
1765
1766 #define STV_VDP2_SPCTL (m_vdp2_regs[0x0e0/2])
1767 #define STV_VDP2_SPCCCS ((STV_VDP2_SPCTL & 0x3000) >> 12)
1768 #define STV_VDP2_SPCCN ((STV_VDP2_SPCTL & 0x700) >> 8)
1769 #define STV_VDP2_SPCLMD ((STV_VDP2_SPCTL & 0x20) >> 5)
1770 #define STV_VDP2_SPWINEN ((STV_VDP2_SPCTL & 0x10) >> 4)
1771 #define STV_VDP2_SPTYPE (STV_VDP2_SPCTL & 0xf)
1772
1773 /* 1800e2 - Shadow Control
1774 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1775 | -- | -- | -- | -- | -- | -- | -- | -- |
1776 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1777 | -- | -- | -- | -- | -- | -- | -- | -- |
1778 \----------|----------|----------|----------|----------|----------|----------|---------*/
1779
1780 #define STV_VDP2_SDCTL (m_vdp2_regs[0x0e2/2])
1781
1782 /* 1800e4 - CRAOFA - Colour Ram Address Offset (NBG0 - NBG3)
1783 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1784 | -- | N0CAOS2 | N3CAOS1 | N3CAOS0 | -- | N2CAOS2 | N2CAOS1 | N2CAOS0 |
1785 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1786 | -- | N1CAOS2 | N1CAOS1 | N1CAOS0 | -- | N0CAOS2 | N0CAOS1 | N0CAOS0 |
1787 \----------|----------|----------|----------|----------|----------|----------|---------*/
1788
1789 #define STV_VDP2_CRAOFA (m_vdp2_regs[0x0e4/2])
1790
1791 /* NxCAOS = */
1792 #define STV_VDP2_N0CAOS ((STV_VDP2_CRAOFA & 0x0007) >> 0)
1793 #define STV_VDP2_N1CAOS ((STV_VDP2_CRAOFA & 0x0070) >> 4)
1794 #define STV_VDP2_N2CAOS ((STV_VDP2_CRAOFA & 0x0700) >> 8)
1795 #define STV_VDP2_N3CAOS ((STV_VDP2_CRAOFA & 0x7000) >> 12)
1796
1797
1798 /* 1800e6 - Colour Ram Address Offset (RBG0, SPRITE)
1799 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1800 | -- | -- | -- | -- | -- | -- | -- | -- |
1801 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1802 | -- | -- | -- | -- | -- | -- | -- | -- |
1803 \----------|----------|----------|----------|----------|----------|----------|---------*/
1804 #define STV_VDP2_CRAOFB (m_vdp2_regs[0x0e6/2])
1805 #define STV_VDP2_R0CAOS ((STV_VDP2_CRAOFB & 0x0007) >> 0)
1806 #define STV_VDP2_SPCAOS ((STV_VDP2_CRAOFB & 0x0070) >> 4)
1807
1808 /* 1800e8 - LNCLEN - Line Colour Screen Enable
1809 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1810 | -- | -- | -- | -- | -- | -- | -- | -- |
1811 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1812 | -- | -- | SPLCEN | R0LCEN | N3LCEN | N2LCEN | N1LCEN | N0LCEN |
1813 \----------|----------|----------|----------|----------|----------|----------|---------*/
1814
1815 #define STV_VDP2_LNCLEN (m_vdp2_regs[0x0e8/2])
1816 #define STV_VDP2_SPLCEN ((STV_VDP2_LNCLEN & 0x0020) >> 5)
1817 #define STV_VDP2_R0LCEN ((STV_VDP2_LNCLEN & 0x0010) >> 4)
1818 #define STV_VDP2_N3LCEN ((STV_VDP2_LNCLEN & 0x0008) >> 3)
1819 #define STV_VDP2_N2LCEN ((STV_VDP2_LNCLEN & 0x0004) >> 2)
1820 #define STV_VDP2_N1LCEN ((STV_VDP2_LNCLEN & 0x0002) >> 1)
1821 #define STV_VDP2_N0LCEN ((STV_VDP2_LNCLEN & 0x0001) >> 0)
1822
1823 /* 1800ea - Special Priority Mode
1824 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1825 | -- | -- | -- | -- | -- | -- | -- | -- |
1826 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1827 | -- | -- | -- | -- | -- | -- | -- | -- |
1828 \----------|----------|----------|----------|----------|----------|----------|---------*/
1829
1830 #define STV_VDP2_SFPRMD (m_vdp2_regs[0x0ea/2])
1831
1832
1833 /* 1800ec - Colour Calculation Control
1834 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1835 | BOKEN | BOKN2 | BOKN1 | BOKN0 | -- | EXCCEN | CCRTMD | CCMD |
1836 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1837 | -- | SPCCEN | LCCCEN | R0CCEN | N3CCEN | N2CCEN | N1CCEN | N0CCEN |
1838 \----------|----------|----------|----------|----------|----------|----------|---------*/
1839
1840 #define STV_VDP2_CCCR (m_vdp2_regs[0x0ec/2])
1841 #define STV_VDP2_CCMD ((STV_VDP2_CCCR & 0x100) >> 8)
1842 #define STV_VDP2_SPCCEN ((STV_VDP2_CCCR & 0x40) >> 6)
1843 #define STV_VDP2_LCCCEN ((STV_VDP2_CCCR & 0x20) >> 5)
1844 #define STV_VDP2_R0CCEN ((STV_VDP2_CCCR & 0x10) >> 4)
1845 #define STV_VDP2_N3CCEN ((STV_VDP2_CCCR & 0x8) >> 3)
1846 #define STV_VDP2_N2CCEN ((STV_VDP2_CCCR & 0x4) >> 2)
1847 #define STV_VDP2_N1CCEN ((STV_VDP2_CCCR & 0x2) >> 1)
1848 #define STV_VDP2_N0CCEN ((STV_VDP2_CCCR & 0x1) >> 0)
1849
1850
1851 /* 1800ee - Special Colour Calculation Mode
1852 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1853 | -- | -- | -- | -- | -- | -- | -- | -- |
1854 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1855 | -- | -- | -- | -- | -- | -- | -- | -- |
1856 \----------|----------|----------|----------|----------|----------|----------|---------*/
1857
1858 #define STV_VDP2_SFCCMD (m_vdp2_regs[0x0ee/2])
1859
1860 /* 1800f0 - Priority Number (Sprite 0,1)
1861 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1862 | -- | -- | -- | -- | -- | S1PRIN2 | S1PRIN1 | S1PRIN0 |
1863 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1864 | -- | -- | -- | -- | -- | S0PRIN2 | S0PRIN1 | S0PRIN0 |
1865 \----------|----------|----------|----------|----------|----------|----------|---------*/
1866
1867 #define STV_VDP2_PRISA (m_vdp2_regs[0x0f0/2])
1868 #define STV_VDP2_S1PRIN ((STV_VDP2_PRISA & 0x0700) >> 8)
1869 #define STV_VDP2_S0PRIN ((STV_VDP2_PRISA & 0x0007) >> 0)
1870
1871 /* 1800f2 - Priority Number (Sprite 2,3)
1872 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1873 | -- | -- | -- | -- | -- | S3PRIN2 | S3PRIN1 | S3PRIN0 |
1874 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1875 | -- | -- | -- | -- | -- | S2PRIN2 | S2PRIN1 | S2PRIN0 |
1876 \----------|----------|----------|----------|----------|----------|----------|---------*/
1877
1878 #define STV_VDP2_PRISB (m_vdp2_regs[0x0f2/2])
1879 #define STV_VDP2_S3PRIN ((STV_VDP2_PRISB & 0x0700) >> 8)
1880 #define STV_VDP2_S2PRIN ((STV_VDP2_PRISB & 0x0007) >> 0)
1881
1882 /* 1800f4 - Priority Number (Sprite 4,5)
1883 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1884 | -- | -- | -- | -- | -- | S5PRIN2 | S5PRIN1 | S5PRIN0 |
1885 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1886 | -- | -- | -- | -- | -- | S4PRIN2 | S4PRIN1 | S4PRIN0 |
1887 \----------|----------|----------|----------|----------|----------|----------|---------*/
1888
1889 #define STV_VDP2_PRISC (m_vdp2_regs[0x0f4/2])
1890 #define STV_VDP2_S5PRIN ((STV_VDP2_PRISC & 0x0700) >> 8)
1891 #define STV_VDP2_S4PRIN ((STV_VDP2_PRISC & 0x0007) >> 0)
1892
1893 /* 1800f6 - Priority Number (Sprite 6,7)
1894 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1895 | -- | -- | -- | -- | -- | S7PRIN2 | S7PRIN1 | S7PRIN0 |
1896 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1897 | -- | -- | -- | -- | -- | S6PRIN2 | S6PRIN1 | S6PRIN0 |
1898 \----------|----------|----------|----------|----------|----------|----------|---------*/
1899
1900 #define STV_VDP2_PRISD (m_vdp2_regs[0x0f6/2])
1901 #define STV_VDP2_S7PRIN ((STV_VDP2_PRISD & 0x0700) >> 8)
1902 #define STV_VDP2_S6PRIN ((STV_VDP2_PRISD & 0x0007) >> 0)
1903
1904
1905 /* 1800f8 - PRINA - Priority Number (NBG 0,1)
1906 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1907 | -- | -- | -- | -- | -- | -- | -- | -- |
1908 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1909 | -- | -- | -- | -- | -- | -- | -- | -- |
1910 \----------|----------|----------|----------|----------|----------|----------|---------*/
1911
1912 #define STV_VDP2_PRINA (m_vdp2_regs[0x0f8/2])
1913
1914 #define STV_VDP2_N1PRIN ((STV_VDP2_PRINA & 0x0700) >> 8)
1915 #define STV_VDP2_N0PRIN ((STV_VDP2_PRINA & 0x0007) >> 0)
1916
1917 /* 1800fa - PRINB - Priority Number (NBG 2,3)
1918 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1919 | -- | -- | -- | -- | -- | -- | -- | -- |
1920 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1921 | -- | -- | -- | -- | -- | -- | -- | -- |
1922 \----------|----------|----------|----------|----------|----------|----------|---------*/
1923
1924 #define STV_VDP2_PRINB (m_vdp2_regs[0x0fa/2])
1925
1926 #define STV_VDP2_N3PRIN ((STV_VDP2_PRINB & 0x0700) >> 8)
1927 #define STV_VDP2_N2PRIN ((STV_VDP2_PRINB & 0x0007) >> 0)
1928
1929 /* 1800fc - Priority Number (RBG0)
1930 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1931 | -- | -- | -- | -- | -- | -- | -- | -- |
1932 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1933 | -- | -- | -- | -- | -- | -- | -- | -- |
1934 \----------|----------|----------|----------|----------|----------|----------|---------*/
1935 #define STV_VDP2_PRIR (m_vdp2_regs[0x0fc/2])
1936
1937 #define STV_VDP2_R0PRIN ((STV_VDP2_PRIR & 0x0007) >> 0)
1938
1939 /* 1800fe - Reserved
1940 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1941 | -- | -- | -- | -- | -- | -- | -- | -- |
1942 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1943 | -- | -- | -- | -- | -- | -- | -- | -- |
1944 \----------|----------|----------|----------|----------|----------|----------|---------*/
1945
1946 /* 180100 - Colour Calculation Ratio (Sprite 0,1)
1947 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1948 | -- | -- | -- | S1CCRT4 | S1CCRT3 | S1CCRT2 | S1CCRT1 | S1CCRT0 |
1949 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1950 | -- | -- | -- | S0CCRT4 | S0CCRT3 | S0CCRT2 | S0CCRT1 | S0CCRT0 |
1951 \----------|----------|----------|----------|----------|----------|----------|---------*/
1952
1953 #define STV_VDP2_CCRSA (m_vdp2_regs[0x100/2])
1954 #define STV_VDP2_S1CCRT ((STV_VDP2_CCRSA & 0x1f00) >> 8)
1955 #define STV_VDP2_S0CCRT ((STV_VDP2_CCRSA & 0x001f) >> 0)
1956
1957 /* 180102 - Colour Calculation Ratio (Sprite 2,3)
1958 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1959 | -- | -- | -- | S3CCRT4 | S3CCRT3 | S3CCRT2 | S3CCRT1 | S3CCRT0 |
1960 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1961 | -- | -- | -- | S2CCRT4 | S2CCRT3 | S2CCRT2 | S2CCRT1 | S2CCRT0 |
1962 \----------|----------|----------|----------|----------|----------|----------|---------*/
1963
1964 #define STV_VDP2_CCRSB (m_vdp2_regs[0x102/2])
1965 #define STV_VDP2_S3CCRT ((STV_VDP2_CCRSB & 0x1f00) >> 8)
1966 #define STV_VDP2_S2CCRT ((STV_VDP2_CCRSB & 0x001f) >> 0)
1967
1968 /* 180104 - Colour Calculation Ratio (Sprite 4,5)
1969 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1970 | -- | -- | -- | S5CCRT4 | S5CCRT3 | S5CCRT2 | S5CCRT1 | S5CCRT0 |
1971 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1972 | -- | -- | -- | S4CCRT4 | S4CCRT3 | S4CCRT2 | S4CCRT1 | S4CCRT0 |
1973 \----------|----------|----------|----------|----------|----------|----------|---------*/
1974
1975 #define STV_VDP2_CCRSC (m_vdp2_regs[0x104/2])
1976 #define STV_VDP2_S5CCRT ((STV_VDP2_CCRSC & 0x1f00) >> 8)
1977 #define STV_VDP2_S4CCRT ((STV_VDP2_CCRSC & 0x001f) >> 0)
1978
1979 /* 180106 - Colour Calculation Ratio (Sprite 6,7)
1980 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1981 | -- | -- | -- | S7CCRT4 | S7CCRT3 | S7CCRT2 | S7CCRT1 | S7CCRT0 |
1982 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1983 | -- | -- | -- | S6CCRT4 | S6CCRT3 | S6CCRT2 | S6CCRT1 | S6CCRT0 |
1984 \----------|----------|----------|----------|----------|----------|----------|---------*/
1985
1986 #define STV_VDP2_CCRSD (m_vdp2_regs[0x106/2])
1987 #define STV_VDP2_S7CCRT ((STV_VDP2_CCRSD & 0x1f00) >> 8)
1988 #define STV_VDP2_S6CCRT ((STV_VDP2_CCRSD & 0x001f) >> 0)
1989
1990 /* 180108 - Colour Calculation Ratio (NBG 0,1)
1991 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
1992 | -- | -- | -- | N1CCRT4 | N1CCRT3 | N1CCRT2 | N1CCRT1 | N1CCRT0 |
1993 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
1994 | -- | -- | -- | N0CCRT4 | N0CCRT3 | N0CCRT2 | N0CCRT1 | N0CCRT0 |
1995 \----------|----------|----------|----------|----------|----------|----------|---------*/
1996
1997 #define STV_VDP2_CCRNA (m_vdp2_regs[0x108/2])
1998 #define STV_VDP2_N1CCRT ((STV_VDP2_CCRNA & 0x1f00) >> 8)
1999 #define STV_VDP2_N0CCRT (STV_VDP2_CCRNA & 0x1f)
2000
2001 /* 18010a - Colour Calculation Ratio (NBG 2,3)
2002 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2003 | -- | -- | -- | N3CCRT4 | N3CCRT3 | N3CCRT2 | N3CCRT1 | N3CCRT0 |
2004 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2005 | -- | -- | -- | N2CCRT4 | N2CCRT3 | N2CCRT2 | N2CCRT1 | N2CCRT0 |
2006 \----------|----------|----------|----------|----------|----------|----------|---------*/
2007
2008 #define STV_VDP2_CCRNB (m_vdp2_regs[0x10a/2])
2009 #define STV_VDP2_N3CCRT ((STV_VDP2_CCRNB & 0x1f00) >> 8)
2010 #define STV_VDP2_N2CCRT (STV_VDP2_CCRNB & 0x1f)
2011
2012 /* 18010c - Colour Calculation Ratio (RBG 0)
2013 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2014 | -- | -- | -- | -- | -- | -- | -- | -- |
2015 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2016 | -- | -- | -- | -- | -- | -- | -- | -- |
2017 \----------|----------|----------|----------|----------|----------|----------|---------*/
2018
2019 #define STV_VDP2_CCRR (m_vdp2_regs[0x10c/2])
2020 #define STV_VDP2_R0CCRT (STV_VDP2_CCRR & 0x1f)
2021
2022 /* 18010e - Colour Calculation Ratio (Line Colour Screen, Back Colour Screen)
2023 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2024 | -- | -- | -- | -- | -- | -- | -- | -- |
2025 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2026 | -- | -- | -- | -- | -- | -- | -- | -- |
2027 \----------|----------|----------|----------|----------|----------|----------|---------*/
2028
2029 #define STV_VDP2_CCRLB (m_vdp2_regs[0x10e/2])
2030
2031
2032 /* 180110 - Colour Offset Enable
2033 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2034 | -- | -- | -- | -- | -- | -- | -- | -- |
2035 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2036 | -- | -- | -- | -- | -- | -- | -- | -- |
2037 \----------|----------|----------|----------|----------|----------|----------|---------*/
2038
2039 #define STV_VDP2_CLOFEN (m_vdp2_regs[0x110/2])
2040 #define STV_VDP2_N0COEN ((STV_VDP2_CLOFEN & 0x01) >> 0)
2041 #define STV_VDP2_N1COEN ((STV_VDP2_CLOFEN & 0x02) >> 1)
2042 #define STV_VDP2_N2COEN ((STV_VDP2_CLOFEN & 0x04) >> 2)
2043 #define STV_VDP2_N3COEN ((STV_VDP2_CLOFEN & 0x08) >> 3)
2044 #define STV_VDP2_R0COEN ((STV_VDP2_CLOFEN & 0x10) >> 4)
2045 #define STV_VDP2_BKCOEN ((STV_VDP2_CLOFEN & 0x20) >> 5)
2046 #define STV_VDP2_SPCOEN ((STV_VDP2_CLOFEN & 0x40) >> 6)
2047
2048 /* 180112 - Colour Offset Select
2049 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2050 | -- | -- | -- | -- | -- | -- | -- | -- |
2051 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2052 | -- | -- | -- | -- | -- | -- | -- | -- |
2053 \----------|----------|----------|----------|----------|----------|----------|---------*/
2054
2055 #define STV_VDP2_CLOFSL (m_vdp2_regs[0x112/2])
2056 #define STV_VDP2_N0COSL ((STV_VDP2_CLOFSL & 0x01) >> 0)
2057 #define STV_VDP2_N1COSL ((STV_VDP2_CLOFSL & 0x02) >> 1)
2058 #define STV_VDP2_N2COSL ((STV_VDP2_CLOFSL & 0x04) >> 2)
2059 #define STV_VDP2_N3COSL ((STV_VDP2_CLOFSL & 0x08) >> 3)
2060 #define STV_VDP2_R0COSL ((STV_VDP2_CLOFSL & 0x10) >> 4)
2061 #define STV_VDP2_BKCOSL ((STV_VDP2_CLOFSL & 0x20) >> 5)
2062 #define STV_VDP2_SPCOSL ((STV_VDP2_CLOFSL & 0x40) >> 6)
2063
2064 /* 180114 - Colour Offset A (Red)
2065 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2066 | -- | -- | -- | -- | -- | -- | -- | -- |
2067 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2068 | -- | -- | -- | -- | -- | -- | -- | -- |
2069 \----------|----------|----------|----------|----------|----------|----------|---------*/
2070
2071 #define STV_VDP2_COAR (m_vdp2_regs[0x114/2])
2072
2073 /* 180116 - Colour Offset A (Green)
2074 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2075 | -- | -- | -- | -- | -- | -- | -- | -- |
2076 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2077 | -- | -- | -- | -- | -- | -- | -- | -- |
2078 \----------|----------|----------|----------|----------|----------|----------|---------*/
2079 #define STV_VDP2_COAG (m_vdp2_regs[0x116/2])
2080
2081 /* 180118 - Colour Offset A (Blue)
2082 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2083 | -- | -- | -- | -- | -- | -- | -- | -- |
2084 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2085 | -- | -- | -- | -- | -- | -- | -- | -- |
2086 \----------|----------|----------|----------|----------|----------|----------|---------*/
2087
2088 #define STV_VDP2_COAB (m_vdp2_regs[0x118/2])
2089
2090 /* 18011a - Colour Offset B (Red)
2091 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2092 | -- | -- | -- | -- | -- | -- | -- | -- |
2093 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2094 | -- | -- | -- | -- | -- | -- | -- | -- |
2095 \----------|----------|----------|----------|----------|----------|----------|---------*/
2096 #define STV_VDP2_COBR (m_vdp2_regs[0x11a/2])
2097
2098 /* 18011c - Colour Offset B (Green)
2099 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2100 | -- | -- | -- | -- | -- | -- | -- | -- |
2101 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2102 | -- | -- | -- | -- | -- | -- | -- | -- |
2103 \----------|----------|----------|----------|----------|----------|----------|---------*/
2104 #define STV_VDP2_COBG (m_vdp2_regs[0x11c/2])
2105
2106 /* 18011e - Colour Offset B (Blue)
2107 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
2108 | -- | -- | -- | -- | -- | -- | -- | -- |
2109 |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
2110 | -- | -- | -- | -- | -- | -- | -- | -- |
2111 \----------|----------|----------|----------|----------|----------|----------|---------*/
2112 #define STV_VDP2_COBB (m_vdp2_regs[0x11e/2])
2113
2114
2115 #define STV_VDP2_RBG_ROTATION_PARAMETER_A 1
2116 #define STV_VDP2_RBG_ROTATION_PARAMETER_B 2
2117
2118
2119 #define mul_fixed32( a, b ) mul_32x32_shift( a, b, 16 )
2120
stv_vdp2_fill_rotation_parameter_table(uint8_t rot_parameter)2121 void saturn_state::stv_vdp2_fill_rotation_parameter_table( uint8_t rot_parameter )
2122 {
2123 uint32_t address;
2124
2125 address = (((STV_VDP2_RPTAU << 16) | STV_VDP2_RPTAL) << 1);
2126 if ( rot_parameter == 1 )
2127 {
2128 address &= ~0x00000080;
2129 }
2130 else if ( rot_parameter == 2 )
2131 {
2132 address |= 0x00000080;
2133 }
2134
2135 stv_current_rotation_parameter_table.xst = (m_vdp2_vram[address/4] & 0x1fffffc0) | ((m_vdp2_vram[address/4] & 0x10000000) ? 0xe0000000 : 0x00000000 );
2136 stv_current_rotation_parameter_table.yst = (m_vdp2_vram[address/4 + 1] & 0x1fffffc0) | ((m_vdp2_vram[address/4 + 1] & 0x10000000) ? 0xe0000000 : 0x00000000 );
2137 stv_current_rotation_parameter_table.zst = (m_vdp2_vram[address/4 + 2] & 0x1fffffc0) | ((m_vdp2_vram[address/4 + 2] & 0x10000000) ? 0xe0000000 : 0x00000000 );
2138 stv_current_rotation_parameter_table.dxst = (m_vdp2_vram[address/4 + 3] & 0x0007ffc0) | ((m_vdp2_vram[address/4 + 3] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2139 stv_current_rotation_parameter_table.dyst = (m_vdp2_vram[address/4 + 4] & 0x0007ffc0) | ((m_vdp2_vram[address/4 + 4] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2140 stv_current_rotation_parameter_table.dx = (m_vdp2_vram[address/4 + 5] & 0x0007ffc0) | ((m_vdp2_vram[address/4 + 5] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2141 stv_current_rotation_parameter_table.dy = (m_vdp2_vram[address/4 + 6] & 0x0007ffc0) | ((m_vdp2_vram[address/4 + 6] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2142 stv_current_rotation_parameter_table.A = (m_vdp2_vram[address/4 + 7] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 7] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2143 stv_current_rotation_parameter_table.B = (m_vdp2_vram[address/4 + 8] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 8] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2144 stv_current_rotation_parameter_table.C = (m_vdp2_vram[address/4 + 9] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 9] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2145 stv_current_rotation_parameter_table.D = (m_vdp2_vram[address/4 + 10] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 10] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2146 stv_current_rotation_parameter_table.E = (m_vdp2_vram[address/4 + 11] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 11] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2147 stv_current_rotation_parameter_table.F = (m_vdp2_vram[address/4 + 12] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 12] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2148 stv_current_rotation_parameter_table.px = (m_vdp2_vram[address/4 + 13] & 0x3fff0000) | ((m_vdp2_vram[address/4 + 13] & 0x30000000) ? 0xc0000000 : 0x00000000 );
2149 stv_current_rotation_parameter_table.py = (m_vdp2_vram[address/4 + 13] & 0x00003fff) << 16;
2150 if ( stv_current_rotation_parameter_table.py & 0x20000000 ) stv_current_rotation_parameter_table.py |= 0xc0000000;
2151 stv_current_rotation_parameter_table.pz = (m_vdp2_vram[address/4 + 14] & 0x3fff0000) | ((m_vdp2_vram[address/4 + 14] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2152 stv_current_rotation_parameter_table.cx = (m_vdp2_vram[address/4 + 15] & 0x3fff0000) | ((m_vdp2_vram[address/4 + 15] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2153 stv_current_rotation_parameter_table.cy = (m_vdp2_vram[address/4 + 15] & 0x00003fff) << 16;
2154 if ( stv_current_rotation_parameter_table.cy & 0x20000000 ) stv_current_rotation_parameter_table.cy |= 0xc0000000;
2155 stv_current_rotation_parameter_table.cz = (m_vdp2_vram[address/4 + 16] & 0x3fff0000) | ((m_vdp2_vram[address/4 + 16] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2156 stv_current_rotation_parameter_table.mx = (m_vdp2_vram[address/4 + 17] & 0x3fffffc0) | ((m_vdp2_vram[address/4 + 17] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2157 stv_current_rotation_parameter_table.my = (m_vdp2_vram[address/4 + 18] & 0x3fffffc0) | ((m_vdp2_vram[address/4 + 18] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2158 stv_current_rotation_parameter_table.kx = (m_vdp2_vram[address/4 + 19] & 0x00ffffff) | ((m_vdp2_vram[address/4 + 19] & 0x00800000) ? 0xff000000 : 0x00000000 );
2159 stv_current_rotation_parameter_table.ky = (m_vdp2_vram[address/4 + 20] & 0x00ffffff) | ((m_vdp2_vram[address/4 + 20] & 0x00800000) ? 0xff000000 : 0x00000000 );
2160 stv_current_rotation_parameter_table.kast = (m_vdp2_vram[address/4 + 21] & 0xffffffc0);
2161 stv_current_rotation_parameter_table.dkast= (m_vdp2_vram[address/4 + 22] & 0x03ffffc0) | ((m_vdp2_vram[address/4 + 22] & 0x02000000) ? 0xfc000000 : 0x00000000 );
2162 stv_current_rotation_parameter_table.dkax = (m_vdp2_vram[address/4 + 23] & 0x03ffffc0) | ((m_vdp2_vram[address/4 + 23] & 0x02000000) ? 0xfc000000 : 0x00000000 );
2163
2164 // check rotation parameter read control, override if specific bits are disabled
2165 // (Batman Forever The Riddler stage relies on this)
2166 switch(rot_parameter)
2167 {
2168 case 1:
2169 // TODO: disable read control if these undocumented bits are on (Radiant Silvergun Xiga final boss)
2170 if(!STV_VDP2_RAUNK)
2171 {
2172 if(!STV_VDP2_RAXSTRE)
2173 stv_current_rotation_parameter_table.xst = 0;
2174
2175 if(!STV_VDP2_RAYSTRE)
2176 stv_current_rotation_parameter_table.yst = 0;
2177
2178 if(!STV_VDP2_RAKASTRE)
2179 stv_current_rotation_parameter_table.dkax = 0;
2180 }
2181 break;
2182 case 2:
2183 // same as above
2184 if(!STV_VDP2_RBUNK)
2185 {
2186 if(!STV_VDP2_RBXSTRE)
2187 stv_current_rotation_parameter_table.xst = 0;
2188
2189 if(!STV_VDP2_RBYSTRE)
2190 stv_current_rotation_parameter_table.yst = 0;
2191
2192 if(!STV_VDP2_RBKASTRE)
2193 stv_current_rotation_parameter_table.dkax = 0;
2194 }
2195 break;
2196 }
2197
2198 #define RP stv_current_rotation_parameter_table
2199
2200 if(LOG_ROZ == 1) logerror( "Rotation parameter table (%d)\n", rot_parameter );
2201 if(LOG_ROZ == 1) logerror( "xst = %x, yst = %x, zst = %x\n", RP.xst, RP.yst, RP.zst );
2202 if(LOG_ROZ == 1) logerror( "dxst = %x, dyst = %x\n", RP.dxst, RP.dyst );
2203 if(LOG_ROZ == 1) logerror( "dx = %x, dy = %x\n", RP.dx, RP.dy );
2204 if(LOG_ROZ == 1) logerror( "A = %x, B = %x, C = %x, D = %x, E = %x, F = %x\n", RP.A, RP.B, RP.C, RP.D, RP.E, RP.F );
2205 if(LOG_ROZ == 1) logerror( "px = %x, py = %x, pz = %x\n", RP.px, RP.py, RP.pz );
2206 if(LOG_ROZ == 1) logerror( "cx = %x, cy = %x, cz = %x\n", RP.cx, RP.cy, RP.cz );
2207 if(LOG_ROZ == 1) logerror( "mx = %x, my = %x\n", RP.mx, RP.my );
2208 if(LOG_ROZ == 1) logerror( "kx = %x, ky = %x\n", RP.kx, RP.ky );
2209 if(LOG_ROZ == 1) logerror( "kast = %x, dkast = %x, dkax = %x\n", RP.kast, RP.dkast, RP.dkax );
2210
2211 /*Attempt to show on screen the rotation table*/
2212 #if 0
2213 if(LOG_ROZ == 2)
2214 {
2215 if(machine().input().code_pressed_once(JOYCODE_Y_UP_SWITCH))
2216 m_vdpdebug_roz++;
2217
2218 if(machine().input().code_pressed_once(JOYCODE_Y_DOWN_SWITCH))
2219 m_vdpdebug_roz--;
2220
2221 if(m_vdpdebug_roz > 10)
2222 m_vdpdebug_roz = 10;
2223
2224 switch(m_vdpdebug_roz)
2225 {
2226 case 0: popmessage( "Rotation parameter Table (%d)", rot_parameter ); break;
2227 case 1: popmessage( "xst = %x, yst = %x, zst = %x", RP.xst, RP.yst, RP.zst ); break;
2228 case 2: popmessage( "dxst = %x, dyst = %x", RP.dxst, RP.dyst ); break;
2229 case 3: popmessage( "dx = %x, dy = %x", RP.dx, RP.dy ); break;
2230 case 4: popmessage( "A = %x, B = %x, C = %x, D = %x, E = %x, F = %x", RP.A, RP.B, RP.C, RP.D, RP.E, RP.F ); break;
2231 case 5: popmessage( "px = %x, py = %x, pz = %x", RP.px, RP.py, RP.pz ); break;
2232 case 6: popmessage( "cx = %x, cy = %x, cz = %x", RP.cx, RP.cy, RP.cz ); break;
2233 case 7: popmessage( "mx = %x, my = %x", RP.mx, RP.my ); break;
2234 case 8: popmessage( "kx = %x, ky = %x", RP.kx, RP.ky ); break;
2235 case 9: popmessage( "kast = %x, dkast = %x, dkax = %x", RP.kast, RP.dkast, RP.dkax ); break;
2236 case 10: break;
2237 }
2238 }
2239 #endif
2240 }
2241
2242 /* check if RGB layer has rotation applied */
stv_vdp2_is_rotation_applied(void)2243 uint8_t saturn_state::stv_vdp2_is_rotation_applied(void)
2244 {
2245 #define _FIXED_1 (0x00010000)
2246 #define _FIXED_0 (0x00000000)
2247
2248 if ( RP.A == _FIXED_1 &&
2249 RP.B == _FIXED_0 &&
2250 RP.C == _FIXED_0 &&
2251 RP.D == _FIXED_0 &&
2252 RP.E == _FIXED_1 &&
2253 RP.F == _FIXED_0 &&
2254 RP.dxst == _FIXED_0 &&
2255 RP.dyst == _FIXED_1 &&
2256 RP.dx == _FIXED_1 &&
2257 RP.dy == _FIXED_0 &&
2258 RP.kx == _FIXED_1 &&
2259 RP.ky == _FIXED_1 &&
2260 STV_VDP2_RPMD < 2) // disable optimizations if roz mode is 2 or 3
2261 {
2262 return 0;
2263 }
2264 else
2265 {
2266 return 1;
2267 }
2268 }
2269
stv_vdp2_are_map_registers_equal(void)2270 uint8_t saturn_state::stv_vdp2_are_map_registers_equal(void)
2271 {
2272 int i;
2273
2274 for ( i = 1; i < stv2_current_tilemap.map_count; i++ )
2275 {
2276 if ( stv2_current_tilemap.map_offset[i] != stv2_current_tilemap.map_offset[0] )
2277 {
2278 return 0;
2279 }
2280 }
2281 return 1;
2282 }
2283
stv_vdp2_check_fade_control_for_layer(void)2284 void saturn_state::stv_vdp2_check_fade_control_for_layer( void )
2285 {
2286 if ( stv2_current_tilemap.fade_control & 1 )
2287 {
2288 if ( stv2_current_tilemap.fade_control & 2 )
2289 {
2290 if ((STV_VDP2_COBR & 0x1ff) == 0 &&
2291 (STV_VDP2_COBG & 0x1ff) == 0 &&
2292 (STV_VDP2_COBB & 0x1ff) == 0 )
2293 {
2294 stv2_current_tilemap.fade_control = 0;
2295 }
2296 }
2297 else
2298 {
2299 if ((STV_VDP2_COAR & 0x1ff) == 0 &&
2300 (STV_VDP2_COAG & 0x1ff) == 0 &&
2301 (STV_VDP2_COAB & 0x1ff) == 0 )
2302 {
2303 stv2_current_tilemap.fade_control = 0;
2304 }
2305 }
2306 }
2307 }
2308
2309 #define STV_VDP2_CP_NBG0_PNMDR 0x0
2310 #define STV_VDP2_CP_NBG1_PNMDR 0x1
2311 #define STV_VDP2_CP_NBG2_PNMDR 0x2
2312 #define STV_VDP2_CP_NBG3_PNMDR 0x3
2313 #define STV_VDP2_CP_NBG0_CPDR 0x4
2314 #define STV_VDP2_CP_NBG1_CPDR 0x5
2315 #define STV_VDP2_CP_NBG2_CPDR 0x6
2316 #define STV_VDP2_CP_NBG3_CPDR 0x7
2317
stv_vdp2_check_vram_cycle_pattern_registers(uint8_t access_command_pnmdr,uint8_t access_command_cpdr,uint8_t bitmap_enable)2318 uint8_t saturn_state::stv_vdp2_check_vram_cycle_pattern_registers( uint8_t access_command_pnmdr, uint8_t access_command_cpdr, uint8_t bitmap_enable )
2319 {
2320 int i;
2321 uint8_t access_command_ok = 0;
2322 uint16_t cp_regs[8];
2323 cp_regs[0] = STV_VDP2_CYCA0L;
2324 cp_regs[1] = STV_VDP2_CYCA0U;
2325 cp_regs[2] = STV_VDP2_CYCA1L;
2326 cp_regs[3] = STV_VDP2_CYCA1U;
2327 cp_regs[4] = STV_VDP2_CYCA2L;
2328 cp_regs[5] = STV_VDP2_CYCA2U;
2329 cp_regs[6] = STV_VDP2_CYCA3L;
2330 cp_regs[7] = STV_VDP2_CYCA3U;
2331
2332 if ( bitmap_enable ) access_command_ok = 1;
2333
2334 for ( i = 0; i < 8; i++ )
2335 {
2336 if ( ((cp_regs[i] >> 12) & 0xf) == access_command_pnmdr )
2337 {
2338 access_command_ok |= 1;
2339 }
2340 if ( ((cp_regs[i] >> 12) & 0xf) == access_command_cpdr )
2341 {
2342 access_command_ok |= 2;
2343 }
2344 if ( ((cp_regs[i] >> 8) & 0xf) == access_command_pnmdr )
2345 {
2346 access_command_ok |= 1;
2347 }
2348 if ( ((cp_regs[i] >> 8) & 0xf) == access_command_cpdr )
2349 {
2350 access_command_ok |= 2;
2351 }
2352 if ( ((cp_regs[i] >> 4) & 0xf) == access_command_pnmdr )
2353 {
2354 access_command_ok |= 1;
2355 }
2356 if ( ((cp_regs[i] >> 4) & 0xf) == access_command_cpdr )
2357 {
2358 access_command_ok |= 2;
2359 }
2360 if ( ((cp_regs[i] >> 0) & 0xf) == access_command_pnmdr )
2361 {
2362 access_command_ok |= 1;
2363 }
2364 if ( ((cp_regs[i] >> 0) & 0xf) == access_command_cpdr )
2365 {
2366 access_command_ok |= 2;
2367 }
2368 }
2369 return access_command_ok == 3 ? 1 : 0;
2370 }
2371
2372
stv_vdp2_compute_color_offset(int * r,int * g,int * b,int cor)2373 void saturn_state::stv_vdp2_compute_color_offset( int *r, int *g, int *b, int cor )
2374 {
2375 if ( cor == 0 )
2376 {
2377 *r = (STV_VDP2_COAR & 0x100) ? (*r - (0x100 - (STV_VDP2_COAR & 0xff))) : ((STV_VDP2_COAR & 0xff) + *r);
2378 *g = (STV_VDP2_COAG & 0x100) ? (*g - (0x100 - (STV_VDP2_COAG & 0xff))) : ((STV_VDP2_COAG & 0xff) + *g);
2379 *b = (STV_VDP2_COAB & 0x100) ? (*b - (0x100 - (STV_VDP2_COAB & 0xff))) : ((STV_VDP2_COAB & 0xff) + *b);
2380 }
2381 else
2382 {
2383 *r = (STV_VDP2_COBR & 0x100) ? (*r - (0xff - (STV_VDP2_COBR & 0xff))) : ((STV_VDP2_COBR & 0xff) + *r);
2384 *g = (STV_VDP2_COBG & 0x100) ? (*g - (0xff - (STV_VDP2_COBG & 0xff))) : ((STV_VDP2_COBG & 0xff) + *g);
2385 *b = (STV_VDP2_COBB & 0x100) ? (*b - (0xff - (STV_VDP2_COBB & 0xff))) : ((STV_VDP2_COBB & 0xff) + *b);
2386 }
2387 if(*r < 0) { *r = 0; }
2388 if(*r > 0xff) { *r = 0xff; }
2389 if(*g < 0) { *g = 0; }
2390 if(*g > 0xff) { *g = 0xff; }
2391 if(*b < 0) { *b = 0; }
2392 if(*b > 0xff) { *b = 0xff; }
2393 }
2394
stv_vdp2_compute_color_offset_UINT32(rgb_t * rgb,int cor)2395 void saturn_state::stv_vdp2_compute_color_offset_UINT32(rgb_t *rgb, int cor)
2396 {
2397 int _r = rgb->r();
2398 int _g = rgb->g();
2399 int _b = rgb->b();
2400 if ( cor == 0 )
2401 {
2402 _r = (STV_VDP2_COAR & 0x100) ? (_r - (0x100 - (STV_VDP2_COAR & 0xff))) : ((STV_VDP2_COAR & 0xff) + _r);
2403 _g = (STV_VDP2_COAG & 0x100) ? (_g - (0x100 - (STV_VDP2_COAG & 0xff))) : ((STV_VDP2_COAG & 0xff) + _g);
2404 _b = (STV_VDP2_COAB & 0x100) ? (_b - (0x100 - (STV_VDP2_COAB & 0xff))) : ((STV_VDP2_COAB & 0xff) + _b);
2405 }
2406 else
2407 {
2408 _r = (STV_VDP2_COBR & 0x100) ? (_r - (0xff - (STV_VDP2_COBR & 0xff))) : ((STV_VDP2_COBR & 0xff) + _r);
2409 _g = (STV_VDP2_COBG & 0x100) ? (_g - (0xff - (STV_VDP2_COBG & 0xff))) : ((STV_VDP2_COBG & 0xff) + _g);
2410 _b = (STV_VDP2_COBB & 0x100) ? (_b - (0xff - (STV_VDP2_COBB & 0xff))) : ((STV_VDP2_COBB & 0xff) + _b);
2411 }
2412 if(_r < 0) { _r = 0; }
2413 if(_r > 0xff) { _r = 0xff; }
2414 if(_g < 0) { _g = 0; }
2415 if(_g > 0xff) { _g = 0xff; }
2416 if(_b < 0) { _b = 0; }
2417 if(_b > 0xff) { _b = 0xff; }
2418
2419 *rgb = rgb_t(_r, _g, _b);
2420 }
2421
stv_vdp2_drawgfxzoom(bitmap_rgb32 & dest_bmp,const rectangle & clip,gfx_element * gfx,uint32_t code,uint32_t color,int flipx,int flipy,int sx,int sy,int transparency,int scalex,int scaley,int sprite_screen_width,int sprite_screen_height,int alpha)2422 void saturn_state::stv_vdp2_drawgfxzoom(
2423 bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
2424 uint32_t code,uint32_t color,int flipx,int flipy,int sx,int sy,
2425 int transparency,int scalex, int scaley,
2426 int sprite_screen_width, int sprite_screen_height, int alpha)
2427 {
2428 rectangle myclip;
2429
2430 if (!scalex || !scaley) return;
2431
2432 if (gfx->has_pen_usage() && !(transparency & STV_TRANSPARENCY_NONE))
2433 {
2434 int transmask;
2435
2436 transmask = 1 << (0 & 0xff);
2437
2438 if ((gfx->pen_usage(code) & ~transmask) == 0)
2439 /* character is totally transparent, no need to draw */
2440 return;
2441 else if ((gfx->pen_usage(code) & transmask) == 0)
2442 /* character is totally opaque, can disable transparency */
2443 transparency |= STV_TRANSPARENCY_NONE;
2444 }
2445
2446 /*
2447 scalex and scaley are 16.16 fixed point numbers
2448 1<<15 : shrink to 50%
2449 1<<16 : uniform scale
2450 1<<17 : double to 200%
2451 */
2452
2453
2454 /* KW 991012 -- Added code to force clip to bitmap boundary */
2455 myclip = clip;
2456 myclip &= dest_bmp.cliprect();
2457
2458 if( gfx )
2459 {
2460 const pen_t *pal = &m_palette->pen(gfx->colorbase() + gfx->granularity() * (color % gfx->colors()));
2461 const uint8_t *source_base = gfx->get_data(code % gfx->elements());
2462
2463 //int sprite_screen_height = (scaley*gfx->height()+0x8000)>>16;
2464 //int sprite_screen_width = (scalex*gfx->width()+0x8000)>>16;
2465
2466 if (sprite_screen_width && sprite_screen_height)
2467 {
2468 /* compute sprite increment per screen pixel */
2469 //int dx = (gfx->width()<<16)/sprite_screen_width;
2470 //int dy = (gfx->height()<<16)/sprite_screen_height;
2471 int dx = stv2_current_tilemap.incx;
2472 int dy = stv2_current_tilemap.incy;
2473
2474 int ex = sx+sprite_screen_width;
2475 int ey = sy+sprite_screen_height;
2476
2477 int x_index_base;
2478 int y_index;
2479
2480 if( flipx )
2481 {
2482 x_index_base = (sprite_screen_width-1)*dx;
2483 dx = -dx;
2484 }
2485 else
2486 {
2487 x_index_base = 0;
2488 }
2489
2490 if( flipy )
2491 {
2492 y_index = (sprite_screen_height-1)*dy;
2493 dy = -dy;
2494 }
2495 else
2496 {
2497 y_index = 0;
2498 }
2499
2500 if( sx < myclip.left())
2501 { /* clip left */
2502 int pixels = myclip.left()-sx;
2503 sx += pixels;
2504 x_index_base += pixels*dx;
2505 }
2506 if( sy < myclip.top() )
2507 { /* clip top */
2508 int pixels = myclip.top()-sy;
2509 sy += pixels;
2510 y_index += pixels*dy;
2511 }
2512 /* NS 980211 - fixed incorrect clipping */
2513 if( ex > myclip.right()+1 )
2514 { /* clip right */
2515 int pixels = ex-myclip.right()-1;
2516 ex -= pixels;
2517 }
2518 if( ey > myclip.bottom()+1 )
2519 { /* clip bottom */
2520 int pixels = ey-myclip.bottom()-1;
2521 ey -= pixels;
2522 }
2523
2524 if( ex>sx )
2525 { /* skip if inner loop doesn't draw anything */
2526 int y;
2527
2528 /* case : STV_TRANSPARENCY_ALPHA */
2529 if (transparency & STV_TRANSPARENCY_ALPHA)
2530 {
2531 for( y=sy; y<ey; y++ )
2532 {
2533 uint8_t const *const source = source_base + (y_index>>16) * gfx->rowbytes();
2534 uint32_t *const dest = &dest_bmp.pix(y);
2535
2536 int x_index = x_index_base;
2537 for( int x=sx; x<ex; x++ )
2538 {
2539 if(stv_vdp2_window_process(x,y))
2540 {
2541 int c = source[x_index>>16];
2542 if ((transparency & STV_TRANSPARENCY_NONE) || (c != 0))
2543 dest[x] = alpha_blend_r32(dest[x], pal[c], alpha);
2544 }
2545 x_index += dx;
2546 }
2547
2548 y_index += dy;
2549 }
2550 } /* case : STV_TRANSPARENCY_ADD_BLEND */
2551 else if (transparency & STV_TRANSPARENCY_ADD_BLEND)
2552 {
2553 for( y=sy; y<ey; y++ )
2554 {
2555 uint8_t const *const source = source_base + (y_index>>16) * gfx->rowbytes();
2556 uint32_t *const dest = &dest_bmp.pix(y);
2557
2558 int x_index = x_index_base;
2559 for( int x=sx; x<ex; x++ )
2560 {
2561 if(stv_vdp2_window_process(x,y))
2562 {
2563 int c = source[x_index>>16];
2564 if ((transparency & STV_TRANSPARENCY_NONE) || (c != 0))
2565 dest[x] = add_blend_r32(dest[x],pal[c]);
2566 }
2567 x_index += dx;
2568 }
2569
2570 y_index += dy;
2571 }
2572 } /* case : STV_TRANSPARENCY_PEN */
2573 else
2574 {
2575 for( y=sy; y<ey; y++ )
2576 {
2577 uint8_t const *const source = source_base + (y_index>>16) * gfx->rowbytes();
2578 uint32_t *const dest = &dest_bmp.pix(y);
2579
2580 int x_index = x_index_base;
2581 for( int x=sx; x<ex; x++ )
2582 {
2583 if(stv_vdp2_window_process(x,y))
2584 {
2585 int c = source[x_index>>16];
2586 if ((transparency & STV_TRANSPARENCY_NONE) || (c != 0))
2587 dest[x] = pal[c];
2588 }
2589 x_index += dx;
2590 }
2591
2592 y_index += dy;
2593 }
2594 }
2595 }
2596 }
2597 }
2598 }
2599
stv_vdp2_drawgfxzoom_rgb555(bitmap_rgb32 & dest_bmp,const rectangle & clip,uint32_t code,uint32_t color,int flipx,int flipy,int sx,int sy,int transparency,int scalex,int scaley,int sprite_screen_width,int sprite_screen_height,int alpha)2600 void saturn_state::stv_vdp2_drawgfxzoom_rgb555(
2601 bitmap_rgb32 &dest_bmp,const rectangle &clip,
2602 uint32_t code,uint32_t color,int flipx,int flipy,int sx,int sy,
2603 int transparency,int scalex, int scaley,
2604 int sprite_screen_width, int sprite_screen_height, int alpha)
2605 {
2606 rectangle myclip;
2607 uint8_t* gfxdata;
2608
2609 gfxdata = m_vdp2.gfx_decode.get() + code * 0x20;
2610
2611 if(stv2_current_tilemap.window_control.enabled[0] ||
2612 stv2_current_tilemap.window_control.enabled[1])
2613 popmessage("Window Enabled for RGB555 Zoom");
2614
2615 if (!scalex || !scaley) return;
2616
2617 #if 0
2618 if (gfx->has_pen_usage() && !(transparency & STV_TRANSPARENCY_NONE))
2619 {
2620 int transmask = 0;
2621
2622 transmask = 1 << (0 & 0xff);
2623
2624 if ((gfx->pen_usage(code) & ~transmask) == 0)
2625 /* character is totally transparent, no need to draw */
2626 return;
2627 else if ((gfx->pen_usage(code) & transmask) == 0)
2628 /* character is totally opaque, can disable transparency */
2629 transparency |= STV_TRANSPARENCY_NONE;
2630 }
2631 #endif
2632
2633 /*
2634 scalex and scaley are 16.16 fixed point numbers
2635 1<<15 : shrink to 50%
2636 1<<16 : uniform scale
2637 1<<17 : double to 200%
2638 */
2639
2640
2641 /* KW 991012 -- Added code to force clip to bitmap boundary */
2642 myclip = clip;
2643 myclip &= dest_bmp.cliprect();
2644
2645 // if( gfx )
2646 {
2647 // const uint8_t *source_base = gfx->get_data(code % gfx->elements());
2648
2649 //int sprite_screen_height = (scaley*gfx->height()+0x8000)>>16;
2650 //int sprite_screen_width = (scalex*gfx->width()+0x8000)>>16;
2651
2652 if (sprite_screen_width && sprite_screen_height)
2653 {
2654 /* compute sprite increment per screen pixel */
2655 //int dx = (gfx->width()<<16)/sprite_screen_width;
2656 //int dy = (gfx->height()<<16)/sprite_screen_height;
2657 int dx = stv2_current_tilemap.incx;
2658 int dy = stv2_current_tilemap.incy;
2659
2660 int ex = sx+sprite_screen_width;
2661 int ey = sy+sprite_screen_height;
2662
2663 int x_index_base;
2664 int y_index;
2665
2666 if( flipx )
2667 {
2668 x_index_base = (sprite_screen_width-1)*dx;
2669 dx = -dx;
2670 }
2671 else
2672 {
2673 x_index_base = 0;
2674 }
2675
2676 if( flipy )
2677 {
2678 y_index = (sprite_screen_height-1)*dy;
2679 dy = -dy;
2680 }
2681 else
2682 {
2683 y_index = 0;
2684 }
2685
2686 if( sx < myclip.left())
2687 { /* clip left */
2688 int pixels = myclip.left()-sx;
2689 sx += pixels;
2690 x_index_base += pixels*dx;
2691 }
2692 if( sy < myclip.top() )
2693 { /* clip top */
2694 int pixels = myclip.top()-sy;
2695 sy += pixels;
2696 y_index += pixels*dy;
2697 }
2698 /* NS 980211 - fixed incorrect clipping */
2699 if( ex > myclip.right()+1 )
2700 { /* clip right */
2701 int pixels = ex-myclip.right()-1;
2702 ex -= pixels;
2703 }
2704 if( ey > myclip.bottom()+1 )
2705 { /* clip bottom */
2706 int pixels = ey-myclip.bottom()-1;
2707 ey -= pixels;
2708 }
2709
2710 if( ex>sx )
2711 { /* skip if inner loop doesn't draw anything */
2712 int y;
2713
2714 /* case : STV_TRANSPARENCY_ALPHA */
2715 if (transparency & STV_TRANSPARENCY_ALPHA)
2716 {
2717 for( y=sy; y<ey; y++ )
2718 {
2719 uint8_t const *const source = gfxdata + (y_index>>16)*16;
2720 uint32_t *const dest = &dest_bmp.pix(y);
2721
2722 int x_index = x_index_base;
2723 for( int x=sx; x<ex; x++ )
2724 {
2725 int data = (source[(x_index>>16)*2] << 8) | source[(x_index>>16)*2+1];
2726 int b = pal5bit((data & 0x7c00) >> 10);
2727 int g = pal5bit((data & 0x03e0) >> 5);
2728 int r = pal5bit( data & 0x001f);
2729 if(stv2_current_tilemap.fade_control & 1)
2730 stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
2731
2732 if ((transparency & STV_TRANSPARENCY_NONE) || (data & 0x8000))
2733 dest[x] = alpha_blend_r32(dest[x], rgb_t(r, g, b), alpha);
2734
2735 x_index += dx;
2736 }
2737
2738 y_index += dy;
2739 }
2740 } /* case : STV_TRANSPARENCY_ADD_BLEND */
2741 else if (transparency & STV_TRANSPARENCY_ADD_BLEND)
2742 {
2743 for( y=sy; y<ey; y++ )
2744 {
2745 uint8_t const *const source = gfxdata + (y_index>>16)*16;
2746 uint32_t *const dest = &dest_bmp.pix(y);
2747
2748 int x_index = x_index_base;
2749 for( int x=sx; x<ex; x++ )
2750 {
2751 int data = (source[(x_index*2+0)>>16]<<0)|(source[(x_index*2+1)>>16]<<8);
2752 int b = pal5bit((data & 0x7c00) >> 10);
2753 int g = pal5bit((data & 0x03e0) >> 5);
2754 int r = pal5bit( data & 0x001f);
2755 if(stv2_current_tilemap.fade_control & 1)
2756 stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
2757
2758 if ((transparency & STV_TRANSPARENCY_NONE) || (data & 0x8000))
2759 dest[x] = add_blend_r32(dest[x], rgb_t(r, g, b));
2760
2761 x_index += dx;
2762 }
2763
2764 y_index += dy;
2765 }
2766 } /* case : STV_TRANSPARENCY_PEN */
2767 else
2768 {
2769 for( y=sy; y<ey; y++ )
2770 {
2771 uint8_t const *const source = gfxdata + (y_index>>16)*16;
2772 uint32_t *const dest = &dest_bmp.pix(y);
2773
2774 int x_index = x_index_base;
2775 for( int x=sx; x<ex; x++ )
2776 {
2777 int data = (source[(x_index>>16)*2] << 8) | source[(x_index>>16)*2+1];
2778 int b = pal5bit((data & 0x7c00) >> 10);
2779 int g = pal5bit((data & 0x03e0) >> 5);
2780 int r = pal5bit( data & 0x001f);
2781 if(stv2_current_tilemap.fade_control & 1)
2782 stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
2783
2784 if ((transparency & STV_TRANSPARENCY_NONE) || (data & 0x8000))
2785 dest[x] = rgb_t(r, g, b);
2786
2787 x_index += dx;
2788 }
2789
2790 y_index += dy;
2791 }
2792 }
2793 }
2794 }
2795 }
2796
2797 }
2798
2799
stv_vdp2_drawgfx_rgb555(bitmap_rgb32 & dest_bmp,const rectangle & clip,uint32_t code,int flipx,int flipy,int sx,int sy,int transparency,int alpha)2800 void saturn_state::stv_vdp2_drawgfx_rgb555( bitmap_rgb32 &dest_bmp, const rectangle &clip, uint32_t code, int flipx, int flipy, int sx, int sy, int transparency, int alpha)
2801 {
2802 rectangle myclip;
2803 uint8_t* gfxdata;
2804 int sprite_screen_width, sprite_screen_height;
2805
2806 gfxdata = m_vdp2.gfx_decode.get() + code * 0x20;
2807 sprite_screen_width = sprite_screen_height = 8;
2808
2809 if(stv2_current_tilemap.window_control.enabled[0] ||
2810 stv2_current_tilemap.window_control.enabled[1])
2811 popmessage("Window Enabled for RGB555 tiles");
2812
2813 /* KW 991012 -- Added code to force clip to bitmap boundary */
2814 myclip = clip;
2815 myclip &= dest_bmp.cliprect();
2816
2817 {
2818 int dx = stv2_current_tilemap.incx;
2819 int dy = stv2_current_tilemap.incy;
2820
2821 int ex = sx+sprite_screen_width;
2822 int ey = sy+sprite_screen_height;
2823
2824 int x_index_base;
2825 int y_index;
2826
2827 if( flipx )
2828 {
2829 x_index_base = (sprite_screen_width-1)*dx;
2830 dx = -dx;
2831 }
2832 else
2833 {
2834 x_index_base = 0;
2835 }
2836
2837 if( flipy )
2838 {
2839 y_index = (sprite_screen_height-1)*dy;
2840 dy = -dy;
2841 }
2842 else
2843 {
2844 y_index = 0;
2845 }
2846
2847 if( sx < myclip.left())
2848 { /* clip left */
2849 int pixels = myclip.left()-sx;
2850 sx += pixels;
2851 x_index_base += pixels*dx;
2852 }
2853 if( sy < myclip.top() )
2854 { /* clip top */
2855 int pixels = myclip.top()-sy;
2856 sy += pixels;
2857 y_index += pixels*dy;
2858 }
2859 /* NS 980211 - fixed incorrect clipping */
2860 if( ex > myclip.right()+1 )
2861 { /* clip right */
2862 int pixels = ex-myclip.right()-1;
2863 ex -= pixels;
2864 }
2865 if( ey > myclip.bottom()+1 )
2866 { /* clip bottom */
2867 int pixels = ey-myclip.bottom()-1;
2868 ey -= pixels;
2869 }
2870
2871 if( ex>sx )
2872 { /* skip if inner loop doesn't draw anything */
2873 int y;
2874
2875 for( y=sy; y<ey; y++ )
2876 {
2877 uint8_t const *const source = gfxdata + (y_index>>16)*16;
2878 uint32_t *const dest = &dest_bmp.pix(y);
2879
2880 int x_index = x_index_base;
2881 for( int x=sx; x<ex; x++ )
2882 {
2883 uint16_t data = (source[(x_index>>16)*2] << 8) | source[(x_index>>16)*2+1];
2884 if ((data & 0x8000) || (transparency & STV_TRANSPARENCY_NONE))
2885 {
2886 int b = pal5bit((data & 0x7c00) >> 10);
2887 int g = pal5bit((data & 0x03e0) >> 5);
2888 int r = pal5bit( data & 0x001f);
2889 if(stv2_current_tilemap.fade_control & 1)
2890 stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
2891
2892 if (transparency & STV_TRANSPARENCY_ALPHA)
2893 dest[x] = alpha_blend_r32( dest[x], rgb_t(r, g, b), alpha );
2894 else
2895 dest[x] = rgb_t(r, g, b);
2896 }
2897 x_index += dx;
2898 }
2899
2900 y_index += dy;
2901 }
2902
2903 }
2904
2905 }
2906
2907 }
2908
2909
stv_vdp2_drawgfx_rgb888(bitmap_rgb32 & dest_bmp,const rectangle & clip,uint32_t code,int flipx,int flipy,int sx,int sy,int transparency,int alpha)2910 void saturn_state::stv_vdp2_drawgfx_rgb888( bitmap_rgb32 &dest_bmp, const rectangle &clip, uint32_t code, int flipx, int flipy,
2911 int sx, int sy, int transparency, int alpha)
2912 {
2913 rectangle myclip;
2914 uint8_t* gfxdata;
2915 int sprite_screen_width, sprite_screen_height;
2916
2917 gfxdata = m_vdp2.gfx_decode.get() + code * 0x20;
2918 sprite_screen_width = sprite_screen_height = 8;
2919
2920 if(stv2_current_tilemap.window_control.enabled[0] ||
2921 stv2_current_tilemap.window_control.enabled[1])
2922 popmessage("Window Enabled for RGB888 tiles");
2923
2924 /* KW 991012 -- Added code to force clip to bitmap boundary */
2925 myclip = clip;
2926 myclip &= dest_bmp.cliprect();
2927 {
2928 int dx = stv2_current_tilemap.incx;
2929 int dy = stv2_current_tilemap.incy;
2930
2931 int ex = sx+sprite_screen_width;
2932 int ey = sy+sprite_screen_height;
2933
2934 int x_index_base;
2935 int y_index;
2936
2937 if( flipx )
2938 {
2939 x_index_base = (sprite_screen_width-1)*dx;
2940 dx = -dx;
2941 }
2942 else
2943 {
2944 x_index_base = 0;
2945 }
2946
2947 if( flipy )
2948 {
2949 y_index = (sprite_screen_height-1)*dy;
2950 dy = -dy;
2951 }
2952 else
2953 {
2954 y_index = 0;
2955 }
2956
2957 if( sx < myclip.left())
2958 { /* clip left */
2959 int pixels = myclip.left()-sx;
2960 sx += pixels;
2961 x_index_base += pixels*dx;
2962 }
2963 if( sy < myclip.top() )
2964 { /* clip top */
2965 int pixels = myclip.top()-sy;
2966 sy += pixels;
2967 y_index += pixels*dy;
2968 }
2969 /* NS 980211 - fixed incorrect clipping */
2970 if( ex > myclip.right()+1 )
2971 { /* clip right */
2972 int pixels = ex-myclip.right()-1;
2973 ex -= pixels;
2974 }
2975 if( ey > myclip.bottom()+1 )
2976 { /* clip bottom */
2977 int pixels = ey-myclip.bottom()-1;
2978 ey -= pixels;
2979 }
2980
2981 if( ex>sx )
2982 { /* skip if inner loop doesn't draw anything */
2983 for( int y=sy; y<ey; y++ )
2984 {
2985 uint8_t const *const source = gfxdata + (y_index>>16)*32;
2986 uint32_t *const dest = &dest_bmp.pix(y);
2987
2988 int x_index = x_index_base;
2989
2990 for( int x=sx; x<ex; x++ )
2991 {
2992 uint32_t data = (source[(x_index>>16)*4+0] << 24) | (source[(x_index>>16)*4+1] << 16) | (source[(x_index>>16)*4+2] << 8) | (source[(x_index>>16)*4+3] << 0);
2993 if ((data & 0x80000000) || (transparency & STV_TRANSPARENCY_NONE))
2994 {
2995 int b = (data & 0xff0000) >> 16;
2996 int g = (data & 0x00ff00) >> 8;
2997 int r = (data & 0x0000ff);
2998
2999 if(stv2_current_tilemap.fade_control & 1)
3000 stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
3001
3002 if (transparency & STV_TRANSPARENCY_ALPHA)
3003 dest[x] = alpha_blend_r32( dest[x], rgb_t(r, g, b), alpha );
3004 else
3005 dest[x] = rgb_t(r, g, b);
3006 }
3007 x_index += dx;
3008 }
3009
3010 y_index += dy;
3011 }
3012
3013 }
3014
3015 }
3016 }
3017
stv_vdp2_drawgfx_alpha(bitmap_rgb32 & dest_bmp,const rectangle & clip,gfx_element * gfx,uint32_t code,uint32_t color,int flipx,int flipy,int offsx,int offsy,int transparency,int alpha)3018 void saturn_state::stv_vdp2_drawgfx_alpha(bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
3019 uint32_t code,uint32_t color, int flipx,int flipy,int offsx,int offsy,
3020 int transparency, int alpha)
3021 {
3022 const pen_t *pal = &m_palette->pen(gfx->colorbase() + gfx->granularity() * (color % gfx->colors()));
3023 const uint8_t *source_base = gfx->get_data(code % gfx->elements());
3024 int x_index_base, y_index, sx, sy, ex, ey;
3025 int xinc, yinc;
3026
3027 xinc = flipx ? -1 : 1;
3028 yinc = flipy ? -1 : 1;
3029
3030 x_index_base = flipx ? gfx->width()-1 : 0;
3031 y_index = flipy ? gfx->height()-1 : 0;
3032
3033 /* start coordinates */
3034 sx = offsx;
3035 sy = offsy;
3036
3037 /* end coordinates */
3038 ex = sx + gfx->width();
3039 ey = sy + gfx->height();
3040
3041 /* clip left */
3042 if (sx < clip.left())
3043 {
3044 int pixels = clip.left()-sx;
3045 sx += pixels;
3046 x_index_base += xinc*pixels;
3047 }
3048
3049 /* clip top */
3050 if (sy < clip.top())
3051 { int pixels = clip.top()-sy;
3052 sy += pixels;
3053 y_index += yinc*pixels;
3054 }
3055
3056 /* clip right */
3057 if (ex > clip.right()+1)
3058 {
3059 ex = clip.right()+1;
3060 }
3061 /* clip bottom */
3062 if (ey > clip.bottom()+1)
3063 {
3064 ey = clip.bottom()+1;
3065 }
3066
3067 /* skip if inner loop doesn't draw anything */
3068 if (ex > sx)
3069 {
3070 for (int y = sy; y < ey; y++)
3071 {
3072 uint8_t const *const source = source_base + y_index*gfx->rowbytes();
3073 uint32_t *const dest = &dest_bmp.pix(y);
3074 int x_index = x_index_base;
3075 for (int x = sx; x < ex; x++)
3076 {
3077 if(stv_vdp2_window_process(x,y))
3078 {
3079 int c = (source[x_index]);
3080 if ((transparency & STV_TRANSPARENCY_NONE) || (c != 0))
3081 dest[x] = alpha_blend_r32( dest[x], pal[c], alpha );
3082 }
3083
3084 x_index += xinc;
3085 }
3086 y_index += yinc;
3087 }
3088 }
3089 }
3090
stv_vdp2_drawgfx_transpen(bitmap_rgb32 & dest_bmp,const rectangle & clip,gfx_element * gfx,uint32_t code,uint32_t color,int flipx,int flipy,int offsx,int offsy,int transparency)3091 void saturn_state::stv_vdp2_drawgfx_transpen(bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
3092 uint32_t code,uint32_t color, int flipx,int flipy,int offsx,int offsy,
3093 int transparency)
3094 {
3095 const pen_t *pal = &m_palette->pen(gfx->colorbase() + gfx->granularity() * (color % gfx->colors()));
3096 const uint8_t *source_base = gfx->get_data(code % gfx->elements());
3097 int x_index_base, y_index, sx, sy, ex, ey;
3098 int xinc, yinc;
3099
3100 xinc = flipx ? -1 : 1;
3101 yinc = flipy ? -1 : 1;
3102
3103 x_index_base = flipx ? gfx->width()-1 : 0;
3104 y_index = flipy ? gfx->height()-1 : 0;
3105
3106 /* start coordinates */
3107 sx = offsx;
3108 sy = offsy;
3109
3110 /* end coordinates */
3111 ex = sx + gfx->width();
3112 ey = sy + gfx->height();
3113
3114 /* clip left */
3115 if (sx < clip.left())
3116 {
3117 int pixels = clip.left()-sx;
3118 sx += pixels;
3119 x_index_base += xinc*pixels;
3120 }
3121
3122 /* clip top */
3123 if (sy < clip.top())
3124 { int pixels = clip.top()-sy;
3125 sy += pixels;
3126 y_index += yinc*pixels;
3127 }
3128
3129 /* clip right */
3130 if (ex > clip.right()+1)
3131 {
3132 ex = clip.right()+1;
3133 }
3134 /* clip bottom */
3135 if (ey > clip.bottom()+1)
3136 {
3137 ey = clip.bottom()+1;
3138 }
3139
3140 /* skip if inner loop doesn't draw anything */
3141 if (ex > sx)
3142 {
3143 for (int y = sy; y < ey; y++)
3144 {
3145 uint8_t const *const source = source_base + y_index*gfx->rowbytes();
3146 uint32_t *const dest = &dest_bmp.pix(y);
3147 int x_index = x_index_base;
3148 for (int x = sx; x < ex; x++)
3149 {
3150 if(stv_vdp2_window_process(x,y))
3151 {
3152 int c = (source[x_index]);
3153 if ((transparency & STV_TRANSPARENCY_NONE) || (c != 0))
3154 dest[x] = pal[c];
3155 }
3156
3157 x_index += xinc;
3158 }
3159 y_index += yinc;
3160 }
3161 }
3162 }
3163
draw_4bpp_bitmap(bitmap_rgb32 & bitmap,const rectangle & cliprect)3164 void saturn_state::draw_4bpp_bitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
3165 {
3166 int xsize, ysize, xsize_mask, ysize_mask;
3167 int xsrc,ysrc,xdst,ydst;
3168 int src_offs;
3169 uint8_t* vram = m_vdp2.gfx_decode.get();
3170 uint32_t map_offset = stv2_current_tilemap.bitmap_map * 0x20000;
3171 int scrollx = stv2_current_tilemap.scrollx;
3172 int scrolly = stv2_current_tilemap.scrolly;
3173 uint16_t dot_data;
3174 uint16_t pal_bank;
3175
3176 xsize = (stv2_current_tilemap.bitmap_size & 2) ? 1024 : 512;
3177 ysize = (stv2_current_tilemap.bitmap_size & 1) ? 512 : 256;
3178
3179 xsize_mask = (stv2_current_tilemap.linescroll_enable) ? 1024 : xsize;
3180 ysize_mask = (stv2_current_tilemap.vertical_linescroll_enable) ? 512 : ysize;
3181
3182 pal_bank = stv2_current_tilemap.bitmap_palette_number;
3183 pal_bank+= stv2_current_tilemap.colour_ram_address_offset;
3184 pal_bank&= 7;
3185 pal_bank<<=8;
3186 if(stv2_current_tilemap.fade_control & 1)
3187 pal_bank += ((stv2_current_tilemap.fade_control & 2) ? (2*2048) : (2048));
3188
3189 for(ydst=cliprect.top();ydst<=cliprect.bottom();ydst++)
3190 {
3191 for(xdst=cliprect.left();xdst<=cliprect.right();xdst++)
3192 {
3193 if(!stv_vdp2_window_process(xdst,ydst))
3194 continue;
3195
3196 xsrc = (xdst + scrollx) & (xsize_mask-1);
3197 ysrc = (ydst + scrolly) & (ysize_mask-1);
3198 src_offs = (xsrc + (ysrc*xsize));
3199 src_offs/= 2;
3200 src_offs += map_offset;
3201 src_offs &= 0x7ffff;
3202
3203 dot_data = vram[src_offs] >> ((xsrc & 1) ? 0 : 4);
3204 dot_data&= 0xf;
3205
3206 if ((dot_data != 0) || (stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE))
3207 {
3208 dot_data += pal_bank;
3209
3210 if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
3211 bitmap.pix(ydst, xdst) = m_palette->pen(dot_data);
3212 else
3213 bitmap.pix(ydst, xdst) = alpha_blend_r32(bitmap.pix(ydst, xdst), m_palette->pen(dot_data), stv2_current_tilemap.alpha);
3214 }
3215 }
3216 }
3217 }
3218
3219
draw_8bpp_bitmap(bitmap_rgb32 & bitmap,const rectangle & cliprect)3220 void saturn_state::draw_8bpp_bitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
3221 {
3222 int xsize, ysize, xsize_mask, ysize_mask;
3223 int xsrc,ysrc,xdst,ydst;
3224 int src_offs;
3225 uint8_t* vram = m_vdp2.gfx_decode.get();
3226 uint32_t map_offset = stv2_current_tilemap.bitmap_map * 0x20000;
3227 int scrollx = stv2_current_tilemap.scrollx;
3228 int scrolly = stv2_current_tilemap.scrolly;
3229 uint16_t dot_data;
3230 uint16_t pal_bank;
3231 int xf, yf;
3232
3233 xsize = (stv2_current_tilemap.bitmap_size & 2) ? 1024 : 512;
3234 ysize = (stv2_current_tilemap.bitmap_size & 1) ? 512 : 256;
3235
3236 xsize_mask = (stv2_current_tilemap.linescroll_enable) ? 1024 : xsize;
3237 ysize_mask = (stv2_current_tilemap.vertical_linescroll_enable) ? 512 : ysize;
3238
3239 pal_bank = stv2_current_tilemap.bitmap_palette_number;
3240 pal_bank+= stv2_current_tilemap.colour_ram_address_offset;
3241 pal_bank&= 7;
3242 pal_bank<<=8;
3243 if(stv2_current_tilemap.fade_control & 1)
3244 pal_bank += ((stv2_current_tilemap.fade_control & 2) ? (2*2048) : (2048));
3245
3246 for(ydst=cliprect.top();ydst<=cliprect.bottom();ydst++)
3247 {
3248 for(xdst=cliprect.left();xdst<=cliprect.right();xdst++)
3249 {
3250 if(!stv_vdp2_window_process(xdst,ydst))
3251 continue;
3252
3253 xf = stv2_current_tilemap.incx * xdst;
3254 xf>>=16;
3255 yf = stv2_current_tilemap.incy * ydst;
3256 yf>>=16;
3257
3258 xsrc = (xf + scrollx) & (xsize_mask-1);
3259 ysrc = (yf + scrolly) & (ysize_mask-1);
3260 src_offs = (xsrc + (ysrc*xsize));
3261 src_offs += map_offset;
3262 src_offs &= 0x7ffff;
3263
3264 dot_data = vram[src_offs];
3265
3266 if ((dot_data != 0) || (stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE))
3267 {
3268 dot_data += pal_bank;
3269
3270 if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
3271 bitmap.pix(ydst, xdst) = m_palette->pen(dot_data);
3272 else
3273 bitmap.pix(ydst, xdst) = alpha_blend_r32(bitmap.pix(ydst, xdst), m_palette->pen(dot_data), stv2_current_tilemap.alpha);
3274 }
3275 }
3276 }
3277 }
3278
draw_11bpp_bitmap(bitmap_rgb32 & bitmap,const rectangle & cliprect)3279 void saturn_state::draw_11bpp_bitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
3280 {
3281 int xsize, ysize, xsize_mask, ysize_mask;
3282 int xsrc,ysrc,xdst,ydst;
3283 int src_offs;
3284 uint8_t* vram = m_vdp2.gfx_decode.get();
3285 uint32_t map_offset = stv2_current_tilemap.bitmap_map * 0x20000;
3286 int scrollx = stv2_current_tilemap.scrollx;
3287 int scrolly = stv2_current_tilemap.scrolly;
3288 uint16_t dot_data;
3289 uint16_t pal_bank;
3290 int xf, yf;
3291
3292 xsize = (stv2_current_tilemap.bitmap_size & 2) ? 1024 : 512;
3293 ysize = (stv2_current_tilemap.bitmap_size & 1) ? 512 : 256;
3294
3295 xsize_mask = (stv2_current_tilemap.linescroll_enable) ? 1024 : xsize;
3296 ysize_mask = (stv2_current_tilemap.vertical_linescroll_enable) ? 512 : ysize;
3297
3298 pal_bank = 0;
3299 if(stv2_current_tilemap.fade_control & 1)
3300 pal_bank = ((stv2_current_tilemap.fade_control & 2) ? (2*2048) : (2048));
3301
3302 for(ydst=cliprect.top();ydst<=cliprect.bottom();ydst++)
3303 {
3304 for(xdst=cliprect.left();xdst<=cliprect.right();xdst++)
3305 {
3306 if(!stv_vdp2_window_process(xdst,ydst))
3307 continue;
3308
3309 xf = stv2_current_tilemap.incx * xdst;
3310 xf>>=16;
3311 yf = stv2_current_tilemap.incy * ydst;
3312 yf>>=16;
3313
3314 xsrc = (xf + scrollx) & (xsize_mask-1);
3315 ysrc = (yf + scrolly) & (ysize_mask-1);
3316 src_offs = (xsrc + (ysrc*xsize));
3317 src_offs *= 2;
3318 src_offs += map_offset;
3319 src_offs &= 0x7ffff;
3320
3321 dot_data = ((vram[src_offs]<<8)|(vram[src_offs+1]<<0)) & 0x7ff;
3322
3323 if ((dot_data != 0) || (stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE))
3324 {
3325 dot_data += pal_bank;
3326
3327 if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
3328 bitmap.pix(ydst, xdst) = m_palette->pen(dot_data);
3329 else
3330 bitmap.pix(ydst, xdst) = alpha_blend_r32(bitmap.pix(ydst, xdst), m_palette->pen(dot_data), stv2_current_tilemap.alpha);
3331 }
3332 }
3333 }
3334 }
3335
3336
draw_rgb15_bitmap(bitmap_rgb32 & bitmap,const rectangle & cliprect)3337 void saturn_state::draw_rgb15_bitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
3338 {
3339 int xsize, ysize, xsize_mask, ysize_mask;
3340 int xsrc,ysrc,xdst,ydst;
3341 int src_offs;
3342 uint8_t* vram = m_vdp2.gfx_decode.get();
3343 uint32_t map_offset = stv2_current_tilemap.bitmap_map * 0x20000;
3344 int scrollx = stv2_current_tilemap.scrollx;
3345 int scrolly = stv2_current_tilemap.scrolly;
3346 int r,g,b;
3347 uint16_t dot_data;
3348 int xf, yf;
3349
3350 xsize = (stv2_current_tilemap.bitmap_size & 2) ? 1024 : 512;
3351 ysize = (stv2_current_tilemap.bitmap_size & 1) ? 512 : 256;
3352
3353 xsize_mask = (stv2_current_tilemap.linescroll_enable) ? 1024 : xsize;
3354 ysize_mask = (stv2_current_tilemap.vertical_linescroll_enable) ? 512 : ysize;
3355
3356 for(ydst=cliprect.top();ydst<=cliprect.bottom();ydst++)
3357 {
3358 for(xdst=cliprect.left();xdst<=cliprect.right();xdst++)
3359 {
3360 if(!stv_vdp2_window_process(xdst,ydst))
3361 continue;
3362
3363 xf = stv2_current_tilemap.incx * xdst;
3364 xf>>=16;
3365 yf = stv2_current_tilemap.incy * ydst;
3366 yf>>=16;
3367
3368 xsrc = (xf + scrollx) & (xsize_mask-1);
3369 ysrc = (yf + scrolly) & (ysize_mask-1);
3370 src_offs = (xsrc + (ysrc*xsize));
3371 src_offs *= 2;
3372 src_offs += map_offset;
3373 src_offs &= 0x7ffff;
3374
3375 dot_data =(vram[src_offs]<<8)|(vram[src_offs+1]<<0);
3376
3377 if ((dot_data & 0x8000) || (stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE))
3378 {
3379 b = pal5bit((dot_data & 0x7c00) >> 10);
3380 g = pal5bit((dot_data & 0x03e0) >> 5);
3381 r = pal5bit((dot_data & 0x001f) >> 0);
3382
3383 if(stv2_current_tilemap.fade_control & 1)
3384 stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
3385
3386 if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
3387 bitmap.pix(ydst, xdst) = rgb_t(r, g, b);
3388 else
3389 bitmap.pix(ydst, xdst) = alpha_blend_r32( bitmap.pix(ydst, xdst), rgb_t(r, g, b), stv2_current_tilemap.alpha );
3390 }
3391 }
3392 }
3393 }
3394
draw_rgb32_bitmap(bitmap_rgb32 & bitmap,const rectangle & cliprect)3395 void saturn_state::draw_rgb32_bitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
3396 {
3397 int xsize, ysize, xsize_mask, ysize_mask;
3398 int xsrc,ysrc,xdst,ydst;
3399 int src_offs;
3400 uint8_t* vram = m_vdp2.gfx_decode.get();
3401 uint32_t map_offset = stv2_current_tilemap.bitmap_map * 0x20000;
3402 int scrollx = stv2_current_tilemap.scrollx;
3403 int scrolly = stv2_current_tilemap.scrolly;
3404 int r,g,b;
3405 uint32_t dot_data;
3406 int xf, yf;
3407
3408 xsize = (stv2_current_tilemap.bitmap_size & 2) ? 1024 : 512;
3409 ysize = (stv2_current_tilemap.bitmap_size & 1) ? 512 : 256;
3410
3411 xsize_mask = (stv2_current_tilemap.linescroll_enable) ? 1024 : xsize;
3412 ysize_mask = (stv2_current_tilemap.vertical_linescroll_enable) ? 512 : ysize;
3413
3414 for(ydst=cliprect.top();ydst<=cliprect.bottom();ydst++)
3415 {
3416 for(xdst=cliprect.left();xdst<=cliprect.right();xdst++)
3417 {
3418 if(!stv_vdp2_window_process(xdst,ydst))
3419 continue;
3420
3421 xf = stv2_current_tilemap.incx * xdst;
3422 xf>>=16;
3423 yf = stv2_current_tilemap.incy * ydst;
3424 yf>>=16;
3425
3426 xsrc = (xf + scrollx) & (xsize_mask-1);
3427 ysrc = (yf + scrolly) & (ysize_mask-1);
3428 src_offs = (xsrc + (ysrc*xsize));
3429 src_offs *= 4;
3430 src_offs += map_offset;
3431 src_offs &= 0x7ffff;
3432
3433 dot_data = (vram[src_offs+0]<<24)|(vram[src_offs+1]<<16)|(vram[src_offs+2]<<8)|(vram[src_offs+3]<<0);
3434
3435 if ((dot_data & 0x80000000) || (stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE))
3436 {
3437 b = ((dot_data & 0x00ff0000) >> 16);
3438 g = ((dot_data & 0x0000ff00) >> 8);
3439 r = ((dot_data & 0x000000ff) >> 0);
3440
3441 if(stv2_current_tilemap.fade_control & 1)
3442 stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
3443
3444 if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
3445 bitmap.pix(ydst, xdst) = rgb_t(r, g, b);
3446 else
3447 bitmap.pix(ydst, xdst) = alpha_blend_r32( bitmap.pix(ydst, xdst), rgb_t(r, g, b), stv2_current_tilemap.alpha );
3448 }
3449 }
3450 }
3451 }
3452
3453
stv_vdp2_draw_basic_bitmap(bitmap_rgb32 & bitmap,const rectangle & cliprect)3454 void saturn_state::stv_vdp2_draw_basic_bitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
3455 {
3456 if (!stv2_current_tilemap.enabled) return;
3457
3458 /* new bitmap code, supposed to rewrite the old one. Not supposed to be clean, but EFFICIENT! */
3459 if(stv2_current_tilemap.incx == 0x10000 && stv2_current_tilemap.incy == 0x10000)
3460 {
3461 switch(stv2_current_tilemap.colour_depth)
3462 {
3463 case 0: draw_4bpp_bitmap(bitmap,cliprect); return;
3464 case 1: draw_8bpp_bitmap(bitmap,cliprect); return;
3465 case 2: draw_11bpp_bitmap(bitmap, cliprect); return;
3466 case 3: draw_rgb15_bitmap(bitmap,cliprect); return;
3467 case 4: draw_rgb32_bitmap(bitmap,cliprect); return;
3468 }
3469
3470 /* intentional fall-through*/
3471 popmessage("%d %s %s %s",stv2_current_tilemap.colour_depth,
3472 stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE ? "no trans" : "trans",
3473 stv2_current_tilemap.colour_calculation_enabled ? "cc" : "no cc",
3474 (stv2_current_tilemap.incx == 0x10000 && stv2_current_tilemap.incy == 0x10000) ? "no zoom" : "zoom");
3475 }
3476 else
3477 {
3478 switch(stv2_current_tilemap.colour_depth)
3479 {
3480 // case 0: draw_4bpp_bitmap(bitmap,cliprect); return;
3481 case 1: draw_8bpp_bitmap(bitmap,cliprect); return;
3482 // case 2: draw_11bpp_bitmap(bitmap, cliprect); return;
3483 case 3: draw_rgb15_bitmap(bitmap,cliprect); return;
3484 case 4: draw_rgb32_bitmap(bitmap,cliprect); return;
3485 }
3486
3487 /* intentional fall-through*/
3488 popmessage("%d %s %s %s",stv2_current_tilemap.colour_depth,
3489 stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE ? "no trans" : "trans",
3490 stv2_current_tilemap.colour_calculation_enabled ? "cc" : "no cc",
3491 (stv2_current_tilemap.incx == 0x10000 && stv2_current_tilemap.incy == 0x10000) ? "no zoom" : "zoom");
3492 }
3493 }
3494
3495 /*---------------------------------------------------------------------------
3496 | Plane Size | Pattern Name Data Size | Character Size | Map Bits / Address |
3497 ----------------------------------------------------------------------------|
3498 | | | 1 H x 1 V | bits 6-0 * 0x02000 |
3499 | | 1 word |-------------------------------------|
3500 | | | 2 H x 2 V | bits 8-0 * 0x00800 |
3501 | 1 H x 1 V ---------------------------------------------------------------|
3502 | | | 1 H x 1 V | bits 5-0 * 0x04000 |
3503 | | 2 words |-------------------------------------|
3504 | | | 2 H x 2 V | bits 7-0 * 0x01000 |
3505 -----------------------------------------------------------------------------
3506 | | | 1 H x 1 V | bits 6-1 * 0x04000 |
3507 | | 1 word |-------------------------------------|
3508 | | | 2 H x 2 V | bits 8-1 * 0x01000 |
3509 | 2 H x 1 V ---------------------------------------------------------------|
3510 | | | 1 H x 1 V | bits 5-1 * 0x08000 |
3511 | | 2 words |-------------------------------------|
3512 | | | 2 H x 2 V | bits 7-1 * 0x02000 |
3513 -----------------------------------------------------------------------------
3514 | | | 1 H x 1 V | bits 6-2 * 0x08000 |
3515 | | 1 word |-------------------------------------|
3516 | | | 2 H x 2 V | bits 8-2 * 0x02000 |
3517 | 2 H x 2 V ---------------------------------------------------------------|
3518 | | | 1 H x 1 V | bits 5-2 * 0x10000 |
3519 | | 2 words |-------------------------------------|
3520 | | | 2 H x 2 V | bits 7-2 * 0x04000 |
3521 --the-highest-bit-is-ignored-if-vram-is-only-4mbits------------------------*/
3522
3523
3524 /*
3525 4.2 Sega's Cell / Character Pattern / Page / Plane / Map system, aka a rather annoying thing that makes optimizations hard
3526 (this is only for the normal tilemaps at the moment, i haven't even thought about the ROZ ones)
3527
3528 Tiles:
3529
3530 Cells are 8x8 gfx stored in video ram, they can be of various colour depths
3531
3532 Character Patterns can be 8x8 or 16x16 (1 hcell x 1 vcell or 2 hcell x 2 vcell)
3533 (a 16x16 character pattern is 4 8x8 cells put together)
3534
3535 A page is made up of 64x64 cells, thats 64x64 character patterns in 8x8 mode or 32x32 character patterns in 16x16 mode.
3536 64 * 8 = 512 (0x200)
3537 32 * 16 = 512 (0x200)
3538 A page is _always_ 512 (0x200) pixels in each direction
3539
3540 in 1 word mode a 32*16 x 32*16 page is 0x0800 bytes
3541 in 1 word mode a 64*8 x 64*8 page is 0x2000 bytes
3542 in 2 word mode a 32*16 x 32*16 page is 0x1000 bytes
3543 in 2 word mode a 64*8 x 64*8 page is 0x4000 bytes
3544
3545 either 1, 2 or 4 pages make each plane depending on the plane size register (per tilemap)
3546 therefore each plane is either
3547 64 * 8 * 1 x 64 * 8 * 1 (512 x 512)
3548 64 * 8 * 2 x 64 * 8 * 1 (1024 x 512)
3549 64 * 8 * 2 x 64 * 8 * 2 (1024 x 1024)
3550
3551 32 * 16 * 1 x 32 * 16 * 1 (512 x 512)
3552 32 * 16 * 2 x 32 * 16 * 1 (1024 x 512)
3553 32 * 16 * 2 x 32 * 16 * 2 (1024 x 1024)
3554
3555 map is always enabled?
3556 map is a 2x2 arrangement of planes, all 4 of the planes can be the same.
3557
3558 */
3559
stv_vdp2_get_map_page(int x,int y,int * _map,int * _page)3560 void saturn_state::stv_vdp2_get_map_page( int x, int y, int *_map, int *_page )
3561 {
3562 int page = 0;
3563 int map;
3564
3565 if ( stv2_current_tilemap.map_count == 4 )
3566 {
3567 if ( stv2_current_tilemap.tile_size == 0 )
3568 {
3569 if ( stv2_current_tilemap.plane_size & 1 )
3570 {
3571 page = ((x >> 6) & 1);
3572 map = (x >> 7) & 1;
3573 }
3574 else
3575 {
3576 map = (x >> 6) & 1;
3577 }
3578
3579 if ( stv2_current_tilemap.plane_size & 2 )
3580 {
3581 page |= ((y >> (6-1)) & 2);
3582 map |= ((y >> (7-1)) & 2);
3583 }
3584 else
3585 {
3586 map |= ((y >> (6-1)) & 2);
3587 }
3588 }
3589 else
3590 {
3591 if ( stv2_current_tilemap.plane_size & 1 )
3592 {
3593 page = ((x >> 5) & 1);
3594 map = (x >> 6) & 1;
3595 }
3596 else
3597 {
3598 map = (x >> 5) & 1;
3599 }
3600
3601 if ( stv2_current_tilemap.plane_size & 2 )
3602 {
3603 page |= ((y >> (5 - 1)) & 2);
3604 map |= ((y >> (6-1)) & 2);
3605 }
3606 else
3607 {
3608 map |= ((y >> (5-1)) & 2);
3609 }
3610 }
3611 }
3612 else //16
3613 {
3614 if ( stv2_current_tilemap.tile_size == 0 )
3615 {
3616 if ( stv2_current_tilemap.plane_size & 1 )
3617 {
3618 page = ((x >> 6) & 1);
3619 map = (x >> 7) & 3;
3620 }
3621 else
3622 {
3623 map = (x >> 6) & 3;
3624 }
3625
3626 if ( stv2_current_tilemap.plane_size & 2 )
3627 {
3628 page |= ((y >> (6-1)) & 2);
3629 map |= ((y >> (7-2)) & 12);
3630 }
3631 else
3632 {
3633 map |= ((y >> (6-2)) & 12);
3634 }
3635 }
3636 else
3637 {
3638 if ( stv2_current_tilemap.plane_size & 1 )
3639 {
3640 page = ((x >> 5) & 1);
3641 map = (x >> 6) & 3;
3642 }
3643 else
3644 {
3645 map = (x >> 5) & 3;
3646 }
3647
3648 if ( stv2_current_tilemap.plane_size & 2 )
3649 {
3650 page |= ((y >> (5 - 1)) & 2);
3651 map |= ((y >> (6-2)) & 12);
3652 }
3653 else
3654 {
3655 map |= ((y >> (5-2)) & 12);
3656 }
3657 }
3658 }
3659 *_page = page;
3660 *_map = map;
3661 }
3662
stv_vdp2_draw_basic_tilemap(bitmap_rgb32 & bitmap,const rectangle & cliprect)3663 void saturn_state::stv_vdp2_draw_basic_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
3664 {
3665 /* hopefully this is easier to follow than it is efficient .. */
3666
3667 /* I call character patterns tiles .. even if they represent up to 4 tiles */
3668
3669 /* Page variables */
3670 int pgtiles_x, pgpixels_x;
3671 int pgtiles_y, pgpixels_y;
3672 int pgsize_bytes, pgsize_dwords;
3673
3674 /* Plane Variables */
3675 int pltiles_x, plpixels_x;
3676 int pltiles_y, plpixels_y;
3677 int plsize_bytes/*, plsize_dwords*/;
3678
3679 /* Map Variables */
3680 int mptiles_x, mppixels_x;
3681 int mptiles_y, mppixels_y;
3682 int mpsize_bytes, mpsize_dwords;
3683
3684 /* work Variables */
3685 int i, x, y;
3686 int base[16];
3687
3688 int scalex,scaley;
3689 int tilesizex, tilesizey;
3690 int drawypos, drawxpos;
3691
3692 int tilecodemin = 0x10000000, tilecodemax = 0;
3693
3694 if ( stv2_current_tilemap.incx == 0 || stv2_current_tilemap.incy == 0 ) return;
3695
3696 if ( stv2_current_tilemap.colour_calculation_enabled == 1 )
3697 {
3698 if ( STV_VDP2_CCMD )
3699 {
3700 stv2_current_tilemap.transparency |= STV_TRANSPARENCY_ADD_BLEND;
3701 }
3702 else
3703 {
3704 stv2_current_tilemap.transparency |= STV_TRANSPARENCY_ALPHA;
3705 }
3706 }
3707
3708 scalex = s32(s64(0x100000000U) / s64(stv2_current_tilemap.incx));
3709 scaley = s32(s64(0x100000000U) / s64(stv2_current_tilemap.incy));
3710 tilesizex = scalex * 8;
3711 tilesizey = scaley * 8;
3712 drawypos = drawxpos = 0;
3713
3714 /* Calculate the Number of tiles for x / y directions of each page (actually these will be the same */
3715 /* (2-stv2_current_tilemap.tile_size) << 5) */
3716 pgtiles_x = ((2-stv2_current_tilemap.tile_size) << 5); // 64 (8x8 mode) or 32 (16x16 mode)
3717 pgtiles_y = ((2-stv2_current_tilemap.tile_size) << 5); // 64 (8x8 mode) or 32 (16x16 mode)
3718
3719 /* Calculate the Page Size in BYTES */
3720 /* 64 * 64 * (1 * 2) = 0x2000 bytes
3721 32 * 32 * (1 * 2) = 0x0800 bytes
3722 64 * 64 * (2 * 2) = 0x4000 bytes
3723 32 * 32 * (2 * 2) = 0x1000 bytes */
3724
3725 pgsize_bytes = (pgtiles_x * pgtiles_y) * ((2-stv2_current_tilemap.pattern_data_size)*2);
3726
3727 /*---------------------------------------------------------------------------
3728 | Plane Size | Pattern Name Data Size | Character Size | Map Bits / Address |
3729 ----------------------------------------------------------------------------|
3730 | | | 1 H x 1 V | bits 6-0 * 0x02000 |
3731 | | 1 word |-------------------------------------|
3732 | | | 2 H x 2 V | bits 8-0 * 0x00800 |
3733 | 1 H x 1 V ---------------------------------------------------------------|
3734 | | | 1 H x 1 V | bits 5-0 * 0x04000 |
3735 | | 2 words |-------------------------------------|
3736 | | | 2 H x 2 V | bits 7-0 * 0x01000 |
3737 ---------------------------------------------------------------------------*/
3738
3739
3740 /* Page Dimensions are always 0x200 pixes (512x512) */
3741 pgpixels_x = 0x200;
3742 pgpixels_y = 0x200;
3743
3744 /* Work out the Plane Size in tiles and Plane Dimensions (pixels) */
3745 switch (stv2_current_tilemap.plane_size & 3)
3746 {
3747 case 0: // 1 page * 1 page
3748 pltiles_x = pgtiles_x;
3749 plpixels_x = pgpixels_x;
3750 pltiles_y = pgtiles_y;
3751 plpixels_y = pgpixels_y;
3752 break;
3753
3754 case 1: // 2 pages * 1 page
3755 pltiles_x = pgtiles_x * 2;
3756 plpixels_x = pgpixels_x * 2;
3757 pltiles_y = pgtiles_y;
3758 plpixels_y = pgpixels_y;
3759 break;
3760
3761 case 3: // 2 pages * 2 pages
3762 pltiles_x = pgtiles_x * 2;
3763 plpixels_x = pgpixels_x * 2;
3764 pltiles_y = pgtiles_y * 2;
3765 plpixels_y = pgpixels_y * 2;
3766 break;
3767
3768 default:
3769 // illegal
3770 pltiles_x = pgtiles_x;
3771 plpixels_x = pgpixels_x;
3772 pltiles_y = pgtiles_y * 2;
3773 plpixels_y = pgpixels_y * 2;
3774 break;
3775 }
3776
3777 /* Plane Size in BYTES */
3778 /* still the same as before
3779 (64 * 1) * (64 * 1) * (1 * 2) = 0x02000 bytes
3780 (32 * 1) * (32 * 1) * (1 * 2) = 0x00800 bytes
3781 (64 * 1) * (64 * 1) * (2 * 2) = 0x04000 bytes
3782 (32 * 1) * (32 * 1) * (2 * 2) = 0x01000 bytes
3783 changed
3784 (64 * 2) * (64 * 1) * (1 * 2) = 0x04000 bytes
3785 (32 * 2) * (32 * 1) * (1 * 2) = 0x01000 bytes
3786 (64 * 2) * (64 * 1) * (2 * 2) = 0x08000 bytes
3787 (32 * 2) * (32 * 1) * (2 * 2) = 0x02000 bytes
3788 changed
3789 (64 * 2) * (64 * 1) * (1 * 2) = 0x08000 bytes
3790 (32 * 2) * (32 * 1) * (1 * 2) = 0x02000 bytes
3791 (64 * 2) * (64 * 1) * (2 * 2) = 0x10000 bytes
3792 (32 * 2) * (32 * 1) * (2 * 2) = 0x04000 bytes
3793 */
3794
3795 plsize_bytes = (pltiles_x * pltiles_y) * ((2-stv2_current_tilemap.pattern_data_size)*2);
3796
3797 /*---------------------------------------------------------------------------
3798 | Plane Size | Pattern Name Data Size | Character Size | Map Bits / Address |
3799 -----------------------------------------------------------------------------
3800 | 1 H x 1 V see above, nothing has changed |
3801 -----------------------------------------------------------------------------
3802 | | | 1 H x 1 V | bits 6-1 * 0x04000 |
3803 | | 1 word |-------------------------------------|
3804 | | | 2 H x 2 V | bits 8-1 * 0x01000 |
3805 | 2 H x 1 V ---------------------------------------------------------------|
3806 | | | 1 H x 1 V | bits 5-1 * 0x08000 |
3807 | | 2 words |-------------------------------------|
3808 | | | 2 H x 2 V | bits 7-1 * 0x02000 |
3809 -----------------------------------------------------------------------------
3810 | | | 1 H x 1 V | bits 6-2 * 0x08000 |
3811 | | 1 word |-------------------------------------|
3812 | | | 2 H x 2 V | bits 8-2 * 0x02000 |
3813 | 2 H x 2 V ---------------------------------------------------------------|
3814 | | | 1 H x 1 V | bits 5-2 * 0x10000 |
3815 | | 2 words |-------------------------------------|
3816 | | | 2 H x 2 V | bits 7-2 * 0x04000 |
3817 --the-highest-bit-is-ignored-if-vram-is-only-4mbits------------------------*/
3818
3819
3820 /* Work out the Map Sizes in tiles, Map Dimensions */
3821 /* maps are always enabled? */
3822 if ( stv2_current_tilemap.map_count == 4 )
3823 {
3824 mptiles_x = pltiles_x * 2;
3825 mptiles_y = pltiles_y * 2;
3826 mppixels_x = plpixels_x * 2;
3827 mppixels_y = plpixels_y * 2;
3828 }
3829 else
3830 {
3831 mptiles_x = pltiles_x * 4;
3832 mptiles_y = pltiles_y * 4;
3833 mppixels_x = plpixels_x * 4;
3834 mppixels_y = plpixels_y * 4;
3835 }
3836
3837 /* Map Size in BYTES */
3838 mpsize_bytes = (mptiles_x * mptiles_y) * ((2-stv2_current_tilemap.pattern_data_size)*2);
3839
3840
3841 /*-----------------------------------------------------------------------------------------------------------
3842 | | | 1 H x 1 V | bits 6-1 (upper mask 0x07f) (0x1ff >> 2) * 0x04000 |
3843 | | 1 word |---------------------------------------------------------------------|
3844 | | | 2 H x 2 V | bits 8-1 (upper mask 0x1ff) (0x1ff >> 0) * 0x01000 |
3845 | 2 H x 1 V -----------------------------------------------------------------------------------------------|
3846 | | | 1 H x 1 V | bits 5-1 (upper mask 0x03f) (0x1ff >> 3) * 0x08000 |
3847 | | 2 words |---------------------------------------------------------------------|
3848 | | | 2 H x 2 V | bits 7-1 (upper mask 0x0ff) (0x1ff >> 1) * 0x02000 |
3849 -------------------------------------------------------------------------------------------------------------
3850 lower mask = ~stv2_current_tilemap.plane_size
3851 -----------------------------------------------------------------------------------------------------------*/
3852
3853 /* Precalculate bases from MAP registers */
3854 for (i = 0; i < stv2_current_tilemap.map_count; i++)
3855 {
3856 static const int shifttable[4] = {0,1,2,2};
3857
3858 int uppermask, uppermaskshift;
3859
3860 uppermaskshift = (1-stv2_current_tilemap.pattern_data_size) | ((1-stv2_current_tilemap.tile_size)<<1);
3861 uppermask = 0x1ff >> uppermaskshift;
3862
3863 base[i] = ((stv2_current_tilemap.map_offset[i] & uppermask) >> shifttable[stv2_current_tilemap.plane_size]) * plsize_bytes;
3864
3865 base[i] &= 0x7ffff; /* shienryu needs this for the text layer, is there a problem elsewhere or is it just right without the ram cart */
3866
3867 base[i] = base[i] / 4; // convert bytes to DWORDS
3868 }
3869
3870 /* other bits */
3871 //stv2_current_tilemap.trans_enabled = stv2_current_tilemap.trans_enabled ? STV_TRANSPARENCY_NONE : STV_TRANSPARENCY_PEN;
3872 stv2_current_tilemap.scrollx &= mppixels_x-1;
3873 stv2_current_tilemap.scrolly &= mppixels_y-1;
3874
3875 pgsize_dwords = pgsize_bytes /4;
3876 //plsize_dwords = plsize_bytes /4;
3877 mpsize_dwords = mpsize_bytes /4;
3878
3879 // if (stv2_current_tilemap.layer_name==3) popmessage ("well this is a bit %08x", stv2_current_tilemap.map_offset[0]);
3880 // if (stv2_current_tilemap.layer_name==3) popmessage ("well this is a bit %08x %08x %08x %08x", stv2_current_tilemap.plane_size, pgtiles_x, pltiles_x, mptiles_x);
3881
3882 if (!stv2_current_tilemap.enabled) return; // stop right now if its disabled ...
3883
3884 /* most things we need (or don't need) to work out are now worked out */
3885
3886 for (y = 0; y<mptiles_y; y++) {
3887 int ypageoffs;
3888 int page, map, newbase, offs, data;
3889 int tilecode, flipyx, pal, gfx = 0;
3890
3891 map = 0 ; page = 0 ;
3892 if ( y == 0 )
3893 {
3894 int drawyposinc = tilesizey*(stv2_current_tilemap.tile_size ? 2 : 1);
3895 drawypos = -(stv2_current_tilemap.scrolly*scaley);
3896 while( ((drawypos + drawyposinc) >> 16) < cliprect.top() )
3897 {
3898 drawypos += drawyposinc;
3899 y++;
3900 }
3901 mptiles_y += y;
3902 }
3903 else
3904 {
3905 drawypos += tilesizey*(stv2_current_tilemap.tile_size ? 2 : 1);
3906 }
3907 if ((drawypos >> 16) > cliprect.bottom()) break;
3908
3909 ypageoffs = y & (pgtiles_y-1);
3910
3911 for (x = 0; x<mptiles_x; x++) {
3912 int xpageoffs;
3913 int tilecodespacing = 1;
3914
3915 if ( x == 0 )
3916 {
3917 int drawxposinc = tilesizex*(stv2_current_tilemap.tile_size ? 2 : 1);
3918 drawxpos = -(stv2_current_tilemap.scrollx*scalex);
3919 while( ((drawxpos + drawxposinc) >> 16) < cliprect.left() )
3920 {
3921 drawxpos += drawxposinc;
3922 x++;
3923 }
3924 mptiles_x += x;
3925 }
3926 else
3927 {
3928 drawxpos+=tilesizex*(stv2_current_tilemap.tile_size ? 2 : 1);
3929 }
3930 if ( (drawxpos >> 16) > cliprect.right() ) break;
3931
3932 xpageoffs = x & (pgtiles_x-1);
3933
3934 stv_vdp2_get_map_page(x,y,&map,&page);
3935
3936 newbase = base[map] + page * pgsize_dwords;
3937 offs = (ypageoffs * pgtiles_x) + xpageoffs;
3938
3939 /* GET THE TILE INFO ... */
3940 /* 1 word per tile mode with supplement bits */
3941 if (stv2_current_tilemap.pattern_data_size ==1)
3942 {
3943 data = m_vdp2_vram[newbase + offs/2];
3944 data = (offs&1) ? (data & 0x0000ffff) : ((data & 0xffff0000) >> 16);
3945
3946 /* Supplement Mode 12 bits, no flip */
3947 if (stv2_current_tilemap.character_number_supplement == 1)
3948 {
3949 /* no flip */ flipyx = 0;
3950 /* 8x8 */ if (stv2_current_tilemap.tile_size==0) tilecode = (data & 0x0fff) + ( (stv2_current_tilemap.supplementary_character_bits&0x1c) << 10);
3951 /* 16x16 */ else tilecode = ((data & 0x0fff) << 2) + (stv2_current_tilemap.supplementary_character_bits&0x03) + ((stv2_current_tilemap.supplementary_character_bits&0x10) << 10);
3952 }
3953 /* Supplement Mode 10 bits, with flip */
3954 else
3955 {
3956 /* flip bits */ flipyx = (data & 0x0c00) >> 10;
3957 /* 8x8 */ if (stv2_current_tilemap.tile_size==0) tilecode = (data & 0x03ff) + ( (stv2_current_tilemap.supplementary_character_bits) << 10);
3958 /* 16x16 */ else tilecode = ((data & 0x03ff) <<2) + (stv2_current_tilemap.supplementary_character_bits&0x03) + ((stv2_current_tilemap.supplementary_character_bits&0x1c) << 10);
3959 }
3960
3961 /*>16cols*/ if (stv2_current_tilemap.colour_depth != 0) pal = ((data & 0x7000)>>8);
3962 /*16 cols*/ else pal = ((data & 0xf000)>>12) +( (stv2_current_tilemap.supplementary_palette_bits) << 4);
3963
3964 }
3965 /* 2 words per tile, no supplement bits */
3966 else
3967 {
3968 data = m_vdp2_vram[newbase + offs];
3969 tilecode = (data & 0x00007fff);
3970 pal = (data & 0x007f0000)>>16;
3971 // specialc = (data & 0x10000000)>>28;
3972 flipyx = (data & 0xc0000000)>>30;
3973 }
3974 /* WE'VE GOT THE TILE INFO ... */
3975
3976 if ( tilecode < tilecodemin ) tilecodemin = tilecode;
3977 if ( tilecode > tilecodemax ) tilecodemax = tilecode;
3978
3979 /* DECODE ANY TILES WE NEED TO DECODE */
3980
3981 pal += stv2_current_tilemap.colour_ram_address_offset<< 4; // bios uses this ..
3982
3983 /*Enable fading bit*/
3984 if(stv2_current_tilemap.fade_control & 1)
3985 {
3986 /*Select fading bit*/
3987 pal += ((stv2_current_tilemap.fade_control & 2) ? (0x100) : (0x80));
3988 }
3989
3990 if (stv2_current_tilemap.colour_depth == 1)
3991 {
3992 gfx = 2;
3993 pal = pal >>4;
3994 tilecode &=0x7fff;
3995 if (tilecode == 0x7fff) tilecode--; /* prevents crash but unsure what should happen; wrapping? */
3996 tilecodespacing = 2;
3997 }
3998 else if (stv2_current_tilemap.colour_depth == 0)
3999 {
4000 gfx = 0;
4001 tilecode &=0x7fff;
4002 tilecodespacing = 1;
4003 }
4004 /* TILES ARE NOW DECODED */
4005
4006 if(!STV_VDP2_VRAMSZ)
4007 tilecode &= 0x3fff;
4008
4009 /* DRAW! */
4010 if(stv2_current_tilemap.incx != 0x10000 ||
4011 stv2_current_tilemap.incy != 0x10000 ||
4012 stv2_current_tilemap.transparency & STV_TRANSPARENCY_ADD_BLEND )
4013 {
4014 #define SCR_TILESIZE_X (((drawxpos + tilesizex) >> 16) - (drawxpos >> 16))
4015 #define SCR_TILESIZE_X1(startx) (((drawxpos + (startx) + tilesizex) >> 16) - ((drawxpos + (startx))>>16))
4016 #define SCR_TILESIZE_Y (((drawypos + tilesizey) >> 16) - (drawypos >> 16))
4017 #define SCR_TILESIZE_Y1(starty) (((drawypos + (starty) + tilesizey) >> 16) - ((drawypos + (starty))>>16))
4018 if (stv2_current_tilemap.tile_size==1)
4019 {
4020 if ( stv2_current_tilemap.colour_depth == 4 )
4021 {
4022 popmessage("Unsupported tilemap gfx zoom color depth = 4, tile size = 1, contact MAMEdev");
4023 }
4024 else if ( stv2_current_tilemap.colour_depth == 3 )
4025 {
4026 /* RGB555 */
4027 stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4028 stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex) >> 16,drawypos >> 16,stv2_current_tilemap.transparency,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4029 stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
4030 stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex)>> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
4031 }
4032 else
4033 {
4034 /* normal */
4035 stv_vdp2_drawgfxzoom(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4036 stv_vdp2_drawgfxzoom(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex) >> 16,drawypos >> 16,stv2_current_tilemap.transparency,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4037 stv_vdp2_drawgfxzoom(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
4038 stv_vdp2_drawgfxzoom(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex)>> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
4039 }
4040 }
4041 else
4042 {
4043 if ( stv2_current_tilemap.colour_depth == 4 )
4044 popmessage("Unsupported tilemap gfx zoom color depth = 4, tile size = 0, contact MAMEdev");
4045 else if ( stv2_current_tilemap.colour_depth == 3)
4046 {
4047 stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,tilecode,pal,flipyx&1,flipyx&2, drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,scalex,scaley,SCR_TILESIZE_X,SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4048 }
4049 else
4050 stv_vdp2_drawgfxzoom(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode,pal,flipyx&1,flipyx&2, drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,scalex,scaley,SCR_TILESIZE_X,SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4051 }
4052 }
4053 else
4054 {
4055 int olddrawxpos, olddrawypos;
4056 olddrawxpos = drawxpos; drawxpos >>= 16;
4057 olddrawypos = drawypos; drawypos >>= 16;
4058 if (stv2_current_tilemap.tile_size==1)
4059 {
4060 if ( stv2_current_tilemap.colour_depth == 4 )
4061 {
4062 /* normal */
4063 stv_vdp2_drawgfx_rgb888(bitmap,cliprect,tilecode+(0+(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos, drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4064 stv_vdp2_drawgfx_rgb888(bitmap,cliprect,tilecode+(1-(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4065 stv_vdp2_drawgfx_rgb888(bitmap,cliprect,tilecode+(2+(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4066 stv_vdp2_drawgfx_rgb888(bitmap,cliprect,tilecode+(3-(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4067 }
4068 else if ( stv2_current_tilemap.colour_depth == 3 )
4069 {
4070 /* normal */
4071 stv_vdp2_drawgfx_rgb555(bitmap,cliprect,tilecode+(0+(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos, drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4072 stv_vdp2_drawgfx_rgb555(bitmap,cliprect,tilecode+(1-(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4073 stv_vdp2_drawgfx_rgb555(bitmap,cliprect,tilecode+(2+(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4074 stv_vdp2_drawgfx_rgb555(bitmap,cliprect,tilecode+(3-(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4075 }
4076 else if (stv2_current_tilemap.transparency & STV_TRANSPARENCY_ALPHA)
4077 {
4078 /* alpha */
4079 stv_vdp2_drawgfx_alpha(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos, drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4080 stv_vdp2_drawgfx_alpha(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4081 stv_vdp2_drawgfx_alpha(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4082 stv_vdp2_drawgfx_alpha(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4083 }
4084 else
4085 {
4086 /* normal */
4087 stv_vdp2_drawgfx_transpen(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos, drawypos,stv2_current_tilemap.transparency);
4088 stv_vdp2_drawgfx_transpen(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos,stv2_current_tilemap.transparency);
4089 stv_vdp2_drawgfx_transpen(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos,drawypos+8,stv2_current_tilemap.transparency);
4090 stv_vdp2_drawgfx_transpen(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,stv2_current_tilemap.transparency);
4091 }
4092 }
4093 else
4094 {
4095 if ( stv2_current_tilemap.colour_depth == 4)
4096 {
4097 stv_vdp2_drawgfx_rgb888(bitmap,cliprect,tilecode,flipyx&1,flipyx&2,drawxpos,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4098 }
4099 else if ( stv2_current_tilemap.colour_depth == 3)
4100 {
4101 stv_vdp2_drawgfx_rgb555(bitmap,cliprect,tilecode,flipyx&1,flipyx&2,drawxpos,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4102 }
4103 else
4104 {
4105 if (stv2_current_tilemap.transparency & STV_TRANSPARENCY_ALPHA)
4106 stv_vdp2_drawgfx_alpha(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode,pal,flipyx&1,flipyx&2, drawxpos, drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4107 else
4108 stv_vdp2_drawgfx_transpen(bitmap,cliprect,m_gfxdecode->gfx(gfx),tilecode,pal,flipyx&1,flipyx&2, drawxpos, drawypos,stv2_current_tilemap.transparency);
4109 }
4110 }
4111 drawxpos = olddrawxpos;
4112 drawypos = olddrawypos;
4113 }
4114 /* DRAWN?! */
4115
4116 }
4117 }
4118 if ( stv2_current_tilemap.layer_name & 0x80 )
4119 {
4120 static const int shifttable[4] = {0,1,2,2};
4121 int uppermask, uppermaskshift;
4122 int mapsize;
4123 uppermaskshift = (1-stv2_current_tilemap.pattern_data_size) | ((1-stv2_current_tilemap.tile_size)<<1);
4124 uppermask = 0x1ff >> uppermaskshift;
4125
4126 if ( LOG_VDP2 )
4127 {
4128 logerror( "Layer RBG%d, size %d x %d\n", stv2_current_tilemap.layer_name & 0x7f, cliprect.right() + 1, cliprect.bottom() + 1 );
4129 logerror( "Tiles: min %08X, max %08X\n", tilecodemin, tilecodemax );
4130 logerror( "MAP size in dwords %08X\n", mpsize_dwords );
4131 for (i = 0; i < stv2_current_tilemap.map_count; i++)
4132 {
4133 logerror( "Map register %d: base %08X\n", stv2_current_tilemap.map_offset[i], base[i] );
4134 }
4135 }
4136
4137 // store map information
4138 stv_vdp2_layer_data_placement.map_offset_min = 0x7fffffff;
4139 stv_vdp2_layer_data_placement.map_offset_max = 0x00000000;
4140
4141 for (i = 0; i < stv2_current_tilemap.map_count; i++)
4142 {
4143 uint32_t max_base;
4144
4145 if ( base[i] < stv_vdp2_layer_data_placement.map_offset_min )
4146 stv_vdp2_layer_data_placement.map_offset_min = base[i];
4147
4148 // Head On in Sega Memorial Collection 1 cares (uses RBG0 with all map regs equal to 0x20)
4149 max_base = (base[i] + plsize_bytes/4);
4150 if ( max_base > stv_vdp2_layer_data_placement.map_offset_max )
4151 stv_vdp2_layer_data_placement.map_offset_max = max_base;
4152 }
4153
4154
4155 mapsize = ((1 & uppermask) >> shifttable[stv2_current_tilemap.plane_size]) * plsize_bytes -
4156 ((0 & uppermask) >> shifttable[stv2_current_tilemap.plane_size]) * plsize_bytes;
4157 mapsize /= 4;
4158
4159 stv_vdp2_layer_data_placement.map_offset_max += mapsize;
4160
4161 stv_vdp2_layer_data_placement.tile_offset_min = tilecodemin * 0x20 / 4;
4162 stv_vdp2_layer_data_placement.tile_offset_max = (tilecodemax + 1) * 0x20 / 4;
4163 }
4164
4165 }
4166
4167 #define STV_VDP2_READ_VERTICAL_LINESCROLL( _val, _address ) \
4168 { \
4169 _val = m_vdp2_vram[ _address ]; \
4170 _val &= 0x07ffff00; \
4171 if ( _val & 0x04000000 ) _val |= 0xf8000000; \
4172 }
4173
4174
stv_vdp2_check_tilemap_with_linescroll(bitmap_rgb32 & bitmap,const rectangle & cliprect)4175 void saturn_state::stv_vdp2_check_tilemap_with_linescroll(bitmap_rgb32 &bitmap, const rectangle &cliprect)
4176 {
4177 rectangle mycliprect;
4178 int cur_line = cliprect.top();
4179 int address;
4180 int active_functions = 0;
4181 int32_t scroll_values[3], prev_scroll_values[3];
4182 int i;
4183 int scroll_values_equal;
4184 int lines;
4185 int16_t main_scrollx, main_scrolly;
4186 // int32_t incx;
4187 int linescroll_enable, vertical_linescroll_enable, linezoom_enable;
4188 int vertical_linescroll_index = -1;
4189
4190 // read original scroll values
4191 main_scrollx = stv2_current_tilemap.scrollx;
4192 main_scrolly = stv2_current_tilemap.scrolly;
4193 // incx = stv2_current_tilemap.incx;
4194
4195 // prepare linescroll flags
4196 linescroll_enable = stv2_current_tilemap.linescroll_enable;
4197 // stv2_current_tilemap.linescroll_enable = 0;
4198 vertical_linescroll_enable = stv2_current_tilemap.vertical_linescroll_enable;
4199 // stv2_current_tilemap.vertical_linescroll_enable = 0;
4200 linezoom_enable = stv2_current_tilemap.linezoom_enable;
4201 // stv2_current_tilemap.linezoom_enable = 0;
4202
4203 // prepare working clipping rectangle
4204 memcpy( &mycliprect, &cliprect, sizeof(rectangle) );
4205
4206 // calculate the number of active functions
4207 if ( linescroll_enable ) active_functions++;
4208 if ( vertical_linescroll_enable )
4209 {
4210 vertical_linescroll_index = active_functions;
4211 active_functions++;
4212 }
4213 if ( linezoom_enable ) active_functions++;
4214
4215 // address of data table
4216 address = stv2_current_tilemap.linescroll_table_address + active_functions*4*cliprect.top();
4217
4218 // get the first scroll values
4219 for ( i = 0; i < active_functions; i++ )
4220 {
4221 if ( i == vertical_linescroll_index )
4222 {
4223 STV_VDP2_READ_VERTICAL_LINESCROLL( prev_scroll_values[i], (address / 4) + i );
4224 prev_scroll_values[i] -= (cur_line * stv2_current_tilemap.incy);
4225 }
4226 else
4227 {
4228 prev_scroll_values[i] = m_vdp2_vram[ (address / 4) + i ];
4229 }
4230 }
4231
4232 while( cur_line <= cliprect.bottom() )
4233 {
4234 lines = 0;
4235 do
4236 {
4237 // update address
4238 address += active_functions*4;
4239
4240 // update lines count
4241 lines += stv2_current_tilemap.linescroll_interval;
4242
4243 // get scroll values
4244 for ( i = 0; i < active_functions; i++ )
4245 {
4246 if ( i == vertical_linescroll_index )
4247 {
4248 STV_VDP2_READ_VERTICAL_LINESCROLL( scroll_values[i], (address/4) + i );
4249 scroll_values[i] -= (cur_line + lines) * stv2_current_tilemap.incy;
4250 }
4251 else
4252 {
4253 scroll_values[i] = m_vdp2_vram[ (address / 4) + i ];
4254 }
4255 }
4256
4257 // compare scroll values
4258 scroll_values_equal = 1;
4259 for ( i = 0; i < active_functions; i++ )
4260 {
4261 scroll_values_equal &= (scroll_values[i] == prev_scroll_values[i]);
4262 }
4263 } while( scroll_values_equal && ((cur_line + lines) <= cliprect.bottom()) );
4264
4265 // determined how many lines can be drawn
4266 // prepare clipping rectangle
4267 mycliprect.sety(cur_line, cur_line + lines - 1);
4268
4269 // prepare scroll values
4270 i = 0;
4271 // linescroll
4272 if ( linescroll_enable )
4273 {
4274 prev_scroll_values[i] &= 0x07ffff00;
4275 if ( prev_scroll_values[i] & 0x04000000 ) prev_scroll_values[i] |= 0xf8000000;
4276 stv2_current_tilemap.scrollx = main_scrollx + (prev_scroll_values[i] >> 16);
4277 i++;
4278 }
4279 // vertical line scroll
4280 if ( vertical_linescroll_enable )
4281 {
4282 stv2_current_tilemap.scrolly = main_scrolly + (prev_scroll_values[i] >> 16);
4283 i++;
4284 }
4285
4286 // linezooom
4287 if ( linezoom_enable )
4288 {
4289 prev_scroll_values[i] &= 0x0007ff00;
4290 if ( prev_scroll_values[i] & 0x00040000 ) prev_scroll_values[i] |= 0xfff80000;
4291 stv2_current_tilemap.incx = prev_scroll_values[i];
4292 i++;
4293 }
4294
4295 // if ( LOG_VDP2 ) logerror( "Linescroll: y < %d, %d >, scrollx = %d, scrolly = %d, incx = %f\n", mycliprect.top(), mycliprect.bottom(), stv2_current_tilemap.scrollx, stv2_current_tilemap.scrolly, (float)stv2_current_tilemap.incx/65536.0 );
4296 // render current tilemap portion
4297 if (stv2_current_tilemap.bitmap_enable) // this layer is a bitmap
4298 {
4299 stv_vdp2_draw_basic_bitmap(bitmap, mycliprect);
4300 }
4301 else
4302 {
4303 //stv_vdp2_apply_window_on_layer(mycliprect);
4304 stv_vdp2_draw_basic_tilemap(bitmap, mycliprect);
4305 }
4306
4307 // update parameters for next iteration
4308 memcpy( prev_scroll_values, scroll_values, sizeof(scroll_values));
4309 cur_line += lines;
4310 }
4311 }
4312
stv_vdp2_draw_line(bitmap_rgb32 & bitmap,const rectangle & cliprect)4313 void saturn_state::stv_vdp2_draw_line(bitmap_rgb32 &bitmap, const rectangle &cliprect)
4314 {
4315 int x,y;
4316 uint8_t* gfxdata = m_vdp2.gfx_decode.get();
4317 uint32_t base_offs,base_mask;
4318 uint32_t pix;
4319 uint8_t interlace;
4320
4321 interlace = (STV_VDP2_LSMD == 3)+1;
4322
4323 {
4324 base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
4325
4326 for(y=cliprect.top();y<=cliprect.bottom();y++)
4327 {
4328 base_offs = (STV_VDP2_LCTA & base_mask) << 1;
4329
4330 if(STV_VDP2_LCCLMD)
4331 base_offs += (y / interlace) << 1;
4332
4333 for(x=cliprect.left();x<=cliprect.right();x++)
4334 {
4335 uint16_t pen;
4336
4337 pen = (gfxdata[base_offs+0]<<8)|gfxdata[base_offs+1];
4338 pix = bitmap.pix(y, x);
4339
4340 bitmap.pix(y, x) = add_blend_r32(m_palette->pen(pen & 0x7ff),pix);
4341 }
4342 }
4343 }
4344 }
4345
stv_vdp2_draw_mosaic(bitmap_rgb32 & bitmap,const rectangle & cliprect,uint8_t is_roz)4346 void saturn_state::stv_vdp2_draw_mosaic(bitmap_rgb32 &bitmap, const rectangle &cliprect, uint8_t is_roz)
4347 {
4348 uint8_t h_size = STV_VDP2_MZSZH+1;
4349 uint8_t v_size = STV_VDP2_MZSZV+1;
4350
4351 if(is_roz)
4352 v_size = 1;
4353
4354 if(h_size == 1 && v_size == 1)
4355 return; // don't bother
4356
4357 if(STV_VDP2_LSMD == 3)
4358 v_size <<= 1;
4359
4360 for(int y=cliprect.top();y<=cliprect.bottom();y+=v_size)
4361 {
4362 for(int x=cliprect.left();x<=cliprect.right();x+=h_size)
4363 {
4364 uint32_t pix = bitmap.pix(y, x);
4365
4366 for(int yi=0;yi<v_size;yi++)
4367 for(int xi=0;xi<h_size;xi++)
4368 bitmap.pix(y+yi, x+xi) = pix;
4369 }
4370 }
4371 }
4372
stv_vdp2_check_tilemap(bitmap_rgb32 & bitmap,const rectangle & cliprect)4373 void saturn_state::stv_vdp2_check_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
4374 {
4375 /* the idea is here we check the tilemap capabilities / whats enabled and call an appropriate tilemap drawing routine, or
4376 at the very list throw up a few errors if the tilemaps want to do something we don't support yet */
4377 // int window_applied = 0;
4378 rectangle mycliprect = cliprect;
4379
4380 if ( stv2_current_tilemap.linescroll_enable ||
4381 stv2_current_tilemap.vertical_linescroll_enable ||
4382 stv2_current_tilemap.linezoom_enable ||
4383 stv2_current_tilemap.vertical_cell_scroll_enable)
4384 {
4385 // check for vertical cell scroll enable (Sonic Jam)
4386 // TODO: it is unknown how this works with vertical linescroll enable too (probably it doesn't?)
4387 if(stv2_current_tilemap.vertical_cell_scroll_enable)
4388 {
4389 uint32_t vcsc_address;
4390 uint32_t base_mask;
4391 int base_offset, base_multiplier;
4392 int16_t base_scrollx, base_scrolly;
4393 //uint32_t base_incx, base_incy;
4394 int cur_char = 0;
4395
4396 base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
4397 vcsc_address = (((STV_VDP2_VCSTAU << 16) | STV_VDP2_VCSTAL) & base_mask) * 2;
4398 vcsc_address >>= 2;
4399
4400 base_offset = 0;
4401 base_multiplier = 1;
4402 // offset for both enabled
4403 if(STV_VDP2_N0VCSC && STV_VDP2_N1VCSC)
4404 {
4405 // NBG1
4406 if(stv2_current_tilemap.layer_name & 1)
4407 base_offset = 1;
4408
4409 base_multiplier = 2;
4410 }
4411
4412 base_scrollx = stv2_current_tilemap.scrollx;
4413 base_scrolly = stv2_current_tilemap.scrolly;
4414 //base_incx = stv2_current_tilemap.incx;
4415 //base_incy = stv2_current_tilemap.incy;
4416
4417 while(cur_char <= cliprect.right())
4418 {
4419 mycliprect.setx(cur_char, cur_char + 8 - 1);
4420
4421 uint32_t cur_address;
4422 int16_t char_scroll;
4423
4424 cur_address = vcsc_address;
4425 cur_address += ((cur_char >> 3) * base_multiplier) + base_offset;
4426
4427 char_scroll = m_vdp2_vram[ cur_address ] >> 16;
4428 char_scroll &= 0x07ff;
4429 if ( char_scroll & 0x0400 ) char_scroll |= 0xf800;
4430 stv2_current_tilemap.scrollx = base_scrollx;
4431 stv2_current_tilemap.scrolly = base_scrolly + (char_scroll);
4432 //stv2_current_tilemap.incx = base_incx;
4433 //stv2_current_tilemap.incy = base_incy;
4434
4435 stv_vdp2_check_tilemap_with_linescroll(bitmap, mycliprect);
4436
4437 // TODO: + 16 for tilemap and char size = 16?
4438 cur_char += 8;
4439
4440 }
4441 }
4442 else
4443 stv_vdp2_check_tilemap_with_linescroll(bitmap, cliprect);
4444
4445 return;
4446 }
4447
4448 if (stv2_current_tilemap.bitmap_enable) // this layer is a bitmap
4449 {
4450 stv_vdp2_draw_basic_bitmap(bitmap, mycliprect);
4451 }
4452 else
4453 {
4454 //stv_vdp2_apply_window_on_layer(mycliprect);
4455 stv_vdp2_draw_basic_tilemap(bitmap, mycliprect);
4456 }
4457
4458 /* post-processing functions */
4459 // (TODO: needs layer bitmaps to be individual planes to work correctly)
4460 if(stv2_current_tilemap.line_screen_enabled && TEST_FUNCTIONS)
4461 stv_vdp2_draw_line(bitmap,cliprect);
4462
4463 if(stv2_current_tilemap.mosaic_screen_enabled && TEST_FUNCTIONS)
4464 stv_vdp2_draw_mosaic(bitmap,cliprect,stv2_current_tilemap.layer_name & 0x80);
4465
4466
4467 {
4468 if(stv2_current_tilemap.colour_depth == 2 && !stv2_current_tilemap.bitmap_enable)
4469 popmessage("2048 color mode used on a non-bitmap plane");
4470
4471 // if(STV_VDP2_SCXDN0 || STV_VDP2_SCXDN1 || STV_VDP2_SCYDN0 || STV_VDP2_SCYDN1)
4472 // popmessage("Fractional part scrolling write, contact MAMEdev");
4473
4474 /* Pukunpa */
4475 //if(STV_VDP2_SPWINEN)
4476 // popmessage("Sprite Window enabled");
4477
4478 /* Capcom Collection Dai 2 - Choh Makaimura (Duh!) */
4479 if(STV_VDP2_MZCTL & 0x1f && POPMESSAGE_DEBUG)
4480 popmessage("Mosaic control enabled = %04x\n",STV_VDP2_MZCTL);
4481
4482 /* Bio Hazard bit 1 */
4483 /* Airs Adventure 0x3e */
4484 /* Bakuretsu Hunter */
4485 if(STV_VDP2_LNCLEN & ~2 && POPMESSAGE_DEBUG)
4486 popmessage("Line Colour screen enabled %04x %08x, contact MAMEdev",STV_VDP2_LNCLEN,STV_VDP2_LCTAU<<16|STV_VDP2_LCTAL);
4487
4488 /* Bio Hazard 0x400 = extended color calculation enabled */
4489 /* Advanced World War 0x200 = color calculation ratio mode */
4490 /* Whizz = 0x8100 */
4491 /* Dark Saviour = 0x9051 on save select screen (the one with a Saturn in the background) */
4492 if(STV_VDP2_CCCR & 0x6000)
4493 popmessage("Gradation enabled %04x, contact MAMEdev",STV_VDP2_CCCR);
4494
4495 /* Advanced VG, Shining Force III */
4496 if(STV_VDP2_SFCCMD && POPMESSAGE_DEBUG)
4497 popmessage("Special Color Calculation enable %04x, contact MAMEdev",STV_VDP2_SFCCMD);
4498
4499 /* Cleopatra Fortune Transparent Shadow */
4500 /* Pretty Fighter X Back & Transparent Shadow*/
4501 //if(STV_VDP2_SDCTL & 0x0120)
4502 // popmessage("%s shadow select bit enabled, contact MAMEdev",STV_VDP2_SDCTL & 0x100 ? "Transparent" : "Back");
4503
4504 /* Langrisser III bit 3 normal, bit 1 during battle field */
4505 /* Metal Slug bit 0 during gameplay */
4506 /* Bug! Sega Away Logo onward 0x470 */
4507 /* Command & Conquer 0x0004 0xc000 */
4508 if(STV_VDP2_SFSEL & ~0x47f)
4509 popmessage("Special Function Code Select enable %04x %04x, contact MAMEdev",STV_VDP2_SFSEL,STV_VDP2_SFCODE);
4510
4511 /* Albert Odyssey Gaiden 0x0001 */
4512 /* Asuka 120% 0x0101 */
4513 /* Slam n Jam 96 0x0003 */
4514 if(STV_VDP2_ZMCTL & 0x0200)
4515 popmessage("Reduction enable %04x, contact MAMEdev",STV_VDP2_ZMCTL);
4516
4517 /* Burning Rangers and friends FMV, J.League Pro Soccer Club Wo Tsukurou!! backgrounds */
4518 if(STV_VDP2_SCRCTL & 0x0101 && POPMESSAGE_DEBUG)
4519 popmessage("Vertical cell scroll enable %04x, contact MAMEdev",STV_VDP2_SCRCTL);
4520
4521 /* Magical Drop III 0x200 -> color calculation window */
4522 /* Ide Yousuke Meijin No Shin Jissen Mahjong 0x0303 */
4523 /* Decathlete 0x088 */
4524 /* Sexy Parodius 0x2300 */
4525 // if(STV_VDP2_WCTLD & 0x2000)
4526 // popmessage("Special window enabled %04x, contact MAMEdev",STV_VDP2_WCTLD);
4527
4528 /* Shining Force III, After Burner 2 (doesn't make a proper use tho?) */
4529 /* Layer Section */
4530 //if(STV_VDP2_W0LWE || STV_VDP2_W1LWE)
4531 // popmessage("Line Window %s %08x enabled, contact MAMEdev",STV_VDP2_W0LWE ? "0" : "1",STV_VDP2_W0LWTA);
4532
4533 /* Akumajou Dracula, bits 2-4 */
4534 /* Arcana Strikes bit 5 */
4535 /* Choh Makai Mura 0x0055 */
4536 /* Sega Rally 0x0155 */
4537 /* Find Love 0x4400 */
4538 /* Dragon Ball Z 0x3800 - 0x2c00 */
4539 /* Assault Suit Leynos 2 0x0200*/
4540 /* Bug! 0x8800 */
4541 /* Wonder 3 0x0018 */
4542 if(STV_VDP2_SFPRMD & ~0xff7f)
4543 popmessage("Special Priority Mode enabled %04x, contact MAMEdev",STV_VDP2_SFPRMD);
4544 }
4545 }
4546
4547
stv_vdp2_copy_roz_bitmap(bitmap_rgb32 & bitmap,bitmap_rgb32 & roz_bitmap,const rectangle & cliprect,int iRP,int planesizex,int planesizey,int planerenderedsizex,int planerenderedsizey)4548 void saturn_state::stv_vdp2_copy_roz_bitmap(bitmap_rgb32 &bitmap,
4549 bitmap_rgb32 &roz_bitmap,
4550 const rectangle &cliprect,
4551 int iRP,
4552 int planesizex,
4553 int planesizey,
4554 int planerenderedsizex,
4555 int planerenderedsizey)
4556 {
4557 int32_t xsp, ysp, xp, yp, dx, dy, x, y, xs, ys, dxs, dys;
4558 int32_t vcnt, hcnt;
4559 int32_t kx, ky;
4560 int8_t use_coeff_table, coeff_table_mode, coeff_table_size, coeff_table_shift;
4561 int8_t screen_over_process;
4562 uint8_t vcnt_shift, hcnt_shift;
4563 uint8_t coeff_msb;
4564 uint32_t *coeff_table_base, coeff_table_offset;
4565 int32_t coeff_table_val;
4566 uint32_t address;
4567 uint32_t *line;
4568 rgb_t pix;
4569 //uint32_t coeff_line_color_screen_data;
4570 int32_t clipxmask = 0, clipymask = 0;
4571
4572
4573 vcnt_shift = ((STV_VDP2_LSMD & 3) == 3);
4574 hcnt_shift = ((STV_VDP2_HRES & 2) == 2);
4575
4576 planesizex--;
4577 planesizey--;
4578 planerenderedsizex--;
4579 planerenderedsizey--;
4580
4581 kx = RP.kx;
4582 ky = RP.ky;
4583
4584 use_coeff_table = coeff_table_mode = coeff_table_size = coeff_table_shift = 0;
4585 coeff_table_offset = 0;
4586 coeff_table_val = 0;
4587 coeff_table_base = nullptr;
4588
4589 if ( LOG_ROZ == 1 ) logerror( "Rendering RBG with parameter %s\n", iRP == 1 ? "A" : "B" );
4590 if ( LOG_ROZ == 1 ) logerror( "RPMD (parameter mode) = %x\n", STV_VDP2_RPMD );
4591 if ( LOG_ROZ == 1 ) logerror( "RPRCTL (parameter read control) = %04x\n", STV_VDP2_RPRCTL );
4592 if ( LOG_ROZ == 1 ) logerror( "KTCTL (coefficient table control) = %04x\n", STV_VDP2_KTCTL );
4593 if ( LOG_ROZ == 1 ) logerror( "KTAOF (coefficient table address offset) = %04x\n", STV_VDP2_KTAOF );
4594 if ( LOG_ROZ == 1 ) logerror( "RAOVR (screen-over process) = %x\n", STV_VDP2_RAOVR );
4595 if ( iRP == 1 )
4596 {
4597 use_coeff_table = STV_VDP2_RAKTE;
4598 if ( use_coeff_table == 1 )
4599 {
4600 coeff_table_mode = STV_VDP2_RAKMD;
4601 coeff_table_size = STV_VDP2_RAKDBS;
4602 coeff_table_offset = STV_VDP2_RAKTAOS;
4603 }
4604 screen_over_process = STV_VDP2_RAOVR;
4605 }
4606 else
4607 {
4608 use_coeff_table = STV_VDP2_RBKTE;
4609 if ( use_coeff_table == 1 )
4610 {
4611 coeff_table_mode = STV_VDP2_RBKMD;
4612 coeff_table_size = STV_VDP2_RBKDBS;
4613 coeff_table_offset = STV_VDP2_RBKTAOS;
4614 }
4615 screen_over_process = STV_VDP2_RBOVR;
4616 }
4617 if ( use_coeff_table )
4618 {
4619 if ( STV_VDP2_CRKTE == 0 )
4620 {
4621 coeff_table_base = m_vdp2_vram.get();
4622 }
4623 else
4624 {
4625 coeff_table_base = m_vdp2_cram.get();
4626 }
4627 if ( coeff_table_size == 0 )
4628 {
4629 coeff_table_offset = (coeff_table_offset & 0x0003) * 0x40000;
4630 coeff_table_shift = 2;
4631 }
4632 else
4633 {
4634 coeff_table_offset = (coeff_table_offset & 0x0007) * 0x20000;
4635 coeff_table_shift = 1;
4636 }
4637 }
4638
4639 if ( stv2_current_tilemap.colour_calculation_enabled == 1 )
4640 {
4641 if ( STV_VDP2_CCMD )
4642 {
4643 stv2_current_tilemap.transparency |= STV_TRANSPARENCY_ADD_BLEND;
4644 }
4645 else
4646 {
4647 stv2_current_tilemap.transparency |= STV_TRANSPARENCY_ALPHA;
4648 }
4649 }
4650
4651 /* clipping */
4652 switch( screen_over_process )
4653 {
4654 case 0:
4655 /* repeated */
4656 clipxmask = clipymask = 0;
4657 break;
4658 case 1:
4659 /* screen over pattern */
4660 // TODO: not supported, cfr. STV_VDP2_OVPNRA / STV_VDP2_OVPNRB
4661 // D-Xhird uses this on practice stage
4662 clipxmask = ~planesizex;
4663 clipymask = ~planesizey;
4664 break;
4665 case 2:
4666 /* outside display area, scroll screen is transparent */
4667 clipxmask = ~planesizex;
4668 clipymask = ~planesizey;
4669 break;
4670 case 3:
4671 /* display area is 512x512, outside is transparent */
4672 clipxmask = ~511;
4673 clipymask = ~511;
4674 break;
4675 }
4676
4677 //dx = (RP.A * RP.dx) + (RP.B * RP.dy);
4678 //dy = (RP.D * RP.dx) + (RP.E * RP.dy);
4679 dx = mul_fixed32( RP.A, RP.dx ) + mul_fixed32( RP.B, RP.dy );
4680 dy = mul_fixed32( RP.D, RP.dx ) + mul_fixed32( RP.E, RP.dy );
4681
4682 //xp = RP.A * ( RP.px - RP.cx ) + RP.B * ( RP.py - RP.cy ) + RP.C * ( RP.pz - RP.cz ) + RP.cx + RP.mx;
4683 //yp = RP.D * ( RP.px - RP.cx ) + RP.E * ( RP.py - RP.cy ) + RP.F * ( RP.pz - RP.cz ) + RP.cy + RP.my;
4684 xp = mul_fixed32( RP.A, RP.px - RP.cx ) + mul_fixed32( RP.B, RP.py - RP.cy ) + mul_fixed32( RP.C, RP.pz - RP.cz ) + RP.cx + RP.mx;
4685 yp = mul_fixed32( RP.D, RP.px - RP.cx ) + mul_fixed32( RP.E, RP.py - RP.cy ) + mul_fixed32( RP.F, RP.pz - RP.cz ) + RP.cy + RP.my;
4686
4687 for (vcnt = cliprect.top(); vcnt <= cliprect.bottom(); vcnt++ )
4688 {
4689 /*xsp = RP.A * ( ( RP.xst + RP.dxst * (vcnt << 16) ) - RP.px ) +
4690 RP.B * ( ( RP.yst + RP.dyst * (vcnt << 16) ) - RP.py ) +
4691 RP.C * ( RP.zst - RP.pz);
4692 ysp = RP.D * ( ( RP.xst + RP.dxst * (vcnt << 16) ) - RP.px ) +
4693 RP.E * ( ( RP.yst + RP.dyst * (vcnt << 16) ) - RP.py ) +
4694 RP.F * ( RP.zst - RP.pz );*/
4695 xsp = mul_fixed32( RP.A, RP.xst + mul_fixed32( RP.dxst, vcnt << (16 - vcnt_shift)) - RP.px ) +
4696 mul_fixed32( RP.B, RP.yst + mul_fixed32( RP.dyst, vcnt << (16 - vcnt_shift)) - RP.py ) +
4697 mul_fixed32( RP.C, RP.zst - RP.pz );
4698 ysp = mul_fixed32( RP.D, RP.xst + mul_fixed32( RP.dxst, vcnt << (16 - vcnt_shift)) - RP.px ) +
4699 mul_fixed32( RP.E, RP.yst + mul_fixed32( RP.dyst, vcnt << (16 - vcnt_shift)) - RP.py ) +
4700 mul_fixed32( RP.F, RP.zst - RP.pz );
4701 //xp = RP.A * ( RP.px - RP.cx ) + RP.B * ( RP.py - RP.cy ) + RP.C * ( RP.pz - RP.cz ) + RP.cx + RP.mx;
4702 //yp = RP.D * ( RP.px - RP.cx ) + RP.E * ( RP.py - RP.cy ) + RP.F * ( RP.pz - RP.cz ) + RP.cy + RP.my;
4703 //dx = (RP.A * RP.dx) + (RP.B * RP.dy);
4704 //dy = (RP.D * RP.dx) + (RP.E * RP.dy);
4705
4706 line = &bitmap.pix(vcnt);
4707
4708 // TODO: nuke this spaghetti code
4709 if ( !use_coeff_table || RP.dkax == 0 )
4710 {
4711 if ( use_coeff_table )
4712 {
4713 switch( coeff_table_size )
4714 {
4715 case 0:
4716 address = coeff_table_offset + ((RP.kast + RP.dkast*(vcnt>>vcnt_shift)) >> 16) * 4;
4717 coeff_table_val = coeff_table_base[ address / 4 ];
4718 //coeff_line_color_screen_data = (coeff_table_val & 0x7f000000) >> 24;
4719 coeff_msb = (coeff_table_val & 0x80000000) > 0;
4720 if ( coeff_table_val & 0x00800000 )
4721 {
4722 coeff_table_val |= 0xff000000;
4723 }
4724 else
4725 {
4726 coeff_table_val &= 0x007fffff;
4727 }
4728 break;
4729 case 1:
4730 address = coeff_table_offset + ((RP.kast + RP.dkast*(vcnt>>vcnt_shift)) >> 16) * 2;
4731 coeff_table_val = coeff_table_base[ address / 4 ];
4732 if ( (address & 2) == 0 )
4733 {
4734 coeff_table_val >>= 16;
4735 }
4736 coeff_table_val &= 0xffff;
4737 //coeff_line_color_screen_data = 0;
4738 coeff_msb = (coeff_table_val & 0x8000) > 0;
4739 if ( coeff_table_val & 0x4000 )
4740 {
4741 coeff_table_val |= 0xffff8000;
4742 }
4743 else
4744 {
4745 coeff_table_val &= 0x3fff;
4746 }
4747 coeff_table_val <<= 6; /* to form 16.16 fixed point val */
4748 break;
4749 default:
4750 coeff_msb = 1;
4751 break;
4752 }
4753 if ( coeff_msb ) continue;
4754
4755 switch( coeff_table_mode )
4756 {
4757 case 0:
4758 kx = ky = coeff_table_val;
4759 break;
4760 case 1:
4761 kx = coeff_table_val;
4762 break;
4763 case 2:
4764 ky = coeff_table_val;
4765 break;
4766 case 3:
4767 xp = coeff_table_val;
4768 break;
4769 }
4770 }
4771
4772 //x = RP.kx * ( xsp + dx * (hcnt << 16)) + xp;
4773 //y = RP.ky * ( ysp + dy * (hcnt << 16)) + yp;
4774 xs = mul_fixed32( kx, xsp ) + xp;
4775 ys = mul_fixed32( ky, ysp ) + yp;
4776 dxs = mul_fixed32( kx, mul_fixed32( dx, 1 << (16-hcnt_shift)));
4777 dys = mul_fixed32( ky, mul_fixed32( dy, 1 << (16-hcnt_shift)));
4778
4779 for (hcnt = cliprect.left(); hcnt <= cliprect.right(); xs+=dxs, ys+=dys, hcnt++ )
4780 {
4781 x = xs >> 16;
4782 y = ys >> 16;
4783
4784 if ( x & clipxmask || y & clipymask ) continue;
4785 if ( stv_vdp2_roz_window(hcnt, vcnt) == false )
4786 continue;
4787
4788 if ( stv2_current_tilemap.roz_mode3 == true )
4789 {
4790 if( stv_vdp2_roz_mode3_window(hcnt, vcnt, iRP-1) == false )
4791 continue;
4792 }
4793
4794 pix = roz_bitmap.pix(y & planerenderedsizey, x & planerenderedsizex);
4795 if (stv2_current_tilemap.transparency & STV_TRANSPARENCY_ALPHA)
4796 {
4797 if ((stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE) || (pix & 0xffffff))
4798 {
4799 if(stv2_current_tilemap.fade_control & 1)
4800 stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
4801
4802 line[hcnt] = alpha_blend_r32( line[hcnt], pix, stv2_current_tilemap.alpha );
4803 }
4804 }
4805 else if (stv2_current_tilemap.transparency & STV_TRANSPARENCY_ADD_BLEND)
4806 {
4807 if ((stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE) || (pix & 0xffffff))
4808 {
4809 if(stv2_current_tilemap.fade_control & 1)
4810 stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
4811
4812 line[hcnt] = add_blend_r32( line[hcnt], pix );
4813 }
4814 }
4815 else
4816 {
4817 if ((stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE) || (pix & 0xffffff))
4818 {
4819 if(stv2_current_tilemap.fade_control & 1)
4820 stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
4821
4822 line[hcnt] = pix;
4823 }
4824 }
4825 }
4826 }
4827 else
4828 {
4829 for (hcnt = cliprect.left(); hcnt <= cliprect.right(); hcnt++ )
4830 {
4831 switch( coeff_table_size )
4832 {
4833 case 0:
4834 address = coeff_table_offset + ((RP.kast + RP.dkast*(vcnt>>vcnt_shift) + RP.dkax*hcnt) >> 16) * 4;
4835 coeff_table_val = coeff_table_base[ address / 4 ];
4836 //coeff_line_color_screen_data = (coeff_table_val & 0x7f000000) >> 24;
4837 coeff_msb = (coeff_table_val & 0x80000000) > 0;
4838 if ( coeff_table_val & 0x00800000 )
4839 {
4840 coeff_table_val |= 0xff000000;
4841 }
4842 else
4843 {
4844 coeff_table_val &= 0x007fffff;
4845 }
4846 break;
4847 case 1:
4848 address = coeff_table_offset + ((RP.kast + RP.dkast*(vcnt>>vcnt_shift) + RP.dkax*hcnt) >> 16) * 2;
4849 coeff_table_val = coeff_table_base[ address / 4 ];
4850 if ( (address & 2) == 0 )
4851 {
4852 coeff_table_val >>= 16;
4853 }
4854 coeff_table_val &= 0xffff;
4855 //coeff_line_color_screen_data = 0;
4856 coeff_msb = (coeff_table_val & 0x8000) > 0;
4857 if ( coeff_table_val & 0x4000 )
4858 {
4859 coeff_table_val |= 0xffff8000;
4860 }
4861 else
4862 {
4863 coeff_table_val &= 0x3fff;
4864 }
4865 coeff_table_val <<= 6; /* to form 16.16 fixed point val */
4866 break;
4867 default:
4868 coeff_msb = 1;
4869 break;
4870 }
4871 if ( coeff_msb ) continue;
4872 switch( coeff_table_mode )
4873 {
4874 case 0:
4875 kx = ky = coeff_table_val;
4876 break;
4877 case 1:
4878 kx = coeff_table_val;
4879 break;
4880 case 2:
4881 ky = coeff_table_val;
4882 break;
4883 case 3:
4884 xp = coeff_table_val;
4885 break;
4886 }
4887
4888 //x = RP.kx * ( xsp + dx * (hcnt << 16)) + xp;
4889 //y = RP.ky * ( ysp + dy * (hcnt << 16)) + yp;
4890 x = mul_fixed32( kx, xsp + mul_fixed32( dx, (hcnt>>hcnt_shift) << 16 ) ) + xp;
4891 y = mul_fixed32( ky, ysp + mul_fixed32( dy, (hcnt>>hcnt_shift) << 16 ) ) + yp;
4892
4893 x >>= 16;
4894 y >>= 16;
4895
4896 if ( x & clipxmask || y & clipymask ) continue;
4897
4898 pix = roz_bitmap.pix(y & planerenderedsizey, x & planerenderedsizex);
4899 if (stv2_current_tilemap.transparency & STV_TRANSPARENCY_ALPHA)
4900 {
4901 if ((stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE) || (pix & 0xffffff))
4902 {
4903 if(stv2_current_tilemap.fade_control & 1)
4904 stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
4905
4906 line[hcnt] = alpha_blend_r32( line[hcnt], pix, stv2_current_tilemap.alpha );
4907 }
4908 }
4909 else if (stv2_current_tilemap.transparency & STV_TRANSPARENCY_ADD_BLEND)
4910 {
4911 if ((stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE) || (pix & 0xffffff))
4912 {
4913 if(stv2_current_tilemap.fade_control & 1)
4914 stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
4915
4916 line[hcnt] = add_blend_r32( line[hcnt], pix );
4917 }
4918 }
4919 else
4920 {
4921 if ((stv2_current_tilemap.transparency & STV_TRANSPARENCY_NONE) || (pix & 0xffffff))
4922 {
4923 if(stv2_current_tilemap.fade_control & 1)
4924 stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
4925
4926 line[hcnt] = pix;
4927 }
4928 }
4929 }
4930 }
4931 }
4932 }
4933
stv_vdp2_roz_window(int x,int y)4934 inline bool saturn_state::stv_vdp2_roz_window(int x, int y)
4935 {
4936 int s_x=0,e_x=0,s_y=0,e_y=0;
4937 int w0_pix, w1_pix;
4938 uint8_t logic = STV_VDP2_R0LOG;
4939 uint8_t w0_enable = STV_VDP2_R0W0E;
4940 uint8_t w1_enable = STV_VDP2_R0W1E;
4941 uint8_t w0_area = STV_VDP2_R0W0A;
4942 uint8_t w1_area = STV_VDP2_R0W1A;
4943
4944 if (w0_enable == 0 &&
4945 w1_enable == 0)
4946 return true;
4947
4948 stv_vdp2_get_window0_coordinates(&s_x, &e_x, &s_y, &e_y, y);
4949 w0_pix = get_roz_window_pixel(s_x,e_x,s_y,e_y,x,y,w0_enable, w0_area);
4950
4951 stv_vdp2_get_window1_coordinates(&s_x, &e_x, &s_y, &e_y, y);
4952 w1_pix = get_roz_window_pixel(s_x,e_x,s_y,e_y,x,y,w1_enable, w1_area);
4953
4954 return (logic & 1 ? (w0_pix | w1_pix) : (w0_pix & w1_pix));
4955 }
4956
stv_vdp2_roz_mode3_window(int x,int y,int rot_parameter)4957 inline bool saturn_state::stv_vdp2_roz_mode3_window(int x, int y, int rot_parameter)
4958 {
4959 int s_x=0,e_x=0,s_y=0,e_y=0;
4960 int w0_pix, w1_pix;
4961 uint8_t logic = STV_VDP2_RPLOG;
4962 uint8_t w0_enable = STV_VDP2_RPW0E;
4963 uint8_t w1_enable = STV_VDP2_RPW1E;
4964 uint8_t w0_area = STV_VDP2_RPW0A;
4965 uint8_t w1_area = STV_VDP2_RPW1A;
4966
4967 if (w0_enable == 0 &&
4968 w1_enable == 0)
4969 return rot_parameter ^ 1;
4970
4971 stv_vdp2_get_window0_coordinates(&s_x, &e_x, &s_y, &e_y, y);
4972 w0_pix = get_roz_window_pixel(s_x,e_x,s_y,e_y,x,y,w0_enable, w0_area);
4973
4974 stv_vdp2_get_window1_coordinates(&s_x, &e_x, &s_y, &e_y, y);
4975 w1_pix = get_roz_window_pixel(s_x,e_x,s_y,e_y,x,y,w1_enable, w1_area);
4976
4977 return (logic & 1 ? (w0_pix | w1_pix) : (w0_pix & w1_pix)) ^ rot_parameter;
4978 }
4979
get_roz_window_pixel(int s_x,int e_x,int s_y,int e_y,int x,int y,uint8_t winenable,uint8_t winarea)4980 inline int saturn_state::get_roz_window_pixel(int s_x,int e_x,int s_y,int e_y,int x, int y,uint8_t winenable, uint8_t winarea)
4981 {
4982 int res;
4983
4984 res = 1;
4985 if(winenable)
4986 {
4987 if(winarea)
4988 res = (y >= s_y && y <= e_y && x >= s_x && x <= e_x);
4989 else
4990 res = (y >= s_y && y <= e_y && x >= s_x && x <= e_x) ^ 1;
4991 }
4992
4993 return res;
4994 }
4995
4996
stv_vdp2_draw_NBG0(bitmap_rgb32 & bitmap,const rectangle & cliprect)4997 void saturn_state::stv_vdp2_draw_NBG0(bitmap_rgb32 &bitmap, const rectangle &cliprect)
4998 {
4999 uint32_t base_mask;
5000
5001 base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
5002
5003 /*
5004 Colours : 16, 256, 2048, 32768, 16770000
5005 Char Size : 1x1 cells, 2x2 cells
5006 Pattern Data Size : 1 word, 2 words
5007 Plane Layouts : 1 x 1, 2 x 1, 2 x 2
5008 Planes : 4
5009 Bitmap : Possible
5010 Bitmap Sizes : 512 x 256, 512 x 512, 1024 x 256, 1024 x 512
5011 Scale : 0.25 x - 256 x
5012 Rotation : No
5013 Linescroll : Yes
5014 Column Scroll : Yes
5015 Mosaic : Yes
5016 */
5017
5018 stv2_current_tilemap.enabled = STV_VDP2_N0ON | STV_VDP2_R1ON;
5019
5020 // if (!stv2_current_tilemap.enabled) return; // stop right now if its disabled ...
5021
5022 //stv2_current_tilemap.trans_enabled = STV_VDP2_N0TPON;
5023 if ( STV_VDP2_N0CCEN )
5024 {
5025 stv2_current_tilemap.colour_calculation_enabled = 1;
5026 stv2_current_tilemap.alpha = ((uint16_t)(0x1f-STV_VDP2_N0CCRT)*0xff)/0x1f;
5027 }
5028 else
5029 {
5030 stv2_current_tilemap.colour_calculation_enabled = 0;
5031 }
5032 if ( STV_VDP2_N0TPON == 0 )
5033 {
5034 stv2_current_tilemap.transparency = STV_TRANSPARENCY_PEN;
5035 }
5036 else
5037 {
5038 stv2_current_tilemap.transparency = STV_TRANSPARENCY_NONE;
5039 }
5040 stv2_current_tilemap.colour_depth = STV_VDP2_N0CHCN;
5041 stv2_current_tilemap.tile_size = STV_VDP2_N0CHSZ;
5042 stv2_current_tilemap.bitmap_enable = STV_VDP2_N0BMEN;
5043 stv2_current_tilemap.bitmap_size = STV_VDP2_N0BMSZ;
5044 stv2_current_tilemap.bitmap_palette_number = STV_VDP2_N0BMP;
5045 stv2_current_tilemap.bitmap_map = STV_VDP2_N0MP_;
5046 stv2_current_tilemap.map_offset[0] = STV_VDP2_N0MPA | (STV_VDP2_N0MP_ << 6);
5047 stv2_current_tilemap.map_offset[1] = STV_VDP2_N0MPB | (STV_VDP2_N0MP_ << 6);
5048 stv2_current_tilemap.map_offset[2] = STV_VDP2_N0MPC | (STV_VDP2_N0MP_ << 6);
5049 stv2_current_tilemap.map_offset[3] = STV_VDP2_N0MPD | (STV_VDP2_N0MP_ << 6);
5050 stv2_current_tilemap.map_count = 4;
5051
5052 stv2_current_tilemap.pattern_data_size = STV_VDP2_N0PNB;
5053 stv2_current_tilemap.character_number_supplement = STV_VDP2_N0CNSM;
5054 stv2_current_tilemap.special_priority_register = STV_VDP2_N0SPR;
5055 stv2_current_tilemap.special_colour_control_register = STV_VDP2_PNCN0;
5056 stv2_current_tilemap.supplementary_palette_bits = STV_VDP2_N0SPLT;
5057 stv2_current_tilemap.supplementary_character_bits = STV_VDP2_N0SPCN;
5058
5059 stv2_current_tilemap.scrollx = STV_VDP2_SCXIN0;
5060 stv2_current_tilemap.scrolly = STV_VDP2_SCYIN0;
5061 stv2_current_tilemap.incx = STV_VDP2_ZMXN0;
5062 stv2_current_tilemap.incy = STV_VDP2_ZMYN0;
5063
5064 stv2_current_tilemap.linescroll_enable = STV_VDP2_N0LSCX;
5065 stv2_current_tilemap.linescroll_interval = (((STV_VDP2_LSMD & 3) == 2) ? (2) : (1)) << (STV_VDP2_N0LSS);
5066 stv2_current_tilemap.linescroll_table_address = (((STV_VDP2_LSTA0U << 16) | STV_VDP2_LSTA0L) & base_mask) * 2;
5067 stv2_current_tilemap.vertical_linescroll_enable = STV_VDP2_N0LSCY;
5068 stv2_current_tilemap.linezoom_enable = STV_VDP2_N0LZMX;
5069 stv2_current_tilemap.vertical_cell_scroll_enable = STV_VDP2_N0VCSC;
5070
5071 stv2_current_tilemap.plane_size = (STV_VDP2_R1ON) ? STV_VDP2_RBPLSZ : STV_VDP2_N0PLSZ;
5072 stv2_current_tilemap.colour_ram_address_offset = STV_VDP2_N0CAOS;
5073 stv2_current_tilemap.fade_control = (STV_VDP2_N0COEN * 1) | (STV_VDP2_N0COSL * 2);
5074 stv_vdp2_check_fade_control_for_layer();
5075 stv2_current_tilemap.window_control.logic = STV_VDP2_N0LOG;
5076 stv2_current_tilemap.window_control.enabled[0] = STV_VDP2_N0W0E;
5077 stv2_current_tilemap.window_control.enabled[1] = STV_VDP2_N0W1E;
5078 // stv2_current_tilemap.window_control.? = STV_VDP2_N0SWE;
5079 stv2_current_tilemap.window_control.area[0] = STV_VDP2_N0W0A;
5080 stv2_current_tilemap.window_control.area[1] = STV_VDP2_N0W1A;
5081 // stv2_current_tilemap.window_control.? = STV_VDP2_N0SWA;
5082
5083 stv2_current_tilemap.line_screen_enabled = STV_VDP2_N0LCEN;
5084 stv2_current_tilemap.mosaic_screen_enabled = STV_VDP2_N0MZE;
5085
5086 stv2_current_tilemap.layer_name=(STV_VDP2_R1ON) ? 0x81 : 0;
5087
5088 if ( stv2_current_tilemap.enabled && (!(STV_VDP2_R1ON))) /* TODO: check cycle pattern for RBG1 */
5089 {
5090 stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( STV_VDP2_CP_NBG0_PNMDR, STV_VDP2_CP_NBG0_CPDR, stv2_current_tilemap.bitmap_enable );
5091 }
5092
5093 if(STV_VDP2_R1ON)
5094 stv_vdp2_draw_rotation_screen(bitmap, cliprect, 2 );
5095 else
5096 stv_vdp2_check_tilemap(bitmap, cliprect);
5097 }
5098
stv_vdp2_draw_NBG1(bitmap_rgb32 & bitmap,const rectangle & cliprect)5099 void saturn_state::stv_vdp2_draw_NBG1(bitmap_rgb32 &bitmap, const rectangle &cliprect)
5100 {
5101 uint32_t base_mask;
5102
5103 base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
5104
5105 /*
5106 Colours : 16, 256, 2048, 32768
5107 Char Size : 1x1 cells, 2x2 cells
5108 Pattern Data Size : 1 word, 2 words
5109 Plane Layouts : 1 x 1, 2 x 1, 2 x 2
5110 Planes : 4
5111 Bitmap : Possible
5112 Bitmap Sizes : 512 x 256, 512 x 512, 1024 x 256, 1024 x 512
5113 Scale : 0.25 x - 256 x
5114 Rotation : No
5115 Linescroll : Yes
5116 Column Scroll : Yes
5117 Mosaic : Yes
5118 */
5119 stv2_current_tilemap.enabled = STV_VDP2_N1ON;
5120
5121 // if (!stv2_current_tilemap.enabled) return; // stop right now if its disabled ...
5122
5123 //stv2_current_tilemap.trans_enabled = STV_VDP2_N1TPON;
5124 if ( STV_VDP2_N1CCEN )
5125 {
5126 stv2_current_tilemap.colour_calculation_enabled = 1;
5127 stv2_current_tilemap.alpha = ((uint16_t)(0x1f-STV_VDP2_N1CCRT)*0xff)/0x1f;
5128 }
5129 else
5130 {
5131 stv2_current_tilemap.colour_calculation_enabled = 0;
5132 }
5133 if ( STV_VDP2_N1TPON == 0 )
5134 {
5135 stv2_current_tilemap.transparency = STV_TRANSPARENCY_PEN;
5136 }
5137 else
5138 {
5139 stv2_current_tilemap.transparency = STV_TRANSPARENCY_NONE;
5140 }
5141 stv2_current_tilemap.colour_depth = STV_VDP2_N1CHCN;
5142 stv2_current_tilemap.tile_size = STV_VDP2_N1CHSZ;
5143 stv2_current_tilemap.bitmap_enable = STV_VDP2_N1BMEN;
5144 stv2_current_tilemap.bitmap_size = STV_VDP2_N1BMSZ;
5145 stv2_current_tilemap.bitmap_palette_number = STV_VDP2_N1BMP;
5146 stv2_current_tilemap.bitmap_map = STV_VDP2_N1MP_;
5147 stv2_current_tilemap.map_offset[0] = STV_VDP2_N1MPA | (STV_VDP2_N1MP_ << 6);
5148 stv2_current_tilemap.map_offset[1] = STV_VDP2_N1MPB | (STV_VDP2_N1MP_ << 6);
5149 stv2_current_tilemap.map_offset[2] = STV_VDP2_N1MPC | (STV_VDP2_N1MP_ << 6);
5150 stv2_current_tilemap.map_offset[3] = STV_VDP2_N1MPD | (STV_VDP2_N1MP_ << 6);
5151 stv2_current_tilemap.map_count = 4;
5152
5153 stv2_current_tilemap.pattern_data_size = STV_VDP2_N1PNB;
5154 stv2_current_tilemap.character_number_supplement = STV_VDP2_N1CNSM;
5155 stv2_current_tilemap.special_priority_register = STV_VDP2_N1SPR;
5156 stv2_current_tilemap.special_colour_control_register = STV_VDP2_PNCN1;
5157 stv2_current_tilemap.supplementary_palette_bits = STV_VDP2_N1SPLT;
5158 stv2_current_tilemap.supplementary_character_bits = STV_VDP2_N1SPCN;
5159
5160 stv2_current_tilemap.scrollx = STV_VDP2_SCXIN1;
5161 stv2_current_tilemap.scrolly = STV_VDP2_SCYIN1;
5162 stv2_current_tilemap.incx = STV_VDP2_ZMXN1;
5163 stv2_current_tilemap.incy = STV_VDP2_ZMYN1;
5164
5165 stv2_current_tilemap.linescroll_enable = STV_VDP2_N1LSCX;
5166 stv2_current_tilemap.linescroll_interval = (((STV_VDP2_LSMD & 3) == 2) ? (2) : (1)) << (STV_VDP2_N1LSS);
5167 stv2_current_tilemap.linescroll_table_address = (((STV_VDP2_LSTA1U << 16) | STV_VDP2_LSTA1L) & base_mask) * 2;
5168 stv2_current_tilemap.vertical_linescroll_enable = STV_VDP2_N1LSCY;
5169 stv2_current_tilemap.linezoom_enable = STV_VDP2_N1LZMX;
5170 stv2_current_tilemap.vertical_cell_scroll_enable = STV_VDP2_N1VCSC;
5171
5172 stv2_current_tilemap.plane_size = STV_VDP2_N1PLSZ;
5173 stv2_current_tilemap.colour_ram_address_offset = STV_VDP2_N1CAOS;
5174 stv2_current_tilemap.fade_control = (STV_VDP2_N1COEN * 1) | (STV_VDP2_N1COSL * 2);
5175 stv_vdp2_check_fade_control_for_layer();
5176 stv2_current_tilemap.window_control.logic = STV_VDP2_N1LOG;
5177 stv2_current_tilemap.window_control.enabled[0] = STV_VDP2_N1W0E;
5178 stv2_current_tilemap.window_control.enabled[1] = STV_VDP2_N1W1E;
5179 // stv2_current_tilemap.window_control.? = STV_VDP2_N1SWE;
5180 stv2_current_tilemap.window_control.area[0] = STV_VDP2_N1W0A;
5181 stv2_current_tilemap.window_control.area[1] = STV_VDP2_N1W1A;
5182 // stv2_current_tilemap.window_control.? = STV_VDP2_N1SWA;
5183
5184 stv2_current_tilemap.line_screen_enabled = STV_VDP2_N1LCEN;
5185 stv2_current_tilemap.mosaic_screen_enabled = STV_VDP2_N1MZE;
5186
5187 stv2_current_tilemap.layer_name=1;
5188
5189 if ( stv2_current_tilemap.enabled )
5190 {
5191 stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( STV_VDP2_CP_NBG1_PNMDR, STV_VDP2_CP_NBG1_CPDR, stv2_current_tilemap.bitmap_enable );
5192 }
5193
5194 stv_vdp2_check_tilemap(bitmap, cliprect);
5195 }
5196
stv_vdp2_draw_NBG2(bitmap_rgb32 & bitmap,const rectangle & cliprect)5197 void saturn_state::stv_vdp2_draw_NBG2(bitmap_rgb32 &bitmap, const rectangle &cliprect)
5198 {
5199 /*
5200 NBG2 is the first of the 2 more basic tilemaps, it has exactly the same capabilities as NBG3
5201
5202 Colours : 16, 256
5203 Char Size : 1x1 cells, 2x2 cells
5204 Pattern Data Size : 1 word, 2 words
5205 Plane Layouts : 1 x 1, 2 x 1, 2 x 2
5206 Planes : 4
5207 Bitmap : No
5208 Bitmap Sizes : N/A
5209 Scale : No
5210 Rotation : No
5211 Linescroll : No
5212 Column Scroll : No
5213 Mosaic : Yes
5214 */
5215
5216 stv2_current_tilemap.enabled = STV_VDP2_N2ON;
5217
5218 /* these modes for N0 disable this layer */
5219 if (STV_VDP2_N0CHCN == 0x03) stv2_current_tilemap.enabled = 0;
5220 if (STV_VDP2_N0CHCN == 0x04) stv2_current_tilemap.enabled = 0;
5221
5222 // if (!stv2_current_tilemap.enabled) return; // stop right now if its disabled ...
5223
5224 //stv2_current_tilemap.trans_enabled = STV_VDP2_N2TPON;
5225 if ( STV_VDP2_N2CCEN )
5226 {
5227 stv2_current_tilemap.colour_calculation_enabled = 1;
5228 stv2_current_tilemap.alpha = ((uint16_t)(0x1f-STV_VDP2_N2CCRT)*0xff)/0x1f;
5229 }
5230 else
5231 {
5232 stv2_current_tilemap.colour_calculation_enabled = 0;
5233 }
5234 if ( STV_VDP2_N2TPON == 0 )
5235 {
5236 stv2_current_tilemap.transparency = STV_TRANSPARENCY_PEN;
5237 }
5238 else
5239 {
5240 stv2_current_tilemap.transparency = STV_TRANSPARENCY_NONE;
5241 }
5242 stv2_current_tilemap.colour_depth = STV_VDP2_N2CHCN;
5243 stv2_current_tilemap.tile_size = STV_VDP2_N2CHSZ;
5244 /* this layer can't be a bitmap,so ignore these registers*/
5245 stv2_current_tilemap.bitmap_enable = 0;
5246 stv2_current_tilemap.bitmap_size = 0;
5247 stv2_current_tilemap.bitmap_palette_number = 0;
5248 stv2_current_tilemap.bitmap_map = 0;
5249 stv2_current_tilemap.map_offset[0] = STV_VDP2_N2MPA | (STV_VDP2_N2MP_ << 6);
5250 stv2_current_tilemap.map_offset[1] = STV_VDP2_N2MPB | (STV_VDP2_N2MP_ << 6);
5251 stv2_current_tilemap.map_offset[2] = STV_VDP2_N2MPC | (STV_VDP2_N2MP_ << 6);
5252 stv2_current_tilemap.map_offset[3] = STV_VDP2_N2MPD | (STV_VDP2_N2MP_ << 6);
5253 stv2_current_tilemap.map_count = 4;
5254
5255 stv2_current_tilemap.pattern_data_size = STV_VDP2_N2PNB;
5256 stv2_current_tilemap.character_number_supplement = STV_VDP2_N2CNSM;
5257 stv2_current_tilemap.special_priority_register = STV_VDP2_N2SPR;
5258 stv2_current_tilemap.special_colour_control_register = STV_VDP2_PNCN2;
5259 stv2_current_tilemap.supplementary_palette_bits = STV_VDP2_N2SPLT;
5260 stv2_current_tilemap.supplementary_character_bits = STV_VDP2_N2SPCN;
5261
5262 stv2_current_tilemap.scrollx = STV_VDP2_SCXN2;
5263 stv2_current_tilemap.scrolly = STV_VDP2_SCYN2;
5264 /*This layer can't be scaled*/
5265 stv2_current_tilemap.incx = 0x10000;
5266 stv2_current_tilemap.incy = 0x10000;
5267
5268 stv2_current_tilemap.linescroll_enable = 0;
5269 stv2_current_tilemap.linescroll_interval = 0;
5270 stv2_current_tilemap.linescroll_table_address = 0;
5271 stv2_current_tilemap.vertical_linescroll_enable = 0;
5272 stv2_current_tilemap.linezoom_enable = 0;
5273 stv2_current_tilemap.vertical_cell_scroll_enable = 0;
5274
5275 stv2_current_tilemap.colour_ram_address_offset = STV_VDP2_N2CAOS;
5276 stv2_current_tilemap.fade_control = (STV_VDP2_N2COEN * 1) | (STV_VDP2_N2COSL * 2);
5277 stv_vdp2_check_fade_control_for_layer();
5278 stv2_current_tilemap.window_control.logic = STV_VDP2_N2LOG;
5279 stv2_current_tilemap.window_control.enabled[0] = STV_VDP2_N2W0E;
5280 stv2_current_tilemap.window_control.enabled[1] = STV_VDP2_N2W1E;
5281 // stv2_current_tilemap.window_control.? = STV_VDP2_N2SWE;
5282 stv2_current_tilemap.window_control.area[0] = STV_VDP2_N2W0A;
5283 stv2_current_tilemap.window_control.area[1] = STV_VDP2_N2W1A;
5284 // stv2_current_tilemap.window_control.? = STV_VDP2_N2SWA;
5285
5286 stv2_current_tilemap.line_screen_enabled = STV_VDP2_N2LCEN;
5287 stv2_current_tilemap.mosaic_screen_enabled = STV_VDP2_N2MZE;
5288
5289 stv2_current_tilemap.layer_name=2;
5290
5291 stv2_current_tilemap.plane_size = STV_VDP2_N2PLSZ;
5292
5293 if ( stv2_current_tilemap.enabled )
5294 {
5295 stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( STV_VDP2_CP_NBG2_PNMDR, STV_VDP2_CP_NBG2_CPDR, stv2_current_tilemap.bitmap_enable );
5296 }
5297
5298 stv_vdp2_check_tilemap(bitmap, cliprect);
5299 }
5300
stv_vdp2_draw_NBG3(bitmap_rgb32 & bitmap,const rectangle & cliprect)5301 void saturn_state::stv_vdp2_draw_NBG3(bitmap_rgb32 &bitmap, const rectangle &cliprect)
5302 {
5303 /*
5304 NBG3 is the second of the 2 more basic tilemaps, it has exactly the same capabilities as NBG2
5305
5306 Colours : 16, 256
5307 Char Size : 1x1 cells, 2x2 cells
5308 Pattern Data Size : 1 word, 2 words
5309 Plane Layouts : 1 x 1, 2 x 1, 2 x 2
5310 Planes : 4
5311 Bitmap : No
5312 Bitmap Sizes : N/A
5313 Scale : No
5314 Rotation : No
5315 Linescroll : No
5316 Column Scroll : No
5317 Mosaic : Yes
5318 */
5319
5320 stv2_current_tilemap.enabled = STV_VDP2_N3ON;
5321
5322 // if (!stv2_current_tilemap.enabled) return; // stop right now if its disabled ...
5323
5324 /* these modes for N1 disable this layer */
5325 if (STV_VDP2_N1CHCN == 0x03) stv2_current_tilemap.enabled = 0;
5326 if (STV_VDP2_N1CHCN == 0x04) stv2_current_tilemap.enabled = 0;
5327
5328 //stv2_current_tilemap.trans_enabled = STV_VDP2_N3TPON;
5329 if ( STV_VDP2_N3CCEN )
5330 {
5331 stv2_current_tilemap.colour_calculation_enabled = 1;
5332 stv2_current_tilemap.alpha = ((uint16_t)(0x1f-STV_VDP2_N3CCRT)*0xff)/0x1f;
5333 }
5334 else
5335 {
5336 stv2_current_tilemap.colour_calculation_enabled = 0;
5337 }
5338 if ( STV_VDP2_N3TPON == 0 )
5339 {
5340 stv2_current_tilemap.transparency = STV_TRANSPARENCY_PEN;
5341 }
5342 else
5343 {
5344 stv2_current_tilemap.transparency = STV_TRANSPARENCY_NONE;
5345 }
5346 stv2_current_tilemap.colour_depth = STV_VDP2_N3CHCN;
5347 stv2_current_tilemap.tile_size = STV_VDP2_N3CHSZ;
5348 /* this layer can't be a bitmap,so ignore these registers*/
5349 stv2_current_tilemap.bitmap_enable = 0;
5350 stv2_current_tilemap.bitmap_size = 0;
5351 stv2_current_tilemap.bitmap_palette_number = 0;
5352 stv2_current_tilemap.bitmap_map = 0;
5353 stv2_current_tilemap.map_offset[0] = STV_VDP2_N3MPA | (STV_VDP2_N3MP_ << 6);
5354 stv2_current_tilemap.map_offset[1] = STV_VDP2_N3MPB | (STV_VDP2_N3MP_ << 6);
5355 stv2_current_tilemap.map_offset[2] = STV_VDP2_N3MPC | (STV_VDP2_N3MP_ << 6);
5356 stv2_current_tilemap.map_offset[3] = STV_VDP2_N3MPD | (STV_VDP2_N3MP_ << 6);
5357 stv2_current_tilemap.map_count = 4;
5358
5359 stv2_current_tilemap.pattern_data_size = STV_VDP2_N3PNB;
5360 stv2_current_tilemap.character_number_supplement = STV_VDP2_N3CNSM;
5361 stv2_current_tilemap.special_priority_register = STV_VDP2_N3SPR;
5362 stv2_current_tilemap.special_colour_control_register = STV_VDP2_N3SCC;
5363 stv2_current_tilemap.supplementary_palette_bits = STV_VDP2_N3SPLT;
5364 stv2_current_tilemap.supplementary_character_bits = STV_VDP2_N3SPCN;
5365
5366 stv2_current_tilemap.scrollx = STV_VDP2_SCXN3;
5367 stv2_current_tilemap.scrolly = STV_VDP2_SCYN3;
5368 /*This layer can't be scaled*/
5369 stv2_current_tilemap.incx = 0x10000;
5370 stv2_current_tilemap.incy = 0x10000;
5371
5372 stv2_current_tilemap.linescroll_enable = 0;
5373 stv2_current_tilemap.linescroll_interval = 0;
5374 stv2_current_tilemap.linescroll_table_address = 0;
5375 stv2_current_tilemap.vertical_linescroll_enable = 0;
5376 stv2_current_tilemap.linezoom_enable = 0;
5377 stv2_current_tilemap.vertical_cell_scroll_enable = 0;
5378
5379 stv2_current_tilemap.colour_ram_address_offset = STV_VDP2_N3CAOS;
5380 stv2_current_tilemap.fade_control = (STV_VDP2_N3COEN * 1) | (STV_VDP2_N3COSL * 2);
5381 stv_vdp2_check_fade_control_for_layer();
5382 stv2_current_tilemap.window_control.logic = STV_VDP2_N3LOG;
5383 stv2_current_tilemap.window_control.enabled[0] = STV_VDP2_N3W0E;
5384 stv2_current_tilemap.window_control.enabled[1] = STV_VDP2_N3W1E;
5385 // stv2_current_tilemap.window_control.? = STV_VDP2_N3SWE;
5386 stv2_current_tilemap.window_control.area[0] = STV_VDP2_N3W0A;
5387 stv2_current_tilemap.window_control.area[1] = STV_VDP2_N3W1A;
5388 // stv2_current_tilemap.window_control.? = STV_VDP2_N3SWA;
5389
5390 stv2_current_tilemap.line_screen_enabled = STV_VDP2_N3LCEN;
5391 stv2_current_tilemap.mosaic_screen_enabled = STV_VDP2_N3MZE;
5392
5393 stv2_current_tilemap.layer_name=3;
5394
5395 stv2_current_tilemap.plane_size = STV_VDP2_N3PLSZ;
5396
5397 if ( stv2_current_tilemap.enabled )
5398 {
5399 stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( STV_VDP2_CP_NBG3_PNMDR, STV_VDP2_CP_NBG3_CPDR, stv2_current_tilemap.bitmap_enable );
5400 }
5401
5402 stv_vdp2_check_tilemap(bitmap, cliprect);
5403 }
5404
5405
stv_vdp2_draw_rotation_screen(bitmap_rgb32 & bitmap,const rectangle & cliprect,int iRP)5406 void saturn_state::stv_vdp2_draw_rotation_screen(bitmap_rgb32 &bitmap, const rectangle &cliprect, int iRP)
5407 {
5408 rectangle roz_clip_rect;
5409 int planesizex = 0, planesizey = 0;
5410 int planerenderedsizex, planerenderedsizey;
5411 uint8_t colour_calculation_enabled;
5412 uint8_t fade_control;
5413
5414 if ( iRP == 1)
5415 {
5416 stv2_current_tilemap.bitmap_map = STV_VDP2_RAMP_;
5417 stv2_current_tilemap.map_offset[0] = STV_VDP2_RAMPA | (STV_VDP2_RAMP_ << 6);
5418 stv2_current_tilemap.map_offset[1] = STV_VDP2_RAMPB | (STV_VDP2_RAMP_ << 6);
5419 stv2_current_tilemap.map_offset[2] = STV_VDP2_RAMPC | (STV_VDP2_RAMP_ << 6);
5420 stv2_current_tilemap.map_offset[3] = STV_VDP2_RAMPD | (STV_VDP2_RAMP_ << 6);
5421 stv2_current_tilemap.map_offset[4] = STV_VDP2_RAMPE | (STV_VDP2_RAMP_ << 6);
5422 stv2_current_tilemap.map_offset[5] = STV_VDP2_RAMPF | (STV_VDP2_RAMP_ << 6);
5423 stv2_current_tilemap.map_offset[6] = STV_VDP2_RAMPG | (STV_VDP2_RAMP_ << 6);
5424 stv2_current_tilemap.map_offset[7] = STV_VDP2_RAMPH | (STV_VDP2_RAMP_ << 6);
5425 stv2_current_tilemap.map_offset[8] = STV_VDP2_RAMPI | (STV_VDP2_RAMP_ << 6);
5426 stv2_current_tilemap.map_offset[9] = STV_VDP2_RAMPJ | (STV_VDP2_RAMP_ << 6);
5427 stv2_current_tilemap.map_offset[10] = STV_VDP2_RAMPK | (STV_VDP2_RAMP_ << 6);
5428 stv2_current_tilemap.map_offset[11] = STV_VDP2_RAMPL | (STV_VDP2_RAMP_ << 6);
5429 stv2_current_tilemap.map_offset[12] = STV_VDP2_RAMPM | (STV_VDP2_RAMP_ << 6);
5430 stv2_current_tilemap.map_offset[13] = STV_VDP2_RAMPN | (STV_VDP2_RAMP_ << 6);
5431 stv2_current_tilemap.map_offset[14] = STV_VDP2_RAMPO | (STV_VDP2_RAMP_ << 6);
5432 stv2_current_tilemap.map_offset[15] = STV_VDP2_RAMPP | (STV_VDP2_RAMP_ << 6);
5433 stv2_current_tilemap.map_count = 16;
5434 }
5435 else
5436 {
5437 stv2_current_tilemap.bitmap_map = STV_VDP2_RBMP_;
5438 stv2_current_tilemap.map_offset[0] = STV_VDP2_RBMPA | (STV_VDP2_RBMP_ << 6);
5439 stv2_current_tilemap.map_offset[1] = STV_VDP2_RBMPB | (STV_VDP2_RBMP_ << 6);
5440 stv2_current_tilemap.map_offset[2] = STV_VDP2_RBMPC | (STV_VDP2_RBMP_ << 6);
5441 stv2_current_tilemap.map_offset[3] = STV_VDP2_RBMPD | (STV_VDP2_RBMP_ << 6);
5442 stv2_current_tilemap.map_offset[4] = STV_VDP2_RBMPE | (STV_VDP2_RBMP_ << 6);
5443 stv2_current_tilemap.map_offset[5] = STV_VDP2_RBMPF | (STV_VDP2_RBMP_ << 6);
5444 stv2_current_tilemap.map_offset[6] = STV_VDP2_RBMPG | (STV_VDP2_RBMP_ << 6);
5445 stv2_current_tilemap.map_offset[7] = STV_VDP2_RBMPH | (STV_VDP2_RBMP_ << 6);
5446 stv2_current_tilemap.map_offset[8] = STV_VDP2_RBMPI | (STV_VDP2_RBMP_ << 6);
5447 stv2_current_tilemap.map_offset[9] = STV_VDP2_RBMPJ | (STV_VDP2_RBMP_ << 6);
5448 stv2_current_tilemap.map_offset[10] = STV_VDP2_RBMPK | (STV_VDP2_RBMP_ << 6);
5449 stv2_current_tilemap.map_offset[11] = STV_VDP2_RBMPL | (STV_VDP2_RBMP_ << 6);
5450 stv2_current_tilemap.map_offset[12] = STV_VDP2_RBMPM | (STV_VDP2_RBMP_ << 6);
5451 stv2_current_tilemap.map_offset[13] = STV_VDP2_RBMPN | (STV_VDP2_RBMP_ << 6);
5452 stv2_current_tilemap.map_offset[14] = STV_VDP2_RBMPO | (STV_VDP2_RBMP_ << 6);
5453 stv2_current_tilemap.map_offset[15] = STV_VDP2_RBMPP | (STV_VDP2_RBMP_ << 6);
5454 stv2_current_tilemap.map_count = 16;
5455 }
5456
5457 stv_vdp2_fill_rotation_parameter_table(iRP);
5458
5459 if ( iRP == 1 )
5460 {
5461 stv2_current_tilemap.plane_size = STV_VDP2_RAPLSZ;
5462 }
5463 else
5464 {
5465 stv2_current_tilemap.plane_size = STV_VDP2_RBPLSZ;
5466 }
5467
5468 if (stv2_current_tilemap.bitmap_enable)
5469 {
5470 switch (stv2_current_tilemap.bitmap_size)
5471 {
5472 case 0: planesizex=512; planesizey=256; break;
5473 case 1: planesizex=512; planesizey=512; break;
5474 case 2: planesizex=1024; planesizey=256; break;
5475 case 3: planesizex=1024; planesizey=512; break;
5476 }
5477 }
5478 else
5479 {
5480 switch( stv2_current_tilemap.plane_size )
5481 {
5482 case 0:
5483 planesizex = planesizey = 2048;
5484 break;
5485 case 1:
5486 planesizex = 4096;
5487 planesizey = 2048;
5488 break;
5489 case 2:
5490 planesizex = 0;
5491 planesizey = 0;
5492 break;
5493 case 3:
5494 planesizex = planesizey = 4096;
5495 break;
5496 }
5497 }
5498
5499 if ( stv_vdp2_is_rotation_applied() == 0 )
5500 {
5501 stv2_current_tilemap.scrollx = stv_current_rotation_parameter_table.mx >> 16;
5502 stv2_current_tilemap.scrolly = stv_current_rotation_parameter_table.my >> 16;
5503
5504 if(stv2_current_tilemap.roz_mode3 == true)
5505 {
5506 // TODO: Cotton 2 enables mode 3 without an actual RP window enabled
5507 // Technically you could use split screen effect without rotation applied,
5508 // which will be annoying to emulate with this video structure.
5509 // Let's see if anything will do it ...
5510 if(STV_VDP2_RPW0E || STV_VDP2_RPW1E)
5511 popmessage("ROZ Mode 3 window enabled without zooming, contact MAMEdev!");
5512
5513 if(iRP == 2)
5514 return;
5515 }
5516
5517 // TODO: legacy code, to be removed
5518 stv2_current_tilemap.window_control.logic = STV_VDP2_R0LOG;
5519 stv2_current_tilemap.window_control.enabled[0] = STV_VDP2_R0W0E;
5520 stv2_current_tilemap.window_control.enabled[1] = STV_VDP2_R0W1E;
5521 // stv2_current_tilemap.window_control.? = STV_VDP2_R0SWE;
5522 stv2_current_tilemap.window_control.area[0] = STV_VDP2_R0W0A;
5523 stv2_current_tilemap.window_control.area[1] = STV_VDP2_R0W1A;
5524 // stv2_current_tilemap.window_control.? = STV_VDP2_R0SWA;
5525
5526 rectangle mycliprect = cliprect;
5527
5528 if ( stv2_current_tilemap.window_control.enabled[0] || stv2_current_tilemap.window_control.enabled[1] )
5529 {
5530 //popmessage("Window control for RBG");
5531 stv_vdp2_apply_window_on_layer(mycliprect);
5532 stv2_current_tilemap.window_control.enabled[0] = 0;
5533 stv2_current_tilemap.window_control.enabled[1] = 0;
5534 }
5535
5536 stv_vdp2_check_tilemap(bitmap,mycliprect);
5537 }
5538 else
5539 {
5540 if ( !m_vdp2.roz_bitmap[iRP-1].valid() )
5541 m_vdp2.roz_bitmap[iRP-1].allocate(4096, 4096);
5542
5543 roz_clip_rect.min_x = roz_clip_rect.min_y = 0;
5544 if ( (iRP == 1 && STV_VDP2_RAOVR == 3) ||
5545 (iRP == 2 && STV_VDP2_RBOVR == 3) )
5546 {
5547 roz_clip_rect.max_x = roz_clip_rect.max_y = 511;
5548 planerenderedsizex = planerenderedsizey = 512;
5549 }
5550 else if (stv_vdp2_are_map_registers_equal() &&
5551 !stv2_current_tilemap.bitmap_enable)
5552 {
5553 roz_clip_rect.max_x = (planesizex / 4) - 1;
5554 roz_clip_rect.max_y = (planesizey / 4) - 1;
5555 planerenderedsizex = planesizex / 4;
5556 planerenderedsizey = planesizey / 4;
5557 }
5558 else
5559 {
5560 roz_clip_rect.max_x = planesizex - 1;
5561 roz_clip_rect.max_y = planesizey - 1;
5562 planerenderedsizex = planesizex;
5563 planerenderedsizey = planesizey;
5564 }
5565
5566
5567 colour_calculation_enabled = stv2_current_tilemap.colour_calculation_enabled;
5568 stv2_current_tilemap.colour_calculation_enabled = 0;
5569 // window_control = stv2_current_tilemap.window_control;
5570 // stv2_current_tilemap.window_control = 0;
5571 fade_control = stv2_current_tilemap.fade_control;
5572 stv2_current_tilemap.fade_control = 0;
5573 g_profiler.start(PROFILER_USER1);
5574 if ( LOG_VDP2 ) logerror( "Checking for cached RBG bitmap, cache_dirty = %d, memcmp() = %d\n", stv_rbg_cache_data.is_cache_dirty, memcmp(&stv_rbg_cache_data.layer_data[iRP-1],&stv2_current_tilemap,sizeof(stv2_current_tilemap)));
5575 if ( (stv_rbg_cache_data.is_cache_dirty & iRP) ||
5576 memcmp(&stv_rbg_cache_data.layer_data[iRP-1],&stv2_current_tilemap,sizeof(stv2_current_tilemap)) != 0 )
5577 {
5578 m_vdp2.roz_bitmap[iRP-1].fill(m_palette->black_pen(), roz_clip_rect );
5579 stv_vdp2_check_tilemap(m_vdp2.roz_bitmap[iRP-1], roz_clip_rect);
5580 // prepare cache data
5581 stv_rbg_cache_data.watch_vdp2_vram_writes |= iRP;
5582 stv_rbg_cache_data.is_cache_dirty &= ~iRP;
5583 memcpy(&stv_rbg_cache_data.layer_data[iRP-1], &stv2_current_tilemap, sizeof(stv2_current_tilemap));
5584 stv_rbg_cache_data.map_offset_min[iRP-1] = stv_vdp2_layer_data_placement.map_offset_min;
5585 stv_rbg_cache_data.map_offset_max[iRP-1] = stv_vdp2_layer_data_placement.map_offset_max;
5586 stv_rbg_cache_data.tile_offset_min[iRP-1] = stv_vdp2_layer_data_placement.tile_offset_min;
5587 stv_rbg_cache_data.tile_offset_max[iRP-1] = stv_vdp2_layer_data_placement.tile_offset_max;
5588 if ( LOG_VDP2 ) logerror( "Cache watch: map = %06X - %06X, tile = %06X - %06X\n", stv_rbg_cache_data.map_offset_min[iRP-1],
5589 stv_rbg_cache_data.map_offset_max[iRP-1], stv_rbg_cache_data.tile_offset_min[iRP-1], stv_rbg_cache_data.tile_offset_max[iRP-1] );
5590 }
5591
5592 g_profiler.stop();
5593
5594 stv2_current_tilemap.colour_calculation_enabled = colour_calculation_enabled;
5595 if ( colour_calculation_enabled )
5596 {
5597 stv2_current_tilemap.transparency |= STV_TRANSPARENCY_ALPHA;
5598 }
5599
5600 #ifdef UNUSED_FUNCTION
5601 // old reference code
5602 mycliprect = cliprect;
5603
5604 if ( stv2_current_tilemap.window_control.enabled[0] || stv2_current_tilemap.window_control.enabled[1] )
5605 {
5606 //popmessage("Window control for RBG");
5607 stv_vdp2_apply_window_on_layer(mycliprect);
5608 stv2_current_tilemap.window_control.enabled[0] = 0;
5609 stv2_current_tilemap.window_control.enabled[1] = 0;
5610 }
5611 #endif
5612
5613 stv2_current_tilemap.fade_control = fade_control;
5614
5615 g_profiler.start(PROFILER_USER2);
5616 stv_vdp2_copy_roz_bitmap(bitmap, m_vdp2.roz_bitmap[iRP-1], cliprect, iRP, planesizex, planesizey, planerenderedsizex, planerenderedsizey );
5617 g_profiler.stop();
5618 }
5619
5620 }
5621
stv_vdp2_draw_RBG0(bitmap_rgb32 & bitmap,const rectangle & cliprect)5622 void saturn_state::stv_vdp2_draw_RBG0(bitmap_rgb32 &bitmap, const rectangle &cliprect)
5623 {
5624 /*
5625 Colours : 16, 256, 2048, 32768, 16770000
5626 Char Size : 1x1 cells, 2x2 cells
5627 Pattern Data Size : 1 word, 2 words
5628 Plane Layouts : 1 x 1, 2 x 1, 2 x 2
5629 Planes : 4
5630 Bitmap : Possible
5631 Bitmap Sizes : 512 x 256, 512 x 512, 1024 x 256, 1024 x 512
5632 Scale : 0.25 x - 256 x
5633 Rotation : Yes
5634 Linescroll : Yes
5635 Column Scroll : Yes
5636 Mosaic : Yes
5637 */
5638
5639 stv2_current_tilemap.enabled = STV_VDP2_R0ON;
5640
5641 // if (!stv2_current_tilemap.enabled) return; // stop right now if its disabled ...
5642
5643 //stv2_current_tilemap.trans_enabled = STV_VDP2_R0TPON;
5644 if ( STV_VDP2_R0CCEN )
5645 {
5646 stv2_current_tilemap.colour_calculation_enabled = 1;
5647 stv2_current_tilemap.alpha = ((uint16_t)(0x1f-STV_VDP2_R0CCRT)*0xff)/0x1f;
5648 }
5649 else
5650 {
5651 stv2_current_tilemap.colour_calculation_enabled = 0;
5652 }
5653 if ( STV_VDP2_R0TPON == 0 )
5654 {
5655 stv2_current_tilemap.transparency = STV_TRANSPARENCY_PEN;
5656 }
5657 else
5658 {
5659 stv2_current_tilemap.transparency = STV_TRANSPARENCY_NONE;
5660 }
5661 stv2_current_tilemap.colour_depth = STV_VDP2_R0CHCN;
5662 stv2_current_tilemap.tile_size = STV_VDP2_R0CHSZ;
5663 stv2_current_tilemap.bitmap_enable = STV_VDP2_R0BMEN;
5664 stv2_current_tilemap.bitmap_size = STV_VDP2_R0BMSZ;
5665 stv2_current_tilemap.bitmap_palette_number = STV_VDP2_R0BMP;
5666
5667 stv2_current_tilemap.pattern_data_size = STV_VDP2_R0PNB;
5668 stv2_current_tilemap.character_number_supplement = STV_VDP2_R0CNSM;
5669 stv2_current_tilemap.special_priority_register = STV_VDP2_R0SPR;
5670 stv2_current_tilemap.special_colour_control_register = STV_VDP2_R0SCC;
5671 stv2_current_tilemap.supplementary_palette_bits = STV_VDP2_R0SPLT;
5672 stv2_current_tilemap.supplementary_character_bits = STV_VDP2_R0SPCN;
5673
5674 stv2_current_tilemap.colour_ram_address_offset = STV_VDP2_R0CAOS;
5675 stv2_current_tilemap.fade_control = (STV_VDP2_R0COEN * 1) | (STV_VDP2_R0COSL * 2);
5676 stv_vdp2_check_fade_control_for_layer();
5677 // disable these, we apply them in the roz routines (they were interfering with stv_vdp2_roz_window() ?)
5678 stv2_current_tilemap.window_control.logic = 0; //STV_VDP2_R0LOG;
5679 stv2_current_tilemap.window_control.enabled[0] = 0; //STV_VDP2_R0W0E;
5680 stv2_current_tilemap.window_control.enabled[1] = 0; //STV_VDP2_R0W1E;
5681 // stv2_current_tilemap.window_control.? = STV_VDP2_R0SWE;
5682 stv2_current_tilemap.window_control.area[0] = 0; //STV_VDP2_R0W0A;
5683 stv2_current_tilemap.window_control.area[1] = 0; //STV_VDP2_R0W1A;
5684 // stv2_current_tilemap.window_control.? = STV_VDP2_R0SWA;
5685
5686 stv2_current_tilemap.scrollx = 0;
5687 stv2_current_tilemap.scrolly = 0;
5688 stv2_current_tilemap.incx = 0x10000;
5689 stv2_current_tilemap.incy = 0x10000;
5690
5691 stv2_current_tilemap.linescroll_enable = 0;
5692 stv2_current_tilemap.linescroll_interval = 0;
5693 stv2_current_tilemap.linescroll_table_address = 0;
5694 stv2_current_tilemap.vertical_linescroll_enable = 0;
5695 stv2_current_tilemap.linezoom_enable = 0;
5696 stv2_current_tilemap.vertical_cell_scroll_enable = 0;
5697
5698 stv2_current_tilemap.line_screen_enabled = STV_VDP2_R0LCEN;
5699 stv2_current_tilemap.mosaic_screen_enabled = STV_VDP2_R0MZE;
5700
5701 /*Use 0x80 as a normal/rotate switch*/
5702 stv2_current_tilemap.layer_name=0x80;
5703
5704 if ( !stv2_current_tilemap.enabled ) return;
5705
5706 switch(STV_VDP2_RPMD)
5707 {
5708 case 0://Rotation Parameter A
5709 stv2_current_tilemap.roz_mode3 = false;
5710 stv_vdp2_draw_rotation_screen(bitmap, cliprect, 1 );
5711 break;
5712 case 1://Rotation Parameter B
5713 //case 2:
5714 stv2_current_tilemap.roz_mode3 = false;
5715 stv_vdp2_draw_rotation_screen(bitmap, cliprect, 2 );
5716 break;
5717 case 2://Rotation Parameter A & B CKTE
5718 stv2_current_tilemap.roz_mode3 = false;
5719 stv_vdp2_draw_rotation_screen(bitmap, cliprect, 2 );
5720 stv_vdp2_draw_rotation_screen(bitmap, cliprect, 1 );
5721 break;
5722 case 3://Rotation Parameter A & B Window
5723 stv2_current_tilemap.roz_mode3 = true;
5724 stv_vdp2_draw_rotation_screen(bitmap, cliprect, 2 );
5725 stv_vdp2_draw_rotation_screen(bitmap, cliprect, 1 );
5726 break;
5727 }
5728
5729 }
5730
stv_vdp2_draw_back(bitmap_rgb32 & bitmap,const rectangle & cliprect)5731 void saturn_state::stv_vdp2_draw_back(bitmap_rgb32 &bitmap, const rectangle &cliprect)
5732 {
5733 uint8_t const *const gfxdata = m_vdp2.gfx_decode.get();
5734
5735 uint8_t interlace = (STV_VDP2_LSMD == 3)+1;
5736
5737 // popmessage("Back screen %08x %08x %08x",STV_VDP2_BDCLMD,STV_VDP2_BKCLMD,STV_VDP2_BKTA);
5738
5739 /* draw black if BDCLMD and DISP are cleared */
5740 if(!(STV_VDP2_BDCLMD) && !(STV_VDP2_DISP))
5741 bitmap.fill(m_palette->black_pen(), cliprect);
5742 else
5743 {
5744 uint32_t base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
5745
5746 for(int y=cliprect.top();y<=cliprect.bottom();y++)
5747 {
5748 uint32_t base_offs = ((STV_VDP2_BKTA ) & base_mask) << 1;
5749 if(STV_VDP2_BKCLMD)
5750 base_offs += ((y / interlace) << 1);
5751
5752 for(int x=cliprect.left();x<=cliprect.right();x++)
5753 {
5754 uint16_t dot = (gfxdata[base_offs+0]<<8)|gfxdata[base_offs+1];
5755 int b = pal5bit((dot & 0x7c00) >> 10);
5756 int g = pal5bit((dot & 0x03e0) >> 5);
5757 int r = pal5bit( dot & 0x001f);
5758 if(STV_VDP2_BKCOEN)
5759 stv_vdp2_compute_color_offset( &r, &g, &b, STV_VDP2_BKCOSL );
5760
5761 bitmap.pix(y, x) = rgb_t(r, g, b);
5762 }
5763 }
5764 }
5765 }
5766
saturn_vdp2_vram_r(offs_t offset)5767 uint32_t saturn_state::saturn_vdp2_vram_r(offs_t offset)
5768 {
5769 return m_vdp2_vram[offset];
5770 }
5771
saturn_vdp2_vram_w(offs_t offset,uint32_t data,uint32_t mem_mask)5772 void saturn_state::saturn_vdp2_vram_w(offs_t offset, uint32_t data, uint32_t mem_mask)
5773 {
5774 uint8_t* gfxdata = m_vdp2.gfx_decode.get();
5775
5776 COMBINE_DATA(&m_vdp2_vram[offset]);
5777
5778 data = m_vdp2_vram[offset];
5779 /* put in gfx region for easy decoding */
5780 gfxdata[offset*4+0] = (data & 0xff000000) >> 24;
5781 gfxdata[offset*4+1] = (data & 0x00ff0000) >> 16;
5782 gfxdata[offset*4+2] = (data & 0x0000ff00) >> 8;
5783 gfxdata[offset*4+3] = (data & 0x000000ff) >> 0;
5784
5785 m_gfxdecode->gfx(0)->mark_dirty(offset/8);
5786 m_gfxdecode->gfx(1)->mark_dirty(offset/8);
5787 m_gfxdecode->gfx(2)->mark_dirty(offset/8);
5788 m_gfxdecode->gfx(3)->mark_dirty(offset/8);
5789
5790 /* 8-bit tiles overlap, so this affects the previous one as well */
5791 if (offset/8 != 0)
5792 {
5793 m_gfxdecode->gfx(2)->mark_dirty(offset/8 - 1);
5794 m_gfxdecode->gfx(3)->mark_dirty(offset/8 - 1);
5795 }
5796
5797 if ( stv_rbg_cache_data.watch_vdp2_vram_writes )
5798 {
5799 if ( stv_rbg_cache_data.watch_vdp2_vram_writes & STV_VDP2_RBG_ROTATION_PARAMETER_A )
5800 {
5801 if ( (offset >= stv_rbg_cache_data.map_offset_min[0] &&
5802 offset < stv_rbg_cache_data.map_offset_max[0]) ||
5803 (offset >= stv_rbg_cache_data.tile_offset_min[0] &&
5804 offset < stv_rbg_cache_data.tile_offset_max[0]) )
5805 {
5806 if ( LOG_VDP2 ) logerror( "RBG Cache: dirtying for RP = 1, write at offset = %06X\n", offset );
5807 stv_rbg_cache_data.is_cache_dirty |= STV_VDP2_RBG_ROTATION_PARAMETER_A;
5808 stv_rbg_cache_data.watch_vdp2_vram_writes &= ~STV_VDP2_RBG_ROTATION_PARAMETER_A;
5809 }
5810 }
5811 if ( stv_rbg_cache_data.watch_vdp2_vram_writes & STV_VDP2_RBG_ROTATION_PARAMETER_B )
5812 {
5813 if ( (offset >= stv_rbg_cache_data.map_offset_min[1] &&
5814 offset < stv_rbg_cache_data.map_offset_max[1]) ||
5815 (offset >= stv_rbg_cache_data.tile_offset_min[1] &&
5816 offset < stv_rbg_cache_data.tile_offset_max[1]) )
5817 {
5818 if ( LOG_VDP2 ) logerror( "RBG Cache: dirtying for RP = 2, write at offset = %06X\n", offset );
5819 stv_rbg_cache_data.is_cache_dirty |= STV_VDP2_RBG_ROTATION_PARAMETER_B;
5820 stv_rbg_cache_data.watch_vdp2_vram_writes &= ~STV_VDP2_RBG_ROTATION_PARAMETER_B;
5821 }
5822 }
5823 }
5824 }
5825
saturn_vdp2_regs_r(offs_t offset)5826 uint16_t saturn_state::saturn_vdp2_regs_r(offs_t offset)
5827 {
5828 switch(offset)
5829 {
5830 case 0x002/2:
5831 {
5832 /* latch h/v signals through HV latch*/
5833 if(!STV_VDP2_EXLTEN)
5834 {
5835 if(!machine().side_effects_disabled())
5836 {
5837 m_vdp2.h_count = get_hcounter();
5838 m_vdp2.v_count = get_vcounter();
5839 /* latch flag */
5840 m_vdp2.exltfg |= 1;
5841 }
5842 }
5843
5844 break;
5845 }
5846 case 0x004/2:
5847 {
5848 /*Screen Status Register*/
5849 /*VBLANK HBLANK ODD PAL */
5850 m_vdp2_regs[offset] = (m_vdp2.exltfg<<9) |
5851 (m_vdp2.exsyfg<<8) |
5852 (get_vblank() << 3) |
5853 (get_hblank() << 2) |
5854 (get_odd_bit() << 1) |
5855 (m_vdp2.pal << 0);
5856
5857 /* vblank bit is always 1 if DISP bit is disabled */
5858 if(!STV_VDP2_DISP)
5859 m_vdp2_regs[offset] |= 1 << 3;
5860
5861 /* HV latches clears if this register is read */
5862 if(!machine().side_effects_disabled())
5863 {
5864 m_vdp2.exltfg &= ~1;
5865 m_vdp2.exsyfg &= ~1;
5866 }
5867 break;
5868 }
5869 case 0x006/2:
5870 {
5871 m_vdp2_regs[offset] = (STV_VDP2_VRAMSZ << 15) |
5872 ((0 << 0) & 0xf); // VDP2 version
5873
5874 /* Games basically r/w the entire VDP2 register area when this is tripped. (example: Silhouette Mirage)
5875 Disable log for the time being. */
5876 //if(!machine().side_effects_disabled())
5877 // printf("Warning: VDP2 version read\n");
5878 break;
5879 }
5880
5881 /* HCNT */
5882 case 0x008/2:
5883 {
5884 m_vdp2_regs[offset] = (m_vdp2.h_count);
5885 break;
5886 }
5887
5888 /* VCNT */
5889 case 0x00a/2:
5890 {
5891 m_vdp2_regs[offset] = (m_vdp2.v_count);
5892 break;
5893 }
5894
5895 default:
5896 //if(!machine().side_effects_disabled())
5897 // printf("VDP2: read from register %08x %08x\n",offset*4,mem_mask);
5898 break;
5899 }
5900
5901 return m_vdp2_regs[offset];
5902 }
5903
saturn_vdp2_cram_r(offs_t offset)5904 uint32_t saturn_state::saturn_vdp2_cram_r(offs_t offset)
5905 {
5906 offset &= (0xfff) >> (2);
5907 return m_vdp2_cram[offset];
5908 }
5909
5910
5911
5912
saturn_vdp2_cram_w(offs_t offset,uint32_t data,uint32_t mem_mask)5913 void saturn_state::saturn_vdp2_cram_w(offs_t offset, uint32_t data, uint32_t mem_mask)
5914 {
5915 int r,g,b;
5916 uint8_t cmode0;
5917
5918 cmode0 = (STV_VDP2_CRMD & 3) == 0;
5919
5920 offset &= (0xfff) >> (2);
5921 COMBINE_DATA(&m_vdp2_cram[offset]);
5922
5923 switch( STV_VDP2_CRMD )
5924 {
5925 /*Mode 2/3*/
5926 case 2:
5927 case 3:
5928 {
5929 //offset &= (0xfff) >> 2;
5930
5931 b = ((m_vdp2_cram[offset] & 0x00ff0000) >> 16);
5932 g = ((m_vdp2_cram[offset] & 0x0000ff00) >> 8);
5933 r = ((m_vdp2_cram[offset] & 0x000000ff) >> 0);
5934 m_palette->set_pen_color(offset,rgb_t(r,g,b));
5935 m_palette->set_pen_color(offset^0x400,rgb_t(r,g,b));
5936 }
5937 break;
5938 /*Mode 0*/
5939 case 0:
5940 case 1:
5941 {
5942 offset &= (0xfff) >> (cmode0+2);
5943
5944 b = ((m_vdp2_cram[offset] & 0x00007c00) >> 10);
5945 g = ((m_vdp2_cram[offset] & 0x000003e0) >> 5);
5946 r = ((m_vdp2_cram[offset] & 0x0000001f) >> 0);
5947 m_palette->set_pen_color((offset*2)+1,pal5bit(r),pal5bit(g),pal5bit(b));
5948 if(cmode0)
5949 m_palette->set_pen_color(((offset*2)+1)^0x400,pal5bit(r),pal5bit(g),pal5bit(b));
5950
5951 b = ((m_vdp2_cram[offset] & 0x7c000000) >> 26);
5952 g = ((m_vdp2_cram[offset] & 0x03e00000) >> 21);
5953 r = ((m_vdp2_cram[offset] & 0x001f0000) >> 16);
5954 m_palette->set_pen_color(offset*2,pal5bit(r),pal5bit(g),pal5bit(b));
5955 if(cmode0)
5956 m_palette->set_pen_color((offset*2)^0x400,pal5bit(r),pal5bit(g),pal5bit(b));
5957 }
5958 break;
5959 }
5960 }
5961
refresh_palette_data(void)5962 void saturn_state::refresh_palette_data( void )
5963 {
5964 int r,g,b;
5965 int c_i;
5966 uint8_t bank;
5967
5968 switch( STV_VDP2_CRMD )
5969 {
5970 case 2:
5971 case 3:
5972 {
5973 for(c_i=0;c_i<0x400;c_i++)
5974 {
5975 b = ((m_vdp2_cram[c_i] & 0x00ff0000) >> 16);
5976 g = ((m_vdp2_cram[c_i] & 0x0000ff00) >> 8);
5977 r = ((m_vdp2_cram[c_i] & 0x000000ff) >> 0);
5978 m_palette->set_pen_color(c_i,rgb_t(r,g,b));
5979 m_palette->set_pen_color(c_i+0x400,rgb_t(r,g,b));
5980 }
5981 }
5982 break;
5983 case 0:
5984 {
5985 for(bank=0;bank<2;bank++)
5986 {
5987 for(c_i=0;c_i<0x400;c_i++)
5988 {
5989 b = ((m_vdp2_cram[c_i] & 0x00007c00) >> 10);
5990 g = ((m_vdp2_cram[c_i] & 0x000003e0) >> 5);
5991 r = ((m_vdp2_cram[c_i] & 0x0000001f) >> 0);
5992 m_palette->set_pen_color((c_i*2)+1+bank*0x400,pal5bit(r),pal5bit(g),pal5bit(b));
5993 b = ((m_vdp2_cram[c_i] & 0x7c000000) >> 26);
5994 g = ((m_vdp2_cram[c_i] & 0x03e00000) >> 21);
5995 r = ((m_vdp2_cram[c_i] & 0x001f0000) >> 16);
5996 m_palette->set_pen_color(c_i*2+bank*0x400,pal5bit(r),pal5bit(g),pal5bit(b));
5997 }
5998 }
5999 }
6000 break;
6001 case 1:
6002 {
6003 for(c_i=0;c_i<0x800;c_i++)
6004 {
6005 b = ((m_vdp2_cram[c_i] & 0x00007c00) >> 10);
6006 g = ((m_vdp2_cram[c_i] & 0x000003e0) >> 5);
6007 r = ((m_vdp2_cram[c_i] & 0x0000001f) >> 0);
6008 m_palette->set_pen_color((c_i*2)+1,pal5bit(r),pal5bit(g),pal5bit(b));
6009 b = ((m_vdp2_cram[c_i] & 0x7c000000) >> 26);
6010 g = ((m_vdp2_cram[c_i] & 0x03e00000) >> 21);
6011 r = ((m_vdp2_cram[c_i] & 0x001f0000) >> 16);
6012 m_palette->set_pen_color(c_i*2,pal5bit(r),pal5bit(g),pal5bit(b));
6013 }
6014 }
6015 break;
6016 }
6017 }
6018
saturn_vdp2_regs_w(offs_t offset,uint16_t data,uint16_t mem_mask)6019 void saturn_state::saturn_vdp2_regs_w(offs_t offset, uint16_t data, uint16_t mem_mask)
6020 {
6021 COMBINE_DATA(&m_vdp2_regs[offset]);
6022
6023 if(m_vdp2.old_crmd != STV_VDP2_CRMD)
6024 {
6025 m_vdp2.old_crmd = STV_VDP2_CRMD;
6026 refresh_palette_data();
6027 }
6028 if(m_vdp2.old_tvmd != STV_VDP2_TVMD)
6029 {
6030 m_vdp2.old_tvmd = STV_VDP2_TVMD;
6031 stv_vdp2_dynamic_res_change();
6032 }
6033
6034 if(STV_VDP2_VRAMSZ)
6035 printf("VDP2 sets up 8 Mbit VRAM!\n");
6036 }
6037
get_hblank_duration(void)6038 int saturn_state::get_hblank_duration( void )
6039 {
6040 int res;
6041
6042 res = (STV_VDP2_HRES & 1) ? 455 : 427;
6043
6044 /* double pump horizontal max res */
6045 if(STV_VDP2_HRES & 2)
6046 res<<=1;
6047
6048 return res;
6049 }
6050
6051 /*some vblank lines measurements (according to Charles MacDonald)*/
6052 /* TODO: interlace mode "eats" one line, should be 262.5 */
get_vblank_duration(void)6053 int saturn_state::get_vblank_duration( void )
6054 {
6055 int res;
6056
6057 res = (m_vdp2.pal) ? 313 : 263;
6058
6059 /* compensate for interlacing */
6060 if((STV_VDP2_LSMD & 3) == 3)
6061 res<<=1;
6062
6063 if(STV_VDP2_HRES & 4)
6064 res = (STV_VDP2_HRES & 1) ? 561 : 525; //Hi-Vision / 31kHz Monitor
6065
6066 return res;
6067 }
6068
get_pixel_clock(void)6069 int saturn_state::get_pixel_clock( void )
6070 {
6071 int res,divider;
6072
6073 res = (m_vdp2.dotsel ? MASTER_CLOCK_352 : MASTER_CLOCK_320).value();
6074 /* TODO: divider is ALWAYS 8, this thing is just to over-compensate for MAME framework faults ... */
6075 divider = 8;
6076
6077 if(STV_VDP2_HRES & 2)
6078 divider>>=1;
6079
6080 if((STV_VDP2_LSMD & 3) == 3)
6081 divider>>=1;
6082
6083 if(STV_VDP2_HRES & 4) //TODO
6084 divider>>=1;
6085
6086 return res/divider;
6087 }
6088
6089 /* TODO: hblank position and hblank firing doesn't really match HW behaviour. */
get_hblank(void)6090 uint8_t saturn_state::get_hblank( void )
6091 {
6092 const rectangle &visarea = m_screen->visible_area();
6093 int cur_h = m_screen->hpos();
6094
6095 if (cur_h > visarea.right()) //TODO
6096 return 1;
6097
6098 return 0;
6099 }
6100
get_vblank(void)6101 uint8_t saturn_state::get_vblank( void )
6102 {
6103 int cur_v,vblank;
6104 cur_v = m_screen->vpos();
6105
6106 vblank = get_vblank_start_position() * get_ystep_count();
6107
6108 if (cur_v >= vblank)
6109 return 1;
6110
6111 return 0;
6112 }
6113
get_odd_bit(void)6114 uint8_t saturn_state::get_odd_bit( void )
6115 {
6116 if(STV_VDP2_HRES & 4) //exclusive monitor mode makes this bit to be always 1
6117 return 1;
6118
6119 // TODO: seabass explicitly wants this bit to be 0 when screen is disabled from bios to game transition.
6120 // But the documentation claims that "non-interlaced" mode is always 1.
6121 // grdforce tests this bit to be 1 from title screen to gameplay, ditto for finlarch/sasissu/magzun.
6122 // Assume documentation is wrong and actually always flip this bit.
6123 return m_vdp2.odd;//m_screen->frame_number() & 1;
6124 }
6125
get_vblank_start_position(void)6126 int saturn_state::get_vblank_start_position( void )
6127 {
6128 // TODO: test says that second setting happens at 241, might need further investigation ...
6129 // also first one happens at 240, but needs mods in SMPC otherwise we get 2 credits at startup in shanhigw and sokyugrt
6130 // (i.e. make a special screen device that handles this for us)
6131 const int d_vres[4] = { 224, 240, 256, 256 };
6132 int vres_mask;
6133 int vblank_line;
6134
6135 vres_mask = (m_vdp2.pal << 1)|1; //PAL uses mask 3, NTSC uses mask 1
6136 vblank_line = d_vres[STV_VDP2_VRES & vres_mask];
6137
6138 return vblank_line;
6139 }
6140
get_ystep_count(void)6141 int saturn_state::get_ystep_count( void )
6142 {
6143 int max_y = m_screen->height();
6144 int y_step;
6145
6146 y_step = 2;
6147
6148 if((max_y == 263 && m_vdp2.pal == 0) || (max_y == 313 && m_vdp2.pal == 1))
6149 y_step = 1;
6150
6151 return y_step;
6152 }
6153
6154 /* TODO: these needs to be checked via HW tests! */
get_hcounter(void)6155 int saturn_state::get_hcounter( void )
6156 {
6157 int hcount;
6158
6159 hcount = m_screen->hpos();
6160
6161 switch(STV_VDP2_HRES & 6)
6162 {
6163 /* Normal */
6164 case 0:
6165 hcount &= 0x1ff;
6166 hcount <<= 1;
6167 break;
6168 /* Hi-Res */
6169 case 2:
6170 hcount &= 0x3ff;
6171 break;
6172 /* Exclusive Normal*/
6173 case 4:
6174 hcount &= 0x1ff;
6175 break;
6176 /* Exclusive Hi-Res */
6177 case 6:
6178 hcount >>= 1;
6179 hcount &= 0x1ff;
6180 break;
6181 }
6182
6183 return hcount;
6184 }
6185
get_vcounter(void)6186 int saturn_state::get_vcounter( void )
6187 {
6188 int vcount;
6189
6190 vcount = m_screen->vpos();
6191
6192 /* Exclusive Monitor */
6193 if(STV_VDP2_HRES & 4)
6194 return vcount & 0x3ff;
6195
6196 /* Double Density Interlace */
6197 if((STV_VDP2_LSMD & 3) == 3)
6198 return (vcount & ~1) | (m_screen->frame_number() & 1);
6199
6200 /* docs says << 1, but according to HW tests it's a typo. */
6201 assert((vcount & 0x1ff) < ARRAY_LENGTH(true_vcount));
6202 return (true_vcount[vcount & 0x1ff][STV_VDP2_VRES]); // Non-interlace
6203 }
6204
stv_vdp2_state_save_postload(void)6205 void saturn_state::stv_vdp2_state_save_postload( void )
6206 {
6207 uint8_t *gfxdata = m_vdp2.gfx_decode.get();
6208 int offset;
6209 uint32_t data;
6210
6211 for ( offset = 0; offset < 0x100000/4; offset++ )
6212 {
6213 data = m_vdp2_vram[offset];
6214 /* put in gfx region for easy decoding */
6215 gfxdata[offset*4+0] = (data & 0xff000000) >> 24;
6216 gfxdata[offset*4+1] = (data & 0x00ff0000) >> 16;
6217 gfxdata[offset*4+2] = (data & 0x0000ff00) >> 8;
6218 gfxdata[offset*4+3] = (data & 0x000000ff) >> 0;
6219
6220 m_gfxdecode->gfx(0)->mark_dirty(offset/8);
6221 m_gfxdecode->gfx(1)->mark_dirty(offset/8);
6222 m_gfxdecode->gfx(2)->mark_dirty(offset/8);
6223 m_gfxdecode->gfx(3)->mark_dirty(offset/8);
6224
6225 /* 8-bit tiles overlap, so this affects the previous one as well */
6226 if (offset/8 != 0)
6227 {
6228 m_gfxdecode->gfx(2)->mark_dirty(offset/8 - 1);
6229 m_gfxdecode->gfx(3)->mark_dirty(offset/8 - 1);
6230 }
6231
6232 }
6233
6234 memset( &stv_rbg_cache_data, 0, sizeof(stv_rbg_cache_data));
6235 stv_rbg_cache_data.is_cache_dirty = 3;
6236 memset( &stv_vdp2_layer_data_placement, 0, sizeof(stv_vdp2_layer_data_placement));
6237
6238 refresh_palette_data();
6239 }
6240
stv_vdp2_exit(void)6241 void saturn_state::stv_vdp2_exit ( void )
6242 {
6243 m_vdp2.roz_bitmap[0].reset();
6244 m_vdp2.roz_bitmap[1].reset();
6245 }
6246
stv_vdp2_start(void)6247 int saturn_state::stv_vdp2_start ( void )
6248 {
6249 machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(&saturn_state::stv_vdp2_exit, this));
6250
6251 m_vdp2_regs = make_unique_clear<uint16_t[]>(0x040000/2 );
6252 m_vdp2_vram = make_unique_clear<uint32_t[]>(0x100000/4 );
6253 m_vdp2_cram = make_unique_clear<uint32_t[]>(0x080000/4 );
6254 m_vdp2.gfx_decode = std::make_unique<uint8_t[]>(0x100000 );
6255
6256 // m_gfxdecode->gfx(0)->granularity()=4;
6257 // m_gfxdecode->gfx(1)->granularity()=4;
6258
6259 memset( &stv_rbg_cache_data, 0, sizeof(stv_rbg_cache_data));
6260 stv_rbg_cache_data.is_cache_dirty = 3;
6261 memset( &stv_vdp2_layer_data_placement, 0, sizeof(stv_vdp2_layer_data_placement));
6262
6263 save_pointer(NAME(m_vdp2_regs), 0x040000/2);
6264 save_pointer(NAME(m_vdp2_vram), 0x100000/4);
6265 save_pointer(NAME(m_vdp2_cram), 0x080000/4);
6266 machine().save().register_postload(save_prepost_delegate(FUNC(saturn_state::stv_vdp2_state_save_postload), this));
6267
6268 return 0;
6269 }
6270
6271 /* maybe we should move this to video/stv.c */
VIDEO_START_MEMBER(saturn_state,stv_vdp2)6272 VIDEO_START_MEMBER(saturn_state,stv_vdp2)
6273 {
6274 int i;
6275 m_screen->register_screen_bitmap(m_tmpbitmap);
6276 stv_vdp2_start();
6277 stv_vdp1_start();
6278 m_vdpdebug_roz = 0;
6279 m_gfxdecode->gfx(0)->set_source(m_vdp2.gfx_decode.get());
6280 m_gfxdecode->gfx(1)->set_source(m_vdp2.gfx_decode.get());
6281 m_gfxdecode->gfx(2)->set_source(m_vdp2.gfx_decode.get());
6282 m_gfxdecode->gfx(3)->set_source(m_vdp2.gfx_decode.get());
6283
6284 /* calc V counter offsets */
6285 /* 224 mode */
6286 for(i=0;i<263;i++)
6287 {
6288 true_vcount[i][0] = i;
6289 if(i>0xec)
6290 true_vcount[i][0]+=0xf9;
6291 }
6292
6293 for(i=0;i<263;i++)
6294 {
6295 true_vcount[i][1] = i;
6296 if(i>0xf5)
6297 true_vcount[i][1]+=0xf9;
6298 }
6299
6300 /* 256 mode, todo */
6301 for(i=0;i<263;i++)
6302 {
6303 true_vcount[i][2] = i;
6304 true_vcount[i][3] = i;
6305 }
6306 }
6307
stv_vdp2_dynamic_res_change(void)6308 void saturn_state::stv_vdp2_dynamic_res_change( void )
6309 {
6310 const int d_vres[4] = { 224, 240, 256, 256 };
6311 const int d_hres[4] = { 320, 352, 640, 704 };
6312 int horz_res,vert_res;
6313 int vres_mask;
6314
6315 // reset odd bit if a dynamic resolution change occurs, seabass ST-V cares!
6316 m_vdp2.odd = 1;
6317 vres_mask = (m_vdp2.pal << 1)|1; //PAL uses mask 3, NTSC uses mask 1
6318 vert_res = d_vres[STV_VDP2_VRES & vres_mask];
6319
6320 if((STV_VDP2_VRES & 3) == 3)
6321 popmessage("Illegal VRES MODE, contact MAMEdev");
6322
6323 /*Double-density interlace mode,doubles the vertical res*/
6324 if((STV_VDP2_LSMD & 3) == 3) { vert_res*=2; }
6325
6326 horz_res = d_hres[STV_VDP2_HRES & 3];
6327 /*Exclusive modes,they sets the Vertical Resolution without considering the
6328 VRES register.*/
6329 if(STV_VDP2_HRES & 4)
6330 vert_res = 480;
6331
6332 {
6333 int vblank_period,hblank_period;
6334 attoseconds_t refresh;
6335 rectangle visarea(0, horz_res-1, 0, vert_res-1);
6336
6337 vblank_period = get_vblank_duration();
6338 hblank_period = get_hblank_duration();
6339 refresh = HZ_TO_ATTOSECONDS(get_pixel_clock()) * (hblank_period) * vblank_period;
6340 //printf("%d %d %d %d\n",horz_res,vert_res,horz_res+hblank_period,vblank_period);
6341
6342 m_screen->configure(hblank_period, vblank_period, visarea, refresh );
6343 }
6344 // m_screen->set_visible_area(0*8, horz_res-1,0*8, vert_res-1);
6345 }
6346
6347 /*This is for calculating the rgb brightness*/
6348 /*TODO: Optimize this...*/
stv_vdp2_fade_effects(void)6349 void saturn_state::stv_vdp2_fade_effects( void )
6350 {
6351 /*
6352 Note:We have to use temporary storages because palette_get_color must use
6353 variables setted with unsigned int8
6354 */
6355 int16_t t_r,t_g,t_b;
6356 uint8_t r,g,b;
6357 rgb_t color;
6358 int i;
6359 //popmessage("%04x %04x",STV_VDP2_CLOFEN,STV_VDP2_CLOFSL);
6360 for(i=0;i<2048;i++)
6361 {
6362 /*Fade A*/
6363 color = m_palette->pen_color(i);
6364 t_r = (STV_VDP2_COAR & 0x100) ? (color.r() - (0x100 - (STV_VDP2_COAR & 0xff))) : ((STV_VDP2_COAR & 0xff) + color.r());
6365 t_g = (STV_VDP2_COAG & 0x100) ? (color.g() - (0x100 - (STV_VDP2_COAG & 0xff))) : ((STV_VDP2_COAG & 0xff) + color.g());
6366 t_b = (STV_VDP2_COAB & 0x100) ? (color.b() - (0x100 - (STV_VDP2_COAB & 0xff))) : ((STV_VDP2_COAB & 0xff) + color.b());
6367 if(t_r < 0) { t_r = 0; }
6368 if(t_r > 0xff) { t_r = 0xff; }
6369 if(t_g < 0) { t_g = 0; }
6370 if(t_g > 0xff) { t_g = 0xff; }
6371 if(t_b < 0) { t_b = 0; }
6372 if(t_b > 0xff) { t_b = 0xff; }
6373 r = t_r;
6374 g = t_g;
6375 b = t_b;
6376 m_palette->set_pen_color(i+(2048*1),rgb_t(r,g,b));
6377
6378 /*Fade B*/
6379 color = m_palette->pen_color(i);
6380 t_r = (STV_VDP2_COBR & 0x100) ? (color.r() - (0xff - (STV_VDP2_COBR & 0xff))) : ((STV_VDP2_COBR & 0xff) + color.r());
6381 t_g = (STV_VDP2_COBG & 0x100) ? (color.g() - (0xff - (STV_VDP2_COBG & 0xff))) : ((STV_VDP2_COBG & 0xff) + color.g());
6382 t_b = (STV_VDP2_COBB & 0x100) ? (color.b() - (0xff - (STV_VDP2_COBB & 0xff))) : ((STV_VDP2_COBB & 0xff) + color.b());
6383 if(t_r < 0) { t_r = 0; }
6384 if(t_r > 0xff) { t_r = 0xff; }
6385 if(t_g < 0) { t_g = 0; }
6386 if(t_g > 0xff) { t_g = 0xff; }
6387 if(t_b < 0) { t_b = 0; }
6388 if(t_b > 0xff) { t_b = 0xff; }
6389 r = t_r;
6390 g = t_g;
6391 b = t_b;
6392 m_palette->set_pen_color(i+(2048*2),rgb_t(r,g,b));
6393 }
6394 //popmessage("%04x %04x %04x %04x %04x %04x",STV_VDP2_COAR,STV_VDP2_COAG,STV_VDP2_COAB,STV_VDP2_COBR,STV_VDP2_COBG,STV_VDP2_COBB);
6395 }
6396
stv_vdp2_get_window0_coordinates(int * s_x,int * e_x,int * s_y,int * e_y,int y)6397 void saturn_state::stv_vdp2_get_window0_coordinates(int *s_x, int *e_x, int *s_y, int *e_y, int y)
6398 {
6399 /*W0*/
6400 switch(STV_VDP2_LSMD & 3)
6401 {
6402 case 0:
6403 case 1:
6404 case 2:
6405 *s_y = ((STV_VDP2_W0SY & 0x3ff) >> 0);
6406 *e_y = ((STV_VDP2_W0EY & 0x3ff) >> 0);
6407 break;
6408 case 3:
6409 *s_y = ((STV_VDP2_W0SY & 0x7ff) >> 0);
6410 *e_y = ((STV_VDP2_W0EY & 0x7ff) >> 0);
6411 break;
6412 }
6413 // check if line window is enabled
6414 if(STV_VDP2_W0LWE)
6415 {
6416 uint32_t base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
6417 uint32_t address = (STV_VDP2_W0LWTA & base_mask) * 2;
6418 // double density makes the line window to fetch data every two lines
6419 uint8_t interlace = (STV_VDP2_LSMD == 3);
6420 uint32_t vram_data = m_vdp2_vram[(address >> 2)+(y >> interlace)];
6421
6422 *s_x = (vram_data >> 16) & 0x3ff;
6423 *e_x = (vram_data & 0x3ff);
6424 }
6425 else
6426 {
6427 switch(STV_VDP2_HRES & 6)
6428 {
6429 /*Normal*/
6430 case 0:
6431 *s_x = ((STV_VDP2_W0SX & 0x3fe) >> 1);
6432 *e_x = ((STV_VDP2_W0EX & 0x3fe) >> 1);
6433 break;
6434 /*Hi-Res*/
6435 case 2:
6436 *s_x = ((STV_VDP2_W0SX & 0x3ff) >> 0);
6437 *e_x = ((STV_VDP2_W0EX & 0x3ff) >> 0);
6438 break;
6439 /*Exclusive Normal*/
6440 case 4:
6441 *s_x = ((STV_VDP2_W0SX & 0x1ff) >> 0);
6442 *e_x = ((STV_VDP2_W0EX & 0x1ff) >> 0);
6443 *s_y = ((STV_VDP2_W0SY & 0x3ff) >> 0);
6444 *e_y = ((STV_VDP2_W0EY & 0x3ff) >> 0);
6445 break;
6446 /*Exclusive Hi-Res*/
6447 case 6:
6448 *s_x = ((STV_VDP2_W0SX & 0x1ff) << 1);
6449 *e_x = ((STV_VDP2_W0EX & 0x1ff) << 1);
6450 *s_y = ((STV_VDP2_W0SY & 0x3ff) >> 0);
6451 *e_y = ((STV_VDP2_W0EY & 0x3ff) >> 0);
6452 break;
6453 }
6454 }
6455 }
6456
stv_vdp2_get_window1_coordinates(int * s_x,int * e_x,int * s_y,int * e_y,int y)6457 void saturn_state::stv_vdp2_get_window1_coordinates(int *s_x, int *e_x, int *s_y, int *e_y, int y)
6458 {
6459 /*W1*/
6460 switch(STV_VDP2_LSMD & 3)
6461 {
6462 case 0:
6463 case 1:
6464 case 2:
6465 *s_y = ((STV_VDP2_W1SY & 0x3ff) >> 0);
6466 *e_y = ((STV_VDP2_W1EY & 0x3ff) >> 0);
6467 break;
6468 case 3:
6469 *s_y = ((STV_VDP2_W1SY & 0x7ff) >> 0);
6470 *e_y = ((STV_VDP2_W1EY & 0x7ff) >> 0);
6471 break;
6472 }
6473 // check if line window is enabled
6474 if(STV_VDP2_W1LWE)
6475 {
6476 uint32_t base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
6477 uint32_t address = (STV_VDP2_W1LWTA & base_mask) * 2;
6478 // double density makes the line window to fetch data every two lines
6479 uint8_t interlace = (STV_VDP2_LSMD == 3);
6480 uint32_t vram_data = m_vdp2_vram[(address >> 2)+(y >> interlace)];
6481
6482 *s_x = (vram_data >> 16) & 0x3ff;
6483 *e_x = (vram_data & 0x3ff);
6484 }
6485 else
6486 {
6487 switch(STV_VDP2_HRES & 6)
6488 {
6489 /*Normal*/
6490 case 0:
6491 *s_x = ((STV_VDP2_W1SX & 0x3fe) >> 1);
6492 *e_x = ((STV_VDP2_W1EX & 0x3fe) >> 1);
6493 break;
6494 /*Hi-Res*/
6495 case 2:
6496 *s_x = ((STV_VDP2_W1SX & 0x3ff) >> 0);
6497 *e_x = ((STV_VDP2_W1EX & 0x3ff) >> 0);
6498 break;
6499 /*Exclusive Normal*/
6500 case 4:
6501 *s_x = ((STV_VDP2_W1SX & 0x1ff) >> 0);
6502 *e_x = ((STV_VDP2_W1EX & 0x1ff) >> 0);
6503 *s_y = ((STV_VDP2_W1SY & 0x3ff) >> 0);
6504 *e_y = ((STV_VDP2_W1EY & 0x3ff) >> 0);
6505 break;
6506 /*Exclusive Hi-Res*/
6507 case 6:
6508 *s_x = ((STV_VDP2_W1SX & 0x1ff) << 1);
6509 *e_x = ((STV_VDP2_W1EX & 0x1ff) << 1);
6510 *s_y = ((STV_VDP2_W1SY & 0x3ff) >> 0);
6511 *e_y = ((STV_VDP2_W1EY & 0x3ff) >> 0);
6512 break;
6513 }
6514 }
6515 }
6516
get_window_pixel(int s_x,int e_x,int s_y,int e_y,int x,int y,uint8_t win_num)6517 int saturn_state::get_window_pixel(int s_x,int e_x,int s_y,int e_y,int x, int y,uint8_t win_num)
6518 {
6519 int res;
6520
6521 res = 1;
6522 if(stv2_current_tilemap.window_control.enabled[win_num])
6523 {
6524 if(stv2_current_tilemap.window_control.area[win_num])
6525 res = (y >= s_y && y <= e_y && x >= s_x && x <= e_x);
6526 else
6527 res = (y >= s_y && y <= e_y && x >= s_x && x <= e_x) ^ 1;
6528 }
6529
6530 return res;
6531 }
6532
stv_vdp2_window_process(int x,int y)6533 inline int saturn_state::stv_vdp2_window_process(int x,int y)
6534 {
6535 int s_x=0,e_x=0,s_y=0,e_y=0;
6536 int w0_pix, w1_pix;
6537
6538 if (stv2_current_tilemap.window_control.enabled[0] == 0 &&
6539 stv2_current_tilemap.window_control.enabled[1] == 0)
6540 return 1;
6541
6542 stv_vdp2_get_window0_coordinates(&s_x, &e_x, &s_y, &e_y, y);
6543 w0_pix = get_window_pixel(s_x,e_x,s_y,e_y,x,y,0);
6544
6545 stv_vdp2_get_window1_coordinates(&s_x, &e_x, &s_y, &e_y, y);
6546 w1_pix = get_window_pixel(s_x,e_x,s_y,e_y,x,y,1);
6547
6548 return stv2_current_tilemap.window_control.logic & 1 ? (w0_pix | w1_pix) : (w0_pix & w1_pix);
6549 }
6550
6551 /* TODO: remove this crap. */
stv_vdp2_apply_window_on_layer(rectangle & cliprect)6552 int saturn_state::stv_vdp2_apply_window_on_layer(rectangle &cliprect)
6553 {
6554 int s_x=0,e_x=0,s_y=0,e_y=0;
6555
6556 if ( stv2_current_tilemap.window_control.enabled[0] && (!stv2_current_tilemap.window_control.area[0]))
6557 {
6558 /* w0, transparent outside supported */
6559 stv_vdp2_get_window0_coordinates(&s_x, &e_x, &s_y, &e_y, 0);
6560
6561 if ( s_x > cliprect.min_x ) cliprect.min_x = s_x;
6562 if ( e_x < cliprect.max_x ) cliprect.max_x = e_x;
6563 if ( s_y > cliprect.min_y ) cliprect.min_y = s_y;
6564 if ( e_y < cliprect.max_y ) cliprect.max_y = e_y;
6565
6566 return 1;
6567 }
6568 else if ( stv2_current_tilemap.window_control.enabled[1] && (!stv2_current_tilemap.window_control.area[1]) )
6569 {
6570 /* w1, transparent outside supported */
6571 stv_vdp2_get_window1_coordinates(&s_x, &e_x, &s_y, &e_y, 0);
6572
6573 if ( s_x > cliprect.min_x ) cliprect.min_x = s_x;
6574 if ( e_x < cliprect.max_x ) cliprect.max_x = e_x;
6575 if ( s_y > cliprect.min_y ) cliprect.min_y = s_y;
6576 if ( e_y < cliprect.max_y ) cliprect.max_y = e_y;
6577
6578 return 1;
6579 }
6580 else
6581 {
6582 return 0;
6583 }
6584 }
6585
draw_sprites(bitmap_rgb32 & bitmap,const rectangle & cliprect,uint8_t pri)6586 void saturn_state::draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, uint8_t pri)
6587 {
6588 int x,y,r,g,b;
6589 int i;
6590 uint16_t pix;
6591 uint16_t *framebuffer_line;
6592 uint32_t *bitmap_line, *bitmap_line2 = nullptr;
6593 uint8_t interlace_framebuffer;
6594 uint8_t double_x;
6595 static const uint16_t sprite_colormask_table[] = {
6596 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x03ff, 0x07ff, 0x03ff, 0x01ff,
6597 0x007f, 0x003f, 0x003f, 0x003f, 0x00ff, 0x00ff, 0x00ff, 0x00ff
6598 };
6599 static const uint16_t priority_shift_table[] = { 14, 13, 14, 13, 13, 12, 12, 12, 7, 7, 6, 0, 7, 7, 6, 0 };
6600 static const uint16_t priority_mask_table[] = { 3, 7, 1, 3, 3, 7, 7, 7, 1, 1, 3, 0, 1, 1, 3, 0 };
6601 static const uint16_t ccrr_shift_table[] = { 11, 11, 11, 11, 10, 11, 10, 9, 0, 6, 0, 6, 0, 6, 0, 6 };
6602 static const uint16_t ccrr_mask_table[] = { 7, 3, 7, 3, 7, 1, 3, 7, 0, 1, 0, 3, 0, 1, 0, 3 };
6603 static const uint16_t shadow_mask_table[] = { 0, 0, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0, 0, 0, 0, 0, 0, 0, 0 };
6604 uint16_t alpha_enabled;
6605
6606 int sprite_type;
6607 int sprite_colormask;
6608 int color_offset_pal;
6609 int sprite_shadow;
6610 uint16_t sprite_priority_shift, sprite_priority_mask, sprite_ccrr_shift, sprite_ccrr_mask;
6611 uint8_t priority;
6612 uint8_t ccr = 0;
6613 uint8_t sprite_priorities[8];
6614 uint8_t sprite_ccr[8];
6615 int sprite_color_mode = STV_VDP2_SPCLMD;
6616
6617 if ( (stv_sprite_priorities_usage_valid == 1) && (stv_sprite_priorities_used[pri] == 0) )
6618 return;
6619
6620 sprite_priorities[0] = STV_VDP2_S0PRIN;
6621 sprite_priorities[1] = STV_VDP2_S1PRIN;
6622 sprite_priorities[2] = STV_VDP2_S2PRIN;
6623 sprite_priorities[3] = STV_VDP2_S3PRIN;
6624 sprite_priorities[4] = STV_VDP2_S4PRIN;
6625 sprite_priorities[5] = STV_VDP2_S5PRIN;
6626 sprite_priorities[6] = STV_VDP2_S6PRIN;
6627 sprite_priorities[7] = STV_VDP2_S7PRIN;
6628
6629 sprite_ccr[0] = STV_VDP2_S0CCRT;
6630 sprite_ccr[1] = STV_VDP2_S1CCRT;
6631 sprite_ccr[2] = STV_VDP2_S2CCRT;
6632 sprite_ccr[3] = STV_VDP2_S3CCRT;
6633 sprite_ccr[4] = STV_VDP2_S4CCRT;
6634 sprite_ccr[5] = STV_VDP2_S5CCRT;
6635 sprite_ccr[6] = STV_VDP2_S6CCRT;
6636 sprite_ccr[7] = STV_VDP2_S7CCRT;
6637
6638 sprite_type = STV_VDP2_SPTYPE;
6639 sprite_colormask = sprite_colormask_table[sprite_type];
6640 sprite_priority_shift = priority_shift_table[sprite_type];
6641 sprite_priority_mask = priority_mask_table[sprite_type];
6642 sprite_ccrr_shift = ccrr_shift_table[sprite_type];
6643 sprite_ccrr_mask = ccrr_mask_table[sprite_type];
6644 sprite_shadow = shadow_mask_table[sprite_type];
6645
6646 for ( i = 0; i < (sprite_priority_mask+1); i++ ) if ( sprite_priorities[i] == pri ) break;
6647 if ( i == (sprite_priority_mask+1) ) return;
6648
6649 /* color offset (RGB brightness) */
6650 color_offset_pal = 0;
6651 if ( STV_VDP2_SPCOEN )
6652 {
6653 if ( STV_VDP2_SPCOSL == 0 )
6654 { color_offset_pal = 2048; }
6655 else
6656 { color_offset_pal = 2048*2; }
6657 }
6658
6659 /* color calculation (alpha blending)*/
6660 if ( STV_VDP2_SPCCEN )
6661 {
6662 alpha_enabled = 0;
6663 switch( STV_VDP2_SPCCCS )
6664 {
6665 case 0x0: if ( pri <= STV_VDP2_SPCCN ) alpha_enabled = 1; break;
6666 case 0x1: if ( pri == STV_VDP2_SPCCN ) alpha_enabled = 1; break;
6667 case 0x2: if ( pri >= STV_VDP2_SPCCN ) alpha_enabled = 1; break;
6668 case 0x3: alpha_enabled = 2; sprite_shadow = 0; break;
6669 }
6670 }
6671 else
6672 {
6673 alpha_enabled = 0;
6674 }
6675
6676 /* framebuffer interlace */
6677 if ( (STV_VDP2_LSMD == 3) && m_vdp1.framebuffer_double_interlace == 0 )
6678 interlace_framebuffer = 1;
6679 else
6680 interlace_framebuffer = 0;
6681
6682 /*Guess:Some games needs that the horizontal sprite size to be doubled
6683 (TODO: understand the proper settings,it might not work like this)*/
6684 if(STV_VDP1_TVM == 0 && STV_VDP2_HRES & 2) // astrass & findlove
6685 double_x = 1;
6686 else
6687 double_x = 0;
6688
6689 /* window control */
6690 stv2_current_tilemap.window_control.logic = STV_VDP2_SPLOG;
6691 stv2_current_tilemap.window_control.enabled[0] = STV_VDP2_SPW0E;
6692 stv2_current_tilemap.window_control.enabled[1] = STV_VDP2_SPW1E;
6693 // stv2_current_tilemap.window_control.? = STV_VDP2_SPSWE;
6694 stv2_current_tilemap.window_control.area[0] = STV_VDP2_SPW0A;
6695 stv2_current_tilemap.window_control.area[1] = STV_VDP2_SPW1A;
6696 // stv2_current_tilemap.window_control.? = STV_VDP2_SPSWA;
6697
6698 // stv_vdp2_apply_window_on_layer(mycliprect);
6699
6700 if (interlace_framebuffer == 0 && double_x == 0 )
6701 {
6702 if ( alpha_enabled == 0 )
6703 {
6704 for ( y = cliprect.top(); y <= cliprect.bottom(); y++ )
6705 {
6706 if ( stv_sprite_priorities_usage_valid )
6707 if (stv_sprite_priorities_in_fb_line[y][pri] == 0)
6708 continue;
6709
6710 framebuffer_line = m_vdp1.framebuffer_display_lines[y];
6711 bitmap_line = &bitmap.pix(y);
6712
6713 for ( x = cliprect.left(); x <= cliprect.right(); x++ )
6714 {
6715 if(!stv_vdp2_window_process(x,y))
6716 continue;
6717
6718 pix = framebuffer_line[x];
6719 if ( (pix & 0x8000) && sprite_color_mode)
6720 {
6721 if ( sprite_priorities[0] != pri )
6722 {
6723 stv_sprite_priorities_used[sprite_priorities[0]] = 1;
6724 stv_sprite_priorities_in_fb_line[y][sprite_priorities[0]] = 1;
6725 continue;
6726 };
6727
6728 if(STV_VDP2_SPWINEN && pix == 0x8000) /* Pukunpa */
6729 continue;
6730
6731 b = pal5bit((pix & 0x7c00) >> 10);
6732 g = pal5bit((pix & 0x03e0) >> 5);
6733 r = pal5bit( pix & 0x001f);
6734 if ( color_offset_pal )
6735 {
6736 stv_vdp2_compute_color_offset( &r, &g, &b, STV_VDP2_SPCOSL );
6737 }
6738
6739 bitmap_line[x] = rgb_t(r, g, b);
6740 }
6741 else
6742 {
6743 priority = sprite_priorities[(pix >> sprite_priority_shift) & sprite_priority_mask];
6744 if ( priority != pri )
6745 {
6746 stv_sprite_priorities_used[priority] = 1;
6747 stv_sprite_priorities_in_fb_line[y][priority] = 1;
6748 continue;
6749 };
6750
6751 // Pretty Fighter X, Game Tengoku shadows
6752 // TODO: Pretty Fighter X doesn't read what's behind on title screen, VDP1 bug?
6753 // TODO: seldomly Game Tengoku shadows aren't drawn properly
6754 if(pix & 0x8000 && STV_VDP2_SDCTL & 0x100)
6755 {
6756 rgb_t p = bitmap_line[x];
6757 bitmap_line[x] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
6758 }
6759 else
6760 {
6761 pix &= sprite_colormask;
6762 if ( pix == (sprite_colormask - 1) )
6763 {
6764 /*shadow - in reality, we should check from what layer pixel beneath comes...*/
6765 if ( STV_VDP2_SDCTL & 0x3f )
6766 {
6767 rgb_t p = bitmap_line[x];
6768 bitmap_line[x] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
6769 }
6770 /* note that when shadows are disabled, "shadow" palette entries are not drawn */
6771 }
6772 else if ( pix )
6773 {
6774 pix += (STV_VDP2_SPCAOS << 8);
6775 pix &= 0x7ff;
6776 pix += color_offset_pal;
6777 bitmap_line[x] = m_palette->pen( pix );
6778
6779 }
6780 }
6781
6782 /* TODO: I don't think this one makes much sense ... (1) */
6783 if ( pix & sprite_shadow )
6784 {
6785 if ( pix & ~sprite_shadow )
6786 {
6787 rgb_t p = bitmap_line[x];
6788 bitmap_line[x] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
6789 }
6790 }
6791 }
6792 }
6793 }
6794 }
6795 else //alpha_enabled == 1
6796 {
6797 for ( y = cliprect.top(); y <= cliprect.bottom(); y++ )
6798 {
6799 if ( stv_sprite_priorities_usage_valid )
6800 if (stv_sprite_priorities_in_fb_line[y][pri] == 0)
6801 continue;
6802
6803 framebuffer_line = m_vdp1.framebuffer_display_lines[y];
6804 bitmap_line = &bitmap.pix(y);
6805
6806 for ( x = cliprect.left(); x <= cliprect.right(); x++ )
6807 {
6808 if(!stv_vdp2_window_process(x,y))
6809 continue;
6810
6811 pix = framebuffer_line[x];
6812 if ( (pix & 0x8000) && sprite_color_mode)
6813 {
6814 if ( sprite_priorities[0] != pri )
6815 {
6816 stv_sprite_priorities_used[sprite_priorities[0]] = 1;
6817 stv_sprite_priorities_in_fb_line[y][sprite_priorities[0]] = 1;
6818 continue;
6819 };
6820
6821 b = pal5bit((pix & 0x7c00) >> 10);
6822 g = pal5bit((pix & 0x03e0) >> 5);
6823 r = pal5bit( pix & 0x001f);
6824 if ( color_offset_pal )
6825 {
6826 stv_vdp2_compute_color_offset( &r, &g, &b, STV_VDP2_SPCOSL );
6827 }
6828 ccr = sprite_ccr[0];
6829 if ( STV_VDP2_CCMD )
6830 {
6831 bitmap_line[x] = add_blend_r32( bitmap_line[x], rgb_t(r, g, b));
6832 }
6833 else
6834 {
6835 bitmap_line[x] = alpha_blend_r32( bitmap_line[x], rgb_t(r, g ,b), ((uint16_t)(0x1f-ccr)*0xff)/0x1f);
6836 }
6837 }
6838 else
6839 {
6840 priority = sprite_priorities[(pix >> sprite_priority_shift) & sprite_priority_mask];
6841 if ( priority != pri )
6842 {
6843 stv_sprite_priorities_used[priority] = 1;
6844 stv_sprite_priorities_in_fb_line[y][priority] = 1;
6845 continue;
6846 };
6847
6848 ccr = sprite_ccr[ (pix >> sprite_ccrr_shift) & sprite_ccrr_mask ];
6849 if ( alpha_enabled == 2 )
6850 {
6851 if ( ( pix & 0x8000 ) == 0 )
6852 {
6853 ccr = 0;
6854 }
6855 }
6856
6857
6858 {
6859 pix &= sprite_colormask;
6860 if ( pix == (sprite_colormask - 1) )
6861 {
6862 /*shadow - in reality, we should check from what layer pixel beneath comes...*/
6863 if ( STV_VDP2_SDCTL & 0x3f )
6864 {
6865 rgb_t p = bitmap_line[x];
6866 bitmap_line[x] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
6867 }
6868 /* note that when shadows are disabled, "shadow" palette entries are not drawn */
6869 } else if ( pix )
6870 {
6871 pix += (STV_VDP2_SPCAOS << 8);
6872 pix &= 0x7ff;
6873 pix += color_offset_pal;
6874 if ( ccr > 0 )
6875 {
6876 if ( STV_VDP2_CCMD )
6877 {
6878 bitmap_line[x] = add_blend_r32( bitmap_line[x], m_palette->pen(pix) );
6879 }
6880 else
6881 {
6882 bitmap_line[x] = alpha_blend_r32( bitmap_line[x], m_palette->pen(pix), ((uint16_t)(0x1f-ccr)*0xff)/0x1f );
6883 }
6884 }
6885 else
6886 bitmap_line[x] = m_palette->pen(pix);
6887 }
6888 }
6889
6890 /* TODO: (1) */
6891 if ( pix & sprite_shadow )
6892 {
6893 if ( pix & ~sprite_shadow )
6894 {
6895 rgb_t p = bitmap_line[x];
6896 bitmap_line[x] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
6897 }
6898 }
6899 }
6900 }
6901 }
6902 }
6903 }
6904 else
6905 {
6906 for ( y = cliprect.top(); y <= cliprect.bottom() / (interlace_framebuffer+1); y++ )
6907 {
6908 if ( stv_sprite_priorities_usage_valid )
6909 if (stv_sprite_priorities_in_fb_line[y][pri] == 0)
6910 continue;
6911
6912 framebuffer_line = m_vdp1.framebuffer_display_lines[y];
6913 if ( interlace_framebuffer == 0 )
6914 {
6915 bitmap_line = &bitmap.pix(y);
6916 }
6917 else
6918 {
6919 bitmap_line = &bitmap.pix(2*y);
6920 bitmap_line2 = &bitmap.pix(2*y + 1);
6921 }
6922
6923 for ( x = cliprect.left(); x <= cliprect.right() /(double_x+1) ; x++ )
6924 {
6925 if(!stv_vdp2_window_process(x,y))
6926 continue;
6927
6928 pix = framebuffer_line[x];
6929 if ( (pix & 0x8000) && sprite_color_mode)
6930 {
6931 if ( sprite_priorities[0] != pri )
6932 {
6933 stv_sprite_priorities_used[sprite_priorities[0]] = 1;
6934 stv_sprite_priorities_in_fb_line[y][sprite_priorities[0]] = 1;
6935 continue;
6936 };
6937
6938 b = pal5bit((pix & 0x7c00) >> 10);
6939 g = pal5bit((pix & 0x03e0) >> 5);
6940 r = pal5bit( pix & 0x001f);
6941 if ( color_offset_pal )
6942 {
6943 stv_vdp2_compute_color_offset( &r, &g, &b, STV_VDP2_SPCOSL );
6944 }
6945 if ( alpha_enabled == 0 )
6946 {
6947 if(double_x)
6948 {
6949 bitmap_line[x*2] = rgb_t(r, g, b);
6950 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = rgb_t(r, g, b);
6951 bitmap_line[x*2+1] = rgb_t(r, g, b);
6952 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = rgb_t(r, g, b);
6953 }
6954 else
6955 {
6956 bitmap_line[x] = rgb_t(r, g, b);
6957 if ( interlace_framebuffer == 1 ) bitmap_line2[x] = rgb_t(r, g, b);
6958 }
6959 }
6960 else // alpha_blend == 1
6961 {
6962 ccr = sprite_ccr[0];
6963
6964 if ( STV_VDP2_CCMD )
6965 {
6966 if(double_x)
6967 {
6968 bitmap_line[x*2] = add_blend_r32( bitmap_line[x*2], rgb_t(r, g, b) );
6969 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = add_blend_r32( bitmap_line2[x*2], rgb_t(r, g, b) );
6970 bitmap_line[x*2+1] = add_blend_r32( bitmap_line[x*2+1], rgb_t(r, g, b) );
6971 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = add_blend_r32( bitmap_line2[x*2+1], rgb_t(r, g, b) );
6972 }
6973 else
6974 {
6975 bitmap_line[x] = add_blend_r32( bitmap_line[x], rgb_t(r, g, b) );
6976 if ( interlace_framebuffer == 1 ) bitmap_line2[x] = add_blend_r32( bitmap_line2[x], rgb_t(r, g, b) );
6977 }
6978 }
6979 else
6980 {
6981 if(double_x)
6982 {
6983 bitmap_line[x*2] = alpha_blend_r32( bitmap_line[x*2], rgb_t(r, g, b), ((uint16_t)(0x1f-ccr)*0xff)/0x1f );
6984 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = alpha_blend_r32( bitmap_line2[x*2], rgb_t(r, g, b), ((uint16_t)(0x1f-ccr)*0xff)/0x1f );
6985 bitmap_line[x*2+1] = alpha_blend_r32( bitmap_line[x*2+1], rgb_t(r, g, b), ((uint16_t)(0x1f-ccr)*0xff)/0x1f );
6986 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = alpha_blend_r32( bitmap_line2[x*2+1], rgb_t(r, g, b), ((uint16_t)(0x1f-ccr)*0xff)/0x1f);
6987 }
6988 else
6989 {
6990 bitmap_line[x] = alpha_blend_r32( bitmap_line[x], rgb_t(r, g, b), ((uint16_t)(0x1f-ccr)*0xff)/0x1f);
6991 if ( interlace_framebuffer == 1 ) bitmap_line2[x] = alpha_blend_r32( bitmap_line2[x], rgb_t(r, g, b), ((uint16_t)(0x1f-ccr)*0xff)/0x1f);
6992 }
6993 }
6994 }
6995 }
6996 else
6997 {
6998 priority = sprite_priorities[(pix >> sprite_priority_shift) & sprite_priority_mask];
6999 if ( priority != pri )
7000 {
7001 stv_sprite_priorities_used[priority] = 1;
7002 stv_sprite_priorities_in_fb_line[y][priority] = 1;
7003 continue;
7004 };
7005
7006 if ( alpha_enabled )
7007 ccr = sprite_ccr[ (pix >> sprite_ccrr_shift) & sprite_ccrr_mask ];
7008
7009 if ( alpha_enabled == 2 )
7010 {
7011 if ( ( pix & 0x8000 ) == 0 )
7012 {
7013 ccr = 0;
7014 }
7015 }
7016
7017 {
7018 pix &= sprite_colormask;
7019 if ( pix == (sprite_colormask - 1) )
7020 {
7021 /*shadow - in reality, we should check from what layer pixel beneath comes...*/
7022 if ( STV_VDP2_SDCTL & 0x3f )
7023 {
7024 rgb_t p = bitmap_line[x];
7025 if(double_x)
7026 {
7027 p = bitmap_line[x*2];
7028 bitmap_line[x*2] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
7029 p = bitmap_line[x*2+1];
7030 bitmap_line[x*2+1] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
7031 }
7032 else
7033 bitmap_line[x] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
7034 }
7035 /* note that when shadows are disabled, "shadow" palette entries are not drawn */
7036 } else if ( pix )
7037 {
7038 pix += (STV_VDP2_SPCAOS << 8);
7039 pix &= 0x7ff;
7040 pix += color_offset_pal;
7041 if ( alpha_enabled == 0 )
7042 {
7043 if(double_x)
7044 {
7045 bitmap_line[x*2] = m_palette->pen( pix );
7046 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = m_palette->pen( pix );
7047 bitmap_line[x*2+1] = m_palette->pen( pix );
7048 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = m_palette->pen( pix );
7049 }
7050 else
7051 {
7052 bitmap_line[x] = m_palette->pen( pix );
7053 if ( interlace_framebuffer == 1 ) bitmap_line2[x] = m_palette->pen( pix );
7054 }
7055 }
7056 else // alpha_blend == 1
7057 {
7058 if ( STV_VDP2_CCMD )
7059 {
7060 if(double_x)
7061 {
7062 bitmap_line[x*2] = add_blend_r32( bitmap_line[x*2], m_palette->pen(pix) );
7063 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = add_blend_r32( bitmap_line2[x], m_palette->pen(pix) );
7064 bitmap_line[x*2+1] = add_blend_r32( bitmap_line[x*2+1], m_palette->pen(pix) );
7065 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = add_blend_r32( bitmap_line2[x], m_palette->pen(pix) );
7066 }
7067 else
7068 {
7069 bitmap_line[x] = add_blend_r32( bitmap_line[x], m_palette->pen(pix) );
7070 if ( interlace_framebuffer == 1 ) bitmap_line2[x] = add_blend_r32( bitmap_line2[x], m_palette->pen(pix) );
7071 }
7072 }
7073 else
7074 {
7075 if(double_x)
7076 {
7077 bitmap_line[x*2] = alpha_blend_r32( bitmap_line[x*2], m_palette->pen(pix), ((uint16_t)(0x1f-ccr)*0xff)/0x1f );
7078 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = alpha_blend_r32( bitmap_line2[x], m_palette->pen(pix), ((uint16_t)(0x1f-ccr)*0xff)/0x1f );
7079 bitmap_line[x*2+1] = alpha_blend_r32( bitmap_line[x*2+1], m_palette->pen(pix), ((uint16_t)(0x1f-ccr)*0xff)/0x1f );
7080 if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = alpha_blend_r32( bitmap_line2[x], m_palette->pen(pix), ((uint16_t)(0x1f-ccr)*0xff)/0x1f );
7081 }
7082 else
7083 {
7084 bitmap_line[x] = alpha_blend_r32( bitmap_line[x], m_palette->pen(pix), ((uint16_t)(0x1f-ccr)*0xff)/0x1f );
7085 if ( interlace_framebuffer == 1 ) bitmap_line2[x] = alpha_blend_r32( bitmap_line2[x], m_palette->pen(pix), ((uint16_t)(0x1f-ccr)*0xff)/0x1f );
7086 }
7087 }
7088 }
7089 }
7090 }
7091
7092 /* TODO: (1) */
7093 if ( pix & sprite_shadow )
7094 {
7095 if ( pix & ~sprite_shadow )
7096 {
7097 rgb_t p = bitmap_line[x];
7098 if(double_x)
7099 {
7100 p = bitmap_line[x*2];
7101 bitmap_line[x*2] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
7102 p = bitmap_line[x*2+1];
7103 bitmap_line[x*2+1] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
7104 }
7105 else
7106 bitmap_line[x] = rgb_t(p.r() >> 1, p.g() >> 1, p.b() >> 1);
7107 }
7108 }
7109 }
7110 }
7111 }
7112 }
7113
7114 stv_sprite_priorities_usage_valid = 1;
7115 }
7116
screen_update_stv_vdp2(screen_device & screen,bitmap_rgb32 & bitmap,const rectangle & cliprect)7117 uint32_t saturn_state::screen_update_stv_vdp2(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
7118 {
7119 stv_vdp2_fade_effects();
7120
7121 stv_vdp2_draw_back(m_tmpbitmap,cliprect);
7122
7123 if(STV_VDP2_DISP)
7124 {
7125 uint8_t pri;
7126
7127 stv_sprite_priorities_usage_valid = 0;
7128 memset(stv_sprite_priorities_used, 0, sizeof(stv_sprite_priorities_used));
7129 memset(stv_sprite_priorities_in_fb_line, 0, sizeof(stv_sprite_priorities_in_fb_line));
7130
7131 /*If a plane has a priority value of zero it isn't shown at all.*/
7132 for(pri=1;pri<8;pri++)
7133 {
7134 if(pri==STV_VDP2_N3PRIN) { stv_vdp2_draw_NBG3(m_tmpbitmap,cliprect); }
7135 if(pri==STV_VDP2_N2PRIN) { stv_vdp2_draw_NBG2(m_tmpbitmap,cliprect); }
7136 if(pri==STV_VDP2_N1PRIN) { stv_vdp2_draw_NBG1(m_tmpbitmap,cliprect); }
7137 if(pri==STV_VDP2_N0PRIN) { stv_vdp2_draw_NBG0(m_tmpbitmap,cliprect); }
7138 if(pri==STV_VDP2_R0PRIN) { stv_vdp2_draw_RBG0(m_tmpbitmap,cliprect); }
7139 { draw_sprites(m_tmpbitmap,cliprect,pri); }
7140 }
7141 }
7142
7143 copybitmap(bitmap, m_tmpbitmap, 0, 0, 0, 0, cliprect);
7144
7145 #if 0
7146 /* Do NOT remove me, used to test video code performance. */
7147 if(machine().input().code_pressed(KEYCODE_Q))
7148 {
7149 popmessage("Halt CPUs");
7150 m_maincpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
7151 m_slave->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
7152 m_audiocpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
7153 }
7154 #endif
7155 return 0;
7156 }
7157