1 /*******************************************************************************
2
3 Momoko 120% (c) 1986 Jaleco
4
5 Video hardware driver by Uki
6
7 02/Mar/2001 -
8
9 *******************************************************************************/
10
11 #include "vidhrdw/generic.h"
12
13 data8_t *momoko_bg_scrollx;
14 data8_t *momoko_bg_scrolly;
15 data8_t momoko_fg_scrollx;
16 data8_t momoko_fg_scrolly;
17 data8_t momoko_fg_select;
18 data8_t momoko_text_scrolly;
19 data8_t momoko_text_mode;
20 data8_t momoko_bg_select;
21 data8_t momoko_bg_priority;
22 data8_t momoko_bg_mask;
23 data8_t momoko_fg_mask;
24 data8_t momoko_flipscreen;
25
26 /****************************************************************************/
27
WRITE_HANDLER(momoko_fg_scrollx_w)28 WRITE_HANDLER ( momoko_fg_scrollx_w )
29 {
30 momoko_fg_scrollx = data;
31 }
WRITE_HANDLER(momoko_fg_scrolly_w)32 WRITE_HANDLER ( momoko_fg_scrolly_w )
33 {
34 momoko_fg_scrolly = data;
35 }
WRITE_HANDLER(momoko_fg_select_w)36 WRITE_HANDLER ( momoko_fg_select_w )
37 {
38 momoko_fg_select = data & 0x0f;
39 momoko_fg_mask = data & 0x10;
40 }
WRITE_HANDLER(momoko_text_scrolly_w)41 WRITE_HANDLER ( momoko_text_scrolly_w )
42 {
43 momoko_text_scrolly = data;
44 }
WRITE_HANDLER(momoko_text_mode_w)45 WRITE_HANDLER ( momoko_text_mode_w )
46 {
47 momoko_text_mode = data;
48 }
WRITE_HANDLER(momoko_bg_scrollx_w)49 WRITE_HANDLER ( momoko_bg_scrollx_w )
50 {
51 momoko_bg_scrollx[ offset ] = data;
52 }
WRITE_HANDLER(momoko_bg_scrolly_w)53 WRITE_HANDLER ( momoko_bg_scrolly_w )
54 {
55 momoko_bg_scrolly[ offset ] = data;
56 }
WRITE_HANDLER(momoko_bg_select_w)57 WRITE_HANDLER( momoko_bg_select_w )
58 {
59 momoko_bg_select = data & 0x0f;
60 momoko_bg_mask = data & 0x10;
61 }
WRITE_HANDLER(momoko_bg_priority_w)62 WRITE_HANDLER( momoko_bg_priority_w )
63 {
64 momoko_bg_priority = data & 0x01;
65 }
WRITE_HANDLER(momoko_flipscreen_w)66 WRITE_HANDLER( momoko_flipscreen_w )
67 {
68 momoko_flipscreen = data & 0x01;
69 }
70 /****************************************************************************/
71
momoko_draw_bg_pri(struct mame_bitmap * bitmap,int chr,int col,int flipx,int flipy,int x,int y,int pri)72 void momoko_draw_bg_pri(struct mame_bitmap *bitmap, int chr, int col, int flipx, int flipy, int x,int y, int pri)
73 {
74 int xx,sx,sy,px,py,dot;
75 data32_t gfxadr;
76 data8_t d0, d1;
77 data8_t *BG_GFX = memory_region( REGION_GFX2 );
78 for (sy=0; sy<8; sy++)
79 {
80 gfxadr = chr*16 + sy*2;
81 for (xx=0; xx<2; xx++)
82 {
83 d0 = BG_GFX[gfxadr + xx*4096];
84 d1 = BG_GFX[gfxadr + xx*4096+1];
85 for (sx=0; sx<4; sx++)
86 {
87 dot = (d0 & 0x08) | ((d0 & 0x80) >>5) | ((d1 & 0x08) >>2) | ((d1 & 0x80) >>7);
88 if (flipx==0) px=sx+xx*4 + x;
89 else px=7-sx-xx*4 + x;
90 if (flipy==0) py=sy + y;
91 else py=7-sy + y;
92
93 if (dot>=pri)
94 plot_pixel(bitmap, px, py, Machine->pens[col*16+dot+256]);
95 d0 = d0 << 1;
96 d1 = d1 << 1;
97 }
98 }
99 }
100 }
101
102 /****************************************************************************/
103
VIDEO_UPDATE(momoko)104 VIDEO_UPDATE( momoko )
105 {
106 int x, y, dx, dy, rx, ry, radr, chr, sy, fx, fy, px, py, offs, col, pri, flip ;
107
108 data8_t *BG_MAP = memory_region( REGION_USER1 );
109 data8_t *BG_COL_MAP = memory_region( REGION_USER2 );
110 data8_t *FG_MAP = memory_region( REGION_USER3 );
111 data8_t *TEXT_COLOR = memory_region( REGION_PROMS );
112
113
114 flip = momoko_flipscreen ^ (readinputport(4) & 0x01);
115
116 /* draw BG layer */
117
118 dx = ( 7 - momoko_bg_scrollx[0] ) & 7 ;
119 dy = ( 7 - momoko_bg_scrolly[0] ) & 7 ;
120 rx = (momoko_bg_scrollx[0] + momoko_bg_scrollx[1]*256) >> 3 ;
121 ry = (momoko_bg_scrolly[0] + momoko_bg_scrolly[1]*256) >> 3 ;
122
123 if (momoko_bg_mask == 0)
124 {
125 for (y=0; y<29; y++)
126 {
127 for (x=0; x<32; x++)
128 {
129 radr = ( (ry + y +2 ) & 0x3ff ) * 128 + ( (rx + x) & 0x7f ) ;
130 chr = BG_MAP[ radr ] ;
131 col = BG_COL_MAP[ chr+momoko_bg_select*512+momoko_bg_priority*256] & 0x0f;
132 chr = chr + momoko_bg_select * 512;
133
134 if (flip==0)
135 {
136 px = 8*x+dx-6;
137 py = 8*y+dy+9;
138 }
139 else
140 {
141 px = 248-(8*x+dx-8);
142 py = 248-(8*y+dy+9);
143 }
144
145 drawgfx(bitmap,Machine->gfx[1],
146 chr,
147 col,
148 flip,flip,
149 px,py,
150 &Machine->visible_area,TRANSPARENCY_NONE,0);
151 }
152 }
153 }
154 else
155 fillbitmap(bitmap, Machine->pens[256], 0);
156
157
158 /* draw sprites (momoko) */
159
160 for (offs=0; offs<9*4; offs +=4)
161 {
162 chr = spriteram[offs+1] | ((spriteram[offs+2]&0x60)<<3);
163 chr = ((chr & 0x380) << 1) | (chr & 0x7f);
164 col = spriteram[offs+2] & 0x07;
165 fx = ((spriteram[offs+2] & 0x10) >> 4) ^ flip;
166 fy = ((spriteram[offs+2] & 0x08) >> 3) ^ flip; /* ??? */
167 x = spriteram[offs+3];
168 y = spriteram[offs+0];
169 if (flip==0)
170 {
171 px = x;
172 py = 239-y;
173 }
174 else
175 {
176 px = 248-x;
177 py = y+1;
178 }
179
180 drawgfx(bitmap,Machine->gfx[3],
181 chr,
182 col,
183 !fx,fy,
184 px,py,
185 &Machine->visible_area,TRANSPARENCY_PEN,0);
186 }
187
188
189 /* draw BG layer */
190
191 if (momoko_bg_mask ==0)
192 {
193 for (y=0; y<29; y++)
194 {
195 for (x=0; x<32; x++)
196 {
197 radr = ( (ry + y +2 ) & 0x3ff ) * 128 + ( (rx + x) & 0x7f ) ;
198 chr = BG_MAP[ radr ] ;
199 col = BG_COL_MAP[ chr+momoko_bg_select*512+momoko_bg_priority*256 ];
200 pri = (col & 0x10) >> 1;
201
202 if (flip==0)
203 {
204 px = 8*x+dx-6;
205 py = 8*y+dy+9;
206 }
207 else
208 {
209 px = 248-(8*x+dx-8);
210 py = 248-(8*y+dy+9);
211 }
212 if (pri != 0)
213 {
214 col = col & 0x0f;
215 chr = chr + momoko_bg_select * 512;
216 momoko_draw_bg_pri(bitmap,chr,col,flip,flip,px,py,pri);
217 }
218 }
219 }
220 }
221
222
223 /* draw sprites (others) */
224
225 for (offs=9*4; offs<spriteram_size; offs +=4)
226 {
227 chr = spriteram[offs+1] | ((spriteram[offs+2]&0x60)<<3);
228 chr = ((chr & 0x380) << 1) | (chr & 0x7f);
229 col = spriteram[offs+2] & 0x07;
230 fx = ((spriteram[offs+2] & 0x10) >> 4) ^ flip;
231 fy = ((spriteram[offs+2] & 0x08) >> 3) ^ flip; /* ??? */
232 x = spriteram[offs+3];
233 y = spriteram[offs+0];
234 if (flip==0)
235 {
236 px = x;
237 py = 239-y;
238 }
239 else
240 {
241 px = 248-x;
242 py = y+1;
243 }
244 drawgfx(bitmap,Machine->gfx[3],
245 chr,
246 col,
247 !fx,fy,
248 px,py,
249 &Machine->visible_area,TRANSPARENCY_PEN,0);
250 }
251
252
253 /* draw text layer */
254
255 for (y=16; y<240; y++)
256 {
257 for (x=0; x<32; x++)
258 {
259 sy = y;
260 if (momoko_text_mode == 0)
261 col = TEXT_COLOR[ (sy >> 3) + 0x100 ] & 0x0f;
262 else
263 {
264 if (TEXT_COLOR[ y ] < 0x08)
265 sy += momoko_text_scrolly;
266 col = (TEXT_COLOR[ y ] & 0x07) + 0x10;
267 }
268 dy=sy & 7;
269 if (flip==0)
270 {
271 px = x*8;
272 py = y;
273 }
274 else
275 {
276 px = 248-x*8;
277 py = 255-y;
278 }
279 drawgfx(bitmap,Machine->gfx[0],
280 videoram[(sy>>3)*32+x]*8+dy,
281 col,
282 flip,0,
283 px,py,
284 &Machine->visible_area,TRANSPARENCY_PEN,0);
285 }
286 }
287
288
289 /* draw FG layer */
290
291 if (momoko_fg_mask==0)
292 {
293 dx = ( 7 - momoko_fg_scrollx ) & 7 ;
294 dy = ( 7 - momoko_fg_scrolly ) & 7 ;
295 rx = momoko_fg_scrollx >> 3 ;
296 ry = momoko_fg_scrolly >> 3 ;
297
298 for (y=0; y<29; y++)
299 {
300 for (x=0; x<32; x++)
301 {
302 radr = ((ry + y +34) & 0x3f) *0x20 + ((rx + x) & 0x1f) + (momoko_fg_select & 3) *0x800;
303 chr = FG_MAP[ radr ] ;
304 if (flip==0)
305 {
306 px = 8*x+dx-6;
307 py = 8*y+dy+9;
308 }
309 else
310 {
311 px = 248-(8*x+dx-8);
312 py = 248-(8*y+dy+9);
313 }
314 drawgfx(bitmap,Machine->gfx[2],
315 chr,
316 0, /* color */
317 flip,flip, /* flip */
318 px,py,
319 &Machine->visible_area,TRANSPARENCY_PEN,0);
320 }
321 }
322 }
323 }
324