~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/mame/video/snes.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
  | 8 bits    | 8 bits   |  | 1 bit    | 7 bits    | 8 bits   |
38
38
  ------------------------  -----------------------------------
39
39
 
40
 
  The screen layers are drawn with the following priorities:
41
 
  (highest to lowest)
42
 
 
43
 
  Modes 0 and 1                         Modes 2 to 7
44
 
  -------------------------------------------------------
45
 
  Mainscreens
46
 
          (BG3:1 - BG3 priority)        OBJ:3
47
 
           OBJ:3                        BG1:1
48
 
           BG1:1                        OBJ:2
49
 
           BG2:1                        BG2:1
50
 
           OBJ:2                        OBJ:1
51
 
           BG1:0                        BG1:0
52
 
           BG2:0                        OBJ:0
53
 
           OBJ:1                        BG2:0
54
 
          (BG3:1 - BG3 not priority)    Background Colour
55
 
           BG4:1
56
 
           OBJ:0
57
 
           BG3:0
58
 
           BG4:0
59
 
           Background Colour
60
 
  Subscreens
61
 
          (BG3:1 - BG3 priority)        OBJ:3
62
 
           OBJ:3                        BG1:1
63
 
           BG1:1                        OBJ:2
64
 
           BG2:1                        BG2:1
65
 
           OBJ:2                        OBJ:1
66
 
           BG1:0                        BG1:0
67
 
           BG2:0                        OBJ:0
68
 
           OBJ:1                        BG2:0
69
 
          (BG3:1 - BG3 not priority)
70
 
           BG4:1
71
 
           OBJ:0
72
 
           BG3:0
73
 
           BG4:0
 
40
  The screen layers are drawn with the following priorities (updated info courtesy of byuu):
 
41
 
 
42
  |           |   1   |   2   |   3   |   4   |   5   |   6   |   7   |   8   |   9   |  10   |  11   |  12   |
 
43
  -------------------------------------------------------------------------------------------------------------
 
44
  | Mode 0    |  BG4B |  BG3B |  OAM0 |  BG4A |  BG3A |  OAM1 |  BG2B |  BG1B |  OAM2 |  BG2A |  BG1A |  OAM3 |
 
45
  -------------------------------------------------------------------------------------------------------------
 
46
  | Mode 1 (*)|  BG3B |  OAM0 |  OAM1 |  BG2B |  BG1B |  OAM2 |  BG2A |  BG1A |  OAM3 |  BG3A |       |       |
 
47
  -------------------------------------------------------------------------------------------------------------
 
48
  | Mode 1 (!)|  BG3B |  OAM0 |  BG3A |  OAM1 |  BG2B |  BG1B |  OAM2 |  BG2A |  BG1A |  OAM3 |       |       |
 
49
  -------------------------------------------------------------------------------------------------------------
 
50
  | Mode 2    |  BG2B |  OAM0 |  BG1B |  OAM1 |  BG2A |  OAM2 |  BG1A |  OAM3 |       |       |       |       |
 
51
  -------------------------------------------------------------------------------------------------------------
 
52
  | Mode 3    |  BG2B |  OAM0 |  BG1B |  OAM1 |  BG2A |  OAM2 |  BG1A |  OAM3 |       |       |       |       |
 
53
  -------------------------------------------------------------------------------------------------------------
 
54
  | Mode 4    |  BG2B |  OAM0 |  BG1B |  OAM1 |  BG2A |  OAM2 |  BG1A |  OAM3 |       |       |       |       |
 
55
  -------------------------------------------------------------------------------------------------------------
 
56
  | Mode 5    |  BG2B |  OAM0 |  BG1B |  OAM1 |  BG2A |  OAM2 |  BG1A |  OAM3 |       |       |       |       |
 
57
  -------------------------------------------------------------------------------------------------------------
 
58
  | Mode 6    |  OAM0 |  BG1B |  OAM1 |  OAM2 |  BG1A |  OAM3 |       |       |       |       |       |       |
 
59
  -------------------------------------------------------------------------------------------------------------
 
60
  | Mode 7 (+)|  OAM0 |  BG1n |  OAM1 |  OAM2 |  OAM3 |       |       |       |       |       |       |       |
 
61
  -------------------------------------------------------------------------------------------------------------
 
62
  | Mode 7 (-)|  BG2B |  OAM0 |  BG1n |  OAM1 |  BG2A |  OAM2 |  OAM3 |       |       |       |       |       |
 
63
  -------------------------------------------------------------------------------------------------------------
 
64
 
 
65
  Where:
 
66
   - Mode 1 (*) is Mode 1 with bg3_pty = 1
 
67
   - Mode 1 (!) is Mode 1 with bg3_pty = 0
 
68
   - Mode 7 (+) is base Mode 7
 
69
   - Mode 7 (-) is Mode 7 EXTBG
74
70
 
75
71
***************************************************************************/
76
72
 
88
84
#define SNES_CLIP_OUT   2
89
85
#define SNES_CLIP_ALL2  3
90
86
 
91
 
#ifdef SNES_DBG_video
 
87
#ifdef MAME_DEBUG
92
88
struct DEBUGOPTS
93
89
{
94
90
        UINT8 input_count;
95
91
        UINT8 bg_disabled[6];
 
92
        UINT8 mode_disabled[8];
96
93
        UINT8 draw_subscreen;
97
94
        UINT8 windows_disabled;
98
95
        UINT8 transparency_disabled;
99
96
};
100
 
static struct DEBUGOPTS debug_options  = {5, {0,0,0,0,0,0}, 0, 0, 0};
 
97
static struct DEBUGOPTS debug_options;
101
98
/*                                    red   green  blue    purple  yellow cyan    grey    white */
102
99
static const UINT16 dbg_mode_colours[8] = { 0x1f, 0x3e0, 0x7c00, 0x7c1f, 0x3ff, 0x7fe0, 0x4210, 0x7fff };
103
 
static UINT8 snes_dbg_video(bitmap_t *bitmap, UINT16 curline);
104
 
#endif /* SNES_DBG_video */
105
 
 
106
 
/* Forward declarations */
107
 
static void snes_update_line_2(UINT8 screen, UINT8 layer, UINT16 curline );
108
 
static void snes_update_line_2_hi(UINT8 screen, UINT8 layer, UINT16 curline );
109
 
static void snes_update_line_4(UINT8 screen, UINT8 layer, UINT16 curline );
110
 
static void snes_update_line_4_hi(UINT8 screen, UINT8 layer, UINT16 curline );
111
 
static void snes_update_line_8(UINT8 screen, UINT8 layer, UINT16 curline );
112
 
static void snes_update_line_mode7(UINT8 screen, UINT8 layer, UINT16 curline );
113
 
 
114
 
/* Lookup tables */
115
 
static const UINT8  table_bgd_pty[2][4][2] = { { {7,10}, {6,9}, {1,4}, {0,3} }, { {3,10}, {1,7}, {0,0}, {0,0} } };
116
 
static const UINT8  table_obj_pty[4]       = { 2, 5, 8, 11 };
 
100
static UINT8 snes_dbg_video(running_machine *machine, bitmap_t *bitmap, UINT16 curline);
 
101
#endif /* MAME_DEBUG */
 
102
 
117
103
static const UINT16 table_obj_offset[8][8] =
118
104
{
119
105
        { (0*32),   (0*32)+32,   (0*32)+64,   (0*32)+96,   (0*32)+128,   (0*32)+160,   (0*32)+192,   (0*32)+224 },
134
120
        UINT16 buffer[(SNES_SCR_WIDTH * 2) + 16];
135
121
        UINT8  zbuf[(SNES_SCR_WIDTH * 2) + 16];
136
122
};
137
 
struct SNES_MODE_CONFIG
138
 
{
139
 
        void (*drawLayer[5])(UINT8 screen, UINT8 layer, UINT16 curline);
140
 
        UINT8 count;
141
 
};
142
123
 
143
124
static struct SCANLINE scanlines[2];
144
125
struct SNES_PPU_STRUCT snes_ppu;
145
 
static const struct SNES_MODE_CONFIG snes_modedefs[8] =
 
126
 
 
127
enum
146
128
{
147
 
/*0*/   { {snes_update_line_2, snes_update_line_2, snes_update_line_2, snes_update_line_2}, 4 },
148
 
/*1*/   { {snes_update_line_4, snes_update_line_4, snes_update_line_2, NULL}, 3 },
149
 
/*2*/   { {snes_update_line_4, snes_update_line_4, NULL, NULL}, 2 },            /* Supports offset per tile */
150
 
/*3*/   { {snes_update_line_8, snes_update_line_4, NULL, NULL}, 2 },            /* Supports direct colour */
151
 
/*4*/   { {snes_update_line_8, snes_update_line_2, NULL, NULL}, 2 },            /* Supports offset per tile and direct colour */
152
 
/*5*/   { {snes_update_line_4_hi, snes_update_line_2_hi, NULL, NULL}, 2 },      /* Supports hires */
153
 
/*6*/   { {snes_update_line_4_hi, NULL, NULL, NULL}, 1 },                                       /* Supports offset per tile and hires */
154
 
/*7*/   { {snes_update_line_mode7, NULL, NULL, NULL}, 1 }                                       /* Supports direct colour */
 
129
        SNES_COLOR_DEPTH_2BPP = 0,
 
130
        SNES_COLOR_DEPTH_4BPP,
 
131
        SNES_COLOR_DEPTH_8BPP
155
132
};
156
133
 
157
134
/*****************************************
160
137
 * Routine for additive/subtractive blending
161
138
 * between the main and sub screens.
162
139
 *****************************************/
163
 
INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 mode, UINT8 clip )
 
