-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-echo option can print correct looking characters in terminal #112
Conversation
I like the feature, but:
|
I will remove UTF8 characters from the C code when I get farther, but it's useful to see the real characters when you develop. I now also support some PETSCII (both unshifted and shifted) and some control codes that map to VT100/xterm. My idea was to adapt to the users locale and use iconv-library, but I might only support UTF8 terminals in the beginning. I also think one should be able to use the original system by having different suboptions to -echo, e.g. raw would be the original system. |
I'm not sure it is useful to convert PETSCII control codes to ANSI control codes. What is the use case? I would say the main use case for
|
With this, we could add an argument ( |
The use case for mapping the control codes to VT100/xterm would be to have the same output in the terminal as on the X16 screen. I believe it could be a sub option if you want to convert PETSCII control codes to VT100/xterm escape codes, or have them converted to hex (i.e. \x13, \x93, or {$13}, {$93}), or The reason I put this in the emulator and not in an external filter program is because I could not get filter programs to work with I believe there are more PETSCII characters in Unicode now than when ~triad wrote those documents in 2002. |
Piping the output of x16emu should work if you add |
echochar.c
Outdated
20 PRINT "case";I;CHR$($9D)": printf(";CHR$(34);CHR$(I);CHR$(34);"); break;" | ||
30 NEXT | ||
*/ | ||
case 160: printf(" "); break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For 88 of these 96 values, the code on the left is the code on the right anyway. You have just made your text editor pre-convert the output into UTF-8. As I have stated before, for the codes $A0-$FF (except for 8 values), Unicode is the same as 8859-15, so can just pass the values into a (quite simple) UTF-8 encoder, instead of having a huge table of pre-encoded UTF-8 values.
I removed Unicode characters from code, but they are in end of line comments. I used programs to write the code from triad files. |
echochar.c
Outdated
case 0xDF: prtflush("?"); break; | ||
case 255: prtflush("▒"); break; | ||
default: prtnumflush("%c", c); | ||
case 0x5C: prtflush("\xC2\xA3"); break; // 0xA3, £ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be much better if it were a table that maps 8 bit PETSCII to 16 bit Unicode numbers, and you do the UTF-8 encoding separately.
(The UTF-8 in the comments is fine, and useful.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know exactly what is the advantage with a table over a switch. A switch is more flexible and easier to maintain. I can shrink the switches further since there are still repetitions in the PETSCII. An array would contain a lot of elements that would have some special value because there is no translation for all PETSCII codes. I could change the cases in the switch so that they don't contain strings in most cases:
From:
case 0x5E: prtflush("\xE2\x86\x91"); break; // 0x2191, ↑
To:
case 0x5E: prtuptflush(0x2191); break; // ↑ upt = Unicode point
I did use int utf8_encode(char *out, uint32_t utf)
to convert from Unicode point to UTF-8. I thought it would make the emulator faster if I did the conversion outside the emulator.
Maybe there are PETSCII characters outside 16 bit Unicode. A switch can handle these characters better.
That is exactly what Commodore 8-bit computers do! Their screens have three special modes: reverse color mode, quote mode (control characters are displayed instead of obeyed), and insert mode (similar to quote mode). Printing a carriage return turns off all those modes. |
Fascinating! I will remove my comments in the code that I compensate for bugs. |
The following compile fix is necessary for macOS:
|
I tried it, and I see some problems:
Unfortunately I am unconvinced about this whole approach. :/ At least by default, I think |
I did fixes for macOS, but I don't have it so I couldn't test them.
I think I could make this as a filter program instead, but then it would be best if |
I have made a filter program, |
I close this as a simpler solution is possible. |
I thought it would be good if what is echoed doesn't contain inverted question marks (unknown character). The goal is that this would print correct looking characters for every mode and in every terminal. Now it only works if the terminal has the same encoding as the system this was compiled on.