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

« back to all changes in this revision

Viewing changes to mess/src/mame/video/popeye.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
 
  video.c
4
 
 
5
 
  Functions to emulate the video hardware of the machine.
6
 
 
7
 
***************************************************************************/
8
 
 
9
 
#include "emu.h"
10
 
#include "includes/popeye.h"
11
 
 
12
 
static const size_t popeye_bitmapram_size = 0x2000;
13
 
 
14
 
enum { TYPE_SKYSKIPR, TYPE_POPEYE };
15
 
 
16
 
 
17
 
 
18
 
/***************************************************************************
19
 
 
20
 
  Convert the color PROMs into a more useable format.
21
 
 
22
 
  Popeye has four color PROMS:
23
 
  - 32x8 char palette
24
 
  - 32x8 background palette
25
 
  - two 256x4 sprite palette
26
 
 
27
 
  The char and sprite PROMs are connected to the RGB output this way:
28
 
 
29
 
  bit 7 -- 220 ohm resistor  -- BLUE (inverted)
30
 
        -- 470 ohm resistor  -- BLUE (inverted)
31
 
        -- 220 ohm resistor  -- GREEN (inverted)
32
 
        -- 470 ohm resistor  -- GREEN (inverted)
33
 
        -- 1  kohm resistor  -- GREEN (inverted)
34
 
        -- 220 ohm resistor  -- RED (inverted)
35
 
        -- 470 ohm resistor  -- RED (inverted)
36
 
  bit 0 -- 1  kohm resistor  -- RED (inverted)
37
 
 
38
 
  The background PROM is connected to the RGB output this way:
39
 
 
40
 
  bit 7 -- 470 ohm resistor  -- BLUE (inverted)
41
 
        -- 680 ohm resistor  -- BLUE (inverted)  (1300 ohm in Sky Skipper)
42
 
        -- 470 ohm resistor  -- GREEN (inverted)
43
 
        -- 680 ohm resistor  -- GREEN (inverted)
44
 
        -- 1.2kohm resistor  -- GREEN (inverted)
45
 
        -- 470 ohm resistor  -- RED (inverted)
46
 
        -- 680 ohm resistor  -- RED (inverted)
47
 
  bit 0 -- 1.2kohm resistor  -- RED (inverted)
48
 
 
49
 
  The bootleg is the same, but the outputs are not inverted.
50
 
 
51
 
***************************************************************************/
52
 
static void convert_color_prom(running_machine &machine,const UINT8 *color_prom)
53
 
{
54
 
        popeye_state *state = machine.driver_data<popeye_state>();
55
 
        int i;
56
 
 
57
 
 
58
 
        /* palette entries 0-15 are directly used by the background and changed at runtime */
59
 
        color_prom += 32;
60
 
 
61
 
        /* characters */
62
 
        for (i = 0;i < 16;i++)
63
 
        {
64
 
                int prom_offs = i | ((i & 8) << 1);     /* address bits 3 and 4 are tied together */
65
 
                int bit0,bit1,bit2,r,g,b;
66
 
 
67
 
                /* red component */
68
 
                bit0 = ((color_prom[prom_offs] ^ state->m_invertmask) >> 0) & 0x01;
69
 
                bit1 = ((color_prom[prom_offs] ^ state->m_invertmask) >> 1) & 0x01;
70
 
                bit2 = ((color_prom[prom_offs] ^ state->m_invertmask) >> 2) & 0x01;
71
 
                r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
72
 
                /* green component */
73
 
                bit0 = ((color_prom[prom_offs] ^ state->m_invertmask) >> 3) & 0x01;
74
 
                bit1 = ((color_prom[prom_offs] ^ state->m_invertmask) >> 4) & 0x01;
75
 
                bit2 = ((color_prom[prom_offs] ^ state->m_invertmask) >> 5) & 0x01;
76
 
                g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
77
 
                /* blue component */
78
 
                bit0 = 0;
79
 
                bit1 = ((color_prom[prom_offs] ^ state->m_invertmask) >> 6) & 0x01;
80
 
                bit2 = ((color_prom[prom_offs] ^ state->m_invertmask) >> 7) & 0x01;
81
 
                b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
82
 
 
83
 
                palette_set_color(machine,16 + (2 * i) + 1,MAKE_RGB(r,g,b));
84
 
        }
85
 
 
86
 
        color_prom += 32;
87
 
 
88
 
        /* sprites */
89
 
        for (i = 0;i < 256;i++)
90
 
        {
91
 
                int bit0,bit1,bit2,r,g,b;
92
 
 
93
 
 
94
 
                /* red component */
95
 
                bit0 = ((color_prom[0] ^ state->m_invertmask) >> 0) & 0x01;
96
 
                bit1 = ((color_prom[0] ^ state->m_invertmask) >> 1) & 0x01;
97
 
                bit2 = ((color_prom[0] ^ state->m_invertmask) >> 2) & 0x01;
98
 
                r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
99
 
                /* green component */
100
 
                bit0 = ((color_prom[0] ^ state->m_invertmask) >> 3) & 0x01;
101
 
                bit1 = ((color_prom[256] ^ state->m_invertmask) >> 0) & 0x01;
102
 
                bit2 = ((color_prom[256] ^ state->m_invertmask) >> 1) & 0x01;
103
 
                g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
104
 
                /* blue component */
105
 
                bit0 = 0;
106
 
                bit1 = ((color_prom[256] ^ state->m_invertmask) >> 2) & 0x01;
107
 
                bit2 = ((color_prom[256] ^ state->m_invertmask) >> 3) & 0x01;
108
 
                b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
109
 
 
110
 
                palette_set_color(machine,48+i,MAKE_RGB(r,g,b));
111
 
 
112
 
                color_prom++;
113
 
        }
114
 
}
115
 
 
116
 
PALETTE_INIT( popeye )
117
 
{
118
 
        popeye_state *state = machine.driver_data<popeye_state>();
119
 
        state->m_invertmask = 0xff;
120
 
 
121
 
        convert_color_prom(machine,color_prom);
122
 
}
123
 
 
124
 
PALETTE_INIT( popeyebl )
125
 
{
126
 
        popeye_state *state = machine.driver_data<popeye_state>();
127
 
        state->m_invertmask = 0x00;
128
 
 
129
 
        convert_color_prom(machine,color_prom);
130
 
}
131
 
 
132
 
static void set_background_palette(running_machine &machine,int bank)
133
 
{
134
 
        popeye_state *state = machine.driver_data<popeye_state>();
135
 
        int i;
136
 
        UINT8 *color_prom = machine.region("proms")->base() + 16 * bank;
137
 
 
138
 
        for (i = 0;i < 16;i++)
139
 
        {
140
 
                int bit0,bit1,bit2;
141
 
                int r,g,b;
142
 
 
143
 
                /* red component */
144
 
                bit0 = ((*color_prom ^ state->m_invertmask) >> 0) & 0x01;
145
 
                bit1 = ((*color_prom ^ state->m_invertmask) >> 1) & 0x01;
146
 
                bit2 = ((*color_prom ^ state->m_invertmask) >> 2) & 0x01;
147
 
                r = 0x1c * bit0 + 0x31 * bit1 + 0x47 * bit2;
148
 
                /* green component */
149
 
                bit0 = ((*color_prom ^ state->m_invertmask) >> 3) & 0x01;
150
 
                bit1 = ((*color_prom ^ state->m_invertmask) >> 4) & 0x01;
151
 
                bit2 = ((*color_prom ^ state->m_invertmask) >> 5) & 0x01;
152
 
                g = 0x1c * bit0 + 0x31 * bit1 + 0x47 * bit2;
153
 
                /* blue component */
154
 
                bit0 = 0;
155
 
                bit1 = ((*color_prom ^ state->m_invertmask) >> 6) & 0x01;
156
 
                bit2 = ((*color_prom ^ state->m_invertmask) >> 7) & 0x01;
157
 
                if (state->m_bitmap_type == TYPE_SKYSKIPR)
158
 
                {
159
 
                        /* Sky Skipper has different weights */
160
 
                        bit0 = bit1;
161
 
                        bit1 = 0;
162
 
                }
163
 
                b = 0x1c * bit0 + 0x31 * bit1 + 0x47 * bit2;
164
 
 
165
 
                palette_set_color(machine,i,MAKE_RGB(r,g,b));
166
 
 
167
 
                color_prom++;
168
 
        }
169
 
}
170
 
 
171
 
WRITE8_HANDLER( popeye_videoram_w )
172
 
{
173
 
        popeye_state *state = space->machine().driver_data<popeye_state>();
174
 
        state->m_videoram[offset] = data;
175
 
        tilemap_mark_tile_dirty(state->m_fg_tilemap, offset);
176
 
}
177
 
 
178
 
WRITE8_HANDLER( popeye_colorram_w )
179
 
{
180
 
        popeye_state *state = space->machine().driver_data<popeye_state>();
181
 
        state->m_colorram[offset] = data;
182
 
        tilemap_mark_tile_dirty(state->m_fg_tilemap, offset);
183
 
}
184
 
 
185
 
