2007-05-29 03:06:33 +00:00
|
|
|
//
|
2017-06-02 02:42:15 +00:00
|
|
|
// VIDEO.CPP: SDL2/local hardware specific video routines
|
2007-05-29 03:06:33 +00:00
|
|
|
//
|
2013-09-28 23:15:54 +00:00
|
|
|
// by James Hammons
|
2007-05-29 03:06:33 +00:00
|
|
|
//
|
2013-09-28 23:15:54 +00:00
|
|
|
// JLH = James Hammons <jlhamm@acm.org>
|
2007-05-29 03:06:33 +00:00
|
|
|
//
|
|
|
|
// WHO WHEN WHAT
|
2017-06-02 02:42:15 +00:00
|
|
|
// --- ---------- -----------------------------------------------------------
|
2007-05-29 03:06:33 +00:00
|
|
|
// JLH 01/04/2006 Added changelog ;-)
|
|
|
|
// JLH 01/20/2006 Cut out unnecessary buffering
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "video.h"
|
2017-06-02 02:42:15 +00:00
|
|
|
#include <string.h> // (for memset, etc... Lazy!)
|
2007-05-29 03:06:33 +00:00
|
|
|
#include <malloc.h>
|
2014-04-01 16:33:48 +00:00
|
|
|
#include "apple2-icon-64x64.h"
|
2007-05-29 03:06:33 +00:00
|
|
|
#include "log.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
|
2017-06-02 02:42:15 +00:00
|
|
|
// Local vars
|
2013-09-09 02:18:23 +00:00
|
|
|
static SDL_Window * sdlWindow = NULL;
|
|
|
|
static SDL_Texture * sdlTexture = NULL;
|
2017-06-02 02:42:15 +00:00
|
|
|
|
|
|
|
// Exported vars
|
|
|
|
SDL_Renderer * sdlRenderer = NULL;
|
2013-09-09 02:18:23 +00:00
|
|
|
uint32_t scrBuffer[VIRTUAL_SCREEN_WIDTH * VIRTUAL_SCREEN_HEIGHT * sizeof(uint32_t)];
|
|
|
|
|
2007-05-29 03:06:33 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Prime SDL and create surfaces
|
|
|
|
//
|
|
|
|
bool InitVideo(void)
|
|
|
|
{
|
2013-09-09 02:18:23 +00:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) != 0)
|
2007-05-29 03:06:33 +00:00
|
|
|
{
|
|
|
|
WriteLog("Video: Could not initialize the SDL library: %s\n", SDL_GetError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
int retVal = SDL_CreateWindowAndRenderer(VIRTUAL_SCREEN_WIDTH * 2, VIRTUAL_SCREEN_HEIGHT * 2, SDL_WINDOW_OPENGL, &sdlWindow, &sdlRenderer);
|
2007-05-29 03:06:33 +00:00
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
if (retVal != 0)
|
2007-05-29 03:06:33 +00:00
|
|
|
{
|
2013-09-09 02:18:23 +00:00
|
|
|
WriteLog("Video: Could not window and/or renderer: %s\n", SDL_GetError());
|
2007-05-29 03:06:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
// Make the scaled rendering look smoother.
|
|
|
|
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
|
|
|
|
// SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
|
|
|
|
SDL_RenderSetLogicalSize(sdlRenderer, VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT);
|
2007-05-29 03:06:33 +00:00
|
|
|
|
2014-04-01 16:33:48 +00:00
|
|
|
// Set the application's icon & title...
|
|
|
|
SDL_Surface * iconSurface = SDL_CreateRGBSurfaceFrom(icon, 64, 64, 32, 64*4, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
|
|
|
SDL_SetWindowIcon(sdlWindow, iconSurface);
|
|
|
|
SDL_FreeSurface(iconSurface);
|
|
|
|
SDL_SetWindowTitle(sdlWindow, "Apple2 Emulator");
|
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
sdlTexture = SDL_CreateTexture(sdlRenderer,
|
|
|
|
SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING,
|
|
|
|
VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT);
|
2007-05-29 03:06:33 +00:00
|
|
|
|
|
|
|
WriteLog("Video: Successfully initialized.\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
|
2007-05-29 03:06:33 +00:00
|
|
|
//
|
|
|
|
// Free various SDL components
|
|
|
|
//
|
|
|
|
void VideoDone(void)
|
|
|
|
{
|
2009-07-09 01:37:07 +00:00
|
|
|
WriteLog("Video: Shutting down SDL...\n");
|
2007-05-29 03:06:33 +00:00
|
|
|
SDL_Quit();
|
2009-07-09 01:37:07 +00:00
|
|
|
WriteLog("Video: Done.\n");
|
2007-05-29 03:06:33 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
|
2007-05-29 03:06:33 +00:00
|
|
|
//
|
|
|
|
// Render the screen buffer to the primary screen surface
|
|
|
|
//
|
|
|
|
void RenderScreenBuffer(void)
|
|
|
|
{
|
2013-09-09 02:18:23 +00:00
|
|
|
SDL_UpdateTexture(sdlTexture, NULL, scrBuffer, VIRTUAL_SCREEN_WIDTH * sizeof(Uint32));
|
|
|
|
SDL_RenderClear(sdlRenderer);
|
|
|
|
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
|
2007-05-29 03:06:33 +00:00
|
|
|
}
|
|
|
|
|
2009-01-30 15:17:27 +00:00
|
|
|
|
2007-05-29 03:06:33 +00:00
|
|
|
//
|
|
|
|
// Fullscreen <-> window switching
|
|
|
|
//
|
2013-09-09 02:18:23 +00:00
|
|
|
void ToggleFullScreen(void)
|
2007-05-29 03:06:33 +00:00
|
|
|
{
|
|
|
|
settings.fullscreen = !settings.fullscreen;
|
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
int retVal = SDL_SetWindowFullscreen(sdlWindow, (settings.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
|
|
|
|
SDL_ShowCursor(settings.fullscreen ? 0 : 1);
|
2007-05-29 03:06:33 +00:00
|
|
|
|
2013-09-09 02:18:23 +00:00
|
|
|
if (retVal != 0)
|
|
|
|
WriteLog("Video::ToggleFullScreen: SDL error = %s\n", SDL_GetError());
|
2007-05-29 03:06:33 +00:00
|
|
|
}
|
2013-09-09 02:18:23 +00:00
|
|
|
|
2013-10-08 21:55:07 +00:00
|
|
|
|