added txt.petscii2scr() and txt.petscii2scr_str()

This commit is contained in:
Irmen de Jong 2024-02-07 22:36:43 +01:00
parent 73ec8c31ad
commit d33aed4ed5
14 changed files with 100 additions and 49 deletions

View File

@ -3,7 +3,7 @@
%import syslib
%import conv
%import shared_textio_functions
txt {

View File

@ -4,6 +4,7 @@
%import syslib
%import conv
%import shared_textio_functions
txt {

View File

@ -1,7 +1,7 @@
; Prog8 definitions for floating point handling on the Commodore-64
%option enable_floats, no_symbol_prefixing, ignore_unused
%import floats_functions
%import shared_floats_functions
floats {
; ---- this block contains C-64 floating point related functions ----

View File

@ -4,7 +4,7 @@
%import syslib
%import conv
%import shared_textio_functions
txt {

View File

@ -1,7 +1,7 @@
; Prog8 definitions for floating point handling on the CommanderX16
%option enable_floats, no_symbol_prefixing, ignore_unused
%import floats_functions
%import shared_floats_functions
floats {
; ---- this block contains C-64 compatible floating point related functions ----

View File

@ -4,7 +4,7 @@
%import syslib
%import conv
%import shared_textio_functions
txt {

View File

@ -4,7 +4,7 @@
%import syslib
%import conv
%import shared_textio_functions
txt {
%option no_symbol_prefixing, ignore_unused

View File

@ -0,0 +1,39 @@
txt {
; the textio functions shared across compiler targets
%option merge, no_symbol_prefixing, ignore_unused
asmsub petscii2scr(ubyte petscii_char @A) -> ubyte @A {
; -- convert petscii character to screencode
%asm {{
sta P8ZP_SCRATCH_REG
lsr a
lsr a
lsr a
lsr a
lsr a
tax
lda _offsets,x
eor P8ZP_SCRATCH_REG
rts
_offsets .byte 128, 0, 64, 32, 64, 192, 128, 128
}}
}
asmsub petscii2scr_str(str petscii_string @AY) {
; -- convert petscii string to screencodes string
%asm {{
sta P8ZP_SCRATCH_W1
sty P8ZP_SCRATCH_W1+1
ldy #0
- lda (P8ZP_SCRATCH_W1),y
beq +
jsr petscii2scr
sta (P8ZP_SCRATCH_W1),y
iny
bne -
+ rts
}}
}
}

View File

@ -145,4 +145,19 @@ sub setchr (ubyte col, ubyte row, ubyte char) {
txt.chrout(char)
}
sub petscii2scr(ubyte petscii_char) -> ubyte {
; -- convert petscii character to screencode
byte[8] offsets = [128, 0, 64, 32, 64, 192, 128, 128]
return petscii_char ^ offsets[petscii_char>>5]
}
sub petscii2scr_str(str petscii_string) {
; -- convert petscii string to screencodes string
cx16.r0 = petscii_string
while @(cx16.r0)!=0 {
@(cx16.r0) = petscii2scr(@(cx16.r0))
cx16.r0++
}
}
}

View File

@ -42,8 +42,9 @@ main {
"textio",
"syslib",
"conv",
"shared_textio_functions",
"floats",
"floats_functions",
"shared_floats_functions",
"math",
"prog8_lib"
)
@ -100,7 +101,7 @@ main {
listOf(
internedStringsModuleName,
filenameBase,
"textio", "syslib", "conv", "floats", "floats_functions", "math", "prog8_lib"
"textio", "syslib", "conv", "shared_textio_functions", "floats", "shared_floats_functions", "math", "prog8_lib"
)
}
options.floats shouldBe true

View File

@ -177,6 +177,7 @@ dealing with text-based input and output (to the screen). Such as
- filling or clearing the screen and colors
- scrolling the text on the screen
- placing individual characters on the screen
- convert petscii to screencode characters
All routines work with Screencode character encoding, except `print`, `chrout` and `input_chars`,
these work with PETSCII encoding instead.

View File

@ -1,8 +1,9 @@
TODO
====
&pointervar[x] isn't correct?? (at least in IR)
&pointervar[x] isn't the correct value
&pointervar[x] AST doesn't print correctly
@(s) where s is a str parameter, doesn't work
(after merge in boolean): move all "OperatorXinplace" from expressionGen to AssignmentGen, see if we can get rid of the Result return type.
@ -13,6 +14,7 @@ Future Things and Ideas
^^^^^^^^^^^^^^^^^^^^^^^
Compiler:
- can we support singed % (remainder) somehow?
- instead of copy-pasting inline asmsubs, make them into a 64tass macro and use that instead.
that will allow them to be reused from custom user written assembly code as well.
- Multidimensional arrays and chained indexing, purely as syntactic sugar over regular arrays.

View File

@ -6,50 +6,42 @@
main {
sub start() {
str namestring = petscii:"The Quick Brown Fox Jumps Over The Lazy Dog\n0123456789!#$%^&*()-=_+[]{};:'<>,./?\n"
str namestring2 = petscii:"The Quick Brown Fox Jumps Over The Lazy Dog\n0123456789!#$%^&*()-=_+[]{};:'<>,./?\n"
txt.petscii2scr_str(namestring2)
for cx16.r0L in 0 to len(namestring) {
txt.print_ubhex(namestring[cx16.r0L], false)
txt.spc()
txt.print_ubhex(namestring2[cx16.r0L], false)
txt.nl()
}
txt.nl()
sys.exit(1)
str name1 = ""
str name2 = "hello \r\n"
str name3 = " \n\rhello"
str name4 = " \n\r\xa0\xa0\xff\xffhello\x02\x02\x02 \n "
txt.print("strip:\n")
string.strip(name1)
txt.chrout('[')
txt.print(name1)
txt.print("]\n")
string.strip(name2)
txt.chrout('[')
txt.print(name2)
txt.print("]\n")
string.strip(name3)
txt.chrout('[')
txt.print(name3)
txt.print("]\n")
string.strip(name4)
txt.chrout('[')
txt.print(name4)
txt.print("]\n")
foo(name2)
}
str tname1 = ""
str tname2 = "hello \r\n"
str tname3 = " \n\r\x09hello"
str tname4 = " \n\x09\x0b\r\xa0\xa0\xff\xffhello\x05\x05\x05 \n "
txt.print("trim:\n")
string.trim(tname1)
txt.chrout('[')
txt.print(tname1)
txt.print("]\n")
string.trim(tname2)
txt.chrout('[')
txt.print(tname2)
txt.print("]\n")
string.trim(tname3)
txt.chrout('[')
txt.print(tname3)
txt.print("]\n")
string.trim(tname4)
txt.chrout('[')
txt.print(tname4)
txt.print("]\n")
sub foo (str s2) {
str s = "irmen"
txt.print_uwhex(s, true)
txt.nl()
txt.print_uwhex(&s, true)
txt.nl()
txt.print_uwhex(&s[2], true) ; TODO doesn't print correctly in the AST!
txt.nl()
txt.nl()
txt.print_uwhex(s2, true)
txt.nl()
txt.print_uwhex(&s2, true)
txt.nl()
txt.print_uwhex(s2+2, true)
txt.nl()
txt.print_uwhex(&s2[2], true) ; TODO should be the same as the previous one! TODO doesn't print correctly in the AST!
txt.nl()
}
}