I have a question. I'm the horrible flavor of coder who doesn't fare well with manipulating the stack perfectly, so in case I run into difficulties with some code, I tried writing two small routines that would get the location of the stack (with an extra pop beforehand) and the value at the top of the stack before I even touch it myself, so when I do a final exit from the app, the stack looks as though it was never touched to the OS. Here is my code for this:
;start stack check initializer
;keeps track of app start location
;followed up later in case of emergency exits
StartStackCheckInit
pop hl
ld (OP6),hl ;load emergency resources into OP6
ld hl,0
adc hl,sp
ld (OP6+2),hl
ld hl,(OP6)
push hl
ret
StartStackCheckInit_end
;emergency exit call
;used only when an exit is REALLY REALLY REALLY needed
ExitUsingEmergencyResources
ld sp,(OP6+2)
ld hl,(OP6)
push hl
END_APP_RUN ;just a small stand-in for that bcall(_JForceNoCMD...) thing I always forget the name frequently
ExitUsingEmergencyResources_end
Looks like it'll work (from what I saw in Wabbit, it seemed to work fine there too -- however, I can't test on hardware ATM) but is it safe to sexually abuse the stack this much? Or is it even safe in general to attempt such a thing?