Rev 8494 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8211 | maxcodehac | 1 | #include |
2 | #include |
||
3 | #include |
||
8494 | maxcodehac | 4 | #include |
8211 | maxcodehac | 5 | #include "SDL.h" |
6 | #include "SDL_error.h" |
||
7 | #include "SDL_video.h" |
||
8 | #include "SDL_mouse.h" |
||
9 | #include "SDL_sysvideo.h" |
||
10 | #include "SDL_pixels_c.h" |
||
11 | #include "SDL_events_c.h" |
||
12 | #include "SDL_menuetvideo.h" |
||
13 | #include |
||
14 | |||
15 | static SDL_VideoDevice * vm_suf=NULL; |
||
16 | static int was_initialized=0; |
||
17 | |||
18 | static int has_null_cursor=0; |
||
19 | static int null_cursor; |
||
20 | |||
21 | inline int get_skinh(void) |
||
22 | { |
||
23 | int res; |
||
24 | __asm__ ("int $0x40" : "=a"(res) : "a"(48),"b"(4)); |
||
25 | return res; |
||
26 | } |
||
27 | |||
28 | //#define KEEP_OBSOLETE_STYLE3 |
||
29 | |||
30 | #ifdef KEEP_OBSOLETE_STYLE3 |
||
31 | static int IsStyle4Available=0; |
||
32 | #endif |
||
33 | |||
8495 | maxcodehac | 34 | void kol_define_window(unsigned short x1,unsigned short y1,unsigned short xsize,unsigned short ysize, |
35 | unsigned long body_color,unsigned long grab_color,unsigned long frame_color) |
||
36 | { |
||
37 | unsigned long a,b; |
||
38 | a=(x1<<16)|xsize; |
||
39 | b=(y1<<16)|ysize; |
||
40 | __asm__ __volatile__("int $0x40"::"a"(0),"b"(a),"c"(b),"d"(body_color),"S"(grab_color), |
||
41 | "D"(frame_color)); |
||
42 | } |
||
43 | |||
8211 | maxcodehac | 44 | void MenuetOS_SDL_RepaintWnd(void) |
45 | { |
||
8495 | maxcodehac | 46 | begin_draw(); |
47 | kol_define_window(1,1,vm_suf->hidden->win_size_x+9,vm_suf->hidden->win_size_y+get_skinh()+4, |
||
8211 | maxcodehac | 48 | #ifdef KEEP_OBSOLETE_STYLE3 |
49 | IsStyle4Available?0x34000000:0x33000000 |
||
50 | #else |
||
51 | 0x34000000 |
||
52 | #endif |
||
53 | ,0,(int)vm_suf->hidden->__title); |
||
54 | |||
55 | // __asm__ __volatile__("int3"); |
||
56 | |||
57 | if(vm_suf && vm_suf->hidden->__video_buffer) |
||
8495 | maxcodehac | 58 | draw_bitmap(vm_suf->hidden->__video_buffer, 0,0, |
59 | vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y); |
||
60 | end_draw(); |
||
8211 | maxcodehac | 61 | } |
62 | |||
63 | static int MenuetOS_AllocHWSurface(_THIS,SDL_Surface * surface) |
||
64 | { |
||
65 | return -1; |
||
66 | } |
||
67 | |||
68 | static void MenuetOS_FreeHWSurface(_THIS,SDL_Surface * surface) |
||
69 | { |
||
70 | } |
||
71 | |||
72 | static int MenuetOS_LockHWSurface(_THIS,SDL_Surface * surface) |
||
73 | { |
||
74 | return 0; |
||
75 | } |
||
76 | |||
77 | static void MenuetOS_UnlockHWSurface(_THIS,SDL_Surface * surface) |
||
78 | { |
||
79 | } |
||
80 | |||
81 | static void MenuetOS_DirectUpdate(_THIS,int numrects,SDL_Rect * rects) |
||
82 | { |
||
83 | if(numrects) |
||
84 | { |
||
8495 | maxcodehac | 85 | draw_bitmap(this->hidden->__video_buffer, 0,0, |
86 | vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y); |
||
8211 | maxcodehac | 87 | } |
88 | } |
||
89 | |||
90 | int MenuetOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) |
||
91 | { |
||
92 | return 0; |
||
93 | } |
||
94 | |||
95 | void MenuetOS_VideoQuit(_THIS) |
||
96 | { |
||
97 | if (has_null_cursor) |
||
98 | { |
||
99 | __asm__("int $0x40"::"a"(37),"b"(6),"c"(null_cursor)); |
||
100 | has_null_cursor = 0; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | void MenuetOS_FinalQuit(void) |
||
105 | { |
||
106 | } |
||
107 | |||
108 | void MenuetOS_SetCaption(_THIS,const char * title,const char * icon) |
||
109 | { |
||
110 | this->hidden->__title=(char *)title; |
||
111 | if(was_initialized) __asm__("int $0x40"::"a"(71),"b"(1),"c"(title)); |
||
112 | } |
||
113 | |||
114 | SDL_Surface * MenuetOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) |
||
115 | { |
||
116 | int ly; |
||
117 | char * lx; |
||
118 | if(bpp!=24) return NULL; |
||
119 | current->flags=flags; |
||
120 | current->w=width; |
||
121 | current->h=height; |
||
122 | current->pitch=width*(bpp>>3); |
||
123 | |||
124 | char info[100]; |
||
125 | sprintf(info, "width = %d, height = %d, pitch = %d, bpp = %d\n", current->w, current->h, current->pitch, bpp); |
||
126 | |||
127 | void debug_board_write_byte(const char ch){ |
||
128 | __asm__ __volatile__( |
||
129 | "int $0x40" |
||
130 | : |
||
131 | :"a"(63), "b"(1), "c"(ch)); |
||
132 | } |
||
133 | |||
134 | void debug_board_write_str(const char* str){ |
||
135 | while(*str) |
||
136 | debug_board_write_byte(*str++); |
||
137 | } |
||
138 | |||
139 | debug_board_write_str(info); |
||
140 | // __asm__ __volatile__("int3"); |
||
141 | |||
142 | current->pixels=this->hidden->__video_buffer=realloc(this->hidden->__video_buffer, |
||
143 | current->pitch*current->h); |
||
144 | this->hidden->__lines=(unsigned char **)realloc(this->hidden->__lines, |
||
145 | sizeof(unsigned char *)*current->h); |
||
146 | |||
147 | for(ly=0,lx=current->pixels;ly |
||
148 | this->hidden->__lines[ly]=lx; |
||
149 | |||
150 | this->UpdateRects=MenuetOS_DirectUpdate; |
||
151 | this->hidden->win_size_x=width; |
||
152 | this->hidden->win_size_y=height; |
||
153 | vm_suf=this; |
||
154 | if (was_initialized) |
||
155 | { |
||
156 | unsigned newheight = height+get_skinh()+4; |
||
157 | unsigned newwidth = width+9; |
||
158 | __asm__("int $0x40"::"a"(67),"b"(-1),"c"(-1),"d"(newwidth),"S"(newheight)); |
||
159 | } |
||
160 | else |
||
161 | { |
||
8494 | maxcodehac | 162 | set_wanted_events_mask(0x27); |
8211 | maxcodehac | 163 | was_initialized=1; |
164 | MenuetOS_SDL_RepaintWnd(); |
||
165 | } |
||
166 | return current; |
||
167 | } |
||
168 | |||
169 | /*static SDL_Rect video_mode[4]; |
||
170 | static SDL_Rect * SDL_modelist[4]={NULL,NULL,NULL,NULL};*/ |
||
171 | |||
172 | static SDL_Rect ** MenuetOS_ListModes(_THIS,SDL_PixelFormat * fmt,Uint32 flags) |
||
173 | { |
||
174 | // return (&SDL_modelist[((fmt->BitsPerPixel+7)/8)-1]); |
||
175 | if (fmt->BitsPerPixel==24) |
||
176 | return (SDL_Rect**)-1; |
||
177 | else |
||
178 | return NULL; |
||
179 | } |
||
180 | |||
181 | static int MenuetOS_Available(void) |
||
182 | { |
||
183 | return 1; |
||
184 | } |
||
185 | |||
186 | static void MenuetOS_DeleteDevice(_THIS) |
||
187 | { |
||
188 | // free(this->hidden->__video_buffer); // it will be freed as current->pixels |
||
189 | free(this->hidden->__lines); |
||
190 | } |
||
191 | |||
192 | static int MenuetOS_VideoInit(_THIS,SDL_PixelFormat * vformat) |
||
193 | { |
||
194 | #ifdef KEEP_OBSOLETE_STYLE3 |
||
195 | char buf[16]; |
||
196 | __asm__("int $0x40"::"a"(18),"b"(13),"c"(buf)); |
||
197 | if (buf[5]=='K' && buf[6]=='o' && buf[7]=='l' && buf[8]=='i') |
||
198 | /* kernels up to 0.7.0.0 do not support style 4 */; |
||
199 | else if (*(unsigned*)(buf+5) >= 549) |
||
200 | /* window style 4 was introduced in revision 549 */ |
||
201 | IsStyle4Available = 1; |
||
202 | #endif |
||
203 | vformat->BitsPerPixel=24; |
||
204 | vformat->BytesPerPixel=3; |
||
205 | this->info.wm_available=1; |
||
206 | this->info.hw_available=0; |
||
207 | this->info.video_mem=0x200000; |
||
208 | /* video_mode[3].x=0; |
||
209 | video_mode[3].y=0; |
||
210 | video_mode[3].w=320; |
||
211 | video_mode[3].h=200; |
||
212 | video_mode[2].x=0; |
||
213 | video_mode[2].y=0; |
||
214 | video_mode[2].w=640; |
||
215 | video_mode[2].h=400; |
||
216 | video_mode[1].x=0; |
||
217 | video_mode[1].y=0; |
||
218 | video_mode[1].w=320; |
||
219 | video_mode[1].h=240; |
||
220 | video_mode[0].x=0; |
||
221 | video_mode[0].y=0; |
||
222 | video_mode[0].w=640; |
||
223 | video_mode[0].h=480; |
||
224 | SDL_modelist[2]=video_mode+0;*/ |
||
225 | return 0; |
||
226 | } |
||
227 | |||
228 | static int MenuetOS_FlipHWSurface(_THIS,SDL_Surface * surface) |
||
229 | { |
||
8495 | maxcodehac | 230 | draw_bitmap(surface->pixels, 0,0,surface->w,surface->h); |
8211 | maxcodehac | 231 | return 0; |
232 | } |
||
233 | |||
234 | WMcursor* KolibriOS_CreateWMCursor(_THIS, |
||
235 | Uint8* data, Uint8* mask, int w, int h, int hot_x, int hot_y) |
||
236 | { |
||
237 | int i,j; |
||
238 | Uint32* cursor; |
||
239 | WMcursor* res; |
||
240 | |||
241 | if (w>32 || h>32) return NULL; |
||
242 | if (w%8 || h%8) return NULL; |
||
243 | cursor = (Uint32*)malloc(32*32*4); |
||
244 | if (!cursor) return NULL; |
||
245 | for (i=0;i<32;i++) |
||
246 | for (j=0;j<32;j++) |
||
247 | { |
||
248 | if (i>=h || j>=w) |
||
249 | { |
||
250 | cursor[i*32+j] = 0x00000000; |
||
251 | continue; |
||
252 | } |
||
253 | if (mask[i*w/8+j/8] & (0x80>>(j&7))) |
||
254 | cursor[i*32+j] = (data[i*w/8+j/8] & (0x80>>(j&7)))?0xFF000000:0xFFFFFFFF; |
||
255 | else |
||
256 | cursor[i*32+j] = 0x00000000; |
||
257 | } |
||
258 | __asm__ ("int $0x40" : "=a"(res) : "a"(37),"b"(4), |
||
259 | "c"(cursor),"d"((hot_x<<24)+(hot_y<<16)+2)); |
||
260 | free(cursor); |
||
261 | return res; |
||
262 | } |
||
263 | int KolibriOS_ShowWMCursor(_THIS,WMcursor*cursor) |
||
264 | { |
||
265 | if (!cursor) |
||
266 | { |
||
267 | if (!has_null_cursor) |
||
268 | { |
||
269 | unsigned* u = malloc(32*32*4); |
||
270 | if (!u) return 1; |
||
271 | memset(u,0,32*32*4); |
||
272 | __asm__("int $0x40":"=a"(null_cursor): |
||
273 | "a"(37),"b"(4),"c"(u),"d"(2)); |
||
274 | free(u); |
||
275 | has_null_cursor = 1; |
||
276 | } |
||
277 | cursor = (WMcursor*)null_cursor; |
||
278 | } |
||
279 | __asm__("int $0x40" : : "a"(37),"b"(5),"c"(cursor)); |
||
280 | return 1; |
||
281 | } |
||
282 | void KolibriOS_FreeWMCursor(_THIS,WMcursor*cursor) |
||
283 | { |
||
284 | __asm__("int $0x40" : : "a"(37),"b"(6),"c"(cursor)); |
||
285 | } |
||
286 | void KolibriOS_CheckMouseMode(_THIS) |
||
287 | { |
||
288 | if (this->input_grab == SDL_GRAB_OFF) |
||
289 | return; |
||
290 | struct process_table_entry buf; |
||
291 | int res; |
||
292 | __asm__ volatile("int $0x40" : "=a"(res): "a"(9), "b"(&buf), "c"(-1)); |
||
293 | if (res == buf.pos_in_windowing_stack) |
||
294 | { |
||
295 | int x = buf.winx_start + buf.client_left + this->hidden->win_size_x/2; |
||
296 | int y = buf.winy_start + buf.client_top + this->hidden->win_size_y/2; |
||
297 | __asm__("int $0x40" : : "a"(18),"b"(19),"c"(4), |
||
298 | "d"(x*65536+y)); |
||
299 | } |
||
300 | } |
||
301 | |||
302 | char def_title[] = "KolibriOS SDL App"; |
||
303 | static SDL_VideoDevice * MenuetOS_CreateDevice(int indx) |
||
304 | { |
||
305 | SDL_VideoDevice * dev; |
||
306 | dev=(SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); |
||
307 | if(dev) |
||
308 | { |
||
309 | memset(dev,0,(sizeof *dev)); |
||
310 | dev->hidden = (struct SDL_PrivateVideoData *)malloc((sizeof *dev->hidden)); |
||
311 | } |
||
312 | if((dev==NULL) || (dev->hidden==NULL)) |
||
313 | { |
||
314 | SDL_OutOfMemory(); |
||
315 | if(dev) |
||
316 | { |
||
317 | free(dev); |
||
318 | } |
||
319 | return(0); |
||
320 | } |
||
321 | memset(dev->hidden,0,(sizeof *dev->hidden)); |
||
322 | dev->hidden->__title = def_title; |
||
323 | dev->VideoInit=MenuetOS_VideoInit; |
||
324 | dev->ListModes=MenuetOS_ListModes; |
||
325 | dev->SetVideoMode=MenuetOS_SetVideoMode; |
||
326 | dev->SetColors=MenuetOS_SetColors; |
||
327 | dev->UpdateRects=NULL; |
||
328 | dev->VideoQuit=MenuetOS_VideoQuit; |
||
329 | dev->AllocHWSurface=MenuetOS_AllocHWSurface; |
||
330 | dev->CheckHWBlit=NULL; |
||
331 | dev->FillHWRect=NULL; |
||
332 | dev->SetHWColorKey=NULL; |
||
333 | dev->SetHWAlpha=NULL; |
||
334 | dev->LockHWSurface=MenuetOS_LockHWSurface; |
||
335 | dev->UnlockHWSurface=MenuetOS_UnlockHWSurface; |
||
336 | dev->FlipHWSurface=MenuetOS_FlipHWSurface; |
||
337 | dev->FreeHWSurface=MenuetOS_FreeHWSurface; |
||
338 | dev->SetCaption=MenuetOS_SetCaption; |
||
339 | dev->SetIcon=NULL; |
||
340 | dev->IconifyWindow=NULL; |
||
341 | dev->GrabInput=NULL; |
||
342 | dev->GetWMInfo=NULL; |
||
343 | dev->InitOSKeymap=MenuetOS_InitOSKeymap; |
||
344 | dev->PumpEvents=MenuetOS_PumpEvents; |
||
345 | dev->free=MenuetOS_DeleteDevice; |
||
346 | dev->CreateWMCursor = KolibriOS_CreateWMCursor; |
||
347 | dev->FreeWMCursor = KolibriOS_FreeWMCursor; |
||
348 | dev->ShowWMCursor = KolibriOS_ShowWMCursor; |
||
349 | dev->CheckMouseMode = KolibriOS_CheckMouseMode; |
||
350 | return dev; |
||
351 | } |
||
352 | |||
353 | VideoBootStrap mosvideo_bootstrab={ |
||
354 | "menuetos","MenuetOS Device Driver", |
||
355 | MenuetOS_Available,MenuetOS_CreateDevice, |
||
356 | };16)+2)); |