[comp.sys.cbm] Forth in Geos! part 3 of 3

anderson@ncrcce.StPaul.NCR.COM (Joel Peter Anderson) (10/25/89)

This is part two of the GeosForth documentation.



---------------Cut Here-------------------
  enclose addr c --- addr n1 n2 n3
  This is the text scanning primative used by word.  From the text
address addr and an ASCII delimiting character c, enclose determines the
offset (n1) to the first non-delimiter character, the offset (n2) to the
first delimiter after the text, and the offset (n3) to the first
character not included.  enclose will not process past an ASCII 'null'
($00), treating it as an unconditional delimiter.

  end --- This is an alias (duplicate) of until.

  endif addr n --- (compile time)
  Occurs in a colon definition in the form:
  if ... endif
  if ... else ... endif
  At run time, endif serves only as the destinition of a forward branch
from if or else.  It marks the conclusion of the conditional structure.
  At compile time, endif computes the forward branch offset from addr to
here and stores it at addr.  n is used to make sure the previous
conditional was if or else.

  erase addr n --- Clear a regions of memory to zeros from addr for a
length of n bytes.

  error n --- Prints the error message ' ?message #n', and calls quit.

  execute addr --- Execute the definition whose code field address (addr)
is on the stack.

  expect addr n --- Transfer characters from the keyboard to addr, until
a return has been input.  Only n characters will be accepted.  The input
string will have an ASCII 'null' added at the end.  expect will recognize
a number of editing characters.  CTRL-X will erase all input characters
so you can start entering them again, the left and right cursor controls
will allow you to move within the buffer.  expect honors the GEOS left
and right margin setting.  If the width of the characters being inputted
exceeds the margins, expect will scroll the window left and right as
needed.

  fence --- addr A user variable containing an address below which
forgetting is trapped.  To forget below this point, the user must alter
the contents of fence.  This prevents accidentially whiping out important
parts of Forth.  fence is initialized to the end of Forth when it is
loaded.

  fill addr n b --- Fill memory from addr with n bytes of the value b.

  first --- addr A constant that leaves the address of the first (lowest)
block buffer.

  fld --- addr A user variable used to hold the output field width.

  flush --- Force all updated disk buffers to be written to disk.
desktop calls flush to make sure all buffers are written before exiting
to the DeskTop.

  forget --- Used in the form:
  forget cccc
  Deletes the definition named cccc from the dictionary, along with all
entries physically following it.  An error message will occur if the
current and context vocabularies are not the same.

  forth --- The name of the primary vocabulary.  Execution makes forth
the context vocabulary.  Until additional user vocabularies are defined,
new user definitions become a part of forth.  forth is immedate, so it
will execute during the creation of a colon definition, to allow the
selection of this vocabulary at compile time.

  get n --- Read the screen n into memory.  Unlike block, this word will
force a read of the screen from the disk.  If the screen is currently in
memory, that buffer will be reused to hold the copy being read in, but
the old screen will not be written to disk.  scr is not updated by this
word.

  here --- addr Leave the address of the next available dictionary
location.

  hex --- Set the numeric conversion base to sixteen (hexadecimal).

  hld --- addr A user variable that holds the adress of the latest
character of text during numeric output conversion.

  hold c --- Used between <# #> to insert an ASCII character into a
pictured numeric output string (e.g. 2E hold will place a decimal point).

  i --- n Used within a do ... to copy the current loop index to the
stack.

  id.  nfa --- Print a definition's name from its name field address.

  if --- addr n (compile time)
  f --- (run time)
  Used in a colon definition in the form:
  if ... endif
  if ... else ... endif
  At run time, if selects execution based on the boolean flag.  If f is
true (non-zero), execution continues immediately past the if.  If f is
false (zero), execution skips till just after the else (if present) to
execute the false part.  After either part, execution resumes after the
endif.  else and its false part are optional.  If missing, false
execution skips to just after the endif.
  At compile time if compiles 0branch and reserves space for an offset at
addr.  addr and n are used later for resolution of the forward branch and
error testing.

  immediate --- Mark the most recently made definition so that when
encountered at compile time, it will be executed rather than being
compiled.  i.e. the precedence bit in the header is set.  This method
allows definitions to handle unusual compiling situations rather.  The
user may force compilation of an immediate definition by preceeding it
with [compile].

  in --- addr A user variable containing the byte offset within the
current input text buffer (terminal or disk) from which the next text
will be accepted.  word uses and moves the value of in.

  interpret --- The outer text interpreter which sequentially executes or
compiles text from the input stream (terminal or disk) depending upon
state.  If the word name cannot be found after a search of context and
then current it is converted to a number according to the current base.
If that fails, an error message echoing the input name with a " ?" will
be output.  Text input will be taken according to the convention for
word.

  key --- c Leave the ASCII value of the next terminal key struck.  key
waits for a key to be struck.

  latest --- nfa Leave the name field address of the top most word in the
current vocabulary.

  leave --- Force termination of a do ... at the next opportunity by
setting the loop limit equal to the current value of the index.  The
index itself remains unchanged, and execution proceeds normally until
loop or +loop is encountered.

  lfa pfa --- lfa Convert the parameter field address of a dictionary
definition to its link field address.

  limit --- n A constant leaving the address just above the highest
memory available for a disk buffer.

  lit --- n Within a colon definition, lit is automatically compiled
before each 16 bit literal number encountered in input text.  Later
execution of lit causes the contents of the next dictionary address to be
put on the stack.

  literal n --- (compile time)
  If compiling, then compile the stack value n as a 16 bit literal.
literal is immediate so that it will execute during a colon definition.
The intended use is in the form:
  : xxx [ calculate ] literal ;
  Compilation is suspended for the compile time calculation of a value.
Compilation is resumed and literal compiles this value.

  lm --- addr A constant which returns the address of the top of memory
available for FORTH to store dictionary words in.  Normally this is the
same as first.

  load n --- Begin interpretation of screen n.  Loading will terminate at
the end of the screen or at ;s.

  loc-blk n --- f Attempt to locate block n in memory.  If it is not
found a true flag is returned.  If is is found prev is updated to point
to the buffer, and a false flag is returned.

  loop addr n --- (compile time)
  --- (run time)
  Occurs in a colon definition in the form:
  do ... loop
  At run time, loop selectively controls branching back to the
corresponding do based on the loop index and limit.  The loop index is
incremented by one and compared to limit.  The branch back to do occurs
until the index equals or exceeds the limit.  At that time, the
parameters are discarded and execution continues after the loop.
  At compile time, loop compiles (loop) and uses addr to calculate an
offset to do.  n is used for error testing.

  machine addr1 addr2 --- Junp to the subroutine at address addr2.  The
6502 registers are loaded from the 4 bytes pointed to by addr1.  These
are in the order X,Y,A,C.  If C is non-zero, the carry flag will be set.
If C is zero, the carry flag will be cleared before calling the
subroutine.  The subroutine should return via an RTS instruction.  The
registers and flags will be returned in the 4 bytes pointed to by addr1.
The full 6502 processor flags will be returned at addr1+3, not just the
CARRY flag.  No registers need be preserved by the subroutine.  Note that
geosFORTH uses all the user pseudoregisters from $70-$7F, and $FB-$FE.

  max n1 n2 --- n3 Leaves the greater (n3) of the two numbers.

  message n --- Display "message n" to the screen.

  min n1 n2 --- n3 Leave the smaller of the two numbers.

  minus n1 --- n2 Leave the two's complement of n1.

  mod n1 n2 --- n3 Leave the remainder of n1/n2, with the same sign as
n1.

  mouseoff --- Turn off the GEOS mouse service routine.

  mouseon n1 n2 --- Turn on the GEOS mouse service routine, and position
the mouse at X pixel coordinate n1, and Y pixel coordinate n2.

  nfa pfa --- nfa Convert the parameter field address of a definition to
its name field address.

  nop --- A word which does nothing, but is sometimes useful because of
that.

  number addr --- n Convert a character string (with a leading count
byte) at addr to a signed 16 bit number, using the current numeric base.
If numeric conversion is not possible, an error message will be given.

  or n1 n2 -- n3 Leave the bit wise logical or of two 16 bit values.

  out --- addr A user variable that contains the pixel location for the
