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