Subversion Repositories Kolibri OS

Rev

Rev 6380 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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