~ubuntu-branches/ubuntu/raring/mame/raring-proposed

« back to all changes in this revision

Viewing changes to mess/src/mame/video/atarisy1.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jordi Mallach, Emmanuel Kasper
  • Date: 2011-12-19 22:56:27 UTC
  • mfrom: (0.1.2)
  • Revision ID: package-import@ubuntu.com-20111219225627-ub5oga1oys4ogqzm
Tags: 0.144-1
[ Jordi Mallach ]
* Fix syntax errors in DEP5 copyright file (lintian).
* Use a versioned copyright Format specification field.
* Update Vcs-* URLs.
* Move transitional packages to the new metapackages section, and make
  them priority extra.
* Remove references to GNU/Linux and MESS sources from copyright.
* Add build variables for s390x.
* Use .xz tarballs as it cuts 4MB for the upstream sources.
* Add nplayers.ini as a patch. Update copyright file to add CC-BY-SA-3.0.

[ Emmanuel Kasper ]
* New upstream release. Closes: #651538.
* Add Free Desktop compliant png icons of various sizes taken from
  the hydroxygen iconset
* Mess is now built from a new source package, to avoid possible source
  incompatibilities between mame and the mess overlay.
* Mame-tools are not built from the mame source package anymore, but
  from the mess source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 
3
 
    Atari System 1 hardware
4
 
 
5
 
****************************************************************************/
6
 
 
7
 
#include "emu.h"
8
 
#include "video/atarimo.h"
9
 
#include "includes/atarisy1.h"
10
 
 
11
 
 
12
 
 
13
 
/*************************************
14
 
 *
15
 
 *  Constants
16
 
 *
17
 
 *************************************/
18
 
 
19
 
/* the color and remap PROMs are mapped as follows */
20
 
#define PROM1_BANK_4                    0x80            /* active low */
21
 
#define PROM1_BANK_3                    0x40            /* active low */
22
 
#define PROM1_BANK_2                    0x20            /* active low */
23
 
#define PROM1_BANK_1                    0x10            /* active low */
24
 
#define PROM1_OFFSET_MASK               0x0f            /* postive logic */
25
 
 
26
 
#define PROM2_BANK_6_OR_7               0x80            /* active low */
27
 
#define PROM2_BANK_5                    0x40            /* active low */
28
 
#define PROM2_PLANE_5_ENABLE    0x20            /* active high */
29
 
#define PROM2_PLANE_4_ENABLE    0x10            /* active high */
30
 
#define PROM2_PF_COLOR_MASK             0x0f            /* negative logic */
31
 
#define PROM2_BANK_7                    0x08            /* active low, plus PROM2_BANK_6_OR_7 low as well */
32
 
#define PROM2_MO_COLOR_MASK             0x07            /* negative logic */
33
 
 
34
 
 
35
 
 
36
 
/*************************************
37
 
 *
38
 
 *  Statics
39
 
 *
40
 
 *************************************/
41
 
 
42
 
static const gfx_layout objlayout_4bpp =
43
 
