Exact emulation of the Snow effect.

Struggling with Fuse or trying to find an emulator with a specific feature. Ask your questions here.
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Exact emulation of the Snow effect.

Post by Weiv »

At the beginning of this year I promised to publish details of the exact snow effect emulation after publication of a new version of my emulator. Well, I changed my mind, the publication of new version of the emulator is planned later, and the details of the exact snow effect emulation I publish now, along with the update of my emulator Spectramine (1.05), in which the correct emulation of the snow effect was first implemented, and my snow effect tests, which are modifications of the snow test with a tuning table.

The snow effect is caused by the interference of two processes — reading screen data by the ULA and memory regeneration by the processor. Under certain conditions, the bits 6..0 of the register R are picked up in the bits 6..0 of the screen memory address set by the ULA on the address bus. In the course of my research, another effect was revealed, determined by the same reasons. I called it the double effect — under certain conditions, the interference of reading ULA screen data and memory regeneration leads to the fact that ULA cannot read the data of the next bar of pixels, and instead displays a bar of pixels with the data read earlier. This effect is perfectly visible on the ULA128 test written by azesmbog/zebest.

And now the actual results of the research — the necessary information for exact emulation of the snow effect.

A prerequisite for the snow effect: at 16/48/128/+2 machines snow appears if register I contains a value that, if it taken by the high byte of address, points to an address in the slow memory. For Spectrum 16/48 these are addresses #4000..#7FFF, for 128/+2 these are also addresses #C000… #FFFF, if a slow memory page is paged there, for 128/+2 these are pages with odd numbers — 1,3,5,7 (not 0,2,4,6).

There is no snow/double effects on Amstrad's black machines (+2A/+2B/+3/...) and on any ZX Spectrum clones except maybe those that based on original ULA.

Additionally, it turned out that on some 128 machines the snow effect leads to a hang / reset of the computer, and on some — it works ok.

Now about the snow phases. Snow phase means how a 4-tacts operation code fetching cycle overlaps an 8-tacts screen drawing cycle by ULA.

So:
1) If the 4th cycle of the operation code fetching cycle coincides with the 3th cycle of the 8-tacts output cycle of 16 pixels, this leads to snow effect — in the pixels1/attributes1 addresses the bit 6..0 of address is replaced with the current contents of the bits 6..0 of register R (it should already be increased in this operation code fetching cycle).

2) If the 4th cycle of the operation code fetching cycle coincides with the 5th cycle of the 8-tacts output cycle of 16 pixels, then this leads to a double effect — the pixels2/attributes2 data will not be read, and the screen bar with pixels1/attributes1 data will be re-displayed.

3) For the remaining variants of overlapping the operation code fetching cycle with the ULA screen drawing cycle, the ULA works normal, without snow and duplicate.

Image

I express my gratitude to Pheel (Alexander Filyanov) and balford (Brendon Alford), who, at my request, launched my tests on their machines, and shot the results in the videos. Also to NEO_SPECTRUMAN, TheMartian and Guesser, for help with a question of register R's participation in the snow effect.

My emulator Spectramine (1.05) with correct snow can be downloaded here: files.fm/u/r7cymnn9m

Snow tests, the old one and my modifications of it, and ULA128 test:
zx-pk.ru/attachment.php?attachmentid=77971&d=1666205428

Sorry for long wait and bad english)

(Snow.tap test is not entirely correct — under certain conditions there will be no running columns on the screen, which is due to the absence of alignment to the beginning of the frame. Try to load it with pressed Ctrl. Very fast running columns on the screen immediately after loading the tests are caused by an imperfect pause acceleration code between the tape blocks during loading).

