[FEAT] Border
[FEAT] Color accepts a third optional parameter for border
This commit is contained in:
2021-12-10 19:32:05 +01:00
parent f21f199917
commit 376c15c272
3 changed files with 27 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ uint8_t *color_screen = NULL;
uint8_t screen_width = 40; uint8_t screen_width = 40;
uint8_t screen_height = 30; uint8_t screen_height = 30;
uint8_t current_color = 0x1e; uint8_t current_color = 0x1e;
uint8_t current_border = 0;
uint8_t current_mode = 1; uint8_t current_mode = 1;
uint8_t cursor_x = 0; uint8_t cursor_x = 0;
uint8_t cursor_y = 0; uint8_t cursor_y = 0;
@@ -65,6 +66,7 @@ void reinit() {
screen_width = 80; screen_width = 80;
screen_height = 30; screen_height = 30;
current_color = 0x07; current_color = 0x07;
current_border = 0;
cursor_x = 0; cursor_x = 0;
cursor_y = 0; cursor_y = 0;
char_screen = &mem[0]; char_screen = &mem[0];
@@ -76,6 +78,7 @@ void reinit() {
screen_width = 40; screen_width = 40;
screen_height = 30; screen_height = 30;
current_color = 0x07; current_color = 0x07;
current_border = 0;
cursor_x = 0; cursor_x = 0;
cursor_y = 0; cursor_y = 0;
char_screen = &mem[0]; char_screen = &mem[0];
@@ -87,6 +90,7 @@ void reinit() {
screen_width = 20; screen_width = 20;
screen_height = 15; screen_height = 15;
current_color = 0x07; current_color = 0x07;
current_border = 0;
cursor_x = 0; cursor_x = 0;
cursor_y = 0; cursor_y = 0;
char_screen = &mem[0]; char_screen = &mem[0];
@@ -268,7 +272,7 @@ int main(int argc,char*argv[]) {
//for (int i=0;i<screen_surface->size;++i) pixels[i] = palette[screen_surface->p[i]]; //for (int i=0;i<screen_surface->size;++i) pixels[i] = palette[screen_surface->p[i]];
SDL_UnlockTexture(mini_bak); 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_SetRenderDrawColor(mini_ren, 255, 0, 0, 0);
SDL_RenderClear(mini_ren); SDL_RenderClear(mini_ren);
SDL_Rect rect = {40, 40, 640, 480}; SDL_Rect rect = {40, 40, 640, 480};
@@ -300,8 +304,13 @@ void paper(uint8_t value) {
current_color = (current_color & 0x0f) + (value << 4); 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); current_color = (ink & 0x0f) + (paper << 4);
if (border >= 0) current_border = border & 0xf;
} }
void locate(uint8_t x, uint8_t y) { void locate(uint8_t x, uint8_t y) {

View File

@@ -115,7 +115,8 @@ void loop();
void cls(uint8_t value=32); void cls(uint8_t value=32);
void ink(uint8_t value); // global::ink void ink(uint8_t value); // global::ink
void paper(uint8_t value); // global::paper 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 locate(uint8_t x, uint8_t y); // global::cursorx, global::cursory
void print(const char *str, int x = -1, int y = -1); void print(const char *str, int x = -1, int y = -1);

16
lua.cpp
View File

@@ -21,10 +21,21 @@ extern "C" {
return 0; 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) { static int cpp_color(lua_State *L) {
uint8_t ink = luaL_checkinteger(L, 1); uint8_t ink = luaL_checkinteger(L, 1);
uint8_t paper = luaL_checkinteger(L, 2); 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; return 0;
} }
@@ -274,7 +285,7 @@ bool lua_is_playing() {
return lua_state == STATE_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) { void lua_init(const char* filename, const bool start_playing) {
if (lua_state != STATE_STOPPED) lua_quit(); 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_cls); lua_setglobal(L, "cls");
lua_pushcfunction(L,cpp_ink); lua_setglobal(L, "ink"); lua_pushcfunction(L,cpp_ink); lua_setglobal(L, "ink");
lua_pushcfunction(L,cpp_paper); lua_setglobal(L, "paper"); 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_color); lua_setglobal(L, "color");
lua_pushcfunction(L,cpp_locate); lua_setglobal(L, "locate"); lua_pushcfunction(L,cpp_locate); lua_setglobal(L, "locate");