Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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