Games behaving differently on the Next

The Speccy's spritely young offspring. Discuss everything from FPGA to ZX
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: Games behaving differently on the Next

Post by Alcoholics Anonymous »

Heimdall wrote: Wed Jun 17, 2020 8:18 am Could you please elaborate a bit on 128K ? I'm asking as I would love to have a parallel [to Next] codepath for a 3.5 MHz rasterizer. Save for 1-bit vs 8-bit, most of rest of the code should be same.

I plan to use a few larger LUTs, hence 128 KB. From what I've seen so far, cycle differences between Pentagon and regular Spectrum aren't huge - well as long as one is only doing low-framerate game, anyway. Couple thousands cycles per frame difference shouldn't matter in a ~10 fps scenario, I reckon.
The 128K Spectrums have 70908 T in a frame and the Pentagon 128 has 71680 T. A big difference is that the Pentagon has no contention so that difference is actually larger than it seems if a good deal of time is spent accessing contended memory like the display file.

A couple of websites that give an overview of differences between the models can be found below. They're not complete and not too in depth but they give a good idea about the main issues.

https://faqwiki.zxnet.co.uk/wiki/ZX_Spectrum_128
https://spectrumforeveryone.com/technic ... ty-issues/

For the 128K machines the main thing is that the contended banks are different. The original 128K and +2 contend odd memory banks 1, 3, 5, 7 due to a hardware bug (the intention was to contend banks 4, 5, 6, 7). The +2A/+3 contends banks 4, 5, 6, 7. Amstrad was likely following the original design spec instead of the reality of the first 128K models when it made the +3.

The contention method is also different between the 128K/+2 on the one hand and the +2A/+3 on the other. The former stops the cpu clock and the latter uses the /wait signal and in a different set of circumstances. This leads to different secondary behaviour when programs affected by contention run.

Lastly the floating bus behaviour is different. The 128K/+2 sees the same sort of floating bus behaviour as the 48K and a small number of programs used that to snoop on the ULA to find out which part of the screen was being drawn. Until recently it was thought the +2A/+3 had no floating bus behaviour but it turns out it does, though it must be detected in a different and incompatible way.

If you're writing new software the main thing to worry about is which memory banks are contended because accessing data or executing programs out of contended memory is a lot slower. Because the 128K/+2 and +2A/+3 contend different banks, programs oblivious to this will run more slowly on one machine than the other. There is a huge gotcha in connection to contended ram however --- if the I register points at contended memory and you're executing code out of a contended memory bank, you can cause the machine to crash. I don't know the exact mechanism for this but it has been seen in modern day games, tested on a 128K spectrum, but found to crash on a +2A. Anyway the main outcome of all these words is that you should point I at uncontended memory and you may want to change what memory banks you load stuff into depending on the model so that your code/data sits in (un)contended memory as you intend irrespective of the model.
Patrik Rak
Microbot
Posts: 116
Joined: Mon Apr 13, 2020 3:07 pm

Re: Games behaving differently on the Next

Post by Patrik Rak »

Alcoholics Anonymous wrote: Thu Jun 18, 2020 12:15 am For the 128K machines the main thing is that the contended banks are different. The original 128K and +2 contend odd memory banks 1, 3, 5, 7 due to a hardware bug (the intention was to contend banks 4, 5, 6, 7). The +2A/+3 contends banks 4, 5, 6, 7. Amstrad was likely following the original design spec instead of the reality of the first 128K models when it made the +3.
Where does this info (that it was a bug) come from?

I was under the impression that the choice for 128K was deliberate. They only needed to contend two banks, for normal and shadow screen. But they wanted to make it cheap, so they have chosen just single line to select it, rather than using two lines and a gate. The fact that they have chosen the lowest bit and made it odd and even is as good choice as choosing the topmost bit. (It is also consistent with why they have chosen the banks 2 and 0 to be mapped in by default, rather than 1 and 0, and why the normal and shadow screen is 5 and 7, rather than 6 and 7. I mean, this is a hint they were very much aware of what was contended and what wasn't.)

IMO the only reason why Amstrad changed it later is that they wanted to have one of the all-ram modes entirely uncontended. It's natural that they wanted to have all ram modes for linear blocks, so 0,1,2,3 and 4,5,6,7 make sense (the remaining 4,5,6,3 is just one way of making it possible to switch between the two, and 4,7,6,3 is just that with shadow screen mapped in). Because 5 and 7 must be contended, they have chosen to contend the 4,5,6,7 block. Again, they could have chosen to contend just 5 and 7, but you know, those gates don't come free. :)

