ASCII > PETSCII and the X16 Emulator

Tmp2k

New Member
Sep 22, 2019
5
2
3
I posted on the FB group but didn't really get anywhere. My lack of C64 experience is probably a big factor here but can someone confirm my understanding here, or set me straight.

The C64/X16 uses PETSCII, which seems to have 128 actual chars, roughly mapped out below in hex.

<--- control chars --->
20 !"#$%&'()*+,-./
30 0123456789:;<=>?
40 @ABCDEFGHIJKLMNO
50 PQRSTUVWXYZ[£]^_
60 <PETSCII drawings>
70 <PETSCII drawings>
<--- control chars --->
a0 <PETSCII drawings>
b0 <PETSCII drawings>

If you change to the "shifted" mode you get a different set of 128 chars, upper/lower case. But how do you actually do that, and what character codes do they have? If I loop through all the character codes in BASIC I just get the same chars, unless I POKE and set shifted mode. Does this mean you can only use one set of chars at one time and by shifting you're just changing the way the X16 outputs them on screen, not the actual value of the chars?

Assuming all that is correct, does anyone know how X16 maps ASCII to PETSCII when pasting in text? If I put all the ASCII codes in a text file and paste it in I don't get the corresponding PETSCII. Most are there but not all.

Image3.png


Left = ASCII pasted in Middle = X16 Emulator output Right = PETSCII
 

Panda

New Member
You can display 255 unique characters at a time.
There are two character sets. When you switch between them, it only changes the output on the screen.
If you point to a separate memory location in RAM you can customize all 255 characters to look any way you like.

The confusing about why you might only see the 127 characters is because characters 128 to 255 are the REVERSE of characters 0 to 127.poke codes.png
 

zdaddyo

New Member
Sep 24, 2019
6
4
3
Colorado
I'm curious if there is a PETSCII keyboard mapping somewhere for the emulator? I've looked around and can't seem to find any resource for that. I've been trying to type the PETSCII 186 "corner" and can't find it on the keyboard.
 
May 22, 2019
486
250
43
So it's a bit confusing at the moment, and I'm hoping that Mike simplifies this a bit.

For now, the "Symbolic" keymap int the VICE Commodore emulator should generally work to get the characters you're looking for. Here's an example:
1569395762870.png

Maybe some enterprising person can edit a graphic like this after some trial and error with the emulator.

To get the left symbol on a key, use the "ALT" key on your keyboard. Alt+A, for example, gives you the upper-left box drawing character.
To get the right symbol, you must be in Upper-Case/Graphics mode, and use Shift. So Shift+A will give you the heart symbol.

Where this breaks down is the @ symbol, * key, and the + and - keys. Those are in different places on the C64 keyboard, but the emulator maps those to their locations on the PC.So I don't think there's currently a way to get the graphic symbols on those 4 keys. Instead, use the CHR$ function to get those characters.

As to upper case, lower case, and graphic symbols, there are actually exactly 128 characters in the character set. The mostly standard symbols are mapped to 32-127, and the C= key symbols (the left side glyphs) are located at 161 to 191. There's a hard space at 160, which I think is accessed with Shift-Space (it is in some programs, anyway.)

