1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-19 06:31:31 +00:00
cc65/libsrc/common/stricmp.s

64 lines
2.1 KiB
ArmAsm
Raw Normal View History

2020-01-02 17:57:03 +00:00
; stricmp.s
;
2020-01-02 17:57:03 +00:00
; This file is part of
; cc65 - a freeware C compiler for 6502 based systems
;
; https://github.com/cc65/cc65
;
; See "LICENSE" file for legal information.
;
; 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
2020-01-02 17:57:03 +00:00
.importzp ptr1, ptr2, tmp1, tmp2
.import ctype_preprocessor_no_check
.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
2020-01-02 17:57:03 +00:00
sta tmp2 ; and save it
; get character classification
jsr ctype_preprocessor_no_check
and #CT_LOWER ; lower case char?
beq L1 ; jump if no
2020-01-02 17:57:03 +00:00
lda #<('A'-'a') ; make upper case char
adc tmp2 ; ctype_preprocessor_no_check ensures carry clear!
sta tmp2 ; remember upper case equivalent
2020-01-02 17:57:03 +00:00
L1: lda (ptr1),y ; get character from first string
sta tmp1
; get character classification
jsr ctype_preprocessor_no_check
and #CT_LOWER ; lower case char?
beq L2 ; jump if no
2020-01-02 17:57:03 +00:00
lda #<('A'-'a') ; make upper case char
adc tmp1 ; ctype_preprocessor_no_check ensures carry clear!
sta tmp1 ; remember upper case equivalent
2020-01-02 17:57:03 +00:00
L2: ldx tmp1
cpx tmp2 ; 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