Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Lunasoft ! (Registered 2018-12-15) You are not logged in 
CSDb User Forums

Forums > C64 Coding > (Vertical) Scroller
2018-04-18 10:49

Registered: Mar 2018
Posts: 23
(Vertical) Scroller


I've been banging me head against the wall for sometime on this, i've read through so many forum posts but am really struggling so turning to you kind souls for advice.

I am trying to write a very simple scroller, that scrolls the screen downwards (think seuck)

The scroller will be 4 directional, (only ever one direction at a time) but needs to...

1) Scroll the full screen (1 char) every frame
2) not use double buffering (screen switching)

This scroller has to be full screen but doesn't have to worry about colour.

I have 3 of the directions working simply by using some speedcode and racing the raster, it still uses a lot of CPU but works fine for left, right and scrolling data upwards.

On the downward one I cannot race the raster as I need to copy from the bottom up.

So instead of dragging the screen data around I've been thinking about alternatives...

My best idea so far is to use an offscreen memory buffer (80*50) and simply copy from top to bottom, 40*25 chars onto the screen, this works but I am only just ahead of the raster, leaving no cpu for anything else, including adding the new chars.

my code looks like this

        lda #$c0
        sta $d1
        lda #$00
        sta $d0
        lda #$04
        sta $d3
        lda #$00
        sta $d2
        ldx #$19
        ldy #$00

        lda ($d0),y
        sta ($d2),y
	... the above three lines are repeated 39 time
        lda ($d0),y
        sta ($d2),y

        lda $d0
        adc #$50
        sta $d0
        bcc @lp1
        inc $d1
        lda $d2
        adc #$28
        sta $d2
        bcc @lp2
        inc $d3
        beq @loop2
        jmp @loop

I'm happy to waste 6k of ram and complete unroll this loop if need be,

Please help me speed this up or give me some advice on how I can do it better?

... 1 post hidden. Click here to view all posts....
2018-04-18 11:19

Registered: Oct 2014
Posts: 240
basically you have to cut it in half.

Cache middle line
while you are in the bottom half of the visible screen, shift up from middle to top. then when you get out of the visible screen you then shift the bottom->middle area.
2018-04-18 12:21

Registered: Dec 2014
Posts: 34
I know you know this, but double buffering would solve all your problems. Are you so memory constrained that you can't have another screen mem area?
2018-04-18 12:27

Registered: Mar 2018
Posts: 23
Quote: I know you know this, but double buffering would solve all your problems. Are you so memory constrained that you can't have another screen mem area?

No I just can't seem to get my head around double buffering :) won't the screen then be a single frame behind the "action"? I know this is likely a miniscule time frame but as I'm scrolling an entire char per frame. It seems like quite lot to be behind?

If double buffering is the way forward then I'll redouble my efforts there.
2018-04-18 12:36

Registered: Apr 2002
Posts: 4317
2018-04-18 13:18

Registered: Feb 2002
Posts: 1073
Using double buffer, you build up what you want to show on the next frame into the hidden screen (and can do that at your own leisure). You're not any more delayed.

Shifting with a single buffer is actually just the same, but your timing is strictly tied to the screen refresh.

Using double buffering and e.g. X register for source offset and Y for destination, you need just 2 copy loops, screen1 to screen2 and vice versa.

Though depending on what your source data is like, you could forget about different shifting directions and just redraw the whole screen from the source data while racing the raster. If you use a tilemap, but format your data cleverly, you could also redraw directly from the tilemap data.
2018-04-18 13:33

Registered: Mar 2007
Posts: 129
It's too long to write about here but, for a single direction at a time (ie. the direction won't change for a complete level of the game), I can get ~6825 cycles to fill the screen - plus some additional cycles for bringing the new line in. The code for this is fully unrolled, though, and takes up ~10k.
2018-04-18 15:27

Registered: Jul 2009
Posts: 444
Also if you intend to put sprites, the more you put the less cycles you have.
2018-04-18 15:38

