magazine logo
Welcome to the official Attitude website - Europe's #1 C64 scene disk magazine
A Few Things You Might Want To Know
by Puterman/Civitas

I thought long and hard, without managing to come up with any interesting effect to describe, so I decided to write down a couple of small ideas and call it an article, so that Cactus won't kill me (ed. Don't be afraid, Linus, at the moment I do not plan to kill anyone. :)). The idea is to give people some ideas, that can make their code better. Experienced coders won't learn anything here, but if you're trying to get started with coding, you might pick up a thing or two. So, time to cut that crap and go to the coding...

1. Setting sprite pointers quickly.

Let's say you have several sprites on the screen, and you need to change the sprite pointers quickly. The most naive idea would be to LDA a sprite pointer value for each sprite and STA it into SCREENMEM+$03F8 etc. For 8 sprites that would take at least 6x8=42 cycles. If you're trying to do something interesting in a tight raster loop, you can't waste 42 cycles on just changing the sprite pointers, so instead you'll have another screen memory prepared with the new sprite pointers, and then you just STA a new value into $D018. That can be done in 6 (LDA immediate, STA absolute) cycles, which is a bit better than 42.

One thing you could do very easily with this trick is to make a 16 pixels wide sprites tech-tech (if you only use $D018), and a wider one, if you're using more than one VIC bank.

2. FLD to get rid of bad lines.

Sometimes bad lines can be kind of irritating, although as a C-64 you have to love them, right. :) FLD (Flexible Line Distance) is a way to scroll individual char lines vertically, and it works by pushing the bad lines forward. So, while you're doing the FLD, there aren't any bad lines. Aha... So you could use an FLD to get rid of the bad lines, to get the same number of cycles on each raster line. Of course you can't have any graphics on the part of the screen where you're doing the FLD, but I guess you've figured that out already.

3. Unrolling loops.

Well, you've probably realized that unrolled loops (speedcode) is a way to do things that you can't do with loops, but anyway, if you've missed it... Unroll your raster loops and see how many new cycles you get to play with when you don't have to worry about loop counters and branching. You don't have to unroll your loops completely, it's often a great help just to unroll a raster loops so that the loop covers a whole char line, not just one raster line.

If you're going to unroll a big, fat raster loop, or some other code that needs to run at maximum speed, try to generate the code, i.e. write code that write the code for you. It's easier than you think, and you will save tons of time. Cutting and pasting might work in some enviroments, but it's better to let the computer to the work for you, than the other way around (in 400 years, when computers are seen as our equals, I'd be demonized for saying things like these).

I wish I could come up with something more to write now, but I'm running out of inspiration and time, so I'll send this off to Cactus now. I hope I'll find something a bit more inspiring to write about.

PUTERMAN/CIVITAS

   Add/view comments on this article (comments: 0)

SCENE GROUPS
 
OPINION POLL
Do you believe we are
able to cope with
releasing "Attitude"
on a regular basis?

yes no

 YES: 279 (70.45%)
NO:117 (29.55%) 

NEWS COMMENTS

ART COMMENTS

STATISTICS
all visits:

visits today:


website started:
23/09/2004
 
Official Webpage
of Attitude
Copyright 2004-2018
 
DJ Gruby/TRIAD