]> git.sur5r.net Git - cc65/blob - libsrc/common/strlower.s
Issue 814
[cc65] / libsrc / common / strlower.s
1 ;
2 ; 1998-06-02, Ullrich von Bassewitz
3 ; 2013-08-28, Greg King
4 ;
5 ; char* __fastcall__ strlower (char* s);
6 ; char* __fastcall__ strlwr (char* s);
7 ;
8 ; Non-ANSI
9 ;
10
11         .export         _strlower, _strlwr
12         .import         popax
13         .import         __ctype
14         .importzp       ptr1, ptr2
15
16         .include        "ctype.inc"
17
18 _strlower:
19 _strlwr:
20         sta     ptr1            ; Save s (working copy)
21         stx     ptr1+1
22         sta     ptr2
23         stx     ptr2+1          ; save function result
24         ldy     #0
25
26 loop:   lda     (ptr1),y        ; get character
27         beq     L9              ; jump if done
28         tax
29         lda     __ctype,x       ; get character classification
30         and     #CT_UPPER       ; upper case char?
31         beq     L1              ; jump if no
32         txa                     ; get character back into accu
33         sec
34         sbc     #<('A'-'a')     ; make lower case char
35         sta     (ptr1),y        ; store back
36 L1:     iny                     ; next char
37         bne     loop
38         inc     ptr1+1          ; handle offset overflow
39         bne     loop            ; branch always
40
41 ; Done, return the argument string
42
43 L9:     lda     ptr2
44         ldx     ptr2+1
45         rts
46
47
48