Subversion Repositories Kolibri OS

Rev

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