Subversion Repositories Kolibri OS

Rev

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

Rev 6441 Rev 7172
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
// file header taken from newlib
4
// file header taken from newlib
5
// added many sys functions, compatible with tcc
5
// added many sys functions, compatible with tcc
-
 
6
// with gcc USE gcc -mno-ms-bitfields!!!
-
 
7
 
6
 
8
 
7
//#include 
9
//#include 
8
//#include 
10
//#include 
9
#include 
11
#include 
10
#include 
12
#include 
11
typedef unsigned int uint32_t;
13
typedef unsigned int uint32_t;
12
typedef int int32_t;
14
typedef int int32_t;
13
typedef unsigned char uint8_t;
15
typedef unsigned char uint8_t;
14
typedef unsigned short int uint16_t;
16
typedef unsigned short int uint16_t;
15
typedef unsigned long long uint64_t;
17
typedef unsigned long long uint64_t;
16
 
18
 
17
#ifdef __cplusplus
19
#ifdef __cplusplus
18
extern "C" {
20
extern "C" {
19
#endif
21
#endif
20
 
22
 
21
//#ifdef CONFIG_DEBUF
23
//#ifdef CONFIG_DEBUF
22
//  #define DBG(format,...) printf(format,##__VA_ARGS__)
24
//  #define DBG(format,...) printf(format,##__VA_ARGS__)
23
//#else
25
//#else
24
//  #define DBG(format,...)
26
//  #define DBG(format,...)
25
//#endif
27
//#endif
26
 
28
 
27
#define TYPE_3_BORDER_WIDTH  5
29
#define TYPE_3_BORDER_WIDTH  5
28
#define WIN_STATE_MINIMIZED  0x02
30
#define WIN_STATE_MINIMIZED  0x02
29
#define WIN_STATE_ROLLED     0x04
31
#define WIN_STATE_ROLLED     0x04
30
#define POS_SCREEN 0
32
#define POS_SCREEN 0
31
#define POS_WINDOW 1
33
#define POS_WINDOW 1
32
 
34
 
33
#define IPC_NOBUFFER 1
35
#define IPC_NOBUFFER 1
34
#define IPC_LOCKED 2
36
#define IPC_LOCKED 2
35
#define IPC_OVERFLOW 3
37
#define IPC_OVERFLOW 3
36
#define IPC_NOPID 4
38
#define IPC_NOPID 4
37
 
39
 
38
#define SHM_OPEN        0x00
40
#define SHM_OPEN        0x00
39
#define SHM_OPEN_ALWAYS 0x04
41
#define SHM_OPEN_ALWAYS 0x04
40
#define SHM_CREATE      0x08
42
#define SHM_CREATE      0x08
41
#define SHM_READ        0x00
43
#define SHM_READ        0x00
42
#define SHM_WRITE       0x01
44
#define SHM_WRITE       0x01
43
 
45
 
44
 
-
 
45
 
46
 
46
typedef  unsigned int color_t;
47
typedef  unsigned int color_t;
47
 
48
 
48
 
49
 
49
typedef union __attribute__((packed)) pos_t
50
typedef union __attribute__((packed)) pos_t
50
{
51
{
51
    uint32_t val;
52
    uint32_t val;
52
    struct
53
    struct
53
    {
54
    {
54
        short  x;
55
        short  x;
55
        short  y;
56
        short  y;
56
    };
57
    };
57
} pos_t;
58
} pos_t;
58
 
59
 
59
 
60
 
60
typedef union __attribute__((packed)) oskey_t
61
typedef union __attribute__((packed)) oskey_t
61
{
62
{
62
    uint32_t val;
63
    uint32_t val;
63
    struct
64
    struct
64
    {
65
    {
65
        uint8_t   state;
66
        uint8_t   state;
66
        uint8_t   code;
67
        uint8_t   code;
67
        uint16_t  ctrl_key;
68
        uint16_t  ctrl_key;
68
    };
69
    };
69
} oskey_t;
70
} oskey_t;
70
 
71
 
71
typedef struct
72
typedef struct
72
{
73
{
73
  unsigned      handle;
74
  unsigned      handle;
74
  unsigned      io_code;
75
  unsigned      io_code;
75
  void          *input;
76
  void          *input;
76
  int           inp_size;
77
  int           inp_size;
77
  void          *output;
78
  void          *output;
78
  int           out_size;
79
  int           out_size;
79
}ioctl_t;
80
}ioctl_t;
80
 
81
 
81
typedef union
82
typedef union
82
{
83
{
83
    struct
84
    struct
84
    {
85
    {
85
        void   *data;
86
        void   *data;
86
        size_t  size;
87
        size_t  size;
87
    } x;
88
    } x;
88
    unsigned long long raw;
89
    unsigned long long raw;
89
}ufile_t;
90
}ufile_t;
90
 
91
 
91
struct kolibri_system_colors {
92
struct kolibri_system_colors {
92
  color_t frame_area;
93
  color_t frame_area;
93
  color_t grab_bar;
94
  color_t grab_bar;
94
  color_t grab_bar_button;
95
  color_t grab_bar_button;
95
  color_t grab_button_text;
96
  color_t grab_button_text;
96
  color_t grab_text;
97
  color_t grab_text;
97
  color_t work_area;
98
  color_t work_area;
98
  color_t work_button;
99
  color_t work_button;
99
  color_t work_button_text;
100
  color_t work_button_text;
100
  color_t work_text;
101
  color_t work_text;
101
  color_t work_graph;
102
  color_t work_graph;
102
};
103
};
103
 
104
 
104
 
105
 
105
struct blit_call
106
struct blit_call
106
{
107
{
107
    int dstx;
108
    int dstx;
108
    int dsty;
109
    int dsty;
109
    int w;
110
    int w;
110
    int h;
111
    int h;
111
 
112
 
112
    int srcx;
113
    int srcx;
113
    int srcy;
114
    int srcy;
114
    int srcw;
115
    int srcw;
115
    int srch;
116
    int srch;
116
 
117
 
117
    void *bitmap;
118
    void *bitmap;
118
    int   stride;
119
    int   stride;
119
};
120
};
120
 
121
 
121
struct ipc_message
122
struct ipc_message
122
{
123
{
123
    uint32_t    pid;        // PID of sending thread
124
    uint32_t    pid;        // PID of sending thread
124
    uint32_t    datalen;    // data bytes
125
    uint32_t    datalen;    // data bytes
125
    char        data[0];    // data begin
126
    char        data[0];    // data begin
126
};
127
};
127
 
128
 
128
struct ipc_buffer
129
struct ipc_buffer
129
{
130
{
130
    uint32_t    lock;   // nonzero is locked
131
    uint32_t    lock;   // nonzero is locked
131
    uint32_t    used;   // used bytes in buffer
132
    uint32_t    used;   // used bytes in buffer
132
    struct ipc_message  data[0];    // data begin
133
    struct ipc_message  data[0];    // data begin
133
};
134
};
-
 
135
 
-
 
136
 
-
 
137
typedef struct __attribute__((packed)) file_op_t
-
 
138
{
-
 
139
	uint32_t    fn;
-
 
140
    uint32_t    flags;
-
 
141
    char*       args;
-
 
142
    uint32_t    res1, res2;
-
 
143
    char        zero;
-
 
144
    char*       app_name  
-
 
145
#ifdef __TINYC__
-
 
146
  __attribute__((packed))
-
 
147
#endif
-
 
148
;
-
 
149
} file_op_t;
-
 
150
 
134
 
151
 
135
static inline void begin_draw(void)
152
static inline void begin_draw(void)
136
{
153
{
137
    __asm__ __volatile__(
154
    __asm__ __volatile__(
138
    "int $0x40" ::"a"(12),"b"(1));
155
    "int $0x40" ::"a"(12),"b"(1));
139
};
156
};
140
 
157
 
141
static inline
158
static inline
142
void end_draw(void)
159
void end_draw(void)
143
{
160
{
144
    __asm__ __volatile__(
161
    __asm__ __volatile__(
145
    "int $0x40" ::"a"(12),"b"(2));
162
    "int $0x40" ::"a"(12),"b"(2));
146
};
163
};
147
 
164
 
148
static inline
165
static inline
149
void sys_create_window(int x, int y, int w, int h, const char *name,
166
void sys_create_window(int x, int y, int w, int h, const char *name,
150
                       color_t workcolor, uint32_t style)
167
                       color_t workcolor, uint32_t style)
151
{
168
{
152
    __asm__ __volatile__(
169
    __asm__ __volatile__(
153
    "int $0x40"
170
    "int $0x40"
154
    ::"a"(0),
171
    ::"a"(0),
155
     "b"((x << 16) | ((w-1) & 0xFFFF)),
172
     "b"((x << 16) | ((w-1) & 0xFFFF)),
156
     "c"((y << 16) | ((h-1) & 0xFFFF)),
173
     "c"((y << 16) | ((h-1) & 0xFFFF)),
157
     "d"((style << 24) | (workcolor & 0xFFFFFF)),
174
     "d"((style << 24) | (workcolor & 0xFFFFFF)),
158
     "D"(name),
175
     "D"(name),
159
     "S"(0) : "memory");
176
     "S"(0) : "memory");
160
};
177
};
161
 
178
 
162
static inline
179
static inline
163
void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color)
180
void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color)
164
{
181
{
165
    __asm__ __volatile__(
182
    __asm__ __volatile__(
166
    "int $0x40"
183
    "int $0x40"
167
    ::"a"(8),
184
    ::"a"(8),
168
      "b"(x_w),
185
      "b"(x_w),
169
      "c"(y_h),
186
      "c"(y_h),
170
      "d"(id),
187
      "d"(id),
171
      "S"(color));
188
      "S"(color));
172
};
189
};
173
 
190
 
174
static inline
191
static inline
175
void draw_line(int xs, int ys, int xe, int ye, color_t color)
192
void draw_line(int xs, int ys, int xe, int ye, color_t color)
176
{
193
{
177
    __asm__ __volatile__(
194
    __asm__ __volatile__(
178
    "int $0x40"
195
    "int $0x40"
179
    ::"a"(38), "d"(color),
196
    ::"a"(38), "d"(color),
180
      "b"((xs << 16) | xe),
197
      "b"((xs << 16) | xe),
181
      "c"((ys << 16) | ye));
198
      "c"((ys << 16) | ye));
182
}
199
}
183
 
200
 
184
static inline
201
static inline
185
void draw_bar(int x, int y, int w, int h, color_t color)
202
void draw_bar(int x, int y, int w, int h, color_t color)
186
{
203
{
187
    __asm__ __volatile__(
204
    __asm__ __volatile__(
188
    "int $0x40"
205
    "int $0x40"
189
    ::"a"(13), "d"(color),
206
    ::"a"(13), "d"(color),
190
      "b"((x << 16) | w),
207
      "b"((x << 16) | w),
191
      "c"((y << 16) | h));
208
      "c"((y << 16) | h));
192
}
209
}
193
 
210
 
194
static inline
211
static inline
195
void draw_bitmap(void *bitmap, int x, int y, int w, int h)
212
void draw_bitmap(void *bitmap, int x, int y, int w, int h)
196
{
213
{
197
    __asm__ __volatile__(
214
    __asm__ __volatile__(
198
    "int $0x40"
215
    "int $0x40"
199
    ::"a"(7), "b"(bitmap),
216
    ::"a"(7), "b"(bitmap),
200
      "c"((w << 16) | h),
217
      "c"((w << 16) | h),
201
      "d"((x << 16) | y));
218
      "d"((x << 16) | y));
202
}
219
}
203
 
220
 
204
static inline
221
static inline
205
void draw_text_sys(const char *text, int x, int y, int len, color_t color)
222
void draw_text_sys(const char *text, int x, int y, int len, color_t color)
206
{
223
{
207
    __asm__ __volatile__(
224
    __asm__ __volatile__(
208
    "int $0x40"
225
    "int $0x40"
209
    ::"a"(4),"d"(text),
226
    ::"a"(4),"d"(text),
210
      "b"((x << 16) | y),
227
      "b"((x << 16) | y),
211
      "S"(len),"c"(color)
228
      "S"(len),"c"(color)
212
     :"memory");
229
     :"memory");
213
}
230
}
214
 
231
 
215
static inline
232
static inline
216
uint32_t get_skin_height(void)
233
uint32_t get_skin_height(void)
217
{
234
{
218
    uint32_t height;
235
    uint32_t height;
219
 
236
 
220
    __asm__ __volatile__(
237
    __asm__ __volatile__(
221
    "int $0x40 \n\t"
238
    "int $0x40 \n\t"
222
    :"=a"(height)
239
    :"=a"(height)
223
    :"a"(48),"b"(4));
240
    :"a"(48),"b"(4));
224
    return height;
241
    return height;
225
};
242
};
226
 
243
 
227
static inline
244
static inline
228
pos_t get_mouse_pos(int origin)
245
pos_t get_mouse_pos(int origin)
229
{
246
{
230
    pos_t val;
247
    pos_t val;
231
 
248
 
232
    __asm__ __volatile__(
249
    __asm__ __volatile__(
233
    "int $0x40 \n\t"
250
    "int $0x40 \n\t"
234
    "rol $16, %%eax"
251
    "rol $16, %%eax"
235
    :"=a"(val)
252
    :"=a"(val)
236
    :"a"(37),"b"(origin));
253
    :"a"(37),"b"(origin));
237
    return val;
254
    return val;
238
}
255
}
239
 
