POWER C coding supported by AI

For the last couple of days, I was writing code to calculate Mandelbrot numbers and put them on the screen in multi-color bitmap mode on the Commodore 64. Writing the Mandelbrot algorithm took me a while, as POWER C messed with my struct that I handed over to various functions, i.e. for calculating the square of a complex number. I got rid of all functions that worked on struct objects, moved all calculations into main( ) and the code was working. Not elegant but working.

Next I wanted to create a function to take a pixel (x,y) with a certain color and put it on the screen. As I had some real issues getting even basic code to work in multi-color bitmap mode, I asked Google Gemini for help.

Well, Google Gemini was very brave in tackling this challenge. Unfortunately, the code versions created by Gemini also did not work. The AI tried to help me troubleshoot the issues, but in some cases made strange beginner mistakes, like displaying a text when the system had been switched to bitmap mode already.

I eventually gave up and consulted OpenAI’s ChatGPT. After uploading the latest code, I explained to ChatGPT what I had done up to this point and what the errors were. ChatGPT answered with

I found several problems in the code. At least three are genuine programming errors, and one of them explains why the screen remains gray instead of turning black.

Wow, this looks promising! Two of the problems happened because of me transferring the code from the C64 to a Windows environment, which screwed up characters like „|“ and „~“, which I forgot to correct.

In the next iteration, ChatGPT found 5 problems, which I all corrected. ChatGPT explained every problem in detail and I was very impressed. Still, the code did not work. Maybe ChatGPT sensed my frustration and finally suggested

I can also rewrite the entire program as a clean, corrected POWER C source file, preserving compatibility with the Commodore 64 and its VIC-II graphics hardware. That would be my preferred next step rather than trying to patch Gemini’s code one error at a time.

Looks like ChatGPT does not believe Gemini’s good reputation in coding software. ChatGPT noticed my growing frustration after working for days on a couple of dozen lines of code and tried to boost my moral by saying

We’ll get this working. The C64’s multicolor bitmap mode is a little tricky, but we can isolate the problems one at a time.

Like a perfect human, it even admitted to making mistakes during the process:

I made a mistake when I told you to change $D018 from $18 to $48. The original value, $18, was correct. I’m sorry about that.

What made me wonder is that neither POWER C nor Google Gemini nor ChatGPT found a typing error in the code:

int set_block_colors(cell_x,cell_y,col_01,col_10,col11)
...
char col_11;

The definition of function set_block_colors lists „col11“ as a parameter, which is later declared as „col_11“!

Something that caught my attention was that Gemini and ChatGPT both mentioned possible bugs in POWER C, especially with memory management. I ignored this until, hours later, I really had enough. ChatGPT wanted to do

One more test, please

And I agreed. After this test failed, I told the AI that I needed a break, and this time the AI agreed with

I know how frustrating it is when something that should be straightforward turns into hours of chasing problems.

Again, very human. By the way, the POWER C code had another strange issue: The code waited for a key press. After receiving it, I had to press RUN/STOP to get the prompt back. The background and border colors were not restored as they should be.

Today I abandoned POWER C and used a non-native compiler: cc65 in version 2.18. And what can I say? cc65 detected the „col11“ mistake above, showed me some warnings for dirty code, and finally after fixing compiled the code. I transferred the binary over to the C64, loaded it into RAM, ran it and voila, the code is fine now!

My resume is two-fold:

a) When using AI to support software development, one must be careful when writing code for old platforms and old compilers. The AI systems do their best and the user can learn a lot in the process, but the AI might make mistakes, like in my case.

b) POWER C has definitely replicable issues and I would not recommend it anymore. The problem with struct objects took me at least two days to figure out. GCC had no issue with the same code, using struct objects in functions by value and by reference. In addition, I can prove that POWER C messes up memory management in bitmap mode. In short: Use Visual Studio VS64 to cross develop software for the C64, or, like it was working for me very easily, use the cc65 cross compiler on a platform like Linux or Windows. This has the additional advantage that your are not stuck with old pre-ANSI C code.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert


Der Zeitraum für die reCAPTCHA-Überprüfung ist abgelaufen. Bitte laden Sie die Seite neu.