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:
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
Edit:
I changed this post to reflect my resetting of the stack.