Subversion Repositories Kolibri OS

Rev

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