Author Topic: How to open the program editor  (Read 3783 times)

0 Members and 1 Guest are viewing this topic.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
How to open the program editor
« on: February 20, 2012, 01:01:49 am »
There's been a lot of trouble lately with people trying to open the program editor (mostly Quigibo and I) so I'm here to show you how it's done. The complete code for opening the edit buffer looks like this:

Code: [Select]
ld a, kExtApps ;1
ld (cxCurApp), a

ld a, kPrgmEd
bcall(_pullDownChk) ;2
bcall(_clrTR)

ld hl, programName
ld de, progToEdit-1 ;3
bcall(_mov9B)

bcall(_newContext0) ;4

ld sp, (onSP) ;5
bcall(_resetStacks)

bcall(_mon) ;6


programName:
.db progObj, "NAME", 0

I'll now explain why this code works by parts:
1. There are two main reasons to set the current app to kExtApps: 1) the OS won't try to clean up an app that isn't already open, 2) if for some reason the previous app was kPrgmEd, the editor is not going to initialize. By setting this, we are essentially resetting the app system

2. This little section takes care of any menus that are currently up. For instance, without this block, if you open the editor from the standard PRGM->Edit menu, the editor will appear to open correctly. But as soon as you try to move, you'll find out that you are actually still inside of the PRGM->Edit menu and all hell will break loose.

3. Simply put, progToEdit is the name of the program you are going to edit. You don't have to copy the progObj token if you don't want to, I just do it for good measure.

4. The _clrTr will actually return kPrgmEd in A, you then feed this value into _newContext0 so that the OS can initialize the program editor app. After the _newContext0, the program editor has actually loaded: the screen looks good and the edit buffer is open. What this means is that at this point, you can mod the edit buffer in whatever way you choose. (In zStart, this is where instant goto happens)

5. These two lines are semi-optional. You don't technically have to have them, but they are a good idea. You should reset the stacks at this point because if you don't do it now, they aren't going to be reset. This means that after a few iterations of opening the editor, SP is going to make its way into the VAT and you'll start corrupting stuff.

6. This hands control back over to the OS so it can do its job.


There's my technical writing of what I've been working on for quite some time. If you don't understand any of it, that's ok I guess, the code still works even if you don't understand why ;D

Edit:
   I changed this post to reflect my resetting of the stack.
« Last Edit: March 03, 2012, 09:04:24 pm by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Online DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: How to open the program editor
« Reply #1 on: February 20, 2012, 01:04:07 am »
Do you mean some people actually got locked out of the program editor? O.O

EDIT: Nvm I see QUigibo name now, so it's to open it from an ASM program lol.
« Last Edit: February 20, 2012, 01:29:52 am by DJ_O »

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: How to open the program editor
« Reply #2 on: February 20, 2012, 01:26:20 am »
Great. Add this to either the wiki page on edit buffers, or maybe a new page.

Edit: The new page he created is on WikiTI's Opening System Apps page. It's actually pretty sweet info, since this helps show the EOS can be event-driven.
« Last Edit: February 20, 2012, 02:00:57 pm by DrDnar »
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: How to open the program editor
« Reply #3 on: March 03, 2012, 09:05:20 pm »
I made a slight change to the way this operates. I added the two stack resets because if you don't do them, the stack will eventually overflow. The updates have been applied to this post and to wikiti.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112