1; toupper.s
2;
3; This file is part of
4; cc65 - a freeware C compiler for 6502 based systems
5;
6; https://cc65.github.io
7;
8; See "LICENSE" file for legal information.
9;
10; int toupper (int c);
11;
12
13        .export         _toupper
14        .include        "ctype.inc"
15        .import         ctypemaskdirect
16
17_toupper:
18        cpx     #$00            ; out of range?
19        bne     @L2             ; if so, return the argument unchanged
20        tay                     ; save char
21        jsr     ctypemaskdirect ; get character classification
22        and     #CT_LOWER       ; lower case char?
23        beq     @L1             ; jump if no
24        tya                     ; restore char
25        adc     #<('A'-'a')     ; make upper case char (ctypemaskdirect ensures carry clear)
26        rts
27@L1:    tya                     ; restore char
28@L2:    rts
29