1 #include "vidhrdw/generic.h"
2
3 static int bgcharbank;
4 static struct tilemap *bg_tilemap, *fg_tilemap;
5
WRITE16_HANDLER(tigeroad_videoram_w)6 WRITE16_HANDLER( tigeroad_videoram_w )
7 {
8 if (videoram16[offset] != data)
9 {
10 COMBINE_DATA(&videoram16[offset]);
11 tilemap_mark_tile_dirty(fg_tilemap, offset);
12 }
13 }
14
WRITE16_HANDLER(tigeroad_videoctrl_w)15 WRITE16_HANDLER( tigeroad_videoctrl_w )
16 {
17 int bank;
18
19 if (ACCESSING_MSB)
20 {
21 data = (data >> 8) & 0xff;
22
23 /* bit 1 flips screen */
24
25 if (flip_screen != (data & 0x02))
26 {
27 flip_screen_set(data & 0x02);
28 tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
29 }
30
31 /* bit 2 selects bg char bank */
32
33 bank = (data & 0x04) >> 2;
34
35 if (bgcharbank != bank)
36 {
37 bgcharbank = bank;
38 tilemap_mark_all_tiles_dirty(bg_tilemap);
39 }
40
41 /* bits 4-5 are coin lockouts */
42
43 coin_lockout_w(0, !(data & 0x10));
44 coin_lockout_w(1, !(data & 0x20));
45
46 /* bits 6-7 are coin counters */
47
48 coin_counter_w(0, data & 0x40);
49 coin_counter_w(1, data & 0x80);
50 }
51 }
52
WRITE16_HANDLER(tigeroad_scroll_w)53 WRITE16_HANDLER( tigeroad_scroll_w )
54 {
55 int scroll = 0;
56
57 COMBINE_DATA(&scroll);
58
59 switch (offset)
60 {
61 case 0:
62 tilemap_set_scrollx(bg_tilemap, 0, scroll);
63 break;
64 case 1:
65 tilemap_set_scrolly(bg_tilemap, 0, -scroll - 32 * 8);
66 break;
67 }
68 }
69
tigeroad_draw_sprites(struct mame_bitmap * bitmap,int priority)70 static void tigeroad_draw_sprites( struct mame_bitmap *bitmap, int priority )
71 {
72 UINT16 *source = &buffered_spriteram16[spriteram_size/2] - 4;
73 UINT16 *finish = buffered_spriteram16;
74
75 // TODO: The Track Map should probably be drawn on top of the background tilemap...
76 // Also convert the below into a for loop!
77
78 while (source >= finish)
79 {
80 int tile_number = source[0];
81
82 if (tile_number != 0xfff) {
83 int attr = source[1];
84 int sy = source[2] & 0x1ff;
85 int sx = source[3] & 0x1ff;
86
87 int flipx = attr & 0x02;
88 int flipy = attr & 0x01;
89 int color = (attr >> 2) & 0x0f;
90
91 if (sx > 0x100) sx -= 0x200;
92 if (sy > 0x100) sy -= 0x200;
93
94 if (flip_screen)
95 {
96 sx = 240 - sx;
97 sy = 240 - sy;
98 flipx = !flipx;
99 flipy = !flipy;
100 }
101
102 drawgfx(bitmap, Machine->gfx[2],
103 tile_number,
104 color,
105 flipx, flipy,
106 sx, 240 - sy,
107 &Machine->visible_area,
108 TRANSPARENCY_PEN, 15);
109 }
110
111 source -= 4;
112 }
113 }
114
get_bg_tile_info(int tile_index)115 static void get_bg_tile_info(int tile_index)
116 {
117 UINT8 *tilerom = memory_region(REGION_GFX4);
118
119 int data = tilerom[tile_index];
120 int attr = tilerom[tile_index + 1];
121 int code = data + ((attr & 0xc0) << 2) + (bgcharbank << 10);
122 int color = attr & 0x0f;
123 int flags = ((attr & 0x20) ? TILE_FLIPX : 0) | ((attr & 0x10) ? TILE_SPLIT(1) : 0);
124
125 SET_TILE_INFO(1, code, color, flags)
126 }
127
get_fg_tile_info(int tile_index)128 static void get_fg_tile_info(int tile_index)
129 {
130 int data = videoram16[tile_index];
131 int attr = data >> 8;
132 int code = (data & 0xff) + ((attr & 0xc0) << 2) + ((attr & 0x20) << 5);
133 int color = attr & 0x0f;
134 int flags = (attr & 0x10) ? TILE_FLIPY : 0;
135
136 SET_TILE_INFO(0, code, color, flags)
137 }
138
tigeroad_tilemap_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)139 static UINT32 tigeroad_tilemap_scan( UINT32 col, UINT32 row, UINT32 num_cols, UINT32 num_rows )
140 {
141 /* logical (col,row) -> memory offset */
142 return 2 * (col % 8) + 16 * ((127 - row) % 8) + 128 * (col / 8) + 2048 * ((127 - row) / 8);
143 }
144
VIDEO_START(tigeroad)145 VIDEO_START( tigeroad )
146 {
147 bg_tilemap = tilemap_create(get_bg_tile_info, tigeroad_tilemap_scan,
148 TILEMAP_SPLIT, 32, 32, 128, 128);
149
150 if ( !bg_tilemap )
151 return 1;
152
153 fg_tilemap = tilemap_create(get_fg_tile_info, tilemap_scan_rows,
154 TILEMAP_TRANSPARENT, 8, 8, 32, 32);
155
156 if ( !fg_tilemap )
157 return 1;
158
159 tilemap_set_transmask(bg_tilemap, 0, 0xffff, 0);
160 tilemap_set_transmask(bg_tilemap, 1, 0x1ff, 0xfe00);
161
162 tilemap_set_transparent_pen(fg_tilemap, 3);
163
164 return 0;
165 }
166
VIDEO_UPDATE(tigeroad)167 VIDEO_UPDATE( tigeroad )
168 {
169 tilemap_draw(bitmap, &Machine->visible_area, bg_tilemap, TILEMAP_BACK, 0);
170 tigeroad_draw_sprites(bitmap, 0);
171 tilemap_draw(bitmap, &Machine->visible_area, bg_tilemap, TILEMAP_FRONT, 1);
172 //tigeroad_draw_sprites(bitmap, 1); draw priority sprites?
173 tilemap_draw(bitmap, &Machine->visible_area, fg_tilemap, 0, 2);
174 }
175
VIDEO_EOF(tigeroad)176 VIDEO_EOF( tigeroad )
177 {
178 buffer_spriteram16_w(0,0,0);
179 }
180