www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/06/20:07:43

Xref: news2.mv.net comp.os.msdos.djgpp:3514
From: Shawn Hargreaves <slh100 AT york DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Memory problem
Date: Sun, 5 May 1996 12:01:15 +0100
Organization: The University of York, UK
Lines: 34
Message-ID: <Pine.SGI.3.91.960504203542.19009A-100000@tower.york.ac.uk>
NNTP-Posting-Host: tower.york.ac.uk
Mime-Version: 1.0
In-Reply-To: <4mdcv7$2qgu@venere.inet.it>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Thread: Frames, NoFrames, TwoWindows

On Fri, 3 May 1996, Edo wrote:

> Can anyone help me with this little piece of code? This program put a
> pixel into a "virtual" screen and then copy the virtual screen into
> the vga...but it doesn't work! I think that it is due to my low skill
[...]
>   vr_screen=(unsigned long *)malloc(320*200);
>   vr_screen_sel=_go32_my_ds();
>   vr_addr=__dpmi_get_segment_base_address(vr_screen_sel,vr_screen);
>   vr_addr=vr_addr*16;

None of that is needed for writing to a virtual buffer. You don't need to 
explicitly load the vr_screen_sel, since that will always be in %ds and 
%es in any case. You don't need to worry about the segment base address 
either: that is a linear address, wheras you want to use the offset into the 
segment which is what malloc returns. It's much simpler than you think...

All you need is:

char *vr_screen = malloc(320*200);

void putpixel(int x, int y, int color)
{
	vr_screen[y*320 + 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   donations   bookstore     delorie software   privacy  
  Copyright 2014   by DJ Delorie     Updated Aug 2014