diff --git a/ascii.cpp b/ascii.cpp index be3d70d..67bddd5 100644 --- a/ascii.cpp +++ b/ascii.cpp @@ -38,6 +38,7 @@ uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0 #define debug_total_size 2400 //debug_line_size*debug_num_lines char debug_text[debug_total_size]; int debug_cursor = 0; +int debug_prompt = 0; int debug_cursor_blink = 30; //Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X }; @@ -53,12 +54,12 @@ void reinit() { case 0: screen_width = 80; screen_height = 30; - current_color = 0x1e; + current_color = 0x19; cursor_x = 0; cursor_y = 0; char_screen = &mem[0]; color_screen = &mem[1200]; - SDL_RenderSetLogicalSize(mini_ren, 640, 480); + //SDL_RenderSetLogicalSize(mini_ren, 640, 480); mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 640, 240); break; case 1: @@ -69,7 +70,7 @@ void reinit() { cursor_y = 0; char_screen = &mem[0]; color_screen = &mem[1200]; - SDL_RenderSetLogicalSize(mini_ren, 320, 240); + //SDL_RenderSetLogicalSize(mini_ren, 320, 240); mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 240); break; case 2: @@ -80,7 +81,7 @@ void reinit() { cursor_y = 0; char_screen = &mem[0]; color_screen = &mem[300]; - SDL_RenderSetLogicalSize(mini_ren, 160, 120); + //SDL_RenderSetLogicalSize(mini_ren, 160, 120); mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 160, 120); break; } @@ -104,7 +105,7 @@ int main(int argc,char*argv[]) { for (int i=0; isize;++i) pixels[i] = palette[screen_surface->p[i]]; SDL_UnlockTexture(mini_bak); - SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL); + SDL_SetRenderDrawColor(mini_ren, (palette[9] >> 16)&0xff, (palette[9] >> 8)&0xff, palette[9]&0xff, 0); + //SDL_SetRenderDrawColor(mini_ren, 255, 0, 0, 0); + SDL_RenderClear(mini_ren); + SDL_Rect rect = {40, 40, 640, 480}; + SDL_RenderCopy(mini_ren, mini_bak, NULL, &rect); + //SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL); SDL_RenderPresent(mini_ren); } lua_quit(); @@ -348,16 +356,24 @@ const char* tostr(int val) { return SDL_itoa(val, tostr_tmp, 10); } +void debug_set_prompt() { + debug_prompt = debug_cursor++; + debug_text[debug_prompt] = '>'; +} + void debug_one_line_up() { for (int i=0; i(debug_prompt+1)) { + debug_text[debug_cursor--] = 32; + debug_text[debug_cursor] = 32; + } } else { debug_text[debug_cursor++] = chr; if (debug_cursor >= debug_total_size) debug_one_line_up(); @@ -372,6 +388,7 @@ void debug(const char *str) { } debug_cursor = (int(debug_cursor/debug_line_size)+1)*debug_line_size; if (debug_cursor >= debug_total_size) debug_one_line_up(); + debug_set_prompt(); } void pdebug() { @@ -384,6 +401,11 @@ void pdebug() { } } +void debug_get_cmd() { + debug_text[debug_cursor] = 0; + lua_call_cmd(&debug_text[debug_prompt+1]); +} + uint8_t ascii(const char *str, uint8_t index) { return str[index]; } diff --git a/ascii.h b/ascii.h index d9f5197..54901b4 100644 --- a/ascii.h +++ b/ascii.h @@ -158,6 +158,7 @@ const char* tostr(int val); void debugchr(const uint8_t chr); void debug(const char *str); void pdebug(); +void debug_get_cmd(); uint8_t ascii(const char *str, uint8_t index); diff --git a/game.lua b/game.lua index cfd7dcb..788a897 100644 --- a/game.lua +++ b/game.lua @@ -1,3 +1,4 @@ +cls() function init() x, y, dx, dy = 0, 0, 1, 1 paper(COLOR_BLACK) diff --git a/lua.cpp b/lua.cpp index a941db5..899967d 100644 --- a/lua.cpp +++ b/lua.cpp @@ -214,20 +214,25 @@ extern "C" { } } +#define STATE_STOPPED 0 +#define STATE_PAUSED 1 +#define STATE_PLAYING 2 + lua_State *L; -bool is_playing = false; +uint8_t lua_state = STATE_STOPPED; bool init_exists = false; bool update_exists = false; bool lua_is_playing() { - return is_playing; + return lua_state == STATE_PLAYING; } -void lua_init() { +void lua_init(const bool start_playing) { + if (lua_state != STATE_STOPPED) lua_quit(); L = luaL_newstate(); if (luaL_loadfile(L, "game.lua")) { - debug("error loading game"); + debug("ERROR LOADING GAME"); debug(lua_tostring(L, -1)); lua_pop(L,1); setmode(0); @@ -400,7 +405,7 @@ void lua_init() { lua_pushinteger(L, 15); lua_setglobal(L, "COLOR_WHITE"); if (lua_pcall(L,0, LUA_MULTRET, 0)) { - debug("runtime error"); + debug("RUNTIME ERROR"); debug(lua_tostring(L, -1)); lua_pop(L,1); setmode(0); @@ -415,18 +420,28 @@ void lua_init() { if (lua_isfunction(L,-1)) update_exists = true; lua_pop(L,1); - is_playing = true; + lua_state = start_playing ? STATE_PLAYING : STATE_PAUSED; +} + +void lua_call_cmd(const char* str) { + if (luaL_dostring(L, str)) { + debug(" "); + debug("ERROR"); + debug(lua_tostring(L, -1)); + lua_pop(L,1); + } + debug(" "); } void lua_call_init() { if (!init_exists) return; lua_getglobal(L, "init"); if (lua_pcall(L, 0, 0, 0)) { - debug("runtime error"); + debug("RUNTIME ERROR"); debug(lua_tostring(L, -1)); lua_pop(L,1); setmode(0); - is_playing = false; + lua_state = STATE_STOPPED; } } @@ -434,16 +449,24 @@ void lua_call_update() { if (!update_exists) return; lua_getglobal(L, "update"); if (lua_pcall(L, 0, 0, 0)) { - debug("runtime error"); + debug("RUNTIME ERROR"); debug(lua_tostring(L, -1)); lua_pop(L,1); setmode(0); - is_playing = false; + lua_state = STATE_STOPPED; } } void lua_quit() { - if (!is_playing) return; - is_playing = false; + if (lua_state == STATE_STOPPED) return; + lua_state = STATE_STOPPED; lua_close(L); } + +void lua_pause() { + lua_state = STATE_PAUSED; +} + +void lua_resume() { + lua_state = STATE_PLAYING; +} diff --git a/lua.h b/lua.h index f991050..cf92ba7 100644 --- a/lua.h +++ b/lua.h @@ -1,7 +1,10 @@ #pragma once bool lua_is_playing(); -void lua_init(); +void lua_init(const bool start_playing=true); void lua_call_init(); void lua_call_update(); +void lua_call_cmd(const char* str); void lua_quit(); +void lua_pause(); +void lua_resume(); diff --git a/main.cpp b/main.cpp index 7559d12..8ed9852 100644 --- a/main.cpp +++ b/main.cpp @@ -3,14 +3,35 @@ int current_editor = 0; void do_terminal() { + SDL_Keymod mods = SDL_GetModState(); const uint8_t key = whichbtn(); if (key != KEY_UNKNOWN) { - if (key < 30) debugchr(key+61); - else if (key < 39) debugchr(key+19); - else if (key == KEY_0) debugchr(key+9); - else if (key == KEY_RETURN) debug(" "); + if (key < 30) { + if ((mods & KMOD_SHIFT) || (mods & KMOD_CAPS)) { + debugchr(key+61); + } else { + debugchr(key+93); + } + } + //else if (key < 39) debugchr(key+19); + else if (key == KEY_0) { if (mods & KMOD_SHIFT) { debugchr('='); } else { debugchr('0'); } } + else if (key == KEY_1) { if (mods & KMOD_SHIFT) { debugchr('!'); } else if (mods & KMOD_RALT) { debugchr('|'); } else { debugchr('1'); } } + else if (key == KEY_2) { if (mods & KMOD_SHIFT) { debugchr('"'); } else if (mods & KMOD_RALT) { debugchr('@'); } else { debugchr('2'); } } + else if (key == KEY_3) { if (mods & KMOD_SHIFT) { debugchr('·'); } else if (mods & KMOD_RALT) { debugchr('#'); } else { debugchr('3'); } } + else if (key == KEY_4) { if (mods & KMOD_SHIFT) { debugchr('$'); } else if (mods & KMOD_RALT) { debugchr('~'); } else { debugchr('4'); } } + else if (key == KEY_5) { if (mods & KMOD_SHIFT) { debugchr('%'); } else if (mods & KMOD_RALT) { debugchr('€'); } else { debugchr('5'); } } + else if (key == KEY_6) { if (mods & KMOD_SHIFT) { debugchr('&'); } else if (mods & KMOD_RALT) { debugchr('¬'); } else { debugchr('6'); } } + else if (key == KEY_7) { if (mods & KMOD_SHIFT) { debugchr('/'); } else { debugchr('7'); } } + else if (key == KEY_8) { if (mods & KMOD_SHIFT) { debugchr('('); } else { debugchr('8'); } } + else if (key == KEY_9) { if (mods & KMOD_SHIFT) { debugchr(')'); } else { debugchr('9'); } } + else if (key == KEY_RETURN) debug_get_cmd(); else if (key == KEY_SPACE) debugchr(32); else if (key == KEY_BACKSPACE) debugchr(8); + else if (key == KEY_MINUS) { if (mods & KMOD_SHIFT) { debugchr('?'); } else { debugchr('\''); } } + else if (key == KEY_EQUALS) { if (mods & KMOD_SHIFT) { debugchr(174); } else { debugchr(175); } } + else if (key == KEY_COMMA) { if (mods & KMOD_SHIFT) { debugchr(';'); } else { debugchr(','); } } + else if (key == KEY_PERIOD) { if (mods & KMOD_SHIFT) { debugchr(':'); } else { debugchr('.'); } } + else if (key == KEY_SLASH) { if (mods & KMOD_SHIFT) { debugchr('_'); } else { debugchr('-'); } } } cls(0); pdebug();