6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 10, 2024 1:57 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Jan 31, 2019 2:42 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
Hi All,

I have this bit of code in my CNC-64 main loop

Code:
        lda frM                 ; (4) get fraction MSB to test for negitive
        bmi @skipB              ; (3) skip if fraction < 0, else do ystep
       
         ; Toggle YStep
        lda outByte             ; (4) outByte^=0x04, toggle yStep for each step
        eor bStepBit            ; (4) XOR in ysstep bit (toggle it)
        sta outByte             ; (4) save it
        LIBMATH_SUB16_AAAAAA frL, frM, daL, daM, frL, frM
@skipB  LIBMATH_ADD16_AAAAAA frL, frM, dbL, dbM, frL, frM

        ; Toggle XStep
xsteps  lda outByte             ; (4) outByte ^= 01, toggle xStep for each step
        eor aStepBit            ; (4) XOR in xstep bit (toggle it)
        sta outByte             ; (4) save it

wdone   OutBufWrite             ; (24) implic. 'wdone beq' if buff full in macro


It is a simplified version of the Bresenham algorithm that decides if both the X and Y axis need to step or just X. In cases where delta X > delta Y, then aStepBit is X and bStepBit is Y, or vice versa if delta Y is greater. This works fine. I came up with the idea below which uses more memory but saves about 5 cycles in the cases where both axis are stepping. The problem is that it does not work properly.


Code:
        lda frM                 ; (4) get fraction MSB to test for negitive
        bmi @skipB              ; (3) skip if fraction < 0, else do ystep
       
        ; Toggle YStep
        lda outByte             ; (4) outByte^=0x04, toggle yStep for each step
        eor aStepBit            ; (4) XOR in ysstep bit (toggle it)
        eor bStepBit            ; (4) XOR in xstep bit (toggle it)
        sta outByte             ; (4) save it
        LIBMATH_SUB16_AAAAAA frL, frM, daL, daM, frL, frM
        LIBMATH_ADD16_AAAAAA frL, frM, dbL, dbM, frL, frM
        jmp wdone               ; (3)

@skipB  LIBMATH_ADD16_AAAAAA frL, frM, dbL, dbM, frL, frM
xsteps  lda outByte             ; (4) outByte ^= 01, toggle xStep for each step
        eor aStepBit            ; (4) XOR in xstep bit (toggle it)
        sta outByte             ; (4) save it

wdone   OutBufWrite             ; (24) implic. 'wdone beq' if buff full in macro
 


The difference in the output between the two (one line of buffer) is below. I have stared at this so long that I can't see what is going wrong. Any help appreciated.

Correct:
>C:c000 01 04 05 04 05 00 01 00 01 04 05 04

Incorrect:
>C:c000 01 fe 05 04 05 fe 01 00 01 fe 05 04


Last edited by Jeff_Birt on Thu Jan 31, 2019 3:06 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 31, 2019 3:01 pm 
Offline

Joined: Sat Nov 11, 2017 1:08 pm
Posts: 33
Can you post a bit more code e.g. Wdone. Is important what the flags are?

Also can you put the Toggle YStep code after the sub add? Then you can combine the last eor and store.?

Not sure it saves 5cycles as you have to add the Jmp.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 31, 2019 3:14 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
dp11 wrote:
Can you post a bit more code e.g. Wdone. Is important what the flags are?

Also can you put the Toggle YStep code after the sub add? Then you can combine the last eor and store.?

Not sure it saves 5cycles as you have to add the Jmp.


I added 'wdone' to the listings above, it comes after the other code so has no effect.

The 'outBufWrite' expects the value to be in A so if I rearrange things I will still need to stash A somehwere before doing the LIBMATH_ADD_16.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 31, 2019 3:35 pm 
Offline

Joined: Sat Nov 11, 2017 1:08 pm
Posts: 33
outBufWrite : What does it expect to be in A? If the code takes the wdone path A will not be outbyte.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 31, 2019 3:40 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
dp11 wrote:
outBufWrite : What does it expect to be in A? If the code takes the wdone path A will not be outbyte.


A is the byte to be saved to the buffer. If a step is to be made that bit is toggled in outbyte. So, yes I see what you are saying, that I did the ADD?SUB after that so my 'A' got thrahsed! THANKS! I think I was so focused on what I 'thought' it shoudl do I missed what it was actually doing :)

I changed it to below and it now works.

Code:
        lda frM                 ; (4) get fraction MSB to test for negitive
        bmi @skipB              ; (3) skip if fraction < 0, else do ystep
       
        ; Toggle YStep
        LIBMATH_SUB16_AAAAAA frL, frM, daL, daM, frL, frM
        LIBMATH_ADD16_AAAAAA frL, frM, dbL, dbM, frL, frM
        lda outByte             ; (4) outByte^=0x04, toggle yStep for each step
        eor bStepBit            ; (4) XOR in ysstep bit (toggle it)
        eor aStepBit            ; (4) XOR in xstep bit (toggle it)
        sta outByte             ; (4) save it
        jmp wdone               ; (3)

@skipB  LIBMATH_ADD16_AAAAAA frL, frM, dbL, dbM, frL, frM
xsteps  lda outByte             ; (4) outByte ^= 01, toggle xStep for each step
        eor aStepBit            ; (4) XOR in xstep bit (toggle it)
        sta outByte             ; (4) save it

wdone   OutBufWrite             ; (24) implic. 'wdone beq' if buff full in macro


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 31, 2019 3:49 pm 
Offline

Joined: Sat Nov 11, 2017 1:08 pm
Posts: 33
sometimes it just takes someone else to talk too.

You can save a few bytes by removing the ending common subexpression :

Code:
        lda frM                 ; (4) get fraction MSB to test for negitive
        bmi @skipB              ; (3) skip if fraction < 0, else do ystep
       
        ; Toggle YStep
        LIBMATH_SUB16_AAAAAA frL, frM, daL, daM, frL, frM
        LIBMATH_ADD16_AAAAAA frL, frM, dbL, dbM, frL, frM
        lda outByte             ; (4) outByte^=0x04, toggle yStep for each step
        eor bStepBit            ; (4) XOR in ysstep bit (toggle it)

        jmp wdone               ; (3)

@skipB  LIBMATH_ADD16_AAAAAA frL, frM, dbL, dbM, frL, frM
xsteps  lda outByte             ; (4) outByte ^= 01, toggle xStep for each step
wdone
        eor aStepBit            ; (4) XOR in xstep bit (toggle it)
        sta outByte             ; (4) save it

         OutBufWrite             ; (24) implic. 'wdone beq' if buff full in macro


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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: