DCD function for SX
Hey all,
I've been playing around with the Stampworks examples with my SX28. I've been trying to keep with the spirit of each project and not cheat my way past the hard stuff [noparse]:D[/noparse]
Today while working on example 5 i ran into the "DCD" command used by the basic stamps, and not available under sx/b.
I wrote this function, and the program works as described in Stampworks, but i wonder if i really got it "right" or just cheated.
I've been playing around with the Stampworks examples with my SX28. I've been trying to keep with the spirit of each project and not cheat my way past the hard stuff [noparse]:D[/noparse]
Today while working on example 5 i ran into the "DCD" command used by the basic stamps, and not available under sx/b.
Regarding DCD the basic Stamp manual said...
The Decoder operator (DCD) is a 2n - power decoder of a four-bit value.
DCD accepts a value from 0 to 15, and returns a 16-bit number with the bit, described by value, set to 1.
for example:
result VAR Word
result = DCD 12 ' Set bit 12
DEBUG BIN16 ? result ' Display result (%0001000000000000)
I wrote this function, and the program works as described in Stampworks, but i wonder if i really got it "right" or just cheated.
' -----[noparse][[/noparse] Variables ]------------------------------------------------------- dcdIN VAR Byte dcdOut VAR Word ' -----[noparse][[/noparse]Subs ]------------------------------------------------------------ DCD Func 1,2
DCD: dcdIn = __PARAM1 dcdOut = $0001 Do While dcdIn > 1 dcdOut = dcdOut << 1 dec dcdIn Loop RETURN dcdOut
Comments
Be sure to declare your function as returning two bytes (word result) and expecting one (bit position to set):
Post Edited (JonnyMac) : 3/30/2007 4:13:44 PM GMT
Post Edited (JonnyMac) : 3/30/2007 4:13:54 PM GMT
It didn't occur to me to use the value as the shifter and a fixed # as the input, very nice.
I havn't run into anything yet that uses NCD, but i'm sure i will, Thanks for it!
Dumb question, since you can recreate these functions so efficiently, why are they not in the sx/b language?
Or is it more complicated then that?
Stuff like setting multiple break points by putting break in a sub (genius!), etc,etc [noparse]:)[/noparse]
Ooooh, what if someone made a collection of functions/subs that you could use "load" on.
Or even better a C like "use" command in the sxkey software that only sucks in the functions/subs pre-compile that you use.
Then you get the great code snips, and still have your list file.
Sure glad i never owned a Basic stamp, i sure would be spoiled [noparse]:)[/noparse]
You can collect useful code snippets into a file and use the LOAD directive in SX/B; see the help file for details.
Post Edited (JonnyMac) : 4/2/2007 4:22:55 AM GMT