delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/08/12:21:34

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Video pointer with Allegro
Date: Mon, 5 May 1997 13:25:03 +0100
Organization: None
Distribution: world
Message-ID: <ZzB17PAfGdbzEw8P@talula.demon.co.uk>
References: <336e2d98 DOT 427920 AT nntp DOT netcomuk DOT co DOT uk>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 59
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

William McGugan writes:
>How do you create a pointer to vesa2 linear memory? I want to be able
>to pass it to an assembler function.

Look at the section titled "Video memory access" in allegro.txt.

If you are sure you are using a VESA2 linear mode, screen->line[0] is
the address of the start of video memory, and that is a far pointer
relative to screen->seg (use the functions in sys/farptr.h to access
it). If your code might be running in a banked SVGA mode, you need to
call the function bmp_write_line(screen, linenumber) to get the start
address for each horizontal line you want to access.

If you want to use the nearptr hack rather than far pointers, you'll
need to do a bit of DPMI magic to get the pointer into the correct
format, eg:


#include <allegro.h>
#include <sys/nearptr.h>


int main()
{
   unsigned char *screenmemory;
   unsigned long screen_base_addr;
   int x;

   /* initialise Allegro. You must use a linear mode, this will  
    * _not_ work in banked video modes!!! 
    */
   allegro_init();
   install_keyboard();
   set_gfx_mode(GFX_VESA2L, 640, 480, 0, 0);
   set_pallete(desktop_palette);

   /* enable near pointers */
   __djgpp_nearptr_enable();

   /* get the base address of the video memory selector */
   __dpmi_get_segment_base_address(screen->seg, &screen_base_addr);

   /* get a pointer to the video memory */
   screenmemory = (unsigned char *)(screen_base_addr + screen->line[0] - 
                                    __djgpp_base_address);

   /* draw a horizontal line across the screen */
   for (x=0; x<SCREEN_H; x++)
      screenmemory[x*(SCREEN_W+1)] = x;

   readkey();
   return 0;
}



--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
Beauty is a French phonetic corruption of a short cloth neck ornament.

- Raw text -


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