Skip to content

Commit

Permalink
atari:xbios: Move all Milan specific stuff to specific backend file.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmandin committed Jul 30, 2014
1 parent 87a9569 commit bd23eaf
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 77 deletions.
111 changes: 39 additions & 72 deletions src/video/xbios/SDL_xbios.c
Expand Up @@ -90,11 +90,6 @@ static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
static void XBIOS_GL_SwapBuffers(_THIS);
#endif

/* To setup palette */

static unsigned short TT_palette[256];
static unsigned long F30_palette[256];

/* Default list of video modes */

static const xbiosmode_t stmodes[1]={
Expand Down Expand Up @@ -202,6 +197,7 @@ static void XBIOS_DeleteDevice(SDL_VideoDevice *device)
static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
long cookie_cvdo;

/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
Expand Down Expand Up @@ -250,6 +246,17 @@ static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)

device->free = XBIOS_DeleteDevice;

/* Setup device specific functions, default to ST for everything */
if (Getcookie(C__VDO, &cookie_cvdo) != C_FOUND) {
cookie_cvdo = VDO_ST << 16;
}

switch (cookie_cvdo>>16) {
case VDO_MILAN:
SDL_XBIOS_VideoInit_Milan(device);
break;
}

return device;
}

Expand Down Expand Up @@ -489,32 +496,8 @@ static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
}
break;
case VDO_MILAN:
{
SCREENINFO si;

/* Read infos about current mode */
VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_GETMODE);

si.size = sizeof(SCREENINFO);
si.devID = XBIOS_oldvmode;
si.scrFlags = 0;
VsetScreen(-1, &si, MI_MAGIC, CMD_GETINFO);

this->info.current_w = si.scrWidth;
this->info.current_h = si.scrHeight;

XBIOS_oldnumcol = 0;
if (si.scrFlags & SCRINFO_OK) {
if (si.scrPlanes <= 8) {
XBIOS_oldnumcol = 1<<si.scrPlanes;
}
}
if (XBIOS_oldnumcol) {
VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}

SDL_XBIOS_ListMilanModes(this, 0);
}
(*XBIOS_saveMode)(this, vformat);
(*XBIOS_listModes)(this, 0);
break;
}

Expand Down Expand Up @@ -592,7 +575,7 @@ static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
}
break;
case VDO_MILAN:
SDL_XBIOS_ListMilanModes(this, 1);
(*XBIOS_listModes)(this, 1);
break;
}

Expand Down Expand Up @@ -629,13 +612,11 @@ static void XBIOS_FreeBuffers(_THIS)
{
int i;

for (i=0;i<2;i++) {
if (XBIOS_screensmem[i]!=NULL) {
if ((XBIOS_cvdo>>16) == VDO_MILAN) {
if (i==1) {
VsetScreen(-1, -1, MI_MAGIC, CMD_FREEPAGE);
}
} else {
if ((XBIOS_cvdo>>16) == VDO_MILAN) {
(*XBIOS_freeVbuffers)(this);
} else {
for (i=0;i<2;i++) {
if (XBIOS_screensmem[i]!=NULL) {
Mfree(XBIOS_screensmem[i]);
}
XBIOS_screensmem[i]=NULL;
Expand Down Expand Up @@ -723,25 +704,24 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
}

/* Allocate buffers */
for (i=0; i<num_buffers; i++) {
if ((XBIOS_cvdo>>16) == VDO_MILAN) {
if (i==0) {
XBIOS_screensmem[i] = XBIOS_oldvbase;
} else {
VsetScreen(-1, &XBIOS_screensmem[i], MI_MAGIC, CMD_ALLOCPAGE);
}
} else {
XBIOS_screensmem[i] = Atari_SysMalloc(new_screen_size, MX_STRAM);
}

if (XBIOS_screensmem[i]==NULL) {
if ((XBIOS_cvdo>>16) == VDO_MILAN) {
if (!(*XBIOS_allocVbuffers)(this, num_buffers, new_screen_size)) {
XBIOS_FreeBuffers(this);
SDL_SetError("Can not allocate %d KB for buffer %d", new_screen_size>>10, i);
return (NULL);
}
SDL_memset(XBIOS_screensmem[i], 0, new_screen_size);
} else {
for (i=0; i<num_buffers; i++) {
XBIOS_screensmem[i] = Atari_SysMalloc(new_screen_size, MX_STRAM);

if (XBIOS_screensmem[i]==NULL) {
XBIOS_FreeBuffers(this);
SDL_SetError("Can not allocate %d KB for buffer %d", new_screen_size>>10, i);
return (NULL);
}
SDL_memset(XBIOS_screensmem[i], 0, new_screen_size);

XBIOS_screens[i]=(void *) (( (long) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL);
XBIOS_screens[i]=(void *) (( (long) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL);
}
}

/* Allocate the new pixel format for the screen */
Expand Down Expand Up @@ -782,9 +762,7 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,

#ifndef DEBUG_VIDEO_XBIOS
/* Now set the video mode */
if ((XBIOS_cvdo>>16) == VDO_MILAN) {
VsetScreen(-1, XBIOS_screens[0], MI_MAGIC, CMD_SETADR);
} else {
if ((XBIOS_cvdo>>16) != VDO_MILAN) {
Setscreen(-1,XBIOS_screens[0],-1);
}

Expand Down Expand Up @@ -828,13 +806,7 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
}
break;
case VDO_MILAN:
VsetScreen(-1, new_video_mode->number, MI_MAGIC, CMD_SETMODE);

/* Set hardware palette to black in True Colour */
if (new_depth > 8) {
SDL_memset(F30_palette, 0, sizeof(F30_palette));
VsetRGB(0,256,F30_palette);
}
(*XBIOS_setMode)(this, new_video_mode);
break;
}

Expand Down Expand Up @@ -910,7 +882,7 @@ static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)

#ifndef DEBUG_VIDEO_XBIOS
if ((XBIOS_cvdo>>16) == VDO_MILAN) {
VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
(*XBIOS_swapVbuffers)(this);
} else {
Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
}
Expand Down Expand Up @@ -954,7 +926,7 @@ static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)

#ifndef DEBUG_VIDEO_XBIOS
if ((XBIOS_cvdo>>16) == VDO_MILAN) {
VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
(*XBIOS_swapVbuffers)(this);
} else {
Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
}
Expand Down Expand Up @@ -1003,7 +975,6 @@ static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors
EsetPalette(firstcolor,ncolors,TT_palette);
break;
case VDO_F30:
case VDO_MILAN:
for(i = 0; i < ncolors; i++)
{
r = colors[i].r;
Expand Down Expand Up @@ -1058,11 +1029,7 @@ static void XBIOS_VideoQuit(_THIS)
}
break;
case VDO_MILAN:
VsetScreen(-1, &XBIOS_oldvbase, MI_MAGIC, CMD_SETADR);
VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_SETMODE);
if (XBIOS_oldnumcol) {
VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
(*XBIOS_restoreMode)(this);
break;
}
Vsync();
Expand Down
27 changes: 27 additions & 0 deletions src/video/xbios/SDL_xbios.h
Expand Up @@ -64,6 +64,19 @@ struct SDL_PrivateVideoData {
int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS];
xbiosmode_t **SDL_xbiosmode[NUM_MODELISTS];

union {
Uint16 pal16[16];
Uint32 pal32[256];
} palette;

void (*listModes)(_THIS, int actually_add); /* List video modes */
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 */
void (*swapVbuffers)(_THIS); /* Swap video buffers */
int (*allocVbuffers)(_THIS, int num_buffers, int bufsize); /* Allocate video buffers */
void (*freeVbuffers)(_THIS); /* Free video buffers */
};

/* _VDO cookie values */
Expand Down Expand Up @@ -104,8 +117,22 @@ enum {
#define XBIOS_centscreen (this->hidden->centscreen)
#define XBIOS_current (this->hidden->current)

#define TT_palette (this->hidden->palette.pal16)
#define F30_palette (this->hidden->palette.pal32)

#define XBIOS_listModes (this->hidden->listModes)
#define XBIOS_saveMode (this->hidden->saveMode)
#define XBIOS_setMode (this->hidden->setMode)
#define XBIOS_restoreMode (this->hidden->restoreMode)
#define XBIOS_swapVbuffers (this->hidden->swapVbuffers)
#define XBIOS_allocVbuffers (this->hidden->allocVbuffers)
#define XBIOS_freeVbuffers (this->hidden->freeVbuffers)

/*--- Functions prototypes ---*/

void SDL_XBIOS_AddMode(_THIS, int actually_add, const xbiosmode_t *modeinfo);

/* SDL_xbios_milan.c */
void SDL_XBIOS_VideoInit_Milan(_THIS);

#endif /* _SDL_xbios_h */
133 changes: 132 additions & 1 deletion src/video/xbios/SDL_xbios_milan.c
Expand Up @@ -60,6 +60,28 @@ static SDL_VideoDevice *enum_this;

/*--- Functions ---*/

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 void swapVbuffers(_THIS);
static int allocVbuffers(_THIS, int num_buffers, int bufsize);
static void freeVbuffers(_THIS);
static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);

void SDL_XBIOS_VideoInit_Milan(_THIS)
{
XBIOS_listModes = listModes;
XBIOS_saveMode = saveMode;
XBIOS_setMode = setMode;
XBIOS_restoreMode = restoreMode;
XBIOS_swapVbuffers = swapVbuffers;
XBIOS_allocVbuffers = allocVbuffers;
XBIOS_freeVbuffers = freeVbuffers;

this->SetColors = setColors;
}

static unsigned long /*cdecl*/ enumfunc(SCREENINFO *inf, unsigned long flag)
{
xbiosmode_t modeinfo;
Expand All @@ -75,7 +97,7 @@ static unsigned long /*cdecl*/ enumfunc(SCREENINFO *inf, unsigned long flag)
return ENUMMODE_CONT;
}

void SDL_XBIOS_ListMilanModes(_THIS, int actually_add)
static void listModes(_THIS, int actually_add)
{
int i;

Expand Down Expand Up @@ -104,3 +126,112 @@ void SDL_XBIOS_ListMilanModes(_THIS, int actually_add)
enum_actually_add = actually_add;
VsetScreen(-1, &enumfunc, MI_MAGIC, CMD_ENUMMODES);
}

static void saveMode(_THIS, SDL_PixelFormat *vformat)
{
SCREENINFO si;

/* Read infos about current mode */
VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_GETMODE);

si.size = sizeof(SCREENINFO);
si.devID = XBIOS_oldvmode;
si.scrFlags = 0;
VsetScreen(-1, &si, MI_MAGIC, CMD_GETINFO);

this->info.current_w = si.scrWidth;
this->info.current_h = si.scrHeight;

XBIOS_oldnumcol = 0;
if (si.scrFlags & SCRINFO_OK) {
if (si.scrPlanes <= 8) {
XBIOS_oldnumcol = 1<<si.scrPlanes;
}
}
if (XBIOS_oldnumcol) {
VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
}

static void setMode(_THIS, xbiosmode_t *new_video_mode)
{
VsetScreen(-1, XBIOS_screens[0], MI_MAGIC, CMD_SETADR);

VsetScreen(-1, new_video_mode->number, MI_MAGIC, CMD_SETMODE);

/* Set hardware palette to black in True Colour */
if (new_video_mode->depth > 8) {
SDL_memset(F30_palette, 0, sizeof(F30_palette));
VsetRGB(0,256,F30_palette);
}
}

static void restoreMode(_THIS)
{
VsetScreen(-1, &XBIOS_oldvbase, MI_MAGIC, CMD_SETADR);
VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_SETMODE);
if (XBIOS_oldnumcol) {
VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
}

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

static int allocVbuffers(_THIS, int num_buffers, int bufsize)
{
int i;

for (i=0; i<num_buffers; i++) {
if (i==0) {
/* Buffer 0 is current screen */
XBIOS_screensmem[i] = XBIOS_oldvbase;
} else {
VsetScreen(-1, &XBIOS_screensmem[i], MI_MAGIC, CMD_ALLOCPAGE);
}

if (!XBIOS_screensmem[i]) {
SDL_SetError("Can not allocate %d KB for buffer %d", bufsize>>10, i);
return (0);
}
SDL_memset(XBIOS_screensmem[i], 0, bufsize);

XBIOS_screens[i]=XBIOS_screensmem[i];
}

return (1);
}

static void freeVbuffers(_THIS)
{
int i;

for (i=0;i<2;i++) {
if (XBIOS_screensmem[i]) {
if (i==1) {
VsetScreen(-1, -1, MI_MAGIC, CMD_FREEPAGE);
} else {
/* Do not touch buffer 0 */
}
XBIOS_screensmem[i]=NULL;
}
}
}

static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
int i, r,g,b;

for(i = 0; i < ncolors; i++) {
r = colors[i].r;
g = colors[i].g;
b = colors[i].b;

F30_palette[i]=(r<<16)|(g<<8)|b;
}
VsetRGB(firstcolor,ncolors,F30_palette);

return (1);
}

0 comments on commit bd23eaf

Please sign in to comment.