83Plus:OS:Opening System Apps

From WikiTI
Revision as of 06:47, 20 February 2012 by Thepenguin77 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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
	bcall(_mon)

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) After you've done your modding (or not) you call _mon to hand control over to the OS and let it do its business.