home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / FONT98.C < prev    next >
C/C++ Source or Header  |  1994-08-10  |  3KB  |  136 lines

  1. #include <stdio.h>
  2. #ifdef __GNUC__
  3.     #include <pc.h>
  4. #else
  5.     #include <conio.h>
  6.     #define outportb(port,value)    outp(port,value)
  7. #endif
  8. #include "graph.h"
  9. #define WIDTH    640
  10. #define HEIGHT    400
  11. #define FONT_WIDTH 8
  12. #define FONT_HEIGHT 16
  13. #define ANKFONTS 256
  14.  
  15. #define GRAPH_ADDRESS_B        (0xe00a8000)
  16.  
  17. void graph_putc(int c, int x, int y, int atr)
  18. {
  19. #ifndef __GNUC__
  20.     unsigned short *cgwindow = (unsigned short *)(0xa4000000L);
  21. #else
  22.     unsigned short *cgwindow = (unsigned short *)(0xe00a4000L);
  23. #endif
  24.     char *gram = (char *)(GRAPH_ADDRESS_B);
  25.     int point, i;
  26.     if ( x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) {
  27.         return;
  28.     }
  29.     point = x / 8 + y * 80 ;
  30.     outportb(0x7c, 0xc0);
  31.     outportb(0x7e, (atr & 0x10) ? 0xff : 0);
  32.     outportb(0x7e, (atr & 0x20) ? 0xff : 0);
  33.     outportb(0x7e, (atr & 0x40) ? 0xff : 0);
  34.     outportb(0x7e, (atr & 0x80) ? 0xff : 0);
  35.     for (i = 0; i < FONT_HEIGHT; ++i) {
  36.         gram[point+i*80] = 0xff;
  37.     }
  38.     outportb(0x68, 0x0b);
  39.     outportb(0xa1, 0);
  40.     outportb(0xa3, c);
  41.     if (c != 0 && c != ' ') {
  42.         outportb(0x7c, 0xc0);
  43.         outportb(0x7e, (atr & 0x01) ? 0xff : 0);
  44.         outportb(0x7e, (atr & 0x02) ? 0xff : 0);
  45.         outportb(0x7e, (atr & 0x04) ? 0xff : 0);
  46.         outportb(0x7e, (atr & 0x08) ? 0xff : 0);
  47.         for (i = 0; i < FONT_HEIGHT; ++i) {
  48.             gram[point+i*80] = cgwindow[i]>>8;
  49.         }
  50.         outportb(0x7c, 0 );
  51.     }
  52.     outportb(0x68, 0x0a);
  53. }
  54.  
  55. static unsigned sjistojis(unsigned code)
  56. {
  57.     int c1, c2;
  58.     c1 = (code >> 8) - 0x81;
  59.     if (c1 > 0xa0 - 0x81) {
  60.         c1 -= (0xe0 - 0xa0);
  61.     }
  62.     c1 *= 2;
  63.     c2 = (code & 0xff) - 0x40 + 0x21;
  64.     if (c2 > (0x7f-0x40+0x21)) {
  65.         c2--;
  66.     }
  67.     if (c2 >= 0x7f) {
  68.         c2 -= (0x7f - 0x21);
  69.         c1++;
  70.     }
  71.     return ((c1+0x21) << 8) | c2;
  72. }
  73.  
  74. void graph_putk(unsigned int c, int x, int y, int atr)
  75. {
  76. #ifndef __GNUC__
  77.     unsigned short *cgwindow = (unsigned short *)(0xa4000000L);
  78. #else
  79.     unsigned short *cgwindow = (unsigned short *)(0xe00a4000L);
  80. #endif
  81.     char *gram = (char *)(GRAPH_ADDRESS_B);
  82.     int code;
  83.     int point, i;
  84.     if ( x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) {
  85.         return;
  86.     }
  87.     point = x / 8 + y * 80 ;
  88.     outportb(0x7c, 0xc0);
  89.     outportb(0x7e, (atr & 0x10) ? 0xff : 0);
  90.     outportb(0x7e, (atr & 0x20) ? 0xff : 0);
  91.     outportb(0x7e, (atr & 0x40) ? 0xff : 0);
  92.     outportb(0x7e, (atr & 0x80) ? 0xff : 0);
  93.     for (i = 0; i < FONT_HEIGHT; ++i) {
  94.         *(unsigned short *)(&(gram[point+i*80])) = 0xffff;
  95.     }
  96.     code = sjistojis(c);
  97.     outportb(0x68, 0x0b);
  98.     outportb(0xa1, (code & 0xff));
  99.     outportb(0xa3, (code >> 8)-0x20);
  100.     outportb(0x7c, 0xc0);
  101.     outportb(0x7e, (atr & 0x01) ? 0xff : 0);
  102.     outportb(0x7e, (atr & 0x02) ? 0xff : 0);
  103.     outportb(0x7e, (atr & 0x04) ? 0xff : 0);
  104.     outportb(0x7e, (atr & 0x08) ? 0xff : 0);
  105.     for (i = 0; i < FONT_HEIGHT; ++i) {
  106.         *(unsigned short*)(&(gram[point+i*80])) = cgwindow[i];
  107.     }
  108.     outportb(0x7c, 0 );
  109.     outportb(0x68, 0x0a);
  110. }
  111.  
  112.  
  113. void graph_puts(char *buf, int x, int y, int atr)
  114. {
  115.     unsigned char *str = buf ;
  116.     for (;*str;++str) {
  117.         if ((0x80 <= *str && *str < 0xa0)
  118.          || (0xe0 <= *str && *str < 0xf7)) {
  119.             if (x >= WIDTH-2*FONT_WIDTH) {
  120.                 x = 0;
  121.                 y += FONT_HEIGHT ;
  122.             }
  123.             graph_putk((str[0] << 8) + str[1], x, y, atr);
  124.             x += FONT_WIDTH ;
  125.             str++;
  126.         } else {
  127.             graph_putc(str[0], x, y, atr);
  128.         }
  129.         x += FONT_WIDTH ;
  130.         if ( x == WIDTH) {
  131.             x = 0;
  132.             y += FONT_HEIGHT ;
  133.         }
  134.     }
  135. }
  136.