1 /***************************************************************************
2
3 Taito F3 Video emulation - Bryan McPhail, mish@tendril.co.uk
4
5 ****************************************************************************
6
7 Brief overview:
8
9 4 scrolling layers (512x512 or 1024x512) of 4/5/6 bpp tiles.
10 1 scrolling text layer (512x512, characters generated in vram), 4bpp chars.
11 1 scrolling pixel layer (512x256 pixels generated in pivot ram), 4bpp pixels.
12 2 sprite banks (for double buffering of sprites)
13 Sprites can be 4, 5 or 6 bpp
14 Sprite scaling.
15 Rowscroll on all playfields
16 Line by line zoom on all playfields
17 Column scroll on all playfields
18 Line by line sprite and playfield priority mixing
19
20 Notes:
21 All special effects are controlled by an area in 'line ram'. Typically
22 there are 256 values, one for each line of the screen (including clipped
23 lines at the top of the screen). For example, at 0x8000 in lineram,
24 there are 4 sets of 256 values (one for each playfield) and each value
25 is the scale control for that line in the destination bitmap (screen).
26 Therefore each line can have a different zoom value for special effects.
27
28 This also applies to playfield priority, rowscroll, column scroll, sprite
29 priority and VRAM/pivot layers.
30
31 However - at the start of line ram there are also sets of 256 values
32 controlling each effect - effects can be selectively applied to individual
33 playfields or only certain lines out of the 256 can be active - in which
34 case the last allowed value can be latched (typically used so a game can
35 use one zoom or row value over the whole playfield).
36
37 The programmers of some of these games made strange use of flipscreen -
38 some games have all their graphics flipped in ROM, and use the flipscreen
39 bit to display them correctly!.
40
41 Most games display 232 scanlines, but some use lineram effects to clip
42 themselves to 224 or less.
43
44 ****************************************************************************
45
46 Line ram memory map:
47
48 Here 'playfield 1' refers to the first playfield in memory, etc
49
50 0x0000: Column line control ram (256 lines)
51 100x: Where bit 0 of x enables effect on playfield 1
52 Where bit 1 of x enables effect on playfield 2
53 Where bit 2 of x enables effect on playfield 3
54 Where bit 3 of x enables effect on playfield 4
55 0x0200: Line control ram for 0x5000 section.
56 0x0400: Line control ram for 0x6000 section.
57 (Alpha control)
58 0x0600: Sprite control ram
59 1c0x: Where x enables sprite control word for that line
60 0x0800: Zoom line control ram (256 lines)
61 200x: Where bit 0 of x enables effect on playfield 1
62 Where bit 1 of x enables effect on playfield 2
63 Where bit 2 of x enables effect on playfield 3
64 Where bit 3 of x enables effect on playfield 4
65 0x0a00: Assumed unused.
66 0x0c00: Rowscroll line control ram (256 lines)
67 280x: Where bit 0 of x enables effect on playfield 1
68 Where bit 1 of x enables effect on playfield 2
69 Where bit 2 of x enables effect on playfield 3
70 Where bit 3 of x enables effect on playfield 4
71 0x0e00: Priority line control ram (256 lines)
72 2c0x: Where bit 0 of x enables effect on playfield 1
73 Where bit 1 of x enables effect on playfield 2
74 Where bit 2 of x enables effect on playfield 3
75 Where bit 3 of x enables effect on playfield 4
76
77 0x4000: Playfield 1 column scroll (on source bitmap, not destination)
78 0x4200: Playfield 2 column scroll (on source bitmap, not destination)
79 0x4400: Playfield 3 column scroll (on source bitmap, not destination)
80 0x4600: Playfield 4 column scroll (on source bitmap, not destination)
81
82 0x5000: ?????
83
84 0x6000: Pivot layer control
85 Cupfinal a255 display, 0255 don't
86 Bubsymph a255 display 0255 don't
87 Pbobbl4u a2ff display (colour 0xa) 02ff don't
88 Landmakr 00df dont display
89 qtheater 01ff dont display
90 0x00p0 - p = priority? (See BubSymph continue screen)
91 0x6200: Alpha blending control
92 Cupfinal 3000
93 Landmakr bbbb
94 qtheater bbbb
95 bubsymph 3000
96 0x6400: Pivot layer control?
97 Cupfinal 7000
98 landmakr 7000
99 qtheater 7000
100 bubsymph 7000
101 pbobbl4u 7000
102 0x6600: Always zero?
103
104 0x7000: ?
105 0x7200: ?
106 0x7400: ?
107 0x7600: Sprite priority values
108 0xf000: Relative priority for sprites with pri value 0xc0
109 0x0f00: Relative priority for sprites with pri value 0x80
110 0x00f0: Relative priority for sprites with pri value 0x40
111 0x000f: Relative priority for sprites with pri value 0x00
112
113 0x8000: Playfield 1 scale (1 word per line, 256 lines, 0x80 = no scale)
114 0x8200: Playfield 2 scale
115 0x8400: Playfield 3 scale
116 0x8600: Playfield 4 scale
117 0x0080 = No scale
118 < 0x80 = Zoom Out
119 > 0x80 = Zoom in
120
121 0xa000: Playfield 1 rowscroll (1 word per line, 256 lines)
122 0xa200: Playfield 2 rowscroll
123 0xa400: Playfield 3 rowscroll
124 0xa600: Playfield 4 rowscroll
125
126 0xb000: Playfield 1 priority (1 word per line, 256 lines)
127 0xb200: Playfield 2 priority
128 0xb400: Playfield 3 priority
129 0xb600: Playfield 4 priority
130 0xf000 = Disable playfield (ElvAct2 second level)
131 0x8000 = Enable alpha-blending for this line
132 0x4000 = Playfield can be alpha-blended against? (Otherwise, playfield shouldn't be in blend calculation?)
133 0x2000 = Enable line? (Darius Gaiden 0x5000 = disable, 0x3000, 0xb000 & 0x7000 = display)
134 0x1000 = ?
135 0x0800 = Disable line (Used by KTiger2 to clip screen)
136 0x07f0 = ?
137 0x000f = Playfield priority
138
139 0xc000 - 0xffff: Unused.
140
141 When sprite priority==playfield priority sprite takes precedence (Bubble Symph title)
142
143 ****************************************************************************
144
145 F3 sprite format:
146
147 Word 0: 0xffff Tile number (LSB)
148 Word 1: 0xff00 X zoom
149 0x00ff Y zoom
150 Word 2: 0x03ff X position
151 Word 3: 0x03ff Y position
152 Word 4: 0xf000 Sprite block controls
153 0x0800 Sprite block start
154 0x0400 Use same colour on this sprite as block start
155 0x0200 Y flip
156 0x0100 X flip
157 0x00ff Colour
158 Word 5: 0xffff Tile number (MSB), probably only low bits used
159 Word 6: 0x8000 If set, jump to sprite location in low bits
160 0x03ff Location to jump to.
161 Word 7: 0xffff Unused? Always zero?
162
163 ****************************************************************************
164
165 Playfield control information (0x660000-1f):
166
167 Word 0- 3: X scroll values for the 4 playfields.
168 Word 4- 7: Y scroll values for the 4 playfields.
169 Word 8-11: Unused. Always zero.
170 Word 12: Pixel + VRAM playfields X scroll
171 Word 13: Pixel + VRAM playfields Y scroll
172 Word 14: Unused. Always zero.
173 Word 15: If set to 0x80, then 1024x512 playfields are used, else 512x512
174
175 ***************************************************************************/
176
177 #include "driver.h"
178 #include "vidhrdw/generic.h"
179 #include "taito_f3.h"
180 #include "state.h"
181
182 #define DARIUSG_KLUDGE
183 #define DEBUG_F3 0
184
185 static struct tilemap *pf1_tilemap,*pf2_tilemap,*pf3_tilemap,*pf4_tilemap;
186 static struct tilemap *pixel_layer;
187 static data32_t *spriteram32_buffered;
188 static int vram_dirty[256];
189 static int pivot_changed,vram_changed,scroll_kludge_y,scroll_kludge_x;
190 static data32_t f3_control_0[8];
191 static data32_t f3_control_1[8];
192 static int flipscreen;
193
194 static UINT8 *pivot_dirty;
195 static int pf23_y_kludge;
196 static struct rectangle pixel_layer_clip;
197
198 static data32_t *f3_pf_data_1,*f3_pf_data_2,*f3_pf_data_3,*f3_pf_data_4;
199
200 data32_t *f3_vram,*f3_line_ram;
201 data32_t *f3_pf_data,*f3_pivot_ram;
202
203 extern int f3_game;
204 #if DEBUG_F3
205 static int sprite_pri_word;
206 #endif /*DEBUG_F3*/
207 static int scroll_dirty,skip_this_frame;
208
209 /* Game specific data, some of this can be
210 removed when the software values are figured out */
211 struct F3config
212 {
213 int name;
214 int extend;
215 int sx;
216 int sy;
217 int pivot;
218 int sprite_lag;
219 };
220
221 const struct F3config *f3_game_config;
222
223 static const struct F3config f3_config_table[] =
224 {
225 /* Name Extend X Offset, Y Offset Flip Pivot Sprite Lag */ /* Uses 5000, uses control bits,works with line X zoom */
226 /**/{ RINGRAGE, 0, 0, -30, 0, 2 }, /*no,no,no*/
227 { ARABIANM, 0, 0, -30, 0, 2 }, /*ff00 in 5000, no,yes*/
228 /**/{ RIDINGF, 1, 0, -30, 0, 1 }, /*yes,yes,yes*/
229 { GSEEKER, 0, 1, -30, 0, 1 }, /*yes,yes,yes*/
230 { TRSTAR, 1, 0, 0, 0, 0 }, /**/
231 { GUNLOCK, 1, 1, -30, 0, 2 }, /*yes,yes,partial*/
232 /**/{ TWINQIX, 1, 0, -30, 1, 1 },
233 { SCFINALS, 0, 0, -30, 1, 1/**/},
234 { LIGHTBR, 1, 0, -30, 0, 2 }, /*yes,?,no*/
235 { KAISERKN, 0, 0, -30, 1, 2 },
236 { DARIUSG, 0, 0, -23, 0, 2 },
237 { BUBSYMPH, 1, 0, -30, 0, 1/**/}, /*yes,yes,?*/
238 { SPCINVDX, 1, 0, -30, 1, 1/**/}, /*yes,yes,?*/
239 { QTHEATER, 1, 0, 0, 0, 1/**/},
240 { HTHERO95, 0, 0, -30, 1, 1/**/},
241 { SPCINV95, 0, 0, -30, 0, 1/**/},
242 { EACTION2, 1, 0, -23, 0, 2 }, /*no,yes,?*/
243 { QUIZHUHU, 1, 0, -23, 0, 1/**/},
244 { PBOBBLE2, 0, 0, 0, 1, 1/**/}, /*no,no,?*/
245 { GEKIRIDO, 0, 0, -23, 0, 1 },
246 { KTIGER2, 0, 0, -23, 0, 0 },/*no,yes,partial*/
247 { BUBBLEM, 1, 0, -30, 0, 1/**/},
248 { CLEOPATR, 0, 0, -30, 0, 1/**/},
249 { PBOBBLE3, 0, 0, 0, 0, 1/**/},
250 { ARKRETRN, 1, 0, -23, 0, 1/**/},
251 { KIRAMEKI, 0, 0, -30, 0, 1/**/},
252 { PUCHICAR, 1, 0, -23, 0, 1/**/},
253 { PBOBBLE4, 0, 0, 0, 1, 1/**/},
254 { POPNPOP, 1, 0, -23, 0, 1/**/},
255 { LANDMAKR, 1, 0, -23, 0, 1/**/},
256 {0}
257 };
258
259
260 struct tempsprite
261 {
262 int code,color;
263 int flipx,flipy;
264 int x,y;
265 int zoomx,zoomy;
266 int pri;
267 };
268 static struct tempsprite *spritelist;
269
270 static int alpha_disable=0;
271 #if DEBUG_F3
272 static char deb_buf[10][80];
273 static int deb_enable=0;
274 static int deb_tileflag=0;
275 static int deb_tile_code=0;
276 #endif /*DEBUG_F3*/
277
278 static const struct tempsprite *sprite_end;
279 static void get_sprite_info(const data32_t *spriteram32_ptr);
280 static int sprite_lag=1;
281 static UINT8 sprite_pri_usage=0;
282
283 struct f3_line_inf
284 {
285 int alpha_mode[256];
286 int alpha_level[256];
287 int pri[256];
288 int spri[256];
289 UINT16 sprite_alpha[256];
290
291 /* use for draw_scanlines */
292 UINT16 *src[256],*src_s[256],*src_e[256];
293 UINT8 *tsrc[256],*tsrc_s[256];
294 int x_count[256];
295 UINT32 x_zoom[256];
296 };
297 /*
298 alpha_mode
299 ---- --xx 0:disable 1:nomal 2:alpha 7000 3:alpha b000
300 ---1 ---- alpha level a
301 --1- ---- alpha level b
302 1-------- opaque line
303 */
304
305 static struct f3_line_inf *line_inf;
306 static struct mame_bitmap *pri_alp_bitmap;
307 /*
308 pri_alp_bitmap
309 ---- ---1 sprite priority 0
310 ---- --1- sprite priority 1
311 ---- -1-- sprite priority 2
312 ---- 1--- sprite priority 3
313 ---1 ---- alpha level a 7000
314 --1- ---- alpha level b 7000
315 -1-- ---- alpha level a b000
316 1--- ---- alpha level b b000
317 1111 1111 opaque pixcel
318 */
319 static int f3_alpha_level_2as=127;
320 static int f3_alpha_level_2ad=127;
321 static int f3_alpha_level_3as=127;
322 static int f3_alpha_level_3ad=127;
323 static int f3_alpha_level_2bs=127;
324 static int f3_alpha_level_2bd=127;
325 static int f3_alpha_level_3bs=127;
326 static int f3_alpha_level_3bd=127;
327
328 static void init_alpha_blend_func(void);
329
330 static int width_mask=0x1ff;
331 static int twidth_mask=0x1f,twidth_mask_bit=5;
332 static UINT8 *tile_opaque_sp;
333 static UINT8 *tile_opaque_pf;
334
335
336 /******************************************************************************/
337
338 #if DEBUG_F3
print_debug_info(int t0,int t1,int t2,int t3,int c0,int c1,int c2,int c3)339 static void print_debug_info(int t0, int t1, int t2, int t3, int c0, int c1, int c2, int c3)
340 {
341 struct mame_bitmap *bitmap = Machine->scrbitmap;
342 int j,trueorientation,l[16];
343 char buf[64];
344
345 trueorientation = Machine->orientation;
346 Machine->orientation = ROT0;
347
348 sprintf(buf,"%04X %04X %04X %04X",f3_control_0[0]>>22,(f3_control_0[0]&0xffff)>>6,f3_control_0[1]>>22,(f3_control_0[1]&0xffff)>>6);
349 for (j = 0;j< 16+3;j++)
350 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,40,0,TRANSPARENCY_NONE,0);
351 sprintf(buf,"%04X %04X %04X %04X",f3_control_0[2]>>23,(f3_control_0[2]&0xffff)>>7,f3_control_0[3]>>23,(f3_control_0[3]&0xffff)>>7);
352 for (j = 0;j< 16+3;j++)
353 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,48,0,TRANSPARENCY_NONE,0);
354 sprintf(buf,"%04X %04X %04X %04X",f3_control_1[0]>>16,f3_control_1[0]&0xffff,f3_control_1[1]>>16,f3_control_1[1]&0xffff);
355 for (j = 0;j< 16+3;j++)
356 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,58,0,TRANSPARENCY_NONE,0);
357 sprintf(buf,"%04X %04X %04X %04X",f3_control_1[2]>>16,f3_control_1[2]&0xffff,f3_control_1[3]>>16,f3_control_1[3]&0xffff);
358 for (j = 0;j< 16+3;j++)
359 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,66,0,TRANSPARENCY_NONE,0);
360
361 sprintf(buf,"%04X %04X %04X %04X %04X %04X %04X %04X",spriteram32_buffered[0]>>16,spriteram32_buffered[0]&0xffff,spriteram32_buffered[1]>>16,spriteram32_buffered[1]&0xffff,spriteram32_buffered[2]>>16,spriteram32_buffered[2]&0xffff,spriteram32_buffered[3]>>16,spriteram32_buffered[3]&0xffff);
362 for (j = 0;j< 32+7;j++)
363 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,76,0,TRANSPARENCY_NONE,0);
364 sprintf(buf,"%04X %04X %04X %04X %04X %04X %04X %04X",spriteram32_buffered[4]>>16,spriteram32_buffered[4]&0xffff,spriteram32_buffered[5]>>16,spriteram32_buffered[5]&0xffff,spriteram32_buffered[6]>>16,spriteram32_buffered[6]&0xffff,spriteram32_buffered[7]>>16,spriteram32_buffered[7]&0xffff);
365 for (j = 0;j< 32+7;j++)
366 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,84,0,TRANSPARENCY_NONE,0);
367 sprintf(buf,"%04X %04X %04X %04X %04X %04X %04X %04X",spriteram32_buffered[8]>>16,spriteram32_buffered[8]&0xffff,spriteram32_buffered[9]>>16,spriteram32_buffered[9]&0xffff,spriteram32_buffered[10]>>16,spriteram32_buffered[10]&0xffff,spriteram32_buffered[11]>>16,spriteram32_buffered[11]&0xffff);
368 for (j = 0;j< 32+7;j++)
369 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,92,0,TRANSPARENCY_NONE,0);
370
371 l[0]=f3_line_ram[0x0040]&0xffff;
372 l[1]=f3_line_ram[0x00c0]&0xffff;
373 l[2]=f3_line_ram[0x0140]&0xffff;
374 l[3]=f3_line_ram[0x01c0]&0xffff;
375 sprintf(buf,"Ctr1: %04x %04x %04x %04x",l[0],l[1],l[2],l[3]);
376 for (j = 0;j < 16+9; j++)
377 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*13,0,TRANSPARENCY_NONE,0);
378
379 l[0]=f3_line_ram[0x0240]&0xffff;
380 l[1]=f3_line_ram[0x02c0]&0xffff;
381 l[2]=f3_line_ram[0x0340]&0xffff;
382 l[3]=f3_line_ram[0x03c0]&0xffff;
383 sprintf(buf,"Ctr2: %04x %04x %04x %04x",l[0],l[1],l[2],l[3]);
384 for (j = 0;j < 16+9; j++)
385 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*14,0,TRANSPARENCY_NONE,0);
386
387 l[0]=f3_line_ram[0x2c60]&0xffff;
388 l[1]=f3_line_ram[0x2ce0]&0xffff;
389 l[2]=f3_line_ram[0x2d60]&0xffff;
390 l[3]=f3_line_ram[0x2de0]&0xffff;
391 sprintf(buf,"Pri : %04x %04x %04x %04x",l[0],l[1],l[2],l[3]);
392 for (j = 0;j < 16+9; j++)
393 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*15,0,TRANSPARENCY_NONE,0);
394
395 l[0]=f3_line_ram[0x2060]&0xffff;
396 l[1]=f3_line_ram[0x20e0]&0xffff;
397 l[2]=f3_line_ram[0x2160]&0xffff;
398 l[3]=f3_line_ram[0x21e0]&0xffff;
399 sprintf(buf,"Zoom: %04x %04x %04x %04x",l[0],l[1],l[2],l[3]);
400 for (j = 0;j < 16+9; j++)
401 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*16,0,TRANSPARENCY_NONE,0);
402
403 l[0]=f3_line_ram[0x2860]&0xffff;
404 l[1]=f3_line_ram[0x28e0]&0xffff;
405 l[2]=f3_line_ram[0x2960]&0xffff;
406 l[3]=f3_line_ram[0x29e0]&0xffff;
407 sprintf(buf,"Line: %04x %04x %04x %04x",l[0],l[1],l[2],l[3]);
408 for (j = 0;j < 16+9; j++)
409 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*17,0,TRANSPARENCY_NONE,0);
410
411 l[0]=f3_line_ram[0x1c60]&0xffff;
412 l[1]=f3_line_ram[0x1ce0]&0xffff;
413 l[2]=f3_line_ram[0x1d60]&0xffff;
414 l[3]=f3_line_ram[0x1de0]&0xffff;
415 sprintf(buf,"Sprt: %04x %04x %04x %04x",l[0],l[1],l[2],l[3]);
416 for (j = 0;j < 16+9; j++)
417 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*18,0,TRANSPARENCY_NONE,0);
418
419 l[0]=f3_line_ram[0x1860]&0xffff;
420 l[1]=f3_line_ram[0x18e0]&0xffff;
421 l[2]=f3_line_ram[0x1960]&0xffff;
422 l[3]=f3_line_ram[0x19e0]&0xffff;
423 sprintf(buf,"Pivt: %04x %04x %04x %04x",l[0],l[1],l[2],l[3]);
424 for (j = 0;j < 16+9; j++)
425 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*19,0,TRANSPARENCY_NONE,0);
426
427 l[0]=f3_line_ram[0x1060]&0xffff;
428 l[1]=f3_line_ram[0x10e0]&0xffff;
429 l[2]=f3_line_ram[0x1160]&0xffff;
430 l[3]=f3_line_ram[0x11e0]&0xffff;
431 sprintf(buf,"Colm: %04x %04x %04x %04x",l[0],l[1],l[2],l[3]);
432 for (j = 0;j < 16+9; j++)
433 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*20,0,TRANSPARENCY_NONE,0);
434
435 l[0]=f3_line_ram[0x1460]&0xffff;
436 l[1]=f3_line_ram[0x14e0]&0xffff;
437 l[2]=f3_line_ram[0x1560]&0xffff;
438 l[3]=f3_line_ram[0x15e0]&0xffff;
439 sprintf(buf,"5000: %04x %04x %04x %04x",l[0],l[1],l[2],l[3]);
440 for (j = 0;j < 16+9; j++)
441 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*21,0,TRANSPARENCY_NONE,0);
442
443 sprintf(buf,"SPri: %04x",sprite_pri_word);
444 for (j = 0;j < 10; j++)
445 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*23,0,TRANSPARENCY_NONE,0);
446 sprintf(buf,"TPri: %04x %04x %04x %04x",t0,t1,t2,t3);
447 for (j = 0;j < 16+9; j++)
448 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*24,0,TRANSPARENCY_NONE,0);
449 sprintf(buf,"Cstm: %04x %04x %04x %04x",c0,c1,c2,c3);
450 for (j = 0;j < 16+9; j++)
451 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*25,0,TRANSPARENCY_NONE,0);
452 sprintf(buf,"6000: %08x %08x %08x",f3_line_ram[0x1800],f3_line_ram[0x1890],f3_line_ram[0x1910]);
453 for (j = 0;j < 16+9; j++)
454 drawgfx(bitmap,Machine->uifont,buf[j],0,0,0,60+6*j,8*27,0,TRANSPARENCY_NONE,0);
455
456 Machine->orientation = trueorientation;
457 }
458 #endif /*DEBUG_F3*/
459
460 /******************************************************************************/
461
get_tile_info(int tile_index,data32_t * gfx_base)462 static INLINE void get_tile_info(int tile_index, data32_t *gfx_base)
463 {
464 data32_t tile=gfx_base[tile_index];
465 UINT8 abtype=(tile>>(16+9))&0x1f;
466
467 #if DEBUG_F3
468 /*if((tile&0xffff)>Machine->gfx[1]->total_elements) log_cb(RETRO_LOG_DEBUG, LOGPRE "tile code:%04x\n",tile&0xffff);*/
469 if(deb_tileflag)
470 {
471 int c=tile&0xffff;
472 if(abtype==deb_tile_code) c=0;
473
474 SET_TILE_INFO(
475 1,
476 c,
477 (tile>>16)&0x1ff,
478 TILE_FLIPYX( tile >> 30 ))
479 tile_info.priority = abtype&1; /* alpha blending type? */
480 }
481 else
482 #endif /*DEBUG_F3*/
483 {
484 SET_TILE_INFO(
485 1,
486 tile&0xffff,
487 (tile>>16)&0x1ff,
488 TILE_FLIPYX( tile >> 30 ))
489 tile_info.priority = abtype&1; /* alpha blending type? */
490 }
491 }
492
get_tile_info1(int tile_index)493 static void get_tile_info1(int tile_index)
494 {
495 get_tile_info(tile_index,f3_pf_data_1);
496 }
497
get_tile_info2(int tile_index)498 static void get_tile_info2(int tile_index)
499 {
500 get_tile_info(tile_index,f3_pf_data_2);
501 }
502
get_tile_info3(int tile_index)503 static void get_tile_info3(int tile_index)
504 {
505 get_tile_info(tile_index,f3_pf_data_3);
506 }
507
get_tile_info4(int tile_index)508 static void get_tile_info4(int tile_index)
509 {
510 get_tile_info(tile_index,f3_pf_data_4);
511 }
512
get_tile_info_pixel(int tile_index)513 static void get_tile_info_pixel(int tile_index)
514 {
515 int color,col_off;
516 int y_offs=(f3_control_1[2]&0x1ff)+scroll_kludge_y;
517
518 if (flipscreen) y_offs+=0x100;
519
520 /* Colour is shared with VRAM layer */
521 if ((((tile_index%32)*8 + y_offs)&0x1ff)>0xff)
522 col_off=0x800+((tile_index%32)*0x40)+((tile_index&0xfe0)>>5);
523 else
524 col_off=((tile_index%32)*0x40)+((tile_index&0xfe0)>>5);
525
526 if (col_off&1)
527 color = ((videoram32[col_off>>1]&0xffff)>>9)&0x3f;
528 else
529 color = ((videoram32[col_off>>1]>>16)>>9)&0x3f;
530
531 SET_TILE_INFO(
532 3,
533 tile_index,
534 color&0x3f,
535 0)
536 tile_info.flags = f3_game_config->pivot ? TILE_FLIPX : 0;
537 }
538
539 /******************************************************************************/
540
VIDEO_EOF(f3)541 VIDEO_EOF( f3 )
542 {
543 if (sprite_lag==2)
544 {
545 if (osd_skip_this_frame() == 0)
546 {
547 get_sprite_info(spriteram32_buffered);
548 }
549 memcpy(spriteram32_buffered,spriteram32,spriteram_size);
550 }
551 else if (sprite_lag==1)
552 {
553 if (osd_skip_this_frame() == 0)
554 {
555 get_sprite_info(spriteram32);
556 }
557 }
558 }
559
VIDEO_STOP(f3)560 VIDEO_STOP( f3 )
561 {
562 #if DEBUG_F3
563 #define FWRITE32(pRAM,len,file) \
564 { \
565 int i; \
566 for(i=0;i<len;i++) \
567 { \
568 unsigned char c; \
569 UINT32 d=*pRAM; \
570 c=(d&0xff000000)>>24; \
571 fwrite(&c,1, 1 ,file); \
572 d<<=8; \
573 c=(d&0xff000000)>>24; \
574 fwrite(&c,1, 1 ,file); \
575 d<<=8; \
576 c=(d&0xff000000)>>24; \
577 fwrite(&c,1, 1 ,file); \
578 d<<=8; \
579 c=(d&0xff000000)>>24; \
580 fwrite(&c,1, 1 ,file); \
581 pRAM++; \
582 } \
583 }
584
585 if (deb_enable) {
586 FILE *fp;
587
588 fp=fopen("line.dmp","wb");
589 if (fp) {
590 FWRITE32(f3_line_ram,0x10000/4,fp);
591 fclose(fp);
592 }
593 fp=fopen("sprite.dmp","wb");
594 if (fp) {
595 FWRITE32(spriteram32,0x10000/4,fp);
596 fclose(fp);
597 }
598 fp=fopen("vram.dmp","wb");
599 if (fp) {
600 FWRITE32(f3_pf_data,0xc000/4,fp);
601 fclose(fp);
602 }
603 }
604 #undef FWRITE32
605 #endif /*DEBUG_F3*/
606 }
607
VIDEO_START(f3)608 VIDEO_START( f3 )
609 {
610 const struct F3config *pCFG=&f3_config_table[0];
611 int tile;
612
613 spritelist=0;
614 spriteram32_buffered=0;
615 pivot_dirty=0;
616 pixel_layer_clip=Machine->visible_area;
617 line_inf=0;
618 pri_alp_bitmap=0;
619 tile_opaque_sp=0;
620 tile_opaque_pf=0;
621
622 /* Setup individual game */
623 do {
624 if (pCFG->name==f3_game)
625 {
626 break;
627 }
628 pCFG++;
629 } while(pCFG->name);
630
631 f3_game_config=pCFG;
632
633 if (f3_game_config->extend) {
634 pf1_tilemap = tilemap_create(get_tile_info1,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,64,32);
635 pf2_tilemap = tilemap_create(get_tile_info2,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,64,32);
636 pf3_tilemap = tilemap_create(get_tile_info3,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,64,32);
637 pf4_tilemap = tilemap_create(get_tile_info4,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,64,32);
638
639 f3_pf_data_1=f3_pf_data+0x0000;
640 f3_pf_data_2=f3_pf_data+0x0800;
641 f3_pf_data_3=f3_pf_data+0x1000;
642 f3_pf_data_4=f3_pf_data+0x1800;
643
644 width_mask=0x3ff;
645 twidth_mask=0x3f;
646 twidth_mask_bit=6;
647
648 } else {
649 pf1_tilemap = tilemap_create(get_tile_info1,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
650 pf2_tilemap = tilemap_create(get_tile_info2,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
651 pf3_tilemap = tilemap_create(get_tile_info3,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
652 pf4_tilemap = tilemap_create(get_tile_info4,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
653
654 f3_pf_data_1=f3_pf_data+0x0000;
655 f3_pf_data_2=f3_pf_data+0x0400;
656 f3_pf_data_3=f3_pf_data+0x0800;
657 f3_pf_data_4=f3_pf_data+0x0c00;
658
659 width_mask=0x1ff;
660 twidth_mask=0x1f;
661 twidth_mask_bit=5;
662 }
663
664 spriteram32_buffered = (UINT32 *)auto_malloc(0x10000);
665 spritelist = auto_malloc(0x400 * sizeof(*spritelist));
666 sprite_end = spritelist;
667 pixel_layer = tilemap_create(get_tile_info_pixel,tilemap_scan_cols,TILEMAP_TRANSPARENT,8,8,64,32);
668 pivot_dirty = (UINT8 *)auto_malloc(2048);
669 line_inf = auto_malloc(4 * sizeof(struct f3_line_inf));
670 pri_alp_bitmap = auto_bitmap_alloc_depth( Machine->scrbitmap->width, Machine->scrbitmap->height, -8 );
671 tile_opaque_sp = (UINT8 *)auto_malloc(Machine->gfx[2]->total_elements);
672 tile_opaque_pf = (UINT8 *)auto_malloc(Machine->gfx[1]->total_elements);
673
674 if (!pf1_tilemap || !pf2_tilemap || !pf3_tilemap || !pf4_tilemap || !line_inf || !pri_alp_bitmap
675 || !spritelist || !pixel_layer || !spriteram32_buffered || !pivot_dirty || !tile_opaque_sp || !tile_opaque_pf)
676 return 1;
677
678 tilemap_set_transparent_pen(pf1_tilemap,0);
679 tilemap_set_transparent_pen(pf2_tilemap,0);
680 tilemap_set_transparent_pen(pf3_tilemap,0);
681 tilemap_set_transparent_pen(pf4_tilemap,0);
682 tilemap_set_transparent_pen(pixel_layer,0);
683
684 tilemap_set_scroll_rows(pf1_tilemap,512);
685 tilemap_set_scroll_rows(pf2_tilemap,512);
686 tilemap_set_scroll_rows(pf3_tilemap,512);
687 tilemap_set_scroll_rows(pf4_tilemap,512);
688
689 /* Y Offset is related to the first visible line in line ram in some way */
690 scroll_kludge_y=f3_game_config->sy;
691 scroll_kludge_x=f3_game_config->sx;
692
693 /* Palettes have 4 bpp indexes despite up to 6 bpp data */
694 Machine->gfx[1]->color_granularity=16;
695 Machine->gfx[2]->color_granularity=16;
696
697 flipscreen = 0;
698 memset(spriteram32_buffered,0,spriteram_size);
699 memset(spriteram32,0,spriteram_size);
700
701 state_save_register_UINT32("f3", 0, "vcontrol0", f3_control_0, 8);
702 state_save_register_UINT32("f3", 0, "vcontrol1", f3_control_1, 8);
703
704 /* Why?!?? These games have different offsets for the two middle playfields only */
705 if (f3_game==LANDMAKR || f3_game==EACTION2 || f3_game==DARIUSG || f3_game==GEKIRIDO)
706 pf23_y_kludge=23;
707 else
708 pf23_y_kludge=0;
709
710 for (tile = 0;tile < 256;tile++)
711 vram_dirty[tile]=1;
712 for (tile = 0;tile < 2048;tile++)
713 pivot_dirty[tile]=1;
714
715 scroll_dirty=1;
716 skip_this_frame=0;
717
718 sprite_lag=f3_game_config->sprite_lag;
719
720 init_alpha_blend_func();
721
722 {
723 const struct GfxElement *sprite_gfx = Machine->gfx[2];
724 int c;
725 #if DEBUG_F3
726 int deb_count_opa=0,deb_count_tra=0,deb_tra_code=-1;
727 #endif /*DEBUG_F3*/
728
729 for (c = 0;c < sprite_gfx->total_elements;c++)
730 {
731 int x,y;
732 int chk_trans_or_opa=0;
733 UINT8 *dp = sprite_gfx->gfxdata + c * sprite_gfx->char_modulo;
734 for (y = 0;y < sprite_gfx->height;y++)
735 {
736 for (x = 0;x < sprite_gfx->width;x++)
737 {
738 if(!dp[x]) chk_trans_or_opa|=2;
739 else chk_trans_or_opa|=1;
740 }
741 dp += sprite_gfx->line_modulo;
742 }
743 if(chk_trans_or_opa==1) tile_opaque_sp[c]=1;
744 else tile_opaque_sp[c]=0;
745 #if DEBUG_F3
746 if (chk_trans_or_opa==2){deb_count_tra++;deb_tra_code=c;}
747 else if(chk_trans_or_opa==1) deb_count_opa++;
748 #endif /*DEBUG_F3*/
749 }
750 #if DEBUG_F3
751 printf("tile_opaque_sp: t=%d o=%d total=%d tra_code=%d\n",deb_count_tra,deb_count_opa,
752 sprite_gfx->total_elements,deb_tra_code);
753 #endif /*DEBUG_F3*/
754 }
755
756
757 {
758 const struct GfxElement *pf_gfx = Machine->gfx[1];
759 int c;
760 #if DEBUG_F3
761 int deb_count_opa=0,deb_count_tra=0,deb_tra_code=-1;
762 #endif /*DEBUG_F3*/
763
764 for (c = 0;c < pf_gfx->total_elements;c++)
765 {
766 int x,y;
767 int chk_trans_or_opa=0;
768 UINT8 *dp = pf_gfx->gfxdata + c * pf_gfx->char_modulo;
769 for (y = 0;y < pf_gfx->height;y++)
770 {
771 for (x = 0;x < pf_gfx->width;x++)
772 {
773 if(!dp[x]) chk_trans_or_opa|=2;
774 else chk_trans_or_opa|=1;
775 }
776 dp += pf_gfx->line_modulo;
777 }
778 tile_opaque_pf[c]=chk_trans_or_opa;
779 #if DEBUG_F3
780 if (chk_trans_or_opa==2){deb_count_tra++;deb_tra_code=c;}
781 else if(chk_trans_or_opa==1) deb_count_opa++;
782 #endif /*DEBUG_F3*/
783 }
784 #if DEBUG_F3
785 printf("tile_opaque_pf: t=%d o=%d total=%d tra_code=%d\n",deb_count_tra,deb_count_opa,
786 pf_gfx->total_elements,deb_tra_code);
787 #endif /*DEBUG_F3*/
788 }
789
790 return 0;
791 }
792
793 /******************************************************************************/
794
WRITE32_HANDLER(f3_pf_data_w)795 WRITE32_HANDLER( f3_pf_data_w )
796 {
797 COMBINE_DATA(&f3_pf_data[offset]);
798
799 if (f3_game_config->extend) {
800 if (offset<0x800) tilemap_mark_tile_dirty(pf1_tilemap,offset-0x0000);
801 else if (offset<0x1000) tilemap_mark_tile_dirty(pf2_tilemap,offset-0x0800);
802 else if (offset<0x1800) tilemap_mark_tile_dirty(pf3_tilemap,offset-0x1000);
803 else if (offset<0x2000) tilemap_mark_tile_dirty(pf4_tilemap,offset-0x1800);
804 } else {
805 if (offset<0x400) tilemap_mark_tile_dirty(pf1_tilemap,offset-0x0000);
806 else if (offset<0x800) tilemap_mark_tile_dirty(pf2_tilemap,offset-0x0400);
807 else if (offset<0xc00) tilemap_mark_tile_dirty(pf3_tilemap,offset-0x0800);
808 else if (offset<0x1000) tilemap_mark_tile_dirty(pf4_tilemap,offset-0xc00);
809 }
810 }
811
WRITE32_HANDLER(f3_control_0_w)812 WRITE32_HANDLER( f3_control_0_w )
813 {
814 COMBINE_DATA(&f3_control_0[offset]);
815 }
816
WRITE32_HANDLER(f3_control_1_w)817 WRITE32_HANDLER( f3_control_1_w )
818 {
819 COMBINE_DATA(&f3_control_1[offset]);
820 }
821
WRITE32_HANDLER(f3_videoram_w)822 WRITE32_HANDLER( f3_videoram_w )
823 {
824 int tile,col_off;
825 COMBINE_DATA(&videoram32[offset]);
826
827 if (offset>0x3ff) offset-=0x400;
828
829 tile=offset<<1;
830 col_off=((tile&0x3f)*32)+((tile&0xfc0)>>6);
831
832 tilemap_mark_tile_dirty(pixel_layer,col_off);
833 tilemap_mark_tile_dirty(pixel_layer,col_off+32);
834 }
835
WRITE32_HANDLER(f3_vram_w)836 WRITE32_HANDLER( f3_vram_w )
837 {
838 COMBINE_DATA(&f3_vram[offset]);
839 vram_dirty[offset/8]=1;
840 vram_changed=1;
841 }
842
WRITE32_HANDLER(f3_pivot_w)843 WRITE32_HANDLER( f3_pivot_w )
844 {
845 COMBINE_DATA(&f3_pivot_ram[offset]);
846 pivot_dirty[offset/8]=1;
847 pivot_changed=1;
848 }
849
WRITE32_HANDLER(f3_lineram_w)850 WRITE32_HANDLER( f3_lineram_w )
851 {
852 /* DariusGX has an interesting bug at the start of Round D - the clearing of lineram
853 (0xa000->0x0xa7ff) overflows into priority RAM (0xb000) and creates garbage priority
854 values. I'm not sure what the real machine would do with these values, and this
855 emulation certainly doesn't like it, so I've chosen to catch the bug here, and prevent
856 the trashing of priority ram. If anyone has information on what the real machine does,
857 please let me know! */
858 if (f3_game==DARIUSG) {
859 if (skip_this_frame)
860 return;
861 if (offset==0xb000/4 && data==0x003f0000) {
862 skip_this_frame=1;
863 return;
864 }
865 }
866
867 COMBINE_DATA(&f3_line_ram[offset]);
868
869 /* if ((offset&0xfe00)==0x2800)*/
870 /* scroll_dirty=1;*/
871
872 /* if (offset>=0x6000/4 && offset<0x7000/4)*/
873 /* if (offset==0x18c0)*/
874 /* log_cb(RETRO_LOG_DEBUG, LOGPRE "%08x: Write 6000 %08x, %08x\n",activecpu_get_pc(),offset,data);*/
875 /* if (offset>=0xa000/4 && offset<0xb000/4)*/
876 /* log_cb(RETRO_LOG_DEBUG, LOGPRE "%08x: Write a000 %08x, %08x\n",activecpu_get_pc(),offset,data);*/
877 /* if (offset>=0xb000/4 && offset<0xc000/4)*/
878 /* log_cb(RETRO_LOG_DEBUG, LOGPRE "%08x: Write b000 %08x, %08x\n",activecpu_get_pc(),offset,data);*/
879
880 }
881
WRITE32_HANDLER(f3_palette_24bit_w)882 WRITE32_HANDLER( f3_palette_24bit_w )
883 {
884 int r,g,b;
885
886 COMBINE_DATA(&paletteram32[offset]);
887
888 /* 12 bit palette games - there has to be a palette select bit somewhere */
889 if (f3_game==SPCINVDX || f3_game==RIDINGF || f3_game==ARABIANM || f3_game==RINGRAGE) {
890 b = 15 * ((paletteram32[offset] >> 4) & 0xf);
891 g = 15 * ((paletteram32[offset] >> 8) & 0xf);
892 r = 15 * ((paletteram32[offset] >> 12) & 0xf);
893 }
894
895 /* This is weird - why are only the sprites and VRAM palettes 21 bit? */
896 else if (f3_game==CLEOPATR) {
897 if (offset<0x100 || offset>0x1000) {
898 r = ((paletteram32[offset] >>16) & 0x7f)<<1;
899 g = ((paletteram32[offset] >> 8) & 0x7f)<<1;
900 b = ((paletteram32[offset] >> 0) & 0x7f)<<1;
901 } else {
902 r = (paletteram32[offset] >>16) & 0xff;
903 g = (paletteram32[offset] >> 8) & 0xff;
904 b = (paletteram32[offset] >> 0) & 0xff;
905 }
906 }
907
908 /* Another weird one */
909 else if (f3_game==TWINQIX) {
910 if (offset>0x1c00) {
911 r = ((paletteram32[offset] >>16) & 0x7f)<<1;
912 g = ((paletteram32[offset] >> 8) & 0x7f)<<1;
913 b = ((paletteram32[offset] >> 0) & 0x7f)<<1;
914 } else {
915 r = (paletteram32[offset] >>16) & 0xff;
916 g = (paletteram32[offset] >> 8) & 0xff;
917 b = (paletteram32[offset] >> 0) & 0xff;
918 }
919 }
920
921 /* All other games - standard 24 bit palette */
922 else {
923 r = (paletteram32[offset] >>16) & 0xff;
924 g = (paletteram32[offset] >> 8) & 0xff;
925 b = (paletteram32[offset] >> 0) & 0xff;
926 }
927
928 palette_set_color(offset,r,g,b);
929 }
930
931 /******************************************************************************/
932
933 #if DEBUG_F3
934 static int deb_alpha_level_a=0;
935 static int deb_alpha_level_b=0;
936 static int deb_alp_mode=0;
937 static int deb_loop=0;
938 static int deb_alpha_cnt=0;
939 #endif /*DEBUG_F3*/
940
941 static UINT8 add_sat[256][256];
942
943 static const UINT8 *alpha_s_1_1;
944 static const UINT8 *alpha_s_1_2;
945 static const UINT8 *alpha_s_1_4;
946 static const UINT8 *alpha_s_1_5;
947 static const UINT8 *alpha_s_1_6;
948 static const UINT8 *alpha_s_1_8;
949 static const UINT8 *alpha_s_1_9;
950 static const UINT8 *alpha_s_1_a;
951
952 static const UINT8 *alpha_s_2a_0;
953 static const UINT8 *alpha_s_2a_4;
954 static const UINT8 *alpha_s_2a_8;
955
956 static const UINT8 *alpha_s_2b_0;
957 static const UINT8 *alpha_s_2b_4;
958 static const UINT8 *alpha_s_2b_8;
959
960 static const UINT8 *alpha_s_3a_0;
961 static const UINT8 *alpha_s_3a_1;
962 static const UINT8 *alpha_s_3a_2;
963
964 static const UINT8 *alpha_s_3b_0;
965 static const UINT8 *alpha_s_3b_1;
966 static const UINT8 *alpha_s_3b_2;
967
968 static UINT32 dval;
969 static UINT8 pval;
970 static UINT8 tval;
971 static UINT8 pdest_2a = 0x10;
972 static UINT8 pdest_2b = 0x20;
973 static int tr_2a = 0;
974 static int tr_2b = 1;
975 static UINT8 pdest_3a = 0x40;
976 static UINT8 pdest_3b = 0x80;
977 static int tr_3a = 0;
978 static int tr_3b = 1;
979
980 static int (*dpix_n[8][16])(UINT32 s_pix);
981 static int (**dpix_lp[4])(UINT32 s_pix);
982 static int (**dpix_sp[9])(UINT32 s_pix);
983
984 /*============================================================================*/
985
986 #define SET_ALPHA_LEVEL(d,s) \
987 { \
988 int level = s; \
989 if(level == 0) level = -1; \
990 d = alpha_cache.alpha[level+1]; \
991 }
992
f3_alpha_set_level(void)993 static INLINE void f3_alpha_set_level(void)
994 {
995 /* SET_ALPHA_LEVEL(alpha_s_1_1, f3_alpha_level_2ad)*/
996 SET_ALPHA_LEVEL(alpha_s_1_1, 255-f3_alpha_level_2as)
997 /* SET_ALPHA_LEVEL(alpha_s_1_2, f3_alpha_level_2bd)*/
998 SET_ALPHA_LEVEL(alpha_s_1_2, 255-f3_alpha_level_2bs)
999 SET_ALPHA_LEVEL(alpha_s_1_4, f3_alpha_level_3ad)
1000 /* SET_ALPHA_LEVEL(alpha_s_1_5, f3_alpha_level_3ad*f3_alpha_level_2ad/255)*/
1001 SET_ALPHA_LEVEL(alpha_s_1_5, f3_alpha_level_3ad*(255-f3_alpha_level_2as)/255)
1002 /* SET_ALPHA_LEVEL(alpha_s_1_6, f3_alpha_level_3ad*f3_alpha_level_2bd/255)*/
1003 SET_ALPHA_LEVEL(alpha_s_1_6, f3_alpha_level_3ad*(255-f3_alpha_level_2bs)/255)
1004 SET_ALPHA_LEVEL(alpha_s_1_8, f3_alpha_level_3bd)
1005 /* SET_ALPHA_LEVEL(alpha_s_1_9, f3_alpha_level_3bd*f3_alpha_level_2ad/255)*/
1006 SET_ALPHA_LEVEL(alpha_s_1_9, f3_alpha_level_3bd*(255-f3_alpha_level_2as)/255)
1007 /* SET_ALPHA_LEVEL(alpha_s_1_a, f3_alpha_level_3bd*f3_alpha_level_2bd/255)*/
1008 SET_ALPHA_LEVEL(alpha_s_1_a, f3_alpha_level_3bd*(255-f3_alpha_level_2bs)/255)
1009
1010 SET_ALPHA_LEVEL(alpha_s_2a_0, f3_alpha_level_2as)
1011 SET_ALPHA_LEVEL(alpha_s_2a_4, f3_alpha_level_2as*f3_alpha_level_3ad/255)
1012 SET_ALPHA_LEVEL(alpha_s_2a_8, f3_alpha_level_2as*f3_alpha_level_3bd/255)
1013
1014 SET_ALPHA_LEVEL(alpha_s_2b_0, f3_alpha_level_2bs)
1015 SET_ALPHA_LEVEL(alpha_s_2b_4, f3_alpha_level_2bs*f3_alpha_level_3ad/255)
1016 SET_ALPHA_LEVEL(alpha_s_2b_8, f3_alpha_level_2bs*f3_alpha_level_3bd/255)
1017
1018 SET_ALPHA_LEVEL(alpha_s_3a_0, f3_alpha_level_3as)
1019 SET_ALPHA_LEVEL(alpha_s_3a_1, f3_alpha_level_3as*f3_alpha_level_2ad/255)
1020 SET_ALPHA_LEVEL(alpha_s_3a_2, f3_alpha_level_3as*f3_alpha_level_2bd/255)
1021
1022 SET_ALPHA_LEVEL(alpha_s_3b_0, f3_alpha_level_3bs)
1023 SET_ALPHA_LEVEL(alpha_s_3b_1, f3_alpha_level_3bs*f3_alpha_level_2ad/255)
1024 SET_ALPHA_LEVEL(alpha_s_3b_2, f3_alpha_level_3bs*f3_alpha_level_2bd/255)
1025 }
1026 #undef SET_ALPHA_LEVEL
1027
1028 /*============================================================================*/
1029
1030 #ifdef MSB_FIRST
1031 #define COLOR1 3
1032 #define COLOR2 2
1033 #define COLOR3 1
1034 #else
1035 #define COLOR1 0
1036 #define COLOR2 1
1037 #define COLOR3 2
1038 #endif
1039
f3_alpha_blend32_s(const UINT8 * alphas,UINT32 s)1040 static INLINE void f3_alpha_blend32_s( const UINT8 *alphas, UINT32 s )
1041 {
1042 UINT8 *sc = (UINT8 *)&s;
1043 UINT8 *dc = (UINT8 *)&dval;
1044 dc[COLOR1] = alphas[sc[COLOR1]];
1045 dc[COLOR2] = alphas[sc[COLOR2]];
1046 dc[COLOR3] = alphas[sc[COLOR3]];
1047 }
1048
f3_alpha_blend32_d(const UINT8 * alphas,UINT32 s)1049 static INLINE void f3_alpha_blend32_d( const UINT8 *alphas, UINT32 s )
1050 {
1051 UINT8 *sc = (UINT8 *)&s;
1052 UINT8 *dc = (UINT8 *)&dval;
1053 dc[COLOR1] = add_sat[dc[COLOR1]][alphas[sc[COLOR1]]];
1054 dc[COLOR2] = add_sat[dc[COLOR2]][alphas[sc[COLOR2]]];
1055 dc[COLOR3] = add_sat[dc[COLOR3]][alphas[sc[COLOR3]]];
1056 }
1057
1058 /*============================================================================*/
1059
f3_alpha_blend_1_1(UINT32 s)1060 static INLINE void f3_alpha_blend_1_1( UINT32 s ){f3_alpha_blend32_d(alpha_s_1_1,s);}
f3_alpha_blend_1_2(UINT32 s)1061 static INLINE void f3_alpha_blend_1_2( UINT32 s ){f3_alpha_blend32_d(alpha_s_1_2,s);}
f3_alpha_blend_1_4(UINT32 s)1062 static INLINE void f3_alpha_blend_1_4( UINT32 s ){f3_alpha_blend32_d(alpha_s_1_4,s);}
f3_alpha_blend_1_5(UINT32 s)1063 static INLINE void f3_alpha_blend_1_5( UINT32 s ){f3_alpha_blend32_d(alpha_s_1_5,s);}
f3_alpha_blend_1_6(UINT32 s)1064 static INLINE void f3_alpha_blend_1_6( UINT32 s ){f3_alpha_blend32_d(alpha_s_1_6,s);}
f3_alpha_blend_1_8(UINT32 s)1065 static INLINE void f3_alpha_blend_1_8( UINT32 s ){f3_alpha_blend32_d(alpha_s_1_8,s);}
f3_alpha_blend_1_9(UINT32 s)1066 static INLINE void f3_alpha_blend_1_9( UINT32 s ){f3_alpha_blend32_d(alpha_s_1_9,s);}
f3_alpha_blend_1_a(UINT32 s)1067 static INLINE void f3_alpha_blend_1_a( UINT32 s ){f3_alpha_blend32_d(alpha_s_1_a,s);}
1068
f3_alpha_blend_2a_0(UINT32 s)1069 static INLINE void f3_alpha_blend_2a_0( UINT32 s ){f3_alpha_blend32_s(alpha_s_2a_0,s);}
f3_alpha_blend_2a_4(UINT32 s)1070 static INLINE void f3_alpha_blend_2a_4( UINT32 s ){f3_alpha_blend32_d(alpha_s_2a_4,s);}
f3_alpha_blend_2a_8(UINT32 s)1071 static INLINE void f3_alpha_blend_2a_8( UINT32 s ){f3_alpha_blend32_d(alpha_s_2a_8,s);}
1072
f3_alpha_blend_2b_0(UINT32 s)1073 static INLINE void f3_alpha_blend_2b_0( UINT32 s ){f3_alpha_blend32_s(alpha_s_2b_0,s);}
f3_alpha_blend_2b_4(UINT32 s)1074 static INLINE void f3_alpha_blend_2b_4( UINT32 s ){f3_alpha_blend32_d(alpha_s_2b_4,s);}
f3_alpha_blend_2b_8(UINT32 s)1075 static INLINE void f3_alpha_blend_2b_8( UINT32 s ){f3_alpha_blend32_d(alpha_s_2b_8,s);}
1076
f3_alpha_blend_3a_0(UINT32 s)1077 static INLINE void f3_alpha_blend_3a_0( UINT32 s ){f3_alpha_blend32_s(alpha_s_3a_0,s);}
f3_alpha_blend_3a_1(UINT32 s)1078 static INLINE void f3_alpha_blend_3a_1( UINT32 s ){f3_alpha_blend32_d(alpha_s_3a_1,s);}
f3_alpha_blend_3a_2(UINT32 s)1079 static INLINE void f3_alpha_blend_3a_2( UINT32 s ){f3_alpha_blend32_d(alpha_s_3a_2,s);}
1080
f3_alpha_blend_3b_0(UINT32 s)1081 static INLINE void f3_alpha_blend_3b_0( UINT32 s ){f3_alpha_blend32_s(alpha_s_3b_0,s);}
f3_alpha_blend_3b_1(UINT32 s)1082 static INLINE void f3_alpha_blend_3b_1( UINT32 s ){f3_alpha_blend32_d(alpha_s_3b_1,s);}
f3_alpha_blend_3b_2(UINT32 s)1083 static INLINE void f3_alpha_blend_3b_2( UINT32 s ){f3_alpha_blend32_d(alpha_s_3b_2,s);}
1084
1085 /*============================================================================*/
1086
dpix_1_noalpha(UINT32 s_pix)1087 static int dpix_1_noalpha(UINT32 s_pix) {dval = s_pix; return 1;}
dpix_ret1(UINT32 s_pix)1088 static int dpix_ret1(UINT32 s_pix) {return 1;}
dpix_ret0(UINT32 s_pix)1089 static int dpix_ret0(UINT32 s_pix) {return 0;}
dpix_1_1(UINT32 s_pix)1090 static int dpix_1_1(UINT32 s_pix) {if(s_pix) f3_alpha_blend_1_1(s_pix); return 1;}
dpix_1_2(UINT32 s_pix)1091 static int dpix_1_2(UINT32 s_pix) {if(s_pix) f3_alpha_blend_1_2(s_pix); return 1;}
dpix_1_4(UINT32 s_pix)1092 static int dpix_1_4(UINT32 s_pix) {if(s_pix) f3_alpha_blend_1_4(s_pix); return 1;}
dpix_1_5(UINT32 s_pix)1093 static int dpix_1_5(UINT32 s_pix) {if(s_pix) f3_alpha_blend_1_5(s_pix); return 1;}
dpix_1_6(UINT32 s_pix)1094 static int dpix_1_6(UINT32 s_pix) {if(s_pix) f3_alpha_blend_1_6(s_pix); return 1;}
dpix_1_8(UINT32 s_pix)1095 static int dpix_1_8(UINT32 s_pix) {if(s_pix) f3_alpha_blend_1_8(s_pix); return 1;}
dpix_1_9(UINT32 s_pix)1096 static int dpix_1_9(UINT32 s_pix) {if(s_pix) f3_alpha_blend_1_9(s_pix); return 1;}
dpix_1_a(UINT32 s_pix)1097 static int dpix_1_a(UINT32 s_pix) {if(s_pix) f3_alpha_blend_1_a(s_pix); return 1;}
1098
dpix_2a_0(UINT32 s_pix)1099 static int dpix_2a_0(UINT32 s_pix)
1100 {
1101 if(s_pix) f3_alpha_blend_2a_0(s_pix);
1102 else dval = 0;
1103 if(pdest_2a) {pval |= pdest_2a;return 0;}
1104 return 1;
1105 }
dpix_2a_4(UINT32 s_pix)1106 static int dpix_2a_4(UINT32 s_pix)
1107 {
1108 if(s_pix) f3_alpha_blend_2a_4(s_pix);
1109 if(pdest_2a) {pval |= pdest_2a;return 0;}
1110 return 1;
1111 }
dpix_2a_8(UINT32 s_pix)1112 static int dpix_2a_8(UINT32 s_pix)
1113 {
1114 if(s_pix) f3_alpha_blend_2a_8(s_pix);
1115 if(pdest_2a) {pval |= pdest_2a;return 0;}
1116 return 1;
1117 }
1118
dpix_3a_0(UINT32 s_pix)1119 static int dpix_3a_0(UINT32 s_pix)
1120 {
1121 if(s_pix) f3_alpha_blend_3a_0(s_pix);
1122 else dval = 0;
1123 if(pdest_3a) {pval |= pdest_3a;return 0;}
1124 return 1;
1125 }
dpix_3a_1(UINT32 s_pix)1126 static int dpix_3a_1(UINT32 s_pix)
1127 {
1128 if(s_pix) f3_alpha_blend_3a_1(s_pix);
1129 if(pdest_3a) {pval |= pdest_3a;return 0;}
1130 return 1;
1131 }
dpix_3a_2(UINT32 s_pix)1132 static int dpix_3a_2(UINT32 s_pix)
1133 {
1134 if(s_pix) f3_alpha_blend_3a_2(s_pix);
1135 if(pdest_3a) {pval |= pdest_3a;return 0;}
1136 return 1;
1137 }
1138
dpix_2b_0(UINT32 s_pix)1139 static int dpix_2b_0(UINT32 s_pix)
1140 {
1141 if(s_pix) f3_alpha_blend_2b_0(s_pix);
1142 else dval = 0;
1143 if(pdest_2b) {pval |= pdest_2b;return 0;}
1144 return 1;
1145 }
dpix_2b_4(UINT32 s_pix)1146 static int dpix_2b_4(UINT32 s_pix)
1147 {
1148 if(s_pix) f3_alpha_blend_2b_4(s_pix);
1149 if(pdest_2b) {pval |= pdest_2b;return 0;}
1150 return 1;
1151 }
dpix_2b_8(UINT32 s_pix)1152 static int dpix_2b_8(UINT32 s_pix)
1153 {
1154 if(s_pix) f3_alpha_blend_2b_8(s_pix);
1155 if(pdest_2b) {pval |= pdest_2b;return 0;}
1156 return 1;
1157 }
1158
dpix_3b_0(UINT32 s_pix)1159 static int dpix_3b_0(UINT32 s_pix)
1160 {
1161 if(s_pix) f3_alpha_blend_3b_0(s_pix);
1162 else dval = 0;
1163 if(pdest_3b) {pval |= pdest_3b;return 0;}
1164 return 1;
1165 }
dpix_3b_1(UINT32 s_pix)1166 static int dpix_3b_1(UINT32 s_pix)
1167 {
1168 if(s_pix) f3_alpha_blend_3b_1(s_pix);
1169 if(pdest_3b) {pval |= pdest_3b;return 0;}
1170 return 1;
1171 }
dpix_3b_2(UINT32 s_pix)1172 static int dpix_3b_2(UINT32 s_pix)
1173 {
1174 if(s_pix) f3_alpha_blend_3b_2(s_pix);
1175 if(pdest_3b) {pval |= pdest_3b;return 0;}
1176 return 1;
1177 }
1178
dpix_2_0(UINT32 s_pix)1179 static int dpix_2_0(UINT32 s_pix)
1180 {
1181 UINT8 tr2=tval&1;
1182 if(s_pix)
1183 {
1184 if(tr2==tr_2b) {f3_alpha_blend_2b_0(s_pix);if(pdest_2b) pval |= pdest_2b;else return 1;}
1185 else if(tr2==tr_2a) {f3_alpha_blend_2a_0(s_pix);if(pdest_2a) pval |= pdest_2a;else return 1;}
1186 }
1187 else
1188 {
1189 if(tr2==tr_2b) {dval = 0;if(pdest_2b) pval |= pdest_2b;else return 1;}
1190 else if(tr2==tr_2a) {dval = 0;if(pdest_2a) pval |= pdest_2a;else return 1;}
1191 }
1192 return 0;
1193 }
dpix_2_4(UINT32 s_pix)1194 static int dpix_2_4(UINT32 s_pix)
1195 {
1196 UINT8 tr2=tval&1;
1197 if(s_pix)
1198 {
1199 if(tr2==tr_2b) {f3_alpha_blend_2b_4(s_pix);if(pdest_2b) pval |= pdest_2b;else return 1;}
1200 else if(tr2==tr_2a) {f3_alpha_blend_2a_4(s_pix);if(pdest_2a) pval |= pdest_2a;else return 1;}
1201 }
1202 else
1203 {
1204 if(tr2==tr_2b) {if(pdest_2b) pval |= pdest_2b;else return 1;}
1205 else if(tr2==tr_2a) {if(pdest_2a) pval |= pdest_2a;else return 1;}
1206 }
1207 return 0;
1208 }
dpix_2_8(UINT32 s_pix)1209 static int dpix_2_8(UINT32 s_pix)
1210 {
1211 UINT8 tr2=tval&1;
1212 if(s_pix)
1213 {
1214 if(tr2==tr_2b) {f3_alpha_blend_2b_8(s_pix);if(pdest_2b) pval |= pdest_2b;else return 1;}
1215 else if(tr2==tr_2a) {f3_alpha_blend_2a_8(s_pix);if(pdest_2a) pval |= pdest_2a;else return 1;}
1216 }
1217 else
1218 {
1219 if(tr2==tr_2b) {if(pdest_2b) pval |= pdest_2b;else return 1;}
1220 else if(tr2==tr_2a) {if(pdest_2a) pval |= pdest_2a;else return 1;}
1221 }
1222 return 0;
1223 }
1224
dpix_3_0(UINT32 s_pix)1225 static int dpix_3_0(UINT32 s_pix)
1226 {
1227 UINT8 tr2=tval&1;
1228 if(s_pix)
1229 {
1230 if(tr2==tr_3b) {f3_alpha_blend_3b_0(s_pix);if(pdest_3b) pval |= pdest_3b;else return 1;}
1231 else if(tr2==tr_3a) {f3_alpha_blend_3a_0(s_pix);if(pdest_3a) pval |= pdest_3a;else return 1;}
1232 }
1233 else
1234 {
1235 if(tr2==tr_3b) {dval = 0;if(pdest_3b) pval |= pdest_3b;else return 1;}
1236 else if(tr2==tr_3a) {dval = 0;if(pdest_3a) pval |= pdest_3a;else return 1;}
1237 }
1238 return 0;
1239 }
dpix_3_1(UINT32 s_pix)1240 static int dpix_3_1(UINT32 s_pix)
1241 {
1242 UINT8 tr2=tval&1;
1243 if(s_pix)
1244 {
1245 if(tr2==tr_3b) {f3_alpha_blend_3b_1(s_pix);if(pdest_3b) pval |= pdest_3b;else return 1;}
1246 else if(tr2==tr_3a) {f3_alpha_blend_3a_1(s_pix);if(pdest_3a) pval |= pdest_3a;else return 1;}
1247 }
1248 else
1249 {
1250 if(tr2==tr_3b) {if(pdest_3b) pval |= pdest_3b;else return 1;}
1251 else if(tr2==tr_3a) {if(pdest_3a) pval |= pdest_3a;else return 1;}
1252 }
1253 return 0;
1254 }
dpix_3_2(UINT32 s_pix)1255 static int dpix_3_2(UINT32 s_pix)
1256 {
1257 UINT8 tr2=tval&1;
1258 if(s_pix)
1259 {
1260 if(tr2==tr_3b) {f3_alpha_blend_3b_2(s_pix);if(pdest_3b) pval |= pdest_3b;else return 1;}
1261 else if(tr2==tr_3a) {f3_alpha_blend_3a_2(s_pix);if(pdest_3a) pval |= pdest_3a;else return 1;}
1262 }
1263 else
1264 {
1265 if(tr2==tr_3b) {if(pdest_3b) pval |= pdest_3b;else return 1;}
1266 else if(tr2==tr_3a) {if(pdest_3a) pval |= pdest_3a;else return 1;}
1267 }
1268 return 0;
1269 }
1270
dpix_1_sprite(UINT32 s_pix)1271 static INLINE void dpix_1_sprite(UINT32 s_pix)
1272 {
1273 if(s_pix)
1274 {
1275 UINT8 p1 = pval&0xf0;
1276 if (p1==0x10) f3_alpha_blend_1_1(s_pix);
1277 else if(p1==0x20) f3_alpha_blend_1_2(s_pix);
1278 else if(p1==0x40) f3_alpha_blend_1_4(s_pix);
1279 else if(p1==0x50) f3_alpha_blend_1_5(s_pix);
1280 else if(p1==0x60) f3_alpha_blend_1_6(s_pix);
1281 else if(p1==0x80) f3_alpha_blend_1_8(s_pix);
1282 else if(p1==0x90) f3_alpha_blend_1_9(s_pix);
1283 else if(p1==0xa0) f3_alpha_blend_1_a(s_pix);
1284 }
1285 }
1286
dpix_bg(UINT32 bgcolor)1287 static INLINE void dpix_bg(UINT32 bgcolor)
1288 {
1289 UINT8 p1 = pval&0xf0;
1290 if(!p1) dval = bgcolor;
1291 else if(p1==0x10) f3_alpha_blend_1_1(bgcolor);
1292 else if(p1==0x20) f3_alpha_blend_1_2(bgcolor);
1293 else if(p1==0x40) f3_alpha_blend_1_4(bgcolor);
1294 else if(p1==0x50) f3_alpha_blend_1_5(bgcolor);
1295 else if(p1==0x60) f3_alpha_blend_1_6(bgcolor);
1296 else if(p1==0x80) f3_alpha_blend_1_8(bgcolor);
1297 else if(p1==0x90) f3_alpha_blend_1_9(bgcolor);
1298 else if(p1==0xa0) f3_alpha_blend_1_a(bgcolor);
1299 }
1300
1301 /******************************************************************************/
1302
init_alpha_blend_func(void)1303 static void init_alpha_blend_func(void)
1304 {
1305 int i,j;
1306
1307 dpix_n[0][0x0]=dpix_1_noalpha;
1308 dpix_n[0][0x1]=dpix_1_noalpha;
1309 dpix_n[0][0x2]=dpix_1_noalpha;
1310 dpix_n[0][0x3]=dpix_1_noalpha;
1311 dpix_n[0][0x4]=dpix_1_noalpha;
1312 dpix_n[0][0x5]=dpix_1_noalpha;
1313 dpix_n[0][0x6]=dpix_1_noalpha;
1314 dpix_n[0][0x7]=dpix_1_noalpha;
1315 dpix_n[0][0x8]=dpix_1_noalpha;
1316 dpix_n[0][0x9]=dpix_1_noalpha;
1317 dpix_n[0][0xa]=dpix_1_noalpha;
1318 dpix_n[0][0xb]=dpix_1_noalpha;
1319 dpix_n[0][0xc]=dpix_1_noalpha;
1320 dpix_n[0][0xd]=dpix_1_noalpha;
1321 dpix_n[0][0xe]=dpix_1_noalpha;
1322 dpix_n[0][0xf]=dpix_1_noalpha;
1323
1324 dpix_n[1][0x0]=dpix_1_noalpha;
1325 dpix_n[1][0x1]=dpix_1_1;
1326 dpix_n[1][0x2]=dpix_1_2;
1327 dpix_n[1][0x3]=dpix_ret1;
1328 dpix_n[1][0x4]=dpix_1_4;
1329 dpix_n[1][0x5]=dpix_1_5;
1330 dpix_n[1][0x6]=dpix_1_6;
1331 dpix_n[1][0x7]=dpix_ret1;
1332 dpix_n[1][0x8]=dpix_1_8;
1333 dpix_n[1][0x9]=dpix_1_9;
1334 dpix_n[1][0xa]=dpix_1_a;
1335 dpix_n[1][0xb]=dpix_ret1;
1336 dpix_n[1][0xc]=dpix_ret1;
1337 dpix_n[1][0xd]=dpix_ret1;
1338 dpix_n[1][0xe]=dpix_ret1;
1339 dpix_n[1][0xf]=dpix_ret1;
1340
1341 dpix_n[2][0x0]=dpix_2a_0;
1342 dpix_n[2][0x1]=dpix_ret0;
1343 dpix_n[2][0x2]=dpix_ret0;
1344 dpix_n[2][0x3]=dpix_ret0;
1345 dpix_n[2][0x4]=dpix_2a_4;
1346 dpix_n[2][0x5]=dpix_ret0;
1347 dpix_n[2][0x6]=dpix_ret0;
1348 dpix_n[2][0x7]=dpix_ret0;
1349 dpix_n[2][0x8]=dpix_2a_8;
1350 dpix_n[2][0x9]=dpix_ret0;
1351 dpix_n[2][0xa]=dpix_ret0;
1352 dpix_n[2][0xb]=dpix_ret0;
1353 dpix_n[2][0xc]=dpix_ret0;
1354 dpix_n[2][0xd]=dpix_ret0;
1355 dpix_n[2][0xe]=dpix_ret0;
1356 dpix_n[2][0xf]=dpix_ret0;
1357
1358 dpix_n[3][0x0]=dpix_3a_0;
1359 dpix_n[3][0x1]=dpix_3a_1;
1360 dpix_n[3][0x2]=dpix_3a_2;
1361 dpix_n[3][0x3]=dpix_ret0;
1362 dpix_n[3][0x4]=dpix_ret0;
1363 dpix_n[3][0x5]=dpix_ret0;
1364 dpix_n[3][0x6]=dpix_ret0;
1365 dpix_n[3][0x7]=dpix_ret0;
1366 dpix_n[3][0x8]=dpix_ret0;
1367 dpix_n[3][0x9]=dpix_ret0;
1368 dpix_n[3][0xa]=dpix_ret0;
1369 dpix_n[3][0xb]=dpix_ret0;
1370 dpix_n[3][0xc]=dpix_ret0;
1371 dpix_n[3][0xd]=dpix_ret0;
1372 dpix_n[3][0xe]=dpix_ret0;
1373 dpix_n[3][0xf]=dpix_ret0;
1374
1375 dpix_n[4][0x0]=dpix_2b_0;
1376 dpix_n[4][0x1]=dpix_ret0;
1377 dpix_n[4][0x2]=dpix_ret0;
1378 dpix_n[4][0x3]=dpix_ret0;
1379 dpix_n[4][0x4]=dpix_2b_4;
1380 dpix_n[4][0x5]=dpix_ret0;
1381 dpix_n[4][0x6]=dpix_ret0;
1382 dpix_n[4][0x7]=dpix_ret0;
1383 dpix_n[4][0x8]=dpix_2b_8;
1384 dpix_n[4][0x9]=dpix_ret0;
1385 dpix_n[4][0xa]=dpix_ret0;
1386 dpix_n[4][0xb]=dpix_ret0;
1387 dpix_n[4][0xc]=dpix_ret0;
1388 dpix_n[4][0xd]=dpix_ret0;
1389 dpix_n[4][0xe]=dpix_ret0;
1390 dpix_n[4][0xf]=dpix_ret0;
1391
1392 dpix_n[5][0x0]=dpix_3b_0;
1393 dpix_n[5][0x1]=dpix_3b_1;
1394 dpix_n[5][0x2]=dpix_3b_2;
1395 dpix_n[5][0x3]=dpix_ret0;
1396 dpix_n[5][0x4]=dpix_ret0;
1397 dpix_n[5][0x5]=dpix_ret0;
1398 dpix_n[5][0x6]=dpix_ret0;
1399 dpix_n[5][0x7]=dpix_ret0;
1400 dpix_n[5][0x8]=dpix_ret0;
1401 dpix_n[5][0x9]=dpix_ret0;
1402 dpix_n[5][0xa]=dpix_ret0;
1403 dpix_n[5][0xb]=dpix_ret0;
1404 dpix_n[5][0xc]=dpix_ret0;
1405 dpix_n[5][0xd]=dpix_ret0;
1406 dpix_n[5][0xe]=dpix_ret0;
1407 dpix_n[5][0xf]=dpix_ret0;
1408
1409 dpix_n[6][0x0]=dpix_2_0;
1410 dpix_n[6][0x1]=dpix_ret0;
1411 dpix_n[6][0x2]=dpix_ret0;
1412 dpix_n[6][0x3]=dpix_ret0;
1413 dpix_n[6][0x4]=dpix_2_4;
1414 dpix_n[6][0x5]=dpix_ret0;
1415 dpix_n[6][0x6]=dpix_ret0;
1416 dpix_n[6][0x7]=dpix_ret0;
1417 dpix_n[6][0x8]=dpix_2_8;
1418 dpix_n[6][0x9]=dpix_ret0;
1419 dpix_n[6][0xa]=dpix_ret0;
1420 dpix_n[6][0xb]=dpix_ret0;
1421 dpix_n[6][0xc]=dpix_ret0;
1422 dpix_n[6][0xd]=dpix_ret0;
1423 dpix_n[6][0xe]=dpix_ret0;
1424 dpix_n[6][0xf]=dpix_ret0;
1425
1426 dpix_n[7][0x0]=dpix_3_0;
1427 dpix_n[7][0x1]=dpix_3_1;
1428 dpix_n[7][0x2]=dpix_3_2;
1429 dpix_n[7][0x3]=dpix_ret0;
1430 dpix_n[7][0x4]=dpix_ret0;
1431 dpix_n[7][0x5]=dpix_ret0;
1432 dpix_n[7][0x6]=dpix_ret0;
1433 dpix_n[7][0x7]=dpix_ret0;
1434 dpix_n[7][0x8]=dpix_ret0;
1435 dpix_n[7][0x9]=dpix_ret0;
1436 dpix_n[7][0xa]=dpix_ret0;
1437 dpix_n[7][0xb]=dpix_ret0;
1438 dpix_n[7][0xc]=dpix_ret0;
1439 dpix_n[7][0xd]=dpix_ret0;
1440 dpix_n[7][0xe]=dpix_ret0;
1441 dpix_n[7][0xf]=dpix_ret0;
1442
1443 for(i=0;i<256;i++)
1444 for(j=0;j<256;j++)
1445 add_sat[i][j] = (i + j < 256) ? i + j : 255;
1446 }
1447
1448 /******************************************************************************/
1449
1450 #define GET_PIXMAP_POINTER(pf_num) \
1451 { \
1452 const struct f3_line_inf *line_tmp=line_t[pf_num]; \
1453 src##pf_num=line_tmp->src[y]; \
1454 src_s##pf_num=line_tmp->src_s[y]; \
1455 src_e##pf_num=line_tmp->src_e[y]; \
1456 tsrc##pf_num=line_tmp->tsrc[y]; \
1457 tsrc_s##pf_num=line_tmp->tsrc_s[y]; \
1458 x_count##pf_num=line_tmp->x_count[y]; \
1459 x_zoom##pf_num=line_tmp->x_zoom[y]; \
1460 }
1461
1462 #define CULC_PIXMAP_POINTER(pf_num) \
1463 { \
1464 x_count##pf_num += x_zoom##pf_num; \
1465 if(x_count##pf_num>>16) \
1466 { \
1467 x_count##pf_num &= 0xffff; \
1468 src##pf_num++; \
1469 tsrc##pf_num++; \
1470 if(src##pf_num==src_e##pf_num) {src##pf_num=src_s##pf_num; tsrc##pf_num=tsrc_s##pf_num;} \
1471 } \
1472 }
1473
1474 /*============================================================================*/
1475
f3_drawscanlines(struct mame_bitmap * bitmap,int x,int xsize,INT16 * draw_line_num,const struct f3_line_inf ** line_t,const int * sprite,UINT32 orient,int skip_layer_num)1476 static INLINE void f3_drawscanlines(
1477 struct mame_bitmap *bitmap,int x,int xsize,INT16 *draw_line_num,
1478 const struct f3_line_inf **line_t,
1479 const int *sprite,
1480 UINT32 orient,
1481 int skip_layer_num)
1482 {
1483 pen_t *clut = &Machine->remapped_colortable[0];
1484 UINT32 bgcolor=clut[0];
1485 int length;
1486
1487 UINT32 sprite_noalp_0=sprite[0]&0x100;
1488 UINT32 sprite_noalp_1=sprite[1]&0x100;
1489 UINT32 sprite_noalp_2=sprite[2]&0x100;
1490 UINT32 sprite_noalp_3=sprite[3]&0x100;
1491 UINT32 sprite_noalp_4=sprite[4]&0x100;
1492
1493 static UINT16 *src0=0,*src_s0=0,*src_e0=0;
1494 static UINT8 *tsrc0=0,*tsrc_s0=0;
1495 static UINT32 x_count0=0,x_zoom0=0;
1496
1497 static UINT16 *src1=0,*src_s1=0,*src_e1=0;
1498 static UINT8 *tsrc1=0,*tsrc_s1=0;
1499 static UINT32 x_count1=0,x_zoom1=0;
1500
1501 static UINT16 *src2=0,*src_s2=0,*src_e2=0;
1502 static UINT8 *tsrc2=0,*tsrc_s2=0;
1503 static UINT32 x_count2=0,x_zoom2=0;
1504
1505 static UINT16 *src3=0,*src_s3=0,*src_e3=0;
1506 static UINT8 *tsrc3=0,*tsrc_s3=0;
1507 static UINT32 x_count3=0,x_zoom3=0;
1508
1509 UINT8 *dstp0,*dstp;
1510
1511 int yadv = bitmap->rowpixels;
1512 int i=0,y=draw_line_num[0];
1513 int ty = y;
1514
1515 if (orient & ORIENTATION_FLIP_Y)
1516 {
1517 ty = bitmap->height - 1 - ty;
1518 yadv = -yadv;
1519 }
1520
1521 dstp0 = (UINT8 *)pri_alp_bitmap->line[ty] + x;
1522
1523 pdest_2a = f3_alpha_level_2ad ? 0x10 : 0;
1524 pdest_2b = f3_alpha_level_2bd ? 0x20 : 0;
1525 tr_2a =(f3_alpha_level_2as==0 && f3_alpha_level_2ad==255) ? -1 : 0;
1526 tr_2b =(f3_alpha_level_2bs==0 && f3_alpha_level_2bd==255) ? -1 : 1;
1527 pdest_3a = f3_alpha_level_3ad ? 0x40 : 0;
1528 pdest_3b = f3_alpha_level_3bd ? 0x80 : 0;
1529 tr_3a =(f3_alpha_level_3as==0 && f3_alpha_level_3ad==255) ? -1 : 0;
1530 tr_3b =(f3_alpha_level_3bs==0 && f3_alpha_level_3bd==255) ? -1 : 1;
1531
1532
1533 /* if (bitmap->depth == 32)*/
1534 {
1535 UINT32 *dsti0,*dsti;
1536 dsti0 = (UINT32 *)bitmap->line[ty] + x;
1537 while(1)
1538 {
1539 length=xsize;
1540 dsti = dsti0;
1541 dstp = dstp0;
1542
1543 switch(skip_layer_num)
1544 {
1545 case 0: GET_PIXMAP_POINTER(0)
1546 case 1: GET_PIXMAP_POINTER(1)
1547 case 2: GET_PIXMAP_POINTER(2)
1548 case 3: GET_PIXMAP_POINTER(3)
1549 }
1550
1551 while (1)
1552 {
1553 pval=*dstp;
1554 if (pval!=0xff)
1555 {
1556 UINT8 sprite_pri;
1557 switch(skip_layer_num)
1558 {
1559 case 0: if((sprite_pri=sprite[0]&pval))
1560 {
1561 if(sprite_noalp_0) break;
1562 if(!dpix_sp[sprite_pri]) break;
1563 if(dpix_sp[sprite_pri][pval>>4](*dsti)) {*dsti=dval;break;}
1564 }
1565 {tval=*tsrc0;if(tval&0xf0) if(dpix_lp[0][pval>>4](clut[*src0])) {*dsti=dval;break;}}
1566 case 1: if((sprite_pri=sprite[1]&pval))
1567 {
1568 if(sprite_noalp_1) break;
1569 if(!dpix_sp[sprite_pri])
1570 {
1571 if(!(pval&0xf0)) break;
1572 else {dpix_1_sprite(*dsti);*dsti=dval;break;}
1573 }
1574 if(dpix_sp[sprite_pri][pval>>4](*dsti)) {*dsti=dval;break;}
1575 }
1576 {tval=*tsrc1;if(tval&0xf0) if(dpix_lp[1][pval>>4](clut[*src1])) {*dsti=dval;break;}}
1577 case 2: if((sprite_pri=sprite[2]&pval))
1578 {
1579 if(sprite_noalp_2) break;
1580 if(!dpix_sp[sprite_pri])
1581 {
1582 if(!(pval&0xf0)) break;
1583 else {dpix_1_sprite(*dsti);*dsti=dval;break;}
1584 }
1585 if(dpix_sp[sprite_pri][pval>>4](*dsti)) {*dsti=dval;break;}
1586 }
1587 {tval=*tsrc2;if(tval&0xf0) if(dpix_lp[2][pval>>4](clut[*src2])) {*dsti=dval;break;}}
1588 case 3: if((sprite_pri=sprite[3]&pval))
1589 {
1590 if(sprite_noalp_3) break;
1591 if(!dpix_sp[sprite_pri])
1592 {
1593 if(!(pval&0xf0)) break;
1594 else {dpix_1_sprite(*dsti);*dsti=dval;break;}
1595 }
1596 if(dpix_sp[sprite_pri][pval>>4](*dsti)) {*dsti=dval;break;}
1597 }
1598 {tval=*tsrc3;if(tval&0xf0) if(dpix_lp[3][pval>>4](clut[*src3])) {*dsti=dval;break;}}
1599 case 4: if((sprite_pri=sprite[4]&pval))
1600 {
1601 if(sprite_noalp_4) break;
1602 if(!dpix_sp[sprite_pri])
1603 {
1604 if(!(pval&0xf0)) break;
1605 else {dpix_1_sprite(*dsti);*dsti=dval;break;}
1606 }
1607 if(dpix_sp[sprite_pri][pval>>4](*dsti)) {*dsti=dval;break;}
1608 }
1609 if(!bgcolor) {if(!(pval&0xf0)) {*dsti=0;break;}}
1610 else dpix_bg(bgcolor);
1611 *dsti=dval;
1612 }
1613 }
1614
1615 if(!(--length)) break;
1616 dsti++;
1617 dstp++;
1618
1619 switch(skip_layer_num)
1620 {
1621 case 0: CULC_PIXMAP_POINTER(0)
1622 case 1: CULC_PIXMAP_POINTER(1)
1623 case 2: CULC_PIXMAP_POINTER(2)
1624 case 3: CULC_PIXMAP_POINTER(3)
1625 }
1626 }
1627
1628 i++;
1629 if(draw_line_num[i]<0) break;
1630 if(draw_line_num[i]==y+1)
1631 {
1632 dsti0 += yadv;
1633 dstp0 += yadv;
1634 y++;
1635 continue;
1636 }
1637 else
1638 {
1639 int dy=(draw_line_num[i]-y)*yadv;
1640 dsti0 += dy;
1641 dstp0 += dy;
1642 y=draw_line_num[i];
1643 }
1644 }
1645 }
1646 }
1647 #undef GET_PIXMAP_POINTER
1648 #undef CULC_PIXMAP_POINTER
1649
1650 /******************************************************************************/
1651
clear_scanlines(struct mame_bitmap * bitmap,int x,int xsize,INT16 * draw_line_num,UINT32 orient)1652 static INLINE void clear_scanlines(struct mame_bitmap *bitmap,int x,int xsize,INT16 *draw_line_num,UINT32 orient)
1653 {
1654 int length;
1655
1656 int yadv = bitmap->rowpixels;
1657 int i=0,y=draw_line_num[0];
1658 int ty = y;
1659
1660 if (orient & ORIENTATION_FLIP_Y)
1661 {
1662 ty = bitmap->height - 1 - ty;
1663 yadv = -yadv;
1664 }
1665
1666 /* if (bitmap->depth == 32)*/
1667 {
1668 UINT32 *dsti0,*dsti;
1669 dsti0 = (UINT32 *)bitmap->line[ty] + x;
1670
1671 while (1)
1672 {
1673 length=xsize;
1674 dsti = dsti0;
1675 while (length--)
1676 {
1677 *dsti = 0;
1678 dsti++;
1679 }
1680
1681 i++;
1682 if(draw_line_num[i]<0) break;
1683 if(draw_line_num[i]==y+1)
1684 {
1685 dsti0 += yadv;
1686 y++;
1687 continue;
1688 }
1689 else
1690 {
1691 dsti0 += (draw_line_num[i]-y)*yadv;
1692 y=draw_line_num[i];
1693 }
1694 }
1695 }
1696 }
1697
1698 /******************************************************************************/
1699
visible_tile_check(struct f3_line_inf * line_t,int line,UINT32 x_index_fx,UINT32 y_index,data32_t * f3_pf_data_n)1700 static void visible_tile_check(struct f3_line_inf *line_t,
1701 int line,
1702 UINT32 x_index_fx,UINT32 y_index,
1703 data32_t *f3_pf_data_n)
1704 {
1705 data32_t *pf_base;
1706 int i,trans_all,tile_index,tile_num;
1707 int alpha_type,alpha_mode;
1708 int opaque_all;
1709 int total_elements;
1710
1711 if(!(alpha_mode=line_t->alpha_mode[line])) return;
1712
1713 total_elements=Machine->gfx[1]->total_elements;
1714
1715 tile_index=x_index_fx>>16;
1716 tile_num=(((line_t->x_zoom[line]*320+(x_index_fx & 0xffff)+0xffff)>>16)+(tile_index%16)+15)/16;
1717 tile_index/=16;
1718
1719 if (flipscreen)
1720 {
1721 pf_base=f3_pf_data_n+((31-(y_index/16))<<twidth_mask_bit);
1722 tile_index=(twidth_mask-tile_index)-tile_num+1;
1723 }
1724 else pf_base=f3_pf_data_n+((y_index/16)<<twidth_mask_bit);
1725
1726
1727 trans_all=1;
1728 opaque_all=1;
1729 alpha_type=0;
1730 for(i=0;i<tile_num;i++)
1731 {
1732 UINT32 tile=pf_base[(tile_index)&twidth_mask];
1733 if(tile&0xffff)
1734 {
1735 trans_all=0;
1736 if(opaque_all)
1737 {
1738 if(tile_opaque_pf[(tile&0xffff)%total_elements]!=1) opaque_all=0;
1739 }
1740
1741 if(alpha_mode==1)
1742 {
1743 if(!opaque_all) return;
1744 }
1745 else
1746 {
1747 if(alpha_type!=3)
1748 {
1749 if((tile>>(16+9))&1) alpha_type|=2;
1750 else alpha_type|=1;
1751 }
1752 else if(!opaque_all) break;
1753 }
1754 }
1755 else if(opaque_all) opaque_all=0;
1756
1757 tile_index++;
1758 }
1759
1760 if(trans_all) {line_t->alpha_mode[line]=0;return;}
1761
1762 if(alpha_mode>1)
1763 {
1764 line_t->alpha_mode[line]|=alpha_type<<4;
1765 }
1766
1767 if(opaque_all)
1768 line_t->alpha_mode[line]|=0x80;
1769 }
1770
1771 /******************************************************************************/
1772
1773 /* sx and sy are 16.16 fixed point numbers */
get_line_ram_info(struct tilemap * tilemap,int sx,int sy,int pos,data32_t * f3_pf_data_n)1774 static void get_line_ram_info(struct tilemap *tilemap,int sx,int sy,int pos,data32_t *f3_pf_data_n)
1775 {
1776 struct f3_line_inf *line_t=&line_inf[pos];
1777 const struct mame_bitmap *srcbitmap;
1778 const struct mame_bitmap *transbitmap;
1779
1780 int y,y_start,y_end,y_inc;
1781 int line_base,zoom_base,col_base,pri_base,spri_base,inc;
1782
1783 int line_enable;
1784 int colscroll=0,x_offset=0;
1785 UINT32 x_zoom=0x10000;
1786 UINT32 y_zoom=0;
1787 UINT16 pri=0;
1788 UINT16 spri=0;
1789 int alpha_level=0;
1790 int bit_select0=0x10000<<pos;
1791 int bit_select1=1<<pos;
1792 UINT16 sprite_alpha=0;
1793
1794 int _colscroll[256];
1795 UINT32 _x_offset[256];
1796 int y_index_fx;
1797
1798 sx+=(46<<16);/*+scroll_kludge_x;*/
1799 if (flipscreen)
1800 {
1801 line_base=0xa1fe + (pos*0x200);
1802 zoom_base=0x81fe + (pos*0x200);
1803 col_base =0x41fe + (pos*0x200);
1804 pri_base =0xb1fe + (pos*0x200);
1805 spri_base =0x77fe;
1806 inc=-2;
1807 y_start=255;
1808 y_end=-1;
1809 y_inc=-1;
1810
1811 if (f3_game_config->extend) sx=-sx+((188-512)<<16); else sx=-sx+(188<<16); /* Adjust for flipped scroll position */
1812 y_index_fx=-sy-(256<<16); /* Adjust for flipped scroll position */
1813 }
1814 else
1815 {
1816 line_base=0xa000 + (pos*0x200);
1817 zoom_base=0x8000 + (pos*0x200);
1818 col_base =0x4000 + (pos*0x200);
1819 pri_base =0xb000 + (pos*0x200);
1820 spri_base =0x7600;
1821 inc=2;
1822 y_start=0;
1823 y_end=256;
1824 y_inc=1;
1825
1826 y_index_fx=sy;
1827 }
1828
1829 y=y_start;
1830 while(y!=y_end)
1831 {
1832 /* The zoom, column and row values can latch according to control ram */
1833 if (y&1)
1834 {
1835 if (f3_line_ram[0x300+(y>>1)]&bit_select1)
1836 x_offset=(f3_line_ram[line_base/4]&0xffff)<<10;
1837 if (f3_line_ram[0x380+(y>>1)]&bit_select1)
1838 pri=f3_line_ram[pri_base/4]&0xffff;
1839 if (pri && !(pri&0x800) ) line_enable=1; else line_enable=0;
1840 if (f3_line_ram[0x200+(y>>1)]&bit_select1)
1841 {
1842 int line_ram_zoom=f3_line_ram[zoom_base/4]&0xffff;
1843 if (line_ram_zoom!=0)
1844 {
1845 x_zoom=0x10080 - line_ram_zoom;
1846 if (y_zoom==0 && line_enable) y_zoom=x_zoom;
1847 }
1848 }
1849 if (f3_line_ram[0x000+(y>>1)]&bit_select1)
1850 colscroll=(f3_line_ram[col_base/4]>> 0)&0x1ff;
1851 }
1852 else
1853 {
1854 if (f3_line_ram[0x300+(y>>1)]&bit_select0)
1855 x_offset=(f3_line_ram[line_base/4]&0xffff0000)>>6;
1856 if (f3_line_ram[0x380+(y>>1)]&bit_select0)
1857 pri=(f3_line_ram[pri_base/4]>>16)&0xffff;
1858 if (pri && !(pri&0x800) ) line_enable=1; else line_enable=0;
1859 if (f3_line_ram[0x200+(y>>1)]&bit_select0)
1860 {
1861 int line_ram_zoom=f3_line_ram[zoom_base/4]>>16;
1862 if (line_ram_zoom!=0)
1863 {
1864 x_zoom=0x10080 - line_ram_zoom;
1865 if (y_zoom==0 && line_enable) y_zoom=x_zoom;
1866 }
1867 }
1868 if (f3_line_ram[0x000+(y>>1)]&bit_select0)
1869 colscroll=(f3_line_ram[col_base/4]>>16)&0x1ff;
1870 }
1871
1872 /* XYZoom? */
1873 if(y_zoom && line_enable && (colscroll!=0 || x_zoom!=y_zoom)) y_zoom=0x10000;
1874
1875
1876 /* if (line_enable)*/
1877 {
1878 if (!pri || (!flipscreen && y<24) || (flipscreen && y>231) ||
1879 (pri&0xc000)==0xc000 || !(pri&0x2000)/**/)
1880 line_enable=0;
1881 else if(pri&0x4000) /*alpha1*/
1882 line_enable=2;
1883 else if(pri&0x8000) /*alpha2*/
1884 line_enable=3;
1885 /*special case when the blend mode is "normal" but the 6200 area is used.
1886 Might be missing a flag*/
1887 else if((pri&0x3000) && (f3_line_ram[0x6230/4]!= 0) && (pos == 2) &&
1888 (((f3_line_ram[(0x6200/4) + (y>>1)] >> 4) &0xf) != 0xb) && (f3_game == EACTION2))
1889 {
1890 line_enable=0x22;
1891 }
1892 else
1893 line_enable=1;
1894 }
1895
1896 _colscroll[y]=colscroll;
1897 _x_offset[y]=(x_offset&0xffff0000) - (x_offset&0x0000ffff);
1898
1899 line_t->x_zoom[y]=x_zoom;
1900 line_t->alpha_mode[y]=line_enable;
1901 line_t->pri[y]=pri;
1902
1903 if(!pos)
1904 {
1905 if (y&1)
1906 {
1907 if (f3_line_ram[(0x0600/4)+(y>>1)]&0x8)
1908 spri=f3_line_ram[spri_base/4]&0xffff;
1909 if (f3_line_ram[(0x0400/4)+(y>>1)]&0x1)
1910 sprite_alpha=f3_line_ram[(spri_base-0x1600)/4]&0xffff;
1911 if (f3_line_ram[(0x0400/4)+(y>>1)]&0x2)
1912 alpha_level=f3_line_ram[(spri_base-0x1400)/4]&0xffff;
1913 }
1914 else
1915 {
1916 if (f3_line_ram[(0x0600/4)+(y>>1)]&0x80000)
1917 spri=f3_line_ram[spri_base/4]>>16;
1918 if (f3_line_ram[(0x0400/4)+(y>>1)]&0x10000)
1919 sprite_alpha=f3_line_ram[(spri_base-0x1600)/4]>>16;
1920 if (f3_line_ram[(0x0400/4)+(y>>1)]&0x20000)
1921 alpha_level=f3_line_ram[(spri_base-0x1400)/4]>>16;
1922 }
1923
1924 line_t->alpha_level[y]=alpha_level;
1925 line_t->spri[y]=spri;
1926 line_t->sprite_alpha[y]=sprite_alpha;
1927 }
1928
1929 zoom_base+=inc;
1930 line_base+=inc;
1931 col_base +=inc;
1932 pri_base +=inc;
1933 spri_base+=inc;
1934 y +=y_inc;
1935 }
1936 if(!y_zoom) y_zoom=0x10000;
1937
1938
1939
1940 /* set pixmap pointer */
1941
1942 srcbitmap = tilemap_get_pixmap(tilemap);
1943 transbitmap = tilemap_get_transparency_bitmap(tilemap);
1944
1945 y=y_start;
1946 while(y!=y_end)
1947 {
1948 UINT32 x_index_fx;
1949 UINT32 y_index;
1950
1951 if(line_t->alpha_mode[y]!=0)
1952 {
1953 UINT16 *src_s;
1954 UINT8 *tsrc_s;
1955
1956 x_index_fx = (sx+_x_offset[y]-(10*0x10000)+10*line_t->x_zoom[y])&((width_mask<<16)|0xffff);
1957 y_index = ((y_index_fx>>16)+_colscroll[y])&0x1ff;
1958
1959 /* check tile status */
1960 visible_tile_check(line_t,y,x_index_fx,y_index,f3_pf_data_n);
1961
1962 if ((pos ==1) && ((((f3_line_ram[(0x6200/4) + (y>>1)]) >> 4) &0xf) > 0xb) && (f3_game == EACTION2)) line_t->alpha_mode[y] = 0x22; /*hack*/
1963
1964 /* set pixmap index */
1965 line_t->x_count[y]=x_index_fx & 0xffff;
1966 line_t->src_s[y]=src_s=(unsigned short *)srcbitmap->line[y_index];
1967 line_t->src_e[y]=&src_s[width_mask+1];
1968 line_t->src[y]=&src_s[x_index_fx>>16];
1969
1970 line_t->tsrc_s[y]=tsrc_s=(unsigned char *)transbitmap->line[y_index];
1971 line_t->tsrc[y]=&tsrc_s[x_index_fx>>16];
1972 }
1973
1974 if(y_zoom==line_t->x_zoom[y])
1975 y_index_fx += y_zoom;
1976 else
1977 y_index_fx += 0x10000;
1978
1979 y +=y_inc;
1980 }
1981 }
1982
1983 /******************************************************************************/
1984
f3_tilemap_draw(struct mame_bitmap * bitmap,const struct rectangle * cliprect)1985 static void f3_tilemap_draw(struct mame_bitmap *bitmap,
1986 const struct rectangle *cliprect)
1987 {
1988 int i,j,y,ys,ye;
1989 int y_start,y_end,y_start_next,y_end_next;
1990 UINT8 draw_line[256];
1991 INT16 draw_line_num[256];
1992
1993 UINT32 rot=0;
1994 #if DEBUG_F3
1995 int enable[4]={~0,~0,~0,~0};
1996
1997 if(deb_enable)
1998 {
1999 if (keyboard_pressed(KEYCODE_Z)) enable[0]=0;
2000 if (keyboard_pressed(KEYCODE_X)) enable[1]=0;
2001 if (keyboard_pressed(KEYCODE_C)) enable[2]=0;
2002 if (keyboard_pressed(KEYCODE_V)) enable[3]=0;
2003
2004 if (keyboard_pressed(KEYCODE_A)) sprite_pri_usage &= ~(1<<3);
2005 if (keyboard_pressed(KEYCODE_S)) sprite_pri_usage &= ~(1<<2);
2006 if (keyboard_pressed(KEYCODE_D)) sprite_pri_usage &= ~(1<<1);
2007 if (keyboard_pressed(KEYCODE_F)) sprite_pri_usage &= ~(1<<0);
2008 }
2009 #endif /*DEBUG_F3*/
2010
2011 if (flipscreen)
2012 {
2013 rot=ORIENTATION_FLIP_Y;
2014 ys=0;
2015 ye=232;
2016 }
2017 else
2018 {
2019 ys=24;
2020 ye=256;
2021 }
2022 /* ys=0;*/
2023 /* ye=256;*/
2024
2025 #if DEBUG_F3
2026 deb_loop=0;
2027 deb_alpha_cnt=0;
2028 #endif /*DEBUG_F3*/
2029
2030 y_start=ys;
2031 y_end=ye;
2032 memset(draw_line,0,256);
2033
2034 while(1)
2035 {
2036 static int alpha_level_last=-1;
2037 int pos;
2038 int pri[4],alpha_mode[4],alpha_mode_flag[4],alpha_level;
2039 UINT16 sprite_alpha;
2040 UINT8 sprite_alpha_check;
2041 UINT8 sprite_alpha_all_2a;
2042 int spri;
2043 int alpha;
2044 int layer_tmp[4];
2045
2046 int count_skip_layer=0;
2047 int sprite[5]={0,0,0,0,0};
2048 const struct f3_line_inf *line_t[4];
2049
2050
2051 /* find same status of scanlines */
2052 pri[0]=line_inf[0].pri[y_start];
2053 pri[1]=line_inf[1].pri[y_start];
2054 pri[2]=line_inf[2].pri[y_start];
2055 pri[3]=line_inf[3].pri[y_start];
2056 alpha_mode[0]=line_inf[0].alpha_mode[y_start];
2057 alpha_mode[1]=line_inf[1].alpha_mode[y_start];
2058 alpha_mode[2]=line_inf[2].alpha_mode[y_start];
2059 alpha_mode[3]=line_inf[3].alpha_mode[y_start];
2060 alpha_level=line_inf[0].alpha_level[y_start];
2061 spri=line_inf[0].spri[y_start];
2062 sprite_alpha=line_inf[0].sprite_alpha[y_start];
2063
2064 draw_line[y_start]=1;
2065 draw_line_num[i=0]=y_start;
2066 y_start_next=-1;
2067 y_end_next=-1;
2068 for(y=y_start+1;y<y_end;y++)
2069 {
2070 if(!draw_line[y])
2071 {
2072 if(pri[0]!=line_inf[0].pri[y]) y_end_next=y+1;
2073 else if(pri[1]!=line_inf[1].pri[y]) y_end_next=y+1;
2074 else if(pri[2]!=line_inf[2].pri[y]) y_end_next=y+1;
2075 else if(pri[3]!=line_inf[3].pri[y]) y_end_next=y+1;
2076 else if(alpha_mode[0]!=line_inf[0].alpha_mode[y]) y_end_next=y+1;
2077 else if(alpha_mode[1]!=line_inf[1].alpha_mode[y]) y_end_next=y+1;
2078 else if(alpha_mode[2]!=line_inf[2].alpha_mode[y]) y_end_next=y+1;
2079 else if(alpha_mode[3]!=line_inf[3].alpha_mode[y]) y_end_next=y+1;
2080 else if(alpha_level!=line_inf[0].alpha_level[y]) y_end_next=y+1;
2081 else if(spri!=line_inf[0].spri[y]) y_end_next=y+1;
2082 else if(sprite_alpha!=line_inf[0].sprite_alpha[y]) y_end_next=y+1;
2083 else
2084 {
2085 draw_line[y]=1;
2086 draw_line_num[++i]=y;
2087 continue;
2088 }
2089
2090 if(y_start_next<0) y_start_next=y;
2091 }
2092 }
2093 y_end=y_end_next;
2094 y_start=y_start_next;
2095 draw_line_num[++i]=-1;
2096
2097
2098 /* for clear top & bottom border */
2099 if(
2100 (!(pri[0]&0xf000) && !(pri[1]&0xf000) && !(pri[2]&0xf000) && !(pri[3]&0xf000)) ||
2101 ((pri[0]&0x800) && (pri[1]&0x800) && (pri[2]&0x800) && (pri[3]&0x800)) /*KTIGER2*/
2102 )
2103 {
2104 clear_scanlines(bitmap,46,320,draw_line_num,rot);
2105 if(y_start<0) break;
2106 continue;
2107 }
2108
2109 #if DEBUG_F3
2110 deb_loop++;
2111 #endif /*DEBUG_F3*/
2112
2113
2114 /* alpha blend */
2115 alpha_mode_flag[0]=alpha_mode[0]&~3;
2116 alpha_mode_flag[1]=alpha_mode[1]&~3;
2117 alpha_mode_flag[2]=alpha_mode[2]&~3;
2118 alpha_mode_flag[3]=alpha_mode[3]&~3;
2119 alpha_mode[0]&=3;
2120 alpha_mode[1]&=3;
2121 alpha_mode[2]&=3;
2122 alpha_mode[3]&=3;
2123 if( alpha_mode[0]>1 ||
2124 alpha_mode[1]>1 ||
2125 alpha_mode[2]>1 ||
2126 alpha_mode[3]>1 ||
2127 (sprite_alpha&0xff) != 0xff )
2128 {
2129 /* set alpha level */
2130 if(alpha_level!=alpha_level_last)
2131 {
2132 int al_s,al_d;
2133 int a=alpha_level;
2134 int b=(a>>8)&0xf;
2135 int c=(a>>4)&0xf;
2136 int d=(a>>0)&0xf;
2137 a>>=12;
2138
2139 /* b000 7000 */
2140 al_s = ( (15-d)*256) / 8;
2141 al_d = ( (15-b)*256) / 8;
2142 if(al_s>255) al_s = 255;
2143 if(al_d>255) al_d = 255;
2144 f3_alpha_level_3as = al_s;
2145 f3_alpha_level_3ad = al_d;
2146 f3_alpha_level_2as = al_d;
2147 f3_alpha_level_2ad = al_s;
2148
2149 al_s = ( (15-c)*256) / 8;
2150 al_d = ( (15-a)*256) / 8;
2151 if(al_s>255) al_s = 255;
2152 if(al_d>255) al_d = 255;
2153 f3_alpha_level_3bs = al_s;
2154 f3_alpha_level_3bd = al_d;
2155 f3_alpha_level_2bs = al_d;
2156 f3_alpha_level_2bd = al_s;
2157
2158 f3_alpha_set_level();
2159 alpha_level_last=alpha_level;
2160 }
2161
2162
2163 /* set sprite alpha mode */
2164 sprite_alpha_check=0;
2165 sprite_alpha_all_2a=1;
2166 dpix_sp[1]=0;
2167 dpix_sp[2]=0;
2168 dpix_sp[4]=0;
2169 dpix_sp[8]=0;
2170 for(i=0;i<4;i++) /* i = sprite priority offset */
2171 {
2172 UINT8 sprite_alpha_mode=(sprite_alpha>>(i*2))&3;
2173 UINT8 sftbit=1<<i;
2174 if(sprite_pri_usage&sftbit)
2175 {
2176 if(sprite_alpha_mode==1)
2177 {
2178 if(f3_alpha_level_2as==0 && f3_alpha_level_2ad==255) sprite_pri_usage&=~sftbit;
2179 else
2180 {
2181 dpix_sp[1<<i]=dpix_n[2];
2182 sprite_alpha_check|=sftbit;
2183 }
2184 }
2185 else if(sprite_alpha_mode==2)
2186 {
2187 if(sprite_alpha&0xff00)
2188 {
2189 if(f3_alpha_level_3as==0 && f3_alpha_level_3ad==255) sprite_pri_usage&=~sftbit;
2190 else
2191 {
2192 dpix_sp[1<<i]=dpix_n[3];
2193 sprite_alpha_check|=sftbit;
2194 sprite_alpha_all_2a=0;
2195 }
2196 }
2197 else
2198 {
2199 if(f3_alpha_level_3bs==0 && f3_alpha_level_3bd==255) sprite_pri_usage&=~sftbit;
2200 else
2201 {
2202 dpix_sp[1<<i]=dpix_n[5];
2203 sprite_alpha_check|=sftbit;
2204 sprite_alpha_all_2a=0;
2205 }
2206 }
2207 }
2208 }
2209 }
2210
2211
2212 /* check alpha level */
2213 for(i=0;i<4;i++) /* i = playfield num (pos) */
2214 {
2215 int alpha_type = (alpha_mode_flag[i]>>4)&3;
2216
2217 if(alpha_mode[i]==2)
2218 {
2219 if(alpha_type==1)
2220 {
2221 if (f3_alpha_level_2as==0 && f3_alpha_level_2ad==255) alpha_mode[i]=0;
2222 else if(f3_alpha_level_2as==255 && f3_alpha_level_2ad==0 ) alpha_mode[i]=1;
2223 }
2224 else if(alpha_type==2)
2225 {
2226 if (f3_alpha_level_2bs==0 && f3_alpha_level_2bd==255) alpha_mode[i]=0;
2227 else if(f3_alpha_level_2as==255 && f3_alpha_level_2ad==0 &&
2228 f3_alpha_level_2bs==255 && f3_alpha_level_2bd==0 ) alpha_mode[i]=1;
2229 }
2230 else if(alpha_type==3)
2231 {
2232 if (f3_alpha_level_2as==0 && f3_alpha_level_2ad==255 &&
2233 f3_alpha_level_2bs==0 && f3_alpha_level_2bd==255) alpha_mode[i]=0;
2234 else if(f3_alpha_level_2as==255 && f3_alpha_level_2ad==0 &&
2235 f3_alpha_level_2bs==255 && f3_alpha_level_2bd==0 ) alpha_mode[i]=1;
2236 }
2237 }
2238 else if(alpha_mode[i]==3)
2239 {
2240 if(alpha_type==1)
2241 {
2242 if (f3_alpha_level_3as==0 && f3_alpha_level_3ad==255) alpha_mode[i]=0;
2243 else if(f3_alpha_level_3as==255 && f3_alpha_level_3ad==0 ) alpha_mode[i]=1;
2244 }
2245 else if(alpha_type==2)
2246 {
2247 if (f3_alpha_level_3bs==0 && f3_alpha_level_3bd==255) alpha_mode[i]=0;
2248 else if(f3_alpha_level_3as==255 && f3_alpha_level_3ad==0 &&
2249 f3_alpha_level_3bs==255 && f3_alpha_level_3bd==0 ) alpha_mode[i]=1;
2250 }
2251 else if(alpha_type==3)
2252 {
2253 if (f3_alpha_level_3as==0 && f3_alpha_level_3ad==255 &&
2254 f3_alpha_level_3bs==0 && f3_alpha_level_3bd==255) alpha_mode[i]=0;
2255 else if(f3_alpha_level_3as==255 && f3_alpha_level_3ad==0 &&
2256 f3_alpha_level_3bs==255 && f3_alpha_level_3bd==0 ) alpha_mode[i]=1;
2257 }
2258 }
2259 }
2260
2261
2262 /* enable/disable alpha blend */
2263 if (alpha_disable)
2264 {
2265 if(alpha_mode[0]>1) alpha_mode[0]=1;
2266 if(alpha_mode[1]>1) alpha_mode[1]=1;
2267 if(alpha_mode[2]>1) alpha_mode[2]=1;
2268 if(alpha_mode[3]>1) alpha_mode[3]=1;
2269 sprite_alpha_check=0;
2270 dpix_sp[1]=0;
2271 dpix_sp[2]=0;
2272 dpix_sp[4]=0;
2273 dpix_sp[8]=0;
2274 }
2275 else
2276 {
2277 if ( (alpha_mode[0]==1 || alpha_mode[0]==2 || !alpha_mode[0]) &&
2278 (alpha_mode[1]==1 || alpha_mode[1]==2 || !alpha_mode[1]) &&
2279 (alpha_mode[2]==1 || alpha_mode[2]==2 || !alpha_mode[2]) &&
2280 (alpha_mode[3]==1 || alpha_mode[3]==2 || !alpha_mode[3]) &&
2281 sprite_alpha_all_2a )
2282 {
2283 int alpha_type = (alpha_mode_flag[0] | alpha_mode_flag[1] | alpha_mode_flag[2] | alpha_mode_flag[3])&0x30;
2284 if( (alpha_type==0x10 && f3_alpha_level_2as==255) ||
2285 (alpha_type==0x20 && f3_alpha_level_2as==255 && f3_alpha_level_2bs==255) ||
2286 (alpha_type==0x30 && f3_alpha_level_2as==255 && f3_alpha_level_2bs==255) )
2287 {
2288 if(alpha_mode[0]>1) alpha_mode[0]=1;
2289 if(alpha_mode[1]>1) alpha_mode[1]=1;
2290 if(alpha_mode[2]>1) alpha_mode[2]=1;
2291 if(alpha_mode[3]>1) alpha_mode[3]=1;
2292 sprite_alpha_check=0;
2293 dpix_sp[1]=0;
2294 dpix_sp[2]=0;
2295 dpix_sp[4]=0;
2296 dpix_sp[8]=0;
2297 }
2298 }
2299 }
2300 }
2301 else
2302 {
2303 sprite_alpha_check=0;
2304 dpix_sp[1]=0;
2305 dpix_sp[2]=0;
2306 dpix_sp[4]=0;
2307 dpix_sp[8]=0;
2308 }
2309
2310
2311
2312 /* set scanline priority */
2313 {
2314 int pri_max_opa=-1;
2315 for(i=0;i<4;i++) /* i = playfield num (pos) */
2316 {
2317 int p0=pri[i];
2318 int pri_sl1=p0&0x0f;
2319 int pri_sl2=(p0&0xf0)>>4;
2320
2321 if (f3_game == ARKRETRN && (p0&0xf00)==0x300) /*???*/
2322 pri_sl1=pri_sl2<pri_sl1 ? pri_sl2 : pri_sl1;
2323
2324 layer_tmp[i]=i + (pri_sl1<<2);
2325
2326 if(!alpha_mode[i]
2327 #if DEBUG_F3
2328 || !enable[i]
2329 #endif /*DEBUG_F3*/
2330 /*|| !(pri[i]&0x2000)*/)
2331 {
2332 layer_tmp[i]|=0x40;
2333 count_skip_layer++;
2334 }
2335 else if(alpha_mode[i]==1 && (alpha_mode_flag[i]&0x80))
2336 {
2337 if(layer_tmp[i]>pri_max_opa) pri_max_opa=layer_tmp[i];
2338 }
2339 }
2340
2341 if(pri_max_opa!=-1)
2342 {
2343 if(pri_max_opa>layer_tmp[0]) {layer_tmp[0]|=0x40;count_skip_layer++;}
2344 if(pri_max_opa>layer_tmp[1]) {layer_tmp[1]|=0x40;count_skip_layer++;}
2345 if(pri_max_opa>layer_tmp[2]) {layer_tmp[2]|=0x40;count_skip_layer++;}
2346 if(pri_max_opa>layer_tmp[3]) {layer_tmp[3]|=0x40;count_skip_layer++;}
2347 }
2348 }
2349
2350
2351 /* sort layer_tmp */
2352 for(i=0;i<3;i++)
2353 {
2354 for(j=i+1;j<4;j++)
2355 {
2356 if(layer_tmp[i]<layer_tmp[j])
2357 {
2358 int temp = layer_tmp[i];
2359 layer_tmp[i] = layer_tmp[j];
2360 layer_tmp[j] = temp;
2361 }
2362 }
2363 }
2364
2365
2366 /* check sprite & layer priority */
2367 {
2368 int l0,l1,l2,l3;
2369 int pri_sp[4];
2370
2371 l0=layer_tmp[0]>>2;
2372 l1=layer_tmp[1]>>2;
2373 l2=layer_tmp[2]>>2;
2374 l3=layer_tmp[3]>>2;
2375
2376 pri_sp[0]=spri&0xf;
2377 pri_sp[1]=(spri>>4)&0xf;
2378 pri_sp[2]=(spri>>8)&0xf;
2379 pri_sp[3]=spri>>12;
2380
2381 for(i=0;i<4;i++) /* i = sprite priority offset */
2382 {
2383 int sp,sflg=1<<i;
2384 if(!(sprite_pri_usage & sflg)) continue;
2385 sp=pri_sp[i];
2386
2387 /*
2388 sprite priority==playfield priority
2389 BUBSYMPH (title) ---> sprite
2390 DARIUSG (ZONE V' BOSS) ---> playfield
2391 */
2392
2393 if (f3_game == BUBSYMPH ) sp++; /*BUBSYMPH (title)*/
2394
2395 if( sp>l0) sprite[0]|=sflg;
2396 else if(sp<=l0 && sp>l1) sprite[1]|=sflg;
2397 else if(sp<=l1 && sp>l2) sprite[2]|=sflg;
2398 else if(sp<=l2 && sp>l3) sprite[3]|=sflg;
2399 else if(sp<=l3 ) sprite[4]|=sflg;
2400 }
2401 }
2402
2403
2404 /* draw scanlines */
2405 alpha=0;
2406 for(i=count_skip_layer;i<4;i++)
2407 {
2408 pos=layer_tmp[i]&3;
2409 line_t[i]=&line_inf[pos];
2410
2411 if(sprite[i]&sprite_alpha_check) alpha=1;
2412 else if(!alpha) sprite[i]|=0x100;
2413
2414 if(alpha_mode[pos]>1)
2415 {
2416 int alpha_type=(((alpha_mode_flag[pos]>>4)&3)-1)*2;
2417 dpix_lp[i]=dpix_n[alpha_mode[pos]+alpha_type];
2418 alpha=1;
2419 }
2420 else
2421 {
2422 #if DEBUG_F3
2423 if(!alpha_mode[pos]) usrintf_showmessage("layer priority error");
2424 #endif /*DEBUG_F3*/
2425 if(alpha) dpix_lp[i]=dpix_n[1];
2426 else dpix_lp[i]=dpix_n[0];
2427 }
2428 }
2429 if(sprite[4]&sprite_alpha_check) alpha=1;
2430 else if(!alpha) sprite[4]|=0x100;
2431
2432 #if DEBUG_F3
2433 if(alpha) deb_alpha_cnt++;
2434 if(deb_enable)
2435 sprintf(deb_buf[8],"spr:%3x %3x %3x %3x %3x",sprite[0],
2436 sprite[1],
2437 sprite[2],
2438 sprite[3],
2439 sprite[4]);
2440 #endif /*DEBUG_F3*/
2441
2442 f3_drawscanlines(bitmap,46,320,draw_line_num,line_t,sprite,rot,count_skip_layer);
2443 if(y_start<0) break;
2444 }
2445 }
2446
2447 /******************************************************************************/
2448
f3_update_pivot_layer(void)2449 static void f3_update_pivot_layer(void)
2450 {
2451 struct rectangle pivot_clip;
2452 int tile,i,pivot_base;
2453
2454 /* A poor way to guess if the pivot layer is enabled, but quicker than
2455 parsing control ram. */
2456 int ctrl = f3_line_ram[0x180f]&0xa000; /* SpcInvDX sets only this address */
2457 int ctrl2 = f3_line_ram[0x1870]&0xa0000000; /* SpcInvDX flipscreen */
2458 int ctrl3 = f3_line_ram[0x1820]&0xa000; /* Other games set the whole range 0x6000-0x61ff */
2459 int ctrl4 = f3_line_ram[0x1840]&0xa000; /* ScFinals only sets a small range over the screen area */
2460
2461 /* Quickly decide whether to process the rest of the pivot layer */
2462 if (!(ctrl || ctrl2 || ctrl3 || ctrl4)) {
2463 tilemap_set_enable(pixel_layer,0);
2464 return;
2465 }
2466 tilemap_set_enable(pixel_layer,1);
2467
2468 if (flipscreen) {
2469 tilemap_set_scrollx( pixel_layer,0,(f3_control_1[2]>>16)-(512-320)-16);
2470 tilemap_set_scrolly( pixel_layer,0,-(f3_control_1[2]&0xff));
2471 } else {
2472 tilemap_set_scrollx( pixel_layer,0,-(f3_control_1[2]>>16)-5);
2473 tilemap_set_scrolly( pixel_layer,0,-(f3_control_1[2]&0xff));
2474 }
2475
2476 /* Clip top scanlines according to line ram - Bubble Memories makes use of this */
2477 pivot_clip.min_x=0;/*Machine->visible_area.min_x;*/
2478 pivot_clip.max_x=512;/*Machine->visible_area.max_x;*/
2479 pivot_clip.min_y=Machine->visible_area.min_y;
2480 pivot_clip.max_y=Machine->visible_area.max_y;
2481 if (flipscreen)
2482 pivot_base=0x61fe;
2483 else
2484 pivot_base=0x6000;
2485
2486 for (i=0; i<256; i++) {
2487 /* Loop through until first visible line */
2488 if (pivot_base&2) {
2489 if ((f3_line_ram[pivot_base/4]&0xa000)==0xa000) {
2490 pivot_clip.min_y=i;
2491 i=256;
2492 }
2493 } else {
2494 if ((f3_line_ram[pivot_base/4]&0xa0000000)==0xa0000000) {
2495 pivot_clip.min_y=i;
2496 i=256;
2497 }
2498 }
2499 if (flipscreen) pivot_base-=2; else pivot_base+=2;
2500 }
2501
2502 if (!flipscreen)
2503 pixel_layer_clip = pivot_clip;
2504
2505 /* Decode chars & mark tilemap dirty */
2506 if (pivot_changed)
2507 for (tile = 0;tile < 2048;tile++)
2508 if (pivot_dirty[tile]) {
2509 decodechar(Machine->gfx[3],tile,(UINT8 *)f3_pivot_ram,Machine->drv->gfxdecodeinfo[3].gfxlayout);
2510 tilemap_mark_tile_dirty(pixel_layer,tile);
2511 pivot_dirty[tile]=0;
2512 }
2513 pivot_changed=0;
2514 }
2515
2516 /******************************************************************************/
2517
f3_draw_vram_layer(struct mame_bitmap * bitmap,const struct rectangle * cliprect)2518 static void f3_draw_vram_layer(struct mame_bitmap *bitmap,const struct rectangle *cliprect)
2519 {
2520 int offs,mx,my,tile,color,fx,fy,sx,sy;
2521
2522 sx=(f3_control_1[2]>>16)+5;
2523 sy=f3_control_1[2]&0xffff;
2524
2525 for (offs = 0; offs < 0x2000 ;offs += 2)
2526 {
2527 mx = (offs%128)/2;
2528 my = offs/128;
2529
2530 if (offs&2)
2531 tile = videoram32[offs>>2]&0xffff;
2532 else
2533 tile = videoram32[offs>>2]>>16;
2534
2535 /* Transparency hack, 6010 for PB2, 1205 for PB3 */
2536 if (tile==0x6010 || tile==0x1205) continue;
2537
2538 color = (tile>>9) &0x3f;
2539 fx = tile&0x0100;
2540 fy = tile&0x8000;
2541
2542 tile&=0xff;
2543 if (!tile) continue;
2544
2545 /* Graphics flip */
2546 if (flipscreen) {
2547 if (fx) fx=0; else fx=1;
2548 if (fy) fy=0; else fy=1;
2549 drawgfx(bitmap,Machine->gfx[0],
2550 tile,
2551 color,
2552 fx,fy,
2553 504+17-(((8*mx)+sx)&0x1ff),504-(((8*my)+sy)&0x1ff),
2554 cliprect,TRANSPARENCY_PEN,0);
2555 }
2556 else
2557 drawgfx(bitmap,Machine->gfx[0],
2558 tile,
2559 color,
2560 fx,fy,
2561 ((8*mx)+sx)&0x1ff,((8*my)+sy)&0x1ff,
2562 cliprect,TRANSPARENCY_PEN,0);
2563 }
2564 }
2565
2566 /******************************************************************************/
2567
2568 #define PSET_T \
2569 c = *source; \
2570 if(c) \
2571 { \
2572 p=*pri; \
2573 if(!p || p==0xff) \
2574 { \
2575 *dest = pal[c]; \
2576 *pri = pri_dst; \
2577 } \
2578 }
2579
2580 #define PSET_O \
2581 p=*pri; \
2582 if(!p || p==0xff) \
2583 { \
2584 *dest = pal[*source]; \
2585 *pri = pri_dst; \
2586 }
2587
2588 #define NEXT_P \
2589 source += dx; \
2590 dest++; \
2591 pri++;
2592
f3_drawgfx(struct mame_bitmap * dest_bmp,const struct GfxElement * gfx,unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,const struct rectangle * clip,UINT8 pri_dst)2593 static INLINE void f3_drawgfx( struct mame_bitmap *dest_bmp,const struct GfxElement *gfx,
2594 unsigned int code,
2595 unsigned int color,
2596 int flipx,int flipy,
2597 int sx,int sy,
2598 const struct rectangle *clip,
2599 UINT8 pri_dst)
2600 {
2601 struct rectangle myclip;
2602
2603 pri_dst=1<<pri_dst;
2604
2605 /* KW 991012 -- Added code to force clip to bitmap boundary */
2606 if(clip)
2607 {
2608 myclip.min_x = clip->min_x;
2609 myclip.max_x = clip->max_x;
2610 myclip.min_y = clip->min_y;
2611 myclip.max_y = clip->max_y;
2612
2613 if (myclip.min_x < 0) myclip.min_x = 0;
2614 if (myclip.max_x >= dest_bmp->width) myclip.max_x = dest_bmp->width-1;
2615 if (myclip.min_y < 0) myclip.min_y = 0;
2616 if (myclip.max_y >= dest_bmp->height) myclip.max_y = dest_bmp->height-1;
2617
2618 clip=&myclip;
2619 }
2620
2621
2622 if( gfx && gfx->colortable )
2623 {
2624 const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
2625 /* int palBase = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)] - Machine->remapped_colortable;*/
2626 int source_base = (code % gfx->total_elements) * 16;
2627
2628 {
2629 /* compute sprite increment per screen pixel */
2630 int dx = 1;
2631 int dy = 1;
2632
2633 int ex = sx+16;
2634 int ey = sy+16;
2635
2636 int x_index_base;
2637 int y_index;
2638
2639 if( flipx )
2640 {
2641 x_index_base = 15;
2642 dx = -1;
2643 }
2644 else
2645 {
2646 x_index_base = 0;
2647 }
2648
2649 if( flipy )
2650 {
2651 y_index = 15;
2652 dy = -1;
2653 }
2654 else
2655 {
2656 y_index = 0;
2657 }
2658
2659 if( clip )
2660 {
2661 if( sx < clip->min_x)
2662 { /* clip left */
2663 int pixels = clip->min_x-sx;
2664 sx += pixels;
2665 x_index_base += pixels*dx;
2666 }
2667 if( sy < clip->min_y )
2668 { /* clip top */
2669 int pixels = clip->min_y-sy;
2670 sy += pixels;
2671 y_index += pixels*dy;
2672 }
2673 /* NS 980211 - fixed incorrect clipping */
2674 if( ex > clip->max_x+1 )
2675 { /* clip right */
2676 int pixels = ex-clip->max_x-1;
2677 ex -= pixels;
2678 }
2679 if( ey > clip->max_y+1 )
2680 { /* clip bottom */
2681 int pixels = ey-clip->max_y-1;
2682 ey -= pixels;
2683 }
2684 }
2685
2686 if( ex>sx && ey>sy)
2687 { /* skip if inner loop doesn't draw anything */
2688 /* if (dest_bmp->depth == 32)*/
2689 {
2690 int y=ey-sy;
2691 int x=(ex-sx-1)|(tile_opaque_sp[code]<<4);
2692 UINT8 *source0 = gfx->gfxdata + (source_base+y_index) * 16 + x_index_base;
2693 UINT32 *dest0 = (UINT32 *)dest_bmp->line[sy]+sx;
2694 UINT8 *pri0 = (UINT8 *)pri_alp_bitmap->line[sy]+sx;
2695 int yadv = dest_bmp->rowpixels;
2696 dy=dy*16;
2697 while(1)
2698 {
2699 UINT8 *source = source0;
2700 UINT32 *dest = dest0;
2701 UINT8 *pri = pri0;
2702
2703 switch(x)
2704 {
2705 int c;
2706 UINT8 p;
2707 case 31: PSET_O NEXT_P
2708 case 30: PSET_O NEXT_P
2709 case 29: PSET_O NEXT_P
2710 case 28: PSET_O NEXT_P
2711 case 27: PSET_O NEXT_P
2712 case 26: PSET_O NEXT_P
2713 case 25: PSET_O NEXT_P
2714 case 24: PSET_O NEXT_P
2715 case 23: PSET_O NEXT_P
2716 case 22: PSET_O NEXT_P
2717 case 21: PSET_O NEXT_P
2718 case 20: PSET_O NEXT_P
2719 case 19: PSET_O NEXT_P
2720 case 18: PSET_O NEXT_P
2721 case 17: PSET_O NEXT_P
2722 case 16: PSET_O break;
2723
2724 case 15: PSET_T NEXT_P
2725 case 14: PSET_T NEXT_P
2726 case 13: PSET_T NEXT_P
2727 case 12: PSET_T NEXT_P
2728 case 11: PSET_T NEXT_P
2729 case 10: PSET_T NEXT_P
2730 case 9: PSET_T NEXT_P
2731 case 8: PSET_T NEXT_P
2732 case 7: PSET_T NEXT_P
2733 case 6: PSET_T NEXT_P
2734 case 5: PSET_T NEXT_P
2735 case 4: PSET_T NEXT_P
2736 case 3: PSET_T NEXT_P
2737 case 2: PSET_T NEXT_P
2738 case 1: PSET_T NEXT_P
2739 case 0: PSET_T
2740 }
2741
2742 if(!(--y)) break;
2743 source0 += dy;
2744 dest0+=yadv;
2745 pri0+=yadv;
2746 }
2747 }
2748 }
2749 }
2750 }
2751 }
2752 #undef PSET_T
2753 #undef PSET_O
2754 #undef NEXT_P
2755
2756
f3_drawgfxzoom(struct mame_bitmap * dest_bmp,const struct GfxElement * gfx,unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,const struct rectangle * clip,int scalex,int scaley,UINT8 pri_dst)2757 static INLINE void f3_drawgfxzoom( struct mame_bitmap *dest_bmp,const struct GfxElement *gfx,
2758 unsigned int code,
2759 unsigned int color,
2760 int flipx,int flipy,
2761 int sx,int sy,
2762 const struct rectangle *clip,
2763 int scalex, int scaley,
2764 UINT8 pri_dst)
2765 {
2766 struct rectangle myclip;
2767
2768 pri_dst=1<<pri_dst;
2769
2770 /* KW 991012 -- Added code to force clip to bitmap boundary */
2771 if(clip)
2772 {
2773 myclip.min_x = clip->min_x;
2774 myclip.max_x = clip->max_x;
2775 myclip.min_y = clip->min_y;
2776 myclip.max_y = clip->max_y;
2777
2778 if (myclip.min_x < 0) myclip.min_x = 0;
2779 if (myclip.max_x >= dest_bmp->width) myclip.max_x = dest_bmp->width-1;
2780 if (myclip.min_y < 0) myclip.min_y = 0;
2781 if (myclip.max_y >= dest_bmp->height) myclip.max_y = dest_bmp->height-1;
2782
2783 clip=&myclip;
2784 }
2785
2786
2787 if( gfx && gfx->colortable )
2788 {
2789 const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
2790 /* int palBase = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)] - Machine->remapped_colortable;*/
2791 int source_base = (code % gfx->total_elements) * 16;
2792
2793 {
2794 /* compute sprite increment per screen pixel */
2795 int dx = (16<<16)/scalex;
2796 int dy = (16<<16)/scaley;
2797
2798 int ex = sx+scalex;
2799 int ey = sy+scaley;
2800
2801 int x_index_base;
2802 int y_index;
2803
2804 if( flipx )
2805 {
2806 x_index_base = (scalex-1)*dx;
2807 dx = -dx;
2808 }
2809 else
2810 {
2811 x_index_base = 0;
2812 }
2813
2814 if( flipy )
2815 {
2816 y_index = (scaley-1)*dy;
2817 dy = -dy;
2818 }
2819 else
2820 {
2821 y_index = 0;
2822 }
2823
2824 if( clip )
2825 {
2826 if( sx < clip->min_x)
2827 { /* clip left */
2828 int pixels = clip->min_x-sx;
2829 sx += pixels;
2830 x_index_base += pixels*dx;
2831 }
2832 if( sy < clip->min_y )
2833 { /* clip top */
2834 int pixels = clip->min_y-sy;
2835 sy += pixels;
2836 y_index += pixels*dy;
2837 }
2838 /* NS 980211 - fixed incorrect clipping */
2839 if( ex > clip->max_x+1 )
2840 { /* clip right */
2841 int pixels = ex-clip->max_x-1;
2842 ex -= pixels;
2843 }
2844 if( ey > clip->max_y+1 )
2845 { /* clip bottom */
2846 int pixels = ey-clip->max_y-1;
2847 ey -= pixels;
2848 }
2849 }
2850
2851 if( ex>sx )
2852 { /* skip if inner loop doesn't draw anything */
2853 /* if (dest_bmp->depth == 32)*/
2854 {
2855 int y;
2856 for( y=sy; y<ey; y++ )
2857 {
2858 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * 16;
2859 UINT32 *dest = (UINT32 *)dest_bmp->line[y];
2860 UINT8 *pri = pri_alp_bitmap->line[y];
2861
2862 int x, x_index = x_index_base;
2863 for( x=sx; x<ex; x++ )
2864 {
2865 int c = source[x_index>>16];
2866 if(c)
2867 {
2868 UINT8 p=pri[x];
2869 if (p == 0 || p == 0xff)
2870 {
2871 dest[x] = pal[c];
2872 pri[x] = pri_dst;
2873 }
2874 }
2875 x_index += dx;
2876 }
2877 y_index += dy;
2878 }
2879 }
2880 }
2881 }
2882 }
2883 }
2884
2885
2886 #define CALC_ZOOM(p) { \
2887 p##_addition = 0x100 - block_zoom_##p + p##_addition_left; \
2888 p##_addition_left = p##_addition & 0xf; \
2889 p##_addition = p##_addition >> 4; \
2890 /*zoom##p = p##_addition << 12;*/ \
2891 }
2892
get_sprite_info(const data32_t * spriteram32_ptr)2893 static void get_sprite_info(const data32_t *spriteram32_ptr)
2894 {
2895 const int min_x=Machine->visible_area.min_x,max_x=Machine->visible_area.max_x;
2896 const int min_y=Machine->visible_area.min_y,max_y=Machine->visible_area.max_y;
2897 int offs,spritecont,flipx,flipy,old_x,old_y,color,x,y;
2898 int sprite,global_x=0,global_y=0,subglobal_x=0,subglobal_y=0;
2899 int block_x=0, block_y=0;
2900 int last_color=0,last_x=0,last_y=0,block_zoom_x=0,block_zoom_y=0;
2901 int this_x,this_y;
2902 int y_addition=16, x_addition=16;
2903 int multi=0;
2904 int sprite_top;
2905
2906 int x_addition_left = 8, y_addition_left = 8;
2907
2908 struct tempsprite *sprite_ptr = spritelist;
2909
2910 color=0;
2911 flipx=flipy=0;
2912 old_y=old_x=0;
2913 y=x=0;
2914
2915 sprite_top=0x1000;
2916 for (offs = 0; offs < sprite_top; offs += 4)
2917 {
2918 /* Check if special command bit is set */
2919 if (spriteram32_ptr[offs+1] & 0x8000) {
2920 data32_t cntrl=(spriteram32_ptr[offs+2])&0xffff;
2921 flipscreen=cntrl&0x2000;
2922
2923 /* cntrl&0x1000 = disabled? (From F2 driver, doesn't seem used anywhere)
2924 cntrl&0x0010 = ???
2925 cntrl&0x0020 = ???
2926 */
2927
2928 /* Sprite bank select */
2929 if (cntrl&1) {
2930 offs=offs|0x2000;
2931 sprite_top=sprite_top|0x2000;
2932 }
2933 continue;
2934 }
2935
2936 /* Check if the sprite list jump command bit is set */
2937 if ((spriteram32_ptr[offs+3]>>16) & 0x8000) {
2938 data32_t jump = (spriteram32_ptr[offs+3]>>16)&0x3ff;
2939
2940 offs=((offs&0x2000)|((jump<<4)/4));
2941 continue;
2942 }
2943
2944 /* Set global sprite scroll */
2945 if (((spriteram32_ptr[offs+1]>>16) & 0xf000) == 0xa000) {
2946 global_x = (spriteram32_ptr[offs+1]>>16) & 0xfff;
2947 if (global_x >= 0x800) global_x -= 0x1000;
2948 global_y = spriteram32_ptr[offs+1] & 0xfff;
2949 if (global_y >= 0x800) global_y -= 0x1000;
2950 }
2951
2952 /* And sub-global sprite scroll */
2953 if (((spriteram32_ptr[offs+1]>>16) & 0xf000) == 0x5000) {
2954 subglobal_x = (spriteram32_ptr[offs+1]>>16) & 0xfff;
2955 if (subglobal_x >= 0x800) subglobal_x -= 0x1000;
2956 subglobal_y = spriteram32_ptr[offs+1] & 0xfff;
2957 if (subglobal_y >= 0x800) subglobal_y -= 0x1000;
2958 }
2959
2960 if (((spriteram32_ptr[offs+1]>>16) & 0xf000) == 0xb000) {
2961 subglobal_x = (spriteram32_ptr[offs+1]>>16) & 0xfff;
2962 if (subglobal_x >= 0x800) subglobal_x -= 0x1000;
2963 subglobal_y = spriteram32_ptr[offs+1] & 0xfff;
2964 if (subglobal_y >= 0x800) subglobal_y -= 0x1000;
2965 global_y=subglobal_y;
2966 global_x=subglobal_x;
2967 }
2968
2969 /* A real sprite to process! */
2970 sprite = (spriteram32_ptr[offs]>>16) | ((spriteram32_ptr[offs+2]&1)<<16);
2971 spritecont = spriteram32_ptr[offs+2]>>24;
2972
2973 /* These games either don't set the XY control bits properly (68020 bug?), or
2974 have some different mode from the others */
2975 #ifdef DARIUSG_KLUDGE
2976 if (f3_game==DARIUSG || f3_game==GEKIRIDO || f3_game==CLEOPATR)
2977 multi=spritecont&0xf0;
2978 #endif
2979
2980 /* Check if this sprite is part of a continued block */
2981 if (multi) {
2982 /* Bit 0x4 is 'use previous colour' for this block part */
2983 if (spritecont&0x4) color=last_color;
2984 else color=(spriteram32_ptr[offs+2]>>16)&0xff;
2985
2986 #ifdef DARIUSG_KLUDGE
2987 if (f3_game==DARIUSG || f3_game==GEKIRIDO || f3_game==CLEOPATR) {
2988 /* Adjust X Position */
2989 if ((spritecont & 0x40) == 0) {
2990 if (spritecont & 0x4) {
2991 x = block_x;
2992 } else {
2993 this_x = spriteram32_ptr[offs+1]>>16;
2994 if (this_x&0x800) this_x= 0 - (0x800 - (this_x&0x7ff)); else this_x&=0x7ff;
2995
2996 if ((spriteram32_ptr[offs+1]>>16)&0x8000) {
2997 this_x+=0;
2998 } else if ((spriteram32_ptr[offs+1]>>16)&0x4000) {
2999 /* Ignore subglobal (but apply global) */
3000 this_x+=global_x;
3001 } else { /* Apply both scroll offsets */
3002 this_x+=global_x+subglobal_x;
3003 }
3004
3005 x = block_x = this_x;
3006 }
3007 x_addition_left = 8;
3008 CALC_ZOOM(x)
3009 }
3010 else if ((spritecont & 0x80) != 0) {
3011 x = last_x+x_addition;
3012 CALC_ZOOM(x)
3013 }
3014
3015 /* Adjust Y Position */
3016 if ((spritecont & 0x10) == 0) {
3017 if (spritecont & 0x4) {
3018 y = block_y;
3019 } else {
3020 this_y = spriteram32_ptr[offs+1]&0xffff;
3021 if (this_y&0x800) this_y= 0 - (0x800 - (this_y&0x7ff)); else this_y&=0x7ff;
3022
3023 if ((spriteram32_ptr[offs+1]>>16)&0x8000) {
3024 this_y+=0;
3025 } else if ((spriteram32_ptr[offs+1]>>16)&0x4000) {
3026 /* Ignore subglobal (but apply global) */
3027 this_y+=global_y;
3028 } else { /* Apply both scroll offsets */
3029 this_y+=global_y+subglobal_y;
3030 }
3031
3032 y = block_y = this_y;
3033 }
3034 y_addition_left = 8;
3035 CALC_ZOOM(y)
3036 }
3037 else if ((spritecont & 0x20) != 0) {
3038 y = last_y+y_addition;
3039 CALC_ZOOM(y)
3040 }
3041 } else
3042 #endif
3043 {
3044 /* Adjust X Position */
3045 if ((spritecont & 0x40) == 0) {
3046 x = block_x;
3047 x_addition_left = 8;
3048 CALC_ZOOM(x)
3049 }
3050 else if ((spritecont & 0x80) != 0) {
3051 x = last_x+x_addition;
3052 CALC_ZOOM(x)
3053 }
3054 /* Adjust Y Position */
3055 if ((spritecont & 0x10) == 0) {
3056 y = block_y;
3057 y_addition_left = 8;
3058 CALC_ZOOM(y)
3059 }
3060 else if ((spritecont & 0x20) != 0) {
3061 y = last_y+y_addition;
3062 CALC_ZOOM(y)
3063 }
3064 /* Both zero = reread block latch? */
3065 }
3066 }
3067 /* Else this sprite is the possible start of a block */
3068 else {
3069 color = (spriteram32_ptr[offs+2]>>16)&0xff;
3070 last_color=color;
3071
3072 /* Sprite positioning */
3073 this_y = spriteram32_ptr[offs+1]&0xffff;
3074 this_x = spriteram32_ptr[offs+1]>>16;
3075 if (this_y&0x800) this_y= 0 - (0x800 - (this_y&0x7ff)); else this_y&=0x7ff;
3076 if (this_x&0x800) this_x= 0 - (0x800 - (this_x&0x7ff)); else this_x&=0x7ff;
3077
3078 /* Ignore both scroll offsets for this block */
3079 if ((spriteram32_ptr[offs+1]>>16)&0x8000) {
3080 this_x+=0;
3081 this_y+=0;
3082 } else if ((spriteram32_ptr[offs+1]>>16)&0x4000) {
3083 /* Ignore subglobal (but apply global) */
3084 this_x+=global_x;
3085 this_y+=global_y;
3086 } else { /* Apply both scroll offsets */
3087 this_x+=global_x+subglobal_x;
3088 this_y+=global_y+subglobal_y;
3089 }
3090
3091 block_y = y = this_y;
3092 block_x = x = this_x;
3093
3094 block_zoom_x=spriteram32_ptr[offs];
3095 block_zoom_y=(block_zoom_x>>8)&0xff;
3096 block_zoom_x&=0xff;
3097
3098 x_addition_left = 8;
3099 CALC_ZOOM(x)
3100
3101 y_addition_left = 8;
3102 CALC_ZOOM(y)
3103 }
3104
3105 /* These features are common to sprite and block parts */
3106 flipx = spritecont&0x1;
3107 flipy = spritecont&0x2;
3108 multi = spritecont&0x8;
3109 last_x=x;
3110 last_y=y;
3111
3112 if (!sprite) continue;
3113 if (!x_addition || !y_addition) continue;
3114
3115 if (flipscreen)
3116 {
3117 int tx,ty;
3118 if (f3_game == GSEEKER )
3119 {
3120 tx = 512-x_addition-x-44;
3121 ty = 256-y_addition-y+17;
3122 }
3123 else
3124 {
3125 tx = 512-x_addition-x;
3126 ty = 256-y_addition-y;
3127 }
3128 if (tx+x_addition<=min_x || tx>max_x || ty+y_addition<=min_y || ty>max_y) continue;
3129 sprite_ptr->x = tx;
3130 sprite_ptr->y = ty;
3131 sprite_ptr->flipx = !flipx;
3132 sprite_ptr->flipy = !flipy;
3133 }
3134 else
3135 {
3136 if (x+x_addition<=min_x || x>max_x || y+y_addition<=min_y || y>max_y) continue;
3137 sprite_ptr->x = x;
3138 sprite_ptr->y = y;
3139 sprite_ptr->flipx = flipx;
3140 sprite_ptr->flipy = flipy;
3141 }
3142
3143
3144 sprite_ptr->code = sprite;
3145 sprite_ptr->color = color;
3146 sprite_ptr->zoomx = x_addition;
3147 sprite_ptr->zoomy = y_addition;
3148 sprite_ptr->pri = (color & 0xc0) >> 6;
3149 sprite_ptr++;
3150 }
3151 sprite_end = sprite_ptr;
3152 }
3153 #undef CALC_ZOOM
3154
3155
f3_drawsprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)3156 static void f3_drawsprites(struct mame_bitmap *bitmap,const struct rectangle *cliprect)
3157 {
3158 const struct tempsprite *sprite_ptr;
3159 const struct GfxElement *sprite_gfx = Machine->gfx[2];
3160
3161 sprite_ptr = sprite_end;
3162 sprite_pri_usage=0;
3163 while (sprite_ptr != spritelist)
3164 {
3165 int pri;
3166 sprite_ptr--;
3167
3168 pri=sprite_ptr->pri;
3169 sprite_pri_usage|=1<<pri;
3170
3171 if(sprite_ptr->zoomx==16 && sprite_ptr->zoomy==16)
3172 f3_drawgfx(bitmap,sprite_gfx,
3173 sprite_ptr->code,
3174 sprite_ptr->color,
3175 sprite_ptr->flipx,sprite_ptr->flipy,
3176 sprite_ptr->x,sprite_ptr->y,
3177 cliprect,
3178 pri);
3179 else
3180 f3_drawgfxzoom(bitmap,sprite_gfx,
3181 sprite_ptr->code,
3182 sprite_ptr->color,
3183 sprite_ptr->flipx,sprite_ptr->flipy,
3184 sprite_ptr->x,sprite_ptr->y,
3185 cliprect,
3186 sprite_ptr->zoomx,sprite_ptr->zoomy,
3187 pri);
3188 }
3189 }
3190
3191 /******************************************************************************/
3192
VIDEO_UPDATE(f3)3193 VIDEO_UPDATE( f3 )
3194 {
3195 struct rectangle tempclip;
3196 unsigned int sy_fix[4],sx_fix[4];
3197 int tile;
3198 #if DEBUG_F3
3199 static int deb_sc_x=0,deb_sc_y=0;
3200 #endif /*DEBUG_F3*/
3201 struct mame_bitmap *priority_bitmap_bak;
3202
3203 skip_this_frame=0;
3204 tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
3205
3206 /* Dynamically decode VRAM chars if dirty */
3207 if (vram_changed)
3208 for (tile = 0;tile < 256;tile++)
3209 if (vram_dirty[tile]) {
3210 decodechar(Machine->gfx[0],tile,(UINT8 *)f3_vram,Machine->drv->gfxdecodeinfo[0].gfxlayout);
3211 vram_dirty[tile]=0;
3212 }
3213 vram_changed=0;
3214
3215 /* if (scroll_dirty)*/
3216 {
3217 sy_fix[0]=((f3_control_0[2]&0xffff0000)>> 7)+(scroll_kludge_y<<16);
3218 sy_fix[1]=((f3_control_0[2]&0x0000ffff)<< 9)+((scroll_kludge_y+pf23_y_kludge)<<16);
3219 sy_fix[2]=((f3_control_0[3]&0xffff0000)>> 7)+((scroll_kludge_y+pf23_y_kludge)<<16);
3220 sy_fix[3]=((f3_control_0[3]&0x0000ffff)<< 9)+(scroll_kludge_y<<16);
3221 sx_fix[0]=((f3_control_0[0]&0xffc00000)>> 6)-((6+scroll_kludge_x)<<16);
3222 sx_fix[1]=((f3_control_0[0]&0x0000ffc0)<<10)-((10+scroll_kludge_x)<<16);
3223 sx_fix[2]=((f3_control_0[1]&0xffc00000)>> 6)-((14+scroll_kludge_x)<<16);
3224 sx_fix[3]=((f3_control_0[1]&0x0000ffc0)<<10)-((18+scroll_kludge_x)<<16);
3225
3226 sx_fix[0]-=((f3_control_0[0]&0x003f0000)>> 6)+0x0400-0x10000;
3227 sx_fix[1]-=((f3_control_0[0]&0x0000003f)<<10)+0x0400-0x10000;
3228 sx_fix[2]-=((f3_control_0[1]&0x003f0000)>> 6)+0x0400-0x10000;
3229 sx_fix[3]-=((f3_control_0[1]&0x0000003f)<<10)+0x0400-0x10000;
3230
3231 #if DEBUG_F3
3232 sy_fix[0]+=deb_sc_y;
3233 sy_fix[1]+=deb_sc_y;
3234 sy_fix[2]+=deb_sc_y;
3235 sy_fix[3]+=deb_sc_y;
3236 sx_fix[0]+=deb_sc_x;
3237 sx_fix[1]+=deb_sc_x;
3238 sx_fix[2]+=deb_sc_x;
3239 sx_fix[3]+=deb_sc_x;
3240 #endif /*DEBUG_F3*/
3241
3242 if (flipscreen)
3243 {
3244 sy_fix[0]= 0x3000000-sy_fix[0];
3245 sy_fix[1]= 0x3000000-sy_fix[1];
3246 sy_fix[2]= 0x3000000-sy_fix[2];
3247 sy_fix[3]= 0x3000000-sy_fix[3];
3248 sx_fix[0]=-0x1a00000-sx_fix[0];
3249 sx_fix[1]=-0x1a00000-sx_fix[1];
3250 sx_fix[2]=-0x1a00000-sx_fix[2];
3251 sx_fix[3]=-0x1a00000-sx_fix[3];
3252 }
3253 }
3254 /* scroll_dirty=1;// 0*/
3255
3256 /* Update pivot layer */
3257 f3_update_pivot_layer();
3258
3259
3260 fillbitmap(pri_alp_bitmap,0,cliprect);
3261 #if DEBUG_F3
3262 if (deb_enable) fillbitmap(bitmap,255,cliprect);
3263 #endif /*DEBUG_F3*/
3264
3265 /* Pixel layer */
3266 tempclip = pixel_layer_clip;
3267 sect_rect(&tempclip,cliprect);
3268 #if DEBUG_F3
3269 if (!deb_enable || !keyboard_pressed(KEYCODE_N))
3270 #endif /*DEBUG_F3*/
3271 {
3272 priority_bitmap_bak=priority_bitmap;
3273 priority_bitmap=pri_alp_bitmap;
3274 tilemap_draw(bitmap,&tempclip,pixel_layer,0,0xff);
3275 priority_bitmap=priority_bitmap_bak;
3276 }
3277
3278
3279 /* sprites */
3280 if (sprite_lag==0)
3281 {
3282 get_sprite_info(spriteram32);
3283 }
3284
3285 #if DEBUG_F3
3286 if (!deb_enable || !keyboard_pressed(KEYCODE_B))
3287 #endif /*DEBUG_F3*/
3288 {
3289 f3_drawsprites(bitmap,cliprect);
3290 }
3291
3292 #if DEBUG_F3
3293 deb_tileflag=0;
3294 if (deb_enable && keyboard_pressed(KEYCODE_G))
3295 {
3296 deb_tileflag=1;
3297 tilemap_mark_all_tiles_dirty( pf1_tilemap );
3298 tilemap_mark_all_tiles_dirty( pf2_tilemap );
3299 tilemap_mark_all_tiles_dirty( pf3_tilemap );
3300 tilemap_mark_all_tiles_dirty( pf4_tilemap );
3301 }
3302 #endif /*DEBUG_F3*/
3303
3304 /* Playfield */
3305 get_line_ram_info(pf1_tilemap,sx_fix[0],sy_fix[0],0,f3_pf_data_1);
3306 get_line_ram_info(pf2_tilemap,sx_fix[1],sy_fix[1],1,f3_pf_data_2);
3307 get_line_ram_info(pf3_tilemap,sx_fix[2],sy_fix[2],2,f3_pf_data_3);
3308 get_line_ram_info(pf4_tilemap,sx_fix[3],sy_fix[3],3,f3_pf_data_4);
3309
3310 f3_tilemap_draw(bitmap,cliprect);
3311
3312
3313 /* vram layer */
3314 #if DEBUG_F3
3315 if (!deb_enable || !keyboard_pressed(KEYCODE_M))
3316 #endif /*DEBUG_F3*/
3317 f3_draw_vram_layer(bitmap,cliprect);
3318
3319
3320 #if DEBUG_F3
3321 if (0 && keyboard_pressed(KEYCODE_O))
3322 print_debug_info(0,0,0,0,0,0,0,0);
3323 #endif /*DEBUG_F3*/
3324
3325
3326 if (!keyboard_pressed(KEYCODE_LSHIFT) && keyboard_pressed_memory(KEYCODE_F1))
3327 {
3328 alpha_disable=!alpha_disable;
3329 if(alpha_disable)
3330 usrintf_showmessage("alpha blending:off");
3331 else usrintf_showmessage("alpha blending:on");
3332 }
3333
3334 #if DEBUG_F3
3335 {/******************************************************************************/
3336 static int debdisp = 0;
3337 static int cz_pos=0,cz_line=24;
3338
3339 if (keyboard_pressed(KEYCODE_LSHIFT) && keyboard_pressed_memory(KEYCODE_F1))
3340 {
3341 deb_enable=!deb_enable;
3342 if(!deb_enable)
3343 {
3344 debdisp = 0;
3345 usrintf_showmessage("debug mode:off");
3346 }
3347 else usrintf_showmessage("debug mode:on");
3348
3349 }
3350
3351 if (deb_enable && keyboard_pressed_memory(KEYCODE_Q))
3352 {
3353 debdisp++;
3354 if(debdisp==4) debdisp = 0;
3355 }
3356
3357 if(debdisp)
3358 {
3359 int sft;
3360 if (keyboard_pressed(KEYCODE_K)) cz_line--;
3361 if (keyboard_pressed(KEYCODE_L)) cz_line++;
3362 if (keyboard_pressed_memory(KEYCODE_I)) cz_line--;
3363 if (keyboard_pressed_memory(KEYCODE_O)) cz_line++;
3364 cz_line=cz_line & 0xff;
3365 sft=16*~(cz_line & 1);
3366
3367 if(debdisp==2)
3368 {
3369 sprintf(deb_buf[0],"LINE:%3d Z:%04x R:%04x C:%04x",cz_line,
3370 (f3_line_ram[(0x0800+cz_line*2)/4]>>sft)&0xffff,
3371 (f3_line_ram[(0x0c00+cz_line*2)/4]>>sft)&0xffff,
3372 (f3_line_ram[(0x0000+cz_line*2)/4]>>sft)&0xffff
3373 );
3374
3375 for(cz_pos=0;cz_pos<4;cz_pos++)
3376 sprintf(deb_buf[1+cz_pos],"Layer:%2d z:%04x r:%04x c:%04x",cz_pos,
3377 (f3_line_ram[(0x8000+cz_pos*256*2+cz_line*2)/4]>>sft)&0xffff,
3378 (f3_line_ram[(0xa000+cz_pos*256*2+cz_line*2)/4]>>sft)&0xffff,
3379 (f3_line_ram[(0x4000+cz_pos*256*2+cz_line*2)/4]>>sft)&0xffff
3380 );
3381 }
3382 else if(debdisp==3)
3383 {
3384 int deb_sx[4],deb_sx_fix[4];
3385 int deb_sy[4],deb_sy_fix[4];
3386
3387 deb_sx[0]=(f3_control_0[0]&0xffc00000)>>22;
3388 deb_sx[1]=(f3_control_0[0]&0x0000ffc0)>>6;
3389 deb_sx[2]=(f3_control_0[1]&0xffc00000)>>22;
3390 deb_sx[3]=(f3_control_0[1]&0x0000ffc0)>>6;
3391
3392 deb_sx_fix[0]=(f3_control_0[0]&0x003f0000)>>14;
3393 deb_sx_fix[1]=(f3_control_0[0]&0x0000003f)<<2;
3394 deb_sx_fix[2]=(f3_control_0[1]&0x003f0000)>>14;
3395 deb_sx_fix[3]=(f3_control_0[1]&0x0000003f)<<2;
3396
3397 deb_sy[0]=(f3_control_0[2]&0xffff0000)>>23;
3398 deb_sy[1]=(f3_control_0[2]&0x0000ffff)>>7;
3399 deb_sy[2]=(f3_control_0[3]&0xffff0000)>>23;
3400 deb_sy[3]=(f3_control_0[3]&0x0000ffff)>>7;
3401
3402 deb_sy_fix[0]=(f3_control_0[2]&0x007f0000)>>15;
3403 deb_sy_fix[1]=(f3_control_0[2]&0x0000007f)<<1;
3404 deb_sy_fix[2]=(f3_control_0[3]&0x007f0000)>>15;
3405 deb_sy_fix[3]=(f3_control_0[3]&0x0000007f)<<1;
3406
3407 for(cz_pos=0;cz_pos<4;cz_pos++)
3408 sprintf(deb_buf[1+cz_pos],"Layer:%2d x:%03x.%02x y:%03x.%02x",cz_pos,
3409 deb_sx[cz_pos],deb_sx_fix[cz_pos],
3410 deb_sy[cz_pos],deb_sy_fix[cz_pos]
3411 );
3412 }
3413 else if(debdisp==1)
3414 {
3415 sprintf(deb_buf[0],"LINE:%3d S:%04x T:%04x A:%04x ?:%04x",cz_line,
3416 (f3_line_ram[(0x0600+cz_line*2)/4]>>sft)&0xffff,
3417 (f3_line_ram[(0x0e00+cz_line*2)/4]>>sft)&0xffff,
3418 (f3_line_ram[(0x0400+cz_line*2)/4]>>sft)&0xffff,
3419 (f3_line_ram[(0x0200+cz_line*2)/4]>>sft)&0xffff
3420 );
3421
3422 for(cz_pos=0;cz_pos<4;cz_pos++)
3423 sprintf(deb_buf[1+cz_pos],"Layer:%2d s:%04x t:%04x a:%04x ?:%04x",cz_pos,
3424 (f3_line_ram[(0x7000+cz_pos*256*2+cz_line*2)/4]>>sft)&0xffff,
3425 (f3_line_ram[(0xb000+cz_pos*256*2+cz_line*2)/4]>>sft)&0xffff,
3426 (f3_line_ram[(0x6000+cz_pos*256*2+cz_line*2)/4]>>sft)&0xffff,
3427 (f3_line_ram[(0x5000+cz_pos*256*2+cz_line*2)/4]>>sft)&0xffff
3428 );
3429 }
3430
3431 if(1)
3432 {
3433 if (keyboard_pressed_memory(KEYCODE_0_PAD)) deb_sc_x-=0x0400;
3434 if (keyboard_pressed_memory(KEYCODE_DEL_PAD)) deb_sc_x+=0x0400;
3435 if (keyboard_pressed_memory(KEYCODE_1_PAD)) deb_sc_x-=0x10000;
3436 if (keyboard_pressed_memory(KEYCODE_2_PAD)) deb_sc_x+=0x10000;
3437
3438 if (keyboard_pressed_memory(KEYCODE_4_PAD)) deb_sc_y-=0x0200;
3439 if (keyboard_pressed_memory(KEYCODE_5_PAD)) deb_sc_y+=0x0200;
3440 if (keyboard_pressed_memory(KEYCODE_7_PAD)) deb_sc_y-=0x10000;
3441 if (keyboard_pressed_memory(KEYCODE_8_PAD)) deb_sc_y+=0x10000;
3442 sprintf(deb_buf[5],"sc offset x:%8x y:%8x",deb_sc_x,deb_sc_y);
3443
3444 sprintf(deb_buf[6],"flip:%d alp/loop:%2d/%2d",!(!flipscreen),deb_alpha_cnt,deb_loop);
3445
3446 if (keyboard_pressed_memory(KEYCODE_H)) deb_tile_code--;
3447 if (keyboard_pressed_memory(KEYCODE_J)) deb_tile_code++;
3448 deb_tile_code&=0x1f;
3449 sprintf(deb_buf[7],"tile code flg:%02x",deb_tile_code);
3450 }
3451 else
3452 {
3453 if (keyboard_pressed(KEYCODE_0_PAD)) deb_alpha_level_a-=1;
3454 if (keyboard_pressed(KEYCODE_DEL_PAD)) deb_alpha_level_a+=1;
3455 if (keyboard_pressed_memory(KEYCODE_1_PAD)) deb_alpha_level_a-=1;
3456 if (keyboard_pressed_memory(KEYCODE_2_PAD)) deb_alpha_level_a+=1;
3457
3458 if (keyboard_pressed(KEYCODE_4_PAD)) deb_alpha_level_b-=1;
3459 if (keyboard_pressed(KEYCODE_5_PAD)) deb_alpha_level_b+=1;
3460 if (keyboard_pressed_memory(KEYCODE_7_PAD)) deb_alpha_level_b-=1;
3461 if (keyboard_pressed_memory(KEYCODE_8_PAD)) deb_alpha_level_b+=1;
3462
3463 deb_alpha_level_a &= 0xff;
3464 deb_alpha_level_b &= 0xff;
3465
3466 if (keyboard_pressed_memory(KEYCODE_6_PAD)) deb_alp_mode++;
3467 if (deb_alp_mode>2 ) deb_alp_mode=0;
3468
3469 sprintf(deb_buf[5],"mode:%d alpha_a:%2x alpha_b:%2x",
3470 deb_alp_mode,deb_alpha_level_a,deb_alpha_level_b );
3471
3472 {
3473 int al_s,al_d;
3474 int deb_alpha_level_s0,deb_alpha_level_d0;
3475 int deb_alpha_level_s1,deb_alpha_level_d1;
3476
3477 int a=(f3_line_ram[(0x6000+1*256*2+cz_line*2)/4]>>sft)&0xffff;
3478 int b=(a>>8)&0xf;
3479 /* int c=(a>>4)&0xf;*/
3480 int d=(a>>0)&0xf;
3481 a>>=12;
3482
3483 /* b000 */
3484 al_s = ( (15-d)*256) / 8;
3485 al_d = ( (15-b)*256) / 8;
3486 if(al_s>255) al_s = 255;
3487 if(al_d>255) al_d = 255;
3488 deb_alpha_level_s0 = al_s;
3489 deb_alpha_level_d0 = al_d;
3490
3491 /* 7000 */
3492 if(a==11 || a>=b) al_s = ((15-b)*256) / 8;
3493 else al_s = ((15-a)*256) / 8;
3494 if(al_s>255) al_s = 255;
3495 al_d = 255-al_s;
3496 deb_alpha_level_s1 = al_s;
3497 deb_alpha_level_d1 = al_d;
3498
3499 sprintf(deb_buf[6],"alpb src:%4d dst:%4d",deb_alpha_level_s0,deb_alpha_level_d0);
3500 sprintf(deb_buf[7],"alp7 src:%4d dst:%4d",deb_alpha_level_s1,deb_alpha_level_d1);
3501 }
3502 }
3503
3504 ui_text(bitmap,deb_buf[0],0,Machine->uifontheight*0);
3505 ui_text(bitmap,deb_buf[1],0,Machine->uifontheight*1);
3506 ui_text(bitmap,deb_buf[2],0,Machine->uifontheight*2);
3507 ui_text(bitmap,deb_buf[3],0,Machine->uifontheight*3);
3508 ui_text(bitmap,deb_buf[4],0,Machine->uifontheight*4);
3509 ui_text(bitmap,deb_buf[5],0,Machine->uifontheight*5);
3510 ui_text(bitmap,deb_buf[6],0,Machine->uifontheight*6);
3511 ui_text(bitmap,deb_buf[7],0,Machine->uifontheight*7);
3512 ui_text(bitmap,deb_buf[8],0,Machine->uifontheight*8);
3513 memset(deb_buf, 0x00, sizeof(deb_buf));
3514 }
3515 }
3516 #endif /*DEBUG_F3*/
3517 }
3518