
How to write a game on a ZX81 [video] - ingve
http://cowlark.com/2018-09-26-zx81-programming/index.html
======
sehugg
The ZX80/81 used Don Lancaster's "Cheap Video and Lying To the Machine" method
of graphics output:
[http://laughtonelectronics.com/Arcana/KimKlone/BrideOfSon%20...](http://laughtonelectronics.com/Arcana/KimKlone/BrideOfSon%20KK%20Lancaster.html)

Essentially, the CPU executes each line of video, jumping to the start of each
line of cells. The video system latches each byte onto a shift register and
displays it.

But the CPU is tricked -- NOPs are forced onto its data bus right before it
decodes the instruction. So it merrily marches along fetching successive bytes
for the video subsystem, without interpreting them.

That is, until a certain bit of the character code is seen, then the CPU is
allowed to execute the instruction and terminate the scanline (usually HALT on
the ZX). This process repeats over and over for each scanline.

As a result, it's pretty tricky to program animations. There's not much CPU
time left for anything while a frame is being displayed.

~~~
rcarmo
In FAST mode, the 81 blanked the entire screen while drawing because of that.
It was eerily fascinating.

------
macdice
This was very nicely done and a really enjoyable time travel video. I learned
to program on a ZX81 at a young age. With the manual (shown), the Usborne
1980s programming books that actually taught kids how to do machine code (all
now released free: [https://usborne.com/browse-books/features/computer-and-
codin...](https://usborne.com/browse-books/features/computer-and-coding-
books/) ) and then also the Rodney Zak's Z80 book (also available free
somewhere). What a great start to a career as a hacker! Cost my parents
something like a hundred bucks down here in New Zealand, but I also had to mow
my neighbour's lawn to get my hands on an old black and white TV set to plug
it into. How I loved that machine, but also hated it (they keyboard was
terrible, and the 16kb "RAM pack" would crash the machine if you wobbled it).
I envied the more feature-rich Commodore 64s etc that other kids had, but they
tended to use them in a more passive way: playing games only. I think the
austerity of the ZX81 either produced or at least selected for a curiosity
about how code works.

------
david-given
Author here. Thanks for the kind words. It was fun to do, and I just wish I
could have touched on stuff like FAST vs SLOW, more about the weird display
system, etc... but TBH FAST doesn't really get on well with modern monitors
and video capture systems and I was terrified of getting 40 minutes into it
and then discovering that all my captured video was unusable!

Oh, yeah: ZX81 BASIC doesn't support multiple statements per line, and the
IF...THEN statement doesn't support ELSE. Writing complex logic on it can be a
challenge!

~~~
dukoid
Is there any advantage in using A, B, C etc. as variable names? W and H seemed
to be potentially more readable for the with and height, X and Y for the ball
position and in particular O and I for 0 and 1 etc.? Also, I think I have
spotted a few remaining 0s in the saved file?

~~~
david-given
The practice version did, but name collisions got too confusing (W and H is
fine for width and height, but then I wanted horizontal and vertical
velocity...). I thought it was clearer to give up completely and use the
notepad instead.

And yes, some optimisations are left as an exercise for the reader.

------
zygotic12
Back in the day I hand dis-assembled the code for
[https://en.wikipedia.org/wiki/Jetpac](https://en.wikipedia.org/wiki/Jetpac)
It is beautiful. Without the 80/81 it would not exist. Seriously have a look.

------
Razengan
I've always wanted to make something on the Sinclair Spectrum but I was too
young back then and computers advanced too fast (it was exciting, watching the
future materialize in real-time, though.)

Still hope to get around to it some day.

------
keyle
I wish I had this when I was a kid. I basically had a ZX-Spectrum from
Sinclair and all I learnt was by reverse engineering things. I'd load a tape
or whatever and try figure out how it does what it does.

Although it taught me from an early age to dig to find things, you can't beat
having learning material...

~~~
tluyben2
I am happy I learned it via reverse engineering. It gave me skills that allow
me to learn new things fast and it showed me that nothing is magic. You would
be surprised how many uni cs graduates find a lot of computer things magic but
do not have the tools in their head to discover they are not.

I am also of the opinion videos are the worst and laziest way to convey deep
technical information; yet it is really popular. If someone wrote this into a
post, I would he able to digest and try out in a very short period of time,
with videos it is pretty uncomfortable. I wonder why it is so popular aside
that most people who watch it will never try it out to begin with.

~~~
david-given
It's true about videos, but this was never intended as a technical resource.
Instead I wanted to show how working on one of these machines _felt_.

I showed this video to some work-mates, mostly younger than I am, and some of
the questions I got were really revealing: 'Does it boot into Basic?' 'But if
there's no disk, where does it put the compiled program?' These machines are
_completely alien_ to the modern mindset, and so I wanted to actually
demonstrate working on one in practice, rather than just write it up. There's
plenty of technical docs out there already.

