KERNAL

Last updated

KERNAL [1] is Commodore's name for the ROM-resident operating system core in its 8-bit home computers; from the original PET of 1977, followed by the extended but related versions used in its successors: the VIC-20, Commodore 64, Plus/4, Commodore 16, and Commodore 128.

Contents

Description

The Commodore 8-bit machines' KERNAL consists of the low-level, close-to-the-hardware OS routines roughly equivalent to the BIOS in IBM PC compatibles (in contrast to the BASIC interpreter routines, also located in ROM) as well as higher-level, device-independent I/O functionality. It is user-callable via a jump table in RAM whose central (oldest) part, for reasons of backwards compatibility, [2] remains largely identical throughout the whole 8-bit series. The KERNAL ROM occupies the last 8 KB of the 8-bit CPU's 64 KB address space ($E000–$FFFF).

The jump table can be modified to point to user-written routines, for example, to integrate a fast loader so that its fast replacement routines are used system-wide or to replace the system text output routine with one that works in bitmapped mode rather than character mode. This use of a jump table was new to small computers then. [3]

The Adventure International games published for the VIC-20 on the cartridge are an example of software that uses the KERNAL. Because they only use the jump table, the games can be memory dumped to disk, loaded into a Commodore 64, and run without modification. [4]

The KERNAL was initially written for the Commodore PET by John Feagans, who introduced the idea of separating the BASIC routines from the operating system. It was further developed by several people, notably Robert Russell, who added many of the features for the VIC-20 and the C64.

Example

A simple, yet characteristic, example of using the KERNAL is given by the following 6502 assembly language subroutine [5] (written in ca65 assembler format/syntax):

   CHROUT  = $ffd2          ; CHROUT is the address of the character output routine    CR      = $0d            ; PETSCII code for Carriage Return     ;    hello:            ldx #0           ; start with character 0 by loading 0 into the x index register    next:            lda message,x    ; load byte from address message+x into the accumulator            beq done         ; if the accumulator holds zero, we're done and want to branch out of the loop            jsr CHROUT       ; call CHROUT to output char to current output device (defaults to screen)            inx              ; increment x to move to the next character            bne next         ; loop back while the last character is not zero (max string length 255 bytes)    done:            rts              ; return from subroutine    ;    message:            .byte "Hello, world!"            .byte CR, 0      ; Carriage Return and zero marking end of string

This code stub employs the CHROUT routine, whose address is found at address $FFD2 (65490), to send a text string to the default output device (e.g., the display screen).

The name

The KERNAL was known as kernel [6] inside of Commodore since the PET days, but in 1980 Robert Russell misspelled the word as kernal in his notebooks. When Commodore technical writers Neil Harris and Andy Finkel collected Russell's notes and used them as the basis for the VIC-20 programmer's manual, the misspelling followed them along and stuck. [7]

According to early Commodore myth, and reported by writer/programmer Jim Butterfield among others, the "word" KERNAL is an acronym (or, more likely, a backronym) standing for Keyboard Entry Read, Network, And Link, which in fact makes good sense considering its role. Berkeley Softworks later used it when naming the core routines of its GUI OS for 8-bit home computers: the GEOS KERNAL.

On device-independent I/O

Surprisingly, the KERNAL implemented a device-independent I/O API not entirely dissimilar from that of Unix or Plan-9, which nobody actually exploited, as far as is publicly known. Whereas one could reasonably argue that "everything is a file" in these latter systems, others could easily claim that "everything is a GPIB-device" in the former.

Due to limitations with the 6502 architecture at the time, opening an I/O channel requires three system calls. The first typically sets the logical filename through the SETNAM system call. The second call, SETLFS, establishes the GPIB/IEEE-488 "device" address to communicate with. Finally OPEN is called to perform the actual transaction. The application then used CHKIN and CHKOUT system calls to set the application's current input and output channels, respectively. Applications may have any number of concurrently open files (up to some system-dependent limit; e.g., the C64 allows for ten files to be opened at once). Thereafter, CHRIN and CHROUT prove useful for actually conducting input and output, respectively. CLOSE then closes a channel.

Observe that no system call exists to "create" an I/O channel, for devices cannot be created or destroyed dynamically under normal circumstances. Likewise, no means exists for seeking, nor for performing "I/O control" functions such as ioctl() in Unix. Indeed, the KERNAL proves much closer to the Plan-9 philosophy here, where an application would open a special "command" channel to the indicated device to conduct such "meta" or "out-of-band" transactions. For example, to delete ("scratch") a file from a disk, the user typically will "open" the resource called S0:THE-FILE-TO-RMV on device 8 or 9, channel 15. Per established convention in the Commodore 8-bit world, channel 15 represents the "command channel" for peripherals, relying on message-passing techniques to communicate both commands and results, including exceptional cases. For example, in Commodore BASIC, they might find software not unlike the following:

70...80REM ROTATE LOGS CURRENTLY OPENED ON LOGICAL CHANNEL #1.90CLOSE1100OPEN15,8,15,"R0:ERROR.1=0:ERROR.0":REM RENAME FILE ERROR.0 TO ERROR.1110INPUT#15,A,B$,C,D:REM READ ERROR CHANNEL120CLOSE15130IFA=0THENGOTO200140PRINT"ERROR RENAMING LOG FILE:"150PRINT"  CODE: "+A160PRINT"  MSG : "+B$170END200REM CONTINUE PROCESSING HERE, CREATING NEW LOG FILE AS WE GO...210OPEN1,8,1,"0:ERROR.0,S,W"220...

Device numbers, per established documentation, are restricted to the range [0,16]. However, this limitation came from the specific adaptation of the IEEE-488 protocol and, in effect, applies only to external peripherals. With all relevant KERNAL system calls vectored, programmers can intercept system calls to implement virtual devices with any address in the range of [32,256]. Conceivably, one can load a device driver binary into memory, patch the KERNAL I/O vectors, and from that moment forward, a new (virtual) device could be addressed. So far, this capability has never been publicly known as utilized, presumably for two reasons: (1) The KERNAL provides no means for dynamically allocating device IDs, and (2) the KERNAL provides no means for loading a relocatable binary image. Thus, the burden of collisions both in I/O space and in memory space falls upon the user, while platform compatibility across a wide range of machines falls upon the software author. Nonetheless, support software for these functions could easily be implemented if desired.

Logical filename formats tends to depend upon the specific device addressed. The most common device used, of course, is the floppy disk system, which uses a format similar to MD:NAME,ATTRS, where M is a flag of sorts ($ for directory listing, @ for indicating a desire to overwrite a file if it already exists, unused otherwise.), D is the (optional) physical disk unit number (0: or 1: for dual-drive systems, just 0: for single-disk units like the 1541, et al., which defaults to 0: if left unspecified), NAME is a resource name up to 16 characters in length (most characters allowed except for certain special characters), and ATTRS is an optional comma-separated list of attributes or flags. For example, if the user wants to overwrite a program file called PRGFILE, they might see a filename like @0:PRGFILE,P used in conjunction with device 8 or 9. Meanwhile, a filename for the RS-232 driver (device 2) consists simply of four characters, encoded in binary format. [8]

Other devices, such as the keyboard (device 0), cassette (device 1), the display interface (device 3), and printer (device 4 and 5), require no filenames to function, either assuming reasonable defaults or simply not needing them at all.

Notes

  1. Commodore 64 Programmer's Reference Guide. Commodore Business Machines, Inc., 1982, p. 268
  2. The KERNAL jump table, used to access all the subroutines in the KERNAL, is an array of JMP (jump) instructions leading to the actual subroutines. This feature ensures compatibility with user-written software in the event that code within the KERNAL ROM needs to be relocated in a later revision.
  3. "Exploring the VIC-20". January 1983.
  4. Kevelson, Morton (January 1986). "Speech Synthesizers for the Commodore Computers / Part II". Ahoy!. p. 32. Retrieved 17 July 2014.
  5. Many of the KERNAL subroutines (e.g., OPEN and CLOSE) were vectored through page three in RAM, allowing a programmer to intercept the associated KERNAL calls and add to or replace the original functions.
  6. The kernel is the most fundamental part of a program, typically an operating system, that resides in memory at all times and provides the basic services. It is the part of the operating system that is closest to the machine and may activate the hardware directly or interface to another software layer that drives the hardware
  7. On The Edge: The Spectacular Rise and Fall of Commodore, page 202.
  8. Commodore 128 Programmers Reference Guide, Commodore Business Machines, Inc., 1986, p. 382

