]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/video.cpp
Added missing images, added some fixes to ZIP file support
[virtualjaguar] / src / video.cpp
index b35cc1a048e50b68abad5a7dc7e8388ab26cc54d..1d86f18b83e61dfa725cfd4b5806a0400c7fc4d1 100644 (file)
@@ -2,11 +2,18 @@
 // VIDEO.CPP: SDL/local hardware specific video routines
 //
 // by James L. Hammons
+// (C) 2010 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -------------------------------------------------------------
+// JLH  01/16/2010  Created this log ;-)
 //
 
 #include "video.h"
 
-#include "gui.h"                                                               // For "finished"
+//#include "gui.h"                                                             // For "finished"
 #include "log.h"
 #include "tom.h"
 #include "sdlemu_opengl.h"
 //shouldn't these exist here??? Prolly.
 //And now, they do! :-)
 SDL_Surface * surface, * mainSurface;
-SDL_Joystick * joystick;
+SDL_Joystick * joystick1;
 Uint32 mainSurfaceFlags;
 //int16 * backbuffer;
 uint32 * backbuffer;
 
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+       #define RMASK 0xFF000000
+       #define GMASK 0x00FF0000
+       #define BMASK 0x0000FF00
+       #define AMASK 0x000000FF
+#else
+       #define RMASK 0x000000FF
+       #define GMASK 0x0000FF00
+       #define BMASK 0x00FF0000
+       #define AMASK 0xFF000000
+#endif
+
+
 // One of the reasons why OpenGL is slower then normal SDL rendering, is because
 // the data is being pumped into the buffer every frame with a overflow as result.
 // So, we going tot render every 1 frame instead of every 0 frame.
@@ -37,7 +57,7 @@ int frame_ticker = 0;
 //
 // Create SDL/OpenGL surfaces
 //
-bool InitVideo(void)
+bool VideoInit(void)
 {
        // Get proper info about the platform we're running on...
        const SDL_VideoInfo * info = SDL_GetVideoInfo();
@@ -50,11 +70,10 @@ bool InitVideo(void)
 
        if (vjs.useOpenGL)
        {
-           // Initializing SDL attributes with OpenGL
-           SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
-        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+               // Initializing SDL attributes with OpenGL
+               SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
+               SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
                mainSurfaceFlags = SDL_OPENGL;
-
        }
        else
        {
@@ -112,12 +131,7 @@ bool InitVideo(void)
 //             vsWidth = 1280;
 //24BPP
 //     surface = SDL_CreateRGBSurface(SDL_SWSURFACE, VIRTUAL_SCREEN_WIDTH,
-       surface = SDL_CreateRGBSurface(SDL_SWSURFACE, vsWidth, vsHeight, 32,
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-                0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
-#else
-                0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
-#endif//*/
+       surface = SDL_CreateRGBSurface(SDL_SWSURFACE, vsWidth, vsHeight, 32, RMASK, GMASK, BMASK, AMASK);
 
        if (surface == NULL)
        {
@@ -144,7 +158,7 @@ bool InitVideo(void)
                }
                else
                {
-                       if ((joystick = SDL_JoystickOpen(vjs.joyport)) == 0)
+                       if ((joystick1 = SDL_JoystickOpen(vjs.joyport)) == 0)
                        {
                                vjs.useJoystick = false;
                                printf("VJ: Unable to open a Joystick on port: %d\n", (int)vjs.joyport);
@@ -172,7 +186,7 @@ void VideoDone(void)
        if (vjs.useOpenGL)
                sdlemu_close_opengl();
 
-       SDL_JoystickClose(joystick);
+       SDL_JoystickClose(joystick1);
        SDL_FreeSurface(surface);
        free(backbuffer);
 }
@@ -199,9 +213,9 @@ void RenderBackbuffer(void)
 //     memcpy(surface->pixels, backbuffer, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 2);
 // This memcpy is expensive--do some profiling to see what the impact is!
        if (vjs.renderType == RT_NORMAL)
-               memcpy(surface->pixels, backbuffer, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 4);
+               memcpy(surface->pixels, backbuffer, TOMGetVideoModeWidth() * TOMGetVideoModeHeight() * 4);
        else if (vjs.renderType == RT_TV)
-               memcpy(surface->pixels, backbuffer, 1280 * tom_getVideoModeHeight() * 4);
+               memcpy(surface->pixels, backbuffer, 1280 * TOMGetVideoModeHeight() * 4);
 
        if (SDL_MUSTLOCK(surface))
                SDL_UnlockSurface(surface);
@@ -227,12 +241,7 @@ void RenderBackbuffer(void)
 void ResizeScreen(uint32 width, uint32 height)
 {
        SDL_FreeSurface(surface);
-       surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-                0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
-#else
-                0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
-#endif//*/
+       surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, RMASK, GMASK, BMASK, AMASK);
 
        if (surface == NULL)
        {
@@ -241,7 +250,8 @@ void ResizeScreen(uint32 width, uint32 height)
 //as well as screwing up SDL... !!! FIX !!!
 //             exit(1);
                // OK, this is cleaner. We can't continue if there is no surface created!
-               finished = true;
+#warning "!!! FIX !!! (finished = true)"
+//             finished = true;
        }
 
        if (vjs.useOpenGL)
@@ -282,11 +292,16 @@ uint32 GetSDLScreenWidthInPixels(void)
 //
 void ToggleFullscreen(void)
 {
+       // Set our internal variable, then toggle the SDL flag
        vjs.fullscreen = !vjs.fullscreen;
-       mainSurfaceFlags &= ~SDL_FULLSCREEN;
+       mainSurfaceFlags ^= SDL_FULLSCREEN;
+//     mainSurfaceFlags = (vjs.fullscreen ? mainSurfaceFlags | SDL_FULLSCREEN :
+//             mainSurfaceFlags & ~SDL_FULLSCREEN);
 
-       if (vjs.fullscreen)
-               mainSurfaceFlags |= SDL_FULLSCREEN;
+//     mainSurfaceFlags &= ~SDL_FULLSCREEN;
+
+//     if (vjs.fullscreen)
+//             mainSurfaceFlags |= SDL_FULLSCREEN;
 
        if (vjs.useOpenGL)
        {
@@ -294,7 +309,7 @@ void ToggleFullscreen(void)
                // This way we have good scaling functionality and when the screen is resized
                // because of the NTSC <-> PAL resize, we only have to re-create the texture
                // instead of initializing the entire OpenGL texture en screens.
-               mainSurface = SDL_SetVideoMode(640, 480, 32, mainSurfaceFlags);//*/
+               mainSurface = SDL_SetVideoMode(640, 480, 32, mainSurfaceFlags);
 
                // Reset viewport, etc.
                glViewport(0, 0, mainSurface->w, mainSurface->h);