Here are the changes I have made to the assembly code to try to get it to work with PicBasic:
commented out EXTERN AARGB3, UDATA_ACS, IDATA, CODE, edited variable descriptions so that variables are declared in PicBasic.
Original Code:
I edited out where the result is moved to AARGB3, and just use the word variables _x, _y, and _ang to store the results. Commented out Globals and End. And of course added ASM and ENDASM.Code:; Import the address the compiler uses to store 32-bit return values EXTERN AARGB3 UDATA_ACS ; Variable declarations i RES 1 j RES 1 quad RES 1 x RES 2 y RES 2 ang RES 2 dy RES 2 dx RES 2 IDATA ; Table of arctan values atans DW D'16384', D'9672', D'5110', D'2594', D'1302', D'652', D'326', D'163' DW D'81', D'41', D'20', D'10', D'5', D'3', D'1' CODE
My code:
Please let me know if you have any suggestions. It does compile without errors, but I do not get useful data out. When I input 5461 as the angle, I get the sin=29998, and cos=405. The result should be 15000, and 25980. But then if I run it again, a different value pops up for cos, that still does not get close to expected values.Code:i var byte j Var byte quad var byte x var word y var word ang var word dy var word dx var word goto main asm ;IDATA ; Table of arctan values atans DW D'16384', D'9672', D'5110', D'2594', D'1302', D'652', D'326', D'163' DW D'81', D'41', D'20', D'10', D'5', D'3', D'1' ;CODE -snip ; Output the calculated _x and _y values sc_output: ;movff _y, AARGB3 ;movff _y+1, AARGB3+1 ;movff _x, AARGB3+2 ;movff _x+1, AARGB3+3 -snip ; Output the calculated angle and hypotenuse values as_output: ;movff _ang, AARGB3 ;movff _ang+1, AARGB3+1 ;movff _x, AARGB3+2 ;movff _x+1, AARGB3+3 ; Restore the stack to its previous state movf POSTDEC1 movff INDF1, FSR2L return endasm ; Export the functions to the linker 'GLOBAL sin_cos 'GLOBAL atan2_sqrt 'END
Thanks,
Walter




Bookmarks