-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/optimize str[n]casecmp, remove buggy OS tolower/toupper
- Loading branch information
1 parent
f979fd6
commit 40e668e
Showing
5 changed files
with
107 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
assume adl=1 | ||
|
||
section .text | ||
public _strcasecmp | ||
|
||
if PREFER_OS_LIBC | ||
|
||
_strcasecmp := 021E3Ch | ||
|
||
else | ||
|
||
_strcasecmp: | ||
pop iy | ||
pop de | ||
ex (sp), hl | ||
push de | ||
ld b, 1+'z'-'a' | ||
ld c, 'a'-'A' | ||
jr .loop_entry | ||
.loop: | ||
cp a, (hl) | ||
jr z, .done | ||
.loop_nonnull: | ||
inc hl | ||
inc de | ||
.loop_entry: | ||
ld a, (de) | ||
xor a, (hl) | ||
jr z, .loop | ||
cp a, c | ||
jr nz, .mismatch | ||
or a, (hl) | ||
sub a, 'a' | ||
cp a, b | ||
jr c, .loop_nonnull | ||
|
||
end if | ||
|
||
section .text | ||
public _strcasecmp.mismatch | ||
public _strcasecmp.done | ||
_strcasecmp.mismatch: | ||
ld l, (hl) | ||
call _tolower.internal | ||
ex de, hl | ||
ld l, (hl) | ||
call _tolower.internal | ||
ld a, l | ||
sub a, e | ||
_strcasecmp.done: | ||
sbc hl, hl | ||
ld l, a | ||
jp (iy) | ||
|
||
section .text | ||
public _strncasecmp | ||
_strncasecmp: | ||
pop iy | ||
pop de | ||
pop hl | ||
pop bc | ||
push bc | ||
push de | ||
push hl | ||
|
||
scf | ||
sbc hl, hl | ||
add hl, bc | ||
ex (sp), hl | ||
|
||
call c, .loop_entry | ||
jr c, _strcasecmp.mismatch | ||
sbc hl, hl | ||
jp (iy) | ||
|
||
.checkcase: | ||
or a, (hl) | ||
sub a, 'a' | ||
add a, -(1+'z'-'a') | ||
ret c | ||
.loop: | ||
cpi | ||
ret po | ||
ret z | ||
inc de | ||
.loop_entry: | ||
ld a, (de) | ||
xor a, (hl) | ||
jr z, .loop | ||
cp a, 'a'-'A' | ||
jr z, .checkcase | ||
scf | ||
ret | ||
|
||
extern _tolower.internal |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters