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 >
Wrap
C/C++ Source or Header
|
1994-08-10
|
3KB
|
136 lines
#include <stdio.h>
#ifdef __GNUC__
#include <pc.h>
#else
#include <conio.h>
#define outportb(port,value) outp(port,value)
#endif
#include "graph.h"
#define WIDTH 640
#define HEIGHT 400
#define FONT_WIDTH 8
#define FONT_HEIGHT 16
#define ANKFONTS 256
#define GRAPH_ADDRESS_B (0xe00a8000)
void graph_putc(int c, int x, int y, int atr)
{
#ifndef __GNUC__
unsigned short *cgwindow = (unsigned short *)(0xa4000000L);
#else
unsigned short *cgwindow = (unsigned short *)(0xe00a4000L);
#endif
char *gram = (char *)(GRAPH_ADDRESS_B);
int point, i;
if ( x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) {
return;
}
point = x / 8 + y * 80 ;
outportb(0x7c, 0xc0);
outportb(0x7e, (atr & 0x10) ? 0xff : 0);
outportb(0x7e, (atr & 0x20) ? 0xff : 0);
outportb(0x7e, (atr & 0x40) ? 0xff : 0);
outportb(0x7e, (atr & 0x80) ? 0xff : 0);
for (i = 0; i < FONT_HEIGHT; ++i) {
gram[point+i*80] = 0xff;
}
outportb(0x68, 0x0b);
outportb(0xa1, 0);
outportb(0xa3, c);
if (c != 0 && c != ' ') {
outportb(0x7c, 0xc0);
outportb(0x7e, (atr & 0x01) ? 0xff : 0);
outportb(0x7e, (atr & 0x02) ? 0xff : 0);
outportb(0x7e, (atr & 0x04) ? 0xff : 0);
outportb(0x7e, (atr & 0x08) ? 0xff : 0);
for (i = 0; i < FONT_HEIGHT; ++i) {
gram[point+i*80] = cgwindow[i]>>8;
}
outportb(0x7c, 0 );
}
outportb(0x68, 0x0a);
}
static unsigned sjistojis(unsigned code)
{
int c1, c2;
c1 = (code >> 8) - 0x81;
if (c1 > 0xa0 - 0x81) {
c1 -= (0xe0 - 0xa0);
}
c1 *= 2;
c2 = (code & 0xff) - 0x40 + 0x21;
if (c2 > (0x7f-0x40+0x21)) {
c2--;
}
if (c2 >= 0x7f) {
c2 -= (0x7f - 0x21);
c1++;
}
return ((c1+0x21) << 8) | c2;
}
void graph_putk(unsigned int c, int x, int y, int atr)
{
#ifndef __GNUC__
unsigned short *cgwindow = (unsigned short *)(0xa4000000L);
#else
unsigned short *cgwindow = (unsigned short *)(0xe00a4000L);
#endif
char *gram = (char *)(GRAPH_ADDRESS_B);
int code;
int point, i;
if ( x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) {
return;
}
point = x / 8 + y * 80 ;
outportb(0x7c, 0xc0);
outportb(0x7e, (atr & 0x10) ? 0xff : 0);
outportb(0x7e, (atr & 0x20) ? 0xff : 0);
outportb(0x7e, (atr & 0x40) ? 0xff : 0);
outportb(0x7e, (atr & 0x80) ? 0xff : 0);
for (i = 0; i < FONT_HEIGHT; ++i) {
*(unsigned short *)(&(gram[point+i*80])) = 0xffff;
}
code = sjistojis(c);
outportb(0x68, 0x0b);
outportb(0xa1, (code & 0xff));
outportb(0xa3, (code >> 8)-0x20);
outportb(0x7c, 0xc0);
outportb(0x7e, (atr & 0x01) ? 0xff : 0);
outportb(0x7e, (atr & 0x02) ? 0xff : 0);
outportb(0x7e, (atr & 0x04) ? 0xff : 0);
outportb(0x7e, (atr & 0x08) ? 0xff : 0);
for (i = 0; i < FONT_HEIGHT; ++i) {
*(unsigned short*)(&(gram[point+i*80])) = cgwindow[i];
}
outportb(0x7c, 0 );
outportb(0x68, 0x0a);
}
void graph_puts(char *buf, int x, int y, int atr)
{
unsigned char *str = buf ;
for (;*str;++str) {
if ((0x80 <= *str && *str < 0xa0)
|| (0xe0 <= *str && *str < 0xf7)) {
if (x >= WIDTH-2*FONT_WIDTH) {
x = 0;
y += FONT_HEIGHT ;
}
graph_putk((str[0] << 8) + str[1], x, y, atr);
x += FONT_WIDTH ;
str++;
} else {
graph_putc(str[0], x, y, atr);
}
x += FONT_WIDTH ;
if ( x == WIDTH) {
x = 0;
y += FONT_HEIGHT ;
}
}
}