Can't type a \ in the emulator.

Get technical support from the community & developers with specific X16 programs if you can't find the solution elsewhere
(for general non-support related chat about programs please comment directly under the program in the software library)
void_null

Can't type a \ in the emulator.

Post by void_null »

I've been trying to learn to program this thing in Basic (a language I have no professional training in, though I do have a certificate for Python which Basic seems to resemble). A recurring problem I've been having though is I can't type \. Instead, the emulator inputs the British pound sign.

I first ran into this when I tried to copy the 8-bit guy's 'lightning' program from one of his videos. Now I've encountered it looking at the code for Crazy Snake. I decided to try out the strange print"\x1d" command used at the end of the program just to see what it did. However, as stated I can't type that slash in the emulator.

I have no idea why I can't. My keyboard can obviously type the character. I can type a / in the emulator fine, but it won't let me do a \. I even tried to once to make it input a character using its hexcode, but I couldn't get it to work. Pressing shift just gives me a petsci character (I really need the official keyboard).

This is so annoying. Why won't the emulator let me type in \, especially since there seems to be so many programs that need it?
TomXP411
Posts: 1732
Joined: Tue May 19, 2020 8:49 pm

Re: Can't type a \ in the emulator.

Post by TomXP411 »

That's because the \ character on the keyboard doesn't exist there in PETSCII. The ASCII value occupied by \ on PCs is the £ symbol in PETSCII. (Actually, it was the backslash on early PET systems, but Commodore changed this to £ for the VIC-20 to appeal to British users.)

So when you see a \x code in a listing, that doesn't mean "type \, X, and a number. That's the way the emulator escapes hexadecimal numbers when printing out BASIC programs to the console.

For example: \X01 is Control+A, \X0D is the RETURN key, and so on.