256
 
240
static inline
257
static inline
241
uint32_t get_mouse_buttons(void)
258
uint32_t get_mouse_buttons(void)
242
{
259
{
243
    uint32_t val;
260
    uint32_t val;
244
 
261
 
245
    __asm__ __volatile__(
262
    __asm__ __volatile__(
246
    "int $0x40"
263
    "int $0x40"
247
    :"=a"(val)
264
    :"=a"(val)
248
    :"a"(37),"b"(2));
265
    :"a"(37),"b"(2));
249
    return val;
266
    return val;
250
};
267
};
251
 
268
 
252
static inline
269
static inline
253
uint32_t get_mouse_wheels(void)
270
uint32_t get_mouse_wheels(void)
254
{
271
{
255
    uint32_t val;
272
    uint32_t val;
256
 
273
 
257
    __asm__ __volatile__(
274
    __asm__ __volatile__(
258
    "int $0x40 \n\t"
275
    "int $0x40 \n\t"
259
    :"=a"(val)
276
    :"=a"(val)
260
    :"a"(37),"b"(7));
277
    :"a"(37),"b"(7));
261
    return val;
278
    return val;
262
};
279
};
263
 
280
 
264
static inline uint32_t load_cursor(void *path, uint32_t flags)
281
static inline uint32_t load_cursor(void *path, uint32_t flags)
265
{
282
{
266
    uint32_t  val;
283
    uint32_t  val;
267
    __asm__ __volatile__(
284
    __asm__ __volatile__(
268
    "int $0x40"
285
    "int $0x40"
269
    :"=a"(val)
286
    :"=a"(val)
270
    :"a"(37), "b"(4), "c"(path), "d"(flags));
287
    :"a"(37), "b"(4), "c"(path), "d"(flags));
271
    return val;
288
    return val;
272
}
289
}
273
 
290
 
274
static inline uint32_t  set_cursor(uint32_t  cursor)
291
static inline uint32_t  set_cursor(uint32_t  cursor)
275
{
292
{
276
    uint32_t  old;
293
    uint32_t  old;
277
    __asm__ __volatile__(
294
    __asm__ __volatile__(
278
    "int $0x40"
295
    "int $0x40"
279
    :"=a"(old)
296
    :"=a"(old)
280
    :"a"(37), "b"(5), "c"(cursor));
297
    :"a"(37), "b"(5), "c"(cursor));
281
    return old;
298
    return old;
282
};
299
};
283
 
300
 
284
static inline int destroy_cursor(uint32_t cursor)
301
static inline int destroy_cursor(uint32_t cursor)
285
{
302
{
286
    int ret;
303
    int ret;
287
    __asm__ __volatile__(
304
    __asm__ __volatile__(
288
    "int $0x40"
305
    "int $0x40"
289
    :"=a"(ret)
306
    :"=a"(ret)
290
    :"a"(37), "b"(6), "c"(cursor)
307
    :"a"(37), "b"(6), "c"(cursor)
291
    :"memory");
308
    :"memory");
292
    return ret;
309
    return ret;
293
};
310
};
294
 
311
 
295
 
312
 
296
static inline
313
static inline
297
uint32_t wait_for_event(uint32_t time)
314
uint32_t wait_for_event(uint32_t time)
298
{
315
{
299
    uint32_t val;
316
    uint32_t val;
300
    __asm__ __volatile__(
317
    __asm__ __volatile__(
301
    "int $0x40"
318
    "int $0x40"
302
    :"=a"(val)
319
    :"=a"(val)
303
    :"a"(23), "b"(time));
320
    :"a"(23), "b"(time));
304
    return val;
321
    return val;
305
};
322
};
306
 
323
 
307
static inline uint32_t check_os_event()
324
static inline uint32_t check_os_event()
308
{
325
{
309
    uint32_t val;
326
    uint32_t val;
310
    __asm__ __volatile__(
327
    __asm__ __volatile__(
311
    "int $0x40"
328
    "int $0x40"
312
    :"=a"(val)
329
    :"=a"(val)
313
    :"a"(11));
330
    :"a"(11));
314
    return val;
331
    return val;
315
};
332
};
316
 
333
 
317
static inline uint32_t get_os_event()
334
static inline uint32_t get_os_event()
318
{
335
{
319
    uint32_t val;
336
    uint32_t val;
320
    __asm__ __volatile__(
337
    __asm__ __volatile__(
321
    "int $0x40"
338
    "int $0x40"
322
    :"=a"(val)
339
    :"=a"(val)
323
    :"a"(10));
340
    :"a"(10));
324
    return val;
341
    return val;
325
};
342
};
326
 
343
 
327
static inline
344
static inline
328
uint32_t get_tick_count(void)
345
uint32_t get_tick_count(void)
329
{
346
{
330
    uint32_t val;
347
    uint32_t val;
331
    __asm__ __volatile__(
348
    __asm__ __volatile__(
332
    "int $0x40"
349
    "int $0x40"
333
    :"=a"(val)
350
    :"=a"(val)
334
    :"a"(26),"b"(9));
351
    :"a"(26),"b"(9));
335
    return val;
352
    return val;
336
};
353
};
337
 
354
 
338
static inline
355
static inline
339
uint64_t get_ns_count(void)
356
uint64_t get_ns_count(void)
340
{
357
{
341
    uint64_t val;
358
    uint64_t val;
342
    __asm__ __volatile__(
359
    __asm__ __volatile__(
343
    "int $0x40"
360
    "int $0x40"
344
    :"=A"(val)
361
    :"=A"(val)
345
    :"a"(26), "b"(10));
362
    :"a"(26), "b"(10));
346
    return val;
363
    return val;
347
};
364
};
348
 
365
 
349
static inline
366
static inline
350
oskey_t get_key(void)
367
oskey_t get_key(void)
351
{
368
{
352
    oskey_t val;
369
    oskey_t val;
353
    __asm__ __volatile__(
370
    __asm__ __volatile__(
354
    "int $0x40"
371
    "int $0x40"
355
    :"=a"(val)
372
    :"=a"(val)
356
    :"a"(2));
373
    :"a"(2));
357
    return val;
374
    return val;
358
}
375
}
359
 
376
 
360
static inline
377
static inline
361
uint32_t get_os_button()
378
uint32_t get_os_button()
362
{
379
{
363
    uint32_t val;
380
    uint32_t val;
364
    __asm__ __volatile__(
381
    __asm__ __volatile__(
365
    "int $0x40"
382
    "int $0x40"
366
    :"=a"(val)
383
    :"=a"(val)
367
    :"a"(17));
384
    :"a"(17));
368
    return val>>8;
385
    return val>>8;
369
};
386
};
370
 
387
 
371
static inline uint32_t get_service(char *name)
388
static inline uint32_t get_service(char *name)
372
{
389
{
373
    uint32_t retval = 0;
390
    uint32_t retval = 0;
374
    __asm__ __volatile__(
391
    __asm__ __volatile__(
375
    "int $0x40"
392
    "int $0x40"
376
    :"=a"(retval)
393
    :"=a"(retval)
377
    :"a"(68),"b"(16),"c"(name)
394
    :"a"(68),"b"(16),"c"(name)
378
    :"memory");
395
    :"memory");
379
 
396
 
380
    return retval;
397
    return retval;
381
};
398
};
382
 
399
 
383
static inline int call_service(ioctl_t *io)
400
static inline int call_service(ioctl_t *io)
384
{
401
{
385
    int retval;
402
    int retval;
386
 
403
 
387
    __asm__ __volatile__(
404
    __asm__ __volatile__(
388
    "int $0x40"
405
    "int $0x40"
389
    :"=a"(retval)
406
    :"=a"(retval)
390
    :"a"(68),"b"(17),"c"(io)
407
    :"a"(68),"b"(17),"c"(io)
391
    :"memory","cc");
408
    :"memory","cc");
392
 
409
 
393
    return retval;
410
    return retval;
394
};
411
};
395
 
412
 
396
 
413
 
397
static inline void yield(void)
414
static inline void yield(void)
398
{
415
{
399
    __asm__ __volatile__(
416
    __asm__ __volatile__(
400
    "int $0x40"
417
    "int $0x40"
401
    ::"a"(68), "b"(1));
418
    ::"a"(68), "b"(1));
402
};
419
};
403
 
420
 
404
static inline void delay(uint32_t time)
421
static inline void delay(uint32_t time)
405
{
422
{
406
    __asm__ __volatile__(
423
    __asm__ __volatile__(
407
    "int $0x40"
424
    "int $0x40"
408
    ::"a"(5), "b"(time)
425
    ::"a"(5), "b"(time)
409
    :"memory");
426
    :"memory");
410
};
427
};
411
 
428
 
412
static inline
429
static inline
413
void *user_alloc(size_t size)
430
void *user_alloc(size_t size)
414
{
431
{
415
    void  *val;
432
    void  *val;
416
    __asm__ __volatile__(
433
    __asm__ __volatile__(
417
    "int $0x40"
434
    "int $0x40"
418
    :"=a"(val)
435
    :"=a"(val)
419
    :"a"(68),"b"(12),"c"(size));
436
    :"a"(68),"b"(12),"c"(size));
420
    return val;
437
    return val;
421
}
438
}
422
 
439
 
423
static inline
440
static inline
424
int user_free(void *mem)
441
int user_free(void *mem)
425
{
442
{
426
    int  val;
443
    int  val;
427
    __asm__ __volatile__(
444
    __asm__ __volatile__(
428
    "int $0x40"
445
    "int $0x40"
429
    :"=a"(val)
446
    :"=a"(val)
430
    :"a"(68),"b"(13),"c"(mem));
447
    :"a"(68),"b"(13),"c"(mem));
431
    return val;
448
    return val;
432
}
449
}
433
 
450
 
434
static inline
451
static inline
435
void* user_realloc(void *mem, size_t size)
452
void* user_realloc(void *mem, size_t size)
436
{
453
{
437
    void *val;
454
    void *val;
438
    __asm__ __volatile__(
455
    __asm__ __volatile__(
439
    "int $0x40"
456
    "int $0x40"
440
    :"=a"(val)
457
    :"=a"(val)
441
    :"a"(68),"b"(20),"c"(size),"d"(mem)
458
    :"a"(68),"b"(20),"c"(size),"d"(mem)
442
    :"memory");
459
    :"memory");
443
 
460
 
444
    return val;
461
    return val;
445
};
462
};
446
 
463
 
447
static inline
464
static inline
448
int *user_unmap(void *base, size_t offset, size_t size)
465
int *user_unmap(void *base, size_t offset, size_t size)
449
{
466
{
450
    int  *val;
467
    int  *val;
451
    __asm__ __volatile__(
468
    __asm__ __volatile__(
452
    "int $0x40"
469
    "int $0x40"
453
    :"=a"(val)
470
    :"=a"(val)
454
    :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
471
    :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
455
    return val;
472
    return val;
456
};
473
};
457
 
474
 
458
static inline ufile_t load_file(const char *path)
475
static inline ufile_t load_file(const char *path)
459
{
476
{
460
    ufile_t uf;
477
    ufile_t uf;
461
 
478
 
462
    __asm__ __volatile__ (
479
    __asm__ __volatile__ (
463
    "int $0x40"
480
    "int $0x40"
464
    :"=A"(uf.raw)
481
    :"=A"(uf.raw)
465
    :"a" (68), "b"(27),"c"(path));
482
    :"a" (68), "b"(27),"c"(path));
466
 
483
 
467
    return uf;
484
    return uf;
468
};
485
};
469
 
486
 
470
static inline int GetScreenSize()
487
static inline int GetScreenSize()
471
{
488
{
472
    int retval;
489
    int retval;
473
 
490
 
474
    __asm__ __volatile__(
491
    __asm__ __volatile__(
475
    "int $0x40"
492
    "int $0x40"
476
    :"=a"(retval)
493
    :"=a"(retval)
477
    :"a"(61), "b"(1));
494
    :"a"(61), "b"(1));
478
    return retval;
495
    return retval;
479
}
496
}
480
 
497
 
481
 
498
 
482
static inline void get_proc_info(char *info)
499
static inline void get_proc_info(char *info)
483
{
500
{
484
    __asm__ __volatile__(
501
    __asm__ __volatile__(
485
    "int $0x40"
502
    "int $0x40"
486
    :
503
    :
487
    :"a"(9), "b"(info), "c"(-1)
504
    :"a"(9), "b"(info), "c"(-1)
488
    :"memory");
505
    :"memory");
489
};
506
};
490
 
507
 
491
static inline void Blit(void *bitmap, int dst_x, int dst_y,
508
static inline void Blit(void *bitmap, int dst_x, int dst_y,
492
                        int src_x, int src_y, int w, int h,
509
                        int src_x, int src_y, int w, int h,
493
                        int src_w, int src_h, int stride)
510
                        int src_w, int src_h, int stride)
494
{
511
{
495
    volatile struct blit_call bc;
512
    volatile struct blit_call bc;
496
 
513
 
497
    bc.dstx = dst_x;
514
    bc.dstx = dst_x;
498
    bc.dsty = dst_y;
515
    bc.dsty = dst_y;
499
    bc.w    = w;
516
    bc.w    = w;
500
    bc.h    = h;
517
    bc.h    = h;
501
    bc.srcx = src_x;
518
    bc.srcx = src_x;
502
    bc.srcy = src_y;
519
    bc.srcy = src_y;
503
    bc.srcw = src_w;
520
    bc.srcw = src_w;
504
    bc.srch = src_h;
521
    bc.srch = src_h;
505
    bc.stride = stride;
522
    bc.stride = stride;
506
    bc.bitmap = bitmap;
523
    bc.bitmap = bitmap;
507
 
524
 
508
    __asm__ __volatile__(
525
    __asm__ __volatile__(
509
    "int $0x40"
526
    "int $0x40"
510
    ::"a"(73),"b"(0),"c"(&bc.dstx));
527
    ::"a"(73),"b"(0),"c"(&bc.dstx));
511
};
528
};
512
 
529
 
513
 
530
 
514
// newlib exclusive
531
// newlib exclusive
515
#ifndef __TINYC__
532
#ifndef __TINYC__
516
int create_thread(int (*proc)(void *param), void *param, int stack_size);
533
int create_thread(int (*proc)(void *param), void *param, int stack_size);
517
 
534
 
518
void* load_library(const char *name);
535
void* load_library(const char *name);
519
 
536
 
520
void* get_proc_address(void *handle, const char *proc_name);
537
void* get_proc_address(void *handle, const char *proc_name);
521
 
538
 
522
void enumerate_libraries(int (*callback)(void *handle, const char* name,
539
void enumerate_libraries(int (*callback)(void *handle, const char* name,
523
                                         uint32_t base, uint32_t size, void *user_data),
540
                                         uint32_t base, uint32_t size, void *user_data),
524
                         void *user_data);
541
                         void *user_data);
525
#endif
542
#endif
-
 
543
 
526
 
544
///////////////////////////////////////////////////////////////////////////////
-
 
545
/// May be next section need to be added in newlibc
-
 
546
// Siemargl addenium
-
 
547
 
527
// May be next section need to be added in newlibc
548
#define X_Y(x,y) (((x)<<16)|(y))
528
 
549
 
529
enum KOLIBRI_GUI_EVENTS {
550
enum KOLIBRI_GUI_EVENTS {
530
    KOLIBRI_EVENT_NONE = 0,     /* Event queue is empty */
551
    KOLIBRI_EVENT_NONE = 0,     /* Event queue is empty */
531
    KOLIBRI_EVENT_REDRAW = 1,   /* Window and window elements should be redrawn */
552
    KOLIBRI_EVENT_REDRAW = 1,   /* Window and window elements should be redrawn */
532
    KOLIBRI_EVENT_KEY = 2,      /* A key on the keyboard was pressed */
553
    KOLIBRI_EVENT_KEY = 2,      /* A key on the keyboard was pressed */
533
    KOLIBRI_EVENT_BUTTON = 3,   /* A button was clicked with the mouse */
554
    KOLIBRI_EVENT_BUTTON = 3,   /* A button was clicked with the mouse */
534
    KOLIBRI_EVENT_DESKTOP = 5,  /* Desktop redraw finished */
555
    KOLIBRI_EVENT_DESKTOP = 5,  /* Desktop redraw finished */
535
    KOLIBRI_EVENT_MOUSE = 6,    /* Mouse activity (movement, button press) was detected */
556
    KOLIBRI_EVENT_MOUSE = 6,    /* Mouse activity (movement, button press) was detected */
536
    KOLIBRI_EVENT_IPC = 7,      /* Interprocess communication notify */
557
    KOLIBRI_EVENT_IPC = 7,      /* Interprocess communication notify */
537
    KOLIBRI_EVENT_NETWORK = 8,  /* Network event */
558
    KOLIBRI_EVENT_NETWORK = 8,  /* Network event */
538
    KOLIBRI_EVENT_DEBUG = 9,    /* Debug subsystem event */
559
    KOLIBRI_EVENT_DEBUG = 9,    /* Debug subsystem event */
539
    KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */
560
    KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */
540
};
561
};
-
 
562
 
-
 
563
enum control_keys {
-
 
564
    KM_SHIFT = 0x00010000,
-
 
565
    KM_CTRL = 0x00020000,
-
 
566
    KM_ALT = 0x00040000,
-
 
567
    KM_NUMLOCK = 0x00080000
-
 
568
};
-
 
569
 
-
 
570
 
-
 
571
struct  __attribute__ ((__packed__)) fs_dirinfo {
-
 
572
    uint32_t    subfn; // 1 read dir
-
 
573
    uint32_t    start;
-
 
574
    uint32_t    flags;
-
 
575
    uint32_t    size;
-
 
576
    uint32_t    retval;
-
 
577
    union {
-
 
578
        struct __attribute__ ((__packed__)) {
-
 
579
            uint8_t zero;  // 0
-
 
580
            char*   ppath;
-
 
581
        };
-
 
582
        char path[5];  // up to 4096
-
 
583
    } ;
-
 
584
};
-
 
585
 
-
 
586
static inline
-
 
587
uint32_t sf_file(int subfn, struct fs_dirinfo* dinfo)
-
 
588
/// SysFn70 call with subfunction
-
 
589
/// retval 0 if ok
-
 
590
{
-
 
591
    uint32_t retval;
-
 
592
    dinfo->subfn = subfn;
-
 
593
 
-
 
594
    __asm__ __volatile__(
-
 
595
    "int $0x40 "
-
 
596
    :"=a"(retval)
-
 
597
    :"a"(70),"b"(dinfo)
-
 
598
    :);
-
 
599
 
-
 
600
    return retval;
-
 
601
};
-
 
602
 
-
 
603
 
-
 
604
struct fs_dirheader {
-
 
605
    uint32_t     version; // 1
-
 
606
    uint32_t     curn_blocks;  // number of read dir items (BDFE)
-
 
607
    uint32_t     totl_blocks;  // directory full size
-
 
608
    char         other[20]; // reserved 0
-
 
609
};
-
 
610
 
-
 
611
enum filetype
-
 
612
{
-
 
613
	FS_RONLY = 1,
-
 
614
	FS_HIDDEN = 2,
-
 
615
	FS_SYSTEM = 4,
-
 
616
	FS_VOLID = 8,
-
 
617
	FS_SUBDIR = 16,
-
 
618
	FS_FOLDER = 16,
-
 
619
	FS_ARCHIV = 32
-
 
620
};
-
 
621
 
-
 
622
struct __attribute__ ((__packed__)) fs_filetime {
-
 
623
    uint8_t    sec;
-
 
624
    uint8_t    mm;
-
 
625
    uint8_t    hour;
-
 
626
    uint8_t    zero;
-
 
627
};
-
 
628
 
-
 
629
struct __attribute__ ((__packed__)) fs_filedate {
-
 
630
    uint8_t    day;
-
 
631
    uint8_t    month;
-
 
632
    uint16_t   year;
-
 
633
};
-
 
634
 
-
 
635
/// directory entry cp866
-
 
636
struct fsBDFE {
-
 
637
    uint32_t filetype;
-
 
638
    uint32_t encoding; // 0 - cp866, 1 - utf16le
-
 
639
    struct fs_filetime tm_created;
-
 
640
    struct fs_filedate dt_created;
-
 
641
    struct fs_filetime tm_accessed;
-
 
642
    struct fs_filedate dt_accessed;
-
 
643
    struct fs_filetime tm_modified;
-
 
644
    struct fs_filedate dt_modified;
-
 
645
    uint64_t size;
-
 
646
    char   fname[264];
-
 
647
}; // must be sized 304
-
 
648
 
-
 
649
/// directory entry UTF16LE
-
 
650
struct fsBDFE_16 {
-
 
651
    uint32_t filetype;
-
 
652
    uint32_t encoding; // 0 - cp866, 1 - utf16le
-
 
653
    struct fs_filetime tm_created;
-
 
654
    struct fs_filedate dt_created;
-
 
655
    struct fs_filetime tm_accessed;
-
 
656
    struct fs_filedate dt_accessed;
-
 
657
    struct fs_filetime tm_modified;
-
 
658
    struct fs_filedate dt_modified;
-
 
659
    uint64_t size;
-
 
660
    wchar_t   fname[260];
-
 
661
}; // must be sized 560
-
 
662
 
541
 
663
 
542
 
664
 
543
// copied from /programs/system/shell/system/kolibri.c
665
// copied from /programs/system/shell/system/kolibri.c
544
// fn's returned -1 as syserror, 1 as error, 0 as OK
666
// fn's returned -1 as syserror, 1 as error, 0 as OK
545
static inline
667
static inline
546
int kol_clip_num()
668
int kol_clip_num()
547
{
669
{
548
    register uint32_t val;
670
    register uint32_t val;
549
    asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(0));
671
    asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(0));
550
    return val;
672
    return val;
551
}
673
}
552
 
