~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to mess/src/mame/video/atarisy2.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 2 hardware
4
 
 
5
 
****************************************************************************/
6
 
 
7
 
#include "emu.h"
8
 
#include "video/atarimo.h"
9
 
#include "includes/slapstic.h"
10
 
#include "includes/atarisy2.h"
11
 
 
12
 
 
13
 
 
14
 
/*************************************
15
 
 *
16
 
 *  Prototypes
17
 
 *
18
 
 *************************************/
19
 
 
20
 
static TIMER_CALLBACK( reset_yscroll_callback );
21
 
 
22
 
 
23
 
 
24
 
/*************************************
25
 
 *
26
 
 *  Tilemap callbacks
27
 
 *
28
 
 *************************************/
29
 
 
30
 
static TILE_GET_INFO( get_alpha_tile_info )
31
 
{
32
 
        atarisy2_state *state = machine.driver_data<atarisy2_state>();
33
 
        UINT16 data = state->m_alpha[tile_index];
34
 
        int code = data & 0x3ff;
35
 
        int color = (data >> 13) & 0x07;
36
 
        SET_TILE_INFO(2, code, color, 0);
37
 
}
38
 
 
39
 
 
40
 
static TILE_GET_INFO( get_playfield_tile_info )
41
 
{
42
 
        atarisy2_state *state = machine.driver_data<atarisy2_state>();
43
 
        UINT16 data = state->m_playfield[tile_index];
44
 
        int code = state->m_playfield_tile_bank[(data >> 10) & 1] + (data & 0x3ff);
45
 
        int color = (data >> 11) & 7;
46
 
        SET_TILE_INFO(0, code, color, 0);
47
 
        tileinfo->category = (~data >> 14) & 3;
48
 
}
49
 
 
50
 
 
51
 
 
52
 
/*************************************
53
 
 *
54
 
 *  Video system start
55
 
 *
56
 
 *************************************/
57
 
 
58
 
VIDEO_START( atarisy2 )
59
 
{
60
 
        static const atarimo_desc modesc =
61
 
        {
62
 
                1,                                      /* index to which gfx system */
63
 
                1,                                      /* number of motion object banks */
64
 
                1,                                      /* are the entries linked? */
65
 
                0,                                      /* are the entries split? */
66
 
                0,                                      /* render in reverse order? */
67
 
                0,                                      /* render in swapped X/Y order? */
68
 
                0,                                      /* does the neighbor bit affect the next object? */
69
 
                0,                                      /* pixels per SLIP entry (0 for no-slip) */
70
 
                0,                                      /* pixel offset for SLIPs */
71
 
                0,                                      /* maximum number of links to visit/scanline (0=all) */
72
 
 
73
 
                0x00,                           /* base palette entry */
74
 
                0x40,                           /* maximum number of colors */
75
 
                15,                                     /* transparent pen index */
76
 
 
77
 
                {{ 0,0,0,0x07f8 }},     /* mask for the link */
78
 
                {{ 0 }},                        /* mask for the graphics bank */
79
 
                {{ 0,0x07ff,0,0 }},     /* mask for the code index */
80
 
                {{ 0x0007,0,0,0 }},     /* mask for the upper code index */
81
 
                {{ 0,0,0,0x3000 }},     /* mask for the color */
82
 
                {{ 0,0,0xffc0,0 }},     /* mask for the X position */
83
 
                {{ 0x7fc0,0,0,0 }},     /* mask for the Y position */
84
 
                {{ 0 }},                        /* mask for the width, in tiles*/
85
 
                {{ 0,0x3800,0,0 }},     /* mask for the height, in tiles */
86
 
                {{ 0,0x4000,0,0 }},     /* mask for the horizontal flip */
87
 
                {{ 0 }},                        /* mask for the vertical flip */
88
 
                {{ 0,0,0,0xc000 }},     /* mask for the priority */
89
 
                {{ 0,0x8000,0,0 }},     /* mask for the neighbor */
90
 
                {{ 0 }},                        /* mask for absolute coordinates */
91
 
 
92
 
                {{ 0 }},                        /* mask for the special value */
93
 
                0,                                      /* resulting value to indicate "special" */
94
 
                0                                       /* callback routine for special entries */
95
 
        };
96
 
        atarisy2_state *state = machine.driver_data<atarisy2_state>();
97
 
 
98
 
        /* initialize banked memory */
99
 
        state->m_alpha = &state->m_vram[0x0000];
100
 
        state->m_playfield = &state->m_vram[0x2000];
101
 
 
102
 
        /* initialize the playfield */
103
 
        state->m_playfield_tilemap = tilemap_create(machine, get_playfield_tile_info, tilemap_scan_rows,  8,8, 128,64);
104
 
 
105
 
        /* initialize the motion objects */
106
 
        atarimo_init(machine, 0, &modesc);
107
 
 
108
 
        /* initialize the alphanumerics */
109
 
        state->m_alpha_tilemap = tilemap_create(machine, get_alpha_tile_info, tilemap_scan_rows,  8,8, 64,48);
110
 
        tilemap_set_transparent_pen(state->m_alpha_tilemap, 0);
111
 
 
112
 
        /* reset the statics */
113
 
        state->m_yscroll_reset_timer = machine.scheduler().timer_alloc(FUNC(reset_yscroll_callback));
114
 
        state->m_videobank = 0;
115
 
 
116
 
        /* save states */
117
 
        state->save_item(NAME(state->m_playfield_tile_bank));
118
 
        state->save_item(NAME(state->m_videobank));
119
 
        state->save_item(NAME(state->m_vram));
120
 
}
121
 
 
122
 
 
123
 
 
124
 
/*************************************
125
 
 *
126
 
 *  Scroll/playfield bank write
127
 
 *
128
 
 *************************************/
129
 
 
130
 
WRITE16_HANDLER( atarisy2_xscroll_w )
131
 
{
132
 
        atarisy2_state *state = space->machine().driver_data<atarisy2_state>();
133
 
        UINT16 oldscroll = *state->m_xscroll;
134
 
        UINT16 newscroll = oldscroll;
135
 
        COMBINE_DATA(&newscroll);
136
 
 
137
 
        /* if anything has changed, force a partial update */
138
 
        if (newscroll != oldscroll)
139
 
                space->machine().primary_screen->update_partial(space->machine().primary_screen->vpos());
140
 
 
141
 
        /* update the playfield scrolling - hscroll is clocked on the following scanline */
142
 
        tilemap_set_scrollx(state->m_playfield_tilemap, 0, newscroll >> 6);
143
 
 
144
 
        /* update the playfield banking */
145
 
        if (state->m_playfield_tile_bank[0] != (newscroll & 0x0f) * 0x400)
146
 
        {
147
 
                state->m_playfield_tile_bank[0] = (newscroll & 0x0f) * 0x400;
148
 
                tilemap_mark_all_tiles_dirty(state->m_playfield_tilemap);
149
 
        }
150
 
 
151
 
        /* update the data */
152
 
        *state->m_xscroll = newscroll;
153
 
}
154
 
 
155
 
 
156
 
static TIMER_CALLBACK( reset_yscroll_callback )
157
 
{
158
 
        atarisy2_state *state = machine.driver_data<atarisy2_state>();
159
 
        tilemap_set_scrolly(state->m_playfield_tilemap, 0, param);
160
 
}
161
 
 
162
 
 
163
 
WRITE16_HANDLER( atarisy2_yscroll_w )
164
 
{
165
 
        atarisy2_state *state = space->machine().driver_data<atarisy2_state>();
166
 
        UINT16 oldscroll = *state->m_yscroll;
167
 
        UINT16 newscroll = oldscroll;
168
 
        COMBINE_DATA(&newscroll);
169
 
 
170
 
        /* if anything has changed, force a partial update */
171
 
        if (newscroll != oldscroll)
172
 
                space->machine().primary_screen->update_partial(space->machine().primary_screen->vpos());
173
 
 
174
 
        /* if bit 4 is zero, the scroll value is clocked in right away */
175
 
        if (!(newscroll & 0x10))
176
 
                tilemap_set_scrolly(state->m_playfield_tilemap, 0, (newscroll >> 6) - space->machine().primary_screen->vpos());
177
 
        else
178
 
                state->m_yscroll_reset_timer->adjust(space->machine().primary_screen->time_until_pos(0), newscroll >> 6);
179
 
 
180
 
        /* update the playfield banking */
181
 
        if (state->m_playfield_tile_bank[1] != (newscroll & 0x0f) * 0x400)
182
 
        {
183
 
                state->m_playfield_tile_bank[1] = (newscroll & 0x0f) * 0x400;
184
 
                tilemap_mark_all_tiles_dirty(state->m_playfield_tilemap);
185
 
        }
186
 
 
187
 
        /* update the data */
188
 
        *state->m_yscroll = newscroll;
189
 
}
190
 
 
191
 
 
192
 
 
193
 
/*************************************
194
 
 *
195
 
 *  Palette RAM write handler
196
 
 *
197
 
 *************************************/
198
 
 
199
 
WRITE16_HANDLER( atarisy2_paletteram_w )
200
 
{
201
 
        static const int intensity_table[16] =
202
 
        {
203
 
                #define ZB 115
204
 
                #define Z3 78
205
 
                #define Z2 37
206
 
                #define Z1 17
207
 
                #define Z0 9
208
 
                0, ZB+Z0, ZB+Z1, ZB+Z1+Z0, ZB+Z2, ZB+Z2+Z0, ZB+Z2+Z1, ZB+Z2+Z1+Z0,
209
 
                ZB+Z3, ZB+Z3+Z0, ZB+Z3+Z1, ZB+Z3+Z1+Z0,ZB+ Z3+Z2, ZB+Z3+Z2+Z0, ZB+Z3+Z2+Z1, ZB+Z3+Z2+Z1+Z0
210
 
        };
211
 
        static const int color_table[16] =
212
 
                { 0x0, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xe, 0xf, 0xf };
213
 
 
214
 
        int newword, inten, red, green, blue;
215
 
 
216
 
        COMBINE_DATA(&space->machine().generic.paletteram.u16[offset]);
217
 
        newword = space->machine().generic.paletteram.u16[offset];
218
 
 
219
 
        inten = intensity_table[newword & 15];
220
 
        red = (color_table[(newword >> 12) & 15] * inten) >> 4;
221
 
        green = (color_table[(newword >> 8) & 15] * inten) >> 4;
222
 
        blue = (color_table[(newword >> 4) & 15] * inten) >> 4;
223
 
        palette_set_color(space->machine(), offset, MAKE_RGB(red, green, blue));
224
 
}
225
 
 
226
 
 
227
 
 
228
 
/*************************************
229
 
 *
230
 
 *  Video RAM bank read/write handlers
231
 
 *
232
 
 *************************************/
233
 
 
234
 
READ16_HANDLER( atarisy2_slapstic_r )
235
 
{
236
 
        atarisy2_state *state = space->machine().driver_data<atarisy2_state>();
237
 
        int result = state->m_slapstic_base[offset];
238
 
        slapstic_tweak(space, offset);
239
 
 
240
 
        /* an extra tweak for the next opcode fetch */
241
 
        state->m_videobank = slapstic_tweak(space, 0x1234) * 0x1000;
242
 
        return result;
243
 
}
244
 
 
245
 
 
246
 
WRITE16_HANDLER( atarisy2_slapstic_w )
247
 
{
248
 
        atarisy2_state *state = space->machine().driver_data<atarisy2_state>();
249
 
 
250
 
        slapstic_tweak(space, offset);
251
 
 
252
 
        /* an extra tweak for the next opcode fetch */
253
 
        state->m_videobank = slapstic_tweak(space, 0x1234) * 0x1000;
254
 
}
255
 
 
256
 
 
257
 
 
258
 
/*************************************
259
 
 *
260
 
 *  Video RAM read/write handlers
261
 
 *
262
 
 *************************************/
263
 
 
264
 
READ16_HANDLER( atarisy2_videoram_r )
265
 
{
266
 
        atarisy2_state *state = space->machine().driver_data<atarisy2_state>();
267
 
        int offs = offset | state->m_videobank;
268
 
        if (offs >= 0xc00 && offs < 0x1000)
269
 
        {
270
 
                return atarimo_0_spriteram_r(space, offs - 0x0c00, mem_mask);
271
 
        }
272
 
 
273
 
        return state->m_vram[offs];
274
 
}
275
 
 
276
 
 
277
 
WRITE16_HANDLER( atarisy2_videoram_w )
278
 