next output.  This variable is incremented by emit and set to zero by cr.
You may alter this value to control display formatting.

  over n1 n2 --- n1 n2 n1 Copy the second stack value (n1) to the top of
the stack.

  pad --- addr Leave the address of the text output buffer, which is a
fixed offset above here.

  pfa nfa --- pfa Convert the name field address of a compiled definition
to its parameter field address.

  ppl --- n Returns the current number of pixels per text line (based on
the current font value).

  prev --- addr A variable containing the address of the disk buffer most
recently referenced.  update marks this buffer to be latter written to
disk if the buffer is needed again.

  put n --- Force the write of screen number n to disk.  The update flag
will be cleared, but the buffer will still indicate that screen n is in
memory.

  query --- Accept up to 80 characters of text (until a RETURN) from the
keyboard.  Text is returned at the address contained in tib and in is set
to zero.

  quit --- Clear the return stack, stop compiliation, and return control
to the keyboard.  No message is given.

  r --- n Copy the top of the return stack to the computation stack.

  r> --- n Remove the top value from the return stack and leave it on the
computation stack.

  repeat addr n --- (compile time)
  --- (run time)
  Used within a colon definition in the form:
  begin ... while ... repeat
  At run time, repeat forces an unconditional branch back to just after
the corresponding begin.
  At compile time, repeat compiles branch and the offset from here to
addr.  n is used for error testing.

  rot n1 n2 n3 --- n2 n3 n1 Rotate the top three values on the stack,
bringing the third to the top.

  row --- addr A user variable which contains the current pixel row where
the next output character will be written.

  rows --- n A constant which returns the maximum number of pixel rows
available on the screen.

  rp!  --- The word which will initialize the return stack pointer from
the user variable r0.

  rsa --- addr A four (4) byte user variable area which can be used as a
register I/O area for a call to machine.

  scr --- addr A user variable which contains the current screen number
being interpreted.

  scroll --- This word will scroll up the C64 high res graphic screen one
text line.  The area to be scrolled is specified by the contents of the
GEOS page zero areas: windowTop ($33), windowBottom ($34), leftMargin
($35), rightMargin ($36).

  sign n1 n2 --- n2 Stores and ASCII minus sign (-) just before a
converted numeric output string in the text output buffer when n1 is
negative.  n1 is discarded, but n2 is maintained.  Must be used between
<# #>.

  smudge --- Used during word definition to toggle the "smudge bit" in a
definitions name field.  This prevents an uncompleted definition from
being found during dictionary searches until compiling is completed
without an error.

  source --- addr a user variable indicating the source of the current
input stream (0=keyboard, 1=disk buffer).

  sp!  --- Initialize the computational stack from tos.

  sp@ --- addr Returns the address of the stack position to the top of
the stack as it was before sp@ was execute.
  (e.g. 11 21 sp@ @ . . . would type 2 21 11).

  space --- Output an ASCII blank.

  spaces n --- Output n ASCII blanks.

  state --- addr A user variable containing the compilation state.  A
non-zero indicates compilation.

  swap n1 n2 --- n2 n1 Exchange the top two values on the stack.

  then addr n --- (compile time)
  An alias of endif.

  tib --- addr A user variable containing the address of the terminal
input buffer.

  toggle addr b --- Complement the contents of addr by the bit pattern b.

  tos --- n A constant which returns the initial value to use as the top
of the FORTH computational stack.

  traverse addr1 n --- addr2 Move across the variable length name field
of a word.  addr1 is the address of either the length byte or the last
letter of the name.  If n=1, the motion is toward high memory (addr1
should point to the length byte): if n=-1, the motion is toward low
memory.  addr2 is the address of the other end of the name.

  type addr count --- Output n characters from addr.

  u* u1 u2 --- u3 Leave the unsigned number product of two unsigned
numbers.

  u/ u1 u2 --- u3 u4 Leave the unsigned remainder (u3) and the unsigned
