Mail Archives: djgpp/1997/05/08/12:21:34
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 -