1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 07:29:33 +00:00
cc65/libsrc/common/stricmp.s

59 lines
1.7 KiB
ArmAsm

;
; Ullrich von Bassewitz, 03.06.1998
;
; int stricmp (const char* s1, const char* s2); /* DOS way */
; int strcasecmp (const char* s1, const char* s2); /* UNIX way */
;
.export _stricmp, _strcasecmp
.import popptr1
.import __ctype
.importzp ptr1, ptr2, tmp1
.include "ctype.inc"
_stricmp:
_strcasecmp:
sta ptr2 ; Save s2
stx ptr2+1
jsr popptr1 ; get s1
; ldy #0 ; Y=0 guaranteed by popptr1
loop: lda (ptr2),y ; get char from second string
tax
lda __ctype,x ; get character classification
and #CT_LOWER ; lower case char?
beq L1 ; jump if no
txa ; get character back
clc
adc #<('A'-'a') ; make upper case char
tax ;
L1: stx tmp1 ; remember upper case equivalent
lda (ptr1),y ; get character from first string
tax
lda __ctype,x ; get character classification
and #CT_LOWER ; lower case char?
beq L2 ; jump if no
txa ; get character back
clc
adc #<('A'-'a') ; make upper case char
tax
L2: cpx tmp1 ; compare characters
bne L3
txa ; end of strings?
beq L5 ; a/x both zero
iny
bne loop
inc ptr1+1
inc ptr2+1
bne loop
L3: bcs L4
ldx #$FF
rts
L4: ldx #$01
L5: rts