1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-26 08:32:00 +00:00
cc65/libsrc/common/stricmp.s

62 lines
1.9 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
;
2020-02-02 17:21:25 +00:00
; https://cc65.github.io
2020-01-02 17:57:03 +00:00
;
; 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
2020-04-02 20:58:16 +00:00
.import ctypemaskdirect
.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
2020-04-02 20:58:16 +00:00
jsr ctypemaskdirect ; get character classification
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
2020-04-02 20:58:16 +00:00
adc tmp2 ; ctypemaskdirect ensures carry clear!
2020-01-02 17:57:03 +00:00
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
2020-04-02 20:58:16 +00:00
jsr ctypemaskdirect ; get character classification
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
2020-04-02 20:58:16 +00:00
adc tmp1 ; ctypemaskdirect ensures carry clear!
2020-02-02 17:21:25 +00:00
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