Func Call Question
I cant seem to find in the help file how to pass a parameter to a Func.
for example I have a Func called Acc_error and I want to pass in __param3 the base number with which to calculate the error.· I will then return the result in __wparam12.· If I do this:
__param3 = AccBase
TmpW1 = Acc_Error
I get the correct results, however I thought if you declaired in the Func Def
Acc_Error Func 2,1
It would let you write
tmpW1 = AccError· AccBase
and it would pass accBase in __param1
where am I tripping up?
Post Edited (Radio Shack Jim) : 11/19/2009 2:35:06 AM GMT
for example I have a Func called Acc_error and I want to pass in __param3 the base number with which to calculate the error.· I will then return the result in __wparam12.· If I do this:
__param3 = AccBase
TmpW1 = Acc_Error
I get the correct results, however I thought if you declaired in the Func Def
Acc_Error Func 2,1
It would let you write
tmpW1 = AccError· AccBase
and it would pass accBase in __param1
where am I tripping up?
Post Edited (Radio Shack Jim) : 11/19/2009 2:35:06 AM GMT
Comments
MyFunc FUNC return bytes, minimum number of parameters, maximum number of parameters
If you are expecting to pass different numbers of bytes (sometimes a word, sometimes a word and a byte, etc), then you either need to parse and decide what to do based on __PARAMCNT (in your function itself):
MyFunc FUNC 2, 1, 3
FUNC MyFunc
IF __PARAMCNT = 1 THEN ' only one byte? clear MSB of wparam12 and clear param3
__PARAM2 = 0
__PARAM3 = 0
ELSEIF __PARAMCNT = 2 THEN
__PARAM3 = 0
ENDIF
tmpW1 = __WPARAM12
tmpB3 = __PARAM3
' do stuff
RETURN tmpW1
ENDFUNC
--- OR ----
you need to force the function call to "promote" values to Words, even if you pass a byte, e.g.
MyFunc FUNC 2, 3, 3, Word, Byte
would be a function that returns two bytes (__WPARAM12) and expects 3 bytes as a Word and a Byte. The cool thing is even if your value for the Word parameter is <256, SX/B will clear the upper byte of the parameter word. So....
FUNC MyFunc
tmpW1 = __WPARAM12
tmpB3 = __PARAM3
' do some stuff
RETURN tmpW1
ENDFUNC
If I do this:
someWord = MyFunc, 1, 10
then param1 = 1
param2 = 0
param3 = 10
If I do this:
someWord = MyFunc, 2000, 10
then param1 = 2000 & $FF
param2 = 2000 >> 8
param3 = 10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
RS_JIM