Subversion Repositories Kolibri OS

Rev

Rev 9288 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9288 Rev 9768
Line 1... Line 1...
1
#include 
1
#include 
2
#include 
2
#include 
3
#include 
-
 
4
#include 
3
#include 
5
#include "SDL.h"
4
#include "SDL.h"
6
#include "SDL_error.h"
5
#include "SDL_error.h"
7
#include "SDL_video.h"
6
#include "SDL_video.h"
8
#include "SDL_mouse.h"
7
#include "SDL_mouse.h"
9
#include "SDL_sysvideo.h"
8
#include "SDL_sysvideo.h"
10
#include "SDL_pixels_c.h"
9
#include "SDL_pixels_c.h"
11
#include "SDL_events_c.h"
-
 
12
#include "SDL_menuetvideo.h"
10
#include "SDL_menuetvideo.h"
13
#include 
11
#include 
Line 14... Line 12...
14
 
12
 
15
static SDL_VideoDevice * vm_suf=NULL;
13
static SDL_VideoDevice * vm_suf=NULL;
Line 16... Line 14...
16
static int was_initialized=0;
14
static int was_initialized=0;
17
 
15
 
Line -... Line 16...
-
 
16
static int has_null_cursor=0;
18
static int has_null_cursor=0;
17
static void* null_cursor;
Line 19... Line 18...
19
static int null_cursor;
18
 
20
 
-
 
21
//#define KEEP_OBSOLETE_STYLE3
-
 
22
 
-
 
23
#ifdef KEEP_OBSOLETE_STYLE3
-
 
24
static int IsStyle4Available=0;
-
 
25
#endif
19
#define WINDOW_BORDER_H 4
26
 
20
#define WINDOW_BORDER_W 9
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
{
21
 
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
 
22
void kos_SDL_RepaintWnd(void)
37
void MenuetOS_SDL_RepaintWnd(void)
-
 
38
{
-
 
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,
-
 
41
#ifdef KEEP_OBSOLETE_STYLE3
-
 
42
 	IsStyle4Available?0x34000000:0x33000000
23
{
43
#else
-
 
44
	0x34000000
-
 
Line 45... Line 24...
45
#endif
24
    _ksys_start_draw();
46
 	,0,(int)vm_suf->hidden->__title);
25
    _ksys_create_window(1, 1, vm_suf->hidden->win_size_x+WINDOW_BORDER_W, 
47
 
26
                              vm_suf->hidden->win_size_y+_ksys_get_skin_height()+ WINDOW_BORDER_H,
-
 
27
                              vm_suf->hidden->__title, 0, 0x34);
48
 // __asm__ __volatile__("int3");
28
 
49
 
29
     if (vm_suf && vm_suf->hidden->__video_buffer) {
Line 50... Line 30...
50
 if(vm_suf && vm_suf->hidden->__video_buffer)
30
          _ksys_draw_bitmap(vm_suf->hidden->__video_buffer, 0, 0,
51
  draw_bitmap(vm_suf->hidden->__video_buffer, 0,0,
31
                             vm_suf->hidden->win_size_x, vm_suf->hidden->win_size_y);
52
   vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y);
32
    }
53
 end_draw();
33
    _ksys_end_draw();
Line 54... Line 34...
54
}
34
}
55
 
-
 
56
static int MenuetOS_AllocHWSurface(_THIS,SDL_Surface * surface)
-
 
Line 57... Line 35...
57
{
35
 
58
 return -1;
36
static int kos_AllocHWSurface(_THIS,SDL_Surface * surface)
59
}
37
{
60
 
38
    return -1;
Line 61... Line 39...
61
static void MenuetOS_FreeHWSurface(_THIS,SDL_Surface * surface)
39
}
62
{
-
 
63
}
-
 
Line 64... Line 40...
64
 
40
 
65
static int MenuetOS_LockHWSurface(_THIS,SDL_Surface * surface)
41
static void kos_FreeHWSurface(_THIS,SDL_Surface * surface) {/*STUB*/}
66
{
42
 
67
 return 0;
-
 
68
}
43
static int kos_LockHWSurface(_THIS,SDL_Surface * surface)
69
 
44
{
70
static void MenuetOS_UnlockHWSurface(_THIS,SDL_Surface * surface)
45
    return 0;
71
{
46
}
Line 72... Line 47...
72
}
47
 
73
 
48
static void kos_UnlockHWSurface(_THIS,SDL_Surface * surface) {/*STUB*/}
74
static void MenuetOS_DirectUpdate(_THIS,int numrects,SDL_Rect * rects)
49
 
75
{
50
static void kos_DirectUpdate(_THIS,int numrects,SDL_Rect * rects)
Line 76... Line 51...
76
 if(numrects)
51
{
77
 {
-
 
78
  draw_bitmap(this->hidden->__video_buffer, 0,0,
-
 
79
   vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y);
52
    if (numrects) {
-
 
53
          _ksys_draw_bitmap(this->hidden->__video_buffer, 0,0,
80
 }
54
                            vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y);
81
}
55
     }
82
 
56
}
83
int MenuetOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
57
 
Line 84... Line 58...
84
{
58
int kos_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
85
 return 0;
-
 
86
}
-
 
Line 87... Line 59...
87
 
59
{
88
void MenuetOS_VideoQuit(_THIS)
60
    return 0;
89
{
61
}
90
	if (has_null_cursor)
62
 
91
	{
63
void kos_VideoQuit(_THIS)
Line 92... Line 64...
92
		__asm__("int $0x40"::"a"(37),"b"(6),"c"(null_cursor));
64
{
93
		has_null_cursor = 0;
65
    if (has_null_cursor) {
94
	}
66
        _ksys_delete_cursor(null_cursor);
95
}
67
        has_null_cursor = 0;
96
 
68
    }
-
 
69
}
97
void MenuetOS_FinalQuit(void)
70
 
98
{
71
void kos_FinalQuit(void) {/*STUB*/}
99
}
72
 
100
 
73
void kos_SetCaption(_THIS,const char * title, const char * icon)
Line 101... Line 74...
101
void MenuetOS_SetCaption(_THIS,const char * title,const char * icon)
74
{
102
{
75
     this->hidden->__title=(char *)title;
-
 
76
     if (was_initialized) _ksys_set_window_title(title);
Line 103... Line -...
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);
-
 
116
 
-
 
117
 char info[100];
-
 
118
 sprintf(info, "width = %d, height = %d, pitch = %d, bpp = %d\n", current->w, current->h, current->pitch, bpp);
-
 
119
 
77
}
120
 
-
 
121
 void debug_board_write_byte(const char ch){
78
 
122
   __asm__ __volatile__(
-
 
Line 123... Line 79...
123
			"int $0x40"
79
SDL_Surface *kos_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
124
			:
80
{
Line 125... Line 81...
125
			:"a"(63), "b"(1), "c"(ch));
81
    int ly;
126
 }
82
     unsigned char* lx;
127
 
83
     if (bpp!=24) return NULL;
128
 void debug_board_write_str(const char* str){
84
 
Line 129... Line -...
129
   while(*str)
-
 
130
     debug_board_write_byte(*str++);
85
     current->flags=flags;
131
 }
-
 
132
 
86
     current->w=width;
133
 debug_board_write_str(info);
87
     current->h=height;
134
 // __asm__ __volatile__("int3");
-
 
135
 
88
     current->pitch=width*(bpp>>3);
136
 current->pixels=this->hidden->__video_buffer=realloc(this->hidden->__video_buffer,
-
 
137
	current->pitch*current->h);
89
 
138
 this->hidden->__lines=(unsigned char **)realloc(this->hidden->__lines,
-
 
139
		    sizeof(unsigned char *)*current->h);
-
 
140
 
90
     char info[100];
141
 for(ly=0,lx=current->pixels;lyh;ly++,lx+=current->pitch)
91
     sprintf(info, "width = %d, height = %d, pitch = %d, bpp = %d\n", current->w, current->h, current->pitch, bpp);
142
   this->hidden->__lines[ly]=lx;
92
    _ksys_debug_puts(info);
143
 
93
 
144
 this->UpdateRects=MenuetOS_DirectUpdate;
94
    current->pixels=this->hidden->__video_buffer=realloc(this->hidden->__video_buffer, current->pitch*current->h);
145
 this->hidden->win_size_x=width;
95
     this->hidden->__lines=(unsigned char **)realloc(this->hidden->__lines, sizeof(unsigned char *)*current->h);
Line 146... Line 96...
146
 this->hidden->win_size_y=height;
96
 
147
 vm_suf=this;
97
     for (ly=0, lx=current->pixels; lyh; ly++, lx+=current->pitch)
Line 148... Line 98...
148
 
98
           this->hidden->__lines[ly]=lx;
149
 
99
 
150
 if (was_initialized)
100
     this->UpdateRects=kos_DirectUpdate;
151
 {
101
     this->hidden->win_size_x=width;
152
  unsigned newheight = height+get_skin_height+4;
102
     this->hidden->win_size_y=height;
153
  unsigned newwidth  = width+9;
103
     vm_suf=this;
154
 
104
 
155
  sys_change_window(-1, -1, newwidth, newheight);
105
     if (was_initialized) {
Line 156... Line 106...
156
 }
106
          unsigned newheight = height+_ksys_get_skin_height()+WINDOW_BORDER_H;
157
 else
107
          unsigned newwidth  = width+WINDOW_BORDER_W;
158
 {
108
          _ksys_change_window(-1, -1, newwidth, newheight);
159
 
109
     } else {
Line 160... Line 110...
160
  set_wanted_events_mask(0x27);
110
        _ksys_set_event_mask(0x27);
161
  was_initialized=1;
111
          was_initialized=1;
162
  MenuetOS_SDL_RepaintWnd();
112
          kos_SDL_RepaintWnd();
163
 }
113
     }
164
 return current;
114
     return current;
Line 165... Line 115...
165
}
115
}
166
 
116
 
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;
117
/*static SDL_Rect video_mode[4];
177
}
118
static SDL_Rect * SDL_modelist[4]={NULL,NULL,NULL,NULL};*/
178
 
119
 
179
static int MenuetOS_Available(void)
120
static SDL_Rect** kos_ListModes(_THIS,SDL_PixelFormat * fmt,Uint32 flags)
180
{
121
{
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 */
122
// return (&SDL_modelist[((fmt->BitsPerPixel+7)/8)-1]);
199
		IsStyle4Available = 1;
123
    if (fmt->BitsPerPixel==24)
Line 200... Line 124...
200
#endif
124
        return (SDL_Rect**)-1;
201
 vformat->BitsPerPixel=24;
125
    else
202
 vformat->BytesPerPixel=3;
126
        return NULL;
203
 this->info.wm_available=1;
127
}
204
 this->info.hw_available=0;
128
 
Line 205... Line -...
205
 this->info.video_mem=0x200000;
-
 
206
/* video_mode[3].x=0;
129
static int kos_Available(void)
207
 video_mode[3].y=0;
130
{
208
 video_mode[3].w=320;
131
     return 1;
209
 video_mode[3].h=200;
132
}
210
 video_mode[2].x=0;
133
 
Line 211... Line 134...
211
 video_mode[2].y=0;
134
static void kos_DeleteDevice(_THIS)
212
 video_mode[2].w=640;
135
{
213
 video_mode[2].h=400;
136
//  free(this->hidden->__video_buffer);	// it will be freed as current->pixels
214
 video_mode[1].x=0;
137
     free(this->hidden->__lines);
215
 video_mode[1].y=0;
138
}
216
 video_mode[1].w=320;
139
 
217
 video_mode[1].h=240;
-
 
218
 video_mode[0].x=0;
140
static int kos_VideoInit(_THIS,SDL_PixelFormat * vformat)
219
 video_mode[0].y=0;
-
 
220
 video_mode[0].w=640;
141
{
221
 video_mode[0].h=480;
142
    vformat->BitsPerPixel = 24;
222
 SDL_modelist[2]=video_mode+0;*/
143
     vformat->BytesPerPixel = 3;
223
 return 0;
144
     this->info.wm_available = 1;
224
}
145
     this->info.hw_available = 0;
225
 