140
INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 mode, UINT8 clip, UINT8 black_pen_clip )
164
141
{
165
 
#ifdef SNES_DBG_video
 
142
        if( (black_pen_clip == SNES_CLIP_ALL2) ||
 
143
                (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[5][offset]) ||
 
144
                (black_pen_clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[5][offset]))
 
145
                *colour = 0; //clip to black before color math
 
146
 
 
147
        if (clip == SNES_CLIP_ALL2) // blending mode 3 == always OFF
 
148
                return;
 
149
 
 
150
#ifdef MAME_DEBUG
166
151
        if( !debug_options.transparency_disabled )
167
 
#endif /* SNES_DBG_video */
168
 
        if( (clip == SNES_CLIP_ALL || clip == SNES_CLIP_ALL2) ||
169
 
                (clip == SNES_CLIP_IN  && snes_ppu.clipmasks[5][offset]) ||
170
 
                (clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[5][offset]) )
 
152
#endif /* MAME_DEBUG */
 
153
        if( (clip == SNES_CLIP_ALL) ||
 
154
                (clip == SNES_CLIP_IN  && !snes_ppu.clipmasks[5][offset]) ||
 
155
                (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[5][offset]) )
171
156
        {
172
157
                UINT16 r, g, b;
 
158
 
173
159
                if( mode == SNES_BLEND_ADD )
174
160
                {
175
 
                        if( snes_ram[CGWSEL] & 0x2 ) /* Subscreen*/
 
161
                        if( snes_ppu.sub_add_mode ) /* Subscreen*/
176
162
                        {
177
163
                                r = (*colour & 0x1f) + (scanlines[SUBSCREEN].buffer[offset] & 0x1f);
178
164
                                g = ((*colour & 0x3e0) >> 5) + ((scanlines[SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
179
165
                                b = ((*colour & 0x7c00) >> 10) + ((scanlines[SUBSCREEN].buffer[offset] & 0x7c00) >> 10);
180
 
                                if( (snes_ram[CGADSUB] & 0x40) && (scanlines[SUBSCREEN].zbuf[offset]) ) /* FIXME: We shouldn't halve for the back colour */
 
166
 
 
167
                                /* don't halve for the back colour */
 
168
                                if( (snes_ram[CGADSUB] & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]) )
181
169
                                {
182
170
                                        r >>= 1;
183
171
                                        g >>= 1;
189
177
                                r = (*colour & 0x1f) + (snes_cgram[FIXED_COLOUR] & 0x1f);
190
178
                                g = ((*colour & 0x3e0) >> 5) + ((snes_cgram[FIXED_COLOUR] & 0x3e0) >> 5);
191
179
                                b = ((*colour & 0x7c00) >> 10) + ((snes_cgram[FIXED_COLOUR] & 0x7c00) >> 10);
192
 
                                if( snes_ram[CGADSUB] & 0x40 ) /* FIXME: We shouldn't halve for the back colour */
 
180
 
 
181
                                /* don't halve for the back colour */
 
182
                                if( (snes_ram[CGADSUB] & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]) )
193
183
                                {
194
184
                                        r >>= 1;
195
185
                                        g >>= 1;
203
193
                }
204
194
                else if( mode == SNES_BLEND_SUB )
205
195
                {
206
 
                        if( snes_ram[CGWSEL] & 0x2 ) /* Subscreen */
 
196
                        if( snes_ppu.sub_add_mode ) /* Subscreen */
207
197
                        {
208
198
                                r = (*colour & 0x1f) - (scanlines[SUBSCREEN].buffer[offset] & 0x1f);
209
199
                                g = ((*colour & 0x3e0) >> 5) - ((scanlines[SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
211
201
                                if( r > 0x1f ) r = 0;
212
202
                                if( g > 0x1f ) g = 0;
213
203
                                if( b > 0x1f ) b = 0;
214
 
                                if( (snes_ram[CGADSUB] & 0x40) && (scanlines[SUBSCREEN].zbuf[offset]) ) /* FIXME: We shouldn't halve for the back colour */
 
204
 
 
205
                                /* don't halve for the back colour */
 
206
                                if( (snes_ram[CGADSUB] & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]) )
215
207
                                {
216
208
                                        r >>= 1;
217
209
                                        g >>= 1;
226
218
                                if( r > 0x1f ) r = 0;
227
219
                                if( g > 0x1f ) g = 0;
228
220
                                if( b > 0x1f ) b = 0;
229
 
                                if( snes_ram[CGADSUB] & 0x40 ) /* FIXME: We shouldn't halve for the back colour */
 
221
 
 
222
                                /* don't halve for the back colour */
 
223
                                if( (snes_ram[CGADSUB] & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]) )
230
224
                                {
231
225
                                        r >>= 1;
232
226
                                        g >>= 1;
238
232
        }
239
233
}
240
234
 
241
 
/*****************************************
242
 
 * snes_draw_tile_2()
243
 
 *
244
 
 * Draw tiles with 2 bit planes(4 colors)
245
 
 *****************************************/
246
 
INLINE void snes_draw_tile_2(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
247
 
{
248
 
        UINT8 mask, plane[2];
249
 
        UINT16 c;
250
 
        INT16 ii;
251
 
 
252
 
        plane[0] = snes_vram[tileaddr];
253
 
        plane[1] = snes_vram[tileaddr + 1];
254
 
 
255
 
        if( flip )
256
 
                mask = 0x1;
257
 
        else
258
 
                mask = 0x80;
259
 
 
260
 
        for( ii = x; ii < (x + 8); ii++ )
261
 
        {
262
 
                register UINT8 colour;
263
 
                if( flip )
264
 
                {
265
 
                        colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0);
266
 
                        mask <<= 1;
267
 
                }
268
 
                else
269
 
                {
270
 
                        colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0);
271
 
                        mask >>= 1;
272
 
                }
273
 
 
274
 
#ifdef SNES_DBG_video
275
 
                if( !debug_options.windows_disabled )
276
 
#endif /* SNES_DBG_video */
277
 
                /* Clip to windows */
278
 
                if( (screen == MAINSCREEN && (snes_ram[TMW] & (0x1 << layer))) || (screen == SUBSCREEN && (snes_ram[TSW] & (0x1 << layer))))
279
 
                        colour &= snes_ppu.clipmasks[layer][ii];
280
 
 
281
 
                /* Only draw if we have a colour (0 == transparent) */
282
 
                if( colour )
283
 
                {
284
 
                        if( (scanlines[screen].zbuf[ii] <= priority) && (ii >= 0) )
285
 
                        {
286
 
                                c = snes_cgram[pal + colour];
287
 
                                if( screen == MAINSCREEN )      /* Only blend main screens */
288
 
                                        snes_draw_blend(ii, &c, snes_ppu.layer[layer].blend, (snes_ram[CGWSEL] & 0x30) >> 4 );
289
 
                                scanlines[screen].buffer[ii] = c;
290
 
                                scanlines[screen].zbuf[ii] = priority;
291
 
                        }
292
 
                }
293
 
        }
294
 
}
295
 
 
296
 
/*****************************************
297
 
 * snes_draw_tile_2x2()
298
 
 *
299
 
 * Draw 2 tiles with 2 bit planes(4 colors)
300
 
 *****************************************/
301
 
INLINE void snes_draw_tile_2x2(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
302
 
{
303
 
        if( flip )
304
 
        {
305
 
                snes_draw_tile_2(screen, layer, tileaddr + 16, x, priority, flip, pal );
306
 
                snes_draw_tile_2(screen, layer, tileaddr, x + 8, priority, flip, pal );
307
 
        }
308
 
        else
309
 
        {
310
 
                snes_draw_tile_2(screen, layer, tileaddr, x, priority, flip, pal );
311
 
                snes_draw_tile_2(screen, layer, tileaddr + 16, x + 8, priority, flip, pal );
312
 
        }
313
 
}
314
 
 
315
 
/*****************************************
316
 
 * snes_draw_tile_4()
317
 
 *
318
 
 * Draw tiles with 4 bit planes(16 colors)
319
 
 *****************************************/
320
 
INLINE void snes_draw_tile_4(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
321
 
{
322
 
        UINT8 mask, plane[4];
323
 
        UINT16 c;
324
 
        INT16 ii;
325
 
 
326
 
        plane[0] = snes_vram[tileaddr];
327
 
        plane[1] = snes_vram[tileaddr + 1];
328
 
        plane[2] = snes_vram[tileaddr + 16];
329
 
        plane[3] = snes_vram[tileaddr + 17];
330
 
 
331
 
        if( flip )
332
 
                mask = 0x1;
333
 
        else
334
 
                mask = 0x80;
335
 
 
336
 
        for( ii = x; ii < (x + 8); ii++ )
337
 
        {
338
 
                register UINT8 colour;
339
 
                if( flip )
340
 
                {
341
 
                        colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) |
342
 
                                         (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0);
343
 
                        mask <<= 1;
344
 
                }
345
 
                else
346
 
                {
347
 
                        colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) |
348
 
                                         (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0);
349
 
                        mask >>= 1;
350
 
                }
351
 
 
352
 
#ifdef SNES_DBG_video
353
 
                if( !debug_options.windows_disabled )
354
 
#endif /* SNES_DBG_video */
355
 
                /* Clip to windows */
356
 
                if( (screen == MAINSCREEN && (snes_ram[TMW] & (0x1 << layer))) || (screen == SUBSCREEN && (snes_ram[TSW] & (0x1 << layer))))
357
 
                        colour &= snes_ppu.clipmasks[layer][ii];
358
 
 
359
 
                /* Only draw if we have a colour (0 == transparent) */
360
 
                if( colour )
361
 
                {
362
 
                        if( (scanlines[screen].zbuf[ii] <= priority) && (ii >= 0) )
363
 
                        {
364
 
                                c = snes_cgram[pal + colour];
365
 
                                if( screen == MAINSCREEN )      /* Only blend main screens */
366
 
                                        snes_draw_blend(ii, &c, snes_ppu.layer[layer].blend, (snes_ram[CGWSEL] & 0x30) >> 4 );
367
 
                                scanlines[screen].buffer[ii] = c;
368
 
                                scanlines[screen].zbuf[ii] = priority;
369
 
                        }
370
 
                }
371
 
        }
372
 
}
373
 
 
374
 
/*****************************************
375
 
 * snes_draw_tile_4x2()
376
 
 *
377
 
 * Draw 2 tiles with 4 bit planes(16 colors)
378
 
 *****************************************/
379
 
INLINE void snes_draw_tile_4x2(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
380
 
{
381
 
        if( flip )
382
 
        {
383
 
                snes_draw_tile_4(screen, layer, tileaddr + 32, x, priority, flip, pal );
384
 
                snes_draw_tile_4(screen, layer, tileaddr, x + 8, priority, flip, pal );
385
 
        }
386
 
        else
387
 
        {
388
 
                snes_draw_tile_4(screen, layer, tileaddr, x, priority, flip, pal );
389
 
                snes_draw_tile_4(screen, layer, tileaddr + 32, x + 8, priority, flip, pal );
390
 
        }
391
 
}
392
 
 
393
 
/*****************************************
394
 
 * snes_draw_tile_8()
395
 
 *
396
 
 * Draw tiles with 8 bit planes(256 colors)
397
 
 *****************************************/
398
 
INLINE void snes_draw_tile_8(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip )
399
 
{
400
 
        UINT8 mask, plane[8];
401
 
        UINT16 c;
402
 
        INT16 ii;
403
 
 
404
 
        plane[0] = snes_vram[tileaddr];
405
 
        plane[1] = snes_vram[tileaddr + 1];
406
 
        plane[2] = snes_vram[tileaddr + 16];
407
 
        plane[3] = snes_vram[tileaddr + 17];
408
 
        plane[4] = snes_vram[tileaddr + 32];
409
 
        plane[5] = snes_vram[tileaddr + 33];
410
 
        plane[6] = snes_vram[tileaddr + 48];
411
 
        plane[7] = snes_vram[tileaddr + 49];
412
 
 
413
 
        if( flip )
414
 
                mask = 0x1;
415
 
        else
416
 
                mask = 0x80;
417
 
 
418
 
        for( ii = x; ii < (x + 8); ii++ )
419
 
        {
420
 
                register UINT8 colour;
421
 
                if( flip )
422
 
                {
423
 
                        colour = (plane[0] & mask ? 1 : 0)  | (plane[1] & mask ? 2 : 0)  |
424
 
                                         (plane[2] & mask ? 4 : 0)  | (plane[3] & mask ? 8 : 0)  |
425
 
                                         (plane[4] & mask ? 16 : 0) | (plane[5] & mask ? 32 : 0) |
426
 
                                         (plane[6] & mask ? 64 : 0) | (plane[7] & mask ? 128 : 0);
427
 
                        mask <<= 1;
428
 
                }
429
 
                else
430
 
                {
431
 
                        colour = (plane[0] & mask ? 1 : 0)  | (plane[1] & mask ? 2 : 0)  |
432
 
                                         (plane[2] & mask ? 4 : 0)  | (plane[3] & mask ? 8 : 0)  |
433
 
                                         (plane[4] & mask ? 16 : 0) | (plane[5] & mask ? 32 : 0) |
434
 
                                         (plane[6] & mask ? 64 : 0) | (plane[7] & mask ? 128 : 0);
435
 
                        mask >>= 1;
436
 
                }
437
 
 
438
 
#ifdef SNES_DBG_video
439
 
                if( !debug_options.windows_disabled )
440
 
#endif /* SNES_DBG_video */
441
 
                /* Clip to windows */
442
 
                if( (screen == MAINSCREEN && (snes_ram[TMW] & (0x1 << layer))) || (screen == SUBSCREEN && (snes_ram[TSW] & (0x1 << layer))))
443
 
                        colour &= snes_ppu.clipmasks[layer][ii];
444
 
 
445
 
                /* Only draw if we have a colour (0 == transparent) */
446
 
                if( colour )
447
 
                {
448
 
                        if( (scanlines[screen].zbuf[ii] <= priority) && (ii >= 0) )
449
 
                        {
450
 
                                c = snes_cgram[colour];
451
 
                                if( screen == MAINSCREEN )      /* Only blend main screens */
452
 
                                        snes_draw_blend(ii, &c, snes_ppu.layer[layer].blend, (snes_ram[CGWSEL] & 0x30) >> 4 );
453
 
                                scanlines[screen].buffer[ii] = c;
454
 
                                scanlines[screen].zbuf[ii] = priority;
455
 
                        }
456
 
                }
457
 
        }
458
 
}
459
 
 
460
 
/*****************************************
461
 
 * snes_draw_tile_8x2()
462
 
 *
463
 
 * Draw 2 tiles with 8 bit planes(256 colors)
464
 
 *****************************************/
465
 
INLINE void snes_draw_tile_8x2(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip )
466
 
{
467
 
        if( flip )
468
 
        {
469
 
                snes_draw_tile_8(screen, layer, tileaddr + 64, x, priority, flip );
470
 
                snes_draw_tile_8(screen, layer, tileaddr, x + 8, priority, flip );
471
 
        }
472
 
        else
473
 
        {
474
 
                snes_draw_tile_8(screen, layer, tileaddr, x, priority, flip );
475
 
                snes_draw_tile_8(screen, layer, tileaddr + 64, x + 8, priority, flip );
 
235
 
 
236
/*****************************************
 
237
 * snes_draw_tile()
 
238
 *
 
239
 * Draw tiles with variable bit planes
 
240
 *****************************************/
 
241
INLINE void snes_draw_tile(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors )
 
242
{
 
243
        UINT8 mask, plane[8], window_enabled = 0;
 
244
        UINT16 c;
 
245
        INT16 ii, jj;
 
246
 
 
247
        for (ii = 0; ii < planes / 2; ii++)
 
248
        {
 
249
                plane[2 * ii] = snes_vram[tileaddr + 16 * ii];
 
250
                plane[2 * ii + 1] = snes_vram[tileaddr + 16 * ii + 1];
 
251
        }
 
252
 
 
253
        if (flip)
 
254
                mask = 0x1;
 
255
        else
 
256
                mask = 0x80;
 
257
 
 
258
        for (ii = x; ii < (x + 8); ii++)
 
259
        {
 
260
                UINT8 colour = 0;
 
261
                if (flip)
 
262
                {
 
263
                        for (jj = 0; jj < planes; jj++)
 
264
                                colour |= plane[jj] & mask ? (1 << jj) : 0;
 
265
 
 
266
                        mask <<= 1;
 
267
                }
 
268
                else
 
269
                {
 
270
                        for (jj = 0; jj < planes; jj++)
 
271
                                colour |= plane[jj] & mask ? (1 << jj) : 0;
 
272
 
 
273
                        mask >>= 1;
 
274
                }
 
275
 
 
276
#ifdef MAME_DEBUG
 
277
                if(!debug_options.windows_disabled)
 
278
#endif /* MAME_DEBUG */
 
279
                /* Clip to windows */
 
280
                window_enabled = (screen == MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
 
281
                if (window_enabled)
 
282
                        colour &= snes_ppu.clipmasks[layer][ii];
 
283
 
 
284
                /* Only draw if we have a colour (0 == transparent) */
 
285
                if (colour)
 
286
                {
 
287
                        if ((scanlines[screen].zbuf[ii] <= priority) && (ii >= 0))
 
288
                        {
 
289
                                if(direct_colors)
 
290
                                {
 
291
                                        /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
 
292
                                        c = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
 
293
                                        c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
 
294
                                }
 
295
                                else
 
296
                                        c = snes_cgram[pal + colour];
 
297
 
 
298
                                if (screen == MAINSCREEN)       /* Only blend main screens */
 
299
                                        snes_draw_blend(ii/snes_htmult, &c, snes_ppu.layer[layer].blend, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
 
300
                                if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic
 
301
                                {
 
302
                                        int x_mos;
 
303
 
 
304
                                        //TODO: 512 modes has the h values doubled.
 
305
                                        for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
 
306
                                        {
 
307
                                                scanlines[screen].buffer[ii + x_mos] = c;
 
308
                                                scanlines[screen].zbuf[ii + x_mos] = priority;
 
309
                                        }
 
310
                                        ii += x_mos - 1;
 
311
                                }
 
312
                                else
 
313
                                {
 
314
                                        scanlines[screen].buffer[ii] = c;
 
315
                                        scanlines[screen].zbuf[ii] = priority;
 
316
                                }
 
317
                        }
 
318
                }
 
319
        }
 
320
}
 
321
 
 
322
/*****************************************
 
323
 * snes_draw_tile_x2()
 
324
 *
 
325
 * Draw 2 tiles with variable bit planes
 
326
 *****************************************/
 
327
INLINE void snes_draw_tile_x2(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors )
 
328
{
 
329
        if( flip )
 
330
        {
 
331
                snes_draw_tile(screen, planes, layer, tileaddr + (8 * planes), x, priority, flip, pal, direct_colors);
 
332
                snes_draw_tile(screen, planes, layer, tileaddr, x + 8, priority, flip, pal, direct_colors);
 
333
        }
 
334
        else
 
335
        {
 
336
                snes_draw_tile(screen, planes, layer, tileaddr, x, priority, flip, pal, direct_colors);
 
337
                snes_draw_tile(screen, planes, layer, tileaddr + (8 * planes), x + 8, priority, flip, pal, direct_colors);
476
338
        }
477
339
}
478
340
 
483
345
 * The same as snes_draw_tile_4() except
484
346
 * that it takes a blend parameter.
485
347
 *****************************************/
486
 
INLINE void snes_draw_tile_object(UINT8 screen, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 blend )
487
 
{
488
 
        UINT8 mask, plane[4];
489
 
        UINT16 c;
490
 
        INT16 ii;
491
 
 
492
 
        plane[0] = snes_vram[tileaddr];
493
 
        plane[1] = snes_vram[tileaddr + 1];
494
 
        plane[2] = snes_vram[tileaddr + 16];
495
 
        plane[3] = snes_vram[tileaddr + 17];
496
 
 
497
 
        if( flip )
498
 
                mask = 0x1;
499
 
        else
500
 
                mask = 0x80;
501
 
 
502
 
        for( ii = x; ii < (x + 8); ii++ )
503
 
        {
504
 
                register UINT8 colour;
505
 
                if( flip )
506
 
                {
507
 
                        colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) |
508
 
                                         (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0);
509
 
                        mask <<= 1;
510
 
                }
511
 
                else
512
 
                {
513
 
                        colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) |
514
 
                                         (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0);
515
 
                        mask >>= 1;
516
 
                }
517
 
 
518
 
#ifdef SNES_DBG_video
519
 
                if( !debug_options.windows_disabled )
520
 
#endif /* SNES_DBG_video */
521
 
                /* Clip to windows */
522
 
                if( (screen == MAINSCREEN && (snes_ram[TMW] & 0x10)) || (screen == SUBSCREEN && (snes_ram[TSW] & 0x10)))
523
 
                        colour &= snes_ppu.clipmasks[4][ii];
524
 
 
525
 
                /* Only draw if we have a colour (0 == transparent) */
526
 
                if( colour )
527
 
                {
528
 
                        if( ii >= 0 )
529
 
                        {
530
 
                                c = snes_cgram[pal + colour];
531
 
                                if( blend && screen == MAINSCREEN )     /* Only blend main screens */
532
 
                                        snes_draw_blend(ii, &c, snes_ppu.layer[4].blend, (snes_ram[CGWSEL] & 0x30) >> 4 );
533
 
 
534
 
                                scanlines[screen].buffer[ii] = c;
535
 
                                scanlines[screen].zbuf[ii] = priority;
536
 
                        }
537
 
                }
538
 
        }
539
 
}
540
 
 
541
 
/*****************************************
542
 
 * snes_draw_tile_object_w()
543
 
 *
544
 
 * Draw tiles with 4 bit planes(16 colors)
545
 
 * The same as snes_draw_tile_4() except
546
 
 * that it takes a blend parameter.
547
 
 * Wide version.
548
 
 *****************************************/
549
 
INLINE void snes_draw_tile_object_w(UINT8 screen, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 blend )
550
 
{
551
 
        UINT8 mask, plane[4];
552
 
        UINT16 c;
553
 
        INT16 ii;
554
 
 
555
 
        plane[0] = snes_vram[tileaddr];
556
 
        plane[1] = snes_vram[tileaddr + 1];
557
 
        plane[2] = snes_vram[tileaddr + 16];
558
 
        plane[3] = snes_vram[tileaddr + 17];
559
 
 
560
 
        if( flip )
561
 
                mask = 0x1;
562
 
        else
563
 
                mask = 0x80;
564
 
 
565
 
        x <<= 1;
566
 
        for( ii = x; ii < (x + 16); ii += 2 )
567
 
        {
568
 
                register UINT8 colour;
569
 
                if( flip )
570
 
                {
571
 
                        colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) |
572
 
                                         (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0);
573
 
                        mask <<= 1;
574
 
                }
575
 
                else
576
 
                {
577
 
                        colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) |
578
 
                                         (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0);
579
 
                        mask >>= 1;
580
 
                }
581
 
 
582
 
#ifdef SNES_DBG_video
583
 
                if( !debug_options.windows_disabled )
584
 
#endif /* SNES_DBG_video */
585
 
                /* Clip to windows */
586
 
                if( (screen == MAINSCREEN && (snes_ram[TMW] & 0x10)) || (screen == SUBSCREEN && (snes_ram[TSW] & 0x10)))
587
 
                        colour &= snes_ppu.clipmasks[4][ii];
588
 
 
589
 
                /* Only draw if we have a colour (0 == transparent) */
590
 
                if( colour )
591
 
                {
592
 
                        if( ii >= 0 )
593
 
                        {
594
 
                                c = snes_cgram[pal + colour];
595
 
                                if( blend && screen == MAINSCREEN )     /* Only blend main screens */
596
 
                                        snes_draw_blend(ii, &c, snes_ppu.layer[4].blend, (snes_ram[CGWSEL] & 0x30) >> 4 );
597
 
 
598
 
                                scanlines[screen].buffer[ii] = c;
599
 
                                scanlines[screen].zbuf[ii] = priority;
600
 
                                scanlines[screen].buffer[ii + 1] = c;
601
 
                                scanlines[screen].zbuf[ii + 1] = priority;
602
 
                        }
603
 
                }
604
 
        }
605
 
}
606
 
 
607
 
/*********************************************
608
 
 * snes_update_line_2()
609
 
 *
610
 
 * Update an entire line of 2 bit plane tiles.
611
 
 *********************************************/
612
 
static void snes_update_line_2(UINT8 screen, UINT8 layer, UINT16 curline )
613
 
{
614
 
        UINT32 tmap, tile;
615
 
        UINT16 ii, vflip, hflip, pal;
616
 
        INT8 line, tile_line;
617
 
        UINT8 priority;
618
 
        /* scrolling */
619
 
        UINT32 basevmap;
620
 
        UINT16 vscroll, hscroll, vtilescroll;
621
 
        UINT8 vshift, hshift, tile_size;
622
 
        UINT8 bg3_pty = 0;
623
 
 
624
 
#ifdef SNES_DBG_video
625
 
        if( debug_options.bg_disabled[layer] )
626
 
                return;
627
 
#endif /* SNES_DBG_video */
628
 
 
629
 
        /* set special priority bit */
630
 
        if( snes_ppu.mode == 1 && snes_ram[BGMODE] & 0x8 )
631
 
                bg3_pty = 1;
632
 
 
633
 
        /* Handle Mosaic effects */
634
 
        if( snes_ram[MOSAIC] & (1 << layer) )
635
 
                curline -= (curline % ((snes_ram[MOSAIC] >> 4) + 1));
636
 
 
637
 
        /* Find the size of the tiles (8x8 or 16x16) */
638
 
        tile_size = snes_ppu.layer[layer].tile_size;
639
 
        /* Find scroll info */
640
 
        vscroll = snes_ppu.layer[layer].offset.tile_vert;
641
 
        vshift = snes_ppu.layer[layer].offset.shift_vert;
642
 
        hscroll = snes_ppu.layer[layer].offset.tile_horz;
643
 
        hshift = snes_ppu.layer[layer].offset.shift_horz;
644
 
 
645
 
        /* Find vertical scroll amount */
646
 
        vtilescroll = vscroll + (curline >> (3 + tile_size));
647
 
        /* figure out which line to draw */
648
 
        line = (curline % (8 << tile_size)) + vshift;
649
 
        if( line > ((8 << tile_size) - 1) )     /* scrolled into the next tile */
650
 
        {
651
 
                vtilescroll++;  /* pretend we scrolled by 1 tile line */
652
 
                line -= (8 << tile_size);
653
 
        }
654
 
        if( vtilescroll >= 128 )
655
 
                vtilescroll -= 128;
656
 
 
657
 
        /* Jump to base map address */
658
 
        tmap = snes_ppu.layer[layer].map;
659
 
        /* Offset vertically */
660
 
        tmap += table_vscroll[snes_ppu.layer[layer].map_size][vtilescroll >> 5];
661
 
        /* Scroll vertically */
662
 
        tmap += (vtilescroll & 0x1f) << 6;
663
 
        /* Remember this position */
664
 
        basevmap = tmap;
665
 
        /* Offset horizontally */
666
 
        tmap += table_hscroll[snes_ppu.layer[layer].map_size & 3][(hscroll >> 5) & 3];
667
 
        /* Scroll horizontally */
668
 
        tmap += (hscroll & 0x1f) << 1;
669
 
 
670
 
        for( ii = 0; ii < (66 >> tile_size); ii += 2 )
671
 
        {
672
 
                /* Have we scrolled into the next map? */
673
 
                if( hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f)) )
674
 
                {
675
 
                        tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3];
676
 
                        tmap -= ii;
677
 
                        hscroll = 0;    /* Make sure we don't do this again */
678
 
                }
679
 
                if (tmap > 0x10000) tmap %= 0x10000;
680
 
                vflip = (snes_vram[tmap + ii + 1] & 0x80);
681
 
                hflip = snes_vram[tmap + ii + 1] & 0x40;
682
 
                priority = table_bgd_pty[snes_ppu.mode > 1][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5];
683
 
                pal = (snes_vram[tmap + ii + 1] & 0x1c);                /* 8 palettes of 4 colours */
684
 
                tile = (snes_vram[tmap + ii + 1] & 0x3) << 8;
685
 
                tile |= snes_vram[tmap + ii];
686
 
 
687
 
                /* Mode 0 palettes are layer specific */
688
 
                if( snes_ppu.mode == 0 )
689
 
                {
690
 
                        pal += (layer << 5);
691
 
                }
692
 
 
693
 
                tile_line = line;
694
 
                if( vflip )
695
 
                {
696
 
                        if( tile_size )
697
 
                        {
698
 
                                if( line > 7 )
699
 
                                {
700
 
                                        tile_line -= 8;
701
 
                                }
702
 
                                else
703
 
                                {
704
 
                                        tile += 32;
705
 
                                }
706
 
                        }
707
 
                        tile_line = -tile_line + 7;
708
 
                }
709
 
                else
710
 
                {
711
 
                        if( line > 7 )
712
 
                        {
713
 
                                tile += 32;
714
 
                                tile_line -= 8;
715
 
                        }
716
 
                }
717
 
                tile_line <<= 1;
718
 
 
719
 
                /* Special case for bg3 */
720
 
                if( layer == 2 && bg3_pty && (snes_vram[tmap + ii + 1] & 0x20) )
721
 
                        priority = table_obj_pty[3] + 1;                /* We want to have the highest priority here */
722
 
 
723
 
                if( tile_size )
724
 
                {
725
 
                        snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal );
726
 
                }
727
 
                else
728
 
                {
729
 
                        snes_draw_tile_2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal );
730
 
                }
731
 
        }
732
 
}
733
 
 
734
 
/*********************************************
735
 
 * snes_update_line_2_hi()
736
 
 *
737
 
 * Update an entire line of 2 bit plane tiles.
738
 
 * This is the hires version.
739
 
 *********************************************/
740
 
static void snes_update_line_2_hi(UINT8 screen, UINT8 layer, UINT16 curline )
741
 
{
742
 
        UINT32 tmap, tile;
743
 
        UINT16 ii, vflip, hflip, pal;
744
 
        INT8 line, tile_line;
745
 
        UINT8 priority;
746
 
        /* scrolling */
747
 
        UINT32 basevmap;
748
 
        UINT16 vscroll, hscroll, vtilescroll;
749
 
        UINT8 vshift, hshift, tile_size;
750
 
        UINT8 bg3_pty = 0;
751
 
 
752
 
#ifdef SNES_DBG_video
753
 
        if( debug_options.bg_disabled[layer] )
754
 
                return;
755
 
#endif /* SNES_DBG_video */
756
 
 
757
 
        /* set special priority bit */
758
 
        if( snes_ppu.mode == 1 && snes_ram[BGMODE] & 0x8 )
759
 
                bg3_pty = 1;
760
 
 
761
 
        /* Handle Mosaic effects */
762
 
        if( snes_ram[MOSAIC] & (1 << layer) )
763
 
                curline -= (curline % ((snes_ram[MOSAIC] >> 4) + 1));
764
 
 
765
 
        /* Find the size of the tiles (8x8 or 16x16) */
766
 
        tile_size = snes_ppu.layer[layer].tile_size;
767
 
        /* Find scroll info */
768
 
        vscroll = snes_ppu.layer[layer].offset.tile_vert;
769
 
        vshift = snes_ppu.layer[layer].offset.shift_vert;
770
 
        hscroll = snes_ppu.layer[layer].offset.tile_horz;
771
 
        hshift = snes_ppu.layer[layer].offset.shift_horz;
772
 
 
773
 
        /* Find vertical scroll amount */
774
 
        vtilescroll = vscroll + (curline >> (3 + tile_size));
775
 
        /* figure out which line to draw */
776
 
        line = (curline % (8 << tile_size)) + vshift;
777
 
        if( line > ((8 << tile_size) - 1) )     /* scrolled into the next tile */
778
 
        {
779
 
                vtilescroll++;  /* pretend we scrolled by 1 tile line */
780
 
                line -= (8 << tile_size);
781
 
        }
782
 
        if( vtilescroll >= 128 )
783
 
                vtilescroll -= 128;
784
 
 
785
 
        /* Jump to base map address */
786
 
        tmap = snes_ppu.layer[layer].map;
787
 
        /* Offset vertically */
788
 
        tmap += table_vscroll[snes_ppu.layer[layer].map_size][vtilescroll >> 5];
789
 
        /* Scroll vertically */
790
 
        tmap += (vtilescroll & 0x1f) << 6;
791
 
        /* Remember this position */
792
 
        basevmap = tmap;
793
 
        /* Offset horizontally */
794
 
        tmap += table_hscroll[snes_ppu.layer[layer].map_size & 3][(hscroll >> 5) & 3];
795
 
        /* Scroll horizontally */
796
 
        tmap += (hscroll & 0x1f) << 1;
797
 
 
798
 
        for( ii = 0; ii < (66 >> tile_size); ii += 2 )
799
 
        {
800
 
                /* Have we scrolled into the next map? */
801
 
                if( hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f)) )
802
 
                {
803
 
                        tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3];
804
 
                        tmap -= ii;
805
 
                        hscroll = 0;    /* Make sure we don't do this again */
806
 
                }
807
 
                if (tmap > 0x10000) tmap %= 0x10000;
808
 
                vflip = (snes_vram[tmap + ii + 1] & 0x80);
809
 
                hflip = snes_vram[tmap + ii + 1] & 0x40;
810
 
                priority = table_bgd_pty[snes_ppu.mode > 1][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5];
811
 
                pal = (snes_vram[tmap + ii + 1] & 0x1c);                /* 8 palettes of 4 colours */
812
 
                tile = (snes_vram[tmap + ii + 1] & 0x3) << 8;
813
 
                tile |= snes_vram[tmap + ii];
814
 
 
815
 
                /* Mode 0 palettes are layer specific */
816
 
                if( snes_ppu.mode == 0 )
817
 
                {
818
 
                        pal += (layer << 5);
819
 
                }
820
 
 
821
 
                tile_line = line;
822
 
                if( vflip )
823
 
                {
824
 
                        if( tile_size )
825
 
                        {
826
 
                                if( line > 7 )
827
 
                                {
828
 
                                        tile_line -= 8;
829
 
                                }
830
 
                                else
831
 
                                {
832
 
                                        tile += 32;
833
 
                                }
834
 
                        }
835
 
                        tile_line = -tile_line + 7;
836
 
                }
837
 
                else
838
 
                {
839
 
                        if( line > 7 )
840
 
                        {
841
 
                                tile += 32;
842
 
                                tile_line -= 8;
843
 
                        }
844
 
                }
845
 
                tile_line <<= 1;
846
 
 
847
 
                /* Special case for bg3 */
848
 
                if( layer == 2 && bg3_pty && (snes_vram[tmap + ii + 1] & 0x20) )
849
 
                        priority = table_obj_pty[3] + 1;                /* We want to have the highest priority here */
850
 
 
851
 
                if( tile_size )
852
 
                {
853
 
                        if( hflip )
854
 
                        {
855
 
                                snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal );
856
 
                                snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
857
 
                        }
858
 
                        else
859
 
                        {
860
 
                                snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
861
 
                                snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal );
862
 
                        }
863
 
                }
864
 
                else
865
 
                {
866
 
                        snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
867
 
                }
868
 
        }
