Saturday, April 20, 2024

DevLog001: Parallax scrolling in a game

My attempts at horizontal parallax scrolling turned out to be somehow usable - so why not create a game?

After some experimentation with BASIC, strings, MCODER2, and z88dk, and having some experience with C code, I began rewriting my efforts, gradually adding game-like functionality. So far things went along nicely, the code generated by z88dk doesn't seem to be as efficient as that generated by MCODER2, but good enough to create some fast loops, esp. for graphics. The huge advantage of z88dk and C code is its usability - meaning you're using ASCII text files in a Linux environment, with all its proven tools like vim editor, git version management, diff, make, networking, etc., and you have all the power of a C compiler, meaning #define, functions, labels, pointers, types, etc., to write proper code. Of course some extra work is required to transfer the results of a Linux cross-compiled C program to your real ZX81 machine - but during development, using an emulator, the workflow and turnaround-times are amazingly smooth and quick.

A title screen with instructions / info

Creating graphics on a ZX81 is always a bit of a peculiar challenge, unless you're a very experienced machine code wizard, able to use hi-res graphics. The fixed character set doesn't give you much to work with, but when time and motion is added, the illusion of a "big" arcade game is actually quite enjoyable. 

So currently this little shoot-em-up game-thing is called "Nemezys 2081", has pretty much the parallax scrolling as shown in the BASIC/MCODER2 tech demo videos, and you can actually do something with it: move around and shoot a bullet! :-)

Game screen: ship, enemy, bullet - it's a shoot'em-up!

I have a ton of ideas that I'd like to put into the game, but I also have zero idea if it'll work out. A C compiler potentially generates more code than strictly necessary, and CPU cycles are tight on a ZX81. But it's great to just add features and see the progress, even if memory runs out, or it becomes just too slow - it's a fun learning experience, thus a win-win situation in any case. 

* * *

Thanks for reading, see ya next time!



Tuesday, February 13, 2024

Safi's "3D Engine DEMO" (2020) - Doom on ZX81?

Legendary first person shooter game "Doom" requires a little more horsepower than the Sinclair ZX81 has to offer. But then, a VIC-20 can do it, so why shouldn't the ZX81?

Spoiler: So far, "3D Monster Maze" (1981) is still the most realistic first person "shooter" game for the little ZX81. 

But there are some efforts to push the boundaries - one of which is this 3D engine demo by Sandor Safar from 2020, found on his YouTube channel "Safi's ZX-81".

It looks a bit crude, there are no walls, no enemies, no objects to interact with, you can't shoot, not even turn, and there are no maps or levels. But it works! We can move around smoothly in a 3D rendered 2D playfield! :-) The demo is written in BASIC, and compiled to machine code - giving it the speed required for fast graphics.

LISTing "3D Engine DEMO" gives a couple of clues: The BASIC code has been compiled with ZXGT

Obviously, this is just a technical demonstration, far from a "usable" game - but it's still impressive, and, well, who knows, maybe one day we'll play some sort of actual Doom on the ZX81? Also this demo is a great example of how BASIC programmers can create fast programs by using a machine code compiler such as ZXGT or MCODER2.

You can download the .p file and try it on your own ZX81, see video description / link below.

LISTing the "3D Engine DEMO", we can see that the BASIC code is still there, with some information added in the REM statements: It's been compiled with ZXGT (MCODER), and the machine code program starts at address 18823.

To run the (extremely slow) BASIC version, type RUN.
To run the (amazingly fast) machine code version, type RAND USR 18823.

 

Thursday, February 8, 2024

Using a ZOOM H4 digital recorder with the ZX81

The ZX81 has very simple, apparently quirky audio in- and outputs, for loading and saving files. But in fact these are designed to work with cassette tape recorders built about 40 years ago, which are slightly different from modern audio devices.

You can read a bit about the ZX81's audio i/o characteristics if you like - they appear to be a bit unusual on first sight.

Will a modern ZOOM H4 digital recorder be able to handle the task?

The program on the screen was saved to and loaded from Zoom H4.

The good news first: It works! :-D

One or two extra steps are required to handle the main issue with the ZX81's tape ports: low volume. The ZX81's MIC/EAR tape ports are designed for old cassette tape recorders, which handle audio signal slightly different from modern digital equipment. Zoom H4 digital recorder provides enough audio processing functions to make it work.

Saving

Connect ZX81 "MIC" to Zoom Input 1 or 2, and switch that input to high sensitivity. In Zoom's "Input menu", set "Mono mix" to "On" (so you don't have to worry about left/right channels), all other settings to "Off", and turn "Level" all the way up (0 db). 

Saving/recording from the ZX81 to the Zoom H4 will still have only ~50% amplitude - select "WAV" recording format, so you can "normalize" (via "Menu"->"File"->"Normalize") to full volume. (Zoom H4 can't normalize mp3.)

Loading

For loading/playback use "phones" output jack, and near-full volume (~90% or so).

Are there any bad news? Not really. A little understanding of what's going on is required, as are the necessary steps to make things happen successfully, which is really manageable for everyone.

The perfect solution would either require an old cassette tape recorder with built-in recording amplification, if you like the original 1981 workflow, or some sort of hardware amplification to the signals, so no more post-processing is required on the digital recorder. This could be an external amplifier, or a modification to the ZX81's mainboard.

But unless you're a hardcore coder who does constant saving and loading, the Zoom H4 is quite a usable storage device for ZX81 tape port i/o, even without extra circuitry. 

 

Wednesday, February 7, 2024

ZX81 alive Web Directory

A new page has been created, see links on the right (or... somewhere, on your smartphone): ZX81 alive Web Directory - a collection of active Sinclair ZX81 related websites.

Currently there are 21 links, but more to come, and if you like to add your website just leave a comment, or post it in facebook group "Keeping the Sinclair ZX80 and ZX81 Alive". 

>>> ZX81 alive Web Directory

(NOTE: The similarity of facebook group name "Keeping the... Alive" and "ZX81 alive" is pure coincidence. But it is quite fitting.)

 

Tuesday, February 6, 2024

ZX81 alive #02: Parallax scrolling in machine code

A new video of parallax scrolling, with a significant speed increase.

With an upgraded ZEsarUX emulator, and a little bit of newly gained know-how about ZX81 BASIC compilers, a machine code version of the "PARALLAX" demo was created. 

"MCODER2" is an easily available compiler, and basically just two USR calls (via LET) are required to do the compilation. There are a few limitations to what BASIC code MCODER2 can handle, but interestingly it looks as if in this case none applied. (See MCODER2 documentation, and source code in the video.)

Anyway - the increase in speed is quite nice. :-)

ZX81 alive YouTube channel

 

Sunday, February 4, 2024

ZX81 alive #01: Parallax scrolling in BASIC

Yesss! The first ZX81 alive video has been uploaded to YouTube. 

It shows a little experiment in creating some sort of parallax-scrolling 3D view, written in BASIC. Source code is shown in the video. (Well, it's not too spectacular. ;-) )

Maybe an inspiration for your own coding efforts?

Enjoy!

ZX81 alive YouTube channel

Friday, February 2, 2024

ZX81 video display system in-depth

Here's a very good article extensively explaining the ZX81's video display system.

Written by wilf rigter in 1996, this tutorial from 8bit-museum's collection of Sinclair scans gives excellent information about how all things video work in a ZX81.

https://8bit-museum.de/heimcomputer-2/sinclair/sinclair-scans/scans-zx81-video-display-system/