Previous 15994 Revisions Next

r7510 Friday 5th March, 2010 at 13:32:47 UTC by Fabio Priuli
more fixes
[src/mess/drivers]apexc.c camplynx.c cat.c gba.c
[src/mess/includes]gba.h mac.h
[src/mess/video]gba.c gbam345.c gbamode0.c gbamode1.c gbamode2.c

src/mess/video/gbamode0.c
r7509r7510
88
99***************************************************************************/
1010
11static void draw_mode0_scanline(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
11static void draw_mode0_scanline(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
1212{
1313   int x = 0;
14   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
14   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
1515
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);
16   draw_bg_scanline(state, line0, y, DISPCNT_BG0_EN, state->BG0CNT, state->BG0HOFS, state->BG0VOFS);
17   draw_bg_scanline(state, line1, y, DISPCNT_BG1_EN, state->BG1CNT, state->BG1HOFS, state->BG1VOFS);
18   draw_bg_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2HOFS, state->BG2VOFS);
19   draw_bg_scanline(state, line3, y, DISPCNT_BG3_EN, state->BG3CNT, state->BG3HOFS, state->BG3VOFS);
20   draw_gba_oam(state, machine, lineOBJ, y);
2121
2222   for(x = 0; x < 240; x++)
2323   {
r7509r7510
8383            top2 = 0x08;
8484         }
8585
86         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
86         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
8787         {
88            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
88            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
8989         }
9090         else
9191         {
92            switch(gba_state->BLDCNT & BLDCNT_SFX)
92            switch(state->BLDCNT & BLDCNT_SFX)
9393            {
9494               case BLDCNT_SFX_LIGHTEN:
95                  if(top & gba_state->BLDCNT)
95                  if(top & state->BLDCNT)
9696                  {
97                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
97                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
9898                  }
9999                  break;
100100               case BLDCNT_SFX_DARKEN:
101                  if(top & gba_state->BLDCNT)
101                  if(top & state->BLDCNT)
102102                  {
103                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
103                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
104104                  }
105105                  break;
106106            }
r7509r7510
111111   }
112112}
113113
114static void draw_mode0_scanline_nowindow(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
114static void draw_mode0_scanline_nowindow(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
115115{
116116   int x = 0;
117   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
118   int effect = gba_state->BLDCNT & BLDCNT_SFX;
117   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
118   int effect = state->BLDCNT & BLDCNT_SFX;
119119
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);
120   draw_bg_scanline(state, line0, y, DISPCNT_BG0_EN, state->BG0CNT, state->BG0HOFS, state->BG0VOFS);
121   draw_bg_scanline(state, line1, y, DISPCNT_BG1_EN, state->BG1CNT, state->BG1HOFS, state->BG1VOFS);
122   draw_bg_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2HOFS, state->BG2VOFS);
123   draw_bg_scanline(state, line3, y, DISPCNT_BG3_EN, state->BG3CNT, state->BG3HOFS, state->BG3VOFS);
124   draw_gba_oam(state, machine, lineOBJ, y);
125125
126126   for(x = 0; x < 240; x++)
127127   {
r7509r7510
165165            case BLDCNT_SFX_NONE:
166166               break;
167167            case BLDCNT_SFX_ALPHA:
168               if(gba_state->BLDCNT & top)
168               if(state->BLDCNT & top)
169169               {
170170                  UINT32 back = backdrop;
171171                  UINT8 top2 = 0x20;
r7509r7510
215215                     }
216216                  }
217217
218                  if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
218                  if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
219219                  {
220                     color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
220                     color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
221221                  }
222222               }
223223               break;
224224            case BLDCNT_SFX_LIGHTEN:
225               if(top & gba_state->BLDCNT)
225               if(top & state->BLDCNT)
226226               {
227                  color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
227                  color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
228228               }
229229               break;
230230            case BLDCNT_SFX_DARKEN:
231               if(top & gba_state->BLDCNT)
231               if(top & state->BLDCNT)
232232               {
233                  color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
233                  color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
234234               }
235235               break;
236236         }
r7509r7510
264264            top2 = 0x08;
265265         }
266266
267         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
267         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
268268         {
269            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
269            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
270270         }
271271         else
272272         {
273            switch(gba_state->BLDCNT & BLDCNT_SFX)
273            switch(state->BLDCNT & BLDCNT_SFX)
274274            {
275275               case BLDCNT_SFX_LIGHTEN:
276                  if(top & gba_state->BLDCNT)
276                  if(top & state->BLDCNT)
277277                  {
278                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
278                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
279279                  }
280280                  break;
281281               case BLDCNT_SFX_DARKEN:
282                  if(top & gba_state->BLDCNT)
282                  if(top & state->BLDCNT)
283283                  {
284                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
284                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
285285                  }
286286                  break;
287287            }
r7509r7510
291291   }
292292}
293293
294static void draw_mode0_scanline_all(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
294static void draw_mode0_scanline_all(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
295295{
296296   int x = 0;
297   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
297   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
298298   int inWindow0 = 0;
299299   int inWindow1 = 0;
300   UINT8 inWin0Mask = gba_state->WININ & 0x00ff;
301   UINT8 inWin1Mask = gba_state->WININ >> 8;
302   UINT8 outMask = gba_state->WINOUT & 0x00ff;
300   UINT8 inWin0Mask = state->WININ & 0x00ff;
301   UINT8 inWin1Mask = state->WININ >> 8;
302   UINT8 outMask = state->WINOUT & 0x00ff;
303303
304   if(gba_state->DISPCNT & DISPCNT_WIN0_EN)
304   if(state->DISPCNT & DISPCNT_WIN0_EN)
305305   {
306      UINT8 v0 = gba_state->WIN0V >> 8;
307      UINT8 v1 = gba_state->WIN0V & 0x00ff;
306      UINT8 v0 = state->WIN0V >> 8;
307      UINT8 v1 = state->WIN0V & 0x00ff;
308308      inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
309309      if(v1 >= v0)
310310      {
r7509r7510
316316      }
317317   }
318318
319   if(gba_state->DISPCNT & DISPCNT_WIN1_EN)
319   if(state->DISPCNT & DISPCNT_WIN1_EN)
320320   {
321      UINT8 v0 = gba_state->WIN1V >> 8;
322      UINT8 v1 = gba_state->WIN1V & 0x00ff;
321      UINT8 v0 = state->WIN1V >> 8;
322      UINT8 v1 = state->WIN1V & 0x00ff;
323323      inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
324324      if(v1 >= v0)
325325      {
r7509r7510
331331      }
332332   }
333333
334   draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS);
335   draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS);
336   draw_bg_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2HOFS, gba_state->BG2VOFS);
337   draw_bg_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3HOFS, gba_state->BG3VOFS);
338   draw_gba_oam(gba_state, machine, lineOBJ, y);
339   draw_gba_oam_window(gba_state, machine, lineOBJWin, y);
334   draw_bg_scanline(state, line0, y, DISPCNT_BG0_EN, state->BG0CNT, state->BG0HOFS, state->BG0VOFS);
335   draw_bg_scanline(state, line1, y, DISPCNT_BG1_EN, state->BG1CNT, state->BG1HOFS, state->BG1VOFS);
336   draw_bg_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2HOFS, state->BG2VOFS);
337   draw_bg_scanline(state, line3, y, DISPCNT_BG3_EN, state->BG3CNT, state->BG3HOFS, state->BG3VOFS);
338   draw_gba_oam(state, machine, lineOBJ, y);
339   draw_gba_oam_window(state, machine, lineOBJWin, y);
340340
341341   for(x = 0; x < 240; x++)
342342   {
r7509r7510
346346
347347      if((lineOBJWin[x] & 0x80000000) == 0)
348348      {
349         mask = gba_state->WINOUT >> 8;
349         mask = state->WINOUT >> 8;
350350      }
351351
352352      if(inWindow1)
353353      {
354         if(is_in_window(gba_state, x, 1))
354         if(is_in_window(state, x, 1))
355355         {
356356            mask = inWin1Mask;
357357         }
r7509r7510
359359
360360      if(inWindow0)
361361      {
362         if(is_in_window(gba_state, x, 0))
362         if(is_in_window(state, x, 0))
363363         {
364364            mask = inWin0Mask;
365365         }
r7509r7510
399399      {
400400         if((color & 0x00010000) == 0)
401401         {
402            switch(gba_state->BLDCNT & BLDCNT_SFX)
402            switch(state->BLDCNT & BLDCNT_SFX)
403403            {
404404               case BLDCNT_SFX_NONE:
405405                  break;
406406               case BLDCNT_SFX_ALPHA:
407407               {
408                  if(top & gba_state->BLDCNT)
408                  if(top & state->BLDCNT)
409409                  {
410410                     UINT32 back = backdrop;
411411                     UINT8 top2 = 0x20;
r7509r7510
454454                        }
455455                     }
456456
457                     if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
457                     if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
458458                     {
459                        color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
459                        color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
460460                     }
461461                  }
462462                  break;
463463               }
464464               case BLDCNT_SFX_LIGHTEN:
465                  if(top & gba_state->BLDCNT)
465                  if(top & state->BLDCNT)
466466                  {
467                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
467                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
468468                  }
469469                  break;
470470               case BLDCNT_SFX_DARKEN:
471                  if(top & gba_state->BLDCNT)
471                  if(top & state->BLDCNT)
472472                  {
473                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
473                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
474474                  }
475475                  break;
476476            }
r7509r7510
504504               top2 = 0x08;
505505            }
506506
507            if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
507            if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
508508            {
509               color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
509               color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
510510            }
511511            else
512512            {
513               switch(gba_state->BLDCNT & BLDCNT_SFX)
513               switch(state->BLDCNT & BLDCNT_SFX)
514514               {
515515                  case BLDCNT_SFX_LIGHTEN:
516                     if(top & gba_state->BLDCNT)
516                     if(top & state->BLDCNT)
517517                     {
518                        color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
518                        color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
519519                     }
520520                     break;
521521                  case BLDCNT_SFX_DARKEN:
522                     if(top & gba_state->BLDCNT)
522                     if(top & state->BLDCNT)
523523                     {
524                        color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
524                        color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
525525                     }
526526                     break;
527527               }
r7509r7510
557557            top2 = 0x08;
558558         }
559559
560         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
560         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
561561         {
562            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
562            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
563563         }
564564         else
565565         {
566            switch(gba_state->BLDCNT & BLDCNT_SFX)
566            switch(state->BLDCNT & BLDCNT_SFX)
567567            {
568568               case BLDCNT_SFX_LIGHTEN:
569                  if(top & gba_state->BLDCNT)
569                  if(top & state->BLDCNT)
570570                  {
571                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
571                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
572572                  }
573573                  break;
574574               case BLDCNT_SFX_DARKEN:
575                  if(top & gba_state->BLDCNT)
575                  if(top & state->BLDCNT)
576576                  {
577                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
577                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
578578                  }
579579                  break;
580580            }
src/mess/video/gbamode1.c
r7509r7510
88
99***************************************************************************/
1010
11static void draw_mode1_scanline(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
11static void draw_mode1_scanline(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
1212{
1313   int x = 0;
14   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
14   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
1515
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);
16   draw_bg_scanline(state, line0, y, DISPCNT_BG0_EN, state->BG0CNT, state->BG0HOFS, state->BG0VOFS);
17   draw_bg_scanline(state, line1, y, DISPCNT_BG1_EN, state->BG1CNT, state->BG1HOFS, state->BG1VOFS);
18   draw_roz_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2X, state->BG2Y, state->BG2PA, state->BG2PB, state->BG2PC, state->BG2PD, &state->gfxBG2X, &state->gfxBG2Y, state->gfxBG2Changed);
19   draw_gba_oam(state, machine, lineOBJ, y);
2020
2121   for(x = 0; x < 240; x++)
2222   {
r7509r7510
7070            top2 = 0x04;
7171         }
7272
73         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
73         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
7474         {
75            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
75            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
7676         }
7777         else
7878         {
79            switch(gba_state->BLDCNT & BLDCNT_SFX)
79            switch(state->BLDCNT & BLDCNT_SFX)
8080            {
8181               case BLDCNT_SFX_LIGHTEN:
82                  if(top & gba_state->BLDCNT)
82                  if(top & state->BLDCNT)
8383                  {
84                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
84                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
8585                  }
8686                  break;
8787               case BLDCNT_SFX_DARKEN:
88                  if(top & gba_state->BLDCNT)
88                  if(top & state->BLDCNT)
8989                  {
90                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
90                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
9191                  }
9292                  break;
9393            }
r7509r7510
9696
9797      lineMix[x] = color;
9898   }
99   gba_state->gfxBG2Changed = 0;
99   state->gfxBG2Changed = 0;
100100}
101101
102static void draw_mode1_scanline_nowindow(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
102static void draw_mode1_scanline_nowindow(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
103103{
104104   int x = 0;
105   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
106   int effect = gba_state->BLDCNT & BLDCNT_SFX;
105   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
106   int effect = state->BLDCNT & BLDCNT_SFX;
107107
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);
108   draw_bg_scanline(state, line0, y, DISPCNT_BG0_EN, state->BG0CNT, state->BG0HOFS, state->BG0VOFS);
109   draw_bg_scanline(state, line1, y, DISPCNT_BG1_EN, state->BG1CNT, state->BG1HOFS, state->BG1VOFS);
110   draw_roz_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2X, state->BG2Y, state->BG2PA, state->BG2PB, state->BG2PC, state->BG2PD, &state->gfxBG2X, &state->gfxBG2Y, state->gfxBG2Changed);
111   draw_gba_oam(state, machine, lineOBJ, y);
112112
113113   for(x = 0; x < 240; x++)
114114   {
r7509r7510
146146            case BLDCNT_SFX_NONE:
147147               break;
148148            case BLDCNT_SFX_ALPHA:
149               if(gba_state->BLDCNT & top)
149               if(state->BLDCNT & top)
150150               {
151151                  UINT32 back = backdrop;
152152                  UINT8 top2 = 0x20;
r7509r7510
187187                     }
188188                  }
189189
190                  if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
190                  if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
191191                  {
192                     color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
192                     color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
193193                  }
194194               }
195195               break;
196196            case BLDCNT_SFX_LIGHTEN:
197               if(top & gba_state->BLDCNT)
197               if(top & state->BLDCNT)
198198               {
199                  color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
199                  color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
200200               }
201201               break;
202202            case BLDCNT_SFX_DARKEN:
203               if(top & gba_state->BLDCNT)
203               if(top & state->BLDCNT)
204204               {
205                  color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
205                  color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
206206               }
207207               break;
208208         }
r7509r7510
230230            top2 = 0x04;
231231         }
232232
233         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
233         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
234234         {
235            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
235            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
236236         }
237237         else
238238         {
239            switch(gba_state->BLDCNT & BLDCNT_SFX)
239            switch(state->BLDCNT & BLDCNT_SFX)
240240            {
241241               case BLDCNT_SFX_LIGHTEN:
242                  if(top & gba_state->BLDCNT)
242                  if(top & state->BLDCNT)
243243                  {
244                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
244                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
245245                  }
246246                  break;
247247               case BLDCNT_SFX_DARKEN:
248                  if(top & gba_state->BLDCNT)
248                  if(top & state->BLDCNT)
249249                  {
250                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
250                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
251251                  }
252252                  break;
253253            }
r7509r7510
255255      }
256256      lineMix[x] = color;
257257   }
258   gba_state->gfxBG2Changed = 0;
258   state->gfxBG2Changed = 0;
259259}
260260
261static void draw_mode1_scanline_all(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
261static void draw_mode1_scanline_all(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
262262{
263263   int x = 0;
264   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
264   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
265265   int inWindow0 = 0;
266266   int inWindow1 = 0;
267   UINT8 inWin0Mask = gba_state->WININ & 0x00ff;
268   UINT8 inWin1Mask = gba_state->WININ >> 8;
269   UINT8 outMask = gba_state->WINOUT & 0x00ff;
267   UINT8 inWin0Mask = state->WININ & 0x00ff;
268   UINT8 inWin1Mask = state->WININ >> 8;
269   UINT8 outMask = state->WINOUT & 0x00ff;
270270
271   if(gba_state->DISPCNT & DISPCNT_WIN0_EN)
271   if(state->DISPCNT & DISPCNT_WIN0_EN)
272272   {
273      UINT8 v0 = gba_state->WIN0V >> 8;
274      UINT8 v1 = gba_state->WIN0V & 0x00ff;
273      UINT8 v0 = state->WIN0V >> 8;
274      UINT8 v1 = state->WIN0V & 0x00ff;
275275      inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
276276      if(v1 >= v0)
277277      {
r7509r7510
283283      }
284284   }
285285
286   if(gba_state->DISPCNT & DISPCNT_WIN1_EN)
286   if(state->DISPCNT & DISPCNT_WIN1_EN)
287287   {
288      UINT8 v0 = gba_state->WIN1V >> 8;
289      UINT8 v1 = gba_state->WIN1V & 0x00ff;
288      UINT8 v0 = state->WIN1V >> 8;
289      UINT8 v1 = state->WIN1V & 0x00ff;
290290      inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
291291      if(v1 >= v0)
292292      {
r7509r7510
298298      }
299299   }
300300
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);
301   draw_bg_scanline(state, line0, y, DISPCNT_BG0_EN, state->BG0CNT, state->BG0HOFS, state->BG0VOFS);
302   draw_bg_scanline(state, line1, y, DISPCNT_BG1_EN, state->BG1CNT, state->BG1HOFS, state->BG1VOFS);
303   draw_roz_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2X, state->BG2Y, state->BG2PA, state->BG2PB, state->BG2PC, state->BG2PD, &state->gfxBG2X, &state->gfxBG2Y, state->gfxBG2Changed);
304   draw_gba_oam(state, machine, lineOBJ, y);
305   draw_gba_oam_window(state, machine, lineOBJWin, y);
306306
307307   for(x = 0; x < 240; x++)
308308   {
r7509r7510
312312
313313      if((lineOBJWin[x] & 0x80000000) == 0)
314314      {
315         mask = gba_state->WINOUT >> 8;
315         mask = state->WINOUT >> 8;
316316      }
317317
318318      if(inWindow1)
319319      {
320         if(is_in_window(gba_state, x, 1))
320         if(is_in_window(state, x, 1))
321321         {
322322            mask = inWin1Mask;
323323         }
r7509r7510
325325
326326      if(inWindow0)
327327      {
328         if(is_in_window(gba_state, x, 0))
328         if(is_in_window(state, x, 0))
329329         {
330330            mask = inWin0Mask;
331331         }
r7509r7510
359359      {
360360         if((color & 0x00010000) == 0)
361361         {
362            switch(gba_state->BLDCNT & BLDCNT_SFX)
362            switch(state->BLDCNT & BLDCNT_SFX)
363363            {
364364               case BLDCNT_SFX_NONE:
365365                  break;
366366               case BLDCNT_SFX_ALPHA:
367367               {
368                  if(top & gba_state->BLDCNT)
368                  if(top & state->BLDCNT)
369369                  {
370370                     UINT32 back = backdrop;
371371                     UINT8 top2 = 0x20;
r7509r7510
405405                        }
406406                     }
407407
408                     if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
408                     if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
409409                     {
410                        color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
410                        color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
411411                     }
412412                  }
413413                  break;
414414               }
415415               case BLDCNT_SFX_LIGHTEN:
416                  if(top & gba_state->BLDCNT)
416                  if(top & state->BLDCNT)
417417                  {
418                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
418                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
419419                  }
420420                  break;
421421               case BLDCNT_SFX_DARKEN:
422                  if(top & gba_state->BLDCNT)
422                  if(top & state->BLDCNT)
423423                  {
424                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
424                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
425425                  }
426426                  break;
427427            }
r7509r7510
449449               top2 = 0x04;
450450            }
451451
452            if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
452            if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
453453            {
454               color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
454               color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
455455            }
456456            else
457457            {
458               switch(gba_state->BLDCNT & BLDCNT_SFX)
458               switch(state->BLDCNT & BLDCNT_SFX)
459459               {
460460                  case BLDCNT_SFX_LIGHTEN:
461                     if(top & gba_state->BLDCNT)
461                     if(top & state->BLDCNT)
462462                     {
463                        color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
463                        color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
464464                     }
465465                     break;
466466                  case BLDCNT_SFX_DARKEN:
467                     if(top & gba_state->BLDCNT)
467                     if(top & state->BLDCNT)
468468                     {
469                        color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
469                        color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
470470                     }
471471                     break;
472472               }
r7509r7510
496496            top2 = 0x04;
497497         }
498498
499         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
499         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
500500         {
501            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
501            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
502502         }
503503         else
504504         {
505            switch(gba_state->BLDCNT & BLDCNT_SFX)
505            switch(state->BLDCNT & BLDCNT_SFX)
506506            {
507507               case BLDCNT_SFX_LIGHTEN:
508                  if(top & gba_state->BLDCNT)
508                  if(top & state->BLDCNT)
509509                  {
510                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
510                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
511511                  }
512512                  break;
513513               case BLDCNT_SFX_DARKEN:
514                  if(top & gba_state->BLDCNT)
514                  if(top & state->BLDCNT)
515515                  {
516                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
516                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
517517                  }
518518                  break;
519519            }
r7509r7510
521521      }
522522      lineMix[x] = color;
523523   }
524   gba_state->gfxBG2Changed = 0;
524   state->gfxBG2Changed = 0;
525525}
src/mess/video/gbam345.c
r7509r7510
88
99***************************************************************************/
1010
11static void draw_roz_bitmap_mode_scanline(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
11static void draw_roz_bitmap_mode_scanline(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
1212{
1313   int x = 0;
14   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
14   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
1515
1616   if(bpp == 4)
1717   {
1818      fatalerror( "Screen mode 5 is not fully supported yet, contact MESSdev!\n" );
1919   }
2020
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);
21   draw_roz_bitmap_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2X, state->BG2Y, state->BG2PA, state->BG2PB, state->BG2PC, state->BG2PD, &state->gfxBG2X, &state->gfxBG2Y, state->gfxBG2Changed, bpp);
22   draw_gba_oam(state, machine, lineOBJ, y);
2323
2424   for(x = 0; x < 240; x++)
2525   {
r7509r7510
4949            top2 = 0x04;
5050         }
5151
52         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
52         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
5353         {
54            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
54            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
5555         }
5656         else
5757         {
58            switch(gba_state->BLDCNT & BLDCNT_SFX)
58            switch(state->BLDCNT & BLDCNT_SFX)
5959            {
6060               case BLDCNT_SFX_LIGHTEN:
61                  if(top & gba_state->BLDCNT)
61                  if(top & state->BLDCNT)
6262                  {
63                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
63                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
6464                  }
6565                  break;
6666               case BLDCNT_SFX_DARKEN:
67                  if(top & gba_state->BLDCNT)
67                  if(top & state->BLDCNT)
6868                  {
69                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
69                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
7070                  }
7171                  break;
7272            }
r7509r7510
7575
7676      lineMix[x] = color;
7777   }
78   gba_state->gfxBG2Changed = 0;
78   state->gfxBG2Changed = 0;
7979}
8080
81static void draw_roz_bitmap_mode_scanline_nowindow(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
81static void draw_roz_bitmap_mode_scanline_nowindow(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
8282{
8383   int x = 0;
84   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
85   int effect = gba_state->BLDCNT & BLDCNT_SFX;
84   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
85   int effect = state->BLDCNT & BLDCNT_SFX;
8686
8787   if(bpp == 4)
8888   {
8989      fatalerror( "Screen mode 5 is not fully supported yet, contact MESSdev!\n" );
9090   }
9191
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);
92   draw_roz_bitmap_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2X, state->BG2Y, state->BG2PA, state->BG2PB, state->BG2PC, state->BG2PD, &state->gfxBG2X, &state->gfxBG2Y, state->gfxBG2Changed, bpp);
93   draw_gba_oam(state, machine, lineOBJ, y);
9494
9595   for(x = 0; x < 240; x++)
9696   {
r7509r7510
116116            case BLDCNT_SFX_NONE:
117117               break;
118118            case BLDCNT_SFX_ALPHA:
119               if(gba_state->BLDCNT & top)
119               if(state->BLDCNT & top)
120120               {
121121                  UINT32 back = backdrop;
122122                  UINT8 top2 = 0x20;
r7509r7510
139139                     }
140140                  }
141141
142                  if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
142                  if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
143143                  {
144                     color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
144                     color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
145145                  }
146146               }
147147               break;
148148            case BLDCNT_SFX_LIGHTEN:
149               if(top & gba_state->BLDCNT)
149               if(top & state->BLDCNT)
150150               {
151                  color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
151                  color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
152152               }
153153               break;
154154            case BLDCNT_SFX_DARKEN:
155               if(top & gba_state->BLDCNT)
155               if(top & state->BLDCNT)
156156               {
157                  color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
157                  color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
158158               }
159159               break;
160160         }
r7509r7510
170170            top2 = 0x04;
171171         }
172172
173         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
173         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
174174         {
175            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
175            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
176176         }
177177         else
178178         {
179            switch(gba_state->BLDCNT & BLDCNT_SFX)
179            switch(state->BLDCNT & BLDCNT_SFX)
180180            {
181181               case BLDCNT_SFX_LIGHTEN:
182                  if(top & gba_state->BLDCNT)
182                  if(top & state->BLDCNT)
183183                  {
184                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
184                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
185185                  }
186186                  break;
187187               case BLDCNT_SFX_DARKEN:
188                  if(top & gba_state->BLDCNT)
188                  if(top & state->BLDCNT)
189189                  {
190                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
190                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
191191                  }
192192                  break;
193193            }
r7509r7510
195195      }
196196      lineMix[x] = color;
197197   }
198   gba_state->gfxBG2Changed = 0;
198   state->gfxBG2Changed = 0;
199199}
200200
201static void draw_roz_bitmap_mode_scanline_all(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
201static void draw_roz_bitmap_mode_scanline_all(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
202202{
203203   int x = 0;
204   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
204   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
205205   int inWindow0 = 0;
206206   int inWindow1 = 0;
207   UINT8 inWin0Mask = gba_state->WININ & 0x00ff;
208   UINT8 inWin1Mask = gba_state->WININ >> 8;
209   UINT8 outMask = gba_state->WINOUT & 0x00ff;
207   UINT8 inWin0Mask = state->WININ & 0x00ff;
208   UINT8 inWin1Mask = state->WININ >> 8;
209   UINT8 outMask = state->WINOUT & 0x00ff;
210210
211211   if(bpp == 4)
212212   {
213213      fatalerror( "Screen mode 5 is not fully supported yet, contact MESSdev!\n" );
214214   }
215215
216   if(gba_state->DISPCNT & DISPCNT_WIN0_EN)
216   if(state->DISPCNT & DISPCNT_WIN0_EN)
217217   {
218      UINT8 v0 = gba_state->WIN0V >> 8;
219      UINT8 v1 = gba_state->WIN0V & 0x00ff;
218      UINT8 v0 = state->WIN0V >> 8;
219      UINT8 v1 = state->WIN0V & 0x00ff;
220220      inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
221221      if(v1 >= v0)
222222      {
r7509r7510
228228      }
229229   }
230230
231   if(gba_state->DISPCNT & DISPCNT_WIN1_EN)
231   if(state->DISPCNT & DISPCNT_WIN1_EN)
232232   {
233      UINT8 v0 = gba_state->WIN1V >> 8;
234      UINT8 v1 = gba_state->WIN1V & 0x00ff;
233      UINT8 v0 = state->WIN1V >> 8;
234      UINT8 v1 = state->WIN1V & 0x00ff;
235235      inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
236236      if(v1 >= v0)
237237      {
r7509r7510
243243      }
244244   }
245245
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);
246   draw_roz_bitmap_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2X, state->BG2Y, state->BG2PA, state->BG2PB, state->BG2PC, state->BG2PD, &state->gfxBG2X, &state->gfxBG2Y, state->gfxBG2Changed, bpp);
247   draw_gba_oam(state, machine, lineOBJ, y);
248   draw_gba_oam_window(state, machine, lineOBJWin, y);
249249
250250   for(x = 0; x < 240; x++)
251251   {
r7509r7510
255255
256256      if((lineOBJWin[x] & 0x80000000) == 0)
257257      {
258         mask = gba_state->WINOUT >> 8;
258         mask = state->WINOUT >> 8;
259259      }
260260
261261      if(inWindow1)
262262      {
263         if(is_in_window(gba_state, x, 1))
263         if(is_in_window(state, x, 1))
264264         {
265265            mask = inWin1Mask;
266266         }
r7509r7510
268268
269269      if(inWindow0)
270270      {
271         if(is_in_window(gba_state, x, 0))
271         if(is_in_window(state, x, 0))
272272         {
273273            mask = inWin0Mask;
274274         }
r7509r7510
290290      {
291291         if((color & 0x00010000) == 0)
292292         {
293            switch(gba_state->BLDCNT & BLDCNT_SFX)
293            switch(state->BLDCNT & BLDCNT_SFX)
294294            {
295295               case BLDCNT_SFX_NONE:
296296                  break;
297297               case BLDCNT_SFX_ALPHA:
298298               {
299                  if(top & gba_state->BLDCNT)
299                  if(top & state->BLDCNT)
300300                  {
301301                     UINT32 back = backdrop;
302302                     UINT8 top2 = 0x20;
r7509r7510
318318                        }
319319                     }
320320
321                     if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
321                     if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
322322                     {
323                        color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
323                        color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
324324                     }
325325                  }
326326                  break;
327327               }
328328               case BLDCNT_SFX_LIGHTEN:
329                  if(top & gba_state->BLDCNT)
329                  if(top & state->BLDCNT)
330330                  {
331                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
331                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
332332                  }
333333                  break;
334334               case BLDCNT_SFX_DARKEN:
335                  if(top & gba_state->BLDCNT)
335                  if(top & state->BLDCNT)
336336                  {
337                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
337                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
338338                  }
339339                  break;
340340            }
r7509r7510
350350               top2 = 0x04;
351351            }
352352
353            if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
353            if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
354354            {
355               color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
355               color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
356356            }
357357            else
358358            {
359               switch(gba_state->BLDCNT & BLDCNT_SFX)
359               switch(state->BLDCNT & BLDCNT_SFX)
360360               {
361361                  case BLDCNT_SFX_LIGHTEN:
362                     if(top & gba_state->BLDCNT)
362                     if(top & state->BLDCNT)
363363                     {
364                        color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
364                        color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
365365                     }
366366                     break;
367367                  case BLDCNT_SFX_DARKEN:
368                     if(top & gba_state->BLDCNT)
368                     if(top & state->BLDCNT)
369369                     {
370                        color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
370                        color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
371371                     }
372372                     break;
373373               }
r7509r7510
385385            top2 = 0x04;
386386         }
387387
388         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
388         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
389389         {
390            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
390            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
391391         }
392392         else
393393         {
394            switch(gba_state->BLDCNT & BLDCNT_SFX)
394            switch(state->BLDCNT & BLDCNT_SFX)
395395            {
396396               case BLDCNT_SFX_LIGHTEN:
397                  if(top & gba_state->BLDCNT)
397                  if(top & state->BLDCNT)
398398                  {
399                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
399                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
400400                  }
401401                  break;
402402               case BLDCNT_SFX_DARKEN:
403                  if(top & gba_state->BLDCNT)
403                  if(top & state->BLDCNT)
404404                  {
405                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
405                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
406406                  }
407407                  break;
408408            }
r7509r7510
410410      }
411411      lineMix[x] = color;
412412   }
413   gba_state->gfxBG2Changed = 0;
413   state->gfxBG2Changed = 0;
414414}
src/mess/video/gbamode2.c
r7509r7510
88
99***************************************************************************/
1010
11static void draw_mode2_scanline(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
11static void draw_mode2_scanline(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
1212{
1313   int x = 0;
14   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
14   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
1515
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);
16   draw_roz_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2X, state->BG2Y, state->BG2PA, state->BG2PB, state->BG2PC, state->BG2PD, &state->gfxBG2X, &state->gfxBG2Y, state->gfxBG2Changed);
17   draw_roz_scanline(state, line3, y, DISPCNT_BG3_EN, state->BG3CNT, state->BG3X, state->BG3Y, state->BG3PA, state->BG3PB, state->BG3PC, state->BG3PD, &state->gfxBG3X, &state->gfxBG3Y, state->gfxBG3Changed);
18   draw_gba_oam(state, machine, lineOBJ, y);
1919
2020   for(x = 0; x < 240; x++)
2121   {
r7509r7510
5757            top2 = 0x08;
5858         }
5959
60         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
60         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
6161         {
62            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
62            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
6363         }
6464         else
6565         {
66            switch(gba_state->BLDCNT & BLDCNT_SFX)
66            switch(state->BLDCNT & BLDCNT_SFX)
6767            {
6868               case BLDCNT_SFX_LIGHTEN:
69                  if(top & gba_state->BLDCNT)
69                  if(top & state->BLDCNT)
7070                  {
71                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
71                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
7272                  }
7373                  break;
7474               case BLDCNT_SFX_DARKEN:
75                  if(top & gba_state->BLDCNT)
75                  if(top & state->BLDCNT)
7676                  {
77                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
77                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
7878                  }
7979                  break;
8080            }
r7509r7510
8383
8484      lineMix[x] = color;
8585   }
86   gba_state->gfxBG2Changed = 0;
87   gba_state->gfxBG3Changed = 0;
86   state->gfxBG2Changed = 0;
87   state->gfxBG3Changed = 0;
8888}
8989
90static void draw_mode2_scanline_nowindow(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
90static void draw_mode2_scanline_nowindow(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
9191{
9292   int x = 0;
93   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
94   int effect = gba_state->BLDCNT & BLDCNT_SFX;
93   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
94   int effect = state->BLDCNT & BLDCNT_SFX;
9595
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);
96   draw_roz_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2X, state->BG2Y, state->BG2PA, state->BG2PB, state->BG2PC, state->BG2PD, &state->gfxBG2X, &state->gfxBG2Y, state->gfxBG2Changed);
97   draw_roz_scanline(state, line3, y, DISPCNT_BG3_EN, state->BG3CNT, state->BG3X, state->BG3Y, state->BG3PA, state->BG3PB, state->BG3PC, state->BG3PD, &state->gfxBG3X, &state->gfxBG3Y, state->gfxBG3Changed);
98   draw_gba_oam(state, machine, lineOBJ, y);
9999
100100   for(x = 0; x < 240; x++)
101101   {
r7509r7510
127127            case BLDCNT_SFX_NONE:
128128               break;
129129            case BLDCNT_SFX_ALPHA:
130               if(gba_state->BLDCNT & top)
130               if(state->BLDCNT & top)
131131               {
132132                  UINT32 back = backdrop;
133133                  UINT8 top2 = 0x20;
r7509r7510
159159                     }
160160                  }
161161
162                  if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
162                  if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
163163                  {
164                     color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
164                     color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
165165                  }
166166               }
167167               break;
168168            case BLDCNT_SFX_LIGHTEN:
169               if(top & gba_state->BLDCNT)
169               if(top & state->BLDCNT)
170170               {
171                  color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
171                  color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
172172               }
173173               break;
174174            case BLDCNT_SFX_DARKEN:
175               if(top & gba_state->BLDCNT)
175               if(top & state->BLDCNT)
176176               {
177                  color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
177                  color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
178178               }
179179               break;
180180         }
r7509r7510
196196            top2 = 0x08;
197197         }
198198
199         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
199         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
200200         {
201            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
201            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
202202         }
203203         else
204204         {
205            switch(gba_state->BLDCNT & BLDCNT_SFX)
205            switch(state->BLDCNT & BLDCNT_SFX)
206206            {
207207               case BLDCNT_SFX_LIGHTEN:
208                  if(top & gba_state->BLDCNT)
208                  if(top & state->BLDCNT)
209209                  {
210                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
210                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
211211                  }
212212                  break;
213213               case BLDCNT_SFX_DARKEN:
214                  if(top & gba_state->BLDCNT)
214                  if(top & state->BLDCNT)
215215                  {
216                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
216                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
217217                  }
218218                  break;
219219            }
r7509r7510
221221      }
222222      lineMix[x] = color;
223223   }
224   gba_state->gfxBG2Changed = 0;
225   gba_state->gfxBG3Changed = 0;
224   state->gfxBG2Changed = 0;
225   state->gfxBG3Changed = 0;
226226}
227227
228static void draw_mode2_scanline_all(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
228static void draw_mode2_scanline_all(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
229229{
230230   int x = 0;
231   UINT32 backdrop = ((UINT16*)gba_state->gba_pram)[0] | 0x30000000;
231   UINT32 backdrop = ((UINT16*)state->gba_pram)[0] | 0x30000000;
232232   int inWindow0 = 0;
233233   int inWindow1 = 0;
234   UINT8 inWin0Mask = gba_state->WININ & 0x00ff;
235   UINT8 inWin1Mask = gba_state->WININ >> 8;
236   UINT8 outMask = gba_state->WINOUT & 0x00ff;
234   UINT8 inWin0Mask = state->WININ & 0x00ff;
235   UINT8 inWin1Mask = state->WININ >> 8;
236   UINT8 outMask = state->WINOUT & 0x00ff;
237237
238   if(gba_state->DISPCNT & DISPCNT_WIN0_EN)
238   if(state->DISPCNT & DISPCNT_WIN0_EN)
239239   {
240      UINT8 v0 = gba_state->WIN0V >> 8;
241      UINT8 v1 = gba_state->WIN0V & 0x00ff;
240      UINT8 v0 = state->WIN0V >> 8;
241      UINT8 v1 = state->WIN0V & 0x00ff;
242242      inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
243243      if(v1 >= v0)
244244      {
r7509r7510
250250      }
251251   }
252252
253   if(gba_state->DISPCNT & DISPCNT_WIN1_EN)
253   if(state->DISPCNT & DISPCNT_WIN1_EN)
254254   {
255      UINT8 v0 = gba_state->WIN1V >> 8;
256      UINT8 v1 = gba_state->WIN1V & 0x00ff;
255      UINT8 v0 = state->WIN1V >> 8;
256      UINT8 v1 = state->WIN1V & 0x00ff;
257257      inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
258258      if(v1 >= v0)
259259      {
r7509r7510
265265      }
266266   }
267267
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);
268   draw_roz_scanline(state, line2, y, DISPCNT_BG2_EN, state->BG2CNT, state->BG2X, state->BG2Y, state->BG2PA, state->BG2PB, state->BG2PC, state->BG2PD, &state->gfxBG2X, &state->gfxBG2Y, state->gfxBG2Changed);
269   draw_roz_scanline(state, line3, y, DISPCNT_BG3_EN, state->BG3CNT, state->BG3X, state->BG3Y, state->BG3PA, state->BG3PB, state->BG3PC, state->BG3PD, &state->gfxBG3X, &state->gfxBG3Y, state->gfxBG3Changed);
270   draw_gba_oam(state, machine, lineOBJ, y);
271   draw_gba_oam_window(state, machine, lineOBJWin, y);
272272
273273   for(x = 0; x < 240; x++)
274274   {
r7509r7510
278278
279279      if((lineOBJWin[x] & 0x80000000) == 0)
280280      {
281         mask = gba_state->WINOUT >> 8;
281         mask = state->WINOUT >> 8;
282282      }
283283
284284      if(inWindow1)
285285      {
286         if(is_in_window(gba_state, x, 1))
286         if(is_in_window(state, x, 1))
287287         {
288288            mask = inWin1Mask;
289289         }
r7509r7510
291291
292292      if(inWindow0)
293293      {
294         if(is_in_window(gba_state, x, 0))
294         if(is_in_window(state, x, 0))
295295         {
296296            mask = inWin0Mask;
297297         }
r7509r7510
319319      {
320320         if((color & 0x00010000) == 0)
321321         {
322            switch(gba_state->BLDCNT & BLDCNT_SFX)
322            switch(state->BLDCNT & BLDCNT_SFX)
323323            {
324324               case BLDCNT_SFX_NONE:
325325                  break;
326326               case BLDCNT_SFX_ALPHA:
327327               {
328                  if(top & gba_state->BLDCNT)
328                  if(top & state->BLDCNT)
329329                  {
330330                     UINT32 back = backdrop;
331331                     UINT8 top2 = 0x20;
r7509r7510
356356                        }
357357                     }
358358
359                     if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
359                     if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
360360                     {
361                        color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
361                        color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
362362                     }
363363                  }
364364                  break;
365365               }
366366               case BLDCNT_SFX_LIGHTEN:
367                  if(top & gba_state->BLDCNT)
367                  if(top & state->BLDCNT)
368368                  {
369                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
369                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
370370                  }
371371                  break;
372372               case BLDCNT_SFX_DARKEN:
373                  if(top & gba_state->BLDCNT)
373                  if(top & state->BLDCNT)
374374                  {
375                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
375                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
376376                  }
377377                  break;
378378            }
r7509r7510
394394               top2 = 0x08;
395395            }
396396
397            if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
397            if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
398398            {
399               color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
399               color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
400400            }
401401            else
402402            {
403               switch(gba_state->BLDCNT & BLDCNT_SFX)
403               switch(state->BLDCNT & BLDCNT_SFX)
404404               {
405405                  case BLDCNT_SFX_LIGHTEN:
406                     if(top & gba_state->BLDCNT)
406                     if(top & state->BLDCNT)
407407                     {
408                        color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
408                        color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
409409                     }
410410                     break;
411411                  case BLDCNT_SFX_DARKEN:
412                     if(top & gba_state->BLDCNT)
412                     if(top & state->BLDCNT)
413413                     {
414                        color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
414                        color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
415415                     }
416416                     break;
417417               }
r7509r7510
435435            top2 = 0x08;
436436         }
437437
438         if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT))
438         if(top2 & (state->BLDCNT >> BLDCNT_TP2_SHIFT))
439439         {
440            color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]);
440            color = alpha_blend_pixel(color, back, coeff[state->BLDALPHA & 0x1f], coeff[(state->BLDALPHA >> 8) & 0x1f]);
441441         }
442442         else
443443         {
444            switch(gba_state->BLDCNT & BLDCNT_SFX)
444            switch(state->BLDCNT & BLDCNT_SFX)
445445            {
446446               case BLDCNT_SFX_LIGHTEN:
447                  if(top & gba_state->BLDCNT)
447                  if(top & state->BLDCNT)
448448                  {
449                     color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]);
449                     color = increase_brightness(color, coeff[state->BLDY & 0x1f]);
450450                  }
451451                  break;
452452               case BLDCNT_SFX_DARKEN:
453                  if(top & gba_state->BLDCNT)
453                  if(top & state->BLDCNT)
454454                  {
455                     color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]);
455                     color = decrease_brightness(color, coeff[state->BLDY & 0x1f]);
456456                  }
457457                  break;
458458            }
r7509r7510
460460      }
461461      lineMix[x] = color;
462462   }
463   gba_state->gfxBG2Changed = 0;
464   gba_state->gfxBG3Changed = 0;
463   state->gfxBG2Changed = 0;
464   state->gfxBG3Changed = 0;
465465}
src/mess/video/gba.c
r7509r7510
3333};
3434
3535/* Drawing functions */
36static void draw_roz_bitmap_scanline(gba_state_t *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_t *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_t *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs);
39static void draw_gba_oam_window(gba_state_t *gba_state, running_machine *machine, UINT32 *scanline, int y);
40static void draw_gba_oam(gba_state_t *gba_state, running_machine *machine, UINT32 *scanline, int y);
41static void invalid_gba_draw_function(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux);
36static void draw_roz_bitmap_scanline(gba_state *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 *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 *state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs);
39static void draw_gba_oam_window(gba_state *state, running_machine *machine, UINT32 *scanline, int y);
40static void draw_gba_oam(gba_state *state, running_machine *machine, UINT32 *scanline, int y);
41static void invalid_gba_draw_function(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux);
4242
4343/* Utility functions */
44INLINE int is_in_window(gba_state_t *gba_state, int x, int window);
44INLINE int is_in_window(gba_state *state, int x, int window);
4545INLINE UINT32 alpha_blend_pixel(UINT32 color0, UINT32 color1, int ca, int cb);
4646INLINE UINT32 increase_brightness(UINT32 color, int coeff_);
4747INLINE UINT32 decrease_brightness(UINT32 color, int coeff_);
r7509r7510
5151#include "gbamode2.c"
5252#include "gbam345.c"
5353
54static void (*const gba_draw_scanline_modes[8][3])(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux) =
54static void (*const gba_draw_scanline_modes[8][3])(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux) =
5555{
5656   /* All modes have three sub-modes: No effects, effects, and windowed effects. */
5757   {   /* Mode 0: 4 non-rotatable tilemaps and 1 OAM layer */
r7509r7510
9696   },
9797};
9898
99static void invalid_gba_draw_function(running_machine *machine, gba_state_t *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux)
99static void invalid_gba_draw_function(running_machine *machine, gba_state *state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux)
100100{
101101   fatalerror( "Invalid screen mode (6 or 7)!\n" );
102102}
103103
104static void draw_roz_bitmap_scanline(gba_state_t *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)
104static void draw_roz_bitmap_scanline(gba_state *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)
105105{
106   UINT8 *src8 = (UINT8 *)gba_state->gba_vram;
107   UINT16 *src16 = (UINT16 *)gba_state->gba_vram;
108   UINT16 *palette = (UINT16 *)gba_state->gba_pram;
106   UINT8 *src8 = (UINT8 *)state->gba_vram;
107   UINT16 *src16 = (UINT16 *)state->gba_vram;
108   UINT16 *palette = (UINT16 *)state->gba_pram;
109109   INT32 sx = 240;
110110   INT32 sy = 160;
111111   UINT32 prio = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000;
r7509r7510
114114
115115   if(depth == 8)
116116   {
117      if(gba_state->DISPCNT & DISPCNT_FRAMESEL)
117      if(state->DISPCNT & DISPCNT_FRAMESEL)
118118      {
119119         src8 += 0xa000;
120120      }
r7509r7510
164164
165165   if(ctrl & BGCNT_MOSAIC)
166166   {
167      INT32 mosaic_line = ((gba_state->MOSAIC & 0x00f0) >> 4) + 1;
167      INT32 mosaic_line = ((state->MOSAIC & 0x00f0) >> 4) + 1;
168168      INT32 tempy = (ypos / mosaic_line) * mosaic_line;
169169      rx = startx + tempy*dmx;
170170      ry = starty + tempy*dmy;
r7509r7510
209209
210210   if(ctrl & BGCNT_MOSAIC)
211211   {
212      INT32 mosaicx = (gba_state->MOSAIC & 0x0f) + 1;
212      INT32 mosaicx = (state->MOSAIC & 0x0f) + 1;
213213      if(mosaicx > 1)
214214      {
215215         INT32 m = 1;
r7509r7510
227227   }
228228}
229229
230static void draw_roz_scanline(gba_state_t *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)
230static void draw_roz_scanline(gba_state *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)
231231{
232232   UINT32 base, mapbase, size;
233233   INT32 sizes[4] = { 128, 256, 512, 1024 };
234234   INT32 cx, cy, x, pixx, pixy;
235   UINT8 *mgba_vram = (UINT8 *)gba_state->gba_vram;
235   UINT8 *mgba_vram = (UINT8 *)state->gba_vram;
236236   UINT32 tile;
237   UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram;
237   UINT16 *pgba_pram = (UINT16 *)state->gba_pram;
238238   UINT16 pixel;
239239   UINT32 prio = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000;
240240
r7509r7510
243243      scanline[x] = 0x80000000;
244244   }
245245
246   if (gba_state->DISPCNT & enablemask)
246   if (state->DISPCNT & enablemask)
247247   {
248248      base = ((ctrl & BGCNT_CHARBASE) >> BGCNT_CHARBASE_SHIFT) * 0x4000;         // VRAM base of tiles
249249      mapbase = ((ctrl & BGCNT_SCREENBASE) >> BGCNT_SCREENBASE_SHIFT) * 0x800;   // VRAM base of map
r7509r7510
285285
286286      if(ctrl & BGCNT_MOSAIC)
287287      {
288         int mosaicy = ((gba_state->MOSAIC & 0xf0) >> 4) + 1;
288         int mosaicy = ((state->MOSAIC & 0xf0) >> 4) + 1;
289289         int y = ypos % mosaicy;
290290         cx -= y*PB;
291291         cy -= y*PD;
r7509r7510
393393
394394      if(ctrl & BGCNT_MOSAIC)
395395      {
396         int mosaicx = (gba_state->MOSAIC & 0x0f) + 1;
396         int mosaicx = (state->MOSAIC & 0x0f) + 1;
397397         if(mosaicx > 1)
398398         {
399399            int m = 1;
r7509r7510
412412   }
413413}
414414
415static void draw_bg_scanline(gba_state_t *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs)
415static void draw_bg_scanline(gba_state *state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs)
416416{
417   UINT8 *vram = (UINT8*)gba_state->gba_vram;
418   UINT16 *palette = (UINT16*)gba_state->gba_pram;
417   UINT8 *vram = (UINT8*)state->gba_vram;
418   UINT16 *palette = (UINT16*)state->gba_pram;
419419   UINT8 *chardata = &vram[((ctrl & BGCNT_CHARBASE) >> BGCNT_CHARBASE_SHIFT) * 0x4000];
420420   UINT16 *screendata = (UINT16*)&vram[((ctrl & BGCNT_SCREENBASE) >> BGCNT_SCREENBASE_SHIFT) * 0x800];
421421   UINT32 priority = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000;
r7509r7510
423423   INT32 height = 256;
424424   INT32 maskx, masky, pixx, pixy;
425425   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;
426   INT32 mosaicx = (state->MOSAIC & 0x000f) + 1;
427   INT32 mosaicy = ((state->MOSAIC & 0x00f0) >> 4) + 1;
428428   INT32 stride;
429429   INT32 x;
430430
431   if(!(gba_state->DISPCNT & enablemask))
431   if(!(state->DISPCNT & enablemask))
432432   {
433433      for(x = 0; x < 240; x++)
434434      {
r7509r7510
636636   }
637637}
638638
639static void draw_gba_oam_window(gba_state_t *gba_state, running_machine *machine, UINT32 *scanline, int y)
639static void draw_gba_oam_window(gba_state *state, running_machine *machine, UINT32 *scanline, int y)
640640{
641641   INT16 gba_oamindex;
642642   UINT32 tilebytebase, tileindex, tiledrawindex;
643643   UINT32 width, height;
644   UINT16 *pgba_oam = (UINT16 *)gba_state->gba_oam;
644   UINT16 *pgba_oam = (UINT16 *)state->gba_oam;
645645   int x = 0;
646   UINT8 *src = (UINT8*)gba_state->gba_vram;
646   UINT8 *src = (UINT8*)state->gba_vram;
647647
648648   for(x = 0; x < 240; x++)
649649   {
650650      scanline[x] = 0x80000000;
651651   }
652652
653   if( gba_state->DISPCNT & DISPCNT_OBJWIN_EN )
653   if( state->DISPCNT & DISPCNT_OBJWIN_EN )
654654   {
655655      for( gba_oamindex = 127; gba_oamindex >= 0; gba_oamindex-- )
656656      {
r7509r7510
794794                     if((attr0 & OBJ_PALMODE) == OBJ_PALMODE_256)
795795                     {
796796                        int inc = 32;
797                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
797                        if((state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
798798                        {
799799                           continue;
800800                        }
801                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
801                        if((state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
802802                        {
803803                           inc = sx >> 2;
804804                        }
r7509r7510
833833                     else
834834                     {
835835                        int inc = 32;
836                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
836                        if((state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
837837                        {
838838                           continue;
839839                        }
840                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
840                        if((state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
841841                        {
842842                           inc = sx >> 3;
843843                        }
r7509r7510
897897                        {
898898                           cury_ = height - cury_ - 1;
899899                        }
900                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
900                        if((state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
901901                        {
902902                           continue;
903903                        }
904904
905                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
905                        if((state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
906906                        {
907907                           inc = width >> 2;
908908                        }
r7509r7510
976976                        {
977977                           cury_ = height - cury_ - 1;
978978                        }
979                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
979                        if((state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
980980                        {
981981                           continue;
982982                        }
983983
984                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
984                        if((state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
985985                        {
986986                           inc = width >> 3;
987987                        }
r7509r7510
10821082   }
10831083}
10841084
1085static void draw_gba_oam(gba_state_t *gba_state, running_machine *machine, UINT32 *scanline, int y)
1085static void draw_gba_oam(gba_state *state, running_machine *machine, UINT32 *scanline, int y)
10861086{
10871087   INT16 gba_oamindex;
10881088   INT32 mosaiccnt = 0;
1089   INT32 mosaicy = ((gba_state->MOSAIC & 0xf000) >> 12) + 1;
1090   INT32 mosaicx = ((gba_state->MOSAIC & 0x0f00) >>  8) + 1;
1089   INT32 mosaicy = ((state->MOSAIC & 0xf000) >> 12) + 1;
1090   INT32 mosaicx = ((state->MOSAIC & 0x0f00) >>  8) + 1;
10911091   UINT32 tilebytebase, tileindex, tiledrawindex;
10921092   UINT8 width, height;
1093   UINT16 *pgba_oam = (UINT16 *)gba_state->gba_oam;
1094   UINT8 *src = (UINT8 *)gba_state->gba_vram;
1095   UINT16 *palette = (UINT16*)gba_state->gba_pram;
1093   UINT16 *pgba_oam = (UINT16 *)state->gba_oam;
1094   UINT8 *src = (UINT8 *)state->gba_vram;
1095   UINT16 *palette = (UINT16*)state->gba_pram;
10961096   int x = 0;
10971097
10981098   for(x = 0; x < 240; x++)
r7509r7510
11001100      scanline[x] = 0x80000000;
11011101   }
11021102
1103   if( gba_state->DISPCNT & DISPCNT_OBJ_EN )
1103   if( state->DISPCNT & DISPCNT_OBJ_EN )
11041104   {
11051105      for( gba_oamindex = 0; gba_oamindex < 128; gba_oamindex++ )
11061106      {
r7509r7510
12501250                     {
12511251                        INT32 inc = 32;
12521252
1253                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
1253                        if((state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
12541254                        {
12551255                           continue;
12561256                        }
12571257
1258                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
1258                        if((state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
12591259                        {
12601260                           inc = width >> 2;
12611261                        }
r7509r7510
13111311                        INT32 inc = 32;
13121312                        INT32 palentry = (attr2 >> 8) & 0xf0;
13131313
1314                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
1314                        if((state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
13151315                        {
13161316                           continue;
13171317                        }
13181318
1319                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
1319                        if((state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
13201320                        {
13211321                           inc = width >> 3;
13221322                        }
r7509r7510
14151415                           cury = height - cury - 1;
14161416                        }
14171417
1418                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
1418                        if((state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
14191419                        {
14201420                           continue;
14211421                        }
14221422
1423                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
1423                        if((state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
14241424                        {
14251425                           inc = width >> 2;
14261426                        }
r7509r7510
15231523                           cury = height - cury - 1;
15241524                        }
15251525
1526                        if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
1526                        if((state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200)
15271527                        {
15281528                           continue;
15291529                        }
15301530
1531                        if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
1531                        if((state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D)
15321532                        {
15331533                           inc = width >> 3;
15341534                        }
r7509r7510
16751675   }
16761676}
16771677
1678INLINE int is_in_window(gba_state_t *gba_state, int x, int window)
1678INLINE int is_in_window(gba_state *state, int x, int window)
16791679{
1680   int x0 = gba_state->WIN0H >> 8;
1681   int x1 = gba_state->WIN0H & 0x00ff;
1680   int x0 = state->WIN0H >> 8;
1681   int x1 = state->WIN0H & 0x00ff;
16821682
16831683   if(window == 1)
16841684   {
1685      x0 = gba_state->WIN1H >> 8;
1686      x1 = gba_state->WIN1H & 0x00ff;
1685      x0 = state->WIN1H >> 8;
1686      x1 = state->WIN1H & 0x00ff;
16871687   }
16881688
16891689   if(x0 <= x1)
r7509r7510
17671767   UINT16 *scanline = BITMAP_ADDR16(bitmap, y, 0);
17681768   int i, x;
17691769   static UINT32 xferscan[7][240+2048];   // up to 1024 pixels of slop on either side to allow easier clip handling
1770   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
1770   gba_state *state = (gba_state *)machine->driver_data;
17711771   UINT8 submode = 0;
17721772   int bpp = 0;
17731773
17741774   // forced blank
1775   if (gba_state->DISPCNT & DISPCNT_BLANK)
1775   if (state->DISPCNT & DISPCNT_BLANK)
17761776   {
17771777      // forced blank is white
17781778      for (i = 0; i < 240; i++)
r7509r7510
17821782      return;
17831783   }
17841784
1785   if(!gba_state->fxOn && !gba_state->windowOn && !(gba_state->DISPCNT & DISPCNT_OBJWIN_EN))
1785   if(!state->fxOn && !state->windowOn && !(state->DISPCNT & DISPCNT_OBJWIN_EN))
17861786   {
17871787      submode = 0;
17881788   }
1789   else if(gba_state->fxOn && !gba_state->windowOn && !(gba_state->DISPCNT & DISPCNT_OBJWIN_EN))
1789   else if(state->fxOn && !state->windowOn && !(state->DISPCNT & DISPCNT_OBJWIN_EN))
17901790   {
17911791      submode = 1;
17921792   }
r7509r7510
17951795      submode = 2;
17961796   }
17971797
1798   //printf( "mode = %d, %d\n", gba_state->DISPCNT & 7, submode );
1798   //printf( "mode = %d, %d\n", state->DISPCNT & 7, submode );
17991799
1800   switch(gba_state->DISPCNT & 7)
1800   switch(state->DISPCNT & 7)
18011801   {
18021802      case 3:
18031803         bpp = 16;
r7509r7510
18101810         break;
18111811   }
18121812
1813   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);
1813   gba_draw_scanline_modes[state->DISPCNT & 7][submode](machine, state, y, &xferscan[0][1024], &xferscan[1][1024], &xferscan[2][1024], &xferscan[3][1024], &xferscan[4][1024], &xferscan[5][1024], &xferscan[6][1024], bpp);
18141814
18151815   for(x = 0; x < 240; x++)
18161816   {
src/mess/includes/gba.h
r7509r7510
146146};
147147
148148/* driver state */
149typedef struct
149class gba_state
150150{
151public:
152   static void *alloc(running_machine &machine) { return auto_alloc_clear(&machine, gba_state(machine)); }
153
154   gba_state(running_machine &machine) { }
155
151156   UINT32 DISPSTAT;
152157   UINT32 BG2X, BG2Y, BG3X, BG3Y;
153158   UINT16 DISPCNT,   GRNSWAP;
r7509r7510
207212
208213   int fifo_a_ptr, fifo_b_ptr, fifo_a_in, fifo_b_in;
209214   UINT8 fifo_a[20], fifo_b[20];
210} gba_state_t;
215};
211216
212217/*----------- defined in video/gba.c -----------*/
213218
src/mess/includes/mac.h
r7509r7510
169169
170170/* Mac driver data */
171171
172typedef struct
172class mac_state
173173{
174public:
175   static void *alloc(running_machine &machine) { return auto_alloc_clear(&machine, mac_state(machine)); }
176
177   mac_state(running_machine &machine) { }
178
174179   mac_model_t mac_model;
175180
176181   UINT32 mac_overlay;
r7509r7510
243248   // Apple Sound Chip
244249   UINT8 mac_asc_regs[0x2000];
245250   INT16 xfersamples[0x800];
246} mac_state;
251};
247252
248253#endif /* MAC_H_ */
249254
src/mess/drivers/cat.c
r7509r7510
1111#include "cpu/m68000/m68000.h"
1212#include "machine/68681.h"
1313
14typedef struct _cat_state cat_state;
15struct _cat_state
14class cat_state
1615{
16public:
17   static void *alloc(running_machine &machine) { return auto_alloc_clear(&machine, cat_state(machine)); }
18
19   cat_state(running_machine &machine) { }
20
1721   UINT16 *video_ram;
1822
1923   UINT8 duart_inp;// = 0x0e;
src/mess/drivers/camplynx.c
r7509r7510
8181#include "video/mc6845.h"
8282#include "sound/dac.h"
8383
84typedef struct _camplynx_state camplynx_state;
85struct _camplynx_state
84class camplynx_state
8685{
86public:
87   static void *alloc(running_machine &machine) { return auto_alloc_clear(&machine, camplynx_state(machine)); }
88
89   camplynx_state(running_machine &machine) { }
90
8791   running_device *mc6845;
8892};
8993
src/mess/drivers/apexc.c
r7509r7510
1010#include "cpu/apexc/apexc.h"
1111
1212
13typedef struct _apexc_state apexc_state;
14struct _apexc_state
13class apexc_state
1514{
15public:
16   static void *alloc(running_machine &machine) { return auto_alloc_clear(&machine, apexc_state(machine)); }
17
18   apexc_state(running_machine &machine) { }
19
1620   UINT32 panel_data_reg;   /* value of a data register on the control panel which can
1721                                be edited - the existence of this register is a personnal
1822                                guess */
src/mess/drivers/gba.c
r7509r7510
7373
7474static void gba_request_irq(running_machine *machine, UINT32 int_type)
7575{
76   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
76   gba_state *state = (gba_state *)machine->driver_data;
7777
7878   // set flag for later recovery
79   gba_state->IF |= int_type;
79   state->IF |= int_type;
8080
8181   // is this specific interrupt enabled?
82   int_type &= gba_state->IE;
82   int_type &= state->IE;
8383   if (int_type != 0)
8484   {
8585      // master enable?
86      if (gba_state->IME & 1)
86      if (state->IME & 1)
8787      {
8888         cpu_set_input_line(devtag_get_device(machine, "maincpu"), ARM7_IRQ_LINE, ASSERT_LINE);
8989         cpu_set_input_line(devtag_get_device(machine, "maincpu"), ARM7_IRQ_LINE, CLEAR_LINE);
r7509r7510
9696   int ctrl;
9797   FPTR ch;
9898   static UINT32 ch_int[4] = { INT_DMA0, INT_DMA1, INT_DMA2, INT_DMA3 };
99   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
99   gba_state *state = (gba_state *)machine->driver_data;
100100
101101   ch = param;
102102
103103//  printf("dma complete: ch %d\n", ch);
104104
105   timer_adjust_oneshot(gba_state->dma_timer[ch], attotime_never, 0);
105   timer_adjust_oneshot(state->dma_timer[ch], attotime_never, 0);
106106
107   ctrl = gba_state->dma_regs[(ch*3)+2] >> 16;
107   ctrl = state->dma_regs[(ch*3)+2] >> 16;
108108
109109   // IRQ
110110   if (ctrl & 0x4000)
r7509r7510
117117   if (!((ctrl>>9) & 1) || ((ctrl & 0x3000) == 0))
118118   {
119119//      printf("clear active for ch %d\n", ch);
120      gba_state->dma_regs[(ch*3)+2] &= ~0x80000000;   // clear "active" bit
120      state->dma_regs[(ch*3)+2] &= ~0x80000000;   // clear "active" bit
121121   }
122122   else
123123   {
124124      // if repeat, reload the count
125125      if ((ctrl>>9) & 1)
126126      {
127         gba_state->dma_cnt[ch] = gba_state->dma_regs[(ch*3)+2]&0xffff;
127         state->dma_cnt[ch] = state->dma_regs[(ch*3)+2]&0xffff;
128128
129129         // if increment & reload mode, reload the destination
130130         if (((ctrl>>5)&3) == 3)
131131         {
132            gba_state->dma_dst[ch] = gba_state->dma_regs[(ch*3)+1];
132            state->dma_dst[ch] = state->dma_regs[(ch*3)+1];
133133         }
134134      }
135135   }
r7509r7510
142142   int srcadd, dstadd;
143143   UINT32 src, dst;
144144   const address_space *space = cpu_get_address_space(devtag_get_device(machine, "maincpu"), ADDRESS_SPACE_PROGRAM);
145   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
145   gba_state *state = (gba_state *)machine->driver_data;
146146
147   src = gba_state->dma_src[ch];
148   dst = gba_state->dma_dst[ch];
149   ctrl = gba_state->dma_regs[(ch*3)+2] >> 16;
150   srcadd = gba_state->dma_srcadd[ch];
151   dstadd = gba_state->dma_dstadd[ch];
147   src = state->dma_src[ch];
148   dst = state->dma_dst[ch];
149   ctrl = state->dma_regs[(ch*3)+2] >> 16;
150   srcadd = state->dma_srcadd[ch];
151   dstadd = state->dma_dstadd[ch];
152152
153   cnt = gba_state->dma_cnt[ch];
153   cnt = state->dma_cnt[ch];
154154   if (!cnt)
155155   {
156156      if (ch == 3)
r7509r7510
263263      }
264264   }
265265
266   gba_state->dma_src[ch] = src;
267   gba_state->dma_dst[ch] = dst;
266   state->dma_src[ch] = src;
267   state->dma_dst[ch] = dst;
268268
269//  printf("settng DMA timer %d for %d cycs (tmr %x)\n", ch, cnt, (UINT32)gba_state->dma_timer[ch]);
270//  timer_adjust_oneshot(gba_state->dma_timer[ch], ATTOTIME_IN_CYCLES(0, cnt), ch);
269//  printf("settng DMA timer %d for %d cycs (tmr %x)\n", ch, cnt, (UINT32)state->dma_timer[ch]);
270//  timer_adjust_oneshot(state->dma_timer[ch], ATTOTIME_IN_CYCLES(0, cnt), ch);
271271   dma_complete(machine, NULL, ch);
272272}
273273
274274static void audio_tick(running_machine *machine, int ref)
275275{
276   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
276   gba_state *state = (gba_state *)machine->driver_data;
277277
278   if (!(gba_state->SOUNDCNT_X & 0x80))
278   if (!(state->SOUNDCNT_X & 0x80))
279279   {
280280      return;
281281   }
282282
283283   if (!ref)
284284   {
285      if (gba_state->fifo_a_ptr != gba_state->fifo_a_in)
285      if (state->fifo_a_ptr != state->fifo_a_in)
286286      {
287         if (gba_state->fifo_a_ptr == 17)
287         if (state->fifo_a_ptr == 17)
288288         {
289            gba_state->fifo_a_ptr = 0;
289            state->fifo_a_ptr = 0;
290290         }
291291
292         if (gba_state->SOUNDCNT_H & 0x100)
292         if (state->SOUNDCNT_H & 0x100)
293293         {
294294            running_device *dac_device = devtag_get_device(machine, "direct_a_left");
295295
296            dac_signed_data_w(dac_device, gba_state->fifo_a[gba_state->fifo_a_ptr]^0x80);
296            dac_signed_data_w(dac_device, state->fifo_a[state->fifo_a_ptr]^0x80);
297297         }
298         if (gba_state->SOUNDCNT_H & 0x200)
298         if (state->SOUNDCNT_H & 0x200)
299299         {
300300            running_device *dac_device = devtag_get_device(machine, "direct_a_right");
301301
302            dac_signed_data_w(dac_device, gba_state->fifo_a[gba_state->fifo_a_ptr]^0x80);
302            dac_signed_data_w(dac_device, state->fifo_a[state->fifo_a_ptr]^0x80);
303303         }
304         gba_state->fifo_a_ptr++;
304         state->fifo_a_ptr++;
305305      }
306306
307307      // fifo empty?
308      if (gba_state->fifo_a_ptr == gba_state->fifo_a_in)
308      if (state->fifo_a_ptr == state->fifo_a_in)
309309      {
310310         // is a DMA set up to feed us?
311         if ((gba_state->dma_regs[(1*3)+1] == 0x40000a0) && ((gba_state->dma_regs[(1*3)+2] & 0x30000000) == 0x30000000))
311         if ((state->dma_regs[(1*3)+1] == 0x40000a0) && ((state->dma_regs[(1*3)+2] & 0x30000000) == 0x30000000))
312312         {
313313            // channel 1 it is
314314            dma_exec(machine, 1);
315315         }
316         if ((gba_state->dma_regs[(2*3)+1] == 0x40000a0) && ((gba_state->dma_regs[(2*3)+2] & 0x30000000) == 0x30000000))
316         if ((state->dma_regs[(2*3)+1] == 0x40000a0) && ((state->dma_regs[(2*3)+2] & 0x30000000) == 0x30000000))
317317         {
318318            // channel 2 it is
319319            dma_exec(machine, 2);
r7509r7510
322322   }
323323   else
324324   {
325      if (gba_state->fifo_b_ptr != gba_state->fifo_b_in)
325      if (state->fifo_b_ptr != state->fifo_b_in)
326326      {
327         if (gba_state->fifo_b_ptr == 17)
327         if (state->fifo_b_ptr == 17)
328328         {
329            gba_state->fifo_b_ptr = 0;
329            state->fifo_b_ptr = 0;
330330         }
331331
332         if (gba_state->SOUNDCNT_H & 0x1000)
332         if (state->SOUNDCNT_H & 0x1000)
333333         {
334334            running_device *dac_device = devtag_get_device(machine, "direct_b_left");
335335
336            dac_signed_data_w(dac_device, gba_state->fifo_b[gba_state->fifo_b_ptr]^0x80);
336            dac_signed_data_w(dac_device, state->fifo_b[state->fifo_b_ptr]^0x80);
337337         }
338         if (gba_state->SOUNDCNT_H & 0x2000)
338         if (state->SOUNDCNT_H & 0x2000)
339339         {
340340            running_device *dac_device = devtag_get_device(machine, "direct_b_right");
341341
342            dac_signed_data_w(dac_device, gba_state->fifo_b[gba_state->fifo_b_ptr]^0x80);
342            dac_signed_data_w(dac_device, state->fifo_b[state->fifo_b_ptr]^0x80);
343343         }
344         gba_state->fifo_b_ptr++;
344         state->fifo_b_ptr++;
345345      }
346346
347      if (gba_state->fifo_b_ptr == gba_state->fifo_b_in)
347      if (state->fifo_b_ptr == state->fifo_b_in)
348348      {
349349         // is a DMA set up to feed us?
350         if ((gba_state->dma_regs[(1*3)+1] == 0x40000a4) && ((gba_state->dma_regs[(1*3)+2] & 0x30000000) == 0x30000000))
350         if ((state->dma_regs[(1*3)+1] == 0x40000a4) && ((state->dma_regs[(1*3)+2] & 0x30000000) == 0x30000000))
351351         {
352352            // channel 1 it is
353353            dma_exec(machine, 1);
354354         }
355         if ((gba_state->dma_regs[(2*3)+1] == 0x40000a4) && ((gba_state->dma_regs[(2*3)+2] & 0x30000000) == 0x30000000))
355         if ((state->dma_regs[(2*3)+1] == 0x40000a4) && ((state->dma_regs[(2*3)+2] & 0x30000000) == 0x30000000))
356356         {
357357            // channel 2 it is
358358            dma_exec(machine, 2);
r7509r7510
365365{
366366   static UINT32 tmr_ints[4] = { INT_TM0_OVERFLOW, INT_TM1_OVERFLOW, INT_TM2_OVERFLOW, INT_TM3_OVERFLOW };
367367   FPTR tmr = (FPTR) param;
368   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
368   gba_state *state = (gba_state *)machine->driver_data;
369369
370//  printf("Timer %d expired, SOUNDCNT_H %04x\n", tmr, gba_state->SOUNDCNT_H);
370//  printf("Timer %d expired, SOUNDCNT_H %04x\n", tmr, state->SOUNDCNT_H);
371371
372372   // check if timers 0 or 1 are feeding directsound
373373   if (tmr == 0)
374374   {
375      if ((gba_state->SOUNDCNT_H & 0x400) == 0)
375      if ((state->SOUNDCNT_H & 0x400) == 0)
376376      {
377377         audio_tick(machine, 0);
378378      }
379379
380      if ((gba_state->SOUNDCNT_H & 0x4000) == 0)
380      if ((state->SOUNDCNT_H & 0x4000) == 0)
381381      {
382382         audio_tick(machine, 1);
383383      }
r7509r7510
385385
386386   if (tmr == 1)
387387   {
388      if ((gba_state->SOUNDCNT_H & 0x400) == 0x400)
388      if ((state->SOUNDCNT_H & 0x400) == 0x400)
389389      {
390390         audio_tick(machine, 0);
391391      }
392392
393      if ((gba_state->SOUNDCNT_H & 0x4000) == 0x4000)
393      if ((state->SOUNDCNT_H & 0x4000) == 0x4000)
394394      {
395395         audio_tick(machine, 1);
396396      }
r7509r7510
400400   switch (tmr)
401401   {
402402   case 0:
403           if (gba_state->timer_regs[1] & 0x40000)
403           if (state->timer_regs[1] & 0x40000)
404404           {
405              gba_state->timer_regs[1] = ( ( gba_state->timer_regs[1] & 0x0000ffff ) + 1 ) & 0x0000ffff;
406              if( ( gba_state->timer_regs[1] & 0x0000ffff ) == 0 )
405              state->timer_regs[1] = ( ( state->timer_regs[1] & 0x0000ffff ) + 1 ) & 0x0000ffff;
406              if( ( state->timer_regs[1] & 0x0000ffff ) == 0 )
407407              {
408                      gba_state->timer_regs[1] |= gba_state->timer_reload[1];
409                      if( ( gba_state->timer_regs[1] & 0x400000 ) && ( gba_state->IME != 0 ) )
408                      state->timer_regs[1] |= state->timer_reload[1];
409                      if( ( state->timer_regs[1] & 0x400000 ) && ( state->IME != 0 ) )
410410                      {
411411                         gba_request_irq( machine, tmr_ints[1] );
412412                      }
413                      if( ( gba_state->timer_regs[2] & 0x40000 ) )
413                      if( ( state->timer_regs[2] & 0x40000 ) )
414414                      {
415                         gba_state->timer_regs[2] = ( ( gba_state->timer_regs[2] & 0x0000ffff ) + 1 ) & 0x0000ffff;
416                         if( ( gba_state->timer_regs[2] & 0x0000ffff ) == 0 )
415                         state->timer_regs[2] = ( ( state->timer_regs[2] & 0x0000ffff ) + 1 ) & 0x0000ffff;
416                         if( ( state->timer_regs[2] & 0x0000ffff ) == 0 )
417417                         {
418                                 gba_state->timer_regs[2] |= gba_state->timer_reload[2];
419                                 if( ( gba_state->timer_regs[2] & 0x400000 ) && ( gba_state->IME != 0 ) )
418                                 state->timer_regs[2] |= state->timer_reload[2];
419                                 if( ( state->timer_regs[2] & 0x400000 ) && ( state->IME != 0 ) )
420420                                 {
421421                                    gba_request_irq( machine, tmr_ints[2] );
422422                                 }
423                                 if( ( gba_state->timer_regs[3] & 0x40000 ) )
423                                 if( ( state->timer_regs[3] & 0x40000 ) )
424424                                 {
425                                    gba_state->timer_regs[3] = ( ( gba_state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff;
426                                    if( ( gba_state->timer_regs[3] & 0x0000ffff ) == 0 )
425                                    state->timer_regs[3] = ( ( state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff;
426                                    if( ( state->timer_regs[3] & 0x0000ffff ) == 0 )
427427                                    {
428                                            gba_state->timer_regs[3] |= gba_state->timer_reload[3];
429                                            if( ( gba_state->timer_regs[3] & 0x400000 ) && ( gba_state->IME != 0 ) )
428                                            state->timer_regs[3] |= state->timer_reload[3];
429                                            if( ( state->timer_regs[3] & 0x400000 ) && ( state->IME != 0 ) )
430430                                            {
431431                                               gba_request_irq( machine, tmr_ints[3] );
432432                                            }
r7509r7510
438438           }
439439           break;
440440   case 1:
441           if (gba_state->timer_regs[2] & 0x40000)
441           if (state->timer_regs[2] & 0x40000)
442442           {
443              gba_state->timer_regs[2] = ( ( gba_state->timer_regs[2] & 0x0000ffff ) + 1 ) & 0x0000ffff;
444              if( ( gba_state->timer_regs[2] & 0x0000ffff ) == 0 )
443              state->timer_regs[2] = ( ( state->timer_regs[2] & 0x0000ffff ) + 1 ) & 0x0000ffff;
444              if( ( state->timer_regs[2] & 0x0000ffff ) == 0 )
445445              {
446                      gba_state->timer_regs[2] |= gba_state->timer_reload[2];
447                      if( ( gba_state->timer_regs[2] & 0x400000 ) && ( gba_state->IME != 0 ) )
446                      state->timer_regs[2] |= state->timer_reload[2];
447                      if( ( state->timer_regs[2] & 0x400000 ) && ( state->IME != 0 ) )
448448                      {
449449                         gba_request_irq( machine, tmr_ints[2] );
450450                      }
451                      if( ( gba_state->timer_regs[3] & 0x40000 ) )
451                      if( ( state->timer_regs[3] & 0x40000 ) )
452452                      {
453                         gba_state->timer_regs[3] = ( ( gba_state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff;
454                         if( ( gba_state->timer_regs[3] & 0x0000ffff ) == 0 )
453                         state->timer_regs[3] = ( ( state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff;
454                         if( ( state->timer_regs[3] & 0x0000ffff ) == 0 )
455455                         {
456                                 gba_state->timer_regs[2] |= gba_state->timer_reload[2];
457                                 if( ( gba_state->timer_regs[3] & 0x400000 ) && ( gba_state->IME != 0 ) )
456                                 state->timer_regs[2] |= state->timer_reload[2];
457                                 if( ( state->timer_regs[3] & 0x400000 ) && ( state->IME != 0 ) )
458458                                 {
459459                                    gba_request_irq( machine, tmr_ints[3] );
460460                                 }
r7509r7510
464464           }
465465           break;
466466   case 2:
467           if (gba_state->timer_regs[3] & 0x40000)
467           if (state->timer_regs[3] & 0x40000)
468468           {
469              gba_state->timer_regs[3] = ( ( gba_state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff;
470              if( ( gba_state->timer_regs[3] & 0x0000ffff ) == 0 )
469              state->timer_regs[3] = ( ( state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff;
470              if( ( state->timer_regs[3] & 0x0000ffff ) == 0 )
471471              {
472                      gba_state->timer_regs[3] |= gba_state->timer_reload[3];
473                      if( ( gba_state->timer_regs[3] & 0x400000 ) && ( gba_state->IME != 0 ) )
472                      state->timer_regs[3] |= state->timer_reload[3];
473                      if( ( state->timer_regs[3] & 0x400000 ) && ( state->IME != 0 ) )
474474                      {
475475                         gba_request_irq( machine, tmr_ints[3] );
476476                      }
r7509r7510
480480   }
481481
482482   // are we supposed to IRQ?
483   if ((gba_state->timer_regs[tmr] & 0x400000) && (gba_state->IME != 0))
483   if ((state->timer_regs[tmr] & 0x400000) && (state->IME != 0))
484484   {
485485      gba_request_irq(machine, tmr_ints[tmr]);
486486   }
r7509r7510
488488
489489static TIMER_CALLBACK(handle_irq)
490490{
491   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
491   gba_state *state = (gba_state *)machine->driver_data;
492492
493   gba_request_irq(machine, gba_state->IF);
493   gba_request_irq(machine, state->IF);
494494
495   timer_adjust_oneshot(gba_state->irq_timer, attotime_never, 0);
495   timer_adjust_oneshot(state->irq_timer, attotime_never, 0);
496496}
497497
498498static READ32_HANDLER( gba_io_r )
r7509r7510
500500   UINT32 retval = 0;
501501   running_machine *machine = space->machine;
502502   running_device *gb_device = devtag_get_device(space->machine, "custom");
503   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
503   gba_state *state = (gba_state *)machine->driver_data;
504504
505505   switch( offset )
506506   {
507507      case 0x0000/4:
508508         if( (mem_mask) & 0x0000ffff )
509509         {
510            verboselog(machine, 2, "GBA IO Register Read: DISPCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->DISPCNT );
511            retval |= gba_state->DISPCNT;
510            verboselog(machine, 2, "GBA IO Register Read: DISPCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->DISPCNT );
511            retval |= state->DISPCNT;
512512         }
513513         if( (mem_mask) & 0xffff0000 )
514514         {
515            verboselog(machine, 2, "GBA IO Register Read: Green Swap (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->GRNSWAP );
516            retval |= gba_state->GRNSWAP << 16;
515            verboselog(machine, 2, "GBA IO Register Read: Green Swap (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->GRNSWAP );
516            retval |= state->GRNSWAP << 16;
517517         }
518518         break;
519519      case 0x0004/4:
520         retval = (gba_state->DISPSTAT & 0xffff) | (video_screen_get_vpos(machine->primary_screen)<<16);
520         retval = (state->DISPSTAT & 0xffff) | (video_screen_get_vpos(machine->primary_screen)<<16);
521521         break;
522522      case 0x0008/4:
523523         if( (mem_mask) & 0x0000ffff )
524524         {
525            verboselog(machine, 2, "GBA IO Register Read: BG0CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->BG0CNT );
526            retval |= gba_state->BG0CNT;
525            verboselog(machine, 2, "GBA IO Register Read: BG0CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->BG0CNT );
526            retval |= state->BG0CNT;
527527         }
528528         if( (mem_mask) & 0xffff0000 )
529529         {
530            verboselog(machine, 2, "GBA IO Register Read: BG1CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->BG1CNT );
531            retval |= gba_state->BG1CNT << 16;
530            verboselog(machine, 2, "GBA IO Register Read: BG1CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->BG1CNT );
531            retval |= state->BG1CNT << 16;
532532         }
533533         break;
534534      case 0x000c/4:
535535         if( (mem_mask) & 0x0000ffff )
536536         {
537            verboselog(machine, 2, "GBA IO Register Read: BG2CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->BG2CNT );
538            retval |= gba_state->BG2CNT;
537            verboselog(machine, 2, "GBA IO Register Read: BG2CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->BG2CNT );
538            retval |= state->BG2CNT;
539539         }
540540         if( (mem_mask) & 0xffff0000 )
541541         {
542            verboselog(machine, 2, "GBA IO Register Read: BG3CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->BG3CNT );
543            retval |= gba_state->BG3CNT << 16;
542            verboselog(machine, 2, "GBA IO Register Read: BG3CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->BG3CNT );
543            retval |= state->BG3CNT << 16;
544544         }
545545         break;
546546      case 0x0010/4:
r7509r7510
686686      case 0x0048/4:
687687         if( (mem_mask) & 0x0000ffff )
688688         {
689            verboselog(machine, 2, "GBA IO Register Read: WININ (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->WININ );
690            retval |= gba_state->WININ;
689            verboselog(machine, 2, "GBA IO Register Read: WININ (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->WININ );
690            retval |= state->WININ;
691691         }
692692         if( (mem_mask) & 0xffff0000 )
693693         {
694            verboselog(machine, 2, "GBA IO Register Read: WINOUT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->WINOUT );
695            retval |= gba_state->WINOUT << 16;
694            verboselog(machine, 2, "GBA IO Register Read: WINOUT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->WINOUT );
695            retval |= state->WINOUT << 16;
696696         }
697697         break;
698698      case 0x004c/4:
r7509r7510
708708      case 0x0050/4:
709709         if( (mem_mask) & 0x0000ffff )
710710         {
711            verboselog(machine, 2, "GBA IO Register Read: BLDCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->BLDCNT );
712            retval |= gba_state->BLDCNT;
711            verboselog(machine, 2, "GBA IO Register Read: BLDCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->BLDCNT );
712            retval |= state->BLDCNT;
713713         }
714714         if( (mem_mask) & 0xffff0000 )
715715         {
r7509r7510
774774         retval = gb_sound_r(gb_device, 0x14) | gb_sound_r(gb_device, 0x15)<<8;
775775         if( (mem_mask) & 0xffff0000 )
776776         {
777            verboselog(machine, 2, "GBA IO Register Read: SOUNDCNT_H (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->SOUNDCNT_H );
778            retval |= gba_state->SOUNDCNT_H << 16;
777            verboselog(machine, 2, "GBA IO Register Read: SOUNDCNT_H (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->SOUNDCNT_H );
778            retval |= state->SOUNDCNT_H << 16;
779779         }
780780         break;
781781      case 0x0084/4:
r7509r7510
784784      case 0x0088/4:
785785         if( (mem_mask) & 0x0000ffff )
786786         {
787            verboselog(machine, 2, "GBA IO Register Read: SOUNDBIAS (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->SOUNDBIAS );
788            retval |= gba_state->SOUNDBIAS;
787            verboselog(machine, 2, "GBA IO Register Read: SOUNDBIAS (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->SOUNDBIAS );
788            retval |= state->SOUNDBIAS;
789789         }
790790         if( (mem_mask) & 0xffff0000 )
791791         {
r7509r7510
824824            // no idea why here, but it matches VBA better
825825            if (((offset-0xb0/4) % 3) == 2)
826826            {
827               return gba_state->dma_regs[offset-(0xb0/4)] & 0xff000000;
827               return state->dma_regs[offset-(0xb0/4)] & 0xff000000;
828828            }
829829
830            return gba_state->dma_regs[offset-(0xb0/4)];
830            return state->dma_regs[offset-(0xb0/4)];
831831         }
832832         break;
833833      case 0x0100/4:
r7509r7510
842842//              printf("Read timer reg %x (PC=%x)\n", timer, cpu_get_pc(space->cpu));
843843
844844            // update times for
845            if (gba_state->timer_regs[timer] & 0x800000)
845            if (state->timer_regs[timer] & 0x800000)
846846            {
847               time = attotime_to_double(timer_timeelapsed(gba_state->tmr_timer[timer]));
847               time = attotime_to_double(timer_timeelapsed(state->tmr_timer[timer]));
848848
849               ticks = (double)(0x10000 - (gba_state->timer_regs[timer] & 0xffff));
849               ticks = (double)(0x10000 - (state->timer_regs[timer] & 0xffff));
850850
851//                  printf("time %f ticks %f 1/hz %f\n", time, ticks, 1.0 / gba_state->timer_hz[timer]);
851//                  printf("time %f ticks %f 1/hz %f\n", time, ticks, 1.0 / state->timer_hz[timer]);
852852
853853               time *= ticks;
854               time /= (1.0 / gba_state->timer_hz[timer]);
854               time /= (1.0 / state->timer_hz[timer]);
855855
856856               elapsed = (UINT32)time;
857857
r7509r7510
863863               elapsed = 0;
864864            }
865865
866            return (gba_state->timer_regs[timer] & 0xffff0000) | (elapsed & 0xffff);
866            return (state->timer_regs[timer] & 0xffff0000) | (elapsed & 0xffff);
867867         }
868868         break;
869869      case 0x0120/4:
870870         if( (mem_mask) & 0x0000ffff )
871871         {
872            verboselog(machine, 2, "GBA IO Register Read: SIOMULTI0 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->SIOMULTI0 );
873            retval |= gba_state->SIOMULTI0;
872            verboselog(machine, 2, "GBA IO Register Read: SIOMULTI0 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->SIOMULTI0 );
873            retval |= state->SIOMULTI0;
874874         }
875875         if( (mem_mask) & 0xffff0000 )
876876         {
877            verboselog(machine, 2, "GBA IO Register Read: SIOMULTI1 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->SIOMULTI1 );
878            retval |= gba_state->SIOMULTI1 << 16;
877            verboselog(machine, 2, "GBA IO Register Read: SIOMULTI1 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->SIOMULTI1 );
878            retval |= state->SIOMULTI1 << 16;
879879         }
880880         break;
881881      case 0x0124/4:
882882         if( (mem_mask) & 0x0000ffff )
883883         {
884            verboselog(machine, 2, "GBA IO Register Read: SIOMULTI2 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->SIOMULTI2 );
885            retval |= gba_state->SIOMULTI2;
884            verboselog(machine, 2, "GBA IO Register Read: SIOMULTI2 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->SIOMULTI2 );
885            retval |= state->SIOMULTI2;
886886         }
887887         if( (mem_mask) & 0xffff0000 )
888888         {
889            verboselog(machine, 2, "GBA IO Register Read: SIOMULTI3 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->SIOMULTI3 );
890            retval |= gba_state->SIOMULTI3 << 16;
889            verboselog(machine, 2, "GBA IO Register Read: SIOMULTI3 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->SIOMULTI3 );
890            retval |= state->SIOMULTI3 << 16;
891891         }
892892         break;
893893      case 0x0128/4:
894894         if( (mem_mask) & 0x0000ffff )
895895         {
896            verboselog(machine, 2, "GBA IO Register Read: SIOCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->SIOCNT );
897            retval |= gba_state->SIOCNT;
896            verboselog(machine, 2, "GBA IO Register Read: SIOCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->SIOCNT );
897            retval |= state->SIOCNT;
898898         }
899899         if( (mem_mask) & 0xffff0000 )
900900         {
901            verboselog(machine, 2, "GBA IO Register Read: SIODATA8 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->SIODATA8 );
902            retval |= gba_state->SIODATA8 << 16;
901            verboselog(machine, 2, "GBA IO Register Read: SIODATA8 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->SIODATA8 );
902            retval |= state->SIODATA8 << 16;
903903         }
904904         break;
905905      case 0x0130/4:
r7509r7510
909909         }
910910         if( (mem_mask) & 0xffff0000 )
911911         {
912            verboselog(machine, 2, "GBA IO Register Read: KEYCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->KEYCNT );
913            retval |= gba_state->KEYCNT << 16;
912            verboselog(machine, 2, "GBA IO Register Read: KEYCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->KEYCNT );
913            retval |= state->KEYCNT << 16;
914914         }
915915         break;
916916      case 0x0134/4:
917917         if( (mem_mask) & 0x0000ffff )
918918         {
919            verboselog(machine, 2, "GBA IO Register Read: RCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->RCNT );
920            retval |= gba_state->RCNT;
919            verboselog(machine, 2, "GBA IO Register Read: RCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->RCNT );
920            retval |= state->RCNT;
921921         }
922922         if( (mem_mask) & 0xffff0000 )
923923         {
r7509r7510
927927      case 0x0140/4:
928928         if( (mem_mask) & 0x0000ffff )
929929         {
930            verboselog(machine, 2, "GBA IO Register Read: JOYCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->JOYCNT );
931            retval |= gba_state->JOYCNT;
930            verboselog(machine, 2, "GBA IO Register Read: JOYCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->JOYCNT );
931            retval |= state->JOYCNT;
932932         }
933933         if( (mem_mask) & 0xffff0000 )
934934         {
r7509r7510
938938      case 0x0150/4:
939939         if( (mem_mask) & 0x0000ffff )
940940         {
941            verboselog(machine, 2, "GBA IO Register Read: JOY_RECV_LSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->JOY_RECV & 0x0000ffff );
942            retval |= gba_state->JOY_RECV & 0x0000ffff;
941            verboselog(machine, 2, "GBA IO Register Read: JOY_RECV_LSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->JOY_RECV & 0x0000ffff );
942            retval |= state->JOY_RECV & 0x0000ffff;
943943         }
944944         if( (mem_mask) & 0xffff0000 )
945945         {
946            verboselog(machine, 2, "GBA IO Register Read: JOY_RECV_MSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, ( gba_state->JOY_RECV & 0xffff0000 ) >> 16 );
947            retval |= gba_state->JOY_RECV & 0xffff0000;
946            verboselog(machine, 2, "GBA IO Register Read: JOY_RECV_MSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, ( state->JOY_RECV & 0xffff0000 ) >> 16 );
947            retval |= state->JOY_RECV & 0xffff0000;
948948         }
949949         break;
950950      case 0x0154/4:
951951         if( (mem_mask) & 0x0000ffff )
952952         {
953            verboselog(machine, 2, "GBA IO Register Read: JOY_TRANS_LSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->JOY_TRANS & 0x0000ffff );
954            retval |= gba_state->JOY_TRANS & 0x0000ffff;
953            verboselog(machine, 2, "GBA IO Register Read: JOY_TRANS_LSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->JOY_TRANS & 0x0000ffff );
954            retval |= state->JOY_TRANS & 0x0000ffff;
955955         }
956956         if( (mem_mask) & 0xffff0000 )
957957         {
958            verboselog(machine, 2, "GBA IO Register Read: JOY_TRANS_MSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, ( gba_state->JOY_TRANS & 0xffff0000 ) >> 16 );
959            retval |= gba_state->JOY_TRANS & 0xffff0000;
958            verboselog(machine, 2, "GBA IO Register Read: JOY_TRANS_MSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, ( state->JOY_TRANS & 0xffff0000 ) >> 16 );
959            retval |= state->JOY_TRANS & 0xffff0000;
960960         }
961961         break;
962962      case 0x0158/4:
963963         if( (mem_mask) & 0x0000ffff )
964964         {
965            verboselog(machine, 2, "GBA IO Register Read: JOYSTAT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->JOYSTAT );
966            retval |= gba_state->JOYSTAT;
965            verboselog(machine, 2, "GBA IO Register Read: JOYSTAT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->JOYSTAT );
966            retval |= state->JOYSTAT;
967967         }
968968         if( (mem_mask) & 0xffff0000 )
969969         {
r7509r7510
973973      case 0x0200/4:
974974         if( (mem_mask) & 0x0000ffff )
975975         {
976//              printf("Read: IE (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->IE );
976//              printf("Read: IE (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->IE );
977977         }
978978         if( (mem_mask) & 0xffff0000 )
979979         {
980            verboselog(machine, 2, "GBA IO Register Read: IF (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->IF );
980            verboselog(machine, 2, "GBA IO Register Read: IF (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->IF );
981981         }
982982
983         retval = gba_state->IE | (gba_state->IF<<16);
983         retval = state->IE | (state->IF<<16);
984984         break;
985985      case 0x0204/4:
986986         if( (mem_mask) & 0x0000ffff )
987987         {
988            verboselog(machine, 2, "GBA IO Register Read: WAITCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->WAITCNT );
989            retval |= gba_state->WAITCNT;
988            verboselog(machine, 2, "GBA IO Register Read: WAITCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->WAITCNT );
989            retval |= state->WAITCNT;
990990         }
991991         if( (mem_mask) & 0xffff0000 )
992992         {
r7509r7510
996996      case 0x0208/4:
997997         if( (mem_mask) & 0x0000ffff )
998998         {
999            verboselog(machine, 2, "GBA IO Register Read: IME (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->IME );
1000            retval |= gba_state->IME;
999            verboselog(machine, 2, "GBA IO Register Read: IME (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->IME );
1000            retval |= state->IME;
10011001         }
10021002         if( (mem_mask) & 0xffff0000 )
10031003         {
r7509r7510
10051005         }
10061006         break;
10071007      case 0x0300/4:
1008         retval = gba_state->HALTCNT << 8;
1008         retval = state->HALTCNT << 8;
10091009         break;
10101010      default:
10111011//          verboselog(machine, 0, "Unknown GBA I/O register Read: %08x (%08x)\n", 0x04000000 + ( offset << 2 ), ~mem_mask );
r7509r7510
10181018{
10191019   running_machine *machine = space->machine;
10201020   running_device *gb_device = devtag_get_device(space->machine, "custom");
1021   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
1021   gba_state *state = (gba_state *)machine->driver_data;
10221022
10231023   switch( offset )
10241024   {
r7509r7510
10261026         if( (mem_mask) & 0x0000ffff )
10271027         {
10281028            verboselog(machine, 2, "GBA IO Register Write: DISPCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1029            gba_state->DISPCNT = ( gba_state->DISPCNT & ~mem_mask ) | ( data & mem_mask );
1030            if(gba_state->DISPCNT & (DISPCNT_WIN0_EN | DISPCNT_WIN1_EN))
1029            state->DISPCNT = ( state->DISPCNT & ~mem_mask ) | ( data & mem_mask );
1030            if(state->DISPCNT & (DISPCNT_WIN0_EN | DISPCNT_WIN1_EN))
10311031            {
1032               gba_state->windowOn = 1;
1032               state->windowOn = 1;
10331033            }
10341034            else
10351035            {
1036               gba_state->windowOn = 0;
1036               state->windowOn = 0;
10371037            }
10381038         }
10391039         if( (mem_mask) & 0xffff0000 )
10401040         {
10411041            verboselog(machine, 2, "GBA IO Register Write: Green Swap (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1042            gba_state->GRNSWAP = ( gba_state->GRNSWAP & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1042            state->GRNSWAP = ( state->GRNSWAP & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
10431043         }
10441044         break;
10451045      case 0x0004/4:
1046         COMBINE_DATA(&gba_state->DISPSTAT);
1046         COMBINE_DATA(&state->DISPSTAT);
10471047         break;
10481048      case 0x0008/4:
10491049         if( (mem_mask) & 0x0000ffff )
10501050         {
10511051            verboselog(machine, 2, "GBA IO Register Write: BG0CNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1052            gba_state->BG0CNT = ( gba_state->BG0CNT & ~mem_mask ) | ( data & mem_mask );
1052            state->BG0CNT = ( state->BG0CNT & ~mem_mask ) | ( data & mem_mask );
10531053         }
10541054         if( (mem_mask) & 0xffff0000 )
10551055         {
10561056            verboselog(machine, 2, "GBA IO Register Write: BG1CNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1057                gba_state->BG1CNT = ( gba_state->BG1CNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1057                state->BG1CNT = ( state->BG1CNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
10581058         }
10591059         break;
10601060      case 0x000c/4:
10611061         if( (mem_mask) & 0x0000ffff )
10621062         {
10631063            verboselog(machine, 2, "GBA IO Register Write: BG2CNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1064            gba_state->BG2CNT = ( gba_state->BG2CNT & ~mem_mask ) | ( data & mem_mask );
1064            state->BG2CNT = ( state->BG2CNT & ~mem_mask ) | ( data & mem_mask );
10651065         }
10661066         if( (mem_mask) & 0xffff0000 )
10671067         {
10681068            verboselog(machine, 2, "GBA IO Register Write: BG3CNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1069                gba_state->BG3CNT = ( gba_state->BG3CNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1069                state->BG3CNT = ( state->BG3CNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
10701070         }
10711071         break;
10721072      case 0x0010/4:
10731073         if( (mem_mask) & 0x0000ffff )
10741074         {
10751075            verboselog(machine, 2, "GBA IO Register Write: BG0HOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1076            gba_state->BG0HOFS = ( gba_state->BG0HOFS & ~mem_mask ) | ( data & mem_mask );
1076            state->BG0HOFS = ( state->BG0HOFS & ~mem_mask ) | ( data & mem_mask );
10771077         }
10781078         if( (mem_mask) & 0xffff0000 )
10791079         {
10801080            verboselog(machine, 2, "GBA IO Register Write: BG0VOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1081                gba_state->BG0VOFS = ( gba_state->BG0VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1081                state->BG0VOFS = ( state->BG0VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
10821082         }
10831083         break;
10841084      case 0x0014/4:
10851085         if( (mem_mask) & 0x0000ffff )
10861086         {
10871087            verboselog(machine, 2, "GBA IO Register Write: BG1HOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1088            gba_state->BG1HOFS = ( gba_state->BG1HOFS & ~mem_mask ) | ( data & mem_mask );
1088            state->BG1HOFS = ( state->BG1HOFS & ~mem_mask ) | ( data & mem_mask );
10891089         }
10901090         if( (mem_mask) & 0xffff0000 )
10911091         {
10921092            verboselog(machine, 2, "GBA IO Register Write: BG1VOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1093                gba_state->BG1VOFS = ( gba_state->BG1VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1093                state->BG1VOFS = ( state->BG1VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
10941094         }
10951095         break;
10961096      case 0x0018/4:
10971097         if( (mem_mask) & 0x0000ffff )
10981098         {
10991099            verboselog(machine, 2, "GBA IO Register Write: BG2HOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1100            gba_state->BG2HOFS = ( gba_state->BG2HOFS & ~mem_mask ) | ( data & mem_mask );
1100            state->BG2HOFS = ( state->BG2HOFS & ~mem_mask ) | ( data & mem_mask );
11011101         }
11021102         if( (mem_mask) & 0xffff0000 )
11031103         {
11041104            verboselog(machine, 2, "GBA IO Register Write: BG2VOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1105                gba_state->BG2VOFS = ( gba_state->BG2VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1105                state->BG2VOFS = ( state->BG2VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
11061106         }
11071107         break;
11081108      case 0x001c/4:
11091109         if( (mem_mask) & 0x0000ffff )
11101110         {
11111111            verboselog(machine, 2, "GBA IO Register Write: BG3HOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1112            gba_state->BG3HOFS = ( gba_state->BG3HOFS & ~mem_mask ) | ( data & mem_mask );
1112            state->BG3HOFS = ( state->BG3HOFS & ~mem_mask ) | ( data & mem_mask );
11131113         }
11141114         if( (mem_mask) & 0xffff0000 )
11151115         {
11161116            verboselog(machine, 2, "GBA IO Register Write: BG3VOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1117                gba_state->BG3VOFS = ( gba_state->BG3VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1117                state->BG3VOFS = ( state->BG3VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
11181118         }
11191119         break;
11201120      case 0x0020/4:
11211121         if( (mem_mask) & 0x0000ffff )
11221122         {
11231123            verboselog(machine, 2, "GBA IO Register Write: BG2PA (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1124            gba_state->BG2PA = ( gba_state->BG2PA & ~mem_mask ) | ( data & mem_mask );
1124            state->BG2PA = ( state->BG2PA & ~mem_mask ) | ( data & mem_mask );
11251125         }
11261126         if( (mem_mask) & 0xffff0000 )
11271127         {
11281128            verboselog(machine, 2, "GBA IO Register Write: BG2PB (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1129                gba_state->BG2PB = ( gba_state->BG2PB & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1129                state->BG2PB = ( state->BG2PB & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
11301130         }
11311131         break;
11321132      case 0x0024/4:
11331133         if( (mem_mask) & 0x0000ffff )
11341134         {
11351135            verboselog(machine, 2, "GBA IO Register Write: BG2PC (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1136            gba_state->BG2PC = ( gba_state->BG2PC & ~mem_mask ) | ( data & mem_mask );
1136            state->BG2PC = ( state->BG2PC & ~mem_mask ) | ( data & mem_mask );
11371137         }
11381138         if( (mem_mask) & 0xffff0000 )
11391139         {
11401140            verboselog(machine, 2, "GBA IO Register Write: BG2PD (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1141                gba_state->BG2PD = ( gba_state->BG2PD & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1141                state->BG2PD = ( state->BG2PD & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
11421142         }
11431143         break;
11441144      case 0x0028/4:
r7509r7510
11501150         {
11511151            verboselog(machine, 2, "GBA IO Register Write: BG2X_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
11521152         }
1153         COMBINE_DATA(&gba_state->BG2X);
1154         gba_state->gfxBG2Changed |= 1;
1153         COMBINE_DATA(&state->BG2X);
1154         state->gfxBG2Changed |= 1;
11551155         break;
11561156      case 0x002c/4:
11571157         if( (mem_mask) & 0x0000ffff )
r7509r7510
11621162         {
11631163            verboselog(machine, 2, "GBA IO Register Write: BG2Y_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
11641164         }
1165         COMBINE_DATA(&gba_state->BG2Y);
1166         gba_state->gfxBG2Changed |= 2;
1165         COMBINE_DATA(&state->BG2Y);
1166         state->gfxBG2Changed |= 2;
11671167         break;
11681168      case 0x0030/4:
11691169         if( (mem_mask) & 0x0000ffff )
11701170         {
11711171            verboselog(machine, 2, "GBA IO Register Write: BG3PA (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1172            gba_state->BG3PA = ( gba_state->BG3PA & ~mem_mask ) | ( data & mem_mask );
1172            state->BG3PA = ( state->BG3PA & ~mem_mask ) | ( data & mem_mask );
11731173         }
11741174         if( (mem_mask) & 0xffff0000 )
11751175         {
11761176            verboselog(machine, 2, "GBA IO Register Write: BG3PB (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1177                gba_state->BG3PB = ( gba_state->BG3PB & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1177                state->BG3PB = ( state->BG3PB & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
11781178         }
11791179         break;
11801180      case 0x0034/4:
11811181         if( (mem_mask) & 0x0000ffff )
11821182         {
11831183            verboselog(machine, 2, "GBA IO Register Write: BG3PC (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1184            gba_state->BG3PC = ( gba_state->BG3PC & ~mem_mask ) | ( data & mem_mask );
1184            state->BG3PC = ( state->BG3PC & ~mem_mask ) | ( data & mem_mask );
11851185         }
11861186         if( (mem_mask) & 0xffff0000 )
11871187         {
11881188            verboselog(machine, 2, "GBA IO Register Write: BG3PD (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1189                gba_state->BG3PD = ( gba_state->BG3PD & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1189                state->BG3PD = ( state->BG3PD & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
11901190         }
11911191         break;
11921192      case 0x0038/4:
r7509r7510
11981198         {
11991199            verboselog(machine, 2, "GBA IO Register Write: BG3X_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
12001200         }
1201         COMBINE_DATA(&gba_state->BG3X);
1202         gba_state->gfxBG3Changed |= 1;
1201         COMBINE_DATA(&state->BG3X);
1202         state->gfxBG3Changed |= 1;
12031203         break;
12041204      case 0x003c/4:
12051205         if( (mem_mask) & 0x0000ffff )
r7509r7510
12101210         {
12111211            verboselog(machine, 2, "GBA IO Register Write: BG3Y_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
12121212         }
1213         COMBINE_DATA(&gba_state->BG3Y);
1214         gba_state->gfxBG3Changed |= 2;
1213         COMBINE_DATA(&state->BG3Y);
1214         state->gfxBG3Changed |= 2;
12151215         break;
12161216      case 0x0040/4:
12171217         if( (mem_mask) & 0x0000ffff )
12181218         {
12191219            verboselog(machine, 2, "GBA IO Register Write: WIN0H (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1220            gba_state->WIN0H = ( gba_state->WIN0H & ~mem_mask ) | ( data & mem_mask );
1220            state->WIN0H = ( state->WIN0H & ~mem_mask ) | ( data & mem_mask );
12211221         }
12221222         if( (mem_mask) & 0xffff0000 )
12231223         {
12241224            verboselog(machine, 2, "GBA IO Register Write: WIN1H (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1225                gba_state->WIN1H = ( gba_state->WIN1H & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1225                state->WIN1H = ( state->WIN1H & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
12261226         }
12271227         break;
12281228      case 0x0044/4:
12291229         if( (mem_mask) & 0x0000ffff )
12301230         {
12311231            verboselog(machine, 2, "GBA IO Register Write: WIN0V (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1232            gba_state->WIN0V = ( gba_state->WIN0V & ~mem_mask ) | ( data & mem_mask );
1232            state->WIN0V = ( state->WIN0V & ~mem_mask ) | ( data & mem_mask );
12331233         }
12341234         if( (mem_mask) & 0xffff0000 )
12351235         {
12361236            verboselog(machine, 2, "GBA IO Register Write: WIN1V (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1237                gba_state->WIN1V = ( gba_state->WIN1V & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1237                state->WIN1V = ( state->WIN1V & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
12381238         }
12391239         break;
12401240      case 0x0048/4:
12411241         if( (mem_mask) & 0x0000ffff )
12421242         {
12431243            verboselog(machine, 2, "GBA IO Register Write: WININ (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1244            gba_state->WININ = ( gba_state->WININ & ~mem_mask ) | ( data & mem_mask );
1244            state->WININ = ( state->WININ & ~mem_mask ) | ( data & mem_mask );
12451245         }
12461246         if( (mem_mask) & 0xffff0000 )
12471247         {
12481248            verboselog(machine, 2, "GBA IO Register Write: WINOUT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1249                gba_state->WINOUT = ( gba_state->WINOUT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1249                state->WINOUT = ( state->WINOUT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
12501250         }
12511251         break;
12521252      case 0x004c/4:
12531253         if( (mem_mask) & 0x0000ffff )
12541254         {
12551255            verboselog(machine, 2, "GBA IO Register Write: MOSAIC (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1256            gba_state->MOSAIC = ( gba_state->MOSAIC & ~mem_mask ) | ( data & mem_mask );
1256            state->MOSAIC = ( state->MOSAIC & ~mem_mask ) | ( data & mem_mask );
12571257         }
12581258         if( (mem_mask) & 0xffff0000 )
12591259         {
r7509r7510
12641264         if( (mem_mask) & 0x0000ffff )
12651265         {
12661266            verboselog(machine, 2, "GBA IO Register Write: BLDCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1267            gba_state->BLDCNT = ( gba_state->BLDCNT & ~mem_mask ) | ( data & mem_mask );
1268            if(gba_state->BLDCNT & BLDCNT_SFX)
1267            state->BLDCNT = ( state->BLDCNT & ~mem_mask ) | ( data & mem_mask );
1268            if(state->BLDCNT & BLDCNT_SFX)
12691269            {
1270               gba_state->fxOn = 1;
1270               state->fxOn = 1;
12711271            }
12721272            else
12731273            {
1274               gba_state->fxOn = 0;
1274               state->fxOn = 0;
12751275            }
12761276         }
12771277         if( (mem_mask) & 0xffff0000 )
12781278         {
12791279            verboselog(machine, 2, "GBA IO Register Write: BLDALPHA (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask );
1280                gba_state->BLDALPHA = ( gba_state->BLDALPHA & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1280                state->BLDALPHA = ( state->BLDALPHA & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
12811281         }
12821282         break;
12831283      case 0x0054/4:
12841284         if( (mem_mask) & 0x0000ffff )
12851285         {
12861286            verboselog(machine, 2, "GBA IO Register Write: BLDY (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1287            gba_state->BLDY = ( gba_state->BLDY & ~mem_mask ) | ( data & mem_mask );
1287            state->BLDY = ( state->BLDY & ~mem_mask ) | ( data & mem_mask );
12881288         }
12891289         if( (mem_mask) & 0xffff0000 )
12901290         {
r7509r7510
14121412         if ((mem_mask) & 0xffff0000)
14131413         {
14141414            data >>= 16;
1415            gba_state->SOUNDCNT_H = data;
1415            state->SOUNDCNT_H = data;
14161416
14171417            // DAC A reset?
14181418            if (data & 0x0800)
r7509r7510
14201420               running_device *gb_a_l = devtag_get_device(machine, "direct_a_left");
14211421               running_device *gb_a_r = devtag_get_device(machine, "direct_a_right");
14221422
1423               gba_state->fifo_a_ptr = 17;
1424               gba_state->fifo_a_in = 17;
1423               state->fifo_a_ptr = 17;
1424               state->fifo_a_in = 17;
14251425               dac_signed_data_w(gb_a_l, 0x80);
14261426               dac_signed_data_w(gb_a_r, 0x80);
14271427            }
r7509r7510
14321432               running_device *gb_b_l = devtag_get_device(machine, "direct_b_left");
14331433               running_device *gb_b_r = devtag_get_device(machine, "direct_b_right");
14341434
1435               gba_state->fifo_b_ptr = 17;
1436               gba_state->fifo_b_in = 17;
1435               state->fifo_b_ptr = 17;
1436               state->fifo_b_in = 17;
14371437               dac_signed_data_w(gb_b_l, 0x80);
14381438               dac_signed_data_w(gb_b_r, 0x80);
14391439            }
r7509r7510
14481448            running_device *gb_b_r = devtag_get_device(machine, "direct_b_right");
14491449
14501450            gb_sound_w(gb_device, 0x16, data);
1451            if ((data & 0x80) && !(gba_state->SOUNDCNT_X & 0x80))
1451            if ((data & 0x80) && !(state->SOUNDCNT_X & 0x80))
14521452            {
1453               gba_state->fifo_a_ptr = gba_state->fifo_a_in = 17;
1454               gba_state->fifo_b_ptr = gba_state->fifo_b_in = 17;
1453               state->fifo_a_ptr = state->fifo_a_in = 17;
1454               state->fifo_b_ptr = state->fifo_b_in = 17;
14551455               dac_signed_data_w(gb_a_l, 0x80);
14561456               dac_signed_data_w(gb_a_r, 0x80);
14571457               dac_signed_data_w(gb_b_l, 0x80);
14581458               dac_signed_data_w(gb_b_r, 0x80);
14591459            }
1460            gba_state->SOUNDCNT_X = data;
1460            state->SOUNDCNT_X = data;
14611461         }
14621462         break;
14631463      case 0x0088/4:
14641464         if( (mem_mask) & 0x0000ffff )
14651465         {
14661466            verboselog(machine, 2, "GBA IO Register Write: SOUNDBIAS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask );
1467            gba_state->SOUNDBIAS = ( gba_state->SOUNDBIAS & ~mem_mask ) | ( data & mem_mask );
1467            state->SOUNDBIAS = ( state->SOUNDBIAS & ~mem_mask ) | ( data & mem_mask );
14681468         }
14691469         if( (mem_mask) & 0xffff0000 )
14701470         {
r7509r7510
15441544         }
15451545         break;
15461546      case 0x00a0/4:
1547         gba_state->fifo_a_in %= 17;
1548         gba_state->fifo_a[gba_state->fifo_a_in++] = (data)&0xff;
1549         gba_state->fifo_a_in %= 17;
1550         gba_state->fifo_a[gba_state->fifo_a_in++] = (data>>8)&0xff;
1551         gba_state->fifo_a_in %= 17;
1552         gba_state->fifo_a[gba_state->fifo_a_in++] = (data>>16)&0xff;
1553         gba_state->fifo_a_in %= 17;
1554         gba_state->fifo_a[gba_state->fifo_a_in++] = (data>>24)&0xff;
1547         state->fifo_a_in %= 17;
1548         state->fifo_a[state->fifo_a_in++] = (data)&0xff;
1549         state->fifo_a_in %= 17;
1550         state->fifo_a[state->fifo_a_in++] = (data>>8)&0xff;
1551         state->fifo_a_in %= 17;
1552         state->fifo_a[state->fifo_a_in++] = (data>>16)&0xff;
1553         state->fifo_a_in %= 17;
1554         state->fifo_a[state->fifo_a_in++] = (data>>24)&0xff;
15551555         break;
15561556      case 0x00a4/4:
1557         gba_state->fifo_b_in %= 17;
1558         gba_state->fifo_b[gba_state->fifo_b_in++] = (data)&0xff;
1559         gba_state->fifo_b_in %= 17;
1560         gba_state->fifo_b[gba_state->fifo_b_in++] = (data>>8)&0xff;
1561         gba_state->fifo_b_in %= 17;
1562         gba_state->fifo_b[gba_state->fifo_b_in++] = (data>>16)&0xff;
1563         gba_state->fifo_b_in %= 17;
1564         gba_state->fifo_b[gba_state->fifo_b_in++] = (data>>24)&0xff;
1557         state->fifo_b_in %= 17;
1558         state->fifo_b[state->fifo_b_in++] = (data)&0xff;
1559         state->fifo_b_in %= 17;
1560         state->fifo_b[state->fifo_b_in++] = (data>>8)&0xff;
1561         state->fifo_b_in %= 17;
1562         state->fifo_b[state->fifo_b_in++] = (data>>16)&0xff;
1563         state->fifo_b_in %= 17;
1564         state->fifo_b[state->fifo_b_in++] = (data>>24)&0xff;
15651565         break;
15661566      case 0x00b0/4:
15671567      case 0x00b4/4:
r7509r7510
15941594               // retrigger/restart on a rising edge.
15951595               // also reload internal regs
15961596               // (note: Metroid Fusion fails if we enforce the "rising edge" requirement...)
1597               if (ctrl & 0x8000) //&& !(gba_state->dma_regs[offset] & 0x80000000))
1597               if (ctrl & 0x8000) //&& !(state->dma_regs[offset] & 0x80000000))
15981598               {
1599                  gba_state->dma_src[ch] = gba_state->dma_regs[(ch*3)+0];
1600                  gba_state->dma_dst[ch] = gba_state->dma_regs[(ch*3)+1];
1601                  gba_state->dma_srcadd[ch] = (ctrl>>7)&3;
1602                  gba_state->dma_dstadd[ch] = (ctrl>>5)&3;
1599                  state->dma_src[ch] = state->dma_regs[(ch*3)+0];
1600                  state->dma_dst[ch] = state->dma_regs[(ch*3)+1];
1601                  state->dma_srcadd[ch] = (ctrl>>7)&3;
1602                  state->dma_dstadd[ch] = (ctrl>>5)&3;
16031603
1604                        COMBINE_DATA(&gba_state->dma_regs[offset]);
1605                        gba_state->dma_cnt[ch] = gba_state->dma_regs[(ch*3)+2]&0xffff;
1604                        COMBINE_DATA(&state->dma_regs[offset]);
1605                        state->dma_cnt[ch] = state->dma_regs[(ch*3)+2]&0xffff;
16061606
16071607                        // immediate start
16081608                  if ((ctrl & 0x3000) == 0)
r7509r7510
16131613               }
16141614            }
16151615
1616            COMBINE_DATA(&gba_state->dma_regs[offset]);
1616            COMBINE_DATA(&state->dma_regs[offset]);
16171617         }
16181618         break;
16191619      case 0x0100/4:
r7509r7510
16251625
16261626            offset -= (0x100/4);
16271627
1628            COMBINE_DATA(&gba_state->timer_regs[offset]);
1628            COMBINE_DATA(&state->timer_regs[offset]);
16291629
16301630//              printf("%x to timer %d (mask %x PC %x)\n", data, offset, ~mem_mask, cpu_get_pc(space->cpu));
16311631
16321632            if (ACCESSING_BITS_0_15)
16331633            {
1634                    gba_state->timer_reload[offset] = ( gba_state->timer_reload[offset] & ~mem_mask ) | ( ( data & 0x0000ffff ) & mem_mask );
1634                    state->timer_reload[offset] = ( state->timer_reload[offset] & ~mem_mask ) | ( ( data & 0x0000ffff ) & mem_mask );
16351635            }
16361636
16371637            // enabling this timer?
r7509r7510
16391639            {
16401640               double final;
16411641
1642               rate = 0x10000 - (gba_state->timer_regs[offset] & 0xffff);
1642               rate = 0x10000 - (state->timer_regs[offset] & 0xffff);
16431643
1644               clocksel = timer_clks[(gba_state->timer_regs[offset] >> 16) & 3];
1644               clocksel = timer_clks[(state->timer_regs[offset] >> 16) & 3];
16451645
16461646               final = clocksel / rate;
16471647
1648               gba_state->timer_hz[offset] = final;
1648               state->timer_hz[offset] = final;
16491649
16501650//                  printf("Enabling timer %d @ %f Hz\n", offset, final);
16511651
16521652               // enable the timer
16531653               if( !(data & 0x40000) ) // if we're not in Count-Up mode
16541654               {
1655                  timer_adjust_periodic(gba_state->tmr_timer[offset], ATTOTIME_IN_HZ(final), offset, ATTOTIME_IN_HZ(final));
1655                  timer_adjust_periodic(state->tmr_timer[offset], ATTOTIME_IN_HZ(final), offset, ATTOTIME_IN_HZ(final));
16561656               }
16571657            }
16581658         }
r7509r7510
16611661         if( (mem_mask) & 0x0000ffff )
16621662         {
16631663            verboselog(machine, 2, "GBA IO Register Write: SIOMULTI0 (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask );
1664            gba_state->SIOMULTI0 = ( gba_state->SIOMULTI0 & ~mem_mask ) | ( data & mem_mask );
1664            state->SIOMULTI0 = ( state->SIOMULTI0 & ~mem_mask ) | ( data & mem_mask );
16651665         }
16661666         if( (mem_mask) & 0xffff0000 )
16671667         {
16681668            verboselog(machine, 2, "GBA IO Register Write: SIOMULTI1 (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask );
1669                gba_state->SIOMULTI1 = ( gba_state->SIOMULTI1 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1669                state->SIOMULTI1 = ( state->SIOMULTI1 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
16701670         }
16711671         break;
16721672      case 0x0124/4:
16731673         if( (mem_mask) & 0x0000ffff )
16741674         {
16751675            verboselog(machine, 2, "GBA IO Register Write: SIOMULTI2 (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask );
1676            gba_state->SIOMULTI2 = ( gba_state->SIOMULTI2 & ~mem_mask ) | ( data & mem_mask );
1676            state->SIOMULTI2 = ( state->SIOMULTI2 & ~mem_mask ) | ( data & mem_mask );
16771677         }
16781678         if( (mem_mask) & 0xffff0000 )
16791679         {
16801680            verboselog(machine, 2, "GBA IO Register Write: SIOMULTI3 (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask );
1681                gba_state->SIOMULTI3 = ( gba_state->SIOMULTI3 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1681                state->SIOMULTI3 = ( state->SIOMULTI3 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
16821682         }
16831683         break;
16841684      case 0x0128/4:
16851685         if( (mem_mask) & 0x0000ffff )
16861686         {
16871687            verboselog(machine, 2, "GBA IO Register Write: SIOCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask );
1688            gba_state->SIOCNT = ( gba_state->SIOCNT & ~mem_mask ) | ( data & mem_mask );
1688            state->SIOCNT = ( state->SIOCNT & ~mem_mask ) | ( data & mem_mask );
16891689         }
16901690         if( (mem_mask) & 0xffff0000 )
16911691         {
16921692            verboselog(machine, 2, "GBA IO Register Write: SIODATA8 (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask );
1693                gba_state->SIODATA8 = ( gba_state->SIODATA8 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1693                state->SIODATA8 = ( state->SIODATA8 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
16941694         }
16951695         break;
16961696      case 0x0130/4:
r7509r7510
16981698         {
16991699//              printf("KEYCNT = %04x\n", data>>16);
17001700            verboselog(machine, 2, "GBA IO Register Write: KEYCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask );
1701                gba_state->KEYCNT = ( gba_state->KEYCNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1701                state->KEYCNT = ( state->KEYCNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
17021702         }
17031703         break;
17041704      case 0x0134/4:
17051705         if( (mem_mask) & 0x0000ffff )
17061706         {
17071707            verboselog(machine, 2, "GBA IO Register Write: RCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask );
1708            gba_state->RCNT = ( gba_state->RCNT & ~mem_mask ) | ( data & mem_mask );
1708            state->RCNT = ( state->RCNT & ~mem_mask ) | ( data & mem_mask );
17091709         }
17101710         if( (mem_mask) & 0xffff0000 )
17111711         {
17121712            verboselog(machine, 2, "GBA IO Register Write: IR (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask );
1713                gba_state->IR = ( gba_state->IR & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1713                state->IR = ( state->IR & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
17141714         }
17151715         break;
17161716      case 0x0140/4:
17171717         if( (mem_mask) & 0x0000ffff )
17181718         {
17191719            verboselog(machine, 2, "GBA IO Register Write: JOYCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask );
1720            gba_state->JOYCNT = ( gba_state->JOYCNT & ~mem_mask ) | ( data & mem_mask );
1720            state->JOYCNT = ( state->JOYCNT & ~mem_mask ) | ( data & mem_mask );
17211721         }
17221722         if( (mem_mask) & 0xffff0000 )
17231723         {
r7509r7510
17281728         if( (mem_mask) & 0x0000ffff )
17291729         {
17301730            verboselog(machine, 2, "GBA IO Register Write: JOY_RECV_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask );
1731            gba_state->JOY_RECV = ( gba_state->JOY_RECV & ~mem_mask ) | ( data & mem_mask );
1731            state->JOY_RECV = ( state->JOY_RECV & ~mem_mask ) | ( data & mem_mask );
17321732         }
17331733         if( (mem_mask) & 0xffff0000 )
17341734         {
17351735            verboselog(machine, 2, "GBA IO Register Write: JOY_RECV_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask );
1736                gba_state->JOY_RECV = ( gba_state->JOY_RECV & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1736                state->JOY_RECV = ( state->JOY_RECV & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
17371737         }
17381738         break;
17391739      case 0x0154/4:
17401740         if( (mem_mask) & 0x0000ffff )
17411741         {
17421742            verboselog(machine, 2, "GBA IO Register Write: JOY_TRANS_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask );
1743            gba_state->JOY_TRANS = ( gba_state->JOY_TRANS & ~mem_mask ) | ( data & mem_mask );
1743            state->JOY_TRANS = ( state->JOY_TRANS & ~mem_mask ) | ( data & mem_mask );
17441744         }
17451745         if( (mem_mask) & 0xffff0000 )
17461746         {
17471747            verboselog(machine, 2, "GBA IO Register Write: JOY_TRANS_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask );
1748                gba_state->JOY_TRANS = ( gba_state->JOY_TRANS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
1748                state->JOY_TRANS = ( state->JOY_TRANS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 );
17491749         }
17501750         break;
17511751      case 0x0158/4:
17521752         if( (mem_mask) & 0x0000ffff )
17531753         {
17541754            verboselog(machine, 2, "GBA IO Register Write: JOYSTAT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask );
1755            gba_state->JOYSTAT = ( gba_state->JOYSTAT & ~mem_mask ) | ( data & mem_mask );
1755            state->JOYSTAT = ( state->JOYSTAT & ~mem_mask ) | ( data & mem_mask );
17561756         }
17571757         if( (mem_mask) & 0xffff0000 )
17581758         {
r7509r7510
17631763         if( (mem_mask) & 0x0000ffff )
17641764         {
17651765//              printf("IE (%08x) = %04x raw %x (%08x) (scan %d PC %x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, data, ~mem_mask, video_screen_get_vpos(machine->primary_screen), cpu_get_pc(space->cpu));
1766            gba_state->IE = ( gba_state->IE & ~mem_mask ) | ( data & mem_mask );
1766            state->IE = ( state->IE & ~mem_mask ) | ( data & mem_mask );
17671767#if 0
1768            if (gba_state->IE & gba_state->IF)
1768            if (state->IE & state->IF)
17691769            {
1770               gba_request_irq(machine, gba_state->IF);
1770               gba_request_irq(machine, state->IF);
17711771            }
17721772#endif
17731773         }
17741774         if( (mem_mask) & 0xffff0000 )
17751775         {
17761776            verboselog(machine, 2, "GBA IO Register Write: IF (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ) + 2, ( data & mem_mask ) >> 16, ~mem_mask );
1777            gba_state->IF &= ~( ( data & mem_mask ) >> 16 );
1777            state->IF &= ~( ( data & mem_mask ) >> 16 );
17781778
17791779            // if we still have interrupts, yank the IRQ line again
1780            if (gba_state->IF)
1780            if (state->IF)
17811781            {
1782               timer_adjust_oneshot(gba_state->irq_timer, cpu_clocks_to_attotime(devtag_get_device(machine, "maincpu"), 120), 0);
1782               timer_adjust_oneshot(state->irq_timer, cpu_clocks_to_attotime(devtag_get_device(machine, "maincpu"), 120), 0);
17831783            }
17841784         }
17851785         break;
r7509r7510
17871787         if( (mem_mask) & 0x0000ffff )
17881788         {
17891789            verboselog(machine, 2, "GBA IO Register Write: WAITCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask );
1790            gba_state->WAITCNT = ( gba_state->WAITCNT & ~mem_mask ) | ( data & mem_mask );
1790            state->WAITCNT = ( state->WAITCNT & ~mem_mask ) | ( data & mem_mask );
17911791         }
17921792         if( (mem_mask) & 0xffff0000 )
17931793         {
r7509r7510
17981798         if( (mem_mask) & 0x0000ffff )
17991799         {
18001800            verboselog(machine, 3, "GBA IO Register Write: IME (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask );
1801            gba_state->IME = ( gba_state->IME & ~mem_mask ) | ( data & mem_mask );
1802            if (gba_state->IF)
1801            state->IME = ( state->IME & ~mem_mask ) | ( data & mem_mask );
1802            if (state->IF)
18031803            {
1804               timer_adjust_oneshot(gba_state->irq_timer, attotime_zero, 0);
1804               timer_adjust_oneshot(state->irq_timer, attotime_zero, 0);
18051805            }
18061806         }
18071807         if( (mem_mask) & 0xffff0000 )
r7509r7510
18151815            if( (mem_mask) & 0x000000ff )
18161816            {
18171817               verboselog(machine, 2, "GBA IO Register Write: POSTFLG (%08x) = %02x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x000000ff, ~mem_mask );
1818               gba_state->POSTFLG = data & 0x000000ff;
1818               state->POSTFLG = data & 0x000000ff;
18191819            }
18201820            else
18211821            {
1822               gba_state->HALTCNT = data & 0x000000ff;
1822               state->HALTCNT = data & 0x000000ff;
18231823
18241824               // either way, wait for an IRQ
18251825               cpu_spinuntil_int(devtag_get_device(machine, "maincpu"));
r7509r7510
18661866static WRITE32_HANDLER(gba_pram_w)
18671867{
18681868   running_machine *machine = space->machine;
1869   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
1869   gba_state *state = (gba_state *)machine->driver_data;
18701870
1871   gba_state->gba_pram[offset] = COMBINE_DATA32_16(gba_state->gba_pram[offset], data, mem_mask);
1871   state->gba_pram[offset] = COMBINE_DATA32_16(state->gba_pram[offset], data, mem_mask);
18721872}
18731873
18741874static WRITE32_HANDLER(gba_vram_w)
18751875{
18761876   running_machine *machine = space->machine;
1877   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
1877   gba_state *state = (gba_state *)machine->driver_data;
18781878
1879   gba_state->gba_vram[offset] = COMBINE_DATA32_16(gba_state->gba_vram[offset], data, mem_mask);
1879   state->gba_vram[offset] = COMBINE_DATA32_16(state->gba_vram[offset], data, mem_mask);
18801880}
18811881
18821882static WRITE32_HANDLER(gba_oam_w)
18831883{
18841884   running_machine *machine = space->machine;
1885   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
1885   gba_state *state = (gba_state *)machine->driver_data;
18861886
1887   gba_state->gba_oam[offset] = COMBINE_DATA32_16(gba_state->gba_oam[offset], data, mem_mask);
1887   state->gba_oam[offset] = COMBINE_DATA32_16(state->gba_oam[offset], data, mem_mask);
18881888}
18891889
18901890static ADDRESS_MAP_START( gbadvance_map, ADDRESS_SPACE_PROGRAM, 32 )
r7509r7510
18921892   AM_RANGE(0x02000000, 0x0203ffff) AM_RAM AM_MIRROR(0xfc0000)
18931893   AM_RANGE(0x03000000, 0x03007fff) AM_RAM AM_MIRROR(0xff8000)
18941894   AM_RANGE(0x04000000, 0x040003ff) AM_READWRITE( gba_io_r, gba_io_w )
1895   AM_RANGE(0x05000000, 0x050003ff) AM_RAM_WRITE(gba_pram_w) AM_BASE_MEMBER(gba_state_t, gba_pram)   // Palette RAM
1896   AM_RANGE(0x06000000, 0x06017fff) AM_RAM_WRITE(gba_vram_w) AM_BASE_MEMBER(gba_state_t, gba_vram)   // VRAM
1897   AM_RANGE(0x07000000, 0x070003ff) AM_RAM_WRITE(gba_oam_w) AM_BASE_MEMBER(gba_state_t, gba_oam)   // OAM
1895   AM_RANGE(0x05000000, 0x050003ff) AM_RAM_WRITE(gba_pram_w) AM_BASE_MEMBER(gba_state, gba_pram)   // Palette RAM
1896   AM_RANGE(0x06000000, 0x06017fff) AM_RAM_WRITE(gba_vram_w) AM_BASE_MEMBER(gba_state, gba_vram)   // VRAM
1897   AM_RANGE(0x07000000, 0x070003ff) AM_RAM_WRITE(gba_oam_w) AM_BASE_MEMBER(gba_state, gba_oam)   // OAM
18981898   AM_RANGE(0x08000000, 0x09ffffff) AM_ROM AM_REGION("cartridge", 0)   // cartridge ROM (mirror 0)
18991899   AM_RANGE(0x0a000000, 0x0bffffff) AM_ROM AM_REGION("cartridge", 0)   // cartridge ROM (mirror 1)
19001900   AM_RANGE(0x0c000000, 0x0cffffff) AM_ROM AM_REGION("cartridge", 0)   // final mirror
r7509r7510
19181918static TIMER_CALLBACK( perform_hbl )
19191919{
19201920   int ch, ctrl;
1921   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
1921   gba_state *state = (gba_state *)machine->driver_data;
19221922   int scanline = video_screen_get_vpos(machine->primary_screen);
19231923
19241924   // draw only visible scanlines
r7509r7510
19261926   {
19271927      gba_draw_scanline(machine, scanline);
19281928   }
1929   gba_state->DISPSTAT |= DISPSTAT_HBL;
1930   if ((gba_state->DISPSTAT & DISPSTAT_HBL_IRQ_EN ) != 0)
1929   state->DISPSTAT |= DISPSTAT_HBL;
1930   if ((state->DISPSTAT & DISPSTAT_HBL_IRQ_EN ) != 0)
19311931   {
19321932      gba_request_irq(machine, INT_HBL);
19331933   }
19341934
19351935   for (ch = 0; ch < 4; ch++)
19361936   {
1937      ctrl = gba_state->dma_regs[(ch*3)+2]>>16;
1937      ctrl = state->dma_regs[(ch*3)+2]>>16;
19381938
19391939      // HBL-triggered DMA?
19401940      if ((ctrl & 0x8000) && ((ctrl & 0x3000) == 0x2000))
r7509r7510
19431943      }
19441944   }
19451945
1946   timer_adjust_oneshot(gba_state->hbl_timer, attotime_never, 0);
1946   timer_adjust_oneshot(state->hbl_timer, attotime_never, 0);
19471947}
19481948
19491949static TIMER_CALLBACK( perform_scan )
19501950{
19511951   int scanline;
1952   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
1952   gba_state *state = (gba_state *)machine->driver_data;
19531953
19541954   // clear hblank and raster IRQ flags
1955   gba_state->DISPSTAT &= ~(DISPSTAT_HBL|DISPSTAT_VCNT);
1955   state->DISPSTAT &= ~(DISPSTAT_HBL|DISPSTAT_VCNT);
19561956
19571957   scanline = video_screen_get_vpos(machine->primary_screen);
19581958
19591959   // VBL is set for scanlines 160 through 226 (but not 227, which is the last line)
19601960   if (scanline >= 160 && scanline < 227)
19611961   {
1962      gba_state->DISPSTAT |= DISPSTAT_VBL;
1962      state->DISPSTAT |= DISPSTAT_VBL;
19631963   }
19641964   else
19651965   {
1966      gba_state->DISPSTAT &= ~DISPSTAT_VBL;
1966      state->DISPSTAT &= ~DISPSTAT_VBL;
19671967   }
19681968
19691969   // handle VCNT match interrupt/flag
1970   if (scanline == ((gba_state->DISPSTAT >> 8) & 0xff))
1970   if (scanline == ((state->DISPSTAT >> 8) & 0xff))
19711971   {
1972      gba_state->DISPSTAT |= DISPSTAT_VCNT;
1973      if (gba_state->DISPSTAT & DISPSTAT_VCNT_IRQ_EN)
1972      state->DISPSTAT |= DISPSTAT_VCNT;
1973      if (state->DISPSTAT & DISPSTAT_VCNT_IRQ_EN)
19741974      {
19751975         gba_request_irq(machine, INT_VCNT);
19761976      }
r7509r7510
19811981   {
19821982      int ch, ctrl;
19831983
1984      if (gba_state->DISPSTAT & DISPSTAT_VBL_IRQ_EN)
1984      if (state->DISPSTAT & DISPSTAT_VBL_IRQ_EN)
19851985      {
19861986         gba_request_irq(machine, INT_VBL);
19871987      }
19881988
19891989      for (ch = 0; ch < 4; ch++)
19901990      {
1991         ctrl = gba_state->dma_regs[(ch*3)+2]>>16;
1991         ctrl = state->dma_regs[(ch*3)+2]>>16;
19921992
19931993         // VBL-triggered DMA?
19941994         if ((ctrl & 0x8000) && ((ctrl & 0x3000) == 0x1000))
r7509r7510
19981998      }
19991999   }
20002000
2001   timer_adjust_oneshot(gba_state->hbl_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline, 240), 0);
2002   timer_adjust_oneshot(gba_state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, ( scanline + 1 ) % 228, 0), 0);
2001   timer_adjust_oneshot(state->hbl_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline, 240), 0);
2002   timer_adjust_oneshot(state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, ( scanline + 1 ) % 228, 0), 0);
20032003}
20042004
20052005static MACHINE_RESET( gba )
r7509r7510
20082008   running_device *gb_a_r = devtag_get_device(machine, "direct_a_right");
20092009   running_device *gb_b_l = devtag_get_device(machine, "direct_b_left");
20102010   running_device *gb_b_r = devtag_get_device(machine, "direct_b_right");
2011   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
2011   gba_state *state = (gba_state *)machine->driver_data;
20122012
2013   memset(gba_state, 0, sizeof(gba_state));
2014   gba_state->SOUNDBIAS = 0x0200;
2015   gba_state->flash64k_state = FLASH_IDLEBYTE0;
2016   gba_state->eeprom_state = EEP_IDLE;
2017   gba_state->SIOMULTI0 = 0xffff;
2018   gba_state->SIOMULTI1 = 0xffff;
2019   gba_state->SIOMULTI2 = 0xffff;
2020   gba_state->SIOMULTI3 = 0xffff;
2021   gba_state->KEYCNT = 0x03ff;
2022   gba_state->RCNT = 0x8000;
2023   gba_state->JOYSTAT = 0x0002;
2024   gba_state->gfxBG2Changed = 0;
2025   gba_state->gfxBG3Changed = 0;
2026   gba_state->gfxBG2X = 0;
2027   gba_state->gfxBG2Y = 0;
2028   gba_state->gfxBG3X = 0;
2029   gba_state->gfxBG3Y = 0;
2013   memset(state, 0, sizeof(state));
2014   state->SOUNDBIAS = 0x0200;
2015   state->flash64k_state = FLASH_IDLEBYTE0;
2016   state->eeprom_state = EEP_IDLE;
2017   state->SIOMULTI0 = 0xffff;
2018   state->SIOMULTI1 = 0xffff;
2019   state->SIOMULTI2 = 0xffff;
2020   state->SIOMULTI3 = 0xffff;
2021   state->KEYCNT = 0x03ff;
2022   state->RCNT = 0x8000;
2023   state->JOYSTAT = 0x0002;
2024   state->gfxBG2Changed = 0;
2025   state->gfxBG3Changed = 0;
2026   state->gfxBG2X = 0;
2027   state->gfxBG2Y = 0;
2028   state->gfxBG3X = 0;
2029   state->gfxBG3Y = 0;
20302030
2031   gba_state->windowOn = 0;
2032   gba_state->fxOn = 0;
2031   state->windowOn = 0;
2032   state->fxOn = 0;
20332033
2034   timer_adjust_oneshot(gba_state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
2035   timer_adjust_oneshot(gba_state->hbl_timer, attotime_never, 0);
2036   timer_adjust_oneshot(gba_state->dma_timer[0], attotime_never, 0);
2037   timer_adjust_oneshot(gba_state->dma_timer[1], attotime_never, 1);
2038   timer_adjust_oneshot(gba_state->dma_timer[2], attotime_never, 2);
2039   timer_adjust_oneshot(gba_state->dma_timer[3], attotime_never, 3);
2034   timer_adjust_oneshot(state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
2035   timer_adjust_oneshot(state->hbl_timer, attotime_never, 0);
2036   timer_adjust_oneshot(state->dma_timer[0], attotime_never, 0);
2037   timer_adjust_oneshot(state->dma_timer[1], attotime_never, 1);
2038   timer_adjust_oneshot(state->dma_timer[2], attotime_never, 2);
2039   timer_adjust_oneshot(state->dma_timer[3], attotime_never, 3);
20402040
2041   gba_state->fifo_a_ptr = gba_state->fifo_b_ptr = 17;   // indicate empty
2042   gba_state->fifo_a_in = gba_state->fifo_b_in = 17;
2041   state->fifo_a_ptr = state->fifo_b_ptr = 17;   // indicate empty
2042   state->fifo_a_in = state->fifo_b_in = 17;
20432043
20442044   // and clear the DACs
20452045        dac_signed_data_w(gb_a_l, 0x80);
r7509r7510
20502050
20512051static MACHINE_START( gba )
20522052{
2053   gba_state_t *gba_state = (gba_state_t *)machine->driver_data;
2053   gba_state *state = (gba_state *)machine->driver_data;
20542054
20552055   /* add a hook for battery save */
20562056   add_exit_callback(machine, gba_machine_stop);
20572057
20582058   /* create a timer to fire scanline functions */
2059   gba_state->scan_timer = timer_alloc(machine, perform_scan, 0);
2060   gba_state->hbl_timer = timer_alloc(machine, perform_hbl, 0);
2061   timer_adjust_oneshot(gba_state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
2059   state->scan_timer = timer_alloc(machine, perform_scan, 0);
2060   state->hbl_timer = timer_alloc(machine, perform_hbl, 0);
2061   timer_adjust_oneshot(state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
20622062
20632063   /* and one for each DMA channel */
2064   gba_state->dma_timer[0] = timer_alloc(machine, dma_complete, 0);
2065   gba_state->dma_timer[1] = timer_alloc(machine, dma_complete, 0);
2066   gba_state->dma_timer[2] = timer_alloc(machine, dma_complete, 0);
2067   gba_state->dma_timer[3] = timer_alloc(machine, dma_complete, 0);
2068   timer_adjust_oneshot(gba_state->dma_timer[0], attotime_never, 0);
2069   timer_adjust_oneshot(gba_state->dma_timer[1], attotime_never, 1);
2070   timer_adjust_oneshot(gba_state->dma_timer[2], attotime_never, 2);
2071   timer_adjust_oneshot(gba_state->dma_timer[3], attotime_never, 3);
2064   state->dma_timer[0] = timer_alloc(machine, dma_complete, 0);
2065   state->dma_timer[1] = timer_alloc(machine, dma_complete, 0);
2066   state->dma_timer[2] = timer_alloc(machine, dma_complete, 0);
2067   state->dma_timer[3] = timer_alloc(machine, dma_complete, 0);
2068   timer_adjust_oneshot(state->dma_timer[0], attotime_never, 0);
2069   timer_adjust_oneshot(state->dma_timer[1], attotime_never, 1);
2070   timer_adjust_oneshot(state->dma_timer[2], attotime_never, 2);
2071   timer_adjust_oneshot(state->dma_timer[3], attotime_never, 3);
20722072
20732073   /* also one for each timer (heh) */
2074   gba_state->tmr_timer[0] = timer_alloc(machine, timer_expire, 0);
2075   gba_state->tmr_timer[1] = timer_alloc(machine, timer_expire, 0);
2076   gba_state->tmr_timer[2] = timer_alloc(machine, timer_expire, 0);
2077   gba_state->tmr_timer[3] = timer_alloc(machine, timer_expire, 0);
2078   timer_adjust_oneshot(gba_state->tmr_timer[0], attotime_never, 0);
2079   timer_adjust_oneshot(gba_state->tmr_timer[1], attotime_never, 1);
2080   timer_adjust_oneshot(gba_state->tmr_timer[2], attotime_never, 2);
2081   timer_adjust_oneshot(gba_state->tmr_timer[3], attotime_never, 3);
2074   state->tmr_timer[0] = timer_alloc(machine, timer_expire, 0);
2075   state->tmr_timer[1] = timer_alloc(machine, timer_expire, 0);
2076   state->tmr_timer[2] = timer_alloc(machine, timer_expire, 0);
2077   state->tmr_timer[3] = timer_alloc(machine, timer_expire, 0);
2078   timer_adjust_oneshot(state->tmr_timer[0], attotime_never, 0);
2079   timer_adjust_oneshot(state->tmr_timer[1], attotime_never, 1);
2080   timer_adjust_oneshot(state->tmr_timer[2], attotime_never, 2);
2081   timer_adjust_oneshot(state->tmr_timer[3], attotime_never, 3);
20822082
20832083   /* and an IRQ handling timer */
2084   gba_state->irq_timer = timer_alloc(machine, handle_irq, 0);
2085   timer_adjust_oneshot(gba_state->irq_timer, attotime_never, 0);
2084   state->irq_timer = timer_alloc(machine, handle_irq, 0);
2085   timer_adjust_oneshot(state->irq_timer, attotime_never, 0);
20862086
20872087   gba_video_start(machine);
20882088}
r7509r7510
20972097
20982098static READ32_HANDLER( sram_r )
20992099{
2100   gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data;
2100   gba_state *state = (gba_state *)space->machine->driver_data;
21012101
2102   return gba_state->gba_sram[offset];
2102   return state->gba_sram[offset];
21032103}
21042104
21052105static WRITE32_HANDLER( sram_w )
21062106{
2107   gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data;
2107   gba_state *state = (gba_state *)space->machine->driver_data;
21082108
2109   COMBINE_DATA(&gba_state->gba_sram[offset]);
2109   COMBINE_DATA(&state->gba_sram[offset]);
21102110}
21112111
21122112static READ32_HANDLER( flash64k_r )
21132113{
2114   gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data;
2115   switch( gba_state->flash64k_state )
2114   gba_state *state = (gba_state *)space->machine->driver_data;
2115   switch( state->flash64k_state )
21162116   {
21172117      case FLASH_IDLEBYTE0:
21182118      case FLASH_IDLEBYTE1:
r7509r7510
21202120      case FLASH_ERASEBYTE0:
21212121      case FLASH_ERASEBYTE1:
21222122      case FLASH_ERASEBYTE2:
2123              return gba_state->gba_flash64k[offset];
2123              return state->gba_flash64k[offset];
21242124      case FLASH_IDENT:
21252125              if( offset == 0 )
21262126              {
2127              return ( gba_state->gba_flash64k[0] & 0xffff0000 ) | 0x00001b32;
2127              return ( state->gba_flash64k[0] & 0xffff0000 ) | 0x00001b32;
21282128              }
21292129              else
21302130              {
2131              return gba_state->gba_flash64k[offset];
2131              return state->gba_flash64k[offset];
21322132              }
21332133              return 0x00001b32;
21342134      case FLASH_ERASE_ALL:
21352135      case FLASH_ERASE_4K:
2136              return gba_state->gba_flash64k[offset];
2136              return state->gba_flash64k[offset];
21372137   }
2138   return gba_state->gba_flash64k[offset];
2138   return state->gba_flash64k[offset];
21392139}
21402140
21412141static WRITE32_HANDLER( flash64k_w )
21422142{
2143   gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data;
2143   gba_state *state = (gba_state *)space->machine->driver_data;
21442144
2145   switch( gba_state->flash64k_state )
2145   switch( state->flash64k_state )
21462146   {
21472147      case FLASH_IDLEBYTE0:
21482148      case FLASH_ERASEBYTE0:
r7509r7510
21502150              {
21512151              if( ( data & mem_mask ) == 0x0000aa00 )
21522152              {
2153                      if( gba_state->flash64k_state == FLASH_IDLEBYTE0 )
2153                      if( state->flash64k_state == FLASH_IDLEBYTE0 )
21542154                      {
2155                         gba_state->flash64k_state = FLASH_IDLEBYTE1;
2155                         state->flash64k_state = FLASH_IDLEBYTE1;
21562156                      }
2157                      else if( gba_state->flash64k_state == FLASH_ERASEBYTE0 )
2157                      else if( state->flash64k_state == FLASH_ERASEBYTE0 )
21582158                      {
2159                         gba_state->flash64k_state = FLASH_ERASEBYTE1;
2159                         state->flash64k_state = FLASH_ERASEBYTE1;
21602160                      }
21612161              }
21622162              }
r7509r7510
21672167              {
21682168              if( ( data & mem_mask ) == 0x00550000 )
21692169              {
2170                      if( gba_state->flash64k_state == FLASH_IDLEBYTE1 )
2170                      if( state->flash64k_state == FLASH_IDLEBYTE1 )
21712171                      {
2172                         gba_state->flash64k_state = FLASH_IDLEBYTE2;
2172                         state->flash64k_state = FLASH_IDLEBYTE2;
21732173                      }
2174                      else if( gba_state->flash64k_state == FLASH_ERASEBYTE1 )
2174                      else if( state->flash64k_state == FLASH_ERASEBYTE1 )
21752175                      {
2176                         gba_state->flash64k_state = FLASH_ERASEBYTE2;
2176                         state->flash64k_state = FLASH_ERASEBYTE2;
21772177                      }
21782178              }
21792179              }
r7509r7510
21822182      case FLASH_ERASEBYTE2:
21832183              if( offset == 0x5555/4 && ~mem_mask == 0xffff00ff )
21842184              {
2185                 if( gba_state->flash64k_state == FLASH_IDLEBYTE2 )
2185                 if( state->flash64k_state == FLASH_IDLEBYTE2 )
21862186                 {
21872187                         switch( ( data & mem_mask ) >> 8 )
21882188                         {
21892189                         case 0x80:
2190                                 gba_state->flash64k_state = FLASH_ERASEBYTE0;
2190                                 state->flash64k_state = FLASH_ERASEBYTE0;
21912191                                 break;
21922192                         case 0x90:
2193                                 gba_state->flash64k_state = FLASH_IDENT;
2193                                 state->flash64k_state = FLASH_IDENT;
21942194                                 break;
21952195                         case 0xa0:
2196                                 gba_state->flash64k_state = FLASH_WRITE;
2196                                 state->flash64k_state = FLASH_WRITE;
21972197                                 break;
21982198                         }
21992199                 }
2200                 else if( gba_state->flash64k_state == FLASH_ERASEBYTE2 )
2200                 else if( state->flash64k_state == FLASH_ERASEBYTE2 )
22012201                 {
22022202                         if( ( data & mem_mask ) == 0x00001000 )
22032203                         {
22042204                            UINT32 flashWord;
22052205                            for( flashWord = 0; flashWord < 0x10000/4; flashWord++ )
22062206                            {
2207                                    gba_state->gba_flash64k[flashWord] = 0xffffffff;
2207                                    state->gba_flash64k[flashWord] = 0xffffffff;
22082208                            }
2209                            gba_state->flash64k_state = FLASH_ERASE_ALL;
2209                            state->flash64k_state = FLASH_ERASE_ALL;
22102210                         }
22112211                 }
22122212              }
22132213              else if( ( offset & 0xffffc3ff ) == 0 && ( data & mem_mask ) == 0x00000030 )
22142214              {
22152215                 UINT32 flashWord;
2216                 gba_state->flash64k_page = offset >> 10;
2216                 state->flash64k_page = offset >> 10;
22172217                 for( flashWord = offset; flashWord < offset + 0x1000/4; flashWord++ )
22182218                 {
2219                         gba_state->gba_flash64k[flashWord] = 0xffffffff;
2219                         state->gba_flash64k[flashWord] = 0xffffffff;
22202220                 }
2221                 gba_state->flash64k_state = FLASH_ERASE_4K;
2221                 state->flash64k_state = FLASH_ERASE_4K;
22222222              }
22232223              break;
22242224      case FLASH_IDENT:
22252225              // Hack; any sensibly-written game should follow up with the relevant read, which will reset the state to FLASH_IDLEBYTE0.
2226              gba_state->flash64k_state = FLASH_IDLEBYTE0;
2226              state->flash64k_state = FLASH_IDLEBYTE0;
22272227              flash64k_w( space, offset, data, ~mem_mask );
22282228              break;
22292229      case FLASH_ERASE_4K:
22302230              // Hack; any sensibly-written game should follow up with the relevant read, which will reset the state to FLASH_IDLEBYTE0.
2231              gba_state->flash64k_state = FLASH_IDLEBYTE0;
2231              state->flash64k_state = FLASH_IDLEBYTE0;
22322232              flash64k_w( space, offset, data, ~mem_mask );
22332233              break;
22342234      case FLASH_ERASE_ALL:
22352235              // Hack; any sensibly-written game should follow up with the relevant read, which will reset the state to FLASH_IDLEBYTE0.
2236              gba_state->flash64k_state = FLASH_IDLEBYTE0;
2236              state->flash64k_state = FLASH_IDLEBYTE0;
22372237              flash64k_w( space, offset, data, ~mem_mask );
22382238              break;
22392239      case FLASH_WRITE:
2240              COMBINE_DATA(&gba_state->gba_flash64k[offset]);
2241              gba_state->flash64k_state = FLASH_IDLEBYTE0;
2240              COMBINE_DATA(&state->gba_flash64k[offset]);
2241              state->flash64k_state = FLASH_IDLEBYTE0;
22422242              break;
22432243   }
22442244}
r7509r7510
22462246static READ32_HANDLER( eeprom_r )
22472247{
22482248   UINT32 out;
2249   gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data;
2249   gba_state *state = (gba_state *)space->machine->driver_data;
22502250
2251   switch (gba_state->eeprom_state)
2251   switch (state->eeprom_state)
22522252   {
22532253      case EEP_IDLE:
2254//          printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %d\n", offset, ~mem_mask, gba_state->eeprom_state, activecpu_get_pc(), 1);
2254//          printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %d\n", offset, ~mem_mask, state->eeprom_state, activecpu_get_pc(), 1);
22552255         return 0x00010001;   // "ready"
22562256
22572257        case EEP_READFIRST:
2258            gba_state->eeprom_count--;
2258            state->eeprom_count--;
22592259
2260            if (!gba_state->eeprom_count)
2260            if (!state->eeprom_count)
22612261            {
2262                gba_state->eeprom_count = 64;
2263                gba_state->eeprom_bits = 0;
2264                gba_state->eep_data = 0;
2265                gba_state->eeprom_state = EEP_READ;
2262                state->eeprom_count = 64;
2263                state->eeprom_bits = 0;
2264                state->eep_data = 0;
2265                state->eeprom_state = EEP_READ;
22662266            }
22672267            break;
22682268      case EEP_READ:
2269         if ((gba_state->eeprom_bits == 0) && (gba_state->eeprom_count))
2269         if ((state->eeprom_bits == 0) && (state->eeprom_count))
22702270         {
2271            gba_state->eep_data = gba_state->gba_eeprom[gba_state->eeprom_addr];
2272             //       printf("EEPROM read @ %x = %x (%x)\n", gba_state->eeprom_addr, gba_state->eep_data, (gba_state->eep_data & 0x80) ? 1 : 0);
2273            gba_state->eeprom_addr++;
2274            gba_state->eeprom_bits = 8;
2271            state->eep_data = state->gba_eeprom[state->eeprom_addr];
2272             //       printf("EEPROM read @ %x = %x (%x)\n", state->eeprom_addr, state->eep_data, (state->eep_data & 0x80) ? 1 : 0);
2273            state->eeprom_addr++;
2274            state->eeprom_bits = 8;
22752275         }
22762276
2277         out = (gba_state->eep_data & 0x80) ? 1 : 0;
2277         out = (state->eep_data & 0x80) ? 1 : 0;
22782278         out |= (out<<16);
2279         gba_state->eep_data <<= 1;
2279         state->eep_data <<= 1;
22802280
2281         gba_state->eeprom_bits--;
2282         gba_state->eeprom_count--;
2281         state->eeprom_bits--;
2282         state->eeprom_count--;
22832283
2284         if (!gba_state->eeprom_count)
2284         if (!state->eeprom_count)
22852285         {
2286            gba_state->eeprom_state = EEP_IDLE;
2286            state->eeprom_state = EEP_IDLE;
22872287         }
22882288
22892289//          printf("out = %08x\n", out);
2290//          printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %08x\n", offset, ~mem_mask, gba_state->eeprom_state, activecpu_get_pc(), out);
2290//          printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %08x\n", offset, ~mem_mask, state->eeprom_state, activecpu_get_pc(), out);
22912291         return out;
22922292   }
2293//  printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %d\n", offset, ~mem_mask, gba_state->eeprom_state, activecpu_get_pc(), 0);
2293//  printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %d\n", offset, ~mem_mask, state->eeprom_state, activecpu_get_pc(), 0);
22942294   return 0;
22952295}
22962296
22972297static WRITE32_HANDLER( eeprom_w )
22982298{
2299   gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data;
2299   gba_state *state = (gba_state *)space->machine->driver_data;
23002300
23012301   if (~mem_mask == 0x0000ffff)
23022302   {
23032303      data >>= 16;
23042304   }
23052305
2306//  printf("eeprom_w: %x @ %x (state %d) (PC=%x)\n", data, offset, gba_state->eeprom_state, activecpu_get_pc());
2306//  printf("eeprom_w: %x @ %x (state %d) (PC=%x)\n", data, offset, state->eeprom_state, activecpu_get_pc());
23072307
2308   switch (gba_state->eeprom_state)
2308   switch (state->eeprom_state)
23092309   {
23102310      case EEP_IDLE:
23112311         if (data == 1)
23122312         {
2313            gba_state->eeprom_state++;
2313            state->eeprom_state++;
23142314         }
23152315         break;
23162316
23172317      case EEP_COMMAND:
23182318         if (data == 1)
23192319         {
2320                gba_state->eeprom_command = EEP_READFIRST;
2320                state->eeprom_command = EEP_READFIRST;
23212321         }
23222322         else
23232323         {
2324            gba_state->eeprom_command = EEP_WRITE;
2324            state->eeprom_command = EEP_WRITE;
23252325         }
2326         gba_state->eeprom_state = EEP_ADDR;
2327         gba_state->eeprom_count = 6;
2328         gba_state->eeprom_addr = 0;
2326         state->eeprom_state = EEP_ADDR;
2327         state->eeprom_count = 6;
2328         state->eeprom_addr = 0;
23292329         break;
23302330
23312331      case EEP_ADDR:
2332         gba_state->eeprom_addr <<= 1;
2333         gba_state->eeprom_addr |= (data & 1);
2334         gba_state->eeprom_count--;
2335         if (!gba_state->eeprom_count)
2332         state->eeprom_addr <<= 1;
2333         state->eeprom_addr |= (data & 1);
2334         state->eeprom_count--;
2335         if (!state->eeprom_count)
23362336         {
2337            gba_state->eeprom_addr *= 8;   // each address points to 8 bytes
2338                if (gba_state->eeprom_command == EEP_READFIRST)
2337            state->eeprom_addr *= 8;   // each address points to 8 bytes
2338                if (state->eeprom_command == EEP_READFIRST)
23392339            {
2340               gba_state->eeprom_state = EEP_AFTERADDR;
2340               state->eeprom_state = EEP_AFTERADDR;
23412341            }
23422342            else
23432343            {
2344               gba_state->eeprom_count = 64;
2345               gba_state->eeprom_bits = 8;
2346               gba_state->eeprom_state = EEP_WRITE;
2347               gba_state->eep_data = 0;
2344               state->eeprom_count = 64;
2345               state->eeprom_bits = 8;
2346               state->eeprom_state = EEP_WRITE;
2347               state->eep_data = 0;
23482348            }
23492349         }
23502350         break;
23512351
23522352      case EEP_AFTERADDR:
2353         gba_state->eeprom_state = gba_state->eeprom_command;
2354         gba_state->eeprom_count = 64;
2355         gba_state->eeprom_bits = 0;
2356         gba_state->eep_data = 0;
2357            if( gba_state->eeprom_state == EEP_READFIRST )
2353         state->eeprom_state = state->eeprom_command;
2354         state->eeprom_count = 64;
2355         state->eeprom_bits = 0;
2356         state->eep_data = 0;
2357            if( state->eeprom_state == EEP_READFIRST )
23582358            {
2359                gba_state->eeprom_count = 4;
2359                state->eeprom_count = 4;
23602360            }
23612361         break;
23622362
23632363      case EEP_WRITE:
2364         gba_state->eep_data<<= 1;
2365         gba_state->eep_data |= (data & 1);
2366         gba_state->eeprom_bits--;
2367         gba_state->eeprom_count--;
2364         state->eep_data<<= 1;
2365         state->eep_data |= (data & 1);
2366         state->eeprom_bits--;
2367         state->eeprom_count--;
23682368
2369         if (gba_state->eeprom_bits == 0)
2369         if (state->eeprom_bits == 0)
23702370         {
2371            mame_printf_verbose("%08x: EEPROM: %02x to %x\n", cpu_get_pc(devtag_get_device(space->machine, "maincpu")), gba_state->eep_data, gba_state->eeprom_addr );
2372            gba_state->gba_eeprom[gba_state->eeprom_addr] = gba_state->eep_data;
2373            gba_state->eeprom_addr++;
2374            gba_state->eep_data = 0;
2375            gba_state->eeprom_bits = 8;
2371            mame_printf_verbose("%08x: EEPROM: %02x to %x\n", cpu_get_pc(devtag_get_device(space->machine, "maincpu")), state->eep_data, state->eeprom_addr );
2372            state->gba_eeprom[state->eeprom_addr] = state->eep_data;
2373            state->eeprom_addr++;
2374            state->eep_data = 0;
2375            state->eeprom_bits = 8;
23762376         }
23772377
2378         if (!gba_state->eeprom_count)
2378         if (!state->eeprom_count)
23792379         {
2380            gba_state->eeprom_state = EEP_AFTERWRITE;
2380            state->eeprom_state = EEP_AFTERWRITE;
23812381         }
23822382         break;
23832383
23842384      case EEP_AFTERWRITE:
2385         gba_state->eeprom_state = EEP_IDLE;
2385         state->eeprom_state = EEP_IDLE;
23862386         break;
23872387   }
23882388}
r7509r7510
23912391{
23922392   UINT8 *ROM = memory_region(image->machine, "cartridge");
23932393   int i;
2394   gba_state_t *gba_state = (gba_state_t *)image->machine->driver_data;
2394   gba_state *state = (gba_state *)image->machine->driver_data;
23952395
23962396   nvsize = 0;
23972397   nvptr = (UINT8 *)NULL;
r7509r7510
24022402   {
24032403      if (!memcmp(&ROM[i], "EEPROM_", 7))
24042404      {
2405         nvptr = (UINT8 *)&gba_state->gba_eeprom;
2405         nvptr = (UINT8 *)&state->gba_eeprom;
24062406         nvsize = 0x2000;
24072407
24082408         if (image_length(image) <= (16*1024*1024))
r7509r7510
24192419      }
24202420      else if (!memcmp(&ROM[i], "SRAM_", 5))
24212421      {
2422         nvptr = (UINT8 *)&gba_state->gba_sram;
2422         nvptr = (UINT8 *)&state->gba_sram;
24232423         nvsize = 0x10000;
24242424
24252425         memory_install_read32_handler(cpu_get_address_space(devtag_get_device(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_r);
r7509r7510
24332433      }
24342434      else if (!memcmp(&ROM[i], "FLASH", 5))
24352435      {
2436         nvptr = (UINT8 *)&gba_state->gba_flash64k;
2436         nvptr = (UINT8 *)&state->gba_flash64k;
24372437         nvsize = 0x10000;
24382438
24392439         memory_install_read32_handler(cpu_get_address_space(devtag_get_device(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash64k_r);
r7509r7510
24802480}
24812481
24822482static MACHINE_DRIVER_START( gbadv )
2483   MDRV_DRIVER_DATA(gba_state_t)
2483   MDRV_DRIVER_DATA(gba_state)
24842484
24852485   MDRV_CPU_ADD("maincpu", ARM7, 16777216)
24862486   MDRV_CPU_PROGRAM_MAP(gbadvance_map)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team