869
 
}
870
 
 
871
 
/*********************************************
872
 
 * snes_update_line_4()
873
 
 *
874
 
 * Update an entire line of 4 bit plane tiles.
875
 
 *********************************************/
876
 
static void snes_update_line_4(UINT8 screen, UINT8 layer, UINT16 curline )
877
 
{
878
 
        UINT32 tmap, tile;
879
 
        UINT16 ii, vflip, hflip, pal;
880
 
        INT8 line, tile_line;
881
 
        UINT8 priority;
882
 
        /* scrolling */
883
 
        UINT32 basevmap;
884
 
        UINT16 vscroll, hscroll, vtilescroll;
885
 
        UINT8 vshift, hshift, tile_size;
886
 
 
887
 
#ifdef SNES_DBG_video
888
 
        if( debug_options.bg_disabled[layer] )
889
 
                return;
890
 
#endif /* SNES_DBG_video */
891
 
 
892
 
        /* Handle Mosaic effects */
893
 
        if( snes_ram[MOSAIC] & (1 << layer) )
894
 
                curline -= (curline % ((snes_ram[MOSAIC] >> 4) + 1));
895
 
 
896
 
        /* Find the size of the tiles (8x8 or 16x16) */
897
 
        tile_size = snes_ppu.layer[layer].tile_size;
898
 
        /* Find scroll info */
899
 
        vscroll = snes_ppu.layer[layer].offset.tile_vert;
900
 
        vshift = snes_ppu.layer[layer].offset.shift_vert;
901
 
        hscroll = snes_ppu.layer[layer].offset.tile_horz;
902
 
        hshift = snes_ppu.layer[layer].offset.shift_horz;
903
 
 
904
 
        /* Jump to base map address */
905
 
        tmap = snes_ppu.layer[layer].map;
906
 
 
907
 
        /* Find vertical scroll amount */
908
 
        vtilescroll = vscroll + (curline >> (3 + tile_size));
909
 
        /* figure out which line to draw */
910
 
        line = (curline % (8 << tile_size)) + vshift;
911
 
        if( line > ((8 << tile_size) - 1) )     /* scrolled into the next tile */
912
 
        {
913
 
                vtilescroll++;  /* pretend we scrolled by 1 tile line */
914
 
                line -= (8 << tile_size);
915
 
        }
916
 
        if( vtilescroll >= 128 )
917
 
                vtilescroll -= 128;
918
 
 
919
 
        /* Offset vertically */
920
 
        tmap += table_vscroll[snes_ppu.layer[layer].map_size][vtilescroll >> 5];
921
 
        /* Scroll vertically */
922
 
        tmap += (vtilescroll & 0x1f) << 6;
923
 
        /* Remember this position */
924
 
        basevmap = tmap;
925
 
        /* Offset horizontally */
926
 
        tmap += table_hscroll[snes_ppu.layer[layer].map_size & 3][(hscroll >> 5) & 3];
927
 
        /* Scroll horizontally */
928
 
        tmap += (hscroll & 0x1f) << 1;
929
 
 
930
 
        for( ii = 0; ii < (66 >> tile_size); ii += 2 )
931
 
        {
932
 
                /* Have we scrolled into the next map? */
933
 
                if( hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f)) )
934
 
                {
935
 
                        tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3];
936
 
                        tmap -= ii;
937
 
                        hscroll = 0;    /* Make sure we don't do this again */
938
 
                }
939
 
                if (tmap > 0x10000) tmap %= 0x10000;
940
 
                vflip = snes_vram[tmap + ii + 1] & 0x80;
941
 
                hflip = snes_vram[tmap + ii + 1] & 0x40;
942
 
                priority = table_bgd_pty[snes_ppu.mode > 1][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5];             /* is this even right??? */
943
 
                pal = (snes_vram[tmap + ii + 1] & 0x1c) << 2;   /* 8 palettes of 16 colours */
944
 
                tile = (snes_vram[tmap + ii + 1] & 0x3) << 8;
945
 
                tile |= snes_vram[tmap + ii];
946
 
 
947
 
                tile_line = line;
948
 
                if( vflip )
949
 
                {
950
 
                        if( tile_size )
951
 
                        {
952
 
                                if( line > 7 )
953
 
                                {
954
 
                                        tile_line -= 8;
955
 
                                }
956
 
                                else
957
 
                                {
958
 
                                        tile += 16;
959
 
                                }
960
 
                        }
961
 
                        tile_line = -tile_line + 7;
962
 
                }
963
 
                else
964
 
                {
965
 
                        if( line > 7 )
966
 
                        {
967
 
                                tile += 16;
968
 
                                tile_line -= 8;
969
 
                        }
970
 
                }
971
 
                tile_line <<= 1;
972
 
 
973
 
                if( tile_size )
974
 
                {
975
 
                        snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal );
976
 
                }
977
 
                else
978
 
                {
979
 
                        snes_draw_tile_4(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal );
980
 
                }
981
 
        }
982
 
}
983
 
 
984
 
/*********************************************
985
 
 * snes_update_line_4_hi()
986
 
 *
987
 
 * Update an entire line of 4 bit plane tiles.
988
 
 * This is the hires version
989
 
 *********************************************/
990
 
static void snes_update_line_4_hi(UINT8 screen, UINT8 layer, UINT16 curline )
991
 
