Subversion Repositories Kolibri OS

Rev

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