Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
9093 turbocat 1
/* Copyright (C) KolibriOS team 2004-2021. All rights reserved. */
2
/* Distributed under terms of the GNU General Public License    */
3
 
4
/* This file contains basic wrappers over KolibriOS system calls. */
5
/* See sysfuncs.txt file for details. */
6
 
7
/*
8
 * This file was created with you in mind. Lest you reinvent the wheel.
9
 * If for some reason there is not enough wrapper add! I ask you to stick to the same style: snake_case.
10
 * Structure names must start with "ksys_" and end with "_t".
11
 * All wrappers must start with the "_ksys_" prefix.
12
 * I consider it mandatory to place the wrappers in the correct order in the official documentation.
13
 * Enjoy writing your code :)
9137 turbocat 14
 
15
 * Warning! The end of the file is the old definitions of function/structure names.
16
 * They are for compatibility... Better not to use them.
9093 turbocat 17
*/
18
 
8687 turbocat 19
#ifndef _KSYS_H_
20
#define _KSYS_H_
21
 
22
#include 
23
 
24
#define asm_inline __asm__ __volatile__
25
 
9093 turbocat 26
/*============== General structures ==============*/
8687 turbocat 27
 
9093 turbocat 28
#pragma pack(push,1)
8687 turbocat 29
 
30
typedef struct {
9093 turbocat 31
    uint8_t blue;
32
    uint8_t green;
33
    uint8_t red;
8687 turbocat 34
}rgb_t;
9093 turbocat 35
 
36
typedef union {
37
    uint32_t val;
38
    struct{
39
        uint8_t hour;
40
        uint8_t min;
41
        uint8_t sec;
42
        uint8_t _zero;
43
    };
44
}ksys_time_t;
45
 
46
typedef union {
47
    uint32_t val;
48
    struct{
49
        uint8_t  year;
50
        uint8_t  month;
51
        uint8_t  day;
52
        uint8_t  _zero;
53
    };
54
}ksys_date_t;
55
 
8687 turbocat 56
typedef union{
9093 turbocat 57
    uint32_t val;
8687 turbocat 58
    struct{
9093 turbocat 59
        uint16_t  x;
60
        uint16_t  y;
8687 turbocat 61
    };
62
}ksys_pos_t;
63
 
64
typedef union ksys_oskey_t{
9093 turbocat 65
    uint32_t val;
8687 turbocat 66
    struct{
9093 turbocat 67
        uint8_t state;
68
        uint8_t code;
69
        uint8_t ctrl_key;
8687 turbocat 70
    };
71
}ksys_oskey_t;
72
 
73
typedef struct{
74
    void *data;
75
    size_t size;
76
}ksys_ufile_t;
77
 
78
 
79
typedef struct{
9093 turbocat 80
    uint32_t            p00;
8687 turbocat 81
    union{
82
        uint64_t        p04;
83
        struct {
9093 turbocat 84
            uint32_t    p04dw;
85
            uint32_t    p08dw;
8687 turbocat 86
        };
87
    };
9093 turbocat 88
    uint32_t            p12;
8687 turbocat 89
    union {
9093 turbocat 90
        uint32_t        p16;
8687 turbocat 91
        const char     *new_name;
92
        void           *bdfe;
93
        void           *buf16;
94
        const void     *cbuf16;
95
    };
96
    char                p20;
97
    const char         *p21;
98
}ksys70_t;
99
 
100
typedef struct {
9093 turbocat 101
    uint32_t attributes;
102
    uint32_t name_cp;
103
    ksys_time_t creation_time;
104
    ksys_date_t creation_date;
105
    ksys_time_t last_access_time;
106
    ksys_date_t last_access_date;
107
    ksys_time_t last_modification_time;
108
    ksys_date_t last_modification_date;
8687 turbocat 109
    unsigned long long size;
110
    char name[0];
111
}ksys_bdfe_t;
112
 
113
typedef struct {
114
  int cpu_usage;             //+0
115
  int window_pos_info;       //+4
116
  short int reserved1;       //+8
117
  char name[12];             //+10
118
  int memstart;              //+22
119
  int memused;               //+26
120
  int pid;                   //+30
121
  int winx_start;            //+34
122
  int winy_start;            //+38
123
  int winx_size;             //+42
124
  int winy_size;             //+46
125
  short int slot_info;       //+50
126
  short int reserved2;       //+52
127
  int clientx;               //+54
128
  int clienty;               //+58
129
  int clientwidth;           //+62
130
  int clientheight;          //+66
131
  unsigned char window_state;//+70
132
  char reserved3[1024-71];   //+71
9093 turbocat 133
}ksys_thread_t;
8687 turbocat 134
 
135
typedef unsigned int ksys_color_t;
136
 
137
typedef struct{
138
    ksys_color_t frame_area;
139
    ksys_color_t grab_bar;
140
    ksys_color_t grab_bar_button;
141
    ksys_color_t grab_button_text;
142
    ksys_color_t grab_text;
143
    ksys_color_t work_area;
144
    ksys_color_t work_button;
145
    ksys_color_t work_button_text;
146
    ksys_color_t work_text;
147
    ksys_color_t work_graph;
148
}ksys_colors_table_t;
149
 
150
typedef struct{
151
    unsigned pid;      // PID of sending thread
152
    unsigned datalen;  // data bytes
153
    char     *data;    // data begin
154
}ksys_ipc_msg;
155
 
156
typedef struct{
157
    unsigned lock;              // nonzero is locked
158
    unsigned used;              // used bytes in buffer
159
    ksys_ipc_msg *data;         // data begin
160
}ksys_ipc_buffer;
161
 
162
typedef struct {
163
    char* func_name;
164
    void* func_ptr;
9093 turbocat 165
}ksys_dll_t;
8687 turbocat 166
 
8702 turbocat 167
typedef unsigned ksys_drv_hand_t;
8699 turbocat 168
 
169
typedef struct{
170
    ksys_drv_hand_t handler;
171
    unsigned func_num;
172
    void* in_data_ptr;
173
    unsigned in_data_size;
174
    void* out_data_ptr;
175
    unsigned out_data_size;
8718 turbocat 176
}ksys_ioctl_t;
8699 turbocat 177
 
9093 turbocat 178
typedef struct{
179
    char  key[64];
180
    char path[64];
181
}ksys_dir_key_t;
182
 
8687 turbocat 183
#pragma pack(pop)
184
 
9093 turbocat 185
typedef rgb_t ksys_bitmap_t;
186
 
187
enum KSYS_FS_ERRORS {
188
    KSYS_FS_ERR_SUCCESS = 0,  // Success
189
    KSYS_FS_ERR_1       = 1,  // Base and/or partition of a hard disk is not defined (fn21.7 & fn21.8)
190
    KSYS_FS_ERR_2       = 2,  // Function is not supported for the given file system
191
    KSYS_FS_ERR_3       = 3,  // Unknown file system
192
    KSYS_FS_ERR_4       = 4,  // Reserved, is never returned in the current implementation
193
    KSYS_FS_ERR_5       = 5,  // File not found
194
    KSYS_FS_ERR_EOF     = 6,  // End of file, EOF
195
    KSYS_FS_ERR_7       = 7,  // Pointer lies outside of application memory
196
    KSYS_FS_ERR_8       = 8,  // Disk is full
197
    KSYS_FS_ERR_9       = 9,  // FAT table is destroyed
198
    KSYS_FS_ERR_10      = 10, // Access denied
199
    KSYS_FS_ERR_11      = 11 // Device error
200
};
201
 
8687 turbocat 202
enum KSYS_EVENTS {
203
    KSYS_EVENT_NONE = 0,     /* Event queue is empty */
204
    KSYS_EVENT_REDRAW = 1,   /* Window and window elements should be redrawn */
205
    KSYS_EVENT_KEY = 2,      /* A key on the keyboard was pressed */
206
    KSYS_EVENT_BUTTON = 3,   /* A button was clicked with the mouse */
207
    KSYS_EVENT_DESKTOP = 5,  /* Desktop redraw finished */
208
    KSYS_EVENT_MOUSE = 6,    /* Mouse activity (movement, button press) was detected */
209
    KSYS_EVENT_IPC = 7,      /* Interprocess communication notify */
210
    KSYS_EVENT_NETWORK = 8,  /* Network event */
211
    KSYS_EVENT_DEBUG = 9,    /* Debug subsystem event */
212
    KSYS_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */
213
};
214
 
215
enum KSYS_FILE_ENCODING{
216
    KSYS_FILE_CP866 =1,
217
    KSYS_FILE_UTF16LE = 2,
218
    KSYS_FILE_UTF8 = 3
219
};
220
 
221
static inline
222
int _ksys_strcmp(const char * s1, const char * s2 )
223
{
224
    while ((*s1) && (*s1 == *s2)){ ++s1; ++s2; }
225
    return(*(unsigned char*)s1 - *(unsigned char *)s2);
226
}
227
 
9093 turbocat 228
/* ####################################################################### */
229
/* ############### ะก wrappers for system calls Kolibri OS ################ */
230
/* ####################################################################### */
8687 turbocat 231
 
232
 
9093 turbocat 233
/*=============== Function -1 - terminate thread/process ===============*/
234
 
235
static inline
236
void _ksys_exit(){
237
    asm_inline("int $0x40"::"a"(-1));
8687 turbocat 238
}
239
 
9093 turbocat 240
/*============== Function 0 - define and draw the window. ==============*/
241
 
8687 turbocat 242
static inline
9093 turbocat 243
void _ksys_create_window(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const char *name, ksys_color_t workcolor, uint32_t style) {
8687 turbocat 244
    asm_inline(
245
        "int $0x40"
246
        ::"a"(0),
247
        "b"((x << 16) | ((w-1) & 0xFFFF)),
248
        "c"((y << 16) | ((h-1) & 0xFFFF)),
249
        "d"((style << 24) | (workcolor & 0xFFFFFF)),
250
        "D"(name),
251
        "S"(0)
252
        :"memory"
253
     );
254
};
255
 
9093 turbocat 256
/*================ Function 1 - put pixel in the window. ===============*/
257
 
258
static inline
259
void _ksys_draw_pixel(uint32_t x, uint32_t y, ksys_color_t color){
260
    asm_inline(
261
        "int $0x40"
262
        ::"a"(1), "b"(x), "c"(y), "d"(color)
263
    );
264
}
265
 
266
/*============ Function 2 - get the code of the pressed key. ===========*/
267
 
8687 turbocat 268
static inline
9093 turbocat 269
ksys_oskey_t _ksys_get_key(void){
270
    ksys_oskey_t val;
8687 turbocat 271
    asm_inline(
272
        "int $0x40"
9093 turbocat 273
        :"=a"(val)
274
        :"a"(2)
8687 turbocat 275
    );
9093 turbocat 276
    return val;
8687 turbocat 277
}
9093 turbocat 278
 
279
/*==================== Function 3 - get system time. ===================*/
280
 
8687 turbocat 281
static inline
9093 turbocat 282
ksys_time_t _ksys_get_time(){
283
    ksys_time_t c_time;
284
    asm_inline(
285
        "int $0x40"
286
        :"=a"(c_time)
287
        :"a"(3)
288
        :"memory"
289
    );
290
    return c_time;
291
}
292
 
293
/*=================== Function 4 - draw text string. ===================*/
294
 
295
static inline
296
void _ksys_draw_text(const char *text, uint32_t x, uint32_t y, uint32_t len, ksys_color_t color) {
8687 turbocat 297
   asm_inline(
298
        "int $0x40"
9093 turbocat 299
        ::"a"(4),"d"(text),
300
        "b"((x << 16) | y),
301
        "S"(len),"c"(color)
302
        :"memory"
303
    );
304
}
305
 
306
/*========================= Function 5 - delay. ========================*/
307
 
308
static inline
309
void _ksys_delay(uint32_t time){
310
    asm_inline(
311
        "int $0x40"
312
        ::"a"(5), "b"(time)
313
        :"memory"
314
    );
315
}
316
 
9094 turbocat 317
/*=============== Function 7 - draw image in the window. ===============*/
318
 
319
static inline
320
void _ksys_draw_bitmap(void *bitmap, int x, int y, int w, int h)
321
{
322
    asm_inline(
323
        "int $0x40"
324
        ::"a"(7), "b"(bitmap),
325
        "c"((w << 16) | h),
326
        "d"((x << 16) | y)
327
        :"memory"
328
    );
329
}
330
 
9093 turbocat 331
/*=============== Function 8 - define/delete the button. ===============*/
332
 
333
static inline
334
void _ksys_define_button(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t id, ksys_color_t color) {
335
   asm_inline(
336
        "int $0x40"
8687 turbocat 337
        ::"a"(8),
338
        "b"((x<<16)+w),
339
        "c"((y<<16)+h),
340
        "d"(id),
341
        "S"(color)
342
    );
343
};
344
 
345
static inline
9093 turbocat 346
void _ksys_delete_button(uint32_t id){
8687 turbocat 347
    asm_inline(
348
        "int $0x40"
9093 turbocat 349
        ::"a"(8),"d"(id & 0x00FFFFFF | 0x80000000)
8687 turbocat 350
    );
9093 turbocat 351
}
352
 
353
/*============ Function 9 - information on execution thread. ===========*/
354
 
355
static inline
356
int _ksys_thread_info(ksys_thread_t* table, int slot){
357
    int val;
358
    asm_inline(
359
        "int $0x40"
360
        :"=a"(val)
361
        :"a"(9), "b"(table), "c"(slot)
362
        :"memory"
363
    );
364
    return val;
8687 turbocat 365
}
366
 
9093 turbocat 367
/*==================== Function 10 - wait for event. ===================*/
368
 
8687 turbocat 369
static inline
9093 turbocat 370
uint32_t _ksys_wait_event(void){
371
    uint32_t val;
8687 turbocat 372
    asm_inline(
373
        "int $0x40"
9093 turbocat 374
        :"=a"(val)
375
        :"a"(10)
376
    );
377
    return val;
378
}
379
 
380
/*=============== Function 11 - check for event, no wait. ==============*/
381
 
382
static inline
383
uint32_t _ksys_check_event(void){
384
    uint32_t val;
385
    asm_inline(
386
        "int $0x40"
387
        :"=a"(val)
388
        :"a"(11)
389
    );
390
    return val;
391
}
392
 
393
/*=============== Function 12 - begin/end window redraw. ===============*/
394
 
395
static inline
396
void _ksys_start_draw(){
397
   asm_inline("int $0x40"::"a"(12),"b"(1));
398
}
399
 
400
static inline
401
void _ksys_end_draw(){
402
    asm_inline("int $0x40" ::"a"(12),"b"(2));
403
}
404
 
405
/*============ Function 13 - draw a rectangle in the window. ===========*/
406
 
407
static inline
408
void _ksys_draw_bar(uint32_t x, uint32_t y, uint32_t w, uint32_t h, ksys_color_t color){
409
    asm_inline(
410
        "int $0x40"
8687 turbocat 411
        ::"a"(13), "d"(color),
412
        "b"((x << 16) | w),
413
        "c"((y << 16) | h)
414
    );
415
}
416
 
9093 turbocat 417
/*=================== Function 14 - get screen size. ===================*/
418
 
8687 turbocat 419
static inline
9093 turbocat 420
ksys_pos_t _ksys_screen_size(){
421
	ksys_pos_t size;
422
    ksys_pos_t size_tmp;
423
    asm_inline(
424
        "int $0x40"
425
        :"=a"(size_tmp)
426
        :"a"(14)
427
    );
428
    size.x = size_tmp.y;
429
    size.y = size_tmp.x;
430
    return size;
431
}
432
 
433
/*== Function 15, subfunction 1 - set a size of the background image. ==*/
434
 
435
static inline
436
void _ksys_bg_set_size(uint32_t w, uint32_t h){
437
    asm_inline(
438
        "int $0x40"
439
        ::"a"(15), "b"(1), "c"(w), "d"(h)
440
    );
441
}
442
 
443
/*=== Function 15, subfunction 2 - put pixel on the background image. ==*/
444
 
445
static inline
446
void _ksys_bg_put_pixel(uint32_t x, uint32_t y, uint32_t w, ksys_color_t color){
447
    asm_inline(
448
        "int $0x40"
449
        ::"a"(15), "b"(2), "c"((x+y*w)*3), "d"(color)
450
    );
451
}
452
 
453
/*=========== Function 15, subfunction 3 - redraw background. ==========*/
454
 
455
static inline
456
void _ksys_bg_redraw(void){
457
    asm_inline(
458
        "int $0x40"
459
        ::"a"(15), "b"(3)
460
    );
461
}
462
 
463
/*== Function 15, subfunction 4 - set drawing mode for the background. =*/
464
 
465
enum KSYS_BG_MODES{
466
    KSYS_BG_MODE_PAVE=1,
467
    KSYS_BG_MODE_STRETCH=2
468
};
469
 
470
static inline
471
void _ksys_bg_set_mode(uint32_t mode){
472
    asm_inline(
473
        "int $0x40"
474
        ::"a"(15), "b"(4), "c"(mode)
475
    );
476
}
477
 
478
/*===================== Function 15, subfunction 5 =====================*/
479
/*============ Put block of pixels on the background image. ============*/
480
 
481
static inline
482
void _ksys_bg_put_bitmap(ksys_bitmap_t* bitmap, size_t bitmap_size, uint32_t x, uint32_t y, uint32_t w){
483
    asm_inline(
484
        "int $0x40"
485
        ::"a"(15), "b"(5), "c"(bitmap), "d"((x+y*w)*3), "S"(bitmap_size)
486
    );
487
}
488
 
489
/*===================== Function 15, subfunction 6 =====================*/
490
/*======= Map background data to the address space of process. ==========*/
491
 
492
static inline
493
ksys_bitmap_t* _ksys_bg_get_map()
8687 turbocat 494
{
9093 turbocat 495
    ksys_bitmap_t *bitmap;
8687 turbocat 496
    asm_inline(
497
        "int $0x40"
9093 turbocat 498
        :"=a"(bitmap)
499
        :"a"(15), "b"(6)
8687 turbocat 500
    );
9093 turbocat 501
    return bitmap;
8687 turbocat 502
}
503
 
9093 turbocat 504
/*===== Function 15, subfunction 7 - close mapped background data. =====*/
505
 
8687 turbocat 506
static inline
9093 turbocat 507
int _ksys_bg_close_map(ksys_bitmap_t* bitmap)
508
{
509
    int status; // 1 - OK, 0 - ERROR
510
    asm_inline(
511
        "int $0x40"
512
        :"=a"(status)
513
        :"a"(15), "b"(7), "c"(bitmap)
514
    );
515
    return status;
516
}
517
 
518
/*===================== Function 15, subfunction 9 =====================*/
519
/*============= Redraws a rectangular part of the background ===========*/
520
 
521
static inline
522
void _ksys_bg_redraw_bar(ksys_pos_t angle1, ksys_pos_t angle2)
8687 turbocat 523
{
9093 turbocat 524
    asm_inline(
8687 turbocat 525
        "int $0x40"
9093 turbocat 526
        ::"a"(15), "b"(9),
527
        "c"(angle1.x*(1<<16)+angle2.x),
528
        "d"(angle1.y*(1<<16)+angle2.y)
8687 turbocat 529
    );
530
}
531
 
9093 turbocat 532
/*=============== Function 16 - save ramdisk on a floppy. ==============*/
533
 
8687 turbocat 534
static inline
9093 turbocat 535
int _ksys_save_ramdisk_fd(uint32_t floppy_id)
8687 turbocat 536
{
9093 turbocat 537
    int status; // 0 - OK, 1 - ERROR
8687 turbocat 538
    asm_inline(
539
        "int $0x40"
9093 turbocat 540
        :"=a"(status)
541
        :"a"(16), "b"(floppy_id)
8687 turbocat 542
    );
9093 turbocat 543
    return status;
8687 turbocat 544
}
545
 
9093 turbocat 546
/*======= Function 17 - get the identifier of the pressed button. ======*/
547
 
548
static inline
549
uint32_t _ksys_get_button()
550
{
551
    unsigned val;
552
    asm_inline(
553
        "int $0x40"
554
        :"=a"(val)
555
        :"a"(17)
556
    );
557
    return val>>8;
558
}
559
 
560
/*===================== Function 18, subfunction 1 =====================*/
561
/*============= Make deactive the window of the given thread. ==========*/
562
 
8687 turbocat 563
static inline
9093 turbocat 564
void _ksys_unfocus_window(int slot)
565
{
8687 turbocat 566
    asm_inline(
567
        "int $0x40"
9093 turbocat 568
        ::"a"(18), "b"(1), "c"(slot)
8687 turbocat 569
    );
570
}
9093 turbocat 571
 
572
/*= Function 18, subfunction 2 - terminate process/thread by the slot. =*/
573
 
8687 turbocat 574
static inline
9093 turbocat 575
void _ksys_kill_by_slot(int slot)
576
{
8687 turbocat 577
    asm_inline(
578
        "int $0x40"
9093 turbocat 579
        ::"a"(18), "b"(2), "c"(slot)
8687 turbocat 580
    );
581
}
582
 
9093 turbocat 583
/*===================== Function 18, subfunction 3 =====================*/
584
/*============= Make active the window of the given thread. ============*/
585
 
586
static inline
587
void _ksys_focus_window(int slot){
588
    asm_inline(
589
        "int $0x40"
590
        ::"a"(18), "b"(3), "c"(slot)
591
    );
592
}
593
 
594
/*===================== Function 18, subfunction 4 =====================*/
595
/*=========== Get counter of idle time units per one second. ===========*/
596
 
8687 turbocat 597
static inline
9093 turbocat 598
uint32_t  _ksys_get_idle(void){
599
    uint32_t sec;
600
    asm_inline(
601
        "int $0x40"
602
        :"=a"(sec)
603
        :"a"(18), "b"(4)
604
    );
605
    return sec;
606
}
607
 
608
/*========== Function 18, subfunction 5 - get CPU clock rate. ==========*/
609
/*================ modulo 2^32 clock ticks = 4GHz ======================*/
610
 
611
static inline
612
uint32_t _ksys_get_cpu_clock(void){
613
    uint32_t clock;
614
    asm_inline(
615
        "int $0x40"
616
        :"=a"(clock)
617
        :"a"(18), "b"(5)
618
    );
619
    return clock;
620
}
621
 
622
/* Function 18, subfunction 6 - save ramdisk to the file on hard drive. */
623
 
624
static inline
625
uint32_t _ksys_save_ramdisk_hd(const char* ramdisk_path){
626
    uint32_t fs_err;
627
    asm_inline(
628
        "int $0x40"
629
        :"=a"(fs_err)
630
        :"a"(18), "b"(6), "c"(ramdisk_path)
631
    );
632
    return fs_err;
633
}
634
 
635
/* Function 18, subfunction 9 - system shutdown with the parameter. */
636
 
637
enum KSYS_SHD_PARAM {
638
    KSYS_SHD_POWEROFF    = 2,
639
    KSYS_SHD_REBOOT      = 3,
640
    KSYS_SHD_RESTART_KRN = 4
641
};
642
 
643
static inline
644
void _ksys_shutdown(uint32_t shd_param){
645
    asm_inline(
646
        "int $0x40"
647
        ::"a"(18), "b"(9), "c"(shd_param)
648
    );
649
}
650
 
651
/*========= Function 18, subfunction 16 - get size of free RAM. ========*/
652
 
653
static inline
654
size_t _ksys_get_ram_size(void){
655
    size_t size;
656
    asm_inline(
657
        "int $0x40"
658
        :"=a"(size)
659
        :"a"(18), "b"(16)
660
    );
661
    return size;
662
}
663
 
664
/*======== Function 18, subfunction 17 - get full amount of RAM. =======*/
665
 
666
static inline
667
size_t _ksys_get_full_ram(void){
668
    size_t size;
669
    asm_inline(
670
        "int $0x40"
671
        :"=a"(size)
672
        :"a"(18), "b"(17)
673
    );
674
    return size;
675
}
676
 
677
/*===================== Function 18, subfunction 18 ====================*/
678
/*============= Terminate process/thread by the identifier. ============*/
679
 
680
static inline
681
void _ksys_kill_by_pid(uint32_t PID)
8687 turbocat 682
{
683
    asm_inline(
9093 turbocat 684
        "int $0x40"
685
        ::"a"(18), "b"(18), "c"(PID)
8687 turbocat 686
    );
687
}
688
 
9137 turbocat 689
/*===================== Function 18, subfunction 21 ====================*/
690
/*=====Get the slot number of the process / thread by identifier.. =====*/
9093 turbocat 691
 
8687 turbocat 692
static inline
9093 turbocat 693
int _ksys_get_thread_slot(int PID){
694
    int val;
8687 turbocat 695
    asm_inline(
9093 turbocat 696
        "int $0x40"
697
        :"=a"(val)
698
        :"a"(18), "b"(21), "c"(PID)
8687 turbocat 699
    );
9093 turbocat 700
    return val;
8687 turbocat 701
}
702
 
9093 turbocat 703
/*============= Function 23 - wait for event with timeout. =============*/
8687 turbocat 704
 
705
static inline
9093 turbocat 706
uint32_t _ksys_wait_event_timeout(uint32_t timeout){
707
    unsigned val;
8687 turbocat 708
    asm_inline(
709
        "int $0x40"
9093 turbocat 710
        :"=a"(val)
711
        :"a"(23), "b"(timeout)
8687 turbocat 712
    );
9093 turbocat 713
    return val;
8687 turbocat 714
}
715
 
9093 turbocat 716
/*=== Function 26, subfunction 9 - get the value of the time counter. ==*/
8687 turbocat 717
 
9093 turbocat 718
static inline
719
uint32_t _ksys_get_tick_count(){
720
    unsigned val;
721
    asm_inline(
722
        "int $0x40"
723
        :"=a"(val)
724
        :"a"(26),"b"(9)
725
    );
726
    return val;
727
}
8687 turbocat 728
 
9093 turbocat 729
/*===================== Function 26, subfunction 10 ====================*/
730
/*========== Get the value of the high precision time counter. =========*/
731
 
8687 turbocat 732
static inline
9093 turbocat 733
uint64_t  _ksys_get_ns_count(){
734
    uint64_t val;
735
    asm_inline(
736
        "int $0x40"
737
        :"=A"(val)
738
        :"a"(26), "b"(10)
739
    );
740
    return val;
741
}
742
 
743
/*=================== Function 29 - get system date. ===================*/
744
 
745
static inline
746
ksys_date_t _ksys_get_date(){
747
    ksys_date_t val;
748
    asm_inline("int $0x40":"=a"(val):"a"(29));
749
    return val;
750
}
751
 
752
/*===========+ Function 30 - work with the current folder.==============*/
753
/*--------- Subfunction 1 - set current folder for the thread. ---------*/
754
 
755
static inline
756
void _ksys_setcwd(char* dir){
757
    asm_inline(
758
        "int $0x40"
759
        ::"a"(30), "b"(1), "c"(dir)
760
    );
761
}
762
 
763
/*--------- Subfunction 2 - get current folder for the thread. ---------*/
764
 
765
static inline
766
int _ksys_getcwd(char* buf, int bufsize){
767
    register int val;
768
    asm_inline(
769
        "int $0x40"
770
        :"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize)
771
    );
772
    return val;
773
}
774
 
775
/* ---- Subfunction 3 - install the add.system directory for the kernel ------*/
776
 
777
static inline
778
int _ksys_set_kernel_dir(ksys_dir_key_t *table){
779
    register int val;
780
    asm_inline(
781
        "int $0x40"
782
        :"=a"(val)
783
        :"a"(30), "b"(3), "c"(table)
784
        :"memory"
785
    );
786
    return val;
787
}
788
 
789
/*=================== Function 37 - work with mouse. ===================*/
790
 
791
enum KSYS_MOUSE_POS{
792
    KSYS_MOUSE_SCREEN_POS = 0,
793
    KSYS_MOUSE_WINDOW_POS = 1
794
};
795
 
796
static inline
797
ksys_pos_t _ksys_get_mouse_pos(int origin){
8687 turbocat 798
    ksys_pos_t pos;
799
    asm_inline(
800
        "int $0x40 \n\t"
801
        "rol $16, %%eax"
802
        :"=a"(pos)
803
        :"a"(37),"b"(origin)
804
    );
805
    return pos;
806
}
9093 turbocat 807
 
8687 turbocat 808
static inline
9093 turbocat 809
uint32_t _ksys_get_mouse_buttons(void){ // subfunction 2 - states of the mouse buttons
810
    uint32_t val;
8687 turbocat 811
    asm_inline(
812
        "int $0x40"
813
        :"=a"(val)
814
        :"a"(37),"b"(2)
815
    );
816
    return val;
817
}
9093 turbocat 818
 
8687 turbocat 819
static inline
9093 turbocat 820
uint32_t _ksys_get_mouse_eventstate(void){   // subfunction 3 - states and events of the mouse buttons
821
    uint32_t val;
8687 turbocat 822
    asm_inline(
9093 turbocat 823
        "int $0x40"
8687 turbocat 824
        :"=a"(val)
9093 turbocat 825
        :"a"(37),"b"(3)
8687 turbocat 826
    );
827
    return val;
828
}
9093 turbocat 829
 
830
static inline
831
uint32_t _ksys_load_cursor(void *path, uint32_t flags) { // subfunction 4 - load cursor
832
    uint32_t val;
8687 turbocat 833
    asm_inline(
834
        "int $0x40"
835
        :"=a"(val)
836
        :"a"(37), "b"(4), "c"(path), "d"(flags)
837
        :"memory"
838
    );
839
    return val;
9093 turbocat 840
}
841
 
8687 turbocat 842
static inline
9093 turbocat 843
uint32_t _ksys_set_cursor(uint32_t cursor){ // subfunction 5 - set curso
844
    uint32_t old;
8687 turbocat 845
    asm_inline(
846
        "int $0x40"
847
        :"=a"(old)
848
        :"a"(37), "b"(5), "c"(cursor)
849
    );
850
    return old;
851
}
9093 turbocat 852
 
853
static inline
854
int _ksys_delete_cursor(uint32_t cursor){ // subfunction 6 - delete curso
8687 turbocat 855
    int ret;
856
    asm_inline(
857
        "int $0x40"
858
        :"=a"(ret)
859
        :"a"(37), "b"(6), "c"(cursor)
860
        :"memory"
861
    );
862
    return ret;
863
}
864
 
865
static inline
9093 turbocat 866
uint32_t _ksys_get_mouse_wheels(void)  // subfunction 7 - get scroll data
8687 turbocat 867
{
9093 turbocat 868
    uint32_t val;
8687 turbocat 869
    asm_inline(
870
        "int $0x40"
871
        :"=a"(val)
9093 turbocat 872
        :"a"(37),"b"(7)
8687 turbocat 873
    );
874
    return val;
875
}
876
 
9093 turbocat 877
/*=========== Function 40 - set the mask for expected events. ==========*/
8687 turbocat 878
 
9093 turbocat 879
enum KSYS_EVENT_MASK{
880
    KSYS_EVM_REDRAW = 1,
881
    KSYS_EVM_KEY    = 2,
882
    KSYS_EVM_BUTTON = 4,
883
    KSYS_EVM_EXIT   = 8,
884
    KSYS_EVM_BACKGROUND = 16,
885
    KSYS_EVM_MOUSE      = 32,
886
    KSYS_EVM_IPC        = 64,
887
    KSYS_EVM_STACK      = 128,
888
    KSYS_EVM_DEBUG      = 256,
889
    KSYS_EVM_STACK2     = 512,
890
    KSYS_EVM_MOUSE_FILTER  = 0x80000000,
891
    KSYS_EVM_CURSOR_FILTER = 0x40000000,
892
};
8687 turbocat 893
 
894
static inline
9093 turbocat 895
uint32_t _ksys_set_event_mask(uint32_t mask){
8687 turbocat 896
    unsigned val;
897
    asm_inline(
898
        "int $0x40"
899
        :"=a"(val)
900
        :"a"(40), "b"(mask)
901
    );
902
    return val;
903
}
904
 
9093 turbocat 905
/*====================== Function 38 - draw line. ======================*/
906
 
8687 turbocat 907
static inline
9093 turbocat 908
void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color)
8687 turbocat 909
{
910
    asm_inline(
911
        "int $0x40"
9093 turbocat 912
        ::"a"(38), "d"(color),
913
        "b"((xs << 16) | xe),
914
        "c"((ys << 16) | ye)
8687 turbocat 915
    );
916
}
9093 turbocat 917
 
918
/*============= Function 47 - draw a number in the window. =============*/
919
 
8687 turbocat 920
static inline
9093 turbocat 921
void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color){
922
    unsigned fmt;
923
    fmt = len << 16 | 0x80000000; // no leading zeros + width
8687 turbocat 924
    asm_inline(
925
        "int $0x40"
9093 turbocat 926
        ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color)
8687 turbocat 927
    );
928
}
9093 turbocat 929
 
8687 turbocat 930
static inline
9093 turbocat 931
void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg){
932
    unsigned fmt;
933
    fmt = len << 16 | 0x80000000; // no leading zeros + width
8687 turbocat 934
    asm_inline(
935
        "int $0x40"
9093 turbocat 936
        ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg)
8687 turbocat 937
    );
938
}
939
 
9093 turbocat 940
/*====== Function 48, subfunction 3 - get standard window colors. ======*/
941
 
942
static inline
943
void _ksys_get_system_colors(ksys_colors_table_t *color_table)
8687 turbocat 944
{
945
    asm_inline(
9093 turbocat 946
       "int $0x40"
947
        ::"a"(48),"b"(3),"c"(color_table),"d"(40)
948
    );
949
}
950
 
951
/*============ Function 48, subfunction 4 - get skin height. ===========*/
952
 
953
static inline
954
uint32_t _ksys_get_skin_height(){
955
    unsigned height;
956
    asm_inline(
8687 turbocat 957
        "int $0x40"
9093 turbocat 958
        :"=a"(height)
959
        :"a"(48),"b"(4)
8687 turbocat 960
    );
9093 turbocat 961
    return height;
8687 turbocat 962
}
9093 turbocat 963
 
964
/*==================== Function 51 - create thread. ====================*/
965
 
966
static inline
9137 turbocat 967
int _ksys_create_thread(void* thread_entry, void* stack_top){
9093 turbocat 968
    int val;
8687 turbocat 969
    asm_inline(
970
        "int $0x40"
971
        :"=a"(val)
9093 turbocat 972
        :"a"(51), "b"(1), "c"(thread_entry), "d"(stack_top)
9137 turbocat 973
        :"memory"
8687 turbocat 974
    );
975
    return val;
976
}
977
 
978
 
9093 turbocat 979
/*==================== Function 54, subfunction 0 ======================*/
980
/*============== Get the number of slots in the clipboard. =============*/
981
 
982
enum KSYS_CLIP_ENCODING{
983
    KSYS_CLIP_UTF8 = 0,
984
    KSYS_CLIP_CP866 = 1,
985
    KSYS_CLIP_CP1251 = 2
986
};
987
 
988
enum KSYS_CLIP_TYPES{
989
    KSYS_CLIP_TEXT = 0,
990
    KSYS_CLIP_IMAGE = 1,
991
    KSYS_CLIP_RAW = 2
992
};
993
 
8687 turbocat 994
static inline
9093 turbocat 995
int _ksys_clip_num(){
8687 turbocat 996
    unsigned val;
997
    asm_inline(
998
        "int $0x40"
999
        :"=a"(val)
1000
        :"a"(54), "b"(0)
1001
    );
1002
    return val;
1003
}
1004
 
9093 turbocat 1005
/*==================== Function 54, subfunction 1 ======================*/
1006
/*================= Read the data from the clipboard. ==================-*/
1007
 
8687 turbocat 1008
static inline
9093 turbocat 1009
char* _ksys_clip_get(int n) {  // returned buffer must be freed by _ksys_free()
8687 turbocat 1010
    char* val;
1011
    asm_inline(
1012
        "int $0x40"
1013
        :"=a"(val)
1014
        :"a"(54), "b"(1), "c"(n)
1015
    );
1016
    return val;
1017
}
1018
 
9093 turbocat 1019
/*==================== Function 54, subfunction 2 ======================*/
1020
/*================= Write the data to the clipboard. ===================*/
1021
 
8687 turbocat 1022
static inline
9093 turbocat 1023
int _ksys_clip_set(int n, char *buffer){
8687 turbocat 1024
    unsigned val;
1025
    asm_inline(
1026
        "int $0x40"
1027
        :"=a"(val)
1028
        :"a"(54), "b"(2), "c"(n), "d"(buffer)
1029
        :"memory"
1030
    );
1031
    return val;
1032
}
1033
 
9093 turbocat 1034
/*===================== Function 54, subfunction 3 =====================*/
1035
/*================ Delete the last slot in the clipboard ===============*/
1036
 
8687 turbocat 1037
static inline
9093 turbocat 1038
int _ksys_clip_pop(){
8687 turbocat 1039
    unsigned val;
1040
    asm_inline (
1041
        "int $0x40"
1042
        :"=a"(val)
1043
        :"a"(54), "b"(3)
1044
    );
1045
    return val;
1046
}
1047
 
9093 turbocat 1048
/*===================== Function 54, subfunction 4 =====================*/
1049
/*===================== Alarm reset the lock buffer ====================*/
1050
 
8687 turbocat 1051
static inline
9093 turbocat 1052
int _ksys_clip_unlock(){
8687 turbocat 1053
    unsigned val;
1054
    asm_inline(
1055
        "int $0x40"
1056
        :"=a"(val)
1057
        :"a"(54), "b"(4)
1058
    );
1059
    return val;
1060
}
1061
 
9093 turbocat 1062
/*============== Function 63 - work with the debug board. ==============*/
8687 turbocat 1063
 
1064
static inline
9093 turbocat 1065
void _ksys_debug_putc(char c){
1066
    asm_inline("int $0x40"::"a"(63), "b"(1), "c"(c));
8687 turbocat 1067
}
1068
 
1069
static inline
9093 turbocat 1070
void _ksys_debug_puts(char *s){
1071
    unsigned i=0;
1072
    while (*(s+i)){
1073
        asm_inline ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i)));
1074
        i++;
1075
    }
8687 turbocat 1076
}
1077
 
9093 turbocat 1078
/*========= Function 67 - change position/sizes of the window. =========*/
1079
 
8687 turbocat 1080
static inline
9093 turbocat 1081
void _ksys_change_window(int new_x, int new_y, int new_w, int new_h){
8687 turbocat 1082
    asm_inline(
1083
        "int $0x40"
9093 turbocat 1084
        ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
8687 turbocat 1085
    );
1086
}
1087
 
9093 turbocat 1088
/*======== Function 68, subfunction 12 - allocate memory block. ========*/
8687 turbocat 1089
 
1090
static inline
1091
void* _ksys_alloc(size_t size){
1092
    void  *val;
1093
    asm_inline(
1094
        "int $0x40"
1095
        :"=a"(val)
1096
        :"a"(68),"b"(12),"c"(size)
1097
    );
1098
    return val;
1099
}
9093 turbocat 1100
 
1101
/*========== Function 68, subfunction 13 - free memory block. ==========*/
1102
 
8687 turbocat 1103
static inline
9093 turbocat 1104
int _ksys_free(void *mem){
8687 turbocat 1105
    int val;
1106
    asm_inline(
1107
        "int $0x40"
1108
        :"=a"(val)
1109
        :"a"(68),"b"(13),"c"(mem)
1110
    );
1111
    return val;
1112
}
1113
 
9093 turbocat 1114
/*============= Function 68, subfunction 16 - load driver. =============*/
1115
 
8687 turbocat 1116
static inline
9093 turbocat 1117
ksys_drv_hand_t _ksys_load_driver(char *driver_name)
8687 turbocat 1118
{
9093 turbocat 1119
    ksys_drv_hand_t driver_h;
8687 turbocat 1120
    asm_inline(
1121
        "int $0x40"
9093 turbocat 1122
        :"=a"(driver_h)
1123
        :"a"(68), "b"(16), "c"(driver_name)
8687 turbocat 1124
    );
9093 turbocat 1125
    return driver_h;
8687 turbocat 1126
}
9093 turbocat 1127
 
1128
/*============ Function 68, subfunction 17 - driver control. ===========*/
1129
 
8687 turbocat 1130
static inline
9093 turbocat 1131
unsigned _ksys_driver_control(ksys_ioctl_t *ioctl)
8687 turbocat 1132
{
9093 turbocat 1133
    unsigned status;
8687 turbocat 1134
    asm_inline(
1135
        "int $0x40"
9093 turbocat 1136
        :"=a"(status)
1137
        :"a"(68), "b"(17), "c"(ioctl)
1138
        :"memory"
8687 turbocat 1139
    );
9093 turbocat 1140
    return status;
8687 turbocat 1141
}
1142
 
9093 turbocat 1143
/*== Function 68, subfunction 18 - subfunction 19 - load DLL (MS COFF) ==*/
8687 turbocat 1144
 
1145
static inline
9093 turbocat 1146
ksys_dll_t* _ksys_dlopen(const char* path){
1147
    ksys_dll_t *table;
8687 turbocat 1148
    asm_inline(
1149
        "int $0x40"
1150
        :"=a"(table)
1151
        :"a"(68),"b"(19), "c"(path)
1152
        :"memory"
1153
    );
1154
    return table;
1155
}
1156
 
9093 turbocat 1157
/* It is not a system call, it serves as an auxiliary tool*/
1158
 
8687 turbocat 1159
static inline
9093 turbocat 1160
void* _ksys_dlsym(ksys_dll_t *table, const char* fun_name){
8687 turbocat 1161
    unsigned i=0;
1162
    while (1){
9093 turbocat 1163
        if (!(table+i)->func_name){
8687 turbocat 1164
            break;
1165
        }else{
1166
            if (!_ksys_strcmp(fun_name, (table+i)->func_name)){
1167
                return (table+i)->func_ptr;
1168
            }
1169
        }
1170
        i++;
1171
    }
1172
    return NULL;
1173
}
1174
 
9093 turbocat 1175
/* Function 68, subfunction 20 - reallocate memory block.*/
8687 turbocat 1176
 
1177
static inline
9093 turbocat 1178
void* _ksys_realloc(void *mem, size_t size){
1179
    void *val;
8687 turbocat 1180
    asm_inline(
1181
        "int $0x40"
1182
        :"=a"(val)
9093 turbocat 1183
        :"a"(68),"b"(20),"c"(size),"d"(mem)
1184
        :"memory"
8687 turbocat 1185
    );
1186
    return val;
1187
}
9093 turbocat 1188
 
1189
/* Function 68, subfunction 21 - load driver by full name. */
1190
 
1191
static inline
1192
ksys_drv_hand_t _ksys_load_driver_opt(char *driver_path, char *cmd_line)
1193
{
1194
    ksys_drv_hand_t driver_h;
8687 turbocat 1195
    asm_inline(
1196
        "int $0x40"
9093 turbocat 1197
        :"=a"(driver_h)
1198
        :"a"(68), "b"(21), "c"(driver_path), "d"(cmd_line)
8687 turbocat 1199
    );
9093 turbocat 1200
    return driver_h;
8687 turbocat 1201
}
1202
 
9093 turbocat 1203
/*======== Function 68, subfunction 22 - open named memory area. =======*/
1204
 
1205
enum KSYS_SHM_MODE{
1206
    KSYS_SHM_OPEN = 0x00,
1207
    KSYS_SHM_OPEN_ALWAYS = 0x04,
1208
    KSYS_SHM_CREATE = 0x08,
1209
    KSYS_SHM_READ = 0x00,
1210
    KSYS_SHM_WRITE = 0x01,
1211
};
1212
 
1213
static inline
1214
int _ksys_shm_open(char *name, int mode, int size, char **new_shm)
8687 turbocat 1215
{
9093 turbocat 1216
    int error;
8687 turbocat 1217
    asm_inline(
1218
        "int $0x40"
9093 turbocat 1219
        :"=a"(*new_shm), "=d"(error)
1220
        :"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode)
8687 turbocat 1221
    );
9093 turbocat 1222
    return error;
8687 turbocat 1223
}
1224
 
9093 turbocat 1225
/*======= Function 68, subfunction 23 - close named memory area. =======*/
1226
 
8687 turbocat 1227
static inline
9093 turbocat 1228
void _ksys_shm_close(char *shm_name)
8687 turbocat 1229
{
9093 turbocat 1230
    asm_inline(
1231
        "int $0x40":
1232
        :"a"(68), "b"(23), "c"(shm_name)
1233
    );
8687 turbocat 1234
}
1235
 
9093 turbocat 1236
/*====== Function 68, subfunction 26 - release memory pages ============*/
8687 turbocat 1237
 
9093 turbocat 1238
static inline
1239
int* _ksys_unmap(void *base, size_t offset, size_t size){
1240
    int  *val;
8687 turbocat 1241
    asm_inline(
1242
        "int $0x40"
9093 turbocat 1243
        :"=a"(val)
1244
        :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size)
8687 turbocat 1245
    );
1246
    return val;
1247
}
1248
 
9093 turbocat 1249
/*========== Function 68, subfunction 27 - load file ===================*/
1250
 
8687 turbocat 1251
static inline
1252
ksys_ufile_t _ksys_load_file(const char *path)
1253
{
1254
    ksys_ufile_t uf;
1255
    asm_inline(
1256
        "int $0x40"
1257
        :"=a"(uf.data), "=d"(uf.size)
1258
        :"a"(68), "b"(27),"c"(path)
1259
        :"memory"
1260
    );
1261
    return uf;
1262
}
1263
 