{
992
 
        UINT32 tmap, tile;
993
 
        UINT16 ii, vflip, hflip, pal;
994
 
        INT8 line, tile_line;
995
 
        UINT8 priority;
996
 
        /* scrolling */
997
 
        UINT32 basevmap;
998
 
        UINT16 vscroll, hscroll, vtilescroll;
999
 
        UINT8 vshift, hshift, tile_size;
1000
 
 
1001
 
#ifdef SNES_DBG_video
1002
 
        if( debug_options.bg_disabled[layer] )
1003
 
                return;
1004
 
#endif /* SNES_DBG_video */
1005
 
 
1006
 
        /* Handle Mosaic effects */
1007
 
        if( snes_ram[MOSAIC] & (1 << layer) )
1008
 
                curline -= (curline % ((snes_ram[MOSAIC] >> 4) + 1));
1009
 
 
1010
 
        /* Find the size of the tiles (8x8 or 16x16) */
1011
 
        tile_size = snes_ppu.layer[layer].tile_size;
1012
 
        /* Find scroll info */
1013
 
        vscroll = snes_ppu.layer[layer].offset.tile_vert;
1014
 
        vshift = snes_ppu.layer[layer].offset.shift_vert;
1015
 
        hscroll = snes_ppu.layer[layer].offset.tile_horz;
1016
 
        hshift = snes_ppu.layer[layer].offset.shift_horz;
1017
 
 
1018
 
        /* Find vertical scroll amount */
1019
 
        vtilescroll = vscroll + (curline >> (3 + tile_size));
1020
 
        /* figure out which line to draw */
1021
 
        line = (curline % (8 << tile_size)) + vshift;
1022
 
        if( line > ((8 << tile_size) - 1) )     /* scrolled into the next tile */
1023
 
        {
1024
 
                vtilescroll++;  /* pretend we scrolled by 1 tile line */
1025
 
                line -= (8 << tile_size);
1026
 
        }
1027
 
        if( vtilescroll >= 128 )
1028
 
                vtilescroll -= 128;
1029
 
 
1030
 
        /* Jump to base map address */
1031
 
        tmap = snes_ppu.layer[layer].map;
1032
 
        /* Offset vertically */
1033
 
        tmap += table_vscroll[snes_ppu.layer[layer].map_size][vtilescroll >> 5];
1034
 
        /* Scroll vertically */
1035
 
        tmap += (vtilescroll & 0x1f) << 6;
1036
 
        /* Remember this position */
1037
 
        basevmap = tmap;
1038
 
        /* Offset horizontally */
1039
 
        tmap += table_hscroll[snes_ppu.layer[layer].map_size & 3][(hscroll >> 5) & 3];
1040
 
        /* Scroll horizontally */
1041
 
        tmap += (hscroll & 0x1f) << 1;
1042
 
 
1043
 
        for( ii = 0; ii < (66 >> tile_size); ii += 2 )
1044
 
        {
1045
 
                /* Have we scrolled into the next map? */
1046
 
                if( hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f)) )
1047
 
                {
1048
 
                        tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3];
1049
 
                        tmap -= ii;
1050
 
                        hscroll = 0;    /* Make sure we don't do this again */
1051
 
                }
1052
 
                if (tmap > 0x10000) tmap %= 0x10000;
1053
 
 
1054
 
                vflip = snes_vram[tmap + ii + 1] & 0x80;
1055
 
                hflip = snes_vram[tmap + ii + 1] & 0x40;
1056
 
                priority = table_bgd_pty[snes_ppu.mode > 1][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5];             /* is this even right??? */
1057
 
                pal = (snes_vram[tmap + ii + 1] & 0x1c) << 2;   /* 8 palettes of 16 colours */
1058
 
                tile = (snes_vram[tmap + ii + 1] & 0x3) << 8;
1059
 
                tile |= snes_vram[tmap + ii];
1060
 
 
1061
 
                tile_line = line;
1062
 
                if( vflip )
1063
 
                {
1064
 
                        if( tile_size )
1065
 
                        {
1066
 
                                if( line > 7 )
1067
 
                                {
1068
 
                                        tile_line -= 8;
1069
 
                                }
1070
 
                                else
1071
 
                                {
1072
 
                                        tile += 16;
1073
 
                                }
1074
 
                        }
1075
 
                        tile_line = -tile_line + 7;
1076
 
                }
1077
 
                else
1078
 
                {
1079
 
                        if( line > 7 )
1080
 
                        {
1081
 
                                tile += 16;
1082
 
                                tile_line -= 8;
1083
 
                        }
1084
 
                }
1085
 
                tile_line <<= 1;
1086
 
 
1087
 
                /* Does hi-res support the tile-size option? */
1088
 
                if( tile_size )
1089
 
                {
1090
 
                        if( hflip )
1091
 
                        {
1092
 
                                snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal );
1093
 
                                snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
1094
 
                        }
1095
 
                        else
1096
 
                        {
1097
 
                                snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
1098
 
                                snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal );
1099
 
                        }
1100
 
                }
1101
 
                else
1102
 
                {
1103
 
                        snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
1104
 
                }
1105
 
        }
1106
 
}
1107
 
 
1108
 
/*********************************************
1109
 
 * snes_update_line_8()
1110
 
 *
1111
 
 * Update an entire line of 8 bit plane tiles.
1112
 
 *********************************************/
1113
 
static void snes_update_line_8(UINT8 screen, UINT8 layer, UINT16 curline )
1114
 
{
1115
 
        UINT32 tmap, tile;
1116
 
        UINT16 ii, vflip, hflip, pal;
1117
 
        INT8 line, tile_line;
1118
 
        UINT8 priority;
1119
 
        /* scrolling */
1120
 
        UINT32 basevmap;
1121
 
        UINT16 vscroll, hscroll, vtilescroll;
1122
 
        UINT8 vshift, hshift, tile_size;
1123
 
 
1124
 
#ifdef SNES_DBG_video
1125
 
        if( debug_options.bg_disabled[layer] )
1126
 
                return;
1127
 
#endif /* SNES_DBG_video */
1128
 
 
1129
 
        /* Handle Mosaic effects */
1130
 
        if( snes_ram[MOSAIC] & (1 << layer) )
1131
 
                curline -= (curline % ((snes_ram[MOSAIC] >> 4) + 1));
1132
 
 
1133
 
        /* Find the size of the tiles (8x8 or 16x16) */
1134
 
        tile_size = snes_ppu.layer[layer].tile_size;
1135
 
        /* Find scroll info */
1136
 
        vscroll = snes_ppu.layer[layer].offset.tile_vert;
1137
 
        vshift = snes_ppu.layer[layer].offset.shift_vert;
1138
 
        hscroll = snes_ppu.layer[layer].offset.tile_horz;
1139
 
        hshift = snes_ppu.layer[layer].offset.shift_horz;
1140
 
 
1141
 
        /* Find vertical scroll amount */
1142
 
        vtilescroll = vscroll + (curline >> (3 + tile_size));
1143
 
        /* figure out which line to draw */
1144
 
        line = (curline % (8 << tile_size)) + vshift;
1145
 
        if( line > ((8 << tile_size) - 1) )     /* scrolled into the next tile */
1146
 
        {
1147
 
                vtilescroll++;  /* pretend we scrolled by 1 tile line */
1148
 
                line -= (8 << tile_size);
1149
 
        }
1150
 
        if( vtilescroll >= 128 )
1151
 
                vtilescroll -= 128;
1152
 
 
1153
 
        /* Jump to base map address */
1154
 
        tmap = snes_ppu.layer[layer].map;
1155
 
        /* Offset vertically */
1156
 
        tmap += table_vscroll[snes_ppu.layer[layer].map_size][vtilescroll >> 5];
1157
 
        /* Scroll vertically */
1158
 
        tmap += (vtilescroll & 0x1f) << 6;
1159
 
        /* Remember this position */
1160
 
        basevmap = tmap;
1161
 
        /* Offset horizontally */
1162
 
        tmap += table_hscroll[snes_ppu.layer[layer].map_size & 3][(hscroll >> 5) & 3];
1163
 
        /* Scroll horizontally */
1164
 
        tmap += (hscroll & 0x1f) << 1;
1165
 
 
1166
 
        for( ii = 0; ii < (66 >> tile_size); ii += 2 )
1167
 
        {
1168
 
                /* Have we scrolled into the next map? */
1169
 
                if( hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f)) )
1170
 
                {
1171
 
                        tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3];
1172
 
                        tmap -= ii;
1173
 
                        hscroll = 0;    /* Make sure we don't do this again */
1174
 
                }
1175
 
                if (tmap > 0x10000) tmap %= 0x10000;
1176
 
                vflip = (snes_vram[tmap + ii + 1] & 0x80);
1177
 
                hflip = snes_vram[tmap + ii + 1] & 0x40;
1178
 
                priority = table_bgd_pty[snes_ppu.mode > 1][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5];
1179
 
                pal = (snes_vram[tmap + ii + 1] & 0x1c);                /* what does this do for 8 bit screen? */
1180
 
                tile = (snes_vram[tmap + ii + 1] & 0x3) << 8;
1181
 
                tile |= snes_vram[tmap + ii];
1182
 
 
1183
 
                tile_line = line;
1184
 
                if( vflip )
1185
 
                {
1186
 
                        if( tile_size )
1187
 
                        {
1188
 
                                if( line > 7 )
1189
 
                                {
1190
 
                                        tile_line -= 8;
1191
 
                                }
1192
 
                                else
1193
 
                                {
1194
 
                                        tile += 8;
1195
 
                                }
1196
 
                        }
1197
 
                        tile_line = -tile_line + 7;
1198
 
                }
1199
 
                else
1200
 
                {
1201
 
                        if( line > 7 )
1202
 
                        {
1203
 
                                tile += 8;
1204
 
                                tile_line -= 8;
1205
 
                        }
1206
 
                }
1207
 
                tile_line <<= 1;
1208
 
 
1209
 
                if( tile_size )
1210
 
                {
1211
 
                        snes_draw_tile_8x2(screen, layer, snes_ppu.layer[layer].data + (tile << 6) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip );
1212
 
                }
1213
 
                else
1214
 
                {
1215
 
                        snes_draw_tile_8(screen, layer, snes_ppu.layer[layer].data + (tile << 6) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip );
1216
 
                }
1217
 
        }
1218
 
}
 
348
INLINE void snes_draw_tile_object(UINT8 screen, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 blend, UINT8 wide )
 
349
{
 
350
        UINT8 mask, plane[4], window_enabled = 0;
 
351
        UINT16 c;
 
352
        INT16 ii;
 
353
        UINT8 x_shift = wide ? 1 : 0;
 
354
        UINT8 size = wide ? 16 : 8;
 
355
        UINT8 step = wide ? 1 : 0;
 
356
 
 
357
        plane[0] = snes_vram[tileaddr];
 
358
        plane[1] = snes_vram[tileaddr + 1];
 
359
        plane[2] = snes_vram[tileaddr + 16];
 
360
        plane[3] = snes_vram[tileaddr + 17];
 
361
 
 
362
        if (flip)
 
363
                mask = 0x01;
 
364
        else
 
365
                mask = 0x80;
 
366
 
 
367
        x <<= x_shift;
 
368
        for (ii = x; ii < (x + size); ii += 1 + step)
 
369
        {
 
370
                UINT8 colour;
 
371
                if (flip)
 
372
                {
 
373
                        colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) |
 
374
                                         (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0);
 
375
                        mask <<= 1;
 
376
                }
 
377
                else
 
378
                {
 
379
                        colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) |
 
380
                                         (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0);
 
381
                        mask >>= 1;
 
382
                }
 
383
 
 
384
#ifdef MAME_DEBUG
 
385
                if (!debug_options.windows_disabled)
 
386
#endif /* MAME_DEBUG */
 
387
                /* Clip to windows */
 
388
                window_enabled = (screen == MAINSCREEN) ? snes_ppu.layer[4].main_window_enabled : snes_ppu.layer[4].sub_window_enabled;
 
389
                if (window_enabled)
 
390
                        colour &= snes_ppu.clipmasks[4][ii];
 
391
 
 
392
                /* Only draw if we have a colour (0 == transparent) */
 
393
                if (colour)
 
394
                {
 
395
                        if (ii >= 0)
 
396
                        {
 
397
                                c = snes_cgram[pal + colour];
 
398
                                if (blend && screen == MAINSCREEN)      /* Only blend main screens */
 
399
                                        snes_draw_blend(ii/snes_htmult, &c, snes_ppu.layer[4].blend, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
 
400
 
 
401
                                scanlines[screen].buffer[ii] = c;
 
402
                                scanlines[screen].zbuf[ii] = priority;
 
403
                                if (wide)
 
404
                                {
 
405
                                        scanlines[screen].buffer[ii + 1] = c;
 
406
                                        scanlines[screen].zbuf[ii + 1] = priority;
 
407
                                }
 
408
                        }
 
409
                }
 
410
        }
 
411
}
 
412
 
 
413
/*********************************************
 
414
 * snes_update_line()
 
415
 *
 
416
 * Update an entire line of tiles.
 
417
 *********************************************/
 
418
INLINE void snes_update_line( UINT8 screen, UINT8 color_depth, UINT8 hires, UINT8 priority_a, UINT8 priority_b, UINT8 layer, UINT16 curline, UINT8 offset_per_tile, UINT8 direct_colors )
 
419
{
 
420
        UINT32 tmap, tile;
 
421
        UINT16 ii, vflip, hflip, pal;
 
422
        INT8 line, tile_line;
 
423
        UINT8 priority;
 
424
        /* scrolling */
 
425
        UINT32 basevmap;
 
426
        UINT16 vscroll, hscroll, vtilescroll;
 
427
//  UINT16 offset_per_tile_valid;
 
428
//  UINT8 offset_per_tile_mode;
 
429
        UINT8 vshift, hshift, tile_size;
 
430
        /* variables depending on color_depth */
 
431
        UINT8 color_shift = 0;
 
432
        UINT8 color_planes = 2;
 
433
        UINT8 tile_divider = 1;
 
434
        UINT8 wrap_around_x; //helper for wrap-around
 
435
 
 
436
#ifdef MAME_DEBUG
 
437
        if (debug_options.bg_disabled[layer])
 
438
                return;
 
439
 
 
440
        if (debug_options.mode_disabled[snes_ppu.mode])
 
441
                return;
 
442
#endif /* MAME_DEBUG */
 
443
 
 
444
        /* Handle Mosaic effects */
 
445
        if (snes_ppu.layer[layer].mosaic_enabled)
 
446
                curline -= (curline % (snes_ppu.mosaic_size + 1));
 
447
 
 
448
        if((snes_ppu.interlace == 2) && !hires)
 
449
                curline/=2;
 
450
 
 
451
        /* Find the size of the tiles (8x8 or 16x16) */
 
452
        tile_size = snes_ppu.layer[layer].tile_size;
 
453
        /* Find scroll info */
 
454
        vscroll = snes_ppu.layer[layer].offset.tile_vert;
 
455
        vshift = snes_ppu.layer[layer].offset.shift_vert;
 
456
        hscroll = snes_ppu.layer[layer].offset.tile_horz;
 
457
        hshift = snes_ppu.layer[layer].offset.shift_horz;
 
458
 
 
459
        /* Find vertical scroll amount */
 
460
        vtilescroll = vscroll + (curline >> (3 + tile_size));
 
461
        /* figure out which line to draw */
 
462
        line = (curline % (8 << tile_size)) + vshift;
 
463
        if (line > ((8 << tile_size) - 1))      /* scrolled into the next tile */
 
464
        {
 
465
                vtilescroll++;  /* pretend we scrolled by 1 tile line */
 
466
                line -= (8 << tile_size);
 
467
        }
 
468
        if( vtilescroll >= 128 )
 
469
                vtilescroll -= 128;
 
470
 
 
471
        /* Jump to base map address */
 
472
        tmap = snes_ppu.layer[layer].map;
 
473
 
 
474
        /* Offset vertically */
 
475
        tmap += table_vscroll[snes_ppu.layer[layer].map_size & 3][(vtilescroll >> 5) & 3];
 
476
        /* Scroll vertically */
 
477
        tmap += (vtilescroll & 0x1f) << 6;
 
478
        /* Remember this position */
 
479
        basevmap = tmap;
 
480
        /* Offset horizontally */
 
481
        tmap += table_hscroll[snes_ppu.layer[layer].map_size & 3][(hscroll >> 5) & 3];
 
482
        /* Scroll horizontally */
 
483
        tmap += (hscroll & 0x1f) << 1;
 
484
 
 
485
        /* set a couple of variables depending on color_dept */
 
486
        switch (color_depth)
 
487
        {
 
488
                case SNES_COLOR_DEPTH_2BPP:
 
489
                        color_shift = 0;
 
490
                        color_planes = 2;
 
491
                        tile_divider = 2;
 
492
                        break;
 
493
                case SNES_COLOR_DEPTH_4BPP:
 
494
                        color_shift = 2;
 
495
                        color_planes = 4;
 
496
                        tile_divider = 2;
 
497
                        break;
 
498
                case SNES_COLOR_DEPTH_8BPP:
 
499
                        color_shift = 0;        //n/a, pal offset is always zero
 
500
                        color_planes = 8;
 
501
                        tile_divider = 4;
 
502
                        break;
 
503
        }
 
504
 
 
505
        wrap_around_x = 1;
 
506
 
 
507
        for (ii = 0; ii < (66*(hires+1) >> tile_size); ii += 2)
 
508
        {
 
509
                /* Have we scrolled into the next map? */
 
510
                if (wrap_around_x && ((ii >> 1) >= 32 - (hscroll & 0x1f)))
 
511
                {
 
512
                        tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3];
 
513
                        tmap -= ii;
 
514
                        wrap_around_x = 0;      /* Make sure we don't do this again */
 
515
                }
 
516
                //if (tmap > 0x10000)
 
517
                //  tmap %= 0x10000;
 
518
 
 
519
                vflip = snes_vram[tmap + ii + 1] & 0x80;
 
520
                hflip = snes_vram[tmap + ii + 1] & 0x40;
 
521
                priority = ((snes_vram[tmap + ii + 1] & 0x20) >> 5) ? priority_b : priority_a;
 
522
                pal = (color_depth == SNES_COLOR_DEPTH_8BPP && direct_colors == 0) ? 0 : (snes_vram[tmap + ii + 1] & 0x1c) << color_shift;              /* 8 palettes of (4 * color_shift) colours */
 
523
                tile = (snes_vram[tmap + ii + 1] & 0x3) << 8;
 
524
                tile |= snes_vram[tmap + ii] & 0xff;
 
525
 
 
526
                /* Mode 0 palettes are layer specific */
 
527
                if (snes_ppu.mode == 0)
 
528
                {
 
529
                        pal += (layer << 5);
 
530
                }
 
531
 
 
532
                tile_line = line;
 
533
                if (vflip)
 
534
                {
 
535
                        if (tile_size)
 
536
                        {
 
537
                                if (line > 7)
 
538
                                {
 
539
                                        tile_line -= 8;
 
540
                                }
 
541
                                else
 
542
                                {
 
543
                                        tile += 32 / tile_divider;
 
544
                                }
 
545
                        }
 
546
                        tile_line = -tile_line + 7;
 
547
                }
 
548
                else
 
549
                {
 
550
                        if (line > 7)
 
551
                        {
 
552
                                tile += 32 / tile_divider;
 
553
                                tile_line -= 8;
 
554
                        }
 
555
                }
 
556
                tile_line <<= 1;
 
557
 
 
558
                /* below, only color_planes depends on color_depth */
 
559
                if (tile_size)
 
560
                {
 
561
                        #if 0
 
562
                        /* Bishoujo Janshi SuchiiPai and Desert Fighter sets this in hires, no noticeable difference apart that x must be doubled somehow... */
 
563
                        if (hires)      /* Hi-Res: 2bpp & 4bpp */
 
564
                        {
 
565
                                if (hflip)
 
566
                                {
 
567
                                        snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + (tile * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal);
 
568
                                        snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + ((tile + 2)  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal);
 
569
                                }
 
570
                                else
 
571
                                {
 
572
                                        snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal);
 
573
                                        snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + ((tile + 2)  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal);
 
574
                                }
 
575
                        }
 
576
                        else    /* No Hi-Res: 2bpp, 4bpp & 8bpp */
 
577
                        #endif
 
578
                        {
 
579
                                snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal, direct_colors);
 
580
                        }
 
