Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => Topic started by: Deep Toaster on June 24, 2011, 06:35:20 pm

Title: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on June 24, 2011, 06:35:20 pm
BBify (http://clrhome.org/resources/bbify/)

A little web project I've been working on.

I know it looks horrible, but I'll prettify it up soon. At least it's functional: paste in some Z80 code and click Submit, and it'll wrap stuff in BBCode so you can copy-paste the result straight into a forum. Or HTML, so you can paste it into a webpage, or plain old colored code, so you can paste it into an email!

Right now it can only handle strings, numbers, comments, and directives, but the way I've set it up all I have to do is add a regex array element for any replacements I want to do and it'll put that on the queue.

Better yet, I'm planning to add customized colors. Right now I'm taking colors off the Tango scheme (http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines#Color_Palette), but the way I have it set up I can just add some form elements and you'll be able to change the colors to whatever you want :D

Latest update: http://ourl.ca/9167/289088/
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: DJ Omnimaga on June 24, 2011, 06:36:35 pm
This is nice O.O. I wonder if eventually it could be integrated in the forum or something? I think there's a SMF hack ephans/Scout posted that does that with PHP/C++, but someone could modify it to do it with Z80 instead.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on June 24, 2011, 06:37:47 pm
Yeah, I wasn't aware of that one when I started making this :-\
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Munchor on June 24, 2011, 06:38:22 pm
Deep Thought, very nice :D I'd like this on the forums like DJ :)

Test:
; Program Name: Memory Checker
; Author: David Gomes
; Version: <<1>>.<1>
; Written for Doors CS <<1>>.<1> and higher
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org progstart
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
 
  set textWrite,(IY + sGrFlags)
  set fracDrawLFont,(IY + fontFlags)
 
  ld a,1
  ld (penCol), a
  ld (penRow), a
  ld hl,Title
  B_CALL (_VPutS)
 
  ld a,17
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld hl,RAMText
  B_CALL (_VPutS)
 
  ld a,41
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld hl,ARCText
  B_CALL (_VPutS)
 
  ld h,0
  ld l,9
  ld d,95
  ld e,9
  ld a,1
  call fastline
 
  res fracDrawLFont,(IY + fontFlags)
 
  ld a,10
  ld (penRow),a
  ld a,20
  ld (penCol),a
  B_CALL (_memchk)
  call VDispHL
 
  ld a,17
  ld (penRow),a
  ld a,20
  ld (penCol),a
  ld hl,OutOf
  B_CALL (_VPutS)
 
  ld a,24
  ld (penRow),a
  ld a,20
  ld (penCol),a
  ld hl,24756
  call VDispHL
 
  call GetFreeArc
  ld a,35
  ld (penRow),a
  ld a,20
  ld (penCol),a
  B_CALL (_VPutS)
 
  ld a,41
  ld (penRow),a
  ld a,20
  ld (penCol),a
  ld hl,OutOf
  B_CALL (_VPutS)
 
  call GetTotalArc
  ld a,47
  ld (penRow),a
  ld a,20
  ld (penCol),a
  B_CALL (_VPutS)
 
  call iFastCopy
  B_CALL (_GetKey)
 
  res textWrite,(IY + sGrFlags)
 
  ret

RAMText:
  .db <0>,0

ARCText:
  .db <0>,0

Title:
  .db <0>,0

OutOf:
  .db <0>,0

;The following code was made by Runer112
GetTotalArc:
;——————————————————————————————————————————————;
;—> Returns the total amount of user archive as a <0>-character decimal string
;INPUTS:    none
;OUTPUTS:   hl=pointer to string (OP3)
;DESTROYS:  af  bc  de  ix
;——————————————————————————————————————————————;
  B_CALL($80BA)
  add   a,a
  add   a,a
  ld   d,0
  ld   e,a
  ld   hl,GetTotalArc_HWValues
  add   hl,de
  jr   ConvArc
GetTotalArc_HWValues:
  .db   (10*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4>
  .db   (94*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4>
  .db   (30*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4>
  .db   (94*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4>

GetFreeArc:
;——————————————————————————————————————————————;
;—> Returns the amount of free archive as a <0>-character decimal string
;INPUTS:    none
;OUTPUTS:   hl=pointer to string (OP3)
;DESTROYS:  af  bc  de  ix
;——————————————————————————————————————————————;
  B_CALL($5014)      ;ArcChk
  ex   de,hl
  inc   hl


ConvArc:
;——————————————————————————————————————————————;
;—> Converts a <0>-bit integer into a <1>-character decimal string
;INPUTS:    hl=pointer to <0>-bit integer (big-endian)
;OUTPUTS:   hl=pointer to string (OP3)
;DESTROYS:  af  bc  de  ix
;——————————————————————————————————————————————;
  rst   20h
  ld   hl,OP3+7
  ld   de,10
  ld   (hl),d
  ld   b,7
ConvArc_Loop1:
  push   bc
  push   hl
  B_CALL($80B1)      ;Div32By16
  pop   hl
  pop   bc
  ld   a,(OP2+3)
  add   a,'0'
  dec   hl
  ld   (hl),a
  djnz   ConvArc_Loop1
  ld   d,h
  ld   e,l
  ld   bc,6<;<<1>+<2>
ConvArc_Loop2:
  ld   a,(de)
  cp   c
  ret   nz
  ld   a,' '
  ld   (de),a
  inc   de
  djnz   ConvArc_Loop2
  ret

Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: DJ Omnimaga on June 24, 2011, 06:39:22 pm
Yeah, I wasn't aware of that one when I started making this :-\
Nah it's fine. Plus yours is independent from forums, so your tool can still be used on forums that lacks this.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Juju on June 24, 2011, 06:39:56 pm
Nice :)

Could be nice if it gets integrated in the forum indeed.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on June 24, 2011, 06:43:47 pm
GetTotalArc_HWValues:
  .db   (10*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4>
  .db   (94*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4>
  .db   (30*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4>
  .db   (94*$4000)>;><3>&<4>,(<0><1><2>)>><<13>>&<4>,(<0><1><2>)>><13>&<4>,(<0><1><2>)&<4>


Eek, bugs! Mind posting your original code for me?
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Munchor on June 24, 2011, 06:44:21 pm
http://pastebin.com/AsNg0fBx (http://pastebin.com/AsNg0fBx)
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on June 24, 2011, 06:45:09 pm
Thanks, I'll work on fixing it soon :)
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Eeems on June 24, 2011, 07:52:07 pm
BootExe:
; File Header
   dw BootExeEnd-BootExe   ; Size of File
; Executable Header
   db 0         ; Size of Stack needed
BootExeStart:
; End Headers Start Data
   ldrDE(_-BootExeStart)
   call LoadFileToRAM
   if(SUCCESS)
      jp nz, KernelPanic
   ex de,hl
   rDrawWrappedString
   rFastCopy
   call FlushKeys
   call WaitKey
   rEndThread
_   db <0>,0
BootExeEnd:

Hrm, it seems to not parse db "string",0 statements correctly
everything else is great though, maybe add in some highlighting for commands too?
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on June 24, 2011, 08:04:34 pm
Hrm, it seems to not parse db "string",0 statements correctly

Yeah, there are a few issues with numbers.

everything else is great though, maybe add in some highlighting for commands too?

Definitely, and also registers, bcalls, and everything else I highlight in my gedit scheme file.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Eeems on June 24, 2011, 08:12:56 pm
Hrm, it seems to not parse db "string",0 statements correctly

Yeah, there are a few issues with numbers.

everything else is great though, maybe add in some highlighting for commands too?

Definitely, and also registers, bcalls, and everything else I highlight in my gedit scheme file.
Maybe add in support for KOS and RogueOS calls too? ( when they are finalized of course )
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on June 24, 2011, 08:33:13 pm
Hrm, it seems to not parse db "string",0 statements correctly

Yeah, there are a few issues with numbers.

everything else is great though, maybe add in some highlighting for commands too?

Definitely, and also registers, bcalls, and everything else I highlight in my gedit scheme file.
Maybe add in support for KOS and RogueOS calls too? ( when they are finalized of course )

Sure. No need to give me the actual call lists because it's all just regex -- it highlights the instruction bcall/kcall/rcall one way, then assumes whatever's in the parentheses following or the next word is the routine.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on July 03, 2011, 08:56:39 pm
Update-bump: instructions, registers, operators, all that fun stuff. I also fixed those annoying bugs.

Spoiler For ephan's code posted earlier:
; Program Name: Memory Checker
; Author: David Gomes
; Version: 1.0
; Written for Doors CS 7.0 and higher
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
        .org progstart
        .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
 
  set textWrite,(IY + sGrFlags)
  set fracDrawLFont,(IY + fontFlags)
 
  ld a,1
  ld (penCol), a
  ld (penRow), a
  ld hl,Title
  B_CALL (_VPutS)
 
  ld a,17
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld hl,RAMText
  B_CALL (_VPutS)
 
  ld a,41
  ld (penRow),a
  ld a,1
  ld (penCol),a
  ld hl,ARCText
  B_CALL (_VPutS)
 
  ld h,0
  ld l,9
  ld d,95
  ld e,9
  ld a,1
  call fastline
 
  res fracDrawLFont,(IY + fontFlags)
 
  ld a,10
  ld (penRow),a
  ld a,20
  ld (penCol),a
  B_CALL (_memchk)
  call VDispHL
 
  ld a,17
  ld (penRow),a
  ld a,20
  ld (penCol),a
  ld hl,OutOf
  B_CALL (_VPutS)
 
  ld a,24
  ld (penRow),a
  ld a,20
  ld (penCol),a
  ld hl,24756
  call VDispHL
 
  call GetFreeArc
  ld a,35
  ld (penRow),a
  ld a,20
  ld (penCol),a
  B_CALL (_VPutS)
 
  ld a,41
  ld (penRow),a
  ld a,20
  ld (penCol),a
  ld hl,OutOf
  B_CALL (_VPutS)
 
  call GetTotalArc
  ld a,47
  ld (penRow),a
  ld a,20
  ld (penCol),a
  B_CALL (_VPutS)
 
  call iFastCopy
  B_CALL (_GetKey)
 
  res textWrite,(IY + sGrFlags)
 
  ret
 
RAMText:
  .db "RAM",0
 
ARCText:
  .db "ARC",0
 
Title:
  .db "Memory Checker",0
 
OutOf:
  .db "out of",0
 
;The following code was made by Runer112
GetTotalArc:
;——————————————————————————————————————————————;
;—> Returns the total amount of user archive as a 7-character decimal string
;INPUTS:    none
;OUTPUTS:   hl=pointer to string (OP3)
;DESTROYS:  af  bc  de  ix
;——————————————————————————————————————————————;
  B_CALL($80BA)
  add   a,a
  add   a,a
  ld    d,0
  ld    e,a
  ld    hl,GetTotalArc_HWValues
  add   hl,de
  jr    ConvArc
GetTotalArc_HWValues:
  .db   (10*$4000)>>24&$FF,(10*$4000)>>16&$FF,(10*$4000)>>8&$FF,(10*$4000)&$FF
  .db   (94*$4000)>>24&$FF,(94*$4000)>>16&$FF,(94*$4000)>>8&$FF,(94*$4000)&$FF
  .db   (30*$4000)>>24&$FF,(30*$4000)>>16&$FF,(30*$4000)>>8&$FF,(30*$4000)&$FF
  .db   (94*$4000)>>24&$FF,(94*$4000)>>16&$FF,(94*$4000)>>8&$FF,(94*$4000)&$FF
 
GetFreeArc:
;——————————————————————————————————————————————;
;—> Returns the amount of free archive as a 7-character decimal string
;INPUTS:    none
;OUTPUTS:   hl=pointer to string (OP3)
;DESTROYS:  af  bc  de  ix
;——————————————————————————————————————————————;
  B_CALL($5014)         ;ArcChk
  ex    de,hl
  inc   hl
 
 
ConvArc:
;——————————————————————————————————————————————;
;—> Converts a 32-bit integer into a 7-character decimal string
;INPUTS:    hl=pointer to 32-bit integer (big-endian)
;OUTPUTS:   hl=pointer to string (OP3)
;DESTROYS:  af  bc  de  ix
;——————————————————————————————————————————————;
  rst   20h
  ld    hl,OP3+7
  ld    de,10
  ld    (hl),d
  ld    b,7
ConvArc_Loop1:
  push  bc
  push  hl
  B_CALL($80B1)         ;Div32By16
  pop   hl
  pop   bc
  ld    a,(OP2+3)
  add   a,'0'
  dec   hl
  ld    (hl),a
  djnz  ConvArc_Loop1
  ld    d,h
  ld    e,l
  ld    bc,6<<8+'0'
ConvArc_Loop2:
  ld    a,(de)
  cp    c
  ret   nz
  ld    a,' '
  ld    (de),a
  inc   de
  djnz  ConvArc_Loop2
  ret
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on July 04, 2011, 01:26:30 pm
Another (huge) update-bump:EDIT: And now I got banned from my own website x.x
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: DJ Omnimaga on July 04, 2011, 06:00:43 pm
O.O
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on July 04, 2011, 06:01:58 pm
Yep, special feature at http://clrhome.org/resources/bbify/?action=ie <_<

EDIT: Man, your screen is huge!
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: thepenguin77 on July 04, 2011, 09:07:23 pm
O.O

I was just going to come here and do that.  :D
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on July 04, 2011, 09:14:57 pm
I should make Bieber dance >.> <.<
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on July 19, 2011, 07:28:28 pm
Idea: What about one for Axe? I'm starting to work on it (it doesn't work yet).
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Munchor on July 24, 2011, 05:06:07 pm
Idea: What about one for Axe? I'm starting to work on it here (http://clrhome.co.cc/resources/gild/) (it doesn't work yet).

Can you make it in a way it uses XML files or something like that, so it's easy to make it for all languages?

Either way, yeah I want an Axe version too :)
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: ben_g on July 28, 2011, 06:29:24 pm
A little web project I've been working on: BBify (http://clrhome.org/resources/bbify/)
Could you please post it again? I only get a 403: Forbidden error.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: DJ Omnimaga on July 28, 2011, 06:35:24 pm
Aw it's down. I wonder if Juju could maybe host it? It would probably be more stable.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on July 28, 2011, 11:19:02 pm
A little web project I've been working on: BBify (http://clrhome.org/resources/bbify/)
Could you please post it again? I only get a 403: Forbidden error.
Yeah, I managed to get my webhosting account suspended.
Aw it's down. I wonder if Juju could maybe host it? It would probably be more stable.
I'm moving the entire site to his server right now, in fact. You can now access BBify at http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/) (notice I'm taking the opportunity to change my domain name too).
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 04, 2011, 03:55:15 pm
WHOO HOO BUMP

Same URL as before: http://clrhome.org/resources/bbify/

New features that don't matter at all:New features that matter if you use the worst browser in existence:New features that actually do make a difference:
EDIT: Another update! Pastes from http://paste.bwns.be/ also work :D
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Munchor on August 04, 2011, 04:28:57 pm
Looking awesome Deep Thought, I dislike the W3C Compliant button, it just looks bad :P
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 04, 2011, 04:34:42 pm
Looking awesome Deep Thought, I dislike the W3C Compliant button, it just looks bad :P
(http://img.removedfromgame.com/imgs/0-test.png)

^ That better? :P

Seriously, though, I have no idea where else to put it. And I want to put it somewhere ;D
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Jim Bauwens on August 04, 2011, 04:34:45 pm
EDIT: Another update! Pastes from http://paste.bwns.be/ also work :D

w00t, its actually being used \o/
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Munchor on August 04, 2011, 04:35:53 pm
Quote
Seriously, though, I have no idea where else to put it. And I want to put it somewhere

My problem is using it, having validated pages is cool, but showing it off is not so cool in my opinion. The only important website using it was python.org, but they removed it recently.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 04, 2011, 05:09:28 pm
Quote
Seriously, though, I have no idea where else to put it. And I want to put it somewhere
My problem is using it, having validated pages is cool, but showing it off is not so cool in my opinion. The only important website using it was python.org, but they removed it recently.
I was actually planning to have (http://clrhome.org/images/compliant.png) there as well, but yeah, that's a good point.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 04, 2011, 06:27:19 pm
AWESOME UPDATE:

Idea: What about one for Axe? I'm starting to work on it (it doesn't work yet).
Can you make it in a way it uses XML files or something like that, so it's easy to make it for all languages?

Guess what? Done!

I don't have time to post the specs right now, but here's the z80.xml (default) set. See if you can understand it, and I'll post more info tomorrow.

Enjoy!

EDIT: Hint: it uses my regex parser that uses <#> for backreferences.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: DJ Omnimaga on August 04, 2011, 06:46:40 pm
Nice update Deep Thought :)
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: ben_g on August 04, 2011, 07:29:46 pm
It's a great tool. I already used it a few times when i posted asm source code.

BTW: those terms and conditions, I don't really know how you can agree with them :p
And nobody has said anything abouth this. I think nobody here checks them.
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 05, 2011, 01:34:57 pm
It's a great tool. I already used it a few times when i posted asm source code.
w00t, its actually being used \o/ (http://omniurl.tk/9167/178903/)

Don't forget to post any bugs you come across! :)

EDIT: Update: made it a dozen times faster and accepting multi-line comments!
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Jim Bauwens on August 05, 2011, 03:49:24 pm
Nice Deep :)
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 05, 2011, 04:52:44 pm
If anyone's interested, some info on the XML:
Quote from: http://www.revsoft.org/phpBB3/viewtopic.php?f=5&t=1242
The XML file should be wrapped in a single <scheme> tag, containing one or more <rule> elements that defines a replacement rule. Each <rule> is parsed one by one, so order is important.

Each <rule> tag has one <f> element and one <r> element, both containing one CDATA section with a preg regex inside. <f> defines the pattern to search for, and should be wrapped in the appropriate delimiters (http://www.php.net/manual/en/regexp.reference.delimiters.php). (Remember that all &, <, and > chars are HTML-escaped.) <r> contains the replacement text, using <#> for backreferences (no escaping since it's in a CDATA).

Here's an example (the default z80.xml):
Code: [Select]
<?xml version='1.0' encoding='UTF-8'?>
<scheme name="Z80 Assembly">
<rule>
<f><![CDATA[#\['"]#]]></f>
<r><![CDATA[<0>]]></r>
</rule>
<rule>
<f><![CDATA[#['"].*?['"]#i]]></f>
<r><![CDATA[[color=$num]<0>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#&[lg]t;|[+\-*/%~=!&|^]#]]></f>
<r><![CDATA[[b]<0>[/b]]]></r>
</rule>
<rule>
<f><![CDATA[#;.*#]]></f>
<r><![CDATA[[i][color=$com]<0>[/color][/i]]]></r>
</rule>
<rule>
<f><![CDATA[#\$[\dA-F]+\b|\b[\dA-F]+h\b|%[01]+\b|\b[01]+b\b|(?<!\<)\b\d+\b(?!\>)|\$|\*#i]]></f>
<r><![CDATA[[color=$num]<0>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#\.\w+|\bEND\b|^\s*\#(define|defcont|if(n?def)?|else|endif|include)\b#i]]></f>
<r><![CDATA[[color=$pre]<0>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#^\s+(exx?|ld([di]r?)?|pop|push|ad[cd]|cp([di]r?|l)?|daa|dec|inc|neg|sbc|sub|and|bit|[cs]cf|x?or|res|set|r[lr](a|ca?|)?|sla|sr[al]|call|djnz|j[pr]|nop|ret[in]?|rst|[de]i|halt|im|in([di]r?)?|ot[di]r|out[di]?|b_?(call|jump))\b#i]]></f>
<r><![CDATA[[b][color=$ins]<0>[/color][/b]]]></r>
</rule>
<rule>
<f><![CDATA[#\b([hl][xy]|i[xy][hl]|slia|sll)\b#i]]></f>
<r><![CDATA[[b][s][color=$err]<0>[/color][/s][/b]]]></r>
</rule>
<rule>
<f><![CDATA[#\b(a(f'?)?|b(c'?)?|d(e'?)?|h(l'?)?|[celr]|i[xy]?)\b#i]]></f>
<r><![CDATA[[b][color=$reg]<0>[/color][/b]]]></r>
</rule>
</scheme>
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Spyro543 on August 05, 2011, 06:31:34 pm
Here's what I learned of assembly by looking at other's code (really this is all I know how to do in assembly):

; I'm using what I learned by looking at other's codes.
; I know how to make comments in z80 now!
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: ralphdspam on August 05, 2011, 06:50:34 pm
Here's what I learned of assembly by looking at other's code (really this is all I know how to do in assembly):

; I'm using what I learned by looking at other's codes.
; I know how to make comments in z80 now!

Next lesson: Nop = do nothing.  :)
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 05, 2011, 11:07:24 pm
Here's what I learned of assembly by looking at other's code (really this is all I know how to do in assembly):

; I'm using what I learned by looking at other's codes.
; I know how to make comments in z80 now!
Why is that ! bolded ???
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Eeems on August 08, 2011, 05:19:35 am
Next lesson: Nop = do nothing.  :)
Actually Nop just uses up a few cycles, so it actually does something, that something is just sitting and waiting though :P
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 10, 2011, 04:12:07 pm
whoo hoo fixed a few bugs with HTML encoding and jim's pastebin and added permalinking (http://clrhome.org/resources/bbify/?t=.nolist%0D%0A%23include++++%22ti83plus.inc%22%0D%0A%23define+++++ProgStart++++%249D95%0D%0A.list%0D%0A.org++++++++ProgStart%2C2%0D%0A.db+++++++++%24BB%2C%246D%0D%0A++++B_CALL++%28_ClrLCDFull%29%0D%0A++++LD++++++HL%2C0%0D%0A++++LD++++++%28PenCol%29%2CHL%0D%0A++++LD++++++HL%2CMessage%0D%0A++++B_CALL++%28_PutS%29+++++%3B+Displays+the+string%0D%0A++++B_CALL++%28_NewLine%29%0D%0A++++RET%0D%0AMessage%3A%0D%0A.db+++++++++%22Hello+world%21%22%2C0%0D%0A.end%0D%0AEND&l=z80#done)
EDIT: What the heck. Made it work with any page with a textarea on it!
Title: Re: BBify: a BBCode syntax highlighter for Z80 ASM
Post by: Deep Toaster on August 23, 2011, 06:24:56 pm
Update (as always, located at http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/)


EDIT: Whoops, forgot to turn off ?ie in the normal BBify...
Title: Re: BBify your Axe and Z80 code!
Post by: Deep Toaster on August 29, 2011, 01:52:44 pm
Sorry for the triple-post, but the BBify'r now works for Axe! :w00t:

Finished making the rules sheet for Axe syntax. Turns out it's even more complicated than ASM:
Spoiler For Code:
<?xml version='1.0' encoding='UTF-8'?>
<scheme name="Axe">
<rule>
<f><![CDATA[# |'"'#]]></f>
<r><![CDATA[<0>]]></r>
</rule>
<rule>
<f><![CDATA[#\^\^T(\w+?\(?|.)#]]></f>
<r><![CDATA[[sup]T[/sup]<1>]]></r>
</rule>
<rule>
<f><![CDATA[#".*?"?#]]></f>
<r><![CDATA[[color=$num]<0>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#^\.\.\..*?^\.\.\.|\..*?$#s]]></f>
<r><![CDATA[[i][color=$com]<0>[/color][/i]]]></r>
</rule>
<rule>
<f><![CDATA[#Asm\([\dABCDEF]{2}+\)?|(\#Axiom\(|prgm)([ABCDEFGHIJKLMNOPQRSTUBWXYZ]|theta)([\dABCDEFGHIJKLMNOPQRSTUBWXYZ]|theta){0,7}\)?|\#Icon\([\dABCDEF]{64}\)?|\#Realloc\(.*?\)?#]]></f>
<r><![CDATA[[color=$pre]<0>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#\[i\]#]]></f>
<r><![CDATA[[b][i][color=$ins]i[/color][/i][/b]]]></r>
</rule>
<rule>
<f><![CDATA[#\[[\dABCDEF]*?\]?|Data\(.*?\)?#]]></f>
<r><![CDATA[[color=$num]<0>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#If|Else|While|Repeat|For\b|DS&lt;\b|End|Return#]]></f>
<r><![CDATA[[b][color=$reg]<0>[/color][/b]]]></r>
</rule>
<rule>
<f><![CDATA[#(Lbl|Goto)(<\d+>[ABCDEFGHIJKLMNOPQRSTUBWXYZ]+)#]]></f>
<r><![CDATA[[b][color=$reg]<1>[/color][/b][color=black]<2>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#sub\(([ABCDEFGHIJKLMNOPQRSTUBWXYZ]+)(\)?)#]]></f>
<r><![CDATA[[b][color=$reg]sub[/color][/b][color=black][b]([/b]<1>[b])[/b][/color]]]></r>
</rule>
<rule>
<f><![CDATA[#(Pause|Disp|Store(GDB|Pic)|RecallPic|DrawInv|Horizontal|Vertical|<\d+>(and|x?or)|Text|Fix|(Un)?Archive|DelVar|FnO(n|ff)\b|LnReg|Port)<\d+>|Diagnostic(On|Off)|Full|Normal|getKey|Clr(Home|Draw)|DispGraph|Shade\b|rand|abs\b|sin\b|cos\b|e\^\b|ln\b|min\b|max\b|not\b|P(t|xl)-(On|Off|Change)\b|pxl-Test\b|Line\b|RectI?\b|Circle\b|Pt-Mask\b|Bitmap\b|rotCC?\b|flip[VH]\b|Output\b|Text\b|sign\b|nib\b|Fill\b|Copy\b|Exch\b|length\b|inData\b|Equ>String\b|SortD\b|Ans|GetCalc\b|input|float\b|FnInt\b|Stop|Port|Freq\b|Send\b|Get#]]></f>
<r><![CDATA[[color=$ins]<0>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#sqrt\(#]]></f>
<r><![CDATA[[color=$ins]&radic;[/color][b][color=black]([/color][/b]]]></r>
</rule>
<rule>
<f><![CDATA[#\[i\]#]]></f>
<r><![CDATA[[b][color=$ins]i[/color][/b]]]></r>
</rule>
<rule>
<f><![CDATA[#\|E([\dABCDEF]{1,4})#]]></f>
<r><![CDATA[[color=black][sub]E[/sub]<1>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#\^\^o([ABCDEFGHIJKLMNOPQRSTUBWXYZ]|theta|r[1-6])#]]></f>
<r><![CDATA[[color=black][b]&deg;[/b]<1>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#'.'|(GDB|Pic|Str)\d|L[1-6]|(?<!\<)\d+(?!\>)|b[01]{1,16}#]]></f>
<r><![CDATA[[color=black]<0>[/color]]]></r>
</rule>
<rule>
<f><![CDATA[#-&gt;#]]></f>
<r><![CDATA[[b][color=black]&rarr;[/color][/b]]]></r>
</rule>
<rule>
<f><![CDATA[#\^\^([2r]|-1)#]]></f>
<r><![CDATA[[b][color=black][sup]<1>[/sup][/color][/b]]]></r>
</rule>
<rule>
<f><![CDATA[#\[e\]#]]></f>
<r><![CDATA[[b][color=black]e[/color][/b]]]></r>
</rule>
<rule>
<f><![CDATA[#&[lg]t;|[+\-*/~=!\^(),:]#]]></f>
<r><![CDATA[[b][color=black]<0>[/color][/b]]]></r>
</rule>
<rule>
<f><![CDATA[#\A.*\Z#s]]></f>
<r><![CDATA[[color=$con]<0>[/color]]]></r>
</rule>
</scheme>
For Axe, it does more than just highlight certain strings of text, like with the Z80 rules. It actually recognizes every command you're allowed to use in Axe, so it's a great way to check your syntax. It's lenient on closing parentheses and braces (since Axe Parser does that too).

Axe code should be in TokenIDE format. (I may create a new rule sheet for SourceCoder later on.) The easiest way to grab valid code to put into BBify'r:Remember to choose Axe (Tokens) as your engine. And don't worry about those weird ^^r things -- the BBify'r will automagically do replacements for you, such as ^^r to r and -> to →!

Here she is parsing the AXEGOL example program:
Quote from: Axe
.\G\A\M\E\O\F\L\
Full
DiagnosticOff
ClrDraw
For(A,33,62
For(B,17,43
If rand^2
sub(AB
End:End:End
While getKey!=15:DispGraph
For(A,33,62
For(B,17,43
pxl-Test(A-1,B-1)+pxl-Test(A-1,B)+pxl-Test(A-1,B+1)+pxl-Test(A,B-1)+pxl-Test(A,B+1)+pxl-Test(A+1,B-1)+pxl-Test(A+1,B)+pxl-Test(A+1,B+1)S
If S=3oror (S=2 and pxl-Test(A,B
Pxl-On(A-32,B
Pxl-On(A-32,B
End
End:End
For(A,33,62
For(B,17,43
Pxl-Off(A,B
If pxl-Test(A-32,B
sub(AB
Pxl-Off(A-32,B
End
End:End
End
Return

Lbl AB
Pxl-On(A,B
Return

Generated by the BBify'r (http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/))
http://clrhome.org/resources/bbify/?t=.GAMEOFL%0AFull%0ADiagnosticOff%0AClrDraw%0AFor(A%2C33%2C62%0AFor(B%2C17%2C43%0AIf%20rand^2%0Asub(AB%0AEnd%3AEnd%3AEnd%0AWhile%20getKey!%3D15%3ADispGraph%0AFor(A%2C33%2C62%0AFor(B%2C17%2C43%0Apxl-Test(A-1%2CB-1)%2Bpxl-Test(A-1%2CB)%2Bpxl-Test(A-1%2CB%2B1)%2Bpxl-Test(A%2CB-1)%2Bpxl-Test(A%2CB%2B1)%2Bpxl-Test(A%2B1%2CB-1)%2Bpxl-Test(A%2B1%2CB)%2Bpxl-Test(A%2B1%2CB%2B1)-%3ES%0AIf%20S%3D3%20or%20(S%3D2%20and%20pxl-Test(A%2CB%0APxl-On(A-32%2CB%0APxl-On(A-32%2CB%0AEnd%0AEnd%3AEnd%0AFor(A%2C33%2C62%0AFor(B%2C17%2C43%0APxl-Off(A%2CB%0AIf%20pxl-Test(A-32%2CB%0Asub(AB%0APxl-Off(A-32%2CB%0AEnd%0AEnd%3AEnd%0AEnd%0AReturn%0A%0ALbl%20AB%0APxl-On(A%2CB%0AReturn&l=axe (http://clrhome.org/resources/bbify/?t=.GAMEOFL%0AFull%0ADiagnosticOff%0AClrDraw%0AFor(A%2C33%2C62%0AFor(B%2C17%2C43%0AIf%20rand^2%0Asub(AB%0AEnd%3AEnd%3AEnd%0AWhile%20getKey!%3D15%3ADispGraph%0AFor(A%2C33%2C62%0AFor(B%2C17%2C43%0Apxl-Test(A-1%2CB-1)%2Bpxl-Test(A-1%2CB)%2Bpxl-Test(A-1%2CB%2B1)%2Bpxl-Test(A%2CB-1)%2Bpxl-Test(A%2CB%2B1)%2Bpxl-Test(A%2B1%2CB-1)%2Bpxl-Test(A%2B1%2CB)%2Bpxl-Test(A%2B1%2CB%2B1)-%3ES%0AIf%20S%3D3%20or%20(S%3D2%20and%20pxl-Test(A%2CB%0APxl-On(A-32%2CB%0APxl-On(A-32%2CB%0AEnd%0AEnd%3AEnd%0AFor(A%2C33%2C62%0AFor(B%2C17%2C43%0APxl-Off(A%2CB%0AIf%20pxl-Test(A-32%2CB%0Asub(AB%0APxl-Off(A-32%2CB%0AEnd%0AEnd%3AEnd%0AEnd%0AReturn%0A%0ALbl%20AB%0APxl-On(A%2CB%0AReturn&l=axe)

EDIT: By the way, I've noticed hardly anyone uses the [pre] tag. It's an awesome tag, something like [tt] and [code] combined.
Title: Re: BBify your Axe and Z80 code!
Post by: ralphdspam on August 29, 2011, 02:03:50 pm
Wow!  That looks great!  :D
Bieber would be so proud.  :P
Title: Re: BBify your Axe and Z80 code!
Post by: Deep Toaster on August 29, 2011, 07:06:19 pm
Wow!  That looks great!  :D
Thanks! And this is a bit of a late tip, but in case you haven't figured it out yet, put [pre] tags inside the [quote] to make it nice and monospaced. The reason I don't include it automatically is because only SMF supports it.
Title: Re: BBify your Axe and Z80 code!
Post by: Deep Toaster on September 04, 2011, 09:15:23 pm
Big update!

You can now upload .8xp files as Axe source. Valid programs will be automatically detokenized into TokenIDE-style text! That also makes the BBify'r an online detokenizer :D
Title: Re: BBify your Axe and Z80 code!
Post by: DJ Omnimaga on September 04, 2011, 09:58:52 pm
Awesome Deep Thought.
Title: Re: BBify your Axe and Z80 code!
Post by: Deep Toaster on September 24, 2011, 12:17:07 pm
Updates:
Spoiler For Example:
Quote from: Lua
-- Balance chemical equation
-- John Powers  2010-06-03





--------------------------------------------------------------------- View

View = class()

function View:init(window)
    self.window         = window
    self.widgetList     = {}
    self.focusList      = {}
    self.currentFocus   = 1

    -- Previous location of mouse pointer
    self.prev_mousex    = 0
    self.prev_mousey    = 0
end


function View:invalidate()
    self.window:invalidate()
end


function View:add(o)
    table.insert(self.widgetList, o)
    if o.acceptsFocus then
        table.insert(self.focusList, o)
    end
    return o
end


function View:sendStringToFocus(str)
    self.focusList[self.currentFocus]:addString(str)
    self.window:invalidate()
end


function View:sendBackspaceToFocus()
    self.focusList[self.currentFocus]:delChar()
    self.window:invalidate()
end


function View:tabForward()
    local nextFocus = self.currentFocus + 1
    if nextFocus > #self.focusList then
        nextFocus = 1
    end
    self.currentFocus = nextFocus
    self.window:invalidate()
end


function View:tabBackward()
    local nextFocus = self.currentFocus - 1
    if nextFocus < 1 then
        nextFocus = #self.focusList
    end
    self.currentFocus = nextFocus
    self.window:invalidate()
end


function View:onMouseDown(x, y)
    -- Find a widget that has a mouse down handler and bounds the click point
    for _, o in ipairs(self.widgetList) do
        local md = o.onMouseDown
        if md and o:contains(x, y) then
            self.mouseCaptured = o
            md(o, window, x - o.x, y - o.y)
            break
        end
    end
end


function View:onMouseMove(x, y)
    local prev_mousex = self.prev_mousex
    local prev_mousey = self.prev_mousey
    for _, o in ipairs(self.widgetList) do
        local xyin = o:contains(x, y)
        local prev_xyin = o:contains(prev_mousex, prev_mousey)
        if xyin and not prev_xyin then
            -- Mouse entered widget
            o:onMouseEnter(x, y)
        elseif prev_xyin and not xyin then
            -- Mouse left widget
            o:onMouseLeave(x, y)
        end
    end
    self.prev_mousex = x
    self.prev_mousey = y
end


function View:onMouseUp(x, y)
    local mc = self.mouseCaptured
    if mc then
        self.mouseCaptured = nil
        if mc:contains(x, y) then
            mc:onMouseUp(x - mc.x, y - mc.y)
        else
            mc:cancelClick()
        end
    end
end


function View:enterHandler()
    -- Does the focused widget accept Enter?
    local o = self.focusList[self.currentFocus]
    if o.acceptsEnter then
        o:enterHandler()
        self.window:invalidate()
    else -- look for a default Enter handler
        for _, o in ipairs(self.widgetList) do
            if o.visible and o.default then
                o:enterHandler()
                self.window:invalidate()
            end
        end
    end
end


function View:paint(gc)
    local fo = self.focusList[self.currentFocus]
    for _, o in ipairs(self.widgetList) do
        if o.visible then
            o:paint(gc, fo == o)
        end
    end
end






--------------------------------------------------------------------- Widget

Widget = class()

function Widget:init(view, x, y, w, h)
    self.view         = view
    self.x              = x
    self.y              = y
    self.w              = w
    self.h              = h
    self.acceptsFocus   = false
    self.visible        = true
end


function Widget:contains(x, y)
    return x >= self.x and x <= self.x + self.w
       and y >= self.y and y <= self.y + self.h
end


function Widget:onMouseEnter(x, y)
    -- Implemented in subclasses
end


function Widget:onMouseLeave(x, y)
    -- Implemented in subclasses
end






--------------------------------------------------------------------- Text

Text = class(Widget)

function Text:init(view, x, y, w, h, text, just, style)
    if w <= 0 then
        w = 10 * #text
    end
    if h <= 0 then
        h = 22
    end
    Widget.init(self, view, x, y, w, h)
    self.text = text or ""
    if just == "right" then
        self.just = 2       -- right justified
    elseif just == "center" then
        self.just = 1       -- centered
    else
        self.just = 0       -- left justified
    end
    self.style = style or "r"
end


-- Adds a string to the end of the text
function Text:addString(str)
    self.text = self.text .. str
    self.view:invalidate()
end


function Text:stringWidth()
    local gc = platform.gc()
    gc:begin()
    local w = gc:getStringWidth(self.text)
    gc:finish()
    return w
end


function Text:stringHeight()
    local gc = platform.gc()
    gc:begin()
    local h = gc:getStringHeight(self.text)
    gc:finish()
    return h
end


function Text:setText(str)
    self.text = tostring(str)
    self.view:invalidate()
end


-- Deletes character from end of text
function Text:delChar()
    if #self.text > 0 then
        self.text = self.text:usub(1, -2)
        self.view:invalidate()
    end
end


-- Returns a formatted version of the text
function Text:format()
    return self.text
end


function Text:paint(gc, focused)
    local text = self:format()
    gc:setColorRGB(0, 0, 0)
    if focused then
        gc:setPen("thin", "dotted")
        gc:drawRect(self.x, self.y, self.w, self.h)
        text = text .. "_"
    end
    gc:setFont("sansserif", self.style, 11)
    local x = self.x + 1
    if self.just == 1 then      -- centered
        x = self.x + (self.w - gc:getStringWidth(text))/2
    elseif self.just == 2 then  -- right justified
        x = self.x + self.w - gc:getStringWidth(text) - 1
    end
    gc:drawString(text, x, self.y + self.h, "bottom")
end






--------------------------------------------------------------------- Entry

Entry = class(Text)

function Entry:init(...)
    Text.init(self, ...)
    self.acceptsFocus = true
end






--------------------------------------------------------------------- Button

Button = class(Widget)

function Button:init(view, x, y, w, h, text, default, command)
    Widget.init(self, view, x, y, w, h)

    -- Button configuration
    self.text           = text
    self.default        = default        -- is default button when ENTER is pressed
    self.command        = command or function() end      -- what to do when pressed
    self.acceptsFocus   = true
    self.acceptsEnter   = true

    -- Current button state
    self.clicked        = false
    self.highlighted    = false
end


-- Act on key press on button
function Button:addString(str)
    if str == " " then
        self:command()
    end
end


function Button:onMouseDown(x, y)
    self.clicked     = true
    self.highlighted = true
    self.view:invalidate()
end


function Button:onMouseEnter(x, y)
    if self.clicked and not self.highlighted then
        self.highlighted = true
        self.view:invalidate()
    end
end


function Button:onMouseLeave(x, y)
    if self.clicked and self.highlighted then
        self.highlighted = false
        self.view:invalidate()
    end
end


function Button:onMouseUp(x, y)
    if self.clicked then
        self.highlighted = false
        self.clicked     = false
        self:command()
        self.view:invalidate()
    end
end


function Button:cancelClick()
    self.clicked = false
end


function Button:enterHandler()
    self:command()
end


function Button:paint(gc, focused)
    local x = self.x
    local y = self.y
    local w = self.w
    local h = self.h
    local radius = 5
    local diam   = 2*radius

    if focused then
        gc:setPen("thin", "dotted")
    elseif self.default then
        gc:setPen("thin", "smooth")
    else
        gc:setPen("thin", "smooth")
    end

    local bkgr, bkgg, bkgb = 0xE0, 0xE0, 0xE0
    if self.highlighted then
        bkgr = 0xC0
        bkgg = 0xC0
        bkgb = 0xC0
    end

    -- Draw background
    gc:setColorRGB(bkgr, bkgg, bkgb)
    gc:fillRect(x+radius, y, w-2*radius, h)
    gc:fillRect(x, y+radius, w, h-2*radius)

    -- Draw border
    gc:setColorRGB(0, 0, 0)
    gc:drawLine(x+radius, y, x+w-radius, y)
    gc:drawLine(x+radius, y+h, x+w-radius, y+h)
    gc:drawLine(x, y+radius, x, y+h-radius)
    gc:drawLine(x+w, y+radius, x+w, y+h-radius)

    -- top left corner
    gc:setColorRGB(bkgr, bkgg, bkgb)
    gc:fillArc(x, y, diam, diam, 90, 90)
    gc:setColorRGB(0, 0, 0)
    gc:drawArc(x, y, diam, diam, 90, 90)

    -- bottom left corner
    gc:setColorRGB(bkgr, bkgg, bkgb)
    gc:fillArc(x, y + h - diam, diam, diam, 180, 90)
    gc:setColorRGB(0, 0, 0)
    gc:drawArc(x, y + h - diam, diam, diam, 180, 90)

    -- bottom right corner
    gc:setColorRGB(bkgr, bkgg, bkgb)
    gc:fillArc(x + w - diam, y + h - diam, diam, diam, 270, 90)
    gc:setColorRGB(0, 0, 0)
    gc:drawArc(x + w - diam, y + h - diam, diam, diam, 270, 90)

    -- top right corner
    gc:setColorRGB(bkgr, bkgg, bkgb)
    gc:fillArc(x + w - diam, y, diam, diam, 0, 90)
    gc:setColorRGB(0, 0, 0)
    gc:drawArc(x + w - diam, y, diam, diam, 0, 90)

    -- Draw label
    gc:setFont("sansserif", "b", 10)
    gc:drawString(self.text, x + (w - gc:getStringWidth(self.text))/2, y+1, "top")
end






--------------------------------------------------------------------- SpinBox Arrow

SpinBoxArrow = class(Button)

function SpinBoxArrow:init(view, x, y, w, h, dir, command)
    Button.init(self, view, x, y, w, h, nil, false, command)
    self.dir = dir      -- "up" or "down"
end


function SpinBoxArrow:onMouseDown(x, y)
    self:command()
end


function SpinBoxArrow:onMouseEnter(x, y)
end


function SpinBoxArrow:onMouseLeave(x, y)
end


function SpinBoxArrow:onMouseUp(x, y)
end


function SpinBoxArrow:paint(gc, focused)
    local x1        = self.x + self.w/2
    local x2        = x1 + 5
    local x3        = x2 - 10

    local y1, y2, y3

    if self.dir == "up" then
        y1          = self.y
        y2          = y1 + self.h
        y3          = y2
    else
        y1          = self.y + self.h
        y2          = self.y
        y3          = y2
    end

    gc:setPen("thin", "smooth")
    gc:drawPolyLine({x1, y1, x2, y2, x3, y3, x1, y1})

    if focused then
        gc:setPen("thin", "dotted")
        gc:drawRect(x3-2, self.y-2, 14, self.h+4)
    end
end






--------------------------------------------------------------------- SpinBox

SpinBox = class(Text)

function SpinBox:init(view, x, y, w, h, value)
    Text.init(self, view, x, y, w, h, tostring(value or 1), "center")
    self.acceptsFocus   = true

    self.view:add(SpinBoxArrow(view, x, y-10,       w, 7, "up", function() self:up() end ))
    self.view:add(SpinBoxArrow(view, x, y+self.h+3, w, 7, "down", function() self:down() end ))
end


function SpinBox:value()
    return tonumber(self.text)
end


function SpinBox:up()
    self.text = tostring(tonumber(self.text) + 1)
    self.view:invalidate()
end


function SpinBox:down()
    if tonumber(self.text) > 1 then
        self.text = tostring(tonumber(self.text) - 1)
        self.view:invalidate()
    end
end








--------------------------------------------------------------------- Molecule input

-- This is a subclass of an Input box. It converts digits to subscripts before
-- being displayed.

MoleculeEntry = class(Entry)

function MoleculeEntry:init(...)
    Entry.init(self, ...)
end


-- Subscript digits 0 ... 9
Subscript = {
    ["0"] = string.uchar(0x2080),
    ["1"] = string.uchar(0x2081),
    ["2"] = string.uchar(0x2082),
    ["3"] = string.uchar(0x2083),
    ["4"] = string.uchar(0x2084),
    ["5"] = string.uchar(0x2085),
    ["6"] = string.uchar(0x2086),
    ["7"] = string.uchar(0x2087),
    ["8"] = string.uchar(0x2088),
    ["9"] = string.uchar(0x2089),
}

function MoleculeEntry:format()
    return self.text:gsub("%d", Subscript)
end






--------------------------------------------------------------------- Molecule Text

-- This is a subclass of an Text box. It converts digits to subscripts before
-- being displayed.

MoleculeText = class(Text)

function MoleculeText:init(view, x, y, w, h, spinbox, molecule)
    Text.init(self, view, x, y, w, h, molecule.formula)
    self.spinbox = spinbox
    self.elements = molecule.elements
end


function MoleculeText:value()
    return self.spinbox:value()
end


function MoleculeText:format()
    return self.text:gsub("%d", Subscript)
end






--------------------------------------------------------------------- Molecule


Molecule = class()

-- Splits up elements in the formula for a molecule.
-- Returns a Molecule
--     .formula = molecular formula
--     .elements = {element = count, ...}
function Molecule.splitElements(formula)
    local m = {}
    m.formula = formula

    local elems = {}
    for elem, count in formula:gmatch("(%u%l?)(%d*)") do
        if #count == 0 then
            count = 1
        else
            count = tonumber(count)
        end
        elems[elem] = count
    end
    m.elements = elems
    return m
end


-- Splits up molecules in the formula for a reaction.
-- Returns a list of Molecules
function Molecule.splitMolecules(formula)
    local molecules = {}
    for mol in formula:gmatch("[^%s+]+") do
        molecules[#molecules + 1] = Molecule.splitElements(mol)
    end
    return molecules
end






--------------------------------------------------------------------- Element Text

ElementText = class(Text)

function ElementText:init(view, x, y, w, h, name, molecules)
    Text.init(self, view, x, y, w, h)
    self.name       = name
    self.molecules  = molecules
end


-- Count total atoms in molecules
function ElementText:total()
    local total = 0
    for _, m in ipairs(self.molecules) do
        local count = m.elements[self.name]
        if count then
            total = total + m.controller:value() * count
        end
    end
    return total
end


function ElementText:format()
    return self:total() .. " " .. self.name
end






--------------------------------------------------------------------- Beam balance
--
-- This is a visual widget that looks like a balance. It leans in the direction
-- of the heavier side or is level when the same number of elements on each side.

Balance = class(Widget)


-- The balance needs references to the elements on left and right sides. These
-- must be ElementText objects.
function Balance:init(view, x, y, leftElement, rightElement)
    Widget.init(self, view, x, y, self.width, self.height)

    self.left = leftElement
    self.right = rightElement
end


Balance.width       = 80
Balance.height      = 18
Balance.leftx       = 5
Balance.rightx      = Balance.width - Balance.leftx
Balance.topy        = 0
Balance.bottomy     = Balance.height
Balance.midy        = Balance.height / 2
Balance.smallRadius = 5
Balance.largeRadius = 6


function Balance:paint(gc)
    local left  = self.left:total()
    local right = self.right:total()
    local x     = self.x
    local y     = self.y

    local color                     = {0, 0, 255}     -- blue
    local leftBeamEndpoint          = {0, self.midy}
    local rightBeamEndpoint         = {self.width, self.midy}
    local leftRadius                = self.smallRadius
    local rightRadius               = self.smallRadius

    if left > right then
        -- Left side is heavier
        color                       = {255, 0, 0}     -- red
        leftBeamEndpoint            = {self.leftx, self.bottomy}
        rightBeamEndpoint           = {self.rightx, 0}
        leftRadius                  = self.largeRadius
        rightRadius                 = self.smallRadius

    elseif left < right then
        -- Right side is heavier
        color                       = {255, 0, 0}
        leftBeamEndpoint            = {self.leftx, 0}
        rightBeamEndpoint           = {self.rightx, self.bottomy}
        leftRadius                  = self.smallRadius
        rightRadius                 = self.largeRadius

    end

    gc:setPen("thin", "smooth")

    gc:setColorRGB(unpack(color))

    -- Draw pedestal
    local x1 = self.width/2 - 3
    local y1 = self.height
    local x2 = self.width/2
    local y2 = self.height/2
    local x3 = self.width/2 + 3
    local y3 = self.height
    gc:drawPolyLine({x1+x, y1+y, x2+x, y2+y, x3+x, y3+y, x1+x, y1+y})

    -- Draw cross beam
    x1, y1 = unpack(leftBeamEndpoint)
    x2, y2 = unpack(rightBeamEndpoint)
    gc:drawLine(x1+x, y1+y, x2+x, y2+y)

    -- Draw elements
    local diam = 2*leftRadius
    y1 = y1 - diam * 0.87
    gc:fillArc(x1+x, y1+y, diam, diam, 0, 360)

    diam = 2*rightRadius
    x2 = x2 - diam
    y2 = y2 - diam * 0.87
    gc:fillArc(x2+x, y2+y, diam, diam, 0, 360)
end






--------------------------------------------------------------------- Edit screen


function createEditScreen(window, input_formula, output_formula)

    theView = View(window)

    -- Title
    theView:add(Text(theView, 10, 2, 300, 22, "Edit Chemical Formula", "center", "b"))
   
    -- Input molecular formula
    input = MoleculeEntry(theView, 10, 24, 140, 22, input_formula or "", "right")
    theView:add(input)
   
    -- Right-pointing arrow
    theView:add(Text(theView, 150, 24, 20, 22, string.uchar(0x2192), "center"))
   
    -- Output molecular formula
    output = MoleculeEntry(theView, 170, 24, 140, 22, output_formula or "")
    theView:add(output)
   
    -- Balance button
    theView:add(Button(theView, 110, 187, 100, 22, "Balance", true,
        function() createBalanceScreen(window, input.text, output.text) end ))

end






--------------------------------------------------------------------- Balance screen

function createBalanceScreen(window, input_formula, output_formula)

    theView = View(window)

    -- Title
    theView:add(Text(theView, 10, 2, 300, 22, "Balance Chemical Formula", "center", "b"))

    local input_molecules = Molecule.splitMolecules(input_formula)
    local output_molecules = Molecule.splitMolecules(output_formula)

    -- Survey the elements
    local elements = {}
    for _, m in ipairs(input_molecules) do
        for elem, count in pairs(m.elements) do
            elements[elem] = true
        end
    end

    local x = 10
    local y = 33
    local sb_width = 15

    -- Display reactants
    for i, m in ipairs(input_molecules) do
        local sb = SpinBox(theView, x, y, 15, 22)
        theView:add(sb)
        x = x + sb_width
        local molecule = MoleculeText(theView, x, y, 0, 0, sb, m)
        theView:add(molecule)
        m.controller = molecule

        x = x + molecule:stringWidth()

        if i < #input_molecules then
            local plus = Text(theView, x, y, 0, 0, "+")
            theView:add(plus)
            x = x + plus:stringWidth()
        end
    end

    -- Arrow
    theView:add(Text(theView, x+3, y, 14, 22, string.uchar(0x2192), "center"))
    x = x + 17

    -- Display resultants
    for i, m in ipairs(output_molecules) do
        local sb = SpinBox(theView, x, y, 15, 22)
        theView:add(sb)
        x = x + sb_width
        local molecule = MoleculeText(theView, x, y, 0, 0, sb, m)
        theView:add(molecule)
        m.controller = molecule

        x = x + molecule:stringWidth()

        if i < #output_molecules then
            local plus = Text(theView, x, y, 0, 0, "+")
            theView:add(plus)
            x = x + plus:stringWidth()
        end
    end

    -- Display elements

    local col1x = 30
    local col3x = 210
    y = 75
    for elename, _ in pairs(elements) do
        -- Reactants
        local left = ElementText(theView, col1x, y, 70, 22, elename, input_molecules)
        theView:add(left)

        -- Resultants
        local right = ElementText(theView, col3x, y, 70, 22, elename, output_molecules)
        theView:add(right)

        -- Balance
        theView:add(Balance(theView, 110, y, left, right))

        y = y + 34
    end

    -- Edit button
    theView:add(Button(theView, 110, y, 100, 22, "Edit", true,
        function() createEditScreen(window, input_formula, output_formula) end ))

end


createEditScreen(platform.window)




--------------------------------------------------------------------- Event handlers

function on.resize()
    print("resize")
end

function on.create()
    print("create")
end

function on.charIn(ch)
    theView:sendStringToFocus(ch)
end

function on.backspaceKey(ch)
    theView:sendBackspaceToFocus()
end

function on.tabKey()
    theView:tabForward()
end

function on.backtabKey()
    theView:tabBackward()
end

function on.paint(gc)
    theView:paint(gc)
end

function on.enterKey(gc)
    theView:enterHandler()
end

function on.mouseDown(x, y)
    theView:onMouseDown(x, y)
end

function on.mouseMove(x, y)
    theView:onMouseMove(x, y)
end

function on.mouseUp(x, y)
    theView:onMouseUp(x, y)
end

function on.save()
    return {input = input.text, output = output.text}
end

function on.restore(state)
    createEditScreen(platform.window, state.input, state.output)
end


Generated by the BBify'r (http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/))
Title: Re: BBify your Z80, Axe, and Lua
Post by: mrmprog on September 24, 2011, 02:15:29 pm
Nice! Now axe code won't be such a pain. I like how it saves the stuff so you can keep working, and the colors.
Title: Re: BBify your Z80, Axe, and Lua
Post by: Deep Toaster on October 01, 2011, 10:25:53 pm
As Darl181 suggested, I've fixed the bug where Axe comments have a backslash before every token when uploading an Axe source.
Title: Re: BBify your Z80, Axe, and Lua
Post by: Darl181 on October 01, 2011, 10:53:50 pm
Hm, it seems it's replacing [Sto►] arrows with "?"

EDIT: wait a sec, for the copy/paste in the piratepad which text editor did you use?
Title: Re: BBify your Z80, Axe, and Lua
Post by: Deep Toaster on October 01, 2011, 11:00:34 pm
Notepad++, which is probably why. The editor's UI only supports ASCII. BBify handles it perfectly:

Quote from: Axe


Generated by the BBify'r (http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/))
Title: Re: BBify your Z80, Axe, and Lua
Post by: Deep Toaster on October 18, 2011, 11:48:26 pm
UPDATE: TIOS v3.0.2 and Luna make this update seem a bit late in coming, but whatever. Just like with Axe source programs, you can now upload your Lua source in TI Document format, as long as it's unencrypted (for Lua on OS 3.0.1 and before)! It'll read the Lua code from your TNS documents.
Title: Re: BBify your Z80, Axe, and Lua
Post by: DJ Omnimaga on October 18, 2011, 11:59:35 pm
Nice to hear it supports Nspire too. I was sure it was only for z80 stuff. Good job so far. :)

Does it support TI-BASIC, Casio BASIC, C and BBC Basic, btw? (The first two might be a bit obsolete though due to SourceCoder)
Title: Re: BBify your Z80, Axe, and Lua
Post by: Deep Toaster on October 19, 2011, 12:14:18 am
I wasn't planning on BASIC support since SourceCoder does that very well, but C and other languages might be possible.
Title: Re: BBify your Z80, Axe, and Lua
Post by: Jim Bauwens on October 19, 2011, 03:32:44 am
I somehow must have skipped all of this D:
Lua support \o/
/me hugs Deep Thought
Title: Re: BBify your Z80, Axe, and Lua
Post by: Deep Toaster on October 19, 2011, 10:38:29 am
Yep :) I don't think I've posted this yet, so here's more information about the Lua syntax it supports. Standard Lua control structures, operators, and keywords are supported, but not individual libraries like table, math, and debug. Instead, it recognizes and highlights functions and libraries specific to Nspire Lua like timer, gc, and D2Editor.
Title: Re: BBify your Z80, Axe, and Lua
Post by: Chockosta on October 19, 2011, 02:16:37 pm
Just amazing !
I love Lua support !
/me gives respect to DT
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on November 07, 2011, 07:51:49 pm
Update: 83P-series TI-BASIC detokenizing and syntax highlighting has been added, and lots of bugs with Axe syntax have been fixed! It now automatically checks if a program you upload is an Axe source or TI-BASIC program.

Quote from: TI-BASIC
"THE GAME→Str0
0
For(I,1,8
30Ans+inData("ABCDEFGHIJKLMNOPQRSTUVWXYZtheta :?",sub(Str0,I,1
End
Ans→J
" →Str0
J
For(I,1,8
Ans/30→J
sub("ABCDEFGHIJKLMNOPQRSTUVWXYZtheta :?",round(3�float{Ans),�),1)+Str0→Str0
nib{J
End
Str0


Generated by the BBify'r (http://clrhome.org/resources/bbify/ (http://clrhome.org/resources/bbify/))
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Darl181 on November 08, 2011, 02:49:49 pm
Might it be possible to disable the coloring?  It gets pretty hard if you want to modify your code later when every token has its own color tag x.x

Also, for some reason some chars (esp. zeroes) don't display/get parsed properly or something, firefox shows a diamond with a ?
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on November 08, 2011, 03:48:07 pm
Quote from: Darl181
Might it be possible to disable the coloring?  It gets pretty hard if you want to modify your code later when every token has its own color tag
Yeah, I added a "Plain text" option for highlighting, but remember you can always copy-paste your code back into BBify (not the BBCode, but what shows up on the forum).
Quote from: Darl181
Also, for some reason some chars (esp. zeroes) don't display/get parsed properly or something, firefox shows a diamond with a ?
I thought I'd fixed that. Do you have the code you used?
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Darl181 on November 09, 2011, 11:18:23 am
The code attached in this (http://ourl.ca/9165/259893) post.
It seemed to center on the sprite declarations in particular, if that helps.
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on November 09, 2011, 06:35:01 pm
Fixed. All zeros were being parsed as null bytes :P
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Darl181 on November 12, 2011, 11:14:15 am
...and now it's putting slashes between every token again x.x
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on November 12, 2011, 11:48:14 am
It doesn't for me ??? Only in the input box after detokenizing, and that's to prevent it from reading a minus sign followed by a greater-than sign as → and so on. \ separates ambiguous characters in TokenIDE.
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Darl181 on November 12, 2011, 05:37:35 pm
Nvm, it was set as "Plain Text" :P
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on November 12, 2011, 07:26:45 pm
Should I remove the slashes even for plain text?
Title: BBify: detokenize and highlight your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on January 01, 2012, 03:00:47 pm
UPDATE: I had this idea months ago, but I finally sat down and made it today. The BBify'r now has a "BBify Builder" function, where you type some stuff and watch it generate a language rules sheet for you. So you can now use it to highlight the syntax of any language without needing to know regular expressions. Just type what it asks you to type and it builds everything for you.

When you're done, you can choose to download the XML file (and upload it as a custom rules sheet to use) or save it online—it'll be there as an option the next time you need it!

(http://img.removedfromgame.com/imgs/bbify.png)
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Darl181 on January 01, 2012, 03:12:18 pm
Should I remove the slashes even for plain text?
I'm not sure, but maybe make the options more prominent?  Maybe not fill one in by default or something, and require that one is checked.

Also awesome :D
Title: Re: BBify your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on January 01, 2012, 03:13:42 pm
Should I remove the slashes even for plain text?
I'm not sure, but maybe make the options more prominent?  Maybe not fill one in by default or something, and require that one is checked.
I actually got rid of the Plain Text option :/ If you need your code without highlighting, just post it in a forum (you can use Preview) and copy-paste the result.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on March 30, 2013, 06:07:03 pm
Major necro-update

The BBify'r now generates code coloring in HTML as well as BBCode!

That means two things:
As always: http://clrhome.org/bbify/

I might change the URL and the name of the project someday, since it's not just for BBCode conversion anymore.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Jonius7 on July 11, 2013, 06:57:39 am
I was reminded of this topic by this topic: http://ourl.ca/119725
And bbify literally went offline 5 minutes after I started using it.
And now it's back online.
EDIT: It didn't seem to work for uploading code files, it would submit/reload the page but do nothing else.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Sorunome on July 11, 2013, 11:12:26 am
Ui, nice, this is useful!
We should have a modified [code] tag though to also highlight for like basic or axe :P
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on July 11, 2013, 01:32:35 pm
I was reminded of this topic by this topic: http://ourl.ca/119725
And bbify literally went offline 5 minutes after I started using it.
And now it's back online.
I'm on a free server that seems to have gotten worse over time. Looking for a new host soon.
EDIT: It didn't seem to work for uploading code files, it would submit/reload the page but do nothing else.
Works for me.

There are two file upload buttons, one for the (optional) stylesheet and one for the actual code. Are you sure you uploaded it in the right place?

I think I'll reverse the order of steps on the page. Seems to make more sense to put code in first, and then customize colors and stuff.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Jonius7 on July 12, 2013, 03:29:56 am
Yeah step 3, under give me your code, with the code box on the left and the upload file/url link on the right.
The code box works, the file upload doesn't.

EDIT: oh wait a minute it wasn't working before, now it's uploading... but it didn't seem to work. What kind of TI-nspire/Lua files can it
accept?

EDIT: it works for Axe 8xp :)

Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on July 12, 2013, 01:00:13 pm
You're right—seems file uploads worked with 8XP and unencrypted (OS 3.0.1) TNS files, which get detokenized and parsed, but not plain-text source code :P Fixed.

Thanks for the bug report!

Supported filetypes are 8XP (protected or unprotected), TNS (unencrypted only), and plain-text.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: DJ Omnimaga on July 26, 2013, 01:18:29 am
I was reminded of this topic by this topic: http://ourl.ca/119725
And bbify literally went offline 5 minutes after I started using it.
And now it's back online.
I'm on a free server that seems to have gotten worse over time. Looking for a new host soon.
I assume that Omnimaga hosting (like ASM Unsquisher) isn't an option?

(Also you might want to backup your site and tools more often since your hosting is getting worse and worse. No one knows if it won't shut down tomorrow or at any other moment without warning)
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: Deep Toaster on July 26, 2013, 01:04:05 pm
I was reminded of this topic by this topic: http://ourl.ca/119725
And bbify literally went offline 5 minutes after I started using it.
And now it's back online.
I'm on a free server that seems to have gotten worse over time. Looking for a new host soon.
I assume that Omnimaga hosting (like ASM Unsquisher) isn't an option?

(Also you might want to backup your site and tools more often since your hosting is getting worse and worse. No one knows if it won't shut down tomorrow or at any other moment without warning)
I'm looking into getting a paid host of my own, preferably a VPS.

You're completely right that the uptime's getting worse. 000webhost "guarantees" 99% uptime, and their official "independent" uptime tracker at http://www.serviceuptime.com/users/monitoring.php?S=6c8ef11fcca35bab3d971cdce3d7179b shows well above 99%. But notice how they stopped keeping track of uptime last year (specifically doomsday). Meanwhile, Pingdom tells me my uptime's been dropping steadily, and now it's around 75% >:(

On the other hand, I'm taking backups every night straight into my Google Drive, and one of my flash drives is a mirror of the complete site, so data loss isn't a problem.
Title: Re: BBify: syntax-color your Z80, TI-BASIC, Axe, and Lua
Post by: DJ Omnimaga on July 29, 2013, 09:31:56 pm
Yeah, hosting providers try to lure new customers by offering really good uptime and sometimes speed, then once the customers have settled in for a while, they slowly degrade the performances then eventually offer more expensive plans to those who are no longer satantified by the performances. Then they just shut down their free hosting entirely.

The other scenario is when they offer a pool of resources just for free hosting, but that are split between customers. If the company doesn't upgrade, it really gets slow when there are 1000 customers.