6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 8:26 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Question on AND'ing
PostPosted: Mon Oct 19, 2020 4:01 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
I have a simple animation loop going on the C64.
In that loop, I have a delay between each frame. During each frame, I update a ZP counter (single byte).

My delay looks something like this (KickAsm):

Code:
            lda ZP.COUNTER
            and ObjectAnimationDelay, y
            bne !+

            clc
            lda ObjectAnimationIndex, y
            adc #$01
            sta ObjectAnimationIndex, y
        !:


Now, if I have a value such as $03 in the ObjectAnimationDelay, I notice the frames update every 4th frame. Which is correct. And, it's "even". Meaning, no single frame gets more time than any other.

Other values that seem to work OK are: $0f, $1f, etc.

What is odd is that some values cause funny behaviors. One value is $06.

If I use that, one frame will get much longer display time than the others.
My assumption is because 6 isn't evenly divisible by 256. But I would have thought the amount of time visible would only be slightly longer than the other frames but in reality, it's like 5 times longer. Just doesn't seem proportional.

So then I tried changing to other values that ARE evenly divisible by 256 and some of them behave the same way. Some don't.

For example, these work just fine: $03, $07, $0f, $1f, $3f
These do not work: $2f, $4f

I'm perfectly OK with sticking to a handful of "good values". I'd just like to understand why some numbers are drastically out of proportion.

Thanks!

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question on AND'ing
PostPosted: Mon Oct 19, 2020 4:36 pm 
Offline

Joined: Sat Jan 02, 2016 10:22 am
Posts: 197
AND is working on the individual bits, so if you convert your numbers to binary it should make it clearer what's happening.

Using 6 as an example that's 110 in binary, it's still counting 1 frame in 4 as the 03 value would, but the zero flag will be set twice in succession, then skip 6.
Code:
xxxxx000 AND 00000110 = 00000000 
xxxxx001 AND 00000110 = 00000000
xxxxx010 AND 00000110 = 00000010
xxxxx011 AND 00000110 = 00000010
xxxxx100 AND 00000110 = 00000100
xxxxx101 AND 00000110 = 00000100
xxxxx110 AND 00000110 = 00000110
xxxxx111 AND 00000110 = 00000110


Top
 Profile  
Reply with quote  
 Post subject: Re: Question on AND'ing
PostPosted: Mon Oct 19, 2020 5:24 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
OK that makes sense. I knew I needed to create a large truth table to see a real pattern.
Thanks

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question on AND'ing
PostPosted: Tue Oct 20, 2020 2:43 am 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
For this purpose, you could use a "virtual clock" scheduling algorithm as follows:
Code:
  LDA animSched
  CMP animClock
  BNE DoNothing
  CLC
  ADC #animDelay
  STA animSched

  ; Do animation stuff

  INC animIndex  ; point to next frame
DoNothing:
  RTS


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: