02.07.2013 Views

Amiga Computing - Commodore Is Awesome

Amiga Computing - Commodore Is Awesome

Amiga Computing - Commodore Is Awesome

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

DMA, and found that every now and<br />

then you get a stationary vertical bar<br />

running down your screen. If you turn<br />

off sprite DMA at the exact moment the<br />

sprite is being displayed it will continue<br />

to display the last line of sprite data<br />

forever.<br />

To disable sprite DMA properly you<br />

have to use — yes, you guessed it — a<br />

VPOS wait loop. Simply wait for the last<br />

line, 305, before disabling the sprite<br />

DMA and you can avoid hitting the<br />

sprite, as it will never reach that low.<br />

IF YOU are ever unfortunate enough to<br />

listen in to a crowd of programmers<br />

talking, they will sooner or later (usually<br />

sooner) mention how few raster lines<br />

their latest routine takes. Raster lines, in<br />

this particular instance, are a measure<br />

of time — it's the time taken for the video<br />

beam to trace one line across the<br />

screen. As it draws a whole screen of<br />

over 300 lines every 50th of a second,<br />

it's not a really large measure of time, in<br />

fact it's only 63 microseconds.<br />

It's quite simple to do — turn the<br />

background colour to red. run your<br />

routine, and turn the background colour<br />

to black when it finishes. You will see a<br />

red flash on the screen. and you count<br />

the number of red lines. This gives you<br />

the speed of your routine in raster lines.<br />

You have to run this routine continuously,<br />

once every frame, otherwise the<br />

screen will just flash once — for 1/50 of a<br />

second — and stop. You'll have to count<br />

the lines pretty quickly to make use of<br />

this ploy.<br />

How do you do it? Yet another<br />

application for this wonderful VPOS wait<br />

routine. Here's the basic theory. I'll<br />

leave the code for you this time (and<br />

here's one I didn't prepare earlier...)<br />

WAIT for line 150 (somewhere in the<br />

middle of the screen, to make it easy to<br />

see)<br />

CHANGE BACKGROUND TO RED<br />

BRANCH TO YOUR SUBROUTINE<br />

CHANGE BACKGROUND TO BLACK<br />

WAIT FOR LINE 140 (to make sure<br />

one whole frame has appeared)<br />

JUMP BACK TO BEGINING.<br />

Why do I wait for line 140 before<br />

jumping back to the beginning? If your<br />

routine is very fast it may only take a<br />

fraction of the line to finish. In this case.<br />

it will jump back to wait for line 150, and<br />

as it will still be line 150 it will go on to<br />

execute a second time in one frame,<br />

giving a misleading raster line time.<br />

If you're feeling bored you can<br />

experiment with different colours<br />

instead of red. You've got 4095 to try<br />

MOO would be a little pointless).<br />

There are a few flaws with the raster<br />

line timing method. You'll still find<br />

programmers saying "My blitter stack<br />

interrupt routine takes that' (holding<br />

forefinger and thumb a very short<br />

distance apart) 'much time", This is a bit<br />

pointless, as you don't know whether he<br />

is using a 9 inch monitor or a 26 inch<br />

monitor.<br />

Go up to them and say, "Yes, but how<br />

many lines is that?". You can look very<br />

smug and they'll be very embarrassed.<br />

Ten to one they're using a TV and can't<br />

count the individual lines without getting<br />

a migrane.<br />

THERE IS nothing more annoying than<br />

a piece of code that just refuses to<br />

work. It's a really good feeling when a<br />

routine works first time, but with long<br />

and complex ones that doesn't happen<br />

very often.<br />

A good 80 to 90 per cent of bugs can<br />

be trapped with a decent debugger.<br />

such as Monam 2 from HiSoft. but some<br />

bugs are so cleverly hidden and so<br />

perfect in design that you have to resort<br />

to very special tactics to dig them out.<br />

Here, for the first time. I reveal some<br />

of these alternative debugging practices:<br />

Print out your source code: You will<br />

often find the problem is obvious by the<br />

time it is completed. This doesn't have<br />

anything to do with what's printed on the<br />

paper. it's just that the time taken to<br />

print out the source gives you time to<br />

think.<br />

You really need a cheap old noisy dot<br />

matrix printer for this, laser printers work<br />

too quickly, and they don't make the<br />

right noise.<br />

Some people have successfully<br />

debugged by removing the ribbon and<br />

printer paper on their machine, printing<br />

nothing. The time delay and the noise<br />

are still right, but you don't waste<br />

valuable printer paper and ink.<br />

Invite a friend round: Every coder<br />

knows some annoying little person who<br />

comes round, stands behind you<br />

looking over your shoulder, who knows<br />

almost nothing about programming but<br />

comes out with statements like<br />

"Shouldn't that be a DO, not an AO?'<br />

every now and then while your typing.<br />

What's even more annoying is that<br />

they are more often than not right. A<br />

useful debugging technique, but it has a<br />

high embarrassment factor.<br />

The kludge: This is the dirtiest of<br />

debugging techniques. Frowned upon<br />

by almost every decent programmer —<br />

but a lot resort to it in a dire emergency<br />

— it involves logic which goes something<br />

like this:<br />

This code is theoretically perfect so it<br />

should work. It doesn't. If I insert<br />

something that is theoretically unnecessary,<br />

or even theoretically wrong, it may,<br />

with a bit of luck, fix the problem.<br />

Good examples of kludges are<br />

Jolyon Ralph<br />

cures the coding<br />

blues with his<br />

previously top<br />

secret bumper<br />

bug-busting<br />

hints<br />

randomly clearing registers at the<br />

beginning of a routine, or changing the<br />

length of a DBRA loop by +1 or -1 "just<br />

to see what it would do". The whole<br />

kludge ethic is based on the philosophy<br />

that 'As long as the program works.<br />

I don't have to understand why it<br />

works".<br />

Naturally, this is rather repulsive to<br />

most programmers, except when faced<br />

with a tight deadline involving sums of<br />

money. A very few programmers code<br />

purely by the kludge method, leading to<br />

unbeheveably badly-written code. I've<br />

seen some of their games.<br />

The US foreign policy. debugging<br />

method: This was something I developed<br />

when programming the Spectrum<br />

in Z80. I noticed that it was taking 20<br />

per cent of my time to write a routine.<br />

and 80 per cent to debug it. I also<br />

noticed that about 40 per cent of my<br />

routines worked first time (If only it was<br />

that way now!).<br />

So I worked out that debugging was<br />

a waste of time. All I had to do was<br />

write a routine, if it worked, great. If it<br />

didn't, nuke it and start again.<br />

If I could narrow down the error to a<br />

certain line, it was a simple matter of<br />

deleting the line, and the three lines<br />

above and below it, and rewriting it.<br />

This technique definitely works, but<br />

the only problem is it makes your<br />

fingers ache.<br />

Next month: More of the same, with<br />

loads of interesting facts about<br />

interrupts and copperliste Don't<br />

you just love it? Answers on a<br />

postcard please.<br />

AMIGA COMPL 'MG November 1 990 1<br />

25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!