From 80f98802b6d5a1da03040e2f3423f2345993aa7f Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 28 Jul 2020 19:09:24 -0500 Subject: [PATCH] [nostalgia/core/gba] Add hideSprite and add flipX parameter to setSrpite --- src/nostalgia/core/gba/addresses.hpp | 2 ++ src/nostalgia/core/gba/gfx.cpp | 23 ++++++++++++++++++++++- src/nostalgia/core/gfx.hpp | 4 ++-- src/nostalgia/core/sdl/gfx.cpp | 7 +++++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/nostalgia/core/gba/addresses.hpp b/src/nostalgia/core/gba/addresses.hpp index ad4b9b47..2d171cc6 100644 --- a/src/nostalgia/core/gba/addresses.hpp +++ b/src/nostalgia/core/gba/addresses.hpp @@ -76,6 +76,8 @@ using interrupt_handler = void (*)(void); #define MEM_IWRAM_BEGIN reinterpret_cast(0x03000000) #define MEM_IWRAM_END reinterpret_cast(0x03007FFF) +#define REG_BLNDCTL *reinterpret_cast(0x04000050) + #define MEM_BG_PALETTE reinterpret_cast(0x05000000) #define MEM_SPRITE_PALETTE reinterpret_cast(0x05000200) diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index 91e120b7..ef6f6bda 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -214,12 +214,33 @@ void clearTileLayer(Context*, int layer) { memset(&MEM_BG_MAP[layer], 0, GbaTileRows * GbaTileColumns); } -void setSprite(unsigned idx, unsigned x, unsigned y, unsigned tileIdx, unsigned spriteShape, unsigned spriteSize) { +void hideSprite(unsigned idx) { + GbaSpriteAttrUpdate oa; + oa.attr0 = 2 << 8; + oa.idx = idx; + // block until g_spriteUpdates is less than buffer len + if (g_spriteUpdates >= config::GbaSpriteBufferLen) { + nostalgia_core_vblankintrwait(); + } + if constexpr(config::GbaEventLoopTimerBased) { + REG_IE &= ~Int_vblank; // disable vblank interrupt handler + g_spriteBuffer[g_spriteUpdates++] = oa; + REG_IE |= Int_vblank; // enable vblank interrupt handler + } else { + auto ie = REG_IE; // disable vblank interrupt handler + REG_IE &= ~Int_vblank; // disable vblank interrupt handler + g_spriteBuffer[g_spriteUpdates++] = oa; + REG_IE = ie; // enable vblank interrupt handler + } +} + +void setSprite(unsigned idx, unsigned x, unsigned y, unsigned tileIdx, unsigned spriteShape, unsigned spriteSize, unsigned flipX) { GbaSpriteAttrUpdate oa; oa.attr0 = static_cast(y & ox::onMask(7)) | (static_cast(1) << 10) // enable alpha | (static_cast(spriteShape) << 14); oa.attr1 = (static_cast(x) & ox::onMask(8)) + | (static_cast(flipX) << 12) | (static_cast(spriteSize) << 14); oa.attr2 = static_cast(tileIdx & ox::onMask(8)); oa.idx = idx; diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index 06a38689..955a25e5 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -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, unsigned tileShape = 0, unsigned spriteSize = 0); +void setSprite(unsigned idx, unsigned x, unsigned y, unsigned tileIdx, unsigned spriteShape = 0, unsigned spriteSize = 0, unsigned flipX = 0); } diff --git a/src/nostalgia/core/sdl/gfx.cpp b/src/nostalgia/core/sdl/gfx.cpp index 057d1b87..5c49a5be 100644 --- a/src/nostalgia/core/sdl/gfx.cpp +++ b/src/nostalgia/core/sdl/gfx.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 gtalent2@gmail.com + * Copyright 2016 - 2020 gary@drinkingtea.net * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -200,7 +200,10 @@ 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, unsigned, unsigned) { +void hideSprite(unsigned) { +} + +void setSprite(unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, unsigned) { } }