Commit 18e83c57 authored by Jack's avatar Jack
Browse files

added palt, enhanced band, added bnot, added stat(7) for framerate,...

added palt, enhanced band, added bnot, added stat(7) for framerate, implemented transparency maangement for palette (still to be tested)
parent 36b97117
......@@ -97,14 +97,15 @@ void GameView::render()
code.initFromSource(str.c_str());*/
machine.code().loadAPI();
retro8::io::LoaderP8 loader;
std::string path = !_path.empty() ? _path : "test.p8";
std::string path = !_path.empty() ? _path : "pico-man.p8";
loader.load(path, machine);
manager->setFrameRate(machine.code().require60fps() ? 60 : 30);
machine.code().loadAPI();
if (machine.code().hasInit())
machine.code().init();
......
......@@ -120,19 +120,30 @@ namespace retro8
class palette_t
{
std::array<color_t, COLOR_COUNT> colors;
std::array<uint8_t, COLOR_COUNT> colors;
public:
void reset()
{
for (size_t i = 0; i < COLOR_COUNT; ++i)
colors[i] = (color_t)i;
colors[i] = i;
transparent(color_t::BLACK, true);
}
void resetTransparency()
{
transparent(color_t::BLACK, true);
for (size_t i = 1; i < COLOR_COUNT; ++i)
transparent(color_t(i), false);
}
//TODO: %16 to make it wrap around, is it intended behavior? mandel.
color_t get(color_t i) const { return (color_t)(colors[i%COLOR_COUNT] % COLOR_COUNT); }
color_t set(color_t i, color_t color) { return colors[i] = color; }
color_t operator[](color_t i) { return (color_t)(colors[i%COLOR_COUNT] % COLOR_COUNT); }
color_t get(color_t i) const { return color_t(colors[i] & 0x0F); }
void set(color_t i, color_t color) { colors[i] |= color | (colors[i] & 0x10); }
color_t operator[](color_t i) { return get(i); }
bool transparent(color_t i) const { return (colors[i] & 0x10) != 0; }
void transparent(color_t i, bool f) { colors[i] = f ? (colors[i] | 0x10) : (colors[i] & 0x0f); }
};
struct clip_rect_t
......
......@@ -170,6 +170,24 @@ int pal(lua_State* L)
return 0;
}
int palt(lua_State* L)
{
/* no arguments, reset palette */
if (lua_gettop(L) == 0)
{
machine.memory().paletteAt(gfx::DRAW_PALETTE_INDEX)->resetTransparency();
}
else
{
color_t c = color_t(int(lua_tonumber(L, 1)));
int f = lua_toboolean(L, 2);
palette_index_t index = gfx::DRAW_PALETTE_INDEX;
machine.memory().paletteAt(gfx::DRAW_PALETTE_INDEX)->transparent(c, f);
}
return 0;
}
namespace draw
{
int clip(lua_State* L)
......@@ -512,13 +530,26 @@ namespace bitwise
assert(lua_isnumber(L, 1));
assert(lua_isnumber(L, 2));
uint64_t a = lua_tonumber(L, 1);
uint64_t b = lua_tonumber(L, 2);
data_t a = lua_tonumber(L, 1);
data_t b = lua_tonumber(L, 2);
lua_pushnumber(L, F()(a,b));
return 1;
}
inline int band(lua_State* L) { return bitwise<std::bit_and<data_t>>(L); }
int bnot(lua_State* L)
{
assert(lua_isnumber(L, 1));
data_t a = lua_tonumber(L, 1);
lua_pushnumber(L, std::bit_not<data_t>()(a));
return 1;
}
}
namespace sound
......@@ -583,7 +614,17 @@ namespace platform
int stat(lua_State* L)
{
//TODO: implement
lua_pushinteger(L, 0);
enum class Stat { FRAME_RATE = 7 };
Stat s = static_cast<Stat>((int)lua_tonumber(L, -1));
switch (s)
{
case Stat::FRAME_RATE: lua_pushnumber(L, machine.code().require60fps() ? 60 : 30); break;
default: lua_pushnumber(L, 0);
}
return 1;
}
......@@ -601,6 +642,7 @@ void lua::registerFunctions(lua_State* L)
lua_register(L, "pset", pset);
lua_register(L, "pget", pget);
lua_register(L, "pal", pal);
lua_register(L, "palt", palt);
lua_register(L, "color", color);
lua_register(L, "line", line);
lua_register(L, "rect", rect);
......@@ -636,7 +678,8 @@ void lua::registerFunctions(lua_State* L)
lua_register(L, "sgn", math::sgn);
lua_register(L, "sqrt", math::sqrt);
lua_register(L, "band", bitwise::bitwise<std::bit_and<uint64_t>>);
lua_register(L, "band", bitwise::band);
lua_register(L, "bnot", bitwise::bnot);
lua_register(L, "music", sound::music);
......@@ -661,8 +704,6 @@ void Code::loadAPI()
L = luaL_newstate();
}
return;
std::ifstream apiFile("api.lua");
std::string api((std::istreambuf_iterator<char>(apiFile)), std::istreambuf_iterator<char>());
......
......@@ -170,12 +170,13 @@ void Machine::circfill(coord_t xc, coord_t yc, amount_t r, color_t color)
void Machine::spr(index_t idx, coord_t x, coord_t y)
{
const gfx::sprite_t* sprite = _memory.spriteAt(idx);
const gfx::palette_t* palette = _memory.paletteAt(gfx::DRAW_PALETTE_INDEX);
for (coord_t ty = 0; ty < gfx::SPRITE_HEIGHT; ++ty)
for (coord_t tx = 0; tx < gfx::SPRITE_WIDTH; ++tx)
{
color_t color = sprite->get(tx, ty);
if (color != 0) //TODO: manage real transparency through flags
if (!palette->transparent(color)) //TODO: manage real transparency through flags
pset(x + tx, y + ty, sprite->get(tx, ty));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment