(MESS) gba.c: simplified video code, removing many redundancies. [Fabio Priuli]

This commit is contained in:
Fabio Priuli 2013-05-31 07:47:21 +00:00
parent 2337fd6287
commit 156b88338e
8 changed files with 426 additions and 2374 deletions

4
.gitattributes vendored
View File

@ -8067,10 +8067,6 @@ src/mess/video/galeb.c svneol=native#text/plain
src/mess/video/gamecom.c svneol=native#text/plain
src/mess/video/gb.c svneol=native#text/plain
src/mess/video/gba.c svneol=native#text/plain
src/mess/video/gbam345.c svneol=native#text/plain
src/mess/video/gbamode0.c svneol=native#text/plain
src/mess/video/gbamode1.c svneol=native#text/plain
src/mess/video/gbamode2.c svneol=native#text/plain
src/mess/video/gf4500.c svneol=native#text/plain
src/mess/video/gf4500.h svneol=native#text/plain
src/mess/video/gime.c svneol=native#text/plain

View File

@ -262,24 +262,8 @@ public:
void draw_gba_oam(UINT32 *scanline, int y);
inline int is_in_window(int x, int window);
void draw_mode0(int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode1(int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode2(int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode345(int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode0_scanline(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode0_scanline_nowindow(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode0_scanline_all(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode1_scanline(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode1_scanline_nowindow(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode1_scanline_all(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode2_scanline(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode2_scanline_nowindow(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_mode2_scanline_all(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_roz_bitmap_mode_scanline(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_roz_bitmap_mode_scanline_nowindow(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_roz_bitmap_mode_scanline_all(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
void draw_modes(int mode, int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp);
protected:
required_memory_region m_region_maincpu;

View File

@ -2193,11 +2193,6 @@ $(MESS_MACHINE)/snescx4.o: $(MESSSRC)/machine/cx4ops.c \
$(MESSSRC)/machine/cx4fn.c \
$(MESSSRC)/machine/cx4data.c \
$(MESS_VIDEO)/gba.o: $(MESSSRC)/video/gbamode0.c \
$(MESSSRC)/video/gbamode1.c \
$(MESSSRC)/video/gbamode2.c \
$(MESSSRC)/video/gbam345.c
$(MESS_MACHINE)/nes_slot.o: $(MESSSRC)/machine/nes_ines.c \
$(MESSSRC)/machine/nes_pcb.c \
$(MESSSRC)/machine/nes_unif.c \

View File

@ -36,11 +36,276 @@ INLINE UINT32 alpha_blend_pixel(UINT32 color0, UINT32 color1, int ca, int cb);
INLINE UINT32 increase_brightness(UINT32 color, int coeff_);
INLINE UINT32 decrease_brightness(UINT32 color, int coeff_);
#include "gbamode0.c"
#include "gbamode1.c"
#include "gbamode2.c"
#include "gbam345.c"
#define GBA_MODE0 0
#define GBA_MODE1 1
#define GBA_MODE2 2
#define GBA_MODE345 3
#define GBA_SUBMODE0 0
#define GBA_SUBMODE1 1
#define GBA_SUBMODE2 2
void gba_state::draw_modes(int mode, int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
int inWindow0 = 0;
int inWindow1 = 0;
UINT8 inWin0Mask = m_WININ & 0x00ff;
UINT8 inWin1Mask = m_WININ >> 8;
UINT8 outMask = m_WINOUT & 0x00ff;
if (submode == GBA_SUBMODE2)
{
if (m_DISPCNT & DISPCNT_WIN0_EN)
{
UINT8 v0 = m_WIN0V >> 8;
UINT8 v1 = m_WIN0V & 0x00ff;
inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
if (v1 >= v0)
inWindow0 |= (y >= v0 && y < v1) ? 1 : 0;
else
inWindow0 |= (y >= v0 || y < v1) ? 1 : 0;
}
if (m_DISPCNT & DISPCNT_WIN1_EN)
{
UINT8 v0 = m_WIN1V >> 8;
UINT8 v1 = m_WIN1V & 0x00ff;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
if (v1 >= v0)
inWindow1 |= (y >= v0 && y < v1) ? 1 : 0;
else
inWindow1 |= (y >= v0 || y < v1) ? 1 : 0;
}
}
// Draw BG
switch (mode)
{
case 0:
draw_bg_scanline(line0, y, DISPCNT_BG0_EN, m_BG0CNT, m_BG0HOFS, m_BG0VOFS);
draw_bg_scanline(line1, y, DISPCNT_BG1_EN, m_BG1CNT, m_BG1HOFS, m_BG1VOFS);
draw_bg_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2HOFS, m_BG2VOFS);
draw_bg_scanline(line3, y, DISPCNT_BG3_EN, m_BG3CNT, m_BG3HOFS, m_BG3VOFS);
break;
case 1:
draw_bg_scanline(line0, y, DISPCNT_BG0_EN, m_BG0CNT, m_BG0HOFS, m_BG0VOFS);
draw_bg_scanline(line1, y, DISPCNT_BG1_EN, m_BG1CNT, m_BG1HOFS, m_BG1VOFS);
draw_roz_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed);
break;
case 2:
draw_roz_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed);
draw_roz_scanline(line3, y, DISPCNT_BG3_EN, m_BG3CNT, m_BG3X, m_BG3Y, m_BG3PA, m_BG3PB, m_BG3PC, m_BG3PD, &m_gfxBG3X, &m_gfxBG3Y, m_gfxBG3Changed);
break;
case 3:
case 4:
case 5:
draw_roz_bitmap_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed, bpp);
break;
}
// Draw OAM
draw_gba_oam(lineOBJ, y);
if (submode == GBA_SUBMODE2)
draw_gba_oam_window(lineOBJWin, y);
for (int x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
UINT8 mask = outMask;
if (submode == GBA_SUBMODE2)
{
if ((lineOBJWin[x] & 0x80000000) == 0)
mask = m_WINOUT >> 8;
if (inWindow1)
{
if (is_in_window(x, 1))
mask = inWin1Mask;
}
if (inWindow0)
{
if (is_in_window(x, 0))
mask = inWin0Mask;
}
}
if (mode == GBA_MODE0 || mode == GBA_MODE1)
if ((UINT8)(line0[x] >> 24) < (UINT8)(color >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x01)))
{
color = line0[x];
top = 0x01;
}
if (mode == GBA_MODE0 || mode == GBA_MODE1)
if ((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x02)))
{
color = line1[x];
top = 0x02;
}
if (mode == GBA_MODE0 || mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345)
if ((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x04)))
{
color = line2[x];
top = 0x04;
}
if (mode == GBA_MODE0 || mode == GBA_MODE2)
if ((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x08)))
{
color = line3[x];
top = 0x08;
}
if (mode == GBA_MODE0 || mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345)
if ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x10)))
{
color = lineOBJ[x];
top = 0x10;
}
if (color & 0x00010000)
{
if ((submode == GBA_SUBMODE0 && top == 0x10) || submode == GBA_SUBMODE1 || submode == GBA_SUBMODE2)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if (mode == GBA_MODE0 || mode == GBA_MODE1)
if ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x01)))
{
back = line0[x];
top2 = 0x01;
}
if (mode == GBA_MODE0 || mode == GBA_MODE1)
if ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x02)))
{
back = line1[x];
top2 = 0x02;
}
if (mode == GBA_MODE0 || mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345)
if ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x04)))
{
back = line2[x];
top2 = 0x04;
}
if (mode == GBA_MODE0 || mode == GBA_MODE2)
if ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x08)))
{
back = line3[x];
top2 = 0x08;
}
if (top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
else
{
if (top & m_BLDCNT)
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
break;
case BLDCNT_SFX_DARKEN:
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
break;
}
}
}
}
}
else if (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x20))
{
if (top & m_BLDCNT)
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_NONE:
break;
case BLDCNT_SFX_ALPHA:
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if (mode == GBA_MODE0 || mode == GBA_MODE1)
if ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x01)))
{
if (top != 0x01)
{
back = line0[x];
top2 = 0x01;
}
}
if (mode == GBA_MODE0 || mode == GBA_MODE1)
if ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x02)))
{
if (top != 0x02)
{
back = line1[x];
top2 = 0x02;
}
}
if (mode == GBA_MODE0 || mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345)
if ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x04)))
{
if (top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if (mode == GBA_MODE0 || mode == GBA_MODE2)
if ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x08)))
{
if (top != 0x08)
{
back = line3[x];
top2 = 0x08;
}
}
if (mode == GBA_MODE0 || mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345)
if ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x10)))
{
if (top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if (top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
break;
case BLDCNT_SFX_LIGHTEN:
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
break;
case BLDCNT_SFX_DARKEN:
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
break;
}
}
}
lineMix[x] = color;
}
if (mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345)
m_gfxBG2Changed = 0;
if (mode == GBA_MODE2)
m_gfxBG3Changed = 0;
}
void gba_state::draw_roz_bitmap_scanline(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)
{
@ -50,15 +315,14 @@ void gba_state::draw_roz_bitmap_scanline(UINT32 *scanline, int ypos, UINT32 enab
INT32 sx = (depth == 4) ? 160 : 240;
INT32 sy = (depth == 4) ? 128 : 160;
UINT32 prio = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000;
INT32 dx, dmx, dy, dmy, startx, starty;
INT32 rx, ry, pixx, pixy, x;
INT32 cx, cy, pixx, pixy, x;
if ((depth == 8) && (m_DISPCNT & DISPCNT_FRAMESEL))
src8 += 0xa000;
if ((depth == 4) && (m_DISPCNT & DISPCNT_FRAMESEL))
src16 += 0xa000/2;
// sign extend roz parameters
if (X & 0x08000000) X |= 0xf0000000;
if (Y & 0x08000000) Y |= 0xf0000000;
@ -66,42 +330,34 @@ void gba_state::draw_roz_bitmap_scanline(UINT32 *scanline, int ypos, UINT32 enab
if (PB & 0x8000) PB |= 0xffff0000;
if (PC & 0x8000) PC |= 0xffff0000;
if (PD & 0x8000) PD |= 0xffff0000;
// re-assign parameters for convenience's sake
dx = PA;
dmx = PB;
dy = PC;
dmy = PD;
startx = X;
starty = Y;
if(ypos == 0)
changed = 3;
if(changed & 1)
*currentx = startx;
*currentx = X;
else
*currentx += dmx;
*currentx += PB;
if(changed & 2)
*currenty = starty;
*currenty = Y;
else
*currenty += dmy;
rx = *currentx;
ry = *currenty;
*currenty += PD;
cx = *currentx;
cy = *currenty;
if(ctrl & BGCNT_MOSAIC)
{
INT32 mosaic_line = ((m_MOSAIC & 0x00f0) >> 4) + 1;
INT32 mosaic_line = ((m_MOSAIC & 0xf0) >> 4) + 1;
INT32 tempy = (ypos / mosaic_line) * mosaic_line;
rx = startx + tempy*dmx;
ry = starty + tempy*dmy;
cx = X + tempy*PB;
cy = Y + tempy*PD;
}
pixx = rx >> 8;
pixy = ry >> 8;
pixx = cx >> 8;
pixy = cy >> 8;
for(x = 0; x < 240; x++)
{
if(pixx < 0 || pixy < 0 || pixx >= sx || pixy >= sy)
@ -120,14 +376,14 @@ void gba_state::draw_roz_bitmap_scanline(UINT32 *scanline, int ypos, UINT32 enab
scanline[x] = src16[pixy*sx + pixx] | prio;
}
}
rx += dx;
ry += dy;
pixx = rx >> 8;
pixy = ry >> 8;
cx += PA;
cy += PC;
pixx = cx >> 8;
pixy = cy >> 8;
}
if(ctrl & BGCNT_MOSAIC)
{
INT32 mosaicx = (m_MOSAIC & 0x0f) + 1;
@ -152,17 +408,16 @@ void gba_state::draw_roz_scanline(UINT32 *scanline, int ypos, UINT32 enablemask,
{
UINT32 base, mapbase, size;
static const INT32 sizes[4] = { 128, 256, 512, 1024 };
INT32 cx, cy, x, pixx, pixy;
INT32 cx, cy, pixx, pixy;
UINT8 *mgba_vram = (UINT8 *)m_gba_vram.target();
UINT32 tile;
UINT16 *pgba_pram = (UINT16 *)m_gba_pram.target();
UINT16 pixel;
UINT32 prio = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000;
int x = 0;
for(x = 0; x < 240; x++)
{
for (x = 0; x < 240; x++)
scanline[x] = 0x80000000;
}
if (m_DISPCNT & enablemask)
{
@ -179,35 +434,25 @@ void gba_state::draw_roz_scanline(UINT32 *scanline, int ypos, UINT32 enablemask,
if (PD & 0x8000) PD |= 0xffff0000;
if(ypos == 0)
{
changed = 3;
}
if(changed & 1)
{
*currentx = X;
}
else
{
*currentx += PB;
}
if(changed & 2)
{
*currenty = Y;
}
else
{
*currenty += PD;
}
cx = *currentx;
cy = *currenty;
if(ctrl & BGCNT_MOSAIC)
{
int mosaicy = ((m_MOSAIC & 0xf0) >> 4) + 1;
int y = ypos % mosaicy;
int mosaic_line = ((m_MOSAIC & 0xf0) >> 4) + 1;
int y = ypos % mosaic_line;
cx -= y*PB;
cy -= y*PD;
}
@ -229,85 +474,42 @@ void gba_state::draw_roz_scanline(UINT32 *scanline, int ypos, UINT32 enablemask,
}
}
if(ctrl & BGCNT_PALETTE256)
for(x = 0; x < 240; x++)
{
for(x = 0; x < 240; x++)
if(pixx < 0 || pixy < 0 || pixx >= sizes[size] || pixy >= sizes[size])
{
if(pixx < 0 || pixy < 0 || pixx >= sizes[size] || pixy >= sizes[size])
{
scanline[x] = 0x80000000;
}
else
{
int tilex = pixx & 7;
int tiley = pixy & 7;
tile = mgba_vram[mapbase + (pixx >> 3) + (pixy >> 3) * (sizes[size] >> 3)];
pixel = mgba_vram[base + (tile << 6) + (tiley << 3) + tilex];
// plot it
scanline[x] = pixel ? (pgba_pram[pixel] | prio) : 0x80000000;
}
cx += PA;
cy += PC;
pixx = cx >> 8;
pixy = cy >> 8;
if(ctrl & BGCNT_PALETTESET_WRAP)
{
pixx %= sizes[size];
pixy %= sizes[size];
if(pixx < 0)
{
pixx += sizes[size];
}
if(pixy < 0)
{
pixy += sizes[size];
}
}
scanline[x] = 0x80000000;
}
}
else
{
for(x = 0; x < 240; x++)
else
{
if(pixx < 0 || pixy < 0 || pixx >= sizes[size] || pixy >= sizes[size])
int tilex = pixx & 7;
int tiley = pixy & 7;
// shall we shift for (ctrl & BGCNT_PALETTE256)?? or is not effective for ROZ?
tile = mgba_vram[mapbase + (pixx >> 3) + (pixy >> 3) * (sizes[size] >> 3)];
pixel = mgba_vram[base + (tile << 6) + (tiley << 3) + tilex];
// plot it
scanline[x] = pixel ? (pgba_pram[pixel] | prio) : 0x80000000;
}
cx += PA;
cy += PC;
pixx = cx >> 8;
pixy = cy >> 8;
if(ctrl & BGCNT_PALETTESET_WRAP)
{
pixx %= sizes[size];
pixy %= sizes[size];
if(pixx < 0)
{
scanline[x] = 0x80000000;
pixx += sizes[size];
}
else
if(pixy < 0)
{
int tilex = pixx & 7;
int tiley = pixy & 7;
tile = mgba_vram[mapbase + (pixx >> 3) + (pixy >> 3) * (sizes[size] >> 3)];
pixel = mgba_vram[base + (tile << 6) + (tiley << 3) + tilex];
// plot it
scanline[x] = pixel ? (pgba_pram[pixel] | prio) : 0x80000000;
}
cx += PA;
cy += PC;
pixx = cx >> 8;
pixy = cy >> 8;
if(ctrl & BGCNT_PALETTESET_WRAP)
{
pixx %= sizes[size];
pixy %= sizes[size];
if(pixx < 0)
{
pixx += sizes[size];
}
if(pixy < 0)
{
pixy += sizes[size];
}
pixy += sizes[size];
}
}
}
@ -347,124 +549,55 @@ void gba_state::draw_bg_scanline(UINT32 *scanline, int ypos, UINT32 enablemask,
INT32 mosaicx = (m_MOSAIC & 0x000f) + 1;
INT32 mosaicy = ((m_MOSAIC & 0x00f0) >> 4) + 1;
INT32 stride;
INT32 x;
int x = 0;
if(!(m_DISPCNT & enablemask))
for (x = 0; x < 240; x++)
scanline[x] = 0x80000000;
if(m_DISPCNT & enablemask)
{
for(x = 0; x < 240; x++)
switch((ctrl & BGCNT_SCREENSIZE) >> BGCNT_SCREENSIZE_SHIFT)
{
scanline[x] = 0x80000000;
case 1:
width = 512;
break;
case 2:
height = 512;
break;
case 3:
width = 512;
height = 512;
break;
}
return;
}
switch((ctrl & BGCNT_SCREENSIZE) >> BGCNT_SCREENSIZE_SHIFT)
{
case 1:
width = 512;
break;
case 2:
height = 512;
break;
case 3:
width = 512;
height = 512;
break;
}
maskx = width - 1;
masky = height - 1;
pixx = hofs & maskx;
pixy = (vofs + ypos) & masky;
if(use_mosaic)
{
if((ypos % mosaicy) != 0)
maskx = width - 1;
masky = height - 1;
pixx = hofs & maskx;
pixy = (vofs + ypos) & masky;
if(use_mosaic)
{
mosaicy = (ypos / mosaicy) * mosaicy;
pixy = (vofs + mosaicy) & masky;
if((ypos % mosaicy) != 0)
{
mosaicy = (ypos / mosaicy) * mosaicy;
pixy = (vofs + mosaicy) & masky;
}
}
}
if(pixy > 255 && height > 256)
{
pixy &= 0x000000ff;
screendata += 0x400;
if(width > 256)
if(pixy > 255 && height > 256)
{
pixy &= 0x000000ff;
screendata += 0x400;
}
}
stride = (pixy >> 3) << 5;
if(ctrl & BGCNT_PALETTE256)
{
UINT16 *src = screendata + 0x400 * (pixx >> 8) + ((pixx & 255) >> 3) + stride;
for(x = 0; x < 240; x++)
{
UINT16 data = *src;
INT32 tile = data & TILEOBJ_TILE;
INT32 tilex = pixx & 7;
INT32 tiley = pixy & 7;
UINT8 color;
if(data & TILEOBJ_HFLIP)
if(width > 256)
{
tilex = 7 - tilex;
}
if(data & TILEOBJ_VFLIP)
{
tiley = 7 - tiley;
}
color = chardata[(tile << 6) + (tiley << 3) + tilex];
if(color)
{
scanline[x] = palette[color] | priority;
}
else
{
scanline[x] = 0x80000000;
}
if(data & TILEOBJ_HFLIP)
{
if(tilex == 0)
{
src++;
}
}
else if(tilex == 7)
{
src++;
}
pixx++;
if(pixx == 256)
{
if(width > 256)
{
src = screendata + 0x400 + stride;
}
else
{
src = screendata + stride;
pixx = 0;
}
}
else if(pixx >= width)
{
pixx = 0;
src = screendata + stride;
screendata += 0x400;
}
}
}
else
{
stride = (pixy >> 3) << 5;
UINT16 *src = screendata + 0x400 * (pixx >> 8) + ((pixx & 255) >> 3) + stride;
for(x = 0; x < 240; x++)
{
@ -474,7 +607,7 @@ void gba_state::draw_bg_scanline(UINT32 *scanline, int ypos, UINT32 enablemask,
INT32 tiley = pixy & 7;
UINT8 color;
UINT8 palindex;
if(data & TILEOBJ_HFLIP)
{
tilex = 7 - tilex;
@ -483,40 +616,40 @@ void gba_state::draw_bg_scanline(UINT32 *scanline, int ypos, UINT32 enablemask,
{
tiley = 7 - tiley;
}
color = chardata[(tile << 5) + (tiley << 2) + (tilex >> 1)];
if(tilex & 1)
if (ctrl & BGCNT_PALETTE256)
{
color >>= 4;
color = chardata[(tile << 6) + (tiley << 3) + tilex];
palindex = 0;
}
else
{
color &= 0x0f;
}
color = chardata[(tile << 5) + (tiley << 2) + (tilex >> 1)];
if (tilex & 1)
color >>= 4;
else
color &= 0x0f;
palindex = (data >> 8) & 0x00f0;
}
palindex = (data >> 8) & 0x00f0;
if(color)
{
if (color)
scanline[x] = palette[palindex + color] | priority;
}
else
{
scanline[x] = 0x80000000;
}
if(data & TILEOBJ_HFLIP)
if (data & TILEOBJ_HFLIP)
{
if(tilex == 0)
if (tilex == 0)
{
src++;
}
}
else if(tilex == 7)
else if (tilex == 7)
{
src++;
}
pixx++;
if(pixx == 256)
{
@ -536,24 +669,25 @@ void gba_state::draw_bg_scanline(UINT32 *scanline, int ypos, UINT32 enablemask,
src = screendata + stride;
}
}
}
if(use_mosaic)
{
if(mosaicx > 1)
if(use_mosaic)
{
INT32 m = 1;
for(x = 0; x < 239; x++)
if(mosaicx > 1)
{
scanline[x+1] = scanline[x];
m++;
if(m == mosaicx)
INT32 m = 1;
for(x = 0; x < 239; x++)
{
m = 1;
x++;
scanline[x+1] = scanline[x];
m++;
if(m == mosaicx)
{
m = 1;
x++;
}
}
}
}
}
}
@ -563,15 +697,13 @@ void gba_state::draw_gba_oam_window(UINT32 *scanline, int y)
UINT32 tilebytebase, tileindex, tiledrawindex;
UINT32 width, height;
UINT16 *pgba_oam = (UINT16 *)m_gba_oam.target();
int x = 0;
UINT8 *src = (UINT8*)m_gba_vram.target();
int x = 0;
for(x = 0; x < 240; x++)
{
for (x = 0; x < 240; x++)
scanline[x] = 0x80000000;
}
if( m_DISPCNT & DISPCNT_OBJWIN_EN )
if (m_DISPCNT & DISPCNT_OBJWIN_EN)
{
for( gba_oamindex = 127; gba_oamindex >= 0; gba_oamindex-- )
{
@ -1016,11 +1148,9 @@ void gba_state::draw_gba_oam(UINT32 *scanline, int y)
UINT16 *palette = (UINT16*)m_gba_pram.target();
int x = 0;
for(x = 0; x < 240; x++)
{
for (x = 0; x < 240; x++)
scanline[x] = 0x80000000;
}
if( m_DISPCNT & DISPCNT_OBJ_EN )
{
for( gba_oamindex = 0; gba_oamindex < 128; gba_oamindex++ )
@ -1686,61 +1816,50 @@ void gba_state::draw_scanline(int y)
{
bitmap_ind16 &bitmap = m_bitmap;
UINT16 *scanline = &bitmap.pix16(y);
int i, x;
UINT8 submode = 0;
int depth = 0;
// forced blank
if (m_DISPCNT & DISPCNT_BLANK)
{
// forced blank is white
for (i = 0; i < 240; i++)
{
scanline[i] = 0x7fff;
}
for (int x = 0; x < 240; x++)
scanline[x] = 0x7fff;
return;
}
if(!m_fxOn && !m_windowOn && !(m_DISPCNT & DISPCNT_OBJWIN_EN))
{
submode = 0;
}
submode = GBA_SUBMODE0;
else if(m_fxOn && !m_windowOn && !(m_DISPCNT & DISPCNT_OBJWIN_EN))
{
submode = 1;
}
submode = GBA_SUBMODE1;
else
{
submode = 2;
}
submode = GBA_SUBMODE2;
//printf( "mode = %d, %d\n", m_DISPCNT & 7, submode );
if (m_DISPCNT & 7 == 3)
depth = 16;
else if (m_DISPCNT & 7 == 4)
depth = 8;
else if (m_DISPCNT & 7 == 5)
depth = 4;
//printf("mode = %d, %d\n", m_DISPCNT & 7, submode);
switch(m_DISPCNT & 7)
{
case 0:
draw_mode0(submode, y, &m_xferscan[0][1024], &m_xferscan[1][1024], &m_xferscan[2][1024], &m_xferscan[3][1024], &m_xferscan[4][1024], &m_xferscan[5][1024], &m_xferscan[6][1024], 0);
break;
case 1:
draw_mode1(submode, y, &m_xferscan[0][1024], &m_xferscan[1][1024], &m_xferscan[2][1024], &m_xferscan[3][1024], &m_xferscan[4][1024], &m_xferscan[5][1024], &m_xferscan[6][1024], 0);
break;
case 2:
draw_mode2(submode, y, &m_xferscan[0][1024], &m_xferscan[1][1024], &m_xferscan[2][1024], &m_xferscan[3][1024], &m_xferscan[4][1024], &m_xferscan[5][1024], &m_xferscan[6][1024], 0);
break;
case 3:
draw_mode345(submode, y, &m_xferscan[0][1024], &m_xferscan[1][1024], &m_xferscan[2][1024], &m_xferscan[3][1024], &m_xferscan[4][1024], &m_xferscan[5][1024], &m_xferscan[6][1024], 16);
break;
case 4:
draw_mode345(submode, y, &m_xferscan[0][1024], &m_xferscan[1][1024], &m_xferscan[2][1024], &m_xferscan[3][1024], &m_xferscan[4][1024], &m_xferscan[5][1024], &m_xferscan[6][1024], 8);
break;
case 5:
draw_mode345(submode, y, &m_xferscan[0][1024], &m_xferscan[1][1024], &m_xferscan[2][1024], &m_xferscan[3][1024], &m_xferscan[4][1024], &m_xferscan[5][1024], &m_xferscan[6][1024], 4);
draw_modes( m_DISPCNT & 7, submode, y, &m_xferscan[0][1024], &m_xferscan[1][1024], &m_xferscan[2][1024], &m_xferscan[3][1024], &m_xferscan[4][1024], &m_xferscan[5][1024], &m_xferscan[6][1024], depth);
break;
default:
fatalerror( "Invalid screen mode (6 or 7)!\n" );
break;
}
for(x = 0; x < 240; x++)
for (int x = 0; x < 240; x++)
{
scanline[x] = m_xferscan[6][1024 + x] & 0x7fff;
}

View File

@ -1,416 +0,0 @@
/***************************************************************************
gbam345.c
Handles GBA rendering for modes 3, 4, and 5.
By R. Belmont & Harmony
***************************************************************************/
void gba_state::draw_mode345(int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
switch (submode)
{
case 0:
draw_roz_bitmap_mode_scanline(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
case 1:
draw_roz_bitmap_mode_scanline_nowindow(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
case 2:
draw_roz_bitmap_mode_scanline_all(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
}
}
void gba_state::draw_roz_bitmap_mode_scanline(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
draw_roz_bitmap_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed, bpp);
draw_gba_oam(lineOBJ, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
if(line2[x] < color)
{
color = line2[x];
top = 0x04;
}
if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if(top == 0x10 && (color & 0x00010000) != 0)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if(line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
m_gfxBG2Changed = 0;
}
void gba_state::draw_roz_bitmap_mode_scanline_nowindow(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
int effect = m_BLDCNT & BLDCNT_SFX;
draw_roz_bitmap_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed, bpp);
draw_gba_oam(lineOBJ, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
if(line2[x] < color)
{
color = line2[x];
top = 0x04;
}
if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if((color & 0x00010000) == 0)
{
switch(effect)
{
case BLDCNT_SFX_NONE:
break;
case BLDCNT_SFX_ALPHA:
if(m_BLDCNT & top)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if(line2[x] < back)
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
}
break;
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
else
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if(line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
m_gfxBG2Changed = 0;
}
void gba_state::draw_roz_bitmap_mode_scanline_all(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
int inWindow0 = 0;
int inWindow1 = 0;
UINT8 inWin0Mask = m_WININ & 0x00ff;
UINT8 inWin1Mask = m_WININ >> 8;
UINT8 outMask = m_WINOUT & 0x00ff;
if(m_DISPCNT & DISPCNT_WIN0_EN)
{
UINT8 v0 = m_WIN0V >> 8;
UINT8 v1 = m_WIN0V & 0x00ff;
inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
if(v1 >= v0)
{
inWindow0 |= (y >= v0 && y < v1) ? 1 : 0;
}
else
{
inWindow0 |= (y >= v0 || y < v1) ? 1 : 0;
}
}
if(m_DISPCNT & DISPCNT_WIN1_EN)
{
UINT8 v0 = m_WIN1V >> 8;
UINT8 v1 = m_WIN1V & 0x00ff;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
if(v1 >= v0)
{
inWindow1 |= (y >= v0 && y < v1) ? 1 : 0;
}
else
{
inWindow1 |= (y >= v0 || y < v1) ? 1 : 0;
}
}
draw_roz_bitmap_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed, bpp);
draw_gba_oam(lineOBJ, y);
draw_gba_oam_window(lineOBJWin, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
UINT8 mask = outMask;
if((lineOBJWin[x] & 0x80000000) == 0)
{
mask = m_WINOUT >> 8;
}
if(inWindow1)
{
if(is_in_window(x, 1))
{
mask = inWin1Mask;
}
}
if(inWindow0)
{
if(is_in_window(x, 0))
{
mask = inWin0Mask;
}
}
if((mask & 0x04) != 0 && (line2[x] < color))
{
color = line2[x];
top = 0x04;
}
if((mask & 0x10) != 0 && (UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if((mask & 0x20) != 0)
{
if((color & 0x00010000) == 0)
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_NONE:
break;
case BLDCNT_SFX_ALPHA:
{
if(top & m_BLDCNT)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x04) != 0 && (line2[x] < back))
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
}
break;
}
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
else
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x04) != 0 && (line2[x] < back))
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
}
else if(color & 0x00010000)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x04) != 0 && (line2[x] < back))
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
m_gfxBG2Changed = 0;
}

View File

@ -1,602 +0,0 @@
/***************************************************************************
gbamode0.c
Handles GBA mode 0 screen rendering
By R. Belmont & Harmony
***************************************************************************/
void gba_state::draw_mode0(int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
switch (submode)
{
case 0:
draw_mode0_scanline(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
case 1:
draw_mode0_scanline_nowindow(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
case 2:
draw_mode0_scanline_all(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
}
}
void gba_state::draw_mode0_scanline(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
draw_bg_scanline(line0, y, DISPCNT_BG0_EN, m_BG0CNT, m_BG0HOFS, m_BG0VOFS);
draw_bg_scanline(line1, y, DISPCNT_BG1_EN, m_BG1CNT, m_BG1HOFS, m_BG1VOFS);
draw_bg_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2HOFS, m_BG2VOFS);
draw_bg_scanline(line3, y, DISPCNT_BG3_EN, m_BG3CNT, m_BG3HOFS, m_BG3VOFS);
draw_gba_oam(lineOBJ, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
if(line0[x] < color)
{
color = line0[x];
top = 0x01;
}
if((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24))
{
color = line1[x];
top = 0x02;
}
if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24))
{
color = line2[x];
top = 0x04;
}
if((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24))
{
color = line3[x];
top = 0x08;
}
if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if(top == 0x10 && (color & 0x00010000) != 0)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))
{
back = line0[x];
top2 = 0x01;
}
if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))
{
back = line1[x];
top2 = 0x02;
}
if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
}
void gba_state::draw_mode0_scanline_nowindow(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
int effect = m_BLDCNT & BLDCNT_SFX;
draw_bg_scanline(line0, y, DISPCNT_BG0_EN, m_BG0CNT, m_BG0HOFS, m_BG0VOFS);
draw_bg_scanline(line1, y, DISPCNT_BG1_EN, m_BG1CNT, m_BG1HOFS, m_BG1VOFS);
draw_bg_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2HOFS, m_BG2VOFS);
draw_bg_scanline(line3, y, DISPCNT_BG3_EN, m_BG3CNT, m_BG3HOFS, m_BG3VOFS);
draw_gba_oam(lineOBJ, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
if(line0[x] < color)
{
color = line0[x];
top = 0x01;
}
if(line1[x] < (color & 0xff000000))
{
color = line1[x];
top = 0x02;
}
if(line2[x] < (color & 0xff000000))
{
color = line2[x];
top = 0x04;
}
if(line3[x] < (color & 0xff000000))
{
color = line3[x];
top = 0x08;
}
if(lineOBJ[x] < (color & 0xff000000))
{
color = lineOBJ[x];
top = 0x10;
}
if((color & 0x00010000) == 0)
{
switch(effect)
{
case BLDCNT_SFX_NONE:
break;
case BLDCNT_SFX_ALPHA:
if(m_BLDCNT & top)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if(line0[x] < back)
{
if(top != 0x01)
{
back = line0[x];
top2 = 0x01;
}
}
if(line1[x] < (back & 0xff000000))
{
if(top != 0x02)
{
back = line1[x];
top2 = 0x02;
}
}
if(line2[x] < (back & 0xff000000))
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if(line3[x] < (back & 0xff000000))
{
if(top != 0x08)
{
back = line3[x];
top2 = 0x08;
}
}
if(lineOBJ[x] < (back & 0xff000000))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
}
break;
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
else
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if(line0[x] < back)
{
back = line0[x];
top2 = 0x01;
}
if(line1[x] < (back & 0xff000000))
{
back = line1[x];
top2 = 0x02;
}
if(line2[x] < (back & 0xff000000))
{
back = line2[x];
top2 = 0x04;
}
if(line3[x] < (back & 0xff000000))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
}
void gba_state::draw_mode0_scanline_all(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
int inWindow0 = 0;
int inWindow1 = 0;
UINT8 inWin0Mask = m_WININ & 0x00ff;
UINT8 inWin1Mask = m_WININ >> 8;
UINT8 outMask = m_WINOUT & 0x00ff;
if(m_DISPCNT & DISPCNT_WIN0_EN)
{
UINT8 v0 = m_WIN0V >> 8;
UINT8 v1 = m_WIN0V & 0x00ff;
inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
if(v1 >= v0)
{
inWindow0 |= (y >= v0 && y < v1) ? 1 : 0;
}
else
{
inWindow0 |= (y >= v0 || y < v1) ? 1 : 0;
}
}
if(m_DISPCNT & DISPCNT_WIN1_EN)
{
UINT8 v0 = m_WIN1V >> 8;
UINT8 v1 = m_WIN1V & 0x00ff;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
if(v1 >= v0)
{
inWindow1 |= (y >= v0 && y < v1) ? 1 : 0;
}
else
{
inWindow1 |= (y >= v0 || y < v1) ? 1 : 0;
}
}
draw_bg_scanline(line0, y, DISPCNT_BG0_EN, m_BG0CNT, m_BG0HOFS, m_BG0VOFS);
draw_bg_scanline(line1, y, DISPCNT_BG1_EN, m_BG1CNT, m_BG1HOFS, m_BG1VOFS);
draw_bg_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2HOFS, m_BG2VOFS);
draw_bg_scanline(line3, y, DISPCNT_BG3_EN, m_BG3CNT, m_BG3HOFS, m_BG3VOFS);
draw_gba_oam(lineOBJ, y);
draw_gba_oam_window(lineOBJWin, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
UINT8 mask = outMask;
if((lineOBJWin[x] & 0x80000000) == 0)
{
mask = m_WINOUT >> 8;
}
if(inWindow1)
{
if(is_in_window(x, 1))
{
mask = inWin1Mask;
}
}
if(inWindow0)
{
if(is_in_window(x, 0))
{
mask = inWin0Mask;
}
}
if((mask & 0x01) != 0 && (line0[x] < color))
{
color = line0[x];
top = 0x01;
}
if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24)))
{
color = line1[x];
top = 0x02;
}
if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24)))
{
color = line2[x];
top = 0x04;
}
if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24)))
{
color = line3[x];
top = 0x08;
}
if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24)))
{
color = lineOBJ[x];
top = 0x10;
}
if((mask & 0x20) != 0)
{
if((color & 0x00010000) == 0)
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_NONE:
break;
case BLDCNT_SFX_ALPHA:
{
if(top & m_BLDCNT)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x01)
{
back = line0[x];
top2 = 0x01;
}
}
if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x02)
{
back = line1[x];
top2 = 0x02;
}
}
if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x08)
{
back = line3[x];
top2 = 0x08;
}
}
if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
}
break;
}
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
else
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
{
back = line0[x];
top2 = 0x01;
}
if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
{
back = line1[x];
top2 = 0x02;
}
if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
{
back = line2[x];
top2 = 0x04;
}
if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
}
else if(color & 0x00010000)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
{
back = line0[x];
top2 = 0x01;
}
if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
{
back = line1[x];
top2 = 0x02;
}
if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
{
back = line2[x];
top2 = 0x04;
}
if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
}

