PropBasic: TX_BIN, TX_DEC, TX_HEX
VonSzarvas
Posts: 3,523
With SX/B, JonnyMac had provided these useful wrappers around TX_BYTE for formatting "numbers" for transmission to a serial terminal or an LCD (etc..). Very useful for debugging.
Is there such code available for PropBasic ?
---
In case I am overlooking something already available and am asking the wrong question, this is what I would like to achieve:
I have a byte array populated by SHIFTIN.
tmp(0) = $12
tmp(1) = $6a
...
tmp(16) = $17
I would like to TX_HEX each byte to a serial terminal, so it reads 12 6a ... 17
In SX/B I would have run a loop 0 to 16, calling TX_HEX tmp(idx). I think I can almost manage this in a big loop using the STR function to generate DEC format, but not HEX - and it also seems a little heavier than a simple TX_HEX might be...
I have tried to adjust the original TX_HEX, but I believe I am tripping over on the fact that LONGS are longer than bytes!
So really each TX_HEX might need to transmit 00000012 0000006a (or even 1ECF0F1E if I had such a big number in my array!)
* I appreciate my last example is bigger than a byte, but others may need to use TX_HEX for longs - heck even me later!...
Max.
Post Edited (Maxwin) : 5/18/2010 4:13:25 PM GMT
Is there such code available for PropBasic ?
---
In case I am overlooking something already available and am asking the wrong question, this is what I would like to achieve:
I have a byte array populated by SHIFTIN.
tmp(0) = $12
tmp(1) = $6a
...
tmp(16) = $17
I would like to TX_HEX each byte to a serial terminal, so it reads 12 6a ... 17
In SX/B I would have run a loop 0 to 16, calling TX_HEX tmp(idx). I think I can almost manage this in a big loop using the STR function to generate DEC format, but not HEX - and it also seems a little heavier than a simple TX_HEX might be...
I have tried to adjust the original TX_HEX, but I believe I am tripping over on the fact that LONGS are longer than bytes!
So really each TX_HEX might need to transmit 00000012 0000006a (or even 1ECF0F1E if I had such a big number in my array!)
* I appreciate my last example is bigger than a byte, but others may need to use TX_HEX for longs - heck even me later!...
Max.
Post Edited (Maxwin) : 5/18/2010 4:13:25 PM GMT
Comments
[noparse][[/noparse]Edit] #1: Added TX_DEC
[noparse][[/noparse]Edit] #2: Improved TX_DEC speed by about 14% -- removed one division (replaced with loop)
[noparse][[/noparse]Edit] #3: See below
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 5/19/2010 5:31:09 PM GMT
I have also updated the title of this post to reflect the TX_BIN routine included in your sample code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
The attached is my final version which LOADs subroutine definitions and associated code·from external files; this makes using formatted TX output easy in any program without copy-and-paste.· Some of you will notice a small bit of inline Assembly in a couple routines;··I did this to circumvent the normal compiler output which was creating problems when I wanted to reuse __paramx variables (I've sent a note to Bean about this with a suggested compiler update).
Okay, I'm done; I hope someone finds this useful.
[noparse][[/noparse]Edit] Fixed bug in TX_DEC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 5/20/2010 3:33:31 PM GMT
The TX_HEX routine is helping me debug my SD-CARD reader/writer in PropBasic - without it I was really struggling to debug and fathom the protocol. Looking forward to sharing the code soon. Gonna be a late night....
Ray
I had read your earlier thread, and so I would just mention I am not working on FATxx; rather direct storage much like a portable big cheap eeprom.
For analysis I have written some c# .NET code to read into Windows the data (direct from the PhysicalDisc), so it's not needed the FAT overhead (in my case). .. Heck - you can also use WinHex or the like for occasional data grabbing anyhow!
Don't sell me as "generous" too quickly -- we're all motivated by something and my "something" will reveal itself in a few months!
The matter did resolve; my mother required surgery for cancer and it all went very well -- she'll be fine. It's tough being in Los Angeles when she's in Anchorage, AK. Thankfully, my sister is there and keeps me up to date.
I don't have a treadmill but I do like to walk and jog; after I posted the update I walked down to the Warner Brothers movie studio (about 2.5 miles) and then jogged back. Now it's time to tackle a big work project!
I, too, am looking forward to seeing your SD card code. I've actually asked Parallax for an "official" SD card object to go along with their video output, audio output, keyboard and mouse input -- the only thing missing is file storage. FSRW (Spin/PASM) works very well, but is not full-featured (no file rename, no sub-directories) and I'd like to have these things.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Good news: I was speaking with Bean yesterday and asked him about integrating the definitions and sub/func code into one file (for LOAD); he was already working on an idea and seems to have made it work so, perhaps in a day or two, libraries like this will be contained in a single file and that will be good for all of us when sharing code. Will be good, too, if some sort of PropBASIC repository is created.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Yeah, basically just combine the two files into one with a '{$CODE} line seperating the header and code sections.
I haven't tried it for TASKs yet, but it should work the same way.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
www.norfolkhelicopterclub.com
Announcement: To cut costs in the current economic climate, we have switched-off the light at the end of the tunnel.