commit 43fd35a79a9159b2fa6cea462a7ef7171c1a4762
Author: Jon Bell <jondbell@protonmail.com>
AuthorDate: Fri Apr 24 16:36:08 2020 -0600
Commit: Jon Bell <jondbell@protonmail.com>
CommitDate: Fri Apr 24 16:36:08 2020 -0600
Add palt() (transparency mapping) support
---
source/Readme.md | 5 +++--
source/console.cpp | 1 +
source/graphics.cpp | 20 ++++++++++++++++----
source/graphics.h | 3 +++
source/picoluaapi.cpp | 15 +++++++++++++++
source/picoluaapi.h | 1 +
6 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/source/Readme.md b/source/Readme.md
index 07941be..af137c3 100644
--- a/source/Readme.md
+++ b/source/Readme.md
@@ -14,8 +14,9 @@ Basic Roadmap:
(x) Add camera() support
(x) Add clip() support
(x) Add map(), mget(), mset() support
-( ) Add pal() support
-( ) Add palt() support
+(x) Add pal() support
+(x) Add palt() support
+( ) add flip support to sprite drawing
Add support for other non-lua pico functions
diff --git a/source/console.cpp b/source/console.cpp
index fd5ef63..b7fb479 100644
--- a/source/console.cpp
+++ b/source/console.cpp
@@ -80,6 +80,7 @@ void Console::LoadCart(std::string filename){
lua_register(_luaState, "clip", clip);
lua_register(_luaState, "pal", pal);
+ lua_register(_luaState, "palt", palt);
lua_register(_luaState, "mget", mget);
lua_register(_luaState, "mset", mset);
diff --git a/source/graphics.cpp b/source/graphics.cpp
index a24bf8c..264f059 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -93,7 +93,7 @@ void Graphics::copySpriteToScreen(
? bothPix & 0x0f //just first 4 bits
: bothPix >> 4; //just last 4 bits
- if (c != 0) { //if not transparent. Come back later to add palt() support by checking tranparency palette
+ if (_gfxState_transparencyPalette[c] == false) { //if not transparent. Come back later to add palt() support by checking tranparency palette
_private_pset(scr_x + x, scr_y + y, c); //set color on framebuffer. Come back later and add pal() by translating color
}
}
@@ -147,7 +147,7 @@ void Graphics::copyStretchSpriteToScreen(
uint8_t c = (pixIndex >> 16) % 2 == 0
? bothPix & 0x0f //just first 4 bits
: bothPix >> 4; //just last 4 bits
- if (c != 0) {
+ if (_gfxState_transparencyPalette[c] == false) {
_private_pset(scr_x + x, scr_y + y, c);
}
}
@@ -160,7 +160,7 @@ void Graphics::copyStretchSpriteToScreen(
uint8_t c = (pixIndex >> 16) % 2 == 0
? bothPix & 0x0f //just first 4 bits
: bothPix >> 4; //just last 4 bits
- if (c != 0) {
+ if (_gfxState_transparencyPalette[c] == false) {
_private_pset(scr_x + x, scr_y + y, c);
}
}
@@ -595,9 +595,9 @@ void Graphics::pal() {
for (uint8_t c = 0; c < 16; c++) {
_gfxState_drawPaletteMap[c] = c;
_gfxState_screenPaletteMap[c] = c;
- //todo: also clear transparency palette here once implemented
}
+ this->palt();
}
void Graphics::pal(uint8_t c0, uint8_t c1, uint8_t p){
@@ -610,6 +610,18 @@ void Graphics::pal(uint8_t c0, uint8_t c1, uint8_t p){
}
}
+void Graphics::palt() {
+ for (uint8_t c = 0; c < 16; c++) {
+ _gfxState_transparencyPalette[c] = c == 0 ? true : false;
+ }
+}
+
+void Graphics::palt(uint8_t c, bool t){
+ if (c < 16) {
+ _gfxState_transparencyPalette[c] = t;
+ }
+}
+
void Graphics::flipBuffer(uint8_t* fb) {
short x, y;
for(x = 0; x < 400; x++) {
diff --git a/source/graphics.h b/source/graphics.h
index 4bbdea2..746c152 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -53,6 +53,7 @@ class Graphics {
uint8_t _gfxState_drawPaletteMap[16];
uint8_t _gfxState_screenPaletteMap[16];
+ bool _gfxState_transparencyPalette[16];
//not actually part of graphics state memory?
short _gfxState_line_x;
@@ -178,6 +179,8 @@ class Graphics {
void pal();
void pal(uint8_t c0, uint8_t c1, uint8_t p);
+ void palt();
+ void palt(uint8_t c0, bool t);
void flipBuffer(uint8_t* fb);
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index c5161e2..0327e07 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -456,6 +456,21 @@ int pal(lua_State *L) {
return 0;
}
+int palt(lua_State *L) {
+ if (lua_gettop(L) == 0) {
+ _graphicsForLuaApi->palt();
+
+ return 0;
+ }
+
+ uint8_t c = lua_tonumber(L,1);
+ bool t = lua_toboolean(L,2);
+
+ _graphicsForLuaApi->palt(c, t);
+
+ return 0;
+}
+
//Input
//input api
diff --git a/source/picoluaapi.h b/source/picoluaapi.h
index 0443a38..f4fc0ae 100644
--- a/source/picoluaapi.h
+++ b/source/picoluaapi.h
@@ -37,6 +37,7 @@ int mget(lua_State *L);
int mset(lua_State *L);
int map(lua_State *L);
int pal(lua_State *L);
+int palt(lua_State *L);
//input api
int btn(lua_State *L);