Monday 1 June 2015

ZX Spectrum fun

When you think about it, the 48K Spectrum was a fucking amazing piece of hardware for its time.


I got mine in late 1983 as a combined birthday and Xmas present and I think it was £129.99, but it might have been reduced to £99.99 by then. Now I know that nowadays you could probably get them cobbled together in a Chinese sweatshop for about ten pence each, but at the time it was unbelievable value for money. 48 kilobytes RAM FFS! OK, only 41.5K was usable, but that was still more than the C64 (38K I think), which cost twice the price.

Anyway, I did loads and loads of programming in Spectrum BASIC - which is still an awesome programming language by the way - and have been trying to remember all the tricks I used to save on memory.  I mean, 41.5K seemed loads at the time, but it's very quickly filled, especially given the weird quirks of Spectrum Basic.

For instance, using a single digit number - such as 0, 1, 7 - used seven bytes of storage space.  But a single character variable only used one byte of space.  So, every time you can use a static variable rather than a number, you save six bytes.  So I would set up static variables for any number that was going to be very commonly used in the code, such as:

10  LET o = 0
20  LET i = 1
30  LET tw = 2
40  LET th = 3

But you could go further than that, because in Spectrum BASIC, PI was a defined in ROM, and that only took one byte of storage. Using the logical functions (one byte), I would instead do:

10  LET i = SGN PI   (five bytes saved!)
20  LET o = NOT i   (five bytes saved!)
30  LET tw = i+i   (four bytes saved!)
40  LET th = INT PI   (five bytes saved!)

and so on.

Actually I wouldn't even have done that, because each new line of code cost bytes (can't remember how many), so I'd have actually stuffed them all into a single line, separated by colons:

10  LET i = SGN PI: LET o = NOT i: LET tw = i+i: LET th=INT PI: ...

What other ones were there? I remember using bits of screen memory as RAM (which you could only do if you weren't displaying anything on it at the time, obviously) and I'm sure there was a way of using the UDG character set (all 168 bytes of it!) amongst other things.

I really should plan these things properly instead of just sitting down and typing; I've forgotten (and probably misremembered) a lot of it. Trigonometric functions, other logical stuff, etc.

Ah well.


[Edit @ 22/09/2016:  This isn't too bad.  It's actually readable and (to me, anyway) quite interesting. It's odd that I remember a lot of these posts as "mad" when they weren't really.]

No comments:

Post a Comment