quotient (u4) from the unsigned dividend (u1) and the unsigned divisor
(u1).

  u< u1 u2 --- f Leave a true flag if the unsigned 16 bit number u1 is
less than the 16 bit unsigned number u2.

  ua --- n A constant that returns the address of the start of the user
variable area.

  until f --- (run time)
  addr n --- (compile time)
  Used within a colon definition in the form:
  begin ... until
  At run time, until controls the conditional branch back to the
corresponding begin.  If f is false, execution returns to just after
begin; if it is true, execution continues following the until.
  At compile time, until compiles 0branch and and offset from here to
addr.  n is used for error tests.

  update --- Mark the most recently referenced disk block (pointed to by
prev) as altered.  The block will subsequently be written automatically
to disk should its buffer be required for storage of a different block.

  use --- addr A user variable containing the address of the block to use
next, as the least recently read.

  user n --- A defining word used in the form:
  n user cccc
  This creates a user variable cccc.  The parameter field of cccc
contains n as a fixed offset relative to the user pointer register for
this user variable.  When cccc is later executed, it places the sum of
the offset and the user area base on the stack as the storage address of
that particular variable.  In geosForth, the user variable area is 64
bytes long.  The first 48 bytes are currently used.

  variable n --- A defining word used in the form:
  n variable cccc
  This creates a definition cccc with its parameter gfield initialized to
n.  When cccc is later executed, the address of its parameter field
(containing n) is left on the stack, so that a fetch or store may access
this location.

  vclose --- f Close the currently open GEOS VLIR file.  The flag
returned is the status flag from the GEOS close.

  vfn --- addr A sting variable which contains the name to be used by
vopen for the GEOS VLIR filename.  This is normally the source code file,
but can contain other data.  The default value is Forth Source.  There is
room to hold up to 16 characters plus a null.  The name must be null
terminated.

  vgoto n --- f Set the GEOS current VLIR record pointer to n.  The flag
returned is the status flag from the GEOS routine.

  vlist --- List the names of the definitions in the context vocabulary.
Pressing the pointer device button will stop the listing.

  voc-link --- addr A user variable containing the address of a field in
the definition of the most recently created vcoabulary.  All vocabulary
names are linked by these fields to allow control for forgeting through
multiple vocabularies.

  vocabulary --- A defining word used in the form:
  vocabulary cccc
  This creates a vocabulary definition cccc.  The subsequent use of cccc
will make it the context vacabulary which is searched first by interpret.
The sequence cccc definitions will also make cccc the current vocabulary
into which new definitions are compiled.
  cccc will be chained so as to include all definitions of the vocabulary
in which cccc is itself defined.  All vocabularies ultimately chain to
forth.  By convention, vocabulary names are to be declared immediate.

  vopen addr --- f This word opens the GEOS VLIR file whose name is
pointed to by addr.  If the file does not exist, it will be created using
an INFO Sector for a Forth Source file.  The flag returned is the normal
GEOS return from OpenRecordFile.

  while f --- (run time)
  addr1 n1 --- addr1 n1 addr2 n2 (compile time)
  Used in a colon definition in the form:
  begin ... while ... repeat
  At run time, while selects conditional execution based on the boolean
flag (f).  if f is true (non-zero), while continues execution of the
following true part through to repeat, which then branches back to begin.
If f is false (zero) execution skips to just after repeat, exiting the
structure.
  At compile time, while compiles 0branch, and leaves addr2 of the
reserved offset.  The stack values will be resolved by repeat.

  width --- addr A user variable containing the maximum number of letters
saved in the compilation of a definition's name.  It must be 1 through
31, with a default value of 31.

  word c --- Process the next text characters from the input stream
(either tib or a disk buffer), until a delimiter c is found, storing the
character string beginning at here.  word leaves the character count in
the first byte, the characters, and ends with two or more blanks.
Leading occurances of c are ignored.

  x --- This is the pseudonynm for the "null" or dictionary name of one
character of ASCII null (zero).  It is the execution proceedure to
terminate interpretation of a line of text from the terminal, or within a
disk buffer, as both buffers always have a null at the end.

  xor n1 n2 --- n3 Leave the bitwise logical exclusive or of the two
