www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/09/17:18:44

Xref: news2.mv.net comp.os.msdos.djgpp:4765
From: Shawn Hargreaves <slh100 AT york DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: newbie djgpp putpixel ques.
Date: Sun, 9 Jun 1996 12:05:01 +0100
Organization: The University of York, UK
Lines: 46
Message-ID: <Pine.SGI.3.91.960609115443.18230B-100000@tower.york.ac.uk>
NNTP-Posting-Host: tower.york.ac.uk
Mime-Version: 1.0
In-Reply-To: <31BA4381.7C6E@ccm.tdsnet.com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Sat, 8 Jun 1996, Chris Grubb wrote:

> I'm new to djgpp, and c in general..but I'm learning..can someone 
> please point out to me what's wrong with this putpixel routine..when I 
> try to run it, I get a page fault..here's the code
> 
> void set_mode_13h(void) {
> 	asm("movw $0x13,%ax
> 		int $0x10
> 		");	
> }

I'd be inclined to do this with __dpmi_int() rather than inline asm. Your 
method will probably work, but using __dpmi_int() is a lot safer...

> void put_pixel(int color, int x, int y)
> {
> long *base_address = 0xA0000;
> long *memory_address = 0;
> 
> 	memory_address = base_address + (320 * y) + x;	
> 	*(memory_address) = color;
> }

There are lots of problems with that. Most seriously, you are writing to 
0xA0000, which is a protected mode address and not the one you want. Read 
the FAQ! It explains all this in detail...

Also you are writing to *(memory_address), which is a long pointer, and so 
in mode13h you will be setting 4 pixels rather than just one.

The easiest way to fix your code would be to #include "sys/farptr.h" and 
then do:

void put_pixel(int color, int x, int y)
{
	_farpokeb(_dos_ds, 0xA0000+(320*y)+x, color);
}


/*
 *	Shawn Hargreaves.        Why is 'phonetic' spelt with a ph?
 *	Check out Allegro and FED on http://www.york.ac.uk/~slh100/
 */


- Raw text -


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