mirror of
https://github.com/irmen/prog8.git
synced 2026-04-19 20:16:51 +00:00
added txt.iso2petscii() and txt.iso2petscii_str()
This commit is contained in:
@@ -229,7 +229,51 @@ _offsets .byte 128, 0, 64, 32, 64, 192, 128, 128
|
||||
bne -
|
||||
+ rts
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
sub iso2petscii(ubyte iso_char) -> ubyte {
|
||||
; --converts iso 8859-15 character to petscii character (lowercase)
|
||||
if iso_char & $7f <= $20
|
||||
return petscii:' ' ; whitspace
|
||||
if iso_char <= $3f
|
||||
return iso_char ; numbers and symbols
|
||||
if iso_char < $80
|
||||
return translate40to7F[iso_char-$40]
|
||||
return translateA0toFF[iso_char-$a0]
|
||||
|
||||
ubyte[$40] translate40to7F = [
|
||||
$40, $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $ca, $cb, $cc, $cd, $ce, $cf,
|
||||
$d0, $d1, $d2, $d3, $d4, $d5, $d6, $d7, $d8, $d9, $da, $5b, $3f, $5d, $5e, $e4,
|
||||
$27, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4a, $4b, $4c, $4d, $4e, $4f,
|
||||
$50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5a, $f3, $7d, $eb, $3f, $3f,
|
||||
]
|
||||
ubyte[$60] translateA0toFF = [
|
||||
$20, $21, $20, $5c, $c5, $d9, $3f, $3f, $3f, $c3, $3f, $28, $3f, $3f, $d2, $e3,
|
||||
$3f, $3f, $32, $33, $3f, $3f, $ff, $3f, $3f, $31, $3f, $3e, $3f, $3f, $d9, $3f,
|
||||
$c1, $c1, $c1, $c1, $c1, $c1, $c1, $c3, $c5, $c5, $c5, $c5, $c9, $c9, $c9, $c9,
|
||||
$c4, $ce, $cf, $cf, $cf, $cf, $cf, $58, $cf, $d5, $d5, $d5, $d5, $d9, $3f, $53,
|
||||
$41, $41, $41, $41, $41, $41, $41, $43, $45, $45, $45, $45, $49, $49, $49, $49,
|
||||
$4f, $4e, $4f, $4f, $4f, $4f, $4f, $3f, $4f, $55, $55, $55, $55, $59, $3f, $59,
|
||||
]
|
||||
}
|
||||
|
||||
asmsub iso2petscii_str(str iso_string @AY) {
|
||||
; -- convert iso string to petscii (lowercase) string
|
||||
%asm {{
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
ldy #0
|
||||
- lda (P8ZP_SCRATCH_W1),y
|
||||
beq +
|
||||
sty P8ZP_SCRATCH_REG
|
||||
jsr iso2petscii
|
||||
ldy P8ZP_SCRATCH_REG
|
||||
sta (P8ZP_SCRATCH_W1),y
|
||||
iny
|
||||
bne -
|
||||
+ rts
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
sub print_bool(bool value) {
|
||||
|
||||
@@ -220,4 +220,38 @@ sub petscii2scr_str(str petscii_string) {
|
||||
}
|
||||
}
|
||||
|
||||
sub iso2petscii(ubyte iso_char) -> ubyte {
|
||||
; --converts iso 8859-15 character to petscii character (lowercase)
|
||||
if iso_char & $7f <= $20
|
||||
return petscii:' ' ; whitspace
|
||||
if iso_char <= $3f
|
||||
return iso_char ; numbers and symbols
|
||||
if iso_char < $80
|
||||
return translate40to7F[iso_char-$40]
|
||||
return translateA0toFF[iso_char-$a0]
|
||||
|
||||
ubyte[$40] translate40to7F = [
|
||||
$40, $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $ca, $cb, $cc, $cd, $ce, $cf,
|
||||
$d0, $d1, $d2, $d3, $d4, $d5, $d6, $d7, $d8, $d9, $da, $5b, $3f, $5d, $5e, $e4,
|
||||
$27, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4a, $4b, $4c, $4d, $4e, $4f,
|
||||
$50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5a, $f3, $7d, $eb, $3f, $3f,
|
||||
]
|
||||
ubyte[$60] translateA0toFF = [
|
||||
$20, $21, $20, $5c, $c5, $d9, $3f, $3f, $3f, $c3, $3f, $28, $3f, $3f, $d2, $e3,
|
||||
$3f, $3f, $32, $33, $3f, $3f, $ff, $3f, $3f, $31, $3f, $3e, $3f, $3f, $d9, $3f,
|
||||
$c1, $c1, $c1, $c1, $c1, $c1, $c1, $c3, $c5, $c5, $c5, $c5, $c9, $c9, $c9, $c9,
|
||||
$c4, $ce, $cf, $cf, $cf, $cf, $cf, $58, $cf, $d5, $d5, $d5, $d5, $d9, $3f, $53,
|
||||
$41, $41, $41, $41, $41, $41, $41, $43, $45, $45, $45, $45, $49, $49, $49, $49,
|
||||
$4f, $4e, $4f, $4f, $4f, $4f, $4f, $3f, $4f, $55, $55, $55, $55, $59, $3f, $59,
|
||||
]
|
||||
}
|
||||
|
||||
sub iso2petscii_str(str iso_string) {
|
||||
; -- convert iso string to petscii (lowercase) string
|
||||
cx16.r0 = iso_string
|
||||
while @(cx16.r0)!=0 {
|
||||
@(cx16.r0) = iso2petscii(@(cx16.r0))
|
||||
cx16.r0++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -823,6 +823,8 @@ txt {
|
||||
height () clobbers (X,Y) -> ubyte @A
|
||||
home ()
|
||||
input_chars (^^ubyte buffer @AY) clobbers (A) -> ubyte @Y
|
||||
iso2petscii (ubyte iso_char) -> ubyte
|
||||
iso2petscii_str (str iso_string @AY)
|
||||
lowercase ()
|
||||
nl ()
|
||||
petscii2scr (ubyte petscii_char @A) -> ubyte @A
|
||||
|
||||
@@ -934,6 +934,8 @@ txt {
|
||||
height () clobbers (X,Y) -> ubyte @A
|
||||
home ()
|
||||
input_chars (^^ubyte buffer @AY) clobbers (A) -> ubyte @Y
|
||||
iso2petscii (ubyte iso_char) -> ubyte
|
||||
iso2petscii_str (str iso_string @AY)
|
||||
lowercase ()
|
||||
nl ()
|
||||
petscii2scr (ubyte petscii_char @A) -> ubyte @A
|
||||
|
||||
@@ -1432,6 +1432,8 @@ txt {
|
||||
input_chars (^^ubyte buffer @AY) clobbers (A) -> ubyte @Y
|
||||
iso ()
|
||||
iso16 ()
|
||||
iso2petscii (ubyte iso_char) -> ubyte
|
||||
iso2petscii_str (str iso_string @AY)
|
||||
iso5 ()
|
||||
iso_off ()
|
||||
kata ()
|
||||
|
||||
@@ -538,6 +538,8 @@ txt {
|
||||
height () clobbers (X,Y) -> ubyte @A
|
||||
home ()
|
||||
input_chars (^^ubyte buffer @AY) clobbers (A) -> ubyte @Y
|
||||
iso2petscii (ubyte iso_char) -> ubyte
|
||||
iso2petscii_str (str iso_string @AY)
|
||||
lowercase ()
|
||||
nl ()
|
||||
petscii2scr (ubyte petscii_char @A) -> ubyte @A
|
||||
|
||||
@@ -561,6 +561,8 @@ txt {
|
||||
height () -> ubyte
|
||||
home ()
|
||||
input_chars (str buffer) -> ubyte
|
||||
iso2petscii (ubyte iso_char) -> ubyte
|
||||
iso2petscii_str (str iso_string)
|
||||
lowercase ()
|
||||
nl ()
|
||||
petscii2scr (ubyte petscii_char) -> ubyte
|
||||
|
||||
+9
-20
@@ -1,26 +1,15 @@
|
||||
%import strings
|
||||
%import textio
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
alias func1 = actualfunc
|
||||
alias func2 = mkword
|
||||
alias func3 = func1
|
||||
alias func4 = func2
|
||||
txt.lowercase()
|
||||
|
||||
; all wrong:
|
||||
func1(1,2)
|
||||
func1()
|
||||
func2(1,2,3,4)
|
||||
func2()
|
||||
func3()
|
||||
func4()
|
||||
str message = iso:"The Quick Brown Fox !@#$%^&*() {_} 12345 /'`|"
|
||||
|
||||
; all ok:
|
||||
func1(1)
|
||||
cx16.r0 = func2(1,2)
|
||||
func3(1)
|
||||
cx16.r0 = func4(1,2)
|
||||
|
||||
sub actualfunc(ubyte a) {
|
||||
a++
|
||||
}
|
||||
txt.iso2petscii_str(&message)
|
||||
txt.print(message)
|
||||
txt.nl()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user