From bf2b08b26204c9d5ded14a880715d8a66a319422 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 18 Jul 2020 01:24:26 -0500 Subject: [PATCH] [nostalgia/core/gba] Add sprite shape and size options --- src/nostalgia/core/gba/gfx.cpp | 36 +++++++++++++++++++++++++--------- src/nostalgia/core/gfx.hpp | 2 +- src/nostalgia/core/sdl/gfx.cpp | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index c13b0877..e4e00b41 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -27,6 +27,24 @@ constexpr uint16_t DispStat_irq_vblank = 1 << 3; constexpr uint16_t DispStat_irq_hblank = 1 << 4; constexpr uint16_t DispStat_irq_vcount = 1 << 5; +enum DispCtl { + DispCtl_Mode0 = 0, + DispCtl_Mode1 = 1, + DispCtl_Mode2 = 2, + DispCtl_Mode3 = 3, + DispCtl_Mode4 = 4, + DispCtl_Mode5 = 5, + + DispCtl_SpriteMap1D = 1 << 6, + + DispCtl_Bg0 = 1 << 8, + DispCtl_Bg1 = 1 << 9, + DispCtl_Bg2 = 1 << 10, + DispCtl_Bg3 = 1 << 11, + + DispCtl_Obj = 1 << 12, +}; + struct GbaPaletteTarget { static constexpr auto TypeName = NostalgiaPalette::TypeName; static constexpr auto Fields = NostalgiaPalette::Fields; @@ -87,12 +105,10 @@ ox::Error modelRead(T *io, GbaTileMapTarget *t) { } ox::Error initGfx(Context*) { - /* Sprite Mode ----\ */ - /* ---\| */ - /* Background 0 -\|| */ - /* Objects -----\||| */ - /* |||| */ - REG_DISPCTL = 0x1101; + REG_DISPCTL = DispCtl_Mode0 + | DispCtl_SpriteMap1D + | DispCtl_Bg0 + | DispCtl_Obj; // tell display to trigger vblank interrupts REG_DISPSTAT |= DispStat_irq_vblank; // enable vblank interrupt @@ -216,11 +232,13 @@ void clearTileLayer(Context*, int layer) { memset(&MEM_BG_MAP[layer], 0, GbaTileRows * GbaTileColumns); } -void setSprite(unsigned idx, unsigned x, unsigned y, unsigned tileIdx) { +void setSprite(unsigned idx, unsigned x, unsigned y, unsigned tileIdx, unsigned spriteShape, unsigned spriteSize) { GbaSpriteAttrUpdate oa; oa.attr0 = static_cast(y & ox::onMask(7)) - | (static_cast(1) << 10); // enable alpha - oa.attr1 = static_cast(x) & ox::onMask(8); + | (static_cast(1) << 10) // enable alpha + | (static_cast(spriteShape) << 14); + oa.attr1 = (static_cast(x) & ox::onMask(8)) + | (static_cast(spriteSize) << 14); oa.attr2 = static_cast(tileIdx & ox::onMask(8)); oa.idx = idx; // block until g_spriteUpdates is less than buffer len diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index 6842bbf4..06a38689 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -127,6 +127,6 @@ void setTile(Context *ctx, int layer, int column, int row, uint8_t tile); void clearTileLayer(Context*, int layer); -void setSprite(unsigned idx, unsigned x, unsigned y, unsigned tileIdx); +void setSprite(unsigned idx, unsigned x, unsigned y, unsigned tileIdx, unsigned tileShape = 0, unsigned spriteSize = 0); } diff --git a/src/nostalgia/core/sdl/gfx.cpp b/src/nostalgia/core/sdl/gfx.cpp index 1cd93756..057d1b87 100644 --- a/src/nostalgia/core/sdl/gfx.cpp +++ b/src/nostalgia/core/sdl/gfx.cpp @@ -200,7 +200,7 @@ void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) { id->bgTileMaps[z][y][x] = tile; } -void setSprite(unsigned, unsigned, unsigned, unsigned) { +void setSprite(unsigned, unsigned, unsigned, unsigned, unsigned, unsigned) { } }