]> git.sur5r.net Git - cc65/blob - libsrc/common/signal.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / common / signal.s
1 ;
2 ; Ullrich von Bassewitz, 2002-12-16
3 ;
4 ; __sigfunc __fastcall__ signal (int sig, __sigfunc func);
5 ;
6
7         .import         popax
8         .importzp       ptr1
9
10         .include        "signal.inc"
11         .include        "errno.inc"
12
13
14 ; Default signal functions: The standard specifies explicitly that the values
15 ; for SIG_IGN and SIG_DFL must be distinct, so we make them so by using both
16 ; rts exits we have. This works because signal functions are __fastcall__, so
17 ; we don't have arguments on the stack.
18
19
20 ;----------------------------------------------------------------------------
21 ; __sigfunc __fastcall__ signal (int sig, __sigfunc func);
22
23
24 _signal:
25         sta     ptr1
26         stx     ptr1+1          ; Remember func
27
28         jsr     popax           ; Get sig
29
30         cpx     #0
31         bne     invalidsig
32         cmp     #SIGCOUNT
33         bcs     invalidsig
34
35 ; Signal number is valid. Replace the pointer in the table saving the old
36 ; value temporarily on the stack.
37
38         asl     a               ; Prepare for word access
39         tax
40
41         sei                     ; Disable interrupts in case of async signals
42         lda     sigtable,x
43         pha
44         lda     ptr1
45         sta     sigtable,x
46         lda     sigtable+1,x
47         pha
48         lda     ptr1+1
49         sta     sigtable+1,x
50         cli                     ; Reenable interrupts
51
52 ; Get the old value from the stack and return it
53
54         pla
55         tax
56         pla
57 __sig_ign:
58         rts
59
60 ; Error entry: We use our knowledge that SIG_ERR is zero here to save a byte
61
62 invalidsig:
63         lda     #<EINVAL
64         jsr     __seterrno      ; Returns 0 in A
65         tax                     ; A/X = 0
66 __sig_dfl:
67         rts
68