TheMartian's addition:
— Pixels and attributes are read in «bursts». First the CAS signal is asserted, and the column address, (that's bits 6-0 of the video address), are set. Then the RAS signal is asserted twice, setting a row address (bits 13-7) which can point to a pixel byte and its attribute. The first RAS pulse is for the data byte, the second for the attribute, only bits 13-7 change.
— In RFSH cycles MREQ is asserted, and MREQ controls (is) CAS, and since MREQ is low in the first half of T4 it cancels contention, but it proceeds keeping fixed bits 6-0.
— So if it happens on this 3rd pixel cycle T-state, it's the first pixel/attribute burst, the CAS asserted the refresh address, so you get snow.
— If it happens on this 5th pixel cycle T-state, the CAS is kept low between the first and second bursts, so it keeps the bits 6-0 of the video address for the second burst. So, duplicate.

Recommendation for game writers — to avoid the snow effect you need to make sure that the register I does not point to slow memory, and the interrupt vector does not get into the slow memory. It is safer and easiest to place it in addresses $8000… $BFFF (register I within $80… $BF) — on machines with snow it's always fast memory page.

Update: Recently (04.2023) yet another snow peculiarity was open. When register I points to slow memory page on 128 machine, the page from where the snow bytes are fetched depends from: 1) on which slow page register I points; 2) what screen is active.
The table shows needed memory page for snow bytes fetching:

Code: Select all

  
  I-pointed page   Screen 0(page 5)     Screen 1(page 7)
     1                  1                   3 
     3                  1                   3
     5                  5                   7 
     7                  5                   7
 
In this table rows mean slow page number on which register I points to, columns mean active screen number, table cells mean from what page the snow bytes are fetched. Thanks to @TheMartian, @IceKnight and Richard Chandler for participation.

Updated by PJ at request of author

Text updated with latest additions by the author
User avatar
ZjoyKiLer
Dizzy
Posts: 67
Joined: Thu Sep 09, 2021 3:20 pm

Re: Exact emulation of the Snow effect.

Post by ZjoyKiLer »

THANK YOU VERY MUCH FOR THIS!!

THANK YOU!!
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

Also, video by @balford :
User avatar
NEO SPECTRUMAN
Microbot
Posts: 110
Joined: Tue Jan 26, 2021 10:27 pm

Re: Exact emulation of the Snow effect.

Post by NEO SPECTRUMAN »

so WUT about hardware/snow scroll? :mrgreen:
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

NEO SPECTRUMAN wrote: Wed Oct 19, 2022 9:15 pm so WUT about hardware/snow scroll? :mrgreen:
Only for even columns, alas)
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

Weiv wrote: Wed Oct 19, 2022 8:45 pm So:
1) If the 4th cycle of the operation code fetching cycle coincides with the 3th cycle of the 8-tacts output cycle of 16 pixels, this leads to snow effect - in the pixels2/attributes2 addresses the low byte of address is replaced with the current contents of the R register (it should already be increased in this operation code fetching cycle).
It's mistake - must be "pixels1/attributes1 addresses". So the Snow effect runs on odd columns (first,third,etc...), and the Double effect runs on even columns (second, fourth, etc...)/
Last edited by Weiv on Thu Oct 20, 2022 1:00 am, edited 1 time in total.
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

And the table with a bit more info:
Image
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

An obvious addition - there is no snow/double effects on Amstrad's black machines (+2A/+2B/+3/...) and on any ZX Spectrum clones except maybe those that based on original ULA.
TheMartian
Microbot
Posts: 100
Joined: Wed Feb 03, 2021 5:18 am

Re: Exact emulation of the Snow effect.

Post by TheMartian »

Awesome :)

Actually, if you think it, it makes sense:
- Pixels and attributes are read in "bursts". First the CAS signal is asserted, and the column address, (that's bits 7-0 of the video address), are set. Then the RAS signal is asserted twice, setting a row address (bits 13-8) which can point to a pixel byte and its attribute. The first RAS pulse is for the data byte, the second for the attribute, only bits 13-8 change.
- In RFSH cycles MREQ is asserted, and MREQ controls (is) CAS, and since MREQ is low in the first half of T4 it cancels contention, but it proceeds keeping fixed bits 7-0.
- So if it happens on this 3rd pixel cycle T-state, it's the first pixel/attribute burst, the CAS asserted the refresh address, so you get snow.
- If it happens on this 5th pixel cycle T-state, the CAS is kept low between the first and second bursts, so it keeps the bits 7-0 of the video address for the second burst. So, duplicate.

I had figured out the first burst part on my emulator, but not the second. Thank you!

Still the emulation is not yet perfect, but I think I can rule out the snow effect mechanics for the moment. I think that maybe how I implement the pipeline from reading video data to painting pixels may be 1 state off. (Serious hacks in there...) :)
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

