►
From YouTube: RustFest Paris 2018 - Monotron: Making a 80s style computer with a $20 dev kit by Jonathan Pallant
Description
Jonathan Pallant has a knack
for bringing that retro feel back
with embedded Rust code
on a Cortex M node
I would say that's a glorious hack
I missed the simplicity of of computers like the C64 and the Apple 2 and I wondered if I could recreate something like that, but using the Cortex M4 devboard on my desk and a handful of resistors. Can you generate VGA without a video chip? Can you render text without enough RAM for a framebuffer? Can you read from a PS/2 keyboard? Can you do it all in Rust, and run tests on an actual PC? Will it run fast enough to be useful?
(Limerick by @llogiq)
https://paris.rustfest.eu/sessions/monotron-recreating-an-80s-style-computer
A
B
All
right,
thank
you
very
much
everyone.
It's
a
pleasure
to
be
here,
sir
yeah
I'm
talking
about
mono
Tron,
my
attempt
to
pretend
I'm,
not
quite
as
old
as
I.
Actually
am
so
a
very
good
question.
Why?
So?
This
is
an
embedded
righteous
project.
Embedded
rust
is
cool.
You
should
all
do
more
embedded
rust.
I
am
an
embedded
C
programmer
by
trade.
I
work
in
Cambridge
at
a
company
called
Cambridge
consultants
and
I.
Don't
get
to
do
enough
embedded
programming
at
work.
I
mean
it's
literally
my
whole
day
at
work,
but
it's
not
enough.
B
So
I
come
home
and
I
do
more.
At
home,
I
have
tried
some
embedded
C++.
We
have
long
engaging
discussions
at
lunch,
breaks
over
the
values
of
C
versus
C++.
It's
not
for
me.
I've
tried
it
at
work.
We
mainly
stick
to
C
but
I'm,
trying
to
convince
people
that
embedded
rust
is
the
answer
because
it
fixes
all
of
my
problems.
Right,
I've
got
Docs
built
in
doc,
generator
built
in
build
system
tests,
package
manager'
memory
safety,
it's
amazing
it.
It
is
an
an
excellent
solution.
B
When
you're
trying
to
build
small
embedded
devices
like
modems
or
Bluetooth
headsets
and
you're
you're
in
a
hurry,
so
one
of
the
things
I
take
part
in
because
clearly
I
have
vast
amount
of
spare
time
is
the
embedded
working
group
so
jorge's
out
there
somewhere
Jorge
heads
up
the
the
embedded
working
group.
There's
a
bunch
of
us
get
together
and
talk
about
what
the
future
of
rust
is
like
on
embedded
systems
and
I'm
happy
to
say
it
looks
like
by
the
end
of
this
year
by
Russ
2018
edition.
B
B
Seriously,
the
number
of
times
I've
rolled
the
roster
update,
dice
and
everything's
broken,
so
why
this
particular
project
well
I,
like
the
eighties
systems,
were
much
simpler.
Computers,
like
the
the
vic-20
in
the
the
Commodore
64
that
I
had
a
fear
all
goes
wrong.
You
turn
it
off
turn
it
on
again,
and
everything
is
back
to
factory
settings
I
like
I
like
working
on
bare
metal.
You
know
libraries
and
things
that
help
you
do
stuff
are
interesting,
but
I'm
quite
interesting.
B
Getting
down
to
the
to
the
guts
I
want
to
understand
what
the
processor
is
doing
and
why
it's
doing
what
it's
doing.
So
that's
what
that's?
What
interests
me
and
it
turns
out
I,
don't
seem
to
watch
any
TV
these
days
because
I'm
far
too
busy
watching
YouTube
find
selection
of
retro
YouTube
channels,
I
recommend
you
check
them
all
out,
because
they're
all
marvelous.
B
B
B
For
those
of
you
who
don't
know
arm
cell
processor
cause,
but
you
don't
just
buy
a
cortex
m3,
you
buy
a
chip
from
Texas
Instruments
or
one
of
the
other
manufacturers
ST
micro,
and
they
give
you
the
arm
core
and
a
whole
bunch
of
peripherals
around
it
in
the
olden
days.
This
was
what
was
on
your
motherboard
a
processor,
a
serial
port.
You
know
maybe
a
video
controller,
maybe
a
sound
controller,
but
now
they
all
come
on
on
one
chip
and
they're,
incredibly
cheap
you
can.
B
You
can
get
some
of
the
basic
ones
for
literally
pennies
in
a
very
low
power,
but
I
didn't
want
to
use
a
platform.
I
had
lots
of
built-in
peripherals
because
built-in
peripherals
are
cheating
we're
supposed
to
do
this.
The
hard
way
to
try
and
understand
these
constraints.
So
you
know
things
with
video
generators.
Well,
that's
just
no
fun.
So
this
was
the
first
platform.
I
looked
at
the
the
SD
micro
f7
discovery.
B
It's
got
a
megabyte
of
flash
340k
of
SRAM
this
board
retails
for
about
fifty
pounds
or
about
fifty
dollars
because
everything
Britain's
expensive,
but
it
comes
with
a
proper
LCD
interface
and
you
could
probably
just
wear
up
a
a
monitor
and
have
full
color
output,
pretty
trivially,
with
audio
and
Ethernet
and
memory
cards
and
well
frankly,
that
is
cheating
that
is
far
too
much
working
out
of
the
box
someone's
already
written
some
rough
software,
so
most
of
this
stuff
already
works
no
fun
at
all.
This
is
what
it
looks
like.
B
So
the
the
board
I
use
is
the
stellaris
launchpad
from
Texas
Instruments.
You
get
256
K
a
flash
and
32
K
of
RAM,
it's
clocked
at
up
to
80,
megahertz
and
because
I've
been
working
with
these
for
a
little
while
I
have
some
some
board
support,
crates,
I
kind
of
know
how
to
start
the
processor,
the
ones
I
did
originally
they're,
not
great.
There
was
a
lot
of
a
lot
of
difference
of
opinion
in
the
embedded,
rust
community.
B
Every
time
someone
supported
a
new
chip,
they
did
it
differently
and
now
we've
started
to
work
out
now.
There's
a
consistent
way
to
do
this,
that
that
allows
these
things
to
feel
the
same,
look
more
similar.
So
this
was
an
exercise
in
testing
out
some
of
those
things
and
I've
got
some
very
simple.
Peripherals.
Spi
is
basically
just
a
one
bit:
digital
output.
You
can
turn
on
and
off
at
quite
high
speed.
We've
got
serial
ports,
you,
arts
and
a
thing
called
PWM
pulse
width
modulation.
This
is
basically
on
autonomous
waveform.
B
You
can
generate
from
the
process
it's
on
for
a
period
of
time
and
then
off
for
a
period
of
time.
It's
just
like
a
blinking
light
on
off
on
off
and
you
get
to
choose
how
long
it's
on
and
how
long
it's
off
and
everything
else
happens
by
magic,
but
there's
literally
nothing
else
on
there.
That's
of
use
to
me
so
we're
gonna
have
to
roll
our
sleeves
up
to
do
this.
This
is
what
the
board
looks
like.
B
If
you're
interested
later
I've
I've
got
one
with
me,
you
can
have
a
little
look-see
looks
like
with
all
the
wires
on.
So
how
are
we
doing
this?
Well?
This
is
the
this.
Is
the
chip
I'm
apologize
for
failing
to
respect
margins
in
my
Google
presentation,
but
basically,
we've
got
a
DMA
engine.
This
is
a
piece
of
silicon
baked
into
the
chip
that
can
automatically
move
memory
from
somewhere
to
somewhere
else,
and
you
can
get
off
and
do
a
different.
You
can
execute
some
code
while
that's
happening
in
the
background
may
be
useful.
B
We
have
some
timers
on
there.
These
are
the
devices
that
generate
those
PWM
signals
so
that
you
can
either
do
on/off
on/off
in
cycles
or
they
can.
They
can
wait
a
period
of
time
and
when
the
time
expires,
an
alarm
goes
off
and
your
CPU
is
in
too
and
can
go
and
do
some
work
and
it
can
run
at
a
speed
of
sixty
six
point,
six,
seven
or
or
80
megahertz
and
we'll
see,
if
that's
relevant.
B
Now
the
some
of
the
great
work
Jorge's
been
doing
and
others
it's
this
tool
called
SVD
to
rust
and
what
an
SVD
is.
It's
basically
a
description
of
the
chip
provided
by
the
manufacturer.
The
way
these
chips
work
is
all
of
their
peripherals
exist
at
magic
memory,
addresses
that
aren't
really
memory
their
chip,
peripheral
and
this
file
describes
them
all.
B
I
admit
that
is
relatively
unreadable
to
some
people.
But
if
you
understand
the
chip-
and
you
understand
that
there
is
an
IO
P
enable
bit
in
the
AHB
enable
register,
then
that
becomes
a
lot
more
readable
and
actually
the
compiler
just
turns
that
in
to
set
this
bit
in
this
memory
location.
So,
although
there's
more
typing,
it
doesn't
cost
you
anything
at
runtime,
it's
just
as
fast
as
doing
it.
B
The
old-fashioned
way,
which
I
think
is
just
brilliant,
who
listens
to
new
rush
station,
the
podcast
there's
a
brilliant
podcast
kraits,
you
should
know,
is
my
list
of
crates.
You
should
know
SVD
to
rust,
generates
a
crate
for
each
supported
chip.
The
TM
is
the
the
TI
chip
I've
gone
on
mine,
there's
an
STM
chip
there,
but
these
are
fairly
low-level
api's
as
you
as
you've
seen,
so
we
wrapped
them
up
in
something
a
little
higher
level.
B
These
Hal
crates
describe
the
various
types
of
peripherals
in
a
common
fashion,
so
there's
one
further
chip
I'm
using
run
for
the
STM,
but
they
use
these
embedded
howl
traits.
And
basically,
if
you
write
your
code
to
use
a
UART,
then
you
should
be
able
to
plug
in
any
of
these
chip
crates
and
use
any
UART
from
any
of
these
chips,
and
it
helps
people
write
reusable
libraries
that
will
run
on
a
number
of
embedded
platforms.
B
Again,
it's
quite
difficult
to
do
in
C,
though,
for
this
specific
case
of
a
cortex-m,
then
there
are
a
couple
of
cortex-m
help
with
crates
again,
based
on
great
work
on
those
ones,
are
sort
of
managing
the
chip
and
one
artis,
the
runtime.
So
that's
for
getting
the
chip
booted.
So
there
was
a
bunch
of
stuff
I
didn't
have
to
do
so.
B
B
Well,
it's
an
analog
video
signal
and
it
involves
the
three
standard:
analog,
colors,
red,
green
and
blue,
and
these
are
analog
signals
that
vary
between
naught
and
0.7
volts
and
the
amount
of
voltage
you
put
on
each
of
those
colored
pins
controls
how
bright
the
screen
is
in
that
particular
color,
and
so
the
signals
on
the
screen
start
and
left
and
go
to
the
right.
And
that
is
time.
B
So
the
left-hand
edge
of
the
screen
is
this
edge
on
the
left
and
the
right-hand
edge
of
the
screen
is
here
except
of
course,
in
my
case,
I
think
the
edge
of
the
projector
is
probably
about
here,
which
is
why
you're
you're
missing
the
left-hand
side
of
the
screen,
the
the
black
line
at
the
top.
This
is
called
the
sync
pulse,
so
this
helps
the
monitor,
find
the
edge
of
the
screen.
B
So
we
have
a
horizontal
sync
that
says
where
you
are
within
your
line
and
our
vertical
sync.
This
is
where
you
are
within
your
frame
and
again
there's
some
blank
lines.
The
sync
pulse
goes
low,
some
more
blank
lines
and
then
these
blue
lines
are
whether
where
the
picture
is
so,
is
it
it's
kind
of
straightforward?
You
can
kind
of
start
to
see
where
these
timer
peripherals
might
be
useful
to
generate
these
sort
of
repeated
on-off
signals
of
loss.
My
mouse
cursor,
so
timing
is
incredibly
important.
B
If
you
get
the
timing
wrong,
your
monitor
will
tell
you
to
go
away.
My
monitor
has
told
me
to
go
away
on
a
very
large
number
of
occasions.
It's
taken
awhile
to
get
this
to
work.
It's
all
about
this
thing
called
the
pixel
clock.
The
pixels
must
change
repeatedly
and
reliably,
and
each
pixel
must
be
exactly
the
right
length
in
time
and
if
they're,
not
the
monitor
will
get
confused
and
the
pixels
will
start
to
look
very
strange
and
the
timing
basically
comes
from
the
resolution.
You
choose
right.
B
So
there's
a
pixels
across
lines
down
640
pixels
across
times,
480
lines,
high
60
frames
per
second.
This
is
the
good
old
fashioned
IBM
standard,
and
that
means
you
need
to
be
generating
new
pixels
every
well.
You
need
25
point
one,
seven,
five
million
pixels
per
second.
This
is
quite
a
large
number
for
the
small
embedded
chips.
It
also
does
not
divide
down
nicely
into
sixty
six
point,
seven
or
80.
B
So
that's
not
going
to
work
so
the
other
one.
When
you
turn
on
your
old-fashioned
PC
and
you
get
the
BIOS
screen
comes
up
when
he
makes
the
beep
sound.
You
know
press
Delete
to
enter
setup.
Well
that
used
to
be
at
a
resolution
of
720
by
470
Hertz,
just
how
the
numbers
worked
out
when
IBM
developed
it
twenty-eight
point
three
to
two
megahertz:
that's
not
gonna
work
either,
which
is
a
shame
because
it
would
have
a
great
sort
of
IBM
classic
retro
feel
800
by
600
at
sixty
Hertz.
B
Well,
that's
sort
of
a
resolution
you
were
using
in
Windows
95
windows
3.1.
It
feels
quite
a
retro
40.000
megahertz.
Ladies
and
gentlemen,
I
think
we
have
a
winner.
I
can
just
take
my
80
megahertz
processor
clock
divide
it
by
two
and
there's
the
pixel
clock.
I
need
to
generate
this
data,
so
the
math
stacks
up.
B
So
what
do
we
end
up
with
well
800
by
600,
the
40
megahertz
clock
done
turns
out
800
horizontal
pixels
is
too
many
I.
Don't
have
enough
processor
time
to
generate
that
many,
but
I've
got
a
plan.
If
I
make
my
pixels
twice
as
long
and
send
half
as
many
the
monitor
will
have
no
idea
I've
done
this,
it
will
see
two
pixels
when
I've
only
sent
one.
So
we
can
do
it
400
by
600,
and
the
monitor
has
no
idea
and
that
will
work.
If
we
then
divide
the
screen
into
characters.
B
Eight
pixels
across
16
pixels
high
that's
sort
of
a
good
old-fashioned
dos
style
font.
Then
we
get
about
48
by
36.
It
doesn't
divide
evenly.
We
put
a
border
on
12
pixels
top
bottom
8
on
the
side,
makes
it
feel
like
a
Commodore
64
and
helpfully
makes
up
with
math
simpler
as
it
turns
out,
and
then
the
idea
is.
We
can
load
these
pixels
into
our
into
our
digital
output.
B
Our
SPI
peripheral
synchronous,
peripheral
interface,
basically,
I
can
load
bytes
in
8-bit
values
and
single
bits
will
magically
appear,
so
my
processor
can
put
an
8-bit
value
in
and
then
go
off
and
do
something
else
and
the
eight
bits
will
be
generated
at
well.
In
my
case,
20
megahertz,
to
get
my
double-width
pixels
automatically
and
even
better.
B
This
particular
chip
has
what's
called
a
5,
though
first
in
first
out
queue,
I
can
load,
16,
bytes
up
and
then
go
away
and
the
chip
will
generate
8
bits
for
each
of
those
16
bytes
completely
all
by
itself.
It's
never
designed
to
do
video.
It
was
designed
to
talk
to
modems
and
memory
chips
and
SD
cards.
Spi,
incidentally,
is
exactly
how
SD
cards
work
in
their
basic
mode.
B
B
There
aren't
scales
of
grey
here
either
the
output
is
maximum
on
or
maximum
off,
and
so
what
we
do
is
we
set
up
some
timer
interrupts
and
at
the
beginning
of
the
line,
the
start
of
this
sync
pulse
and
when
the
sync
pulse
goes
low,
a
timer
interrupts
fires
and
we
execute
some
code
and
what
we
do
is
we
get
the
line
set
up.
What
line
am
I
on?
Well,
that's
one
more
than
the
one
I
was
last
time.
B
Basically,
my
SPI
five
throws
like
a
bath.
The
first
interrupt
I
fill
my
bath
on
the
second
interrupt.
I
pull
the
plug
and
I
can't
quite
fill
my
bath
fast
enough,
but
that's
fine,
because
I've
had
a
bit
of
a
head
start
and
hopefully,
by
the
end
of
the
line,
the
very
last
bit
of
pixel
data
drains
out
of
my
bath,
just
as
I'm
pouring
it
in
and
everything
will
work
and
I
have
to
do
that.
B
Six
hundred
and
twenty
eight
times
as
times
a
frame
60
frames
a
second
it's
best,
not
to
think
about
how
much
work
this
processor
is
doing
because
you
start
to
question
what's
happening.
So
this
is
the
magic
number.
If
I
have
an
80,
megahertz
processor
clock
and
I'm,
dividing
it
down
with
a
20
megahertz,
pixel
clock
and
I
have
to
output
these
8
bits
for
my
every
character.
Basically,
what
happens
is
I
have
32
you
clock
cycles
of
my
processor.
B
I
can
perform
about
32
instructions
in
my
processor
for
every
character
across
my
screen,
I
have
to
go
to
the
character
buffer,
find
out
what
letter
is
being
displayed.
A
letter,
a
workout
where
I
am
in
the
letter
I'm
in
the
middle,
maybe
across
the
bar
of
the
letter,
a
work
out
which
bits
need
to
be
on
and
off.
Well,
there's
some
off
at
the
edge
and
there's.
B
B
So
this
is
actually
the
font
from
FreeBSD.
If
you
boot,
FreeBSD
on
a
spark
machine
or
something
that
doesn't
have
a
VGA
video
card,
they
use
this
exact
font
and
we
can
see
here
I'm
generating
green
text
on
a
black
background,
I'm
just
wagging
the
green
pin
out
of
my
red
green
blue
at
this
point
can't
manage
red
and
blue,
but
it
you
know
it's
a
solid
picked.
It
goes
fuzzy
in
the
corner,
but
that
is
my
appalling
ability
to
use
my
Canon
SLR
as
opposed
to
the
quality
of
the
video.
B
And
the
very
observant
of
you
will
spot
that
it
is
no
longer
green
on
black.
It
is
now
in
fact
white
on
blue.
There
are
some
shortcuts
you
can
take
when
it
comes
to
generating
color
video.
If
you
want
to
generate
white
on
blue,
then
for
every
pixel
that
is
set,
then
you
need
to
put
a
one
in
the
red,
the
green
and
the
blue,
and
for
every
background
pixel.
You
just
need
the
blue
on
on
the
red
and
the
green
a
blank.
B
B
Menu
system,
so
it's
a
serial
port,
so
you
can
send
it
commands
and
you
can
do
things
like
if
you
want
to
see
how
this
chip
boots
dump
hex
100
bytes
at
address
0
for
the
terminally
curious.
The
base
value
here
is
the
the
stack
pointer
and
then
these
values
are
my
interrupt
vectors
and
you
notice
all
my
all
interrupt
vectors
are
the
same.
They
pointed
an
interrupter
vector
that
says:
I
haven't
written
this
this
this,
yet
you
need
to
crash.
So
basically
the
function
at
address
0
these
addresses
are
backwards.
B
B
Let's
say
that's
a
scene
many
people
have
seen
before,
but
you
know
what
enough
of
this?
Let's
talk
about
some
art.
What
can
you
do
with
this
system?
Well,
I.
Don't
have
pixels.
If
I
had
a
pixel
buffer,
then
I
would
blow
half
of
my
memory
storing
individual
pixels
and
there
would
be
no
color,
so
we've
got
blocks.
It's
a
bit
like
teletext,
but
you
can
imagine
if
I
put
the
effort
in
this
would
be
a
playable
game.
You
know
my
kids
might
enjoy
this
right
space
invaders,
that's
good!
All
right,
maybe
not
space
invaders.
B
B
So
it
turns
out
there
are
some
more
cheats
you
can
take
if
you
are
prepared
to
use
vast
amounts
of
flash
memory.
I
don't
have
enough
time
to
do
maths
to
say
if
this
character
is
yellow,
then
place
values
here
and
here
and
not
here
if
this
value
is
green.
Do
this
other
thing,
because
the
if
it's
yellow,
if
it's
green,
if
it's
blue,
if
it's
whatever
takes
too
long,
you
can
arrange
a
table
in
memory
and
pre-compute
values.
It
basically
uses
one
kilobyte
per
color
and
I
have
64
color
combinations.
B
So
I
have
eight
foreground
and
eight
background.
But
if
you
just
blow
64
kilobytes
of
memory,
then
your
color
lookup
just
becomes
an
index
into
find
the
table.
I
want
jump
down
to
the
8-bit
value.
I
want
there's
my
red
green
blue
values
until
we
have
full
color.
So
this
is
a
bit
more
exciting
right.
How
about
we
have
a
sort
of
a
dot
style,
dot
style.
There
are
a
Productivity
application
right,
I
can
manage.
B
B
So,
incidentally,
typing
these
into
your
source
code
by
hand
is
incredibly
slow,
so
I
found
a
wonderful
paint
package
called
Rex
paint
and
it
is
designed
to
paint
these
DA
style
pictures
and,
as
I
have
absolutely
no
artistic
merit.
The
only
other
thing
I
could
think
to
draw
while
using
Rex
paint
was
a
picture
of
Rex
paint.
B
So
this
is
an
ASCII
art,
editor
again,
mine's,
just
a
sort
of
a
fictional
version.
It's
an
artwork,
but
you
can
imagine
you
can
select
the
characters.
This
is
my
character
set.
It
is
if
you're
interested
dose
code
page
850
for
those
of
you
who
remember
dose
code
pages.
Basically,
Unicode
hadn't
been
invented,
and
so
you
had
a
choice.
Did
you
want
Central
European
languages
or
Western
European
languages,
or
were
you
American
and
you
didn't
give
a
damn
about
accented
letters?
In
which
case
you
could
have
lots
of
boxes
and
drawing
characters?
B
This
is
a
this
is
a
combination
of
the
two.
We
have
some
accents.
We
have
a
few
boxes.
This
is
the
50%
character,
which
is
50%
foreground
50%
background,
but
it
helps
get
you
a
few
more
a
few
more
colors,
but
you
know
I'm
use
myself.
I
drew
some
new
trees
and
hills
and
suns
and
backgrounds,
but
but
let's
face
it,
this
project
was
never
going
to
set
the
world
on
fire.
Thank
you
very
much,
ladies
gentlemen.
B
B
B
Interesting
question,
so
this
requires
a
certain
amount
of
processing
power.
I'd
have
to
go
and
look
at
the
specs,
but
I
think
the
micro
bit
is
another
cortex-m
I'd
have
to
check
the
exact
clock
frequencies
you
can
tell
it
to,
but
maybe
you
could
handle
Powell,
video
or
NTSC
analog,
video
or
maybe
a
lower
resolution.
So
it's
it's
possible
and
the
crates
are
portable.
So
there
is
a
crate
that
called
VGA
frame
buffer
and
that
just
has
some
plug-in
values
of
the
timing
and
some
hardware
specific
callbacks
you
can
set
so
yeah.
B
B
Yeah
there
is
a
little
limited,
smooth
ship
of
inline
assembler,
if
I'm
honest.
So
it
turns
out
if
you
activate
your
red
Fife,
oh
and
then
in
the
next
machine
instruction.
You
activate
your
green
FIFO.
Well,
the
red
FIFO
has
already
started
sending
pixels
and
then
you'll
read
your
green
in
your
blue.
Don't
line
up
and
you
get
these
sort
of
weird
fringe
effects
around
all
of
your
letters.
So
the
solution
and
then
it
took
me
a
while
to
get
to
this.
B
Is
you
preload
your
red
FIFO
with
two
8-bit
values
that
are
all
zero
and
you
preload
your
green
with
one
8-bit
value?
That's
all
zeros
and
you
start
your
red
16
pixels
early,
and
then
you
have
to
put
exactly
the
right
number
of
assemble
and
no
operation
instructions
in,
and
you
start
the
green
and
then
you
have
another
seven,
no
ops,
and
then
you
start
the
blue
and
they
are
always
in
sync
perfectly
in
sync.
But
you
do
need
that
little.
Just
a
smoosh
of
inline
assembler.