]> git.sur5r.net Git - cc65/blob - libsrc/common/longjmp.s
Added an IRQ vector
[cc65] / libsrc / common / longjmp.s
1 ;
2 ; Ullrich von Bassewitz, 06.06.1998
3 ;
4 ; void longjmp (jmp_buf buf, int retval);
5 ;
6
7         .export         _longjmp
8         .import         popax
9         .importzp       sp, ptr1, ptr2
10
11 _longjmp:
12         sta     ptr2            ; Save retval
13         stx     ptr2+1
14         ora     ptr2+1          ; Check for 0
15         bne     @L1
16         lda     #1              ; 0 is illegal according to the standard...
17         sta     ptr2            ; ... and must be replaced by 1
18 @L1:    jsr     popax           ; get buf
19         sta     ptr1
20         stx     ptr1+1
21         ldy     #0
22
23 ; Get the old parameter stack
24
25         lda     (ptr1),y
26         iny
27         sta     sp
28         lda     (ptr1),y
29         iny
30         sta     sp+1
31
32 ; Get the old stack pointer
33
34         lda     (ptr1),y
35         iny
36         tax
37         txs
38
39 ; Get the return address and push it on the stack
40
41         lda     (ptr1),y
42         iny
43         pha
44         lda     (ptr1),y
45         pha
46
47 ; Load the return value and return to the caller
48
49         lda     ptr2
50         ldx     ptr2+1
51         rts
52