Skip to content

Commit

Permalink
atari:xbios: Let SDL handles centering on screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmandin committed Aug 22, 2014
1 parent 18106f4 commit 74ce543
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 59 deletions.
42 changes: 29 additions & 13 deletions src/video/xbios/SDL_xbios.c
Expand Up @@ -528,6 +528,8 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
#endif

this->UpdateRects = XBIOS_updRects;
XBIOS_recoffset = 2;

return (current);
}

Expand All @@ -552,6 +554,21 @@ static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
return;
}

static void recalc_offset(_THIS)
{
int offset_x;

offset_x = (XBIOS_current->width - this->screen->w)>>1;
offset_x &= ~15;

this->offset_x = offset_x;

this->screen->offset = this->offset_y*this->screen->pitch +
this->offset_x*this->screen->format->BytesPerPixel;

--XBIOS_recoffset;
}

static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
Expand All @@ -562,8 +579,12 @@ static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
int i;
int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);

if (XBIOS_recoffset>0) {
recalc_offset(this);
}

for (i=0;i<numrects;i++) {
void *source,*destination;
Uint8 *source,*destination;
int x1,x2;

x1 = rects[i].x & ~15;
Expand All @@ -576,7 +597,7 @@ static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
source += surface->pitch * rects[i].y;
source += x1;

destination = XBIOS_screens[XBIOS_fbnum];
destination = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
destination += XBIOS_pitch * rects[i].y;
destination += x1;

Expand All @@ -602,29 +623,24 @@ static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
XBIOS_fbnum ^= 1;
if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
surface->pixels=XBIOS_screens[XBIOS_fbnum];
surface->pixels=((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
}
}
}