The rest of the PETSCII set is either redundant characters ( (192-255) or control codes (0-31, 128-159).

So, as was already mentioned, you can get lower case letters with the C= and Shift keys. Or you can print CHR$(14). Printing CHR$(142) (14+128) switches to upper case mode.

When in lower case mode, the right-side graphic characters are not available. Instead, 65-90 become lower-case characters and 97 and up become upper-case text. This is a clever solution, as it means the Shift key has a consistent function, and upper-case ASCII text is always readable, even if the case is switched.

If I recall, The CX16 emulator maps 7-bit ASCII symbols and text to the same byte value when pasting text into the emulator, in upper case mode. So "A" in Windows becomes "A" in the emulator. "a" in Windows should become ┌ in the emulator.

The problem comes in when trying to map character values above 128. Technically, ASCII does not define values above 128, and so those characters do not have a clear mapping. I believe they are mapped to some Unicode characters that have no relationship to the values in question. This means copying and pasting left-side graphic symbols is not going to work reliably, unless you do a lot of trial and error.

Instead, I'd work on tokenizing your programs using something like TOK64, PetCAT, or another tool to convert ASCII text to BASIC binaries. They use {token codes} to encode symbols that don't appear in ASCII. For example: {CM S} for the heart symbol.

The Commodore utilities obviously don't support the new CX16 keywords yet, but some are coming.
 
  • Like
Reactions: mobluse

Schlowski

Member
Sep 24, 2019
46
26
18
There are some (Windows) editors out there which can edit basic files and load and save them in binary format.

CBM PrgStudio
BasEdit.NET

Don't know about PrgStudio, but for BasEdit you can edit the token-list to add the new X16 tokens.
 
  • Like
Reactions: zdaddyo
May 22, 2019
486
250
43
Thanks for the tip on BasEdit. I'm looking at that right now.

CBM Prog Studio is buggy enough that I only use it when I have no other alternative. I've forwarded some bug reports to the creator, but he has not even replied to my messages, and there hasn't been a release since long before that. I wish he'd just open source it, so we can actually fix those issues (and add CX16 support.)
 
May 22, 2019
486
250
43
I tried out BasEdit.NET and that did the trick. Thanks Schlowski!
Since we'll need to extend BasEdit to work on the CX16, I opened a Github repo....


At the very least, you'll want to grab the config file and the X16 basic token file I added.

The attached file is JUST the config file and the token file. This adds VPOKE and changes the default target to Commander X16 BASIC.
 

Attachments

  • Like
Reactions: Schlowski

Schlowski

Member
Sep 24, 2019
46
26
18
That's great, thanks for your efforts Tom!

I had to change two more lines in the BasEdit.ini to get F5 (Save&Run) to work:

Code:
' values>=0 = real startaddress
Startaddress=-2
to set the correct load address for BASIC programs

and

Code:
' special emulator for load address -2 = 2049 --> X16
Emu=d:\Emulation\X16\Emu\x16emu.exe
EmuParams=-prg %F -run -keymap de -scale 2
so that BasEdit.NET starts the correct emulator.

Btw, this ominous Mr. Stojalowski is me, BasEdit.NET is my creation and I put it to public domain many years ago. So go on and enhance it :)
I made a pdf out of the (crude and not very detailed) original Website, see the appended pdf.
 

Attachments

Last edited:

BruceMcF

Active Member
May 19, 2019
139
42
28
I posted on the FB group but didn't really get anywhere. My lack of C64 experience is probably a big factor here but can someone confirm my understanding here, or set me straight.

The C64/X16 uses PETSCII, which seems to have 128 actual chars, roughly mapped out below in hex.

<--- control chars --->
20 !"#$%&'()*+,-./
30 0123456789:;<=>?
40 @ABCDEFGHIJKLMNO
50 PQRSTUVWXYZ[£]^_
60 <PETSCII drawings>
70 <PETSCII drawings>
<--- control chars --->
a0 <PETSCII drawings>
b0 <PETSCII drawings>

If you change to the "shifted" mode you get a different set of 128 chars, upper/lower case. But how do you actually do that, and what character codes do they have? ...
As mentioned, the display for each Petscii character may change, depending on whether the display is set to upper case / graphics or lower/upper case.

You DO that by printing a control character ... print(14) for lower/upper case, print(142) for upper/gfx, which basically prints the control character that corresponds to the unshifted and shifted upper/lower case control key in the C64,

Changing text colors -- I don't know if these are implemented: white print(5), red 28, green 30, blue 31, orange 129, black 144, brown 149, pink 150, dark grey 151, grey 152, light green 153, light blue 154, light grey 155, purplle 156, yellow 158, cyan 159,

Cursor control: cursor down 17, Home 19, cursor right 29, cursor up 145, cursor left 157

