From e211869c921939b9d212bd85c5dad1259d85bbae Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 26 Apr 2017 21:39:19 -0700 Subject: [PATCH] DS GX: Add toon shading --- CHANGES | 4 ++++ README.md | 1 - include/mgba/internal/ds/gx.h | 2 ++ src/ds/gx.c | 1 + src/ds/gx/software.c | 10 ++++++++++ src/ds/io.c | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 96c248b35..f74c2732a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +medusa alpha 3 (Future) +Features: + - DS GX: Toon shading + 0.6.0: (Future) Features: - GBA: Support printing debug strings from inside a game diff --git a/README.md b/README.md index 412694a8a..d440d43a9 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,6 @@ Missing features on DS are - Microphone - Graphics: - Edge marking/wireframe - - Toon shading - Highlight shading - Fog - Clear depth diff --git a/include/mgba/internal/ds/gx.h b/include/mgba/internal/ds/gx.h index fc745a2f0..a03fa14c7 100644 --- a/include/mgba/internal/ds/gx.h +++ b/include/mgba/internal/ds/gx.h @@ -148,6 +148,8 @@ struct DSGXRenderer { uint16_t* tex[4]; uint16_t* texPal[6]; + + uint16_t* toonTable; }; struct DSGXLight { diff --git a/src/ds/gx.c b/src/ds/gx.c index 618b21ee3..06da79c99 100644 --- a/src/ds/gx.c +++ b/src/ds/gx.c @@ -1307,6 +1307,7 @@ void DSGXAssociateRenderer(struct DSGX* gx, struct DSGXRenderer* renderer) { gx->renderer = renderer; memcpy(gx->renderer->tex, gx->tex, sizeof(gx->renderer->tex)); memcpy(gx->renderer->texPal, gx->texPal, sizeof(gx->renderer->texPal)); + gx->renderer->toonTable = &gx->p->memory.io9[DS9_REG_TOON_TABLE_00 >> 1]; gx->renderer->init(gx->renderer); } diff --git a/src/ds/gx/software.c b/src/ds/gx/software.c index d8d9103d5..6876358bb 100644 --- a/src/ds/gx/software.c +++ b/src/ds/gx/software.c @@ -263,6 +263,16 @@ static color_t _lookupColor(struct DSGXSoftwareRenderer* renderer, struct DSGXSo wg = (g * ta + ep->cg * (63 - ta)) >> 6; wb = (b * ta + ep->cb * (63 - ta)) >> 6; return _finishColor(wr, wg, wb, pa); + case 2: { + uint8_t tr, tg, tb; + _expandColor(renderer->d.toonTable[ep->cr >> 1], &tr, &tg, &tb); + // TODO: highlight mode + wr = ((r + 1) * (tr + 1) - 1) >> 6; + wg = ((g + 1) * (tg + 1) - 1) >> 6; + wb = ((b + 1) * (tb + 1) - 1) >> 6; + wa = ((ta + 1) * (pa + 1) - 1) >> 6; + return _finishColor(wr, wg, wb, pa); + } case 3: return _finishColor(r, g, b, pa); } diff --git a/src/ds/io.c b/src/ds/io.c index 4d74b75b7..99b7838ec 100644 --- a/src/ds/io.c +++ b/src/ds/io.c @@ -821,6 +821,38 @@ uint16_t DS9IORead(struct DS* ds, uint32_t address) { case DS9_REG_SQRT_RESULT_LO: case DS9_REG_SQRT_RESULT_HI: case DS_REG_POSTFLG: + case DS9_REG_TOON_TABLE_00: + case DS9_REG_TOON_TABLE_01: + case DS9_REG_TOON_TABLE_02: + case DS9_REG_TOON_TABLE_03: + case DS9_REG_TOON_TABLE_04: + case DS9_REG_TOON_TABLE_05: + case DS9_REG_TOON_TABLE_06: + case DS9_REG_TOON_TABLE_07: + case DS9_REG_TOON_TABLE_08: + case DS9_REG_TOON_TABLE_09: + case DS9_REG_TOON_TABLE_0A: + case DS9_REG_TOON_TABLE_0B: + case DS9_REG_TOON_TABLE_0C: + case DS9_REG_TOON_TABLE_0D: + case DS9_REG_TOON_TABLE_0E: + case DS9_REG_TOON_TABLE_0F: + case DS9_REG_TOON_TABLE_10: + case DS9_REG_TOON_TABLE_11: + case DS9_REG_TOON_TABLE_12: + case DS9_REG_TOON_TABLE_13: + case DS9_REG_TOON_TABLE_14: + case DS9_REG_TOON_TABLE_15: + case DS9_REG_TOON_TABLE_16: + case DS9_REG_TOON_TABLE_17: + case DS9_REG_TOON_TABLE_18: + case DS9_REG_TOON_TABLE_19: + case DS9_REG_TOON_TABLE_1A: + case DS9_REG_TOON_TABLE_1B: + case DS9_REG_TOON_TABLE_1C: + case DS9_REG_TOON_TABLE_1D: + case DS9_REG_TOON_TABLE_1E: + case DS9_REG_TOON_TABLE_1F: case DS9_REG_GXSTAT_LO: case DS9_REG_GXSTAT_HI: case DS9_REG_CLIPMTX_RESULT_00: