Subversion Repositories Kolibri OS

Rev

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

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