home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / prnout / src / graphic.c < prev    next >
Text File  |  1990-06-14  |  5KB  |  212 lines

  1. #include    <stdio.h>
  2. #include    <stdarg.h>
  3. #include    <ctype.h>
  4. #include    <fmc.h>
  5. #include    <egb.h>
  6. #include    "defs.h"
  7.  
  8. static char    work[2048];
  9. static int    c_x=0;
  10. static int    c_y=0;
  11. static int    c_f=STD_COL;
  12. static int    c_b=BAK_COL;
  13. static short    c_bak =CUR_OFF;
  14.  
  15. extern void wrtank(int ch,int x,int y,int fc,int bc,int of);
  16. extern void wrtkan(int ch,int x,int y,int fc,int bc,int of);
  17. extern void disp_cur(int x,int y,int of);
  18.  
  19. void    wrtstr(char *str)
  20. {
  21.     while ( *str != '\0' ) {
  22.     if ( iskanji(*str) ) {
  23.         wrtkan((*(str++) << 8) | *(str++),c_x,c_y,c_f,c_b,0);
  24.         if ( (c_x += 2) >= 80 ) {
  25.         c_x = 0;
  26.         if ( ++c_y >= 25 )
  27.             c_y = 0;
  28.         }
  29.     } else {
  30.         wrtank(*(str++),c_x,c_y,c_f,c_b,0);
  31.         if ( ++c_x >= 80 ) {
  32.         c_x = 0;
  33.         if ( ++c_y >= 25 )
  34.             c_y = 0;
  35.         }
  36.     }
  37.     }
  38. /***************************************
  39.     char    para[128];
  40.  
  41.     WORD(para + 0) = c_x * 8;
  42.     WORD(para + 2) = c_y * 16 + 16;
  43.     WORD(para + 4) = strlen(str);
  44.     strcpy(para + 6,str);
  45.     EGB_color(work,0,c_f),
  46.     EGB_color(work,1,c_b),
  47.     EGB_sjisString(work,para);
  48.     c_x += WORD(para + 4);
  49. *******************************************/
  50. }
  51. void    putch(int ch)
  52. {
  53.     wrtank(ch,c_x,c_y,c_f,c_b,0);
  54.     if ( ++c_x >= 80 ) {
  55.     c_x = 0;
  56.     if ( ++c_y >= 25 )
  57.         c_y = 0;
  58.     }
  59. /*************************************
  60.     char    para[64];
  61.  
  62.     WORD(para + 0) = c_x * 8;
  63.     WORD(para + 2) = c_y * 16 + 16;
  64.     WORD(para + 4) = 1;
  65.     BYTE(para + 6) = (char)ch;
  66.     EGB_color(work,0,c_f),
  67.     EGB_color(work,1,c_b),
  68.     EGB_asciiString(work,1,para);
  69.     c_x++;
  70. ***************************************/
  71. }
  72. void    echo(sw)
  73. int     sw;
  74. {
  75.     if ( sw == CUR_ON ) {
  76.     disp_cur(c_x,c_y,0);
  77.     c_bak = CUR_ON;
  78.     }
  79.     if ( sw == CUR_OFF && c_bak == CUR_ON ) {
  80.     disp_cur(c_x,c_y,0);
  81.     c_bak = CUR_OFF;
  82.     }
  83. }
  84. void    locate(int x,int y)
  85. {
  86.     c_x = x;
  87.     c_y = y;
  88. }
  89. void    color(int cl)
  90. {
  91.     if ( (cl & 0x10) != 0 ) {
  92.     c_f = BAK_COL; c_b = cl & 0x0F;
  93.     } else {
  94.     c_b = BAK_COL; c_f = cl & 0x0F;
  95.     }
  96. }
  97. void    con_printf(char *form,...)
  98. {
  99.     va_list arg;
  100.     char    tmp[80];
  101.  
  102.     va_start(arg,form);
  103.     vsprintf(tmp,form,arg);
  104.     wrtstr(tmp);
  105.     va_end(arg);
  106. }
  107. void    line(x1,y1,x2,y2,md,cl,fc,st)
  108. int     x1,y1,x2,y2,md,cl,fc,st;
  109. {
  110.     char    para[10];
  111.     int        pattn[]={ 0xFFFFFFFF,0x33333333,0xF0F0F0F0,0xFFF0FFF0,0xFF18FF18 };
  112.  
  113.     EGB_writeMode(work,md);
  114.     EGB_color(work,0,cl),
  115.     EGB_linePattern(work,1,pattn[fc >= 3 ? st:0]);
  116.     if ( fc == 0 || fc == 3 ) {
  117.     EGB_paintMode(work,0x002);
  118.     WORD(para + 0) = 2;
  119.     WORD(para + 2) = x1;
  120.     WORD(para + 4) = y1;
  121.     WORD(para + 6) = x2;
  122.     WORD(para + 8) = y2;
  123.     EGB_connect(work,para);
  124.     } else if ( fc == 1 || fc == 4 ) {
  125.     EGB_paintMode(work,0x002);
  126.     WORD(para + 0) = x1;
  127.     WORD(para + 2) = y1;
  128.     WORD(para + 4) = x2;
  129.     WORD(para + 6) = y2;
  130.     EGB_rectangle(work,para);
  131.     } else if ( fc == 2 ) {
  132.     EGB_paintMode(work,0x022);
  133.     EGB_color(work,2,cl);
  134.     WORD(para + 0) = x1;
  135.     WORD(para + 2) = y1;
  136.     WORD(para + 4) = x2;
  137.     WORD(para + 6) = y2;
  138.     EGB_rectangle(work,para);
  139.     }
  140. }
  141. void    Palet_init()
  142. {
  143.     int     i,p;
  144.     char    para[64];
  145.  
  146.     for ( i = 0 ; i < 16 ; i++ ) {
  147.     p = i << 4;
  148.     DWORD(para + 0) = 1;
  149.     DWORD(para + 4) = i;
  150.     BYTE(para + 8) = p;
  151.     BYTE(para + 9) = p;
  152.     BYTE(para + 10) = p;
  153.     BYTE(para + 11) = 0;
  154.     EGB_palette(work,0,para);
  155. /******************************************
  156.     outp(0xFD90,i);
  157.     outp(0xFD92,p);
  158.     outp(0xFD94,p);
  159.     outp(0xFD96,p);
  160. *******************************************/
  161.     }
  162. }
  163. void    G_init()
  164. {
  165.     EGB_init(work,2048);
  166.     EGB_resolution(work, 0, 3);
  167. /*************
  168.     EGB_resolution(work, 1, 3);
  169.     EGB_displayPage(work, 0, 3);
  170. **************/
  171.     Palet_init();
  172.     EGB_pen(work,0);
  173.     EGB_penSize(work,1);
  174.     line(0,0,639,479,PSET,BAK_COL,FBOX,LINE_1);
  175. }
  176. void    G_era()
  177. {
  178.     line(GRA_OFFX-2,GRA_OFFY-2,GRA_MAXX,GRA_MAXY,PSET,BAK_COL,FBOX,LINE_1);
  179. }
  180. int    kbhit()
  181. {
  182.     int         cnt;
  183.     unsigned ec;
  184.  
  185.     KYB_inpchk(&cnt,&ec);
  186.     return cnt;
  187. }
  188. int    getch()
  189. {
  190.     unsigned ec;
  191.  
  192.     while ( kbhit() == 0 );
  193.     return KYB_read(0,&ec);
  194. }
  195. void    wind(x,y,s,w)
  196. int    x,y,s,w;
  197. {
  198.     x = x * 8; s++; s = x + s * 8;
  199.     y = y * 16; w++; w = y + w * 16;
  200.     x += 4; s += 4;
  201.     y += 10; w += 6;
  202.  
  203.     line(x,y,s,y,PSET,10,LINE,LINE_1);
  204.     line(x+1,y+1,s-1,y+1,PSET,10,LINE,LINE_1);
  205.     line(s,y,s,w,PSET,0,LINE,LINE_1);
  206.     line(s-1,y+1,s-1,w-1,PSET,0,LINE,LINE_1);
  207.     line(x,w,s,w,PSET,0,LINE,LINE_1);
  208.     line(x+1,w-1,s-1,w-1,PSET,0,LINE,LINE_1);
  209.     line(x,y,x,w,PSET,10,LINE,LINE_1);
  210.     line(x+1,y+1,x+1,w-1,PSET,10,LINE,LINE_1);
  211. }
  212.