static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
{
if (XBIOS_current->flags & XBIOSMODE_C2P) {
void *destscr;
int destx;
int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);

/* Center on destination screen */
destscr = XBIOS_screens[XBIOS_fbnum];
destscr += XBIOS_pitch * ((XBIOS_current->height - surface->h) >> 1);
destx = (XBIOS_current->width - surface->w) >> 1;
destx &= ~15;
destscr += destx;
if (XBIOS_recoffset>0) {
recalc_offset(this);
}

/* Convert chunky to planar screen */
SDL_Atari_C2pConvert(
surface->pixels,
destscr,
((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset,
surface->w,
surface->h,
doubleline,
Expand All @@ -642,7 +658,7 @@ static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
XBIOS_fbnum ^= 1;
if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
surface->pixels=XBIOS_screens[XBIOS_fbnum];
surface->pixels=((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/video/xbios/SDL_xbios.h
Expand Up @@ -56,6 +56,7 @@ struct SDL_PrivateVideoData {
void *shadowscreen; /* Shadow screen for c2p conversion */
int frame_number; /* Number of frame for double buffer */
int pitch; /* Destination line width for C2P */
int recalc_offset; /* Recalculate SDL_Surface offset for C2P */

xbiosmode_t *current; /* Current set mode */
int SDL_nummodes[NUM_MODELISTS];
Expand Down Expand Up @@ -113,6 +114,7 @@ enum {
#define XBIOS_fbnum (this->hidden->frame_number)
#define XBIOS_pitch (this->hidden->pitch)
#define XBIOS_current (this->hidden->current)
#define XBIOS_recoffset (this->hidden->recalc_offset)

#define TT_palette (this->hidden->palette.pal16)
#define F30_palette (this->hidden->palette.pal32)
Expand Down
41 changes: 14 additions & 27 deletions src/video/xbios/SDL_xbios_ctpci.c
Expand Up @@ -74,7 +74,6 @@ static void saveMode(_THIS, SDL_PixelFormat *vformat);
static void setMode(_THIS, xbiosmode_t *new_video_mode);
static void restoreMode(_THIS);
static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp);
static void swapVbuffers(_THIS);
static int allocVbuffers(_THIS, int num_buffers, int bufsize);
static void freeVbuffers(_THIS);
static void updateRects(_THIS, int numrects, SDL_Rect *rects);
Expand All @@ -87,7 +86,6 @@ void SDL_XBIOS_VideoInit_Ctpci(_THIS)
XBIOS_setMode = setMode;
XBIOS_restoreMode = restoreMode;
XBIOS_getLineWidth = getLineWidth;
XBIOS_swapVbuffers = swapVbuffers;
XBIOS_allocVbuffers = allocVbuffers;
XBIOS_freeVbuffers = freeVbuffers;

Expand Down Expand Up @@ -209,11 +207,6 @@ static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp)
return (retvalue);
}

static void swapVbuffers(_THIS)
{
VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], VN_MAGIC, CMD_SETADR);
}

static int allocVbuffers(_THIS, int num_buffers, int bufsize)
{
int i;
Expand Down Expand Up @@ -275,15 +268,9 @@ static void updateRects(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
int i;
/*unsigned long offset,size;*/

surface = this->screen;

/* Center on destination screen */
/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
destscr = (void *)((unsigned long)destscr+offset);*/

for (i=0;i<numrects;i++) {
Uint8 *blockSrcStart, *blockDstStart;
int y;
Expand All @@ -292,7 +279,7 @@ static void updateRects(_THIS, int numrects, SDL_Rect *rects)
blockSrcStart += surface->pitch*rects[i].y;
blockSrcStart += surface->format->BytesPerPixel*rects[i].x;

blockDstStart = (Uint8 *) XBIOS_screens[XBIOS_fbnum];
blockDstStart = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
blockDstStart += XBIOS_pitch*rects[i].y;
blockDstStart += surface->format->BytesPerPixel*rects[i].x;

Expand All @@ -309,29 +296,29 @@ static void updateRects(_THIS, int numrects, SDL_Rect *rects)

if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
XBIOS_fbnum ^= 1;
if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
surface->pixels=XBIOS_screens[XBIOS_fbnum];
}
}
}

static int flipHWSurface(_THIS, SDL_Surface *surface)
{
/* Center on destination screen */
/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
destscr = (void *)((unsigned long)destscr+offset);*/
int i;
Uint8 *src, *dst;

src = surface->pixels;
dst = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;

for (i=0; i<surface->h; i++) {
SDL_memcpy(dst, src, surface->w * surface->format->BytesPerPixel);
src += surface->pitch;
dst += XBIOS_pitch;

}

SDL_memcpy(XBIOS_screens[XBIOS_fbnum], surface->pixels, surface->h * surface->pitch);

VsetScreen(-1L, -1L, VN_MAGIC, CMD_FLIPPAGE);
Vsync();

if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
XBIOS_fbnum ^= 1;
if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
surface->pixels=XBIOS_screens[XBIOS_fbnum];
}
}

return(0);
Expand Down
32 changes: 13 additions & 19 deletions src/video/xbios/SDL_xbios_f30.c
Expand Up @@ -268,15 +268,9 @@ static void updateRects_SV(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
int i;
/*unsigned long offset,size;*/

surface = this->screen;

/* Center on destination screen */
/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
destscr = (void *)((unsigned long)destscr+offset);*/

for (i=0;i<numrects;i++) {
Uint8 *blockSrcStart, *blockDstStart;
int y;
Expand All @@ -285,7 +279,7 @@ static void updateRects_SV(_THIS, int numrects, SDL_Rect *rects)
blockSrcStart += surface->pitch*rects[i].y;
blockSrcStart += surface->format->BytesPerPixel*rects[i].x;

blockDstStart = (Uint8 *) XBIOS_screens[XBIOS_fbnum];
blockDstStart = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
blockDstStart += XBIOS_pitch*rects[i].y;
blockDstStart += surface->format->BytesPerPixel*rects[i].x;

Expand All @@ -302,29 +296,29 @@ static void updateRects_SV(_THIS, int numrects, SDL_Rect *rects)

if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
XBIOS_fbnum ^= 1;
if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
surface->pixels=XBIOS_screens[XBIOS_fbnum];
}
}
}

static int flipHWSurface_SV(_THIS, SDL_Surface *surface)
{
/* Center on destination screen */
/*offset=XBIOS_pitch * ((newScreenInfo.virtHeight - surface->h) >> 1);
offset=offset+(newScreenInfo.scrPlanes>>3)*((newScreenInfo.virtWidth - surface->w) >> 1);
destscr = (void *)((unsigned long)destscr+offset);*/
int i;
Uint8 *src, *dst;

src = surface->pixels;
dst = ((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;

for (i=0; i<surface->h; i++) {
SDL_memcpy(dst, src, surface->w * surface->format->BytesPerPixel);
src += surface->pitch;
dst += XBIOS_pitch;

}

SDL_memcpy(XBIOS_screens[XBIOS_fbnum], surface->pixels, surface->h * surface->pitch);

Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
Vsync();

if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
XBIOS_fbnum ^= 1;
if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
surface->pixels=XBIOS_screens[XBIOS_fbnum];
}
}

return(0);
Expand Down

0 comments on commit 74ce543

Please sign in to comment.