### Author Topic: Hardware scrolling  (Read 1675 times)

0 Members and 1 Guest are viewing this topic.

#### redbox

• Supporter
• 6128 Plus
• Posts: 1.788
• Country:
• Liked: 406
• Likes Given: 287
##### Hardware scrolling
« on: 14:34, 28 January 10 »
I want to scroll the screen using the hardware and print new graphics on the left and right.

When I scroll the screen left (like in this example) I notice that the second line wraps around to the top once the screen is scrolled.

Is there anyway to avoid this, or do you really have to write a routine to factor in this offset (for example, I would have to start writing the graphics at &C080 instead of &C000 after I have scrolled the screen)...?

#### arnoldemu

• Supporter
• 6128 Plus
• Posts: 5.336
• Country:
• Liked: 2280
• Likes Given: 3478
##### Re: Hardware scrolling
« Reply #1 on: 15:59, 28 January 10 »
I want to scroll the screen using the hardware and print new graphics on the left and right.

When I scroll the screen left (like in this example) I notice that the second line wraps around to the top once the screen is scrolled.

Is there anyway to avoid this, or do you really have to write a routine to factor in this offset (for example, I would have to start writing the graphics at &C080 instead of &C000 after I have scrolled the screen)...?
Well I remember the screen "base" (e.g. which 16k block it is in).
This can be derived from r12 like this:( (r12 & 0x030)*4)
So that &30->&c0, &10->&40
I then treat r12 and r13 combined seperately and mask them with &3ff.
This gives me the offset.
You can convert this into a byte offset by multiplying with 2.
From this you can work out the address of the top-left of the screen.

If you're doing a hardware scroll you then calculate the address of the left/right column and draw 1 column of pixels (1 column = 2 bytes wide and 200 lines tall).

If you're wanting to draw software sprites, then I keep a table of offsets for each line:
e.g.
0,
&800,
&1000,
&1800
&2000,
&2800,
&3000,
&3800,
&80,
&880

I use the y sprite coord to look up into the table and I add this onto the base address.
I then add on the x offset to get the final plot address.

So a little more work but not that much.

Using that code as a base:

Code: [Select]
ld hl,(scroll_offset) ;; crtc scroll offset writable direct to r12,r13. Looks like this &3010
ld e,h ;; store r12
ld a,h ;; mask for scroll offset
and &3
ld h,a
add hl,hl ;; x2 to get byte offset

ld a,e ;; old r12
and &30 ;; isolate page bits
add a,a ;; move into bit 7,6 &30->&c0
or h ;; combine with byte offset
ld h,a
;; hl = scr address of top-left of screen

defw 0
« Last Edit: 16:03, 28 January 10 by arnoldemu »
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

#### redbox

• Supporter
• 6128 Plus
• Posts: 1.788
• Country:
• Liked: 406
• Likes Given: 287
##### Re: Hardware scrolling
« Reply #2 on: 18:07, 28 January 10 »
Thanks for the explanation - I thought it might have to be something like this and I will give it a go!