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/_memcmp.s

      1 ;-------------------------------------------------------------------------
      2 ;   memcmp.s - standarc C library
      3 ;
      4 ;   Copyright (C) 2003, Ullrich von Bassewitz
      5 ;   Copyright (C) 2009, Christian Krueger
      6 ;   Copyright (C) 2023, Gabriele Gorla
      7 ;
      8 ;   This library is free software; you can redistribute it and/or modify it
      9 ;   under the terms of the GNU General Public License as published by the
     10 ;   Free Software Foundation; either version 2, or (at your option) any
     11 ;   later version.
     12 ;
     13 ;   This library is distributed in the hope that it will be useful,
     14 ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 ;   GNU General Public License for more details.
     17 ;
     18 ;   You should have received a copy of the GNU General Public License
     19 ;   along with this library; see the file COPYING. If not, write to the
     20 ;   Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
     21 ;   MA 02110-1301, USA.
     22 ;
     23 ;   As a special exception, if you link this library with other files,
     24 ;   some of which are compiled with SDCC, to produce an executable,
     25 ;   this library does not by itself cause the resulting executable to
     26 ;   be covered by the GNU General Public License. This exception does
     27 ;   not however invalidate any other reasons why the executable file
     28 ;   might be covered by the GNU General Public License.
     29 ;-------------------------------------------------------------------------
     30 
     31 	.module memcmp
     32 
     33 ;--------------------------------------------------------
     34 ; exported symbols
     35 ;--------------------------------------------------------
     36 	.globl _memcmp_PARM_2
     37 	.globl _memcmp_PARM_3
     38 	.globl _memcmp
     39 
     40 ;--------------------------------------------------------
     41 ; overlayable function parameters in zero page
     42 ;--------------------------------------------------------
     43 	.area	OSEG    (PAG, OVR)
     44 _memcmp_PARM_2:
     45 	.ds 2
     46 _memcmp_PARM_3:
     47 	.ds 2
     48 
     49 ;--------------------------------------------------------
     50 ; local aliases
     51 ;--------------------------------------------------------
     52 	.define s1    "DPTR"
     53 	.define s2    "_memcmp_PARM_2"
     54 	.define count "_memcmp_PARM_3"
     55 
     56 ;--------------------------------------------------------
     57 ; code
     58 ;--------------------------------------------------------
     59 	.area _CODE
     60 	
     61 ;--------------------------------------------------------
     62 ; int memcmp (int *s1, int *s2, int count)
     63 ;--------------------------------------------------------
     64 
     65 _memcmp:
     66 	sta	*s1+0
     67 	stx	*s1+1
     68 	ldy	#0
     69 	ldx	*count+1
     70 	beq	endhi
     71 hiloop:
     72 	lda	[s1],y
     73 	cmp	[s2],y
     74 	bne	noteq
     75 	iny
     76 	bne	hiloop
     77 	inc	*s1+1
     78 	inc	*s2+1
     79 	dex
     80 	bne	hiloop
     81 endhi:
     82 	ldx	*count+0
     83 	beq	end
     84 loloop:
     85 	lda	[s1],y
     86 	cmp	[s2],y
     87 	bne	noteq
     88 	iny
     89 	dex
     90 	bne	loloop
     91 end:
     92 	txa
     93 	rts
     94 noteq:
     95 	bcs	L2
     96 	ldx	#0xFF
     97 	rts
     98 L2:
     99 	ldx	#0x01
    100 	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.