From fc962b4e18fbaea86c776094debe2c9691defccc Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 24 Feb 2026 11:03:21 +0100 Subject: [PATCH] =?UTF-8?q?-=20[NEW]=20draw.mode(),=20amb=20modes=20NORMAL?= =?UTF-8?q?,=20PATTERN,=20AND,=20OR,=20XOR=20i=20NOT=20-=20[NEW]=20Ara=20p?= =?UTF-8?q?er=20a=20pintar=20en=20pattern=20hi=20ha=20que=20dir-ho=20en=20?= =?UTF-8?q?draw.mode(),=20no=20es=20automatic=20al=20ficar=20un=20pattern.?= =?UTF-8?q?=20-=20[NEW]=20Nous=20modes=20de=20pintat=20booleans.=20AND,=20?= =?UTF-8?q?OR=20i=20XOR=20fan=20l'operaci=C3=B3=20pixel=5Factual=20=3D=20p?= =?UTF-8?q?ixel=5Factual=20OP=20color=5Fespecificat.=20NOT=20no=20usa=20el?= =?UTF-8?q?=20color=20especificat,=20nomes=20fa=20un=20NOT=20del=20pixel?= =?UTF-8?q?=20actual.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua.cpp | 15 +++++++++++++++ mini.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- mini.h | 8 ++++++++ version.h | 2 +- vscode/library.lua | 20 ++++++++++++++++++++ 5 files changed, 85 insertions(+), 2 deletions(-) diff --git a/lua.cpp b/lua.cpp index 16a3f3a..b0bdbff 100644 --- a/lua.cpp +++ b/lua.cpp @@ -578,6 +578,12 @@ extern "C" { return 0; } + static int cpp_draw_mode(lua_State *L) { + int mode = luaL_checknumber(L, 1); + set_draw_mode(mode); + return 0; + } + // shaders // =============================================== @@ -1032,6 +1038,15 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_draw_surface); lua_setfield(L, -2, "surf"); lua_pushcfunction(L,cpp_draw_surfaceRotated); lua_setfield(L, -2, "surfrot"); lua_pushcfunction(L,cpp_draw_text); lua_setfield(L, -2, "text"); + lua_pushcfunction(L,cpp_draw_mode); lua_setfield(L, -2, "mode"); + + lua_pushinteger(L, 0); lua_setfield(L, -2, "NORMAL"); + lua_pushinteger(L, 1); lua_setfield(L, -2, "PATTERN"); + lua_pushinteger(L, 2); lua_setfield(L, -2, "AND"); + lua_pushinteger(L, 3); lua_setfield(L, -2, "OR"); + lua_pushinteger(L, 4); lua_setfield(L, -2, "XOR"); + lua_pushinteger(L, 5); lua_setfield(L, -2, "NOT"); + lua_setglobal(L, "draw"); lua_newtable(L); diff --git a/mini.cpp b/mini.cpp index a4bd261..88fe463 100644 --- a/mini.cpp +++ b/mini.cpp @@ -78,6 +78,7 @@ namespace ds { uint16_t fill_pattern = 0b1111111111111111; bool fill_trans = false; uint8_t draw_palette[256]; + uint8_t mode = DRAWMODE_NORMAL; } int update_mode = UPDATE_ALWAYS; @@ -163,6 +164,25 @@ void pset_fast(int x, int y) { if (ds::trans != ds::pen_color) DEST(x, y) = ds::draw_palette[ds::pen_color]; } +void pset_bool(int x, int y) { + if (ds::trans != ds::pen_color) { + switch (ds::mode) { + case DRAWMODE_AND: + DEST(x, y) = DEST(x, y) & ds::draw_palette[ds::pen_color]; + break; + case DRAWMODE_OR: + DEST(x, y) = DEST(x, y) | ds::draw_palette[ds::pen_color]; + break; + case DRAWMODE_XOR: + DEST(x, y) = DEST(x, y) ^ ds::draw_palette[ds::pen_color]; + break; + case DRAWMODE_NOT: + DEST(x, y) = ~DEST(x, y); + break; + } + } +} + void pset_pattern(int x, int y) { int pbx = x % 4, pby = y % 4; int pb = pbx+pby*4; @@ -173,6 +193,27 @@ void pset_pattern(int x, int y) { } } +void set_draw_mode(uint8_t mode) { + ds::mode = mode; + switch (mode) { + case DRAWMODE_NORMAL: + do_pset = pset_fast; + break; + case DRAWMODE_PATTERN: + do_pset = pset_pattern; + break; + case DRAWMODE_AND: + case DRAWMODE_OR: + case DRAWMODE_XOR: + case DRAWMODE_NOT: + do_pset = pset_bool; + break; + default: + do_pset = pset_fast; + break; + } +} + void reinit() { log_msg(LOG_INFO, "STARTING A SYSTEM REINITIALIZATION\n"); do_pset = pset_fast; @@ -816,7 +857,6 @@ void rectfill(int x, int y, int w, int h, uint8_t color) { void fillp(uint16_t pat, bool transparent) { ds::fill_trans = true; //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 f5db147..e0f9b2e 100644 --- a/mini.h +++ b/mini.h @@ -112,6 +112,13 @@ #define KEY_RALT 230 #define KEY_RGUI 231 +#define DRAWMODE_NORMAL 0 +#define DRAWMODE_PATTERN 1 +#define DRAWMODE_AND 2 +#define DRAWMODE_OR 3 +#define DRAWMODE_XOR 4 +#define DRAWMODE_NOT 5 + void loop(); int scrw(); @@ -146,6 +153,7 @@ uint8_t gettrans(); void subpal(uint8_t index, uint8_t color); void reset_subpal(); +void set_draw_mode(uint8_t mode); void pset(int x, int y); void pset(int x, int y, uint8_t color); diff --git a/version.h b/version.h index 5b50edb..b9c412e 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #pragma once -#define MINI_VERSION "1.3.14" +#define MINI_VERSION "1.3.15" diff --git a/vscode/library.lua b/vscode/library.lua index c124b9f..74e0bbe 100644 --- a/vscode/library.lua +++ b/vscode/library.lua @@ -164,7 +164,15 @@ function view.origin(x, y) end ---Convert screen position to viewport position function view.tolocal(x, y) end + ---@class draw +---@field draw.NORMAL number +---@field draw.PATTERN number +---@field draw.AND number +---@field draw.OR number +---@field draw.XOR number +---@field draw.NOT number + draw = {} ---@param x1 number @@ -301,6 +309,18 @@ function draw.text(text, x, y, color) end ---Draw text to (x,y) using the specified color function draw.text(text, x, y, color) end +---@param mode number +---Specify the mode for the drawing functions +function draw.mode(mode) end + +draw.NORMAL = 0 +draw.PATTERN = 1 +draw.AND = 2 +draw.OR = 3 +draw.XOR = 4 +draw.NOT = 5 + + ---@class shader shader = {}