2009-02-10 19:15:21 +00:00
|
|
|
;
|
|
|
|
; Christian Groessler, 10.02.2009
|
|
|
|
; derived from strncmp.s and stricmp.s
|
|
|
|
;
|
|
|
|
; int __fastcall__ strnicmp (const char* s1, const char* s2, size_t count);
|
|
|
|
; int __fastcall__ strncasecmp (const char* s1, const char* s2, size_t count);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _strnicmp, _strncasecmp
|
2020-01-02 17:57:03 +00:00
|
|
|
.import popax, popptr1
|
|
|
|
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
|
2020-04-02 20:58:16 +00:00
|
|
|
.import ctypemaskdirect
|
2009-02-10 22:11:56 +00:00
|
|
|
.include "ctype.inc"
|
2009-02-10 19:15:21 +00:00
|
|
|
|
|
|
|
_strnicmp:
|
|
|
|
_strncasecmp:
|
|
|
|
|
2020-11-01 21:59:07 +00:00
|
|
|
inx
|
|
|
|
stx ptr3+1
|
|
|
|
tax
|
|
|
|
inx
|
|
|
|
stx ptr3 ; save count with each byte incremented separately
|
2009-02-10 19:15:21 +00:00
|
|
|
|
|
|
|
; Get the remaining arguments
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr popax ; get s2
|
|
|
|
sta ptr2
|
|
|
|
stx ptr2+1
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1 ; get s1
|
2009-02-10 19:15:21 +00:00
|
|
|
|
|
|
|
; Loop setup
|
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
; ldy #0 Y=0 guaranteed by popptr1
|
2009-02-10 19:15:21 +00:00
|
|
|
|
|
|
|
; Start of compare loop. Check the counter.
|
|
|
|
|
2020-11-03 10:54:50 +00:00
|
|
|
Loop: dec ptr3 ; decrement high byte
|
|
|
|
beq IncHi
|
2009-02-10 19:15:21 +00:00
|
|
|
|
|
|
|
; Compare a byte from the strings
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
Comp: lda (ptr2),y
|
2020-01-02 17:57:03 +00:00
|
|
|
sta tmp2 ; remember original char
|
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
|
|
|
|
|
|
|
|
L1: lda (ptr1),y ; get character from first string
|
|
|
|
sta tmp1 ; remember original char
|
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-04-02 08:03:01 +00:00
|
|
|
sta tmp1 ; remember upper case equivalent
|
2013-05-09 11:56:54 +00:00
|
|
|
|
2020-01-02 17:57:03 +00:00
|
|
|
L2: ldx tmp1
|
|
|
|
cpx tmp2 ; compare characters
|
2020-04-02 08:03:01 +00:00
|
|
|
bne NotEqual ; jump if strings different
|
|
|
|
txa ; end of strings?
|
|
|
|
beq Equal1 ; jump if EOS reached, a/x == 0
|
2009-02-10 19:15:21 +00:00
|
|
|
|
|
|
|
; Increment the pointers
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
iny
|
|
|
|
bne Loop
|
|
|
|
inc ptr1+1
|
|
|
|
inc ptr2+1
|
2020-04-02 08:03:01 +00:00
|
|
|
bne Loop ; branch always
|
2009-02-10 19:15:21 +00:00
|
|
|
|
|
|
|
; Increment hi byte
|
|
|
|
|
2020-11-01 21:59:07 +00:00
|
|
|
IncHi: dec ptr3+1
|
2020-04-02 08:03:01 +00:00
|
|
|
bne Comp ; jump if counter not zero
|
2009-02-10 19:15:21 +00:00
|
|
|
|
|
|
|
; Exit code if strings are equal. a/x not set
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
Equal: lda #$00
|
|
|
|
tax
|
|
|
|
Equal1: rts
|
2009-02-10 19:15:21 +00:00
|
|
|
|
|
|
|
; Exit code if strings not equal
|
|
|
|
|
|
|
|
NotEqual:
|
2013-05-09 11:56:54 +00:00
|
|
|
bcs L3
|
2020-04-02 08:03:01 +00:00
|
|
|
ldx #$FF ; make result negative
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2009-02-10 19:15:21 +00:00
|
|
|
|
2020-04-02 08:03:01 +00:00
|
|
|
L3: ldx #$01 ; make result positive
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|