1 /***************************************************************************
2
3 vidhrdw.c
4
5 Functions to emulate the video hardware of the machine.
6
7 ***************************************************************************/
8
9 #include "vidhrdw/generic.h"
10
11 static struct tilemap *background_layer,*text_layer;
12
13
get_back_tile_info(int tile_index)14 static void get_back_tile_info(int tile_index)
15 {
16 int tile = videoram16[tile_index];
17 int color = (tile>>12)&0xf;
18
19 tile &= 0xfff;
20
21 SET_TILE_INFO(
22 1,
23 tile,
24 color,
25 0)
26 }
27
get_text_tile_info(int tile_index)28 static void get_text_tile_info(int tile_index)
29 {
30 int tile = colorram16[tile_index];
31 int color = (tile>>10);
32
33 tile &= 0x3ff;
34
35 SET_TILE_INFO(
36 0,
37 tile,
38 color,
39 0)
40 }
41
42
VIDEO_START(cabal)43 VIDEO_START( cabal )
44 {
45 background_layer = tilemap_create(get_back_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,16,16);
46 text_layer = tilemap_create(get_text_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8,8,32,32);
47
48 if (!text_layer || !background_layer ) return 1;
49
50 tilemap_set_transparent_pen(text_layer,3);
51 tilemap_set_transparent_pen(background_layer,15);
52
53 return 0;
54 }
55
56
57 /**************************************************************************/
58
WRITE16_HANDLER(cabal_flipscreen_w)59 WRITE16_HANDLER( cabal_flipscreen_w )
60 {
61 if (ACCESSING_LSB)
62 {
63 int flip = (data & 0x20) ? (TILEMAP_FLIPX | TILEMAP_FLIPY) : 0;
64 tilemap_set_flip(background_layer,flip);
65 tilemap_set_flip(text_layer,flip);
66
67 flip_screen_set(data & 0x20);
68 }
69 }
70
WRITE16_HANDLER(cabal_background_videoram16_w)71 WRITE16_HANDLER( cabal_background_videoram16_w )
72 {
73 int oldword = videoram16[offset];
74 COMBINE_DATA(&videoram16[offset]);
75 if (oldword != videoram16[offset])
76 tilemap_mark_tile_dirty(background_layer,offset);
77 }
78
WRITE16_HANDLER(cabal_text_videoram16_w)79 WRITE16_HANDLER( cabal_text_videoram16_w )
80 {
81 int oldword = colorram16[offset];
82 COMBINE_DATA(&colorram16[offset]);
83 if (oldword != colorram16[offset])
84 tilemap_mark_tile_dirty(text_layer,offset);
85 }
86
87
88 /********************************************************************
89
90 Cabal Spriteram
91 ---------------
92
93 +0 .......x ........ Sprite enable bit
94 +0 ........ xxxxxxxx Sprite Y coordinate
95 +1 ..??.... ........ ??? unknown ???
96 +1 ....xxxx xxxxxxxx Sprite tile number
97 +2 .xxxx... ........ Sprite color bank
98 +2 .....x.. ........ Sprite flip x
99 +2 .......x xxxxxxxx Sprite X coordinate
100 +3 (unused)
101
102 -------E YYYYYYYY
103 ----BBTT TTTTTTTT
104 -CCCCF-X XXXXXXXX
105 -------- --------
106
107 ********************************************************************/
108
cabal_draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)109 static void cabal_draw_sprites( struct mame_bitmap *bitmap, const struct rectangle *cliprect )
110 {
111 int offs,data0,data1,data2;
112
113 for( offs = spriteram_size/2 - 4; offs >= 0; offs -= 4 )
114 {
115 data0 = spriteram16[offs];
116 data1 = spriteram16[offs+1];
117 data2 = spriteram16[offs+2];
118
119 if( data0 & 0x100 )
120 {
121 int tile_number = data1 & 0xfff;
122 int color = ( data2 & 0x7800 ) >> 11;
123 int sy = ( data0 & 0xff );
124 int sx = ( data2 & 0x1ff );
125 int flipx = ( data2 & 0x0400 );
126 int flipy = 0;
127
128 if ( sx>256 ) sx -= 512;
129
130 if (flip_screen)
131 {
132 sx = 240 - sx;
133 sy = 240 - sy;
134 flipx = !flipx;
135 flipy = !flipy;
136 }
137
138 drawgfx( bitmap,Machine->gfx[2],
139 tile_number,
140 color,
141 flipx,flipy,
142 sx,sy,
143 cliprect,TRANSPARENCY_PEN,0xf );
144 }
145 }
146 }
147
148
VIDEO_UPDATE(cabal)149 VIDEO_UPDATE( cabal )
150 {
151 tilemap_draw(bitmap,cliprect,background_layer,TILEMAP_IGNORE_TRANSPARENCY,0);
152 cabal_draw_sprites(bitmap,cliprect);
153 tilemap_draw(bitmap,cliprect,text_layer,0,0);
154 }
155
156
157