Rev 8695 | Rev 9124 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8695 | Rev 9097 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | 4 | ||
5 | #define asm_inline __asm__ __volatile__ |
5 | #define asm_inline __asm__ __volatile__ |
6 | 6 | ||
7 | #pragma pack(push,1) |
7 | #pragma pack(push,1) |
8 | typedef union{ |
8 | typedef union{ |
9 | unsigned val; |
9 | unsigned val; |
10 | struct{ |
10 | struct{ |
11 | short x; |
11 | short x; |
12 | short y; |
12 | short y; |
13 | }; |
13 | }; |
14 | }ksys_pos_t; |
14 | }ksys_pos_t; |
15 | 15 | ||
16 | typedef union ksys_oskey_t{ |
16 | typedef union ksys_oskey_t{ |
17 | unsigned val; |
17 | unsigned val; |
18 | struct{ |
18 | struct{ |
19 | unsigned char state; |
19 | unsigned char state; |
20 | unsigned char code; |
20 | unsigned char code; |
21 | unsigned char ctrl_key; |
21 | unsigned char ctrl_key; |
22 | }; |
22 | }; |
23 | }ksys_oskey_t; |
23 | }ksys_oskey_t; |
24 | 24 | ||
25 | typedef struct{ |
25 | typedef struct{ |
26 | unsigned handle; |
26 | unsigned handle; |
27 | unsigned io_code; |
27 | unsigned io_code; |
28 | unsigned *input; |
28 | unsigned *input; |
29 | int inp_size; |
29 | int inp_size; |
30 | void *output; |
30 | void *output; |
31 | int out_size; |
31 | int out_size; |
32 | }ksys_ioctl_t; |
32 | }ksys_ioctl_t; |
33 | 33 | ||
34 | typedef struct{ |
34 | typedef struct{ |
35 | void *data; |
35 | void *data; |
36 | size_t size; |
36 | size_t size; |
37 | }ksys_ufile_t; |
37 | }ksys_ufile_t; |
38 | 38 | ||
39 | 39 | ||
40 | typedef struct{ |
40 | typedef struct{ |
41 | unsigned p00; |
41 | unsigned p00; |
42 | union{ |
42 | union{ |
43 | uint64_t p04; |
43 | uint64_t p04; |
44 | struct { |
44 | struct { |
45 | unsigned p04dw; |
45 | unsigned p04dw; |
46 | unsigned p08dw; |
46 | unsigned p08dw; |
47 | }; |
47 | }; |
48 | }; |
48 | }; |
49 | unsigned p12; |
49 | unsigned p12; |
50 | union { |
50 | union { |
51 | unsigned p16; |
51 | unsigned p16; |
52 | const char *new_name; |
52 | const char *new_name; |
53 | void *bdfe; |
53 | void *bdfe; |
54 | void *buf16; |
54 | void *buf16; |
55 | const void *cbuf16; |
55 | const void *cbuf16; |
56 | }; |
56 | }; |
57 | char p20; |
57 | char p20; |
58 | const char *p21; |
58 | const char *p21; |
59 | }ksys70_t; |
59 | }ksys70_t; |
60 | 60 | ||
61 | typedef struct { |
61 | typedef struct { |
62 | int cpu_usage; //+0 |
62 | int cpu_usage; //+0 |
63 | int window_pos_info; //+4 |
63 | int window_pos_info; //+4 |
64 | short int reserved1; //+8 |
64 | short int reserved1; //+8 |
65 | char name[12]; //+10 |
65 | char name[12]; //+10 |
66 | int memstart; //+22 |
66 | int memstart; //+22 |
67 | int memused; //+26 |
67 | int memused; //+26 |
68 | int pid; //+30 |
68 | int pid; //+30 |
69 | int winx_start; //+34 |
69 | int winx_start; //+34 |
70 | int winy_start; //+38 |
70 | int winy_start; //+38 |
71 | int winx_size; //+42 |
71 | int winx_size; //+42 |
72 | int winy_size; //+46 |
72 | int winy_size; //+46 |
73 | short int slot_info; //+50 |
73 | short int slot_info; //+50 |
74 | short int reserved2; //+52 |
74 | short int reserved2; //+52 |
75 | int clientx; //+54 |
75 | int clientx; //+54 |
76 | int clienty; //+58 |
76 | int clienty; //+58 |
77 | int clientwidth; //+62 |
77 | int clientwidth; //+62 |
78 | int clientheight; //+66 |
78 | int clientheight; //+66 |
79 | unsigned char window_state;//+70 |
79 | unsigned char window_state;//+70 |
80 | char reserved3[1024-71]; //+71 |
80 | char reserved3[1024-71]; //+71 |
81 | }ksys_proc_table_t; |
81 | }ksys_proc_table_t; |
82 | 82 | ||
83 | #pragma pack(pop) |
83 | #pragma pack(pop) |
84 | 84 | ||
85 | static inline |
85 | static inline |
86 | int _ksys_process_info(ksys_proc_table_t* table, int pid) |
86 | int _ksys_process_info(ksys_proc_table_t* table, int pid) |
87 | { |
87 | { |
88 | int val; |
88 | int val; |
89 | asm_inline( |
89 | asm_inline( |
90 | "int $0x40" |
90 | "int $0x40" |
91 | :"=a"(val) |
91 | :"=a"(val) |
92 | :"a"(9), "b"(table), "c"(pid) |
92 | :"a"(9), "b"(table), "c"(pid) |
93 | :"memory" |
93 | :"memory" |
94 | ); |
94 | ); |
95 | return val; |
95 | return val; |
96 | } |
96 | } |
97 | 97 | ||
98 | static inline |
98 | static inline |
99 | void _ksys_change_window(int new_x, int new_y, int new_w, int new_h) |
99 | void _ksys_change_window(int new_x, int new_y, int new_w, int new_h) |
100 | { |
100 | { |
101 | asm_inline( |
101 | asm_inline( |
102 | "int $0x40" |
102 | "int $0x40" |
103 | ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h) |
103 | ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h) |
104 | ); |
104 | ); |
105 | } |
105 | } |
106 | 106 | ||
107 | static inline |
107 | static inline |
108 | ksys_pos_t _ksys_screen_size() |
108 | ksys_pos_t _ksys_screen_size() |
109 | { |
109 | { |
110 | ksys_pos_t size; |
110 | ksys_pos_t size; |
111 | ksys_pos_t size_tmp; |
111 | ksys_pos_t size_tmp; |
112 | asm_inline( |
112 | asm_inline( |
113 | "int $0x40" |
113 | "int $0x40" |
114 | :"=a"(size_tmp) |
114 | :"=a"(size_tmp) |
115 | :"a"(14) |
115 | :"a"(14) |
116 | ); |
116 | ); |
117 | size.x = size_tmp.y; |
117 | size.x = size_tmp.y; |
118 | size.y = size_tmp.x; |
118 | size.y = size_tmp.x; |
119 | return size; |
119 | return size; |
120 | } |
120 | } |
121 | 121 | ||
122 | void *memrchr(const void *m, int c, size_t n) |
122 | void *memrchr(const void *m, int c, size_t n) |
123 | { |
123 | { |
124 | const unsigned char *s = (const unsigned char*)m; |
124 | const unsigned char *s = (const unsigned char*)m; |
125 | c = (unsigned char)c; |
125 | c = (unsigned char)c; |
126 | while (n--) if (s[n]==c) return (void *)(s+n); |
126 | while (n--) if (s[n]==c) return (void *)(s+n); |
127 | return 0; |
127 | return 0; |
128 | } |
128 | } |
129 | 129 | ||
130 | void kolibri_set_win_center() |
130 | void kolibri_set_win_center() |
131 | { |
131 | { |
132 | ksys_proc_table_t *info = (ksys_proc_table_t*)malloc(sizeof(ksys_proc_table_t)); |
132 | ksys_proc_table_t *info = (ksys_proc_table_t*)malloc(sizeof(ksys_proc_table_t)); |
133 | _ksys_process_info(info, -1); |
133 | _ksys_process_info(info, -1); |
134 | 134 | ||
135 | ksys_pos_t screen_size= _ksys_screen_size(); |
135 | ksys_pos_t screen_size= _ksys_screen_size(); |
136 | int new_x = screen_size.x/2-info->winx_size/2; |
136 | int new_x = screen_size.x/2-info->winx_size/2; |
137 | int new_y = screen_size.y/2-info->winy_size/2; |
137 | int new_y = screen_size.y/2-info->winy_size/2; |
138 | _ksys_change_window(new_x, new_y, -1, -1); |
138 | _ksys_change_window(new_x, new_y, -1, -1); |
139 | free(info); |
139 | free(info); |
140 | } |
140 | } |
141 | 141 | ||
142 | int mkdir(const char *path, unsigned v) |
142 | int mkdir(const char *path, unsigned v) |
143 | { |
143 | { |
144 | int status; |
144 | int status; |
145 | ksys70_t dir_opt; |
145 | ksys70_t dir_opt; |
146 | dir_opt.p00 = 9; |
146 | dir_opt.p00 = 9; |
147 | dir_opt.p21 = path; |
147 | dir_opt.p21 = path; |
148 | asm_inline( |
148 | asm_inline( |
149 | "int $0x40" |
149 | "int $0x40" |
150 | :"=a"(status) |
150 | :"=a"(status) |
151 | :"a"(70), "b"(&dir_opt) |
151 | :"a"(70), "b"(&dir_opt) |
152 | :"memory" |
152 | :"memory" |
153 | ); |
153 | ); |
154 | return status; |
154 | return status; |
155 | } |
155 | } |
156 | 156 | ||
157 | char *dirname (char *path) |
157 | char *dirname (char *path) |
158 | { |
158 | { |
159 | static const char dot[] = "."; |
159 | static const char dot[] = "."; |
160 | char *last_slash; |
160 | char *last_slash; |
161 | /* Find last '/'. */ |
161 | /* Find last '/'. */ |
162 | last_slash = path != NULL ? strrchr (path, '/') : NULL; |
162 | last_slash = path != NULL ? strrchr (path, '/') : NULL; |
163 | if (last_slash != NULL && last_slash != path && last_slash[1] == '\0') |
163 | if (last_slash != NULL && last_slash != path && last_slash[1] == '\0') |
164 | { |
164 | { |
165 | /* Determine whether all remaining characters are slashes. */ |
165 | /* Determine whether all remaining characters are slashes. */ |
166 | char *runp; |
166 | char *runp; |
167 | for (runp = last_slash; runp != path; --runp) |
167 | for (runp = last_slash; runp != path; --runp) |
168 | if (runp[-1] != '/') |
168 | if (runp[-1] != '/') |
169 | break; |
169 | break; |
170 | /* The '/' is the last character, we have to look further. */ |
170 | /* The '/' is the last character, we have to look further. */ |
171 | if (runp != path) |
171 | if (runp != path) |
172 | last_slash = (char*)memrchr((void*)path, '/', runp - path); |
172 | last_slash = (char*)memrchr((void*)path, '/', runp - path); |
173 | } |
173 | } |
174 | if (last_slash != NULL) |
174 | if (last_slash != NULL) |
175 | { |
175 | { |
176 | /* Determine whether all remaining characters are slashes. */ |
176 | /* Determine whether all remaining characters are slashes. */ |
177 | char *runp; |
177 | char *runp; |
178 | for (runp = last_slash; runp != path; --runp) |
178 | for (runp = last_slash; runp != path; --runp) |
179 | if (runp[-1] != '/') |
179 | if (runp[-1] != '/') |
180 | break; |
180 | break; |
181 | /* Terminate the path. */ |
181 | /* Terminate the path. */ |
182 | if (runp == path) |
182 | if (runp == path) |
183 | { |
183 | { |
184 | /* The last slash is the first character in the string. We have to |
184 | /* The last slash is the first character in the string. We have to |
185 | return "/". As a special case we have to return "//" if there |
185 | return "/". As a special case we have to return "//" if there |
186 | are exactly two slashes at the beginning of the string. See |
186 | are exactly two slashes at the beginning of the string. See |
187 | XBD 4.10 Path Name Resolution for more information. */ |
187 | XBD 4.10 Path Name Resolution for more information. */ |
188 | if (last_slash == path + 1) |
188 | if (last_slash == path + 1) |
189 | ++last_slash; |
189 | ++last_slash; |
190 | else |
190 | else |
191 | last_slash = path + 1; |
191 | last_slash = path + 1; |
192 | } |
192 | } |
193 | else |
193 | else |
194 | last_slash = runp; |
194 | last_slash = runp; |
195 | last_slash[0] = '\0'; |
195 | last_slash[0] = '\0'; |
196 | } |
196 | } |
197 | else |
197 | else |
198 | /* This assignment is ill-designed but the XPG specs require to |
198 | /* This assignment is ill-designed but the XPG specs require to |
199 | return a string containing "." in any case no directory part is |
199 | return a string containing "." in any case no directory part is |
200 | found and so a static and constant string is required. */ |
200 | found and so a static and constant string is required. */ |
201 | path = (char *) dot; |
201 | path = (char *) dot; |
202 | return path; |
202 | return path; |
203 | } |
203 | } |
204 | 204 | ||
205 | void setcwd(char* path){ |
205 | void setcwd(char* path){ |
206 | asm_inline( |
206 | asm_inline( |
207 | "int $0x40" |
207 | "int $0x40" |
208 | ::"a"(30), "b"(1), "c"(path) |
208 | ::"a"(30), "b"(1), "c"(path) |
209 | ); |
209 | ); |
210 | } |
210 | } |
- | 211 |