3 * SVGALib video functions
28 int vid_installed = 0;
31 extern void mouse_handler (int button, int dx, int dy, int dz, int drx, int dry, int drz);
33 GraphicsContext *physicalscreen, *screenbuffer;
39 gl_copyscreen(physicalscreen);
43 uint32_t Vid_current_mode;
46 int vid_set_mode(uint32_t mode)
50 vga_modeinfo *modeinfo;
62 Vid_current_mode = mode;
66 sprintf(vgamode, "G%dx%dx256", w, h);
67 modenum = vga_getmodenumber(vgamode);
70 mouse_seteventhandler(mouse_handler);
72 modeinfo = vga_getmodeinfo(modenum);
74 if (modeinfo->flags & CAPABLE_LINEAR)
78 vga_setlinearaddressing();
80 // Set up physical screen only
81 gl_setcontextvga(modenum);
82 physicalscreen = gl_allocatecontext();
83 gl_getcontext(physicalscreen);
84 screenbuffer = physicalscreen;
86 framebuffer = physicalscreen->vbuf;
87 rowsize = physicalscreen->bytewidth;
93 // Set up the physical screen
94 gl_setcontextvga(modenum);
95 physicalscreen = gl_allocatecontext();
96 gl_getcontext(physicalscreen);
98 // Set up the virtual screen
99 gl_setcontextvgavirtual(modenum);
100 screenbuffer = gl_allocatecontext();
101 gl_getcontext(screenbuffer);
103 framebuffer = screenbuffer->vbuf;
104 rowsize = screenbuffer->bytewidth;
107 //gamefont_choose_game_font(w,h);
109 return gr_init_screen(BM_LINEAR, w, h, 0, 0, rowsize, framebuffer);
116 int mode = SM(320,200);
118 // Only do this function once!
119 if (vid_installed == 1)
124 if ((retcode = gr_set_mode(mode)))
135 if (vid_installed == 1) {
138 gl_freecontext(screenbuffer);
139 gl_freecontext(physicalscreen);
143 // Palette functions follow.
145 static int last_r=0, last_g=0, last_b=0;
147 void gr_palette_clear ()
151 memset (colors, 0, 768 * sizeof(int));
152 vga_setpalvec (0, 256, colors);
154 gr_palette_faded_out = 1;
158 void gr_palette_step_up (int r, int g, int b)
161 ubyte *p = gr_palette;
166 if (gr_palette_faded_out) return;
168 if ((r==last_r) && (g==last_g) && (b==last_b)) return;
176 temp = (int)(*p++) + r + gr_palette_gamma.intval;
178 else if (temp>63) temp=63;
180 temp = (int)(*p++) + g + gr_palette_gamma.intval;
182 else if (temp>63) temp=63;
184 temp = (int)(*p++) + b + gr_palette_gamma.intval;
186 else if (temp>63) temp=63;
189 vga_setpalvec (0, 256, colors);
192 //added on 980913 by adb to fix palette problems
193 // need a min without side effects...
195 static inline int min(int x, int y) { return x < y ? x : y; }
198 void gr_palette_load (ubyte *pal)
203 for (i = 0; i < 768; i++)
205 gr_current_pal[i] = pal[i];
206 if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
207 colors[i] = (min(gr_current_pal[i] + gr_palette_gamma.intval, 63));
210 vga_setpalvec (0, 256, colors);
212 gr_palette_faded_out = 0;
213 init_computed_colors();
218 int gr_palette_fade_out (ubyte *pal, int nsteps, int allow_keys)
222 fix fade_palette[768];
223 fix fade_palette_delta[768];
225 int fade_colors[768];
227 if (gr_palette_faded_out) return 0;
229 if (pal==NULL) pal=gr_current_pal;
231 for (i=0; i<768; i++)
233 gr_current_pal[i] = pal[i];
234 fade_palette[i] = i2f(pal[i]);
235 fade_palette_delta[i] = fade_palette[i] / nsteps;
238 for (j=0; j<nsteps; j++)
240 for (i = 0; i < 768; i++)
242 fade_palette[i] -= fade_palette_delta[i];
243 if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma.intval))
244 fade_palette[i] = i2f(pal[i] + gr_palette_gamma.intval);
245 c = f2i(fade_palette[i]);
249 vga_setpalvec (0, 256, fade_colors);
252 gr_palette_faded_out = 1;
258 int gr_palette_fade_in (ubyte *pal, int nsteps, int allow_keys)
262 fix fade_palette[768];
263 fix fade_palette_delta[768];
265 int fade_colors[768];
267 if (!gr_palette_faded_out) return 0;
269 for (i=0; i<768; i++)
271 gr_current_pal[i] = pal[i];
273 fade_palette_delta[i] = i2f(pal[i] + gr_palette_gamma.intval) / nsteps;
276 for (j=0; j<nsteps; j++ )
278 for (i = 0; i < 768; i++ )
280 fade_palette[i] += fade_palette_delta[i];
281 if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma.intval))
282 fade_palette[i] = i2f(pal[i] + gr_palette_gamma.intval);
283 c = f2i(fade_palette[i]);
287 vga_setpalvec (0, 256, fade_colors);
290 gr_palette_faded_out = 0;
296 void gr_palette_read (ubyte *pal)
301 vga_getpalvec (0, 256, colors);
303 for (i = 0; i < 768; i++)