home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
comm
/
ykh121.zip
/
YKHSRC.ZIP
/
FONT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-18
|
2KB
|
112 lines
#include <mem.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include "utility.h"
#include "font.h"
char lpszFont16[80];
typedef struct {
unsigned index;
unsigned uses;
unsigned char buffer[32];
} cache_entry;
#define MAX_CACHE 500
cache_entry cache[MAX_CACHE];
BOOL font_incache(unsigned index)
{
int i;
for (i=0; i<MAX_CACHE; i++)
if (cache[i].index==index)
return TRUE;
return FALSE;
}
void font_loadcache(unsigned index)
{
FILE* infile;
unsigned i,j,minuses;
long foo;
infile=fopen(lpszFont16,"rb");
foo=index;
foo*=32;
fseek(infile,foo,SEEK_SET);
minuses=65000;
j=0;
for (i=0; i<MAX_CACHE; i++)
{
if (cache[i].uses<minuses)
{
j=i;
minuses=cache[i].uses;
}
}
cache[j].index=index;
cache[j].uses=0;
fread(cache[j].buffer,32,1,infile);
fclose(infile);
}
void font_getcache(unsigned char* buffer,int index)
{
int i;
for (i=0; i<MAX_CACHE; i++)
{
if (cache[i].index==index)
{
cache[i].uses++;
memcpy(buffer,cache[i].buffer,32);
return;
}
}
}
void font_init ()
{
int i;
GetPrivateProfileString("Kanji Fonts","font16","JIS.16",lpszFont16,80,"ykh.ini" );
for (i=0; i<MAX_CACHE; i++)
{
cache[i].index=0;
cache[i].uses=0;
}
}
void font_deinit ()
{
}
void far font_put(unsigned index,unsigned y, unsigned x)
{
unsigned char buffer[32];
unsigned char far* src;
unsigned char far* dest;
int i;
if (!font_incache(index)) font_loadcache(index);
font_getcache(buffer,index);
dest=MK_FP(0xa000,3200+x+(80*16*y));
src=buffer;
for (i=0; i<16; i++)
{
*dest++=*src++;
*dest++=*src++;
dest+=78;
}
}