explaination of PUB end
ksam
Posts: 19
I know it is probably pretty simple, but could someone explain how PUB end works exactly?
I'm having a hard time with
if cog
cogstop (cog ~ -1)
I'm probably reading too much into it
I'm having a hard time with
if cog
cogstop (cog ~ -1)
I'm probably reading too much into it
Comments
You posted a pretty typical bit of code to stop an I/O driver's cog where the cog # + 1 is kept in a variable called cog. Read the description of COGNEW and COGSTOP and read the description of the unary post-fix "~" operator which is used to zero the variable cog after its value is used for the expression.
The cognew method can return 0 to 7, so 1 is added there. Then in PUB stop, one will only cogstop if cog is non-zero.
If cogstop(cog~ -1) is run, then the cog identifier or cognew return +1 from PUB start is used to stop the cog and the ~ will set cog back to zero.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
Thanks