values.

  [ --- Used in a colon definition in the form:
  : xxx [ ... ] ... ;
  [ suspends compilation.  The words after [ are executed instead of
compiled.  This allows calculations or compilation execptions before
resuming compilation with ].  See literal, ].

  [compile] --- Used in a colon definition in the form:
  : xxx [compile] forth ;
  [compile] will force the compilation of an immediate word that would
otherwise execute during compilation.  The above example will select the
forth vocabulary when xxx executes, rather than selecting it at compile
time.

  ] --- Resulte compilation to the completion of a colon definition.  See
[.

  ^cl --- n Returns the usable number of characters of the current screen
editing line (the last line has only 63 usable characters since the last
character in the screen buffer must be a null).

  ^ed addr n --- This is a variation of expect except that ^ed does not
empty the buffer at addr before accepting input.  This allows you to
change the data in the buffer without retyping it.  n is the number of
input characters allowed.  Up to n+1 characters may be used.  ^ed pads
the result out to n characters by appending spaces to what was entered.

  ^el n --- Edits line n of the current source screen.

  ^es n --- A full screen edit of source screen number n (source screen n
is the same as VLIR record n).  ^es will display the contents of the
source screen as 16 rows of up to 64 characters on the screen and turn on
the mouse.  To edit one of the rows, simply position the mouse over a row
and click.  The mouse cursor will be replaced by a text cursor (at the
beginning of the line) and you may enter data.  Hitting return will put
the new information back into the screen line (see expect for the editing
characters available).  To exit ^es click the mouse cursor below the 16th
line.  Note: you can only click the mouse cursor after you are done
editing a line.

  ^il n --- Insert a blank line at line n into the current source screen.
The current line n and all following lines are shifted down one line.
The last line is discarded.

  ^is n --- Input the new source screen n.  This word uses buffer to
obtain a new buffer for the source screen, fills the buffer with spaces,
and then calls ^el for each of the 16 lines to allow you to imput source
code.  You will be presented with a text cursor for all 16 lines.

  ^la --- addr Calculate the address of the current editing line in the
current source screen buffer.

  ^ln --- addr A user variable which hold the current source screen
during editing.

  ^sn" --- Used in the form:
  ^sn" cccc"
  Used to change the name used for the VLIR file opened by vopen.  The
characters up to the next " will be placed in the variable vfn.  The
space after the ^sn" is required and is not used as part of the name.
Returns error number 6 if the name is longer than 16 characters.

  ^vs n --- View screen number n.  The screen is read in from the disk if
necessary, and then is displayed on the screen.

  geosFORTH error message numbers

  0 Word not found.
  1 Stack was empty when an item was needed.
  2 Dictionary full.
  4 New word not unique (warning only).
  5 Referenced screen is already in memory and should not be.
  6 New vfn is more than 16 characters.
  17 Use during compilation only.
  18 Use during execution only.
  19 Conditionals not paired.
  20 Definition not completed.
  21 In protected dictionary.
  22 Use only while loading.
  24 Declare vocabulary.


---------------Cut Here-------------------
-------------------------------------------------------------------------
"We know only the strong will survive, But the meek will inherit.
 So if you've got a coat of arms, oh friend, I suggest we wear it."
					John Mellencamp.
-------------------------------------------------------------------------
  anderson@c10sd3.StPaul.NCR.COM |UUCP: {rosevax, crash}!orbit!pnet51!jpa
     Joel Peter Anderson         |ARPA: crash!orbit!pnet51!jpa@nosc.mil
  NCR Comten / Software engineer |INET: jpa@pnet51.cts.com
-------------------------------------------------------------------------

bwildasi@silver.bacs.indiana.edu (Ben Wildasin) (10/26/89)

With all the geoDiscussion currently going on here on the net, I thought
it would be an ideal time to ask some questions that I have been wondering
about for quite some time. 

1. Could someone post a list of all the languages currently available to
run under GEOS? Which of these languages work in 80 columns? Of those that
don't, do they work in 40 columns in GEOS 128 or only in GEOS 64?

2. I am especially interested in Scheme (a lexically-scoped dialect of LISP).
If anyone else is interested, please post your suggestions. Maybe if there's
enough demand, someone will write one.

3. What is the chance that someone could write a virus and put it in a posted
program or one on a BBS? Is there a virus checker available for GEOS?

4. I think that all this stuff warrants creation of a comp.binaries.cbm,
comp.os.geos, comp.binaries.geos, or some other such thing. Is anyone else
interested?




*****************************************************************************
Ben Wildasin * Mail: bwildasi@silver.bacs.indiana.edu * Phone: (812) 332-0245 
*****************************************************************************
"Since there was once water on Mars, probably there is enough oxygen there to
support human life." --Dan Quayle
*****************************************************************************

anderson@ncrcce.StPaul.NCR.COM (Joel Peter Anderson) (10/26/89)

In article <28443@iuvax.cs.indiana.edu> bwildasi@silver.bacs.indiana.edu (Ben Wildasin) writes:
>
>With all the geoDiscussion currently going on here on the net, I thought
>it would be an ideal time to ask some questions that I have been wondering
>about for quite some time. 
>
>1. Could someone post a list of all the languages currently available to
>run under GEOS? 

Here is what >I< know;  I can only speak for Geos on a 64.

LANGUAGE	Implementation		Source		Comments
---------	---------------		----------	-------------
ASSEMBLER:
			Geoprogrammer 		BSW			I haven't used it
											highly regarded/macros
			GeoCope				Shareware/Qlink  Has own editor; supports
											Macros.  
			SpringBoard			Shareware/Qlink	Uses GeoWrite files; no
											macros.  Automatically
											builds Icon and header
											for Geos Appl (i.e. not for
											making DA's).  Lowest featured
											assembler, but (I found) quickest
											to use - only one I have used 
											productively.
BASIC:
			BeckerBasic			Abacus		I haven't used it
											I don't know much; requires
											large interpreter to run -
											said to be a good structured
											BASIC; INFO mag said it was
											'slower than continental drift'
FORTH:
			GeoForth			Shareware/Qlink
								Posted here, by me.
											Nice, nifty and easy mid-range
											language;  easy to interactively
											try out Geos kernal routines.
											(you want more languages? >THAT<
											is EXACTLY what Forth is good for.
											Roll-your-own!)

>2. I am especially interested in Scheme (a lexically-scoped dialect of LISP).
.... Well - see note above on FORTH -  I have read about Forth based Lisps....
maybe you could find one of those?

>
>3. What is the chance that someone could write a virus and put it in a posted
>program or one on a BBS?
No 'chance'. It happens.  Not much on '64s - but Geos moves the Operating
system from ROM to RAM >AND< uses a lot of virtual memory/disk access.  Those
two are common weaknesses exploited by Virii - now that >WE'VE< let the cat out
of the bag YEESH! why did you have to ask this question.

(ON the whole -  the Commodore 8 bit crowd is more honest, kinder and more
virtuous than the other people.... :)   )

> Is there a virus checker available for GEOS?
Not that I know about - you volunteering?

>4. I think that all this stuff warrants creation of a comp.binaries.cbm,
>comp.os.geos, comp.binaries.geos, or some other such thing. Is anyone else
>interested?
	Yes!  Ditto above - you volunteering?  I would be happy
	moderate (but can only check C64 aimed stuff (where I would prefer to
	dwell as it is the 8 bit common coin)). But I will leave the 
	organizing, vote getting and such to other more net savvy heads.



Shalom,
		Joel.

-------------------------------------------------------------------------
"We know only the strong will survive, But the meek will inherit.
 So if you've got a coat of arms, oh friend, I suggest we wear it."
					John Mellencamp.
-------------------------------------------------------------------------
  anderson@c10sd3.StPaul.NCR.COM |UUCP: {rosevax, crash}!orbit!pnet51!jpa
     Joel Peter Anderson         |ARPA: crash!orbit!pnet51!jpa@nosc.mil
  NCR Comten / Software engineer |INET: jpa@pnet51.cts.com  QLINK: JPA
-------------------------------------------------------------------------