1 /***************************************************************************
2 Goindol
3
4 Functions to emulate the video hardware of the machine.
5
6 ***************************************************************************/
7
8 #include "driver.h"
9 #include "generic.h"
10
11 UINT8 *goindol_bg_videoram;
12 UINT8 *goindol_fg_videoram;
13 UINT8 *goindol_fg_scrollx;
14 UINT8 *goindol_fg_scrolly;
15
16 size_t goindol_fg_videoram_size;
17 size_t goindol_bg_videoram_size;
18 int goindol_char_bank;
19
20 static struct tilemap *bg_tilemap,*fg_tilemap;
21
22
23
24 /***************************************************************************
25
26 Callbacks for the TileMap code
27
28 ***************************************************************************/
29
get_fg_tile_info(int tile_index)30 static void get_fg_tile_info(int tile_index)
31 {
32 int code = goindol_fg_videoram[2*tile_index+1];
33 int attr = goindol_fg_videoram[2*tile_index];
34 SET_TILE_INFO(
35 0,
36 code | ((attr & 0x7) << 8) | (goindol_char_bank << 11),
37 (attr & 0xf8) >> 3,
38 0)
39 }
40
get_bg_tile_info(int tile_index)41 static void get_bg_tile_info(int tile_index)
42 {
43 int code = goindol_bg_videoram[2*tile_index+1];
44 int attr = goindol_bg_videoram[2*tile_index];
45 SET_TILE_INFO(
46 1,
47 code | ((attr & 0x7) << 8) | (goindol_char_bank << 11),
48 (attr & 0xf8) >> 3,
49 0)
50 }
51
52
53
54 /***************************************************************************
55
56 Start the video hardware emulation.
57
58 ***************************************************************************/
59
VIDEO_START(goindol)60 VIDEO_START( goindol )
61 {
62 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,TILEMAP_SPLIT, 8,8,32,32);
63 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
64
65 if (!fg_tilemap || !bg_tilemap)
66 return 1;
67
68 tilemap_set_transparent_pen(fg_tilemap,0);
69
70 return 0;
71 }
72
73
74 /***************************************************************************
75
76 Memory handlers
77
78 ***************************************************************************/
79
WRITE_HANDLER(goindol_fg_videoram_w)80 WRITE_HANDLER( goindol_fg_videoram_w )
81 {
82 if (goindol_fg_videoram[offset] != data)
83 {
84 goindol_fg_videoram[offset] = data;
85 tilemap_mark_tile_dirty(fg_tilemap,offset / 2);
86 }
87 }
88
WRITE_HANDLER(goindol_bg_videoram_w)89 WRITE_HANDLER( goindol_bg_videoram_w )
90 {
91 if (goindol_bg_videoram[offset] != data)
92 {
93 goindol_bg_videoram[offset] = data;
94 tilemap_mark_tile_dirty(bg_tilemap,offset / 2);
95 }
96 }
97
98
99
100 /***************************************************************************
101
102 Display refresh
103
104 ***************************************************************************/
105
draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect,int gfxbank,unsigned char * sprite_ram)106 static void draw_sprites(struct mame_bitmap *bitmap, const struct rectangle *cliprect, int gfxbank, unsigned char *sprite_ram)
107 {
108 int offs,sx,sy,tile,palette;
109
110 for (offs = 0 ;offs < spriteram_size; offs+=4)
111 {
112 sx = sprite_ram[offs];
113 sy = 240-sprite_ram[offs+1];
114
115 if (flip_screen)
116 {
117 sx = 248 - sx;
118 sy = 248 - sy;
119 }
120
121 if ((sprite_ram[offs+1] >> 3) && (sx < 248))
122 {
123 tile = ((sprite_ram[offs+3])+((sprite_ram[offs+2] & 7) << 8));
124 tile += tile;
125 palette = sprite_ram[offs+2] >> 3;
126
127 drawgfx(bitmap,Machine->gfx[gfxbank],
128 tile,
129 palette,
130 flip_screen,flip_screen,
131 sx,sy,
132 cliprect,
133 TRANSPARENCY_PEN, 0);
134 drawgfx(bitmap,Machine->gfx[gfxbank],
135 tile+1,
136 palette,
137 flip_screen,flip_screen,
138 sx,sy + (flip_screen ? -8 : 8),
139 cliprect,
140 TRANSPARENCY_PEN, 0);
141 }
142 }
143 }
144
VIDEO_UPDATE(goindol)145 VIDEO_UPDATE( goindol )
146 {
147 tilemap_set_scrollx(fg_tilemap,0,*goindol_fg_scrollx);
148 tilemap_set_scrolly(fg_tilemap,0,*goindol_fg_scrolly);
149
150 tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
151 tilemap_draw(bitmap,cliprect,fg_tilemap,0,0);
152 draw_sprites(bitmap,cliprect,1,spriteram);
153 draw_sprites(bitmap,cliprect,0,spriteram_2);
154 }
155