Subversion Repositories Kolibri OS

Rev

Rev 8660 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8622 Boppan 1
#ifndef _KSYS_H_
2
#define _KSYS_H_
3
 
4
#ifdef __cplusplus
5
extern "C" {
6
#endif
7
 
8
#include 
9
 
10
#define asm_inline __asm__ __volatile__
11
#define not_optimized __attribute__((optimize("O0")))
12
 
8628 turbocat 13
#define KSYS_FS_ERR_SUCCESS 0  // Success
14
#define KSYS_FS_ERR_1       1  // Base and/or partition of a hard disk is not defined (fn21.7 & fn21.8)
15
#define KSYS_FS_ERR_2       2  // Function is not supported for the given file system
16
#define KSYS_FS_ERR_3       3  // Unknown file system
17
#define KSYS_FS_ERR_4       4  // Reserved, is never returned in the current implementation
18
#define KSYS_FS_ERR_5       5  // File not found
19
#define KSYS_FS_ERR_EOF     6  // End of file, EOF
20
#define KSYS_FS_ERR_7       7  // Pointer lies outside of application memory
21
#define KSYS_FS_ERR_8       8  // Disk is full
22
#define KSYS_FS_ERR_9       9  // FAT table is destroyed
23
#define KSYS_FS_ERR_10      10 // Access denied
24
#define KSYS_FS_ERR_11      11 // Device error
8623 Boppan 25
 
8622 Boppan 26
typedef struct {
27
    unsigned char blue;
28
    unsigned char green;
29
    unsigned char red;
30
}rgb_t;
31
 
32
#pragma pack(push,1)
33
typedef union{
34
    unsigned val;
35
    struct{
36
        short  x;
37
        short  y;
38
    };
39
}ksys_pos_t;
40
 
41
typedef union ksys_oskey_t{
42
    unsigned val;
43
    struct{
44
        unsigned char state;
45
        unsigned char code;
46
        unsigned char ctrl_key;
47
    };
48
}ksys_oskey_t;
49
 
50
typedef struct{
51
  unsigned     handle;
52
  unsigned     io_code;
53
  unsigned     *input;
54
  int          inp_size;
55
  void         *output;
56
  int          out_size;
57
}ksys_ioctl_t;
58
 
59
typedef struct{
60
    void *data;
61
    size_t size;
62
}ksys_ufile_t;
63
 
8628 turbocat 64
 
8622 Boppan 65
typedef struct{
66
    unsigned            p00;
67
    union{
68
        uint64_t        p04;
69
        struct {
70
            unsigned    p04dw;
71
            unsigned    p08dw;
72
        };
73
    };
74
    unsigned            p12;
75
    union {
76
        unsigned        p16;
77
        const char     *new_name;
78
        void           *bdfe;
79
        void           *buf16;
80
        const void     *cbuf16;
81
    };
82
    char                p20;
83
    const char         *p21;
84
}ksys70_t;
85
 
86
 
87
typedef struct {
88
    unsigned attributes;
89
    unsigned name_cp;
90
    char creation_time[4];
91
    char creation_date[4];
92
    char last_access_time[4];
93
    char last_access_date[4];
94
    char last_modification_time[4];
95
    char last_modification_date[4];
96
    unsigned long long size;
97
    char name[0];
98
}ksys_bdfe_t;
99
 
100
typedef struct {
101
  int cpu_usage;             //+0
102
  int window_pos_info;       //+4
103
  short int reserved1;       //+8
104
  char name[12];             //+10
105
  int memstart;              //+22
106
  int memused;               //+26
107
  int pid;                   //+30
108
  int winx_start;            //+34
109
  int winy_start;            //+38
110
  int winx_size;             //+42
111
  int winy_size;             //+46
112
  short int slot_info;       //+50
113
  short int reserved2;       //+52
114
  int clientx;               //+54
115
  int clienty;               //+58
116
  int clientwidth;           //+62
117
  int clientheight;          //+66
118
  unsigned char window_state;//+70
119
  char reserved3[1024-71];   //+71
120
}ksys_proc_table_t;
121
 
122
typedef unsigned int ksys_color_t;
123
 
124
typedef struct{
125
    ksys_color_t frame_area;
126
    ksys_color_t grab_bar;
127
    ksys_color_t grab_bar_button;
128
    ksys_color_t grab_button_text;
129
    ksys_color_t grab_text;
130
    ksys_color_t work_area;
131
    ksys_color_t work_button;
132
    ksys_color_t work_button_text;
133
    ksys_color_t work_text;
134
    ksys_color_t work_graph;
135
}ksys_colors_table_t;
136
 
137
typedef struct{
138
    unsigned pid;      // PID of sending thread
139
    unsigned datalen;  // data bytes
140
    char     *data;    // data begin
141
}ksys_ipc_msg;
142
 
143
typedef struct{
144
    unsigned lock;              // nonzero is locked
145
    unsigned used;              // used bytes in buffer
146
    ksys_ipc_msg *data;         // data begin
147
}ksys_ipc_buffer;
148
 
149
typedef struct {
150
    char* func_name;
151
    void* func_ptr;
152
}ksys_coff_etable_t;
153
 
154
#pragma pack(pop)
155
 
156
enum KSYS_EVENTS {
157
    KSYS_EVENT_NONE = 0,     /* Event queue is empty */
158
    KSYS_EVENT_REDRAW = 1,   /* Window and window elements should be redrawn */
159
    KSYS_EVENT_KEY = 2,      /* A key on the keyboard was pressed */
160
    KSYS_EVENT_BUTTON = 3,   /* A button was clicked with the mouse */
161
    KSYS_EVENT_DESKTOP = 5,  /* Desktop redraw finished */
162
    KSYS_EVENT_MOUSE = 6,    /* Mouse activity (movement, button press) was detected */
163
    KSYS_EVENT_IPC = 7,      /* Interprocess communication notify */
164
    KSYS_EVENT_NETWORK = 8,  /* Network event */
165
    KSYS_EVENT_DEBUG = 9,    /* Debug subsystem event */
166
    KSYS_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */
167
};
168
 
169
enum KSYS_FILE_ENCODING{
170
    KSYS_FILE_CP866 =1,
171
    KSYS_FILE_UTF16LE = 2,
172
    KSYS_FILE_UTF8 = 3
173
};
174
 
175
enum KSYS_CLIP_ENCODING{
176
    KSYS_CLIP_UTF8 = 0,
177
    KSYS_CLIP_CP866 = 1,
178
    KSYS_CLIP_CP1251 = 2
179
};
180
 
181
enum KSYS_CLIP_TYPES{
182
    KSYS_CLIP_TEXT = 0,
183
    KSYS_CLIP_IMAGE = 1,
184
    KSYS_CLIP_RAW = 2
185
};
186
 
8628 turbocat 187
enum KSYS_MOUSE_POS{
188
    KSYS_MOUSE_SCREEN_POS = 0,
189
    KSYS_MOUSE_WINDOW_POS = 1
190
};
191
 
8629 turbocat 192
enum KSYS_SHM_MODE{
193
    KSYS_SHM_OPEN = 0x00,
194
    KSYS_SHM_OPEN_ALWAYS = 0x04,
195
    KSYS_SHM_CREATE = 0x08,
196
    KSYS_SHM_READ = 0x00,
197
    KSYS_SHM_WRITE = 0x01,
198
};
199
 
8622 Boppan 200
static inline
201
int _ksys_strcmp(const char * s1, const char * s2 )
202
{
8629 turbocat 203
    while ((*s1) && (*s1 == *s2)){ ++s1; ++s2; }
204
    return(*(unsigned char*)s1 - *(unsigned char *)s2);
8622 Boppan 205
}
206
 
207
// Functions for working with the graphical interface
208
 
209
static inline
210
void _ksys_start_draw()
211
{
212
   asm_inline("int $0x40"::"a"(12),"b"(1));
213
}
214
 
215
static inline
216
void _ksys_end_draw()
217
{
218
    asm_inline("int $0x40" ::"a"(12),"b"(2));
219
}
220
 
221
static inline
222
void _ksys_create_window(int x, int y, int w, int h, const char *name, ksys_color_t workcolor, unsigned style)
223
{
224
    asm_inline(
225
        "int $0x40"
226
        ::"a"(0),
227
        "b"((x << 16) | ((w-1) & 0xFFFF)),
228
        "c"((y << 16) | ((h-1) & 0xFFFF)),
229
        "d"((style << 24) | (workcolor & 0xFFFFFF)),
230
        "D"(name),
231
        "S"(0) : "memory"
232
     );
233
};
234
 
235
static inline
236
void _ksys_change_window(int new_x, int new_y, int new_w, int new_h)
237
{
238
    asm_inline(
239
        "int $0x40"
240
        ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
241
    );
242
}
243
 
244
static inline
245
void _ksys_define_button(unsigned x, unsigned y, unsigned w, unsigned h, unsigned id, ksys_color_t color)
246
{
247
   asm_inline(
248
        "int $0x40"
249
        ::"a"(8),
250
        "b"((x<<16)+w),
251
        "c"((y<<16)+h),
252
        "d"(id),
253
        "S"(color)
254
    );
255
};
256
 
257
static inline
258
void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color)
259
{
260
    asm_inline(
261
        "int $0x40"
262
        ::"a"(38), "d"(color),
263
        "b"((xs << 16) | xe),
264
        "c"((ys << 16) | ye)
265
    );
266
}
267
 
268
static inline
269
void _ksys_draw_bar(int x, int y, int w, int h, ksys_color_t color)
270
{
271
    asm_inline(
272
        "int $0x40"
273
        ::"a"(13), "d"(color),
274
        "b"((x << 16) | w),
275
        "c"((y << 16) | h)
276
    );
277
}
278
 
279
static inline
280
void _ksys_draw_bitmap(void *bitmap, int x, int y, int w, int h)
281
{
282
    asm_inline(
283
        "int $0x40"
284
        ::"a"(7), "b"(bitmap),
285
        "c"((w << 16) | h),
286
        "d"((x << 16) | y)
287
    );
288
}
289
 
290
static inline
291
void _ksys_draw_text(const char *text, int x, int y, int len, ksys_color_t color)
292
{
293
   asm_inline(
294
        "int $0x40"
295
        ::"a"(4),"d"(text),
296
        "b"((x << 16) | y),
297
        "S"(len),"c"(color)
298
        :"memory"
299
    );
300
}
301
 
302
static inline
303
void _ksys_draw_text_bg(const char *text, int x, int y, int len, ksys_color_t color, ksys_color_t bg)
304
{
305
    asm_inline(
306
        "int $0x40"
307
        ::"a"(4),"d"(text),
308
        "b"((x << 16) | y),
309
        "S"(len),"c"(color), "D"(bg)
310
        :"memory"
311
    );
312
}
313
 
314
static inline
315
void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color){
316
    unsigned fmt;
317
    fmt = len << 16 | 0x80000000; // no leading zeros + width
318
    asm_inline(
319
        "int $0x40"
320
        ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color)
321
    );
322
}
323
 
324
static inline
325
void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg){
326
    unsigned fmt;
327
    fmt = len << 16 | 0x80000000; // no leading zeros + width
328
    asm_inline(
329
        "int $0x40"
330
        ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg)
331
    );
332
}
333
 
334
static inline
335
unsigned _ksys_get_skin_height()
336
{
337
    unsigned height;
338
    asm_inline(
339
        "int $0x40 \n\t"
340
        :"=a"(height)
341
        :"a"(48),"b"(4)
342
    );
343
    return height;
344
}
345
 
346
static inline
347
void _ksys_get_colors(ksys_colors_table_t *color_table)
348
{
349
    asm_inline(
350
       "int $0x40"
351
        ::"a"(48),"b"(3),"c"(color_table),"d"(40)
352
    );
353
}
354
 
8654 turbocat 355
/* Functions for working with a screen. */
8622 Boppan 356
 
8654 turbocat 357
static inline
8660 turbocat 358
ksys_pos_t not_optimized _ksys_screen_size()
8654 turbocat 359
{
360
	ksys_pos_t size;
361
    ksys_pos_t size_tmp;
362
    asm_inline(
363
        "int $0x40"
364
        :"=a"(size_tmp)
365
        :"a"(14)
366
    );
367
    size.x = size_tmp.y;
368
    size.y = size_tmp.x;
369
    return size;
370
}
371
 
372
 
8622 Boppan 373
/* Functions for working with a mouse and cursors. */
374
 
375
static inline
376
ksys_pos_t _ksys_get_mouse_pos(int origin)
377
{
378
    ksys_pos_t val;
379
    asm_inline(
380
        "int $0x40 \n\t"
381
        "rol $16, %%eax"
382
        :"=a"(val)
383
        :"a"(37),"b"(origin)
8629 turbocat 384
        :"memory"
8622 Boppan 385
    );
386
    return val;
387
}
388
 
389
static inline
390
unsigned _ksys_get_mouse_buttons()
391
{
392
    unsigned val;
393
    asm_inline(
394
        "int $0x40"
395
        :"=a"(val)
396
        :"a"(37),"b"(2)
397
    );
398
    return val;
399
}
400
 
401
static inline
402
unsigned _ksys_get_mouse_wheels()
403
{
404
    unsigned val;
405
    asm_inline(
406
        "int $0x40 \n\t"
407
        :"=a"(val)
408
        :"a"(37),"b"(7)
409
    );
410
    return val;
411
}
412
 
413
static inline
414
unsigned _ksys_load_cursor(void *path, unsigned flags)
415
{
416
    unsigned val;
417
    asm_inline(
418
        "int $0x40"
419
        :"=a"(val)
420
        :"a"(37), "b"(4), "c"(path), "d"(flags)
421
    );
422
    return val;
423
}
424
 
425
static inline
426
unsigned _ksys_set_cursor(unsigned  cursor)
427
{
428
    unsigned old;
429
    asm_inline(
430
        "int $0x40"
431
        :"=a"(old)
432
        :"a"(37), "b"(5), "c"(cursor)
433
    );
434
    return old;
435
}
436
 
437
static inline
438
int _ksys_destroy_cursor(unsigned cursor)
439
{
440
    int ret;
441
    asm_inline(
442
        "int $0x40"
443
        :"=a"(ret)
444
        :"a"(37), "b"(6), "c"(cursor)
445
        :"memory"
446
    );
447
    return ret;
448
}
449
 
450
static inline
451
unsigned _ksys_get_mouse_eventstate()
452
{
453
    unsigned val;
454
    asm_inline(
455
        "int $0x40"
456
        :"=a"(val)
457
        :"a"(37),"b"(3)
458
    );
459
    return val;
460
}
461
 
462
 
463
/* Functions for working with events and buttons. */
464
 
465
static inline
466
unsigned _ksys_set_event_mask(unsigned mask)
467
{
468
    unsigned val;
469
    asm_inline(
470
        "int $0x40"
471
        :"=a"(val)
472
        :"a"(40), "b"(mask)
473
    );
474
    return val;
475
}
476
 
477
static inline
478
unsigned _ksys_wait_event(unsigned time)
479
{
480
    unsigned val;
481
    asm_inline(
482
        "int $0x40"
483
        :"=a"(val)
484
        :"a"(23), "b"(time)
485
    );
486
    return val;
487
}
488
 
489
static inline
490
unsigned _ksys_check_event()
491
{
492
    unsigned val;
493
    asm_inline(
494
        "int $0x40"
495
        :"=a"(val)
496
        :"a"(11)
497
    );
498
    return val;
499
}
500
 
501
static inline
502
unsigned _ksys_get_event()
503
{
504
    unsigned val;
505
    asm_inline(
506
        "int $0x40"
507
        :"=a"(val)
508
        :"a"(10)
509
    );
510
    return val;
511
}
512
 
513
static inline
514
unsigned _ksys_get_button()
515
{
516
    unsigned val;
517
    asm_inline(
518
        "int $0x40"
519
        :"=a"(val)
520
        :"a"(17)
521
    );
522
    return val>>8;
523
}
524
 
525
static inline
526
ksys_oskey_t _ksys_get_key(void)
527
{
528
    ksys_oskey_t val;
529
    asm_inline(
530
        "int $0x40"
531
        :"=a"(val)
532
        :"a"(2)
533
    );
534
    return val;
535
}
536
 
537
/* Functions for working with the clipboard */
538
 
539
static inline
540
int _ksys_clip_num()
541
{
542
    unsigned val;
543
    asm_inline(
544
        "int $0x40"
545
        :"=a"(val)
546
        :"a"(54), "b"(0)
547
    );
548
    return val;
549
}
550
 
551
static inline
552
char* _ksys_clip_get(int n) // returned buffer must be freed by _ksys_free()
553
{
554
    char* val;
555
    asm_inline(
556
        "int $0x40"
557
        :"=a"(val)
558
        :"a"(54), "b"(1), "c"(n)
559
    );
560
    return val;
561
}
562
 
563
static inline
564
int _ksys_clip_set(int n, char *buffer)
565
{
566
    unsigned val;
567
    asm_inline(
568
        "int $0x40"
569
        :"=a"(val)
570
        :"a"(54), "b"(2), "c"(n), "d"(buffer)
571
    );
572
    return val;
573
}
574
 
575
static inline
576
int _ksys_clip_pop()
577
{
578
    unsigned val;
579
    asm_inline (
580
        "int $0x40"
581
        :"=a"(val)
582
        :"a"(54), "b"(3)
583
    );
584
    return val;
585
}
586
 
587
static inline
588
int _ksys_clip_unlock()
589
{
590
    unsigned val;
591
    asm_inline(
592
        "int $0x40"
593
        :"=a"(val)
594
        :"a"(54), "b"(4)
595
    );
596
    return val;
597
}
598
 
599
 
600
/* Working with time */
601
 
602
static inline
603
unsigned _ksys_get_tick_count()
604
{
605
    unsigned val;
606
    asm_inline(
607
        "int $0x40"
608
        :"=a"(val)
609
        :"a"(26),"b"(9)
610
    );
611
    return val;
612
}
613
 
614
static inline
615
uint64_t  _ksys_get_ns_count()
616
{
617
    uint64_t val;
618
    asm_inline(
619
        "int $0x40"
620
        :"=A"(val)
621
        :"a"(26), "b"(10)
622
    );
623
    return val;
624
}
625
 
626
static inline
627
void _ksys_delay(unsigned time)
628
{
629
    asm_inline(
630
        "int $0x40"
631
        ::"a"(5), "b"(time)
632
        :"memory"
633
    );
634
}
635
 
636
static inline
637
unsigned _ksys_get_date()
638
{
639
    unsigned val;
640
    asm_inline("int $0x40":"=a"(val):"a"(29));
641
    return val;
642
}
643
 
644
static inline
645
unsigned _ksys_get_clock()
646
{
647
    unsigned val;
648
    asm_inline("int $0x40":"=a"(val):"a"(3));
649
    return val;
650
}
651
 
652
 
653
/* Working with memory allocation */
654
 
655
static inline
656
void* _ksys_alloc(size_t size){
657
    void  *val;
658
    asm_inline(
659
        "int $0x40"
660
        :"=a"(val)
661
        :"a"(68),"b"(12),"c"(size)
662
    );
663
    return val;
664
}
665
 
666
static inline
667
int _ksys_free(void *mem)
668
{
669
    int val;
670
    asm_inline(
671
        "int $0x40"
672
        :"=a"(val)
673
        :"a"(68),"b"(13),"c"(mem)
674
    );
675
    return val;
676
}
677
 
678
static inline
679
void* _ksys_realloc(void *mem, size_t size)
680
{
681
    void *val;
682
    asm_inline(
683
        "int $0x40"
684
        :"=a"(val)
685
        :"a"(68),"b"(20),"c"(size),"d"(mem)
686
        :"memory"
687
    );
688
    return val;
689
}
690
 
691
static inline
692
int* _ksys_unmap(void *base, size_t offset, size_t size)
693
{
694
    int  *val;
695
    asm_inline(
696
        "int $0x40"
697
        :"=a"(val)
698
        :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size)
699
    );
700
    return val;
701
}
702
 
703
 
704
/* Loading the dynamic coff library */
705
 
