Page 2 of 3

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Sun Feb 04, 2024 8:56 am
by TomXP411
FuzzySilk wrote: Sat Feb 03, 2024 9:40 pm Ok so right now I think the port looks best in the lower rez screen, just hit the 40/80 display button before you run it.
`SCREEN 3` is your friend. That's the 40x30 text mode that approximates the typical 80s 8-bit computer screen.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Sun Feb 04, 2024 5:46 pm
by mortarm
TomXP411 wrote: Sun Feb 04, 2024 8:56 am SCREEN 3 is your friend.
My go-to screen. Would've been nice of they included a true C=64 sized (40x25) screen and an 80x25 screen, which was most common with terminals and PCs. They could make room by dumping screens 5 and 6 which probably won't get much use, being only 20 characters wide.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Sun Feb 04, 2024 6:19 pm
by FuzzySilk
TomXP411 wrote: Sun Feb 04, 2024 8:56 am
FuzzySilk wrote: Sat Feb 03, 2024 9:40 pm Ok so right now I think the port looks best in the lower rez screen, just hit the 40/80 display button before you run it.
`SCREEN 3` is your friend. That's the 40x30 text mode that approximates the typical 80s 8-bit computer screen.
Thank you for the info on the screen, I'll use that for this direct port. I'm hoping to redisgn the program with a better layout and functionality, so still need to decide what resolution I'll use. Might like to have the map up and the menu options available at all times.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Sun Feb 04, 2024 6:46 pm
by FuzzySilk
TomXP411 wrote: Sat Feb 03, 2024 6:52 pm The good news is Commander has a COLOR command, so the POKE to change color can be done with COLOR.

The SYS for RESET is also not needed. We have a RESET command that actually does a hardware reset of the system.
Thanks for the info. Yes COLOR should work nice. From what I have been able to figure out this program manipulates the position of the cursor a lot in the print commands. Specially for the map. It seems to have a short hand for the CHR$() codes. These don't seem to work in c64 or Commander X16 BASIC is you just put in the rawl code. If I create a prg file using CBM PRG Studio understands short hand in the print commands. It's able to create a working PRG file from the code.

I've been trying to covert to actually using the CHR$() codes. But I can't figure out how to do multiples other then a for loop as a multiplication just gives a type mismatch. For example:

240 PRINT"{REVERSE ON}TRY AGAIN{REVERSE OFF}{SPACE*7}"

I tried: 240 PRINT CHR$(18); "TRY AGAIN"; CHR$(146); CHR$(32)*7;
But that gives you the type mismatch, so the only way I have been able to figure out how to do it is like this:
240 PRINT CHR$(18); "TRY AGAIN"; CHR$(146);
245 FOR I = 1 to 7: PRINT CHR(32);: NEXT I

if someone knows a better way to multiply CHR$() codes it would appreciate it. CBM PRG Studio understands the sort hand and is obviously tokenizing it somehow so it works.

I've been using copy paste to change to the CHR$() but it keeps it in the quotes and like I said anything that with * x does not work. I'll include what I have changed so far, it does not work. Need to take all the codes out of quotes and need to put code in for multiples.

Not sure how much I'll work on this as it might be better for me to recreate everything the way I want.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Sun Feb 04, 2024 10:03 pm
by TomXP411
FuzzySilk wrote: Sun Feb 04, 2024 6:46 pm I've been trying to covert to actually using the CHR$() codes. But I can't figure out how to do multiples other then a for loop as a multiplication just gives a type mismatch. For example:

240 PRINT"{REVERSE ON}TRY AGAIN{REVERSE OFF}{SPACE*7}"
Those are called Tok64 codes. They were a convention started in type-in magazines in the 80s. It just means you need to press that key when typing in the code, or you can use the PETCAT program that comes with the VICE emulation suite to turn it back into a PRG file. (I'm also working on a tokenizer that will do this, but I've got a few things ahead of that on my to-do list.)

So the key is quote mode. In Commodore BASIC, typing a quote puts you in quote mode, where the editor inserts the raw values for command keys (arrow keys, control+letter, colors, F-keys). These are displayed in reverse print. A-Z represent PETSCII 1-26, and [ £ ] ↑ ← represent 27-31.

At the keyboard, if you type PRINT " and then press Control+9 (the Rvs On key), you'll see an inverted R after the quote. Any text printed after that will be in inverse print, until the next CR, Shift+CR, or Rvs Off (Control+0).

Pressing the INS (Insert) key also triggers quote mode for 1 character. So you can use that to quickly insert a single command character.

Resolving the issue

While the X16 emulator does not support tok64 codes, it does support a different shorthand: \X hex codes. In this case, Rvs On is \X12.

You can get the hex for any control code this way:
PRINT HEX$(ASC("{Control+9}"))
12
█
The {SPACE*7} literally just means "press the space bar 7 times."

So for line 240, what you need to do is manually convert those tok64 codes to either hex codes or simply edit them in the emulator.

Approach 1: In a text editor, edit the line to look like this:
240 PRINT "\X12TRY AGAIN\X92 "

Approach 2:
leave the tok64 codes in the string. Paste the program into the emulator, then LIST 240
Move the cursor to +REVERSE ON|. Delete that and press INS one time. Press Control+9.
You should now have an inverse R in front of TRY AGAIN.
Now go to the +SPACE * 7| and type over that with 7 spaces, removing the extra 4 characters with the Delete key.

I hope that helps a little.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Mon Feb 05, 2024 2:58 am
by FuzzySilk
TomXP411 wrote: Sun Feb 04, 2024 10:03 pm
Those are called Tok64 codes. They were a convention started in type-in magazines in the 80s. It just means you need to press that key when typing in the code, or you can use the PETCAT program that comes with the VICE emulation suite to turn it back into a PRG file. (I'm also working on a tokenizer that will do this, but I've got a few things ahead of that on my to-do list.)

So the key is quote mode. In Commodore BASIC, typing a quote puts you in quote mode, where the editor inserts the raw values for command keys (arrow keys, control+letter, colors, F-keys). These are displayed in reverse print. A-Z represent PETSCII 1-26, and [ £ ] ↑ ← represent 27-31.

At the keyboard, if you type PRINT " and then press Control+9 (the Rvs On key), you'll see an inverted R after the quote. Any text printed after that will be in inverse print, until the next CR, Shift+CR, or Rvs Off (Control+0).

Pressing the INS (Insert) key also triggers quote mode for 1 character. So you can use that to quickly insert a single command character.

Resolving the issue

While the X16 emulator does not support tok64 codes, it does support a different shorthand: \X hex codes. In this case, Rvs On is \X12.

You can get the hex for any control code this way:
PRINT HEX$(ASC("{Control+9}"))
12
█
The {SPACE*7} literally just means "press the space bar 7 times."

So for line 240, what you need to do is manually convert those tok64 codes to either hex codes or simply edit them in the emulator.

Approach 1: In a text editor, edit the line to look like this:
240 PRINT "\X12TRY AGAIN\X92 "

Approach 2:
leave the tok64 codes in the string. Paste the program into the emulator, then LIST 240
Move the cursor to +REVERSE ON|. Delete that and press INS one time. Press Control+9.
You should now have an inverse R in front of TRY AGAIN.
Now go to the +SPACE * 7| and type over that with 7 spaces, removing the extra 4 characters with the Delete key.

I hope that helps a little.
This helps a lot! Thanks! :D I get what you are saying for the spaces but there is code that moves up, down and to the left. I can’t simulate that by hitting the space bar. I’l have to figure out the hex code for them. But now I have an understanding what this is and how to deal with it.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Mon Feb 05, 2024 4:06 am
by TomXP411
FuzzySilk wrote: Mon Feb 05, 2024 2:58 amThis helps a lot! Thanks! :D I get what you are saying for the spaces but there is code that moves up, down and to the left. I can’t simulate that by hitting the space bar. I’ll have to figure out the hex code for them. But now I have an understanding what this is and how to deal with it.
Cursor movement is one of the things you can do in quote mode. If you see {up} or {up 3}, then replace that by just pressing cursor up while in quote mode (once for just {up} and 3 times for {up 3}).

You can also use LOCATE if you know where the cursor needs to be. That's actually the preferred method now, since LOCATEs are absolute.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Mon Feb 05, 2024 10:34 pm
by FuzzySilk
Yes LOCATE seems a lot better. Looking at this persons code it is crazy the way they manipulated the cursor.

He has a couple of variables he sets up that they setup and use through out.
100 SP$="{space*39}"
110 VTB$="{home}{down*25}"

Then has lines like this:
990 PRINTLEFT$(VTB$,21)LEFT$(SP$,24)"defender fires":I=0
1000 I=I+1:PRINTLEFT$(VTB$,19)SPC(19)"{space*2}{down}{left*2}{cm d}{cm f}{down}{left*2}{cm c}{cm v}{down}{left*2}{space*2}";:GOSUB180
1010 PRINT"{up*2}{left*2}{space*2}{down}{left*2}{space*2}"

180 RETURN

I think the variables are used for the star field. And I see so many GOSUBs that just go to a return. What's the purpose of that, time delay? Figuring out this spaghetti code is rough.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Mon Feb 05, 2024 11:24 pm
by ahenry3068
FuzzySilk wrote: Mon Feb 05, 2024 10:34 pm
I think the variables are used for the star field. And I see so many GOSUBs that just go to a return. What's the purpose of that, time delay? Figuring out this spaghetti code is rough.
It would seem pretty odd to me to use an EMPTY GOSUB as a Time Delay. Thinking of my Own BASIC coding style I might have an empty GOSUB either as a place Holder for code I intend to write but haven't written yet. (In which case I would expect a REM there) Or possibly to preserve Program flow if I deprecate code that I no longer want to use.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Tue Feb 06, 2024 6:05 am
by Ser Olmy
FuzzySilk wrote: Mon Feb 05, 2024 10:34 pm Yes LOCATE seems a lot better. Looking at this persons code it is crazy the way they manipulated the cursor.
Commodore BASIC V2 didn't have any commands for cursor control, so short of manipulating the cursor position by POKEing values into locations 211 and 214, using control characters was basically (ahem) the only way to do it.

Doing cursor positioning involves first printing the "home" character (which looks like an inverse letter S when typed in quote mode), which places the cursor in the upper left corner, and then a number of "cursor right" characters (inverse closed square bracket) from the for the X position, and finally a number of "cursor down" characters (inverse letter Q) for the Y position. Of course, you can do the latter two in any order.

The original author's solution of having two string variables contain a sequence of "cursor right" and "cursor down" control characters respectively, makes the code much more readable. He could then easily produce the required number of characters using the LEFT$ function, which coincidentally (and conveniently) will return an empty string if the number of characters requested is 0.

My only real criticism is that he chose to include the "home" character in the Y position string, which does confuse matters somewhat, and his use of a three-letter variable name: "VTB$" could cause issues, as it will be interpreted as just "VT$" and would clash with any other string variable name starting with "VT".