diff --git a/.vscode/settings.json b/.vscode/settings.json index 2a17d46..805b389 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,27 +2,39 @@ "editor.tabSize": 4, "editor.insertSpaces": false, "files.associations": { - "stdlib.h": "c" + "stdlib.h": "c", + "ksys.h": "c", + "socket.h": "c", + "graphic.h": "c", + "syscalls.h": "c", + "registers.h": "c" }, "cSpell.words": [ + "syscalls", + "INET", + "IPPROTO", + "DGRAM", "ksys", "ksys_oskey_t", "LUALIB_API", "luaL_newlib", "metatable", + "tonumber", "luaL_newmetatable", "luaL_setmetatable", - "lua_createtable", "luaL_setfuncs", "luaL_checkinteger", "luaL_checkstring", "luaL_checkudata", + "luaL_optinteger", + "luaL_pushfail", "lua_pushboolean", "lua_pushinteger", "lua_pushnumber", - "luaL_optinteger", "lua_pushstring", "lua_pushnil", + "lua_createtable", + "lua_newtable", "lua_touserdata", "lua_setfield", "lua_getfield", diff --git a/Makefile b/Makefile index 230d05c..81b8f3e 100644 --- a/Makefile +++ b/Makefile @@ -1,35 +1,39 @@ LUA_V = 54 -CC=kos32-gcc -LD=kos32-ld -STRIP=kos32-strip -OBJCOPY=kos32-objcopy -STD=-std=gnu99 -CFLAGS=$(SYSCFLAGS) -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(STD) $(MYCFLAGS) -LDFLAGS=$(SYSLDFLAGS) $(MYLDFLAGS) -LIBS=$(SYSLIBS) $(MYLIBS) $(TOOLCHAIN_PATH)/mingw32/lib/lua$(LUA_V).dll.a +CC = kos32-gcc +LD = kos32-ld +STRIP = kos32-strip +OBJCOPY = kos32-objcopy +STD = -std=gnu11 +CFLAGS = $(SYSCFLAGS) -O2 -Wall -Wextra $(STD) $(MYCFLAGS) +LDFLAGS = $(SYSLDFLAGS) $(MYLDFLAGS) +LIBS = $(SYSLIBS) $(MYLIBS) $(TOOLCHAIN_PATH)/mingw32/lib/lua$(LUA_V).dll.a ifeq ($(OS), Windows_NT) - TOOLCHAIN_PATH=C:/MinGW/msys/1.0/home/autobuild/tools/win32 + TOOLCHAIN_PATH = C:/MinGW/msys/1.0/home/autobuild/tools/win32 else - TOOLCHAIN_PATH=/home/autobuild/tools/win32 + TOOLCHAIN_PATH = /home/autobuild/tools/win32 endif -KOLIBRIOS_REPO=../kolibrios +KOLIBRIOS_REPO = $(abspath ../kolibrios) -SDK_DIR=$(KOLIBRIOS_REPO)/contrib/sdk -NewLib_DIR=$(SDK_DIR)/sources/newlib -SYSCFLAGS=-fno-ident -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -I$(NewLib_DIR)/libc/include -I$(abspath .)/lua/src -SYSLDFLAGS=--image-base 0 -Tapp-dynamic.lds -SYSLIBS=-nostdlib -L $(SDK_DIR)/lib -L$(TOOLCHAIN_PATH)/lib -L$(TOOLCHAIN_PATH)/mingw32/lib -lgcc -lc.dll -ldll -MYCFLAGS= -MYLDFLAGS= -MYLIBS= -MYOBJS= +SDK_DIR = $(KOLIBRIOS_REPO)/contrib/sdk +NewLib_DIR = $(SDK_DIR)/sources/newlib +SYSCFLAGS = -fno-ident -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -I$(NewLib_DIR)/libc/include -I$(abspath .)/lua/src +SYSLDFLAGS = --image-base 0 -Tapp-dynamic.lds +SYSLIBS = -nostdlib -L $(SDK_DIR)/lib -L$(TOOLCHAIN_PATH)/lib -L$(TOOLCHAIN_PATH)/mingw32/lib -lgcc -lc.dll -ldll +MYCFLAGS = +MYLDFLAGS = +MYLIBS = +MYOBJS = -ALL_O = src/syscalls.o src/ARP_entry.o src/systemColors.o + +Socket_O = src/sockets/socket.o src/sockets/socket_lua.o src/sockets/sockaddr.o +Debug_O = src/debug/debug.o src/debug/registers.o + +ALL_O = src/syscalls.o src/ARP_entry.o src/systemColors.o src/graphic.o $(Socket_O) $(Debug_O) syscalls.dll: $(ALL_O) $(CC) -shared -T dll.lds --entry _DllStartup -o $@ $(ALL_O) $(LIBS) @@ -37,7 +41,24 @@ syscalls.dll: $(ALL_O) clean: rm -f $(ALL_O) syscalls.dll +# Depends -src/syscalls.o: src/syscalls.c src/systemColors.h src/ARP_entry.h src/scancodes.h -src/ARP_entry.o: src/ARP_entry.c src/ARP_entry.h src/debug.h -src/systemColors.o: src/systemColors.c src/systemColors.h src/debug.h +## Sources + +src/syscalls.o: src/syscalls.c src/syscalls.h src/systemColors.h src/ARP_entry.h src/scancodes.h src/sockets/socket_lua.h src/graphic.h +src/ARP_entry.o: src/ARP_entry.c src/ARP_entry.h src/debug.h +src/systemColors.o: src/systemColors.c src/systemColors.h src/debug.h +src/sockets/socket.o: src/sockets/socket.c src/sockets/socket.h +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 + +## headers + +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/doc/manual.md b/doc/manual.md new file mode 100644 index 0000000..3ee2a47 --- /dev/null +++ b/doc/manual.md @@ -0,0 +1,173 @@ +# Manual + +```lua +local syscalls = require("syscalls") +``` + + + +## Events + +```lua +syscalls.Event. +``` + ++ `Redraw` ++ `Button` ++ `Key` ++ `Desktop` ++ `Mouse` ++ `Network` ++ `IPC` ++ `Debug` + +## Graphic + +### Text encoding + +```lua +syscalls.Encoding. +``` + ++ `cp866` ++ `cp866_8x16` ++ `utf8` ++ `utf16` + +### Text sizes + +```lua +syscalls.textSize. +``` + ++ `6x9` (cp866 only) ++ `8x16` ++ `12x18` (cp866 only) ++ `16x32` ++ `18x27` (cp866 only) ++ `24x36` (cp866 only) ++ `24x48` ++ `30x45` (cp866 only) ++ `32x64` ++ `36x54` (cp866 only) ++ `40x80` ++ `42x63` (cp866 only) ++ `48x72` (cp866 only) ++ `48x96` ++ `56x112` ++ `64x128` + +### `DrawText(text, xPos, yPos, textColor, textScale, textLen, backgroundColor, encoding)` + +### `DrawTextFixSize(text, xPos, yPos, textColor, textSize, textLen, backgroundColor, encoding)` + +Draw text. + +textSize, textLen, backgroundColor, encoding are optional. + +### `DrawLine(x1, y1, x2, y2)` + +### `DrawRectangle(x, y, w, h color)` + +### `ReadPoint(x, y)` + +return color + +## Sockets + +### `OpenSocket(domain, type, protocol)` + +```lua +local socket, err = syscalls.OpenSocket( + syscalls.SOCK.STREAM, + syscalls.AF.INET, + syscalls.IPPROTO.IP +) + +if err then + print("Error", err) +else + print("Ok") +end +``` + +### `CloseSocket(socket)` + +### `PairSocket()` + +```lua +local first, second = PairSocket() + +if first then + print("OK") +else + print("Error:", second) +end +``` + +### `Bind(socket, address)` + +### `Listen(socket, backlog)` + +### `Connect(socket, address)` + +### `Accept(socket, , flags)` + +### `Receive(socket, , flags)` + +### `SetSocketOption(socket, opt)` + +### `GetSocketOption(socket, opt)` + +### Socket types + +```lua +syscalls.SOCK. +``` + ++ `STREAM` ++ `RAW` ++ `DGRAM` + +### Address families + +```lua +syscalls.AF. +``` + ++ `UNSPEC` ++ `LOCAL` ++ `INET` ++ `INET4` ++ `INET6` + +### IP options + +```lua +syscalls.IP. +``` + ++ `TTL` + +### IP protocols + +```lua +syscalls.IPPROTO. +``` + ++ `IP` ++ `ICMP` ++ `TCP` ++ `UDP` ++ `RAW` + +### Socket options + +```lua +syscalls.SO. +``` + ++ `BINDTODEVICE` ++ `NONBLOCK` + + diff --git a/src/ARP_entry.c b/src/ARP_entry.c index 6a5dfe2..f2443b0 100644 --- a/src/ARP_entry.c +++ b/src/ARP_entry.c @@ -8,7 +8,7 @@ static int syscalls_gcARPEntry(lua_State* L) { - free(lua_touserdata(L, 1)); + free(luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name)); return 0; } @@ -90,8 +90,8 @@ static int syscalls_eqAPREntry(lua_State* L) lua_pushboolean( L, syscalls_cmpAPREntry( - (struct ARP_entry*)lua_touserdata(L, 1), - (struct ARP_entry*)lua_touserdata(L, 2) + luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name), + luaL_checkudata(L, 2, syscalls_ARPEntry_metatable_name) ) ); diff --git a/src/debug.h b/src/debug.h index 2d4ce14..cb4335d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -21,4 +21,5 @@ #define DEBUG_LINE(msg) DEBUG_PRINT(msg); DEBUG_PRINT("\n") + #endif // __DEBUG_H__ diff --git a/src/debug/debug.c b/src/debug/debug.c new file mode 100644 index 0000000..28d46f5 --- /dev/null +++ b/src/debug/debug.c @@ -0,0 +1,195 @@ +#include +#include "debug.h" +#include "registers.h" + +int syscalls_DebugPuts(lua_State* L) +{ + _ksys_debug_puts(luaL_checkstring(L, 1)); + + return 0; +} + +int syscalls_DebugPutc(lua_State* L) +{ + _ksys_debug_putc(*luaL_checkstring(L, 1)); + + return 0; +} + +struct DebugMessageArea +{ + int Size; + int Used; + char data[]; +}; + +int syscalls_SetMessageArea(lua_State* L) +{ + struct DebugMessageArea* p = luaL_checkinteger(L, 1); + + asm_inline( + "int $0x40" + :: "a"(69), "b"(0), "c"(p) + ); + + return 0; +} + +int syscalls_GetRegisters(lua_State* L) +{ + struct registers* r = syscalls_pushRegisters(L); + + uint32_t pid = luaL_checkinteger(L, 1); + + asm_inline( + "int $0x40" + :: "a"(69), "b"(1), "c"(pid), "d"(sizeof(struct registers)), "S"(r) + ); + + return 1; +} + +int syscalls_SetRegisters(lua_State* L) +{ + uint32_t pid = luaL_checkinteger(L, 1); + struct registers* r = luaL_checkudata(L, 1, syscalls_registers_metatable_name); + + asm_inline( + "int $0x40" + :: "a"(69), "b"(2), "c"(pid), "d"(sizeof(struct registers)), "S"(r) + ); + + return 1; +} + +int syscalls_Disconnect(lua_State* L) +{ + uint32_t pid = luaL_checkinteger(L, 1); + + asm_inline( + "int $0x40" + :: "a"(69), "b"(3), "c"(pid) + ); + + return 1; +} + +int syscalls_Stop(lua_State* L) +{ + uint32_t pid = luaL_checkinteger(L, 1); + + asm_inline( + "int $0x40" + :: "a"(69), "b"(4), "c"(pid) + ); + + return 1; +} + +int syscalls_Continue(lua_State* L) +{ + uint32_t pid = luaL_checkinteger(L, 1); + + asm_inline( + "int $0x40" + :: "a"(69), "b"(5), "c"(pid) + ); + + return 1; +} + +int syscalls_ReadFromMem(lua_State* L) +{ + uint32_t pid = luaL_checkinteger(L, 1); + uint32_t bytes = luaL_checkinteger(L, 2); + uint32_t pointer = luaL_checkinteger(L, 3); + uint32_t buffer = luaL_checkinteger(L, 4); + uint32_t ret; + + asm_inline( + "int $0x40" + : "=a"(ret) + : "a"(69), "b"(6), "c"(pid), "d"(bytes), "S"(pointer), "D"(buffer) + ); + + if (ret == -1) + lua_pushnil(L); + else + lua_pushinteger(L, ret); + + return 1; +} + +int syscalls_WriteToMem(lua_State* L) +{ + uint32_t pid = luaL_checkinteger(L, 1); + uint32_t bytes = luaL_checkinteger(L, 2); + uint32_t pointer = luaL_checkinteger(L, 3); + uint32_t buffer = luaL_checkinteger(L, 4); + uint32_t ret; + + asm_inline( + "int $0x40" + : "=a"(ret) + : "a"(69), "b"(7), "c"(pid), "d"(bytes), "S"(pointer), "D"(buffer) + ); + + if (ret == -1) + lua_pushnil(L); + else + lua_pushinteger(L, ret); + + return 1; +} + +int syscalls_Done(lua_State* L) +{ + uint32_t pid = luaL_checkinteger(L, 1); + + asm_inline( + "int $0x40" + :: "a"(69), "b"(8), "c"(pid) + ); + + return 1; +} + +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) | (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; + + asm_inline( + "int $0x40" + : "=a"(ret) + : "a"(69), "b"(9), "c"(pid), "d"(flags) + ); + + lua_pushinteger(L, ret); + + return 1; +} diff --git a/src/debug/debug.h b/src/debug/debug.h new file mode 100644 index 0000000..5102b7a --- /dev/null +++ b/src/debug/debug.h @@ -0,0 +1,46 @@ +#ifndef __DEBUG_LUA_H__ +#define __DEBUG_LUA_H__ + +#include "../syscalls.h" + +enum BreakpointCondition +{ + Execute = 0, + Write = 1, + ReadWrite = 0b11 +}; + +enum BreakpointLen +{ + Byte = 0, + Word = 1, + Dword = 0b11 +}; + +int syscalls_DebugPutc(lua_State* L); + +int syscalls_DebugPuts(lua_State* L); + +int syscalls_SetMessageArea(lua_State* L); + +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 new file mode 100644 index 0000000..f153e05 --- /dev/null +++ b/src/debug/registers.c @@ -0,0 +1,147 @@ +#include "registers.h" +#include "../syscalls.h" +#include +#include "../debug.h" + +static int syscalls_indexRegisters(lua_State* L) +{ + struct registers* r = luaL_checkudata(L, 1, syscalls_registers_metatable_name); + const char* index = luaL_checkstring(L, 2); + + if (strcmp(index, "eax") == 0) + { + lua_pushinteger(L, r->eax); + } + else if (strcmp(index, "ebx") == 0) + { + lua_pushinteger(L, r->ebx); + } + else if (strcmp(index, "esp") == 0) + { + lua_pushinteger(L, r->esp); + } + else if (strcmp(index, "esi") == 0) + { + lua_pushinteger(L, r->esi); + } + else if (strcmp(index, "edi") == 0) + { + lua_pushinteger(L, r->edi); + } + else if (strcmp(index, "eip") == 0) + { + lua_pushinteger(L, r->eip); + } + else if (strcmp(index, "eflags") == 0) + { + lua_pushinteger(L, r->eflags); + } + else + { + lua_pushnil(L); + } + + return 1; +} + +static int syscalls_newindexRegisters(lua_State* L) +{ + struct registers* r = luaL_checkudata(L, 1, syscalls_registers_metatable_name); + const char* index = luaL_checkstring(L, 2); + uint32_t val = luaL_checkinteger(L, 3); + + if (strcmp(index, "eax") == 0) + { + r->eax = val; + } + else if (strcmp(index, "ebx") == 0) + { + r->ebx = val; + } + else if (strcmp(index, "esp") == 0) + { + r->esp = val; + } + else if (strcmp(index, "esi") == 0) + { + r->esi = val; + } + else if (strcmp(index, "edi") == 0) + { + r->edi = val; + } + else if (strcmp(index, "eip") == 0) + { + r->eip = val; + } + else if (strcmp(index, "eflags") == 0) + { + r->eflags = val; + } + else + { + luaL_error(L, "wrong index: %s", index); + } + + return 1; +} + +static int syscalls_eqRegisters(lua_State* L) +{ + lua_pushboolean( + L, + memcmp( + luaL_checkudata(L, 1, syscalls_registers_metatable_name), + luaL_checkudata(L, 2, syscalls_registers_metatable_name), + sizeof(struct registers) + ) + ); + + return 1; +} + +static const luaL_Reg syscalls_registers_m[] = { + {"__index", syscalls_indexRegisters}, + {"__newindex", syscalls_newindexRegisters}, + {"__eq", syscalls_eqRegisters}, + {NULL, NULL} +}; + +struct registers* syscalls_pushRegisters(lua_State* L) +{ + DEBUG_LINE("push registers entry"); + + struct registers* entry = lua_newuserdata(L, sizeof(struct registers)); + + luaL_setmetatable(L, syscalls_registers_metatable_name); + + return entry; +} + +static int syscalls_newRegisters(lua_State* L) +{ + struct registers* r = syscalls_pushRegisters(L); + memset(r, 0, sizeof(struct registers)); + + return 1; +} + +static const luaL_Reg syscalls_registers_lib[] = { + {"new", syscalls_newRegisters}, + {NULL, NULL} +}; + +void syscalls_register_registers(lua_State* L) +{ + DEBUG_LINE("register registers entry"); + + luaL_newlib(L, syscalls_registers_lib); + + lua_setfield(L, -2, syscalls_registers_name); + + + luaL_newmetatable(L, syscalls_registers_metatable_name); + luaL_setfuncs(L, syscalls_registers_m, 0); + + lua_pop(L, 1); +} diff --git a/src/debug/registers.h b/src/debug/registers.h new file mode 100644 index 0000000..e5dbd16 --- /dev/null +++ b/src/debug/registers.h @@ -0,0 +1,25 @@ +#ifndef __REGISTERS_H__ +#define __REGISTERS_H__ + +#include "../syscalls.h" + +struct registers +{ + uint32_t eip; + uint32_t eflags; + uint32_t eax; + uint32_t ebx; + uint32_t esp; + uint32_t esi; + uint32_t edi; + char zero[12]; +}; + +#define syscalls_registers_name "Registers table" +#define syscalls_registers_metatable_name "Registers metatable" + +struct registers* syscalls_pushRegisters(lua_State* L); + +inline void syscalls_register_registers(lua_State* L); + +#endif // __REGISTERS_H__ diff --git a/src/graphic.c b/src/graphic.c new file mode 100644 index 0000000..a6ee6ec --- /dev/null +++ b/src/graphic.c @@ -0,0 +1,208 @@ +#include "graphic.h" +#include "debug.h" + +/* + Кеш размера экрана. + + Нужно для того чтобы не вызывать систменое прерывание лишний раз (другие функции тоже используют это значение) + + Сомневаюсь что в размер экрана в колибри вообще может меняться без перезагрузки + + обновляется функцией syscalls_updateScreenSize +*/ +static ksys_pos_t syscalls_screenSizeCache = { 0 }; + +inline void syscalls_updateScreenSize() +{ + syscalls_screenSizeCache = _ksys_screen_size(); +} + +int syscalls_drawLine(lua_State* L) +{ + _ksys_draw_line( + luaL_checkinteger(L, 1), + luaL_checkinteger(L, 2), + luaL_checkinteger(L, 3), + luaL_checkinteger(L, 4), + luaL_checkinteger(L, 5)); + + return 0; +} + +static inline void drawText(char* text, uint32_t x, uint32_t y, ksys_color_t color, size_t len, uint64_t backgroundColor) +{ + if (backgroundColor < (1 << 32)) + color |= (1 << 30); + + if (len == 0) + color |= (1 << 31); + + asm_inline( + "int $0x40" + ::"a"(4), + "b"((x << 16) | y), + "c"(color), + "d"(text), + "S"(len), + "D"((uint32_t)backgroundColor)); +} + + +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_ + { + cp866_6x9 = 0, + cp866_8x16 = 1 + }; + + enum scale + { + scale_x1 = 0, + scale_x2 = 1, + scale_x3 = 2, + scale_x4 = 3, + scale_x5 = 4, + scale_x6 = 5, + scale_x7 = 6, + scale_x8 = 7 + }; + + color &= 0x00ffffff; + + switch (size) + { + case TextScale_SIZE_6x9: + color |= (cp866_6x9 << 28) | (scale_x1 << 24); + break; + case TextScale_SIZE_8x16: + color |= (encoding << 28) | (scale_x1 << 24); + break; + case TextScale_SIZE_12x18: + color |= (cp866_6x9 << 28) | (scale_x2 << 24); + break; + case TextScale_SIZE_16x32: + color |= (encoding << 28) | (scale_x2 << 24); + break; + case TextScale_SIZE_18x27: + color |= (cp866_6x9 << 28) | (scale_x3 << 24); + break; + case TextScale_SIZE_24x36: + color |= (cp866_6x9 << 28) | (scale_x4 << 24); + break; + case TextScale_SIZE_24x48: + color |= (encoding << 28) | (scale_x3 << 24); + break; + case TextScale_SIZE_30x45: + color |= (cp866_6x9 << 28) | (scale_x5 << 24); + break; + case TextScale_SIZE_32x64: + color |= (encoding << 28) | (scale_x4 << 24); + break; + case TextScale_SIZE_36x54: + color |= (cp866_6x9 << 28) | (scale_x6 << 24); + break; + case TextScale_SIZE_40x80: + color |= (encoding << 28) | (scale_x5 << 24); + break; + case TextScale_SIZE_42x63: + color |= (cp866_6x9 << 28) | (scale_x7 << 24); + break; + case TextScale_SIZE_48x72: + color |= (cp866_6x9 << 28) | (scale_x8 << 24); + break; + case TextScale_SIZE_48x96: + color |= (encoding << 28) | (scale_x6 << 24); + break; + case TextScale_SIZE_56x112: + color |= (encoding << 28) | (scale_x7 << 24); + break; + case TextScale_SIZE_64x128: + color |= (encoding << 28) | (scale_x8 << 24); + break; + default: + _ksys_debug_puts("Unknown size"); + break; + }; + + drawText(text, x, y, color, len, backgroundColor); +} + +int syscalls_drawText(lua_State* L) +{ + 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) +{ + drawTextFixSize( + luaL_checkstring(L, 1), + luaL_checkinteger(L, 2), + luaL_checkinteger(L, 3), + luaL_checkinteger(L, 4), + luaL_optinteger(L, 5, TextScale_SIZE_8x16), + luaL_optinteger(L, 6, 0), + luaL_optinteger(L, 7, 1 << 32), + luaL_optinteger(L, 8, DEFAULT_ENCODING) + ); + + return 0; +} + +int syscalls_drawRectangle(lua_State* L) +{ + _ksys_draw_bar( + luaL_checkinteger(L, 1), + luaL_checkinteger(L, 2), + luaL_checkinteger(L, 3), + luaL_checkinteger(L, 4), + luaL_checkinteger(L, 5)); + + return 0; +} + +int syscalls_ReadPoint(lua_State* L) +{ + ksys_color_t color; + + if (syscalls_screenSizeCache.val == 0) + syscalls_updateScreenSize(); + + uint32_t x = luaL_checkinteger(L, 1); + uint32_t y = luaL_checkinteger(L, 2); + + asm_inline( + "int $ 0x40" + : "=a"(color) + : "a"(35), "b"(x * syscalls_screenSizeCache.x + y)); + + lua_pushinteger(L, color); + + return 1; +} + +int syscalls_screenSize(lua_State* L) +{ + syscalls_updateScreenSize(); + + lua_createtable(L, 0, 2); + + lua_pushinteger(L, syscalls_screenSizeCache.x); + lua_setfield(L, -2, "x"); + + lua_pushinteger(L, syscalls_screenSizeCache.y); + lua_setfield(L, -2, "y"); + + return 1; +} diff --git a/src/graphic.h b/src/graphic.h new file mode 100644 index 0000000..84574a2 --- /dev/null +++ b/src/graphic.h @@ -0,0 +1,120 @@ +#ifndef __GRAPHIC_H__ +#define __GRAPHIC_H__ + +#include +#include "syscalls.h" + +enum TextScale +{ + TextScale_SIZE_6x9, // 1x 6x9 + TextScale_SIZE_8x16, // 1x 8x16 + TextScale_SIZE_12x18, // 2x 6x9 + TextScale_SIZE_16x32, // 2x 8x16 + TextScale_SIZE_18x27, // 3x 6x9 + TextScale_SIZE_24x36, // 4x 6x9 + TextScale_SIZE_24x48, // 3x 8x16 + TextScale_SIZE_30x45, // 5x 6x9 + TextScale_SIZE_32x64, // 4x 8x16 + TextScale_SIZE_36x54, // 6x 6x9 + TextScale_SIZE_40x80, // 5x 8x16 + TextScale_SIZE_42x63, // 7x 6x9 + TextScale_SIZE_48x72, // 8x 6x9 + TextScale_SIZE_48x96, // 6x 8x16 + TextScale_SIZE_56x112, // 7x 8x16 + TextScale_SIZE_64x128 // 8x 8x16 +}; + +enum DrawTextEncoding +{ + cp866 = 1, + cp866_8x16 = 2, + utf8 = 3, + utf16 = 4 +}; + +#define DEFAULT_ENCODING cp866 + +int syscalls_drawLine(lua_State* L); +int syscalls_drawText(lua_State* L); +int syscalls_drawTextFixSize(lua_State* L); +int syscalls_drawRectangle(lua_State* L); +int syscalls_ReadPoint(lua_State* L); +int syscalls_screenSize(lua_State* L); + +inline void syscalls_push_textSizes(lua_State* L) +{ + lua_newtable(L); + + lua_pushinteger(L, TextScale_SIZE_6x9); + lua_setfield(L, -2, "6x9"); + + lua_pushinteger(L, TextScale_SIZE_8x16); + lua_setfield(L, -2, "8x16"); + + lua_pushinteger(L, TextScale_SIZE_12x18); + lua_setfield(L, -2, "12x18"); + + lua_pushinteger(L, TextScale_SIZE_16x32); + lua_setfield(L, -2, "16x32"); + + lua_pushinteger(L, TextScale_SIZE_18x27); + lua_setfield(L, -2, "18x27"); + + lua_pushinteger(L, TextScale_SIZE_24x36); + lua_setfield(L, -2, "24x36"); + + lua_pushinteger(L, TextScale_SIZE_24x48); + lua_setfield(L, -2, "24x48"); + + lua_pushinteger(L, TextScale_SIZE_30x45); + lua_setfield(L, -2, "30x45"); + + lua_pushinteger(L, TextScale_SIZE_32x64); + lua_setfield(L, -2, "32x64"); + + lua_pushinteger(L, TextScale_SIZE_36x54); + lua_setfield(L, -2, "36x54"); + + lua_pushinteger(L, TextScale_SIZE_40x80); + lua_setfield(L, -2, "40x80"); + + lua_pushinteger(L, TextScale_SIZE_42x63); + lua_setfield(L, -2, "42x63"); + + lua_pushinteger(L, TextScale_SIZE_48x72); + lua_setfield(L, -2, "48x72"); + + lua_pushinteger(L, TextScale_SIZE_48x96); + lua_setfield(L, -2, "48x96"); + + lua_pushinteger(L, TextScale_SIZE_56x112); + lua_setfield(L, -2, "56x112"); + + lua_pushinteger(L, TextScale_SIZE_64x128); + lua_setfield(L, -2, "64x128"); + + lua_setfield(L, -2, "textSize"); +} + +inline void syscalls_push_Encoding(lua_State* L) +{ + lua_newtable(L); + + lua_pushinteger(L, cp866); + lua_setfield(L, -2, "cp866"); + + lua_pushinteger(L, cp866_8x16); + lua_setfield(L, -2, "cp866_8x16"); + + lua_pushinteger(L, utf8); + lua_setfield(L, -2, "utf8"); + + lua_pushinteger(L, utf16); + lua_setfield(L, -2, "utf16"); + + lua_setfield(L, -2, "Encoding"); +} + +#define syscalls_push_graphic(L) syscalls_push_textSizes(L); syscalls_push_Encoding(L); + +#endif // __GRAPHIC_H__ diff --git a/src/sockets/optstruct.c b/src/sockets/optstruct.c new file mode 100644 index 0000000..e69de29 diff --git a/src/sockets/sockaddr.c b/src/sockets/sockaddr.c new file mode 100644 index 0000000..6e2b1ec --- /dev/null +++ b/src/sockets/sockaddr.c @@ -0,0 +1,49 @@ +#include "sockaddr.h" +#include "../debug.h" + +struct sockaddr* syscalls_push_sockaddr(lua_State* L) +{ + DEBUG_LINE("push sockaddr struct"); + + struct sockaddr* colorsTable = lua_newuserdata(L, sizeof(struct sockaddr)); + luaL_setmetatable(L, syscalls_sockaddr_metatable_name); + + return colorsTable; +} + +static int syscalls_sockaddr_new(lua_State* L) +{ + struct sockaddr* add = syscalls_push_sockaddr(L); + + add->sin_addr = luaL_checkinteger(L, 1); + add->sin_family = luaL_checkinteger(L, 1); + add->sin_port = luaL_checkinteger(L, 1); + + return 1; +} + +static int syscalls_sockaddr_tonumber(lua_State* L) +{ + lua_pushinteger(L, luaL_checkudata(L, 1, syscalls_sockaddr_metatable_name)); + return 1; +} + +static const luaL_Reg syscalls_sockaddr_m[] = { + {"__tonumber", syscalls_sockaddr_tonumber}, + {NULL, NULL} +}; + +static const luaL_Reg syscalls_sockaddr_lib[] = { + {NULL, NULL} +}; + +void syscalls_register_sockaddr(lua_State* L) +{ + luaL_newlib(L, syscalls_sockaddr_lib); + lua_setfield(L, -2, "SystemColors"); + + luaL_newmetatable(L, syscalls_sockaddr_metatable_name); + luaL_setfuncs(L, syscalls_sockaddr_m, 0); + + lua_pop(L, 1); +} diff --git a/src/sockets/sockaddr.h b/src/sockets/sockaddr.h new file mode 100644 index 0000000..d69f6cc --- /dev/null +++ b/src/sockets/sockaddr.h @@ -0,0 +1,12 @@ +#ifndef __SOCKADDR_H__ +#define __SOCKADDR_H__ + +#include "../syscalls.h" +#include "socket.h" + +#define syscalls_sockaddr_metatable_name "sockaddr metatable" + +void syscalls_register_sockaddr(lua_State* L); +struct sockaddr* syscalls_push_sockaddr(lua_State* L); + +#endif // __SOCKADDR_H__ \ No newline at end of file diff --git a/src/sockets/socket.c b/src/sockets/socket.c new file mode 100644 index 0000000..ab5099a --- /dev/null +++ b/src/sockets/socket.c @@ -0,0 +1,155 @@ +#include "socket.h" + +static void _conv_socket_err() { + switch (errno) { + case 1: errno = ENOBUFS; break; + case 2: errno = EINPROGRESS; break; + case 4: errno = EOPNOTSUPP; break; + case 6: errno = EWOULDBLOCK; break; + case 9: errno = ENOTCONN; break; + case 10: errno = EALREADY; break; + case 11: errno = EINVAL; break; + case 12: errno = EMSGSIZE; break; + case 18: errno = ENOMEM; break; + case 20: errno = EADDRINUSE; break; + case 61: errno = ECONNREFUSED; break; + case 52: errno = ECONNRESET; break; + case 56: errno = EISCONN; break; + case 60: errno = ETIMEDOUT; break; + case 54: errno = ECONNABORTED; break; + default: errno = 0; break; + } +} + +int socket(int domain, int type, int protocol) +{ + int socket; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(socket) + : "a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol) + ); + _conv_socket_err(); + return socket; +} + +int close(int socket) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + : "a"(75), "b"(1), "c"(socket) + ); + _conv_socket_err(); + return status; +} + +int bind(int socket, const struct sockaddr* addres, int addres_len) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + : "a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len) + ); + _conv_socket_err(); + return status; +} + +int listen(int socket, int backlog) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + : "a"(75), "b"(3), "c"(socket), "d"(backlog) + ); + _conv_socket_err(); + return status; +} + +int connect(int socket, const struct sockaddr* address, int socket_len) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + : "a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len) + ); + _conv_socket_err(); + return status; +} + +int accept(int socket, const struct sockaddr* address, int address_len) +{ + int new_socket; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(new_socket) + : "a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len) + ); + _conv_socket_err(); + return new_socket; +} + +int send(int socket, const void* message, size_t msg_len, int flag) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + : "a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag) + ); + _conv_socket_err(); + return status; +} + +int recv(int socket, void* buffer, size_t buff_len, int flag) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + : "a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag) + ); + _conv_socket_err(); + return status; +} + +int setsockopt(int socket, const optstruct* opt) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + : "a"(75), "b"(8), "c"(socket), "d"(opt) + ); + _conv_socket_err(); + return status; +} + +int getsockopt(int socket, optstruct* opt) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + : "a"(75), "b"(9), "c"(socket), "d"(opt) + ); + _conv_socket_err(); + return status; +} + +int socketpair(int* socket1, int* socket2) +{ + asm_inline( + "int $0x40" + :"=b"(*socket2), "=a"(*socket1) + : "a"(75), "b"(10) + ); + errno = *socket2; + _conv_socket_err(); + return *socket1; +} + diff --git a/src/sockets/socket.h b/src/sockets/socket.h new file mode 100644 index 0000000..12cfe3b --- /dev/null +++ b/src/sockets/socket.h @@ -0,0 +1,91 @@ +/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv2 */ + +#ifndef _SOCKET_H_ +#define _SOCKET_H_ + +#include +#include +#include + +// Socket Types +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 +#define SOCK_RAW 3 + +// IP protocols +#define IPPROTO_IP 0 +#define IPPROTO_ICMP 1 +#define IPPROTO_TCP 6 +#define IPPROTO_UDP 17 +#define IPPROTO_RAW 255 + +// IP options +#define IP_TTL 2 + +// Address families +#define AF_UNSPEC 0 +#define AF_LOCAL 1 +#define AF_INET 2 // Default INET=IPv4 +#define AF_INET4 2 // IPv4 +#define AF_INET6 10 // IPv6 + +#define PF_UNSPEC AF_UNSPEC +#define PF_LOCAL AF_LOCAL +#define PF_INET4 AF_INET4 +#define PF_INET6 AF_INET6 + +// internal definition +#define AI_SUPPORTED 0x40F + +// for system function 76 +#define API_ETH (0 << 16) +#define API_IPv4 (1 << 16) +#define API_ICMP (2 << 16) +#define API_UDP (3 << 16) +#define API_TCP (4 << 16) +#define API_ARP (5 << 16) +#define API_PPPOE (6 << 16) + +// Socket flags for user calls +#define MSG_NOFLAG 0 +#define MSG_PEEK 0x02 +#define MSG_DONTWAIT 0x40 + +// Socket levels +#define SOL_SOCKET 0xffff + +// Socket options +#define SO_BINDTODEVICE (1 << 9) +#define SO_NONBLOCK (1 << 31) + +#define PORT(X) (X << 8) + +#pragma pack(push, 1) +struct sockaddr { + unsigned short sin_family; + unsigned short sin_port; + unsigned int sin_addr; + unsigned long long sin_zero; +}; + +typedef struct { + unsigned int level; + unsigned int optionname; + unsigned int optlenght; + unsigned char options; +} optstruct; +#pragma pack(pop) + +int socket(int domain, int type, int protocol); +int close(int socket); +int bind(int socket, const struct sockaddr* addres, int addres_len); +int listen(int socket, int backlog); +int connect(int socket, const struct sockaddr* address, int socket_len); +int accept(int socket, const struct sockaddr* address, int address_len); +int send(int socket, const void* message, size_t msg_len, int flag); +int recv(int socket, void* buffer, size_t buff_len, int flag); +int setsockopt(int socket, const optstruct* opt); +int getsockopt(int socket, optstruct* opt); +int socketpair(int* socket1, int* socket2); + +#endif //_SOCKET_H_ diff --git a/src/sockets/socket_lua.c b/src/sockets/socket_lua.c new file mode 100644 index 0000000..ac07853 --- /dev/null +++ b/src/sockets/socket_lua.c @@ -0,0 +1,246 @@ +#include +#include "socket_lua.h" +#include "socket.h" + +int syscalls_OpenSocket(lua_State* L) +{ + int socketNum = socket( + luaL_checkinteger(L, 1), + luaL_checkinteger(L, 2), + luaL_checkinteger(L, 3) + ); + + if (socketNum != -1) + { + lua_pushnumber(L, socketNum); // Push socketNum + lua_pushnil(L); // Push error code + } + else + { + lua_pushnil(L); // Push socketNum + lua_pushnumber(L, errno); // Push error Code + } + + return 2; +} + +int syscalls_CloseSocket(lua_State* L) +{ + int ret = close(luaL_checkinteger(L, 1)); + + syscalls_ReturnIntegerValueOrNil(ret, errno, L); + + return 1; +} + +int syscalls_Bind(lua_State* L) +{ + int ret = bind( + luaL_checkinteger(L, 1), + luaL_checkinteger(L, 2), + sizeof(struct sockaddr) + ); + + syscalls_ReturnIntegerValueOrNil(ret, errno, L); + + return 1; +} + +int syscalls_Listen(lua_State* L) +{ + int ret = listen( + luaL_checkinteger(L, 1), + luaL_checkinteger(L, 2) + ); + + syscalls_ReturnIntegerValueOrNil(ret, errno, L); + + return 1; +} + +int syscalls_Connect(lua_State* L) +{ + int ret = connect( + luaL_checkinteger(L, 1), + luaL_checkinteger(L, 2), + sizeof(struct sockaddr) + ); + + syscalls_ReturnIntegerValueOrNil(ret, errno, L); + + return 1; +} + +int syscalls_Accept(lua_State* L) +{ + int ret = accept( + luaL_checkinteger(L, 1), + luaL_checkinteger(L, 2), + sizeof(struct sockaddr) + ); + + syscalls_ReturnIntegerValueOrNil(ret, errno, L); + + return 1; +} + +int syscalls_Send(lua_State* L) +{ + int ret = send( + luaL_checkinteger(L, 1), + luaL_checkinteger(L, 2), + luaL_checkinteger(L, 3), + luaL_checkinteger(L, 4) + ); + + syscalls_ReturnIntegerValueOrNil(ret, errno, L); + + return 1; +} + +int syscalls_Receive(lua_State* L) +{ + int ret = recv( + luaL_checkinteger(L, 1), + luaL_checkinteger(L, 2), + luaL_checkinteger(L, 3), + luaL_checkinteger(L, 4) + ); + + syscalls_ReturnIntegerValueOrNil(ret, errno, L); + + return 1; +} + + +int syscalls_SetSocketOption(lua_State* L) +{ + int ret = setsockopt(luaL_checkinteger(L, 1), luaL_checkinteger(L, 2)); + + syscalls_ReturnIntegerValueOrNil(ret, errno, L); + + return 1; +} + +int syscalls_GetSocketOption(lua_State* L) +{ + int ret = getsockopt(luaL_checkinteger(L, 1), luaL_checkinteger(L, 2)); + + syscalls_ReturnIntegerValueOrNil(ret, errno, L); + + return 1; +} + +int syscalls_PairSocket(lua_State* L) +{ + int firstSocketNum; + int secondSocketNum; + + int ret = socketpair(&firstSocketNum, &secondSocketNum); + + if (ret == -1) + { + lua_pushnil(L); + lua_pushinteger(L, errno); + } + else + { + lua_pushinteger(L, firstSocketNum); + lua_pushinteger(L, secondSocketNum); + } + + return 2; +} + +inline static void syscalls_socket_types(lua_State* L) +{ + lua_createtable(L, 0, 0); + + lua_pushinteger(L, SOCK_STREAM); + lua_setfield(L, -2, "STREAM"); + + lua_pushinteger(L, SOCK_RAW); + lua_setfield(L, -2, "RAW"); + + lua_pushinteger(L, SOCK_DGRAM); + lua_setfield(L, -2, "DGRAM"); + + lua_setfield(L, -2, "SOCK"); +} + +inline static void syscalls_socket_ipproto(lua_State* L) +{ + lua_createtable(L, 0, 0); + + + lua_pushinteger(L, IPPROTO_IP); + lua_setfield(L, -2, "IP"); + + lua_pushinteger(L, IPPROTO_ICMP); + lua_setfield(L, -2, "ICMP"); + + lua_pushinteger(L, IPPROTO_TCP); + lua_setfield(L, -2, "TCP"); + + lua_pushinteger(L, IPPROTO_UDP); + lua_setfield(L, -2, "UDP"); + + lua_pushinteger(L, IPPROTO_RAW); + lua_setfield(L, -2, "RAW"); + + lua_setfield(L, -2, "IPPROTO"); +} + +inline static void syscalls_socket_ip(lua_State* L) +{ + lua_createtable(L, 0, 0); + + lua_pushinteger(L, IP_TTL); + lua_setfield(L, -2, "TTL"); + + lua_setfield(L, -2, "IP"); +} + +inline static void syscalls_socket_AF(lua_State* L) +{ + lua_createtable(L, 0, 0); + + lua_pushinteger(L, AF_UNSPEC); + lua_setfield(L, -2, "UNSCPEC"); + + lua_pushinteger(L, AF_LOCAL); + lua_setfield(L, -2, "LOCAL"); + + lua_pushinteger(L, AF_INET); + lua_setfield(L, -2, "INET"); + + lua_pushinteger(L, AF_INET4); + lua_setfield(L, -2, "INET4"); + + lua_pushinteger(L, AF_INET6); + lua_setfield(L, -2, "INET6"); + + lua_setfield(L, -2, "AF"); +} + +inline static void syscalls_socket_options(lua_State* L) +{ + lua_createtable(L, 0, 0); + + lua_pushinteger(L, SO_BINDTODEVICE); + lua_setfield(L, -2, "BINDTODEVICE"); + + lua_pushinteger(L, SO_NONBLOCK); + lua_setfield(L, -2, "NONBLOCK"); + + lua_setfield(L, -2, "SO"); +} + +void syscalls_register_socket(lua_State* L) +{ + syscalls_socket_types(L); + syscalls_socket_ipproto(L); + syscalls_socket_ip(L); + syscalls_socket_AF(L); + syscalls_socket_options(L); +} diff --git a/src/sockets/socket_lua.h b/src/sockets/socket_lua.h new file mode 100644 index 0000000..ac30041 --- /dev/null +++ b/src/sockets/socket_lua.h @@ -0,0 +1,21 @@ +#ifndef __SOCKET_H__ +#define __SOCKET_H__ + +#include "../syscalls.h" + +int syscalls_OpenSocket(lua_State* L); +int syscalls_CloseSocket(lua_State* L); +int syscalls_Bind(lua_State* L); +int syscalls_Listen(lua_State* L); +int syscalls_Connect(lua_State* L); +int syscalls_Accept(lua_State* L); +int syscalls_Send(lua_State* L); +int syscalls_Receive(lua_State* L); +int syscalls_SetSocketOption(lua_State* L); +int syscalls_GetSocketOption(lua_State* L); +int syscalls_PairSocket(lua_State* L); + +void syscalls_register_socket(lua_State* L); + + +#endif // __SOCKET_H__ diff --git a/src/syscalls.c b/src/syscalls.c index e548e98..3855795 100644 --- a/src/syscalls.c +++ b/src/syscalls.c @@ -2,20 +2,19 @@ syscalls */ -#include -#include -#include - #include #include #include +#include "syscalls.h" #include "scancodes.h" #include "ARP_entry.h" #include "systemColors.h" - +#include "sockets/socket_lua.h" +#include "debug/debug.h" +#include "graphic.h" /* @@ -25,73 +24,6 @@ */ static ksys_key_input_mode_t syscalls_KeyInputState = KSYS_KEY_INPUT_MODE_ASCII; -/* - Кеш размера экрана. - - Нужно для того чтобы не вызывать систменое прерывание лишний раз (другие функции тоже используют это значение) - - Сомневаюсь что в размер экрана в колибри вообще может меняться без перезагрузки - - обновляется функцией syscalls_updateScreenSize -*/ -static ksys_pos_t syscalls_screenSizeCache = { 0 }; - - -/* - функции для того чтобы возвращаемые значения функций были болле-мение едиообразны -*/ - - -inline void syscalls_ReturnIntegerOrNil(LUA_INTEGER value, lua_State* L) -{ - if (value == -1) - { - lua_pushnil(L); - } - else - { - lua_pushinteger(L, value); - } -} - -inline void syscalls_ReturnIntegerValueOrNil(LUA_INTEGER cond, LUA_INTEGER value, lua_State* L) -{ - if (cond == -1) - { - lua_pushnil(L); - } - else - { - lua_pushinteger(L, value); - } -} - -inline void syscalls_ReturnTrueOrNil(LUA_INTEGER value, lua_State* L) -{ - if (value == -1) - { - lua_pushnil(L); - } - else - { - lua_pushboolean(L, true); - } -} - -inline void syscalls_ReturnStringOrNil(LUA_INTEGER cond, const char* value, lua_State* L) -{ - if (cond == -1) - { - lua_pushnil(L); - } - else - { - lua_pushstring(L, value); - } -} - - - static int syscalls_createWindow(lua_State* L) { @@ -106,6 +38,7 @@ static int syscalls_createWindow(lua_State* L) { uint32_t borderColor = luaL_checkinteger(L, 5); uint32_t titleColor = luaL_checkinteger(L, 8); + asm_inline( "int $0x40" ::"a"(0), "b"((x << 16) | ((w - 1) & 0xFFFF)), @@ -287,6 +220,23 @@ static int syscalls_drawPixel(lua_State* L) return 0; } +static int syscalls_WindowMsg(lua_State* L) +{ + int event = luaL_checkinteger(L, 1); + int code = luaL_checkinteger(L, 2); + int ret; + + asm_inline( + "int $0x40" + :"=a"(ret) + : "a"(72), "b"(1), "c"(event), "d"(code) + ); + + syscalls_ReturnTrueOrNil(ret, L); + + return 1; +} + static int syscalls_threadInfo(lua_State* L) { ksys_thread_t t; @@ -447,25 +397,6 @@ static int syscalls_getButton(lua_State* L) return 2; } -static void syscalls_updateScreenSize() -{ - syscalls_screenSizeCache = _ksys_screen_size(); -} - -static int syscalls_screenSize(lua_State* L) -{ - syscalls_updateScreenSize(); - - lua_createtable(L, 0, 2); - - lua_pushinteger(L, syscalls_screenSizeCache.x); - lua_setfield(L, -2, "x"); - - lua_pushinteger(L, syscalls_screenSizeCache.y); - lua_setfield(L, -2, "y"); - - return 1; -} /* Backgound @@ -505,173 +436,7 @@ static int syscalls_getCPUClock(lua_State* L) return 1; } -static int syscalls_drawLine(lua_State* L) -{ - _ksys_draw_line( - luaL_checkinteger(L, 1), - luaL_checkinteger(L, 2), - luaL_checkinteger(L, 3), - luaL_checkinteger(L, 4), - luaL_checkinteger(L, 5)); - return 0; -} - -enum TextScale -{ - TextScale_SIZE_6x9, // 1x 6x9 - TextScale_SIZE_8x16, // 1x 8x16 - TextScale_SIZE_12x18, // 2x 6x9 - TextScale_SIZE_16x32, // 2x 8x16 - TextScale_SIZE_18x27, // 3x 6x9 - TextScale_SIZE_24x36, // 4x 6x9 - TextScale_SIZE_24x48, // 3x 8x16 - TextScale_SIZE_30x45, // 5x 6x9 - TextScale_SIZE_32x64, // 4x 8x16 - TextScale_SIZE_36x54, // 6x 6x9 - TextScale_SIZE_40x80, // 5x 8x16 - TextScale_SIZE_42x63, // 7x 6x9 - TextScale_SIZE_48x72, // 8x 6x9 - TextScale_SIZE_48x96, // 6x 8x16 - TextScale_SIZE_56x112, // 7x 8x16 - TextScale_SIZE_64x128 // 8x 8x16 -}; - -static void syscall_drawText(const char* text, uint32_t x, uint32_t y, ksys_color_t color, enum TextScale size, uint32_t len, bool fillBackground, ksys_color_t backgroundColor) -{ - enum DrawTextEncoding - { - cp866_6x9 = 0, - cp866_8x16 = 1, - utf8 = 3, - utf16 = 4 - }; - - enum scale - { - scale_x1 = 0, - scale_x2 = 1, - scale_x3 = 2, - scale_x4 = 3, - scale_x5 = 4, - scale_x6 = 5, - scale_x7 = 6, - scale_x8 = 7 - }; - - color &= 0x00FFFFFF; - - color |= (fillBackground << 30); - - switch (size) - { - case TextScale_SIZE_6x9: - color |= (cp866_8x16 << 28) | (scale_x1 << 24); - break; - case TextScale_SIZE_8x16: - color |= (cp866_8x16 << 28); - break; - case TextScale_SIZE_12x18: - color |= (cp866_6x9 << 28) | (scale_x2 << 24); - break; - case TextScale_SIZE_16x32: - color |= (cp866_8x16 << 28) | (scale_x2 << 24); - break; - case TextScale_SIZE_18x27: - color |= (cp866_6x9 << 28) | (scale_x3 << 24); - break; - case TextScale_SIZE_24x36: - color |= (cp866_6x9 << 28) | (scale_x4 << 24); - break; - case TextScale_SIZE_24x48: - color |= (cp866_8x16 << 28) | (scale_x3 << 24); - break; - case TextScale_SIZE_30x45: - color |= (cp866_6x9 << 28) | (scale_x5 << 24); - break; - case TextScale_SIZE_36x54: - color |= (cp866_6x9 << 28) | (scale_x6 << 24); - break; - case TextScale_SIZE_40x80: - color |= (cp866_8x16 << 28) | (scale_x5 << 24); - break; - case TextScale_SIZE_42x63: - color |= (cp866_6x9 << 28) | (scale_x7 << 24); - break; - case TextScale_SIZE_48x72: - color |= (cp866_6x9 << 28) | (scale_x8 << 24); - break; - case TextScale_SIZE_48x96: - color |= (cp866_8x16 << 28) | (scale_x6 << 24); - break; - case TextScale_SIZE_56x112: - color |= (cp866_8x16 << 28) | (scale_x7 << 24); - break; - case TextScale_SIZE_64x128: - color |= (cp866_8x16 << 28) | (scale_x8 << 24); - break; - default: - break; - }; - - if (len <= 0) - color |= (1 << 31); - - asm_inline( - "int $0x40" ::"a"(4), - "b"((x << 16) | y), - "c"(color), - "d"(text), - "S"(len), - "D"(backgroundColor)); -} - -static int syscalls_drawText(lua_State* L) -{ - syscall_drawText( - luaL_checkstring(L, 1), - luaL_checkinteger(L, 2), - luaL_checkinteger(L, 3), - luaL_checkinteger(L, 4), - luaL_optinteger(L, 5, TextScale_SIZE_8x16), - luaL_optinteger(L, 6, 0), - luaL_optinteger(L, 7, 0), - luaL_optinteger(L, 8, 0)); - - return 0; -} - -static int syscalls_drawRectangle(lua_State* L) -{ - _ksys_draw_bar( - luaL_checkinteger(L, 1), - luaL_checkinteger(L, 2), - luaL_checkinteger(L, 3), - luaL_checkinteger(L, 4), - luaL_checkinteger(L, 5)); - - return 0; -} - -static int syscalls_ReadPoint(lua_State* L) -{ - ksys_color_t color; - - if (syscalls_screenSizeCache.val == 0) - syscalls_updateScreenSize(); - - uint32_t x = luaL_checkinteger(L, 1); - uint32_t y = luaL_checkinteger(L, 2); - - asm_inline( - "int $ 0x40" - : "=a"(color) - : "a"(35), "b"(x * syscalls_screenSizeCache.x + y)); - - lua_pushnumber(L, color); - - return 1; -} static int syscalls_getSystemColors(lua_State* L) { @@ -684,7 +449,7 @@ static int syscalls_getSystemColors(lua_State* L) static int syscalls_SetSystemColors(lua_State* L) { - ksys_colors_table_t* t = (ksys_colors_table_t*)lua_touserdata(L, 1); + ksys_colors_table_t* t = (ksys_colors_table_t*)luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name); asm_inline( "int $0x40" ::"a"(48), "b"(2), "c"(t), "d"(40)); @@ -1637,17 +1402,25 @@ static int syscalls_ReadARPEntries(lua_State* L) return 1; } +/** + * Return ARP entry + */ static int syscalls_ReadARPEntry(lua_State* L) { uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); uint32_t entryNum = luaL_checkinteger(L, 2); - struct ARP_entry* buffer = syscalls_pushARPEntry(L); + struct ARP_entry buffer; asm_inline( "int $0x40" : "=a"(eax) - : "a"(76), "b"((ARP << 24) | (device << 8) | 3), "c"(entryNum), "D"(buffer)); + : "a"(76), "b"((ARP << 24) | (device << 8) | 3), "c"(entryNum), "D"(&buffer)); + + if (eax == -1) + lua_pushnil(L); + else + memcpy(syscalls_pushARPEntry(L), &buffer, sizeof(struct ARP_entry)); return 1; } @@ -1657,7 +1430,7 @@ static int syscalls_AddARPEntry(lua_State* L) uint32_t eax; uint8_t device = luaL_checkinteger(L, 1); uint32_t entryNum = luaL_checkinteger(L, 2); - struct ARP_entry* buffer = (struct ARP_entry*)lua_touserdata(L, 3); + struct ARP_entry* buffer = (struct ARP_entry*)luaL_checkudata(L, 3, syscalls_ARPEntry_metatable_name); asm_inline( "int $0x40" @@ -1715,211 +1488,6 @@ static int syscalls_ReadARPConflicts(lua_State* L) return 1; } -/* Сокеты */ - -static int syscalls_OpenSocket(lua_State* L) -{ - int32_t socketNum; - uint32_t errorCode; - - uint32_t family = luaL_checkinteger(L, 1); - uint32_t type = luaL_checkinteger(L, 2); - uint32_t protocol = luaL_checkinteger(L, 3); - - asm_inline( - "int $0x40" - :"=a"(socketNum), "=b"(errorCode) - : "a"(77), "b"(0), "c"(family), "d"(type), "S"(protocol) - ); - - if (socketNum == -1) - { - lua_pushnil(L); // Push socketNum - lua_pushnumber(L, socketNum); // Push error Code - } - else - { - lua_pushnumber(L, socketNum); // Push socketNum - lua_pushnil(L); // Push error code - } - - return 2; -} - -static int syscalls_CloseSocket(lua_State* L) -{ - uint32_t eax; - uint32_t errorCode; - uint32_t socketNum = luaL_checkinteger(L, 1); - - asm_inline( - "int $0x40" - : "=a"(eax), "=b"(errorCode) - : "a"(77), "b"(1), "c"(socketNum)); - - syscalls_ReturnIntegerValueOrNil(eax, errorCode, L); - - return 1; -} - -static int syscalls_Bind(lua_State* L) -{ - uint32_t eax; - uint32_t errorCode; - - uint32_t socketNum = luaL_checkinteger(L, 1); - uint32_t sockaddr = luaL_checkinteger(L, 2); - uint32_t sockaddrLen = luaL_checkinteger(L, 3); - - asm_inline( - "int $0x40" - : "=a"(eax), "=b"(errorCode) - : "a"(77), "b"(2), "c"(socketNum), "d"(sockaddr), "S"(sockaddrLen)); - - syscalls_ReturnIntegerValueOrNil(eax, errorCode, L); - - return 1; -} - -static int syscalls_Listen(lua_State* L) -{ - uint32_t eax; - uint32_t errorCode; - - uint32_t socketNum = luaL_checkinteger(L, 1); - uint32_t backlog = luaL_checkinteger(L, 2); - - asm_inline( - "int $0x40" - : "=a"(eax), "=b"(errorCode) - : "a"(77), "b"(3), "c"(socketNum), "d"(backlog)); - - syscalls_ReturnIntegerValueOrNil(eax, errorCode, L); - - return 1; -} - -static int syscalls_Connect(lua_State* L) -{ - uint32_t eax; - uint32_t errorCode; - - uint32_t socketNum = luaL_checkinteger(L, 1); - uint32_t sockaddr = luaL_checkinteger(L, 2); - uint32_t sockaddrLen = luaL_checkinteger(L, 3); - - asm_inline( - "int $0x40" - : "=a"(eax), "=b"(errorCode) - : "a"(77), "b"(4), "c"(socketNum), "d"(sockaddr), "S"(sockaddrLen)); - - syscalls_ReturnIntegerValueOrNil(eax, errorCode, L); - - return 1; -} - -static int syscalls_Accept(lua_State* L) -{ - uint32_t eax; - uint32_t errorCode; - - uint32_t socketNum = luaL_checkinteger(L, 1); - uint32_t sockaddr = luaL_checkinteger(L, 2); - uint32_t sockaddrLen = luaL_checkinteger(L, 3); - - asm_inline( - "int $0x40" - : "=a"(eax), "=b"(errorCode) - : "a"(77), "b"(5), "c"(socketNum), "d"(sockaddr), "S"(sockaddrLen)); - - syscalls_ReturnIntegerValueOrNil(eax, errorCode, L); - - return 1; -} - -static int syscalls_Send(lua_State* L) -{ - uint32_t eax; - uint32_t errorCode; - - uint32_t socketNum = luaL_checkinteger(L, 1); - uint32_t buffer = luaL_checkinteger(L, 2); - uint32_t bufferLen = luaL_checkinteger(L, 3); - uint32_t flags = luaL_checkinteger(L, 4); - - asm_inline( - "int $0x40" - : "=a"(eax), "=b"(errorCode) - : "a"(77), "b"(6), "c"(socketNum), "d"(buffer), "S"(bufferLen), "D"(flags)); - - syscalls_ReturnIntegerValueOrNil(eax, errorCode, L); - - return 1; -} - -static int syscalls_Receive(lua_State* L) -{ - uint32_t eax; - uint32_t errorCode; - - uint32_t socketNum = luaL_checkinteger(L, 1); - uint32_t buffer = luaL_checkinteger(L, 2); - uint32_t bufferLen = luaL_checkinteger(L, 3); - uint32_t flags = luaL_checkinteger(L, 4); - - asm_inline( - "int $0x40" - : "=a"(eax), "=b"(errorCode) - : "a"(77), "b"(7), "c"(socketNum), "d"(buffer), "S"(bufferLen), "D"(flags)); - - syscalls_ReturnIntegerValueOrNil(eax, errorCode, L); - - return 1; -} - -static int syscalls_GetSocketOptions(lua_State* L) -{ - uint32_t eax; - uint32_t errorCode; - - uint32_t socketNum = luaL_checkinteger(L, 1); - uint32_t optstruct = luaL_checkinteger(L, 2); - - asm_inline( - "int $0x40" - : "=a"(eax), "=b"(errorCode) - : "a"(77), "b"(8), "c"(socketNum), "d"(optstruct)); - - syscalls_ReturnIntegerValueOrNil(eax, errorCode, L); - - return 1; -} - -static int syscalls_GetPairSocket(lua_State* L) -{ - int32_t firstSocketNum; - uint32_t secondSocketNum; - - asm_inline( - "int $0x40" - : "=a"(firstSocketNum), "=b"(secondSocketNum) - : "a"(77), "b"(9)); - - if (firstSocketNum == -1) - { - lua_pushnil(L); - lua_pushinteger(L, secondSocketNum); - } - else - { - lua_pushinteger(L, firstSocketNum); - lua_pushinteger(L, secondSocketNum); - } - - return 2; -} - - /* ** functions for 'syscalls' library */ @@ -1965,11 +1533,12 @@ static const luaL_Reg syscallsLib[] = { {"DrawLine", syscalls_drawLine}, {"DrawPixel", syscalls_drawPixel}, {"DrawText", syscalls_drawText}, + {"DrawTextFixSize", syscalls_drawTextFixSize}, {"DrawRectangle", syscalls_drawRectangle}, {"ReadPoint", syscalls_ReadPoint}, /* keyboard funcs */ {"SetKeyInputMode", syscalls_setKeyInputMode}, - {"GetKeyInputMouse", syscalls_getKeyInputMode}, + {"GetKeyInputMode", syscalls_getKeyInputMode}, {"getKey", syscalls_getKey}, {"getControlKeyState", syscalls_getControlKeyState}, {"SetHotkey", syscalls_SetHotkey}, @@ -2050,9 +1619,25 @@ static const luaL_Reg syscallsLib[] = { {"Accept", syscalls_Accept}, {"Send", syscalls_Send}, {"Receive", syscalls_Receive}, - {"GetSocketOptions", syscalls_GetSocketOptions}, - {"GetPairSocket", syscalls_GetPairSocket}, - {NULL, NULL} }; + { "SetSocketOption", syscalls_SetSocketOption }, + { "GetSocketOption", syscalls_GetSocketOption }, + {"PairSocket", syscalls_PairSocket}, + /* Debug */ + {"DebugPuts", syscalls_DebugPuts}, + { "DebugPutc", syscalls_DebugPutc }, + {"SetMessageArea", syscalls_SetMessageArea}, + { "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) { @@ -2235,60 +1820,7 @@ static inline void syscalls_push_connectionStatus(lua_State* L) lua_setfield(L, -2, "connectionStatus"); } -inline void syscalls_push_textSizes(lua_State* L) -{ - lua_newtable(L); - lua_pushinteger(L, TextScale_SIZE_6x9); - lua_setfield(L, -2, "6x9"); - - lua_pushinteger(L, TextScale_SIZE_8x16); - lua_setfield(L, -2, "8x16"); - - lua_pushinteger(L, TextScale_SIZE_12x18); - lua_setfield(L, -2, "12x18"); - - lua_pushinteger(L, TextScale_SIZE_16x32); - lua_setfield(L, -2, "16x32"); - - lua_pushinteger(L, TextScale_SIZE_18x27); - lua_setfield(L, -2, "18x27"); - - lua_pushinteger(L, TextScale_SIZE_24x36); - lua_setfield(L, -2, "24x36"); - - lua_pushinteger(L, TextScale_SIZE_24x48); - lua_setfield(L, -2, "24x48"); - - lua_pushinteger(L, TextScale_SIZE_30x45); - lua_setfield(L, -2, "30x45"); - - lua_pushinteger(L, TextScale_SIZE_32x64); - lua_setfield(L, -2, "32x64"); - - lua_pushinteger(L, TextScale_SIZE_36x54); - lua_setfield(L, -2, "36x54"); - - lua_pushinteger(L, TextScale_SIZE_40x80); - lua_setfield(L, -2, "40x80"); - - lua_pushinteger(L, TextScale_SIZE_42x63); - lua_setfield(L, -2, "42x63"); - - lua_pushinteger(L, TextScale_SIZE_48x72); - lua_setfield(L, -2, "48x72"); - - lua_pushinteger(L, TextScale_SIZE_48x96); - lua_setfield(L, -2, "48x96"); - - lua_pushinteger(L, TextScale_SIZE_56x112); - lua_setfield(L, -2, "56x112"); - - lua_pushinteger(L, TextScale_SIZE_64x128); - lua_setfield(L, -2, "64x128"); - - lua_setfield(L, -2, "textSize"); -} LUALIB_API int luaopen_syscalls(lua_State* L) { @@ -2302,7 +1834,7 @@ LUALIB_API int luaopen_syscalls(lua_State* L) syscalls_push_windowStyles(L); syscalls_push_buttons(L); syscalls_push_connectionStatus(L); - syscalls_push_textSizes(L); + syscalls_push_graphic(L); syscalls_register_ARPEntry(L); syscalls_register_SystemColors(L); diff --git a/src/syscalls.h b/src/syscalls.h new file mode 100644 index 0000000..0888c58 --- /dev/null +++ b/src/syscalls.h @@ -0,0 +1,56 @@ +#ifndef __SYSCALLS_H__ +#define __SYSCALLS_H__ + +#include +#include +#include + +inline void syscalls_ReturnIntegerOrNil(LUA_INTEGER value, lua_State* L) +{ + if (value == -1) + { + lua_pushnil(L); + } + else + { + lua_pushinteger(L, value); + } +} + +inline void syscalls_ReturnIntegerValueOrNil(LUA_INTEGER cond, LUA_INTEGER value, lua_State* L) +{ + if (cond == -1) + { + lua_pushnil(L); + } + else + { + lua_pushinteger(L, value); + } +} + +inline void syscalls_ReturnTrueOrNil(LUA_INTEGER value, lua_State* L) +{ + if (value == -1) + { + lua_pushnil(L); + } + else + { + lua_pushboolean(L, 1); + } +} + +inline void syscalls_ReturnStringOrNil(LUA_INTEGER cond, const char* value, lua_State* L) +{ + if (cond == -1) + { + lua_pushnil(L); + } + else + { + lua_pushstring(L, value); + } +} + +#endif // __SYSCALLS_H__ diff --git a/src/systemColors.c b/src/systemColors.c index e9ef6ee..7502449 100644 --- a/src/systemColors.c +++ b/src/systemColors.c @@ -3,9 +3,6 @@ #include #include - -static int syscalls_SystemColors_m_index; - int syscalls_newSystemColors(lua_State* L) { ksys_colors_table_t* colorsTable = syscalls_pushSystemColors(L); @@ -44,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); } @@ -100,7 +97,7 @@ static int syscalls_newindexSystemColors(lua_State* L) { t->grab_bar_button = val; } - else if (strcmp("grab_button_text", index) == 0) + else if (strcmp("grabButtonText", index) == 0) { t->grab_button_text = val; } diff --git a/src/systemColors.h b/src/systemColors.h index a7ea281..bad5c67 100644 --- a/src/systemColors.h +++ b/src/systemColors.h @@ -1,9 +1,7 @@ #ifndef _SYSCALLS_SYSTEM_COLORS_H_ #define _SYSCALLS_SYSTEM_COLORS_H_ -#include -#include -#include +#include "syscalls.h" #include #define syscalls_SystemColors_metatable_name "syscalls SystemColors metatable" diff --git a/tests/SystemColors.lua b/tests/SystemColors.lua index 0e98b08..7b03c37 100644 --- a/tests/SystemColors.lua +++ b/tests/SystemColors.lua @@ -4,6 +4,29 @@ local SystemColors = syscalls.GetSystemColors() print(SystemColors) -for i, v in pairs(SystemColors) do - print(i, v) +function DEC_HEX(IN) + local B, K, OUT, I, D = 16, "0123456789ABCDEF", "", 0 + while IN > 0 do + I = I + 1 + IN, D = math.floor(IN / B), math.mod(IN, B) + 1 + OUT = string.sub(K, D, D) .. OUT + end + return OUT +end + +local keys = { + "frameArea", + "workArea", + "grabBar", + "grabBarButton", + "grabButtonText", + "grabText", + "workButton", + "workButtonText", + "workGraph", + "workText" +} + +for _, v in pairs(keys) do + print(v .. ':', "#" .. DEC_HEX(SystemColors[v])) end diff --git a/tests/helloWorld.lua b/tests/helloWorld.lua new file mode 100644 index 0000000..e01b07d --- /dev/null +++ b/tests/helloWorld.lua @@ -0,0 +1,40 @@ +local syscalls = require("syscalls") + +local systemColors = syscalls.GetSystemColors() + + + +local function redraw() + syscalls.StartRedraw() + + syscalls.CreateWindow(100, 100, 200, 200, "Hello World", systemColors.workArea, 3) + + local t = syscalls.ThreadInfo(-1) + + + local y = syscalls.GetSkinHeight() + for i, v in pairs(syscalls.textSize) do + local a = string.gmatch(i, "(%d+)")() + syscalls.DrawTextFixSize("HelloWorld " .. i, math.floor(t.winXSize / 8), y, systemColors.workText, v) + y = y + tonumber(a) + 24 + end + + syscalls.EndRedraw() +end + +redraw() + +local exit = false +while not exit do + local event = syscalls.WaitEvent() + + if event == syscalls.Event.Redraw then + redraw() + elseif event == syscalls.Event.Button then + local ButtonID = syscalls.GetButton() + + if ButtonID == syscalls.buttons.close then + exit = true + end + end +end diff --git a/tests/libraryStruct.lua b/tests/libraryStruct.lua index f279934..9cdb514 100644 --- a/tests/libraryStruct.lua +++ b/tests/libraryStruct.lua @@ -1,3 +1,10 @@ -for i, v in pairs(require("syscalls")) do - print(i, v) + +local function tree(t) + for i, v in pairs(t) do + if type(v) == "table" then + tree(v) + end + end end + +tree(require("syscalls"))