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

« back to all changes in this revision

Viewing changes to mess/src/mame/video/firetrap.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/firetrap.h"
11
 
 
12
 
 
13
 
/***************************************************************************
14
 
 
15
 
  Convert the color PROMs into a more useable format.
16
 
 
17
 
  Fire Trap has one 256x8 and one 256x4 palette PROMs.
18
 
  I don't know for sure how the palette PROMs are connected to the RGB
19
 
  output, but it's probably the usual:
20
 
 
21
 
  bit 7 -- 220 ohm resistor  -- GREEN
22
 
        -- 470 ohm resistor  -- GREEN
23
 
        -- 1  kohm resistor  -- GREEN
24
 
        -- 2.2kohm resistor  -- GREEN
25
 
        -- 220 ohm resistor  -- RED
26
 
        -- 470 ohm resistor  -- RED
27
 
        -- 1  kohm resistor  -- RED
28
 
  bit 0 -- 2.2kohm resistor  -- RED
29
 
 
30
 
  bit 3 -- 220 ohm resistor  -- BLUE
31
 
        -- 470 ohm resistor  -- BLUE
32
 
        -- 1  kohm resistor  -- BLUE
33
 
  bit 0 -- 2.2kohm resistor  -- BLUE
34
 
 
35
 
***************************************************************************/
36
 
 
37
 
PALETTE_INIT( firetrap )
38
 
{
39
 
        int i;
40
 
 
41
 
 
42
 
        for (i = 0; i < machine.total_colors(); i++)
43
 
        {
44
 
                int bit0, bit1, bit2, bit3, r, g, b;
45
 
 
46
 
 
47
 
                bit0 = (color_prom[i] >> 0) & 0x01;
48
 
                bit1 = (color_prom[i] >> 1) & 0x01;
49
 
                bit2 = (color_prom[i] >> 2) & 0x01;
50
 
                bit3 = (color_prom[i] >> 3) & 0x01;
51
 
                r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
52
 
                bit0 = (color_prom[i] >> 4) & 0x01;
53
 
                bit1 = (color_prom[i] >> 5) & 0x01;
54
 
                bit2 = (color_prom[i] >> 6) & 0x01;
55
 
                bit3 = (color_prom[i] >> 7) & 0x01;
56
 
                g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
57
 
                bit0 = (color_prom[i + machine.total_colors()] >> 0) & 0x01;
58
 
                bit1 = (color_prom[i + machine.total_colors()] >> 1) & 0x01;
59
 
                bit2 = (color_prom[i + machine.total_colors()] >> 2) & 0x01;
60
 
                bit3 = (color_prom[i + machine.total_colors()] >> 3) & 0x01;
61
 
                b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
62
 
 
63
 
                palette_set_color(machine, i, MAKE_RGB(r,g,b));
64
 
        }
65
 
}
66
 
 
67
 
 
68
 
/***************************************************************************
69
 
 
70
 
  Callbacks for the TileMap code
71
 
 
72
 
***************************************************************************/
73
 
 
74
 
static TILEMAP_MAPPER( get_fg_memory_offset )
75
 
{
76
 
        return (row ^ 0x1f) + (col << 5);
77
 
}
78
 
 
79
 
static TILEMAP_MAPPER( get_bg_memory_offset )
80
 
{
81
 
        return ((row & 0x0f) ^ 0x0f) | ((col & 0x0f) << 4) |
82
 
                        /* hole at bit 8 */
83
 
                        ((row & 0x10) << 5) | ((col & 0x10) << 6);
84
 
}
85
 
 
86
 
static TILE_GET_INFO( get_fg_tile_info )
87
 
{
88
 
        firetrap_state *state = machine.driver_data<firetrap_state>();
89
 
        int code = state->m_fgvideoram[tile_index];
90
 
        int color = state->m_fgvideoram[tile_index + 0x400];
91
 
        SET_TILE_INFO(
92
 
                        0,
93
 
                        code | ((color & 0x01) << 8),
94
 
                        color >> 4,
95
 
                        0);
96
 
}
97
 
 
98
 
INLINE void get_bg_tile_info(running_machine &machine, tile_data *tileinfo, int tile_index, UINT8 *bgvideoram, int gfx_region)
99
 
{
100
 
        int code = bgvideoram[tile_index];
101
 
        int color = bgvideoram[tile_index + 0x100];
102
 
        SET_TILE_INFO(
103
 
                        gfx_region,
104
 
                        code + ((color & 0x03) << 8),
105
 
                        (color & 0x30) >> 4,
106
 
                        TILE_FLIPXY((color & 0x0c) >> 2));
107
 
}
108
 
 
109
 