WRITE8_HANDLER( popeye_bitmap_w )
186
 
{
187
 
        popeye_state *state = space->machine().driver_data<popeye_state>();
188
 
        int sx,sy,x,y,colour;
189
 
 
190
 
        state->m_bitmapram[offset] = data;
191
 
 
192
 
        if (state->m_bitmap_type == TYPE_SKYSKIPR)
193
 
        {
194
 
                sx = 8 * (offset % 128);
195
 
                sy = 8 * (offset / 128);
196
 
 
197
 
                if (flip_screen_get(space->machine()))
198
 
                        sy = 512-8 - sy;
199
 
 
200
 
                colour = data & 0x0f;
201
 
                for (y = 0; y < 8; y++)
202
 
                {
203
 
                        for (x = 0; x < 8; x++)
204
 
                        {
205
 
                                *BITMAP_ADDR16(state->m_tmpbitmap2, sy+y, sx+x) = colour;
206
 
                        }
207
 
                }
208
 
        }
209
 
        else
210
 
        {
211
 
                sx = 8 * (offset % 64);
212
 
                sy = 4 * (offset / 64);
213
 
 
214
 
                if (flip_screen_get(space->machine()))
215
 
                        sy = 512-4 - sy;
216
 
 
217
 
                colour = data & 0x0f;
218
 
                for (y = 0; y < 4; y++)
219
 
                {
220
 
                        for (x = 0; x < 8; x++)
221
 
                        {
222
 
                                *BITMAP_ADDR16(state->m_tmpbitmap2, sy+y, sx+x) = colour;
223
 
                        }
224
 
                }
225
 
        }
226
 
}
227
 
 
228
 
WRITE8_HANDLER( skyskipr_bitmap_w )
229
 
{
230
 
        offset = ((offset & 0xfc0) << 1) | (offset & 0x03f);
231
 
        if (data & 0x80)
232
 
                offset |= 0x40;
233
 
 
234
 
        popeye_bitmap_w(space,offset,data);
235
 
}
236
 
 
237
 
static TILE_GET_INFO( get_fg_tile_info )
238
 
{
239
 
        popeye_state *state = machine.driver_data<popeye_state>();
240
 
        int code = state->m_videoram[tile_index];
241
 
        int color = state->m_colorram[tile_index] & 0x0f;
242
 
 
243
 
        SET_TILE_INFO(0, code, color, 0);
244
 
}
245
 
 
246
 
VIDEO_START( skyskipr )
247
 
{
248
 
        popeye_state *state = machine.driver_data<popeye_state>();
249
 
        state->m_bitmapram = auto_alloc_array(machine, UINT8, popeye_bitmapram_size);
250
 
        state->m_tmpbitmap2 = auto_bitmap_alloc(machine,1024,1024,machine.primary_screen->format());    /* actually 1024x512 but not rolling over vertically? */
251
 
 
252
 
        state->m_bitmap_type = TYPE_SKYSKIPR;
253
 
 
254
 
        state->m_fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows, 16, 16, 32, 32);
255
 
        tilemap_set_transparent_pen(state->m_fg_tilemap, 0);
256
 
 
257
 
    state->m_lastflip = 0;
258
 
 
259
 
    state_save_register_global(machine, state->m_lastflip);
260
 
    state_save_register_global_bitmap(machine, state->m_tmpbitmap2);
261
 
    state_save_register_global_pointer(machine, state->m_bitmapram, popeye_bitmapram_size);
262
 
}
263
 
 
264
 
VIDEO_START( popeye )
265
 
{
266
 
        popeye_state *state = machine.driver_data<popeye_state>();
267
 
        state->m_bitmapram = auto_alloc_array(machine, UINT8, popeye_bitmapram_size);
268
 
        state->m_tmpbitmap2 = auto_bitmap_alloc(machine,512,512,machine.primary_screen->format());
269
 
 
270
 
        state->m_bitmap_type = TYPE_POPEYE;
271
 
 
272
 
        state->m_fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows, 16, 16, 32, 32);
273
 
        tilemap_set_transparent_pen(state->m_fg_tilemap, 0);
274
 
 
275
 
    state->m_lastflip = 0;
276
 
 
277
 
    state_save_register_global(machine, state->m_lastflip);
278
 
    state_save_register_global_bitmap(machine, state->m_tmpbitmap2);
279
 
    state_save_register_global_pointer(machine, state->m_bitmapram, popeye_bitmapram_size);
280
 
}
281
 
 
282
 
static void draw_background(running_machine &machine, bitmap_t *bitmap, const rectangle *cliprect)
283
 
{
284
 
        popeye_state *state = machine.driver_data<popeye_state>();
285
 
        int offs;
286
 
        address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
287
 
 
288
 
        if (state->m_lastflip != flip_screen_get(machine))
289
 
        {
290
 
                for (offs = 0;offs < popeye_bitmapram_size;offs++)
291
 
                        popeye_bitmap_w(space,offs,state->m_bitmapram[offs]);
292
 
 
293
 
                state->m_lastflip = flip_screen_get(machine);
294
 
        }
295
 
 
296
 
        set_background_palette(machine, (*state->m_palettebank & 0x08) >> 3);
297
 
 
298
 
        if (state->m_background_pos[1] == 0)    /* no background */
299
 
                bitmap_fill(bitmap,cliprect,0);
300
 
        else
301
 
        {
302
 
                /* copy the background graphics */
303
 
                int scrollx = 200 - state->m_background_pos[0] - 256*(state->m_background_pos[2]&1); /* ??? */
304
 
                int scrolly = 2 * (256 - state->m_background_pos[1]);
305
 
 
306
 
                if (state->m_bitmap_type == TYPE_SKYSKIPR)
307
 
                        scrollx = 2*scrollx - 512;
308
 
 
309
 
                if (flip_screen_get(machine))
310
 
                {
311
 
                        if (state->m_bitmap_type == TYPE_POPEYE)
312
 
                                scrollx = -scrollx;
313
 
                        scrolly = -scrolly;
314
 
                }
315
 
 
316
 
                copyscrollbitmap(bitmap,state->m_tmpbitmap2,1,&scrollx,1,&scrolly,cliprect);
317
 
        }
318
 
}
319
 
 
320
 
static void draw_sprites(running_machine &machine, bitmap_t *bitmap, const rectangle *cliprect)
321
 
{
322
 
        popeye_state *state = machine.driver_data<popeye_state>();
323
 
        UINT8 *spriteram = state->m_spriteram;
324
 
        int offs;
325
 
 
326
 
        for (offs = 0;offs < state->m_spriteram_size;offs += 4)
327
 
        {
328
 
                int code,color,flipx,flipy,sx,sy;
329
 
 
330
 
                /*
331
 
         * offs+3:
332
 
         * bit 7 ?
333
 
         * bit 6 ?
334
 
         * bit 5 ?
335
 
         * bit 4 MSB of sprite code
336
 
         * bit 3 vertical flip
337
 
         * bit 2 sprite bank
338
 
         * bit 1 \ color (with bit 2 as well)
339
 
         * bit 0 /
340
 
         */
341
 
 
342
 
                code = (spriteram[offs + 2] & 0x7f) + ((spriteram[offs + 3] & 0x10) << 3)
343
 
                                                        + ((spriteram[offs + 3] & 0x04) << 6);
344
 
                color = (spriteram[offs + 3] & 0x07) + 8*(*state->m_palettebank & 0x07);
345
 
                if (state->m_bitmap_type == TYPE_SKYSKIPR)
346
 
                {
347
 
                        /* Two of the PROM address pins are tied together and one is not connected... */
348
 
                        color = (color & 0x0f) | ((color & 0x08) << 1);
349
 
                }
350
 
 
351
 
                flipx = spriteram[offs + 2] & 0x80;
352
 
                flipy = spriteram[offs + 3] & 0x08;
353
 
 
354
 
                sx = 2*(spriteram[offs])-8;
355
 
                sy = 2*(256-spriteram[offs + 1]);
356
 
 
357
 
                if (flip_screen_get(machine))
358
 
                {
359
 
                        flipx = !flipx;
360
 
                        flipy = !flipy;
361
 
                        sx = 496 - sx;
362
 
                        sy = 496 - sy;
363
 
                }
364
 
 
365
 
                if (spriteram[offs] != 0)
366
 
                        drawgfx_transpen(bitmap,cliprect,machine.gfx[1],
367
 
                                        code ^ 0x1ff,
368
 
                                        color,
369
 
                                        flipx,flipy,
370
 
                                        sx,sy,0);
371
 
        }
372
 
}
373
 
 
374
 
SCREEN_UPDATE( popeye )
375
 
{
376
 
        popeye_state *state = screen->machine().driver_data<popeye_state>();
377
 
        draw_background(screen->machine(), bitmap, cliprect);
378
 
        draw_sprites(screen->machine(), bitmap, cliprect);
379
 
        tilemap_draw(bitmap, cliprect, state->m_fg_tilemap, 0, 0);
380
 
        return 0;
381
 
}