git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/libc/asm/mos6502/_setjmp.s

      1 ;-------------------------------------------------------------------------
      2 ;   setjmp.s - source file for ANSI routines setjmp & longjmp
      3 ;
      4 ;   Copyright (C) 2020, Steven Hugg. hugg@efasterlight.com
      5 ;   Copyright (C) 2023, Gabriele Gorla
      6 ;
      7 ;   This library is free software; you can redistribute it and/or modify it
      8 ;   under the terms of the GNU General Public License as published by the
      9 ;   Free Software Foundation; either version 2, or (at your option) any
     10 ;   later version.
     11 ;
     12 ;   This library is distributed in the hope that it will be useful,
     13 ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 ;   GNU General Public License for more details.
     16 ;
     17 ;   You should have received a copy of the GNU General Public License
     18 ;   along with this library; see the file COPYING. If not, write to the
     19 ;   Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
     20 ;   MA 02110-1301, USA.
     21 ;
     22 ;   As a special exception, if you link this library with other files,
     23 ;   some of which are compiled with SDCC, to produce an executable,
     24 ;   this library does not by itself cause the resulting executable to
     25 ;   be covered by the GNU General Public License. This exception does
     26 ;   not however invalidate any other reasons why the executable file
     27 ;   might be covered by the GNU General Public License.
     28 ;-------------------------------------------------------------------------
     29 
     30 	.module _setjmp
     31 
     32 ;--------------------------------------------------------
     33 ; exported symbols
     34 ;--------------------------------------------------------
     35 	.globl ___setjmp    ; 
     36         .globl _longjmp
     37         .globl _longjmp_PARM_2
     38 	
     39 ;--------------------------------------------------------
     40 ; overlayable function parameters in zero page
     41 ;--------------------------------------------------------
     42 	.area	OSEG    (PAG, OVR)
     43 _longjmp_PARM_2:
     44         .ds 2
     45 
     46 ;--------------------------------------------------------
     47 ; local aliases
     48 ;--------------------------------------------------------
     49 	.define ptr "DPTR"
     50 	.define rv "_longjmp_PARM_2"
     51 
     52 ;--------------------------------------------------------
     53 ; code
     54 ;--------------------------------------------------------
     55         .area _CODE
     56 
     57 ;------------------------------------------------------------
     58 ; int __setjmp (jmp_buf buf)
     59 ;------------------------------------------------------------
     60 
     61 ___setjmp:
     62         stx	*(ptr + 1)		; msb(buf)
     63         sta	*(ptr + 0)		; lsb(buf)
     64 
     65         ; save stack pointer
     66         tsx
     67         ldy	#0
     68         txa
     69         sta	[ptr],y
     70 
     71         ; save return address
     72         lda	0x101,x
     73         iny
     74         sta	[ptr],y
     75         lda	0x102,x
     76         iny
     77         sta	[ptr],y
     78 
     79         ; return 0
     80         lda	#0
     81         tax
     82         rts
     83 
     84 ;------------------------------------------------------------
     85 ; int longjmp (jmp_buf buf, int rv)
     86 ;------------------------------------------------------------
     87 
     88 _longjmp:
     89         stx	*(ptr + 1)		; msb(buf)
     90         sta	*(ptr + 0)		; lsb(buf)
     91 
     92         ; restore stack pointer
     93         ldy	#0
     94         lda	[ptr],y
     95         tax
     96         txs
     97 
     98         ; set return address
     99         iny
    100         lda	[ptr],y
    101         sta	0x101,x
    102         iny
    103         lda	[ptr],y
    104         sta	0x102,x
    105 
    106 ;_setjmp.c:224: return rv ? rv : 1;
    107         ldx    *(rv + 1)
    108         txa
    109         ora    *(rv + 0)
    110         beq     0001$
    111         lda    *(rv + 0)
    112         rts
    113 0001$:
    114         lda     #0x01
    115         rts

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.