Previous 15994 Revisions Next

r5698 Saturday 12th September, 2009 at 00:48:39 UTC by R. Belmont
[GBA] Greatly expanded video emulation [Harmony, R. Belmont]

- Support windowing
- Support color blending
- Fix ROZ BGs
- Support byte-smearing for bitmap BGs
- Better priorities
- Much, much more
[src/mess/drivers]gba.c
[src/mess/includes]gba.h
[src/mess/video]gba.c gbam345.c* gbamode0.c* gbamode1.c* gbamode2.c*

src/mess/video/gbamode0.c
r0r5698
1 /***************************************************************************
2
3  gbamode0.c
4
5  Handles GBA mode 0 screen rendering
6
7  By R. Belmont & Harmony
8
9***************************************************************************/
10
11void draw_mode0_scanline(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
12{
13   int x = 0;
14   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
15
16   draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS);
17   draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS);
18   draw_bg_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2HOFS, gba_state->BG2VOFS);
19   draw_bg_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3HOFS, gba_state->BG3VOFS);
20   draw_gba_oam(gba_state, machine, lineOBJ, y);
21
22   for(x = 0; x < 240; x++)
23   {
24      UINT32 color = backdrop;
25      UINT8 top = 0x20;
26
27      if(line0[x] < color)
28      {
29         color = line0[x];
30         top = 0x01;
31      }
32
33      if((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24))
34      {
35         color = line1[x];
36         top = 0x02;
37      }
38
39      if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24))
40      {
41         color = line2[x];
42         top = 0x04;
43      }
44
45      if((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24))
46      {
47         color = line3[x];
48         top = 0x08;
49      }
50
51      if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
52      {
53         color = lineOBJ[x];
54         top = 0x10;
55      }
56
57      if(top == 0x10 && (color & 0x00010000) != 0)
58      {
59         UINT32 back = backdrop;
60         UINT8 top2 = 0x20;
61
62         if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))
63         {
64            back = line0[x];
65            top2 = 0x01;
66         }
67
68         if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))
69         {
70            back = line1[x];
71            top2 = 0x02;
72         }
73
74         if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
75         {
76            back = line2[x];
77            top2 = 0x04;
78         }
79
80         if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))
81         {
82            back = line3[x];
83            top2 = 0x08;
84         }
85
86         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
87         {
88            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
89         }
90         else
91         {
92            switch(gba_state->BLDCNT & BLDCNT_SFX)
93            {
94               case BLDCNT_SFX_LIGHTEN:
95                  if(top & gba_state->BLDCNT)
96                  {
97                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
98                  }
99                  break;
100               case BLDCNT_SFX_DARKEN:
101                  if(top & gba_state->BLDCNT)
102                  {
103                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
104                  }
105                  break;
106            }
107         }
108      }
109
110      lineMix[x] = color;
111   }
112}
113
114void draw_mode0_scanline_nowindow(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
115{
116   int x = 0;
117   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
118   int effect = gba_state->BLDCNT & BLDCNT_SFX;
119
120   draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS);
121   draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS);
122   draw_bg_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2HOFS, gba_state->BG2VOFS);
123   draw_bg_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3HOFS, gba_state->BG3VOFS);
124   draw_gba_oam(gba_state, machine, lineOBJ, y);
125
126   for(x = 0; x < 240; x++)
127   {
128      UINT32 color = backdrop;
129      UINT8 top = 0x20;
130
131      if(line0[x] < color)
132      {
133         color = line0[x];
134         top = 0x01;
135      }
136
137      if(line1[x] < (color & 0xff000000))
138      {
139         color = line1[x];
140         top = 0x02;
141      }
142
143      if(line2[x] < (color & 0xff000000))
144      {
145         color = line2[x];
146         top = 0x04;
147      }
148
149      if(line3[x] < (color & 0xff000000))
150      {
151         color = line3[x];
152         top = 0x08;
153      }
154
155      if(lineOBJ[x] < (color & 0xff000000))
156      {
157         color = lineOBJ[x];
158         top = 0x10;
159      }
160
161      if((color & 0x00010000) == 0)
162      {
163         switch(effect)
164         {
165            case BLDCNT_SFX_NONE:
166               break;
167            case BLDCNT_SFX_ALPHA:
168               if(gba_state->BLDCNT & top)
169               {
170                  UINT32 back = backdrop;
171                  UINT8 top2 = 0x20;
172
173                  if(line0[x] < back)
174                  {
175                     if(top != 0x01)
176                     {
177                        back = line0[x];
178                        top2 = 0x01;
179                     }
180                  }
181
182                  if(line1[x] < (back & 0xff000000))
183                  {
184                     if(top != 0x02)
185                     {
186                        back = line1[x];
187                        top2 = 0x02;
188                     }
189                  }
190
191                  if(line2[x] < (back & 0xff000000))
192                  {
193                     if(top != 0x04)
194                     {
195                        back = line2[x];
196                        top2 = 0x04;
197                     }
198                  }
199
200                  if(line3[x] < (back & 0xff000000))
201                  {
202                     if(top != 0x08)
203                     {
204                        back = line3[x];
205                        top2 = 0x08;
206                     }
207                  }
208
209                  if(lineOBJ[x] < (back & 0xff000000))
210                  {
211                     if(top != 0x10)
212                     {
213                        back = lineOBJ[x];
214                        top2 = 0x10;
215                     }
216                  }
217
218                  if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
219                  {
220                     color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
221                  }
222               }
223               break;
224            case BLDCNT_SFX_LIGHTEN:
225               if(top & gba_state->BLDCNT)
226               {
227                  color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
228               }
229               break;
230            case BLDCNT_SFX_DARKEN:
231               if(top & gba_state->BLDCNT)
232               {
233                  color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
234               }
235               break;
236         }
237      }
238      else
239      {
240         UINT32 back = backdrop;
241         UINT8 top2 = 0x20;
242
243         if(line0[x] < back)
244         {
245            back = line0[x];
246            top2 = 0x01;
247         }
248
249         if(line1[x] < (back & 0xff000000))
250         {
251            back = line1[x];
252            top2 = 0x02;
253         }
254
255         if(line2[x] < (back & 0xff000000))
256         {
257            back = line2[x];
258            top2 = 0x04;
259         }
260
261         if(line3[x] < (back & 0xff000000))
262         {
263            back = line3[x];
264            top2 = 0x08;
265         }
266
267         if(lineOBJ[x] < (back & 0xff000000))
268         {
269            back = lineOBJ[x];
270            top2 = 0x10;
271         }
272
273         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
274         {
275            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
276         }
277         else
278         {
279            switch(gba_state->BLDCNT & BLDCNT_SFX)
280            {
281               case BLDCNT_SFX_LIGHTEN:
282                  if(top & gba_state->BLDCNT)
283                  {
284                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
285                  }
286                  break;
287               case BLDCNT_SFX_DARKEN:
288                  if(top & gba_state->BLDCNT)
289                  {
290                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
291                  }
292                  break;
293            }
294         }
295      }
296      lineMix[x] = color;
297   }
298}
299
300void draw_mode0_scanline_all(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
301{
302   int x = 0;
303   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
304   int inWindow0 = 0;
305   int inWindow1 = 0;
306   UINT8 inWin0Mask = gba_state->WININ & 0x00ff;
307   UINT8 inWin1Mask = gba_state->WININ >> 8;
308   UINT8 outMask = gba_state->WINOUT & 0x00ff;
309
310   if(gba_state->DISPCNT & DISPCNT_WIN0_EN)
311   {
312      UINT8 v0 = gba_state->WIN0V >> 8;
313      UINT8 v1 = gba_state->WIN0V & 0x00ff;
314      inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
315      if(v1 >= v0)
316      {
317         inWindow0 |= (y >= v0 && y < v1) ? 1 : 0;
318      }
319      else
320      {
321         inWindow0 |= (y >= v0 || y < v1) ? 1 : 0;
322      }
323   }
324
325   if(gba_state->DISPCNT & DISPCNT_WIN1_EN)
326   {
327      UINT8 v0 = gba_state->WIN1V >> 8;
328      UINT8 v1 = gba_state->WIN1V & 0x00ff;
329      inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
330      if(v1 >= v0)
331      {
332         inWindow1 |= (y >= v0 && y < v1) ? 1 : 0;
333      }
334      else
335      {
336         inWindow1 |= (y >= v0 || y < v1) ? 1 : 0;
337      }
338   }
339
340   draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS);
341   draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS);
342   draw_bg_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2HOFS, gba_state->BG2VOFS);
343   draw_bg_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3HOFS, gba_state->BG3VOFS);
344   draw_gba_oam(gba_state, machine, lineOBJ, y);
345   draw_gba_oam_window(gba_state, machine, lineOBJWin, y);
346
347   for(x = 0; x < 240; x++)
348   {
349      UINT32 color = backdrop;
350      UINT8 top = 0x20;
351      UINT8 mask = outMask;
352
353      if((lineOBJWin[x] & 0x80000000) == 0)
354      {
355         mask = gba_state->WINOUT >> 8;
356      }
357
358      if(inWindow1)
359      {
360         if(is_in_window(gba_state, x, 1))
361         {
362            mask = inWin1Mask;
363         }
364      }
365
366      if(inWindow0)
367      {
368         if(is_in_window(gba_state, x, 0))
369         {
370            mask = inWin0Mask;
371         }
372      }
373
374      if((mask & 0x01) != 0 && (line0[x] < color))
375      {
376         color = line0[x];
377         top = 0x01;
378      }
379
380      if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24)))
381      {
382         color = line1[x];
383         top = 0x02;
384      }
385
386      if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24)))
387      {
388         color = line2[x];
389         top = 0x04;
390      }
391
392      if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24)))
393      {
394         color = line3[x];
395         top = 0x08;
396      }
397
398      if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24)))
399      {
400         color = lineOBJ[x];
401         top = 0x10;
402      }
403
404      if((mask & 0x20) != 0)
405      {
406         if((color & 0x00010000) == 0)
407         {
408            switch(gba_state->BLDCNT & BLDCNT_SFX)
409            {
410               case BLDCNT_SFX_NONE:
411                  break;
412               case BLDCNT_SFX_ALPHA:
413               {
414                  if(top & gba_state->BLDCNT)
415                  {
416                     UINT32 back = backdrop;
417                     UINT8 top2 = 0x20;
418                     if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
419                     {
420                        if(top != 0x01)
421                        {
422                           back = line0[x];
423                           top2 = 0x01;
424                        }
425                     }
426
427                     if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
428                     {
429                        if(top != 0x02)
430                        {
431                           back = line1[x];
432                           top2 = 0x02;
433                        }
434                     }
435
436                     if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
437                     {
438                        if(top != 0x04)
439                        {
440                           back = line2[x];
441                           top2 = 0x04;
442                        }
443                     }
444
445                     if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
446                     {
447                        if(top != 0x08)
448                        {
449                           back = line3[x];
450                           top2 = 0x08;
451                        }
452                     }
453
454                     if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24)))
455                     {
456                        if(top != 0x10)
457                        {
458                           back = lineOBJ[x];
459                           top2 = 0x10;
460                        }
461                     }
462
463                     if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
464                     {
465                        color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
466                     }
467                  }
468                  break;
469               }
470               case BLDCNT_SFX_LIGHTEN:
471                  if(top & gba_state->BLDCNT)
472                  {
473                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
474                  }
475                  break;
476               case BLDCNT_SFX_DARKEN:
477                  if(top & gba_state->BLDCNT)
478                  {
479                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
480                  }
481                  break;
482            }
483         }
484         else
485         {
486            UINT32 back = backdrop;
487            UINT8 top2 = 0x20;
488
489            if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
490            {
491               back = line0[x];
492               top2 = 0x01;
493            }
494
495            if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
496            {
497               back = line1[x];
498               top2 = 0x02;
499            }
500
501            if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
502            {
503               back = line2[x];
504               top2 = 0x04;
505            }
506
507            if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
508            {
509               back = line3[x];
510               top2 = 0x08;
511            }
512
513            if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
514            {
515               color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
516            }
517            else
518            {
519               switch(gba_state->BLDCNT & BLDCNT_SFX)
520               {
521                  case BLDCNT_SFX_LIGHTEN:
522                     if(top & gba_state->BLDCNT)
523                     {
524                        color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
525                     }
526                     break;
527                  case BLDCNT_SFX_DARKEN:
528                     if(top & gba_state->BLDCNT)
529                     {
530                        color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
531                     }
532                     break;
533               }
534            }
535         }
536      }
537      else if(color & 0x00010000)
538      {
539         UINT32 back = backdrop;
540         UINT8 top2 = 0x20;
541
542         if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
543         {
544            back = line0[x];
545            top2 = 0x01;
546         }
547
548         if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
549         {
550            back = line1[x];
551            top2 = 0x02;
552         }
553
554         if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
555         {
556            back = line2[x];
557            top2 = 0x04;
558         }
559
560         if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
561         {
562            back = line3[x];
563            top2 = 0x08;
564         }
565
566         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
567         {
568            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
569         }
570         else
571         {
572            switch(gba_state->BLDCNT & BLDCNT_SFX)
573            {
574               case BLDCNT_SFX_LIGHTEN:
575                  if(top & gba_state->BLDCNT)
576                  {
577                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
578                  }
579                  break;
580               case BLDCNT_SFX_DARKEN:
581                  if(top & gba_state->BLDCNT)
582                  {
583                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
584                  }
585                  break;
586            }
587         }
588      }
589      lineMix[x] = color;
590   }
591}
src/mess/video/gbamode1.c
r0r5698
1 /***************************************************************************
2
3  gbamode1.c
4
5  Handles GBA mode 1 screen rendering
6
7  By R. Belmont & Harmony
8
9***************************************************************************/
10
11void draw_mode1_scanline(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
12{
13   int x = 0;
14   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
15
16   draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS);
17   draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS);
18   draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed);
19   draw_gba_oam(gba_state, machine, lineOBJ, y);
20
21   for(x = 0; x < 240; x++)
22   {
23      UINT32 color = backdrop;
24      UINT8 top = 0x20;
25
26      if(line0[x] < color)
27      {
28         color = line0[x];
29         top = 0x01;
30      }
31
32      if((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24))
33      {
34         color = line1[x];
35         top = 0x02;
36      }
37
38      if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24))
39      {
40         color = line2[x];
41         top = 0x04;
42      }
43
44      if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
45      {
46         color = lineOBJ[x];
47         top = 0x10;
48      }
49
50      if(top == 0x10 && (color & 0x00010000) != 0)
51      {
52         UINT32 back = backdrop;
53         UINT8 top2 = 0x20;
54
55         if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))
56         {
57            back = line0[x];
58            top2 = 0x01;
59         }
60
61         if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))
62         {
63            back = line1[x];
64            top2 = 0x02;
65         }
66
67         if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
68         {
69            back = line2[x];
70            top2 = 0x04;
71         }
72
73         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
74         {
75            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
76         }
77         else
78         {
79            switch(gba_state->BLDCNT & BLDCNT_SFX)
80            {
81               case BLDCNT_SFX_LIGHTEN:
82                  if(top & gba_state->BLDCNT)
83                  {
84                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
85                  }
86                  break;
87               case BLDCNT_SFX_DARKEN:
88                  if(top & gba_state->BLDCNT)
89                  {
90                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
91                  }
92                  break;
93            }
94         }
95      }
96
97      lineMix[x] = color;
98   }
99   gba_state->gfxBG2Changed = 0;
100}
101
102void draw_mode1_scanline_nowindow(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
103{
104   int x = 0;
105   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
106   int effect = gba_state->BLDCNT & BLDCNT_SFX;
107
108   draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS);
109   draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS);
110   draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed);
111   draw_gba_oam(gba_state, machine, lineOBJ, y);
112
113   for(x = 0; x < 240; x++)
114   {
115      UINT32 color = backdrop;
116      UINT8 top = 0x20;
117
118      if(line0[x] < color)
119      {
120         color = line0[x];
121         top = 0x01;
122      }
123
124      if(line1[x] < (color & 0xff000000))
125      {
126         color = line1[x];
127         top = 0x02;
128      }
129
130      if(line2[x] < (color & 0xff000000))
131      {
132         color = line2[x];
133         top = 0x04;
134      }
135
136      if(lineOBJ[x] < (color & 0xff000000))
137      {
138         color = lineOBJ[x];
139         top = 0x10;
140      }
141
142      if((color & 0x00010000) == 0)
143      {
144         switch(effect)
145         {
146            case BLDCNT_SFX_NONE:
147               break;
148            case BLDCNT_SFX_ALPHA:
149               if(gba_state->BLDCNT & top)
150               {
151                  UINT32 back = backdrop;
152                  UINT8 top2 = 0x20;
153
154                  if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))
155                  {
156                     if(top != 0x01)
157                     {
158                        back = line0[x];
159                        top2 = 0x01;
160                     }
161                  }
162
163                  if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))
164                  {
165                     if(top != 0x02)
166                     {
167                        back = line1[x];
168                        top2 = 0x02;
169                     }
170                  }
171
172                  if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
173                  {
174                     if(top != 0x04)
175                     {
176                        back = line2[x];
177                        top2 = 0x04;
178                     }
179                  }
180
181                  if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24))
182                  {
183                     if(top != 0x10)
184                     {
185                        back = lineOBJ[x];
186                        top2 = 0x10;
187                     }
188                  }
189
190                  if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
191                  {
192                     color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
193                  }
194               }
195               break;
196            case BLDCNT_SFX_LIGHTEN:
197               if(top & gba_state->BLDCNT)
198               {
199                  color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
200               }
201               break;
202            case BLDCNT_SFX_DARKEN:
203               if(top & gba_state->BLDCNT)
204               {
205                  color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
206               }
207               break;
208         }
209      }
210      else
211      {
212         UINT32 back = backdrop;
213         UINT8 top2 = 0x20;
214
215         if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))
216         {
217            back = line0[x];
218            top2 = 0x01;
219         }
220
221         if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))
222         {
223            back = line1[x];
224            top2 = 0x02;
225         }
226
227         if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
228         {
229            back = line2[x];
230            top2 = 0x04;
231         }
232
233         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
234         {
235            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
236         }
237         else
238         {
239            switch(gba_state->BLDCNT & BLDCNT_SFX)
240            {
241               case BLDCNT_SFX_LIGHTEN:
242                  if(top & gba_state->BLDCNT)
243                  {
244                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
245                  }
246                  break;
247               case BLDCNT_SFX_DARKEN:
248                  if(top & gba_state->BLDCNT)
249                  {
250                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
251                  }
252                  break;
253            }
254         }
255      }
256      lineMix[x] = color;
257   }
258   gba_state->gfxBG2Changed = 0;
259}
260
261void draw_mode1_scanline_all(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
262{
263   int x = 0;
264   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
265   int inWindow0 = 0;
266   int inWindow1 = 0;
267   UINT8 inWin0Mask = gba_state->WININ & 0x00ff;
268   UINT8 inWin1Mask = gba_state->WININ >> 8;
269   UINT8 outMask = gba_state->WINOUT & 0x00ff;
270
271   if(gba_state->DISPCNT & DISPCNT_WIN0_EN)
272   {
273      UINT8 v0 = gba_state->WIN0V >> 8;
274      UINT8 v1 = gba_state->WIN0V & 0x00ff;
275      inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
276      if(v1 >= v0)
277      {
278         inWindow0 |= (y >= v0 && y < v1) ? 1 : 0;
279      }
280      else
281      {
282         inWindow0 |= (y >= v0 || y < v1) ? 1 : 0;
283      }
284   }
285
286   if(gba_state->DISPCNT & DISPCNT_WIN1_EN)
287   {
288      UINT8 v0 = gba_state->WIN1V >> 8;
289      UINT8 v1 = gba_state->WIN1V & 0x00ff;
290      inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
291      if(v1 >= v0)
292      {
293         inWindow1 |= (y >= v0 && y < v1) ? 1 : 0;
294      }
295      else
296      {
297         inWindow1 |= (y >= v0 || y < v1) ? 1 : 0;
298      }
299   }
300
301   draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS);
302   draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS);
303   draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed);
304   draw_gba_oam(gba_state, machine, lineOBJ, y);
305   draw_gba_oam_window(gba_state, machine, lineOBJWin, y);
306
307   for(x = 0; x < 240; x++)
308   {
309      UINT32 color = backdrop;
310      UINT8 top = 0x20;
311      UINT8 mask = outMask;
312
313      if((lineOBJWin[x] & 0x80000000) == 0)
314      {
315         mask = gba_state->WINOUT >> 8;
316      }
317
318      if(inWindow1)
319      {
320         if(is_in_window(gba_state, x, 1))
321         {
322            mask = inWin1Mask;
323         }
324      }
325
326      if(inWindow0)
327      {
328         if(is_in_window(gba_state, x, 0))
329         {
330            mask = inWin0Mask;
331         }
332      }
333
334      if((mask & 0x01) != 0 && (line0[x] < color))
335      {
336         color = line0[x];
337         top = 0x01;
338      }
339
340      if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24)))
341      {
342         color = line1[x];
343         top = 0x02;
344      }
345
346      if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24)))
347      {
348         color = line2[x];
349         top = 0x04;
350      }
351
352      if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24)))
353      {
354         color = lineOBJ[x];
355         top = 0x10;
356      }
357
358      if((mask & 0x20) != 0)
359      {
360         if((color & 0x00010000) == 0)
361         {
362            switch(gba_state->BLDCNT & BLDCNT_SFX)
363            {
364               case BLDCNT_SFX_NONE:
365                  break;
366               case BLDCNT_SFX_ALPHA:
367               {
368                  if(top & gba_state->BLDCNT)
369                  {
370                     UINT32 back = backdrop;
371                     UINT8 top2 = 0x20;
372                     if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
373                     {
374                        if(top != 0x01)
375                        {
376                           back = line0[x];
377                           top2 = 0x01;
378                        }
379                     }
380
381                     if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
382                     {
383                        if(top != 0x02)
384                        {
385                           back = line1[x];
386                           top2 = 0x02;
387                        }
388                     }
389
390                     if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
391                     {
392                        if(top != 0x04)
393                        {
394                           back = line2[x];
395                           top2 = 0x04;
396                        }
397                     }
398
399                     if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24)))
400                     {
401                        if(top != 0x10)
402                        {
403                           back = lineOBJ[x];
404                           top2 = 0x10;
405                        }
406                     }
407
408                     if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
409                     {
410                        color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
411                     }
412                  }
413                  break;
414               }
415               case BLDCNT_SFX_LIGHTEN:
416                  if(top & gba_state->BLDCNT)
417                  {
418                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
419                  }
420                  break;
421               case BLDCNT_SFX_DARKEN:
422                  if(top & gba_state->BLDCNT)
423                  {
424                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
425                  }
426                  break;
427            }
428         }
429         else
430         {
431            UINT32 back = backdrop;
432            UINT8 top2 = 0x20;
433
434            if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
435            {
436               back = line0[x];
437               top2 = 0x01;
438            }
439
440            if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
441            {
442               back = line1[x];
443               top2 = 0x02;
444            }
445
446            if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
447            {
448               back = line2[x];
449               top2 = 0x04;
450            }
451
452            if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
453            {
454               color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
455            }
456            else
457            {
458               switch(gba_state->BLDCNT & BLDCNT_SFX)
459               {
460                  case BLDCNT_SFX_LIGHTEN:
461                     if(top & gba_state->BLDCNT)
462                     {
463                        color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
464                     }
465                     break;
466                  case BLDCNT_SFX_DARKEN:
467                     if(top & gba_state->BLDCNT)
468                     {
469                        color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
470                     }
471                     break;
472               }
473            }
474         }
475      }
476      else if(color & 0x00010000)
477      {
478         UINT32 back = backdrop;
479         UINT8 top2 = 0x20;
480
481         if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
482         {
483            back = line0[x];
484            top2 = 0x01;
485         }
486
487         if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
488         {
489            back = line1[x];
490            top2 = 0x02;
491         }
492
493         if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
494         {
495            back = line2[x];
496            top2 = 0x04;
497         }
498
499         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
500         {
501            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
502         }
503         else
504         {
505            switch(gba_state->BLDCNT & BLDCNT_SFX)
506            {
507               case BLDCNT_SFX_LIGHTEN:
508                  if(top & gba_state->BLDCNT)
509                  {
510                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
511                  }
512                  break;
513               case BLDCNT_SFX_DARKEN:
514                  if(top & gba_state->BLDCNT)
515                  {
516                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
517                  }
518                  break;
519            }
520         }
521      }
522      lineMix[x] = color;
523   }
524   gba_state->gfxBG2Changed = 0;
525}
src/mess/video/gbam345.c
r0r5698
1 /***************************************************************************
2
3  gbam345.c
4
5  Handles GBA rendering for modes 3, 4, and 5.
6
7  By R. Belmont & Harmony
8
9***************************************************************************/
10
11void draw_roz_bitmap_mode_scanline(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
12{
13   int x = 0;
14   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
15
16   if(bpp == 4)
17   {
18      fatalerror("Screen mode 5 is not fully supported yet, contact MESSdev!\n" );
19   }
20
21   draw_roz_bitmap_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed, bpp);
22   draw_gba_oam(gba_state, machine, lineOBJ, y);
23
24   for(x = 0; x < 240; x++)
25   {
26      UINT32 color = backdrop;
27      UINT8 top = 0x20;
28
29      if(line2[x] < color)
30      {
31         color = line2[x];
32         top = 0x04;
33      }
34
35      if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
36      {
37         color = lineOBJ[x];
38         top = 0x10;
39      }
40
41      if(top == 0x10 && (color & 0x00010000) != 0)
42      {
43         UINT32 back = backdrop;
44         UINT8 top2 = 0x20;
45
46         if(line2[x] < back)
47         {
48            back = line2[x];
49            top2 = 0x04;
50         }
51
52         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
53         {
54            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
55         }
56         else
57         {
58            switch(gba_state->BLDCNT & BLDCNT_SFX)
59            {
60               case BLDCNT_SFX_LIGHTEN:
61                  if(top & gba_state->BLDCNT)
62                  {
63                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
64                  }
65                  break;
66               case BLDCNT_SFX_DARKEN:
67                  if(top & gba_state->BLDCNT)
68                  {
69                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
70                  }
71                  break;
72            }
73         }
74      }
75
76      lineMix[x] = color;
77   }
78   gba_state->gfxBG2Changed = 0;
79}
80
81void draw_roz_bitmap_mode_scanline_nowindow(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
82{
83   int x = 0;
84   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
85   int effect = gba_state->BLDCNT & BLDCNT_SFX;
86
87   if(bpp == 4)
88   {
89      fatalerror( "Screen mode 5 is not fully supported yet, contact MESSdev!\n" );
90   }
91
92   draw_roz_bitmap_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed, bpp);
93   draw_gba_oam(gba_state, machine, lineOBJ, y);
94
95   for(x = 0; x < 240; x++)
96   {
97      UINT32 color = backdrop;
98      UINT8 top = 0x20;
99
100      if(line2[x] < color)
101      {
102         color = line2[x];
103         top = 0x04;
104      }
105
106      if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
107      {
108         color = lineOBJ[x];
109         top = 0x10;
110      }
111
112      if((color & 0x00010000) == 0)
113      {
114         switch(effect)
115         {
116            case BLDCNT_SFX_NONE:
117               break;
118            case BLDCNT_SFX_ALPHA:
119               if(gba_state->BLDCNT & top)
120               {
121                  UINT32 back = backdrop;
122                  UINT8 top2 = 0x20;
123
124                  if(line2[x] < back)
125                  {
126                     if(top != 0x04)
127                     {
128                        back = line2[x];
129                        top2 = 0x04;
130                     }
131                  }
132
133                  if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24))
134                  {
135                     if(top != 0x10)
136                     {
137                        back = lineOBJ[x];
138                        top2 = 0x10;
139                     }
140                  }
141
142                  if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
143                  {
144                     color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
145                  }
146               }
147               break;
148            case BLDCNT_SFX_LIGHTEN:
149               if(top & gba_state->BLDCNT)
150               {
151                  color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
152               }
153               break;
154            case BLDCNT_SFX_DARKEN:
155               if(top & gba_state->BLDCNT)
156               {
157                  color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
158               }
159               break;
160         }
161      }
162      else
163      {
164         UINT32 back = backdrop;
165         UINT8 top2 = 0x20;
166
167         if(line2[x] < back)
168         {
169            back = line2[x];
170            top2 = 0x04;
171         }
172
173         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
174         {
175            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
176         }
177         else
178         {
179            switch(gba_state->BLDCNT & BLDCNT_SFX)
180            {
181               case BLDCNT_SFX_LIGHTEN:
182                  if(top & gba_state->BLDCNT)
183                  {
184                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
185                  }
186                  break;
187               case BLDCNT_SFX_DARKEN:
188                  if(top & gba_state->BLDCNT)
189                  {
190                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
191                  }
192                  break;
193            }
194         }
195      }
196      lineMix[x] = color;
197   }
198   gba_state->gfxBG2Changed = 0;
199}
200
201void draw_roz_bitmap_mode_scanline_all(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
202{
203   int x = 0;
204   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
205   int inWindow0 = 0;
206   int inWindow1 = 0;
207   UINT8 inWin0Mask = gba_state->WININ & 0x00ff;
208   UINT8 inWin1Mask = gba_state->WININ >> 8;
209   UINT8 outMask = gba_state->WINOUT & 0x00ff;
210
211   if(bpp == 4)
212   {
213      fatalerror( "Screen mode 5 is not fully supported yet, contact MESSdev!\n" );
214   }
215
216   if(gba_state->DISPCNT & DISPCNT_WIN0_EN)
217   {
218      UINT8 v0 = gba_state->WIN0V >> 8;
219      UINT8 v1 = gba_state->WIN0V & 0x00ff;
220      inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
221      if(v1 >= v0)
222      {
223         inWindow0 |= (y >= v0 && y < v1) ? 1 : 0;
224      }
225      else
226      {
227         inWindow0 |= (y >= v0 || y < v1) ? 1 : 0;
228      }
229   }
230
231   if(gba_state->DISPCNT & DISPCNT_WIN1_EN)
232   {
233      UINT8 v0 = gba_state->WIN1V >> 8;
234      UINT8 v1 = gba_state->WIN1V & 0x00ff;
235      inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
236      if(v1 >= v0)
237      {
238         inWindow1 |= (y >= v0 && y < v1) ? 1 : 0;
239      }
240      else
241      {
242         inWindow1 |= (y >= v0 || y < v1) ? 1 : 0;
243      }
244   }
245
246   draw_roz_bitmap_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed, bpp);
247   draw_gba_oam(gba_state, machine, lineOBJ, y);
248   draw_gba_oam_window(gba_state, machine, lineOBJWin, y);
249
250   for(x = 0; x < 240; x++)
251   {
252      UINT32 color = backdrop;
253      UINT8 top = 0x20;
254      UINT8 mask = outMask;
255
256      if((lineOBJWin[x] & 0x80000000) == 0)
257      {
258         mask = gba_state->WINOUT >> 8;
259      }
260
261      if(inWindow1)
262      {
263         if(is_in_window(gba_state, x, 1))
264         {
265            mask = inWin1Mask;
266         }
267      }
268
269      if(inWindow0)
270      {
271         if(is_in_window(gba_state, x, 0))
272         {
273            mask = inWin0Mask;
274         }
275      }
276
277      if((mask & 0x04) != 0 && (line2[x] < color))
278      {
279         color = line2[x];
280         top = 0x04;
281      }
282
283      if((mask & 0x10) != 0 && (UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
284      {
285         color = lineOBJ[x];
286         top = 0x10;
287      }
288
289      if((mask & 0x20) != 0)
290      {
291         if((color & 0x00010000) == 0)
292         {
293            switch(gba_state->BLDCNT & BLDCNT_SFX)
294            {
295               case BLDCNT_SFX_NONE:
296                  break;
297               case BLDCNT_SFX_ALPHA:
298               {
299                  if(top & gba_state->BLDCNT)
300                  {
301                     UINT32 back = backdrop;
302                     UINT8 top2 = 0x20;
303                     if((mask & 0x04) != 0 && (line2[x] < back))
304                     {
305                        if(top != 0x04)
306                        {
307                           back = line2[x];
308                           top2 = 0x04;
309                        }
310                     }
311
312                     if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24)))
313                     {
314                        if(top != 0x10)
315                        {
316                           back = lineOBJ[x];
317                           top2 = 0x10;
318                        }
319                     }
320
321                     if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
322                     {
323                        color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
324                     }
325                  }
326                  break;
327               }
328               case BLDCNT_SFX_LIGHTEN:
329                  if(top & gba_state->BLDCNT)
330                  {
331                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
332                  }
333                  break;
334               case BLDCNT_SFX_DARKEN:
335                  if(top & gba_state->BLDCNT)
336                  {
337                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
338                  }
339                  break;
340            }
341         }
342         else
343         {
344            UINT32 back = backdrop;
345            UINT8 top2 = 0x20;
346
347            if((mask & 0x04) != 0 && (line2[x] < back))
348            {
349               back = line2[x];
350               top2 = 0x04;
351            }
352
353            if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
354            {
355               color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
356            }
357            else
358            {
359               switch(gba_state->BLDCNT & BLDCNT_SFX)
360               {
361                  case BLDCNT_SFX_LIGHTEN:
362                     if(top & gba_state->BLDCNT)
363                     {
364                        color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
365                     }
366                     break;
367                  case BLDCNT_SFX_DARKEN:
368                     if(top & gba_state->BLDCNT)
369                     {
370                        color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
371                     }
372                     break;
373               }
374            }
375         }
376      }
377      else if(color & 0x00010000)
378      {
379         UINT32 back = backdrop;
380         UINT8 top2 = 0x20;
381
382         if((mask & 0x04) != 0 && (line2[x] < back))
383         {
384            back = line2[x];
385            top2 = 0x04;
386         }
387
388         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
389         {
390            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
391         }
392         else
393         {
394            switch(gba_state->BLDCNT & BLDCNT_SFX)
395            {
396               case BLDCNT_SFX_LIGHTEN:
397                  if(top & gba_state->BLDCNT)
398                  {
399                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
400                  }
401                  break;
402               case BLDCNT_SFX_DARKEN:
403                  if(top & gba_state->BLDCNT)
404                  {
405                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
406                  }
407                  break;
408            }
409         }
410      }
411      lineMix[x] = color;
412   }
413   gba_state->gfxBG2Changed = 0;
414}
src/mess/video/gbamode2.c
r0r5698
1 /***************************************************************************
2
3  gbamode2.c
4
5  Handles GBA mode 2 screen rendering
6
7  By R. Belmont & Harmony
8
9***************************************************************************/
10
11void draw_mode2_scanline(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
12{
13   int x = 0;
14   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
15
16   draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed);
17   draw_roz_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3X, gba_state->BG3Y, gba_state->BG3PA, gba_state->BG3PB, gba_state->BG3PC, gba_state->BG3PD, &gba_state->gfxBG3X, &gba_state->gfxBG3Y, gba_state->gfxBG3Changed);
18   draw_gba_oam(gba_state, machine, lineOBJ, y);
19
20   for(x = 0; x < 240; x++)
21   {
22      UINT32 color = backdrop;
23      UINT8 top = 0x20;
24
25      if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24))
26      {
27         color = line2[x];
28         top = 0x04;
29      }
30
31      if((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24))
32      {
33         color = line3[x];
34         top = 0x08;
35      }
36
37      if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
38      {
39         color = lineOBJ[x];
40         top = 0x10;
41      }
42
43      if(top == 0x10 && (color & 0x00010000) != 0)
44      {
45         UINT32 back = backdrop;
46         UINT8 top2 = 0x20;
47
48         if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
49         {
50            back = line2[x];
51            top2 = 0x04;
52         }
53
54         if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))
55         {
56            back = line3[x];
57            top2 = 0x08;
58         }
59
60         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
61         {
62            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
63         }
64         else
65         {
66            switch(gba_state->BLDCNT & BLDCNT_SFX)
67            {
68               case BLDCNT_SFX_LIGHTEN:
69                  if(top & gba_state->BLDCNT)
70                  {
71                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
72                  }
73                  break;
74               case BLDCNT_SFX_DARKEN:
75                  if(top & gba_state->BLDCNT)
76                  {
77                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
78                  }
79                  break;
80            }
81         }
82      }
83
84      lineMix[x] = color;
85   }
86   gba_state->gfxBG2Changed = 0;
87   gba_state->gfxBG3Changed = 0;
88}
89
90void draw_mode2_scanline_nowindow(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
91{
92   int x = 0;
93   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
94   int effect = gba_state->BLDCNT & BLDCNT_SFX;
95
96   draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed);
97   draw_roz_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3X, gba_state->BG3Y, gba_state->BG3PA, gba_state->BG3PB, gba_state->BG3PC, gba_state->BG3PD, &gba_state->gfxBG3X, &gba_state->gfxBG3Y, gba_state->gfxBG3Changed);
98   draw_gba_oam(gba_state, machine, lineOBJ, y);
99
100   for(x = 0; x < 240; x++)
101   {
102      UINT32 color = backdrop;
103      UINT8 top = 0x20;
104
105      if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24))
106      {
107         color = line2[x];
108         top = 0x04;
109      }
110
111      if((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24))
112      {
113         color = line3[x];
114         top = 0x08;
115      }
116
117      if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
118      {
119         color = lineOBJ[x];
120         top = 0x10;
121      }
122
123      if((color & 0x00010000) == 0)
124      {
125         switch(effect)
126         {
127            case BLDCNT_SFX_NONE:
128               break;
129            case BLDCNT_SFX_ALPHA:
130               if(gba_state->BLDCNT & top)
131               {
132                  UINT32 back = backdrop;
133                  UINT8 top2 = 0x20;
134
135                  if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
136                  {
137                     if(top != 0x04)
138                     {
139                        back = line2[x];
140                        top2 = 0x04;
141                     }
142                  }
143
144                  if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))
145                  {
146                     if(top != 0x08)
147                     {
148                        back = line3[x];
149                        top2 = 0x08;
150                     }
151                  }
152
153                  if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24))
154                  {
155                     if(top != 0x10)
156                     {
157                        back = lineOBJ[x];
158                        top2 = 0x10;
159                     }
160                  }
161
162                  if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
163                  {
164                     color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
165                  }
166               }
167               break;
168            case BLDCNT_SFX_LIGHTEN:
169               if(top & gba_state->BLDCNT)
170               {
171                  color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
172               }
173               break;
174            case BLDCNT_SFX_DARKEN:
175               if(top & gba_state->BLDCNT)
176               {
177                  color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
178               }
179               break;
180         }
181      }
182      else
183      {
184         UINT32 back = backdrop;
185         UINT8 top2 = 0x20;
186
187         if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
188         {
189            back = line2[x];
190            top2 = 0x04;
191         }
192
193         if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))
194         {
195            back = line3[x];
196            top2 = 0x08;
197         }
198
199         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
200         {
201            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
202         }
203         else
204         {
205            switch(gba_state->BLDCNT & BLDCNT_SFX)
206            {
207               case BLDCNT_SFX_LIGHTEN:
208                  if(top & gba_state->BLDCNT)
209                  {
210                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
211                  }
212                  break;
213               case BLDCNT_SFX_DARKEN:
214                  if(top & gba_state->BLDCNT)
215                  {
216                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
217                  }
218                  break;
219            }
220         }
221      }
222      lineMix[x] = color;
223   }
224   gba_state->gfxBG2Changed = 0;
225   gba_state->gfxBG3Changed = 0;
226}
227
228void draw_mode2_scanline_all(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
229{
230   int x = 0;
231   UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000;
232   int inWindow0 = 0;
233   int inWindow1 = 0;
234   UINT8 inWin0Mask = gba_state->WININ & 0x00ff;
235   UINT8 inWin1Mask = gba_state->WININ >> 8;
236   UINT8 outMask = gba_state->WINOUT & 0x00ff;
237
238   if(gba_state->DISPCNT & DISPCNT_WIN0_EN)
239   {
240      UINT8 v0 = gba_state->WIN0V >> 8;
241      UINT8 v1 = gba_state->WIN0V & 0x00ff;
242      inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
243      if(v1 >= v0)
244      {
245         inWindow0 |= (y >= v0 && y < v1) ? 1 : 0;
246      }
247      else
248      {
249         inWindow0 |= (y >= v0 || y < v1) ? 1 : 0;
250      }
251   }
252
253   if(gba_state->DISPCNT & DISPCNT_WIN1_EN)
254   {
255      UINT8 v0 = gba_state->WIN1V >> 8;
256      UINT8 v1 = gba_state->WIN1V & 0x00ff;
257      inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
258      if(v1 >= v0)
259      {
260         inWindow1 |= (y >= v0 && y < v1) ? 1 : 0;
261      }
262      else
263      {
264         inWindow1 |= (y >= v0 || y < v1) ? 1 : 0;
265      }
266   }
267
268   draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed);
269   draw_roz_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3X, gba_state->BG3Y, gba_state->BG3PA, gba_state->BG3PB, gba_state->BG3PC, gba_state->BG3PD, &gba_state->gfxBG3X, &gba_state->gfxBG3Y, gba_state->gfxBG3Changed);
270   draw_gba_oam(gba_state, machine, lineOBJ, y);
271   draw_gba_oam_window(gba_state, machine, lineOBJWin, y);
272
273   for(x = 0; x < 240; x++)
274   {
275      UINT32 color = backdrop;
276      UINT8 top = 0x20;
277      UINT8 mask = outMask;
278
279      if((lineOBJWin[x] & 0x80000000) == 0)
280      {
281         mask = gba_state->WINOUT >> 8;
282      }
283
284      if(inWindow1)
285      {
286         if(is_in_window(gba_state, x, 1))
287         {
288            mask = inWin1Mask;
289         }
290      }
291
292      if(inWindow0)
293      {
294         if(is_in_window(gba_state, x, 0))
295         {
296            mask = inWin0Mask;
297         }
298      }
299
300      if((mask & 0x04) != 0 && (line2[x] < color))
301      {
302         color = line2[x];
303         top = 0x04;
304      }
305
306      if((mask & 0x08) != 0 && (UINT8)(line3[x] >> 24) < (UINT8)(color >> 24))
307      {
308         color = line3[x];
309         top = 0x08;
310      }
311
312      if((mask & 0x10) != 0 && (UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
313      {
314         color = lineOBJ[x];
315         top = 0x10;
316      }
317
318      if((mask & 0x20) != 0)
319      {
320         if((color & 0x00010000) == 0)
321         {
322            switch(gba_state->BLDCNT & BLDCNT_SFX)
323            {
324               case BLDCNT_SFX_NONE:
325                  break;
326               case BLDCNT_SFX_ALPHA:
327               {
328                  if(top & gba_state->BLDCNT)
329                  {
330                     UINT32 back = backdrop;
331                     UINT8 top2 = 0x20;
332                     if((mask & 0x04) != 0 && (line2[x] < back))
333                     {
334                        if(top != 0x04)
335                        {
336                           back = line2[x];
337                           top2 = 0x04;
338                        }
339                     }
340
341                     if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
342                     {
343                        if(top != 0x08)
344                        {
345                           back = line3[x];
346                           top2 = 0x08;
347                        }
348                     }
349
350                     if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24)))
351                     {
352                        if(top != 0x10)
353                        {
354                           back = lineOBJ[x];
355                           top2 = 0x10;
356                        }
357                     }
358
359                     if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
360                     {
361                        color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
362                     }
363                  }
364                  break;
365               }
366               case BLDCNT_SFX_LIGHTEN:
367                  if(top & gba_state->BLDCNT)
368                  {
369                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
370                  }
371                  break;
372               case BLDCNT_SFX_DARKEN:
373                  if(top & gba_state->BLDCNT)
374                  {
375                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
376                  }
377                  break;
378            }
379         }
380         else
381         {
382            UINT32 back = backdrop;
383            UINT8 top2 = 0x20;
384
385            if((mask & 0x04) != 0 && (line2[x] < back))
386            {
387               back = line2[x];
388               top2 = 0x04;
389            }
390
391            if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
392            {
393               back = line3[x];
394               top2 = 0x08;
395            }
396
397            if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
398            {
399               color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
400            }
401            else
402            {
403               switch(gba_state->BLDCNT & BLDCNT_SFX)
404               {
405                  case BLDCNT_SFX_LIGHTEN:
406                     if(top & gba_state->BLDCNT)
407                     {
408                        color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
409                     }
410                     break;
411                  case BLDCNT_SFX_DARKEN:
412                     if(top & gba_state->BLDCNT)
413                     {
414                        color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
415                     }
416                     break;
417               }
418            }
419         }
420      }
421      else if(color & 0x00010000)
422      {
423         UINT32 back = backdrop;
424         UINT8 top2 = 0x20;
425
426         if((mask & 0x04) != 0 && (line2[x] < back ))
427         {
428            back = line2[x];
429            top2 = 0x04;
430         }
431
432         if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
433         {
434            back = line3[x];
435            top2 = 0x08;
436         }
437
438         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
439         {
440            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
441         }
442         else
443         {
444            switch(gba_state->BLDCNT & BLDCNT_SFX)
445            {
446               case BLDCNT_SFX_LIGHTEN:
447                  if(top & gba_state->BLDCNT)
448                  {
449                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
450                  }
451                  break;
452               case BLDCNT_SFX_DARKEN:
453                  if(top & gba_state->BLDCNT)
454                  {
455                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
456                  }
457                  break;
458            }
459         }
460      }
461      lineMix[x] = color;
462   }
463   gba_state->gfxBG2Changed = 0;
464   gba_state->gfxBG3Changed = 0;
465}
src/mess/video/gba.c
r5697r5698
1/***************************************************************************
1 /***************************************************************************
22
33  gba.c
44
55  File to handle emulation of the video hardware of the Game Boy Advance
66
7  By R. Belmont & MooglyGuy
7  By R. Belmont & Harmony
88
99***************************************************************************/
1010
r5697r5698
1515#define VERBOSE_LEVEL   (0)
1616#define DISABLE_ROZ   (0)
1717
18static UINT16 mosaic_offset[16][4096];
19
2018INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...)
2119{
2220   if( VERBOSE_LEVEL >= n_level )
r5697r5698
2624      va_start( v, s_fmt );
2725      vsprintf( buf, s_fmt, v );
2826      va_end( v );
29      logerror( "%08x: %s", cpu_get_pc(machine->firstcpu), buf );
27      logerror( "%08x: %s", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), buf );
3028   }
3129}
3230
33static void draw_4bpp_tile(gba_state *gba_state, UINT16 *scanline, UINT32 gba_vrambase, UINT16 tilenum, int scnx, int tiley, int vflip, int hflip, int pal, int mosX)
31static UINT16 mosaic_offset[16][4096];
32static int coeff[32] = {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
33                   16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 };
34
35/* Drawing functions */
36static void draw_roz_bitmap_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, INT32 *currentx, INT32 *currenty, int changed, int depth);
37static void draw_roz_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, INT32 *currentx, INT32 *currenty, int changed);
38static void draw_bg_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs);
39static void draw_gba_oam_window(gba_state *gba_state, running_machine *machine, UINT32 *scanline, int y);
40static void draw_gba_oam(gba_state *gba_state, running_machine *machine, UINT32 *scanline, int y);
41static void invalid_gba_draw_function(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux);
42
43/* Utility functions */
44INLINE int is_in_window(gba_state *gba_state, int x, int window);
45INLINE UINT32 alpha_blend_pixel(UINT32 color0, UINT32 color1, int ca, int cb);
46INLINE UINT32 increase_brightness(UINT32 color, int coeff);
47INLINE UINT32 decrease_brightness(UINT32 color, int coeff);
48
49#include "gbamode0.c"
50#include "gbamode1.c"
51#include "gbamode2.c"
52#include "gbam345.c"
53
54void (*gba_draw_scanline_modes[8][3])(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux) =
3455{
35   int pixx, yofs;
36   UINT8 *pgba_vram = (UINT8 *)&gba_state->gba_vram[gba_vrambase>>2], pixel;
37   UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram;
56   /* All modes have three sub-modes: No effects, effects, and windowed effects. */
57   {   /* Mode 0: 4 non-rotatable tilemaps and 1 OAM layer */
58      &draw_mode0_scanline,
59      &draw_mode0_scanline_nowindow,
60      &draw_mode0_scanline_all
61   },
62   {   /* Mode 1: 2 non-rotatable tilemaps, 1 rotozoomable tilemap, and 1 OAM layer */
63      &draw_mode1_scanline,
64      &draw_mode1_scanline_nowindow,
65      &draw_mode1_scanline_all
66   },
67   {   /* Mode 2: 2 rotozoomable tilemaps, and 1 OAM layer */
68      &draw_mode2_scanline,
69      &draw_mode2_scanline_nowindow,
70      &draw_mode2_scanline_all
71   },
72   {   /* Mode 3: 1 rotatable 8bpp bitmap and one OAM layer */
73      &draw_roz_bitmap_mode_scanline,
74      &draw_roz_bitmap_mode_scanline_nowindow,
75      &draw_roz_bitmap_mode_scanline_all
76   },
77   {   /* Mode 4: 1 rotatable 16bpp bitmap and one OAM layer */
78      &draw_roz_bitmap_mode_scanline,
79      &draw_roz_bitmap_mode_scanline_nowindow,
80      &draw_roz_bitmap_mode_scanline_all
81   },
82   {   /* Mode 5: 1 rotatable 4bpp bitmap and one OAM layer */
83      &draw_roz_bitmap_mode_scanline,
84      &draw_roz_bitmap_mode_scanline_nowindow,
85      &draw_roz_bitmap_mode_scanline_all
86   },
87   {
88      &invalid_gba_draw_function,
89      &invalid_gba_draw_function,
90      &invalid_gba_draw_function,
91   },
92   {
93      &invalid_gba_draw_function,
94      &invalid_gba_draw_function,
95      &invalid_gba_draw_function,
96   },
97};
3898
39   if (vflip)
99static void invalid_gba_draw_function(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux)
100{
101   fatalerror( "Invalid screen mode (6 or 7)!\n" );
102}
103
104static void draw_roz_bitmap_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, INT32 *currentx, INT32 *currenty, int changed, int depth)
105{
106   UINT8 *src8 = (UINT8 *)gba_state->gba_vram;
107   UINT16 *src16 = (UINT16 *)gba_state->gba_vram;
108   UINT16 *palette = (UINT16 *)gba_state->gba_pram;
109   INT32 sx = 240;
110   INT32 sy = 160;
111   UINT32 prio = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000;
112   INT32 dx, dmx, dy, dmy, startx, starty;
113   INT32 rx, ry, pixx, pixy, x;
114
115   if(depth == 8)
40116   {
41      yofs = 28-(tiley*4);
117      if(gba_state->DISPCNT & DISPCNT_FRAMESEL)
118      {
119         src8 += 0xa000;
120      }
42121   }
43   else
122
123   // sign extend roz parameters
124   if (X & 0x08000000) X |= 0xf0000000;
125   if (Y & 0x08000000) Y |= 0xf0000000;
126   if (PA & 0x8000) PA |= 0xffff0000;
127   if (PB & 0x8000) PB |= 0xffff0000;
128   if (PC & 0x8000) PC |= 0xffff0000;
129   if (PD & 0x8000) PD |= 0xffff0000;
130
131   // re-assign parameters for convenience's sake
132   dx = PA;
133   dmx = PB;
134   dy = PC;
135   dmy = PD;
136   startx = X;
137   starty = Y;
138
139   if(ypos == 0)
44140   {
45      yofs = tiley*4;
141      changed = 3;
46142   }
47143
48   if (hflip)
144   if(changed & 1)
49145   {
50      for (pixx = 0; pixx < 8; pixx+= 2)
51      {
52         pixel = pgba_vram[(tilenum*32)+(3-(pixx/2))+yofs];
53
54         if (pixel & 0xf0)
55         {
56            scanline[scnx+pixx] = pgba_pram[(pixel>>4)+pal]&0x7fff;
57         }
58         if (pixel & 0x0f)
59         {
60            scanline[scnx+pixx+1] = pgba_pram[(pixel&0xf)+pal]&0x7fff;
61         }
62      }
146      *currentx = startx;
63147   }
64148   else
65149   {
66      for (pixx = 0; pixx < 8; pixx+= 2)
67      {
68         pixel = pgba_vram[(tilenum*32)+(pixx/2)+yofs];
69
70         if (pixel & 0x0f)
71         {
72            scanline[scnx+pixx] = pgba_pram[(pixel&0xf)+pal]&0x7fff;
73         }
74         if (pixel & 0xf0)
75         {
76            scanline[scnx+pixx+1] = pgba_pram[(pixel>>4)+pal]&0x7fff;
77         }
78      }
150      *currentx += dmx;
79151   }
80}
81152
82static void draw_8bpp_tile(gba_state *gba_state, UINT16 *scanline, UINT32 gba_vrambase, UINT16 tilenum, int scnx, int tiley, int vflip, int hflip, int pal, int mosX)
83{
84   int pixx, yofs;
85   UINT8 *pgba_vram = (UINT8 *)&gba_state->gba_vram[gba_vrambase>>2], pixel;
86   UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram;
87
88   if (vflip)
153   if(changed & 2)
89154   {
90      yofs = 56-(tiley*8);
155      *currenty = starty;
91156   }
92157   else
93158   {
94      yofs = tiley*8;
159      *currenty += dmy;
95160   }
96161
97   if (hflip)
162   rx = *currentx;
163   ry = *currenty;
164
165   if(ctrl & BGCNT_MOSAIC)
98166   {
99      for (pixx = 0; pixx < 8; pixx++)
167      INT32 mosaic_line = ((gba_state->MOSAIC & 0x00f0) >> 4) + 1;
168      INT32 tempy = (ypos / mosaic_line) * mosaic_line;
169      rx = startx + tempy*dmx;
170      ry = starty + tempy*dmy;
171   }
172
173   pixx = rx >> 8;
174   pixy = ry >> 8;
175
176   for(x = 0; x < 240; x++)
177   {
178      if(pixx < 0 || pixy < 0 || pixx >= sx || pixy >= sy)
100179      {
101         pixel = pgba_vram[(tilenum*32)+(7-pixx)+yofs];
180         scanline[x] = 0x80000000;
181      }
182      else
183      {
184         if(depth == 8)
185         {
186            UINT8 color = src8[pixy*sx + pixx];
102187
103         if (pixel)
188            if(color)
189            {
190               scanline[x] = palette[color] | prio;
191            }
192            else
193            {
194               scanline[x] = 0x80000000;
195            }
196         }
197         else if(depth == 16)
104198         {
105            scanline[scnx+pixx] = pgba_pram[pixel+pal]&0x7fff;
199            scanline[x] = src16[pixy*sx + pixx] | prio;
106200         }
107201      }
202
203      rx += dx;
204      ry += dy;
205
206      pixx = rx >> 8;
207      pixy = ry >> 8;
108208   }
109   else
209
210   if(ctrl & BGCNT_MOSAIC)
110211   {
111      for (pixx = 0; pixx < 8; pixx++)
212      INT32 mosaicx = (gba_state->MOSAIC & 0x0f) + 1;
213      if(mosaicx > 1)
112214      {
113         pixel = pgba_vram[(tilenum*32)+pixx+yofs];
114
115         if (pixel)
215         INT32 m = 1;
216         for(x = 0; x < 239; x++)
116217         {
117            scanline[scnx+pixx] = pgba_pram[pixel+pal]&0x7fff;
218            scanline[x+1] = scanline[x];
219            m++;
220            if(m == mosaicx)
221            {
222               m = 1;
223               x++;
224            }
118225         }
119226      }
120227   }
121228}
122229
123static void draw_roz_scanline(gba_state *gba_state, UINT16 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, int priority)
230static void draw_roz_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, INT32 *currentx, INT32 *currenty, int changed)
124231{
125   UINT32 base, mapbase, size, ovr;
232   UINT32 base, mapbase, size;
126233   INT32 sizes[4] = { 128, 256, 512, 1024 };
127   INT32 cx, cy, x, ax, ay;
128   UINT8 *mgba_vram = (UINT8 *)gba_state->gba_vram, tile;
234   INT32 cx, cy, x, pixx, pixy;
235   UINT8 *mgba_vram = (UINT8 *)gba_state->gba_vram;
236   UINT32 tile;
129237   UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram;
130238   UINT16 pixel;
239   UINT32 prio = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000;
131240
132   if ((gba_state->DISPCNT & enablemask) && ((ctrl & 3) == priority))
241   for(x = 0; x < 240; x++)
133242   {
243      scanline[x] = 0x80000000;
244   }
245
246   if (gba_state->DISPCNT & enablemask)
247   {
134248      base = ((ctrl & BGCNT_CHARBASE) >> BGCNT_CHARBASE_SHIFT) * 0x4000;         // VRAM base of tiles
135249      mapbase = ((ctrl & BGCNT_SCREENBASE) >> BGCNT_SCREENBASE_SHIFT) * 0x800;   // VRAM base of map
136250      size = (ctrl & BGCNT_SCREENSIZE) >> BGCNT_SCREENSIZE_SHIFT;               // size of map in submaps
137      ovr = ctrl & BGCNT_PALETTESET_WRAP;
138251
139252      // sign extend roz parameters
140253      if (X & 0x08000000) X |= 0xf0000000;
r5697r5698
144257      if (PC & 0x8000) PC |= 0xffff0000;
145258      if (PD & 0x8000) PD |= 0xffff0000;
146259
147      cx = X;
148      cy = Y;
260      if(ypos == 0)
261      {
262         changed = 3;
263      }
149264
150      cx += ypos * PB;
151      cy += ypos * PD;
265      if(changed & 1)
266      {
267         *currentx = X;
268      }
269      else
270      {
271         *currentx += PB;
272      }
152273
274      if(changed & 2)
275      {
276         *currenty = Y;
277      }
278      else
279      {
280         *currenty += PD;
281      }
282
283      cx = *currentx;
284      cy = *currenty;
285
153286      if(ctrl & BGCNT_MOSAIC)
154287      {
155288         int mosaicy = ((gba_state->MOSAIC & 0xf0) >> 4) + 1;
r5697r5698
158291         cy -= y*PD;
159292      }
160293
161      ax = cx >> 8;
162      ay = cy >> 8;
294      pixx = cx >> 8;
295      pixy = cy >> 8;
163296
164297      if(ctrl & BGCNT_PALETTESET_WRAP)
165298      {
166         ax %= sizes[size];
167         ay %= sizes[size];
168         if(ax < 0)
299         pixx %= sizes[size];
300         pixy %= sizes[size];
301         if(pixx < 0)
169302         {
170            ax += sizes[size];
303            pixx += sizes[size];
171304         }
172         if(ay < 0)
305         if(pixy < 0)
173306         {
174            ay += sizes[size];
307            pixy += sizes[size];
175308         }
176309      }
177310
r5697r5698
179312      {
180313         for(x = 0; x < 240; x++)
181314         {
182            if(!(ax < 0 || ay < 0 || ax >= sizes[size] || ay >= sizes[size]))
315            if(pixx < 0 || pixy < 0 || pixx >= sizes[size] || pixy >= sizes[size])
183316            {
184               int tilex = ax & 7;
185               int tiley = ay & 7;
317               scanline[x] = 0x80000000;
318            }
319            else
320            {
321               int tilex = pixx & 7;
322               int tiley = pixy & 7;
186323
187               tile = mgba_vram[mapbase + (ax / 8) + (ay / 8) * (sizes[size] / 8)];
188               pixel = mgba_vram[base + (tile * 64) + (tiley * 8) + tilex];
324               tile = mgba_vram[mapbase + (pixx >> 3) + (pixy >> 3) * (sizes[size] >> 3)];
325               pixel = mgba_vram[base + (tile << 6) + (tiley << 3) + tilex];
189326
190327               // plot it
191               if (pixel)
192               {
193                  scanline[x] = pgba_pram[pixel] & 0x7fff;
194               }
328               scanline[x] = pixel ? (pgba_pram[pixel] | prio) : 0x80000000;
195329            }
196330
197331            cx += PA;
198332            cy += PC;
199333
200            ax = cx >> 8;
201            ay = cy >> 8;
334            pixx = cx >> 8;
335            pixy = cy >> 8;
202336
203337            if(ctrl & BGCNT_PALETTESET_WRAP)
204338            {
205               ax %= sizes[size];
206               ay %= sizes[size];
207               if(ax < 0)
339               pixx %= sizes[size];
340               pixy %= sizes[size];
341               if(pixx < 0)
208342               {
209                  ax += sizes[size];
343                  pixx += sizes[size];
210344               }
211               if(ay < 0)
345               if(pixy < 0)
212346               {
213                  ay += sizes[size];
347                  pixy += sizes[size];
214348               }
215349            }
216350         }
r5697r5698
219353      {
220354         for(x = 0; x < 240; x++)
221355         {
222            if(!(ax < 0 || ay < 0 || ax >= sizes[size] || ay >= sizes[size]))
356            if(pixx < 0 || pixy < 0 || pixx >= sizes[size] || pixy >= sizes[size])
223357            {
224               int tilex = ax & 7;
225               int tiley = ay & 7;
358               scanline[x] = 0x80000000;
359            }
360            else
361            {
362               int tilex = pixx & 7;
363               int tiley = pixy & 7;
226364
227               tile = mgba_vram[mapbase + (ax / 8) + (ay / 8) * (sizes[size] / 8)];
228               pixel = mgba_vram[base + (tile * 64) + (tiley * 8) + tilex];
365               tile = mgba_vram[mapbase + (pixx >> 3) + (pixy >> 3) * (sizes[size] >> 3)];
366               pixel = mgba_vram[base + (tile << 6) + (tiley << 3) + tilex];
229367
230368               // plot it
231               if (pixel)
232               {
233                  scanline[x] = pgba_pram[pixel] & 0x7fff;
234               }
369               scanline[x] = pixel ? (pgba_pram[pixel] | prio) : 0x80000000;
235370            }
236371
237372            cx += PA;
238373            cy += PC;
239374
240            ax = cx >> 8;
241            ay = cy >> 8;
375            pixx = cx >> 8;
376            pixy = cy >> 8;
242377
243378            if(ctrl & BGCNT_PALETTESET_WRAP)
244379            {
245               ax %= sizes[size];
246               ay %= sizes[size];
247               if(ax < 0)
380               pixx %= sizes[size];
381               pixy %= sizes[size];
382               if(pixx < 0)
248383               {
249                  ax += sizes[size];
384                  pixx += sizes[size];
250385               }
251               if(ay < 0)
386               if(pixy < 0)
252387               {
253                  ay += sizes[size];
388                  pixy += sizes[size];
254389               }
255390            }
256391         }
r5697r5698
277412   }
278413}
279414
280static void draw_bg_scanline(gba_state *gba_state, UINT16 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs, int priority)
415static void draw_bg_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs)
281416{
282   UINT32 base, mapbase, size, mode;
283   UINT16 *mgba_vram = (UINT16 *)gba_state->gba_vram, tile;
284   int mx, my, tx, mosX, mosY;
417   UINT8 *vram = (UINT8*)gba_state->gba_vram;
418   UINT16 *palette = (UINT16*)gba_state->gba_pram;
419   UINT8 *chardata = &vram[((ctrl & BGCNT_CHARBASE) >> BGCNT_CHARBASE_SHIFT) * 0x4000];
420   UINT16 *screendata = (UINT16*)&vram[((ctrl & BGCNT_SCREENBASE) >> BGCNT_SCREENBASE_SHIFT) * 0x800];
421   UINT32 priority = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000;
422   INT32 width = 256;
423   INT32 height = 256;
424   INT32 maskx, masky, pixx, pixy;
425   UINT8 use_mosaic = (ctrl & BGCNT_MOSAIC) ? 1 : 0;
426   INT32 mosaicx = (gba_state->MOSAIC & 0x000f) + 1;
427   INT32 mosaicy = ((gba_state->MOSAIC & 0x00f0) >> 4) + 1;
428   INT32 stride;
429   INT32 x;
285430
286   if (ctrl & 0x40)   // mosaic
431   if(!(gba_state->DISPCNT & enablemask))
287432   {
288      mosX = gba_state->MOSAIC & 0xf;
289      mosY = (gba_state->MOSAIC>>4) & 0xf;
433      for(x = 0; x < 240; x++)
434      {
435         scanline[x] = 0x80000000;
436      }
290437
291      ypos = mosaic_offset[mosY][ypos];
438      return;
292439   }
293   else
440
441   switch((ctrl & BGCNT_SCREENSIZE) >> BGCNT_SCREENSIZE_SHIFT)
294442   {
295      mosX = mosY = 0;
443      case 1:
444         width = 512;
445         break;
446      case 2:
447         height = 512;
448         break;
449      case 3:
450         width = 512;
451         height = 512;
452         break;
296453   }
297454
298   if ((gba_state->DISPCNT & enablemask) && ((ctrl & BGCNT_PRIORITY) == priority))
455   maskx = width - 1;
456   masky = height - 1;
457
458   pixx = hofs & maskx;
459   pixy = (vofs + ypos) & masky;
460
461   if(use_mosaic)
299462   {
300      base = ((ctrl>>2)&3) * 0x4000;      // VRAM base of tiles
301      mapbase = ((ctrl>>8)&0x1f) * 0x800;   // VRAM base of map
302      size = ((ctrl>>14) & 3);      // size of map in submaps
303      mode = (ctrl & 0x80) ? 1 : 0;   // 1 for 8bpp, 0 for 4bpp
463      if((ypos % mosaicy) != 0)
464      {
465         mosaicy = (ypos / mosaicy) * mosaicy;
466         pixy = (vofs + mosaicy) & masky;
467      }
468   }
304469
305      mx = hofs/8;      // X tile offset
306      my = (ypos + vofs) / 8;   // Y tile offset
470   if(pixy > 255 && height > 256)
471   {
472      pixy &= 0x000000ff;
473      screendata += 0x400;
474      if(width > 256)
475      {
476         screendata += 0x400;
477      }
478   }
307479
308      switch (size)
480   stride = (pixy >> 3) << 5;
481
482   if(ctrl & BGCNT_PALETTE256)
483   {
484      UINT16 *src = screendata + 0x400 * (pixx >> 8) + ((pixx & 255) >> 3) + stride;
485      INT32 x = 0;
486      for(x = 0; x < 240; x++)
309487      {
310         case 0:   // 32x32
311            for (tx = 0; tx < 31; tx++)
488         UINT16 data = *src;
489         INT32 tile = data & TILEOBJ_TILE;
490         INT32 tilex = pixx & 7;
491         INT32 tiley = pixy & 7;
492         UINT8 color;
493
494         if(data & TILEOBJ_HFLIP)
495         {
496            tilex = 7 - tilex;
497         }
498         if(data & TILEOBJ_VFLIP)
499         {
500            tiley = 7 - tiley;
501         }
502
503         color = chardata[(tile << 6) + (tiley << 3) + tilex];
504
505         if(color)
506         {
507            scanline[x] = palette[color] | priority;
508         }
509         else
510         {
511            scanline[x] = 0x80000000;
512         }
513
514         if(data & TILEOBJ_HFLIP)
515         {
516            if(tilex == 0)
312517            {
313               tile = mgba_vram[(mapbase>>1) + ((tx + mx) % 32) + ((my % 32) * 32)];
314
315               if (mode)
316               {
317                  draw_8bpp_tile(gba_state, scanline, base, (tile&0x3ff)<<1, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, 0, mosX);
318               }
319               else
320               {
321                  draw_4bpp_tile(gba_state, scanline, base, tile&0x3ff, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, ((tile&0xf000)>>8), mosX);
322               }
518               src++;
323519            }
324            break;
520         }
521         else if(tilex == 7)
522         {
523            src++;
524         }
325525
326         case 1:   // 64x32
327            for (tx = 0; tx < 31; tx++)
526         pixx++;
527         if(pixx == 256)
528         {
529            if(width > 256)
328530            {
329               int mapxofs = ((tx + mx) % 64);
531               src = screendata + 0x400 + stride;
532            }
533            else
534            {
535               src = screendata + stride;
536               pixx = 0;
537            }
538         }
539         else if(pixx >= width)
540         {
541            pixx = 0;
542            src = screendata + stride;
543         }
544      }
545   }
546   else
547   {
548      UINT16 *src = screendata + 0x400 * (pixx >> 8) + ((pixx & 255) >> 3) + stride;
549      INT32 x = 0;
550      for(x = 0; x < 240; x++)
551      {
552         UINT16 data = *src;
553         INT32 tile = data & TILEOBJ_TILE;
554         INT32 tilex = pixx & 7;
555         INT32 tiley = pixy & 7;
556         UINT8 color;
557         UINT8 palindex;
330558
331               if (mapxofs >= 32)
332               {
333                  mapxofs %= 32;
334                  mapxofs += (32*32);   // offset to reach the second page of the tilemap
335               }
559         if(data & TILEOBJ_HFLIP)
560         {
561            tilex = 7 - tilex;
562         }
563         if(data & TILEOBJ_VFLIP)
564         {
565            tiley = 7 - tiley;
566         }
336567
337               tile = mgba_vram[(mapbase>>1) + mapxofs + ((my % 32) * 32)];
568         color = chardata[(tile << 5) + (tiley << 2) + (tilex >> 1)];
338569
339               if (mode)
340               {
341                  draw_8bpp_tile(gba_state, scanline, base, (tile&0x3ff)<<1, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, 0, mosX);
342               }
343               else
344               {
345                  draw_4bpp_tile(gba_state, scanline, base, tile&0x3ff, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, ((tile&0xf000)>>8), mosX);
346               }
570         if(tilex & 1)
571         {
572            color >>= 4;
573         }
574         else
575         {
576            color &= 0x0f;
577         }
578
579         palindex = (data >> 8) & 0x00f0;
580         if(color)
581         {
582            scanline[x] = palette[palindex + color] | priority;
583         }
584         else
585         {
586            scanline[x] = 0x80000000;
587         }
588
589         if(data & TILEOBJ_HFLIP)
590         {
591            if(tilex == 0)
592            {
593               src++;
347594            }
348            break;
595         }
596         else if(tilex == 7)
597         {
598            src++;
599         }
349600
350         case 2:   // 32x64
351            for (tx = 0; tx < 31; tx++)
601         pixx++;
602         if(pixx == 256)
603         {
604            if(width > 256)
352605            {
353               int mapyofs = (my % 64);
606               src = screendata + 0x400 + stride;
607            }
608            else
609            {
610               src = screendata + stride;
611               pixx = 0;
612            }
613         }
614         else if(pixx >= width)
615         {
616            pixx = 0;
617            src = screendata + stride;
618         }
619      }
620   }
354621
355               if (mapyofs >= 32)
356               {
357                  mapyofs %= 32;
358                  mapyofs += 32;
359               }
622   if(use_mosaic)
623   {
624      if(mosaicx > 1)
625      {
626         INT32 m = 1;
627         for(x = 0; x < 239; x++)
628         {
629            scanline[x+1] = scanline[x];
630            m++;
631            if(m == mosaicx)
632            {
633               m = 1;
634               x++;
635            }
636         }
637      }
638   }
639}
360640
361               tile = mgba_vram[(mapbase>>1) + ((tx + mx) % 32) + (mapyofs * 32)];
641static void draw_gba_oam_window(gba_state *gba_state, running_machine *machine, UINT32 *scanline, int y)
642{
643   INT16 gba_oamindex;
644   UINT32 tilebytebase, tileindex, tiledrawindex;
645   UINT32 width, height;
646   UINT16 *pgba_oam = (UINT16 *)gba_state->gba_oam;
647   int x = 0;
648   UINT8 *src = (UINT8*)gba_state->gba_vram;
362649
363               if (mode)
364               {
365                  draw_8bpp_tile(gba_state, scanline, base, (tile&0x3ff)<<1, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, 0, mosX);
366               }
367               else
368               {
369                  draw_4bpp_tile(gba_state, scanline, base, tile&0x3ff, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, ((tile&0xf000)>>8), mosX);
370               }
371            }
372            break;
650   for(x = 0; x < 240; x++)
651   {
652      scanline[x] = 0x80000000;
653   }
373654
374         case 3: // 64x64
375         #if 0
376            if (1)
377            {
378               int mapyofs = (my % 64);
655   if( gba_state->DISPCNT & DISPCNT_OBJWIN_EN )
656   {
657      for( gba_oamindex = 127; gba_oamindex >= 0; gba_oamindex-- )
658      {
659         INT32 sx, sy;
660         UINT16 attr0, attr1, attr2;
661         INT32 cury;
379662
380               if (mapyofs >= 32)
381               {
382                  mapyofs %= 32;
383                  mapyofs += 64;
384               }
663         attr0 = pgba_oam[(4*gba_oamindex)+0];
664         attr1 = pgba_oam[(4*gba_oamindex)+1];
665         attr2 = pgba_oam[(4*gba_oamindex)+2];
385666
386//               printf("%d yofs %d (ypos %d vofs %d my %d) tileofs %x\n", video_screen_get_vpos(machine->primary_screen), mapyofs, ypos, vofs, my, (mapbase>>1) + (mapyofs * 32));
667         sx = (attr1 & OBJ_X_COORD);
668         sy = (attr0 & OBJ_Y_COORD);
669
670         if(sy > 160)
671         {
672            sy -= 256;
673         }
674
675         if ((attr0 & OBJ_MODE) != OBJ_MODE_WINDOW)
676         {
677            continue;
678         }
679         else
680         {
681            width = 0;
682            height = 0;
683            switch (attr0 & OBJ_SHAPE )
684            {
685               case OBJ_SHAPE_SQR:
686                  switch(attr1 & OBJ_SIZE )
687                  {
688                     case OBJ_SIZE_8:
689                        width = 1;
690                        height = 1;
691                        break;
692                     case OBJ_SIZE_16:
693                        width = 2;
694                        height = 2;
695                        break;
696                     case OBJ_SIZE_32:
697                        width = 4;
698                        height = 4;
699                        break;
700                     case OBJ_SIZE_64:
701                        width = 8;
702                        height = 8;
703                        break;
704                  }
705                  break;
706               case OBJ_SHAPE_HORIZ:
707                  switch(attr1 & OBJ_SIZE )
708                  {
709                     case OBJ_SIZE_8:
710                        width = 2;
711                        height = 1;
712                        break;
713                     case OBJ_SIZE_16:
714                        width = 4;
715                        height = 1;
716                        break;
717                     case OBJ_SIZE_32:
718                        width = 4;
719                        height = 2;
720                        break;
721                     case OBJ_SIZE_64:
722                        width = 8;
723                        height = 4;
724                        break;
725                  }
726                  break;
727               case OBJ_SHAPE_VERT:
728                  switch(attr1 & OBJ_SIZE )
729                  {
730                     case OBJ_SIZE_8:
731                        width = 1;
732                        height = 2;
733                        break;
734                     case OBJ_SIZE_16:
735                        width = 1;
736                        height = 4;
737                        break;
738                     case OBJ_SIZE_32:
739                        width = 2;
740                        height = 4;
741                        break;
742                     case OBJ_SIZE_64:
743                        width = 4;
744                        height = 8;
745                        break;
746                  }
747                  break;
748               default:
749                  width = 0;
750                  height = 0;
751                  verboselog(machine, 0, "OAM error: Trying to draw OBJ with OBJ_SHAPE = 3!\n" );
752                  break;
387753            }
388         #endif
389754
390            for (tx = 0; tx < 31; tx++)
755            tiledrawindex = tileindex = (attr2 & OBJ_TILENUM);
756            tilebytebase = 0x10000;   // the index doesn't change in the higher modes, we just ignore sprites that are out of range
757
758             if (attr0 & OBJ_ROZMODE_ROZ)
391759            {
392               int mapxofs = ((tx + mx) % 64);
393               int mapyofs = (my % 64);
760               INT32 fx, fy, ax, ay, rx, ry;
761               INT16 dx, dy, dmx, dmy;
762               UINT8 color;
394763
395               if (mapyofs >= 32)
764               width *= 8;
765               height *= 8;
766
767               if ((attr0 & OBJ_ROZMODE) == OBJ_ROZMODE_DISABLE)
396768               {
397                  mapyofs %= 32;
398                  mapyofs += 64;
769                  continue;
399770               }
400771
401               if (mapxofs >= 32)
772               fx = width;
773               fy = height;
774
775               if((attr0 & OBJ_ROZMODE) == OBJ_ROZMODE_DBLROZ)
402776               {
403                  mapxofs %= 32;
404                  mapxofs += (32*32);   // offset to reach the second/fourth page of the tilemap
777                  fx *= 2;
778                  fy *= 2;
405779               }
406780
407               tile = mgba_vram[(mapbase>>1) + mapxofs + (mapyofs * 32)];
781               cury = y - sy;
408782
409               if (mode)
783               if(cury >= 0 && cury < fy)
410784               {
411                  draw_8bpp_tile(gba_state, scanline, base, (tile&0x3ff)<<1, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, 0, mosX);
785                  if(sx < 240 || ((sx + fx) & 0x1ff) < 240)
786                  {
787                     int rot = (attr1 & OBJ_SCALE_PARAM) >> OBJ_SCALE_PARAM_SHIFT;
788                     dx  = (INT16)pgba_oam[(rot << 4)+3];
789                     dmx = (INT16)pgba_oam[(rot << 4)+7];
790                     dy  = (INT16)pgba_oam[(rot << 4)+11];
791                     dmy = (INT16)pgba_oam[(rot << 4)+15];
792
793                     rx = (width << 7) - (fx >> 1)*dx - (fy >> 1)*dmx + cury * dmx;
794                     ry = (height << 7) - (fx >> 1)*dy - (fy >> 1)*dmy + cury * dmy;
795
796                     if((attr0 & OBJ_PALMODE) == OBJ_PALMODE_256)
797                     {
798                        int inc = 32;
799                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
800                        {
801                           continue;
802                        }
803                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
804                        {
805                           inc = sx >> 2;
806                        }
807                        else
808                        {
809                           tiledrawindex &= 0x3fe;
810                        }
811                        for(x = 0; x < fx; x++)
812                        {
813                           ax = rx >> 8;
814                           ay = ry >> 8;
815
816                           if(ax < 0 || ax >= sx || ay < 0 || ay >= sy)
817                           {
818                           }
819                           else
820                           {
821                              color = src[tilebytebase + ((((tiledrawindex + (ay >> 3) * inc) << 5) + ((ay & 0x07) << 3) + ((ax >> 3) << 6) + (ax & 0x07)) & 0x7fff)];
822
823                              if(color)
824                              {
825                                 scanline[sx] = 1;
826                              }
827                           }
828
829                           sx = (sx + 1) & 0x1ff;
830
831                           rx += dx;
832                           ry += dy;
833                        }
834                     }
835                     else
836                     {
837                        int inc = 32;
838                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
839                        {
840                           continue;
841                        }
842                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
843                        {
844                           inc = sx >> 3;
845                        }
846                        for(x = 0; x < fx; x++)
847                        {
848                           ax = rx >> 8;
849                           ay = ry >> 8;
850
851                           if(ax < 0 || ax >= sx || ay < 0 || ay >= sy)
852                           {
853                           }
854                           else
855                           {
856                              color = src[tilebytebase + ((((tiledrawindex + (ay >> 3) * inc) << 5) + ((ay & 0x07) << 2) + ((ax >> 3) << 5) + ((ax & 0x07) >> 1)) & 0x7fff)];
857
858                              if(ax & 1)
859                              {
860                                 color >>= 4;
861                              }
862                              else
863                              {
864                                 color &= 0x0f;
865                              }
866
867                              if(color)
868                              {
869                                 scanline[sx] = 1;
870                              }
871                           }
872
873                           sx = (sx + 1) & 0x1ff;
874
875                           rx += dx;
876                           ry += dy;
877                        }
878                     }
879                  }
412880               }
413               else
414               {
415                  draw_4bpp_tile(gba_state, scanline, base, tile&0x3ff, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, ((tile&0xf000)>>8), mosX);
416               }
417881            }
418            break;
419      }
420   }
421}
882            else
883            {
884               INT32 ax;
885               int cury = y - sy;
422886
423static void draw_mode3_scanline(gba_state *gba_state, UINT16 *scanline, int y)
424{
425   int x;
426   UINT16 *pgba_vram = (UINT16 *)gba_state->gba_vram;
887               width *= 8;
888               height *= 8;
427889
428   for (x = 0; x < 240; x++)
429   {
430      scanline[x] = pgba_vram[(240*y)+x]&0x7fff;
431   }
432}
890               if(cury >= 0 && cury < height)
891               {
892                  if( ( (sx < 240) || ( ( (sx + width) & 0x1ff ) < 240 ) ) && (attr0 & OBJ_ROZMODE_DISABLE) == 0)
893                  {
894                     if((attr0 & OBJ_PALMODE) == OBJ_PALMODE_256)
895                     {
896                        int inc = 32;
897                        int address = 0;
898                        if(attr1 & OBJ_VFLIP)
899                        {
900                           cury = height - cury - 1;
901                        }
902                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
903                        {
904                           continue;
905                        }
433906
434static void draw_mode4_scanline(gba_state *gba_state, UINT16 *scanline, int y)
435{
436   UINT32 base;
437   int x;
438   UINT8 *pgba_vram = (UINT8 *)gba_state->gba_vram, pixel;
439   UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram;
907                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
908                        {
909                           inc = width >> 2;
910                        }
911                        else
912                        {
913                           tiledrawindex &= 0x3fe;
914                        }
440915
441   if (gba_state->DISPCNT & DISPCNT_FRAMESEL)
442   {
443      base = 0xa000;
444   }
445   else
446   {
447      base = 0;
448   }
916                        ax = 0;
917                        if(attr1 & OBJ_HFLIP)
918                        {
919                           ax = width - 1;
920                        }
449921
450   for (x = 0; x < 240; x++)
451   {
452      pixel = pgba_vram[base+(240*y)+x];
453      if (pixel != 0)
454      {
455         scanline[x] = pgba_pram[pixel]&0x7fff;
456      }
457   }
458}
922                        address = 0x10000 + ((((tiledrawindex + (cury >> 3) * inc) << 5) + ((cury & 7) << 3) + ((ax >> 3) << 6) + (ax & 7)) & 0x7fff);
459923
460static void draw_mode5_scanline(gba_state *gba_state, UINT16 *scanline, int y)
461{
462   UINT32 base;
463   int x;
464   UINT16 *pgba_vram = (UINT16 *)gba_state->gba_vram;
924                        if(attr1 & OBJ_HFLIP)
925                        {
926                           ax = 7;
927                        }
465928
466   if (gba_state->DISPCNT & DISPCNT_FRAMESEL)
467   {
468      base = 0xa000>>1;
469   }
470   else
471   {
472      base = 0;
473   }
929                        for(x = 0; x < width; x++)
930                        {
931                           if(sx < 240)
932                           {
933                              UINT8 color = src[address];
474934
475   for (x = 0; x < 160; x++)
476   {
477      scanline[x] = pgba_vram[base+(160*y)+x];
935                              if(color)
936                              {
937                                 scanline[sx] = 1;
938                              }
939                           }
940
941                           sx = (sx + 1) & 0x1ff;
942
943                           if(attr1 & OBJ_HFLIP)
944                           {
945                              ax--;
946                              address--;
947                              if(ax == -1)
948                              {
949                                 address -= 56;
950                                 ax = 7;
951                              }
952                              if(address < 0x10000)
953                              {
954                                 address += 0x8000;
955                              }
956                           }
957                           else
958                           {
959                              ax++;
960                              address++;
961                              if(ax == 8)
962                              {
963                                 address += 56;
964                                 ax = 0;
965                              }
966                              if(address > 0x17fff)
967                              {
968                                 address -= 0x8000;
969                              }
970                           }
971                        }
972                     }
973                     else
974                     {
975                        int inc = 32;
976                        int address;
977                        if(attr1 & OBJ_VFLIP)
978                        {
979                           cury = height - cury - 1;
980                        }
981                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
982                        {
983                           continue;
984                        }
985
986                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
987                        {
988                           inc = width >> 3;
989                        }
990
991                        ax = 0;
992                        if(attr1 & OBJ_HFLIP)
993                        {
994                           ax = width - 1;
995                        }
996
997                        address = 0x10000 + ((((tiledrawindex + (cury >> 3) * inc) << 5) + ((cury & 0x07) << 2) + ((ax >> 3) << 5) + ((ax & 0x07) >> 1)) & 0x7fff);
998                        if(attr1 & OBJ_HFLIP)
999                        {
1000                           ax = 7;
1001                           for(x = width - 1; x >= 0; x--)
1002                           {
1003                              if(sx < 240)
1004                              {
1005                                 UINT8 color = src[address];
1006                                 if(x & 1)
1007                                 {
1008                                    color >>= 4;
1009                                 }
1010                                 else
1011                                 {
1012                                    color &= 0x0f;
1013                                 }
1014
1015                                 if(color)
1016                                 {
1017                                    scanline[sx] = 1;
1018                                 }
1019                              }
1020
1021                              sx = (sx + 1) & 0x1ff;
1022                              ax--;
1023                              if((x & 1) == 0)
1024                              {
1025                                 address--;
1026                              }
1027                              if(ax == -1)
1028                              {
1029                                 ax = 7;
1030                                 address -= 28;
1031                              }
1032                              if(address < 0x10000)
1033                              {
1034                                 address += 0x8000;
1035                              }
1036                           }
1037                        }
1038                        else
1039                        {
1040                           for(x = 0; x < width; x++)
1041                           {
1042                              if(sx < 240)
1043                              {
1044                                 UINT8 color = src[address];
1045
1046                                 if(x & 1)
1047                                 {
1048                                    color >>= 4;
1049                                 }
1050                                 else
1051                                 {
1052                                    color &= 0x0f;
1053                                 }
1054
1055                                 if(color)
1056                                 {
1057                                    scanline[sx] = 1;
1058                                 }
1059                              }
1060
1061                              sx = (sx + 1) & 0x1ff;
1062                              ax++;
1063                              if(x & 1)
1064                              {
1065                                 address++;
1066                              }
1067                              if(ax == 8)
1068                              {
1069                                 address += 28;
1070                                 ax = 0;
1071                              }
1072                              if(address > 0x17fff)
1073                              {
1074                                 address -= 0x8000;
1075                              }
1076                           }
1077                        }
1078                     }
1079                  }
1080               }
1081            }
1082         }
1083      }
4781084   }
4791085}
4801086
481static void draw_gba_oam(gba_state *gba_state, running_machine *machine, UINT16 *scanline, int y, int priority)
1087static void draw_gba_oam(gba_state *gba_state, running_machine *machine, UINT32 *scanline, int y)
4821088{
4831089   INT16 gba_oamindex;
484   UINT8 tilex, tiley;
1090   INT32 mosaiccnt = 0;
1091   INT32 mosaicy = ((gba_state->MOSAIC & 0xf000) >> 12) + 1;
1092   INT32 mosaicx = ((gba_state->MOSAIC & 0x0f00) >>  8) + 1;
4851093   UINT32 tilebytebase, tileindex, tiledrawindex;
4861094   UINT8 width, height;
4871095   UINT16 *pgba_oam = (UINT16 *)gba_state->gba_oam;
1096   UINT8 *src = (UINT8 *)gba_state->gba_vram;
1097   UINT16 *palette = (UINT16*)gba_state->gba_pram;
1098   int x = 0;
4881099
1100   for(x = 0; x < 240; x++)
1101   {
1102      scanline[x] = 0x80000000;
1103   }
1104
4891105   if( gba_state->DISPCNT & DISPCNT_OBJ_EN )
4901106   {
491      for( gba_oamindex = 127; gba_oamindex >= 0; gba_oamindex-- )
1107      for( gba_oamindex = 0; gba_oamindex < 128; gba_oamindex++ )
4921108      {
4931109         UINT16 attr0, attr1, attr2;
494         INT32 cury, lg;
495         UINT8 *src;
496         UINT16 j;
1110         INT32 cury;
1111         UINT32 prio;
1112         UINT32 priority;
4971113
4981114         attr0 = pgba_oam[(4*gba_oamindex)+0];
4991115         attr1 = pgba_oam[(4*gba_oamindex)+1];
5001116         attr2 = pgba_oam[(4*gba_oamindex)+2];
1117         priority = (attr2 & OBJ_PRIORITY) >> OBJ_PRIORITY_SHIFT;
1118         prio = (priority << 25) | ((attr0 & OBJ_MODE) << 6);
5011119
502         if (((attr0 & OBJ_MODE) != OBJ_MODE_WINDOW) && (((attr2 >> 10) & 3) == priority))
1120         if ((attr0 & OBJ_MODE) != OBJ_MODE_WINDOW)
5031121         {
5041122            width = 0;
5051123            height = 0;
506            switch (attr0 & OBJ_SHAPE )
1124            switch (attr0 & OBJ_SHAPE)
5071125            {
5081126               case OBJ_SHAPE_SQR:
5091127                  switch(attr1 & OBJ_SIZE )
r5697r5698
5801198
5811199             if (attr0 & OBJ_ROZMODE_ROZ)
5821200            {
583               INT16 sx, sy;
584               INT32 fx, fy, ax, ay, rx, ry, offs;
585               UINT8 blockparam;
1201               INT32 sx, sy;
1202               INT32 fx, fy, rx, ry;
5861203               INT16 dx, dy, dmx, dmy;
587               UINT8 color;
5881204
5891205               width *= 8;
5901206               height *= 8;
r5697r5698
5971213               sx = (attr1 & OBJ_X_COORD);
5981214               sy = (attr0 & OBJ_Y_COORD);
5991215
600               lg = width;
601
602               if(sx & 0x100)
1216               if(sy > 160)
6031217               {
604                  sx |= 0xffffff00;
1218                  sy -= 256;
6051219               }
6061220
607               if(sy >= 160)
608               {
609                  sy |= 0xffffff00;
610               }
611
6121221               fx = width;
6131222               fy = height;
6141223
r5697r5698
6161225               {
6171226                  fx *= 2;
6181227                  fy *= 2;
619                  lg *= 2;
6201228               }
6211229
622               if((y < sy) || (y >= sy + fy) || (sx >= 240) || (sx + fx <= 0))
623               {
624                  continue;
625               }
626
6271230               cury = y - sy;
6281231
629               blockparam = ((attr1 & OBJ_SCALE_PARAM) >> OBJ_SCALE_PARAM_SHIFT) << 4;
630
631               dx  = (INT16)pgba_oam[blockparam+3];
632               dmx = (INT16)pgba_oam[blockparam+7];
633               dy  = (INT16)pgba_oam[blockparam+11];
634               dmy = (INT16)pgba_oam[blockparam+15];
635
636               rx = (width << 7) - (fx >> 1)*dx - (fy >> 1)*dmx + cury * dmx;
637               ry = (height << 7) - (fx >> 1)*dy - (fy >> 1)*dmy + cury * dmy;
638
639               if (sx < 0)
1232               if(cury >= 0 && cury < fy)
6401233               {
641                  if(sx + fx <= 0)
1234                  if(sx < 240 || ((sx + fx) & 0x1ff) < 240)
6421235                  {
643                     continue;
644                  }
1236                     INT32 oamparam = (attr1 & OBJ_SCALE_PARAM) >> OBJ_SCALE_PARAM_SHIFT;
6451237
646                  lg += sx;
647                  rx -= sx*dx;
648                  ry -= sx*dy;
649                  sx = 0;
650               }
651               else
652               {
653                  if(sx + fx > 256)
654                  {
655                     lg = 256 - sx;
656                  }
657               }
1238                     dx  = (INT16)pgba_oam[(oamparam << 4)+3];
1239                     dmx = (INT16)pgba_oam[(oamparam << 4)+7];
1240                     dy  = (INT16)pgba_oam[(oamparam << 4)+11];
1241                     dmy = (INT16)pgba_oam[(oamparam << 4)+15];
6581242
659               if(attr0 & OBJ_PALMODE_256)
660               {
661                  UINT16 *pgba_pram = (UINT16*)gba_state->gba_pram;
1243                     if(attr0 & OBJ_MOSAIC)
1244                     {
1245                        cury -= (cury % mosaicy);
1246                     }
6621247
663                  src = (UINT8*)&gba_state->gba_vram[tilebytebase >> 2];
664                  if(!src)
665                  {
666                     continue;
667                  }
1248                     rx = (width << 7) - (fx >> 1)*dx - (fy >> 1)*dmx + cury*dmx;
1249                     ry = (height << 7) - (fx >> 1)*dy - (fy >> 1)*dmy + cury*dmy;
6681250
669                  src += tiledrawindex * 32;
1251                     if((attr0 & OBJ_PALMODE) == OBJ_PALMODE_256)
1252                     {
1253                        INT32 inc = 32;
6701254
671                  for(j = 0; j < lg; ++j, ++sx)
672                  {
673                     ax = (rx >> 8);
674                     ay = (ry >> 8);
1255                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
1256                        {
1257                           continue;
1258                        }
6751259
676                     if(ax >= 0 && ay >= 0 && ax < width && ay < height)
677                     {
678                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_2D)
1260                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
6791261                        {
680                           offs = (ax & 0x7) + ((ax & 0xfff8) << 3) + ((ay >> 3) << 10) + ((ay & 0x7) << 3);
1262                           inc = width >> 2;
6811263                        }
6821264                        else
6831265                        {
684                           offs = (ax & 0x7) + ((ax & 0xfff8) << 3) + (((ay >> 3) * width) << 3) + ((ay & 0x7) << 3);
1266                           tiledrawindex &= 0x3fe;
6851267                        }
6861268
687                        color = src[offs];
688
689                        if(color)
1269                        for(x = 0; x < fx; x++)
6901270                        {
691                           scanline[sx] = pgba_pram[256+color] & 0x7fff;
692                        }
693                     }
1271                           INT32 pixx = rx >> 8;
1272                           INT32 pixy = ry >> 8;
6941273
695                     rx += dx;
696                     ry += dy;
697                  }
698               }
699               else
700               {
701                  UINT16 *pgba_pram = (UINT16*)gba_state->gba_pram;
1274                           if(!(pixx < 0 || pixx >= width || pixy < 0 || pixy >= height || sx >= 240))
1275                           {
1276                              UINT8 color = src[0x10000 + ((((tiledrawindex + (pixy >> 3) * inc) << 5) + ((pixy & 7) << 3) + ((pixx >> 3) << 6) + (pixx & 7)) & 0x7fff)];
1277                              if(color == 0 && priority < ((scanline[sx] >> 25) & 3))
1278                              {
1279                                 scanline[sx] = (scanline[sx] & 0xf9ffffff) | prio;
1280                                 if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0)
1281                                 {
1282                                    scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio;
1283                                 }
1284                              }
1285                              else if(color != 0 && prio < (scanline[sx] & 0xff000000))
1286                              {
1287                                 scanline[sx] = palette[256 + color] | prio;
1288                                 if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0)
1289                                 {
1290                                    scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio;
1291                                 }
1292                              }
7021293
703                  src = (UINT8*)&gba_state->gba_vram[tilebytebase >> 2];
704                  if(!src)
705                  {
706                     continue;
707                  }
1294                              if(attr0 & OBJ_MOSAIC)
1295                              {
1296                                 mosaiccnt++;
1297                                 if(mosaiccnt == mosaicx)
1298                                 {
1299                                    mosaiccnt = 0;
1300                                 }
1301                              }
1302                           }
7081303
709                  src += tiledrawindex * 32;
1304                           sx++;
1305                           sx &= 0x1ff;
7101306
711                  for(j = 0; j < lg; ++j, ++sx)
712                  {
713                     ax = (rx >> 8);
714                     ay = (ry >> 8);
1307                           rx += dx;
1308                           ry += dy;
1309                        }
1310                     }
1311                     else
1312                     {
1313                        INT32 inc = 32;
1314                        INT32 palentry = (attr2 >> 8) & 0xf0;
7151315
716                     if(ax >= 0 && ay >= 0 && ax < width && ay < height)
717                     {
718                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_2D)
1316                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
7191317                        {
720                           offs = ((ax >> 1) & 0x3) + (((ax >> 1) & 0xfffc) << 3) + ((ay >> 3) << 10) + ((ay & 0x7) << 2);
1318                           continue;
7211319                        }
722                        else
1320
1321                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
7231322                        {
724                           offs = ((ax >> 1) & 0x3) + (((ax >> 1) & 0xfffc) << 3) + (((ay >> 3) * width) << 2) + ((ay & 0x7) << 2);
1323                           inc = width >> 3;
7251324                        }
7261325
727                        color = src[offs];
728
729                        if(ax & 1)
1326                        for(x = 0; x < fx; x++)
7301327                        {
731                           color >>= 4;
732                        }
733                        else
734                        {
735                           color &= 0x0f;
736                        }
1328                           INT32 pixx = rx >> 8;
1329                           INT32 pixy = ry >> 8;
7371330
738                        if(color)
739                        {
740                           scanline[sx] = pgba_pram[256 + ((attr2 & 0xf000) >> 8) + color] & 0x7fff;
1331                           if(!(pixx < 0 || pixx >= width || pixy < 0 || pixy >= height || sx >= 240))
1332                           {
1333                              UINT8 color = src[0x10000 + ((((tiledrawindex + (pixy >> 3) * inc) << 5) + ((pixy & 7) << 2) + ((pixx >> 3) << 5) + ((pixx & 7) >> 1)) & 0x7fff)];
1334
1335                              if(pixx & 1)
1336                              {
1337                                 color >>= 4;
1338                              }
1339                              else
1340                              {
1341                                 color &= 0x0f;
1342                              }
1343
1344                              if(color == 0 && priority < ((scanline[sx] >> 25) & 3))
1345                              {
1346                                 scanline[sx] = (scanline[sx] & 0xf9ffffff) | prio;
1347                                 if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0)
1348                                 {
1349                                    scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio;
1350                                 }
1351                              }
1352                              else if(color != 0 && prio < (scanline[sx] & 0xff000000))
1353                              {
1354                                 scanline[sx] = palette[256 + palentry + color] | prio;
1355                                 if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0)
1356                                 {
1357                                    scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio;
1358                                 }
1359                              }
1360                           }
1361
1362                           if(attr0 & OBJ_MOSAIC)
1363                           {
1364                              mosaiccnt++;
1365                              if(mosaiccnt == mosaicx)
1366                              {
1367                                 mosaiccnt = 0;
1368                              }
1369                           }
1370
1371                           sx++;
1372
1373                           sx &= 0x1ff;
1374
1375                           rx += dx;
1376                           ry += dy;
7411377                        }
7421378                     }
743
744                     rx += dx;
745                     ry += dy;
7461379                  }
7471380               }
7481381            }
7491382            else
7501383            {
751               INT16 sx, sy;
752               int vflip, hflip;
1384               INT32 sx, sy;
1385               INT32 vflip = (attr1 & OBJ_VFLIP) ? 1 : 0;
1386               INT32 hflip = (attr1 & OBJ_HFLIP) ? 1 : 0;
7531387
1388               width *= 8;
1389               height *= 8;
1390
7541391               if ((attr0 & OBJ_ROZMODE) == OBJ_ROZMODE_DISABLE)
7551392               {
7561393                  continue;
r5697r5698
7581395
7591396               sx = (attr1 & OBJ_X_COORD);
7601397               sy = (attr0 & OBJ_Y_COORD);
761               vflip = (attr1 & OBJ_VFLIP) ? 1 : 0;
762               hflip = (attr1 & OBJ_HFLIP) ? 1 : 0;
7631398
764               if (sy > 160)
1399               if(sy > 160)
7651400               {
766                  sy = 0 - (255-sy);
1401                  sy -= 256;
7671402               }
7681403
769               if (sx > 256)
1404               cury = y - sy;
1405               if(cury >= 0 && cury < height)
7701406               {
771                  sx = 0 - (511-sx);
772               }
773
774               // on this scanline?
775               if ((y >= sy) && (y < (sy+(height*8))))
776               {
777                  // Y = scanline we're drawing
778                  // SY = starting Y position of sprite
779                  if (vflip)
1407                  if(sx < 240 || ((sx + width) & 0x1ff) < 240)
7801408                  {
781                     tiley = (sy+(height*8)-1) - y;
782                  }
783                  else
784                  {
785                     tiley = y - sy;
786                  }
787
788                  if (( gba_state->DISPCNT & DISPCNT_VRAM_MAP ) == DISPCNT_VRAM_MAP_2D)
789                  {
790                     tiledrawindex = (tileindex + ((tiley/8) * 32));
791                  }
792                  else
793                  {
794                     if ((attr0 & OBJ_PALMODE) == OBJ_PALMODE_16)
1409                     if((attr0 & OBJ_PALMODE) == OBJ_PALMODE_256)
7951410                     {
796                        tiledrawindex = (tileindex + ((tiley/8) * width));
797                     }
798                     else
799                     {
800                        tiledrawindex = (tileindex + ((tiley/8) * (width*2)));
801                     }
802                  }
1411                        INT32 pixx;
1412                        INT32 inc = 32;
1413                        INT32 address = 0;
8031414
804                  if (hflip)
805                  {
806                     tiledrawindex += (width-1);
807                     for (tilex = 0; tilex < width; tilex++)
808                     {
809                        if ((attr0 & OBJ_PALMODE) == OBJ_PALMODE_16)
1415                        if(vflip)
8101416                        {
811                           draw_4bpp_tile(gba_state, scanline, tilebytebase, tiledrawindex, sx+(tilex*8), tiley % 8, 0, hflip, 256+((attr2&0xf000)>>8), 0);
1417                           cury = height - cury - 1;
8121418                        }
1419
1420                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
1421                        {
1422                           continue;
1423                        }
1424
1425                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
1426                        {
1427                           inc = width >> 2;
1428                        }
8131429                        else
8141430                        {
815                           draw_8bpp_tile(gba_state, scanline, tilebytebase, tiledrawindex, sx+(tilex*8), tiley % 8, 0, hflip, 256, 0);
816                           tiledrawindex++;
1431                           tiledrawindex &= 0x3fe;
8171432                        }
818                        tiledrawindex--;
1433
1434                        pixx = 0;
1435                        if(hflip)
1436                        {
1437                           pixx = width - 1;
1438                        }
1439
1440                        if(attr0 & OBJ_MOSAIC)
1441                        {
1442                           cury -= (cury % mosaicy);
1443                        }
1444
1445                        address = 0x10000 + ((((tiledrawindex + (cury >> 3) * inc) << 5) + ((cury & 7) << 3) + ((pixx >> 3) << 6) + (pixx & 7)) & 0x7fff);
1446
1447                        if(hflip)
1448                        {
1449                           pixx = 7;
1450                        }
1451
1452                        for(x = 0; x < width; x++)
1453                        {
1454                           if(sx < 240)
1455                           {
1456                              UINT8 color = src[address];
1457                              if(color == 0 && priority < ((scanline[sx] >> 25) & 3))
1458                              {
1459                                 scanline[sx] = (scanline[sx] & 0xf9ffffff) | prio;
1460                                 if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0)
1461                                 {
1462                                    scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio;
1463                                 }
1464                              }
1465                              else if(color != 0 && prio < (scanline[sx] & 0xff000000))
1466                              {
1467                                 scanline[sx] = palette[256 + color] | prio;
1468                                 if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0)
1469                                 {
1470                                    scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio;
1471                                 }
1472                              }
1473                           }
1474
1475                           if(attr0 & OBJ_MOSAIC)
1476                           {
1477                              mosaiccnt++;
1478                              if(mosaiccnt == mosaicx)
1479                              {
1480                                 mosaiccnt = 0;
1481                              }
1482                           }
1483
1484                           sx++;
1485                           sx &= 0x1ff;
1486
1487                           if(hflip)
1488                           {
1489                              pixx--;
1490                              address--;
1491                              if(pixx == -1)
1492                              {
1493                                 address -= 56;
1494                                 pixx = 7;
1495                              }
1496                              if(address < 0x10000)
1497                              {
1498                                 address += 0x8000;
1499                              }
1500                           }
1501                           else
1502                           {
1503                              pixx++;
1504                              address++;
1505                              if(pixx == 8)
1506                              {
1507                                 address += 56;
1508                                 pixx = 0;
1509                              }
1510                              if(address > 0x17fff)
1511                              {
1512                                 address -= 0x8000;
1513                              }
1514                           }
1515                        }
8191516                     }
820                  }
821                  else
822                  {
823                     for (tilex = 0; tilex < width; tilex++)
1517                     else
8241518                     {
825                        if ((attr0 & OBJ_PALMODE) == OBJ_PALMODE_16)
1519                        INT32 pixx;
1520                        INT32 inc = 32;
1521                        UINT32 address = 0;
1522
1523                        if(vflip)
8261524                        {
827                           draw_4bpp_tile(gba_state, scanline, tilebytebase, tiledrawindex, sx+(tilex*8), tiley % 8, 0, hflip, 256+((attr2&0xf000)>>8), 0);
1525                           cury = height - cury - 1;
8281526                        }
1527
1528                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
1529                        {
1530                           continue;
1531                        }
1532
1533                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
1534                        {
1535                           inc = width >> 3;
1536                        }
1537
1538                        pixx = 0;
1539                        if(hflip)
1540                        {
1541                           pixx = width - 1;
1542                        }
1543
1544                        if(attr0 & OBJ_MOSAIC)
1545                        {
1546                           cury -= (cury % mosaicy);
1547                        }
1548
1549                        address = 0x10000 + ((((tiledrawindex + (cury >> 3) * inc) << 5) + ((cury & 7) << 2) + ((pixx >> 3) << 5) + ((pixx & 7) >> 1)) & 0x7fff);
1550
1551                        if(hflip)
1552                        {
1553                           pixx = 7;
1554                           for(x = width - 1; x >= 0; x--)
1555                           {
1556                              if(sx < 240)
1557                              {
1558                                 UINT8 color = src[address];
1559                                 UINT8 palentry = (attr2 >> 8) & 0xf0;
1560
1561                                 if(x & 1)
1562                                 {
1563                                    color >>= 4;
1564                                 }
1565                                 else
1566                                 {
1567                                    color &= 0x0f;
1568                                 }
1569
1570                                 if(color == 0 && priority < ((scanline[sx] >> 25) & 3))
1571                                 {
1572                                    scanline[sx] = (scanline[sx] & 0xf9ffffff) | prio;
1573                                    if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0)
1574                                    {
1575                                       scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio;
1576                                    }
1577                                 }
1578                                 else if(color != 0 && prio < (scanline[sx] & 0xff000000))
1579                                 {
1580                                    scanline[sx] = palette[256 + palentry + color] | prio;
1581                                    if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0)
1582                                    {
1583                                       scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio;
1584                                    }
1585                                 }
1586                              }
1587
1588                              sx++;
1589                              sx &= 0x1ff;
1590
1591                              pixx--;
1592                              if(!(x & 1))
1593                              {
1594                                 address--;
1595                              }
1596                              if(pixx == -1)
1597                              {
1598                                 address -= 28;
1599                                 pixx = 7;
1600                              }
1601                              if(address < 0x10000)
1602                              {
1603                                 address += 0x8000;
1604                              }
1605                           }
1606                        }
8291607                        else
8301608                        {
831                           draw_8bpp_tile(gba_state, scanline, tilebytebase, tiledrawindex, sx+(tilex*8), tiley % 8, 0, hflip, 256, 0);
832                           tiledrawindex++;
1609                           for(x = 0; x < width; x++)
1610                           {
1611                              if(sx < 240)
1612                              {
1613                                 UINT8 color = src[address];
1614                                 UINT8 palentry = (attr2 >> 8) & 0xf0;
1615
1616                                 if(x & 1)
1617                                 {
1618                                    color >>= 4;
1619                                 }
1620                                 else
1621                                 {
1622                                    color &= 0x0f;
1623                                 }
1624
1625                                 if(color == 0 && priority < ((scanline[sx] >> 25) & 3))
1626                                 {
1627                                    scanline[sx] = (scanline[sx] & 0xf9ffffff) | prio;
1628                                    if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0)
1629                                    {
1630                                       scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio;
1631                                    }
1632                                 }
1633                                 else if(color != 0 && prio < (scanline[sx] & 0xff000000))
1634                                 {
1635                                    scanline[sx] = palette[256 + palentry + color] | prio;
1636                                    if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0)
1637                                    {
1638                                       scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio;
1639                                    }
1640                                 }
1641                              }
1642
1643                              if(attr0 & OBJ_MOSAIC)
1644                              {
1645                                 mosaiccnt++;
1646                                 if(mosaiccnt == mosaicx)
1647                                 {
1648                                    mosaiccnt = 0;
1649                                 }
1650                              }
1651
1652                              sx++;
1653                              sx &= 0x1ff;
1654
1655                              pixx++;
1656                              if(x & 1)
1657                              {
1658                                 address++;
1659                              }
1660                              if(pixx == 8)
1661                              {
1662                                 address += 28;
1663                                 pixx = 0;
1664                              }
1665                              if(address > 0x17fff)
1666                              {
1667                                 address -= 0x8000;
1668                              }
1669                           }
8331670                        }
834                        tiledrawindex++;
8351671                     }
8361672                  }
8371673               }
r5697r5698
8411677   }
8421678}
8431679
1680INLINE int is_in_window(gba_state *gba_state, int x, int window)
1681{
1682   int x0 = gba_state->WIN0H >> 8;
1683   int x1 = gba_state->WIN0H & 0x00ff;
1684
1685   if(window == 1)
1686   {
1687      x0 = gba_state->WIN1H >> 8;
1688      x1 = gba_state->WIN1H & 0x00ff;
1689   }
1690
1691   if(x0 <= x1)
1692   {
1693      if(x >= x0 && x < x1)
1694      {
1695         return 1;
1696      }
1697   }
1698   else
1699   {
1700      if(x >= x0 || x < x1)
1701      {
1702         return 1;
1703      }
1704   }
1705
1706   return 0;
1707}
1708
1709INLINE UINT32 alpha_blend_pixel(UINT32 color0, UINT32 color1, int ca, int cb)
1710{
1711   if(color0 < 0x80000000)
1712   {
1713      int r0 = (color0 >>  0) & 0x1f;
1714      int g0 = (color0 >>  5) & 0x1f;
1715      int b0 = (color0 >> 10) & 0x1f;
1716      int r1 = (color1 >>  0) & 0x1f;
1717      int g1 = (color1 >>  5) & 0x1f;
1718      int b1 = (color1 >> 10) & 0x1f;
1719      int r = ((r0 * ca) >> 4) + ((r1 * cb) >> 4);
1720      int g = ((g0 * ca) >> 4) + ((g1 * cb) >> 4);
1721      int b = ((b0 * ca) >> 4) + ((b1 * cb) >> 4);
1722
1723      if(r > 0x1f) r = 0x1f;
1724      if(g > 0x1f) g = 0x1f;
1725      if(b > 0x1f) b = 0x1f;
1726
1727      return (color0 & 0xffff0000) | (b << 10) | (g << 5) | r;
1728   }
1729   return color0;
1730}
1731
1732INLINE UINT32 increase_brightness(UINT32 color, int coeff)
1733{
1734   int r = (color >>  0) & 0x1f;
1735   int g = (color >>  5) & 0x1f;
1736   int b = (color >> 10) & 0x1f;
1737
1738   r += ((0x1f - r) * coeff) >> 4;
1739   g += ((0x1f - g) * coeff) >> 4;
1740   b += ((0x1f - b) * coeff) >> 4;
1741
1742   if(r > 0x1f) r = 0x1f;
1743   if(g > 0x1f) g = 0x1f;
1744   if(b > 0x1f) b = 0x1f;
1745
1746   return (color & 0xffff0000) | (b << 10) | (g << 5) | r;
1747}
1748
1749INLINE UINT32 decrease_brightness(UINT32 color, int coeff)
1750{
1751   int r = (color >>  0) & 0x1f;
1752   int g = (color >>  5) & 0x1f;
1753   int b = (color >> 10) & 0x1f;
1754
1755   r -= (r * coeff) >> 4;
1756   g -= (g * coeff) >> 4;
1757   b -= (b * coeff) >> 4;
1758
1759   if(r < 0) r = 0;
1760   if(g < 0) g = 0;
1761   if(b < 0) b = 0;
1762
1763   return (color & 0xffff0000) | (b << 10) | (g << 5) | r;
1764}
1765
8441766void gba_draw_scanline(running_machine *machine, int y)
8451767{
846   UINT16 *pgba_pram, *scanline;
847   int prio;
8481768   bitmap_t *bitmap = tmpbitmap;
849   int i;
850   static UINT16 xferscan[240+2048];   // up to 1024 pixels of slop on either side to allow easier clip handling
1769   UINT16 *scanline = BITMAP_ADDR16(bitmap, y, 0);
1770   int i, x;
1771   static UINT32 xferscan[7][240+2048];   // up to 1024 pixels of slop on either side to allow easier clip handling
8511772   gba_state *gba_state = machine->driver_data;
1773   UINT8 submode = 0;
1774   int bpp = 0;
8521775
853   pgba_pram = (UINT16 *)gba_state->gba_pram;
854
855   scanline = BITMAP_ADDR16(bitmap, y, 0);
856
8571776   // forced blank
8581777   if (gba_state->DISPCNT & DISPCNT_BLANK)
8591778   {
r5697r5698
8651784      return;
8661785   }
8671786
868   // BG color
869   for (i = 0; i < 240; i++)
1787   //printf( "mode = %d\n", gba_state->DISPCNT & 7 );
1788
1789   if(gba_state->DISPCNT & DISPCNT_OBJWIN_EN)
8701790   {
871      xferscan[1024+i] = pgba_pram[0]&0x7fff;
1791      submode = 2;
8721792   }
1793   else if(gba_state->fxOn)
1794   {
1795      submode = 1;
1796   }
1797   else
1798   {
1799      submode = 0;
1800   }
8731801
874
875//   printf("mode %d\n", (gba_state->DISPCNT & 7));
876
877//   if (y == 0) printf("DISPCNT %04x\n", gba_state->DISPCNT);
878
879   switch (gba_state->DISPCNT & 7)
1802   switch(gba_state->DISPCNT & 7)
8801803   {
881      case 0:
882         for (prio = 3; prio >= 0; prio--)
883         {
884            draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3HOFS, gba_state->BG3VOFS, prio);
885            draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2HOFS, gba_state->BG2VOFS, prio);
886            draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS, prio);
887            draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS, prio);
888            draw_gba_oam(gba_state, machine, &xferscan[1024], y, prio);
889         }
890         break;
891
892      case 1:
893         for (prio = 3; prio >= 0; prio--)
894         {
895            draw_roz_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, prio);
896            draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS, prio);
897            draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS, prio);
898            draw_gba_oam(gba_state, machine, &xferscan[1024], y, prio);
899         }
900         break;
901
902      case 2:
903         for (prio = 3; prio >= 0; prio--)
904         {
905            draw_roz_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3X, gba_state->BG3Y, gba_state->BG3PA, gba_state->BG3PB, gba_state->BG3PC, gba_state->BG3PD, prio);
906            draw_roz_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, prio);
907            draw_gba_oam(gba_state, machine, &xferscan[1024], y, prio);
908         }
909         break;
910
9111804      case 3:
912         draw_mode3_scanline(gba_state, &xferscan[1024], y);
913         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 3);
914         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 2);
915         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 1);
916         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 0);
1805         bpp = 16;
9171806         break;
918
9191807      case 4:
920         draw_mode4_scanline(gba_state, &xferscan[1024], y);
921         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 3);
922         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 2);
923         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 1);
924         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 0);
1808         bpp = 8;
9251809         break;
926
9271810      case 5:
928         draw_mode5_scanline(gba_state, &xferscan[1024], y);
929         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 3);
930         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 2);
931         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 1);
932         draw_gba_oam(gba_state, machine, &xferscan[1024], y, 0);
1811         bpp = 4;
9331812         break;
9341813   }
9351814
1815   gba_draw_scanline_modes[gba_state->DISPCNT & 7][submode](machine, gba_state, y, &xferscan[0][1024], &xferscan[1][1024], &xferscan[2][1024], &xferscan[3][1024], &xferscan[4][1024], &xferscan[5][1024], &xferscan[6][1024], bpp);
9361816
937   // copy the working scanline to the real one
938   memcpy(scanline, &xferscan[1024], 240*2);
1817   for(x = 0; x < 240; x++)
1818   {
1819      scanline[x] = xferscan[6][1024 + x] & 0x7fff;
1820   }
9391821
9401822   return;
9411823}
src/mess/includes/gba.h
r5697r5698
5353#define OBJ_MODE_NORMAL         0x0000
5454#define OBJ_MODE_ALPHA         0x0400
5555#define OBJ_MODE_WINDOW         0x0800
56#define OBJ_MODE_BITMAP         0x0c00
56#define OBJ_MODE_UNDEFINED      0x0c00
5757
5858#define OBJ_MOSAIC         0x1000
5959
r5697r5698
9494#define BGCNT_CHARBASE_SHIFT   2
9595#define BGCNT_PRIORITY         0x0003
9696
97#define BLDCNT_BG0TP1         0x0001
98#define BLDCNT_BG1TP1         0x0002
99#define BLDCNT_BG2TP1         0x0004
100#define BLDCNT_BG3TP1         0x0008
101#define BLDCNT_OBJTP1         0x0010
102#define BLDCNT_BDTP1         0x0020
103#define BLDCNT_SFX            0x00c0
104#define BLDCNT_SFX_NONE         0x0000
105#define BLDCNT_SFX_ALPHA      0x0040
106#define BLDCNT_SFX_LIGHTEN      0x0080
107#define BLDCNT_SFX_DARKEN      0x00c0
108#define BLDCNT_BG0TP2         0x0100
109#define BLDCNT_BG1TP2         0x0200
110#define BLDCNT_BG2TP2         0x0400
111#define BLDCNT_BG3TP2         0x0800
112#define BLDCNT_OBJTP2         0x1000
113#define BLDCNT_BDTP2         0x2000
114#define BLDCNT_TP2_SHIFT      8
115
116#define TILEOBJ_TILE         0x03ff
117#define TILEOBJ_HFLIP         0x0400
118#define TILEOBJ_VFLIP         0x0800
119#define TILEOBJ_PALETTE         0xf000
120
97121// states for carts with flash saves
98122enum
99123{
r5697r5698
125149typedef struct
126150{
127151   UINT32 DISPSTAT;
152   UINT32 BG2X, BG2Y, BG3X, BG3Y;
128153   UINT16 DISPCNT,   GRNSWAP;
129154   UINT16 BG0CNT, BG1CNT, BG2CNT, BG3CNT;
130155   UINT16 BG0HOFS, BG0VOFS, BG1HOFS, BG1VOFS, BG2HOFS, BG2VOFS, BG3HOFS, BG3VOFS;
131   UINT16 BG2PA, BG2PB, BG2PC, BG2PD, BG2X, BG2Y, BG3PA, BG3PB, BG3PC, BG3PD, BG3X, BG3Y;
156   UINT16 BG2PA, BG2PB, BG2PC, BG2PD, BG3PA, BG3PB, BG3PC, BG3PD;
132157   UINT16 WIN0H, WIN1H, WIN0V, WIN1V, WININ, WINOUT;
133158   UINT16 MOSAIC;
134159   UINT16 BLDCNT;
r5697r5698
149174   UINT8  POSTFLG;
150175   UINT8  HALTCNT;
151176
177   UINT8  windowOn;
178   UINT8  fxOn;
179   UINT8  gfxBG2Changed;
180   UINT8  gfxBG3Changed;
181   INT32  gfxBG2X;
182   INT32  gfxBG2Y;
183   INT32  gfxBG3X;
184   INT32  gfxBG3Y;
185
152186   UINT32 *gba_pram;
153187   UINT32 *gba_vram;
154188   UINT32 *gba_oam;
src/mess/drivers/gba.c
r5697r5698
44
55  Driver file to handle emulation of the Nintendo Game Boy Advance.
66
7  By R. Belmont & MooglyGuy
7  By R. Belmont & Harmony
88
99  TODO:
10  - Raster interrupts have issues
11  - Roz sprites
12  - Roz BG support
13  - Windows
14  - Blending
10  - Raster timing issues.  Castlevania (HOD and AOS)'s raster effects
11    work if the VBlank is fired on scanline 0, else they're offset by
12    the height of the vblank region.  Is scanline 0 the start of the
13    visible area?
1514
1615***************************************************************************/
1716
r5697r5698
2524#include "includes/gb.h"
2625#include "sound/dac.h"
2726
28#define VERBOSE_LEVEL   (0)
27#define VERBOSE_LEVEL   (2)
2928
3029INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...)
3130{
r5697r5698
3635      va_start( v, s_fmt );
3736      vsprintf( buf, s_fmt, v );
3837      va_end( v );
39      logerror( "%08x: %s", cpu_get_pc(machine->firstcpu), buf );
38      logerror( "%08x: %s", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), buf );
4039   }
4140}
4241
r5697r5698
8685      // master enable?
8786      if (gba_state->IME & 1)
8887      {
89         cpu_set_input_line(machine->firstcpu, ARM7_IRQ_LINE, ASSERT_LINE);
90         cpu_set_input_line(machine->firstcpu, ARM7_IRQ_LINE, CLEAR_LINE);
88         cpu_set_input_line(cputag_get_cpu(machine, "maincpu"), ARM7_IRQ_LINE, ASSERT_LINE);
89         cpu_set_input_line(cputag_get_cpu(machine, "maincpu"), ARM7_IRQ_LINE, CLEAR_LINE);
9190      }
9291   }
9392}
r5697r5698
142141   int ctrl;
143142   int srcadd, dstadd;
144143   UINT32 src, dst;
145   const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM);
144   const address_space *space = cpu_get_address_space(cputag_get_cpu(machine, "maincpu"), ADDRESS_SPACE_PROGRAM);
146145   gba_state *gba_state = machine->driver_data;
147146
148147   src = gba_state->dma_src[ch];
r5697r5698
998997         {
999998            verboselog(machine, 2, "GBA IO Register Write: DISPCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1000999            gba_state->DISPCNT = ( gba_state->DISPCNT & ~mem_mask ) | ( data & mem_mask );
1000            if(gba_state->DISPCNT & (DISPCNT_WIN0_EN | DISPCNT_WIN1_EN))
1001            {
1002               gba_state->windowOn = 1;
1003            }
1004            else
1005            {
1006               gba_state->windowOn = 0;
1007            }
10011008         }
10021009         if( (mem_mask) & 0xffff0000 )
10031010         {
r5697r5698
10061013         }
10071014         break;
10081015      case 0x0004/4:
1009//         printf("DISPSTAT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, mem_mask );
10101016         COMBINE_DATA(&gba_state->DISPSTAT);
10111017         break;
10121018      case 0x0008/4:
r5697r5698
11091115         if( (mem_mask) & 0x0000ffff )
11101116         {
11111117            verboselog(machine, 2, "GBA IO Register Write: BG2X_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1112            gba_state->BG2X = ( gba_state->BG2X & ~mem_mask ) | ( data & mem_mask );
11131118         }
11141119         if( (mem_mask) & 0xffff0000 )
11151120         {
11161121            verboselog(machine, 2, "GBA IO Register Write: BG2X_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1117                      gba_state->BG2X = ( gba_state->BG2X & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
11181122         }
1123         COMBINE_DATA(&gba_state->BG2X);
1124         gba_state->gfxBG2Changed |= 1;
11191125         break;
11201126      case 0x002c/4:
11211127         if( (mem_mask) & 0x0000ffff )
11221128         {
11231129            verboselog(machine, 2, "GBA IO Register Write: BG2Y_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1124            gba_state->BG2Y = ( gba_state->BG2Y & ~mem_mask ) | ( data & mem_mask );
11251130         }
11261131         if( (mem_mask) & 0xffff0000 )
11271132         {
11281133            verboselog(machine, 2, "GBA IO Register Write: BG2Y_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1129                      gba_state->BG2Y = ( gba_state->BG2Y & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
11301134         }
1135         COMBINE_DATA(&gba_state->BG2Y);
1136         gba_state->gfxBG2Changed |= 2;
11311137         break;
11321138      case 0x0030/4:
11331139         if( (mem_mask) & 0x0000ffff )
r5697r5698
11571163         if( (mem_mask) & 0x0000ffff )
11581164         {
11591165            verboselog(machine, 2, "GBA IO Register Write: BG3X_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1160            gba_state->BG3X = ( gba_state->BG3X & ~mem_mask ) | ( data & mem_mask );
11611166         }
11621167         if( (mem_mask) & 0xffff0000 )
11631168         {
11641169            verboselog(machine, 2, "GBA IO Register Write: BG3X_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1165                gba_state->BG3X = ( gba_state->BG3X & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
11661170         }
1171         COMBINE_DATA(&gba_state->BG3X);
1172         gba_state->gfxBG3Changed |= 1;
11671173         break;
11681174      case 0x003c/4:
11691175         if( (mem_mask) & 0x0000ffff )
11701176         {
11711177            verboselog(machine, 2, "GBA IO Register Write: BG3Y_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1172            gba_state->BG3Y = ( gba_state->BG3Y & ~mem_mask ) | ( data & mem_mask );
11731178         }
11741179         if( (mem_mask) & 0xffff0000 )
11751180         {
11761181            verboselog(machine, 2, "GBA IO Register Write: BG3Y_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1177                gba_state->BG3Y = ( gba_state->BG3Y & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
11781182         }
1183         COMBINE_DATA(&gba_state->BG3Y);
1184         gba_state->gfxBG3Changed |= 2;
11791185         break;
11801186      case 0x0040/4:
11811187         if( (mem_mask) & 0x0000ffff )
r5697r5698
12291235         {
12301236            verboselog(machine, 2, "GBA IO Register Write: BLDCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
12311237            gba_state->BLDCNT = ( gba_state->BLDCNT & ~mem_mask ) | ( data & mem_mask );
1238            if(gba_state->BLDCNT & BLDCNT_SFX)
1239            {
1240               gba_state->fxOn = 1;
1241            }
1242            else
1243            {
1244               gba_state->fxOn = 0;
1245            }
12321246         }
12331247         if( (mem_mask) & 0xffff0000 )
12341248         {
r5697r5698
13751389            {
13761390               const device_config *gb_a_l = devtag_get_device(machine, "direct_a_left");
13771391               const device_config *gb_a_r = devtag_get_device(machine, "direct_a_right");
1378                           
1392
13791393               gba_state->fifo_a_ptr = 17;
13801394               gba_state->fifo_a_in = 17;
13811395               dac_signed_data_w(gb_a_l, 0x80);
r5697r5698
13871401            {
13881402               const device_config *gb_b_l = devtag_get_device(machine, "direct_b_left");
13891403               const device_config *gb_b_r = devtag_get_device(machine, "direct_b_right");
1390                           
1404
13911405               gba_state->fifo_b_ptr = 17;
13921406               gba_state->fifo_b_in = 17;
13931407               dac_signed_data_w(gb_b_l, 0x80);
r5697r5698
17341748            // if we still have interrupts, yank the IRQ line again
17351749            if (gba_state->IF)
17361750            {
1737               timer_adjust_oneshot(gba_state->irq_timer, cpu_clocks_to_attotime(machine->firstcpu, 120), 0);
1751               timer_adjust_oneshot(gba_state->irq_timer, cpu_clocks_to_attotime(cputag_get_cpu(machine, "maincpu"), 120), 0);
17381752            }
17391753         }
17401754         break;
r5697r5698
17771791               gba_state->HALTCNT = data & 0x000000ff;
17781792
17791793               // either way, wait for an IRQ
1780               cpu_spinuntil_int(machine->firstcpu);
1794               cpu_spinuntil_int(cputag_get_cpu(machine, "maincpu"));
17811795            }
17821796         }
17831797         if( (mem_mask) & 0xffff0000 )
r5697r5698
17911805   }
17921806}
17931807
1808INLINE UINT32 COMBINE_DATA32_16(UINT32 prev, UINT32 data, UINT32 mem_mask)
1809{
1810   COMBINE_DATA(&prev);
1811   switch(mem_mask)
1812   {
1813      case 0x000000ff:
1814         prev &= 0xffff00ff;
1815         prev |= data << 8;
1816         break;
1817      case 0x0000ff00:
1818         prev &= 0xffffff00;
1819         prev |= data >> 8;
1820         break;
1821      case 0x00ff0000:
1822         prev &= 0x00ffffff;
1823         prev |= data << 8;
1824         break;
1825      case 0xff000000:
1826         prev &= 0xffffffff;
1827         prev |= data << 8;
1828         break;
1829      default:
1830         break;
1831   }
1832   return prev;
1833}
1834
1835static WRITE32_HANDLER(gba_pram_w)
1836{
1837   running_machine *machine = space->machine;
1838   gba_state *gba_state = machine->driver_data;
1839
1840   gba_state->gba_pram[offset] = COMBINE_DATA32_16(gba_state->gba_pram[offset], data, mem_mask);
1841}
1842
1843static WRITE32_HANDLER(gba_vram_w)
1844{
1845   running_machine *machine = space->machine;
1846   gba_state *gba_state = machine->driver_data;
1847
1848   gba_state->gba_vram[offset] = COMBINE_DATA32_16(gba_state->gba_vram[offset], data, mem_mask);
1849}
1850
1851static WRITE32_HANDLER(gba_oam_w)
1852{
1853   running_machine *machine = space->machine;
1854   gba_state *gba_state = machine->driver_data;
1855
1856   gba_state->gba_oam[offset] = COMBINE_DATA32_16(gba_state->gba_oam[offset], data, mem_mask);
1857}
1858
17941859static ADDRESS_MAP_START( gbadvance_map, ADDRESS_SPACE_PROGRAM, 32 )
17951860   AM_RANGE(0x00000000, 0x00003fff) AM_ROMBANK(1)
17961861   AM_RANGE(0x02000000, 0x0203ffff) AM_RAM AM_MIRROR(0xfc0000)
17971862   AM_RANGE(0x03000000, 0x03007fff) AM_RAM AM_MIRROR(0xff8000)
17981863   AM_RANGE(0x04000000, 0x040003ff) AM_READWRITE( gba_io_r, gba_io_w )
1799   AM_RANGE(0x05000000, 0x050003ff) AM_RAM AM_BASE_MEMBER(gba_state, gba_pram)   // Palette RAM
1800   AM_RANGE(0x06000000, 0x06017fff) AM_RAM AM_BASE_MEMBER(gba_state, gba_vram)   // VRAM
1801   AM_RANGE(0x07000000, 0x070003ff) AM_RAM AM_BASE_MEMBER(gba_state, gba_oam)   // OAM
1864   AM_RANGE(0x05000000, 0x050003ff) AM_RAM_WRITE(gba_pram_w) AM_BASE_MEMBER(gba_state, gba_pram)   // Palette RAM
1865   AM_RANGE(0x06000000, 0x06017fff) AM_RAM_WRITE(gba_vram_w) AM_BASE_MEMBER(gba_state, gba_vram)   // VRAM
1866   AM_RANGE(0x07000000, 0x070003ff) AM_RAM_WRITE(gba_oam_w) AM_BASE_MEMBER(gba_state, gba_oam)   // OAM
18021867   AM_RANGE(0x08000000, 0x09ffffff) AM_ROM AM_REGION("cartridge", 0)   // cartridge ROM (mirror 0)
18031868   AM_RANGE(0x0a000000, 0x0bffffff) AM_ROM AM_REGION("cartridge", 0)   // cartridge ROM (mirror 1)
18041869   AM_RANGE(0x0c000000, 0x0cffffff) AM_ROM AM_REGION("cartridge", 0)   // final mirror
r5697r5698
18241889   int ch, ctrl;
18251890   gba_state *gba_state = machine->driver_data;
18261891   int scanline = video_screen_get_vpos(machine->primary_screen);
1827   
1892
18281893   // draw only visible scanlines
18291894   if (scanline < 160)
18301895   {
r5697r5698
18811946   }
18821947
18831948   // entering VBL, handle interrupts and DMA triggers
1884   if (scanline == 160)
1949   if (scanline == 0)
18851950   {
18861951      int ch, ctrl;
18871952
r5697r5698
19251990   gba_state->KEYCNT = 0x03ff;
19261991   gba_state->RCNT = 0x8000;
19271992   gba_state->JOYSTAT = 0x0002;
1993   gba_state->gfxBG2Changed = 0;
1994   gba_state->gfxBG3Changed = 0;
1995   gba_state->gfxBG2X = 0;
1996   gba_state->gfxBG2Y = 0;
1997   gba_state->gfxBG3X = 0;
1998   gba_state->gfxBG3Y = 0;
19281999
2000   gba_state->windowOn = 0;
2001   gba_state->fxOn = 0;
2002
19292003   timer_adjust_oneshot(gba_state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
19302004   timer_adjust_oneshot(gba_state->hbl_timer, attotime_never, 0);
19312005   timer_adjust_oneshot(gba_state->dma_timer[0], attotime_never, 0);
r5697r5698
22652339
22662340         if (gba_state->eeprom_bits == 0)
22672341         {
2268            mame_printf_verbose("%08x: EEPROM: %02x to %x\n", cpu_get_pc(space->   machine->firstcpu), gba_state->eep_data, gba_state->eeprom_addr );
2342            mame_printf_verbose("%08x: EEPROM: %02x to %x\n", cpu_get_pc(cputag_get_cpu(space->machine, "maincpu")), gba_state->eep_data, gba_state->eeprom_addr );
22692343            gba_state->gba_eeprom[gba_state->eeprom_addr] = gba_state->eep_data;
22702344            gba_state->eeprom_addr++;
22712345            gba_state->eep_data = 0;
r5697r5698
23042378
23052379         if (image_length(image) <= (16*1024*1024))
23062380         {
2307            memory_install_read32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_r);
2308            memory_install_write32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_w);
2381            memory_install_read32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_r);
2382            memory_install_write32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_w);
23092383         }
23102384         else
23112385         {
2312            memory_install_read32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_r);
2313            memory_install_write32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_w);
2386            memory_install_read32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_r);
2387            memory_install_write32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_w);
23142388         }
23152389         break;
23162390      }
r5697r5698
23192393         nvptr = (UINT8 *)&gba_state->gba_sram;
23202394         nvsize = 0x10000;
23212395
2322         memory_install_read32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_r);
2323         memory_install_write32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_w);
2396         memory_install_read32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_r);
2397         memory_install_write32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_w);
23242398         break;
23252399      }
23262400      else if (!memcmp(&ROM[i], "FLASH1M_", 8))
r5697r5698
23332407         nvptr = (UINT8 *)&gba_state->gba_flash64k;
23342408         nvsize = 0x10000;
23352409
2336         memory_install_read32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash64k_r);
2337         memory_install_write32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash64k_w);
2410         memory_install_read32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash64k_r);
2411         memory_install_write32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash64k_w);
23382412         break;
23392413      }
23402414      else if (!memcmp(&ROM[i], "SIIRTC_V", 8))
r5697r5698
24312505
24322506static DRIVER_INIT(gbadv)
24332507{
2434   memory_set_direct_update_handler( cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM), gba_direct );
2508   memory_set_direct_update_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), gba_direct );
24352509}
24362510
24372511/*    YEAR  NAME PARENT COMPAT MACHINE INPUT   INIT   CONFIG COMPANY     FULLNAME */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team