2
/* GravityWars 1.1, SDL wrapper (C) 2003 Sam Hocevar <sam@zoy.org> */
22
SDL_Rect score_rect, level_rect, game_rect;
25
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0)
33
int vga_setmode(int mode) {
37
screen = SDL_SetVideoMode(WIDTH, HEIGHT, 8,
38
SDL_HWPALETTE/*|SDL_FULLSCREEN*/);
40
fprintf(stderr, "error setting %dx%d 8bpp indexed mode: %s\n",
41
WIDTH, HEIGHT, SDL_GetError());
49
/* The level area in the background bitmap */
51
level_rect.h = HEIGHT;
53
level_rect.y = 16; /* gets modified, between 16 and 960 */
55
/* Where our viewport gets blitted */
61
/* The score area in the background bitmap */
67
/* Where the score gets blitted - heh, we use NULL! */
72
/* This one is SDL-only */
73
void vga_setsplitline(int sl) {
74
score_rect.h = 480 - sl;
75
score_rect.y = 16 - (480 - sl);
79
#define MIN(a, b) ((a) < (b) ? (a) : (b))
82
#define MAX(a, b) ((a) > (b) ? (a) : (b))
85
int vga_claimvideomemory(int m) {
86
bg = SDL_CreateRGBSurface(SDL_SWSURFACE, WIDTH, m / WIDTH, 8, 0, 0, 0, 0);
91
/* set the palette to the logical screen palette so that blits
92
won't be translated */
93
SDL_SetColors(bg, screen->format->palette->colors, 0, 256);
100
unsigned char *vga_getgraphmem(void) {
104
/* FIXME: implement this as a macro */
105
void vga_setpage(int page) {
106
vga_ptr = bg->pixels + (page << 16);
109
void vga_waitretrace(void) {
110
SDL_BlitSurface(bg, &level_rect, screen, &game_rect);
111
SDL_BlitSurface(bg, &score_rect, screen, NULL);
112
SDL_UpdateRect(screen, 0, 0, 0, 0);
117
void gl_setpalette(void *sp) {
119
char *cols = (char *)sp;
122
for(i=0; i<256; i++) {
123
cmap[i].r = *cols++ * 4;
124
cmap[i].g = *cols++ * 4;
125
cmap[i].b = *cols++ * 4;
128
SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, 256);
131
int gl_setcontextvga(int mode) {
135
void gl_setcontextvirtual(int w, int h, int bpp, int bitspp, void *vbuf) {
139
void *gl_setdisplaystart(int x, int y) {
141
level_rect.y = y; /* y >= 16 */
146
void gl_setpalettecolor(int c, int r, int g, int b) {
152
SDL_SetColors(screen, cmap, 0, 1);
157
int mouse_init(char *dev, int type, int samplerate) {
161
int mouse_update(void) {
165
int mouse_getbutton(void) {
169
void mouse_close(void) {
175
unsigned char keybuf[256];
177
int keyboard_init(void) {
179
memset(scans, 0, 256);
183
void keyboard_close(void) {
187
char *keyboard_getstate(void) {
191
int keyboard_update(void) {
196
mod = SDL_GetModState();
197
scans[SCANCODE_LEFTCONTROL] = mod & KMOD_LCTRL;
198
scans[SCANCODE_RIGHTCONTROL] = mod & KMOD_RCTRL;
200
while(SDL_PollEvent(&e)) {
201
if(e.type == SDL_KEYDOWN) {
202
switch(e.key.keysym.sym) {
204
scans[SCANCODE_ESCAPE] = 1;
208
scans[SCANCODE_CURSORBLOCKLEFT] = 1;
212
scans[SCANCODE_CURSORBLOCKRIGHT] = 1;
216
scans[SCANCODE_CURSORBLOCKUP] = 1;
220
SDL_WM_ToggleFullScreen(screen);
226
} else if(e.type == SDL_KEYUP) {
227
switch(e.key.keysym.sym) {
229
scans[SCANCODE_ESCAPE] = 0;
232
scans[SCANCODE_CURSORBLOCKLEFT] = 0;
235
scans[SCANCODE_CURSORBLOCKRIGHT] = 0;
238
scans[SCANCODE_CURSORBLOCKUP] = 0;