home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / comm / ykh121.zip / YKHSRC.ZIP / FONT.C < prev    next >
C/C++ Source or Header  |  1993-04-18  |  2KB  |  112 lines

  1. #include <mem.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include "utility.h"
  6. #include "font.h"
  7.  
  8. char lpszFont16[80];
  9.  
  10. typedef struct {
  11.   unsigned index;
  12.   unsigned uses;
  13.   unsigned char buffer[32];
  14. } cache_entry;
  15.  
  16. #define MAX_CACHE 500
  17. cache_entry cache[MAX_CACHE];
  18.  
  19.  
  20. BOOL font_incache(unsigned index)
  21. {
  22. int i;
  23. for (i=0; i<MAX_CACHE; i++)
  24.   if (cache[i].index==index)
  25.     return TRUE;
  26. return FALSE;
  27. }
  28.  
  29. void font_loadcache(unsigned index)
  30. {
  31. FILE* infile;
  32. unsigned i,j,minuses;
  33. long foo;
  34.  
  35. infile=fopen(lpszFont16,"rb");
  36.  
  37. foo=index;
  38. foo*=32;
  39. fseek(infile,foo,SEEK_SET);
  40.  
  41. minuses=65000;
  42. j=0;
  43. for (i=0; i<MAX_CACHE; i++)
  44.   {
  45.   if (cache[i].uses<minuses)
  46.     {
  47.     j=i;
  48.     minuses=cache[i].uses;
  49.     }
  50.   }
  51. cache[j].index=index;
  52. cache[j].uses=0;
  53. fread(cache[j].buffer,32,1,infile);
  54. fclose(infile);
  55. }
  56.  
  57. void font_getcache(unsigned char* buffer,int index)
  58. {
  59. int i;
  60.  
  61. for (i=0; i<MAX_CACHE; i++)
  62.   {
  63.   if (cache[i].index==index)
  64.     {
  65.     cache[i].uses++;
  66.     memcpy(buffer,cache[i].buffer,32);
  67.     return;
  68.     }
  69.   }
  70. }
  71.  
  72.  
  73. void font_init   ()
  74. {
  75. int i;
  76. GetPrivateProfileString("Kanji Fonts","font16","JIS.16",lpszFont16,80,"ykh.ini"   );
  77. for (i=0; i<MAX_CACHE; i++)
  78.   {
  79.   cache[i].index=0;
  80.   cache[i].uses=0;
  81.   }
  82. }
  83.  
  84.  
  85. void font_deinit ()
  86. {
  87. }
  88.  
  89.  
  90. void far font_put(unsigned index,unsigned y, unsigned x)
  91. {
  92. unsigned char buffer[32];
  93. unsigned char far* src;
  94. unsigned char far* dest;
  95. int i;
  96.  
  97. if (!font_incache(index)) font_loadcache(index);
  98. font_getcache(buffer,index);
  99.  
  100. dest=MK_FP(0xa000,3200+x+(80*16*y));
  101.  
  102. src=buffer;
  103. for (i=0; i<16; i++)
  104.   {
  105.   *dest++=*src++;
  106.   *dest++=*src++;
  107.   dest+=78;
  108.   }
  109. }
  110.  
  111.  
  112.