5 #include <X11/extensions/Xsp.h>
15 #define DIE(format, ...) do { \
16 fprintf(stderr, "Died at %s:%d: ", __FILE__, __LINE__ ); \
17 fprintf(stderr, format "\n", ## __VA_ARGS__); \
21 static SDL_Surface *screen;
23 static void setDoubling(bool enable)
26 SDL_VERSION(&wminfo.version);
27 if ( SDL_GetWMInfo(&wminfo) ) {
28 XSPSetPixelDoubling(wminfo.info.x11.display, 0, enable ? 1 : 0);
32 void S9xSetTitle(const char *title)
35 SDL_VERSION(&info.version);
36 if ( SDL_GetWMInfo(&info) ) {
37 Display *dpy = info.info.x11.display;
40 win = info.info.x11.fswindow;
41 if (win) XStoreName(dpy, win, title);
42 win = info.info.x11.wmwindow;
43 if (win) XStoreName(dpy, win, title);
48 static void freeVideoSurface()
50 screen = 0; // There's no need to free the screen surface.
53 free(GFX.SubScreen); GFX.SubScreen = 0;
54 free(GFX.ZBuffer); GFX.ZBuffer = 0;
55 free(GFX.SubZBuffer); GFX.SubZBuffer = 0;
58 static void setupVideoSurface()
63 // By now, just assume xsp == fullscreen. This has to change.
64 Config.xsp = Config.fullscreen;
69 setDoubling(false); // Before switching video modes
72 screen = SDL_SetVideoMode(w, h,
73 Settings.SixteenBit ? 16 : 8,
75 (Config.fullscreen ? SDL_FULLSCREEN : 0));
78 DIE("SDL_SetVideoMode: %s", SDL_GetError());
80 SDL_ShowCursor(SDL_DISABLE);
82 if (Config.xsp) setDoubling(true);
84 GFX.RealPitch = GFX.Pitch = screen->pitch;
86 GFX.Screen = (uint8*) screen->pixels;
87 GFX.SubScreen = (uint8 *) malloc(GFX.RealPitch * IMAGE_HEIGHT);
88 GFX.ZBuffer = (uint8 *) malloc(GFX.RealPitch * IMAGE_HEIGHT);
89 GFX.SubZBuffer = (uint8 *) malloc(GFX.RealPitch * IMAGE_HEIGHT);
91 GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;
92 GFX.PPL = GFX.Pitch >> 1;
93 GFX.PPLx2 = GFX.Pitch;
94 GFX.ZPitch = GFX.Pitch >> 1;
96 printf("Video: %dx%d, %hu bits per pixel, %s %s\n", screen->w, screen->h,
97 screen->format->BitsPerPixel,
98 Config.fullscreen ? "fullscreen" : "windowed",
99 Config.xsp ? "with pixel doubling" : "");
102 void S9xInitDisplay(int argc, const char ** argv)
104 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
105 DIE("SDL_InitSubSystem(VIDEO): %s", SDL_GetError());
110 void S9xDeinitDisplay()
113 SDL_QuitSubSystem(SDL_INIT_VIDEO);
116 void S9xVideoToggleFullscreen()
118 Config.fullscreen = !Config.fullscreen;
123 void S9xVideoOutputFocus(bool hasFocus)
126 setDoubling(hasFocus);
130 // This is here for completeness, but palette mode is useless on N8x0
131 void S9xSetPalette ()
133 if (Settings.SixteenBit) return;
135 SDL_Color colors[256];
136 int brightness = IPPU.MaxBrightness *138;
137 for (int i = 0; i < 256; i++)
139 colors[i].r = ((PPU.CGDATA[i] >> 0) & 0x1F) * brightness;
140 colors[i].g = ((PPU.CGDATA[i] >> 5) & 0x1F) * brightness;
141 colors[i].b = ((PPU.CGDATA[i] >> 10) & 0x1F) * brightness;
144 SDL_SetColors(screen, colors, 0, 256);
147 bool8_32 S9xInitUpdate ()
149 if(SDL_MUSTLOCK(screen))
151 if(SDL_LockSurface(screen) < 0) {
152 DIE("Failed to lock SDL surface: %s", SDL_GetError());
159 bool8_32 S9xDeinitUpdate (int width, int height, bool8_32 sixteenBit)
161 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
168 SDL_UpdateRect(screen, 0, 0, width, height);