Previous 15994 Revisions Next

r5618 Monday 7th September, 2009 at 06:25:34 UTC by MooglyGuy
- Improved ROZ emulation for BG layers. Still not quite right.
- Fixed a bug involving bit depth detection when rendering BG layers. Fixes the title screen in Super Mario Advance, Mario Kart Super Circuit, and probably many others.
[src/mess/video]gba.c

src/mess/video/gba.c
r5617r5618
1313#include "includes/gba.h"
1414
1515#define VERBOSE_LEVEL   (0)
16#define DISABLE_ROZ   (1)
16#define DISABLE_ROZ   (0)
1717
1818static UINT16 mosaic_offset[16][4096];
1919
r5617r5618
122122
123123static void draw_roz_scanline(gba_state *gba_state, UINT16 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, int priority)
124124{
125#if !DISABLE_ROZ
126125   UINT32 base, mapbase, size, ovr;
127126   INT32 sizes[4] = { 128, 256, 512, 1024 };
128   INT32 cx, cy, psx, psy, x, px, py;
127   INT32 cx, cy, x, ax, ay;
129128   UINT8 *mgba_vram = (UINT8 *)gba_state->gba_vram, tile;
130129   UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram;
131130   UINT16 pixel;
132131
133132   if ((gba_state->DISPCNT & enablemask) && ((ctrl & 3) == priority))
134133   {
135      base = ((ctrl>>2)&3) * 0x4000;      // VRAM base of tiles
136      mapbase = ((ctrl>>8)&0x1f) * 0x800;   // VRAM base of map
137      size = ((ctrl>>14) & 3);      // size of map in submaps
138      ovr = ((ctrl >>13) & 1);
134      base = ((ctrl & BGCNT_CHARBASE) >> BGCNT_CHARBASE_SHIFT) * 0x4000;         // VRAM base of tiles
135      mapbase = ((ctrl & BGCNT_SCREENBASE) >> BGCNT_SCREENBASE_SHIFT) * 0x800;   // VRAM base of map
136      size = (ctrl & BGCNT_SCREENSIZE) >> BGCNT_SCREENSIZE_SHIFT;               // size of map in submaps
137      ovr = ctrl & BGCNT_PALETTESET_WRAP;
139138
140139      // sign extend roz parameters
141140      if (X & 0x08000000) X |= 0xf0000000;
r5617r5618
145144      if (PC & 0x8000) PC |= 0xffff0000;
146145      if (PD & 0x8000) PD |= 0xffff0000;
147146
148      cx = cy = sizes[size] / 2;
147      cx = X;
148      cy = Y;
149149
150//      psx = ((PA * (X - cx)) & ~63) + ((PB * (Y - cy)) & ~63) + ((PB * ypos) & ~63) + (cx << 8); //pixel start x
151//      psy = ((PC * (X - cx)) & ~63) + ((PD * (Y - cy)) & ~63) + ((PD * ypos) & ~63) + (cy << 8); //pixel start y
152      psx = ((PA * (X - cx))) + ((PB * (Y - cy))) + ((PB * ypos)) + (cx << 8); //pixel start x
153      psy = ((PC * (X - cx))) + ((PD * (Y - cy))) + ((PD * ypos)) + (cy << 8); //pixel start y
150      cx += ypos * PB;
151      cy += ypos * PD;
154152
153      if(ctrl & BGCNT_MOSAIC)
154      {
155         int mosaicy = ((gba_state->MOSAIC & 0xf0) >> 4) + 1;
156         int y = ypos % mosaicy;
157         cx -= y*PB;
158         cy -= y*PD;
159      }
155160
156      /*
161      ax = cx >> 8;
162      ay = cy >> 8;
157163
158 x2 = A*(x1-x0) + B*(y1-y0) + x0
159 y2 = C*(x1-x0) + D*(y1-y0) + y0
164      if(ctrl & BGCNT_PALETTESET_WRAP)
165      {
166         ax %= sizes[size];
167         ay %= sizes[size];
168         if(ax < 0)
169         {
170            ax += sizes[size];
171         }
172         if(ay < 0)
173         {
174            ay += sizes[size];
175         }
176      }
160177
161 x2-x0 = A*(x1-x0) + B*(y1-y0)
162 y2-y0 = C*(x1-x0) + D*(y1-y0)
163      */
178      if(ctrl & BGCNT_PALETTE256)
179      {
180         for(x = 0; x < 240; x++)
181         {
182            if(!(ax < 0 || ay < 0 || ax >= sizes[size] || ay >= sizes[size]))
183            {
184               int tilex = ax & 7;
185               int tiley = ay & 7;
164186
165      for (x = 0; x < 240; x++)
187               tile = mgba_vram[mapbase + (ax / 8) + (ay / 8) * (sizes[size] / 8)];
188               pixel = mgba_vram[base + (tile * 64) + (tiley * 8) + tilex];
189
190               // plot it
191               if (pixel)
192               {
193                  scanline[x] = pgba_pram[pixel] & 0x7fff;
194               }
195            }
196
197            cx += PA;
198            cy += PC;
199
200            ax = cx >> 8;
201            ay = cy >> 8;
202
203            if(ctrl & BGCNT_PALETTESET_WRAP)
204            {
205               ax %= sizes[size];
206               ay %= sizes[size];
207               if(ax < 0)
208               {
209                  ax += sizes[size];
210               }
211               if(ay < 0)
212               {
213                  ay += sizes[size];
214               }
215            }
216         }
217      }
218      else
166219      {
167         px = psx + (PA * x); //pixel x position
168         py = psy + (PC * x); //pixel y position
220         for(x = 0; x < 240; x++)
221         {
222            if(!(ax < 0 || ay < 0 || ax >= sizes[size] || ay >= sizes[size]))
223            {
224               int tilex = ax & 7;
225               int tiley = ay & 7;
169226
170         // mask 'floating-point' bits (low 8 bits)
171         px >>= 8;
172         py >>= 8;
227               tile = mgba_vram[mapbase + (ax / 8) + (ay / 8) * (sizes[size] / 8)];
228               pixel = mgba_vram[base + (tile * 64) + (tiley * 8) + tilex];
173229
174         // do infinite repeat for now
175         px %= sizes[size];
176         py %= sizes[size];
230               // plot it
231               if (pixel)
232               {
233                  scanline[x] = pgba_pram[pixel] & 0x7fff;
234               }
235            }
177236
178         // px and py are now offsets into the tilemap
179         tile = mgba_vram[mapbase + (px/8) + ((py/8)*sizes[size]/8)];
237            cx += PA;
238            cy += PC;
180239
181         // get the pixel
182              pixel = mgba_vram[(tile*64) + (px%8) + ((py%8)*8)];
240            ax = cx >> 8;
241            ay = cy >> 8;
183242
184         // plot it
185         if (pixel)
243            if(ctrl & BGCNT_PALETTESET_WRAP)
244            {
245               ax %= sizes[size];
246               ay %= sizes[size];
247               if(ax < 0)
248               {
249                  ax += sizes[size];
250               }
251               if(ay < 0)
252               {
253                  ay += sizes[size];
254               }
255            }
256         }
257      }
258
259      if(ctrl & BGCNT_MOSAIC)
260      {
261         int mosaicx = (gba_state->MOSAIC & 0x0f) + 1;
262         if(mosaicx > 1)
186263         {
187            scanline[x] = pgba_pram[pixel]&0x7fff;
264            int m = 1;
265            for(x = 0; x < 239; x++)
266            {
267               scanline[x+1] = scanline[x];
268               m++;
269               if(m == mosaicx)
270               {
271                  m = 1;
272                  x++;
273               }
274            }
188275         }
189276      }
190277   }
191#endif
192278}
193279
194280static void draw_bg_scanline(gba_state *gba_state, UINT16 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs, int priority)
r5617r5618
209295      mosX = mosY = 0;
210296   }
211297
212   if ((gba_state->DISPCNT & enablemask) && ((ctrl & 3) == priority))
298   if ((gba_state->DISPCNT & enablemask) && ((ctrl & BGCNT_PRIORITY) == priority))
213299   {
214300      base = ((ctrl>>2)&3) * 0x4000;      // VRAM base of tiles
215301      mapbase = ((ctrl>>8)&0x1f) * 0x800;   // VRAM base of map
216302      size = ((ctrl>>14) & 3);      // size of map in submaps
217      mode = (gba_state->BG0CNT & 0x80) ? 1 : 0;   // 1 for 8bpp, 0 for 4bpp
303      mode = (ctrl & 0x80) ? 1 : 0;   // 1 for 8bpp, 0 for 4bpp
218304
219305      mx = hofs/8;      // X tile offset
220306      my = (ypos + vofs) / 8;   // Y tile offset
r5617r5618
331417            }
332418            break;
333419      }
334
335420   }
336421}
337422
r5617r5618
571656                  }
572657               }
573658
574               //printf( "Drawing a sprite scanline, y = %d, sx = %d, sy = %d\n", y, sx, sy );
575659               if(attr0 & OBJ_PALMODE_256)
576660               {
577661                  UINT16 *pgba_pram = (UINT16*)gba_state->gba_pram;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team