2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 03.06.1998
|
|
|
|
;
|
2013-05-09 11:56:54 +00:00
|
|
|
; int stricmp (const char* s1, const char* s2); /* DOS way */
|
|
|
|
; int strcasecmp (const char* s1, const char* s2); /* UNIX way */
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _stricmp, _strcasecmp
|
|
|
|
.import popax
|
|
|
|
.import __ctype
|
|
|
|
.importzp ptr1, ptr2, tmp1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2009-02-10 22:11:56 +00:00
|
|
|
.include "ctype.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
_stricmp:
|
|
|
|
_strcasecmp:
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr2 ; Save s2
|
|
|
|
stx ptr2+1
|
|
|
|
jsr popax ; get s1
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
ldy #0
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
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
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
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
|
2009-02-10 22:11:56 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
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
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
L3: bcs L4
|
|
|
|
ldx #$FF
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
L4: ldx #$01
|
|
|
|
L5: rts
|