Subversion Repositories Kolibri OS

Rev

Rev 6725 | Details | Compare with Previous | Last modification | View Log | RSS feed

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