2000-05-28 13:40:48 +00:00
|
|
|
;
|
2015-09-11 18:18:22 +00:00
|
|
|
; 1998-06-06, Ullrich von Bassewitz
|
|
|
|
; 2015-09-11, Greg King
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
2015-09-11 18:18:22 +00:00
|
|
|
; void __fastcall__ longjmp (jmp_buf buf, int retval);
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _longjmp
|
|
|
|
.import popax
|
|
|
|
.importzp sp, ptr1, ptr2
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
_longjmp:
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr2 ; Save retval
|
|
|
|
stx ptr2+1
|
|
|
|
ora ptr2+1 ; Check for 0
|
|
|
|
bne @L1
|
2015-09-11 18:18:22 +00:00
|
|
|
inc ptr2 ; 0 is illegal, according to the standard ...
|
|
|
|
; ... and, must be replaced by 1
|
2013-05-09 11:56:54 +00:00
|
|
|
@L1: jsr popax ; get buf
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
ldy #0
|
2000-07-22 18:26:31 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; Get the old parameter stack
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
iny
|
|
|
|
sta sp
|
|
|
|
lda (ptr1),y
|
|
|
|
iny
|
|
|
|
sta sp+1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Get the old stack pointer
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
iny
|
|
|
|
tax
|
|
|
|
txs
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Get the return address and push it on the stack
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
iny
|
|
|
|
pha
|
|
|
|
lda (ptr1),y
|
|
|
|
pha
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Load the return value and return to the caller
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda ptr2
|
|
|
|
ldx ptr2+1
|
|
|
|
rts
|