1
0
mirror of https://github.com/hsoft/collapseos.git synced 2025-04-04 13:38:39 +11:00

Corrected error in comments, and a new parseHex

5 bytes saved in parseHex, again hard to say what that does to speed, the shortest possible speed is probably a little slower but I think non-error cases should be around 9 cycles faster for decimal and 18 cycles faster for hex as there's now only two conditional returns and no compliment carries.
This commit is contained in:
Clanmaster21 2019-10-13 18:45:28 +01:00 committed by GitHub
parent f871ea671e
commit 2224a9264e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,23 +11,21 @@
; On success, the carry flag is reset. On error, it is set.
parseHex:
; First, let's see if we have an easy 0-9 case
sub '0'
ret c
cp 10
ccf
add a, 0xc6 ; maps '0'-'9' onto 0xf6-0xff
sub 0xf6 ; maps to 0-9 and carries if not a digit
ret nc
.alpha:
and 0xdf ; converts uppercase to lowercase
sub 0x11 ; C if <'A'
ret c
cp 6 ; not C if >'F'
ccf
ret c
and 0xdf ; converts lowercase to uppercase
add 0xe9 ; map 0x11-x017 onto 0xFA - 0xFF
sub 0xfa ; map onto 0-6
ret c
; We have alpha.
add a, 10 ; C is clear
add a, 10 ; C is clear, map back to 0xA-0xF
ret
; Parses 2 characters of the string pointed to by HL and returns the numerical
; value in A. If the second character is a "special" character (<0x21) we don't
; error out: the result will be the one from the first char only.