Patrik
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: Games behaving differently on the Next

Post by Alcoholics Anonymous »

Patrik Rak wrote: Thu Jun 18, 2020 9:11 am Where does this info (that it was a bug) come from?
It's coming from the Derby design spec (which I have never seen nor can I find it in a quick google search) and the 128K service manual. The 128K service manual clearly documents banks 4,5,6,7 as contended (VA14 and VA15 are not in a don't care state for those banks) even though the reality is banks 1,3,5,7 are contended. So I think it's very likely Amstrad used these documents for the +3 and produced the 4,5,6,7 contention that it got.

It seems likely Amstrad never understood how contention was applied on the Spectrum either and just gave up to produce the /wait method they actually used. This is more in line with how the CPC machines work which round up the machine cycles to 4T using the /wait signal.

Everything else you said makes sense but the same could have been achieved with 1,3,5,7 contention by using different bits as input to the hardware :)
Patrik Rak
Microbot
Posts: 116
Joined: Mon Apr 13, 2020 3:07 pm

Re: Games behaving differently on the Next

Post by Patrik Rak »

Thanks for the info, one learns something new every day. I never had a 128K myself, and neither that manual. I am in fact surprised they mentioned contention at all, I don't remember something like that ever mentioned in a 48K manual. For us, it was a matter of trial and error to find out that you really can't have a sound routine below 32768 :). Good old days...
AndyC
Dynamite Dan
Posts: 1403
Joined: Mon Nov 13, 2017 5:12 am

Re: Games behaving differently on the Next

Post by AndyC »

Alcoholics Anonymous wrote: Thu Jun 18, 2020 12:15 amThere is a huge gotcha in connection to contended ram however --- if the I register points at contended memory and you're executing code out of a contended memory bank, you can cause the machine to crash. I don't know the exact mechanism for this but it has been seen in modern day games, tested on a 128K spectrum, but found to crash on a +2A. Anyway the main outcome of all these words is that you should point I at uncontended memory and you may want to change what memory banks you load stuff into depending on the model so that your code/data sits in (un)contended memory as you intend irrespective of the model.
It's actually the other way around, pointing I at uncontended memory is fine on a +2A/+3, but causes issues on a 128 or original +2. The +3 manual suggests it can theoretically cause a crash although I don't think anyone has successfully proved a guaranteed repro case for that. It certainly does cause snow issues on the display. Best avoided in any case.
AndyC
Dynamite Dan
Posts: 1403
Joined: Mon Nov 13, 2017 5:12 am

Re: Games behaving differently on the Next

Post by AndyC »

Alcoholics Anonymous wrote: Thu Jun 18, 2020 3:30 pm
Patrik Rak wrote: Thu Jun 18, 2020 9:11 am Where does this info (that it was a bug) come from?
It's coming from the Derby design spec (which I have never seen nor can I find it in a quick google search) and the 128K service manual. The 128K service manual clearly documents banks 4,5,6,7 as contended (VA14 and VA15 are not in a don't care state for those banks) even though the reality is banks 1,3,5,7 are contended. So I think it's very likely Amstrad used these documents for the +3 and produced the 4,5,6,7 contention that it got.

It seems likely Amstrad never understood how contention was applied on the Spectrum either and just gave up to produce the /wait method they actually used. This is more in line with how the CPC machines work which round up the machine cycles to 4T using the /wait signal.

Everything else you said makes sense but the same could have been achieved with 1,3,5,7 contention by using different bits as input to the hardware :)
Yes, I had a conversation with Cliff Lawson back in the CSS days where he attributed this to design documents containing an error that wasn't picked up until far too late in the day to change things. He also said that documentation on how the 128s actually worked was, at best, scant and had Amstrad engineers scratching their heads at why things had been done that way and having to just do what they could to get something that actually worked, which probably explains why the contention implementation is closer to how it is implemented on the CPC.
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: Games behaving differently on the Next

Post by Alcoholics Anonymous »

Yeah I am not surprised that Sinclair had little in the form of documentation. The engineers at Timex encountered similar problems and ended up hiring Dr Ian Logan as consultant for extending the Basic (or was it Andy Pennell? I can't remember anymore -- there was someone though). That part is easy to understand as Nine Tiles wrote Sinclair basic and Sinclair wasn't any help there.

Even with resources like Chris Smith's ULA book, it was still not straightforward to iron out all the edge cases in the Next's ULA implementation.
Last edited by Alcoholics Anonymous on Fri Jun 19, 2020 4:00 pm, edited 2 times in total.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Games behaving differently on the Next

Post by Ast A. Moore »

AndyC wrote: Fri Jun 19, 2020 11:12 am The +3 manual suggests it can theoretically cause a crash although I don't think anyone has successfully proved a guaranteed repro case for that. It certainly does cause snow issues on the display. Best avoided in any case.
Indeed. I tried my best to crash a Toastrack this way (there’s even a thread on that at WoS), but all I got was the snow. Couldn’t crash it for the life of me. I even used the example Alvin had posted, citing somebody else, which was supposed to guarantee a crash. Nada.
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
bob_fossil
Manic Miner
Posts: 654
Joined: Mon Nov 13, 2017 6:09 pm

Re: Games behaving differently on the Next

Post by bob_fossil »

Alcoholics Anonymous wrote: Thu Jun 18, 2020 3:30 pm
It's coming from the Derby design spec (which I have never seen nor can I find it in a quick google search)
Is this it? I downloaded it many moons ago.

http://www.thefossilrecord.co.uk/wp-con ... bySpec.pdf
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: Games behaving differently on the Next

Post by Alcoholics Anonymous »

Yes cheers Bob. There it is on page 2.
ICEknight
Drutt
Posts: 1
Joined: Mon Jun 29, 2020 2:49 pm

Re: Games behaving differently on the Next

Post by ICEknight »

Alcoholics Anonymous wrote: Wed Jun 17, 2020 6:03 amThere is minor willy demo program about that runs on a 48K and relies on analog effects to display different brightness on the screen -- this sort of thing is not going to display properly on the Next.
That sounds interesting to try on old hardware, which demo is that?
azesmbog
Manic Miner
Posts: 307
Joined: Sat May 16, 2020 8:43 am

Re: Games behaving differently on the Next

Post by azesmbog »

ICEknight wrote: Mon Jun 29, 2020 2:54 pm That sounds interesting to try on old hardware, which demo is that?
Maybe this is a demo of Walking Manic Miner
http://www.zxuno.com/forum/download/fil ... 7e047ce164

Well, you can also check the correct four squares on old equipment
Spoiler
Nobody showed the correct picture on the Next one. Is it really repaired?))
ZX48
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Games behaving differently on the Next

Post by Seven.FFF »

azesmbog wrote: Mon Jun 29, 2020 10:08 pm Nobody showed the correct picture on the Next one. Is it really repaired?))
Not yet. It's on the list of things to look at when the CPU is revisited, along with MEMPTR and SCF/CCF. That'll happen after a few other things get finished. The fixes already done in the MISTer can't just be copied verbatim because they don't deal with the expansion bus or hardware signals for attached devices. So it'll need some extra work too.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Pegaz
Dynamite Dan
Posts: 1210
Joined: Mon Nov 13, 2017 1:44 pm

Re: Games behaving differently on the Next

Post by Pegaz »

ICEknight wrote: Mon Jun 29, 2020 2:54 pm
Alcoholics Anonymous wrote: Wed Jun 17, 2020 6:03 amThere is minor willy demo program about that runs on a 48K and relies on analog effects to display different brightness on the screen -- this sort of thing is not going to display properly on the Next.
That sounds interesting to try on old hardware, which demo is that?
We mentioned this a couple of times before, here are all the programs that demonstrate this ULA effects:
https://gofile.io/d/NvIh7Y

Apart from the real hardware, currently only the ZX Spin emulator can display all these examples correctly.
Unfortunately, SpecEmu with newer versions (from the last year and a half) does not display the "stripes" demo correctly.
I hope Woody corrects this in future versions.
Post Reply