2 ; Christian Groessler, 10.02.2009
3 ; derived from strncmp.s and stricmp.s
5 ; int __fastcall__ strnicmp (const char* s1, const char* s2, size_t count);
6 ; int __fastcall__ strncasecmp (const char* s1, const char* s2, size_t count);
9 .export _strnicmp, _strncasecmp
10 .import popax, __ctype
11 .importzp ptr1, ptr2, ptr3, tmp1
18 ; Convert the given counter value in a/x from a downward counter into an
19 ; upward counter, so we can increment the counter in the loop below instead
20 ; of decrementing it. This adds some overhead now, but is cheaper than
21 ; executing a more complex test in each iteration of the loop. We do also
22 ; correct the value by one, so we can do the test on top of the loop.
30 ; Get the remaining arguments
43 ; Start of compare loop. Check the counter.
46 beq IncHi ; Increment high byte
48 ; Compare a byte from the strings
52 lda __ctype,x ; get character classification
53 and #CT_LOWER ; lower case char?
55 txa ; get character back
57 sbc #<('a'-'A') ; make upper case char
59 L1: stx tmp1 ; remember upper case equivalent
61 lda (ptr1),y ; get character from first string
63 lda __ctype,x ; get character classification
64 and #CT_LOWER ; lower case char?
66 txa ; get character back
68 sbc #<('a'-'A') ; make upper case char
71 L2: cpx tmp1 ; compare characters
72 bne NotEqual ; Jump if strings different
74 beq Equal1 ; Jump if EOS reached, a/x == 0
76 ; Increment the pointers
82 bne Loop ; Branch always
87 bne Comp ; Jump if counter not zero
89 ; Exit code if strings are equal. a/x not set
95 ; Exit code if strings not equal
99 ldx #$FF ; Make result negative
102 L3: ldx #$01 ; Make result positive