📄 sdl_gemvideo.c
字号:
vs_color(VDI_handle, vdi_index[0], oldrgb);
v_show_c(VDI_handle, 1);
}
static void GEM_LockScreen(_THIS)
{
if (!GEM_locked) {
/* Reserve memory space, used to be sure of compatibility */
form_dial( FMD_START, 0,0,0,0, 0,0,VDI_w,VDI_h);
/* Lock AES */
wind_update(BEG_UPDATE);
wind_update(BEG_MCTRL);
GEM_locked=SDL_TRUE;
}
}
static void GEM_UnlockScreen(_THIS)
{
if (GEM_locked) {
/* Restore screen memory, and send REDRAW to all apps */
form_dial( FMD_FINISH, 0,0,0,0, 0,0,VDI_w,VDI_h);
/* Unlock AES */
wind_update(END_MCTRL);
wind_update(END_UPDATE);
GEM_locked=SDL_FALSE;
}
}
SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags)
{
int maxwidth, maxheight;
Uint32 modeflags, screensize;
SDL_bool use_shadow;
modeflags = SDL_HWPALETTE;
GEM_FreeBuffers(this);
/*--- Verify if asked mode can be used ---*/
if (flags & SDL_FULLSCREEN) {
maxwidth=VDI_w;
maxheight=VDI_h;
} else {
/* Windowed mode */
maxwidth=GEM_desk_w;
maxheight=GEM_desk_h;
}
if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) {
SDL_SetError("Couldn't find requested mode in list");
return(NULL);
}
/*--- Allocate the new pixel format for the screen ---*/
if ( ! SDL_ReallocFormat(current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, VDI_alphamask) ) {
SDL_SetError("Couldn't allocate new pixel format for requested mode");
return(NULL);
}
/*--- Allocate shadow buffer if needed ---*/
use_shadow=SDL_FALSE;
if (flags & SDL_FULLSCREEN) {
if (!VDI_screen) {
/* No access to real framebuffer, use shadow surface */
use_shadow=SDL_TRUE;
} else {
if (VDI_format==VDI_FORMAT_INTER) {
/* Real framebuffer, interleaved bitplanes,
use shadow surface */
use_shadow=SDL_TRUE;
} else if (flags & SDL_DOUBLEBUF) {
/* Real framebuffer, double-buffered,
use shadow surface */
use_shadow=SDL_TRUE;
modeflags |= SDL_DOUBLEBUF;
}
}
} else {
/* Windowed mode, always with shadow surface */
use_shadow=SDL_TRUE;
}
if (use_shadow) {
screensize = width * height * VDI_pixelsize;
GEM_buffer = Atari_SysMalloc(screensize, MX_PREFTTRAM);
if (GEM_buffer==NULL) {
fprintf(stderr,"Unable to allocate shadow buffer\n");
return NULL;
}
memset(GEM_buffer, 0, screensize);
}
/*--- Initialize screen ---*/
if (flags & SDL_FULLSCREEN) {
GEM_LockScreen(this);
GEM_ClearScreen(this);
modeflags |= SDL_FULLSCREEN;
if (VDI_screen && (VDI_format==VDI_FORMAT_PACK) && !use_shadow) {
modeflags |= SDL_HWSURFACE;
} else {
modeflags |= SDL_SWSURFACE;
}
} else {
int posx,posy;
short x2,y2,w2,h2;
GEM_UnlockScreen(this);
/* Center our window */
posx = GEM_desk_x;
posy = GEM_desk_y;
if (width<GEM_desk_w)
posx += (GEM_desk_w - width) >> 1;
if (height<GEM_desk_h)
posy += (GEM_desk_h - height) >> 1;
/* Calculate our window size and position */
if (!(flags & SDL_NOFRAME)) {
GEM_win_type=NAME|MOVER|CLOSER|SMALLER;
if (flags & SDL_RESIZABLE) {
GEM_win_type |= FULLER|SIZER;
modeflags |= SDL_RESIZABLE;
}
} else {
GEM_win_type=0;
modeflags |= SDL_NOFRAME;
}
if (!wind_calc(0, GEM_win_type, posx, posy, width, height, &x2, &y2, &w2, &h2)) {
GEM_FreeBuffers(this);
fprintf(stderr,"Can not calculate window attributes\n");
return NULL;
}
/* Create window */
GEM_handle=wind_create(GEM_win_type, x2, y2, w2, h2);
if (GEM_handle<0) {
GEM_FreeBuffers(this);
fprintf(stderr,"Can not create window\n");
return NULL;
}
/* Setup window name */
wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
/* Open the window */
wind_open(GEM_handle,x2,y2,w2,h2);
modeflags |= SDL_SWSURFACE;
}
/* Set up the new mode framebuffer */
current->flags = modeflags;
current->w = width;
current->h = height;
if (use_shadow) {
current->pixels = GEM_buffer;
current->pitch = width * (VDI_bpp >> 3);
} else {
current->pixels = VDI_screen;
current->pixels += VDI_pitch * ((VDI_h - height) >> 1);
current->pixels += VDI_pixelsize * ((VDI_w - width) >> 1);
current->pitch = VDI_pitch;
}
this->UpdateRects = GEM_UpdateRects;
/* We're done */
return(current);
}
/* We don't actually allow hardware surfaces other than the main one */
static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface)
{
return -1;
}
static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
/* We need to wait for vertical retrace on page flipped displays */
static int GEM_LockHWSurface(_THIS, SDL_Surface *surface)
{
return(0);
}
static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
static void GEM_UpdateRectsFullscreen(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
MFDB mfdb_src;
short blitcoords[8];
int i;
surface = this->screen;
if (VDI_screen) {
if (VDI_format==VDI_FORMAT_INTER) {
void *destscr;
int destx;
destscr = VDI_screen;
destscr += VDI_pitch * ((VDI_h - surface->h) >> 1);
destx = (VDI_w - surface->w) >> 1;
destx &= ~15;
destscr += destx;
for (i=0;i<numrects;i++) {
void *source,*destination;
int x1,x2;
x1 = rects[i].x & ~15;
x2 = rects[i].x+rects[i].w;
if (x2 & 15) {
x2 = (x2 | 15) +1;
}
source = surface->pixels;
source += surface->pitch * rects[i].y;
source += x1;
destination = destscr;
destination += VDI_pitch * rects[i].y;
destination += x1;
/* Convert chunky to planar screen */
Atari_C2pConvert(
source,
destination,
x2-x1,
rects[i].h,
SDL_FALSE,
surface->pitch,
VDI_pitch
);
}
return;
}
if (!(surface->flags & SDL_DOUBLEBUF)) {
return;
}
}
mfdb_src.fd_addr=surface->pixels;
mfdb_src.fd_w=surface->w;
mfdb_src.fd_h=surface->h;
mfdb_src.fd_wdwidth=(surface->w) >> 4;
mfdb_src.fd_stand=0;
mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
mfdb_src.fd_r1=0;
mfdb_src.fd_r2=0;
mfdb_src.fd_r3=0;
for ( i=0; i<numrects; ++i ) {
blitcoords[0] = rects[i].x;
blitcoords[1] = rects[i].y;
blitcoords[2] = blitcoords[0] + rects[i].w - 1;
blitcoords[3] = blitcoords[1] + rects[i].h - 1;
blitcoords[4] = rects[i].x + ((VDI_w - surface->w) >> 1);
blitcoords[5] = rects[i].y + ((VDI_h - surface->h) >> 1);
blitcoords[6] = blitcoords[4] + rects[i].w - 1;
blitcoords[7] = blitcoords[5] + rects[i].h - 1;
vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
}
}
static void GEM_UpdateRectsWindowed(_THIS, int numrects, SDL_Rect *rects)
{
short pxy[8], wind_pxy[8];
int i;
wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
for ( i=0; i<numrects; ++i ) {
pxy[0] = wind_pxy[0] + rects[i].x;
pxy[1] = wind_pxy[1] + rects[i].y;
pxy[2] = rects[i].w;
pxy[3] = rects[i].h;
GEM_wind_redraw(this, GEM_handle, pxy);
}
}
static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
surface = this->screen;
if (surface->flags & SDL_FULLSCREEN) {
GEM_UpdateRectsFullscreen(this, numrects, rects);
} else {
GEM_UpdateRectsWindowed(this, numrects, rects);
}
}
static int GEM_FlipHWSurfaceFullscreen(_THIS, SDL_Surface *surface)
{
MFDB mfdb_src;
short blitcoords[8];
if (VDI_screen) {
if (VDI_format==VDI_FORMAT_INTER) {
void *destscr;
int destx;
/* Center on destination screen */
destscr = VDI_screen;
destscr += VDI_pitch * ((VDI_h - surface->h) >> 1);
destx = (VDI_w - surface->w) >> 1;
destx &= ~15;
destscr += destx;
/* Convert chunky to planar screen */
Atari_C2pConvert(
surface->pixels,
destscr,
surface->w,
surface->h,
SDL_FALSE,
surface->pitch,
VDI_pitch
);
return(0);
}
if (!(surface->flags & SDL_DOUBLEBUF)) {
return(0);
}
}
mfdb_src.fd_addr=surface->pixels;
mfdb_src.fd_w=surface->w;
mfdb_src.fd_h=surface->h;
mfdb_src.fd_wdwidth=(surface->w) >> 4;
mfdb_src.fd_stand=0;
mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
mfdb_src.fd_r1=0;
mfdb_src.fd_r2=0;
mfdb_src.fd_r3=0;
blitcoords[0] = 0;
blitcoords[1] = 0;
blitcoords[2] = surface->w - 1;
blitcoords[3] = surface->h - 1;
blitcoords[4] = (VDI_w - surface->w) >> 1;
blitcoords[5] = (VDI_h - surface->h) >> 1;
blitcoords[6] = blitcoords[4] + surface->w - 1;
blitcoords[7] = blitcoords[5] + surface->h - 1;
vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
return(0);
}
static int GEM_FlipHWSurfaceWindowed(_THIS, SDL_Surface *surface)
{
short pxy[8];
/* Update the whole window */
wind_get(GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]);
GEM_wind_redraw(this, GEM_handle, pxy);
return(0);
}
static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface)
{
if (surface->flags & SDL_FULLSCREEN) {
return GEM_FlipHWSurfaceFullscreen(this, surface);
} else {
return GEM_FlipHWSurfaceWindowed(this, surface);
}
}
static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
int i;
SDL_Surface *surface;
/* Do not change palette in True Colour */
surface = this->screen;
if (surface->format->BitsPerPixel > 8) {
return 1;
}
for(i = 0; i < ncolors; i++)
{
int r, g, b;
short rgb[3];
r = colors[i].r;
g = colors[i].g;
b = colors[i].b;
rgb[0] = (1000 * r) / 255;
rgb[1] = (1000 * g) / 255;
rgb[2] = (1000 * b) / 255;
vs_color(VDI_handle, vdi_index[firstcolor+i], rgb);
}
return(1);
}
#if 0
static int GEM_ToggleFullScreen(_THIS, int on)
{
if (on) {
GEM_LockScreen(this);
} else {
GEM_UnlockScreen(this);
}
return(1);
}
#endif
/* Note: If we are terminated, this could be called in the middle of
another SDL video routine -- notably UpdateRects.
*/
void GEM_VideoQuit(_THIS)
{
SDL_AtariXbios_RestoreVectors();
GEM_FreeBuffers(this);
GEM_UnlockScreen(this);
appl_exit();
/* Restore palette */
if (VDI_oldnumcolors) {
int i;
for(i = 0; i < VDI_oldnumcolors; i++) {
short rgb[3];
rgb[0] = VDI_oldpalette[i][0];
rgb[1] = VDI_oldpalette[i][1];
rgb[2] = VDI_oldpalette[i][2];
vs_color(VDI_handle, i, rgb);
}
}
/* Close VDI workstation */
if (VDI_handle) {
v_clsvwk(VDI_handle);
}
/* Free mode list */
if (SDL_modelist[0]) {
free(SDL_modelist[0]);
SDL_modelist[0]=NULL;
}
this->screen->pixels = NULL;
}
void GEM_wind_redraw(_THIS, int winhandle, short *inside)
{
short todo[4];
/* Tell AES we are going to update */
wind_update(BEG_UPDATE);
v_hide_c(VDI_handle);
/* Browse the rectangle list to redraw */
wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3]);
while (todo[2] && todo[3]) {
if (rc_intersect((GRECT *)inside,(GRECT *)todo)) {
todo[2] += todo[0]-1;
todo[3] += todo[1]-1;
refresh_window(this, winhandle, todo);
}
wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3]);
}
/* Update finished */
wind_update(END_UPDATE);
v_show_c(VDI_handle,1);
}
static void refresh_window(_THIS, int winhandle, short *rect)
{
MFDB mfdb_src;
short pxy[8], wind_pxy[8];
int iconified;
SDL_Surface *surface;
surface=this->screen;
/* Is window iconified ? */
iconified = 0;
if (GEM_wfeatures & (1<<WF_ICONIFY)) {
wind_get(winhandle, WF_ICONIFY, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
iconified = pxy[0];
}
wind_get(winhandle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
if (iconified) {
/* Refresh icon */
mfdb_src.fd_addr=surface->pixels; /* Should be icon image */
mfdb_src.fd_w=surface->w;
mfdb_src.fd_h=surface->h;
mfdb_src.fd_wdwidth=mfdb_src.fd_w>>4;
mfdb_src.fd_stand=0;
mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
mfdb_src.fd_r1=0;
mfdb_src.fd_r2=0;
mfdb_src.fd_r3=0;
} else {
/* Refresh window */
mfdb_src.fd_addr=surface->pixels;
mfdb_src.fd_w=surface->w;
mfdb_src.fd_h=surface->h;
mfdb_src.fd_wdwidth=mfdb_src.fd_w>>4;
mfdb_src.fd_stand=0;
mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
mfdb_src.fd_r1=0;
mfdb_src.fd_r2=0;
mfdb_src.fd_r3=0;
}
pxy[0] = rect[0] - wind_pxy[0];
pxy[1] = rect[1] - wind_pxy[1];
pxy[2] = pxy[0] + rect[2] - rect[0];
pxy[3] = pxy[1] + rect[3] - rect[1];
pxy[4] = rect[0];
pxy[5] = rect[1];
pxy[6] = rect[2];
pxy[7] = rect[3];
vro_cpyfm( VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -