.rodata
-; Value that must be added to an upper case char to make it lower case
-; char (example: for ASCII, this must be $E0).
-
-
- .export __cdiff
-
-__cdiff:
- .byte $E0
-
-
; The following 256 byte wide table specifies attributes for the isxxx type
; of functions. Doing it by a table means some overhead in space, but it
; has major advantages:
.rodata
-; Value that must be added to an upper case char to make it lower case
-; char (example: for ASCII, this must be $E0).
-
-
- .export __cdiff
-
-__cdiff:
- .byte $E0
-
-
; The following 256 byte wide table specifies attributes for the isxxx type
; of functions. Doing it by a table means some overhead in space, but it
; has major advantages:
.rodata
-; Value that must be added to a lower case char to make it an upper case
-; char (example: for ASCII, this must be $E0).
-
-
- .export __cdiff
-
-__cdiff:
- .byte $80
-
-
; The following 256 byte wide table specifies attributes for the isxxx type
; of functions. Doing it by a table means some overhead in space, but it
; has major advantages:
.export _stricmp, _strcasecmp
.import popax
- .import __ctype, __cdiff
+ .import __ctype
.importzp ptr1, ptr2, tmp1
_stricmp:
_strcasecmp:
- sta ptr2 ; Save s2
+ sta ptr2 ; Save s2
stx ptr2+1
- jsr popax ; get s1
+ jsr popax ; get s1
sta ptr1
stx ptr1+1
ldy #0
-loop: lda (ptr2),y ; get char from second string
+loop: lda (ptr2),y ; get char from second string
tax
- lda __ctype,x ; get character classification
- and #$01 ; lower case char?
- beq L1 ; jump if no
- txa ; get character back
+ lda __ctype,x ; get character classification
+ and #$01 ; lower case char?
+ beq L1 ; jump if no
+ txa ; get character back
clc
- adc __cdiff ; make upper case char
+ adc #<('A'-'a') ; make upper case char
tax ;
L1: stx tmp1 ; remember upper case equivalent
beq L2 ; jump if no
txa ; get character back
clc
- adc __cdiff ; make upper case char
+ adc #<('A'-'a') ; make upper case char
tax
L2: cpx tmp1 ; compare characters
.export _strlower, _strlwr
.import popax
- .import __ctype, __cdiff
+ .import __ctype
.importzp ptr1, ptr2
_strlower:
_strlwr:
- sta ptr1 ; Save s (working copy)
- stx ptr1+1
+ sta ptr1 ; Save s (working copy)
+ stx ptr1+1
sta ptr2
- sta ptr2+2 ; save function result
+ sta ptr2+2 ; save function result
ldy #0
-loop: lda (ptr1),y ; get character
- beq L9 ; jump if done
+loop: lda (ptr1),y ; get character
+ beq L9 ; jump if done
tax
- lda __ctype,x ; get character classification
- and #$02 ; upper case char?
- beq L1 ; jump if no
- txa ; get character back into accu
+ lda __ctype,x ; get character classification
+ and #$02 ; upper case char?
+ beq L1 ; jump if no
+ txa ; get character back into accu
sec
- sbc __cdiff ; make lower case char
- sta (ptr1),y ; store back
+ sbc #<('A'-'a') ; make lower case char
+ sta (ptr1),y ; store back
L1: iny ; next char
bne loop
inc ptr1+1 ; handle offset overflow
.export _strupper, _strupr
.import popax
- .import __ctype, __cdiff
+ .import __ctype
.importzp ptr1, ptr2
_strupper:
_strupr:
sta ptr1 ; Save s (working copy)
- stx ptr1+1
+ stx ptr1+1
sta ptr2
sta ptr2+2 ; save function result
ldy #0
beq L1 ; jump if no
txa ; get character back into accu
clc
- adc __cdiff ; make upper case char
+ adc #<('A'-'a') ; make upper case char
sta (ptr1),y ; store back
L1: iny ; next char
bne loop
;
.export _tolower
- .import __ctype, __cdiff
+ .import __ctype
_tolower:
cpx #$00 ; Outside valid range?
lsr a ; Get bit 1 (upper case char) into carry
tya ; Get char back into A
bcc L9 ; Jump if no upper case char
- sbc __cdiff ; Make lower case char (carry already set)
+ sbc #<('A'-'a') ; Make lower case char (carry already set)
L9: rts
;
.export _toupper
- .import __ctype, __cdiff
+ .import __ctype
_toupper:
cpx #$00 ; Outside valid range?
tya ; Get C back into A
bcc L9 ; Jump if not lower char
clc
- adc __cdiff ; make upper case char
+ adc #<('A'-'a') ; make upper case char
L9: rts ; CC are set