581
                }
 
582
                else    /* tile_size = 0 */
 
583
                {
 
584
                        if (hires)      /* Hi-Res: 2bpp & 4bpp */
 
585
                                snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal, direct_colors);
 
586
                        else    /* No Hi-Res: 2bpp, 4bpp & 8bpp */
 
587
                                snes_draw_tile(screen, color_planes, layer, snes_ppu.layer[layer].data + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal, direct_colors);
 
588
                }
 
589
        }
 
590
}
 
591
 
1219
592
 
1220
593
/*********************************************
1221
594
 * snes_update_line_mode7()
1222
595
 *
1223
596
 * Update an entire line of mode7 tiles.
1224
597
 *********************************************/
1225
 
static void snes_update_line_mode7(UINT8 screen, UINT8 layer, UINT16 curline )
 
598
#define MODE7_CLIP(x) (((x) & 0x2000) ? ((x) | ~0x03ff) : ((x) & 0x03ff))
 
599
 
 
600
static void snes_update_line_mode7(UINT8 screen, UINT8 priority_a, UINT8 priority_b, UINT8 layer, UINT16 curline )
1226
601
{
1227
602
        UINT32 tiled;
1228
603
        INT16 ma, mb, mc, md;
1229
 
        INT16 xc, yc, tx, ty, sx, sy, hs, vs, xpos, xdir;
1230
 
        UINT8 priority = 0;
1231
 
        register UINT8 colour = 0;
1232
 
 
1233
 
#ifdef SNES_DBG_video
1234
 
        if( debug_options.bg_disabled[0] )
1235
 
                return;
1236
 
#endif /* SNES_DBG_video */
 
604
        INT32 xc, yc, tx, ty, sx, sy, hs, vs, xpos, xdir, x0, y0;
 
605
        UINT8 priority = priority_a;
 
606
        UINT8 colour = 0, window_enabled = 0;
 
607
        UINT16 *mosaic_x, *mosaic_y;
 
608
 
 
609
#ifdef MAME_DEBUG
 
610
        if (debug_options.bg_disabled[layer])
 
611
                return;
 
612
 
 
613
        if (debug_options.mode_disabled[snes_ppu.mode])
 
614
                return;
 
615
#endif /* MAME_DEBUG */
1237
616
 
1238
617
        ma = snes_ppu.mode7.matrix_a;
1239
618
        mb = snes_ppu.mode7.matrix_b;
1241
620
        md = snes_ppu.mode7.matrix_d;
1242
621
        xc = snes_ppu.mode7.origin_x;
1243
622
        yc = snes_ppu.mode7.origin_y;
1244
 
        hs = snes_ppu.layer[0].offset.horizontal;
1245
 
        vs = snes_ppu.layer[0].offset.vertical;
 
623
        hs = snes_ppu.mode7.hor_offset;
 
624
        vs = snes_ppu.mode7.ver_offset;
1246
625
 
1247
626
        /* Sign extend */
1248
 
        xc <<= 3;
1249
 
        xc >>= 3;
1250
 
        yc <<= 3;
1251
 
        yc >>= 3;
1252
 
        hs <<= 3;
1253
 
        hs >>= 3;
1254
 
        vs <<= 3;
1255
 
        vs >>= 3;
 
627
        xc <<= 19;
 
628
        xc >>= 19;
 
629
        yc <<= 19;
 
630
        yc >>= 19;
 
631
        hs <<= 19;
 
632
        hs >>= 19;
 
633
        vs <<= 19;
 
634
        vs >>= 19;
1256
635
 
1257
636
        /* Vertical flip */
1258
 
        if( snes_ram[M7SEL] & 0x2 )
 
637
        if (snes_ppu.mode7.vflip)
1259
638
                sy = 255 - curline;
1260
639
        else
1261
640
                sy = curline;
1262
641
 
1263
642
        /* Horizontal flip */
1264
 
        if( snes_ram[M7SEL] & 0x1 )
 
643
        if (snes_ppu.mode7.hflip)
1265
644
        {
1266
645
                xpos = 255;
1267
646
                xdir = -1;
1272
651
                xdir = 1;
1273
652
        }
1274
653
 
 
654
        /* MOSAIC - to be verified */
 
655
        if (layer == 1) // BG2 use two different bits for horizontal and vertical mosaic
 
656
        {
 
657
                mosaic_x = snes_ppu.mosaic_table[snes_ppu.layer[1].mosaic_enabled ? snes_ppu.mosaic_size : 0];
 
658
                mosaic_y = snes_ppu.mosaic_table[snes_ppu.layer[0].mosaic_enabled ? snes_ppu.mosaic_size : 0];
 
659
        }
 
660
        else    // BG1 works as usual
 
661
        {
 
662
                mosaic_x =  snes_ppu.mosaic_table[snes_ppu.layer[0].mosaic_enabled ? snes_ppu.mosaic_size : 0];
 
663
                mosaic_y =  snes_ppu.mosaic_table[snes_ppu.layer[0].mosaic_enabled ? snes_ppu.mosaic_size : 0];
 
664
        }
 
665
 
1275
666
        /* Let's do some mode7 drawing huh? */
1276
 
        for( sx = 0; sx < 256; sx++, xpos += xdir )
 
667
        /* These can be computed only once, since they do not depend on sx */
 
668
        x0 = ((ma * MODE7_CLIP(hs - xc)) & ~0x3f) + ((mb * mosaic_y[sy]) & ~0x3f) + ((mb * MODE7_CLIP(vs - yc)) & ~0x3f) + (xc << 8);
 
669
        y0 = ((mc * MODE7_CLIP(hs - xc)) & ~0x3f) + ((md * mosaic_y[sy]) & ~0x3f) + ((md * MODE7_CLIP(vs - yc)) & ~0x3f) + (yc << 8);
 
670
 
 
671
        for (sx = 0; sx < 256; sx++, xpos += xdir)
1277
672
        {
1278
 
                tx = (((ma * ((sx + hs) - xc)) + (mb * ((sy + vs) - yc))) >> 8) + xc;
1279
 
                ty = (((mc * ((sx + hs) - xc)) + (md * ((sy + vs) - yc))) >> 8) + yc;
1280
 
                switch( snes_ram[M7SEL] & 0xc0 )
 
673
                tx = (x0 + (ma * mosaic_x[sx])) >> 8;
 
674
                ty = (y0 + (mc * mosaic_x[sx])) >> 8;
 
675
 
 
676
                switch (snes_ppu.mode7.repeat)
1281
677
                {
1282
678
                        case 0x00:      /* Repeat if outside screen area */
 
679
                        case 0x01:      /* Repeat if outside screen area */
1283
680
                                tx &= 0x3ff;
1284
681
                                ty &= 0x3ff;
1285
 
                                tiled = snes_vram[((tx >> 3) * 2) + ((ty >> 3) * 128 * 2)] << 7;
1286
 
                                colour = snes_vram[tiled + ((tx & 0x7) * 2) + ((ty & 0x7) * 16) + 1];
 
682
                                tiled = snes_vram[(((tx >> 3) & 0x7f) + (((ty >> 3) & 0x7f) * 128)) * 2] << 7;
 
683
                                colour = snes_vram[tiled + ((tx & 0x07) * 2) + ((ty & 0x07) * 16) + 1];
1287
684
                                break;
1288
 
                        case 0x80:      /* Single colour backdrop screen if outside screen area */
1289
 
                                if( (tx & 0x7fff) < 1024 && (ty & 0x7fff) < 1024 )
 
685
                        case 0x02:      /* Single colour backdrop screen if outside screen area */
 
686
                                if ((tx > 0) && (tx < 1024) && (ty > 0) && (ty < 1024))
1290
687
                                {
1291
 
                                        tiled = snes_vram[((tx >> 3) * 2) + ((ty >> 3) * 128 * 2)] << 7;
1292
 
                                        colour = snes_vram[tiled + ((tx & 0x7) * 2) + ((ty & 0x7) * 16) + 1];
 
688
                                        tiled = snes_vram[(((tx >> 3) & 0x7f) + (((ty >> 3) & 0x7f) * 128)) * 2] << 7;
 
689
                                        colour = snes_vram[tiled + ((tx & 0x07) * 2) + ((ty & 0x07) * 16) + 1];
1293
690
                                }
1294
691
                                else
1295
 
                                {
1296
692
                                        colour = 0;
1297
 
                                }
1298
693
                                break;
1299
 
                        case 0xC0:      /* Character 0x00 repeat if outside screen area */
1300
 
                                if( (tx & 0x7fff) < 1024 && (ty & 0x7fff) < 1024 )
1301
 
                                {
1302
 
                                        tiled = snes_vram[(((tx & 0x3ff) >> 3) * 2) + (((ty & 0x3ff) >> 3) * 128 * 2)] << 7;
1303
 
                                        colour = snes_vram[tiled + ((tx & 0x7) * 2) + ((ty & 0x7) * 16) + 1];
1304
 
                                }
 
694
                        case 0x03:      /* Character 0x00 repeat if outside screen area */
 
695
                                if ((tx > 0) && (tx < 1024) && (ty > 0) && (ty < 1024))
 
696
                                        tiled = snes_vram[(((tx >> 3) & 0x7f) + (((ty >> 3) & 0x7f) * 128)) * 2] << 7;
1305
697
                                else
1306
 
                                {
1307
 
                                        colour = snes_vram[((sx & 0x7) * 2) + ((sy & 0x7) * 16) + 1];
1308
 
                                }
 
698
                                        tiled = 0;
 
699
 
 
700
                                colour = snes_vram[tiled + ((tx & 0x07) * 2) + ((ty & 0x07) * 16) + 1];
1309
701
                                break;
1310
702
                }
1311
703
 
1312
 
                /* The last bit is for priority in EXTBG mode */
1313
 
                if( snes_ram[SETINI] & 0x40 )
 
704
                /* The last bit is for priority in EXTBG mode (used only for BG2) */
 
705
                if (layer == 1)
1314
706
                {
1315
 
                        priority = (colour & 0x80) >> 7;
 
707
                        priority = ((colour & 0x80) >> 7) ? priority_b : priority_a;
1316
708
                        colour &= 0x7f;
1317
709
                }
1318
710
 
1319
 
                colour &= snes_ppu.clipmasks[0][xpos];
 
711
                window_enabled = (screen == MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
 
712
                if (window_enabled)
 
713
                        colour &= snes_ppu.clipmasks[layer][xpos];
1320
714
 
1321
715
                /* Draw pixel if appropriate */
1322
 
                if( scanlines[screen].zbuf[xpos] < table_bgd_pty[1][0][priority] && colour > 0 )
 
716
                if (scanlines[screen].zbuf[xpos] <= priority && colour > 0)
1323
717
                {
1324
718
                        UINT16 clr;
1325
 
                        /* Direct select */
1326
 
                        if( snes_ram[CGWSEL] & 0x1 )
1327
 
                                clr = ((colour & 0x7) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
 
719
                        /* Direct select, but only outside EXTBG! */
 
720
                        if (snes_ppu.direct_color && layer == 0)
 
721
                        {
 
722
                                /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */
 
723
                                clr = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
 
724
                        }
1328
725
                        else
1329
726
                                clr = snes_cgram[colour];
1330
727
                        /* Only blend main screens */
1331
 
                        if( screen == MAINSCREEN )
1332
 
                                snes_draw_blend(xpos, &clr, snes_ppu.layer[0].blend, (snes_ram[CGWSEL] & 0x30) >> 4 );          /* FIXME: Need to support clip mode */
 
728
                        if (screen == MAINSCREEN)
 
729
                                snes_draw_blend(xpos, &clr, snes_ppu.layer[layer].blend, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); /* FIXME: Need to support clip mode */
1333
730
 
1334
731
                        scanlines[screen].buffer[xpos] = clr;
1335
 
                        scanlines[screen].zbuf[xpos] = table_bgd_pty[1][0][priority];
 
732
                        scanlines[screen].zbuf[xpos] = priority;
1336
733
                }
1337
734
        }
1338
735
}
1343
740
 * Update an entire line of sprites.
1344
741
 * FIXME: We need to support high priority bit
1345
742
 *********************************************/
1346
 
static void snes_update_objects(UINT8 screen, UINT16 curline )
 
743
static void snes_update_objects( UINT8 screen, UINT8 priority_tbl, UINT16 curline )
1347
744
{
1348
745
        INT8 xs, ys;
1349
746
        UINT8 line, widemode = 0;
1355
752
        INT16 i, x, y;
1356
753
        UINT8 *oamram = (UINT8 *)snes_oam;
1357
754
        UINT32 name_sel = 0;
 
755
        static const UINT8 table_obj_priority[10][4] = {
 
756
                                                {2, 5, 8, 11},  // mode 0
 
757
                                                {1, 3, 6, 9},   // mode 1
 
758
                                                {1, 3, 5, 7},   // mode 2
 
759
                                                {1, 3, 5, 7},   // mode 3
 
760
                                                {1, 3, 5, 7},   // mode 4
 
761
                                                {1, 3, 5, 7},   // mode 5
 
762
                                                {0, 2, 3, 5},   // mode 6
 
763
                                                {0, 2, 3, 4},   // mode 7
 
764
                                                {1, 3, 5, 6},   // mode 7 EXTBG
 
765
                                                {1, 2, 5, 8}    // mode 1 + BG3 priority bit
 
766
                                        };
1358
767
 
1359
 
#ifdef SNES_DBG_video
 
768
#ifdef MAME_DEBUG
1360
769
        if( debug_options.bg_disabled[4] )
1361
770
                return;
1362
 
#endif /* SNES_DBG_video */
 
771
#endif /* MAME_DEBUG */
1363
772
 
1364
773
        if( snes_ppu.mode == 5 || snes_ppu.mode == 6 )
1365
774
                widemode = 1;
1366
775
 
 
776
        curline/=snes_ppu.interlace;
 
777
        curline*=snes_ppu.obj_interlace;
 
778
 
1367
779
        oam = 0x1ff;
1368
780
        oam_extra = oam + 0x20;
1369
781
        extra = 0;
1374
786
 
1375
787
                vflip = (oamram[oam] & 0x80) >> 7;
1376
788
                hflip = (oamram[oam] & 0x40) >> 6;
1377
 
                priority = table_obj_pty[(oamram[oam] & 0x30) >> 4];
1378
 
                pal = 128 + ((oamram[oam] & 0xE) << 3);
 
789
                priority = table_obj_priority[priority_tbl][(oamram[oam] & 0x30) >> 4];
 
790
                pal = 128 + ((oamram[oam] & 0x0e) << 3);
1379
791
                tile = (oamram[oam--] & 0x1) << 8;
1380
792
                tile |= oamram[oam--];
1381
793
                y = oamram[oam--] + 1;  /* We seem to need to add one here.... */
1384
796
                extra <<= 1;
1385
797
                x |= ((extra & 0x80) << 1);
1386
798
                extra <<= 1;
 
799
                y*=snes_ppu.obj_interlace;
1387
800
 
1388
801
                /* Adjust if past maximum position */
1389
 
                if( y >= snes_ppu.beam.last_visible_line )
1390
 
                        y -= 256;
 
802
                if( y >= snes_ppu.beam.last_visible_line*snes_ppu.interlace )
 
803
                        y -= 256*snes_ppu.interlace;
1391
804
                if( x > 255 )
1392
805
                        x -= 512;
1393
806
 
1417
830
                                        if( (x + (count << 3) < SNES_SCR_WIDTH + 8) )
1418
831
                                        {
1419
832
                                                if( widemode )
1420
 
                                                        snes_draw_tile_object_w(screen, snes_ppu.layer[4].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend );
 
833
                                                        snes_draw_tile_object(screen, snes_ppu.layer[4].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend, 1);
1421
834
                                                else
1422
 
                                                        snes_draw_tile_object(screen, snes_ppu.layer[4].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend );
 
835
                                                        snes_draw_tile_object(screen, snes_ppu.layer[4].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend, 0);
1423
836
                                        }
1424
837
                                        time_over++;    /* Increase time_over. Should we stop drawing if exceeded 34 tiles? */
1425
838
                                }
1431
844
                                        if( (x + (xs << 3) < SNES_SCR_WIDTH + 8) )
1432
845
                                        {
1433
846
                                                if( widemode )
1434
 
                                                        snes_draw_tile_object_w(screen, snes_ppu.layer[4].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend );
 
847
                                                        snes_draw_tile_object(screen, snes_ppu.layer[4].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend, 1);
1435
848
                                                else
1436
 
                                                        snes_draw_tile_object(screen, snes_ppu.layer[4].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend );
 
849
                                                        snes_draw_tile_object(screen, snes_ppu.layer[4].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend, 0);
1437
850
                                        }
1438
851
                                        time_over++;    /* Increase time_over. Should we stop drawing if exceeded 34 tiles? */
1439
852
                                }
1461
874
        }
