From 411fe87f64f57dd3b2469214fdbca01a121b4569 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Thu, 2 Apr 2020 22:14:22 +0200 Subject: [PATCH 169/170] Fixed tolower() and toupper() to save high byte. --- libsrc/common/tolower.s | 21 +++++++++++---------- libsrc/common/toupper.s | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/libsrc/common/tolower.s b/libsrc/common/tolower.s index e672f077..bebac3c5 100644 --- a/libsrc/common/tolower.s +++ b/libsrc/common/tolower.s @@ -12,16 +12,17 @@ .export _tolower .include "ctype.inc" - .import ctype_preprocessor + .import ctype_preprocessor_no_check _tolower: - tay ; save char - jsr ctype_preprocessor ; (always clears X) - bcc @L2 ; out of range? -@L1: tya ; if so, return the argument unchanged - rts -@L2: and #CT_UPPER ; upper case char? - beq @L1 ; jump if no - tya ; restore char - adc #<('a'-'A') ; make lower case char (ctype_preprocessor ensures carry clear) + cpx #$00 ; out of range? + bne @L2 ; if so, return the argument unchanged + tay ; save char + jsr ctype_preprocessor_no_check + and #CT_UPPER ; upper case char? + beq @L1 ; jump if no + tya ; restore char + adc #<('a'-'A') ; make lower case char (ctype_preprocessor_no_check ensures carry clear) rts +@L1: tya ; restore char +@L2: rts diff --git a/libsrc/common/toupper.s b/libsrc/common/toupper.s index 5b3a4c22..ed3dd9b0 100644 --- a/libsrc/common/toupper.s +++ b/libsrc/common/toupper.s @@ -12,16 +12,17 @@ .export _toupper .include "ctype.inc" - .import ctype_preprocessor + .import ctype_preprocessor_no_check _toupper: - tay ; save char - jsr ctype_preprocessor ; (always clears X) - bcc @L2 ; out of range? -@L1: tya ; if so, return the argument unchanged - rts -@L2: and #CT_LOWER ; lower case char? - beq @L1 ; jump if no - tya ; restore char - adc #<('A'-'a') ; make upper case char (ctype_preprocessor ensures carry clear) + cpx #$00 ; out of range? + bne @L2 ; if so, return the argument unchanged + tay ; save char + jsr ctype_preprocessor_no_check + and #CT_LOWER ; lower case char? + beq @L1 ; jump if no + tya ; restore char + adc #<('A'-'a') ; make upper case char (ctype_preprocessor_no_check ensures carry clear) rts +@L1: tya ; restore char +@L2: rts -- 2.26.0