Software

The PC compatibility software layer works on the hardware 8088 card and contains routines that emulate the PC BIOS and other aspects of the PC architecture to achieve a high degree of PC compatibility. The software consists of the following functional parts:

PC BIOS emulation

The software contains around 40 BIOS functions of INT 10h, INT 13h, INT 16h and so on (see the GitHub repository for complete list). The functions serve as a bridge between the PC BIOS interface and the IPC library that runs on the 6509 CPU. For example, INT 16h function 00h (read from keyboard buffer) is implemented as a wrapper for the IPC library function $11, which in turn calls the GETIN function in the Commodore KERNAL to read the input buffer.

Some BIOS functions are simple wrappers like that, while others require more sophisticated processing. For example INT 13h functions are used to simulate a PC disk drive with an 8050 or 8250 Commodore drive. This requires sector position recalculation because the PC disk geometry is vastly different than that of the 8050, plus simulating 512 byte PC disk sectors with two 256 byte Commodore disk sectors.

Additionally, an 18.2 Hz timer interrupt is implemented on INT 8 just like on the PC, by programming the CIA timers A and B to generate a square wave. Because the IRQs are assigned differently on the 8088 card than on the PC (for example, the timer interrupt is IRQ0 on the PC but IRQ7 on the card), the interrupt vectors are remapped into INT 50h-57h and code was added to call appropriate PC interrupt vectors from IRQ handler routines.

Video memory emulation

Most PC software does not use the BIOS for screen output, because direct manipulation of the video memory at segment 0B000h is much faster. To maintain compatibility with these applications, a software emulation of video memory was added which periodically copies the contents of this memory area into the Commodore video memory at $D000.

This routine is run periodically when the CPU is idle, for example when waiting for keyboard input. It converts the PC video characters into appropriate PETSCII equivalents and sets the character reverse bit according to the character attributes, thus emulating an MDA text adapter closely. A hardware latch register was added to the board, which latches bits when a specific region of the video memory is written by the CPU; this way, the routine works much faster because it needs to refresh only the modified screen regions.

Hardware virtualization

To allow compatibility with PC applications that access the PC hardware directly, the concept of hardware virtualization was created. It works as follows: whenever the applications tries to access a hardware device using IN or OUT instructions, a NMI interrupt is generated. The address of the I/O port is latched, so that the NMI handler routine can see which hardware device is being accessed. It can then perform necessary actions to simulate the workings of this hardware device.

As an example, an emulation of the PC speaker was created by hooking up code on accesses to ports 42h and 61h. This code checks the frequency of the sound that’s being generated and uses the specifically created IPC $1D function which programs the SID chip on the Commodore to play the same sound.

Card hardware support

The card contains several hardware features that need software support, for example:

  • The SPI interface is used to attach a memory card. This card is visible to the PC applications via the INT 13h interface as an 8 GB hard disk, which can be used to boot DOS.
  • The I2C interface is used to attach a real time clock, which is visible to the PC applications via the INT 1Ah interface.
  • The card configuration registers are used to select the system clock frequency. The card boots with the 8 MHz clock, but if the NEC V20 processor is detected, it is switched to faster 12 MHz clock.

The software also re-implements a portion of the original Commodore KERNAL to fix a race condition bug which occurs when the RS-232 port is being used with the card.