Skip to content

Commit

Permalink
atari:xbios: Add function to get line width.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmandin committed Aug 3, 2014
1 parent 74dffe6 commit 54638e7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/video/xbios/SDL_xbios.c
Expand Up @@ -409,6 +409,7 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
xbiosmode_t *new_video_mode;
Uint32 new_screen_size;
Uint32 modeflags;
Uint32 lineWidth;

/* Free current buffers */
XBIOS_FreeBuffers(this);
Expand Down Expand Up @@ -442,7 +443,9 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
modeflags |= SDL_HWSURFACE;
}

new_screen_size = width * height * ((new_depth)>>3);
lineWidth = (*XBIOS_getLineWidth)(this, new_video_mode, width, new_depth);

new_screen_size = lineWidth * height;
new_screen_size += 256; /* To align on a 256 byte adress */

if (new_video_mode->flags & XBIOSMODE_C2P) {
Expand Down Expand Up @@ -491,10 +494,10 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
XBIOS_current = new_video_mode;
current->w = width;
current->h = height;
current->pitch = (width * new_depth)>>3;
current->pitch = lineWidth;

/* this is for C2P conversion */
XBIOS_pitch = (new_video_mode->width * new_video_mode->depth)>>3;
XBIOS_pitch = (*XBIOS_getLineWidth)(this, new_video_mode, new_video_mode->width, new_video_mode->depth);

if (XBIOS_shadowscreen)
current->pixels = XBIOS_shadowscreen;
Expand Down
2 changes: 2 additions & 0 deletions src/video/xbios/SDL_xbios.h
Expand Up @@ -71,6 +71,7 @@ struct SDL_PrivateVideoData {
void (*saveMode)(_THIS, SDL_PixelFormat *vformat); /* Save mode,palette,vbase change format if needed */
void (*setMode)(_THIS, xbiosmode_t *new_video_mode); /* Set mode */
void (*restoreMode)(_THIS); /* Restore system mode */
int (*getLineWidth)(_THIS, xbiosmode_t *new_video_mode, int width, int bpp); /* Return video mode pitch */
void (*swapVbuffers)(_THIS); /* Swap video buffers */
int (*allocVbuffers)(_THIS, int num_buffers, int bufsize); /* Allocate video buffers */
void (*freeVbuffers)(_THIS); /* Free video buffers */
Expand Down Expand Up @@ -120,6 +121,7 @@ enum {
#define XBIOS_saveMode (this->hidden->saveMode)
#define XBIOS_setMode (this->hidden->setMode)
#define XBIOS_restoreMode (this->hidden->restoreMode)
#define XBIOS_getLineWidth (this->hidden->getLineWidth)
#define XBIOS_swapVbuffers (this->hidden->swapVbuffers)
#define XBIOS_allocVbuffers (this->hidden->allocVbuffers)
#define XBIOS_freeVbuffers (this->hidden->freeVbuffers)
Expand Down
30 changes: 19 additions & 11 deletions src/video/xbios/SDL_xbios_ctpci.c
Expand Up @@ -73,6 +73,7 @@ static void listModes(_THIS, int actually_add);
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);
Expand All @@ -85,6 +86,7 @@ void SDL_XBIOS_VideoInit_Ctpci(_THIS)
XBIOS_saveMode = saveMode;
XBIOS_setMode = setMode;
XBIOS_restoreMode = restoreMode;
XBIOS_getLineWidth = getLineWidth;
XBIOS_swapVbuffers = swapVbuffers;
XBIOS_allocVbuffers = allocVbuffers;
XBIOS_freeVbuffers = freeVbuffers;
Expand Down Expand Up @@ -170,8 +172,6 @@ static void saveMode(_THIS, SDL_PixelFormat *vformat)

static void setMode(_THIS, xbiosmode_t *new_video_mode)
{
SCREENINFO si;

VsetScreen(-1, XBIOS_screens[0], VN_MAGIC, CMD_SETADR);

VsetScreen(-1, new_video_mode->number, VN_MAGIC, CMD_SETMODE);
Expand All @@ -181,15 +181,6 @@ static void setMode(_THIS, xbiosmode_t *new_video_mode)
SDL_memset(F30_palette, 0, sizeof(F30_palette));
VsetRGB(0,256,F30_palette);
}

/* Set pitch of new mode */
si.size = sizeof(SCREENINFO);
si.devID = new_video_mode->number;
si.scrFlags = 0;
VsetScreen(-1, &si, VN_MAGIC, CMD_GETINFO);
if (si.scrFlags & SCRINFO_OK) {
XBIOS_pitch = si.lineWrap;
}
}

static void restoreMode(_THIS)
Expand All @@ -201,6 +192,23 @@ static void restoreMode(_THIS)
}
}

static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp)
{
SCREENINFO si;
int retvalue = width * (((bpp==15) ? 16 : bpp)>>3);

/* Set pitch of new mode */
si.size = sizeof(SCREENINFO);
si.devID = new_video_mode->number;
si.scrFlags = 0;
VsetScreen(-1, &si, VN_MAGIC, CMD_GETINFO);
if (si.scrFlags & SCRINFO_OK) {
retvalue = si.lineWrap;
}

return (retvalue);
}

static void swapVbuffers(_THIS)
{
VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], VN_MAGIC, CMD_SETADR);
Expand Down
4 changes: 2 additions & 2 deletions src/video/xbios/SDL_xbios_f30.c
Expand Up @@ -180,7 +180,7 @@ static void setMode(_THIS, xbiosmode_t *new_video_mode)
{
Setscreen(-1,XBIOS_screens[0],-1);

VsetMode(new_video_mode->number);
(void) VsetMode(new_video_mode->number);

/* Set hardware palette to black in True Colour */
if (new_video_mode->depth > 8) {
Expand All @@ -193,7 +193,7 @@ static void restoreMode(_THIS)
{
Setscreen(-1,XBIOS_oldvbase,-1);

VsetMode(XBIOS_oldvmode);
(void) VsetMode(XBIOS_oldvmode);

if (XBIOS_oldnumcol) {
VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
Expand Down
19 changes: 19 additions & 0 deletions src/video/xbios/SDL_xbios_milan.c
Expand Up @@ -64,6 +64,7 @@ static void listModes(_THIS, int actually_add);
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);
Expand All @@ -75,6 +76,7 @@ void SDL_XBIOS_VideoInit_Milan(_THIS)
XBIOS_saveMode = saveMode;
XBIOS_setMode = setMode;
XBIOS_restoreMode = restoreMode;
XBIOS_getLineWidth = getLineWidth;
XBIOS_swapVbuffers = swapVbuffers;
XBIOS_allocVbuffers = allocVbuffers;
XBIOS_freeVbuffers = freeVbuffers;
Expand Down Expand Up @@ -180,6 +182,23 @@ static void swapVbuffers(_THIS)
VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
}

static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp)
{
SCREENINFO si;
int retvalue = width * (((bpp==15) ? 16 : bpp)>>3);

/* Set pitch of new mode */
si.size = sizeof(SCREENINFO);
si.devID = new_video_mode->number;
si.scrFlags = 0;
VsetScreen(-1, &si, VN_MAGIC, CMD_GETINFO);
if (si.scrFlags & SCRINFO_OK) {
retvalue = si.lineWrap;
}

return (retvalue);
}

static int allocVbuffers(_THIS, int num_buffers, int bufsize)
{
int i;
Expand Down
7 changes: 7 additions & 0 deletions src/video/xbios/SDL_xbios_st.c
Expand Up @@ -45,6 +45,7 @@ static void saveMode(_THIS, SDL_PixelFormat *vformat);
static void setMode_ST(_THIS, xbiosmode_t *new_video_mode);
static void setMode_STE(_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);
Expand All @@ -56,6 +57,7 @@ void SDL_XBIOS_VideoInit_ST(_THIS, unsigned long cookie_cvdo)
XBIOS_saveMode = saveMode;
XBIOS_setMode = setMode_ST;
XBIOS_restoreMode = restoreMode;
XBIOS_getLineWidth = getLineWidth;
XBIOS_swapVbuffers = swapVbuffers;
XBIOS_allocVbuffers = allocVbuffers;
XBIOS_freeVbuffers = freeVbuffers;
Expand Down Expand Up @@ -140,6 +142,11 @@ static void restoreMode(_THIS)
}
}

static int getLineWidth(_THIS, xbiosmode_t *new_video_mode, int width, int bpp)
{
return (width * (((bpp==15) ? 16 : bpp)>>3));
}

static void swapVbuffers(_THIS)
{
Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
Expand Down

0 comments on commit 54638e7

Please sign in to comment.