Re: A83: error handler
[Prev][Next][Index][Thread]
Re: A83: error handler
On 10-Jun-99, you wrote:
> How do you make a built-in error handler?
>
>
> Bud
You push it to the stack, using a special rom call. Like this:
ld hl,errorhandler
call __pushErrorHandlER
; now do something that may cause an error...
call _parseInp
;If an error occurs, the error handler will be invoked, and the
;rest of the program is never executed. But if no error occurs,
;the error handler must be removed:
call __popErrorHandleR
;Done!
ret
errorhandler:
; Whatever code you like to have to clean up after an error.
; If you allocate memory in the beginning of the program, you
; must free it after the __popErrorHandleR. If an error occurs,
; however, you must free the memory from this routine too. To
; make it practical, use several error handlers! Just remember
; that error handlers use the stack, so you can't push something,
; then push an error handler, and then try to pop what you pushed.
; Don't end with a ret, end with:
jp _JerrorNo ;Always end error handlers with this instruction.
; The following is a workaround for a particularly stupid bug.
; The normal error handler routines can only be called directly, by
; bypassing the rompage c stubs, so these routines fetch the address
; of the real routine and jump there.
__pushErrorHandlER:
.db e5h,2ah,a6h,46h,22h
.dw __pushErrorHandlER+9
.db e1h,c3h,00h,00h
__popErrorHandleR:
.db e5h,2ah,aah,46h,22h
.dw __popErrorHandleR+9
.db e1h,c3h,00h,00h
Linus
--
wwww
(o)(O)
.--> .-------mm--(__)--mm--------.
| Linus Akesson | http://linusworld.cjb.net |
`---------------^-- ----- --- -- -- - - - `---------ooO--Ooo----------'
Pentium instruction of the day: GWA: Generate Wrong Answer
References: