2015-05-13 18:47:23 +00:00
|
|
|
#include "sysconfig.h"
|
|
|
|
#include "sysdeps.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "uae.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "gui.h"
|
2016-04-24 09:45:29 +00:00
|
|
|
#include "memory.h"
|
|
|
|
#include "newcpu.h"
|
2015-05-13 18:47:23 +00:00
|
|
|
#include "custom.h"
|
2016-04-24 09:45:29 +00:00
|
|
|
#include "xwin.h"
|
2015-05-13 18:47:23 +00:00
|
|
|
#include "drawing.h"
|
2016-04-24 09:45:29 +00:00
|
|
|
#include "inputdevice.h"
|
2015-05-13 18:47:23 +00:00
|
|
|
#include "savestate.h"
|
2015-09-09 21:49:41 +02:00
|
|
|
#include "picasso96.h"
|
2015-05-13 18:47:23 +00:00
|
|
|
|
|
|
|
#include <png.h>
|
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_image.h>
|
|
|
|
#include <SDL_gfxPrimitives.h>
|
2016-04-24 09:45:29 +00:00
|
|
|
#include <SDL/SDL_ttf.h>
|
2015-09-09 21:49:41 +02:00
|
|
|
|
2015-05-13 18:47:23 +00:00
|
|
|
#ifdef ANDROIDSDL
|
|
|
|
#include <android/log.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
/* SDL variable for output of emulation */
|
2015-05-13 18:47:23 +00:00
|
|
|
SDL_Surface *prSDLScreen = NULL;
|
2015-09-09 21:49:41 +02:00
|
|
|
|
|
|
|
/* Possible screen modes (x and y resolutions) */
|
|
|
|
#define MAX_SCREEN_MODES 6
|
|
|
|
static int x_size_table[MAX_SCREEN_MODES] = { 640, 640, 800, 1024, 1152, 1280 };
|
|
|
|
static int y_size_table[MAX_SCREEN_MODES] = { 400, 480, 480, 768, 864, 960 };
|
|
|
|
|
|
|
|
static int red_bits, green_bits, blue_bits;
|
|
|
|
static int red_shift, green_shift, blue_shift;
|
|
|
|
|
2015-11-16 22:32:10 +01:00
|
|
|
struct PicassoResolution *DisplayModes;
|
|
|
|
struct MultiDisplay Displays[MAX_DISPLAYS];
|
2015-09-09 21:49:41 +02:00
|
|
|
|
2015-11-16 22:32:10 +01:00
|
|
|
int screen_is_picasso = 0;
|
2015-09-09 21:49:41 +02:00
|
|
|
|
|
|
|
static SDL_Surface *current_screenshot = NULL;
|
2015-05-13 18:47:23 +00:00
|
|
|
static char screenshot_filename_default[255]={
|
|
|
|
'/', 't', 'm', 'p', '/', 'n', 'u', 'l', 'l', '.', 'p', 'n', 'g', '\0'
|
|
|
|
};
|
|
|
|
char *screenshot_filename=(char *)&screenshot_filename_default[0];
|
|
|
|
FILE *screenshot_file=NULL;
|
|
|
|
static void CreateScreenshot(void);
|
|
|
|
static int save_thumb(char *path);
|
|
|
|
int delay_savestate_frame = 0;
|
|
|
|
|
|
|
|
#define VIDEO_FLAGS_INIT SDL_SWSURFACE|SDL_FULLSCREEN
|
|
|
|
#ifdef ANDROIDSDL
|
|
|
|
#define VIDEO_FLAGS VIDEO_FLAGS_INIT
|
|
|
|
#else
|
|
|
|
#define VIDEO_FLAGS VIDEO_FLAGS_INIT | SDL_DOUBLEBUF
|
|
|
|
#endif
|
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
|
2015-05-13 18:47:23 +00:00
|
|
|
static unsigned long previous_synctime = 0;
|
|
|
|
static unsigned long next_synctime = 0;
|
|
|
|
|
|
|
|
|
|
|
|
int graphics_setup (void)
|
|
|
|
{
|
2015-09-09 21:49:41 +02:00
|
|
|
#ifdef PICASSO96
|
2015-11-16 22:32:10 +01:00
|
|
|
picasso_InitResolutions();
|
2015-09-09 21:49:41 +02:00
|
|
|
InitPicasso96();
|
|
|
|
#endif
|
2015-05-13 18:47:23 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
#ifdef WITH_LOGGING
|
|
|
|
|
|
|
|
SDL_Surface *liveInfo = NULL;
|
|
|
|
TTF_Font *liveFont = NULL;
|
|
|
|
int liveInfoCounter = 0;
|
|
|
|
void ShowLiveInfo(char *msg)
|
|
|
|
{
|
|
|
|
if(liveFont == NULL)
|
|
|
|
{
|
|
|
|
TTF_Init();
|
|
|
|
liveFont = TTF_OpenFont("data/FreeSans.ttf", 12);
|
|
|
|
}
|
|
|
|
if(liveInfo != NULL)
|
|
|
|
SDL_FreeSurface(liveInfo);
|
|
|
|
SDL_Color col;
|
|
|
|
col.r = 0xbf;
|
|
|
|
col.g = 0xbf;
|
|
|
|
col.b = 0xbf;
|
|
|
|
liveInfo = TTF_RenderText_Solid(liveFont, msg, col);
|
|
|
|
liveInfoCounter = 50 * 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RefreshLiveInfo()
|
|
|
|
{
|
|
|
|
if(liveInfoCounter > 0)
|
|
|
|
{
|
|
|
|
SDL_Rect dst, src;
|
|
|
|
|
|
|
|
dst.x = 0;
|
|
|
|
dst.y = 2;
|
|
|
|
src.w = liveInfo->w;
|
|
|
|
src.h = liveInfo->h;
|
|
|
|
src.x = 0;
|
|
|
|
src.y = 0;
|
|
|
|
SDL_BlitSurface(liveInfo, &src, prSDLScreen, &dst);
|
|
|
|
liveInfoCounter--;
|
|
|
|
if(liveInfoCounter == 0)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(liveInfo);
|
|
|
|
liveInfo = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-05-13 18:47:23 +00:00
|
|
|
void InitAmigaVidMode(struct uae_prefs *p)
|
|
|
|
{
|
|
|
|
/* Initialize structure for Amiga video modes */
|
|
|
|
gfxvidinfo.pixbytes = 2;
|
|
|
|
gfxvidinfo.bufmem = (uae_u8 *)prSDLScreen->pixels;
|
2016-04-24 09:45:29 +00:00
|
|
|
gfxvidinfo.outwidth = p->gfx_size.width;
|
|
|
|
gfxvidinfo.outheight = p->gfx_size.height;
|
2015-05-13 18:47:23 +00:00
|
|
|
gfxvidinfo.rowbytes = prSDLScreen->pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void graphics_subshutdown (void)
|
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
if(prSDLScreen != NULL)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(prSDLScreen);
|
|
|
|
prSDLScreen = NULL;
|
|
|
|
}
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CalcPandoraWidth(struct uae_prefs *p)
|
|
|
|
{
|
|
|
|
int amigaWidth = p->gfx_size.width;
|
|
|
|
int amigaHeight = p->gfx_size.height;
|
|
|
|
int pandHeight = 480;
|
|
|
|
|
2015-11-16 22:32:10 +01:00
|
|
|
p->gfx_resolution = p->gfx_size.width > 600 ? 1 : 0;
|
2015-05-13 18:47:23 +00:00
|
|
|
if(amigaWidth > 600)
|
|
|
|
amigaWidth = amigaWidth / 2; // Hires selected, but we calc in lores
|
|
|
|
int pandWidth = (amigaWidth * pandHeight) / amigaHeight;
|
|
|
|
pandWidth = pandWidth & (~1);
|
|
|
|
if((pandWidth * amigaHeight) / pandHeight < amigaWidth)
|
|
|
|
pandWidth += 2;
|
|
|
|
if(pandWidth > 800)
|
|
|
|
pandWidth = 800;
|
|
|
|
p->gfx_size_fs.width = pandWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
static void open_screen(struct uae_prefs *p)
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
2015-09-09 21:49:41 +02:00
|
|
|
char layersize[20];
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
graphics_subshutdown();
|
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
if(!screen_is_picasso)
|
|
|
|
{
|
|
|
|
CalcPandoraWidth(p);
|
2016-07-10 13:48:11 +02:00
|
|
|
|
|
|
|
snprintf(layersize, 20, "%dx480", p->gfx_size_fs.width);
|
2015-09-09 21:49:41 +02:00
|
|
|
#ifndef WIN32
|
2016-07-10 13:48:11 +02:00
|
|
|
setenv("SDL_OMAP_LAYER_SIZE", layersize, 1);
|
2015-09-09 21:49:41 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-24 17:42:00 +01:00
|
|
|
#ifdef PICASSO96
|
2015-11-16 22:32:10 +01:00
|
|
|
if(picasso_vidinfo.height < 480)
|
|
|
|
snprintf(layersize, 20, "%dx480", picasso_vidinfo.width);
|
|
|
|
else
|
|
|
|
snprintf(layersize, 20, "%dx%d", picasso_vidinfo.width, picasso_vidinfo.height);
|
2016-01-24 17:42:00 +01:00
|
|
|
#endif
|
2015-05-13 18:47:23 +00:00
|
|
|
#ifndef WIN32
|
|
|
|
setenv("SDL_OMAP_LAYER_SIZE", layersize, 1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ANDROIDSDL
|
|
|
|
update_onscreen();
|
|
|
|
#endif
|
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
if(!screen_is_picasso)
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
2015-09-09 21:49:41 +02:00
|
|
|
if(prSDLScreen == NULL || prSDLScreen->w != p->gfx_size.width || prSDLScreen->h != p->gfx_size.height)
|
|
|
|
{
|
2015-05-13 18:47:23 +00:00
|
|
|
#if defined(PANDORA) && !defined(WIN32)
|
2015-09-09 21:49:41 +02:00
|
|
|
prSDLScreen = SDL_SetVideoMode(p->gfx_size.width, p->gfx_size.height, 16, SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF);
|
2015-05-13 18:47:23 +00:00
|
|
|
#elif defined(PANDORA) && defined(WIN32)
|
2015-09-09 21:49:41 +02:00
|
|
|
prSDLScreen = SDL_SetVideoMode(p->gfx_size.width, p->gfx_size.height, 16, SDL_SWSURFACE|SDL_DOUBLEBUF);
|
2015-05-13 18:47:23 +00:00
|
|
|
#else
|
2015-09-09 21:49:41 +02:00
|
|
|
prSDLScreen = SDL_SetVideoMode(p->gfx_size.width, p->gfx_size.height, 16, SDL_HWSURFACE|SDL_FULLSCREEN);
|
2015-05-13 18:47:23 +00:00
|
|
|
#endif
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-24 17:42:00 +01:00
|
|
|
#ifdef PICASSO96
|
2015-11-16 22:32:10 +01:00
|
|
|
prSDLScreen = SDL_SetVideoMode(picasso_vidinfo.width, picasso_vidinfo.height, 16, SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF);
|
2016-01-24 17:42:00 +01:00
|
|
|
#endif
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
if(prSDLScreen != NULL)
|
|
|
|
{
|
2015-10-11 14:23:51 +02:00
|
|
|
InitAmigaVidMode(p);
|
2015-09-09 21:49:41 +02:00
|
|
|
init_row_map();
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void update_display(struct uae_prefs *p)
|
|
|
|
{
|
|
|
|
open_screen(p);
|
|
|
|
|
2015-05-13 18:47:23 +00:00
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
|
|
|
|
|
|
framecnt = 1; // Don't draw frame before reset done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int check_prefs_changed_gfx (void)
|
|
|
|
{
|
|
|
|
int changed = 0;
|
|
|
|
|
|
|
|
if(currprefs.gfx_size.height != changed_prefs.gfx_size.height ||
|
|
|
|
currprefs.gfx_size.width != changed_prefs.gfx_size.width ||
|
2015-11-16 22:32:10 +01:00
|
|
|
currprefs.gfx_size_fs.width != changed_prefs.gfx_size_fs.width ||
|
|
|
|
currprefs.gfx_resolution != changed_prefs.gfx_resolution)
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
|
|
|
cfgfile_configuration_change(1);
|
|
|
|
currprefs.gfx_size.height = changed_prefs.gfx_size.height;
|
|
|
|
currprefs.gfx_size.width = changed_prefs.gfx_size.width;
|
|
|
|
currprefs.gfx_size_fs.width = changed_prefs.gfx_size_fs.width;
|
2015-11-16 22:32:10 +01:00
|
|
|
currprefs.gfx_resolution = changed_prefs.gfx_resolution;
|
2015-05-13 18:47:23 +00:00
|
|
|
update_display(&currprefs);
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
if (currprefs.leds_on_screen != changed_prefs.leds_on_screen ||
|
2016-06-25 09:23:49 +00:00
|
|
|
currprefs.pandora_hide_idle_led != changed_prefs.pandora_hide_idle_led ||
|
2015-05-13 18:47:23 +00:00
|
|
|
currprefs.pandora_vertical_offset != changed_prefs.pandora_vertical_offset)
|
|
|
|
{
|
|
|
|
currprefs.leds_on_screen = changed_prefs.leds_on_screen;
|
2016-06-25 09:23:49 +00:00
|
|
|
currprefs.pandora_hide_idle_led = changed_prefs.pandora_hide_idle_led;
|
2015-05-13 18:47:23 +00:00
|
|
|
currprefs.pandora_vertical_offset = changed_prefs.pandora_vertical_offset;
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
if (currprefs.chipset_refreshrate != changed_prefs.chipset_refreshrate)
|
|
|
|
{
|
|
|
|
currprefs.chipset_refreshrate = changed_prefs.chipset_refreshrate;
|
2016-04-24 09:45:29 +00:00
|
|
|
init_hz_full ();
|
2015-05-13 18:47:23 +00:00
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int lockscr (void)
|
|
|
|
{
|
2015-09-09 21:49:41 +02:00
|
|
|
SDL_LockSurface(prSDLScreen);
|
|
|
|
return 1;
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void unlockscr (void)
|
|
|
|
{
|
2015-09-09 21:49:41 +02:00
|
|
|
SDL_UnlockSurface(prSDLScreen);
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 14:23:51 +02:00
|
|
|
void flush_screen ()
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
|
|
|
if (savestate_state == STATE_DOSAVE)
|
|
|
|
{
|
|
|
|
if(delay_savestate_frame > 0)
|
|
|
|
--delay_savestate_frame;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CreateScreenshot();
|
|
|
|
save_thumb(screenshot_filename);
|
|
|
|
savestate_state = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long start = read_processor_time();
|
|
|
|
if(start < next_synctime && next_synctime - start > time_per_frame - 1000)
|
2015-09-09 21:49:41 +02:00
|
|
|
usleep((next_synctime - start) - 750);
|
2015-11-16 22:32:10 +01:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
#ifdef WITH_LOGGING
|
|
|
|
RefreshLiveInfo();
|
|
|
|
#endif
|
|
|
|
|
2015-11-16 22:32:10 +01:00
|
|
|
SDL_Flip(prSDLScreen);
|
|
|
|
last_synctime = read_processor_time();
|
|
|
|
|
|
|
|
if(!screen_is_picasso)
|
2015-10-11 14:23:51 +02:00
|
|
|
gfxvidinfo.bufmem = (uae_u8 *)prSDLScreen->pixels;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-06-25 09:23:49 +00:00
|
|
|
if(last_synctime - next_synctime > time_per_frame - 1000 || next_synctime < start)
|
2015-05-13 18:47:23 +00:00
|
|
|
adjust_idletime(0);
|
|
|
|
else
|
|
|
|
adjust_idletime(next_synctime - start);
|
|
|
|
|
|
|
|
if(last_synctime - next_synctime > time_per_frame - 5000)
|
|
|
|
next_synctime = last_synctime + time_per_frame * (1 + currprefs.gfx_framerate);
|
|
|
|
else
|
|
|
|
next_synctime = next_synctime + time_per_frame * (1 + currprefs.gfx_framerate);
|
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
init_row_map();
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void black_screen_now(void)
|
|
|
|
{
|
|
|
|
SDL_FillRect(prSDLScreen,NULL,0);
|
|
|
|
SDL_Flip(prSDLScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void graphics_subinit (void)
|
|
|
|
{
|
|
|
|
if (prSDLScreen == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SDL_Flip(prSDLScreen);
|
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
|
|
|
|
|
|
InitAmigaVidMode(&currprefs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC_INLINE int bitsInMask (unsigned long mask)
|
|
|
|
{
|
|
|
|
/* count bits in mask */
|
|
|
|
int n = 0;
|
|
|
|
while (mask)
|
|
|
|
{
|
|
|
|
n += mask & 1;
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
STATIC_INLINE int maskShift (unsigned long mask)
|
|
|
|
{
|
|
|
|
/* determine how far mask is shifted */
|
|
|
|
int n = 0;
|
|
|
|
while (!(mask & 1))
|
|
|
|
{
|
|
|
|
n++;
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int init_colors (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int red_bits, green_bits, blue_bits;
|
|
|
|
int red_shift, green_shift, blue_shift;
|
|
|
|
|
|
|
|
/* Truecolor: */
|
|
|
|
red_bits = bitsInMask(prSDLScreen->format->Rmask);
|
|
|
|
green_bits = bitsInMask(prSDLScreen->format->Gmask);
|
|
|
|
blue_bits = bitsInMask(prSDLScreen->format->Bmask);
|
|
|
|
red_shift = maskShift(prSDLScreen->format->Rmask);
|
|
|
|
green_shift = maskShift(prSDLScreen->format->Gmask);
|
|
|
|
blue_shift = maskShift(prSDLScreen->format->Bmask);
|
|
|
|
alloc_colors64k (red_bits, green_bits, blue_bits, red_shift, green_shift, blue_shift, 0);
|
2015-09-09 21:49:41 +02:00
|
|
|
notice_new_xcolors();
|
2015-05-13 18:47:23 +00:00
|
|
|
for (i = 0; i < 4096; i++)
|
|
|
|
xcolors[i] = xcolors[i] * 0x00010001;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
/*
|
|
|
|
* Find the colour depth of the display
|
|
|
|
*/
|
|
|
|
static int get_display_depth (void)
|
|
|
|
{
|
|
|
|
const SDL_VideoInfo *vid_info;
|
|
|
|
int depth = 0;
|
|
|
|
|
|
|
|
if ((vid_info = SDL_GetVideoInfo())) {
|
|
|
|
depth = vid_info->vfmt->BitsPerPixel;
|
|
|
|
|
|
|
|
/* Don't trust the answer if it's 16 bits; the display
|
|
|
|
* could actually be 15 bits deep. We'll count the bits
|
|
|
|
* ourselves */
|
|
|
|
if (depth == 16)
|
|
|
|
depth = bitsInMask (vid_info->vfmt->Rmask) + bitsInMask (vid_info->vfmt->Gmask) + bitsInMask (vid_info->vfmt->Bmask);
|
|
|
|
}
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-16 22:32:10 +01:00
|
|
|
int GetSurfacePixelFormat(void)
|
|
|
|
{
|
|
|
|
int depth = get_display_depth();
|
|
|
|
int unit = (depth + 1) & 0xF8;
|
|
|
|
|
|
|
|
return (unit == 8 ? RGBFB_CHUNKY
|
|
|
|
: depth == 15 && unit == 16 ? RGBFB_R5G5B5
|
|
|
|
: depth == 16 && unit == 16 ? RGBFB_R5G6B5
|
|
|
|
: unit == 24 ? RGBFB_B8G8R8
|
|
|
|
: unit == 32 ? RGBFB_R8G8B8A8
|
|
|
|
: RGBFB_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-13 18:47:23 +00:00
|
|
|
int graphics_init (void)
|
|
|
|
{
|
|
|
|
graphics_subinit ();
|
|
|
|
|
|
|
|
if (!init_colors ())
|
|
|
|
return 0;
|
2015-09-09 21:49:41 +02:00
|
|
|
|
2015-05-13 18:47:23 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void graphics_leave (void)
|
|
|
|
{
|
|
|
|
graphics_subshutdown ();
|
|
|
|
SDL_VideoQuit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define systemRedShift (prSDLScreen->format->Rshift)
|
|
|
|
#define systemGreenShift (prSDLScreen->format->Gshift)
|
|
|
|
#define systemBlueShift (prSDLScreen->format->Bshift)
|
|
|
|
#define systemRedMask (prSDLScreen->format->Rmask)
|
|
|
|
#define systemGreenMask (prSDLScreen->format->Gmask)
|
|
|
|
#define systemBlueMask (prSDLScreen->format->Bmask)
|
|
|
|
|
|
|
|
static int save_png(SDL_Surface* surface, char *path)
|
|
|
|
{
|
|
|
|
int w = surface->w;
|
|
|
|
int h = surface->h;
|
|
|
|
unsigned char * pix = (unsigned char *)surface->pixels;
|
|
|
|
unsigned char writeBuffer[1024 * 3];
|
|
|
|
FILE *f = fopen(path,"wb");
|
|
|
|
if(!f) return 0;
|
|
|
|
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if(!png_ptr) {
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
png_infop info_ptr = png_create_info_struct(png_ptr);
|
|
|
|
|
|
|
|
if(!info_ptr) {
|
|
|
|
png_destroy_write_struct(&png_ptr,NULL);
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
png_init_io(png_ptr,f);
|
|
|
|
|
|
|
|
png_set_IHDR(png_ptr,
|
|
|
|
info_ptr,
|
|
|
|
w,
|
|
|
|
h,
|
|
|
|
8,
|
|
|
|
PNG_COLOR_TYPE_RGB,
|
|
|
|
PNG_INTERLACE_NONE,
|
|
|
|
PNG_COMPRESSION_TYPE_DEFAULT,
|
|
|
|
PNG_FILTER_TYPE_DEFAULT);
|
|
|
|
|
|
|
|
png_write_info(png_ptr,info_ptr);
|
|
|
|
|
|
|
|
unsigned char *b = writeBuffer;
|
|
|
|
|
|
|
|
int sizeX = w;
|
|
|
|
int sizeY = h;
|
|
|
|
int y;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
unsigned short *p = (unsigned short *)pix;
|
|
|
|
for(y = 0; y < sizeY; y++)
|
|
|
|
{
|
|
|
|
for(x = 0; x < sizeX; x++)
|
|
|
|
{
|
|
|
|
unsigned short v = p[x];
|
|
|
|
|
|
|
|
*b++ = ((v & systemRedMask ) >> systemRedShift ) << 3; // R
|
|
|
|
*b++ = ((v & systemGreenMask) >> systemGreenShift) << 2; // G
|
|
|
|
*b++ = ((v & systemBlueMask ) >> systemBlueShift ) << 3; // B
|
|
|
|
}
|
|
|
|
p += surface->pitch / 2;
|
|
|
|
png_write_row(png_ptr,writeBuffer);
|
|
|
|
b = writeBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
png_write_end(png_ptr, info_ptr);
|
|
|
|
|
|
|
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CreateScreenshot(void)
|
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
if(current_screenshot != NULL)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(current_screenshot);
|
|
|
|
current_screenshot = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
w=prSDLScreen->w;
|
|
|
|
h=prSDLScreen->h;
|
2015-09-09 21:49:41 +02:00
|
|
|
current_screenshot = SDL_CreateRGBSurfaceFrom(prSDLScreen->pixels, w, h, prSDLScreen->format->BitsPerPixel, prSDLScreen->pitch,
|
|
|
|
prSDLScreen->format->Rmask, prSDLScreen->format->Gmask, prSDLScreen->format->Bmask, prSDLScreen->format->Amask);
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int save_thumb(char *path)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
if(current_screenshot != NULL)
|
|
|
|
{
|
|
|
|
ret = save_png(current_screenshot, path);
|
|
|
|
SDL_FreeSurface(current_screenshot);
|
|
|
|
current_screenshot = NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2015-09-09 21:49:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef PICASSO96
|
|
|
|
|
2016-07-10 13:48:11 +02:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
int picasso_palette (void)
|
|
|
|
{
|
|
|
|
int i, changed;
|
|
|
|
|
|
|
|
changed = 0;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
int r = picasso96_state.CLUT[i].Red;
|
|
|
|
int g = picasso96_state.CLUT[i].Green;
|
|
|
|
int b = picasso96_state.CLUT[i].Blue;
|
|
|
|
uae_u32 v = CONVERT_RGB(r << 16 | g << 8 | b);
|
|
|
|
if (v != picasso_vidinfo.clut[i]) {
|
|
|
|
picasso_vidinfo.clut[i] = v;
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
2015-09-09 21:49:41 +02:00
|
|
|
|
2015-11-16 22:32:10 +01:00
|
|
|
static int resolution_compare (const void *a, const void *b)
|
2015-09-09 21:49:41 +02:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
struct PicassoResolution *ma = (struct PicassoResolution *)a;
|
|
|
|
struct PicassoResolution *mb = (struct PicassoResolution *)b;
|
|
|
|
if (ma->res.width < mb->res.width)
|
|
|
|
return -1;
|
|
|
|
if (ma->res.width > mb->res.width)
|
|
|
|
return 1;
|
|
|
|
if (ma->res.height < mb->res.height)
|
|
|
|
return -1;
|
|
|
|
if (ma->res.height > mb->res.height)
|
|
|
|
return 1;
|
|
|
|
return ma->depth - mb->depth;
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
2015-11-16 22:32:10 +01:00
|
|
|
static void sortmodes (void)
|
2015-09-09 21:49:41 +02:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
int i = 0, idx = -1;
|
|
|
|
int pw = -1, ph = -1;
|
|
|
|
while (DisplayModes[i].depth >= 0)
|
|
|
|
i++;
|
|
|
|
qsort (DisplayModes, i, sizeof (struct PicassoResolution), resolution_compare);
|
|
|
|
for (i = 0; DisplayModes[i].depth >= 0; i++) {
|
|
|
|
if (DisplayModes[i].res.height != ph || DisplayModes[i].res.width != pw) {
|
2015-11-16 22:32:10 +01:00
|
|
|
ph = DisplayModes[i].res.height;
|
|
|
|
pw = DisplayModes[i].res.width;
|
|
|
|
idx++;
|
2016-04-24 09:45:29 +00:00
|
|
|
}
|
|
|
|
DisplayModes[i].residx = idx;
|
|
|
|
}
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:32:10 +01:00
|
|
|
static void modesList (void)
|
2015-09-09 21:49:41 +02:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
int i, j;
|
2015-11-16 22:32:10 +01:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
i = 0;
|
|
|
|
while (DisplayModes[i].depth >= 0) {
|
|
|
|
write_log ("%d: %s (", i, DisplayModes[i].name);
|
|
|
|
j = 0;
|
|
|
|
while (DisplayModes[i].refresh[j] > 0) {
|
2015-11-16 22:32:10 +01:00
|
|
|
if (j > 0)
|
2016-04-24 09:45:29 +00:00
|
|
|
write_log (",");
|
2015-11-16 22:32:10 +01:00
|
|
|
write_log ("%d", DisplayModes[i].refresh[j]);
|
|
|
|
j++;
|
2016-04-24 09:45:29 +00:00
|
|
|
}
|
|
|
|
write_log (")\n");
|
|
|
|
i++;
|
|
|
|
}
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:32:10 +01:00
|
|
|
void picasso_InitResolutions (void)
|
2015-09-09 21:49:41 +02:00
|
|
|
{
|
2015-11-16 22:32:10 +01:00
|
|
|
struct MultiDisplay *md1;
|
2015-09-09 21:49:41 +02:00
|
|
|
int i, count = 0;
|
2015-11-16 22:32:10 +01:00
|
|
|
char tmp[200];
|
2016-04-24 09:45:29 +00:00
|
|
|
int bit_idx;
|
|
|
|
int bits[] = { 8, 16, 32 };
|
2015-11-16 22:32:10 +01:00
|
|
|
|
|
|
|
Displays[0].primary = 1;
|
|
|
|
Displays[0].disabled = 0;
|
|
|
|
Displays[0].rect.left = 0;
|
|
|
|
Displays[0].rect.top = 0;
|
|
|
|
Displays[0].rect.right = 800;
|
|
|
|
Displays[0].rect.bottom = 640;
|
|
|
|
sprintf (tmp, "%s (%d*%d)", "Display", Displays[0].rect.right, Displays[0].rect.bottom);
|
|
|
|
Displays[0].name = my_strdup(tmp);
|
|
|
|
Displays[0].name2 = my_strdup("Display");
|
|
|
|
|
|
|
|
md1 = Displays;
|
2016-04-24 09:45:29 +00:00
|
|
|
DisplayModes = md1->DisplayModes = xmalloc (struct PicassoResolution, MAX_PICASSO_MODES);
|
2015-09-09 21:49:41 +02:00
|
|
|
for (i = 0; i < MAX_SCREEN_MODES && count < MAX_PICASSO_MODES; i++) {
|
2016-04-24 09:45:29 +00:00
|
|
|
for(bit_idx = 0; bit_idx < 3; ++bit_idx) {
|
|
|
|
int bitdepth = bits[bit_idx];
|
2015-11-16 22:32:10 +01:00
|
|
|
int bit_unit = (bitdepth + 1) & 0xF8;
|
2016-04-24 09:45:29 +00:00
|
|
|
int rgbFormat = (bitdepth == 8 ? RGBFB_CLUT : (bitdepth == 16 ? RGBFB_R5G6B5 : RGBFB_R8G8B8A8));
|
2015-11-16 22:32:10 +01:00
|
|
|
int pixelFormat = 1 << rgbFormat;
|
|
|
|
pixelFormat |= RGBFF_CHUNKY;
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
if (SDL_VideoModeOK (x_size_table[i], y_size_table[i], 16, SDL_SWSURFACE))
|
2015-11-16 22:32:10 +01:00
|
|
|
{
|
|
|
|
DisplayModes[count].res.width = x_size_table[i];
|
|
|
|
DisplayModes[count].res.height = y_size_table[i];
|
|
|
|
DisplayModes[count].depth = bit_unit >> 3;
|
|
|
|
DisplayModes[count].refresh[0] = 50;
|
|
|
|
DisplayModes[count].refresh[1] = 60;
|
|
|
|
DisplayModes[count].refresh[2] = 0;
|
|
|
|
DisplayModes[count].colormodes = pixelFormat;
|
|
|
|
sprintf(DisplayModes[count].name, "%dx%d, %d-bit",
|
|
|
|
DisplayModes[count].res.width, DisplayModes[count].res.height, DisplayModes[count].depth * 8);
|
|
|
|
|
|
|
|
count++;
|
|
|
|
}
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DisplayModes[count].depth = -1;
|
2015-11-16 22:32:10 +01:00
|
|
|
sortmodes();
|
|
|
|
modesList();
|
|
|
|
DisplayModes = Displays[0].DisplayModes;
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
void gfx_set_picasso_state (int on)
|
|
|
|
{
|
|
|
|
if (on == screen_is_picasso)
|
|
|
|
return;
|
|
|
|
|
|
|
|
screen_is_picasso = on;
|
|
|
|
open_screen(&currprefs);
|
|
|
|
picasso_vidinfo.rowbytes = prSDLScreen->pitch;
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
void gfx_set_picasso_modeinfo (uae_u32 w, uae_u32 h, uae_u32 depth, RGBFTYPE rgbfmt)
|
|
|
|
{
|
|
|
|
depth >>= 3;
|
|
|
|
if( ((unsigned)picasso_vidinfo.width == w ) &&
|
|
|
|
( (unsigned)picasso_vidinfo.height == h ) &&
|
|
|
|
( (unsigned)picasso_vidinfo.depth == depth ) &&
|
|
|
|
( picasso_vidinfo.selected_rgbformat == rgbfmt) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
picasso_vidinfo.selected_rgbformat = rgbfmt;
|
|
|
|
picasso_vidinfo.width = w;
|
|
|
|
picasso_vidinfo.height = h;
|
2016-04-24 09:45:29 +00:00
|
|
|
picasso_vidinfo.depth = 2; // Native depth
|
2015-09-09 21:49:41 +02:00
|
|
|
picasso_vidinfo.extra_mem = 1;
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
picasso_vidinfo.pixbytes = 2; // Native bytes
|
2015-09-09 21:49:41 +02:00
|
|
|
if (screen_is_picasso)
|
|
|
|
{
|
|
|
|
open_screen(&currprefs);
|
|
|
|
picasso_vidinfo.rowbytes = prSDLScreen->pitch;
|
2016-04-24 09:45:29 +00:00
|
|
|
picasso_vidinfo.rgbformat = RGBFB_R5G6B5;
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uae_u8 *gfx_lock_picasso (void)
|
|
|
|
{
|
|
|
|
SDL_LockSurface(prSDLScreen);
|
|
|
|
picasso_vidinfo.rowbytes = prSDLScreen->pitch;
|
|
|
|
return (uae_u8 *)prSDLScreen->pixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_unlock_picasso (void)
|
|
|
|
{
|
|
|
|
SDL_UnlockSurface(prSDLScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PICASSO96
|