delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/02/09:15:42

From: "A. Sinan Unur" <sinan DOT unur AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: The hard way to get VESA info
Date: Fri, 02 Jan 1998 08:40:21 -0500
Organization: Cornell University (http://www.cornell.edu/)
Lines: 87
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <34ACEE44.441760AE@cornell.edu>
References: <34AC5A4A DOT 8AC5A474 AT gold DOT com DOT br>
NNTP-Posting-Host: cu-dialup-0051.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Sérgio Vale e Pace wrote:
> 
> Could somebody out there tell-me why the code below don't work?
> 
> typedef struct {
>   byte signature[4];
>   word version;
>   dword oem;
>   dword capabilities;
>   dword modelistptr;
>   word memory;
>   byte reserved[262];
>   } svgainfo;

djgpp aligns structure members on 32-bit boundaries. so, everything
starting with dword oem in the above struct will be misaligned. to get
around it, you can use:

typedef struct tag_svgainfo
{
  ...
} svgainfo __attribute__((packed));

there is more info on this in the faq.

> typedef struct RMREGS{

why are you doing this? in any case, the same point holds for your
register structure members, too. they will all be misaligned. also, note
that any pointers specified in the sructure are in segment:offset form,
and you will need to convert them to 32 bit offsets.

> void cpymem(void* source, void* dest, dword size)

and this

> void* allocdos(word size, dword* segment, dword* selector)

and this
 
> void freedos(dword selector)

and this and so on.

> inline void rmint(word inter, rmregs* regs)

isn't it safer and more meaningful to use the functions supplied in
dpmi.h for this type of stuff? do you feel like re-writing the whole
dpmi interface? info libc func dpmi should tell you what's available.

instead of dealing with packing issues, i find it conceptually easier to
translate the structure definition to a bunch of offsets for the fields,
and then define get/set macros for each field using farpeek/farpoke
functions. here's is a snippet from the lowest layer of the netbios
interface i am working on:

/* Offsets of NCB fields */
enum ncb_offset
{
 O_CMD      =	0x00,
 O_RET_CODE =	0x01,
<snip>
 O_RSRV     =	0x32,
 O_USER     = 0x40  /* start of user-defined area */
};

/* masking macros to get/set NCB fields */
#ifdef GET_SET_MACROS /* to mask the accessor functions */

#include <sys/farptr.h>
#define NB_SET_CMD(x,y)      ( _farpokeb(_dos_ds, (x) + O_CMD, (y)) )
<snip>
#define NB_GET_CMD(x)      ( _farpeekb(_dos_ds, (x) + O_CMD) )
#define NB_GET_RET_CODE(x) ( _farpeekb(_dos_ds, (x) + O_RET_CODE) )
<snip>
#endif /* GET_SET_MACROS */  

#ifndef GET_SET_MACROS

-- 
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA

mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/

- Raw text -


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