2 * $Source: /cvs/cvsroot/d2x/video/svgalib_gr.c,v $
5 * $Date: 2001-01-29 13:47:52 $
7 * SVGALib video functions
9 * $Log: not supported by cvs2svn $
35 extern void mouse_handler (int button, int dx, int dy, int dz, int drx, int dry, int drz);
37 GraphicsContext *physicalscreen, *screenbuffer;
42 gl_copyscreen(physicalscreen);
45 int gr_set_mode(u_int32_t mode)
49 vga_modeinfo *modeinfo;
64 sprintf(vgamode, "G%dx%dx256", w, h);
65 modenum = vga_getmodenumber(vgamode);
68 mouse_seteventhandler(mouse_handler);
70 modeinfo = vga_getmodeinfo(modenum);
72 if (modeinfo->flags & CAPABLE_LINEAR)
76 vga_setlinearaddressing();
78 // Set up physical screen only
79 gl_setcontextvga(modenum);
80 physicalscreen = gl_allocatecontext();
81 gl_getcontext(physicalscreen);
82 screenbuffer = physicalscreen;
84 framebuffer = physicalscreen->vbuf;
85 rowsize = physicalscreen->bytewidth;
91 // Set up the physical screen
92 gl_setcontextvga(modenum);
93 physicalscreen = gl_allocatecontext();
94 gl_getcontext(physicalscreen);
96 // Set up the virtual screen
97 gl_setcontextvgavirtual(modenum);
98 screenbuffer = gl_allocatecontext();
99 gl_getcontext(screenbuffer);
101 framebuffer = screenbuffer->vbuf;
102 rowsize = screenbuffer->bytewidth;
105 memset(grd_curscreen, 0, sizeof(grs_screen));
106 grd_curscreen->sc_mode = mode;
107 grd_curscreen->sc_w = w;
108 grd_curscreen->sc_h = h;
109 grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
110 grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
111 grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
112 grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
113 grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
114 grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = rowsize;
115 grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_LINEAR;
116 grd_curscreen->sc_canvas.cv_bitmap.bm_data = framebuffer;
117 gr_set_current_canvas(NULL);
119 //gamefont_choose_game_font(w,h);
127 int mode = SM(320,200);
129 // Only do this function once!
132 MALLOC(grd_curscreen,grs_screen, 1);
133 memset(grd_curscreen, 0, sizeof(grs_screen));
137 if ((retcode=gr_set_mode(mode)))
140 grd_curscreen->sc_canvas.cv_color = 0;
141 grd_curscreen->sc_canvas.cv_drawmode = 0;
142 grd_curscreen->sc_canvas.cv_font = NULL;
143 grd_curscreen->sc_canvas.cv_font_fg_color = 0;
144 grd_curscreen->sc_canvas.cv_font_bg_color = 0;
145 gr_set_current_canvas( &grd_curscreen->sc_canvas );
158 gl_freecontext(screenbuffer);
159 gl_freecontext(physicalscreen);
163 // Palette functions follow.
165 static int last_r=0, last_g=0, last_b=0;
167 void gr_palette_clear ()
171 memset (colors, 0, 768 * sizeof(int));
172 vga_setpalvec (0, 256, colors);
174 gr_palette_faded_out = 1;
178 void gr_palette_step_up (int r, int g, int b)
181 ubyte *p = gr_palette;
186 if (gr_palette_faded_out) return;
188 if ((r==last_r) && (g==last_g) && (b==last_b)) return;
196 temp = (int)(*p++) + r + gr_palette_gamma;
198 else if (temp>63) temp=63;
200 temp = (int)(*p++) + g + gr_palette_gamma;
202 else if (temp>63) temp=63;
204 temp = (int)(*p++) + b + gr_palette_gamma;
206 else if (temp>63) temp=63;
209 vga_setpalvec (0, 256, colors);
212 //added on 980913 by adb to fix palette problems
213 // need a min without side effects...
215 static inline int min(int x, int y) { return x < y ? x : y; }
218 void gr_palette_load (ubyte *pal)
223 for (i = 0; i < 768; i++)
225 gr_current_pal[i] = pal[i];
226 if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
227 colors[i] = (min(gr_current_pal[i] + gr_palette_gamma, 63));
230 vga_setpalvec (0, 256, colors);
232 gr_palette_faded_out = 0;
233 init_computed_colors();
238 int gr_palette_fade_out (ubyte *pal, int nsteps, int allow_keys)
242 fix fade_palette[768];
243 fix fade_palette_delta[768];
245 int fade_colors[768];
247 if (gr_palette_faded_out) return 0;
249 if (pal==NULL) pal=gr_current_pal;
251 for (i=0; i<768; i++)
253 gr_current_pal[i] = pal[i];
254 fade_palette[i] = i2f(pal[i]);
255 fade_palette_delta[i] = fade_palette[i] / nsteps;
258 for (j=0; j<nsteps; j++)
260 for (i = 0; i < 768; i++)
262 fade_palette[i] -= fade_palette_delta[i];
263 if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma))
264 fade_palette[i] = i2f(pal[i] + gr_palette_gamma);
265 c = f2i(fade_palette[i]);
269 vga_setpalvec (0, 256, fade_colors);
272 gr_palette_faded_out = 1;
278 int gr_palette_fade_in (ubyte *pal, int nsteps, int allow_keys)
282 fix fade_palette[768];
283 fix fade_palette_delta[768];
285 int fade_colors[768];
287 if (!gr_palette_faded_out) return 0;
289 for (i=0; i<768; i++)
291 gr_current_pal[i] = pal[i];
293 fade_palette_delta[i] = i2f(pal[i] + gr_palette_gamma) / nsteps;
296 for (j=0; j<nsteps; j++ )
298 for (i = 0; i < 768; i++ )
300 fade_palette[i] += fade_palette_delta[i];
301 if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma))
302 fade_palette[i] = i2f(pal[i] + gr_palette_gamma);
303 c = f2i(fade_palette[i]);
307 vga_setpalvec (0, 256, fade_colors);
310 gr_palette_faded_out = 0;
316 void gr_palette_read (ubyte *pal)
321 vga_getpalvec (0, 256, colors);
323 for (i = 0; i < 768; i++)