Subversion Repositories Kolibri OS

Rev

Rev 300 | Blame | Last modification | View Log | Download | RSS feed

  1. // Emacs style mode select   -*- C++ -*-
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //      DOOM graphics stuff for SDL library
  21. //
  22. //-----------------------------------------------------------------------------
  23.  
  24. static const char
  25. rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
  26.  
  27. #include <stdlib.h>
  28.  
  29. #include "m_swap.h"
  30. #include "doomstat.h"
  31. #include "i_system.h"
  32. #include "v_video.h"
  33. #include "m_argv.h"
  34. #include "d_main.h"
  35.  
  36. #include "doomdef.h"
  37.  
  38. #include "kolibri.h"
  39.  
  40. void BlitDIB();
  41.  
  42. typedef struct SURFACE
  43. {
  44.         unsigned char *pixels;  
  45.         int w, h;              
  46.         int pitch;              
  47.         int offset;            
  48. } SURFACE;
  49.  
  50. SURFACE screen;
  51.  
  52. // Fake mouse handling.
  53. boolean         grabMouse;
  54.  
  55. // Blocky mode,
  56. // replace each 320x200 pixel with multiply*multiply pixels.
  57. // According to Dave Taylor, it still is a bonehead thing
  58. // to use ....
  59. static int      multiply=2;
  60.  
  61. static int disableVerticalMouse = 0;
  62.  
  63. static int scr_w =0;
  64. static int scr_h =0;
  65. static int win_x, win_y;
  66. static int win_w, win_h;
  67.  
  68.  
  69.  
  70. //int palette_color[256];
  71.  
  72.  
  73. static int      lastmousex = 0;
  74. static int      lastmousey = 0;
  75. boolean         mousemoved = false;
  76.  
  77.  
  78. void I_ShutdownGraphics(void)
  79. {
  80.  
  81. }
  82.  
  83.  
  84.  
  85. //
  86. // I_StartFrame
  87. //
  88. void I_StartFrame (void)
  89. {
  90.     // er?
  91.    
  92.    //printf("start new frame\n\r" );
  93.  
  94. }
  95.  
  96. int test_for_event(void)
  97. { int retval;
  98.   _asm
  99.  {   push ebx
  100.      push ecx
  101.      push edx
  102.      push esi
  103.      push edi
  104.      mov  eax,11
  105.      int  0x40
  106.      mov [retval], eax
  107.      pop edi
  108.      pop esi
  109.      pop edx
  110.      pop ecx
  111.      pop ebx
  112.  };
  113.  return retval;
  114. };
  115.  
  116.  
  117. void I_GetEvent(void)
  118. {
  119.   event_t evnt;
  120.   int val;
  121.   int key;
  122.   //printf("begin get_event()\n\r");
  123.   do
  124.   { val= test_for_event();
  125.     switch(val)
  126.     { case EV_REDRAW:
  127.         BeginDraw();
  128.         DrawWindow(win_x,win_y,win_w,win_h,0x404040,3,0,0,0);
  129.         EndDraw();
  130.         BlitDIB();
  131.         break;
  132.  
  133.       case EV_KEY:
  134.         if(!get_key(&key))
  135.         {
  136.           switch(key)
  137.           {  case 0xE0:
  138.              case 0xE1:
  139.                continue;
  140.              default:
  141.                if(key&0x80)
  142.                { //printf("key released\n\r");
  143.                  evnt.type = ev_keyup;
  144.                }
  145.                else
  146.                { //printf("key pressed %x\n\r",key);
  147.                  evnt.type = ev_keydown;
  148.                };
  149.                key&=0x7F;
  150.                evnt.data1=remap_key(key);
  151.                if ( evnt.data1 != 0 )
  152.                  D_PostEvent(&evnt);
  153.                continue;
  154.           };    
  155.         };  
  156.         continue;
  157.  
  158.       case EV_BUTTON:
  159.         switch(get_button_id())
  160.         {  case 1:
  161.              return;
  162.              
  163.           default:;
  164.         };
  165.     };  
  166.   }while(val);
  167. }
  168.  
  169.  
  170.  
  171. //
  172. // I_StartTic
  173. //
  174. void I_StartTic (void)
  175. {
  176.     I_GetEvent();
  177.    
  178. }
  179.  
  180.  
  181. //
  182. // I_UpdateNoBlit
  183. //
  184. void I_UpdateNoBlit (void)
  185. {
  186.     // what is this?
  187. }
  188.  
  189. //
  190. // I_ReadScreen
  191. //
  192. void I_ReadScreen (byte* scr)
  193. {
  194.     memcpy (scr, screens[0], SCREENWIDTH*SCREENHEIGHT);
  195. }
  196.  
  197.  
  198. //
  199. // I_SetPalette
  200. //
  201.  
  202. unsigned int colors[256];
  203.  
  204. void I_SetPalette (byte* palette)
  205. {
  206.     int i;
  207.     unsigned int r;
  208.     unsigned int g;
  209.     unsigned int b;
  210.    
  211.     for ( i=0; i<256; ++i )
  212.     {
  213.           r = gammatable[usegamma][*palette++];
  214.           g = gammatable[usegamma][*palette++];
  215.           b = gammatable[usegamma][*palette++];
  216.           colors[i]= b|(g<<8)|(r<<16);
  217.     }
  218. }
  219.  
  220. void BeginDraw()
  221. { _asm
  222.   { push ebx
  223.     mov   eax,12
  224.     mov   ebx, 1
  225.     int   0x40
  226.     pop ebx
  227.   };  
  228. };
  229.  
  230. void EndDraw()
  231. { _asm
  232.   { push ebx
  233.     mov   eax,12
  234.     mov   ebx, 2
  235.     int   0x40
  236.     pop ebx
  237.   };  
  238. };
  239.  
  240. void I_InitGraphics(void)
  241. {
  242.     static int firsttime=1;
  243.  
  244.     int frameX, frameY;
  245.  
  246.     if (!firsttime)
  247.         return;
  248.     firsttime = 0;
  249.  
  250.     if (M_CheckParm("-2"))
  251.         multiply = 2;
  252.  
  253.     if (M_CheckParm("-3"))
  254.         multiply = 3;
  255.  
  256.     if (M_CheckParm("-4"))
  257.         multiply = 4;
  258.  
  259.     win_w = SCREENWIDTH * multiply;
  260.     win_h = SCREENHEIGHT * multiply;
  261.  
  262.     // check if the user wants to grab the mouse (quite unnice)
  263.     grabMouse = !!M_CheckParm("-grabmouse");
  264.  
  265.     /* [Petteri] New: Option to disable mouse vertical movement - useful
  266.        for players used to Quake: */
  267.     disableVerticalMouse = !!M_CheckParm("-novertmouse");
  268.  
  269.     /* Build and initialize the window: */
  270.    
  271.     frameX = 0;
  272.     frameY = 18;
  273.    
  274.     GetScreenSize(&scr_w, &scr_h);
  275.     win_x = (scr_w-win_w)/2;
  276.     win_y = (scr_h-win_h)/2;
  277.      
  278.  //   hCursor = LoadCursor( 0, IDC_ARROW );
  279.    
  280.     printf("I_InitGraphics: Client area: %ux%u\n\r", win_w, win_h);
  281.  
  282.     screen.pixels= (byte*) UserAlloc(640*400*4);
  283.     screen.h = win_w;
  284.     screen.w = win_h;
  285.     screen.pitch=640;
  286.    
  287.     BeginDraw();
  288.     DrawWindow(win_x,win_y,win_w,win_h,0x404040,3,0,0,0);
  289.     EndDraw();
  290.  
  291. }
  292.  
  293.  
  294. void conv(char *dst, char *src);
  295.  
  296. void BlitDIB()
  297. {
  298.   _asm
  299.   {  push ebx
  300.      push ecx
  301.      push edx
  302.      mov eax, 7
  303.      mov ebx, dword ptr [screen]
  304.      mov ecx, 0x02800190
  305.      xor edx, edx
  306.      int 0x40
  307.      pop edx
  308.      pop ecx
  309.      pop ebx
  310.   }
  311. };
  312.  
  313. //
  314. // I_FinishUpdate
  315. //
  316. void I_FinishUpdate (void)
  317. {
  318.     char *dst0;
  319.     char *dst1;
  320.     char *src;
  321.        
  322.     int x, y;
  323.    
  324.     dst0 = &((char *)screen.pixels)[0];
  325.     dst1 = dst0+640*3;
  326.     src= (char*)screens[0];
  327.     y = SCREENHEIGHT;
  328.     while (y--)
  329.     {
  330.       x = SCREENWIDTH;
  331.       conv(dst0,src);
  332.       src+=320;
  333.       dst0+=640*3*2;
  334.       dst1+=640*3*2;
  335.     }
  336.     BlitDIB();
  337. }
  338.  
  339. void conv(char *dst, char *src)
  340. {
  341.    _asm
  342.    {
  343.      push ebx
  344.      push ecx
  345.      push esi
  346.      push edi
  347.      
  348.      mov ecx, 320
  349.      mov esi, [src]
  350.      mov edi, [dst]
  351.      cld
  352. l1:    
  353.      lodsb
  354.      movzx eax, al
  355.      mov eax, [colors+eax*4]
  356.      mov ebx, eax
  357.      bswap ebx
  358.      and ebx, 0xFF000000
  359.      or eax, ebx
  360.      mov [edi],eax
  361.      mov [edi+640*3], eax
  362.      shr eax, 8
  363.      mov [edi+4], ax
  364.      mov [edi+640*3+4], ax
  365.      add edi, 6
  366.      dec ecx
  367.      jnz l1
  368.      
  369.      pop edi
  370.      pop esi
  371.      pop ecx
  372.      pop ebx    
  373.   };  
  374. };  
  375.    
  376.    
  377.  
  378.  
  379.