www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/23/22:04:23

From: almichvl AT aol DOT com (ALMICHVL)
Newsgroups: comp.os.msdos.djgpp
Subject: FAR POINTERS AND FP_SEG CODE IN A PROGRAM THAT LOADS A FONT
Lines: 173
Message-ID: <1998072401534100.VAA13013@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
Date: 24 Jul 1998 01:53:41 GMT
Organization: AOL http://www.aol.com
References: <35B79AFF DOT 7489 AT cableol DOT co DOT uk>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

THIS IS THE PROGRAM I AM TRYING TO COMPILE . ITS  BASICALLY A PROGRAM THAT
TRIES TO DISPLAY AND LOAD A USER-DEFINED FONT.

MOST OF THE CODE WORKS ITS JUST THE PART WHERE THE FP_SEG COMES IN. IF THERES
ANYBODY THAT CAN HELP ME OUT WITH THIS PIECE OF IT I WOULD APPRECIATE IT

#define far



       #include <sys/nearptr.h>
       #include <crt0.h>
     
       void * MK_FP (unsigned short seg, unsigned short ofs);


    /*Make far pointer function*/
       void * MK_FP (unsigned short seg, unsigned short ofs)
       {
         if ( !(_crt0_startup_flags & _CRT0_FLAG_NEARPTR) )
           if (!__djgpp_nearptr_enable ())
             return (void *)0;
         return (void *) (seg*16 + ofs + __djgpp_conventional_base);
       }
#include <sys/farptr.h>
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>

#define FONTSIZE 256*8

// Global Variables
int OldMode;					// variable to save user's
original mode
unsigned char far *VgaScreen;		// variable to point to screen
unsigned char far *UserFont;		// variable to save user's original
font
unsigned char far *OurFont;

// Function Declarations
void OpenGraph();
void CloseGraph();
void Go2xy(int x, int y);
void GraphChar(unsigned char value, unsigned char color);
void GraphString(int x, int y, unsigned char *string, unsigned char color);
void LoadFont();
void NewFont(unsigned char far *font);
void OldFont();

// Main Program
void main()
{
	OpenGraph();				// open graphics mode 0x13
	LoadFont();				// allocate memory and load new font
	GraphString(6, 10, "You Can Write Your Own Games", 4); // red text
	NewFont(OurFont);			// install our new font
	GraphString(6, 12, "And Your Own Fonts, too!!!", 1);	// blue text
	getch();                      // wait for a keypress
	OldFont();				// back to user's original font
	CloseGraph();          		// back to user's original mode
}

/
// OPENGRAPH                         			//
// Gets into graphics mode 0x13 (320x200x256)	void OpenGraph()
{
	union REGS regs;

	VgaScreen = MK_FP(0xA000, 0x0000);	// set pointer to screen address
     OldMode = _farpeekb(0x0040, 0x0049);   // save user's video mode first

	regs.h.ah = 0x00;			// service 0, Set Video Mode
	regs.h.al = 0x13;			// set graphics mode to 320x200x256
	int86(0x10, &regs, &regs);	// execute BIOS call
}

// CLOSEGRAPH                         			//
// Restores user's original video mode      		//
void CloseGraph()
{
	union REGS regs;

	regs.h.ah = 0x00;			// service 0, Set Video Mode
	regs.h.al = OldMode;		// set graphics mode back to user's
	int86(0x10, &regs, &regs);	// execute BIOS call
}

// GO2XY	
// Goto x/y position						//
// Input: x as 0-39, y as 0-24				//
void Go2xy(int x,int y)
{
   union REGS regs;

   regs.h.ah = 0x02;			  // service 2, Set Cursor Position
   regs.h.bh = 0;				  // set page number (always 0
for us)
   regs.h.dh = y;				  // set x/y coordinates
   regs.h.dl = x;
   int86(0x10,&regs,&regs);		  // execute BIOS call
}

// GRAPHCHAR								//
// Outputs 1 graphic character, in color		//
// Input: ASCII character value, color	void GraphChar(unsigned char value,
unsigned char color)
{
	union REGS regs;

	regs.h.ah = 0x0E;		 	  // service 0x0E, Write Character
	regs.h.al = value;			  // ASCII value of character
	regs.h.bh = 0;				  // page (always 0 for mode
0x13)
	regs.h.bl = color;			  // color (0-255)
	int86(0x10,&regs,&regs);		  // execute BIOS call
}

// GRAPHSTRING								//
// Outputs a string of graphic chars, in color	//
// Input: x, y, string, color	

void GraphString(int x, int y, unsigned char *string, unsigned char color)
{
	int loop;

	Go2xy(x,y);
	for (loop = 0; loop < strlen(string); loop++)
		GraphChar(string[loop],color);
}

// LOADFONT					//
// Load a user-defined font from disk	void LoadFont()
{
	FILE *fontfile;

	if ((OurFont = (char *) malloc(FONTSIZE)) == NULL)
	{
		CloseGraph();
		printf("Not enough memory to allocate font buffer\n");
		exit(1);
	}

	if ((fontfile = fopen("PUDGY.FNT", "rb")) == NULL)
	{
		CloseGraph();
		printf("Can't open font file for reading\n");
		exit(1);
	}

	fread(OurFont, FONTSIZE, 1, fontfile);
	fclose(fontfile);
}
// NEWFONT
// Installs new font by putting pointer to new 
// font into int43 (location $010c)			//
// Input: pointer to new font	
void NewFont(unsigned char far *font)
{
	// save old font pointer 1st
	UserFont = MK_FP(peek(0x0000,0x010e), peek(0x0000,0x010c));

	// install our font
	poke(0x0000, 0x010e, FP_SEG(font));
	poke(0x0000, 0x010c, FP_OFF(font));
}
// OLDFONT								//
// ReInstalls user's original font pointer	void OldFont()
{
	poke(0x0000, 0x010e, FP_SEG(UserFont));
	poke(0x0000, 0x010c, FP_OFF(UserFont));
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019