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.
This commit is contained in:
Oliver Schmidt 2020-04-02 11:15:53 +02:00
parent 65dd931d22
commit df015f4766
2 changed files with 38 additions and 26 deletions

View file

@ -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); ; int tolower (int c);
; ;
.export _tolower .export _tolower
.import __ctype .include "ctype.inc"
.import ctype_preprocessor
_tolower: _tolower:
cpx #$00 ; Outside valid range? tay ; save char
bne L9 ; If so, return the argument unchanged jsr ctype_preprocessor ; (always clears X)
tay ; Get C into Y bcc @L2 ; out of range?
lda __ctype,y ; Get character classification @L1: tya ; if so, return the argument unchanged
lsr a rts
lsr a ; Get bit 1 (upper case char) into carry @L2: and #CT_UPPER ; upper case char?
tya ; Get char back into A beq @L1 ; jump if no
bcc L9 ; Jump if no upper case char tya ; restore char
sbc #<('A'-'a') ; Make lower case char (carry already set) adc #<('a'-'A') ; make lower case char (ctype_preprocessor ensures carry clear)
L9: rts rts

View file

@ -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); ; int toupper (int c);
; ;
.export _toupper .export _toupper
.import __ctype .include "ctype.inc"
.import ctype_preprocessor
_toupper: _toupper:
cpx #$00 ; Outside valid range? tay ; save char
bne L9 ; If so, return the argument unchanged jsr ctype_preprocessor ; (always clears X)
tay ; Get c into Y bcc @L2 ; out of range?
lda __ctype,y ; Get character classification @L1: tya ; if so, return the argument unchanged
lsr a ; Get bit 0 (lower char) into carry rts
tya ; Get C back into A @L2: and #CT_LOWER ; lower case char?
bcc L9 ; Jump if not lower char beq @L1 ; jump if no
clc tya ; restore char
adc #<('A'-'a') ; make upper case char adc #<('A'-'a') ; make upper case char (ctype_preprocessor ensures carry clear)
L9: rts ; CC are set rts