?? sdl_driver.c
字號:
int VBE_getPalette(long start, long num, char *palettebuffer){ SDL_Color *sdlp = surface->format->palette->colors + start; char *p = palettebuffer + (start * 4); int i; for (i = 0; i < num; i++) { *p++ = (Uint8) ((((float) sdlp->b) / 255.0) * 63.0); *p++ = (Uint8) ((((float) sdlp->g) / 255.0) * 63.0); *p++ = (Uint8) ((((float) sdlp->r) / 255.0) * 63.0); *p++ = sdlp->unused; /* This byte is unused in both SDL and BUILD. */ sdlp++; } /* for */ return(1);} /* VBE_getPalette */void _uninitengine(void){ SDL_QuitSubSystem(SDL_INIT_VIDEO);} /* _uninitengine */void uninitvesa(void){ SDL_QuitSubSystem(SDL_INIT_VIDEO);} /* uninitvesa */int setupmouse(void){ SDL_GrabMode mode = SDL_GRAB_OFF; if (surface == NULL) return(0); if (mouse_grabbed) mode = SDL_GRAB_ON; SDL_WM_GrabInput(mode); SDL_ShowCursor(0); mouse_x = surface->w / 2; mouse_y = surface->h / 2; mouse_relative_x = mouse_relative_y = 0; /* * this global usually gets set by BUILD, but it's a one-shot * deal, and we may not have an SDL surface at that point. --ryan. */ moustat = 1; return(1);} /* setupmouse */void readmousexy(short *x, short *y){ if (x) *x = mouse_relative_x << 2; if (y) *y = mouse_relative_y << 2; mouse_relative_x = mouse_relative_y = 0;} /* readmousexy */void readmousebstatus(short *bstatus){ if (bstatus) *bstatus = mouse_buttons;} /* readmousebstatus */static unsigned char mirrorcolor = 0;void _updateScreenRect(long x, long y, long w, long h){ if (renderer == RENDERER_SOFTWARE) SDL_UpdateRect(surface, x, y, w, h);} /* _updatescreenrect */void _nextpage(void){ Uint32 ticks; handle_events(); if (renderer == RENDERER_SOFTWARE) { if (qsetmode == 200) memcpy(surface->pixels, (const void *) frameplace, surface->w * surface->h); SDL_UpdateRect(surface, 0, 0, 0, 0); /*SDL_Flip(surface); !!! */ } /* if */#ifdef USE_OPENGL else if (renderer == RENDERER_OPENGL3D) { opengl_swapbuffers(); } /* else if */#endif if ((debug_hall_of_mirrors) && (qsetmode == 200) && (frameplace)) { memset((void *) frameplace, mirrorcolor, surface->w * surface->h); mirrorcolor++; } /* if */ ticks = SDL_GetTicks(); total_render_time = (ticks - last_render_ticks); if (total_render_time > 1000) { total_rendered_frames = 0; total_render_time = 1; last_render_ticks = ticks; } /* if */ total_rendered_frames++;} /* _nextpage */unsigned char readpixel(long offset){ return( *((unsigned char *) offset) );} /* readpixel */void drawpixel(long offset, Uint8 pixel){ *((unsigned char *) offset) = pixel;} /* drawpixel *//* !!! These are incorrect. */void drawpixels(long offset, Uint16 pixels){ Uint8 *surface_end; Uint16 *pos; printf("Blargh!\n"); exit(91); if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface); surface_end = (((Uint8 *) surface->pixels) + (surface->w * surface->h)) - 2; pos = (Uint16 *) (((Uint8 *) surface->pixels) + offset); if ((pos >= (Uint16 *) surface->pixels) && (pos < (Uint16 *) surface_end)) *pos = pixels; if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);} /* drawpixels */void drawpixelses(long offset, Uint32 pixelses){ Uint8 *surface_end; Uint32 *pos; printf("Blargh!\n"); exit(91); if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface); surface_end = (((Uint8 *)surface->pixels) + (surface->w * surface->h)) - 2; pos = (Uint32 *) (((Uint8 *) surface->pixels) + offset); if ((pos >= (Uint32 *) surface->pixels) && (pos < (Uint32 *) surface_end)) *pos = pixelses; if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);} /* drawpixelses *//* Fix this up The Right Way (TM) - DDOI */void setcolor16(int col){ drawpixel_color = col;}void drawpixel16(long offset){ drawpixel(((long) surface->pixels + offset), drawpixel_color);} /* drawpixel16 */void fillscreen16(long offset, long color, long blocksize){ Uint8 *surface_end; Uint8 *wanted_end; Uint8 *pixels;#if (defined USE_OPENGL) if (renderer == RENDERER_OPENGL3D) { /* !!! dglClearColor() ... */ return; } /* if */#endif if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface); pixels = get_framebuffer(); /* Make this function pageoffset aware - DDOI */ if (!pageoffset) { offset = offset << 3; offset += 640*336; } surface_end = (pixels + (surface->w * surface->h)) - 1; wanted_end = (pixels + offset) + blocksize; if (offset < 0) offset = 0; if (wanted_end > surface_end) blocksize = ((unsigned long) surface_end) - ((unsigned long) pixels + offset); memset(pixels + offset, (int) color, blocksize); if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); _nextpage();} /* fillscreen16 *//* Most of this line code is taken from Abrash's "Graphics Programming Blackbook".Remember, sharing code is A Good Thing. AH */inline void DrawHorizontalRun (char **ScreenPtr, int XAdvance, int RunLength, char Color){ int i; char *WorkingScreenPtr = *ScreenPtr; for (i=0; i<RunLength; i++) { *WorkingScreenPtr = Color; WorkingScreenPtr += XAdvance; } WorkingScreenPtr += surface->w; *ScreenPtr = WorkingScreenPtr;}inline void DrawVerticalRun (char **ScreenPtr, int XAdvance, int RunLength, char Color){ int i; char *WorkingScreenPtr = *ScreenPtr; for (i=0; i<RunLength; i++) { *WorkingScreenPtr = Color; WorkingScreenPtr += surface->w; } WorkingScreenPtr += XAdvance; *ScreenPtr = WorkingScreenPtr;}void drawline16(long XStart, long YStart, long XEnd, long YEnd, char Color){ int Temp, AdjUp, AdjDown, ErrorTerm, XAdvance, XDelta, YDelta; int WholeStep, InitialPixelCount, FinalPixelCount, i, RunLength; char *ScreenPtr; long dx, dy; if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface); dx = XEnd-XStart; dy = YEnd-YStart; if (dx >= 0) { if ((XStart > 639) || (XEnd < 0)) return; if (XStart < 0) { if (dy) YStart += scale(0-XStart,dy,dx); XStart = 0; } if (XEnd > 639) { if (dy) YEnd += scale(639-XEnd,dy,dx); XEnd = 639; } } else { if ((XEnd > 639) || (XStart < 0)) return; if (XEnd < 0) { if (dy) YEnd += scale(0-XEnd,dy,dx); XEnd = 0; } if (XStart > 639) { if (dy) YStart += scale(639-XStart,dy,dx); XStart = 639; } } if (dy >= 0) { if ((YStart >= ydim16) || (YEnd < 0)) return; if (YStart < 0) { if (dx) XStart += scale(0-YStart,dx,dy); YStart = 0; } if (YEnd >= ydim16) { if (dx) XEnd += scale(ydim16-1-YEnd,dx,dy); YEnd = ydim16-1; } } else { if ((YEnd >= ydim16) || (YStart < 0)) return; if (YEnd < 0) { if (dx) XEnd += scale(0-YEnd,dx,dy); YEnd = 0; } if (YStart >= ydim16) { if (dx) XStart += scale(ydim16-1-YStart,dx,dy); YStart = ydim16-1; } } /* Make sure the status bar border draws correctly - DDOI */ if (!pageoffset) { YStart += 336; YEnd += 336; } /* We'll always draw top to bottom */ if (YStart > YEnd) { Temp = YStart; YStart = YEnd; YEnd = Temp; Temp = XStart; XStart = XEnd; XEnd = Temp; } /* Point to the bitmap address first pixel to draw */ ScreenPtr = (char *) (get_framebuffer()) + XStart + (surface->w * YStart); /* Figure out whether we're going left or right, and how far we're going horizontally */ if ((XDelta = XEnd - XStart) < 0) { XAdvance = (-1); XDelta = -XDelta; } else { XAdvance = 1; } /* Figure out how far we're going vertically */ YDelta = YEnd - YStart; /* Special cases: Horizontal, vertical, and diagonal lines */ if (XDelta == 0) { for (i=0; i <= YDelta; i++) { *ScreenPtr = Color; ScreenPtr += surface->w; } UNLOCK_SURFACE_AND_RETURN; } if (YDelta == 0) { for (i=0; i <= XDelta; i++) { *ScreenPtr = Color; ScreenPtr += XAdvance; } UNLOCK_SURFACE_AND_RETURN; } if (XDelta == YDelta) { for (i=0; i <= XDelta; i++) { *ScreenPtr = Color; ScreenPtr += XAdvance + surface->w; } UNLOCK_SURFACE_AND_RETURN; } /* Determine whether the line is X or Y major, and handle accordingly */ if (XDelta >= YDelta) /* X major line */ { WholeStep = XDelta / YDelta; AdjUp = (XDelta % YDelta) * 2; AdjDown = YDelta * 2; ErrorTerm = (XDelta % YDelta) - (YDelta * 2); InitialPixelCount = (WholeStep / 2) + 1; FinalPixelCount = InitialPixelCount; if ((AdjUp == 0) && ((WholeStep & 0x01) == 0)) InitialPixelCount--; if ((WholeStep & 0x01) != 0) ErrorTerm += YDelta; DrawHorizontalRun(&ScreenPtr, XAdvance, InitialPixelCount, Color); for (i=0; i<(YDelta-1); i++) { RunLength = WholeStep; if ((ErrorTerm += AdjUp) > 0) { RunLength ++; ErrorTerm -= AdjDown; } DrawHorizontalRun(&ScreenPtr, XAdvance, RunLength, Color); } DrawHorizontalRun(&ScreenPtr, XAdvance, FinalPixelCount, Color); UNLOCK_SURFACE_AND_RETURN; } else { /* Y major line */ WholeStep = YDelta / XDelta; AdjUp = (YDelta % XDelta) * 2; AdjDown = XDelta * 2; ErrorTerm = (YDelta % XDelta) - (XDelta * 2); InitialPixelCount = (WholeStep / 2) + 1; FinalPixelCount = InitialPixelCount; if ((AdjUp == 0) && ((WholeStep & 0x01) == 0)) InitialPixelCount --; if ((WholeStep & 0x01) != 0) ErrorTerm += XDelta; DrawVerticalRun(&ScreenPtr, XAdvance, InitialPixelCount, Color); for (i=0; i<(XDelta-1); i++) { RunLength = WholeStep; if ((ErrorTerm += AdjUp) > 0) { RunLength ++; ErrorTerm -= AdjDown; } DrawVerticalRun(&ScreenPtr, XAdvance, RunLength, Color); } DrawVerticalRun(&ScreenPtr, XAdvance, FinalPixelCount, Color); UNLOCK_SURFACE_AND_RETURN; }} /* drawline16 */void clear2dscreen(void){ SDL_Rect rect; rect.x = rect.y = 0; rect.w = surface->w; if (qsetmode == 350) rect.h = 350; else if (qsetmode == 480) { if (ydim16 <= 336) rect.h = 336; else rect.h = 480; } /* else if */ SDL_FillRect(surface, &rect, 0);} /* clear2dscreen */void _idle(void){ handle_events(); SDL_Delay(1);} /* _idle */void *_getVideoBase(void){ return((void *) surface->pixels);}void setactivepage(long dapagenum){ /* !!! Is this really still needed? - DDOI */ /*fprintf(stderr, "%s, line %d; setactivepage(): STUB.\n", __FILE__, __LINE__);*/} /* setactivepage */void limitrate(void){ /* this is a no-op in SDL. It was for buggy VGA cards in DOS. */} /* limitrate */Uint32 _timer_catcher(Uint32 interval, void *bleh){ timerhandler(); return(1);} /* _timer_catcher */void inittimer(void){ SDL_ClearError(); primary_timer = SDL_AddTimer(1000 / PLATFORM_TIMER_HZ, _timer_catcher, NULL); if (primary_timer == NULL) { fprintf(stderr, "BUILDSDL: -ERROR- Problem initializing primary timer!\n"); fprintf(stderr, "BUILDSDL: Reason: [%s]\n", SDL_GetError()); SDL_Quit(); exit(2); } /* if */}void uninittimer(void){ if (primary_timer != NULL) { SDL_RemoveTimer(primary_timer); primary_timer = NULL; } /* if */}void initkeys(void){ /* does nothing in SDL. Key input handling is set up elsewhere. */ /* !!! why not here? */}void uninitkeys(void){ /* does nothing in SDL. Key input handling is set up elsewhere. */}void set16color_palette(void){ /* Backup old palette */ /*VBE_getPalette (0, 16, (char *)&backup_palette);*/ memcpy (&backup_palette, &palette, 16*3); /* Set new palette */ /*VBE_setPalette (0, 16, (char *)&egapalette);*/ memcpy (&palette, &egapalette, 16*3); in_egapalette = 1;} /* set16color_palette */void restore256_palette(void){ /*VBE_setPalette (0, 16, (char *)&backup_palette);*/ memcpy (&palette, &backup_palette, 16*3); in_egapalette = 0;} /* restore256_palette */unsigned long getticks(void){ return(SDL_GetTicks());} /* getticks *//* end of sdl_driver.c ... */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -