home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / REND.LZH / REND / CRT98.C < prev    next >
C/C++ Source or Header  |  1996-04-22  |  19KB  |  841 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4.  
  5. #include "reader.h"
  6. #include "glib.h"
  7. #include "rend.h"
  8.  
  9. static void graph_cls(void);
  10.  
  11. #ifdef __GNUC__
  12.     #define GRAPH_ADDRESS_B        (0xe00a8000)
  13.     #define GRAPH_ADDRESS_R        (0xe00b0000)
  14.     #define GRAPH_ADDRESS_G        (0xe00b8000)
  15.     #define GRAPH_ADDRESS_I        (0xe00e0000)
  16. #else
  17.     #define GRAPH_ADDRESS_B        (0xa8000000)
  18.     #define GRAPH_ADDRESS_R        (0xb0000000)
  19.     #define GRAPH_ADDRESS_G        (0xb8000000)
  20.     #define GRAPH_ADDRESS_I        (0xe0000000)
  21. #endif
  22.  
  23. #ifdef __GNUC__
  24.     #include <pc.h>
  25. #else
  26.     #include <conio.h>
  27.     #define outportb(port,value)    outp(port,value)
  28. #endif
  29.  
  30. static short paletdata[16];
  31.  
  32. #ifdef __GNUC__
  33. #define far
  34. static unsigned int longleftedge[32] = {
  35.     0xffffffff, 0xffffff7f, 0xffffff3f, 0xffffff1f,
  36.     0xffffff0f, 0xffffff07, 0xffffff03, 0xffffff01,
  37.     0xffffff00, 0xffff7f00, 0xffff3f00, 0xffff1f00,
  38.     0xffff0f00, 0xffff0700, 0xffff0300, 0xffff0100,
  39.     0xffff0000, 0xff7f0000, 0xff3f0000, 0xff1f0000,
  40.     0xff0f0000, 0xff070000, 0xff030000, 0xff010000,
  41.     0xff000000, 0x7f000000, 0x3f000000, 0x1f000000,
  42.     0x0f000000, 0x07000000, 0x03000000, 0x01000000,
  43. };
  44. static unsigned int longrightedge[32] = {
  45.     0x00000080, 0x000000c0, 0x000000e0, 0x000000f0,
  46.     0x000000f8, 0x000000fc, 0x000000fe, 0x000000ff,
  47.     0x000080ff, 0x0000c0ff, 0x0000e0ff, 0x0000f0ff,
  48.     0x0000f8ff, 0x0000fcff, 0x0000feff, 0x0000ffff,
  49.     0x0080ffff, 0x00c0ffff, 0x00e0ffff, 0x00f0ffff,
  50.     0x00f8ffff, 0x00fcffff, 0x00feffff, 0x00ffffff,
  51.     0x80ffffff, 0xc0ffffff, 0xe0ffffff, 0xf0ffffff,
  52.     0xf8ffffff, 0xfcffffff, 0xfeffffff, 0xffffffff,
  53. };
  54. #endif
  55. static unsigned char charleftedge[8] = {
  56.     0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01
  57. };
  58. static unsigned char charrightedge[8] = {
  59.     0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
  60. };
  61.  
  62. static void graph_line_1(int x1, int y1, int x2, int y2, int color)
  63. {
  64.     int temp;
  65.     int i;
  66.     int offset;
  67.     int data;
  68.     unsigned char *gram = (unsigned char *)GRAPH_ADDRESS_B;
  69.     if (y1 > y2) {
  70.         temp = y1; y1 = y2; y2 = temp;
  71.     }
  72.     gram += offset = y1 * 80 + x1 / 8;
  73.     data = 0x80 >> (x1 % 8);
  74.     for (i = y2 - y1 + 1; i > 0; --i) {
  75.         *gram = data;
  76.         gram += 80;
  77.     }
  78. }
  79.  
  80. static void graph_line_2(int x1, int y1, int x2, int y2, int color)
  81. {
  82.     int i;
  83.     int offset;
  84.     int data;
  85.     int diff;
  86.     int plus, minus;
  87.     unsigned char *gram = (unsigned char *)GRAPH_ADDRESS_B;
  88.     plus = (y1 - y2) * 2;
  89.     minus = (x2 - x1) * 2;
  90.     diff = plus / 2;
  91.     gram += offset = y1 * 80 + x1 / 8;
  92.     data = 0x80 >> (x1 % 8);
  93.     for (i = y1 - y2 + 1; i > 0; --i) {
  94.         *gram = data;
  95.         gram -= 80;
  96.         if ((diff -= minus) < 0) {
  97.             if ((data >>= 1) == 0) {
  98.                 data = 0x80;
  99.                 gram++;
  100.             }
  101.             diff += plus;
  102.         }
  103.     }
  104. }
  105.  
  106. static void graph_line_3(int x1, int y1, int x2, int y2, int color)
  107. {
  108.     int i;
  109.     int offset;
  110.     int data;
  111.     unsigned char *gram = (unsigned char *)GRAPH_ADDRESS_B;
  112.     gram += offset = y1 * 80 + x1 / 8;
  113.     data = 0x80 >> (x1 % 8);
  114.     for (i = y1 - y2 + 1; i > 0; --i) {
  115.         *gram = data;
  116.         gram -= 80;
  117.         if ((data >>= 1) == 0) {
  118.             data = 0x80;
  119.             gram++;
  120.         }
  121.     }
  122. }
  123.  
  124. static void graph_line_4(int x1, int y1, int x2, int y2, int color)
  125. {
  126.     int i;
  127.     int offset;
  128.     int diff;
  129.     int plus, minus;
  130.     int start, end;
  131.     unsigned char *gram = (unsigned char *)GRAPH_ADDRESS_B;
  132.     plus = (x2 - x1) * 2;
  133.     minus = (y1 - y2) * 2;
  134.     diff = plus / 2;
  135.     gram += offset = y1 * 80 + x1 / 8;
  136.     start = end = x1 % 8;
  137.     for (i = x2 - x1 + 1; i > 0; --i) {
  138.         end++;
  139.         if ((diff -= minus) < 0) {
  140.             *gram = charleftedge[start] & charrightedge[(end-1)];
  141.             gram -= 80;
  142.             if (end == 8) {
  143.                 gram++;
  144.                 end = 0;
  145.             }
  146.             start = end;
  147.             diff += plus;
  148.         } else if (end == 8) {
  149.             *gram++ = charleftedge[start];
  150.             start = end = 0;
  151.         }
  152.     }
  153.     if (end != 0) {
  154.         *gram = charleftedge[start] & charrightedge[end-1];
  155.     }
  156. }
  157.  
  158. static void graph_line_5(int x1, int y1, int x2, int y2, int color)
  159. {
  160.     int i;
  161.     int offset1, offset2;
  162. #ifdef __GNUC__
  163.     unsigned int *gram = (unsigned int *)GRAPH_ADDRESS_B;
  164.     offset1 = y1 * 20 + x1 / 32;
  165.     offset2 = y1 * 20 + x2 / 32;
  166.     gram += offset1;
  167.     if (offset1 == offset2) {
  168.         *gram = longleftedge[x1%32] & longrightedge[x2%32];
  169.     } else if (offset2 == offset1 + 1) {
  170.         *gram++ = longleftedge[x1%32];
  171.         *gram = longrightedge[x2%32];
  172.     } else {
  173.         *gram++ = longleftedge[x1%32];
  174.         for (i = offset2 - offset1 - 1;i > 0; --i) {
  175.             *gram++ = 0xffffffff;
  176.         }
  177.         *gram = longrightedge[x2%32];
  178.     }
  179. #else
  180.     unsigned char far *gram = (unsigned char far *)GRAPH_ADDRESS_B;
  181.     offset1 = y1 * 80 + x1 / 8;
  182.     offset2 = y1 * 80 + x2 / 8;
  183.     gram += offset1;
  184.     if (offset1 == offset2) {
  185.         *gram = charleftedge[x1%8] & charrightedge[x2%8];
  186.     } else if (offset2 == offset1 + 1) {
  187.         *gram++ = charleftedge[x1%8];
  188.         *gram = charrightedge[x2%8];
  189.     } else {
  190.         *gram++ = charleftedge[x1%8];
  191.         for (i = offset2 - offset1 - 1;i > 0; --i) {
  192.             *gram++ = 0xff;
  193.         }
  194.         *gram = charrightedge[x2%8];
  195.     }
  196. #endif
  197. }
  198.  
  199. static void graph_line_6(int x1, int y1, int x2, int y2, int color)
  200. {
  201.     int i;
  202.     int offset;
  203.     int diff;
  204.     int plus, minus;
  205.     int start, end;
  206.     unsigned char *gram = (unsigned char *)GRAPH_ADDRESS_B;
  207.     plus = (x2 - x1) * 2;
  208.     minus = (y2 - y1) * 2;
  209.     diff = plus / 2;
  210.     gram += offset = y1 * 80 + x1 / 8;
  211.     start = end = x1 % 8;
  212.     for (i = x2 - x1 + 1; i > 0; --i) {
  213.         end++;
  214.         if ((diff -= minus) < 0) {
  215.             *gram = charleftedge[start] & charrightedge[(end-1)];
  216.             gram += 80;
  217.             start = end;
  218.             diff += plus;
  219.             if (end == 8) {
  220.                 gram++;
  221.                 start = end = 0;
  222.             }
  223.         } else if (end == 8) {
  224.             *gram++ = charleftedge[start];
  225.             start = end = 0;
  226.         }
  227.     }
  228.     if (end != 0) {
  229.         *gram = charleftedge[start] & charrightedge[end-1];
  230.     }
  231. }
  232.  
  233. static void graph_line_7(int x1, int y1, int x2, int y2, int color)
  234. {
  235.     int i;
  236.     int offset;
  237.     int data;
  238.     unsigned char *gram = (unsigned char *)GRAPH_ADDRESS_B;
  239.     gram += offset = y1 * 80 + x1 / 8;
  240.     data = 0x80 >> (x1 % 8);
  241.     for (i = y2 - y1 + 1; i > 0; --i) {
  242.         *gram = data;
  243.         gram += 80;
  244.         if ((data >>= 1) == 0) {
  245.             data = 0x80;
  246.             gram++;
  247.         }
  248.     }
  249. }
  250.  
  251. static void graph_line_8(int x1, int y1, int x2, int y2, int color)
  252. {
  253.     int i;
  254.     int offset;
  255.     int data;
  256.     int diff;
  257.     int plus, minus;
  258.     unsigned char *gram = (unsigned char *)GRAPH_ADDRESS_B;
  259.     plus = (y2 - y1) * 2;
  260.     minus = (x2 - x1) * 2;
  261.     diff = plus / 2;
  262.     gram += offset = y1 * 80 + x1 / 8;
  263.     data = 0x80 >> (x1 % 8);
  264.     for (i = y2 - y1 + 1; i > 0; --i) {
  265.         *gram = data;
  266.         gram += 80;
  267.         if ((diff -= minus) < 0) {
  268.             if ((data >>= 1) == 0) {
  269.                 data = 0x80;
  270.                 gram++;
  271.             }
  272.             diff += plus;
  273.         }
  274.     }
  275. }
  276.  
  277. void graph_line(int x1, int y1, int x2, int y2, int color)
  278. {
  279.     int temp;
  280.     if (y1 > y2) {
  281.         temp = x1; x1 = x2; x2 = temp;
  282.         temp = y1; y1 = y2; y2 = temp;
  283.     }
  284.     if (y2 < 0 || y1 > 399) {
  285.         return;
  286.     }
  287.     if (y1 < 0) {
  288.         x1 = (x1 * y2 - x2 * y1) / (y2 - y1);
  289.         y1 = 0;
  290.     }
  291.     if (y2 > 399) {
  292.         x2 = (x2 - x1) * (399 - y1) / (y2 - y1) + x1;
  293.         y2 = 399;
  294.     }
  295.     if (x1 > x2) {
  296.         temp = x1; x1 = x2; x2 = temp;
  297.         temp = y1; y1 = y2; y2 = temp;
  298.     }
  299.     if (x2 < 0 || x1 > 639) {
  300.         return;
  301.     }
  302.     if (x1 < 0) {
  303.         y1 = (y1 * x2 - y2 * x1) / (x2 - x1);
  304.         x1 = 0;
  305.     }
  306.     if (x2 > 639) {
  307.         y2 = (y2 - y1) * (639 - x1) / (x2 - x1) + y1;
  308.         x2 = 639;
  309.     }
  310. /*
  311.                 1 2 3
  312.                 |  / 
  313.                 | / 4
  314.                 |/  
  315.                 .---5
  316.                  \
  317.                   \ 6
  318.                    \
  319.                 9 8 7
  320. */
  321.     outportb(0x7c, 0xc8);
  322. #ifdef __GNUC__
  323.     outportb(0x7e, (color & 1) ? 0xff : 0);
  324.     outportb(0x7e, (color & 2) ? 0xff : 0);
  325.     outportb(0x7e, (color & 4) ? 0xff : 0);
  326. #else
  327.     outportb(0x7e, (color & 1) ? 0 : 0xff);
  328.     outportb(0x7e, (color & 2) ? 0 : 0xff);
  329.     outportb(0x7e, (color & 4) ? 0 : 0xff);
  330. #endif
  331.     if (x1 == x2) {
  332.         graph_line_1(x1, y1, x2, y2, color);
  333.     } else if (y1 == y2) {
  334.         graph_line_5(x1, y1, x2, y2, color);
  335.     } else if (y2 < y1) {
  336.         if (y1 - y2 > x2 - x1) {
  337.             graph_line_2(x1, y1, x2, y2, color);
  338.         } else if (y1 - y2 == x2 - x1) {
  339.             graph_line_3(x1, y1, x2, y2, color);
  340.         } else {
  341.             graph_line_4(x1, y1, x2, y2, color);
  342.         }
  343.     } else {
  344.         if (y2 - y1 < x2 - x1) {
  345.             graph_line_6(x1, y1, x2, y2, color);
  346.         } else if (y2 - y1 == x2 - x1) {
  347.             graph_line_7(x1, y1, x2, y2, color);
  348.         } else {
  349.             graph_line_8(x1, y1, x2, y2, color);
  350.         }
  351.     }
  352.     outportb(0x7c, 0 );
  353. }
  354.  
  355. void graph_palet(int paletmode, int color)
  356. {
  357.     paletdata[paletmode & 7] = color;
  358.     switch(paletmode & 7) {
  359.     case 0:
  360.     case 4:
  361.         outportb(0xae, paletdata[0] * 16 + paletdata[4]);
  362.         break;
  363.     case 1:
  364.     case 5:
  365.         outportb(0xaa, paletdata[1] * 16 + paletdata[5]);
  366.         break;
  367.     case 2:
  368.     case 6:
  369.         outportb(0xac, paletdata[2] * 16 + paletdata[6]);
  370.         break;
  371.     case 3:
  372.     case 7:
  373.         outportb(0xa8, paletdata[3] * 16 + paletdata[7]);
  374.         break;
  375.     }
  376. }
  377.  
  378.  
  379. void graph_init(void)
  380. {
  381.     union    REGS in;
  382.     union    REGS out;
  383.     int i;
  384.     in.h.ah = 0x42;
  385.     in.h.ch = 0xc0;
  386.     int86( 0x18, &in, &out );    /*graphic bios set gvram domain*/
  387. #if 0
  388.     outportb( 0x68, 2 );        /*graphic mode = color*/
  389.     outportb( 0x68, 8 );        /*brp mode = 400line*/
  390.     outportb( 0x6a, 1 );        /*color = 8*/
  391. #endif
  392.     in.h.ah = 0x40;
  393.     int86( 0x18, &in, &out );
  394.     outportb( 0x6a, 0);
  395.     for (i = 0; i < 8; ++i) {
  396.         graph_palet(i, i);
  397.     }
  398.     outportb(0xa6, 0);/*apage=0*/
  399.     outportb(0xa4, 0);/*vpage=0*/
  400.     graph_cls();
  401. }
  402.  
  403. void graph_cls(void)
  404. {
  405.     int i;
  406.     unsigned long far *p;
  407.     outportb(0x7c, 0xc8);
  408.     outportb(0x7e, 0);
  409.     outportb(0x7e, 0);
  410.     outportb(0x7e, 0);
  411.     for (i = 8000, p = (unsigned long far *)GRAPH_ADDRESS_B; i > 0; --i) {
  412.         *p++ = 0xffffffffUL;
  413.     }
  414. #if 0
  415.     memset(GRAPH_ADDRESS_B, 0, 0x8000);
  416. #endif
  417.     outportb(0x7c, 0);
  418. }
  419.  
  420. static    int        vline ;
  421.  
  422. #define LINE1        80
  423. #define LINE2        160
  424.  
  425. #define T0     6
  426. #define T1    12
  427. #define T2    18
  428. #define T3    24
  429.  
  430. #define setvalall0(c0,c1,c2,c3,c4,c5,c6,c7)            \
  431.           (unsigned char)( ((c0)     > T1 ? 0x80 : 0) \
  432.                 | ((c1)     > T2 ? 0x40 : 0) \
  433.                 | ((c2)     > T1 ? 0x20 : 0) \
  434.                 | ((c3)     > T2 ? 0x10 : 0) \
  435.                 | ((c4)     > T1 ? 0x08 : 0) \
  436.                 | ((c5)     > T2 ? 0x04 : 0) \
  437.                 | ((c6)     > T1 ? 0x02 : 0) \
  438.                 | ((c7)     > T2 ? 0x01 : 0) )
  439.  
  440. #define setvalall1(c0,c1,c2,c3,c4,c5,c6,c7)            \
  441.           (unsigned char)( ((c0)     > T3 ? 0x80 : 0) \
  442.                 | ((c1)     > T0 ? 0x40 : 0) \
  443.                 | ((c2)     > T3 ? 0x20 : 0) \
  444.                 | ((c3)     > T0 ? 0x10 : 0) \
  445.                 | ((c4)     > T3 ? 0x08 : 0) \
  446.                 | ((c5)     > T0 ? 0x04 : 0) \
  447.                 | ((c6)     > T3 ? 0x02 : 0) \
  448.                 | ((c7)     > T0 ? 0x01 : 0) )
  449.  
  450. #define setval0(c0, c1, c2, c3)                        \
  451.           (unsigned char)( ((c0)     > tiletable[0] ? 0x80 : 0) \
  452.                 | ((c0)     > tiletable[1] ? 0x40 : 0) \
  453.                 | ((c1)     > tiletable[2] ? 0x20 : 0) \
  454.                 | ((c1)     > tiletable[3] ? 0x10 : 0) \
  455.                 | ((c2)     > tiletable[0] ? 0x08 : 0) \
  456.                 | ((c2)     > tiletable[1] ? 0x04 : 0) \
  457.                 | ((c3)     > tiletable[2] ? 0x02 : 0) \
  458.                 | ((c3)     > tiletable[3] ? 0x01 : 0) )
  459.  
  460. #define setval1(c0,c1,c2,c3)                        \
  461.           (unsigned char)( ((c0)     > tiletable[4] ? 0x80 : 0) \
  462.                 | ((c0)     > tiletable[5] ? 0x40 : 0) \
  463.                 | ((c1)     > tiletable[6] ? 0x20 : 0) \
  464.                 | ((c1)     > tiletable[7] ? 0x10 : 0) \
  465.                 | ((c2)     > tiletable[4] ? 0x08 : 0) \
  466.                 | ((c2)     > tiletable[5] ? 0x04 : 0) \
  467.                 | ((c3)     > tiletable[6] ? 0x02 : 0) \
  468.                 | ((c3)     > tiletable[7] ? 0x01 : 0) )
  469.  
  470. #define setval2(c0,c1,c2,c3)                         \
  471.           (unsigned char)( ((c0)     > tiletable[ 8] ? 0x80 : 0) \
  472.                 | ((c0)     > tiletable[ 9] ? 0x40 : 0) \
  473.                 | ((c1)     > tiletable[10] ? 0x20 : 0) \
  474.                 | ((c1)     > tiletable[11] ? 0x10 : 0) \
  475.                 | ((c2)     > tiletable[ 8] ? 0x08 : 0) \
  476.                 | ((c2)     > tiletable[ 9] ? 0x04 : 0) \
  477.                 | ((c3)     > tiletable[10] ? 0x02 : 0) \
  478.                 | ((c3)     > tiletable[11] ? 0x01 : 0) )
  479.  
  480. int tiletable[] = {
  481.          7 * 32 / 12,  4 * 32 / 12, 10 * 32 / 12,  1 * 32 / 12,
  482.          3 * 32 / 12,  0 * 32 / 12,     6 * 32 / 12,  9 * 32 / 12,
  483.         11 * 32 / 12,  8 * 32 / 12,     2 * 32 / 12,  5 * 32 / 12
  484. };
  485. /*
  486. int tilealltable[] = {
  487.         12,18,24,6
  488. };
  489. */
  490.  
  491. #define gc(c)        ((c) >> 11) /* (((c) >> 11) & 0x1f) */
  492. #define rc(c)        (((c) >>  6) & 0x1f)
  493. #define bc(c)        (((c) >>  1) & 0x1f)
  494.  
  495. void    crtclr( void );
  496. #ifdef MSC
  497. char    *program = "Do-GA C.G.A System Rendering Program for PC-9800 & PC-286" ;
  498. #endif
  499. #ifdef GCC
  500. char    *program = "Do-GA C.G.A System Rendering Program for MS-DOS+go32" ;
  501. #endif
  502.  
  503. /*    CRTの初期化    */
  504. void    crtinit( line )
  505. int        line ;
  506. {
  507.     union REGS inregs, outregs;
  508.     inregs.h.ah = 0x40;
  509.     int86(0x18, &inregs, &outregs);
  510.     vline = line ;
  511.     graph_init();
  512. }
  513.  
  514. /*    CRTのクリア    */
  515. void    crtclr()
  516. {
  517.     fprintf( stderr, "\x1B[2J" );
  518.     graph_cls();
  519. }
  520.  
  521. /*    CRT出力    */
  522. void    crtout( framebuf, xlen, y )
  523. unsigned short    *framebuf ;
  524. int        xlen ;
  525. int        y ;
  526. {
  527.     int                    i, n ;
  528.     unsigned short        cl0, cl1, cl2, cl3;
  529.     unsigned short        c0, c1, c2, c3;
  530. #ifdef HIVISION
  531.     unsigned short        cl4, cl5, cl6, cl7, c4,c5,c6,c7 ;
  532. #endif
  533.     unsigned short        offset ;
  534.  
  535.     unsigned char far    *r_vram;
  536.     unsigned char far    *g_vram;
  537.     unsigned char far    *b_vram;
  538.  
  539. #ifdef HIVISION
  540.     if (PixelMode == P320x200 
  541.      || PixelMode == P640x400
  542.      || PixelMode == P640x480) {
  543.         offset = y * 80;
  544. #ifdef GRAPHUPPERRIGHT
  545.         if (PixelMode == P320x200) {
  546.             offset += 40;
  547.         }
  548. #endif
  549.         n = xlen / 8;
  550.         if (y >= 400) {
  551.             return;
  552.         }
  553.         b_vram = (unsigned char far*)GRAPH_ADDRESS_B + offset ;
  554.         r_vram = (unsigned char far*)GRAPH_ADDRESS_R + offset ;
  555.         g_vram = (unsigned char far*)GRAPH_ADDRESS_G + offset ;
  556.         for (i = 0; i < n; i++ ) {
  557.             cl0 = *framebuf++;
  558.             cl1 = *framebuf++;
  559.             cl2 = *framebuf++;
  560.             cl3 = *framebuf++;
  561.             cl4 = *framebuf++;
  562.             cl5 = *framebuf++;
  563.             cl6 = *framebuf++;
  564.             cl7 = *framebuf++;
  565.             c0 = gc(cl0);        /* green */
  566.             c1 = gc(cl1);
  567.             c2 = gc(cl2);
  568.             c3 = gc(cl3);
  569.             c4 = gc(cl4);
  570.             c5 = gc(cl5);
  571.             c6 = gc(cl6);
  572.             c7 = gc(cl7);
  573.             if (y & 1)
  574.                 *(g_vram        ) = setvalall0(c0, c1, c2, c3,c4,c5,c6,c7);
  575.             else
  576.                 *(g_vram        ) = setvalall1(c0, c1, c2, c3,c4,c5,c6,c7);
  577.  
  578.             c0 = rc(cl0);        /* red */
  579.             c1 = rc(cl1);
  580.             c2 = rc(cl2);
  581.             c3 = rc(cl3);
  582.             c4 = rc(cl4);
  583.             c5 = rc(cl5);
  584.             c6 = rc(cl6);
  585.             c7 = rc(cl7);
  586.             if (y & 1)
  587.                 *(r_vram        ) = setvalall0(c0, c1, c2, c3,c4,c5,c6,c7);
  588.             else
  589.                 *(r_vram        ) = setvalall1(c0, c1, c2, c3,c4,c5,c6,c7);
  590.  
  591.             c0 = bc(cl0);        /* blue */
  592.             c1 = bc(cl1);
  593.             c2 = bc(cl2);
  594.             c3 = bc(cl3);
  595.             c4 = bc(cl4);
  596.             c5 = bc(cl5);
  597.             c6 = bc(cl6);
  598.             c7 = bc(cl7);
  599.             if (y & 1)
  600.                 *(b_vram        ) = setvalall0(c0, c1, c2, c3,c4,c5,c6,c7);
  601.             else
  602.                 *(b_vram        ) = setvalall1(c0, c1, c2, c3,c4,c5,c6,c7);
  603.  
  604.             b_vram++ ;
  605.             r_vram++ ;
  606.             g_vram++ ;
  607.         }
  608.         return;
  609. #ifdef GRAPHUPPERRIGHT
  610.     } else if ( vline <= 256 ) {
  611.         if (y % 4 != 0)
  612.             return;
  613.         offset = ((y+YPosition) / 4) * 80 * 3 + XPosition / 8 + (80-32);
  614.         n = xlen / 8 ;
  615.     } else if ( vline <= 512 ) {
  616.         if (y % 8 != 0)
  617.             return;
  618.         offset = ((y+YPosition) / 8) * 80 * 3 + XPosition / 16 + (80-32);
  619.         n = xlen / 16 ;
  620.     } else if ( vline <= 1024 ) {
  621.         if (y % 16 != 0)
  622.             return;
  623.         offset = ((y+YPosition) / 16) * 80 * 3 + XPosition / 64 + (80-32);
  624.         n = xlen / 32 ;
  625.     } else if ( vline <= 2048 ) {
  626.         if (y % 32 != 0)
  627.             return;
  628.         offset = ((y+YPosition) / 32) * 80 * 3 + XPosition / 128 + (80-32);
  629.         n = xlen / 64 ;
  630.     }
  631. #else
  632.     } else if ( vline <= 256 ) {
  633.         if (y % 2 != 0)
  634.             return;
  635.         offset = ((y+YPosition) / 2) * 80 * 3 + XPosition / 8;
  636.         n = xlen / 4 ;
  637.     } else if ( vline <= 512 ) {
  638.         if (y % 4 != 0)
  639.             return;
  640.         offset = ((y+YPosition) / 4) * 80 * 3 + XPosition / 16;
  641.         n = xlen / 8 ;
  642.     } else if ( vline <= 1024 ) {
  643.         if (y % 8 != 0)
  644.             return;
  645.         offset = ((y+YPosition) / 8) * 80 * 3 + XPosition / 32;
  646.         n = xlen / 16 ;
  647.     } else if ( vline <= 2048 ) {
  648.         if (y % 16 != 0)
  649.             return;
  650.         offset = ((y+YPosition) / 16) * 80 * 3 + XPosition / 64;
  651.         n = xlen / 32 ;
  652.     }
  653. #endif
  654. #else
  655.     if ( vline == 256 ) {
  656.         if (y % 2 != 0)
  657.             return;
  658.         offset = (y / 2) * 80 * 3;
  659.         n = xlen / 4 ;
  660.     } else {
  661.         if (y % 4 != 0)
  662.             return;
  663.         offset = (y / 4) * 80 * 3;
  664.         n = xlen / 8 ;
  665.     }
  666. #endif
  667.  
  668.     b_vram = (unsigned char far*)GRAPH_ADDRESS_B + offset ;
  669.     r_vram = (unsigned char far*)GRAPH_ADDRESS_R + offset ;
  670.     g_vram = (unsigned char far*)GRAPH_ADDRESS_G + offset ;
  671.  
  672.     for (i = n; i > 0; --i) {
  673. #ifdef HIVISION
  674. #ifdef GRAPHUPPERRIGHT
  675.     #define SIZE1 0
  676.     #define SIZE2 256
  677.     #define SIZE3 512
  678.     #define SIZE4 1024
  679.     #define SIZE5 2048
  680. #else
  681.     #define SIZE1 256
  682.     #define SIZE2 512
  683.     #define SIZE3 1024
  684.     #define SIZE4 2048
  685.     #define SIZE5 0
  686. #endif
  687.         if (vline <= SIZE1) {
  688.             cl0 = *framebuf++;
  689.             cl1 = *framebuf++;
  690.             cl2 = *framebuf++;
  691.             cl3 = *framebuf++;
  692.         } else if (vline <= SIZE2) {
  693.             cl0 = *framebuf;
  694.             cl1 = *(framebuf + 2);
  695.             cl2 = *(framebuf + 4);
  696.             cl3 = *(framebuf + 6);
  697.             framebuf += 8;
  698.         } else if (vline <= SIZE3) {
  699.             cl0 = *framebuf;
  700.             cl1 = *(framebuf + 4);
  701.             cl2 = *(framebuf + 8);
  702.             cl3 = *(framebuf + 12);
  703.             framebuf += 16;
  704.         } else if (vline <= SIZE4) {
  705.             cl0 = *framebuf;
  706.             cl1 = *(framebuf + 8);
  707.             cl2 = *(framebuf + 16);
  708.             cl3 = *(framebuf + 24);
  709.             framebuf += 32;
  710.         } else if (vline <= SIZE5) {
  711.             cl0 = *framebuf;
  712.             cl1 = *(framebuf + 16);
  713.             cl2 = *(framebuf + 32);
  714.             cl3 = *(framebuf + 48);
  715.             framebuf += 64;
  716.         }
  717. #undef SIZE1
  718. #undef SIZE2
  719. #undef SIZE3
  720. #undef SIZE4
  721. #undef SIZE5
  722. #else
  723.         if ( vline <= 256 ) {
  724.             cl0 = *framebuf++;
  725.             cl1 = *framebuf++;
  726.             cl2 = *framebuf++;
  727.             cl3 = *framebuf++;
  728.         } else {
  729.             cl0 = *framebuf;
  730.             cl1 = *(framebuf + 2);
  731.             cl2 = *(framebuf + 4);
  732.             cl3 = *(framebuf + 6);
  733.             framebuf += 8;
  734.         }
  735. #endif
  736.         c0 = gc(cl0);        /* green */
  737.         c1 = gc(cl1);
  738.         c2 = gc(cl2);
  739.         c3 = gc(cl3);
  740.         *(g_vram        ) = setval0(c0, c1, c2, c3);
  741.         *(g_vram + LINE1) = setval1(c0, c1, c2, c3);
  742.         *(g_vram + LINE2) = setval2(c0, c1, c2, c3);
  743.  
  744.         c0 = rc(cl0);        /* red */
  745.         c1 = rc(cl1);
  746.         c2 = rc(cl2);
  747.         c3 = rc(cl3);
  748.         *(r_vram        ) = setval1(c0, c1, c2, c3);
  749.         *(r_vram + LINE1) = setval2(c0, c1, c2, c3);
  750.         *(r_vram + LINE2) = setval0(c0, c1, c2, c3);
  751.  
  752.         c0 = bc(cl0);        /* blue */
  753.         c1 = bc(cl1);
  754.         c2 = bc(cl2);
  755.         c3 = bc(cl3);
  756.         *(b_vram        ) = setval2(c0, c1, c2, c3);
  757.         *(b_vram + LINE1) = setval0(c0, c1, c2, c3);
  758.         *(b_vram + LINE2) = setval1(c0, c1, c2, c3);
  759.  
  760.         b_vram++ ;
  761.         r_vram++ ;
  762.         g_vram++ ;
  763.     }
  764. }
  765.  
  766.  
  767.  
  768.  
  769. void    crtline( x1, y1, x2, y2 )
  770. int        x1, y1, x2, y2 ;
  771. {
  772. #ifdef HIVISION
  773.     x1 += XPosition;
  774.     y1 += YPosition;
  775.     x2 += XPosition;
  776.     y2 += YPosition;
  777.     if (PixelMode != P320x200
  778.      && PixelMode != P640x400
  779.      && PixelMode != P640x480) {
  780. #ifdef GRAPHUPPERRIGHT
  781.         if (vline > 1024) {
  782.             x1 = x1 / 8 ;
  783.             y1 = y1 / 8 ;
  784.             x2 = x2 / 8 ;
  785.             y2 = y2 / 8 ;
  786.         } else if (vline > 512) {
  787.             x1 = x1 / 4 ;
  788.             y1 = y1 / 4 ;
  789.             x2 = x2 / 4 ;
  790.             y2 = y2 / 4 ;
  791.         } else if (vline > 256) {
  792.             x1 = x1 / 2;
  793.             y1 = y1 / 2;
  794.             x2 = x2 / 2;
  795.             y2 = y2 / 2;
  796.         }
  797.         x1 += (80-32) * 8;
  798.         x2 += (80-32) * 8;
  799. #else
  800.         if (vline > 1024) {
  801.             x1 = x1 / 4 ;
  802.             y1 = y1 / 4 ;
  803.             x2 = x2 / 4 ;
  804.             y2 = y2 / 4 ;
  805.         } else if (vline > 512) {
  806.             x1 = x1 / 2 ;
  807.             y1 = y1 / 2 ;
  808.             x2 = x2 / 2 ;
  809.             y2 = y2 / 2 ;
  810.         } else if (vline > 256) {
  811.         } else {
  812.             x1 = x1 * 2 ;
  813.             y1 = y1 * 2 ;
  814.             x2 = x2 * 2 ;
  815.             y2 = y2 * 2 ;
  816.         }
  817. #endif
  818.         y1 = y1 * 3 / 4 ;
  819.         y2 = y2 * 3 / 4 ;
  820.     }
  821. #ifdef GRAPHUPPERRIGHT
  822.     else if (PixelMode == P320x200 ) {
  823.         x1 += 320;
  824.         x2 += 320;
  825.     }
  826. #endif
  827. #else
  828.     if ( vline <= 256 )
  829.     {
  830.         x1 *= 2 ;
  831.         y1 *= 2 ;
  832.         x2 *= 2 ;
  833.         y2 *= 2 ;
  834.     }
  835.     y1 = y1 * 3 / 4 ;
  836.     y2 = y2 * 3 / 4 ;
  837. #endif
  838.     graph_line(x1, y1, x2, y2, 7);
  839. }
  840.  
  841.