static TILE_GET_INFO( get_bg1_tile_info )
110
 
{
111
 
        firetrap_state *state = machine.driver_data<firetrap_state>();
112
 
        get_bg_tile_info(machine, tileinfo, tile_index, state->m_bg1videoram, 1);
113
 
}
114
 
 
115
 
static TILE_GET_INFO( get_bg2_tile_info )
116
 
{
117
 
        firetrap_state *state = machine.driver_data<firetrap_state>();
118
 
        get_bg_tile_info(machine, tileinfo, tile_index, state->m_bg2videoram, 2);
119
 
}
120
 
 
121
 
 
122
 
/***************************************************************************
123
 
 
124
 
  Start the video hardware emulation.
125
 
 
126
 
***************************************************************************/
127
 
 
128
 
VIDEO_START( firetrap )
129
 
{
130
 
        firetrap_state *state = machine.driver_data<firetrap_state>();
131
 
        state->m_fg_tilemap  = tilemap_create(machine, get_fg_tile_info, get_fg_memory_offset, 8, 8, 32, 32);
132
 
        state->m_bg1_tilemap = tilemap_create(machine, get_bg1_tile_info, get_bg_memory_offset, 16, 16, 32, 32);
133
 
        state->m_bg2_tilemap = tilemap_create(machine, get_bg2_tile_info, get_bg_memory_offset, 16, 16, 32, 32);
134
 
 
135
 
        tilemap_set_transparent_pen(state->m_fg_tilemap, 0);
136
 
        tilemap_set_transparent_pen(state->m_bg1_tilemap, 0);
137
 
}
138
 
 
139
 
 
140
 
/***************************************************************************
141
 
 
142
 
  Memory handlers
143
 
 
144
 
***************************************************************************/
145
 
 
146
 
WRITE8_HANDLER( firetrap_fgvideoram_w )
147
 
{
148
 
        firetrap_state *state = space->machine().driver_data<firetrap_state>();
149
 
        state->m_fgvideoram[offset] = data;
150
 
        tilemap_mark_tile_dirty(state->m_fg_tilemap, offset & 0x3ff);
151
 
}
152
 
 
153
 
WRITE8_HANDLER( firetrap_bg1videoram_w )
154
 
{
155
 
        firetrap_state *state = space->machine().driver_data<firetrap_state>();
156
 
        state->m_bg1videoram[offset] = data;
157
 
        tilemap_mark_tile_dirty(state->m_bg1_tilemap, offset & 0x6ff);
158
 
}
159
 
 
160
 
WRITE8_HANDLER( firetrap_bg2videoram_w )
161
 
{
162
 
        firetrap_state *state = space->machine().driver_data<firetrap_state>();
163
 
        state->m_bg2videoram[offset] = data;
164
 
        tilemap_mark_tile_dirty(state->m_bg2_tilemap, offset & 0x6ff);
165
 
}
166
 
 
167
 
 
168
 
WRITE8_HANDLER( firetrap_bg1_scrollx_w )
169
 
{
170
 
        firetrap_state *state = space->machine().driver_data<firetrap_state>();
171
 
        state->m_scroll1_x[offset] = data;
172
 
        tilemap_set_scrollx(state->m_bg1_tilemap, 0, state->m_scroll1_x[0] | (state->m_scroll1_x[1] << 8));
173
 
}
174
 
 
175
 
WRITE8_HANDLER( firetrap_bg1_scrolly_w )
176
 
{
177
 
        firetrap_state *state = space->machine().driver_data<firetrap_state>();
178
 
        state->m_scroll1_y[offset] = data;
179
 
        tilemap_set_scrolly(state->m_bg1_tilemap, 0, -(state->m_scroll1_y[0] | (state->m_scroll1_y[1] << 8)));
180
 
}
181
 
 
182
 
WRITE8_HANDLER( firetrap_bg2_scrollx_w )
183
 
{
184
 
        firetrap_state *state = space->machine().driver_data<firetrap_state>();
185
 
        state->m_scroll2_x[offset] = data;
186
 
        tilemap_set_scrollx(state->m_bg2_tilemap, 0, state->m_scroll2_x[0] | (state->m_scroll2_x[1] << 8));
187
 
}
188
 
 
189
 