Other Terminal control: disable C=-shift print(8), enable C=-shift 9, lower/upper display 14, reverse-on 18, Home 19, delete 20, upper/gfx display 142, Clear Screen 147, Insert 148
 
May 22, 2019
486
250
43
That's great, thanks for your efforts Tom!

I had to change two more lines in the BasEdit.ini to get F5 (Save&Run) to work:

Code:
' values>=0 = real startaddress
Startaddress=-2
to set the correct load address for BASIC programs

and

Code:
' special emulator for load address -2 = 2049 --> X16
Emu=d:\Emulation\X16\Emu\x16emu.exe
EmuParams=-prg %F -run -keymap de -scale 2
so that BasEdit.NET starts the correct emulator.

Btw, this ominous Mr. Stojalowski is me, BasEdit.NET is my creation and I put it to public domain many years ago. So go on and enhance it :)
I made a pdf out of the (crude and not very detailed) original Website, see the appended pdf.
Thank you very much. :)

I was concerned about a hearsay Copyright notice; hearing this from you is definitely appreciated. Also, the fact that you created this for the community is very much appreciated, thank you.
 
Last edited:

Tmp2k

New Member
Sep 22, 2019
5
2
3
Thanks for the replies, sorry it took me a while to get back, I've been really busy. I've since wrapped my head around the charset and more importantly the difference between ASCII, PETSCII, Unicode, UTF-8 and UTF-16. The result is, I've got JavaScript talking to the emulator using UTF-8 correctly, which fixed the issues of direct ASCII > PETSCII conversion (this only half worked as a coincidence, I needed UTF-8 to get the full set of chars).

I've since added a clickable PETSCII table to the editor, and the ability to type PETSCII chars directly using the ALT key, which also popus up an on-screen keyboard. You can leave the on-screen keyboard present and click the buttons as well if you want. I just need to add the remaining PETSCII symbols to the keyboard.

See it in action at https://x16.tmp2k.com


1571835684980.png
 
  • Like
Reactions: BruceMcF
May 22, 2019
486
250
43
That's looking pretty good. =)

I've noticed that while this sort of works on my iPad (I can type in the edit box on the left), it doesn't let me use the keyboard to run the emulator. I'm not sure if there's a fix for that... I'll play with that myself and see if I can figure out how to make that work.

It might also be nice to be able to set the emulator to a larger view, maybe one that fills the vertical space in the window. I tweaked the style to make the window larger and ended up with this on my laptop (running Chrome on a 1080p display)

position: absolute; left:480; top:0; width:960; height:720;

I can see this being real useful for people with Chromebooks and tablets; keep up the great work!!
 
Last edited:

Tmp2k

New Member
Sep 22, 2019
5
2
3
That's looking pretty good. =)

You're missing a few symbols, though. There are a few non-ASCII symbols in the 32-127 space that don't translate at all when entering them in the BASIC editor.In ASCII, those are the grave symbol (`), tilde (~), and braces ({ and }).

I've also noticed that, while this comes up on a tablet (like my iPad), I can't get it to trigger the keyboard. Maybe adding a virtual keyboard on the right side would be a nice feature.

Thanks for the feedback, I hadn't noticed those missing chars, I'll look into it. The missing soft keyboard is on my list https://github.com/Tmp2k/x16wide/issues/2 There are a few things that need fixing on mobile and tablet at the moment, I'll get them sorted when I get some time.

Also, none of the tabs work on mobile at the moment, I just hid them so the rest of the page made sense on a small screen, I need to figure out the best way of laying out the page yet.
 
  • Like
Reactions: TomXP411

mobluse

Member
Sep 20, 2019
35
15
8
To get the left symbol on a key, use the "ALT" key on your keyboard. Alt+A, for example, gives you the upper-left box drawing character.
To get the right symbol, you must be in Upper-Case/Graphics mode, and use Shift. So Shift+A will give you the heart symbol.
A small correction: Shift+A gives spade symbol ♠. (Shift+S gives heart symbol ♥.)