Utility

Reference Section

c_code
_ptr_to_seg

c_code


Descrip
(Variable) Contains the status of the most recent conversion.

Syntax
#include <util.h>
extern int c_code;

Notes
This int variable is updated by the data conversion and date/time conversion functions to contain the status of each conversion. Possible values for this variable are 1, 0, and -1 and have the following meanings:

C_OFLOW (0) Overflow occurred
C_SUCCESS(1) Conversion was successful
C_UFLOW (-1) Underflow was detected (no digits were encountered)

Possible values for c_code vary for each function and are noted in the reference section.

c_code is initialized to 0.

UTIL.H is automatically included by DATACONV.H and DATETIME.H.

Source file _UTCCODE.ASM ASM equivâ
See also
_asc_to_..., _dec_to_..., _hex_to_...

_ptr_to_seg


Descrip
Converts a far pointer to a segment address (unsigned int).

Syntax
#include <util.h>
segaddr _ptr_to_seg(void far *addr);

Returns
The calculated segment address of the buffer pointed to by addr if the resulting segment is in the first 1MB of addressable RAM.

0 if the resulting segment is in the high memory area (segment at 0xFFFF).

Notes
This function converts addr into a segment address. A valid segment address is returned if addr points to a location in the first megabyte of memory (between 0:0 and 0xFFFF:0). The returned segment address is always aligned at the next segment boundary beyond addr. 0 is returned if addr points to a location in the high memory area (approximately first 64K above the 1MB boundary).

Memory locations in the high memory area must be referenced from a segment in the first megabyte of memory (usually 0xFFFF).

WARNING! Since 0 is a valid (but unlikely) segment address, the programmer must evaluate whether or not a return value of 0 is an error.

C/C++ Example
	{
	   char rel_heap_buf[0x4010];
	   ...
	   if(_ptr_to_seg(rel_heap_buf) != 0);
	   _rel_init(0x4010);/* initialize relative heap */
	   _rel_malloc(0x2000);/* allocate block on rel heap*/
	   ...
	}

Inline Assembly Example
	#include <inline.h>
	{
	   char rel_heap_buf[0x4010];
	   ...
	   lea     ax,rel_heap_buf
	   mov     dx,ss	/* DX:AX -> rel_heap_buf */
	   ptr_to_seg	/* DX = 1st seg boundary */
	   	  	 	/*   in rel_heap_buf */
	    jc     handle_error/* if error, go handle it
	   mov     es,dx	/* ES = starting segment */
	   	  	 	/*   of relative heap */
	 mov     ax,0x4010
	    rel_init();	 /* initialize a 0x4010 byte */
	    	   	  	 /*   relative heap */
	    mov     ax,0x2000
	    rel_malloc();	 /* allocate a 0x2000 byte */
	    	   	  	 /*   block from heap */
	     jc     handle_error/* if error, go handle it */
	    ... 	  	 /* ES:DI -> mem block on */
	    	   	  	 /*   relative heap */
	handle_error:
	    ... 	  	 /* handle errors here */
	    }

Source file _UTPTOS.ASM ASM equiv PTR_TO_SEG