Subversion Repositories Kolibri OS

Rev

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