DEADSOFTWARE

kos32: initial port for KolibriOS
[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 2 --- */
190 static inline int GetKey (void) {
191 int ret;
192 __asm__ __volatile__ (
193 "int $0x40"
194 : "=a" (ret)
195 : "a" (2)
196 );
197 return ret;
200 /* --- fn 17 --- */
201 static inline int GetButton (void) {
202 int ret;
203 __asm__ __volatile__ (
204 "int $0x40"
205 : "=a" (ret)
206 : "a" (17)
207 );
208 return ret;
211 #define KOS32_INPUT_MODE_ASCII 0
212 #define KOS32_INPUT_MODE_SCANCODE 1
214 /* --- fn 66.1 --- */
215 static inline void SetInputMode (int mode) {
216 __asm__ __volatile__ (
217 "int $0x40"
219 : "a" (66),
220 "b" (1),
221 "c" (mode)
222 );
225 /* --- fn 66.2 --- */
226 static inline int GetInputMode (void) {
227 int ret;
228 __asm__ __volatile__ (
229 "int $0x40"
230 : "=a" (ret)
231 : "a" (66),
232 "b" (2)
233 );
234 return ret;
237 /* --- fn 48.4 --- */
238 static inline int GetSkinHeight (void) {
239 int ret;
240 __asm__ __volatile__ (
241 "int $0x40"
242 : "=a" (ret)
243 : "a" (48),
244 "b" (4)
245 );
246 return ret;
249 #define KOS32_SC_UNKNOWN 0x00
250 #define KOS32_SC_ESCAPE 0x01
251 #define KOS32_SC_1 0x02
252 #define KOS32_SC_2 0x03
253 #define KOS32_SC_3 0x04
254 #define KOS32_SC_4 0x05
255 #define KOS32_SC_5 0x06
256 #define KOS32_SC_6 0x07
257 #define KOS32_SC_7 0x08
258 #define KOS32_SC_8 0x09
259 #define KOS32_SC_9 0x0A
260 #define KOS32_SC_0 0x0B
261 #define KOS32_SC_MINUS 0x0C
262 #define KOS32_SC_EQUALS 0x0D
263 #define KOS32_SC_BACKSPACE 0x0E
264 #define KOS32_SC_TAB 0x0F
265 #define KOS32_SC_Q 0x10
266 #define KOS32_SC_W 0x11
267 #define KOS32_SC_E 0x12
268 #define KOS32_SC_R 0x13
269 #define KOS32_SC_T 0x14
270 #define KOS32_SC_Y 0x15
271 #define KOS32_SC_U 0x16
272 #define KOS32_SC_I 0x17
273 #define KOS32_SC_O 0x18
274 #define KOS32_SC_P 0x19
275 #define KOS32_SC_LEFTBRACKET 0x1A
276 #define KOS32_SC_RIGHTBRACKET 0x1B
277 #define KOS32_SC_RETURN 0x1C
278 #define KOS32_SC_LCTRL 0x1D
279 #define KOS32_SC_A 0x1E
280 #define KOS32_SC_S 0x1F
281 #define KOS32_SC_D 0x20
282 #define KOS32_SC_F 0x21
283 #define KOS32_SC_G 0x22
284 #define KOS32_SC_H 0x23
285 #define KOS32_SC_J 0x24
286 #define KOS32_SC_K 0x25
287 #define KOS32_SC_L 0x26
288 #define KOS32_SC_SEMICOLON 0x27
289 #define KOS32_SC_APOSTROPHE 0x28
290 #define KOS32_SC_GRAVE 0x29
291 #define KOS32_SC_LSHIFT 0x2A
292 #define KOS32_SC_BACKSLASH 0x2B
293 #define KOS32_SC_Z 0x2C
294 #define KOS32_SC_X 0x2D
295 #define KOS32_SC_C 0x2E
296 #define KOS32_SC_V 0x2F
297 #define KOS32_SC_B 0x30
298 #define KOS32_SC_N 0x31
299 #define KOS32_SC_M 0x32
300 #define KOS32_SC_COMMA 0x33
301 #define KOS32_SC_PERIOD 0x34
302 #define KOS32_SC_SLASH 0x35
303 #define KOS32_SC_RSHIFT 0x36
304 #define KOS32_SC_KP_MULTIPLY 0x37
305 #define KOS32_SC_LALT 0x38
306 #define KOS32_SC_SPACE 0x39
307 #define KOS32_SC_CAPSLOCK 0x3A
308 #define KOS32_SC_F1 0x3B
309 #define KOS32_SC_F2 0x3C
310 #define KOS32_SC_F3 0x3D
311 #define KOS32_SC_F4 0x3E
312 #define KOS32_SC_F5 0x3F
313 #define KOS32_SC_F6 0x40
314 #define KOS32_SC_F7 0x41
315 #define KOS32_SC_F8 0x42
316 #define KOS32_SC_F9 0x43
317 #define KOS32_SC_F10 0x44
318 #define KOS32_SC_NUMLOCK 0x45
319 #define KOS32_SC_SCROLLLOCK 0x46
320 #define KOS32_SC_KP_7 0x47
321 #define KOS32_SC_KP_8 0x48
322 #define KOS32_SC_KP_9 0x49
323 #define KOS32_SC_KP_MINUS 0x4A
324 #define KOS32_SC_KP_4 0x4B
325 #define KOS32_SC_KP_5 0x4C
326 #define KOS32_SC_KP_6 0x4D
327 #define KOS32_SC_KP_PLUS 0x4E
328 #define KOS32_SC_KP_1 0x4F
329 #define KOS32_SC_KP_2 0x50
330 #define KOS32_SC_KP_3 0x51
331 #define KOS32_SC_KP_0 0x52
332 #define KOS32_SC_KP_PERIOD 0x53
333 /* ... */
334 #define KOS32_SC_F11 0x57
335 #define KOS32_SC_F12 0x58
337 /* extended scancodes */
338 #define KOS32_SC_EXTENDED 0xE0 /* starts with this */
339 #define KOS32_SC_PREV_TRACK 0x10
340 #define KOS32_SC_NEXT_TRACK 0x19
341 #define KOS32_SC_KP_ENTER 0x1C
342 #define KOS32_SC_RCTRL 0x1D
343 #define KOS32_SC_MUTE 0x20
344 #define KOS32_SC_CALC 0x21
345 #define KOS32_SC_PLAY 0x22
346 #define KOS32_SC_STOP 0x24
347 #define KOS32_SC_VOLUME_DOWN 0x2E
348 #define KOS32_SC_VOLUME_UP 0x30
349 #define KOS32_SC_WWW 0x32
350 #define KOS32_SC_KP_DIVIDE 0x35
351 #define KOS32_SC_RALT 0x38
352 #define KOS32_SC_HOME 0x47
353 #define KOS32_SC_UP 0x48
354 #define KOS32_SC_PAGEUP 0x49
355 #define KOS32_SC_LEFT 0x4B
356 #define KOS32_SC_RIGHT 0x4D
357 #define KOS32_SC_END 0x4F
358 #define KOS32_SC_DOWN 0x50
359 #define KOS32_SC_PAGEDOWN 0x51
360 #define KOS32_SC_INSERT 0x52
361 #define KOS32_SC_DELETE 0x53
362 #define KOS32_SC_LSUPER 0x5B
363 #define KOS32_SC_RSUPER 0x5C
364 #define KOS32_SC_APP 0x5D
365 #define KOS32_SC_POWER 0x5E
366 #define KOS32_SC_SLEEP 0x5F
367 #define KOS32_SC_WAKE 0x63
368 #define KOS32_SC_WWW_SEARCH 0x65
369 #define KOS32_SC_WWW_FAVORITE 0x66
370 #define KOS32_SC_WWW_REFRESH 0x67
371 #define KOS32_SC_WWW_STOP 0x68
372 #define KOS32_SC_WWW_FORWARD 0x69
373 #define KOS32_SC_WWW_BACK 0x6A
374 #define KOS32_SC_MY_COMPUTER 0x6B
375 #define KOS32_SC_EMAIL 0x6C
376 #define KOS32_SC_SELECT 0x6D
378 #define KOS32_SC_EXTENDED_PAUSE 0xE1 /* pause key seq */
380 #endif /* KOS32_H */