Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5130 → Rev 5131

/contrib/sdk/sources/SDL-1.2.2/src/video/menuetos/SDL_menuetevents.c
0,0 → 1,244
#include<menuet/os.h>
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
#include "SDL_sysevents.h"
#include "SDL_sysvideo.h"
#include "SDL_events_c.h"
#include "SDL_menuetvideo.h"
 
extern void MenuetOS_SDL_RepaintWnd(void);
 
void MenuetOS_InitOSKeymap(_THIS)
{
__asm__("int $0x40"::"a"(66),"b"(1),"c"(1));
}
 
#define LSHIFT 1
#define RSHIFT 2
#define LCTRL 4
#define RCTRL 8
#define LALT 0x10
#define RALT 0x20
#define CAPS 0x40
#define NUML 0x80
#define SCRL 0x100
 
#define SHIFT (LSHIFT+RSHIFT)
#define CTRL (LCTRL+RCTRL)
#define ALT (LALT+RALT)
 
static SDLMod GetModState(void)
{
unsigned controlstate;
__asm__("int $0x40":"=a"(controlstate):"a"(66),"b"(3));
SDLMod res = 0;
if (controlstate & LSHIFT)
res |= KMOD_LSHIFT;
if (controlstate & RSHIFT)
res |= KMOD_RSHIFT;
if (controlstate & LCTRL)
res |= KMOD_LCTRL;
if (controlstate & RCTRL)
res |= KMOD_RCTRL;
if (controlstate & LALT)
res |= KMOD_LALT;
if (controlstate & RALT)
res |= KMOD_RALT;
if (controlstate & CAPS)
res |= KMOD_CAPS;
if (controlstate & NUML)
res |= KMOD_NUM;
return res;
}
 
/*static __u8 scan2ascii(__u8 n,SDLMod mod)
{
__u8 layout[128];
int layouttype;
int bControlLayout = 0;
if (mod & KMOD_ALT)
layouttype = 3;
else if (mod & KMOD_SHIFT)
layouttype = 2;
else
{
if (mod & KMOD_CTRL)
bControlLayout = 1;
layouttype = 1;
}
__asm__("int $0x40" :: "a"(26),"b"(2),"c"(layouttype),"d"(layout));
__u8 res = layout[n];
if (bControlLayout)
res -= 0x60;
return res;
}*/
static SDLKey sdlkeys[0x80] =
{
// 0x0*
0, SDLK_ESCAPE, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6,
SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS, SDLK_BACKSPACE, SDLK_TAB,
// 0x1*
SDLK_q, SDLK_w, SDLK_e, SDLK_r, SDLK_t, SDLK_y, SDLK_u, SDLK_i,
SDLK_o, SDLK_p, SDLK_LEFTBRACKET, SDLK_RIGHTBRACKET, SDLK_RETURN, SDLK_LCTRL, SDLK_a, SDLK_s,
// 0x2*
SDLK_d, SDLK_f, SDLK_g, SDLK_h, SDLK_j, SDLK_k, SDLK_l, SDLK_SEMICOLON,
SDLK_QUOTE, SDLK_BACKQUOTE, SDLK_LSHIFT, SDLK_BACKSLASH, SDLK_z, SDLK_x, SDLK_c, SDLK_v,
// 0x3*
SDLK_b, SDLK_n, SDLK_m, SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_RSHIFT, SDLK_KP_MULTIPLY,
SDLK_LALT, SDLK_SPACE, SDLK_CAPSLOCK, SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5,
// 0x4*
SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_NUMLOCK, SDLK_SCROLLOCK, SDLK_KP7,
SDLK_KP8, SDLK_KP9, SDLK_KP_MINUS, SDLK_KP4, SDLK_KP5, SDLK_KP6, SDLK_KP_PLUS, SDLK_KP1,
// 0x5*
SDLK_KP2, SDLK_KP3, SDLK_KP0, SDLK_KP_PERIOD, 0, 0, 0, SDLK_F11,
SDLK_F12, 0, 0, 0, 0, 0, 0, 0,
// 0x6*
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
// 0x7*
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
static SDLKey sdlkeys_shift[0x80] =
{
// 0x0*
0, SDLK_ESCAPE, SDLK_EXCLAIM, SDLK_AT, SDLK_HASH, SDLK_DOLLAR, '%', SDLK_CARET,
SDLK_AMPERSAND, SDLK_ASTERISK, SDLK_LEFTPAREN, SDLK_RIGHTPAREN, SDLK_UNDERSCORE, SDLK_PLUS, SDLK_BACKSPACE, SDLK_TAB,
// 0x1*
SDLK_q, SDLK_w, SDLK_e, SDLK_r, SDLK_t, SDLK_y, SDLK_u, SDLK_i,
SDLK_o, SDLK_p, '{', '}', SDLK_RETURN, SDLK_LCTRL, SDLK_a, SDLK_s,
// 0x2*
SDLK_d, SDLK_f, SDLK_g, SDLK_h, SDLK_j, SDLK_k, SDLK_l, SDLK_COLON,
SDLK_QUOTEDBL, '~', SDLK_LSHIFT, '|', SDLK_z, SDLK_x, SDLK_c, SDLK_v,
// 0x3*
SDLK_b, SDLK_n, SDLK_m, SDLK_LESS, SDLK_GREATER, SDLK_QUESTION, SDLK_RSHIFT, SDLK_KP_MULTIPLY,
SDLK_LALT, SDLK_SPACE, SDLK_CAPSLOCK, SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5,
// 0x4*
SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_NUMLOCK, SDLK_SCROLLOCK, SDLK_KP7,
SDLK_KP8, SDLK_KP9, SDLK_KP_MINUS, SDLK_KP4, SDLK_KP5, SDLK_KP6, SDLK_KP_PLUS, SDLK_KP1,
// 0x5*
SDLK_KP2, SDLK_KP3, SDLK_KP0, SDLK_KP_PERIOD, 0, 0, 0, SDLK_F11,
SDLK_F12, 0, 0, 0, 0, 0, 0, 0,
// 0x6*
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
// 0x7*
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
static SDLKey sdlkeys_e0[0x80] =
{
// 0x0*
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
// 0x1*
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, SDLK_KP_ENTER, SDLK_RCTRL, 0, 0,
// 0x2*
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
// 0x3*
0, 0, 0, 0, 0, SDLK_KP_DIVIDE, 0, SDLK_PRINT,
SDLK_RALT, 0, 0, 0, 0, 0, 0, 0,
// 0x4*
0, 0, 0, 0, 0, 0, 0, SDLK_HOME,
SDLK_UP, SDLK_PAGEUP, 0, SDLK_LEFT, 0, SDLK_RIGHT, 0, SDLK_END,
// 0x5*
SDLK_DOWN, SDLK_PAGEDOWN, SDLK_INSERT, SDLK_DELETE, 0, 0, 0, 0,
0, 0, 0, SDLK_LSUPER, SDLK_RSUPER, SDLK_MENU, 0, 0,
// 0x6*
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
// 0x7*
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
 
extern void KolibriOS_CheckMouseMode(_THIS);
void MenuetOS_PumpEvents(_THIS)
{
int i;
SDL_keysym key;
static int ext_code=0;
static __u8 old_mode=0;
for (;;) {
i=__menuet__check_for_event();
switch(i)
{
case 0:
return;
case 1:
MenuetOS_SDL_RepaintWnd();
break;
case 2:
key.scancode = __menuet__getkey();
if (key.scancode == 0xE0 || key.scancode == 0xE1)
{ext_code=key.scancode;break;}
if (ext_code == 0xE1 && (key.scancode & 0x7F) == 0x1D) break;
if (ext_code == 0xE1 && key.scancode == 0xC5) {ext_code=0;break;}
key.mod = GetModState();
if (ext_code == 0xE1) key.mod &= ~KMOD_CTRL;
if (!(key.scancode&0x80))
old_mode = key.mod;
SDL_SetModState(key.mod);
int code = (key.scancode & 0x80) ? SDL_RELEASED : SDL_PRESSED;
key.scancode &= 0x7F;
// key.sym = scan2ascii(key.scancode,key.mod);
if (ext_code == 0xE1 && key.scancode == 0x45)
key.sym = SDLK_PAUSE;
else if (ext_code == 0xE0)
key.sym = sdlkeys_e0[key.scancode];
else if (old_mode & KMOD_SHIFT)
key.sym = sdlkeys_shift[key.scancode];
else
key.sym = sdlkeys[key.scancode];
ext_code = 0;
if (!key.sym) break;
SDL_PrivateKeyboard(code,&key);
break;
case 3:
if(__menuet__get_button_id()==1) exit(0);
break;
case 6: {
int __tmp,mx,my;
static int oldmousestate = 0;
__asm__("int $0x40":"=a"(__tmp):"a"(37),"b"(1));
mx=(__tmp>>16);
my=(__tmp&0xffff);
if(mx>=0 && mx<this->hidden->win_size_x &&
my>=0 && my<this->hidden->win_size_y || this->input_grab != SDL_GRAB_OFF)
{
if (this->input_grab != SDL_GRAB_OFF)
{
int dx=mx-this->hidden->win_size_x/2;
int dy=my-this->hidden->win_size_y/2;
if (dx||dy)
{
SDL_PrivateMouseMotion(0,1,dx,dy);
KolibriOS_CheckMouseMode(this);
}
}
else
SDL_PrivateMouseMotion(0,0,mx,my);
__asm__("int $0x40":"=a"(__tmp):"a"(37),"b"(2));
if ((__tmp^oldmousestate)&1) {
if(__tmp&1)
{
SDL_PrivateMouseButton(SDL_PRESSED,SDL_BUTTON_LMASK,0,0);
} else {
SDL_PrivateMouseButton(SDL_RELEASED,SDL_BUTTON_LMASK,0,0);
} }
if ((__tmp^oldmousestate)&2) {
if(__tmp&2)
{
SDL_PrivateMouseButton(SDL_PRESSED,SDL_BUTTON_RMASK,0,0);
} else {
SDL_PrivateMouseButton(SDL_RELEASED,SDL_BUTTON_RMASK,0,0);
} }
oldmousestate = __tmp;
}
}
}
}
}
/contrib/sdk/sources/SDL-1.2.2/src/video/menuetos/SDL_menuetvideo.c
0,0 → 1,324
#include <stdlib.h>
#include <stdio.h>
#include <menuet/os.h>
#include "SDL.h"
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_sysvideo.h"
#include "SDL_pixels_c.h"
#include "SDL_events_c.h"
#include "SDL_menuetvideo.h"
#include <string.h>
 
static SDL_VideoDevice * vm_suf=NULL;
static int was_initialized=0;
 
static int has_null_cursor=0;
static int null_cursor;
 
inline int get_skinh(void)
{
int res;
__asm__ ("int $0x40" : "=a"(res) : "a"(48),"b"(4));
return res;
}
 
//#define KEEP_OBSOLETE_STYLE3
 
#ifdef KEEP_OBSOLETE_STYLE3
static int IsStyle4Available=0;
#endif
 
void MenuetOS_SDL_RepaintWnd(void)
{
__menuet__window_redraw(1);
__menuet__define_window(1,1,vm_suf->hidden->win_size_x+9,vm_suf->hidden->win_size_y+get_skinh()+4,
#ifdef KEEP_OBSOLETE_STYLE3
IsStyle4Available?0x34000000:0x33000000
#else
0x34000000
#endif
,0,(int)vm_suf->hidden->__title);
if(vm_suf && vm_suf->hidden->__video_buffer)
__menuet__putimage(0,0,
vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y,
vm_suf->hidden->__video_buffer);
__menuet__window_redraw(2);
}
 
static int MenuetOS_AllocHWSurface(_THIS,SDL_Surface * surface)
{
return -1;
}
 
static void MenuetOS_FreeHWSurface(_THIS,SDL_Surface * surface)
{
}
 
static int MenuetOS_LockHWSurface(_THIS,SDL_Surface * surface)
{
return 0;
}
 
static void MenuetOS_UnlockHWSurface(_THIS,SDL_Surface * surface)
{
}
 
static void MenuetOS_DirectUpdate(_THIS,int numrects,SDL_Rect * rects)
{
if(numrects)
{
__menuet__putimage(0,0,
vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y,
this->hidden->__video_buffer);
}
}
 
int MenuetOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
return 0;
}
 
void MenuetOS_VideoQuit(_THIS)
{
if (has_null_cursor)
{
__asm__("int $0x40"::"a"(37),"b"(6),"c"(null_cursor));
has_null_cursor = 0;
}
}
 
void MenuetOS_FinalQuit(void)
{
}
 
void MenuetOS_SetCaption(_THIS,const char * title,const char * icon)
{
this->hidden->__title=(char *)title;
if(was_initialized) __asm__("int $0x40"::"a"(71),"b"(1),"c"(title));
}
 
SDL_Surface * MenuetOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
{
int ly;
char * lx;
if(bpp!=24) return NULL;
current->flags=flags;
current->w=width;
current->h=height;
current->pitch=width*(bpp>>3);
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->UpdateRects=MenuetOS_DirectUpdate;
this->hidden->win_size_x=width;
this->hidden->win_size_y=height;
vm_suf=this;
if (was_initialized)
{
unsigned newheight = height+get_skinh()+4;
unsigned newwidth = width+9;
__asm__("int $0x40"::"a"(67),"b"(-1),"c"(-1),"d"(newwidth),"S"(newheight));
}
else
{
__menuet__set_bitfield_for_wanted_events(0x27);
was_initialized=1;
MenuetOS_SDL_RepaintWnd();
}
return current;
}
 
/*static SDL_Rect video_mode[4];
static SDL_Rect * SDL_modelist[4]={NULL,NULL,NULL,NULL};*/
 
static SDL_Rect ** MenuetOS_ListModes(_THIS,SDL_PixelFormat * fmt,Uint32 flags)
{
// return (&SDL_modelist[((fmt->BitsPerPixel+7)/8)-1]);
if (fmt->BitsPerPixel==24)
return (SDL_Rect**)-1;
else
return NULL;
}
 
static int MenuetOS_Available(void)
{
return 1;
}
 
static void MenuetOS_DeleteDevice(_THIS)
{
// free(this->hidden->__video_buffer); // it will be freed as current->pixels
free(this->hidden->__lines);
}
 
static int MenuetOS_VideoInit(_THIS,SDL_PixelFormat * vformat)
{
#ifdef KEEP_OBSOLETE_STYLE3
char buf[16];
__asm__("int $0x40"::"a"(18),"b"(13),"c"(buf));
if (buf[5]=='K' && buf[6]=='o' && buf[7]=='l' && buf[8]=='i')
/* kernels up to 0.7.0.0 do not support style 4 */;
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;
}
 
static int MenuetOS_FlipHWSurface(_THIS,SDL_Surface * surface)
{
__menuet__putimage(0,0,surface->w,surface->h,
surface->pixels);
return 0;
}
 
WMcursor* KolibriOS_CreateWMCursor(_THIS,
Uint8* data, Uint8* mask, int w, int h, int hot_x, int hot_y)
{
int i,j;
Uint32* cursor;
WMcursor* res;
 
if (w>32 || h>32) return NULL;
if (w%8 || h%8) return NULL;
cursor = (Uint32*)malloc(32*32*4);
if (!cursor) return NULL;
for (i=0;i<32;i++)
for (j=0;j<32;j++)
{
if (i>=h || j>=w)
{
cursor[i*32+j] = 0x00000000;
continue;
}
if (mask[i*w/8+j/8] & (0x80>>(j&7)))
cursor[i*32+j] = (data[i*w/8+j/8] & (0x80>>(j&7)))?0xFF000000:0xFFFFFFFF;
else
cursor[i*32+j] = 0x00000000;
}
__asm__ ("int $0x40" : "=a"(res) : "a"(37),"b"(4),
"c"(cursor),"d"((hot_x<<24)+(hot_y<<16)+2));
free(cursor);
return res;
}
int KolibriOS_ShowWMCursor(_THIS,WMcursor*cursor)
{
if (!cursor)
{
if (!has_null_cursor)
{
unsigned* u = malloc(32*32*4);
if (!u) return 1;
memset(u,0,32*32*4);
__asm__("int $0x40":"=a"(null_cursor):
"a"(37),"b"(4),"c"(u),"d"(2));
free(u);
has_null_cursor = 1;
}
cursor = (WMcursor*)null_cursor;
}
__asm__("int $0x40" : : "a"(37),"b"(5),"c"(cursor));
return 1;
}
void KolibriOS_FreeWMCursor(_THIS,WMcursor*cursor)
{
__asm__("int $0x40" : : "a"(37),"b"(6),"c"(cursor));
}
void KolibriOS_CheckMouseMode(_THIS)
{
if (this->input_grab == SDL_GRAB_OFF)
return;
struct process_table_entry buf;
int res;
__asm__ volatile("int $0x40" : "=a"(res): "a"(9), "b"(&buf), "c"(-1));
if (res == buf.pos_in_windowing_stack)
{
int x = buf.winx_start + buf.client_left + this->hidden->win_size_x/2;
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";
static SDL_VideoDevice * MenuetOS_CreateDevice(int indx)
{
SDL_VideoDevice * dev;
dev=(SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
if(dev)
{
memset(dev,0,(sizeof *dev));
dev->hidden = (struct SDL_PrivateVideoData *)malloc((sizeof *dev->hidden));
}
if((dev==NULL) || (dev->hidden==NULL))
{
SDL_OutOfMemory();
if(dev)
{
free(dev);
}
return(0);
}
memset(dev->hidden,0,(sizeof *dev->hidden));
dev->hidden->__title = def_title;
dev->VideoInit=MenuetOS_VideoInit;
dev->ListModes=MenuetOS_ListModes;
dev->SetVideoMode=MenuetOS_SetVideoMode;
dev->SetColors=MenuetOS_SetColors;
dev->UpdateRects=NULL;
dev->VideoQuit=MenuetOS_VideoQuit;
dev->AllocHWSurface=MenuetOS_AllocHWSurface;
dev->CheckHWBlit=NULL;
dev->FillHWRect=NULL;
dev->SetHWColorKey=NULL;
dev->SetHWAlpha=NULL;
dev->LockHWSurface=MenuetOS_LockHWSurface;
dev->UnlockHWSurface=MenuetOS_UnlockHWSurface;
dev->FlipHWSurface=MenuetOS_FlipHWSurface;
dev->FreeHWSurface=MenuetOS_FreeHWSurface;
dev->SetCaption=MenuetOS_SetCaption;
dev->SetIcon=NULL;
dev->IconifyWindow=NULL;
dev->GrabInput=NULL;
dev->GetWMInfo=NULL;
dev->InitOSKeymap=MenuetOS_InitOSKeymap;
dev->PumpEvents=MenuetOS_PumpEvents;
dev->free=MenuetOS_DeleteDevice;
dev->CreateWMCursor = KolibriOS_CreateWMCursor;
dev->FreeWMCursor = KolibriOS_FreeWMCursor;
dev->ShowWMCursor = KolibriOS_ShowWMCursor;
dev->CheckMouseMode = KolibriOS_CheckMouseMode;
return dev;
}
 
VideoBootStrap mosvideo_bootstrab={
"menuetos","MenuetOS Device Driver",
MenuetOS_Available,MenuetOS_CreateDevice,
};
/contrib/sdk/sources/SDL-1.2.2/src/video/menuetos/SDL_menuetvideo.h
0,0 → 1,20
#ifndef _SDL_menuetvideo_h
#define _SDL_menuetvideo_h
 
#include "SDL_mouse.h"
#include "SDL_sysvideo.h"
 
#define _THIS SDL_VideoDevice *this
 
struct SDL_PrivateVideoData {
unsigned char * __video_buffer;
char * __title;
int win_size_x,win_size_y;
int vx_ofs,vy_ofs;
unsigned char** __lines;
};
 
void MenuetOS_InitOSKeymap(_THIS);
void MenuetOS_PumpEvents(_THIS);
 
#endif