Related Research Articles

Applesoft BASIC is a dialect of Microsoft BASIC, developed by Marc McDonald and Ric Weiland, supplied with the Apple II series of computers. It supersedes Integer BASIC and is the BASIC in ROM in all Apple II series computers after the original Apple II model. It is also referred to as FP BASIC because of the Apple DOS command FP used to invoke it, instead of INT for Integer BASIC.

<span class="mw-page-title-main">Commodore 64</span> 8-bit home computer introduced in 1982

The Commodore 64, also known as the C64, is an 8-bit home computer introduced in January 1982 by Commodore International. It has been listed in the Guinness World Records as the highest-selling single computer model of all time, with independent estimates placing the number sold between 12.5 and 17 million units. Volume production started in early 1982, marketing in August for US$595. Preceded by the VIC-20 and Commodore PET, the C64 took its name from its 64 kilobytes(65,536 bytes) of RAM. With support for multicolor sprites and a custom chip for waveform generation, the C64 could create superior visuals and audio compared to systems without such custom hardware.

<span class="mw-page-title-main">PDP-8</span> Minicomputer product line

The PDP-8 is a family of 12-bit minicomputers that was produced by Digital Equipment Corporation (DEC). It was the first commercially successful minicomputer, with over 50,000 units being sold over the model's lifetime. Its basic design follows the pioneering LINC but has a smaller instruction set, which is an expanded version of the PDP-5 instruction set. Similar machines from DEC are the PDP-12 which is a modernized version of the PDP-8 and LINC concepts, and the PDP-14 industrial controller system.

<span class="mw-page-title-main">Commodore 128</span> Home computer released in 1985

The Commodore 128, also known as the C128, C-128, or C= 128, is the last 8-bit home computer that was commercially released by Commodore Business Machines (CBM). Introduced in January 1985 at the CES in Las Vegas, it appeared three years after its predecessor, the Commodore 64, the bestselling computer of the 1980s. Approximately 2.5 million C128s were sold during its four year production run.

<span class="mw-page-title-main">VIC-20</span> 1981 home computer by Commodore

The VIC-20 is an 8-bit home computer that was sold by Commodore Business Machines. The VIC-20 was announced in 1980, roughly three years after Commodore's first personal computer, the PET. The VIC-20 was the first computer of any description to sell one million units. It was described as "one of the first anti-spectatorial, non-esoteric computers by design...no longer relegated to hobbyist/enthusiasts or those with money, the computer Commodore developed was the computer of the future."

<span class="mw-page-title-main">Atari BASIC</span> Dialect of the BASIC programming language

Atari BASIC is an interpreter for the BASIC programming language that shipped with Atari 8-bit computers. Unlike most American BASICs of the home computer era, Atari BASIC is not a derivative of Microsoft BASIC and differs in significant ways. It includes keywords for Atari-specific features and lacks support for string arrays.

<span class="mw-page-title-main">Commodore Plus/4</span> 1984 home computer by Commodore International

The Commodore Plus/4 is a home computer released by Commodore International in 1984. The "Plus/4" name refers to the four-application ROM-resident office suite ; it was billed as "the productivity computer with software built in".

Commodore BASIC, also known as PET BASIC or CBM-BASIC, is the dialect of the BASIC programming language used in Commodore International's 8-bit home computer line, stretching from the PET (1977) to the Commodore 128 (1985).

<span class="mw-page-title-main">IBM 1130</span> 16-bit IBM minicomputer introduced in 1965

The IBM 1130 Computing System, introduced in 1965, was IBM's least expensive computer at that time. A binary 16-bit machine, it was marketed to price-sensitive, computing-intensive technical markets, like education and engineering, succeeding the decimal IBM 1620 in that market segment. Typical installations included a 1 megabyte disk drive that stored the operating system, compilers and object programs, with program source generated and maintained on punched cards. Fortran was the most common programming language used, but several others, including APL, were available.

