]> icculus.org git repositories - btb/d2x.git/blob - main/gamerend.c
ff11b6bd81b588beab43fc599565ecefd71715f3
[btb/d2x.git] / main / gamerend.c
1 /* $Id: gamerend.c,v 1.17 2005-07-30 07:46:03 chris Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Stuff for rendering the HUD
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #ifdef RCS
26 static char rcsid[] = "$Id: gamerend.c,v 1.17 2005-07-30 07:46:03 chris Exp $";
27 #endif
28
29 #ifdef WINDOWS
30 #include "desw.h"
31 #include "winapp.h"
32 #endif
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <stdlib.h>
37
38 #include "pstypes.h"
39 #include "console.h"
40 #include "inferno.h"
41 #include "error.h"
42 #include "mono.h"
43 #include "gr.h"
44 #include "palette.h"
45 #include "ibitblt.h"
46 #include "bm.h"
47 #include "player.h"
48 #include "render.h"
49 #include "menu.h"
50 #include "newmenu.h"
51 #include "screens.h"
52 #include "fix.h"
53 #include "robot.h"
54 #include "game.h"
55 #include "gauges.h"
56 #include "gamefont.h"
57 #include "newdemo.h"
58 #include "text.h"
59 #include "multi.h"
60 #include "endlevel.h"
61 #include "cntrlcen.h"
62 #include "powerup.h"
63 #include "laser.h"
64 #include "playsave.h"
65 #include "automap.h"
66 #include "mission.h"
67 #include "gameseq.h"
68
69 #ifdef OGL
70 #include "ogl_init.h"
71 #endif
72
73 extern fix Cruise_speed;
74 extern int LinearSVGABuffer;
75 extern int Current_display_mode;
76 extern cvar_t r_framerate;
77
78
79 #ifdef WINDOWS
80 cockpit_span_line win_cockpit_mask[480];
81 void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest);
82 #endif
83
84
85 #ifndef NDEBUG
86 extern int Debug_pause;                         //John's debugging pause system
87 #endif
88
89 #ifndef RELEASE
90 extern int Saving_movie_frames;
91 #else
92 #define Saving_movie_frames 0
93 #endif
94
95 // Returns the length of the first 'n' characters of a string.
96 int string_width( char * s, int n )
97 {
98         int w,h,aw;
99         char p;
100         p = s[n];
101         s[n] = 0;
102         gr_get_string_size( s, &w, &h, &aw );
103         s[n] = p;
104         return w;
105 }
106
107 // Draw string 's' centered on a canvas... if wider than
108 // canvas, then wrap it.
109 void draw_centered_text( int y, char * s )
110 {
111         int i, l;
112         char p;
113
114         l = strlen(s);
115
116         if ( string_width( s, l ) < grd_curcanv->cv_bitmap.bm_w )       {
117                 gr_string( 0x8000, y, s );
118                 return;
119         }
120
121         for (i=0; i<l; i++ )    {
122                 if ( string_width(s,i) > (grd_curcanv->cv_bitmap.bm_w - 16) )   {
123                         p = s[i];
124                         s[i] = 0;
125                         gr_string( 0x8000, y, s );
126                         s[i] = p;
127                         gr_string( 0x8000, y+grd_curcanv->cv_font->ft_h+1, &s[i] );
128                         return;
129                 }
130         }
131 }
132
133 extern ubyte DefiningMarkerMessage;
134 extern char Marker_input[];
135
136 #define MAX_MARKER_MESSAGE_LEN 120
137 void game_draw_marker_message()
138 {
139         char temp_string[MAX_MARKER_MESSAGE_LEN+25];
140
141         if ( DefiningMarkerMessage)
142           {
143                 gr_set_curfont( GAME_FONT );    //GAME_FONT 
144                 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
145                 sprintf( temp_string, "Marker: %s_", Marker_input );
146                 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
147           }
148
149 }
150
151 #ifdef NETWORK
152 void game_draw_multi_message()
153 {
154         char temp_string[MAX_MULTI_MESSAGE_LEN+25];
155
156         if ( (Game_mode&GM_MULTI) && (multi_sending_message))   {
157                 gr_set_curfont( GAME_FONT );    //GAME_FONT );
158                 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
159                 sprintf( temp_string, "%s: %s_", TXT_MESSAGE, Network_message );
160                 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
161
162         }
163
164         if ( (Game_mode&GM_MULTI) && (multi_defining_message))  {
165                 gr_set_curfont( GAME_FONT );    //GAME_FONT );
166                 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
167                 sprintf( temp_string, "%s #%d: %s_", TXT_MACRO, multi_defining_message, Network_message );
168                 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
169         }
170 }
171 #endif
172
173 //these should be in gr.h 
174 #define cv_w  cv_bitmap.bm_w
175 #define cv_h  cv_bitmap.bm_h
176
177 fix frame_time_list[8] = {0,0,0,0,0,0,0,0};
178 fix frame_time_total=0;
179 int frame_time_cntr=0;
180
181 void ftoa(char *string, fix f)
182 {
183         int decimal, fractional;
184         
185         decimal = f2i(f);
186         fractional = ((f & 0xffff)*100)/65536;
187         if (fractional < 0 )
188                 fractional *= -1;
189         if (fractional > 99 ) fractional = 99;
190         sprintf( string, "%d.%02d", decimal, fractional );
191 }
192
193 void show_framerate()
194 {
195         char temp[50];
196    //static int q;
197
198         fix rate;
199         int x = 8, y = 5; // position measured from lower right corner
200
201         frame_time_total += RealFrameTime - frame_time_list[frame_time_cntr];
202         frame_time_list[frame_time_cntr] = RealFrameTime;
203         frame_time_cntr = (frame_time_cntr+1)%8;
204
205         rate = fixdiv(f1_0*8,frame_time_total);
206
207         gr_set_curfont( GAME_FONT );    
208         gr_set_fontcolor(gr_getcolor(0,31,0),-1 );
209
210         ftoa( temp, rate );     // Convert fixed to string
211         if (Game_mode & GM_MULTI)
212                 y = 7;
213         gr_printf(grd_curcanv->cv_w-(x*GAME_FONT->ft_w),grd_curcanv->cv_h-y*(GAME_FONT->ft_h+GAME_FONT->ft_h/4),"FPS: %s ", temp );
214 //   if ( !( q++ % 30 ) )
215 //      mprintf( (0,"fps: %s\n", temp ) );
216 }
217
218 #ifndef NDEBUG
219
220 fix Show_view_text_timer = -1;
221
222 void draw_window_label()
223 {
224         if ( Show_view_text_timer > 0 )
225         {
226                 char *viewer_name,*control_name;
227                 char    *viewer_id;
228                 Show_view_text_timer -= FrameTime;
229                 gr_set_curfont( GAME_FONT );
230
231                 viewer_id = "";
232                 switch( Viewer->type )
233                 {
234                         case OBJ_FIREBALL:      viewer_name = "Fireball"; break;
235                         case OBJ_ROBOT:         viewer_name = "Robot";
236 #ifdef EDITOR
237                                                                                 viewer_id = Robot_names[Viewer->id];
238 #endif
239                                 break;
240                         case OBJ_HOSTAGE:               viewer_name = "Hostage"; break;
241                         case OBJ_PLAYER:                viewer_name = "Player"; break;
242                         case OBJ_WEAPON:                viewer_name = "Weapon"; break;
243                         case OBJ_CAMERA:                viewer_name = "Camera"; break;
244                         case OBJ_POWERUP:               viewer_name = "Powerup";
245 #ifdef EDITOR
246                                                                                 viewer_id = Powerup_names[Viewer->id];
247 #endif
248                                 break;
249                         case OBJ_DEBRIS:                viewer_name = "Debris"; break;
250                         case OBJ_CNTRLCEN:      viewer_name = "Reactor"; break;
251                         default:                                        viewer_name = "Unknown"; break;
252                 }
253
254                 switch ( Viewer->control_type) {
255                         case CT_NONE:                   control_name = "Stopped"; break;
256                         case CT_AI:                             control_name = "AI"; break;
257                         case CT_FLYING:         control_name = "Flying"; break;
258                         case CT_SLEW:                   control_name = "Slew"; break;
259                         case CT_FLYTHROUGH:     control_name = "Flythrough"; break;
260                         case CT_MORPH:                  control_name = "Morphing"; break;
261                         default:                                        control_name = "Unknown"; break;
262                 }
263
264                 gr_set_fontcolor( gr_getcolor(31, 0, 0), -1 );
265                 gr_printf( 0x8000, 45, "%i: %s [%s] View - %s",Viewer-Objects, viewer_name, viewer_id, control_name );
266
267         }
268 }
269 #endif
270
271 extern int Game_window_x;
272 extern int Game_window_y;
273 extern int Game_window_w;
274 extern int Game_window_h;
275 extern int max_window_w;
276 extern int max_window_h;
277
278 void render_countdown_gauge()
279 {
280         if (!Endlevel_sequence && Control_center_destroyed  && (Countdown_seconds_left>-1)) { // && (Countdown_seconds_left<127))       {
281                 int     y;
282
283                 if (!is_D2_OEM && !is_MAC_SHARE && !is_SHAREWARE)    // no countdown on registered only
284                 {
285                         //      On last level, we don't want a countdown.
286                         if (PLAYING_BUILTIN_MISSION && Current_level_num == Last_level)
287                         {
288                                 if (!(Game_mode & GM_MULTI))
289                                         return;
290                                 if (Game_mode & GM_MULTI_ROBOTS)
291                                         return;
292                         }
293                 }
294
295                 gr_set_curfont( SMALL_FONT );
296                 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
297                 y = SMALL_FONT->ft_h*4;
298                 if (Cockpit_mode == CM_FULL_SCREEN)
299                         y += SMALL_FONT->ft_h*2;
300
301                 if (Player_is_dead)
302                         y += SMALL_FONT->ft_h*2;
303
304                 //if (!((Cockpit_mode == CM_STATUS_BAR) && (Game_window_y >= 19)))
305                 //      y += 5;
306                 gr_printf(0x8000, y, "T-%d s", Countdown_seconds_left );
307         }
308 }
309
310 void game_draw_hud_stuff()
311 {
312 #ifdef MACINTOSH
313         int odisplay_mode = Current_display_mode;
314         if (Scanline_double) {
315                 FontHires = 0;
316                 Current_display_mode = 0;
317         }
318 #endif
319
320
321         //mprintf ((0,"Linear is %d!\n",LinearSVGABuffer));
322         
323         #ifndef NDEBUG
324         if (Debug_pause) {
325                 gr_set_curfont( MEDIUM1_FONT );
326                 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 ); // gr_getcolor(31,0,0));
327                 gr_ustring( 0x8000, 85/2, "Debug Pause - Press P to exit" );
328         }
329         #endif
330
331         #ifndef NDEBUG
332         draw_window_label();
333         #endif
334
335 #ifdef NETWORK
336         game_draw_multi_message();
337 #endif
338
339    game_draw_marker_message();
340
341 //   if (Game_mode & GM_MULTI)
342 //    {
343 //     if (Netgame.PlayTimeAllowed)
344 //       game_draw_time_left ();
345 //  }
346
347         if ((Newdemo_state == ND_STATE_PLAYBACK) || (Newdemo_state == ND_STATE_RECORDING)) {
348                 char message[128];
349                 int h,w,aw;
350
351                 if (Newdemo_state == ND_STATE_PLAYBACK) {
352                         if (Newdemo_vcr_state != ND_STATE_PRINTSCREEN) {
353                                 sprintf(message, "%s (%d%%%% %s)", TXT_DEMO_PLAYBACK, newdemo_get_percent_done(), TXT_DONE);
354                         } else {
355                                 sprintf (message, " ");
356                         }
357                 } else 
358                         sprintf (message, TXT_DEMO_RECORDING);
359
360                 gr_set_curfont( GAME_FONT );    //GAME_FONT );
361                 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
362
363                 gr_get_string_size(message, &w, &h, &aw );
364                 #ifdef MACINTOSH
365                 if (Scanline_double)            // double height if scanline doubling since we have the correct
366                         h += h;                                 // font for printing, but the wrong height.
367                 #endif
368                 if (Cockpit_mode == CM_FULL_COCKPIT) {
369                         if (grd_curcanv->cv_bitmap.bm_h > 240)
370                                 h += 40;
371                         else
372                                 h += 15;
373                 } else if ( Cockpit_mode == CM_LETTERBOX )
374                         h += 7;
375                 if (Cockpit_mode != CM_REAR_VIEW && !Saving_movie_frames)
376                         gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, grd_curcanv->cv_bitmap.bm_h - h - 2, message );
377         }
378
379         render_countdown_gauge();
380
381         if ( Player_num > -1 && Viewer->type==OBJ_PLAYER && Viewer->id==Player_num )    {
382                 int     x = 3;
383                 int     y = grd_curcanv->cv_bitmap.bm_h;
384
385                 gr_set_curfont( GAME_FONT );
386                 gr_set_fontcolor( gr_getcolor(0, 31, 0), -1 );
387                 if (Cruise_speed > 0) {
388                         int line_spacing = GAME_FONT->ft_h + GAME_FONT->ft_h/4;
389
390 mprintf((0,"line_spacing=%d ",line_spacing));
391
392                         if (Cockpit_mode==CM_FULL_SCREEN) {
393                                 if (Game_mode & GM_MULTI)
394                                         y -= line_spacing * 11; //64
395                                 else
396                                         y -= line_spacing * 6;  //32
397                         } else if (Cockpit_mode == CM_STATUS_BAR) {
398                                 if (Game_mode & GM_MULTI)
399                                         y -= line_spacing * 8;  //48
400                                 else
401                                         y -= line_spacing * 4;  //24
402                         } else {
403                                 y = line_spacing * 2;   //12
404                                 x = 20+2;
405                         }
406
407                         gr_printf( x, y, "%s %2d%%", TXT_CRUISE, f2i(Cruise_speed) );
408                 }
409         }
410
411         if (r_framerate.value)
412                 show_framerate();
413
414         if ( (Newdemo_state == ND_STATE_PLAYBACK) )
415                 Game_mode = Newdemo_game_mode;
416
417         draw_hud();
418
419         if ( (Newdemo_state == ND_STATE_PLAYBACK) )
420                 Game_mode = GM_NORMAL;
421
422         if ( Player_is_dead )
423                 player_dead_message();
424
425 #ifdef MACINTOSH
426         if (Scanline_double) {
427                 FontHires = 1;
428                 Current_display_mode = odisplay_mode;
429         }
430 #endif
431 }
432
433 extern int gr_bitblt_dest_step_shift;
434 extern int gr_wait_for_retrace;
435 extern int gr_bitblt_double;
436
437 #if 0
438 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels );
439 #pragma aux expand_row parm [edi] [esi] [ecx] modify exact [ecx esi edi eax ebx] = \
440         "add    esi, ecx"                       \
441         "dec    esi"                                    \
442         "add    edi, ecx"                       \
443         "add    edi, ecx"                       \
444         "dec    edi"                                    \
445         "dec    edi"                                    \
446 "nextpixel:"                                    \
447         "mov    al,[esi]"                       \
448         "mov    ah, al"                         \
449         "dec    esi"                                    \
450         "mov    [edi], ax"                      \
451         "dec    edi"                                    \
452         "dec    edi"                                    \
453         "dec    ecx"                                    \
454         "jnz    nextpixel"                      \
455 "done:"
456 #else
457 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels )
458 {
459         int i;
460         
461         for (i = 0; i < num_src_pixels; i++) {
462                 *dest++ = *src;
463                 *dest++ = *src++;
464         }
465 }
466 #endif
467
468 // doubles the size in x or y of a bitmap in place.
469 void game_expand_bitmap( grs_bitmap * bmp, uint flags )
470 {
471         int i;
472         ubyte * dptr, * sptr;
473
474         switch(flags & 3)       {
475         case 2: // expand x
476                 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
477                 dptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
478                 for (i=bmp->bm_h-1; i>=0; i-- ) {
479                         expand_row( dptr, dptr, bmp->bm_w );    
480                         dptr -= bmp->bm_rowsize;
481                 }
482                 bmp->bm_w *= 2;
483                 break;
484         case 1: // expand y
485                 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
486                 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
487                 for (i=bmp->bm_h-1; i>=0; i-- ) {
488                         memcpy( dptr, sptr, bmp->bm_w );        
489                         dptr -= bmp->bm_rowsize;
490                         memcpy( dptr, sptr, bmp->bm_w );        
491                         dptr -= bmp->bm_rowsize;
492                         sptr -= bmp->bm_rowsize;
493                 }
494                 bmp->bm_h *= 2;
495                 break;
496         case 3: // expand x & y
497                 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
498                 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
499                 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
500                 for (i=bmp->bm_h-1; i>=0; i-- ) {
501                         expand_row( dptr, sptr, bmp->bm_w );    
502                         dptr -= bmp->bm_rowsize;
503                         expand_row( dptr, sptr, bmp->bm_w );    
504                         dptr -= bmp->bm_rowsize;
505                         sptr -= bmp->bm_rowsize;
506                 }
507                 bmp->bm_w *= 2;
508                 bmp->bm_h *= 2;
509                 break;
510         }
511 }
512
513 extern int SW_drawn[2], SW_x[2], SW_y[2], SW_w[2], SW_h[2];
514
515 extern int Guided_in_big_window;
516
517 #if 0
518 //render a frame for the game in stereo
519 void game_render_frame_stereo()
520 {
521         int dw,dh,sw,sh;
522         fix save_aspect;
523         fix actual_eye_width;
524         int actual_eye_offset;
525         grs_canvas RenderCanvas[2];
526         int no_draw_hud=0;
527
528         save_aspect = grd_curscreen->sc_aspect;
529         grd_curscreen->sc_aspect *= 2;  //Muck with aspect ratio
530
531         sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
532         sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
533
534         if (VR_low_res & 1)     {
535                 sh /= 2;                                
536                 grd_curscreen->sc_aspect *= 2;  //Muck with aspect ratio                                
537         }
538         if (VR_low_res & 2)     {
539                 sw /= 2;                                
540                 grd_curscreen->sc_aspect /= 2;  //Muck with aspect ratio                                
541         }
542
543         gr_init_sub_canvas( &RenderCanvas[0], &VR_render_buffer[0], 0, 0, sw, sh );
544         gr_init_sub_canvas( &RenderCanvas[1], &VR_render_buffer[1], 0, 0, sw, sh );
545
546         // Draw the left eye's view
547         if (VR_eye_switch)      {
548                 actual_eye_width = -VR_eye_width;
549                 actual_eye_offset = -VR_eye_offset;
550         } else {
551                 actual_eye_width = VR_eye_width;
552                 actual_eye_offset = VR_eye_offset;
553         }
554
555         if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window)
556                 actual_eye_offset = 0;
557
558         gr_set_current_canvas(&RenderCanvas[0]);
559
560         if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window) {
561                 char *msg = "Guided Missile View";
562                 object *viewer_save = Viewer;
563                 int w,h,aw;
564
565                 Viewer = Guided_missile[Player_num];
566
567                 WIN(DDGRLOCK(dd_grd_curcanv));  // Must lock DD canvas!!!
568                 {
569                         #ifdef MACINTOSH
570                         if (Scanline_double)
571                                 FontHires = 0;
572                         #endif
573                         update_rendered_data(0, Viewer, 0, 0);
574                         render_frame(0, 0);
575   
576                         wake_up_rendered_objects(Viewer, 0);
577                         Viewer = viewer_save;
578
579                         gr_set_curfont( GAME_FONT );    //GAME_FONT );
580                         gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
581                         gr_get_string_size(msg, &w, &h, &aw );
582
583                         gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
584
585                         draw_guided_crosshair();
586                 }
587                 WIN(DDGRUNLOCK(dd_grd_curcanv));
588
589                         HUD_render_message_frame();
590                         #ifdef MACINTOSH
591                         if (Scanline_double)
592                                 FontHires = 1;
593                         #endif
594
595                 no_draw_hud=1;
596         }
597         else if (Rear_view)
598                 render_frame(actual_eye_width, 0);      // switch eye positions for rear view
599         else
600                 render_frame(-actual_eye_width, 0);             // Left eye
601
602         if ( VR_low_res )
603                 game_expand_bitmap( &RenderCanvas[0].cv_bitmap, VR_low_res );
604
605         {       //render small window into left eye's canvas
606                 grs_canvas *save=grd_curcanv;
607                 fix save_aspect2 = grd_curscreen->sc_aspect;
608                 grd_curscreen->sc_aspect = save_aspect*2;
609                 SW_drawn[0] = SW_drawn[1] = 0;
610                 show_extra_views();
611                 gr_set_current_canvas(save);
612                 grd_curscreen->sc_aspect = save_aspect2;
613         }
614
615 //NEWVR
616         if (actual_eye_offset > 0 ) {
617                 gr_setcolor( gr_getcolor(0,0,0) );
618                 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0, 
619                grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
620         } else if (actual_eye_offset < 0 ) {
621                 gr_setcolor( gr_getcolor(0,0,0) );
622                 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
623         }
624
625         if ( VR_show_hud && !no_draw_hud )      {
626                 grs_canvas tmp;
627                 if (actual_eye_offset < 0 ) {
628                         gr_init_sub_canvas( &tmp, grd_curcanv, labs(actual_eye_offset*2), 0, grd_curcanv->cv_bitmap.bm_w-(labs(actual_eye_offset)*2), grd_curcanv->cv_bitmap.bm_h );
629                 } else {
630                         gr_init_sub_canvas( &tmp, grd_curcanv, 0, 0, grd_curcanv->cv_bitmap.bm_w-(labs(actual_eye_offset)*2), grd_curcanv->cv_bitmap.bm_h );
631                 }
632                 gr_set_current_canvas( &tmp );
633                 game_draw_hud_stuff();
634         }
635
636
637         // Draw the right eye's view
638         gr_set_current_canvas(&RenderCanvas[1]);
639
640         if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window)
641                 gr_bitmap(0,0,&RenderCanvas[0].cv_bitmap);
642         else {
643                 if (Rear_view)
644                         render_frame(-actual_eye_width, 0);     // switch eye positions for rear view
645                 else
646                         render_frame(actual_eye_width, 0);              // Right eye
647
648                 if ( VR_low_res )
649                         game_expand_bitmap( &RenderCanvas[1].cv_bitmap, VR_low_res );
650         }
651
652
653         {       //copy small window from left eye
654                 grs_canvas temp;
655                 int w;
656                 for (w=0;w<2;w++) {
657                         if (SW_drawn[w]) {
658                                 gr_init_sub_canvas(&temp,&RenderCanvas[0],SW_x[w],SW_y[w],SW_w[w],SW_h[w]);
659                                 gr_bitmap(SW_x[w]+actual_eye_offset*2,SW_y[w],&temp.cv_bitmap);
660                         }
661                 }
662         }
663
664 //NEWVR
665         if (actual_eye_offset>0) {
666                 gr_setcolor( gr_getcolor(0,0,0) );
667                 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
668         } else if ( actual_eye_offset < 0 )     {
669                 gr_setcolor( gr_getcolor(0,0,0) );
670                 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0, 
671                grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
672         }
673
674 //NEWVR (Add the next 2 lines)
675         if ( VR_show_hud && !no_draw_hud )      {
676                 grs_canvas tmp;
677                 if (actual_eye_offset > 0 ) {
678                         gr_init_sub_canvas( &tmp, grd_curcanv, labs(actual_eye_offset*2), 0, grd_curcanv->cv_bitmap.bm_w-(labs(actual_eye_offset)*2), grd_curcanv->cv_bitmap.bm_h );
679                 } else {
680                         gr_init_sub_canvas( &tmp, grd_curcanv, 0, 0, grd_curcanv->cv_bitmap.bm_w-(labs(actual_eye_offset)*2), grd_curcanv->cv_bitmap.bm_h );
681                 }
682                 gr_set_current_canvas( &tmp );
683                 game_draw_hud_stuff();
684         }
685
686
687         // Draws white and black registration encoding lines
688         // and Accounts for pixel-shift adjustment in upcoming bitblts
689         if (VR_use_reg_code)    {
690                 int width, height, quarter;
691
692                 width = RenderCanvas[0].cv_bitmap.bm_w;
693                 height = RenderCanvas[0].cv_bitmap.bm_h;
694                 quarter = width / 4;
695
696                 // black out left-hand side of left page
697
698                 // draw registration code for left eye
699                 if ( VR_eye_switch )
700                         gr_set_current_canvas( &RenderCanvas[1] );
701                 else
702                         gr_set_current_canvas( &RenderCanvas[0] );
703                 gr_setcolor( VR_WHITE_INDEX );
704                 gr_scanline( 0, quarter, height-1 );
705                 gr_setcolor( VR_BLACK_INDEX );
706                 gr_scanline( quarter, width-1, height-1 );
707
708                 if ( VR_eye_switch )
709                         gr_set_current_canvas( &RenderCanvas[0] );
710                 else
711                         gr_set_current_canvas( &RenderCanvas[1] );
712                 gr_setcolor( VR_WHITE_INDEX );
713                 gr_scanline( 0, quarter*3, height-1 );
714                 gr_setcolor( VR_BLACK_INDEX );
715                 gr_scanline( quarter*3, width-1, height-1 );
716    }
717
718                 // Copy left eye, then right eye
719         if ( VR_screen_flags&VRF_USE_PAGING )
720                 VR_current_page = !VR_current_page;
721         else 
722                 VR_current_page = 0;
723         gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
724
725 //NEWVR
726
727         if ( VR_eye_offset_changed > 0 )        {
728                 VR_eye_offset_changed--;
729                 gr_clear_canvas(0);
730         }
731
732         sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
733         sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
734
735         // Copy left eye, then right eye
736         gr_bitblt_dest_step_shift = 1;          // Skip every other scanline.
737
738         if (VR_render_mode == VR_INTERLACED )   {
739                 if ( actual_eye_offset > 0 )    {
740                         int xoff = labs(actual_eye_offset);
741                         gr_bm_ubitblt( dw-xoff, dh, xoff, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
742                         gr_bm_ubitblt( dw-xoff, dh, 0, 1, xoff, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
743                 } else if ( actual_eye_offset < 0 )     {
744                         int xoff = labs(actual_eye_offset);
745                         gr_bm_ubitblt( dw-xoff, dh, 0, 0, xoff, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
746                         gr_bm_ubitblt( dw-xoff, dh, xoff, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
747                 } else {
748                         gr_bm_ubitblt( dw, dh, 0, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
749                         gr_bm_ubitblt( dw, dh, 0, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
750                 }
751         } else if (VR_render_mode == VR_AREA_DET) {
752                 // VFX copy
753                 gr_bm_ubitblt( dw, dh, 0,  VR_current_page, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
754                 gr_bm_ubitblt( dw, dh, dw, VR_current_page, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
755         } else {
756                 Int3();         // Huh?
757         }
758
759         gr_bitblt_dest_step_shift = 0;
760
761         //if ( Game_vfx_flag )
762         //      vfx_set_page(VR_current_page);          // 0 or 1
763         //else 
764                 if ( VR_screen_flags&VRF_USE_PAGING )   {
765                         gr_wait_for_retrace = 0;
766
767 //      Added by Samir from John's code
768                 if ( (VR_screen_pages[VR_current_page].cv_bitmap.bm_type == BM_MODEX) && (Game_3dmax_flag==3) ) {
769                         int old_x, old_y, new_x;
770                         old_x = VR_screen_pages[VR_current_page].cv_bitmap.bm_x;
771                         old_y = VR_screen_pages[VR_current_page].cv_bitmap.bm_y;
772                         new_x = old_y*VR_screen_pages[VR_current_page].cv_bitmap.bm_rowsize;
773                         new_x += old_x/4;
774                         VR_screen_pages[VR_current_page].cv_bitmap.bm_x = new_x;
775                         VR_screen_pages[VR_current_page].cv_bitmap.bm_y = 0;
776                         VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_SVGA;
777                         gr_show_canvas( &VR_screen_pages[VR_current_page] );
778                         VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_MODEX;
779                         VR_screen_pages[VR_current_page].cv_bitmap.bm_x = old_x;
780                         VR_screen_pages[VR_current_page].cv_bitmap.bm_y = old_y;
781                 } else {
782                         gr_show_canvas( &VR_screen_pages[VR_current_page] );
783                 }
784                 gr_wait_for_retrace = 1;
785         }
786         grd_curscreen->sc_aspect=save_aspect;
787 }
788 #endif
789 ubyte RenderingType=0;
790 ubyte DemoDoingRight=0,DemoDoingLeft=0;
791 extern ubyte DemoDoRight,DemoDoLeft;
792 extern object DemoRightExtra,DemoLeftExtra;
793
794 char DemoWBUType[]={0,WBU_MISSILE,WBU_MISSILE,WBU_REAR,WBU_ESCORT,WBU_MARKER,WBU_MISSILE};
795 char DemoRearCheck[]={0,0,0,1,0,0,0};
796 char *DemoExtraMessage[]={"PLAYER","GUIDED","MISSILE","REAR","GUIDE-BOT","MARKER","SHIP"};
797
798 extern char guidebot_name[];
799
800 void show_extra_views()
801 {
802         int did_missile_view=0;
803         int save_newdemo_state = Newdemo_state;
804         int w;
805
806    if (Newdemo_state==ND_STATE_PLAYBACK)
807     {
808      if (DemoDoLeft)
809       { 
810                  DemoDoingLeft=DemoDoLeft;
811                 
812        if (DemoDoLeft==3)
813                         do_cockpit_window_view(0,ConsoleObject,1,WBU_REAR,"REAR");
814        else
815               do_cockpit_window_view(0,&DemoLeftExtra,DemoRearCheck[DemoDoLeft],DemoWBUType[DemoDoLeft],DemoExtraMessage[DemoDoLeft]);
816                 }
817      else
818                 do_cockpit_window_view(0,NULL,0,WBU_WEAPON,NULL);
819
820           if (DemoDoRight)
821                 {
822                  DemoDoingRight=DemoDoRight;
823                 
824        if (DemoDoRight==3)
825                         do_cockpit_window_view(1,ConsoleObject,1,WBU_REAR,"REAR");
826        else
827            do_cockpit_window_view(1,&DemoRightExtra,DemoRearCheck[DemoDoRight],DemoWBUType[DemoDoRight],DemoExtraMessage[DemoDoRight]);
828                 } 
829      else
830         do_cockpit_window_view(1,NULL,0,WBU_WEAPON,NULL);
831           
832       DemoDoLeft=DemoDoRight=0;
833                 DemoDoingLeft=DemoDoingRight=0;
834     
835         return;
836     } 
837
838         if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num]) {
839                 if (Guided_in_big_window)
840                  {
841                         RenderingType=6+(1<<4);
842                         do_cockpit_window_view(1,Viewer,0,WBU_MISSILE,"SHIP");
843                  }
844                 else
845                  {
846                         RenderingType=1+(1<<4);
847                         do_cockpit_window_view(1,Guided_missile[Player_num],0,WBU_GUIDED,"GUIDED");
848             }
849                         
850                 did_missile_view=1;
851         }
852         else {
853
854                 if (Guided_missile[Player_num]) {               //used to be active
855                         if (!Guided_in_big_window)
856                                 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
857                         Guided_missile[Player_num] = NULL;
858                 }
859
860                 if (Missile_viewer) {           //do missile view
861                         static int mv_sig=-1;
862                         if (mv_sig == -1)
863                                 mv_sig = Missile_viewer->signature;
864                         if (Missile_view_enabled && Missile_viewer->type!=OBJ_NONE && Missile_viewer->signature == mv_sig) {
865                                 RenderingType=2+(1<<4);
866                                 do_cockpit_window_view(1,Missile_viewer,0,WBU_MISSILE,"MISSILE");
867                                 did_missile_view=1;
868                         }
869                         else {
870                                 Missile_viewer = NULL;
871                                 mv_sig = -1;
872                                 RenderingType=255;
873                                 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
874                         }
875                 }
876         }
877
878         for (w=0;w<2;w++) {
879
880                 if (w==1 && did_missile_view)
881                         continue;               //if showing missile view in right window, can't show anything else
882
883                 //show special views if selected
884                 switch (Cockpit_3d_view[w]) {
885                         case CV_NONE:
886                                 RenderingType=255;
887                                 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
888                                 break;
889                         case CV_REAR:
890                                 if (Rear_view) {                //if big window is rear view, show front here
891                                         RenderingType=3+(w<<4);                         
892                                         do_cockpit_window_view(w,ConsoleObject,0,WBU_REAR,"FRONT");
893                                 }
894                                 else {                                  //show normal rear view
895                                         RenderingType=3+(w<<4);                         
896                                         do_cockpit_window_view(w,ConsoleObject,1,WBU_REAR,"REAR");
897                                 }
898                                 break;
899                         case CV_ESCORT: {
900                                 object *buddy;
901                                 buddy = find_escort();
902                                 if (buddy == NULL) {
903                                         do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
904                                         Cockpit_3d_view[w] = CV_NONE;
905                                 }
906                                 else {
907                                         RenderingType=4+(w<<4);
908                                         do_cockpit_window_view(w,buddy,0,WBU_ESCORT,guidebot_name);
909                                 }
910                                 break;
911                         }
912 #ifdef NETWORK
913                         case CV_COOP: {
914                                 int player = Coop_view_player[w];
915
916                  RenderingType=255; // don't handle coop stuff                  
917                                 
918                                 if (player!=-1 && Players[player].connected && ((Game_mode & GM_MULTI_COOP) || ((Game_mode & GM_TEAM) && (get_team(player) == get_team(Player_num)))))
919                                         do_cockpit_window_view(w,&Objects[Players[Coop_view_player[w]].objnum],0,WBU_COOP,Players[Coop_view_player[w]].callsign);
920                                 else {
921                                         do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
922                                         Cockpit_3d_view[w] = CV_NONE;
923                                 }
924                                 break;
925                         }
926 #endif
927                         case CV_MARKER: {
928                                 char label[10];
929                                 RenderingType=5+(w<<4);
930                                 if (Marker_viewer_num[w] == -1 || MarkerObject[Marker_viewer_num[w]] == -1) {
931                                         Cockpit_3d_view[w] = CV_NONE;
932                                         break;
933                                 }
934                                 sprintf(label,"Marker %d",Marker_viewer_num[w]+1);
935                                 do_cockpit_window_view(w,&Objects[MarkerObject[Marker_viewer_num[w]]],0,WBU_MARKER,label);
936                                 break;
937                         }
938                         default:
939                                 Int3();         //invalid window type
940                 }
941         }
942         RenderingType=0;
943         Newdemo_state = save_newdemo_state;
944 }
945
946 int BigWindowSwitch=0;
947 extern int force_cockpit_redraw;
948 #ifndef MACINTOSH
949 extern ubyte * Game_cockpit_copy_code;
950 #else
951 extern ubyte Game_cockpit_copy_code;
952 #endif
953
954 void draw_guided_crosshair(void);
955
956
957 //render a frame for the game
958 //              WINDOWS:
959 //                      will render everything to dd_VR_render_sub_buffer
960 //                      which all leads to the dd_VR_offscreen_buffer
961 void game_render_frame_mono(void)
962 {
963         WINDOS (
964                 dd_grs_canvas Screen_3d_window,
965                 grs_canvas Screen_3d_window
966         );
967         int no_draw_hud=0;
968         
969
970         WINDOS (
971                 dd_gr_init_sub_canvas(&Screen_3d_window, &dd_VR_screen_pages[0],
972                         dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x, 
973                         dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y, 
974                         dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_w, 
975                         dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_h),
976                 gr_init_sub_canvas( &Screen_3d_window, &VR_screen_pages[0], 
977                         VR_render_sub_buffer[0].cv_bitmap.bm_x, 
978                         VR_render_sub_buffer[0].cv_bitmap.bm_y, 
979                         VR_render_sub_buffer[0].cv_bitmap.bm_w, 
980                         VR_render_sub_buffer[0].cv_bitmap.bm_h)
981         );
982
983         if ( Game_double_buffer ) {     
984                 WINDOS(
985                         dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
986                         gr_set_current_canvas(&VR_render_sub_buffer[0])
987                 );
988         }
989         else    {
990                 WINDOS(
991                         dd_gr_set_current_canvas(&Screen_3d_window),
992                         gr_set_current_canvas(&Screen_3d_window)
993                 );
994         }
995         
996         if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window) {
997                 char *msg = "Guided Missile View";
998                 object *viewer_save = Viewer;
999                 int w,h,aw;
1000
1001       if (Cockpit_mode==CM_FULL_COCKPIT)
1002                         {
1003                          BigWindowSwitch=1;
1004                          force_cockpit_redraw=1;
1005                          Cockpit_mode=CM_STATUS_BAR;
1006                          return;
1007                    }
1008   
1009                 Viewer = Guided_missile[Player_num];
1010
1011                 WIN(DDGRLOCK(dd_grd_curcanv));  // Must lock DD canvas!!!
1012                 {
1013                         #ifdef MACINTOSH
1014                         if (Scanline_double)
1015                                 FontHires = 0;
1016                         #endif
1017                         update_rendered_data(0, Viewer, 0, 0);
1018                         render_frame(0, 0);
1019   
1020                         wake_up_rendered_objects(Viewer, 0);
1021                         Viewer = viewer_save;
1022
1023                         gr_set_curfont( GAME_FONT );    //GAME_FONT );
1024                         gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
1025                         gr_get_string_size(msg, &w, &h, &aw );
1026
1027                         gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
1028
1029                         draw_guided_crosshair();
1030                 }
1031                 WIN(DDGRUNLOCK(dd_grd_curcanv));
1032
1033                         HUD_render_message_frame();
1034                         #ifdef MACINTOSH
1035                         if (Scanline_double)
1036                                 FontHires = 1;
1037                         #endif
1038
1039                 no_draw_hud=1;
1040         }
1041         else
1042          {      
1043                 if (BigWindowSwitch)
1044                  {
1045                    force_cockpit_redraw=1;
1046                         Cockpit_mode=CM_FULL_COCKPIT;
1047                    BigWindowSwitch=0;
1048                         return;
1049                  }
1050                 WIN(DDGRLOCK(dd_grd_curcanv));  // Must lock DD canvas!!!
1051                 update_rendered_data(0, Viewer, Rear_view, 0);
1052                 render_frame(0, 0);
1053                 WIN(DDGRUNLOCK(dd_grd_curcanv));
1054          }
1055
1056         if ( Game_double_buffer ) {     
1057                 WINDOS(
1058                         dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1059                         gr_set_current_canvas(&VR_render_sub_buffer[0])
1060                 );
1061         }
1062         else    {
1063                 WINDOS(
1064                         dd_gr_set_current_canvas(&Screen_3d_window),
1065                         gr_set_current_canvas(&Screen_3d_window)
1066                 );
1067         }
1068
1069         if (!no_draw_hud)       {
1070                 WIN(DDGRLOCK(dd_grd_curcanv));
1071                 game_draw_hud_stuff();
1072                 WIN(DDGRUNLOCK(dd_grd_curcanv));
1073         }
1074
1075         show_extra_views();             //missile view, buddy bot, etc.
1076
1077 #ifdef WINDOWS
1078         if (Game_paused) {              //render pause message over off-screen 3d (to minimize flicker)
1079                 extern char *Pause_msg;
1080 //              LPDIRECTDRAWSURFACE save_dds = dd_VR_screen_pages[VR_current_page].lpdds;
1081
1082 //              dd_VR_screen_pages[VR_current_page].lpdds = dd_VR_render_buffer[VR_current_page].lpdds;
1083                 show_boxed_message(Pause_msg);
1084 //              dd_VR_screen_pages[VR_current_page].lpdds = save_dds;
1085         }
1086 #else
1087         if (Game_paused) {              //render pause message over off-screen 3d (to minimize flicker)
1088                 extern char *Pause_msg;
1089                 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1090
1091                 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1092                 show_boxed_message(Pause_msg);
1093                 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1094         }
1095 #endif
1096
1097         if ( Game_double_buffer ) {             //copy to visible screen
1098                 if ( !Game_cockpit_copy_code )  {
1099                         if ( VR_screen_flags&VRF_USE_PAGING )   {       
1100                                 VR_current_page = !VR_current_page;
1101                                 #ifdef WINDOWS
1102                                         dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]);
1103                                         dd_gr_flip();
1104                                 #else
1105                                         gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1106                                         gr_bm_ubitblt( VR_render_sub_buffer[0].cv_w, VR_render_sub_buffer[0].cv_h, VR_render_sub_buffer[0].cv_bitmap.bm_x, VR_render_sub_buffer[0].cv_bitmap.bm_y, 0, 0, &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap );
1107                                         gr_wait_for_retrace = 0;
1108                                         gr_show_canvas( &VR_screen_pages[VR_current_page] );
1109                                         gr_wait_for_retrace = 1;
1110                                 #endif
1111                         } else {
1112                         #ifdef MACINTOSH
1113                                 if (Scanline_double)
1114                                         gr_bm_ubitblt_double( VR_render_sub_buffer[0].cv_w, VR_render_sub_buffer[0].cv_h, VR_render_sub_buffer[0].cv_bitmap.bm_x, VR_render_sub_buffer[0].cv_bitmap.bm_y, 0, 0, &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap );
1115                                 else
1116                         #endif // NOTE LINK TO ABOVE IF
1117                         #ifdef WINDOWS    
1118                                 if (GRMODEINFO(emul) || GRMODEINFO(modex) || GRMODEINFO(dbuf))
1119                                         // From render buffer to screen buffer.
1120                                         dd_gr_blt_notrans(&dd_VR_render_sub_buffer[0],
1121                                                 0,0,
1122                                                 dd_VR_render_sub_buffer[0].canvas.cv_w,
1123                                                 dd_VR_render_sub_buffer[0].canvas.cv_h,
1124                                                 dd_grd_screencanv,
1125                                                 dd_VR_render_sub_buffer[0].xoff, 
1126                                                 dd_VR_render_sub_buffer[0].yoff, 
1127                                                 dd_VR_render_sub_buffer[0].canvas.cv_w,
1128                                                 dd_VR_render_sub_buffer[0].canvas.cv_h);
1129
1130                                         DDGRRESTORE;
1131                         // Puts back canvas to front canvas by blt or flip
1132                                 if (GRMODEINFO(modex)) {
1133                                         //@@VR_current_page = !VR_current_page;
1134                                         //@@dd_gr_flip();
1135                                         win_flip = 1;
1136                                 }
1137                         #else
1138                                 gr_bm_ubitblt( VR_render_sub_buffer[0].cv_w, 
1139                                                 VR_render_sub_buffer[0].cv_h, 
1140                                                 VR_render_sub_buffer[0].cv_bitmap.bm_x, 
1141                                                 VR_render_sub_buffer[0].cv_bitmap.bm_y, 
1142                                                 0, 0, 
1143                                                 &VR_render_sub_buffer[0].cv_bitmap, 
1144                                                 &VR_screen_pages[0].cv_bitmap );
1145                         #endif
1146                         }
1147                 } else  {
1148                         #if 1 //def MACINTOSH
1149                                 gr_ibitblt( &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Scanline_double );
1150                         #else
1151                         #ifndef WINDOWS
1152                                 gr_ibitblt( &VR_render_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Game_cockpit_copy_code );
1153                         #else
1154                                 win_do_emul_ibitblt( &dd_VR_render_sub_buffer[0], dd_grd_screencanv);
1155                                 DDGRRESTORE;
1156                                 if (GRMODEINFO(modex)) {
1157                                         //@@VR_current_page = !VR_current_page;
1158                                         //@@dd_gr_flip();
1159                                         win_flip = 1;
1160                                 }
1161                         #endif
1162                         #endif
1163                 }
1164         }
1165
1166         if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR) {
1167
1168                 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1169                         Game_mode = Newdemo_game_mode;
1170
1171                 render_gauges();
1172
1173                 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1174                         Game_mode = GM_NORMAL;
1175         }
1176
1177 #ifdef WINDOWS
1178         if (win_flip) {
1179                 VR_current_page = !VR_current_page;
1180                 dd_gr_flip();
1181         }
1182 #endif
1183
1184         con_update();
1185
1186         gr_update();
1187 #ifdef OGL
1188         ogl_swap_buffers();
1189 #endif
1190 }
1191
1192 void toggle_cockpit()
1193 {
1194         int new_mode;
1195
1196         switch (Cockpit_mode) {
1197
1198                 case CM_FULL_COCKPIT: {
1199                         int max_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
1200                         if (Game_window_h > max_h)              //too big for statusbar
1201                                 new_mode = CM_FULL_SCREEN;
1202                         else
1203                                 new_mode = CM_STATUS_BAR;
1204                         break;
1205                 }
1206
1207                 case CM_STATUS_BAR:
1208                 case CM_FULL_SCREEN:
1209                         if (Rear_view)
1210                                 return;
1211                         new_mode = CM_FULL_COCKPIT;
1212                         break;
1213
1214                 case CM_REAR_VIEW:
1215                 case CM_LETTERBOX:
1216                 default:
1217                         return;                 //do nothing
1218                         break;
1219
1220         }
1221
1222         select_cockpit(new_mode);
1223         HUD_clear_messages();
1224         write_player_file();
1225 }
1226
1227 #ifndef MACINTOSH
1228 #define WINDOW_W_DELTA  ((max_window_w / 16)&~1)        //24    //20
1229 #define WINDOW_H_DELTA  ((max_window_h / 16)&~1)        //12    //10
1230
1231 #define WINDOW_MIN_W            ((max_window_w * 10) / 22)      //160
1232 #define WINDOW_MIN_H            ((max_window_h * 10) / 22)
1233 #else
1234 //#define WINDOW_W_DELTA        32
1235 //#define WINDOW_H_DELTA        16
1236
1237 #define WINDOW_W_DELTA  ((max_window_w / 16) & ~15)             // double word aligned
1238 #define WINDOW_H_DELTA  ((max_window_h / 16) & ~15)             // double word aligned
1239
1240 #define WINDOW_MIN_W            (max_window_w-(WINDOW_W_DELTA*11))
1241 #define WINDOW_MIN_H            (max_window_h-(WINDOW_H_DELTA*11))
1242 #endif
1243
1244 void grow_window()
1245 {
1246         if (Cockpit_mode == CM_FULL_COCKPIT) {
1247                 Game_window_h = max_window_h;
1248                 Game_window_w = max_window_w;
1249                 toggle_cockpit();
1250                 HUD_init_message("Press F3 to return to Cockpit mode");
1251                 return;
1252         }
1253
1254         if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1255                 return;
1256
1257         if (Game_window_h>=max_window_h || Game_window_w>=max_window_w) {
1258                 //Game_window_w = max_window_w;
1259                 //Game_window_h = max_window_h;
1260                 select_cockpit(CM_FULL_SCREEN);
1261         } else {
1262                 //int x,y;
1263
1264                 Game_window_w += WINDOW_W_DELTA;
1265                 Game_window_h += WINDOW_H_DELTA;
1266
1267                 #ifdef MACINTOSH                // horrible hack to ensure that height is even to satisfy pixel doubling blitter
1268                 if ( Scanline_double && (Game_window_h & 1) )
1269                         Game_window_h--;
1270                 #endif
1271
1272                 if (Game_window_h > max_window_h)
1273                         Game_window_h = max_window_h;
1274
1275                 if (Game_window_w > max_window_w)
1276                         Game_window_w = max_window_w;
1277
1278                 Game_window_x = (max_window_w - Game_window_w)/2;
1279                 Game_window_y = (max_window_h - Game_window_h)/2;
1280
1281                 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1282         }
1283
1284         HUD_clear_messages();   //      @mk, 11/11/94
1285
1286         write_player_file();
1287 }
1288
1289 // grs_bitmap background_bitmap;        already declared in line 434 (samir 4/10/94)
1290
1291 extern grs_bitmap background_bitmap;
1292
1293 void copy_background_rect(int left,int top,int right,int bot)
1294 {
1295         grs_bitmap *bm = &background_bitmap;
1296         int x,y;
1297         int tile_left,tile_right,tile_top,tile_bot;
1298         int ofs_x,ofs_y;
1299         int dest_x,dest_y;
1300
1301         if (right < left || bot < top)
1302                 return;
1303
1304         tile_left = left / bm->bm_w;
1305         tile_right = right / bm->bm_w;
1306         tile_top = top / bm->bm_h;
1307         tile_bot = bot / bm->bm_h;
1308
1309         ofs_y = top % bm->bm_h;
1310         dest_y = top;
1311
1312 WIN(DDGRLOCK(dd_grd_curcanv))
1313 {
1314         for (y=tile_top;y<=tile_bot;y++) {
1315                 int w,h;
1316
1317                 ofs_x = left % bm->bm_w;
1318                 dest_x = left;
1319
1320                 //h = (bot < dest_y+bm->bm_h)?(bot-dest_y+1):(bm->bm_h-ofs_y);
1321                 h = min(bot-dest_y+1,bm->bm_h-ofs_y);
1322
1323                 for (x=tile_left;x<=tile_right;x++) {
1324
1325                         //w = (right < dest_x+bm->bm_w)?(right-dest_x+1):(bm->bm_w-ofs_x);
1326                         w = min(right-dest_x+1,bm->bm_w-ofs_x);
1327                 
1328                         gr_bm_ubitblt(w,h,dest_x,dest_y,ofs_x,ofs_y,
1329                                         &background_bitmap,&grd_curcanv->cv_bitmap);
1330
1331                         ofs_x = 0;
1332                         dest_x += w;
1333                 }
1334
1335                 ofs_y = 0;
1336                 dest_y += h;
1337         }
1338
1339 WIN(DDGRUNLOCK(dd_grd_curcanv));
1340
1341 }
1342
1343 #ifdef WINDOWS
1344 int force_background_fill=0;
1345 #endif
1346
1347 //fills int the background surrounding the 3d window
1348 void fill_background()
1349 {
1350         int x,y,w,h,dx,dy;
1351
1352         x = Game_window_x;
1353         y = Game_window_y;
1354         w = Game_window_w;
1355         h = Game_window_h;
1356
1357         dx = x;
1358         dy = y;
1359
1360         WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1361                                 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1362         );
1363         copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1364         copy_background_rect(x+w,y-dy,grd_curcanv->cv_w-1,y+h+dy-1);
1365         copy_background_rect(x,y-dy,x+w-1,y-1);
1366         copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1367
1368 #ifdef WINDOWS
1369         if (GRMODEINFO(modex)) {
1370                 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1371                 copy_background_rect(x+w,y-dy,grd_curcanv->cv_w-1,y+h+dy-1);
1372                 copy_background_rect(x,y-dy,x+w-1,y-1);
1373                 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1374         }
1375 #endif
1376
1377         if (VR_screen_flags & VRF_USE_PAGING) {
1378                 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[!VR_current_page]),
1379                                         gr_set_current_canvas(&VR_screen_pages[!VR_current_page])
1380                 );
1381                 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1382                 copy_background_rect(x+w,y-dy,x+w+dx-1,y+h+dy-1);
1383                 copy_background_rect(x,y-dy,x+w-1,y-1);
1384                 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1385         }
1386
1387         #ifdef WINDOWS
1388         if (GRMODEINFO(modex) && force_background_fill==0)              //double-buffered
1389                 force_background_fill=2;
1390         #endif
1391 }
1392
1393 void shrink_window()
1394 {
1395         #ifdef WINDOWS
1396         //When you shrink the window twice in two frames, the background doens't
1397         //restore properly.  So this hack keeps you from shrinking the window
1398         //before two frames have been drawn
1399         static int last_shrink_framecount=-1;
1400         if (FrameCount - last_shrink_framecount < 2)
1401                 return;
1402         last_shrink_framecount = FrameCount;
1403         #endif
1404         
1405         mprintf((0,"%d ",FrameCount));
1406
1407 //  mprintf ((0,"W=%d H=%d\n",Game_window_w,Game_window_h));
1408  
1409         if (Cockpit_mode == CM_FULL_COCKPIT && (VR_screen_flags & VRF_ALLOW_COCKPIT)) {
1410                 Game_window_h = max_window_h;
1411                 Game_window_w = max_window_w;
1412                 //!!toggle_cockpit();
1413                 select_cockpit(CM_STATUS_BAR);
1414 //              shrink_window();
1415 //              shrink_window();
1416                 HUD_init_message("Press F3 to return to Cockpit mode");
1417                 write_player_file();
1418                 return;
1419         }
1420
1421         if (Cockpit_mode == CM_FULL_SCREEN && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1422         {
1423                 //Game_window_w = max_window_w;
1424                 //Game_window_h = max_window_h;
1425                 select_cockpit(CM_STATUS_BAR);
1426                 write_player_file();
1427                 return;
1428         }
1429
1430         if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1431                 return;
1432
1433    mprintf ((0,"Cockpit mode=%d\n",Cockpit_mode));
1434
1435         if (Game_window_w > WINDOW_MIN_W) {
1436                 //int x,y;
1437
1438       Game_window_w -= WINDOW_W_DELTA;
1439                 Game_window_h -= WINDOW_H_DELTA;
1440
1441
1442   mprintf ((0,"NewW=%d NewH=%d VW=%d maxH=%d\n",Game_window_w,Game_window_h,max_window_w,max_window_h));
1443                   
1444                 if ( Game_window_w < WINDOW_MIN_W )
1445                         Game_window_w = WINDOW_MIN_W;
1446
1447                 if ( Game_window_h < WINDOW_MIN_H )
1448                         Game_window_h = WINDOW_MIN_H;
1449                         
1450                 #ifdef MACINTOSH                // horrible hack to ensure that height is even to satisfy pixel doubling blitter
1451                 if ( Scanline_double && (Game_window_h & 1) )
1452                         Game_window_h--;
1453                 #endif
1454
1455                 Game_window_x = (max_window_w - Game_window_w)/2;
1456                 Game_window_y = (max_window_h - Game_window_h)/2;
1457
1458                 fill_background();
1459
1460                 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1461                 HUD_clear_messages();
1462                 write_player_file();
1463         }
1464
1465 }
1466
1467 int last_drawn_cockpit[2] = { -1, -1 };
1468
1469 // This actually renders the new cockpit onto the screen.
1470 void update_cockpits(int force_redraw)
1471 {
1472         //int x, y, w, h;
1473
1474         //Redraw the on-screen cockpit bitmaps
1475         if (VR_render_mode != VR_NONE ) return;
1476
1477         switch( Cockpit_mode )  {
1478         case CM_FULL_COCKPIT:
1479         case CM_REAR_VIEW:
1480         WINDOS(
1481                 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1482                 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1483         );
1484                 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1485
1486         WIN(DDGRLOCK(dd_grd_curcanv));
1487                 gr_ubitmapm(0,0, &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);   
1488         WIN(DDGRUNLOCK(dd_grd_curcanv));
1489                 break;
1490
1491         case CM_FULL_SCREEN:
1492                 Game_window_x = (max_window_w - Game_window_w)/2;
1493                 Game_window_y = (max_window_h - Game_window_h)/2;
1494                 fill_background();
1495                 break;
1496
1497         case CM_STATUS_BAR:
1498
1499                         WINDOS (        dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1500                                                 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1501                         );
1502
1503                         PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1504                         
1505                         WIN(DDGRLOCK(dd_grd_curcanv));
1506                                 gr_ubitmapm(0,max_window_h,&GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1507                         WIN(DDGRUNLOCK(dd_grd_curcanv));
1508         
1509                 #ifdef MACINTOSH                // hideously horrible hack to put grey line 1 scanline above because of pixel doubling "oddness"
1510                         if (Scanline_double)
1511                         {
1512                                 gr_setcolor(BM_XRGB(13,13,13));         // color of top of status bar
1513                                 gr_uscanline( 0, grd_curcanv->cv_w, max_window_h-1 );
1514                         }
1515                 #endif
1516
1517                 Game_window_x = (max_window_w - Game_window_w)/2;
1518                 Game_window_y = (max_window_h - Game_window_h)/2;
1519                 fill_background();
1520                 break;
1521
1522         case CM_LETTERBOX:
1523                 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1524                                         gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1525                 );
1526                 WINDOS ( dd_gr_clear_canvas( BM_XRGB(0,0,0) ),
1527                                         gr_clear_canvas( BM_XRGB(0,0,0) ) );
1528
1529                 // In a modex mode, clear the other buffer.
1530                 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
1531                         gr_set_current_canvas(&VR_screen_pages[VR_current_page^1]);
1532                         gr_clear_canvas( BM_XRGB(0,0,0) );
1533                         gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1534                 }
1535                 break;
1536
1537         }
1538
1539         WINDOS (        dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1540                                 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1541         );
1542
1543         if (Cockpit_mode != last_drawn_cockpit[VR_current_page] || force_redraw )
1544                 last_drawn_cockpit[VR_current_page] = Cockpit_mode;
1545         else
1546                 return;
1547
1548         if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
1549                 init_gauges();
1550
1551 }
1552
1553
1554 void game_render_frame()
1555 {
1556         set_screen_mode( SCREEN_GAME );
1557
1558         update_cockpits(0);
1559
1560         #ifdef WINDOWS
1561         if (force_background_fill) {
1562                 fill_background();
1563                 force_background_fill--;
1564         }
1565         #endif
1566
1567         play_homing_warning();
1568
1569         if (VR_render_mode == VR_NONE )
1570                 game_render_frame_mono();        
1571 /*      else
1572                 game_render_frame_stereo();      
1573                 */
1574
1575         // Make sure palette is faded in
1576         stop_time();
1577         gr_palette_fade_in( gr_palette, 32, 0 );
1578         start_time();
1579
1580         FrameCount++;
1581 }
1582
1583 extern int Color_0_31_0;
1584
1585 //draw a crosshair for the guided missile
1586 void draw_guided_crosshair(void)
1587 {
1588         int x,y,w,h;
1589
1590         gr_setcolor(Color_0_31_0);
1591
1592         w = grd_curcanv->cv_w>>5;
1593         if (w < 5)
1594                 w = 5;
1595
1596         h = i2f(w) / grd_curscreen->sc_aspect;
1597
1598         x = grd_curcanv->cv_w / 2;
1599         y = grd_curcanv->cv_h / 2;
1600
1601         gr_scanline(x-w/2,x+w/2,y);
1602         gr_uline(i2f(x),i2f(y-h/2),i2f(x),i2f(y+h/2));
1603
1604 }
1605
1606 typedef struct bkg {
1607         short x, y, w, h;                       // The location of the menu.
1608         grs_bitmap * bmp;                       // The background under the menu.
1609 } bkg;
1610
1611 bkg bg = {0,0,0,0,NULL};
1612
1613 #define BOX_BORDER (MenuHires?60:30)
1614
1615 //show a message in a nice little box
1616 void show_boxed_message(char *msg)
1617 {       
1618         int w,h,aw;
1619         int x,y;
1620
1621         WINDOS(
1622                 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1623                 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1624         );
1625         gr_set_curfont( MEDIUM1_FONT );
1626
1627         gr_get_string_size(msg,&w,&h,&aw);
1628
1629         x = (grd_curscreen->sc_w-w)/2;
1630         y = (grd_curscreen->sc_h-h)/2;
1631
1632         if (bg.bmp) {
1633                 gr_free_bitmap(bg.bmp);
1634                 bg.bmp = NULL;
1635         }
1636
1637         // Save the background of the display
1638         bg.x=x; bg.y=y; bg.w=w; bg.h=h;
1639
1640         bg.bmp = gr_create_bitmap( w+BOX_BORDER, h+BOX_BORDER );
1641
1642         WIN( DDGRLOCK(dd_grd_curcanv));
1643                 gr_bm_ubitblt(w+BOX_BORDER, h+BOX_BORDER, 0, 0, x-BOX_BORDER/2, y-BOX_BORDER/2, &(grd_curcanv->cv_bitmap), bg.bmp );
1644         WIN( DDGRUNLOCK(dd_grd_curcanv));
1645
1646                 nm_draw_background(x-BOX_BORDER/2,y-BOX_BORDER/2,x+w+BOX_BORDER/2-1,y+h+BOX_BORDER/2-1);
1647
1648                 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 );
1649
1650         WIN( DDGRLOCK(dd_grd_curcanv));
1651                 gr_ustring( 0x8000, y, msg );
1652         WIN( DDGRUNLOCK(dd_grd_curcanv));
1653         WIN( DDGRRESTORE);
1654 }
1655
1656 void clear_boxed_message()
1657 {
1658
1659         if (bg.bmp) {
1660
1661                 WIN(DDGRLOCK(dd_grd_curcanv));
1662                         gr_bitmap(bg.x-BOX_BORDER/2, bg.y-BOX_BORDER/2, bg.bmp);
1663                 WIN(DDGRUNLOCK(dd_grd_curcanv));
1664                 WIN(DDGRRESTORE);
1665         
1666                 gr_free_bitmap(bg.bmp);
1667                 bg.bmp = NULL;
1668         }
1669 }
1670
1671
1672 #ifdef WINDOWS
1673 void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest)
1674 {
1675         ubyte *src_data;
1676         ubyte *dest_data;
1677         int line, span;
1678
1679
1680         WIN(DDGRLOCK(csrc));
1681         WIN(DDGRLOCK(cdest));
1682                 src_data = csrc->canvas.cv_bitmap.bm_data;
1683                 dest_data = cdest->canvas.cv_bitmap.bm_data; 
1684
1685 //              mprintf((0, "Render Ptr: %x;  Dest Ptr: %x;\n",src_data, dest_data));
1686
1687                 for (line = 0; line < 480; line++, 
1688                                                 dest_data += cdest->canvas.cv_bitmap.bm_rowsize)
1689                 {
1690                         cockpit_span_line *sline;
1691
1692                         sline = &win_cockpit_mask[line];
1693
1694                         if (!sline->num) continue;
1695                         if (sline->num == 255) break;
1696                         for (span = 0; span < sline->num; span++)
1697                         {
1698                                 if ((sline->span[span].xmax-sline->span[span].xmin+1) < 10) {
1699                                         gr_winckpit_blt_span(sline->span[span].xmin,
1700                                                                                 sline->span[span].xmax,
1701                                                                                 src_data, dest_data);
1702                                 }
1703                                 else {
1704                                         gr_winckpit_blt_span_long(sline->span[span].xmin,
1705                                                                                 sline->span[span].xmax,
1706                                                                                 src_data, dest_data);
1707                                 }
1708                         }
1709                         src_data += csrc->canvas.cv_bitmap.bm_rowsize;
1710                 }
1711         WIN(DDGRUNLOCK(cdest));
1712         WIN(DDGRUNLOCK(csrc));
1713 }
1714
1715
1716 //@@void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest)
1717 //@@{
1718 //@@    HRESULT res;
1719 //@@    DDBLTFX bltfx;
1720 //@@    RECT srect, drect;
1721 //@@
1722 //@@//  Do Render Blt to Mask Surface (dest blt 1-255)
1723 //@@    bltfx.dwSize = sizeof(bltfx);
1724 //@@    bltfx.ddckDestColorkey.dwColorSpaceLowValue = 1;
1725 //@@    bltfx.ddckDestColorkey.dwColorSpaceHighValue = 255;
1726 //@@    SetRect(&srect, 0,0,    csrc->canvas.cv_w, csrc->canvas.cv_h);
1727 //@@    SetRect(&drect, 0,0,    csrc->canvas.cv_w, csrc->canvas.cv_h);
1728 //@@
1729 //@@    res = IDirectDrawSurface_Blt(_lpDDSMask, &drect, csrc->lpdds, &srect,
1730 //@@                                                                            DDBLT_WAIT | DDBLT_KEYDESTOVERRIDE,
1731 //@@                                                                            &bltfx);
1732 //@@    if (res != DD_OK) 
1733 //@@            Error("win_ibitblt: ddraw blt to mask err: %x.\n", res);
1734 //@@
1735 //@@//  Do Mask Blt to Screen (src blt !0)
1736 //@@    bltfx.dwSize = sizeof(bltfx);
1737 //@@    bltfx.ddckSrcColorkey.dwColorSpaceLowValue = 0;
1738 //@@    bltfx.ddckSrcColorkey.dwColorSpaceHighValue = 0;
1739 //@@
1740 //@@    res = IDirectDrawSurface_Blt(cdest->lpdds, &drect, _lpDDSMask, &srect,
1741 //@@                                                                            DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE,
1742 //@@                                                                            NULL);
1743 //@@    if (res != DD_OK) 
1744 //@@            Error("win_ibitblt: ddraw blt to screen err: %x.\n", res);
1745 //@@}
1746 #endif
1747