ScuzzBlog: Diaries December 2020
Entry 14th December 2020: Post 1: AmigaBASIC - Are we CLEAR.
AmigaBASIC - Are we CLEAR.
Today I field a question posed about changing the 'STACK' size of
an AmigaBASIC program so that a very large program can be used.
AmigaBASIC first found favour on the Amiga 1000 and was supplied
by a company called MetaCompo but labelled under the Commodore
label. It was later replaced with Microsoft BASIC for the Amiga.
Important that you know which version you have. Please note that
AmigaBASIC was removed from the Workbench with 2.x and so really
we are only focussing on 1.2 and 1.3 predominantly. Also note that
the original version was called ABasic.
The Stack: Man I have grown weary of the term.
01: The ToolType Icon Info Stack is normally set at 4096. Some have
suggested changing the figure. I am doubtful that will help as this
deals with temporary storage for program variables and functions that
are constantly changing. I wait to be corrected.
I always thought the icon STACK was for temporary storage with the
program itself allocating the memory requirements for the application.
I had read that the temp storage literally calls in function
data etc and pops it out on completion. I didn't think it was the
whole program storage area. It seems that most tools/applications
on the Amiga are 4096 irrespective of the program size. Looking
at the opening screen AmigaBASIC allocates 25000 bytes for the
program. Dunno
02: CLI stack can be modifies but this relates to the SHELL only and
has nothing to do with AmigaBASIC.
03: The stack parameter set within BASIC. Now I think that this is
the variable we are discussing. More importantly the command CLEAR.
Please note that I photographed a very thick book to show this
function. I was in no mood to split the spine on the book by placing
the book flat in a scanner. So sorry.. 'buck up'. It's all you are
going to get in written form.
To the command that I think determines the STACK size.
[What I read ]
The program itself allocates the default setting for the memory
it uses and only the CLEAR command can adjust the BASICdata Area
and the System Stack. Each must be 1024 bytes or greater.
Memory Management.
When running a BASIC program, the amount of memory you have available
is divided into three distinct areas. These contain the 'stack' the
'heap' and the 'BASIC data'. These terms are explained below. The
amount of memory assigned to each can be changed using the CLEAR
command.
CLEAR used on its own erases all variables and arrays and closes
any open files. In addition, it can be given one or two arguments
which allocate space for the BASICdata and stack respectively.
For example
#CLEAR, 50000,1024
This allocates 50000 bytes for the BASIC data area and 1024 bytes
for the stack. All the remaining memory is made available to the
heap. The smallest value which can be assigned using CLEAR is 1024
bytes. NOTE: The default values are 25000 bytes and 4789 bytes
respectively.
The Stack is used internally by BASIC to hold information about
the flow of control of a program. For example whenever BASIC encounters
a GOSUB, function call or subprogram call, it has to remember its
current position in the program so that it can return to the correct
place after executing the appropriate body of code. This information
is stored on the stack. Similar situations arise in the case of
loops. The address of the start of each loop has to be stored so
that when the end of the loop is reached, BASIC knows where to jump
back to.
This means that the amount of stack space required depends on how
deeply you nest structures. It is INDEPENDENT of the size of the
program or the number of independent structures the program contains.
CLEAR:
CLEAR can specify an amount of memory to be allocated to the Amiga
BASIC data area and to the system stack. This is used to change
default values, for example, when you want to use less of the
default space allocated for graphics and more for numeric data.
CLEAR, BASICdata, stack
[ end quote ]
CHAIN Format: CHAIN [MERGE] filename [,line-number] [,ALL[ ,DELETE
range]]] Purpose: To load or merge and execute another program file
into memory. Options: MERGE = Merge the new program with the existing
program into memory. Line-number = This will specify where the
program will start execution from. ALL = All global variable are
available to the called program. DELETE = Remove a range of lines
from the calling program. Example: CHAIN MERGE "myprogram2"
MERGE Format: MERGE "filename" Purpose: To append lines from from
program file to the program in memory. The merged program must have
been saved in ASCII format using the A option with the SAVE command.
Input: filename = Name of file to merge in. Example: MERGE
"Extrafunctions"
CLEAR Format: CLEAR [,basicData] [,stack] Purpose: Clears all
variables, closes files and allocates memory for basic Data area
and the stack. Input: basicData = Amount of memory for text,
variable, string and file data (1024 bytes or more), stack = Amount
of memory for system stack (1024 bytes or more).
Example: CLEAR ,,4096
For my part without the actual program to play with and interrogate
it is difficult for me to get my head round what the specific issue
is. If that STACK variable on the icon fixes things then it would
be good to know. Problem solved as it were. However having read a
lot these last few days on memory management for AmigaBASIC I have
never yet come across any reference to changing the ToolType Icon
Stack. I guess I could try something out myself and see how I get
on. Not an expert on AmigaBASIC but would be good to know how this
works.
Anyhoo .... like I said in an earlier post my only way round using
large programs was to use CHAIN and MERGE commands and break the
thing down into workable chunks.
AmigaBasic always appears to use the same amount of memory allocation.
In days of old I would merge and chain programs by removing all
the lines and just saving the variables. It seems you can save in
ascii one part and then merging with another. You would have to
sift your code for how you did it.
AmigaBASIC - Are we CLEAR.
|