Rev 4874 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | #ifndef __KOS_32_SYS_H__ |
2 | #define __KOS_32_SYS_H__ |
||
3 | |||
4 | #include |
||
5 | #include |
||
6 | #include |
||
7 | |||
8 | //#ifdef CONFIG_DEBUF |
||
9 | // #define DBG(format,...) printf(format,##__VA_ARGS__) |
||
10 | //#else |
||
11 | // #define DBG(format,...) |
||
12 | //#endif |
||
13 | |||
4499 | Serge | 14 | #define TYPE_3_BORDER_WIDTH 5 |
15 | |||
4349 | Serge | 16 | typedef unsigned int color_t; |
17 | |||
18 | typedef union __attribute__((packed)) |
||
19 | { |
||
20 | uint32_t val; |
||
21 | struct |
||
22 | { |
||
23 | short x; |
||
24 | short y; |
||
25 | }; |
||
26 | }pos_t; |
||
27 | |||
28 | typedef union __attribute__((packed)) |
||
29 | { |
||
30 | uint32_t val; |
||
31 | struct |
||
32 | { |
||
33 | uint8_t state; |
||
34 | uint8_t code; |
||
35 | uint16_t ctrl_key; |
||
36 | }; |
||
37 | }oskey_t; |
||
38 | |||
39 | typedef struct |
||
40 | { |
||
41 | unsigned handle; |
||
42 | unsigned io_code; |
||
43 | void *input; |
||
44 | int inp_size; |
||
45 | void *output; |
||
46 | int out_size; |
||
47 | }ioctl_t; |
||
48 | |||
49 | |||
50 | static inline |
||
51 | void DefineButton(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color) |
||
52 | { |
||
53 | __asm__ __volatile__( |
||
54 | "int $0x40" |
||
55 | ::"a"(8), |
||
56 | "b"(x_w), |
||
57 | "c"(y_h), |
||
58 | "d"(id), |
||
59 | "S"(color)); |
||
60 | |||
61 | |||
62 | }; |
||
63 | |||
64 | static inline |
||
4499 | Serge | 65 | uint32_t get_skin_height(void) |
66 | { |
||
67 | uint32_t height; |
||
68 | |||
69 | __asm__ __volatile__( |
||
70 | "int $0x40 \n\t" |
||
71 | :"=a"(height) |
||
72 | :"a"(48),"b"(4)); |
||
73 | return height; |
||
74 | } |
||
75 | |||
76 | static inline |
||
4349 | Serge | 77 | void BeginDraw(void) |
78 | { |
||
79 | __asm__ __volatile__( |
||
80 | "int $0x40" ::"a"(12),"b"(1)); |
||
81 | }; |
||
82 | |||
83 | static inline |
||
84 | void EndDraw(void) |
||
85 | { |
||
86 | __asm__ __volatile__( |
||
87 | "int $0x40" ::"a"(12),"b"(2)); |
||
88 | }; |
||
89 | |||
4499 | Serge | 90 | static inline void DrawWindow(int x, int y, int w, int h, const char *name, |
4349 | Serge | 91 | color_t workcolor, uint32_t style) |
92 | { |
||
93 | |||
94 | __asm__ __volatile__( |
||
95 | "int $0x40" |
||
96 | ::"a"(0), |
||
4506 | Serge | 97 | "b"((x << 16) | ((w-1) & 0xFFFF)), |
98 | "c"((y << 16) | ((h-1) & 0xFFFF)), |
||
99 | "d"((style << 24) | (workcolor & 0xFFFFFF)), |
||
100 | "D"(name), |
||
101 | "S"(0)); |
||
4349 | Serge | 102 | }; |
103 | |||
104 | static inline |
||
105 | pos_t get_mouse_pos(void) |
||
106 | { |
||
107 | pos_t val; |
||
108 | |||
109 | __asm__ __volatile__( |
||
110 | "int $0x40 \n\t" |
||
111 | "rol $16, %%eax" |
||
112 | :"=a"(val) |
||
113 | :"a"(37),"b"(1)); |
||
114 | return val; |
||
115 | } |
||
116 | |||
117 | static inline |
||
118 | pos_t get_cursor_pos(void) |
||
119 | { |
||
120 | pos_t val; |
||
121 | |||
122 | __asm__ __volatile__( |
||
123 | "int $0x40 \n\t" |
||
124 | "rol $16, %%eax" |
||
125 | :"=a"(val) |
||
126 | :"a"(37),"b"(0)); |
||
127 | return val; |
||
128 | } |
||
129 | |||
130 | static inline |
||
131 | uint32_t get_mouse_buttons(void) |
||
132 | { |
||
133 | uint32_t val; |
||
134 | |||
135 | __asm__ __volatile__( |
||
136 | "int $0x40" |
||
137 | :"=a"(val) |
||
138 | :"a"(37),"b"(2)); |
||
139 | return val; |
||
140 | }; |
||
141 | |||
142 | static inline |
||
143 | uint32_t get_mouse_wheels(void) |
||
144 | { |
||
145 | uint32_t val; |
||
146 | |||
147 | __asm__ __volatile__( |
||
148 | "int $0x40 \n\t" |
||
149 | :"=a"(val) |
||
150 | :"a"(37),"b"(7)); |
||
151 | return val; |
||
152 | }; |
||
153 | |||
154 | static inline |
||
155 | uint32_t wait_for_event(uint32_t time) |
||
156 | { |
||
157 | uint32_t val; |
||
158 | __asm__ __volatile__( |
||
159 | "int $0x40" |
||
160 | :"=a"(val) |
||
161 | :"a"(23), "b"(time)); |
||
162 | return val; |
||
163 | }; |
||
164 | |||
165 | static inline uint32_t check_os_event() |
||
166 | { |
||
167 | uint32_t val; |
||
168 | __asm__ __volatile__( |
||
169 | "int $0x40" |
||
170 | :"=a"(val) |
||
171 | :"a"(11)); |
||
172 | return val; |
||
173 | }; |
||
174 | |||
4499 | Serge | 175 | static inline uint32_t get_os_event() |
176 | { |
||
177 | uint32_t val; |
||
178 | __asm__ __volatile__( |
||
179 | "int $0x40" |
||
180 | :"=a"(val) |
||
181 | :"a"(10)); |
||
182 | return val; |
||
183 | }; |
||
184 | |||
4349 | Serge | 185 | static inline |
186 | uint32_t get_tick_count(void) |
||
187 | { |
||
188 | uint32_t val; |
||
189 | __asm__ __volatile__( |
||
190 | "int $0x40" |
||
191 | :"=a"(val) |
||
192 | :"a"(26),"b"(9)); |
||
193 | return val; |
||
194 | }; |
||
195 | |||
196 | static inline |
||
197 | oskey_t get_key(void) |
||
198 | { |
||
199 | oskey_t val; |
||
200 | __asm__ __volatile__( |
||
201 | "int $0x40" |
||
202 | :"=a"(val) |
||
203 | :"a"(2)); |
||
204 | return val; |
||
205 | } |
||
206 | |||
207 | static inline |
||
208 | uint32_t get_os_button() |
||
209 | { |
||
210 | uint32_t val; |
||
211 | __asm__ __volatile__( |
||
212 | "int $0x40" |
||
213 | :"=a"(val) |
||
214 | :"a"(17)); |
||
215 | return val>>8; |
||
216 | }; |
||
217 | |||
218 | static inline uint32_t get_service(char *name) |
||
219 | { |
||
220 | uint32_t retval = 0; |
||
221 | asm volatile ("int $0x40" |
||
222 | :"=a"(retval) |
||
223 | :"a"(68),"b"(16),"c"(name) |
||
224 | :"memory"); |
||
225 | |||
226 | return retval; |
||
227 | }; |
||
228 | |||
229 | static inline int call_service(ioctl_t *io) |
||
230 | { |
||
231 | int retval; |
||
232 | |||
233 | asm volatile("int $0x40" |
||
234 | :"=a"(retval) |
||
235 | :"a"(68),"b"(17),"c"(io) |
||
236 | :"memory","cc"); |
||
237 | |||
238 | return retval; |
||
239 | }; |
||
240 | |||
241 | |||
242 | static inline |
||
243 | void draw_line(int xs, int ys, int xe, int ye, color_t color) |
||
244 | { |
||
245 | __asm__ __volatile__( |
||
246 | "int $0x40" |
||
247 | ::"a"(38), "d"(color), |
||
248 | "b"((xs << 16) | xe), |
||
249 | "c"((ys << 16) | ye)); |
||
250 | } |
||
251 | |||
252 | |||
253 | |||
254 | static inline |
||
255 | void draw_bar(int x, int y, int w, int h, color_t color) |
||
256 | { |
||
257 | __asm__ __volatile__( |
||
258 | "int $0x40" |
||
259 | ::"a"(13), "d"(color), |
||
260 | "b"((x << 16) | w), |
||
261 | "c"((y << 16) | h)); |
||
262 | } |
||
263 | |||
264 | static inline |
||
265 | void draw_bitmap(void *bitmap, int x, int y, int w, int h) |
||
266 | { |
||
267 | __asm__ __volatile__( |
||
268 | "int $0x40" |
||
269 | ::"a"(7), "b"(bitmap), |
||
270 | "c"((w << 16) | h), |
||
271 | "d"((x << 16) | y)); |
||
272 | } |
||
273 | |||
274 | static inline |
||
275 | void draw_text_sys(const char *text, int x, int y, int len, color_t color) |
||
276 | { |
||
277 | __asm__ __volatile__( |
||
278 | "int $0x40" |
||
279 | ::"a"(4),"d"(text), |
||
280 | "b"((x << 16) | y), |
||
281 | "S"(len),"c"(color)); |
||
282 | } |
||
283 | |||
284 | static inline void yield(void) |
||
285 | { |
||
286 | __asm__ __volatile__( |
||
287 | "int $0x40" |
||
288 | ::"a"(68), "b"(1)); |
||
289 | }; |
||
290 | |||
291 | static inline void delay(uint32_t time) |
||
292 | { |
||
293 | __asm__ __volatile__( |
||
294 | "int $0x40" |
||
295 | ::"a"(5), "b"(time) |
||
296 | :"memory"); |
||
297 | }; |
||
298 | |||
299 | static inline |
||
300 | void *user_alloc(size_t size) |
||
301 | { |
||
302 | void *val; |
||
303 | __asm__ __volatile__( |
||
304 | "int $0x40" |
||
305 | :"=a"(val) |
||
306 | :"a"(68),"b"(12),"c"(size)); |
||
307 | return val; |
||
308 | } |
||
309 | |||
310 | static inline |
||
311 | int user_free(void *mem) |
||
312 | { |
||
313 | int val; |
||
314 | __asm__ __volatile__( |
||
315 | "int $0x40" |
||
316 | :"=a"(val) |
||
4461 | Serge | 317 | :"a"(68),"b"(13),"c"(mem)); |
4349 | Serge | 318 | return val; |
319 | } |
||
320 | |||
321 | static inline |
||
322 | int *user_unmap(void *base, size_t offset, size_t size) |
||
323 | { |
||
4768 | Serge | 324 | int *val; |
4349 | Serge | 325 | __asm__ __volatile__( |
326 | "int $0x40" |
||
327 | :"=a"(val) |
||
328 | :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size)); |
||
329 | return val; |
||
330 | } |
||
331 | |||
332 | typedef union |
||
333 | { |
||
334 | struct |
||
335 | { |
||
336 | void *data; |
||
337 | size_t size; |
||
338 | }; |
||
339 | unsigned long long raw; |
||
340 | }ufile_t; |
||
341 | |||
342 | |||
343 | static inline ufile_t load_file(const char *path) |
||
344 | { |
||
345 | ufile_t uf; |
||
346 | |||
347 | __asm__ __volatile__ ( |
||
348 | "int $0x40" |
||
349 | :"=A"(uf.raw) |
||
350 | :"a" (68), "b"(27),"c"(path)); |
||
351 | |||
352 | return uf; |
||
353 | }; |
||
354 | |||
355 | |||
356 | static inline int GetScreenSize() |
||
357 | { |
||
358 | int retval; |
||
359 | |||
360 | __asm__ __volatile__( |
||
361 | "int $0x40" |
||
362 | :"=a"(retval) |
||
363 | :"a"(61), "b"(1)); |
||
364 | return retval; |
||
365 | } |
||
366 | |||
367 | static inline |
||
368 | uint32_t load_cursor(void *path, uint32_t flags) |
||
369 | { |
||
370 | uint32_t val; |
||
371 | __asm__ __volatile__( |
||
372 | "int $0x40" |
||
373 | :"=a"(val) |
||
374 | :"a"(37), "b"(4), "c"(path), "d"(flags)); |
||
375 | return val; |
||
376 | } |
||
377 | |||
378 | static inline |
||
379 | uint32_t set_cursor(uint32_t cursor) |
||
380 | { |
||
381 | uint32_t old; |
||
382 | __asm__ __volatile__( |
||
383 | "int $0x40" |
||
384 | :"=a"(old) |
||
385 | :"a"(37), "b"(5), "c"(cursor)); |
||
386 | return old; |
||
387 | } |
||
388 | |||
389 | static inline |
||
390 | int destroy_cursor(uint32_t cursor) |
||
391 | { |
||
392 | int ret; |
||
393 | __asm__ __volatile__( |
||
394 | "int $0x40" |
||
395 | :"=a"(ret) |
||
396 | :"a"(37), "b"(6), "c"(cursor) |
||
397 | :"memory"); |
||
398 | return ret; |
||
399 | }; |
||
400 | |||
401 | static inline void get_proc_info(char *info) |
||
402 | { |
||
403 | __asm__ __volatile__( |
||
404 | "int $0x40" |
||
405 | : |
||
406 | :"a"(9), "b"(info), "c"(-1)); |
||
407 | } |
||
408 | |||
409 | static inline |
||
410 | void* user_realloc(void *mem, size_t size) |
||
411 | { |
||
412 | void *val; |
||
413 | __asm__ __volatile__( |
||
414 | "int $0x40" |
||
415 | :"=a"(val) |
||
416 | :"a"(68),"b"(20),"c"(size),"d"(mem) |
||
417 | :"memory"); |
||
418 | |||
419 | return val; |
||
420 | } |
||
421 | |||
422 | |||
423 | void *get_resource(void *data, uint32_t id); |
||
424 | |||
425 | struct blit_call |
||
426 | { |
||
427 | int dstx; |
||
428 | int dsty; |
||
429 | int w; |
||
430 | int h; |
||
431 | |||
432 | int srcx; |
||
433 | int srcy; |
||
434 | int srcw; |
||
435 | int srch; |
||
436 | |||
437 | unsigned char *bitmap; |
||
438 | int stride; |
||
439 | }; |
||
440 | |||
441 | void Blit(void *bitmap, int dst_x, int dst_y, |
||
442 | int src_x, int src_y, int w, int h, |
||
443 | int src_w, int src_h, int stride); |
||
444 | |||
445 | |||
446 | #endif><>><>><>><>><>><>><>><>><>><> |
||
447 |