2022 Update - Or what I did over Christmas with my Spectrum Next
Some vaguely structured waffle about what I did over Christmas with my Spectrum Next, GameMaker and Windows Paint.
So I had three weeks off over Christmas to recover from the unending excitement that was 2021 and spent a decent amount of time in front of my PC writing code for my Spectrum Next, ready to turn into videos and little projects.
After the fun I had last time creating a game in Z80 assembly language, I thought it'd be good to have a go at writing Conway's Life in z80.
While "fun" is one of the words I could use to describe the process, there are several more, but writing them here would upset YouTube. Let's just say I learnt a lot about debugging assembly language!
Github Repository: https://github.com/ncot-tech/z80-life
Website: https://ncot.uk/z80-homebrew-computer/conways-life-in-z80-assembly/
Support me: https://ko-fi.com/C0C116W2L
Video Sections
============
0:00 - Intro
0:44 - What is Life?
1:29 - Rules
2:34 - Overall algorithm
3:05 - Double buffering
7:19 - How the data is stored
8:19 - Maths on a Z80 is difficult
9:53 - Asteroids?
12:05 - Code
15:20 - Outro
...
https://www.youtube.com/watch?v=DelPw_fY1J0
I'm making a game for the ZX Spectrum Next using C. This is my ongoing devlog on the process.
In this episode I waffle on about the general aim of what I'm trying to do and some of the code I have written so far.
Chapters
--------
Intro 00:00
My game engine design 05:09
What I'm trying to do 06:15
The state machine 09:42
High score table code 10:33
Text printing 11:04
Next to do 12:31
...
https://www.youtube.com/watch?v=52yLar2brJE
This is the third video in a short series looking at some of the more advanced parts of the Spectrum Next. If you've not seen the others, go watch them after this one. In this video we're looking at how to program the DMA controller in the Spectrum Next.
This'll be technical, it'll include code on how to do this using Z88DK and C for the Spectrum Next. It's a pretty advanced technique, but it's quite understandable and can add some nice speed boosts to code if used appropriately.
DMA or Direct Memory Access is a way to allow devices access to system RAM without the CPU being involved.
The DMA controller in the Next is a programmable device and has a few registers that need writing to. This is well documented on the Spectrum Next wiki https://wiki.specnext.dev/DMA.
There are seven registers called WR0 to WR6. Writing to them is like when we configured the sprite system in my other video. Each register is accessed through the same IO port and the pattern of the first three bits tells the DMA controller which register you're writing to.
The only thing to know is this is purely a DMA, it can copy continuous runs of bytes. It's not a blitter so it is unable to copy a rectanglular block of RAM.
Also for small copies, the setup and configuration may actually be slower than doing it by hand with memcpy. It's definitely something to use with large amounts of data though. A music playing routine running in a vblank interrupt would use this to feed the audio hardware with sound data.
Chapters:
00:00 Start!
00:45 What is DMA?
01:41 ZX Next DMA
02:01 The DMA Registers
02:32 Register WR0
03:10 Code example DMA Screen Copy
04:23 Register WR1
05:03 Registers WR2 and WR3
05:20 Register WR4
05:44 Register WR6
06:13 A note on writing to registers
06:45 Repeating DMA transfers
08:00 Closing Notes
Credits:
Casio Calculators - J. C. Barros from Portugal, CC BY 2.0, via Wikimedia Commons
Random images - Midjourney
Music - Epidemic Sounds
...
https://www.youtube.com/watch?v=6bd7LfCcID4
Let’s briefly look back at last year and see what things were like, then look forward to the coming year and what I want to achieve. I did this last year too, and I’ve just been reading that.
So previously I was quite pleased at hitting 1000 subscribers on my YouTube channel, and by the end of the year had 1300 or so. This year I seem to have gained another 1000 as I’m somewhere around 2300.
Most of my videos last year were Spectrum Next related as I tried to work out how to program it, and then explain what I’d learnt to others who might be interested. I quite like learning things and then explaining what I know, I also seem to like telling stories of how things were.
It doesn’t feel like I did much else. I know I did far too much sitting in front of my TV watching YouTube, rather than making my own content but I guess that’s what happens when you do a full time job during the day. Doing more work at home seems like too much effort. Especially when it’s dark in the evenings and the space you work in is a bit of a complete mess.
So let’s look forwards then and see what I want to do in the coming year.
Making things easier is a goal. I’ve ditched my Hugo powered static website and moved everything back to WordPress. It’s just easier being able to type directly into the editor and hit “Publish” compared to the equivalent of compiling my text into a site.
I also really need to improve the place I work in for these videos and my own projects. The desk is all wrong, things are randomly put on the walls with no actual thought, it’s just sort of evolved over time.
Something I did do last year was tidy up my main workshed and put in better benches, and that’s improved things a lot. I will do the same in here.
I also find it really hard to make videos on a consistent schedule because most of my content is based on me explaining something I’ve been learning. Trying to figure something out can take weeks or months to complete, and I never liked releasing half finished videos.
I’m going to change things a bit this year and have a bunch of background, long term projects that I’ll make videos on as and when I feel the need, and then some easier to make videos each month.
Another thing I’m doing is resurrecting my blog and website to make it more useful. Previously it was just a place to dump the video description and a link to my videos in the hope someone Googling would find my content.
Now I want to actually write proper posts here. They might take the form of random waffle like this, or notes from the projects I’m working on. I can also use my site as a place to put the detailed, complex information I sometimes need to explain without trying to put it in a video. Yes, I’m just as annoyed as you are when Google directs me to a video on something I want to know, and I have to sit through ten minutes of YouTube fluff when a 30 second blog post could have told me the same thing.
I also want to try less structured vlog style videos on random topics that I’ve found interesting. I think I’ve figured out how to read a script to the camera, now I want to learn how to just switch one on and talk at it without going off topic or forgetting what I was trying to say.
Blog Post: https://ncot.uk/2022-review/
...
https://www.youtube.com/watch?v=rcRx8TRpe_M
Various tricks and techniques I used to improve the speed of my RC2014 implementation of Conway's Life that was written in Z80 assembly.
Grab the source code: https://github.com/ncot-tech/z80-life
Read the text version: https://ncot.uk/z80-homebrew-computer/optimised-z80-conways-life-improved/
Donate: https://ko-fi.com/ncot_tech
...
https://www.youtube.com/watch?v=mRV55685XO0
I'm on a mission to document programming the ZX Spectrum Next. Between making the instructional videos I need to learn how the machine works. I thought it might be fun to document this process too.
In this video I work out how to use fixed point maths to make things move around the screen in pleasing ways, ready for the next video I'm releasing next week.
It takes a lot of effort to produce a video explaining how to program a certain aspect of the Spectrum Next, most of that effort is me learning something new and trying to find any documentation on it. I get a bit lost along the way so if I make videos and you watch them, it'll motivate me to carry on!
...
https://www.youtube.com/watch?v=H_xv1kKugzE
How clever engineers made a cheap computer powerful
How do you make an underpowered 8 bit CPU seem a bit more capable than it really is? Interrupts! that mechanism where the CPU can be poked and told to do something completely different, then resume whatever it was originally doing as if it'd never stopped.
On the Spectrum - and in this instance I mean the original 16K Spectrum - this was done in a typical Sinclair way - cheaply, with as few components as possible, leaving the majority of the work to the programmer. I'm sure Sinclair HQ must have had a sign on their wall saying "if you can do it in software, we can build it cheaper" or something.
Let's look at how those devious hardware designers crafted a cheap and functional system that didn't exactly follow the Z80 specs.
You see the Spectrum was made to be cheap, like super cheap. Cheaper than any other home micro. And unlike cheap computers of the time, it was designed to be a usable computer.
Cheap computers of the time had a nasty habit of being severely crippled in one way or another. Maybe they had barely any RAM, or couldn't do graphics or they were so insanely hard to program for nobody bothered. Maybe the screen blanked out every time you pressed a key.
So to make the machine cheap they put in as little hardware as possible. Inside a 48K spectrum there's barely anything. Compare it to a C64 with its SID chip, VIC 2 chip, IO controllers... there's none of that in a spectrum just a big ULA that does everything.
So CPUs are machines that follow very precise and mechanical processes. They fetch, decode and execute instructions one at a time. Some instructions take multiple cycles to complete, but it's all very precise. Every time the CPU clock ticks, the CPU does a very specific task.
The real world isn't quite as predictable. One way to deal with this is called polling. This is where the machine sits in a loop constantly checking for something interesting happening. Instead of polling, we can configure our devices to trigger interrupts to tell the CPU something needs its attention.
The website http://www.z80.info/1653.htm explains how the Z80 is supposed to do interrupts, however Sinclair were in an arms race to build the cheapest computer possible to beat their competitors. That meant using as little hardware as possible, and making the hardware work as cheaply as it could.
The website http://www.breakintoprogram.co.uk/computers/zx-spectrum/interrupts explains how the Spectrum does it. It's quite clever. Go and have a look!
Credits:
Sinclair 48K ZX Spectrum motherboard - Bill Bertram
Commodore 64 Rev A. PAL motherboard - Bill Bertram
Texas Instruments TI-99 computer - Rama & Musée Bolo
Dragon 32 - Liftarn, Editing by: Bill Bertram
Byte Magazine, September and October 1982
Bus Queue - Jimmcgovern15
Social Media
============
Twitter: https://twitter.com/ncot_tech
Ko-Fi: https://ko-fi.com/ncot_tech
Web version: https://ncot.uk/spectrum-next/Clever-engineering-on-a-budget-ZX-Spectrum-Interrupts
Chapters
========
00:00 - Start
00:37 - Brief history of the Spectrum
02:10 - Polling and Interrupts
03:49 - Z80 Interrupts
05:20 - Z80 Interrupt Modes
06:11 - Z80 IM2
09:54 - Final Words
#Programming
#Z80 Interrupts
#ZX Spectrum
Video Title: Clever engineering on a budget - ZX Spectrum Interrupts
...
https://www.youtube.com/watch?v=3Ch2eV4xnQw