{
44
 
        8,8,    /* 8*8 sprites */
45
 
        4096,   /* 4096 of them */
46
 
        4,              /* 4 bits per pixel */
47
 
        { 3*8*0x10000, 2*8*0x10000, 1*8*0x10000, 0*8*0x10000 },
48
 
        { 0, 1, 2, 3, 4, 5, 6, 7 },
49
 
        { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
50
 
        8*8             /* every sprite takes 8 consecutive bytes */
51
 
};
52
 
 
53
 
static const gfx_layout objlayout_5bpp =
54
 
{
55
 
        8,8,    /* 8*8 sprites */
56
 
        4096,   /* 4096 of them */
57
 
        5,              /* 5 bits per pixel */
58
 
        { 4*8*0x10000, 3*8*0x10000, 2*8*0x10000, 1*8*0x10000, 0*8*0x10000 },
59
 
        { 0, 1, 2, 3, 4, 5, 6, 7 },
60
 
        { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
61
 
        8*8             /* every sprite takes 8 consecutive bytes */
62
 
};
63
 
 
64
 
static const gfx_layout objlayout_6bpp =
65
 
{
66
 
        8,8,    /* 8*8 sprites */
67
 
        4096,   /* 4096 of them */
68
 
        6,              /* 6 bits per pixel */
69
 
        { 5*8*0x10000, 4*8*0x10000, 3*8*0x10000, 2*8*0x10000, 1*8*0x10000, 0*8*0x10000 },
70
 
        { 0, 1, 2, 3, 4, 5, 6, 7 },
71
 
        { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
72
 
        8*8             /* every sprite takes 8 consecutive bytes */
73
 
};
74
 
 
75
 
 
76
 
 
77
 
/*************************************
78
 
 *
79
 
 *  Prototypes
80
 
 *
81
 
 *************************************/
82
 
 
83
 
static void update_timers(running_machine &machine, int scanline);
84
 
static void decode_gfx(running_machine &machine, UINT16 *pflookup, UINT16 *molookup);
85
 
static int get_bank(running_machine &machine, UINT8 prom1, UINT8 prom2, int bpp);
86
 
 
87
 
 
88
 
 
89
 
/*************************************
90
 
 *
91
 
 *  Tilemap callbacks
92
 
 *
93
 
 *************************************/
94
 
 
95
 
static TILE_GET_INFO( get_alpha_tile_info )
96
 
{
97
 
        atarisy1_state *state = machine.driver_data<atarisy1_state>();
98
 
        UINT16 data = state->m_alpha[tile_index];
99
 
        int code = data & 0x3ff;
100
 
        int color = (data >> 10) & 0x07;
101
 
        int opaque = data & 0x2000;
102
 
        SET_TILE_INFO(0, code, color, opaque ? TILE_FORCE_LAYER0 : 0);
103
 
}
104
 
 
105
 
 
106
 
static TILE_GET_INFO( get_playfield_tile_info )
107
 
{
108
 
        atarisy1_state *state = machine.driver_data<atarisy1_state>();
109
 
        UINT16 data = state->m_playfield[tile_index];
110
 
        UINT16 lookup = state->m_playfield_lookup[((data >> 8) & 0x7f) | (state->m_playfield_tile_bank << 7)];
111
 
        int gfxindex = (lookup >> 8) & 15;
112
 
        int code = ((lookup & 0xff) << 8) | (data & 0xff);
113
 
        int color = 0x20 + (((lookup >> 12) & 15) << state->m_bank_color_shift[gfxindex]);
114
 
        SET_TILE_INFO(gfxindex, code, color, (data >> 15) & 1);
115
 
}
116
 
 
117
 
 
118
 
 
119
 
/*************************************
120
 
 *
121
 
 *  Generic video system start
122
 
 *
123
 
 *************************************/
124
 
 
125
 
VIDEO_START( atarisy1 )
126
 
{
127
 
        static const atarimo_desc modesc =
128
 
        {
129
 
                0,                                      /* index to which gfx system */
130
 
                8,                                      /* number of motion object banks */
131
 
                1,                                      /* are the entries linked? */
132
 
                1,                                      /* are the entries split? */
133
 
                0,                                      /* render in reverse order? */
134
 
                0,                                      /* render in swapped X/Y order? */
135
 
                0,                                      /* does the neighbor bit affect the next object? */
136
 
                0,                                      /* pixels per SLIP entry (0 for no-slip) */
137
 
                0,                                      /* pixel offset for SLIPs */
138
 
                0x38,                           /* maximum number of links to visit/scanline (0=all) */
139
 
 
140
 
                0x100,                          /* base palette entry */
141
 
                0x100,                          /* maximum number of colors */
142
 
                0,                                      /* transparent pen index */
143
 
 
144
 
                {{ 0,0,0,0x003f }},     /* mask for the link */
145
 
                {{ 0,0xff00,0,0 }},     /* mask for the graphics bank */
146
 
                {{ 0,0xffff,0,0 }},     /* mask for the code index */
147
 
                {{ 0 }},                        /* mask for the upper code index */
148
 
                {{ 0,0xff00,0,0 }},     /* mask for the color */
149
 
                {{ 0,0,0x3fe0,0 }},     /* mask for the X position */
150
 
                {{ 0x3fe0,0,0,0 }},     /* mask for the Y position */
151
 
                {{ 0 }},                        /* mask for the width, in tiles*/
152
 
                {{ 0x000f,0,0,0 }},     /* mask for the height, in tiles */
153
 
                {{ 0x8000,0,0,0 }},     /* mask for the horizontal flip */
154
 
                {{ 0 }},                        /* mask for the vertical flip */
155
 
                {{ 0,0,0x8000,0 }},     /* mask for the priority */
156
 
                {{ 0 }},                        /* mask for the neighbor */
157
 
                {{ 0 }},                        /* mask for absolute coordinates */
158
 
 
159
 
                {{ 0,0xffff,0,0 }},     /* mask for the special value */
160
 
                0xffff,                         /* resulting value to indicate "special" */
161
 
                0                                       /* callback routine for special entries */
162
 
        };
163
 
 
164
 
        atarisy1_state *state = machine.driver_data<atarisy1_state>();
165
 
        UINT16 motable[256];
166
 
        UINT16 *codelookup;
167
 
        UINT8 *colorlookup, *gfxlookup;
168
 
        int i, size;
169
 
 
170
 
        /* first decode the graphics */
171
 
        decode_gfx(machine, state->m_playfield_lookup, motable);
172
 
 
173
 
        /* initialize the playfield */
174
 
        state->m_playfield_tilemap = tilemap_create(machine, get_playfield_tile_info, tilemap_scan_rows,  8,8, 64,64);
175
 
 
176
 
        /* initialize the motion objects */
177
 
        atarimo_init(machine, 0, &modesc);
178
 
 
179
 
        /* initialize the alphanumerics */
180
 
        state->m_alpha_tilemap = tilemap_create(machine, get_alpha_tile_info, tilemap_scan_rows,  8,8, 64,32);
181
 
        tilemap_set_transparent_pen(state->m_alpha_tilemap, 0);
182
 
 
183
 
        /* modify the motion object code lookup */
184
 
        codelookup = atarimo_get_code_lookup(0, &size);
185
 
        for (i = 0; i < size; i++)
186
 
                codelookup[i] = (i & 0xff) | ((motable[i >> 8] & 0xff) << 8);
187
 
 
188
 
        /* modify the motion object color and gfx lookups */
189
 
        colorlookup = atarimo_get_color_lookup(0, &size);
190
 
        gfxlookup = atarimo_get_gfx_lookup(0, &size);
191
 
        for (i = 0; i < size; i++)
192
 
        {
193
 
                colorlookup[i] = ((motable[i] >> 12) & 15) << 1;
194
 
                gfxlookup[i] = (motable[i] >> 8) & 15;
195
 
        }
196
 
 
197
 
        /* reset the statics */
198
 
        atarimo_set_yscroll(0, 256);
199
 
        state->m_next_timer_scanline = -1;
200
 
 
201
 
        /* save state */
202
 
        state->save_item(NAME(state->m_playfield_tile_bank));
203
 
        state->save_item(NAME(state->m_playfield_priority_pens));
204
 
        state->save_item(NAME(state->m_next_timer_scanline));
205
 
}
206
 
 
207
 
 
208
 
 
209
 
/*************************************
210
 
 *
211
 
 *  Graphics bank selection
212
 
 *
213
 
 *************************************/
214
 
 
215
 
WRITE16_HANDLER( atarisy1_bankselect_w )
216
 
{
217
 
        atarisy1_state *state = space->machine().driver_data<atarisy1_state>();
218
 
        UINT16 oldselect = *state->m_bankselect;
219
 
        UINT16 newselect = oldselect, diff;
220
 
        int scanline = space->machine().primary_screen->vpos();
221
 
 
222
 
        /* update memory */
223
 
        COMBINE_DATA(&newselect);
224
 
        diff = oldselect ^ newselect;
225
 
 
226
 
        /* sound CPU reset */
227
 
        if (diff & 0x0080)
228
 
        {
229
 
                cputag_set_input_line(space->machine(), "audiocpu", INPUT_LINE_RESET, (newselect & 0x0080) ? CLEAR_LINE : ASSERT_LINE);
230
 
                if (!(newselect & 0x0080)) atarigen_sound_reset(space->machine());
231
 
        }
232
 
 
233
 
        /* if MO or playfield banks change, force a partial update */
234
 
        if (diff & 0x003c)
235
 
                space->machine().primary_screen->update_partial(scanline);
236
 
 
237
 
        /* motion object bank select */
238
 
        atarimo_set_bank(0, (newselect >> 3) & 7);
239
 
        update_timers(space->machine(), scanline);
240
 
 
241
 
        /* playfield bank select */
242
 
        if (diff & 0x0004)
243
 
        {
244
 
                state->m_playfield_tile_bank = (newselect >> 2) & 1;
245
 
                tilemap_mark_all_tiles_dirty(state->m_playfield_tilemap);
246
 
        }
247
 
 
248
 
        /* stash the new value */
249
 
        *state->m_bankselect = newselect;
250
 
}
251
 
 
252
 
 
253
 
 
254
 
/*************************************
255
 
 *
256
 
 *  Playfield priority pens
257
 
 *
258
 
 *************************************/
259
 
 
260
 
WRITE16_HANDLER( atarisy1_priority_w )
261
 
{
262
 
        atarisy1_state *state = space->machine().driver_data<atarisy1_state>();
263
 
        UINT16 oldpens = state->m_playfield_priority_pens;
264
 
        UINT16 newpens = oldpens;
265
 
 
266
 
        /* force a partial update in case this changes mid-screen */
267
 
        COMBINE_DATA(&newpens);
268
 
        if (oldpens != newpens)
269
 
                space->machine().primary_screen->update_partial(space->machine().primary_screen->vpos());
270
 
        state->m_playfield_priority_pens = newpens;
271
 
}
272
 
 
273
 
 
274
 
 
275
 
/*************************************
276
 
 *
277
 
 *  Playfield horizontal scroll
278
 
 *
279
 
 *************************************/
280
 
 
281
 
WRITE16_HANDLER( atarisy1_xscroll_w )
282
 
{
283
 
        atarisy1_state *state = space->machine().driver_data<atarisy1_state>();
284
 
        UINT16 oldscroll = *state->m_xscroll;
285
 
        UINT16 newscroll = oldscroll;
286
 
 
287
 
        /* force a partial update in case this changes mid-screen */
288
 
        COMBINE_DATA(&newscroll);
289
 
        if (oldscroll != newscroll)
290
 
                space->machine().primary_screen->update_partial(space->machine().primary_screen->vpos());
291
 
 
292
 
        /* set the new scroll value */
293
 
        tilemap_set_scrollx(state->m_playfield_tilemap, 0, newscroll);
294
 
 
295
 
        /* update the data */
296
 
        *state->m_xscroll = newscroll;
297
 
}
298
 
 
299
 
 
300
 
 
301
 
/*************************************
302
 
 *
303
 
 *  Playfield vertical scroll
304
 
 *
305
 
 *************************************/
306
 
 
307
 
TIMER_DEVICE_CALLBACK( atarisy1_reset_yscroll_callback )
308
 
{
309
 
        atarisy1_state *state = timer.machine().driver_data<atarisy1_state>();
310
 
        tilemap_set_scrolly(state->m_playfield_tilemap, 0, param);
311
 
}
312
 
 
313
 
 
314
 
WRITE16_HANDLER( atarisy1_yscroll_w )
315
 
{
316
 
        atarisy1_state *state = space->machine().driver_data<atarisy1_state>();
317
 
        UINT16 oldscroll = *state->m_yscroll;
318
 
        UINT16 newscroll = oldscroll;
319
 
        int scanline = space->machine().primary_screen->vpos();
320
 
        int adjusted_scroll;
321
 
 
322
 
        /* force a partial update in case this changes mid-screen */
323
 
        COMBINE_DATA(&newscroll);
324
 
        space->machine().primary_screen->update_partial(scanline);
325
 
 
326
 
        /* because this latches a new value into the scroll base,
327
 
       we need to adjust for the scanline */
328
 
        adjusted_scroll = newscroll;
329
 
        if (scanline <= space->machine().primary_screen->visible_area().max_y)
330
 
                adjusted_scroll -= (scanline + 1);
331
 
        tilemap_set_scrolly(state->m_playfield_tilemap, 0, adjusted_scroll);
332
 
 
333
 
        /* but since we've adjusted it, we must reset it to the normal value
334
 
       once we hit scanline 0 again */
335
 
        state->m_yscroll_reset_timer->adjust(space->machine().primary_screen->time_until_pos(0), newscroll);
336
 
 
337
 
        /* update the data */
338
 
        *state->m_yscroll = newscroll;
339
 
}
340
 
 
341
 
 
342
 
 
343
 
/*************************************
344
 
 *
345
 
 *  Sprite RAM write handler
346
 
 *
347
 
 *************************************/
348
 
 
349
 
WRITE16_HANDLER( atarisy1_spriteram_w )
350
 
{
351
 
        int active_bank = atarimo_get_bank(0);
352
 
        int oldword = atarimo_0_spriteram_r(space, offset, mem_mask);
353
 
        int newword = oldword;
354
 
        COMBINE_DATA(&newword);
355
 
 
356
 
        /* if the data changed, and it modified the live sprite bank, do some extra work */
357
 
        if (oldword != newword && (offset >> 8) == active_bank)
358
 
        {
359
 
                /* if modifying a timer, beware */
360
 
                if (((offset & 0xc0) == 0x00 && atarimo_0_spriteram_r(space, offset | 0x40, mem_mask) == 0xffff) ||
361
 
                    ((offset & 0xc0) == 0x40 && (newword == 0xffff || oldword == 0xffff)))
362
 
                {
363
 
                        /* if the timer is in the active bank, update the display list */
364
 
                        atarimo_0_spriteram_w(space, offset, data, 0xffff);
365
 
                        update_timers(space->machine(), space->machine().primary_screen->vpos());
366
 
                }
367
 
 
368
 
                /* if we're about to modify data in the active sprite bank, make sure the video is up-to-date */
369
 
                /* Road Runner needs this to work; note the +2 kludge -- +1 would be correct since the video */
370
 
                /* renders the next scanline's sprites to the line buffers, but Road Runner still glitches */
371
 
                /* without the extra +1 */
372
 
                else
373
 
                        space->machine().primary_screen->update_partial(space->machine().primary_screen->vpos() + 2);
374
 
        }
375
 
 
376
 
        /* let the MO handler do the basic work */
377
 
        atarimo_0_spriteram_w(space, offset, data, 0xffff);
378
 
}
379
 
 
380
 
 
381
 
 
382
 
/*************************************
383
 
 *
384
 
 *  MO interrupt handlers
385
 
 *
386
 
 *************************************/
387
 
 
388
 
TIMER_DEVICE_CALLBACK( atarisy1_int3off_callback )
389
 
{
390
 
        address_space *space = timer.machine().device("maincpu")->memory().space(AS_PROGRAM);
391
 
 
392
 
        /* clear the state */
393
 
        atarigen_scanline_int_ack_w(space, 0, 0, 0xffff);
394
 
}
395
 
 
396
 
 
397
 
TIMER_DEVICE_CALLBACK( atarisy1_int3_callback )
398
 
{
399
 
        atarisy1_state *state = timer.machine().driver_data<atarisy1_state>();
400
 
        int scanline = param;
401
 
 
402
 
        /* update the state */
403
 
        atarigen_scanline_int_gen(timer.machine().device("maincpu"));
404
 
 
405
 
        /* set a timer to turn it off */
406
 
        state->m_int3off_timer->adjust(timer.machine().primary_screen->scan_period());
407
 
 
408
 
        /* determine the time of the next one */
409
 
        state->m_next_timer_scanline = -1;
410
 
        update_timers(timer.machine(), scanline);
411
 
}
412
 
 
413
 
 
414
 
 
415
 
/*************************************
416
 
 *
417
 
 *  MO interrupt state read
418
 
 *
419
 
 *************************************/
420
 
 
421
 
READ16_HANDLER( atarisy1_int3state_r )
422
 
{
423
 
        atarigen_state *atarigen = space->machine().driver_data<atarigen_state>();
424
 
        return atarigen->m_scanline_int_state ? 0x0080 : 0x0000;
425
 
}
426
 
 
427
 
 
428
 
 
429
 
/*************************************
430
 
 *
431
 
 *  Timer updater
432
 
 *
433
 
 *************************************/
434
 
 
435
 
static void update_timers(running_machine &machine, int scanline)
436
 
{
437
 
        atarisy1_state *state = machine.driver_data<atarisy1_state>();
438
 
        address_space *space = NULL;
439
 
        UINT16 mem_mask = 0xffff;
440
 
        int offset = atarimo_get_bank(0) * 64 * 4;
441
 
        int link = 0, best = scanline, found = 0;
442
 
        UINT8 spritevisit[64];
443
 
 
444
 
        /* track which ones we've visited */
445
 
        memset(spritevisit, 0, sizeof(spritevisit));
446
 
 
447
 
        /* walk the list until we loop */
448
 
        while (!spritevisit[link])
449
 
        {
450
 
                /* timers are indicated by 0xffff in entry 2 */
451
 
                if (atarimo_0_spriteram_r(space, offset + link + 0x40, mem_mask) == 0xffff)
452
 
                {
453
 
                        int data = atarimo_0_spriteram_r(space, offset + link, mem_mask);
454
 
                        int vsize = (data & 15) + 1;
455
 
                        int ypos = (256 - (data >> 5) - vsize * 8 - 1) & 0x1ff;
456
 
 
457
 
                        /* note that we found something */
458
 
                        found = 1;
459
 
 
460
 
                        /* is this a better entry than the best so far? */
461
 
                        if (best <= scanline)
462
 
                        {
463
 
                                if ((ypos <= scanline && ypos < best) || ypos > scanline)
464
 
                                        best = ypos;
465
 
                        }
466
 
                        else
467
 
                        {
468
 
                                if (ypos < best)
469
 
                                        best = ypos;
470
 
                        }
471
 
                }
472
 
 
473
 
                /* link to the next */
474
 
                spritevisit[link] = 1;
475
 
                link = atarimo_0_spriteram_r(space, offset + link + 0xc0, mem_mask) & 0x3f;
476
 
        }
477
 
 
478
 
        /* if nothing was found, use scanline -1 */
479
 
        if (!found)
480
 
                best = -1;
481
 
 
482
 
        /* update the timer */
483
 
        if (best != state->m_next_timer_scanline)
484
 
        {
485
 
                state->m_next_timer_scanline = best;
486
 
 
487
 
                /* set a new one */
488
 
                if (best != -1)
489
 
                        state->m_scanline_timer->adjust(machine.primary_screen->time_until_pos(best), best);
490
 
                else
491
 
                        state->m_scanline_timer->reset();
492
 
        }
493
 
}
494
 
 
495
 
 
496
 
 
497
 
/*************************************
498
 
 *
499
 
 *  Main refresh
500
 
 *
501
 
 *************************************/
502
 
 
503
 
SCREEN_UPDATE( atarisy1 )
504
 
{
505
 
        atarisy1_state *state = screen->machine().driver_data<atarisy1_state>();
506
 
        atarimo_rect_list rectlist;
507
 
        bitmap_t *mobitmap;
508
 
        int x, y, r;
509
 
 
510
 
        /* draw the playfield */
511
 
        tilemap_draw(bitmap, cliprect, state->m_playfield_tilemap, 0, 0);
512
 
 
513
 
        /* draw and merge the MO */
514
 
        mobitmap = atarimo_render(0, cliprect, &rectlist);
515
 
        for (r = 0; r < rectlist.numrects; r++, rectlist.rect++)
516
 
                for (y = rectlist.rect->min_y; y <= rectlist.rect->max_y; y++)
517
 
                {
518
 
                        UINT16 *mo = (UINT16 *)mobitmap->base + mobitmap->rowpixels * y;
519
 
                        UINT16 *pf = (UINT16 *)bitmap->base + bitmap->rowpixels * y;
520
 
                        for (x = rectlist.rect->min_x; x <= rectlist.rect->max_x; x++)
521
 
                                if (mo[x])
522
 
                                {
523
 
                                        /* high priority MO? */
524
 
                                        if (mo[x] & ATARIMO_PRIORITY_MASK)
525
 
                                        {
526
 
                                                /* only gets priority if MO pen is not 1 */
527
 
                                                if ((mo[x] & 0x0f) != 1)
528
 
                                                        pf[x] = 0x300 + ((pf[x] & 0x0f) << 4) + (mo[x] & 0x0f);
529
 
                                        }
530
 
 
531
 
                                        /* low priority */
532
 
                                        else
533
 
                                        {
534
 
                                                /* priority pens for playfield color 0 */
535
 
                                                if ((pf[x] & 0xf8) != 0 || !(state->m_playfield_priority_pens & (1 << (pf[x] & 0x07))))
536
 
                                                        pf[x] = mo[x];
537
 
                                        }
538
 
 
539
 
                                        /* erase behind ourselves */
540
 
                                        mo[x] = 0;
541
 
                                }
542
 
                }
543
 
 
544
 
        /* add the alpha on top */
545
 
        tilemap_draw(bitmap, cliprect, state->m_alpha_tilemap, 0, 0);
546
 
        return 0;
547
 
}
548
 
 
549
 
 
550
 
 
551
 
/*************************************
552
 
 *
553
 
 *  Graphics decoding
554
 
 *
555
 
 *************************************/
556
 
 
557
 
static void decode_gfx(running_machine &machine, UINT16 *pflookup, UINT16 *molookup)
558
 
{
559
 
        atarisy1_state *state = machine.driver_data<atarisy1_state>();
560
 
        UINT8 *prom1 = &machine.region("proms")->u8(0x000);
561
 
        UINT8 *prom2 = &machine.region("proms")->u8(0x200);
562
 
        int obj, i;
563
 
 
564
 
        /* reset the globals */
565
 
        memset(&state->m_bank_gfx[0][0], 0, sizeof(state->m_bank_gfx));
566
 
 
567
 
        /* loop for two sets of objects */
568
 
        for (obj = 0; obj < 2; obj++)
569
 
        {
570
 
                /* loop for 256 objects in the set */
571
 
                for (i = 0; i < 256; i++, prom1++, prom2++)
572
 
                {
573
 
                        int bank, bpp, color, offset;
574
 
 
575
 
                        /* determine the bpp */
576
 
                        bpp = 4;
577
 
                        if (*prom2 & PROM2_PLANE_4_ENABLE)
578
 
                        {
579
 
                                bpp = 5;
580
 
                                if (*prom2 & PROM2_PLANE_5_ENABLE)
581
 
                                        bpp = 6;
582
 
                        }
583
 
 
584
 
                        /* determine the offset */
585
 
                        offset = *prom1 & PROM1_OFFSET_MASK;
586
 
 
587
 
                        /* determine the bank */
588
 
                        bank = get_bank(machine, *prom1, *prom2, bpp);
589
 
 
590
 
                        /* set the value */
591
 
                        if (obj == 0)
592
 
                        {
593
 
                                /* playfield case */
594
 
                                color = (~*prom2 & PROM2_PF_COLOR_MASK) >> (bpp - 4);
595
 
                                if (bank == 0)
596
 
                                {
597
 
                                        bank = 1;
598
 
                                        offset = color = 0;
599
 
                                }
600
 
                                pflookup[i] = offset | (bank << 8) | (color << 12);
601
 
                        }
602
 
                        else
603
 
                        {
604
 
                                /* motion objects (high bit ignored) */
605
 
                                color = (~*prom2 & PROM2_MO_COLOR_MASK) >> (bpp - 4);
606
 
                                molookup[i] = offset | (bank << 8) | (color << 12);
607
 
                        }
608
 
                }
609
 
        }
610
 
}
611
 
 
612
 
 
613
 
 
614
 
/*************************************
615
 
 *
616
 
 *  Graphics bank mapping
617
 
 *
618
 
 *************************************/
619
 
 
620
 
static int get_bank(running_machine &machine, UINT8 prom1, UINT8 prom2, int bpp)
621
 
{
622
 
        atarisy1_state *state = machine.driver_data<atarisy1_state>();
623
 
        const UINT8 *srcdata;
624
 
        int bank_index, gfx_index;
625
 
 
626
 
        /* determine the bank index */
627
 
        if ((prom1 & PROM1_BANK_1) == 0)
628
 
                bank_index = 1;
629
 
        else if ((prom1 & PROM1_BANK_2) == 0)
630
 
                bank_index = 2;
631
 
        else if ((prom1 & PROM1_BANK_3) == 0)
632
 
                bank_index = 3;
633
 
        else if ((prom1 & PROM1_BANK_4) == 0)
634
 
                bank_index = 4;
635
 
        else if ((prom2 & PROM2_BANK_5) == 0)
636
 
                bank_index = 5;
637
 
        else if ((prom2 & PROM2_BANK_6_OR_7) == 0)
638
 
        {
639
 
                if ((prom2 & PROM2_BANK_7) == 0)
640
 
                        bank_index = 7;
641
 
                else
642
 
                        bank_index = 6;
643
 
        }
644
 
        else
645
 
                return 0;
646
 
 
647
 
        /* find the bank */
648
 
        if (state->m_bank_gfx[bpp - 4][bank_index])
649
 
                return state->m_bank_gfx[bpp - 4][bank_index];
650
 
 
651
 
        /* if the bank is out of range, call it 0 */
652
 
        const memory_region *tiles = machine.region("tiles");
653
 
        if (0x80000 * (bank_index - 1) >= tiles->bytes())
654
 
                return 0;
655
 
 
656
 
        /* don't have one? let's make it ... first find any empty slot */
657
 
        for (gfx_index = 0; gfx_index < MAX_GFX_ELEMENTS; gfx_index++)
658
 
                if (machine.gfx[gfx_index] == NULL)
659
 
                        break;
660
 
        assert(gfx_index != MAX_GFX_ELEMENTS);
661
 
 
662
 
        /* decode the graphics */
663
 
        srcdata = &tiles->u8(0x80000 * (bank_index - 1));
664
 
        switch (bpp)
665
 
        {
666
 
        case 4:
667
 
                machine.gfx[gfx_index] = gfx_element_alloc(machine, &objlayout_4bpp, srcdata, 0x40, 256);
668
 
                break;
669
 
 
670
 
        case 5:
671
 
                machine.gfx[gfx_index] = gfx_element_alloc(machine, &objlayout_5bpp, srcdata, 0x40, 256);
672
 
                break;
673
 
 
674
 
        case 6:
675
 
                machine.gfx[gfx_index] = gfx_element_alloc(machine, &objlayout_6bpp, srcdata, 0x40, 256);
676
 
                break;
677
 
 
678
 
        default:
679
 
                fatalerror("Unsupported bpp");
680
 
        }
681
 
 
682
 
        /* set the color information */
683
 
        machine.gfx[gfx_index]->color_granularity = 8;
684
 
        state->m_bank_color_shift[gfx_index] = bpp - 3;
685
 
 
686
 
        /* set the entry and return it */
687
 
        return state->m_bank_gfx[bpp - 4][bank_index] = gfx_index;
688
 
}