Star Wars Scroller Routine

Show us what you're working on, (preferably with screenshots).
Post Reply
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Star Wars Scroller Routine

Post by Joefish »

This function scrolls the screen in a 'Star Wars' style and can be called from BASIC.
Start by printing up to 16 characters of text in the top-left corner of the screen, hidden by using the same INK and PAPER colour, then call this routine 16 times. Print another line of text, and repeat.

It expands the text 2x, then scrolls it up the screen, squeezing as it goes. Note that it draws in the bottom two lines of the screen that you can't normally print on from BASIC, so you have to POKE the desired attributes in to those addresses before you run it (see the BASIC demo).

Image

Demo and source code: http://railtron.com/files/spectrum/StarWarsScroller.zip

No doubt it can be optimised a lot. Also it could be tweaked to not always wipe out the same pair of doubled-up pixels quite so quickly (where some of the upright lines in the text vanish altogether too soon), but it's too hard for me to work out right now.
User avatar
R-Tape
Site Admin
Posts: 6409
Joined: Thu Nov 09, 2017 11:46 am

Re: Star Wars Scroller Routine

Post by R-Tape »

Image

This is great @Joefish! And thanks for making it available for general use—I'm already loosely thinking about Woot.
User avatar
Morkin
Bugaboo
Posts: 3277
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Star Wars Scroller Routine

Post by Morkin »

Great stuff....!

I would've 100% thought someone would've done this scroll before, but not sure I've seen one till now.

Ooh... Ooh... I wonder if it'd be possible to do this scrolling message while the game is loading..? That would've been awesome back in 87/88 8-)

(Oi - stop throwing things at me..! :lol: )
My Speccy site: thirdharmoniser.com
User avatar
R-Tape
Site Admin
Posts: 6409
Joined: Thu Nov 09, 2017 11:46 am

Re: Star Wars Scroller Routine

Post by R-Tape »

Now we just need the Star Wars tune as an AY track (don't suppose you fancy it @Lee Bee? :mrgreen: )
Morkin wrote: Sat Aug 19, 2023 11:27 pm Ooh... Ooh... I wonder if it'd be possible to do this scrolling message while the game is loading..? That would've been awesome back in 87/88 8-)
Come to think of it, I can't think of any custom loaders that have even a regular text scroller. But if Joe Blade can have Pacman then this must be possible too.
User avatar
arkannoyed
Manic Miner
Posts: 438
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: Star Wars Scroller Routine

Post by arkannoyed »

Bobby Bearing
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Star Wars Scroller Routine

Post by Ast A. Moore »

R-Tape wrote: Sun Aug 20, 2023 2:02 pm Come to think of it, I can't think of any custom loaders that have even a regular text scroller.
Vectron.
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
Lee Bee
Dynamite Dan
Posts: 1297
Joined: Sat Nov 16, 2019 11:01 pm
Location: Devon, England
Contact:

Re: Star Wars Scroller Routine

Post by Lee Bee »

