SDL: Refactoring part1

git-svn-id: svn://kolibrios.org@9768 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2022-04-15 14:05:41 +00:00
parent 56ff702799
commit 635fbac815
3 changed files with 224 additions and 275 deletions

View File

@ -0,0 +1,34 @@
-D_REENTRANT
-I../include
-I SYSCALL/include
-I.
-DENABLE_AUDIO
-UDISABLE_AUDIO
-DDISABLE_JOYSTICK
-DDISABLE_CDROM
-DDISABLE_THREADS
-DENABLE_TIMERS
-DUSE_ASMBLIT
-Ihermes
-Iaudio
-Ivideo
-Ievent
-Ijoystick
-Icdrom
-Ithread
-Itimer
-Iendian
-Ifile
-DENABLE_KOLIBRIOS
-DNO_SIGNAL_H
-DDISABLE_STDIO
-DNEED_SDL_GETENV
-DENABLE_FILE
-UDISABLE_FILE
-D__KOLIBRIOS__
-DDEBUG_VIDEO
-UWIN32
-U_Win32
-U_WIN32
-U__MINGW32__
-I../../newlib/libc/include/

View File

@ -8,7 +8,7 @@
#include "SDL_events_c.h" #include "SDL_events_c.h"
#include "SDL_menuetvideo.h" #include "SDL_menuetvideo.h"
extern void MenuetOS_SDL_RepaintWnd(void); extern void kos_SDL_RepaintWnd(void);
void MenuetOS_InitOSKeymap(_THIS) void MenuetOS_InitOSKeymap(_THIS)
{ {
@ -170,7 +170,7 @@ void MenuetOS_PumpEvents(_THIS)
case 0: case 0:
return; return;
case 1: case 1:
MenuetOS_SDL_RepaintWnd(); kos_SDL_RepaintWnd();
break; break;
case 2: case 2:
key.scancode = __menuet__getkey(); key.scancode = __menuet__getkey();
@ -218,7 +218,7 @@ void MenuetOS_PumpEvents(_THIS)
if (dx||dy) if (dx||dy)
{ {
SDL_PrivateMouseMotion(0,1,dx,dy); SDL_PrivateMouseMotion(0,1,dx,dy);
KolibriOS_CheckMouseMode(this); kos_CheckMouseMode(this);
} }
} }
else else

View File

