1 //**************************************************************************
5 //**************************************************************************
14 #include "p_local.h" // for P_AproxDistance
21 int DisplayTicker = 0;
26 void I_StartupNet (void);
27 void I_ShutdownNet (void);
28 void I_ReadExternDriver(void);
29 void GrabScreen (void);
31 extern int usemouse, usejoystick;
33 extern void **lumpcache;
36 externdata_t *i_ExternData;
37 boolean useexterndriver;
39 SDL_Surface* sdl_screen;
44 //===============================
49 boolean novideo; // if true, stay in text mode for debugging
59 ============================================================================
63 ============================================================================
66 //--------------------------------------------------------------------------
70 //--------------------------------------------------------------------------
72 void I_WaitVBL(int vbls)
80 SDL_Delay( 16667/1000 );
84 //--------------------------------------------------------------------------
88 // Palette source must use 8 bit RGB elements.
90 //--------------------------------------------------------------------------
92 void I_SetPalette(byte *palette)
96 SDL_Color cmap[ 256 ];
106 for( ; c != cend; c++ )
108 //_outbyte(PEL_DATA, (gammatable[usegamma][*palette++])>>2);
110 c->r = gammatable[usegamma][*palette++];
111 c->g = gammatable[usegamma][*palette++];
112 c->b = gammatable[usegamma][*palette++];
114 SDL_SetColors( sdl_screen, cmap, 0, 256 );
118 ============================================================================
122 ============================================================================
125 byte *pcscreen, *destscreen, *destview;
136 extern int screenblocks;
146 // blit screen to video
150 if(screenblocks > 9 || UpdateState&(I_FULLSCRN|I_MESSAGES))
152 dest = (byte *)screen;
156 dest = (byte *)pcscreen;
158 tics = ticcount-lasttic;
164 for(i = 0; i < tics; i++)
169 for(i = tics; i < 20; i++)
176 //memset(pcscreen, 255, SCREENHEIGHT*SCREENWIDTH);
178 if(UpdateState == I_NOUPDATE)
182 if(UpdateState&I_FULLSCRN)
184 memcpy(pcscreen, screen, SCREENWIDTH*SCREENHEIGHT);
185 UpdateState = I_NOUPDATE; // clear out all draw types
187 SDL_UpdateRect( sdl_screen, 0, 0, SCREENWIDTH, SCREENHEIGHT );
189 if(UpdateState&I_FULLVIEW)
191 if(UpdateState&I_MESSAGES && screenblocks > 7)
194 (viewwindowy+viewheight)*SCREENWIDTH; i += SCREENWIDTH)
196 memcpy(pcscreen+i, screen+i, SCREENWIDTH);
198 UpdateState &= ~(I_FULLVIEW|I_MESSAGES);
200 SDL_UpdateRect( sdl_screen, 0, 0, SCREENWIDTH,
201 viewwindowy+viewheight );
205 for(i = viewwindowy*SCREENWIDTH+viewwindowx; i <
206 (viewwindowy+viewheight)*SCREENWIDTH; i += SCREENWIDTH)
208 memcpy(pcscreen+i, screen+i, viewwidth);
210 UpdateState &= ~I_FULLVIEW;
212 SDL_UpdateRect( sdl_screen, viewwindowx, viewwindowy, viewwidth,
216 if(UpdateState&I_STATBAR)
218 memcpy(pcscreen+SCREENWIDTH*(SCREENHEIGHT-SBARHEIGHT),
219 screen+SCREENWIDTH*(SCREENHEIGHT-SBARHEIGHT),
220 SCREENWIDTH*SBARHEIGHT);
221 UpdateState &= ~I_STATBAR;
223 SDL_UpdateRect( sdl_screen, 0, SCREENHEIGHT-SBARHEIGHT,
224 SCREENWIDTH, SBARHEIGHT );
226 if(UpdateState&I_MESSAGES)
228 memcpy(pcscreen, screen, SCREENWIDTH*28);
229 UpdateState &= ~I_MESSAGES;
231 SDL_UpdateRect( sdl_screen, 0, 0, SCREENWIDTH, 28 );
235 //--------------------------------------------------------------------------
237 // PROC I_InitGraphics
239 //--------------------------------------------------------------------------
241 void I_InitGraphics(void)
250 // SDL_DOUBLEBUF does not work in full screen mode. Does not seem to
251 // be necessary anyway.
253 sdl_screen = SDL_SetVideoMode(SCREENWIDTH, SCREENHEIGHT, 8, SDL_SWSURFACE);
254 //SDL_HWSURFACE | SDL_FULLSCREEN );
256 if( sdl_screen == NULL )
258 fprintf( stderr, "Couldn't set video mode %dx%d: %s\n",
259 SCREENWIDTH, SCREENHEIGHT, SDL_GetError() );
263 if( SDL_MUSTLOCK( sdl_screen ) )
265 printf( "SDL_MUSTLOCK\n" );
269 // Only grab if we want to
270 if (M_CheckParm ("-nograb")) {
274 SDL_WM_GrabInput (1);
277 snprintf (text, 20, "HHeretic v%s", HHERETIC_VERSION);
279 SDL_WM_SetCaption( text, "HHERETIC" );
282 pcscreen = destscreen = sdl_screen->pixels;
284 I_SetPalette( W_CacheLumpName("PLAYPAL", PU_CACHE) );
287 //--------------------------------------------------------------------------
289 // PROC I_ShutdownGraphics
291 //--------------------------------------------------------------------------
294 void I_ShutdownGraphics(void)
300 //--------------------------------------------------------------------------
304 // Reads the screen currently displayed into a linear buffer.
306 //--------------------------------------------------------------------------
309 void I_ReadScreen(byte *scr)
311 memcpy(scr, screen, SCREENWIDTH*SCREENHEIGHT);
315 //===========================================================================
319 // Translates the key
322 int xlatekey(SDL_keysym *key)
329 case SDLK_LEFT: rc = KEY_LEFTARROW; break;
330 case SDLK_RIGHT: rc = KEY_RIGHTARROW; break;
331 case SDLK_DOWN: rc = KEY_DOWNARROW; break;
332 case SDLK_UP: rc = KEY_UPARROW; break;
333 case SDLK_ESCAPE: rc = KEY_ESCAPE; break;
334 case SDLK_RETURN: rc = KEY_ENTER; break;
335 case SDLK_F1: rc = KEY_F1; break;
336 case SDLK_F2: rc = KEY_F2; break;
337 case SDLK_F3: rc = KEY_F3; break;
338 case SDLK_F4: rc = KEY_F4; break;
339 case SDLK_F5: rc = KEY_F5; break;
340 case SDLK_F6: rc = KEY_F6; break;
341 case SDLK_F7: rc = KEY_F7; break;
342 case SDLK_F8: rc = KEY_F8; break;
343 case SDLK_F9: rc = KEY_F9; break;
344 case SDLK_F10: rc = KEY_F10; break;
345 case SDLK_F11: rc = KEY_F11; break;
346 case SDLK_F12: rc = KEY_F12; break;
348 case SDLK_INSERT: rc = KEY_INS; break;
349 case SDLK_DELETE: rc = KEY_DEL; break;
350 case SDLK_PAGEUP: rc = KEY_PGUP; break;
351 case SDLK_PAGEDOWN: rc = KEY_PGDN; break;
352 case SDLK_HOME: rc = KEY_HOME; break;
353 case SDLK_END: rc = KEY_END; break;
355 case SDLK_BACKSPACE: rc = KEY_BACKSPACE; break;
357 case SDLK_PAUSE: rc = KEY_PAUSE; break;
359 case SDLK_EQUALS: rc = KEY_EQUALS; break;
362 case SDLK_MINUS: rc = KEY_MINUS; break;
391 /* This processes SDL events */
392 void I_GetEvent(SDL_Event *Event)
400 event.type = ev_keydown;
401 event.data1 = xlatekey(&Event->key.keysym);
406 event.type = ev_keyup;
407 event.data1 = xlatekey(&Event->key.keysym);
411 case SDL_MOUSEBUTTONDOWN:
412 case SDL_MOUSEBUTTONUP:
413 buttonstate = SDL_GetMouseState(NULL, NULL);
414 event.type = ev_mouse;
416 | (buttonstate & SDL_BUTTON(1) ? 1 : 0)
417 | (buttonstate & SDL_BUTTON(2) ? 2 : 0)
418 | (buttonstate & SDL_BUTTON(3) ? 4 : 0);
419 event.data2 = event.data3 = 0;
423 case SDL_MOUSEMOTION:
424 /* Ignore mouse warp events */
425 if ( (Event->motion.x != sdl_screen->w/2) ||
426 (Event->motion.y != sdl_screen->h/2) )
428 /* Warp the mouse back to the center */
430 SDL_WarpMouse(sdl_screen->w/2, sdl_screen->h/2);
432 event.type = ev_mouse;
434 | (Event->motion.state & SDL_BUTTON(1) ? 1 : 0)
435 | (Event->motion.state & SDL_BUTTON(2) ? 2 : 0)
436 | (Event->motion.state & SDL_BUTTON(3) ? 4 : 0);
437 event.data2 = Event->motion.xrel << 3;
438 event.data3 = -Event->motion.yrel << 3;
452 void I_StartTic (void)
456 while ( SDL_PollEvent(&Event) )
462 ============================================================================
466 ============================================================================
478 int I_TimerISR (void)
485 ============================================================================
489 ============================================================================
497 ============================================================================
501 ============================================================================
514 void I_StartupMouse (void)
519 void GrabScreen (void)