Blob Blame History Raw
From df015f47662d3b2f44a383bd5dc520216c9285f7 Mon Sep 17 00:00:00 2001
From: Oliver Schmidt <ol.sc@web.de>
Date: Thu, 2 Apr 2020 11:15:53 +0200
Subject: [PATCH 168/170] Adjusted tolower() and toupper() to
 https://github.com/cc65/cc65/pull/997

For some reason or another both the author of the PR in question and its reviewers didn't notice that the two functions in question were totally overlooked.
---
 libsrc/common/tolower.s | 32 +++++++++++++++++++-------------
 libsrc/common/toupper.s | 32 +++++++++++++++++++-------------
 2 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/libsrc/common/tolower.s b/libsrc/common/tolower.s
index 2c624cb7..e672f077 100644
--- a/libsrc/common/tolower.s
+++ b/libsrc/common/tolower.s
@@ -1,21 +1,27 @@
+; tolower.s
 ;
-; Ullrich von Bassewitz, 02.06.1998
+; This file is part of
+; cc65 - a freeware C compiler for 6502 based systems
+;
+; https://cc65.github.io
+;
+; See "LICENSE" file for legal information.
 ;
 ; int tolower (int c);
 ;
 
         .export         _tolower
-        .import         __ctype
+        .include        "ctype.inc"
+        .import         ctype_preprocessor
 
 _tolower:
-        cpx     #$00            ; Outside valid range?
-        bne     L9              ; If so, return the argument unchanged
-        tay                     ; Get C into Y
-        lda     __ctype,y       ; Get character classification
-        lsr     a
-        lsr     a               ; Get bit 1 (upper case char) into carry
-        tya                     ; Get char back into A
-        bcc     L9              ; Jump if no upper case char
-        sbc     #<('A'-'a')     ; Make lower case char (carry already set)
-L9:     rts
-
+        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)
+        rts
diff --git a/libsrc/common/toupper.s b/libsrc/common/toupper.s
index da1ee042..5b3a4c22 100644
--- a/libsrc/common/toupper.s
+++ b/libsrc/common/toupper.s
@@ -1,21 +1,27 @@
+; toupper.s
 ;
-; Ullrich von Bassewitz, 02.06.1998
+; This file is part of
+; cc65 - a freeware C compiler for 6502 based systems
+;
+; https://cc65.github.io
+;
+; See "LICENSE" file for legal information.
 ;
 ; int toupper (int c);
 ;
 
         .export         _toupper
-        .import         __ctype
+        .include        "ctype.inc"
+        .import         ctype_preprocessor
 
 _toupper:
-        cpx     #$00            ; Outside valid range?
-        bne     L9              ; If so, return the argument unchanged
-        tay                     ; Get c into Y
-        lda     __ctype,y       ; Get character classification
-        lsr     a               ; Get bit 0 (lower char) into carry
-        tya                     ; Get C back into A
-        bcc     L9              ; Jump if not lower char
-        clc
-        adc     #<('A'-'a')     ; make upper case char
-L9:     rts                     ; CC are set
-
+        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)
+        rts
-- 
2.26.0