<span class="mw-page-title-main">MOS Technology 8563</span>

The 8563 Video Display Controller (VDC) was an integrated circuit produced by MOS Technology. It was used in the Commodore 128 (C128) computer to generate an 80-column RGB video display, running alongside a VIC-II which supported Commodore 64-compatible graphics. The DCR models of the C128 used the later and more technically advanced 8568 [D]VDC controller.

The Macintosh Toolbox implements many of the high-level features of the Classic Mac OS, including a set of application programming interfaces for software development on the platform. The Toolbox consists of a number of "managers," software components such as QuickDraw, responsible for drawing onscreen graphics, and the Menu Manager, which maintain data structures describing the menu bar. As the original Macintosh was designed without virtual memory or memory protection, it was important to classify code according to when it should be loaded into memory or kept on disk, and how it should be accessed. The Toolbox consists of subroutines essential enough to be permanently kept in memory and accessible by a two-byte machine instruction; however it excludes core "kernel" functionality such as memory management and the file system. Note that the Toolbox does not draw the menu onscreen: menus were designed to have a customizable appearance, so the drawing code was stored in a resource, which could be on a disk.

<span class="mw-page-title-main">Commodore DOS</span> Operating system

Commodore DOS, also known as CBM DOS, is the disk operating system used with Commodore's 8-bit computers. Unlike most other DOSes, which are loaded from disk into the computer's own RAM and executed there, CBM DOS is executed internally in the drive: the DOS resides in ROM chips inside the drive, and is run there by one or more dedicated MOS 6502 family CPUs. Thus, data transfer between Commodore 8-bit computers and their disk drives more closely resembles a local area network connection than typical disk/host transfers.

MBASIC is the Microsoft BASIC implementation of BASIC for the CP/M operating system. MBASIC is a descendant of the original Altair BASIC interpreters that were among Microsoft's first products. MBASIC was one of the two versions of BASIC bundled with the Osborne 1 computer. The name "MBASIC" is derived from the disk file name MBASIC.COM of the BASIC interpreter.

<span class="mw-page-title-main">Super Expander</span>

The VIC-1211 Super Expander is a cartridge for the VIC-20 home computer. It was designed to provide several extensions to the BASIC interpreter on the computer, mostly to help with programming graphics and sound. It also provided 3 kB of extra RAM. The cartridge was created by Commodore Business Machines (CBM) and released in 1981.

<span class="mw-page-title-main">Commodore 64 peripherals</span>

The Commodore 64 home computer used various external peripherals. Due to the backwards compatibility of the Commodore 128, most peripherals would also work on that system. There is also some compatibility with the VIC-20 and Commodore PET.

<span class="mw-page-title-main">Simons' BASIC</span>

Simons' BASIC is an extension to BASIC 2.0 for the Commodore 64 home computer. Written by British programmer David Simons in 1983, who was 16 years old at the time, it was distributed by Commodore as a cartridge.

<span class="mw-page-title-main">Acorn MOS</span> Computer operating system

The Machine Operating System (MOS) or OS is a discontinued computer operating system (OS) used in Acorn Computers' BBC computer range. It included support for four-channel sound, graphics, file system abstraction, and digital and analogue input/output (I/O) including a daisy-chained expansion bus. The system was single-tasking, monolithic and non-reentrant.

IBM System/36 BASIC was an interpreter for the IBM System/36 midrange computer.

IDEDOS is a ROM-based disk operating system written in 6502/65816 assembly language for the Commodore 64, 128 and SuperCPU. Its main purpose is to control ATA(PI) devices connected to an IDE64 cartridge and present them like normal Commodore drives. Additionally it supports networked drives (PCLink) and has a built-in machine code monitor and file manager.

<span class="mw-page-title-main">COP400</span> 4-bit microcontroller family

The COP400 or COP II is a 4-bit microcontroller family introduced in 1977 by National Semiconductor as a follow-on product to their original PMOS COP microcontroller. COP400 family members are complete microcomputers containing internal timing, logic, ROM, RAM, and I/O necessary to implement dedicated controllers. Some COP400 devices were second-sourced by Western Digital as the WD4200 family. In the Soviet Union several COP400 microcontrollers were manufactured as the 1820 series.