From 664d4e5d1adea5d8e3b390a452d4ec94162af319 Mon Sep 17 00:00:00 2001 From: stephena Date: Fri, 12 Jun 2009 13:29:26 +0000 Subject: [PATCH] Fixed issue with incorrect reporting of OpenGL version number for Windows. Because the version was always being returned as 0, the TV effects were always disabled, even on hardware that could support them. Creation of OpenGL video mode is now more robust. If it fails for any reason, fallback to software mode is now done (and a message stating that it happened). This still won't protect against the operating system lying to Stella and saying OpenGL support is really available when it isn't, though. Added support for ROMs smaller than 2K. These are still treated as 2K ROMs, but have their contents mirrored appropriately. Bumped version number. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1768 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- Todo.txt | 2 ++ src/common/FrameBufferGL.cxx | 8 ++++---- src/common/FrameBufferGL.hxx | 2 ++ src/common/Version.hxx | 2 +- src/emucore/Cart.cxx | 12 ++++++++++-- src/emucore/Cart2K.cxx | 21 ++++++++++++++++++--- src/emucore/Cart2K.hxx | 3 ++- src/emucore/MediaFactory.cxx | 12 ------------ src/emucore/OSystem.cxx | 29 +++++++++++++++++++++++++---- 9 files changed, 64 insertions(+), 27 deletions(-) diff --git a/Todo.txt b/Todo.txt index b612c6994..c12008370 100644 --- a/Todo.txt +++ b/Todo.txt @@ -31,6 +31,8 @@ Stephen Anthony at stephena@users.sourceforge.net. * Improve debugger support for remaining cartridges with dedicated RAM, and add source-level debugging + * Make the prompt tab in the debugger accept case-insensitive commands. + * Fix bank going over 255 (when accessing RAM) for 3E in the debugger RomWidget view. diff --git a/src/common/FrameBufferGL.cxx b/src/common/FrameBufferGL.cxx index 9f9860945..d1d955c0e 100644 --- a/src/common/FrameBufferGL.cxx +++ b/src/common/FrameBufferGL.cxx @@ -188,10 +188,6 @@ bool FrameBufferGL::loadFuncs() else return false; - // Grab OpenGL version number - string version((const char *)p_glGetString(GL_VERSION)); - myGLVersion = atof(version.substr(0, 3).c_str()); - return true; } @@ -345,6 +341,10 @@ bool FrameBufferGL::setVidMode(VideoMode& mode) if(!loadFuncs()) return false; + // Grab OpenGL version number + string version((const char *)p_glGetString(GL_VERSION)); + myGLVersion = atof(version.substr(0, 3).c_str()); + // Check for some extensions that can potentially speed up operation // Don't use it if we've been instructed not to if(myOSystem->settings().getBool("gl_texrect")) diff --git a/src/common/FrameBufferGL.hxx b/src/common/FrameBufferGL.hxx index 5f12e66c2..456dcf141 100644 --- a/src/common/FrameBufferGL.hxx +++ b/src/common/FrameBufferGL.hxx @@ -64,6 +64,8 @@ class FrameBufferGL : public FrameBuffer /** Return version of the OpenGL library found by the OSystem (0 indicates that the libary was not loaded successfully). + This will not return a valid version number until setVidMode() + has been called at least once. */ static float glVersion() { return myGLVersion; } diff --git a/src/common/Version.hxx b/src/common/Version.hxx index 7225ccee7..91d0c478e 100644 --- a/src/common/Version.hxx +++ b/src/common/Version.hxx @@ -19,7 +19,7 @@ #ifndef VERSION_HXX #define VERSION_HXX -#define STELLA_BASE_VERSION "2.8" +#define STELLA_BASE_VERSION "2.8.1_svn" #ifdef NIGHTLY_BUILD #define STELLA_VERSION STELLA_BASE_VERSION "pre-" NIGHTLY_BUILD diff --git a/src/emucore/Cart.cxx b/src/emucore/Cart.cxx index acd69d622..c8ba9a5f2 100644 --- a/src/emucore/Cart.cxx +++ b/src/emucore/Cart.cxx @@ -88,12 +88,16 @@ Cartridge* Cartridge::create(const uInt8* image, uInt32 size, type = detected; } - buf << type << autodetect << " (" << (size/1024) << "K) "; + buf << type << autodetect << " ("; + if(size < 1024) + buf << size << "B) "; + else + buf << (size/1024) << "K) "; myAboutString = buf.str(); // We should know the cart's type by now so let's create it if(type == "2K") - cartridge = new Cartridge2K(image); + cartridge = new Cartridge2K(image, size); else if(type == "3E") cartridge = new Cartridge3E(image, size); else if(type == "3F") @@ -203,6 +207,10 @@ string Cartridge::autodetectType(const uInt8* image, uInt32 size) { type = "AR"; } + else if(size < 2048) // Sub2K images + { + type = "2K"; + } else if((size == 2048) || (size == 4096 && memcmp(image, image + 2048, 2048) == 0)) { diff --git a/src/emucore/Cart2K.cxx b/src/emucore/Cart2K.cxx index 725d9bcd5..4353d6b6f 100644 --- a/src/emucore/Cart2K.cxx +++ b/src/emucore/Cart2K.cxx @@ -23,10 +23,25 @@ #include "Cart2K.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Cartridge2K::Cartridge2K(const uInt8* image) +Cartridge2K::Cartridge2K(const uInt8* image, uInt32 size) { - // Copy the ROM image into my buffer - memcpy(myImage, image, 2048); + // Size can be a maximum of 2K + if(size > 2048) size = 2048; + + // Initialize ROM with illegal 6502 opcode that causes a real 6502 to jam + memset(myImage, 0x02, 2048); + + // Mirror each power-of-two slice in the 2K address space + uInt32 slice = 1, numslices = 2048; + while(slice < size) + { + slice <<= 1; + numslices >>= 1; + } + + // Copy the ROM image slices into my buffer + for(uInt32 i = 0; i < numslices; ++i) + memcpy(myImage + i*slice, image, slice); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart2K.hxx b/src/emucore/Cart2K.hxx index 4ab3346cc..f38d631e3 100644 --- a/src/emucore/Cart2K.hxx +++ b/src/emucore/Cart2K.hxx @@ -41,8 +41,9 @@ class Cartridge2K : public Cartridge Create a new cartridge using the specified image @param image Pointer to the ROM image + @param size The size of the ROM image (<= 2048 bytes) */ - Cartridge2K(const uInt8* image); + Cartridge2K(const uInt8* image, uInt32 size); /** Destructor diff --git a/src/emucore/MediaFactory.cxx b/src/emucore/MediaFactory.cxx index a94273556..c18d4e446 100644 --- a/src/emucore/MediaFactory.cxx +++ b/src/emucore/MediaFactory.cxx @@ -60,8 +60,6 @@ FrameBuffer* MediaFactory::createVideo(OSystem* osystem) const string& gl_lib = osystem->settings().getString("gl_lib"); if(FrameBufferGL::loadLibrary(gl_lib)) fb = new FrameBufferGL(osystem); - else - cerr << "ERROR: Couldn't dynamically load OpenGL library ...\n"; } #endif @@ -80,16 +78,6 @@ FrameBuffer* MediaFactory::createVideo(OSystem* osystem) // This should never happen assert(fb != NULL); - switch(fb->type()) - { - case kSoftBuffer: - osystem->settings().setString("video", "soft"); - break; - - case kGLBuffer: - osystem->settings().setString("video", "gl"); - break; - } return fb; } diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 0c1c5e0a9..0ba8b76ee 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -376,22 +376,23 @@ bool OSystem::createFrameBuffer() case EventHandler::S_MENU: case EventHandler::S_CMDMENU: if(!myConsole->initializeVideo()) - return false; + goto fallback; break; // S_EMULATE, S_PAUSE, S_MENU, S_CMDMENU case EventHandler::S_LAUNCHER: if(!myLauncher->initializeVideo()) - return false; + goto fallback; break; // S_LAUNCHER #ifdef DEBUGGER_SUPPORT case EventHandler::S_DEBUGGER: if(!myDebugger->initializeVideo()) - return false; + goto fallback; break; // S_DEBUGGER #endif - default: + default: // Should never happen + cerr << "ERROR: Unknown emulation state in createFrameBuffer()" << endl; break; } @@ -406,6 +407,26 @@ bool OSystem::createFrameBuffer() } return true; + + // GOTO are normally considered evil, unless well documented :) + // If initialization of video system fails while in OpenGL mode, + // attempt to fallback to software mode +fallback: + if(myFrameBuffer && myFrameBuffer->type() == kGLBuffer) + { + cerr << "ERROR: OpenGL mode failed, fallback to software" << endl; + delete myFrameBuffer; myFrameBuffer = NULL; + mySettings->setString("video", "soft"); + bool ret = createFrameBuffer(); + if(ret) + { + setFramerate(60); + myFrameBuffer->showMessage("OpenGL mode failed, fallback to software", kMiddleCenter); + } + return ret; + } + else + return false; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -