| 1 |
/* |
| 2 |
* Copyright (C) 2002-2014 The DOSBox Team |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
/* $Id: sdlmain.cpp,v 1.154 2009-06-01 10:25:51 qbix79 Exp $ */ |
| 20 |
|
| 21 |
#ifndef _GNU_SOURCE |
| 22 |
#define _GNU_SOURCE |
| 23 |
#endif |
| 24 |
|
| 25 |
#include <stdlib.h> |
| 26 |
#include <string.h> |
| 27 |
#include <stdio.h> |
| 28 |
#include <unistd.h> |
| 29 |
#include <stdarg.h> |
| 30 |
#include <sys/types.h> |
| 31 |
#ifdef WIN32 |
| 32 |
#include <signal.h> |
| 33 |
#include <process.h> |
| 34 |
#endif |
| 35 |
|
| 36 |
#include "cross.h" |
| 37 |
#include "SDL.h" |
| 38 |
|
| 39 |
#include "dosbox.h" |
| 40 |
#include "video.h" |
| 41 |
#include "mouse.h" |
| 42 |
#include "pic.h" |
| 43 |
#include "timer.h" |
| 44 |
#include "setup.h" |
| 45 |
#include "support.h" |
| 46 |
#include "debug.h" |
| 47 |
#include "mapper.h" |
| 48 |
#include "vga.h" |
| 49 |
#include "keyboard.h" |
| 50 |
#include "cpu.h" |
| 51 |
#include "cross.h" |
| 52 |
#include "control.h" |
| 53 |
|
| 54 |
#define MAPPERFILE "mapper-" VERSION ".map" |
| 55 |
//#define DISABLE_JOYSTICK |
| 56 |
|
| 57 |
#if C_OPENGL |
| 58 |
#include "SDL_opengl.h" |
| 59 |
|
| 60 |
#ifndef APIENTRY |
| 61 |
#define APIENTRY |
| 62 |
#endif |
| 63 |
#ifndef APIENTRYP |
| 64 |
#define APIENTRYP APIENTRY * |
| 65 |
#endif |
| 66 |
|
| 67 |
#ifndef GL_ARB_pixel_buffer_object |
| 68 |
#define GL_ARB_pixel_buffer_object 1 |
| 69 |
#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB |
| 70 |
#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC |
| 71 |
#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED |
| 72 |
#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF |
| 73 |
#endif |
| 74 |
|
| 75 |
#ifndef GL_ARB_vertex_buffer_object |
| 76 |
#define GL_ARB_vertex_buffer_object 1 |
| 77 |
typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); |
| 78 |
typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); |
| 79 |
typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); |
| 80 |
typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); |
| 81 |
typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access); |
| 82 |
typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target); |
| 83 |
#endif |
| 84 |
|
| 85 |
PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL; |
| 86 |
PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL; |
| 87 |
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL; |
| 88 |
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL; |
| 89 |
PFNGLMAPBUFFERARBPROC glMapBufferARB = NULL; |
| 90 |
PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB = NULL; |
| 91 |
|
| 92 |
#endif //C_OPENGL |
| 93 |
|
| 94 |
#if !(ENVIRON_INCLUDED) |
| 95 |
extern char** environ; |
| 96 |
#endif |
| 97 |
|
| 98 |
#ifdef WIN32 |
| 99 |
#ifndef WIN32_LEAN_AND_MEAN |
| 100 |
#define WIN32_LEAN_AND_MEAN |
| 101 |
#endif |
| 102 |
#include <windows.h> |
| 103 |
#if (HAVE_DDRAW_H) |
| 104 |
#include <ddraw.h> |
| 105 |
struct private_hwdata { |
| 106 |
LPDIRECTDRAWSURFACE3 dd_surface; |
| 107 |
LPDIRECTDRAWSURFACE3 dd_writebuf; |
| 108 |
}; |
| 109 |
#endif |
| 110 |
|
| 111 |
#define STDOUT_FILE TEXT("stdout.txt") |
| 112 |
#define STDERR_FILE TEXT("stderr.txt") |
| 113 |
#define DEFAULT_CONFIG_FILE "/dosbox.conf" |
| 114 |
#elif defined(MACOSX) |
| 115 |
#define DEFAULT_CONFIG_FILE "/Library/Preferences/DOSBox Preferences" |
| 116 |
#else /*linux freebsd*/ |
| 117 |
#define DEFAULT_CONFIG_FILE "/.dosboxrc" |
| 118 |
#endif |
| 119 |
|
| 120 |
#if C_SET_PRIORITY |
| 121 |
#include <sys/resource.h> |
| 122 |
#define PRIO_TOTAL (PRIO_MAX-PRIO_MIN) |
| 123 |
#endif |
| 124 |
|
| 125 |
#ifdef OS2 |
| 126 |
#define INCL_DOS |
| 127 |
#define INCL_WIN |
| 128 |
#include <os2.h> |
| 129 |
#endif |
| 130 |
|
| 131 |
enum SCREEN_TYPES { |
| 132 |
SCREEN_SURFACE, |
| 133 |
SCREEN_SURFACE_DDRAW, |
| 134 |
SCREEN_OVERLAY, |
| 135 |
SCREEN_OPENGL |
| 136 |
}; |
| 137 |
|
| 138 |
enum PRIORITY_LEVELS { |
| 139 |
PRIORITY_LEVEL_PAUSE, |
| 140 |
PRIORITY_LEVEL_LOWEST, |
| 141 |
PRIORITY_LEVEL_LOWER, |
| 142 |
PRIORITY_LEVEL_NORMAL, |
| 143 |
PRIORITY_LEVEL_HIGHER, |
| 144 |
PRIORITY_LEVEL_HIGHEST |
| 145 |
}; |
| 146 |
|
| 147 |
|
| 148 |
struct SDL_Block { |
| 149 |
bool inited; |
| 150 |
bool active; //If this isn't set don't draw |
| 151 |
bool updating; |
| 152 |
struct { |
| 153 |
Bit32u width; |
| 154 |
Bit32u height; |
| 155 |
Bit32u bpp; |
| 156 |
Bitu flags; |
| 157 |
double scalex,scaley; |
| 158 |
GFX_CallBack_t callback; |
| 159 |
} draw; |
| 160 |
bool wait_on_error; |
| 161 |
struct { |
| 162 |
struct { |
| 163 |
Bit16u width, height; |
| 164 |
bool fixed; |
| 165 |
} full; |
| 166 |
struct { |
| 167 |
Bit16u width, height; |
| 168 |
} window; |
| 169 |
Bit8u bpp; |
| 170 |
bool fullscreen; |
| 171 |
bool doublebuf; |
| 172 |
SCREEN_TYPES type; |
| 173 |
SCREEN_TYPES want_type; |
| 174 |
} desktop; |
| 175 |
#if C_OPENGL |
| 176 |
struct { |
| 177 |
Bitu pitch; |
| 178 |
void * framebuf; |
| 179 |
GLuint buffer; |
| 180 |
GLuint texture; |
| 181 |
GLuint displaylist; |
| 182 |
GLint max_texsize; |
| 183 |
bool bilinear; |
| 184 |
bool packed_pixel; |
| 185 |
bool paletted_texture; |
| 186 |
bool pixel_buffer_object; |
| 187 |
} opengl; |
| 188 |
#endif |
| 189 |
struct { |
| 190 |
SDL_Surface * surface; |
| 191 |
#if (HAVE_DDRAW_H) && defined(WIN32) |
| 192 |
RECT rect; |
| 193 |
#endif |
| 194 |
} blit; |
| 195 |
struct { |
| 196 |
PRIORITY_LEVELS focus; |
| 197 |
PRIORITY_LEVELS nofocus; |
| 198 |
} priority; |
| 199 |
SDL_Rect clip; |
| 200 |
SDL_Surface * surface; |
| 201 |
SDL_Overlay * overlay; |
| 202 |
SDL_cond *cond; |
| 203 |
struct { |
| 204 |
bool autolock; |
| 205 |
bool autoenable; |
| 206 |
bool requestlock; |
| 207 |
bool locked; |
| 208 |
Bitu sensitivity; |
| 209 |
} mouse; |
| 210 |
SDL_Rect updateRects[1024]; |
| 211 |
Bitu num_joysticks; |
| 212 |
#if defined (WIN32) |
| 213 |
bool using_windib; |
| 214 |
// Time when sdl regains focus (alt-tab) in windowed mode |
| 215 |
Bit32u focus_ticks; |
| 216 |
#endif |
| 217 |
// state of alt-keys for certain special handlings |
| 218 |
Bit8u laltstate; |
| 219 |
Bit8u raltstate; |
| 220 |
}; |
| 221 |
|
| 222 |
static SDL_Block sdl; |
| 223 |
|
| 224 |
#define SETMODE_SAVES 1 //Don't set Video Mode if nothing changes. |
| 225 |
#define SETMODE_SAVES_CLEAR 1 //Clear the screen, when the Video Mode is reused |
| 226 |
SDL_Surface* SDL_SetVideoMode_Wrap(int width,int height,int bpp,Bit32u flags){ |
| 227 |
#if SETMODE_SAVES |
| 228 |
static int i_height = 0; |
| 229 |
static int i_width = 0; |
| 230 |
static int i_bpp = 0; |
| 231 |
static Bit32u i_flags = 0; |
| 232 |
if (sdl.surface != NULL && height == i_height && width == i_width && bpp == i_bpp && flags == i_flags) { |
| 233 |
// I don't see a difference, so disabled for now, as the code isn't finished either |
| 234 |
#if SETMODE_SAVES_CLEAR |
| 235 |
//TODO clear it. |
| 236 |
#if C_OPENGL |
| 237 |
if ((flags & SDL_OPENGL)==0) |
| 238 |
SDL_FillRect(sdl.surface,NULL,SDL_MapRGB(sdl.surface->format,0,0,0)); |
| 239 |
else { |
| 240 |
glClearColor (0.0, 0.0, 0.0, 1.0); |
| 241 |
glClear(GL_COLOR_BUFFER_BIT); |
| 242 |
SDL_GL_SwapBuffers(); |
| 243 |
} |
| 244 |
#else //C_OPENGL |
| 245 |
SDL_FillRect(sdl.surface,NULL,SDL_MapRGB(sdl.surface->format,0,0,0)); |
| 246 |
#endif //C_OPENGL |
| 247 |
#endif //SETMODE_SAVES_CLEAR |
| 248 |
return sdl.surface; |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
#ifdef WIN32 |
| 253 |
//SDL seems to crash if we are in OpenGL mode currently and change to exactly the same size without OpenGL. |
| 254 |
//This happens when DOSBox is in textmode with aspect=true and output=opengl and the mapper is started. |
| 255 |
//The easiest solution is to change the size. The mapper doesn't care. (PART PXX) |
| 256 |
|
| 257 |
//Also we have to switch back to windowed mode first, as else it may crash as well. |
| 258 |
//Bug: we end up with a locked mouse cursor, but at least that beats crashing. (output=opengl,aspect=true,fullscreen=true) |
| 259 |
if((i_flags&SDL_OPENGL) && !(flags&SDL_OPENGL) && (i_flags&SDL_FULLSCREEN) && !(flags&SDL_FULLSCREEN)){ |
| 260 |
GFX_SwitchFullScreen(); |
| 261 |
return SDL_SetVideoMode_Wrap(width,height,bpp,flags); |
| 262 |
} |
| 263 |
|
| 264 |
//PXX |
| 265 |
if ((i_flags&SDL_OPENGL) && !(flags&SDL_OPENGL) && height==i_height && width==i_width && height==480) { |
| 266 |
height++; |
| 267 |
} |
| 268 |
#endif //WIN32 |
| 269 |
#endif //SETMODE_SAVES |
| 270 |
SDL_Surface* s = SDL_SetVideoMode(width,height,bpp,flags); |
| 271 |
#if SETMODE_SAVES |
| 272 |
if (s == NULL) return s; //Only store when successful |
| 273 |
i_height = height; |
| 274 |
i_width = width; |
| 275 |
i_bpp = bpp; |
| 276 |
i_flags = flags; |
| 277 |
#endif |
| 278 |
return s; |
| 279 |
} |
| 280 |
|
| 281 |
extern const char* RunningProgram; |
| 282 |
extern bool CPU_CycleAutoAdjust; |
| 283 |
//Globals for keyboard initialisation |
| 284 |
bool startup_state_numlock=false; |
| 285 |
bool startup_state_capslock=false; |
| 286 |
|
| 287 |
void GFX_SetTitle(Bit32s cycles,Bits frameskip,bool paused){ |
| 288 |
char title[200]={0}; |
| 289 |
static Bit32s internal_cycles=0; |
| 290 |
static Bits internal_frameskip=0; |
| 291 |
if(cycles != -1) internal_cycles = cycles; |
| 292 |
if(frameskip != -1) internal_frameskip = frameskip; |
| 293 |
if(CPU_CycleAutoAdjust) { |
| 294 |
sprintf(title,"DOSBox %s, Cpu speed: max %3d%% cycles, Frameskip %2d, Program: %8s",VERSION,internal_cycles,internal_frameskip,RunningProgram); |
| 295 |
} else { |
| 296 |
sprintf(title,"DOSBox %s, Cpu speed: %8d cycles, Frameskip %2d, Program: %8s",VERSION,internal_cycles,internal_frameskip,RunningProgram); |
| 297 |
} |
| 298 |
|
| 299 |
if(paused) strcat(title," PAUSED"); |
| 300 |
SDL_WM_SetCaption(title,VERSION); |
| 301 |
} |
| 302 |
|
| 303 |
static unsigned char logo[32*32*4]= { |
| 304 |
#include "dosbox_logo.h" |
| 305 |
}; |
| 306 |
static void GFX_SetIcon() { |
| 307 |
#if !defined(MACOSX) |
| 308 |
/* Set Icon (must be done before any sdl_setvideomode call) */ |
| 309 |
/* But don't set it on OS X, as we use a nicer external icon there. */ |
| 310 |
/* Made into a separate call, so it can be called again when we restart the graphics output on win32 */ |
| 311 |
#ifdef WORDS_BIGENDIAN |
| 312 |
SDL_Surface* logos= SDL_CreateRGBSurfaceFrom((void*)logo,32,32,32,128,0xff000000,0x00ff0000,0x0000ff00,0); |
| 313 |
#else |
| 314 |
SDL_Surface* logos= SDL_CreateRGBSurfaceFrom((void*)logo,32,32,32,128,0x000000ff,0x0000ff00,0x00ff0000,0); |
| 315 |
#endif |
| 316 |
SDL_WM_SetIcon(logos,NULL); |
| 317 |
#endif |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
static void KillSwitch(bool pressed) { |
| 322 |
if (!pressed) |
| 323 |
return; |
| 324 |
throw 1; |
| 325 |
} |
| 326 |
|
| 327 |
static void PauseDOSBox(bool pressed) { |
| 328 |
if (!pressed) |
| 329 |
return; |
| 330 |
GFX_SetTitle(-1,-1,true); |
| 331 |
bool paused = true; |
| 332 |
KEYBOARD_ClrBuffer(); |
| 333 |
SDL_Delay(500); |
| 334 |
SDL_Event event; |
| 335 |
while (SDL_PollEvent(&event)) { |
| 336 |
// flush event queue. |
| 337 |
} |
| 338 |
|
| 339 |
while (paused) { |
| 340 |
SDL_WaitEvent(&event); // since we're not polling, cpu usage drops to 0. |
| 341 |
switch (event.type) { |
| 342 |
|
| 343 |
case SDL_QUIT: KillSwitch(true); break; |
| 344 |
case SDL_KEYDOWN: // Must use Pause/Break Key to resume. |
| 345 |
case SDL_KEYUP: |
| 346 |
if(event.key.keysym.sym == SDLK_PAUSE) { |
| 347 |
|
| 348 |
paused = false; |
| 349 |
GFX_SetTitle(-1,-1,false); |
| 350 |
break; |
| 351 |
} |
| 352 |
#if defined (MACOSX) |
| 353 |
if (event.key.keysym.sym == SDLK_q && (event.key.keysym.mod == KMOD_RMETA || event.key.keysym.mod == KMOD_LMETA) ) { |
| 354 |
/* On macs, all aps exit when pressing cmd-q */ |
| 355 |
KillSwitch(true); |
| 356 |
break; |
| 357 |
} |
| 358 |
#endif |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
#if defined (WIN32) |
| 364 |
bool GFX_SDLUsingWinDIB(void) { |
| 365 |
return sdl.using_windib; |
| 366 |
} |
| 367 |
#endif |
| 368 |
|
| 369 |
/* Reset the screen with current values in the sdl structure */ |
| 370 |
Bitu GFX_GetBestMode(Bitu flags) { |
| 371 |
Bitu testbpp,gotbpp; |
| 372 |
switch (sdl.desktop.want_type) { |
| 373 |
case SCREEN_SURFACE: |
| 374 |
check_surface: |
| 375 |
flags &= ~GFX_LOVE_8; //Disable love for 8bpp modes |
| 376 |
/* Check if we can satisfy the depth it loves */ |
| 377 |
if (flags & GFX_LOVE_8) testbpp=8; |
| 378 |
else if (flags & GFX_LOVE_15) testbpp=15; |
| 379 |
else if (flags & GFX_LOVE_16) testbpp=16; |
| 380 |
else if (flags & GFX_LOVE_32) testbpp=32; |
| 381 |
else testbpp=0; |
| 382 |
#if (HAVE_DDRAW_H) && defined(WIN32) |
| 383 |
check_gotbpp: |
| 384 |
#endif |
| 385 |
if (sdl.desktop.fullscreen) gotbpp=SDL_VideoModeOK(640,480,testbpp,SDL_FULLSCREEN|SDL_HWSURFACE|SDL_HWPALETTE); |
| 386 |
else gotbpp=sdl.desktop.bpp; |
| 387 |
/* If we can't get our favorite mode check for another working one */ |
| 388 |
switch (gotbpp) { |
| 389 |
case 8: |
| 390 |
if (flags & GFX_CAN_8) flags&=~(GFX_CAN_15|GFX_CAN_16|GFX_CAN_32); |
| 391 |
break; |
| 392 |
case 15: |
| 393 |
if (flags & GFX_CAN_15) flags&=~(GFX_CAN_8|GFX_CAN_16|GFX_CAN_32); |
| 394 |
break; |
| 395 |
case 16: |
| 396 |
if (flags & GFX_CAN_16) flags&=~(GFX_CAN_8|GFX_CAN_15|GFX_CAN_32); |
| 397 |
break; |
| 398 |
case 24: |
| 399 |
case 32: |
| 400 |
if (flags & GFX_CAN_32) flags&=~(GFX_CAN_8|GFX_CAN_15|GFX_CAN_16); |
| 401 |
break; |
| 402 |
} |
| 403 |
flags |= GFX_CAN_RANDOM; |
| 404 |
break; |
| 405 |
#if (HAVE_DDRAW_H) && defined(WIN32) |
| 406 |
case SCREEN_SURFACE_DDRAW: |
| 407 |
if (!(flags&(GFX_CAN_15|GFX_CAN_16|GFX_CAN_32))) goto check_surface; |
| 408 |
if (flags & GFX_LOVE_15) testbpp=15; |
| 409 |
else if (flags & GFX_LOVE_16) testbpp=16; |
| 410 |
else if (flags & GFX_LOVE_32) testbpp=32; |
| 411 |
else testbpp=0; |
| 412 |
flags|=GFX_SCALING; |
| 413 |
goto check_gotbpp; |
| 414 |
#endif |
| 415 |
case SCREEN_OVERLAY: |
| 416 |
//We only accept 32bit output from the scalers here |
| 417 |
//Can't handle true color inputs |
| 418 |
if (flags & GFX_RGBONLY || !(flags&GFX_CAN_32)) goto check_surface; |
| 419 |
flags|=GFX_SCALING; |
| 420 |
flags&=~(GFX_CAN_8|GFX_CAN_15|GFX_CAN_16); |
| 421 |
break; |
| 422 |
#if C_OPENGL |
| 423 |
case SCREEN_OPENGL: |
| 424 |
//We only accept 32bit output from the scalers here |
| 425 |
if (!(flags&GFX_CAN_32)) goto check_surface; |
| 426 |
flags|=GFX_SCALING; |
| 427 |
flags&=~(GFX_CAN_8|GFX_CAN_15|GFX_CAN_16); |
| 428 |
break; |
| 429 |
#endif |
| 430 |
default: |
| 431 |
goto check_surface; |
| 432 |
break; |
| 433 |
} |
| 434 |
return flags; |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
void GFX_ResetScreen(void) { |
| 439 |
GFX_Stop(); |
| 440 |
if (sdl.draw.callback) |
| 441 |
(sdl.draw.callback)( GFX_CallBackReset ); |
| 442 |
GFX_Start(); |
| 443 |
CPU_Reset_AutoAdjust(); |
| 444 |
} |
| 445 |
|
| 446 |
static int int_log2 (int val) { |
| 447 |
int log = 0; |
| 448 |
while ((val >>= 1) != 0) |
| 449 |
log++; |
| 450 |
return log; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
static SDL_Surface * GFX_SetupSurfaceScaled(Bit32u sdl_flags, Bit32u bpp) { |
| 455 |
Bit16u fixedWidth; |
| 456 |
Bit16u fixedHeight; |
| 457 |
|
| 458 |
if (sdl.desktop.fullscreen) { |
| 459 |
fixedWidth = sdl.desktop.full.fixed ? sdl.desktop.full.width : 0; |
| 460 |
fixedHeight = sdl.desktop.full.fixed ? sdl.desktop.full.height : 0; |
| 461 |
sdl_flags |= SDL_FULLSCREEN|SDL_HWSURFACE; |
| 462 |
} else { |
| 463 |
fixedWidth = sdl.desktop.window.width; |
| 464 |
fixedHeight = sdl.desktop.window.height; |
| 465 |
sdl_flags |= SDL_HWSURFACE; |
| 466 |
} |
| 467 |
if (fixedWidth && fixedHeight) { |
| 468 |
double ratio_w=(double)fixedWidth/(sdl.draw.width*sdl.draw.scalex); |
| 469 |
double ratio_h=(double)fixedHeight/(sdl.draw.height*sdl.draw.scaley); |
| 470 |
if ( ratio_w < ratio_h) { |
| 471 |
sdl.clip.w=fixedWidth; |
| 472 |
sdl.clip.h=(Bit16u)(sdl.draw.height*sdl.draw.scaley*ratio_w + 0.1); //possible rounding issues |
| 473 |
} else { |
| 474 |
/* |
| 475 |
* The 0.4 is there to correct for rounding issues. |
| 476 |
* (partly caused by the rounding issues fix in RENDER_SetSize) |
| 477 |
*/ |
| 478 |
sdl.clip.w=(Bit16u)(sdl.draw.width*sdl.draw.scalex*ratio_h + 0.4); |
| 479 |
sdl.clip.h=(Bit16u)fixedHeight; |
| 480 |
} |
| 481 |
if (sdl.desktop.fullscreen) |
| 482 |
sdl.surface = SDL_SetVideoMode_Wrap(fixedWidth,fixedHeight,bpp,sdl_flags); |
| 483 |
else |
| 484 |
sdl.surface = SDL_SetVideoMode_Wrap(sdl.clip.w,sdl.clip.h,bpp,sdl_flags); |
| 485 |
if (sdl.surface && sdl.surface->flags & SDL_FULLSCREEN) { |
| 486 |
sdl.clip.x=(Sint16)((sdl.surface->w-sdl.clip.w)/2); |
| 487 |
sdl.clip.y=(Sint16)((sdl.surface->h-sdl.clip.h)/2); |
| 488 |
} else { |
| 489 |
sdl.clip.x = 0; |
| 490 |
sdl.clip.y = 0; |
| 491 |
} |
| 492 |
return sdl.surface; |
| 493 |
} else { |
| 494 |
sdl.clip.x=0;sdl.clip.y=0; |
| 495 |
sdl.clip.w=(Bit16u)(sdl.draw.width*sdl.draw.scalex); |
| 496 |
sdl.clip.h=(Bit16u)(sdl.draw.height*sdl.draw.scaley); |
| 497 |
sdl.surface=SDL_SetVideoMode_Wrap(sdl.clip.w,sdl.clip.h,bpp,sdl_flags); |
| 498 |
return sdl.surface; |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
Bitu GFX_SetSize(Bitu width,Bitu height,Bitu flags,double scalex,double scaley,GFX_CallBack_t callback) { |
| 503 |
if (sdl.updating) |
| 504 |
GFX_EndUpdate( 0 ); |
| 505 |
|
| 506 |
sdl.draw.width=width; |
| 507 |
sdl.draw.height=height; |
| 508 |
sdl.draw.callback=callback; |
| 509 |
sdl.draw.scalex=scalex; |
| 510 |
sdl.draw.scaley=scaley; |
| 511 |
|
| 512 |
Bitu bpp=0; |
| 513 |
Bitu retFlags = 0; |
| 514 |
|
| 515 |
if (sdl.blit.surface) { |
| 516 |
SDL_FreeSurface(sdl.blit.surface); |
| 517 |
sdl.blit.surface=0; |
| 518 |
} |
| 519 |
switch (sdl.desktop.want_type) { |
| 520 |
case SCREEN_SURFACE: |
| 521 |
dosurface: |
| 522 |
if (flags & GFX_CAN_8) bpp=8; |
| 523 |
if (flags & GFX_CAN_15) bpp=15; |
| 524 |
if (flags & GFX_CAN_16) bpp=16; |
| 525 |
if (flags & GFX_CAN_32) bpp=32; |
| 526 |
sdl.desktop.type=SCREEN_SURFACE; |
| 527 |
sdl.clip.w=width; |
| 528 |
sdl.clip.h=height; |
| 529 |
if (sdl.desktop.fullscreen) { |
| 530 |
if (sdl.desktop.full.fixed) { |
| 531 |
sdl.clip.x=(Sint16)((sdl.desktop.full.width-width)/2); |
| 532 |
sdl.clip.y=(Sint16)((sdl.desktop.full.height-height)/2); |
| 533 |
sdl.surface=SDL_SetVideoMode_Wrap(sdl.desktop.full.width,sdl.desktop.full.height,bpp, |
| 534 |
SDL_FULLSCREEN | ((flags & GFX_CAN_RANDOM) ? SDL_SWSURFACE : SDL_HWSURFACE) | |
| 535 |
(sdl.desktop.doublebuf ? SDL_DOUBLEBUF|SDL_ASYNCBLIT : 0) | SDL_HWPALETTE); |
| 536 |
if (sdl.surface == NULL) E_Exit("Could not set fullscreen video mode %ix%i-%i: %s",sdl.desktop.full.width,sdl.desktop.full.height,bpp,SDL_GetError()); |
| 537 |
} else { |
| 538 |
sdl.clip.x=0;sdl.clip.y=0; |
| 539 |
sdl.surface=SDL_SetVideoMode_Wrap(width,height,bpp, |
| 540 |
SDL_FULLSCREEN | ((flags & GFX_CAN_RANDOM) ? SDL_SWSURFACE : SDL_HWSURFACE) | |
| 541 |
(sdl.desktop.doublebuf ? SDL_DOUBLEBUF|SDL_ASYNCBLIT : 0)|SDL_HWPALETTE); |
| 542 |
if (sdl.surface == NULL) |
| 543 |
E_Exit("Could not set fullscreen video mode %ix%i-%i: %s",width,height,bpp,SDL_GetError()); |
| 544 |
} |
| 545 |
} else { |
| 546 |
sdl.clip.x=0;sdl.clip.y=0; |
| 547 |
sdl.surface=SDL_SetVideoMode_Wrap(width,height,bpp,(flags & GFX_CAN_RANDOM) ? SDL_SWSURFACE : SDL_HWSURFACE); |
| 548 |
#ifdef WIN32 |
| 549 |
if (sdl.surface == NULL) { |
| 550 |
SDL_QuitSubSystem(SDL_INIT_VIDEO); |
| 551 |
if (!sdl.using_windib) { |
| 552 |
LOG_MSG("Failed to create hardware surface.\nRestarting video subsystem with windib enabled."); |
| 553 |
putenv("SDL_VIDEODRIVER=windib"); |
| 554 |
sdl.using_windib=true; |
| 555 |
} else { |
| 556 |
LOG_MSG("Failed to create hardware surface.\nRestarting video subsystem with directx enabled."); |
| 557 |
putenv("SDL_VIDEODRIVER=directx"); |
| 558 |
sdl.using_windib=false; |
| 559 |
} |
| 560 |
SDL_InitSubSystem(SDL_INIT_VIDEO); |
| 561 |
GFX_SetIcon(); //Set Icon again |
| 562 |
sdl.surface = SDL_SetVideoMode_Wrap(width,height,bpp,SDL_HWSURFACE); |
| 563 |
if(sdl.surface) GFX_SetTitle(-1,-1,false); //refresh title. |
| 564 |
} |
| 565 |
#endif |
| 566 |
if (sdl.surface == NULL) |
| 567 |
E_Exit("Could not set windowed video mode %ix%i-%i: %s",width,height,bpp,SDL_GetError()); |
| 568 |
} |
| 569 |
if (sdl.surface) { |
| 570 |
switch (sdl.surface->format->BitsPerPixel) { |
| 571 |
case 8: |
| 572 |
retFlags = GFX_CAN_8; |
| 573 |
break; |
| 574 |
case 15: |
| 575 |
retFlags = GFX_CAN_15; |
| 576 |
break; |
| 577 |
case 16: |
| 578 |
retFlags = GFX_CAN_16; |
| 579 |
break; |
| 580 |
case 32: |
| 581 |
retFlags = GFX_CAN_32; |
| 582 |
break; |
| 583 |
} |
| 584 |
if (retFlags && (sdl.surface->flags & SDL_HWSURFACE)) |
| 585 |
retFlags |= GFX_HARDWARE; |
| 586 |
if (retFlags && (sdl.surface->flags & SDL_DOUBLEBUF)) { |
| 587 |
sdl.blit.surface=SDL_CreateRGBSurface(SDL_HWSURFACE, |
| 588 |
sdl.draw.width, sdl.draw.height, |
| 589 |
sdl.surface->format->BitsPerPixel, |
| 590 |
sdl.surface->format->Rmask, |
| 591 |
sdl.surface->format->Gmask, |
| 592 |
sdl.surface->format->Bmask, |
| 593 |
0); |
| 594 |
/* If this one fails be ready for some flickering... */ |
| 595 |
} |
| 596 |
} |
| 597 |
break; |
| 598 |
#if (HAVE_DDRAW_H) && defined(WIN32) |
| 599 |
case SCREEN_SURFACE_DDRAW: |
| 600 |
if (flags & GFX_CAN_15) bpp=15; |
| 601 |
if (flags & GFX_CAN_16) bpp=16; |
| 602 |
if (flags & GFX_CAN_32) bpp=32; |
| 603 |
if (!GFX_SetupSurfaceScaled((sdl.desktop.doublebuf && sdl.desktop.fullscreen) ? SDL_DOUBLEBUF : 0,bpp)) goto dosurface; |
| 604 |
sdl.blit.rect.top=sdl.clip.y; |
| 605 |
sdl.blit.rect.left=sdl.clip.x; |
| 606 |
sdl.blit.rect.right=sdl.clip.x+sdl.clip.w; |
| 607 |
sdl.blit.rect.bottom=sdl.clip.y+sdl.clip.h; |
| 608 |
sdl.blit.surface=SDL_CreateRGBSurface(SDL_HWSURFACE,sdl.draw.width,sdl.draw.height, |
| 609 |
sdl.surface->format->BitsPerPixel, |
| 610 |
sdl.surface->format->Rmask, |
| 611 |
sdl.surface->format->Gmask, |
| 612 |
sdl.surface->format->Bmask, |
| 613 |
0); |
| 614 |
if (!sdl.blit.surface || (!sdl.blit.surface->flags&SDL_HWSURFACE)) { |
| 615 |
if (sdl.blit.surface) { |
| 616 |
SDL_FreeSurface(sdl.blit.surface); |
| 617 |
sdl.blit.surface=0; |
| 618 |
} |
| 619 |
LOG_MSG("Failed to create ddraw surface, back to normal surface."); |
| 620 |
goto dosurface; |
| 621 |
} |
| 622 |
switch (sdl.surface->format->BitsPerPixel) { |
| 623 |
case 15: |
| 624 |
retFlags = GFX_CAN_15 | GFX_SCALING | GFX_HARDWARE; |
| 625 |
break; |
| 626 |
case 16: |
| 627 |
retFlags = GFX_CAN_16 | GFX_SCALING | GFX_HARDWARE; |
| 628 |
break; |
| 629 |
case 32: |
| 630 |
retFlags = GFX_CAN_32 | GFX_SCALING | GFX_HARDWARE; |
| 631 |
break; |
| 632 |
} |
| 633 |
sdl.desktop.type=SCREEN_SURFACE_DDRAW; |
| 634 |
break; |
| 635 |
#endif |
| 636 |
case SCREEN_OVERLAY: |
| 637 |
if (sdl.overlay) { |
| 638 |
SDL_FreeYUVOverlay(sdl.overlay); |
| 639 |
sdl.overlay=0; |
| 640 |
} |
| 641 |
if (!(flags&GFX_CAN_32) || (flags & GFX_RGBONLY)) goto dosurface; |
| 642 |
if (!GFX_SetupSurfaceScaled(0,0)) goto dosurface; |
| 643 |
sdl.overlay=SDL_CreateYUVOverlay(width*2,height,SDL_UYVY_OVERLAY,sdl.surface); |
| 644 |
if (!sdl.overlay) { |
| 645 |
LOG_MSG("SDL:Failed to create overlay, switching back to surface"); |
| 646 |
goto dosurface; |
| 647 |
} |
| 648 |
sdl.desktop.type=SCREEN_OVERLAY; |
| 649 |
retFlags = GFX_CAN_32 | GFX_SCALING | GFX_HARDWARE; |
| 650 |
break; |
| 651 |
#if C_OPENGL |
| 652 |
case SCREEN_OPENGL: |
| 653 |
{ |
| 654 |
if (sdl.opengl.pixel_buffer_object) { |
| 655 |
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0); |
| 656 |
if (sdl.opengl.buffer) glDeleteBuffersARB(1, &sdl.opengl.buffer); |
| 657 |
} else if (sdl.opengl.framebuf) { |
| 658 |
free(sdl.opengl.framebuf); |
| 659 |
} |
| 660 |
sdl.opengl.framebuf=0; |
| 661 |
if (!(flags&GFX_CAN_32)) goto dosurface; |
| 662 |
int texsize=2 << int_log2(width > height ? width : height); |
| 663 |
if (texsize>sdl.opengl.max_texsize) { |
| 664 |
LOG_MSG("SDL:OPENGL:No support for texturesize of %d, falling back to surface",texsize); |
| 665 |
goto dosurface; |
| 666 |
} |
| 667 |
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 668 |
#if SDL_VERSION_ATLEAST(1, 2, 11) |
| 669 |
SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 ); |
| 670 |
#endif |
| 671 |
GFX_SetupSurfaceScaled(SDL_OPENGL,0); |
| 672 |
if (!sdl.surface || sdl.surface->format->BitsPerPixel<15) { |
| 673 |
LOG_MSG("SDL:OPENGL:Can't open drawing surface, are you running in 16bpp(or higher) mode?"); |
| 674 |
goto dosurface; |
| 675 |
} |
| 676 |
/* Create the texture and display list */ |
| 677 |
if (sdl.opengl.pixel_buffer_object) { |
| 678 |
glGenBuffersARB(1, &sdl.opengl.buffer); |
| 679 |
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, sdl.opengl.buffer); |
| 680 |
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, width*height*4, NULL, GL_STREAM_DRAW_ARB); |
| 681 |
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0); |
| 682 |
} else { |
| 683 |
sdl.opengl.framebuf=malloc(width*height*4); //32 bit color |
| 684 |
} |
| 685 |
sdl.opengl.pitch=width*4; |
| 686 |
// glViewport(sdl.clip.x,sdl.clip.y,sdl.clip.w,sdl.clip.h); |
| 687 |
if(sdl.clip.x ==0 && sdl.clip.y ==0 && sdl.desktop.fullscreen && !sdl.desktop.full.fixed && (sdl.clip.w != sdl.surface->w || sdl.clip.h != sdl.surface->h)) { |
| 688 |
// LOG_MSG("attempting to fix the centering to %d %d %d %d",(sdl.surface->w-sdl.clip.w)/2,(sdl.surface->h-sdl.clip.h)/2,sdl.clip.w,sdl.clip.h); |
| 689 |
glViewport((sdl.surface->w-sdl.clip.w)/2,(sdl.surface->h-sdl.clip.h)/2,sdl.clip.w,sdl.clip.h); |
| 690 |
} |
| 691 |
else { |
| 692 |
glViewport(sdl.clip.x,sdl.clip.y,sdl.clip.w,sdl.clip.h); |
| 693 |
} |
| 694 |
glMatrixMode (GL_PROJECTION); |
| 695 |
glDeleteTextures(1,&sdl.opengl.texture); |
| 696 |
glGenTextures(1,&sdl.opengl.texture); |
| 697 |
glBindTexture(GL_TEXTURE_2D,sdl.opengl.texture); |
| 698 |
// No borders |
| 699 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); |
| 700 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
| 701 |
if (sdl.opengl.bilinear) { |
| 702 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 703 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 704 |
} else { |
| 705 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 706 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 707 |
} |
| 708 |
|
| 709 |
Bit8u* emptytex = new Bit8u[texsize * texsize * 4]; |
| 710 |
memset((void*) emptytex, 0, texsize * texsize * 4); |
| 711 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texsize, texsize, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, (const GLvoid*)emptytex); |
| 712 |
delete [] emptytex; |
| 713 |
|
| 714 |
glClearColor (0.0, 0.0, 0.0, 1.0); |
| 715 |
glClear(GL_COLOR_BUFFER_BIT); |
| 716 |
SDL_GL_SwapBuffers(); |
| 717 |
glClear(GL_COLOR_BUFFER_BIT); |
| 718 |
glShadeModel (GL_FLAT); |
| 719 |
glDisable (GL_DEPTH_TEST); |
| 720 |
glDisable (GL_LIGHTING); |
| 721 |
glDisable(GL_CULL_FACE); |
| 722 |
glEnable(GL_TEXTURE_2D); |
| 723 |
glMatrixMode (GL_MODELVIEW); |
| 724 |
glLoadIdentity (); |
| 725 |
|
| 726 |
GLfloat tex_width=((GLfloat)(width)/(GLfloat)texsize); |
| 727 |
GLfloat tex_height=((GLfloat)(height)/(GLfloat)texsize); |
| 728 |
|
| 729 |
if (glIsList(sdl.opengl.displaylist)) glDeleteLists(sdl.opengl.displaylist, 1); |
| 730 |
sdl.opengl.displaylist = glGenLists(1); |
| 731 |
glNewList(sdl.opengl.displaylist, GL_COMPILE); |
| 732 |
glBindTexture(GL_TEXTURE_2D, sdl.opengl.texture); |
| 733 |
glBegin(GL_QUADS); |
| 734 |
// lower left |
| 735 |
glTexCoord2f(0,tex_height); glVertex2f(-1.0f,-1.0f); |
| 736 |
// lower right |
| 737 |
glTexCoord2f(tex_width,tex_height); glVertex2f(1.0f, -1.0f); |
| 738 |
// upper right |
| 739 |
glTexCoord2f(tex_width,0); glVertex2f(1.0f, 1.0f); |
| 740 |
// upper left |
| 741 |
glTexCoord2f(0,0); glVertex2f(-1.0f, 1.0f); |
| 742 |
glEnd(); |
| 743 |
glEndList(); |
| 744 |
sdl.desktop.type=SCREEN_OPENGL; |
| 745 |
retFlags = GFX_CAN_32 | GFX_SCALING; |
| 746 |
if (sdl.opengl.pixel_buffer_object) |
| 747 |
retFlags |= GFX_HARDWARE; |
| 748 |
break; |
| 749 |
}//OPENGL |
| 750 |
#endif //C_OPENGL |
| 751 |
default: |
| 752 |
goto dosurface; |
| 753 |
break; |
| 754 |
}//CASE |
| 755 |
if (retFlags) |
| 756 |
GFX_Start(); |
| 757 |
if (!sdl.mouse.autoenable) SDL_ShowCursor(sdl.mouse.autolock?SDL_DISABLE:SDL_ENABLE); |
| 758 |
return retFlags; |
| 759 |
} |
| 760 |
|
| 761 |
void GFX_CaptureMouse(void) { |
| 762 |
sdl.mouse.locked=!sdl.mouse.locked; |
| 763 |
if (sdl.mouse.locked) { |
| 764 |
SDL_WM_GrabInput(SDL_GRAB_ON); |
| 765 |
SDL_ShowCursor(SDL_DISABLE); |
| 766 |
} else { |
| 767 |
SDL_WM_GrabInput(SDL_GRAB_OFF); |
| 768 |
if (sdl.mouse.autoenable || !sdl.mouse.autolock) SDL_ShowCursor(SDL_ENABLE); |
| 769 |
} |
| 770 |
mouselocked=sdl.mouse.locked; |
| 771 |
} |
| 772 |
|
| 773 |
bool mouselocked; //Global variable for mapper |
| 774 |
static void CaptureMouse(bool pressed) { |
| 775 |
if (!pressed) |
| 776 |
return; |
| 777 |
GFX_CaptureMouse(); |
| 778 |
} |
| 779 |
|
| 780 |
void GFX_SwitchFullScreen(void) { |
| 781 |
sdl.desktop.fullscreen=!sdl.desktop.fullscreen; |
| 782 |
if (sdl.desktop.fullscreen) { |
| 783 |
if (!sdl.mouse.locked) GFX_CaptureMouse(); |
| 784 |
} else { |
| 785 |
if (sdl.mouse.locked) GFX_CaptureMouse(); |
| 786 |
} |
| 787 |
GFX_ResetScreen(); |
| 788 |
} |
| 789 |
|
| 790 |
static void SwitchFullScreen(bool pressed) { |
| 791 |
if (!pressed) |
| 792 |
return; |
| 793 |
GFX_SwitchFullScreen(); |
| 794 |
} |
| 795 |
|
| 796 |
|
| 797 |
bool GFX_StartUpdate(Bit8u * & pixels,Bitu & pitch) { |
| 798 |
if (!sdl.active || sdl.updating) |
| 799 |
return false; |
| 800 |
switch (sdl.desktop.type) { |
| 801 |
case SCREEN_SURFACE: |
| 802 |
if (sdl.blit.surface) { |
| 803 |
if (SDL_MUSTLOCK(sdl.blit.surface) && SDL_LockSurface(sdl.blit.surface)) |
| 804 |
return false; |
| 805 |
pixels=(Bit8u *)sdl.blit.surface->pixels; |
| 806 |
pitch=sdl.blit.surface->pitch; |
| 807 |
} else { |
| 808 |
if (SDL_MUSTLOCK(sdl.surface) && SDL_LockSurface(sdl.surface)) |
| 809 |
return false; |
| 810 |
pixels=(Bit8u *)sdl.surface->pixels; |
| 811 |
pixels+=sdl.clip.y*sdl.surface->pitch; |
| 812 |
pixels+=sdl.clip.x*sdl.surface->format->BytesPerPixel; |
| 813 |
pitch=sdl.surface->pitch; |
| 814 |
} |
| 815 |
sdl.updating=true; |
| 816 |
return true; |
| 817 |
#if (HAVE_DDRAW_H) && defined(WIN32) |
| 818 |
case SCREEN_SURFACE_DDRAW: |
| 819 |
if (SDL_LockSurface(sdl.blit.surface)) { |
| 820 |
// LOG_MSG("SDL Lock failed"); |
| 821 |
return false; |
| 822 |
} |
| 823 |
pixels=(Bit8u *)sdl.blit.surface->pixels; |
| 824 |
pitch=sdl.blit.surface->pitch; |
| 825 |
sdl.updating=true; |
| 826 |
return true; |
| 827 |
#endif |
| 828 |
case SCREEN_OVERLAY: |
| 829 |
if (SDL_LockYUVOverlay(sdl.overlay)) return false; |
| 830 |
pixels=(Bit8u *)*(sdl.overlay->pixels); |
| 831 |
pitch=*(sdl.overlay->pitches); |
| 832 |
sdl.updating=true; |
| 833 |
return true; |
| 834 |
#if C_OPENGL |
| 835 |
case SCREEN_OPENGL: |
| 836 |
if(sdl.opengl.pixel_buffer_object) { |
| 837 |
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, sdl.opengl.buffer); |
| 838 |
pixels=(Bit8u *)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY); |
| 839 |
} else |
| 840 |
pixels=(Bit8u *)sdl.opengl.framebuf; |
| 841 |
pitch=sdl.opengl.pitch; |
| 842 |
sdl.updating=true; |
| 843 |
return true; |
| 844 |
#endif |
| 845 |
default: |
| 846 |
break; |
| 847 |
} |
| 848 |
return false; |
| 849 |
} |
| 850 |
|
| 851 |
|
| 852 |
void GFX_EndUpdate( const Bit16u *changedLines ) { |
| 853 |
#if (HAVE_DDRAW_H) && defined(WIN32) |
| 854 |
int ret; |
| 855 |
#endif |
| 856 |
if (!sdl.updating) |
| 857 |
return; |
| 858 |
sdl.updating=false; |
| 859 |
switch (sdl.desktop.type) { |
| 860 |
case SCREEN_SURFACE: |
| 861 |
if (SDL_MUSTLOCK(sdl.surface)) { |
| 862 |
if (sdl.blit.surface) { |
| 863 |
SDL_UnlockSurface(sdl.blit.surface); |
| 864 |
int Blit = SDL_BlitSurface( sdl.blit.surface, 0, sdl.surface, &sdl.clip ); |
| 865 |
LOG(LOG_MISC,LOG_WARN)("BlitSurface returned %d",Blit); |
| 866 |
} else { |
| 867 |
SDL_UnlockSurface(sdl.surface); |
| 868 |
} |
| 869 |
SDL_Flip(sdl.surface); |
| 870 |
} else if (changedLines) { |
| 871 |
Bitu y = 0, index = 0, rectCount = 0; |
| 872 |
while (y < sdl.draw.height) { |
| 873 |
if (!(index & 1)) { |
| 874 |
y += changedLines[index]; |
| 875 |
} else { |
| 876 |
SDL_Rect *rect = &sdl.updateRects[rectCount++]; |
| 877 |
rect->x = sdl.clip.x; |
| 878 |
rect->y = sdl.clip.y + y; |
| 879 |
rect->w = (Bit16u)sdl.draw.width; |
| 880 |
rect->h = changedLines[index]; |
| 881 |
#if 0 |
| 882 |
if (rect->h + rect->y > sdl.surface->h) { |
| 883 |
LOG_MSG("WTF %d + %d >%d",rect->h,rect->y,sdl.surface->h); |
| 884 |
} |
| 885 |
#endif |
| 886 |
y += changedLines[index]; |
| 887 |
} |
| 888 |
index++; |
| 889 |
} |
| 890 |
if (rectCount) |
| 891 |
SDL_UpdateRects( sdl.surface, rectCount, sdl.updateRects ); |
| 892 |
} |
| 893 |
break; |
| 894 |
#if (HAVE_DDRAW_H) && defined(WIN32) |
| 895 |
case SCREEN_SURFACE_DDRAW: |
| 896 |
SDL_UnlockSurface(sdl.blit.surface); |
| 897 |
ret=IDirectDrawSurface3_Blt( |
| 898 |
sdl.surface->hwdata->dd_writebuf,&sdl.blit.rect, |
| 899 |
sdl.blit.surface->hwdata->dd_surface,0, |
| 900 |
DDBLT_WAIT, NULL); |
| 901 |
switch (ret) { |
| 902 |
case DD_OK: |
| 903 |
break; |
| 904 |
case DDERR_SURFACELOST: |
| 905 |
IDirectDrawSurface3_Restore(sdl.blit.surface->hwdata->dd_surface); |
| 906 |
IDirectDrawSurface3_Restore(sdl.surface->hwdata->dd_surface); |
| 907 |
break; |
| 908 |
default: |
| 909 |
LOG_MSG("DDRAW:Failed to blit, error %X",ret); |
| 910 |
} |
| 911 |
SDL_Flip(sdl.surface); |
| 912 |
break; |
| 913 |
#endif |
| 914 |
case SCREEN_OVERLAY: |
| 915 |
SDL_UnlockYUVOverlay(sdl.overlay); |
| 916 |
SDL_DisplayYUVOverlay(sdl.overlay,&sdl.clip); |
| 917 |
break; |
| 918 |
#if C_OPENGL |
| 919 |
case SCREEN_OPENGL: |
| 920 |
// Clear drawing area. Some drivers (on Linux) have more than 2 buffers and the screen might |
| 921 |
// be dirty because of other programs. |
| 922 |
glClearColor (0.0, 0.0, 0.0, 1.0); |
| 923 |
glClear(GL_COLOR_BUFFER_BIT); |
| 924 |
if (sdl.opengl.pixel_buffer_object) { |
| 925 |
glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT); |
| 926 |
glBindTexture(GL_TEXTURE_2D, sdl.opengl.texture); |
| 927 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, |
| 928 |
sdl.draw.width, sdl.draw.height, GL_BGRA_EXT, |
| 929 |
GL_UNSIGNED_INT_8_8_8_8_REV, 0); |
| 930 |
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0); |
| 931 |
glCallList(sdl.opengl.displaylist); |
| 932 |
SDL_GL_SwapBuffers(); |
| 933 |
} else if (changedLines) { |
| 934 |
Bitu y = 0, index = 0; |
| 935 |
glBindTexture(GL_TEXTURE_2D, sdl.opengl.texture); |
| 936 |
while (y < sdl.draw.height) { |
| 937 |
if (!(index & 1)) { |
| 938 |
y += changedLines[index]; |
| 939 |
} else { |
| 940 |
Bit8u *pixels = (Bit8u *)sdl.opengl.framebuf + y * sdl.opengl.pitch; |
| 941 |
Bitu height = changedLines[index]; |
| 942 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, y, |
| 943 |
sdl.draw.width, height, GL_BGRA_EXT, |
| 944 |
GL_UNSIGNED_INT_8_8_8_8_REV, pixels ); |
| 945 |
y += height; |
| 946 |
} |
| 947 |
index++; |
| 948 |
} |
| 949 |
glCallList(sdl.opengl.displaylist); |
| 950 |
SDL_GL_SwapBuffers(); |
| 951 |
} |
| 952 |
break; |
| 953 |
#endif |
| 954 |
default: |
| 955 |
break; |
| 956 |
} |
| 957 |
} |
| 958 |
|
| 959 |
|
| 960 |
void GFX_SetPalette(Bitu start,Bitu count,GFX_PalEntry * entries) { |
| 961 |
/* I should probably not change the GFX_PalEntry :) */ |
| 962 |
if (sdl.surface->flags & SDL_HWPALETTE) { |
| 963 |
if (!SDL_SetPalette(sdl.surface,SDL_PHYSPAL,(SDL_Color *)entries,start,count)) { |
| 964 |
E_Exit("SDL:Can't set palette"); |
| 965 |
} |
| 966 |
} else { |
| 967 |
if (!SDL_SetPalette(sdl.surface,SDL_LOGPAL,(SDL_Color *)entries,start,count)) { |
| 968 |
E_Exit("SDL:Can't set palette"); |
| 969 |
} |
| 970 |
} |
| 971 |
} |
| 972 |
|
| 973 |
Bitu GFX_GetRGB(Bit8u red,Bit8u green,Bit8u blue) { |
| 974 |
switch (sdl.desktop.type) { |
| 975 |
case SCREEN_SURFACE: |
| 976 |
case SCREEN_SURFACE_DDRAW: |
| 977 |
return SDL_MapRGB(sdl.surface->format,red,green,blue); |
| 978 |
case SCREEN_OVERLAY: |
| 979 |
{ |
| 980 |
Bit8u y = ( 9797*(red) + 19237*(green) + 3734*(blue) ) >> 15; |
| 981 |
Bit8u u = (18492*((blue)-(y)) >> 15) + 128; |
| 982 |
Bit8u v = (23372*((red)-(y)) >> 15) + 128; |
| 983 |
#ifdef WORDS_BIGENDIAN |
| 984 |
return (y << 0) | (v << 8) | (y << 16) | (u << 24); |
| 985 |
#else |
| 986 |
return (u << 0) | (y << 8) | (v << 16) | (y << 24); |
| 987 |
#endif |
| 988 |
} |
| 989 |
case SCREEN_OPENGL: |
| 990 |
// return ((red << 0) | (green << 8) | (blue << 16)) | (255 << 24); |
| 991 |
//USE BGRA |
| 992 |
return ((blue << 0) | (green << 8) | (red << 16)) | (255 << 24); |
| 993 |
} |
| 994 |
return 0; |
| 995 |
} |
| 996 |
|
| 997 |
void GFX_Stop() { |
| 998 |
if (sdl.updating) |
| 999 |
GFX_EndUpdate( 0 ); |
| 1000 |
sdl.active=false; |
| 1001 |
} |
| 1002 |
|
| 1003 |
void GFX_Start() { |
| 1004 |
sdl.active=true; |
| 1005 |
} |
| 1006 |
|
| 1007 |
static void GUI_ShutDown(Section * /*sec*/) { |
| 1008 |
GFX_Stop(); |
| 1009 |
if (sdl.draw.callback) (sdl.draw.callback)( GFX_CallBackStop ); |
| 1010 |
if (sdl.mouse.locked) GFX_CaptureMouse(); |
| 1011 |
if (sdl.desktop.fullscreen) GFX_SwitchFullScreen(); |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
static void SetPriority(PRIORITY_LEVELS level) { |
| 1016 |
|
| 1017 |
#if C_SET_PRIORITY |
| 1018 |
// Do nothing if priorties are not the same and not root, else the highest |
| 1019 |
// priority can not be set as users can only lower priority (not restore it) |
| 1020 |
|
| 1021 |
if((sdl.priority.focus != sdl.priority.nofocus ) && |
| 1022 |
(getuid()!=0) ) return; |
| 1023 |
|
| 1024 |
#endif |
| 1025 |
switch (level) { |
| 1026 |
#ifdef WIN32 |
| 1027 |
case PRIORITY_LEVEL_PAUSE: // if DOSBox is paused, assume idle priority |
| 1028 |
case PRIORITY_LEVEL_LOWEST: |
| 1029 |
SetPriorityClass(GetCurrentProcess(),IDLE_PRIORITY_CLASS); |
| 1030 |
break; |
| 1031 |
case PRIORITY_LEVEL_LOWER: |
| 1032 |
SetPriorityClass(GetCurrentProcess(),BELOW_NORMAL_PRIORITY_CLASS); |
| 1033 |
break; |
| 1034 |
case PRIORITY_LEVEL_NORMAL: |
| 1035 |
SetPriorityClass(GetCurrentProcess(),NORMAL_PRIORITY_CLASS); |
| 1036 |
break; |
| 1037 |
case PRIORITY_LEVEL_HIGHER: |
| 1038 |
SetPriorityClass(GetCurrentProcess(),ABOVE_NORMAL_PRIORITY_CLASS); |
| 1039 |
break; |
| 1040 |
case PRIORITY_LEVEL_HIGHEST: |
| 1041 |
SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS); |
| 1042 |
break; |
| 1043 |
#elif C_SET_PRIORITY |
| 1044 |
/* Linux use group as dosbox has mulitple threads under linux */ |
| 1045 |
case PRIORITY_LEVEL_PAUSE: // if DOSBox is paused, assume idle priority |
| 1046 |
case PRIORITY_LEVEL_LOWEST: |
| 1047 |
setpriority (PRIO_PGRP, 0,PRIO_MAX); |
| 1048 |
break; |
| 1049 |
case PRIORITY_LEVEL_LOWER: |
| 1050 |
setpriority (PRIO_PGRP, 0,PRIO_MAX-(PRIO_TOTAL/3)); |
| 1051 |
break; |
| 1052 |
case PRIORITY_LEVEL_NORMAL: |
| 1053 |
setpriority (PRIO_PGRP, 0,PRIO_MAX-(PRIO_TOTAL/2)); |
| 1054 |
break; |
| 1055 |
case PRIORITY_LEVEL_HIGHER: |
| 1056 |
setpriority (PRIO_PGRP, 0,PRIO_MAX-((3*PRIO_TOTAL)/5) ); |
| 1057 |
break; |
| 1058 |
case PRIORITY_LEVEL_HIGHEST: |
| 1059 |
setpriority (PRIO_PGRP, 0,PRIO_MAX-((3*PRIO_TOTAL)/4) ); |
| 1060 |
break; |
| 1061 |
#endif |
| 1062 |
default: |
| 1063 |
break; |
| 1064 |
} |
| 1065 |
} |
| 1066 |
|
| 1067 |
extern Bit8u int10_font_14[256 * 14]; |
| 1068 |
static void OutputString(Bitu x,Bitu y,const char * text,Bit32u color,Bit32u color2,SDL_Surface * output_surface) { |
| 1069 |
Bit32u * draw=(Bit32u*)(((Bit8u *)output_surface->pixels)+((y)*output_surface->pitch))+x; |
| 1070 |
while (*text) { |
| 1071 |
Bit8u * font=&int10_font_14[(*text)*14]; |
| 1072 |
Bitu i,j; |
| 1073 |
Bit32u * draw_line=draw; |
| 1074 |
for (i=0;i<14;i++) { |
| 1075 |
Bit8u map=*font++; |
| 1076 |
for (j=0;j<8;j++) { |
| 1077 |
if (map & 0x80) *((Bit32u*)(draw_line+j))=color; else *((Bit32u*)(draw_line+j))=color2; |
| 1078 |
map<<=1; |
| 1079 |
} |
| 1080 |
draw_line+=output_surface->pitch/4; |
| 1081 |
} |
| 1082 |
text++; |
| 1083 |
draw+=8; |
| 1084 |
} |
| 1085 |
} |
| 1086 |
|
| 1087 |
#include "dosbox_splash.h" |
| 1088 |
|
| 1089 |
//extern void UI_Run(bool); |
| 1090 |
static void GUI_StartUp(Section * sec) { |
| 1091 |
sec->AddDestroyFunction(&GUI_ShutDown); |
| 1092 |
Section_prop * section=static_cast<Section_prop *>(sec); |
| 1093 |
sdl.active=false; |
| 1094 |
sdl.updating=false; |
| 1095 |
|
| 1096 |
GFX_SetIcon(); |
| 1097 |
|
| 1098 |
sdl.desktop.fullscreen=section->Get_bool("fullscreen"); |
| 1099 |
sdl.wait_on_error=section->Get_bool("waitonerror"); |
| 1100 |
|
| 1101 |
Prop_multival* p=section->Get_multival("priority"); |
| 1102 |
std::string focus = p->GetSection()->Get_string("active"); |
| 1103 |
std::string notfocus = p->GetSection()->Get_string("inactive"); |
| 1104 |
|
| 1105 |
if (focus == "lowest") { sdl.priority.focus = PRIORITY_LEVEL_LOWEST; } |
| 1106 |
else if (focus == "lower") { sdl.priority.focus = PRIORITY_LEVEL_LOWER; } |
| 1107 |
else if (focus == "normal") { sdl.priority.focus = PRIORITY_LEVEL_NORMAL; } |
| 1108 |
else if (focus == "higher") { sdl.priority.focus = PRIORITY_LEVEL_HIGHER; } |
| 1109 |
else if (focus == "highest") { sdl.priority.focus = PRIORITY_LEVEL_HIGHEST; } |
| 1110 |
|
| 1111 |
if (notfocus == "lowest") { sdl.priority.nofocus=PRIORITY_LEVEL_LOWEST; } |
| 1112 |
else if (notfocus == "lower") { sdl.priority.nofocus=PRIORITY_LEVEL_LOWER; } |
| 1113 |
else if (notfocus == "normal") { sdl.priority.nofocus=PRIORITY_LEVEL_NORMAL; } |
| 1114 |
else if (notfocus == "higher") { sdl.priority.nofocus=PRIORITY_LEVEL_HIGHER; } |
| 1115 |
else if (notfocus == "highest") { sdl.priority.nofocus=PRIORITY_LEVEL_HIGHEST; } |
| 1116 |
else if (notfocus == "pause") { |
| 1117 |
/* we only check for pause here, because it makes no sense |
| 1118 |
* for DOSBox to be paused while it has focus |
| 1119 |
*/ |
| 1120 |
sdl.priority.nofocus=PRIORITY_LEVEL_PAUSE; |
| 1121 |
} |
| 1122 |
|
| 1123 |
SetPriority(sdl.priority.focus); //Assume focus on startup |
| 1124 |
sdl.mouse.locked=false; |
| 1125 |
mouselocked=false; //Global for mapper |
| 1126 |
sdl.mouse.requestlock=false; |
| 1127 |
sdl.desktop.full.fixed=false; |
| 1128 |
const char* fullresolution=section->Get_string("fullresolution"); |
| 1129 |
sdl.desktop.full.width = 0; |
| 1130 |
sdl.desktop.full.height = 0; |
| 1131 |
if(fullresolution && *fullresolution) { |
| 1132 |
char res[100]; |
| 1133 |
safe_strncpy( res, fullresolution, sizeof( res )); |
| 1134 |
fullresolution = lowcase (res);//so x and X are allowed |
| 1135 |
if (strcmp(fullresolution,"original")) { |
| 1136 |
sdl.desktop.full.fixed = true; |
| 1137 |
if (strcmp(fullresolution,"desktop")) { //desktop = 0x0 |
| 1138 |
char* height = const_cast<char*>(strchr(fullresolution,'x')); |
| 1139 |
if (height && * height) { |
| 1140 |
*height = 0; |
| 1141 |
sdl.desktop.full.height = (Bit16u)atoi(height+1); |
| 1142 |
sdl.desktop.full.width = (Bit16u)atoi(res); |
| 1143 |
} |
| 1144 |
} |
| 1145 |
} |
| 1146 |
} |
| 1147 |
|
| 1148 |
sdl.desktop.window.width = 0; |
| 1149 |
sdl.desktop.window.height = 0; |
| 1150 |
const char* windowresolution=section->Get_string("windowresolution"); |
| 1151 |
if(windowresolution && *windowresolution) { |
| 1152 |
char res[100]; |
| 1153 |
safe_strncpy( res,windowresolution, sizeof( res )); |
| 1154 |
windowresolution = lowcase (res);//so x and X are allowed |
| 1155 |
if(strcmp(windowresolution,"original")) { |
| 1156 |
char* height = const_cast<char*>(strchr(windowresolution,'x')); |
| 1157 |
if(height && *height) { |
| 1158 |
*height = 0; |
| 1159 |
sdl.desktop.window.height = (Bit16u)atoi(height+1); |
| 1160 |
sdl.desktop.window.width = (Bit16u)atoi(res); |
| 1161 |
} |
| 1162 |
} |
| 1163 |
} |
| 1164 |
sdl.desktop.doublebuf=section->Get_bool("fulldouble"); |
| 1165 |
#if SDL_VERSION_ATLEAST(1, 2, 10) |
| 1166 |
#ifdef WIN32 |
| 1167 |
const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo(); |
| 1168 |
if (vidinfo) { |
| 1169 |
int sdl_w = vidinfo->current_w; |
| 1170 |
int sdl_h = vidinfo->current_h; |
| 1171 |
int win_w = GetSystemMetrics(SM_CXSCREEN); |
| 1172 |
int win_h = GetSystemMetrics(SM_CYSCREEN); |
| 1173 |
if (sdl_w != win_w && sdl_h != win_h) |
| 1174 |
LOG_MSG("\nWindows dpi/blurry apps scaling detected! The screen might be too large or not\n" |
| 1175 |
"show properly, please see the DOSBox options file (fullresolution) for details.\n"); |
| 1176 |
} |
| 1177 |
#else |
| 1178 |
if (!sdl.desktop.full.width || !sdl.desktop.full.height){ |
| 1179 |
//Can only be done on the very first call! Not restartable. |
| 1180 |
//On windows don't use it as SDL returns the values without taking in account the dpi scaling |
| 1181 |
const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo(); |
| 1182 |
if (vidinfo) { |
| 1183 |
sdl.desktop.full.width = vidinfo->current_w; |
| 1184 |
sdl.desktop.full.height = vidinfo->current_h; |
| 1185 |
} |
| 1186 |
} |
| 1187 |
#endif |
| 1188 |
#endif |
| 1189 |
|
| 1190 |
if (!sdl.desktop.full.width) { |
| 1191 |
#ifdef WIN32 |
| 1192 |
sdl.desktop.full.width=(Bit16u)GetSystemMetrics(SM_CXSCREEN); |
| 1193 |
#else |
| 1194 |
LOG_MSG("Your fullscreen resolution can NOT be determined, it's assumed to be 1024x768.\nPlease edit the configuration file if this value is wrong."); |
| 1195 |
sdl.desktop.full.width=1024; |
| 1196 |
#endif |
| 1197 |
} |
| 1198 |
if (!sdl.desktop.full.height) { |
| 1199 |
#ifdef WIN32 |
| 1200 |
sdl.desktop.full.height=(Bit16u)GetSystemMetrics(SM_CYSCREEN); |
| 1201 |
#else |
| 1202 |
sdl.desktop.full.height=768; |
| 1203 |
#endif |
| 1204 |
} |
| 1205 |
sdl.mouse.autoenable=section->Get_bool("autolock"); |
| 1206 |
if (!sdl.mouse.autoenable) SDL_ShowCursor(SDL_DISABLE); |
| 1207 |
sdl.mouse.autolock=false; |
| 1208 |
sdl.mouse.sensitivity=section->Get_int("sensitivity"); |
| 1209 |
std::string output=section->Get_string("output"); |
| 1210 |
|
| 1211 |
/* Setup Mouse correctly if fullscreen */ |
| 1212 |
if(sdl.desktop.fullscreen) GFX_CaptureMouse(); |
| 1213 |
|
| 1214 |
if (output == "surface") { |
| 1215 |
sdl.desktop.want_type=SCREEN_SURFACE; |
| 1216 |
#if (HAVE_DDRAW_H) && defined(WIN32) |
| 1217 |
} else if (output == "ddraw") { |
| 1218 |
sdl.desktop.want_type=SCREEN_SURFACE_DDRAW; |
| 1219 |
#endif |
| 1220 |
} else if (output == "overlay") { |
| 1221 |
sdl.desktop.want_type=SCREEN_OVERLAY; |
| 1222 |
#if C_OPENGL |
| 1223 |
} else if (output == "opengl") { |
| 1224 |
sdl.desktop.want_type=SCREEN_OPENGL; |
| 1225 |
sdl.opengl.bilinear=true; |
| 1226 |
} else if (output == "openglnb") { |
| 1227 |
sdl.desktop.want_type=SCREEN_OPENGL; |
| 1228 |
sdl.opengl.bilinear=false; |
| 1229 |
#endif |
| 1230 |
} else { |
| 1231 |
LOG_MSG("SDL:Unsupported output device %s, switching back to surface",output.c_str()); |
| 1232 |
sdl.desktop.want_type=SCREEN_SURFACE;//SHOULDN'T BE POSSIBLE anymore |
| 1233 |
} |
| 1234 |
|
| 1235 |
sdl.overlay=0; |
| 1236 |
#if C_OPENGL |
| 1237 |
if(sdl.desktop.want_type==SCREEN_OPENGL){ /* OPENGL is requested */ |
| 1238 |
sdl.surface=SDL_SetVideoMode_Wrap(640,400,0,SDL_OPENGL); |
| 1239 |
if (sdl.surface == NULL) { |
| 1240 |
LOG_MSG("Could not initialize OpenGL, switching back to surface"); |
| 1241 |
sdl.desktop.want_type=SCREEN_SURFACE; |
| 1242 |
} else { |
| 1243 |
sdl.opengl.buffer=0; |
| 1244 |
sdl.opengl.framebuf=0; |
| 1245 |
sdl.opengl.texture=0; |
| 1246 |
sdl.opengl.displaylist=0; |
| 1247 |
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &sdl.opengl.max_texsize); |
| 1248 |
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)SDL_GL_GetProcAddress("glGenBuffersARB"); |
| 1249 |
glBindBufferARB = (PFNGLBINDBUFFERARBPROC)SDL_GL_GetProcAddress("glBindBufferARB"); |
| 1250 |
glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)SDL_GL_GetProcAddress("glDeleteBuffersARB"); |
| 1251 |
glBufferDataARB = (PFNGLBUFFERDATAARBPROC)SDL_GL_GetProcAddress("glBufferDataARB"); |
| 1252 |
glMapBufferARB = (PFNGLMAPBUFFERARBPROC)SDL_GL_GetProcAddress("glMapBufferARB"); |
| 1253 |
glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)SDL_GL_GetProcAddress("glUnmapBufferARB"); |
| 1254 |
const char * gl_ext = (const char *)glGetString (GL_EXTENSIONS); |
| 1255 |
if(gl_ext && *gl_ext){ |
| 1256 |
sdl.opengl.packed_pixel=(strstr(gl_ext,"EXT_packed_pixels") != NULL); |
| 1257 |
sdl.opengl.paletted_texture=(strstr(gl_ext,"EXT_paletted_texture") != NULL); |
| 1258 |
sdl.opengl.pixel_buffer_object=(strstr(gl_ext,"GL_ARB_pixel_buffer_object") != NULL ) && |
| 1259 |
glGenBuffersARB && glBindBufferARB && glDeleteBuffersARB && glBufferDataARB && |
| 1260 |
glMapBufferARB && glUnmapBufferARB; |
| 1261 |
} else { |
| 1262 |
sdl.opengl.packed_pixel=sdl.opengl.paletted_texture=false; |
| 1263 |
} |
| 1264 |
} |
| 1265 |
} /* OPENGL is requested end */ |
| 1266 |
|
| 1267 |
#endif //OPENGL |
| 1268 |
/* Initialize screen for first time */ |
| 1269 |
sdl.surface=SDL_SetVideoMode_Wrap(640,400,0,0); |
| 1270 |
if (sdl.surface == NULL) E_Exit("Could not initialize video: %s",SDL_GetError()); |
| 1271 |
sdl.desktop.bpp=sdl.surface->format->BitsPerPixel; |
| 1272 |
if (sdl.desktop.bpp==24) { |
| 1273 |
LOG_MSG("SDL:You are running in 24 bpp mode, this will slow down things!"); |
| 1274 |
} |
| 1275 |
GFX_Stop(); |
| 1276 |
SDL_WM_SetCaption("DOSBox",VERSION); |
| 1277 |
|
| 1278 |
/* The endian part is intentionally disabled as somehow it produces correct results without according to rhoenie*/ |
| 1279 |
//#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
| 1280 |
// Bit32u rmask = 0xff000000; |
| 1281 |
// Bit32u gmask = 0x00ff0000; |
| 1282 |
// Bit32u bmask = 0x0000ff00; |
| 1283 |
//#else |
| 1284 |
Bit32u rmask = 0x000000ff; |
| 1285 |
Bit32u gmask = 0x0000ff00; |
| 1286 |
Bit32u bmask = 0x00ff0000; |
| 1287 |
//#endif |
| 1288 |
|
| 1289 |
/* Please leave the Splash screen stuff in working order in DOSBox. We spend a lot of time making DOSBox. */ |
| 1290 |
SDL_Surface* splash_surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 640, 400, 32, rmask, gmask, bmask, 0); |
| 1291 |
if (splash_surf) { |
| 1292 |
SDL_FillRect(splash_surf, NULL, SDL_MapRGB(splash_surf->format, 0, 0, 0)); |
| 1293 |
|
| 1294 |
Bit8u* tmpbufp = new Bit8u[640*400*3]; |
| 1295 |
GIMP_IMAGE_RUN_LENGTH_DECODE(tmpbufp,gimp_image.rle_pixel_data,640*400,3); |
| 1296 |
for (Bitu y=0; y<400; y++) { |
| 1297 |
|
| 1298 |
Bit8u* tmpbuf = tmpbufp + y*640*3; |
| 1299 |
Bit32u * draw=(Bit32u*)(((Bit8u *)splash_surf->pixels)+((y)*splash_surf->pitch)); |
| 1300 |
for (Bitu x=0; x<640; x++) { |
| 1301 |
//#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
| 1302 |
// *draw++ = tmpbuf[x*3+2]+tmpbuf[x*3+1]*0x100+tmpbuf[x*3+0]*0x10000+0x00000000; |
| 1303 |
//#else |
| 1304 |
*draw++ = tmpbuf[x*3+0]+tmpbuf[x*3+1]*0x100+tmpbuf[x*3+2]*0x10000+0x00000000; |
| 1305 |
//#endif |
| 1306 |
} |
| 1307 |
} |
| 1308 |
|
| 1309 |
bool exit_splash = false; |
| 1310 |
|
| 1311 |
static Bitu max_splash_loop = 600; |
| 1312 |
static Bitu splash_fade = 100; |
| 1313 |
static bool use_fadeout = true; |
| 1314 |
|
| 1315 |
for (Bit32u ct = 0,startticks = GetTicks();ct < max_splash_loop;ct = GetTicks()-startticks) { |
| 1316 |
SDL_Event evt; |
| 1317 |
while (SDL_PollEvent(&evt)) { |
| 1318 |
if (evt.type == SDL_QUIT) { |
| 1319 |
exit_splash = true; |
| 1320 |
break; |
| 1321 |
} |
| 1322 |
} |
| 1323 |
if (exit_splash) break; |
| 1324 |
|
| 1325 |
if (ct<1) { |
| 1326 |
SDL_FillRect(sdl.surface, NULL, SDL_MapRGB(sdl.surface->format, 0, 0, 0)); |
| 1327 |
SDL_SetAlpha(splash_surf, SDL_SRCALPHA,255); |
| 1328 |
SDL_BlitSurface(splash_surf, NULL, sdl.surface, NULL); |
| 1329 |
SDL_Flip(sdl.surface); |
| 1330 |
} else if (ct>=max_splash_loop-splash_fade) { |
| 1331 |
if (use_fadeout) { |
| 1332 |
SDL_FillRect(sdl.surface, NULL, SDL_MapRGB(sdl.surface->format, 0, 0, 0)); |
| 1333 |
SDL_SetAlpha(splash_surf, SDL_SRCALPHA, (Bit8u)((max_splash_loop-1-ct)*255/(splash_fade-1))); |
| 1334 |
SDL_BlitSurface(splash_surf, NULL, sdl.surface, NULL); |
| 1335 |
SDL_Flip(sdl.surface); |
| 1336 |
} |
| 1337 |
} |
| 1338 |
|
| 1339 |
} |
| 1340 |
|
| 1341 |
if (use_fadeout) { |
| 1342 |
SDL_FillRect(sdl.surface, NULL, SDL_MapRGB(sdl.surface->format, 0, 0, 0)); |
| 1343 |
SDL_Flip(sdl.surface); |
| 1344 |
} |
| 1345 |
SDL_FreeSurface(splash_surf); |
| 1346 |
delete [] tmpbufp; |
| 1347 |
|
| 1348 |
} |
| 1349 |
|
| 1350 |
/* Get some Event handlers */ |
| 1351 |
MAPPER_AddHandler(KillSwitch,MK_f9,MMOD1,"shutdown","ShutDown"); |
| 1352 |
MAPPER_AddHandler(CaptureMouse,MK_f10,MMOD1,"capmouse","Cap Mouse"); |
| 1353 |
MAPPER_AddHandler(SwitchFullScreen,MK_return,MMOD2,"fullscr","Fullscreen"); |
| 1354 |
#if C_DEBUG |
| 1355 |
/* Pause binds with activate-debugger */ |
| 1356 |
#else |
| 1357 |
MAPPER_AddHandler(&PauseDOSBox, MK_pause, MMOD2, "pause", "Pause"); |
| 1358 |
#endif |
| 1359 |
/* Get Keyboard state of numlock and capslock */ |
| 1360 |
SDLMod keystate = SDL_GetModState(); |
| 1361 |
if(keystate&KMOD_NUM) startup_state_numlock = true; |
| 1362 |
if(keystate&KMOD_CAPS) startup_state_capslock = true; |
| 1363 |
} |
| 1364 |
|
| 1365 |
void Mouse_AutoLock(bool enable) { |
| 1366 |
sdl.mouse.autolock=enable; |
| 1367 |
if (sdl.mouse.autoenable) sdl.mouse.requestlock=enable; |
| 1368 |
else { |
| 1369 |
SDL_ShowCursor(enable?SDL_DISABLE:SDL_ENABLE); |
| 1370 |
sdl.mouse.requestlock=false; |
| 1371 |
} |
| 1372 |
} |
| 1373 |
|
| 1374 |
static void HandleMouseMotion(SDL_MouseMotionEvent * motion) { |
| 1375 |
if (sdl.mouse.locked || !sdl.mouse.autoenable) |
| 1376 |
Mouse_CursorMoved((float)motion->xrel*sdl.mouse.sensitivity/100.0f, |
| 1377 |
(float)motion->yrel*sdl.mouse.sensitivity/100.0f, |
| 1378 |
(float)(motion->x-sdl.clip.x)/(sdl.clip.w-1)*sdl.mouse.sensitivity/100.0f, |
| 1379 |
(float)(motion->y-sdl.clip.y)/(sdl.clip.h-1)*sdl.mouse.sensitivity/100.0f, |
| 1380 |
sdl.mouse.locked); |
| 1381 |
} |
| 1382 |
|
| 1383 |
static void HandleMouseButton(SDL_MouseButtonEvent * button) { |
| 1384 |
switch (button->state) { |
| 1385 |
case SDL_PRESSED: |
| 1386 |
if (sdl.mouse.requestlock && !sdl.mouse.locked) { |
| 1387 |
GFX_CaptureMouse(); |
| 1388 |
// Dont pass klick to mouse handler |
| 1389 |
break; |
| 1390 |
} |
| 1391 |
if (!sdl.mouse.autoenable && sdl.mouse.autolock && button->button == SDL_BUTTON_MIDDLE) { |
| 1392 |
GFX_CaptureMouse(); |
| 1393 |
break; |
| 1394 |
} |
| 1395 |
switch (button->button) { |
| 1396 |
case SDL_BUTTON_LEFT: |
| 1397 |
Mouse_ButtonPressed(0); |
| 1398 |
break; |
| 1399 |
case SDL_BUTTON_RIGHT: |
| 1400 |
Mouse_ButtonPressed(1); |
| 1401 |
break; |
| 1402 |
case SDL_BUTTON_MIDDLE: |
| 1403 |
Mouse_ButtonPressed(2); |
| 1404 |
break; |
| 1405 |
} |
| 1406 |
break; |
| 1407 |
case SDL_RELEASED: |
| 1408 |
switch (button->button) { |
| 1409 |
case SDL_BUTTON_LEFT: |
| 1410 |
Mouse_ButtonReleased(0); |
| 1411 |
break; |
| 1412 |
case SDL_BUTTON_RIGHT: |
| 1413 |
Mouse_ButtonReleased(1); |
| 1414 |
break; |
| 1415 |
case SDL_BUTTON_MIDDLE: |
| 1416 |
Mouse_ButtonReleased(2); |
| 1417 |
break; |
| 1418 |
} |
| 1419 |
break; |
| 1420 |
} |
| 1421 |
} |
| 1422 |
|
| 1423 |
void GFX_LosingFocus(void) { |
| 1424 |
sdl.laltstate=SDL_KEYUP; |
| 1425 |
sdl.raltstate=SDL_KEYUP; |
| 1426 |
MAPPER_LosingFocus(); |
| 1427 |
} |
| 1428 |
|
| 1429 |
#if defined(MACOSX) |
| 1430 |
#define DB_POLLSKIP 3 |
| 1431 |
#else |
| 1432 |
//Not used yet, see comment below |
| 1433 |
#define DB_POLLSKIP 1 |
| 1434 |
#endif |
| 1435 |
|
| 1436 |
#if defined(LINUX) |
| 1437 |
#define SDL_XORG_FIX 1 |
| 1438 |
#else |
| 1439 |
#define SDL_XORG_FIX 0 |
| 1440 |
#endif |
| 1441 |
|
| 1442 |
void GFX_Events() { |
| 1443 |
//Don't poll too often. This can be heavy on the OS, especially Macs. |
| 1444 |
//In idle mode 3000-4000 polls are done per second without this check. |
| 1445 |
//Macs, with this code, max 250 polls per second. (non-macs unused default max 500) |
| 1446 |
//Currently not implemented for all platforms, given the ALT-TAB stuff for WIN32. |
| 1447 |
#if defined (MACOSX) |
| 1448 |
static int last_check = 0; |
| 1449 |
int current_check = GetTicks(); |
| 1450 |
if (current_check - last_check <= DB_POLLSKIP) return; |
| 1451 |
last_check = current_check; |
| 1452 |
#endif |
| 1453 |
|
| 1454 |
SDL_Event event; |
| 1455 |
#if defined (REDUCE_JOYSTICK_POLLING) |
| 1456 |
static int poll_delay = 0; |
| 1457 |
int time = GetTicks(); |
| 1458 |
if (time - poll_delay > 20) { |
| 1459 |
poll_delay = time; |
| 1460 |
if (sdl.num_joysticks > 0) SDL_JoystickUpdate(); |
| 1461 |
MAPPER_UpdateJoysticks(); |
| 1462 |
} |
| 1463 |
#endif |
| 1464 |
while (SDL_PollEvent(&event)) { |
| 1465 |
#if SDL_XORG_FIX |
| 1466 |
// Special code for broken SDL with Xorg 1.20.1, where pairs of inputfocus gain and loss events are generated |
| 1467 |
// when locking the mouse in windowed mode. |
| •1468 |
// This also seems to give wrong key up events in fullscreen mode. |
| 1469 |
// sdl-1.2 has a fix in hg, but this shouldn't interfere with that fix. |
| 1470 |
if (event.type == SDL_ACTIVEEVENT && event.active.state == SDL_APPINPUTFOCUS && event.active.gain == 0) { |
| 1471 |
SDL_Event test; //Check if the next event would undo this one. |
| 1472 |
if (SDL_PeepEvents(&test,1,SDL_PEEKEVENT,SDL_ACTIVEEVENTMASK) == 1 && test.active.state == SDL_APPINPUTFOCUS && test.active.gain == 1) { |
| 1473 |
// Skip both events. |
| 1474 |
SDL_PeepEvents(&test,1,SDL_GETEVENT,SDL_ACTIVEEVENTMASK); |
| •1475 |
// Look for KEY UP events and check their validity. |
| 1476 |
while(SDL_PeepEvents(&test,1,SDL_PEEKEVENT,SDL_KEYUPMASK) == 1) { |
| 1477 |
const Uint8* kstate = SDL_GetKeyState(NULL); |
| 1478 |
if ( kstate[test.key.keysym.sym] != SDL_PRESSED) break; |
| 1479 |
SDL_PeepEvents(&test,1,SDL_GETEVENT,SDL_KEYUPMASK); |
| 1480 |
} |
| 1481 |
continue; |
| 1482 |
} |
| 1483 |
} |
| 1484 |
#endif |
| 1485 |
|
| 1486 |
switch (event.type) { |
| 1487 |
case SDL_ACTIVEEVENT: |
| 1488 |
if (event.active.state & SDL_APPINPUTFOCUS) { |
| 1489 |
if (event.active.gain) { |
| 1490 |
#ifdef WIN32 |
| 1491 |
if (!sdl.desktop.fullscreen) sdl.focus_ticks = GetTicks(); |
| 1492 |
#endif |
| 1493 |
if (sdl.desktop.fullscreen && !sdl.mouse.locked) |
| 1494 |
GFX_CaptureMouse(); |
| 1495 |
SetPriority(sdl.priority.focus); |
| 1496 |
CPU_Disable_SkipAutoAdjust(); |
| 1497 |
} else { |
| 1498 |
if (sdl.mouse.locked) { |
| 1499 |
#ifdef WIN32 |
| 1500 |
if (sdl.desktop.fullscreen) { |
| 1501 |
VGA_KillDrawing(); |
| 1502 |
sdl.desktop.fullscreen=false; |
| 1503 |
GFX_ResetScreen(); |
| 1504 |
} |
| 1505 |
#endif |
| 1506 |
GFX_CaptureMouse(); |
| 1507 |
} |
| 1508 |
SetPriority(sdl.priority.nofocus); |
| 1509 |
GFX_LosingFocus(); |
| 1510 |
CPU_Enable_SkipAutoAdjust(); |
| 1511 |
} |
| 1512 |
} |
| 1513 |
|
| 1514 |
/* Non-focus priority is set to pause; check to see if we've lost window or input focus |
| 1515 |
* i.e. has the window been minimised or made inactive? |
| 1516 |
*/ |
| 1517 |
if (sdl.priority.nofocus == PRIORITY_LEVEL_PAUSE) { |
| 1518 |
if ((event.active.state & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) && (!event.active.gain)) { |
| 1519 |
/* Window has lost focus, pause the emulator. |
| 1520 |
* This is similar to what PauseDOSBox() does, but the exit criteria is different. |
| 1521 |
* Instead of waiting for the user to hit Alt-Break, we wait for the window to |
| 1522 |
* regain window or input focus. |
| 1523 |
*/ |
| 1524 |
bool paused = true; |
| 1525 |
SDL_Event ev; |
| 1526 |
|
| 1527 |
GFX_SetTitle(-1,-1,true); |
| 1528 |
KEYBOARD_ClrBuffer(); |
| 1529 |
// SDL_Delay(500); |
| 1530 |
// while (SDL_PollEvent(&ev)) { |
| 1531 |
// flush event queue. |
| 1532 |
// } |
| 1533 |
|
| 1534 |
while (paused) { |
| 1535 |
// WaitEvent waits for an event rather than polling, so CPU usage drops to zero |
| 1536 |
SDL_WaitEvent(&ev); |
| 1537 |
|
| 1538 |
switch (ev.type) { |
| 1539 |
case SDL_QUIT: throw(0); break; // a bit redundant at linux at least as the active events gets before the quit event. |
| 1540 |
case SDL_ACTIVEEVENT: // wait until we get window focus back |
| 1541 |
if (ev.active.state & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) { |
| 1542 |
// We've got focus back, so unpause and break out of the loop |
| 1543 |
if (ev.active.gain) { |
| 1544 |
paused = false; |
| 1545 |
GFX_SetTitle(-1,-1,false); |
| 1546 |
} |
| 1547 |
|
| 1548 |
/* Now poke a "release ALT" command into the keyboard buffer |
| 1549 |
* we have to do this, otherwise ALT will 'stick' and cause |
| 1550 |
* problems with the app running in the DOSBox. |
| 1551 |
*/ |
| 1552 |
KEYBOARD_AddKey(KBD_leftalt, false); |
| 1553 |
KEYBOARD_AddKey(KBD_rightalt, false); |
| 1554 |
} |
| 1555 |
break; |
| 1556 |
} |
| 1557 |
} |
| 1558 |
} |
| 1559 |
} |
| 1560 |
break; |
| 1561 |
case SDL_MOUSEMOTION: |
| 1562 |
HandleMouseMotion(&event.motion); |
| 1563 |
break; |
| 1564 |
case SDL_MOUSEBUTTONDOWN: |
| 1565 |
case SDL_MOUSEBUTTONUP: |
| 1566 |
HandleMouseButton(&event.button); |
| 1567 |
break; |
| 1568 |
case SDL_VIDEORESIZE: |
| 1569 |
// HandleVideoResize(&event.resize); |
| 1570 |
break; |
| 1571 |
case SDL_QUIT: |
| 1572 |
throw(0); |
| 1573 |
break; |
| 1574 |
case SDL_VIDEOEXPOSE: |
| 1575 |
if (sdl.draw.callback) sdl.draw.callback( GFX_CallBackRedraw ); |
| 1576 |
break; |
| 1577 |
#ifdef WIN32 |
| 1578 |
case SDL_KEYDOWN: |
| 1579 |
case SDL_KEYUP: |
| 1580 |
// ignore event alt+tab |
| 1581 |
if (event.key.keysym.sym==SDLK_LALT) sdl.laltstate = event.key.type; |
| 1582 |
if (event.key.keysym.sym==SDLK_RALT) sdl.raltstate = event.key.type; |
| 1583 |
if (((event.key.keysym.sym==SDLK_TAB)) && |
| 1584 |
((sdl.laltstate==SDL_KEYDOWN) || (sdl.raltstate==SDL_KEYDOWN))) break; |
| 1585 |
// This can happen as well. |
| 1586 |
if (((event.key.keysym.sym == SDLK_TAB )) && (event.key.keysym.mod & KMOD_ALT)) break; |
| 1587 |
// ignore tab events that arrive just after regaining focus. (likely the result of alt-tab) |
| 1588 |
if ((event.key.keysym.sym == SDLK_TAB) && (GetTicks() - sdl.focus_ticks < 2)) break; |
| 1589 |
#endif |
| 1590 |
#if defined (MACOSX) |
| 1591 |
case SDL_KEYDOWN: |
| 1592 |
case SDL_KEYUP: |
| 1593 |
/* On macs CMD-Q is the default key to close an application */ |
| 1594 |
if (event.key.keysym.sym == SDLK_q && (event.key.keysym.mod == KMOD_RMETA || event.key.keysym.mod == KMOD_LMETA) ) { |
| 1595 |
KillSwitch(true); |
| 1596 |
break; |
| 1597 |
} |
| 1598 |
#endif |
| 1599 |
default: |
| 1600 |
void MAPPER_CheckEvent(SDL_Event * event); |
| 1601 |
MAPPER_CheckEvent(&event); |
| 1602 |
} |
| 1603 |
} |
| 1604 |
} |
| 1605 |
|
| 1606 |
#if defined (WIN32) |
| 1607 |
static BOOL WINAPI ConsoleEventHandler(DWORD event) { |
| 1608 |
switch (event) { |
| 1609 |
case CTRL_SHUTDOWN_EVENT: |
| 1610 |
case CTRL_LOGOFF_EVENT: |
| 1611 |
case CTRL_CLOSE_EVENT: |
| 1612 |
case CTRL_BREAK_EVENT: |
| 1613 |
raise(SIGTERM); |
| 1614 |
return TRUE; |
| 1615 |
case CTRL_C_EVENT: |
| 1616 |
default: //pass to the next handler |
| 1617 |
return FALSE; |
| 1618 |
} |
| 1619 |
} |
| 1620 |
#endif |
| 1621 |
|
| 1622 |
|
| 1623 |
/* static variable to show wether there is not a valid stdout. |
| 1624 |
* Fixes some bugs when -noconsole is used in a read only directory */ |
| 1625 |
static bool no_stdout = false; |
| 1626 |
void GFX_ShowMsg(char const* format,...) { |
| 1627 |
char buf[512]; |
| 1628 |
va_list msg; |
| 1629 |
va_start(msg,format); |
| 1630 |
vsprintf(buf,format,msg); |
| 1631 |
strcat(buf,"\n"); |
| 1632 |
va_end(msg); |
| 1633 |
if(!no_stdout) printf("%s",buf); //Else buf is parsed again. |
| 1634 |
} |
| 1635 |
|
| 1636 |
|
| 1637 |
void Config_Add_SDL() { |
| 1638 |
Section_prop * sdl_sec=control->AddSection_prop("sdl",&GUI_StartUp); |
| 1639 |
sdl_sec->AddInitFunction(&MAPPER_StartUp); |
| 1640 |
Prop_bool* Pbool; |
| 1641 |
Prop_string* Pstring; |
| 1642 |
Prop_int* Pint; |
| 1643 |
Prop_multival* Pmulti; |
| 1644 |
|
| 1645 |
Pbool = sdl_sec->Add_bool("fullscreen",Property::Changeable::Always,false); |
| 1646 |
Pbool->Set_help("Start dosbox directly in fullscreen. (Press ALT-Enter to go back)"); |
| 1647 |
|
| 1648 |
Pbool = sdl_sec->Add_bool("fulldouble",Property::Changeable::Always,false); |
| 1649 |
Pbool->Set_help("Use double buffering in fullscreen. It can reduce screen flickering, but it can also result in a slow DOSBox."); |
| 1650 |
|
| 1651 |
Pstring = sdl_sec->Add_string("fullresolution",Property::Changeable::Always,"original"); |
| 1652 |
Pstring->Set_help("What resolution to use for fullscreen: original, desktop or fixed size (e.g. 1024x768).\n" |
| 1653 |
" Using your monitor's native resolution (desktop) with aspect=true might give the best results.\n" |
| 1654 |
" If you end up with small window on a large screen, try an output different from surface.\n" |
| 1655 |
" On Windows 10 with display scaling (Scale and layout) set to a value above 100%, it is recommended\n" |
| 1656 |
" to use a lower full/windowresolution, in order to avoid window size problems."); |
| 1657 |
Pstring = sdl_sec->Add_string("windowresolution",Property::Changeable::Always,"original"); |
| 1658 |
Pstring->Set_help("Scale the window to this size IF the output device supports hardware scaling.\n" |
| 1659 |
" (output=surface does not!)"); |
| 1660 |
|
| 1661 |
const char* outputs[] = { |
| 1662 |
"surface", "overlay", |
| 1663 |
#if C_OPENGL |
| 1664 |
"opengl", "openglnb", |
| 1665 |
#endif |
| 1666 |
#if (HAVE_DDRAW_H) && defined(WIN32) |
| 1667 |
"ddraw", |
| 1668 |
#endif |
| 1669 |
0 }; |
| 1670 |
#if C_OPENGL && defined(MACOSX) |
| 1671 |
Pstring = sdl_sec->Add_string("output",Property::Changeable::Always,"opengl"); |
| 1672 |
#else |
| 1673 |
Pstring = sdl_sec->Add_string("output",Property::Changeable::Always,"surface"); |
| 1674 |
#endif |
| 1675 |
Pstring->Set_help("What video system to use for output."); |
| 1676 |
Pstring->Set_values(outputs); |
| 1677 |
|
| 1678 |
Pbool = sdl_sec->Add_bool("autolock",Property::Changeable::Always,true); |
| 1679 |
Pbool->Set_help("Mouse will automatically lock, if you click on the screen. (Press CTRL-F10 to unlock)"); |
| 1680 |
|
| 1681 |
Pint = sdl_sec->Add_int("sensitivity",Property::Changeable::Always,100); |
| 1682 |
Pint->SetMinMax(1,1000); |
| 1683 |
Pint->Set_help("Mouse sensitivity."); |
| 1684 |
|
| 1685 |
Pbool = sdl_sec->Add_bool("waitonerror",Property::Changeable::Always, true); |
| 1686 |
Pbool->Set_help("Wait before closing the console if dosbox has an error."); |
| 1687 |
|
| 1688 |
Pmulti = sdl_sec->Add_multi("priority", Property::Changeable::Always, ","); |
| 1689 |
Pmulti->SetValue("higher,normal"); |
| 1690 |
Pmulti->Set_help("Priority levels for dosbox. Second entry behind the comma is for when dosbox is not focused/minimized.\n" |
| 1691 |
" pause is only valid for the second entry."); |
| 1692 |
|
| 1693 |
const char* actt[] = { "lowest", "lower", "normal", "higher", "highest", "pause", 0}; |
| 1694 |
Pstring = Pmulti->GetSection()->Add_string("active",Property::Changeable::Always,"higher"); |
| 1695 |
Pstring->Set_values(actt); |
| 1696 |
|
| 1697 |
const char* inactt[] = { "lowest", "lower", "normal", "higher", "highest", "pause", 0}; |
| 1698 |
Pstring = Pmulti->GetSection()->Add_string("inactive",Property::Changeable::Always,"normal"); |
| 1699 |
Pstring->Set_values(inactt); |
| 1700 |
|
| 1701 |
Pstring = sdl_sec->Add_path("mapperfile",Property::Changeable::Always,MAPPERFILE); |
| •1702 |
Pstring->Set_help("File used to load/save the key/event mappings from. Resetmapper only works with the default value."); |
| 1703 |
|
| 1704 |
Pbool = sdl_sec->Add_bool("usescancodes",Property::Changeable::Always,true); |
| 1705 |
Pbool->Set_help("Avoid usage of symkeys, might not work on all operating systems."); |
| 1706 |
} |
| 1707 |
|
| 1708 |
static void show_warning(char const * const message) { |
| 1709 |
bool textonly = true; |
| 1710 |
#ifdef WIN32 |
| 1711 |
textonly = false; |
| 1712 |
if ( !sdl.inited && SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0 ) textonly = true; |
| 1713 |
sdl.inited = true; |
| 1714 |
#endif |
| 1715 |
printf("%s", message); |
| 1716 |
if(textonly) return; |
| 1717 |
if(!sdl.surface) sdl.surface = SDL_SetVideoMode_Wrap(640,400,0,0); |
| 1718 |
if(!sdl.surface) return; |
| 1719 |
#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
| 1720 |
Bit32u rmask = 0xff000000; |
| 1721 |
Bit32u gmask = 0x00ff0000; |
| 1722 |
Bit32u bmask = 0x0000ff00; |
| 1723 |
#else |
| 1724 |
Bit32u rmask = 0x000000ff; |
| 1725 |
Bit32u gmask = 0x0000ff00; |
| 1726 |
Bit32u bmask = 0x00ff0000; |
| 1727 |
#endif |
| 1728 |
SDL_Surface* splash_surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 640, 400, 32, rmask, gmask, bmask, 0); |
| 1729 |
if (!splash_surf) return; |
| 1730 |
|
| 1731 |
int x = 120,y = 20; |
| 1732 |
std::string m(message),m2; |
| 1733 |
std::string::size_type a,b,c,d; |
| 1734 |
|
| 1735 |
while(m.size()) { //Max 50 characters. break on space before or on a newline |
| 1736 |
c = m.find('\n'); |
| 1737 |
d = m.rfind(' ',50); |
| 1738 |
if(c>d) a=b=d; else a=b=c; |
| 1739 |
if( a != std::string::npos) b++; |
| 1740 |
m2 = m.substr(0,a); m.erase(0,b); |
| 1741 |
OutputString(x,y,m2.c_str(),0xffffffff,0,splash_surf); |
| 1742 |
y += 20; |
| 1743 |
} |
| 1744 |
|
| 1745 |
SDL_BlitSurface(splash_surf, NULL, sdl.surface, NULL); |
| 1746 |
SDL_Flip(sdl.surface); |
| 1747 |
SDL_Delay(12000); |
| 1748 |
} |
| 1749 |
|
| 1750 |
static void launcheditor() { |
| 1751 |
std::string path,file; |
| 1752 |
Cross::CreatePlatformConfigDir(path); |
| 1753 |
Cross::GetPlatformConfigName(file); |
| 1754 |
path += file; |
| 1755 |
FILE* f = fopen(path.c_str(),"r"); |
| 1756 |
if(!f && !control->PrintConfig(path.c_str())) { |
| 1757 |
printf("tried creating %s. but failed.\n",path.c_str()); |
| 1758 |
exit(1); |
| 1759 |
} |
| 1760 |
if(f) fclose(f); |
| 1761 |
/* if(edit.empty()) { |
| 1762 |
printf("no editor specified.\n"); |
| 1763 |
exit(1); |
| 1764 |
}*/ |
| 1765 |
std::string edit; |
| 1766 |
while(control->cmdline->FindString("-editconf",edit,true)) //Loop until one succeeds |
| 1767 |
execlp(edit.c_str(),edit.c_str(),path.c_str(),(char*) 0); |
| 1768 |
//if you get here the launching failed! |
| 1769 |
printf("can't find editor(s) specified at the command line.\n"); |
| 1770 |
exit(1); |
| 1771 |
} |
| 1772 |
static void launchcaptures(std::string const& edit) { |
| 1773 |
std::string path,file; |
| 1774 |
Section* t = control->GetSection("dosbox"); |
| 1775 |
if(t) file = t->GetPropValue("captures"); |
| 1776 |
if(!t || file == NO_SUCH_PROPERTY) { |
| 1777 |
printf("Config system messed up.\n"); |
| 1778 |
exit(1); |
| 1779 |
} |
| 1780 |
Cross::CreatePlatformConfigDir(path); |
| 1781 |
path += file; |
| 1782 |
Cross::CreateDir(path); |
| 1783 |
struct stat cstat; |
| 1784 |
if(stat(path.c_str(),&cstat) || (cstat.st_mode & S_IFDIR) == 0) { |
| 1785 |
printf("%s doesn't exists or isn't a directory.\n",path.c_str()); |
| 1786 |
exit(1); |
| 1787 |
} |
| 1788 |
/* if(edit.empty()) { |
| 1789 |
printf("no editor specified.\n"); |
| 1790 |
exit(1); |
| 1791 |
}*/ |
| 1792 |
|
| 1793 |
execlp(edit.c_str(),edit.c_str(),path.c_str(),(char*) 0); |
| 1794 |
//if you get here the launching failed! |
| 1795 |
printf("can't find filemanager %s\n",edit.c_str()); |
| 1796 |
exit(1); |
| 1797 |
} |
| 1798 |
|
| 1799 |
static void printconfiglocation() { |
| 1800 |
std::string path,file; |
| 1801 |
Cross::CreatePlatformConfigDir(path); |
| 1802 |
Cross::GetPlatformConfigName(file); |
| 1803 |
path += file; |
| 1804 |
|
| 1805 |
FILE* f = fopen(path.c_str(),"r"); |
| 1806 |
if(!f && !control->PrintConfig(path.c_str())) { |
| 1807 |
printf("tried creating %s. but failed",path.c_str()); |
| 1808 |
exit(1); |
| 1809 |
} |
| 1810 |
if(f) fclose(f); |
| 1811 |
printf("%s\n",path.c_str()); |
| 1812 |
exit(0); |
| 1813 |
} |
| 1814 |
|
| 1815 |
static void eraseconfigfile() { |
| 1816 |
FILE* f = fopen("dosbox.conf","r"); |
| 1817 |
if(f) { |
| 1818 |
fclose(f); |
| 1819 |
show_warning("Warning: dosbox.conf exists in current working directory.\nThis will override the configuration file at runtime.\n"); |
| 1820 |
} |
| 1821 |
std::string path,file; |
| 1822 |
Cross::GetPlatformConfigDir(path); |
| 1823 |
Cross::GetPlatformConfigName(file); |
| 1824 |
path += file; |
| 1825 |
f = fopen(path.c_str(),"r"); |
| 1826 |
if(!f) exit(0); |
| 1827 |
fclose(f); |
| 1828 |
unlink(path.c_str()); |
| 1829 |
exit(0); |
| 1830 |
} |
| 1831 |
|
| 1832 |
static void erasemapperfile() { |
| 1833 |
FILE* g = fopen("dosbox.conf","r"); |
| 1834 |
if(g) { |
| 1835 |
fclose(g); |
| 1836 |
show_warning("Warning: dosbox.conf exists in current working directory.\nKeymapping might not be properly reset.\n" |
| 1837 |
"Please reset configuration as well and delete the dosbox.conf.\n"); |
| 1838 |
} |
| 1839 |
|
| 1840 |
std::string path,file=MAPPERFILE; |
| 1841 |
Cross::GetPlatformConfigDir(path); |
| 1842 |
path += file; |
| 1843 |
FILE* f = fopen(path.c_str(),"r"); |
| 1844 |
if(!f) exit(0); |
| 1845 |
fclose(f); |
| 1846 |
unlink(path.c_str()); |
| 1847 |
exit(0); |
| 1848 |
} |
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
//extern void UI_Init(void); |
| 1853 |
int main(int argc, char* argv[]) { |
| 1854 |
try { |
| 1855 |
CommandLine com_line(argc,argv); |
| 1856 |
Config myconf(&com_line); |
| 1857 |
control=&myconf; |
| 1858 |
/* Init the configuration system and add default values */ |
| 1859 |
Config_Add_SDL(); |
| 1860 |
DOSBOX_Init(); |
| 1861 |
|
| 1862 |
std::string editor; |
| 1863 |
if(control->cmdline->FindString("-editconf",editor,false)) launcheditor(); |
| 1864 |
if(control->cmdline->FindString("-opencaptures",editor,true)) launchcaptures(editor); |
| 1865 |
if(control->cmdline->FindExist("-eraseconf")) eraseconfigfile(); |
| 1866 |
if(control->cmdline->FindExist("-resetconf")) eraseconfigfile(); |
| 1867 |
if(control->cmdline->FindExist("-erasemapper")) erasemapperfile(); |
| 1868 |
if(control->cmdline->FindExist("-resetmapper")) erasemapperfile(); |
| 1869 |
|
| 1870 |
/* Can't disable the console with debugger enabled */ |
| 1871 |
#if defined(WIN32) && !(C_DEBUG) |
| 1872 |
if (control->cmdline->FindExist("-noconsole")) { |
| 1873 |
FreeConsole(); |
| 1874 |
/* Redirect standard input and standard output */ |
| 1875 |
if(freopen(STDOUT_FILE, "w", stdout) == NULL) |
| 1876 |
no_stdout = true; // No stdout so don't write messages |
| 1877 |
freopen(STDERR_FILE, "w", stderr); |
| 1878 |
setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ |
| 1879 |
setbuf(stderr, NULL); /* No buffering */ |
| 1880 |
} else { |
| 1881 |
if (AllocConsole()) { |
| 1882 |
fclose(stdin); |
| 1883 |
fclose(stdout); |
| 1884 |
fclose(stderr); |
| 1885 |
freopen("CONIN$","r",stdin); |
| 1886 |
freopen("CONOUT$","w",stdout); |
| 1887 |
freopen("CONOUT$","w",stderr); |
| 1888 |
} |
| 1889 |
SetConsoleTitle("DOSBox Status Window"); |
| 1890 |
} |
| 1891 |
#endif //defined(WIN32) && !(C_DEBUG) |
| 1892 |
if (control->cmdline->FindExist("-version") || |
| 1893 |
control->cmdline->FindExist("--version") ) { |
| 1894 |
printf("\nDOSBox version %s, copyright 2002-2019 DOSBox Team.\n\n",VERSION); |
| 1895 |
printf("DOSBox is written by the DOSBox Team (See AUTHORS file))\n"); |
| 1896 |
printf("DOSBox comes with ABSOLUTELY NO WARRANTY. This is free software,\n"); |
| 1897 |
printf("and you are welcome to redistribute it under certain conditions;\n"); |
| 1898 |
printf("please read the COPYING file thoroughly before doing so.\n\n"); |
| 1899 |
return 0; |
| 1900 |
} |
| 1901 |
if(control->cmdline->FindExist("-printconf")) printconfiglocation(); |
| 1902 |
|
| 1903 |
#if C_DEBUG |
| 1904 |
DEBUG_SetupConsole(); |
| 1905 |
#endif |
| 1906 |
|
| 1907 |
#if defined(WIN32) |
| 1908 |
SetConsoleCtrlHandler((PHANDLER_ROUTINE) ConsoleEventHandler,TRUE); |
| 1909 |
#endif |
| 1910 |
|
| 1911 |
#ifdef OS2 |
| 1912 |
PPIB pib; |
| 1913 |
PTIB tib; |
| 1914 |
DosGetInfoBlocks(&tib, &pib); |
| 1915 |
if (pib->pib_ultype == 2) pib->pib_ultype = 3; |
| 1916 |
setbuf(stdout, NULL); |
| 1917 |
setbuf(stderr, NULL); |
| 1918 |
#endif |
| 1919 |
|
| 1920 |
/* Display Welcometext in the console */ |
| 1921 |
LOG_MSG("DOSBox version %s",VERSION); |
| 1922 |
LOG_MSG("Copyright 2002-2019 DOSBox Team, published under GNU GPL."); |
| 1923 |
LOG_MSG("---"); |
| 1924 |
|
| 1925 |
/* Init SDL */ |
| 1926 |
#if SDL_VERSION_ATLEAST(1, 2, 14) |
| 1927 |
/* Or debian/ubuntu with older libsdl version as they have done this themselves, but then differently. |
| 1928 |
* with this variable they will work correctly. I've only tested the 1.2.14 behaviour against the windows version |
| 1929 |
* of libsdl |
| 1930 |
*/ |
| 1931 |
putenv(const_cast<char*>("SDL_DISABLE_LOCK_KEYS=1")); |
| 1932 |
#endif |
| 1933 |
// Don't init timers, GetTicks seems to work fine and they can use a fair amount of power (Macs again) |
| 1934 |
// Please report problems with audio and other things. |
| 1935 |
if ( SDL_Init( SDL_INIT_AUDIO|SDL_INIT_VIDEO | /*SDL_INIT_TIMER |*/ SDL_INIT_CDROM |
| 1936 |
|SDL_INIT_NOPARACHUTE |
| 1937 |
) < 0 ) E_Exit("Can't init SDL %s",SDL_GetError()); |
| 1938 |
sdl.inited = true; |
| 1939 |
|
| 1940 |
#ifndef DISABLE_JOYSTICK |
| 1941 |
//Initialise Joystick separately. This way we can warn when it fails instead |
| 1942 |
//of exiting the application |
| 1943 |
if( SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0 ) LOG_MSG("Failed to init joystick support"); |
| 1944 |
#endif |
| 1945 |
|
| 1946 |
sdl.laltstate = SDL_KEYUP; |
| 1947 |
sdl.raltstate = SDL_KEYUP; |
| 1948 |
|
| 1949 |
#if defined (WIN32) |
| 1950 |
#if SDL_VERSION_ATLEAST(1, 2, 10) |
| 1951 |
sdl.using_windib=true; |
| 1952 |
#else |
| 1953 |
sdl.using_windib=false; |
| 1954 |
#endif |
| 1955 |
char sdl_drv_name[128]; |
| 1956 |
if (getenv("SDL_VIDEODRIVER")==NULL) { |
| 1957 |
if (SDL_VideoDriverName(sdl_drv_name,128)!=NULL) { |
| 1958 |
sdl.using_windib=false; |
| 1959 |
if (strcmp(sdl_drv_name,"directx")!=0) { |
| 1960 |
SDL_QuitSubSystem(SDL_INIT_VIDEO); |
| 1961 |
putenv("SDL_VIDEODRIVER=directx"); |
| 1962 |
if (SDL_InitSubSystem(SDL_INIT_VIDEO)<0) { |
| 1963 |
putenv("SDL_VIDEODRIVER=windib"); |
| 1964 |
if (SDL_InitSubSystem(SDL_INIT_VIDEO)<0) E_Exit("Can't init SDL Video %s",SDL_GetError()); |
| 1965 |
sdl.using_windib=true; |
| 1966 |
} |
| 1967 |
} |
| 1968 |
} |
| 1969 |
} else { |
| 1970 |
char* sdl_videodrv = getenv("SDL_VIDEODRIVER"); |
| 1971 |
if (strcmp(sdl_videodrv,"directx")==0) sdl.using_windib = false; |
| 1972 |
else if (strcmp(sdl_videodrv,"windib")==0) sdl.using_windib = true; |
| 1973 |
} |
| 1974 |
if (SDL_VideoDriverName(sdl_drv_name,128)!=NULL) { |
| 1975 |
if (strcmp(sdl_drv_name,"windib")==0) LOG_MSG("SDL_Init: Starting up with SDL windib video driver.\n Try to update your video card and directx drivers!"); |
| 1976 |
} |
| 1977 |
#endif |
| 1978 |
sdl.num_joysticks=SDL_NumJoysticks(); |
| 1979 |
|
| 1980 |
/* Parse configuration files */ |
| 1981 |
std::string config_file,config_path; |
| 1982 |
bool parsed_anyconfigfile = false; |
| 1983 |
//First Parse -userconf |
| 1984 |
if(control->cmdline->FindExist("-userconf",true)){ |
| 1985 |
config_file.clear(); |
| 1986 |
Cross::GetPlatformConfigDir(config_path); |
| 1987 |
Cross::GetPlatformConfigName(config_file); |
| 1988 |
config_path += config_file; |
| 1989 |
if(control->ParseConfigFile(config_path.c_str())) parsed_anyconfigfile = true; |
| 1990 |
if(!parsed_anyconfigfile) { |
| 1991 |
//Try to create the userlevel configfile. |
| 1992 |
config_file.clear(); |
| 1993 |
Cross::CreatePlatformConfigDir(config_path); |
| 1994 |
Cross::GetPlatformConfigName(config_file); |
| 1995 |
config_path += config_file; |
| 1996 |
if(control->PrintConfig(config_path.c_str())) { |
| 1997 |
LOG_MSG("CONFIG: Generating default configuration.\nWriting it to %s",config_path.c_str()); |
| 1998 |
//Load them as well. Makes relative paths much easier |
| 1999 |
if(control->ParseConfigFile(config_path.c_str())) parsed_anyconfigfile = true; |
| 2000 |
} |
| 2001 |
} |
| 2002 |
} |
| 2003 |
|
| 2004 |
//Second parse -conf entries |
| 2005 |
while(control->cmdline->FindString("-conf",config_file,true)) |
| 2006 |
if (control->ParseConfigFile(config_file.c_str())) parsed_anyconfigfile = true; |
| 2007 |
|
| 2008 |
//if none found => parse localdir conf |
| 2009 |
config_file = "dosbox.conf"; |
| 2010 |
if (!parsed_anyconfigfile && control->ParseConfigFile(config_file.c_str())) parsed_anyconfigfile = true; |
| 2011 |
|
| 2012 |
//if none found => parse userlevel conf |
| 2013 |
if(!parsed_anyconfigfile) { |
| 2014 |
config_file.clear(); |
| 2015 |
Cross::GetPlatformConfigDir(config_path); |
| 2016 |
Cross::GetPlatformConfigName(config_file); |
| 2017 |
config_path += config_file; |
| 2018 |
if(control->ParseConfigFile(config_path.c_str())) parsed_anyconfigfile = true; |
| 2019 |
} |
| 2020 |
|
| 2021 |
if(!parsed_anyconfigfile) { |
| 2022 |
//Try to create the userlevel configfile. |
| 2023 |
config_file.clear(); |
| 2024 |
Cross::CreatePlatformConfigDir(config_path); |
| 2025 |
Cross::GetPlatformConfigName(config_file); |
| 2026 |
config_path += config_file; |
| 2027 |
if(control->PrintConfig(config_path.c_str())) { |
| 2028 |
LOG_MSG("CONFIG: Generating default configuration.\nWriting it to %s",config_path.c_str()); |
| 2029 |
//Load them as well. Makes relative paths much easier |
| 2030 |
control->ParseConfigFile(config_path.c_str()); |
| 2031 |
} else { |
| 2032 |
LOG_MSG("CONFIG: Using default settings. Create a configfile to change them"); |
| 2033 |
} |
| 2034 |
} |
| 2035 |
|
| 2036 |
|
| 2037 |
#if (ENVIRON_LINKED) |
| 2038 |
control->ParseEnv(environ); |
| 2039 |
#endif |
| 2040 |
// UI_Init(); |
| 2041 |
// if (control->cmdline->FindExist("-startui")) UI_Run(false); |
| 2042 |
/* Init all the sections */ |
| 2043 |
control->Init(); |
| 2044 |
/* Some extra SDL Functions */ |
| 2045 |
Section_prop * sdl_sec=static_cast<Section_prop *>(control->GetSection("sdl")); |
| 2046 |
|
| 2047 |
if (control->cmdline->FindExist("-fullscreen") || sdl_sec->Get_bool("fullscreen")) { |
| •2048 |
if(!sdl.desktop.fullscreen) { //only switch if not already in fullscreen |
| 2049 |
GFX_SwitchFullScreen(); |
| 2050 |
} |
| 2051 |
} |
| 2052 |
|
| 2053 |
/* Init the keyMapper */ |
| 2054 |
MAPPER_Init(); |
| 2055 |
if (control->cmdline->FindExist("-startmapper")) MAPPER_RunInternal(); |
| 2056 |
/* Start up main machine */ |
| 2057 |
control->StartUp(); |
| 2058 |
/* Shutdown everything */ |
| 2059 |
} catch (char * error) { |
| 2060 |
GFX_ShowMsg("Exit to error: %s",error); |
| 2061 |
fflush(NULL); |
| 2062 |
if(sdl.wait_on_error) { |
| 2063 |
//TODO Maybe look for some way to show message in linux? |
| 2064 |
#if (C_DEBUG) |
| 2065 |
GFX_ShowMsg("Press enter to continue"); |
| 2066 |
fflush(NULL); |
| 2067 |
fgetc(stdin); |
| 2068 |
#elif defined(WIN32) |
| 2069 |
Sleep(5000); |
| 2070 |
#endif |
| 2071 |
} |
| 2072 |
|
| 2073 |
} |
| 2074 |
catch (int){ |
| 2075 |
;//nothing pressed killswitch |
| 2076 |
} |
| 2077 |
catch(...){ |
| 2078 |
//Force visible mouse to end user. Somehow this sometimes doesn't happen |
| 2079 |
SDL_WM_GrabInput(SDL_GRAB_OFF); |
| 2080 |
SDL_ShowCursor(SDL_ENABLE); |
| 2081 |
throw;//dunno what happened. rethrow for sdl to catch |
| 2082 |
} |
| 2083 |
//Force visible mouse to end user. Somehow this sometimes doesn't happen |
| 2084 |
SDL_WM_GrabInput(SDL_GRAB_OFF); |
| 2085 |
SDL_ShowCursor(SDL_ENABLE); |
| 2086 |
|
| 2087 |
SDL_Quit();//Let's hope sdl will quit as well when it catches an exception |
| 2088 |
return 0; |
| 2089 |
} |
| 2090 |
|
| 2091 |
void GFX_GetSize(int &width, int &height, bool &fullscreen) { |
| 2092 |
width = sdl.draw.width; |
| 2093 |
height = sdl.draw.height; |
| 2094 |
fullscreen = sdl.desktop.fullscreen; |
| 2095 |
} |