comparison src/error.s @ 75:5f8f0b0781e8

Split some code into separate files for easier management (3) Because the source for lwbasic is so large, split it into several different files to make it easier to navigate and modify. This is part three of the split. Includes a file missing from part one.
author William Astle <lost@l-w.ca>
date Sun, 06 Aug 2023 00:41:26 -0600
parents
children bb50ac9fdf37
comparison
equal deleted inserted replaced
74:e74d00ac6b79 75:5f8f0b0781e8
1 *pragmapush list
2 *pragma list
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ; The error handler
5 ;
6 ; Enter with the error number in B. This routine will do some cleanup and handle any ON ERROR GOTO handler that
7 ; may be active.
8 ;
9 ; Note the error message lookup does not need to be efficient which is why the lookup just runs through the list
10 ; of error messages in sequence looking for NUL terminators. The specific handling of B (error number) below avoids
11 ; issues if there happen to be error codes above 128.
12 ERROR clr filenum ; reset display device to console
13 jsr writecondnl ; do a newline if needed (will preserve B)
14 ldx #errormsg ; point to error message list
15 incb ; account for decb below
16 bra ERROR1 ; go search for correct message
17 ERROR0 lda ,x+ ; end of message?
18 bne ERROR0 ; brif not end of message
19 ERROR1 decb ; at the correct one?
20 bne ERROR0 ; brif not - skip to next one
21 ERROR2 jsr writestrconduc ; output error message
22 ldu curline ; are we in immediate mode?
23 beq ERROR3 ; brif so
24 ldx #inmsg ; point to " in "
25 jsr writestrconduc ; output " in "
26 ldd 2,u ; get line number
27 jsr print_uint16d ; display the line number
28 ERROR3 lds freetop ; reset the stack pointer (error routine could be called anywhere)
29 clr ,-s ; reset the call stack
30 sts stackptr
31 jmp immediate ; go back to immediate mode
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ; Error messages
34 ;
35 ; Each error begins with a deferr macro invocation which will define a symbol err_slug with the next error number
36 ;
37 ; deferr slug
38 ;
39 ; This is then followed by the error message defined with fcn.
40 ;
41 ; Real error numbers start at 1; 0 is used to indicate no error.
42 *pragmapush list
43 *pragma nolist
44 __errnum set 0
45 deferr macro noexpand
46 err_{1} equ __errnum
47 __errnum set __errnum+1
48 endm
49 *pragmapop list
50 errormsg deferr none
51 fcn 'No error'
52 deferr nf
53 fcn 'NEXT without FOR'
54 deferr sn
55 fcn 'Syntax error'
56 deferr ul
57 fcn 'Undefined line number'
58 deferr rg
59 fcn 'RETURN without GOSUB'
60 deferr ov
61 fcn 'Overflow'
62 deferr tm
63 fcn 'Type mismatch'
64 *pragmapop list