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, popptr1, __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
39 ; ldy #0 Y=0 guaranteed by popptr1
41 ; Start of compare loop. Check the counter.
44 beq IncHi ; Increment high byte
46 ; Compare a byte from the strings
50 lda __ctype,x ; get character classification
51 and #CT_LOWER ; lower case char?
53 txa ; get character back
55 sbc #<('a'-'A') ; make upper case char
57 L1: stx tmp1 ; remember upper case equivalent
59 lda (ptr1),y ; get character from first string
61 lda __ctype,x ; get character classification
62 and #CT_LOWER ; lower case char?
64 txa ; get character back
66 sbc #<('a'-'A') ; make upper case char
69 L2: cpx tmp1 ; compare characters
70 bne NotEqual ; Jump if strings different
72 beq Equal1 ; Jump if EOS reached, a/x == 0
74 ; Increment the pointers
80 bne Loop ; Branch always
85 bne Comp ; Jump if counter not zero
87 ; Exit code if strings are equal. a/x not set
93 ; Exit code if strings not equal
97 ldx #$FF ; Make result negative
100 L3: ldx #$01 ; Make result positive