NAME

seg - current segment address

SYNOPSIS

v = seg

DESCRIPTION

The predefined, read-only variable seg always contains the address of the current segment.  It is automatically set by varptr and varptr$ and can be explicitly set by def seg.  The current value of seg is automatically used by peek and poke and can be explicitly accessed by reading the variable seg directly. 

EXAMPLE

	 1 option base 1
	 5 dim src%(50), dst%(50)
	10 srcoff% = varptr(src%)
	15 srcseg% = seg
	20 dstoff% = varptr(dst%)
	25 dstseg% = seg
	30 for i% = 1 to 100
	35	def seg = srcseg%
	40	temp% = peek(srcoff%)
	45	def seg = dstseg%
	50	poke dstoff%, temp%
	55	srcoff% = srcoff% + 1
	60	if srcoff% = 0% then srcseg% = srcseg% + 1%
	65	dstoff% = dstoff% +1
	70	if dstoff% = 0% then dstseg% = dstseg% + 1%
	80 next i%
The example illustrates the use of seg in an unusual means of copying the array src% to the array dst%.  Varptr is used in lines 10 and 20 to assign the lower 16-bits of the 32-bit addresses (the offsets) to the variables srcoff% and dstoff%.  The value of seg (the high-order 16-bits of the addresses) for each of the arrays is saved (in lines 15 and 20) in the variables srcseg% and dstseg% for later use.  The for...next loop (lines 30-80) increment the offsets (lines 55 and 65) and check for segment incrementing (lines 60 and 70).  The poke (line 50) effects the swap.  Of course, there are better ways to copy arrays.  This method is shown only to illustrate the seg variable. 

SEE ALSO

peek, poke, varptr, varptr$

USAGE NOTES

In most Basmark QuickBASIC implementations, 32 bit addresses are assumed.  Def seg is used to set the high-order 16 bits of an address for future peeks and pokes (although these have questionable utility in a UNIX environment).  Seg is a variable provided to obtain the high-order 16 bits from a prior invocation of varptr or varptr$.  In Microsoft BASIC, "pointers" (or addresses) are customarily stored in integer variables.  This works out nicely on systems with 16-bit addresses because integer variables are also 16-bits.  In Basmark QuickBASIC implementations with 32-bit addresses, the high-order 16 bits must be correctly set before using peek or poke

from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber