This week I wrote my first "real" assembly program. It's a CE cursor hook which prints the If, While, Repeat, or For statement that corresponds to each End statement.



It supports both ICE and TI-BASIC, and handles inline If statements (but not control statements inside inline if statements).

And the source, which is probably about twice as long as it need to be:

Code:

CursorHook_start:
   .db   83h
   cp   a, 24h
   jr   nz, +_
   inc   a
   ld   a, b
   ret
_:   cp   a, 22h
   ret   nz
   ld   a, (cxCurApp)
   cp   a, cxPrgmEdit
   ret   nz
   ld   hl, (editCursor)
   ld   a, (hl)
   cp   a, tSum
   jr   z, DrawDetText
   cp   a, tDet
   jr   z, DrawDetText
   cp   a, tEnd
   ret   nz
   push   hl
   ld   hl, DrawEndTextBegin
   ld   de, (rawKeyHookPtr)
   add   hl, de
   jp   (hl)
DrawDetText:
;   Regular ICE hook stuff...
_:   inc   a
   ret
DrawEndTextBegin:
   pop hl
   ld   b, 1
DrawEndTextLoop:
   ld   de, (editTop)
   scf
   sbc   hl, de
   jr   c, -_
   add hl, de
   ld   a, (hl)
   cp   a, tIf
   jr   nz, +_
   push   hl
   ld   hl, (editTop)
   ld   a, (hl)
   pop   hl
   cp   a, tii
   ld   a, (hl)
   jr   z, ++_
_:   cp   a, tThen
   jr   z, +_
   cp   a, tWhile
   jr   z, +_
   cp   a, tRepeat
   jr   z, +_
   cp   a, tFor
   jr   z, +_
   cp   a, tEnd
   jr   nz, DrawEndTextLoop
   inc   b
   jr   DrawEndTextLoop
_:   dec   b
   jr   nz, DrawEndTextLoop
DrawEndTextEnd:
   cp   a, tThen
   jr   nz, ++_
_:   ld   de, (editTop)
   scf
   sbc   hl, de
   jr   c, DrawEndTextExit
   add hl, de
   ld   a, (hl)
   cp   a, tIf
   jr   nz, -_
_:   
   ld   de, 000E71Ch
   ld.sis   (drawFGColor & 0FFFFh), de
   ld.sis   de, (statusBarBGColor & 0FFFFh)
   ld.sis   (drawBGColor & 0FFFFh), de
   ld   a, 14
   ld   (penRow),a
   ld   de, 2
   ld.sis   (penCol & 0FFFFh), de
DrawEndTextPrint:
   push   hl
   call   _Get_Tok_Strng
   ld   hl, OP3
   call   _VPutS
   pop   hl
   ld   a, (hl)
   call   _Isa2ByteTok
   jr   nz, +_
   inc   hl
_:   inc   hl
   ld   a, (hl)
   cp   a, tEnter
   jr   nz, DrawEndTextPrint
DrawEndTextExit:
   or   a, a
   ret


I'm using SPASM because I modified ICEHOOKS instead of making my own hook loader.
This still isn't super complete yet (Else statements do nothing, and the battery indicator is overwritten if the string is too long), but if you want to try it, a download is available here. This is an appvar, run ICE after transferring to install it.
This is very neat and useful! You dont know how many times I have to check to see if the End statements are in order.

I just have one critique. I like to use ICE and have it installed. I want this to be compatible with ICE. You said:
commandblockguy wrote:
It supports both ICE and TIBASIC

and...
commandblockguy wrote:
This is an appvar, run ICE after transferring to install it


This sounds contradictory, at least to me. Does it work with ICE or not? This makes it sound like it breaks hooks, which I consiter a major part of ICE. Is it coupled into the existing ICE hooks? You screenshot looks this way but this could be elaborated on. Perhaps you could modify the ICE Hook loader and make it its own program.

Please continue your work, the oncalc programmers will most certainly thank you!
The program itself is a modified version of the ICE hooks appvar. The ICE program is not modified, just the hook appvar. All normal ICE functions still work, including hooks. It requires ICE to be installed on the calc, but supports both vanilla TI-BASIC programs and ICE source files.

I may release a standalone version that does not require ICE to be installed (if people don't want the other hooks, for whatever reason?).
Wow, this looks like a great tool! I don't know how much I'd use it since I've moved to KryptonIDE but I'll give it a download.
How do you plan on dealing with the long strings? Would it be possible to have the text scroll along the top? That'd be pretty cool! Razz
I am currently working on implementing a cutoff. I don't think scrolling is a necessity, as usually the first part of a line is more helpful than the last part in identifying what it does. If people think scrolling would be helpful, I will implement it, but right now it seems like more trouble than it's worth given the use case for this program.

I've also realized that the program is not accurate if you include control tokens inside string literals. As far as I know there is no valid reason that a control token be included in a string literal.

More pressing is probably the fact that the program does not consider whether a token is part of an ICE comment, which I will fix soon.

EDIT:
Implemented comments and cutoff. Also fixed a bug where colors were off in the TRACE and GRAPH menus.

Code:
CursorHook_start:
   .db   83h
   cp   a, 24h
   jr   nz, +_
   inc   a
   ld   a, b
   ret
_:   cp   a, 22h
   ret   nz
   ld   a, (cxCurApp)
   cp   a, cxPrgmEdit
   ret   nz
   ld   hl, (editCursor)
   ld   a, (hl)
   cp   a, tSum
   jr   z, DrawDetText
   cp   a, tDet
   jr   z, DrawDetText
   cp   a, tEnd
   ret   nz
   push   hl
   ld   hl, DrawEndTextBegin
   ld   de, (rawKeyHookPtr)
   add   hl, de
   jp   (hl)
DrawDetText:
;Skipping unmodified original code
_:   inc   a
   ret
;b: control/end counter
DrawEndTextBegin:
   pop hl
   ld   b, 1
DrawEndTextLoop:
   ld   de, (editTop)
   scf
   sbc   hl, de
   jr   c, -_
   add hl, de
   ld   a, (hl)
   cp   a, tIf
   jr   nz, +_
   push   hl
   ld   hl, (editTop)
   ld   a, (hl)
   pop   hl
   cp   a, tii
   ld   a, (hl)
   jr   z, ++_
_:   cp   a, tThen
   jr   z, +_
   cp   a, tWhile
   jr   z, +_
   cp   a, tRepeat
   jr   z, +_
   cp   a, tFor
   jr   z, +_
   cp   a, tEnd
   jr   nz, DrawEndTextLoop
   inc   b
   jr   DrawEndTextLoop
_:   push hl
CheckCommentLoop:
   ld   de, (editTop)
   scf
   sbc   hl, de
   jr   c, InComment
   add hl, de
   ld   a, (hl)
   cp   a, tii
   jr   nz, +_
   pop hl
   jr   DrawEndTextLoop
_:   cp   a, tEnter
   jr   nz, CheckCommentLoop
InComment:
   pop   hl
   dec   b
   jr   nz, DrawEndTextLoop
DrawEndTextEnd:
   cp   a, tThen
   jr   nz, ++_
_:   ld   de, (editTop)
   scf
   sbc   hl, de
   jr   c, DrawEndTextExit
   add hl, de
   ld   a, (hl)
   cp   a, tIf
   jr   nz, -_
_:   
   ld   de, 000E71Ch
   ld.sis   (drawFGColor & 0FFFFh), de
   ld.sis   de, (statusBarBGColor & 0FFFFh)
   ld.sis   (drawBGColor & 0FFFFh), de
   ld   a, 14
   ld   (penRow),a
   ld   de, 2
   ld.sis   (penCol & 0FFFFh), de
   ld   b, 0
DrawEndTextPrint:
   inc e
   push   de
   call   _Get_Tok_Strng
   pop de
   add   a, e
   cp   a, 25h
   jr   nc, DrawEndTextExit
   push   hl
   ld   hl, OP3
   call   _VPutS
   pop   hl
   ld   a, (hl)
   call   _Isa2ByteTok
   jr   nz, +_
   inc   hl
_:   inc   hl
   ld   a, (hl)
   cp   a, tEnter
   jr   nz, DrawEndTextPrint
   ld   de, 0FFFFh
   ld.sis   (drawBGColor & 0FFFFh), de
DrawEndTextExit:
   or   a, a
   ret


And a download.

This version should be "finished" unless bugs are found or optimizations are made. However, I would still be careful running it on an actual calculator until I do further testing.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement