Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - makeptr() convert segment/offset to 32-bit address http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 makeptr()           Convert segment/offset to 32-bit address
------------------------------------------------------------------------------
 Declaration
   memory.hdr

 Syntax
   func _POINTER makeptr extern
   param value uint uSegment, ;
         value uint uOffset

 Arguments
   uSegment is the segment address for the calculation.
   uOffset is the offset address for the calculation.

 Return
   A long pointer to a 32-bit memory address.

 Description
   The makeptr() function converts the segment/offset parameter pair into
   a ulong pointer value.

   On 80x86 machines the addresses of memory locations are normally specified
   by two 16-bit values: the segment and the offset address. Another method
   of specifying an address is to define a pointer as a 32-bit value. The
   pointer can be computed as follows:

   nPointer := longshiftleft( uSegment, 16 ) + uOffset

   which is equivalent to

   nPointer := makeptr( uSegment, uOffset )

   Some Force functions return or expect memory addresses, where some use
   a pointer (like malloc()) and others use the segment/offset scheme
   (like peek(), or poke()).

 Example
   #define EXAMPLE_MEMORY
   #include example.hdr

   /*
   This example accesses public variables via pointing to appropriate
   locations of the data segment
   */
   
   vardef
      char( 7 ) c1st := "DATASEG"     // first string in data segment
      char      c2nd := "hello there" // second string
   enddef
   
   proc Test_makeptr
   vardef
      ptr( char ) pVar             // memory pointer
   enddef
   getregs()                       // obtain CPU register values
   pVar := makeptr( __regs.ds, 0 ) // make pointer to beginning of data segment
   ? *pVar                         // print value of c1st
   pVar += len( c1st ) + 1         // point to c2nd
   ? *pVar                         // print value of c2nd
   endproc

   proc main
   Test_makeptr()
   endproc

See Also: splitptr()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson