Interlace stuff

Got a programming project in mind? Tell everyone about it!
Post Reply
tom_seddon
Posts: 194
Joined: Mon Aug 29, 2005 11:42 pm
Contact:

Interlace stuff

Post by tom_seddon » Fri Sep 14, 2018 12:11 am

Kieran mentioned interlacing at the recent ABUG, and this got me thinking about it a bit. I always have interlace switched off, because of course when it's switched on, every other field has this half scanline offset, and I've always found the resulting 25Hz judder massively annoying.

I always knew that in principle interlace was there for displaying images with twice the vertical resolution of the display, so I'd tried in the past to do that manually (as you have to with the Beeb bitmap modes anyway since their output is effectively progressive). Here's a toy example: an 8x8 image, to be shown on an 8x4 display.
fig1.png
fig1.png (249.02 KiB) Viewed 329 times
Create one image, consisting of the even lines of the image.
fig2.png
fig2.png (141.4 KiB) Viewed 329 times
And another, consisting of the odd lines of the image.
fig3.png
fig3.png (127.86 KiB) Viewed 329 times
Then display them both, on alternate fields. Since I always have interlace switched off, the result I saw was always roughly like this diagram, where dark squares represent pixels lit on every field, and red squares those lit on alternate fields (i.e., the ones that flicker). It doesn't look very good to me, it certainly never looked all that much like twice the vertical resolution, and so I'd always dismissed it.
fig4.png
fig4.png (138.36 KiB) Viewed 329 times
But thinking about it, I realised, and better late than never I suppose, that the half scanline offset actually means you sort-of *do* have double the vertical resolution! So suppose you try again with the same pair of images, but this time with interlace on - and the result is more like this: (again, dark = lit, red = flicker)
fig5.png
fig5.png (180.64 KiB) Viewed 329 times
Note that on the non-flickering parts you've actually got the half scanline resolution you're looking for, and while the flickering area is larger in total, it's more like a fringe around the smoother non-flickering shape that you're trying to achieve.

(Interlacing actually works! Who knew?)

Here the odd rows are being displayed with the half scanline offset, so working down the screen you have row 0, then row 1, then row 2, and so on, all in their proper order. But if you're doing things manually, you can also display in the other way round, with the even rows getting the half scanline offset, so working down the screen you have row 1, then row 0, then row 3, and so on. You can probably guess this is going to look rubbish.
fig6.png
fig6.png (171.68 KiB) Viewed 329 times
Demo attached:
circle.ssd
(3.5 KiB) Downloaded 7 times
(B/Master, probably needs CRT)

It creates a 320x512 image of a circle, then displays it in Mode 4 with interlace off. Press I to switch interlace on, and it should look a bit better! (If it looks disastrous, you've hit the bad case I just described. Press SPACE to delay an extra field and sort it out. You can wait for an extra field with interlace off too, but it makes no lasting difference.)

--Tom

tom_seddon
Posts: 194
Joined: Mon Aug 29, 2005 11:42 pm
Contact:

Re: Interlace stuff

Post by tom_seddon » Fri Sep 14, 2018 12:40 am

Another demo, which is the one I was originally going to write when I suddenly realised the above!

More toy examples, this time vertical motion on a 1x6 display. Suppose you've got a pixel moving downwards at 50Hz; you're going to see the following fields as you watch it move.
50hz_noninterlaced.png
50hz_noninterlaced.png (134.35 KiB) Viewed 326 times
And at 25Hz, you'd see the following.
25hz_noninterlaced.png
25hz_noninterlaced.png (133.92 KiB) Viewed 326 times
You can probably imagine what these two cases might look like, with the 50Hz one appearing nice and smooth, and the 25Hz one appearing a touch juddery, I think because the motion doesn't quite match up with the CRT flicker.

But with interlace, you get some downward motion for free, because alternate frames are shifted half a scanline down! So you can move things downwards pixel by pixel at 25Hz while maintaining that nice smooth 50Hz look:
25hz_interlaced.png
25hz_interlaced.png (135.37 KiB) Viewed 326 times
Here's a demo of it:
interlaced_animation.ssd
(3 KiB) Downloaded 5 times
Initially, it shows vertical lines moving at 50Hz with interlace off.

Press I to toggle interlace: I=0 means it's off, I=1 means it's on.

Press W to toggle 25Hz/50Hz: W=1 is 50Hz, W=2 is 25Hz.

Compare 25Hz interlaced motion with 50Hz and 25Hz non-interlaced motion!

(As with the other demo, if you hit the nasty interlace case, press SPACE.)

--Tom

cmorley
Posts: 616
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford
Contact:

Re: Interlace stuff

Post by cmorley » Fri Sep 14, 2018 6:08 am

This is what I did for my mode 0 640x512 Bad Apple demo. LCDs will incorrectly de-interlace the 256p giving you the same effect but with different timing. They introduce their own artefacts though due to various image enhancing :lol: filters.

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

Re: Interlace stuff

Post by RobC » Fri Sep 14, 2018 8:33 am

There are a couple of other demos of (what I think is) this technique on GLM PD disks 8 and 9 by Lars Osterballe at 8bs.

I vaguely remember typing in something from Acorn User on my Master that claimed to draw a circle in 640x512 but I couldn't get it to work! This would have been sometime between 1988 and 1990. It's nice to finally see an example of it working :D
Last edited by RobC on Fri Sep 14, 2018 8:34 am, edited 1 time in total.

User avatar
Rich Talbot-Watkins
Posts: 1339
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Interlace stuff

Post by Rich Talbot-Watkins » Fri Sep 14, 2018 9:21 am

And the interlaced sync and video mode can be used to ensure the even field reads even addresses, and the odd field (which is offset by half a scanline) reads odd addresses, thus avoiding the problem with the fields being out of sync with the rendering. The only problem is you have to use the Beeb's screen memory for *both* fields, which typically means needing a reduced size Mode 0; shadow RAM can't really help here.

User avatar
jgharston
Posts: 3184
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Interlace stuff

Post by jgharston » Fri Sep 14, 2018 9:24 am

Rich Talbot-Watkins wrote:
Fri Sep 14, 2018 9:21 am
And the interlaced sync and video mode can be used to ensure the even field reads even addresses, and the odd field (which is offset by half a scanline) reads odd addresses, thus avoiding the problem with the fields being out of sync with the rendering. The only problem is you have to use the Beeb's screen memory for *both* fields, which typically means needing a reduced size Mode 0; shadow RAM can't really help here.
It can if you toggle between each screen bank on each field. I remember the Acorn User article, on my monitor it flickered unacceptably. I'll see if I can find it.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
Rich Talbot-Watkins
Posts: 1339
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Interlace stuff

Post by Rich Talbot-Watkins » Fri Sep 14, 2018 9:41 am

jgharston wrote:
Fri Sep 14, 2018 9:24 am
It can if you toggle between each screen bank on each field. I remember the Acorn User article, on my monitor it flickered unacceptably. I'll see if I can find it.
Yeah, I guess if you get the timing perfect, and switch displayed bank just before line 128 is rasterised, you could do it. You'd have to make a point of ensuring it didn't coincide with any other interrupt, e.g. if the OS 100Hz interrupt happened just before line 128, it would lead to unnecessarily high latency. You'd need to reset the timer at a 'safe' moment during rasterisation, and even then keyboard interrupts might cause a problem. If you were operating with an entirely custom IRQ handler, this is probably no problem.

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

Re: Interlace stuff

Post by RobC » Fri Sep 14, 2018 11:23 am

Rich Talbot-Watkins wrote:
Fri Sep 14, 2018 9:41 am
Yeah, I guess if you get the timing perfect, and switch displayed bank just before line 128 is rasterised, you could do it.
Could you get around this by using a bit more memory in the first bank to duplicate the first row of the second bank (640 bytes)? So set the main display up from 0x2D80 - 0x7FFF. Then, some time during the duplicate row, switch to shadow memory and set R12 and R13 of the CRTC to point back to 0x3000?
Last edited by RobC on Fri Sep 14, 2018 11:24 am, edited 1 time in total.

User avatar
Rich Talbot-Watkins
Posts: 1339
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Interlace stuff

Post by Rich Talbot-Watkins » Fri Sep 14, 2018 3:18 pm

That would require a vertical rupture type technique, but I'm uncertain whether that even works in interlaced modes; it depends whether the crtc uses R4 or R7 to determine when to toggle the field type. It would work if it were the latter.

tom_seddon
Posts: 194
Joined: Mon Aug 29, 2005 11:42 pm
Contact:

Re: Interlace stuff

Post by tom_seddon » Fri Sep 14, 2018 11:06 pm

Thanks for the note about interlace sync & video! I'd never really played around with that before either, but I've had a quick go now, and here's another interlace demo: SUPER MODE 8, the graphics mode you never knew you wanted.
supermode8.ssd
(1.5 KiB) Downloaded 11 times
(Unlike the others, a real CRT is strictly optional for this one - and in fact, it looks much nicer on jsbeeb, which shows you the full vertical resolution on its emulated TV.)

--Tom

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

Re: Interlace stuff

Post by tricky » Sat Sep 15, 2018 7:41 am

jsbeeb isn't doing a great job of representing what that looks like on a beeb+CRT, b-em with your screen refresh set to 50Hz is the closest.

tom_seddon
Posts: 194
Joined: Mon Aug 29, 2005 11:42 pm
Contact:

Re: Interlace stuff

Post by tom_seddon » Sat Sep 15, 2018 4:58 pm

True, but in this case I feel the emulation inaccuracy is a *good* thing, because it looks nice on jsbeeb, horrid on a CRT, and the effect is so useless I'm not sure it matters anyway ;)

--Tom

P.S. I've been doing all this stuff with Master 128+SCART lead+CRT - but I got my BBC B running again this afternoon, and tried this stuff on it too, connected to an LCD TV with a SCART lead.

Interlaced circle demo: the TV couldn't seem to distinguish the interlaced/non-interlaced cases, so it tried to deinterlace them the same way in both cases, producing effects a bit similar to the CRT + interlace on.

Moving lines demo: the overall effect was actually rather similar to seeing it on a CRT, with (when interlaced the right way round) 25Hz interlaced looking smooth like 50Hz non-interlaced.

Super Mode 8: after a few dodgy-looking frames the TV seemed to get itself together and display a full-resolution image quite similar to what you see in jsbeeb.
Last edited by tom_seddon on Sat Sep 15, 2018 5:01 pm, edited 2 times in total.

User avatar
Rich Talbot-Watkins
Posts: 1339
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Interlace stuff

Post by Rich Talbot-Watkins » Sat Sep 15, 2018 5:27 pm

B-Em can be coaxed into displaying it in the same way as jsbeeb by selecting Settings -> Video -> Display type -> Interlaced.

It's really hard to know how to display a 50Hz emulated screen on a PC with an arbitrary monitor refresh rate. If you don't mind the latency, you can run a frame in advance and interpolate between the previous and current frames according to the moment in time that PC screen refresh happens. I'd like to try this in jsbeeb one of these days, but never find the time (and I suspect it might look horrible!).

(Incidentally this is considered the best way these days to implement games running on platforms not tied to a fixed frame rate: implement an update rate independent of the refresh rate, and use interpolation to render at a point in between the two last updates according to when screen refresh happened. It was so much easier when we used to just use *FX19 :) )
Last edited by Rich Talbot-Watkins on Sat Sep 15, 2018 5:30 pm, edited 1 time in total.

Post Reply