Rev 4506 | 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 | "rol $16, %%eax" |
||
150 | :"=a"(val) |
||
151 | :"a"(37),"b"(7)); |
||
152 | return val; |
||
153 | }; |
||
154 | |||
155 | static inline |
||
156 | uint32_t wait_for_event(uint32_t time) |
||
157 | { |
||
158 | uint32_t val; |
||
159 | __asm__ __volatile__( |
||
160 | "int $0x40" |
||
161 | :"=a"(val) |
||
162 | :"a"(23), "b"(time)); |
||
163 | return val; |
||
164 | }; |
||
165 | |||
166 | static inline uint32_t check_os_event() |
||
167 | { |
||
168 | uint32_t val; |
||
169 | __asm__ __volatile__( |
||
170 | "int $0x40" |
||
171 | :"=a"(val) |
||
172 | :"a"(11)); |
||
173 | return val; |
||
174 | }; |
||
175 | |||
4499 | Serge | 176 | static inline uint32_t get_os_event() |
177 | { |
||
178 | uint32_t val; |
||
179 | __asm__ __volatile__( |
||
180 | "int $0x40" |
||
181 | :"=a"(val) |
||
182 | :"a"(10)); |
||
183 | return val; |
||
184 | }; |
||
185 | |||
4349 | Serge | 186 | static inline |
187 | uint32_t get_tick_count(void) |
||
188 | { |
||
189 | uint32_t val; |
||
190 | __asm__ __volatile__( |
||
191 | "int $0x40" |
||
192 | :"=a"(val) |
||
193 | :"a"(26),"b"(9)); |
||
194 | return val; |
||
195 | }; |
||
196 | |||
197 | static inline |
||
198 | oskey_t get_key(void) |
||
199 | { |
||
200 | oskey_t val; |
||
201 | __asm__ __volatile__( |
||
202 | "int $0x40" |
||
203 | :"=a"(val) |
||
204 | :"a"(2)); |
||
205 | return val; |
||
206 | } |
||
207 | |||
208 | static inline |
||
209 | uint32_t get_os_button() |
||
210 | { |
||
211 | uint32_t val; |
||
212 | __asm__ __volatile__( |
||
213 | "int $0x40" |
||
214 | :"=a"(val) |
||
215 | :"a"(17)); |
||
216 | return val>>8; |
||
217 | }; |
||
218 | |||
219 | static inline uint32_t get_service(char *name) |
||
220 | { |
||
221 | uint32_t retval = 0; |
||
222 | asm volatile ("int $0x40" |
||
223 | :"=a"(retval) |
||
224 | :"a"(68),"b"(16),"c"(name) |
||
225 | :"memory"); |
||
226 | |||
227 | return retval; |
||
228 | }; |
||
229 | |||
230 | static inline int call_service(ioctl_t *io) |
||
231 | { |
||
232 | int retval; |
||
233 | |||
234 | asm volatile("int $0x40" |
||
235 | :"=a"(retval) |
||
236 | :"a"(68),"b"(17),"c"(io) |
||
237 | :"memory","cc"); |
||
238 | |||
239 | return retval; |
||
240 | }; |
||
241 | |||
242 | |||
243 | static inline |
||
244 | void draw_line(int xs, int ys, int xe, int ye, color_t color) |
||
245 | { |
||
246 | __asm__ __volatile__( |
||
247 | "int $0x40" |
||
248 | ::"a"(38), "d"(color), |
||
249 | "b"((xs << 16) | xe), |
||
250 | "c"((ys << 16) | ye)); |
||
251 | } |
||
252 | |||
253 | |||
254 | |||
255 | static inline |
||
256 | void draw_bar(int x, int y, int w, int h, color_t color) |
||
257 | { |
||
258 | __asm__ __volatile__( |
||
259 | "int $0x40" |
||
260 | ::"a"(13), "d"(color), |
||
261 | "b"((x << 16) | w), |
||
262 | "c"((y << 16) | h)); |
||
263 | } |
||
264 | |||
265 | static inline |
||
266 | void draw_bitmap(void *bitmap, int x, int y, int w, int h) |
||
267 | { |
||
268 | __asm__ __volatile__( |
||
269 | "int $0x40" |
||
270 | ::"a"(7), "b"(bitmap), |
||
271 | "c"((w << 16) | h), |
||
272 | "d"((x << 16) | y)); |
||
273 | } |
||
274 | |||
275 | static inline |
||
276 | void draw_text_sys(const char *text, int x, int y, int len, color_t color) |
||
277 | { |
||
278 | __asm__ __volatile__( |
||
279 | "int $0x40" |
||
280 | ::"a"(4),"d"(text), |
||
281 | "b"((x << 16) | y), |
||
282 | "S"(len),"c"(color)); |
||
283 | } |
||
284 | |||
285 | static inline void yield(void) |
||
286 | { |
||
287 | __asm__ __volatile__( |
||
288 | "int $0x40" |
||
289 | ::"a"(68), "b"(1)); |
||
290 | }; |
||
291 | |||
292 | static inline void delay(uint32_t time) |
||
293 | { |
||
294 | __asm__ __volatile__( |
||
295 | "int $0x40" |
||
296 | ::"a"(5), "b"(time) |
||
297 | :"memory"); |
||
298 | }; |
||
299 | |||
300 | static inline |
||
301 | void *user_alloc(size_t size) |
||
302 | { |
||
303 | void *val; |
||
304 | __asm__ __volatile__( |
||
305 | "int $0x40" |
||
306 | :"=a"(val) |
||
307 | :"a"(68),"b"(12),"c"(size)); |
||
308 | return val; |
||
309 | } |
||
310 | |||
311 | static inline |
||
312 | int user_free(void *mem) |
||
313 | { |
||
314 | int val; |
||
315 | __asm__ __volatile__( |
||
316 | "int $0x40" |
||
317 | :"=a"(val) |
||
4461 | Serge | 318 | :"a"(68),"b"(13),"c"(mem)); |
4349 | Serge | 319 | return val; |
320 | } |
||
321 | |||
322 | static inline |
||
323 | int *user_unmap(void *base, size_t offset, size_t size) |
||
324 | { |
||
4768 | Serge | 325 | int *val; |
4349 | Serge | 326 | __asm__ __volatile__( |
327 | "int $0x40" |
||
328 | :"=a"(val) |
||
329 | :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size)); |
||
330 | return val; |
||
331 | } |
||
332 | |||
333 | typedef union |
||
334 | { |
||
335 | struct |
||
336 | { |
||
337 | void *data; |
||
338 | size_t size; |
||
339 | }; |
||
340 | unsigned long long raw; |
||
341 | }ufile_t; |
||
342 | |||
343 | |||
344 | static inline ufile_t load_file(const char *path) |
||
345 | { |
||
346 | ufile_t uf; |
||
347 | |||
348 | __asm__ __volatile__ ( |
||
349 | "int $0x40" |
||
350 | :"=A"(uf.raw) |
||
351 | :"a" (68), "b"(27),"c"(path)); |
||
352 | |||
353 | return uf; |
||
354 | }; |
||
355 | |||
356 | |||
357 | static inline int GetScreenSize() |
||
358 | { |
||
359 | int retval; |
||
360 | |||
361 | __asm__ __volatile__( |
||
362 | "int $0x40" |
||
363 | :"=a"(retval) |
||
364 | :"a"(61), "b"(1)); |
||
365 | return retval; |
||
366 | } |
||
367 | |||
368 | static inline |
||
369 | uint32_t load_cursor(void *path, uint32_t flags) |
||
370 | { |
||
371 | uint32_t val; |
||
372 | __asm__ __volatile__( |
||
373 | "int $0x40" |
||
374 | :"=a"(val) |
||
375 | :"a"(37), "b"(4), "c"(path), "d"(flags)); |
||
376 | return val; |
||
377 | } |
||
378 | |||
379 | static inline |
||
380 | uint32_t set_cursor(uint32_t cursor) |
||
381 | { |
||
382 | uint32_t old; |
||
383 | __asm__ __volatile__( |
||
384 | "int $0x40" |
||
385 | :"=a"(old) |
||
386 | :"a"(37), "b"(5), "c"(cursor)); |
||
387 | return old; |
||
388 | } |
||
389 | |||
390 | static inline |
||
391 | int destroy_cursor(uint32_t cursor) |
||
392 | { |
||
393 | int ret; |
||
394 | __asm__ __volatile__( |
||
395 | "int $0x40" |
||
396 | :"=a"(ret) |
||
397 | :"a"(37), "b"(6), "c"(cursor) |
||
398 | :"memory"); |
||
399 | return ret; |
||
400 | }; |
||
401 | |||
402 | static inline void get_proc_info(char *info) |
||
403 | { |
||
404 | __asm__ __volatile__( |
||
405 | "int $0x40" |
||
406 | : |
||
407 | :"a"(9), "b"(info), "c"(-1)); |
||
408 | } |
||
409 | |||
410 | static inline |
||
411 | void* user_realloc(void *mem, size_t size) |
||
412 | { |
||
413 | void *val; |
||
414 | __asm__ __volatile__( |
||
415 | "int $0x40" |
||
416 | :"=a"(val) |
||
417 | :"a"(68),"b"(20),"c"(size),"d"(mem) |
||
418 | :"memory"); |
||
419 | |||
420 | return val; |
||
421 | } |
||
422 | |||
423 | |||
424 | void *get_resource(void *data, uint32_t id); |
||
425 | |||
426 | struct blit_call |
||
427 | { |
||
428 | int dstx; |
||
429 | int dsty; |
||
430 | int w; |
||
431 | int h; |
||
432 | |||
433 | int srcx; |
||
434 | int srcy; |
||
435 | int srcw; |
||
436 | int srch; |
||
437 | |||
438 | unsigned char *bitmap; |
||
439 | int stride; |
||
440 | }; |
||
441 | |||
442 | void Blit(void *bitmap, int dst_x, int dst_y, |
||
443 | int src_x, int src_y, int w, int h, |
||
444 | int src_w, int src_h, int stride); |
||
445 | |||
446 | |||
447 | #endif><>><>><>><>><>><>><>><>><>><> |
||
448 |