@TheMartian , thanks! Alas, I am far from hardware details, so your explanation perfectly explains and complements my results.
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

And recommendation for game writers - to avoid the snow effect you need to make sure that the interrupt vector does not get into the slow memory. It is safer and easiest to place it in addresses $8000 ... $BFFF (register I within $80 ... $BF) - on machines with snow it's always fast memory page .
User avatar
NEO SPECTRUMAN
Microbot
Posts: 110
Joined: Tue Jan 26, 2021 10:27 pm

Re: Exact emulation of the Snow effect.

Post by NEO SPECTRUMAN »

а атрибуты от пикселей так отделить низя?

7-й бит R влият как нибудь? хотя наверно нет
но в описании то надо бы про это что то написать
что память 7х7 итд :dance
хотя тут пишут такое
In detail, the address which is actually read by the ULA is the following:

A15-A8 = A15-A8 of the ULA address
A7-A0 = the R register of the Z80
https://k1.spdns.de/Develop/Projects/zx ... guide.html

так же где найти гофносорцы гофнотеста?


так же не ясно как работает при этом contention
так проц может выжать больше тактов за строку?
ULA gets confused by the memory refresh cycles of the Z80 (performed during each instruction fetch), and it doesn't apply contention to take precedence as usual.
для звука вообще не важно что на экране
тогда можно включать I
и получать сплошную fastram?
так это нужно использоовать
а не расказывать про не ставьте i в slowram...
User avatar
NEO SPECTRUMAN
Microbot
Posts: 110
Joined: Tue Jan 26, 2021 10:27 pm

Re: Exact emulation of the Snow effect.

Post by NEO SPECTRUMAN »

what about this 2 cases?
Image

why there is no any glitches?

MOAR diagrams request
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

NEO SPECTRUMAN wrote: Thu Oct 20, 2022 2:40 pm а атрибуты от пикселей так отделить низя?
No.
Use English please. Or you can be banned here also)
7-й бит R влият как нибудь? хотя наверно нет
It affects as a 7th bit of address from where value is read.(upd. I'm not sure about it)
но в описании то надо бы про это что то написать
что память 7х7 итд :dance
You need - you write. For emulator writing it's not important.
так же где найти гофносорцы гофнотеста?
I lost them, but I can disassemble the code especially for you)

так же не ясно как работает при этом contention
так проц может выжать больше тактов за строку?
No, delays are usual.
Last edited by Weiv on Thu Oct 20, 2022 5:32 pm, edited 1 time in total.
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

NEO SPECTRUMAN wrote: Thu Oct 20, 2022 4:06 pm what about this 2 cases?
Image
3) For the remaining variants of overlapping the operation code fetching cycle with the ULA screen drawing cycle, the ULA works normal, without snow and duplicate.
why there is no any glitches?
Just because)
TheMartian
Microbot
Posts: 100
Joined: Wed Feb 03, 2021 5:18 am

Re: Exact emulation of the Snow effect.

Post by TheMartian »

Weiv wrote: Thu Oct 20, 2022 4:42 pm 3) For the remaining variants of overlapping the operation code fetching cycle with the ULA screen drawing cycle, the ULA works normal, without snow and duplicate.

Just because)
It can never happen, because these two fall in the middle of a pixel/attribute read. The column address (video address bits 6.0) are already fixed, and do not change until the burst has ended.

By burst reads I mean that reading pixel/attribute pairs are done like this:
1. Give memory the low bits. (6.0)
2. Give memory the high bits (13.7, pixel range)
3. Read pixel
4. Give memory the high bits (13.7, attr range), don't need to repeat (6.0) because these are the same.
5. Read attribute

These the ULA keeps bits 6.0 locked, asserting the CAS line for the entire burst read.
The Z80 can only hijack the burst read by asserting CAS before (snow, the address loaded in bits 6.0 comes from R), or between burst reads (duplicate, the Z80 simply extends the CAS signal, so the bits from the first burst read are kept)

The bit ranges in the address should be A13-A7 and A6-A0, because the RAM chips have only seven address lines. A15-A14 are not used for memory chips, but for selection logic. I don't know if this actually means that only bits 6.0 from register R affect the snow...
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

TheMartian wrote: Thu Oct 20, 2022 5:11 pm The bit ranges in the address should be A13-A7 and A6-A0, because the RAM chips have only seven address lines. A15-A14 are not used for memory chips, but for selection logic. I don't know if this actually means that only bits 6.0 from register R affect the snow...
I'm not really sure about it. Maybe really only bits 6..0 from register R affect the snow.
User avatar
NEO SPECTRUMAN
Microbot
Posts: 110
Joined: Tue Jan 26, 2021 10:27 pm

Re: Exact emulation of the Snow effect.

Post by NEO SPECTRUMAN »

Weiv wrote: Thu Oct 20, 2022 5:31 pm I'm not really sure about it. Maybe really only bits 6..0 from register R affect the snow.
so another test is request

looks like z80 put all 8 bits
The whole IR register is put on the address bus, and the RFSH pin is lowered
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

NEO SPECTRUMAN wrote: Thu Oct 20, 2022 5:32 pm The whole IR register is put on the address bus, and the RFSH pin is lowered.
Such a relief)
User avatar
NEO SPECTRUMAN
Microbot
Posts: 110
Joined: Tue Jan 26, 2021 10:27 pm

Re: Exact emulation of the Snow effect.

Post by NEO SPECTRUMAN »

maybe draw some like this
Image

turn on snow

and change R 7 bit on every 50 frames

or not...
User avatar
NEO SPECTRUMAN
Microbot
Posts: 110
Joined: Tue Jan 26, 2021 10:27 pm

Re: Exact emulation of the Snow effect.

Post by NEO SPECTRUMAN »

test
Image

expected results

r $00
Image

r $80
Image
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

@TheMartian , do you have a real ZX Spectrum with snow effect?
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: Exact emulation of the Snow effect.

Post by Weiv »

I write small test in BASIC to solve our little question about register R.
Can somebody here type and launch this test?

10 POKE 30000,62: POKE 30001,64: POKE 30002,237: POKE 30003,71: POKE 30004,201
20 PLOT 0,175: DRAW 255,0
30 RANDOMIZE USR 30000

And answer the question: is black stripes appears at whole upper screen third or only at it's upper half?
C.Born
Manic Miner
Posts: 239
Joined: Sat Dec 09, 2017 4:09 pm

Re: Exact emulation of the Snow effect.

Post by C.Born »

Hi
i used RVM emulator and it works very well while fuse(1.6.0) does not know it runs.
I made a 16k version of a border effect and tried to avoid snow by NOT using the #38 routines.
https://zxart.ee/eng/software/demoscene ... id:524423/

now my question is , does it realy work?
on RVM (in debian10) its snow free afaik, but thats an emulator, although it works 'perfect' with your routine.

i made a disas of the 130 bytes and maybe an all 16k version is possible.
timings are a bit different and maybe the straight effect will be ruined.
the routine you provide gives space to some nice effects like a dust storm or things alike.

But changing R_register influences the hardware direct of course. so it very limited in use
afaik bit 7 is not used and not set, but i can be wrong. i tried a RND based on R but it fails
TheMartian
Microbot
Posts: 100
Joined: Wed Feb 03, 2021 5:18 am

Re: Exact emulation of the Snow effect.

Post by TheMartian »

Weiv wrote: Thu Oct 20, 2022 7:07 pm @TheMartian , do you have a real ZX Spectrum with snow effect?
Got them all XD... 48K, 128K Toastrack, Grey +2... (but the Toastrack doesn't have the original ULA, so no snow I guess)
Post Reply