Subversion Repositories Kolibri OS

Rev

Rev 4874 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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