{
279
 
        atarisy2_state *state = space->machine().driver_data<atarisy2_state>();
280
 
        int offs = offset | state->m_videobank;
281
 
 
282
 
        /* alpharam? */
283
 
        if (offs < 0x0c00)
284
 
        {
285
 
                COMBINE_DATA(&state->m_alpha[offs]);
286
 
                tilemap_mark_tile_dirty(state->m_alpha_tilemap, offs);
287
 
        }
288
 
 
289
 
        /* spriteram? */
290
 
        else if (offs < 0x1000)
291
 
        {
292
 
                /* force an update if the link of object 0 is about to change */
293
 
                if (offs == 0x0c03)
294
 
                        space->machine().primary_screen->update_partial(space->machine().primary_screen->vpos());
295
 
                atarimo_0_spriteram_w(space, offs - 0x0c00, data, mem_mask);
296
 
        }
297
 
 
298
 
        /* playfieldram? */
299
 
        else if (offs >= 0x2000)
300
 
        {
301
 
                offs -= 0x2000;
302
 
                COMBINE_DATA(&state->m_playfield[offs]);
303
 
                tilemap_mark_tile_dirty(state->m_playfield_tilemap, offs);
304
 
        }
305
 
 
306
 
        /* generic case */
307
 
        else
308
 
        {
309
 
                COMBINE_DATA(&state->m_vram[offs]);
310
 
        }
311
 
}
312
 
 
313
 
 
314
 
 
315
 
/*************************************
316
 
 *
317
 
 *  Main refresh
318
 
 *
319
 
 *************************************/
320
 
 
321
 
SCREEN_UPDATE( atarisy2 )
322
 
{
323
 
        atarisy2_state *state = screen->machine().driver_data<atarisy2_state>();
324
 
        bitmap_t *priority_bitmap = screen->machine().priority_bitmap;
325
 
        atarimo_rect_list rectlist;
326
 
        bitmap_t *mobitmap;
327
 
        int x, y, r;
328
 
 
329
 
        /* draw the playfield */
330
 
        bitmap_fill(priority_bitmap, cliprect, 0);
331
 
        tilemap_draw(bitmap, cliprect, state->m_playfield_tilemap, 0, 0);
332
 
        tilemap_draw(bitmap, cliprect, state->m_playfield_tilemap, 1, 1);
333
 
        tilemap_draw(bitmap, cliprect, state->m_playfield_tilemap, 2, 2);
334
 
        tilemap_draw(bitmap, cliprect, state->m_playfield_tilemap, 3, 3);
335
 
 
336
 
        /* draw and merge the MO */
337
 
        mobitmap = atarimo_render(0, cliprect, &rectlist);
338
 
        for (r = 0; r < rectlist.numrects; r++, rectlist.rect++)
339
 
                for (y = rectlist.rect->min_y; y <= rectlist.rect->max_y; y++)
340
 
                {
341
 
                        UINT16 *mo = (UINT16 *)mobitmap->base + mobitmap->rowpixels * y;
342
 
                        UINT16 *pf = (UINT16 *)bitmap->base + bitmap->rowpixels * y;
343
 
                        UINT8 *pri = (UINT8 *)priority_bitmap->base + priority_bitmap->rowpixels * y;
344
 
                        for (x = rectlist.rect->min_x; x <= rectlist.rect->max_x; x++)
345
 
                                if (mo[x] != 0x0f)
346
 
                                {
347
 
                                        int mopriority = mo[x] >> ATARIMO_PRIORITY_SHIFT;
348
 
 
349
 
                                        /* high priority PF? */
350
 
                                        if ((mopriority + pri[x]) & 2)
351
 
                                        {
352
 
                                                /* only gets priority if PF pen is less than 8 */
353
 
                                                if (!(pf[x] & 0x08))
354
 
                                                        pf[x] = mo[x] & ATARIMO_DATA_MASK;
355
 
                                        }
356
 
 
357
 
                                        /* low priority */
358
 
                                        else
359
 
                                                pf[x] = mo[x] & ATARIMO_DATA_MASK;
360
 
 
361
 
                                        /* erase behind ourselves */
362
 
                                        mo[x] = 0x0f;
363
 
                                }
364
 
                }
365
 
 
366
 
        /* add the alpha on top */
367
 
        tilemap_draw(bitmap, cliprect, state->m_alpha_tilemap, 0, 0);
368
 
        return 0;
369
 
}