Subversion Repositories Kolibri OS

Rev

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