1
0
mirror of https://frontier.innolan.net/github/AmigaExamples.git synced 2025-05-17 06:14:03 +00:00
AmigaExamples/019.hori_scroll
..
2016-03-14 15:05:44 +11:00
2016-03-20 21:11:56 +11:00
2016-03-14 15:05:44 +11:00
2016-03-14 16:23:59 +11:00
2016-03-14 15:53:23 +11:00

horizontally scrolling the playfield

Hardware reference link

Unfortunately, horizontal scrolling is slightly more involved compared to vertical scrolling. Firstly, we can only scroll on word boundaries using the bitplane pointers, so we need to add a delay to allow for pixel scrolling.

Firstly, we need to modify the data fetch to start one word earlier (See init.s):

 move.w  #(RASTER_X_START/2-SCREEN_RES)-8,DDFSTRT(a6)

Then we need to adjust the modulo to account for this. Also the modulo needs to also account for the new large bitmap size. We change the base screen width bytes symbol in constants.i to allow for the new 2x wider bitplane:

 SCREEN_WIDTH_BYTES      equ (2*SCREEN_WIDTH/8)

We set the modulo with extra bytes for the extra width, and two less counts for the extra scrolling byte.

move.w  #(SCREEN_WIDTH_BYTES*SCREEN_BIT_DEPTH-SCREEN_WIDTH_BYTES)+(SCREEN_WIDTH_BYTES/2)-2,BPL1MOD(a6)

Calculate the number of bits to scroll:

move.l  hpos,d0         ; number of pixels we want to scroll
lsr.l   #3,d0           ; bytes to scroll                                               
add.l   d0,bitplaneAddress  ; used to set the bitplane pointers when combined with vertical scrolling
move.l  hpos,d1         ; pixels = 0xf - (hpos - (hpos_bytes*8))
and.l   #$F,d1
move.l  #$F,d0
sub.l   d1,d0           ; bits to delay

Finally we set the delay for the pixel portion of the scroll in BPLCON1:

SetupHoriScrollBitDelay:
;; d0 = number of bits to scroll                                                       
   movem.l d0/d1,-(sp)
   move.w  d0,d1
   lsl.w   #4,d1
   or.w    d1,d0
   move.w   d 0,BPLCON1(a6)
   movem.l (sp)+,d0/d1
   rts

try it