Commodore 128 Programmer's Reference Manual

Commodore 128 Programmer's Reference Manual

Hide thumbs Also See for 128:

Advertisement

T .M .
cfl
COMMODORE
Programmer' s

Reference Guide

COMMODORE
BUSINESS MACHINES, INC.
B A N T A M
A Bantam Computer Book
C O M P U T E R
B O O K S

Advertisement

Table of Contents
loading

Summary of Contents for Commodore 128

  • Page 1: Reference Guide

    T .M . COMMODORE Programmer’ s Reference Guide COMMODORE BUSINESS MACHINES, INC. B A N T A M A Bantam Computer Book C O M P U T E R B O O K S...
  • Page 3 COMMODORE 128 PROGRAMMER’S REFERENCE GUIDE...
  • Page 4 ORCHESTRATING SYMPHONY MANUAL by The Waite Group/Dan Shafer by Winn L. Rosch PC-DOS/MS-DOS COM M ODORE 128 PROGRAM M ER’S User’s Guide to the M ost Popular Operating REFERENCE GUIDE System fo r Personal Computers by Commodore Business Machines, Inc.
  • Page 5 CO M M ODORE 128 PROGRAMMER’S REFERENCE GUIDE COMM ODORE BUSINESS MACHINES, INC. BANTAM BOOKS TORONTO • NEW YORK • LONDON • SYDNEY • AUCKLAND...
  • Page 6 COM M O D O RE 128 PROGRAMMER S REFERENCE GUIDE A Bantam Book / February 1986 Commodore 64 and Commodore 128 are registered trademarks o f Commodore Electronics. Ltd. CPIM and CPIM Plus Version 3.0 are registered trademarks o f Digital Research Inc.
  • Page 7: Table Of Contents

    B A SIC Building Blocks and BASIC 7.0 Encyclopedia C hapter 3 O ne Step Beyond Simple BASIC C hapter 4 C om m odore 128 G raphics Program m ing Chapter 5 M achine Language Chapter 6 H ow to Enter M achine Language Programs Into the...
  • Page 8 The Com m odore 128 O perating System Chapter 14 CP/M 3.0 on the Commodore 128 A l l Chapter 15 The Com m odore 128 and Com m odore 64 M em ory M aps Chapter 16 C l 28 H ardware Specifications Appendixes G lossary...
  • Page 9 Norman McVey The authors are deeply indebted to the many people who have contributed to the preparation of this book. Special thanks go to Jim Gracely of Commodore Publications, who reviewed the entire manuscript for technical accuracy and provided important...
  • Page 11: Introduction

    J___ _ INTRODUCTION...
  • Page 12 ■ Enhanced BASIC language As this Guide shows, the Commodore 128 has many other new or expanded capabilities and features. Those listed above, however, are the most significant when assessing the Commodore 128’s capabilities against those of the Commodore 64 and other microcomputers.
  • Page 13 RAM expansion to 256 or 640K with optional RAM expansion modules C64 MODE In C64 Mode, the Commodore 128 retains all the capabilities of the Commodore 64, thus allowing you to use the wide range of available Commodore 64 software.
  • Page 14: Hardware Components

    COMMODORE 128 CP/M MODE In CP/M M ode, an onboard Z80 microprocessor gives you access to the capabilities of Digital Research’s CP/M Version 3.0, plus a number of new capabilities added by Commodore. CP/M Mode features iclude: ■ Integral Z80 processor running at 2.04 MHz ■...
  • Page 15 The Commodore 128 system is designed as an upgrade to the Commodore 64. Accord­ ingly, one of the major features of the Commodore 128 design is hardware and software compatibility with the Commodore 64 when operating in C64 Mode. This means that in C64 Mode the Commodore 128 is capable of running Commodore 64 application software.
  • Page 16 2. Press 3. Turn com ­ 3. Turn com ­ RESET puter OFF, puter OFF, button. then ON. then ON. Figure I —I . C o m m o d o re 128 M ode Sw itching C h a rt...
  • Page 17 4. Turn com ­ 80 COL puter ON. BOOT BOOT. puter OFF. 3. Press 5. Press 5. Press RETURN. RETURN. RETURN. Figure I —I . C o m m o d o re 128 Mode Sw itching C h a rt (continued)
  • Page 18: C Hapter

    Commodore 128 Personal Computer. Since many of the design features of the Commodore 128 can be viewed from various aspects, it may be necessary to consult several different chapters to find the information you want.
  • Page 19 THE COMMODORE 128 OPERATING SYSTEM— Describes, with examples, the operating system (Kernal), which controls the functioning of the Commodore 128; includes the Kernal Jump Table, which lists the ROM entry points used to call the Kernal routines; defines each Kernal routine; defines the C128 Screen Editor.
  • Page 20 COMMODORE 128 C H A P T E R 15. COMMODORE 128 AND COMMODORE 64 MEMORY MAPS— Provides detailed memory maps for C l 28 and C64 modes. (The Z80 memory map is shown in Appendix K.) C H A P T E R 16.
  • Page 21: B A Sic Building Blocks And Basic 7.0 Encyclopedia

    B A S I C BUILDING BLOCKS AND BASIC 7.0 ENCYCLOPEDIA...
  • Page 22 NUMERIC MEMORY STORAGE: CONSTANTS, VARIABLES A N D ARRAYS There are three ways to store numeric information in Commodore BASIC. The first way is to use a constant. A constant is a form of memory storage in which the contents remain the same throughout the course of a program.
  • Page 23 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA which the contents vary or change throughout the course of a program. The last way to store information is to use an array, a series of related memory locations consisting of variables. Each of these three units of memory storage can have three different types of information or data assigned.
  • Page 24 If the exponent is positive, the decimal point moves to the right representing it in simple number notation. The Commodore 128 limits the size of floating-point numbers. The highest number you can represent in scientific notation is 1.70141183E + 38. If you try to represent a number larger than that, an OVERFLOW ERROR occurs.
  • Page 25 Assign a string a null value by omitting characters between the double quotes and follow the opening double quote directly with a closing double quote. Here are some examples of string constants: “ Commodore 128” “ q w erl2 3 4 !# $ % ()* .:,” “ ” (null string) “...
  • Page 26: C Hapter

    COMMODORE 128 3.679 (floating-point) Z% = 714 (integer) F$ = “ CELEBRATE THE COMMODORE 128” (string) A + Z% (floating-point) Count % = Count % + 1 (integer) “ SEEK A HIGHER LEVEL OF CONSCIOUSNESS” (string) G$ = H$ =...
  • Page 27 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA 10 DIM A(99) dimensions a one-dimensional floating-point array with 100 elements. The following are examples of two-, three- and four-dimensional integer arrays: 20 DIM B(9, 9) (100 elements) 30 DIM C(20,20,20) (9261 elements) 40 DIM D( 10,15,15,10) (30976 elements)
  • Page 28 This is usually done by assigning the value of the expression to a variable name. An operator is a special symbol the BASIC Interpreter in your Commodore 128 recognizes as representing an operation to be performed on the variables or constant data.
  • Page 29 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA A D D IT IO N ( + ) The plus sign ( + ) specifies that the operand on the right is added to the operand on the left. EXA M PLES: A + B + C X % + 1 BR + 10E-2...
  • Page 30: Relational Operators

    COMMODORE 128 EX A M P LE S: 10/2 6400/4 4E2/XR E X P O N E N T IA T IO N ( | ) The up arrow ( f ) specifies that the operand on the left is raised to the power specified by the operand on the right (the exponent).
  • Page 31: Logical Operators

    BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA evaluating the relationship between corresponding characters from left to right (see string operations). EXA M PLES: “ A ” < “ B ” result true (-1) “ X ” = “ YY ” result false (0) BB$ <...
  • Page 32 COMMODORE 128 The AND operation results in a 1 only if both bits are 1: 1 AND 1 = 1 0 AND 1 = 0 1 AND 0 = 0 0 AND 0 = 0 The OR operation results in a 1 if either bit is 1:...
  • Page 33 A < = B Logical NOT NOT K% (Integer T w o’s Complement) Logical AND JK AND 128 Logical OR PQ OR 15 T a b le 2 -2 H ierarch y o f O peratio ns P erfo rm ed on Expressions...
  • Page 34 This section of Chapter 2 lists BASIC 7.0 language elements in an encyclopedia format. It provides an abbreviated list of the rules (syntax) o f Commodore 128 BASIC 7.0, along with a concise description of each. Consult the Commodore 128...
  • Page 35 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA more detailed description of each command. BASIC 7.0 includes all the elements of BASIC 2.0. The different types of BASIC operations are listed in individual sections, as follows: C om m ands Statem ents: the commands used to edit, store and erase programs, and the BASIC program statements used in the numbered lines of a...
  • Page 36 COMMODORE 128 The boldface line that defines the format consists of the following elements: DLOAD “ program nam e” [,D0,U8] keyword argument additional arguments (possibly optional) The parts of the command or statement that must be typed exactly as shown are in capital letters.
  • Page 37 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA V ariab le 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.
  • Page 38 Select one of the 16 BASIC banks (default memory configurations), numbered 0-15 to be used during PEEK, POKE, SYS, and WAIT commands. BANK bank number Here is a table of available BANK configurations in the Commodore 128 memory: BANK CONFIGURATION...
  • Page 39 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA IF condition THEN BEGIN : statement statement statement BEND : ELSE BEGIN statement statement BEND EXAMPLE 10 IF X = 1 THEN BEGIN: PRINT “ X = 1 is True” 20 PRINT “ So this part of the statement is performed” 30 PRINT “...
  • Page 40 COMMODORE 128 BOOT “ GRAPHICS 1” , DO, U9 LOADS the binary program “ GRAPHICS 1” from unit 9, drive 0, and executes it. Draw box at specified position on screen BOX [color source], X I, Yl[,X 2,Y 2][,angle][,paint] where:...
  • Page 41 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA BSAVE Save a binary file from the specified memory locations BSAVE “ filenam e” [,Ddrive num ber][< O N I,U >device number] [,Bbank number],Pstart address TO Pend address where: ■ start address is the starting address where the program is SAVEd from end address is the last address + 1 in memory which is SAVEd This is similar to the SAVE command in the Machine Language MONITOR.
  • Page 42 COMMODORE 128 Character row (0-24) string String to print reverse Reverse field flag (0 = off, 1 = on) E X A M P LE : 10 COLOR 2,3: REM MULTI-COLOR 1 = RED 20 COLOR 3,7: REM MULTI-COLOR 2 = BLUE 30 GRAPHIC 3,1 30 CHAR 0,10,10, “...
  • Page 43 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA CIRCLE1, 60,40,20,18,,,,45 Draws an octagon. CIRCLE 1, 260,40,20,,,,.90 Draws a diamond. CIRCLE 1, 60,140,20.18,,,,120 Draws a triangle. CIRCLE 1, + 2, + 2,50,50 Draws a circle (two pixels down and two to the right) relative to the original coordinates of the pixel cursor.
  • Page 44 COMMODORE 128 COLLECT Free inaccessible disk space COLLECT [Ddrive num ber][<O N |,>U device] E X A M P LE : COLLECT DO Free all available space which has been incorrectly allocated to improperly closed files. Such files are indicated with an asterisk on the disk directory.
  • Page 45 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA Colors that are usable are in the range 1-16. CO LOR CODE COLOR CO LOR CODE COLOR Black Orange White Brown Light Red Cyan Dark Gray Purple Medium Gray Green Light Green Blue Light Blue Yellow...
  • Page 46 COMMODORE 128 Whenever a variable is used as a filename, as in the last example, the filename variable must be within parentheses. C O N T Continue program execution CONT COPY Copy a file from one drive to another within a dual disk drive. Copy one file to another with a different name within a single drive COPY [Ddrive num ber,]“...
  • Page 47 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA DCLEAR Clear all open channels on disk drive DCLEAR [Ddrive num ber][<O N |,>U device] EXA M P LE S: DCLEAR DO Clears all open files on drive 0, device number 8. DCLEAR D1,U9 Clears all open files (channels) on drive 1, device number 9.
  • Page 48 COMMODORE 128 DELETE Delete lines of a BASIC program in the specified range DELETE [first line] [-last line] EXA M PLES: DELETE 75 Deletes line 75. DELETE 10-50 Deletes lines 10 through 50, inclusive. DELETE-50 Deletes all lines from the beginning of the program up to and including line 50.
  • Page 49 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA DIRECTORY D1,U9,(A$) LISTS the filename stored in the variable A$ on device number 9, drive 1. Remember, when­ ever a variable is used as a filename, put the variable in parentheses. NOTE: To print the DIRECTORY of the disk in drive 0, unit 8, use the following example: LOAD“...
  • Page 50 COMMODORE 128 EX A M P LE S: This example performs the statements X = X -l 10 X = 25 and PRINT “ X = ” ;X until X = 0 . When X = Othe 20 DO UNTIL X = 0 program resumes with the PRINT “...
  • Page 51 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA DRAW Draw dots, lines and shapes at specified positions on the screen DRAW [color source] [,X1, Y l][T O X2, Y2] . . . where: Color source 0 = Bit map background 1 = Bit map foreground 2 = Multi-color 1 3 = Multi-color 2...
  • Page 52 COMMODORE 128 □VERIFY Verify the program in memory against the one on disk DVERIFY “ filename” [,Ddrive num ber][<O N |,>U device number] To verify Binary data, see VERIFY “ filename” ,8,1 format, under VERIFY command description. EX A M P LE S: DVERIFY “...
  • Page 53 All operations are speeded up considerably. Graphics may be used, but will not be visible until a SLOW command is issued. The Commodore 128 powers up in 1MHz mode. The DMA operations (FETCH, SWAP, STASH) must be performed at 1MHz (slow) speed.
  • Page 54 COMMODORE 128 FOR / T O / STEP / N E X T Define a repetitive program loop structure. FOR variable = start value TO end value [STEP increment] NEXT variable The logic of the FOR/NEXT statement is as follows. First, the loop variable is set to the start value.
  • Page 55 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA 20 GET B, C, D GET numeric variables B,C and D from the keyboard without waiting for a key to be pressed. GETKEY Receive input data from the keyboard, one character at a time and wait for a key to be pressed.
  • Page 56 GRAPHIC Select a graphic mode 1) GRAPHIC mode [,clear][,s] 2) GRAPHIC CLR This statement puts the Commodore 128 in one of the six graphic modes: M ODE DESCRIPTION 40-column text (default) standard bit-map graphics...
  • Page 57 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA HEADER Format a diskette HEADER “ diskname” [,1 i.d.] [,Ddrive number] [< O N |,> U d evice number] Before a new disk can be used for the first time, it must be formatted with the HEADER command.
  • Page 58 COMMODORE 128 IF expression THEN statements [:ELSE else-clause] THE IF . . . THEN statement evaluates a BASIC expression and takes one of two possible courses of action depending upon the outcome of the expression. If the expression is true, the statement(s) following THEN is executed. This can be any BASIC statement or a line number.
  • Page 59 20 KEY I, CHR$(I + 132):NEXT 30 FOR I = 2 to 8 STEP 2 40 KEY I, CHR$(I + 132):NEXT This defines the function keys as they are defined on the Commodore 64. Assigns a value to a variable [LET] variable = expression...
  • Page 60 (outside the quotes) and a number which acts as a device number to determine where the program is stored (disk or tape). If no number is supplied, the Commodore 128 assumes device number 1 (the Datassette tape recorder). EXA M PLES: LOAD Reads in the next program from tape.
  • Page 61 PRINTing RDOT(2). M O N ITO R Enter the Commodore 128 machine language monitor MONITOR See Chapter 6 for details on the Commodore 128 Machine Language Monitor. MOVSPR Position or move sprite on the screen 1) MOVSPR number,X,Y Place the specified sprite at absolute sprite coordinate X,Y.
  • Page 62 COMMODORE 128 4) MOVSPR number, angle # speed Move sprite at an angle relative to its current coordinate, in the clock­ wise direction and at the specified speed. where: number is sprite’s number (1 through 8) X,Y is coordinate of the sprite location.
  • Page 63 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA Conditionally branch to a specified program line number according to the results of the specified expression ON expression <G O T O /G O SU B> line # 1 [, line # 2 , . . .] E X A M P LE : 10 INPUT X:IF X <...
  • Page 64 PAINTing the circle where the coordinate assumes the background source. The Commodore 128 will only PAINT where the specified source in the PAINT statement is different from the source of the x and y pixel coordinate.
  • Page 65 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA 100 PAINT 1, 100;90 Paint the screen area 90° relative to and 100 pixels away from the current pixel cursor co­ ordinate. PLAY Defines and plays musical notes and elements within a string or string variable. PLAY “...
  • Page 66 COMMODORE 128 EX A M P LE S: PLAY “ VIO4T0U5X0CDEFGAB ’ Play the notes C ,D ,E ,F,G ,A and B in voice 1, octave 4, tune envelope 0 (piano), at volume 5, with the filter off. PLAY “ V 305T6U 7X 1#B$A W .CH D Q EIF...
  • Page 67 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA PR IN T# Output data to files PR IN T # file number[, print list] P R IN T # is followed by a number which refers to the data file previously OPENed. E X A M P LE : 10 OPEN 4,4 Outputs the data “...
  • Page 68 COMMODORE 128 The pound sign ( # ) reserves room for a single character in the output field. If the data item contains more characters than there are # signs in the format field, the entire field is filled with asterisks (*): no characters are printed.
  • Page 69 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA EXA M PLES: 10 PUDEF“ *” PRINT * in the place of blanks. 20 PUDEF“ < ” PRINT < in the place of commas. READ Read data from DATA statements and input it into a numeric or string variable) READ variable list This statement inputs information from DATA statements and stores it in variables, where the data can be used by the RUNning program.
  • Page 70 COMMODORE 128 This example opens an existing relative file called “ FILE” as file number 2 in line 10. Line 20 positions the relative file pointer at the first byte in record number 10. Line 30 actually writes the data, A$, to file number 2.
  • Page 71 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA RENUM BER,, 65 Starting at line 65, renumbers in increments of 10. Line 65 becomes line 10. If you omit a parameter, you must still enter a comma in its place. RESTORE Reset READ pointer so the DATA can be reREAD RESTORE [line#]...
  • Page 72 COMMODORE 128 50 INPUT “ DO YOU WANT TO RUN IT AGAIN (Y/N)” ;Z$:IF Z$ = “ Y ” THEN 10 60 STOP 100 INPUT“ ENTER ANOTHER NUMBER (NOT ZERO)” ;A 110 RESUME 20 This example traps a “ DIVISION BY ZERO ERROR” in line 20 if 0 is entered in line 15.
  • Page 73 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA SAVE Store the program in memory to disk or tape SAVE [“ filenam e” ][,device number][,EOT flag] EXA M PLES: SAVE Stores program on tape, without a name. SAVE “ HELLO” Stores a program on tape, under the name HELLO.
  • Page 74 COMMODORE 128 SCNCLR Clear screen SCNCLR mode number The modes are as follows: MODE NUMBER MODE 40 column (VIC) text bit map split screen bit map multi-color bit map split screen multi-color bit map 80 column (8563) text This statement with no argument clears the graphic screen, if it is present, otherwise the current text screen is cleared.
  • Page 75 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA SLOW Return the Commodore 128 to 1MHz operation SLOW SO UND Output sound effects and musical notes SOUND v,f,d[,dir][,m ][,s][,w ][,p] where: = voice (1..3) = frequency value (0..65535) = duration (0..32767) dir = step direction (0(up), l(down) or 2(oscillate)) default = 0 = minimum frequency (if sweep is used) (0..65535) default =...
  • Page 76 COMMODORE 128 Either of these parameters may be any color from 1 through 16. EXA M PLES: SPRCOLOR 3,7 Sets sprite multi-color 1 to red and multi-color 2 to blue. SPRCOLOR 1,2 Sets sprite multi-color 1 to black and multi-color 2 to white.
  • Page 77 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA PARAMETER DESCRIPTION number Sprite number (1-8) on/off Turn sprite on (1) or off (0) foreground Sprite foreground color (1-16) (default = sprite number) priority Priority is 0 if sprites appear in front o f objects on the screen. Priority is 1 if sprites appear in back of objects on the screen.
  • Page 78 COMMODORE 128 S S H A P E / GSHAPE Save/retrieve shapes to/from string variables SSHAPE and GSHAPE are used to save and load rectangular areas of bit map screens to/from BASIC string variables. The command to save an area of the bit map...
  • Page 79 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA GSHAPE A$, 120,20 Retrieves shape contained in string variable A$ and displays it at top left coordinate (120,20). GSHAPE B$,30,30,1 Retrieves shape contained in string variable B$ and displays it at top left coordinate 30,30. The shape is inverted due to the replacement mode being selected by the 1.
  • Page 80 COMMODORE 128 EXA M PLES: SYS 32768 Calls and executes the machine-language routine at location 32768 ($8000). SYS 6144,0 Calls and executes the machine-language routine at location 6144 ($1800) and loads zero into the accumulator. TEMPO Define the speed of the song being played...
  • Page 81 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA TRON Turn on error tracing TRON TRON is used in program debugging. This statement begins trace mode. When you RUN the program, the line numbers of the program appear in brackets before any action for that line occurs.
  • Page 82 COMMODORE 128 EXA M PLES: WAIT 1, 32, 32 WAIT 53273, 2 WAIT 36868, 144, 16 W ID T H Set the width of drawn lines WIDTH n EXA M PLES: WIDTH 1 Set single width for graphic commands WIDTH 2...
  • Page 83 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA Return absolute value of argument X A B S (X ) E X A M P LE : PRINT ABS (7*(-5)) Return CBM ASCII code for the first character in X$ ASC(X$) This function returns the CBM ASCII code of the first character of X$.
  • Page 84 COMMODORE 128 H ere’s how the sprite numbers and BUMP values that are returned correspond: BUMP Value: Sprite Number: EXA M P LE S: PRINT BUMP (1) 12 indicates that sprites 3 and 4 have collided. PRINT BUMP (2) 32 indicates the sprite 6 has collided with an object on the screen.
  • Page 85 Return starting position of string 2 within string 1 INSTR (string 1, string 2 [,starting position]) E X A M P LE : PRINT INSTR (“ COMMODORE 128” ,“ 128” ) IN T Return integer form (truncated) of a floating point value INT(X) This function returns the integer value of the expression.
  • Page 86 JOY returns postion of joystick 2. Any value of 128 or more means that the fire button is also pressed. To find the joystick position if the fire button is pressed subtract 128 from the JOY value. The direction is indicated as follows.
  • Page 87 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA Return the length of a string LEN (string) The returned integer value is in the range 0-255. EXAMPLE: PRINT LEN (“ COMMODORE 128” ) Return natural log of X LOG(X) The argument X must be greater than 0. EXAMPLE: PRINT LOG (37/5) 2.00148...
  • Page 88 COMMODORE 128 Return X and Y coordinates of the light pen PEN(n) where n = 0 PEN returns the X coordinate of light pen position on any VIC screen, n = 1 PEN returns the Y coordinate of light pen position on any VIC screen,...
  • Page 89 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA Return the current cursor column position within the current screen window POS(X) The POS function indicates where the cursor is within the defined screen window. X is a dummy argument, which must be specified, but the value is ignored. The values returned range from 0-39 on the VIC screen and 0-79 on the 80-column screen.
  • Page 90 COMMODORE 128 SO U R CE DESCRIPTION 40-column background bit map foreground multi-color 1 multi-color 2 40-column border 40- or 80-column character color 80-column background color The counterpart to the RCLR function is the COLOR command. EX A M P LE : 10 FOR I = 0 TO 6 20 PRINT “...
  • Page 91 BASIC BUILDING BLOCKS AN D BASIC 7.0 ENCYCLOPEDIA GRAPHIC MODE VALUE 40 column (VIC) text Standard bit map Split screen bit map Multi-color bit map Split screen Multi-color bit map 80 column (8563) text E X A M P LE : PRINT RGR(O) Displays the current graphic mode;...
  • Page 92 COMMODORE 128 RSPCOLOR Return sprite multicolor values RSPCOLOR (X) When: RSPCOLOR returns the sprite multi-color 1. RSPCOLOR returns the sprite multi-color 2. The returned color value is a value between 1 and 16. The counterpart of the RSPCOLOR function is the SPRCOLOR statement.
  • Page 93 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA RSPRITE Return sprite characteristics RSPRITE (sprite number,characteristic) RSPRITE returns sprite characteristics that were specified in the SPRITE command. Sprite number specifies the sprite (1-8) you are checking and the characteristic specifies the sprite’s display qualities as follows: RSPRITE RETURNS CH ARA CTERISTIC...
  • Page 94 E X A M P LE : PRINT SIN .866025404 Skip spaces on printed output SPC (X) E X A M P LE : PRINT “ COMMODORE” ;SPC(3);“ 128” COMMODORE Return square root of argument SQR (X) E X A M P LE : PRINT SQR(25)
  • Page 95 PRINT STR$(1E20) IE + 20 Moves cursor to tab position in present statement TAB (X) E X A M P LE : 10 PRINT“ COMM ODORE” TAB(25)“ 128” COMMODORE TA N Return tangent of argument in radians TAN(X) This function returns the tangent of X, where X is an angle in radians E X A M P LE : PRINT TA N (.785398163)
  • Page 96 X = XOR (nl,n2) where n l, n2, are 2 unsigned values (0-65535) E X A M P LE : PRINT XOR( 128,64) RESERVED SYSTEM WORDS (KEYWORDS) This section lists the words used to make up the BASIC 7.0 language. These words cannot be used within a program as other than a component of the BASIC language.
  • Page 97 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA DELETE HELP SPRCOLOR HEX$ PRINT SPRDEF APPEND DIRECTORY PRINT# SPRITE DLOAD INPUT PUDEF SPRSAV INPUT# (QUIT) AUTO DOPEN INSTR RCLR SSHAPE DRAW BACKUP RDOT BANK READ STASH BEGIN RECORD STEP BEND DSAVE LEFTS STOP...
  • Page 98 TI and TI$ 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 TI$. The variable TI gives the current value of the clock in l/60th of a second.
  • Page 99 BASIC BUILDING BLOCKS A N D BASIC 7.0 ENCYCLOPEDIA S Y M B O L USE(S) Period Decimal point in floating-point constants Semicolon Format output in variable lists; delimiter > Colon Separate multiple BASIC statements on a program line Quotation mark Enclose string constants Question mark Abbreviation for the keyword PRINT...
  • Page 101: O Ne Step Beyond Simple Basic

    ONE STEP BEYOND SIMPLE B A S I C...
  • Page 102 COMMODORE 128 ■ This chapter takes you one step beyond simple BASIC and presents a collection of useful routines. You can incorporate these routines into your own programs as needed. In most cases the routines will require only line number changes to be fitted into your programs.
  • Page 103 ONE STEP BEYOND SIMPLE BASIC BUFFER ROUTINE The C l 28 keyboard buffer can hold and dispense up to ten characters from the keyboard. This is useful in a word processing program where it is possible at certain moments to type faster than the software can actually process. The characters that haven’t been displayed yet are temporarily stored in the keyboard buffer.
  • Page 104 COMMODORE 128 C O L O R 4 , 1 : C O L O R 0 , 1 : C O L O R 5 , 1 A $ = " P I C T U R E "...
  • Page 105 ONE STEP BEYOND SIMPLE BASIC C H A N G IN G FU N C T IO N KEYS You can change the value assigned to any function key by entering the KEY command followed by the number (1 through 8) of the key you want changed, a comma, and the new key instruction in a string format.
  • Page 106 COMMODORE 128 USING MULTIPLE INSTRUCTIO NS Colons allow you to place several instructions within a single program line. Each program line consumes additional memory. Be careful, however, crunching IF state­ ments. Any instruction after the IF statement with the same line number can be bypassed along with the IF .
  • Page 107 ONE STEP BEYOND SIMPLE BASIC USING B A S I C INTELLIGENTLY If information is used repeatedly, store the data in integer arrays, if possible. Use DATA statements where feasible. Where a similar line is used repeatedly, create a single line with variables and access it with GOSUBs.
  • Page 108 To turn on a bit, place a “ 1” in its position. To turn it off, enter a “ 0 ” . Hence the binary 10010000 has bits 4 and 7 on. Their values are 128 and 16. So if a particular byte is POKED with 144 (1 2 8 + 1 6 ), these two bits are turned on.
  • Page 109 ONE STEP BEYOND SIMPLE BASIC byte in question with an operand byte of all ON bits except the bit you want turned off. Bits to remain on will not be affected. To turn off bit 5, AND the byte in question with the mirror image of 00100000 or the operand byte 11011111.
  • Page 110 COMMODORE 128 USING PRINT A N D STOP Insert STOP statements within your program prior to the suspect instruction line. Good locations are at the end of specific tasks. Run the program. After the STOP statement puts you into direct mode, use the PRINT command to identify clues to the problem by determining the values of the various variables, especially those within loops.
  • Page 111 Some errors can only be found by acting like the computer and methodically following each instruction step-by-step, and then doing all the calculations until you discover something wrong. Fortunately the Commodore 128 can trace errors for you. Enter the direct command TRON prior to running a program. The program displays each line number as they occur in brackets, followed by each result.
  • Page 112 HOME key twice. This is useful if you have a listing on the main screen and wish to keep it while you display something else in a window. See Chapter 13, the Commodore 128 Operating System, under the screen editor for special ESCape controls within a window.
  • Page 113 Row 2 (770 Hz) Row 3 (852 Hz) Row 4 (941 Hz) To generate these tones in BASIC with your Commodore 128, follow this procedure: Initialize the sound (SID) chip with the following BASIC statements: SID = 54272 POKE SID 2 4 .15:POKE SID +...
  • Page 114 PROGRAMMING THE TELEPHONE T O BE O N OR OFF THE H O O K To program the phone to be off the hook using a Commodore 128, enter the following statements in a program: OH = 56577:HI = 32:LO = 255 - 32...
  • Page 115 Since a caller may forget to hang up, your program should monitor the transmit and receive data lines. If there is no activity for five minutes or so, the modem itself should hang up. To detect carrier on the Commodore 128, the following statement can be used in a BASIC program: OH = 56577: IF ((PEEK (OH) AND 16) = 0) THEN PRINT “...
  • Page 116 10160 PRINT CHR$(27) + “ @ ” (See the Screen Editor section of Chapter 13 for all the escape and control codes available on the Commodore 128.) RELOCATING BASIC To relocate the beginning or ending of BASIC (in C128 mode) for additional memory or to protect machine-language programs from being overwritten by BASIC text, it is necessary to redefine the starting and ending pointers in required memory addresses.
  • Page 117 ONE STEP BEYOND SIMPLE BASIC MERGING PROGRAM A N D FILES Files can be merged (combined) by opening an existing file and locating the pointer to the end of the file so subsequent data can be written to the disk file. C l28 BASIC has included the APPEND command to accomplish this: A PPEN D #5, “...
  • Page 119: Commodore 128 Graphics Programming

    COMMODORE 128 GRAPHICS PROGRAMMING HOW TO USE GRAPHICS SYSTEM T H E...
  • Page 120 VIC II (Video Interface Controller) chip (8564)— similar to that used in the Commodore 64— mixes all of the colors of the spectrum in a single signal to the video monitor. The 8563 separates the colors red, green and blue to drive separate cathode ray guns within the video monitor for a cleaner, crisper and sharper image than composite video.
  • Page 121 The Commodore 128 normally operates in standard character mode. When you first turn on the Commodore 128, you are automatically in standard character mode. In addition, when you write programs, the C128 is in standard character mode. Standard character mode displays characters in one of sixteen colors on a background of one of sixteen colors.
  • Page 122 Commodore 128 memory. Normally, character information is taken from character memory stored in a separate chip called ROM (Read Only Memory). However, the Commodore 128 gives you the option of designing your own characters and replacing the original characters with your own. Your own programmable characters are stored in RAM.
  • Page 123 COMMODORE 128 GRAPHICS PROGRAMMING CO M M AND SUMMARY Following is abrief explanation of each graphics command available in BASIC 7.0: B O X : Draws rectangles on the bit-map screen C H A R : Displays characters on the bit-map screen...
  • Page 124 COMMODORE 128 EXA M P LE S: C O L O R 0 , 1 : C O L O R 1 , 6 : C O L O R 4 , 1 G R A P H I C...
  • Page 125 COMMODORE 128 GRAPHICS PROGRAMMING CHAR Display characters at the specified position on the screen. CHAR [color source],X,Y[,string][,RVS] This is primarily designed to display characters on a bit mapped screen, but it can also be used on a text screen. Here’s what the parameters mean:...
  • Page 126 COMMODORE 128 CIRCLE1, 260,40,20,,,,,90 Draws a diamond. CIRCLE 1, 60,140,20,18,,,, 120 Draws a triangle. C IR C LE1,+ 2 ,+ 2,50,50 Draws a circle (two pixels down and two to the right) relative to the original coordinates of the pixel cursor.
  • Page 127 COMMODORE 128 GRAPHICS PROGRAMMING CO LO R CODE COLOR COLOR CODE COLOR Black Orange Brown White Light Red Cyan Dark Gray Medium Gray Purple Green Light Green Light Blue Blue Light Gray Yellow C o lo r Codes in 40-C olum n (V IC ) O u tp u t...
  • Page 128 COMMODORE 128 where: color source 0 Bit map background 1 Bit map foreground 2 Multi-color 1 3 Multi-color 2 X I,Y l Starting coordinate (0,0 through 319,199) (scaled) X2,Y2 Ending coordinate (0,0 through 319,199) (scaled) EX A M P LE S: DRAW 1, 100, 50 Draw a dot.
  • Page 129 COMMODORE 128 GRAPHICS PROGRAMMING GRAPHIC Select a graphic mode. 1) GRAPHIC mode [,clear][,s] 2) GRAPHIC CLR This statement puts the Commodore 128 in one of the six graphic modes: MODE DESCRIPTION 40-coluinn text standard bit map graphics standard bit map graphics (split screen)
  • Page 130 COMMODORE 128 where: string Contains shape to be drawn Top left coordinate (0,0 through 319,199) telling where to draw the shape (scaled— the default is the pixel cursor) mode Replacement mode: 0 = place shape as is (default) 1 = invert shape...
  • Page 131 COMMODORE 128 GRAPHICS PROGRAMMING where: color source 0 Bit map background 1 Bit map foreground (default) 2 Multi-color 1 3 Multi-color 2 X ,Y starting coordinate, scaled (default at pixel cursor (PC)) mode 0 = paint an area defined by...
  • Page 132 COMMODORE 128 10 GRAPHIC 1,3 Enter multi-color mode, turn scaling 20 SCALE 1,1000,5000 on to size (1000,5000) and draw a 30 CIRCLE 1,180,100,100,100 circle. SSHAPE Save shapes to string variables. SSHAPE and GSHAPE are used to save and load rectangular areas of multi-color or bit mapped screens to/from BASIC string variables.
  • Page 133 ______ MACHINE LANGUAGE ON THE COMMODORE 128...
  • Page 134 Every computer has its own machine language. The type of machine language depends on which processor is built into the computer. Your Commodore 128 understands 8502 machine language, which is based on 6502 machine language, to carry out its opera­...
  • Page 135 MACHINE LANGUAGE O N THE COMMODORE 128 Programs such as those used in arcade games cannot operate in the relatively slow speed of BASIC, so they are written in machine language. Other instances dictate the use of machine language simply because those programming operations are handled better than in a high-level language like BASIC.
  • Page 136 Addresses in your computer are necessary so they can receive, store and send (LOAD) data back and forth to the microprocessor. When you use the Commodore 128’s built-in machine-language monitor, all numbers and addresses default to hexadecimal numbers, but they can be represented in decimal, octal or binary.
  • Page 137: Chapter 5 M Achine Language

    You have learned that an address is a reference to a specific memory location among the 2 banks of RAM within the Commodore 128. Separate and independent of those RAM locations are special purpose work and storage areas within the microprocessor chip itself, called registers.
  • Page 138 COMMODORE 128 For example, if you want to store a value within one of the RAM locations, you must first load the value into the accumulator (or the X or Y register) and then store it into the specified RAM location. You cannot store a value directly into RAM, without placing it into the accumulator or the index registers first.
  • Page 139 M ACHINE LANGUAGE ON THE COMMODORE 128 All mathematical operations are performed within the arithmetic logic unit (ALU) and stored in the accumulator. It is considered a temporary mathematical work area. For example, you want to add two numbers, 2 + 3. First, load the accumulator with the 2.
  • Page 140 COMMODORE 128 The BASIC example above places a 0 in locations (addresses) 1024 through 1034. Line 10 sets up a loop from memory locations 1024 to 1034. Line 20 POKEs the value 0 into the location specified by I. The first time through the loop, I equals 1024. The second time through the loop, I equals 1025 and so on.
  • Page 141 MACHINE LANGUAGE ON THE COMMODORE 128 [ N 1 j 1 B j D 1 I | Z~|C] PROCESSOR STATUS REG "P" (-► CARRY 1 = TRUE ----- ZERO 1 = RESULT ZERO -----------► IR Q DISABLE 1 = DISABLE --------------- ►...
  • Page 142 Then they are decoded and executed. TH E STACK POINTER Within the RAM of the Commodore 128 is a temporary work area called the stack. It starts at location decimal 256 and ends at location 511 (hex $100 to $1FF). This area of computer RAM is referred to as page 1.
  • Page 143 16-BIT ADDRESSING: THE CONCEPT OF PAGING The Commodore 128 contains 128K of Random Access Memory (RAM). This means you have two banks of 65536 (64K) RAM memory locations (minus two for locations 0 and 1, which are always present in a RAM bank). Since the 8502 is an 8-bit micropro­...
  • Page 144 2° One binary byte The byte in decimal = 128 + 64 + 0 Figure 5 -5 . B in ary/D ecim al Conversion Remember, only add the values of two raised to the bit position if the bit is set.
  • Page 145 The low byte contains the value 100 decimal. The low byte value is added to the high byte to find the actual, or effective address. When you look at the memory map of your Commodore 128, you will see references to the low byte and high byte pointers or vectors to certain machine-language routines within the operating system or to important system memory locations, like the start of BASIC.
  • Page 146 COMMODORE 128 HEXADECIMAL N O TA TIO N Your 8502 microprocessor only understands the binary digits 0 and 1. Although machine language usually requires hexadecimal notation and BASIC processes decimal numbers, those numbers are translated and processed as binary numbers. Your computer uses three different number systems, binary (base 2), hexadecimal (base 16) and decimal (base 10).
  • Page 147 MACHINE LANGUAGE O N THE COMMODORE 128 BINARY HEXADECIMAL DECIMAL 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Figure 5-7 . H e xa d ecim al/D ecim al/B in ary Conversion Each hex digit represents four bits.
  • Page 148 COMMODORE 128 A CCU M ULA TO R ADDRESSING Accumulator addressing implies that the specified operation code operates on the accumulator. The operand field is omitted since the instruction can only perform the operation on the accumulator. Accumulator instructions require only one byte of stor­...
  • Page 149 MACHINE LANGUAGE ON THE COMMODORE 128 INSTRUCTION HEX OPCODE MEANING Increment the contents of address $4FFC by 1 INC $4FFC LDX $200C Load the X register with the contents of address $200C Jump to location $FFC3 and save the return address...
  • Page 150 COMMODORE 128 RELATIVE ADDRESSING Relative addressing is used exclusively with branch instructions. The branch instructions (BEQ, BNE, BCC, etc.) allow you to alter the execution path depending on a particular condition. Branch instructions are similar to IF . . . THEN statements in BASIC since they both conditionally perform a specified set of instructions.
  • Page 151 The offset ranges from -128 through 127. If the condition of the branch is met, the offset is added to the program counter and the program branches to the address in memory.
  • Page 152 00,000. This example shows just one way to modify addresses with the index registers. The Commodore 128 has four indexed addressing modes: (1) indexed absolute address­ ing (illustrated in the example just shown), (2) indexed zero-page addressing, (3) indexed indirect addressing, and (4) indirect indexed addressing.
  • Page 153 MACHINE LANGUAGE ON THE COMMODORE 128 IN D E XE D ABSOLUTE ADDRESSING Indexed absolute addressing allows you to access and modify any of the memory locations in each of the two 64K banks. The effective address is calculated by adding the contents of the index register (X or Y) to the high and low byte base address determined by the operand.
  • Page 154 Indirect X addressing is useful in addressing a series of pointers such as the zero-page memory of the Commodore 128. IN D IRECT IN D E XE D ADDRESSING This mode, also called indirect Y addressing, is post-indexed, which means the adding o f the index itself obtains the effective address.
  • Page 155 X indexing, which is indexed prior to the arrival of the effective address. Indirect indexed is post-indexed with the Y register. You have just covered all the addressing modes in the Commodore 128. Each calls for different circumstances and you should use the correct mode whenever circum­...
  • Page 156 COMMODORE 128 Use this information as a reference for background on each instruction. Figure 5-9 provides an alphabetized list of the 8502 microprocessor op-code mnemonics. For detailed, quick-reference information, see the following section for an alphabetic list of instructions, their hexadecimal op-codes, the different versions of the instructions for each addressing mode and the way they affect the flags in the status register.
  • Page 157 MACHINE LANGUAGE ON THE COMMODORE 128 8502 M ICROPROCESSOR INSTRUCTION S E T - ALPHABETIC SEQUENCE (cont’d) “ O R ” Memory with Accumulator Push Accumulator on Stack Push Processor Status on Stack Pull Accumulator from Stack Pull Processor Status from Stack...
  • Page 158 COMMODORE 128 LDA $2000 This instruction loads the contents of the memory location $2000 (8192 decimal) into the accumulator. The value in the memory location $2000 remains the same. The value also remains in the accumulator until another value is placed there or another operation acts upon it.
  • Page 159 MACHINE LANGUAGE ON THE COMMODORE 128 series of addresses. The counter instruction, INC, increments the contents of a memory address by a value of 1 each time it is encountered. These instructions are used primarily within a program loop and in conjunction with a branch instruction. Here’s an example...
  • Page 160 COMMODORE 128 COMPARE INSTRUCTIONS The Commodore 128 has three compare instructions that check the contents of a register with the contents of memory. A compare operation can be used to determine which instructions to execute as a result of a conditioned value. The compare instructions are: The CMP instruction compares the contents of the accumulator with the contents of the specified address in the instruction.
  • Page 161 MACHINE LANGUAGE ON THE COMMODORE 128 Remember, if you want to compare numbers larger than eight bits can represent (greater than 255 decimal), you must separate the number into a low byte and a high byte. The BIT instruction can also be used for comparisons. See the logical instructions next.
  • Page 162 COMMODORE 128 This program segment essentially performs the following mathematical operation: (10 + 4 )- 6 + 10= 18. The first instruction clears the carry bit. The second instruction loads the accumu­ lator with $0A (10 decimal). The third instruction stores the value in address $FB for later use.
  • Page 163 M ACHINE LANGUAGE O N THE COMMODORE 128 If either of the operands equals 1, the resulting Boolean value is 1, except if both operands are 1, then the result equals 0. Here’s an example using this rule: Contents of Memory Address = 10101001...
  • Page 164 COMMODORE 128 ________ B D I Z C Contents of Memory Address = 01111010 _______________ Contents of Accumulator = 10000100 — > 0 Result of BIT instruction = 00001000 Status Register This time the bit patterns result in 0. Therefore, the zero flag in the status register is set to 1.
  • Page 165 MACHINE LANGUAGE ON THE COMMODORE 128 B C C — (Branch on Carry Clear) Branch if the Carry flag in the status register equals 0. BCS— (Branch on Carry Set) Branch if the Carry flag in the status register equals 1.
  • Page 166 COMMODORE 128 with an 8563 register number, into the 8563 address register. The BIT instruction places bit 7 of location $D600 into the negative flag in the 8502 status register. The BPL instruction branches to the BIT instruction in location $ 185B as long as the value of the negative flag is equal to 0.
  • Page 167 MACHINE LANGUAGE ON THE COMMODORE 128 flag. If the carry flag is enabled (1), then the joystick is being pushed in the direction corresponding to that bit. Here is a joystick read routine that uses the LSR instruction to evaluate the direction of the joystick: R E A D Y .
  • Page 168 COMMODORE 128 SET A N D CLEAR INSTRUCTIONS The set and clear instructions are designed to manipulate the bits (flags) within the status register and control certain conditions within the microprocessor. These are the set and clear instructions available in 8502 machine language:...
  • Page 169 M ACHINE LANGUAGE O N THE COMMODORE 128 adding two numbers in the accumulator. To perform mathematical operations in hexa­ decimal or binary numbers, clear the decimal mode flag so that your calculations are not mistakenly performed in binary coded decimal. W henever the result of a signed mathe­...
  • Page 170 COMMODORE 128 0 1 8 5 8 S T X $ D 6 0 0 0 1 8 5 B $ D 6 0 0 B I T 0 1 8 5 E B P L $ 1 8 5 B...
  • Page 171 M ACHINE LANGUAGE ON THE COMMODORE 128 8502 INSTRUCTION AND ADDRESSING TABLE The next 16 pages contain the 8502 Instruction and Addressing Table. These are the conventions used in the table: OP-CODE Brief definition Operation notation Status flags Flags affected...
  • Page 172 COMMODORE 128 A D C A D C Add memory accumulator with carry Operation: + C - ^ A , C N E C I ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE BYTES CYCLES Immediate # Oper Zero Page Oper Zero Page, X...
  • Page 173 MACHINE LANGUAGE ON THE COMMODORE 128 A S L A S L ASL S h ift L e ft O n e B it (M e m o r y o r A c c u m u la to r) Operation: C [7 |6 |5 |4 |3 |2 lH o 1 <...
  • Page 174 COMMODORE 128 B ranch on result ze ro Operation: Branch on Z = 1 ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE BYTES CYCLES Relative Oper * Add if branch occurs to same page. * Add 2 if branch occurs to next page.
  • Page 175 MACHINE LANGUAGE ON THE COMMODORE 128 B ranch on result plus Operation: Branch on N = 0 ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE BYTES CYCLES Relative BPL Oper * Add 1 if branch occurs to same page. * Add 2 if branch occurs to different page.
  • Page 176 COMMODORE 128 C L C C LC C le a r c a rry fla g Operation: O ^ C ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE BYTES CYCLES Implied C L D C le a r d ec im al m ode...
  • Page 177 MACHINE LANGUAGE ON THE COMMODORE 128 C M P C M P C M P C o m p a re m e m o ry and a c c u m u la to r Operation: A - M...
  • Page 178 COMMODORE 128 D E C D E C D e c re m e n t m e m o ry by one D E C Operation: M - 1 — > M N Z C I ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE;...
  • Page 179 MACHINE LANGUAGE ON THE COMMODORE 128 IN C IN C IN C In c re m e n t m e m o ry by one Operation: M + 1 — > M ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE BYTES...
  • Page 180 COMMODORE 128 JSR Jump to new location saving return address Operation: PC + 2 j , (PC + 1) -> PCL (PC + 2) -> PCH ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE BYTES CYCLES Absolute Oper L D A LDA Load accumulator with memory...
  • Page 181 MACHINE LANGUAGE O N THE COMMODORE 128 L D Y L D Y Load in d e x Y w ith m e m o ry L D Y Operation: M — > Y ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE...
  • Page 182 COMMODORE 128 O R A O R A O RA " O R ” m e m o ry w ith a c c u m u la to r Operation: A V M - » A ASSEMBLY ADDRESSING CODE :...
  • Page 183 MACHINE LANGUAGE ON THE COMMODORE 128 PLP P u ll processor status fro m stack Operation: P f From Stack ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE BYTES CYCLES Implied R O L R o ta te one b it le ft (m e m o ry o r a c c u m u la to r)
  • Page 184 COMMODORE 128 R T I R T I R eturn fro m in te rru p t P f P C f Operation: From Stack ASSEMBLY ADDRESSING MODE LANGUAGE FORM CODE BYTES CYCLES Implied RTS R eturn fro m subroutine PC f , PC + 1 —...
  • Page 185 M ACHINE LANGUAGE O N THE COMMODORE 128 SEC S et c a rry flag Operation: 1 — » C ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE BYTES CYCLES Implied SED Set d ec im al mode Operation: 1 — *...
  • Page 186 COMMODORE 128 S T X S T X STX Store ind ex X in m e m o ry Operation: X — > M ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE BYTES CYCLES Zero Page Oper Zero Page, Y Oper, Y...
  • Page 187 M ACHINE LANGUAGE O N THE COMMODORE 128 T S X TSX Transfer stack pointer to index X T S X Operation: S ADDRESSING ASSEMBLY MODE LANGUAGE FORM CODE BYTES CYCLES Implied T X A TXA Transfer index X to accumulator...
  • Page 188 COMMODORE 128 INSTRUCTION ADDRESSING MODES AND RELATED EXECUTION TIMES (in clock cycles) x > * < < < Q > £ 3 J O y : — J < os c* < '—- <...
  • Page 189 M ACHINE LANGUAGE ON THE COMMODORE 128 & > >- > < w" e> < < < > fie; < C /j C /5 C /3 C S2 < < < * Add one cycle if indexing across page boundary ** Add one cycle if branch is taken.
  • Page 191: Machine Language

    6 ________ HOW TO ENTER MACHINE LANGUAGE PROGRAMS INTO THE COMMODORE 128...
  • Page 192 Commodore 128 memory. The C l 28 offers three methods of inputting instructions so that they may be operated on by the microprocessor. You can enter machine language instructions by: Using the built-in machine language monitor (available in C l 28 mode only).
  • Page 193 Commodore 128 memory. Notice the 5-digit hexadecimal number specifying the address. The leftmost digit (0-F) speci­ fies the configuration of the Commodore 128 memory layout. This is the same as the BANK command in BASIC.
  • Page 194 COMMODORE 128 appears in the first instruction you entered. You must have an RTS instruction at the end of the routine if you want to return to BASIC. Often, the Kernal must be resident in the current configuration in context in order to obtain results.
  • Page 195: H Ow To Enter M Achine Language Programs Into The C Om M Odore 128

    H O W T O ENTER MACHINE LANGUAGE PROGRAMS IN TO THE COMMODORE 128 pressing the X key and R E T U R N . This places you back within the control of the BASIC language. Next, issue the SYS command and reference the starting address in...
  • Page 196 Compares memory with tape or “ < file n a n ie> ” [,< d evice # > [ , disk c lo a d address>]] EXIT Exits Commodore 128 MONITOR (period) Assembles a line of 8502 code > (greater than)
  • Page 197 NOTES < > enclose required parameters [] enclose optional parameters Figure 6 -1 . S u m m a ry o f C o m m o d o re 128 M o n ito r Com m ands N O TE: 5-Digit Addresses The Commodore 128 displays 5-digit hexadecimal addresses within the machine language monitor.
  • Page 198 COMMODORE 128 < n u ll> (default) precedes hexadecimal values. < d o llar> precedes hexadecimal (base-16) values. < p lu s > precedes decimal (base-10) values. & < am persand> precedes octal (base-8) values. < p ercen t> precedes binary (base-2) values.
  • Page 199 HO W T O ENTER MACHINE LANGUAGE PROGRAMS IN TO THE COMMODORE 128 COMMAND: PURPOSE: Compare two areas of memory. SYNTAX: <address 1> <address 2 > <address 3 > <address 1> A number indicating the start address of the area of memory to compare against.
  • Page 200 The GO command restores all registers (displayable by using the R command) and begins execution at the specified starting address. Caution is recommended in using the GO command. To return to the Commodore 128 MONITOR after executing a machine language program, use the BRK instruction at the end of the program.
  • Page 201 HO W TO ENTER MACHINE LANGUAGE PROGRAMS IN TO THE COMMODORE 128 subroutine located at the specified address. This command saves the return address as does the 8502 instruction JSR (Jump to Subroutine). In other words, the JUMP command is a two-way instruction, where the application gains control of the computer.
  • Page 202 < “ filenam e” > ,< d e v ic e > ,< a d d ress 1 > , <address 2 > < “ filename ” > Any legal Commodore 128 filename. To save the data, the file name must be enclosed in dou­...
  • Page 203 HO W T O ENTER MACHINE LANGUAGE PROGRAMS IN T O THE COMMODORE 128 The file created by this command is a program file. The first two bytes contain the starting address <address 1> of the data. The file may be recalled, using the L command.
  • Page 204 COMMODORE 128 COMMAND: PURPOSE: Exit to BASIC. SYNTAX: COMMAND: > (greater than) PURPOSE: Can be used to assign values for one to eight memory locations at a time (in 40-column mode; up to 16 in 80-column mode). SYNTAX: > < address> < data byte 1> < data byte 2 . .
  • Page 205 . Notice that the letter T is now displayed at the right of the screen. R E T U R N Refer to Appendix E, ASCII and CHR$ Codes, for a list of the Commodore ASCII codes for each character available in the Commodore 128.
  • Page 207: M Ixing M Achine Language And Basic

    MIXING MACHINE LANGUAGE AND B A S I C...
  • Page 208 COMMODORE 128 W H Y M IX B A S I C AND M ACHINE LANGUAGE? Certain application programs are better suited for a high-level language such as BASIC rather than low-level machine language. In other cases, however, certain portions of a program, such as displaying graphics, may require the speed of machine language while the rest of the program lends itself to the use of BASIC.
  • Page 209 M IX IN G MACHINE LANGUAGE A N D BASIC 1000 DATA 162,0: REM = LDX # $ 0 0 = $A2, $00 The hexadecimal number $A2 represents the 8502 instruction for LDX, which equals 162 in decimal. The 0 (zero) represents the operand 0, which is loaded into the X register in the instruction.
  • Page 210 COMMODORE 128 The second example, in C64 mode, uses a FO R . . . NEXT loop to enter the data. This requires you to know how many data items are in the data list. You can add an IF . . . TH EN statement to check for a terminator value like -9 9 9 , as in the first example.
  • Page 211 M IXIN G MACHINE LANGUAGE A N D BASIC Symbolic A ddress Hex O pcode Instruction Decimal Equivalent 1st Byte 2nd Byte 3rd Byte (O pcode) (Operand) L D X # $ 0 0 0 2 0 0 0 0 2 0 0 2 L D A # $ 2 0 0 2 0 0 4...
  • Page 212 Commodore 128 memory is layered, so RAM is beneath the overlaid ROM. The designers of the Commodore 128 have managed to squeeze 28K of ROM and 128K of RAM into 128K of address space. Only one bank is available or mapped in at a time, since the highest address an 8-bit microprocessor can address is 65535 ($FFFF).
  • Page 213 M IXIN G MACHINE LANGUAGE A N D BASIC Management Unit (MMU). For detailed information, refer to the sections on the Registers of the Memory Management Unit (specifically, the discussion of the Configu­ ration Register) in Chapter 13. WHERE TO PLACE MACHINE LANGUAGE ROUTINES IN C O N JU N C TIO N W ITH B A S I C Within BASIC, the operating system takes care of the mapping in and out of ROM and...
  • Page 214 COMMODORE 128 1. Place the subroutine, preferably in bank 0, either through the monitor or by POKEing in the code through BASIC. If the Kernal, BASIC, and I/O are required, execute your program from configuration (BASIC Bank) 15. If you enter the subroutine through the monitor, place the routine in bank 0 by placing the digit 0 before the 4-digit hexadecimal address where the instruc­...
  • Page 215 M IXIN G MACHINE LANGUAGE A N D BASIC via the BASIC command, so it becomes your responsibility to manage the memory configurations by manipulating the Configuration Register in your application program. Figure 13-5, on page 462, defines the values to place in the configuration register to arrive at the different memory configurations.
  • Page 216 •» •* *> «■...
  • Page 217 THE POWER BEHIND COMMODORE GRAPHICS...
  • Page 218 The Commodore 128 Operating System. TH E T W O 64K RAM BANKS The Commodore 128 memory is composed of two RAM banks (labeled 0 and 1), each having 64K of RAM, giving a total of 128K. The 8502 microprocessor address bus is 16 bits wide, allowing it to address 65536 (64K) memory locations at a time.
  • Page 219 THE POWER BEHIND COMMODORE 128 GRAPHICS BANK CONFIGURATION RAM(O) only R A M (l) only RAM(2) only (same as 0) RAM(3) only (same as 1) Internal ROM , RAM(O), I/O Internal ROM , R A M (l), I/O Internal ROM , RAM (2), I/O (same as 4)
  • Page 220 Where you place the VIC video bank depends on your application program. The Commodore 128 ROM operating system expects this bank in default video Bank 0, in the bottom of RAM Bank 0. Screen and character memory may be located at different positions within each 16K video bank, though in order to successfully program the VIC chip, the current 16K bank must contain screen and character memory in their entirety.
  • Page 221 THE POWER BEHIND COMMODORE 128 GRAPHICS video bank 3 video bank 2 video bank 1 video bank 0 video bank 3 video bank 2 video bank 1 video bank 0 Figure 8 -4 . V ideo Banks w ith in RA M Banks...
  • Page 222 The MMU chip, particularly the value in the configuration register, controls most of the memory management in the Commodore 128. In order to PEEK (read) from or POKE (write) to a particular portion of memory, you must choose a BASIC or monitor configuration that contains the desired section of memory.
  • Page 223 Users who are experienced in programming the Commodore 64 VIC chip will find that most of the graphics operations of the Commodore 128 are performed in the same way as the C64. The main difference between the Commodore 64 and the Commodore 128 graphics systems is the hardware implementation of split-screen modes.
  • Page 224: Screen Editor

    COMMODORE 128 You must store to and load from the indirect locations when accessing the above features of the VIC (8564) chip. For example, in C64 mode, this is how you set up the video matrix and bit map mode:...
  • Page 225 Since disabling the interrupt allows you to program the VIC chip in the same way as the Commodore 64, you can store values directly to the actual registers. You do not have to address the indirect storage locations for VIC chip programming. However, if you don’t disable the interrupt, it is still active and your values will be cleared upon the...
  • Page 226 15” in the POKE 2604 statement ensures that the lower nybble is not upset. (If it had been, you would not see the correct character data.) In Commodore 128 bit map mode (standard or multi-color), the default bit map screen memory (video matrix) is located between 7168 ($1C00) and 8167 ($1FFF).
  • Page 227 ($07E7). In bit map mode, the video matrix (screen memory) also defaults to this range though the screen memory is interpreted differently in either mode. Commodore 64 BASIC allows you to move the location of the video matrix to any one of the sixteen locations specified in Figure 8-6.
  • Page 228 COLOR RAM C l 28 BASIC Color RAM within the Commodore 128 is always stationary in memory. It occupies the address range 55296 ($D800) through 56295 (SDBE7). In standard character mode, screen RAM and color RAM correspond to one another on a one-to-one basis. Location 1024 gets color data from 55296, 1025 gets color from 55297 and so on.
  • Page 229 This is true in any of the four video banks in both 64K RAM banks. This feature allows the Commodore 128 character set to be available in any video bank at any time. To read the character ROM, enter BANK 14 either in BASIC or the MONITOR, and read the ROM, starting at location 53248.
  • Page 230 COMMODORE 128 The character memory is relocatable as is screen memory. To move standard character memory in C128 BASIC, alter the lower four bits (nybble) of location 2604 ($0A2C). Location 2604 is a shadow register for 53272 for the text screen memory (upper four bits) and character memory (lower four bits).
  • Page 231 THE POWER BEHIND COMMODORE 128 GRAPHICS C l 28 BASIC-BIT MAP MODES In bit map mode, the character memory data, also referred to as the bit map, defaults to the range 8192 ($2000) to 16191 ($3F3F). The bit patterns of these 8000 bytes tell the computer which pixels to turn on.
  • Page 232 COMMODORE 128 C64 BASIC-CHARACTER MODES In standard character mode in C64 BASIC, the lower four bits of location 53272 control where character memory is placed. As in C128 mode, the character ROM is actually mapped into memory between 53248 ($D000) and 57343 ($DFFF). The ROM image appears in RAM in the range 4096-8191 (in video bank 0) and 36864-40959 in bank 2, since it must be accessible to the VIC chip in a 16K range in video banks 0 and 2.
  • Page 233 THE POWER BEHIND COMMODORE 128 GRAPHICS M A C H IN E LANGUAGE There are three ways to select the placement of character memory, as shown in Figure 8-11. Example A places character memory using the shadow register $0A2C in place of the actual $D018 register.
  • Page 234 COMMODORE 128 SCREEN LO C A T IO N In standard character mode, the screen memory defaults to the range 1024 ($0400) through 2023 ($07E7). This is relocatable. See the Screen Memory section in the preceding pages. Since the screen is 40 columns by 25 lines, the text screen requires 1,000 memory locations to store all of the screen information in memory.
  • Page 235 THE POWER BEHIND COMMODORE 128 GRAPHICS different due to the way they are stored in the character ROM. Notice in Appendix D that the screen code for an at-sign (@) is 0. The @ is numbered 0 because it is the first character to be stored in the character ROM.
  • Page 236 COMMODORE 128 H O W COLOR MEMORY IS INTERPRETED The contents of the color RAM locations contains the color codes 0-15. Each color memory location may have a different color code. The lower four bits (nybble) of COLOR RAM are significant. Figure 8-14 shows the COLOR RAM color codes:...
  • Page 237 Upon power-up, the uppercase/graphics character set is available through the keyboard. To access the second character set, press the Commodore key ( O ) and shift key at the same time. The second character set is composed of the upper- and lowercase/graphics characters.
  • Page 238 COMMODORE 128 Note that there is really 8K of character ROM— 4K for C64 mode and 4K for C l 28 mode. The system automatically selects the appropriate character ROM for each mode of operation. The bit patterns stored in the character ROM have a direct relationship to the pixels on the screen, where the character is displayed.
  • Page 239 THE POWER BEHIND COMMODORE 128 GRAPHICS 2 ' + 22 + 25 + 26 = 102 The last byte of the at-sign character is equal to zero, since no bits are set. Therefore, each pixel on the screen is displayed in the background color. The values of the binary digits on the right in Figure 8-16 are directly related to the image of the character as it appears on the screen on the left in Figure 8-16.
  • Page 240 PROGRAMMABLE CHARACTERS The Commodore 128 has a feature that allows you to redefine the character set into custom characters of your own. In most cases, you'll want to redefine only a few characters at most, while obtaining the rest of the character set from the Commodore 128 character ROM.
  • Page 241 THE POWER BEHIND COMMODORE 128 GRAPHICS Standard Character Mode section, you saw how a character on the screen is stored in the character ROM. Each character requires eight bytes of storage. Each byte corresponds to a row of pixels on the visible screen within the 8 by 8 character matrix; therefore, eight rows of pixels make up one character.
  • Page 242 ROM share the same locations ($D000-$DFFF). Depending on whether bit 0 in the configuration register (location $FF00) is on or off, the C 128 addresses the I/O registers or the character ROM. Normally the C128 powers up with bit 1 turned off; therefore, the I/O registers in locations $D000-$DFFF are addressed.
  • Page 243 THE POWER BEHIND COMMODORE 128 GRAPHICS change the value back to the original one within a sixtieth of a second. (You can, how­ ever, disable the interrupt-driven screen editor. See the Shadow Register section for details.) The value (AND 240) or 12 is placed in address 2604 to tell the C l28 to point to character memory in RAM, starting at address 12288.
  • Page 244 COMMODORE 128 SCREEN LO C A TIO N The screen location in multi-color character mode defaults to 1024 ($0400) through 2023 ($07E7), the same as standard character mode. The screen memory locations can be relocated. See the Screen Memory section for details.
  • Page 245 THE POWER BEHIND COMMODORE 128 GRAPHICS 0 0 1 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 0 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0 0...
  • Page 246 COMMODORE 128 If the bit pair equals 00 (binary), the color of those two pixels corresponding to the bit pair are colored by background color register 0 (location 53281 ($D021)). If the bit pair equals 01 (binary), the pixels are colored by background color register 1 (location 53282 ($D022)).
  • Page 247 THE POWER BEHIND COMMODORE 128 GRAPHICS alphabet on the screen twenty-five times. Line 35 fills the last 512 bytes of color RAM with yellow. Line 37 disables the IRQ VIC screen editor. Line 40 enables multi-color mode. At this point, all the screen locations corresponding to the color RAM locations which have a color code greater than or equal to 8 are displayed in multi-color mode.
  • Page 248 COMMODORE 128 H O W T O INTERPRET SCREEN DATA The data in screen memory is interpreted as screen codes, which are actually the indexes into the character ROM. Instead of representing the data as ASCII characters, the screen codes represent the index into the character ROM which provide the ASCII codes. The first character in character ROM is the at sign (@);...
  • Page 249 THE POWER BEHIND COMMODORE 128 GRAPHICS However, in this mode, you can only represent the first sixty-four characters, since you only have five bits to represent screen characters. By trying to represent the screen code 65, bit 6 is enabled, which tells the computer to select the background color register 1 (location 53282 ($D022)), and display the same character, but with the extended background color specified by background color register 1.
  • Page 250 COMMODORE 128 X Coordinate 319,0 Y Coordinate 0,199 319,199 Figure 8 -2 4 . B it M ap Screen C oordinates H O W T O ENTER STANDARD BIT MAP MODE To enter standard bit map mode, set bit 5 of location 216 ($00D8) (the shadow register of location 53265 ($D011)).
  • Page 251 THE POWER BEHIND COMMODORE 128 GRAPHICS ($07E7). The video matrix can be moved, however. See the Screen Memory section elsewhere in this chapter for information on relocating the video matrix. VIDEO MATRIX IS INTERPRETED In bit map mode, the video matrix (bit map screen memory) is interpreted differently than it is in the character display modes.
  • Page 252 COMMODORE 128 The bit map tells the computer which pixels in the foreground to enable on the screen. Like a road map, it spells out exactly which pixels to turn on (in the foreground) and off (in the background color) in order to display a picture on the screen. For example, if the bit map started at location 8192 (the C l 28 BASIC default) the first byte of the bit map corresponds to the bit map pixel coordinates 0,0 through 0,7.
  • Page 253 POKE 216, PEEK (216) OR 160 This POKEs the value 160 and turns on the multi-color mode bit 7 (value 128) and the bit map mode bit 5 (value 32) in the GRAPHM register which interfaces to the C l 28 interrupt driven screen editor.
  • Page 254 COMMODORE 128 specific VIC registers. GRAPHM is one such register; therefore, every sixtieth of a second, the value in the GRAPHM register is loaded into the appropriate VIC registers. MACHINE LANGUAGE To select multi-color bit map mode in C l 28 machine language, perform the following instructions: LDA $A0;...
  • Page 255 C l 28. SPLIT-SCREEN MODES The Commodore 128 has a split-screen feature that allows you to display the top portion of the screen in bit map mode and the bottom portion in character mode. This allows you to...
  • Page 256 RUN it and see the immediate results without losing the text screen. Without the Commodore 128’s split-screen capabilities, you would have to pro­ gram a split screen yourself. This involves raster interrupts which utilize either two screen memories in two different video banks, or a fairly choppy single-screen memory, usually with a visible raster line.
  • Page 257 THE POWER BEHIND COMMODORE 128 GRAPHICS INTERPRETING SCREEN D A TA The text portion of the split screen is interpreted according to the standard character mode section. The bit map portion, whether standard or multi-color, is interpreted according to the description in the bit map mode section.
  • Page 258 C l 28 Mode. A few differ­ ences will occur in the timing of the raster. In Commodore 128 mode, all interrupts occur according to the position of the raster beam as it scans the screen. This is why shadow registers are necessary for certain graphics locations, since the C l 28 screen editor is interrupt driven to allow the split screen modes in BASIC.
  • Page 259 If you have a C128 assembler, create a source file, assemble and load it. If your assembler allows it, save the program as a binary file. NOTE: If you have the Commodore 64 Assembler Development System, create a source file (with start address $0C00), assemble and load it in C64 mode.
  • Page 260 COMMODORE 128 Now you are ready to enter C64 mode and run the program with the following command: GO 64 Reply to the question “ ARE YOU SURE?” by pressing the “ Y ” key and RETURN. You are now placed in C64 mode.
  • Page 261 THE POWER BEHIND COMMODORE 128 GRAPHICS 1 0 0 0 R A S T E R I N T E R R U P T S P L I T S C R I H O R I Z O N T A L...
  • Page 262 COMMODORE 128 1 6 9 0 # $ 7 F 1 7 0 0 S T A $ D 0 1 1 ; D I S A B L E I N T R P T D I S B I T...
  • Page 263 THE ROWER BEHIND COMMODORE 128 GRAPHICS 2380 ; 2390 LDA $DD00 ;SELECT BANK 1 2400 AND # $FE 2410 STA SDD00 2420 2430 LDA SREG ;SET SCRRREG 2440 AND #$F8 2450 ORA #$03 2460 STA SREG 2470 ; 2480 LDA #14...
  • Page 264 Line 1010 assigns the variable IVEC to the address $0314, the hardware interrupt request (IRQ) vector. The interrupt vector is the means by which the Commodore 128 displays split screens and scrolling. By wedging your own routine into the hardware...
  • Page 265 THE POWER BEHIND COMMODORE 128 GRAPHICS will SYS to this address to start the program in BASIC, or GO to this address from the Machine Language Monitor. The first sequence of program instructions starting at line 1140 places the contents of the address (named FRANK) of the beginning of the scrolling text into the memory locations ($FA and $FB) called TXTPTR and TXTPTR + 1.
  • Page 266 COMMODORE 128 (0) can interrupts occur. The last line (1720) of the interrupt initialization routine clears the interrupt disable and allows interrupts to occur. Lines 1440 through 1470 store the original contents of the Interrupt Request (IRQ) vector into temporary storage locations TEMP (low byte $ 1806) and TEMP + 1 (high byte $1807).
  • Page 267 THE POWER BEHIND COMMODORE 128 GRAPHICS The instruction in line 1720 clears the interrupt disable status bit, which enables interrupts to occur. This is the last operation to be performed by the interrupt initializa­ tion routine. Now interrupts are ready to occur and be serviced.
  • Page 268 Lines 2040 through 2130 represent the data to be scrolled by the program. The data is stored in .BYTE statements as it appears in the Commodore Assembler 64 Development System. In your case, the Machine Language Monitor handles data by simply storing it in an absolute memory range.
  • Page 269 Although this program example is long and complex, it contains useful routines and explanations that have never appeared before in any Commodore text. Study these routines carefully and add them into your own programs. This section includes a wealth of information for the novice and experienced software developer alike.
  • Page 270 COMMODORE 128 C H ANG ING VIDEO BANKS M O VING SCREEN RAM POKE 56576, (PEEK (56576) TEXT BASIC AND 252) OR X POKE 2604, (PEEK(2604 AND 15) W HERE X IS THE DECIMAL OR X VALUE OF BITS 0 AND 1 IN...
  • Page 271 THE POWER BEHIND COMMODORE 128 GRAPHICS M O VIN G CHARACTER MEMORY ACCESSING CHARACTER ROM 10 BANK 14: REM SW AP IN CHAR ROM TEXT 20 FOR 1 = 0 TO 7 POKE 2604, (PEEK(2604)AND 240) OR Z 30 ? PEEK (I)
  • Page 272 COMMODORE 128 L O C A T I O N * BITS DECIMAL OOOOXXXX $ 0 0 0 0 1024 0001XXXX $0400 (DEFAULT) 0010XXXX 2048 $0800 0011XXXX 3072 $0C00 0100XXXX 4096 $ 1 0 0 0 0101XXXX 5120 $1400 6144...
  • Page 273: The Power Behind Commodore 128 Graphics

    THE POWER BEHIND COMMODORE 128 GRAPHICS SCREEN DATA COLOR DATA CHARACTER DATA T E X T B IT M A P T E X T B IT M A P B IT M A P T E X T C128 BASIC...
  • Page 274 ■...
  • Page 275: Sprites

    SPRITES...
  • Page 276 Most of the commercially available graphics software packages for the Commo­ dore 128 and C64 rely on sprites. For graphics programming applications, sprites offer superior animation capabilities. Single sprites are useful for small moving objects. However, you can adjoin and overlay several sprites to give greater detail to animated graphic images.
  • Page 277 SPRITES BASIC 7.0 SPRITE COM M AND SUMMARY H ere’s a brief description of each BASIC 7.0 sprite command: C O L L IS IO N : Defines the type of sprite collision on the screen, either sprite to sprite or sprite to data collision M O VSPR : Positions or moves sprites from one screen location to another...
  • Page 278 COMMODORE 128 MOVSPR number, + X, + Y Move sprite relative to its current position. MOVSPR number, X;Y Move sprite distance x at angle y relative to its current position. MOVSPR number, angle # speed Move sprite at an angle relative to its original coordinates, in the clockwise direction and at the specified speed.
  • Page 279: Chapter 9 Sprites

    Erases entire grid. keys Selects color source and enables sprite pixels. CTRL key, 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 and returns to SPRITE NUMBER? prompt.
  • Page 280 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 create the shape of your sprite. The numbered keys 1 through 4 fill the sprite and give it shape.
  • Page 281 ■ Immediately after you SAVE your sprite in memory (shift RETURN) ■ Immediately after you press the STOP key 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...
  • Page 282 COMMODORE 128 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. To turn it on, use the SPRITE command you learned. For example, you created sprite 1 in SPRDEF mode. To turn it...
  • Page 283 SPRITES SPRITE 2,1,7,1,1,1 Turn on sprite number 2, color it blue, make it pass behind objects on the screen and expand it in the vertical and horizontal directions. SPRITE 6 ,1,1,0,0,1,1 Turn on SPRITE number 6 , color it black. The first 0 tells the computer to display the sprites in front of objects on the screen.
  • Page 284 COMMODORE 128 EXA M P LE S: 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$.
  • Page 285 SPRITES H ere’s an explanation of the program: Line 5 COLORs the background black and the foreground white. Line 10 selects standard bit map mode and clears the bit map screen. Lines 17 through 21 DRAW the stars. Line 23 BOXes in a display area for the picture of the spacecraft in the top-left corner of the screen.
  • Page 286 COMMODORE 128 Line 97 is another time delay so the retro rocket, sprite 2, has time to move off the screen. Line 98 turns off sprite 2, once it is off the screen. Line 99 is another delay so the capsule can continue to move across the screen.
  • Page 287 SPRITES Notice that the sprites move continuously even after the program has stopped RUNning. The reason for this is that sprites are wedged into the interrupt processing of the C128. To turn off and stop the sprites on the screen, either issue a SPRITE command that turns them off, or press RUN/STOP and RESTORE.
  • Page 288 COMMODORE 128 The third sprite example provides an algorithm to overlay two sprites and move them on the screen on a 45-degree angle. Again, this program assumes your sprite data resides in sprite storage. If your sprite images are not stored there, fill the sprites with data as you did in the last adjoining example.
  • Page 289 RETURN at the same time; this allows SPRDEF to store the sprite data in the sprite data storage area. Press RETURN a second time to exit SPRDEF. The Commodore 128 has a dedicated portion of memory ranging from decimal address 3584 ($0E00) through 4095 ($0FFF), where sprite data is stored. This portion of...
  • Page 290 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 6 4 ) bytes to represent the data of all eight sprite images.
  • Page 291 Figure 9-3. See Figure 9-4 for an illustration. The way the Commodore 128 automatically points to the correct sprite data is conven­ ient for programming, since it eliminates a step (provided the original values of the sprite pointers have not been modified).
  • Page 292 LDA #$ 20 STA $D015 To enable sprites 5 and 7, raise two to the fifth (32 ($20)) and add it to two to the seventh (128($80)) to obtain the result 160 ($A0): LDA $A0 STA $D015 An easier way of perceiving the idea is through binary notation in the Machine...
  • Page 293 SPRITES ASSIGNING COLOR TO SPRITES Sprites have two kinds of color displays: standard bit-map and multi-color bit-map sprites. The color assignments to the pixels within the sprites work in a similar way to standard bit-map and multi-color bit-map modes for the screen. STANDARD BIT MAP SPRITES Standard bit-map sprites each have their own color register.
  • Page 294 COMMODORE 128 is equal to zero, those pixels on the sprite are transparent and the background data from the screen passes through the sprite. M U LTI-C O LO R SPRITES Multi-color sprites offer a degree of freedom in the use of color, but you trade the higher resolution of standard sprites for the added color.
  • Page 295 SPRITES If the bit pair is equal to 00, the pixels are transparent and the background from the screen passes through the sprite. If the bit pattern equals 10 (binary), the color is taken from the sprite color register (locations 53287-53294) of the sprite being defined. Otherwise, the other two bit pair possibilities (01 and 11) are taken from sprite multi-color registers 0 and 1 respectively.
  • Page 296 255. An extra bit is already set aside in the Commodore 128 memory in case you want to move a sprite past the 255th horizontal coordinate. Location 53264 controls sprite movement past position 255.
  • Page 297 #$ 80 $D010 The number 128 is the resulting decimal value from setting bit 7. You arrive at this value by raising two to the seventh power. If you want to enable bit 5, raise two to the fifth power, which, of course, is 32. The general rule is to raise two to the power of the sprite number that you want to move past the 255th horizontal screen position.
  • Page 298 Sprite-to-data SPRITE-TO-SPRITE DISPLAY PRIORITIES Each of the eight sprites available on the Commodore 128 is assigned its own plane in which it moves independent of other sprites or of the pictures on the screen background. Visualize the sprite planes as in Figure 9-9.
  • Page 299 SPRITES feature is preset by the C l 28 hardware, and is not controlled through a software register. The lower the sprite number, the higher the priority. The higher priority sprite passes in front of the lower priority sprite. Sprite 0 has the highest priority; therefore, it passes in front of any other sprites that may be on the screen should they meet at a particular screen location.
  • Page 300 COMMODORE 128 SPRITE-TO-SPRITE COLLISIONS A sprite-to-sprite collision occurs when an enabled pixel in the foreground of one sprite overlaps an enabled pixel from the foreground of another sprite at any point on the sprite coordinate plane. The collision may also occur at an off-screen coordinate location.
  • Page 301: Program M Ing The 80-Colum N (8563) Chip

    PROGRAMMING THE 8 O-COLUMN (8563) CHIP...
  • Page 302 Commodore 128 I/O memory. $D600 and $D601. This means that only two memory locations in the Commodore 128 I/O memory pertain to the 8563 video chip. Internally, the 8563 has thirty-seven internal registers, though they are not...
  • Page 303 PROGRAMMING THE 80-CQLUMN (8563) CHIP is independent of the Commodore 128 RAM. You must address locations $D600 and $D601 as the gateways through which you indirectly address the thirty-seven internal registers and 16K of 8563 RAM. You cannot directly access any of the thirty-seven internal registers or the 16K of 8563 RAM.
  • Page 304 COMMODORE 128 BITS H orizontal Total H orizontal Displayed Horizontal Sync Position VW 3 VW 2 HW1 HWO Vert/Horiz Sync Width Vertical Total Vertical Total Adjust — — — Vertical Displayed Vertical Sync Position Interlace Mode — — — —...
  • Page 305 RAM location. You must indirectly read or write to $D600 and $D601 in order to communicate between the 8563 chip and the rest of the Commodore 128. Figure 10-2 gives description of each of the mapped registers and the bits within them: $D600 —...
  • Page 306 COMMODORE 128 This is the sequence of steps to perform a read or write operation: 1. Address the registers (by number) or internal RAM location. 2. Check the value of bit 7 until it equals 1 in order for the data to be valid.
  • Page 307 PROGRAMMING THE 8O-COLUMN (8563) CHIP s b k h b h b h h a. Visible 8 by 8 pixel character. b. H o rizo n ta l in terch aracter spacing. c. V e rtic a l in terch aracter spacing. Figure 10-3.
  • Page 308 COMMODORE 128 H AS AD KH AD KS FD K H A H AS AD KH AD KS FD K H A H AS AD KH AD KS FD K H A H AS AD KH AD KS FD K H A...
  • Page 309 PROGRAMMING THE 8Q-COLUMN (8563) CHIP UNDERSTANDING THE 8O-COLUMN CHARACTER DISPLAY A N D ATTRIBUTE MEMORY As you learned earlier in this chapter, the 8563 has three areas of memory that control the 80-column display: character definitions, character attributes and display screen memory.
  • Page 310: Display Memory

    COMMODORE 128 UNDERSTANDING DISPLAY MEMORY The frame, which was introduced earlier in this chapter, pertains to display memory, the portion of memory you can see on the screen. Display memory resides in the range $0000-$07FF in the 16K independent 8563 RAM. Think of the screen as a frame of 25 rows of 80 characters each.
  • Page 311 PROGRAMMING THE 8Q-COLUMN (8563) CHIP In general, add an offset of 1 for each character position to the right of the upper-left corner of the frame. To reach the same column in the row below the current character position, add an offset of 80. Although the screen (frame) appears as a two-dimensional matrix of characters, the address references in memory are accessed linearly in sequence.
  • Page 312 COMMODORE 128 The REVERSE VIDEO ATTRIBUTE (bit 6), when high (1), reverses the foreground and background colors for the corresponding character in display memory. See also the register-by-register description of the 8563 chip for all the details about register 24, the Reverse Screen Register.
  • Page 313 PROGRAMMING THE 80-CQLUMN (8563) CHIP 20 and 21 for each character attribute to the right of the HOME position. To address the character attribute directly below the HOME position (row 2, column 1), add an offset of 80 to the contents of registers 20 and 21. To address the character attribute of the character in the lower-left corner of the 80 by 25 frame, add a decimal offset of 1920 (24 x 80).
  • Page 314 As you know, the 8563 chip has its own 16K of RAM and its own set of registers. Neither of these appear in the standard Commodore 128 memory map. The only memory locations that apply to the 8563 chip in Commodore 128 memory are the locations...
  • Page 315 PROGRAMMING THE 80-CQLUMN (8563) CHIP D600 and $D601. These are the 8563 address and data registers, respectively. In order to read or write to 8563 RAM or registers, you must pass data through the address and data registers. This section explains how to read the 8563 registers. The next section illustrates how to write to the 8563 registers and RAM.
  • Page 316 COMMODORE 128 S Y S D E C ( " 1 8 0 0 " ) 2 0 A $ = H E X $ ( P E E K ( 2 5 1 ) ) B $ = H E X $ ( P E E K ( 2 5 2 ) )
  • Page 317 (1) is the data in $D601 valid. This is the point where the data is communicated from the 8563 chip to the Commodore 128 memory. Now you can read and act upon the contents of the address within register $14 of the 8563 chip.
  • Page 318 COMMODORE 128 WRITING TO AN 8563 REGISTER The five-step algorithm to read data from an 8563 register is similar to writing to an 8563 register. In the last section. Step 5 in the read algorithm loaded the accumulator with the value contained in the 8563 data register ($D601). When writing, perform the opposite operation.
  • Page 319 PROGRAMMING THE 8O-COLUMN (8563) CHIP ■ The first instruction (at $1800) loads the X register with the register number 18 ($12). ■ The next instruction loads the accumulator with the high byte of the value you are placing in register 18 ($20). ■...
  • Page 320 COMMODORE 128 R E A D Y . M O N I T O R S R A C X R YR F B 0 0 0 # $ 1 2 L D X 0 1 8 0 0 L D A...
  • Page 321 PROGRAMMING THE 8O-COLUMN (8563) CHIP RAM, you must address register 31 because it acts as the internal data register of the 8563 chip. All data that will be written to the 8563 RAM must pass through register 31. The next three instructions: STX $D600 BIT SD600 BPL $1824...
  • Page 322 COMMODORE 128 1 0 0 V I = D E C ( " 1 8 0 0 " ) : V 0 = D E C ( " 1 8 0 C " ) : B A N K 1 5...
  • Page 323 PROGRAMMING THE 80-CQLUMN (8563) CHIP Finally, place the number of successive memory locations you want to write to 8563 RAM in register 30. At this point, the 8563 writes the data in register 31 starting from the location deter­ mined by registers 18 and 19 through the number of successive memory locations specified by register 30.
  • Page 324 COMMODORE 128 Bits 4 through 0 in register 10 determine the bottom scan line in which the cursor definition begins within the 8 scan line cursor character block. Scan line 0 is at the top of the cursor character block, while scan line 8 is at the bottom.
  • Page 325 PROGRAMMING THE 80-CQLUMN (8563) CHIP visible 8563 raster rows are 640 pixels wide. Both the VIC and 8563 screens have raster rows which are not visible on the screen. This portion is known as the vertical retrace. The 8563 screen is stored byte by byte across a raster row. The first eight pixels of the first raster row are stored in the first byte of the 8563 bit-map byte, address $0000 in 8563 RAM.
  • Page 326 COMMODORE 128 You have two choices: either disable the attributes or reduce the size of your bit map by 2000 bytes, then define and enable the attributes. With a full-size bit map, you cannot implement the attributes, because there is simply not enough independent 8563 RAM to do both.
  • Page 327 PROGRAMMING THE 80-CQLUMN (8563) CH IP 0 1 8 2 9 S T A $ F E 0 1 8 2 B N O P 0 1 8 2 C N O P 0 1 8 2 D L D X # $ 0 0 ( $ F A , X ) 0 1 8 2 F...
  • Page 328 COMMODORE 128 0 1 8 A F R T S N O P 0 1 8 B 0 N O P 0 1 8 B 1 0 1 8 B 2 N O P L D A # $ 0 0...
  • Page 329 PROGRAMMING THE 8O-COLUMN (8563) CHIP Here’s where a major difference between the two video chips becomes important— the way the bit map corresponds to the image on the screen. As you know, the VIC screen stores eight rows of 8 pixels each to make up one character cell. Each row of the eight pixels in a character on the screen are stored consecutively in memory.
  • Page 330 COMMODORE 128 In the program, as discussed, the instructions in $180A through $181A start the VIC and 8563 bit maps at locations $2000 and $0000 respectively. All these instructions encompass step 1 of the algorithm. The instructions that perform step 2 of the algorithm are stored at locations $182D-$1830.
  • Page 331 PROGRAMMING THE 80-CQLUMN (8563) CHIP VERTICAL SCROLLING Scrolling in the vertical direction is easier than scrolling horizontally. The general algorithm to scroll vertically is as follows: 1. Set the default start of the character RAM storage to $2000 in 8563 RAM. This is done through writing to (or using the default contents of) registers 12 ($0C) and 13 ($0D).
  • Page 332 COMMODORE 128 #$oc L D X 0 1 8 0 0 # $ 2 0 0 1 8 0 2 L D A S T A $ F B 0 1 8 0 4 $ 1 8 6 0 J S R...
  • Page 333 PROGRAMMING THE 80-CQLUMN (8563) CHIP in the 8563 “ w indow .” This means that to display a window of 25 rows of 80 characters of a virtual screen of width 132 characters, the Display RAM memory must have at least 3300 (132 25) memory locations and the same number of attributes.
  • Page 334 COMMODORE 128 REGISTER-BY-REGISTER DESCRIPTION This section describes each 8563 register in detail by register number. The significant bits are isolated and explained separately. The conventions used in the register descriptions are as follows: Rn (msb-lsb) The R stands for “ register.” The letter n represents the register number, ranging from 0 through 36.
  • Page 335 PROGRAMMING THE 8Q-COLUMN (8563) CHIP VERTICAL T O T A L The number of character rows, minus 1, between successive vertical sync pulses. This number includes the displayed rows, vertical border and the blanking interval during the vertical sync pulse and determines the vertical sync rate. R5(4-0) VERTICAL T O T A L ADJUST The number of scan lines added to the end of the frame for fine adjustment of the...
  • Page 336 COMMODORE 128 R l0(4-0) CURSOR START SCAN LINE The number of the first (top) scan line of the reverse-video cursor. The number 0 refers to the first (top) scan line of the character. This register and register 11 (below) define the cursor height, and can create a variety of effects, from a block cursor to an underline cursor.
  • Page 337 PROGRAMMING THE 8Q-COLUMN (8563) CHIP R 10(4— 0) and R 1 1(4-0). These registers allow the 8563 to be programmed for a reverse-video “ block” cursor, or for an “ underline” cursor. The location of the cursor can be changed by changing the contents of registers R14 and R15. RI6, RI7 LIG H T PEN VERTICAL, H O R IZ O N T A L The 8563 supports a light pen function.
  • Page 338 COMMODORE 128 subsequent characters are incremented from the previous address, so horizontally adjacent characters have attributes in adjacent memory locations. A frame of 25 character rows of 80 characters each will use 2000 attributes at display 8563 RAM memory locations (R20/R21) through (R20/R21 + 1999).
  • Page 339 PROGRAMMING THE 8Q-COLUMN (8563) CHIP The number in R24(4-0) can be increased, increasing the number of scan lines scrolled, until R24(4— 0) equals R9(4-0). This is the maximum amount of smooth scroll allowed. At this point, only one (the bottom) scan line will exist for the first character row and the last character row will have scrolled onto the frame with only the last scan line not visible.
  • Page 340 COMMODORE 128 pixels, up to the width of one character. Before horizontal smooth scrolling can occur, the 8563 must have something to scroll ‘onto’ the right side of the screen, so R27 must be greater than 0. This sets up a virtual screen at least one character greater than the displayed screen.
  • Page 341 PROGRAMMING THE 80-CQLUMN (8563) CHIP particular 8563 version in the system. The 8563 version can be easily ascertained through software by reading the 8563 status register, located at $D600 in I/O memory. Bits 0 -2 contain the version number. Refer to the table below for the actual data to be used.
  • Page 342 COMMODORE 128 disable attribute usage. If R25(6) is a 0, then attributes will not be fetched by the 8563 and the RAM memory may be used for other purposes. In this case, no character may be underlined, individually reversed or blinked. Only one character set of 256 characters may be used.
  • Page 343 PROGRAMMING THE 80-CQLUMN (8563) CHIP be configured to be compatible with 4164 8563 RAMs (64K by 1) or with 4416 8563 RAMs (16K x 4). Register 28, bit 4 should be initialized to a 0 for operation with 4416s a 1 for operation with 4164s. 4416: Row/Col = A7/A15, A6/A13, A5/A12, A4/A11, A3/A10, A2/A9, A1/A8, A0/A8 4164: Row/Col = A7/A15, A6/A14, A5/A13, A4/A12, A3/A 11, A2/A10, A1/A9,...
  • Page 344 COMMODORE 128 R36(3-0) 8563 RAM REFRESH/SCAN LINE The number of Dynamic RAM refresh cycles every scan line. These refresh cycles occur on displayed and nondisplayed scan lines, during the displayed part of the screen and nondisplayed parts (blanked scan lines, vertical borders and vertical sync). Each refresh address is incremented from the previous refresh address, incrementing through all 65,536 addresses.
  • Page 345: Sound And Music On The Commodore

    SOUND AND MUSIC ON THE COMMODORE 128...
  • Page 346 To make it easy for you to select and manipulate the many capabilities of the SID chip, Commodore has developed new and powerful BASIC music statements. Here are the new sound and music statements available on the Commodore 128: SOUND...
  • Page 347 SO UND A N D MUSIC O N THE COMMODORE A parameter that is not specified will retain its predefined or currently redefined value. Pulse width applies to the width of the variable pulse waveform (wf = 2) only. The Commodore 128 has initialized the following ten envelopes:...
  • Page 348 COMMODORE 128 EX A M P LE S: FILTER 1024,0,1,0,2 Set the cutoff frequency at 1024, select the band pass filter and a resonance level of 2. FILTER 2000,1,0,1,10 Set the cutoff frequency at 2000, select both the low pass and high pass filters (to form a notch reject) and set the resonance level at 10.
  • Page 349 SO UND AN D MUSIC ON THE COMMODORE 128 EXA M P LE S: PLAY “ V1O4T0U5X0CDEFGAB” Play the notes C ,D ,E ,F,G ,A and B in voice 1, octave 4, tune enve­ lope 0 (piano), at volume 5, with the filter off.
  • Page 350 COMMODORE 128 SOUND 3,5000,90,2.3000,500,1 This example outputs a range of sounds start­ ing 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.
  • Page 351 This exercise is substantially faster and easier if you know how to read 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 11-1 shows how a typical musical staff is arranged and how the notes on the staff are related to the keys on a piano.
  • Page 352 Figure 11-2. P art o f B ach’s Invention 13 The best way to start coding a song on your Commodore 128 is to break the notes down into an intermediate code. Write down the upper staff notes on a piece of paper.
  • Page 353 Commodore 128. You must give the computer time to play the longer note first, and then PLAY the notes of shorter duration, or else the composition will not be synchronized.
  • Page 354 COMMODORE 128 Here are two sample sounds programs that you can try: R E M S O U N D L O O P S R E M C H A N G E S S T E P V A L U E ,...
  • Page 355 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 11-6 for a graphic representation of these...
  • Page 356 COMMODORE 128 — PULSE W IDTH — Figure 11-6. Sound W ave fo rm Types...
  • Page 357 The ENVELOPE generator controls the ADSR parameters of sound. See Figure 11-7 for a graphical representation of ADSR. The Commodore 128 can change each ADSR parameter to sixteen different levels. This gives you absolute flexibility over the ENVELOPE generator and the resulting proper­...
  • Page 358 COMMODORE 128 automatically by the Commodore 128. Here are the preselected envelopes for different types of musical instruments: ENVELOPE NUMBER DECAY INSTRUMENT ATTACK SUSTAIN RELEASE W AVEFORM Piano 1536 Accordion Calliope Drum Flute Guitar Harpsichord Organ 2048 Trumpet Xylophone Figure 11-8. D e fa u lt P aram eters fo r E N V E L O P E S ta te m e n t...
  • Page 359 SOUND AN D MUSIC ON THE COMMODORE 128 Figure 11-9. Low-pass F ilter Conversely, the high-pass filter allows all the frequencies above the cutoff fre­ quency to pass through the chip. All the ones below it are filtered out. See Figure 11-10.
  • Page 360 COMMODORE 128 Figure 11-11. Band-pass F ilter A D VA N C ED FILTERING Each of the previous FILTERing examples used only one type of filtering at a time. You can combine the SID chip’s three methods of filtering with each other to achieve different filtering effects.
  • Page 361 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 362 COMMODORE 128 NOTE TYPE Luminance/SYNC output LUM/SYNC AUDIO OUT Composite signal output VIDEO OUT AUDIO IN Chroma signal output COLOR OUT No connection No connection Run the three connecting wires inside the cable to attach to the audio in, audio out and ground on the end of your component.
  • Page 363 SO UND A N D MUSIC O N THE COMMODORE 128 > - > > > > - > > > > - > - > - > • > - _______ I ____________ I ____________ l — I ___________ I —...
  • Page 364 COMMODORE 128 Here’s the general algorithm to output sound from the SID chip in voice 1. Clear the sound chip (For $D400-$D41C) Select ATTACK and DECAY for each voice ($D405)vl Select SUSTAIN and release for each voice ($D406) vl Select a waveform ($D404 for v l)
  • Page 365 SOUND AN D MUSIC O N THE COMMODORE 128 To synchronize three voices, divide each measure into sixteen equal parts. Play (Gate) the notes with longer duration first, then gate the values of smaller duration, but of equal proportion, next. For example, one staff has an eighth note. The staff below it has two sixteenth notes.
  • Page 366 COMMODORE 128 0 1 8 3 4 B E Q $ 1 8 7 5 0 1 8 3 6 S T A $ D 4 0 0 , X 0 1 8 3 9 I N X 0 1 8 3 A...
  • Page 367 SOUND AN D MUSIC ON THE COMMODORE 128 G F I 800 The program plays a series of notes in a single voice (voice 1). Here’s a line by line description of the instructions in the program. The instructions stored in locations $1800 through $180A clear the SID registers ($D400-$D418) to zero.
  • Page 368 COMMODORE 128 register is incremented again and the high byte duration is loaded into the accumulator and stored in zero page location $FB. These two locations are decremented in the instructions stored in location $ 185B through $1862. The instructions stored in locations $1850 through $1857 GATE the note, in other words play the note.
  • Page 369 SOUND AN D MUSIC O N THE COMMODORE 128 Clear sound chip registers. Set high frequency voice 1. Set Attack/Decay for voice 1 (A = 13, D = 11). Set high frequency voice 3. Set volume 15. Set start triangle, sync waveform control for voice 1.
  • Page 370 COMMODORE 128 PWout = (PW n/40.95) % Where PWn is the 12-bit number in the Pulse Width registers. The pulse width resolution allows the width to be smoothly swept with no discern- able stepping. Note that the Pulse waveform on Oscillator 1 must be selected in order for the Pulse Width registers to have any audible effect.
  • Page 371 SO UND AN D MUSIC ON THE COMMODORE 128 (B it 6): When set to a one, the Pulse waveform output of Oscillator 1 is selected. The harmonic content of this waveform can be adjusted by the Pulse Width registers, producing tone qualities ranging from a bright, hollow square wave to a nasal, reedy pulse.
  • Page 372 COMMODORE 128 Bits 0 -3 (RLS0-RLS3) select 1 of 16 RELEASE rates for the Envelope Genera­ tor. The RELEASE cycle follows the SUSTAIN cycle when the Gate bit is reset to zero. At this time, the output of Voice 1 will fall from the SUSTAIN amplitude to zero amplitude at the selected RELEASE rate.
  • Page 373 SOUND AN D MUSIC ON THE COMMODORE 128 VO ICE 2 Registers $07-$0D control Voice 2 and are functionally identical to registers $00-$06 with these exceptions: When selected, SYNC synchronizes Oscillator 2 with Oscillator 1. When selected, RING MOD replaces the Triangle output of Oscillator 2 with the ring modulated combination of Oscillators 2 and 1.
  • Page 374 COMMODORE 128 F IL T 2 (B it I): Same as bit 0 for Voice 2. F IL T 3 (B it 2): Same as bit 0 for Voice 3. F IL T E X (B it 3): Same as bit 0 for External audio input (pin 26).
  • Page 375 SOUND A N D MUSIC ON THE COMMODORE 128 MISCELLANEOUS P O T X (REGISTER $19) This register allows the microprocessor to read the position of the potentiometer tied to POTX (pin 24), with values ranging from 0 at minimum resistance, to 255 ($FF) at maximum resistance.
  • Page 376 COMMODORE 128 EQUAL-TEMPERED MUSICAL SCALE VALUES The table in Figure 11-15 lists the numerical values which must be stored in the SID Oscillator frequency control registers to produce the notes of the equal-tempered musical scale. The equal-tempered scale consists of an octave containing twelve semitones (notes): C ,D ,E ,F,G ,A ,B and C # ,D # ,F # ,G # ,A # .
  • Page 377 SOUND A N D MUSIC O N THE COMMODORE 128 Figure 11-15. Music N o te Values M U S I C A L N O T E O S C I L L A T O R F R E Q...
  • Page 378 COMMODORE 128 Figure 11—15. Music N o te Values (continued) M U S I C A L N O T E O S C I L L A T O R F R E Q NOTE OCTAVE DECIMAL 3608 A -3...
  • Page 379 SO UND A N D MUSIC O N THE COMMODORE 128 M U S I C A L N O T E O S C I L L A T O R F R E Q NOTE OCTAVE DECIM AL...
  • Page 381: Input/Output Guide

    12____ INPUT/OUTPUT GUIDE...
  • Page 382: Disk Drive

    COMMODORE 128 IN TR O D U C TIO N Besides being a calculator and a data manipulator, the Commodore 128 is a communica­ tor. Through the various connecting ports, it can transmit and receive information to many different kinds of peripheral equipment. Because of the variety of devices, each must have its unique access codes and specific instructions (software).
  • Page 383 IN P U T /O U TP U T GUIDE you change disks— so, for your own protection, try to assign each disk a unique code. The format command for C l28 mode is as follows: HEADER “ disk name” , lxy,DO,ON U8 For C64 or C l28 modes, use: OPEN 15,8,15, “...
  • Page 384 COMMODORE 128 In these formats: “ b ” is the memory bank number (0 through 15) “ s” is the starting address “ e ” is the ending address E X A M P LE : BSAVE“ filename” ,B2,P3584 TO P4096 This saves the binary file named “...
  • Page 385 IN P U T /O U TP U T GUIDE (to verify the program from the memory location from which it was SAVEd, primarily machine language programs). After your program has been saved and verified, it is stored on your disk for future use.
  • Page 386 COMMODORE 128 BLOAD“ filename” ,DO,U9,Bb,Ps (for disk drive unit 9, drive 0) where b is the bank number and s is the starting address. In BASIC 2.0, use the following command formats: To load a BASIC program: LOAD“ filename” ,8 To load a machine language program: LOAD“...
  • Page 387 IF N $ = “ END’T H E N CLOSE 5:END LOOP N O TE: In C128 mode, the Commodore 128 has a set of disk input/ output commands. These include the DLOAD and DSAVE commands already described, as well as the DOPEN, DCLOSE and other com­...
  • Page 388 The 1571 has a device number switch on the back. O U TP U T TO A PRINTER Your Commodore 128 computer transmits data over the serial port to many different styles of printers. The most popular Commodore printers today are the daisy wheel and dot matrix types.
  • Page 389 OPEN 3,4 establishes a link to the printer as device number 4. The first number can be any number between 1 and 255. Numbers beyond 128 force a line feed after a carriage return. PRINTING A PROGRAM LISTING The following commands will produce a printed listing: OPEN3,4:CMD3:LIST The CMD command redirects all screen output to the printer.
  • Page 390 COMMODORE 128 PRINTING A TYPED LINE A PR IN T # command to an opened print file number outputs the associated data to the printer. The following commands output whatever is typed: OPEN3 ,4:PR IN T#3, ‘‘TYPE ANYTHING’ ’ R E T U R N...
  • Page 391 Generally, a computer uses an RS232 port to communicate with the external world. Commodore’s RS232C Port (also known as the User Port) is a variation of the RS232 standard port. The RS232 has 0 to 5 TTL voltage levels rather than the standard plus/minus 12 volts.
  • Page 392 RS-232 channel as can happen with the Commodore 64. By permanently allocating the buffers in a fixed location, no “ OUT OF M EM ORY” error can occur, and your program in memory will not get “ stepped o n .”...
  • Page 393 7-bit word and 1200-baud rate yields: 1010 1000 (in binary), which is decimal 168 ($A8) and results in OPEN 3,2,0,CHR$(168) defining these parameters. 128 64 32 4 2 0 @ @ 0 || [| 0 0...
  • Page 394 COMMODORE 128 OPEN3,4,O.CHR$(168)CHR$(32) specifies odd parity, full duplex. A baud rate other than those listed in the Control Register Map is also selectable by choosing 0000 for bits 0 through 3 in the Control Register and including this rate in the OPEN statement as two bytes following the Command Register.
  • Page 395 G ETTING DA TA FROM RS-232 C H AN N EL The Commodore 128 receiver buffer ($OCOO-$OCFF) will hold up to 255 characters before overflowing. This is indicated in the RS-232 status word ST. If an overflow occurs, sub­ sequent characters are lost. Keep the buffer as clear as possible. To receive data at high speeds, use machine language routines or use the FAST command to process at 2MHz with the 80-column screen (in C l 28 mode only).
  • Page 396 COMMODORE 128 N O TE: Care should be taken to ensure all data is transmitted before closing the channel. A way to check this from BASIC is: LOOP WHILE PEEK (2575) and 3 CLOSE lfn Location 2575 is the RS-232 “ ENABL” location.
  • Page 397 F O R J = l 9 3 T 0 2 1 8 : K = J - 1 2 8 : T % ( J ) = K : N E X T 100 T%(146)=16:T%(133)=16 110 T%(137)=3:T%(134)=17:T%(138)=19 120 FORJ=0TO255 130 K = T % (J ) 140 IFKOOTHENF%(K)=J:F% (K+128 ) = J 150 NEXT 160 PRINT" "CHRS(147) 170 GET#5,A$ 180 IFA$=""ORST<>0THEN220 1 9 0 P R I N T "...
  • Page 398 COMMODORE 128 $00AA-RIDATA— Receiver byte buffer/assembly location. $00AB-RIPRTY— Receiver parity bit storage. $00B4-BITTS — Transmitter bit count out. $00B5-NXTBIT — Transmitter next bit to be sent. $OOB6-RODATA— Transmitter byte buffer/disassembly location. All the above zero-page locations are used locally and are given only as a guide to understand the associated routines.
  • Page 399 The following command will also swap the display output device: PRINT CHR$(27)“ X ” In addition to a screen display, sound commands can be used through a Commodore monitor or the television speakers. See Chapter 11, Sound and Music. O U TP U T TO THE DATASSETTE Commodore programs and files can also be stored on tape cassette using a special recorder called the Datassette.
  • Page 400 COMMODORE 128 OPEN 1,1,2 ‘ ‘FILENAM E” The end-of-tape marker prevents searching for files beyond the data file you are looking for. It is written when the CLOSE command is given. N O TE: Do not connect the Datassette and the 1571 disk drive to the C l 28 at the same time.
  • Page 401 0 is stationary and 1 through 8 represent clockwise positions. Values between 128 and 136 signify the fire button is pressed as well. Thus if JOY(2) returns 131, it means joystick number 2 fires to the right (position 3).
  • Page 402 IF (JOY(N)AND 128)= 128 THEN PRINT“ FIRE” TH E 1350 MOUSE The Commodore 128 makes use of an additional new peripheral device known as a mouse. The Commodore mouse is a user interface that allows you to control the operations of a program, such as selecting menu or icon options, without the need to type on the keyboard.
  • Page 403 IN P U T /O U TP U T GUIDE LIG H T PEN The light pen input latches the current screen position into a pair of registers (LPX, LPY) on a low-going edge. The X position register 53267 ($D013) will contain the 8 MSB of the X position at the time of transition.
  • Page 404 PINOUTS THE SERIAL PORT The Serial Port is a daisy chain arrangement designed to let the Commodore 128 computer communicate with more than one device, such as Commodore disk drives and printers. Up to five devices can be connected at one time. The serial bus can transmit control signals from the computer, send data onto the bus, and receive data from the bus.
  • Page 405 + 5V (100 mA M AX.) RESET By grounding this pin, the Commodore 128 will do a cold start, resetting completely. The pointers to a BASIC program will be reset, but memory will not be cleared. This is also a RESET output for the external devices.
  • Page 406 VIDEO CO N N EC TO R This DIN connector supplies direct audio and composite video signals. These can be connected to the Commodore monitor or used with separate components. This is the 40-column output connector. Figure 12-7 shows the pinouts for the composite video...
  • Page 407 IN P U T /O U TP U T GUIDE Figure 12-7. C om posite Video C o n necto r Pinouts TYPE NOTE LUM/SYNC Luminance/SYNC output AUDIO OUT VIDEO OUT Composite signal output AUDIO IN Chroma signal output COLOR OUT No connection No connection T ab le 12-5.
  • Page 408 COMMODORE 128 SIGNAL Ground Ground Green Blue Intensity Monochrome Horizontal Sync Vertical Sync T a b le 12-6. RGBI C o n necto r Pin Descriptions THE CASSETTE C O NNECTO R A 1530 Datassette recorder can be attached to the cassette port to store programs and information.
  • Page 409: The Expansion Port

    THE EXPANSION PORT Vhe expansion port connector is a 44-pin female edge connector accessing the comput­ er’s address and data buses. It accepts Commodore’s preprogrammed game and utility software cartridges. As a parallel port, it can accept Commodore’s IEEE peripherals with an IEEE interface for controlling instrumentation and other devices.
  • Page 410 COMMODORE 128 TYPE TYPE + 5V ROMH + 5V RESET S 02 Dot Clock I/O 1 GAME EXROM I/O 2 A l l ROML T a b le 12-9. Expansion P o rt Pin Descriptions...
  • Page 411 COMMODORE 128 OPERATING SYSTEM...
  • Page 412 COMMODORE 128 The Commodore 128 operating system controls, directly or indirectly, all functions of your computer. The Commodore 128 operating system is housed in a ROM chip called the K ernal, which contains about 16K of machine language instructions. These instruc­...
  • Page 413 THE COMMODORE 128 OPERATING SYSTEM HOW TO USE (CALL) THE KERNAL ROUTINES YOUR OWN PROGRAMS Most of the system subroutines require specific parameters, or values, which must be loaded into the accumulator, X or Y index registers. Some Kernal subroutines require additional preparatory routines to be called before invoking the specific target routine.
  • Page 414 COMMODORE 128 C l 28 S Y S T E M V E C T O R S $FFFB SYSTEM ;operating system vector (RAM I) $FFFA p rocessor NMI vector $FFFC RESET ;processor RESET vector $FFFE p rocessor IRQ/BRK vector...
  • Page 415: The Com M Odore 128 O Perating System

    THE COMMODORE 128 OPERATING SYSTEM $FFE4 JM P (IGETIN) ;read buffered data $FFE7 JM P (ICLALL) ;close all files and channels $FFEA JM P UDTIM in crem ent internal clock $FFED JM P SCRORG ;get current screen window size $FFF0 JM P PLOT ;read/set cursor position...
  • Page 416 COMMODORE 128 USER CALLABLE KERNAL ROUTINE C O N VE N TIO N S C all Address: This is the call address of the Kemal routine, given in hexadecimal. Function N am e: Name of the Kemal routine. Register: Registers, memory and flags listed under this heading are used to pass parameters to and from the Kemal routines.
  • Page 417 THE COMMODORE 128 OPERATING SYSTEM C l28 SYSTEM VECTORS The vectors listed below, with the exception of the SYSTEM vector, are located not only in system ROM but in each RAM bank. The beginning and end of the system interrupt handlers are found in the top page ($FFxx) of all memory configurations as well.
  • Page 418 COMMODORE 128 configuration on the stack, brings the system configuration (ROM ’s, I/O, RAMO) into context, and executes an indirect jump through the RAM vector located at $318. The system NMI handler clears the ICR register of CIA-2, from which it determines the source of the interrupt.
  • Page 419 THE COMMODORE 128 OPERATING SYSTEM Up to this point there is no provision for user code. The next two routines in the initialization path actually look for installed user code: 7. SECURE: Check and initialize the SYSTEM vector. 8. POLL: Check for a ROM cartridge.
  • Page 420 During initialization, the user may press certain keys as a means of selecting an operating mode. One key checked is the Commodore key O , indicating C64 mode is desired. While this key was scanned much earlier by the Z80 to speed the switchover to C64 mode, there is a redundant check for it here.
  • Page 421 THE COMMODORE 128 OPERATING SYSTEM Any IOINIT calls, including Reset, will not result in 8563 character RAM initial­ ization if B7 is set. Similarly, CINT will not initialize the keyboard matrix lookup tables and the programmable key definitions if B6 is set. This is how N M I’s, for example, can call IOINIT and CINT without destroying users’...
  • Page 422 COMMODORE 128 1. IRQ ’s disabled. 2. Editor: split screen handler. 3. Editor: clear VIC raster IRQ. 4. IRQ ’s enabled. 5. Editor: keyboard scan. 6. Editor: VIC cursor blink. 7. Kernal: “ jiffie” clock. 8. Kernal: cassette switches. 9. Kernal: clear CIA-1 ICR.
  • Page 423 THE COMMODORE 128 OPERATING SYSTEM desirable for the system IRQ functions to continue normally (e.g., keyscan) as opposed to replacing them totally with our own (as we did with the NMI examples). The following examples accomplish these objectives as well as masking out all but the main IRQ.
  • Page 424 CBM STANDARD KERNAL CALLS The following system calls make up the set of standard CBM system calls for the Commodore 128 Personal Computer. Several of the calls, however, function somewhat differently or may require slightly different setups than C64 mode. This was necessary to accommodate specific features of the system, notably the 40/80 column windowing Editor and banked memory facilities.
  • Page 425 THE COMMODORE 128 OPERATING SYSTEM does not do that pertains to the Editor is I/O initialization, which is needed for IRQ’s (keyscan, VIC cursor blink, split screen modes), key lines, screen background colors, etc. (see IOINIT). Because CINT updates Editor indirect vectors that are used during IRQ processing, you should disable IRQ ’s prior to calling it.
  • Page 426 COMMODORE 128 You should be sure IRQ’s are disabled before calling IOINIT to avoid interrupts while the various I/O devices are being initialized. 3. $FF87 RAMTAS ;init RAM and buffers PREPARATION: Registers: none Memory: system map none Flags: none Calls:...
  • Page 427 THE COMMODORE 128 OPERATING SYSTEM E X A M P LE : JSR $FF8A ;restore Kernal indirects RESTOR restores the default values of all the Kemal indirect vectors from the Kemal ROM list. It does not affect any other vectors, such as those used by the Editor (see CINT) and BASIC.
  • Page 428 COMMODORE 128 6. $FF90 SETMSG ;Kemal messages on/off PREPARATION: Registers: .A = message control Memory: system map Flags: none Calls: none RESULTS: Registers: none Memory: MSGFLG ($9D) updated Flags: none E X A M P LE : LDA # 0 JSR $FF90 ;turn OFF all Kernal...
  • Page 429 THE COMMODORE 128 OPERATING SYSTEM SECND is a low-level serial routine used to send a secondary address (SA) to a LISTNing device (see LISTN Kemal call). An SA is usually used to provide setup information to a device before the actual data I/O operation begins. Attention is released after a call to SECND.
  • Page 430 COMMODORE 128 RESULTS: Registers: .X = lsb of MEMSIZ .Y = msb of MEMSIZ Memory: MEMSIZ ($A07) Flags: none E X A M P LE : JSR $FF99 ;get top of user RAMO JSR $FF99 ;lower it 1 block MEMTOP is used to read or set the top of system RAM, pointed to by MEMSIZ ($A07).
  • Page 431 THE COMMODORE 128 OPERATING SYSTEM MEMBOT is used to read or set the bottom of system RAM, pointed to by MEMSTR ($A05). This call is included in the C128 for completeness, but neither the Kemal nor BASIC utilizes MEMBOT since it has little meaning in the banked memory environment of the C128.
  • Page 432 COMMODORE 128 The following list briefly describes some of the more vital variables utilized or maintained by KEY: I/O port outputting keys ROWS $DC01 I/O port driving C64 keys COLM $DC00 I/O port driving new keys VIC # 4 7...
  • Page 433 THE COMMODORE 128 OPERATING SYSTEM RESULTS: Registers: .A = data byte Memory: STATUS ($90) Flags: none E X A M P LE : JSR $FFA5 ;input a byte from serial bus STA data A C PTR is a low-level serial I/O utility to accept a single byte from the current serial bus TALKer using full handshaking.
  • Page 434 COMMODORE 128 15. $FFAB UNTLK ;serial: send untalk PREPARATION: none Registers: Memory: system map none Flags: none Calls: RESULTS: .A used Registers: STATUS ($90) Memory: none Flags: E X A M P LE : ;UNTALK serial device JSR $FFAB U N TLK is a low-level Kemal serial bus routine that sends an UNTALK command to all serial bus devices.
  • Page 435 THE COMMODORE 128 OPERATING SYSTEM 17. $FFB1 LISTN ;serial: send listen command PREPARATION: Registers: .A = device (0-31) Memory: system map Flags: none Calls: none RESULTS: Registers: .A used Memory: STATUS ($90) Flags: none E X A M P LE : JSR $FFB1 ;command device to LISTEN...
  • Page 436 COMMODORE 128 19. $FFB7 READSS ;read I/O status byte PREPARATION: Registers: none Memory: system map Flags: none Calls: none RESULTS: Registers: .A = STATUS ($90 or $A14) Memory: STATUS cleared if RS-232 Flags: none E X A M P LE : JSR $FFB7 ;STATUS for last I/O...
  • Page 437 THE COMMODORE 128 OPERATING SYSTEM operations. The device number range is 0 to 31 and is used to target I/O. The SA is a command to be sent to the indicated device, usually to place it in a particular mode. If the SA is not needed, the .Y register should pass $FF. SETLFS is often used along with SETNAM and SETBNK calls prior to OPENs.
  • Page 438 COMMODORE 128 RESULTS: Registers: .A = error code (if any) .X used .Y used Memory: setup for I/O STATUS, RSSTAT updated Flags: .C — 1 —> error E X A M P LE : OPEN 1,8,15,“ 10” LDA #length fnlen LDX # <...
  • Page 439 THE COMMODORE 128 OPERATING SYSTEM RESULTS: Registers: .A = error code (if any) .X used .Y used Memory: logical tables updated STATUS, RSSTAT updated Flags: .C = 1 —* error E X A M P LE : LDA #1 JSR $FFC3 ;CLOSE...
  • Page 440 COMMODORE 128 RESULTS: .A = error code (if any) Registers: .X used .Y used LA, FA, SA, DFLTN Memory: STATUS, RSSTAT updated .C = 1 — » error Flags: E X A M P LE : LDX #1 JSR $FFC6 ;CHKIN...
  • Page 441 THE COMMODORE 128 OPERATING SYSTEM E X A M P LE : LDX # 1 JSR $FFC9 ;CKOUT BCS error CKOUT establishes an output channel to the device associated with the logical address (LA) passed in .X, in preparation for a call to BSOUT. The Kernal variable DFLTO ($9A) is updated to indicate the current output device and the variables LA, FA and SA are updated with the file’s parameters from its entry in...
  • Page 442 COMMODORE 128 The path to CLRCH is through an indirect RAM vector at $322. Applications may therefore provide their own CLRCH procedures or supplement the system ’s by redirecting this vector to their own routine. 27. $FFCF BASIN ;input from channel...
  • Page 443 THE COMMODORE 128 OPERATING SYSTEM e. Keyboard data is input by turning on the cursor, reading characters from the keyboard buffer, and echoing them on the screen until a carriage return is encountered. Characters are then returned one at a time from the screen until all characters input have been passed, including the carriage return.
  • Page 444 COMMODORE 128 29. $FFD5 LOAD ;load from file PREPARATION: .A = 0 — > LOAD Registers: .A > 0 — > VERIFY .X = load adr lo (if SA = 0) .Y = load adr hi (if SA = 0)
  • Page 445 THE COMMODORE 128 OPERATING SYSTEM device-specific tasks for serial and cassette LOADs. You cannot LOAD from RS-232 devices, the screen or the keyboard. While LOAD performs all the tasks of an OPEN, it does not create any logical files as an OPEN does. Also note that LOAD cannot “...
  • Page 446 COMMODORE 128 LDA # 0 ;save from bank (RAM 0) LDX # 0 ;fnbank (RAM 0) JSR $FF68 ;SETBNK LDA # 0 ;la (not used) LDX # 8 LDY # 0 ;sa (cassette only) JSR $FFBA ;SETLFS LDA #start ;pointer to start address LDX end ;ending address lo...
  • Page 447 THE COMMODORE 128 OPERATING SYSTEM RESULTS: Registers: none Memory: TIME ($A0) updated Flags: none E X A M P LE : LDA # 0 ;reset clock JSR $FFDB ;SETTIM SETTIM sets the system software (jiffic) clock, which counts sixtieths (1/60) of a second.
  • Page 448 COMMODORE 128 RESULTS: Registers: .A = last keyboard row .X = used (if STOP key) Memory: none Flags: status valid E X A M P L E : JSR $FFE1 ;scan STOP key BEQ stop ;branch if down STOP checks a Kemal variable STKEY ($91), which is updated by UDTIM during normal IRQ processing and contains the last scan of keyboard column C7.
  • Page 449 THE COMMODORE 128 OPERATING SYSTEM a. Keyboard input: A character is removed from the keyboard buffer and passed in .A. If the buffer is empty, a null ($00) is returned. b. RS-232 input: A character is removed from the RS-232 input buffer at $C00 and passed in .A.
  • Page 450 COMMODORE 128 RESULTS: Registers: .A used .X used TIME, TIMER, STKEY updated Memory: none Flags: EX A M P LE : JSR $FFEA ;UDTIM UDTIM increments the system software (jiffie) clock, which counts sixtieths (1/60) of a second when called by the system 60Hz IRQ. TIME, a 3-byte counter located at $A0, is reset at the 24-hour point.
  • Page 451 THE COMMODORE 128 OPERATING SYSTEM 38. $FFF0 PLOT ;read/set cursor position PREPARATION: .X = cursor line Registers: .Y = cursor column Memory: system map ,C = 0 — » set cursor position Flags: .C = 1 — > get cursor position...
  • Page 452 COMMODORE 128 39. $FFF3 IOBASE ;read base address of I/O block PREPARATION: Registers: none system map Memory: none Flags: Calls: none RESULTS: .X = lsb of I/O block Registers: .Y = msb of I/O block none Memory: Flags: none E X A M P LE : ;find the I/O block...
  • Page 453 JSR $FF47 ;setup for fast serial input The C 128/1571 fast serial protocol utilizes CIA 1 (6526 at $DC00) and a special driver circuit controlled in part by the MMU (at $D500). SPINP and SPOUT are routines used by the system to set up the CIA and fast serial driver circuit for input or output.
  • Page 454 COMMODORE 128 3. $FF4D C64MODE ;reconfigure system as a C64 PREPARATION: Registers: none Memory: system map none Flags: none Calls: RESULTS: none Registers: none Memory: none Flags: E X A M P LE : JMP $FF4D ;switch to C64 mode There is no return from this routine.
  • Page 455 THE COMMODORE 128 OPERATING SYSTEM EX A M P LE : LDA # $ 0 0 ;setup C l28 base address ;low STA $DF02 LDA # $ 2 0 STA $DF03 ;high ;setup expansion RAM address LDA # $ 0 0 STA $DF04 ;low...
  • Page 456 COMMODORE 128 5. $FF53 BOOT CALL ;boot load program from disk PREPARATION: Registers: .A = drive number (ASCII) .X = device number (0-31) Memory: system map Flags: none Calls: none RESULTS: Registers: .A used .X used .Y used Memory: changed as per command...
  • Page 457 THE COMMODORE 128 OPERATING SYSTEM The following examples illustrate the flexibility of this layout. This loads and runs a BASIC program: :key » $00,$00,$00.$00 :no other BOOT sector — -> NAM E,$00 :message “ NAM E” :no filename :code $A2,$13,$A0,$0B $4C,$A5,$AF ->...
  • Page 458 COMMODORE 128 6. $FF56 PHOENIX ;init function cartridges PREPARATION: Registers: none Memory: cartridge map Flags: none Calls: none RESULTS: Registers: .A used .X used .Y used Memory: changed as per command Flags: none E X A M P LE : JSR $FF56 ;PHOENIX...
  • Page 459 THE COMMODORE 128 OPERATING SYSTEM E X A M P LE : LDY # $ 6 0 ;find an available SA AGAIN INY CPY #$ 6 F BCS TOO MANY ;too many files open JSR $FF5C ;LKUPSA BCC AGAIN ;get another if in use LKUPLA and LKUPSA are Kernal routines used primarily by BASIC DOS commands to work around a user’s open disk channels.
  • Page 460 COMMODORE 128 10. $FF62 DLCHR ;init 80-col character RAM PREPARATION: Registers: none Memory: system map Flags: none Calls: none RESULTS: Registers: .A used .X used .Y used Memory: 8563 character RAM initialized Flags: none E X A M P LE : JSR $FF62 initialize 8563 char, defns.
  • Page 461 THE COMMODORE 128 OPERATING SYSTEM EX A M P LE : LDA #$FA pointer to string address LDY #$06 length LDX #$0A key # (HELP key) JSR $FF65 install new key def’n BCS NO ROOM >000FA 00 13 00 :ptr to $1300 bank 0 >01300 53 54 52 49 4E 47 :“...
  • Page 462 Refer to the Memory Management Unit in the Commodore 128 section later in this chapter for details concern­ ing memory configuration. The C128 Kemal memory banks are assigned as follows:...
  • Page 463 THE COMMODORE 128 OPERATING SYSTEM 14. $FF6E JSRFAR ;gosub in another bank 15. $FF71 JMPFAR ;goto another bank PREPARATION: none Registers: Memory: system map, also: bank (0-15) PC high $04 -> PC low .S (status) Flags: none none Calls: RESULTS:...
  • Page 464 COMMODORE 128 ;want to call $2000 in bank 1 LDA #1 LDY # $ 2 0 LDX # $0 0 STA $02 STY $03 STX $04 JSR $FF6E ;JSRFAR LDA $05 ;restore status and registers LDA $06 LDX $07 LDY $08 16.
  • Page 465 THE COMMODORE 128 OPERATING SYSTEM common (shared) RAM at $2A2 which switches banks, loads the data, restores the user’s bank, and returns. When calling a non-system bank, the user should take necessary precautions to ensure that interrupts (IRQ’s and N M I’s) will be handled properly (or disabled beforehand).
  • Page 466 COMMODORE 128 18. $FF7A INDCMP ;CMP (cmpvec),Y to any bank PREPARATION: Registers: .A = data .X = bank (0-15) .Y = index Memory: setup indirect vector setup CMPVEC ($2C8) pointer Flags: none Calls: none RESULTS: Registers: .X used Memory: none...
  • Page 467 JMP to PRIMM. There must be a valid address on the stack. C l28 DEVICE NUMBERS The following are the device numbers for the Commodore 128: 0 — * Keyboard 1 — » Cassette 2 ->...
  • Page 468 THE MEMORY MANAGEMENT U N IT (MMU) In Commodore 128 mode, all memory management is controlled through a series of I/O registers called the Memory Management Unit (MMU). The Memory Manage­ ment Unit consists of memory locations that reside between $D500 and $D50B and $FF00 and $FF04.
  • Page 469 THE COMMODORE 128 OPERATING SYSTEM When this occurs, some features of the MMU are no longer available to the programmer. So before switching out I/O in the $D000-$DFFF range, make sure you have made all the manipulations you need on the MMU (particularly, preselecting the preconfiguration register values for the load configuration registers).
  • Page 470 ROM, RAM and input/output configurations for the entire Commo­ dore 128 memory in C l 28 mode. (The MMU is not present at all in the C64 memory map.) The CR is located at address $D500 when I/O is available and at address $FF00 at all times.
  • Page 471 8502) into the CR. Reading an LCR returns the value stored in the currently inaccessible PCR. The MMU registers ranging from $FF00 through $FF04 are always present in the Commodore 128 memory, regardless of the memory configuration. Bit 1 in the CR specifies how the microprocessor accesses the address range $4000 through $7FFF, called ROM LOW memory.
  • Page 472 PRECONFIGURING COMMODORE 128 MEMORY As noted, the Configuration Register in the MMU is the means by which the Commo­ dore 128 organizes the memory layout. Commodore 128 memory management has a mechanism that allows the programmer to set up four predefined memory configura­...
  • Page 473 THE COMMODORE 128 OPERATING SYSTEM corresponds to LCR B, and so on). The format for the Load Configuration' and Preconfiguration Registers is the same as for the Configuration Register. The four LCRs and four PCRs are all initialized to zero.
  • Page 474 COMMODORE 128 PART 1 LDA # $ 0 E Load accumulator with 14 This selects I/O ($D000-$DFFF) RAM ($4000-$7FFF,$8000-$BFFF) Kernal and Character ROM ($C000-$FFFF) RAM Bank 0 STA $D501 Store in PCR A— no immediate results Place interim part of the program here...
  • Page 475 CP/M operating system from disk. The value of bit 0 in the Mode Configuration Register in this case is 0. When the Z80A takes control of the Commodore 128, all memory references from $0000 through $0FFF are translated to $D000 through $DFFF, where the CP/M BIOS exists in ROM.
  • Page 476 C l 28 mode. Bit 6 selects the operating system that takes over the Commodore 128. Upon power-up or reset, this bit is cleared (0) to enable all of the MMU registers and Commodore 128 mode features.
  • Page 477 (1), then 8K is common, and if both bits 2 and 3 are high (1), then 16K of RAM becomes common. (These bits have no effect in Commodore 64 mode). The reset values of these bits are both 0. See Figure 13-8 to understand how the two RAM banks share...
  • Page 478 COMMODORE 128 BANK 1 BANK 1 BANKO BANKO Hi Common RAM Hi Common RAM $F000 • $F000 $0FFF S03FF Low Common RAM Low Common RAM 4KCOMMON RAM 1KCOMMON RAM BANKO BANK 1 BANKO BANK 1 Hi Common $E000 - Common...
  • Page 479 THE COMMODORE 128 OPERATING SYSTEM a section of the bottom of RAM bank 0 replaces the corresponding section of RAM bank 1 for all RAM address accesses. If bit 3 is set high (1) and bit 2 is set low (0), a section of the top RAM bank 0 replaces the corresponding section of RAM bank 1 for all RAM address accesses.
  • Page 480 COMMODORE 128 THE PAGE POINTERS The Commodore 128 has a feature that allows you to relocate page 0 ($00-$FF) and page 1 ($100-$1FF) of memory. Certain applications may require you to keep page 0 intact while running BASIC, switch out the BASIC ROM, resume processing within the control of your machine language program, and then switch 0 page and the BASIC ROM back in.
  • Page 481 THE COMMODORE 128 OPERATING SYSTEM Bit 0 of both high-byte page pointers (0 and 1) corresponds to the RAM bank number for any address access in page zero or one. The page zero high byte (bit 0) normally overrides the RAM bank set by the configuration register. However, if common RAM (at the bottom of RAM bank 0) is specified, the high-byte pointer for pages zero and one is ignored and pages zero and one appear in common RAM.
  • Page 482 COMMODORE 128 The first 9 bytes of the Commodore 128 auto start sequence are: BYTE $X000 Cold Start Vector $X003 Warm Start Vector (not used but must be specified) $X006 Cartridge I.D . (The I.D . = 1 for an auto start card) $X007 The ASCII Character “...
  • Page 483 THE COMMODORE 128 SCREEN EDITOR The Commodore screen editor is among the easiest to use of all screen editors. As soon as you turn on the computer, the screen editor is available to you. You don’t have to call any additional text editors. Using the keys for manipulating text, the screen editor gives you more freedom than most other editors.
  • Page 484 CHARACTER FUNCTION Underline ON (80-column screen only) Produces bell tone Tab character Line feed character Disable shift Commodore key (formerly code 9) Enable shift Commodore key (formerly code Turn ON flash on (80-column screen only) Tab set/clear Escape character Underline OFF (80-column screen only)
  • Page 485 Entries 17, 18, and 24 are table pointers, and are not callable routines. Entries 19-23 are considered indirect vectors, not true entry points. This chapter has presented the Commodore 128 operating system. Chapter 16 provides information on CP/M on the Commodore 128 and Commodore 64 memory maps.
  • Page 487 CP/M 3.0 ON THE COMMODORE 128...
  • Page 488 CP/M® is a microprocessor operating system produced by Digital Research, Inc. (DRI). The version of CP/M used on the Commodore 128 is CP/M Plus® Version 3.0. In this chapter, CP/M is generally referred to as CP/M 3.0, or simply CP/M.
  • Page 489 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. They include such things as a selectively displayed disk status line, a virtual disk drive, local/remote handling of keyboard codes, programmable function keys (strings) and a number of additional functions/characters that are assigned to various keys.
  • Page 490 COMMODORE 128 USER NUMBER CP/M 3.0 further identifies all files by assigning each one a user number, which can range from 0 to 15. CP/M 3.0 assigns the user number to a file when the file is created. User numbers allow you to separate your files into sixteen file groups.
  • Page 491 Built-in commands are entered in the computer’s memory when CP/M 3.0 is loaded, and are always available for use, regardless of which disk is in which drive. Table 14— 3 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 492 USING CONTROL CHARACTERS FOR LINE EDITING Table 14— 5 lists the line-editing control characters for CP/M 3.0 on the Commodore 128. H O W TO MAKE COPIES OF CP/M 3.0 DISKS A N D FILES NOTE: The Digital Research Inc.
  • Page 493 CP/M 3.0 ON THE COMMODORE 128 NAME FUNCTION DATE Sets or displays the date and time. DEVICE Assigns logical CP/M devices to one or more physical devices, changes device driver protocol and baud rates, or sets console screen size. Displays directory with files and their characteristics.
  • Page 494 COMMODORE 128 CHARACTER MEANING CTRL-A or Moves the cursor one character to the left. SHIFT-LEFT CURSOR CTRL-B Moves the cursor to the beginning of the command line without having any effect on the contents of the line. If the cursor is at the beginning, CTRL-B moves it to the end o f the line.
  • Page 495 MAKING COPIES W ITH A SINGLE DISK DRIVE You can copy the contents of a disk with a single Commodore disk drive (1541 or 1571). For example, use the following sequence of commands to create a bootable CP/M system disk. First type: A >FO RM A T...
  • Page 496 (TPA), the region of memory where all application programs execute. The CCP contains the Program Loader Module, which loads transient (applications) programs from disk into the TPA for execution. On the Commodore 128, a 58K to 59K TPA area is provided for CP/M.
  • Page 497 I/O, however, this relationship is more complex. The BDOS file may make many BIOS function calls to perform a single BDOS file I/O function. BDOS disk I/O is in terms of 128-byte logical records. BIOS disk I/O is in terms of physical sectors and tracks.
  • Page 498 JM P SETBNK Specify banks for inter-bank MOVE. JM P XMOVE Set banks for an inter-bank MOVE. JM P USERF Commodore CP/M system functions. JM P RESERV1 Reserved for future use. JM P RESERV2 Reserved for future use. T ab le 14-6. C P /M 3.0 B IO S Jump Vectors...
  • Page 499 Note that two entry points are reserved for future versions of CP/M, and one entry point is provided for the Commodore system functions. Table 14-7 shows the five categories of system operations and the function calls that accomplish these operations.
  • Page 500 C O M M O N SYSTEM M E M O R Y F000 EO O O DOOO COOO B O O O B A N K E D SYSTEM AOOO 9000 8000 7000 6000 5000 4000 C C P BUFFER 3000 VIC SCREEN 8502 BIOS...
  • Page 501 Commodore format is single-sided Commodore GCR, which is compatible with the CP/M 2.2 that runs on the Commodore 64. With this format, the File Control Block (FCB) is set up as 32 tracks of 17 sectors each and a track offset of 2. The BIOS routine adds a 1 to tracks greater than 18 (this is the C64 directory track).
  • Page 502 The skew is used only with the new larger format. A different skew table is used for each region of the disk. The third Commodore format is a GCR double-sided format. The disk is treated as 1276 sectors of data with a track offset of 0. Side 1 is used first; then side 2 is used.
  • Page 503 CP/M 3.0 ON THE COMMODORE 128 S E C T O R ..............................................................U sed by C P /M . Boot S ector (System ). D irecto ry S ector (Disk DOS), N ot used by C P /M .
  • Page 504 COMMODORE 128 S E C T O R ....................................................................................................................................................................................................................................................................................................................1 0 ................................... 1 1 ................................... 1 2 ............................................................................................................................................................................................................................................................................2 1 ................................. 2 2 .................................
  • Page 505 However CP/M-86 programs cannot be run on the C128, since on the C l 28, CP/M Plus runs on a Z80, not an 8088. When used with the 1571 Disk Drive, the Commodore 128 supports a variety of double-density MFM disk formats (for reading and/or writing), including:...
  • Page 506 ■ Control The alpha shift mode is toggled on/off by pressing the Commodore (O ) key. When this mode is turned on, a small white box appears on the bottom of the screen. The first key that is pressed thereafter is the key to be defined. The current hex value assigned to this key is displayed, and the user can then type the new hex code for the key, or abort by typing a non-hex key.
  • Page 507 CP/M 3.0 O N THE COMMODORE 128 CODE FUNCTION Null (same as not pressing a key) Olh to 7Fh Normal ASCII codes 80h to 9Fh String assigned AOh to AFh 80-column character color BOh to BFh 80-column background color COh to CFh 40-column character color...
  • Page 508 Terminal emulation is handled by the Z80 BIOS, and the terminal function is handled primarily in the Z80 ROM. The following section shows the various terminal emulation protocols supported by Commodore 128 CP/M. TERMINAL EM ULATION PROTOCOLS FUNCTION CHARACTER SEQUENCE...
  • Page 509 CP/M 3.0 O N THE COMMODORE 128 N O TE: The following have been added to allow the system to emulate the KayPro II display more closely. CHARACTER FUNCTION SEQUENCE Home Cursor Control CEL (Clear to End of Line) Control-X...
  • Page 510: System Operations

    Z80 is re-enabled; it then looks at the command status and takes the appropriate actions. The 8502 BIOS commands are defined in Appendix K. This concludes the summary explanation of the Commodore 128 CP/M system. However, the Commodore 128 CP/M System includes many additional Commodore 128-dependent routines and functions that are performed by the Z80 microprocessor.
  • Page 511 COMMODORE 128 COMMODORE 64 MEMORY MAPS...
  • Page 512 Refer to the memory map whenever you need directions throughout the memory of your Commodore 128. Addresses listed with more than one address label are used for more than one purpose. To BASIC, the variable has one purpose; to the Machine Language Monitor, it may have another.
  • Page 513 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS C128 Memory M ap (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION COUNT OOOD INPUT BUF.PTR / # OF SUBSCRIPTS DIM FLG OOOE FLAG: DEFAULT ARRAY DIMENSION...
  • Page 514 COMMODORE 128 C l28 Memory M ap (continued) M EM ORY ADDRESS HEXADECIM AL DECIMAL LABEL ADDRESS ADDRESS DESCRIPTION BASIC ZERO PAGE STORAGE DATLIN 0041 CURRENT DATA LINE NUMBER DATPTR 0043 CURRENT DATA ITEM ADDRESS INPPTR 0045 VECTOR: INPUT ROUTINE...
  • Page 515 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS MEMORY ADDRESS HEXADECIMAL DECIMAL ADDRESS ADDRESS DESCRIPTION LABEL BASIC ZERO PAGE STORAGE DSCTM P PAINT-LEFT FLAG LEFT__FLAG F A C #1E X P O N E N T FACEXP M ONITOR Z .P. STORAGE IN FAC...
  • Page 516 COMMODORE 128 C128 Memory Map (continued) MEMORY ADDRESS HEXADECIMAL DECIMAL LABEL ADDRESS ADDRESS DESCRIPTION BASIC ZERO PAGE STORAGE PARSTX 0081 OLDSTK 0082 BASIC Z-P STORAGE FOR GRAPHIC COMMANDS CURRENT COLOR SELECTED COLSEL 0083 M U L T IC O L O R _l 0084 MULTICOLOR—2...
  • Page 517 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION KERNAL/EDITOR STORAGE INBIT 00A7 RS-232 RCVR INPUT BIT STORAGE CASSETTE SHORT COUNT SHCNL 00A8 RS-232 RCVR BIT COUNT IN...
  • Page 518 COMMODORE 128 C128 Memory Map (continued) MEMORY ADDRESS HEXADECIMAL DECIMAL LABEL ADDRESS ADDRESS DESCRIPTION KERNAL/EDITOR STORAGE BANK FOR CURRENT LOAD/SAVE/ VERIFY OPERATION FNBANK 00C7 BANK WHERE CURRENT FN IS FOUND (AT ‘FN A D R ’) RIBUF RS-232 INPUT BUFFER POINTER...
  • Page 519 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS MEMORY ADDRESS HEXADECIMAL DECIMAL LABEL ADDRESS ADDRESS DESCRIPTION LOCAL SCREEN EDITOR VARIABLES. THESE ARE SWAPPED OUT TO $0A40 WHEN SCREEN (40/80) MODE CHANGES WINDOW LOWER LIMIT SCBOT 00E4 SCTOP 00E5...
  • Page 520 COMMODORE 128 C128 Memory Map (continued) MEMORY HEXADECIMAL DECIMAL ADDRESS ADDRESS DESCRIPTION LABEL ADDRESS BASIC/DOS INTERFACE VARS DOSF1L DOS FILENAM E 1 LEN 0 1 1 1 DOSDS1 DOS DISK DRIVE 1 0 1 1 2 DOSF2L 0113 DOS FILENAM E 2 LEN...
  • Page 521 THE COMMODORE 128 AN D COMMODORE 64 MEMORY MAPS MEMORY ADDRESS HEXADECIMAL DECIMAL LABEL ADDRESS ADDRESS DESCRIPTION BASIC/DOS INTERFACE VARS FETCH 02A2 L D A (-),Y FROM ANY BANK FETVEC 02AA STASH 02AF ST A (-),Y TO ANY BANK STAVEC...
  • Page 522 COMMODORE 128 C128 Memory Map (continued) MEMORY ADDRESS HEXADECIMAL DECIMAL LABEL ADDRESS ADDRESS DESCRIPTION VECTORS IBASIN 0324 KERNAL CHRIN ROUTINE VECTOR IBSOUT 0326 KERNAL CHROUT ROUTINE VECTOR ISTOP 0328 KERNAL STOP ROUTINE VECTOR IGETIN 032A KERNAL GETIN ROUTINE VECTOR ICLALL...
  • Page 523 THE COMMODORE 128 AN D COMMODORE 64 MEMORY MAPS MEMORY ADDRESS HEXADECIMAL DECIMAL ADDRESS DESCRIPTION LABEL ADDRESS INDIRECT LOAD SUBROUTINE AREA NUMERIC CONSTANT FOR BASIC ZERO 03D2 C UR RENT_ CONTEXT FOR SY S,PO K E,PEEK 03D5 BANK FROM BANK CMMD...
  • Page 524 COMMODORE 128 C128 Memory M ap (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION ABSOLUTE KERNAL VARIABLES 2576 RS-232 CONTROL REGI STER M51CTR 0A10 2577 RS-232 COMMAND REGISTER M51CDR 0A11 2578 M51AJB 0A12 RS-232 USER BAUD RATE...
  • Page 525 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS MEMORY DECIMAL ADDRESS HEXADECIMAL LABEL ADDRESS ADDRESS DESCRIPTION GLOBAL ABSOLUTE SCREEN EDITOR DECLARATIONS SAV80A 2609 TEMPORARY FOR O-COL ROUTINES 0A31 SAV80B 0A32 2610 TEMPORARY FOR O-COL ROUTINES 2611 CURCOL 0A33...
  • Page 526 COMMODORE 128 C128 Memory M ap (continued) MEMORY ADDRESS HEXADECIMAL DECIMAL LABEL ADDRESS ADDRESS DESCRIPTION FUNCTION KEY ROM CARD TABLES 0AC1 2753 PHYSICAL ADDRESS TABLE(IDS OF LOGGED-IN CARDS) D K _FLA G 0AC5 2757 RESERVED FOR FOREIGN SCREEN EDITORS 0AC6...
  • Page 527 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS MEMORY ADDRESS HEXADECIMAL DECIMAL LABEL ADDRESS ADDRESS DESCRIPTION DOS/VSP AREA COSVAL 114C 4428 COSINE OF VALUE OF ANGLE ANGCNT 114E 4430 TEMPS FOR ANGLE DISTANCE ROUTINES BASIC GRAPHIC VARIABLES. THE FOLLOW ING 24 BYTES ARE MULTIPLY DEFINED.
  • Page 528 COMMODORE 128 C128 M emory M ap (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION SHAPE AND M OVE-SHAPE VARIABLES 4436 REPLACE SHAPE MODE GETTYP 1154 4437 STRING PO S’N COUNTER STRPTR 1155 OLDBYT 1156...
  • Page 529 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS MEMORY ADDRESS HEXADECIMAL DECIMAL LABEL ADDRESS ADDRESS DESCRIPTION BASIC GENERAL NON-ZP STORAGE OLDLIN 1200 4608 PREVIOUS BASIC LINE NUMBER OLDTXT 1202 4610 POINTER: BASIC STATEM ENT FOR CONTINUE PRINT USING DECLARATIONS...
  • Page 530 COMMODORE 128 C128 Memory M ap (continued) MEMORY ADDRESS HEXADECIMAL DECIMAL LABEL ADDRESS ADDRESS DESCRIPTION BASIC STORAGE FOR MUSIC VECTORS 123B 4667 TONVAL PARCNT 123E 4668 ATKTAB 123F 4669 SUSTAB 1249 4681 WAVTAB 4691 1253 PULSLW 125D 4701 PULSHI 1267...
  • Page 531 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS MEMORY ADDRESS HEXADECIMAL DECIMAL ADDRESS ADDRESS DESCRIPTION LABEL BASIC SOUND COMMAND VARS 12B1 P O T _T E M P _l 4785 TEM PORARIES FOR ‘PO T ’ FUNCTION 12B2...
  • Page 532 COMMODORE 128 Basic Jump Table (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION FORMAT CONVERSIONS 44806 JM P FOUT AF06 CONVERT F .P . TO ASCII STRING JM P VAT, I 44809 AF09 CONVERT ASCII STRING TO F.P.
  • Page 533 THE COMMODORE 128 AN D COMMODORE 64 MEMORY MAPS M EM ORY ADDRESS HEXADECIM AL D ECIM AL LABEL ADDRESS ADDRESS DESCRIPTION OTHER BASIC ROUTINES JM P GPLOT AF75 44917 JM P CIRSUB AF78 44920 JM P RUN AF7B 44923...
  • Page 534 COMMODORE 128 Editor Jump Table (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION JM P SCNKEY C012 49170 SCAN KEYBOARD SUBROUTINE JM P REPEAT C015 49173 HANDLE REPEAT KEY&STORE DECODED KEY JM P PLOT C018...
  • Page 535 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION VIC CHIP REGISTERS VICREG17 D O ll 53265 VIC CONTROL REGISTER 1 RASTER COMPARE BIT EXTENDED COLOR TEXT...
  • Page 536 COMMODORE 128 C128 Memory M ap (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION VIC CHIP REGISTERS D019 53273 VIC INTERRUPT FLAG REGISTER VICREG25 (1 = IRQ OCCURRED) SET ON ANY ENABLED VIC IRQ CONDITION...
  • Page 537 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS M EM ORY HEXADECIM AL DECIM AL ADDRESS DESCRIPTION LABEL ADDRESS ADDRESS VIC CHIP REGISTERS D02B 53291 SPRITE 4 COLOR VICREG43 VICREG44 53292 SPRITE 5 COLOR D02C 53293 SPRITE 6 COLOR...
  • Page 538 COMMODORE 128 C128 Memory Map (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION SID REGISTERS SIDREG6 D406 54278 VOICE 1 SUSTAIN/RELEASE 7 -4 SUSTAIN (0-15) 3 -0 RELEASE (0-15) SIDREG7 D407 54279 VOICE 2 FREQUENCY LO...
  • Page 539 THE COMMODORE 128 AN D COMMODORE 64 MEMORY MAPS M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION SID REGISTERS SIDREG18 D412 54290 VOICE 3 CONTROL REGISTER NOISE (1 NOISE) PULSE (1 PULSE) SAW TOOTH) TRIANGLE) (l = r...
  • Page 540 COMMODORE 128 C128 Memory Map (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL ADDRESS LABEL ADDRESS DESCRIPTION SID REGISTERS SIDREG24 D418 54296 MODE/VOLUME CUTOFF VOICE 3 OUTPUT (1 = OFF) SELECT HI-PASS FILTER ( l = ON) SELECT BAND-PASS FILTER...
  • Page 541 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION C128 MEMORY M ANAGEM ENT UNIT, PRIM ARY REGISTERS IMPLEMENTS C128, C64, & CP/M 3.0 MODES 54534 RAM CONFIGURATION REGISTER...
  • Page 542 COMMODORE 128 C128 Memory Map (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL DESCRIPTION ADDRESS ADDRESS ADDRESS AND DATA REGISTER BITS D600------ WRITE READ VBLANK — — — — STATUS VDCDAT D601 54785 8563 DATA REGISTER D601- -DATA...
  • Page 543 THE COMMODORE 128 AN D COMMODORE 64 MEMORY MAPS M EM ORY HEXADECIM AL DECIM AL ADDRESS ADDRESS LABEL ADDRESS DESCRIPTION 6526 C IA # 1 , COMPLEX INTERFACE ADAPTER # 1 KEYBOARD, JOYSTICK, PADDLES , LIGHTPEN, FAST DISK 56325...
  • Page 544 COMMODORE 128 C128 Memory Map (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION 56577 PORT B, USER PORT, RS-232 D2PRB D D 01 BITS PRBO : USER PORT / RS-232 RECEIVED DATA PRB1 : USER PORT / RS-232...
  • Page 545 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION INTERRUPT PENDING (1 = INT. W AITING TO BE SERVICED) END OF BLOCK (1 = TRANSFER COMPLETE) FAULT (1 = BLOCK VERIFY ERROR) SIZE (0 = EXP.
  • Page 546 COMMODORE 128 C128 Memory Map (continued) M EM ORY ADDRESS HEXADECIM AL DECIM AL LABEL ADDRESS ADDRESS DESCRIPTION NOT USED EXPANSION BANK NUMBER DM A DAL DF07 57095 LSB OF BYTE COUNT DMA DAH DF08 57096 MSB OF BYTE COUNT (BLOCK...
  • Page 547 THE COMMODORE 128 AN D COMMODORE 64 MEMORY MAPS KERNAL JUMP TABLE NEW ENTRIES FOR C l 28 JM P SPIN SPOUT FF47 65351 SET UP FAST SERIAL PORT FOR I/O JM P CLOSE ALL FF4A 65354 CLOSE ALL LOGICAL...
  • Page 548 COMMODORE 128 C128 Memory M ap (continued) STANDARD KERNAL JUM P TABLE 65412 INIT I/O DEVICES (PORTS, JM P IOINIT FF84 TIM ERS, ETC.) 65415 INITIALIZE RAM AND JM P RAMTAS FF87 BUFFERS FOR SYSTEM 65418 RESTORE VECTORS TO FF8A...
  • Page 549 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS STANDARD KERNAL JUM P TABLE JM P UDTIM FFEA CLOCK 65514 INCREM ENT INTERNAL CLOCK JM P SCRORG FFED 65517 RETURN SCREEN WINDOW SIZE (EDITOR) JM P PLOT FFFO 65520...
  • Page 550 The monitor respects it too. System. Vector in RAMI at $FFF8. Set at power-up to C128MODE, user may redirect it to his code. Taken at reset always providing user with control (protection) from reset. COMMODORE 64 MEMORY MAP DECIM AL LABEL LOCATION DESCRIPTION...
  • Page 551 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS DECIMAL LABEL ADDRESS LOCATION DESCRIPTION TRM POS 0009 Screen Column From Last TAB VERCK 000A Flag: 0 = Load, 1 = Verify COUNT 000B Input Buffer Pointer/No. o f Subscripts...
  • Page 552 COMMODORE 128 Commodore 64 Memory Map (continued) DECIMAL LABEL ADDRESS LOCATION DESCRIPTION SGNFLG 0067 Pointer: Series Evaluation Constant BITS 0068 Floating Accum. # 1 : Overflow Digit ARGEXP 0069 Floating-Point Accumulator # 2 : Exponent 006A -006D 106-109 ARGHO Floating Accum. # 2 : Mantissa...
  • Page 553 THE COMMODORE 328 A N D COMMODORE 64 MEMORY MAPS DECIMAL LABEL ADDRESS LOCATION DESCRIPTION RIDATA OOAA RS-232 Input Byte Buffer/Cassette Temp RIPRTY OOAB RS-232 Input Parity / Cassette Short 00AC-00AD 172-173 Pointer: Tape Buffer/Screen Scrolling OOAE-OOAF 174-175 Tape End Addresses / End of Program...
  • Page 554 COMMODORE 128 C o m m o d o re 6 4 M e m o ry M a p (co n tin u ed ) DECIMAL LOCATION LABEL ADDRESS DESCRIPTION TBLX Current Cursor Physical Line 00D6 Number 00D7 Temp Data Area...
  • Page 555 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS DECIMAL LABEL ADDRESS LOCATION DESCRIPTION M51AJB 0295-0296 661-662 RS-232 Non-Standard BPS (Time/2-100) USA RSSTAT 0297 RS-232: 6551 Status Register Image BITNUM RS-232 Number o f Bits Left to Send 0298...
  • Page 556 Input/Output Devices and Color or Character Generator ROM or RAM— 4096 Bytes E000-FFFF 57344-65535 KERNAL ROM— 8192 Bytes (or 8K RAM) COMMODORE 64 IN P U T /O U T P U T ASSIGNMENTS DECIMAL BITS DESCRIPTION 0000 6510 Data Direction Register...
  • Page 557 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS DECIMAL BITS DESCRIPTION D 000-D02E 53248-54271 MOS 6566 VIDEO INTERFACE CONTROLLER (VIC) DOOO 53248 Spr te 0 D001 53249 Spr te 0 Y Pos D002 53250 Spr te 1 X Pos...
  • Page 558 COMMODORE 128 Commodore 64 Input/Output Assignments (continued) DECIMAL BITS DESCRIPTION 3 -1 Character Dot-Data Base Address (inside VIC) D019 53273 VIC Interrupt Flag Register (Bit = 1: IRQ Occurred) Set on Any Enabled VIC IRQ Condition Light-Pen Triggered IRQ Flag...
  • Page 559 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS DECIM AL BITS DESCRIPTION 7 -4 D403 54275 Unused 3 -0 Voice 1: Pulse W aveform Width— High-Nybble D404 54276 Voice 1: Control Register Select Random Noise W aveform , 1 =...
  • Page 560 COMMODORE 128 Commodore 64 Input/Output Assignments (continued) DECIM AL BITS DESCRIPTION 3 -0 Select Decay Cycle Duration: 0-15 D40D 54285 Envelope Generator 2: Sustain / Release Cycle Control 7^» Select Sustain Cycle Duration: 0-15 3 -0 Select Release Cycle Duration: 0-15...
  • Page 561 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS DECIM AL BITS DESCRIPTION Filter Voice 1 Output: 1 = Yes, 0 = D418 54296 Select Filter Mode and Volume Cut-Off Voice 3 Output: 1 = Off, 0 = On...
  • Page 562 COMMODORE 128 Commodore 64 Input/Output Assignments (continued) DECIMAL BITS DESCRIPTION DC07 56327 Timer B: High-Byte DC08 56328 Time-of-Day Clock: 1/10 Seconds DC09 56329 Time-of-Day Clock: Seconds DCOA 56330 Time-of-Day Clock: Minutes DCOB 56331 Time-of-Day Clock: Hours + AM/PM Flag (Bit 7)
  • Page 563 THE COMMODORE 128 A N D COMMODORE 64 MEMORY MAPS DECIM AL BITS DESCRIPTION DDOO-DDFF 56576-56831 MOS 6526 Complex Interface Adapter (CIA) # 2 DDOO 56576 Data Port A (Serial Bus, RS-232, VIC Memory Control) Serial Bus Data Input Serial Bus Clock Pulse Input...
  • Page 564 COMMODORE 128 Commodore 64 Input/Output Assignments (continued) DECIM AL BITS DESCRIPTION Timer A Counts: 1 = CNT Signals, 0 = System 02 Clock Force Load Timer A: 1 = Yes Timer A Run Mode: 1 = One-Shot, 0 = Continuous...
  • Page 565 16____ C128 HARDWARE SPECIFICATIONS...
  • Page 566 The C l 28 personal computer is compatible with C64 software and peripherals. In addition to C64 compatibility, a C l 28 mode exists in which 128K of RAM is available for system/user use. BASIC version 7.0 is the default language. The Commodore Kernal is supported in a compatible fashion.
  • Page 567: Chapter 16 C L 28 H Ardware Specifications

    C l 28 HARDWARE SPECIFICATIONS SYSTEM ARCHITECTURE The C l 28 computer utilizes a shared bus structure similar to that of the C64. The shared bus emulates dual-port RAM and ROM, which allows the character ROM, color RAM and system RAM to be shared by both the microprocessor and the 8564 VIC video controller, with no interference to each other.
  • Page 568: System Specification

    The cassette port is implemented using the zero page ports available on the 8502 and software control of hardware handshaking. The Commodore serial bus port is imple­ mented in a similar manner using a 6526 CIA for I/O. The serial bus works with Commodore serial components, and in C64 mode is actually driven by the software routines contained in the C64.
  • Page 570 For more information on this logic, consult the section on the Z80 processor and the C l 28 Schematic, Commodore Part No. 310378. As mentioned above, the Z80 is not in direct communication with the processor data bus, because of the need to adapt the Z80 to 8502 bus protocol.
  • Page 571 C128 HARDWARE SPECIFICATIONS chip by driving the multiplexed address buses. It directly drives system ROM 4 address line 12 to allow the Z80 ROM relocation. Finally, this bus becomes address lines 8 through 15 of the C64 compatible expansion port. During a VIC cycle or a DMA, the MMU pulls TA 12-T A 15 high, while TAg-TAn are tri-stated.
  • Page 572 COMMODORE 128 drive the shared address bus. During DMA, the SA lines, like the TA, are driven backward to drive the processor bus. As noted above, this allows peripheral chips, ROM and RAM to be accessed by a DMA source, like the RAM expansion module. Only the MMU and the 8563 video controller cannot be accessed during DMA.
  • Page 573 CD <-> *-< cr 3=0_ siQ- —1 CL CD CD C\J _ CD CD CD CD Li_ CD CD CD = _ CJ « — < CD CD □ li_ Li_ U_ - tA - ■ W & Figure 16-2. C l 28 M em o ry Map (C 64 M ode)
  • Page 574 The ROMs in C64 mode look like Commodore 64 ROMs. The internal BASIC and Kemal provide the C64 mode with the normal Commodore 64 operating system in ROM. This ROM actually duplicates some of the ROM used in C l 28 mode, but it is necessary, as it is not accessible from C128 mode.
  • Page 575 =3 tr a o) Q . ^ I I I I I I I I 0 3 0 x ~ - a CE CC UJ O d d l i J O cc x x cc 3E X o - a x O —■...
  • Page 576 COMMODORE 128 C l 28 RAM MEMORY O R G A N IZA T IO N As shown in Figure 16-2, the RAM present in the system is actually composed of two banks of 64K by 8 bytes of DRAM. The RAM is accessed by selecting one of the two 64K banks, the maximum address range of the 8502 and Z80, according to the RAM banking rules set in the RAM configuration register of the MMU.
  • Page 577: Performance Specifications

    C l 28 HARDWARE SPECIFICATIONS N O TE: There are actually several memory modes that override parts of the bank as selected here. These modes are mentioned below, and are covered in detail in a later section. For VIC-chip access, one bit in the MMU status register substitutes for extended address line A 16, selecting the proper CAS enable to make it possible to steer the VIC to anywhere in the 128K range.
  • Page 578 COMMODORE 128 Dev: DRAM ROM VIC 8563 4016 2332 LS MMU PLA 8502 Z80 4066 SID TOTAL Signal CIA LOADS T A .-T A ,, . . . — . . . 10 800 — . . . — . . .
  • Page 579 C l28 HARDWARE SPECIFICATIONS THE 8502 MICROPROCESSOR GENERAL DESCRIPTION The 8502 is an HMOSII Technology microprocessor, similar to the 6510/6502. It is the normal operating processor used in C64 and C l28 modes. Software-compatible with the 6510, hence the 6502, the 8502 also features a zero page port used in memory management and cassette implementation.
  • Page 580 COMMODORE 128 SYMBOL UNIT CH ARACTERISTIC Input High Voltage Vss + 2.4 < t> o (in) Vss + 2.2 /RES, P0- P 7,/IRQ, Data — — Input Low Voltage 4>o (in) Vss + 0.5 Vss-0 .3 /RES, P0- P 7,/IRQ, Data Yss + 0.8...
  • Page 581 C128 HARDWARE SPECIFICATIONS RESET — This input is used to reset or start the processor from a power down condition. During the time that this line is held low, writing to or from the processor is inhibited. When a positive edge is detected on the input, the processor will immediately begin the reset sequence.
  • Page 582 COMMODORE 128 Electrical Characteristics Vcc = 5v ± 5% , Vss = Ov, Ts = 0 °C to 70 °C CHARACTERISTIC SYMBOL UNITS AEC setup time Up data setup from < | Up write data hold Data bus to tri-state from AEC...
  • Page 583 C l 28 HARDWARE SPECIFICATIONS 1 M H z C l o c k “ 1 2 M H z C l o c k I / O f l e e Pr o c H c c e s s C l o c k I / O f l e e...
  • Page 584: Hardware Specification

    COMMODORE 128 R 1 5 PH I _ 0 R 1 4 R 1 3 R 1 2 £4 R 1 1 R I G 2_9_ / N M I □ 7 / R E S / I R Q...
  • Page 585: System Description

    C l 28 HARDWARE SPECIFICATIONS the C128 system, but some important electrical and timing specifications of the Z80. For more information on Z80 bus interfacing, consult the Zilog Z80 Data Book. SYSTEM DESCRIPTION The Z80A, a 4MHz version of Zilog’s standard Z80 processor, is included as an alternate processor in the C l 28 system.
  • Page 586 COMMODORE 128 S y s t e n C l o c k Z - 8 0 C l o c k Z - 8 0 A d d r e s s V a l i d 0 d d r...
  • Page 587 C l 28 HARDWARE SPECIFICATIONS When the /Z80EN line goes high, it triggers a Z80 /BUSRQ. The Z80 then relin­ quishes the bus by pulling /BUSACK low. This action drives the 8502 AEC high and (providing VIC does not request a DMA) also drives the 8502 RDY line high, enabling the 8502.
  • Page 588 COMMODORE 128 N O TE: While the Z80 is in either a wait state or a bus acknowledge (/BUSAK) state, a dynamic memory refresh cannot be performed. See Bus Acknowledge. Active low input, driven by external devices. If the In te rru p t Request (/IN T ): interrupt flag IFF is enabled and the bus request (/BUSRQ) line is not active, the processor honors the request interrupt at the end of the current instruction.
  • Page 589: Electrical Specifications

    C l 28 HARDWARE SPECIFICATIONS / M l A ? 32 / M E M R E Q J ^ - C / I N R Q / R D ' AS 35 / W R A 7 37 / R F S H ^ <...
  • Page 590: Dc Operating Characteristics

    COMMODORE 128 PARAM ETER SYMBOL RANGE UNITS Operating Temperature to + 7 0 °C °c -6 5 to + 1 5 0 Storage Temperature -0 .3 to 7.0 Input Voltage Power Dissipation T a b le 16-6. Z 80 A bsolute M a x im u m Ratings DC OPERATING CHARACTERISTICS Table 16-7 shows the maximum DC operating ratings for the Z80.
  • Page 591 THE PROGRAMMED LOGIC ARRAY (PLA) The 8721 C128 PLA is a programmed version of the Commodore 48 Pin Programmable Logic Array (Commodore Part #315011). It provides all the chip selects and other decoded signals that are necessary for the C64, along with a number of such signals new in the C128 system.
  • Page 592 COMMODORE 128 used in C l28 mode to turn the Character ROM on and off in the VIC bank selected; in C l 28 mode the ROM can appear or disappear in any VIC bank. The second of the new functions uses LORAM and HIRAM to select one of two Color RAM banks.
  • Page 593: Physical Description

    C l28 HARDWARE SPECIFICATIONS THE MEMORY MANAGEMENT UNIT (MMU) The MMU is designed to allow complex control of the C l28 system memory resources. Because of the way it handles all the standard C64 modes of operation, it is completely compatible with the C64.
  • Page 594: Pin Description

    COMMODORE 128 NUMBER O F PINS SIGNAL NAMES DESCRIPTION Address Lines In Combined Address Lines In Data Lines In/Out Translated Addr. Lines Out T A s-T A + 5V Ground 2 MHz 4>„ Clock In PHI„ RESET System Reset In...
  • Page 595 CI28 HARDWARE SPECIFICATIONS bus and VA 16 have the processor bus, and no pointer or BIOS translation takes place. This signal occupies pin 16. ■ MUX: The memory multiplex signal, used to clock various sections of the MMU. It is located at pin 17. ■...
  • Page 596 COMMODORE 128 high, then a built-in function ROM has been selected. If MS0 alone is high, then an external function ROM has been selected. Finally, if both are high, the RAM that occupies the particular slot has been selected. In C64 mode, the PLA completely ignores these lines.
  • Page 597 C l 28 HARDWARE SPECIFICATIONS V O D M U X R / W R 1 4 R E C f l 1 3 H 1 2 / Z 8 0 E N f l 1 G T R 1 5 T R 1 4 A 6 / 7 T R 1 3...
  • Page 598 COMMODORE 128 THE 8564 VIDEO INTERFACE CHIP The 8564 VIC chip used in the C l 28 is an updated version of the VIC chip used in current C64 systems. It contains all the video capabilities of the earlier 6567 VIC chip, including high-resolution bit-mapped graphics and movable image blocks.
  • Page 599 C l28 HARDWARE SPECIFICATIONS retaining C64 keyboard compatibility in C64 mode. In this register (register 53295 ($D02F)), bits 0 -2 are directly reflected in output lines K0 to K2, while bits 3-7 are unused, returning high when read. 2 M Hz OPERATION The VIC chip contains a register that allows the C l28 system to operate at 2 MHz instead of the standard 1 MHz speed of the C64.
  • Page 600 COMMODORE 128 ■ A0- A 6: Multiplexed address lines, pins 32 through 38. During row address time, A0- A 8 are driven on A0- A 5. During column address time, A8- A 13 are driven on A0- A5 and A6 is held at 1. During a processor read or write, A0- A 5 serve as address inputs that latch on the low edge or /RAS.
  • Page 601 C128 HARDWARE SPECIFICATIONS SYMBOL RANGE UNIT ITEM Input Voltage -0 .5 to + 7 .0 -0 .5 to + 7 .0 Supply Voltage VC C Operating Temperature 0 to 75 °C -6 5 to 150 Storage Temperature °C Table 16-12. Absolute Maximum Ratings for V IC Chip Below is a list of the maximum operating specifications for the new VIC chip: RANGE UNIT...
  • Page 602: Screen Blanking

    COMMODORE 128 LATCH ENABLE W HEN SET raster IRST ERST Actual count = stored raster count (bit 0) IMDC EMDC M OB-DATA collision (first bit only) (bit 1) IMMC EMMC MOB-MOB collision (first bit only) (bit 2) First negative transition of LP per frame (bit 3) When IRQ/ output low (bit Table 16-14.
  • Page 603 The light pen latch may be triggered only once per frame, and subse­ quent triggers within the same frame will have no effect. For more information on programming the VIC (8564) chip, see Chapter 8, The Power Behind Commodore 128 Graphics.
  • Page 604 COMMODORE 128 V u U PH _I N P H _C L Z80_PH 1 M H Z D IO ■i^o 2M H Z / 1 O R C C 22^> R l 1 CO /R R S 1 9 , 3 ±...
  • Page 605: Video Controller

    C l 28 HARDWARE SPECIFICATIONS THE 8563 VIDEO CONTROLLER The 8563 is a HMOSII technology custom 80-column, color video display controller. The 8563 supplies all necessary signals to interface directly to 16K of DRAM, including refresh, and generated RGBI for use with an external RGBI monitor. For more informa­ tion on the 8563 video controller, see Chapter 10, Programming the 80-Column (8563) Chip.
  • Page 606 COMMODORE 128 B i t B i t 3 Bi t 2 B i t 1 B i t 0 B i t B i t B i t H o r i z o n t o l T o t o 1...
  • Page 607 C l 28 HARDWARE SPECIFICATIONS ■ /RS: Register Select input. A high allows reads and writes to the selected data register. A low allows reads of the status register and writes to the address register. In the system, this line is tied to AO. It is located at pin 8. ■...
  • Page 608 COMMODORE 128 I 3 7 ■ , 1 2 D D 7 V D D 3 3 g D R 7 D D 6 D R 6 oiS. D D 5 D R 5 3 Q ^ 3 3 9...
  • Page 609 C l 28 HARDWARE SPECIFICATIONS 6581 SOUND INTERFACE DEVICE (SID) CH IP SPECIFICATIONS CONCEPT The 6581 Sound Interface Device (SID) is a single-chip, three-voice electronic music synthesizer/sound effects generator compatible with the 8502 and similar microprocessor families. SID provides wide-range, high-resolution control of pitch (frequency), tone color (harmonic content), and dynamics (volume).
  • Page 610 COMMODORE 128 .. ^ ..’ C A P 1 V DD AUDIO OUT c a p EXT IN c a p c a p P O T X P O T Y < t> 2 6581 Figure 16-13. 6581 SID Pin Configuration...
  • Page 611 C l28 HARDWARE SPECIFICATIONS a C L C L C L Figure 16-14. 6581 Block D iag ram...
  • Page 612 SID chips to be daisy-chained or mixed in complex polyphonic systems. For full register descriptions, see Chapter 11, Sound and Music on the Commodore 128. SID PIN DESCRIPTION CAP I A, CAP IB, (PINS 1,2)/ CAP2A.CAP2B (PINS 3,4) These pins are used to connect the two integrating capacitors required by the program­...
  • Page 613 C l 28 HARDWARE SPECIFICATIONS 4>2 (PSN 6) This TTL-level input is the master clock for SID. All oscillator frequencies and envelope rates are referenced to this clock. < J> 2 also controls data transfers between SID and the microprocessor. Data can only be transferred when <|>2 is high. Essentially, 4>2 acts as a high-active chip select as far as data transfers are concerned.
  • Page 614 COMMODORE 128 P O T X ,P O T Y (PINS 24,23) These pins are inputs to the A/D converters used to digitize the position of potentiome­ ters. The conversion process is based on the time constant of a capacitor tied from the POT pin to ground, charged by a potentiometer tied from the POT pin to + 5 volts.
  • Page 615 C l28 HARDWARE SPECIFICATIONS 6581 SID CHARACTERISTICS ABSOLUTE M AXIM UM RATINGS RATING SYMBOL VALUE UNITS Supply Voltage -0 .3 to + 1 7 Supply Voltage -0 .3 to + 7 v in a Input Voltage (analog) -0 .3 to + 1 7 Input Voltage (digital) -0 .3 to + 7 Vind...
  • Page 616 COMMODORE 128 SYMBOL UNITS CHARA CTERISTIC Input Impedance (EXT IN) k fl — R„ Audio Input Voltage (EXT IN) — Audio Output Voltage (AUDIO OUT; 1 kH v o u , load, volume = max) One Voice on: All Voices on:...
  • Page 617 C l28 HARDWARE SPECIFICATIONS ---------------- T w ‘ -------------- -------- ------------ 4 ~ t W H R ,w WWWW_____________ J ~ ~ T A W S 4 ~ j | (-------- t a h n~x~ w m r ~ « wxxxw_______ —...
  • Page 618 COMMODORE 128 entries (24 bytes) consist of the 16-bit values for the eighth octave (C-7 through B-7), then notes in lower octaves can be derived by choosing the appropriate note in the eighth octave and dividing the 16-bit value by two for each octave of difference. As division by two is nothing more than a right-shift of the value, the calculation can easily be accomplished by a simple software routine.
  • Page 619 C128 HARDWARE SPECIFICATIONS ATTACK: 10 ($A) 500 ms DECAY: 300 ms SUSTAIN: 10 ($A) RELEASE: 750 ms Note that the tone can be held at the intermediate SUSTAIN level for as long as desired. The tone will not begin to die away until GATE is cleared. With minor alterations, this basic envelope can be used for brass and woodwinds as well as strings.
  • Page 620 COMMODORE 128 ATTACK: 2 ms DECAY: 6 ms 15 ($F) SUSTAIN: 6 ms RELEASE: The real power of SID lies in the ability to create original sounds rather than simulations of acoustic instruments. The ADSR is capable of creating envelopes which do not correspond to any “...
  • Page 621 C l 28 HARDWARE SPECIFICATIONS 6526 COMPLEX INTERFACE ADAPTER (CIA) CHIP SPECIFICATIONS________ DESCRIPTION The 6526 Complex Interface Adapter (CIA) is an 8502 bus compatible peripheral interface device with extremely flexible timing and I/O capabilities. Figure 16-19 shows the 6526 pin configuration. Figure 16-20 shows the 6526 block diagram. FEATURES ■...
  • Page 622 COMMODORE 128 Figure 16-19. 6526 C IA Pin Configuration...
  • Page 623 C128 HARDWARE SPECIFICATIONS 6 13 D 0-D7 DATA BUS BUFFERS ----------- 7 \ ------------- < > PA P R A B U F F E R S SERIAL B U F F E R P ORT D O R A C N T C N T B U F F E R...
  • Page 624 COMMODORE 128 All inputs contain protection circuitry to prevent damage due to high static discharges. Care should be exercised to prevent unnecessary application o f voltages in excess of the allowable limits. C O M M EN T Stresses above those listed under “ Absolute Maximum Ratings” may cause permanent damage to the device.
  • Page 625 C128 HARDWARE SPECIFICATIONS 6 15 0 2 I N P U T PERIPHERAL DATA OUT DATA IN D B 7 -D B 0 Figure 16-21. 6526 W rite Tim ing Diagram Figure 16-22. 6526 Read Timing Diagram 6526 INTERFACE SIGNALS 4)2—...
  • Page 626 COMMODORE 128 R/W— READ/WRITE IN P U T The R/W signal is normally supplied by the microprocessor and controls the direction of data transfers of the 6526. A high on R/W indicates a read (data transfer out of the 6526), while a low indicates a write (data transfer into the 6526).
  • Page 627 C128 HARDWARE SPECIFICATIONS 6 17 6526 TIMING CHARACTERISTICS (continued) 1 MHz 2MHz SYMBOL CHARACTERISTIC UNIT Read Cycle Port Setup Time — — CS low while < j> 2 high — — Tyvcs(2) Address Setup Time — — Address Hold Time —...
  • Page 628 COMMODORE 128 6526 FU N C TIO N A L DESCRIPTION I/O PARTS (PRA, PRB, DDRA, DDRB). Parts A and B each consist of an 8-bit Peripheral Data Register (PR) and an 8-bit Data Direction Register (DDR). If a bit in the DDR is set to one, the corresponding bit in the PR is an output', if a DDR bit is set to a 0, the corresponding PR bit is defined as an input.
  • Page 629 C128 HARDWARE SPECIFICATIONS 6 19 PB ON/OFF A control bit allows the timer output to appear on a PORT B output line (PB6 for TIMER A and PB7 for TIMER B). This function overrides the DDRB control bit and forces the appropriate PB line to an output. TOGGLE/PULSE A control bit selects the output applied to PORT B .
  • Page 630 COMMODORE 128 TIM E OF D A Y CLOCK (T O D ) The TOD clock is a special purpose timer for real-time applications. TOD consists of a 24-hour (AM/PM) clock with l/10th second resolution. It is organized into four regis­...
  • Page 631 C l 28 HARDWARE SPECIFICATIONS shifted out on the SP pin at one half the underflow rate of TIMER A. The maximum baud rate possible is (J>2 divided by 4, but the maximum useable baud rate will be determined by line loading and the speed at which the receiver responds to input data. Transmission will start following a write to the Serial Data Register (provided TIMER A is running and in continuous mode).
  • Page 632 COMMODORE 128 mask bit written with a one will be cleared, while those mask bits written with a 0 will be unaffected. If bit 7 of the data written is a ONE, any mask bit written with a one will be set, while those mask bits written with a 0 will be unaffected. In order for an interrupt flag to set IR and generate an Interrupt Request, the corresponding MASK bit must be set.
  • Page 633 C l28 HARDWARE SPECIFICATIONS CRB: NAME FUNCTION (Bits C RB0-C RB4 are identical to C RA 0-CR A 4 for TIM ER B with the exception that bit 1 controls the output o f TIMER B on PB7). INMODE Bits CRB5 and CRB6 select one of four input modes for TIM ER B as: CRB6 CRB5...
  • Page 634: Physical Characteristics

    COMMODORE 128 DYNAMIC RANDOM ACCESS MEMORY This section discusses the characteristics of the C l28 dynamic RAMs, which are currently the 4164 64K-bit RAM. This RAM device is in the 64K by 1-bit configura­ tion. This section also contains information on the 4416 dynamic RAMs used by the 8563 video controller.
  • Page 635 C l 28 HARDWARE SPECIFICATIONS NAME DESCRIPTION No Connection Data In Write Enable (Active Low) /RAS Row Address Strobe (Active Low) Address Bit 0 Address Bit 2 Address Bit 1 Power Supply + 5 Vdc V cc Address Bit 7 Address Bit 5 Address Bit 4 Address Bit 3...
  • Page 636 COMMODORE 128 DESCRIPTION NAME Output Enable (Active Low) Data Bit 1 Data Bit 2 Write Enable (Active Low) Row Address Strobe (Active Low) /RAS Address Bit 6 Address Bit 5 Address Bit 4 Power Supply + 5 Vdc Address Bit 7...
  • Page 637 C l 28 HARDWARE SPECIFICATIONS READ ONLY MEMORY (ROM) This section describes the C l 28 system ROM, both from a logical and a hardware point of view. It mentions aspects of the ROM banking structure, the management of Kernal and BASIC, and explains the physical specifications of the ROM devices themselves.
  • Page 638 COMMODORE 128 T IM IN G SPECIFICATION IN TER N A L ROMs This section specifies timing parameters for both the 23128 and the 27256 Read Only Memories. This timing spec applies to internal ROMs and for external ROMs run at 1 MHz.
  • Page 639 C l 28 HARDWARE SPECIFICATIONS THE 23128 ROM N A M E D E S C R IP T IO N v pp Programming Voltage Address Bit 12 (AJ3 on the C64 OS ROM) Address Bit 7 Address Bit 6 Address Bit 5 Address Bit 4 Address Bit 3...
  • Page 640 COMMODORE 128 0 ------------ ------------ 0 o ------------- ------------ © o ------------- f l f i o ------------- ------------ © 0 — ------------ 0 f l l o ------------- ------------ 0 o ------------- o — — © f l l...
  • Page 641 C128 HARDWARE SPECIFICATIONS THE 23256 ROM NAME DESCRIPTION v pp Programming Voltage Address Bit 12 Address Bit 7 Address Bit Address Bit 5 Address Bit 4 Address Bit 3 Address Bit 2 Address Bit 1 Address Bit 0 Data Bit 0 Data Bit 1 Data Bit 2 Power Supply Ground...
  • Page 642 COMMODORE 128 0 — — — o ------------ 0 ------------ — — o — ------------ 0 0 ------------ — o ------------ o ------------ — 0 — ________ — o ------------- ------------ 0 0 ------------- — o — — o ------------ —...
  • Page 643 Both hardware and software drive this bus protocol. SIGNALS The Commodore serial bus is composed of the following signals: ■ SRQ (pin 1): This signal is called Service Request. The slow serial bus does not use this line, the fast bidirectional clock line.
  • Page 644 COMMODORE 128 FAST SERIAL BUS FAST PROTOCOL To function as a fast talker, the system must be addressing a fast device, such as the 1571 disk drive. When addressing any device, the C128 sends a fast byte, toggling the SQR line eight times, with the ATN line low. If the device is a fast device, it will record the fact that a fast controller accessed it and respond with a fast acknowledge.
  • Page 645 C l 28 HARDWARE SPECIFICATIONS THE EXPANSION BUS The C128 Expansion Bus is compatible with the C64 Expansion Bus, while at the same time allowing extended capabilities in C128 mode. CARTRIDGE A D D IT IO N The C128 can use larger and more sophisticated cartridges than the C64. One of the main reasons for this is the new banking scheme used in the C l 28 for external cartridges.
  • Page 646 COMMODORE 128 DMA priority. When on the bus, the DMA source has access to RAM , ROM and I/O in the C64 scheme. A proper DMA shutdown is usually achieved via some C64 software handshaking with the DMA source. The C128 system uses a similar DMA scheme. When the /DMA input goes low, the RDY input to the 8502, the AEC input to the 8502, and the /BUSRQST input to the Z80 immediately go low.
  • Page 647 C l 28 HARDWARE SPECIFICATIONS EXPANSIO N BUS P IN O U T NAME D ESCRIPTION System Ground + 5V System Vcc + 5V System Vcc /IRQ Interrupt Request System Read W rite Signal DCLOCK 8.18 MHz Video Dot Clock I/O, I/O Chip Select: $DEOO-$DEFF, Active Low /GAME...
  • Page 648 COMMODORE 128 THE VIDEO INTERFACE The C l28 VIC video interface hardware allows the connection of a standard NTSC or PAL commercial television and/or a color monitor. The monitor can accept either a composite video signal or separate chroma and luminance/sync signals in addition to an audio signal.
  • Page 649 C l 28 HARDWARE SPECIFICATIONS SIGNAL Luminance/Sync Ground Audio Out Composite Audio In Chroma N .C. N .C. Table 16-23. Video Connector Signals THE 8563 VIDEO INTERFACE The following items specify the 8563 video interface for 80-column display in sixteen colors.
  • Page 650: The Keyboard

    COMMODORE 128 SIGNAL Ground Ground Green Blue Intensity Monochrome (non-standard) Horizontal Sync Vertical Sync T ab le 16-25. 8563 Video C o n necto r Pinout THE KEYBOARD The C l28 Keyboard is an advance over the standard C64 keyboard, while still maintain­...
  • Page 651 C128 HARDWARE SPECIFICATIONS D-TYPE SIGNAL Ground Restore + 5V Row 3 Row 6 Row 5 Row 4 Row 7 Row 2 Row 1 Row 0 Column 0 Column 6 Column 5 Column 4 Column 3 Column 2 Column 1 Column 7 K„...
  • Page 652 COMMODORE 128 THE C l28 KEYBOARD TABLE PIN13 PIN19 PIN18 PIN17 PIN16 PIN15 PIN14 PIN20 PIN21 PIN22 PIN23 PIN-1 HELP PIN12 « - PIN11 CTRL PIN10 » & LINE PIN5 FEED > RIGHT SPACE ENTER PIN8 SHIFT « - PIN7 •ir...
  • Page 653 P art 11-Calling C P/M BIO S, 8502 BIO S, and CP/M User Functions in Z80 Machine Language P art lll-T h e CP/M System M em o ry M ap A ppendix L - C om m odore 128 System Schematics...
  • Page 654 COMMODORE 128 A PPENDIX A BASIC 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.
  • Page 655 APPENDIXES ERROR # ERROR NAME DESCRIPTION RETURN WITHOUT GOSUB A RETURN statement was encountered when no GOSUB statement was active. OUT OF DATA A READ statement is encountered without any data left to READ. ILLEGAL QUANTITY A number used as the argument of a func­ tion or statement is outside the allowable range.
  • Page 656 COMMODORE 128 DESCRIPTION ERROR # ERROR NAME The program on tape or disk does not match VERIFY the program in memory. There was a problem loading. Try again. LOAD The STOP command was issued in a pro­ BREAK gram or the...
  • Page 657: Appendixes

    APPENDIXES ERROR # ERROR NAME DESCRIPTION FILE READ An error condition was encountered while loading or reading a program or file from the disk drive (e.g., opening the disk drive door while a program was loading).
  • Page 658 COMMODORE 128 A PPENDIX B DOS ERROR MESSAGES The following DOS 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 659 APPENDIXES ERROR ERROR MESSAGE AND DESCRIPTION NUMBER READ ERROR This message is generated when a checksum error has been detected in the header of the requested data block. The block has not been read into DOS memory. W RITE ERROR This error message is generated when a data block is too long and overwrites the sync mark of the next header.
  • Page 660 COMMODORE 128 ERROR NUMBER ERROR MESSAGE AND DESCRIPTION OVERFLOW IN RECORD PR IN T # statement exceeds record boundary. Information is truncated. Since the carriage return that is sent as a record terminator is counted in the record size, this message will occur if the total characters in the record (including the final carriage return) exceed the defined size of the record.
  • Page 661 APPENDIXES ERROR NUMBER ERROR MESSAGE AND DESCRIPTION DIRECTORY ERROR The BAM (Block Availability Map) on the diskette does not match the copy on disk memory. To correct this, initialize the disk drive. DISK FULL Either the blocks on the diskette are used, or the directory is at its entry limit.
  • Page 662 COMMODORE 128 A PPEN DIX C CONNECTORS/PORTS FOR PERIPHERAL EQUIPMENT Serial Port Power Socket Composite Video Connector Power Switch Channel Selector Reset Button RF Connector Controller Ports RGBI Connector Expansion Port User Port Cassette Port...
  • Page 663 APPENDIXES SIDE PANEL C O N N E C TIO N S 1. Power Socket— The free end of the cable from the power supply is attached here. 2. Power Switch— Turns on power from the transformer. Reset Button— Resets computer (warm start). Controller Ports—...
  • Page 664 COMMODORE 128 CARTRIDGE EXPANSION PORT TYPE TYPE + 5V + 5V IRQ. Dot Clock I/O 1 GAME EXROM I/O 2 ROML TYPE TYPE ROMH RESET S 02 A l l 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 8 5 4 3 2 W W f W ■...
  • Page 665 APPENDIXES Serial Port— A Commodore serial printer or disk drive can be attached directly to the Commodore 128 through this port. SERIAL I/O PORT TYPE SERIAL SRQIN SERIAL ATN IN/OUT SERIAL CLK IN/OUT SERIAL DATA IN/OUT RESET Composite Video Connector—This DIN connector supplies direct audio and com­...
  • Page 666 COMMODORE 128 Channel Selector— Use this switch to select which TV channel (L = channel 3, H = channel 4) the computer’s picture will be displayed on when using a television instead of a monitor. RF Connector— This connector supplies both picture and sound to your television set.
  • Page 667 APPENDIXES USER I/O PO R T NOTE TYPE M AX. 100mA + 5V RESET CNT1 CNT2 SER. ATN IN MAX. 100mA 9 VAC 9 VAC MAX. 100mA TYPE NOTE FLAG2 9 10 11 12 A B C D E F H J K L M N...
  • Page 668 SCREEN DISPLAY CODES 40 COLUM NS The chart below lists all the characters built into the Commodore screen character sets. It shows which numbers should be POKEd into the VIC chip (40-column) screen memory (location 1024 to 2023) to get a desired character on the 40-column screen.
  • Page 669 □ □ □ □ □ □ □ □ □ □ □ □ f f l □ < □ □ > □ SPACE □ C o d e s from 128-255 are reversed im ages of co d e s 0-127.
  • Page 670 COMMODORE 128 APPENDIX E ASCII AND CHR$ CODES 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.
  • Page 671 APPENDIXES CHRS PRINT! CHRS PRINTS CHRS PRINTS PRINTS CHRS £ □ □ □ ■ S W U l ' M TO I 42 cast □ □ ■ u P P t H E O L □ □ fm n f f l 124 ■...
  • Page 672 COMMODORE 128 N O TE: The 80-column (RGBI) output has three colors that are different from the 40-column (composite video) color output. This means that the character string codes that represent color codes for these three colors are used differently depending on which video output is used. The following character string codes represent these colors in each video output.
  • Page 673 APPENDIXES A PPENDIX F SCREEN AND COLOR MEMORY MAPS— C l28 MODE, 40-COLUMN AND C64 MODE The maps below display the memory locations used in 40-column mode (C l28 and C64) for identifying the characters on the screen as well as their color. Each map is separately controlled and consists of 1000 positions.
  • Page 674 COMMODORE 128 V IC C H IP (4 0 -C Q L U M N ) C O L O R M E M O R Y M AP COLUMN 1063 1 0 2 4------- - 1064 1104 1144 1184...
  • Page 675 APPENDIXES A PPENDIX G DERIVED TRIGONOMETRIC FUNCTIONS FUNCTION BASIC EQUIVALENT SECANT SEC(X) = l/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)) tt/2 INVERSE SECANT ARCSEC(X) = ATN(X/SQR(X*X-I)) INVERSE COSECANT ARCCSC(X) = ATN(X/SQR(X*X-1)) + (SGN(X)-1)*...
  • Page 676 CONTROL AND ESCAPE CODES C O N TR O L CODES The table below lists the control codes used by the Commodore 128. The print codes in the first column are used in PRINT statements. The key codes in the second column are the sequence of keys pressed to perform specific controls.
  • Page 677 APPENDIXES PR IN T CO D ES KEY CODES EFFEC TIV E IN M ODE: (CHR$) KEY SEQUENCE FUNCTION CHR$(20) DEL or CTRL T Delete last character typed and move all characters to the right o f the deleted character one space to the left CHR$(24) CTRL X, CTRL TAB...
  • Page 678 COMMODORE 128 PR IN T CO D ES KEY CODES EFFEC TIV E IN M ODE: FUNCTION (CHR$) KEY SEQUENCE CHR$(144) Set character color to black (40) CTRL 1 and (80) M ove cursor or printing position CHR$(145) CRSR UP...
  • Page 679 APPENDIXES ESCAPE CODES This table lists the key sequences for the ESCape functions available on the Commodore 128. ESCape sequences are entered by pressing and releasing the key, fol­ lowed by pressing the key listed in the right column. ESCAPE FUNCTION...
  • Page 680 COMMODORE 128 A PPEN DIX I BASIC 7.0 ABBREVIATIONS N O TE: The abbreviations below operate in upper case/graphics mode. Press the letter S H I F T key(s) indicated, then hold down the key and press the letter key follow­...
  • Page 681 APPENDIXES KEYW ORD ABBREVIATION DIRECTORY D lSH IFT R DLOAD D SHIFT L none DOPEN D SHIFT O DRAW D SHIFT R none none DSAVE D SHIFT S DVERIFY D SHIFT V none none ENVELOPE E SHIFT N none ERRS E SHIFT R EXIT EX SHIFT I...
  • Page 682 COMMODORE 128 KEYW ORD ABBREVIATION LOOP LO SHIFT 0 MID$ M SHIFT I MO SHIFT N M ONITOR M SHIFT O MOVSPR none N SHIFT E NEXT ON GOSUB ON GO SHIFT S ON G SHIFT o ON GOTO OPEN...
  • Page 683 APPENDIXES KEYW ORD ABBREVIATION SHIFT I SHIFT L SLEEP SLOW none SOUND SHIFT O none SPR SHIFT C SPRCOLOR SPRDEF SPR SHIFT D SHIFT P SPRITE SPR SHIFT S SPRSAV S SHIFT SHIFT SSHAPE STASH SHIFT T none ST SHIFT E STEP ST SHIFT O STOP...
  • Page 684 This appendix lists the commands used for disk operation in C l 28 and C64 modes on the Commodore 128. For detailed information on any of these commands, see Chapter 2. Your disk drive manual also has information on disk commands.
  • Page 685 APPENDIXES BASIC 2.0 BASIC 7.0 c o m m a n d u s e RUN filename Execute BASIC program from disk SAVE Store program in memory to disk VERIFY Verify program in memory against pro- gram on disk *Although there is no single equivalent command in BASIC 2 .0 , there is an equivalent multi-comm and instruction.
  • Page 686 For more detailed information on the Z80 microprocessor consult the “ Sugges­ tions for Further Reading.” For more detailed information on the CP/M system, refer to the Commodore 128 System Guide to receive the full set of CP/M Plus documentation, written by Digital Research Inc., through Commodore.
  • Page 687 ROUTINES 128 CP/M BIOS The Commodore 128 CP/M system has a set of routines called the CP/M BIOS, which handle the low level input/output operations of the system. Each of these routines can be accessed via the CP/M BIOS jump table below. The jum p vector numbers 0 through 29 are the CP/M BIOS jump vectors.
  • Page 688 COMMODORE 128 BOOT Bank: Input: None Output: None This code does all of the hardware initialization, sets up zero Function: page, prints any sign-on message and loads the CCP and then transfers control to the CCP. WBOOT Bank: 0 or 1...
  • Page 689 APPENDIXES AUXOUT Bank: 0 or 1 Input: C = ASCII Character to send to AUX device Output: None Function: Sends the character in C to ALL devices that are currently assigned to the AUXOUT device. It waits for all assigned devices to accept a character before exiting.
  • Page 690 COMMODORE 128 SETDMA Bank: Input: BC = Direct memory access address Output: None Function: The value in BC is saved as the current DMA address. This is the address where ALL disk reads or writes occur. The DMA address that is set is used until it is changed by a future call to this routine to change it.
  • Page 691 APPENDIXES SECTRN Bank: Input: BC = Logical sector number (0-n) DE = Translation table address (from DPB) Output: HL = Physical sector number Function: This routine converts the physical sector number to a logical sector number. If no translation is needed then it moves the BC register to HL and returns.
  • Page 692 COMMODORE 128 DEVINI 0 or 1 Bank: C = device number Input: Output: None Initializes the physical character device specified in the C Function: register to the BAUD rate in the DEVTBL. DRVTBL Bank: None Input: Output: HL = address of the drive table...
  • Page 693 A = function number, L = subfunction number Output: Outputs depend on the called function or subfunction. Function: This calls the user functions and 8502 BIOS routines, which are defined in the Commodore 128 System Dependent User Function section. RESERV1 Bank: Input:...
  • Page 694: Data Structures

    COMMODORE 128 DATA STRUCTURES SYSTEM CONTROL BLOCK—(SCB) The System Control Block is a 100-byte data structure. The data structure is used as the basic communication between the various modules that make up the CP/M Plus system. The contents of the data structure are system parameters and variables.
  • Page 695 USER FUNCTIONS The Z80 machine language routines discussed in this section pertain explicitly to the Commodore 128 Personal Computer. These routines are not part of the standard CP/M system that is transportable from one manufacturer’s computer to another. They are written to run only on the Commodore 128.
  • Page 696 COMMODORE 128 function number, require that the function number be placed in the Z80 A register (accumulator). Many of these routines have subfunctions which require the user to place a value in the eight bit L register, which is used to call the appropriate subfunction. All other additional required parameters are noted if they are necessary.
  • Page 697 APPENDIXES Bit 2 1 = control key down, 0 = up Bit 3 Not implemented Bit 4 1 = Right shift key down, 0 = up Bit 5 1 = C * key is active (not necessarily down) Bit 6 Not implemented Bit 7 1 = left shift key down, 0 = up...
  • Page 698 COMMODORE 128 ASCIISTBL: 12EA 74545414 7 4H ,5 4 H ,5 4 H ,1 4 H 7 8H ,5 8 H ,5 8 H ,1 8 H 12EE 78585818 ; 7 ’ 12F2 373727A 6 3 7H ,3 7 H ,2 7 H ,0 A 6 H...
  • Page 699 APPENDIXES ASCIISTBL: 1392 9F9F9F9F 9FH ,9FH ,9FH ,9FH /HELP/ 1396 383838B7 38H ,38H ,38H ,0B7H 139A 353535B4 35H ,35H ,35H ,0B4H 139E 09090900 09H ,09H ,09H ,00H /TAB/ 13A2 323232B1 32H,32H ,32H ,0B1H 13A6 343434B3 34H,34H ,34H ,0B3H 13AA 373737B6 37H ,37H ,37H ,0B6H 13AE 313131B0 31H ,31H ,31H ,0B0H...
  • Page 700 COMMODORE 128 III. 0a) Subfunction 0: Write Character b) wr$char c) Register D = character to write auto advance cursor to next position d) — III. 4a) Subfunction 4: Cursor Position b) cursor$pos c) Register D = row value Register E = column value d) This subfunction sets the current position of the cursor on the 80-column screen.
  • Page 701 APPENDIXES III. 32a) Subfunction 32: Clear to end of screen b) CES c) No values returned. d) This subfunction clears the screen starting where the cursor is currently located through the end of screen. III. 36a) Subfunction 36: Character insert b) char$ins c) No values returned.
  • Page 702 COMMODORE 128 III. 60a) Subfunction 60: Read Character Attribute (80) b) rd$chr$atr D = 8563 character row E = 8563 character column c) D = 8563 character row L = 8563 character column B = character value C = attribute bit pattern of selected character location d) This function reads the attribute byte of the selected character row and column on the 8563 screen, and returns the true RGBI color.
  • Page 703 APPENDIXES III. 96a) Subfunction 96: Track 40 b) trk$40 c) @ off 40 d) This function computes the logical (offset) position of the cursor on the physical 80-column screen. The variable @ off40 is computed on 8-character boundaries, and is used in the next subfunction. III.
  • Page 704 COMMODORE 128 d) This function works like the previous one, except the start address of the string is taken from DE, and execution resumes with the return address from the stack. III. 108a) Subfunction 108: Incripted Messages b) update$it c) No value returned d) This function displays incripted messages.
  • Page 705 L = -1 c) none d) This subfunction reboots the Commodore 128 hardware when the value in the L register is equal to -1 ($FF). This sub function is not normally used. It performs the same actions as pressing reset.
  • Page 706 COMMODORE 128 c3) Sets up PAL and NTSC variables (SYSFREQ) c4) Closes all open channels d) This subfunction intializes 8502 system variables, interrupt processing and system frequencies so that the Z80 and 8502 may communicate back and forth. Processor control is given to either the Z80 or the 8502 at one particular time.
  • Page 707 APPENDIXES e) Additional Information: This subfunction assumes that both the data and command channels have been opened previously. Data is written from the buffer at $FE00H. IV. 3 .a) Subfunction 3: 1571 Read Set Up (MFM or GCR formats) b) A = 4 L = 3 * VICTRACK = (1-35)—...
  • Page 708 COMMODORE 128 e) Additional Information. This is how the user should select between a 1541 and 1571 Drive. To access the back side of an MFM disk set bit 7 of VICSECTOR. To perform a write operation, the user will have to do so in their application.
  • Page 709 MD ....Mode: 1 = MFM, 0 = GCR..........Drive Number. 12 ........... Sector Size. a) 00 = 128 bytes b) 01 = 256 bytes c) 10 = 512 bytes d) 11 = 1024 bytes D 1-D 4 ........Controller Status OOOx = Ok.
  • Page 710 COMMODORE 128 IV. 7 .a) Subfunction 7: Print characters to a serial bus printer b) A = 4 L = 7 VICDRV = Printer number (either 4 or 5) VICTRACK = Secondary address in which device is opened as VICDATA = Character to be printed to the serial bus printer (if...
  • Page 711 APPENDIXES KERNAL routine, you must enable the KERNAL after you have trans­ ferred control to the 8502. Before you return to the Z80, you must disable the KERNAL again. When control passes from the Z80 to the 8502 processor, the Z80 is idle.
  • Page 712 CP/M USER FUNCTIONS IN Z80 MACHINE LANGUAGE The Commodore 128 CP/M system allows you to call the CP/M BIOS, 8502 BIOS and CP/M user functions in your own Z80 assembly language programs. However, in order to program in Z80 assembly language, you need either an assembler or machine language monitor.
  • Page 713 APPENDIXES recalling the CP/M jum p vector on page 677 of Appendix K. The first 30 jumps (0-29) are direct calls to CP/M BIOS routines. Jump number 30 is the call to the user functions, of which user function 4 is the 8502 BIOS. The 8502 BIOS is a subset of the CP/M user functions.
  • Page 714 COMMODORE 128 The XTHL instruction exchanges the HL register pair with the top of the stack. This places the computed address on the top of the stack and the entry values of HL back in HL. When the RETum instruction is reached by the Z80, program control is therefore passed to the USERF vector, entry 30 in the CP/M BIOS jump table.
  • Page 715 CP/M software formats available on the market. This does not mean that the Commodore 128 CP/M system can read every single CP/M disk format in the universe; however, the majority of available CP/M software can run on the Commodore 128, if the particular application is not hardware dependant.
  • Page 716 MFM$table. In the current system, these are the formats that are read and write compatible on the Commodore 128 CP/M Plus system. The following is a listing of the MFM format table:...
  • Page 717 256 byte sect, 16 sect/trk MFM + S256 + TypeO + CO + SI DSDD start on track 2 sect 1 (2 ale) 256,32,40,2048,128,2 se c t# 1 to 16 (top and bottom numbered the same) ‘Epson QX10’ 1 Epson QX10...
  • Page 718 COMMODORE 128 S1024*2 + (5*2-8) + 1 ; 1024 byte sect, 5 sect/trk MFM + S1024 + TypeO + CO + SI SSDD ; start on track 3 sector 1 (2 ale) 1024,5,40,1024,64,3 ; se c t# 1 to 5 ‘Osborne D D ’...
  • Page 719 The memory map includes all the key CP/M locations, vectors and variable tables. Use it as a guide through the Z80 CP/M system within the Commodore 128. The CP/M memory map is available as a disk file “ CXEQU.LIB” on the disk...
  • Page 720 COMMODORE 128 $*MACRO e q u f a l s e t r u e e q u n o t f a l s e e q u t r u e b a n k e d EXTSYS...
  • Page 721 APPENDIXES v i c $ s e c t e q u v i c $ t r k + l b i o s 8 5 0 2 s e c t o r # v i c $ c o u n t e q u v i c $ s e c t + l b i o s 8 5 0 2 s e c t o r c o u n t...
  • Page 722 COMMODORE 128 r e c v $ d a t a + l i n t $ r a t e e q u s t b y t e i s a p o i n t e r i n t o...
  • Page 723 APPENDIXES ;==> CXKEYS parameters key$down$tbl key$buf+l ; not used any more (int code) free space above, new interrupt driven code does not require this space ; c o n t r o l $ k e y s e q u k e y $ d o w n $ t b l + l ;...
  • Page 724 COMMODORE 128 O bh 16K t o p C a n n o n r a m ? r e g e q u p a g e $ e q u MMU+7 p a g e $ e q u...
  • Page 725 APPENDIXES RM$ co m m a n d e q u R A M $ d s k $ b a s e + l ; r / w b i t 7 e x e c u t e p e r c u r r e n t c o n f i g . s e t r e s e r v e d e n a b l e a u t o r e l o a d i f...
  • Page 726 COMMODORE 128 k e y $ c o l e q u C I A 1 + D a ta $ b i n p u t V I C $ k e y $ r o w e q u...
  • Page 727 APPENDIXES F R $ t r k $ s e c t e q u 5 Oh F R $ ch e c k $ C B M e q u 5 2 h F R $ b e l l 5 4 h e q u e q u...
  • Page 728 COMMODORE 128 (MFM) p a s s t h e b y t e v a l u e s s u p p l i e d T y p e 7 e q u 7 * 2 a n d ' s e c t...
  • Page 729 APPENDIXES © & — , & ® a “ z o , S os as < S , z o o g ^ fa D S j M < ( 2 3 s s o E S ^ S S ; J u W J <...
  • Page 730 COMMODORE 128 n z > a! « o < !> £ * i | s o j o | w g B 3 < W c a o ^ S u S w S td p a § o X o ^ w g w ' * ;...
  • Page 731 APPENDIX L COMMODORE 128 SYSTEM SCHEMATICS The following eight pages contain the full system schematics for the Commodore 128. Each two-page spread represents one full-size engineering schematic sheet. For easier readability, the right edge of the left-hand page and the left edge of the right-hand page have portions of the schematic that are duplicated.
  • Page 732 COMMODORE 128...
  • Page 733 APPENDIXES...
  • Page 734 COMMODORE 128 A U D IO O U T r ID A C C 7 A 5 - T A I I C L R B N K SA7y 1 0 > SA < 0 / SA5, l£ SA4, vA ;- <...
  • Page 735 APPENDIXES...
  • Page 736 COMMODORE 128...
  • Page 737 APPENDIXES CN 13 R 4 2 l8o -n_ R 3 2 I/O CONNECTOR t e ; : / \ L O W E N D O N L Y I/O — C o n tro l P o rts , K e y b o a rd , f e \ H I G H O J D O N L Y...
  • Page 738 COMMODORE 128 OPEN- 1 2 8 k ROM CLOSE - 25G>K ROM - 0 1 ONLY - 0 1 ONLY | R A S G C A 5 0 MAffl - M A T D 0 -...
  • Page 739 APPENDIXES C /PS . o t p f R A M , R O M S C H E M A T I C 3 1 0 3 7 8...
  • Page 741 GLOSSARY This glossary provides brief definitions of frequently used computing terms. Acoustic C oupler o r Acoustic M odem : A device that converts digital signals to audible tones for transmission over telephone lines. Speed is limited to about 1200 baud, or bits per second (bps).
  • Page 742 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. An advanced graphic mode in the Commodore 128 in which you can B it Map Mode: control every pixel on the screen.
  • Page 743 Determination of collision between two or more sprites or between sprites and data. C o lo r M em ory: The area in the Commodore 128’s memory that controls the color of each location in screen memory. C om m and: A BASIC instruction used in direct mode to perform an action.
  • Page 744 Function: 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 745: G Lossary

    The 1571 disk drives can read and write to MFM disks. Microprocessor: A CPU that is contained on a single integrated circuit (IC). M icropro­ cessors used in Commodore personal computers include the 6510, the 8502 and the Z80. Mode:...
  • Page 746 COMMODORE 128 M odem : The acronym for MOdulator/DEModulator. A device that transforms digital signals from the computer into analog electrical impulses for transmission over telephone lines, and does the reverse for reception. M onitor: A display device resembling a television set but with a higher-resolution (sharper) image on the video screen.
  • Page 747 P rogram 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. Program m able: Capable of being processed with computer instructions.
  • Page 748 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 749 674— 675 intelligent use of, 97 CATALOG, 31 See also specific commands mixed with machine language, CHAR, 31-32, 115 Commodore 128. See C l28 Mode 198-205 Character mode Commodore 64. See C64 Mode placement of machine language accessing character ROM, 229 Complex Interface Adapter.
  • Page 750 IN D EX C l28 Mode (continued) DEY, 168 FETCH, 43 character memory, 219-220 DIM, 38 Files DIRECTORY, 38-39 character set availability, 222 CP/M, 479-481 color RAM in BASIC, 218 Directory, 375 creating and storing, 376-378 CP/M disk format, 493-494 Disk drive disk drive, 374-376 memory map, 502-540...
  • Page 751 IN D E X Input/output (continued) routine, 93-94 screen (RAM), 215-218 screen outpuut, 388-389 LOCATE, 51, 120 16K video banks, 210-212 64K RAM banks, 208-210 INSTR, 75 LOG, 77 split-screen mode, 246-247 Instructions Logic errors, 99 storage, 12-13, 148 arithmetic, 151-152 switching banks, 459-460 branching, 154-156 instructions, 151, 152-153...
  • Page 752 IN D E X 80-column (8563) chip, 304-309, SETLFS, 426-427 Performance specifications, 567-568 324-334 SETMSG, 418 PFKEY, 450-451 8502 microprocessor, 127 SETNAM, 427 PHA, 172 PHOENIX, 448 8563 video controller, 595 SETTIM, 436-437 PHP, 172 interrupt, 591-592 SETTMO, 422 Pinouts, 394-400 raster, 591 SGN, 84 shadow, 213-214, 539-540...
  • Page 753: Index

    IN D E X STORE, 148 Text composite connector, 396-397 STR$, 84-85 display, 111-112 display codes, 658-659 String, 497 manipulation within machine 8563 controller, 595-598 STX, 176 monitor, 194-195 features, 110-112 STY, 176 TKSA, 419 40/80 column display, 498-499 Subtraction, 19 TouchTone frequencies, 103-104 interface chip, 524-527, 557-558, SWAP, 69...
  • Page 754 Programmed Logic Array. He is co-author of the C l 28 hardware specifications. TERRY RYAN, a Software Engineer at Commodore, was the major contributor to the development and implementation of the BASIC 7.0 language and cocreator of the software architecture.
  • Page 755 E nclosed is m y ch ec k o r m o n ey o rd e r for $ _______ (M a ke check o r m o n e y order, f o r S2 6 .9 5 p e r subscription, p a y a b le to COMMODORE PUBLICATIONS) □...
  • Page 758 Programmer’ s Reference Guide This book is an indispensable reference guide and sourcebook for anyone using the new and powerful Commodore 128 computer. This machine has many new and exciting built-in features, such as the advanced BASIC programming language Version 7.0, superior graphics, and excellent sound and music capabilities.

Table of Contents