********* Welcome to iDOC= - the international CBM documentation project! The goal of iDOC= is to preserve (non-English) Commodore related documents in electronic text format that might otherwise cease to exist with the rapid advancement of computer technology and declining interest in 8-bit computers on the part of the general population. If you would like to help by converting Commodore related hardcopy documents to electronic texts please contact the manager of iDOC=, Peter Karlsson, at pk@abc.se. Extensive efforts were made to preserve the contents of the original document. However, certain portions, such as diagrams, program listings, and indexes may have been either altered or sacrificed due to the limitations of plain vanilla text. Diagrams may have been eliminated where ASCII-art was not feasible. Program listings may be missing display codes where substitutions were not possible. Tables of contents and indexes may have been changed from page number references to section number references. Please accept our apologies for these limitations, alterations, and possible omissions. Document names consists of a reasonably short unique title, followed by the document language. Two optional fields follow; first the document version (0 for incomplete texts, version 1 is usually unnumbered), and then the document source, if there are more than one. Finally, the document is given a .txt extension. The author(s) of the original document and members of iDOC= make no representations about the accuracy or suitability of this material for any purpose. This etext is provided "as-is". Please refer to the warranty of the original document, if any, that may included in this etext. No other warranties, express or implied, are made to you as to the etext or any medium it may be on. Neither the author(s) nor the members of iDOC= will assume liability for damages either from the direct or indirect use of this etext or from the distribution of or modification to this etext. Therefore if you read this document or use the information herein you do so at your own risk. ********* The iDOC= etext of SAMS' The official book for the Commodore 128, converted to text by Peter Karlsson offical128_en1.txt, July 2000, etext #66. Note from the etexter: ********* ACKNOWLEDGMENTS The authors would like to acknowledge the assistance of the following people, without whom this book could neither have been written in the first place, nor changed from a manuscript into an actual product: Jim Gracely and Bob Kenny of Commodore Business Machines; Damon Davis, Phil Debrabant, Esther Eisman, John Obst, and Barbara Sams of Howard W. Sams, Inc.; and Lyn Cordell and Joan Frank of The Waite Group. AH these people made sacrifices far beyond the call of duty; we salute their dedication. CONTENTS Acknowledgments 1 Introduction to the Commodore 128 1.1 What's in This Book 1.2 The Commodore 128: Three Computers in One 1.3 The C64 Mode 1.4 The C128 Mode 1.5 The CP/M Mode 1.6 The Bottom Line 2 Peripherials: Displays, Disk Drives, Printers and More 2.1 What's Already Inside the Commodore 128 2.2 Display Devices 2.3 Program Cartridges 2.4 Cassette Units 2.5 Disk Drives 2.6 Printers 2.7 Modems 2.8 Joysticks 2.9 Other Peripherial Devices 2.10 Connecting Peripherials to the Commodore 128 2.11 The User Port 3 The C128 Mode 3.1 What Is the C128 mode? 3.2 What Does the C128 Mode Offer? 3.3 What Are the C128 Mode Enhancements? 3.4 40- and 80-Column Text and Graphics 3.5 What Equipment Do I Need to Use the C128 Mode? 3.6 All About BASIC 7.0 3.7 What is DOS and How Do I Use It? 3.8 Where Can You Learn More About C128? 4 The C64 Mode 4.1 What Is the C64 Mode? 4.2 What External Devices Do You Need to Use the C64 Mode? 4.3 How and When Do You Change to the C64 Mode? 4.4 What Can You Do While in This Mode? 4.5 What Can't You Do While in the C64 Mode? 4.6 How Does BASIC Differ in the C64 Mode? 4.7 About C64 Mode DOS 5 The CP/M Mode 5.1 What Is CP/M and What Is the CP/M Mode? 5.2 What Does CP/M Offer? 5.3 What Equipment Do You Need to Run CP/M? 5.4 Important Programs on the CP/M Owner's List 5.5 Free Software for CP/M 5.6 The Structure of CP/M: Layout, Commands and Utilities 5.7 Where Can You Learn More About CP/M? 6 Graphics on the C128 6.1 C128 Graphics Overview 6.2 Character (Block) Graphics Mode 6.3 The Bit-Mapped Mode 6.4 Sprite Graphics 6.5 Windows 7 Sound and Music 7.1 What Can You Do with Sound on the Commodore 128? 7.2 Commercial Software and Hardware for Sound Generation 7.3 Sound Ideas 7.4 Sound and BASIC 7.0 A Addresses of Companies and Organizations [1.] Introduction to the Commodore 128 In this chapter you'll learn: * What this book is about * The main features of the Commodore 128 * The three modes of operation of the Commodore 128 * Why you might want to buy a Commodore 128 The Commodore 128 Personal Computer (Shown in Figure 1-1) is one of the best values ever to appear on the home computer scene. It incorporates an amazing variety of features, at a price of less than $300. Some of these features represents firsts in the computer industry. The Commodore 128 is, of course, the first upgrade of the ubiquitous Commodore 64 computer, of which over three million has been sold to date. the Commodore 128 is the first low-cost personal computer to offer a full one-eight megabyte (128K) of memory. It is also the first computer to combine the high resolution color graphics of the Commodore 64 with a serious business operating system (CP/M). The Commodore 128 is the first computer to offer two entirely separate microprocessor brains and view graphic chips, giving it essentially two different personalities: home computer and small business computer. It is also the first low-cost personal computer to offer an intelligent disk drive capable of reading dozens of storage formats. Finally, and most importantly, it is the first computer to combine, in one case, what amounts to three separate computers: the C64 mode, the C128 mode and CP/M mode. [1.1] What's in This Book This book describes the features of the Commodore 128, what it does, how it does it, and what kinds of things you can use it for. In this first chapter we'll give you a quick overview of the Commodore 128, explaining how it came to be and what its major features are. In later chapters we'll go into more detail about particular features of the C128, and how to use these features. We'll discuss the kinds of external devices (peripherals) you may need to operate the Commodore 128, and then we'll explore in some detail the three modes of operation available: the C128 mode, the C64 mode, and the CP/M mode. We'll finish up with chapters describing the sound and graphics capabilities of the C128, and how to make use of them in your own programs. Our purpose in this book is not to give you an entire course in computers from the ground up, nor to teach you the fundamentals of BASIC or computer programming. Rather, we focus on those features of the Commodore 128 that make it unique and interesting. From time to time in this book we'll mention the names of manufacturers of peripheral equipment and software, as well as organizations that are involved in the Commodore industry. The addresses of these manufacturers and organizations will be found in the back of the book. Figure 1-1. The Commodore 128 [Omitted] If you have bought a Commodore 128, or if you are thinking of buying one, this book should answer most of your questions concerning the operation of the computer and whether it can do what you want. A Word about Names In a computer that contains three other computers, it's easy to get confused about whether you mean the main computer case or the individual computers inside. Commodore refers to the inside computers as modes, and that's what we'll do in this book. The main computer we'll refer to as the Commodore 128, or as the C128, for short. The three modes built into it are the C128 mode, the C64 mode, and the CP/M mode. The earlier computer on which the Commodore 128 was based we'll call the Commodore 64, or the C64, for short. [1.2] The Commodore 128: Three Computers in One The main feature of the Commodore 128 - what sets it apart from almost every other computer ever manufactured - is that it is really three separate computers packed into one case. These three computers share the same keyboard, and can share external equipment, like the display screen and disk drives; so that when the C128 is sitting on your desk it may look as if there is only one computer system there. However, buried inside its handsome case there are really three separate computers, as shown somewhat fancifully in Figure 1-2. What are these three computers, and why did Commodore put them together in one case? The first computer hidden inside the Commodore 128 is a faithful copy of an earlier computer: the Commodore 64. Introduced in 1982, the C64 turned out to be one of the most successful home computers of all time, with sales of over three million (and still climbing). The C64 was successful because it offered excellent color graphics and sound, which made it a perfect computer for such applications as education and entertainment. It was also, with its built in Microsoft BASIC, easy for users to learn to program, and, most importantly, it was priced below the competition. Because the Commodore 64 was so successful, a large software industry grew up to support it. Today there are more than six thousand programs which run on the C64, with new ones being written every day. As we'll see, this huge existing software base has played a major part in the evolution of the Commodore 128. The Commodore 64 was not without its faults. For one thing, the speed at which the disk system could transfer data was woefully slow. Users who needed to load a really long program or data file from a disk got used to brewing a cup of coffee while the transfer took place. Also, the C64 could display only 40 characters on one line of the screen. This was fine for simple business programs and for games, but users who wanted to use professional-quality software needed a screen capable of displaying 80 columns, the industry standard. Commodore, in the face of competition from other home computer manufacturers, wanted to introduce a new computer which, using more advanced technology, would eliminate some of the problems found on the C64. However, because there were so many Commodore 64 programs in existence, they did not want a new machine which would be unable to run these programs. The millions of people who had invested heavily in programs designed to run on the C64 would not look kindly on a computer that was supposed to improve on the C64 but would not run the existing software. However, it is difficult to make a computer better, without at the same time making it different. If Commodore made major changes in the Commodore 64, then the new computer would not have been able to run the old C64 programs. Many manufacturers have wrestled with this problem, and decided on one course or another: compatibility versus innovation. Figure 1-2. Three Computers in One [Picture of a Commodore 128 with three blocks depicting the three modes] Commodore decided to have their cake and eat it too: in one machine they would combine both the old C64, and a new computer called the C128, which would be similar to the C64, but better. As we noted earlier, these two computers-within-a-computer are referred to as modes: the C64 mode, which lets the Commodore 128 emulate a Commodore 64; and the C128 mode, which is an entirely new computer with many enhancements and improvements over the C64. In addition to the C64 and C128 modes, Commodore added a third mode: the CP/M mode, which turns the Commodore 128 into a serious business computer. We'll describe these modes briefly here, and explore them in more detail in the chapters to come. It is difficult to make a computer better without, at the same time, making it different. You will soon see why the Commodore 128 is both - a different computer, and a better one. [1.3] The C64 Mode As we noted, the Commodore 64 featured excellent color graphics and sound; in fact, the most advanced in the industry for a home computer. The color graphics made use of sprites - sophisticated, intelligent graphics entities which could be programmed to represent objects like race cars and space ships. These sprites could be told to move anywhere on the screen and they would do so automatically, without slowing the program down. The sound generating capability provided amazing versatility for a machine in this price range, including three voices and a wide variety of ways to shape the sound to produce almost any imaginable effect, from musical instruments to space ships to the human voice. All these features have been retained in the C64 mode of the Commodore 128. In fact, in C64 mode the Commodore 128 is almost identical to the old Commodore 64. It will run all the same software. The screen display is the same, the keyboard operates the same way, and the disk drives and other peripherals that worked on the C64 will work the same way on the C128. If you are a Commodore 64 owner you'll find this mode invaluable, because all your software will work on the new machine, without any modification, just as it did on the old one. Even if you never owned a Commodore C64, you'll still profit from the C64 mode, because you'll be able to buy and use any of the thousands of programs already written for the Commodore 64. This mode will be discussed further in Chapter 4. [1.4] The C128 Mode The C128 mode is, in effect, a brand new computer inside the Commodore 128. What improvements does this mode offer over the C64 mode? We've already mentioned two areas where the Commodore 64 needed improvement: the slow disk access, and the lack of an 80-column screen display. The C128 mode eliminates both problems, offering both much faster disk access and the choice - with the push of a button - of either 80-column or 40-column color displays. Disk Data Transfer Speed Data transfer times using the disk have been increased more than five times. This is possible using an entirely new family of accessory drives for the C128. These new drives are called the Commodore 1571 and 1572. The 1571 (shown with other peripherals in Figure 1-3) is a single drive, and the 1572 is a dual-drive unit. These drives will be discussed in more detail in the chapter on peripherals. 80-Column Mode There are two different screen displays on the Commodore 128: 40 column, and 80 column, selected by a key on the keyboard. The 80 column display makes possible the use of much more sophisticated business-oriented software on the Commodore 128 than was possible on the Commodore 64. Note that not all monitors will work in 80-column mode; we'll have more to say about this in the next chapter. The innovations introduced by the C128 mode don't end with faster disk access and the 80 column screen display. In addition, there is a vastly improved BASIC, increased memory capacity, and a machine language monitor, to name only the most obvious improvements. Advanced BASIC 7.0 Most home computers come with a programming language built in, so that users can learn programming, write their own programs, or customize programs written by others. The standard language built into most small computers is BASIC, which is probably the easiest programming language to learn. The version of BASIC built into the Commodore 64, called BASIC 2.0, in general served very well, but it had some drawbacks. For one thing, it was difficult to take advantage of the excellent graphics and sound capabilities of the Commodore 64. Also, it was difficult to write programs in the modern "structured" style, since C64 BASIC did not have certain statements designed to make this kind of programming easy. Several accessories, notably Simons BASIC and SuperExpander, provided add on commands to improve the BASIC, but they were not a part of the standard language. Figure 1-3. The Commodore 128 System [Picture of a c128 with monitor, disk drive, printer, mouse and modem] The new version of BASIC that is accessible from C128 mode, called BASIC 7.0, remedies these deficiencies and adds many other new features as well. It provides a greatly increased number of statements, including those that make modern structured programming easier, such as DO...LOOP, BEGIN...BEND, and IF...THEN...ELSE. Graphics is simplified by the addition of commands that let you instantly draw circles, boxes, dots, and lines; fill areas with color; and split the screen into a text section and a graphics section. Sprites (the colored graphics objects which can be programmed to move independently on the screen, like race cars and space ships) are supported by simple commands which create sprites, move them, and check for collisions between them. There is even a built in sprite editor that lets you design sprites on the Commodore screen and then save them for use in a program. There are also better statements to use the disk system (the DOS, or Disk Operating System), and a variety of new statements to help make the programming process easier, like AUTO, to automatically number program lines; RENUM, to renumber program lines; and TRACE, to allow line by line analysis of a program's operation. In general, the new BASIC is a programmer's delight. It is probably the best and most powerful BASIC available to anyone buying a computer in the Commodore 128's price range. Increased Memory As its name implies, the Commodore 128 has 128K of memory, twice that of the Commodore 64. Because of various technicalities, the actual effect of this increased memory is that BASIC programs in C128 mode can be more than twice as large as they could be in C64 mode, as we'll discover in the chapter on C128 mode. And, if 128K of memory isn't enough, it's possible to expand it still further with optional plug in memory modules, up to a maximum of 512K. Improved Keyboard A numeric keypad (the number keys clustered together as they are on a calculator) is useful for anyone entering large amounts of numeric data, but this feature was lacking on the Commodore 64. Since many Commodore 64 owners spent hours entering machine language programs in the form of long lists of numbers, this feature was often asked for. The Commodore 128 provides a full featured numeric keypad, built into the computer on the right side of the keyboard. In addition, the new keyboard has (among other new keys) additional cursor keys to make moving the cursor easier, a key to ask for explanatory messages from those programs that use this capability, and the 40 column/80 column key for switching between display modes. We'll talk more about the new keyboard in the chapter on the C128 mode. Built in Machine Language Monitor If you're a machine language or assembly language programmer, or even if you just like to explore various technical aspects of your computer, you'll appreciate this new feature of the Commodore 128: a built in monitor program that lets you assemble, disassemble, and debug assembly language or machine language programs; and examine and modify memory. [1.5] The CP/M Mode As if two computers in one weren't enough, Commodore also added a third, entirely different mode, to the Commodore 128. This is the CP/M mode. CP/M stands for "Control Program for Microcomputers." It's a disk operating system (a program which controls disk operations) developed by Digital Research, Inc., and available since the early days of microcomputers, almost a decade ago. You'll learn more about what operating systems are in general and about CP/M in particular in Chapter 5. CP/M is an operating system that attempts to standardize program writing and usage, so that a program written to work on CP/M on one computer will work on CP/M on any other computer. CP/M has, in fact, been enormously successful, and tens of thousands of programs - mostly professional level business programs - have been written for it. Thus, by making CP/M available on the C128, Commodore is tapping into this vast reservoir of existing software. Since so much of this software is business-oriented, the addition of CP/M (along with the 80 column screen and faster disk drives) transforms the Commodore 128 into a serious business-oriented machine. Chapter 5 details some of the more popular CP/M programs. It also describes the great amount of free "public domain" software available for CP/M. [1.6] The Bottom Line If you're interested in owning one of the most versatile computers designed to date, with the ability to run thousands of existing educational, entertainment, and other programs, with many new enhanced features, and at the same time, a computer that can serve as a serious business machine, the Commodore 128 represents an excellent value. In the chapters that follow, we'll tell you more about this computer and explore its capabilities in detail. We'll begin by discussing peripherals for the C128: display screens, disk drives, printers, and other external devices. Then we'll discuss the three modes available on the Commodore 128: the C128 mode, the C64 mode, and the CP/M mode; and finally we'll show you something about the C128's most exciting features: graphics and sound. [2.] Peripherals: Displays, Disk Drives, Printers, and More In this chapter you'll learn: * What "peripherals" are and why they're needed * What peripherals are commonly used with the Commodore 128 * What peripherals are available from Commodore * How peripherals attach to the Commodore 128 When you buy a car, you probably also purchase a certain number of options: probably an automatic transmission and power steering, perhaps air conditioning, or tinted glass, or a stereo tapedeck. Some of these options are essential to the operation of the car, some are conveniences, and some - like racing stripes - are merely ego-boosters. A similar situation exists when you buy a computer: there are many options besides the computer itself - some essential to the operation of the computer, some less essential. In the computer world these options are called "peripherals," meaning that they sit around your computer, on its "periphery." Peripherals commonly used with the Commodore 128 are display devices, disk drives, printers, and modems. If you want to see the output from your computer, you'll need some sort of display device: either a TV set or monitor. If you want to store programs or data when the computer is turned off, you'll need either a cassette tape storage device or a disk drive. If you want to print out programs or other data on paper, you'll need a printer; and if you want to communicate over telephone lines with your computer, you'll need a modem. And this is just the beginning; there are many other peripherals as well. Just as it is difficult to decide which options to buy (and which you can afford) when you buy a car, there may seem to be a bewildering array of peripherals to choose for your computer. In this chapter we're going to introduce you to the world of Commodore 128 peripherals, explaining what they are, reviewing what is available in the marketplace, and suggesting how to choose which equipment is right for you. We'll then explain just how these peripherals are attached to the Commodore 128. This is not a simple topic. There are so many plugs, openings, ports and connectors of different shapes and sizes on the Commodore 128 that it's necessary to explain which kind of peripheral plugs in where, and why. We'll start off by talking about what's already built into the Commodore 128. From this discussion, the reason for needing some peripherals will begin to emerge. [2.1] What's Already Inside the Commodore 128 We've mentioned several different kinds of peripheral devices that may be necessary for your computer system. But what comes with the computer itself? What don't you need to buy? The Keyboard As you can see from Figure 1-1 in the last chapter, the Commodore 128 looks as if it's mostly a keyboard. This keyboard is the way that you, the user, will most commonly put information into the computer. However, the nicely styled plastic case that houses the keyboard contains many other things as well. Chips First and most importantly, the Commodore 128 contains the handful of "chips" (complex circuits etched onto a small crystal of silicon) that control the computer's operation. As a user you probably won't need to know much about these chips. If you're not interested in technical details, you can skip the next few paragraphs. At the heart of the Commodore 128's circuitry is the 8502 microprocessor. This chip is a close cousin of the 6502 chip which powers the Apple II, Atari, and other computers. The 8502 controls the operation of the Commodore when it is in C64 mode and C128 mode. In CP/M mode, an entirely different microprocessor is used, the Z80A. In addition to the microprocessor chips, the Commodore 128 also has specialized chips to control graphics, sound, and communication with peripheral devices. Graphics is handled by a chip called the VIC II, for "Video Interface Chip." In 80 column mode (which we'll discuss below), another chip is used, the 8563, which can display twice as many dots per line as the VIC II chip. Sound is controlled by the SID, or "Sound Interface Device." The SID chip is the same one that was used in the Commodore 64 computer. There are two chips to handle communications with peripheral devices: they're called CIAs, for "Complex Interface Adaptors." Memory There are other chips which constitute the memory of the Commodore 128. The memory is divided into two parts: a permanent part which is filled with information at the factory, called ROM (for Read Only Memory); and a temporary part which can hold programs or data generated by the user, called RAM (Random Access Memory). The Commodore 128, as its name implies, contains 128K of RAM memory. (One "K" is equivalent to 1024 bytes (or characters), so the C128 actually holds 131,072 bytes). This is twice as much as the Commodore 64. Something to remember about the RAM in your computer is that any programs or data that are stored in it will disappear when the power is turned off. Thus it is not a good place for permanent storage of programs or data. We'll have more to say about this when we talk about cassettes and disk drives. Connectors The last major category of components built into the Commodore 128 itself is the various plugs and connectors which allow it to communicate with its peripheral devices. We'll cover these in the last part of the chapter. In the sections that follow we'll talk in turn about each of the broad categories of peripherals; then we'll discuss how these devices are connected to the C128. In later chapters we'll talk more about the kinds of peripherals which are particularly suitable for each of the three modes. [2.2] Display Devices A display device is the only peripheral you absolutely must have to operate your Commodore 128. This display device can be an ordinary TV set, or it can be a video monitor. What's a monitor? It's very similar to a TV set, except that it can't receive TV broadcasts. Thus it offers a sharper picture than a TV set, because the signals from the computer don't need to go through the complex circuitry intended for TV broadcast reception. There are several different types of monitors, so choosing a display device is not a simple task. It depends on what you want to use your computer for, how good a picture you like to look at, and how much you want to spend. Let's review the available options. The TV Set The least expensive display device for your Commodore 128 is an ordinary home TV set. This is an excellent choice if you want to play games or use other simple programs. For these uses a color set is preferable, since almost all computer games make use of color. Since almost everyone has a TV set, this option usually doesn't cost you anything. Of course, if you only have one TV set, and you want to use your computer in a different room than where you usually watch TV, then you might find yourself wanting a second TV set; a somewhat more expensive proposition. In this case you should consider a monitor, to be described below. To use your TV set with the computer you'll need a small box which contains a switch, so you can switch the TV back and forth between the computer and the normal TV antenna. This box is provided by Commodore along with the the C128. To use it, simply plug the cable from the computer into the switchbox, and plug another cable coming from the box into your TV set. The major disadvantage of a TV set is that the resolution, or amount of detail you can see, in a TV image is fairly limited. For pictures - such as those you'll find in games and simple educational programs - a TV set works very well. But for text - such as program listings - it is less satisfactory: the letters and words are somewhat fuzzy, and can be tiring to read. The Direct Video Color Monitor Because text can be difficult to read on a TV set, different kinds of monitors are available, all of which offer clearer pictures than the standard TV does. You should consider a monitor if you will be using your computer for writing with a word processing program, or for working with spreadsheet or financial programs, or if you plan to spend a substantial amount of time writing your own programs. You might even want a monitor simply because you don't have a TV, or don't want to use your TV with your computer. The least expensive color monitor available for the Commodore 128 is called a direct monitor, because the picture signals from the computer don't go through the broadcast-decoding circuitry as they do on a standard TV set. Here, one cable plugs into the computer, but is split into three separate plugs where it plugs into the monitor: one wire for sound, and two for special picture signals called lump and chrome. Commodore is unique among makers of small computers in using this kind of monitor. Most computer-makers use something called a composite monitor, in which the luma and chroma signals are combined in one wire. The Commodore approach offers a clearer picture, but you must buy a special monitor, made by Commodore, to take advantage of the system. Commodore builds a direct monitor which has been very popular with users of the Commodore 64 computer: the 1702 color video monitor. You can also use a composite monitor, although the picture will not be quite as sharp. Other manufacturers produce inexpensive (under $200) composite monitors. Somewhat higher-quality composite monitors cost around $350. Although a direct monitor offers a clearer picture than you might obtain with a TV set, it may still not be clear enough for all purposes. Specifically, it will display 40 columns of characters, but not 80. Let's see what this means. 40-Column Versus 80-Column The Commodore 64 - the predecessor of the Commodore 128 - displays text of one size only. Forty characters (letters or numbers) just fit on one line of the screen: that is, there is one character in each of forty columns, so the letters are fairly large, and can be read even though they're a little fuzzy. This same way of displaying text is used when the Commodore 128 is used in C64 mode. However, when you're typing a letter with a typewriter, you can usually get more than 40 characters on a line: closer to 80, in fact. This is also true of documents printed out on a computer's printer. Many people who use a computer for word processing, or for other business uses, want to see a line of text on the computer screen which corresponds more to what they will see when the letter is printed out. For this reason, most business computers use an 80 column display mode, which fits 80 characters on each line. The Commodore 128 computer lets you choose between a 40-column and an 80-column display. This is done by depressing a key on the keyboard. However, if you select the 80-column display, you'll need to use a monitor which will clearly display letters this small (half the size of the letters in the 40-column display). A TV set cannot be used in 80 column mode, and a composite monitor lacks sufficient resolution. To use this mode, you need a new kind of monitor called an RGBI monitor. The RGBI Monitor More expensive than the direct or composite monitors, but with a substantially better picture, is an RGBI monitor. RGBI stands for Red-Green-Blue Intensity. In this type of monitor, signals containing information about these three colors and the intensity are sent on four separate wires from the computer to the monitor. This results in a very clear color picture, since the signals for the colors are not first mixed in the computer and then unmixed in the monitor, as they are in direct and composite monitors. Because an entirely different set of signals coming from the Commodore 128 is used for the RGBI monitor, a different connector on the back of the C128 is used for this kind of monitor than is used for a composite monitor or TV set. In fact, it's possible to have both kinds of monitors connected simultaneously, showing different pictures. (We'll show these connectors in the last section in this chapter.) Many manufacturers make RGBI monitors. They vary widely in price: the better the picture you want, the more you must pay. The highest quality monitors sell for $750 or more, but good RGB monitors are available for around $400. Figure 2-1 shows the connections for the various types of color displays. A potential problem to note with the Commodore 128 is that you can't use an RGB monitor in 40 column mode. This is unfortunate, since it means that to use all the modes on your C128 you really need two monitors: direct (or composite) and RGB. Fortunately, Commodore has solved this problem. At the same time it introduced the C128 computer, Commodore also announced a new monitor: the 1902, shown in Figure 2-2. This monitor, which costs less than $300, actually combines several monitors in one. You can use it either as a composite monitor, or as an RGB monitor, switching from one to the other by means of a switch on the front panel. Since it also accepts a composite signal, this monitor can also be used to display regular TV pictures, if you connect it to your VCR. Figure 2-1. Connections for Different Displays [Picture describing the various ways of connecting a C128 to a display device: * From the TV connector to the Radio Frequency Signal input of a TV * From the Video connector to the Chroma/Luma/Audio inputs of a direct monitor * From the Video connector to the Composite Picture Signal/Audio input of a composite monitor * From the Video connector to the Audio input and from the RGBI connector to the Red/Green/Blue/Intensity inputs of a RGBI monitor Monochrome Monitors If you plan to use your computer mostly for word processing, or for business programs such as spreadsheets and database programs, your best bet might be what is called a monochrome monitor. Like a black and white TV set, this monitor doesn't show a color picture; it is usually either black and amber or black and green. This monitor can be obtained for less than $200, and offers a much sharper picture than even an ROB monitor. If you're going to spend all day gazing at words or program listings on the screen, and you're not interested in full-color games, this option has a lot to offer. If you're going to use the 80-column mode, make sure that the monochrome monitor you choose has enough resolution to handle this degree of detail; not all of them do. Figure 2-2. 1902 Color Monitor [Omitted] [2.3] Program Cartridges Program cartridges aren't exactly peripherals in the sense a monitor or disk drive is. The cartridge slot (the connector where the cartridges plug in) is already built into the Commodore 128, so there is no major purchase to make to use this peripheral. The sole purpose of program cartridges is to provide a convenient way for software manufacturers to distribute their product. Only the manufacturer can put a program in the cartridge, so you can't use it to store programs of your own, as you can with a cassette or disk drive. The program cartridge itself is a plastic box about the size of a deck of cards. Some software manufacturers like it because it is almost indestructible, and the program inside can't be conveniently copied. However, cartridges are more expensive to produce than disks, so other manufacturers avoid them. There is a considerable variety of commercially produced software available on program cartridges for the Commodore 64, which will also work on the Commodore 128 in the C64 mode. These programs are fairly inexpensive, ranging from around $19 to $40 for games, and up to $100 for more serious programs. It remains to be seen whether software developers will use this format for programs written specifically for the C128 mode. Something to remember about program cartridges is that you should turn off the power to the computer before plugging in the cartridge. If you don't do this, you run the risk of damaging the computer, or the cartridge. [2.4] Cassette Units When you turn off the power to your C128, everything you've stored in its internal RAM disappears. If you've written a long program and want to use it again without having to type it in again, this can be discouraging. You need some sort of permanent storage device, where programs and other data, such as letters you've written with a word-processor program, can be stored more or less permanently. Such long-term storage devices are sometimes called mass storage, since they can hold more data than can the memory in the computer. Program cartridges won't serve the purpose because, while they do store programs, you can't write your own programs on them; you can only read the manufacturer's program from them into your computer. Cassettes offer the most inexpensive form of mass storage for your Commodore 128. A cassette unit is similar to the small cassette tape recorders used for playing music, and in fact it uses the same kind of cassette tapes. On many small computers it's possible to use any kind of cassette recorder, but the Commodore 128 uses a special kind of cassette recorder called a Datasette, made only by Commodore. (The Datasette records digital signals, rather than the analog signals used in other recorders. This makes it somewhat more reliable.) It is the most inexpensive way to store your programs and data, but it is also slow: you'll spend a long time waiting for a program to load. Most users who start with a cassette recorder eventually upgrade to a disk drive, so our advice is to start off with a disk drive if you can possibly afford it. Over 90 percent of Commodore 64 users chose a disk drive over the Datasette, and this figure will probably be similar for buyers of the Commodore 128. [2.5] Disk Drives After a display device, a disk drive is probably the most popular peripheral for most personal computers. Like cassettes, disk drives serve two principal purposes: they are a medium on which commercial software can be made available to your computer; and they also allow you to save, more or less permanently, programs or other data which you've created yourself However, they offer far better performance than a cassette drive. At somewhat less than $300, the disk drive represents a relatively serious investment, but it is so much faster and more reliable than a cassette unit that it is worth the price for most users. It is possible to use old-style Commodore drives, which were built for use with the Commodore 64, with the new Commodore 128. The most popular drive built by Commodore for the C64 was the 1541, a single drive unit (meaning it would hold only one disk at a time). Dual-drive units are also available from other manufacturers. All of these units will also work on the Commodore 128. However, they do not take full advantage of one of the major improvements of the Commodore 128 over the Commodore 64: the increased speed of the disk drives. For the C128, Commodore has announced an entirely new line of disk drives. The single drive model is the 1571, shown in Figure 2-3. This drive operates in three modes, corresponding to the three personalities of the Commodore 128 computer. In C64 mode, it's completely compatible with the old 1541 drive, and runs at the same speed as the old drive. In C128 mode, it runs five times faster; and in CP/M mode, it runs faster still - and is also compatible with most existing CP/M formats. The dual-drive version of the drive is called the 1572. Data Transfer Speed What does this speed advantage of the new drive mean to you? The old 1541 drive ran at about 320 characters per second. If you had a five page letter or program listing of, say, 15,000 characters, it would take 46 seconds to transfer with the old drive (or with the new drive in C64 mode). In C128 mode, the new drive runs at 2000 characters per second, so the same document will take only 7.5 seconds to transfer. In CP/M mode, it's even faster: 3500 characters per second, for a 4.2 second transfer. If you've ever sat waiting for a long program to load on your Commodore 64, you'll know that this increased speed is is not just a gimmick: it can really make your life easier. The longer the programs you write or use, and the more you operate your computer, the more you'll appreciate the increased speed of these drives. The new 1571 drive also stores twice as much information on a disk: 340K bytes, versus only 170K for the older 1541 drive. The new 1571 intelligent disk drive can transfer data up to ten tines faster than the older 1541 disk drive. Figure 2-3. 1571 Disk Drive [Omitted] [2.6] Printers You can have a lot of fun playing games and writing programs on the Commodore 128 without ever printing anything out. However, if you want to use your C128 for word processing, or for other serious business programs like spreadsheets, or if you want to write really long BASIC programs, then you'll need a printer so you can save the results of your work on paper. The kind of printer you need depends on how fast you want your output printed, how good you want it to look, and how much money you want to spend. The least expensive kind of printer is called a dot-matrix printer. This kind of printer is fast, but the printed characters have that made of dots computer look to them. If you intend to write serious business letters on your computer, you will probably want what's called a letter quality printer. These printers are more expensive, and use some form of typewriter-like mechanism to form the letters, so the printing is much cleaner. However, these printers are usually slower than dot-matrix printers. Commodore did not announce any new printers specifically for the Commodore 128, but they manufacture a variety of dot-matrix printers which work very well for the Commodore 64 and which are also perfect for the C128. These are the MPS-801, the MPS-802, and the MPS-803. The 801 and the 803 are the least expensive. The 802 is a heavier-duty machine suitable for business. All these printers can print not only text, but graphics (pictures). Being able to print graphics is useful if you are interested in computer art, or if you need to generate graphs and charts. Other manufacturers also make printers that can be used with the Commodore 128. Notice however, that if a printer has not been built specifically to work with the Commodore, you'll need an adaptor (a small box or a special plug) to make the printer work with the computer. MSD Systems and CardCo are two companies making the adaptors, which are priced between $50 and $150 (addresses are shown in the back of the book). Even with the adaptor, not all printers will print graphics, so be sure to check that the printer does what you expect before you take it home. For serious business use you'll probably want a letter quality printer, such as the Commodore DPS-1101. This produces copy like that typed on a good-quality office typewriter; but it's somewhat slower than the dot-matrix printers. [2.7] Modems One of the fastest growing uses of personal computers is the field of telecommunications. This means using your computer to send and receive data over the telephone lines. Why would you want to do that? You might want to send a program to a friend in another city. Or you might be interested in accessing one of the on-line database services, such as CompuServe or The Source. These services give you instant access to the latest stock prices, weather reports, movie reviews, and other data. They also let you communicate with groups of people who share a common interest, such as stamp collecting or electronic music. These groups are called SIGs, for special interest groups. There is, for example, a SIG for Commodore computers on CompuServe. These groups offer free programs, free advice, and a forum for discussion. The most important variance between different kinds of modems is that of speed: how fast can the modem send or receive a certain amount of information? A slow modem can take a long time to transmit even a small amount of information; so if you plan to use a modem extensively, a fast one is a good investment. The slowest modems used today are rated at 300 baud. What does baud mean? Very roughly, the baud rate is the number of characters per second the modem can send, divided by 10. Thus, a 300 baud modem can send about 30 characters per second. (This definition isn't exactly right, but it's close enough to give you an idea how fast modems work.) Commodore sells a variety of modems: the 1600 and the 1650, which have been around for some time, and the newer 1660 and 1670, which were introduced with the C128 computer. The first three are 300 baud modems, while the 1670, shown in Figure 2-4, runs at a brisk 1200 baud. While the 300 baud modems range in price from $40 to about $100, the 1670 will set you back about $200. In addition to Commodore, there are a wide variety of other modem manufacturers, including Hayes, Human Engineered Software, and Anchor Automation. Some of these modems are designed to plug directly into the C128, but others will require an adaptor called an RS-232 interface module, which costs about $50 and can be obtained from several manufacturers, including Commodore and MSD Systems. Besides speed, modems are also distinguished by features such as: Will the modem automatically answer the telephone? Will it automatically dial the phone to make an outgoing call? In the Commodore line, all but the 1600 have these autoanswer autodial features. However, the 1650 and 1660 require special software to use these features. For instance, if you want to dial a number, it is the software that generates the clicks for each digit you dial. In the 1670 on the other hand, the modem itself generates the clicks; all the software needs to tell it is what number to dial. The 1670 is thus a "smart" modem, which makes it compatible with a wider variety of communications software. A modem should be one of the first peripherals you own. With it, you can shop from home, access the latest stock prices, weather reports, movie reviews, electronic bulletin boards, and perhaps best of all, obtain free programs. Figure 2-4. 1670 Modem [Omitted] [2.8] Joysticks For games and various other programs you'll probably want to buy one or more joysticks or similar devices. Joysticks are small handheld levers that let you input up-down left-right directional information directly into the computer. Most joysticks also include a button, which is used to fire guns or lasers in computer games. Besides joysticks, there is a variety of other devices that act more or less like joysticks, including trackballs, mice, touch tablets, and paddles. Some users prefer one or the other of these devices, and some games or programs are designed to work with a particular device. However, the joystick is the most popular of such devices, and is a good start for anyone interested in games. Note that not all such devices can be used with any given program. Joysticks and trackballs are mostly compatible with each other, in that they both transmit information about direction to the computer: is the stick pointed north, northeast, east, or where? Touch tablets, mice, and game paddles, on the other hand, send a position to the computer. They often work in conjunction with a pointer on the computer screen, which is positioned at a particular place. [2.9] Other Peripheral Devices The variety of peripheral devices made for the Commodore 64 and the Commodore 128 is truly staggering. There are speech synthesis and recognition devices, as well as peripherals to open your garage door, check your house for burglars and fire, and operate your model trains. With the proper equipment you can get your C128 to draw engineering drawings, respond to your touching its screen, or synthesize music from a piano-like keyboard. We won't describe these esoteric devices here. What we've said about the more common peripherals should be enough to begin thinking about what you'll need for your Commodore 128. [2.10] Connecting Peripherals to the Commodore 128 Any peripheral device you buy is connected to the Commodore 128 by plugging it into one of the openings on the side or the back of the C128. There are quite a number of these connection ports, in a wide variety of shapes and sizes. It's easy to get confused and try to connect things in the wrong place, so this section will describe these connectors, and explain which peripheral gets plugged into which connector. The first group of connectors we'll talk about is located on the right side of the Commodore 128, as shown in Figure 2-5. Be Careful Connecting peripherals to the Commodore 128 is as simple as connecting the components of a stereo system - usually, there is only one way a connector can be plugged in. Because some of the Commodore 128 connectors contain voltages from inside the computer, it is a good practice to turn off power before plugging or unplugging peripherals. Never plug or unplug ROM cartridges or peripherals connected to the user port without first turning off the power. Figure 2-5. Right Side of the Commodore 128 _____ _____ __ __ | \___/ \___/ [] |__| |__| | ŻŻŻŻŻŻ|ŻŻŻŻŻŻ|ŻŻŻŻŻ|ŻŻŻŻ|ŻŻŻŻŻ|ŻŻŻŻŻ Controller Port 1 | | | Power Controller Port 2 | On/Off Switch Reset Button Power and Reset On the right side of the Commodore 128, closest to the back, is the power connector. One cord from the power supply plugs in here. The power supply is a small box, about 6 inches long, which converts house current to the lower voltage used by the C128. Next to the power connector is the on/off switch. Notice that although this switch turns off the power to the computer, the power supply itself keeps going. You might want to unplug the power supply from the wall outlet if you're not going to use the computer for a while. This will make the power supply last longer. You can also buy a "power strip," a row of outlets with its own switch which plugs into the wall. This is useful because you can plug your computer and all your peripherals into it, and turn them all off at once with the switch on the power strip. Next to the on/off switch is the reset button. This is used to restart your machine without turning it on and then off again. You may need to restart it if a program gets "hung up," and the computer will not respond to keyboard commands. Also, some types of copy-protected software require you to reset the computer before they will load. You can do this by turning the computer off and then on again, but that's hard on the electrical components inside the computer, so it's better to use the reset switch. The Controller Ports The controller ports are for joysticks and similar devices. Attaching such devices is fairly straightforward: you simply plug them in. Be careful, however, if you're only using one joystick, to plug it into the correct port. Software written by Commodore generally requires you to plug your joystick into port number 1, while that written by other developers often requires you to use port number 2. The rest of the connections are found on the rear of the C128, shown in Figure 2-6. Figure 2-6. Rear View of the Commodore 128 TV Channel Selector Switch ,TV Output | |ŻŻŻŻŻŻŻŻŻŻ| _______ ( ) ( ) \__ o' ____ | \ |__________| |-------| | | ŻŻ \__/ |ŻŻŻŻŻŻŻŻŻŻ| / ŻŻŻŻŻŻŻŻŻ|ŻŻŻŻŻŻŻŻŻ|ŻŻŻŻŻŻŻ|ŻŻŻŻ|ŻŻŻŻŻŻŻŻŻŻŻŻŻŻ|ŻŻŻŻŻŻŻ|ŻŻŻŻŻŻŻŻ Expansion Port | | Composite Video | User Port (Program Cartridges) | Serial Port RGBI Video Output Cassette Port The Serial Bus Connection This connection is used for several different kinds of peripherals, most commonly disk drives and printers. Technically, the word serial means that each character or byte of information is sent in separate bits, one after the other. Since each byte is composed of eight bits, this way of sending information is theoretically eight times slower than sending each byte all at once, as is done in a parallel connection. However, sending all eight bits at once requires eight separate connectors, so the serial technique is less expensive. The word bus refers to a kind of data path used in the computer. The bus is really more like a highway than a bus. Data is sent down the bus to a variety of different destinations. Like cities lying along a highway, peripherals can occupy different positions along the bus. Let's look at this arrangement in more detail. Daisy-Chaining An unusual feature of the serial bus connector is that more than one peripheral can be plugged into it. How is this possible? Through a technique called daisy-chaining. This means that the first peripheral is plugged directly into the serial bus connector on the back of the computer. Then the second peripheral is plugged, not into the computer, but into the first peripheral. The third peripheral is plugged into the second, and so on. There can be as many as five different peripherals connected to the Commodore's serial bus connector. This process is shown in Figure 2-7. A question that might occur to you is, if all these peripherals are on one cable, how does the computer know which peripheral it's talking to when it sends a message out this connector? Because the Commodore 128 uses intelligent peripherals that can communicate over a daisy-chained serial bus, connections are simpler than on other computers, and expanding the system is also easier. Figure 2-7. Daisy chained Peripherals [Picture of a Commodore 128 connected to a disk drive, which is in turn connected to another disk drive, and in its turn a printer] Intelligent Peripherals To understand how the serial bus connector works, you should know that the Commodore 128 can make use of a special kind of peripheral device called an intelligent peripheral. In this regard the Commodore is unusual in the computer world. Most computer systems can only use what can be called "dumb" peripherals. The computer tells them exactly what to do, and they report back every little thing that's going on inside them, and can make no decisions without the computer's help. The C64 and C128, on the other hand, can use peripherals that perform complex tasks all by themselves. The disk drive, for instance, can format a disk, keep track of what programs are on a disk, and read and write programs from the disk, without any help from the computer itself. This intelligence also permits the computer to communicate with a particular peripheral, even though there are several peripherals connected to the single serial bus connector. Every time the computer sends a message to a peripheral, such as a request to the disk drive to send a file, it sends something called a device number along with the message. Each peripheral has its own device number, and when it sees the message going down the cable, it checks to see if the number on the message is addressed to it. If the disk drive is device #8, for example, and the message is for device #4 - the printer - the disk drive will ignore it; but the printer will accept the message and do what the message says, probably to print out a particular file. Now you know why only certain peripherals, those built especially for the Commodore system, will work on the C128. They must be intelligent peripherals, capable of interpreting the special messages sent from the computer. Networks and File Servers Another use for the serial bus connector is to connect a number of C128s or C64s together so that they can all share certain peripherals - commonly a disk drive and printer. This is a popular system in schools, where it's more economical to give each student only the keyboard unit, and buy a disk drive and printer that will serve an entire class. In such a system, each computer is connected - via the serial bus - to a box called a file server. The file server is, in turn, connected to the printer and disk drive. [2.11] The User Port The user port is a connection on the right-hand side on the rear of the Commodore 128. It is most commonly used for modems, but it is also used for a variety of more esoteric peripherals, such as voice synthesizers, model train controllers, and so forth. It is, in many ways, like the RS 232 port which is standard on many other computers - but there are differences - so that standard RS 232 equipment, such as modems, will not work. Modems and other equipment which use this port must be specially modified to work with Commodore equipment. This port is the same on the C128 as it is on the old C64, however, so that any equipment that is attached to the user port on the C64 will work on the C128. To attach a Commodore modem to this port no cable is needed: you simply push the modem right into the port. Of course, you must then connect the modem to the telephone, following the instructions for the particular modem. It is possible to use standard RS-232 equipment with this port, but you'll need a special adaptor to make it work with the C128. The TV Output and Channel Selector Switch This small round outlet is where you plug in the cable if you're using a standard TV set. The cable actually connects the computer to the switchbox, which is, in turn, connected to the TV. The channel selector switch is set to channel 3 or 4, whichever channel is not used (or is weakest) in your area. Composite or Direct Video Connector This connector is the leftmost of the two large round connectors on the rear of the C128.This kind of connector is called a DIN connector. The cable coming out of it separates into several RCA-type jacks (the kind you use to connect your hi-fi equipment together). If you're using the direct color monitor, these jacks go to three separate connections on the back of the monitor, labeled chrome, luma, and audio. If you're using the composite monitor, there are only two jacks to connect to the monitor: the video signal and the audio signal. The RGB Video Connector This is the small oblong D-connector. It connects directly to the back of four different jacks: red, green, blue, and audio. The Expansion (or Program Cartridge) Slot This is a simple connector to use, but its effect on the computer is rather complicated. The most common use of this slot is for plugging in program cartridges. This is easily done: you turn the computer off, plug in the cartridge, turn the computer on again, and the game or whatever program is in the cartridge takes control of the computer. Besides games, you can also use this slot to change your computer from one which speaks BASIC into one which speaks other computer languages, such as FORTH. If you know something about how computers work, you'll be interested to know that almost every interior signal in the Commodore 64 and Commodore 128 computers is made available on this connector, including the data bus and the address bus. Thus, whatever is plugged into the slot can completely take over the operation of the computer, changing it into a machine with different characteristics. It's even possible to plug in a different microprocessor chip here, so that the computer assumes an entirely different personality. The C64 uses this capability to turn itself into a CP/M computer with the aid of an optional cartridge; on the C128 this capability is built into the computer. The Cassette Port The type of connector used for the cassette port is called a Molex. A cable from the Commodore Datasette recorder or another recorder specially designed to work with the Commodore 128 plugs in here. Now that you know what peripherals are available for the C128 and how to hook them up, you're ready to find out more about the three modes of the Commodore 128 Personal Computer: the C128 mode, the C64 mode, and the CP/M mode. In our discussion of each of these modes we'll have more to say about which peripherals are suitable for which mode. [3.] The C128 Mode In this chapter you'll learn: * What the C128 mode is * What the C128 mode has to offer * What equipment you will need to use this mode * The new features of BASIC 7.0 * About the C128 Disk Operating System * Sources for additional information The C128 Mode is one of three possible operating modes for the Commodore 128 personal computer. It is in this mode that the C128 distinguishes itself as more than just a slightly enhanced version of the Commodore 64. The purpose of the first part of this chapter will be to clarify this mode's more interesting features and its more unusual characteristics, and to explain the various applications suited to the C128 mode. The next part of the chapter explains which extra system components you should have to use this mode. Then we'll summarize the operations possible from the new version of BASIC, and the disk drive support provided by the new DOS. Lastly, we tell where you can go to get additional information or help about this mode. [3.1] What Is the C128 Mode? As you will recall from the introduction, Commodore had three different markets in mind when it designed the Commodore 128. It wanted the C128 to be "absolutely compatible" with the Commodore 64 (the C64 mode), but it also wanted the C128 to have sufficiently enhanced features, as compared to the C64, to attract new buying interest (the C128 mode). It also wanted the C128 to run software written for CP/M based computers (the CP/M mode). In order to meet these three design goals Commodore had to literally design three modes of operation into the C128. At first thought, such a feat might seem very difficult, especially if the three personalities were really different, as they are in the case of the C64, C128, and CP/M modes. Building three computers into one multimode computer would have been an impossible task had Commodore limited itself to traditional computer designs. Instead, it compared the various hardware and software components that make up a C64, a C128, and a CP/M machine to see exactly how they overlapped with one another. Then it built the Commodore 128 using a composite pool of all these components, and used an organizer function (an intelligent memory/device manager) to arrange the parts to make a C64, a C128, or a CP/M computer on the fly. Figure 3-1 shows this arrangement of different components as used in the C128 mode. As you can see, some components of the Commodore 128 are not used in the C128 mode, and others are. The overall selection was to ensure the best possible arrangement of all C128 features. Details on how these components are rearranged for the C64 and CP/M modes will be found in chapters 4 and 5. Figure 3-1. How C128 Mode Stacks Up ##======================================## || Keyboard, Controllers, || || User Input/Output || ##======================================## || SID 3 Voice Sound Synthesizer || ##======================================## || VIC-II 40 Column Text + Graphics || ##=========================##===========## || 8563 80 Column || C64 Kernal | || Text + Graphics || BASIC 2.0 | ##==========##=============## | | CP/M || C128 Kernal || | | 3.0 || BASIC 7.0 || | +-----------##=============##------------+ | 64 K RAM || 128 K RAM || 64 K RAM | +-----------##=============##------------+ | Z80 A || 8502 || 8502 | +-----------##=============##------------+ | CP/M Mode || C128 Mode || C64 Mode | ##==========##=============##===========## || Intelligent Memory/Device Manager || ##======================================## [3.2] What Does the C128 Mode Offer? When used in the C128 mode, the Commodore 128 is essentially an enhancement of the Commodore 64. As such, this mode offers all of the features of the C64 with very few of its disadvantages. The C128 mode has access to the same graphics and sound capabilities and the same input and output capabilities, including the expansion bus, the versatile programmable user port and the two internal real-time clocks. It will even operate with all C64 peripherals, such as the 1702 color monitor and the 1541 disk drive. On the other hand, the C128 mode removes its users from having to work within the somewhat primitive confines of the C64's BASIC 2.0 and its equally antiquated DOS structure. So what are the enhancements? To begin with, the C128 mode has access to at least twice the memory of a C64. It also provides a second powerful, 80-column color text and graphics system, a better equipped 96-key keyboard, and access to a friendlier and faster single- or dual-disk drive system. The C128 mode enhancements just mentioned are changes to the computer's hardware side. On the software side, Commodore updated the Kernal Operating System (its built-in operating instructions), added some important enhancements to the screen editor, built in a super powerful machine-language monitor utility, and threw in the most powerful BASIC ever in a Commodore computer. Lastly, when you use the C128 mode with one of the new multiformat disk drives, the 1571 or 1572, you get double-sided disk storage instead of single (twice as much room per disk) and a noticeably improved computer-to-disk-to-computer transfer rate. Let's examine each of these features in more detail. What Types of Applications Does the C128 Have? The Commodore 128 is an extremely capable computer, with features that broaden its appeal to a much wider range of applications than those the C64 focused on. For all its graphics and sound power, the C64 had a number of weaknesses that made it more useful for applications relying on eye and ear stimulation than for those requiring fast or versatile computing power. As a result, the C64 found its primary niche in applications such as entertainment and education. The C128, on the other hand, incorporates 128K of memory, a choice of both 40- and 80-column screens and a more business-capable disk storage system, plus a number of other enhancements that make it adaptable to just about any personal computer application. Because of the C128's unique balance of computing features it will find equal acceptance in homes, schools, offices and even industry. For example, the types of real-life situations the C128 can be used in include: Office productivity Business management Computer aided design Instrumentation control Computer software design Computer aided instruction Personal productivity Home management Entertainment [3.3] What Are the C128 Mode Enhancements? In order for you to appreciate why the C128 is capable of such different working applications you need to understand how its new features affect its overall capabilities as a personal computer. That's what we'll explore in the following section. More Memory The C128 mode offers 128K of user memory, or twice that found in the C64. It also has memory space for larger ROM-based software packages. A ROM based software package is software that is permanently stored in a special memory chip that can then be used by the C128. This type of software is merged into the C128 memory either as a cartridge through the C128's expansion slot or as a "ROM chip" addition inside the C128. For many C128 users, the expanded memory of the Commodore 128 means only one thing: they'll be able to run larger and more sophisticated software programs like Artificial Intelligence (AI), Expert Systems, large spreadsheets, and fuller-featured text editors. This is an important consideration, since many non-Commodore commercial application programs could only be made available to the C128 if it has a sufficient amount of memory. Whereas a few years ago, 64K of memory was more than satisfactory, today most popular business-oriented software packages are intended to run on systems with 128K or 256K of memory. The C128, with its ROM based operating system and unique intelligent memory manager, frees up virtually all of its 128K of RAM for program use. In contrast, most other personal computers using a disk-based operating system (like CP/M or MS-DOS) forfeit a fair amount of their available RAM to hold their DOS. Since the C128 does not have this type of overhead there is more of the 128K to use for programs. C128's memory power can be further enhanced through the external addition of up to 384K of additional RAM. This added memory is plugged into the C128 via the expansion bus in the same manner that you might plug in a software cartridge. Don't be misled, though - this additional 384K of memory is not intended to be an add on to the existing RAM area. Commodore has chosen instead to use it as a RAM disk. A RAM disk is a section of RAM memory that is used as if it were another disk drive. Programs and data can be moved back and forth from regular memory to the RAM disk area just as if a disk drive were involved. The major advantage of this type of memory use is speed, since programs and files can be moved from one area of memory to another in a fraction of a second. This is a quantum improvement in speed; even when compared to the typical transfer rate of a very fast disk drive. A RAM disk option is especially useful with a large application that normally has to continually read and write to a disk during operation. Of course, when you are finished using a particular program all data in the RAM disk area must be saved on a disk or it will be lost. Further, before a program can be used from the RAM disk area it must first be copied to it from a disk. A Larger Keyboard Selection The Commodore 128 has a new keyboard. The C128's keyboard, shown in Figure 3-2, has 26 more keys than the C64. To begin with, there is the original C64 keyboard area. This section has all the familiar multifunction text and graphics keys, as well as the standard C64 control keys: , , , , , , and . The Commodore 128 adds a 14-key numeric keypad just to the right of the main keyboard. This is perfect for long sessions of calculator style data entry. The keypad even has its own plus, minus, decimal and keys to add to its convenience. Directly above the main keyboard is a single horizontal row of 16 keys, divided into four banks of four each. These key banks include the original C64 Function Keys, a new set of individual up, down, left, and right cursor motion keys, and eight special-purpose keys. The four physical "function keys," so familiar to C64 owners, are now located just above the numeric keypad section. As before, these keys can have two different values assigned to them (F1/F2, F3/F4, etc.); that is why Commodore refers to them as eight actual keys. Regardless of how you count them, they remain very important because of what they are not - they are not predefined in the same way as the other keyboard keys. Instead, they are user definable keys. This means that their definitions, either simple or complex, can be changed through software - a nice plus for creating menu driven application programs. The Commodore 128's new keyboard has two very important keys - ESCape and ALTernative (located in the leftmost bank of new keys). and keys have been pretty common to business-style small computers for a number of years now, so it was only natural for Commodore to provide them on the business oriented C128. The purpose of these two keys is to further extend the range of different code combinations that can be output from the keyboard. By doing so they make the C128 more attractive to those established business software developers who are used to working with more traditional keyboard arrangements. The key is of particular use to C128 users, especially those planning to write their own BASIC programs. When the C128 is in BASIC, pressing the key sends a special "give me help - where did I go wrong" signal to the BASIC interpreter. If used just after a BASIC program stops due to some error condition, then BASIC will respond with additional information as to where and possibly why the program ran into trouble. Of course, since the key, like all C128 keyboard keys, is also redefinable it is certain to become a favorite for application software developers too. The remaining new keys, summarized in Table 3-1, all add certain operating conveniences to the C128. Figure 3-2. The C128 Keyboard [Omitted] Table 3-1. New Keys for the Commodore 128 -------------------------------------------------------------------------- Key Definition or Function -------------------------------------------------------------------------- Used in conjunction with one or more text keys to generate an ESCape code sequence (used in the C128 in the CP/M terminal emulator mode). Used to move the cursor to the next Tab Stop. Used simultaneously with some other text key to generate a special ALT code. Used in the 80 column mode to allow independent selection of upper and lowercase letters and the two graphics sets. Used in BASIC 7.0 to locate errors while programming. May also be used as a general "HELP" key by some software applications. Provides a LINE FEED without CARRIAGE RETURN. <40/80 Disp> Switches display from 40 to 80 columns. Inhibits screen scrolling by preventing the cursor from going beyond the 25th display line. <^> Moves cursor up one line. Moves cursor down one line. <<-> Moves cursor left by one character position. <->> Moves cursor right by one character position. Function Keys Definable function keys (see BASIC 7.0 section). 14-Key Keypad Calculator style keypad with separate plus, minus, decimal, and keys. -------------------------------------------------------------------------- [3.4] 40- and 80-Column Text and Graphics Another new feature of the C128 mode is its ability to display 80 as well as 40 characters on a line. This is possible because of a second video processor chip inside the C128. This chip, an 8563, can be used instead of the standard 40 column chip by depressing the <40/80 Disp> key to its locked-down position before either applying power to the C128, or by pressing the RESET button when power is on. When this is done, the C128 initializes itself in the 80-column format. Of course, to use this new screen mode you must have a video monitor, capable of displaying 80 columns, connected to the C128's RGBI connector. Switching back to the 40-column mode also requires either turning the power off and on again or pressing RESET. Fortunately, there are ways to perform the screen mode switch from within a program, which is how most commercial software will ensure that the C128 is in the correct screen mode. The advantages to using the new 80-column screen mode are numerous. Naturally, you have an 80-character by 25-line display so you can have up to 2000 characters on the screen at the same time, and they can be in color. What's more, because of the bit-mapped nature of this screen mode you can have the C128 display a total mix of all available text and graphics characters (not possible in the 40-column mode) and even mix text and graphics characters with high-resolution drawings. The character font definitions within the C128 (they determine what shapes will show up on the screen when you press a certain text or graphics key) can be changed to give the screen output a totally new set of characters - even a new language. It is possible by doing a little internal rearranging to use a reduced-size character set and obtain an even larger 132-column by 25-line screen display. Remember that the C128 has access to both the 40- and the 80-column screen video processors and the C128 can take advantage of that fact too. Not only can the C128 choose between these modes according to the position of the <40/0 Disp> key, the screen modes can also be switched from within a program. Therefore, it is possible to use two displays (a 40-column display and an 80-column one) to show outputs from the same program. Both displays can't be updated at the same time but changes can be alternated between the two. As long as both displays remain enabled, their outputs will stay visible. As the 40- and 80-column outputs come from separate screen processors, they can display different information and even be in totally different text and graphics modes. In order to take advantage of this dual-screen display ability the C128 must have both of its video outputs connected to appropriate video monitors. We'll discuss this more later. The Commodore 128 can actually be speeded up internally by using the 80-column screen mode by itself. To do this, you must use software to actually turn the 40-column chip off. C128 data processing operations, when used in this manner, run at nearly twice the rate obtained when the 40 column screen processor is enabled. This increase in processing power is greatly appreciated when a computer is required to do the type of data processing and number crunching typical of most business, industrial, and scientific applications. Enhanced BASIC The enhanced BASIC, called BASIC 7.0, that is available to you in the C128 mode is the most powerful version of BASIC yet offered by Commodore. In all there are 140 commands, operations, and functions - 20 commands, 35 operations and 13 functions more than were found in the Commodore 64's BASIC version 2.0. BASIC 7.0 gives you increased control of: program flow; conditional testing; logical evaluations; mathematical functions and procedures; text manipulation and output; data input, processing, storage, retrieval, and presentation; file construction and usage; program testing; and just about every conceivable graphics and sound operation that the 128 can perform. In addition, BASIC 7.0 supports a full array of commands that greatly simplify the tasks of disk drive control and file maintenance. Despite its enhancements, BASIC 7.0 remains downward-compatible with earlier Commodore BASIC versions 2.0 and 4.0. That is, a program written for the earlier Commodore BASICs will run under 7.0, although not vice versa. Note that this downward compatibility applies to the program as written on paper. The disk versions of BASIC programs are stored differently, and are not compatible. BASIC 7.0 takes advantage of nearly the full 128K of the C128's RAM (122365 bytes), and does it in such a way as to eliminate the old "garbage collection" delays that occurred when larger BASIC programs were run on the Commodore 64. (C64 programs would often halt on their own for several minutes while BASIC 2.0 tried to make room in memory for more operations.) 64K of the Commodore 128's memory is set aside to hold just the program code, while all variables generated by that program are kept and maintained in the other 64K segment of memory. With so much memory space, it is possible to further divide the C128's memory so that a number of programs can be placed in memory at the same time. Another feature of BASIC 7.0 is that the C128's eight function keys come predefined with often-used BASIC commands. Of course, they can be easily redefined by BASIC commands to perform other operations of your choice. Later in this chapter we'll take a look at the various commands, statements, and functions found in BASIC 7.0. Enhanced Screen Editor Commodore computers have always been famous for the versatility of their built-in screen editors. These "full screen" editors act as temporary working windows where you write and organize your BASIC commands or program statements. Through them you can move the cursor anywhere on the screen, insert and delete any number of characters, and erase the screen completely. Commodore screen editors have some interesting side capabilities too. For example, you can list a group of lines from a program in memory to the screen and then use the screen editor's cursor motion and editing keys to change anything on any BASIC line within the editing screen, although nothing actually changes in BASIC's program memory until you press the key. Duplicating entire lines is as simple as typing a new line number over the old and pressing . The screen editor also has a special quote mode that allows you to mix text, graphics, and even cursor actions right in your program code. Commodore has added some new features to the Commodore 128's screen editor to improve upon the C64's screen editor. For example, program lines can be 160 characters long, as compared to 80 on the C64. This is made possible by an ingenious form of auto-wraparound within the screen editor that keeps track of where on the screen each BASIC line begins. In the 80-column screen mode a BASIC statement can be two screen lines in length, while in the 40-column mode it can be up to four screen lines. Two other screen editor enhancements are line insert and delete and four way margin control. Built In Monitor Program for Assembly Language Programmers The Commodore 128 has a built-in Machine Language Monitor. This special programming utility was once a built in feature on all Commodore PETs, but was later removed from the VIC 20 and C64 due to memory restrictions. The Monitor, as it is called, is an absolutely essential tool for anyone interested in writing, testing, or modifying programs written in 8502 machine language. It will be used by professional software developers as well as by C128 owners who want to write short and fast machine language routines to speed up critical parts of their own BASIC programs. The Monitor is also an excellent learning tool for students who want to understand how machine language programs work (most commercial software is written in machine language, and so are programs like BASIC 7.0, Logo, and FORTH). The Monitor utility in the Commodore 128 is an enhanced version of the earlier Commodore monitors. A similar version was made available to Commodore 64 users as part of Commodore's "Assembler Development Package" for that machine. Table 3-2 summarizes the monitor commands built in to the C128. Complete details on how the monitor is used can be found in both the Commodore 128 User's Guide and the Commodore 128 System Guide. Table 3-2. Commodore 128 Monitor Command Summary -------------------------------------------------------------------------- Command Command Name Command Description -------------------------------------------------------------------------- A ASSEMBLE Assembles a line of 6502 machine code C COMPARE Compares two sections of memory and reports the differences D DISASSEMBLE Disassembles a line of 6502 machine code F FILL Fills memory with the specified byte G GO Starts 6502 code execution at the specified address H HUNT Hunts through memory within a specified range for all occurrences of a set of bytes L LOAD Loads a file from tape or disk M MEMORY Displays the hexadecimal and ASCII values of memory locations R REGISTERS Displays the 8502 registers S SAVE Saves memory to tape or disk T TRANSFER Transfers code from one section of memory to another V VERIFY Compares memory with tape or disk E EXIT Exits Commodore 128 MONITOR . (period) Assembles a line of 6502 code > (greater than) Modifies memory ; (semicolon) Modifies 8510 register values @ (at sign) Displays disk status -------------------------------------------------------------------------- Faster and Friendlier Disk System The last really important enhancement that the Commodore 128 provides is improved disk storage capabilities. Not only can the C128 operate using the Commodore 64's 1541 single-sided disk drive, it can also work with its own special "super intelligent" double sided disk systems - the 1571 (single drive) and the 1572 (dual drive). You can choose to use the C128 with one or more of the older 1541 disk drives as they are totally compatible. However, doing so does not provide you with the disk storage improvements that the C128 is capable of - more storage capacity per diskette and vastly improved data transfer rates. The advantage of the new disk system's increased friendliness is a function of BASIC 7.0, not the drives, so the C128's friendlier disk commands hold true even for the 1541s. The real improvement in disk storage capabilities happens when the C128 is used with the 1571 or 1572 disk drives. When these drives are used, the C128 has immediate access to twice the storage space per disk of the 1541s. For example, the 1541 could store 170K of programs and data per disk, but the 1571 and 1572 can store 340K per disk. Of course, the total disk storage space available to the C128 doubles to 680K when you consider both disks in a dual drive 1572. In addition to storage space improvements, these new drives are also fast. The 1541, with its typical data transfer rate of about 320 characters per second, is extremely slow in operation and, unfortunately, doesn't get any faster when it is connected to a C128. On the other hand, the new drives, when used in the C128 mode, operate at up to 5200 characters per second. High data transfer rates like this make the C128 a viable machine for even the most disk-intensive business application. Finally, Commodore has provided the C128 with an easy to use set of DOS commands. The DOS commands are the same as those found in the late model Commodore PET and CBM machines (BASIC 4.0). DOS calls are used to perform a wide assortment of disk-related functions, including reading directories, formatting blank disks (using a command called HEADER), copying files, renaming files, or removing (scratching) files. When the 1572 dual drive is used there is even a command to copy one disk to another (BACKUP). These commands are very important to all C128 users, so we'll take a detailed look at them later in this chapter. [3.5] What Equipment Do I Need to Use the C128 Mode? As you learned in the previous chapter, the Commodore 128, with all its power and flexibility, is just the computing part of a system. You still need a monitor of some sort so you can view the messages it wants you to see, and you will probably want some form of external mass-storage device to hold your programs and data. Major C128 system accessories also include a printer for a permanent paper copy of important computing activities, and a modem to allow you to connect your C128 to other computers via the telephone. Other system add-ons would really depend on the requirements of your application. Since the Commodore 128 is still compatible with all Commodore 64 peripheral devices, you have a very wide assortment of peripherals to choose from - both old and new. If you already have a complete assortment of C64 peripherals, than you can simply connect them to the C128. Of course, you won't be able to take advantage of all of the C128's features, like the 80 column option or the increased storage ability and speed of the newer disk drives; but you will be able to do most anything you want, as long as you remain within the limitations of those C64 peripherals. The best way to take full advantage of your C128's capabilities is to use the system components that were designed specifically for it. Figure 3-3 shows the C128 system configuration that we would recommend for general use. Figure 3-3. Recommended Commodore 128 System [Picture showing: Commodore 128 Computer, 1670 Modem, 1571 Disk Drive, 1902 40 Column Monitor, MPS-802 Printer] If your computer needs are less complicated - for instance, if you simply want to experiment with BASIC 7.0 and 40-column graphics - then you might want to consider starting with a color television as a monitor and a Datasette as a mass storage device. Now that you know the major improvements the Commodore 128 has made over the Commodore 64, let's examine two of these improvements in more detail: BASIC 7.0 and the new DOS. [3.6] All About BASIC 7.0 In this section we'll describe the new BASIC 7.0 that is built into the Commodore 128. This section is presented in three parts. The first part examines the most general facts about BASIC 7.0, giving you a bird's eye view of the language. The second part explains and lists the BASIC statements and commands that are common to both the C64 (BASIC 2.0) and C128 (BASIC 7.0) modes of the Commodore 128. This way you'll get a feel for the available statements if you wanted to write programs that would run in both the C64 and C128 modes. The third part lists and explains the statements unique to the C128 mode. If you are only interested in BASIC 7.0 enhancements then you can read the third section directly, but if you want to know what BASIC 7.0 is like to program with, then you should read the first section as well. Chapters 6 and 7 explore the graphics and sound statements of BASIC 7.0. Important Facts About BASIC 7.0 Let's examine the major features of the new BASIC 7.0 that come with the Commodore 128. Modes When you are in the C64 mode you are actually using BASIC 2.0; the same BASIC found in the Commodore 64. Therefore BASIC programs are written in exactly the same manner as they would be on a C64. When you are in the C128 mode, however, BASIC 2.0 is replaced with BASIC 7.0 and you have virtually an entirely new programming environment to work in. Modified Microsoft BASIC Commodore 128 BASIC is a modified version of Microsoft BASIC, commonly referred to in the CP/M universe as MBASIC (see description of MBASIC in Chapter 5, CP/M Mode). The new BASIC 7.0 is based on statements from the older C64 BASIC 2.0. Added to these are disk statements and commands from the Commodore PET/CBM BASIC 4.0 (the CBM line of business microcomputers). In addition there is a large number of new statements for controlling sound, graphics, windows, sprites, and peripherals. Microsoft BASIC was the first BASIC made available for the 8080, Z80, and 6502 microprocessors and enjoys a wide following. The new BASIC 7.0 has included several new statements that tend to completely remove several C64 BASIC 2.0 weaknesses, chiefly in the area of program control and looping. Also added are new statements for graphics, sound, windowing, external I/O devices, and keyboard access. Onscreen Editor The new BASIC 7.0 is built around a cursor key controlled onscreen editor. This is much like the BASIC editor of the IBM PC, where to alter or edit a line of the program, you move the cursor to the line you wish to change, type the correct information, and press to capture the change. When using the 40-column screen mode, BASIC 7.0 allows the same keyboard character and graphics set combinations as on the C64. Therefore you still can't display upper- and lower-case letters with both sets of keyboard graphics. On the other hand, when BASIC 7.0 is used to program for the 80-column screen mode, you can mix and match all available text and graphic symbols. Also when you enter a program in BASIC 7.0, putting spaces between keywords, variables, operators and such is strictly optional. Adding spaces will clarify the meaning of statements, and spaces consume very little additional memory space, so they can be used generously. Graphics and PRINT Statements Any characters, any colors, and any cursor activity can go inside of quotation marks. That is, you can use any key on the keyboard directly in PRINT statements. Thus you can insert dozens of cursor direction keys, graphics symbols, and colors in PRINT statements, and thereby create complex images on the screen. Programmable Function Keys and Other Keys There are four function keys, and each key can perform two functions. The keys are programmable from BASIC and thus can be used by your program for any function you want. When you first start BASIC the function keys are predefined, as shown in Table 3-3. F1, F3, F5, and F7 functions are accessed directly by pressing the appropriate key. You use the key to access the F2, F4, F6, and F8 keys. You program a function key with the KEY command to stand for some other BASIC sequence or string. For example: KEY 7, "GRAPHIC 0" + CHR$(13) would make the command GRAPHIC 0 followed by a carriage return occur when was pressed. BASIC also responds to the , , , , <40/80 Disp>, , and keys. Each of these keys has its own initial definition and this definition can be changed in BASIC. Table 3-3. Predefined Functions Keys in BASIC 7.0 (C128 Mode) -------------------------------------------------------------------------- Key BASIC Keyword Purpose -------------------------------------------------------------------------- F1 GRAPHIC Sets graphic mode you enter F2 DLOAD" Loads a filename you type F3 DIRECTORY Gives a directory of the disk F4 SCNCLR Clears the screen to current background color F5 DSAVE" Saves a filename you type F6 RUN Runs the program in memory or one on disk F7 LIST Lists the program in memory F8 MONITOR Enters the machine language monitor -------------------------------------------------------------------------- Memory and BASIC 7.0 BASIC 7.0 has access to all 128K of the Commodore 128's total RAM space. This 128K is split into two banks. The lower 64K bank is for the text portion of BASIC programs: the actual statements that make up the program. The upper 64K bank is used strictly as work space. This is where BASIC will keep the program's variables, arrays, and strings. The BASIC interpreter occupies 48K of ROM. Since arrays, strings, and variables are kept in a separate area of memory, this configuration allows the texts of a BASIC program to occupy a full 64K regardless of the length of strings or arrays. This means a 64K program on the C128 is actually equivalent to a much larger program on the C64; thus longer, more sophisticated programs are possible. Variables and Limits of BASIC 7.0 BASIC 7.0 allows three kinds of variables: normal numeric (floating point), integer, and string variables. A floating point variable is assumed as a default (that is, BASIC will assume you mean floating point unless you tell it otherwise). Floating point variables can have up to nine digits of significance and can range in size from ten to the -38 power to ten to the +38 power. In BASIC 7.0, integer variables (whole numbers without fractions) range between -32768 and +32767 and are indicated in a program by appending the percent symbol (%) to the end of a variable name. String variables, used to hold symbolic data like text and graphics, can be up to 255 characters long and are indicated by a $ sign appended to the end of the variable name. A variable name in BASIC 7.0 can be as long as desired, but only the first two characters are significant. In other words, UNCOLA and UNLIMITED are legal variables, but are considered by BASIC to refer to the same variable. The first character has to be a letter but the second character may be a letter or a number. Graphic symbols are not allowed in variable names. Here are some legal BASIC 7.0 variables: FOOBAR a floating point variable NAME$ a string variable P123% an integer variable BASIC arrays are defined by the DIM statement. The number of dimensions is limited only by the length of the program line. Arrays follow the same name rules as regular variables do. Besides BASIC keywords, there are eight variable names that are reserved to BASIC 7.0 and can't be used in your programs. These are listed in Table 3-4. The Commodore 128 has a built in 24 hour clock function that is automatically updated every 1/60th of a second. It is both set and read using the reserved variable TI$. This clock is not a separate real-time clock operation, but instead a software jiffy clock just like the one used in the C64. It is most appropriate for programming operations where short term accuracy is required as it does lose count during certain system operations (for example, when the disk drive is being used). Since there is no battery backup, the clock must be set each time the computer is powered up. You can use the error trapping variables with the new TRAP command to process errors in more creative ways than BASIC normally offers. The disk channel variable DS lets you find out why the red error light on the disk drive is blinking. Table 3-4. Reserved Variable Names in BASIC 7.0 -------------------------------------------------------------------------- Variable Purpose -------------------------------------------------------------------------- ST Status variable: tells success of an I/O operation TI Holds the value of the 24 hour jiffy clock TI$ Sets the jiffy clock with this variable DS Reads disk drive command channel, returns status EL Line where the last error occurred ER Returns last error (number) since the program was run ERR$ Contains error message for last error -------------------------------------------------------------------------- Other Details BASIC 7.0 offers all the normal math operators (+ - * / ^) and has the logic operators AND, OR, and NOT. The length of a BASIC 7.0 line is limited to 160 characters (counting spaces). Thus a BASIC line can occupy two lines on an 80-column screen and four lines on a 40-column screen. Overview of C128/C64 Common BASIC Statements In this section we will briefly review the statements and commands that are common to both BASIC 2.0 and BASIC 7.0. The BASIC DOS commands are covered in a separate section later in this chapter. Assignments and Equates Both BASIC 7.0 and BASIC 2.0 offer statements for clearing all variables, defining a custom function, and for dimensioning an array. These are shown in Table 3-5. Table 3-5. BASIC Assignments and Equates -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- CLR Clears out variables and arrays DEF Defines a custom function DIM Dimensions an array LET Optional assignment statement -------------------------------------------------------------------------- Programming Commands As Table 3-6 shows, both BASICs have commands that let you manipulate the program in memory. Table 3-6. BASIC Programming Commands -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- LIST Lists program in memory to screen REM Adds a remark or comment to a line STOP Program will stop and print out line number NEW Erases current program and all variables RUN Runs or executes current program or filename CONT Continues a stopped program -------------------------------------------------------------------------- Looping The statements for controlling program flow and looping are listed in Table 3-7. The standard FOR...NEXT loop allows looping a fixed number of times. A STEP option allows making the loop index at some value other than one. GOSUB is used for branching to subroutines. A RETURN statement returns control to the line following the GOSUB. ONGOSUB is a more advanced GOSUB that allows indexed subroutine branching. Table 3-7. BASIC Looping Statements -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- FOR...NEXT STEP Loops a fixed number of times GOSUB/RETURN Used for branching and returning from subroutines GOTO Forces direct jump to a program line number ONGOSUB Indexed GOSUB ONGOTO Indexed GOTO RETURN Return from subroutine -------------------------------------------------------------------------- Program Control Statements Several useful program control statements are provided, as shown in Table 3-8. The WAIT statement is a way to make the program stop and wait for a particular bit in a specific memory location to change. It is mostly used to monitor the status of bits in input/output registers, such as sprite registers. Table 3-8. Program Control Statements -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- END End program execution RESUME Resume program execution at a certain line WAIT Wait for a memory location to change -------------------------------------------------------------------------- Machine and Memory Control As shown in Table 3 9, there are several useful statements for controlling the memory of the C128, including PEEK (which reads the contents of a memory location) and POKE (which places an integer between 0 and 255 in a memory location). The SYS statement performs a call (like a GOSUB) to a machine language subroutine at a certain address. It can also optionally load the arguments a, x, y, and s into the accumulator, x-register, y-register, and stack register of the 8502 microprocessor. The address range of SYS is 0 to 65535 so the high bank of the 128K memory must be accessed indirectly with SYS. USR is another function that allows you access to a machine language subroutine. Unlike SYS, USR requires that you poke the starting address of the machine language routine into two specific memory locations (1281 and 1282). USR can also pass a parameter (a variable value) from BASIC to that routine and from that routine back to BASIC. SYS will not allow you to pass this type of two way parameter. Table 3-9. Machine/Memory Control -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- PEEK Returns contents of memory location POKE Places a value in a memory location SYS Calls a machine language subroutine and loads registers USR Calls a machine language subroutine and passes parameter -------------------------------------------------------------------------- Input/Output and Data Control Both BASIC 7.0 and BASIC 2.0, as shown in Table 3-10, provide numerous statements for controlling the input and output of information, as well as the storing of information and data within the program. The INPUT and GET statements are used to get information typed at the keyboard into variables (string or numeric) in a program. The key must always be pressed to terminate anything typed in response to the INPUT statement. The GET statement (used only with string variables) does not need a as it simply reads the keyboard for its current status and returns whatever key value (including none) that it received to its variable. INPUT# and GET# are two variations of INPUT and GET that are used to read from any file structured input devices like the Datasette disk drive, modem, and even the keyboard. PRINT is the statement used to output information to the display. PRINT# is used to output information to any file structured output device. CMD is a redirection command that allows you to redefine the default output device. DATA is used to store a list of constants, numbers or letters, in a program in an easy-to-read format. READ is used to assign these constants in the DATA statements to variables. Table 3-10. Input/Output and Data Control Statements -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- GET Allows inputting a keyboard character without ~ Return GET# Single character inputting from any legal input device INPUT Inputs a string or number from the keyboard INPUT# Inputs a string or number from any legal input device PRINT Displays a string or number on the screen PRINT# Displays a string or number to any legal output device DATA Holds a list of numbers or strings READ Reads numbers or strings in data statements into variables RESTORE Resets the DATA/READ pointer -------------------------------------------------------------------------- Functions Functions perform operations on numbers, strings, output devices, and memory. Table 3-11 shows that BASIC 7.0 and BASIC 2.0 contain a large number of these functions. The functions are used for obtaining the SIN or COS of a number, converting a string to a number, or vice versa, and so on. It also tells if a joystick fire button has been pressed. This completes the description of the BASIC statements and keywords common to both BASIC 7.0 and BASIC 2.0. In the next section we will examine those enhanced keywords that are particular to BASIC 7.0. Table 3-11. BASIC Functions -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- FRE Tells how much memory space is left ASC Returns the ASCII value of a string CHR$ Converts number to ASCII character INSTR Locates and returns a substring in another string LEFT$ Returns the left N characters of a string LEN Returns the length of a string MID$ Returns the middle N characters of a string ABS Gives the absolute value of a number ATN Returns the arc tangent of a floating point number COS Gives the cosine of a number DEC Returns the decimal value of a hexadecimal string EXP Returns the value of e raised to the X power FN Allows custom functions with parameters HEX$ Returns hexadecimal number string from decimal number INT Truncates decimal portion of floating point number LOG Returns the natural log of X -------------------------------------------------------------------------- Enhanced BASIC 7.0 Statements You can see the real power of the new BASIC 7.0 when you examine the new statements that have been added to it. Here we will present details on all of these except the new DOS, graphics, and sound commands, which we will explore later. The new statements are made up of bit-mapped graphics commands, sprite control statements, and very sophisticated three-voice sound and music control statements. There are also new looping statements that allow more structured programming constructs, and a new window statement that lets you control the rectangle where text will scroll. New C128 Mode Bit-Mapped Graphics Statements Table 3-12 lists the new statements that allow drawing on the bit mapped display. You can draw lines, rectangles, polygons, and circles, and fill them with any color. You can capture a pixel area to a string (most BASICs capture a pixel area to an array) and then draw it anywhere on the screen quickly. There are statements for reading the color of any pixel, and scaling the entire screen to a 1024 by 1024 grid. These statements and how they work are covered in Chapter 6 - Graphics. Table 3-12. BASIC 7.0 Graphics Statements -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- BOX Draws a rectangle CHAR Displays characters at any pixel coordinate CIRCLE Draws a circle, oval, triangle, or polygon COLOR Chooses colors for foregrounds, backgrounds, border DRAW Draws lines and plots points GRAPHIC Chooses one of six graphics modes LOCATE Sets the pixel cursor to a certain pixel coordinate PAINT Fills any closed boundary with a color SCALE Scales the coordinates of the entire screen to 1024 SCNCLR Clears the screen to the current background color SSHAPE Captures pixels of an area in a string GSHAPE Draws pixels captured in a string to the screen WINDOW Draws a window of defined boundaries RCLR Returns the color of a source RDOT Returns the color of a pixel on the screen RGR Returns the mode of the screen RWINDOW Reads the current window boundaries -------------------------------------------------------------------------- New C128 Mode Sprite Control Statements One of the greatest enhancements to the C128 mode BASIC 7.0 is its sprite handling statements (see Table 3-13). Sprites, which are covered in more detail in Chapter 6, are programmable graphic objects used often in games and simulations. Since sprites live on independent bit planes that don't erase each other, and since they can be moved by the VIC II chip automatically, it makes great sense to exploit them in programs. Unfortunately, in the C64, sprites had to be controlled via POKE and PEEK statements, rendering sprites quite difficult to control. The new BASIC 7.0 contains a set of clear, simple statements that allow sprites to be easily created, edited, saved, colored, expanded, and moved about on the screen. You can also find out when sprites cross over each other, or when they pass over background display data. Table 3-13. BASIC 7.0 Sprite Control Statements -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- BUMP Records what sprites (1 8) hit what COLLISION Causes a GOSUB when sprites collide or sprite hits display data MOVSPR Moves a sprite to new coordinates automatically SPRCOLOR Sets multicolor colors for all sprites SPRDEF Enters sprite editor SPRITE Turns on a sprite, colors it, expands size, sets priority and mode SPRSAV Moves picture string to a sprite or sprite to a string RSPCOLOR Checks what sprite multicolor values last set RSPPOS Checks speed and position of sprite RSPRITE Returns sprite attributes -------------------------------------------------------------------------- C128 Mode Sound Control Statements The Commodore 64 has always been known for its powerful SID (sound interface chip) and the incredible noises that can emanate from it: Bach-like sonnets, powerful symphonies, or screeching sound effects. BASIC 7.0 adds a set of powerful statements for easily creating these effects. Table 3.14 lists the six sound control statements. These are covered in detail in Chapter 7 - Sound. Note that these statements control a three voice music synthesizer. You can create custom envelopes with your own attack, sustain, and release curves, that in turn control one of the three voices. It is easy to have a guitar, drum, and saxophone playing simultaneously. A FILTER statement lets you attach a frequency filter to the output of the SID chip, thereby allowing strange synthesizer effects, like ring modulation. Table 3-14. BASIC 7.0 Sound Control Statements -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- ENVELOPE Creates instrument envelopes: ADSR, sustain, waveform, pulse width FILTER Defines sound filters: low, band or hi-pass, cut-off frequency PLAY Defines and plays notes with sophisticated instrument voices SOUND Sound effects: any frequency with sweep control TEMPO Sets up standard note duration for three voices VOL Sets output volume for SOUND statement -------------------------------------------------------------------------- C128 Mode Program Control Statements Table 3-15 shows the new program control statements that are offered. There is now a DO UNTIL and DO WHILE looping structure. You can say something like this: 100 DO 110 INPUT "DO YOU LIKE YOUR COMPUTER"; ANS$ 120 LOOP UNTIL ANS$="YES" 130 PRINT "THANKS" or you can do this: 100 DO UNTIL ANS$="QUIT" . . (statements) . 200 INPUT "AGAIN OR QUIT"; ANS$ 210 LOOP You can also say DO WHILE something is true or false. The EXIT statement is provided to let you force a program to exit a DO LOOP when a special condition is met. The ELSE statement has been added to the IF THEN statement to allow more elegant decision statements. The BEGIN/ BEND statements are a way of getting around the fact that you can't get a Microsoft BASIC IF THEN statement to allow multiple lines to be executed if the condition is true. Now you can do this in BASIC 7.0: 100 INPUT A 110 IF A<100 THEN BEGIN: 120 PRINT "NUMBER IS LESS THAN 100" 130 BEND: ELSE: PRINT "NUMBER IS GREATER THAN 100" Table 3 15. BASIC 7.0 Advanced Program Control Statements -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- DO/UNTIL/LOOP Structured DO/UNTIL loop DO/WHILE/LOOP Structured DO/WHILE loop EXIT Causes immediate exit from a DO loop IF THEN BEGIN/BEND Allows multiple statements after a THEN IF THEN ELSE Allows processing for false and true conditions -------------------------------------------------------------------------- PRINT USING, PUTDEF, and GETKEY The C128 now allows PRINT USING which means you can format how your numbers appear on the screen. This was one of the most missed statements among C64 BASIC 2.0 users. Decimal points can be fixed and so can the number of digits that are displayed. There is also a PUTDEF statement that lets you replace format characters ($, etc) with any character from the keyboard. This means you can display in British pounds, for example. A GETKEY statement is provided that is similar to the GET statement (used to loop on the keyboard and wait for a key to be pressed). GETKEY eliminates the need to loop: it waits on its own for a keypress. Program Aids Finally, the new BASIC 7.0 adds all the popular Microsoft program entry and aid commands, as shown in Table 3-16. Take special note that the TRAP statement allows you to process user errors and turn off BASIC's normal syntax error checking. Table 3-16. BASIC 7.0 Programming Aids Statements -------------------------------------------------------------------------- Statement Purpose -------------------------------------------------------------------------- AUTO Turns on automatic line numbers RENUMBER Renumbers line numbers of program DELETE Deletes groups of lines HELP Shows where line number error occurred on screen TRAP Branches to subroutine containing user error handler TRON, TROFF Trace mode: displays line numbers as program runs -------------------------------------------------------------------------- [3.7] What Is DOS and How Do I Use It? Commodore disk drives are random access mass storage devices. The term random applies somewhat loosely to a method of storing programs and their data (using files and records). The disk drive method of storage has many advantages over cassette storage, but at the cost of increased complexity. With cassette storage you are personally responsible for starting, stopping, and positioning the tape. Manual operations like these are simply inappropriate to the manner of storage used by disk drives. For example, a single floppy disk can store hundreds of programs or data files with thousands of individual records or both. And these programs and files are partitioned into very small data blocks that are spread all over the disk. It is ridiculous to attempt to control a disk device as you would a cassette. This type of storage control and accounting (knowing where things are, etc.) is better left to a computer. When you use a Commodore disk drive with your Commodore 128 you actually get a second computer with its own special Disk Operating System (DOS) program. Its only task is to manage all disk storage activities for you. What is DOS? The term DOS is a sort of collective name for a group of single purpose disk utility programs. These utilities do things like preparing a brand new diskette for future storage operations, reading the current contents of a diskette, copying data from one diskette to another, and erasing old data to make room for new data. Some DOS utilities have disk operations whose actual functions are less apparent. These "specialty" DOS operations are the ones requested by programs operating in the C128. For example, if a mailing list program needs to see the list of names and addresses already stored on a diskette, the mailing list program must make a series of properly organized requests to the disk drive's DOS. The DOS, in turn, uses the requested DOS operations to locate and then send back this data to the program. DOS operations like these are seldom recognized or even used by C128 users who primarily use commercially written programs, but they are important for C128 users who want to write their own programs. Commodore DOS has a number of disk operations that are primarily used within other C128 programs. The most familiar DOS operations, however, are those used by every disk drive user at one time or another. Where is Commodore DOS Kept? Commodore disk drives are intelligent disk drives. They are intelligent because they have their own internal computer, running under a special Commodore DOS program that allows them to perform routine disk functions and maintenance. What's more, since this DOS program is actually stored in the intelligent disk drive's memory, the drive can do any DOS operation on its own. Most computers need to instruct their drives with a continuous flow of instructions. All the C128 need do is send a single command word or phrase over the serial bus to a Commodore disk drive. The disk drive's computer compares this command against a list of known commands within its own DOS program, selects the appropriate disk function, and the proper DOS operation is performed. Since the Commodore disk drive does all the real DOS work, the C128 need only pass along the appropriate commands and then go back to its normal processing activities. Commodore DOS is stored in ROM in the disk drive. The disk drive has its own computer, with a microprocessor, RAM and ROM memory, and I/O circuits. One advantage to storing DOS in ROM, as opposed to putting it on a diskette, is that a ROM based DOS is there and ready for use as soon as the disk drive is turned on. Another advantage is that the memory space needed to store DOS is taken from the disk drive's internal computer, not the C128's. This means there will be more room in the C128's memory for application programs. Finally, keeping DOS in ROM eliminates the need to keep it on your diskettes, therefore all of the diskettes' available storage can be used for programs and data. Are All DOSs the Same? Commodore has three different disk drives that you can connect to the C128 - the 1541 (designed for the C64), the 1571, and the 1572 (designed to work on any current Commodore computer). All three drives have DOS already built-in. The 1541's DOS is slightly different than the DOS found in the 1571 and 1572, but there is a high level of compatibility between the two. They are programmed by the user in the same way, but their capabilities differ. Many of the differences between the old and the new DOS have to do with the slower serial bus capabilities of the Commodore 64 and the fact that the 1541 could only access one side of a floppy disk (single-sided). The new drives are precision instruments that are able to take advantage of the C128's faster serial bus capabilities. They are double-sided (that is, they use both sides of a floppy disk). Despite these differences, the new drives can read and write to any disks originating from a 1541 (only one side of the disk is used). They do this by changing their DOS "personality" to that of a 1541. What Tasks Can the DOS Perform for Me? Since DOS is stored in the Commodore disk drive, it is running as soon as you turn on the disk drive's power. Thereafter, in order to get DOS to do something for you, all you need to do is get its attention and send it a command. Fortunately, the C128 has a complete set of easy to use DOS commands and statements that are accessible through BASIC 7.0. You will note that many of these commands and statements are similar to one another. This slight redundancy was necessary in order to remain compatible with the DOS structure used in BASIC 2.0 (Commodore 64), while providing an alternate set of disk based commands and statements that are easier to remember and use. Here is a list of these new DOS commands and statements: APPEND CONCAT HEADER BACKUP COPY LOAD BLOAD DCLEAR OPEN BOOT DCLOSE RECORD BSAVE DIRECTORY RENAME CATALOG DLOAD SAVE CLOSE DSAVE SCRATCH COLLECT DVERIFY VERIFY DOPEN Let's review these DOS commands and statements one by one. Those that are referred to as "commands" can be entered directly on the keyboard and can often be included within a program as well. Those listed specifically as "statements" are generally used from within programs only, so they will be of most use to C128 owners who plan to do their own programming using BASIC 7.0. The descriptions we give here are just meant to give you a feel for their functions. Complete details on the actual syntax and modifiers can be found in C128 Users Guide. APPEND The APPEND command is a special "open file" command that is used to add new data to the end of an existing file. BACKUP The BACKUP command copies all files from one diskette onto another. This command can only be used with a dual drive system like the 1572 and it will not back up "copy protected" software. BLOAD This command is used to load binary type files from a disk. The C128 has two disk specific file loading commands - DLOAD and BLOAD. DLOAD is used on files such as BASIC programs that are always placed in the same area of memory. However, not all programs are in BASIC so they don't necessarily go to that same portion of memory. Binary files can go just about any place in memory. Where they go during a load should be determined by the load address parameters that BSAVE automatically tags onto them when they are originally saved. BLOAD reads these parameters and puts the binary files back where they belong (see BSAVE). BOOT BOOT is a completely new DOS command for Commodore computers. It is used to load (and subsequently run) an executable binary file from a disk. Like BLOAD, it does not automatically relocate the file to the start of BASIC memory. BSAVE BSAVE is the binary file variation of DSAVE. It is used to save a segment of C128 memory to a binary disk file. Files created in this manner must be not be loaded with DLOAD as they would be automatically relocated to BASIC memory. Instead they should be loaded with BLOAD (see BLOAD). CATALOG This command is used to read the contents of a diskette's file directory. Its operation is quite different from the C64 method of viewing a directory - LOAD"$",8:LIST. The old command did not work well on long directory listings because you could not stop and start the display once it started scrolling. Also the old method actually loaded the directory into memory as if it were a BASIC file, thus overwriting any BASIC programs already in memory. The CATALOG command corrects both of these deficiencies: its display scrolling can be controlled, and it is loaded directly into screen memory so as not to disrupt BASIC programs (see DIRECTORY). CLOSE This statement completes and closes any files previously opened by either DOPEN or OPEN statements. CLOSE is normally used only in programs and is applicable to files of all types, including those meant for a printer or modem. COLLECT This command is used to reclaim disk space that is currently allocated to improperly closed files. CONCAT The CONCAT command (derived from the word concatenate) is used to merge two data files together. COPY COPY is used to make copies of files. It can be used to copy from one disk to another (which requires a dual-disk drive) and it can be used to create a second copy of a file under a different name on the same disk. DCLEAR This statement clears the contents of all currently open channels to disk files. It is used by programmers to insure the removal of any old data that may have been left in a channel from some previous file operation (see DCLOSE). DCLOSE DCLOSE is used to close one or all currently opened channels to the disk drive. The term channel is used to indicate a specific communication path between the C128 and the disk drive's internal computer. Under normal operation there can be a number of channels open (each to different files), but there is a finite limit to just how many are open at any one time. The DCLOSE statement is issued by a program to close channels that are no longer needed (see DOPEN). DIRECTORY The DIRECTORY command displays a disk directory on the C128 screen (same as CATALOG). DOPEN This statement is used to open a communication channel to a disk drive. It is a disk-specific version of the OPEN statement. DSAVE The DSAVE command saves a program currently located in BASIC memory to a disk file. It is a disk-specific form of the SAVE command (see BSAVE). DVERIFY This command is used to compare a program in memory with one in a disk file. This is a disk-specific version of VERIFY. HEADER The HEADER command is used to prepare a new diskette for its first write and read operations. It formats a blank diskette into storage blocks and then establishes a fresh block allocation table and a blank disk directory. It also gives the disk a specific disk title and ID code. This is a destructive command as it totally erases any files already on a diskette. LOAD LOAD is used to load a file from either a Dataset or a disk drive. Variations of this command can be used for regular file types (BASIC programs) and binary file types (non-relocatable machine language programs of data) (see SAVE). RECORD This statement is used from within a program as a relative file pointer to select any byte of any record in a relative file. RENAME The RENAME command is used to change the name of a disk file. You should note that no two files on a single diskette can ever have the same name. SAVE This version of DSAVE can be used to save a file to any legal Commodore destination device such as a dataset, a screen, a modem, a printer, or a disk drive. It can only be used to save a program located in the standard BASIC memory area. Binary-type programs must be saved using the C128's built-in MONITOR utility (see LOAD). SCRATCH This command is used to erase or delete a file or group of files from a diskette. It is recommended that it be used to delete an existing file before attempting to save another file by that same name. Commodore DOS will not allow you to save a file if one by that name already exists. VERIFY This version of DVERIFY works for file