File: stroserr.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (61 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download | duplicates (3)
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
54
55
56
57
58
59
60
61
;
; Ullrich von Bassewitz, 17.07.2002
;
; const char* __fastcall__ _stroserror (unsigned char errcode);
; /* Map an operating system error number to an error message. */
;

        .export         __stroserror
        .import         __sys_oserrlist
        .importzp       ptr1, tmp1

        .macpack        generic


; The table is built as a list of entries
;
;       .byte   entrylen
;       .byte   errorcode
;       .asciiz errormsg
;
; and terminated by an entry with length zero that is returned if the
; error code could not be found.

__stroserror:
        sta     tmp1                    ; Save the error code

        ldy     #<__sys_oserrlist
        sty     ptr1
        ldy     #>__sys_oserrlist
        sty     ptr1+1                  ; Setup pointer to message table

@L1:    ldy     #0
        lda     (ptr1),y                ; Get the length
        beq     Done                    ; Bail out if end of list reached

        iny
        lda     (ptr1),y                ; Compare the error code
        cmp     tmp1
        beq     Done                    ; Jump if found

; Not found, move pointer to next entry

        dey
        clc
        lda     ptr1
        adc     (ptr1),y
        sta     ptr1
        bcc     @L1
        inc     ptr1+1
        bcs     @L1                     ; Branch always

; We've found the code or reached the end of the list

Done:   ldx     ptr1+1
        lda     ptr1
        add     #2                      ; Add a total of #2
        bcc     @L1
        inx                             ; Bump high byte
@L1:    rts