~ubuntu-branches/ubuntu/karmic/xmame/karmic

« back to all changes in this revision

Viewing changes to src/vidhrdw/yard.c

  • Committer: Bazaar Package Importer
  • Author(s): Bruno Barrera C.
  • Date: 2007-02-16 10:06:54 UTC
  • mfrom: (2.1.5 edgy)
  • Revision ID: james.westby@ubuntu.com-20070216100654-iztas2cl47k5j039
Tags: 0.106-2
* Added Italian debconf templates translation. (closes: #382672)
* Added German debconf templates translation. (closes: #396610)
* Added Japanese debconf templates translation. (closes: #400011)
* Added Portuguese debconf templates translation. (closes: #409960)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
***************************************************************************/
13
13
 
14
14
#include "driver.h"
15
 
#include "vidhrdw/generic.h"
16
 
 
17
 
 
18
 
unsigned char *yard_scroll_x_low;
19
 
unsigned char *yard_scroll_x_high;
20
 
unsigned char *yard_scroll_y_low;
21
 
unsigned char *yard_score_panel_disabled;
22
 
static struct mame_bitmap *scroll_panel_bitmap;
 
15
 
 
16
UINT8 *yard_scroll_x_low;
 
17
UINT8 *yard_scroll_x_high;
 
18
UINT8 *yard_scroll_y_low;
 
19
UINT8 *yard_score_panel_disabled;
 
20
static mame_bitmap *scroll_panel_bitmap;
 
21
 
 
22
static tilemap *bg_tilemap;
23
23
 
24
24
#define SCROLL_PANEL_WIDTH  (14*4)
25
 
 
26
25
#define RADAR_PALETTE_BASE (256+16)
 
26
#define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
 
27
#define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
27
28
 
28
 
static struct rectangle panelvisiblearea =
 
29
static rectangle clippanel =
29
30
{
30
31
        26*8, 32*8-1,
31
32
        1*8, 31*8-1
32
33
};
33
34
 
34
 
static struct rectangle panelvisibleareaflip =
 
35
static rectangle clippanelflip =
35
36
{
36
37
        0*8, 6*8-1,
37
38
        1*8, 31*8-1
38
39
};
39
40
 
40
 
 
41
41
/***************************************************************************
42
42
 
43
43
  Convert the color PROMs into a more useable format.
63
63
PALETTE_INIT( yard )
64
64
{
65
65
        int i;
66
 
        #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
67
 
        #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
68
 
 
69
66
 
70
67
        /* character palette */
71
68
        for (i = 0;i < 256;i++)
72
69
        {
73
70
                int bit0,bit1,bit2,r,g,b;
74
71
 
75
 
 
76
72
                /* red component */
77
73
                bit0 = 0;
78
74
                bit1 = (color_prom[256] >> 2) & 0x01;
97
93
        color_prom += 256;
98
94
        /* color_prom now points to the beginning of the sprite palette */
99
95
 
100
 
 
101
96
        /* sprite palette */
102
97
        for (i = 0;i < 16;i++)
103
98
        {
104
99
                int bit0,bit1,bit2,r,g,b;
105
100
 
106
 
 
107
101
                /* red component */
108
102
                bit0 = 0;
109
103
                bit1 = (*color_prom >> 6) & 0x01;
128
122
        color_prom += 16;
129
123
        /* color_prom now points to the beginning of the sprite lookup table */
130
124
 
131
 
 
132
125
        /* sprite lookup table */
133
126
        for (i = 0;i < TOTAL_COLORS(1);i++)
134
127
                COLOR(1,i) = 256 + (*(color_prom++) & 0x0f);
135
128
 
136
129
        /* color_prom now points to the beginning of the radar palette */
137
130
 
138
 
 
139
131
        /* radar palette */
140
132
        for (i = 0;i < 256;i++)
141
133
        {
142
134
                int bit0,bit1,bit2,r,g,b;
143
135
 
144
 
 
145
136
                /* red component */
146
137
                bit0 = 0;
147
138
                bit1 = (color_prom[256] >> 2) & 0x01;
164
155
        }
165
156
}
166
157
 
167
 
 
168
 
 
169
 
/***************************************************************************
170
 
 
171
 
  Start the video hardware emulation.
172
 
 
173
 
***************************************************************************/
174
 
VIDEO_START( yard )
175
 
{
176
 
        if ((dirtybuffer = auto_malloc(videoram_size)) == 0)
177
 
                return 1;
178
 
        memset(dirtybuffer,1,videoram_size);
179
 
 
180
 
        if ((tmpbitmap = auto_bitmap_alloc(Machine->drv->screen_width*2,Machine->drv->screen_height)) == 0)
181
 
                return 1;
182
 
 
183
 
        if ((scroll_panel_bitmap = auto_bitmap_alloc(SCROLL_PANEL_WIDTH,Machine->drv->screen_height)) == 0)
184
 
                return 1;
185
 
 
186
 
        return 0;
187
 
}
188
 
 
189
 
 
190
 
 
191
 
 
192
 
WRITE8_HANDLER( yard_flipscreen_w )
193
 
{
194
 
        /* screen flip is handled both by software and hardware */
195
 
        data ^= ~readinputport(4) & 1;
196
 
 
197
 
        flip_screen_set(data & 1);
198
 
 
199
 
        coin_counter_w(0,data & 0x02);
200
 
        coin_counter_w(1,data & 0x20);
201
 
}
202
 
 
 
158
WRITE8_HANDLER( yard_videoram_w )
 
159
{
 
160
        if (videoram[offset] != data)
 
161
        {
 
162
                videoram[offset] = data;
 
163
                tilemap_mark_tile_dirty(bg_tilemap, offset / 2);
 
164
        }
 
165
}
203
166
 
204
167
WRITE8_HANDLER( yard_scroll_panel_w )
205
168
{
219
182
                col = (data >> i) & 0x11;
220
183
                col = ((col >> 3) | col) & 3;
221
184
 
222
 
                plot_pixel(scroll_panel_bitmap, sx + i, sy, Machine->pens[RADAR_PALETTE_BASE + (sy & 0xfc) + col]);
 
185
                plot_pixel(scroll_panel_bitmap, sx + i, sy,
 
186
                        Machine->pens[RADAR_PALETTE_BASE + (sy & 0xfc) + col]);
223
187
        }
224
188
}
225
189
 
226
 
 
227
 
/***************************************************************************
228
 
 
229
 
  Draw the game screen in the given mame_bitmap.
230
 
  Do NOT call osd_update_display() from this function, it will be called by
231
 
  the main emulation engine.
232
 
 
233
 
***************************************************************************/
234
 
VIDEO_UPDATE( yard )
 
190
static void yard_get_bg_tile_info(int tile_index)
 
191
{
 
192
        int offs = tile_index * 2;
 
193
        int attr = videoram[offs + 1];
 
194
        int code = videoram[offs] + ((attr & 0xc0) << 2);
 
195
        int color = attr & 0x1f;
 
196
        int flags = (attr & 0x20) ? TILE_FLIPX : 0;
 
197
 
 
198
        SET_TILE_INFO(0, code, color, flags)
 
199
}
 
200
 
 
201
static UINT32 yard_tilemap_scan_rows( UINT32 col, UINT32 row, UINT32 num_cols, UINT32 num_rows )
 
202
{
 
203
        /* logical (col,row) -> memory offset */
 
204
        if (col >= 32)
 
205
                return (row+32)*32 + col-32;
 
206
        else
 
207
                return row*32 + col;
 
208
}
 
209
 
 
210
VIDEO_START( yard )
 
211
{
 
212
        bg_tilemap = tilemap_create(yard_get_bg_tile_info, yard_tilemap_scan_rows,
 
213
                TILEMAP_OPAQUE, 8, 8, 64, 32);
 
214
 
 
215
        if ( !bg_tilemap )
 
216
                return 1;
 
217
 
 
218
        if ((scroll_panel_bitmap = auto_bitmap_alloc(SCROLL_PANEL_WIDTH, Machine->drv->screen_height)) == 0)
 
219
                return 1;
 
220
 
 
221
        return 0;
 
222
}
 
223
 
 
224
#define DRAW_SPRITE(code, sy) drawgfx(bitmap, Machine->gfx[1], code, color, flipx, flipy, sx, sy, cliprect, TRANSPARENCY_COLOR, 256);
 
225
 
 
226
static void yard_draw_sprites( mame_bitmap *bitmap, const rectangle *cliprect )
235
227
{
236
228
        int offs;
237
229
 
238
 
 
239
 
        if (get_vh_global_attribute_changed())
240
 
        {
241
 
                memset(dirtybuffer,1,videoram_size);
242
 
        }
243
 
 
244
 
 
245
 
        /* for every character in the Video RAM, check if it has been modified */
246
 
        /* since last time and update it accordingly. */
247
 
        for (offs = videoram_size-2;offs >= 0;offs -= 2)
248
 
        {
249
 
                if (dirtybuffer[offs] || dirtybuffer[offs+1])
250
 
                {
251
 
                        int sx,sy,flipx;
252
 
 
253
 
 
254
 
                        dirtybuffer[offs] = 0;
255
 
                        dirtybuffer[offs+1] = 0;
256
 
 
257
 
                        sx = (offs/2) % 32;
258
 
                        sy = (offs/2) / 32;
259
 
                        flipx = videoram[offs+1] & 0x20;
260
 
 
261
 
                        if (sy >= 32)
262
 
                        {
263
 
                                sy -= 32;
264
 
                                sx += 32;
265
 
                        }
266
 
 
267
 
                        if (flip_screen)
268
 
                        {
269
 
                                sx = 63 - sx;
270
 
                                sy = 31 - sy;
271
 
                                flipx = !flipx;
272
 
                        }
273
 
 
274
 
                        drawgfx(tmpbitmap,Machine->gfx[0],
275
 
                                        videoram[offs] + ((videoram[offs+1] & 0xc0) << 2),
276
 
                                        videoram[offs+1] & 0x1f,
277
 
                                        flipx,flip_screen,
278
 
                                        8*sx,8*sy,
279
 
                                        0,TRANSPARENCY_NONE,0);
280
 
                }
281
 
        }
282
 
 
283
 
        /* copy the temporary bitmap to the screen */
284
 
        {
285
 
                int scroll_x,scroll_y;
286
 
 
287
 
                scroll_x = (*yard_scroll_x_high * 0x100) + *yard_scroll_x_low;
288
 
 
289
 
                if (flip_screen)
290
 
                {
291
 
                        scroll_x += 256;
292
 
                        scroll_y = *yard_scroll_y_low ;
293
 
                }
294
 
                else
295
 
                {
296
 
                        scroll_x = -scroll_x;
297
 
                        scroll_y = -*yard_scroll_y_low ;
298
 
                }
299
 
 
300
 
                copyscrollbitmap(bitmap,tmpbitmap,1,&scroll_x,1,&scroll_y,&Machine->visible_area,TRANSPARENCY_NONE,0);
301
 
        }
302
 
 
303
 
 
304
 
        for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
305
 
        {
306
 
                int code1,code2,bank,sx,sy1,sy2,flipx,flipy;
307
 
 
308
 
 
309
 
                bank  = (spriteram[offs + 1] & 0x20) >> 5;
310
 
                code1 =  spriteram[offs + 2] & 0xbf;
311
 
                sx    =  spriteram[offs + 3];
312
 
                sy1   =  241 - spriteram[offs];
313
 
                flipx =  spriteram[offs + 1] & 0x40;
314
 
                flipy =  spriteram[offs + 1] & 0x80;
 
230
        for (offs = spriteram_size - 4; offs >= 0; offs -= 4)
 
231
        {
 
232
                int attr = spriteram[offs + 1];
 
233
                int bank = (attr & 0x20) >> 5;
 
234
                int code1 = spriteram[offs + 2] & 0xbf;
 
235
                int code2 = 0;
 
236
                int color = attr & 0x1f;
 
237
                int flipx = attr & 0x40;
 
238
                int flipy = attr & 0x80;
 
239
                int sx = spriteram[offs + 3];
 
240
                int sy1 = 241 - spriteram[offs];
 
241
                int sy2 = 0;
315
242
 
316
243
                if (flipy)
317
244
                {
325
252
 
326
253
                if (flip_screen)
327
254
                {
 
255
                        sx = 240 - sx;
 
256
                        sy2 = 224 - sy1;
 
257
                        sy1 = sy2 + 0x10;
328
258
                        flipx = !flipx;
329
259
                        flipy = !flipy;
330
 
                        sx  = 240 - sx;
331
 
                        sy2 = 224 - sy1;
332
 
                        sy1 = sy2 + 0x10;
333
260
                }
334
261
                else
335
262
                {
336
263
                        sy2 = sy1 + 0x10;
337
264
                }
338
265
 
339
 
                drawgfx(bitmap,Machine->gfx[1],
340
 
                                code1 + 256 * bank,
341
 
                                spriteram[offs + 1] & 0x1f,
342
 
                                flipx,flipy,
343
 
                                sx, sy1,
344
 
                                &Machine->visible_area,TRANSPARENCY_COLOR,256);
345
 
 
346
 
                drawgfx(bitmap,Machine->gfx[1],
347
 
                                code2 + 256 * bank,
348
 
                                spriteram[offs + 1] & 0x1f,
349
 
                                flipx,flipy,
350
 
                                sx, sy2,
351
 
                                &Machine->visible_area,TRANSPARENCY_COLOR,256);
 
266
                DRAW_SPRITE(code1 + 256 * bank, sy1)
 
267
                DRAW_SPRITE(code2 + 256 * bank, sy2)
352
268
        }
353
 
 
354
 
 
355
 
        /* draw the static bitmapped area to screen */
 
269
}
 
270
 
 
271
static void yard_draw_panel( mame_bitmap *bitmap, const rectangle *cliprect )
 
272
{
356
273
        if (! *yard_score_panel_disabled)
357
274
        {
358
 
                int xpos;
359
 
 
360
 
                xpos = flip_screen ? Machine->visible_area.min_x - 8 :
361
 
                                     Machine->visible_area.max_x + 1 - SCROLL_PANEL_WIDTH;
362
 
 
363
 
                copybitmap(bitmap,scroll_panel_bitmap,flip_screen,flip_screen,
364
 
                           xpos,0,
365
 
                                   flip_screen ? &panelvisibleareaflip : &panelvisiblearea,TRANSPARENCY_NONE,0);
 
275
                int sx = flip_screen ? cliprect->min_x - 8 : cliprect->max_x + 1 - SCROLL_PANEL_WIDTH;
 
276
 
 
277
                copybitmap(bitmap, scroll_panel_bitmap, flip_screen, flip_screen, sx, 0,
 
278
                        flip_screen ? &clippanelflip : &clippanel, TRANSPARENCY_NONE, 0);
366
279
        }
367
280
}
 
281
 
 
282
VIDEO_UPDATE( yard )
 
283
{
 
284
        tilemap_set_scrollx(bg_tilemap, 0, (*yard_scroll_x_high * 0x100) + *yard_scroll_x_low);
 
285
        tilemap_set_scrolly(bg_tilemap, 0, *yard_scroll_y_low);
 
286
 
 
287
        tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0);
 
288
        yard_draw_sprites(bitmap, cliprect);
 
289
        yard_draw_panel(bitmap, cliprect);
 
290
}