view src/error.s @ 119:a6a53e5c04bd

Make a call stack implementation that is more complete and maybe cleaner.
author William Astle <lost@l-w.ca>
date Fri, 29 Dec 2023 01:40:39 -0700
parents bb50ac9fdf37
children 5d5472b11ccd
line wrap: on
line source

                *pragmapush list
                *pragma list
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The error handler
;
; Enter with the error number in B. This routine will do some cleanup and handle any ON ERROR GOTO handler that
; may be active.
;
; Note the error message lookup does not need to be efficient which is why the lookup just runs through the list
; of error messages in sequence looking for NUL terminators. The specific handling of B (error number) below avoids
; issues if there happen to be error codes above 128.
ERROR           clr filenum                     ; reset display device to console
                jsr writecondnl                 ; do a newline if needed (will preserve B)
                ldx #errormsg                   ; point to error message list
                incb                            ; account for decb below
                bra ERROR1                      ; go search for correct message
ERROR0          lda ,x+                         ; end of message?
                bne ERROR0                      ; brif not end of message
ERROR1          decb                            ; at the correct one?
                bne ERROR0                      ; brif not - skip to next one
ERROR2          jsr writestrconduc              ; output error message
                ldu curline                     ; are we in immediate mode?
                beq ERROR3                      ; brif so
                ldx #inmsg                      ; point to " in "
                jsr writestrconduc              ; output " in "
                ldd 2,u                         ; get line number
                jsr print_uint16d               ; display the line number
ERROR3          lds freetop                     ; reset the stack pointer (error routine could be called anywhere)
                clr ,-s                         ; reset the call stack
                sts cstackptr
                jmp immediate                   ; go back to immediate mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error messages
;
; Each error begins with a deferr macro invocation which will define a symbol err_slug with the next error number
;
;               deferr slug
;
; This is then followed by the error message defined with fcn.
;
; Real error numbers start at 1; 0 is used to indicate no error.
                *pragmapush list
                *pragma nolist
__errnum        set 0
deferr          macro noexpand
err_{1}         equ __errnum
__errnum        set __errnum+1
                endm
                *pragmapop list
errormsg        deferr none
                fcn 'No error'
                deferr nf
                fcn 'NEXT without FOR'
                deferr sn
                fcn 'Syntax error'
                deferr ul
                fcn 'Undefined line number'
                deferr rg
                fcn 'RETURN without GOSUB'
                deferr ov
                fcn 'Overflow'
                deferr tm
                fcn 'Type mismatch'
                deferr div0
                fcn 'Division by zero'
                *pragmapop list