How to use hardware scrolling in games?

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Zamuel_a
Atari God
Atari God
Posts: 1242
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: How to use hardware scrolling in games?

Post by Zamuel_a »

I noticed some other problem I couldn't find any really good solution for. Then I split the drawing by 16 parts I use the x coordinate AND 15 to get values between 0->15 to choose what to draw and thats ok, but if Im going to the right and then suddenly change direction to the left I will change from a positive number to first -1 and then -2 and so on, that means I miss number 0 and I will not draw one of the 16 parts, how to solve that easily? I would have to go right (draw right parts), STOP in right direction (still drawing right parts), change direction so we are standing still in LEFT direction so we can start draw left parts at part 0. I guess that works on a platform game, you will loose one frame then the player change direction, but that could be normal I guess. But have to try to see what it looks like.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
User avatar
unseenmenace
Atari God
Atari God
Posts: 1965
Joined: Tue Sep 21, 2004 9:33 pm
Location: Margate, Kent, UK
Contact:

Re: How to use hardware scrolling in games?

Post by unseenmenace »

Zamuel_a wrote:I can't understand how you can manage it with just 21 blocks, 20 are visible, but if you scroll left then number 21 is the one you see with the HSCROLL register and 21 is the same you are currently redrawing? I need at least 22 blocks, 20 blocks showing if HSCROLL is 0, but if HSCROLL increase I start to see number 21 and I start to draw number 22 in 16 parts.
I don't understand how to do it any other way?
If we stick with just horizontal again for now you need to view one half of the screen and draw in the other so in your example above you are seeing 21 columns and drawing in the 22nd. Once you have scrolled right by one column you'll be viewing columns 2 to 22 and drawing in columns 1 and 23. In column 23 you draw the scenery you are about to scroll into and in column 1 you are drawing the screen that you will flip to when you reach the right hand edge. Most of the time you will be drawing in the columns either side of the viewable area its just when you are at one edge that you only draw one column. When you get to the point where you are viewing the last 21 columns (22 to 42) again you will only be drawing one column (21) and once the hscroll (effectively) reaches 16 you flip left to view the other half of the screen again.
UNSEEN MENACE
Several STFM's, 4MB STE, 2MB TT with 1.2GB Hard Drive and 14MB Falcon with 540MB Hard Drive,
Lynx 2 and Jaguar with JagCD
Member of GamebaseST and AtariLegend team
Check out my website at http://unseenmenace.110mb.com
Zamuel_a
Atari God
Atari God
Posts: 1242
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: How to use hardware scrolling in games?

Post by Zamuel_a »

Ok, I might have missunderstod you then, I thought you were drawing new tiles on column 21 and thats the one HSCROLL is affecting. I was drawing in column 22 and made the copy on column -2 since I needed -1 to be untouched in case I was changing direction and walked left instead. If I just suddenly change direction I could have half on the leftside column updated with new data, but I came up with something and thats what you are doing I guess.
You walk to the right 8 pixels, half of the column on the left side of the screen gets updated with data, so if I now change direction and walks left (without drawing anything) I will see half of what should be on my left and the rest is the copy of my right, but if I redraw the part I made the copy to then I start walking left I should get back to the original, making a "undo" of my last rightside copy.
You said that then you reached the edge of the screen you only had to draw one column, do you treat that as a special case then? I didnt bother about that so I draw outside the screen to, thats why I needed more than 16 pixels on my right and left side just to prevent writing in a unspecified memory location.

Well its alot more work than just scroll some ordinary pictures in memory, thats for sure! But more fun then it works:) I guess this is how all games had to do it on the Amiga since it got hardware scrolling.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
Zamuel_a
Atari God
Atari God
Posts: 1242
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: How to use hardware scrolling in games?

Post by Zamuel_a »

One other thing I was thinking about...

How do you divide the drawing in 16 parts? By divide the number of tiles to draw by 16 or draw all tiles in the column, but just one line at a time.
For example in my "draw right column" routine I have 3 loops, the one from top of screen to top of the visible screen, then one loop for the right part and then one loop for the bottom part. I had to make 3 loops since I have to change the pointer for the tiledata since its not linear from top to bottom.
I guess I could make on loop and then have a check for every tile to see then I need to change the pointer, but it sounds like it takes more processor power than 3 individual loops.
The drawback is that its hard to divide the drawing in 16 parts, but I draw all the tiles every frame, but just one line for each tile per frame. It might be slower than draw full tiles instead, but now every frame takes exactly the same processor time and it sounds like if I divide it by tiles instead I would get first a initiation time for the first tile and then the rest 15 frames will be faster since I dont have to recalc all data again, but its no use to have more processor power for 15 frames and then have a lag one frame:)

