]> git.sur5r.net Git - cc65/blob - libsrc/common/stroserr.s
Changes due to code review.
[cc65] / libsrc / common / stroserr.s
1 ;
2 ; Ullrich von Bassewitz, 17.07.2002
3 ;
4 ; const char* __fastcall__ _stroserror (unsigned char errcode);
5 ; /* Map an operating system error number to an error message. */
6 ;
7
8         .export         __stroserror
9         .import         __sys_oserrlist
10         .importzp       ptr1, tmp1
11
12         .macpack        generic
13
14
15 ; The table is built as a list of entries
16 ;
17 ;       .byte   entrylen
18 ;       .byte   errorcode
19 ;       .asciiz errormsg
20 ;
21 ; and terminated by an entry with length zero that is returned if the
22 ; error code could not be found.
23
24 __stroserror:
25         sta     tmp1                    ; Save the error code
26
27         ldy     #<__sys_oserrlist
28         sty     ptr1
29         ldy     #>__sys_oserrlist
30         sty     ptr1+1                  ; Setup pointer to message table
31
32 @L1:    ldy     #0
33         lda     (ptr1),y                ; Get the length
34         beq     Done                    ; Bail out if end of list reached
35
36         iny
37         lda     (ptr1),y                ; Compare the error code
38         cmp     tmp1
39         beq     Done                    ; Jump if found
40
41 ; Not found, move pointer to next entry
42
43         dey
44         clc
45         lda     ptr1
46         adc     (ptr1),y
47         sta     ptr1
48         bcc     @L1
49         inc     ptr1+1
50         bcs     @L1                     ; Branch always
51
52 ; We've found the code or reached the end of the list
53
54 Done:   ldx     ptr1+1
55         lda     ptr1
56         add     #2                      ; Add a total of #2
57         bcc     @L1
58         inx                             ; Bump high byte
59 @L1:    rts
60
61