home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Zone / VRZONE.ISO / mac / PC / REND386 / JIREND / RENDER.C < prev    next >
C/C++ Source or Header  |  1993-04-11  |  18KB  |  676 lines

  1. /* Written by Bernie Roehl, January 1992 */
  2. /* Redone by Dave Stampe for integer, fast polys, colors etc */
  3. /* Modified by Bernie Roehl to support surface types */
  4.   
  5. /* Copyright 1992 by Dave Stampe and Bernie Roehl.
  6.    May be freely used to write software for release into the public domain;
  7.    all commercial endeavours MUST contact Bernie Roehl and Dave Stamrpe
  8.    for permission to incorporate any part of this software into their
  9.    products!
  10.  */
  11.   
  12. /* Contact: broehl@sunee.waterloo.edu or dstampe@sunee.waterloo.edu */
  13.   
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <dos.h>
  17. #include <conio.h>
  18.  
  19. #include "rend386.h"
  20. #include "userint.h"
  21. #include "f3dkitd.h"
  22. #include "intmath.h"
  23. #include "splits.h"
  24.   
  25. extern int ticks_per_second;
  26.   
  27. #define MAIN_VGA  1  /* for multi-VGA only */
  28. #define LEFT_VGA  2
  29. #define RIGHT_VGA 4
  30. #define ALL_VGA   7
  31.   
  32. #define MONOSCOPIC 0 /* stereo types */
  33. #define SWITCHED   1
  34. #define SPLITLR    3
  35. #define SEPARATE   5
  36.   
  37. struct Screeninfo *screeninfo;
  38.   
  39. extern void status_on_screen(void);
  40.  
  41. extern int screen_clear_color;
  42. extern int sky_color;
  43. extern int ground_color;
  44. extern int wireframe_color;
  45. extern int highlight_color;
  46. extern int highest_color;
  47.   
  48. extern int use_wide;
  49. extern int use_ht;
  50. extern int use_BW;
  51. extern int vdmode;
  52.   
  53. long display_tilt =8*65536L; /* correction for display toe-in */
  54.   
  55. int enter_graphics(void) /* enter and setup graphics screen */
  56. {
  57.    int i;
  58.   
  59.    set_gmode(vdmode);
  60.    set_vpage(0);
  61.    set_drawpage(0);
  62.    clr_page(0,0);
  63.    set_colors(use_BW);
  64.    return 0;
  65. }
  66.   
  67.   
  68. void exit_graphics(void) /* exit and restore text screen */
  69. {
  70.    exit_gmode();
  71. }
  72.   
  73. void clear_display(int pge)
  74. {
  75.    clr_page(pge,screen_clear_color);
  76. }
  77.   
  78. void ptpoly(int count, int *pcoords, int color)
  79. {
  80.    int surface_type = (color>>12)&3;
  81.   
  82.    color &= 0xFFF;
  83.   
  84.    switch (surface_type) {
  85.       case 0:
  86.       case 1:
  87.          fastpoly(count, pcoords, color);
  88.          break;
  89.       case 2:
  90.          m_fastpoly(count, pcoords, color, 0xFF, 0x00);
  91.          break;
  92.       case 3:
  93.          m_fastpoly(count, pcoords, color, 0xAA, 0xFF);
  94.          break;
  95.    }
  96. }
  97.   
  98.   
  99. extern int above_horizon(long x, long y, VIEW *v);
  100. extern long y_horizon(long x, VIEW *v);
  101. extern long x_horizon(long y, VIEW *v);
  102. extern int clr_block(int left, int top, int right, int bottom, int page, int color);
  103.   
  104. static void five(int x1, int y1, int x2, int y2, int x3, int y3,
  105.     int x4, int y4, int x5, int y5, int color)
  106. {
  107.    int p[10];
  108.    p[0] = x1;
  109.    p[1] = y1;
  110.    p[2] = x2;
  111.    p[3] = y2;
  112.    p[4] = x3;
  113.    p[5] = y3;
  114.    p[6] = x4;
  115.    p[7] = y4;
  116.    p[8] = x5;
  117.    p[9] = y5;
  118.   
  119.    ptpoly(5,&p[0], color);
  120. }
  121.   
  122. static void four(int x1, int y1, int x2, int y2, int x3, int y3,
  123.     int x4, int y4, int color)
  124. {
  125.    int p[8];
  126.    p[0] = x1;
  127.    p[1] = y1;
  128.    p[2] = x2;
  129.    p[3] = y2;
  130.    p[4] = x3;
  131.    p[5] = y3;
  132.    p[6] = x4;
  133.    p[7] = y4;
  134.   
  135.    ptpoly(4,&p[0], color);
  136. }
  137.   
  138. static void three(int x1, int y1, int x2, int y2, int x3, int y3, int color)
  139. {
  140.    int p[6];
  141.    p[0] = x1;
  142.    p[1] = y1;
  143.    p[2] = x2;
  144.    p[3] = y2;
  145.    p[4] = x3;
  146.    p[5] = y3;
  147.   
  148.    ptpoly(3,&p[0], color);
  149. }
  150.   
  151.   
  152. static void horizon(VIEW *v, int page)
  153. {
  154.    int l = v->left;
  155.    int r = v->right;
  156.    int t = v->top;
  157.    int b = v->bottom-1;
  158.    int mf1;
  159.    int pl,pr,pt,pb;
  160.   
  161.    mf1 = (above_horizon(l,t,v) ) +
  162.    (above_horizon(r,t,v)<<1) +
  163.    (above_horizon(l,b,v)<<2) +
  164.    (above_horizon(r,b,v)<<3) ;
  165.   
  166.    set_drawpage(page);
  167.    setup_hdwe(0);
  168.   
  169.    switch(mf1)
  170.    {
  171.       case 0:
  172.          clr_block(l, t, r, b, page, ground_color);
  173.          break;
  174.       case 15:
  175.          clr_block(l, t, r, b, page, sky_color);
  176.          break;
  177.       case 3:
  178.          pl = y_horizon(l,v);
  179.          pr = y_horizon(r,v);
  180.          if (pl == pr)
  181.          {
  182.             clr_block(l,t,r,pl-1,page,sky_color);
  183.             clr_block(l,pl,r,b,page,ground_color);
  184.             break;
  185.          }
  186.          four(r,t,l,t,l,pl,r,pr,sky_color);
  187.          four(l,b,r,b,r,pr,l,pl,ground_color);
  188.          break;
  189.       case 12:
  190.          pl = y_horizon(l,v);
  191.          pr = y_horizon(r,v);
  192.          if (pl == pr)
  193.          {
  194.             clr_block(l,t,r,pl-1,page,ground_color);
  195.             clr_block(l,pl,r,b,page,sky_color);
  196.             break;
  197.          }
  198.          four(r,t,l,t,l,pl,r,pr,ground_color);
  199.          four(l,b,r,b,r,pr,l,pl,sky_color);
  200.          break;
  201.       case 5:
  202.          pt = x_horizon(t,v);
  203.          pb = x_horizon(b,v);
  204.          four(l,t,l,b,pb,b,pt,t,sky_color);
  205.          four(r,b,r,t,pt,t,pb,b,ground_color);
  206.          break;
  207.       case 10:
  208.          pt = x_horizon(t,v);
  209.          pb = x_horizon(b,v);
  210.          four(l,t,l,b,pb,b,pt,t,ground_color);
  211.          four(r,b,r,t,pt,t,pb,b,sky_color);
  212.          break;
  213.       case 1:
  214.          pt = x_horizon(t,v);
  215.          pl = y_horizon(l,v);
  216.          three(l,t,l,pl,pt,t,sky_color);
  217.          five(l,b,r,b,r,t,pt,t,l,pl,ground_color);
  218.          break;
  219.       case 14:
  220.          pt = x_horizon(t,v);
  221.          pl = y_horizon(l,v);
  222.          three(l,t,l,pl,pt,t,ground_color);
  223.          five(l,b,r,b,r,t,pt,t,l,pl,sky_color);
  224.          break;
  225.       case 2:
  226.          pt = x_horizon(t,v);
  227.          pr = y_horizon(r,v);
  228.          three(r,t,pt,t,r,pr,sky_color);
  229.          five(l,t,l,b,r,b,r,pr,pt,t,ground_color);
  230.          break;
  231.       case 13:
  232.          pt = x_horizon(t,v);
  233.          pr = y_horizon(r,v);
  234.          three(r,t,pt,t,r,pr,ground_color);
  235.          five(l,t,l,b,r,b,r,pr,pt,t,sky_color);
  236.          break;
  237.       case 4:
  238.          pb = x_horizon(b,v);
  239.          pl = y_horizon(l,v);
  240.          three(l,pl,l,b,pb,b,sky_color);
  241.          five(r,b,r,t,l,t,l,pl,pb,b,ground_color);
  242.          break;
  243.       case 11:
  244.          pb = x_horizon(b,v);
  245.          pl = y_horizon(l,v);
  246.          three(l,pl,l,b,pb,b,ground_color);
  247.          five(r,b,r,t,l,t,l,pl,pb,b,sky_color);
  248.          break;
  249.       case 8:
  250.          pb = x_horizon(b,v);
  251.          pr = y_horizon(r,v);
  252.          three(pb,b,r,b,r,pr,sky_color);
  253.          five(r,t,l,t,l,b,pb,b,r,pr,ground_color);
  254.          break;
  255.       case 7:
  256.          pb = x_horizon(b,v);
  257.          pr = y_horizon(r,v);
  258.          three(pb,b,r,b,r,pr,ground_color);
  259.          five(r,t,l,t,l,b,pb,b,r,pr,sky_color);
  260.          break;
  261.    }
  262.    reset_hdwe();
  263. }
  264.   
  265.   
  266. extern volatile int has_switched; /* 3 when Sega has shown both eyes */
  267. extern int v_page;
  268. extern int fancy_background, reflection_pool, have_logo, show_logo;
  269. extern int do_screen_clear, do_horizon;
  270. extern int reframe, use_frame;
  271. extern int stereo_type;
  272. extern int swap_eyes;
  273. extern int left_page, right_page;
  274. extern STEREO default_stereo;
  275. extern SPLIT *split_tree;
  276. extern int show_location, show_compass, show_framerate;
  277.   
  278. extern int screen_clear_color;
  279.   
  280. long last_render_time = 8; /* time in 1/180 sec to redraw */
  281.   
  282. static int ccyc[30] = {
  283.    0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
  284. 14,13,12,11,10,9,8,7,6,5,4,3,2,1 };
  285.   
  286. void background(int page, int top, int bot, int color)
  287. {
  288.    int inc = (top + (color & 15)) % 30;
  289.    color &= 0xF0;
  290.   
  291.    for (; top <= bot; top += 2)
  292.    {
  293.       clr_block(0, top, 319, top+1, page, color+ccyc[inc]);
  294.       if ((++inc) == 30) inc = 0;
  295.    }
  296. }
  297.   
  298. void reflection(int page, int top, int bot, int step)
  299. {
  300.    int src = top-step;
  301.   
  302.    for( ; top <= bot; top++)
  303.    {
  304.       copy_block(page, 0, src, page, 0, top, 320, 1);
  305.       src -= step;
  306.    }
  307. }
  308.   
  309. static void coord_ref(int xc, int yc, int size, VIEW *v, int xcolor, int ycolor, int zcolor, int bcolor)
  310. {
  311.    long x, y, z;
  312.    MATRIX m;
  313.   
  314.    if (show_compass == 0) return;
  315.   
  316.    view_to_matrix(v,m);
  317.    m[3][0] = m[3][1] = m[3][2] = 0;
  318.    matrix_transpose(m,m);
  319.   
  320.    setup_hdwe(0);
  321.    x = size;
  322.    y = 0;
  323.    z = 0;
  324.    matrix_point(m, &x, &y, &z);
  325.    if (v->orientation & XFLIP)
  326.    {
  327.       vgaline(xc,yc,xc-x,yc-y,bcolor);
  328.       printxyr(xc-x-5,yc-y,bcolor,"x",1);
  329.       setup_hdwe(0);
  330.       vgaline(xc-1,yc+1,xc-1-x,yc+1-y,xcolor);
  331.       printxyr(xc-x-5-1,yc-y+1,xcolor,"x",1);
  332.    }
  333.    else
  334.    {
  335.       vgaline(xc,yc,x+xc,yc-y,bcolor);
  336.       printxyr(x+xc+5,yc-y,bcolor,"x",0);
  337.       setup_hdwe(0);
  338.       vgaline(xc+1,yc+1,x+xc+1,yc-y+1,xcolor);
  339.       printxyr(x+xc+5+1,yc-y+1,xcolor,"x",0);
  340.    }
  341.   
  342.    setup_hdwe(0);
  343.    y = size;
  344.    x = 0;
  345.    z = 0;
  346.    matrix_point(m, &x, &y, &z);
  347.    if (v->orientation & XFLIP)
  348.    {
  349.       vgaline(xc,yc,xc-x,yc-y,bcolor);
  350.       printxyr(xc-x-5,yc-y,bcolor,"y",1);
  351.       setup_hdwe(0);
  352.       vgaline(xc-1,yc+1,xc-1-x,yc+1-y,ycolor);
  353.       printxyr(xc-x-5-1,yc-y+1,ycolor,"y",1);
  354.    }
  355.    else
  356.    {
  357.       vgaline(xc,yc,x+xc,yc-y,bcolor);
  358.       printxyr(x+xc+5,yc-y,bcolor,"y",0);
  359.       setup_hdwe(0);
  360.       vgaline(xc+1,yc+1,x+xc+1,yc-y+1,ycolor);
  361.       printxyr(x+xc+5+1,yc-y+1,ycolor,"y",0);
  362.    }
  363.   
  364.    setup_hdwe(0);
  365.    z = size;
  366.    y = 0;
  367.    x = 0;
  368.    matrix_point(m, &x, &y, &z);
  369.    if (v->orientation & XFLIP)
  370.    {
  371.       vgaline(xc,yc,xc-x,yc-y,bcolor);
  372.       printxyr(xc-x-5,yc-y,bcolor,"z",1);
  373.       setup_hdwe(0);
  374.       vgaline(xc-1,yc+1,xc-1-x,yc+1-y,zcolor);
  375.       printxyr(xc-x-5-1,yc-y+1,zcolor,"z",1);
  376.    }
  377.    else
  378.    {
  379.       vgaline(xc,yc,x+xc,yc-y,bcolor);
  380.       printxyr(x+xc+5,yc-y,bcolor,"z",0);
  381.       setup_hdwe(0);
  382.       vgaline(xc+1,yc+1,x+xc+1,yc-y+1,zcolor);
  383.       printxyr(x+xc+5+1,yc-y+1,zcolor,"z",0);
  384.    }
  385.    reset_hdwe();
  386. }
  387.   
  388.   
  389. static VIEW left_view, right_view;
  390.   
  391. extern int frame_x, frame_y, frame_w, frame_h;
  392.   
  393. void reset_screens(void)
  394. {
  395.    int i;
  396.    cursor_hide();
  397.    for (i = 0; i < 4; ++i) {
  398.       if (use_frame)
  399.          copy_block(3, 0, 0, i, frame_x, frame_y, frame_w, frame_h);
  400.       else
  401.          clear_display(i);
  402.    }
  403.    cursor_show(v_page);
  404. }
  405.   
  406. void screen_refresh(VIEW *current_view) /* now does stereo drawing */
  407. {
  408.    long old_time = current_time();
  409.    int mxpge = 2;
  410.    if (screeninfo->pages < 3) mxpge = 1;
  411.   
  412.    if (stereo_type == MONOSCOPIC)
  413.    {
  414.       if (reframe && use_frame) {
  415.          copy_block((v_page == 3) ? 0 : (v_page + 1), 0, 0,
  416.          v_page, 0, 0, 320, 200);
  417.          reframe = 0;
  418.       }
  419.       if (++v_page > mxpge) v_page = 0; /* use 3 pages to avoid flicker */
  420.       set_drawpage(v_page);
  421.       if (fancy_background)
  422.       {
  423.          if (have_logo && show_logo)
  424.             background(v_page, 30, reflection_pool ? 160 : 199, 0xBF);
  425.          else background(v_page, 0, reflection_pool ? 160 : 199, 0xB0);
  426.       }
  427.       else if (use_frame && do_screen_clear && !do_horizon)
  428.          clr_block(current_view->left,current_view->top,
  429.          current_view->right,current_view->bottom,
  430.          v_page,screen_clear_color);
  431.       else if (do_horizon) {
  432.          horizon(current_view,v_page);
  433.       }
  434.       else if (do_screen_clear)
  435.          clear_display(v_page);
  436.       if (have_logo && show_logo)
  437.          copy_block(3, 0, 0, v_page, 0, 0, 320, 30);
  438.       render_set_view(current_view);
  439.       render_split(split_tree, current_view);
  440.       if (reflection_pool) reflection(v_page, 160, 199, 3);
  441.       status_on_screen();
  442.       coord_ref(250,65,35,current_view,15,13,10,0);
  443.       set_vpage(v_page);
  444.       cursor_hide();
  445.    }
  446.    else if (stereo_type==SPLITLR)
  447.    {
  448.       if (++v_page > mxpge) v_page = 0; /* use 3 pages to avoid flicker */
  449.       make_stereo_view(current_view,&left_view,LEFT_EYE);
  450.   
  451.       set_drawpage(v_page);
  452.       render_set_view(&left_view);
  453.       if (do_horizon) horizon(&left_view,v_page);
  454.       else clear_display(v_page);
  455.   
  456.       render_split(split_tree, &left_view);
  457.       make_stereo_view(current_view,&right_view,RIGHT_EYE);
  458.       render_set_view(&right_view);
  459.       if (do_horizon) horizon(&right_view,v_page);
  460.       render_split(split_tree, &right_view);
  461.       set_vpage(v_page);
  462.       cursor_hide();
  463.       if (mxpge < 2) vsync();
  464.    }
  465.    else
  466.    {
  467.       v_page = v_page ^ 2;
  468.   
  469.       if (stereo_type == SWITCHED)
  470.       {
  471.          make_stereo_view(current_view,&left_view,0);
  472.          while ((has_switched&1) == 0) if (kbhit()) break;
  473.          if (do_horizon) horizon(&left_view,v_page);
  474.          else if (do_screen_clear)
  475.             clear_display(v_page);
  476.          set_drawpage(v_page);
  477.          render_set_view(&left_view);
  478.          render_split(split_tree, &left_view);
  479.          setup_hdwe(0);
  480.          printxyr(20,10,0,"L",0);
  481.          status_on_screen();
  482.          reset_hdwe();
  483.          coord_ref(250,65,35,current_view,15,13,10,0);
  484.          make_stereo_view(current_view,&right_view,1);
  485.          while ((has_switched&2) == 0) if (kbhit()) break;
  486.          if (do_horizon) horizon(&right_view,v_page+1);
  487.          else if (do_screen_clear)
  488.             clear_display(v_page+1); /* right page */
  489.          set_drawpage(v_page+1);
  490.          render_set_view(&right_view);
  491.          render_split(split_tree, &right_view);
  492.          setup_hdwe(0);
  493.          printxyr(300,10,0,"R",0);
  494.          status_on_screen();
  495.          reset_hdwe();
  496.          coord_ref(250,65,35,current_view,15,13,10,0);
  497.          disable();
  498.          if (swap_eyes)
  499.          {
  500.             left_page = v_page+1; /* display them now */
  501.             right_page = v_page;
  502.          }
  503.          else
  504.          {
  505.             left_page = v_page;
  506.             right_page = v_page+1;
  507.          }
  508.          has_switched = 0;
  509.          enable();
  510.          cursor_hide();
  511.       }
  512.       else if (stereo_type == SEPARATE) /* wide- angle display with seperate VGA cards */
  513.       {
  514.          set_drawpage(v_page);
  515.          VGA_select(swap_eyes ? RIGHT_VGA : LEFT_VGA|MAIN_VGA);
  516.          make_stereo_view(current_view, &left_view,0);
  517.          if (do_horizon) horizon(&left_view,v_page);
  518.          else if (do_screen_clear)
  519.             clear_display(v_page);
  520.          render_set_view(&left_view);
  521.          render_split(split_tree, &left_view);
  522.          setup_hdwe(0);
  523.          printxyr(20,10,0,"L",0);
  524.          reset_hdwe();
  525.   
  526.          VGA_select(swap_eyes ? LEFT_VGA|MAIN_VGA : RIGHT_VGA);
  527.          make_stereo_view(current_view, &right_view, 1);
  528.          if (do_horizon) horizon(&right_view,v_page);
  529.          else if (do_screen_clear)
  530.             clear_display(v_page);
  531.          render_set_view(&right_view);
  532.          render_split(split_tree, &right_view);
  533.          setup_hdwe(0);
  534.          printxyr(20,10,0,"R",1);
  535.          coord_ref(60,175,25,&right_view,15,14,13,0);
  536.          reset_hdwe();
  537.   
  538.          VGA_select(LEFT_VGA|MAIN_VGA);
  539.          set_vpage(v_page);
  540.          VGA_select(LEFT_VGA);
  541.          VGA_select(RIGHT_VGA);
  542.          set_vpage(v_page);
  543.          VGA_select(MAIN_VGA);
  544.          cursor_hide();
  545.       }
  546.    }
  547.   
  548.    last_render_time = current_time() - old_time;
  549.    if (last_render_time == 0) last_render_time++;
  550.    if (show_framerate)
  551.    {
  552.       char c[69];
  553.       sprintf(c,"Frames/sec: %d",get_ticks_per_second()/last_render_time);
  554.       printxyr(5,170,15,c,0);
  555.    }
  556.    set_drawpage(v_page);
  557.    cursor_show(v_page);
  558.   
  559. }
  560.   
  561.   
  562.   
  563. /********************************************************/
  564. /* USER ROUTINES CALLED BY THE RENDERING LIBRARY        */
  565. /* KEEP THIS AS FAST AS POSSIBLE: SOME MAY BE           */
  566. /* CALLED UP TO 1000 TIMES PER SCREEN!                  */
  567. /********************************************************/
  568.   
  569. extern int wireframe;
  570.   
  571. /* USER ROUTINE TO SETUP FOR POLY DRAWING - CALLED ONCE PER FRAME */
  572. void user_setup_blitter(void)
  573. {
  574.    setup_hdwe(0);
  575. }
  576.   
  577. /* USER ROUTINE TO RECOVER AFTER POLY DRAWING: ONCE PER FRAME */
  578. void user_reset_blitter(void)
  579. {
  580.    reset_hdwe();
  581. }
  582.   
  583.   
  584. /* USER ROUTINE TO DRAW TEXT BOXES */
  585. void user_box(int x1, int y1, int x2, int y2, int color)
  586. {
  587.    int av[8];
  588.   
  589.    setup_hdwe(0);
  590.   
  591.    if (x1 < screeninfo->xmin) x1 = screeninfo->xmin;
  592.    if (x2 < screeninfo->xmin) x2 = screeninfo->xmin;
  593.    if (y1 < screeninfo->ymin) y1 = screeninfo->ymin;
  594.    if (y2 < screeninfo->ymin) y2 = screeninfo->ymin;
  595.    if (x1 > screeninfo->xmax) x1 = screeninfo->xmax;
  596.    if (x2 > screeninfo->xmax) x2 = screeninfo->xmax;
  597.    if (y1 > screeninfo->ymax) y1 = screeninfo->ymax;
  598.    if (y2 > screeninfo->ymax) y2 = screeninfo->ymax;
  599.   
  600.    av[0] = x1;
  601.    av[1] = y1;
  602.    av[2] = x1;
  603.    av[3] = y2;
  604.    av[4] = x2;
  605.    av[5] = y2;
  606.    av[6] = x2;
  607.    av[7] = y1;
  608.   
  609.    fastpoly(4, &av[0], color);
  610.    reset_hdwe();
  611. }
  612.   
  613. /* USER ROUTINE TO DRAW TEXT */
  614. void user_text(int x, int y, int color, char *string)
  615. {
  616.    printxyr(x, y, color, string,0);
  617. }
  618.   
  619.   
  620. static int x1, y1;
  621. static void vlineto(int x, int y, int color)
  622. {
  623.    vgaline(x,y,x1,y1,color);
  624.    x1 = x;
  625.    y1 = y;
  626. }
  627.   
  628. /* CALLED FROM RENDREP TO DRAW POLYS */
  629.   
  630. void user_render_poly(int number, int *pcoords, unsigned color, long maxz)
  631. {
  632.    int i;
  633.   
  634.    if (number == 1)
  635.    {
  636.       setup_hdwe(0);
  637.       vgapoint(pcoords[0], pcoords[1], color);
  638.       reset_hdwe();
  639.       return;
  640.    }
  641.    if (number == 2)
  642.    {
  643.       vgaline(pcoords[0],pcoords[1],pcoords[2],pcoords[3],color);
  644.       return;
  645.    }
  646.    if (!wireframe)
  647.    {
  648.       ptpoly(number, pcoords, color);
  649.   
  650.       if (color & 0x8000) /* highlighted? */
  651.       {
  652.          x1 = pcoords[0];
  653.          y1 = pcoords[1];
  654.          for (i = 1; i < number; ++i) vlineto(pcoords[i+i], pcoords[i+i+1], highlight_color);
  655.          vlineto(pcoords[0], pcoords[1], highlight_color);
  656.       }
  657.    }
  658.    else
  659.    {
  660.       x1 = pcoords[0];
  661.       y1 = pcoords[1];
  662.       for (i = 1; i < number; ++i) vlineto(pcoords[i+i], pcoords[i+i+1], wireframe_color);
  663.       vlineto(pcoords[0], pcoords[1], wireframe_color);
  664.    }
  665. }
  666.   
  667. void vgabox(int left, int top, int right, int bottom, int color)
  668. {
  669.    setup_hdwe(0);
  670.    vgaline(left, top, right, top, color);
  671.    vgaline(right, top, right, bottom, color);
  672.    vgaline(right, bottom, left, bottom, color);
  673.    vgaline(left, bottom, left, top, color);
  674.    reset_hdwe();
  675. }
  676.