674
 
553
static inline
675
static inline
554
char* kol_clip_get(int n)
676
char* kol_clip_get(int n)
555
// returned buffer must be freed by user_free()
677
// returned buffer must be freed by user_free()
556
{
678
{
557
    register char* val;
679
    register char* val;
558
    asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(1), "c"(n));
680
    asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(1), "c"(n));
559
    return val;
681
    return val;
560
}
682
}
561
 
683
 
562
static inline
684
static inline
563
int kol_clip_set(int n, char buffer[])
685
int kol_clip_set(int n, char buffer[])
564
{
686
{
565
    register uint32_t val;
687
    register uint32_t val;
566
    asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(2), "c"(n), "d"(buffer));
688
    asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(2), "c"(n), "d"(buffer));
567
    return val;
689
    return val;
568
}
690
}
569
 
691
 
570
static inline
692
static inline
571
int kol_clip_pop()
693
int kol_clip_pop()
572
{
694
{
573
    register uint32_t val;
695
    register uint32_t val;
574
    asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(3));
696
    asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(3));
575
    return val;
697
    return val;
576
}
698
}
577
 
699
 
578
static inline
700
static inline
579
int kol_clip_unlock()
701
int kol_clip_unlock()
580
{
702
{
581
    register uint32_t val;
703
    register uint32_t val;
582
    asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(4));
704
    asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(4));
583
    return val;
705
    return val;
584
}
706
}
585
 
707
 
586
static inline void get_system_colors(struct kolibri_system_colors *color_table)
708
static inline void get_system_colors(struct kolibri_system_colors *color_table)
587
{
709
{
588
  __asm__ volatile ("int $0x40"
710
  __asm__ volatile ("int $0x40"
589
		    :
711
		    :
590
		    :"a"(48),"b"(3),"c"(color_table),"d"(40)
712
		    :"a"(48),"b"(3),"c"(color_table),"d"(40)
591
		    );
713
		    );
592
 
714
 
593
  /* color_table should point to the system color table */
715
  /* color_table should point to the system color table */
594
}
716
}
595
 
717
 
596
static inline void debug_board_write_byte(const char ch){
718
static inline void debug_board_write_byte(const char ch){
597
    __asm__ __volatile__(
719
    __asm__ __volatile__(
598
    "int $0x40"
720
    "int $0x40"
599
    :
721
    :
600
    :"a"(63), "b"(1), "c"(ch));
722
    :"a"(63), "b"(1), "c"(ch));
601
}
723
}
602
 
724
 
603
 
725
 
604
static inline void draw_number_sys(int32_t number, int x, int y, int len, color_t color){
726
static inline void draw_number_sys(int32_t number, int x, int y, int len, color_t color){
605
    register uint32_t fmt;
727
    register uint32_t fmt;
606
    fmt = len << 16 | 0x80000000; // no leading zeros + width
728
    fmt = len << 16 | 0x80000000; // no leading zeros + width
607
//    fmt = len << 16 | 0x00000000; //  leading zeros + width
729
//    fmt = len << 16 | 0x00000000; //  leading zeros + width
608
    __asm__ __volatile__(
730
    __asm__ __volatile__(
609
    "int $0x40"
731
    "int $0x40"
610
    :
732
    :
611
    :"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color));
733
    :"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color));
612
}
734
}
613
 
735
 
614
static inline
736
static inline
615
uint32_t get_mouse_eventstate(void)
737
uint32_t get_mouse_eventstate(void)
616
{
738
{
617
    uint32_t val;
739
    uint32_t val;
618
 
740
 
619
    __asm__ __volatile__(
741
    __asm__ __volatile__(
620
    "int $0x40"
742
    "int $0x40"
621
    :"=a"(val)
743
    :"=a"(val)
622
    :"a"(37),"b"(3));
744
    :"a"(37),"b"(3));
623
    return val;
745
    return val;
624
};
746
};
625
 
747
 
626
static inline
748
static inline
627
uint32_t set_event_mask(uint32_t mask)
749
uint32_t set_event_mask(uint32_t mask)
628
{
750
{
629
    register uint32_t val;
751
    register uint32_t val;
630
    asm volatile ("int $0x40":"=a"(val):"a"(40), "b"(mask));
752
    asm volatile ("int $0x40":"=a"(val):"a"(40), "b"(mask));
631
    return val;
753
    return val;
632
}
754
}
633
 
755
 
634
typedef void (*thread_proc)(void*);
756
typedef void (*thread_proc)(void*);
635
 
757
 
636
static inline
758
static inline
637
int start_thread(thread_proc proc, char* stack_top)
759
int start_thread(thread_proc proc, char* stack_top)
638
{
760
{
639
    register int val;
761
    register int val;
640
    asm volatile ("int $0x40":"=a"(val):"a"(51), "b"(1), "c"(proc), "d"(stack_top));
762
    asm volatile ("int $0x40":"=a"(val):"a"(51), "b"(1), "c"(proc), "d"(stack_top));
641
    return val;
763
    return val;
642
}
764
}
643
 
765
 
644
static inline
766
static inline
645
void kos_exit()
767
void kos_exit()
646
{
768
{
647
    asm volatile ("int $0x40"::"a"(-1));
769
    asm volatile ("int $0x40"::"a"(-1));
648
}
770
}
649
 
771
 
650
static inline void focus_window(int slot){
772
static inline void focus_window(int slot){
651
    asm volatile ("int $0x40"::"a"(18), "b"(3), "c"(slot));
773
    asm volatile ("int $0x40"::"a"(18), "b"(3), "c"(slot));
652
}
774
}
653
 
775
 
654
static inline int get_thread_slot(int tid){
776
static inline int get_thread_slot(int tid){
655
    register int val;
777
    register int val;
656
    asm volatile ("int $0x40":"=a"(val):"a"(18), "b"(21), "c"(tid));
778
    asm volatile ("int $0x40":"=a"(val):"a"(18), "b"(21), "c"(tid));
657
    return val;
779
    return val;
658
}
780
}
659
 
781
 
660
static inline void set_current_folder(char* dir){
782
static inline void set_current_folder(char* dir){
661
    asm volatile ("int $0x40"::"a"(30), "b"(1), "c"(dir));
783
    asm volatile ("int $0x40"::"a"(30), "b"(1), "c"(dir));
662
}
784
}
663
 
785
 
664
static inline int get_current_folder(char* buf, int bufsize){
786
static inline int get_current_folder(char* buf, int bufsize){
665
    register int val;
787
    register int val;
666
    asm volatile ("int $0x40":"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize));
788
    asm volatile ("int $0x40":"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize));
667
    return val;
789
    return val;
668
}
790
}
669
 
791
 
670
static inline
792
static inline
671
void ipc_set_area(void* buf, int bufsize){
793
void ipc_set_area(void* buf, int bufsize){
672
    asm volatile ("int $0x40"::"a"(60), "b"(1), "c"(buf), "d"(bufsize));
794
    asm volatile ("int $0x40"::"a"(60), "b"(1), "c"(buf), "d"(bufsize));
673
}
795
}
674
 
796
 
675
static inline
797
static inline
676
int ipc_send_message(int pid_reciever, void *data, int datalen) {
798
int ipc_send_message(int pid_reciever, void *data, int datalen) {
677
    register int val;
799
    register int val;
678
    asm volatile ("int $0x40":"=a"(val):"a"(60), "b"(2), "c"(pid_reciever), "d"(data), "S"(datalen));
800
    asm volatile ("int $0x40":"=a"(val):"a"(60), "b"(2), "c"(pid_reciever), "d"(data), "S"(datalen));
679
    return val;
801
    return val;
680
}
802
}
681
 
803
 
682
static inline
804
static inline
683
void* shm_open(char *shm_name, int msize, int flags, int *retsz){
805
void* shm_open(char *shm_name, int msize, int flags, int *retsz){
684
    register int val, cod;
806
    register int val, cod;
685
    asm volatile ("int $0x40":"=a"(val),"=d"(cod):"a"(68), "b"(22), "c"(shm_name), "d"(msize), "S"(flags));
807
    asm volatile ("int $0x40":"=a"(val),"=d"(cod):"a"(68), "b"(22), "c"(shm_name), "d"(msize), "S"(flags));
686
 
808
 
687
    if(retsz) *retsz = cod;  // errcode if NULL or memsize when open
809
    if(retsz) *retsz = cod;  // errcode if NULL or memsize when open
688
    return (void*)val;
810
    return (void*)val;
689
}
811
}
690
 
812
 
691
static inline
813
static inline
692
void shm_close(char *shm_name){
814
void shm_close(char *shm_name){
693
    asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(shm_name));
815
    asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(shm_name));
694
}
816
}
695
 
817
 
696
static inline
818
static inline
697
int start_app(char *app_name, char *args){
819
int start_app(char *app_name, char *args){
698
    struct file_op_t
820
    file_op_t file_op;
699
    {
-
 
700
        uint32_t    fn;
-
 
701
        uint32_t    flags;
-
 
702
        char*       args;
-
 
703
        uint32_t    res1, res2;
-
 
704
        char        zero;
-
 
705
        char*       app_name  __attribute__((packed));
-
 
706
    } file_op;
-
 
707
    memset(&file_op, 0, sizeof(file_op));
821
    memset(&file_op, 0, sizeof(file_op));
708
    file_op.fn = 7;
822
    file_op.fn = 7;
709
    file_op.args = args;
823
    file_op.args = args;
710
    file_op.app_name = app_name;
824
    file_op.app_name = app_name;
711
 
825
 
712
    register int val;
826
    register int val;
713
    asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op));
827
    asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op));
714
 
828
 
715
    return val;
829
    return val;
716
}
830
}
-
 
831
 
-
 
832
static inline
-
 
833
uint32_t get_control_keys(void)
-
 
834
{
-
 
835
    uint32_t ctrl;
-
 
836
 
-
 
837
    __asm__ __volatile__(
-
 
838
    "int $0x40 \n\t"
-
 
839
    :"=a"(ctrl)
-
 
840
    :"a"(66),"b"(3));
-
 
841
 
-
 
842
    return ctrl;
-
 
843
};
-
 
844
 
-
 
845
static inline
-
 
846
int get_keyboard_layout(int opt, char* buf)
-
 
847
/// 128 byte buffer
-
 
848
/// opt: 1 - normal, 2 - shifted, 3 - alted, or 9 - return language
-
 
849
{
-
 
850
    uint32_t lang;
-
 
851
 
-
 
852
    __asm__ __volatile__(
-
 
853
    "int $0x40 \n\t"
-
 
854
    :"=a"(lang)
-
 
855
    :"a"(26),"b"(2), "c"(opt), "d"(buf));
-
 
856
 
-
 
857
    return lang;
-
 
858
};
-
 
859
 
-
 
860
 
-
 
861
static inline
-
 
862
int font_size(int color)
-
 
863
/// decode font size in pixels from color as SysFn4
-
 
864
/// returns (width, hight)
-
 
865
{            
-
 
866
    int font = color >> 24;
-
 
867
    int font_multipl = (font & 7) + 1;
-
 
868
	int width_sym, hight_sym;
-
 
869
 
-
 
870
    if (font & 0x10) // 8x16
-
 
871
    {
-
 
872
        width_sym = 8 * font_multipl;
-
 
873
        hight_sym = 16 * font_multipl;
-
 
874
    } else   // 6x9
-
 
875
    {
-
 
876
        width_sym = 6 * font_multipl;
-
 
877
        hight_sym = 9 * font_multipl;
-
 
878
    }
-
 
879
    return hight_sym + (width_sym << 16);
717
 
880
}
718
 
881
 
719
/*
882
/*
720
static inline char *getcwd(char *buf, size_t size)
883
static inline char *getcwd(char *buf, size_t size)
721
{
884
{
722
	int rc = get_current_folder(buf, size);
885
	int rc = get_current_folder(buf, size);
723
	if (rc > size)
886
	if (rc > size)
724
	{
887
	{
725
		errno = ERANGE;
888
		errno = ERANGE;
726
		return 0;
889
		return 0;
727
	}
890
	}
728
	else
891
	else
729
		return buf;
892
		return buf;
730
}
893
}
731
*/
894
*/
-
 
895
/* not finished
-
 
896
void staticnum_draw(staticnum *st)
-
 
897
{
-
 
898
    register uint32_t fmt;
-
 
899
    if (st->width < 0)
-
 
900
        fmt = (-st->width << 16); // leading zeros, decimal
-
 
901
    else
-
 
902
        fmt = (st->width << 16) | 0x80000000; // no leading zeros, decimal
-
 
903
 
-
 
904
    __asm__ __volatile__(
-
 
905
    "int $0x40"
-
 
906
    ::"a"(47),
-
 
907
      "b"(fmt),
-
 
908
      "c"(st->number),
-
 
909
      "d"(st->start_xy),
-
 
910
      "S"(st->color_flags),
-
 
911
      "D"(st->bg_color)
-
 
912
    :);
-
 
913
}
-
 
914
 
-
 
915
*/
732
// end section
916
//////////// end section
733
 
917
 
734
 
918
 
735
 
919
 
736
//added nonstatic inline because incomfortabre stepping in in debugger
920
//added nonstatic inline because incomfortabre stepping in in debugger
737
void __attribute__ ((noinline)) debug_board_write_str(const char* str);
921
void __attribute__ ((noinline)) debug_board_write_str(const char* str);
738
void __attribute__ ((noinline)) debug_board_printf(const char *format,...);
922
void __attribute__ ((noinline)) debug_board_printf(const char *format,...);
739
 
923
 
740
/* copy body to only one project file
924
/* copy body to only one project file
741
void __attribute__ ((noinline)) debug_board_write_str(const char* str){
925
void __attribute__ ((noinline)) debug_board_write_str(const char* str){
742
  while(*str)
926
  while(*str)
743
    debug_board_write_byte(*str++);
927
    debug_board_write_byte(*str++);
744
}
928
}
745
 
929
 
746
void __attribute__ ((noinline)) debug_board_printf(const char *format,...)
930
void __attribute__ ((noinline)) debug_board_printf(const char *format,...)
747
{
931
{
748
        va_list ap;
932
        va_list ap;
749
        char log_board[300];
933
        char log_board[300];
750
 
934
 
751
        va_start (ap, format);
935
        va_start (ap, format);
752
        vsnprintf(log_board, sizeof log_board, format, ap);
936
        vsnprintf(log_board, sizeof log_board, format, ap);
753
        va_end(ap);
937
        va_end(ap);
754
        debug_board_write_str(log_board);
938
        debug_board_write_str(log_board);
755
}
939
}
-
 
940
 
-
 
941
__attribute__ ((noinline)) void trap(int n)
-
 
942
{
-
 
943
    // nothing todo, just see n in debugger. use "bp trap" command
-
 
944
    __asm__ __volatile__(
-
 
945
    "nop"
-
 
946
    :
-
 
947
    :"a"(n));
-
 
948
}
-
 
949
 
756
*/
950
*/
757
 
951
 
758
 
952
 
759
 
953
 
760
// TinyC don't support aliasing of static inline funcs
954
// TinyC don't support aliasing of static inline funcs
761
#ifndef __TINYC__
955
#ifndef __TINYC__
762
static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw")));
956
static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw")));
763
static inline void EndDraw(void) __attribute__ ((alias ("end_draw")));
957
static inline void EndDraw(void) __attribute__ ((alias ("end_draw")));
764
static inline void DrawWindow(int x, int y, int w, int h, const char *name,
958
static inline void DrawWindow(int x, int y, int w, int h, const char *name,
765
                              color_t workcolor, uint32_t style)
959
                              color_t workcolor, uint32_t style)
766
                              __attribute__ ((alias ("sys_create_window")));
960
                              __attribute__ ((alias ("sys_create_window")));
767
static inline void DefineButton(void) __attribute__ ((alias ("define_button")));
961
static inline void DefineButton(void) __attribute__ ((alias ("define_button")));
768
static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color)
962
static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color)
769
                            __attribute__ ((alias ("draw_line")));
963
                            __attribute__ ((alias ("draw_line")));
770
static inline void DrawBar(int x, int y, int w, int h, color_t color)
964
static inline void DrawBar(int x, int y, int w, int h, color_t color)
771
                           __attribute__ ((alias ("draw_bar")));
965
                           __attribute__ ((alias ("draw_bar")));
772
static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h)
966
static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h)
773
                              __attribute__ ((alias ("draw_bitmap")));
967
                              __attribute__ ((alias ("draw_bitmap")));
774
static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height")));
968
static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height")));
775
static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos")));
969
static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos")));
776
static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons")));
970
static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons")));
777
static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));
971
static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));
778
static inline uint32_t  LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
972
static inline uint32_t  LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
779
static inline uint32_t SetCursor(uint32_t  cursor) __attribute__ ((alias ("set_cursor")));
973
static inline uint32_t SetCursor(uint32_t  cursor) __attribute__ ((alias ("set_cursor")));
780
static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
974
static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
781
static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
975
static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
782
static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
976
static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
783
static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
977
static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
784
static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
978
static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
785
static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
979
static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
786
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
980
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
787
static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
981
static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
788
#endif
982
#endif
789
 
983
 
790
#ifdef __cplusplus
984
#ifdef __cplusplus
791
}
985
}
792
#endif
986
#endif
793
 
987
 
794
 
988
 
795
#endif
989
#endif
-
 
990
 
-
 
991
enum>
-
 
992
 
-
 
993
enum>