2022-04-06 16:37:19 +02:00
|
|
|
/*
|
|
|
|
sys/kos.h
|
|
|
|
An attempt to create new C/C++ wrapper for syscalls
|
|
|
|
Based on kos32sys.h
|
|
|
|
KolibriOS Team
|
|
|
|
*/
|
2021-02-24 10:25:50 +01:00
|
|
|
|
2021-02-24 09:40:54 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
/*********************** Types *************************/
|
2021-02-24 09:40:54 +01:00
|
|
|
typedef unsigned int color_t;
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
// struct for sysfn 70
|
2021-02-24 09:40:54 +01:00
|
|
|
#pragma pack(push,1)
|
2022-04-06 16:37:19 +02:00
|
|
|
typedef struct {
|
|
|
|
unsigned p00;
|
|
|
|
unsigned p04;
|
|
|
|
char *p08;
|
|
|
|
unsigned p12;
|
|
|
|
unsigned p16;
|
|
|
|
char p20;
|
|
|
|
char *p21;
|
2021-02-24 09:40:54 +01:00
|
|
|
} kos_Struct70;
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
// struct for blitter
|
|
|
|
struct blit_call {
|
2021-02-24 10:25:50 +01:00
|
|
|
int dstx;
|
|
|
|
int dsty;
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
int srcx;
|
|
|
|
int srcy;
|
|
|
|
int srcw;
|
|
|
|
int srch;
|
|
|
|
void *bitmap;
|
2022-04-06 16:37:19 +02:00
|
|
|
int stride;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
// struct for sysfn 9
|
2021-02-24 09:40:54 +01:00
|
|
|
#pragma pack(push, 1)
|
2022-04-06 16:37:19 +02:00
|
|
|
struct proc_info {
|
|
|
|
unsigned long cpu_usage;
|
|
|
|
unsigned short pos_in_stack;
|
|
|
|
unsigned short slot;
|
|
|
|
unsigned short reserved;
|
|
|
|
char name[12];
|
|
|
|
unsigned long address;
|
|
|
|
unsigned long memory_usage;
|
|
|
|
unsigned long ID;
|
|
|
|
unsigned long left,top;
|
|
|
|
unsigned long width,height;
|
|
|
|
unsigned short thread_state;
|
|
|
|
unsigned short reserved2;
|
|
|
|
unsigned long cleft, ctop, cwidth, cheight;
|
|
|
|
unsigned char window_state;
|
|
|
|
unsigned char reserved3[1024 - 71];
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
// struct for sysfn 48
|
2021-02-24 09:40:54 +01:00
|
|
|
struct kolibri_system_colors {
|
|
|
|
color_t frame_area;
|
|
|
|
color_t grab_bar;
|
|
|
|
color_t grab_bar_button;
|
|
|
|
color_t grab_button_text;
|
|
|
|
color_t grab_text;
|
|
|
|
color_t work_area;
|
|
|
|
color_t work_button;
|
|
|
|
color_t work_button_text;
|
|
|
|
color_t work_text;
|
|
|
|
color_t work_graph;
|
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
typedef union __attribute__((packed)) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t val;
|
2022-04-06 16:37:19 +02:00
|
|
|
struct {
|
|
|
|
short x;
|
|
|
|
short y;
|
2021-02-24 10:25:50 +01:00
|
|
|
};
|
2021-02-24 09:40:54 +01:00
|
|
|
} pos_t;
|
|
|
|
|
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
/*********************** Window Syscalls *************************/
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_BeginDraw(void) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40" ::"a"(12),"b"(1));
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_EndDraw(void) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40" ::"a"(12),"b"(2));
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_DrawWindow(int x, int y, int w, int h, const char *title, color_t bgcolor, uint32_t style) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(0),
|
|
|
|
"b"((x << 16) | ((w-1) & 0xFFFF)),
|
|
|
|
"c"((y << 16) | ((h-1) & 0xFFFF)),
|
|
|
|
"d"((style << 24) | (bgcolor & 0xFFFFFF)),
|
|
|
|
"D"(title),
|
|
|
|
"S"(0) : "memory");
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ZPOS_DESKTOP -2
|
|
|
|
#define ZPOS_ALWAYS_BACK -1
|
|
|
|
#define ZPOS_NORMAL 0
|
|
|
|
#define ZPOS_ALWAYS_TOP 1
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_SetWindowLayerBehaviour(int zpos) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(18),
|
|
|
|
"b"(25),
|
|
|
|
"c"(2),
|
|
|
|
"d"(-1),
|
|
|
|
"S"(zpos) : "memory");
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#define OLD -1
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_ChangeWindow(int new_x, int new_y, int new_w, int new_h) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
|
|
|
|
);
|
2021-02-24 09:40:54 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
/*********************** Other GUI functions *************************/
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_DrawText(int x, int y, const char *text, color_t color) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(4),"d"(text),
|
|
|
|
"b"((x << 16) | y),
|
|
|
|
"S"(strlen(text)),"c"(color)
|
|
|
|
:"memory");
|
2021-02-24 09:40:54 +01:00
|
|
|
}
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_DrawButton(int x, int y, int w, int h, int id, color_t color) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(8),
|
|
|
|
"b"(x * 65536 + w),
|
|
|
|
"c"(y * 65536 + h),
|
|
|
|
"d"(id),
|
|
|
|
"S"(color));
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_DrawButtonWithText(int x, int y, int w, int h, int id, color_t color, const char* text) {
|
2021-02-24 09:40:54 +01:00
|
|
|
kos_DrawButton(x, y, w, h, id, color);
|
|
|
|
|
|
|
|
int tx = ((((-strlen(text))*8)+w)/2)+x;
|
|
|
|
int ty = h/2-7+y;
|
|
|
|
|
|
|
|
kos_DrawText(tx, ty, text, 0x90000000);
|
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_DrawLine(int x_start, int y_start, int x_end, int y_end, color_t color) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(38), "d"(color),
|
|
|
|
"b"((x_start << 16) | x_end),
|
|
|
|
"c"((y_start << 16) | y_end));
|
2021-02-24 09:40:54 +01:00
|
|
|
}
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_DrawBar(int x, int y, int w, int h, color_t color) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(13), "d"(color),
|
|
|
|
"b"((x << 16) | w),
|
|
|
|
"c"((y << 16) | h));
|
2021-02-24 09:40:54 +01:00
|
|
|
}
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_PutPixel(int x, int y, color_t color) {
|
2021-02-24 09:40:54 +01:00
|
|
|
__asm__ __volatile__("int $0x40"
|
|
|
|
::"a"(1),
|
|
|
|
"b"(x),
|
|
|
|
"c"(y),
|
|
|
|
"d"(color));
|
|
|
|
}
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_DrawBitmap(void *bitmap, int x, int y, int w, int h) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(7), "b"(bitmap),
|
|
|
|
"c"((w << 16) | h),
|
|
|
|
"d"((x << 16) | y));
|
2021-02-24 09:40:54 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
static inline void Blit(void *bitmap, int dst_x, int dst_y,
|
|
|
|
int src_x, int src_y, int w, int h,
|
|
|
|
int src_w, int src_h, int stride)
|
|
|
|
{
|
|
|
|
volatile struct blit_call bc;
|
|
|
|
|
|
|
|
bc.dstx = dst_x;
|
|
|
|
bc.dsty = dst_y;
|
|
|
|
bc.w = w;
|
|
|
|
bc.h = h;
|
|
|
|
bc.srcx = src_x;
|
|
|
|
bc.srcy = src_y;
|
|
|
|
bc.srcw = src_w;
|
|
|
|
bc.srch = src_h;
|
|
|
|
bc.stride = stride;
|
|
|
|
bc.bitmap = bitmap;
|
|
|
|
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(73),"b"(0),"c"(&bc.dstx));
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get screen part as image
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_ScreenShot(char* image, int x, int y, int w, int h) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(36),
|
|
|
|
"b"(image),
|
|
|
|
"c"(w*65536+h),
|
|
|
|
"d"(x*65536+y) : "memory");
|
|
|
|
};
|
2021-02-24 09:40:54 +01:00
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
/*********************** Skin *************************/
|
2022-04-06 16:37:19 +02:00
|
|
|
// Get skin height
|
|
|
|
static inline uint32_t kos_SkinHeight(void) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t height;
|
2024-01-04 23:20:35 +01:00
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40 \n\t"
|
|
|
|
:"=a"(height)
|
|
|
|
:"a"(48),"b"(4));
|
|
|
|
return height;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
/*********************** Mouse *************************/
|
2021-02-24 09:40:54 +01:00
|
|
|
#define POS_SCREEN 0
|
|
|
|
#define POS_WINDOW 1
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline pos_t kos_GetMousePos(int origin) {
|
2021-02-24 10:25:50 +01:00
|
|
|
pos_t val;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40 \n\t"
|
|
|
|
"rol $16, %%eax"
|
|
|
|
:"=a"(val)
|
|
|
|
:"a"(37),"b"(origin));
|
|
|
|
return val;
|
2021-02-24 09:40:54 +01:00
|
|
|
}
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline uint32_t kos_GetMouseButtons(void) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t val;
|
2024-01-04 23:20:35 +01:00
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(val)
|
|
|
|
:"a"(37),"b"(2));
|
|
|
|
return val;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline uint32_t kos_GetMouseWheels(void) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t val;
|
2024-01-04 23:20:35 +01:00
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40 \n\t"
|
|
|
|
:"=a"(val)
|
|
|
|
:"a"(37),"b"(7));
|
|
|
|
return val;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline uint32_t kos_LoadCursor(void *path, uint32_t flags) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t val;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(val)
|
|
|
|
:"a"(37), "b"(4), "c"(path), "d"(flags));
|
|
|
|
return val;
|
2021-02-24 09:40:54 +01:00
|
|
|
}
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline uint32_t kos_SetCursor(uint32_t cursor) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t old;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(old)
|
|
|
|
:"a"(37), "b"(5), "c"(cursor));
|
|
|
|
return old;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline int kos_DestroyCursor(uint32_t cursor) {
|
2021-02-24 10:25:50 +01:00
|
|
|
int ret;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(ret)
|
|
|
|
:"a"(37), "b"(6), "c"(cursor)
|
|
|
|
:"memory");
|
|
|
|
return ret;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
/*********************** OS Events *************************/
|
2021-02-24 09:40:54 +01:00
|
|
|
#define evReDraw 1
|
|
|
|
#define evKey 2
|
|
|
|
#define evButton 3
|
|
|
|
#define evExit 4
|
|
|
|
#define evDesktop 5
|
|
|
|
#define evMouse 6
|
|
|
|
#define evIPC 7
|
|
|
|
#define evNetwork 8
|
|
|
|
#define evDebug 9
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline uint32_t kos_WaitForEventTimeout(uint32_t time) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t val;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(val)
|
|
|
|
:"a"(23), "b"(time));
|
|
|
|
return val;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
2024-01-04 23:20:35 +01:00
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline uint32_t kos_CheckForEvent(void) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t val;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(val)
|
|
|
|
:"a"(11));
|
|
|
|
return val;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
2024-01-04 23:20:35 +01:00
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline uint32_t kos_WaitForEvent(void) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t val;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(val)
|
|
|
|
:"a"(10));
|
|
|
|
return val;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
/*********************** Eventmask *************************/
|
2021-02-24 09:40:54 +01:00
|
|
|
#define EVM_REDRAW 1
|
|
|
|
#define EVM_KEY 2
|
|
|
|
#define EVM_BUTTON 4
|
|
|
|
#define EVM_EXIT 8
|
|
|
|
#define EVM_BACKGROUND 16
|
|
|
|
#define EVM_MOUSE 32
|
|
|
|
#define EVM_IPC 64
|
|
|
|
#define EVM_STACK 128
|
|
|
|
#define EVM_DEBUG 256
|
|
|
|
#define EVM_STACK2 512
|
|
|
|
#define EVM_MOUSE_FILTER 0x80000000
|
|
|
|
#define EVM_CURSOR_FILTER 0x40000000
|
2024-01-04 23:20:35 +01:00
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline uint32_t kos_SetMaskForEvents(uint32_t event_mask) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t old_event_mask;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(old_event_mask)
|
|
|
|
:"a"(40),"b"(event_mask));
|
|
|
|
|
|
|
|
return old_event_mask;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2021-02-24 10:25:50 +01:00
|
|
|
/*********************** Other *************************/
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline int kos_GetKey() {
|
2021-02-24 09:40:54 +01:00
|
|
|
unsigned short key;
|
|
|
|
__asm__ __volatile__("int $0x40":"=a"(key):"0"(2));
|
|
|
|
if(!(key & 0xFF)) return (key>>8)&0xFF; else return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline uint32_t kos_GetButtonID(void) {
|
2021-02-24 10:25:50 +01:00
|
|
|
uint32_t val;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(val)
|
|
|
|
:"a"(17));
|
|
|
|
return val>>8;
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_Delay(uint32_t time) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(5), "b"(time)
|
|
|
|
:"memory");
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline pos_t kos_ScreenSize() {
|
2021-02-24 09:40:54 +01:00
|
|
|
pos_t size;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(size)
|
|
|
|
:"a"(14));
|
|
|
|
|
|
|
|
return size;
|
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_GetSystemColors(struct kolibri_system_colors *color_table) {
|
2021-02-24 09:40:54 +01:00
|
|
|
__asm__ __volatile__ ("int $0x40"
|
|
|
|
:
|
|
|
|
:"a"(48),"b"(3),"c"(color_table),"d"(40)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
// sysfn 9
|
|
|
|
static inline void kos_ProcessInfo(char *info) {
|
2021-02-24 10:25:50 +01:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:
|
|
|
|
:"a"(9), "b"(info), "c"(-1)
|
|
|
|
:"memory");
|
2021-02-24 09:40:54 +01:00
|
|
|
};
|
|
|
|
|
2022-04-06 16:37:19 +02:00
|
|
|
static inline void kos_RunApp(char* app, char* param) {
|
2021-02-24 09:40:54 +01:00
|
|
|
kos_Struct70 r;
|
|
|
|
r.p00 = 7;
|
|
|
|
r.p04 = 0;
|
|
|
|
r.p08 = param;
|
|
|
|
r.p12 = 0;
|
|
|
|
r.p16 = 0;
|
|
|
|
r.p20 = 0;
|
|
|
|
r.p21 = app;
|
|
|
|
__asm__ __volatile__ ("int $0x40"::"a"(70), "b"(&r));
|
|
|
|
}
|
2024-01-04 23:20:35 +01:00
|
|
|
|