From bd23eaf33eff9b628f967e95e147b06f2040e98e Mon Sep 17 00:00:00 2001 From: Patrice Mandin Date: Wed, 30 Jul 2014 11:36:59 +0200 Subject: [PATCH] atari:xbios: Move all Milan specific stuff to specific backend file. --- src/video/xbios/SDL_xbios.c | 111 +++++++++---------------- src/video/xbios/SDL_xbios.h | 27 ++++++ src/video/xbios/SDL_xbios_milan.c | 133 +++++++++++++++++++++++++++++- src/video/xbios/SDL_xbios_milan.h | 4 - 4 files changed, 198 insertions(+), 77 deletions(-) diff --git a/src/video/xbios/SDL_xbios.c b/src/video/xbios/SDL_xbios.c index a7800efaf..81e283d7d 100644 --- a/src/video/xbios/SDL_xbios.c +++ b/src/video/xbios/SDL_xbios.c @@ -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]={ @@ -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)); @@ -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; } @@ -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<>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; @@ -723,25 +704,24 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, } /* Allocate buffers */ - for (i=0; i>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>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 */ @@ -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); } @@ -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; } @@ -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); } @@ -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); } @@ -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; @@ -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(); diff --git a/src/video/xbios/SDL_xbios.h b/src/video/xbios/SDL_xbios.h index 3ad682715..29e6c57e9 100644 --- a/src/video/xbios/SDL_xbios.h +++ b/src/video/xbios/SDL_xbios.h @@ -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 */ @@ -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 */ diff --git a/src/video/xbios/SDL_xbios_milan.c b/src/video/xbios/SDL_xbios_milan.c index a99ee18c5..16d43507c 100644 --- a/src/video/xbios/SDL_xbios_milan.c +++ b/src/video/xbios/SDL_xbios_milan.c @@ -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; @@ -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; @@ -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<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>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); +} diff --git a/src/video/xbios/SDL_xbios_milan.h b/src/video/xbios/SDL_xbios_milan.h index 4443cd9c1..bed5dc762 100644 --- a/src/video/xbios/SDL_xbios_milan.h +++ b/src/video/xbios/SDL_xbios_milan.h @@ -209,8 +209,4 @@ typedef struct _scrlineblk { long blk_pattern; /* pattern (-1: solid line) */ } SCRLINEMEMBLK; -/*--- Functions prototypes ---*/ - -void SDL_XBIOS_ListMilanModes(_THIS, int actually_add); - #endif /* _SDL_xbios_milan_h */