Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8610 maxcodehac 1
////////////////////////////////////////////
2
//  Copyright (C) 2021 maxcodehack, GPLv2 //
3
//           KolibriOS Syscalls           //
4
//               sys/kos.h                //
5
//                                        //
6
// Syscalls scheme: kos_XxxYyy            //
7
//				(e.g. kos_DrawWindow)     //
8
////////////////////////////////////////////
9
 
10
#include 
11
#include 
12
 
13
typedef unsigned int color_t;
14
 
15
// Struct for App running
16
#pragma pack(push,1)
17
typedef struct
18
{
19
unsigned	p00;
20
unsigned 	p04;
21
char	 	*p08;
22
unsigned	p12;
23
unsigned	p16;
24
char		p20;
25
char		*p21;
26
} kos_Struct70;
27
#pragma pack(pop)
28
 
29
// Blitter struct
30
struct blit_call
31
{
32
    int dstx;
33
    int dsty;
34
    int w;
35
    int h;
36
 
37
    int srcx;
38
    int srcy;
39
    int srcw;
40
    int srch;
41
 
42
    void *bitmap;
43
    int   stride;
44
};
45
 
46
// Process info for sysfn 9
47
#pragma pack(push, 1)
48
struct proc_info
49
{
50
        unsigned long cpu_usage;
51
        unsigned short pos_in_stack;
52
        unsigned short slot;
53
        unsigned short reserved;
54
        char name[12];
55
        unsigned long address;
56
        unsigned long memory_usage;
57
        unsigned long ID;
58
        unsigned long left,top;
59
        unsigned long width,height;
60
        unsigned short thread_state;
61
        unsigned short reserved2;
62
        unsigned long cleft, ctop, cwidth, cheight;
63
        unsigned char window_state;
64
        unsigned char reserved3[1024-71];
65
};
66
#pragma pack(pop)
67
 
68
// Color struct for sysfn ?
69
struct kolibri_system_colors {
70
  color_t frame_area;
71
  color_t grab_bar;
72
  color_t grab_bar_button;
73
  color_t grab_button_text;
74
  color_t grab_text;
75
  color_t work_area;
76
  color_t work_button;
77
  color_t work_button_text;
78
  color_t work_text;
79
  color_t work_graph;
80
};
81
 
82
typedef union __attribute__((packed))
83
{
84
    uint32_t val;
85
    struct
86
    {
87
        short  x;
88
        short  y;
89
    };
90
} pos_t;
91
 
92
 
93
/// Window Syscalls:
94
// Start drawing
95
static inline void kos_BeginDraw(void)
96
{
97
    __asm__ __volatile__(
98
    "int $0x40" ::"a"(12),"b"(1));
99
};
100
 
101
// End drawing
102
static inline void kos_EndDraw(void)
103
{
104
    __asm__ __volatile__(
105
    "int $0x40" ::"a"(12),"b"(2));
106
};
107
 
108
// Draw window
109
static inline void kos_DrawWindow(int x, int y, int w, int h, const char *title,
110
                       color_t bgcolor, uint32_t style)
111
{
112
    __asm__ __volatile__(
113
    "int $0x40"
114
    ::"a"(0),
115
     "b"((x << 16) | ((w-1) & 0xFFFF)),
116
     "c"((y << 16) | ((h-1) & 0xFFFF)),
117
     "d"((style << 24) | (bgcolor & 0xFFFFFF)),
118
     "D"(title),
119
     "S"(0) : "memory");
120
};
121
 
122
// Change window size
123
#define OLD -1
124
static inline void kos_ChangeWindow(int new_x, int new_y, int new_w, int new_h)
125
{
126
    __asm__ __volatile__(
127
        "int $0x40"
128
        ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
129
    );
130
}
131
 
132
/// Other GUI functions:
133
// Draw text
134
static inline void kos_DrawText(int x, int y, const char *text, color_t color)
135
{
136
    __asm__ __volatile__(
137
    "int $0x40"
138
    ::"a"(4),"d"(text),
139
      "b"((x << 16) | y),
140
      "S"(strlen(text)),"c"(color)
141
     :"memory");
142
}
143
 
144
// Draw button
145
static inline void kos_DrawButton(int x, int y, int w, int h, int id, color_t color)
146
{
147
    __asm__ __volatile__(
148
    "int $0x40"
149
    ::"a"(8),
150
      "b"(x * 65536 + w),
151
      "c"(y * 65536 + h),
152
      "d"(id),
153
      "S"(color));
154
};
155
 
156
// Draw button with text
157
void kos_DrawButtonWithText(int x, int y, int w, int h, int id, color_t color, const char* text)
158
{
159
	kos_DrawButton(x, y, w, h, id, color);
160
 
161
	int tx = ((((-strlen(text))*8)+w)/2)+x;
162
	int ty = h/2-7+y;
163
 
164
	kos_DrawText(tx, ty, text, 0x90000000);
165
};
166
 
167
// Draw line
168
static inline void kos_DrawLine(int x_start, int y_start, int x_end, int y_end, color_t color)
169
{
170
    __asm__ __volatile__(
171
    "int $0x40"
172
    ::"a"(38), "d"(color),
173
      "b"((x_start << 16) | x_end),
174
      "c"((y_start << 16) | y_end));
175
}
176
 
177
// Draw bar
178
static inline void kos_DrawBar(int x, int y, int w, int h, color_t color)
179
{
180
    __asm__ __volatile__(
181
    "int $0x40"
182
    ::"a"(13), "d"(color),
183
      "b"((x << 16) | w),
184
      "c"((y << 16) | h));
185
}
186
 
187
// Put one pixel
188
void kos_PutPixel(int x, int y, color_t color) {
189
	__asm__ __volatile__("int $0x40"
190
			 ::"a"(1),
191
			  "b"(x),
192
			  "c"(y),
193
			  "d"(color));
194
}
195
 
196
// Draw bitmap image
197
static inline void kos_DrawBitmap(void *bitmap, int x, int y, int w, int h)
198
{
199
    __asm__ __volatile__(
200
    "int $0x40"
201
    ::"a"(7), "b"(bitmap),
202
      "c"((w << 16) | h),
203
      "d"((x << 16) | y));
204
}
205
 
206
 
207
/// Skin:
208
// Return skin height
209
static inline uint32_t kos_SkinHeight(void)
210
{
211
    uint32_t height;
212
 
213
    __asm__ __volatile__(
214
    "int $0x40 \n\t"
215
    :"=a"(height)
216
    :"a"(48),"b"(4));
217
    return height;
218
};
219
 
220
/// Mouse:
221
// Get mouse position
222
#define POS_SCREEN 0
223
#define POS_WINDOW 1
224
 
225
static inline
226
pos_t kos_GetMousePos(int origin)
227
{
228
    pos_t val;
229
 
230
    __asm__ __volatile__(
231
    "int $0x40 \n\t"
232
    "rol $16, %%eax"
233
    :"=a"(val)
234
    :"a"(37),"b"(origin));
235
    return val;
236
}
237
 
238
// Get mouse buttons
239
static inline
240
uint32_t kos_GetMouseButtons(void)
241
{
242
    uint32_t val;
243
 
244
    __asm__ __volatile__(
245
    "int $0x40"
246
    :"=a"(val)
247
    :"a"(37),"b"(2));
248
    return val;
249
};
250
 
251
// Get mouse wheels
252
static inline
253
uint32_t kos_GetMouseWheels(void)
254
{
255
    uint32_t val;
256
 
257
    __asm__ __volatile__(
258
    "int $0x40 \n\t"
259
    :"=a"(val)
260
    :"a"(37),"b"(7));
261
    return val;
262
};
263
 
264
// Load cursor
265
static inline uint32_t kos_LoadCursor(void *path, uint32_t flags)
266
{
267
    uint32_t  val;
268
    __asm__ __volatile__(
269
    "int $0x40"
270
    :"=a"(val)
271
    :"a"(37), "b"(4), "c"(path), "d"(flags));
272
    return val;
273
}
274
 
275
// Set cursor
276
static inline uint32_t kos_SetCursor(uint32_t cursor)
277
{
278
    uint32_t  old;
279
    __asm__ __volatile__(
280
    "int $0x40"
281
    :"=a"(old)
282
    :"a"(37), "b"(5), "c"(cursor));
283
    return old;
284
};
285
 
286
// Destroy cursor
287
static inline int kos_DestroyCursor(uint32_t cursor)
288
{
289
    int ret;
290
    __asm__ __volatile__(
291
    "int $0x40"
292
    :"=a"(ret)
293
    :"a"(37), "b"(6), "c"(cursor)
294
    :"memory");
295
    return ret;
296
};
297
 
298
/// OS Events:
299
#define evReDraw  1
300
#define evKey     2
301
#define evButton  3
302
#define evExit    4
303
#define evDesktop 5
304
#define evMouse   6
305
#define evIPC     7
306
#define evNetwork 8
307
#define evDebug   9
308
 
309
static inline
310
uint32_t kos_WaitForEventTimeout(uint32_t time)
311
{
312
    uint32_t val;
313
    __asm__ __volatile__(
314
    "int $0x40"
315
    :"=a"(val)
316
    :"a"(23), "b"(time));
317
    return val;
318
};
319
 
320
static inline uint32_t kos_CheckForEvent(void)
321
{
322
    uint32_t val;
323
    __asm__ __volatile__(
324
    "int $0x40"
325
    :"=a"(val)
326
    :"a"(11));
327
    return val;
328
};
329
 
330
static inline uint32_t kos_WaitForEvent(void)
331
{
332
    uint32_t val;
333
    __asm__ __volatile__(
334
    "int $0x40"
335
    :"=a"(val)
336
    :"a"(10));
337
    return val;
338
};
339
 
340
/// Eventmask:
341
#define EVM_REDRAW        1
342
#define EVM_KEY           2
343
#define EVM_BUTTON        4
344
#define EVM_EXIT          8
345
#define EVM_BACKGROUND    16
346
#define EVM_MOUSE         32
347
#define EVM_IPC           64
348
#define EVM_STACK         128
349
#define EVM_DEBUG         256
350
#define EVM_STACK2        512
351
#define EVM_MOUSE_FILTER  0x80000000
352
#define EVM_CURSOR_FILTER 0x40000000
353
 
354
static inline uint32_t kos_SetMaskForEvents(uint32_t event_mask)
355
{
356
  uint32_t  old_event_mask;
357
    __asm__ __volatile__(
358
    "int $0x40"
359
    :"=a"(old_event_mask)
360
    :"a"(40),"b"(event_mask));
361
 
362
    return old_event_mask;
363
};
364
 
365
/// Other:
366
// Get key
367
int kos_GetKey()
368
{
369
	unsigned short key;
370
	__asm__ __volatile__("int $0x40":"=a"(key):"0"(2));
371
	if(!(key & 0xFF)) return (key>>8)&0xFF; else return 0;
372
}
373
 
374
// Get pressed button ID
375
static inline
376
uint32_t kos_GetButtonID(void)
377
{
378
    uint32_t val;
379
    __asm__ __volatile__(
380
    "int $0x40"
381
    :"=a"(val)
382
    :"a"(17));
383
    return val>>8;
384
};
385
 
386
// Sleep..
387
static inline void kos_Delay(uint32_t time)
388
{
389
    __asm__ __volatile__(
390
    "int $0x40"
391
    ::"a"(5), "b"(time)
392
    :"memory");
393
};
394
 
395
// Get screen size
396
static inline
397
pos_t kos_ScreenSize()
398
{
399
	pos_t size;
400
	__asm__ __volatile__(
401
	"int $0x40"
402
	:"=a"(size)
403
	:"a"(14));
404
 
405
	return size;
406
};
407
 
408
// Get system color table
409
static inline void kos_GetSystemColors(struct kolibri_system_colors *color_table)
410
{
411
	__asm__ __volatile__ ("int $0x40"
412
	:
413
	:"a"(48),"b"(3),"c"(color_table),"d"(40)
414
	);
415
}
416
 
417
// SysFn 9
418
static inline void kos_ProcessInfo(char *info)
419
{
420
    __asm__ __volatile__(
421
    "int $0x40"
422
    :
423
    :"a"(9), "b"(info), "c"(-1)
424
    :"memory");
425
};
426
 
427
// Blitter
428
static inline void Blit(void *bitmap, int dst_x, int dst_y,
429
                        int src_x, int src_y, int w, int h,
430
                        int src_w, int src_h, int stride)
431
{
432
    volatile struct blit_call bc;
433
 
434
    bc.dstx = dst_x;
435
    bc.dsty = dst_y;
436
    bc.w    = w;
437
    bc.h    = h;
438
    bc.srcx = src_x;
439
    bc.srcy = src_y;
440
    bc.srcw = src_w;
441
    bc.srch = src_h;
442
    bc.stride = stride;
443
    bc.bitmap = bitmap;
444
 
445
    __asm__ __volatile__(
446
    "int $0x40"
447
    ::"a"(73),"b"(0),"c"(&bc.dstx));
448
};
449
 
450
void kos_RunApp(char* app, char* param)
451
{
452
	kos_Struct70 r;
453
	r.p00 = 7;
454
	r.p04 = 0;
455
	r.p08 = param;
456
	r.p12 = 0;
457
	r.p16 = 0;
458
	r.p20 = 0;
459
	r.p21 = app;
460
	__asm__ __volatile__ ("int $0x40"::"a"(70), "b"(&r));
461
}