mirror of https://github.com/mgba-emu/mgba.git
Bitmap of enabled sprites
This commit is contained in:
parent
edecf6c1f6
commit
6829b54234
|
@ -312,6 +312,8 @@ void GBAStore32(struct ARMMemory* memory, uint32_t address, int32_t value, int*
|
||||||
break;
|
break;
|
||||||
case BASE_OAM:
|
case BASE_OAM:
|
||||||
((int32_t*) gbaMemory->p->video.oam.raw)[(address & (SIZE_OAM - 1)) >> 2] = value;
|
((int32_t*) gbaMemory->p->video.oam.raw)[(address & (SIZE_OAM - 1)) >> 2] = value;
|
||||||
|
gbaMemory->p->video.renderer->writeOAM(gbaMemory->p->video.renderer, (address & (SIZE_OAM - 4)) >> 1);
|
||||||
|
gbaMemory->p->video.renderer->writeOAM(gbaMemory->p->video.renderer, ((address & (SIZE_OAM - 4)) >> 1) + 1);
|
||||||
break;
|
break;
|
||||||
case BASE_CART0:
|
case BASE_CART0:
|
||||||
break;
|
break;
|
||||||
|
@ -352,6 +354,7 @@ void GBAStore16(struct ARMMemory* memory, uint32_t address, int16_t value, int*
|
||||||
break;
|
break;
|
||||||
case BASE_OAM:
|
case BASE_OAM:
|
||||||
gbaMemory->p->video.oam.raw[(address & (SIZE_OAM - 1)) >> 1] = value;
|
gbaMemory->p->video.oam.raw[(address & (SIZE_OAM - 1)) >> 1] = value;
|
||||||
|
gbaMemory->p->video.renderer->writeOAM(gbaMemory->p->video.renderer, (address & (SIZE_OAM - 1)) >> 1);
|
||||||
break;
|
break;
|
||||||
case BASE_CART0:
|
case BASE_CART0:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -161,6 +161,7 @@ struct GBAVideoRenderer {
|
||||||
|
|
||||||
uint16_t (*writeVideoRegister)(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
uint16_t (*writeVideoRegister)(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
||||||
void (*writePalette)(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
void (*writePalette)(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
||||||
|
void (*writeOAM)(struct GBAVideoRenderer* renderer, uint32_t oam);
|
||||||
void (*drawScanline)(struct GBAVideoRenderer* renderer, int y);
|
void (*drawScanline)(struct GBAVideoRenderer* renderer, int y);
|
||||||
void (*finishFrame)(struct GBAVideoRenderer* renderer);
|
void (*finishFrame)(struct GBAVideoRenderer* renderer);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
static void GBAVideoSoftwareRendererInit(struct GBAVideoRenderer* renderer);
|
static void GBAVideoSoftwareRendererInit(struct GBAVideoRenderer* renderer);
|
||||||
static void GBAVideoSoftwareRendererDeinit(struct GBAVideoRenderer* renderer);
|
static void GBAVideoSoftwareRendererDeinit(struct GBAVideoRenderer* renderer);
|
||||||
|
static void GBAVideoSoftwareRendererWriteOAM(struct GBAVideoRenderer* renderer, uint32_t oam);
|
||||||
static void GBAVideoSoftwareRendererWritePalette(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
static void GBAVideoSoftwareRendererWritePalette(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
||||||
static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
||||||
static void GBAVideoSoftwareRendererDrawScanline(struct GBAVideoRenderer* renderer, int y);
|
static void GBAVideoSoftwareRendererDrawScanline(struct GBAVideoRenderer* renderer, int y);
|
||||||
|
@ -43,6 +44,7 @@ void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer) {
|
||||||
renderer->d.init = GBAVideoSoftwareRendererInit;
|
renderer->d.init = GBAVideoSoftwareRendererInit;
|
||||||
renderer->d.deinit = GBAVideoSoftwareRendererDeinit;
|
renderer->d.deinit = GBAVideoSoftwareRendererDeinit;
|
||||||
renderer->d.writeVideoRegister = GBAVideoSoftwareRendererWriteVideoRegister;
|
renderer->d.writeVideoRegister = GBAVideoSoftwareRendererWriteVideoRegister;
|
||||||
|
renderer->d.writeOAM = GBAVideoSoftwareRendererWriteOAM;
|
||||||
renderer->d.writePalette = GBAVideoSoftwareRendererWritePalette;
|
renderer->d.writePalette = GBAVideoSoftwareRendererWritePalette;
|
||||||
renderer->d.drawScanline = GBAVideoSoftwareRendererDrawScanline;
|
renderer->d.drawScanline = GBAVideoSoftwareRendererDrawScanline;
|
||||||
renderer->d.finishFrame = GBAVideoSoftwareRendererFinishFrame;
|
renderer->d.finishFrame = GBAVideoSoftwareRendererFinishFrame;
|
||||||
|
@ -73,6 +75,7 @@ static void GBAVideoSoftwareRendererInit(struct GBAVideoRenderer* renderer) {
|
||||||
softwareRenderer->blendEffect = BLEND_NONE;
|
softwareRenderer->blendEffect = BLEND_NONE;
|
||||||
memset(softwareRenderer->normalPalette, 0, sizeof(softwareRenderer->normalPalette));
|
memset(softwareRenderer->normalPalette, 0, sizeof(softwareRenderer->normalPalette));
|
||||||
memset(softwareRenderer->variantPalette, 0, sizeof(softwareRenderer->variantPalette));
|
memset(softwareRenderer->variantPalette, 0, sizeof(softwareRenderer->variantPalette));
|
||||||
|
memset(softwareRenderer->enabledBitmap, 0, sizeof(softwareRenderer->enabledBitmap));
|
||||||
|
|
||||||
softwareRenderer->blda = 0;
|
softwareRenderer->blda = 0;
|
||||||
softwareRenderer->bldb = 0;
|
softwareRenderer->bldb = 0;
|
||||||
|
@ -250,6 +253,17 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void GBAVideoSoftwareRendererWriteOAM(struct GBAVideoRenderer* renderer, uint32_t oam) {
|
||||||
|
struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer;
|
||||||
|
if ((oam & 0x3) != 0x3) {
|
||||||
|
oam >>= 2;
|
||||||
|
struct GBAObj* sprite = &renderer->oam->obj[oam];
|
||||||
|
int enabled = sprite->transformed || !sprite->disable;
|
||||||
|
enabled << (oam & 0x1F);
|
||||||
|
softwareRenderer->enabledBitmap[oam >> 5] = (softwareRenderer->enabledBitmap[oam >> 5] & ~(1 << (oam & 0x1F))) | enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void GBAVideoSoftwareRendererWritePalette(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value) {
|
static void GBAVideoSoftwareRendererWritePalette(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value) {
|
||||||
struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer;
|
struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer;
|
||||||
uint32_t color32 = 0;
|
uint32_t color32 = 0;
|
||||||
|
@ -420,12 +434,22 @@ static void _drawScanline(struct GBAVideoSoftwareRenderer* renderer, int y) {
|
||||||
int i;
|
int i;
|
||||||
memset(renderer->spriteLayer, 0, sizeof(renderer->spriteLayer));
|
memset(renderer->spriteLayer, 0, sizeof(renderer->spriteLayer));
|
||||||
if (renderer->dispcnt.objEnable) {
|
if (renderer->dispcnt.objEnable) {
|
||||||
for (i = 0; i < 128; ++i) {
|
int j;
|
||||||
struct GBAObj* sprite = &renderer->d.oam->obj[i];
|
for (j = 0; j < 4; ++j) {
|
||||||
if (sprite->transformed) {
|
uint32_t bitmap = renderer->enabledBitmap[j];
|
||||||
_preprocessTransformedSprite(renderer, &renderer->d.oam->tobj[i], y);
|
if (!bitmap) {
|
||||||
} else if (!sprite->disable) {
|
continue;
|
||||||
_preprocessSprite(renderer, sprite, y);
|
}
|
||||||
|
for (i = j * 16; i < (j + 1) * 16; ++i) {
|
||||||
|
if (bitmap & 1) {
|
||||||
|
struct GBAObj* sprite = &renderer->d.oam->obj[i];
|
||||||
|
if (sprite->transformed) {
|
||||||
|
_preprocessTransformedSprite(renderer, &renderer->d.oam->tobj[i], y);
|
||||||
|
} else {
|
||||||
|
_preprocessSprite(renderer, sprite, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bitmap >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,8 @@ struct GBAVideoSoftwareRenderer {
|
||||||
int start;
|
int start;
|
||||||
int end;
|
int end;
|
||||||
|
|
||||||
|
uint32_t enabledBitmap[4];
|
||||||
|
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
pthread_cond_t upCond;
|
pthread_cond_t upCond;
|
||||||
pthread_cond_t downCond;
|
pthread_cond_t downCond;
|
||||||
|
|
Loading…
Reference in New Issue