Commit 911c373f authored by Jack's avatar Jack
Browse files

add dummy cartdata, dget, dset and sub

parent 49ce2724
......@@ -364,7 +364,7 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
#define lua_to_or_default(L, w, i, d) lua_gettop(L) >= i ? lua_to ## w(L, i) : d
#define lua_insert(L,idx) lua_rotate(L, (idx), 1)
......
......@@ -29,6 +29,7 @@ namespace retro8
using index_t = uint32_t;
using sprite_index_t = uint8_t;
using sprite_flags_t = uint8_t;
using integral_t = int32_t;
using color_index_t = uint8_t;
using palette_index_t = size_t;
using address_t = int32_t;
......
......@@ -428,9 +428,7 @@ namespace math
int rnd(lua_State* L)
{
assert(lua_isnumber(L, 1));
real_t max = lua_tonumber(L, 1);
real_t max = lua_gettop(L) >= 1 ? lua_tonumber(L, 1) : 1.0f;
lua_pushnumber(L, (machine.state().rnd() / (float)machine.state().rnd.max()) * max);
return 1;
......@@ -592,6 +590,26 @@ namespace sound
}
}
namespace string
{
int sub(lua_State* L)
{
const std::string v = lua_tostring(L, 1);
size_t s = lua_tonumber(L, 2);
size_t e = lua_to_or_default(L, number, 3, -1);
if (s < 0)
s = v.length() - s + 1;
if (e < 0)
e = v.length() - e + 1;
assert(s <= e);
lua_pushstring(L, v.substr(s, e - s + 1).c_str());
return 1;
}
}
namespace platform
{
int btn(lua_State* L)
......@@ -654,6 +672,30 @@ namespace platform
return 1;
}
int cartdata(lua_State* L)
{
//TODO: implement
return 0;
}
int dset(lua_State* L)
{
index_t idx = lua_tonumber(L, 1);
integral_t value = lua_tonumber(L, 2);
*machine.memory().cartData(idx) = value;
return 0;
}
int dget(lua_State* L)
{
index_t idx = lua_tonumber(L, 1);
lua_pushnumber(L, *machine.memory().cartData(idx));
return 1;
}
int flip(lua_State* L)
{
machine.flip();
......@@ -714,10 +756,16 @@ void lua::registerFunctions(lua_State* L)
lua_register(L, "music", ::sound::music);
lua_register(L, "sfx", ::sound::music);
lua_register(L, "sub", string::sub);
lua_register(L, "btn", platform::btn);
lua_register(L, "btnp", platform::btnp);
lua_register(L, "flip", platform::flip);
lua_register(L, "stat", platform::stat);
lua_register(L, "cartdata", platform::cartdata);
lua_register(L, "dset", platform::dset);
lua_register(L, "dget", platform::dget);
lua_register(L, "flip", platform::flip);
}
Code::~Code()
......
......@@ -26,6 +26,7 @@ namespace retro8
static constexpr address_t SPRITE_SHEET = 0x0000;
static constexpr address_t SPRITE_FLAGS = 0x3000;
static constexpr address_t CART_DATA = 0x5e00;
static constexpr address_t PALETTES = 0x5f00;
static constexpr address_t CLIP_RECT = 0x5f20;
static constexpr address_t PEN_COLOR = 0x5f25;
......@@ -72,6 +73,7 @@ namespace retro8
gfx::color_byte_t* screenData() { return reinterpret_cast<gfx::color_byte_t*>(&memory[address::SCREEN_DATA]); }
gfx::color_byte_t* screenData(coord_t x, coord_t y) { return screenData() + (y * BYTES_PER_SCREEN_ROW + x) / 2; }
integral_t* cartData(index_t idx) { return as<integral_t>(address::CART_DATA + idx * sizeof(integral_t)); } //TODO: ENDIANNESS!!
sprite_flags_t* spriteFlagsFor(sprite_index_t index)
{
......
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