Then I guess the use only one time at the end of the program just makes the code simpler. It's by the way the title of the book I've mentioned (MSX Made Simple).
Repeating it several times can give a code more difficult to understand, and it explains the choice made by most coders.
I think we can therefore give all examples with both variants as it can also modify how the RESUME instruction works.
Then I guess the use only one time at the end of the program just makes the code simpler.
No, it makes a big difference. If you only call "ON ERROR GOTO 0" when exiting your program your error handler(s) will have to handle *all* errors that might occur in your program, including syntax errors, subscripts out of range, overflows etc.
Repeating it several times can give a code more difficult to understand,
On the contrary, it can make the code easier to understand. This is how I implemented the loading/saving of hiscore mentioned in my first post:
1400 on error goto 1470 1410 hi$=dski$(0,0) 1420 open "game.bas" for input as #1:close(1) 1440 if hi%=0 then open "game.hi" for input as #1:input #1,hi$:hi%=val(hi$):close(1):goto 1460 1450 open "game.hi" for output as #1:print #1,hi%:close(1) 1460 on error goto 0:return:' Reinstall default error handler 1470 resume 1460:' Ignore all errors
This is a very simple example because the error code does not matter (it just ignores anything that goes wrong, which is exactly the point in this particular case), but I think the point is clear - the error handler does not have to care about anything else than dealing with any errors that might occur in 1420-1450. Any errors occuring outside of such local error handlers will be handled by the default handler (or you could install your own "critical error" handler for this if you want to exit your program cleanly in case of a crash).
If all you want is to detect if there's a disk system available, just do PEEK(&HFFA7)
. If you get &HC9 then there's no disk system available, any other value means there is.
Explanation: &HFFA7 is the H.PHYD
hook, the one that bootstraps the BIOS routine PHYDIO. &HC9 is the opcode for RET, and is the initial value of the hook on system boot set by main BIOS; MSX-DOS sets it with a jump to a proper sector access routine on startup.
mars2000, in fact, we had both missed something. Now that I figured out what was wrong I re-edited the wiki. I hope it's clearer now.
mars2000, in fact, we had both missed something. Now that I figured out what was wrong I re-edited the wiki. I hope it's clearer now.
I think it's more complete now, and explains why ON ERROR GOTO O is required. Its location finally depends on what the coder wants to achieve but apparently, many coders prefer the last line option. 'Hiding' the errors inside a game section as in the example above can be an option for some reason, but it's a special case anyway.