Subversion Repositories Kolibri OS

Rev

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