146
     this->info.video_mem = 0x200000;
226
static int MenuetOS_FlipHWSurface(_THIS,SDL_Surface * surface)
147
     return 0;
227
{
148
}
228
 draw_bitmap(surface->pixels, 0,0,surface->w,surface->h);
149
 
229
 return 0;
150
static int kos_FlipHWSurface(_THIS,SDL_Surface * surface)
230
}
151
{
231
 
152
    _ksys_draw_bitmap(surface->pixels, 0, 0, surface->w,surface->h);
232
WMcursor* KolibriOS_CreateWMCursor(_THIS,
153
     return 0;
233
	Uint8* data, Uint8* mask, int w, int h, int hot_x, int hot_y)
-
 
234
{
154
}
235
	int i,j;
-
 
236
	Uint32* cursor;
-
 
237
	WMcursor* res;
155
 
238
 
156
WMcursor* kos_CreateWMCursor(_THIS, Uint8* data, Uint8* mask, int w, int h, int hot_x, int hot_y)
-
 
157
{
-
 
158
    int i,j;
239
	if (w>32 || h>32) return NULL;
159
    Uint32* cursor;
240
	if (w%8 || h%8) return NULL;
160
    WMcursor* res;
241
	cursor = (Uint32*)malloc(32*32*4);
161
 
242
	if (!cursor) return NULL;
162
    if (w>32 || h>32) return NULL;
243
	for (i=0;i<32;i++)
-
 
244
		for (j=0;j<32;j++)
163
    if (w%8 || h%8) return NULL;
245
		{
164
    cursor = (Uint32*)malloc(32*32*4);
246
			if (i>=h || j>=w)
165
    if (!cursor) return NULL;
247
			{
166
    for (i=0;i<32;i++) {
248
				cursor[i*32+j] = 0x00000000;
167
        for (j=0;j<32;j++) {
249
				continue;
168
            if (i>=h || j>=w) {
250
			}
169
                cursor[i*32+j] = 0x00000000;
251
			if (mask[i*w/8+j/8] & (0x80>>(j&7)))
170
                continue;
252
				cursor[i*32+j] = (data[i*w/8+j/8] & (0x80>>(j&7)))?0xFF000000:0xFFFFFFFF;
171
            }
253
			else
172
            if (mask[i*w/8+j/8] & (0x80>>(j&7)))
254
				cursor[i*32+j] = 0x00000000;
173
                cursor[i*32+j] = (data[i*w/8+j/8] & (0x80>>(j&7)))?0xFF000000:0xFFFFFFFF;
255
		}
174
            else
256
	__asm__ ("int $0x40" : "=a"(res) : "a"(37),"b"(4),
175
                cursor[i*32+j] = 0x00000000;
257
		"c"(cursor),"d"((hot_x<<24)+(hot_y<<16)+2));
176
        }
258
	free(cursor);
177
    }
259
	return res;
178
    res = _ksys_load_cursor(cursor, (hot_x<<24)+(hot_y<<16)+KSYS_CURSOR_INDIRECT);
260
}
179
    free(cursor);
261
int KolibriOS_ShowWMCursor(_THIS,WMcursor*cursor)
-
 
262
{
180
    return res;
263
	if (!cursor)
181
}
264
	{
-
 
265
		if (!has_null_cursor)
182
 
266
		{
183
int kos_ShowWMCursor(_THIS, WMcursor* cursor)
267
			unsigned* u = malloc(32*32*4);
184
{
268
			if (!u) return 1;
-
 
269
			memset(u,0,32*32*4);
185
    if (!cursor) {
270
			__asm__("int $0x40":"=a"(null_cursor):
186
        if (!has_null_cursor) {
Line 271... Line 187...
271
				"a"(37),"b"(4),"c"(u),"d"(2));
187
            unsigned* u = malloc(32*32*4);
-
 
188
            if (!u) return 1;
272
			free(u);
189
            memset(u,0,32*32*4);
273
			has_null_cursor = 1;
190
            null_cursor = _ksys_load_cursor(u, KSYS_CURSOR_INDIRECT);
274
		}
191
            free(u);
275
		cursor = (WMcursor*)null_cursor;
192
            has_null_cursor = 1;
276
	}
193
        }
277
	__asm__("int $0x40" : : "a"(37),"b"(5),"c"(cursor));
-
 
278
	return 1;
194
        cursor = (WMcursor*)null_cursor;
279
}
195
    }
280
void KolibriOS_FreeWMCursor(_THIS,WMcursor*cursor)
196
    _ksys_set_cursor(cursor);
281
{
197
    return 1;
282
	__asm__("int $0x40" : : "a"(37),"b"(6),"c"(cursor));
-
 
283
}
198
}
284
void KolibriOS_CheckMouseMode(_THIS)
199
void kos_FreeWMCursor(_THIS, WMcursor* cursor)
285
{
-
 
286
	if (this->input_grab == SDL_GRAB_OFF)
200
{
287
		return;
201
    _ksys_delete_cursor(cursor);
288
	struct process_table_entry buf;
202
}
289
	int res;
203
void kos_CheckMouseMode(_THIS)
-
 
204
{
290
	__asm__ volatile("int $0x40" : "=a"(res): "a"(9), "b"(&buf), "c"(-1));
205
    if (this->input_grab == SDL_GRAB_OFF)
291
	if (res == buf.pos_in_windowing_stack)
206
        return;
292
	{
207
    ksys_thread_t thread_info;
293
		int x = buf.winx_start + buf.client_left + this->hidden->win_size_x/2;
208
    int res = _ksys_thread_info(&thread_info, -1);
294
		int y = buf.winy_start + buf.client_top + this->hidden->win_size_y/2;
209
    if (res == thread_info.window_pos_info) {
295
		__asm__("int $0x40" : : "a"(18),"b"(19),"c"(4),
210
        int x = thread_info.winx_start + thread_info.clientx + this->hidden->win_size_x/2;
296
			"d"(x*65536+y));
211
        int y = thread_info.winy_start + thread_info.clienty + this->hidden->win_size_y/2;
297
	}
212
        _ksys_set_mouse_pos(x, y);
298
}
213
    }
299
 
214
}
300
char def_title[] = "KolibriOS SDL App";
215
 
301
static SDL_VideoDevice * MenuetOS_CreateDevice(int indx)
216
char def_title[] = "KolibriOS SDL App";
302
{
217
 
303
 SDL_VideoDevice * dev;
218
static SDL_VideoDevice *kos_CreateDevice(int indx)
304
 dev=(SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
219
{
305
 if(dev) 
220
    SDL_VideoDevice * dev;
306
 {
221
     dev = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
307
  memset(dev,0,(sizeof *dev));
222
     if (dev) {
308
  dev->hidden = (struct SDL_PrivateVideoData *)malloc((sizeof *dev->hidden));
223
          memset(dev,0,(sizeof *dev));
309
 }
224
          dev->hidden = (struct SDL_PrivateVideoData*)malloc((sizeof *dev->hidden));
310
 if((dev==NULL) || (dev->hidden==NULL)) 
225
     }
311
 {
226
     if ((dev==NULL) || (dev->hidden==NULL)) {
312
  SDL_OutOfMemory();
227
          SDL_OutOfMemory();
313
  if(dev) 
228
          if(dev) {
314
  {
229
               free(dev);
315
   free(dev);
230
          }
316
  }
231
          return(0);
317
  return(0);
232
     }
318
 }
233
 
319
 memset(dev->hidden,0,(sizeof *dev->hidden));
234
    memset(dev->hidden, 0, (sizeof *dev->hidden));
320
 dev->hidden->__title = def_title;
235
    dev->hidden->__title = def_title;
Line 321... Line 236...
321
 dev->VideoInit=MenuetOS_VideoInit;
236
    dev->VideoInit = kos_VideoInit;
322
 dev->ListModes=MenuetOS_ListModes;
237
     dev->ListModes = kos_ListModes;
323
 dev->SetVideoMode=MenuetOS_SetVideoMode;
238
    dev->SetVideoMode = kos_SetVideoMode;
324
 dev->SetColors=MenuetOS_SetColors;
239
    dev->SetColors = kos_SetColors;