To enter these codes, use copy and paste. Copy the entire listing to the clipboard, then paste it in to the emulator with Control+V. (Make sure the screen is clear and the cursor is at the top of the screen. Otherwise, you'll lose data.) During a paste operation, the emulator will parse \X codes and will replace the code with the actual character.

if you want to type in a PETSCII code, like \X1D, take a look at a PETSCII character chart, like the one at https://en.wikipedia.org/wiki/PETSCII

As it turns out, \X1D is the cursor-right key. If you type PRINT" (including the quote), then press the right arrow key once, you'll see an inverted ] symbol. This actually stores a $1D character in the program, and when you run the program, that PRINT statement moves the cursor to the right one place.
void_null

Re: Can't type a \ in the emulator.

Post by void_null »

Well, I tried to copy-paste the program from a notepad document. The resulting program was just a bunch of petsci characters that the emulator wouldn't even run. Copy-pasting just the \ symbol inputs a pound sign instead. There just seems to be no way to make this program unless you have ANOTHER basic interpreter you can type the program into. Notepad++ supports blitzbasic, but not basic. Codeblocks also doesn't seem to support it. I know of nothing that would let me type in any form of basic other than the emulator. Does this mean that its simply impossible to write the lightning program on the machine? It must be written and saved on another one?
Last edited by void_null on Thu Apr 13, 2023 5:34 pm, edited 1 time in total.
TomXP411
Posts: 1732
Joined: Tue May 19, 2020 8:49 pm

Re: Can't type a \ in the emulator.

Post by TomXP411 »

void_null wrote: Thu Apr 13, 2023 5:31 pm Well, I tried to copy-paste the program from a notepad document. The resulting program was just a bunch of petsci characters that the emulator wouldn't even run. Copy-pasting just the \ symbol inputs a pound sign instead. There just seems to be no way to make this program unless you have ANOTHER basic interpreter you can type the program into. Notepad++ supports blitzbasic, but not basic. Codeblocks also doesn't seem to support it. I know of nothing that would let me type in any form of basic other than the emulator. Does this mean that its simply impossible to write the lightning program on the machine? It must be written and saved on another one?
All of your text needs to be upper case. The lower case characters in ASCII map to PETSCII graphic characters, so you have to use upper case text exclusively. And the \ character can't be used by itself. It needs to be used as part of a character code, like \X1D.

I've copied and pasted hundreds of BASIC programs now, so I know it works. Try running the emulator with the -echo switch and look at what comes out when you LIST a BASIC program. You can copy that text out to Notepad++, edit it, and then paste it back in.

And it doesn't matter whether Notepad++ provides syntax highlighting for BASIC code. You're just writing text; the syntax highlighting doesn't matter - it's better to just leave it turned off for line-numbered BASIC.
void_null

Re: Can't type a \ in the emulator.

Post by void_null »

Well, how do you enter in such a code then? As I said, you can't type \, so there's no way to type it in. On a side note, I can't figure out what key correlates to 'highlighted' A. Q is down and } is right. Pressing every key on the keyboard I can't figure out what A correlates to. I suspect the return key, but pressing enter just starts a new line.

Also, if the symbol can't be typed in, then why did the original code made on the commodore work fine on the actual cx16 machine with no modification?

Changing all the text to capitals did get the program to display right, and it does technically 'run', though it keeps displaying the pound sign and AQ. I have no way idea how to get it to use the proper characters.
TomXP411
Posts: 1732
Joined: Tue May 19, 2020 8:49 pm

Re: Can't type a \ in the emulator.

Post by TomXP411 »

Like I said, you type the \Xnn code into a text editor, not directly into the emulator.

In a text editor, type in something like :

PRINT "\X07"

Now copy that to the clipboard and paste it in to the emulator.

It should look like this on your screen:
Screenshot 2023-04-13 135429.png
Screenshot 2023-04-13 135429.png (2.68 KiB) Viewed 4734 times
If you press RETURN or ENTER, you should hear a beep when that command runs.



As to the highlighted letters: it's literally Control plus that letter on the keyboard.

Try typing PRINT ", then Control+G. It will show the same thing you pasted above. Press ENTER to hear the beep.


By convention, in both ASCII and PETSCII, Control+A is 01, Control+B is 02, and so on. Following this sequence, the 5 ASCII symbols after Z fill the 27-31 space. Those would be [ \ ] ^ _ on your PC. In PETSCII, they are [ £ ] ↑ ←
void_null

Re: Can't type a \ in the emulator.

Post by void_null »

Well, I was finally able to get this AQ into the emulator (highlighted Q is apparently \X11). The program still isn't working like it does in the video though, and its still printing out a pound symbol rather than \. Is there nothing I can do about it? Clearly the machine can display the thing. Heck, the 8-bit guy's maze program works fine. Of course, it doesn't have the symbol in its code. I have no idea how its encoded though. I would guess its these CHR commands, but I have no idea how to get them into the lightning program. All this for a program that I can't unravel, and clearly won't serve any benefit to me. I was thinking of making a version of breakout in basic (the bouncing balls program being the inspiration for that), though I haven't attempted it yet. I can't unravel the bouncing ball program though, and either way I can't figure out for the life of me how to read input from the keyboard in basic. I would guess the key being pressed is being inserted into some memory address in the IO section, but I have no clue which memory address it is, and making test programs has proven fruitless for some mysterious reason.
TomXP411
Posts: 1732
Joined: Tue May 19, 2020 8:49 pm

Re: Can't type a \ in the emulator.

Post by TomXP411 »

FYI there are diagonal lines: the ╱ and ╲ symbols are used in the simple maze program.

That's not the \ character used in the \Xxx escape codes, however.

Try shift+M and shift+N.

The most common form of the Maze program is something like this:
10 M$(1) = CHR$($CE):M$(2)=CHR$($CD)
20 I=INT(RND(1)*2)+1
30 PRINT M$(I);
40 GOTO 20
You can also substitute shifted M and N, which is converted to lower case in ASCII, like this:

Code: Select all

10 M$(1) = "m":M$(2)="n"
If you copy and paste that line into the emulator, it will look like
10 M$(1) = "╲":M$(2)="╱"
So while \ doesn't exist in the PETSCII character set, ╲ does. Just remember that this is actually the shifted letter M, not the mathematical symbol.

As to "Breakout" - don't use the keyboard. Breakout is supposed to be played with a paddle controller, a spinner, or a mouse. So I'd suggest reading the mouse position (MX) and using that to move the paddle.

Here's something to give you an idea of how that might work:
10 XW=5:LX=1:Y=55:MOUSE 1
100 X=MX/8
110 IF X<2  THEN X=2
120 IF X>80-XW THEN X=80-XW
130 IF X=LX THEN 100
140 LOCATE Y,LX:PRINT"     ";
150 LOCATE 55,X:PRINT "\X12     \X92";
160 LX=X:GOTO 100
void_null

Re: Can't type a \ in the emulator.

Post by void_null »

Well, that helps. Program is still malfunctioning though. For some reason its only printing characters on the side of the screen, and not drawing the image it does on the 8-bit guy's video. I have no idea what could be wrong. The code's the same as in the video (though I found that actually AQ was supposed to be SQ, fixing that doesn't solve the issue at all though it does stop the screen from changing color). What could be wrong? He clearly shows it running on the cx16. I don't get this.

edit: Nevermind, I figured it out. Actually setting the video to fullscreen, I found I had missed a semi-colon on line 40 (and the home key in line 10 too). Now it works, though it only fills part of the screen. The video doesn't give an immediate hint that he set the computer to f4 mode (whatever that resolution is called).

As for the mouse thing, is it possible to hide the mouse? It would be a bit annoying to have it on screen since the pointer clearly serves no purpose for this game.
TomXP411
Posts: 1732
Joined: Tue May 19, 2020 8:49 pm

Re: Can't type a \ in the emulator.

Post by TomXP411 »

What you'd have to do is change the sprite definition. I haven't really played with sprites at all, but I I suspect if you set the sprite to all 0 bytes, it will hide the pointer while still letting the mouse operate.
Post Reply