Date : Sat, 28 Dec 1996 23:10:33 +0000 (GMT)
From : Steven Flintham <sf4000@...>
Subject: Redirecting the BRK vector and paging out the current language
I'm writing a machine code program which needs to be able to cope with
OS errors, so I'm installing my own handler on the BRK vector. This
seems to work fine, except that I don't know what to do when the
program finishes. I can't just RTS as usual because if an error has
occurred the BRK instruction used to generate it will destroy the
stack. I don't think just saving the return address at the start of
the program will work either, because the caller might expect the
whole stack to be valid. I did try it briefly and it didn't appear to
work but I didn't spend ages checking the code for errors.
I also thought about re-entering the current language using *FX142.
This should work on the host but I want the program to be Tube-
compatible and I'm not sure if this will work if (for example) HI-
BASIC has been loaded from disc. I haven't got a 6502 second processor
myself but under 65Tube on RISC OS it didn't seem to (I was calling
*FX142 with the ROM number returned by *FX252). (Actually, it seemed
to work if I put LDA #42:JSR &FFEE just before it, but I can only
assume this was a coincidence.)
At the moment I'm generating a `Program terminated' error after
restoring the original BRK vector. This works but it's not very
satisfactory. Can anyone suggest another way of exiting the program?
In order to get extra workspace I'm also thinking of paging a sideways
RAM bank in over the current language ROM (since I'm not using it) at
the start of the program and then paging the language back in before
exiting. I tried this and it seemed to work, but is it actually
acceptable or was it just coincidence? I can't see why it shouldn't,
since I'm setting up my own BRK handler and I don't think there's
anything else which will try to access the current language, but I
know paging ROMs out can be dangerous.
Thanks in advance.
Steven