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