]> git.sur5r.net Git - cc65/blob - libsrc/common/signal.s
removed some duplicated GEOS conio stuff
[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         lda     sigtable,x
42         pha
43         lda     ptr1
44         sta     sigtable,x
45         lda     sigtable+1,x
46         pha
47         lda     ptr1+1
48         sta     sigtable+1,x
49
50 ; Get the old value from the stack and return it
51
52         pla
53         tax
54         pla
55 __sig_ign:
56         rts
57
58 ; Error entry: We use our knowledge that SIG_ERR is zero here to save a byte
59
60 invalidsig:
61         lda     #<EINVAL
62         sta     __errno
63         lda     #>EINVAL        ; A = 0
64         sta     __errno+1
65         tax                     ; A/X = 0
66 __sig_dfl:
67         rts
68