Changes

Jump to: navigation, search

Technical information about Locomotive BASIC

1,314 bytes added, 10:58, 13 July 2019
[[Category:Cpctech.org]]
'''''This artikel article originally came from Kevin Thackers' archive at [http://www.cpctech.org.uk http://www.cpctech.org.uk].'''''
= Technical information about Locomotive BASIC =
The are two versions of Locomotive BASIC used in the Amstrad CPC and CPC+ computers. v1.0 is used by the CPC464, and v1.1 is used by the CPC664, CPC6128, CPC464+ and CPC6128+.
 
== BASIC v1.0 only ==
 
There is a region of memory between AC00-AC1B which is filled with RET instructions. The BASIC ROM calls the following locations:
AC01,AC04,AC07,AC0A,AC0D,AC10,AC13,AC16,AC19
 
It almost looks like these were used for debugging the ROM but were left in.
 
They can be used to implement new BASIC commands.
== Passing parameters to a RSX (Resident System Extension) command or binary function ==
A RSX (Resident System Extension) command is accessed through BASIC with a "|" character prefix. e.g. The "DIR" RSX, is accessed by "|DIR". A binary function is accessed through BASIC using the "CALL" command.
Both RSX and CALL commands works work (are!) similar from the BASIC command line and invokes a invoke machine code - the only difference is: with the help of a RSX command you don't need to know the exact access address. You can pass up to 32 parameters with a CALL or RSX command. Possible parameters could be integer, floating points and strings. Just store the parameter into a variable:
Passing for integer:
<pre>
...
MSB PARAMn
IX+2 0 ------> LSB PARAMn
</pre>
with the help of that assembly code is it possible to find the parameters:
<pre>
ROUT1: CP "x" ;test register A if "x" parameters were hand-overedgiven, e.g. "x" = 2 RET NZ ; if no > failure and returnnot exactly x parameters then do not execute RSX. LD L,(IX+20) LD H,(IX+31) ; HL = value of last parameter LD E,(IX+42) LD D,(IX+53) ; DE = value of next to last parameter
...
</pre>
A register holds the number of parameters. IX points to each parameter. IX+0/IX+1 is the last parameter. This happens because each parameter in order is pushed onto the stack and IX then points to the last parameter pushed. Each parameter is a 16-bit value.
If a parameter is a string, then IX holds the 16-bit value is an address of a "the string descriptor which point to a 3 byte block". The first byte of the string description or descriptor is the length. The next 2 bytes are an address that point to the string in memory.
With the help of the variable container "@" it is also possible to get a result from an invoked mc-code back to basic.
In this case the param parameter contains the address of the integer, floating point or string. You can modify these to give the result.
BASIC allocates the strings, so when you modify a string, do not write more characters than the original string.
<br> <br>
== Entering BASIC programs ==
A maximum of 255 characters can be entered for a single BASIC line.
There are some rules for assigning names for variables:
: - it is not allowed to define a variable starting with a figure (the system expect then programming mode and interpret it as a programm program line number)
: - no space (or 'under' as it is common today) between variable names are allowed
: - BASIC keywords can't be used
: - Use variables instead of constants. A constand has always to be converted in a binary/digital format. A variable is already converted.
: - Dimensioning at the beginning of the program
: - Dimensioning your variables & pre-calculate
: - Avoid AND/OR/XOR in IF-THEN statements. It's faster to write IF ... THEN (statement 1).. IF ... THEN (statement 2).
== Structure of a BASIC program ==
| INPUT
|-
| &amp;a4
| KEY
|-
|-
| &amp;b5
| ON SQ
|-
| &amp;b6
|}
*This token identifies a integer (16-bit) number. The two bytes following this token is the number, stored low byte then high byte. e.g. &amp;191a,&amp;2d,&amp;00 represents the integer number "&amp;002d"="45".
*This token (&amp;0B) is changed at run-time to &amp;0D
*This token identifies a integer variable. 02,00,00,var name offset to number in program setup when program RUN. The variable name is stored directly, with bit 7 of the last character set.
* When a REM or ' is seen, the characters following it are output directly (i.e. the bytes are not tokenized) until the end of line or a ':' is seen.
 
* When a BASIC program is listed each line is converted to a string (this includes the line number and the tokens converted to their strings). There is a maximum length for this string of 256 characters. This means that if the BASIC line is LISTed or EDITed, then the line will be displayed incorrectly with missing characters on the end. This is also noticed if you have a "10-liner" program that packs as much BASIC as possible into each line and renumber it so the line number has more digits.
== Floating Point data definition ==
#**A string variable can store a minimum of 0 characters and a maximum of 255 characters.
#**The length of the string in characters is defined in the string descriptor block. The string does not have a termination character.
 
[[Category:Programming]]
[[Category:BASIC| ]]
[[Category:CPC Internal Components]]
[[Category:Operating System| ]]
[[Category:Software]]
[[Category:Programming software| ]]
2,541
edits