DEADSOFTWARE

files: move resource manager to system drivers
[flatwaifu.git] / src / kos32 / kos32.h
1 #ifndef KOS32_H
2 #define KOS32_H
4 /* --- fn 0 (styles) --- */
5 #define KOS32_WIN_STYLE_EMPTY 0
6 #define KOS32_WIN_STYLE_SKIN 3
7 #define KOS32_WIN_STYLE_FIXED 4
9 /* --- fn 0 (flags) --- */
10 #define KOS32_WIN_FLAG_CAPTION 1
11 #define KOS32_WIN_FLAG_RELATIVE 2
12 #define KOS32_WIN_FLAG_NOFILL 4
13 #define KOS32_WIN_FLAG_GRADIENT 8
14 #define KOS32_WIN_FLAG_UNMOVABLE 256
16 /* --- fn 0 --- */
17 static inline void CreateWindow (int x, int y, int w, int h, int style, int flags, int color, int hcolor, const char *title) {
18 int f = (title ? KOS32_WIN_FLAG_CAPTION : 0) | (flags & ~KOS32_WIN_FLAG_CAPTION);
19 __asm__ __volatile__ (
20 "int $0x40"
21 :
22 : "a" (0),
23 "b" (x << 16 | ((w - 1) & 0xffff)),
24 "c" (y << 16 | ((h - 1) & 0xffff)),
25 "d" ((f << 28) | ((style & 0xf) << 24) | (color & 0xffffff)),
26 "S" (((f >> 8) << 24) | (hcolor & 0xffffff)),
27 "D" (title)
28 : "memory"
29 );
30 }
32 /* --- fn 12.1 --- */
33 static inline void BeginDraw (void) {
34 __asm__ __volatile__ (
35 "int $0x40"
36 :
37 : "a" (12),
38 "b" (1)
39 );
40 }
42 /* --- fn 12.2 --- */
43 static inline void EndDraw (void) {
44 __asm__ __volatile__ (
45 "int $0x40"
46 :
47 : "a" (12),
48 "b" (2)
49 );
50 }
52 /* --- fn 65 --- */
53 static inline void PutImageExt (const void *image, int w, int h, int x, int y, int bpp, const void *pal, int offset) {
54 __asm__ __volatile__ (
55 "push %%ebp; movl %6, %%ebp; int $0x40; pop %%ebp"
56 :
57 : "a" (65),
58 "b" (image),
59 "c" (w << 16 | (h & 0xffff)),
60 "d" (x << 16 | (y & 0xffff)),
61 "S" (bpp),
62 "D" (pal),
63 "m" (offset)
64 : "memory", "ebp"
65 );
66 }
68 /* --- fn 18.4 --- */
69 static inline int GetIdleCount (void) {
70 int ret;
71 __asm__ __volatile__ (
72 "int $0x40"
73 : "=a" (ret)
74 : "a" (18),
75 "b" (4)
76 );
77 return ret;
78 }
80 /* --- fn 26.9 --- */
81 /* result is 1/100 sec */
82 static inline int GetTimeCount (void) {
83 int ret;
84 __asm__ __volatile__ (
85 "int $0x40"
86 : "=a" (ret)
87 : "a" (26),
88 "b" (9)
89 );
90 return ret;
91 }
93 /* --- fn 26.10 --- */
94 /* result is 1/1000000 sec (nanosec) */
95 static inline long GetTimeCountPro (void) {
96 union {
97 struct { int lo, hi; };
98 long pair;
99 } ret;
100 __asm__ __volatile__ (
101 "int $0x40"
102 : "=a" (ret.lo),
103 "=b" (ret.hi)
104 : "a" (26),
105 "b" (10)
106 );
107 return ret.pair;
110 /* --- fn 40 (flags) --- */
111 #define KOS32_EVENT_FLAG_REDRAW (1 << 0)
112 #define KOS32_EVENT_FLAG_KEYBOARD (1 << 1)
113 #define KOS32_EVENT_FLAG_BUTTON (1 << 2)
114 #define KOS32_EVENT_FLAG_RESERVED (1 << 3)
115 #define KOS32_EVENT_FLAG_REDRAW_BG (1 << 4)
116 #define KOS32_EVENT_FLAG_MOUSE (1 << 5)
117 #define KOS32_EVENT_FLAG_IPC (1 << 6)
118 #define KOS32_EVENT_FLAG_NETWORK (1 << 7)
119 #define KOS32_EVENT_FLAG_DEBUG (1 << 8)
120 #define KOS32_EVENT_FLAG_IRQ0 (1 << 15)
121 #define KOS32_EVENT_FLAG_IRQ1 (1 << 16)
122 #define KOS32_EVENT_FLAG_IRQ2 (1 << 17)
123 #define KOS32_EVENT_FLAG_IRQ3 (1 << 18)
124 #define KOS32_EVENT_FLAG_IRQ4 (1 << 19)
125 #define KOS32_EVENT_FLAG_IRQ5 (1 << 20)
126 #define KOS32_EVENT_FLAG_IRQ6 (1 << 21)
127 #define KOS32_EVENT_FLAG_IRQ7 (1 << 22)
128 #define KOS32_EVENT_FLAG_IRQ8 (1 << 23)
129 #define KOS32_EVENT_FLAG_IRQ9 (1 << 24)
130 #define KOS32_EVENT_FLAG_IRQ10 (1 << 25)
131 #define KOS32_EVENT_FLAG_IRQ11 (1 << 26)
132 #define KOS32_EVENT_FLAG_IRQ12 (1 << 27)
133 #define KOS32_EVENT_FLAG_IRQ13 (1 << 28)
134 #define KOS32_EVENT_FLAG_IRQ14 (1 << 29)
135 #define KOS32_EVENT_FLAG_IRQ15 (1 << 30) /* ??? */
136 #define KOS32_EVENT_FLAG_MOUSE_NOFOCUS (1 << 30)
137 #define KOS32_EVENT_FLAG_MOUSE_NOACTIVE (1 << 31)
139 /* --- fn 40 (events) --- */
140 #define KOS32_EVENT_NONE 0
141 #define KOS32_EVENT_REDRAW 1
142 #define KOS32_EVENT_KEYBOARD 2
143 #define KOS32_EVENT_BUTTON 3
144 #define KOS32_EVENT_RESERVED 4
145 #define KOS32_EVENT_REDRAW_BG 5
146 #define KOS32_EVENT_MOUSE 6
147 #define KOS32_EVENT_IPC 7
148 #define KOS32_EVENT_NETWORK 8
149 #define KOS32_EVENT_DEBUG 9
150 #define KOS32_EVENT_IRQ0 16
151 #define KOS32_EVENT_IRQ1 17
152 #define KOS32_EVENT_IRQ2 18
153 #define KOS32_EVENT_IRQ3 19
154 #define KOS32_EVENT_IRQ4 20
155 #define KOS32_EVENT_IRQ5 21
156 #define KOS32_EVENT_IRQ6 22
157 #define KOS32_EVENT_IRQ7 23
158 #define KOS32_EVENT_IRQ8 24
159 #define KOS32_EVENT_IRQ9 25
160 #define KOS32_EVENT_IRQ10 26
161 #define KOS32_EVENT_IRQ11 27
162 #define KOS32_EVENT_IRQ12 28
163 #define KOS32_EVENT_IRQ13 29
164 #define KOS32_EVENT_IRQ14 30
165 #define KOS32_EVENT_IRQ15 31
167 /* --- fn 40 --- */
168 static inline int SetEventsMask (int mask) {
169 int ret;
170 __asm__ __volatile__ (
171 "int $0x40"
172 : "=a" (ret)
173 : "a" (mask)
174 );
175 return ret;
178 /* --- fn 11 --- */
179 static inline int CheckEvent (void) {
180 int ret;
181 __asm__ __volatile__ (
182 "int $0x40"
183 : "=a" (ret)
184 : "a" (11)
185 );
186 return ret;
189 /* --- fn 23 --- */
190 static inline int WaitEventTimeout (int timeout) {
191 int ret;
192 __asm__ __volatile__ (
193 "int $0x40"
194 : "=a" (ret)
195 : "a" (23),
196 "b" (timeout)
197 );
198 return ret;
201 /* --- fn 2 --- */
202 static inline int GetKey (void) {
203 int ret;
204 __asm__ __volatile__ (
205 "int $0x40"
206 : "=a" (ret)
207 : "a" (2)
208 );
209 return ret;
212 /* --- fn 17 --- */
213 static inline int GetButton (void) {
214 int ret;
215 __asm__ __volatile__ (
216 "int $0x40"
217 : "=a" (ret)
218 : "a" (17)
219 );
220 return ret;
223 #define KOS32_INPUT_MODE_ASCII 0
224 #define KOS32_INPUT_MODE_SCANCODE 1
226 /* --- fn 66.1 --- */
227 static inline void SetInputMode (int mode) {
228 __asm__ __volatile__ (
229 "int $0x40"
231 : "a" (66),
232 "b" (1),
233 "c" (mode)
234 );
237 /* --- fn 66.2 --- */
238 static inline int GetInputMode (void) {
239 int ret;
240 __asm__ __volatile__ (
241 "int $0x40"
242 : "=a" (ret)
243 : "a" (66),
244 "b" (2)
245 );
246 return ret;
249 /* --- fn 48.4 --- */
250 static inline int GetSkinHeight (void) {
251 int ret;
252 __asm__ __volatile__ (
253 "int $0x40"
254 : "=a" (ret)
255 : "a" (48),
256 "b" (4)
257 );
258 return ret;
261 /* --- fn 68.1 --- */
262 static inline void SwitchTask (void) {
263 __asm__ __volatile__ (
264 "int $0x40"
266 : "a" (68),
267 "b" (1)
268 );
271 /* --- fn 5 --- */
272 static inline void Delay (int time) {
273 __asm__ __volatile__ (
274 "int $0x40"
276 : "a" (5),
277 "b" (time)
278 );
281 #define KOS32_SC_UNKNOWN 0x00
282 #define KOS32_SC_ESCAPE 0x01
283 #define KOS32_SC_1 0x02
284 #define KOS32_SC_2 0x03
285 #define KOS32_SC_3 0x04
286 #define KOS32_SC_4 0x05
287 #define KOS32_SC_5 0x06
288 #define KOS32_SC_6 0x07
289 #define KOS32_SC_7 0x08
290 #define KOS32_SC_8 0x09
291 #define KOS32_SC_9 0x0A
292 #define KOS32_SC_0 0x0B
293 #define KOS32_SC_MINUS 0x0C
294 #define KOS32_SC_EQUALS 0x0D
295 #define KOS32_SC_BACKSPACE 0x0E
296 #define KOS32_SC_TAB 0x0F
297 #define KOS32_SC_Q 0x10
298 #define KOS32_SC_W 0x11
299 #define KOS32_SC_E 0x12
300 #define KOS32_SC_R 0x13
301 #define KOS32_SC_T 0x14
302 #define KOS32_SC_Y 0x15
303 #define KOS32_SC_U 0x16
304 #define KOS32_SC_I 0x17
305 #define KOS32_SC_O 0x18
306 #define KOS32_SC_P 0x19
307 #define KOS32_SC_LEFTBRACKET 0x1A
308 #define KOS32_SC_RIGHTBRACKET 0x1B
309 #define KOS32_SC_RETURN 0x1C
310 #define KOS32_SC_LCTRL 0x1D
311 #define KOS32_SC_A 0x1E
312 #define KOS32_SC_S 0x1F
313 #define KOS32_SC_D 0x20
314 #define KOS32_SC_F 0x21
315 #define KOS32_SC_G 0x22
316 #define KOS32_SC_H 0x23
317 #define KOS32_SC_J 0x24
318 #define KOS32_SC_K 0x25
319 #define KOS32_SC_L 0x26
320 #define KOS32_SC_SEMICOLON 0x27
321 #define KOS32_SC_APOSTROPHE 0x28
322 #define KOS32_SC_GRAVE 0x29
323 #define KOS32_SC_LSHIFT 0x2A
324 #define KOS32_SC_BACKSLASH 0x2B
325 #define KOS32_SC_Z 0x2C
326 #define KOS32_SC_X 0x2D
327 #define KOS32_SC_C 0x2E
328 #define KOS32_SC_V 0x2F
329 #define KOS32_SC_B 0x30
330 #define KOS32_SC_N 0x31
331 #define KOS32_SC_M 0x32
332 #define KOS32_SC_COMMA 0x33
333 #define KOS32_SC_PERIOD 0x34
334 #define KOS32_SC_SLASH 0x35
335 #define KOS32_SC_RSHIFT 0x36
336 #define KOS32_SC_KP_MULTIPLY 0x37
337 #define KOS32_SC_LALT 0x38
338 #define KOS32_SC_SPACE 0x39
339 #define KOS32_SC_CAPSLOCK 0x3A
340 #define KOS32_SC_F1 0x3B
341 #define KOS32_SC_F2 0x3C
342 #define KOS32_SC_F3 0x3D
343 #define KOS32_SC_F4 0x3E
344 #define KOS32_SC_F5 0x3F
345 #define KOS32_SC_F6 0x40
346 #define KOS32_SC_F7 0x41
347 #define KOS32_SC_F8 0x42
348 #define KOS32_SC_F9 0x43
349 #define KOS32_SC_F10 0x44
350 #define KOS32_SC_NUMLOCK 0x45
351 #define KOS32_SC_SCROLLLOCK 0x46
352 #define KOS32_SC_KP_7 0x47
353 #define KOS32_SC_KP_8 0x48
354 #define KOS32_SC_KP_9 0x49
355 #define KOS32_SC_KP_MINUS 0x4A
356 #define KOS32_SC_KP_4 0x4B
357 #define KOS32_SC_KP_5 0x4C
358 #define KOS32_SC_KP_6 0x4D
359 #define KOS32_SC_KP_PLUS 0x4E
360 #define KOS32_SC_KP_1 0x4F
361 #define KOS32_SC_KP_2 0x50
362 #define KOS32_SC_KP_3 0x51
363 #define KOS32_SC_KP_0 0x52
364 #define KOS32_SC_KP_PERIOD 0x53
365 /* ... */
366 #define KOS32_SC_F11 0x57
367 #define KOS32_SC_F12 0x58
369 /* extended scancodes */
370 #define KOS32_SC_EXTENDED 0xE0 /* starts with this */
371 #define KOS32_SC_PREV_TRACK 0x10
372 #define KOS32_SC_NEXT_TRACK 0x19
373 #define KOS32_SC_KP_ENTER 0x1C
374 #define KOS32_SC_RCTRL 0x1D
375 #define KOS32_SC_MUTE 0x20
376 #define KOS32_SC_CALC 0x21
377 #define KOS32_SC_PLAY 0x22
378 #define KOS32_SC_STOP 0x24
379 #define KOS32_SC_VOLUME_DOWN 0x2E
380 #define KOS32_SC_VOLUME_UP 0x30
381 #define KOS32_SC_WWW 0x32
382 #define KOS32_SC_KP_DIVIDE 0x35
383 #define KOS32_SC_RALT 0x38
384 #define KOS32_SC_HOME 0x47
385 #define KOS32_SC_UP 0x48
386 #define KOS32_SC_PAGEUP 0x49
387 #define KOS32_SC_LEFT 0x4B
388 #define KOS32_SC_RIGHT 0x4D
389 #define KOS32_SC_END 0x4F
390 #define KOS32_SC_DOWN 0x50
391 #define KOS32_SC_PAGEDOWN 0x51
392 #define KOS32_SC_INSERT 0x52
393 #define KOS32_SC_DELETE 0x53
394 #define KOS32_SC_LSUPER 0x5B
395 #define KOS32_SC_RSUPER 0x5C
396 #define KOS32_SC_APP 0x5D
397 #define KOS32_SC_POWER 0x5E
398 #define KOS32_SC_SLEEP 0x5F
399 #define KOS32_SC_WAKE 0x63
400 #define KOS32_SC_WWW_SEARCH 0x65
401 #define KOS32_SC_WWW_FAVORITE 0x66
402 #define KOS32_SC_WWW_REFRESH 0x67
403 #define KOS32_SC_WWW_STOP 0x68
404 #define KOS32_SC_WWW_FORWARD 0x69
405 #define KOS32_SC_WWW_BACK 0x6A
406 #define KOS32_SC_MY_COMPUTER 0x6B
407 #define KOS32_SC_EMAIL 0x6C
408 #define KOS32_SC_SELECT 0x6D
410 #define KOS32_SC_EXTENDED_PAUSE 0xE1 /* pause key seq */
412 #pragma pack(push, 1)
413 struct FileExt {
414 int fn;
415 int a, b, c, d;
416 int enc;
417 const void *path;
418 };
420 struct FileTime {
421 char s, m, h, reserved;
422 };
424 struct FileDate {
425 char d, m;
426 unsigned short y;
427 };
429 struct FileInfo {
430 int attr;
431 int enc;
432 struct FileTime ctime;
433 struct FileDate cdate;
434 struct FileTime atime;
435 struct FileDate cdate;
436 struct FileTime mtime;
437 struct FileDate mdate;
438 long long size;
439 union {
440 char cp866[264];
441 short utf16[260];
442 char utf8[520];
443 };
444 };
445 #pragma pack(pop)
447 #define KOS32_READ_FILE 0
448 #define KOS32_READ_FOLDER 1
449 #define KOS32_CREATE_FILE 2
450 #define KOS32_WRITE_FILE 3
451 #define KOS32_SET_END 4
452 #define KOS32_GET_INFO 5
453 #define KOS32_SET_INFO 6
454 #define KOS32_START_APP 7
455 #define KOS32_DELETE 8
456 #define KOS32_CREATE_FOLDER 9
457 #define KOS32_RENAME 10
459 #define KOS32_FILE_SUCCESS 0
460 #define KOS32_FILE_NOT_SUPPORTED 2
461 #define KOS32_FILE_UNKNOWN_FS 3
462 #define KOS32_FILE_NOT_FOUND 5
463 #define KOS32_FILE_EOF 6
464 #define KOS32_FILE_INVALID_PTR 7
465 #define KOS32_FILE_DISK_FULL 8
466 #define KOS32_FILE_FS_ERROR 9
467 #define KOS32_FILE_ACCESS_DENIED 10
468 #define KOS32_FILE_DEVICE_ERROR 11
469 #define KOS32_FILE_OUT_OF_MEMORY 12
471 #define KOS32_CP866 1
472 #define KOS32_UTF16 2
473 #define KOS32_UTF8 3
475 #define KOS32_ATTR_READONLY 0
476 #define KOS32_ATTR_HIDDEN 1
477 #define KOS32_ATTR_SYSTEM 2
478 #define KOS32_ATTR_VOLUME 3
479 #define KOS32_ATTR_FOLDER 4
480 #define KOS32_ATTR_ARCHIVED 5
482 #define KOS32_ATTR_MASK_READONLY (1 << KOS32_ATTR_READONLY)
483 #define KOS32_ATTR_MASK_HIDDEN (1 << KOS32_ATTR_HIDDEN)
484 #define KOS32_ATTR_MASK_SYSTEM (1 << KOS32_ATTR_SYSTEM)
485 #define KOS32_ATTR_MASK_VOLUME (1 << KOS32_ATTR_VOLUME)
486 #define KOS32_ATTR_MASK_FOLDER (1 << KOS32_ATTR_FOLDER)
487 #define KOS32_ATTR_MASK_ARCHIVED (1 << KOS32_ATTR_ARCHIVED)
489 static inline int FileExt (struct FileExt *info, int *ret) {
490 int ret1, ret2;
491 __asm__ __volatile__ (
492 "int $0x40"
493 : "=a" (ret1),
494 "=b" (ret2)
495 : "a" (80),
496 "b" (info)
497 : "memory"
498 );
499 if (ret) *ret = ret2;
500 return ret1;
503 /* --- fn 30.4 --- */
504 static inline void SetCurrentFolderEnc (char *path, int enc) {
505 __asm__ __volatile__ (
506 "int $0x40"
508 : "a" (30),
509 "b" (4),
510 "c" (path),
511 "d" (enc)
512 : "memory"
513 );
516 /* --- fn 30.5 --- */
517 static inline int GetCurrentFolderEnc (char *buf, int maxlen, int enc) {
518 int len;
519 __asm__ __volatile__ (
520 "int $0x40"
521 : "=a" (len)
522 : "a" (30),
523 "b" (5),
524 "c" (buf),
525 "d" (maxlen),
526 "S" (enc)
527 : "memory"
528 );
529 return len;
532 #endif /* KOS32_H */