9093 turbocat 1264
/*==== Function 68, subfunction 28 - load file, specifying the encoding ===*/
1265
 
8687 turbocat 1266
static inline
1267
ksys_ufile_t _ksys_load_file_enc(const char *path, unsigned file_encoding)
1268
{
1269
    ksys_ufile_t uf;
1270
    asm_inline(
1271
        "int $0x40"
1272
        :"=a"(uf.data), "=d"(uf.size)
1273
        :"a"(68), "b"(28),"c"(path), "d"(file_encoding)
1274
        :"memory"
1275
    );
1276
    return uf;
1277
}
1278
 
9093 turbocat 1279
/*==== Function 70 - work with file system with long names support. ====*/
1280
 
8687 turbocat 1281
static inline
1282
int _ksys_work_files(const ksys70_t *k)
1283
{
1284
    int status;
1285
    asm_inline(
1286
        "int $0x40"
1287
        :"=a"(status)
1288
        :"a"(70), "b"(k)
1289
        :"memory"
1290
    );
1291
    return status;
1292
}
1293
 
9093 turbocat 1294
/*====== Function 70, subfunction 0 - read file with long names support. ======*/
1295
 
8687 turbocat 1296
static inline
1297
int _ksys_file_read_file(const char *name, unsigned long long offset, unsigned size, void *buf, unsigned *bytes_read)
1298
{
1299
    ksys70_t k;
1300
    k.p00 = 0;
1301
    k.p04 = offset;
1302
    k.p12 = size;
1303
    k.buf16 = buf;
1304
    k.p20 = 0;
1305
    k.p21 = name;
1306
    int status;
8730 turbocat 1307
    asm_inline(
1308
        "int $0x40"
9165 turbocat 1309
        :"=a"(status), "=b"(*bytes_read)
8730 turbocat 1310
        :"a"(70), "b"(&k)
1311
        :"memory"
1312
    );
8687 turbocat 1313
    return status;
1314
}
1315
 
9093 turbocat 1316
/*===================== Function 70, subfunction 2 =====================*/
1317
/*============ Create/rewrite file with long names support. ============*/
1318
 
1319
static inline
1320
int _ksys_file_create(const char* name){
1321
    ksys70_t k;
9179 turbocat 1322
    k.p00   = 2;
1323
    k.p04dw = 0;
1324
    k.p08dw = 0;
1325
    k.p12   = 0;
1326
    k.p21   = name;
9093 turbocat 1327
    return _ksys_work_files(&k);
1328
}
1329
 
1330
/*===================== Function 70, subfunction 3 =====================*/
1331
/*=========== Write to existing file with long names support. ==========*/
1332
 
8687 turbocat 1333
static inline
1334
int _ksys_file_write_file(const char *name, unsigned long long offset, unsigned size, const void *buf, unsigned *bytes_written)
1335
{
1336
    ksys70_t k;
1337
    k.p00 = 3;
1338
    k.p04 = offset;
1339
    k.p12 = size;
1340
    k.cbuf16 = buf;
1341
    k.p20 = 0;
1342
    k.p21 = name;
1343
    int status;
1344
    asm_inline(
1345
        "int $0x40"
9165 turbocat 1346
        :"=a"(status), "=b"(*bytes_written)
8687 turbocat 1347
        :"a"(70), "b"(&k)
1348
        :"memory"
1349
    );
1350
    return status;
1351
}
1352
 
9093 turbocat 1353
/*========== Function 70, subfunction 5 - get information on file/folder. =====*/
8687 turbocat 1354
 
1355
static inline
1356
int _ksys_file_get_info(const char *name, ksys_bdfe_t *bdfe)
1357
{
1358
    ksys70_t k;
9179 turbocat 1359
    k.p00   = 5;
1360
    k.p04dw = 0;
1361
    k.p08dw = 0;
1362
    k.p12   = 0;
1363
    k.bdfe  = bdfe;
1364
    k.p20   = 0;
1365
    k.p21   = name;
8687 turbocat 1366
    return _ksys_work_files(&k);
1367
}
1368
 
9093 turbocat 1369
/*=========== Function 70, subfunction 7 - start application. ===========*/
1370
 
8687 turbocat 1371
static inline
9093 turbocat 1372
int _ksys_exec(char *app_name, char *args)
8687 turbocat 1373
{
9093 turbocat 1374
    ksys70_t file_opt;
1375
    file_opt.p00 = 7;
1376
    file_opt.p04dw = 0;
1377
    file_opt.p08dw = (unsigned)args;
9463 turbocat 1378
 
1379
    file_opt.p12 = 0;
1380
    file_opt.p16 = 0;
1381
    file_opt.p20 = 0;
1382
 
9093 turbocat 1383
    file_opt.p21 = app_name;
1384
    return _ksys_work_files(&file_opt);
8687 turbocat 1385
}
1386
 
9093 turbocat 1387
/*========== Function 70, subfunction 8 - delete file/folder. ==========*/
1388
 
8687 turbocat 1389
static inline
9093 turbocat 1390
int _ksys_file_delete(const char *name)
8687 turbocat 1391
{
1392
    ksys70_t k;
9093 turbocat 1393
    k.p00 = 8;
8687 turbocat 1394
    k.p20 = 0;
1395
    k.p21 = name;
1396
    return _ksys_work_files(&k);
1397
}
1398
 
9093 turbocat 1399
/*============= Function 70, subfunction 9 - create folder. ============*/
8687 turbocat 1400
 
1401
static inline
1402
int _ksys_mkdir(const char *path)
1403
{
1404
    ksys70_t dir_opt;
1405
    dir_opt.p00 = 9;
1406
    dir_opt.p21 = path;
1407
    return _ksys_work_files(&dir_opt);
1408
}
1409
 
9093 turbocat 1410
/*============= Function 70, subfunction 10 - rename/move. =============*/
8687 turbocat 1411
 
1412
static inline
9093 turbocat 1413
int _ksys_file_rename(const char *name, const char *new_name)
8687 turbocat 1414
{
9093 turbocat 1415
    ksys70_t k;
1416
    k.p00 = 10;
1417
    k.new_name = new_name;
1418
    k.p20 = 0;
1419
    k.p21 = name;
1420
    return _ksys_work_files(&k);
8687 turbocat 1421
}
1422
 
1423
 
9093 turbocat 1424
/* ######### Old names of functions and structures. Do not use again! ##########*/
8699 turbocat 1425
 
9093 turbocat 1426
#define _ksys_get_event    _ksys_wait_event
8699 turbocat 1427
 
8687 turbocat 1428
#endif // _KSYS_H_