Difference between revisions of "Programming:Hardware scrolling 2"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
 
 
(One intermediate revision by one other user not shown)
Line 17: Line 17:
 
Now you can use fast sprite routines to draw.
 
Now you can use fast sprite routines to draw.
  
For this to work you need to ensure the width and height of the screen, when multiplied together equal 1024.
+
For this to work you need to ensure that 1024 is exactly divisible by the width.
 +
1024 is the maximum scroll offset which can be programmed to register 12 and 13 of the crtc.
  
width (in chars)*height (in chars) = 1024.
+
One common screen size is 32 chars wide.
 
+
One common screen size is 32 chars wide, 32 chars tall.
+
  
 
Now if you only scroll vertically you can avoid the problem completely. Ideal for vertical shoot em ups.
 
Now if you only scroll vertically you can avoid the problem completely. Ideal for vertical shoot em ups.
Line 36: Line 35:
  
 
With a screen size of 40 chars x20  chars, the maximum scroll offset is 224 chars.
 
With a screen size of 40 chars x20  chars, the maximum scroll offset is 224 chars.
 +
 
If you combine this with the register 3 trick (to scroll in byte sized increments),
 
If you combine this with the register 3 trick (to scroll in byte sized increments),
then you get up to 7 seconds of scroll:
+
then you get up to 7 seconds of scroll if you scroll every frame:
  
 
(224 * 2)/60 = 7 seconds
 
(224 * 2)/60 = 7 seconds
 +
 +
Otherwise you get 224/40 = 5 screens which can be scrolled
 +
 +
[[Category:Programming]]

Latest revision as of 07:50, 30 October 2006

Drawing sprites on a hardware scrolling screen can often be slower, because of the way the CPC hardware "wraps" the screen.

Here are some ways to avoid it, and so you can use faster sprite drawing routines:

The "problem" occurs when you scroll the screen, the following addressess are horizontally next together, but in really they are not a simple "inc" away :(

So you have to handle these as special cases. If you do this a lot your sprite routines will be much slower.

&C7FF->&C000 &CFFF->&C800 &D7FF->&D000

Vertical Scroll Only


Adjust the screen dimensions so that the problem happens on the left side of the screen. Now you can use fast sprite routines to draw.

For this to work you need to ensure that 1024 is exactly divisible by the width. 1024 is the maximum scroll offset which can be programmed to register 12 and 13 of the crtc.

One common screen size is 32 chars wide.

Now if you only scroll vertically you can avoid the problem completely. Ideal for vertical shoot em ups.

Horizontal Scroll Only


Limit the scroll so that you never encounter the problem.

The maximum scroll offset is: (1024-(width*height))

so that problem is in bottom right corner at maximum scroll offset.

With a screen size of 40 chars x20 chars, the maximum scroll offset is 224 chars.

If you combine this with the register 3 trick (to scroll in byte sized increments), then you get up to 7 seconds of scroll if you scroll every frame:

(224 * 2)/60 = 7 seconds

Otherwise you get 224/40 = 5 screens which can be scrolled