R-Tape wrote: Sun Aug 20, 2023 2:02 pm Now we just need the Star Wars tune as an AY track (don't suppose you fancy it @Lee Bee? :mrgreen: )
Jason's scroller came about on @HEXdidnt's Empire Strikes Back thread, where I posted a (technically impossible) visual of how such a scroller could look, postulating that some whizz coder might actually be able to achieve something like this—which Jason proved correct! Much earlier in that thread, I also posted a Star wars tune. Only a work-in-progress, but I shall be completing it for HEX's upcoming slideshow :dance
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Star Wars Scroller Routine

Post by Joefish »

Takes up far too much CPU time to be used in a loader. It could be optimised; it's copying up whole pixel rows every time rather than narrowing its efforts as the text narrows. But it'd still be far too intensive.

I can maybe tweak it to better preserve the legibility of the text, and moving it up two rows would help with calling it from BASIC.
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Star Wars Scroller Routine

Post by Joefish »

Sick of browsers that refuse to even pull a sodding GIF off a site that doesn't have SSL. Bunch of gits.
And apparently I can't spell 'Fortresses'. Then again 16 letters on a line is not a lot. I guess you could do better with proportional printing.

Image

https://cluster3.secure-staging.uk/rail ... roller.zip
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Star Wars Scroller Routine

Post by Joefish »

R-Tape wrote: Sat Aug 19, 2023 8:05 pm Image
Not sure how you're getting stray blank lines across that. It should copy each line up from the line below, before moving down to do the the next one. So even if there's raster tearing there shouldn't be any blank lines in the screen memory at any time.
User avatar
R-Tape
Site Admin
Posts: 6409
Joined: Thu Nov 09, 2017 11:46 am

Re: Star Wars Scroller Routine

Post by R-Tape »

Joefish wrote: Mon Aug 21, 2023 3:03 pm Not sure how you're getting stray blank lines across that. It should copy each line up from the line below, before moving down to do the the next one. So even if there's raster tearing there shouldn't be any blank lines in the screen memory at any time.
Not sure why, but that happens when I BREAK into the BASIC near the start of the scrolling, and then RUN 40. If I wait for it to do a full loop it seems okay. I haven't used the asm listing yet.
User avatar
flatduckrecords
Manic Miner
Posts: 787
Joined: Thu May 07, 2020 11:47 am
Location: Oban, Scotland
Contact:

Re: Star Wars Scroller Routine

Post by flatduckrecords »

I noticed that in Fuse. Emulator bug maybe?
User avatar
flatduckrecords
Manic Miner
Posts: 787
Joined: Thu May 07, 2020 11:47 am
Location: Oban, Scotland
Contact:

Re: Star Wars Scroller Routine

Post by flatduckrecords »

Thanks for sharing this @Joefish, I've been having fun adapting it to SAM's screen MODE 3.
Joefish wrote: Sat Aug 19, 2023 12:27 am It expands the text 2x, then scrolls it up the screen, squeezing as it goes.
Can you explain a wee bit about the squeezing, and in particular how you derived the numbers for the shift_table please?

Each line that it operates on is now 384px wide (96 bytes at 2bpp) up from 256px (and 32 bytes at 1bpp). I've adjusted the loops and tripled each of the values (which gives the result pictured) but I'd like to make the angles *steeper* (i.e. make the upper rows narrower) so that the perspective looks correct. Can you give me any pointers?

User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Star Wars Scroller Routine

Post by Joefish »

flatduckrecords wrote: Wed Aug 23, 2023 1:15 pm Can you explain a wee bit about the squeezing, and in particular how you derived the numbers for the shift_table please?
It was all vague guesswork.

The number indicates how many bytes, counting from the left, get rotated by 1 pixel to the right, before the rest are just copied up from the line below. On the next line, the same value is used, but this time counting in from the right. So it manages to lose a pixel somewhere along each line, but always at a byte boundary. Each value in the shift_table thus corresponds to two lines of the screen and thus two entries from the line address table. Note there are 80 entries in the shift_table, and the scroll works over 160 rows. The number in the table should be 15 or less, such that the point where a pixel is lost never crosses the centre of the screen.

First, you have to keep track of how wide the scroll is at each row, and make sure the number you've chosen extends as far as the remaining pixels. Or else it'll just take a pixel out of the empty space beside the scroller. You judge this because every 16 rows the scroll gets 16 pixels narrower, 8 in from the left and 8 in from the right. You could add an extra factor to the table to skip the blank space on a row first, if you'd like to optimise it a bit.

Then it's guesswork. I start from the bottom up; pick a number somewhere part-way along the row, from 0-15. Then another, and another. I try to distribute them evenly along the row, scattering back and forth, for 8 numbers picked from 1-15. That's the last group of numbers labelled with the ';1' comment.

The next row up, labelled ';2', the scroll is now a byte narrower, so the numbers must be from 2-15, and so-on, up to the top, where the numbers run from 10-15. The last few use '16' so everything shifts inward 1 pixel, to help with aligning the stipple that gets applied on the last few rows.

As I ran it, I found lots of cases where a pixel is removed, then because the lines move inward, the pixel right next to it gets taken out a few lines above, and so a 'doubled-up' pixel completely disappears, rather than all the doubles being gradually whittled away. I haven't figured out a way to predict and avoid this yet. You can try to track it happening - I put a grid of BRIGHT 0/1 white squares over the screen and watch it run to try to track the points these problems occur, then try an tweak the relevant number. But it's a painful process. It'd be easier if you could take out a specific pixel on each row, but I have to do it all at byte edges for speed.

Note also that the scroll up the screen shifts varying numbers of lines counting up from the bottom - not always the full 160. This means that as you go up the scroller, various lines get over-written by the one below and disappear entirely. This squeezes the text vertically. Again, I need to look at tweaking this so that doubled-up rows don't entirely disappear.

I'm trying to refine it for this version, but it's hard work.
User avatar
HEXdidnt
Manic Miner
Posts: 224
Joined: Thu Mar 09, 2023 2:40 pm
Location: Harrow, London, UK
Contact:

Re: Star Wars Scroller Routine

Post by HEXdidnt »

Joefish wrote: Wed Aug 23, 2023 11:22 pm It was all vague guesswork.
...
I'm trying to refine it for this version, but it's hard work.
Well, it's pretty frickin' impressive for guesswork!

Curious to see any refinements you make, as it's already looking amazing, considering the comparatively low screen resolution and low-definition fonts: 8 x 8 pixels (or 6 x 6 in most cases) really ain't a lot to work with!
...Dropping litter in the zen garden of your mind

The Hub of all things HEXdidn't... | HEXdidn't... on YouTube ...on ZXArt ...on deviantart
User avatar
MatGubbins
Dynamite Dan
Posts: 1239
Joined: Mon Nov 13, 2017 11:45 am
Location: Kent, UK

Re: Star Wars Scroller Routine

Post by MatGubbins »

Bloody brilliant!
During the early 90s I remember seeing an Atari ST demo in a shop performing the opening Star Wars scroller and wondered how it was done.
Now it's on the Spectrum....
Thank you indeed.
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Star Wars Scroller Routine

Post by Joefish »

I seem to remember seeing an ST one that had a few single columns of text going up the screen, not whole rows of text, but that sort of thing was always done with a fixed pattern of stripes in 8 colours, then redefining the colours per line to make the pattern look like text characters. Kind of like how the road in Roger The Pangolin works - the road edges are fixed, curved lines of pixels. It only manipulates the attributes line-by-line to make them appear different colours.

The Star Wars game did something like it, but with vector versions of the font so it was all done mathematically.
User avatar
flatduckrecords
Manic Miner
Posts: 787
Joined: Thu May 07, 2020 11:47 am
Location: Oban, Scotland
Contact:

Re: Star Wars Scroller Routine

Post by flatduckrecords »

Thanks for the explanation @Joefish, that was really helpful.
Joefish wrote: Wed Aug 23, 2023 11:22 pm I start from the bottom up; pick a number somewhere part-way along the row, from 0-15. Then another, and another. I try to distribute them evenly along the row, scattering back and forth, for 8 numbers picked from 1-15.
I thought I'd try prime numbers for this. (I think it works because they aren't divisors of each other, so the distribution of discarded pixels is inherently even? I'm not sure, in any case it helped to get rid of the "warping" I was getting from just picking random numbers). I've got rows of 96 bytes, so I used primes in the range 1-47 and sort of interleaved them as you described bottom-to-top, and it seemed to work quite well.

The other change I made was to remove a pixel from *both* sides of each row, so the column of text narrows twice as quickly.

I've just sent @HEXdidnt a demonstration (so I won't spoil it with a screenshot here yet!)
User avatar
HEXdidnt
Manic Miner
Posts: 224
Joined: Thu Mar 09, 2023 2:40 pm
Location: Harrow, London, UK
Contact:

