www.retrosoftware.co.uk
http://www.retrosoftware.co.uk/forum/

OSFILE load and save errors.
http://www.retrosoftware.co.uk/forum/viewtopic.php?f=73&t=718
Page 1 of 1

Author:  PitfallJ [ Fri Jan 27, 2012 1:04 pm ]
Post subject:  OSFILE load and save errors.

Hi,

I'm trying to load and save files using OSFILE (Incidentally is it $FFDD or $FFCE? - I'm using the former at the moment) but when an error occurs like "file not found" or "disk write protected" it will print the error message to the screen and crash my program - it prints "Bad Program" on the screen as well.

These are valid errors but if they occur I'd like to handle them myself and my program to keep control.

Any suggestions?

Thanks

PJ

P.S. The same thing happens using OSCLI.

Author:  TomW [ Fri Jan 27, 2012 1:37 pm ]
Post subject:  Re: OSFILE load and save errors.

Trap BRKV (&202-203).

Author:  RichTW [ Fri Jan 27, 2012 10:12 pm ]
Post subject:  Re: OSFILE load and save errors.

Just to expand on that, the Beeb OS doesn't expect to resume the code which follows BRK instructions, so your BRK handler should end by JMPing to a fixed location afterwards, in the same spirit as ON ERROR GOTO in BASIC.

To avoid bad stack shenanigans, I'd suggest that the best trick is to remember the current stack pointer (TSX / STX storedsp), point the BRKV at your own handler (remembering its old contents) and call OSFILE.

Your BRK handler should print the error message (addresses &FD/&FE point at the error number followed by the zero-terminated error message), then exit by restoring the stack pointer you saved earlier and jumping to your error recovery code.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/