News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_llopis

Calculating next line with HW horizontal scroll and wraparound

Started by llopis, 15:38, 06 December 22

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

llopis

Right now I have a screen with the default CRTC dimensions (mode 0, but that's not relevant). I'm changing the start address to do horizontal scrolling.

I get the basic layout theory: To go to the next character I add #50 to the address, and to go to the next row within the line I add #800 more. The tiles I'm rendering are aligned with character lines, so that makes it easier (once I start with to render it, I can assume the next 8 rows are all part of the same character line).

However, I'm not happy about the wraparound. When I scroll enough, it gets to a point that, on the bottom right of the screen, when I get the next character line, the address value becomes greater than #FFFF. If that's the case, I need to do some extra addition to set the address to the correct wrap-around.

My question is: Is there a way to avoid that and have a simple function that gives the address of the next character line (or row across character lines) without having to check for wraparound?

I found this one which claims to do it, but unless I'm missing something, it also fails: https://cpctech.cpc-live.com/docs/scraddr.html (at the bottom of the page).

It does make sure it's always in the right range, but when it wraps around, you still need to subtract #800 from the address. Am I wrong and somehow I misunderstood that code? 

Alternatively, is it possible to slightly tweak the screen dimensions to turn it into a nice multiple so wraparound works without extra work?

Prodatron

Behind...
adc a,&C0

...you have to add...
res 3,a

...to get the wraparound.

Screens with a width of 64 bytes (instead of 80) would never have a wraparound inside a line. Because of this several games choosed this screensize. But if all your objects/sprites only have the size of a character that wouldn't matter in your case.

*EDIT* Sorry for the confusion, this RES 3,A should always work, no matter where the screen starts.

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

llopis

Quote from: Prodatron on 16:40, 06 December 22Behind...
adc a,&C0


...you have to add...
res 3,a


...to get the wraparound.

Screens with a width of 64 bytes (instead of 80) would never have a wraparound inside a line. Because of this several games choosed this screensize. But if all your objects/sprites only have the size of a character that wouldn't matter in your case.

*EDIT* Sorry for the confusion, this RES 3,A should always work, no matter where the screen starts.
Oh wow, you're right! That's a very efficient way to do the same thing. Works like a charm. Thank you!

(Now on to vertical scrolling, which is going to add a whole new bunch of issues I'm sure).

andycadley

Quote from: Prodatron on 16:40, 06 December 22Screens with a width of 64 bytes (instead of 80) would never have a wraparound inside a line
Isn't that only true for vertical scrolling? Surely if you're scrolling horizontally, the wrap around within a line is inevitable?

lmimmfn

Agreed, for horizontal scrolling it has to wrap around regardless of screen width. Not the same for vertical scrolling of course.
6128 for the win!!!

Powered by SMFPacks Menu Editor Mod