From 0eb821a67b196f638eaa085e32bae3fb65403c75 Mon Sep 17 00:00:00 2001 From: Egor00f Date: Fri, 11 Apr 2025 14:49:53 +0500 Subject: [PATCH] fix drawText Func --- .vscode/settings.json | 1 + Makefile | 3 ++- src/debug/debug.c | 28 ++++++++++++++++++++++++---- src/debug/debug.h | 22 +++++++++++++++++++++- src/debug/registers.c | 9 +++++---- src/debug/registers.h | 2 +- src/graphic.c | 37 +++++++++++++++++-------------------- src/syscalls.c | 12 +++++++++++- src/systemColors.c | 2 +- 9 files changed, 83 insertions(+), 33 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 83001e8..805b389 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -27,6 +27,7 @@ "luaL_checkstring", "luaL_checkudata", "luaL_optinteger", + "luaL_pushfail", "lua_pushboolean", "lua_pushinteger", "lua_pushnumber", diff --git a/Makefile b/Makefile index 5ae86b5..81b8f3e 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ src/sockets/socket_lua.o: src/sockets/socket_lua.c src/sockets/socket_lua.h src/sockets/sockaddr.o: src/sockets/sockaddr.c src/sockets/sockaddr.h src/graphic.o: src/graphic.c src/graphic.h src/debug/debug.o: src/debug/debug.c src/debug/debug.h src/debug/registers.h -src/debug/registers.o: src/debug/registers.c src/debug/registers.h src/syscalls.h +src/debug/registers.o: src/debug/registers.c src/debug/registers.h src/syscalls.h ## headers @@ -61,3 +61,4 @@ src/graphic.h: src/syscalls.h src/sockets/socket_lua.h: src/syscalls.h src/sockets/socket.h src/sockets/sockaddr.h: src/sockets/socket.h src/syscalls.h src/debug/debug.h: src/syscalls.h +src/debug/registers.h: src/syscalls.h diff --git a/src/debug/debug.c b/src/debug/debug.c index 27cc447..28d46f5 100644 --- a/src/debug/debug.c +++ b/src/debug/debug.c @@ -98,7 +98,7 @@ int syscalls_Continue(lua_State* L) return 1; } -int syscalls_ReadFromMem(lua_State *L) +int syscalls_ReadFromMem(lua_State* L) { uint32_t pid = luaL_checkinteger(L, 1); uint32_t bytes = luaL_checkinteger(L, 2); @@ -112,7 +112,7 @@ int syscalls_ReadFromMem(lua_State *L) : "a"(69), "b"(6), "c"(pid), "d"(bytes), "S"(pointer), "D"(buffer) ); - if (ret == -1) + if (ret == -1) lua_pushnil(L); else lua_pushinteger(L, ret); @@ -158,8 +158,28 @@ int syscalls_DefineBreakpoint(lua_State* L) { uint32_t pid = luaL_checkinteger(L, 1); - - uint32_t flags = luaL_checkinteger(L, 2) & 0xFF | (luaL_checkinteger(L, 3) << 16) | (luaL_checkinteger(L, 4) << 18); + // точки останова условие длина указатель + uint32_t flags = luaL_checkinteger(L, 2) & 0xFF | (luaL_checkinteger(L, 3) << 16) | (luaL_checkinteger(L, 4) << 18) | (luaL_checkinteger(L, 4) << 20); + + uint32_t ret; + + asm_inline( + "int $0x40" + : "=a"(ret) + : "a"(69), "b"(9), "c"(pid), "d"(flags) + ); + + lua_pushinteger(L, ret); + + return 1; +} + +int syscalls_UndefBreakpoint(lua_State* L) +{ + uint32_t pid = luaL_checkinteger(L, 1); + + // точки останова условие длина указатель бит + uint32_t flags = luaL_checkinteger(L, 2) & 0xFF | (luaL_checkinteger(L, 3) << 16) | (luaL_checkinteger(L, 4) << 18) | (luaL_checkinteger(L, 4) << 20) | (1 << 31); uint32_t ret; diff --git a/src/debug/debug.h b/src/debug/debug.h index 0cede26..5102b7a 100644 --- a/src/debug/debug.h +++ b/src/debug/debug.h @@ -23,4 +23,24 @@ int syscalls_DebugPuts(lua_State* L); int syscalls_SetMessageArea(lua_State* L); -#endif // __DEBUG_LUA_H__ \ No newline at end of file +int syscalls_GetRegisters(lua_State* L); + +int syscalls_SetRegisters(lua_State* L); + +int syscalls_Disconnect(lua_State* L); + +int syscalls_Stop(lua_State* L); + +int syscalls_Continue(lua_State* L); + +int syscalls_ReadFromMem(lua_State* L); + +int syscalls_WriteToMem(lua_State* L); + +int syscalls_Done(lua_State* L); + +int syscalls_DefineBreakpoint(lua_State* L); + +int syscalls_UndefBreakpoint(lua_State* L); + +#endif // __DEBUG_LUA_H__ diff --git a/src/debug/registers.c b/src/debug/registers.c index 436f935..f153e05 100644 --- a/src/debug/registers.c +++ b/src/debug/registers.c @@ -1,6 +1,7 @@ #include "registers.h" #include "../syscalls.h" #include +#include "../debug.h" static int syscalls_indexRegisters(lua_State* L) { @@ -79,7 +80,7 @@ static int syscalls_newindexRegisters(lua_State* L) } else { - luaL_pushfail(L); + luaL_error(L, "wrong index: %s", index); } return 1; @@ -106,11 +107,11 @@ static const luaL_Reg syscalls_registers_m[] = { {NULL, NULL} }; -struct ARP_entry* syscalls_pushRegisters(lua_State* L) +struct registers* syscalls_pushRegisters(lua_State* L) { - DEBUG_LINE("push ARP entry"); + DEBUG_LINE("push registers entry"); - struct ARP_entry* entry = lua_newuserdata(L, sizeof(struct registers)); + struct registers* entry = lua_newuserdata(L, sizeof(struct registers)); luaL_setmetatable(L, syscalls_registers_metatable_name); diff --git a/src/debug/registers.h b/src/debug/registers.h index da4ee47..e5dbd16 100644 --- a/src/debug/registers.h +++ b/src/debug/registers.h @@ -1,7 +1,7 @@ #ifndef __REGISTERS_H__ #define __REGISTERS_H__ -#include +#include "../syscalls.h" struct registers { diff --git a/src/graphic.c b/src/graphic.c index 4a1f0c3..a6ee6ec 100644 --- a/src/graphic.c +++ b/src/graphic.c @@ -1,4 +1,5 @@ #include "graphic.h" +#include "debug.h" /* Кеш размера экрана. @@ -30,14 +31,11 @@ int syscalls_drawLine(lua_State* L) static inline void drawText(char* text, uint32_t x, uint32_t y, ksys_color_t color, size_t len, uint64_t backgroundColor) { - bool fillBackground = !(backgroundColor << 32); - - color |= (fillBackground << 30); + if (backgroundColor < (1 << 32)) + color |= (1 << 30); if (len == 0) - { color |= (1 << 31); - } asm_inline( "int $0x40" @@ -50,7 +48,7 @@ static inline void drawText(char* text, uint32_t x, uint32_t y, ksys_color_t col } -static inline void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_color_t color, enum TextScale size, uint32_t len, uint64_t backgroundColor, enum DrawTextEncoding encoding) +static inline void drawTextFixSize(const char* text, uint32_t x, uint32_t y, ksys_color_t color, enum TextScale size, uint32_t len, uint64_t backgroundColor, enum DrawTextEncoding encoding) { enum DrawTextEncoding_ { @@ -70,7 +68,7 @@ static inline void syscall_drawText(const char* text, uint32_t x, uint32_t y, ks scale_x8 = 7 }; - color &= 0x00FFFFFF; + color &= 0x00ffffff; switch (size) { @@ -123,6 +121,7 @@ static inline void syscall_drawText(const char* text, uint32_t x, uint32_t y, ks color |= (encoding << 28) | (scale_x8 << 24); break; default: + _ksys_debug_puts("Unknown size"); break; }; @@ -131,25 +130,23 @@ static inline void syscall_drawText(const char* text, uint32_t x, uint32_t y, ks int syscalls_drawText(lua_State* L) { - const char text = luaL_checkstring(L, 1); - uint32_t x = luaL_checkinteger(L, 2); - uint32_t y = luaL_checkinteger(L, 3); - ksys_color_t color = luaL_checkinteger(L, 4); - uint8_t scale = luaL_optinteger(L, 5, 1); - uint32_t len = luaL_optinteger(L, 6, 0); - LUA_INTEGER backgroundColor = luaL_optinteger(L, 7, 1 << 32); - enum DrawTextEncoding encoding = luaL_optinteger(L, 8, DEFAULT_ENCODING); - - color |= (encoding << 28) | (scale << 24); - - drawText(text, x, y, color, len, backgroundColor); + drawText( + luaL_checkstring(L, 1), + luaL_checkinteger(L, 2), + luaL_checkinteger(L, 3), + (luaL_checkinteger(L, 4) & 0x00ffffff) | + ((luaL_optinteger(L, 8, DEFAULT_ENCODING) & 0b11) << 28) | + (luaL_optinteger(L, 5, 1) << 24), + luaL_optinteger(L, 6, 0), + luaL_optinteger(L, 7, 1 << 32) + ); return 0; } int syscalls_drawTextFixSize(lua_State* L) { - syscall_drawText( + drawTextFixSize( luaL_checkstring(L, 1), luaL_checkinteger(L, 2), luaL_checkinteger(L, 3), diff --git a/src/syscalls.c b/src/syscalls.c index e75c894..3855795 100644 --- a/src/syscalls.c +++ b/src/syscalls.c @@ -1626,7 +1626,17 @@ static const luaL_Reg syscallsLib[] = { {"DebugPuts", syscalls_DebugPuts}, { "DebugPutc", syscalls_DebugPutc }, {"SetMessageArea", syscalls_SetMessageArea}, - {NULL, NULL} + { "GetRegisters", syscalls_GetRegisters }, + { "SetRegisters", syscalls_SetRegisters }, + { "Disconnect", syscalls_Disconnect }, + { "Stop", syscalls_Stop }, + { "Continue", syscalls_Continue }, + { "ReadFromMem", syscalls_ReadFromMem }, + { "WriteToMem", syscalls_WriteToMem }, + { "Done", syscalls_Done }, + { "DefineBreakpoint", syscalls_DefineBreakpoint }, + { "UndefBreakpoint", syscalls_UndefBreakpoint }, + { NULL, NULL } }; static inline void syscalls_push_events(lua_State* L) diff --git a/src/systemColors.c b/src/systemColors.c index d619479..7502449 100644 --- a/src/systemColors.c +++ b/src/systemColors.c @@ -41,7 +41,7 @@ static int syscalls_indexSystemColors(lua_State* L) { lua_pushinteger(L, t->grab_bar_button); } - else if (strcmp("grab_button_text", index) == 0) + else if (strcmp("grabButtonText", index) == 0) { lua_pushinteger(L, t->grab_button_text); }