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