2020-04-02 11:15:53 +02:00
|
|
|
; tolower.s
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
2020-04-02 11:15:53 +02:00
|
|
|
; This file is part of
|
|
|
|
; cc65 - a freeware C compiler for 6502 based systems
|
|
|
|
;
|
|
|
|
; https://cc65.github.io
|
|
|
|
;
|
|
|
|
; See "LICENSE" file for legal information.
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; int tolower (int c);
|
|
|
|
;
|
|
|
|
|
2024-03-22 17:19:26 +01:00
|
|
|
.export _tolower, tolowerdirect
|
2020-04-02 11:15:53 +02:00
|
|
|
.include "ctype.inc"
|
2020-04-02 22:58:16 +02:00
|
|
|
.import ctypemaskdirect
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
_tolower:
|
2020-04-02 22:14:22 +02:00
|
|
|
cpx #$00 ; out of range?
|
2024-03-19 18:07:17 +01:00
|
|
|
bne out ; if so, return the argument unchanged
|
2024-03-22 17:19:26 +01:00
|
|
|
tolowerdirect:
|
2024-03-18 19:52:04 +01:00
|
|
|
pha ; save char
|
2020-04-02 22:58:16 +02:00
|
|
|
jsr ctypemaskdirect ; get character classification
|
2020-04-02 22:14:22 +02:00
|
|
|
and #CT_UPPER ; upper case char?
|
|
|
|
beq @L1 ; jump if no
|
2024-03-18 19:52:04 +01:00
|
|
|
pla ; restore char
|
2020-04-02 22:58:16 +02:00
|
|
|
adc #<('a'-'A') ; make lower case char (ctypemaskdirect ensures carry clear)
|
2020-04-02 11:15:53 +02:00
|
|
|
rts
|
2024-03-18 19:52:04 +01:00
|
|
|
@L1: pla ; restore char
|
2024-03-19 18:07:17 +01:00
|
|
|
out: rts
|