#include <conio.h>
#include <dpmi.h>
#include <sys/nearptr.h>
#define CHARW 8
#define CHARH 8

unsigned char *video_memory = (unsigned char *) 0xA0000;
unsigned char *rom_font = (unsigned char *)0xFFA6E;
unsigned char color = 14;

void init_mode13h()
{
 __dpmi_regs regs;
 regs.x.ax = 0x13;
 __dpmi_int(0x10, &regs);
 __djgpp_nearptr_enable();
}

void put_pixel(int x, int y, unsigned char color)
{
 video_memory[y * 320 + x + __djgpp_conventional_base] = color;
}

void init_textmode()
{
 __dpmi_regs regs;
 __djgpp_nearptr_disable();
 regs.x.ax = 0x3;
 __dpmi_int(0x10, &regs);
}

void drawchar(int x, int y, char c)
{
 int ix, iy;
 char *work_byte;
 unsigned char work_bit = 0x80;
 work_byte = rom_font +(c << 3) +__djgpp_conventional_base;
 for (iy = 0; iy < CHARH; iy++)
 {
  work_bit = 0x80;
  for (ix = 0; ix < CHARW; ix++)
  {
   if ((*work_byte & work_bit))	put_pixel(x +ix, y +iy, color);
   work_bit >>= 1;
  }
  work_byte++;
 }
}

void writestring(int x, int y, char *string)
{
 int index;
 for (index = 0; string[index] != '\0'; index++)
  drawchar(x +(index << 3), y, string[index]);
}

void writestringi(int x, int y, int number)
{
 char string[7] = "";
 int index;
 itoa(number, string, 10);
 for (index = 0; string[index] != '\0'; index++)
  drawchar(x +(index << 3), y, string[index]);
}

int main()
{
 init_mode13h();
 writestring(120, 96, "Hello World!");
 writestringi(120, 105, 2000);
 getch();
 init_textmode();
}
