mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 23:29:55 +00:00
added string.lower() / string.upper()
This commit is contained in:
parent
24eee0cb34
commit
72b4198301
@ -190,4 +190,46 @@ _found sty P8ZP_SCRATCH_B1
|
||||
}}
|
||||
}
|
||||
|
||||
asmsub lower(uword st @AY) {
|
||||
; Lowercases the petscii string in-place.
|
||||
; (for efficiency, non-letter characters > 128 will also not be left intact,
|
||||
; but regular text doesn't usually contain those characters anyway.)
|
||||
%asm {{
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
ldy #0
|
||||
- lda (P8ZP_SCRATCH_W1),y
|
||||
beq _done
|
||||
and #$7f
|
||||
cmp #97
|
||||
bcc +
|
||||
cmp #123
|
||||
bcs +
|
||||
and #%11011111
|
||||
+ sta (P8ZP_SCRATCH_W1),y
|
||||
iny
|
||||
bne -
|
||||
_done rts
|
||||
}}
|
||||
}
|
||||
|
||||
asmsub upper(uword st @AY) {
|
||||
; Uppercases the petscii string in-place.
|
||||
%asm {{
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
ldy #0
|
||||
- lda (P8ZP_SCRATCH_W1),y
|
||||
beq _done
|
||||
cmp #65
|
||||
bcc +
|
||||
cmp #91
|
||||
bcs +
|
||||
ora #%00100000
|
||||
+ sta (P8ZP_SCRATCH_W1),y
|
||||
iny
|
||||
bne -
|
||||
_done rts
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
@ -173,6 +173,12 @@ Provides string manipulation routines.
|
||||
Often you don't have to call this explicitly and can just write ``string1 = string2``
|
||||
but this function is useful if you're dealing with addresses for instance.
|
||||
|
||||
``lower(string)``
|
||||
Lowercases the petscii-string in place.
|
||||
|
||||
``upper(string)``
|
||||
Uppercases the petscii-string in place.
|
||||
|
||||
|
||||
floats
|
||||
------
|
||||
|
@ -12,11 +12,23 @@ main {
|
||||
str s2 = "12345 ABCDEF..UVWXYZ ()!@#$%;:&*()-=[]<>\xff\xfa\xeb\xc0\n"
|
||||
str s3 = "12345 \x61\x62\x63\x64\x65\x66..\x75\x76\x77\x78\x79\x7a ()!@#$%;:&*()-=[]<>\xff\xfa\xeb\xc0\n"
|
||||
|
||||
lower(s1)
|
||||
lower(s2)
|
||||
lower(s3)
|
||||
|
||||
txt.lowercase()
|
||||
|
||||
txt.print(s1)
|
||||
txt.print(s2)
|
||||
txt.print(s3)
|
||||
|
||||
string.lower(s1)
|
||||
string.lower(s2)
|
||||
string.lower(s3)
|
||||
txt.print(s1)
|
||||
txt.print(s2)
|
||||
txt.print(s3)
|
||||
|
||||
string.upper(s1)
|
||||
string.upper(s2)
|
||||
string.upper(s3)
|
||||
|
||||
txt.print(s1)
|
||||
txt.print(s2)
|
||||
txt.print(s3)
|
||||
@ -24,49 +36,5 @@ main {
|
||||
txt.nl()
|
||||
}
|
||||
|
||||
asmsub lower(uword st @AY) clobbers(X) {
|
||||
%asm {{
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
ldy #0
|
||||
- lda (P8ZP_SCRATCH_W1),y
|
||||
beq _done
|
||||
and #$7f
|
||||
tax
|
||||
and #%11100000
|
||||
cmp #%01100000
|
||||
bne +
|
||||
txa
|
||||
and #%11011111
|
||||
tax
|
||||
+ txa
|
||||
sta (P8ZP_SCRATCH_W1),y
|
||||
iny
|
||||
bne -
|
||||
_done rts
|
||||
}}
|
||||
}
|
||||
|
||||
asmsub upper(uword st @AY) clobbers(X) {
|
||||
%asm {{
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
ldy #0
|
||||
- lda (P8ZP_SCRATCH_W1),y
|
||||
beq _done
|
||||
and #$7f
|
||||
tax
|
||||
and #%11100000
|
||||
cmp #%01100000
|
||||
bne +
|
||||
txa
|
||||
and #%11011111
|
||||
tax
|
||||
+ txa
|
||||
sta (P8ZP_SCRATCH_W1),y
|
||||
iny
|
||||
bne -
|
||||
_done rts
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user