Using POWER C On An Emulated C64

If you know how, developing code in POWER C using an emulated C64 is not that hard. In contrast to real hardware it even has some advantages.

The light-weight C64 emulator from Thomas Hochgoetz does not support multiple disk drives and no cut & paste, this is why I definitely recommend the VICE emulator for working in POWER C. This is how to do it:

Tell VICE under Preferences / Settings… / Peripheral Devices / Drive that two CBM 1541-II are in use, one as drive 8, the other as drive 9:

Prepare three virtual floppy disks (e.g. with DirMaster),

  • One write-protected disk called „compiler“ that contains everything from the powerc-1.d64 container, which can be found at GitHub
  • One write-protected disk called „object“ that contains everything from the powerc-2.d64 container, also from GitHub
  • One disk called „work“ that will contain the source code files, the object files, and the compiled programs. Make sure that all later required header files are copied on this disk including stdio.h!

In VICE, under File / Attach disk image, attach the virtual floppy disks. Attach the „compiler“ disk as drive 8, the „work“ disk as drive 9:

POWER C can only work with two drives, so attaching the „object“ disk to drive 10 will have no benefit.

Load the POWER C shell with the command

LOAD "*",8,1

and type in „RUN“ when done. At the shell prompt, type in

work 9 0 

This will tell POWER C that drive 9 is used for the work disk. Start the editor with the command „ced“ and type in a small C program like in

/* Hello World */
#include <stdio.h>
#define LOWER 14
int main(void) {
  putchar(LOWER);
  printf ("Hello World!");
return 0;
}

You will notice that most characters can be easily entered if the default symbolic keyboard map is used in VICE. Unfortunately, this is not the case for some special characters that are not part of the PETSCII keyboard but will be mapped internally in the POWER C editor. First and foremost, these are the curly bracket open „{“ and curly bracket close „}“ characters. To get these characters, one must tell VICE to switch to the positional keyboard map under Preferences / Settings… / Input Devices / Keyboard:

After closing the window by clicking „Close“, the curly bracket open „{“ can be entered by hitting SHIFT-ß and the curly bracket close „}“ by hitting SHIFT-´ on the German keyboard. On an US keyboard its SHIFT-minus and SHIFT-equal instead.

  • Curly bracket open { : SHIFT-ssharp „ß“
  • Curly bracket close } : SHIFT-dead_acute „´“
  • Vertical bar | : STRG-plus „+“
  • Backslash \ : less „<„

If all special characters are typed in, the keyboard map can be changed back to the more convenient symbolic map.

Now this process is very cumbersome. If we want to stay in the symbolic key map and do not need the vertical bar often, there is a solution: Add the following lines to your VICE symbolic key map file, in my case gtk3_sym_de.vkm:

# keys for POWER C
question 5 0 8
dead_grave 5 3 8
# arrow-up is caret
# backslash is AltGr-less

and make sure that other lines for question (mark) and dead_grave are commented out. Reload the keyboard mapping and you are good to go.

Next, we hit the ESC key to go into command mode and type in the command „check“. This will start the syntax checker. If the C program was typed in correctly, the „cmd:“ prompt is back and we can save the source code to disk with the command „put h0.c“. h0.c is the name of the new source code file. POWER C knows that our work disk is drive 9 and will store the file there.

Leave the editor with the command „quit“ and enter „cc h0.c“ at the shell prompt. This will start the compiler. You will notice that POWER C will correctly access drive 9 for the header files and the C source code. Drive 8 will be accessed for the compiler:

When POWER C says „enter source disk“, just hit enter (as the source disk is already in drive 9). The next message will be „enter compiler disk“ – again hit enter and POWER C will access disk 8. Last but not least, POWER C will ask for the object disk:

Detach disk 8 and attach the „object“ disk to drive 8 in VICE. Hit enter. As soon as the shell prompt „$“ is back, the work disk will contain the files h0.c and h0.o.

Attach the „compiler“ disk to drive 8 and start the linking process in POWER C by entering the command „link -s“. Enter the object file to link (i.e. h0.o) at the linker prompt. In the next line, tell the linker we are done by entering the arrow-up key („^“ on the keyboard). Before hitting enter, make sure that the „object“ disk is in drive 8:

Note: If even one function is not declared, there will be an error message from the linker and we can start all over again with editing our source code. In this example the function clrscrn( ) was not found by the linker:

In case you would like to know which external references the linker needs to find, hit the enter key before the arrow-up key. Now the linker will tell you each reference that it could not find in our object file, here pointer2.o:

Continue with arrow-up and enter.

As soon as the linker displays a new line with the „>“ prompt, we hit the enter key and enter the file name of the executable, in this case h1.prg. We can now leave the POWER C shell with the „bye“ command and are back in BASIC.

The command

load "h1.prg",9

loads the new executable from drive 9 (the work disk) into memory, „run“ starts the executable:

Note that I switched the character map to „upper / lower characters“ with the BASIC command

poke 53272,23

This ensures that the „Hello World!“ string is being displayed correctly.

The work disk should look like this if two source code files h0.c and h1.c were created:

Note that only h1.o could be linked correctly in this example.

If you read all the way to end of this article, here is a little trick to make your life as a software developer even easier: Create a .81 container with e.g. DirMaster and name it „compiler+object.d81“. Now copy all files from first powerc-1.d64 and then powerc-2.d64 onto this virtual floppy disk. Write-protect the file. Now tell VICE that you have a CBM 1581 disk drive as unit 8:

Again in VICE, mount this virtual floppy disk as unit 8 drive 0:

The CBM 1581 disk drive is a 3.5″ double density floppy drive, which can hold the compiler and object files on one disk.

Instead of playing disk jockey with unit 8 (our first floppy disk drive), now we only have to press the enter key if the compiler or the linker ask for another floppy disk!

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.