706
static inline
707
ksys_coff_etable_t* not_optimized _ksys_cofflib_load(const char* path)
708
{
709
    ksys_coff_etable_t *table;
710
    asm_inline(
711
        "int $0x40"
712
        :"=a"(table)
713
        :"a"(68),"b"(19), "c"(path)
714
    );
715
    return table;
716
}
717
 
718
static inline
719
void* not_optimized _ksys_cofflib_getproc(ksys_coff_etable_t *table, const char* fun_name)
720
{
721
    unsigned i=0;
722
    while (1){
723
        if (NULL == (table+i)->func_name){
724
            break;
725
        }else{
726
            if (!_ksys_strcmp(fun_name, (table+i)->func_name)){
727
                return (table+i)->func_ptr;
728
            }
729
        }
730
        i++;
731
    }
732
    return NULL;
733
}
734
 
735
 
736
/* Debug board functions */
737
 
738
static inline
739
void _ksys_debug_putc(char c)
740
{
741
    asm_inline("int $0x40"::"a"(63), "b"(1), "c"(c));
742
}
743
 
744
static inline
745
void _ksys_debug_puts(char *s)
746
{
747
    unsigned i=0;
748
    while (*(s+i)){
749
        asm_inline ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i)));
750
        i++;
751
    }
752
}
753
 
754
 
755
/* Working with threads and process */
756
 
757
static inline
758
int _ksys_start_thread(void* proc, char* stack_top)
759
{
760
    int val;
761
    asm_inline(
762
        "int $0x40"
763
        :"=a"(val)
764
        :"a"(51), "b"(1), "c"(proc), "d"(stack_top)
765
    );
766
    return val;
767
}
768
 
769
static inline
770
void _ksys_focus_window(int slot){
771
    asm_inline(
772
        "int $0x40"
773
        ::"a"(18), "b"(3), "c"(slot)
774
    );
775
}
776
 
777
static inline
778
int _ksys_get_thread_slot(int tid){
779
    int val;
780
    asm_inline(
781
        "int $0x40"
782
        :"=a"(val)
783
        :"a"(18), "b"(21), "c"(tid)
784
    );
785
    return val;
786
}
787
 
788
static inline
789
int not_optimized _ksys_process_info(ksys_proc_table_t* table, int pid)
790
{
791
    int val;
792
    asm_inline(
793
        "int $0x40"
794
        :"=a"(val)
795
        :"a"(9), "b"(table), "c"(pid)
8665 turbocat 796
        :"memory"
8622 Boppan 797
    );
798
    return val;
799
}
800
 
801
static inline
802
void _ksys_exit()
803
{
804
    asm_inline("int $0x40"::"a"(-1));
805
}
806
 
807
 
808
/* Working with files and directories */
809
 
810
static inline
811
void _ksys_setcwd(char* dir){
812
    asm_inline(
813
        "int $0x40"
814
        ::"a"(30), "b"(1), "c"(dir)
815
    );
816
}
817
 
818
static inline
819
int _ksys_getcwd(char* buf, int bufsize){
820
    register int val;
821
    asm_inline(
822
        "int $0x40"
823
        :"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize)
824
    );
825
    return val;
826
}
827
 
828
static inline
829
ksys_ufile_t _ksys_load_file(const char *path)
830
{
831
    ksys_ufile_t uf;
832
    asm_inline(
833
        "int $0x40"
834
        :"=a"(uf.data), "=d"(uf.size)
835
        :"a"(68), "b"(27),"c"(path)
836
    );
837
    return uf;
838
}
839
 
840
static inline
841
ksys_ufile_t _ksys_load_file_enc(const char *path, unsigned file_encoding)
842
{
843
    ksys_ufile_t uf;
844
    asm_inline(
845
        "int $0x40"
846
        :"=a"(uf.data), "=d"(uf.size)
847
        :"a"(68), "b"(28),"c"(path), "d"(file_encoding)
848
    );
849
    return uf;
850
}
851
 
852
static inline
853
int not_optimized _ksys_work_files(const ksys70_t *k)
854
{
855
    int status;
856
    asm_inline(
857
        "int $0x40"
858
        :"=a"(status)
859
        :"a"(70), "b"(k)
860
    );
861
    return status;
862
}
863
 
