From 376c15c272e49bc5c417e2ec72a280979ef9595e Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Fri, 10 Dec 2021 19:32:05 +0100 Subject: [PATCH] v0.5.4 [FEAT] Border [FEAT] Color accepts a third optional parameter for border --- ascii.cpp | 13 +++++++++++-- ascii.h | 3 ++- lua.cpp | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ascii.cpp b/ascii.cpp index bb7d8ed..737ff83 100644 --- a/ascii.cpp +++ b/ascii.cpp @@ -19,6 +19,7 @@ uint8_t *color_screen = NULL; uint8_t screen_width = 40; uint8_t screen_height = 30; uint8_t current_color = 0x1e; +uint8_t current_border = 0; uint8_t current_mode = 1; uint8_t cursor_x = 0; uint8_t cursor_y = 0; @@ -65,6 +66,7 @@ void reinit() { screen_width = 80; screen_height = 30; current_color = 0x07; + current_border = 0; cursor_x = 0; cursor_y = 0; char_screen = &mem[0]; @@ -76,6 +78,7 @@ void reinit() { screen_width = 40; screen_height = 30; current_color = 0x07; + current_border = 0; cursor_x = 0; cursor_y = 0; char_screen = &mem[0]; @@ -87,6 +90,7 @@ void reinit() { screen_width = 20; screen_height = 15; current_color = 0x07; + current_border = 0; cursor_x = 0; cursor_y = 0; char_screen = &mem[0]; @@ -268,7 +272,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_SetRenderDrawColor(mini_ren, (palette[0] >> 16)&0xff, (palette[0] >> 8)&0xff, palette[0]&0xff, 0); + SDL_SetRenderDrawColor(mini_ren, (palette[current_border] >> 16)&0xff, (palette[current_border] >> 8)&0xff, palette[current_border]&0xff, 0); //SDL_SetRenderDrawColor(mini_ren, 255, 0, 0, 0); SDL_RenderClear(mini_ren); SDL_Rect rect = {40, 40, 640, 480}; @@ -300,8 +304,13 @@ void paper(uint8_t value) { current_color = (current_color & 0x0f) + (value << 4); } -void color(uint8_t ink, uint8_t paper) { +void border(uint8_t value) { + current_border = value & 0xf; +} + +void color(uint8_t ink, uint8_t paper, int8_t border) { current_color = (ink & 0x0f) + (paper << 4); + if (border >= 0) current_border = border & 0xf; } void locate(uint8_t x, uint8_t y) { diff --git a/ascii.h b/ascii.h index 040a9fd..086bde6 100644 --- a/ascii.h +++ b/ascii.h @@ -115,7 +115,8 @@ void loop(); void cls(uint8_t value=32); void ink(uint8_t value); // global::ink void paper(uint8_t value); // global::paper -void color(uint8_t ink, uint8_t paper); +void border(uint8_t value); +void color(uint8_t ink, uint8_t paper, int8_t border=-1); void locate(uint8_t x, uint8_t y); // global::cursorx, global::cursory void print(const char *str, int x = -1, int y = -1); diff --git a/lua.cpp b/lua.cpp index 5cc970e..1fafc89 100644 --- a/lua.cpp +++ b/lua.cpp @@ -21,10 +21,21 @@ extern "C" { return 0; } + static int cpp_border(lua_State *L) { + uint8_t val = luaL_checkinteger(L, 1); + border(val); + return 0; + } + static int cpp_color(lua_State *L) { uint8_t ink = luaL_checkinteger(L, 1); uint8_t paper = luaL_checkinteger(L, 2); - color(ink, paper); + if (lua_gettop(L) > 2) { + uint8_t border = luaL_checkinteger(L, 3); + color(ink, paper, border); + } else { + color(ink, paper); + } return 0; } @@ -274,7 +285,7 @@ bool lua_is_playing() { return lua_state == STATE_PLAYING; } -const char boot[] = "function init()setmode(1)cls()play('o5l0v5cegv4cegv3cegv2cegv1ceg')memcpy(360,4608,240)memcpy(1560,4848,240)ink(1)print('G A M E',8,16)ink(4)print('S Y S T E M',20,16)ink(8)print('v0.5.2',26,8)w=0 end function update()w=w+1 if w>90 then cls()load()end end"; +const char boot[] = "function init()setmode(1)cls()play('o5l0v5cegv4cegv3cegv2cegv1ceg')memcpy(360,4608,240)memcpy(1560,4848,240)ink(1)print('G A M E',8,16)ink(4)print('S Y S T E M',20,16)ink(7)print('mini',9,8)ink(8)print('v0.5.4',34,29)w=0 end function update()w=w+1 if w>90 then cls()load()end end"; void lua_init(const char* filename, const bool start_playing) { if (lua_state != STATE_STOPPED) lua_quit(); @@ -303,6 +314,7 @@ void lua_init(const char* filename, const bool start_playing) { lua_pushcfunction(L,cpp_cls); lua_setglobal(L, "cls"); lua_pushcfunction(L,cpp_ink); lua_setglobal(L, "ink"); lua_pushcfunction(L,cpp_paper); lua_setglobal(L, "paper"); + lua_pushcfunction(L,cpp_border); lua_setglobal(L, "border"); lua_pushcfunction(L,cpp_color); lua_setglobal(L, "color"); lua_pushcfunction(L,cpp_locate); lua_setglobal(L, "locate");