DEF SEG - DualBrain/bsharp Wiki

To assign the current segment address to be referenced by a subsequent BLOAD, BSAVE, CALL, PEEK, POKE, or USR.

Syntax

DEF SEG [=address]

Comments

address is a numeric expression within the range of 0 to 65535.

The address specified is saved for use as the segment required by BLOAD, BSAVE, CALL, PEEK and POKE statements.

Entry of any value outside the address range (0-65535) results in an "Illegal Function Call" error, and the previous value is retained.

If the address option is omitted, the segment to be used is set to BASIC's data segment (DS). This is the initial default value.

If you specify the address option, base it on a 16-byte boundary.

Segment addresses are shifted 4 bits to the left; so to get the segment address, divide the memory location by 16.

For BLOAD, BSAVE, CALL, PEEK and POKE statements, the value is shifted left four bits (this is done by the microprocessor, not by BASIC) to form the code segment address for the subsequent call instruction (see the BLOAD, BSAVE, CALL, PEEK and POKE statements).

BASIC does not perform additional checking to assure that the resultant segment address is valid.

Examples

10 DEF SEG=&HB800

Sets segment to screen buffer.

20 DEF SEG

Restores segment to BASIC DS.

Note

DEF and SEG must be separated by a space. Otherwise, BASIC will interpret the statement DEFSEG=100 to mean, "assign the value 100 to the variable DEFSEG."

See Also