diff --git a/Src/Display.h b/Src/Display.h index 23bbcb9..4128936 100644 --- a/Src/Display.h +++ b/Src/Display.h @@ -89,6 +89,7 @@ public: void Update_16(uint8 *src_pixels); void Update_32(uint8 *src_pixels); void Update_stretched(uint8 *src_pixels); + SDL_Surface *SurfaceFromC64Display(); char *GetTextMessage(); #endif bool NumLock(void); diff --git a/Src/Display_SDL.h b/Src/Display_SDL.h index 3e3e93e..0cd9041 100644 --- a/Src/Display_SDL.h +++ b/Src/Display_SDL.h @@ -66,6 +66,7 @@ enum { }; static Uint16 palette_16[PALETTE_SIZE]; static Uint32 palette_32[PALETTE_SIZE]; +SDL_Color sdl_palette[PALETTE_SIZE]; /* C64 keyboard matrix: @@ -337,6 +338,48 @@ void C64Display::Update() this->Update((Uint8*)screen); } +SDL_Surface *C64Display::SurfaceFromC64Display() +{ + Uint32 rmask,gmask,bmask,amask; + SDL_Surface *out; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif + + out = SDL_CreateRGBSurface(SDL_SWSURFACE, DISPLAY_X, DISPLAY_Y, 8, + rmask,gmask,bmask,amask); + if (!out) + return NULL; + + Uint8 *dst_pixels = (Uint8*)out->pixels; + const Uint16 src_pitch = DISPLAY_X; + + /* Draw 1-1 */ + for (int y = 0; y < DISPLAY_Y; y++) + { + for (int x = 0; x < DISPLAY_X; x++) + { + int src_off = y * src_pitch + x; + int dst_off = src_off; + Uint8 v = screen[src_off]; + + dst_pixels[ dst_off ] = v; + } + } + SDL_SetPalette(out, SDL_LOGPAL | SDL_PHYSPAL, sdl_palette, 0, PALETTE_SIZE); + + return out; +} + void C64Display::display_status_string(char *str, int seconds) { Uint32 time_now = SDL_GetTicks(); @@ -931,22 +974,21 @@ uint8 C64::poll_joystick(int port) void C64Display::InitColors(uint8 *colors) { - SDL_Color palette[PALETTE_SIZE]; for (int i=0; i<16; i++) { - palette[i].r = palette_red[i]; - palette[i].g = palette_green[i]; - palette[i].b = palette_blue[i]; + sdl_palette[i].r = palette_red[i]; + sdl_palette[i].g = palette_green[i]; + sdl_palette[i].b = palette_blue[i]; } - palette[fill_gray].r = palette[fill_gray].g = palette[fill_gray].b = 0xd0; - palette[shine_gray].r = palette[shine_gray].g = palette[shine_gray].b = 0xf0; - palette[shadow_gray].r = palette[shadow_gray].g = palette[shadow_gray].b = 0x80; - palette[red].r = 0xf0; - palette[red].g = palette[red].b = 0; - palette[green].g = 0xf0; - palette[green].r = palette[green].b = 0; + sdl_palette[fill_gray].r = sdl_palette[fill_gray].g = sdl_palette[fill_gray].b = 0xd0; + sdl_palette[shine_gray].r = sdl_palette[shine_gray].g = sdl_palette[shine_gray].b = 0xf0; + sdl_palette[shadow_gray].r = sdl_palette[shadow_gray].g = sdl_palette[shadow_gray].b = 0x80; + sdl_palette[red].r = 0xf0; + sdl_palette[red].g = sdl_palette[red].b = 0; + sdl_palette[green].g = 0xf0; + sdl_palette[green].r = sdl_palette[green].b = 0; if (real_screen->format->BitsPerPixel == 8) - SDL_SetColors(real_screen, palette, 0, PALETTE_SIZE); + SDL_SetColors(real_screen, sdl_palette, 0, PALETTE_SIZE); for (int i = 0; i < PALETTE_SIZE; i++) { int rs = real_screen->format->Rshift; int gs = real_screen->format->Gshift; diff --git a/Src/gui/game_info_box.hh b/Src/gui/game_info_box.hh index d84660a..ac58626 100644 --- a/Src/gui/game_info_box.hh +++ b/Src/gui/game_info_box.hh @@ -17,21 +17,12 @@ public: void setGameInfo(GameInfo *gi) { /* Make a copy */ - if (this->gi) - delete this->gi; - this->gi = new GameInfo(gi); + this->gi = gi; this->updateMessages(); } void loadGameInfo(const char *what) { - /* Reset the current game info */ - if (this->gi) - { - delete this->gi; - this->gi = NULL; - } - /* No need to do this for directories or the special "None" field */ if ( !(strcmp(what, "None") == 0 || what[0] == '[') ) diff --git a/Src/gui/game_info_menu.cpp b/Src/gui/game_info_menu.cpp index 10c356a..bfbe915 100644 --- a/Src/gui/game_info_menu.cpp +++ b/Src/gui/game_info_menu.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "gui.hh" #include "menu.hh" #include "game_info_box.hh" @@ -56,6 +59,13 @@ public: virtual void escapeCallback(int which) { + /* If we haven't' saved a screenshot, save it anyway */ + if (!this->box->gi->screenshot) + { + SDL_Surface *p = TheC64->TheDisplay->SurfaceFromC64Display(); + + this->box->gi->screenshot = p; + } Gui::gui->popView(); } @@ -94,6 +104,11 @@ public: this->gameInfo->setGameInfo(Gui::gui->cur_gameInfo); } + void viewPopCallback() + { + Gui::gui->cur_gameInfo = this->gameInfo->gi; + } + void draw(SDL_Surface *where) { SDL_Rect dst; diff --git a/Src/utils.cpp b/Src/utils.cpp index 15aa853..6e49815 100644 --- a/Src/utils.cpp +++ b/Src/utils.cpp @@ -185,7 +185,6 @@ static void png_user_error(png_structp ctx, png_const_charp str) fprintf(stderr, "libpng: error: %s\n", str); } - /* This is taken from http://encelo.netsons.org/programming/sdl (GPLed) */ void *sdl_surface_to_png(SDL_Surface *surf, size_t *out_sz) {