Horizontal Scrolling :0-

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Horizontal Scrolling :0-

Post by Wall_Axe »

Does anyone have any idea how its done in Ghosts n' Goblins?

It seems quite impressive.

I imagine each tile has 4 copies at 4 different horizontal positions and the screen scrolls 2 pixels at a time, at a total guess?
User avatar
MustardTiger
Microbot
Posts: 122
Joined: Tue May 02, 2023 8:05 pm

Re: Horizontal Scrolling :0-

Post by MustardTiger »

There's an old thread about stack tricks here viewtopic.php?t=3995 which has some Ghost and Goblins info.

The stack trick sounds really interesting and i'd like to give it a try sometime.
berarma
Microbot
Posts: 106
Joined: Thu Mar 09, 2023 10:55 am

Re: Horizontal Scrolling :0-

Post by berarma »

It's explained in good detail here: http://www.emix8.org/ggdisasm/
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Horizontal Scrolling :0-

Post by Wall_Axe »

ah i see thanks if there are 8 tiles ahead they would be rotated the same, so thats just a case of drawing 8 tiles at the same rotation across the screen, I can see how thats fast.

loads of empty space and repeating tiles ftw
User avatar
Lee Bee
Dynamite Dan
Posts: 1297
Joined: Sat Nov 16, 2019 11:01 pm
Location: Devon, England
Contact:

Re: Horizontal Scrolling :0-

Post by Lee Bee »

I have no idea about the technicalities of this, but visually the scrolling looks the same to me as Agent X 2.
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Horizontal Scrolling :0-

Post by Joefish »

There are as many different ways of scrolling the screen as there are Speccy games!
You can try and redraw the screen really fast and get the sprites up before the TV refresh comes round again.
Or you can copy the scenery into a buffer, add the sprites, then copy the buffer to the screen (or swap the visible screen over on a 128K).
R-Type has an ingenious method of just pixel-shifting the character cells on the screen that contain scenery, whilst making sure that sprites are never drawn over those character cells.

You can pixel-shift scenes in memory, filling-in more scenery at the edges, before copying to the screen (Green Beret, Hysteria), or you can repaint the whole play area every time from pre-shifted tiles (e.g. a small number of pre-shifted tiles in 2-pixel steps like Cobra). Or repaint strips pattern with special treatment for the ends (as in that Ghosts'n'Goblins breakdown). Or you can move things around in whole character squares (Gauntlet) if the game runs a bit slower or the graphics and sprites are pretty big.
Ralf
Rick Dangerous
Posts: 2289
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Horizontal Scrolling :0-

Post by Ralf »

Does anyone have any idea how its done in Ghosts n' Goblins?
It seems quite impressive.
For me it's not impressive. Ghosts'n'Goblins has actually a very ugly, messy code with different routines for everything. I made some research into it one
day and my conclusions were the same as given at the link:
Most of the optimizations are done using specialization. A lot of cycles are saved by writing specific routines for every case that would otherwise require expensive testing for various conditions. This does increase the code size: at least 35 different routines are used in combination to fill the screen.
It's not even an engine. An engine for me is something reusable that you can use with any graphics. Here we have everything hardcoded with different code for player, demons, zombies, graves, ladders etc.

Yes, the result is smooth. But look at the graphics - tiny sprites and very few simplistic background tiles.
But well, maybe I should have started from saying that I really don't like GNG on Spectrum that much :)
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Horizontal Scrolling :0-

Post by Wall_Axe »

I made a Little game with pixel shifting done right on the screen. It works beautifully as there are z80 commands which can be used to put the bit that is shifted off onto the next byte ,so it works perfectly for scrolling.

I think a flag is set if the bit destroyed by a shift is a one. So then you add one to the previous byte on screen.

It only had one line of tiles. Imagine the floor to a Mario game.
It was fast but any more tiles would have been slow.
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Horizontal Scrolling :0-

Post by Joefish »

This code (128K only) can repaint the whole screen from pixel-shifted tiles at 50 frames per second. Unfortunately it's limited to only one type of tile (brickwork or platform) on each row, and that's made up of four tiles (background, left-end, right-end and mid-platform). At least the background tile is a parallax scrolling pattern.

https://spectrumcomputing.co.uk/entry/3 ... um/50Hurts

It's almost unheard of for horizontal scrolling Speccy games to run at 50fps though. Sidewize does, but not many others. Most of the fastest ones run at 25fps, but are limited in screen area and number of sprites on-screen. Green Beret, Hysteria and Ghosts'n'Goblins are the best examples. But Ghosts'n'Goblins, for all its technical trickery, does have some ugly graphics in it.
Ralf
Rick Dangerous
Posts: 2289
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Horizontal Scrolling :0-

Post by Ralf »

I hope that one day we will see this game:



I don't know what's the framerate there but it's really, really fast with support of big masked sprites, possible paralax scrolling and background without any limitation.
I'm not sure if it is flickering a bit while scrolling or it is some artifact of Youtube.

Still it could be the best ever done on Speccy when completed.
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Horizontal Scrolling :0-

Post by Wall_Axe »

Goncharov nice 👍🏻
Very similar to robocop.

I'll check out that 128k code
User avatar
Bedazzle
Manic Miner
Posts: 305
Joined: Sun Mar 24, 2019 9:03 am

Re: Horizontal Scrolling :0-

Post by Bedazzle »

Ralf wrote: Sun May 28, 2023 9:24 pm I'm not sure if it is flickering a bit while scrolling or it is some artifact of Youtube.
I think, it is evolved from

Ralf
Rick Dangerous
Posts: 2289
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Horizontal Scrolling :0-

Post by Ralf »

Yes, Goncharov looks basically like Robocop on steroids :)
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Horizontal Scrolling :0-

Post by Joefish »

Metal Man moves the foreground in whole character squares. Goncharov is using 4-pixel steps. Robocop scrolls two pixels at a time.
The step size is just as important as the frame rate.
Ralf
Rick Dangerous
Posts: 2289
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Horizontal Scrolling :0-

Post by Ralf »

Goncharov is using 4-pixel steps
I wasn't quite sure about it from the video but it explains a bit why it's so fast.

Robocop first game was a bit sluggish but it surprisingly fits well becase the real Robocop from the movie was also a bit
sluggish and akward, similar to a heavy armour tank. I never like Robocop adaptations on other platforms where he is faster and can even jump (see 64 version for example).
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Horizontal Scrolling :0-

Post by Wall_Axe »

4 pixel scrolling looks great.

I saw the video without knowing any of the technical details. It just felt like a 'real game' unlike the 8 pixel scrolling games.
User avatar
Bedazzle
Manic Miner
Posts: 305
Joined: Sun Mar 24, 2019 9:03 am

Re: Horizontal Scrolling :0-

Post by Bedazzle »

Joefish wrote: Mon May 29, 2023 11:05 pm Metal Man moves the foreground in whole character squares. Goncharov is using 4-pixel steps.
This is why I used "evolved". Same author, more recent engine.
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Horizontal Scrolling :0-

Post by Joefish »

When it comes to pixel scrolling, you can call RL (HL) or RR (HL) to rotate a byte in memory by one bit, filling in the empty bit at one end from the carry flag, and catching the bit that falls out the other end in the new setting of the carry flag. So you call it on a series of bytes and the whole lot shift along one bit (or one pixel). But there's no equivalent way to shift by two pixels (which would be really handy).

However, when it comes to four pixels, there's a pair of rarely-used instructions in Z80 called RLD and RRD. These shift the byte in memory that HL points to, by four pixels right or left, and use the bottom half of the A register as the 'carry' or 'overflow'. So what's in the bottom four bits of A gets pushed into one end of a byte in memory, and what falls out the other end goes back into A. In that way, you can shift a screen buffer along by four pixels, and it only takes a fraction longer (18 cycles compared to 15) than the 1-pixel equivalent.

But when it comes to four-pixel scrolling, you could instead have two back-buffers, one permanently shifted four pixels over relative to the other, then you can shift each one by whole bytes for 8-pixel movement, and and just swap between them for four pixel movement. It uses more memory, but it's much faster, and a bit more versatile.
Nienn Heskil
Microbot
Posts: 134
Joined: Tue Jun 09, 2020 6:14 am
Contact:

Re: Horizontal Scrolling :0-

Post by Nienn Heskil »

Scrolling is just a way of showing a bigger map in a small window. Chances are you don't even need that for your game idea. If you don't, that's a big plus on such a platform.

Otherwise just use Unity/Godot really. Only downside is it's not Spectrum anymore, everything else is a plus, you aren't in pain (not to that extent anyway) and your game isn't crippled by 25fps, bad graphics and all that
Inky
Dizzy
Posts: 95
Joined: Tue Dec 10, 2019 10:05 pm
Location: Sheffield, UK

Re: Horizontal Scrolling :0-

Post by Inky »

Ralf wrote: Sat May 27, 2023 12:51 pm For me it's not impressive. Ghosts'n'Goblins has actually a very ugly, messy code with different routines for everything. I made some research into it one
day and my conclusions were the same as given at the link:



It's not even an engine. An engine for me is something reusable that you can use with any graphics. Here we have everything hardcoded with different code for player, demons, zombies, graves, ladders etc.

Yes, the result is smooth. But look at the graphics - tiny sprites and very few simplistic background tiles.
But well, maybe I should have started from saying that I really don't like GNG on Spectrum that much :)
Seems a bit harsh :) What does it matter how he achieved a 25 FPS almost full-screen scroller (and in no doubt written to a tight deadline), or whether it used re-usable/”engine” code? I don’t think the end result could have been bettered on the ol' 48K machine.

Also you could accuse most push scrollers of the same – lots of repeated code, just variations on a theme. Or even non-push-scrollers like Commando which also has a lot of custom blitting code for the scenery. Just curious as to what GnG in particular has done to offend you :D
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Horizontal Scrolling :0-

Post by Wall_Axe »

using rotate right on an onscreen byte is one way of doing it.
But wouldnt it be faster to just repaint everything every frame?
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Horizontal Scrolling :0-

Post by Joefish »

Wall_Axe wrote: Wed May 31, 2023 3:30 pm using rotate right on an onscreen byte is one way of doing it.
But wouldnt it be faster to just repaint everything every frame?
Depends entirely on how complicated the scene is. Storing tiles pre-shifted into different scroll positions so the scene can be repainted in any position is memory-consuming, so it's only viable when the scene consists of a very limited number of repeated patterns and structures - as with Ghosts'n'Goblins and Cobra, for example.
User avatar
Lethargeek
Manic Miner
Posts: 743
Joined: Wed Dec 11, 2019 6:47 am

Re: Horizontal Scrolling :0-

Post by Lethargeek »

Wall_Axe wrote: Wed May 31, 2023 3:30 pm using rotate right on an onscreen byte is one way of doing it.
But wouldnt it be faster to just repaint everything every frame?
for caves, rotate edges, skip empty and solid tiles
Joefish wrote: Wed Jun 21, 2023 6:23 pm Depends entirely on how complicated the scene is. Storing tiles pre-shifted into different scroll positions so the scene can be repainted in any position is memory-consuming, so it's only viable when the scene consists of a very limited number of repeated patterns and structures - as with Ghosts'n'Goblins and Cobra, for example.
with limited numbers you may not even need preshifted
shift every used pattern once, then copy
Post Reply