From 841f4f66f304e334c224a6aa172e2ae6a1d2efcf Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Mon, 20 Dec 2021 18:15:39 +0100 Subject: [PATCH] [FEAT] cnt() i rst() --- ascii.cpp | 12 +++++++++++- ascii.h | 5 ++++- lua.cpp | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ascii.cpp b/ascii.cpp index 6abb0b9..324073f 100644 --- a/ascii.cpp +++ b/ascii.cpp @@ -42,6 +42,7 @@ SDL_Texture *mini_bak = NULL; SDL_AudioDeviceID mini_audio_device; Uint32 *pixels; int pitch; +Uint32 counter=0; uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0000, 0x00AA00AA, 0x00AA5500, 0x00AAAAAA, 0x00555555, 0x005555FF, 0x0055FF55, 0x0055FFFF, 0x00FF5555, 0x00FF55FF, 0x00FFFF55, 0x00FFFFFF }; @@ -63,6 +64,7 @@ const char* get_filename() { void reinit() { if (mini_bak != NULL) SDL_DestroyTexture(mini_bak); + counter=0; switch (current_mode) { case 0: screen_width = 80; @@ -305,6 +307,7 @@ int main(int argc,char*argv[]) { SDL_RenderCopy(mini_ren, mini_bak, NULL, &rect); //SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL); SDL_RenderPresent(mini_ren); + counter++; } lua_quit(); SDL_Quit(); @@ -672,4 +675,11 @@ const char* fromclipboard() { SDL_free((void*)text); return str_tmp; -} \ No newline at end of file +} + +uint32_t cnt() { + return counter; +} +void rst() { + counter = 0; +} diff --git a/ascii.h b/ascii.h index e8fe2a9..d1a055d 100644 --- a/ascii.h +++ b/ascii.h @@ -204,4 +204,7 @@ void fileout(const char* str, uint16_t addr, uint16_t size); void filein(const char* str, uint16_t addr, uint16_t size); void toclipboard(const char* str); -const char* fromclipboard(); \ No newline at end of file +const char* fromclipboard(); + +uint32_t cnt(); +void rst(); diff --git a/lua.cpp b/lua.cpp index d2e5f00..7c053f9 100644 --- a/lua.cpp +++ b/lua.cpp @@ -392,6 +392,16 @@ extern "C" { lua_pushstring(L, fromclipboard()); return 1; } + + static int cpp_cnt(lua_State *L) { + lua_pushinteger(L, cnt()); + return 1; + } + + static int cpp_rst(lua_State *L) { + rst(); + return 0; + } } #define STATE_STOPPED 0 @@ -485,6 +495,9 @@ void lua_init(const char* filename, const bool start_playing) { lua_pushcfunction(L,cpp_toclipboard); lua_setglobal(L, "toclipboard"); lua_pushcfunction(L,cpp_fromclipboard); lua_setglobal(L, "fromclipboard"); + lua_pushcfunction(L,cpp_cnt); lua_setglobal(L, "cnt"); + lua_pushcfunction(L,cpp_rst); lua_setglobal(L, "rst"); + lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN"); lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A"); lua_pushinteger(L, 5); lua_setglobal(L, "KEY_B");