GS BASIC: Features and Editing Commands

This article discusses GS BASIC features and editing commands.
ToolBox Primitives
GS BASIC includes primitives (built-in, low-level commands) that let the user interact with the ToolBox routines. Whereas most other ToolBox routines are implemented in external libraries that need to be explicitly called up, these commands -- Eventdef, Menudef, and Taskpoll -- are included in GS BASIC itself because they bind the ToolBox and BASIC line numbers.

Eventdef
The structure of Macintosh-like programs, as implemented by the Apple II GS and its ToolBox routines, requires that programs be event-driven. This means that the heart of a program is a main loop that constantly monitors what events -- mouse clicks, keyboard presses, window update events, network activity, and so on -- have taken place. Eventdef associates BASIC line numbers with these events: whenever one of these events occurs, GS BASIC starts running the instructions specified in a table set up by the programmer and maintained by Eventdef.

Menudef
One of the places a mouse click can occur is in the menu bar. When this happens, a menu is displayed, letting the user select a menu item. The user specifies that a certain function is to be performed. Like Eventdef, Menudef associates BASIC line numbers with menu items, so that when a menu item is selected, GS BASIC can easily determine what statements to run, and run them.

Taskpoll
Programs shouldn't start fielding events and responding to them until all the ToolBox libraries are loaded and the tables that Menudef and Eventdef maintain are initialized. The Taskpoll command lets the programmer turn off the interrupting feature of GS BASIC and turn them on when ready for them.


Procedures and Functions
The most convenient structure of of any program is a procedure, function, or subroutine. In most BASICs, including Applesoft, subroutines are implemented in a very straightforward fashion. GS BASIC provides a more powerful way to specify and call procedures.

Applesoft lets programmers call subroutines with the GOSUB xxx command, where xxx is the line number to which control branches. Statements are then executed until a RETURN command is executed, at which time the program returns to the line that called the subroutines, and continues from there.

GS BASIC allows programmers to define specific procedures that are called with the PROC command. The PROC command performs the same functions as Applesoft's GOSUB, and lets the programmer pass local parameters as well.

GS BASIC has a more powerful line editor than Applesoft's. Access it by typing EDIT linnum[-linnum]

Editing Commands
CONTROL-D delete character to the left of cursor; moves line to left
CONTROL-Fdelete character under the cursor; moves line left
CONTROL-Xdelete entire line
CONTROL-Ydelete line to left and under cursor
CONTROL-Etoggle insert mode
RETURNaccept entire line (even characters to right of cursor)
DELETEsame as CONTROL-D

GS BASIC Commands
_ (underscore)ERRLINLOG(SCALB(
ABS(ERRORLOG1(SCALE(
ANDERRTOOLLOG2(SECONDS@
ANU(ERRTXT$(LOGB%(SET
APPENDEVENTDEFMENUDEFSGN(
ASEXCEPTIONMID$(SHOWDIGITS
ASC(EXECMODSIN(
ASSIGNEXEVENT@(NEGATE(SPACE$(
ATN(EXFNNEWSPC(
AUTOEXP(NEXTSQR(
AUXID@EXP1(NORMALSRC
BASIC@(EXP2(NOTSTEP
BDFFILE(NOTRACESTOP
BREAKFILTYP(OFFSTR$(
BTN(FILTYP=ONSUB$(
CALLFIX(OPENSWAP
CALL%FNORTAB(
CATFOROPUTPUTTAN(
CATALOGFREOUTRECTASKPOLL
CHAINFREMEM(PDL(TASKREC%(
CHR$(GETPEEK(TASKREC@(
CLEARGOSUBPERFORMTEN(
CLOSEGOTOPFX$(TEXT
COMPI(GRAFPITEXTPORT
CONTHEX$(POKETHEN
CONV(HLISTPREFIXTIME$
CONV@(HOMEPREFIX$TIME(
CONV#(HPOSPRINTTIMER
CONV$(IFPROCTO
CONV%(IMAGEPROGNAM$TRACE
CONV&(INDENTPUTTXT
COPYINITQUITTYPE
COS(INPUTR.STACK%(TYP(
CREATEINSTR(R.STACK@(UBOUND(
DATAINT(R.STACK&(UCASE$(
DATE$INVERSERANDOMIZEUIR(
DATE(INVOKEREADUNLOCK
DEFJOYX(REC(UNTIL
DELJOYY(RELATION(UPDATE
DELETEKBDREMUSING
DIMLEFT$(REMDRVAL(
DIRLEN(RENAMEVAR(
DIVLETREP$(VAR$(
DOLIBFINDRESTOREVARPTR(
EDITLIBRARYRESUMEVARPTR$(
ELSELISTRETURNVOLUMES
ENDLISTTABRIGHT$(VPOS
EOFLOADRND(WHILE
EOFMARK(LOCALROUND(WRITE
ERASELOCATERUNXOR
ERRLOCKSAVE



Toolbox Definition Files (TDFs)
QuickDrawADBDeskDialog
QuickDrawFontIntmathLineEdit
ListLoaderLocaterMemory
Menu MiscToolNoteSynPrint
Menu SchedulerScrapStdFile
TextWindowControl

Built-in Constants and Reserved Variables
PIto 20 digits
LISTTABnumber of spaces between line number and first statement
INDENTcontrols indenting of FOR...NEXT and WHILE...UNTIL loops
OUTRECmaximum line length
VPOSvertical cursor position
HPOShorizontal cursor position
FREamount of memory available
SHOWDIGITSspecifies the number of digits to display for REAL numbers
KBDholds value of last key pressed
ERRcontains error number
ERRLINcontains line where error occurred

Variable Specifications
Real:(+ or - 1.7E38) (less than 1.5E-45 equals 0)
Double real:(+ or - 1.7E308) (less than 5.0E-324 equals 0)
Integer:(%) (2 bytes) (-32768 to 32767)
Double integer:(@) (4 bytes) (-2147483648 to 2147483647)
Long integer:(&) (8 bytes) (-9223372036854775808 to 9223372036854775807)
String:($) 255 characters
Arrays: (!)
Published Date: Feb 18, 2012