gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 084e6d585df94f4907d8c54d2c0a75df60bbff98 parent 0985166ef3d59a7583cbfd02341d79cd467d2628 Author: Toxa <56631470+untoxa@users.noreply.github.com> Date: Wed, 17 Jan 2024 18:43:13 +0300 Merge pull request #612 from michel-iwaniec/nes_update_libc_for_sdcc_4.4.0-develop NES: Upgrade libc to latest one from sdcc 4.4.0 Diffstat:
31 files changed, 739 insertions(+), 100 deletions(-)
diff --git a/.github/workflows/gbdk_build_and_package.yml b/.github/workflows/gbdk_build_and_package.yml @@ -29,26 +29,26 @@ jobs: - name: Linux Depends if: matrix.name == 'Linux-x64' run: | - curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14228-Linux-x64.tar.gz + curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14581-Linux-x64.tar.gz tar xvfz sdcc.tar.gz - name: MacOS Depends if: matrix.name == 'MacOS-x64' run: | - curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14228-MacOS-x64.tar.gz + curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14581-MacOS-x64.tar.gz tar xvfz sdcc.tar.gz - name: Windows-x64 Depends if: matrix.name == 'Windows-x64' run: | - curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14228-Win64-On-Linux.tar.gz + curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14581-Win64-On-Linux.tar.gz 7z x sdcc.tar.gz 7z x sdcc.tar - name: Windows-x32 Depends if: matrix.name == 'Windows-x32' run: | - curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14228-Win32-On-Linux.tar.gz + curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14581-Win32-On-Linux.tar.gz 7z x sdcc.tar.gz 7z x sdcc.tar diff --git a/.github/workflows/gbdk_build_examples.yml b/.github/workflows/gbdk_build_examples.yml @@ -29,26 +29,26 @@ jobs: - name: Linux Depends if: matrix.name == 'Linux-x64' run: | - curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14228-Linux-x64.tar.gz + curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14581-Linux-x64.tar.gz tar xvfz sdcc.tar.gz - name: MacOS Depends if: matrix.name == 'MacOS-x64' run: | - curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14228-MacOS-x64.tar.gz + curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14581-MacOS-x64.tar.gz tar xvfz sdcc.tar.gz - name: Windows-x64 Depends if: matrix.name == 'Windows-x64' run: | - curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14228-Win64-On-Linux.tar.gz + curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14581-Win64-On-Linux.tar.gz 7z x sdcc.tar.gz 7z x sdcc.tar - name: Windows-x32 Depends if: matrix.name == 'Windows-x32' run: | - curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14228-Win32-On-Linux.tar.gz + curl -Lo sdcc.tar.gz https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-patched-gbdk-4.2.0-Next/sdcc-14581-Win32-On-Linux.tar.gz 7z x sdcc.tar.gz 7z x sdcc.tar diff --git a/gbdk-lib/libc/asm/mos6502/Makefile b/gbdk-lib/libc/asm/mos6502/Makefile @@ -4,14 +4,18 @@ TOPDIR = ../../.. THIS = mos6502 -ASSRC = __sdcc_indirect_jsr.s _memcpy.s _strcpy.s _strcmp.s \ +ASSRC = __sdcc_indirect_jsr.s _memcpy.s _strcpy.s _strcmp.s _memset.s \ rand.s \ - _divuint.s _divsint.s _modsint.s _moduint.s \ + _divuint.s _divsint.s _modsint.s _moduint.s _moduchar.s \ _divulong.s _divslong.s _modulong.s _modslong.s \ + _divuchar.s \ _mulint.s \ - _muluchar.s _mulschar.s + _mullong.s \ + _muluchar.s _mulschar.s \ + _setjmp.s \ + _dptr.s _ret01.s _ret23.s _ret4567.s _temp.s -CSRC = _memmove.c _memset.c _ret.c abs.c \ +CSRC = _memmove.c _memset.c abs.c \ _rrulonglong.c _rrslonglong.c \ atomic_flag_test_and_set.c \ __itoa.c _strlen.c diff --git a/gbdk-lib/libc/asm/mos6502/__sdcc_indirect_jsr.s b/gbdk-lib/libc/asm/mos6502/__sdcc_indirect_jsr.s @@ -1,3 +1,3 @@ .area _CODE __sdcc_indirect_jsr:: - jmp [__TEMP] + jmp [REGTEMP] diff --git a/gbdk-lib/libc/asm/mos6502/_divuchar.s b/gbdk-lib/libc/asm/mos6502/_divuchar.s @@ -0,0 +1,54 @@ +;------------------------------------------------------------------------- +; _divuchar.s - routine for 8 bit (unsigned char) division +; +; Copyright (C) 2023, Gabriele Gorla +; +; 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. +;------------------------------------------------------------------------- + + .module _divuchar + +;-------------------------------------------------------- +; exported symbols +;-------------------------------------------------------- + .globl __divuchar ; arguments in A and X, result in AX + +;-------------------------------------------------------- +; overlayable function parameters in zero page +;-------------------------------------------------------- + .area OSEG (PAG, OVR) + +;-------------------------------------------------------- +; local aliases +;-------------------------------------------------------- + +;-------------------------------------------------------- +; code +;-------------------------------------------------------- + .area _CODE +__divuchar: + stx *__divuint_PARM_2 + ldx #0x00 + stx *(__divuint_PARM_2 + 1) + jmp __divuint + diff --git a/gbdk-lib/libc/asm/mos6502/_divuint.s b/gbdk-lib/libc/asm/mos6502/_divuint.s @@ -40,7 +40,7 @@ .globl ___udivmod16 ;-------------------------------------------------------- -; overlayable function paramters in zero page +; overlayable function parameters in zero page ;-------------------------------------------------------- .area OSEG (PAG, OVR) __divuint_PARM_2: diff --git a/gbdk-lib/libc/asm/mos6502/_divulong.s b/gbdk-lib/libc/asm/mos6502/_divulong.s @@ -44,7 +44,7 @@ .globl ___udivmod32 ;-------------------------------------------------------- -; overlayable function paramters in zero page +; overlayable function parameters in zero page ;-------------------------------------------------------- .area OSEG (PAG, OVR) __divulong_PARM_1: diff --git a/gbdk-lib/libc/asm/mos6502/_dptr.s b/gbdk-lib/libc/asm/mos6502/_dptr.s @@ -0,0 +1,4 @@ +; data pointer used by SDCC for indirect indexed memory access + + .area _ZP (PAG) +DPTR:: .ds 2 diff --git a/gbdk-lib/libc/asm/mos6502/_memcmp.s b/gbdk-lib/libc/asm/mos6502/_memcmp.s @@ -0,0 +1,100 @@ +;------------------------------------------------------------------------- +; memcmp.s - standarc C library +; +; Copyright (C) 2003, Ullrich von Bassewitz +; Copyright (C) 2009, Christian Krueger +; Copyright (C) 2023, Gabriele Gorla +; +; 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. +;------------------------------------------------------------------------- + + .module memcmp + +;-------------------------------------------------------- +; exported symbols +;-------------------------------------------------------- + .globl _memcmp_PARM_2 + .globl _memcmp_PARM_3 + .globl _memcmp + +;-------------------------------------------------------- +; overlayable function parameters in zero page +;-------------------------------------------------------- + .area OSEG (PAG, OVR) +_memcmp_PARM_2: + .ds 2 +_memcmp_PARM_3: + .ds 2 + +;-------------------------------------------------------- +; local aliases +;-------------------------------------------------------- + .define s1 "DPTR" + .define s2 "_memcmp_PARM_2" + .define count "_memcmp_PARM_3" + +;-------------------------------------------------------- +; code +;-------------------------------------------------------- + .area _CODE + +;-------------------------------------------------------- +; int memcmp (int *s1, int *s2, int count) +;-------------------------------------------------------- + +_memcmp: + sta *s1+0 + stx *s1+1 + ldy #0 + ldx *count+1 + beq endhi +hiloop: + lda [s1],y + cmp [s2],y + bne noteq + iny + bne hiloop + inc *s1+1 + inc *s2+1 + dex + bne hiloop +endhi: + ldx *count+0 + beq end +loloop: + lda [s1],y + cmp [s2],y + bne noteq + iny + dex + bne loloop +end: + txa + rts +noteq: + bcs L2 + ldx #0xFF + rts +L2: + ldx #0x01 + rts diff --git a/gbdk-lib/libc/asm/mos6502/_memset.s b/gbdk-lib/libc/asm/mos6502/_memset.s @@ -0,0 +1,92 @@ +;------------------------------------------------------------------------- +; _memset.s - standarc C library +; +; Copyright (C) 2003, Ullrich von Bassewitz +; Copyright (C) 2009, Christian Krueger +; Copyright (C) 2023, Gabriele Gorla +; +; 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. +;------------------------------------------------------------------------- + + .module _memset + +;-------------------------------------------------------- +; exported symbols +;-------------------------------------------------------- + .globl _memset_PARM_2 + .globl _memset_PARM_3 + .globl _memset + +;-------------------------------------------------------- +; overlayable function parameters in zero page +;-------------------------------------------------------- + .area OSEG (PAG, OVR) +_memset_PARM_2: + .ds 1 +_memset_PARM_3: + .ds 2 + +;-------------------------------------------------------- +; local aliases +;-------------------------------------------------------- + .define save "REGTEMP+0" + .define dst "DPTR" + .define val "_memset_PARM_2" + .define count "_memset_PARM_3" + +;-------------------------------------------------------- +; code +;-------------------------------------------------------- + .area _CODE + +_memset: + sta *save+0 + stx *save+1 + sta *dst+0 + stx *dst+1 + + ldy #0 + lda *val + ldx *count+1 + beq 00002$ +00001$: + sta [dst],y + iny + sta [dst],y + iny + bne 00001$ + inc *dst+1 + dex + bne 00001$ +00002$: + ldx *count+0 + beq 00004$ +00003$: + sta [dst],y + iny + dex + bne 00003$ +00004$: + lda *save+0 + ldx *save+1 + rts diff --git a/gbdk-lib/libc/asm/mos6502/_moduchar.s b/gbdk-lib/libc/asm/mos6502/_moduchar.s @@ -0,0 +1,54 @@ +;------------------------------------------------------------------------- +; _moduchar.s - routine for 8 bit (unsigned char) modulo +; +; Copyright (C) 2023, Gabriele Gorla +; +; 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. +;------------------------------------------------------------------------- + + .module _moduchar + +;-------------------------------------------------------- +; exported symbols +;-------------------------------------------------------- + .globl __moduchar ; arguments in A and X, result in AX + +;-------------------------------------------------------- +; overlayable function parameters in zero page +;-------------------------------------------------------- + .area OSEG (PAG, OVR) + +;-------------------------------------------------------- +; local aliases +;-------------------------------------------------------- + +;-------------------------------------------------------- +; code +;-------------------------------------------------------- + .area _CODE +__moduchar: + stx *__moduint_PARM_2 + ldx #0x00 + stx *(__moduint_PARM_2 + 1) + jmp __moduint + diff --git a/gbdk-lib/libc/asm/mos6502/_mulint.s b/gbdk-lib/libc/asm/mos6502/_mulint.s @@ -36,7 +36,7 @@ .globl __mulint ;-------------------------------------------------------- -; overlayable function paramters in zero page +; overlayable function parameters in zero page ;-------------------------------------------------------- .area OSEG (PAG, OVR) __mulint_PARM_2: diff --git a/gbdk-lib/libc/asm/mos6502/_mullong.s b/gbdk-lib/libc/asm/mos6502/_mullong.s @@ -37,7 +37,7 @@ .globl __mullong ;-------------------------------------------------------- -; overlayable function paramters in zero page +; overlayable function parameters in zero page ;-------------------------------------------------------- .area OSEG (PAG, OVR) __mullong_PARM_1: diff --git a/gbdk-lib/libc/asm/mos6502/_mulschar.s b/gbdk-lib/libc/asm/mos6502/_mulschar.s @@ -1,8 +1,8 @@ ;------------------------------------------------------------------------- -; _mulschar.s - routine for multiplication of 16 bit (unsigned) int +; _mulschar.s - routine for multiplication of 8 bit signed char ; ; Copyright (C) 2009, Ullrich von Bassewitz -; Copyright (C) 2022, Gabriele Gorla +; Copyright (C) 2022-2023, Gabriele Gorla ; ; 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 @@ -37,7 +37,7 @@ .globl __mulsuchar ;-------------------------------------------------------- -; overlayable function paramters in zero page +; overlayable function parameters in zero page ;-------------------------------------------------------- .area OSEG (PAG, OVR) @@ -55,26 +55,26 @@ .area _CODE __mulschar: - sta s1 + sta *s1 cmp #0x00 bpl pos1 sec eor #0xff adc #0x00 pos1: - sta arg1 + sta *arg1 txa - sta s2 + sta *s2 bpl pos2 sec eor #0xff adc #0x00 pos2: - sta arg2 + sta *arg2 jsr ___umul8 - lda s1 - eor s2 + lda *s1 + eor *s2 bpl skip lda arg2 jmp ___negax @@ -83,9 +83,9 @@ skip: lda arg2 rts __muluschar: - stx __mulint_PARM_2 + stx *__mulint_PARM_2 ldx #0x00 - stx __mulint_PARM_2+1 + stx *__mulint_PARM_2+1 cmp #0x00 bpl pos1m ldx #0xff @@ -93,10 +93,10 @@ pos1m: jmp __mulint __mulsuchar: - sta __mulint_PARM_2 + sta *__mulint_PARM_2 txa ldx #0x00 - stx __mulint_PARM_2+1 + stx *__mulint_PARM_2+1 cmp #0x00 bpl pos2m ldx #0xff diff --git a/gbdk-lib/libc/asm/mos6502/_muluchar.s b/gbdk-lib/libc/asm/mos6502/_muluchar.s @@ -1,8 +1,8 @@ ;------------------------------------------------------------------------- -; _muluchar.s - routine for multiplication of 16 bit (unsigned) int +; _muluchar.s - routine for multiplication of 8 bit (unsigned char) ; ; Copyright (C) 2009, Ullrich von Bassewitz -; Copyright (C) 2022, Gabriele Gorla +; Copyright (C) 2022-2023, Gabriele Gorla ; ; 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 @@ -32,11 +32,11 @@ ;-------------------------------------------------------- ; exported symbols ;-------------------------------------------------------- - .globl __muluchar - .globl ___umul8 - + .globl __muluchar ; arguments in A and X, result in AX + .globl ___umul8 ; arguments in ret0 and ret1, result in AX + ;-------------------------------------------------------- -; overlayable function paramters in zero page +; overlayable function parameters in zero page ;-------------------------------------------------------- .area OSEG (PAG, OVR) @@ -52,20 +52,19 @@ .area _CODE __muluchar: - sta arg1 - stx arg2 + sta *arg1 + stx *arg2 ___umul8: lda #0 ; Clear byte 1 ldy #8 ; Number of bits - lsr arg2 ; Get first bit of RHS into carry + lsr *arg2 ; Get first bit of RHS into carry L0: bcc L1 clc - adc arg1 + adc *arg1 L1: ror - ror arg2 + ror *arg2 dey bne L0 - tax -;// stx arg2+1 ; Result in .XA and ptr1 - lda arg2 ; Load the result + tax ; Load the result MSB + lda *arg2 ; Load the result LSB rts ; Done diff --git a/gbdk-lib/libc/asm/mos6502/_ret.c b/gbdk-lib/libc/asm/mos6502/_ret.c @@ -1,39 +0,0 @@ -/*------------------------------------------------------------------------- - _ret.c - - Copyright (C) 2003, Erik Petrich - Copyright (C) 2012, Philipp Klaus Krause - Considering how short this file is, it is probably not copyrightable, though. - - 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. --------------------------------------------------------------------------*/ - -__data unsigned char __SDCC_m6502_ret0; -__data unsigned char __SDCC_m6502_ret1; -__data unsigned char __SDCC_m6502_ret2; -__data unsigned char __SDCC_m6502_ret3; -__data unsigned char __SDCC_m6502_ret4; -__data unsigned char __SDCC_m6502_ret5; -__data unsigned char __SDCC_m6502_ret6; -__data unsigned char __SDCC_m6502_ret7; - diff --git a/gbdk-lib/libc/asm/mos6502/_ret01.s b/gbdk-lib/libc/asm/mos6502/_ret01.s @@ -0,0 +1,10 @@ + .module _ret01 + +;-------------------------------------------------------- +; ZP ram data +;-------------------------------------------------------- + .area _ZP (PAG) +___SDCC_m6502_ret0:: + .ds 1 +___SDCC_m6502_ret1:: + .ds 1 diff --git a/gbdk-lib/libc/asm/mos6502/_ret23.s b/gbdk-lib/libc/asm/mos6502/_ret23.s @@ -0,0 +1,10 @@ + .module _ret23 + +;-------------------------------------------------------- +; ZP ram data +;-------------------------------------------------------- + .area _ZP (PAG) +___SDCC_m6502_ret2:: + .ds 1 +___SDCC_m6502_ret3:: + .ds 1 diff --git a/gbdk-lib/libc/asm/mos6502/_ret4567.s b/gbdk-lib/libc/asm/mos6502/_ret4567.s @@ -0,0 +1,14 @@ + .module _ret4567 + +;-------------------------------------------------------- +; ZP ram data +;-------------------------------------------------------- + .area _ZP (PAG) +___SDCC_m6502_ret4:: + .ds 1 +___SDCC_m6502_ret5:: + .ds 1 +___SDCC_m6502_ret6:: + .ds 1 +___SDCC_m6502_ret7:: + .ds 1 diff --git a/gbdk-lib/libc/asm/mos6502/_setjmp.s b/gbdk-lib/libc/asm/mos6502/_setjmp.s @@ -0,0 +1,115 @@ +;------------------------------------------------------------------------- +; setjmp.s - source file for ANSI routines setjmp & longjmp +; +; Copyright (C) 2020, Steven Hugg. hugg@efasterlight.com +; Copyright (C) 2023, Gabriele Gorla +; +; 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. +;------------------------------------------------------------------------- + + .module _setjmp + +;-------------------------------------------------------- +; exported symbols +;-------------------------------------------------------- + .globl ___setjmp ; + .globl _longjmp + .globl _longjmp_PARM_2 + +;-------------------------------------------------------- +; overlayable function parameters in zero page +;-------------------------------------------------------- + .area OSEG (PAG, OVR) +_longjmp_PARM_2: + .ds 2 + +;-------------------------------------------------------- +; local aliases +;-------------------------------------------------------- + .define ptr "DPTR" + .define rv "_longjmp_PARM_2" + +;-------------------------------------------------------- +; code +;-------------------------------------------------------- + .area _CODE + +;------------------------------------------------------------ +; int __setjmp (jmp_buf buf) +;------------------------------------------------------------ + +___setjmp: + stx *(ptr + 1) ; msb(buf) + sta *(ptr + 0) ; lsb(buf) + + ; save stack pointer + tsx + ldy #0 + txa + sta [ptr],y + + ; save return address + lda 0x101,x + iny + sta [ptr],y + lda 0x102,x + iny + sta [ptr],y + + ; return 0 + lda #0 + tax + rts + +;------------------------------------------------------------ +; int longjmp (jmp_buf buf, int rv) +;------------------------------------------------------------ + +_longjmp: + stx *(ptr + 1) ; msb(buf) + sta *(ptr + 0) ; lsb(buf) + + ; restore stack pointer + ldy #0 + lda [ptr],y + tax + txs + + ; set return address + iny + lda [ptr],y + sta 0x101,x + iny + lda [ptr],y + sta 0x102,x + +;_setjmp.c:224: return rv ? rv : 1; + ldx *(rv + 1) + txa + ora *(rv + 0) + beq 0001$ + lda *(rv + 0) + rts +0001$: + lda #0x01 + rts diff --git a/gbdk-lib/libc/asm/mos6502/_strcmp.s b/gbdk-lib/libc/asm/mos6502/_strcmp.s @@ -36,7 +36,7 @@ .globl _strcmp ;-------------------------------------------------------- -; overlayable function paramters in zero page +; overlayable function parameters in zero page ;-------------------------------------------------------- .area OSEG (PAG, OVR) _strcmp_PARM_2: @@ -46,7 +46,7 @@ _strcmp_PARM_2: ; local aliases ;-------------------------------------------------------- .define _str2 "_strcmp_PARM_2" - .define _str1 "___SDCC_m6502_ret0" + .define _str1 "DPTR" ;-------------------------------------------------------- ; code ;-------------------------------------------------------- @@ -58,8 +58,8 @@ _strcmp: ldy #0 loop: - lda [*_str1],y - cmp [*_str2],y + lda [_str1],y + cmp [_str2],y bne L1 tax beq end diff --git a/gbdk-lib/libc/asm/mos6502/_strcpy.s b/gbdk-lib/libc/asm/mos6502/_strcpy.s @@ -36,7 +36,7 @@ .globl _strcpy ;-------------------------------------------------------- -; overlayable function paramters in zero page +; overlayable function parameters in zero page ;-------------------------------------------------------- .area OSEG (PAG, OVR) _strcpy_PARM_2: @@ -46,7 +46,7 @@ _strcpy_PARM_2: ; local aliases ;-------------------------------------------------------- .define _src "_strcpy_PARM_2" - .define _dst "___SDCC_m6502_ret0" + .define _dst "DPTR" ;-------------------------------------------------------- ; code @@ -56,15 +56,11 @@ _strcpy_PARM_2: _strcpy: sta *_dst+0 stx *_dst+1 -;// lda _strcpy_PARM_2+0 -;// sta *_src+0 -;// ldx _strcpy_PARM_2+1 -;// stx *_src+1 ldy #0 cpy_loop: - lda [*_src],y - sta [*_dst],y + lda [_src],y + sta [_dst],y beq end iny bne cpy_loop diff --git a/gbdk-lib/libc/asm/mos6502/_strlen.s b/gbdk-lib/libc/asm/mos6502/_strlen.s @@ -0,0 +1,63 @@ +;------------------------------------------------------------------------- +; _strlen.s - standard C library function +; +; Copyright (C) 1998, Ullrich von Bassewitz +; Copyright (C) 2023, Gabriele Gorla +; +; 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. +;------------------------------------------------------------------------- + + .module _strlen + +;-------------------------------------------------------- +; exported symbols +;-------------------------------------------------------- + .globl _strlen + +;-------------------------------------------------------- +; local aliases +;-------------------------------------------------------- + .define _src "DPTR" + +;-------------------------------------------------------- +; code +;-------------------------------------------------------- + .area _CODE + +_strlen: + sta *_src+0 + stx *_src+1 + + ldy #0x00 + ldx #0x00 +loop: + lda [_src],y + beq end + iny + bne loop + inc *_src+1 + inx + bne loop +end: + tya + rts diff --git a/gbdk-lib/libc/asm/mos6502/_temp.s b/gbdk-lib/libc/asm/mos6502/_temp.s @@ -0,0 +1,5 @@ +; REGTEMP stack for temporaries used by SDCC +; Keep this in sync with NUM_TEMP_REGS in mos6502/gen.c + + .area _ZP (PAG) +REGTEMP:: .ds 8 diff --git a/gbdk-lib/libc/asm/mos6502/abs.s b/gbdk-lib/libc/asm/mos6502/abs.s @@ -0,0 +1,57 @@ +;------------------------------------------------------------------------- +; abs.s - standard C library function +; +; Copyright (C) 2023, Gabriele Gorla +; +; 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. +;------------------------------------------------------------------------- + + .module _abs + +;-------------------------------------------------------- +; exported symbols +;-------------------------------------------------------- + .globl _abs + .globl ___negax + +;-------------------------------------------------------- +; code +;-------------------------------------------------------- + + .area _CODE +_abs: + cpx #0x00 + bpl skip +___negax: + sec + eor #0xff + adc #0x00 + pha + txa + eor #0xff + adc #0x00 + tax + pla +skip: + rts + diff --git a/gbdk-lib/libc/asm/mos6502/memcpy.s b/gbdk-lib/libc/asm/mos6502/memcpy.s @@ -0,0 +1,101 @@ +;------------------------------------------------------------------------- +; memcpy.s - standarc C library +; +; Copyright (C) 2003, Ullrich von Bassewitz +; Copyright (C) 2009, Christian Krueger +; Copyright (C) 2022-2023, Gabriele Gorla +; +; 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. +;------------------------------------------------------------------------- + +; .module __memcpy + +;-------------------------------------------------------- +; exported symbols +;-------------------------------------------------------- + .globl ___memcpy_PARM_2 + .globl ___memcpy_PARM_3 + .globl ___memcpy + .globl _memcpy_PARM_2 + .globl _memcpy_PARM_3 + .globl _memcpy + +;-------------------------------------------------------- +; overlayable function parameters in zero page +;-------------------------------------------------------- + .area OSEG (PAG, OVR) +_memcpy_PARM_2: +___memcpy_PARM_2: + .ds 2 +_memcpy_PARM_3: +___memcpy_PARM_3: + .ds 2 + +;-------------------------------------------------------- +; local aliases +;-------------------------------------------------------- + .define save "REGTEMP+0" + .define dst "DPTR" + .define src "___memcpy_PARM_2" + .define count "___memcpy_PARM_3" + +;-------------------------------------------------------- +; code +;-------------------------------------------------------- + .area _CODE + +_memcpy: +___memcpy: + sta *save+0 + stx *save+1 + sta *dst+0 + stx *dst+1 + + ldy #0 + ldx *count+1 + beq 00002$ +00001$: + lda [src],y + sta [dst],y + iny + lda [src],y + sta [dst],y + iny + bne 00001$ + inc *src+1 + inc *dst+1 + dex + bne 00001$ +00002$: + ldx *count+0 + beq 00004$ +00003$: + lda [src],y + sta [dst],y + iny + dex + bne 00003$ +00004$: + lda *save+0 + ldx *save+1 + rts diff --git a/gbdk-lib/libc/asm/mos6502/rand.s b/gbdk-lib/libc/asm/mos6502/rand.s @@ -13,7 +13,7 @@ ___rand_seed:: .area _HOME -.define .tmp "__TEMP" +.define .tmp "REGTEMP" ; ; Returns an 8-bit / 16-bit rand value and updates the seed. diff --git a/gbdk-lib/libc/targets/mos6502/nes/global.s b/gbdk-lib/libc/targets/mos6502/nes/global.s @@ -110,7 +110,7 @@ ;; Global variables .globl .mode - .define .tmp "__TEMP" + .define .tmp "REGTEMP" .globl _shadow_PPUCTRL, _shadow_PPUMASK .globl _bkg_scroll_x, _bkg_scroll_y diff --git a/gbdk-lib/libc/targets/mos6502/nes/sdcc_bcall.s b/gbdk-lib/libc/targets/mos6502/nes/sdcc_bcall.s @@ -1,7 +1,7 @@ .include "global.s" .include "mapper_macros.s" -.define .tempA "(__TEMP+7)" +.define .tempA "(REGTEMP+7)" ; ; Banked call support function. diff --git a/gbdk-lib/libc/targets/mos6502/nes/set_bk_attributes.s b/gbdk-lib/libc/targets/mos6502/nes/set_bk_attributes.s @@ -299,7 +299,7 @@ unaligned_x_column_loop: lbl: .endm unaligned_y: -.define pRow "__TEMP" +.define pRow "REGTEMP" ; Round num_rows lda *.attribute_num_rows_odd bpl 9$ diff --git a/gbdk-lib/libc/targets/mos6502/nes/vram_transfer_buffer.s b/gbdk-lib/libc/targets/mos6502/nes/vram_transfer_buffer.s @@ -48,7 +48,7 @@ __vram_transfer_buffer_num_cycles_x8:: .ds 1 __vram_transfer_buffer_pos_w:: .ds 1 __vram_transfer_buffer_pos_old:: .ds 1 -.define __vram_transfer_buffer_temp "(__TEMP+6)" +.define __vram_transfer_buffer_temp "(REGTEMP+6)" .area _HOME
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.