WRITE8_HANDLER( firetrap_bg2_scrolly_w )
190
 
{
191
 
        firetrap_state *state = space->machine().driver_data<firetrap_state>();
192
 
        state->m_scroll2_y[offset] = data;
193
 
        tilemap_set_scrolly(state->m_bg2_tilemap, 0, -(state->m_scroll2_y[0] | (state->m_scroll2_y[1] << 8)));
194
 
}
195
 
 
196
 
 
197
 
/***************************************************************************
198
 
 
199
 
  Display refresh
200
 
 
201
 
***************************************************************************/
202
 
 
203
 
static void draw_sprites( running_machine &machine, bitmap_t *bitmap, const rectangle *cliprect )
204
 
{
205
 
        firetrap_state *state = machine.driver_data<firetrap_state>();
206
 
        int offs;
207
 
 
208
 
        for (offs = 0; offs < state->m_spriteram_size; offs += 4)
209
 
        {
210
 
                int sx, sy, flipx, flipy, code, color;
211
 
 
212
 
 
213
 
                /* the meaning of bit 3 of [offs] is unknown */
214
 
 
215
 
                sy = state->m_spriteram[offs];
216
 
                sx = state->m_spriteram[offs + 2];
217
 
                code = state->m_spriteram[offs + 3] + 4 * (state->m_spriteram[offs + 1] & 0xc0);
218
 
                color = ((state->m_spriteram[offs + 1] & 0x08) >> 2) | (state->m_spriteram[offs + 1] & 0x01);
219
 
                flipx = state->m_spriteram[offs + 1] & 0x04;
220
 
                flipy = state->m_spriteram[offs + 1] & 0x02;
221
 
                if (flip_screen_get(machine))
222
 
                {
223
 
                        sx = 240 - sx;
224
 
                        sy = 240 - sy;
225
 
                        flipx = !flipx;
226
 
                        flipy = !flipy;
227
 
                }
228
 
 
229
 
                if (state->m_spriteram[offs + 1] & 0x10)        /* double width */
230
 
                {
231
 
                        if (flip_screen_get(machine)) sy -= 16;
232
 
 
233
 
                        drawgfx_transpen(bitmap,cliprect,machine.gfx[3],
234
 
                                        code & ~1,
235
 
                                        color,
236
 
                                        flipx,flipy,
237
 
                                        sx,flipy ? sy : sy + 16,0);
238
 
                        drawgfx_transpen(bitmap,cliprect,machine.gfx[3],
239
 
                                        code | 1,
240
 
                                        color,
241
 
                                        flipx,flipy,
242
 
                                        sx,flipy ? sy + 16 : sy,0);
243
 
 
244
 
                        /* redraw with wraparound */
245
 
                        drawgfx_transpen(bitmap,cliprect,machine.gfx[3],
246
 
                                        code & ~1,
247
 
                                        color,
248
 
                                        flipx,flipy,
249
 
                                        sx - 256,flipy ? sy : sy + 16,0);
250
 
                        drawgfx_transpen(bitmap,cliprect,machine.gfx[3],
251
 
                                        code | 1,
252
 
                                        color,
253
 
                                        flipx,flipy,
254
 
                                        sx - 256,flipy ? sy + 16 : sy,0);
255
 
                }
256
 
                else
257
 
                {
258
 
                        drawgfx_transpen(bitmap,cliprect,machine.gfx[3],
259
 
                                        code,
260
 
                                        color,
261
 
                                        flipx,flipy,
262
 
                                        sx,sy,0);
263
 
 
264
 
                        /* redraw with wraparound */
265
 
                        drawgfx_transpen(bitmap,cliprect,machine.gfx[3],
266
 
                                        code,
267
 
                                        color,
268
 
                                        flipx,flipy,
269
 
                                        sx - 256,sy,0);
270
 
                }
271
 
        }
272
 
}
273
 
 
274
 
SCREEN_UPDATE( firetrap )
275
 
{
276
 
        firetrap_state *state = screen->machine().driver_data<firetrap_state>();
277
 
        tilemap_draw(bitmap, cliprect, state->m_bg2_tilemap, 0, 0);
278
 
        tilemap_draw(bitmap, cliprect, state->m_bg1_tilemap, 0, 0);
279
 
        draw_sprites(screen->machine(), bitmap, cliprect);
280
 
        tilemap_draw(bitmap, cliprect, state->m_fg_tilemap, 0, 0);
281
 
        return 0;
282
 
}