-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.s
54 lines (48 loc) · 1.14 KB
/
error.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;
; Error codes and messages
;
; Steve Maddison, 25/02/2007
;
error_div_0: equ 0x01
error_overflow: equ 0x02
error_underflow: equ 0x03
error_delimeter: equ 0x04
error_no_dev: equ 0x05
error_max: equ 0x06
error_str_div0: defm "Division by 0\0"
error_str_overflow: defm "Overflow\0"
error_str_underflow: defm "Underflow\0"
error_str_delimeter: defm "Unmatched delimeter\0"
error_str_no_dev: defm "No such device\0"
error_str_unknown: defm "Unknown error\0"
error_str_table: defw error_str_unknown
defw error_str_div0
defw error_str_overflow
defw error_str_underflow
defw error_str_delimeter
defw error_str_no_dev
; Name: error_str
; Desc: Return natural language error message
; In: A = error code
; Out: HL = address of error message string
error_str:
push bc
; Check A is a valid error code
cp error_max
jp nc,error_str_valid
xor a ; 0 = unknown error
error_str_valid:
; Load HL with address of table + (2 * A)
ld hl,error_str_table
ld b,0
ld c,a
add hl,bc ; Yes, slower than multiplying A,
add hl,bc ; but it's 16-bit safe
; Load HL with word (HL)
ld c,(hl)
inc hl
ld b,(hl)
push bc
pop hl
pop bc
ret