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