@ -1,14 +1,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <menuet/os.h> #include <sys/ksys.h>
#include <kos32sys.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_error.h" #include "SDL_error.h"
#include "SDL_video.h" #include "SDL_video.h"
#include "SDL_mouse.h" #include "SDL_mouse.h"
#include "SDL_sysvideo.h" #include "SDL_sysvideo.h"
#include "SDL_pixels_c.h" #include "SDL_pixels_c.h"
#include "SDL_events_c.h"
#include "SDL_menuetvideo.h" #include "SDL_menuetvideo.h"
#include <string.h> #include <string.h>
@ -16,99 +14,74 @@ static SDL_VideoDevice * vm_suf=NULL;
static int was_initialized=0; static int was_initialized=0;
static int has_null_cursor=0; static int has_null_cursor=0;
static int null_cursor; static void* null_cursor;
//#define KEEP_OBSOLETE_STYLE3 #define WINDOW_BORDER_H 4
#define WINDOW_BORDER_W 9
#ifdef KEEP_OBSOLETE_STYLE3 void kos_SDL_RepaintWnd(void)
static int IsStyle4Available=0;
#endif
void kol_define_window(unsigned short x1,unsigned short y1,unsigned short xsize,unsigned short ysize,
unsigned long body_color,unsigned long grab_color,unsigned long frame_color)
{ {
unsigned long a,b; _ksys_start_draw();
a=(x1<<16)|xsize; _ksys_create_window(1, 1, vm_suf->hidden->win_size_x+WINDOW_BORDER_W,
b=(y1<<16)|ysize; vm_suf->hidden->win_size_y+_ksys_get_skin_height()+ WINDOW_BORDER_H,
__asm__ __volatile__("int $0x40"::"a"(0),"b"(a),"c"(b),"d"(body_color),"S"(grab_color), vm_suf->hidden->__title, 0, 0x34);
"D"(frame_color));
if (vm_suf && vm_suf->hidden->__video_buffer) {
_ksys_draw_bitmap(vm_suf->hidden->__video_buffer, 0, 0,
vm_suf->hidden->win_size_x, vm_suf->hidden->win_size_y);
}
_ksys_end_draw();
} }
void MenuetOS_SDL_RepaintWnd(void) static int kos_AllocHWSurface(_THIS,SDL_Surface * surface)
{
begin_draw();
kol_define_window(1,1,vm_suf->hidden->win_size_x+9,vm_suf->hidden->win_size_y+get_skin_height()+4,
#ifdef KEEP_OBSOLETE_STYLE3
IsStyle4Available?0x34000000:0x33000000
#else
0x34000000
#endif
,0,(int)vm_suf->hidden->__title);
// __asm__ __volatile__("int3");
if(vm_suf && vm_suf->hidden->__video_buffer)
draw_bitmap(vm_suf->hidden->__video_buffer, 0,0,
vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y);
end_draw();
}
static int MenuetOS_AllocHWSurface(_THIS,SDL_Surface * surface)
{ {
return -1; return -1;
} }
static void MenuetOS_FreeHWSurface(_THIS,SDL_Surface * surface) static void kos_FreeHWSurface(_THIS,SDL_Surface * surface) {/*STUB*/}
{
}
static int MenuetOS_LockHWSurface(_THIS,SDL_Surface * surface) static int kos_LockHWSurface(_THIS,SDL_Surface * surface)
{ {
return 0; return 0;
} }
static void MenuetOS_UnlockHWSurface(_THIS,SDL_Surface * surface) static void kos_UnlockHWSurface(_THIS,SDL_Surface * surface) {/*STUB*/}
{
}
static void MenuetOS_DirectUpdate(_THIS,int numrects,SDL_Rect * rects) static void kos_DirectUpdate(_THIS,int numrects,SDL_Rect * rects)
{ {
if(numrects) if (numrects) {
{ _ksys_draw_bitmap(this->hidden->__video_buffer, 0,0,
draw_bitmap(this->hidden->__video_buffer, 0,0,
vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y); vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y);
} }
} }
int MenuetOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) int kos_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{ {
return 0; return 0;
} }
void MenuetOS_VideoQuit(_THIS) void kos_VideoQuit(_THIS)
{ {
if (has_null_cursor) if (has_null_cursor) {
{ _ksys_delete_cursor(null_cursor);
__asm__("int $0x40"::"a"(37),"b"(6),"c"(null_cursor));
has_null_cursor = 0; has_null_cursor = 0;
} }
} }
void MenuetOS_FinalQuit(void) void kos_FinalQuit(void) {/*STUB*/}
{
}
void MenuetOS_SetCaption(_THIS,const char * title,const char * icon) void kos_SetCaption(_THIS,const char * title, const char * icon)
{ {
this->hidden->__title=(char *)title; this->hidden->__title=(char *)title;
if(was_initialized) __asm__("int $0x40"::"a"(71),"b"(1),"c"(title)); if (was_initialized) _ksys_set_window_title(title);
} }
SDL_Surface * MenuetOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) SDL_Surface *kos_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
{ {
int ly; int ly;
char * lx; unsigned char* lx;
if(bpp!=24) return NULL; if (bpp!=24) return NULL;
current->flags=flags; current->flags=flags;
current->w=width; current->w=width;
current->h=height; current->h=height;
@ -116,50 +89,27 @@ SDL_Surface * MenuetOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int
char info[100]; char info[100];
sprintf(info, "width = %d, height = %d, pitch = %d, bpp = %d\n", current->w, current->h, current->pitch, bpp); sprintf(info, "width = %d, height = %d, pitch = %d, bpp = %d\n", current->w, current->h, current->pitch, bpp);
_ksys_debug_puts(info);
current->pixels=this->hidden->__video_buffer=realloc(this->hidden->__video_buffer, current->pitch*current->h);
this->hidden->__lines=(unsigned char **)realloc(this->hidden->__lines, sizeof(unsigned char *)*current->h);
void debug_board_write_byte(const char ch){ for (ly=0, lx=current->pixels; ly<current->h; ly++, lx+=current->pitch)
__asm__ __volatile__(
"int $0x40"
:
:"a"(63), "b"(1), "c"(ch));
}
void debug_board_write_str(const char* str){
while(*str)
debug_board_write_byte(*str++);
}
debug_board_write_str(info);
// __asm__ __volatile__("int3");
current->pixels=this->hidden->__video_buffer=realloc(this->hidden->__video_buffer,
current->pitch*current->h);
this->hidden->__lines=(unsigned char **)realloc(this->hidden->__lines,
sizeof(unsigned char *)*current->h);
for(ly=0,lx=current->pixels;ly<current->h;ly++,lx+=current->pitch)
this->hidden->__lines[ly]=lx; this->hidden->__lines[ly]=lx;
this->UpdateRects=MenuetOS_DirectUpdate; this->UpdateRects=kos_DirectUpdate;
this->hidden->win_size_x=width; this->hidden->win_size_x=width;
this->hidden->win_size_y=height; this->hidden->win_size_y=height;
vm_suf=this; vm_suf=this;
if (was_initialized) {
if (was_initialized) unsigned newheight = height+_ksys_get_skin_height()+WINDOW_BORDER_H;
{ unsigned newwidth = width+WINDOW_BORDER_W;
unsigned newheight = height+get_skin_height+4; _ksys_change_window(-1, -1, newwidth, newheight);
unsigned newwidth = width+9; } else {
_ksys_set_event_mask(0x27);
sys_change_window(-1, -1, newwidth, newheight);
}
else
{
set_wanted_events_mask(0x27);
was_initialized=1; was_initialized=1;
MenuetOS_SDL_RepaintWnd(); kos_SDL_RepaintWnd();
} }
return current; return current;
} }
@ -167,7 +117,7 @@ SDL_Surface * MenuetOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int
/*static SDL_Rect video_mode[4]; /*static SDL_Rect video_mode[4];
static SDL_Rect * SDL_modelist[4]={NULL,NULL,NULL,NULL};*/ static SDL_Rect * SDL_modelist[4]={NULL,NULL,NULL,NULL};*/
static SDL_Rect ** MenuetOS_ListModes(_THIS,SDL_PixelFormat * fmt,Uint32 flags) static SDL_Rect** kos_ListModes(_THIS,SDL_PixelFormat * fmt,Uint32 flags)
{ {
// return (&SDL_modelist[((fmt->BitsPerPixel+7)/8)-1]); // return (&SDL_modelist[((fmt->BitsPerPixel+7)/8)-1]);
if (fmt->BitsPerPixel==24) if (fmt->BitsPerPixel==24)
@ -176,61 +126,34 @@ static SDL_Rect ** MenuetOS_ListModes(_THIS,SDL_PixelFormat * fmt,Uint32 flags)
return NULL; return NULL;
} }
static int MenuetOS_Available(void) static int kos_Available(void)
{ {
return 1; return 1;
} }
static void MenuetOS_DeleteDevice(_THIS) static void kos_DeleteDevice(_THIS)
{ {
// free(this->hidden->__video_buffer); // it will be freed as current->pixels // free(this->hidden->__video_buffer); // it will be freed as current->pixels
free(this->hidden->__lines); free(this->hidden->__lines);
} }
static int MenuetOS_VideoInit(_THIS,SDL_PixelFormat * vformat) static int kos_VideoInit(_THIS,SDL_PixelFormat * vformat)
{ {
#ifdef KEEP_OBSOLETE_STYLE3 vformat->BitsPerPixel = 24;
char buf[16]; vformat->BytesPerPixel = 3;
__asm__("int $0x40"::"a"(18),"b"(13),"c"(buf)); this->info.wm_available = 1;
if (buf[5]=='K' && buf[6]=='o' && buf[7]=='l' && buf[8]=='i') this->info.hw_available = 0;
/* kernels up to 0.7.0.0 do not support style 4 */; this->info.video_mem = 0x200000;
else if (*(unsigned*)(buf+5) >= 549)
/* window style 4 was introduced in revision 549 */
IsStyle4Available = 1;
#endif
vformat->BitsPerPixel=24;
vformat->BytesPerPixel=3;
this->info.wm_available=1;
this->info.hw_available=0;
this->info.video_mem=0x200000;
/* video_mode[3].x=0;
video_mode[3].y=0;
video_mode[3].w=320;
video_mode[3].h=200;
video_mode[2].x=0;
video_mode[2].y=0;
video_mode[2].w=640;
video_mode[2].h=400;
video_mode[1].x=0;
video_mode[1].y=0;
video_mode[1].w=320;
video_mode[1].h=240;
video_mode[0].x=0;
video_mode[0].y=0;
video_mode[0].w=640;
video_mode[0].h=480;
SDL_modelist[2]=video_mode+0;*/
return 0; return 0;
} }
static int MenuetOS_FlipHWSurface(_THIS,SDL_Surface * surface) static int kos_FlipHWSurface(_THIS,SDL_Surface * surface)
{ {
draw_bitmap(surface->pixels, 0,0,surface->w,surface->h); _ksys_draw_bitmap(surface->pixels, 0, 0, surface->w,surface->h);
return 0; return 0;
} }
WMcursor* KolibriOS_CreateWMCursor(_THIS, WMcursor* kos_CreateWMCursor(_THIS, Uint8* data, Uint8* mask, int w, int h, int hot_x, int hot_y)
Uint8* data, Uint8* mask, int w, int h, int hot_x, int hot_y)
{ {
int i,j; int i,j;
Uint32* cursor; Uint32* cursor;
@ -240,11 +163,9 @@ WMcursor* KolibriOS_CreateWMCursor(_THIS,
if (w%8 || h%8) return NULL; if (w%8 || h%8) return NULL;
cursor = (Uint32*)malloc(32*32*4); cursor = (Uint32*)malloc(32*32*4);
if (!cursor) return NULL; if (!cursor) return NULL;
for (i=0;i<32;i++) for (i=0;i<32;i++) {
for (j=0;j<32;j++) for (j=0;j<32;j++) {
{ if (i>=h || j>=w) {
if (i>=h || j>=w)
{
cursor[i*32+j] = 0x00000000; cursor[i*32+j] = 0x00000000;
continue; continue;
} }
@ -253,102 +174,96 @@ WMcursor* KolibriOS_CreateWMCursor(_THIS,
else else
cursor[i*32+j] = 0x00000000; cursor[i*32+j] = 0x00000000;
} }
__asm__ ("int $0x40" : "=a"(res) : "a"(37),"b"(4), }
"c"(cursor),"d"((hot_x<<24)+(hot_y<<16)+2)); res = _ksys_load_cursor(cursor, (hot_x<<24)+(hot_y<<16)+KSYS_CURSOR_INDIRECT);
free(cursor); free(cursor);
return res; return res;
} }
int KolibriOS_ShowWMCursor(_THIS,WMcursor*cursor)
int kos_ShowWMCursor(_THIS, WMcursor* cursor)
{ {
if (!cursor) if (!cursor) {
{ if (!has_null_cursor) {
if (!has_null_cursor)
{
unsigned* u = malloc(32*32*4); unsigned* u = malloc(32*32*4);
if (!u) return 1; if (!u) return 1;
memset(u,0,32*32*4); memset(u,0,32*32*4);
__asm__("int $0x40":"=a"(null_cursor): null_cursor = _ksys_load_cursor(u, KSYS_CURSOR_INDIRECT);
"a"(37),"b"(4),"c"(u),"d"(2));
free(u); free(u);
has_null_cursor = 1; has_null_cursor = 1;
} }
cursor = (WMcursor*)null_cursor; cursor = (WMcursor*)null_cursor;
} }
__asm__("int $0x40" : : "a"(37),"b"(5),"c"(cursor)); _ksys_set_cursor(cursor);
return 1; return 1;
} }
void KolibriOS_FreeWMCursor(_THIS,WMcursor*cursor) void kos_FreeWMCursor(_THIS, WMcursor* cursor)
{ {
__asm__("int $0x40" : : "a"(37),"b"(6),"c"(cursor)); _ksys_delete_cursor(cursor);
} }
void KolibriOS_CheckMouseMode(_THIS) void kos_CheckMouseMode(_THIS)
{ {
if (this->input_grab == SDL_GRAB_OFF) if (this->input_grab == SDL_GRAB_OFF)
return; return;
struct process_table_entry buf; ksys_thread_t thread_info;
int res; int res = _ksys_thread_info(&thread_info, -1);
__asm__ volatile("int $0x40" : "=a"(res): "a"(9), "b"(&buf), "c"(-1)); if (res == thread_info.window_pos_info) {
if (res == buf.pos_in_windowing_stack) int x = thread_info.winx_start + thread_info.clientx + this->hidden->win_size_x/2;
{ int y = thread_info.winy_start + thread_info.clienty + this->hidden->win_size_y/2;
int x = buf.winx_start + buf.client_left + this->hidden->win_size_x/2; _ksys_set_mouse_pos(x, y);
int y = buf.winy_start + buf.client_top + this->hidden->win_size_y/2;
__asm__("int $0x40" : : "a"(18),"b"(19),"c"(4),
"d"(x*65536+y));
} }
} }
char def_title[] = "KolibriOS SDL App"; char def_title[] = "KolibriOS SDL App";
static SDL_VideoDevice * MenuetOS_CreateDevice(int indx)
static SDL_VideoDevice *kos_CreateDevice(int indx)
{ {
SDL_VideoDevice * dev; SDL_VideoDevice * dev;
dev=(SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); dev = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
if(dev) if (dev) {
{
memset(dev,0,(sizeof *dev)); memset(dev,0,(sizeof *dev));
dev->hidden = (struct SDL_PrivateVideoData *)malloc((sizeof *dev->hidden)); dev->hidden = (struct SDL_PrivateVideoData*)malloc((sizeof *dev->hidden));
} }
if((dev==NULL) || (dev->hidden==NULL)) if ((dev==NULL) || (dev->hidden==NULL)) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
if(dev) if(dev) {
{
free(dev); free(dev);
} }
return(0); return(0);
} }
memset(dev->hidden,0,(sizeof *dev->hidden));
memset(dev->hidden, 0, (sizeof *dev->hidden));
dev->hidden->__title = def_title; dev->hidden->__title = def_title;
dev->VideoInit=MenuetOS_VideoInit; dev->VideoInit = kos_VideoInit;
dev->ListModes=MenuetOS_ListModes; dev->ListModes = kos_ListModes;
dev->SetVideoMode=MenuetOS_SetVideoMode; dev->SetVideoMode = kos_SetVideoMode;
dev->SetColors=MenuetOS_SetColors; dev->SetColors = kos_SetColors;
dev->UpdateRects=NULL; dev->UpdateRects = NULL;
dev->VideoQuit=MenuetOS_VideoQuit; dev->VideoQuit = kos_VideoQuit;
dev->AllocHWSurface=MenuetOS_AllocHWSurface; dev->AllocHWSurface=kos_AllocHWSurface;
dev->CheckHWBlit=NULL; dev->CheckHWBlit = NULL;
dev->FillHWRect=NULL; dev->FillHWRect = NULL;
dev->SetHWColorKey=NULL; dev->SetHWColorKey = NULL;
dev->SetHWAlpha=NULL; dev->SetHWAlpha = NULL;
dev->LockHWSurface=MenuetOS_LockHWSurface; dev->LockHWSurface = kos_LockHWSurface;
dev->UnlockHWSurface=MenuetOS_UnlockHWSurface; dev->UnlockHWSurface = kos_UnlockHWSurface;
dev->FlipHWSurface=MenuetOS_FlipHWSurface; dev->FlipHWSurface = kos_FlipHWSurface;
dev->FreeHWSurface=MenuetOS_FreeHWSurface; dev->FreeHWSurface = kos_FreeHWSurface;
dev->SetCaption=MenuetOS_SetCaption; dev->SetCaption = kos_SetCaption;
dev->SetIcon=NULL; dev->SetIcon = NULL;
dev->IconifyWindow=NULL; dev->IconifyWindow = NULL;
dev->GrabInput=NULL; dev->GrabInput = NULL;
dev->GetWMInfo=NULL; dev->GetWMInfo = NULL;
dev->InitOSKeymap=MenuetOS_InitOSKeymap; dev->InitOSKeymap = MenuetOS_InitOSKeymap;
dev->PumpEvents=MenuetOS_PumpEvents; dev->PumpEvents = MenuetOS_PumpEvents;
dev->free=MenuetOS_DeleteDevice; dev->free = kos_DeleteDevice;
dev->CreateWMCursor = KolibriOS_CreateWMCursor; dev->CreateWMCursor = kos_CreateWMCursor;
dev->FreeWMCursor = KolibriOS_FreeWMCursor; dev->FreeWMCursor = kos_FreeWMCursor;
dev->ShowWMCursor = KolibriOS_ShowWMCursor; dev->ShowWMCursor = kos_ShowWMCursor;
dev->CheckMouseMode = KolibriOS_CheckMouseMode; dev->CheckMouseMode = kos_CheckMouseMode;
return dev; return dev;
} }
VideoBootStrap mosvideo_bootstrab={ VideoBootStrap mosvideo_bootstrab={
"menuetos","MenuetOS Device Driver", "kolibrios", "KolibriOS Device Driver",
MenuetOS_Available,MenuetOS_CreateDevice, kos_Available, kos_CreateDevice,
}; };