This is only a preview of the February 2020 issue of Practical Electronics. You can view 0 of the 80 pages in the full issue. Articles in this series:
|
Colour Maximite Computer
Part 4
Words: Phil Boyce
Design: Geoff Graham
A retro 80s home computer with modern-day features
Graphics capabilities, demo programs and hardware control
I
n Part 3, we covered the three
Maximite modes: Immediate, Editor, and Run (and how to switch
between them) allowing you to test
commands, enter code, or run a program. We also showed how to save
and load a program from the SD card
– this included running the game Donut Dilemma, which demonstrated
just how versatile MMBASIC really
is. In this final part of the project we
will work through a number of other
demo programs; some will show the
graphics capabilities of the Colour
Maximite Computer, and others will
challenge you, with some fun thrown
in! We will finish by explaining how
to access the GPIO pins to control external hardware, with a quick practical project: the Maximite Mood Light.
The topics covered this month are deliberately kept at a high level because we
want you to explore your Colour Maximite Computer. Do download the User
Manual (http://geoffg.net/maximite.
html) – it contains extra detail and useful examples of hardware interfacing.
This month’s download
There are many programs that we will
be referencing and using in this final
part of the Colour Maximite Computer
project, so this month’s download contains more files than usual. Start by
downloading the CMC_DemoPrograms
folder from the February 2020 page of
the PE website. Unzip the folder, and
then copy the contents (comprising
multiple files and directories) directly
42
onto your SD card. Next, power up your
Maximite, insert your SD card, and you
will see the usual flashing cursor (command prompt) meaning that the Maximite is in Immediate mode and waiting
for a command to be entered. To check
that your SD card has been prepared
correctly, type FILES (Enter) and you
should see a list of folders (shown as a
list of <DIR> folder_name) followed
by a list of files (.bas, .fnt, .spr,
.mod, .txt) listed alphabetically. If
you don’t see this, then make sure you
correct things before proceeding.
At various points throughout this article, we will reference a specific program
(by filename) that you need to run. Before you run the program you will first
need to locate the appropriate .bas file
(the .bas extension means program
code). There are two possible scenarios:
1. It is in the initial FILES list when
you first power up the Colour Maximite Computer – think of this as
the ‘root folder’
2. It is in a dedicated folder (<DIR>)
which has a folder name similar to
the filename (more on this shortly).
Taking these two scenarios in turn:
1. Some programs will comprise just a
.bas file. These are typically found
in the root folder – try it now by typing FILES (Enter) and check that
you can see MODES.BAS
2. Several of the demo programs require extra support files such as
sprites (.spr), bitmaps (.bmp), fonts
(.fnt), and/or sounds (.mod) – this is
in addition to the .bas file. To keep
things tidy, these multi-file programs
have all of the required files inside
their own dedicated folder (shown
as <DIR> folder_name when you
type FILES in the root folder). So in
order to locate the .bas file for a multi-file program, you will first need to
switch to the relevant folder with the
change-directory command, CHDIR
folder_name (as we did last month
when running the Donut Dilemma
game from the DONUT folder). Typing
FILES (Enter) shows you all the files
that make up the multi-file program.
To return back to the root folder, type
CHDIR .. (Enter). In effect, this goes
up a folder level. An alternative is to
simply reset the Maximite (power off,
then back on) – by default, the root
folder is always accessed first.
Once you have located the relevant
.bas file, you could run the program by
typing (at the command prompt) LOAD
"filename.bas" (Enter), and then RUN
(Enter). However, MMBASIC lets you
shorten this by typing RUN filename
(Enter). Note that the double quotes
around the filename can be omitted, as
well as the .bas file extension.
Please note that some programs will
use screen MODE 4 (240 × 216 pixels)
and/or different-sized font characters.
This can mean that when you stop the
program and return to the command
prompt (Ctrl-C), the characters that
appear on the screen will be much
bigger than normal. Typing MODE 3
Practical Electronics | February | 2020
(Enter) will generally return the characters to normal size – alternatively,
reset the Maximite by temporarily removing power (or by typing WATCHDOG
1 to reset the processor).
All this may seem a bit confusing at
first, but all we’re doing here is keeping
things tidy on the SD card. After running the first few programs from this
month’s article, things will become very
straightforward – I promise!
Graphics capabilities
We’ve already explored some of the
easier graphics commands in the User
Manual, but do have a play with the
commands CLS, PIXEL, LINE, and
CIRCLE directly from the command
prompt (for starters, just try something
as simple as CLS RED). There are many
more graphical features that are available on the Maximite, so let’s begin
by working through four of the demo
programs to see some of these features.
Graphics
The Graphics.bas program is located in the root folder – run it with RUN
Graphics.BAS (Enter). It demonstrates the speed of various Maximite
graphics commands. It works through
PIXEL, LINE and CIRCLE commands,
and finishes with some nice animations
using the BLIT command. Press any key
to progress through the demonstration.
As with all the programs, we recommend you look at the code to see how
various commands are used.
C16
Modes
The Modes.bas program (in root)
nicely demonstrates the four different
screen modes available on the Maximite
Practical Electronics | February | 2020
by showing them all simultaneously on
one screen. The different modes allow
you to balance speed, resolution, colour
range and memory usage, as explained
in the User Manual. For high-resolution
(along with access to all eight colours),
you would use MODE 3. For games,
MODE 4 is recommended as the bigger
pixels are processed faster, meaning onscreen objects move quicker – examine
the code to see how different elements
are drawn. More importantly, play with
the code to alter effects using the User
Manual to guide you. (To be clear, we
are referring to screen modes here – not
the Maximite’s three modes: Immediate,
Editor, or Run.)
BlitDemo
BlitDemo.bas is a multi-file program,
so first type CHDIR BlitDemo (Enter)
and then RUN BlitDemo (Enter). To
stop the program, press Ctrl-C. This
will return you to the command prompt,
with the SD card access still pointing
to the BlitDemo folder (you can see this
by typing FILES (Enter), after which
you will see all the files that BlitDemo.bas uses). To return to the main
folder on the SD card, type CHDIR ..
(Enter). Typing FILES (Enter) will
again show a list of all the demo programs / directories ready for you to try
the next program. Follow this process
for all multi-file demo programs.
BlitDemo shows how some fantastic
animation effects can be generated by
using the BLIT command. Check out
the colour mixing in the lower right
corner. Why not try changing the colour of the ‘scrolling waveform’ to ensure you understand how the BLIT
command works. (This program runs
in MODE 3.)
SprtDemo
This is another multi-file program. SprtDemo shows how sprites (blocks of pixels) can be drawn on the screen without
affecting the background. In this demo,
little ‘Pacman ghosts’ wander over a
bitmap (.bmp) image of a well-known
landscape. See if you can change the
background to one of your own – hint:
use something like Microsoft Paint to
save a .bmp file with the appropriate
pixel resolution and colour depth.
These four graphics demonstrations
have shown you something new, and
given you a chance to explore code and
make changes. If you mess something
up, simply re-copy the original program
onto the SD card.
Further demo programs
Now take some time to try some of the
other demo programs. One of the great
things with MMBASIC is that it is easy
to customise the code to suit your own
requirements. Remember, all programs
are written in BASIC – there is absolutely no machine code or complex C code!
There are actually more programs in the
download folder than shown here in the
screenshots, so do be sure to try them
all out. As you have just seen, some programs nicely demonstrate how to use the
Maximite’s graphical commands, while
other programs provide some mind challenges; for example, Tetris, Checkers,
and Four-in-a-row. Plus, there’s a handful of action games, some that you can
play straight away, and others requiring
you to build a simple hardware controller (comprising a potentiometer and
a button). Remember, the Maximite is
easy to hook up to external hardware,
and these particular games demonstrate
the interaction between hardware and
software in a fun way.
Important note: if a multi-file program
uses any .mod sound files then you
may have to perform a manual process
before the program will run correctly –
see next section!
All of the programs in the download
folder have been collated from various
authors around the world and we thank
them all for making their code publically available. In some cases, the code
has been written from scratch, specifically for the Maximite, whereas other
programs are simply conversions of old
BASIC code that was originally written
for 80s home computers such as the BBC
micro. If you look at the code, you will
see that some incorporate line numbers.
This raises an important point worth
stressing – you can literally take any
old BASIC program (with or without
43
FileMngr.bas – A simple file explorer utility.
You use the arrow keys to navigate to a
.bas program file (or a folder), and then
press Enter to launch the program (or
open a folder).
Julia.bas – Generates a colourful image
that is mathematically similar to the
famous Mandelbrot set. Be patient, it
takes about 15 minutes to completely
generate the image.
MoonLand.bas – Use the arrow keys to
land your spacecraft on the landing pad.
Ensure you land as gently as possible by
minimising the speed. (Multi-file program –
manually copy .mod files).
HighIQ.bas – This version of the classic
Solitaire game challenges you to remove all
but one of the 32 counters. You can jump
either horizontally or vertically by entering
the grid reference numbers.
Checkers.bas – This is another variation
of solitaire, and is similar to HighIQ.
However, in this version you can only jump
in a diagonal direction, and there are more
counters to remove.
Sudoku.bas – Challenge yourself to this
popular number puzzle. Try to populate the
empty squares with digits 1-9 so that no
digit is repeated in a row, column, or 3×3
cell. Three difficulty levels await.
line numbers), and migrate the code
to MMBASIC without too much effort.
Drive B is the only other ‘drive’ on the
Maximite, and this refers to the SD card
itself. Drive B is the default drive when
the Maximite is powered on (or reset).
you (in code). The MUSIC demo program
is a good example of this (it automatically copied T1.mod, T2.mod, and T3.mod
into Drive A). However, other programs
require you to copy the files manually.
To understand if you need to copy the
files yourself, just run the program, and
see if an error message like ‘PlayMOD
Error: Cannot find file’ appears – if so,
you will need to do transfers manually.
We will now work through the process
involved by using the MoonLand demo
program (which has three .mod files that
need copying to Drive A).
Begin by pointing to the MoonLand
folder by typing CHDIR MoonLand (Enter), and then list the .mod files with
FILES (Enter). Before we go any further, lets see the error message generated
when the .mod files are missing from
Drive A. Type RUN MoonLand (Enter),
and press any key to start the game (you
will then see a screen similar to the above
screenshot). Press the UP arrow key and
you will see an error message as the
program is trying to play the ‘missing’
turbine.mod sound file. You will see
large characters on the screen – so type
MODE 3 (Enter) to return to normal size
characters (ignoring any error message).
Now type FILES (Enter) and you will
.mod sound files
Playback of a .mod sound file results
in very impressive sound, as witnessed
back in Part 2 when you tested your
Maximite with the MUSIC demo. However, for the Maximite to be able to
perform this task in the background,
the data in a .mod sound file needs to
be accessed very quickly by the PIC
processor. Reading the .mod data directly from the .mod file on the SD
card is just too slow, hence the .mod
file needs to reside in (ie, copied to) the
PIC’s ultra-fast memory. However, the
amount of ultra-fast memory available
is very limited, so if there are any existing .mod files from a previous program,
then these files need to be deleted from
the fast memory first to make space for
new sound files. Otherwise, you will
likely see an ‘out of memory’ message.
The memory space where .mod files
need to be placed is referred to as ‘Drive
A’. To access this, type DRIVE A (Enter)
and then type FILES (Enter) to see if
any files are currently there. Note that the
number of files, and the number of ‘bytes
free’ are displayed. For completeness,
44
Deleting .mod files
To delete a file from Drive A, use the
KILL "filename" command (this causes the screen to blank temporarily). To
gain the maximum possible space in
Drive A for new files, the KILL command should ideally be repeated to delete each file until there are none left.
You can check how many files are left
by typing FILES (Enter) at any time.
If you have been following this project,
and if you successfully ran the MUSIC
demo, then you will likely see T1.mod,
T2.mod, and T3.mod listed. You should
now delete these files to free up space.
When no files are left, type DRIVE B
to point back to the SD card (and then
type FILES (Enter) to list the files and
folders (<DIR>) stored on the SD card).
Installing .mod files
Once we have space in Drive A for new
.mod files, we now potentially need to
copy the files from the SD card to Drive
A. ‘Potentially’, because some programs
will actually do this automatically for
Practical Electronics | February | 2020
FourRow.bas – The classic four-in-a-row
program; in this version you play against the
Maximite. Use the < and > keys to select
a column, and then drop your counter by
pressing the spacebar.
MaxiTrek.bas – A retro game in which
you travel the galaxy. You mission is to
destroy the fleet of Arduitrons that have
attacked your planet. Press I to see the
keyboard controls.
MaxiTrek – Pressing M displays a map
of the galaxy. Navigate to different parts
in order to attack the enemy. (The code
automatically copies the .mod file into Drive
A (and renames it title.mod)).
Breakout.bas – This game is a variation
of the classic breakout game but with a
difference – you need to build a game
controller! Details are provided at the start
of the program code.
Arcade.bas – An arcade-style game
in which you need to shoot the enemy.
Requires a DIY controller (potentiometer
and button – see start of code for details).
(Copy the two .mod files to Drive A).
Invaders.bas – A copy of the classic Space
Invaders game. This also requires the DIY
controller (potentiometer and button – see
start of code for details). (Copy the two
.mod files to Drive A).
see that the Maximite is pointing to Drive
A (probably containing 0 files) – this
is because the program crashed while
trying to locate the turbine.mod file
which needs to be in Drive A.
So point the Maximite back to Drive
B with DRIVE B (Enter), and then type
FILES to list the files in the MoonLand
folder. Next, use the COPY "source"
TO "destination" command on each
.mod file. Start with COPY "explode.
mod" TO "A:explode.mod" (Enter).
(The screen will go blank temporarily
while the file is copied.) Copy the other
two files with COPY "landed.mod" TO
"A:landed.mod" (Enter) and COPY
"turbine.mod" TO "A:turbine.
mod" (Enter). Use KILL to delete any
misspelt file names. When all three
.mod files have been copied into Drive
A correctly, type DRIVE B (Enter) to
point back to the SD card. You can now
type RUN MoonLand to play the game
and this time you will not see the error message).
Note: After running a multi-file program, ensure that you’re pointing to
Drive B (SD card) and not Drive A (fast
Maximite memory). To do this, use the
command DRIVE B (Enter). Then use
CHDIR .. to go up a level to see all
the other demo programs, and folders
(<DIR>) in the root folder.
The above topic has been discussed
in detail since several of the demo programs use .mod sound files and the program won’t run properly if there is not
enough space in Drive A for the .mod
files. In summary, there are possibly two
tasks that need to be performed – clear
space in Drive A, then (potentially) copy
the .mod file(s) manually into Drive A.
Once you have done this a couple of
times, it will become second nature!
Now it’s time for you to explore
the other demo programs. Remember,
there are more programs contained
on the SD card than are shown here
as screenshots.
end the Colour Maximite Computer
project with an example of software
controlling some externally connected
hardware. The example is based on
the Blinkt! RGB LED module featured
in this month’s Make it with Micromite (MIWM), and we’ll use the SPI
command to control eight ultra-bright
RGB LEDs.
Before we start, please refer to Fig.2
in MIWM Part 2 (PE, December 2019)
to see how to build a simple logic probe
comprising an LED, 470Ω resistor, and
some jumper leads. Next, assemble this
simple (and useful) test device. You can
check it works correctly by inserting
the test probe onto either 5V or 3.3V
(and the LEDs cathode to GND) – if
the LED lights then all is good. If the
LED does not light up, then first check
the LEDs polarity, and also check the
resistor is the correct value (or between
270Ω and 1kΩ).
Practical Electronics | February | 2020
GPIO hardware control
As we have often said, it is very easy
to interface external hardware with the
Colour Maximite Computer. The User
Manual provides various examples on
the commands used (especially SETPIN and PIN) so we won’t repeat that
information here. Instead, we will explain how you address the 40 available
I/O pins (20 external on the rear-panel
connector, and 20 internal on an Arduino footprint connectors). We will
The rear-panel connector
At the back of the Colour Maximite
Computer, there is a centrally mounted 26-way connector. This connector
makes 20 GPIO pins available, along
with GND, 3.3V and 5V power outputs. The pinout is shown in Fig.1
45
5
19
20
8
17
18
7
15
16
10
9
13
14
G n d
3
6
11
G n d
4
1
G n d
3 .3 V
G n d
5 V
2
12
Fig.1. The pinout for the 26-way connector
on the rear panel (as viewed outside box). It
provides 20 GPIO pins (numbered 1 to 20)
and also 3.3V and 5V power for powering
external hardware.
(as viewed when looking at the rear
panel). The numbers in orange boxes
are the pin numbers that are used to
reference these twenty GPIO pins. If
we connect the LED test probe to Pin 1
(the third pin along from top left) and
the other end to GND, then to be able
to control the LED with software, we
would first need to configure Pin 1 as
a digital output (DOUT) by using the
command SETPIN(1),DOUT. Then,
to turn the test LED on (set Pin 1 to
a high logic level), you would use
PIN(1)=1. Likewise, to turn it off,
use PIN(1)=0. Use the test probe to
confirm this works as expected.
The Arduino connector
Inside the case, you will see two 6-way,
and two 8-way sockets that make up the
Arduino footprint connector. Alongside
each socket you will see the Arduino pin
references highlighted on the silkscreen.
This is shown in Fig.2, along with the
pin numbers that are used to reference
these twenty GPIO pins. If we were to
connect the test probe to the lower left
socket (marked D0), then in order to use
software to control the LED we would
first configure pin D0 (pin 21) as a digital
output with SETPIN (21),DOUT. Note
that with the Arduino pins we can also
reference the pins by the silkscreen
A 5
V IN
G N D
G N D
5 V
3 .3 V
R E S
A 0
27
26
28
29
31
D 9
D 1 0
D 1 1
D 1 2
D 1 3
G N D
25
24
D 8
D 5
23
35
D 4
D 3
D 2
D 1
D 0
21
22
36
37
D 7
38
39
D 6
40
A 1
A 2
A 3
A 4
A 5
A 4
30
33
32
34
Fig.2. The pinout for the 20 GPIO pins
available on the internal Arduino connector.
These pins are numbered 21 to 40, and can
also be referenced by the ‘Arduino name’
(D0-D13, A0-A5).
46
legend – so SETPIN(D0),DOUT will
perform exactly the same result. Then
to turn the LED on, simply use either
PIN(21)=1 or PIN(D0)=1. Likewise,
to turn it off, use either PIN(21)=0 or
PIN(D0)=0. Once again, go ahead and
check that both these pin references
work as expected to control the test LED.
Now that we know how to address the
40 available GPIO pins (and where they
are physically located), we next need to
explain that some pins perform specific
or special tasks. These pins (and their
functions) are:
Pin 12 = I2C Data (SDA) and IR receiver
Pin 13 = I2C Clock (SCL)
Pin 15 = COM1 Rx
Pin 16 = COM1 Tx
Pin 17 = COM1 RTS
Pin 18 = COM1 CTS
Pin D0/21 = COM2 Rx
Pin D1/22 = COM2 Tx
SPI and one-wire can use any digital I/O
pin – the pin numbers are specified in
the relevant MMBASIC command (as
commented in the SPI example below).
We recommend you work through
some of the examples in the User Manual to get used to how to control hardware. And for readers following the
Make it with Micromite (MIWM) series:
a lot of the topics and projects covered
in that series can be migrated to the Colour Maximite Computer with minimal
change. However, there are two important points that need to be highlighted:
1. The Colour Maximite Computer is
based on a 100-pin PIC micro-controller, whereas the Micromite is based
on a 28-pin PIC. Therefore, the pin
numbers quoted in the MIWM series will not apply to the Maximite.
Instead, any external hardware will
need to be connected to the appropriate Maximite pins. The MIWM code
then simply needs to be updated (to
reflect the new pin numbers) before
it will run properly on the Maximite.
This is much easier than it sounds.
2. MMBASIC can only connect to a single display. Since the Maximite has
a dedicated VGA monitor for its ‘display’, no other external display can be
added. Therefore, any program code
for MIWM projects that incorporate
the IPS display (or any other display)
will need to be modified to write and
draw to the VGA monitor instead.
This will generally mean having to
use different commands and/or parameters for the graphical commands.
Have a look at the MIWM series and
convert some of the projects to run on
your Maximite. To help you get started,
let’s modify parts of the Mood Light from
this month’s article and control the RGB
LEDs from the Maximite.
Fig.3. The Maximite Mood Light is built
around the Blinkt! module (see page 67) and
is connected to the rear-panel connector
via a short ribbon cable. A suitable adaptor
board keeps everything tidy.
Maximite Mood Light!
Here’s a practical example, explaining
how to connect a Blinkt! module to the
Maximite and control it with a small
program. We won’t repeat the Blinkt!
operational details other than to say
that we need four connections – 0V, 5V,
SPI Data, and SPI Clock. Do read this
months MIWM article to understand
the SPI data that we need to send to the
Blinkt! to control LED brightness and
colour. We can connect the Blinkt! to
the Maximite’s rear-mounted connector by using a short ribbon cable, and a
breadboard to keep everything tidy. To
make it easier to connect hardware to
the rear-mounted connector, we recommend the use of a T-Cobbler module.
The T-Cobbler simply allows a ribbon
cable to be plugged into a breadboard.
An alternative to the T-cobbler is something like that shown in Fig.3.
The four pins we need to connect
to on the Blinkt! are shown in MIMW,
Fig.4, page 67. At the Maximite end, the
positions of 0V and 5V on the rear-panel
connector are shown in Fig.1. SPI Data
and SPI Clock can be connected to any
available I/O pin (the selection is specified in the SPI command). Here, we have
chosen to use pins 2 and 3 respectively.
Once these four connection have
been made, we need to send 41 bytes
of data to set a colour on the eight RGB
LEDs (see Fig.6 on Page 67). We have
written a very short program to do this
– MoodLite.bas. Download and run it,
follow the on-screen instructions and
you should soon see some action on
the LEDs. We will not explain the code
in detail here – comments are scattered
throughout the program. Try adding
new features such as controlling colour with an IR remote control. A good
exercise is to make the MIWM Mood
Light software fully operational on the
Maximite. This is not as daunting as it
sounds, and as usual, if you need help,
just drop me an email!
Practical Electronics | February | 2020
|