src/mess/video/gba.c
| r5617 | r5618 | |
| 13 | 13 | #include "includes/gba.h" |
| 14 | 14 | |
| 15 | 15 | #define VERBOSE_LEVEL (0) |
| 16 | | #define DISABLE_ROZ (1) |
| 16 | #define DISABLE_ROZ (0) |
| 17 | 17 | |
| 18 | 18 | static UINT16 mosaic_offset[16][4096]; |
| 19 | 19 | |
| r5617 | r5618 | |
| 122 | 122 | |
| 123 | 123 | static 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) |
| 124 | 124 | { |
| 125 | | #if !DISABLE_ROZ |
| 126 | 125 | UINT32 base, mapbase, size, ovr; |
| 127 | 126 | INT32 sizes[4] = { 128, 256, 512, 1024 }; |
| 128 | | INT32 cx, cy, psx, psy, x, px, py; |
| 127 | INT32 cx, cy, x, ax, ay; |
| 129 | 128 | UINT8 *mgba_vram = (UINT8 *)gba_state->gba_vram, tile; |
| 130 | 129 | UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram; |
| 131 | 130 | UINT16 pixel; |
| 132 | 131 | |
| 133 | 132 | if ((gba_state->DISPCNT & enablemask) && ((ctrl & 3) == priority)) |
| 134 | 133 | { |
| 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; |
| 139 | 138 | |
| 140 | 139 | // sign extend roz parameters |
| 141 | 140 | if (X & 0x08000000) X |= 0xf0000000; |
| r5617 | r5618 | |
| 145 | 144 | if (PC & 0x8000) PC |= 0xffff0000; |
| 146 | 145 | if (PD & 0x8000) PD |= 0xffff0000; |
| 147 | 146 | |
| 148 | | cx = cy = sizes[size] / 2; |
| 147 | cx = X; |
| 148 | cy = Y; |
| 149 | 149 | |
| 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; |
| 154 | 152 | |
| 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 | } |
| 155 | 160 | |
| 156 | | /* |
| 161 | ax = cx >> 8; |
| 162 | ay = cy >> 8; |
| 157 | 163 | |
| 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 | } |
| 160 | 177 | |
| 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; |
| 164 | 186 | |
| 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 |
| 166 | 219 | { |
| 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; |
| 169 | 226 | |
| 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]; |
| 173 | 229 | |
| 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 | } |
| 177 | 236 | |
| 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; |
| 180 | 239 | |
| 181 | | // get the pixel |
| 182 | | pixel = mgba_vram[(tile*64) + (px%8) + ((py%8)*8)]; |
| 240 | ax = cx >> 8; |
| 241 | ay = cy >> 8; |
| 183 | 242 | |
| 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) |
| 186 | 263 | { |
| 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 | } |
| 188 | 275 | } |
| 189 | 276 | } |
| 190 | 277 | } |
| 191 | | #endif |
| 192 | 278 | } |
| 193 | 279 | |
| 194 | 280 | static void draw_bg_scanline(gba_state *gba_state, UINT16 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs, int priority) |
| r5617 | r5618 | |
| 209 | 295 | mosX = mosY = 0; |
| 210 | 296 | } |
| 211 | 297 | |
| 212 | | if ((gba_state->DISPCNT & enablemask) && ((ctrl & 3) == priority)) |
| 298 | if ((gba_state->DISPCNT & enablemask) && ((ctrl & BGCNT_PRIORITY) == priority)) |
| 213 | 299 | { |
| 214 | 300 | base = ((ctrl>>2)&3) * 0x4000; // VRAM base of tiles |
| 215 | 301 | mapbase = ((ctrl>>8)&0x1f) * 0x800; // VRAM base of map |
| 216 | 302 | 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 |
| 218 | 304 | |
| 219 | 305 | mx = hofs/8; // X tile offset |
| 220 | 306 | my = (ypos + vofs) / 8; // Y tile offset |
| r5617 | r5618 | |
| 331 | 417 | } |
| 332 | 418 | break; |
| 333 | 419 | } |
| 334 | | |
| 335 | 420 | } |
| 336 | 421 | } |
| 337 | 422 | |
| r5617 | r5618 | |
| 571 | 656 | } |
| 572 | 657 | } |
| 573 | 658 | |
| 574 | | //printf( "Drawing a sprite scanline, y = %d, sx = %d, sy = %d\n", y, sx, sy ); |
| 575 | 659 | if(attr0 & OBJ_PALMODE_256) |
| 576 | 660 | { |
| 577 | 661 | UINT16 *pgba_pram = (UINT16*)gba_state->gba_pram; |