Re: Star Wars Scroller Routine

Post by HEXdidnt »

The latest version is looking fantastic - thank you @flatduckrecords and @Joefish for making this happen!

Honestly, MODE 3 is amazing for this kind of effect.
...Dropping litter in the zen garden of your mind

The Hub of all things HEXdidn't... | HEXdidn't... on YouTube ...on ZXArt ...on deviantart
Speccyman
Drutt
Posts: 4
Joined: Tue Jan 17, 2023 4:42 pm

Re: Star Wars Scroller Routine

Post by Speccyman »

Impressive and something I always wanted to do, but never could. My first experience was just an scroller from bottom to top, this I used in FUN PART DEMO (https://zxdemo.org/productions/13070/ last part ). Later then I had the idea of making a scroller from bottom and top at the same time. I made this in IRON-I ( https://zxdemo.org/productions/13205/ also last part). But all was just done because I couldn´t do the Star Wars scroller.
Will happily investigate the source code.
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Star Wars Scroller Routine

Post by Joefish »

R-Tape wrote: Mon Aug 21, 2023 7:58 pm Not sure why, but that happens when I BREAK into the BASIC near the start of the scrolling, and then RUN 40. If I wait for it to do a full loop it seems okay. I haven't used the asm listing yet.
Actually, I've noticed a blank-line glitch in it too. It's mostly disguised amongst the blank rows you'll get from using the regular Speccy font, but it shows up if you use an 8-pixel high pattern.
Post Reply