MODE 2 Vertical Scrolling on the Electron

Discuss all aspects of programming here. From 8-bit through to modern architectures.
User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

MODE 2 Vertical Scrolling on the Electron

Postby davidb » Tue Feb 21, 2017 5:35 pm

I've been getting distracted again. :)

Using the Electron's capability to run code a bit faster from ROM when using MODEs 0-2, I've been experimenting with a ROM-based scrolling routine. You can see the results in this video. The first scroll-through updates the scroll offset every two frames; the second updates every frame.

It's at least possible to plot a few tiles each frame, and that's enough to keep the background updated and looking reasonably smooth. I haven't tried on a real Electron yet, though simple scrolling of a static screen works fine on both Elkulator and a real Electron.

I've attached the map I used for the demo. I think it looks nice when scaled down and shown in its entirety. :D
Attachments
MODE_2_scrolling_level.png

User avatar
oss003
Posts: 2554
Joined: Tue Jul 14, 2009 11:57 am
Location: Netherlands
Contact:

Re: MODE 2 Vertical Scrolling on the Electron

Postby oss003 » Tue Feb 21, 2017 5:59 pm

Nice job David =D>

If you need some backgrounds: http://www.zx-spectrum.cz/maps-direct.php

Greetings
Kees

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: MODE 2 Vertical Scrolling on the Electron

Postby davidb » Tue Feb 21, 2017 6:19 pm

Thanks, Kees. :)
That site is ... overwhelming! ;)

RobC
Posts: 1823
Joined: Sat Sep 01, 2007 9:41 pm

Re: MODE 2 Vertical Scrolling on the Electron

Postby RobC » Tue Feb 21, 2017 10:07 pm

That's really excellent.

How is the scrolling implemented? (I know how vertical rupture works on a Beeb but don't know as much about the Electron...)

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: MODE 2 Vertical Scrolling on the Electron

Postby davidb » Tue Feb 21, 2017 11:56 pm

Thanks, Rob. :)

It works by starting in MODE 3 then switching to MODE 2 after a certain number of scanlines. The same trick was used in Electron Firetrack, only that switched from MODE 6 to MODE 5.

Let's start at the end result and work backwards. The end result is vertical scrolling in two scanline increments. This is done by vertically displacing the visible part of the display by increasing amounts in four steps, then we change the screen start address and begin again with zero displacement. We get the displacement from the mode switch which we perform after a certain number of scanlines. The more scanlines we wait before switching, the more displacement we get.

For zero displacement, we switch to MODE 2 almost immediately. The second MODE 2 text line is the usual 8 scanlines below the first.
For 2 lines displacement, we switch after ten scanlines. The first text line remains where it always is but, because it is MODE 3, it includes 2 blank scanlines that do not contain any data from screen memory. This means that the second text line is in MODE 2 and 10 scanlines after the first, which is 2 scanlines lower than it would usually be. All other text lines are also 2 scanlines lower than normal.
For 4 lines displacement, we switch after twenty scanlines. The first 2 text lines are each 8 + 2 scanlines high and the third text line is in MODE 2 and 4 scanlines lower than normal.
For 6 lines displacement, we switch after thirty scanlines. The first 3 text lines are each 8 + 2 scanlines high and the fourth text line is in MODE 2 and 6 scanlines lower than normal.

There is also the matter of hiding all this mode switching. We blank the palette at the top of the display and set it after switching to MODE 2, but only after around 40 scanlines. This means that, after switching mode, we just wait until the right time to enable the palette again.

I hope that makes sense. There's a lot of tweaking involved, so not everything is as exact as I describe. ;)

I would have thought that the same technique should work on the Beeb. Has it been used by anyone?

User avatar
tricky
Posts: 1922
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: MODE 2 Vertical Scrolling on the Electron

Postby tricky » Wed Feb 22, 2017 8:05 am

We (Gil and I) changed the number of blank lines at the top of the screen to move it down, which is similar, but as we never got the timing perfect to takethem out again at the bottom we didn't use it. I think this is what Orlando used for Firetrack on the beeb.

RobC
Posts: 1823
Joined: Sat Sep 01, 2007 9:41 pm

Re: MODE 2 Vertical Scrolling on the Electron

Postby RobC » Wed Feb 22, 2017 9:41 am

Thanks for the explanation - it makes the demo even more impressive! =D>

User avatar
uniforix
Posts: 26
Joined: Sun Apr 21, 2013 9:57 pm
Contact:

Re: MODE 2 Vertical Scrolling on the Electron

Postby uniforix » Tue Sep 19, 2017 7:12 pm

Wow, this is great, don't really understand but really interesting and smooth scrolling, maybe one day I will figure it out :)

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: MODE 2 Vertical Scrolling on the Electron

Postby davidb » Tue Sep 19, 2017 9:21 pm

Perhaps the following diagram will help:
Image
It shows, from left to right, the top-left corner of the screen for the first 5 frames of the scrolling demo, except that I've set the palette to all white for the first 32 scanlines.

Image
In the first frame, all the screen is MODE 2, so the text is where you would expect it to be without any fancy tricks.

Image
In the second frame, the first 10 scanlines are used to display MODE 3. Even though the palette is all white, the ULA still shows 2 blank scanlines. Everything after that is MODE 2. However, because we switched back to MODE 2 after 10 scanlines, everything after this point is shifted down by 2 scanlines.

Image
In the third frame, the first 20 scanlines are used to display MODE 3 so we see two gaps. Now things are shifted down by 4 scanlines.

Image
In the fourth frame, the first 30 scanlines show MODE 3 and we see three gaps for the three text lines you get with this mode, and all the MODE 2 content is shifted down by 6 scanlines as a result.

Image
In the fifth frame, we do the same as the first frame except that the screen start address has been moved "upwards" in memory to a lower address. This causes the screen data to be moved down by 8 scanlines.

So, we do the MODE switching to shift everything down by 2 scanlines for each frame then reset it every four frames to move to a new screen start address. Because everything below the white area in the fourth frame is shifted by 6 scanlines, when we disable MODE switching for the fifth frame and change the screen start address, it again looks like everything only moved by 2 scanlines.

Of course, in the real demo I blanked the palette at the top of the screen so that you wouldn't notice the MODE change. :)
Attachments
f4.png
(362 Bytes) Not downloaded yet
f3.png
(346 Bytes) Not downloaded yet
f2.png
(352 Bytes) Not downloaded yet
f1.png
(361 Bytes) Not downloaded yet
f0.png
(364 Bytes) Not downloaded yet
frames.png

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: MODE 2 Vertical Scrolling on the Electron

Postby davidb » Tue Sep 19, 2017 10:52 pm

It seems I forgot to upload the code until now. It's in this repository for those who are curious.


Return to “programming”

Who is online

Users browsing this forum: No registered users and 1 guest