From 74ce543a49894134d48b09f15a67892e60234057 Mon Sep 17 00:00:00 2001 From: Patrice Mandin Date: Fri, 22 Aug 2014 12:40:49 +0200 Subject: [PATCH] atari:xbios: Let SDL handles centering on screen. --- src/video/xbios/SDL_xbios.c | 42 +++++++++++++++++++++---------- src/video/xbios/SDL_xbios.h | 2 ++ src/video/xbios/SDL_xbios_ctpci.c | 41 +++++++++++------------------- src/video/xbios/SDL_xbios_f30.c | 32 ++++++++++------------- 4 files changed, 58 insertions(+), 59 deletions(-) diff --git a/src/video/xbios/SDL_xbios.c b/src/video/xbios/SDL_xbios.c index 9b363d739..216c3cbac 100644 --- a/src/video/xbios/SDL_xbios.c +++ b/src/video/xbios/SDL_xbios.c @@ -528,6 +528,8 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, #endif this->UpdateRects = XBIOS_updRects; + XBIOS_recoffset = 2; + return (current); } @@ -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; @@ -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;ipitch * 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; @@ -602,7 +623,7 @@ 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; } } } @@ -610,21 +631,16 @@ static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects) 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, @@ -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; } } diff --git a/src/video/xbios/SDL_xbios.h b/src/video/xbios/SDL_xbios.h index 13c5169eb..766cb9f32 100644 --- a/src/video/xbios/SDL_xbios.h +++ b/src/video/xbios/SDL_xbios.h @@ -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]; @@ -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) diff --git a/src/video/xbios/SDL_xbios_ctpci.c b/src/video/xbios/SDL_xbios_ctpci.c index b6397a489..f3f2e3881 100644 --- a/src/video/xbios/SDL_xbios_ctpci.c +++ b/src/video/xbios/SDL_xbios_ctpci.c @@ -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); @@ -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; @@ -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; @@ -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;ipitch*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; @@ -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; ih; 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); diff --git a/src/video/xbios/SDL_xbios_f30.c b/src/video/xbios/SDL_xbios_f30.c index a7655069a..02645ad6a 100644 --- a/src/video/xbios/SDL_xbios_f30.c +++ b/src/video/xbios/SDL_xbios_f30.c @@ -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;ipitch*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; @@ -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; ih; 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);