This page (revision-22) was last changed on 03-Feb-2023 15:21 by Gromit 

This page was created on 14-Mar-2010 18:17 by Carsten Strotmann

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
22 03-Feb-2023 15:21 23 KB Gromit to previous
21 01-Feb-2011 12:53 23 KB Gromit to previous | to last

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 11 added one line
[{TableOfContents }]
At line 57 added 63 lines
!! PROCedures.
An Action! PROCedure is roughly the same as an Atari BASIC subroutine, One distinction is that it' s possible to pass arguments to an Action! PROCedure. If you've ever called a function in BASIC, then you have already used argument passing without even realizing it. In the BASIC line:
{{{
A=SIN(X)
}}}
X is the argument to the function call SIN().
The Listing 1 lines:
{{{
MoveBlock (e, P, REC)
Gen (P)
}}}
are examples of PROC calls. Note that the Action! compiler makes no distinction between user-defined PROCs and system subroutines. Thus, the PROC calls:
{{{
Graphics (24)
SetCo1or(1,8,14) : SetColor(2,8,8)
}}}
are simiiar to the BASIC statements:
{{{
GRAPHICS 24
SETCOLOR 1,8,14:SETCOLOR 2,8,8
}}}
This gives us a nice, uniform PROCedure-calling mechanism and provides an easy method for users
to provide their own versions of system routines. PROCedure declarations tell the Action! compiler
the name by which the PROC can be called, the arguments and variables which are unique to that PROC, and which statements are to be executed when the PROC is called. In our Listing 1 example, everything between:
{{{
PROC Gen (REC POIHTER r)
}}}
and
{{{
PROC Kal()
}}}
constitutes the declaration for the PROCedure
Gen().
Gen() has one argument, r, which is a POINTER
variable of type REC (a userdefined TYPE). The line:
{{{
BYTE x0, y0, x1 , y1 , ATRACT=77
}}}
declares a number of local variables that are only used in Gen(). They can not be accessed by any other PROCedure in the program (Kal() in this case). However, the global variable period (which was declared at the beginning of the program) can be used by either PROCedure.
The RETURN statement at the end of the declaration for Gen() is the same as a RETURN statement in BASIC, and causes execution to jump back to the point from which the PROCedure was called. The last procedure declared in a program is the one which will be called first when the program is started (Kal() in this example). If you don't quite follow all of this, don't worry; things should get clearer as we walk through the example.
!!Walking through.
As stated earlier, Listing 1 draws kaleidoscopic patterns on the screen. This is done by repeatedly calling the PROCedure Gen(). The Gen() statements:
{{{
r.ax = (r.ax + r.bx) ! r.bx
r.ay = (r.ay + r.by) ! r.by
}}}
generate new values for ax and ay (fields of record r, passed to the Gen() PROCedure). These values are used to calculate xO and yO as follows:
{{{
x0 = r.ax RSH 9
y0 = r.ay RSH 9
}}}
Without going into details about bit arithmetic and operations, the RSH 9 statements have the effect of
dividing r.ax and r.ay by 512 (but do it much faster than a "real" divide). The reason for dividing by 512 is to get values in the range 0-127, so that they can be plotted in graphics mode 24.