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 - memtosegoff() copy from an object to segment/offset address http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 memtosegoff()       Copy from an object to segment/offset address
------------------------------------------------------------------------------
 Declaration
   memory.hdr

 Syntax
   proc memtosegoff extern
   param       untyped xObject, ;
         value uint    uSegment, ;
         value uint    uOffset, ;
         value uint    uLength

 Arguments
   xObject is the source memory object.
   uSegment is the target segment address.
   uOffset is the target offset address.
   uLength is the length of the copy operation.

 Return
   None.

 Description
   The procedure copies uLength bytes from the memory contents starting at the
   address of xObject to the memory block starting at the address
   specified by the uSegment/uOffset pair. The procedure can be used, as
   an example, to copy the contents of arrays to some other place. Use
   this procedure with extreme care, as it may overwrite important
   memory areas if called with an invalid address.

 Example
   #define EXAMPLE_MEMORY
   #include example.hdr

   proc Test_memtosegoff
   vardef
      ptr( char ) pMem        // pointer
      uint        nSeg, nOff  // segment and offset
      char        cString
   enddef
   pMem := malloc( 1000 )     // allocate working space
   splitptr( nSeg, nOff, pMem ) // obtain segment and offset values
   ? *pMem                    // prints accidental value
   cString := "hello"
   memtosegoff( cString, nSeg, nOff, len( cString ) + 1 ) // via function call
   ? *pMem                    // prints "hello"
   cString := "world"
   *pMem := cString           // write string to memory via pointer
   ? *pMem                    // prints "world"
   free( pMem )               // free allocation
   endproc

   proc main
   Test_memtosegoff()
   endproc

See Also: memtoptr() ptrtomem() segofftomem()

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