File: signal.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 (68 lines) | stat: -rw-r--r-- 1,706 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
62
63
64
65
66
67
68
;
; Ullrich von Bassewitz, 2002-12-16
;
; __sigfunc __fastcall__ signal (int sig, __sigfunc func);
;

        .import         popax
        .importzp       ptr1

        .include        "signal.inc"
        .include        "errno.inc"


; Default signal functions: The standard specifies explicitly that the values
; for SIG_IGN and SIG_DFL must be distinct, so we make them so by using both
; rts exits we have. This works because signal functions are __fastcall__, so
; we don't have arguments on the stack.


;----------------------------------------------------------------------------
; __sigfunc __fastcall__ signal (int sig, __sigfunc func);


_signal:
        sta     ptr1
        stx     ptr1+1          ; Remember func

        jsr     popax           ; Get sig

        cpx     #0
        bne     invalidsig
        cmp     #SIGCOUNT
        bcs     invalidsig

; Signal number is valid. Replace the pointer in the table saving the old
; value temporarily on the stack.

        asl     a               ; Prepare for word access
        tax

        sei                     ; Disable interrupts in case of async signals
        lda     sigtable,x
        pha
        lda     ptr1
        sta     sigtable,x
        lda     sigtable+1,x
        pha
        lda     ptr1+1
        sta     sigtable+1,x
        cli                     ; Reenable interrupts

; Get the old value from the stack and return it

        pla
        tax
        pla
__sig_ign:
        rts

; Error entry: We use our knowledge that SIG_ERR is zero here to save a byte

invalidsig:
        lda     #<EINVAL
        jsr     __seterrno      ; Returns 0 in A
        tax                     ; A/X = 0
__sig_dfl:
        rts