diff --git a/.gitignore b/.gitignore index b7a1994..ced825c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ mini.exe mini -vscode/* +.vscode/* diff --git a/game.ini b/game.ini new file mode 100644 index 0000000..f25da58 --- /dev/null +++ b/game.ini @@ -0,0 +1,4 @@ +title=AEE: El Laberinto de Akhenotep +width=160 +height=120 +zoom=4 diff --git a/lua.cpp b/lua.cpp index 007236f..68b192f 100644 --- a/lua.cpp +++ b/lua.cpp @@ -23,7 +23,7 @@ extern "C" { } uint8_t c0 = luaL_checkinteger(L, 1); uint8_t c1 = luaL_checkinteger(L, 2); - uint8_t p = luaL_optinteger(L, 1, 0); + uint8_t p = luaL_optinteger(L, 3, 0); pal(c0, c1, p); return 0; } @@ -41,8 +41,8 @@ extern "C" { } static int cpp_pset(lua_State *L) { - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); if (lua_gettop(L) > 2) { uint8_t color = luaL_checkinteger(L, 3); pset(x, y, color); @@ -53,17 +53,17 @@ extern "C" { } static int cpp_pget(lua_State *L) { - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); lua_pushinteger(L, pget(x, y)); return 1; } static int cpp_line(lua_State *L) { - int x0 = luaL_checkinteger(L, 1); - int y0 = luaL_checkinteger(L, 2); - int x1 = luaL_checkinteger(L, 3); - int y1 = luaL_checkinteger(L, 4); + int x0 = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); + int y1 = luaL_checknumber(L, 4); if (lua_gettop(L) > 4) { uint8_t color = luaL_checkinteger(L, 5); line(x0, y0, x1, y1, color); @@ -74,9 +74,9 @@ extern "C" { } static int cpp_hline(lua_State *L) { - int x0 = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - int x1 = luaL_checkinteger(L, 3); + int x0 = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); if (lua_gettop(L) > 3) { uint8_t color = luaL_checkinteger(L, 4); hline(x0, y, x1, color); @@ -87,9 +87,9 @@ extern "C" { } static int cpp_vline(lua_State *L) { - int x = luaL_checkinteger(L, 1); - int y0 = luaL_checkinteger(L, 2); - int y1 = luaL_checkinteger(L, 3); + int x = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int y1 = luaL_checknumber(L, 3); if (lua_gettop(L) > 3) { uint8_t color = luaL_checkinteger(L, 4); vline(x, y0, y1, color); @@ -100,10 +100,10 @@ extern "C" { } static int cpp_rect(lua_State *L) { - int x0 = luaL_checkinteger(L, 1); - int y0 = luaL_checkinteger(L, 2); - int x1 = luaL_checkinteger(L, 3); - int y1 = luaL_checkinteger(L, 4); + int x0 = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); + int y1 = luaL_checknumber(L, 4); if (lua_gettop(L) > 4) { uint8_t color = luaL_checkinteger(L, 5); rect(x0, y0, x1, y1, color); @@ -114,10 +114,10 @@ extern "C" { } static int cpp_rectfill(lua_State *L) { - int x0 = luaL_checkinteger(L, 1); - int y0 = luaL_checkinteger(L, 2); - int x1 = luaL_checkinteger(L, 3); - int y1 = luaL_checkinteger(L, 4); + int x0 = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); + int y1 = luaL_checknumber(L, 4); if (lua_gettop(L) > 4) { uint8_t color = luaL_checkinteger(L, 5); rectfill(x0, y0, x1, y1, color); @@ -136,8 +136,8 @@ extern "C" { static int cpp_print(lua_State *L) { const char* str = luaL_checkstring(L, 1); - int x = luaL_checkinteger(L, 2); - int y = luaL_checkinteger(L, 3); + int x = luaL_checknumber(L, 2); + int y = luaL_checknumber(L, 3); if (lua_gettop(L) > 3) { uint8_t color = luaL_checkinteger(L, 4); print(str, x, y, color); @@ -148,10 +148,10 @@ extern "C" { } static int cpp_clip(lua_State *L) { - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - int w = luaL_checkinteger(L, 3); - int h = luaL_checkinteger(L, 4); + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int w = luaL_checknumber(L, 3); + int h = luaL_checknumber(L, 4); clip(x, y, w, h); return 0; } @@ -164,9 +164,9 @@ extern "C" { } static int cpp_circ(lua_State *L) { - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - int r = luaL_optinteger(L, 3, 4); + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int r = luaL_optnumber(L, 3, 4); if (lua_gettop(L) > 3) { uint8_t color = luaL_checkinteger(L, 4); circ(x, y, r, color); @@ -177,9 +177,9 @@ extern "C" { } static int cpp_circfill(lua_State *L) { - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - int r = luaL_optinteger(L, 3, 4); + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int r = luaL_optnumber(L, 3, 4); if (lua_gettop(L) > 3) { uint8_t color = luaL_checkinteger(L, 4); circfill(x, y, r, color); @@ -190,10 +190,10 @@ extern "C" { } static int cpp_oval(lua_State *L) { - int x0 = luaL_checkinteger(L, 1); - int y0 = luaL_checkinteger(L, 2); - int x1 = luaL_checkinteger(L, 3); - int y1 = luaL_checkinteger(L, 4); + int x0 = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); + int y1 = luaL_checknumber(L, 4); if (lua_gettop(L) > 4) { uint8_t color = luaL_checkinteger(L, 5); oval(x0, y0, x1, y1, color); @@ -204,10 +204,10 @@ extern "C" { } static int cpp_ovalfill(lua_State *L) { - int x0 = luaL_checkinteger(L, 1); - int y0 = luaL_checkinteger(L, 2); - int x1 = luaL_checkinteger(L, 3); - int y1 = luaL_checkinteger(L, 4); + int x0 = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); + int y1 = luaL_checknumber(L, 4); if (lua_gettop(L) > 4) { uint8_t color = luaL_checkinteger(L, 5); ovalfill(x0, y0, x1, y1, color); @@ -218,8 +218,8 @@ extern "C" { } static int cpp_sset(lua_State *L) { - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); if (lua_gettop(L) > 2) { uint8_t color = luaL_checkinteger(L, 3); sset(x, y, color); @@ -230,16 +230,16 @@ extern "C" { } static int cpp_sget(lua_State *L) { - int x = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); lua_pushinteger(L, sget(x, y)); return 1; } static int cpp_spr(lua_State *L) { uint8_t n = luaL_checkinteger(L, 1); - int x = luaL_checkinteger(L, 2); - int y = luaL_checkinteger(L, 3); + int x = luaL_checknumber(L, 2); + int y = luaL_checknumber(L, 3); float w = luaL_optnumber(L, 4, 1.0f); float h = luaL_optnumber(L, 5, 1.0f); bool flip_x = lua_toboolean(L, 6); @@ -249,14 +249,14 @@ extern "C" { } static int cpp_sspr(lua_State *L) { - int sx = luaL_checkinteger(L, 1); - int sy = luaL_checkinteger(L, 2); - int sw = luaL_checkinteger(L, 3); - int sh = luaL_checkinteger(L, 4); - int dx = luaL_checkinteger(L, 5); - int dy = luaL_checkinteger(L, 6); - int dw = luaL_optinteger(L, 7, 0); - int dh = luaL_optinteger(L, 8, 0); + int sx = luaL_checknumber(L, 1); + int sy = luaL_checknumber(L, 2); + int sw = luaL_checknumber(L, 3); + int sh = luaL_checknumber(L, 4); + int dx = luaL_checknumber(L, 5); + int dy = luaL_checknumber(L, 6); + int dw = luaL_optnumber(L, 7, 0); + int dh = luaL_optnumber(L, 8, 0); bool flip_x = lua_toboolean(L, 9); bool flip_y = lua_toboolean(L, 10); sspr(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y); @@ -264,10 +264,10 @@ extern "C" { } static int cpp_tline(lua_State *L) { - int x0 = luaL_checkinteger(L, 1); - int y0 = luaL_checkinteger(L, 2); - int x1 = luaL_checkinteger(L, 3); - int y1 = luaL_checkinteger(L, 4); + int x0 = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); + int y1 = luaL_checknumber(L, 4); float mx = luaL_checknumber(L, 5); float my = luaL_checknumber(L, 6); float mdx = luaL_optnumber(L, 7, 0.125f); @@ -277,9 +277,9 @@ extern "C" { } static int cpp_thline(lua_State *L) { - int x0 = luaL_checkinteger(L, 1); - int y = luaL_checkinteger(L, 2); - int x1 = luaL_checkinteger(L, 3); + int x0 = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int x1 = luaL_checknumber(L, 3); float mx = luaL_checknumber(L, 4); float my = luaL_checknumber(L, 5); float mdx = luaL_optnumber(L, 6, 0.125f); @@ -289,9 +289,9 @@ extern "C" { } static int cpp_tvline(lua_State *L) { - int x = luaL_checkinteger(L, 1); - int y0 = luaL_checkinteger(L, 2); - int y1 = luaL_checkinteger(L, 3); + int x = luaL_checknumber(L, 1); + int y0 = luaL_checknumber(L, 2); + int y1 = luaL_checknumber(L, 3); float mx = luaL_checknumber(L, 4); float my = luaL_checknumber(L, 5); float mdx = luaL_optnumber(L, 6, 0.0f); @@ -301,27 +301,27 @@ extern "C" { } static int cpp_mset(lua_State *L) { - int celx = luaL_checkinteger(L, 1); - int cely = luaL_checkinteger(L, 2); + int celx = luaL_checknumber(L, 1); + int cely = luaL_checknumber(L, 2); uint8_t snum = luaL_checkinteger(L, 3); mset(celx, cely, snum); return 0; } static int cpp_mget(lua_State *L) { - int celx = luaL_checkinteger(L, 1); - int cely = luaL_checkinteger(L, 2); + int celx = luaL_checknumber(L, 1); + int cely = luaL_checknumber(L, 2); lua_pushinteger(L, mget(celx, cely)); return 1; } static int cpp_map(lua_State *L) { - uint8_t celx = luaL_checkinteger(L, 1); - uint8_t cely = luaL_checkinteger(L, 2); - int sx = luaL_checkinteger(L, 3); - int sy = luaL_checkinteger(L, 4); - uint8_t celw = luaL_checkinteger(L, 5); - uint8_t celh = luaL_checkinteger(L, 6); + uint8_t celx = luaL_checknumber(L, 1); + uint8_t cely = luaL_checknumber(L, 2); + int sx = luaL_checknumber(L, 3); + int sy = luaL_checknumber(L, 4); + uint8_t celw = luaL_checknumber(L, 5); + uint8_t celh = luaL_checknumber(L, 6); uint8_t layer = luaL_optinteger(L, 7, 0); map(celx, cely, sx, sy, celw, celh, layer); return 0; @@ -339,6 +339,27 @@ extern "C" { return 1; } + static int cpp_mouseX(lua_State *L) { + lua_pushinteger(L, mouseX()); + return 1; + } + + static int cpp_mouseY(lua_State *L) { + lua_pushinteger(L, mouseY()); + return 1; + } + + static int cpp_mouseWheel(lua_State *L) { + lua_pushinteger(L, mouseWheel()); + return 1; + } + + static int cpp_mouseButton(lua_State *L) { + uint8_t i = luaL_checkinteger(L, 1); + lua_pushboolean(L, mouseButton(i)); + return 1; + } + static int cpp_time(lua_State *L) { lua_pushnumber(L, time()); return 1; @@ -414,7 +435,11 @@ extern "C" { srand(x); return 0; } - + static int cpp_tostr(lua_State *L) { + int val = luaL_checknumber(L, 1); + lua_pushstring(L, tostr(val)); + return 1; + } } lua_State *L; @@ -467,6 +492,11 @@ void lua_init() { lua_pushcfunction(L,cpp_map); lua_setglobal(L, "map"); lua_pushcfunction(L,cpp_btn); lua_setglobal(L, "btn"); lua_pushcfunction(L,cpp_btnp); lua_setglobal(L, "btnp"); + lua_pushcfunction(L,cpp_mouseX); lua_setglobal(L, "mouseX"); + lua_pushcfunction(L,cpp_mouseY); lua_setglobal(L, "mouseY"); + lua_pushcfunction(L,cpp_mouseWheel); lua_setglobal(L, "mouseWheel"); + lua_pushcfunction(L,cpp_mouseButton); lua_setglobal(L, "mouseButton"); + lua_pushcfunction(L,cpp_time); lua_setglobal(L, "time"); lua_pushcfunction(L,cpp_abs); lua_setglobal(L, "abs"); lua_pushcfunction(L,cpp_ceil); lua_setglobal(L, "ceil"); @@ -481,6 +511,7 @@ void lua_init() { lua_pushcfunction(L,cpp_min); lua_setglobal(L, "min"); lua_pushcfunction(L,cpp_rnd); lua_setglobal(L, "rnd"); lua_pushcfunction(L,cpp_srand); lua_setglobal(L, "srand"); + lua_pushcfunction(L,cpp_tostr); lua_setglobal(L, "tostr"); lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN"); lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A"); diff --git a/mini.cpp b/mini.cpp index e8efd31..0f0fb11 100644 --- a/mini.cpp +++ b/mini.cpp @@ -1,8 +1,17 @@ #include "mini.h" #include +#include #include "lua.h" +struct surface_t { + uint8_t *pointer; + uint16_t w, h; + uint32_t size_in_bytes; +}; + #define swap(a, b) {auto tmp=a;a=b;b=tmp;} + +char window_title[256]; #define SCREEN_WIDTH 160 #define SCREEN_HEIGHT 120 #define SCREEN_SIZE_BYTES SCREEN_WIDTH*SCREEN_HEIGHT @@ -43,11 +52,15 @@ uint8_t tiles[TILES_SIZE_BYTES]; uint32_t palette[16] = { 0x1a1c2c00, 0x5d275d00, 0xb13e5300, 0xef7d5700, 0xffcd7500, 0xa7f07000, 0x38b76400, 0x25717900, 0x29366f00, 0x3b5dc900, 0x41a6f600, 0x73eff700, 0xf4f4f400, 0x94b0c200, 0x566c8600, 0x333c5700 }; +const char base64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + char base64font[241] = "00@B@]0X__OnZDYK[G10:9BTDEG5j20@1h000RB:_]OBjW?odl]Wlil9_oTT__omT@@02:DA477ADid@Z=nm]_[g9a[]oIi?;a9m]_mBjGB[M]99o_][]e]M" "_?A]c_[eiLGBZ]e]mZ]o]Z]mlW:O9IABdTdZ000hR00__H[7?iH]3Oih;1?mXm5GjhB3M]897o]H]5^Mhm1ZchM5>LhB2]eXm2]oXZ5mlh