20 extern void mouse_handler (int button, int dx, int dy, int dz, int drx, int dry, int drz);
22 GraphicsContext *physicalscreen, *screenbuffer;
27 gl_copyscreen(physicalscreen);
30 int gr_set_mode(u_int32_t mode)
34 vga_modeinfo *modeinfo;
49 sprintf(vgamode, "G%dx%dx256", w, h);
50 modenum = vga_getmodenumber(vgamode);
53 mouse_seteventhandler(mouse_handler);
55 modeinfo = vga_getmodeinfo(modenum);
57 if (modeinfo->flags & CAPABLE_LINEAR)
61 vga_setlinearaddressing();
63 // Set up physical screen only
64 gl_setcontextvga(modenum);
65 physicalscreen = gl_allocatecontext();
66 gl_getcontext(physicalscreen);
67 screenbuffer = physicalscreen;
69 framebuffer = physicalscreen->vbuf;
70 rowsize = physicalscreen->bytewidth;
76 // Set up the physical screen
77 gl_setcontextvga(modenum);
78 physicalscreen = gl_allocatecontext();
79 gl_getcontext(physicalscreen);
81 // Set up the virtual screen
82 gl_setcontextvgavirtual(modenum);
83 screenbuffer = gl_allocatecontext();
84 gl_getcontext(screenbuffer);
86 framebuffer = screenbuffer->vbuf;
87 rowsize = screenbuffer->bytewidth;
90 memset(grd_curscreen, 0, sizeof(grs_screen));
91 grd_curscreen->sc_mode = mode;
92 grd_curscreen->sc_w = w;
93 grd_curscreen->sc_h = h;
94 grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
95 grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
96 grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
97 grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
98 grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
99 grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = rowsize;
100 grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_LINEAR;
101 grd_curscreen->sc_canvas.cv_bitmap.bm_data = framebuffer;
102 gr_set_current_canvas(NULL);
104 gamefont_choose_game_font(w,h);
109 int gr_init(int mode)
112 // Only do this function once!
115 MALLOC(grd_curscreen,grs_screen, 1);
116 memset(grd_curscreen, 0, sizeof(grs_screen));
120 if ((retcode=gr_set_mode(mode)))
123 grd_curscreen->sc_canvas.cv_color = 0;
124 grd_curscreen->sc_canvas.cv_drawmode = 0;
125 grd_curscreen->sc_canvas.cv_font = NULL;
126 grd_curscreen->sc_canvas.cv_font_fg_color = 0;
127 grd_curscreen->sc_canvas.cv_font_bg_color = 0;
128 gr_set_current_canvas( &grd_curscreen->sc_canvas );
141 gl_freecontext(screenbuffer);
142 gl_freecontext(physicalscreen);
146 // Palette functions follow.
148 static int last_r=0, last_g=0, last_b=0;
150 void gr_palette_clear ()
154 memset (colors, 0, 768 * sizeof(int));
155 vga_setpalvec (0, 256, colors);
157 gr_palette_faded_out = 1;
161 void gr_palette_step_up (int r, int g, int b)
164 ubyte *p = gr_palette;
169 if (gr_palette_faded_out) return;
171 if ((r==last_r) && (g==last_g) && (b==last_b)) return;
179 temp = (int)(*p++) + r + gr_palette_gamma;
181 else if (temp>63) temp=63;
183 temp = (int)(*p++) + g + gr_palette_gamma;
185 else if (temp>63) temp=63;
187 temp = (int)(*p++) + b + gr_palette_gamma;
189 else if (temp>63) temp=63;
192 vga_setpalvec (0, 256, colors);
195 //added on 980913 by adb to fix palette problems
196 // need a min without side effects...
198 static inline int min(int x, int y) { return x < y ? x : y; }
201 void gr_palette_load (ubyte *pal)
206 for (i = 0; i < 768; i++)
208 gr_current_pal[i] = pal[i];
209 if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
210 colors[i] = (min(gr_current_pal[i] + gr_palette_gamma, 63));
213 vga_setpalvec (0, 256, colors);
215 gr_palette_faded_out = 0;
216 init_computed_colors();
221 int gr_palette_fade_out (ubyte *pal, int nsteps, int allow_keys)
225 fix fade_palette[768];
226 fix fade_palette_delta[768];
228 int fade_colors[768];
230 if (gr_palette_faded_out) return 0;
232 if (pal==NULL) pal=gr_current_pal;
234 for (i=0; i<768; i++)
236 gr_current_pal[i] = pal[i];
237 fade_palette[i] = i2f(pal[i]);
238 fade_palette_delta[i] = fade_palette[i] / nsteps;
241 for (j=0; j<nsteps; j++)
243 for (i = 0; i < 768; i++)
245 fade_palette[i] -= fade_palette_delta[i];
246 if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma))
247 fade_palette[i] = i2f(pal[i] + gr_palette_gamma);
248 c = f2i(fade_palette[i]);
252 vga_setpalvec (0, 256, fade_colors);
255 gr_palette_faded_out = 1;
261 int gr_palette_fade_in (ubyte *pal, int nsteps, int allow_keys)
265 fix fade_palette[768];
266 fix fade_palette_delta[768];
268 int fade_colors[768];
270 if (!gr_palette_faded_out) return 0;
272 for (i=0; i<768; i++)
274 gr_current_pal[i] = pal[i];
276 fade_palette_delta[i] = i2f(pal[i] + gr_palette_gamma) / nsteps;
279 for (j=0; j<nsteps; j++ )
281 for (i = 0; i < 768; i++ )
283 fade_palette[i] += fade_palette_delta[i];
284 if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma))
285 fade_palette[i] = i2f(pal[i] + gr_palette_gamma);
286 c = f2i(fade_palette[i]);
290 vga_setpalvec (0, 256, fade_colors);
293 gr_palette_faded_out = 0;
299 void gr_palette_read (ubyte *pal)
304 vga_getpalvec (0, 256, colors);
306 for (i = 0; i < 768; i++)