View File

@ -1,542 +0,0 @@
/***************************************************************************
gbamode1.c
Handles GBA mode 1 screen rendering
By R. Belmont & Harmony
***************************************************************************/
void gba_state::draw_mode1(int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
switch (submode)
{
case 0:
draw_mode1_scanline(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
case 1:
draw_mode1_scanline_nowindow(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
case 2:
draw_mode1_scanline_all(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
}
}
void gba_state::draw_mode1_scanline(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
draw_bg_scanline(line0, y, DISPCNT_BG0_EN, m_BG0CNT, m_BG0HOFS, m_BG0VOFS);
draw_bg_scanline(line1, y, DISPCNT_BG1_EN, m_BG1CNT, m_BG1HOFS, m_BG1VOFS);
draw_roz_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed);
draw_gba_oam(lineOBJ, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
if(line0[x] < color)
{
color = line0[x];
top = 0x01;
}
if((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24))
{
color = line1[x];
top = 0x02;
}
if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24))
{
color = line2[x];
top = 0x04;
}
if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if(top == 0x10 && (color & 0x00010000) != 0)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))
{
back = line0[x];
top2 = 0x01;
}
if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))
{
back = line1[x];
top2 = 0x02;
}
if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
m_gfxBG2Changed = 0;
}
void gba_state::draw_mode1_scanline_nowindow(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
int effect = m_BLDCNT & BLDCNT_SFX;
draw_bg_scanline(line0, y, DISPCNT_BG0_EN, m_BG0CNT, m_BG0HOFS, m_BG0VOFS);
draw_bg_scanline(line1, y, DISPCNT_BG1_EN, m_BG1CNT, m_BG1HOFS, m_BG1VOFS);
draw_roz_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed);
draw_gba_oam(lineOBJ, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
if(line0[x] < color)
{
color = line0[x];
top = 0x01;
}
if(line1[x] < (color & 0xff000000))
{
color = line1[x];
top = 0x02;
}
if(line2[x] < (color & 0xff000000))
{
color = line2[x];
top = 0x04;
}
if(lineOBJ[x] < (color & 0xff000000))
{
color = lineOBJ[x];
top = 0x10;
}
if((color & 0x00010000) == 0)
{
switch(effect)
{
case BLDCNT_SFX_NONE:
break;
case BLDCNT_SFX_ALPHA:
if(m_BLDCNT & top)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))
{
if(top != 0x01)
{
back = line0[x];
top2 = 0x01;
}
}
if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))
{
if(top != 0x02)
{
back = line1[x];
top2 = 0x02;
}
}
if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
}
break;
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
else
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))
{
back = line0[x];
top2 = 0x01;
}
if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))
{
back = line1[x];
top2 = 0x02;
}
if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
m_gfxBG2Changed = 0;
}
void gba_state::draw_mode1_scanline_all(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
int inWindow0 = 0;
int inWindow1 = 0;
UINT8 inWin0Mask = m_WININ & 0x00ff;
UINT8 inWin1Mask = m_WININ >> 8;
UINT8 outMask = m_WINOUT & 0x00ff;
if(m_DISPCNT & DISPCNT_WIN0_EN)
{
UINT8 v0 = m_WIN0V >> 8;
UINT8 v1 = m_WIN0V & 0x00ff;
inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
if(v1 >= v0)
{
inWindow0 |= (y >= v0 && y < v1) ? 1 : 0;
}
else
{
inWindow0 |= (y >= v0 || y < v1) ? 1 : 0;
}
}
if(m_DISPCNT & DISPCNT_WIN1_EN)
{
UINT8 v0 = m_WIN1V >> 8;
UINT8 v1 = m_WIN1V & 0x00ff;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
if(v1 >= v0)
{
inWindow1 |= (y >= v0 && y < v1) ? 1 : 0;
}
else
{
inWindow1 |= (y >= v0 || y < v1) ? 1 : 0;
}
}
draw_bg_scanline(line0, y, DISPCNT_BG0_EN, m_BG0CNT, m_BG0HOFS, m_BG0VOFS);
draw_bg_scanline(line1, y, DISPCNT_BG1_EN, m_BG1CNT, m_BG1HOFS, m_BG1VOFS);
draw_roz_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed);
draw_gba_oam(lineOBJ, y);
draw_gba_oam_window(lineOBJWin, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
UINT8 mask = outMask;
if((lineOBJWin[x] & 0x80000000) == 0)
{
mask = m_WINOUT >> 8;
}
if(inWindow1)
{
if(is_in_window(x, 1))
{
mask = inWin1Mask;
}
}
if(inWindow0)
{
if(is_in_window(x, 0))
{
mask = inWin0Mask;
}
}
if((mask & 0x01) != 0 && (line0[x] < color))
{
color = line0[x];
top = 0x01;
}
if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24)))
{
color = line1[x];
top = 0x02;
}
if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24)))
{
color = line2[x];
top = 0x04;
}
if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24)))
{
color = lineOBJ[x];
top = 0x10;
}
if((mask & 0x20) != 0)
{
if((color & 0x00010000) == 0)
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_NONE:
break;
case BLDCNT_SFX_ALPHA:
{
if(top & m_BLDCNT)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x01)
{
back = line0[x];
top2 = 0x01;
}
}
if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x02)
{
back = line1[x];
top2 = 0x02;
}
}
if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
}
break;
}
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
else
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
{
back = line0[x];
top2 = 0x01;
}
if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
{
back = line1[x];
top2 = 0x02;
}
if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
}
else if(color & 0x00010000)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)))
{
back = line0[x];
top2 = 0x01;
}
if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)))
{
back = line1[x];
top2 = 0x02;
}
if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)))
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
m_gfxBG2Changed = 0;
}

View File

@ -1,482 +0,0 @@
/***************************************************************************
gbamode2.c
Handles GBA mode 2 screen rendering
By R. Belmont & Harmony
***************************************************************************/
void gba_state::draw_mode2(int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
switch (submode)
{
case 0:
draw_mode2_scanline(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
case 1:
draw_mode2_scanline_nowindow(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
case 2:
draw_mode2_scanline_all(y, line0, line1, line2, line3, lineOBJ, lineOBJWin, lineMix, bpp);
break;
}
}
void gba_state::draw_mode2_scanline(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
draw_roz_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed);
draw_roz_scanline(line3, y, DISPCNT_BG3_EN, m_BG3CNT, m_BG3X, m_BG3Y, m_BG3PA, m_BG3PB, m_BG3PC, m_BG3PD, &m_gfxBG3X, &m_gfxBG3Y, m_gfxBG3Changed);
draw_gba_oam(lineOBJ, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24))
{
color = line2[x];
top = 0x04;
}
if((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24))
{
color = line3[x];
top = 0x08;
}
if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if(top == 0x10 && (color & 0x00010000) != 0)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
m_gfxBG2Changed = 0;
m_gfxBG3Changed = 0;
}
void gba_state::draw_mode2_scanline_nowindow(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
int effect = m_BLDCNT & BLDCNT_SFX;
draw_roz_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed);
draw_roz_scanline(line3, y, DISPCNT_BG3_EN, m_BG3CNT, m_BG3X, m_BG3Y, m_BG3PA, m_BG3PB, m_BG3PC, m_BG3PD, &m_gfxBG3X, &m_gfxBG3Y, m_gfxBG3Changed);
draw_gba_oam(lineOBJ, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24))
{
color = line2[x];
top = 0x04;
}
if((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24))
{
color = line3[x];
top = 0x08;
}
if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if((color & 0x00010000) == 0)
{
switch(effect)
{
case BLDCNT_SFX_NONE:
break;
case BLDCNT_SFX_ALPHA:
if(m_BLDCNT & top)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))
{
if(top != 0x08)
{
back = line3[x];
top2 = 0x08;
}
}
if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
}
break;
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
else
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
m_gfxBG2Changed = 0;
m_gfxBG3Changed = 0;
}
void gba_state::draw_mode2_scanline_all(int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp)
{
int x = 0;
UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000;
int inWindow0 = 0;
int inWindow1 = 0;
UINT8 inWin0Mask = m_WININ & 0x00ff;
UINT8 inWin1Mask = m_WININ >> 8;
UINT8 outMask = m_WINOUT & 0x00ff;
if(m_DISPCNT & DISPCNT_WIN0_EN)
{
UINT8 v0 = m_WIN0V >> 8;
UINT8 v1 = m_WIN0V & 0x00ff;
inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
if(v1 >= v0)
{
inWindow0 |= (y >= v0 && y < v1) ? 1 : 0;
}
else
{
inWindow0 |= (y >= v0 || y < v1) ? 1 : 0;
}
}
if(m_DISPCNT & DISPCNT_WIN1_EN)
{
UINT8 v0 = m_WIN1V >> 8;
UINT8 v1 = m_WIN1V & 0x00ff;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0;
if(v1 >= v0)
{
inWindow1 |= (y >= v0 && y < v1) ? 1 : 0;
}
else
{
inWindow1 |= (y >= v0 || y < v1) ? 1 : 0;
}
}
draw_roz_scanline(line2, y, DISPCNT_BG2_EN, m_BG2CNT, m_BG2X, m_BG2Y, m_BG2PA, m_BG2PB, m_BG2PC, m_BG2PD, &m_gfxBG2X, &m_gfxBG2Y, m_gfxBG2Changed);
draw_roz_scanline(line3, y, DISPCNT_BG3_EN, m_BG3CNT, m_BG3X, m_BG3Y, m_BG3PA, m_BG3PB, m_BG3PC, m_BG3PD, &m_gfxBG3X, &m_gfxBG3Y, m_gfxBG3Changed);
draw_gba_oam(lineOBJ, y);
draw_gba_oam_window(lineOBJWin, y);
for(x = 0; x < 240; x++)
{
UINT32 color = backdrop;
UINT8 top = 0x20;
UINT8 mask = outMask;
if((lineOBJWin[x] & 0x80000000) == 0)
{
mask = m_WINOUT >> 8;
}
if(inWindow1)
{
if(is_in_window(x, 1))
{
mask = inWin1Mask;
}
}
if(inWindow0)
{
if(is_in_window(x, 0))
{
mask = inWin0Mask;
}
}
if((mask & 0x04) != 0 && (line2[x] < color))
{
color = line2[x];
top = 0x04;
}
if((mask & 0x08) != 0 && (UINT8)(line3[x] >> 24) < (UINT8)(color >> 24))
{
color = line3[x];
top = 0x08;
}
if((mask & 0x10) != 0 && (UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if((mask & 0x20) != 0)
{
if((color & 0x00010000) == 0)
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_NONE:
break;
case BLDCNT_SFX_ALPHA:
{
if(top & m_BLDCNT)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x04) != 0 && (line2[x] < back))
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x08)
{
back = line3[x];
top2 = 0x08;
}
}
if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24)))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
}
break;
}
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
else
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x04) != 0 && (line2[x] < back))
{
back = line2[x];
top2 = 0x04;
}
if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
}
else if(color & 0x00010000)
{
UINT32 back = backdrop;
UINT8 top2 = 0x20;
if((mask & 0x04) != 0 && (line2[x] < back ))
{
back = line2[x];
top2 = 0x04;
}
if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT))
{
color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]);
}
else
{
switch(m_BLDCNT & BLDCNT_SFX)
{
case BLDCNT_SFX_LIGHTEN:
if(top & m_BLDCNT)
{
color = increase_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
case BLDCNT_SFX_DARKEN:
if(top & m_BLDCNT)
{
color = decrease_brightness(color, coeff[m_BLDY & 0x1f]);
}
break;
}
}
}
lineMix[x] = color;
}
m_gfxBG2Changed = 0;
m_gfxBG3Changed = 0;
}