WHAT IS POGO?
Pogo is intended as a language for controlling the motion of animated
creatures. It also has turtle graphics.
To run Pogo from a command line interpreter type
pogo file.pog
To run Pogo from the Desktop double-click on POGO.TTP and then type in
the name of the Pogo program to run. If you don't use a file extension
Pogo will assume .POG. Pogo programs must be in ASCII format, with one
command per line.
You abort any Pogo program by pressing [Control]-C.
Pogo syntax resembles C more than anything else, however, it has elements
of BASIC as well.
Here is a brief description of the syntax of the language.
Comments:
Everything to the right of a semicolon on a line is disregarded.
Variables:
Variables must be declared before use. The syntax is:
type i,j,k
or
type linkcount
Type is either string or int. Ints are 16-bit integers. Strings
can be any length.
Variable names can be up to 512 bytes long or so, but only the
first 39 characters are significant. The first letter must be
alphabetic or an underbar (_). The next letters can be
alphanumeric or underbars. The case is NOT significant.
Variables declared inside a function are local to that function.
Variables declared inside a creature are local to that creature,
but their values persist between Evolve()'s of that creature.
You may not declare a variable inside a function with the same
name as a variable previously declared on a global level.
Arrays:
Arrays are declared like variables with the dimension of the array
in square brackets after the name.
int bigarray[500], littlearray[16]
Numeric Constants:
Decimal constants. No floating point.
5 100 -200
Hexidecimal constants
0x10 0xFF 0xabc
Character constants - ASCII value of character in single quotes.
'a' '*'
Numeric Expressions:
The symbols used for various binary and unary operations are
similar to C, but the precedence is a little better and
assignments are not considered an expression.
Here is a list of operators grouped by preference with the groups
in decreasing precedence.
Unary plus and minus, binary not
+5 -x ~a
Multiplication, division, modulus binary, left shift, right
shift, binary and
5*5 a/b 4%3 a<>c b&c
Addition, subtraction, binary or, xor
a+b x-5 a|b a^b
Comparison operators equal to, not equal, greater, less, etc.
a == b a!= b a > b a < b a >= b a <= b
hello == "Hi Doc!"
Logical not
!a
Logical and
a && b
Logical or
a || b
Comparison and logical operations evaluate to one for true, zero
for false (though in conditional branches any non-zero is
considered true).
For convenience the following BASIC keywords have the same effect
as the corresponding C-like tokens:
EQ and ==
= and ==
OR and ||
AND and &&
NOT and !
<> and !=
String Expressions:
A string constant enclosed in quotes
"Hello World"
A function returning a string
StrNum(100)
Two or more strings concatenated with a '+' sign
filename = "FRAME" + StrNum(i) + ".PC1"
Statements:
1. Assignment statements
var = expression
2. Compound blocks of statements surrounded by curly brackets.
{
statement1
statement2
...
}
Pogo's loop syntax allows you to use single statements within
a loop or if statement without any brackets:
if done
break
3. If statements with optional elses. The statement after the if
is executed if expression is non-zero.
if expression
statement1
else
statement2
if expression
statement
else if expression
{
statement1
statement2
}
4. Loop statements
loop
statement
(The statement following a loop is normally a compound block
with a break in it somewhere.)
loop
{
statement1
statement2
if expression
break
statement3
}
5. Break statements in loops, fors, whiles, etc..
Breaks to end of loop.
6. For statement
for var = expression to expression [step constant]
statement
for i = 0 to x
statement
for i = 100 to 50 step -5
statement
The for statement checks to make sure the index variable is in
range at the top of the loop, and adds the step at the end of the
loop.
7. while statement
while expression
statement
The statement after while is executed until expression is no
longer true.
8. Goto statements
goto label
where label is defined elsewhere (within same function) as a
name followed by a colon.
forever:
prints("Hello")
goto forever
Labels can be constructed using the same rules as variable
names.
9. int and string declaration statements as discussed in the
variables section.
int a,b,c
string filename, month, myname
10. Constant declarations
constant red = 3
This attatches a numerical value to a name without the run-time
overhead of a variable.
11. function declarations.
Function declarations begin with the keyword 'function' or 'to'.
Next is the type of variable returned by the function; int is
assumed. The name of the function follows. This uses the same
rules as variable names. Then you have a list of parameters
(separated by commas) in parenthesis. They must each be preceded
with the word string if they are string parameters.
Here are some examples.
to say_hello()
{
prints ("hello")
}
This function has no parameters and returns zero.
function add2(a,b)
{
return(a+b);
}
This function takes two integer parameters and returns an
integer value.
to string numbername(number, string name)
{
return( name + strnum(number) )
}
This function returns a string. Its first parameter is
an integer and its second parameter is a string.
12. function usages.
say_hello()
add2(5, 2*c)
13. return statements
return
or
return (expression)
If a function 'falls off the end' without a return
statement or if the return has no expression zero is
returned.
14. Creature declarations. Syntactically like function
declarations without any parameters.
creature name
{
statement
statement...
}
Function declarations and other creature declarations are not
allowed inside a creature. Neither are Evolve() calls.
Pogo Built-in Functions and Variables
Input-oriented functions:
InKey() - Returns ASCII value of key pressed, or 0 if no key
pressed.
Keyboard() - Returns 16 bit keycode or 0 if no key pressed.
WaitKey() - Waits for key and returns ASCII value.
MouseX() - Returns mouse x position.
MouseY() - Returns mouse y position.
MouseLeft() - True if left button down.
MouseRight() - True if right button down.
Clock() - Returns current time; 200Hz on ST.
UseJoystick() - to transfer from mouse mode to joystick mode.
UseMouse() - to get back to mouse
Joystick() - returns state of both joysticks. The high order byte
contains info on the right joystick, the low order byte info
on the left joystick. The hi order bit of each byte contains
the state of the fire button. The low order 4 bits contain
the state of the 4 direction switches. From lowest to
highest these are: forward, back, left, right.
The following demo is in the file JOYSTICK.POG:
int i,joy,lastjoy
usejoystick()
loop
{
joy = Joystick()
if (joy & 0x8 && !(lastjoy & 0x8) )
prints("Lefter: right")
if (joy & 0x4 && !(lastjoy & 0x4) )
prints("Lefter: left")
if (joy & 0x2 && !(lastjoy & 0x2) )
prints("Lefter: back")
if (joy & 0x1 && !(lastjoy & 0x1) )
prints("Lefter: forward")
if (joy & 0x80 && !(lastjoy & 0x80) )
prints("Lefter: fire")
if (joy & 0x800 && !(lastjoy & 0x800) )
prints("Rightly: right")
if (joy & 0x400 && !(lastjoy & 0x400) )
prints("Rightly: left")
if (joy & 0x200 && !(lastjoy & 0x200) )
prints("Rightly: back")
if (joy & 0x100 && !(lastjoy & 0x100) )
prints("Rightly: forward")
if (joy & 0x8000 && !(lastjoy & 0x8000) )
prints("Rightly: fire")
lastjoy = joy;
if (inkey())
break;
}
Text Output Functions:
Print(number)
Prints number in decimal on a line.
Prints(string)
Print string and a new line.
Text(string)
Print string without a new line.
General-Purpose Graphics Functions:
ToText()
Takes you back to character oriented screen.
ToGraphics()
Takes you into graphics mode.
PutDot(color, x, y)
Plots a single pixel in color at x, y.
GetDot(x,y)
Returns the color at x, y.
Rectangle(color, x1, y1, x2, y2)
Draws a rectangle in color with the two corners indicated.
Disk(x, y, radius, color)
Draws a solid circle.
Circle(x, y, radius, color)
Draws a hollow circle.
Gtext(color, x, y, string)
Write text in graphics mode in color at x,y position.
Gnumber(color, x, y, digits, number)
Write a number digits wide starting at x,y position.
Line(color,x1,y1,x2,y2)
Line in color between two points.
ClearScreen()
Fast set screen to 0.
SetColor(color, r, g, b)
Set hardware color register color to rgb value. r g and
b go from 0 to 255
LoadPic(filename)
Loads in picture in DEGAS Elite .PC1 format, DEGAS .PI1
format or Neochrome .NEO format (depending on the suffix
of filename).
SavePic(filename)
Save a picture in PC1, PI1 or NEO format.
Graphics-oriented constants:
ScreenW
Width of screen in pixels.
ScreenH
Height of screen in pixels.
Colors
Number of colors in palette.
CharW
Pixel width of character.
CharH
Pixel height of character.
Screen-Oriented Graphics Functions:
screen = AllocScreen()
Sets aside memory for a full screen and return an integer
handle for it.
screen = Pscreen()
Returns a handle on the physical screen.
UseScreen(screen)
Lets you draw on other screens.
CopyScreen(sscreen, dscreen)
Copies between screens.
Blit(w,h,sscreen,sx,sy,dscreen,dx,dy)
Copies a rectangular area between screens.
FreeScreen(screen)
Frees up the memory space used by screen.
Animation Display Oriented Functions:
PreSwap()
Set things up for double buffering. Set drawing pointer
off screen.
Swap()
Swap drawing and display screens.
DeSwap()
Get out of double-buffering mode. Set drawing pointer to
screen.
Vsync()
Wait for start of vertical blank.
"Turtle" Graphics. Turtle is floating point position. Not much good for
real-time, but you can do lots of LOGO tricks.
Right(degrees)
Turn turtle to the right.
Left(degrees)
Turn turtle to the left.
PenUp()
Don't leave a trail when you move turtle.
PenDown()
Start leaving lines behind turtle.
PenColor(color)
Change color of turtle's pen.
Forward(pixels)
Move turtle in the direction it's pointing.
Reverse(pixels)
Back up turtle so many pixels.
Math functions:
Random(MAX)
Returns a random number between 0 and MAX-1.
Random(100) will generate numbers 0-99
XYangle(x,y)
Returns the angle (0-360) associated with the x,y
offsets.
SquareRoot(x)
Returns square root (integer you know) of x.
Distance(x1,y1,x2,y1)
Returns distance between two points.
ArcX(angle,radius)
Gives you the x position of a ray of radius at angle.
ArcY(angle,radius)
Gives you the y position of a ray.
String-Oriented Functions:
StrNum(number)
Returns an ASCII string version of number.
StrChar(char)
Returns a string made up of the single character char.
a = StrChar('a')
StrLen(string)
Returns number of characters in string.
CharAt(string, index)
Returns character at index in string. (0 is index for 1st
character of string.)
CharTo(string, index, char)
Puts char at index in string.
NULL
Special value for string with no characters.
Text file reading functions:
f = Fopen(name, mode)
string name - the filename
mode - "w" if to write
- "r" if to read
Returns 0 if there's a problem, otherwise the file
number.
Fclose(f)
Close file and free up associated memory.
GetChar(f)
Returns a single character or -1 for EOF.
GetWord(f)
Returns next word (as separated by white space, but not
including any white space) from file f. Returns NULL at
end of file.
GetLine(f)
Returns next line of file f, including the
character(s). Returns NULL at end of file.
PutChar(f, char)
Writes a single character char to file f.
PutString(f, string)
Writes a string to a file.
PutLine(f, string)
Writes a string to a file and adds a .
CREATURE ORIENTED PROGRAMMING
Creature oriented programming is much the same thing as multi-programming
for a non-preemptive multi-tasking system, A creature is a function which
is called once every Evolve() with it's own data, as well as access to
global functions and data.
What separates a creature from a function is that local variables are
maintained between calls to Evolve(). Also each instance of a creature
has its own local variables.
Creatures have access to the Spawn variables they were created with as
cx, cy, cdx and cdy. It is recommended that animated creatures actually
use these (implicit local) variables to hold their position and speed as
they move themselves. The system doesn't actually do much with these
variables other than set aside space for them. The ClosestCreature(),
and FindDistance() calls depend on cx and cy to reflect the creature's
position.
Creature Locating Functions:
ClosestCreature(id,x,y)
Finds the closest creature to x and y with the exception
of id.
closest = ClosestCreature(cid,cx,cy)
would be how one creature could find the id of its
closest neighbor.
ClosestT(type,x,y)
Finds closest creature of a given type.
food = ClosestType(rabbit,cx,cy)
where there's a creature rabbit somewhere.
NamedCreature(name)
Finds id of some creature that has that name, or 0 if
none do.
ExistsCreature(id)
Checks if a creature with id exists. Can be used in a
loop from 1 to 255 to look at all creatures around.
Creature Information Functions:
CreatureX(id)
Returns x position of Mr. id
CreatureY(id)
Returns y position.
CreatureAge(id)
Returns age of creature #id
CreatureNewBorn(id)
True if creature is new to game.
s = CreatureName(id)
Returns creature's name string. Try
Prints(CreatureName(id))
during debugging.
value = Cread(type, var, id)
(Note: return value necessary.)
Returns value of another creatures local variable var.
Creature id is checked against type during run-time.
Cwrite(type, var, id, value)
Writes value to creature #id of type's local variable
var.
Creature life and death oriented functions:
id = Spawn(creature,x,y,dx,dy)
Make a copy of creature in the evolution table with this
initial position. Id is used to identify this particular
copy when calling the other creature oriented functions.
The values of x,y,dx and dy are passed to the creature's
local cx,cy,cdx and cdy variables.
Evolve()
Gives all the living creatures a quick run through.
Kill(id)
Kill the creature with this ID. Will cause a run-time
error if the creature doesn't exist. Kill(cid) amounts
to suicide.
KillAll()
Kill all living creatures. Especially useful when want
to restart a game.
Creature spawn parameters:
Cx -current x position. Polite to update this as you move.
Cy -current y position.
Cdx -x speed. This can be socially used for other purposes.
Cdy -y speed. Also not needed by system.
Other system-maintained local creature variables:
Cid - creature id. Unique among LIVING creatures.
Cage - evolution ticks since birth
Cnew - true only on birth tick
Cname - name of creature
Debugging Aids:
Typing ^D will stop your Pogo program and print out a stack trace.
Typing dump at the command line, e.g.
pogo warblers dump
will get a disassembly in Pogo virtual machine code interspersed
with the source it was created from. This may be interesting to
give you an idea how the Pogo compiler works.
Known Bugs
o - Using more than 8k of variable space will suddenly and silently crash
the system. No large arrays for now!
o - You can use an array name without the square brackets in an
expression with unpredictable results.