home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / oakfep / cons.c next >
Text File  |  1990-06-14  |  10KB  |  449 lines

  1. /******************************
  2.  *    Consol Low I/O        *
  3.  ******************************/
  4. #include    <stdio.h>
  5. #include    <stdlib.h>
  6. #include    <stdarg.h>
  7. #include    <ctype.h>
  8. #include    <egb.h>
  9. #include    <fmc.h>
  10. #include    "oaklib.h"
  11.  
  12. extern char work[];
  13.  
  14. #define    PIX_BYTE 1    /* 画面モ-ドにより変化 16色=1 256色=1 32K色=2 */
  15.  
  16. #define    TOP_X    wp->top_x
  17. #define    TOP_Y    wp->top_y
  18. #define    BTM_X    wp->btm_x
  19. #define    BTM_Y    wp->btm_y
  20. #define    SIZ_X    wp->siz_x
  21. #define    SIZ_Y    wp->siz_y
  22. #define    CUR_X    wp->cur_x
  23. #define    CUR_Y    wp->cur_y
  24. #define    CHR_COL    wp->chr_col
  25. #define    CHR_BAK    wp->chr_bak
  26. #define    CUR_COL    wp->cur_col
  27. #define    BAK_COL    wp->bak_col
  28. #define    FNT_X    wp->fnt_x
  29. #define    FNT_Y    wp->fnt_y
  30. #define    FNT_STL    wp->fnt_stl
  31. #define    KAN_COD    wp->kan_cod
  32. #define    DSP_X    wp->dsp.x
  33. #define    DSP_Y    wp->dsp.y
  34. #define    DSP_LEN    wp->dsp.len
  35. #define    DSP_BUF    wp->dsp.buf
  36.  
  37. typedef struct _WP {
  38.     struct _WP *next;
  39.     short    top_x,top_y;
  40.     short    btm_x,btm_y;
  41.     short    siz_x,siz_y;
  42.     short    cur_x,cur_y;
  43.     int    chr_col,chr_bak;
  44.     int    cur_col,bak_col;
  45.     short    fnt_x,fnt_y,fnt_stl;
  46.     short    kan_cod;
  47.     struct {
  48.         short    x,y;
  49.         short    len;
  50.         char    buf[256];
  51.     } dsp;
  52. } WIND;
  53.  
  54. WIND    *act_wind=NULL;
  55.  
  56. static int      bch=0;
  57. static unsigned bec=0;
  58.  
  59. int    kbhit(void)
  60. {
  61.     if ( bch != 0xFFFF ||
  62.     (bch = KAN_read(1,&bec)) != 0xFFFF )
  63.         return 1;
  64.     else
  65.         return 0;
  66. }
  67. int    getch(void)
  68. {
  69.     int    ch;
  70.     while ( kbhit() == 0 );
  71.     ch = bch; bch = 0xFFFF;
  72.     return ch;
  73. }
  74. void    cur_dsp(sw)
  75. int    sw;
  76. {
  77.     register WIND *wp=act_wind;
  78.     char    para[8];
  79.  
  80.     EGB_paintMode(work,0x02);
  81.     EGB_color(work,0,sw == 0 ? CUR_COL:CHR_BAK);
  82.     WORD(para+0) = DSP_X;
  83.     WORD(para+2) = DSP_Y + 1;
  84.     WORD(para+4) = DSP_X + FNT_X - 1;
  85.     WORD(para+6) = DSP_Y + 1;
  86.     EGB_rectangle(work,para);
  87. }
  88. void    chr_bak(void)
  89. {
  90.     register WIND *wp=act_wind;
  91.     char    para[8];
  92.  
  93.     if ( DSP_LEN <= 0 )
  94.     return;
  95.     EGB_paintMode(work,0x22);
  96.     EGB_color(work,0,CHR_BAK);
  97.     EGB_color(work,2,CHR_BAK);
  98.     WORD(para+0) = DSP_X;
  99.     WORD(para+2) = DSP_Y;
  100.     WORD(para+4) = DSP_X + FNT_X * DSP_LEN + ((FNT_STL & 2) ? 2:-1);
  101.     WORD(para+6) = DSP_Y - (FNT_Y - 2);
  102.     EGB_rectangle(work,para);
  103. }
  104. void    cflush(void)
  105. {
  106.     register WIND *wp=act_wind;
  107.  
  108.     cur_dsp(1);
  109.     chr_bak();
  110.     EGB_color(work,0,CHR_COL);
  111.     EGB_textSpace(work,FNT_X - 8);
  112.     EGB_fontStyle(work,FNT_STL);
  113.     EGB_sjisString(work,(char *)&(wp->dsp));
  114.     DSP_X = CUR_X * FNT_X + TOP_X;
  115.     DSP_Y = CUR_Y * FNT_Y + TOP_Y + (FNT_Y - 2);
  116.     DSP_LEN = 0;
  117.     cur_dsp(0);
  118. }
  119. WIND    *wind(int x1,int y1,int x2,int y2,
  120.           int col,int bak,int cur,
  121.           int fx,int fy,int stl)
  122. {
  123.     register WIND *wp;
  124.     char    para[8];
  125.  
  126.     if ( (wp = (WIND *)malloc(sizeof(WIND))) == NULL )
  127.     return NULL;
  128.  
  129.     wp->next = act_wind;
  130.     act_wind = wp;
  131.  
  132.     EGB_paintMode(work,0x22);
  133.     EGB_color(work,0,col);
  134.     EGB_color(work,2,bak);
  135.     WORD(para+0) = x1;
  136.     WORD(para+2) = y1;
  137.     WORD(para+4) = x2;
  138.     WORD(para+6) = y2;
  139.     EGB_rectangle(work,para);
  140.  
  141.     x1 += 2; y1 += 2; x2 -= 2; y2 -= 2;
  142.  
  143.     TOP_X = x1;
  144.     TOP_Y = y1;
  145.     BTM_X = x2;
  146.     BTM_Y = y2;
  147.     FNT_X = fx;
  148.     FNT_Y = fy;
  149.     FNT_STL = stl;
  150.     SIZ_X = (x2 - x1 + ((stl & 2) ? -2:1)) / FNT_X;
  151.     SIZ_Y = (y2 - y1 + 1) / FNT_Y;
  152.     CUR_X = 0;    CUR_Y = 0;
  153.     CHR_COL = col;
  154.     CHR_BAK = BAK_COL = bak;
  155.     CUR_COL = cur;
  156.     KAN_COD = 0;
  157.     DSP_X = TOP_X;
  158.     DSP_Y = TOP_Y + (FNT_Y - 2);
  159.     DSP_LEN = 0;
  160.     cur_dsp(0);
  161.  
  162.     return wp;
  163. }
  164. void    locate(int x,int y)
  165. {
  166.     register WIND *wp=act_wind;
  167.  
  168.     if ( (CUR_X = x) >= SIZ_X )
  169.     CUR_X = SIZ_X - 1;
  170.     if ( (CUR_Y = y) >= SIZ_Y )
  171.     CUR_Y = SIZ_Y - 1;
  172.     cflush();
  173. }
  174. void    color(int col)
  175. {
  176.     register WIND *wp=act_wind;
  177.  
  178.     CHR_COL = col;
  179. }
  180. void    rollup()
  181. {
  182.     register WIND *wp=act_wind;
  183.  
  184.     cur_dsp(1);
  185.     chr_bak();
  186.     EGB_color(work,0,CHR_COL);
  187.     EGB_textSpace(work,FNT_X - 8);
  188.     EGB_fontStyle(work,FNT_STL);
  189.     EGB_sjisString(work,(char *)&(wp->dsp));
  190.     DSP_X = CUR_X * FNT_X + TOP_X;
  191.     DSP_Y = CUR_Y * FNT_Y + TOP_Y + (FNT_Y - 2);
  192.     DSP_LEN = 0;
  193.     EGB_color(work,1,BAK_COL);
  194.     EGB_partScroll(work,1,0,-FNT_Y,(char *)&(TOP_X));
  195.     cur_dsp(0);
  196. }
  197. void    chr_out(unsigned char ch)
  198. {
  199.     register WIND *wp=act_wind;
  200.  
  201.     DSP_BUF[DSP_LEN++] = ch;
  202.     if ( ++CUR_X >= SIZ_X ) {
  203.     CUR_X = 0;
  204.     if ( ++CUR_Y >= SIZ_Y ) {
  205.         CUR_Y = SIZ_Y - 1;
  206.         rollup();
  207.     } else
  208.         cflush();
  209.     }
  210. }
  211. void    put_put(unsigned char ch)
  212. {
  213.     register WIND *wp=act_wind;
  214.  
  215.     if ( KAN_COD != 0 ) {
  216.     if ( iskanji2(ch) ) {
  217.         if ( CUR_X == (SIZ_X - 1) )
  218.         chr_out(' ');
  219.         chr_out(KAN_COD);
  220.         chr_out(ch);
  221.         KAN_COD = 0;
  222.         return;
  223.     }
  224.     KAN_COD = 0;
  225.     }
  226.     if ( iskanji(ch) ) {
  227.     KAN_COD = ch;
  228.     return;
  229.     }
  230.     if ( ch >= ' ' ) {
  231.     chr_out(ch);
  232.     return;
  233.     }
  234.     switch(ch) {
  235.     case 0x08:
  236.     if ( --CUR_X < 0 ) {
  237.         CUR_X = SIZ_X - 1;
  238.         if ( --CUR_Y < 0 )
  239.         CUR_Y = 0;
  240.     }
  241.     cflush();
  242.     break;
  243.     case 0x0D:
  244.     CUR_X = 0;
  245.     cflush();
  246.     break;
  247.     case 0x0A:
  248.     if ( ++CUR_Y >= SIZ_Y ) {
  249.         CUR_Y = SIZ_Y - 1;
  250.         rollup();
  251.     } else
  252.         cflush();
  253.     break;
  254.     }
  255. }
  256. void    putch(unsigned char ch)
  257. {
  258.     if ( ch == 0x0A )
  259.     put_put(0x0D);
  260.     put_put(ch);
  261.     if ( ch == 0x0D )
  262.     put_put(0x0A);
  263. }
  264. void    cputs(char *str)
  265. {
  266.     while ( *str != '\0' )
  267.     putch((unsigned char )*(str++));
  268. }
  269. void    cprintf(char *form,...)
  270. {
  271.     va_list arg;
  272.     char    tmp[256];
  273.  
  274.     va_start(arg,form);
  275.     vsprintf(tmp,form,arg);
  276.     cputs(tmp);
  277.     va_end(arg);
  278. }
  279.  
  280. /*********** 32K 
  281. static unsigned int dmy_pal[]={
  282.     0x00007FFF,0x000c7FFF,0x01807FFF,0x018c7FFF,
  283.     0x30007FFF,0x300c7FFF,0x31807FFF,0x318c7FFF,
  284.     0x42107FFF,0x00187FFF,0x03007FFF,0x03187FFF,
  285.     0x60007FFF,0x60187FFF,0x63007FFF,0x63187FFF };
  286. ************/
  287.  
  288. static unsigned int dmy_pal[]={
  289.     0x0000000F,0x0001000F,0x0002000F,0x0003000F,
  290.     0x0004000F,0x0005000F,0x0006000F,0x0007000F,
  291.     0x0008000F,0x0009000F,0x000A000F,0x000B000F,
  292.     0x000C000F,0x000D000F,0x000E000F,0x000F000F };
  293.  
  294. void    putstr(int pos,int len,char *str,char *att)
  295. {
  296.     static int    bak_len=0;
  297.     static char   *bak_buf[128];
  298.     register WIND *wp=act_wind;
  299.     int           i,x,y,n,m;
  300.     char          *p;
  301.     char          para[16];
  302.  
  303.     for ( i = 0 ; i < bak_len ; i++ ) {
  304.     EGB_putBlock(work,0,bak_buf[i]);
  305.     free(bak_buf[i]);
  306.     }
  307.     cflush();
  308.     bak_len = 0;
  309.     x = CUR_X; y = CUR_Y;
  310.     if ( (m = len) > 0 && len == pos )
  311.     m++;
  312.     for ( i = 0 ; i < m ; i += n ) {
  313.     n = ((i < len && iskanji((unsigned char)*str)) ? 2:1);
  314.  
  315.     if ( (x + n) > SIZ_X ) {
  316.         x = 0;
  317.         y++;
  318.     }
  319.  
  320.     if ( (p = (char *)malloc(FNT_X * FNT_Y * n * PIX_BYTE + 14)) == NULL )
  321.         break;
  322.     DWORD(p+0) = (unsigned int)(p+14);
  323.         WORD(p+4) = 0x014;            /* Data Selecter */
  324.         WORD(p+6) = TOP_X + x * FNT_X;
  325.         WORD(p+8) = TOP_Y + y * FNT_Y;
  326.         WORD(p+10) = WORD(p+6) + n * FNT_X - 1;
  327.         WORD(p+12) = WORD(p+8) + FNT_Y - 1;
  328.         EGB_getBlock(work,p);
  329.     bak_buf[bak_len++] = p;
  330.  
  331.     if ( i < len ) {
  332.             EGB_paintMode(work,0x22);
  333.             EGB_color(work,0,dmy_pal[*att]>>16);
  334.             EGB_color(work,2,dmy_pal[*att]>>16);
  335.             WORD(para+0) = WORD(p+6);
  336.             WORD(para+2) = WORD(p+8);
  337.             WORD(para+4) = WORD(p+10);
  338.             WORD(para+6) = WORD(p+12);
  339.             EGB_rectangle(work,para);
  340.  
  341.             EGB_color(work,0,dmy_pal[*att]&0xFFFF);
  342.             EGB_textSpace(work,FNT_X - 8);
  343.             EGB_fontStyle(work,FNT_STL);
  344.             WORD(para+0) = WORD(p+6);
  345.             WORD(para+2) = WORD(p+8) + (FNT_Y - 2);
  346.             WORD(para+4) = n;
  347.             *(para+6) = *str;
  348.             *(para+7) = *(str+1);
  349.             EGB_sjisString(work,para);
  350.             str += n;
  351.            att += n;
  352.     }
  353.  
  354.     if ( i == pos ) {
  355.             EGB_color(work,0,CUR_COL);
  356.             WORD(para+0) = WORD(p+6);
  357.             WORD(para+2) = WORD(p+12);
  358.             WORD(para+4) = WORD(p+10);
  359.             WORD(para+6) = WORD(p+12);
  360.             EGB_rectangle(work,para);
  361.     }
  362.  
  363.     if ( (x += n) >= SIZ_X ) {
  364.         x = 0;
  365.         y++;
  366.     }
  367.     }
  368. }
  369. void    putsys(int len,char *str,char *att)
  370. {
  371.     static int    bak_len=0;
  372.     static char   *bak_buf;
  373.     register WIND *wp=act_wind;
  374.     int           i,x,y,n;
  375.     char          *p;
  376.     char          para[16];
  377.  
  378.     if ( bak_len > 0 ) {
  379.     EGB_putBlock(work,0,bak_buf);
  380.     free(bak_buf);
  381.     }
  382.  
  383.     bak_len = 0;
  384.     if ( len == 0 )
  385.     return;
  386.  
  387.     if ( (p = bak_buf = 
  388.      (char *)malloc(FNT_X * FNT_Y * len * PIX_BYTE + 14)) == NULL )
  389.     return;
  390.  
  391.     DWORD(p+0) = (unsigned int)(p+14);
  392.     WORD(p+4) = 0x014;            /* Data Selecter */
  393.     WORD(p+6) = x = TOP_X;
  394.     WORD(p+8) = y = BTM_Y + 8;
  395.     WORD(p+10) = x + len * FNT_X - 1;
  396.     WORD(p+12) = y + FNT_Y - 1;
  397.     EGB_getBlock(work,p);
  398.     bak_len = len;
  399.  
  400.     for ( i = 0 ; i < len ; i += n ) {
  401.     n = (iskanji((unsigned char)*str) ? 2:1);
  402.  
  403.         EGB_paintMode(work,0x22);
  404.         EGB_color(work,0,dmy_pal[*att]>>16);
  405.         EGB_color(work,2,dmy_pal[*att]>>16);
  406.         WORD(para+0) = x;
  407.         WORD(para+2) = y;
  408.         WORD(para+4) = x + n * FNT_X - 1;
  409.         WORD(para+6) = y + FNT_Y - 1;
  410.         EGB_rectangle(work,para);
  411.  
  412.         EGB_color(work,0,dmy_pal[*att]&0xFFFF);
  413.         EGB_textSpace(work,FNT_X - 8);
  414.         EGB_fontStyle(work,FNT_STL);
  415.         WORD(para+0) = x;
  416.         WORD(para+2) = y + (FNT_Y - 2);
  417.         WORD(para+4) = n;
  418.         *(para+6) = *str;
  419.         *(para+7) = *(str+1);
  420.         EGB_sjisString(work,para);
  421.         str += n;
  422.        att += n;
  423.     x += (FNT_X * n);
  424.     }
  425. }
  426. void    putmode(int md,int sf,char *str)
  427. {
  428.     register WIND *wp=act_wind;
  429.     char    para[40];
  430.  
  431.     EGB_paintMode(work,0x22);
  432.     EGB_color(work,0,CHR_COL);
  433.     EGB_color(work,2,BAK_COL);
  434.     WORD(para+0) = BTM_X - 74;
  435.     WORD(para+2) = BTM_Y + 8;
  436.     WORD(para+4) = BTM_X + 1;
  437.     WORD(para+6) = BTM_Y + 8 + 19;
  438.     EGB_rectangle(work,para);
  439.  
  440.     strcpy(para+6,str);
  441.     EGB_color(work,0,CHR_COL);
  442.     EGB_textSpace(work,0);
  443.     EGB_fontStyle(work,0);
  444.     WORD(para+0) = BTM_X - 72;
  445.     WORD(para+2) = BTM_Y + 8 + 17;
  446.     WORD(para+4) = 9;
  447.     EGB_sjisString(work,para);
  448. }
  449.