KERNAL is
Commodore's name for the
ROM
Rom, or ROM may refer to:
Biomechanics and medicine
* Risk of mortality, a medical classification to estimate the likelihood of death for a patient
* Rupture of membranes, a term used during pregnancy to describe a rupture of the amniotic sac
* ...
-resident
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
core in its
8-bit
In computer architecture, 8-bit integers or other data units are those that are 8 bits wide (1 octet). Also, 8-bit central processing unit (CPU) and arithmetic logic unit (ALU) architectures are those that are based on registers or data bu ...
home computer
Home computers were a class of microcomputers that entered the market in 1977 and became common during the 1980s. They were marketed to consumers as affordable and accessible computers that, for the first time, were intended for the use of a s ...
s; from the original
PET
A pet, or companion animal, is an animal kept primarily for a person's company or entertainment rather than as a working animal, livestock, or a laboratory animal. Popular pets are often considered to have attractive/ cute appearances, inte ...
of 1977, followed by the extended but related versions used in its successors: the
VIC-20
The VIC-20 (known as the VC-20 in Germany and the VIC-1001 in Japan) is an 8-bit entry level home computer that was sold by Commodore International, Commodore Business Machines. The VIC-20 was announced in 1980, roughly three years after Commod ...
,
Commodore 64
The Commodore 64, also known as the C64, is an 8-bit computing, 8-bit home computer introduced in January 1982 by Commodore International (first shown at the Consumer Electronics Show, January 7–10, 1982, in Las Vegas). It has been listed in ...
,
Plus/4,
Commodore 16, and
Commodore 128.
Description
The Commodore 8-bit machines' KERNAL consists of the low-level, close-to-the-hardware OS routines roughly equivalent to the
BIOS
In computing, BIOS (, ; Basic Input/Output System, also known as the System BIOS, ROM BIOS, BIOS ROM or PC BIOS) is a type of firmware used to provide runtime services for operating systems and programs and to perform hardware initialization d ...
in IBM PC compatibles (in contrast to the
BASIC interpreter
A BASIC interpreter is an Interpreter (computing), interpreter that enables users to enter and run programs in the BASIC programming language, language and was, for the first part of the microcomputer era, the default Application software, applica ...
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
In telecommunications and computing, backward compatibility (or backwards compatibility) is a property of an operating system, software, real-world product, or technology that allows for interoperability with an older legacy system, or with Input ...
, 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 novel in small computers at the time.
The
Adventure International
Adventure International was an American video game publisher, video game publishing company that existed from 1979 until 1986. It was started by Scott Adams (game designer), Scott and Alexis Adams. Their games were notable for being the first i ...
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 dump
In computing, a core dump, memory dump, crash dump, storage dump, system dump, or ABEND dump consists of the recorded state of the working memory of a computer program at a specific time, generally when the program has crashed or otherwise termin ...
ed to disk, loaded into a Commodore 64, and run without modification.
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
In computing, assembly language (alternatively assembler language or symbolic machine code), often referred to simply as assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence bet ...
subroutine (written in
ca65 assembler format/syntax):
CHROUT = $ffd2 ; CHROUT is the address of the character output routine
CR = $0d ;
PETSCII code for
Carriage Return
A carriage return, sometimes known as a cartridge return and often shortened to CR, or return, is a control character or mechanism used to reset a device's position to the beginning of a line of text. It is closely associated with the line feed ...
;
hello:
ldx #0 ; start with character 0 by loading 0 into the x
index register
An index register in a computer's central processing unit, CPU is a processor register (or an assigned memory location) used for pointing to operand addresses during the run of a program. It is useful for stepping through String (computer science ...
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'' 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.
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
A backronym is an acronym formed from an already existing word by expanding its letters into the words of a phrase. Backronyms may be invented with either serious or humorous intent, or they may be a type of false etymology or folk etymology. The ...
) 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
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
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 call
In computing, a system call (syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive ...
s. 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 computing, ioctl (an abbreviation of input/output control) is a system call for device-specific input/output operations and other operations which cannot be expressed by regular file semantics. It takes a parameter specifying a request code; ...
() 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
Commodore BASIC, also known as PET BASIC or CBM-BASIC, is the Dialect (computing), dialect of the BASIC programming language used in Commodore International's 8-bit home computer line, stretching from the Commodore PET, PET (1977) to the Commodore ...
, they might find software not unlike the following:
70 ...
80 REM ROTATE LOGS CURRENTLY OPENED ON LOGICAL CHANNEL #1.
90 CLOSE 1
100 OPEN 15,8,15,"R0:ERROR.1=0:ERROR.0":REM RENAME FILE ERROR.0 TO ERROR.1
110 INPUT# 15,A,B$,C,D:REM READ ERROR CHANNEL
120 CLOSE 15
130 IF A=0 THEN GOTO 200
140 PRINT "ERROR RENAMING LOG FILE:"
150 PRINT " CODE: "+A
160 PRINT " MSG : "+B$
170 END
200 REM CONTINUE PROCESSING HERE, CREATING NEW LOG FILE AS WE GO...
210 OPEN 1,8,1,"0:ERROR.0,S,W"
220 ...
Device numbers, per established documentation, are restricted to the range
,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
2,256 Conceivably, one can load a
device driver
In the context of an operating system, a device driver is a computer program that operates or controls a particular type of device that is attached to a computer or automaton. A driver provides a software interface to hardware devices, enabli ...
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
In telecommunications, RS-232 or Recommended Standard 232 is a standard introduced in 1960 for serial communication transmission of data. It formally defines signals connecting between a ''DTE'' (''data terminal equipment'') such as a compu ...
driver (device 2) consists simply of four characters, encoded in binary format.
[''Commodore 128 Programmers Reference Guide'', Commodore Business Machines, Inc., 1986, p. 382]
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
External links
Original KERNAL Source Code for all Commodore machinesCommodore KERNAL HistoryCommodore 64 KERNAL I/O Monitor Utility
{{Operating system
Operating system kernels
Commodore 64
Nonstandard spelling
1977 software