delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/30/22:35:43

From: Asbjørn <lordcrc AT hotmail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Djgpp + VESA + newbie = trouble, please help
Date: Fri, 30 May 1997 20:20:42 +0200
Organization: Cyber Science Technologies
Lines: 108
Message-ID: <338F1A79.2D28@hotmail.com>
Reply-To: lordcrc AT hotmail DOT com
NNTP-Posting-Host: nm31-15.ppp.sn.no
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi all

I've just started programming c/c++, and i'm trying to get the LFB
working.
Now, it does work, but only in 8bit modes. If i try 16bit (or 24bit), I
can only access a few lines at the top, then a pagefault occurs. So,
what's 
wrong? Here's the code:

#include <stdio.h>
#include <stdlib.h>
#include <pc.h>
#include <dpmi.h>
#include <go32.h>
#include <dos.h>

#include <sys/farptr.h>

#define BYTE unsigned char

typedef struct {
  unsigned ModeAttributes;
  unsigned granularity,startseg,farfunc;
  short bscanline;
  short XResolution;
  short YResolution;
  short charpixels;
  unsigned bogus1,bogus2,bogus3,bogus4;
  unsigned PhysBasePtr;
  char bogus[228];
} ModeInfoBlock;

unsigned int ADDR;
int width,height;

ModeInfoBlock *get_mode_info(int mode)
{
  static ModeInfoBlock info;
  __dpmi_regs r;

  /* Use the transfer buffer to store the results of VBE call */
  r.x.ax = 0x4F01;
  r.x.cx = mode;
  r.x.es = __tb / 16;
  r.x.di = 0;
  __dpmi_int(0x10, &r);
  if (r.h.ah) return 0;
  dosmemget(__tb, sizeof(ModeInfoBlock), &info);
  return &info;
}

void init_graphics(int mode)
{
  __dpmi_meminfo info;
  __dpmi_regs reg;
  ModeInfoBlock *mb;

  mb=get_mode_info(mode);

  width=mb->XResolution;
  height=mb->YResolution;
  info.size=width*height;
  info.address=mb->PhysBasePtr;

  ADDR=info.address;        /* Updated by above call */
  printf("Vesa mode : %d x %d, linear frame: 0x%x\n",width,height,ADDR);
  getkey();

  reg.x.ax=0x4f02;
  reg.x.bx=0x4000+mode;                 /* mode plus linear enable bit
*/
  __dpmi_int(0x10,&reg);                /* set the mode */
}

void close_graphics(void)
{
  __dpmi_regs reg;
  reg.x.ax = 0x0003;
  __dpmi_int(0x10,&reg);
}

void main(void)
{
  int l,x,y,,my_video_ds,r,g,b;

  printf("Test VBE 2.0 linear buffer support with far pointers:\n");
  init_graphics(0x111); // 640x480x16 bit

  my_video_ds = __dpmi_allocate_ldt_descriptors(1);
  __dpmi_set_segment_base_address(my_video_ds,ADDR);
  ADDR = 0; /* basis now zero from selector */
  __dpmi_set_segment_limit(my_video_ds,(width*height*3)|0xfff);

  _farsetsel(my_video_ds);
  for (y=0;y<height;y++)
	 for (x=0;x<width;x++)
		_farnspokew((y*640*2+x*),31);

  getkey();
  close_graphics();
}


-- 
- Asbjørn / Lord Crc

http://home.sn.no/~bheid/
lordcrc AT hotmail DOT com

- Raw text -


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