CPCWiki forum

General Category => Programming => Topic started by: redbox on 14:34, 28 January 10

Title: Hardware scrolling
Post by: redbox 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 (http://www.cpcwiki.eu/index.php/Programming:CPC_Plus_Horizontal_scroll)) 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)...?

Title: Re: Hardware scrolling
Post by: arnoldemu 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 (http://www.cpcwiki.eu/index.php/Programming:CPC_Plus_Horizontal_scroll)) 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
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
ld (scr_addr_top_left),hl

scr_addr_top_left:
defw 0
Title: Re: Hardware scrolling
Post by: redbox 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!