For the vertical scrolling I think drawing a complete line must be the best way to do it, feels more natural and you get a even processor load for all 16 frames.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
Zamuel_a
Atari God
Atari God
Posts: 1242
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: How to use hardware scrolling in games?

Post by Zamuel_a »

Ok I think I got it to work now. I just have that thing about changing direction then:) Since if I go from right scroll to left scroll I have to go pass "zero scroll" or I will lose one frame of drawing.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
Zamuel_a
Atari God
Atari God
Posts: 1242
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: How to use hardware scrolling in games?

Post by Zamuel_a »

I have been sitting with it for some hours now and I think the scrolling works in all directions now, with splitting of the drawing to 16 parts. There is just one problem left I think. (There are always something :evil: )
Let's say I got 45 degrees right/down, then I reach the bottom of the screen so it's time to flip back it will now use data from both the right side drawer and the bottom side drawer. That works, but lets say you walk 8 pixels to the right first and then do the 45 degrees travel right/down. What happens now then I flip back is that I get a "staircase" of data that are partly drawn. Then I first walk the 8 pixels I will update half of the data I will use later then I have done my 45 degres travel and flip back in memory. I don't really know how to prevent that.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
Zamuel_a
Atari God
Atari God
Posts: 1242
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: How to use hardware scrolling in games?

Post by Zamuel_a »

