From 8415841c5cd65c0f280e0576cb1a3783d31d6b56 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 5 Oct 2022 17:47:58 +0200 Subject: [PATCH] -setpal & getpal renamed to setcolor & getcolor -setcolor & getcolor now use r, g & b instead of uint32 --- lua.cpp | 22 ++++++++++++++-------- mini.cpp | 4 ++-- mini.h | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lua.cpp b/lua.cpp index db6d6b1..45d3aa0 100644 --- a/lua.cpp +++ b/lua.cpp @@ -57,16 +57,22 @@ extern "C" { loadpal(str); return 0; } - static int cpp_setpal(lua_State *L) { + static int cpp_setcolor(lua_State *L) { uint8_t index = luaL_checkinteger(L, 1); - uint8_t color = luaL_checkinteger(L, 2); - setpal(index, color); + uint8_t r = luaL_checkinteger(L, 2); + uint8_t g = luaL_checkinteger(L, 3); + uint8_t b = luaL_checkinteger(L, 4); + uint32_t color = (r<<16) + (g<<8) + b; + setcolor(index, color); return 0; } - static int cpp_getpal(lua_State *L) { + static int cpp_getcolor(lua_State *L) { uint8_t index = luaL_checkinteger(L, 1); - lua_pushinteger(L, getpal(index)); - return 1; + uint32_t color = getcolor(index); + lua_pushinteger(L, (color>>16)&0xff); + lua_pushinteger(L, (color>>8)&0xff); + lua_pushinteger(L, color&0xff); + return 3; } static int cpp_settrans(lua_State *L) { uint8_t index = luaL_checkinteger(L, 1); @@ -613,8 +619,8 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_color); lua_setglobal(L, "color"); lua_pushcfunction(L,cpp_loadpal); lua_setglobal(L, "loadpal"); - lua_pushcfunction(L,cpp_setpal); lua_setglobal(L, "setpal"); - lua_pushcfunction(L,cpp_getpal); lua_setglobal(L, "getpal"); + lua_pushcfunction(L,cpp_setcolor); lua_setglobal(L, "setcolor"); + lua_pushcfunction(L,cpp_getcolor); lua_setglobal(L, "getcolor"); lua_pushcfunction(L,cpp_settrans); lua_setglobal(L, "settrans"); lua_pushcfunction(L,cpp_gettrans); lua_setglobal(L, "gettrans"); diff --git a/mini.cpp b/mini.cpp index 41e176b..c83c8aa 100644 --- a/mini.cpp +++ b/mini.cpp @@ -308,11 +308,11 @@ void loadpal(const char* filename) { } } -void setpal(uint8_t index, uint32_t color) { +void setcolor(uint8_t index, uint32_t color) { palette[index] = color; } -uint32_t getpal(uint8_t index) { +uint32_t getcolor(uint8_t index) { return palette[index]; } diff --git a/mini.h b/mini.h index 3b47e99..9c11bbe 100644 --- a/mini.h +++ b/mini.h @@ -123,8 +123,8 @@ void cls(uint8_t color=0); void color(uint8_t color=6); void loadpal(const char* filename); -void setpal(uint8_t index, uint32_t color); -uint32_t getpal(uint8_t index); +void setcolor(uint8_t index, uint32_t color); +uint32_t getcolor(uint8_t index); void settrans(uint8_t index); uint8_t gettrans();