feat: port lua scripting language
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#ifndef _LIBC_DIRENT_H
|
||||
#define _LIBC_DIRENT_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NAME_MAX 255
|
||||
#define DT_UNKNOWN 0
|
||||
#define DT_DIR 4
|
||||
#define DT_REG 8
|
||||
|
||||
struct dirent {
|
||||
unsigned char d_type;
|
||||
char d_name[NAME_MAX + 1];
|
||||
};
|
||||
|
||||
typedef struct _DIR DIR;
|
||||
|
||||
DIR *opendir(const char *name);
|
||||
struct dirent *readdir(DIR *dirp);
|
||||
int closedir(DIR *dirp);
|
||||
void rewinddir(DIR *dirp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LIBC_DIRENT_H */
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef _LIBC_LOCALE_H
|
||||
#define _LIBC_LOCALE_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LC_ALL 0
|
||||
#define LC_COLLATE 1
|
||||
#define LC_CTYPE 2
|
||||
#define LC_MONETARY 3
|
||||
#define LC_NUMERIC 4
|
||||
#define LC_TIME 5
|
||||
|
||||
struct lconv {
|
||||
char *decimal_point;
|
||||
};
|
||||
|
||||
char *setlocale(int category, const char *locale);
|
||||
struct lconv *localeconv(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LIBC_LOCALE_H */
|
||||
@@ -12,18 +12,37 @@ extern "C" {
|
||||
#define NAN __builtin_nanf("")
|
||||
|
||||
double fabs(double x);
|
||||
double frexp(double x, int *exp);
|
||||
double ldexp(double x, int n);
|
||||
long double ldexpl(long double x, int n);
|
||||
double floor(double x);
|
||||
double ceil(double x);
|
||||
double sqrt(double x);
|
||||
double sin(double x);
|
||||
double cos(double x);
|
||||
double tan(double x);
|
||||
double asin(double x);
|
||||
double acos(double x);
|
||||
double atan(double x);
|
||||
double atan2(double y, double x);
|
||||
double pow(double base, double exp);
|
||||
double log(double x);
|
||||
double log2(double x);
|
||||
double log10(double x);
|
||||
double exp(double x);
|
||||
double fmod(double x, double y);
|
||||
double sinh(double x);
|
||||
double cosh(double x);
|
||||
double tanh(double x);
|
||||
double round(double x);
|
||||
|
||||
float floorf(float x);
|
||||
float ceilf(float x);
|
||||
float fabsf(float x);
|
||||
float sqrtf(float x);
|
||||
float sinf(float x);
|
||||
float cosf(float x);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,605 @@
|
||||
/*
|
||||
* montauk.h
|
||||
* MontaukOS C API for user programs (TCC-compatible)
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*
|
||||
* Usage: #include <montauk.h>
|
||||
*
|
||||
* Provides direct access to all MontaukOS system calls from C.
|
||||
* This header is self-contained and does not depend on C++ headers.
|
||||
*/
|
||||
|
||||
#ifndef _MONTAUK_H
|
||||
#define _MONTAUK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ====================================================================
|
||||
Syscall numbers
|
||||
==================================================================== */
|
||||
|
||||
#define MTK_SYS_EXIT 0
|
||||
#define MTK_SYS_YIELD 1
|
||||
#define MTK_SYS_SLEEP_MS 2
|
||||
#define MTK_SYS_GETPID 3
|
||||
#define MTK_SYS_PRINT 4
|
||||
#define MTK_SYS_PUTCHAR 5
|
||||
#define MTK_SYS_OPEN 6
|
||||
#define MTK_SYS_READ 7
|
||||
#define MTK_SYS_GETSIZE 8
|
||||
#define MTK_SYS_CLOSE 9
|
||||
#define MTK_SYS_READDIR 10
|
||||
#define MTK_SYS_ALLOC 11
|
||||
#define MTK_SYS_FREE 12
|
||||
#define MTK_SYS_GETTICKS 13
|
||||
#define MTK_SYS_GETMILLISECONDS 14
|
||||
#define MTK_SYS_GETINFO 15
|
||||
#define MTK_SYS_ISKEYAVAILABLE 16
|
||||
#define MTK_SYS_GETKEY 17
|
||||
#define MTK_SYS_GETCHAR 18
|
||||
#define MTK_SYS_PING 19
|
||||
#define MTK_SYS_SPAWN 20
|
||||
#define MTK_SYS_WAITPID 23
|
||||
#define MTK_SYS_TERMSIZE 24
|
||||
#define MTK_SYS_GETARGS 25
|
||||
#define MTK_SYS_RESET 26
|
||||
#define MTK_SYS_SHUTDOWN 27
|
||||
#define MTK_SYS_GETTIME 28
|
||||
#define MTK_SYS_SOCKET 29
|
||||
#define MTK_SYS_CONNECT 30
|
||||
#define MTK_SYS_BIND 31
|
||||
#define MTK_SYS_LISTEN 32
|
||||
#define MTK_SYS_ACCEPT 33
|
||||
#define MTK_SYS_SEND 34
|
||||
#define MTK_SYS_RECV 35
|
||||
#define MTK_SYS_CLOSESOCK 36
|
||||
#define MTK_SYS_GETNETCFG 37
|
||||
#define MTK_SYS_SETNETCFG 38
|
||||
#define MTK_SYS_SENDTO 39
|
||||
#define MTK_SYS_RECVFROM 40
|
||||
#define MTK_SYS_FWRITE 41
|
||||
#define MTK_SYS_FCREATE 42
|
||||
#define MTK_SYS_TERMSCALE 43
|
||||
#define MTK_SYS_RESOLVE 44
|
||||
#define MTK_SYS_GETRANDOM 45
|
||||
#define MTK_SYS_KLOG 46
|
||||
#define MTK_SYS_MOUSESTATE 47
|
||||
#define MTK_SYS_SETMOUSEBOUNDS 48
|
||||
#define MTK_SYS_SPAWN_REDIR 49
|
||||
#define MTK_SYS_CHILDIO_READ 50
|
||||
#define MTK_SYS_CHILDIO_WRITE 51
|
||||
#define MTK_SYS_WINCREATE 54
|
||||
#define MTK_SYS_WINDESTROY 55
|
||||
#define MTK_SYS_WINPRESENT 56
|
||||
#define MTK_SYS_WINPOLL 57
|
||||
#define MTK_SYS_WINENUM 58
|
||||
#define MTK_SYS_WINMAP 59
|
||||
#define MTK_SYS_WINSENDEVENT 60
|
||||
#define MTK_SYS_PROCLIST 61
|
||||
#define MTK_SYS_KILL 62
|
||||
#define MTK_SYS_WINRESIZE 64
|
||||
#define MTK_SYS_WINSETSCALE 65
|
||||
#define MTK_SYS_WINGETSCALE 66
|
||||
#define MTK_SYS_MEMSTATS 67
|
||||
#define MTK_SYS_WINSETCURSOR 68
|
||||
#define MTK_SYS_FDELETE 77
|
||||
#define MTK_SYS_FMKDIR 78
|
||||
#define MTK_SYS_FRENAME 94
|
||||
#define MTK_SYS_DRIVELIST 79
|
||||
#define MTK_SYS_AUDIOOPEN 80
|
||||
#define MTK_SYS_AUDIOCLOSE 81
|
||||
#define MTK_SYS_AUDIOWRITE 82
|
||||
#define MTK_SYS_AUDIOCTL 83
|
||||
#define MTK_SYS_SETTZ 90
|
||||
#define MTK_SYS_GETTZ 91
|
||||
#define MTK_SYS_GETCWD 95
|
||||
#define MTK_SYS_CHDIR 96
|
||||
|
||||
#define MTK_SOCK_TCP 1
|
||||
#define MTK_SOCK_UDP 2
|
||||
|
||||
/* Window event types */
|
||||
#define MTK_EVENT_KEY 0
|
||||
#define MTK_EVENT_MOUSE 1
|
||||
#define MTK_EVENT_RESIZE 2
|
||||
#define MTK_EVENT_CLOSE 3
|
||||
#define MTK_EVENT_SCALE 4
|
||||
|
||||
/* Audio control commands */
|
||||
#define MTK_AUDIO_SET_VOLUME 0
|
||||
#define MTK_AUDIO_GET_VOLUME 1
|
||||
#define MTK_AUDIO_GET_POS 2
|
||||
#define MTK_AUDIO_PAUSE 3
|
||||
|
||||
/* ====================================================================
|
||||
Structures
|
||||
==================================================================== */
|
||||
|
||||
typedef struct {
|
||||
uint8_t scancode;
|
||||
char ascii;
|
||||
uint8_t pressed;
|
||||
uint8_t shift;
|
||||
uint8_t ctrl;
|
||||
uint8_t alt;
|
||||
} mtk_key_event;
|
||||
|
||||
typedef struct {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t scroll_delta;
|
||||
uint8_t buttons;
|
||||
} mtk_mouse_state;
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
uint8_t _pad[3];
|
||||
union {
|
||||
mtk_key_event key;
|
||||
struct { int32_t x, y, scroll; uint8_t buttons, prev_buttons; } mouse;
|
||||
struct { int32_t w, h; } resize;
|
||||
struct { int32_t scale; } scale;
|
||||
};
|
||||
} mtk_win_event;
|
||||
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
uint32_t _pad;
|
||||
uint64_t pixels; /* virtual address of pixel buffer (uint32_t*) */
|
||||
} mtk_win_result;
|
||||
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
int32_t owner_pid;
|
||||
char title[64];
|
||||
int32_t width, height;
|
||||
uint8_t dirty;
|
||||
uint8_t cursor;
|
||||
uint8_t _pad2[2];
|
||||
} mtk_win_info;
|
||||
|
||||
typedef struct {
|
||||
uint16_t year;
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
} mtk_datetime;
|
||||
|
||||
typedef struct {
|
||||
char os_name[32];
|
||||
char os_version[32];
|
||||
uint32_t api_version;
|
||||
uint32_t max_processes;
|
||||
} mtk_sysinfo;
|
||||
|
||||
typedef struct {
|
||||
uint64_t total_bytes;
|
||||
uint64_t free_bytes;
|
||||
uint64_t used_bytes;
|
||||
uint64_t page_size;
|
||||
} mtk_memstats;
|
||||
|
||||
typedef struct {
|
||||
uint32_t ip_address;
|
||||
uint32_t subnet_mask;
|
||||
uint32_t gateway;
|
||||
uint8_t mac_address[6];
|
||||
uint8_t _pad[2];
|
||||
uint32_t dns_server;
|
||||
} mtk_netcfg;
|
||||
|
||||
typedef struct {
|
||||
int32_t pid;
|
||||
int32_t parent_pid;
|
||||
uint8_t state; /* 0=Free, 1=Ready, 2=Running, 3=Terminated */
|
||||
uint8_t _pad[3];
|
||||
char name[64];
|
||||
uint64_t heap_used;
|
||||
} mtk_procinfo;
|
||||
|
||||
/* ====================================================================
|
||||
Raw syscall wrappers
|
||||
==================================================================== */
|
||||
|
||||
static inline long _mtk_syscall0(long nr) {
|
||||
long ret;
|
||||
__asm__ volatile("syscall" : "=a"(ret) : "a"(nr)
|
||||
: "rcx", "r11", "rdi", "rsi", "rdx", "r8", "r9", "r10", "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline long _mtk_syscall1(long nr, long a1) {
|
||||
long ret;
|
||||
__asm__ volatile(
|
||||
"mov %[a1], %%rdi\n\t"
|
||||
"syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(nr), [a1] "r"(a1)
|
||||
: "rcx", "r11", "rdi", "rsi", "rdx", "r8", "r9", "r10", "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline long _mtk_syscall2(long nr, long a1, long a2) {
|
||||
long ret;
|
||||
__asm__ volatile(
|
||||
"mov %[a1], %%rdi\n\t"
|
||||
"mov %[a2], %%rsi\n\t"
|
||||
"syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(nr), [a1] "r"(a1), [a2] "r"(a2)
|
||||
: "rcx", "r11", "rdi", "rsi", "rdx", "r8", "r9", "r10", "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline long _mtk_syscall3(long nr, long a1, long a2, long a3) {
|
||||
long ret;
|
||||
__asm__ volatile(
|
||||
"mov %[a1], %%rdi\n\t"
|
||||
"mov %[a2], %%rsi\n\t"
|
||||
"mov %[a3], %%rdx\n\t"
|
||||
"syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(nr), [a1] "r"(a1), [a2] "r"(a2), [a3] "r"(a3)
|
||||
: "rcx", "r11", "rdi", "rsi", "rdx", "r8", "r9", "r10", "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline long _mtk_syscall4(long nr, long a1, long a2, long a3, long a4) {
|
||||
long ret;
|
||||
__asm__ volatile(
|
||||
"mov %[a1], %%rdi\n\t"
|
||||
"mov %[a2], %%rsi\n\t"
|
||||
"mov %[a3], %%rdx\n\t"
|
||||
"mov %[a4], %%r10\n\t"
|
||||
"syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(nr), [a1] "r"(a1), [a2] "r"(a2), [a3] "r"(a3), [a4] "r"(a4)
|
||||
: "rcx", "r11", "rdi", "rsi", "rdx", "r8", "r9", "r10", "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline long _mtk_syscall5(long nr, long a1, long a2, long a3, long a4, long a5) {
|
||||
long ret;
|
||||
__asm__ volatile(
|
||||
"mov %[a1], %%rdi\n\t"
|
||||
"mov %[a2], %%rsi\n\t"
|
||||
"mov %[a3], %%rdx\n\t"
|
||||
"mov %[a4], %%r10\n\t"
|
||||
"mov %[a5], %%r8\n\t"
|
||||
"syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(nr), [a1] "r"(a1), [a2] "r"(a2), [a3] "r"(a3), [a4] "r"(a4), [a5] "r"(a5)
|
||||
: "rcx", "r11", "rdi", "rsi", "rdx", "r8", "r9", "r10", "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Process management
|
||||
==================================================================== */
|
||||
|
||||
static inline void mtk_exit(int code) {
|
||||
_mtk_syscall1(MTK_SYS_EXIT, (long)code);
|
||||
}
|
||||
|
||||
static inline void mtk_yield(void) {
|
||||
_mtk_syscall0(MTK_SYS_YIELD);
|
||||
}
|
||||
|
||||
static inline void mtk_sleep_ms(unsigned long ms) {
|
||||
_mtk_syscall1(MTK_SYS_SLEEP_MS, (long)ms);
|
||||
}
|
||||
|
||||
static inline int mtk_getpid(void) {
|
||||
return (int)_mtk_syscall0(MTK_SYS_GETPID);
|
||||
}
|
||||
|
||||
static inline int mtk_spawn(const char *path, const char *args) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_SPAWN, (long)path, (long)args);
|
||||
}
|
||||
|
||||
static inline void mtk_waitpid(int pid) {
|
||||
_mtk_syscall1(MTK_SYS_WAITPID, (long)pid);
|
||||
}
|
||||
|
||||
static inline int mtk_kill(int pid) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_KILL, (long)pid);
|
||||
}
|
||||
|
||||
static inline int mtk_proclist(mtk_procinfo *buf, int max) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_PROCLIST, (long)buf, (long)max);
|
||||
}
|
||||
|
||||
static inline int mtk_getargs(char *buf, unsigned long max_len) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_GETARGS, (long)buf, (long)max_len);
|
||||
}
|
||||
|
||||
static inline int mtk_chdir(const char *path) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_CHDIR, (long)path);
|
||||
}
|
||||
|
||||
static inline int mtk_getcwd(char *buf, unsigned long max_len) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_GETCWD, (long)buf, (long)max_len);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Console I/O
|
||||
==================================================================== */
|
||||
|
||||
static inline void mtk_print(const char *text) {
|
||||
_mtk_syscall1(MTK_SYS_PRINT, (long)text);
|
||||
}
|
||||
|
||||
static inline void mtk_putchar(char c) {
|
||||
_mtk_syscall1(MTK_SYS_PUTCHAR, (long)c);
|
||||
}
|
||||
|
||||
static inline char mtk_getchar(void) {
|
||||
return (char)_mtk_syscall0(MTK_SYS_GETCHAR);
|
||||
}
|
||||
|
||||
static inline int mtk_is_key_available(void) {
|
||||
return (int)_mtk_syscall0(MTK_SYS_ISKEYAVAILABLE);
|
||||
}
|
||||
|
||||
static inline void mtk_getkey(mtk_key_event *out) {
|
||||
_mtk_syscall1(MTK_SYS_GETKEY, (long)out);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
File I/O
|
||||
==================================================================== */
|
||||
|
||||
static inline int mtk_open(const char *path) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_OPEN, (long)path);
|
||||
}
|
||||
|
||||
static inline int mtk_read(int handle, uint8_t *buf, unsigned long offset, unsigned long size) {
|
||||
return (int)_mtk_syscall4(MTK_SYS_READ, (long)handle, (long)buf, (long)offset, (long)size);
|
||||
}
|
||||
|
||||
static inline int mtk_write(int handle, const uint8_t *buf, unsigned long offset, unsigned long size) {
|
||||
return (int)_mtk_syscall4(MTK_SYS_FWRITE, (long)handle, (long)buf, (long)offset, (long)size);
|
||||
}
|
||||
|
||||
static inline unsigned long mtk_getsize(int handle) {
|
||||
return (unsigned long)_mtk_syscall1(MTK_SYS_GETSIZE, (long)handle);
|
||||
}
|
||||
|
||||
static inline void mtk_close(int handle) {
|
||||
_mtk_syscall1(MTK_SYS_CLOSE, (long)handle);
|
||||
}
|
||||
|
||||
static inline int mtk_create(const char *path) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_FCREATE, (long)path);
|
||||
}
|
||||
|
||||
static inline int mtk_delete(const char *path) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_FDELETE, (long)path);
|
||||
}
|
||||
|
||||
static inline int mtk_mkdir(const char *path) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_FMKDIR, (long)path);
|
||||
}
|
||||
|
||||
static inline int mtk_rename(const char *oldpath, const char *newpath) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_FRENAME, (long)oldpath, (long)newpath);
|
||||
}
|
||||
|
||||
static inline int mtk_readdir(const char *path, const char **names, int max) {
|
||||
return (int)_mtk_syscall3(MTK_SYS_READDIR, (long)path, (long)names, (long)max);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Memory
|
||||
==================================================================== */
|
||||
|
||||
static inline void *mtk_alloc_pages(unsigned long bytes) {
|
||||
return (void *)_mtk_syscall1(MTK_SYS_ALLOC, (long)bytes);
|
||||
}
|
||||
|
||||
static inline void mtk_free_pages(void *ptr) {
|
||||
_mtk_syscall1(MTK_SYS_FREE, (long)ptr);
|
||||
}
|
||||
|
||||
static inline void mtk_get_memstats(mtk_memstats *out) {
|
||||
_mtk_syscall1(MTK_SYS_MEMSTATS, (long)out);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Timekeeping
|
||||
==================================================================== */
|
||||
|
||||
static inline unsigned long mtk_get_ticks(void) {
|
||||
return (unsigned long)_mtk_syscall0(MTK_SYS_GETTICKS);
|
||||
}
|
||||
|
||||
static inline unsigned long mtk_get_ms(void) {
|
||||
return (unsigned long)_mtk_syscall0(MTK_SYS_GETMILLISECONDS);
|
||||
}
|
||||
|
||||
static inline void mtk_gettime(mtk_datetime *out) {
|
||||
_mtk_syscall1(MTK_SYS_GETTIME, (long)out);
|
||||
}
|
||||
|
||||
static inline void mtk_settz(int offset_minutes) {
|
||||
_mtk_syscall1(MTK_SYS_SETTZ, (long)offset_minutes);
|
||||
}
|
||||
|
||||
static inline int mtk_gettz(void) {
|
||||
return (int)_mtk_syscall0(MTK_SYS_GETTZ);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
System info
|
||||
==================================================================== */
|
||||
|
||||
static inline void mtk_get_info(mtk_sysinfo *info) {
|
||||
_mtk_syscall1(MTK_SYS_GETINFO, (long)info);
|
||||
}
|
||||
|
||||
static inline long mtk_getrandom(void *buf, unsigned int len) {
|
||||
return _mtk_syscall2(MTK_SYS_GETRANDOM, (long)buf, (long)len);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Terminal
|
||||
==================================================================== */
|
||||
|
||||
static inline void mtk_termsize(int *cols, int *rows) {
|
||||
unsigned long r = (unsigned long)_mtk_syscall0(MTK_SYS_TERMSIZE);
|
||||
if (cols) *cols = (int)(r & 0xFFFFFFFF);
|
||||
if (rows) *rows = (int)(r >> 32);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Window server
|
||||
==================================================================== */
|
||||
|
||||
static inline int mtk_win_create(const char *title, int w, int h, mtk_win_result *result) {
|
||||
return (int)_mtk_syscall4(MTK_SYS_WINCREATE, (long)title, (long)w, (long)h, (long)result);
|
||||
}
|
||||
|
||||
static inline int mtk_win_destroy(int id) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_WINDESTROY, (long)id);
|
||||
}
|
||||
|
||||
static inline unsigned long mtk_win_present(int id) {
|
||||
return (unsigned long)_mtk_syscall1(MTK_SYS_WINPRESENT, (long)id);
|
||||
}
|
||||
|
||||
static inline int mtk_win_poll(int id, mtk_win_event *event) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_WINPOLL, (long)id, (long)event);
|
||||
}
|
||||
|
||||
static inline unsigned long mtk_win_resize(int id, int w, int h) {
|
||||
return (unsigned long)_mtk_syscall3(MTK_SYS_WINRESIZE, (long)id, (long)w, (long)h);
|
||||
}
|
||||
|
||||
static inline int mtk_win_enumerate(mtk_win_info *info, int max) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_WINENUM, (long)info, (long)max);
|
||||
}
|
||||
|
||||
static inline int mtk_win_setcursor(int id, int cursor) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_WINSETCURSOR, (long)id, (long)cursor);
|
||||
}
|
||||
|
||||
static inline int mtk_win_setscale(int scale) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_WINSETSCALE, (long)scale);
|
||||
}
|
||||
|
||||
static inline int mtk_win_getscale(void) {
|
||||
return (int)_mtk_syscall0(MTK_SYS_WINGETSCALE);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Mouse
|
||||
==================================================================== */
|
||||
|
||||
static inline void mtk_get_mouse(mtk_mouse_state *out) {
|
||||
_mtk_syscall1(MTK_SYS_MOUSESTATE, (long)out);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Networking
|
||||
==================================================================== */
|
||||
|
||||
static inline int mtk_socket(int type) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_SOCKET, (long)type);
|
||||
}
|
||||
|
||||
static inline int mtk_connect(int fd, uint32_t ip, uint16_t port) {
|
||||
return (int)_mtk_syscall3(MTK_SYS_CONNECT, (long)fd, (long)ip, (long)port);
|
||||
}
|
||||
|
||||
static inline int mtk_bind(int fd, uint16_t port) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_BIND, (long)fd, (long)port);
|
||||
}
|
||||
|
||||
static inline int mtk_listen(int fd) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_LISTEN, (long)fd);
|
||||
}
|
||||
|
||||
static inline int mtk_accept(int fd) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_ACCEPT, (long)fd);
|
||||
}
|
||||
|
||||
static inline int mtk_send(int fd, const void *data, uint32_t len) {
|
||||
return (int)_mtk_syscall3(MTK_SYS_SEND, (long)fd, (long)data, (long)len);
|
||||
}
|
||||
|
||||
static inline int mtk_recv(int fd, void *buf, uint32_t max_len) {
|
||||
return (int)_mtk_syscall3(MTK_SYS_RECV, (long)fd, (long)buf, (long)max_len);
|
||||
}
|
||||
|
||||
static inline int mtk_closesocket(int fd) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_CLOSESOCK, (long)fd);
|
||||
}
|
||||
|
||||
static inline uint32_t mtk_resolve(const char *hostname) {
|
||||
return (uint32_t)_mtk_syscall1(MTK_SYS_RESOLVE, (long)hostname);
|
||||
}
|
||||
|
||||
static inline int mtk_ping(uint32_t ip, uint32_t timeout_ms) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_PING, (long)ip, (long)timeout_ms);
|
||||
}
|
||||
|
||||
static inline void mtk_get_netcfg(mtk_netcfg *out) {
|
||||
_mtk_syscall1(MTK_SYS_GETNETCFG, (long)out);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Audio
|
||||
==================================================================== */
|
||||
|
||||
static inline int mtk_audio_open(uint32_t sample_rate, uint8_t channels, uint8_t bits) {
|
||||
return (int)_mtk_syscall3(MTK_SYS_AUDIOOPEN, (long)sample_rate, (long)channels, (long)bits);
|
||||
}
|
||||
|
||||
static inline void mtk_audio_close(int handle) {
|
||||
_mtk_syscall1(MTK_SYS_AUDIOCLOSE, (long)handle);
|
||||
}
|
||||
|
||||
static inline int mtk_audio_write(int handle, const void *data, uint32_t size) {
|
||||
return (int)_mtk_syscall3(MTK_SYS_AUDIOWRITE, (long)handle, (long)data, (long)size);
|
||||
}
|
||||
|
||||
static inline int mtk_audio_ctl(int handle, int cmd, int value) {
|
||||
return (int)_mtk_syscall3(MTK_SYS_AUDIOCTL, (long)handle, (long)cmd, (long)value);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Power management
|
||||
==================================================================== */
|
||||
|
||||
static inline void mtk_reset(void) {
|
||||
_mtk_syscall0(MTK_SYS_RESET);
|
||||
}
|
||||
|
||||
static inline void mtk_shutdown(void) {
|
||||
_mtk_syscall0(MTK_SYS_SHUTDOWN);
|
||||
}
|
||||
|
||||
/* ====================================================================
|
||||
Pixel helpers (for window server apps)
|
||||
==================================================================== */
|
||||
|
||||
static inline uint32_t mtk_rgb(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return 0xFF000000 | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||
}
|
||||
|
||||
static inline uint32_t mtk_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
return ((uint32_t)a << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _MONTAUK_H */
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef _LIBC_SETJMP_H
|
||||
#define _LIBC_SETJMP_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef unsigned long jmp_buf[8];
|
||||
|
||||
int setjmp(jmp_buf env);
|
||||
void longjmp(jmp_buf env, int val) __attribute__((noreturn));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LIBC_SETJMP_H */
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef _LIBC_SIGNAL_H
|
||||
#define _LIBC_SIGNAL_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int sig_atomic_t;
|
||||
typedef void (*sighandler_t)(int);
|
||||
|
||||
#define SIGINT 2
|
||||
|
||||
#define SIG_DFL ((sighandler_t)0)
|
||||
#define SIG_IGN ((sighandler_t)1)
|
||||
#define SIG_ERR ((sighandler_t)-1)
|
||||
|
||||
sighandler_t signal(int sig, sighandler_t handler);
|
||||
int raise(int sig);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LIBC_SIGNAL_H */
|
||||
@@ -16,6 +16,11 @@ extern "C" {
|
||||
#define SEEK_END 2
|
||||
#define BUFSIZ 1024
|
||||
#define FILENAME_MAX 256
|
||||
#define L_tmpnam 64
|
||||
#define TMP_MAX 10000
|
||||
#define _IOFBF 0
|
||||
#define _IOLBF 1
|
||||
#define _IONBF 2
|
||||
|
||||
typedef struct _FILE {
|
||||
int handle;
|
||||
@@ -50,6 +55,8 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||
int fseek(FILE *stream, long offset, int whence);
|
||||
long ftell(FILE *stream);
|
||||
int fflush(FILE *stream);
|
||||
FILE *freopen(const char *path, const char *mode, FILE *stream);
|
||||
int setvbuf(FILE *stream, char *buf, int mode, size_t size);
|
||||
|
||||
int rename(const char *oldpath, const char *newpath);
|
||||
int remove(const char *path);
|
||||
@@ -62,6 +69,7 @@ void clearerr(FILE *stream);
|
||||
|
||||
int fgetc(FILE *stream);
|
||||
int getc(FILE *stream);
|
||||
int fputc(int c, FILE *stream);
|
||||
int ungetc(int c, FILE *stream);
|
||||
char *fgets(char *s, int size, FILE *stream);
|
||||
int fputs(const char *s, FILE *stream);
|
||||
|
||||
@@ -44,12 +44,18 @@ void abort(void);
|
||||
int atexit(void (*func)(void));
|
||||
|
||||
char *getenv(const char *name);
|
||||
int setenv(const char *name, const char *value, int overwrite);
|
||||
int unsetenv(const char *name);
|
||||
int putenv(char *string);
|
||||
|
||||
void qsort(void *base, size_t nmemb, size_t size,
|
||||
int (*compar)(const void *, const void *));
|
||||
|
||||
long strtol(const char *nptr, char **endptr, int base);
|
||||
unsigned long strtoul(const char *nptr, char **endptr, int base);
|
||||
double strtod(const char *nptr, char **endptr);
|
||||
float strtof(const char *nptr, char **endptr);
|
||||
long double strtold(const char *nptr, char **endptr);
|
||||
|
||||
int rand(void);
|
||||
void srand(unsigned int seed);
|
||||
|
||||
@@ -16,6 +16,8 @@ int memcmp(const void *s1, const void *s2, size_t n);
|
||||
void *memchr(const void *s, int c, size_t n);
|
||||
|
||||
size_t strlen(const char *s);
|
||||
size_t strspn(const char *s, const char *accept);
|
||||
size_t strcspn(const char *s, const char *reject);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
int strncmp(const char *s1, const char *s2, size_t n);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
@@ -25,9 +27,12 @@ char *strncat(char *dest, const char *src, size_t n);
|
||||
char *strdup(const char *s);
|
||||
char *strchr(const char *s, int c);
|
||||
char *strrchr(const char *s, int c);
|
||||
char *strpbrk(const char *s, const char *accept);
|
||||
int strcasecmp(const char *s1, const char *s2);
|
||||
int strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
int strcoll(const char *s1, const char *s2);
|
||||
char *strstr(const char *haystack, const char *needle);
|
||||
const char *strerror(int errnum);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -3,14 +3,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define S_IFMT 0170000
|
||||
#define S_IFDIR 0040000
|
||||
#define S_IFREG 0100000
|
||||
|
||||
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
||||
|
||||
struct stat {
|
||||
mode_t st_mode;
|
||||
unsigned long st_size;
|
||||
time_t st_mtime;
|
||||
};
|
||||
|
||||
int mkdir(const char *path, unsigned int mode);
|
||||
|
||||
@@ -17,6 +17,8 @@ struct timezone {
|
||||
int tz_dsttime;
|
||||
};
|
||||
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef _LIBC_TIME_H
|
||||
#define _LIBC_TIME_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef long clock_t;
|
||||
|
||||
#define CLOCKS_PER_SEC 1000L
|
||||
|
||||
struct tm {
|
||||
int tm_sec;
|
||||
int tm_min;
|
||||
int tm_hour;
|
||||
int tm_mday;
|
||||
int tm_mon;
|
||||
int tm_year;
|
||||
int tm_wday;
|
||||
int tm_yday;
|
||||
int tm_isdst;
|
||||
};
|
||||
|
||||
clock_t clock(void);
|
||||
time_t time(time_t *tloc);
|
||||
double difftime(time_t time1, time_t time0);
|
||||
struct tm *gmtime(const time_t *timer);
|
||||
struct tm *localtime(const time_t *timer);
|
||||
time_t mktime(struct tm *tm);
|
||||
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LIBC_TIME_H */
|
||||
@@ -9,9 +9,21 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define F_OK 0
|
||||
#define X_OK 1
|
||||
#define W_OK 2
|
||||
#define R_OK 4
|
||||
|
||||
int read(int fd, void *buf, size_t count);
|
||||
int write(int fd, const void *buf, size_t count);
|
||||
int close(int fd);
|
||||
long lseek(int fd, long offset, int whence);
|
||||
int chdir(const char *path);
|
||||
char *getcwd(char *buf, size_t size);
|
||||
int access(const char *path, int mode);
|
||||
int isatty(int fd);
|
||||
|
||||
unsigned int sleep(unsigned int seconds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user