Double buffering on the Spectrum

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Double buffering on the Spectrum

Post by Nomad » Sun Apr 15, 2018 4:01 pm

It is amazing that even years later stuff like this is coming out. It makes you wonder how many other techniques are just waiting to be rediscovered/discovered.

I guess that is why its important for there to be a true fpga implementation of a spectrum for stuff like this in the future. Otherwise you will have emulators that will not implement stuff that was possible on the original hardware just that nobody thought was possible or even knew existed.
1 x

Wall_Axe
Microbot
Posts: 175
Joined: Mon Nov 13, 2017 11:13 pm

Re: Double buffering on the Spectrum

Post by Wall_Axe » Sun Apr 15, 2018 5:00 pm

does the floating bus trick basically allow you to know where the raster beam is at any time?

so if the static part of the game (e.g. a logo) is on the bottom of the screen..you wait until the beam is on the top of the logo before updating the game above?
0 x

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1074
Joined: Mon Nov 13, 2017 3:16 pm

Re: Double buffering on the Spectrum

Post by Ast A. Moore » Sun Apr 15, 2018 5:05 pm

Nomad wrote:
Sun Apr 15, 2018 4:01 pm
I guess that is why its important for there to be a true fpga implementation of a spectrum for stuff like this in the future. Otherwise you will have emulators that will not implement stuff that was possible on the original hardware just that nobody thought was possible or even knew existed.
You hit the nail on the head. It’s a vicious circle: emulator authors primarily focus on adding “features,” leaving the actual emulation at the “good enough” stage. Modern-day Spectrum developers then code for those emulators, rather than the actual Spectrum. Rinse and repeat. This applies to hardware emulators, too, by the way. In essence, they’re little more than Spectrum clones, except that most of them don’t even use the Z80.
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1074
Joined: Mon Nov 13, 2017 3:16 pm

Re: Double buffering on the Spectrum

Post by Ast A. Moore » Sun Apr 15, 2018 5:20 pm

Wall_Axe wrote:
Sun Apr 15, 2018 5:00 pm
does the floating bus trick basically allow you to know where the raster beam is at any time?

so if the static part of the game (e.g. a logo) is on the bottom of the screen..you wait until the beam is on the top of the logo before updating the game above?
Well, yes and no. The trick takes advantage of the fact that you can fetch the value that the ULA is currently reading from contended memory. If that value happens to be the bitmap or attribute byte of the display file, you can then proceed to treat this information as you see fit.

Catching a bitmap byte is typically of little use—you risk running into too many false positives. An attribute byte is a whole different ballgame. You can fill an area of the screen with a unique attribute byte and wait for that byte to appear on the data bus.

So, technically, you’re not so much following the beam as the data that is being fetched by the ULA. That’s the good part. The downside is that the only piece of information available to you is the value that the ULA reads. Unless the value itself is unique, you can’t know for sure where the beam is exactly.
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

Wall_Axe
Microbot
Posts: 175
Joined: Mon Nov 13, 2017 11:13 pm

Re: Double buffering on the Spectrum

Post by Wall_Axe » Sun Apr 15, 2018 6:07 pm

so you put a color(attribute) near the bottom of the screen so you know where the beam is?

so my logo could have a line of magenta and no magenta used in the game?
0 x

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1074
Joined: Mon Nov 13, 2017 3:16 pm

Re: Double buffering on the Spectrum

Post by Ast A. Moore » Sun Apr 15, 2018 6:26 pm

Wall_Axe wrote:
Sun Apr 15, 2018 6:07 pm
so you put a color(attribute) near the bottom of the screen so you know where the beam is?

so my logo could have a line of magenta and no magenta used in the game?
Yes, except it’s the full attribute byte, not just a particular color. You can have, say, a non-bright magenta paper and black ink as your sync zone, but are free to use bright magenta paper and black ink anywhere else on the screen. Or use bright black on black (which is all but invisible). Or set Bit 7 (flashing) and use the same colors for paper and ink.
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
fenderjaguar
Berk
Posts: 17
Joined: Wed Mar 07, 2018 11:48 am

Re: Double buffering on the Spectrum

Post by fenderjaguar » Sun Apr 15, 2018 9:18 pm

Even when I was a kid, I remember playing batman the movie and thinking how no sync on 50hz with all that tearing (at 12.5 or 25 fps, not sure which) was like eye cancer. Especially on the batwing level, I nearly had a seizure :lol:
0 x

User avatar
djnzx48
Manic Miner
Posts: 463
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Double buffering on the Spectrum

Post by djnzx48 » Mon Apr 16, 2018 8:57 am

I read that floating bus thread a while ago and I'm still not entirely sure on how it works. Could someone give a quick rundown from the programmer's perspective on how it differs from the standard floating bus and how you would use it in a game?
0 x

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1074
Joined: Mon Nov 13, 2017 3:16 pm

Re: Double buffering on the Spectrum

Post by Ast A. Moore » Mon Apr 16, 2018 9:15 am

djnzx48 wrote:
Mon Apr 16, 2018 8:57 am
I read that floating bus thread a while ago and I'm still not entirely sure on how it works. Could someone give a quick rundown from the programmer's perspective on how it differs from the standard floating bus and how you would use it in a game?
I think I did just that a couple of posts back. Also, what do you mean by “the standard floating bus”?

To reiterate (what I have already reiterated, I believe):

1. You create a wait loop that reads from a particular port, expecting a particular value (say, a screen attribute byte).
2. When the value read from the port matches the expected value, you exit the loop.

The time you exit the loop will roughly correspond to (plus some delay, naturally) the time the ULA was reading that value from the display fly, which will in turn correspond to the electron beam passing that area of the “physical” screen.

EDIT: I think I know what you mean by “the standard floating bus”—the floating bus on the 48K/128K/+2 as opposed to the +2A/+3. If there’s enough interest in the subject, I’ll do a separate writeup, something along the lines of “The Definitive Guide to Using the Floating Bus” with an actual example and make a separate post about it.
Last edited by Ast A. Moore on Mon Apr 16, 2018 9:24 am, edited 1 time in total.
2 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
djnzx48
Manic Miner
Posts: 463
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Double buffering on the Spectrum

Post by djnzx48 » Mon Apr 16, 2018 9:21 am

Sorry, I was meaning to ask how the +2A/+3 floating bus differs from on the Sinclair machines.
0 x

Post Reply