2020-01-02 17:57:03 +00:00
|
|
|
; stricmp.s
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
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.
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
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
|
2018-05-20 13:30:18 +00:00
|
|
|
.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
|
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
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1 ; get s1
|
|
|
|
; ldy #0 ; Y=0 guaranteed by popptr1
|
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
|
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
|
2013-05-09 11:56:54 +00:00
|
|
|
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
|
2000-05-28 13:40:48 +00:00
|
|
|
|
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
|
2013-05-09 11:56:54 +00:00
|
|
|
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
|
2013-05-09 11:56:54 +00:00
|
|
|
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
|