864
static inline
865
int not_optimized _ksys_file_read_file(const char *name, unsigned long long offset, unsigned size, void *buf, unsigned *bytes_read)
866
{
867
    ksys70_t k;
868
    k.p00 = 0;
869
    k.p04 = offset;
870
    k.p12 = size;
871
    k.buf16 = buf;
872
    k.p20 = 0;
873
    k.p21 = name;
874
    int status;
875
    unsigned bytes_read_v;
876
    asm_inline(
877
        "int $0x40"
878
        :"=a"(status), "=b"(bytes_read_v)
879
        :"a"(70), "b"(&k)
880
    );
881
    if (!status) {
882
        *bytes_read = bytes_read_v;
883
    }
884
    return status;
885
}
886
 
887
static inline
888
int not_optimized _ksys_file_write_file(const char *name, unsigned long long offset, unsigned size, const void *buf, unsigned *bytes_written)
889
{
890
    ksys70_t k;
891
    k.p00 = 3;
892
    k.p04 = offset;
893
    k.p12 = size;
894
    k.cbuf16 = buf;
895
    k.p20 = 0;
896
    k.p21 = name;
897
    int status;
898
    unsigned bytes_written_v;
899
    asm_inline(
900
        "int $0x40"
901
        :"=a"(status), "=b"(bytes_written_v)
902
        :"a"(70), "b"(&k)
903
    );
904
    if (!status) {
905
        *bytes_written = bytes_written_v;
906
    }
907
    return status;
908
}
909
 
910
static inline
911
int not_optimized _ksys_file_get_info(const char *name, ksys_bdfe_t *bdfe)
912
{
913
    ksys70_t k;
914
    k.p00 = 5;
915
    k.bdfe = bdfe;
916
    k.p20 = 0;
917
    k.p21 = name;
918
    return _ksys_work_files(&k);
919
}
920
 
921
static inline
922
int not_optimized _ksys_file_delete(const char *name)
923
{
924
    ksys70_t k;
925
    k.p00 = 8;
926
    k.p20 = 0;
927
    k.p21 = name;
928
    return _ksys_work_files(&k);
929
}
930
 
931
static inline
932
int not_optimized _ksys_file_rename(const char *name, const char *new_name)
933
{
934
    ksys70_t k;
935
    k.p00 = 10;
936
    k.new_name = new_name;
937
    k.p20 = 0;
938
    k.p21 = name;
939
    return _ksys_work_files(&k);
940
}
941
 
942
 
943
static inline
8629 turbocat 944
int not_optimized _ksys_exec(char *app_name, char *args)
945
{
8654 turbocat 946
    ksys70_t file_opt;
947
    file_opt.p00 = 7;
948
    file_opt.p04dw = 0;
949
    file_opt.p08dw = (unsigned)args;
950
    file_opt.p21 = app_name;
951
    return _ksys_work_files(&file_opt);
8622 Boppan 952
}
953
 
8654 turbocat 954
static inline
8659 turbocat 955
int not_optimized _ksys_mkdir(const char *path)
8654 turbocat 956
{
957
    ksys70_t dir_opt;
958
    dir_opt.p00 = 9;
959
    dir_opt.p21 = path;
960
    return _ksys_work_files(&dir_opt);
961
}
962
 
8629 turbocat 963
/* Working with a named shared memory area. */
964
 
965
static inline
966
int _ksys_shm_open(char *name, int mode, int size, char **new_shm)
967
{
968
    int error;
969
    asm_inline(
970
        "int $0x40"
971
        :"=a"(*new_shm), "=d"(error)
972
        :"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode)
973
    );
974
    return error;
975
}
976
 
977
 
978
static inline
979
void _ksys_shm_close(char *shm_name)
980
{
981
    asm_inline(
982
        "int $0x40":
983
        :"a"(68), "b"(23), "c"(shm_name)
984
    );
985
}
986
 
8654 turbocat 987
#ifdef __cplusplus
988
}
989
#endif
990
 
8659 turbocat 991
#endif // _KSYS_H_