1462
875
}
1463
876
 
 
877
 
 
878
/*********************************************
 
879
 * snes_update_mode_X()
 
880
 *
 
881
 * Update Mode X line.
 
882
 *********************************************/
 
883
static void snes_update_mode_0( UINT8 screen, UINT16 curline )
 
884
{
 
885
        UINT8 *bg_enabled;
 
886
        bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
 
887
 
 
888
        if (bg_enabled[4]) snes_update_objects(screen, 0, curline);
 
889
        if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 7, 10, 0, curline, 0, 0);
 
890
        if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 6, 9, 1, curline, 0, 0);
 
891
        if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 1, 4, 2, curline, 0, 0);
 
892
        if (bg_enabled[3]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 3, 3, curline, 0, 0);
 
893
}
 
894
 
 
895
static void snes_update_mode_1( UINT8 screen, UINT16 curline )
 
896
{
 
897
        UINT8 *bg_enabled;
 
898
        bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
 
899
 
 
900
        if (!snes_ppu.bg3_priority_bit)
 
901
        {
 
902
                if (bg_enabled[4]) snes_update_objects(screen, 1, curline);
 
903
                if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 5, 8, 0, curline, 0, 0);
 
904
                if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 4, 7, 1, curline, 0, 0);
 
905
                if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 2, 2, curline, 0, 0);
 
906
        }
 
907
        else
 
908
        {
 
909
                if (bg_enabled[4]) snes_update_objects(screen, 9, curline);
 
910
                if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 4, 7, 0, curline, 0, 0);
 
911
                if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 3, 6, 1, curline, 0, 0);
 
912
                if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 9, 2, curline, 0, 0);
 
913
        }
 
914
}
 
915
 
 
916
static void snes_update_mode_2( UINT8 screen, UINT16 curline )
 
917
{
 
918
        UINT8 *bg_enabled;
 
919
        bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
 
920
 
 
921
        if (bg_enabled[4]) snes_update_objects(screen, 2, curline);
 
922
        if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 2, 6, 0, curline, 1, 0);
 
923
        if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 0, 4, 1, curline, 1, 0);
 
924
}
 
925
 
 
926
static void snes_update_mode_3( UINT8 screen, UINT16 curline )
 
927
{
 
928
        UINT8 *bg_enabled;
 
929
        bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
 
930
 
 
931
        if (bg_enabled[4]) snes_update_objects(screen, 3, curline);
 
932
        if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, 0, curline, 0, snes_ppu.direct_color);
 
933
        if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 0, 4, 1, curline, 0, 0);
 
934
}
 
935
 
 
936
static void snes_update_mode_4( UINT8 screen, UINT16 curline )
 
937
{
 
938
        UINT8 *bg_enabled;
 
939
        bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
 
940
 
 
941
        if (bg_enabled[4]) snes_update_objects(screen, 4, curline);
 
942
        if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, 0, curline, 0, snes_ppu.direct_color);
 
943
        if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 4, 1, curline, 0, 0);
 
944
}
 
945
 
 
946
static void snes_update_mode_5( UINT8 screen, UINT16 curline )
 
947
{
 
948
        UINT8 *bg_enabled;
 
949
        bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
 
950
 
 
951
        if (bg_enabled[4]) snes_update_objects(screen, 5, curline);
 
952
        if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 2, 6, 0, curline, 0, 0);
 
953
        if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 1, 0, 4, 1, curline, 0, 0);
 
954
}
 
955
 
 
956
static void snes_update_mode_6( UINT8 screen, UINT16 curline )
 
957
{
 
958
        UINT8 *bg_enabled;
 
959
        bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
 
960
 
 
961
        if (bg_enabled[4]) snes_update_objects(screen, 6, curline);
 
962
        if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 1, 4, 0, curline, 1, 0);
 
963
}
 
964
 
 
965
static void snes_update_mode_7( UINT8 screen, UINT16 curline )
 
966
{
 
967
        UINT8 extbg_mode = snes_ram[SETINI] & 0x40;
 
968
        UINT8 *bg_enabled;
 
969
        bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
 
970
 
 
971
        if (!extbg_mode)
 
972
        {
 
973
                if (bg_enabled[4]) snes_update_objects(screen, 7, curline);
 
974
                if (bg_enabled[0]) snes_update_line_mode7(screen, 1, 1, 0, curline);
 
975
        }
 
976
        else
 
977
        {
 
978
                if (bg_enabled[4]) snes_update_objects(screen, 8, curline);
 
979
                if (bg_enabled[0]) snes_update_line_mode7(screen, 2, 2, 0, curline);
 
980
                if (bg_enabled[1]) snes_update_line_mode7(screen, 0, 4, 1, curline);
 
981
        }
 
982
}
 
983
 
 
984
/*********************************************
 
985
 * snes_draw_screen()
 
986
 *
 
987
 * Draw the whole screen (Mode 0 -> 7).
 
988
 *********************************************/
 
989
static void snes_draw_screen( UINT8 screen, UINT16 curline )
 
990
{
 
991
        switch (snes_ppu.mode)
 
992
        {
 
993
                case 0: snes_update_mode_0(screen, curline); break;             /* Mode 0 */
 
994
                case 1: snes_update_mode_1(screen, curline); break;             /* Mode 1 */
 
995
                case 2: snes_update_mode_2(screen, curline); break;             /* Mode 2 - Supports offset per tile */
 
996
                case 3: snes_update_mode_3(screen, curline); break;             /* Mode 3 - Supports direct colour */
 
997
                case 4: snes_update_mode_4(screen, curline); break;             /* Mode 4 - Supports offset per tile and direct colour */
 
998
                case 5: snes_update_mode_5(screen, curline); break;             /* Mode 5 - Supports hires */
 
999
                case 6: snes_update_mode_6(screen, curline); break;             /* Mode 6 - Supports offset per tile and hires */
 
1000
                case 7: snes_update_mode_7(screen, curline); break;             /* Mode 7 - Supports direct colour */
 
1001
        }
 
1002
}
 
1003
 
1464
1004
/*********************************************
1465
1005
 * snes_update_windowmasks()
1466
1006
 *
1475
1015
 *********************************************/
1476
1016
static void snes_update_windowmasks(void)
1477
1017
{
1478
 
        UINT16 ii;
 
1018
        UINT16 ii, jj;
1479
1019
        INT8 w1, w2;
1480
1020
 
1481
1021
        snes_ppu.update_windows = 0;            /* reset the flag */
1482
1022
 
1483
 
        for( ii = 0; ii < SNES_SCR_WIDTH; ii++ )
 
1023
        for (ii = 0; ii < SNES_SCR_WIDTH + 8; ii++)
1484
1024
        {
1485
 
                /* update bg 1 */
1486
 
                snes_ppu.clipmasks[0][ii] = 0xff;
1487
 
                w1 = w2 = -1;
1488
 
                if( snes_ram[W12SEL] & 0x2 )
1489
 
                {
1490
 
                        if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
1491
 
                                w1 = 0;
1492
 
                        else
1493
 
                                w1 = 1;
1494
 
                        if( snes_ram[W12SEL] & 0x1 )
1495
 
                                w1 = !w1;
1496
 
                }
1497
 
                if( snes_ram[W12SEL] & 0x8 )
1498
 
                {
1499
 
                        if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1500
 
                                w2 = 0;
1501
 
                        else
1502
 
                                w2 = 1;
1503
 
                        if( snes_ram[W12SEL] & 0x4 )
1504
 
                                w2 = !w2;
1505
 
                }
1506
 
                if( w1 >= 0 && w2 >= 0 )
1507
 
                {
1508
 
                        switch( snes_ram[WBGLOG] & 0x3 )
1509
 
                        {
1510
 
                                case 0x0:       /* OR */
1511
 
                                        snes_ppu.clipmasks[0][ii] = w1 | w2 ? 0x00 : 0xff;
1512
 
                                        break;
1513
 
                                case 0x1:       /* AND */
1514
 
                                        snes_ppu.clipmasks[0][ii] = w1 & w2 ? 0x00 : 0xff;
1515
 
                                        break;
1516
 
                                case 0x2:       /* XOR */
1517
 
                                        snes_ppu.clipmasks[0][ii] = w1 ^ w2 ? 0x00 : 0xff;
1518
 
                                        break;
1519
 
                                case 0x3:       /* XNOR */
1520
 
                                        snes_ppu.clipmasks[0][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1521
 
                                        break;
1522
 
                        }
1523
 
                }
1524
 
                else if( w1 >= 0 )
1525
 
                        snes_ppu.clipmasks[0][ii] = w1 ? 0x00 : 0xff;
1526
 
                else if( w2 >= 0 )
1527
 
                        snes_ppu.clipmasks[0][ii] = w2 ? 0x00 : 0xff;
1528
 
 
1529
 
                /* update bg 2 */
1530
 
                snes_ppu.clipmasks[1][ii] = 0xff;
1531
 
                w1 = w2 = -1;
1532
 
                if( snes_ram[W12SEL] & 0x20 )
1533
 
                {
1534
 
                        if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
1535
 
                                w1 = 0;
1536
 
                        else
1537
 
                                w1 = 1;
1538
 
                        if( snes_ram[W12SEL] & 0x10 )
1539
 
                                w1 = !w1;
1540
 
                }
1541
 
                if( snes_ram[W12SEL] & 0x80 )
1542
 
                {
1543
 
                        if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1544
 
                                w2 = 0;
1545
 
                        else
1546
 
                                w2 = 1;
1547
 
                        if( snes_ram[W12SEL] & 0x40 )
1548
 
                                w2 = !w2;
1549
 
                }
1550
 
                if( w1 >= 0 && w2 >= 0 )
1551
 
                {
1552
 
                        switch( snes_ram[WBGLOG] & 0xc )
1553
 
                        {
1554
 
                                case 0x0:       /* OR */
1555
 
                                        snes_ppu.clipmasks[1][ii] = w1 | w2 ? 0x00 : 0xff;
1556
 
                                        break;
1557
 
                                case 0x4:       /* AND */
1558
 
                                        snes_ppu.clipmasks[1][ii] = w1 & w2 ? 0x00 : 0xff;
1559
 
                                        break;
1560
 
                                case 0x8:       /* XOR */
1561
 
                                        snes_ppu.clipmasks[1][ii] = w1 ^ w2 ? 0x00 : 0xff;
1562
 
                                        break;
1563
 
                                case 0xc:       /* XNOR */
1564
 
                                        snes_ppu.clipmasks[1][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1565
 
                                        break;
1566
 
                        }
1567
 
                }
1568
 
                else if( w1 >= 0 )
1569
 
                        snes_ppu.clipmasks[1][ii] = w1 ? 0x00 : 0xff;
1570
 
                else if( w2 >= 0 )
1571
 
                        snes_ppu.clipmasks[1][ii] = w2 ? 0x00 : 0xff;
1572
 
 
1573
 
                /* update bg 3 */
1574
 
                snes_ppu.clipmasks[2][ii] = 0xff;
1575
 
                w1 = w2 = -1;
1576
 
                if( snes_ram[W34SEL] & 0x2 )
1577
 
                {
1578
 
                        if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
1579
 
                                w1 = 0;
1580
 
                        else
1581
 
                                w1 = 1;
1582
 
                        if( snes_ram[W34SEL] & 0x1 )
1583
 
                                w1 = !w1;
1584
 
                }
1585
 
                if( snes_ram[W34SEL] & 0x8 )
1586
 
                {
1587
 
                        if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1588
 
                                w2 = 0;
1589
 
                        else
1590
 
                                w2 = 1;
1591
 
                        if( snes_ram[W34SEL] & 0x4 )
1592
 
                                w2 = !w2;
1593
 
                }
1594
 
                if( w1 >= 0 && w2 >= 0 )
1595
 
                {
1596
 
                        switch( snes_ram[WBGLOG] & 0x30 )
1597
 
                        {
1598
 
                                case 0x0:       /* OR */
1599
 
                                        snes_ppu.clipmasks[2][ii] = w1 | w2 ? 0x00 : 0xff;
1600
 
                                        break;
1601
 
                                case 0x10:      /* AND */
1602
 
                                        snes_ppu.clipmasks[2][ii] = w1 & w2 ? 0x00 : 0xff;
1603
 
                                        break;
1604
 
                                case 0x20:      /* XOR */
1605
 
                                        snes_ppu.clipmasks[2][ii] = w1 ^ w2 ? 0x00 : 0xff;
1606
 
                                        break;
1607
 
                                case 0x30:      /* XNOR */
1608
 
                                        snes_ppu.clipmasks[2][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1609
 
                                        break;
1610
 
                        }
1611
 
                }
1612
 
                else if( w1 >= 0 )
1613
 
                        snes_ppu.clipmasks[2][ii] = w1 ? 0x00 : 0xff;
1614
 
                else if( w2 >= 0 )
1615
 
                        snes_ppu.clipmasks[2][ii] = w2 ? 0x00 : 0xff;
1616
 
 
1617
 
                /* update bg 4 */
1618
 
                snes_ppu.clipmasks[3][ii] = 0xff;
1619
 
                w1 = w2 = -1;
1620
 
                if( snes_ram[W34SEL] & 0x20 )
1621
 
                {
1622
 
                        if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
1623
 
                                w1 = 0;
1624
 
                        else
1625
 
                                w1 = 1;
1626
 
                        if( snes_ram[W34SEL] & 0x10 )
1627
 
                                w1 = !w1;
1628
 
                }
1629
 
                if( snes_ram[W34SEL] & 0x80 )
1630
 
                {
1631
 
                        if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1632
 
                                w2 = 0;
1633
 
                        else
1634
 
                                w2 = 1;
1635
 
                        if( snes_ram[W34SEL] & 0x40 )
1636
 
                                w2 = !w2;
1637
 
                }
1638
 
                if( w1 >= 0 && w2 >= 0 )
1639
 
                {
1640
 
                        switch( snes_ram[WBGLOG] & 0xc0 )
1641
 
                        {
1642
 
                                case 0x0:       /* OR */
1643
 
                                        snes_ppu.clipmasks[3][ii] = w1 | w2 ? 0x00 : 0xff;
1644
 
                                        break;
1645
 
                                case 0x40:      /* AND */
1646
 
                                        snes_ppu.clipmasks[3][ii] = w1 & w2 ? 0x00 : 0xff;
1647
 
                                        break;
1648
 
                                case 0x80:      /* XOR */
1649
 
                                        snes_ppu.clipmasks[3][ii] = w1 ^ w2 ? 0x00 : 0xff;
1650
 
                                        break;
1651
 
                                case 0xc0:      /* XNOR */
1652
 
                                        snes_ppu.clipmasks[3][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1653
 
                                        break;
1654
 
                        }
1655
 
                }
1656
 
                else if( w1 >= 0 )
1657
 
                        snes_ppu.clipmasks[3][ii] = w1 ? 0x00 : 0xff;
1658
 
                else if( w2 >= 0 )
1659
 
                        snes_ppu.clipmasks[3][ii] = w2 ? 0x00 : 0xff;
1660
 
 
1661
 
                /* update objects */
1662
 
                snes_ppu.clipmasks[4][ii] = 0xff;
1663
 
                w1 = w2 = -1;
1664
 
                if( snes_ram[WOBJSEL] & 0x2 )
1665
 
                {
1666
 
                        if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
1667
 
                                w1 = 0;
1668
 
                        else
1669
 
                                w1 = 1;
1670
 
                        if( snes_ram[WOBJSEL] & 0x1 )
1671
 
                                w1 = !w1;
1672
 
                }
1673
 
                if( snes_ram[WOBJSEL] & 0x8 )
1674
 
                {
1675
 
                        if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1676
 
                                w2 = 0;
1677
 
                        else
1678
 
                                w2 = 1;
1679
 
                        if( snes_ram[WOBJSEL] & 0x4 )
1680
 
                                w2 = !w2;
1681
 
                }
1682
 
                if( w1 >= 0 && w2 >= 0 )
1683
 
                {
1684
 
                        switch( snes_ram[WOBJLOG] & 0x3 )
1685
 
                        {
1686
 
                                case 0x0:       /* OR */
1687
 
                                        snes_ppu.clipmasks[4][ii] = w1 | w2 ? 0x00 : 0xff;
1688
 
                                        break;
1689
 
                                case 0x1:       /* AND */
1690
 
                                        snes_ppu.clipmasks[4][ii] = w1 & w2 ? 0x00 : 0xff;
1691
 
                                        break;
1692
 
                                case 0x2:       /* XOR */
1693
 
                                        snes_ppu.clipmasks[4][ii] = w1 ^ w2 ? 0x00 : 0xff;
1694
 
                                        break;
1695
 
                                case 0x3:       /* XNOR */
1696
 
                                        snes_ppu.clipmasks[4][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1697
 
                                        break;
1698
 
                        }
1699
 
                }
1700
 
                else if( w1 >= 0 )
1701
 
                        snes_ppu.clipmasks[4][ii] = w1 ? 0x00 : 0xff;
1702
 
                else if( w2 >= 0 )
1703
 
                        snes_ppu.clipmasks[4][ii] = w2 ? 0x00 : 0xff;
 
1025
                /* update bg 1, 2, 3, 4 & obj */
 
1026
                /* jj = layer */
 
1027
                for (jj = 0; jj < 5; jj++)
 
1028
                {
 
1029
                        snes_ppu.clipmasks[jj][ii] = 0xff;
 
1030
                        w1 = w2 = -1;
 
1031
                        if (snes_ppu.layer[jj].window1_enabled)
 
1032
                        {
 
1033
                                if ((ii < snes_ppu.window1_left) || (ii > snes_ppu.window1_right))
 
1034
                                        w1 = 0;
 
1035
                                else
 
1036
                                        w1 = 1;
 
1037
                                if (snes_ppu.layer[jj].window1_invert)
 
1038
                                        w1 = !w1;
 
1039
                        }
 
1040
                        if (snes_ppu.layer[jj].window2_enabled)
 
1041
                        {
 
1042
                                if ((ii < snes_ppu.window2_left) || (ii > snes_ppu.window2_right))
 
1043
                                        w2 = 0;
 
1044
                                else
 
1045
                                        w2 = 1;
 
1046
                                if (snes_ppu.layer[jj].window2_invert)
 
1047
                                        w2 = !w2;
 
1048
                        }
 
1049
                        if (w1 >= 0 && w2 >= 0)
 
1050
                        {
 
1051
                                switch (snes_ppu.layer[jj].wlog_mask)
 
1052
                                {
 
1053
                                        case 0x00:      /* OR */
 
1054
                                                snes_ppu.clipmasks[jj][ii] = w1 | w2 ? 0x00 : 0xff;
 
1055
                                                break;
 
1056
                                        case 0x01:      /* AND */
 
1057
                                                snes_ppu.clipmasks[jj][ii] = w1 & w2 ? 0x00 : 0xff;
 
1058
                                                break;
 
1059
                                        case 0x02:      /* XOR */
 
1060
                                                snes_ppu.clipmasks[jj][ii] = w1 ^ w2 ? 0x00 : 0xff;
 
1061
                                                break;
 
1062
                                        case 0x03:      /* XNOR */
 
1063
                                                snes_ppu.clipmasks[jj][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
 
1064
                                                break;
 
1065
                                }
 
1066
                        }
 
1067
                        else if( w1 >= 0 )
 
1068
                                snes_ppu.clipmasks[jj][ii] = w1 ? 0x00 : 0xff;
 
1069
                        else if( w2 >= 0 )
 
1070
                                snes_ppu.clipmasks[jj][ii] = w2 ? 0x00 : 0xff;
 
1071
                }
1704
1072
 
1705
1073
                /* update colour window */
1706
 
                /* FIXME: Why is the colour window different to the other windows? *
1707
 
         * Have I overlooked something or done something wrong? */
1708
1074
                snes_ppu.clipmasks[5][ii] = 0xff;
1709
1075
                w1 = w2 = -1;
1710
 
                if( snes_ram[WOBJSEL] & 0x20 )
 
1076
                if (snes_ppu.colour.window1_enabled)
1711
1077
                {
1712
1078
                        /* Default to mask area inside */
1713
 
                        if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
 
1079
                        if ((ii < snes_ppu.window1_left) || (ii > snes_ppu.window1_right))
1714
1080
                                w1 = 0;
1715
1081
                        else
1716
1082
                                w1 = 1;
1717
1083
                        /* If mask area is outside then swap */
1718
 
                        if( snes_ram[WOBJSEL] & 0x10 )
 
1084
                        if (snes_ppu.colour.window1_invert)
1719
1085
                                w1 = !w1;
1720
1086
                }
1721
 
                if( snes_ram[WOBJSEL] & 0x80 )
 
1087
                if (snes_ppu.colour.window2_enabled)
1722
1088
                {
1723
 
                        /* Default to mask area inside */
1724
 
                        if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
 
1089
                        if ((ii < snes_ppu.window2_left) || (ii > snes_ppu.window2_right))
1725
1090
                                w2 = 0;
1726
1091
                        else
1727
1092
                                w2 = 1;
1728
 
                        /* If mask area is outside then swap */
1729
 
                        if( snes_ram[WOBJSEL] & 0x40 )
 
1093
                        if (snes_ppu.colour.window2_invert)
1730
1094
                                w2 = !w2;
1731
1095
                }
1732
1096
                if( w1 >= 0 && w2 >= 0 )
1733
1097
                {
1734
 
                        switch( snes_ram[WOBJLOG] & 0xc )
 
1098
                        switch (snes_ppu.colour.wlog_mask)
1735
1099
                        {
1736
1100
                                case 0x0:       /* OR */
1737
 
                                        snes_ppu.clipmasks[5][ii] = w1 | w2 ? 0xff : 0x00;
1738
 
/*                  snes_ppu.clipmasks[5][ii] = w1 | w2 ? 0x00 : 0xff;*/
 
1101
                                        snes_ppu.clipmasks[5][ii] = w1 | w2 ? 0x00 : 0xff;
1739
1102
                                        break;
1740
1103
                                case 0x4:       /* AND */
1741
 
                                        snes_ppu.clipmasks[5][ii] = w1 & w2 ? 0xff : 0x00;
1742
 
/*                  snes_ppu.clipmasks[5][ii] = w1 & w2 ? 0x00 : 0xff;*/
 
1104
                                        snes_ppu.clipmasks[5][ii] = w1 & w2 ? 0x00 : 0xff;
1743
1105
                                        break;
1744
1106
                                case 0x8:       /* XOR */
1745
 
                                        snes_ppu.clipmasks[5][ii] = w1 ^ w2 ? 0xff : 0x00;
1746
 
/*                  snes_ppu.clipmasks[5][ii] = w1 ^ w2 ? 0x00 : 0xff;*/
 
1107
                                        snes_ppu.clipmasks[5][ii] = w1 ^ w2 ? 0x00 : 0xff;
1747
1108
                                        break;
1748
1109
                                case 0xc:       /* XNOR */
1749
 
                                        snes_ppu.clipmasks[5][ii] = !(w1 ^ w2) ? 0xff : 0x00;
1750
 
/*                  snes_ppu.clipmasks[5][ii] = !(w1 ^ w2) ? 0x00 : 0xff;*/
 
1110
                                        snes_ppu.clipmasks[5][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1751
1111
                                        break;
1752
1112
                        }
1753
1113
                }
1754
1114
                else if( w1 >= 0 )
1755
 
                        snes_ppu.clipmasks[5][ii] = w1 ? 0xff : 0x00;
1756
 
/*          snes_ppu.clipmasks[5][ii] = w1 ? 0x00 : 0xff;*/
 
1115
                        snes_ppu.clipmasks[5][ii] = w1 ? 0x00 : 0xff;
1757
1116
                else if( w2 >= 0 )
1758
 
                        snes_ppu.clipmasks[5][ii] = w2 ? 0xff : 0x00;
1759
 
/*          snes_ppu.clipmasks[5][ii] = w2 ? 0x00 : 0xff;*/
 
1117
                        snes_ppu.clipmasks[5][ii] = w2 ? 0x00 : 0xff;
1760
1118
        }
1761
1119
}
1762
1120
 
1775
1133
                snes_ppu.layer[ii].offset.tile_vert = (snes_ppu.layer[ii].offset.vertical & 0x3ff) >> (3 + snes_ppu.layer[ii].tile_size);
1776
1134
                snes_ppu.layer[ii].offset.shift_vert = snes_ppu.layer[ii].offset.vertical & ((8 << snes_ppu.layer[ii].tile_size) - 1);
1777
1135
        }
 
1136
        #if 0
 
1137
        popmessage("%04x %04x|%04x %04x|%04x %04x|%04x %04x",
 
1138
        snes_ppu.layer[0].offset.tile_horz,
 
1139
        snes_ppu.layer[0].offset.tile_vert,
 
1140
        snes_ppu.layer[1].offset.tile_horz,
 
1141
        snes_ppu.layer[1].offset.tile_vert,
 
1142
        snes_ppu.layer[2].offset.tile_horz,
 
1143
        snes_ppu.layer[2].offset.tile_vert,
 
1144
        snes_ppu.layer[3].offset.tile_horz,
 
1145
        snes_ppu.layer[3].offset.tile_vert
 
1146
        );
 
1147
        #endif
1778
1148
        snes_ppu.update_offsets = 0;
1779
1149
}
1780
1150
 
1783
1153
 *
1784
1154
 * Redraw the current line.
1785
1155
 *********************************************/
1786
 
static void snes_refresh_scanline(bitmap_t *bitmap, UINT16 curline )
 
1156
static void snes_refresh_scanline( running_machine *machine, bitmap_t *bitmap, UINT16 curline )
1787
1157
{
1788
1158
        UINT16 ii;
1789
1159
        int x;
1790
1160
        int fade;
1791
1161
        struct SCANLINE *scanline;
1792
1162
 
1793
 
        profiler_mark(PROFILER_VIDEO);
 
1163
        profiler_mark_start(PROFILER_VIDEO);
1794
1164
 
1795
 
        if( snes_ram[INIDISP] & 0x80 ) /* screen is forced blank */
1796
 
                for (x = 0; x < SNES_SCR_WIDTH; x++)
 
1165
        if (snes_ram[INIDISP] & 0x80) /* screen is forced blank */
 
1166
                for (x = 0; x < SNES_SCR_WIDTH * 2; x++)
1797
1167
                        *BITMAP_ADDR32(bitmap, curline, x) = RGB_BLACK;
1798
1168
        else
1799
1169
        {
1800
1170
                /* Update clip window masks if necessary */
1801
 
                if( snes_ppu.update_windows )
 
1171
                if (snes_ppu.update_windows)
1802
1172
                        snes_update_windowmasks();
1803
1173
                /* Update the offsets if necessary */
1804
 
                if( snes_ppu.update_offsets )
 
1174
                if (snes_ppu.update_offsets)
1805
1175
                        snes_update_offsets();
1806
1176
 
1807
1177
                /* Clear zbuffers */
1808
 
                memset( scanlines[MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2 );
1809
 
                memset( scanlines[SUBSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2 );
 
1178
                memset(scanlines[MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
 
1179
                memset(scanlines[SUBSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
1810
1180
 
1811
1181
                /* Clear subscreen and draw back colour */
1812
 
                for( ii = 0; ii < SNES_SCR_WIDTH * 2; ii++ )
 
1182
                for (ii = 0; ii < SNES_SCR_WIDTH * 2; ii++)
1813
1183
                {
1814
1184
                        /* Not sure if this is correct behaviour, but a few games seem to
1815
1185
             * require it. (SMW, Zelda etc) */
1819
1189
                }
1820
1190
 
1821
1191
                /* Draw subscreen */
1822
 
                if( snes_ram[TS] & 0x10 )
1823
 
                        snes_update_objects(SUBSCREEN, curline );
1824
 
                for( ii = 0; ii < snes_modedefs[snes_ppu.mode].count; ii++ )
1825
 
                {
1826
 
                        if( snes_ram[TS] & (0x1 << ii) )
1827
 
                                snes_modedefs[snes_ppu.mode].drawLayer[ii](SUBSCREEN, ii, curline );
1828
 
                }
 
1192
                snes_draw_screen(SUBSCREEN, curline);
 
1193
 
1829
1194
                /* Draw the back plane */
1830
 
#ifdef SNES_DBG_video
1831
 
                if( !debug_options.bg_disabled[5] )
1832
 
#endif /* SNES_DBG_video */
1833
 
                if( snes_ram[CGADSUB] & 0x20 )
 
1195
#ifdef MAME_DEBUG
 
1196
                if (!debug_options.bg_disabled[5])
 
1197
#endif /* MAME_DEBUG */
 
1198
                if (snes_ram[CGADSUB] & 0x20)
1834
1199
                {
1835
 
                        for( ii = 0; ii < SNES_SCR_WIDTH; ii++ )
 
1200
                        for(ii = 0; ii < SNES_SCR_WIDTH * snes_htmult; ii++)
1836
1201
                        {
1837
 
                                snes_draw_blend(ii, &scanlines[MAINSCREEN].buffer[ii], (snes_ram[CGADSUB] & 0x80)?SNES_BLEND_SUB:SNES_BLEND_ADD, (snes_ram[CGWSEL] & 0x30) >> 4 );
 
1202
                                snes_draw_blend(ii/snes_htmult, &scanlines[MAINSCREEN].buffer[ii], (snes_ram[CGADSUB] & 0x80) ? SNES_BLEND_SUB : SNES_BLEND_ADD, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1838
1203
                        }
1839
1204
                }
 
1205
 
1840
1206
                /* Draw mainscreen */
1841
 
                if( snes_ram[TM] & 0x10 )
1842
 
                        snes_update_objects(MAINSCREEN, curline );
1843
 
                for( ii = 0; ii < snes_modedefs[snes_ppu.mode].count; ii++ )
1844
 
                {
1845
 
                        if( snes_ram[TM] & (0x1 << ii) )
1846
 
                                snes_modedefs[snes_ppu.mode].drawLayer[ii](MAINSCREEN, ii, curline );
1847
 
                }
 
1207
                snes_draw_screen(MAINSCREEN, curline);
1848
1208
 
1849
 
#ifdef SNES_DBG_video
1850
 
                if( snes_dbg_video(bitmap, curline ) )
 
1209
#ifdef MAME_DEBUG
 
1210
                if (snes_dbg_video(machine, bitmap, curline))
1851
1211
                {
1852
 
                        profiler_mark(PROFILER_END);
 
1212
                        profiler_mark_end();
1853
1213
                        return;
1854
1214
                }
1855
1215
 
1856
1216
                /* Toggle drawing of subscreen or mainscreen */
1857
 
                if( debug_options.draw_subscreen )
 
1217
                if (debug_options.draw_subscreen)
1858
1218
                        scanline = &scanlines[SUBSCREEN];
1859
1219
                else
1860
 
#endif /* SNES_DBG_video */
 
1220
#endif /* MAME_DEBUG */
1861
1221
                        scanline = &scanlines[MAINSCREEN];
1862
1222
 
1863
1223
                /* Phew! Draw the line to screen */
1864
1224
                fade = (snes_ram[INIDISP] & 0xf) + 1;
1865
1225
 
1866
 
                for (x = 0; x < SNES_SCR_WIDTH; x++)
 
1226
                for (x = 0; x < SNES_SCR_WIDTH * 2; x++)
1867
1227
                {
1868
1228
                        int r = ((scanline->buffer[x] & 0x1f) * fade) >> 4;
1869
1229
                        int g = (((scanline->buffer[x] & 0x3e0) >> 5) * fade) >> 4;
1870
1230
                        int b = (((scanline->buffer[x] & 0x7c00) >> 10) * fade) >> 4;
1871
 
                        *BITMAP_ADDR32(bitmap, curline, x) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
 
1231
 
 
1232
                        if(snes_htmult == 1)
 
1233
                        {
 
1234
                                *BITMAP_ADDR32(bitmap, curline, x*2+0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
 
1235
                                *BITMAP_ADDR32(bitmap, curline, x*2+1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
 
1236
                        }
 
1237
                        else
 
1238
                                *BITMAP_ADDR32(bitmap, curline, x) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1872
1239
                }
1873
1240
        }
1874
1241
 
1875
 
        profiler_mark(PROFILER_END);
 
1242
        profiler_mark_end();
 
1243
}
 
1244
 
 
1245
VIDEO_START( snes )
 
1246
{
 
1247
#ifdef MAME_DEBUG
 
1248
        memset(&debug_options, 0, sizeof(debug_options));
 
1249
        debug_options.input_count = 5;
 
1250
#endif
1876
1251
}
1877
1252
 
1878
1253
VIDEO_UPDATE( snes )
1879
1254
{
1880
1255
        int y;
1881
1256
 
 
1257
        /*NTSC SNES draw range is 1-225. */
1882
1258
        for (y = cliprect->min_y; y <= cliprect->max_y; y++)
1883
 
                snes_refresh_scanline(bitmap, y);
 
1259
                snes_refresh_scanline(screen->machine, bitmap, y+1);
1884
1260
        return 0;
1885
1261
}
1886
1262
 
1887
1263
 
1888
1264
/***** Debug Functions *****/
1889
1265
 
1890
 
#ifdef SNES_DBG_video
 
1266
#ifdef MAME_DEBUG
1891
1267
 
1892
 
static void snes_dbg_draw_maps(bitmap_t *bitmap, UINT32 tmap, UINT8 bpl, UINT16 curline, UINT8 layer )
 
1268
static void snes_dbg_draw_maps( bitmap_t *bitmap, UINT32 tmap, UINT8 bpl, UINT16 curline, UINT8 layer )
1893
1269
{
1894
1270
        UINT32 tile, addr = tmap;
1895
1271
        UINT16 ii, vflip, hflip, pal;
1896
1272
        INT8 line;
1897
 
        char str[50];
1898
1273
 
1899
1274
        tmap += (curline >> 3) * 64;
1900
1275
        for( ii = 0; ii < 64; ii += 2 )
1913
1288
                        switch( bpl )
1914
1289
                        {
1915
1290
                                case 1:
1916
 
                                        snes_draw_tile_2(MAINSCREEN, layer, snes_ppu.layer[layer].data + (tile << 4) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal );
 
1291
                                        snes_draw_tile(MAINSCREEN, 2, layer, snes_ppu.layer[layer].data + (tile << 4) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
1917
1292
                                        break;
1918
1293
                                case 2:
1919
1294
                                        pal <<= 2;
1920
 
                                        snes_draw_tile_4(MAINSCREEN, layer, snes_ppu.layer[layer].data + (tile << 5) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal );
 
1295
                                        snes_draw_tile(MAINSCREEN, 4, layer, snes_ppu.layer[layer].data + (tile << 5) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
1921
1296
                                        break;
1922
1297
                                case 4:
1923
 
                                        snes_draw_tile_8(MAINSCREEN, layer, snes_ppu.layer[layer].data + (tile << 6) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip );
 
1298
                                        pal <<= 0;      // n/a
 
1299
                                        snes_draw_tile(MAINSCREEN, 8, layer, snes_ppu.layer[layer].data + (tile << 6) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
1924
1300
                                        break;
1925
1301
                        }
1926
1302
                }
1927
1303
        }
1928
1304
 
1929
 
        sprintf( str, "%d : %8X  ", layer, addr );
 
1305
        logerror("%d : %8X  ", layer, addr );
1930
1306
        //ui_draw_text( str, 0, 227 );
1931
1307
}
1932
1308
 
1933
 
static void snes_dbg_draw_all_tiles(bitmap_t *bitmap, UINT32 tileaddr, UINT8 bpl, UINT16 pal )
 
1309
static void snes_dbg_draw_all_tiles( running_machine *machine, bitmap_t *bitmap, UINT32 tileaddr, UINT8 bpl, UINT16 pal )
1934
1310
{
1935
1311
        UINT16 ii, jj, kk;
1936
1312
        UINT32 addr = tileaddr;
1937
 
        char str[50];
1938
1313
 
1939
1314
        for( jj = 0; jj < 32; jj++ )
1940
1315
        {
1951
1326
                                switch( bpl )
1952
1327
                                {
1953
1328
                                        case 1:
1954
 
                                                snes_draw_tile_2(MAINSCREEN, 0, addr, ii * 8, 255, 0, pal );
 
1329
                                                snes_draw_tile(MAINSCREEN, 2, 0, addr, ii * 8, 255, 0, pal, 0);
1955
1330
                                                break;
1956
1331
                                        case 2:
1957
 
                                                snes_draw_tile_4(MAINSCREEN, 0, addr, ii * 8, 255, 0, pal );
 
1332
                                                snes_draw_tile(MAINSCREEN, 4, 0, addr, ii * 8, 255, 0, pal, 0);
1958
1333
                                                break;
1959
1334
                                        case 4:
1960
 
                                                snes_draw_tile_8(MAINSCREEN, 0, addr, ii * 8, 255, 0 );
 
1335
                                                snes_draw_tile(MAINSCREEN, 8, 0, addr, ii * 8, 255, 0, pal, 0);
1961
1336
                                                break;
1962
1337
                                }
1963
1338
                                addr += (bpl * 16);
1972
1347
                }
1973
1348
        }
1974
1349
 
1975
 
        sprintf( str, "  %8X  ", tileaddr );
 
1350
        logerror("  %8X  ", tileaddr );
1976
1351
        //ui_draw_text( str, 0, 227 );
1977
1352
}
1978
1353
 
1979
 
static UINT8 snes_dbg_video(bitmap_t *bitmap, UINT16 curline )
 
1354
static UINT8 snes_dbg_video( running_machine *machine, bitmap_t *bitmap, UINT16 curline )
1980
1355
{
1981
1356
        UINT16 ii;
1982
1357
 
1986
1361
        if( curline == 0 )
1987
1362
        {
1988
1363
                //UINT16 y = 1;
1989
 
                char t[100];
1990
1364
                static const char WINLOGIC[4] = { '|', '&', '^', '!' };
1991
1365
 
1992
1366
                if( !debug_options.input_count-- )
2008
1382
                                debug_options.bg_disabled[5] = !debug_options.bg_disabled[5];
2009
1383
                        if( toggles & 0x80 )
2010
1384
                                debug_options.windows_disabled = !debug_options.windows_disabled;
 
1385
                        toggles = input_port_read_safe(machine, "DEBUG4", 0);
 
1386
                        if( toggles & 0x01 )
 
1387
                                debug_options.mode_disabled[0] = !debug_options.mode_disabled[0];
 
1388
                        if( toggles & 0x02 )
 
1389
                                debug_options.mode_disabled[1] = !debug_options.mode_disabled[1];
 
1390
                        if( toggles & 0x04 )
 
1391
                                debug_options.mode_disabled[2] = !debug_options.mode_disabled[2];
 
1392
                        if( toggles & 0x08 )
 
1393
                                debug_options.mode_disabled[3] = !debug_options.mode_disabled[3];
 
1394
                        if( toggles & 0x10 )
 
1395
                                debug_options.mode_disabled[4] = !debug_options.mode_disabled[4];
 
1396
                        if( toggles & 0x20 )
 
1397
                                debug_options.mode_disabled[5] = !debug_options.mode_disabled[5];
 
1398
                        if( toggles & 0x40 )
 
1399
                                debug_options.mode_disabled[6] = !debug_options.mode_disabled[6];
 
1400
                        if( toggles & 0x80 )
 
1401
                                debug_options.mode_disabled[7] = !debug_options.mode_disabled[7];
2011
1402
                        toggles = input_port_read_safe(machine, "DEBUG3", 0);
2012
1403
                        if( toggles & 0x4 )
2013
1404
                                debug_options.transparency_disabled = !debug_options.transparency_disabled;
2014
1405
                        debug_options.input_count = 5;
2015
1406
                }
2016
1407
                /* Display some debug info on the screen */
2017
 
                sprintf( t, "%s%s", debug_options.windows_disabled?" ":"W", debug_options.transparency_disabled?" ":"T" );
 
1408
                logerror("%s%s", debug_options.windows_disabled?" ":"W", debug_options.transparency_disabled?" ":"T" );
2018
1409
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2019
 
                sprintf( t, "%s1 %s%s%s%s%s%c%s%s%d%s %d %4X %4X",
 
1410
                logerror("%s1 %s%s%s%s%s%c%s%s%d%s %d %4X %4X",
2020
1411
                                debug_options.bg_disabled[0]?" ":"*",
2021
1412
                                (snes_ram[TM] & 0x1)?"M":" ",
2022
1413
                                (snes_ram[TS] & 0x1)?"S":" ",
2032
1423
                                (snes_ram[BG1SC] & 0xfc) << 9,
2033
1424
                                snes_ppu.layer[0].data );
2034
1425
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2035
 
                sprintf( t, "%s2 %s%s%s%s%s%c%s%s%d%s %d %4X %4X",
 
1426
                logerror("%s2 %s%s%s%s%s%c%s%s%d%s %d %4X %4X",
2036
1427
                                debug_options.bg_disabled[1]?" ":"*",
2037
1428
                                (snes_ram[TM] & 0x2)?"M":" ",
2038
1429
                                (snes_ram[TS] & 0x2)?"S":" ",
2048
1439
                                (snes_ram[BG2SC] & 0xfc) << 9,
2049
1440
                                snes_ppu.layer[1].data );
2050
1441
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2051
 
                sprintf( t, "%s3 %s%s%s%s%s%c%s%s%d%s%s%d %4X %4X",
 
1442
                logerror("%s3 %s%s%s%s%s%c%s%s%d%s%s%d %4X %4X",
2052
1443
                                debug_options.bg_disabled[2]?" ":"*",
2053
1444
                                (snes_ram[TM] & 0x4)?"M":" ",
2054
1445
                                (snes_ram[TS] & 0x4)?"S":" ",
2065
1456
                                (snes_ram[BG3SC] & 0xfc) << 9,
2066
1457
                                snes_ppu.layer[2].data );
2067
1458
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2068
 
                sprintf( t, "%s4 %s%s%s%s%s%c%s%s%d%s %d %4X %4X",
 
1459
                logerror("%s4 %s%s%s%s%s%c%s%s%d%s %d %4X %4X",
2069
1460
                                debug_options.bg_disabled[3]?" ":"*",
2070
1461
                                (snes_ram[TM] & 0x8)?"M":" ",
2071
1462
                                (snes_ram[TS] & 0x8)?"S":" ",
2081
1472
                                (snes_ram[BG4SC] & 0xfc) << 9,
2082
1473
                                snes_ppu.layer[3].data );
2083
1474
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2084
 
                sprintf( t, "%sO %s%s%s%s%s%c%s%s%d%d       %4X",
 
1475
                logerror("%sO %s%s%s%s%s%c%s%s%d%d       %4X",
2085
1476
                                debug_options.bg_disabled[4]?" ":"*",
2086
1477
                                (snes_ram[TM] & 0x10)?"M":" ",
2087
1478
                                (snes_ram[TS] & 0x10)?"S":" ",
2094
1485
                                snes_ppu.oam.size[0], snes_ppu.oam.size[1],
2095
1486
                                snes_ppu.layer[4].data );
2096
1487
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2097
 
                sprintf( t, "%sB   %s  %c%s%s",
 
1488
                logerror("%sB   %s  %c%s%s",
2098
1489
                                debug_options.bg_disabled[5]?" ":"*",
2099
1490
                                (snes_ram[CGADSUB] & 0x20)?"B":" ",
2100
1491
                                WINLOGIC[(snes_ram[WOBJLOG] & 0xc)>>2],
2101
1492
                                (snes_ram[WOBJSEL] & 0x20)?((snes_ram[WOBJSEL] & 0x10)?"o":"i"):" ",
2102
1493
                                (snes_ram[WOBJSEL] & 0x80)?((snes_ram[WOBJSEL] & 0x40)?"o":"i"):" " );
2103
1494
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2104
 
                sprintf( t, "1) %3d %3d   2) %3d %3d", (snes_ppu.bgd_offset.horizontal[0] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[0] & 0x3ff) >> 3, (snes_ppu.bgd_offset.horizontal[1] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[1] & 0x3ff) >> 3 );
2105
 
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2106
 
                sprintf( t, "3) %3d %3d   4) %3d %3d", (snes_ppu.bgd_offset.horizontal[2] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[2] & 0x3ff) >> 3, (snes_ppu.bgd_offset.horizontal[3] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[3] & 0x3ff) >> 3 );
2107
 
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2108
 
                sprintf( t, "Flags: %s%s%s %s %2d", (snes_ram[CGWSEL] & 0x2)?"S":"F", (snes_ram[CGADSUB] & 0x80)?"-":"+", (snes_ram[CGADSUB] & 0x40)?" 50%":"100%",(snes_ram[CGWSEL] & 0x1)?"D":"P", (snes_ram[MOSAIC] & 0xf0) >> 4 );
2109
 
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2110
 
                sprintf( t, "SetINI: %s %s %s %s %s %s", (snes_ram[SETINI] & 0x1)?" I":"NI", (snes_ram[SETINI] & 0x2)?"P":"R", (snes_ram[SETINI] & 0x4)?"240":"225",(snes_ram[SETINI] & 0x8)?"512":"256",(snes_ram[SETINI] & 0x40)?"E":"N",(snes_ram[SETINI] & 0x80)?"ES":"NS" );
2111
 
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2112
 
                sprintf( t, "Mode7: A %5d B %5d", snes_ppu.mode7.matrix_a, snes_ppu.mode7.matrix_b );
2113
 
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2114
 
                sprintf( t, " %s%s%s   C %5d D %5d", (snes_ram[M7SEL] & 0xc0)?((snes_ram[M7SEL] & 0x40)?"0":"C"):"R", (snes_ram[M7SEL] & 0x1)?"H":" ", (snes_ram[M7SEL] & 0x2)?"V":" ", snes_ppu.mode7.matrix_c, snes_ppu.mode7.matrix_d );
2115
 
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2116
 
                sprintf( t, "       X %5d Y %5d", snes_ppu.mode7.origin_x, snes_ppu.mode7.origin_y );
 
1495
                logerror("1) %3d %3d   2) %3d %3d", (snes_ppu.bgd_offset.horizontal[0] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[0] & 0x3ff) >> 3, (snes_ppu.bgd_offset.horizontal[1] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[1] & 0x3ff) >> 3 );
 
1496
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
 
1497
                logerror("3) %3d %3d   4) %3d %3d", (snes_ppu.bgd_offset.horizontal[2] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[2] & 0x3ff) >> 3, (snes_ppu.bgd_offset.horizontal[3] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[3] & 0x3ff) >> 3 );
 
1498
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
 
1499
                logerror("Flags: %s%s%s %s %2d", (snes_ram[CGWSEL] & 0x2)?"S":"F", (snes_ram[CGADSUB] & 0x80)?"-":"+", (snes_ram[CGADSUB] & 0x40)?" 50%":"100%",(snes_ram[CGWSEL] & 0x1)?"D":"P", (snes_ram[MOSAIC] & 0xf0) >> 4 );
 
1500
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
 
1501
                logerror("SetINI: %s %s %s %s %s %s", (snes_ram[SETINI] & 0x1)?" I":"NI", (snes_ram[SETINI] & 0x2)?"P":"R", (snes_ram[SETINI] & 0x4)?"240":"225",(snes_ram[SETINI] & 0x8)?"512":"256",(snes_ram[SETINI] & 0x40)?"E":"N",(snes_ram[SETINI] & 0x80)?"ES":"NS" );
 
1502
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
 
1503
                logerror("Mode7: A %5d B %5d", snes_ppu.mode7.matrix_a, snes_ppu.mode7.matrix_b );
 
1504
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
 
1505
                logerror(" %s%s%s   C %5d D %5d", (snes_ram[M7SEL] & 0xc0)?((snes_ram[M7SEL] & 0x40)?"0":"C"):"R", (snes_ram[M7SEL] & 0x1)?"H":" ", (snes_ram[M7SEL] & 0x2)?"V":" ", snes_ppu.mode7.matrix_c, snes_ppu.mode7.matrix_d );
 
1506
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
 
1507
                logerror("       X %5d Y %5d", snes_ppu.mode7.origin_x, snes_ppu.mode7.origin_y );
2117
1508
                //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
2118
1509
        }
2119
1510
        /* Just for testing, draw as many tiles as possible */
2141
1532
                                {
2142
1533
                                        scanlines[MAINSCREEN].buffer[ii] = 0;
2143
1534
                                }
2144
 
                                snes_dbg_draw_all_tiles(bitmap, addr, dt, pal * 16 );
 
1535
                                snes_dbg_draw_all_tiles(machine, bitmap, addr, dt, pal * 16 );
2145
1536
                        }
2146
1537
                        return 1;
2147
1538
                }
2176
1567
                        return 1;
2177
1568
                                }
2178
1569
                }
2179
 
 
 
1570
#if 0   // 2009-08 FP: what was the purpose of these lines?
2180
1571
                        /* Draw some useful information about the back/fixed colours and current bg mode etc. */
2181
1572
                        *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 26) = machine->pens[dbg_mode_colours[(snes_ram[CGWSEL] & 0xc0) >> 6]];
2182
1573
                        *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 24) = machine->pens[dbg_mode_colours[(snes_ram[CGWSEL] & 0x30) >> 4]];
2193
1584
                        scanlines[MAINSCREEN].buffer[snes_ram[WH1]] = machine->pens[dbg_mode_colours[0]];
2194
1585
                        scanlines[MAINSCREEN].buffer[snes_ram[WH2]] = machine->pens[dbg_mode_colours[2]];
2195
1586
                        scanlines[MAINSCREEN].buffer[snes_ram[WH3]] = machine->pens[dbg_mode_colours[2]];
2196
 
 
 
1587
#endif
2197
1588
        return 0;
2198
1589
        }
2199
1590
 
2200
 
#endif /* SNES_DBG_video */
 
1591
#endif /* MAME_DEBUG */