Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Screen copy CPU intensive
2007-09-21 20:17
johncl

Registered: Aug 2007
Posts: 37
Screen copy CPU intensive

I am working on a little game for the C64 and have stumbled upon a slight problem. A smooth scroller is darn CPU intensive! Its a simple sidescroller where I want to scroll the upper 18 lines. The copy required to move the character and color ram is very expensive! I use kickassembler and at first I tried this:

.macro ScrollLines(screen,from,to) {
.var half = round([to-from]/2)
ldx #0
jmp !loop+
.align $100
!loop:
.for (var i=from;i<from+half;i++) {
lda screen+1+[i*40],x
sta screen+[i*40],x
lda SCREEN_COLOR+1+[i*40],x
sta SCREEN_COLOR+[i*40],x
}
inx
cpx #39
bne !loop-
ldx #0
jmp !loop+
.align $100
!loop:
.for (var i=from+half;i<=to;i++) {
lda screen+1+[i*40],x
sta screen+[i*40],x
lda SCREEN_COLOR+1+[i*40],x
sta SCREEN_COLOR+[i*40],x
}
inx
cpx #39
bne !loop-
}

So here I unroll a full column copy in two parts (because bne wont work if I unroll whole column). This even aligns the two loops so that the bne doesnt cross any page boundaries and end up costing another cycle. But still, this routine eats up my CPU big time.

I then tried a complete unroll of a pure copy:

.macro ScrollLines2(screen,from,to) {
.for (var i=from*40;i<=to*40;i++) {
lda screen+1+i
sta screen+i
lda SCREEN_COLOR+1+i
sta SCREEN_COLOR+i
}
}

This also copies the unecessary column too that I need to copy from my map data. But this complete unroll uses almost 2/3 of the screen raster time! Even with this I have to split up my copy so the top part is copied at the bottom redraw of the refresh and the bottom part on start of next screen refresh.

Am I doing something wrong here?
 
... 25 posts hidden. Click here to view all posts....
 
2007-09-22 18:33
doynax
Account closed

Registered: Oct 2004
Posts: 212
Quote: @doynax: "There are certain alternative hardware tricks..."

Could you be more specific? :)


Well.. To be honest I can't think of anything else that'd be useful off hand. But the hack I was talking about ought to qualify.

Basically I abort every other badline and switched between a pair of charsets every eight lines, which essentially creates a charmode with twice the normal tile height (i.e. half as many char indices/colors to manage and twice as much graphics data). By using the NMI timers kind of like in Ninja's FLI display it cost more than about 500 cycles per frame, what with the time regained from the badlines. And with the IRQ vector free for sprite multiplexing it's actually quite usable in a game, although screen splits and other cycle-exact effects are a mess.
A neat point is that the missed badlines still increase the video matrix pointer so by starting the display a row late you get color ram double buffering for vertical scrolling :)

Anyway, here's the proof-of-concept demo: http://www.minoan.ath.cx/~doynax/6502/Balls%20of%20the%20Scroll..
(I know it isn't all that fancy but I'm a novice when it comes to VIC hacking so I'd like to pretend I invented a new graphics mode ;)
2007-09-22 18:35
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: Well.. To be honest I can't think of anything else that'd be useful off hand. But the hack I was talking about ought to qualify.

Basically I abort every other badline and switched between a pair of charsets every eight lines, which essentially creates a charmode with twice the normal tile height (i.e. half as many char indices/colors to manage and twice as much graphics data). By using the NMI timers kind of like in Ninja's FLI display it cost more than about 500 cycles per frame, what with the time regained from the badlines. And with the IRQ vector free for sprite multiplexing it's actually quite usable in a game, although screen splits and other cycle-exact effects are a mess.
A neat point is that the missed badlines still increase the video matrix pointer so by starting the display a row late you get color ram double buffering for vertical scrolling :)

Anyway, here's the proof-of-concept demo: http://www.minoan.ath.cx/~doynax/6502/Balls%20of%20the%20Scroll..
(I know it isn't all that fancy but I'm a novice when it comes to VIC hacking so I'd like to pretend I invented a new graphics mode ;)


IMO that IS a perfect use of the C64 HW capabilities. Good work! I'm impressed.
2007-09-22 19:13
doynax
Account closed

Registered: Oct 2004
Posts: 212
Quote: IMO that IS a perfect use of the C64 HW capabilities. Good work! I'm impressed.

Thank you :)

Hopefully I'll manage to finish that game sometime..
2007-09-22 20:26
johncl

Registered: Aug 2007
Posts: 37
That is a pretty nice demo of C64 trickery indeed! But for this game I will stick with more simple coding atm.

Even though my horizontal scroller works fine with 17 lines now, it seems I have to go for a double buffered solution simply because unrolling screen and color ram copies in both directions is just eating up all my memory. Since double buffering only requires me to unroll a color ram copy (6 bytes per char * 39 * 17 lines * 2 directions = 7956 bytes) and chances are that I dont need a full unroll but can do one using absolute,x indexing an still have enough cpu time for the rest. For the screen char data I will be fine since I will maximum have 4 pixel scrolls leaving a complete frame free for char copy (where I dont have to worry about where the raster is).

Its strange that this thing turned up to become a challenge after all. Which makes it all the more interesting a project. :)
2007-09-22 21:03
cadaver

Registered: Feb 2002
Posts: 1160
I don't know how much you need leftover rastertime, but I just want to mention that games like Turrican I/II/III do up-to-4-pixels-per-frame scrolling without unrolling either the screen or color copy routine. An example:

frame 1: shift screen data in hidden buffer
frame 2: shift color data, split in two halves
frame 3: repeat above...
2007-09-22 21:22
doynax
Account closed

Registered: Oct 2004
Posts: 212
Quote: I don't know how much you need leftover rastertime, but I just want to mention that games like Turrican I/II/III do up-to-4-pixels-per-frame scrolling without unrolling either the screen or color copy routine. An example:

frame 1: shift screen data in hidden buffer
frame 2: shift color data, split in two halves
frame 3: repeat above...


I'm amazed they had raster time left to do anything useful after that. Having to waste almost half the frame just on scrolling isn't exactly encouraging.

Of course they weren't full screen but still..
2007-09-22 21:55
raven
Account closed

Registered: Jan 2002
Posts: 137
I still havent seen any machine crash by running VSP, be it C64, C64C, C128 or SX64.

Is it verified that RAM refresh causes it?
2007-09-22 22:03
chatGPZ

Registered: Dec 2001
Posts: 11386
no, the actual cause is pretty much unknown. ram-refresh glitches is just the most popular guess :)
2007-09-22 22:20
cadaver

Registered: Feb 2002
Posts: 1160
Doynax: also notice the special "hell elevator" scene in Turrican II where you drop 8 pixels per frame :) *That* at least must consume all rastertime available..
2007-09-22 22:30
Hein

Registered: Apr 2004
Posts: 954
Quote: no, the actual cause is pretty much unknown. ram-refresh glitches is just the most popular guess :)

Guess??? wtf.. Graham guesses his way through life?
Previous - 1 | 2 | 3 | 4 - 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
Advanced
Users Online
MCM/ONSLAUGHT
DnP
wil
v3nt0r/ibex-crew
visionvortex
Guests online: 121
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 The Demo Coder  (9.6)
6 Edge of Disgrace  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Original Suppliers
1 Derbyshire Ram  (9.7)
2 Fungus  (9.3)
3 Black Beard  (9.2)
4 Baracuda  (9.2)
5 hedning  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.047 sec.