Page 1 of 3

Translate Peeks and Pokes from c64 BASIC Program?

Posted: Fri Feb 02, 2024 2:46 pm
by FuzzySilk
I’m fairly new to Retro programming. But I have a Computer Science degree and when I went to college I learned Assembly, Pascal, and C. I currently mostly program in Python or Groovy for my job. I’m 54 so it’s been quite some time since I did assembly but I understand the basics and have been watching a lot of the community’s tutorials on assembly for the 650c2 and even bought a book. So I’m relearning.

Here’s my question, I have a C64 BASIC program I want to port to the Commander X16 but it definitely has Peeks and Pokes in it. What’s the best way to translate those to the Cammander X16. Do you need to use a disassembler? Are there certain Peeks and Pokes that you just can’t translate to the Commander X16 due to the architecture? Are there common peeks and pokes that were used on the c64 that the community have all ready figured out and translated?

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Fri Feb 02, 2024 3:35 pm
by JimmyDansbo
AFAIK, if you want to translate a program from C64 to X16, you need to know exactly what the different peeks and pokes does.

It may not be necessary to disassemble the entire program, but you do need to know what the different peeks and pokes do in order to convert it to something that works on the X16

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Fri Feb 02, 2024 4:56 pm
by skaratso
I'm not very familiar with Commodore-type computers, having grown up with Apple II machines, but just like with Apples, I'm sure there are lists of common PEEKs and POKEs for the Commodore 64 you can find online. Some will be very straightforward to replace, such as the POKE commands to change text screen background and border color, as those can be replaced with commands on the X16. PEEKs and POKEs for graphics and sound will be completely different (fortunately those have been replaced with actual BASIC commands), as will ones intended for POKE-ing text directly to the screen (instead of using PRINT statements).

Look for SYS statements as well. Some might be KERNEL calls, which can be translated to the X16 relatively easily, but if the program has any machine language subroutines those will need to be rewritten for the X16. You can identify those usually by seeing a list of DATA statements followed by a bunch of numbers and then there will be a section in the program where there's a FOR...NEXT loop where the DATA statements are read and POKEd into memory.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Fri Feb 02, 2024 6:04 pm
by mortarm
In addition to what has been discussed, check, if possible, to see which version of the 64 the program is intended for as the memory maps can vary between models. If it doesn't say it's probably for the original "breadbin" version.

Here's a breakdown of the original memory map from the C64 Wiki:
https://www.c64-wiki.com/wiki/Memory_Map

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Fri Feb 02, 2024 6:06 pm
by Ser Olmy
FuzzySilk wrote: Fri Feb 02, 2024 2:46 pmHere’s my question, I have a C64 BASIC program I want to port to the Commander X16 but it definitely has Peeks and Pokes in it. What’s the best way to translate those to the Cammander X16.
As JimmyDansbo pointed out, you will have to know what the various addresses do in order to port the program to the X16.

A C64 BASIC program may perform PEEKs and POKEs into memory for at least four different reasons:
  1. Graphics and/or sprites: As BASIC V2 contains no commands for either, direct memory and VIC-II register access via POKE and PEEK is the only way to use these features.
  2. Sound: As above, BASIC V2 has no commands to access the SID PSG.
  3. System variables: POKEs may be used to alter various KERNAL/BASIC settings, such as lowering the top of BASIC memory.
  4. Assembly routines: Some BASIC programs make use of (typically quite short) assembly language programs that are POKEd into memory and called with the SYS command.
I'm sure there are many other use cases as well, such as reading from or writing to the CIA registers that control the interrupt timers or the memory banking for the VIC-II.

To figure out what a specific address does, consult a memory map for the Commodore 64, like this one.
FuzzySilk wrote: Fri Feb 02, 2024 2:46 pmDo you need to use a disassembler?
Huh? Why would one need a disassembler in order to figure out what a POKE command in BASIC does?
FuzzySilk wrote: Fri Feb 02, 2024 2:46 pmAre there certain Peeks and Pokes that you just can’t translate to the Commander X16 due to the architecture?
There certainly are POKE commands that cannot be directly translated, such as values written to the various SID registers. Since neither of the sound chips in the X16 resemble the SID, one would have to use entirely different commands and/or values to reproduce a similar sound.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Fri Feb 02, 2024 6:08 pm
by Ser Olmy
mortarm wrote: Fri Feb 02, 2024 6:04 pm In addition to what has been discussed, check, if possible, to see which version of the 64 the program is intended for as the memory maps can vary between models.
The memory map is identical for all revisions of the C64.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Fri Feb 02, 2024 9:02 pm
by FuzzySilk
Wow thank you everyone for all this information! :D This definitely helps a lot. Now I know what I’ll be researching, messing with this weekend.

I actually want to port this game “Galaxy” that my friend and I actually played on the Atari 800 from tape cassette, but they have a port on the c64. Believe it was originally on Apple II. I plan on porting it first in BASIC and then writing my own version with updated graphics and other features.


https://en.wikipedia.org/wiki/Galaxy_(video_game)
https://www.mobygames.com/game/14769/galaxy/

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Sat Feb 03, 2024 5:55 pm
by FuzzySilk
OK so I have a version that some what works. There were only a couple of pokes and there is a sys section but I took those out as it looked like the program would run with out them.

90 PRINT"{clear}{light gray}":POKE53280,6:POKE53281,0

POKE 53280,C change border color (C=0-15)
POKE 53281,C change screen color (C=0-15)

3390 POKE198,0:PRINT"{clear}"LEFT$(VTB$,8):INPUT"how many players (1-20)";PN

POKE 198,0 Clears Keyboard Buffer (Default Value 198,0)

AND there is this part:
2090 SYS64738

Which a quick google search comes up with this:
SYS 64738 is a Commodore 64 C-64 ROM routine that would reset the computer (as if it were turned off and then on again).

The rest of the code is just BASIC.

Now I'll start making changes. And refactor the code the way I wan it. First I'll add the proper screen background, then sound, and it's running too fast. And get rid of all the tape code as it is not needed.

I do need to figure out the back arrow key as it's mapped as the excape key for c64 and you need to hit that to open the map or save, change the turns etc.
gal3.prg
prg I created from CPMprogstudio
(11.86 KiB) Downloaded 407 times
galaxy!2.bas
code I extracted
(17.69 KiB) Downloaded 369 times

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Sat Feb 03, 2024 6:52 pm
by TomXP411
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.

Re: Translate Peeks and Pokes from c64 BASIC Program?

Posted: Sat Feb 03, 2024 9:40 pm
by FuzzySilk
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.

Also I figured out that on the Commander X-16 the F1 key brings up the in game menu.