![]() |
toUpper and toLower functions - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: How-To & Tutorials (https://www.boriel.com/forum/forumdisplay.php?fid=13) +---- Thread: toUpper and toLower functions (/showthread.php?tid=143) |
toUpper and toLower functions - britlion - 01-27-2010 Hey all. I'm not anything like a good Z80 programmer, but I'm learning snippets. I wanted a fast way to flip between lower and upper case characters. This can of course be done by +/- 32 to the ascii code. This is of course, the same as setting or resetting bit 5 of the character, which assembly is better at (you could also perhaps use the bAND function listed in How-To). Anyway, I found these two to work. I wasn't sure if resetting the carry flag was necessary or not in all cases, so cleared it to be on the safe side. Edit: It is also with wry amusement that I note that Boriel has LCase and UCase functions in his library as well that I hadn't noticed. #include <lcase.bas> (and/or ucase) would let you use them. They lower/upper a whole string. His functions also use OR and AND instead of set and res. Irritatingly, though I was sure that bit set and bit reset instructions ought to be faster...they aren't. According to the documentation I have, OR and AND take 7 T states when run on the accumulator. SET and RES take 8. Even though that's pretty baffling, since OR can be used as a set of many bits, and AND can be used as a reset of many bits in one go - the documentation says they are faster. Boriel's code almost always is going to be better than mine - unless you happen to have a single character as an ascii code instead of a string. I'll leave these here then as potentially useful for dealing with things like Y/N? responses for a single letter. Code: REM Change a single character code to lower case Code: REM Change a single character code to Upper Case |