From 9b5bda237a75d6d82fafe5a8406811bd6b017b9d Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 3 Mar 2017 18:37:48 -0800 Subject: [PATCH] DS GX: Add color modulation --- include/mgba/internal/ds/gx.h | 10 ++++++++++ include/mgba/internal/ds/gx/software.h | 1 + src/ds/gx/software.c | 14 +++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/mgba/internal/ds/gx.h b/include/mgba/internal/ds/gx.h index 97c55b594..03957be60 100644 --- a/include/mgba/internal/ds/gx.h +++ b/include/mgba/internal/ds/gx.h @@ -47,6 +47,16 @@ DECL_BITS(DSGXTexParams, Format, 26, 3); DECL_BIT(DSGXTexParams, 0Transparent, 29); DECL_BITS(DSGXTexParams, CoordTfMode, 30, 2); +DECL_BITFIELD(DSGXPolygonAttrs, uint32_t); +DECL_BIT(DSGXPolygonAttrs, Light0, 0); +DECL_BIT(DSGXPolygonAttrs, Light1, 1); +DECL_BIT(DSGXPolygonAttrs, Light2, 2); +DECL_BIT(DSGXPolygonAttrs, Light3, 3); +DECL_BITS(DSGXPolygonAttrs, Mode, 4, 2); +DECL_BIT(DSGXPolygonAttrs, FrontFace, 6); +DECL_BIT(DSGXPolygonAttrs, BackFace, 7); +// TODO + enum DSGXCommand { DS_GX_CMD_NOP = 0, DS_GX_CMD_MTX_MODE = 0x10, diff --git a/include/mgba/internal/ds/gx/software.h b/include/mgba/internal/ds/gx/software.h index 3cbfd014e..928910ae0 100644 --- a/include/mgba/internal/ds/gx/software.h +++ b/include/mgba/internal/ds/gx/software.h @@ -20,6 +20,7 @@ struct DSGXSoftwarePolygon { uint16_t* texBase; uint16_t* palBase; int texFormat; + int blendFormat; int texW; int texH; }; diff --git a/src/ds/gx/software.c b/src/ds/gx/software.c index 0887f087b..634e9ca79 100644 --- a/src/ds/gx/software.c +++ b/src/ds/gx/software.c @@ -109,9 +109,20 @@ static color_t _lookupColor(struct DSGXSoftwareEndpoint* ep, struct DSGXSoftware return FLAG_UNWRITTEN; } uint8_t r, g, b; + unsigned wr, wg, wb; texel = poly->palBase[texel]; _expandColor(texel, &r, &g, &b); - return _finishColor(r, g, b); + switch (poly->blendFormat) { + case 1: + default: + // TODO: Alpha + return _finishColor(r, g, b); + case 0: + wr = ((r + 1) * (ep->cr + 1) - 1) >> 6; + wg = ((g + 1) * (ep->cg + 1) - 1) >> 6; + wb = ((b + 1) * (ep->cb + 1) - 1) >> 6; + return _finishColor(wr, wg, wb); + } } static int _edgeSort(const void* a, const void* b) { @@ -285,6 +296,7 @@ static void DSGXSoftwareRendererSetRAM(struct DSGXRenderer* renderer, struct DSG struct DSGXSoftwareEdge* edge = DSGXSoftwareEdgeListAppend(&softwareRenderer->activeEdges); poly->poly = &polys[i]; poly->texFormat = DSGXTexParamsGetFormat(poly->poly->texParams); + poly->blendFormat = DSGXPolygonAttrsGetMode(poly->poly->polyParams); poly->texW = 8 << DSGXTexParamsGetSSize(poly->poly->texParams); poly->texH = 8 << DSGXTexParamsGetTSize(poly->poly->texParams); switch (poly->texFormat) {