1 /*
2 * OpenBOR - http://www.LavaLit.com
3 * -----------------------------------------------------------------------
4 * Licensed under the BSD license, see LICENSE in OpenBOR root for details.
5 *
6 * Copyright (c) 2004 - 2011 OpenBOR Team
7 */
8
9 #include <SDL.h>
10 #include "types.h"
11 #include "video.h"
12 #include "vga.h"
13 #include "screen.h"
14 #include "openbor.h"
15 #include "filecache.h"
16
17 static SDL_Surface *screen = NULL;
18 static SDL_Surface *surface = NULL;
19 static SDL_Color colors[256];
20 static int width=0, height=0, bpp=0, mode=0;
21
22 static unsigned masks[4][4] = {{0x00000000,0x00000000,0x00000000,0x00000000},
23 {0x0000001F,0x000007E0,0x0000F800,0x00000000},
24 {0x000000FF,0x0000FF00,0x00FF0000,0x00000000},
25 {0x000000FF,0x0000FF00,0x00FF0000,0x00000000}};
26
video_set_mode(s_videomodes videomodes)27 int video_set_mode(s_videomodes videomodes)
28 {
29 bpp = videomodes.pixel;
30 width = videomodes.hRes;
31 height = videomodes.vRes;
32 if(videomodes.hRes==480) mode = 1;
33 if(screen) SDL_FreeSurface(screen);
34 screen = SDL_SetVideoMode(mode?640:width,mode?480:height,8*bpp,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
35 if(screen==NULL) return 0;
36 if(bpp>1)
37 {
38 if(surface) SDL_FreeSurface(surface);
39 surface = SDL_AllocSurface(SDL_SWSURFACE, videomodes.hRes, videomodes.vRes, 8*bpp, masks[bpp-1][0], masks[bpp-1][1], masks[bpp-1][2], masks[bpp-1][3]);
40 if(surface==NULL) return 0;
41 }
42 video_clearscreen();
43 SDL_ShowCursor(SDL_DISABLE);
44 return 1;
45 }
46
video_copy_screen(s_screen * src)47 int video_copy_screen(s_screen* src)
48 {
49 unsigned char *sp;
50 char *dp;
51 int i, linew, slinew;
52 int w=width;
53 int h=height;
54 SDL_Surface* ds = bpp>1?surface:screen;
55
56 filecache_process();
57
58 // Copy to linear video ram
59 sp = (unsigned char*)src->data;
60 dp = ds->pixels;
61
62 linew = w*bpp;
63 slinew = src->width*bpp;
64
65 for(i=0; i<h; i++) {
66 memcpy(dp, sp, linew);
67 sp += slinew;
68 dp += ds->pitch;
69 }
70
71 SDL_Rect rect;
72 rect.x = mode?80:0; rect.y = mode?120:0;
73 rect.w = src->width; rect.h = src->height;
74 if(bpp>1) SDL_BlitSurface(surface, NULL, screen, &rect);
75 SDL_Flip(screen);
76 return 1;
77 }
78
video_clearscreen()79 void video_clearscreen()
80 {
81 memset(screen->pixels, 0, screen->pitch*screen->h);
82 }
83
vga_setpalette(char * palette)84 void vga_setpalette(char* palette)
85 {
86 int i;
87 if(bpp>1) return;
88 for(i=0;i<256;i++){
89 colors[i].r=palette[0];
90 colors[i].g=palette[1];
91 colors[i].b=palette[2];
92 palette+=3;
93 }
94 SDL_SetColors(screen,colors,0,256);
95 }
96
video_fullscreen_flip()97 void video_fullscreen_flip()
98 {
99 }
100
vga_vwait(void)101 void vga_vwait(void)
102 {
103 }
104
105