Table of Contents

Advertisement

O
O Commodore
O
System Guide
Ç= Commodore

Advertisement

Table of Contents
loading

Summary of Contents for Commodore 128

  • Page 1 O Commodore System Guide Ç= Commodore...
  • Page 3 System Guide Commodore Personal Computer © Commodore Electronics, Ltd. 1985. All rights reserved.
  • Page 4 Please note: All information about the C 128 in this manual is also valid for the C 128 D C o p y rig h t © 1985 by C o m m o d o re E le c tro n ics Lim ited All rights reserved This m a nual c o n ta in s c o p y rig h te d and pro p rie ta ry inform ation.
  • Page 5: Table Of Contents

    C128 SYSTEM GUIDE CHAPTER I — INTRODUCTION SECTION 1 - HOW TO USE THIS GUIDE SECTION 2 — OVERVIEW OF THE COMMODORE 128 PERSONAL COMPUTER CHAPTER II — USING C128 MODE SECTION 3 — GETTING STARTED IN BASIC SECTION 4 - ADVANCED BASIC PROGRAMMING...
  • Page 6: Section

    CHAPTER V — BASIC 7.0 ENCYCLOPAEDIA SECTION 16 - INTRODUCTION 16-3 SECTION 17 — BASIC COMMANDS AND STATEMENTS 17-3 SECTION 18 - BASIC FUNCTIONS 18-3 SECTION 19 - VARIABLES AND OPERATIONS 19-3 SECTION 20 — RESERVED WORDS AND SYMBOLS 20-3 APPENDICES APPENDIX A BASIC LANGUAGE ERROR MESSAGES...
  • Page 7: Chapter I - Introduction

    CHAPTER INTRODUCTION...
  • Page 9: How To Use This Guide

    SECTION 1 How to Use This Guide...
  • Page 11 If you want to use CP/M on the Commodore 128, read Chapter IV, USING CP/M MODE. This chapter tells you how to start up and use CP/M on the Commodore 128. ln CP/M you can choose from thousands of commercial software packages, including the PERFECT series (PERFECT WRITER, PERFECT CALC, PERFECT FILER).
  • Page 12 BASIC and DOS error messages and a summary of disk commands. A Glossary following the Appendices provides definitions of computing terms. For complete technical details about any feature of the Commodore 128, consult the Commodore 128 Programmer’s Reference Guide.
  • Page 13 SECTION 2 Overview of the Commodore C128 Personal Computer OVERVIEW OF THE COMMODORE C128 PERSONAL COMPUTER ...................2-3 C128 MODE ................2-3 C64 MODE ................. 2-3 CP/M MODE ................2-4 SWITCHING BETWEEN MODES ..........2-5...
  • Page 15 (the 1901). You can also use all standard Commodore serial peripherals. C64 Mode ln C64 Mode, the Commodore 128 operates exactly like a Commodore 64 computer, allowing you to take full advantage of the wide range of available C64 software. You also have full compatibility with all C64 peripherals.
  • Page 16 Chapters II, III and IV, which include Sections 3 through 15, tell you how to access and use the capabilities of the three powerful and versatile operating modes of the Commodore 128 Personal Computer. Switching Between Modes The following chart tells you how to switch to one mode from another.
  • Page 17 RETURN NOTE: If you are using a Commodore 1902 dual monitor, remember to move the video switch on the monitor from CO M PO SITE or SEPARATED to RGBI when switching from 40-column to 80-column display; reverse this step when switching from 80 to 40 columns.
  • Page 19: Chapter Ii - Using C128 Mode

    CHAPTER USING C128 MODE...
  • Page 21: Section 3 - Getting Started In Basic

    SECTION 3 Getting Started in Basic BASIC PROGRAMMING LANGUAGE ........3-3 Direct Mode ................3-3 Program Mode ................. 3-3 USING THE KEYBOARD............3-4 Keyboard Character Sets ............3-5 Using the Command Keys ............. Function Keys ................. 3-10 Displaying Graphic Characters ..........3-10 Rules for Typing BASIC Language Programs ....
  • Page 22 MATHEMATICAL OPERATIONS ..........3-20 Addition and S u btraction............3-20 Multiplication and Division ............ 3-20 Exponentiation ............... 3-21 Order of O p erations............... 3-21 Using Parentheses to Define the Order of Operations — 3-22 CONSTANTS, VARIABLES AND STRINGS ......3-22 Constants ................
  • Page 23: Basic Programming Language

    RETURN key. Most BASIC commands in your Commodore 128 can be used in direct mode as well as in a program. Program Mode ln program mode you enter a set of instructions that perform a specific task.
  • Page 24: Using The Keyboard

    USING THE KEYBOARD Shown below is the keyboard of the Commodore 128 Personal Computer. Using BASIC is essentially the same in both C64 and C128 modes.
  • Page 25: Keyboard Character Sets

    40 column format you can use only one character set at a time. When you turn on the Commodore 128 in 40-column format, the keyboard normally is using the upper-case/graphic character set. This means that everything you type is in capital letters. To...
  • Page 26 RETURN key, you probably will get a message like SYNTAX ERROR on the screen. This is called an “ Error Message.” Appendix A lists the error messages and tells how to correct the errors. NOTE: the examples given in this book, the following symbol indicates that you must press the RETURN key: Shift There are two SHIFT keys on the bottom row of the keyboard.
  • Page 27 Using the Four Arrow Cursor Keys ln C128 mode, the cursor can be moved in any direction simply by using the arrow key in the top row that points in the direction you want to move the cursor. (These keys cannot be used in C64 mode).
  • Page 28 Inserting Characters You must use the SHIFT key with the INST/DEL key when you want to insert characters in a line. Suppose you left some characters out of a line, like this: W HILE« WERE OUT To insert the missing characters, first use the cursor keys to move the cursor back to the error, like this: WHILEHWERE OUT Then, while you hold down the SHIFT key, press the INST/DEL...
  • Page 29 together to add any necessary space. Then type in the corrections. You can also type directly on top of undesired characters, then use INST to add any needed space. Control The Control key is used with other keys to do special tasks called control functions.
  • Page 30: Function Keys

    HOME position. Commodore Key The C* key (known as the COMMODORE key) has a number of functions, including the following ones: 1. When used with the SHIFT key, the O key lets you switch between upper-case/graphics mode and upper/lower-case text modes.
  • Page 31: Rules For Typing Basic Language Programs

    To display the graphic character on the left front face of a key, hold down the O key while you press the key that has the graphic character you want. You can display the left graphic character while the keyboard is in either character set. Rules for Typing BASIC Language Programs You can type and use BASIC language programs even without knowing BASIC.
  • Page 32: Getting Started - The Print Command

    Printing Numbers To print numbers, use the PRINT command followed by the number(s) you want to print. Try typing this on your Commodore 128: PRINTS Then press the RETURN key. Notice the number 5 is now displayed on the screen.
  • Page 33: Printing Text

    OVER HERE” fUTTUnN Printing in Different Colors The Commodore 128 is capable of displaying 16 different colors on the screen. You can change colors easily. All you do is hold down the CTRL key and press a numbered key between one and...
  • Page 34 All the succeeding characters are displayed in the color you selected. Hold down the Commodore key and press a numbered key between one and eight, and eight additional colors are displayed on the screen.
  • Page 35: Using The Cursor Keys Inside Quotes With The Print Command

    DOWN HERE” Now press RETURN. The Commodore 128 prints 10 blank lines, and on the eleventh line, it prints “ DOWN HERE” . As this example shows, you can tell the computer to print anywhere on your screen by using the cursor control keys inside quotation marks.
  • Page 36: Viewing Your Program-The List Command

    Now type RUN and press RETURN. The computer prints the words COMMODORE 128. This is not the same as using the PRINT command in DIRECT mode. What has happened here is that YOU HAVE JUST WRITTEN AND RUN YOUR FIRST BASIC PROGRAM as small as it may seem.
  • Page 37: A Simple Loop-The Goto Statement

    BASIC Encyclopedia.) Type RUN and press RETURN, and watch the words COMMODORE 128 move down your screen. To stop the message from printing on the screen, press the RUN/STOP key on the left side of your keyboard.
  • Page 38: Clearing The Computer's Memory-The New Command

    PRINTs the word RAINBOW in different colors. The color selection characters, known as control characters, in the PRINT statement in line 10 tell the Commodore 128 to change colors. The computer then prints the characters that follow in the new color until another color selection character is encountered.
  • Page 39: Editing Your Program

    Then hold down the SHIFT key and the INST/DEL key together until there is enough space to insert your new characters. Try this example. Clear the computer’s memory by typing NEW and pressing RETURN. Then type: 10 ? “ MY 128 IS GREAT” 3-19...
  • Page 40: Mathematical Operations

    Let's say that you want to add the word COMMODORE in front of the number 128. Just move the cursor so that it is blinking on the “ 1 ” in 128. Hold down the SHIFT and INST/DEL keys until you have enough room to type in COMMODORE (don’t forget to leave...
  • Page 41: Multiplication And Division

    Multiplication and Division Find the asterisk key (*) on the right side of your keyboard. This is the symbol that the Commodore 128 uses for multiplication. The slash ( /) key, located next to the right SHIFT key, is used for division.
  • Page 42: Using Parentheses To Define The Order Of Operations

    PRINT 16/4t2 III MllllI the Commodore 128 responds with a 1 because it squares the 4 before it divides 16. Using Parentheses to Define the Order of Operations You can tell the Commodore 128 which mathematical operation you want performed first by enclosing that operation in parentheses in the PRINT command.
  • Page 43: Variables

    10 PRINT 3 No matter how many times you execute this line, the answer will always be 3. Variables Variables are values that can change over the course of an equation or program statement. There is a part of the computer’s BASIC memory that is reserved for the characters (numbers, letters and symbols) you use in your program.
  • Page 44: Strings

    = sign to assign the result to a variable. You can mix text with constants in a PRINT statement to identify them. Type NEW and press RETURN to clear the Commodore 128’s memory; then try this program: 10 A = 3*100 20 B = 3*200 30 ?“A IS EQUAL TO ”A...
  • Page 45: Sample Program

    Type NEW and press RETURN to clear your computer’s memory, then type in the program below: 10 A$ = “ COMMODORE “ 20 X = 128 30 B$ = “ COMPUTER” 40 Y = 1 50 ? “THE ”A$;X;B$“...
  • Page 46: Storing And Reusing Your Programs

    Once you have created your program, you will probably want to store it permanently so you will be able to recall and use it at some later time. To do this, you’ll need either a Commodore disk drive or the Commodore 1530 Datassette.
  • Page 47: Formatting A Disk-The Header Command

    Each time you store a program on disk, the name you assign to that program will be added to the directory. The Commodore 128 has two kinds of formatting commands. One can be used only in C128 mode, and one can be used in both C64 and C128 mode.
  • Page 48: Saveing On Disk

    The device number parameter starts with the letter U so press the “ U” key followed by the preassigned device number for a Commodore disk drive which is 8. Here is an example of the long form of the HEADER command: HEADER“...
  • Page 49: Saveing On Cassette

    16 characters long. Be sure to enclose the program name ln quotes. You cannot put two programs with the same name on the same disk. If you do, the second program will not be accepted; the disk will retain the first one. ln the second example, the 8 indicates that you are saving your program on device number 8.
  • Page 50: Loading From Cassette

    FOUND PROGRAM NAME To actually load the program, you then press the Commodore key, or in 128 mode press the space bar to find the next program on the tape. You can use the counter on the Datassette to identify the starting position of the programs.
  • Page 51: Other Disk-Related Commands

    Other Disk-Related Commands Verifying a Program To verify that a program has been correctly saved, use the following command in C128 mode. DVERIFY“ PROGRAM NAME” RFTUHN If the program in the computer is identical to the one on the disk, the screen display will respond with the letters “...
  • Page 53: Section 4 - Advanced Basic Programming

    SECTION 4 Advanced Basic Programming COMPUTER DECISIONS— The IF-THEN Statem ent..... 4-3 Using the C o lon................4-4 LOOPS— The FOR-NEXT Com m and........4-5 Empty Loops- Inserting Delays in a Program ......4-6 The STEP Command ..............4-6 INPUTTING D A T A ................. 4-7 The INPUT C o m m and...............
  • Page 54 BASIC FU N C T IO N S ..............4-20 What is a Function?..............4-20 The INTEGER Function (IN T)..........4-20 Generating Random Numbers—The RND F u n ction..4-21 The ASC and CHR$ C om m ands.......... 4-22 Converting Strings and Num bers.......... 4-22 The VAL Function ...............
  • Page 55: Computer Decisionsthe If-Then Statement

    You no longer have to press the STOP key to break out of a looping program. The IF-THEN statement tells the computer to keep printing “ COMMODORE 128” and incrementing (increasing) J until J= 5 is true. When an IF condition is false, the computer jumps to the next line of the program, no matter what comes after the word THEN.
  • Page 56: Using The Colon

    Below is a list of comparison symbols that may be used in the IF statement and their meanings: SYMBOL MEANING EQUALS > GREATER THAN < LESS THAN < > NOT EQUAL TO > = GREATER THAN OR EQUAL TO < = LESS THAN OR EQUAL TO You should be aware that these comparisions work in expected mathematical ways with numbers.
  • Page 57: Loops-The For-Next Command

    LOOPS-THE FOR-NEXT COMMAND ln the program used for the IF-THEN example, we made the computer print Commodore five times by telling it to increase or “ increment” the variable J by units of one, until the value of J equalled five; then we ended the program. There is a simpler way to do this in BASIC.
  • Page 58: Empty Loops-Inserting Delays In A Program

    (by now you have witnessed the speed with which the computer executes commands). See if you can predict what this program will do before you run it. 10 A$=“ COMMODORE 128” 20 FOR J=1 TO 20 30 PRINT 40 FOR K=1 TO 1500...
  • Page 59: Inputting Data

    RETURN, and then type and RUN this program. 10 K=10 20 FOR 1=1 TO K 30 ? “ COMMODORE 128” 40 NEXT ln this program you can change the value of K in line 10 to make the computer execute the loop as many times as you want it to.
  • Page 60: Prompt Messages

    ln other words, you want to be able to change the value of the variable K each time you run the program, without having to change the program itself. We call this the ability to interact with the computer. You can have the computer ask you how many times you want it to execute the loop.
  • Page 61: The Get Command

    The GET command There are other BASIC commands you can use in your program to interact with the computer. One is the GET command and is similar to INPUT. To see how the GET command works, clear the computer's memory and type this program. 10 GET A$ 20 IF A$=“...
  • Page 62: Sample Program

    Section 5 describes how to use the GETKEY statement, which is a new and more powerful BASIC 7.0 command that can be used to perform a similar task. Sample program Now that you know how to use the FOR-NEXT loop and the INPUT command, clear the computer’s memory by typing NEW Tin mm , then type the following program: 10 T=0...
  • Page 63: The Read-Data Command

    The READ-DATA command There is another powerful way to tell the computer what numbers or characters to use in your program. You can use the READ statement in your program to tell the computer to get a number or character(s) from the DATA statement. For example, if you want the computer to find the average of five numbers, you can use the READ and DATA statements this way: 10 T=0...
  • Page 64: The Restore Command

    You can use DATA statements to assign values to string variables. The same rules apply as for numeric data. Clear the computer’s memory and type the following program: 10 FOR J=1 TO 3 20 READ A$ 30 ? AS 40 NEXT 50 END 60 DATA COMMODORE,128,COMPUTER 4-12...
  • Page 65: Using Arrays

    If the READ statement calls for a string variable, you can place letters or numbers in the DATA statement. Notice however, that since the computer is READing a string, numbers will be stored as a string of characters, not as a value which can be manipulated.
  • Page 66: Dimensioning Arrays

    X. You can create string arrays to store the characters in string variables the same way. Try updating the COMMODORE 128 COMPUTER READ-DATA program so the computer will remember the elements in the A$ array. 5 DIM A $(3)
  • Page 67: Sample Program

    This tells the computer to reserve space in its memory for a two- dimensional array named X. The computer reserves enough space for 50 numbers. You do not have to fill an array with as many numbers as you DIMensioned it for, but the computer will still reserve enough space for all of the positions in the array.
  • Page 68 10 DIM X (10,5) , A (10) 20 FOR R=1 TO 10 30 T = 0 40 FOR C=1 TO 5 50 READ X(R,C) 70 NEXT C 80 A(R)=T/5 90 NEXT R 100 FOR R=1 TO 10 110 PRINT "ROW #";R 120 FOR C=1 TO 5 130 PRINT X ( R , C ) 140 NEXT C...
  • Page 69: Programming Subroutines

    PROGRAMMING SUBROUTINES The GOSUB-RETURN command Until now, the only method ou have had to tell the computer to jump to another part of your program is to use the GOTO command. What if you want the computer to jump to another part of the program, execute the statements in that section, then return to the point it left off and continue executing the program? The part of program that the computer jumps to and executes is...
  • Page 70: Using Memory Lo Catio N

    The ON statement is used with either the GOTO or GOSUB- RETURN commands, depending on what you need the program to do. A variable or calculation should be after the ON command. After the GOTO or GOSUB command, there should be a list of line numbers.
  • Page 71: Using Peek

    Memory location 2594 determines whether or not keys like the spacebar and CRSR repeat when you hold them down. A 128 in location 2594 tells the computer to repeat these keys when you hold them down. Hold down the spacebar and watch the cursor move across the screen.
  • Page 72: Basic Functions

    BASIC FUNCTIONS What is a Function A function is a predefined operation of the BASIC language that generally provides you with a single value. When the function provides the value, it is said to "return” the value. For instance, the SQR (square) function is a mathematical function that returns the value of a specific number when it is raised to the second power—...
  • Page 73: Generating Random Numbers-The Rnd Function

    ? INT((100/6)+0.5) n m iw i You can substitute any calculation for the division shown in the inner parentheses. What if you want to round off numbers to the nearest 0.01 ? Instead of adding 0.5 to your number, add 0.005, then multiply by 100.
  • Page 74: Converting Strings And Numbers

    This number is called a character string code (CHR$) and there are 255 of them in the Commodore 128. There are two functions associated with this concept that are very useful. The first is the ASC function.
  • Page 75: The Val Function

    The VAL Function The VAL function returns a numeric value for a string argument. Clear the computer’s memory and type in this program: 10 A $=“ 64” 20 A=VAL(A$) 30 ? “THE VALUE OF ” ;A$;“ IS”;A 40 END The STR$ Function The STR$ function returns the string representation of a numeric value.
  • Page 76 BASIC program m ing language and its capabilities. The rem aining four sections of this chapter describe com m ands that are unique to Com m odore 128 mode. Some Com m odore 128 mode com m ands provide capabilities that are not available in C64 mode.
  • Page 77 4-25...
  • Page 79: Section 5 - Some Basic Commands And Keyboard Operations Unique To C128

    SECTION 5 Some Basic Commands and Keyboard Operations Unique to C128 Mode INTRODUCTION ..............5-3 ADVANCED LOOPING ............5-3 The DO/LOOP Statement ............5-3 Until ..................5-3 While ..................5-4 Exit ...................5-5 The ELSE Clause with IF-THEN ..........5-5 The BEGIN/BEND Sequence with IF-THEN ......5-5 The SLEEP Command .............
  • Page 80 2 MHZ OPERATION ..............5-16 The FAST and SLOW Commands ........5-16 KEYS UNIQUE TO C128 MODE ..........5-17 Function Keys ................. 5-17 Redefining Function Keys ............. 5-17 Other Keys Used in C128 Mode Only ........ 5-18 HELP ..................5-18 NO SCROLL ...............
  • Page 81: Introduction

    INTRODUCTION This section introduces you to some powerful BASIC commands and statements that you probably have not seen before, even if you are an experienced BASIC programmer. If you are familiar with programming in BASIC, you have probably encountered many situations in which you could have used these commands and statements.
  • Page 82: While

    directs the loop. The loop will run continually unless the condition for UNTIL happens. 100 DO: INPUT “ DO YOU LIKE YOUR COMPUTER”;A$ 110 LOOP UNTIL A$=“YES” 120 PRINT “THANK YOU” The DO/LOOP statement is often used to repeat an entire routine indefinitely in the body of a program, as in the following: 10 PRINT “...
  • Page 83: Exit

    EXIT An EXIT statement can be placed within the body of a DO/LOOP. When the EXIT statement Is encountered, the program jumps to the next statement following the LOOP statement. The ELSE clause with IF-THEN The ELSE clause provides a way to tell the computer how to respond if the condition of the IF-THEN statement is false.
  • Page 84: The Sleep Command

    10 INPUT A 20 IF A < 100 THEN BEGIN: ? “YOUR NUMBER WAS ”;A 30 SLEEP 2:REM DELAY 40 FOR X=1 TO A 50 ?“THIS IS AN EXAMPLE OF BEGIN/BEND” 60 NEXT X 70 ?“THAT’S ENOUGH” :BEND:ELSE ?“TOO MANY” 80 END This program asks for a number from the user.
  • Page 85: The Pudef Command

    PRINT USING lets you create a format for your output, using spaces, commas, decimal points and dollar signs. Hash marks (the # sign) are used to represent spaces or characters in the displayed result. For example: PRINT USING “# $ # # # # # # . # # ”;A tells the computer that when A is printed, it should be in the form given, with up to six places to the left of the decimal point, and two places to the right.
  • Page 86: Sample Program

    SAMPLE PROGRAM This program calculates interest and loan payments, using some of the commands and statements you just learned. It sets a minimum value for the loan using the ELSE clause with an IF- THEN statement, and sets up a dollar and cents format with PRINT USING.
  • Page 87: Programming Aids

    answer is assigned to B$, through the GETKEY statements in lines 60 and 90. IF/THEN statements are used for loops in the program to get the proper computer reaction to the different keyboard inputs. 10 PRINT “WHO WROTE T H E RAVEN’?” 20 PRINT “A.
  • Page 88: Renumber

    The computer automatically numbers your program by tens. After you enter a line and press the RETURN key, the next line number appears, and the cursor is in the correct place for you to type the next statement. You can choose to have the computer number the commands with any increment;...
  • Page 89: Identifying Problems In Your Programs

    When a program does not work the way you expected, an error message usually occurs. Sometimes the messages are vague, however, and you still do not understand the problem. The Commodore 128 computer has several ways of helping you locate the problem. Help The Commodore 128 provides a HELP command that specifies the line in which a problem has occurred.
  • Page 90 program. The TRAP command advises you to locate and correct an error, then resume program operation. Usually, the error- trapping function is set in the first line of a program: 5 TRAP 100 tells the computer that if an error occurs to go to a certain line (in this case, line 100).
  • Page 91: Program Tracing - The Tron And Troff Commands

    on the error that was trapped, resuming execution may or may not be possible. For additional information on error trapping, see the error functions ERFt$, EL and ER, described in Chapter V, BASIC 7.0 Encyclopaedia. Program Tracing—TRON and TROFF Commands When a problem in a program occurs, or you do not get the results you expect, it can be useful to methodically work through the program and do exactly what the computer would do.
  • Page 92: Windowing

    The Commodore 128 provides two methods of creating windows: the WINDOW command and ESCAPE key functions. Using the WINDOW Command to Create a Window The Commodore 128 BASIC 7.0 language features a command...
  • Page 93: Using The Esc Key To Create A Window

    Here is a sample program that creates four windows on the screen, in either 40- or 80-column format. Using the ESC Key to Create a Window To set a window with the ESC (Escape) Key, follow these steps: 1. Move the cursor to the screen position you want as the top left corner of the window.
  • Page 94: Mhz Operation

    80-column format at twice the normal speed. You can switch normal and fast operation by using the FAST and SLOW commands. The FAST command places the Commodore in 2 MHz mode. The format of this command is: FAST The SLOW command returns the Commodore 128 to 1 MHz mode.
  • Page 95: Keys Unique To C128 Mode

    KEYS UNIQUE TO C l 28 MODE Function Keys The four keys on the Commodore 128 keyboard on the right side above the numeric keypad are special function keys that let you save time by performing repetitive tasks with the stroke of just one key.
  • Page 96: Other Keys Used In C128 Mode Only

    7SYNTAX ERROR IN LINE 10 Your computer displays this. HELP You press HELP. 10 PRONT “ COMMODORE COMPUTERS” The line with the mistake is high lighted in reverse if in 40 column output or under lined in 80 column output.
  • Page 97: No Scroll

    No Scroll Press this key down to stop the text from scrolling when the cursor reaches the bottom of the screen. This turns off scrolling until you press the NO SCROLL key again. Caps Lock This key lets you type in all capital letters without using the SHIFT key.
  • Page 98 FOR MORE INFORMATION This section covers only some of the concepts, keys and com m ands that make the Commodore 128 a special machine. You can find further explanations of the BASIC language in the BASIC 7.0 Encyclopaedia in Chapter V.
  • Page 99: Section 6 - Color, Animation And Sprite Graphics

    GRAPHICS OVERVIEW ............... 6-3 Graphics Features..............6-3 Command Sum m ary..............6-3 GRAPHICS PROGRAMMING ON THE COMMODORE 128............... 6-4 Choosing C o lo rs................. 6-4 Types of Screen Display............6-5 Selecting the Graphic M ode............. 6-6 Displaying Graphics on the Screen ........6-8 Drawing a Circle - The CIRCLE Com m and......
  • Page 100 Adjoining S prites..............6-28 Storing Sprite Data in Binary Files........6-33 BSAVE................... 6-35 BLOAD ................. 6-36...
  • Page 101: Graphics Overview

    GRAPHICS OVERVIEW ln C128 mode, the Commodore 128 BASIC 7.0 language provides many new and powerful commands and statements that make graphics programming much easier. Each of the two screen formats available in C128 mode (40 columns and 80 columns) is controlled by a separate microprocessor chip. The 40-column chip is called the Video Interface Controller, or VIC for short.
  • Page 102: Graphics Programming On

    See Chapter V, BASIC 7.0 Encyclopaedia, for detailed format and information on all graphic commands and functions, including those not discussed in this section. GRAPHICS PROGRAMMING ON THE C 128 This following section describes a step-by-step graphics programming example. As you learn each graphics command, add it to a program you will build as you read this section.
  • Page 103: Types Of Screen Display

    Number Source 40-column background color (VIC) Foreground for the graphics screen (VIC) Foreground color 1 for the multicolor screen (VIC) Foreground color 2 for the multicolor screen (VIC) 40-column (VIC) border (whether in text or graphics mode) Character color for 40- or 80-column text screen 80-column background color (8563) Figure 6-1.
  • Page 104: Selecting The Graphic Mode

    The first one is text display, which displays only characters, such as letters, numbers, special symbols and the graphics characters on the front faces of most C128 keys. The C128 can display text in both 40-column and 80-column screen formats. The second category of display mode is used for highly detailed graphics, such as pictures and intricate drawings.
  • Page 105 1 through 25. A zero as the s parameter indicates the screen is not split, and is all text. The final GRAPHIC command parameter is CLR. When you first issue a bit map graphic command, the Commodore 128 allocates...
  • Page 106: Displaying Graphics On The Screen

    This is the purpose of CLR. It reorganizes the Commodore 128 memory and gives you back the 9K of memory that was dedicated to the bit map-screen, so you can use it for other purposes.
  • Page 107: Drawing A Circle - The Circle Command

    CIRCLE statement is explained under the CIRCLE listing in Chapter V, BASIC 7.0 Encyclopaedia. On your Commodore 128 screen, the point where X = 0 and Y = 0 is at the top left corner of the screen and is referred to as the HOME position, ln standard geometry however, the point where X and Y equal 0 is the bottom left corner of a graph.
  • Page 108: Drawing A Box - The Box Command

    Drawing a Box — The BOX Command Now try a box. To draw a box, type: 80 BOX1,20,60,100,140,0,1 This draws a solid box to the left of the circle. To find out what the numbers in the box statement mean, consult Chapter V, BASIC 7.0 Encyclopaedia.
  • Page 109: Painting Outlined Areas-The Paint Command

    When the Commodore 128 finishes PAINTing, it leaves the pixel cursor at the point where PAINTing began (in this case, at point 150,97).
  • Page 110: Displaying Characters On A Bit Mapped Screen-The Char Command

    Displaying Characters on a Bit Mapped Screen—The CHAR Command So far, the example program has operated in standard bit map mode. Bit map mode uses a completely different area of memory to store the screen data than text mode (the mode in which you enter programs and text).
  • Page 111 : REM S ELEC T B A C K G R O U N D C O L O R 10 C O L O R 0,1 20 C O L O R 1,3 : REM S E LE C T F O R E G R O U N D C O L O R 30 C O L O R 4,1 : REM S EL E CT B O R D E R C O L O R 40 G R A P H I C...
  • Page 112: Changing The Size Of Graphic Images-The Scale Command

    GRAPHIC statement in line 230. Changing the size of Graphic Images—The SCALE Command The Commodore 128 has another graphics statement which offers additional power to your graphics system. The SCALE statement offers the ability to scale down (reduce) the size of graphic images on your screen.
  • Page 113 Note: SCALE comes after GRAPHIC and does not affect CHAR. Here are some additional example programs using the graphics statements you just learned. 10 C O L O R 20 C O L O R 30 C O L O R 40 G R A P H I C 50 F O R 1=80 TO...
  • Page 114: Sprites: Programmable Movable Object Blocks

    Read the next section and take your first step in learning computer animation. SPRITES: PROGRAMMABLE MOVABLE OBJECT BLOCKS You already have learned about some of the Commodore 128's exceptional graphics capabilities. You’ve learned how to use the first set of high-level graphics statements to draw circles, boxes, 6-16...
  • Page 115: Sprite Creation

    Now it’s time to take the next step in graphics programming — sprite animation. If you have worked with the Commodore 64, you already know something about sprites. For those of you who are not familiar with the subject, a sprite is a moveable object that you can form into any shape or image.
  • Page 116: Drawing The Sprite Image

    by 21 pixels tall in standard bit map mode or 12 pixels wide by 21 tall in multicolor bit map mode. 2. Use the SSHAPE statement to store the picture data into a string variable. 3. Transfer the picture data from the string variable into a sprite with the SPRSAV statement.
  • Page 117: Storing The Sprite Data With Sshape

    : RE M SET C O L O R S 5 C O L O R 0 , 1 : C O L O R 4 , l : C O L O R 1, 2 : RE M SET H I - R E S G R A P H I C MO D E 10 G R A P H I C : RE M P I C T U R E FR A M E...
  • Page 118: Saving The Picture Data In A Sprite

    Make sure you position the SSHAPE statement directly on the correct coordinate. Also, be sure to create the picture with the dimensions 24 pixels wide by 21 pixels tall, the size of a single sprite. The SSHAPE statement transforms the picture of the racing car into a data string that the computer interprets as picture data.
  • Page 119: Moving Sprites With Movspr

    Here’s what each of the numbers in the SPRITE statements mean: SPRITE #,0,C ,P ,X ,Y ,M # — Sprite number (1 to 8) 0 — Turn On (0 = 1 ) or Off (0 = 0 ) C - Color (1 to 16) P—...
  • Page 120 The first number in this statement is the sprite number. The second number is the direction expressed as the number of degrees to move in the clockwise direction, relative to the original position of the sprite. The hash sign (#) signifies that the sprite is moved at the specified angle and speed relative to a starting position, instead of an absolute location, as in lines 70 and 80.
  • Page 121: Creating A Sprite Program

    Now RUN the entire program with all the steps included. You have just written your first sprite program. You have created a raceway with two racing cars. Try adding more cars and more objects on the screen. Experiment by drawing other sprites and include them in the raceway.
  • Page 122: Sprite Definition Mode-The Sprdef Command

    C128 graphics statements such as DRAW and BOX. You learned how to control the sprites, using the Commodore 128 sprite statements. The Commodore 128 has two other ways of creating sprites.
  • Page 123 RETURN. The Commodore 128 displays a sprite grid on the 40 column screen, ln addition, the computer displays the prompt: SPRITE NUMBER ? Enter a number between 1 and 8. The computer displays the corresponding sprite in the upper right corner of the screen. From now on, we will refer to the sprite grid as the work area.
  • Page 124: Sprite Creation Procedure In Sprite Definition Mode

    CONTROL key and press a key between 1 and 8. To select color codes between 9 and 16, hold down the Commodore (C1) key and press a key between 1 and 8. Now you are ready to start creating the shape of your sprite.
  • Page 125 Once you have created a sprite and have exited SPRite DEFinition mode, your sprite data is stored in the appropriate sprite storage area in the Commodore 128’s memory. Since you are now back in the control of the BASIC language, you have to turn on your sprite in order to see it on the screen.
  • Page 126: Adjoining Sprites

    Now use the MOVSPR command to move it as follows: MOVSPR 1, 45 # 5 Now you know all about SPRDEF mode. First, create the sprite, save the sprite data and exit from SPRDEF mode to BASIC. Next turn on your sprite with the SPRITE command. Move it with the MOVSPR command.
  • Page 127 1. Draw a picture on the screen with Commodore 128 graphics statements, such as DRAW, BOX and PAINT, just as you did in the raceway program in the last section. This time, make the picture twice as large as a single sprite with the dimensions 48 pixels wide by 21 pixels tall.
  • Page 128 The following program is an example of adjoining sprites. The program creates an outer space environment. It draws stars, a planet and a spacecraft similiar to Apollo. The spacecraft is drawn, then stored into two data strings, A$ and B$. The front of the spaceship, the capsule, is stored in sprite 1.
  • Page 129 Here’s an explanation of the program: • Line 5 COLORs the background black and the foreground white. • Line 10 selects standard high-resolution mode and clears the high-res screen. • Line 23 BOXes in a display area for the picture of the spacecraft in the top-left corner of the screen.
  • Page 130 • Lines 85 and 87 move the joined sprites across the screen. • Line 90 delays the program. This time delay is necessary for the sprites to complete the two trips across the screen. If you leave out the delay, the sprites do not have enough time to move across the screen.
  • Page 131: Storing Sprite Data In Binary Files

    An object code file must be loaded with a loader, as in the Commodore 64 Assembler Development System; then the SYSTEM command (SYS) must be used to execute it.
  • Page 132 A sprite requires 63 bytes of data. Each sprite block is actually made up of 64 bytes; the extra byte is not used. Since the Commodore 128 has eight sprites and each one consists of a 64- byte sprite block, the computer needs 512 (8 x 64) bytes to represent the data of all eight sprite images.
  • Page 133: Bsave

    Once you exit from the SPRDEF mode, you can save your sprite data in binary sprite files. This way, you can load any collection of sprites back into the Commodore 128 neatly and easily. Use this command to save your sprite data into a binary file: BSAVE “...
  • Page 134: Bload

    computer. It is easier to BSAVE the entire 512 bytes of all eight sprites, regardless if all the sprites are used, rather than BSAVE each sprite block individually. BLOAD Later on, when you want to use the sprites again, just BLOAD the entire 512 bytes for all of the sprites into the range starting at 3584 ($0E00) and ending at 4095 ($0FFF).
  • Page 135: Section 7 - Sound And Music In C128 Mode

    Random S o u n d s ................. 7-9 ADVANCED SOUND AND MUSIC IN C128 M O DE.... 7-11 A brief background: The Characteristics of Sound ... 7-11 Making Music on the Commodore 128 ....... 7-13 The ENVELOPE Statement ..........7-13 The TEMPO Statement ............. 7-15 The PLAY Statement ............
  • Page 137: Introduction

    INTRODUCTION The Commodore 128 has one of the most sophisticated built-in sound synthesizers available in a microcomputer. The synthesizer, called the Sound Interface Device (SID), is a chip dedicated solely to generating sound and music. The SID chip is capable of producing three independent voices (sounds) simultaneously.
  • Page 138: The Sound Statement

    THE SOUND STATEMENT The SOUND statement is designed primarily for quick and easy sound effects in your programs. You will learn a more intricate way of playing complete musical arrangements with the other sound statements later in this section. The format for the SOUND statement is as follows: SOUND VC, FREQ, DUR[, DIR[, MIN[, SV[, WF[, PW]]]]] Here’s what the parameters mean: —...
  • Page 139: Writing A Sound Program

    The first parameter (VC) in the SOUND statement selects which voice will be played. The second parameter (FREQ) determines the frequency of the sound, which ranges from 0 through 65535. The third setting (DUR) specifies the amount of time the sound is played.
  • Page 140 Notice line 30 plays a higher tone than line 20. This shows the direct relationship between the frequency setting and the actual frequency of the sound. As you increase the frequency setting, the Commodore 128 increases the pitch of the tone. Now try this statement: 40 SOUND 1, 0, 60 This shows that a FREQ value of 0 plays the lowest frequency (which is so low it is inaudible).
  • Page 141 The sawtooth waveform sounds similar to the triangle waveform though it has less buzz. Finally, try the white noise waveform (3). Substitute line 60 for this line: 60 SOUND 1 ,1 ,1 ,0 ,0 , 0 ,3 ,0 Now the program loop plays the white noise generator for the entire range of frequencies.
  • Page 142 Here’s a sample program that will help you understand how to program the Commodore 128 synthesizer chip. The program, when run, asks for each parameter, and then plays the sound. Here’s the program listing. Type it into your computer and RUN it.
  • Page 143: Random Sounds

    Here's a quick explanation of the program. Lines 10 and 20 PRINT the introductory messages on the screen. Lines 30 through 50 INPUT the voice, frequency and duration parameters. Line 60 asks if you want to enter the optional SOUND parameters, such as the sweep settings and waveform.
  • Page 144 The seed is the base number generated by the computer. The 1 tells the computer to generate a new seed each time the command is encountered. Since the Commodore 128 has 3 voices, the notation * 3 tells the computer to generate a random number within the range 0 through 3.
  • Page 145: Advanced Sound And Music In C128 M O De

    The timbre of a musical tone, (i.e., the way a tone sounds,) is determined by the tone’s waveform. The Commodore 128 can generate four types of waveforms: triangle, sawtooth, variable pulse and noise. See Figure 7-3 for a graphic representation of these four waveforms.
  • Page 146 TRIANGLE SAWTOOTH VARIABLE PULSE NOISE Figure 7-3. Sound Waveforms Types...
  • Page 147: Making Music On The Commodore 128

    The ENVELOPE generator controls the ADSR parameters of sound. See Figure 7- 4 for a graphical representation of ADSR. The Commodore 128 can change each ADSR parameter to 16 different rates. This gives you absolute flexibility over the envelope generator and the resulting properties of the volume when the sound is originated.
  • Page 148 Now you can realize the power of the ENVELOPE statement. It controls most of the musical qualities of the notes being played by the sound synthesizer. The Commodore 128 has 10 predefined envelopes for 10 different musical instruments, ln using the predefined envelopes you do not have to specify the ADSR parameters, waveform and pulse width settings—this is...
  • Page 149: The Tempo Statement

    15, where 15 is the maximum and 0 is off (no volume). The TEMPO Statement The next step in Commodore 128 music programming is controlling the tempo, or speed of your tune. The TEMPO statement does this for you. Here’s the format:...
  • Page 150: The Play Statement

    0 and 255 (and 255 is the fastest tempo). If you do not specify the TEMPO statement in your program, the Commodore 128 automatically sets the tempo to 8. Add this statement to your musical example program:...
  • Page 151 M — Wait for end of measure The Commodore 128 also has synthesizer control characters you can include in a PLAY string. This gives you absolute control over each note and allows you to change synthesizer controls within a string of notes.
  • Page 152 You don’t absolutely have to specify any of the control characters, but you should to maximize the power from your synthesizer. The Commodore 128 automatically sets the synthesizer controls to the default settings in Figure 7-6. If you don’t assign special control characters, the SID chip can PLAY only one envelope, one voice and one octave without any FILTERing.
  • Page 153 So far, your PLAY statements only played whole notes. Add notes of different duration by placing duration control characters in your PLAY string as follows: 70 PLAY “ MV2O6T0U7X0HCDQEFIGASB” Line 70 PLAYs voice 2 in octave 6 at volume level 7 with the redefined piano envelope (0) on and filter turned off.
  • Page 154: The Sid Filter

    The SID Filter Once you have selected the ENVELOPE, ADSR, VOLume and TEMPO, use the FILTER to perfect your synthesized sounds, ln your program, the FILTER statement will precede the PLAY statement. First you should become comfortable with generating the sound and worry about FILTERing last. Since the SID chip has only one filter, it applies to all three voices.
  • Page 155 Figure 7-7. Low-pass Filter Conversely, the high-pass filter allows all the frequencies above the cutoff frequency to pass through the chip. All the ones below it are filtered out. See Figure 7-8. The high-pass filter produces tinny, hollow sounds. Figure 7-8. High-pass Filter The band-pass filter allows a range of frequencies partially above and below the cutoff frequency to pass through the SID chip.
  • Page 156: The Filter Statement

    The FILTER Statement The FILTER statement specifies the cutoff frequency, the type of filter being used and the resonance. The resonance is the peaking effect of the sound wave frequency as it approaches the cutoff frequency. The resonance determines the sharpness and clearness of a sound: the higher the resonance, the sharper the sound.
  • Page 157: Tying Your Music Program Together

    The new line 45 turns off the low-pass filter and enables the band-pass filter. Press RUN/STOP and RESTORE and RUN your sound program again. Notice the difference between the low- pass and band-pass filters. Change line 45 again to: 45 FILTER 1200, 0,0,1,10 Reset the sound chip and RUN your example program again.
  • Page 158: Advanced Filtering

    Line 10, the ENVELOPE statement, specifies the envelope for piano (0), which sets the attack to 0, decay to 9, sustain to 0 and release to 0. It also selects the variable pulse waveform with a pulse width of 1700. Line 15 sets the VOLume to 8. Line 20 chooses the TEMPO to be 10.
  • Page 159 Accent the notes in the string with the SID control characters. You can combine your Commodore 128 Music synthesizer with C128 mode graphics to make your own videos or “ movies” , complete with sound tracks.
  • Page 160: Coding A Song From Sheet Music

    However, you don’t have to be a musician to be able to play the tune on your Commodore 128. For those of you who cannot read music, Figure 7-11 shows how a typical musical staff is arranged and how the notes on the staff are related to the keys on a piano.
  • Page 161 OF C. F. PETERS, CORP. NEW YORK. The best way to start coding a song into your Commodore 128 is by breaking the notes down into an intermediate code. Write down the upper staff notes on a piece of paper. Now write down the notes for the lower staff.
  • Page 162 1, enter the eighth note in the string first since it must play for the duration while the two sixteenth notes are being fetched by the Commodore 128. You must give the computer time to play the longer note first, then PLAY the notes of shorter duration, or else the composition will not be synchronized.
  • Page 163 You can use the techniques described in this section to code your favorite sheet music and play it on your Commodore 128. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * You now have been introduced to m ost of the pow erful new com m ands of the BASIC 7.0 language that you can use in C128...
  • Page 165: Using 80 Columns

    SECTION 8 Using 80 Columns INTRODUCTION ................8-3 THE 40 /8 0 KEY ................8-3 USING PREPACKAGED 80 COLUMN SOFTWARE ....8-4 CREATING 80 COLUMN PR O G R A M S........8-5 USING 40 AND 80 COLUMNS TOGETHER ......8-4...
  • Page 167: Introduction

    80-column screen display. You could even use both in a single program. Each screen size has special uses. The 40-column screen is the same size screen the Commodore 64 uses. With the 40-column screen you can use the Commodore 128’s full graphics capabilities. You can draw circles, graphs, sprite characters, boxes and other shapes in high-resolution or multicolor graphic modes.
  • Page 168: Using Prepackaged 80 Column Software

    USING PREPACKAGED 80-C0LUMN SOFTWARE Most CP/M programs utilize an 80-column screen, as do many of the other business application packages you can use in C128 mode. Since the width of a normal printed page is 80 columns, an 80-column wordprocessor can display information on the screen exactly as that information will appear on paper.
  • Page 169 For example, you might write a program which asked the user to input data, then create a bar graph based on the user’s input. The message “ CHANGE TO 40 COLUMN TO VIEW GRAPH” would tell the user to switch modes and see the results. As noted previously, you can switch between the 80- and 40- column formats after power-up, with the ESCape/X sequence.
  • Page 170 ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ■ A - * * * * * * The sections of this chapter have introduced you to the m any features and capabilities provided by the Commodore 128 in C l 28 mode. The following chapter tells you how to use the Com m odore 128 in C64 mode.
  • Page 171: Chapter Iii - Using C64 Mode

    CHAPTER USING C64 MODE...
  • Page 173 SECTION 9 Using the Keyboard in C64 Mode USING BASIC 2.0 ..............9-3 KEYBOARD CHARACTER SETS .......... 9-3 USING THE TYPEWRITER-STYLE KEYS ......9-3 USING THE COMMAND KEYS ..........9-3 MOVING THE CURSOR IN C64 MODE ........ 9-4 PROGRAMMING FUNCTION KEYS IN C64 MODE .... 9-4...
  • Page 175: Using Basic

    The entire BASIC 2.0 language built into the Commodore 64 computer has been incorporated into the BASIC 7.0 language of the Commodore 128. You can use the BASIC 2.0 commands in both C128 and C64 modes. Refer to Sections 3 and 4 in Chapter 2 for a description of these commands.
  • Page 176: Moving The Cursor In C64 Mode

    MOVING THE CURSOR IN C64 MODE ln C64 Mode, you use two CRSR keys on the main keyboard and the SHIFT key to move the cursor, as described in Section 3. PROGRAMMING FUNCTION KEYS IN C64 MODE The four keys to the right side of the keyboard, just above the numeric keypad, are called function keys.
  • Page 177 You can use the function keys in your program in several ways. To do this, you need to use the GET statement. (See Section 4 for a description of the GET statement.) As an example, the program below prepares the F1 key to print a message on the screen. 10 ? “...
  • Page 179: Section 10 - Storing And Reusing Your Programs In C64 Mode

    SECTION 10 Storing and Reusing Your Programs in C64 Mode FORMATTING A DISK IN C64 MODE ....... 10-3 THE SAVE COMMAND ............10-3 SAVEing on Disk ..............10-3 SAVEing on Cassette ............10-4 THE LOAD AND RUN COMMANDS ......... 10-4 LOADing and RUNning from Disk ........
  • Page 181: Formatting A Disk In C64 Mode

    Once you have edited a program, you will probably want to store it permanently so that you will be able to recall and use it at some later time. To do this you need either a Commodore disk drive or the Commodore Datassette.
  • Page 182: The Load And Run Commands

    The same rules apply for the PROGRAM NAME whether you are using disk or tape. The PROGRAM NAME can be anything you want it to be. You can use letters, numbers and/or symbols - up to 16 characters in all. Note that you must enclose the PROGRAM NAME in quotation marks.
  • Page 183: Other Disk-Related Commands

    You can use the counter on the Datassette to identify the starting position of the programs. Then, when you want to retrieve a program, simply wind the tape forward from 000 to the program’s start location, and type: nn iiiiii l o a d ln this case, you do not have to specify the PROGRAM NAME;...
  • Page 184: Initializing A Disk Drive

    A list of the programs on your disk will then be displayed. Note that when you load the directory, any program that was in memory is erased. INITIALIZING A DISK DRIVE If the disk drive’s ready light is blinking, it indicates a disk error. You can restore the disk drive to the condition it was in before the error occurred by using a procedure called INITIALIZING.
  • Page 185 CHAPTER USING CP/M MODE...
  • Page 187: Introduction To Cp/M 3.0

    SECTION 11 Introduction to CP/M 3.0 WHATCP/M 3.0 IS ............11-3 WHAT YOU NEED TO RUN CP/M 3.0 ....... 11-3 WHAT IS ON YOUR DISK ..........11-4 CP/M +.SYS ............... 11-4 CCP.COM ................11-4 .COM files ................11-6 Other files ................11-6 GETTING STARTED WITH CP/M 3.0 ......
  • Page 189: Whatcp/M 3.0 Is

    WHAT C P /M 3.0 IS CP/M is a product of Digital Research, Inc. The version of CP/M used on the Commodore 128 is CP/M Plus Version 3.0. ln this chapter, CP/M is generally referred to as CP/M 3.0, or simply CP/M.
  • Page 190: Cp/M+.Sys

    NOTE: Although CP/M can be used with a 40-column monitor, the display is 80 column but with only 40 columns displayed at one time. To view all 80 columns of the display, you must scroll the screen horizontally by pressing the CONTROL key and the appropriate cursor key (left or right).
  • Page 191 WHAT IS ON YOUR C P /M 3.0 DISK show b : B: RW, Space 336k A>d i r [full S c a n n i ng Directory... S o r t i n g Directory... D i r e c t o r y for Drive A: User Name Bytes...
  • Page 192: Com Files

    .COM files The other .COM files all contain transient commands (listed in Table 14.2.). HELP.COM displays messages, held in HELP.HLP (whose extension indicates it is a data file not a program file), about the C128 CP/M system and its commands. If you are not familiar with CP/M and have no other manuals or books about it, you may find it useful to print out any HELP you look at.
  • Page 193: The Opening C P /M Screen Display

    Caution: Always make sure that the disk is fully inserted in the drive before you close the drive door. ln CP/M 3.0 on the Commodore 128, the user has a 59K TPA (Transient Program Area), which is, in effect, user RAM.
  • Page 194: The Command Line

    An important part of the opening display is the following two- character message: A > This is the CP/M 3.0 system prompt. The system prompt tells you that CP/M is ready to read a command entered by you from your keyboard. The prompt also tells you that drive A is your default drive.
  • Page 195: Types Of Commands

    For transient utilities, CP/M 3.0 checks only the command keyword. Many utilities require unique command tails. If you include a command tail, CP/M 3.0 passes it to the utility without checking it. A command tail cannot contain more than 128 characters. How C P /M Reads Command Lines Use the DIR command to demonstrate how CP/M reads command lines.
  • Page 196 CP/M 3.0 recognizes only correctly spelled command keywords. If you make a typing error and press RETURN before correcting your mistake, CP/M 3.0 repeats or “ echoes” the command line, followed by a question mark. For example, suppose you mistype the DIR command, as in the following example: CP/M replies with: DJR?
  • Page 197: Howto Copy Your Cp/M 3.0 Disk

    1571). (The C64 single sided option is for formatting disks compatible with the CP/M 2.2 package once sold for the Commodore 64.) Enter the command FORMAT, select the required disk type with the Cursor Down key, press RETURN, and follow the onscreen instructions.
  • Page 198: What To Buy

    ‘CP/M Software Finder’ published for Digital Research by Que Corporation and available through good software retailers (ISBN 0-88-022-021-X). Since it is not convenient for the CP/M Users Group to supply its library on Commodore format disks, a selection of public domain CP/M 11-12...
  • Page 199 Newbury Park, Ilford, Essex, IG2 7EP, England. CP/M normally uses Modified Frequency Modulation (MFM) to record on disks. Commodore DOS normally uses Group Code Recording (GCR). The Commodore 1571 disk drive can read both, but the older 1541 can only read GCR. Off-the-shelf CP/M software packages only come as MFM disks.
  • Page 200: How To Install It On Your C128

    WINSTALL.COM (the installation program that is part of the Wordstar package). These also provide the information that will be needed for installing other programs, although not all packages ask the same questions. Terminal name Commodore 128 Screen size Screen height Screen width Cursor positioning...
  • Page 201 1 Bh 45h Does your terminal use last character on screen as a scroll command? Most Commodore printers require installation as a Standard Printer with NO Communications Protocol and Primary list device as the Printer Driver. NOTE: The h against the numbers above indicates that they are hexademical numbers (using base 16 instead of the decimal base 10).
  • Page 203 SECTION 12 Files, Disks, and Drives in CP/M 3.0 WHAT IS A FILE? ..............12-3 CREATING A FILE ..............12-3 NAMING A F IL E ................12-4 File Specification ..............12-4 Drive Specifier ..............12-4 Filename ................12-4 F ile typ e ................. .12-4 Password ................
  • Page 205: What Is A File

    WHAT IS A FILE? One of C P /M ’s most important tasks is to access and maintain files on your disks. Files in CP/M are fundamentally the same as in C128 or C64 modes - that is, they are collections of information.
  • Page 206: Naming A File

    NAMING A FILE File Specification CP/M identifies every file by a unique file specification. A file specification can have four parts: a drive specifier, a filename, a filetype, and a password. The only mandatory part is the filename. Drive Specifier The drive specifier is a single letter (A-P) followed by a colon.
  • Page 207: Password

    COM. DO NOT use this filetype in your own file specifications. Password ln the Commodore 128's CP/M 3.0 you can include a password as part of the file specification. The password can be from one to eight characters. If you include a password, separate it from the...
  • Page 208: Using Wildcard Characters To Access More Than One File

    The user number always precedes the drive identifier except for user 0, which is the default user number and is not displayed in the prompt. Here are some examples of user numbers and their meanings. 4A > User number 4, drive A A >...
  • Page 209: Reserved Characters

    then CP/M 3.0 selects all files whose filename ended in TAX and whose filetype is .LIB. Reserved Characters The characters in Table 12-1 have special meaning in CP/M 3.0, so do not use these characters in file specifications except as indicated.
  • Page 210 Table 12-2. C P /M 3.0 Reserved Filetypes Filetype Meaning Assembler source file BASIC source program Z80 or equivalent machine language program Output file from MAC (used by HEXCOM) HELP message file Temporary file Print file from MAC or RMAC Output file from RMAL (used by LINK) List of commands to be executed by SUBMIT Symbol file from MAC, RMAC or LINK...
  • Page 211: Cp/M 3.0

    SECTION 13 Using the Console and Printer in CP/M 3.0 CONTROLLING CONSOLE OUTPUT ........13-3 CONTROLLING PRINTER OUTPUT ........13-3 CONSOLE LINE EDITING ............13-4 USING CONTROL CHARACTERS FOR LINE EDITING ... 13-4 13-1...
  • Page 213: Controlling Console Output

    This section describes how CP/M 3.0 communicates with your console and printer. It tells how to start and stop console and printer output, and edit commands you enter at your console. CONTROLLING CONSOLE OUTPUT Sometimes CP/M 3.0 displays information on your screen too quickly for you to read it.
  • Page 214: Console Line Editing

    CONSOLE LINE EDITING As noted previously, you can correct simple typing errors by using the INST DEL key or CTRL-H. CP/M 3.0 also supports additional line editing functions that you perform with control characters. You can use the control characters to edit command lines or input lines to most programs.
  • Page 215 Table 13-1 gives a complete list of line editing control characters for the CP/M 3.0 system on the Commodore 128. Table 13-1. Banked C P /M 3.0 Line Editing Control Characters Character...
  • Page 216 Table 13-1. Banked C P /M 3.0 Line Editing Control Characters CTRL-J Sends the command line to CP/M 3.0 and returns the cursor to the beginning of a new line. Has the same effect as a RETURN or a CTRL-M keystroke. CTRL-K Deletes from the cursor to the end of the line.
  • Page 217 SECTION 14 Summary of Major CP/M 3.0 Commands THE TWO TYPES OF C P /M 3.0 CO M M ANDS..... 14-3 BUILT-IN CO M M ANDS.............. 14-3 TRANSIENT UTILITY COMMANDS ........14-4 REDIRECTING INPUT AND O U T P U T ........14-6 ASSIGNING LOGICAL D E V IC E S ..........
  • Page 219: Cp/M 3.0 Commands

    Built-in commands are entered in the computer’s memory when CP/M 3.0 is loaded, and are, therefore, executed more quickly than the transient utilities. Table 14-1 lists the Commodore 128 CP/M 3.0 built-in commands. Some built-in commands have options that require support from a related transient utility.
  • Page 220: Transient Utility Commands

    Table 14-1. Built-in Commands Command Function Displays filenames of all files in the directory except those marked with the SYS attribute. DIRSYS Displays filenames of files marked with the SYS (system) attribute in the directory. ERASE Erases a filename from the disk directory and releases the storage space occupied by the file.
  • Page 221 DUMP Displays a file in ASCII and hexadecimal format. Creates and alters ASCII files. ERASE Used for wildcard erase. FORMAT Formats a CP/M disk. Clears data from previously used disks. GENCOM Creates a special COM file with attached RSX file. Temporarily gets console input from a disk file rather than the keyboard.
  • Page 222: Redirecting Input And Output

    REDIRECTING INPUT AND OUTPUT CP/M 3.0’s PUT command allows you to direct console or printer output to a disk file. You can use a GET command to make CP/M 3.0 or a utility program take console input from a disk file. The following examples illustrate some of the capabilities offered by GET and PUT.
  • Page 223: Assigning Logical Devices

    14-3 gives the names of CP/M 3.0 logical devices. It also shows the physical devices assigned to these logical devices in the Commodore 128 CP/M 3.0 system. Table 14-3. C P /M 3.0 Logical Devices...
  • Page 224: Executing Multiple Commands

    EXECUTING MULTIPLE COMMANDS ln the examples so far, CP/M 3.0 executed only one command at a time. CP/M 3.0 can also execute a sequence of commands. You can enter a sequence of commands at the system prompt, or you can put a frequently needed sequence of commands in a disk file, using a filetype of SUB.
  • Page 225 Suppose you type: HELP> PIP CP/M then displays the following information: PIP (COPY) Syntax: DESTINATION SOURCE PIP d: Gn filespec [Gn] =filespec [ o ] d : [o] Explanation: The file copy program PIP copies files, combines files, and transfers files between disks, printers, consoles, or other devices attached to your computer.
  • Page 227: Section 15 - Commodore Enhancements To Cp/M

    SECTION 15 Commodore Enhancements to CP/M 3.0 KEYBOARD ENHANCEMENTS.......... 15-3 Defining a K e y ................. 15-4 Defining a S trin g ..............15-4 Using ALT M o d e ..............15-5 SCREEN ENHANCEMENTS..........15-5 15-1...
  • Page 229: Keyboard Enhancements

    Commodore has added a number of enhancements to CP/M 3.0. These enhancements tailor the capabilities of the Commodore 128 to those of CP/M 3.0. This section describes these enhancements. Any key on the keyboard can be defined to generate a code or...
  • Page 230: Defining A Key

    Defining a Key A user can define the code that a key can produce. Each key has four possible definitions: Normal, Alpha Shift, Shift, and Control. The Alpha Shift is toggled o n /off by pressing the O key. After entering this mode a small box appears on the bottom of the screen.
  • Page 231: Using Alt Mode

    Return Complete string definition RETURN + (on main keyboard) Insert space into string — (on main keyboard) Delete cursor character Left arrow Cursor left Cursor right Right arrow Using ALT Mode ALT mode is a toggle function (that is, it can be switched between ON and OFF.) The default value is OFF.
  • Page 232 C P / M 3.0 is given in the Digital Research, Inc. C P /M Plus User’s Guide. To obtain a copy of this, refer to book, the coupon enclosed in the box in which the Commodore 128 is supplied. 15-6...
  • Page 233 CHAPTER BASIC 7.0 ENCYCLOPAEDIA...
  • Page 235 SECTION 16 Introduction ORGANIZATION OF ENCYCLOPAEDIA......16-3 COMMAND AND STATEMENT FORMAT......16-4 GRAPHIC AND SOUND COMMAND FORMAT....16-6 DISK COMMAND FORMAT..........16-7 16-1...
  • Page 237: Organization Of Encyclopaedia

    ORGANIZATION OF ENCYCLOPAEDIA This chapter lists BASIC 7.0 language elements. It gives a complete list of the rules (syntax) of Commodore 128 BASIC 7.0, along with a concise description of each. BASIC 7.0 includes all the elements of BASIC 2...
  • Page 238: Command And Statement Format

    COMMAND AND STATEMENT FORMAT Command nam e -» AUTO Brief definition -» — Enab le /d is ab le a u to m a ti c line n u m b e r in g Command for mat + AUTO [line#) Discussion of This c o m m a n d tu rn s on the a u to m a ti c li n e -n u m b e ri n g f e a ­...
  • Page 239 Keywords are words that are part of the BASIC language. They are the central part of a command or statement, and they tell the computer what kind of action to take. These words cannot be used as variable names. A complete list of reserved words and symbols is given in Section 20.
  • Page 240: Graphic And Sound Command Format

    VARIABLE refers to any valid BASIC variable names, such as X, A$, T%, etc. EXPRESSION refers to any valid BASIC expressions, such as A + B + 2 , ,5*(X +3), etc. COMMAS (,) COLONS (:) and SEMICOLONS (;) These MUST be included, they are required parts of the command or statement.
  • Page 241: Disk Command Format

    DISK COMMAND FORMAT Optional parameters in disk commands are shown thus: [,parameter] The comma is not required if the parameter is the first after the command itself. If other parameters which require commas are omitted the commas should be ommitted too. EXAMPLE: DIRECTORY [Ddrive][<ON | ,>Udevice number][,wild card] would in full produce:...
  • Page 243 SECTION 17 Basic Commands and Statements 17-1...
  • Page 245 APPEND Append new data to the end of a sequential file. APPEND #logical file number,“filename”[,Ddrive number] [<0N | ,>Udevice] This command opens the file having the specified filename, and positions the pointer at the end of the file. Subsequent PRINT# (write) statements will cause data to be appended to the end of this file.
  • Page 246 EXAMPLES: AUTO 10 Automatically numbers program lines in increments of 10. AUTO 50 Automatically numbers lines in increments of 50. AUTO Turns off automatic line numbering. BACKUP Copy the entire contents from one disk to another on a dual disk drive. BACKUP source Ddrive number TO destination Ddrive number [<ON | ,>Udevice] This command copies all the data from the source diskette onto...
  • Page 247 Select one of the 16 banks, numbered 0-15 BANK bank number This statement specifies the bank number and corresponding memory configuration for the Commodore 128 memory. The default bank is 15. Here is a table of available BANK configurations in the Commodore 128 memory:...
  • Page 248 B EG IN /B E N D A structure used with IF...THEN ELSE so that you can include several program lines between the start (BEGIN) and end (BEND) of the structure. Here is the format: IF Condition THEN BEGIN : statement statement statement BEND : ELSE BEGIN statement...
  • Page 249 where: • filename Is the name of your file • bank number lets you select one of the 16 banks • start address is the memory location where loading begins A binary file is a file, whether a program or data that has been SAVEd either within the machine language monitor or the BSAVE command.
  • Page 250 "GRAPHICS 1 ” , DO, U9 BOOTS the program "GRAPHICS 1 ” from unit 9, drive 0 and executes it. Execution begins at the start address of the program (ie where it starts loading). Draw box at specified position on screen BOX [color source],X1,Y1[,X2,Y2] [.angle] [.paint] where: color source...
  • Page 251 Draws the outline of a rectangle. BOX 1,10, 10, 60, 60, 45,1 Draws a painted, rotated box (a diamond). BOX , 30, 90,, 45,1 Draws a filled, rotated polygon. BOX 1, 20, 20,„1 Draws a filled rectangle from 20, 20 to the current pixel cursor. Any parameter can be omitted but you must include a comma in its place, as in the last two examples.
  • Page 252 Saves the binary file named “ SPRITE DATA” starting at location 3584 through 4095 (BANK 0). BSAVE “ PROGRAM.SCR”,D0,U9,BO,P3182 to P8000 Saves the binary file named “ PROGRAM.SCR” in the memory address range 3182 through 7999 (BANK 0) on drive 0, unit 9. CATALOG Displays the disk directory.
  • Page 253 Text (alphanumeric strings) can be displayed on any screen at a given location by the CHAR statement. Character data is read from the Commodore 128 character ROM area. The user supplies the x and y coordinates of the starting position and the text string to be displayed.
  • Page 254 CIRCLE Draws circles, ellipses, arcs, etc. at specified positions on the screen CIRCLE [color source],X,Y,Xr [,Yr] [,sa] [,ea] [.angle] [,inc] where: color source O=background color 1 =foreground color 2 = m u ltico lo r GRAPHIC modes 3=m ulitcolor > 3 and 4 Centre coordinate of the CIRCLE X radius (scaled)
  • Page 255 EXAMPLES: C IR C LE1,160,100,65,10 Draws an ellipse C IR C LE1,160,100,65 Draws a circle CIRCLE1, 60,40,20,18„„45 Draws an octagon CIRCLE1, 260,40,20,30„„90 Draws a diamond CIRCLE1, 60,140,20,18,,,,120 Draws a triangle You may omit a parameter, but you must still place a comma in the appropriate position.
  • Page 256 write list can be any alpha numeric string or variable. This command is useful for printing headings at the top of program listings. EXAMPLE: OPEN 1,4 OPENS device #4, which is the printer. CMD 1 All normal output now goes to the printer. LIST The LISTing goes to the printer, not the screen—even the word READY.
  • Page 257 statement BASIC line number of a subroutine When the specified situation occurs, BASIC will finish processing the currently executing instruction and perform a GOSUB to the line number given. When the subroutine terminates (it must end with a RETURN), BASIC will resume processing where it left off. Interrupt action continues until a COLLISION of the same type without a line number is specified.
  • Page 258 multicolor 2 40-column (VIC) border character color (40- or 80-column screen) 80-column background color Colors that are usable are in the range 1 -16. Color Code Color Color Color Code Black Orange White Brown Light Red Cyan Dark Gray Medium Gray Purple Green Light Green...
  • Page 259 CONCAT “file 2” [.Ddrive number] TO “file 1” [,Ddrive number] [<ON | ,>Udevice] The CONCAT command attaches file 2 to the end of file 1 and retains the name of file 1. The device number defaults to 8 and the drive number defaults to 0. EXAMPLE: Concat “...
  • Page 260 COPY Copy files from one drive to another in a dual disk drive or within a single drive. COPY < [“source filename”] [.Ddrive number] >TO< [“destinationfilename”] [,Ddrive number]> [CON | ,>Udevice] This command copies files from one disk (the source file) to another (the destination file) on a dual-disk drive.
  • Page 261 READ as a zero if numeric or as an empty string. Also see the RESTORE statement, which allows the Commodore 128 to reREAD data. EXAMPLE: DATA 100, 200, FRED, “HELLO MUM”, , 3,14, ABC123...
  • Page 262 This statement closes a single file or all the files currently open on a disk unit. If no logical file number is specified, all currently open files are closed. The default device number is 8. Note the following examples: EXAMPLES: DCLOSE Closes all files currently open on unit 8.
  • Page 263 EXAMPLE: 10 DEF FNEG(LO)=INT((V1*LO"2)*100)/100 LO IS LOCAL TO THIS LINE 20 LO=15 A NORMAL PROGRAM VARIABLE 30 V1 =3.14159 APPROX PI 40 PRINT FNEG(5) ASSIGN 5 TO THE LOCAL VALUE LO IN THE FUNCTION 50 PRINT FNEG(1) USE 1 IN THE FUNCTION INSTEAD OF LO 60 PRINT INT((V1*LCT2)*100/100 VARIABLE LO USED 70 PRINT LO...
  • Page 264 Declare number of elements in an array DIM variable (subscripts) [,variable(subscripts)][...] Before arrays of variables can be used, the program must first execute a DIM statement to establish DIMensions of the array (unless there are 11 or fewer elements in each DIMension of the array).
  • Page 265 8, drive 0. Use CONTROL S or NO SCROLL to pause the display; any key restarts the display after a pause. Use the COMMODORE key to slow down the display. The DIRECTORY command should not be used to print a hard copy because some printers interfere with the data coming from the disk drive.
  • Page 266 NOTE: To print the DIRECTORY,of the disk in drive 0, unit 8, use the following example: LOAD“ $0”,8 OPEN4,4:CMD4:LIST PRINT#4:CLOSE4 DLOAD Load a BASIC program from disk DLOAD “filename” [.Ddrive number] [<ON | ,>Udevice number] This command loads a BASIC program from disk into current memory.
  • Page 267 This loop structure performs the statements between the DO statement and the LOOP statement. If no UNTIL or WHILE modifies either the DO or the LOOP statement, execution of the statements in between continues indefinitely. If an EXIT statement is encountered in the body of a DO loop, execution is transferred to the first statement following the LOOP statement.
  • Page 268 Logical file numbers greater than 128 automatically send a carriage return and linefeed with each write (print #) command. Logical file numbers less than 128 send only a carriage RETURN, which can be suppressed with a semi-colon at the end of the print # command.
  • Page 269 Open the sequential file number 2 (RECIPES) for a read operation on device number 9, drive 1. DOPEN#3,“BOOKS”,L128 Open the relative file number 3 (BOOKS) for READ or WRITE on unit 8 drive 0. Record length is 128 characters. DRAW Draw dots, lines and shapes at specified positions on screen DRAW [color source],X1,Y1[TO X2, Y2]...
  • Page 270 Verify the program in memory against the one on disk DVERIFY “filename”[,Ddrive number] [CON | ,>Udevice number] This command causes the Commodore 128 to check the program on the specified drive against the program in memory. The default drive number is 0 and the default device number is 8.
  • Page 271 (wf=2) only and is determined by the formula pwout = pw/40.95, so that pw = 2048 produces a square wave and values of 0 and 4095 produce constant DC output. The Commodore 128 has initialized the following 10 envelopes: 17-29...
  • Page 272 instrument ENVELOPE 1536 piano 12, 0 accordion ENVELOPE 12, 0 calliope ENVELOPE 15, 0 drum ENVELOPE ENVELOPE flute guitar ENVELOPE harpsichord ENVELOPE 2048 organ ENVELOPE ENVELOPE trumpet ENVELOPE xylophone To play predefined musical instrument envelopes, you simply specify the envelope number in the PLAY command (see PLAY) you do not need to use the ENVELOPE command.
  • Page 273 FILTER Define sound (SID chip) filter parameters FILTER [freq] [,lp] [,bp] [,hp] [.res] where: freq Filter cut-off frequency (0-2047) Low-pass filter on (1), off (0) Bank-pass filter on (1), off (0) High-pass filter on (1), off (0) Resonance (0-15) Unspecified parameters result in no change to the current value. You can use more than one type of filter at a time.
  • Page 274 This statement executes all the commands enclosed between the FOR and NEXT statements repetitively, according to the start and end values. The start value and the end value are the beginning and ending counts for the loop variable. The loop variable is added to or subtracted from during the FOR/NEXT loop.
  • Page 275 The FOR ... NEXT loop in lines 20 and 30 are nested inside the one in line 10 and 40. Using a STEP increment of .5 is used to illustrate the fact that floating point indices are valid. See also the NEXT statement. Receive input data from the keyboard, one character at a time without waiting for a key to be pressed.
  • Page 276 GETKEY Receive input data from the keyboard, one character at a time and wait for a key to be pressed. GETKEY variable list The GETKEY statement is very similar to the GET statement. Unlike the GET statement, GETKEY if there is no character in the keyboard buffer will wait for the user to type a character on the keyboard.
  • Page 277 GOSUB line number This statement is similar to the GOTO statement, except the Commodore 128 returns from where it came when the subroutine is finished. When a line with a RETURN statement is encountered, the program jumps back to the statement immediately following the GOSUB statement.
  • Page 278 Starts (RUNs) the program starting at line 100, without clearing the variable storage area. GRAPHIC Select a graphic mode 1) GRAPHIC mode [,clear] [,s] or 2) GRAPHIC CLR This statement puts the Commodore 128 in one of the six graphic modes: mode description 40-column text standard bit-map graphics...
  • Page 279 The clear parameter specifies whether the bit mapped screen is cleared (equal to 1) upon running the program, or left intact (equal to 0). The s parameter indicates the starting line number of the split screen when in graphic mode 2 or 4 (multicolor or standard bit map split screen modes).
  • Page 280 The default device number is 8 and the default drive is 0. As a precaution, the system asks "ARE YOU SURE?” before the Commodore 128 completes the operation. Press the “ Y ” key to perform the HEADER, or press any other key to cancel it.
  • Page 281 This HEADERS “ MYDISK” using i.d 51 on drive 0, (default) device number 8. HEADER “ RECS”, 145, D1, ON U9 This HEADERS “ RECS” using i.d 45, on Drive 1, device number 9. HEADER “C128 PROGRAMS”, DO This is a quick header on drive 0, device number 8, assuming the disk in the drive was already formatted.
  • Page 282 The ELSE clause, if present, must be on the same line as the IF...THEN portion of the statement, and separated from the THEN clause by a colon. When an ELSE clause is present, it is executed only when the expression is false. The expression being evaluated may be a variable or formula, in which case it is considered true if nonzero, and false if zero, ln most cases, there is an expression involving relational operators ( = , <...
  • Page 283 INPUT Receive a data string or a number from the keyboard and wait for the user to press RETURN. INPUT [“ prompt string”;] variable list The INPUT statement asks for data from the user while the program is RUNning and places the data into a variable or variables.
  • Page 284 There are eight function keys (F1-F8) available to the user on the Commodore 128: four unshifted and four shifted. The Commodore 128 allows you to perform a function or operation for each time the specified function key is pressed. The definition assigned to a key can consist of data, or a command or series of commands.
  • Page 285 CONTROL S or NO SCROLL KEY (and resumed by pressing any other key), or stopped by hitting the RUN/STOP key. If the word LIST is followed by a line number, the Commodore 128 shows only that line number. If LIST is typed with two numbers separated by a dash all lines from the first to the second line number are displayed.
  • Page 286 Commodore 128 shows all lines from that number to the end of the program. And if LIST is typed with a dash, then a number, all lines from the beginning of the program to that line number are LISTed.
  • Page 287 The relocate flag is a number (0 or 1) that determines where a program is loaded in memory. A relocate flag of 0 tells the Commodore 128 to load the program at the start of the BASIC program area. A flag of 1 tells the computer to LOAD from the point where it was SAVEd.
  • Page 288 L0A D “HELL0”,8 Looks for the program called HELLO on disk drive number 8, drive 0. (This is equivalent to DLOAD “ HELLO” ) LOAD“ MACHLANG”,8,1 LOADs the machine language program called “ MACHLANG” into the location from which it was SAVEd. The LOAD command can be used within a BASIC program to find and RUN the next program on a tape or disk.
  • Page 289 MONITOR Enter the Commodore 128 machine language monitor MONITOR See Appendix J for details on the Commodore 128 Machine Language Monitor. MOVSPR Position or move sprite on the screen MOVSPR number,x1,y1 Place the specified sprite at absolute coordinate x,y (scaled).
  • Page 290 Be careful with the use of this command. The NEW command also can be used as a statement in a BASIC program. However, when the Commodore 128 gets to this line, the program is erased and everything stops.
  • Page 291 The second number, called the device number follows the logical file number. Device number 0 is the Commodore 128 keyboard; 1 is the cassette recorder; 3 is the Commodore 128 screen, 4-7 are normally the printer(s); and 8-11 are reserved for disk drives. It is often a good idea to use the same file number as the device number because it makes it easy to remember which is which.
  • Page 292 Following the device number may be a third parameter called the secondary address, ln the case of the cassette, this can be 0 for read, 1 for write and 2 for write with END-OF-TAPE marker at the end. ln the case of the disk, the number refers to the channel number.
  • Page 293 See also: CLOSE, CMD, GET#, INPUT#, and PRINT# statements and system variables ST, DS, and DS$. PAINT Fill area with color PAINT [color source],X,Y[,mode] where: color source 0 Bit map foreground 1 Bit map background (default) 2 Multicolor 1 3 Multicolor 2 starting coordinate, scaled (default at pixel cursor (PC)) 0 = paint an area defined by the color...
  • Page 294 EXAMPLE 1: 10 COLOR 0,1:COLOR 1,2:COLOR 2,5:COLOR 3,7 20 GRAPHIC 3,1 multicolor graphics 30 CIRCLE 1,80,100,30 draw circle in color source 1 40 CIRCLE 3,80,100,35 draw circle in color source 3 50 BOX 2,80,100,90,110,45,1 draw filled box in color source 2 60 PAINT 3,70,100,0 paint inner circle in color source 3 bounded only by color source 3...
  • Page 295 Un = Volume (n=0-9) (0=off; 9=full vol (VOL 15)) Xn — Filter on (n = 1 ), off (n=0) Elements: NOTES: A,B,C,D,E,F,G Sharp* Flat* Whole note Half note Quarter note Eighth note Sixteenth note Dotted* Rest Wait for all voices currently playing to end current measure The PLAY statement gives you the power to select voice, octave...
  • Page 296 Commodore 128 Input/Output registers. The keyword POKE is always followed by two parameters. The first is a location inside the Commodore 128 memory, this can be a value from 0 to 65535. The second parameter is a value from 0 to 255, which is placed in the location, replacing any value that was there previously.
  • Page 297 The characters inside quotes are often called literals because they are printed literally, exactly as they appear. Variable names have the value they contain (either a number or a string) printed. Functions also have their number values printed. Punctuation marks are used to help format the data neatly on the screen.
  • Page 298 Outputs the data “ HELLO THERE” and the variables A$ and B$ to the printer. 10 OPEN 2,8,2“DATAFILE,S,W” 20 PRINT#2,A,B$>C,D This example outputs the data variables A, B$, C and D to the disk file number 2. NOTE: The PRINT# command is used by itself to clear the channel to a device after outputting via CMD and before closing the file as follows: OPEN 4,4...
  • Page 299 Dollar Sign ($) Four Carets ( Equal Sign (= ) Greater Than Sign (>) The hash sign (#) reserves room for a single character in the output field. With Numeric Data if the data item contains more characters than there are # signs in the format field, the entire field is filled with asterisks (*);...
  • Page 300 A decimal point (.) symbol designates the position of the decimal point in the number. There can be only one decimal point in any format field. If a decimal point is not specified in the format field, the value is rounded to the nearest integer and printed without decimal places.
  • Page 301 EXAMPLES: FIELD EXPRESSION RESULT COMMENT ##.# Leading zero added ##.# Trailing zero added #### -101 Rounded to no -100.5 decimal places #### -1000 Overflow because four digits and a minus sign cannot fit in field ###. Decimal point added #$## Leading dollar sign The up arrows or caret symbols ( ) are used to specify that...
  • Page 302 When this is RUN, line 10 prints: $13.25 $32.00 $ * * * * * Five asterisks ( * * * * * ) are printed instead of a Y value because Y has five digits which does not conform to format list (as explained above).
  • Page 303 NOTE: All positions up to the one(s) to be changed must be specified. For example PUDEF“ $” would print the $ in place of the dollar sign but the decimal point, comma and filler character would all be set to a space. PUDEF only affects numeric formats i.e.
  • Page 304 10 READ A$, B$, C$ 20 DATA JOHN, PAUL, GEORGE READ three strings from data statements. 10 READ A, B$, C 20 DATA 1200, NANCY, 345 READ a numeric variable,a string variable and another numeric variable. RECORD Position relative file pointers RECORD# logical file number, record number [,byte] This statement positions a relative file pointer to select any byte (character) of any record in the relative file.
  • Page 305 The RECORD command accepts variables for its parameters. It is often convenient to place a RECORD command within a FOR...NEXT or DO loop. Also see DOPEN. Comments or remarks about the operation of a program line REM [message] The REMark statement is a note to whoever is reading a listing of the program.
  • Page 306 RENUMBER R enum ber lines of a BASIC program RENUMBER [new starting line number] [.increment] [,old starting line number] The new starting line is the number of the first line in the program after renumbering; the default value is 10. The increment is the interval between line numbers, (i.e., 10, 20, 30, etc.);...
  • Page 307 Also note that long programs should be RENUMBERed in FAST mode as they will take a long time to renumber (up to 30 minutes for a 55K program in FAST). If you only have a 40 column display use FAST:RENUMBER . . . <RETURN>.
  • Page 308 This example READs the data in line 70 and stores it in numeric variable X. It adds the total (T) of all the numeric data items. Once all the data has been READ, three cycles through the loop, the READ pointer is RESTOREd to the beginning of the program and it returns to line 10 and performs repetitively.
  • Page 309 EXAMPLE: 10 TRAP 100 20 INPUT “ ENTER A NUMBER” ,A 30 B=100/A 40 PRINT“THE RESULT=”,B:PRINT”THE END” 50 PRINT“ DO YOU WANT TO RUN IT A G AIN(Y/N)” :GETKEYZ$:IF Z$=“Y”THEN 20 60 STOP 100 INPUT“ ENTER ANOTHER NUMBER (NOT ZERO)” ;A 110 RESUME This example traps a "division by zero error”...
  • Page 310 RUN/RUN Execute BASIC program RUN [line #] RUN “filename” [,Ddrive number] [,Udevice number] C128 mode only Once a program has been typed into memory or LOADed, the RUN command executes it. RUN clears all variables in the program before starting program execution. If there is a number following the RUN command, execution starts at that line number.
  • Page 311 important on the tape before SAVEing (see VERIFY). To give your program a name simply enclose the chosen name in quotes (or use a string variable) immediately after typing SAVE. A filename can be up to 16 characters. NOTE: When SAVEing to disk you must specify a filename or you will get a MISSING FILE NAME ERROR.
  • Page 312 SAVE “HELLO”, 1, 2 Stores on tape, with name HELLO, and places an END-OF TAPE marker after the program. SAVE “”,1,3 Stores on tape, with no name, places an EOT marker after the program, does not allow the program to be relocated on loading. SCALE Alter scaling in graphics mode SCALE n [,xmax,ymax]...
  • Page 313 EXAMPLE: 10 GRAPHIC 1 :GOSUB 100 20 SCALE 1 ¡GOSUBlOO 30 SCALE 1,5000,5000 :GOSUB100 40 END 100 CIRCLE 1,160,100,60:RETURN SCNCLR Clear screen SCNCLR[mode number] The modes are as follows: Mode Number Mode 40 column (VIC) text bit map* split screen bit map* multicolor bit map* split screen multicolor bit map*...
  • Page 314 This command deletes a file from the disk directory. As a precaution, the system asks “ Are you sure," (in direct mode only) before the Commodore 128 starts the operation. Type a Y to perform the SCRATCH or press any other key to cancel the operation.
  • Page 315 SOUND Outputs sound effects and musical notes SOUND v,f,d[,dir] [,m] [,»] [,w] [,p] voice (1 ..3) frequency value (0..65535) duration (0..32767 dir = step direction (0(up) ,1 (down) or 2(oscillate)) default=0 minimum frequency (if sweep is used) (0..65535) default=0 step value for sweep (0..65535) default=0 waveform (0=triangie,1 =sawtooth,2=pulse, 3=noise) default=2 pulse width (0..4095) default=2048...
  • Page 316 This example outputs a range of sounds starting at a minimum frequency of 3000, through 5000, in increments of 500. The direction of the sweep is back and forth (oscillating). The selected waveform is sawtooth and the voice selected is 3. SPRCOLOR Set multicolor 1 a nd /or multicolor 2 colors for all sprites SPRCOLOR [smcr-1] [,smcr-2]...
  • Page 317 1 clear 2 foreground 3 multicolor 1 4 multicolor 2 <CTRL> 1-8 Selects sprite foreground color (1 -8). Commodore key(1 -8) Selects sprite foreground color (9-16). STOP key Cancels changes and returns to prompt. SHIFT RETURN Saves sprite in memory and returns to SPRITE NUMBER? prompt.
  • Page 318 Parameter Description number Sprite number (1 -8). on/off Turn sprite on (1 ) or off (0). fgnd Sprite foreground color (1 -16). priority Priority is 0 if sprites appear in front of objects on the screen priority is 1 if sprites appear behind objects on the screen.
  • Page 319 SPRSAV Store sprite data from a text string variable into a sprite storage area or vice versa SPRSAV origin,destination This command transfers a sprite image from a string variable to a sprite storage area. It can also transfer the data from the sprite storage area into a string variable.
  • Page 320 where: string variable String name to save data in X1,Y1 Corner coordinate (0,0 through 320,200) (scaled) X2,Y2 Corner coordinate opposite (X1 ,Y1 ) (default is the PC) Because BASIC limits strings to 255 characters, the size of the area that can be saved is limited. The string size required can be calculated using one of the following (unsealed) formulas: L(h-r) = INT ( (ABS(x1 -x2) + 1 ) / 8 + .99) * (ABS(y1 -y2)+1 )+4 L(m cm )= IN T ( (ABS(x1 -x2) + 1 ) / 4 + .99) * (ABS(y1 -y2) + 1 ) + 4...
  • Page 321 EXAMPLES: SSHAPE A$,10,10 Saves a rectangular area from the coordinates 10,10 to the location of the pixel cursor, into string variable A$. SSHAPE B$,20,30,47,51 Saves a rectangular area from top left coordinate (20,30) through bottom right coordinate (47,51 ) into string variable B$. GSHAPE AS,120,20 Retrieves shape continued in string variable A$ and displays it at top left corner at coordinate (120,20).
  • Page 322 SWAP Swap contents of host RAM with contents of expansion RAM. SWAP #bytes, intsa, expsa, expb Refer to FETCH command for description of parameters. S Y S /S Y S Called and execute a machine language subroutine at the specified address SYS address C64 mode SYS address [,a] [,x] [,y] [,s]...
  • Page 323 The actual duration for a whole note is determined by using the formula given below: whole note duration = 23.06/n seconds The default value is 8, and note duration increases with n. EXAMPLES: TEMPO 16 Defines the Tempo at 16 TEMPO 1 Defines the TEMPO at the slowest speed TEMPO 250 Defines the TEMPO at 250 TRAP...
  • Page 324 SAVEd. This command is also very useful for positioning a tape so that the Commodore 128 writes after the last program on the tape.
  • Page 325 comma and a number, checks the program on the device with that number (1 for tape, 8 for disk). The relocate flag is the same as in the LOAD command. It verifies the program from the memory location from which it was SAVEd. (See also DVERIFY.) EXAMPLES: VERIFY Checks the next program on the tape.
  • Page 326 WAITs until a key is pressed on the tape unit to continue with the program. The second example will WAIT until the SHIFT key is pressed and then released. The third example will WAIT until either bit 7 (128) is on or bit 4 (16) is off. 17-84...
  • Page 327 EXAMPLES: WAIT 1, 32, 32 WAIT 211,1:WAIT211,1,1 WAIT 36868, 144,16 (144 and 16 are binary masks. 144 = 10010000 in binary and 16 = 10000 in binary.) WIDTH Set the width of drawn lines WIDTH n This command sets the width of lines drawn using BASIC’s graphic commands to either single or double width.
  • Page 328 WINDOW 10,2,33,24,1 Define a window with upper left corner coordinate (10,2) and lower right corner coordinate (33,24). Also clears the portion of the screen within the window as specified by the 1. NOTE: If you specify a column greater than 39 on a 40 column display you will get an “...
  • Page 329 SECTION 18 Basic Functions 18-1...
  • Page 331 BASIC FUNCTIONS The format of the function description is: FUNCTION (argument) where the argument can be a numeric value, variable or string. Each function description is followed by an EXAMPLE. The lines appearing in bold face in the examples are the functions you type in.
  • Page 332 This function returns the angle whose tangent is X, measured in radians. EXAMPLE: PRINT ATN (3) 1.24904577 BUMP Return sprite collision information BUMP (N) To determine which sprites have collided since the last check, use the BUMP function. BUMP(1) records which sprites have collided with each other and BUMP(2) records which sprites have collided with other objects on the screen.
  • Page 333 EXAMPLES: PRINT CHR$ (65) Prints the a character, PRINT CHR$ (147) Clears the text screen. Return cosine for angle of X radians COS(X) This function returns the value of the cosine of X, where X is an angle measured in radians. EXAMPLE: PRINT COS ( Return decimal value of hexadecimal number string...
  • Page 334 EXAMPLE: PRINT ERR$(10) NEXT WITHOUT FOR Return value of an approximation of e (2.7182813) raised to the power X EXP(X) This function returns a value of e (2.7182813) raised to the power EXAMPLE: PRINT EXP(1) 2.7182813 FNxx Return value from user defined function FNxx(X) This function returns the value from the user-defined function xx created in a DEF FNxx statement.
  • Page 335 STARTING POSITION is greater than the length of string 1 or if string 1 is null, INSTR returns the value 0. If string 2 is null, INSTR returns 0. EXAMPLE: PRINT INSTR (“ COMMODORE 128 “ 128”) 18-7...
  • Page 336 1 JOY returns position of joystick 1 2 JOY returns position of joystick 2 Any value of 128 or more means that the fire button is also pressed. To find the JOY value, add the direction value of the joystick plus 128, if the JOY fire button is pressed. The direction...
  • Page 337 If an integer value of zero is used, then a null string (of zero length) is returned. EXAMPLE: PRINT LEFT$ (COMMODORE”,5) COMMO Return the length of a string LEN (string) This function returns the number of characters in the string expression.
  • Page 338 MID$ returns a null string value. If the length argument is left out, all characters to the right of the starting position are returned. EXAMPLE: PRINT M ID $(“ COMMODORE 128,3,5) MMODO EXAMPLE using overlay: A$=“ 123456”:MID$(A$,3,2)=“ABCDE” :PRINT A$...
  • Page 339 This example displays the contents of the registers of the VIC chip. Returns X and Y coordinates of the light pen PEN(n) where n=0 PEN returns the X coordinate of light pen position. n=1 PEN returns the Y coordinate of light pen position. n=2 PEN returns the X coordinate of the 80 column display.
  • Page 340 Returns the value of pi (3.14159265) EXAMPLE: PRINT 7 r 3.14159265 POINTER Return the address of a variable name POINTER (variable name) EXAMPLE: PRINT POINTER (Z) This example returns the address of variable Z. Returns the current cursor column position within the current screen window POS(X) The POS function indicates where the cursor is within the defined...
  • Page 341 when: n=1, POT returns the position of paddle #1 n=2, POT returns the position of paddle #2 n=3, POT returns the position of paddle #3 n=4, POT returns the position of paddle #4 The values for POT range from 0 to 255. Any value of 256 or more means that the fire button is also depressed.
  • Page 342 RDOT Return current position or color of pixel cursor. RDOT (N) where: = 0 returns the X coordinate of the pixel cursor = 1 returns the Y coordinate of the pixel cursor = 2 returns the color source of the pixel cursor This function returns the location of the current position of the pixel cursor (PC) or the current color source of the pixel cursor.
  • Page 343 RIGHTS Return substring from rightmost end of string RIGHT$ (<string>, <num eric>) This function returns a substring taken from the rightmost characters of the string argument. The length of the substring is defined by the length argument which can be any integer in the range of 0 to 255.
  • Page 344 EXAMPLES: PRINT RND(O) This displays a random .507824123 number. PRINT INT(RND(1)*100 + 1) This displays a random positive number less than 100. RSPCOLOR Return sprite multicolor values RSPCOLOR (register) When: X = 1 RSPCOLOR returns the sprite multicolor 1 X = 2 RSPCOLOR returns the sprite multicolor 2 The returned color value is a value between 1 and 16.
  • Page 345 When x equals: 0 RSPPOS returns the current X position of the specified sprite. 1 RSPPOS returns the current Y position of the specified sprite. 2 RSPPOS returns the speed (0-15) of the specified sprite. EXAMPLE: 10 SPRITE 1,1,2 20 MOVSPR 1,45#13 30 PRINT RSPPOS(1,0);RSPPOS(1,1);RSPPOS(1,2) This example returns the current X and Y sprite coordinates and the speed (13).
  • Page 346 RWINDOW Returns the size of the current window RWINDOW (n) When n equals: 0 RWINDOW returns the number of lines in the current window. 1 RWINDOW returns the number of rows in the current window. 2 RWINDOW returns either of the values 40 or 80, depending on the current screen output format you are using.
  • Page 347 SPaCe is printed in the last character position of a line. No SPaCes are printed on the following line. EXAMPLE: PRINT “ COMMODORE” ;SPC(3);“ 128” COMMODORE Return square root of argument SQR (X) This function returns the value of the SQuare Root of X, where X is a positive number or 0.
  • Page 348 X, the TAB command is ignored. The TAB function should only be used with the PRINT statement, since it has varied effects if used with the PRINT# to a logical file depending on the device being used. EXAMPLE: 10 PRINT“COMMODORE”TAB(25)“ 128” COMMODORE 18-20...
  • Page 349 BASIC. EXAMPLE (128 Only): 10 POKE 4633,0 20 POKE 4634,192 Note: default 128 bank 15. 30 A = USR(X) 40 PRINT A Place starting location ($C000=49152:$00=0:$C0=192) of machine language routine in location 4633 and 4634. Line 30 stores the returning value from the floating point accumulator.
  • Page 350 STR$. The string is examined from the left­ most character to the right, for as many characters as are in recognizable number format. If the Commodore 128 finds illegal characters, only the portion of the string up to that point is converted.
  • Page 351 SECTION 19 Variables and Operators VARIABLES .................. 19-3 OPERATORS.................19-5 19-1...
  • Page 353 STRING VARIABLES are those used for character data, which may contain numbers, letters and any other characters the Commodore 128 can display. An example of a string variable is “ COMMODORE 128” . VARIABLE NAMES may consist of a single letter, a letter followed by a number, or two letters.
  • Page 354 Tl and Tl$ are variables that relate to the real time clock built into the Commodore 128. The system clock is updated every 1 /60th of a second. It starts at 0 when the Commodore 128 is turned on, and is reset only by changing the value of Tl$. The variable Tl gives the current value of the clock in 1 /60th of a second.
  • Page 355 If two operators have the same priority, then calculations are performed in order from left to right. If these operations are to occur in a different order, Commodore 128 BASIC allows giving a calculation a higher priority by placing parentheses around it.
  • Page 356 There are also operators for equalities and inequalities, called RELATIONAL operators. Arithmetic operators always take priority over relational operators. is equal to is less than < is greater than > < = or = < is less than or equal to >...
  • Page 357 SECTION 20 Reserved Words and Symbols RESERVED SYSTEM WORDS (KEYWORDS)......20-3 RESERVED SYSTEM SYMBOLS..........20-4 20-1...
  • Page 358 20-2...
  • Page 359 RESERVED SYSTEM WORDS (KEYWORDS) This section lists the words and symbols used to make up the BASIC 7.0 language. These words and symbols cannot be used within a program as other than a component of the BASIC language. The only exception is that they may be used within quotes in a PRINT statement.
  • Page 360 RESERVED SYSTEM SYMBOLS The following characters are reserved system symbols. Symbol Use(s) Plus sign A rith m e tic addition; string c o n c a te n a tio n ; relative sprite m o ve m e n t; d e c la re d e c im a l n u m b e r in m a c h in e la n g u a g e m onitor A rith m e tic subtraction;...
  • Page 361 Hash Precede the logical file number in input/output statements Dollar sign Declare a variable name as a string and declares hexadecimal number in machine language monitor And sign Declare octal number in machine language monitor Declare the numeric constant — approximately 3.14159265...
  • Page 363 APPENDICES BASIC LANGUAGE ERROR MESSAGES APPENDIX A APPENDIX B DOS ERROR MESSAGES APPENDIX C CONNECTORS/PORTS FOR PERIPHERAL EQUIPMENT APPENDIX SCREEN DISPLAY CODES APPENDIX ASCII AND CHR$ CODES APPENDIX SCREEN AND COLOR MEMORY MAPS APPENDIX DERIVED MATHEMATICAL FUNCTIONS APPENDIX H — MEMORY MAP APPENDIX CONTROL AND ESCAPE CODES...
  • Page 365 APPENDIX A BASlC LANGUAGE ERROR MESSAGES The following error messages are displayed by BASIC. Error messages can also be displayed with the use of the ERR$() function. The error numbers below refer only to the number assigned to the error for use with the ERR$() function. ERROR# ERROR NAME DESCRIPTION TOO MANY FILES...
  • Page 366 NOT OUTPUT FILE An attempt was made to send data to a file that was specified as input only. MISSING FILE NAME File name missing in command. ILLEGAL DEVICE An attempt was made to use a device improperly (SAVE NUMBER to the screen, etc.).
  • Page 367 are too many nested DO, FOR or GOSUB statements in effect. A line number refer UNDEF’D STATEMENT enced doesn’t exist in the program. BAD SUBSCRIPT The program tried to reference an element of an array out of the range specified by the DIM statement.
  • Page 368 UNDEFINED FUNCTION A user-defined function was referenced that was never defined. VERIFY The program on tape or disk does not match the program in memory. LOAD There was a problem loading. Try again. BREAK The stop key was hit to halt program execution.
  • Page 369 The program encountered BEND NOT FOUND an “ IF...THEN BEGIN “ or “ IF...THEN...ELSE BEGIN” construct, and could not find a BEND keyword to match the BEGIN. LINE# TOO LARGE An error has occurred in renumbering a BASIC program. The given parameters result in a line number >...
  • Page 371 APPENDIX B DOS ERROR MESSAGES The following error messages are returned through the DS and DS$ variables. The DS variable contains just the error number and the DS$ variable contains the error number, the error message and any corresponding track and sector number. NOTE: Error message numbers less than 20 should be ignored with the exception of 01, which gives information about the number of files scratched with the SCRATCH command.
  • Page 372 READ ERROR (byte decoding error) The data or header has been read into the DOS memory but a hardware error has been created due to an invalid bit pattern in the data byte. This message may also indicate grounding problems. WRITE ERROR (write-verify error) This message is generated if the controller detects a mismatch between the written data...
  • Page 373 SYNTAX ERROR (long line) The command sent is longer than 58 characters. Use abbreviated disk commands. SYNTAX ERROR (invalid file name) Pattern matching is invalidly used in the OPEN or SAVE command. Spell out the file name. SYNTAX ERROR (no file given) The file name was left out of the command or the DOS does not recognize it as such.
  • Page 374 FILE NOT OPEN This message is generated when a file is being accessed that has not been opened in the DOS. Sometimes, in this case, a message is not generated; the request is simply ignored. FILE NOT FOUND The requested file does not exist on the indicated drive.
  • Page 375 DIRECTORY ERROR The BAM (Block Availability Map) on the diskette does not match the copy on disk memory. To correct, initialize the diskette. DISK FULL Either the blocks on the diskette are used or the directory is at its entry limit. DISK FULL is sent when two blocks are still available on the diskette, in order to allow the current file to be closed.
  • Page 376 APPENDIX C 128D CONNECTORS/PORTS FOR PERIPHERAL EQUIPMENT KEYBOARD C O N N EC TIO N — SOCKET — _CO NTRO L PORT 1 CO NTRO L PORT 2 RESET SW ITC H DISK DRIVE RESET SW ITCH EXPANSION PORT CASSETTE PORT SERIAL SOCKET VIDEO SOCKET POW ER SUPPLY...
  • Page 377 APPENDIX C CONNECTORS/PORTS FOR PERIPHERAL EQUIPMENT...
  • Page 378 Side Panel Connections Power Socket—The five pin square plug from the power supply is connected here. Power Switch—Turns on power from the power supply. Reset Button— Resets computer (warm start). Controller Ports—There are two Controller ports, numbered 1 and 2. Each Controller port can accept a joystick or game controller paddle.
  • Page 379 Rear Connections Expansion Port—This rectangular slot is a parallel port that accepts programs or game cartridges as well as special interfaces. Cartridge Expansion Slot Type Type Dot Clock I/O 1 GAME EXROM I/O 2 ROML Type Type ROMH RESET S 02 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 ■■■■■■■■■■■■■■■■■■■■■■...
  • Page 380 Commodore 128 through this port. Serial I/O Type SERIAL SRQIN SERIAL ATN IN/OUT SERIAL CLK IN/OUT SERIAL DATA IN/OUT RESET Note: The Commodore Serial Port is not RS-232 compatible. TTL RS-232 levels can be obtained from the User Port.
  • Page 381 8. 40 Column Video Connector—This DIN connector provides audio and composite video signals which can be directly connected to suitable audio and monitor equipment. These signals can be connected to the Commodore monitor or used with separate components. Note Type Luminance/SYNC output...
  • Page 382 Signal Ground Ground Green Blue Intensity Monochrome Horizontal Sync Vertical Sync 11. User Port—Various interface devices can be attached here. User I/O Type Note MAX. 100 mA RESET CNT1 CNT2 SER. ATN IN 9 VAC MAX. 100 mA 9 VAC MAX.
  • Page 383 From BASIC, PRINT CHR$(142) will switch to upper­ case/graphics mode and PRINT CHR$(14) will switch to upper/lower-case mode. Any number on the chart may also be displayed in REVERSE. The reverse character code may be obtained by adding 128 to the values shown. SET 1 SET 2...
  • Page 384 POKE SET 1 SET 2 SET 2 POKE JET 2 SET 1 POKE & □ □ □ □ □ □ □ □ œ □ □ ■ □ □ □ □ æ □ □ □ æ æ □ 0 s ? ■...
  • Page 385 I SPACE □ □ Codes from 128-255 are reversed images of codes 0-127.
  • Page 387 APPENDIX E ASCII AND CHRSCODES This appendix shows you what characters will appear if you PRINT CHR$(X), for all possible values of X. It also shows the values obtained by typing PRINT ASC(“ x” ), where x is any character that can be displayed. This is useful in evaluating the character received in a GET statement, converting upper to lower case and printing character-based commands (like switch to upper/lower case) that could not be enclosed in quotes.
  • Page 388 CHRS CHRS PRINTS PRINTS CHRS PRINTS CHRS ! PRINTS £ □ □ □ ■ SWITCH TO ■ □ ! 142 ■ □ upper c a s e □ [.II \ i \ f f l □ ■ Brown Lt. Red □...
  • Page 389 C H R S PRINTS PRINT8 C H R S PRINTS C H R S PRINTS C H R S □ CODES 192-223 S AME AS 96-127 CODES 224-254 SAME AS 160-190 CODE SAME AS NOTE: The above codes are for C64 mode. See Appendix I for spécial codes in C128 mode.
  • Page 391 APPENDIX F SCREEN AND COLOR MEMORY MAPS—C128 Mode, 40 Column and C64 Mode The following maps display the memory locations used in 40- column mode (C128 and ¿64) for identifying the characters on the screen as well as their color. Each map is separately controlled and consists of 1,000 positions.
  • Page 392 The Screen Map is POKEd with a Screen Display Code value (see Appendix D). For example: POKE 1024, 13 will display the letter M in the upper-left corner of the screen. COLOR MEMORY MAP COLUMN 55335 5 5 2 9 6 55336 55376 5 5 4 16...
  • Page 393 Color Codes— 40 Columns Black Orange White Brown Light Red Dark Gray Cyan Medium Gray Purple Green Light Green Light Blue Blue Yellow Light Gray Border Control Memory 53280 Background Control Memory 53281...
  • Page 395 APPENDIX G DERIVED TRIGONOMETRIC FUNCTIONS FUNCTION BASIC EQUIVALENT SECANT SEC(X)=1 /COS(X) COSECANT CSC(X)=1 /SIN(X) COTANGENT COT(X)=1 /TAN(X) INVERSE SINE ARCSIN(X)=ATN(X/SQR(-X*X+1 )) INVERSE COSINE ARCCOS(X)=-ATN(X/SQR (-X*X+1))+ INVERSE SECANT ARCSEC(X)=ATN(X/SQR(X*X-1 )) ARCCSC(X)=ATN(X/SQR(X*X-1 )) INVERSE COSECANT +(SGN(X)-1 * INVERSE COTANGENT ARCOT(X)=ATN(X)+ HYPERBOLIC SINE SINH(X)=(EXP(X)-EXP(-X))/2 COSH(X)=(EXP(X)+EXP(-X))/2 HYPERBOLIC COSINE...
  • Page 397: Memory Map

    APPENDIX H MEMORY MAP SYSTEM MEMORY MAP The Commodore 128 BASIC memory map is shown below: COMMODORE 128 MODE MEMORY MAP C128 C128 FFFF FFFA N M I RST IRQ C P /M RAM Code FFDO FF4D - Kernal Jum p Table & -...
  • Page 398 COMMODORE 128 MODE MEMORY MAP C128 C128 4 0 0 0 VIC BIT-M AP Screen 2000 VIC BIT-M AP Color (V m # 2 ) 1C00 1B00 Reserved lor 1888 1A00 Function Key S oftw a re Reserved for Foreign Lang...
  • Page 399 APPENDIX I CONTROL AND ESCAPE CODES CONTROL CODES Effective in Mode: CHR$ Sequence Function C64 C128 ★ CHR$(2) CTRL B Underline (80) CHR$(5) CTRL 2 or Set character color to white ★ CTRL E (40) and (80) CHR$(7) Produce bell tone CTRL G Disable character set CHR$(8)
  • Page 400 Effective in Mode: C64 C128 CHR$ Sequence Function CHR$(19) HOME or Move the cursor to the CTRLS home position (top left) of the display (the current window) CHR$(20) DEL or Delete last character CTRL T typed and move all characters to the right of the deleted character one space to the left...
  • Page 401 Effective in Mode: CHR$ Function C64 C128 Sequence CHR$(137) Reserved CHR$ code for F2 key CHR$(138) Reserved CHR$ code for F4 key CHR$(139) Reserved CHR$ code for ★ F6 key CHR$(140) Reserved CHR$ code for ★ ★ F8 key CHR$(141 ) SHIFT RETURN Send a carriage return and line feed without entering...
  • Page 402 (80)... 80 column screen only ESCAPE CODES Following are key sequence for the ESCape functions available on the Commodore 128. ESCape sequences are entered by pressing and releasing the “ ESC” key, followed by pressing the key listed below. ESCAPE FUNCTION...
  • Page 403 Scroll up ESC V Scroll down ESC W Enable bell (by control-G) ESC G Disable bell ESC H Set cursor to non-flashing mode ESC E Set cursor to flashing mode ESC F Set Bottom of screen window at cursor position ESC B Set top of screen window at cursor position ESC T...
  • Page 405 APPENDIX J MACHINE LANGUAGE MONITOR INTRODUCTION Commodore 128 has a built-in machine language monitor which lets the user write and examine machine language programs easily. Commodore 128 MONITOR includes a machine language monitor, a mini-assembler and a disassembler. The built-in monitor works only in C128 mode;...
  • Page 406 (at sign) Displays disk status, sends disk command, displays directory The commodore 128 displays 5-digit hexadecimal addresses within the machine language monitor. Normally, a hexadecimal number is only four digits, representing the allowable address range. The extra left-most (high order) digit specifies the BANK...
  • Page 407 ? < question> terminatorlogical end of line. Note: < > enclose required parameters [ ] enclose optional parameters COMMODORE 1 2 8 MONITOR COMMAND DESCRIPTIONS Please note that nay number field (e.g..addresses, device number, and data bytes) may be specified as a based number.
  • Page 408 COMMAND: PURPOSE: Enter a line of assembly code. SYNTAX: < address> <opcode mnemonic> < operand> A hexadecimal number < address> indicating the location in memory to place the opcode. Copcode A standard MOS technology m nemonic> assembly language mnemonic, e.g., LDA, STX, ROR. <...
  • Page 409 COMMAND: PURPOSE: Disassemble machine code into assembly language mnemonics and operands. D [<address1> ][< address 2 > ] SYNTAX: <address1> A number setting the address to start the disassembly. <address 2 > An optional ending address of code to be disassembled. The format of the disassembly differs slightly from the input format of an assembly.
  • Page 410 R command) and begins execution at the specified starting address. Caution is recommended in using the GO command. To return to Commodore 128 MONITOR mode after executing a machine language program, use the BRK instruction at the end of the program.
  • Page 411 Load a file from cassette or disk. SYNTAX: < "file name”> [,< d e v ic e > [,alt load address]] < “file name”> Any legal Commodore 128 file name. < d e v ic e > A hexadecimal number indicating the device to load from.
  • Page 412 <address 2 > ] Last address of memory dump. Optional. If omitted, one page is displayed. The first byte is the bank number to be dis-played, the next four bytes are the ending address to be displayed. Memory is displayed in the following format: >03000 45 58 2E 56 41 4C 55 45:EX.VALUE Memory content may be edited using the screen editor.
  • Page 413 Save an area of memory onto tape or disk. SYNTAX: S < “ file name”> ,< device> ,<address 1>, <address 2> < “file name”> A n y legal Commodore 128 file name. To save the data the file name must be enclosed in double quotes. Single quotes cannot be used.
  • Page 414 Verify a file on cassette or disk with the memory contents. SYNTAX: < “file name”> [,< d e v ic e > ] [,alt start address] < "file name”> A n y legal Commodore 128 file name. < d e vic e > A number indicating which device the file is on;...
  • Page 415 < address> First memory address to set. <data byte 1 ...8/16 > Data to be placed in the succes­ sive memory locations following the address with a space preceding each data byte. The maximum number of bytes that can be entered is 8 (in 40 column mode) or 16 (in 80 column mode).
  • Page 417 APPENDIX K BASlC 7.0 ABBREVIATIONS Note: The abbreviations below operate in uppercase/graphic mode. Press the letter key(s) indicated, then hold down the SHIFT key and press the letter key following the word SHIFT. KEYWORD ABBREVIATION A SHIFT B APPEND A SHIFT P A SHIFTS A SHIFT T AUTO...
  • Page 418 KEYWORD ABBREVIATION DATA D SHIFT A none DCL SHIFT E DCLEAR DCLOSE D SHIFTC DEFFN none DELETE DE SHIFT L D SHIFT 1 DIRECTORY Dl SHIFT R D SHIFT L DLOAD none D SHIFT0 DOPEN DRAW D SHIFT R D SHIFT S DSAVE D SHIFT V DVERIFY...
  • Page 419 KEYWORD ABBREVIATION INPUT# 1 SHIFT N INSTR IN SHIFT S none J SHIFT0 K SHIFT E LE SHIFT F LEFTS none L SHIFT E LIST L SHIFT 1 LOAD L SHIFT0 LOCATE LO SHIFTC none LO SHIFT0 LOOP M SHIFT 1 MID$ MO SHIFT N MONITOR...
  • Page 420 ABBREVIATION KEYWORD REN SHIFT U RENUMBER RE SHIFT S RESTORE RES SHIFT U RESUME RE SHIFT T RETURN R SHIFTG R SHIFT I RIGHTS none RLUM R SHIFT N R SHIFT R RREG RSP SHIFTC RSPCOLOR R SHIFT S RSPPOS none RSPR RSP SHIFT R...
  • Page 421 KEYWORD ABBREVIATION none none none T SHIFT R TRAP TROFF TRO SHIFT F TRON TR SHIFT0 UNTIL U SHIFT N U SHIFT S none VERIFY V SHIFT E V SHIFT0 WAIT W SHIFT A WHILE W SHIFT H WIDTH Wl SHIFT D WINDOW W SHIFT 1 X SHIFT0...
  • Page 423 DISK COMMAND SUMMARY This appendix lists the commands used for disk operation in C128 and C64 modes on the Commodore 128. For detailed information on any of these commands, see Chapter V, BASIC 7.0 Encyclopedia. Your disk drive manual also has information on disk commands.
  • Page 424 Command Basic 2.0 Basic COPY Copy files between ✓ drives * DCLEAR Resets and initialises disk drives * DCLOSE Close logical disk files DIRECTORY Display directory of contents of disk on screen * DLOAD Load a BASIC program from disk * DOPEN Open a disk file for a read and/or write...
  • Page 425 GLOSSARY This glossary provides brief definitions of frequently used computing terms. Acoustic Coupler or Acoustic Modem: A device that converts digital signals to audible tones for transmission over telephone lines. Speed is limited to about 1,200 baud, or bits per second (bps). Compare direct-connect modem. Address: The label or number identifying the register or memory location where a unit of information is stored.
  • Page 426 Bit Control: A means of transmitting serial data in which each bit has a significant meaning and a single character is surrounded with start and stop bits. Bit Map Mode: An advanced graphic mode in the Commodore 128 in which you can control every dot on the screen. GL-2...
  • Page 427 Byte: A group of eight bits that make up the smallest unit of addressable storage in a computer. Each memory location in the Commodore 128 contains one byte of information. One byte is the unit of storage needed to represent one character in memory.
  • Page 428 Collision Detection: The recognition of the collision of sprites with other sprites or display data. Color Memory: The area in the Commodore 128’s memory that controls the color of each location in screen memory. Command: A BASIC instruction used in direct mode to perform an action.
  • Page 429 computer containing the circuits that control and perform the execution of computer instructions. Crunch: To minimize the amount of computer memory used to store a program. Cursor: The flashing square that marks the current location on the screen. Data: Numbers, letters or symbols that are input into the computer to be processed.
  • Page 430 “ mail box,” and later retrieved by the addressee. Enable: To turn on a bit, byte or specific operation of the computer. Envelope Generator: Portion of the Commodore 128 that produces specific envelopes (attack, decay, sustain, release) for musical notes. See Waveform.
  • Page 431 Function: A predefined operation that returns a single value. Function Keys: The four keys on the far right of the Commodore 128 keyboard. Each key can be programmed to execute a series of instructions. Since the keys can be SHIFTed, you can create eight different sets of instructions.
  • Page 432 Half-Duplex Mode: Allows transmission in only one direction at a time; if one device is sending, the other must simply receive data until it’s time for it to transmit. Hardware: Physical components in a computer system such as keyboard, disk drive and printer. Hexadecimal: Refers to the base-16 number system.
  • Page 433 There are 131,072 memory locations (0-131,071) in the Commodore 128. Microprocessor: A CPU that is contained on a single integrated circuit (IC). Microprocessors used in Commodore personal computers include the 6510, the 8502 and the Z80. Mode: A state of operation.
  • Page 434 Multi-Color Character Mode: A graphic mode that allows you to display four different colors within an 8 X 8 character grid. Multi-Color Bit Map Mode: A graphic mode that allows you to display one of four colors for each pixel within an 8 X 8 character grid.
  • Page 435 Program Line: A statement or series of statements preceded by a line number in a program. The maximum length of a program line on the Commodore 128 is 160 characters. PROM: Acronym for Programmable Read Only Memory. A semiconductor memory whose contents cannot be changed.
  • Page 436 RS-232: A recommended standard for electronic and mechanical specifications of serial transmission ports. The Commodore 128 parallel user port can be treated as a serial port if accessed through software, sometimes with the addition of an interface device.
  • Page 437 POKE command. Screen Memory: The area of the Commodore 128’s memory that contains the information displayed on the video screen. Serial Port: A port used for serial transmission of data; bits are transmitted one bit after the other over a single wire.
  • Page 438 40-column graphics features of the Commodore 128. Voice: A sound-producing component inside the SID chip. There are three voices within the SID chip so the Commodore 128 can produce three different sounds simultaneously. Each voice consists of a tone oscillator/waveform generator, an envelope generator and an amplitude modulator.
  • Page 439 Waveform: A graphic representation of the shape of a sound wave. The waveform determines some of the physical characteristics of the sound. Word: Number of bits treated as a single unit by the CPU. ln an eight-bit machine, the word length is eight bits; in a 16-bit machine, the word length is 16 bits.
  • Page 441 BUMP, 18-4 Alt mode, 15-5 Animation, 6-16, 6-31 APPEND, 17-3 Arrays, 4-13, 4-14, 19-3 ASC function, 4-22, 18-3 C 128 Mode, 2-3 ASCII character codes, 4-22, E-1 C64 Mode, 2-3 ASM, 12-8 Caps Lock key, 5-19 Asterisk key (*), 3-20...
  • Page 442 Command keyword, 11 -8 Direct mode, 3-3 Command line, 11 -8 Command tail, 11 -8 DIRECTORY, 3-31, 17-23 DIRSYS, 14-4 Commodore key, 3-9, 3-10 Disk commands, 3-26, 10-5, L-1 Composite monitor, 8-4 Disk directory, 3-31, 10-5 CO NCAT, 17-16 CO NIN, 14-7...
  • Page 443 HEX$, 18-7 HLP, 12-7 4 0 /8 0 Display key, 5-19, 8-3 HOME key, 3-9 FAST command, 5-16, 17-30 Hyperbolic functions, G-1 Features, FETCH, 17-30 File, 12-3 Filename, 12-4 File specifications, 12-4 IF.. THEN statement, 4-3, 17-39 File type, INITDIR, 14-5 FILE NO T FOUND, 3-30 Initializing, 10-6 FILTER, 7-22, 17-31...
  • Page 444 Operators, LOCATE, 17-46 arithmetic, 3-20, 19-5 LOGarithm function, 18-9 logical, 19-5 Loops, 4-5 order of, 3-21 LST, 14-7 relational, 4-5, 19-5 Machine language, J-1 PAINT, 6-4, 6-11, 17-51 Mathematics, 3-20, G-1 Parentheses, 3-21, 12-7 Memory maps, F -1. H-1 Password, 12-5 M ID$ function, 18-10 PATCH, 14-5 Mode switching chart, 2-5...
  • Page 445 Screen memory map, F-1 Scrolling, 5-15, 11 -3 RAM, 4-18, 11-5 Sector, 3-27 Random sounds, 7-9 Semicolon, 3-12 RCLR, 18-13 Serial port, C-4 RDOT, 18-14 SET, 14-5 READ, 4-11, 17-61 SETDEF, 13-3, 14-5 RECORD, 17-62 SGN function, 18-18 Relational operators, 4-5 Sharps (#), 7-19 REL, 12-8 Sheet music, 7-26...
  • Page 446 Strings, 3-13, 3-24 STR$ function, 4-23, 18-20 UNTIL statement, 5-3, 17-24 SUB, 12-8 Up arrow (J1) key, 3-21 SUBMIT, 14-5 Upper case/graphic set, 3-5, 9-3 Subroutine, 4-17 U pper/Low er case set, 3-5, 9-3 Subscripts, 4-13 USER, 12-5, 14-4 Subtraction, 3-20 User Number, 12-5 Sustain, 7-3, 7-13 User port, C-6...
  • Page 448 1 9 4 0 S t. S te v e n s - W o lu w e N .S .W . 2 0 6 6 B e lg iu m N e th e rla n d s A u s tra lia Commodore...

This manual is also suitable for:

128d

Table of Contents