2003-03-14 00:02:58 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2002-12-16
|
|
|
|
;
|
|
|
|
; __sigfunc __fastcall__ signal (int sig, __sigfunc func);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.import popax
|
|
|
|
.importzp ptr1
|
2003-03-14 00:02:58 +00:00
|
|
|
|
|
|
|
.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
|
|
|
|
|
2004-12-10 11:50:54 +00:00
|
|
|
sei ; Disable interrupts in case of async signals
|
2003-03-14 00:02:58 +00:00
|
|
|
lda sigtable,x
|
|
|
|
pha
|
|
|
|
lda ptr1
|
|
|
|
sta sigtable,x
|
|
|
|
lda sigtable+1,x
|
|
|
|
pha
|
|
|
|
lda ptr1+1
|
|
|
|
sta sigtable+1,x
|
2004-12-10 11:50:54 +00:00
|
|
|
cli ; Reenable interrupts
|
2003-03-14 00:02:58 +00:00
|
|
|
|
|
|
|
; Get the old value from the stack and return it
|
|
|
|
|
|
|
|
pla
|
|
|
|
tax
|
|
|
|
pla
|
2022-08-28 18:18:34 +00:00
|
|
|
___sig_ign:
|
2003-03-14 00:02:58 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; Error entry: We use our knowledge that SIG_ERR is zero here to save a byte
|
|
|
|
|
|
|
|
invalidsig:
|
|
|
|
lda #<EINVAL
|
2022-08-28 19:52:53 +00:00
|
|
|
jsr ___seterrno ; Returns 0 in A
|
2003-03-14 00:02:58 +00:00
|
|
|
tax ; A/X = 0
|
2022-08-28 18:18:34 +00:00
|
|
|
___sig_dfl:
|
2003-03-14 00:02:58 +00:00
|
|
|
rts
|
|
|
|
|