My scrolling routine is bad

For anything related to VDP (plane, color, sprite, tiles)

Moderators: BigEvilCorporation, Mask of Destiny

Post Reply
Jaklub
Interested
Posts: 41
Joined: Mon Aug 24, 2009 1:36 pm

My scrolling routine is bad

Post by Jaklub » Tue Aug 03, 2010 7:40 pm

I've got another problem I'm trying to solve without good results.
I want to create an illusion of 2 layers of background using only 1 plane. Horizontal scrolling per single line is used.
Here's my C code:

Code: Select all

volatile u16 *pw;
volatile u32 *pl;
pw = (u16 *) GFX_DATA_PORT;
pl = (u32 *) GFX_CTRL_PORT;
s16 i;
bgval[0]++;
bgval[1]+=2;
if(bgval[0]>=512) bgval[0]-=512;
if(bgval[1]>=512) bgval[1]-=512;
// when I cut the code here, no slowdown occurs
for(i=0; i<224; i+=2) {
*pl = ((0x4000 + ((HSCRL + ((i & 0xFF) * 4)+2) & 0x3FFF)) << 16) + (((HSCRL + ((i & 0xFF) * 4)+2) >> 14) | 0x00); *pw = bgval[0];
}
for(i=1; i<224; i+=2) {
*pl = ((0x4000 + ((HSCRL + ((i & 0xFF) * 4)+2) & 0x3FFF)) << 16) + (((HSCRL + ((i & 0xFF) * 4)+2) >> 14) | 0x00); *pw = bgval[1];
}
As you can see, I want to change 224 values of scrolling at once. That's a lot, and in later progress I'll probably need whole 512. Using many subroutines is too slow, so I try to minimalize the amount of them. Basically, this is modified code of VDP_setHorizontalScroll script from Stef's devkit. While this works fine for a menu, where practically no other code is executed, it slows the game down.
The question is: what is the fastest way to change a scroll value in C / at all? I've tried to get the needed info from Charles MacDonald's documentation, but failed miserably, I'm sure I have not enough technical knowledge yet. =P Thanks in advance.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Tue Aug 03, 2010 7:44 pm

Why you calculate all the math for *pl every time? You can precalculate it once, and also do everything in single loop, which is faster.

Jaklub
Interested
Posts: 41
Joined: Mon Aug 24, 2009 1:36 pm

Post by Jaklub » Tue Aug 03, 2010 9:40 pm

After your post I realised *pl indeed can be set once and then only modified, but because I suck at using binary operators (I never could really understand them), I'll have hard time trying to make a good loop. Thanks for your post.

Gigasoft
Very interested
Posts: 95
Joined: Fri Jan 01, 2010 2:24 am

Post by Gigasoft » Wed Aug 04, 2010 2:00 am

The VDP address autoincrements by the amount set in register 15. So, you only need to set the address once.

Jaklub
Interested
Posts: 41
Joined: Mon Aug 24, 2009 1:36 pm

Post by Jaklub » Wed Aug 04, 2010 9:50 am

Thank you, now I have a single loop. Problem solved.

8bitwizard
Very interested
Posts: 159
Joined: Sat Feb 24, 2007 11:35 pm
Location: San Antonio, TX

Post by 8bitwizard » Thu Aug 05, 2010 1:30 pm

I use these for talking to the VDP:

Code: Select all

#define VDP_DATA     ((volatile unsigned short *) 0xC00000)
#define VDP_CTRL     ((volatile unsigned short *) 0xC00004)
#define VDP_STAT     ((volatile unsigned short *) 0xC00004)

#define VDP_DATA_L   ((volatile unsigned long *) 0xC00000)
#define VDP_CTRL_L   ((volatile unsigned long *) 0xC00004)
Then I can do things like "*VDP_DATA = *p++;"

I have a whole .h file full of hardware addresses like that.

Post Reply