Ticket #9019: 16bit_step1_r2.patch

File 16bit_step1_r2.patch, 7.9 KB (added by SF/upthorn, 15 years ago)

The original patch, revised to reflect the fact that freddicove uses 555 rgb, whereas most hardware implementations of 16bit are 565.

  • backends/platform/sdl/graphics.cpp

     
    407407                }
    408408        }
    409409
     410#ifdef ENABLE_16BIT
    410411        //
     412        // Create the surface that contains the 16 bit game data
     413        //
     414        _screen16 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight,
     415                                                16,
     416                                                0x7C00,
     417                                                0x3E0,
     418                                                0x1F,
     419                                                0); //555, not 565
     420        if (_screen16 == NULL)
     421                error("allocating _screen16 failed");
     422#endif
     423
     424        //
    411425        // Create the surface used for the graphics in 16 bit before scaling, and also the overlay
    412426        //
    413427
     
    484498}
    485499
    486500void OSystem_SDL::unloadGFXMode() {
     501#ifdef ENABLE_16BIT
     502        if (_screen16) {
     503                SDL_FreeSurface(_screen16);
     504                _screen16 = NULL;
     505        }
     506#else
    487507        if (_screen) {
    488508                SDL_FreeSurface(_screen);
    489509                _screen = NULL;
    490510        }
     511#endif
    491512
    492513        if (_hwscreen) {
    493514                SDL_FreeSurface(_hwscreen);
     
    519540}
    520541
    521542bool OSystem_SDL::hotswapGFXMode() {
     543#ifdef ENABLE_16BIT
     544        if (!_screen16)
     545#else
    522546        if (!_screen)
     547#endif
    523548                return false;
    524549
    525550        // Keep around the old _screen & _overlayscreen so we can restore the screen data
    526551        // after the mode switch.
     552#ifdef ENABLE_16BIT
     553        SDL_Surface *old_screen = _screen16;
     554        _screen16 = NULL;
     555#else
    527556        SDL_Surface *old_screen = _screen;
     557        _screen = NULL;
     558#endif
    528559        SDL_Surface *old_overlayscreen = _overlayscreen;
    529         _screen = NULL;
    530560        _overlayscreen = NULL;
    531561
    532562        // Release the HW screen surface
     
    544574        if (!loadGFXMode()) {
    545575                unloadGFXMode();
    546576
     577#ifdef ENABLE_16BIT
     578                _screen16 = old_screen;
     579#else
    547580                _screen = old_screen;
     581#endif
    548582                _overlayscreen = old_overlayscreen;
    549583
    550584                return false;
     
    554588        SDL_SetColors(_screen, _currentPalette, 0, 256);
    555589
    556590        // Restore old screen content
     591#ifdef ENABLE_16BIT
     592        SDL_BlitSurface(old_screen, NULL, _screen16, NULL);
     593#else
    557594        SDL_BlitSurface(old_screen, NULL, _screen, NULL);
     595#endif
    558596        SDL_BlitSurface(old_overlayscreen, NULL, _overlayscreen, NULL);
    559597
    560598        // Free the old surfaces
     
    636674#endif
    637675
    638676        if (!_overlayVisible) {
     677#ifdef ENABLE_16BIT
     678                origSurf = _screen16;
     679#else
    639680                origSurf = _screen;
     681#endif
    640682                srcSurf = _tmpscreen;
    641683                width = _videoMode.screenWidth;
    642684                height = _videoMode.screenHeight;
     
    781823        assert (_transactionMode == kTransactionNone);
    782824        assert(src);
    783825
     826#ifdef ENABLE_16BIT
     827        if (_screen16 == NULL) {
     828                warning("OSystem_SDL::copyRectToScreen: _screen16 == NULL");
     829                return;
     830        }
     831#endif
    784832        if (_screen == NULL) {
    785833                warning("OSystem_SDL::copyRectToScreen: _screen == NULL");
    786834                return;
     
    829877        }
    830878
    831879        // Try to lock the screen surface
     880#ifdef ENABLE_16BIT
     881        if (SDL_LockSurface(_screen16) == -1)
     882#else
    832883        if (SDL_LockSurface(_screen) == -1)
     884#endif
    833885                error("SDL_LockSurface failed: %s", SDL_GetError());
    834886
     887#ifdef ENABLE_16BIT
     888        byte *dst = (byte *)_screen16->pixels + y * _videoMode.screenWidth * 2 + x * 2;
     889        if (_videoMode.screenWidth == pitch && pitch == w * 2) {
     890                memcpy(dst, src, h*w*2);
     891        } else {
     892                do {
     893                        memcpy(dst, src, w * 2);
     894                        src += pitch;
     895                        dst += _videoMode.screenWidth * 2;
     896                } while (--h);
     897        }
     898
     899        // Unlock the screen surface
     900        SDL_UnlockSurface(_screen16);
     901#else
    835902        byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x;
    836 
    837903        if (_videoMode.screenWidth == pitch && pitch == w) {
    838904                memcpy(dst, src, h*w);
    839905        } else {
     
    846912
    847913        // Unlock the screen surface
    848914        SDL_UnlockSurface(_screen);
     915#endif
    849916}
    850917
    851918Graphics::Surface *OSystem_SDL::lockScreen() {
     
    859926        _screenIsLocked = true;
    860927
    861928        // Try to lock the screen surface
     929#ifdef ENABLE_16BIT
     930        if (SDL_LockSurface(_screen16) == -1)
     931#else
    862932        if (SDL_LockSurface(_screen) == -1)
     933#endif
    863934                error("SDL_LockSurface failed: %s", SDL_GetError());
    864935
     936#ifdef ENABLE_16BIT
     937        _framebuffer.pixels = _screen16->pixels;
     938        _framebuffer.w = _screen16->w;
     939        _framebuffer.h = _screen16->h;
     940        _framebuffer.pitch = _screen16->pitch;
     941        _framebuffer.bytesPerPixel = 2;
     942#else
    865943        _framebuffer.pixels = _screen->pixels;
    866944        _framebuffer.w = _screen->w;
    867945        _framebuffer.h = _screen->h;
    868946        _framebuffer.pitch = _screen->pitch;
    869947        _framebuffer.bytesPerPixel = 1;
     948#endif
    870949
    871950        return &_framebuffer;
    872951}
     
    879958        _screenIsLocked = false;
    880959
    881960        // Unlock the screen surface
     961#ifdef ENABLE_16BIT
     962        SDL_UnlockSurface(_screen16);
     963#else
    882964        SDL_UnlockSurface(_screen);
     965#endif
    883966
    884967        // Trigger a full screen update
    885968        _forceFull = true;
     
    10541137        // since we don't actually set the palette until the screen is updated.
    10551138        // But it could indicate a programming error, so let's warn about it.
    10561139
     1140#ifdef ENABLE_16BIT
     1141        if (!_screen16)
     1142                warning("OSystem_SDL::setPalette: _screen16 == NULL");
     1143#else
    10571144        if (!_screen)
    10581145                warning("OSystem_SDL::setPalette: _screen == NULL");
     1146#endif
    10591147
    10601148        const byte *b = colors;
    10611149        uint i;
     
    11791267        dst.x = dst.y = 1;
    11801268        src.w = dst.w = _videoMode.screenWidth;
    11811269        src.h = dst.h = _videoMode.screenHeight;
     1270#ifdef ENABLE_16BIT
     1271        if (SDL_BlitSurface(_screen16, &src, _tmpscreen, &dst) != 0)
     1272#else
    11821273        if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0)
     1274#endif
    11831275                error("SDL_BlitSurface failed: %s", SDL_GetError());
    11841276
    11851277        SDL_LockSurface(_tmpscreen);
  • backends/platform/sdl/sdl.cpp

     
    196196        _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0),
    197197#endif
    198198        _hwscreen(0), _screen(0), _tmpscreen(0),
     199#ifdef ENABLE_16BIT
     200        _screen16(0),
     201#endif
    199202        _overlayVisible(false),
    200203        _overlayscreen(0), _tmpscreen2(0),
    201204        _samplesPerSec(0),
  • backends/platform/sdl/sdl.h

     
    227227
    228228        // unseen game screen
    229229        SDL_Surface *_screen;
     230#ifdef ENABLE_16BIT
     231        SDL_Surface *_screen16;
     232#endif
    230233
    231234        // temporary screen (for scalers)
    232235        SDL_Surface *_tmpscreen;
  • dists/msvc8/scummvm.vcproj

     
    11<?xml version="1.0" encoding="windows-1252"?>
    22<VisualStudioProject
    33        ProjectType="Visual C++"
    4         Version="8,00"
     4        Version="8.00"
    55        Name="scummvm"
    66        ProjectGUID="{8434CB15-D08F-427D-9E6D-581AE5B28440}"
    77        RootNamespace="scummvm"
     
    4343                                Optimization="0"
    4444                                InlineFunctionExpansion="0"
    4545                                AdditionalIncludeDirectories="../../;../../engines"
    46                                 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;USE_ZLIB;USE_MAD;USE_VORBIS;USE_MPEG2;USE_NASM;USE_MT32EMU;ENABLE_AGI;ENABLE_AGOS;ENABLE_CINE;ENABLE_CRUISE;ENABLE_DRASCULA;ENABLE_GOB;ENABLE_IGOR;ENABLE_KYRA;ENABLE_LURE;ENABLE_M4;ENABLE_MADE;ENABLE_PARALLACTION;ENABLE_QUEEN;ENABLE_SAGA;ENABLE_SCI;ENABLE_SCUMM;ENABLE_SKY;ENABLE_SWORD1;ENABLE_SWORD2;ENABLE_TOUCHE;ENABLE_SCUMM_7_8;ENABLE_HE;ENABLE_TINSEL;ENABLE_TUCKER;ENABLE_GROOVIE"
     46                                PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;USE_ZLIB;USE_MAD;USE_VORBIS;USE_MPEG2;USE_NASM;USE_MT32EMU;ENABLE_AGI;ENABLE_AGOS;ENABLE_CINE;ENABLE_CRUISE;ENABLE_DRASCULA;ENABLE_GOB;ENABLE_IGOR;ENABLE_KYRA;ENABLE_LURE;ENABLE_M4;ENABLE_MADE;ENABLE_PARALLACTION;ENABLE_QUEEN;ENABLE_SAGA;ENABLE_SCI;ENABLE_SCUMM;ENABLE_SKY;ENABLE_SWORD1;ENABLE_SWORD2;ENABLE_TOUCHE;ENABLE_SCUMM_7_8;ENABLE_HE;ENABLE_TINSEL;ENABLE_TUCKER;ENABLE_GROOVIE; ENABLE_16BIT"
    4747                                MinimalRebuild="true"
    4848                                ExceptionHandling="1"
    4949                                BasicRuntimeChecks="3"
     
    100100                                Name="VCAppVerifierTool"
    101101                        />
    102102                        <Tool
     103                                Name="VCWebDeploymentTool"
     104                        />
     105                        <Tool
    103106                                Name="VCPostBuildEventTool"
    104107                        />
    105108                </Configuration>
     
    192195                                Name="VCAppVerifierTool"
    193196                        />
    194197                        <Tool
     198                                Name="VCWebDeploymentTool"
     199                        />
     200                        <Tool
    195201                                Name="VCPostBuildEventTool"
    196202                        />
    197203                </Configuration>