Rev 2427 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2349 | Serge | 1 | #include |
2 | #include |
||
3 | #include |
||
4 | #include |
||
5 | #include |
||
6 | #include |
||
2427 | Serge | 7 | #include "../winlib/winlib.h" |
2349 | Serge | 8 | #include "fplay.h" |
9 | |||
10 | #define DISPLAY_VERSION 0x0200 /* 2.00 */ |
||
11 | |||
12 | #define SRV_GETVERSION 0 |
||
13 | #define SRV_GET_CAPS 3 |
||
14 | |||
15 | #define SRV_CREATE_SURFACE 10 |
||
2415 | Serge | 16 | #define SRV_LOCK_SURFACE 12 |
17 | |||
2349 | Serge | 18 | #define SRV_BLIT_VIDEO 20 |
19 | |||
20 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
||
21 | #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) |
||
22 | |||
23 | //void InitPixlib(uint32_t flags); |
||
24 | |||
25 | static uint32_t service; |
||
26 | static uint32_t blit_caps; |
||
27 | |||
28 | typedef struct |
||
29 | { |
||
30 | uint32_t idx; |
||
31 | union |
||
32 | { |
||
33 | uint32_t opt[2]; |
||
34 | struct { |
||
35 | uint32_t max_tex_width; |
||
36 | uint32_t max_tex_height; |
||
37 | }cap1; |
||
38 | }; |
||
39 | }hwcaps_t; |
||
40 | |||
41 | static uint32_t get_service(char *name) |
||
42 | { |
||
43 | uint32_t retval = 0; |
||
44 | asm volatile ("int $0x40" |
||
45 | :"=a"(retval) |
||
46 | :"a"(68),"b"(16),"c"(name) |
||
47 | :"memory"); |
||
48 | |||
49 | return retval; |
||
50 | }; |
||
51 | |||
52 | static int call_service(ioctl_t *io) |
||
53 | { |
||
54 | int retval; |
||
55 | |||
56 | asm volatile("int $0x40" |
||
57 | :"=a"(retval) |
||
58 | :"a"(68),"b"(17),"c"(io) |
||
59 | :"memory","cc"); |
||
60 | |||
61 | return retval; |
||
62 | }; |
||
63 | |||
64 | #define BUFFER_SIZE(n) ((n)*sizeof(uint32_t)) |
||
65 | |||
66 | |||
67 | |||
68 | uint32_t InitPixlib(uint32_t caps) |
||
69 | { |
||
70 | uint32_t api_version; |
||
71 | hwcaps_t hwcaps; |
||
72 | ioctl_t io; |
||
73 | |||
74 | // __asm__ __volatile__("int3"); |
||
75 | |||
76 | service = get_service("DISPLAY"); |
||
77 | if(service == 0) |
||
78 | goto fail; |
||
79 | |||
80 | io.handle = service; |
||
81 | io.io_code = SRV_GETVERSION; |
||
82 | io.input = NULL; |
||
83 | io.inp_size = 0; |
||
84 | io.output = &api_version; |
||
85 | io.out_size = BUFFER_SIZE(1); |
||
86 | |||
87 | if (call_service(&io)!=0) |
||
88 | goto fail; |
||
89 | |||
90 | if( (DISPLAY_VERSION > (api_version & 0xFFFF)) || |
||
91 | (DISPLAY_VERSION < (api_version >> 16))) |
||
92 | goto fail; |
||
93 | |||
94 | /* |
||
95 | * Let's see what this service can do |
||
96 | */ |
||
97 | hwcaps.idx = 0; |
||
98 | |||
99 | io.handle = service; |
||
100 | io.io_code = SRV_GET_CAPS; |
||
101 | io.input = &hwcaps; |
||
102 | io.inp_size = sizeof(hwcaps); |
||
103 | io.output = NULL; |
||
104 | io.out_size = 0; |
||
105 | |||
106 | if (call_service(&io)!=0) |
||
107 | goto fail; |
||
108 | |||
109 | blit_caps = hwcaps.opt[0]; |
||
110 | |||
111 | printf("\nDISPLAY service handle %x\n", service); |
||
112 | |||
113 | if( blit_caps ) |
||
114 | printf("service caps %s%s%s\n", |
||
115 | (blit_caps & HW_BIT_BLIT) != 0 ?"HW_BIT_BLIT ":"", |
||
116 | (blit_caps & HW_TEX_BLIT) != 0 ?"HW_TEX_BLIT ":"", |
||
117 | (blit_caps & HW_VID_BLIT) != 0 ?"HW_VID_BLIT ":""); |
||
118 | |||
119 | blit_caps&= caps; |
||
120 | return blit_caps; |
||
121 | |||
122 | fail: |
||
123 | service = 0; |
||
124 | return 0; |
||
125 | }; |
||
126 | |||
127 | |||
128 | int create_bitmap(bitmap_t *bitmap) |
||
129 | { |
||
130 | // __asm__ __volatile__("int3"); |
||
131 | |||
132 | if( blit_caps & HW_BIT_BLIT ) |
||
133 | { |
||
134 | struct __attribute__((packed)) /* SRV_CREATE_SURFACE */ |
||
135 | { |
||
136 | uint32_t handle; // ignored |
||
137 | void *data; // ignored |
||
138 | |||
139 | uint32_t width; |
||
140 | uint32_t height; |
||
141 | uint32_t pitch; // ignored |
||
142 | |||
143 | uint32_t max_width; |
||
144 | uint32_t max_height; |
||
145 | uint32_t format; // reserved mbz |
||
146 | }io_10; |
||
147 | |||
148 | ioctl_t io; |
||
149 | int err; |
||
150 | |||
151 | // printf("create bitmap %d x %d\n", |
||
152 | // bitmap->width, bitmap->height); |
||
153 | |||
154 | io_10.width = bitmap->width; |
||
155 | io_10.height = bitmap->height; |
||
156 | io_10.max_width = 0; |
||
157 | io_10.max_height = 0; |
||
158 | io_10.format = 0; |
||
159 | |||
160 | io.handle = service; |
||
161 | io.io_code = SRV_CREATE_SURFACE; |
||
162 | io.input = &io_10; |
||
163 | io.inp_size = BUFFER_SIZE(8); |
||
164 | io.output = NULL; |
||
165 | io.out_size = 0; |
||
166 | |||
167 | err = call_service(&io); |
||
168 | if(err==0) |
||
169 | { |
||
170 | bitmap->handle = io_10.handle; |
||
171 | bitmap->pitch = io_10.pitch; |
||
172 | bitmap->data = io_10.data; |
||
173 | // printf("Create hardware surface %x pitch %d, buffer %x\n", |
||
174 | // bitmap->handle, bitmap->pitch, bitmap->data); |
||
175 | return 0; |
||
176 | }; |
||
177 | return err; |
||
178 | }; |
||
179 | |||
180 | uint32_t size; |
||
181 | uint32_t pitch; |
||
182 | uint8_t *buffer; |
||
183 | |||
184 | pitch = ALIGN(bitmap->width*4, 16); |
||
185 | size = pitch * bitmap->height; |
||
186 | |||
187 | buffer = (uint8_t*)user_alloc(size); |
||
188 | if( buffer ) |
||
189 | { |
||
190 | bitmap->handle = 0; |
||
191 | bitmap->pitch = pitch; |
||
192 | bitmap->data = buffer; |
||
193 | return 0; |
||
194 | }; |
||
195 | |||
196 | printf("Cannot alloc frame buffer\n\r"); |
||
197 | |||
198 | return -1; |
||
199 | }; |
||
200 | |||
2415 | Serge | 201 | int lock_bitmap(bitmap_t *bitmap) |
202 | { |
||
203 | // __asm__ __volatile__("int3"); |
||
204 | |||
205 | if( blit_caps & HW_BIT_BLIT ) |
||
206 | { |
||
207 | struct __attribute__((packed)) /* SRV_CREATE_SURFACE */ |
||
208 | { |
||
209 | uint32_t handle; // ignored |
||
210 | void *data; // ignored |
||
211 | |||
212 | uint32_t width; |
||
213 | uint32_t height; |
||
214 | uint32_t pitch; // ignored |
||
215 | |||
216 | }io_12; |
||
217 | |||
218 | ioctl_t io; |
||
219 | int err; |
||
220 | |||
221 | io_12.handle = bitmap->handle; |
||
222 | io_12.pitch = 0; |
||
223 | io_12.data = 0; |
||
224 | |||
225 | io.handle = service; |
||
226 | io.io_code = SRV_LOCK_SURFACE; |
||
227 | io.input = &io_12; |
||
228 | io.inp_size = BUFFER_SIZE(5); |
||
229 | io.output = NULL; |
||
230 | io.out_size = 0; |
||
231 | |||
232 | err = call_service(&io); |
||
233 | if(err==0) |
||
234 | { |
||
235 | bitmap->pitch = io_12.pitch; |
||
236 | bitmap->data = io_12.data; |
||
237 | // printf("Lock hardware surface %x pitch %d, buffer %x\n", |
||
238 | // bitmap->handle, bitmap->pitch, bitmap->data); |
||
239 | return 0; |
||
240 | }; |
||
241 | return err; |
||
242 | }; |
||
243 | |||
244 | return 0; |
||
245 | }; |
||
246 | |||
2349 | Serge | 247 | struct blit_call |
248 | { |
||
249 | int dstx; |
||
250 | int dsty; |
||
251 | int w; |
||
252 | int h; |
||
253 | |||
254 | int srcx; |
||
255 | int srcy; |
||
256 | int srcw; |
||
257 | int srch; |
||
258 | |||
259 | unsigned char *bitmap; |
||
260 | int stride; |
||
261 | }; |
||
262 | |||
263 | int blit_bitmap(bitmap_t *bitmap, int dst_x, int dst_y, |
||
264 | int w, int h) |
||
265 | { |
||
266 | |||
267 | if( blit_caps & HW_BIT_BLIT ) |
||
268 | { |
||
269 | |||
270 | /* |
||
271 | * Now you will experience the full power of the dark side... |
||
272 | */ |
||
273 | |||
274 | struct __attribute__((packed)) |
||
275 | { |
||
276 | uint32_t handle; |
||
277 | int dst_x; |
||
278 | int dst_y; |
||
279 | int src_x; |
||
280 | int src_y; |
||
281 | uint32_t w; |
||
282 | uint32_t h; |
||
283 | }io_20; |
||
284 | |||
285 | ioctl_t io; |
||
286 | int err; |
||
287 | |||
288 | io_20.handle = bitmap->handle; |
||
289 | io_20.dst_x = dst_x; |
||
290 | io_20.dst_y = dst_y; |
||
291 | io_20.src_x = 0; |
||
292 | io_20.src_y = 0; |
||
293 | io_20.w = w; |
||
294 | io_20.h = h; |
||
295 | |||
296 | io.handle = service; |
||
297 | io.io_code = SRV_BLIT_VIDEO; |
||
298 | io.input = &io_20; |
||
299 | io.inp_size = BUFFER_SIZE(7); |
||
300 | io.output = NULL; |
||
301 | io.out_size = 0; |
||
302 | |||
303 | // printf("do blit %x pitch %d\n",bitmap->handle, |
||
304 | // bitmap->pitch); |
||
305 | err = call_service(&io); |
||
306 | if (call_service(&io)==0) |
||
307 | { |
||
308 | //bitmap->data = NULL; Not now, Serge |
||
309 | // printf("blit done\n"); |
||
2693 | Serge | 310 | // delay(1); |
2349 | Serge | 311 | return 0; |
312 | }; |
||
313 | return err; |
||
314 | }; |
||
315 | |||
316 | volatile struct blit_call bc; |
||
317 | |||
318 | bc.dstx = dst_x; |
||
319 | bc.dsty = dst_y; |
||
320 | bc.w = w; |
||
321 | bc.h = h; |
||
322 | bc.srcx = 0; |
||
323 | bc.srcy = 0; |
||
324 | bc.srcw = w; |
||
325 | bc.srch = h; |
||
326 | bc.stride = bitmap->pitch; |
||
327 | bc.bitmap = bitmap->data; |
||
328 | |||
329 | __asm__ __volatile__( |
||
330 | "int $0x40" |
||
2693 | Serge | 331 | ::"a"(73),"b"(0x00),"c"(&bc) |
332 | :"memory"); |
||
2415 | Serge | 333 | |
334 | return 0; |
||
2349 | Serge | 335 | }; |
336 | |||
337 | |||
338 | static inline void* user_realloc(void *mem, size_t size) |
||
339 | { |
||
340 | void *val; |
||
341 | __asm__ __volatile__( |
||
342 | "int $0x40" |
||
2427 | Serge | 343 | :"=a"(val) |
2693 | Serge | 344 | :"a"(68),"b"(20),"c"(size),"d"(mem) |
2349 | Serge | 345 | :"memory"); |
346 | |||
347 | return val; |
||
348 | } |
||
349 | |||
350 | int resize_bitmap(bitmap_t *bitmap) |
||
351 | { |
||
352 | // __asm__ __volatile__("int3"); |
||
353 | |||
354 | if( blit_caps & HW_BIT_BLIT ) |
||
355 | { |
||
356 | /* work in progress */ |
||
357 | }; |
||
358 | |||
359 | uint32_t size; |
||
360 | uint32_t pitch; |
||
361 | uint8_t *buffer; |
||
362 | |||
363 | pitch = ALIGN(bitmap->width*4, 16); |
||
364 | size = pitch * bitmap->height; |
||
365 | |||
366 | buffer = (uint8_t*)user_realloc(bitmap->data, size); |
||
367 | if( buffer ) |
||
368 | { |
||
369 | bitmap->handle = 0; |
||
370 | bitmap->pitch = pitch; |
||
371 | bitmap->data = buffer; |
||
372 | return 0; |
||
373 | }; |
||
374 | |||
375 | printf("Cannot realloc frame buffer\n\r"); |
||
376 | |||
377 | return -1; |
||
378 | };> |
||
379 |