Translate Peeks and Pokes from c64 BASIC Program?

All aspects of programming on the Commander X16.
TomXP411
Posts: 1783
Joined: Tue May 19, 2020 8:49 pm

Re: Translate Peeks and Pokes from c64 BASIC Program?

Post by TomXP411 »

Ser Olmy wrote: Tue Feb 06, 2024 6:05 amMy 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".
Including Home as the first row character is the correct way to do it. If Y=1, then the cursor lands on the top row of the screen, and you don't need to do any math.

This way, you don't need to do any math: you can just
PRINT LEFT$(YY$,Y);TAB(X);
Which gives you the fastest, simplest expression possible.

Of course, looking at the Galaxy! code, it looks like SP$ is being used to clear lines of text, rather than just positioning.

Honestly, if I was converting this game, I'd probably leave all the PETSCII stuff just like it is. It works, and it's kind of fun seeing how people got around the lack of absolute cursor positioning using things like this.
TomXP411
Posts: 1783
Joined: Tue May 19, 2020 8:49 pm

Re: Translate Peeks and Pokes from c64 BASIC Program?

Post by TomXP411 »

I don't know if you've already dealt with this one...

3390 POKE 198,0
This clears the keyboard buffer. Another way is just to use GET to read the keyboard until nothing is left:
3390 GET A$:IF A$<>"" GOTO 3390
There's some stuff on the line after the POKE, but that can move to 3395
FuzzySilk
Posts: 15
Joined: Sat Jun 27, 2020 1:53 pm

Re: Translate Peeks and Pokes from c64 BASIC Program?

Post by FuzzySilk »

TomXP411 wrote: Tue Feb 06, 2024 5:34 pm I don't know if you've already dealt with this one...

3390 POKE 198,0
This clears the keyboard buffer. Another way is just to use GET to read the keyboard until nothing is left:
3390 GET A$:IF A$<>"" GOTO 3390
There's some stuff on the line after the POKE, but that can move to 3395
Yeah I looked the three POKE commands up and just deleted them for now. But this is good to know. Thanks.
FuzzySilk
Posts: 15
Joined: Sat Jun 27, 2020 1:53 pm

Re: Translate Peeks and Pokes from c64 BASIC Program?

Post by FuzzySilk »

ahenry3068 wrote: Mon Feb 05, 2024 11:24 pm
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.
Yeah I’m not saying it was a time delay but I have definitely found it through out the code. I have not been able to figure out the purpose other then as you say a place holder that the coder never ended up using, or just to make it harder to read their code… lol
Last edited by FuzzySilk on Wed Feb 07, 2024 1:23 am, edited 1 time in total.
FuzzySilk
Posts: 15
Joined: Sat Jun 27, 2020 1:53 pm

Re: Translate Peeks and Pokes from c64 BASIC Program?

Post by FuzzySilk »

TomXP411 wrote: Tue Feb 06, 2024 4:58 pm
Ser Olmy wrote: Tue Feb 06, 2024 6:05 amMy 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".
Including Home as the first row character is the correct way to do it. If Y=1, then the cursor lands on the top row of the screen, and you don't need to do any math.

This way, you don't need to do any math: you can just
PRINT LEFT$(YY$,Y);TAB(X);
Which gives you the fastest, simplest expression possible.

Of course, looking at the Galaxy! code, it looks like SP$ is being used to clear lines of text, rather than just positioning.

Honestly, if I was converting this game, I'd probably leave all the PETSCII stuff just like it is. It works, and it's kind of fun seeing how people got around the lack of absolute cursor positioning using things like this.
It is interesting but not sure if I want to go that route when I rewrite my own version of this game.
FuzzySilk
Posts: 15
Joined: Sat Jun 27, 2020 1:53 pm

Re: Translate Peeks and Pokes from c64 BASIC Program?

Post by FuzzySilk »

Ser Olmy wrote: Tue Feb 06, 2024 6:05 am
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".
I was trying to find where the LEFT$ function was defined as I couldn’t find it in the code, other than it being used through out the code. Is it part of c64 BASIC and is it part of Commander X16 BASIC? I know they both use Microsoft BASIC V2 with the caveat that the PEEKs and POKEs from the c64 don’t work and the Commander X16 has some additional commands.


Edit: OK I found it in the BASIC docs, should have looked there originally. Belay my questions. I found it! :D
Post Reply