Subversion Repositories Kolibri OS

Rev

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