Rev 2415 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2415 | Rev 2427 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | 4 | ||
5 | #ifdef CONFIG_DEBUF |
5 | #ifdef CONFIG_DEBUF |
6 | #define DBG(format,...) printf(format,##__VA_ARGS__) |
6 | #define DBG(format,...) printf(format,##__VA_ARGS__) |
7 | #else |
7 | #else |
8 | #define DBG(format,...) |
8 | #define DBG(format,...) |
9 | #endif |
9 | #endif |
10 | 10 | ||
11 | typedef unsigned int color_t; |
11 | typedef unsigned int color_t; |
12 | 12 | ||
13 | typedef union __attribute__((packed)) |
13 | typedef union __attribute__((packed)) |
14 | { |
14 | { |
15 | uint32_t val; |
15 | uint32_t val; |
16 | struct |
16 | struct |
17 | { |
17 | { |
18 | short x; |
18 | short x; |
19 | short y; |
19 | short y; |
20 | }; |
20 | }; |
21 | }pos_t; |
21 | }pos_t; |
22 | 22 | ||
23 | typedef union __attribute__((packed)) |
23 | typedef union __attribute__((packed)) |
24 | { |
24 | { |
25 | uint32_t val; |
25 | uint32_t val; |
26 | struct |
26 | struct |
27 | { |
27 | { |
28 | uint8_t state; |
28 | uint8_t state; |
29 | uint8_t code; |
29 | uint8_t code; |
30 | uint16_t ctrl_key; |
30 | uint16_t ctrl_key; |
31 | }; |
31 | }; |
32 | }oskey_t; |
32 | }oskey_t; |
33 | 33 | ||
34 | static inline |
34 | static inline |
35 | void BeginDraw(void) |
35 | void BeginDraw(void) |
36 | { |
36 | { |
37 | __asm__ __volatile__( |
37 | __asm__ __volatile__( |
38 | "int $0x40" ::"a"(12),"b"(1)); |
38 | "int $0x40" ::"a"(12),"b"(1)); |
39 | }; |
39 | }; |
40 | 40 | ||
41 | static inline |
41 | static inline |
42 | void EndDraw(void) |
42 | void EndDraw(void) |
43 | { |
43 | { |
44 | __asm__ __volatile__( |
44 | __asm__ __volatile__( |
45 | "int $0x40" ::"a"(12),"b"(2)); |
45 | "int $0x40" ::"a"(12),"b"(2)); |
46 | }; |
46 | }; |
47 | 47 | ||
48 | static inline void DrawWindow(int x, int y, int w, int h, char *name, |
48 | static inline void DrawWindow(int x, int y, int w, int h, char *name, |
49 | color_t workcolor, uint32_t style) |
49 | color_t workcolor, uint32_t style) |
50 | { |
50 | { |
51 | 51 | ||
52 | __asm__ __volatile__( |
52 | __asm__ __volatile__( |
53 | "int $0x40" |
53 | "int $0x40" |
54 | ::"a"(0), |
54 | ::"a"(0), |
55 | "b"((x << 16) | (w & 0xFFFF)), |
55 | "b"((x << 16) | (w & 0xFFFF)), |
56 | "c"((y << 16) | (h & 0xFFFF)), |
56 | "c"((y << 16) | (h & 0xFFFF)), |
57 | "d"((style << 24) | (workcolor & 0xFFFFFF)), |
57 | "d"((style << 24) | (workcolor & 0xFFFFFF)), |
58 | "D"(name)); |
58 | "D"(name)); |
59 | }; |
59 | }; |
60 | 60 | ||
61 | static inline |
61 | static inline |
62 | pos_t get_mouse_pos(void) |
62 | pos_t get_mouse_pos(void) |
63 | { |
63 | { |
64 | pos_t val; |
64 | pos_t val; |
65 | 65 | ||
66 | __asm__ __volatile__( |
66 | __asm__ __volatile__( |
67 | "int $0x40 \n\t" |
67 | "int $0x40 \n\t" |
68 | "rol $16, %%eax" |
68 | "rol $16, %%eax" |
69 | :"=eax"(val) |
69 | :"=a"(val) |
70 | :"a"(37),"b"(1)); |
70 | :"a"(37),"b"(1)); |
71 | return val; |
71 | return val; |
72 | } |
72 | } |
73 | 73 | ||
74 | static inline |
74 | static inline |
75 | pos_t get_cursor_pos(void) |
75 | pos_t get_cursor_pos(void) |
76 | { |
76 | { |
77 | pos_t val; |
77 | pos_t val; |
78 | 78 | ||
79 | __asm__ __volatile__( |
79 | __asm__ __volatile__( |
80 | "int $0x40 \n\t" |
80 | "int $0x40 \n\t" |
81 | "rol $16, %%eax" |
81 | "rol $16, %%eax" |
82 | :"=eax"(val) |
82 | :"=a"(val) |
83 | :"a"(37),"b"(0)); |
83 | :"a"(37),"b"(0)); |
84 | return val; |
84 | return val; |
85 | } |
85 | } |
86 | 86 | ||
87 | static inline |
87 | static inline |
88 | uint32_t get_mouse_buttons(void) |
88 | uint32_t get_mouse_buttons(void) |
89 | { |
89 | { |
90 | uint32_t val; |
90 | uint32_t val; |
91 | 91 | ||
92 | __asm__ __volatile__( |
92 | __asm__ __volatile__( |
93 | "int $0x40" |
93 | "int $0x40" |
94 | :"=a"(val) |
94 | :"=a"(val) |
95 | :"a"(37),"b"(2)); |
95 | :"a"(37),"b"(2)); |
96 | return val; |
96 | return val; |
97 | }; |
97 | }; |
98 | 98 | ||
99 | static inline |
99 | static inline |
100 | uint32_t get_mouse_wheels(void) |
100 | uint32_t get_mouse_wheels(void) |
101 | { |
101 | { |
102 | uint32_t val; |
102 | uint32_t val; |
103 | 103 | ||
104 | __asm__ __volatile__( |
104 | __asm__ __volatile__( |
105 | "int $0x40 \n\t" |
105 | "int $0x40 \n\t" |
106 | "rol $16, %%eax" |
106 | "rol $16, %%eax" |
107 | :"=a"(val) |
107 | :"=a"(val) |
108 | :"a"(37),"b"(7)); |
108 | :"a"(37),"b"(7)); |
109 | return val; |
109 | return val; |
110 | }; |
110 | }; |
111 | 111 | ||
112 | static inline |
112 | static inline |
113 | uint32_t wait_for_event(uint32_t time) |
113 | uint32_t wait_for_event(uint32_t time) |
114 | { |
114 | { |
115 | uint32_t val; |
115 | uint32_t val; |
116 | __asm__ __volatile__( |
116 | __asm__ __volatile__( |
117 | "int $0x40" |
117 | "int $0x40" |
118 | :"=a"(val) |
118 | :"=a"(val) |
119 | :"a"(23), "b"(time)); |
119 | :"a"(23), "b"(time)); |
120 | return val; |
120 | return val; |
121 | }; |
121 | }; |
122 | 122 | ||
123 | static inline uint32_t check_os_event() |
123 | static inline uint32_t check_os_event() |
124 | { |
124 | { |
125 | uint32_t val; |
125 | uint32_t val; |
126 | __asm__ __volatile__( |
126 | __asm__ __volatile__( |
127 | "int $0x40" |
127 | "int $0x40" |
128 | :"=a"(val) |
128 | :"=a"(val) |
129 | :"a"(11)); |
129 | :"a"(11)); |
130 | return val; |
130 | return val; |
131 | }; |
131 | }; |
132 | 132 | ||
133 | static inline |
133 | static inline |
134 | uint32_t get_tick_count(void) |
134 | uint32_t get_tick_count(void) |
135 | { |
135 | { |
136 | uint32_t val; |
136 | uint32_t val; |
137 | __asm__ __volatile__( |
137 | __asm__ __volatile__( |
138 | "int $0x40" |
138 | "int $0x40" |
139 | :"=eax"(val) |
139 | :"=a"(val) |
140 | :"a"(26),"b"(9)); |
140 | :"a"(26),"b"(9)); |
141 | return val; |
141 | return val; |
142 | }; |
142 | }; |
143 | 143 | ||
144 | static inline |
144 | static inline |
145 | oskey_t get_key(void) |
145 | oskey_t get_key(void) |
146 | { |
146 | { |
147 | oskey_t val; |
147 | oskey_t val; |
148 | __asm__ __volatile__( |
148 | __asm__ __volatile__( |
149 | "int $0x40" |
149 | "int $0x40" |
150 | :"=eax"(val) |
150 | :"=a"(val) |
151 | :"a"(2)); |
151 | :"a"(2)); |
152 | return val; |
152 | return val; |
153 | } |
153 | } |
154 | 154 | ||
155 | static inline |
155 | static inline |
156 | void draw_line(int xs, int ys, int xe, int ye, color_t color) |
156 | void draw_line(int xs, int ys, int xe, int ye, color_t color) |
157 | { |
157 | { |
158 | __asm__ __volatile__( |
158 | __asm__ __volatile__( |
159 | "int $0x40" |
159 | "int $0x40" |
160 | ::"a"(38), "d"(color), |
160 | ::"a"(38), "d"(color), |
161 | "b"((xs << 16) | xe), |
161 | "b"((xs << 16) | xe), |
162 | "c"((ys << 16) | ye)); |
162 | "c"((ys << 16) | ye)); |
163 | } |
163 | } |
164 | 164 | ||
165 | 165 | ||
166 | 166 | ||
167 | static inline |
167 | static inline |
168 | void draw_bar(int x, int y, int w, int h, color_t color) |
168 | void draw_bar(int x, int y, int w, int h, color_t color) |
169 | { |
169 | { |
170 | __asm__ __volatile__( |
170 | __asm__ __volatile__( |
171 | "int $0x40" |
171 | "int $0x40" |
172 | ::"a"(13), "d"(color), |
172 | ::"a"(13), "d"(color), |
173 | "b"((x << 16) | w), |
173 | "b"((x << 16) | w), |
174 | "c"((y << 16) | h)); |
174 | "c"((y << 16) | h)); |
175 | } |
175 | } |
176 | 176 | ||
177 | static inline |
177 | static inline |
178 | void draw_bitmap(void *bitmap, int x, int y, int w, int h) |
178 | void draw_bitmap(void *bitmap, int x, int y, int w, int h) |
179 | { |
179 | { |
180 | __asm__ __volatile__( |
180 | __asm__ __volatile__( |
181 | "int $0x40" |
181 | "int $0x40" |
182 | ::"a"(7), "b"(bitmap), |
182 | ::"a"(7), "b"(bitmap), |
183 | "c"((w << 16) | h), |
183 | "c"((w << 16) | h), |
184 | "d"((x << 16) | y)); |
184 | "d"((x << 16) | y)); |
185 | } |
185 | } |
186 | 186 | ||
187 | static inline |
187 | static inline |
188 | void draw_text(const char *text, int x, int y, int len, color_t color) |
188 | void draw_text(const char *text, int x, int y, int len, color_t color) |
189 | { |
189 | { |
190 | __asm__ __volatile__( |
190 | __asm__ __volatile__( |
191 | "int $0x40" |
191 | "int $0x40" |
192 | ::"a"(4),"d"(text), |
192 | ::"a"(4),"d"(text), |
193 | "b"((x << 16) | y), |
193 | "b"((x << 16) | y), |
194 | "S"(len),"c"(color)); |
194 | "S"(len),"c"(color)); |
195 | } |
195 | } |
196 | 196 | ||
197 | static inline |
197 | static inline |
198 | void *user_alloc(size_t size) |
198 | void *user_alloc(size_t size) |
199 | { |
199 | { |
200 | void *val; |
200 | void *val; |
201 | __asm__ __volatile__( |
201 | __asm__ __volatile__( |
202 | "int $0x40" |
202 | "int $0x40" |
203 | :"=eax"(val) |
203 | :"=a"(val) |
204 | :"a"(68),"b"(12),"c"(size)); |
204 | :"a"(68),"b"(12),"c"(size)); |
205 | return val; |
205 | return val; |
206 | } |
206 | } |
207 | 207 | ||
208 | static inline |
208 | static inline |
209 | int user_free(void *mem) |
209 | int user_free(void *mem) |
210 | { |
210 | { |
211 | int val; |
211 | int val; |
212 | __asm__ __volatile__( |
212 | __asm__ __volatile__( |
213 | "int $0x40" |
213 | "int $0x40" |
214 | :"=eax"(val) |
214 | :"=a"(val) |
215 | :"a"(68),"b"(12),"c"(mem)); |
215 | :"a"(68),"b"(12),"c"(mem)); |
216 | return val; |
216 | return val; |
217 | } |
217 | } |
218 | 218 | ||
219 | static inline |
219 | static inline |
220 | int *user_unmap(void *base, size_t offset, size_t size) |
220 | int *user_unmap(void *base, size_t offset, size_t size) |
221 | { |
221 | { |
222 | void *val; |
222 | void *val; |
223 | __asm__ __volatile__( |
223 | __asm__ __volatile__( |
224 | "int $0x40" |
224 | "int $0x40" |
225 | :"=eax"(val) |
225 | :"=a"(val) |
226 | :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size)); |
226 | :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size)); |
227 | return val; |
227 | return val; |
228 | } |
228 | } |
229 | 229 | ||
230 | /* |
230 | /* |
231 | extern inline |
231 | extern inline |
232 | void exit(int status) __attribute__((noreturn)) ; |
232 | void exit(int status) __attribute__((noreturn)) ; |
233 | 233 | ||
234 | extern inline |
234 | extern inline |
235 | void exit(int status) |
235 | void exit(int status) |
236 | { |
236 | { |
237 | __asm__ __volatile__( |
237 | __asm__ __volatile__( |
238 | "int $0x40" |
238 | "int $0x40" |
239 | ::"a"(-1)); |
239 | ::"a"(-1)); |
240 | for(;;); |
240 | for(;;); |
241 | } |
241 | } |
242 | */ |
242 | */ |
243 | 243 | ||
244 | static inline |
244 | static inline |
245 | uint32_t load_cursor(void *path, uint32_t flags) |
245 | uint32_t load_cursor(void *path, uint32_t flags) |
246 | { |
246 | { |
247 | uint32_t val; |
247 | uint32_t val; |
248 | __asm__ __volatile__( |
248 | __asm__ __volatile__( |
249 | "int $0x40" |
249 | "int $0x40" |
250 | :"=eax"(val) |
250 | :"=a"(val) |
251 | :"a"(37), "b"(4), "c"(path), "d"(flags)); |
251 | :"a"(37), "b"(4), "c"(path), "d"(flags)); |
252 | return val; |
252 | return val; |
253 | } |
253 | } |
254 | 254 | ||
255 | static inline |
255 | static inline |
256 | uint32_t set_cursor(uint32_t cursor) |
256 | uint32_t set_cursor(uint32_t cursor) |
257 | { |
257 | { |
258 | uint32_t old; |
258 | uint32_t old; |
259 | __asm__ __volatile__( |
259 | __asm__ __volatile__( |
260 | "int $0x40" |
260 | "int $0x40" |
261 | :"=eax"(old) |
261 | :"=a"(old) |
262 | :"a"(37), "b"(5), "c"(cursor)); |
262 | :"a"(37), "b"(5), "c"(cursor)); |
263 | return old; |
263 | return old; |
264 | } |
264 | } |
265 | 265 | ||
266 | static inline void get_proc_info(char *info) |
266 | static inline void get_proc_info(char *info) |
267 | { |
267 | { |
268 | __asm__ __volatile__( |
268 | __asm__ __volatile__( |
269 | "int $0x40" |
269 | "int $0x40" |
270 | : |
270 | : |
271 | :"a"(9), "b"(info), "c"(-1)); |
271 | :"a"(9), "b"(info), "c"(-1)); |
272 | } |
272 | } |
273 | 273 | ||
274 | static inline |
274 | static inline |
275 | void* user_realloc(void *mem, size_t size) |
275 | void* user_realloc(void *mem, size_t size) |
276 | { |
276 | { |
277 | void *val; |
277 | void *val; |
278 | __asm__ __volatile__( |
278 | __asm__ __volatile__( |
279 | "int $0x40" |
279 | "int $0x40" |
280 | :"=eax"(val) |
280 | :"=a"(val) |
281 | :"a"(68),"b"(12),"c"(size),"d"(mem) |
281 | :"a"(68),"b"(12),"c"(size),"d"(mem) |
282 | :"memory"); |
282 | :"memory"); |
283 | 283 | ||
284 | return val; |
284 | return val; |
285 | } |
285 | } |
286 | 286 | ||
287 | void *load_file(const char *path, size_t *len); |
287 | void *load_file(const char *path, size_t *len); |
288 | 288 | ||
289 | void *get_resource(void *data, uint32_t id); |
289 | void *get_resource(void *data, uint32_t id); |
290 | 290 | ||
291 | struct blit_call |
291 | struct blit_call |
292 | { |
292 | { |
293 | int dstx; |
293 | int dstx; |
294 | int dsty; |
294 | int dsty; |
295 | int w; |
295 | int w; |
296 | int h; |
296 | int h; |
297 | 297 | ||
298 | int srcx; |
298 | int srcx; |
299 | int srcy; |
299 | int srcy; |
300 | int srcw; |
300 | int srcw; |
301 | int srch; |
301 | int srch; |
302 | 302 | ||
303 | unsigned char *bitmap; |
303 | unsigned char *bitmap; |
304 | int stride; |
304 | int stride; |
305 | }; |
305 | }; |
306 | 306 | ||
307 | void Blit(void *bitmap, int dst_x, int dst_y, |
307 | void Blit(void *bitmap, int dst_x, int dst_y, |
308 | int src_x, int src_y, int w, int h, |
308 | int src_x, int src_y, int w, int h, |
309 | int src_w, int src_h, int stride);><>><>><>><>><>><>><>><>><>><> |
309 | int src_w, int src_h, int stride);><>><>><>><>><>><>><>><>><>><> |
310 | 310 | ||
- | 311 | ||
- | 312 | ||
- | 313 | ||
- | 314 | ||
- | 315 |