From 9a599ce7c0c5331551447295c206cc9c51528b23 Mon Sep 17 00:00:00 2001 From: Patrice Mandin Date: Wed, 30 Jul 2014 12:39:05 +0200 Subject: [PATCH] atari:xbios: Move all ST specific stuff to specific backend file. --- src/video/xbios/SDL_xbios.c | 126 +++------------------ src/video/xbios/SDL_xbios.h | 3 + src/video/xbios/SDL_xbios_st.c | 194 +++++++++++++++++++++++++++++++++ 3 files changed, 214 insertions(+), 109 deletions(-) create mode 100644 src/video/xbios/SDL_xbios_st.c diff --git a/src/video/xbios/SDL_xbios.c b/src/video/xbios/SDL_xbios.c index 81e283d7d..e89ab4bee 100644 --- a/src/video/xbios/SDL_xbios.c +++ b/src/video/xbios/SDL_xbios.c @@ -92,10 +92,6 @@ static void XBIOS_GL_SwapBuffers(_THIS); /* Default list of video modes */ -static const xbiosmode_t stmodes[1]={ - {ST_LOW>>8,320,200,4, XBIOSMODE_C2P} -}; - static const xbiosmode_t ttmodes[2]={ {TT_LOW,320,480,8, XBIOSMODE_C2P}, {TT_LOW,320,240,8, XBIOSMODE_C2P|XBIOSMODE_DOUBLELINE} @@ -250,8 +246,13 @@ static SDL_VideoDevice *XBIOS_CreateDevice(int devindex) if (Getcookie(C__VDO, &cookie_cvdo) != C_FOUND) { cookie_cvdo = VDO_ST << 16; } + SDL_XBIOS_VideoInit_ST(device, cookie_cvdo); switch (cookie_cvdo>>16) { + case VDO_ST: + case VDO_STE: + /* Already done as default */ + break; case VDO_MILAN: SDL_XBIOS_VideoInit_Milan(device); break; @@ -322,11 +323,6 @@ void SDL_XBIOS_AddMode(_THIS, int actually_add, const xbiosmode_t *modeinfo) } } -static void XBIOS_ListSTModes(_THIS, int actually_add) -{ - SDL_XBIOS_AddMode(this, actually_add, &stmodes[0]); -} - static void XBIOS_ListTTModes(_THIS, int actually_add) { int i; @@ -406,29 +402,8 @@ static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat) switch (XBIOS_cvdo >>16) { case VDO_ST: case VDO_STE: - { - short *oldpalette; - - XBIOS_oldvmode=Getrez(); - switch(XBIOS_oldvmode << 8) { - case ST_LOW: - XBIOS_oldnumcol=16; - break; - case ST_MED: - XBIOS_oldnumcol=4; - break; - case ST_HIGH: - XBIOS_oldnumcol=2; - break; - } - - oldpalette= (short *) XBIOS_oldpalette; - for (i=0;i>16) { case VDO_ST: case VDO_STE: - XBIOS_ListSTModes(this, 1); + (*XBIOS_listModes)(this, 1); break; case VDO_TT: XBIOS_ListTTModes(this, 1); @@ -610,18 +585,7 @@ static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) static void XBIOS_FreeBuffers(_THIS) { - int i; - - 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; - } - } + (*XBIOS_freeVbuffers)(this); if (XBIOS_shadowscreen!=NULL) { Mfree(XBIOS_shadowscreen); @@ -633,7 +597,7 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int mode, new_depth; - int i, num_buffers; + int num_buffers; xbiosmode_t *new_video_mode; Uint32 new_screen_size; Uint32 modeflags; @@ -704,24 +668,9 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, } /* Allocate buffers */ - if ((XBIOS_cvdo>>16) == VDO_MILAN) { - if (!(*XBIOS_allocVbuffers)(this, num_buffers, new_screen_size)) { - XBIOS_FreeBuffers(this); - return (NULL); - } - } 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); - } + if (!(*XBIOS_allocVbuffers)(this, num_buffers, new_screen_size)) { + XBIOS_FreeBuffers(this); + return (NULL); } /* Allocate the new pixel format for the screen */ @@ -768,26 +717,8 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, switch(XBIOS_cvdo >> 16) { case VDO_ST: - Setscreen(-1,-1,new_video_mode->number); - - /* Reset palette */ - for (i=0;i<16;i++) { - TT_palette[i]= ((i>>1)<<8) | (((i*8)/17)<<4) | (i>>1); - } - Setpalette(TT_palette); - break; case VDO_STE: - Setscreen(-1,-1,new_video_mode->number); - - /* Reset palette */ - for (i=0;i<16;i++) - { - int c; - - c=((i&1)<<3)|((i>>1)&7); - TT_palette[i]=(c<<8)|(c<<4)|c; - } - Setpalette(TT_palette); + (*XBIOS_setMode)(this, new_video_mode); break; case VDO_TT: EsetShift(new_video_mode->number); @@ -881,11 +812,7 @@ static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects) } #ifndef DEBUG_VIDEO_XBIOS - if ((XBIOS_cvdo>>16) == VDO_MILAN) { - (*XBIOS_swapVbuffers)(this); - } else { - Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1); - } + (*XBIOS_swapVbuffers)(this); Vsync(); #endif @@ -925,11 +852,7 @@ static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface) } #ifndef DEBUG_VIDEO_XBIOS - if ((XBIOS_cvdo>>16) == VDO_MILAN) { - (*XBIOS_swapVbuffers)(this); - } else { - Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1); - } + (*XBIOS_swapVbuffers)(this); Vsync(); #endif @@ -951,18 +874,6 @@ static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors int r,v,b; switch( XBIOS_cvdo >> 16) { - case VDO_ST: - case VDO_STE: - for (i=0;i> 16) { case VDO_ST: case VDO_STE: - Setscreen(-1,XBIOS_oldvbase,XBIOS_oldvmode); - if (XBIOS_oldnumcol) { - Setpalette(XBIOS_oldpalette); - } + (*XBIOS_restoreMode)(this); break; case VDO_TT: Setscreen(-1,XBIOS_oldvbase,-1); diff --git a/src/video/xbios/SDL_xbios.h b/src/video/xbios/SDL_xbios.h index 29e6c57e9..dad3c9694 100644 --- a/src/video/xbios/SDL_xbios.h +++ b/src/video/xbios/SDL_xbios.h @@ -132,6 +132,9 @@ enum { void SDL_XBIOS_AddMode(_THIS, int actually_add, const xbiosmode_t *modeinfo); +/* SDL_xbios_st.c */ +void SDL_XBIOS_VideoInit_ST(_THIS, unsigned long cookie_cvdo); + /* SDL_xbios_milan.c */ void SDL_XBIOS_VideoInit_Milan(_THIS); diff --git a/src/video/xbios/SDL_xbios_st.c b/src/video/xbios/SDL_xbios_st.c new file mode 100644 index 000000000..6981826f6 --- /dev/null +++ b/src/video/xbios/SDL_xbios_st.c @@ -0,0 +1,194 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* + ST/STE Xbios video functions + + Patrice Mandin +*/ + +#include +#include + +#include "../SDL_sysvideo.h" + +#include "../ataricommon/SDL_atarimxalloc_c.h" +#include "../ataricommon/SDL_ataric2p_s.h" +#include "SDL_xbios.h" + +static const xbiosmode_t stmodes[]={ + {ST_LOW>>8,320,200,4, XBIOSMODE_C2P} +}; + +static void listModes(_THIS, int actually_add); +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 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_ST(_THIS, unsigned long cookie_cvdo) +{ + XBIOS_listModes = listModes; + XBIOS_saveMode = saveMode; + XBIOS_setMode = setMode_ST; + XBIOS_restoreMode = restoreMode; + XBIOS_swapVbuffers = swapVbuffers; + XBIOS_allocVbuffers = allocVbuffers; + XBIOS_freeVbuffers = freeVbuffers; + + this->SetColors = setColors; + + if ((cookie_cvdo>>16) == VDO_STE) { + XBIOS_setMode = setMode_STE; + } +} + +static void listModes(_THIS, int actually_add) +{ + SDL_XBIOS_AddMode(this, actually_add, &stmodes[0]); +} + +static void saveMode(_THIS, SDL_PixelFormat *vformat) +{ + short *oldpalette; + int i; + + XBIOS_oldvbase=Physbase(); + XBIOS_oldvmode=Getrez(); + + switch(XBIOS_oldvmode << 8) { + case ST_LOW: + XBIOS_oldnumcol=16; + break; + case ST_MED: + XBIOS_oldnumcol=4; + break; + case ST_HIGH: + XBIOS_oldnumcol=2; + break; + } + + oldpalette= (short *) XBIOS_oldpalette; + for (i=0;inumber); + + /* Reset palette, 8 shades of gray with a bit of green interleaved */ + for (i=0;i<16;i++) { + TT_palette[i]= ((i>>1)<<8) | (((i*8)/17)<<4) | (i>>1); + } + Setpalette(TT_palette); +} + +static void setMode_STE(_THIS, xbiosmode_t *new_video_mode) +{ + int i; + + Setscreen(-1,XBIOS_screens[0],-1); + + Setscreen(-1,-1,new_video_mode->number); + + /* Reset palette, 16 shades of gray */ + for (i=0;i<16;i++) { + int c; + + c=((i&1)<<3)|((i>>1)&7); + TT_palette[i]=(c<<8)|(c<<4)|c; + } + Setpalette(TT_palette); +} + +static void restoreMode(_THIS) +{ + Setscreen(-1,XBIOS_oldvbase,XBIOS_oldvmode); + + if (XBIOS_oldnumcol) { + Setpalette(XBIOS_oldpalette); + } +} + +static void swapVbuffers(_THIS) +{ + Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1); +} + +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]=(void *) (( (long) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL); + } + + return (1); +} + +static void freeVbuffers(_THIS) +{ + int i; + + for (i=0;i<2;i++) { + if (XBIOS_screensmem[i]) { + Mfree(XBIOS_screensmem[i]); + } + XBIOS_screensmem[i]=NULL; + } +} + +static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) +{ + int i, r,g,b; + + for (i=0;i