83Plus:OS:Opening System Apps

From WikiTI
Jump to: navigation, search


For now, this page is purely about how to open the program editor. When someone decides to take a shot at another system app, you can remove this line.

Program Editor

This is all the code that is needed to properly open the program editor.

	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
 

Here's 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, but this example just does 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.