Registered: Mar 2018
Posts: 23
Thanks Everyone,

I decided to go down the double buffer route instead.

below is some very raw code which seems to work nicely,

the border colour change is the raster usage

thanks again gang!

P.S. if you notice any bugs feel free to shout :)



        BYTE    $0B, $08, $0A, $00, $9E, $33, $30, $37, $32, $00, $00, $00

        lda #$7f
        sta $DC0D       ;"Switch off" interrupts signals from CIA-1
        and $D011
        sta $D011       ;Clear most significant bit in VIC's raster register

        lda #$01         
        sta $D012       ; set raster to occour 1 lines down

        lda #<irq_handler
        sta $0314       ; set low bit of start
        lda #>irq_handler
        sta $0315       ; set high bit of start

        lda #$01
        sta $D01A       ;enable raster interrupts
        jmp @endloop


        inc $d020
        ldy #$29+$7c ;change the $29 to change direction, $00 = up, $50=down $27=left, $29 =right
        inc frame
        lda frame
        and #$01
        beq @loopy
        lda $d018
        and $0f
        ora #$10
        sta $d018
        jsr scroll_btof
        jmp @exit
        lda $d018
        and $0f
        ora #$20
        sta $d018
        jsr scroll_ftob

@exit   dec $d020
        asl $D019
        JMP $EA31

        ldx #$7c
        LDA $0400-$28,y
        STA $0800,x
        LDA $047D-$28,y
        STA $087D,x
        LDA $04FA-$28,y
        STA $08FA,x
        LDA $0577-$28,y
        STA $0977,x
        LDA $05F4-$28,y
        STA $09F4,x
        LDA $0671-$28,y
        STA $0A71,x
        LDA $06EE-$28,y
        STA $0AEE,x
        LDA $076B-$28,y
        STA $0B6B,x
        bpl @loop1

        ldx #$7c
        LDA $0800-$28,y
        STA $0400,x
        LDA $087D-$28,y
        STA $047D,x
        LDA $08FA-$28,y
        STA $04FA,x
        LDA $0977-$28,y
        STA $0577,x
        LDA $09F4-$28,y
        STA $05F4,x
        LDA $0A71-$28,y
        STA $0671,x
        LDA $0AEE-$28,y
        STA $06EE,x
        LDA $0B6B-$28,y
        STA $076B,x

        bpl @loop1
2018-04-18 17:29

Registered: Apr 2008
Posts: 280
Perhaps and #$0f instead of and $0f ?
2018-04-18 17:38

Registered: Mar 2018
Posts: 23
Quote: Perhaps and #$0f instead of and $0f ?

Hahaha, I am forever doing that. Nicely spotted!
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Users Online
Guests online: 32
Top Demos
1 Uncensored  (9.7)
2 Comaland 100%  (9.7)
3 Unboxed  (9.7)
4 Edge of Disgrace  (9.7)
5 Coma Light 13  (9.6)
6 The Shores of Reflec..  (9.6)
7 Lunatico  (9.6)
8 Wonderland XII  (9.6)
9 Old Men in Used Cars  (9.5)
10 C=Bit 18  (9.5)
Top onefile Demos
1 Smile to the Sky  (10)
2 Arok 20 Invitation  (9.6)
3 Daah, Those Acid Pil..  (9.5)
4 FMX Music Demo  (9.5)
5 Crystal Gazer  (9.5)
6 Pandemoniac Part 2 o..  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rewind  (9.5)
9 Party Horse  (9.4)
10 Dawnfall  (9.4)
Top Groups
1 Oxyron  (9.4)
2 Booze Design  (9.4)
3 Censor Design  (9.4)
4 Finnish Gold  (9.3)
5 The Transfer Team  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.9)
3 Irata  (9.8)
4 Wotnau  (9.7)
5 hedning  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2018
Page generated in: 0.057 sec.