SX Code Formatter for Forum Submissions
![Phil Pilgrim (PhiPi)](https://forums.parallax.com/uploads/userpics/612/nMG83RHE7MV61.gif)
There was a post on the Support forum that regarded posting readable SX assembly code in the forums. This is hard to do, due to the way the forum code handles tabs. So I've put a code formatter on my website that converts SX code into something that can be displayed here. The web address is: www.phipi.com/sxformat.
Here's an example of code that's gone through the formatter:
Enjoy!
-Phil
Update: Added boldfacing for reserved words. 'Looks like I missed a couple, though!
Post Edited (Phil Pilgrim (PhiPi)) : 3/7/2007 6:40:40 AM GMT
Here's an example of code that's gone through the formatter:
[b]DEVICE[/b] SX28L,[b]OSCHS3[/b],[b]BOR26[/b],[b]TURBO[/b],STACKX_OPTIONX [b]RESET[/b] START ;Begin executing at START. ; OPTDAT [b]EQU[/b] %10000110 ;Option register value: ; Reg $01 is RTCC, not WREG. ; Enable RTCC roll-over interrupt. ; RTCC clocked internally. ; RTCC uses prescaler. ; RTCC divide rate = 1:32 ; [b]FREQ[/b] 50_000_000 ; ;**********************MODE REGISTER VALUE NAMES********************** M_CMP [b]EQU[/b] $08 M_WKPND [b]EQU[/b] $09 M_WKED [b]EQU[/b] $0A M_WKEN [b]EQU[/b] $0B M_ST [b]EQU[/b] $0C M_LVL [b]EQU[/b] $0D M_PLP [b]EQU[/b] $0E M_TRIS [b]EQU[/b] $0F ;***********************PROCESS CONSTANTS***************************** RTCON [b]EQU[/b] 186 ;Added to RTCC after interrupt. ; ;****************************MACROS*********************************** BLOCK [b]MACRO[/b] [b]IF[/b] $ & $100 [b]ERROR[/b] 'Block begins in upper half of [b]page[/b].' [b]ENDIF[/b] [b]ENDM[/b] ; ENDB [b]MACRO[/b] [b]IF[/b] ($-1) & $100 [b]ERROR[/b] 'Block ends in upper half of [b]page[/b].' [b]ENDIF[/b] [b]ENDM[/b] ; NOP3 [b]MACRO[/b] [b]JMP[/b] $+1 [b]ENDM[/b] ; [b]NOEXPAND[/b]
Enjoy!
-Phil
Update: Added boldfacing for reserved words. 'Looks like I missed a couple, though!
Post Edited (Phil Pilgrim (PhiPi)) : 3/7/2007 6:40:40 AM GMT
Comments
Very cool. I wonder if this is something that could be integrated into the forum software. I tried formatting my assembly language template file here:
Looks good except for the conversion of tabs. I set the tabs to "2" before pasting my code, but it looks weird here. I'm not sure if that is an issue with your code, or the way the forum software handles spaces when using FireFox.
Thanks,
PeterM
Is that the same formatter that you put together for the Propeller code? ... If so, I seem to remember "early on" that you had a stand-alone version. Is that available as well?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
It's a modified version: different keywords and comment character, added tab expander. The Propeller version may have started standalone for testing onsite, before it was converted to CGI. This one was adapted from the Propeller CGI, so has never existed standalone.
PeterM,
You have to set the "tabs" value to match whatever you use in the SXKey IDE. Otherwise your code will look different when posted. Also, results will vary if your browser doesn't show a monospaced font for code blocks. I use Opera which, under OS/X and Linux doesn't display the correct font, making code blocks look weird. Opera under WinXP works fine, though.
-Phil
I did set the tabs correctly. In my post, I said, "I set the tabs to "2" before pasting my code." I am referring to setting the tabs to "2" in your web applet before pasting, and a tab setting of "2" is what I use in the IDE.
It doesn't look like FireFox uses a monospaced tab for displaying code blocks, but it's not like I have an option to change that. I do know that your code sample lines up perfectly, while mine lines up weird. Still, handy gizmo you wrote.
Thanks,
PeterM
It's not just your browser. Part of the problem comes from the dotNetBB style sheet at forums.parallax.com//forums/styles/dotNetBB/css/style.css. Here's what it uses for code blocks:
Lucinda Console is the only monospaced font listed. All the others are proportionally-spaced. If you don't have Lucinda Console installed in your system, or if your browser won't use it, you'll get a proportionally-spaced font instead.
It would be a simple matter to fix it, I think. Just changing the font-family line to the following would do the job:
With this, your browser has a choice of several monospaced fonts and will use the first available font listed. If none of those exist in the system, it will default to any other "Monospace" font (the last choice), instead of a proportionally-spaced "Sans-Serif" font. This would also allow Spin programs for the Propeller to display in all their glory.
Perhaps the IT Guy could weigh in on this possibility...
-Phil
At least you provided me with a workaround. I didn't have Lucinda Console installed, but I did have the font on my computer. I installed it and now the formatted code lines up beautifully. I'll post a message to the Forum guy and see if he can do something regarding your suggestion.
Thanks,
PeterM
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture
San Diego Miramar College
There is also a code colorizer at sxlist.com...
http://www.sxlist.com/cgi-bin/colorer.exe ·but it produces actual HTML/CSS rather than BBCode.
Phil, if you like, I could see about hosting your version as well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
That'd be great, since I have a bandwidth-limited account (which, so far, hasn't been an issue). It's a Perl CGI app, though, and requires both the CGI and CGI::Carp modules. Would that fly on your site?
Thanks,
Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!