Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- libc - <b>_far*</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
_far*
=====

Syntax
------

     #include <sys/farptr.h>
     
     unsigned char _farpeekb(unsigned short selector, unsigned long offset);
     unsigned short _farpeekw(unsigned short selector, unsigned long offset);
     unsigned long _farpeekl(unsigned short selector, unsigned long offset);
     
     void _farpokeb(unsigned short sel, unsigned long off, unsigned char val);
     void _farpokew(unsigned short sel, unsigned long off, unsigned short val);
     void _farpokel(unsigned short sel, unsigned long off, unsigned long val);
     
     void _farsetsel(unsigned short selector);
     unsigned short _fargetsel(void);
     
     void _farnspokeb(unsigned long offset, unsigned char value);
     void _farnspokew(unsigned long offset, unsigned short value);
     void _farnspokel(unsigned long offset, unsigned long value);
     
     unsigned char _farnspeekb(unsigned long offset);
     unsigned short _farnspeekw(unsigned long offset);
     unsigned long _farnspeekl(unsigned long offset);

Description
-----------

These functions provide the equivalent functionality of "far pointers"
to peek or poke an absolute memory addresses, even though gcc doesn't
understand the keyword "far".  They come in handy when you need to
access memory-mapped devices (like VGA) or some address in lower memory
returned by a real-mode service.  These functions are provided as
inline assembler functions, so when you optimize your program they
reduce to only a few opcodes (only one more than a regular memory
access), resulting in very optimal code.

The first two groups of functions take a SELECTOR and an OFFSET.  This
selector is *not* a dos segment.  If you want to access dos memory,
pass _go32_info_block.selector_for_linear_memory (or just _dos_ds) as
the selector, and seg*16+ofs as the offset.  For functions which poke
the memory, you should also provide the VALUE to put there.

The last two groups assume that you've used `_farsetsel' to specify the
selector.  You should avoid making any function calls between
`_farsetsel' and using these other functions, unless you're absolutely
sure that they won't modify that selector.  This allows you to optimize
loops by setting the selector once outside the loop, and using the
shorter functions within the loop.  You can use `_fargetsel' if you
want to temporary change the selector with `_farsetsel' and restore it
afterwards.

Return Value
------------

Functions which peek the address return the value at given address.
`_fargetsel' returns the current selector.


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