]> git.sur5r.net Git - cc65/blob - libsrc/common/longjmp.s
Fixed a bug
[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         jsr     popax           ; get buf
15         sta     ptr1
16         stx     ptr1+1
17         ldy     #0
18            
19 ; Get the old parameter stack
20
21         lda     (ptr1),y
22         iny
23         sta     sp
24         lda     (ptr1),y
25         iny
26         sta     sp+1
27
28 ; Get the old stack pointer
29
30         lda     (ptr1),y
31         iny
32         tax
33         txs
34
35 ; Get the return address and push it on the stack
36
37         lda     (ptr1),y
38         iny
39         pha
40         lda     (ptr1),y
41         pha
42
43 ; Load the return value and return to the caller
44
45         lda     ptr2
46         ldx     ptr2+1
47         rts
48