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