Category:Locomotive Basic: Difference between revisions
No edit summary |
No edit summary |
||
(25 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{language|Locomotive Basic |
{{language|Locomotive Basic |
||
|exec=interpreted |
|exec=interpreted |
||
|site=http://www.grimware.org/doku.php/documentations/software/locomotive.basic/ |
|site=http://www.grimware.org/doku.php/documentations/software/locomotive.basic/ |
||
|hopl=no |
|||
}} |
|||
{{implementation|BASIC}} |
{{implementation|BASIC}} |
||
'''Locomotive BASIC''' is a variant of BASIC that is built into the ROM of the [[wp:Amstrad CPC|Amstrad CPC]] series of |
'''Locomotive BASIC''' is a variant of BASIC that is built into the ROM of the [[wp:Amstrad CPC|Amstrad CPC]] series of home computers introduced in 1984. In the 1980s, the CPC was a popular, slightly more expensive alternative to the Commodore C64/C128. It was not just suited for games but also office work because of its high resolution display and [[wp:CP/M|CP/M]] support. |
||
The easiest way to use Locomotive BASIC today is [https://benchmarko.github.io/CPCBasic/cpcbasic.html CPCBasic], a very fast implementation in JavaScript which also allows easy pasting of code from Rosetta Code. Note that programs will run much faster in CPCBasic than on a real CPC. To slow down a program, add an extra delay loop to the main loop, e.g. <code>for delay=1 to 5:frame:next</code>which will pause for five frames or 0.1 seconds. |
|||
⚫ | Locomotive BASIC was comparatively advanced for its time (with e.g. software interrupts and comprehensive graphics and audio commands) and is very cleanly implemented, just like the rest of the Amstrad CPC ROM. |
||
[https://retroshowcase.gr/cpcbox-master/ CPCBox] is another option for the web browser, a whole-machine JavaScript CPC emulator mainly for games which has good compatibility but which lacks copy and paste support. |
|||
Locomotive BASIC doubles as a simple operating system for the CPC and is used (together with AMSDOS RSX commands<ref>http://www.cpcwiki.eu/index.php/RSX</ref>) for disk and tape operations. As on many other 8-bit machines of the era, BASIC programs are often extended with Z80 machine code which is <tt>READ</tt> from <tt>DATA</tt> statements, <tt>[[wp:PEEK and POKE|POKE]]</tt>-d to RAM, and then <tt>CALL</tt>-ed—an approach that was especially popular with type-in games in CPC magazines. |
|||
Locomotive BASIC can also be used via native CPC emulators such as [http://www.winape.net/ WinAPE] (Windows) or [http://sourceforge.net/projects/javacpc/ JavaCPC] (Windows/macOS/Linux). All these CPC emulators are also perfectly legal because Amstrad has given their permission for distributing CPC ROM images with emulators. |
|||
==Getting started with Locomotive BASIC== |
|||
Either use the CPCBasic browser-based Locomotive Basic emulator (https://benchmarko.github.io/CPCBasic/cpcbasic.html) or download a native CPC emulator binary for your platform. A list of emulators is available at http://cpcwiki.eu/index.php/Emulators. JavaCPC (http://sourceforge.net/projects/javacpc/) or WinAPE (http://www.winape.net/) are particularly recommended. |
|||
In CPCBasic, enter your program, e.g. |
|||
<code>10 print "Hello World!"</code> |
|||
into the "CPC Basic" text box at the top and then press the Run button below it. Output goes to the blue CPC screen below. You can also interact with the CPC screen directly if you first click on it with the mouse. The Reset button stops a running program and returns you to the Ready prompt. |
|||
In a native emulator, just type |
|||
<code>10 print "Hello World!" |
|||
run</code> |
|||
to run your first Locomotive BASIC program. |
|||
==CPC Features== |
|||
The CPC was based on a Zilog Z80 CPU running at 4 MHz and came with a built-in cassette deck (CPC 464) or 3" disk drive (CPC 664 and |
|||
6128) as storage devices and a green screen or color monitor which also housed its power supply. Amstrad CPC sales were particularly strong in the UK, Germany, France, and Spain. |
|||
⚫ | Locomotive BASIC was comparatively advanced for its time (with e.g. software interrupts and comprehensive graphics and audio commands) and is very cleanly implemented, just like the rest of the Amstrad CPC ROM. No doubt this was partly because the CPC debuted relatively late during the era of 8-bit machines, so Locomotive Software had more of an opportunity to consider the good and bad software design decisions in existing home computers. |
||
System calls are made with <tt>CALL</tt> via dedicated jump blocks in RAM, so they are unaffected by changes to the ROM between CPC models. This makes software very compatible between the original three CPC models and ''mostly'' compatible for the later, considerably less popular "Plus" models that came out in 1990. Together with AMSDOS, the '''Ams'''trad '''D'''isk '''O'''perating '''S'''ystem, Locomotive BASIC is also used for disk and tape operations. (Some commands however, e.g. <tt>disckit3</tt> for formatting disks, are only available under CP/M.) |
|||
===Screen modes=== |
|||
*mode 0: 160x200 pixels, 16 colors, 20x25 characters |
|||
*mode 1: 320x200 pixels, 4 colors, 40x25 characters |
|||
*mode 2: 640x200 pixels, 2 colors, 80x25 characters |
|||
*mode 3 (CPCBasic only!): 640x400 pixels, 16 colors, 80x50 characters |
|||
Pixels are addressed in physical units from BASIC, i.e. the center of the screen is always at 320, 200 and the top right corner is always at 639, 399, regardless of selected mode. |
|||
==Z80 Extensions== |
|||
As on many other 8-bit machines of the era, BASIC programs are often extended with [[Z80 Assembly|Z80]] machine code which is <tt>READ</tt> from <tt>DATA</tt> statements, <tt>[[wp:PEEK and POKE|POKE]]</tt>-d to RAM, and then <tt>CALL</tt>-ed—an approach that was especially popular with type-in games in CPC magazines. The CPC also has a more convenient form of BASIC extensions, RSX<ref>http://www.cpcwiki.eu/index.php/RSX</ref> commands ('''r'''esident '''s'''ystem e'''x'''tensions). They are easily recognized by being prefixed with a pipe character and have the advantage of being freely relocatable in memory. Some RSX commands, such as "|ren" to rename files, are part of the AMSDOS ROM, but RSX routines can also reside in RAM, e.g. to provide new graphics primitives or other new capabilities to BASIC. |
|||
==Memory management== |
|||
Memory on the CPC 464 and 664 is subdivided into four 16 kB blocks (0 to 3), with block 3 at &c000 normally reserved for the screen. The CPC 6128 features a second 64 kB bank (blocks 4 to 7) which can be accessed from BASIC with [[wp:Bank switching|bank switching]] in block 1 (&4000 and &7fff), e.g. |
Memory on the CPC 464 and 664 is subdivided into four 16 kB blocks (0 to 3), with block 3 at &c000 normally reserved for the screen. The CPC 6128 features a second 64 kB bank (blocks 4 to 7) which can be accessed from BASIC with [[wp:Bank switching|bank switching]] in block 1 (&4000 and &7fff), e.g. |
||
< |
<code>out &7fff,&x11000100</code> |
||
would make block 4 accessible in the address space of block 1.<ref>http://k1.dyndns.org/Vintage/Schneider%20CPC/Das%20Schneider%20CPC%20Systembuch/z87.htm</ref> This way, the entire 128 kB of memory can be used by BASIC. Alternatively, RSX commands for bank switching and copying between banks are included on the system discs and discussed in chapter 8 of the CPC user manual.<ref>http://www.cpcwiki.eu/index.php/User_Manual</ref> Even on the 64 kB models, it is possible to do [[wp:Multiple buffering|double buffering]] in BASIC by reserving another RAM block for the screen, drawing into the hidden screen, and then setting the CRTC screen address to the currently hidden screen with the BASIC [[wp:I/o port|port I/O]] command <tt>OUT</tt>. |
would make block 4 accessible in the address space of block 1.<ref>http://k1.dyndns.org/Vintage/Schneider%20CPC/Das%20Schneider%20CPC%20Systembuch/z87.htm</ref> This way, the entire 128 kB of memory can be used by BASIC. Alternatively, RSX commands for bank switching and copying between banks are included on the system discs and discussed in chapter 8 of the CPC user manual.<ref>http://www.cpcwiki.eu/index.php/User_Manual</ref> Even on the 64 kB models, it is possible to do [[wp:Multiple buffering|double buffering]] in BASIC by reserving another RAM block for the screen, drawing into the hidden screen, and then setting the CRTC screen address to the currently hidden screen with the BASIC [[wp:I/o port|port I/O]] command <tt>OUT</tt>. |
||
==Language versions and user manual== |
|||
⚫ | The extensive CPC user manual features a finely written introduction to BASIC that does not feel as rushed or dumbed-down as in some other manuals of the time. Obviously Amstrad expected many customers would want to program their CPCs themselves, not just use them with off-the-shelf software. There are even some pretty decent BASIC type-in games in appendix 3, such as clones of the arcade classics ''[[wp:Breakout (video game)|Breakout]]'' and ''[[wp:Pong|Pong]]''. |
||
Version 1.0 of Locomotive BASIC shipped with the CPC 464, later models included Locomotive Basic v1.1 which brought some important improvements. Despite the fact that all later BASIC versions call themselves v1.1, ROM headers show that e.g. the Amstrad Plus version is actually v1.40.<ref>http://www.grimware.org/doku.php/documentations/software/locomotive.basic/start#basic.1.1</ref> Amstrad CPC emulators usually default to a CPC 6128 with a color monitor and BASIC 1.1. |
Version 1.0 of Locomotive BASIC shipped with the CPC 464, later models included Locomotive Basic v1.1 which brought some important improvements. Despite the fact that all later BASIC versions call themselves v1.1, ROM headers show that e.g. the Amstrad Plus version is actually v1.40.<ref>http://www.grimware.org/doku.php/documentations/software/locomotive.basic/start#basic.1.1</ref> Amstrad CPC emulators usually default to a CPC 6128 with a color monitor and BASIC 1.1. |
||
⚫ | The extensive CPC user manual features a finely written introduction to BASIC that does not feel as rushed or dumbed-down as in some other manuals of the time. Obviously Amstrad expected many customers would want to program their CPCs themselves, not just use them with off-the-shelf software. There are even some pretty decent BASIC type-in games in appendix 3, such as clones of the arcade classics ''[[wp:Breakout (video game)|Breakout]]'' and ''[[wp:Pong|Pong]]''. |
||
==References== |
==References== |
||
Line 25: | Line 72: | ||
==See Also== |
==See Also== |
||
* |
* Locomotive BASIC documentation: |
||
** [[wp:Locomotive BASIC|Locomotive BASIC]] at Wikipedia |
|||
* [http://www.grimware.org/doku.php/documentations/software/locomotive.basic/ Locomotive BASIC command reference with code examples] (based on the official documentation) |
** [http://www.grimware.org/doku.php/documentations/software/locomotive.basic/ Locomotive BASIC command reference with code examples] (based on the official documentation) |
||
* [http://www.cpcwiki.eu/index.php/User_Manual Scanned CPC user manuals] |
** [http://www.cpcwiki.eu/index.php/User_Manual Scanned CPC user manuals] |
||
⚫ | |||
⚫ | |||
* [http://cpcbox.com/ Amstrad CPC emulator in JavaScript] (best performance in Google Chrome, but sound only works in Firefox right now) |
|||
* CPC emulators: |
|||
⚫ | |||
⚫ | |||
** [http://www.cpcwiki.eu/index.php/Emulators List of CPC emulators] |
Latest revision as of 15:24, 30 June 2024
![Language](http://static.miraheze.org/rosettacodewiki/thumb/2/27/Rcode-button-language-crushed.png/64px-Rcode-button-language-crushed.png)
This programming language may be used to instruct a computer to perform a task.
Official website |
---|
Execution method: | Interpreted |
---|---|
|
Locomotive BASIC is a variant of BASIC that is built into the ROM of the Amstrad CPC series of home computers introduced in 1984. In the 1980s, the CPC was a popular, slightly more expensive alternative to the Commodore C64/C128. It was not just suited for games but also office work because of its high resolution display and CP/M support.
The easiest way to use Locomotive BASIC today is CPCBasic, a very fast implementation in JavaScript which also allows easy pasting of code from Rosetta Code. Note that programs will run much faster in CPCBasic than on a real CPC. To slow down a program, add an extra delay loop to the main loop, e.g. for delay=1 to 5:frame:next
which will pause for five frames or 0.1 seconds.
CPCBox is another option for the web browser, a whole-machine JavaScript CPC emulator mainly for games which has good compatibility but which lacks copy and paste support.
Locomotive BASIC can also be used via native CPC emulators such as WinAPE (Windows) or JavaCPC (Windows/macOS/Linux). All these CPC emulators are also perfectly legal because Amstrad has given their permission for distributing CPC ROM images with emulators.
Getting started with Locomotive BASIC
Either use the CPCBasic browser-based Locomotive Basic emulator (https://benchmarko.github.io/CPCBasic/cpcbasic.html) or download a native CPC emulator binary for your platform. A list of emulators is available at http://cpcwiki.eu/index.php/Emulators. JavaCPC (http://sourceforge.net/projects/javacpc/) or WinAPE (http://www.winape.net/) are particularly recommended.
In CPCBasic, enter your program, e.g.
10 print "Hello World!"
into the "CPC Basic" text box at the top and then press the Run button below it. Output goes to the blue CPC screen below. You can also interact with the CPC screen directly if you first click on it with the mouse. The Reset button stops a running program and returns you to the Ready prompt.
In a native emulator, just type
10 print "Hello World!"
run
to run your first Locomotive BASIC program.
CPC Features
The CPC was based on a Zilog Z80 CPU running at 4 MHz and came with a built-in cassette deck (CPC 464) or 3" disk drive (CPC 664 and 6128) as storage devices and a green screen or color monitor which also housed its power supply. Amstrad CPC sales were particularly strong in the UK, Germany, France, and Spain.
Locomotive BASIC was comparatively advanced for its time (with e.g. software interrupts and comprehensive graphics and audio commands) and is very cleanly implemented, just like the rest of the Amstrad CPC ROM. No doubt this was partly because the CPC debuted relatively late during the era of 8-bit machines, so Locomotive Software had more of an opportunity to consider the good and bad software design decisions in existing home computers.
System calls are made with CALL via dedicated jump blocks in RAM, so they are unaffected by changes to the ROM between CPC models. This makes software very compatible between the original three CPC models and mostly compatible for the later, considerably less popular "Plus" models that came out in 1990. Together with AMSDOS, the Amstrad Disk Operating System, Locomotive BASIC is also used for disk and tape operations. (Some commands however, e.g. disckit3 for formatting disks, are only available under CP/M.)
Screen modes
- mode 0: 160x200 pixels, 16 colors, 20x25 characters
- mode 1: 320x200 pixels, 4 colors, 40x25 characters
- mode 2: 640x200 pixels, 2 colors, 80x25 characters
- mode 3 (CPCBasic only!): 640x400 pixels, 16 colors, 80x50 characters
Pixels are addressed in physical units from BASIC, i.e. the center of the screen is always at 320, 200 and the top right corner is always at 639, 399, regardless of selected mode.
Z80 Extensions
As on many other 8-bit machines of the era, BASIC programs are often extended with Z80 machine code which is READ from DATA statements, POKE-d to RAM, and then CALL-ed—an approach that was especially popular with type-in games in CPC magazines. The CPC also has a more convenient form of BASIC extensions, RSX[1] commands (resident system extensions). They are easily recognized by being prefixed with a pipe character and have the advantage of being freely relocatable in memory. Some RSX commands, such as "|ren" to rename files, are part of the AMSDOS ROM, but RSX routines can also reside in RAM, e.g. to provide new graphics primitives or other new capabilities to BASIC.
Memory management
Memory on the CPC 464 and 664 is subdivided into four 16 kB blocks (0 to 3), with block 3 at &c000 normally reserved for the screen. The CPC 6128 features a second 64 kB bank (blocks 4 to 7) which can be accessed from BASIC with bank switching in block 1 (&4000 and &7fff), e.g.
out &7fff,&x11000100
would make block 4 accessible in the address space of block 1.[2] This way, the entire 128 kB of memory can be used by BASIC. Alternatively, RSX commands for bank switching and copying between banks are included on the system discs and discussed in chapter 8 of the CPC user manual.[3] Even on the 64 kB models, it is possible to do double buffering in BASIC by reserving another RAM block for the screen, drawing into the hidden screen, and then setting the CRTC screen address to the currently hidden screen with the BASIC port I/O command OUT.
Language versions and user manual
Version 1.0 of Locomotive BASIC shipped with the CPC 464, later models included Locomotive Basic v1.1 which brought some important improvements. Despite the fact that all later BASIC versions call themselves v1.1, ROM headers show that e.g. the Amstrad Plus version is actually v1.40.[4] Amstrad CPC emulators usually default to a CPC 6128 with a color monitor and BASIC 1.1.
The extensive CPC user manual features a finely written introduction to BASIC that does not feel as rushed or dumbed-down as in some other manuals of the time. Obviously Amstrad expected many customers would want to program their CPCs themselves, not just use them with off-the-shelf software. There are even some pretty decent BASIC type-in games in appendix 3, such as clones of the arcade classics Breakout and Pong.
References
See Also
- Locomotive BASIC documentation:
- Locomotive BASIC at Wikipedia
- Locomotive BASIC command reference with code examples (based on the official documentation)
- Scanned CPC user manuals
- Locomotive BASIC at the Amstrad CPC Wiki
- CPC emulators:
Subcategories
This category has the following 3 subcategories, out of 3 total.
@
- Locomotive Basic Implementations (empty)
- Locomotive Basic User (4 P)
Pages in category "Locomotive Basic"
The following 73 pages are in this category, out of 73 total.