mirror of https://github.com/mgba-emu/mgba.git
GB Video: Add basic scrolling support
This commit is contained in:
parent
a8b473870d
commit
06f47c8d2c
|
@ -61,9 +61,8 @@ static void GBVideoSoftwareRendererInit(struct GBVideoRenderer* renderer) {
|
||||||
|
|
||||||
static void GBVideoSoftwareRendererReset(struct GBVideoRenderer* renderer) {
|
static void GBVideoSoftwareRendererReset(struct GBVideoRenderer* renderer) {
|
||||||
struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
|
struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
|
||||||
int i;
|
softwareRenderer->scy = 0;
|
||||||
|
softwareRenderer->scx = 0;
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GBVideoSoftwareRendererDeinit(struct GBVideoRenderer* renderer) {
|
static void GBVideoSoftwareRendererDeinit(struct GBVideoRenderer* renderer) {
|
||||||
|
@ -99,6 +98,12 @@ static uint8_t GBVideoSoftwareRendererWriteVideoRegister(struct GBVideoRenderer*
|
||||||
softwareRenderer->objPalette[1][2] = GB_PALETTE[(value >> 4) & 3];
|
softwareRenderer->objPalette[1][2] = GB_PALETTE[(value >> 4) & 3];
|
||||||
softwareRenderer->objPalette[1][3] = GB_PALETTE[(value >> 6) & 3];
|
softwareRenderer->objPalette[1][3] = GB_PALETTE[(value >> 6) & 3];
|
||||||
break;
|
break;
|
||||||
|
case REG_SCY:
|
||||||
|
softwareRenderer->scy = value;
|
||||||
|
break;
|
||||||
|
case REG_SCX:
|
||||||
|
softwareRenderer->scx = value;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -143,17 +148,21 @@ static void GBVideoSoftwareRendererDrawBackground(struct GBVideoSoftwareRenderer
|
||||||
data += 0x1000;
|
data += 0x1000;
|
||||||
}
|
}
|
||||||
int x;
|
int x;
|
||||||
|
int topY = (((y + renderer->scy) >> 3) & 0x1F) * 0x20;
|
||||||
|
int bottomY = (y + renderer->scy) & 7;
|
||||||
for (x = 0; x < GB_VIDEO_HORIZONTAL_PIXELS; ++x) {
|
for (x = 0; x < GB_VIDEO_HORIZONTAL_PIXELS; ++x) {
|
||||||
|
int topX = ((x + renderer->scx) >> 3) & 0x1F;
|
||||||
|
int bottomX = 7 - ((x + renderer->scx) & 7);
|
||||||
int bgTile;
|
int bgTile;
|
||||||
if (GBRegisterLCDCIsTileData(renderer->lcdc)) {
|
if (GBRegisterLCDCIsTileData(renderer->lcdc)) {
|
||||||
bgTile = maps[(x >> 3) + (0x20 * (y >> 3))];
|
bgTile = maps[topX + topY];
|
||||||
} else {
|
} else {
|
||||||
bgTile = ((int8_t*) maps)[(x >> 3) + (0x20 * (y >> 3))];
|
bgTile = ((int8_t*) maps)[topX + topY];
|
||||||
}
|
}
|
||||||
uint8_t tileDataLower = data[(bgTile * 8 + (y & 7)) * 2];
|
uint8_t tileDataLower = data[(bgTile * 8 + bottomY) * 2];
|
||||||
uint8_t tileDataUpper = data[(bgTile * 8 + (y & 7)) * 2 + 1];
|
uint8_t tileDataUpper = data[(bgTile * 8 + bottomY) * 2 + 1];
|
||||||
tileDataUpper >>= 7 - (x & 7);
|
tileDataUpper >>= bottomX;
|
||||||
tileDataLower >>= 7 - (x & 7);
|
tileDataLower >>= bottomX;
|
||||||
renderer->row[x] = renderer->bgPalette[((tileDataUpper & 1) << 1) | (tileDataLower & 1)];
|
renderer->row[x] = renderer->bgPalette[((tileDataUpper & 1) << 1) | (tileDataLower & 1)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,9 @@ struct GBVideoSoftwareRenderer {
|
||||||
|
|
||||||
uint32_t* temporaryBuffer;
|
uint32_t* temporaryBuffer;
|
||||||
|
|
||||||
|
uint8_t scy;
|
||||||
|
uint8_t scx;
|
||||||
|
|
||||||
GBRegisterLCDC lcdc;
|
GBRegisterLCDC lcdc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue