[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: killing time in 6502 assembly



Jim Butterfield <fjb@torfree.net> wrote:

> On Sun, 07 Feb 1999 16:44:11 +0500, joker21@earthlink.net wrote:
> 
> > I'd never thought I'd say this, but the Nes is too fast!
> > I'm trying to kill about 3/4 of a second. I've come up with this:
> > [long string of nops]
> > This just loops about 255*3 then comes back. Is there an opcode better
> > that nop? Or a whole better why to do it?
> 
> If you're doing this on a Commodore product, the easiest (and most
> dependable) way is just to watch the "jiffy timer", which is updated
> by the interrupt services 60 times a second.  Count 45 jiffy changes,
> and you're there.
> 
> On most other platforms, you'll have an I/O chip that contains a timer
> .. set it and have it signal or interrupt you.
> 
> Paul Guertin posted code for a decent delay loop.  On a machine such
> as the Commodore 128, you have to watch it, though:  the clock speed
> can be changed by the user.  And new architectures which fit the 6502
> family with a high-speed clock raise the same problems.  Look to a
> jiffy or hardware timer of some sort.  Some even watch the video
> raster to get timing data; again, this can be tricky since vertical
> retrace differs in different parts of the world.
> 

That's if you're using the pure code, and not watching TI$, right?

My own code usually has some wierd type of timer.  From an interupt, I
have a portion such as:

LDA RASTER
EOR #$FF
STA RASTER

Remember, that's played from an interupt, so it is executed once every
1/60th of a second.  (1/50th a la PAL).

Now, in your code have something like:

        LDA RASTER
-       CMP RASTER
        BEQ -

Loops until the value of RASTER changes, which is every 1/60th of a
second.  Now, multiply this by however long you want it to occur.   IE:
For one second, you would do that 60 times.

Drawback is obvious: the smallest time slice you could get is 1/60th of
a second.  Of course, you could probably software-hack a method of
getting down to multiples of 1/60th of a second, ie: 1/30th of a second,
1/120th of a second, etc.

-p

>                --Jim


-- 
Cyberad/RPG aka Patrick M Pritchard * http://www.interlog.com/~cr
PLUR- Peace Love Unity Respect -Live It, Love It, Be It, BELIEVE!
RENEGADE PROGRAMMING GROUP IN 1999 -- Taking It To The Next Level