Rev 8759 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8759 | turbocat | 1 | /* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */ |
2 | |||
3 | #ifndef _KSYS_FS_H_ |
||
4 | #define _KSYS_FS_H_ |
||
5 | |||
6 | #include |
||
7 | #include |
||
8 | |||
9 | #define asm_inline __asm__ __volatile__ |
||
10 | |||
11 | #pragma pack(push,1) |
||
12 | typedef struct{ |
||
13 | unsigned p00; |
||
14 | union{ |
||
15 | uint64_t p04; |
||
16 | struct { |
||
17 | unsigned p04dw; |
||
18 | unsigned p08dw; |
||
19 | }; |
||
20 | }; |
||
21 | unsigned p12; |
||
22 | union { |
||
23 | unsigned p16; |
||
24 | const char *new_name; |
||
25 | void *bdfe; |
||
26 | void *buf16; |
||
27 | const void *cbuf16; |
||
28 | }; |
||
29 | char p20; |
||
30 | const char *p21; |
||
31 | }ksys70_t; |
||
32 | |||
33 | typedef struct { |
||
34 | unsigned attributes; |
||
35 | unsigned name_cp; |
||
36 | char creation_time[4]; |
||
37 | char creation_date[4]; |
||
38 | char last_access_time[4]; |
||
39 | char last_access_date[4]; |
||
40 | char last_modification_time[4]; |
||
41 | char last_modification_date[4]; |
||
42 | unsigned long long size; |
||
43 | char name[0]; |
||
44 | }ksys_bdfe_t; |
||
45 | #pragma pack(pop) |
||
46 | |||
47 | static inline |
||
48 | int _ksys_work_files(const ksys70_t *k) |
||
49 | { |
||
50 | int status; |
||
51 | asm_inline( |
||
52 | "int $0x40" |
||
53 | :"=a"(status) |
||
54 | :"a"(70), "b"(k) |
||
55 | :"memory" |
||
56 | ); |
||
57 | return status; |
||
58 | } |
||
59 | |||
60 | static inline |
||
61 | int _ksys_file_delete(const char *name) |
||
62 | { |
||
63 | ksys70_t k; |
||
64 | k.p00 = 8; |
||
65 | k.p20 = 0; |
||
66 | k.p21 = name; |
||
67 | return _ksys_work_files(&k); |
||
68 | } |
||
69 | |||
70 | static inline |
||
71 | int _ksys_mkdir(const char *path) |
||
72 | { |
||
73 | ksys70_t dir_opt; |
||
74 | dir_opt.p00 = 9; |
||
75 | dir_opt.p21 = path; |
||
76 | return _ksys_work_files(&dir_opt); |
||
77 | } |
||
78 | |||
79 | static inline |
||
80 | void _ksys_setcwd(char* dir){ |
||
81 | asm_inline( |
||
82 | "int $0x40" |
||
83 | ::"a"(30), "b"(1), "c"(dir) |
||
84 | ); |
||
85 | } |
||
86 | |||
87 | static inline |
||
88 | void* _ksys_alloc(size_t size){ |
||
89 | void *val; |
||
90 | asm_inline( |
||
91 | "int $0x40" |
||
92 | :"=a"(val) |
||
93 | :"a"(68),"b"(12),"c"(size) |
||
94 | ); |
||
95 | return val; |
||
96 | } |
||
97 | |||
98 | static inline |
||
99 | int _ksys_free(void *mem) |
||
100 | { |
||
101 | int val; |
||
102 | asm_inline( |
||
103 | "int $0x40" |
||
104 | :"=a"(val) |
||
105 | :"a"(68),"b"(13),"c"(mem) |
||
106 | ); |
||
107 | return val; |
||
108 | } |
||
109 | |||
8879 | turbocat | 110 | static inline |
111 | int _ksys_getcwd(char* buf, int bufsize){ |
||
112 | register int val; |
||
113 | asm_inline( |
||
114 | "int $0x40" |
||
115 | :"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize) |
||
116 | ); |
||
117 | return val; |
||
118 | } |
||
119 | |||
8759 | turbocat | 120 | #endif |