diff --git a/data/main.lua b/data/main.lua index 7a89220..d861a5c 100644 --- a/data/main.lua +++ b/data/main.lua @@ -37,10 +37,16 @@ function normal_update() cls(20) view(10,10,140,100) cls(3) + color(5) prnt("HOLA",0,0) origin(70,50) prnt("ORIGIN",0,0) prnt(text,x,10) + color(10) + bcolor(15) + fillp(0x5a5a, false); + circfill(20,20,10); + fillp(0xffff,false); end redefinekeys = { diff --git a/lua.cpp b/lua.cpp index c701a87..fedd061 100644 --- a/lua.cpp +++ b/lua.cpp @@ -53,6 +53,12 @@ extern "C" { return 0; } + static int cpp_bcolor(lua_State *L) { + uint8_t col = luaL_optinteger(L, 1, 6); + bcolor(col); + return 0; + } + static int cpp_loadpal(lua_State *L) { const char* str = luaL_checkstring(L, 1); uint32_t *pal = loadpal(str); @@ -126,6 +132,31 @@ extern "C" { lua_pushinteger(L, gettrans()); return 1; } + static int cpp_subpal(lua_State *L) { + const int numargs = lua_gettop(L); + uint8_t index, index2, color; + switch (numargs) { + case 0: + reset_subpal(); + break; + case 1: + index = luaL_checkinteger(L, 1); + subpal(index,index); + break; + case 2: + index = luaL_checkinteger(L, 1); + color = luaL_checkinteger(L, 2); + subpal(index, color); + break; + case 3: + index = luaL_checkinteger(L, 1); + index2 = luaL_checkinteger(L, 2); + color = luaL_checkinteger(L, 3); + for (int i=index;i<=index2;++i) subpal(i, color); + break; + } + return 0; + } /* static int cpp_pal(lua_State *L) { int numargs = lua_gettop(L); switch (numargs) { @@ -842,6 +873,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_cls); lua_setglobal(L, "cls"); lua_pushcfunction(L,cpp_color); lua_setglobal(L, "color"); + lua_pushcfunction(L,cpp_bcolor); lua_setglobal(L, "bcolor"); lua_pushcfunction(L,cpp_loadpal); lua_setglobal(L, "loadpal"); lua_pushcfunction(L,cpp_setpal); lua_setglobal(L, "setpal"); @@ -849,6 +881,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_getcolor); lua_setglobal(L, "getcolor"); lua_pushcfunction(L,cpp_settrans); lua_setglobal(L, "settrans"); lua_pushcfunction(L,cpp_gettrans); lua_setglobal(L, "gettrans"); + lua_pushcfunction(L,cpp_subpal); lua_setglobal(L, "subpal"); lua_pushcfunction(L,cpp_pset); lua_setglobal(L, "pset"); lua_pushcfunction(L,cpp_pget); lua_setglobal(L, "pget"); diff --git a/mini.cpp b/mini.cpp index 19dd471..694d173 100644 --- a/mini.cpp +++ b/mini.cpp @@ -48,14 +48,18 @@ bool file_ignore_comma=true; #define TILES(x, y) map_surface->p[x+y*map_surface->w] #define CURRENT(x, y) surfaces[i].p[(x)+(y)*surfaces[i].w] +void (*do_pset)(int,int); + namespace ds { uint8_t pen_color = 6; + uint8_t back_color = 0; int cam[2] = {0, 0}; int clip[4] = {0, 0, screen_width, screen_height}; int clp[4] = {0, 0, screen_width-1, screen_height-1}; uint8_t trans = 0; uint16_t fill_pattern = 0b1111111111111111; bool fill_trans = false; + uint8_t draw_palette[256]; } bool turbo_mode = true; @@ -128,8 +132,24 @@ void read_ini() { fclose(f); } +void pset_fast(int x, int y) { + if (ds::trans != ds::pen_color) DEST(x, y) = ds::draw_palette[ds::pen_color]; +} + +void pset_pattern(int x, int y) { + int pbx = x % 4, pby = y % 4; + int pb = pbx+pby*4; + if (ds::fill_pattern & (1 << pb)) { + if (ds::trans != ds::pen_color) DEST(x, y) = ds::draw_palette[ds::pen_color]; + } else { + if (!ds::fill_trans) DEST(x, y) = ds::draw_palette[ds::back_color]; + } +} + void reinit() { + do_pset = pset_fast; ds::pen_color = 6; + ds::back_color = 0; ds::cam[0] = ds::cam[1] = 0; ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width; ds::clip[3] = screen_height; ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width-1; ds::clp[3] = screen_height-1; @@ -140,6 +160,7 @@ void reinit() { if (surfaces[i].p != NULL) free(surfaces[i].p); surfaces[i].p = NULL; } + for (int i=0;i<256;++i) ds::draw_palette[i]=i; if (file!=NULL) fclose(file); file = NULL; } @@ -386,9 +407,10 @@ void simple_pset(int x, int y, uint8_t color) { } void cls(uint8_t color) { + const uint8_t col = ds::draw_palette[color]; for (int y=ds::clip[1]+ds::cam[1]; yp, color, dest_surface->size); @@ -398,6 +420,10 @@ void color(uint8_t color) { ds::pen_color=color; } +void bcolor(uint8_t color) { + ds::back_color=color; +} + uint32_t *loadpal(const char* filename) { int size; uint8_t *buffer = (uint8_t*)file_getfilebuffer(filename, size); @@ -442,6 +468,14 @@ uint8_t gettrans() { return ds::trans; } +void subpal(uint8_t index, uint8_t color) { + ds::draw_palette[index] = color; +} + +void reset_subpal() { + for (int i=0;i<256;++i) ds::draw_palette[i]=i; +} + /*void pal() { for (int i=0; i<16; ++i) { ds::draw_palette[i] = i; @@ -471,21 +505,9 @@ void palt(uint8_t col, bool t) { void pset(int x, int y) { x -= ds::cam[0]; y -= ds::cam[1]; if (x < ds::clip[0] || x >= ds::clip[2] || y < ds::clip[1] || y >= ds::clip[3]) return; - if (ds::trans != ds::pen_color) DEST(x, y) = ds::pen_color; + do_pset(x,y); } -/*void pset(int x, int y) { - x -= ds::cam[0]; y -= ds::cam[1]; - if (x < ds::clp[0] || x > ds::clp[2] || y < ds::clp[1] || y > ds::clp[3]) return; - int pbx = x % 4, pby = y % 4; - int pb = pbx+pby*4; - if (ds::fill_pattern & (1 << pb)) { - if (!ds::trans[ds::pen_color & 0xf]) DEST(x, y) = ds::draw_palette[ds::pen_color & 0xf]; - } else { - if (!ds::fill_trans) DEST(x, y) = ds::draw_palette[ds::pen_color >> 4]; - } -}*/ - void pset(int x, int y, uint8_t color) { ds::pen_color = color; pset(x, y); @@ -586,6 +608,7 @@ void rectfill(int x0, int y0, int x1, int y1, uint8_t color) { void fillp(uint16_t pat, bool transparent) { ds::fill_trans = transparent; ds::fill_pattern = pat; + do_pset=(pat==0xffff?pset_fast:pset_pattern); } void print_symbol(char sym, int x, int y) { diff --git a/mini.h b/mini.h index 0e96f09..253854f 100644 --- a/mini.h +++ b/mini.h @@ -126,6 +126,7 @@ void setmap(uint8_t surface); void cls(uint8_t color=0); void color(uint8_t color=6); +void bcolor(uint8_t color=0); uint32_t *loadpal(const char* filename); void setpal(uint32_t *pal); @@ -133,6 +134,8 @@ void setcolor(uint8_t index, uint32_t color); uint32_t getcolor(uint8_t index); void settrans(uint8_t index); uint8_t gettrans(); +void subpal(uint8_t index, uint8_t color); +void reset_subpal(); /*void pal(); void pal(uint8_t c0, uint8_t c1, uint8_t p = 0); diff --git a/version.h b/version.h index b02db80..b490715 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #pragma once -#define MINI_VERSION "0.9.73d" +#define MINI_VERSION "0.9.78d"