Ok, I might have a solution for that problem to:P I have to do some work then I get time.
One other thing I was thinking about is how to draw sprites in a good way. How to use the borders and so. I guess I could set a flag in my TIMER B routine that starts at line 192 to tell that now we are in the bottom border and then in my VBI routine I check for that flag and then it's set I know its ok to start with sprites. The problem is then that I don't really know how much I can draw before I reach the end of the VBI and I can ofcourse (but I had wanted to!) let it wrap around so it continues to draw in the top border.
I guess I could always have like a list for every sprite size (there isn't so many different sizes anyway) with the CPU time it takes to draw and then I draw a sprite I just sum that time together until I reach a point then I know that I can't draw any more in the bottom border and then I continue on then I restart the VBI for the top border again.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
User avatar
unseenmenace
Atari God
Atari God
Posts: 1965
Joined: Tue Sep 21, 2004 9:33 pm
Location: Margate, Kent, UK
Contact:

Re: How to use hardware scrolling in games?

Post by unseenmenace »

Rather than setting a flag I use a timer B interrupt routine to draw sprites, that way sprite drawing can run in a continuous block from the bottom of the playfield, through the bottom border and through the top border of the next VBL without having to check for anything and waste time pausing in the middle. The only proviso is that you have to be damn sure the sprite drawing will be finished before the top of the playfield so that you can initialise any timer B routines that are needed (such as rasters) and to avoid flicker caused by drawing during the screen redraw.
UNSEEN MENACE
Several STFM's, 4MB STE, 2MB TT with 1.2GB Hard Drive and 14MB Falcon with 540MB Hard Drive,
Lynx 2 and Jaguar with JagCD
Member of GamebaseST and AtariLegend team
Check out my website at http://unseenmenace.110mb.com
Zamuel_a
Atari God
Atari God
Posts: 1242
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: How to use hardware scrolling in games?

Post by Zamuel_a »

Ok, I was thinking about using a Timer B interrupt, but won't the next VBI interrupt occur then we finish the bottom border and starts with the top again? So I get kicked out from my spritedrawing routine and starts the next VBI routine again?
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
RA_pdx
Captain Atari
Captain Atari
Posts: 217
Joined: Sun Feb 02, 2003 12:01 pm
Location: Nuernberg/GERMANY

Re: How to use hardware scrolling in games?

Post by RA_pdx »

One more hint: Sort the sprites from top to bottom before drawing - then you could usually draw some more sprites without flickering even they are not anymore drawn in the border.
>> > raZen/Paradox < <<

Atari 1040STE, TOS 2.06, 4MB, MC68010, IDE 8GB SSD, Gigafile
User avatar
unseenmenace
Atari God
Atari God
Posts: 1965
Joined: Tue Sep 21, 2004 9:33 pm
Location: Margate, Kent, UK
Contact:

Re: How to use hardware scrolling in games?

Post by unseenmenace »

Zamuel_a wrote:Ok, I was thinking about using a Timer B interrupt, but won't the next VBI interrupt occur then we finish the bottom border and starts with the top again? So I get kicked out from my spritedrawing routine and starts the next VBI routine again?
Yes it will but the answer then is to do very little (if anything) on the VBL interrupt so it returns back to your Timer B routine to finish drawing sprites. Then you can do the off-screen scenery, input checking, collision detection and other stuff during the visible part of the screen draw.
UNSEEN MENACE
Several STFM's, 4MB STE, 2MB TT with 1.2GB Hard Drive and 14MB Falcon with 540MB Hard Drive,
Lynx 2 and Jaguar with JagCD
Member of GamebaseST and AtariLegend team
Check out my website at http://unseenmenace.110mb.com
User avatar
unseenmenace
Atari God
Atari God
Posts: 1965
Joined: Tue Sep 21, 2004 9:33 pm
Location: Margate, Kent, UK
Contact:

Re: How to use hardware scrolling in games?

Post by unseenmenace »

RalfZenker wrote:One more hint: Sort the sprites from top to bottom before drawing - then you could usually draw some more sprites without flickering even they are not anymore drawn in the border.
I have thought about doing that (I believe Enchanted Land uses that technique heavily) but not sure if its efficient to use up processor time sorting the sprites into Y order (I guess it depends on the game/number of sprites). It could be more efficient and easier to draw certain sprites last if you know they are only ever going to be a certain distance down the screen? For example the main sprite (e.g. Turrican) is usually in the centre of the screen so it shouldn't be a problem to draw him during the top of the visible screen.
UNSEEN MENACE
Several STFM's, 4MB STE, 2MB TT with 1.2GB Hard Drive and 14MB Falcon with 540MB Hard Drive,
Lynx 2 and Jaguar with JagCD
Member of GamebaseST and AtariLegend team
Check out my website at http://unseenmenace.110mb.com
Zamuel_a
Atari God
Atari God
Posts: 1242
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: How to use hardware scrolling in games?

Post by Zamuel_a »

Ok, right now I have put the whole game in the VBI but I guess I could remove it and use Timer B instead so sync everything. First thing I do in the VBI is to set the screen address and HSCROLL register so it's set before we start to draw the screen. I guess that has to be left in the VBI. I reset Timer B to in the VBI to start to count then the screen starts.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
RA_pdx
Captain Atari
Captain Atari
Posts: 217
Joined: Sun Feb 02, 2003 12:01 pm
Location: Nuernberg/GERMANY

Re: How to use hardware scrolling in games?

Post by RA_pdx »

I have thought about doing that (I believe Enchanted Land uses that technique heavily) but not sure if its efficient to use up processor time sorting the sprites into Y order (I guess it depends on the game/number of sprites). It could be more efficient and easier to draw certain sprites last if you know they are only ever going to be a certain distance down the screen? For example the main sprite (e.g. Turrican) is usually in the centre of the screen so it shouldn't be a problem to draw him during the top of the visible screen.
If you have a fast sorting algorithm and you just change the pointers to your sprites it is quite fast. I have tested it some years ago and was really impressed by the result.
>> > raZen/Paradox < <<

Atari 1040STE, TOS 2.06, 4MB, MC68010, IDE 8GB SSD, Gigafile
User avatar
unseenmenace
Atari God
Atari God
Posts: 1965
Joined: Tue Sep 21, 2004 9:33 pm
Location: Margate, Kent, UK
Contact:

Re: How to use hardware scrolling in games?

Post by unseenmenace »

RalfZenker wrote:If you have a fast sorting algorithm and you just change the pointers to your sprites it is quite fast. I have tested it some years ago and was really impressed by the result.
Sounds intriguing, any chance you could explain how you organise the sprites so that they can be sorted that way?
UNSEEN MENACE
Several STFM's, 4MB STE, 2MB TT with 1.2GB Hard Drive and 14MB Falcon with 540MB Hard Drive,
Lynx 2 and Jaguar with JagCD
Member of GamebaseST and AtariLegend team
Check out my website at http://unseenmenace.110mb.com
RA_pdx
Captain Atari
Captain Atari
Posts: 217
Joined: Sun Feb 02, 2003 12:01 pm
Location: Nuernberg/GERMANY

Re: How to use hardware scrolling in games?

Post by RA_pdx »

Sounds intriguing, any chance you could explain how you organise the sprites so that they can be sorted that way?
I know i am a little bit late with my answer... :wink:

Make a list of pointers to all your current sprites which are organised like this:

Code: Select all

sprite
{
    WORD   pos_y;
    WORD   pos_x;
    DWORD  ptrData;
    WORD   energy
    ....
}
Then sort the list of the pointers by comparing the appendant pos_y values (i use a variation of insert sort).
>> > raZen/Paradox < <<

Atari 1040STE, TOS 2.06, 4MB, MC68010, IDE 8GB SSD, Gigafile
Zamuel_a
Atari God
Atari God
Posts: 1242
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: How to use hardware scrolling in games?

Post by Zamuel_a »

Yes it will but the answer then is to do very little (if anything) on the VBL interrupt so it returns back to your Timer B routine to finish drawing sprites. Then you can do the off-screen scenery, input checking, collision detection and other stuff during the visible part of the screen draw.
Do you set a flag then you restart Timer B at the first display line, telling that now we are in the visible part of the screen. Since I shouldn't use the VBI to draw everything in (so I can draw sprites around the borders) I need to put all the game logic and tiledrawing the main loop, but then I need to know then it's ok to do the stuff in the loop so I won't do it in the border for example. I guess I should set a flag at line 1 and then check for that in the main loop and then do all the game stuff and then reset the flag and wait for the next turn. Then it wouldn't affect Timer B eather.
By drawing the main sprite at the first part of the visible screen and the bigger enemy sprites in the borders and then bullets and such stuff as smaller software sprites, sorted vertical and drawin the visible part, I should be able to put out a bounch of sprites I think. One way could be to use sprite multiplexing, like NES and such machines did, you get flicker, but don't drop the framerate.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
User avatar
unseenmenace
Atari God
Atari God
Posts: 1965
Joined: Tue Sep 21, 2004 9:33 pm
Location: Margate, Kent, UK
Contact:

Re: How to use hardware scrolling in games?

Post by unseenmenace »

Zamuel_a wrote:Do you set a flag then you restart Timer B at the first display line, telling that now we are in the visible part of the screen. Since I shouldn't use the VBI to draw everything in (so I can draw sprites around the borders) I need to put all the game logic and tiledrawing the main loop, but then I need to know then it's ok to do the stuff in the loop so I won't do it in the border for example. I guess I should set a flag at line 1 and then check for that in the main loop and then do all the game stuff and then reset the flag and wait for the next turn. Then it wouldn't affect Timer B eather.
Yes, you should only need a flag so that the main loop knows when you've started a new frame. If you set it at the end of your Timer B sprite drawing code then the main loop can wait for it to be set, then do the processing for the next frame (e.g. input, co-ordinate update, collision, tile drawing etc) and clear the flag again when done. I guess you could even have the processing follow immediately after the sprite drawing as part of the same Timer B routine as you would still be able to set Timer B to interrupt for the purposes of Rasters as long as you set it up before the top of the screen has been reached (in the VBL routine perhaps?). If you did that then maybe all your main loop code would need to do was check to see if you'd died or pressed Escape to quit :) .
Zamuel_a wrote:By drawing the main sprite at the first part of the visible screen and the bigger enemy sprites in the borders and then bullets and such stuff as smaller software sprites, sorted vertical and drawin the visible part, I should be able to put out a bounch of sprites I think. One way could be to use sprite multiplexing, like NES and such machines did, you get flicker, but don't drop the framerate.
If you do Y sorted bullets then you may have issues with bullets near the top of the screen if you draw the main sprite during the first visible scanlines. The multiplexing idea is an interesting one though :)
UNSEEN MENACE
Several STFM's, 4MB STE, 2MB TT with 1.2GB Hard Drive and 14MB Falcon with 540MB Hard Drive,
Lynx 2 and Jaguar with JagCD
Member of GamebaseST and AtariLegend team
Check out my website at http://unseenmenace.110mb.com
Zamuel_a
Atari God
Atari God
Posts: 1242
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: How to use hardware scrolling in games?

Post by Zamuel_a »

It could be good to add multiplexing so that it is possible to have more sprites on screen than fitts in the borders, Dropping the framerate is hard to do since I only can draw in the borders anyway. I guess I need to calculate how much time every sprite can take and then I draw them I add that time together to see if it fits in the border. Or else I have no control at all on how much I can draw. If I have a list of all sprites that I want to draw for next frame, then I could add all times together and if that time is higher than what I can have, then I multiplex the sprites, or I would have to just ignore it and don't draw it at all, but that might lead to that you get shoot from enemies you can't see :)

Atleast the main sprite should be drawn in the visible part and perhaps all bullets from the player could be drawn here to, if he can't shoot up and down ofcourse. But like some big "fire bullets" that you only can shoot horisontally could be drawn in the visible part.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
Post Reply

Return to “Coding”