gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit ae0adcb6336edaa3abe2f93b140e2fbfe0df1bac parent ec77ec5c3e414c4600dd8d22daab9423ddff326d Author: Toxa <untoxa@mail.ru> Date: Tue, 7 May 2024 18:05:23 +0300 Z80/SM83: convert abs() to the new calling convention; use REENTRANT macro in stdlib.h Diffstat:
| M | gbdk-lib/include/stdlib.h | 10 | +++------- |
| M | gbdk-lib/libc/asm/sm83/abs.s | 25 | ++++++++++++------------- |
| M | gbdk-lib/libc/asm/z80/abs.s | 68 | +++++++++++--------------------------------------------------------- |
3 files changed, 26 insertions(+), 77 deletions(-)
diff --git a/gbdk-lib/include/stdlib.h b/gbdk-lib/include/stdlib.h @@ -6,10 +6,6 @@ #include <types.h> -#if !defined(__SDCC_mcs51) && !defined(__SDCC_ds390) && !defined(__SDCC_ds400) && !defined(__SDCC_hc08) && !defined(__SDCC_s08) && !defined(__SDCC_mos6502) && !defined(__SDCC_mos65c02) && !defined(__SDCC_pic14) && !defined(__SDCC_pic16) && !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) -#define __reentrant -#endif - /** Causes normal program termination and the value of status is returned to the parent. All open streams are flushed and closed. @@ -27,7 +23,7 @@ int getkey(void) OLDCALL; If i is negative, returns -i; else returns i. */ -int abs(int i) OLDCALL; +int abs(int i); /** Returns the absolute value of long int __num__ @@ -141,7 +137,7 @@ extern void free (void * ptr); Returns: Pointer to array entry that matches the search key. If key is not found, NULL is returned. */ -extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *) __reentrant); +extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *) REENTRANT); /** Sort an array of __nmemb__ items @@ -150,6 +146,6 @@ extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t siz @param size Size in bytes of each element in the array @param compar Function used to compare and sort two elements of the array */ -extern void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *) __reentrant); +extern void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *) REENTRANT); #endif diff --git a/gbdk-lib/libc/asm/sm83/abs.s b/gbdk-lib/libc/asm/sm83/abs.s @@ -4,16 +4,15 @@ ; int abs(int) _abs:: - lda HL, 3(SP) ; 3 - ld A,(HL-) ; 2 Load high byte. - ld D,A ; 1 - ld E,(HL) ; 2 Load low byte - add A,A ; 1 Sign check. - ret nc ; 5/2 Return if positive. - xor A ; 1 A=0. - sub E ; 1 Calculate 0-(low byte). - ld E,A ; 1 - ld A,#0 ; 2 A=0. Can't use xor A because carry flag needs to be preserved. - sbc D ; 1 Calculate 0-(high byte)-carry. - ld D,A ; 1 - ret ; 4 + ld a, d + ld b, a + ld c, e + add a + ret nc + xor a + sub c + ld c, a + ld a, #0 + sbc b + ld b, a + ret diff --git a/gbdk-lib/libc/asm/z80/abs.s b/gbdk-lib/libc/asm/z80/abs.s @@ -1,61 +1,15 @@ -;-------------------------------------------------------------------------- -; abs.s -; -; Copyright (C) 2010, Philipp Klaus Krause -; -; This library is free software; you can redistribute it and/or modify it -; under the terms of the GNU General Public License as published by the -; Free Software Foundation; either version 2, or (at your option) any -; later version. -; -; This library is distributed in the hope that it will be useful, -; but WITHOUT ANY WARRANTY; without even the implied warranty of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; GNU General Public License for more details. -; -; You should have received a copy of the GNU General Public License -; along with this library; see the file COPYING. If not, write to the -; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, -; MA 02110-1301, USA. -; -; As a special exception, if you link this library with other files, -; some of which are compiled with SDCC, to produce an executable, -; this library does not by itself cause the resulting executable to -; be covered by the GNU General Public License. This exception does -; not however invalidate any other reasons why the executable file -; might be covered by the GNU General Public License. -;-------------------------------------------------------------------------- + .area _CODE - .area _CODE + .globl _abs - .globl _abs - -; 12B; 86T for nonnegative arguments, 78T for negative. _abs: - pop hl - pop de - push de - push hl - xor a, a - ld l, a - ld h, a - sbc hl, de - ret P - ex de, hl - ret - -; 14B; 59T for nonegative arguments, 94T for negative: -;_abs: -; pop de -; pop hl -; push hl -; push de -; bit 7, h -; ret Z -; xor a, a -; ld e, a -; ld d, a -; ex de, hl -; sbc hl, de -; ret + xor a + ex de, hl + ld h, a + ld l, a + sbc hl, de + ex de, hl + ret p + ex de, hl + ret
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.