Lines 1-157
Link Here
|
1 |
|
|
|
2 |
$FreeBSD: ports/games/digger-vgl/files/patch-sdl_vid.c,v 1.2 2001/09/22 20:35:22 sobomax Exp $ |
3 |
|
4 |
--- sdl_vid.c.orig Mon Apr 3 23:42:42 2000 |
5 |
+++ sdl_vid.c Thu Sep 13 01:24:35 2001 |
6 |
@@ -1,5 +1,18 @@ |
7 |
-#include <stdlib.h> |
8 |
+/* |
9 |
+ * --------------------------------------------------------------------------- |
10 |
+ * "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp): Maxim |
11 |
+ * Sobolev <sobomax@altavista.net> wrote this file. As long as you retain |
12 |
+ * this notice you can do whatever you want with this stuff. If we meet |
13 |
+ * some day, and you think this stuff is worth it, you can buy me a beer in |
14 |
+ * return. |
15 |
+ * |
16 |
+ * Maxim Sobolev |
17 |
+ * --------------------------------------------------------------------------- |
18 |
+ */ |
19 |
|
20 |
+/* malloc() and friends */ |
21 |
+#include <stdlib.h> |
22 |
+/* Lovely SDL */ |
23 |
#include <SDL.h> |
24 |
|
25 |
#include "def.h" |
26 |
@@ -48,8 +61,11 @@ |
27 |
SDL_Color *ipalettes[] = {vga16_pal1i, vga16_pal2i}; |
28 |
Sint4 currpal=0; |
29 |
|
30 |
+Uint32 addflag=0; |
31 |
+ |
32 |
SDL_Surface *screen = NULL; |
33 |
|
34 |
+/* Data structure holding pending updates */ |
35 |
struct PendNode { |
36 |
void *prevnode; |
37 |
void *nextnode; |
38 |
@@ -77,6 +93,46 @@ |
39 |
{ |
40 |
} |
41 |
|
42 |
+bool setmode(void) |
43 |
+{ |
44 |
+ if((screen = SDL_SetVideoMode(640, 400, 8, \ |
45 |
+ SDL_HWSURFACE | SDL_HWPALETTE | addflag)) == NULL) |
46 |
+ return(FALSE); |
47 |
+ else |
48 |
+ return(TRUE); |
49 |
+} |
50 |
+ |
51 |
+void switchmode(void) |
52 |
+{ |
53 |
+ Uint32 saved; |
54 |
+ SDL_Surface *tmp = NULL; |
55 |
+ SDL_Surface *oldscreen; |
56 |
+ |
57 |
+ vgageti(0, 0, (Uint3 *)&tmp, 80, 200); |
58 |
+ oldscreen = screen; |
59 |
+ saved = addflag; |
60 |
+ |
61 |
+ if(addflag == 0) |
62 |
+ addflag = SDL_FULLSCREEN; |
63 |
+ else |
64 |
+ addflag = 0; |
65 |
+ if(setmode() == FALSE) { |
66 |
+ addflag = saved; |
67 |
+ if(setmode() == FALSE) { |
68 |
+ fprintf(stderr, "Fatal: failed to change videomode and"\ |
69 |
+ "fallback mode failed as well. Exitting.\n"); |
70 |
+ exit(1); |
71 |
+ } |
72 |
+ } |
73 |
+ |
74 |
+ SDL_SetColors(screen, tmp->format->palette->colors, 0, \ |
75 |
+ tmp->format->palette->ncolors); |
76 |
+ vgaputi(0, 0, (Uint3 *)&tmp, 80, 200); |
77 |
+ SDL_FreeSurface(tmp); |
78 |
+ SDL_FreeSurface(oldscreen); |
79 |
+} |
80 |
+ |
81 |
+ |
82 |
void vgainit(void) |
83 |
{ |
84 |
SDL_Surface *tmp = NULL; |
85 |
@@ -92,7 +148,7 @@ |
86 |
} |
87 |
SDL_WM_SetCaption("D I G G E R", NULL); |
88 |
SDL_WM_SetIcon(tmp, NULL); |
89 |
- if ((screen = SDL_SetVideoMode(640, 400, 8, SDL_HWSURFACE | SDL_HWPALETTE)) == NULL) { |
90 |
+ if(setmode() == FALSE) { |
91 |
fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n", SDL_GetError()); |
92 |
exit(1); |
93 |
} |
94 |
@@ -131,7 +187,6 @@ |
95 |
{ |
96 |
struct PendNode *p; |
97 |
|
98 |
- SDL_UnlockSurface(screen); |
99 |
for(p=First;p!=NULL;) |
100 |
{ |
101 |
SDL_UpdateRect(screen,p->rect.x,p->rect.y,p->rect.w,p->rect.h); |
102 |
@@ -139,7 +194,6 @@ |
103 |
free(p); |
104 |
p = First; |
105 |
} |
106 |
- SDL_LockSurface(screen); |
107 |
pendnum = 0; |
108 |
} |
109 |
|
110 |
@@ -161,12 +215,26 @@ |
111 |
tmp->format->palette = screen->format->palette; |
112 |
SDL_BlitSurface(tmp, NULL, screen, &new->rect); |
113 |
tmp->format->palette = reserv; |
114 |
+/* |
115 |
+ * Following piece of code comparing already pending updates with current with |
116 |
+ * main goal to prevent redrawing overlapping rectangles several times. |
117 |
+ */ |
118 |
|
119 |
for(ptr=First;ptr!=NULL;ptr=ptr->nextnode) { |
120 |
if((new->rect.x >= ptr->rect.x) && |
121 |
(new->rect.y >= ptr->rect.y) && |
122 |
- ((new->rect.x+new->rect.w)<=(ptr->rect.x+ptr->rect.w)) && |
123 |
- ((new->rect.y+new->rect.h)<=(ptr->rect.y+ptr->rect.h))) { |
124 |
+ ((new->rect.x+new->rect.w) <= (ptr->rect.x+ptr->rect.w)) && |
125 |
+ ((new->rect.y+new->rect.h) <= (ptr->rect.y+ptr->rect.h))) { |
126 |
+ free(new); |
127 |
+ return; |
128 |
+ } else if((new->rect.x <= ptr->rect.x) && |
129 |
+ (new->rect.y <= ptr->rect.y) && |
130 |
+ ((new->rect.x+new->rect.w) >= (ptr->rect.x+ptr->rect.w)) && |
131 |
+ ((new->rect.y+new->rect.h) >= (ptr->rect.y+ptr->rect.h))) { |
132 |
+ ptr->rect.x = new->rect.x; |
133 |
+ ptr->rect.y = new->rect.y; |
134 |
+ ptr->rect.w = new->rect.w; |
135 |
+ ptr->rect.h = new->rect.h; |
136 |
free(new); |
137 |
return; |
138 |
} |
139 |
@@ -211,6 +279,9 @@ |
140 |
Sint4 rval = 0; |
141 |
Uint8 *pixels; |
142 |
|
143 |
+ if ((x > 319) || (y > 199)) |
144 |
+ return (0xff); |
145 |
+ |
146 |
vgageti(x, y, (Uint3 *)&tmp, 1, 1); |
147 |
pixels = (Uint8 *)tmp->pixels; |
148 |
for (yi=0;yi<tmp->h;yi++) |
149 |
@@ -260,6 +331,8 @@ |
150 |
Sint4 w=3, h=12, size; |
151 |
Sint4 i; |
152 |
|
153 |
+ if(((ch - 32) >= 0x5f) || (ch < 32)) |
154 |
+ return; |
155 |
tmp = ch2bmap(alphas[ch-32], w, h); |
156 |
size = tmp->w*tmp->h; |
157 |
copy = malloc(size); |