background image

Summary of Contents for Commodore 128

Page 1: ...UDWJ8S 8H P ADC S I8WWD 1 0 1d 101 ap1n0 8 U8 1818ll 8 l 8 10pOWWO PNrfS ...

Page 2: ...Commodore 128 Reference Guide for Progrommers David L Heiserman Howard W Sams Co A Division of Macmillan lnc 4300 West 62nd Street lndianapolis IN 46268 USA ...

Page 3: ... 672 22479 8 Library of Congress Catalog Card Number 86 60936 Acquisitions Editor Greg Michael Editor Katherine Stuart Ewing Designer T R Emrick Illustrators Don Clemons and Ralph E Lund Cover Artist Gregg Butler Compositor Shepard Foorman Communications Indianapolis Printed in the United Statesof America Trademark Acknowledgments All terms mentioned in this book that are known to be trademarks or...

Page 4: ...ASIC Formats 106 3 DOS Operating and Programming Procedures 111 Preliminary Considerations 112 4 DOS Related Commands Functions and Statements 113 DOS Related Error Conditions 115 The Disk Directory 119 Disk Pormatting Procedures 121 Procedures for Saving Programs on Disk 125 Procedures for Loading Programs from Disk 132 Procedures for Copying Disk Files 138 Procedures for Cleaning Up Disks 140 Us...

Page 5: ...ng Alternative Screen RAM Locations 276 Writing Directly to the 80 Column Screen 279 201 215 7 Bit Mapped Graphics Procedures 283 Bit Mapped Screen Formats 284 Plotting Figures on the Graphics Sereens 290 Rescaling the Screen 300 Saving and Reloading Bit Mapped Shapes 301 Setting Graphics Sereens from Machine Language Routines 304 Working Directly with Standard Bit Mapped Sereens 307 Working Direc...

Page 6: ... The Upper RAM Only Area 0400 3FFF 437 BASIC ROM 4000 AFFF 443 Screen Editor ROM COOO CFFF 453 I 0 ROM and RAM Block DOOO DFFF 456 Kernal ROM EOOO FFFF 475 Memory Management Procedures The Standard Bank Configurations 508 Bank Switching Statements Registers and Procedures 515 Using the BANK 1 Contiguration 521 Summary of MMU Configuration Registers 525 Bank Switching Procedures 526 Number System B...

Page 7: ...viii Contents B Derived Trigonometrie Functions Index 544 545 ...

Page 8: ...Readers who have the desire to use CP M in a Z 80 or 8080A environment will be pleased to find that the Commodore 128 supports it A Z 80 microprocessor is built into the system and is fully dedicated to the CP M features that are briefly described in Chapter 5 Chapters 2 through 5 deal with the eight programming formats available on the stock Commodore 128 BASIC actually both BASIC 2 0 and 7 0 DOS...

Page 9: ...dore 128 is designed to encourage machine language programming and calls to Kernal sub routines Unlike much of the early literature dealing with the Commo dore 128 no underlying assumption is made that the reader is already familiar with the features and quirks of the earlier Commodore per sonal computers notably the Commodore 64 I believe that paying twice the suggested retail price for this sys ...

Page 10: ...1 General Oparating Procedures ...

Page 11: ... the composite video conneetion is less expensive than the models that include the RGB feature but composite video units are adequate for all 40 column text and graph ics applications You can use an ordinary color TV set as the display unit The video quality is not quite as good as that of a composite video moni tor and TVs lack the RGB feature that is necessary for displaying 80 column text The c...

Page 12: ...PROGRAM CARTRIDGES CONTROlLER PORT 1 SERlAL PORT TV CHANNEL SELECTOR SWITCH USER PORT 3 __ D n 1 0 J co J cp ooQ 7 Ooo 30 Q 3 Do Do cO O J J 0 Q Q D cn Dcn g w Oo o 5 ij g w Oo 1 ij G CD J CD g_ a5 Q a0 CD J ...

Page 13: ... cussionconcerns C128 mode unless clearly stated otherwise One essential feature of C128 mode is Commodore s enhanced BASIC interpreter version 7 0 That language is builtinto the system as non destructible read only memory ROM and is readily available without having to load any kind of external programming Turning on the computer automatically sets up the system for running BASIC 7 0 in C128 mode ...

Page 14: ...rograms developed for the 64 can not run properly on the 128 Rather than allow all Commodore 64 software to become instantly obsolete Commodore decided to in clude the C64 mode one that properly runs all software developed over the years for the Commodore 64 system C64 mode is built ihto the system and does not have to be loaded from an external souree of programming Commodore didn t forget about ...

Page 15: ... and shows that the amount of available memory has been reduced to the level of the older system An alternative way to go to C64 mode is to hold down the Commodore key the Or key in the lower left corner of the key board when you turn on the power to the computer This procedure takes the system directly to C64 mode The material in this book is directed toward the wider range of features available ...

Page 16: ...the 40 80 DISPLAY key CP M can be run on a 40 column screen but you can see only half the display at any given time 2 Insert the CP M System Disk into the disk drive 3 Operate the system Reset pushbutton or enter the BOOT command After a short delay and some changing screen displays the sys tem setties in to CP M mode The screen generally has a brown bor der black background and purple characters ...

Page 17: ...ed in Figure 1 5 most of the keys on the Commodore 128 keyboard are identical to those of a conventional typewriter and can serve the samegeneral purpose However some keys are irrele vant for ordinary typing operation but are quite important for operat ing the computer The RETURN key is perhaps the most frequently used computer key Yau must press this key when you want the computer to execute a ca...

Page 18: ...I C _________ nlOij o Q JQQQGJJQQGJQGJJQJQJ UQQQ N0013H Q J OJOJQQQ G J QGJJQQ QQQQ QQQQQQOJGQQQQQ g QQQQ Gi rti QQQ jj J J J OJJ r IQ Q Q Q I I E JHEJJ m mI Q C J 00 0 0 N E o E D o 0 0 0 0 0 D IQ x 0 i i lMOd ...

Page 19: ...rac ter set format changes all characters currently on the screen as well as those subsequently written to it The 80 column mode supports both character sets at the same time so changing the character set format does not affect any text already printed to the screen This change affects only the characters printed after the change takes place Using ESC CONTROL and K Functions The ESC CONTROL C and ...

Page 20: ...ey while pressing another the procedure is divided into two separate steps press the ESC key release it then press a second key The general notation used in this book is ESC key where key is some other designated key The following ESCape function for example farces the system to show the text cursor as a non blinking rectangle ESC E First press the ESC key release it then press the E key This oper...

Page 21: ...mmsa B Two light colored CRSR keys located near lower right corner ofkeyboard Referring to the cursor control arrow keys shown in Figure 1 6A the arrows indicate the direction of motion Pressing one of these keys moves the cursor one space in the indicated direction Holding down one of the keys makes the cursor move any number of spaces in succession These keys are nat active in C64 mode and they ...

Page 22: ...onglistsof informa tion holding down the C key slows the scrolling rate by inserting a time delay between the printing of each line Releasing C restores the normal printing rate Pressing the NO SCROLL key stops the printing operation al together This keypress does not interrupt the program or computer fundion that is generating the material on the screen but simply puts the program on hold until y...

Page 23: ...et to the desired position prior to turning on the computer operating the Reset pushbutton doing a STOP RESTORE operation or booting the CP M system disk Chapter 6 illustrates some procedures for switching between 40 and 80 column displays within programs and without using the 40 80 DISPLAY key Using the Calculator Keypad Figure 1 7 shows a blockof keys that are arranged in the format tradi tional...

Page 24: ...tter of doing a DEL operation pressing the INST DEL key alone Deletion takes place from right to left Use the cursor control keys to place the text cursor over a character and press the INST DEL key You will see that the operation takes the character under the cursor and moves it one space to the left An INST DEL operation deletes the character immediately to the left of the cursor replaces the de...

Page 25: ... See the description with the KEY statement in Chapter 2 The HELPand RUN keys are configured internally to dotheir tasks in the same way as the function keys Fl F8 Pressing the HELP key emulates the keyboard operation where you type HELP and press the RETURN key See a description of the HELP command in Chapter 2 The RUN function is invoked by holding down the SHIFT key and pressing the RUN STOP ke...

Page 26: ... the instructions for the special quote mode operation Consider this example PRINT 1 SHIFT CLR HOME 4 CRSR down 1 TAB HELLO The statement instructs the system to clear the screen home the cursor move the cursor down four lines tab the cursor to the right then print HELLO On the screen this appears as a series of reverse colored characters one heart four Qs and anI Quote mode routines make easy the...

Page 27: ... valuable data because such disks are by nature of lesser quality than their double sided counterparts Displaying the Disk Directory Once the computer is turned on and operating under C128 BASIC you can display a listing of the programs on a disk by executing one of two commands from the keyboard CATALOGor DIRECTORY By way of an example insert into the drive unit the TEST DEMO DISKETTE supplied wi...

Page 28: ...use for saving your own material on a disk The final column in the main listing shows the file type The computer supports a number of different file types but the ones shown hereare PRG program file and USR special user file The partial directory listing in this example does not show the camment that appears at the end of such a display When you allow the system to display the entire directory for...

Page 29: ...d DSAVE 11 filename 11 where filename is a name up to 15 characters long that you want to assign to the program Suppose that you have developed a BASIC program and want to save it on disk as POPS Enter the following cammand and press the RETURNkey DSAVE 11 POPS11 The system has some built in proteetion against saving more than one program with the same file name For example if POPS is already in t...

Page 30: ...y entering the RUN command If POP is not on the current disk the system returns a FILE NOT FOUND error message and blinks the green light on the 1571 disk drive Whenever that happens do a CATALOGor DIRECTORY command to double check the spelling of the file name Executing the CATALOGor DIRECTORY cammand also clears the disk error condition The DLOAD command loads a BASIC program from the current di...

Page 31: ...2 BASIC Operations and Programming Procedures ...

Page 32: ...ys tem in the Commodore 128 console and some in the disk drive unit The purpose of this chapter is to summarize the essential fea tures of BASIC DOS commands and error messages generated by those systems The discussionsof DOS for the Commodore 128 com puter are limited to the ways it interacts with BASIC Chapter 3 deals with DOS in a more complete fashion Numeric and String Constants for Basic In ...

Page 33: ...ues enter this command PRINT 12345678901 and you will see this response 1 23456789E 10 The PRINT statement specifies a positive constant that has more than nine significant digits and BASIC responds by converting the value to a form of scientific notation The E 10 in thàt response rep resents X 1010 ten to the tenth power The same general idea applies to small numeric values Enter this command PRI...

Page 34: ...ts to the right of the decimal point Eighteen of them are non zero digits sa BASIC treats the number as 0 00123456789 and displays it as 1 23456789E 03 Summarizing the limitations and conventions required for nu meric constantsin BASIC Large numeric values must nat include commas A negative sign must preeede a negative valued constant but a plus sign is optional for positive valued constants BASIC...

Page 35: ...ric values You can prove this point with a simple demonstration First treat the expression 1 2 as a string constant In other words execute this statement PRINT 1 2 The fact that you enclosed the expression in quotation marks means that the computer will interpret the numerals as part of a string and will respond by printing out a literal version of your string 1 2 Next execute this command PRINT 1...

Page 36: ... variables numeric variables and string variables However as described in the following discus sions variations of those two types of variables exist Numeric Variables and Variabie Narnes Numeric variables and numeric variabie narnes refer to numbers or quantities They are used in much the same way that variables are used in ordinary algebra This two line program illustrates the use of a particula...

Page 37: ...ble because the reserved word FOR is used within it Inadver tently using a reserved word within a variabie name cau ses the sys tem togeneratea syntax error message SYNTAX ERROR ABS DELETE HEX PRINT SPC AND DIM IF PRINT USING SPRCOLOR APPEND DIRECTORY INPUT PRINT SPRDEF ASC DLOAD INPUT PRINT USING SPRITE ATN DO INSTR PUDEF SPRSAVE AUTO DOPEN INT QUIT SQR BACKUP DRAW JOY RCLR SSHAPE BANK DsAVE KEY ...

Page 38: ...abie name that ends with a percent sign farces that variabie to work only with integer values The advantage of using integer values is that they require less memory space and are handled faster by the BASIC inter preter than floating point vaiues String Variables and Variabie Narnes String variables and string variabie narnes refer mainly to literal expressions but they aiso can refer to special c...

Page 39: ...ificant Finally string variable narnes must nat include combinations of letters appearing in the reserved words list in Figure 2 1 If you inad vertently use a reserved word in a string variable name the system responds by interrupting the program and printing the SYNTAX ERROR message Here are some examples of valid string variable names TRY AXIS MODELl NAMESFROMTABLElO And here are some invalid st...

Page 40: ...les ought to be clear even frorn those simple examples BASIC supports the use of subscripted string variables as well The next exarnple assigns sorne sirnple words to a group of sub scripted string variables NA O through NA 4 10 FOR X O TO 4 2Ö READ ÀS NAS X A 30 NEXTX 4o DATA CAT DOG RAT BIRD FISH After executing this routine the five strings in the DATA listing are assigned to subscripted string...

Page 41: ...ripted numeric vari ables FE and GEG The first is dimensioned for 51 elements the sec ond for 26 Line 20 sets all51 elementsof FE toa value of 1 and line 30 initializes all values of GEG to 1 Array Variables A variabie array is an extension of subscripted variables Instead of using just one subscript numeral arrays use two or more The tradi tional foundation for arrays in BASIC are the matrices of...

Page 42: ... array to CAT this brief routine does the job in a couple of minutes 10 DIM M 20 15 25 20 FOR 1 0 TO 20 FOR J O TO 15 FOR K O TO 25 30 MS I J K HCAT 40 NEXT K J I Operators for Commodore BASIC Much of the computing and control activity of a computer is deter mined by the nature of operators that are written into the programs Just three families of operators exist arithmetic relational and logical ...

Page 43: ...s assigned to numeric variables The operations apply equally well to string values and variables but their applications in that case are rather different In either case the operators are gener ally meaningful only when used in conditional IF THEN state ments Table 2 2 shows BASIC s family of relational operators Operator or or or Function less than greater than equal to less than or equal to great...

Page 44: ...a greater than operator to determine when the current value of X exceeds 9 and conse quently brings the program to an end 3 The equal to operator 10X 1 20 IF X 10 THEN END 30 PRINT X 40 X X 1 50GOT020 The routine prints integers 1 through 9 and comes to an end when the equal to condition in line 20 is satisfied 4 The less than or equal to operator 10X 1 20 IF X 10 THEN 40 30 END 40 PRfNT X 50X X 1...

Page 45: ...lue of X When you correctly guess the value the does not equal condi tion in line 50 fails and the program concludes by printing THAT S IT and sounding the bell The foregoing examples refer to relational operators as they apply to numeric constauts and variables The examples apply equally well to string constauts and variables however The notion of using relational operators to test relationships ...

Page 46: ...sider this general type of AND statement IF expr1 AND expr2 THEN expr3 The literal interpretation of this statement is IF expr1 is true AND if expr2 is also true THEN execute expr3 IF either exprl or expr2 is not true the impHeation is that computer operations should ignore the action prescribed by expr3 and go to the next statement in the program By way of a specific example IF A 0 AND A 9 THEN P...

Page 47: ...lly says IF the value currently assigned to variabie A is NOT greater than 10 then END the program Each of the foregoing examples used one particular logical oper ator but you aften need to use various combinations of them within the same conditional statement Boolean Operators BASIC offers four operators that perform Boolean logical operations on numeric values NOT AND OR and XOR The first three ...

Page 48: ...system and that tends to obscure applications of Boolean functions in BASIC programming Consider the following comparisons Problem Use the Boolean AND operation to set the four leading bits of a binary value to 0 but leave the four lower order bits unchanged Approach to the Solution Logically AND the given value with 00001111 a value that farces the first four bits to 0 and leaves the remaining bi...

Page 49: ...e 128 system The meaningful and important applications however are cited at appropriate places in other partsof this hook Order of Preeedenee for Operators Many programming situations call for including more than one opera tor within a statement combinations of more than one arithmetic relational and logical operator This situation is handled by some conventions built into BASIC Table 2 5 shows th...

Page 50: ...ion from the result of the summation The same idea applies to all of the operators cited in the table Notice that all of the relational operators have the same level of prec edence meaning that they will be regarded in a strict left to right sequence Logical operators AND and OR are at the bottorn of the list thereby giving them the lowest level of preeedenee Perhaps a need for setting up BASIC st...

Page 51: ...mplete Others refer to details in other chapters Readers who learned BASIC from other sourees will find this a handy guide for dealing with differences between Commodore BASIC actually a version of Microsoft BASIC and other versions It is beyond the scope of this book to deal with the general principles of BASICprogramming on an elementary level however so if you are not already acquainted with th...

Page 52: ... first opens the designated file then sets the file pointer to the end of the file By contrast an OPEN command opens a file but sets the pointer to the beginning of the designated file The APPEND feature allows only writing operations to the des ignated file You can close an appended file by means of the CLOSE DCLOSE or DCLEAR statements Example APPEND 1 NAMES OF FOLKS This example opens an existi...

Page 53: ... gener ates and prints BASIC line numbers to the screen in increments of incr The idea is to save you the trouble of having to type new line numbers during the keyboard entry process The operation is invoked in two steps 1 Type and enter AUTO incr incr being the desired increment between successive line nulnbers in the program 2 Enter the line number and BASICprogramming for the first line to be A...

Page 54: ...BASIC is one where bankno is equal to 15 which makes available the Kernal and BASIC ROM bank 0 RAM and the system s I 0 features Table 2 6 is a summary of bank numbers and the memory con figurations associated with each of them As described in Chapter 14 some of the ban configurations are redundant bankno 0 1 2 3 Bank Contiguration RAM bank 0 only RAM bank 1 only RAM bank 2 only RAM bank 3 only 4 ...

Page 55: ... POINT IN MAKING HAY IF THE BARN IS EMPTY 30 FOR K O TO 1 40 IF K O THEN PRINT M PRINT 50 IF K 1 THEN PRINT FOR N LEN M TO 1 STEP 1 PRINT MID M K 1 NEXT N PRINT 60 NEXT K 70 PRINT PRINT PENNY LOGIC Listing 2 2 1Cl SCNCLR 20 MS WHAT S THE POINT IN MAKING HAY IF THE BARN IS EMPTY 30 FOR K O TO 1 40 IF K O THEN PRINT MS PRINT 50 IF K 1 THEN BEGIN 51 PRINT 52 FOR N LEN M TO 1 STEP 1 53 PRINT MID M K 1...

Page 56: ...memory to the current disk drive The blockis savedunder the name fi_lename The decimal starting address of the block is strtaddr and the end is defined by endaddr the last byte to be saved plus 1 Example BSAVE PICTURE P1024 TO P2024 This example saves the contents of memory locations 1024 through 2023 to the current disk as PICTURE See Chapter 3 for extended versions of the statement that allow th...

Page 57: ... fixes the text bit map cursor to column 10 row 15 and prints an X at that place You can simplify the routine in the foregoing example by taking advantage of an extension of the CHAR statement CHAR x y string where string is a string constant variable or expression to be printed at the designated x y focation CHAR 10 15 X A further extension lets you select whether string is printed in the normal ...

Page 58: ...sforming it to a regular polygon CLOSE fileno CLOSE is a DOS statement that doses a file which was originally opened as fileno under the OPEN DOPEN or AP PEND statements See more details and examples in Chapter 3 CLR The CLR statement resets all numeric variables to zero and nulls all strings The statement is especially useful for filling large multidimensioned arrays with zeros or null characters...

Page 59: ... splat files are virtually useless and are marked on the directory with an asterisk preceding the file type designation Entering the COLLECT command from the keyboard eliminates splat files and makes space available for more useful information COLLISION type lineno COLLISION is a sprite graphics statement that specifies a subroutine to be executed when a specified callision occurs The callision ty...

Page 60: ...d BJ Color Codes for 40 and 80 Column Sereens 40 Column Colors 80 Column Colors colr Color colr Color 1 Black 1 Black 2 White 2 White 3 Red 3 Red 4 Cyan 4 Cyan 5 Purple 5 Purple 6 Green 6 Green 7 Blue 7 Blue 8 Yellow 8 Yellow 9 Orange 9 Dark Purple 10 Brown 10 Dark Yellow 11 Light Red 11 Light Red 12 DarkGray 12 Dark Cyan 13 MediumGray 13 MediumGray 14 Light Green 14 Light Green 15 Light Blue 15 L...

Page 61: ...ame desfilename See Chapter 3 for more details and an extended version of COPY that supports different combinations of drive and device numbers COS x COS x is a numeric function that returns the trigonometrie eosine of angle x where x is expressedinunits of radian measure In instances where it is more convenient to express the angle in degrees convert it to radians by multiplying it by 11 1180 Exa...

Page 62: ...uence string foliowed by numeric value You can place DATA listings at any convenient location in a BASIC program See the READ andRESTORE statements for more examples and relevant details DCLEAR DCLEAR is a DOS statement that doses all files and clears the disk channels See also Chapter 3 DCLOSE DCLOSE is a DOS statement that doses all files for disk de vice 8 You can use an extension of the statem...

Page 63: ...he following function returns the radian form of any angle var that is expressed in degrees FN RAD var Failing to define the fundion before calling it in the program results in an UNDEF D FUNCTION error message DELETE strtline endline Use the DELETE command to delete a range of BASIC line numbers and their programming from an existing program Deletion begins with line number strtline and ends at e...

Page 64: ...am unless a CLR statement precedes the subsequent DIM statement For that reason most programroers DIMension arrays within the first few lines of a program DIRECTORY DIRECTORY is a DOS cammand that displays the contents of the directory file for the disk in the current disk drive This cammand is identical to the CATALOG command See Chapter 3 for extended versions of the cammand that allow for alter...

Page 65: ... LOOPs only UNTIL there are 10 of them Listing 2 3 10 N O 2000 30 PRINT X 40 N N 1 50 LOOP UNTIL N 10 60 PRINT PRINT OONE Rather than running a DO LOOP until a given condition is met often it is more convenient to run the loop WHILE a specified condition exists Consider the version of the X printing routine that is shown in Listing 2 4 Listing 2 4 10 N O 2000 30 PRINT X 40 N N 1 50 LOOP WHILE N 10...

Page 66: ...use DOPEN fi eno 11 filename W and apply the PRINT statement to write text information to the file To open a relative file for writing operations use DOPEN tileno 11 filename11 Lrec en W where reeZen is the number of bytes set aside for each record in the file See Chapter 3 for examples and more information about using sequentia and relative text files DRAW xl yl TO x2 y2 DRAW is a bit mapped grap...

Page 67: ...aled by the blinking green light on the disk drive unit any refer ence to DS clears the error condition Executing a PRINT DS statement shows that the string has this general form status code Jiteral comment trackno sectorno where status code is a decimal number indicating the current status of the disk drive block and the value assigned to reserved numeric variable DS literal camment is a literal ...

Page 68: ...comparison fails See Chapter 3 for more details and ex mples EL EL is a reserved numeric variabie tha has meaning only when a BASIC error condition occurs in which c se EL is assigned the line number where the error occurs EL is m st aften used as part of a custom error handling routine ELSE ELSEis an optional part of the IF THEN statement END BASIC sEND statement brings a programtoa smooth conclu...

Page 69: ...t EXP x EXP is a numeric function that returns the value of constant e 2 71828182 to the power of x where x is a numeric constant vari able or expression FAST The FAST cammand doubles the operating speed of the sys tem s 8502 microprocessor from the normal 1 MHz rate to 2 MHz Text and graphics operations can be included in the FAST mode of operation but results are blanked from the screen until th...

Page 70: ...op is counting and executing the statements included in the loop the current count is assigned to a numeric variable numvar The tzumvar associated with the NEXT term is optional Unless you direct otherwise as described below FOR NEXT counts increments in steps of 1 Variabie numvar is left with a value of end 1 at the condusion of the looping operation Example 10 FOR N O TO 9 20 PRINT N 30 NEXT N T...

Page 71: ...ASIC variables GET strvar The GET statement instructs the system to scan the key boardfora pressed key If a key is pressed when the GET statement is executed the key s character is assigned tostring variable strvar If no key is pressed the GET statement assigns the null character to strvar Unlike the INPUT and GETKEY statements GET doesnothalt execution of the program until a key is pressed GET is...

Page 72: ...line 50 brings the program to an end Line 60 handles the situatio q where the user presses a key other than Y or N operations loop back to the GETKEY statement in line 30 The GETKEY statement can be extended to accept a sequence of keystrokes GETKEY var1 var2 var3 where var arguments are variabie names preferably string variabie names GBT ileno var GET fetches a single byte of string or numeric da...

Page 73: ...Reallocate the area for bit map usage by executing a GRAPHIC statement that sets up a bit map mode of operation GSHAPE strvar x y GSHAPE is a grapbics statement tbat plots a pre defined graphic to the screen You defined the graphic in terms of a string variable strvar usually by means of an SSHAPE or SPRSAV statement GSHAPE plots the figure within a rectangular area on the screen where x y is the ...

Page 74: ...ion of a decimal value x The range of decimal values is all integers from 0 through 65535 The converse operation is DEC See Appendix A for more information about computer number systems IF THEN IF THEN is BASIC s primary conditional statement One general form is IF condition THEN statement This version literally says IF a given condition is met THEN execute the given statement implying that if the...

Page 75: ...formation to string or numeric variable var The user must press the RETURN key to complete the operation The nature of the information entered from the keyboard must match the variabie type A statement such as INPUT X for example requires input of a numeric value whereas INPUT M requires a string constant When the user fails to enter the correct variabie type the system automatically prints a REDO...

Page 76: ... prints the numeral 6 to the screen INT x The INT function returns the next smaller integer value of any numeric constant variable or expression x Examples PRINT INT 3 8 prints 3 to the screen PRINT INT 8 3 prints 8 to the screen PRINT INT 1 2 prints 2 to the screen The result of this example is justified on the grounds that nega tive values farther from zero are considered smaller than those clos...

Page 77: ...0 for more details LEFT string x LEFT is a function that returp s the first x charac ters in the designated string constant variable or expression Example PRINT LEFT HELL0 3 This example prints HEL the first three characters in strin HELLO to the screen LEN string The LEN function returns the number of characters in the qesignated string constant variable ar expression LET var expr LET is a variab...

Page 78: ...vno to 1 the system searches for filename on cassette and loads the file into the system A LOAD cam mand with no file name or device number instructs the system to search for the beginning of the next file on the cassette and load that file into RAM An extension of the LOAD cammand includes a relocate flag LOAD filename devno reloflg Setting relo lg to 0 the default value loads the file from the b...

Page 79: ...erly on the earlier production models of the Commodore 128 Programmers preparing software for commercial distribu tion should either avoid the relative positioning format or use an error handling routine to deal with relative positioning See Chapter 7 for more details and examples LOG x LOG is a numeric function that returns the natural or base e logarithm of x where x is a numeric constant variab...

Page 80: ...om the BASIC interpreter to the monitor operating system See details and examples in Chapter 4 MOVSPR sprnum param MOVSPR is a sprite positioning state ment where sprnum is a t5prite number 1 through 8 and paramis a parameter that determines the nature of the operation The parame ters make possible the use of MOVSPR in four different ways 1 Position the upper left corner of the designated sprite a...

Page 81: ...itional statement IF NOT A B for example is the same as A B As a Boolean opera tor NOT înverts binary bit values changes 0 to 1 and 1 to 0 SUB linel line2 ON GOSUB is a control statement that call a subroutine beginning at one of a list of line numbers The line number is determined by the current value of intege expression x If x has a value of 1 the statement calls the subrouti e specified by the...

Page 82: ... program statement OPEN fileno devno The OPEN statement is the primary mechanism used to set aside files for input and output operations including those for the disk drive cassette recorder printer monitor screen and so on The fileno parameter cites a logical file number 0 through 128 The device number devno specifies the kind of device to use the opened file Table 2 10 summarizes the device numbe...

Page 83: ...s than are de scribed here See more details and examples in Chapters 3 and 12 OR OR is used as both a logicaland a Boolean operator As a logical operator OR is usually fit into conditionat statements such as IF X FE OR Y 40 THEN END The condition is satisfied if X FE Y is greater than 40 or both The Boolean OR operator logically ORs two numeric values For example PRINT 1 OR 2 This statement prints...

Page 84: ...essing the fire pushbutton on the game paddie as sembly causes POT to return values of 256 plus the rotation value PRINT expr PRINT is a statement used for printing information contained in expr to the current output device usually the screen PRINT also can print lists of numeric constauts and strings as well as string constauts and expressions If you separate the items in a list of expressions wi...

Page 85: ...r Dollar sign Inserts a dollar sign in numeric values with the option of fixed or floating dollar signs îttî Four up arrows Forces all numeric values to be printed in the exponential for mat Equal sign Centers all strings within a specified field Greater than Right justifies strings in a field PRINT fileno USING format x The PRINT USING statement combines the features of PRINT and PRINT USING desc...

Page 86: ... source code numbers READ var READ statements must be used in conjunction with DATA lists A READ statement sequentially reacts items in DATA list ings and assigns them to the specified numeric or string variable var The variabie types must match that is READ A expects to read string constants from the DATA list whereas READ X reacts only numeric constants Bear in mind that numbers can be regarded ...

Page 87: ...ames it STUFF RENUMBER The RENUMBER command renurnhers the lines in a BASIC program that currently resides in RAM In its simple form RENUMBER renurnhers the entire program begins the new number ing format from line 10 and uses increments of 10 The extended version of the command looks like this RENUMBER newstart incr o dstart where newstart is the new starting line number incr is the iocrement bet...

Page 88: ...ing 2 6 10 FOR J 1 TO 2 20 FOR K 1 TO 5 30 READ D PRINT D 40 NEXT K 50 RESTORE 60 NEXT J 70 DATA TOM DICK HARRY SALLY MUFF The e l ample in Listing 2 6 reads and prints the list of DATA items twicè If it were not for the RESTORE statement in program line 50 the program would run out of data and display an OUT OF DATA error message RESUME RESUME is always used in conjunction with a custom BASIC err...

Page 89: ...ction that returns a random number value equal to or greater than 0 but less than 1 The value of argu ment x determines the exact nature of the operation Whenever argument x is any positive value RND returns a dif ferent random number each time the function is executed RND l for example represents the most commonly used form of the function Setting the argument to 0 seeds the pseudo random number ...

Page 90: ...d of a speci fied sprite sprno Numeric values assigned to the par argument deter mine which of three sprite parameters is returned 0 Sprite X position 1 Sprite Y position 2 Sprite speed See Chapter 8 for more details and specific examples RSPRITE sprno par RSPRITE is a sprite graphics function that returns the sprite parameters currently assigned under the SPRITE statement The sprno argument speci...

Page 91: ...ns the parameters of the current text window depending on the value that you assign to the argument param param 0 the function returns the number of lines in the current text window param 1 the function returns the number of rows in the current text window param 2 the function returns the column format of the current text screen 40 or 80 column screen See examples in Chapter 6 SAVE filename11 devn...

Page 92: ...nates for an IBM PC high resolution graphics program wholly compatible with the Com modore 128 SCALE 1 640 200 This operation compensates forthefact that the IBM PC s high resalution screen has a 640 by 200 format SCNCLR mode SCNCLR clears the screen specified by the mode parameters shown in Table 2 14 mode 0 1 2 3 4 5 Screen Clearing Function Clears the 40 column text screen Clears bit mapped scr...

Page 93: ...SIN A lr 180 where A is an angle expressed in units of degrees SLEEPt SLEEP executes a time delay of a specified period t where t is expressed in seconds SLOW The slow cammand sets the operating speed of the 8502 mi croprocessor to its default 1MHz rate The system must be eperating at the SLOW rate in order to display any information on the screen Also see the FAST command SOUND voice freq dur The...

Page 94: ...th 0 through 4095 Default is 2048 See Chapter 9 for more details and applications examples SPC x Used with PRINT and PRINT statements SPC prints a des ignated number of spaces x in succession Example PRINT X SPC 8 Y This example prints X eight spaces and Y SPRCOLOR mcolor1 mcolor2 SPRCOLOR is a sprite statement that assigns c lors 1 16 to the two additional color sourees available for multicolor s...

Page 95: ...ics statement that copies sprite image data from a designated source srce to a destina tion dest You can specify the sourees and destinations as sprite num bers 1 through 8 or valid string variabie names Examples SPRSAVE 1 S Copy sprite image data from sprite 1 to variabie S SPRSAVE X 2 Copy sprite image data from string variable X to sprite 2 SPRSAVE 3 1 Copy sprite image data from sprite 3 to sp...

Page 96: ...ommand STOP is aften inserted temporarily into a program to halt opera tions for debugging purpqses This is rarely included in programs intended for use by anyone but the programroer STR x The STR function converts any numeric value x to a string format Example N STR 128 This statement assigns a string version of 128 tostring variabie N STR is the inverse of the VAL function SWAP nobytes instrt ex...

Page 97: ...e USR function for an alternative technique for executing machine coded routines from a BASIC program TAB x TAB is a PRINT tormatting function that advances the text cursor x columns to the right where x is an integer value between 1 and 255 inclusively Example PRINT TAB 5 HELL0 This example prints HELLO five column locations to the right of the current cursor position When a TAB function carries ...

Page 98: ...d on or RESET You can set the correct time by assigning the appropriate string value to Tl Example Tl 123148 This example sets the time of day doek for 12 31 48 This string also sets the time of day counter represented by reserved numeric constant TI to the corresponding count Having thus set the time of day doek the time can be deter mined by a simple PRINT Tl statement TO See the FOR NEXT statem...

Page 99: ...returned to the USR fundion by placing it in FACl See the FAC jump table described at addresses AFOO AFA2 in Chapter 13 VAL str The VAL function returns a true numeric version of numerals that are expressed in a string format str Val str is the inverse of the STR function VERIFY filename devno The VERIFY cammand compares a disk or tape based program filename against the version previously loaded i...

Page 100: ...ault is 39 1 through 79 for an 80 column screen default is 79 botrow 1 through 24 default is 24 See Chapter 6 for more details and examples XOR xl x2 XOR is a Boolean operator that returns the EXCLU SIVE OR value of numeric constants variables or expressions xl and x2 Whereas the OR operator returns a binary 1 when either or bath terms are equal to 1 XOR returns a binary 1 only when either term is...

Page 101: ...followed by SHIFT E COLLISION COL followed by SHIFT L COLOR COL foliow d by SHIFT 0 CONCAT C foliowed by SHIFT 0 CONT none COPY CO foliowed by SHIFT P cos none DATA D foliowed by SHIFT A DEC none DCLEAR DCL followed by SHIFT E DCLOSE D followed by SHIFT C DEFFN none DELETE DE followed by SHIFT L DIM D followed by SHIFT I DIRECTORY DI foliowed by SHIFT R DLOAD D followed by SHIFT L DO none DOPEN D ...

Page 102: ...ELSE none INPUT none INPUT I foliowed by SHIFT N INSTR IN followed by SHIFT S INT none JOY J foliowed by SHIFT 0 KEY K foliowed by SHIFT E LEFT LE foliowed by SHIFT F LEN none LET L foliowed by SHIFT E LIST L followed by SHIFT I LOAD L foliowed by SHIFT 0 LOCATE LO followed by SHIFT C LOG none LOOP LO followed by SHIFT 0 MlD M followed by SHIFT I MONITOR MO followed by SHIFT N MOVSPR M followed by...

Page 103: ...oliowed by SHIFT G RIGHT R foliowed by SHIFT I RND R foliowed by SHIFT N RREG R followed by SHIFT R RSPCOLOR RSP followed by SHIFT C RSPOS R foliowed by SHIFT S RSPR none RSP RITE RSP followed by SHIFT R RUN R foliowed by SHIFT U RWINDOW R followed by SHIFT W SAVE S followed by SHIFT A SCALE SC foliowed by SHIFT A SCNCLR S followed by SHIFT C SCRATCH SC foliowed by SHIFT R SGN S followed by SHIFT ...

Page 104: ... foliowed by HIFT 0 Dealing with BASIC Error Condition Commodore BASIC includes a b ilt in error handling protocol When the interpreter encounters c rtain kinds of error conditions the error handling routine interru ts execution of the statement prints out a descriptive error mes age and shows a relevant line number For example running a p ogram that attempts to execute a FOR statement without a c...

Page 105: ... BASIC Error 37 A BEGIN statement is used without a corresponding BEND BREAK BASIC Error 30 The BREAK message indicates that either the program has encoun tered a STOP cammand within an operating program or that the user has pressed the STOP key during execution of a program CAN T CONTINUE BASIC Error 26 The CONT CONTinue cammand normally is used for resum ing the execution of an interrupted progr...

Page 106: ...me FILE NOT OPEN BASIC Error 3 A file must be opened in some fashion befare you read or write data to it FILEOPEN BASIC Error 2 Once a file is opened it must be closed befare attempting to open it again Otherwise the FILE OPEN error occurs FILEREAD BASIC Error 41 The FILE READ error occurs whenever the systemencounters a problem aftera disk reading operation begins such as removing the disk while ...

Page 107: ... largest BASIC line number is 63999 Typing line numbers of 64000 or greater returns a SYNTAX error message The LINE NUMBER TOO LARGE error condition occurs only when a RENUMBER cammand attempts to create line numbers that are larger than 63999 LOAD BASIC Error 29 Certain classes of data loading errors yield this error condition They are not as clearly defined as some of the other loading errors an...

Page 108: ...E BASIC Error 7 Many files have to be specified as input files or output files The NOT OUTPUT FILE error occurs when you attempt to write data to a file opened for read only operations OUT OF DATA BASIC Error 13 The OUT OF DATA error results from an attempt to READ more items than exist in the current DATA listings OUT OF MEMORY BASIC Error 16 This error occurs when certain kinds of program routin...

Page 109: ...he BASIC interpreter is unable to interpret the meaning of an element in the program The message usually results from a typihg error The SYNTAX error condition also occurs when you assign vari abie narnes that include reserved words and after typing BASIC line numbers greater than 63999 TOO MANY FILES BASiC Error 1 The Commodore 128 can deal with no mate than 10 open files at any given time Attemp...

Page 110: ...interrupts the renurn bering operation and cites the line that contains the unresolved line number VERIFY BASIC Error 28 This error condition arises when using the VERIFY command fails to confirm that a file on disk or tape matches the version in RAM Reserved Variables for BASIC Error Handling Routines BASIC s error handling protocol assigns information to several re served variables ER numeric va...

Page 111: ...hat SYNTAX is assigned to sub scripted string variable ERR 11 and the final item shows that vari abie EL has been set to 10 the line number in the program where the error occurred Regarding the ERR variable you can print out all of the error messages by running this brief program FOR K 1 TO 41 PRINT ERR K SPC 2 NEXT K Creating Customized BASIC Error Handling Routines BASIC s built in error handlin...

Page 112: ...trapping routine and point to the beginning of your own error handling routines 2 Write BASIC routines that determine the nature of the potential error conditions and specify how they are to be handled 3 Use one of several versions of the RESUME statement to re sume normal program execution TRAP lineno This form of BASIC s TRAP statement disables the system s built in error handling features and s...

Page 113: ...EXT K 50 END 60 IF ER 20 THEN PRINT INFINITY RESUME NEXT The TRAP statement in line 5 instructs the system to jump to line 60 in the event of any BASIC error condition Line 60 represents an error handling routine that is executed only if the error happens to be error number 20 the division by zero error In this example the routine prints INFINITY on the screen a reasonable response to a divide by ...

Page 114: ...R 11 z 20 FOR K 5 TO 5 30 PRINT 1 K 40 NEXT K 50 END 60 IF ER 20 THEN PRINT INFINITY RESUME NEXT 70 TRAP GOTO EL Program line 70 uses the TRAP statement without the lineno parametertoturn off the custom error handling feature then it does a GOTO statement that refers to the line where the error occurred line 11 in this example The syntax error is thus executed once again but the TRAP feature is di...

Page 115: ... 3 CATALOG FE 06 254 6 CHAR EO 224 CHR C7 199 CIRCLE E2 226 CLOSE AO 160 CLR 9C 156 CMD 9D 157 COLLECT F3 243 COLLISION FE 17 254 23 COLOR E7 231 CONCAT FE 13 254 19 CONT 9A 154 COPY F4 244 cos BE 190 DATA 83 131 DCLEAR FE 15 254 21 DCLOSE FE OF 254 15 DEC Dl 209 DEFFN 96A5 150 165 DELETE F7 247 DIM 86 134 DIRECTORY EE 238 DLOAD FO 240 DO EB 235 DOPEN FEOD 254 13 DRAW ES 229 DSAVE EF 239 DVERIFY F...

Page 116: ... IF BB 139 INPUT 85 133 INPUT 84 132 INSTR D4 212 INT B5 181 JOY CF 207 KEY F9 249 LEFT es 200 LEN C3 195 LET 88 136 LIST 9B 155 LOAD 93 147 LOCATB E6 230 LOG BC 188 LOOP EC 220 MlD CA 202 MONITOR FA 250 MOVSPR FE 06 254 6 NEW AZ 162 NEXT 82 130 NOT AB 168 ON 91 145 OPEN 9F 159 OR BO 176 PAINT DF 223 PEEK C2 194 PEN CE 04 206 4 PI FF 255 PLAY FE 04 254 4 POINTER CEOA 206 10 POKE 97 151 POS B9 185 ...

Page 117: ...5 RSPRITE CE06 206 6 RUN SA 138 RWINDOW CE09 206 9 SAVE 94 148 SCALE E9 233 SCNCLR ES 232 SCRATCH F2 242 SGN B4 180 SIN BF 191 SLEEP FEOB 254 11 SLOW FE26 254 38 SOUND DA 218 SPC A6 166 SPRCOLOR FE 08 254 8 SPRDEF FE 1D 254 29 SPRITE FE 07 254 7 SPRSAV FE 16 254 22 SQR BA 186 SSHAPE E4 228 STASH FE 1F 254 31 STEP A9 169 STOP 90 144 STR C4 196 SWAP FE23 254 35 SYS 9E 157 TAB A3 163 TAN co 192 TEMPO...

Page 118: ...her or not the blockof RAM beginning at 1COO is allocated for bit mapped graphics operations Each line of BASIC programming as portrayed in RAM begins with two bytes that indicate the actual address of the start of the next line The next two bytes represent the line number of the current line The remain der of non zero bytes carry the BASIC tokens and ASCII versions of numerical and string variabi...

Page 119: ...l 31 DOS Oparating and Programming Procedures ...

Page 120: ...loading and running BASIC and machine language programs saving their own BASIC pro grams and perhaps cleaning up a disk by scratching unwanted pro grams Chapter 1 provides most of the information necessary for operating the system to that extent This chapter also describes those procedures but offers a num ber of alternatives and refinements as well The material is organized generally according to...

Page 121: ...others apply to serial 1 0 opera tions in general This section also lists the Kernal routines most useful for execut ing DOS operations from machine language programming Direct access disk commands those working on the most primitive track and sector levels are described in the closing section of this chapter BASIC Commands Specific to DOS The following BASIC commands are specifically designed for...

Page 122: ...C statements apply to serial I 0 operations in gen eral but are limited to those most useful for DOS operations CLOSE and OPEN aften can be replaced with their simpler counterparts DCLOSE and DOPEN The remaining statements GET INPUT and PRINT are absolutely essential however CLOSE Close a specified file GET Fetch a single character from a file and advance the file pointer INPUT Fetch a string of d...

Page 123: ...2 0pen a logica file READST FFB7 65463 Fetch the block status error condition of the previous operation SAVE FFD8 65496 Save a binary file SETLFS FFBA 65466 Specify file device and secondary ad dress numbers SETNAM FFBD 65469 Specify a file name DOS Related Error Conditions DOS returns errors from three different kinds of sources sametimes more than one at a time Assuming that a file named FOO doe...

Page 124: ...INT DS not only provides information regarding the nature of the error but clears the condition by turning off the annoying blinking green light The DS variabie returns a DOS error number that represents one of the error conditions shown in Figure 3 1 Executing PRINT DS shows the same error number foliowed by a verbal description and where relevant the track and sector numbers Error 0 OK The last ...

Page 125: ...ters Error 33 SYNTAX ERROR Improper use of wildcard characters and Error 34 SYNTAX ERROR Missing file name or colon in a disk command Error 39 SYNTAX ERROR Command channel command contains data not recognizable by DOS Error 50 RECORD NOT PRESENT Command specifies a relative file record that does not exist This is not necessarily a problem when creating new records in a file Error 51 OVERFLOW IN RE...

Page 126: ...mpty drive or a disk not formatted Attempting to DLOAD a file that doesn t exist returns a BASIC error FILE NOT FOUND Doing a PRINT DS returns the DOS error code 62 Doing PRINT DS returns this sart of message 62 FILE NOT FOUND OO OO A third kind of DOS error can occur It is far less obvious because it does nat interrupt the execution of a program and does nat cause the green light on the disk driv...

Page 127: ...irectory for the disk in the default disk drive device 8 drive 0 The listingis always directed to the screen However procedures described in followingtext make possible the direction of the disk directory to other kinds of output devices including the disk itself A directory listing begins with a heading that shows from left to right the current drive number disk name disk identification code and ...

Page 128: ...pecial wildcard characters that can be used for listing groups of files with similar file names A question mark char acter is a wildcard symbol for any single character You use an asterisk in place of any number of characters Suppose that a disk directory contains files having the following names STOOPID STOOPY 1STOOGE 2STOOGE STRIP 1 STRIP 2 STOOP Executing a CATALOG or DIRECTORY cammand lists al...

Page 129: ...s the track sector formatand disk directory Once a disk has been formatled as described in this section you don t need to format it again In fact you shouldn t reformat a disk unless you are willing to lose track of all the data saved on it WARNING Formatting a disk destroys references to any data saved on it FormaHing with BASIC S HEADER Command The simplest procedure for formatting a new disk is...

Page 130: ...ation number The quick formatting procedure is generally used only for clearing the directory and in effect wiping it clean for further use The READER command as described thus far assumes that the disk to be formatted is located in drive 0 That is the only choice in a single drive system When you are working with a multiple drive sys tem you can extend the cammand to point to a drive other than 0...

Page 131: ...l to the disk drive 3 Send the NEW command and its parameters 4 Use the CLOSE command to close the channel when the format ting is done The general form of the NEW cammand is Ndriveno diskname idno where driveno is the disk drive number diskname is the desired disk name up to 16 characters and idno is the disk s identification num ber any two alphanumeric characters The following sequence of steps...

Page 132: ...al routine A Laad length of file name from Step 1 to register A B Laad LSB of starting address of file name to register X C Laad MSB of starting address of file name to register Y D Call SETNAM routine at FFBD 4 Call the OPEN routine at FFCO 5 Set up and execute the CLOSE Kernal routine A Laad logical file number to register A B Call CLOSE routine at FFC3 For all practical purposes the NEW cammand...

Page 133: ...edure extensions of it and alternative procedures for saving BASIC pro grams The following also cites a variety of techniques for saving machine language programs and files of machine language data Saving BASIC Programs with DSAVE BASIC s DSAVE cammand makes rather easy the saving of a BASIC program that is currently in system RAM The simplest farm of the commandis DSAVE filename where filename is...

Page 134: ...current disk directory The disk drive runs and the system returns the READY prompt message but the program is not saved and the flash ing green light on the disk drive indicates that a disk error has occurred Normally this feature is regarded as beneficia It prevents the user from accidentally overwriting a file already on the disk Sometimes though not being able to write over a file is a nuisance...

Page 135: ...m statement as long as the portion enclosed in quotes is represented in a string format and the device number is a constant or numeric variable The following example saves itself on disk as SILLY and lists the current directory 10 F SILLY 20 SAVE O F 8 30CATALOG Like DSAVE SAVE normally does nat allow you tosave a new BASIC program that uses the same name as a file that already exists on the curre...

Page 136: ... assigning the block the name VIDEOl BSAVE VIDE01 P1024 TO P2049 If a file is to be saved with a file name that is identical to one already residing on the current disk the filename parameter should begin with an at character Otherwise the DOS system goes into a FILE EXISTS error condition An important extension of the BSAVE cammand specifies the bank number of the block to be saved Unless specifi...

Page 137: ...nes The Kemal s SAVE routine provides a convenient technique for sav ing programs and blocks of data on disk This routine requires infor mation regarding the starting and ending addresses of the block of memory to be saved on disk The starting address must be loaded to a pair of adjacent zero page RAM locations LSB foliowed by MSB and the first of the two addresses must be loaded to register A The...

Page 138: ... Call SAVE at FFD8 5 Close all files by calling CLALL at FFE7 6 Restare the original TEXTTAB values A Pull MSB of old TEXTTAB from stack B Load to TEXTTAB 2E C Pull LSB of old TEXTTAB from stack D Laad to TEXTTAB 2D 7 Return from the routine The example in Listing 3 2 is a direct implementation of the rec ommended procedure for saving a block of memory to disk The example uses the file name MYPROG...

Page 139: ...B OF END ADDR MSB OF END ADDR SAVE CLALL TO CLOSE FILES GET MSB OF OLD TEXTTAB REPLACE IT GET LSB OF OLD TEXTTAB REPLACE IT RETURN No special commands are available for saving and loading BASIC programs in an ASCII text format but the procedure to do so is rather simple Saving an ASCII coded version of a BASIC program is simply a matter of directing a LISTing of that program to a disk file rather ...

Page 140: ...aved as ASCII text and lines 100 through 140 actually do the job Listing 3 3 10 SCNLCR 20 FOR K O TO 9 30 PRINT HOWDY 40 NEXT K 100 DOPEN 1 HOWDYDOO S W 110 CMD 1 120 LIST 10 40 130 PRINT 1 140 DCLOSE A RUN 100 cammand executes the disk save routine creating a SEQuentia text file called HOWDYDOO As described subsequently in this chapter you can reeover the program by reading it as a sequentia file...

Page 141: ...DOS error condi tions The BASIC error appears on the screen as a FILE NOT FOUND message The DOS version of the error condition flashes the green light on the disk drive Executing a PRINT DS cammand prints the DOS error string and turns off the flashing green light Users whohave more than one disk drive can select the souree drive by extending the DLOAD statement in this fashion DLOAD 11 filename 1...

Page 142: ...ased program called WHY ME LOAD O WHY ME 8 or LOAD WHY ME 8 BASIC programs are saved sametimes from a block of RAM that is different from the default block When this is the case the file begins with an address that marks the starting point of that RAM location Unless directed otherwise a subsequent LOAD cammand loads the file from that starting location The LOAD cammand can be extended to indicate...

Page 143: ... disk to Commodore 128 RAM The simplest form of the cammand is BLOAD 11 filename11 where filename is the name of the disk file to be loaded If the file is not in the disk directory the system responds with both BASIC and DOS error conditions BASIC prints the FILE NOT FOUND message and DOS flashes the green light on the disk drive The BLOAD command as described thus far works according toa set of a...

Page 144: ...s with numeric variables Locding and Running Binary Programs with BOOT BASIC sBOOT cammand loads and runs binary coded programs in the same way that the RUN cammand loads and runs BASIC pro grams BOOT assumes the program is resident on the current disk The simplest form is BOOT 11 filename11 where filename is the name of the machine language program that is to be loaded and run Extensions of the c...

Page 145: ...with the data LOAD has loaded into RAM The LOAD routine must be preceded by SETNAM to specify the name of the file to be loaded and by SETLFS to open a disk file and determine whether or not the file is loaded to an alternative address Consider the following procedure 1 Load the file nametoa blockof RAM 2 Set up and execute the Kemal s SETNAM routine A Length of file name to register A B LSB of fi...

Page 146: ...ETURN Procedures for Copying Disk Files The matter of copying a disk file is aften considered in the context of transferring a copy of the file from one disk to another An alternative is to make a copy of a file on the same disk but give the copy a differ ent file name Using BASIC S COPY Command The simplest form of the COPY cammand makes a copy of an origi nal file on the samedisk but with a diff...

Page 147: ...specify an alternative device number COPY Ddriveno oldname TO Ddriveno newname Udevno Using COPY as a BASIC File Cammand You can OPEN a command channel then use a PRINT operation to copy a file with a different name to the same disk The procedure does not support directly copying files from one disk to another The general procedure looks like this OPEN fileno devno secaddr PRINT fileno Cdriveno ne...

Page 148: ...ile name Being able to make backup copies with the same name is a vital part of the whole concept Thus the routine should use some error handling routines to help the user get through a variety of situa tions in an elegant fashion The program in Listing 3 5 suggests some techniques for making the program work more reliably Listing 3 5 10 SCNCLR 20 OPEN 1 8 15 30 INPUT WHAT FILE TO BACKUP F 40 PRIN...

Page 149: ...names The question mark wildcard char acter represents any single character whereas the asterisk wildcard can replace groups of characters Use this command with care SCRATCH 11 11 It deletes every file on the disk The default drive and device numbers are 0 and 8 respectively Use extensions of the command to specify other drive and device numbers SCRATCH filename Ddriveno Udevno A second version of...

Page 150: ...mbers from DS Line 120 Print the string portion of the DS error message Lines 130 160 Print a prompting message wait for a keystroke andreturn tothetest procedure Listing 3 6 10 OPEN 1 8 15 20GOSUB90 30 SAVE 0 8 40 GOSUB90 50 PRINT 1 SO 60 GOSUB90 70 CLOSE 1 80 GOTO 170 90 IF OS 20 THEN RETURN 100 EMS MIDS DS 4 110 EM LEFT EM 1NSTR EM 1 120 PRINT EM 130 PRINT CHECK THE DISK AND DRIVE THEN STRIKE 1...

Page 151: ... filename is the name on the directory listing DOS SHELL a machine language program is described in subsequent text Most of the utility programs are mentioned in this chapter in conneetion with appropriate DOS topics Most of these programs are written in BASIC and you can load then LIST them to see examples of certain BASIC DOS programming techniques The DOS SHELL program is included on the TEST D...

Page 152: ... Text files are tables of string data that represent information mean ingful to the user names telephone numbers checkhook entries and football statistics Text files are sourees of data generated and recalled by means of other programming operations A sequentia text file is one generated in a sequentia fashion from the first piece of information record to the last Such files must be read in a sequ...

Page 153: ...ile as NUMSl and uses the default drive and device numbers 8 and 0 respectively The next example uses the BASIC 2 0 version to do exactly the samejob OPEN 1 8 211 0 NUMS1 S W11 It is not unusual to have a situation where you need to open an old sequential text file and rewrite it with new information Attempt ing to write information to an existing file creates a FILE EXISTS disk error message You ...

Page 154: ...g the file and string is a string constant variable or expression If you want the data to he printed to the screen as well as the sequentia file use this combination of general statements and PRINT filenum string PRINT string Two statements can he used for reading sequentia file data INPUT filenum strvar GET filenum strvar where fi_lenum is the file number assigned to the text reading file and str...

Page 155: ...1 filename11 D driveno Udevno where fileno is the logical file number filename is the name of the sequentia file to be appended and driveno and devno are optional parameters for the drive and device numbers The BASIC 2 0 version of the APPEND statement is OPEN fileno devno channo 11 driveno filename A11 This example differs from its normal open for write counter part by indicating an append operat...

Page 156: ... 3 Close the file The routine in Listing 3 7 opens a text file called NUMS1 writes some data to it and doses the file The sameroutine then reopens the file reads the data prints the data to the screen and ends by closing the file Line 10 0pen file 1 for writing a sequentia file NUMSl Line 30 Write the following sequence of information to the file HELLO 0 HELLO 1 HELLO 2 HELLO 3 HELLO 4 HELLO 5 HEL...

Page 157: ...always contain a known number of entries records The actual number of records in fact is often irrele vant The next examples illustrate techniques for generating then reading the information from a sequentia file of indefinite length 10 DOPEN 1 STUFF W 20 INPUT ITEM OR TO END I 30 IF 1 THEN DCLOSE END 40 PRINT 1 1 50GOT020 Line 10 0pen a file number 1 as STUFF for sequentia writing operations Line...

Page 158: ...yte within a given record Relative File Statements and Functions Relative disk files must be apened in a particular fashian befare yau can write or read them You can propedy infer from the nature of the OPEN statements that no difference exists between opening a relative file for reading and writing operations DOPEN fi enum 11 filename11 Lrec en Ddriveno Udevno or OPEN filenum devno channo 11 driv...

Page 159: ...d befare executing any read write operations to it The record pointing statement uses this general form RECORD fileno recno byteno where fileno is the file number assigned to the relative file recno is the desired record number 0 through 65535 and byteno is an optional byte number within the record The following example points to the lOth byte within record number 55 RECORD 1 55 10 The subsequent ...

Page 160: ...re adequate for carrying out any task meaningful in a BASIC operating environment Programmets who have no need or desire to execute disk operations beyond those provided through BASIC s DOS commands have no need to delve into the way the disk drive system organizes information storedon disk However the disk drives operating system is readily available for fundamental operations that can be specifi...

Page 161: ...h 52 also include 21 sectors The implication is that those tracks are near the outer edge of the opposite surface of the disk The track auct sector numbering format provides the essenhal tools for pointing to addressing the beginning of any sector on the disk The full range of addressing is from track 1 sector 0 through track 70 sector 16 Track and sector numbers point to a block of 256 bytes of d...

Page 162: ...a corresponding data channel requires a somewhat dif ferent form of the OPEN statement OPEN filenum devicenum channelnum buffer ilenum the number to be assigned to the command channel for ref erence purposes Is different from the command channel file number devicenum device number of the disk drive Is same as the one used for opening the command channel channelnum a data channel number between 2 a...

Page 163: ...disk buffer has this general form U1 channelnum drivenum tracknum sectornum Ul the block read command expression channelnum the data channel number used when opening the channel drivenum disk drive number usually 0 tracknum track number of the block to be transferred sectornurn sector number of the block to be transferred The block read command line doesnotstand alone however It must be directed t...

Page 164: ...channel number used when opening the channel drivenum disk drive number usually 0 tracknum track number where the block is to be transferred sectornurn sector number where the block is to be transferred Like the block read command you have to send the block write command to the disk drive through the command channel PRINT filenum U211 channelnum drivenum tracknum sectornurn where filenum is the co...

Page 165: ...the data channel advance the block pointer accordingly You may want to set the block pointer to a specific byte within the current data buffer This can be done through the command chan nel using the B P block pointer command The general form of the block pointer command is B P channelno byteno channelno the data channel previously opened to the disk drive byteno the byte number for the desired poi...

Page 166: ...trackno sectorno and PRINT fileno 11 B F11 driveno trackno sectorno where fileno is the file number of the previously opened disk com mand channel In principle you can allocate and free disk sectors quite easily In practice however avoid the directory track track 18 altogether allocating sectors already used for other purposes and freeing sectors that contain data you do notwant to lose One built ...

Page 167: ...or locating the blocks in the directory Byte absolute 0 1 2 through 31 34 through 63 66 through 95 98 through 127 130 through 159 162 through 191 194 through 223 226 through 255 Function Track of next directory block Sector of next directory block File entry 30 bytes File entry 30 bytes File entry 30 bytes File entry 30 bytes File entry 30 bytes File entry 30 bytes File entry 30 bytes File entry 3...

Page 168: ...USR 4 Relative REL Bit 6 File lock unlock status where 0 Unlocked 1 Locked Bit 7 File status where 0 Splat file 1 Good file Track number of the beginning of the file Sector number of the beginning of the file File name padded with ASCII 160 AO to fill the 15 byte space Track number of the first side sector block for a relative file Sector number of the first side sector block for a relative file L...

Page 169: ...4 Monitor and Assembly Language Procedures ...

Page 170: ...n means and how it is related to the more common decimal notation The monitor displays data and accepts data from the keyboard in a single byte hexadecimal format This is a clear reflection of the fact that the 8502 microprocessor is an eight bit device Regarding the addressing format the 8502 is a two byte ar 16 bit device The monitor however displays and accepts addresses in a 21 2 byte format w...

Page 171: ...iel Monitor Operations The system monitor uses a series of commands that give you an opportunity to examine the data at a specified range of addresses write new data to a range of RAM addresses save or load ranges of data from disk transfer blocks of data between two address areas search for specified combinations of data bytes campare two blocks of data fill a blockof RAM with a specified data by...

Page 172: ...e system to the BASIC interpreter Pressing the Reset pushbutton also restores the BASIC interpreter but only after checking the current disk drive for a startup program Executing a G F4000 restores operations from the BASIC inter preter in exactly the same way that pressing the Reset pushbutton does checking the current disk drive for a possible startup program Executing G 4003 works like executin...

Page 173: ...ater than symbol foliowed by an address a space and a byte of data to be written to the address Pressing the RETURN key subsequently writes the data to the address After you press the RETURN key the system displays eight con secutive data bytes beginning from the specified address The first byte in the series is the one specified by the command Many instauces occur where it is sufficient to write ...

Page 174: ... ing to such locations but you will find that the data take on their orig inal values after you press the RETURN key Moving Blocks of Memory The Commodore 128 monitor includes a simple command that trans fers a block of ROM or RAM data to an alternative RAM location The general farm of the command is Tsrcestrt srcend destart where srcestrt is the first address in the block of data to be copied src...

Page 175: ...nd begins with a C character foliowed by the ad dresses The parameters are separated with a space and the addresses should begin with a character that indicates the bank number Filling Blocks of RAM Filling blocks of RAM with a single known data byte can serve as part of a useful testing and debugging tool The monitor s Fill command does the job quickly and effectively The Fill command uses this g...

Page 176: ...nary files and machine language programs originally entered in the monitor mode of operation Save is similar in farm and purpose to BASIC s BSAVE command The general form of the Save command S filename devno strtaddr endaddr where filename is any valid file name devno is the device number and strtaddr is the starting address of the block to be saved The final parameter endaddr marks the end of the...

Page 177: ...disk drive L 11 SALTY11 8 The RAM address where the loading begins depends on the ad dress used for saving the file in the first place You can alter the ad dress where the loading begins however by using the altstrt extension L 11 filename11 devno altstrt A disk file called SALTY can be loaded at an alternative RAM address in this fashion L SALTY 8 E4000 The altstrt parameter changes only the star...

Page 178: ...mand that can perfarm several use ful disk operations The general form is devno cmd where devno is the device number default 8 and cmd is one of sev eral disk commands Display the disk status I Initialize the disk Display the entire disk directory SO PR Display directory of files beginning with PR SO filename Scratch a disk file that has a file name filename NO header id Format a disk with the hea...

Page 179: ...ing and the useful and informative coding is not limited to the block of ROM cited in the demonstration The monitor programming includes a disassembler function one that translates blocks of machine coding into a souree code language far easier to read and interpret The next monitor cammand examines the same area of ROM cited in the previous demonstration but in a form far more mean ingful to anyo...

Page 180: ... of the powerful programming tools of a full blown assembler macro assembler Such features are available as separate software items from a number of different suppliers The mini as sembler however is adequate for any sort of programming task and is particularly useful for relatively small tasks Starting an assembly operation is a matter of entering this sart ofcommand A strtaddr first instruction ...

Page 181: ...02 registers can be a powerful test of a debugging tool The content of the registers should nat be changed indiscriminately Assuming you have a clear purpose in mind the simplest procedure is to 1 Execute the monitor s R cammand to display the current con tent of the registers 2 Use the cursor control keys to position the text cursor over the characters to be changed and overstrike them with the d...

Page 182: ...or SYS statement should conclude with an RTS The notion of using a BRK instruction to interrupt a program is mainly a debugging and testing technique Inserting a temporary BRK instruction gives you a chance to halt the operation of the program and verify the results to that point Executing the G command without specifying a starting address forces the system to begin execution at the address curre...

Page 183: ...played by the monitor s disassembler The exception is the form of the address indicated by relative ad dressed operations The table shows the one byte relative addressing format actually used by the 8502 The C128 disassembler however shows the absolute target address in those instances Op Code Hex Dec 00 0 01 1 02 2 03 3 04 4 05 5 06 6 07 7 08 8 09 9 0A 10 OB 11 0C 12 0D 13 OE 14 OF 15 10 16 11 17...

Page 184: ...not used 30 48 BMI relative 2 31 49 AND indirect Y 2 32 50 not used 33 51 not used 34 52 not used 35 53 AND zero page X 2 36 54 ROL zero page X 2 37 55 not used 38 56 SEC implied 1 39 57 AND absolute Y 3 3A 58 not used 3B 59 not used 3C 60 not used 3D 61 AND absolute X 3 3E 62 ROL absolute X 3 3F 63 not used 40 64 RTI implied 1 41 65 EOR indirect X 2 42 66 not used 43 67 not used 44 68 not used 45...

Page 185: ... not used 64 100 not used 65 101 ADC zero page 2 66 102 ROR zero page 2 67 103 not used 68 104 PLA implied 1 69 105 ADC immediate 2 6A 106 ROR accumulator 1 6B 107 not used 6C 108 JMP indirect 3 6D 109 ADC absolute 3 6E 110 ROR absolute 3 6F 111 not used 70 112 BVS relative 2 71 113 ADC indirect Y 2 72 114 not used 73 115 not used 74 116 not used 75 117 ADC zero page X 2 76 118 ROR zero page X 2 7...

Page 186: ...zero page X 2 97 151 not used 98 152 TYA implied 1 99 153 STA absolute Y 3 9A 154 TXS implied 1 9B 155 not used 9C 156 not used 9D 157 STA absolute X 3 9E 158 not used 9F 159 not used AO 160 LDY immediate 2 Al 161 LDA indirect X 2 A2 162 LDX immediate 2 A3 163 not used A4 164 LDY zero page 2 A5 165 LDA zero page 2 A6 166 LDX zero page 2 A7 167 not used A8 168 TAY implied 1 A9 169 LDA immediate 2 A...

Page 187: ...ed 1 C9 201 CMP immediate 2 CA 202 DEX implied 1 CB 203 not used CC 204 CPY absolute 3 CD 20S CMP absolute 3 CE 206 DEC absolute 3 CF 207 not used DO 20S BNE relative 2 Dl 209 CMP indirect Y 2 D2 210 not used D3 211 not used D4 212 not used DS 213 CMP zero page X 2 D6 214 DEC zero page X 2 D7 21S not used DS 216 CLD implied 1 D9 217 CMP absolute Y 3 DA 21S not used DB 219 not used DC 220 not used ...

Page 188: ...BC absolute X 3 FE 254 INC absolute X 3 FF 255 nat used Figure 4 1 shows the organization of registers within the 8502 mi croprocessor including flag bit details of the processor status register P The 8502 lnstruction Set The remainder of this chapter is devoted to a detailed version of the 8502 instructien set The material is arranged in alphabetical order by instructien set mnemonics Asterisks s...

Page 189: ...Y BIT ZERO BIT INTERRUPT DISABLE BIT L DECIMAL MODE ENABLE BIT ADC Add memory to accumulator with carry Operation Sum the contentsof memory accumulator and C Place result in accumulator Status Register P NV D I z c Addressing Assembly Hex Dec No Mode Language Format Op Code Op Code Bytes indirect X ADC Oper X 61 97 2 zero page ADCOper 65 101 2 immediate ADC Oper 69 105 2 absolute ADC Oper 6D 109 3...

Page 190: ... AND Oper Y 31 49 2 zero page X AND Oper X 35 53 2 absolute Y ANDOper Y 39 57 3 absolute X AND Oper X 3D 61 3 ASL Arithmetic shift left Operation Shift the content of memory or accumulator one bit to the left with the high order bit going to C Shift a zero bit into the ow order bit location Actdressing Assembly Mode Language Format zero page ASL Oper accumulator ASL absolute ASL Oper zero page X A...

Page 191: ...s Register P N V D I Z C Hex Dec No Op Code Op Code Bytes 90 144 2 Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes BO 176 2 Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes FO 240 2 BIT Test bits in accumulator with bits in memory Operation Logically AND the content of memory with the accumu lator result of bit 7 to N and bit 6 to V Set Z 1 if bytes in accumu lator and...

Page 192: ...0 Addressing Mode relative Assembly Language Format BNE BPL Branch if result plus Operation Branch if N 0 Addressing Mode relative Assembly Language Format BPL Status Register P NV D I z c M7M6 Hex Dec No Op Code Op Code Bytes 24 36 2 2C 44 3 Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes 30 48 2 Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes DO 208 2 Status Registe...

Page 193: ...lace next address on the stack high or der byte foliowed by low order byte Set I 1 Actdressing Mode implied Assembly Language Format BRK BVC Branch on overflow clear Operation Branch if V 0 Actdressing Mode relative Assembly Language Format BVC BVS Branch on overflow set Operation Branch if V 1 Status Register P N V D I Z C 1 Héx Dec No Op Code Op Code Bytes 00 0 1 Status Register P N V D I Z C Re...

Page 194: ...de implied Assembly Language Format CLD CLI Clear interrupt Operation Set I 0 Addressing Mode implied Assembly Language Format CLI Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes 70 112 2 Status Register P N V D I Z C ___ 0 Hex Dec No Op Code Op Code Bytes 18 24 1 Status Register P NV DIZC o __ _ Hex Dec No Op Code Op Code Bytes DB 216 1 Status Register P N V D I Z C _o __ Hex Dec N...

Page 195: ... Mode Language Format Op Code Op Code Bytes indirect X CMP Oper X Cl 193 2 zero page CMP Oper C5 197 2 immediate CMP Oper C9 201 2 absolute CMP Oper CD 205 3 indirect Y CMP Oper Y Dl 209 2 zero page X CMPOper X D5 213 2 absolute Y CMP Oper Y D9 217 3 absolute X CMPOper X DD 221 3 CPX Campare memory and X register Operation Compare the content of memory and X register Adjust status bits accordingly...

Page 196: ... of memory by one Operation Decrement the content of memory by one Adjust N and Z bits accordingly Status Register P NV D I z c Addressing Assembly Hex Dec No Mode Language Format Op Code Op Code Bytes zero page DEC Oper C6 198 2 absolute DEC Oper CE 206 3 zero page X DECOper X D6 214 2 absolute X DEC Oper X DE 222 3 DEX Decrement the X register Operation Decrement the content of the X register Ad...

Page 197: ...ccumulator Adjpst N and Z bits accordingly Status Register P NV D I z c Addressing Assembly Hex Dec No Mode Language Format Op Code Op Code Bytes indirect X EOR Oper X 41 65 2 zero page EOROper 45 69 2 immediate EOR Oper 49 73 2 absolute EOROper 4D 77 3 indirect Y EOR Oper Y 51 81 2 zero page X EOROper X 55 85 2 absolute Y EOROper Y 59 89 3 absolute X EOROper X 5D 93 3 INC lucrement memory Operati...

Page 198: ...the N and Z bits accordingly Status Register P NV D I z c Addressing Assembly Hex Dec No Mode Language Format Op Code Op Code Bytes implied INX E8 232 1 INY Increment the Y register Operation Increment the Y register by 1 Adjust the N and Z bits accordingly Addressing Mode implied Assembly Language Format INY JMP Jump unconditionally Status Register P NV D I z c Hex Dec No Op Code Op Code Bytes C8...

Page 199: ...Assembly Language Format JSR Oper LDA Load accumulator with memory Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes 20 32 3 Operation Load the content of memory to the accumulator Adjust the N and Z bits accordingly Status Register P NV D I z c Addressing Assembly Rex Dec No Mode Language Format Op Code Op Code Bytes indirect X LDA Oper X Al 161 2 zero page LDAOper A5 165 2 immediate...

Page 200: ... Y BE 190 3 LDY Load Y register with memory Operation Load the content of memory to the Y register Adjust the N and Z bits accordingly Status Register P NV D I z c Actdressing Assembly Hex Dec No Mode Langtlage Format Op Code Op Code Bytes immediate LDY Oper AO 160 2 zero page LDYOper A4 164 2 absolute LDYOper AC 172 3 zero page X LDY Oper X B4 180 2 absolute X LDY Oper X BC 188 3 LSR Lugical shif...

Page 201: ...s 46 70 2 4A 74 1 4E 78 3 56 86 2 5E 94 3 Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes EA 234 1 Operation Logically OR the content of memory and accumulator Place result in the accumulator and adjust N and Z bits accordingly Status Register P NV D I z c Addressing Assembly Hex Dec No Mode Language Format Op Code Op Code Bytes indirect X ORA Oper X 01 1 2 zero page ORAOper 05 5 2 ...

Page 202: ...o the current stack Addressing Mode implied Assembly Language Format PHP PLA Pull accumulator from stack Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes 08 8 1 Operation Pull the top byte from the current stack and place it into the accumulator Adjust the N and Z bits accordingly Status Register P NV D I z c Addressing Assembly Hex Dec No Mode Language Format Op Code Op Code Bytes i...

Page 203: ...No Mode Language Format Op Code Op Code Bytes zero page ROLOper 26 38 2 accumulator ROL 2A 42 1 absolute ROLOper 2E 46 3 zero page X ROL Oper X 36 54 2 absolute X ROLOper X 3E 62 3 ROR Rotate right Operation Rotate memory or accumulator one bit to the right through the C bit Status Register P NV D I z c Addressing Assembly Rex Dec No Mode Language Format Op Code Op Code Bytes zero page ROROper 66 ...

Page 204: ...ssembly Language Format RTS SBC Subtract with carry as borrow bit Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes 60 96 1 Operation Subtrad the content of memory from accumulator subtract inverted C bit from the result and place the result in the accumulator Status Register P NV D I z c Actdressing Assembly Hex Dec No Mode Language Format Op Code Op Code Bytes indirect X SBC Oper X ...

Page 205: ...EI Set interrupt disable Operation Set I 1 Actdressing Mode implied Assembly Language Format SEI STA Store accumulator to memory Status Register P N V D I Z C ___ 1 Hex Dec No Op Code Op Code Bytes 38 56 1 Status Register P N V D I Z C 1 __ _ Hex Dec No Op Code Op Code Bytes F8 248 1 Status Register P N V D I Z C _1 __ Hex Dec No Op Code Op Code Bytes 78 120 1 Operation Store the content of the ac...

Page 206: ...tore register X to memory Operation Store the content of the X register to memory Status Register P N V D I Z C Actdressing Assembly Hex Dec No Mode Language Format Op Code Op Code Bytes zero page STX Oper 86 134 2 absolute STX Oper 8E 142 3 zero page X STX Oper X 96 150 2 STY Store register Y to memory Operation Store the content of register Y to memory Status Register P N V D I Z C Actdressing A...

Page 207: ...nsfer the content of the accumulator to register Y Actdressing Mode implied Assembly Language Format TAY Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes A8 168 1 TSX Transfer the stack pointer to register X Operation Transfer the content of the stack pointer to register X Actdressing Mode implied Assembly Language Format TSX Status Register P N V D I Z C Rex Dec No Op Code Op Code B...

Page 208: ...nt of the X register to the stack pointer Addressing Mode implied Assembly Language Format TXS Status Register P N V D I Z C Hex Dec No Op Code Op Code Bytes 9A 154 1 TYA Transfer register Y to accumulator Operation Transfer the content of the Y register to the accumulator Adjust the N and Z bits accordingly Status Register P NV D I z c Addressing Assembly Hex Dec No Mode Language Format Op Code O...

Page 209: ...5 Introduetion to CP M Procedures ...

Page 210: ...ry of special features that should give Commodore 128 users good reason to pur sue the subject in greater depth Bringing Up CP M on the Commodore 128 The CP M operating system has to be loaded into the Commodore 128 from the CP M System Disk The disk is auto booting so it can be loaded and run by turning on the computer doing a Reset operation or entering the BOOT command The system is ready for u...

Page 211: ...MAC SUBMIT DATE FILESPEC KEYFIG PUT SHOW COMMANDS DUMP HELP MAC SAVE TYPE DEVICE GENCOM LIB RENAME SID CNTRLCHARS COPYSYS ED ERASE HEXCOM INITDIR PATCH PIP COPY SET SETOEF USER XREF The first topic in the list offers a general view of CP M for the Commodore 128 You can access this information by responding to the HELP prompt C128_CP M NOTE The Commodore 128 keyboard does not include the underline ...

Page 212: ...LP prompt with C128_CP M VIRTUALDISK You are wise to begin your computerized study of CP M for the Commodore 128 by reviewing the notational conventions used on the HELP screens Use the following command to display that summary COMMANDS CONVENTIONS The following paragraphs list all help commands and the kinds of information they offer The commands as shown here assume the system is displaying the ...

Page 213: ...ummary of procedures for redefining the functions as signed to keys Help Mode Command C12S_CP M RT_SHFT_FNCT MODE_TOGGLE A description of the ALT key and ways to change screen attributes Help Mode Command C128_CP M RT_SHFT_FNCT STRING_EDIT Instructions on how to redefine the application of keys in terros of string expressions Help Mode Command C128_CP M RT_SHFT_FNCT HELEDIT Instructions on how to ...

Page 214: ...rst time users also ought to be aware of the fact that the CP M System Disk supplied with the Commodore 128 has programming on bath sides It is nat a double sided disk in the technica sense how ever The two sides are entirely separate and use separate directories Thus when you make a backup copy on the 1571 disk drive you should be prepared to copy files from bath sides to copy all the files from ...

Page 215: ...uilt in command DIR with options is a transient command Help Mode Commands DIR DIR BUILT IN DIR BUILT IN EXAMPLES DIR WITHOPTIONS DIR WITHOPTIONS OPTIONS DIR WITHOPTIONS EXAMPLES DUMP The DUMP cammand displays the ASCII coding fora speci fied file Cammand Type Transient Help Mode Command DUMP ED The ED cammand invokes a simple line editor that is intended for generating souree files for 8080A codi...

Page 216: ...sting file for date time stamping Help Mode Command INITDIR LINK The LINK cammand links concatenates one binary file to the end of another The command is not included on the basic CP M disk Help Mode Commands LINK LINK OPTIONS LINK EXAMPLES MAC The MAC cammand assembles 8080NZ80 source code ASM files to executable machine code The cammand is not included on the basic CP M disk Help Mode Commands M...

Page 217: ...E SET The SET cammand sets a number of different disk parameters Command Type Transient Help Mode Commands SET SH LABEL SET LABEL EXAMPLES SET PASSWORDS SET PASSWORDS MODES SET ATTRIBUTES SET ATIRIBUTES EXAMPLES SET DEFAULT SET TIME STAMPS SET TIME STAMPS OPTIONS SET TIME STAMPS EXAMPLES SET DRIVES SETDEP The SETDEF cammand displays or defines disk drives for search order under loading or SUBMIT o...

Page 218: ... summary of variables used in assembly programming The cammand is not available on the basic CP M disk Help Mode Command XREF DATE The DATE cammand is used for setting and displaying the calendar doek built into the CP M system Command Type Transient Help Mode Commands DATE DATE EXAMPLES DEVICE The DEVICE cammand is the primary mechanism for set ting device parameters such as screen size and RS 23...

Page 219: ...EX KEYFIG EDITING_KEYS EDIT_SPECIAL KEYFIG EDITING_KEYS EDIT_STRINGS KEYFIG FINISHING_UP KEYFIG FOR_EXPERTS KEVFIG KEY_ VALUES KEYFIG LOG PHY_CLRS KEYFIG SELECT_A _KEY KEYFIG SETIING_UP KEYFIG SETTING_UP WHAT_TO_DO LIB The library cammand creates library files for REL files It is not included on the basic CP M disk Help Mode Commands LIB LIB OPTIONS LIB MODIFIERS LIB EXAMPLES PUT The PUT cammand d...

Page 220: ... The actual mechanica procedure depends on whether you are using a single or double drive system Using a Single Drive System The procedure for making a backup copy of the CP M master disk refers to virtual disk Drive E No such disk drive exists but the sys tem thinks it does For all practical purposes Drive A and Drive E are the same 1 Bring up the CP M operating system 2 When the A prompt appears...

Page 221: ...ative narnes for Drives 0 and 1 1 Bring up the CP M operating system with the CP M master disk in Drive A and the new disk in Drive B 2 When the A prompt appears enter this command FORMA T B 3 Use the gray up and down arrow keys toselect the C128 double sided format option and press the RETURN key 4 When prompted to do so replace the CP M master disk with the new disk to he formatted and type 5 Wh...

Page 222: ...Text Scre n Procedur s ...

Page 223: ...portions of split text graphics sereens devoted to text operations Column Formats The text sereens for the Commodore 128 are most often specified as 40 column or 80 column screens The 40 column format is available through the composite video output whereas the 80 column screen is visible only through the RGB output The 40 Column Text Screen Format Unless you specify otherwise the Commodore 128 bri...

Page 224: ...es characters that have the same height but half the width of the 40 colurnn characters That 80 colurnn format is the most commonly used version and is available only through the RGB video output The secoud 80 column format uses characters that are the same size as those used for the 40 colurnn screens but the software makes possible scrolling the text horizontally so that complete lines can be vi...

Page 225: ...t window is the largest possible text screen area Gen erally speaking the default text window files all of the area within the screen s border area You can reduce the size of the text window which does not change the size of the characters but rather the size of the screen area where normal printing and text scrolling operations take place Using appropriate techniques you can print important text ...

Page 226: ...n is better in tbat it can display any combination of all the characters at one time The 40 column screen cannot do so As far as 40 column displays are concerned two different ebar aeter sets exist One is commonly called the uppercaselgraphics set It is the system s default character set that prints all alphabetical ebar aeters in tbeir uppercase format and supports all tbe special grapb ics cbara...

Page 227: ...video RAM ad dresses There is little justification for resorting to this more cumher some technique under normal text screen conditions But POKEing does open the door for more sophisticated procedures that call for using multiple sereens of text and loading text data directly from a disk file The closing sections of this chapter describe the nature of video RAM and the kinds of character data that...

Page 228: ...column formats They are drastic procedures however because they restore many other default screen attributes and situations exist where that is quite inconvenient The preferred way to switch column formats from the keyboard is by pressing ESC X press the ESC key release it then press the X key This operation toggles the screen format If the sy tem is using the 40 column format ESC X changes it to ...

Page 229: ...nd clear the 40 column screen Use GRAPBIC 5 1 to set and clear the 80 column screen PRINTing the ESC X Function You can use the toggling effect of the ESC X keyboard operation to change column formats The general idea is to PRINT a string com posed of ASCII characters for ESC and X PRINT CHR 27 CHR 88 or PRINT CHR 27 X Bath examples take advantage of the fact that ASCII code 27 is the ESCape code ...

Page 230: ...e 80 column screen The Kernal includes a routine that toggles swaps the column format in much the same way as the ESC X operation This routine is located at FF5F 65375 and can be implemented from BASIC in this simple fashion SYS65375 Switching Column Formats from Machine Language Programming The zero page 40 80COL register at D7 is critical for executing the simplest column format routines in mach...

Page 231: ...ort of PEEK fundion PEEK 54533 AND 128 If this fundion returns a value of 0 the switch is latched down 80 column Otherwise this fundion returns a value of 128 to show that the switch is in its unlatched position 40 column That is a read only operation It has no effect on the current col umn format You must apply one of the column format operations to take advantage of the information you find ther...

Page 232: ...yboard operations or some programming the system remains in that mode of operation Switching Character Sets trom the Keyboard The preferred way to switch column formats from the keyboard is by pressing SHIFT C holding down one of the SHIFT keys while press ing the Commodore key C This operation toggles the character set if the system is using the uppercase graphics set SHIFT C changes to the upper...

Page 233: ...r you have no way of knowingin advance which character set the user will be using at the moment The exam ple in Listing 6 2 forces the issue Line 10 Clear the screen and home the cursor Line 20 Set the uppercase graphics character set and disable any further change Lines 30 and 40 Get information from the keyboard Lines 50 and 60 Print the information Line 70 Release the loek on character set chan...

Page 234: ...A2C 2604 is cleared to zero when using the uppercase graphics character set and set to 1 when using the uppercase lowercase set If PEEK 2604 AND 2 0 the system is using the uppercase graphics character set If PEEK 2604 AND 2 2 the system is using the uppercase lowercase character set If you want to change character sets you can POKE the appro priate values to that register The character set will c...

Page 235: ...r set changes LDA 12 JSR FFD2 is equivalent to PRINT CHR 12 Provided the system is using its standard ROM based character set machine language routines referring to bit 1 in register 0AZC can switch character sets without regard to the locking feature of the MODE register The following routine sets the uppercase graphics character set LDA 0A2C AND FD STA 0A2C This one sets the uppercase lowercase ...

Page 236: ...red characters on a darker colored background You can reverse the standard foreground background format and plot subsequent characters intheir reverse mode In that case the character is plotted with the background color and the remairring space uses the foreground color The reverse mode is frequently used for highlighting portions of text on the screen Switching Normal Reverse Chdracters from the ...

Page 237: ... PRINT THIS IS GOING TO BE A space RvsOn GREAT RvsOff space DAV An alternative procedure refers to the reverse normal flag regis ter RVS at zero page address F3 243 This register is cleared to zero when the system is to print normal characters and the register is settoa value greater than zero when printing reverse characters RVS A zero page flag register that determines whether characters are pri...

Page 238: ...und background and border colors The background color is the overall color of the blank portion of the screen The border color is the color of the area surrounding the actual working portion of the screen The background and foreground colars work tagether to define the appearance of characters on the screen In the normal character mode characters are plotted with the foreground color and the space...

Page 239: ...15 Light Blue Light Blue 16 Light Gray Light Gray Code 40 Column 80 Column Hex Dec Color Color 00 0 Black Black 01 1 White White 02 2 Red Dark Red 03 3 Cyan Light Cyan 04 4 Purple Light Purple 05 5 Green Green 06 6 Blue Blue 07 7 Yellow Light Yellow 08 8 Orange Dark Purple 09 9 Browrt Dark Yellow 0A 10 Light Red Light Red OB 11 Dark Gray Dark Cyan 0C 12 MediumGray MediumGray 0D 13 Light Green Ligh...

Page 240: ...ming The four lower order bits in the VIC registe r at D020 53280 carry the current border color as represented by the codes in Table 6 2 0 through 15 The presence of this register suggests an alterna tive procedure for setting the border color from BASIC POKE 53280 co r where colris a code number 0 through 15 The default light green border can thus be set by POKE 53280 13 The border color registe...

Page 241: ... with the border color the default can be changed by using BASIC s COLOR state ment or by writing appropriate values to a background color register in the VIC Two COLOR statements exist for setting background colors one for the 40 column screen and another for the 80 column screen Both use color codes colr in the 1 through 16 format See Table 6 1 For the 40 column screen use COLOR O co r For the 8...

Page 242: ...e Character Colors The color attributes of a text character are defined in terms of its fore ground and background colors Unless the system is operatingin the reverse mode the characters are plotted with the foreground color Setting Foreground Colors trom the Keyboard Character colars can be changed directly from the keyboard and specified in quote mode statements according to the keystrokes sum m...

Page 243: ...ark Cyan Ca 5 Medium Gray Medium Gray C 6 Light Green Light Green Ca 7 Light Blue Light Blue C 8 Light Gray Light Gray Code 40 Column 80 Column Hex Dec Foreground Foreground 90 144 Black Black 05 5 White White 1C 28 Red Dark Red 9F 159 Cyan Light Cyan 9C 156 Purple Light Purple 1E 30 Green Green 1F 31 Blue Blue 9E 158 Yellow Light Yellow 81 129 Orange Dark Purple 95 149 Brown Dark Yellow 96 150 Li...

Page 244: ...hin BASIC pro gramming Uslng the COLOR Register The four lower order bits in the zero page register at Fl 241 carry the current character color in the 0 through 15 format see Table 6 2 This suggests an alternative procedure for setting the char acter color from BASIC POKE 241 co r where colris a code number 0 through 15 The general procedure for setting the character color from a machine language ...

Page 245: ...its the character set to the first 64 characters shown in Table 6 5 Most programmets find the smaller family of characters adequate for most extended color operations Although just 64 characters are available they can be handled in four different ways 1 As normal reverse off non shifted characters 2 As normal shifted characters 3 As reverse non shifted characters 4 As reverse shifted characters Wh...

Page 246: ... u 5 5 V V 6 6 w w 7 7 x x 8 8 y y 9 9 z z f f l l Î Î POKE 53265 PEEK 53265 OR 64 Unless you have changed the content of Background Color 2 you immediately notice that the blinking cursor is red rather than the current character color Returning tothenon extended color mode calls for clearing bit 6 to 0 POKE 53265 PEEK 53265 AND 191 You can determine the status of the extended color mode by PEEKin...

Page 247: ...re viously character background colors are taken from four different VIC registers The selection of registers depends on whether the ebar aeter is specified as shifted or non shifted and whether it is using the normal or reverse format Background Color 0 D021 53281 The four lower order bits in this register always hold the color code for the overall screen background When the extended color mode i...

Page 248: ...M has two registers devoted to the current cursor position BASIC S CHAR Statement The CHAR statement represents an especially powerful cursor and text control operation In its simplest form the statement looks like this CHAR co row where col is the desired column location and row is the desired row line location The upper left corner of the text window is located at column 0 row 0 Thus the followi...

Page 249: ...t printing or to 1 for inverse printing NOTE The optional invflg parameter in the CHAR state ment applies only to the string included in that statement Attempting to use the invflg feature without specifying a string parameter results in error conditions A final enhancement of the CHAR statement applies only when printing text on a multicolor bit map screen Assuming that multical ars 1 and 2 have ...

Page 250: ... CARRY FLAG COLUMN NUMBER TO REGISTER Y ROW NUMBER TO REGISTER X CALL PLOT Use this general procedure to return the current column and row location to registers Y and X respectively 1 Execute SEC to set the carry flag 2 Execute JSR FFFO to fetch the cursor location 4 Read the column number from register Y 5 Read the row number from register X For example SEC JSR SFFFO SET THE CARRY FLAG CALL PLOT ...

Page 251: ...e a CHAR 30 0 statement returns an ILLEGAL QUAN TITY error message Although you can work only within one custom text window at any given moment you can specify multiple text windows and work with them individually Setting Text Windows through BASIC s WINDOW Statement BASIC s WINDOW statement provides a convenient means for con figuring text windows from within BASIC programming The general form of...

Page 252: ... NEXT T 130 WINDOW 0 0 39 24 1 Setting Text Windows withESCape Codes The Commodore 128 uses a pair of ESCape key operations for setting the upper left and lower right bounds of custom text windows They are two step operations that require setting the text cursor to the desired corner upper leftor lower right then executing the appropri ate ESCape sequence The general procedure goes sarnething like...

Page 253: ...SIC Procedures ESCape operations can be executed from BASIC statements by PRINTing the ASCII equivalent of the ESC character foliowed by the character to be associated with ESC The ASCII code for the ESC key is decimal27 soanESC T operation looks like this PRINT CHR 27 T An ESC T operation sets the upper left corner of a custom win dow to the current cursor position so this statement does the job ...

Page 254: ... left cursor position by using the PLOT Kernal 3 Set the upper left window position by using the CBROUT Kernalto print ASCII 27 followed by the ASCIIforT equivalent of ESC T 4 Set the lower right cursor position by using the PLOT Kernal 5 Set the lower right window position by using the CBROUT Kernalto print ASCII 27 followed by the ASCII for B equivalent of ESC B LDA 93 JSR FFD2 LDX 04 LDY SOA CL...

Page 255: ...ters and you can set the window configuration by writing appropriate data to them WINDBOT A zero page register that contains the row number of the bottorn line of the cu rent text window i Decimal address 228 Hexadecimal addre ps E4 Default value 18 24 Allowable ranges of values 00 through 18 0 through 24 WINDTOP A zero page register that contains the row number of the top line of the current text...

Page 256: ...lumn 30 The PRINT CHR 147 statement homes the cursor within the newly defined text window and clears that area of the screen Listing 6 9 10 POKE 229 4 20 POKE 228 12 30 POKE 230 10 40 POKE 231 30 50 PRINT CHR 147 REM ROW 4 TO WINDTOP REM ROW 12 TO WINDBOT REM COL 10 TO WINDLEFT REM COL 30 TO WINDRIGT REM HOME AND CLEAR The default screen can be restored by POKEing the default val ues to the window...

Page 257: ...sor position delet ing or erasing selected portions of text and changing the text scrolling parameters The purpose of this section is to describe these features in the context of programming tools Cursor Motion Operations The cursor positioning procedures previously described in this chap ter use absolute column row addressing BASIC s CHAR statement for example sets the cursor to specified locatio...

Page 258: ...e Method 1 PRINT Method 2 PRINT CHR 13 Assembly routine LDA 00 JSR FDD2 UP Move the cursor up one line Leave the text unchanged Key operation Method 1 SHIFT CRSR up Method 2 up arrow key BASIC routine PRINT CHR 145 Assembly routine LDA 91 JSR FFD2 ADV Move the cursor right one column Leave the text unchanged Key operation Method 1 CRSR right Method 2 right arrow key Method 3 CONTROLI BASIC routine...

Page 259: ... is attempting to print text below the lowest line in the window causes the entire screen to shift upward one line The new material then appears on the bottorn line and what was the top line of text is no langer visible The text scrolling operations described in this section make it possible to change the normal automatic scrolling feature You can up or down serall the entire window and even disab...

Page 260: ...st Key operation ESC W BASIC routine PRINT CHR 27 CHR 87 Assembly routine LDA 1 B JSR SFFD2 LDA 57 JSR SFFD2 Text Erasing Operatioos The ability to delete one or more selected characters from the screen is not only a handy editing feature but also a powerful interactive text handling feature HOME CLR Set the cursor to the upper left corner of the current text window Clear all text from the window ...

Page 261: ...mbly routine LDA 1 B JSR FFD2 LDA 40 JSR FFD2 DCHAR Delete the character to the left of the current cursor col umn Move the cursor and all text to the end of the line one space to the left Key operation Method 1 DEL Method 2 CONTROLIT BASIC routine PRINT CHR 20 Assembly routine LDA 14 JSR FFD2 DLINE Delete the entire current line of text Set the cursor to the beginning of that line Serall alllower...

Page 262: ... characters that can be printed to the screen Two sets of characters are available one for the uppercase graphics mode and another for the uppercase low ercase mode Notice that some of the character locations do not repre sent actual characters but rather control functions A good many CHR and CHROUT fundions cited in this chapter take advantage of the code numbers associated with these control ope...

Page 263: ...8 12 set reverse 19 13 home 20 14 delete 21 i5 22 16 23 17 24 18 set clear tab stops 25 19 26 lA 27 1B ESCape 28 1C red 29 1D cursor right 30 1E green 31 1F blue 32 20 space 33 21 34 22 35 23 36 24 37 25 38 26 39 27 40 28 41 29 42 2A 43 2B 44 2C 45 2D 46 2E 47 2F 48 30 0 0 49 31 1 1 50 32 2 2 51 33 3 3 ...

Page 264: ... 6 6 55 37 7 7 56 38 8 8 57 39 9 9 58 3A 59 3B 60 3C 61 3D 62 3E 63 3F 64 40 65 41 A a 66 42 B b 67 43 c c 68 44 D d 69 45 E e 70 46 F f 71 47 G g 72 48 H h 73 49 I 74 4A J 75 4B K k 76 4C L 1 77 4D M m 78 4E N n 79 4F 0 0 80 50 p p 81 51 Q q 82 52 R r 83 53 s s 84 54 T t 85 55 u u 86 56 V V 87 57 w w ...

Page 265: ... f 93 SD l l 94 SE Î Î 9S SF 96 60 B B 97 61 A 98 62 DJ B 99 63 B c 100 64 EJ D 101 6S u E 102 66 g F 103 67 D G 104 68 H 10S 69 5J I 106 6A J 107 6B K 108 6C D L 109 6D LSJ M 110 6E 0 N 111 6F 0 0 112 70 D p 113 71 Q 114 72 D R 11S 73 s 116 74 D T 117 75 Ll u 118 76 V 119 77 c w 120 78 x 121 79 y 122 7A IJ z 123 7B EB EB ...

Page 266: ...rved for F7 137 89 reserved for F2 138 8A reserved for F4 139 8B reserved for F6 140 8C reserved for F8 141 8D SHIFT RETURN 142 8E set uppercase 143 8F flash off 80 col only 144 90 black 145 91 cursor up 146 92 reverse off 147 93 clear screen 148 94 insert 149 95 brown 40 col dark yellow 80 col 150 96 lightred 151 97 dark gray 40 col dark cyan 80 col 152 98 mediumgray 153 99 light green 154 9A lig...

Page 267: ...A4 D 11 165 A5 0 D 166 A6 11 D 167 A7 D D 168 A8 0 169 A9 f J R 170 AA 171 AB rn rn 172 AC c c 173 AD J J 174 AE 5J 6J 175 AF 176 BO ca ca 177 B1 Eg Eg 178 B2 Ea Ea 179 B3 BJ BJ 180 B4 D D 181 B5 182 B6 183 B7 u u 184 B8 185 B9 186 BA D 0 187 BB liL liL 188 BC 189 BD E J E J 190 BE 191 BF 192 CO El E3 193 C3 A 194 C4 DJ B 195 C3 8 c ...

Page 268: ...J I 202 CA CS J 203 CB K 204 CC 0 L 205 CD M 206 CE LZl N 207 CF D 0 208 DO D p 209 Dl Q 210 D2 D R 211 D3 s 212 D4 D T 213 D5 u 214 D6 V 215 D7 c w 216 D8 x 217 D9 Dl y 218 DA LIJ z 219 DB EE EE 220 DC IJ IJ 221 DD DJ DJ 222 DE ij t1l 223 DF 224 EO SHIFT space 225 El IJ IJ 226 E2 227 E3 D 0 228 E4 D 11 229 ES 0 0 230 E6 11 0 231 E7 D 0 ...

Page 269: ...f keyboard characters You may find helpful however substituting PRINT CHR n statements where nis the decimal code number for a character or control operation Writing the machine language versions of programs that print characters to the screen is not quite so easy The printing operation is quite simple The difficult part is specifying the characters to be printed The CHROUT Kernal routine at FFD2 ...

Page 270: ... in dexing operations to load the characters into register A The example in Listing 6 12 prints the HELLO string in that fashion Listing 6 12 FODOO 48 45 4C 4C 4F 00 HELLO NEXT END LOX 00 LDA SODOO X BEQ END JSR FFD2 INX BNE NEXT RTS SET INDEX TO ZERO FETCH A CHARACTER IF 00 THEN END ELSE PRINT IT INCREMENT THE INDEX AND FETCH NEXT The Kernal for the Commodore 128 includes a routine specific ally ...

Page 271: ...de number as signed to it one of decimal values 0 through 127 When the system is instructed to print an S character to the screen it searches the charac ter set for character number 19 and uses the bit mapped data at that place in ROM Fig 6 4 Character Dec Hex Uppercase Graphics Uppercase Lowercase set codes for ROM 0 00 based character 1 01 A sets a 2 02 B b 3 03 c c 4 04 D d 5 05 E e 6 06 F f 7 ...

Page 272: ...y y 26 lA z z 27 1B 28 1C f f 29 1D 1 1 30 1E t t 31 1F 32 20 space 33 21 34 22 35 23 36 24 37 25 o o o o 38 26 39 27 40 28 41 29 4Z ZA 43 ZB 44 2C 45 ZD 46 ZE 47 ZF 48 30 0 0 49 31 1 1 50 3Z z z 51 33 3 3 52 34 4 4 53 35 5 5 54 36 6 6 55 37 7 7 56 38 8 8 57 39 g g 58 3A 59 3B 60 3C ...

Page 273: ...66 42 IJ B 67 43 B c 68 44 EJ D 69 45 u E 70 46 g F 71 47 D G 72 48 H 73 49 EJ I 74 4A J 7S 4B K 76 4C D L 77 4D LSJ M 78 4E 0 N 79 4F D Q 80 50 D p 81 S1 Q 82 S2 D R 83 S3 s 84 54 D T 85 55 G3 u 86 56 V 87 S7 c w 88 58 x 89 59 Dl y 90 SA I z 91 SB EE EE 92 5C IJ IJ 93 SD DJ rn 94 5E ffB 95 5F lB 96 60 SHIFT space ...

Page 274: ...14 72 Ei3 Ei3 115 73 116 74 D D 117 75 IJ 118 76 119 77 u u 120 78 121 79 122 7A D 0 123 7B iJ iJ 124 7C 125 7D 126 7E 127 7F The second half of the character set uses the same characters in the same order but specifies them in the reverse format The codes for the reverse versions are equal to the normal versions plus 128 Thus the system searches for character number 38 when it is to print a norma...

Page 275: ...se the same character set but in different ways For all practical purposes the 40 column screen uses the characters directly as they are portrayed in Bank 14 ROM When invoking the 80 column mode the system copies that character set into a special 80 column RAM area where it is reformatted and used The master character set the one builtinto Bank 14 ROM is composed of 512 character definitions Each ...

Page 276: ...an be reached through techniques de scribed in the closing section of this chapter The 40 column character set is normally defined from Bank 14 ROM but it can be relocated and read directly from Bank 15 RAM The primary justification for reading the set is to provide a means for modify ing the characters or reorganizing the character settosuit special needs In principle a RAM based character set ca...

Page 277: ...ut of tbe area Because a RAM character set overlays the bit map RAM it is difficult to use tbe ebar aeters and bit mapped grapbics at tbe same time Two registers are involved in the procedure for defining a RAM based character set D9 217 and 0A2C 2604 Setting bit 2 of D9 instructs the system to use a RAM based character set Clear ing this bit to 0 restores the normal ROM based character functions ...

Page 278: ... POKE 8192 K C 60 NEXT K 70 SLOW 80 POKE 217 4 90 POKE 2604 PEEK 2604 AND 240 OR 8 The transfer requires several seconds but once it is done the system operales only from the normal uppercase lowercase character set Attempting to print other character sets yields garbage The character set is readily available for bit mapped modifica tions any sort of character you wish to design into the 8 bit for...

Page 279: ...een is rather tedious and indirect The Commodore 128 offers a selection of powerful text plotting routines that eliminate the need for writing characters directly to screen RAM However there are a couple of good reasans why you should consider writing directly Perhaps the best reason is that it offers insight into how and why the video system functions the way it does Furthermore having cammand of...

Page 280: ...743 18 06D0 06F7 1744 1783 19 06F8 071F 1784 1823 20 0720 0747 1824 1863 21 0748 076F 1864 1903 22 0770 0797 1904 1943 23 0798 07BF 1944 1983 24 07C0 07E7 1984 2023 The data to he written tothese RAM locations are the character set codes shown in Figure 6 4 Thus this cammand prints an at sign in the upper left corner of the screen POKE 1024 0 and this one prints the same character in the extreme l...

Page 281: ...ice The example in Listing 6 16 transfers all 1000 bytes of screen data to a different block of RAM which begins at 2000 8192 For the sake of demonstration the routines erase the original screen as the transfer takes place The routine ends by restoring the original screen from the blockat 2000 to the screen Line 10 Move BASIC up to 4000 Line 20 Clear the screen and home the cursor Line 30 Fill the...

Page 282: ...5296 Table 6 9 shows the starting and ending addresses for each line of text in color RAM Line Address Range Hex Dec 0 D800 D827 55296 55335 1 D828 D84F 55336 55375 2 D850 D877 55376 55415 3 D878 D89F 55416 55455 4 D8AO D8C7 55456 55495 5 D8C8 D8EF 55496 55535 6 D8FO D917 55536 55575 7 D918 D93F 55576 55615 8 D940 D967 55616 55655 9 D968 D98F 55656 55695 10 D990 D9B7 55696 55735 11 D9B8 D9DF 55736...

Page 283: ...024 2047 is re served for 40 column screen RAM You can however link the video display to a few other RAM locations The primary justification for such a procedure is to have a couple of text sereens hidden in the background and ready for immediate presentation You can for instance show one screen while preparing the text for a couple of others Then you can flip around through those alter native scr...

Page 284: ...g at 0400 on the other hand can heusedat any time because it is the system s default location for creen RAM The general procedure for displaying an alternative RAM loca tion looks like this 1 Determine the value to he written to the upper nibble of 0A2C 2 Fetch the current value of 0A2C 3 Set the four upper bits to the desired value 4 Write the result back to 0A2C The following BASIC statement mov...

Page 285: ...ired index value to the starting address of the block of screen RAM Line Address Range Hex Dec 0 0000 0027 0 39 1 0028 004F 40 79 2 0050 0077 80 119 3 0078 009F 120 159 4 00A0 00C7 160 199 5 00C8 00EF 200 239 6 00F0 0117 240 279 7 0118 013F 280 319 8 0140 0167 320 359 9 0168 018F 360 399 10 0190 01B7 400 439 11 01B8 01DF 440 479 12 01E0 0207 480 519 13 0208 022F 520 559 14 0230 0257 560 599 15 025...

Page 286: ... are 37 other registers but they are not directly accessible from any of the usual memory banks Rather they are accessed through those two special address locations The control register at D600 accepts register numbers Every 80 column chip operation begins by writing a particular register number to that address When the register is thus specified data can be written or read from the specified regi...

Page 287: ...umn Chip s ColorRAM 0 0800 084F 2048 2127 Showing Addresses 1 0850 089F 2128 2207 of First and Last 2 08AO 08EF 2208 2287 3 08FO 093F 2288 2367 Columns in Each 4 0940 098f 2368 2447 Row 5 0990 09DF 2448 2527 6 09EO 0A2F 2528 2607 7 0A30 0A7F 2608 2687 8 0A80 0ACF 2688 2767 9 0AD0 0B1F 2768 2847 10 0B20 0B6F 2848 2927 11 0B70 0BBF 2928 3007 12 0BCO 0COF 3008 3087 13 0C10 0C5F 3088 3167 14 0C60 0CAF...

Page 288: ...cter at the beginning of the sec ond line of the 80 colurnn screen eharaeter code 18 at address 0050 LDA 12 REGISTER 12 STA D600 TO THE CONTROL REGISTER LDA 00 MSB OF ADDRESS STA D601 TO DATA REGISTER LDA 13 REGISTER 13 STA D600 TO THE CONTROL REGISTER LDA 50 LSB OF ADDRESS STA D601 TO DATA REGISTER LDA 1F REGISTER 1 F STA D600 TO THE CONTROL REGISTER LDA 18 X CODE STA D601 TO DATA REGISTER This a...

Page 289: ...ET FOD23 RTS LDA 18 X CHARACTER LDX 00 MSB OF SCREEN ADDR LDY 50 LSB OF SCREEN ADDR JSR SODOO PLOT IT LDA 02 BLUE COLOR LDX 08 MSB OF COLOR ADDR LDY 50 LSB OF COLOR ADDR JSR SODOO SET THE COLOR calls an initialization routine that copies the 40 column character set into the appropriate blockin the 80 column chip NOTE The 80 column character set is not available until the 80 column mode is initiali...

Page 290: ...7 Bit Mapped Graphics Procedures ...

Page 291: ...ion or bit mapped graphics for the Commodore 128 fea ture two different kinds of screens One screen called the standard screen allows you to plot text and figures from two different color sources foreground and background The second the multicolor screen provides a choice of four different color sources foreground background multicolor 1 and multicolor 2 In either screen the colars assigned to the...

Page 292: ... only through BASIC s CHAR statement Prompt ing message that might be associated with INPUT statements for example can be printed only in the text portion of a split screen 0 I rn z 0 0 9 0 w a IE I t 1J 20 24 0 319 BIT MAP HORIZONTAL LOCATIONS TEXT LINES STANDARD BIT MAP GRAPHICS 40 COLUMN TEXT 0 TEXT COLUMNS 39 The color sourees of particular interest to the standard bit mapped sereens include t...

Page 293: ...ed in the 40 column text portion of the split screen Figures 7 3 and 7 4 show the layout of full and split screen ver sions for two multicolor screens In both instances the 160 horizontal locations are labelect 0 through 159 The full screen version uses ZOO verticallocations whereas the split screen version uses just 160 0 MULTICOLOR HORIZONTAL LOCATIONS 159 0 I Cl z 0 9 i w 0 0 0 IE J0 159 0 MULT...

Page 294: ...n 0 and 5 that indicates the desired screen format Table 7 1 summarizes these values and their meanings mat 0 1 2 3 4 5 Screen Format 40 column text Standard full screen bit mapped graphics Standard split screen bit mapped graphics Multicolor full screen bit mapped graphics Multicolor split screen bit mapped graphics 80 column text Setting up the standard split screen format is a matter of execut ...

Page 295: ...he Graphics Colors with BASIC s COLOR Stdtement BASIC s graphics dtawing operations always use colors previously assigned to sets of color sources All the grapbics sereens have color sourees set asitle for the border background and foreground colors for example You can assign any combination of colors to these sources but ybu must bear in mind that the BASIC GRAPHICs state ments described in this ...

Page 296: ...Gray The configuration of the standard 40 column character set lines up perfectly with the organization of the standard bit mapped screens The standard text and graphics characters thus can be plotted in the graphics area of the standard screens The platting statement for that sort of task has this general form CHAR srce col row string The srce term specifies the desired color source The only sour...

Page 297: ...C 1 1 50 CHAR 1 17 12 HELL0 60 GETKEY K 70 COLOR 0 12 80 COLOR 4 14 90 GRAPHIC 0 1 100 LIST The CHAR statement can be extended to include a term that reverses the color format of the string CHAR srce col row string invflg This statement normally prints the string such that the charac ters appear in the foreground color against a field fixed by the current background color This is also the case whe...

Page 298: ...d in Figures 7 1 through 7 4 NOTE The LOCATE statement fixes the position of the pixel cursor This statement does nat plot anything to the screen The x and y terms in the LOCATE statement also can be ex pressed as absolute or relative terms Absolute terms indicate the actu al screen locations and are specified by using unsigned integer values Using relative terms makes it possible to reLOCATE the ...

Page 299: ...tion of the pixel cursor That posi tion can be determined at any time by means of the RDOT fundion where RDOl O returns the horizontal component of the current pixel cursor location RD0l 1 returns the vertical component of the current pixel cursor location PloHing Points and Straight Lines The DRAW statement is the most flexible of all graphics plotting statements It can be used for platting indiv...

Page 300: ... the coordinate For example DRAW 120 40 The example uses the most recently specified color souree to plot a point at absolute coordinate 120 40 If you omitted the leadihg comma BASIC would attemp 1 to interpret 120 as a color souree and ultimately return an ILLEGAL QUANTITY error Because the DRAW stateinent can be used for plotting a point of color at any location on the graphics screen you can fi...

Page 301: ...280 150 TO 130 150 TO 160 50 HINT Use souree 0 background color to delete a figure from the screen First DRAW it from an appropriate color source then when you are ready to delete it DRAW it again from the background color source The DRAW statement supports relative coordinate components as well as absolute coordinates See the discussion of this topic for the LOCATE statement Bear in mind however ...

Page 302: ...t In this instance the corner is fixed at the pixel cursor location in effect prior to executing the statement Consider the following routine 10 BOX 1 100 100 120 120 20 BOX 10 10 Line 10 in this example uses the color assigned to the fore ground souree to plot a box having its upper left corner at 100 100 and the lower right at 120 120 Bearing in mihd that the pixel cursor is left at the lower ri...

Page 303: ...must use the same number of commas For instance BOX 1 0 1 0 50 50 1 This example uses the last used souree of color and fills the specified boxwithno rotation effect Using The CIRCLE Statement Whereas the BOX statement plots simple rectangles the CIRCLE statement can be used for plotting just about anything else As its name implies it can plot circles but it also plots ellipses arcs and even regul...

Page 304: ...on does the job on a multicolor screen CIRCLE 1 100 100 20 30 NOTE When yr is not specified the system assigns it a value that is equal to xr The CIRCLE statement as described thus far generates ellipses including circles when the ratios of xr and yr are properly adjusted The next extension of the statement makes possible the limitation of the drawing to arcs portions of the ellipse The general id...

Page 305: ... direction you must specify a clockwise rotation of 360 ANG where ANG is the de sired amount of angular rotation in the counterclockwise direction The final extension of the CIRCLE cammand specifies the num ber of degrees between successive points plotled on the ellipse The default value is two degrees Specifying a lesser number of degrees between points doesn t change the appearance very much and...

Page 306: ... is PAINT srce x y where srce is the color souree for the PAINT color and x y is the coor dinate of any point within the figure to be filled The following routine plots an ellipse and fills it with the same color 10 COLOR 0 2 COLOR 1 8 20 GRAPHIC 2 1 30 CIRCLE 1 200 100 50 40 PAINT 200 100 Line 10 Set background to white and foreground to yellow Line 20 Set the standard split screen Line 30 Plot a...

Page 307: ...does not change the number of points that can be plotted It simply shrinks or stretches the measuring stick The general form of the SCALE statement is SCALE sflg xmax ymax The sflg term turns the sealing operation on or off Settingit to 0 turns off the sealing effectandrestores the normal 320 x 200 and 160 x 200 screens In that case the remaining terms arenotrelevant and can be omitted Thus turnin...

Page 308: ...e in instauces where you want to plot the figure a number of different times The procedures described here do not eliminate the need for platting a figure in the usual fashion one time Once it is plotted though you can make a copy that can be duplicated any number of times at a much more rapid rate Two BASIC statements are involved in the procedure SSHAPE and GSHAPE Assuming that you have plotted ...

Page 309: ...f the rectangular area that can he assigned to a string Two equations are available for determining the number of bytes in an SSHAPE field The choice depends on whether the fig ure is taken from a standard bit map screen or a multicolor screen For a standard bit mapped screen L INT ABS xl xZ l 4 99 ABS yl y2 1 4 And for a multicolor screen L INT ABS xl xZ l 8 99 ABS yl y2 1 4 In bath instances L n...

Page 310: ...he upper left corner of the screen Line 40 Use SSHAPE to assign that figure to F Line 50 Use GSHAPE to copy the figure toa different place on the screen its upper left corner at coordinate 100 100 The GSHAPE statement can be extended to include a mode term GSHAPE strvar x y mode where mode is an integer value between 0 and 4 Mode 0 is the default mode It is the one used when the mode term is omitt...

Page 311: ...rs who might want to write hybrid programs those using combinations of BASIC and ma chine language routines Allocating RAM for Bit Mapped Graphics System initialization routines set 1COO asthestarting address for BASIC operations Unfortunately this is also the starting address for two blocks of RAM set aside for bit mapped graphics color and screen RAM If you have any intention of using bit mapped...

Page 312: ...values to that register sets the desired screen mode and reading the content of the register returns a value that indicates the current screen mode GRAPHIC register Address 08 216 Data 00 0 40 column text 20 32 Standard full bit mapped screen 60 96 Standard split bit mapped screen AO 160 Multicolor full bit mapped screen EO 224 Multicolor split bit mapped screen Thus setting the equivalent of the ...

Page 313: ... STA FA Y INV BNE NEXT1 INC SFB LDA 20 CMP SFB BNE NEXT2 STA SFB NEXT4 LDA 00 TAY NEXT3 STA SFA Y INV BNE NEXT3 INC SFB LDA 40 CMP SFB BNE NEXT4 RTS GET CURRENT BKGND COLOR MASK LOWER NIBBLE INITIALIZE POINTER SETCOLOR INCREMENT THE POINTER IF NOT END OF PAGE THEN AGAIN INCR MSB OF BASE ADDRESS IS IT DONE IF NOT DO NEXT PAGE MSB OF SCREEN BASE ADDR ZERO TO CLEAR SCREEN INITIALIZE POINTER CLEAR THE...

Page 314: ...ough 3FFF 8192 16383 Figure 7 1 shows that the screen is organized into 320 horizontal and 200 vertical locations This fig ures out to be 64 000 different locations Being able to access one of 64 000 locations within an 8 000 byte block of RAM obviously calls for some understanding of how all those locations are organized within a relatively small amount of address space One important clue to how ...

Page 315: ... to bottom fashion The following example sets and clears the standard split version of the bit mapped screen then draws a thin straight line along the sec oud graphics line on the screen It is tantamount to executing BASIC s DRAW O l TO 319 1 It actually turns on all eight bits in the secoud byte in all of the fields along the top of the screen 10 GRAPHIC 2 1 20 FOR K O TO 8 39 STEP 8 30 POKE 8193...

Page 316: ... ON FOREGROUND 1 SCREEN DOT PER BIT If you are planningtoplot a dot at bit map coordinate 120 42 COL INT 120 8 15 ROW INT 42 8 5 The dot will he somewhere in the field located at column 15 row 5 The next step is to determine the byte within the field is found by this sort of relation BYTE Y AND7 The example cites Y 42 BYTE 42AND 7 2 It is now established that the point is located somewhere within ...

Page 317: ... these two statements do the same job DRAW 120 42 POKE 9914 128 Consictering all the calculations required for determining the POKE address you can understand why most programroers let the computer do the work usually as a subroutine All the calculations for determining the bit mapped screen address come down to this ADDR 8192 8 INT X 8 320 INT Y 8 Y AND 7 where X and Y represent the coordinate of...

Page 318: ...5871 3CC0 3DFF 24 15872 16191 3EOO 3F3F Column base address Line start address 8 column number determine the on off pattem of dots when a 0 bit turns the point off and a 1 bit turns it on The screen RAM contains no information re garding the colors of the dots That is the job of the bit map color RAM One might suppose that the color RAM for the standard bit map screen would be the same size as the...

Page 319: ...same foreground and background col ars as specified by the corresponding colar RAM location Colars can be different from one screen field to another but no more than two different colars can be in a given field the background and fore ground colors Bit map color RAM accupies the blockof memory from 1COO through 1FE7 7168 8167 Figure 7 6 shows the general column row layout with regard to screen fie...

Page 320: ...1 8008 8047 1F48 1F6F 22 8048 8087 1F70 1F97 23 8088 8127 1F98 1FBF 24 8128 8167 1FCO 1FE7 Each byte in standard bit map color RAM is divided into two equal nibbles As indicated in Figure 7 7 the four higher order bytes determine the foreground color and the four lower order bytes fix the background color Table 7 5 shows the values associated with each color that can he assigned to nihbles of colo...

Page 321: ... Screen The multicolor bit map screen uses the same blocks of screen and color RAM as does the standard graphics screen However the multi color bit map mode works in an entirely different fashion Reeall that the standard bit map screen uses just two color sources foreground and background Thus you can specify the desired color souree with a single bit When the bit is set to 0 the sys tem plots the...

Page 322: ... is no different from the standard bit mapped screen as shown in Figure 7 5 0 39 COLUMN o r 24 1000 SCREEN FIELDS BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7 8 BYTES PER FIELD 8 rs PER 8YT I 00 BACKGROUND 01 FOREGROUND 10 MULTICOLOR 1 1 SCREEN DOT PER 2 BITS The difference is in the way the bits are mapped to the screen The standard bit mapped screen plots one pixel for each bit The mu...

Page 323: ...figure 0 1 2 I 3 4 5 6 7 7 6 B F F F F F F B Listing 7 5 LDA SOE STA D8 LDA OB STA D021 LDA 16 STA 1COO STA 141 STA 2000 STA 2007 LDA 55 STA 2001 STA 2006 LDA 69 STA 2003 STA 2004 STA 2005 5 4 F F M1 M1 M1 M1 M1 F 3 2 F F M1 M1 M1 M1 M1 F 1 B F F F F F F B 0 0 2 I 3 i 4 5 6 7 6 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 B BACKGROUND COLOR 00 F FOREGROUND COLOR 01 M1 MULTICOLOR 1 10 SPECIFY GRAPHIC 4 SET THE ...

Page 324: ...8 Sprite Animation Procedures ...

Page 325: ...prite definition tables An alternative sprite generating technique takes advantage of BASIC s bit map drawing procedures described in the previous chap ter The technique begins with the application of statements such as LOCATE DRAW BOX CIRCLE and PAINT to develop the desired image within an area that is 24 pixels wide and 21 tall The next step is to use the shape saving command SSHAPE to assign th...

Page 326: ...is most important is knowing how to set up the SPRDEF mode plot a figure and save it as a sprite The previous paragraphs outline the procedures for setting up the SPRDEF mode and platting a figure The figure that you develop with SPRDEF is nat actually entered into the system as a legitimate sprite until you do an unusual key operation SHIFT RETURN hold down one of the SHIFT keys and press RETURN ...

Page 327: ...F6 key Set the cursor to the beginning of the next line SHIFT RETURN Transfer the figure to the sprite definition area and prepare to define another sprite SHIFT RETURN foliowed by RETURN Transfer the figure to the sprite definition area and return to BASIC RUN STOP followed by RETURN Abort the operation andreturn to the BASIC interpreter A sprite generated by SPRDEF carries your specified color s...

Page 328: ... as a sprite Listing 8 1 10 GRAPHIC 2 1 20 CIRCLE 1 10 10 10 8 30 PAINT 1 10 10 40 SSHAPE F 0 0 20 20 50 SPRSAV F 1 60 GRAPHIC 0 1 The overall procedure can also be used in conjunction with the SPRDEF routine You can for example use the usual bit map draw ing procedures to generate larger portions of a figure define it as a sprite then use the SPRDEF routine to add the finishing touches Using the ...

Page 329: ... toredefine it as sprite 2 this statement does the job SPRSAV F 2 Once this statement is executed the figure originally generated as F is not ready for use as sprite 2 Conversely a sprite can be redefinedas a string that then can be used with GSHAPE statements to plot it anywhere on the screen as a bit mapped figure The general form of the conversion statement is SPRSAV num string where num is the...

Page 330: ... future use is a simple matter of BSAVEing the block of RAM that is set aside for them And recalling them again from disk is just as simple BLOAD them according to the file narnes originally assigned to them The following example loads a set of sprites originally savedas GAME10 BLOAD GAME10 Once you have thus loaded some sprite definitions either di rectly from the keyboard or through some BASIC p...

Page 331: ... front of other objects 1 Sprite moves behind other objects xexp Horizontal ZX expansion on off 0 Normal horizontal dimension 1 ZX expansion in horizontal dirneusion yexp Vertical2X expansion on off 0 Normal vertical dimension 1 ZX expansion in vertical dimension mode Screen mode flag 0 standard sprite 2 multicolor sprite The first term num specifies the sprite being defined by the remainder of th...

Page 332: ...n the same screen area That is the purpose of the pri priority term in the SPRITE statement If you want the current sprite the one you are defining with the SPRITE statement to move in front of other objects on the screen set the pri term to 0 Set it to 1 and the sprite moves behind other objects Sprites can be expanded to twice their normal dimensions You have the choice of expanding them in the ...

Page 333: ... text and graphics information on the Commodore 128 Therefore you should not be surprised that sprites use their own screen format Figure 8 1 shows the organization of the sprite screen The 512 horizontal loca tions are labeled 0 through 511 and the 256 vertical locations are labeled 0 through 255 0 0 250 255 0 24 24 50 24 250 344 511 344 50 SPRITES VISIBLE ONLY IN THIS AREA 344 255 Unlike any of ...

Page 334: ... MOVSPR num dist ang where num is the sprite number dist is the distance to he moved and ang is the angle The angle is conveniently expressed in degrees 0 through 360 and positive angles refer to a clockwise direction Finally you can set a sprite into continuous motion with a sin gle MOVSPR statement That form of the statement looks like this MOVSPR num ang speed where num is the sprite number ang...

Page 335: ... and move it 0 degrees with a speed of 1 Line 160 Set sprite 7 at 300 100 and move it 180 degrees with a speed of 10 Line 170 Set sprite 8 into motion at 80 degrees with a speed of 10 Listing 8 2 10 GRAPHIC 2 1 20 CIRCLE 1 10 10 10 8 30 PAINT 1 10 10 40 SSHAPE F 0 0 20 20 50 SPRSAV F 1 60 GRAPHIC 0 1 70 FOR K 2 TO 8 SPRSAV 1 K NEXT 80 FOR K 1 TO 8 SPRITE K 1 K 1 1 0 0 0 NEXT 90 MOVSPR 1 0 60 MOVSP...

Page 336: ...or a mecha nism that detects contact between two or more objects on the screen Commodore s BASIC 7 0 deals with sprite contact situations withapair of statements COLLISION and BUMP Generally speak ing both respond to a contact between sprites or between sprites and other objects on the screen The statements respond in different ways though and they are thus used in different ways Using the COLLISI...

Page 337: ...eature the sort of action put into effect by MOVSPR num ang speed The problem is that the VIC chip has full control of sprite motion in that case and because it operates so much faster than the BASIC interpreter COLLISION cannot do its job until some time after the actualcollision occurs aften too late to be of any use Thus the COLLISION statement is most effective when you are rnav ing sprites on...

Page 338: ...int OUCH if sprite 3 runs into another kind of object while other sprites are not in a contact situation If you are acquainted with binary to decimal number conver sions you can understand easily the values returned by the BUMP functions Regarding the value returned by BUMP as an eight bit binary number A sprite l callision sets bit 0 A sprite 2 callision sets bit 1 A sprite 3 callision sets bit 2...

Page 339: ...1 1 15 OF 0 0 0 1 0 0 0 0 16 10 0 0 0 1 0 0 0 11 17 11 0 0 0 1 0 0 1 0 18 12 0 0 0 1 0 0 1 1 19 13 I 0 0 0 1 0 1 0 0 20 14 0 0 0 1 0 1 0 1 21 15 0 0 0 1 0 1 1 0 22 16 0 0 0 1 0 1 1 1 23 17 0 0 0 1 1 0 0 0 24 18 0 0 0 1 1 0 0 1 25 19 0 0 0 1 1 0 1 0 26 1A 0 0 0 1 1 0 1 1 27 1B 0 0 0 1 1 1 0 0 28 1C 0 0 0 1 1 1 0 1 29 1D 0 0 0 1 1 1 1 0 30 1E 0 0 0 1 1 1 1 1 31 1F 0 0 1 0 0 0 0 0 32 20 0 0 1 0 0 0 0...

Page 340: ... 0 1 0 0 0 1 1 0 70 46 0 1 0 0 0 1 1 1 71 47 0 1 0 0 1 0 0 0 72 48 0 1 0 0 1 0 0 1 73 49 0 1 0 0 1 0 1 0 74 4A 0 1 0 0 1 0 1 1 75 4B 0 1 0 0 1 1 0 0 76 4C 0 1 0 0 1 1 0 1 77 4D 0 1 0 0 1 1 1 0 78 4E 0 1 0 0 1 1 1 1 79 4F 0 1 0 1 0 0 0 0 80 50 0 1 0 1 0 0 0 1 81 51 0 1 0 1 0 0 1 0 82 52 0 1 0 1 0 0 1 1 83 53 0 1 0 1 0 1 0 0 84 54 0 1 0 1 0 1 0 1 85 55 0 1 0 1 0 1 1 0 86 56 0 1 0 1 0 1 1 1 87 57 0 1...

Page 341: ...1 1 0 0 1 121 79 0 1 1 1 1 0 1 0 122 7A 0 1 1 1 1 0 1 1 123 7B 0 1 1 1 1 1 0 0 124 7C 0 1 1 1 1 1 0 1 125 7D 0 1 1 1 1 1 1 0 126 7E 0 1 1 1 1 1 1 1 127 7F 1 0 0 0 0 0 0 0 128 80 1 0 0 0 0 0 0 1 129 81 1 0 0 0 0 0 1 0 130 82 1 0 0 0 0 0 1 1 131 83 1 0 0 0 0 1 0 0 132 84 i 0 0 0 0 1 0 1 133 85 1 0 0 0 0 1 1 0 134 86 1 0 0 0 0 1 1 1 135 87 1 0 0 0 1 0 0 0 136 88 1 0 0 0 1 0 0 1 137 89 1 0 0 0 1 0 1 0...

Page 342: ...1 0 1 1 0 0 172 AC 1 0 1 0 1 1 0 1 173 AD 1 0 1 0 1 1 1 0 174 AE 1 0 1 0 1 1 1 1 175 AF 1 0 1 1 0 0 0 0 176 BO 1 0 1 1 0 0 0 1 177 B1 1 0 1 1 0 0 1 0 178 B2 1 0 1 1 0 0 1 1 179 B3 1 0 1 1 0 1 0 0 180 B4 1 0 1 1 0 1 0 1 181 B5 1 0 1 1 0 1 1 0 182 B6 1 0 1 1 0 1 1 1 183 B7 1 0 1 1 1 0 0 0 184 B8 1 0 1 1 1 0 0 1 185 B9 1 0 1 1 1 0 1 0 186 BA 1 0 1 1 1 0 1 1 187 BB 1 0 1 1 1 1 0 0 188 BC 1 0 1 1 1 1 0...

Page 343: ...23 DF 1 1 1 0 0 0 0 0 224 EO 1 1 1 0 0 0 0 1 225 El 1 1 1 0 0 0 1 0 226 E2 1 1 1 0 0 0 1 1 227 E3 1 1 1 0 0 1 0 0 228 E4 1 1 1 0 0 1 0 1 229 E5 1 1 1 0 0 1 1 0 230 E6 1 1 1 0 0 1 1 1 231 E7 1 1 1 0 1 0 0 0 232 E8 1 1 1 0 1 0 0 1 233 E9 1 1 1 0 1 0 1 0 234 EA 1 1 1 0 1 0 1 1 235 EB 1 1 1 0 1 1 0 0 236 EC 1 1 1 0 1 1 0 1 237 ED 1 1 1 0 1 1 1 0 238 EE 1 1 1 0 1 1 1 1 239 EF 1 1 1 1 0 0 0 0 240 FO 1 1...

Page 344: ...find the operations rather straightforward Enabling and Disabling Sprites Any combination of sprites can be enabled and disabled at a single address location D015 53269 Eight different sprites and eight bits in the byte of data are at that address one bit for each sprite Sprite Enable Writing to this register enables disables the sprite display mode Reading from the register returns a value that i...

Page 345: ...reground colars for the eight individual sprites are in the four lower order bytes of a set of VIC registers D027 through D02E Sprite Foreground Colors Writing color values 00 through OF 0 15 tothese registers sets the foreground color for the correspond ing sprites Reading four lower order bits of data from the registers returns the foreground color value 0027 53287 Sprite 1 foreground color 0028...

Page 346: ... and 00 restores all sprites to the standard color mode Sprite Multicolor Enable Writing to this register enables disables the sprite multicolor mode Reading from the register returns a value that indicates the sprite multicolor status Address 001C 53276 Data 0 Disable multicolor mode 1 Enable multicolor mode Bit 0 Sprite 1 Bit 1 Sprite 2 Bit 2 Sprite 3 Bit 3 Sprite 4 Bit 4 Sprite 5 Bit 5 Sprite 6...

Page 347: ...LTICOLOR 1 YELLOW COLOR TO MULTICOLOR 2 Setting Sprite Priorities Sprite priority flags 0 or 1 determine whether a given sprite moves behind or in front of other graphics figures on the screen The flag for each sprite is contained in a single data byte located at address D01B Clearing a bit to 0 causes the corresponding sprite to move in front of other kinds of objects on the screen whereas settin...

Page 348: ...m the registers returns values that indicate the current expansion status Addresses Horizontal expansion 0010 53277 Vertical expansion 0017 53271 Data 0 Normal dirneusion 1 2X expansion Bit 0 Sprite 1 Bit 1 Sprite 2 Bit 2 Sprite 3 Bit 3 Sprite 4 Bit 4 Sprite 5 Bit 5 Sprite 6 Bit 6 Sprite 7 Bit 7 Sprite 8 The portion of a machine language routine shown in Listing 8 5 sets sprite 1 for ZX expansion ...

Page 349: ... for each sprite Finally a single eight bit register handles the high order horizontal position bit for each of the sprites A sprite s position on the screen is determined by the value in its vertical position register 00 FF the value in its own horizontal position register 00 FF plus a single bit in the special high order horizontal position register binary 0 or 1 Table 8 5 summarizes the positio...

Page 350: ...O 0 SET X HIGH BIT TO 0 SPECIFY X POS SOA SET LSB OF X POS FOR SPRITE 1 SPECIFY V POS 0 SET V POS OF SPRITE 1 KILL SOME TIME MOVE SPRITE 1 UP AND REPEAT The program runs in an endless loop so you should end it by doing a RUN STOP RESTORE operation Moving sprites horizontally is just a bit trickier because you have to work with the appropriate 9th bit in 11E6 The general idea is to in crement or de...

Page 351: ...ADC 02 0012 STA 1106 0015 BCC 001 F 0017 LDA 11E6 OD1A EOR 01 OD1C STA 11 E6 001 FJMP FA65 SET INTERRUPT DISABLE LSB OF NEW IRQ TO IRQ VECTOR MSB OF NEW IRQ TO IRQ VECTOR CLEAR INTERRUPT DISABLE GET LSB OF SPRITE 1 X POS CLEAR THE CARRY FLAG ADD DISPLACEMENT SET NEW LSB OF SPRITE 1 XPOS IF NO CARRY THEN BRANCH TO END GET 9TH BIT FOR ALL SPRITES SWITCH BIT FOR SPRITE 1 SET NEW 9TH BIT JUMP TO NORMA...

Page 352: ... is that the latter does nat automatically clear the content to zero BUMP Registers Reading data from these registers indicates the callision status of sprites and other objects on the screen The format is the same as indicated in Table 8 3 Addresses 001E 53278 Sprite to sprite collisions 001 F 53279 Sprite to text graphic collisions Unfortunately for the casual programmer the VIC chip updates the...

Page 353: ......

Page 354: ...9 Sound and Music Procedures ...

Page 355: ...evel specification it is a vital quality of sound synthe sis and SID operations are meaningless without it The amplitude volume or loudness of sounds is normally measured in units of beis or more commonly decibels The SID chip does not recognize those units of measurement however It operates on the basis of simple integer values the larger the value the louder the sound In most instances a volume ...

Page 356: ... determines the time required for diminishing the amplitude from the sustain level to zero You can choose from the four different kinds of sound wave forms illustrated in Figure 9 2 The sawtooth waveform produces the purest tone The sawtooth waveform has araspier quality but tends to be more forceful The pulse waveform is a compromise between the triangular and sawtooth sounds apd the system inclu...

Page 357: ...350 Commodore 128 Fig 9 2 The four kinds of waveforms avoilobie from SID LLI c 1 c 1 5 c 1 i TIME A Triangle wave orm TIME BJ Sawtooth waveform TIME C Variabie pulse waveform TIME Dj Noise wave orm ...

Page 358: ...ilters B High pass filter CUTOFF FREQUENCY CUTOFF FREQUENCY When using the filtering feature remember that your system s audio a mplifier and loudspeaker most likely reproduce higher fre quenci better than lower ones The system has an inherent high pass quality Using BASIC S 1 0L and SOUND Statements BASIC s VOL and SOUND statements are tools for producing the most elementary sorts of sounds and m...

Page 359: ... are defined as voice voice channel to be used 1 through 3 freq numeric value representing desired frequency 0 through 65535 dur duration of sound 0 through 32767 Table 9 1 shows some values for the req parameter as they apply to notes on a 12 octave musical scale In practice req values less than 128 sound more like clicking sounds than musical notes Octave Note freq Value Octave Note freq Value 0...

Page 360: ...3 9 F 13015 5 G 968 9 F 13790 5 A 1025 9 G 14612 5 A 1086 9 G 15480 5 B 1151 9 A 16396 9 A 17372 6 c 1219 9 B 18408 6 C 1291 6 D 1368 10 c 19508 6 D 1450 10 C 20658 6 E 1537 10 D 21894 6 F 1627 10 D 23200 6 F 1724 10 E 24584 6 G 1827 10 F 26030 6 G 1935 10 F 27580 6 A 2050 10 G 29224 6 A 2172 10 G 30960 6 B 2301 10 A 32792 10 A 34744 7 c 2439 10 B 36816 7 C 2582 7 D 2737 11 c 39016 7 D 2900 11 C 4...

Page 361: ... final line in the program silences all three voices at the same time by setting their SOUND parameters to 0 Listing 9 1 10 VOL 4 20 SOUND 1 4877 280 30 FOR T 1 TO 250 NEXT T 40 SOUND 2 6146 280 50 FOR T 1 TO 250 NEXT T 60 SOUND 3 7306 280 70 FOR T 1 TO SOO NEXT T 80 FOR K 1 TO 3 SOUND K O O NEXT K NOTE Use the SOUND statementtoturn off sounds Turn ing sounds on and off with the VOL statement ofte...

Page 362: ...000 in steps of 200 SOUND 1 4000 240 2 3000 200 Another parameter provides the opportunity to select the wave farm of the sound SOUND voice freq dur dir fmin sstep wfrm where wfrm is an integer between 0 and 3 that indicates the wave farm to be used 0 triangle 1 sawtooth 2 variabie pulse 3 noise The default value of wfrm is 0 the triangular waveform Setting it to 1 changes the wavefarmtoa sawtooth...

Page 363: ...ammers who want to play musical compositions A programmer who knows how to read musical scores and understands a bit about BASIC s musical statements can program virtually any composition into the system The only real campromise is that the Commodore 128 can handle only three voices at one time The general form of the PLAY statement is quite simple PLAY string where string is a string constant var...

Page 364: ...le 10 A 01 C CD SE EF F G SA A SB 8 20 PLAY A The followirtg example plays the entire chromatic scale for the system Notice you can work with the PLAY strings to extend the basic musical effects 10 A C CD E EF F G A A BB 20 FOR K O TO 6 30 B 0 STR K 40 PLAY BS AS 50 NEXT K Selecting the Duration of Notes end Rests The duration of a given note can he specified as whole W half H quarter Q eighth 1 s...

Page 365: ... quality where nis an integer between 0 and 9 inclusively Unless you change the tone envelopes as described subsequently the Tn code produces tones that sound much like the instruments shown here TO Piano T1 Accordion T2 Calliope T3 Drum T4 Flute TS Guitar T6 Harpsichord T7 Organ T8 Trumpet T9 Xylophone The next example illustrates a drum selection that uses the U term to achieve soi ne accent eff...

Page 366: ...point where it is not noticeable The timing problem becomes more apparent when using PLAY strings within program loops within FOR NEXT loops for exam ple The example in Listing 9 2 illustrates the problem Line 10 Set the tempo Line 20 Define piano sounds for all three voices Line 30 Define the first measure Line 40 Define the second measure Line 50 Play the first measure three times in succession ...

Page 367: ...Period dotted note R Rest M Wait for all voices to catch up Xn Filter control n 0 for Off n 1 for On Using the Envelope Statement The Tn code in a PLAY statement specifies which one of ten sounds is to be used for a given musical scenario The eliaraeter of those tones is fixed in terms of attack and decay intervals sustain volume level release interval waveform shape and if variabie pulses are use...

Page 368: ...ns to the ten envelopes Envelope Parameters Sound n atk dey sus rel wfrm pw 0 0 9 0 0 2 1536 Piano 1 12 0 12 0 1 Accordion 2 0 0 15 0 0 Calliope 3 0 5 5 0 3 Drum 4 9 4 4 0 0 Flute 5 0 9 2 1 1 Guitar 6 0 9 9 0 2 512 Harpsichord 7 0 9 9 0 2 2048 Organ 8 8 9 4 1 2 512 Trumpet 9 0 9 0 0 0 Xylophone When you select the pulse waveform you must also specify a value that represents the percent of time the...

Page 369: ... or ends The larger the value the higher the cutoff frequency The next three terms in the FILTER statement lof bpf and hpf determine which one of the filtering effects are applied The val ues to be assigned are either 0 or 1 Combinations of more than one selected filter produce the corresponding filtering effects The rel term fixes the sharpness of the filtering effect The larger the value the sha...

Page 370: ...ed of the four higher order bits bits 4 through 7 and the lower order nibble is defined in terros of the four lower order bits bits 0 through 3 Setting Frequencies Each of the three voices uses pairs of registers for setting the desired frequency LSB foliowed by MSB The larger the values written to those registers the higher the frequency Voice 1 frequency 0400 and 0401 54272 and 54273 Voice 2 fre...

Page 371: ... It is assembied in the attackldecay register this way 19 attack nibble foliowed by the decay nibble Setting Sustain Level and Release Interval Each voice uses a single register for setting the sustain volume level and release level In each case the upper nibble sets the sustain level and the lower nibble sets the release interval Voice 1 Sustain Release 0406 54278 Voice 2 Sustain Release 0400 542...

Page 372: ...d routines The sequence is based on a few important facts First a chance always exists that a previous SID pro gram has left some of the registers set in unwanted states so begin a routine in some fashion that ensures no leftover settings are in effect Second changing the overall volume level at D418 often causes a popping sound if any of the voices is gated on Thus write the desired volume level ...

Page 373: ... is the technique illustrated in Listing 9 3 NEXT1 NEXT4 NEXT3 NEXT2 LDY 18 LDA 00 STA D400 Y BPL NEXT1 LDA SOF STA 0018 LDA 00 STA 0400 LDA CA STA 0401 LDA SOA STA 0405 LDA 00 STA 0406 LDA 21 STA 0404 LDA 04 STA FA LDX FF LDY SFF DEY BNE NEXT2 DEX BNE NEXT3 DEC FA BNE NEXT4 LDA 00 STA 0404 RTS CLEAR SlO REGISTERS SPECIFY MAX VOLUME SET SlO VOLUME SPECIFY LSB OF FREQUENCY SET LSB OF V1 FREQUENCY S...

Page 374: ...BYTE OF DELAV SET LOW BYTE OF DELAV DECREMENT LOW BYTE IF NOT DONE DO AGAIN DECREMENT MlD BYTE DO LOW BYTE AGAIN DECREMENT HIGH BYTE DO MlD AND LOW AGAIN RETURN TO MAIN ROUTINE The listing shows a block of RAM organized in the same sequence as the SID registers The first two bytes 0DOO and 0D01 are the LSB and MSB of the frequency for voice 1 The byte at 0D04 indicates the waveform selection for v...

Page 375: ...GATE BIT STA D412 GATE ON VOICE 3 LDA 08 SET DELAY JSR DELAY DO TIME DELAY LDA 00 STA D404 GATE OFF VOICE 1 STA D40B GATE OFF VOICE 2 STA D412 GATE OFF VOICE 3 RTS END THE ROUTINE DELAY STA FA USE REGISTER FA NEXT4 LDX SFF SET MlD BYTE OF DELAY NEXT3 LDY SFF SET LOW BYTE OF DELAY NEXT2 DEY DECREMENT LOW BYTE BNE NEXT2 IF NOT DONE DO AGAIN DEX DECREMENT MlD BYTE BNE NEXT3 DO LOW BYTE AGAIN DEC FA D...

Page 376: ...d 040A 54281 and 54282 Voice 3 pulse width 0410 and 0411 54288 and 54289 Table 9 4 summarizes the range of pulse widths in steps of five percent and shows the hexadecimal values to be written to the pulse registers Pulse Width percent 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 Register Values 0000 00CD 019A 0266 0333 0400 04CD 0599 0666 0733 0800 08CC 0999 0A66 0B33 0BFF 0CCC 0D...

Page 377: ...te voice 2 with oscillator 1 set bit 2 in D40B 54283 To modulate voice 3 with oscillator 1 set bit 2 in D412 54290 Voice 1 in Listing 9 6 generates a relatively high pitched pinging sound with a triangular waveform No attack interval is included but a decay interval drops the volume to a 0 sustain level The byte at 0D04 not only indicates the use of a triangular waveform but ring modulation with o...

Page 378: ...T4 LDX FF SET MlD BYTE OF DELAY NEXT3 LDY FF SH LOW BYTE OF DELAY NEXT2 DEY DECREMENT LOW BYTE BNE NEXT2 IF NOT DONE DO AGAIN DEX DECREMENT MlD BYTE BNE NEXT3 DO LOW BYTE AGAIN DEC FA DECREMENT HIGH BYTE BNE NEXT4 DO MlD AND LOW AGAIN RTS RETURN TO MAIN ROUTINE The format is established by setting a single bit in one of three wavefarm gate registers Setting the bit to 1 invokes the modulation form...

Page 379: ...to registers allocated for the purpose Cutoff frequency Low order value bits 0 1 and 2 of 0415 54293 High order byte 0416 54294 Resonance level Bits 4 7 of 0417 54295 External filter flag Bit 3 of 0417 45295 O off 1 on Voice 3 filter flag Bit 2 of 0417 45295 O off 1 on Voice 2 filter flag Bit 1 of 0417 45295 O off 1 on Voice 1 filter flag Bit 0 of 0417 45295 O off 1 on High pass filter flag Bit 6 ...

Page 380: ...he attack and decay cycles The register is entirely bit mapped Address 0404 54276 Data 0 disable 1 enable Bit 7 Random noise Bit 6 Pulse wavefarm Bit 5 Sawtooth wavefarm Bit 4 Triangular wavefarm Bit 3 Oscillator test bit Bit 2 Ring modulate 1 with 3 Bit 1 Synchronize 1 with 3 Bit 0 Start attack sustain decay gate 1 start attack sustain 0 start decay VOICE 1 Envelope Generator 1 Writing to this re...

Page 381: ...he larger the values the longer the duty cycle of the waveform Addresses 0409 54281 LSB of pulse wavefarm 040A 54282 MSB of pulse wavefarm Data LSB 00 SFF 0 255 MSB 00 SOF 0 15 Overall range 0000 SOFFF 0 4095 NOTE Bits 4 7 of D40A are not used VOICE 2 Control Register Writing to this register sets the charac ter of the tonal quality of the wavefarm and starts the attack and decay cycles The regist...

Page 382: ...e the higher the frequency Addresses D40E 54286 LSB of voice 3 frequency D40F 54287 MSB of voice 3 frequency Data 00 SFF 0 255 for both registers Total range 0000 SFFFF 0 65535 VOICE 3 Pulse Width Registers Writing tothese registers sets the pulse width when the pulse wavefarm mode is enabled The larger the values the longer the duty cycle of the waveform Addresses D41 0 54288 LSB of pulse wavefar...

Page 383: ...Address 0413 54291 Data Bits 4 7 Attack duration Bits 0 3 Decay duration VOICE 3 Envelope Generator 2 Writing to this register sets the sustain volume level and release interval Address 0414 54292 Data Bits 4 7 Sustain volume level Bits 0 3 Release duration OVERALL VOLUME Writing to the four lower order bytes in this register sets the peak volume level for all voices Address 0418 54296 Data Bits 0...

Page 384: ...10 Keyboard Procedures ...

Page 385: ...e deter mines its matrix coordinate according to values in CIA 1 registers DCOO and DC01 SCNKEY is an integral part of the system s nor mal IRQ interrupt handler so the eperation automatically takes place 60 times a second Unless you are prepared to write your own interrupt handler there is little point in trying to deal directly with the keyboard matrix and the CIA registers It is far simpler and...

Page 386: ...fi IGRAY KEY DCALCULATOR KEY PAD BIT I7 6 I5 I4 I3 I2 I l I0 I COlUMN ROW 1 SFPX REGISTER 04 212 10 by running the short program in Listing 10 1 and pressing the desired keys End the program by striking the STOP key listing 10 1 10 A PEEK 212 20 PRINT RIGHT HEX A 2 A 30 GOTO 10 Six keys in the keyboard matrix do nat appear as unique values in SFDX the two SHIFT keys OF and 34 CONTROL 3A C 3D and A...

Page 387: ... 04 4 11 1D 29 36 54 05 5 11 1E 30 EJ 37 55 06 6 11 1F 31 38 56 07 7 m 20 32 DJ 39 57 8 08 8 21 33 3A 58 09 9 E 22 34 fE 3B 59 0A 10 23 35 lGJJ 3C 60 SPACEBAR OB 11 lE 24 36 EJJ 3D 61 0C 12 f 25 37 EJ 3E 62 EJ 0D 13 26 38 3F 63 OE 14 27 39 lEJJ I 40 64 OF 15 28 40 rEJ I 41 65 10 16 29 41 fJ 42 66 11 17 2A 42 ro 43 67 11 12 18 fl 2B 43 44 68 13 19 0 2C 44 I 45 69 14 20 2D 45 JJ I 46 70 15 21 2E 46 ...

Page 388: ...wn Down Up Down OB 11 Up Up Down Down 0C 12 Down Up Down Down 0D 13 Up Down Down Down OE 14 Down Down Down Down OF 15 mal IRQ interrupt handler Codes indicating the status of these keys appear in the SHFLG register at D3 211 See Figure 10 4 SFDX indicates which of the basic keys is pressed and SHFLG in dicates the current combination of SHIFT C CONTROL and ALT keys Given those two registers you ca...

Page 389: ...ch is latched down 80 column display and 128 if it is up 40 column display The RESTORE key is connected to CIA 2 and is checked as part of the systems NMI interrupt routine The SHIFT LOCK key is simply a push on push off toggle switch that is connected in parallel with the SHIFT keys Using the Keyboard Queue and GETIN The system s keyboard queue is a small 10 byte buffer located from 034A through ...

Page 390: ...f being codes that indicate the column row coordinate of a pressed key the codes in the keyboard queue are adjusted according to the Commodore 128 s ASCII character format shown in Figure 10 5 Key Alone 8 5F 95 lEJl 31 49 EJ 32 50 33 51 34 52 tJ 35 53 lEJ 36 54 EJJ 37 55 I Jl 38 56 f 39 57 i 30 48 f 2B 43 lE 2D 45 Q SC 92 e 13 19 rr Jl 14 20 fJl 51 81 lEJl 57 87 5F 95 21 33 22 34 23 35 24 36 25 37...

Page 391: ...79 CF 207 OF 15 B9 185 50 80 DO 208 10 16 AF 175 f 40 64 BA 186 00 0 A4 164 E ZA 42 CO 192 00 0 DF 223 mJ 5E 94 DE 222 1E 30 DE 222 p 03 3 83 131 03 3 03 3 E 41 65 Cl 193 01 1 BO 176 53 83 D3 211 13 19 AE 174 fJ 44 68 C4 196 04 4 AC 172 0 46 70 C6 198 06 6 BB 187 f 47 71 C7 199 07 7 A5 165 lEJJ 48 72 CS zoo 08 8 B4 180 EJ 4A 74 CA 202 0A 10 B5 181 lEJJ 4B 75 CB 203 OB 11 Al 161 4C 76 CC 204 0C 12 ...

Page 392: ...6 214 16 22 BE 190 42 66 CZ 194 02 2 BF 191 E 4E 78 CE 206 OE 14 AA 170 EJJ 4D 77 CD 205 0D 13 A7 167 E 2C 44 3C 60 00 0 3C 60 ZE 46 3E 62 00 0 3E 62 2F 47 3F 63 00 0 3F 63 m 11 17 91 145 00 0 91 145 ffiJ 1D 29 9D 157 00 0 9D 157 E J 20 32 AO 160 00 0 AO 160 f JJ 31 49 31 49 31 49 31 49 fË 32 50 32 50 32 50 32 50 fE 33 51 33 51 33 51 33 51 fJ 34 52 34 52 34 52 34 52 35 53 35 53 35 53 35 53 f 36 54...

Page 393: ...2B 43 2B 43 2B 43 2B 43 lJ 2D 45 2D 45 2D 45 2D 45 0D 13 8D 141 8D 141 8D 141 1B 27 1B 27 1B 27 1B 27 09 9 18 24 18 24 18 24 84 132 84 132 84 132 84 132 0A 10 0A 10 0A 10 0A 10 91 145 91 145 91 145 91 145 11 17 11 17 11 17 11 17 9D 157 9D 157 9D 157 9D 157 1D 29 1D 29 1D 29 1D 29 85 133 89 137 00 0 89 137 86 134 8A 138 00 0 8A 138 87 135 8B 139 00 0 8B 139 88 136 8C 140 00 0 8C 140 ...

Page 394: ...ueue Pressing the function keys Fl through F8 and the HELP key does not print a simple keycode Rather they stack the queue with the sequence of ASCII characters that spell out the command Strike the Fl key for example and you see hexadecimal values 47 52 41 50 48 49 and 43 Look up those codes in Table 10 5 and you will see that the sequence spells out GRAPHIC the cammand normally assigned to funct...

Page 395: ...ers typedat the keyboard are stacked into this buffer until certain kinds of actions dispatch the information elsewhere The main keyboard buffer is quite different from the simpler keyboard queue in several respects One of the most obvious differ ences is that the main keyboard buffer is much larger 161 bytes as opposed to just 10 That fact leads to another major difference the Kemal s GETIN routi...

Page 396: ...ired for machine language programs A keyboard input routine at 4F93 20371 makes it easy toenter eliar acters from the keyboard into the main keyboard buffer The routine shows the blinking cursor accepts editing operations and ends only when the user presses the RETURN key The machine language program in Listing 10 5 accepts the user s input from the keyboard and places it into the main keyboard bu...

Page 397: ... makes rather easy the changing of func tions assigned to keys F1 through F8 See the description of that state ment in Chapter 2 Any of the ten functions can be changed by taking advantage of a Kernal routine accessed from FF65 65381 The general procedure for altering any of the key functions is 1 Write the text for the desired function to a convenient location in RAM 2 Write the LSB MSB and bank ...

Page 398: ...MID C K 1 1 40 NEXT K 50 POKE 250 0 POKE 251 12 POKE 252 15 60 SYS 65381 250 9 LEN C Line 10 Define the key fundion sound the bell Lines 20 40 Load the text for the function beginning from address 3072 0COO Line 50 Specify the address of the text LSB of the address to 250 MSB of the address to 251 Bank number to 252 Line 60 Call the Kernal at 65381 after setting Address 250 to register A Fundion n...

Page 399: ... key assignments involves copying the ROM version CEA8 CEF4 to the function key RAM table 1000 104C A BASIC version of the procedure looks like this 10 FOR K O TO 76 20 POKE 4096 K PEEK 52904 K 30 NEXT K See Listing 10 8 for an assembly language implementation of the same operation XFER LDX 4C LDA CEA8 X STA 1000 X DEX BPL XFER RTS SET XFER POINTER TO 76 BYTES GET BYTE FROM ROM SAVETO RAM DECREMEN...

Page 400: ...11 Joystick Paddle light Pen and Mouse Procedures ...

Page 401: ...age routines Unfortunately the Commodore 128 products and software documentation for the light pen and mouse are scanty at the time of this writing Instead of guess ing or attempting to generalize such information from Commodore s Amiga computer we have decided to omit further references to light pen and mouse procedures You will simply have to keep an eye open for developments described in future...

Page 402: ...e program in a do nothing loop until a player presses the pushbutton on joystick 1 Once the program is started it is ended only when bath players press their respective pushbuttons at the same time Listing 11 1 10 IF JOY 1 128 THEN 10 20 IF JOY 1 128 THEN J1 JOY 1 128 81 11 11 ELSE 81 1111 30 IF JOY 2 128 THEN J2 JOY 2 128 82 11 11 ELSE 82 1111 40 PRINT J1 81 J2 82 50 IF JOY 1 128 AND JOY 2 128 TH...

Page 403: ... Joystick position switch 0 Bit 1 Joystick position switch 1 Bit 2 Joystick position switch 2 Bit 3 Joystick position switch 3 Bit 4 Pushbutton Determining the position of joystick 1 is thus a matter of PEEK ing into its register and isolating the four lower order bits Such a statement returns the decimal stick position values shown in Table 11 1 For example J1 PEEK 56320 AND 15 Determining the st...

Page 404: ...tick reading pro cedure into the IRQ interrupt handler Once you execute the routine zero page registers FA and FB carry the five switch bits for joy sticks 1 and 2 respectively The advantage is that the system updates the status every 1 60th of a second whether any other programming is running or not 0000 SEI SET INTERRUPT OISABLE 0001 LOA 00 LSB OF NEW IRQ 0003 STA 0314 TO IRQ LSB VECTOR 0006 LOA...

Page 405: ...paddles 1 through 4 The example in Listing 11 3 prints values indicating the posi tions of the dials on the four paddles An asterisk beside the values indicates the corresponding fire pushbutton is pressed The pro gram runs in an endless loop sa you should do a STOP keystroke to end it Listing 11 3 10 FOR K 1 TO 4 20 J K POT K 30 BS K 11 IF J K 255 THEN J K 256 B K 11 11 40 PRINT J K B K 50 NEXT K...

Page 406: ...AM 8 Write 40 toPort A register DCOO to read pots 2 and 4 9 Do a short delay 10 Fetch and save the positions of pots 2 and 4 Read from SID addresses D419 and D41A and save in available RAM 11 Fetch the fire button status for buttons 2 and 4 Read from bits 2 and 3 of DC01 shift them to bits 0 and 1 and mask them off Savetheresult in available RAM 12 Fetch the original CIA 1 direction byte saved in ...

Page 407: ...SABLE INTERRUPTS GET CURRENT DATA DIRECTION FOR PORT A SAVE IT SPECIFY INPUT LINES 6 AND 7 SET THE INPUTS SPECIFY UNIT A POTS 1 AND 3 ADDRESS THEM DO A TIME DELAY GET POT 1 SAVE IT GET POT 3 SAVE IT GET BUTTON STATUS FOR POTS 1 AND 3 ISOLATE THE BUTTON BITS SAVE BUTTON STATUS SPECIFY UNIT B POTS 2 AND 4 ADDRESS THEM DO A TIME DELAY GET POT 2 SAVE IT GET POT 4 SAVE IT GET BUTTON STATUS FOR POTS 2 A...

Page 408: ...12 Printer end Communications Procedures ...

Page 409: ...he screen The simplest printer arrangement uses one of the printers manufactured specific ally for Commodore computers The printer should he daisy chained from the computer s serial portand through other serial devices such as disk drives as shown in Figure 12 1 Other brands of printers use the same general con nections but require a special adapter unit that should he available through your Commo...

Page 410: ...eral form is PRINT filenum text The filenum parameter must be the same file number that was used for opening the printer file and text is any numeric or string constant variable or expression The following example prints HELLO to the printer assuming that the file was previously opened as file number 1 PRINT 1 HELLO When your printer operations are done you must close the printer channel this way ...

Page 411: ... then to the screen Line 70 Close the printer file Listing 12 2 10 SCNCLR 20 PRINT THIS IS GOING ONLV TO THE SCREEN 30 OPEN 1 4 0 40 PRINT 1 THIS IS GOING ONLY TO THE PRINTER 50 M THIS IS GOING TO BOTH 60 PRINT 4 M PRINT M 70 CLOSE 1 An alternative procedure for directing information to the printer is to redirect all screen characters to the printer The procedure makes impractical the sending of d...

Page 412: ...istings to the printer so that you can make a hardcopy listing of a machine lan guage program Begin the operation with this sort of operation OPEN filenum 4 set MONITOR This opens a file for the printer directs screen operations to it and sets the monitor mode Next enter the range of programming to be disassembied and printed D strtaddr endaddr When the listingis clone press the X key to return to...

Page 413: ...oa telephone however requires a special accessory called a modem The modem plugs into the User Port on the rear of the console unit and a telephone jack and cable assembly connects the modem to the telephone system The following discussions assume that you have installed a modem device specifically designed for the Commo dore family of personal computers It is beyond the scope of this book to intr...

Page 414: ...number simply serves as a reference number for subsequent I 0 statements for that channel Consiclering that you cannot work with more than 10 files at any given moment the file numbers are generally numbers between 1 and 10 In the RS 232 C format however using file numbers between 128 and 255 serves a special purpose it instructs the system to insert a line feed character after each carriage retur...

Page 415: ... columns in the table are 0 0 and 6 The sum of the three values is 6 so the value assigned to the control term would be 6 Number of Stop Bits Number Add 1 2 0 128 Number of Bits per Word Number Add 8 7 6 5 0 32 64 96 BaudRate Baud Add user def 0 50 1 75 2 110 3 134 5 4 150 5 300 6 600 7 1200 8 1800 9 2400 10 3600 11 4800 12 7200 13 9600 14 19200 15 The cammand term in the OPEN statement sets the p...

Page 416: ... Obviously these blocks of RAM should be used for no other purpose while the RS 232 C channel is open A more subtie feature of the OPEN statement for an RS 232 C channel is that it automatically clears all specified variabie values and doses any other channels that are open at the time For this reason a program usually opens the RS 232 C channel befare using any vari ables and opening other kinds ...

Page 417: ... 1F RX 1111 THEN 40 30 PRINT RX 40 GET TXS IF TX 1111 THEN 20 50 IF ASC TX 17 THEN 80 60 PRINT 1 TX 70 GOTO 20 80 CLOSE 1 Communicating with Other Computers Many other kinds of computer systems use a character coding format that is slightly different from that of the Commodore 128 Therefore you need to translate characters being sent and received in order to avoid confusion Table 12 4 compares the...

Page 418: ... down 18 12 DC2 reverseon 19 13 DC3 home 20 14 DC4 DEL 21 15 NAK 22 16 SYN 23 17 ETB 24 18 CAN setlclear tabs 25 19 EM 26 lA SUB 27 1B ESC ESC 28 1C FS red 29 1D GS cursor right 30 1E RS green 31 1F US blue 32 20 SPACE SPACE 33 21 34 22 11 11 35 23 36 24 37 25 38 26 39 27 40 28 41 29 42 2A 43 2B 44 2C 45 2D 46 2E 47 2F I I 48 30 0 0 49 31 1 1 50 32 2 2 51 33 3 3 52 34 4 4 53 35 5 5 54 36 6 6 55 37...

Page 419: ... 73 49 I 74 4A J j 75 4B K k 76 4C L 1 77 4D M m 78 4E N n 79 4F 0 0 80 50 p p 81 51 Q q 82 52 R r 83 53 s s 84 54 T t 85 55 u u 86 56 V V 87 57 w w 88 58 x x 89 59 y y 90 5A z z 91 5B 92 5C f 93 5D 1 1 94 5E A t 95 5F 96 60 graphic 97 61 a A 98 62 b B 99 63 c c 100 64 d D 101 65 e E 102 66 f F 103 67 g G 104 68 h H 105 69 i I 106 6A j J 107 6B k K 108 6C 1 L 109 6D m M 110 6E n N 111 6F 0 0 ...

Page 420: ...ration Line 20 Dimension the transmit receive arrays Line 30 Set all values to 1 255 consecutively Line 40 Set 0 31 in the receive array to 0 Lines 50 and 60 Align the uppercase and lowercase letters in bath arrays Line 70 Set 128 159 in the receive array to 0 Line 80 Adjust transmit arraytosend lower valued codes Lines 90 and 100 Align backspace and DEL operations in bath arrays Line 110 Restore ...

Page 421: ... routine Listing 12 5 10 OPEN 1 2 2 6 0 20 FAST 30 DIM T 255 DIM R 255 40 FOR K O TO 255 T K K R K K NEXT 50 FOR K O TO 31 R K O NEXT 60 FOR K 65 TO 90 T K K 32 R K K 32 NEXT 70 FOR K 97 TO 122 T K K 32 R K K 32 NEXT 80 FOR K 128 TO 159 R K O NEXT 90 FOR K 193 TO 218 T K K 128 NEXT 100 T 20 127 T 157 8 110 R 13 13 R 8 157 R 127 20 120 SLOW 130 GET 1 RX 1F RX 1111 THEN 150 140 PRINT CHR R ASC RX 15...

Page 422: ...13 Commodore 128 MemoryMops ...

Page 423: ... RAM area is unique in several important respects First it is directly accessible from all sixteen bank configurations That says sarnething about its relative importance to the system The only other equally accessible block of memory is the four MMU registers at FFOO FF04 A second unique feature is that it includes the microprocessor s zero page RAM a segment of RAM that can be machine language ad...

Page 424: ...program counter 04 4 LSB of program counter 05 5 P register 06 6 Monitor A register 07 7 X register 08 8 Y register 09 9 SP register 0A 10 ENDCHR Scan for quote at the end of a string OB 11 TRMPOS Column location of the previous TAB statement in the current line of BASIC programming 0C 0E 12 14 BASIC applications OF 15 VALTYP BASIC DATA type 00 0 Numeric SFF 255 String 10 16 INTFLG Numeric data fo...

Page 425: ...k 1 BASIC variabie list 2F 47 LSB of address 30 48 MSB of address Default address 0400 31 32 49 50 ARYTAB Pointertostart of RAM Bank 1 BASIC arrays 31 49 LSB of address 32 50 MSB of address Default address 0400 33 34 51 52 PRETOP Pointertostart of free RAM Bank 1 memory space 33 51 LSB of address 34 52 MSB of address Default address 0400 35 36 53 54 STREND Pointer toendof RAM Bank 1 BASIC string s...

Page 426: ...60 CURLIN Current BASIC line number 3B 59 LSB of line number 3C 60 MSB of line number 3D 3E 61 62 TXTPTR Pointer to address of the current BASIC text character 30 61 LSB of address 3E 62 MSB of address 41 42 65 66 DATLIN Current DATA line number 41 65 LSB of line number 42 66 MSB of line number 43 44 67 68 DATPTR RAM address of the current DATA item 43 67 LSB of address 44 68 MSB of address 47 48 ...

Page 427: ...ccumulator 1 6A 6F 106 111 Floating point accumulator 2 70 7C 112 124 Basic applications 7D 7E 125 126 BASIC run time stack pointer 7F 127 Program mode flag 00 0 Direct mode 80 128 Program mode 80 8F 128 143 Graphics parameters registers 90 144 STATUS Kernal I 0 status byte ST 91 145 STKEY STOP key flag 00 0 Key not pressed 80 128 Key pressed ...

Page 428: ...red character to send in TALK 96 150 SYNO Cassette synchronization number 97 151 Scratch register 98 152 LDTND Number of open files file tabie index Reading from this register returns the number of files currently open Default value 00 0 Do nat write data directly to this register 99 153 DFLTN Default input device number The default input device is the keyboard so reading from this register return...

Page 429: ...error message s displayed 80 128 Only control message s displayed CO 192 Control and error messages displayed 9E 9F 158 159 Cassette error flags 9E 158 Pass 1 status 9F 159 Pass 2 status AO A2 160 162 TIME Three byte free running 60Hz counter SAO 160 High order byte A1 161 Middle byte SA2 162 Low order byte Reading from these registers returns the current count Writing to them sets the counter A3 ...

Page 430: ...f cassette input buffer The difference between this pointerand TAPEl at B2 and B3 is not clear AC 172 LSB of address AD 173 MSB of address Default 0800 2816 The registers are also used for text screen scrolling operations AE AF 174 175 EAL Address of the end of a program or file block SAE 174 LSB of address AF 175 MSB of address Reading from these registers after loading a program or file returns ...

Page 431: ...he number of characters in the last referenced file name B8 184 LA Current logical file number Reading from this register returns the file number of the last referenced file B9 185 SA Current secondary address BA 186 FA Current device number BB BC 187 188 FNADR Address of the start of the current file name BB 187 LSB of address BC 188 MSB of address Use BANKFat C7 to specify a bank number other th...

Page 432: ... of vector restare table Set to default value by the RESTOR Kernal E073 57459 C5 197 CDATA Cassette read write scratch register C6 198 BANKB Bank number for the current block read write or verify operation C7 199 BANKF Bank number of the current file name used in conjunction with the file name address FNADR at BB Default bank number 00 0 C8 C9 200 201 RIBUF Address of the start of the RS 232 C inp...

Page 433: ... characters remaining in the keyboard buffer key board index pointer Dl D2 209 210 Keyboard applications 03 211 SHFLAG Key flag for SHIFT C CONTROL and ALT keys 00 0 None of the following keys 01 1 SHIFT key depressed 02 2 C key depressed 04 4 CONTROL key depressed 08 8 ALT key depressed SOF 15 CAPS LOCKis locked down Sum the values to determine the nature of simultaneous key presses See Chapter 1...

Page 434: ...APHIC 1 60 96 Standard split screen graphics GRAPHIC 2 AO 160 Multicolor full screen graphics GRAPHIC 3 EO 224 Multicolor split screen graphics GRAPHIC 4 Reading from this location returns the current text graphics screen mode Writing to the location sets the designated mode D9 217 Image of bit 2 ofthe R8510 register at 01 DA DF 218 223 Editor applications EO E1 224 225 PNT Screen RAM address of t...

Page 435: ...DLFT Left column of the current text window E7 Range of values 40 column screen 00 27 0 39 80 column screen 00 4F 0 79 Default value 00 0 231 WINDRGT Right column of the current text window Range of values 40 column screen 00 27 0 39 80 column screen 00 4F 0 79 Default value 27 39 NOTE The value is set to 4F 79 when the 80 column screen is invoked E8 232 LXSP Logicalline number for current input o...

Page 436: ...T ED Maximum range of values 40 column screen 00 27 0 39 80 column screen 00 4F 0 79 237 WINDUNS Number of available lines in the current text window EE Range of values 00 18 0 24 Default value 18 24 238 WINDCOLS Number of available columns in the current text window EF Range of values 40 column screen 00 27 0 39 80 column screen 00 4F 0 79 Default values 40 column screen 27 39 80 column screen 4F...

Page 437: ... bits 0 through 3 are meaningful F3 243 RVS Normal reverse printing flag 00 0 Normal Non zero value Reverse Reading from RVS register returns the current status Writing the val ues totheregister sets the normal reverse status F4 244 QTSW Quote mode flag 00 0 Quote mode off Non zero value Quote mode on F5 245 QTSW Insert mode flag 00 0 Insert mode off Non zero value Insert mode on F6 246 INSRT Curr...

Page 438: ...er programs FFI 255 BAS ZPT Top of zero page BASIC scratch register System Stack RAM 0100 01FF The 502 microprocessor makes extensive use of the 256 byte block of RÁM known as the system stack The microprocessor handles data on a first in last out basis That is bytes A and B might he pushed onto the stack in that order but they have to he pulled off in the reverse order byte B foliowed by byte A S...

Page 439: ...em 0200 02A1 512 673 Input buffer for BASIC and the monitor 161 bytes 02A2 02AE 674 686 Kernal RAM code for fetching a byte from any bank See the main Kernal at FF74 02AF 02BD 687 701 Kernal RAM code for sending a byte to any bank See the main Kerm ll at FF77 02BE 02CC 702 716 Kernal RAM code for camparing bytes between any two banks See the main Kernal at FF7A 02CD 02E2 717 738 Kernal RAM code fo...

Page 440: ...hat restores a BASICtoken to text Default address 5151 0308 0309 776 777 IGONE Vectortoa routine that executes a BASIC token Default address 4AA2 030A 030B 778 779 lEVAL Vector to a routine that interprets a BASIC arithmetic function Default address 78DA 030C 030D 780 781 Vectortoa routine that tokenizes two character ESCAPE commands Default address 4321 030E 030F 782 783 Vectortoa routine that co...

Page 441: ...790 791 CBINV RAM vector to BRK instruction interrupt handler Default address 8003 0318 0319 792 793 NMINV RAM vector to NMI interrupt handler Default address FA40 031A 031B 794 795 lOPEN RAM Kernal vector to OPEN routine Default function OPEN at address SEFBD 031C 031D 796 797 ICLOSE RAM Kernal vector to CLOSE routine Default function CLOSE at address F188 031E 031F 798 799 ICHKIN RAM Kernal vect...

Page 442: ...lt function CHRIN at address EF06 0326 0327 806 807 IBSOUT RAM Kernal vector to BSOUT routine Default function BSOUT at address EF79 0328 0329 808 809 ISTOP RAM Kernal vector to STOP routine Default function STOP at address F66E 032A 032B 810 811 IGETIN RAM Kernal vector to GETIN routine Default function GETIN at address EEEB 032C 032D 812 813 ICLALL RAM Kernal vector to CLALL routine Default func...

Page 443: ...4A 0353 842 851 KEYD Ten byte IRQkeyboard buffer keyboard queue 0354 035D 852 861 Map of screen TAB stops 10 bytes 035E 0361 862 865 Map of screen line wraps 4 bytes 0362 036B 866 875 LAT Logical file numbers for each open file 10 maximum 036C 0375 876 885 FAT Device numbers for each open file 10 maximum 0376 0 37F 886 895 SAT Secondary addresses for each open file 10 maximum 0380 039E 896 926 CHR...

Page 444: ...h indirect from Bank 0 Index from zero page 3D 3E 03D2 03FF 978 1023 Miscellaneous applications The Upper RAM Only Area 0400 3FFF The upper RAM only area includes important IlO buffers a few rou tines and a lot of video memory It begins with the default text screen RAM at 0400 through 07FF 1024 2047 See Chapter 6 fora line by line map of the screen RAM BASIC Run Time Stock 0800 09FF The BASIC run ...

Page 445: ... start 0AOO LSB of the address 0AOO MSB of the address Default value 4003 16387 0A02 0A04 2562 2564 System status video configuration bytes 0A05 0A06 2565 2566 MEMSTR Pointer to the beginning of system usable Bank 0 RAM 0A05 2565 LSB of the address 0A06 2566 MSB of the address Default value 1COO 7168 0A07 0A08 2567 2568 MEMSIZ Pointer to the top of system usable Bank 1 RAM 0A07 2567 LSB of the add...

Page 446: ...shake bit Bits 2 4 Not used set to 0 Memory Mops 439 Bits 6 7 Parity format default NO PARITY See details in Chapter 12 0A12 0Al3 2578 2579 M51AJB Non standard RS 232 C baudrate 0A14 2580 RSSTAT RS 232 C status register Bit 0 Operating mode bit Bits 1 5 Not used Bit 6 Line feed format Bit 7 Echo format See details in Chapter 12 0A15 2581 BITNUM Number of bits to be sentor received via RS 232 C 0A1...

Page 447: ...RS 232 C flag bit 0AlD 0AlF 2589 2591 TIMED Downcounting version of the three byte real time doek at zero page AO through A2 0A1 D 2589 LSB of counter 0A1 E 2590 Middle byte of counter 0A1F 2591 MSB of counter 0A20 2592 XMAX Maximum size of the keyboard buffer Default value SOA 10 bytes 0A21 2593 Output stop flag generated by CONTROL S key command 0A22 2594 RPTFLG Repeat key flag 00 0 Disable repe...

Page 448: ...p bit maps swapped with 0354 0361 852 865 when switching between 40 and 80 column screens 0A80 0A9F 2688 2719 Monitor buffer 0AA0 0AFF 2720 2815 Reserved for general system applications Buffer Area SOB00 10FF This Bank 0 area of RAM is set aside forsets of 256 byte buffers The blocks are available for machine language programs and files as long as they are nat being used fortheir prescribed purpos...

Page 449: ...ey assignments up to 46 bytes General BASIC Usage 1208 121A 1208 4616 Error number for BASIC slast error condition 1209 120A 4617 4618 Line number for BASIC slast error condition 1209 4617 LSB of line number 120A 4618 MSB of line number 1210 1211 4624 4625 Pointer to end of BASIC programming in Bank 0 1210 4624 LSB of address 1211 4625 MSB of address 1212 1213 4626 4627 Pointer to highest availabl...

Page 450: ...n memory BASIC ROM 4000 SAFFF The BASIC interpreter accupies 4000 through AFFF when the sys tem is configured for ROM in that block Critical BASIC Jump Veetors 4000 16343 Jump instruction to BASIC s cold start routine The point executes a JMP instruction to 4023 4003 16346 Jump instruction to BASIC swarm start routine The point executes a JMP instruction to 4009 4006 16349 Jump instruction to BASI...

Page 451: ...ble at AF5A See more details at AF5A 8COO 35840 Entry point for a routine that transfers a numeric value from Float ing Point Accumulator 1 to a designated location in RAM Execute this routine from the jump table at AF66 See AF66 for more details 8C28 35880 Entry pointfora routine that copies a floating point value from FAC2 to FACl Call this from the FAC jump table at AF69 8C38 35896 Entry pointf...

Page 452: ...rts the current content of FACl into ASCII coded text Enter this routine from AF06 See AF06 in the FAC jump table for more information 8FB7 36791 Entry point for the routine that executes BASIC s SQR operation to calculate the square root of a floating point value Use AF30 to access it See SQR at AF30 for more information 8FFA 36858 Entry point for the routine that negates a floating point value U...

Page 453: ...ation AF03 AF05 44803 44805 This entry point actually executes a JMP 793C AF06 AF08 44806 44808 Jump statement to a routine that converts a floating point value in FAC1 into a ASCII coded string beginning from address 0100 256 Procedure 1 Load the value to be converted into FACl 2 Set the Bank 15 configuration and call the routine LDA 00 STA SFFOO JSR AF06 3 Read the ASCII version from 0100 to the...

Page 454: ...P 8845 AF1B AF1D 44827 44829 This entry point actually executes a JMP 8848 AF1E AF20 44830 44832 This entry point actually executes a JMP 8A24 AF21 AF23 44833 44835 This entry point actually executes a JMP 8A27 AF24 AF26 44836 44838 This entry point actually executes a JMP 8B49 AF27 AF29 44839 44841 This entry point actually executes a JMP 8B4C AF2A AF2C 44842 44844 This entry point actually execu...

Page 455: ...oint Accumulator 1 FAC 1 In effect it multiplies the value by 1 Procedure 1 Laad the argument to FAC l 2 Call this routine JSR AF33 3 Rëad the negated value in FAC l This entry point actually executes a JMP 8FFA AF36 AF38 44854 44856 This entry point actually executes a JMP 8FBE AF39 AF3B 44857 44859 This entry point actually executes a JMP 8FC1 AF3C AF3E 44860 44862 This entry point actually exec...

Page 456: ...F45 AF47 44869 44871 TAN Jump instruction toa routine that calculates the trigonometrie tangent of a value in Floating Point Accumulator 1 FAC 1 Procedure 1 Laad the angle in radians to FAC l 2 Call this routine JSR AF45 3 Read the tangent of the value in FAC l This entry point actually executes a JMP 9459 AF48 AF4A 44872 44874 ATN Jump instruction toa routine that calculates the trigonometrie arc...

Page 457: ...in Floating Point Accumulator 1 FAC 1 Procedure 1 Load the argument to FAC l 2 Call this routine JSR AF4E 3 Read the absolute value from FAC l This entry point actually executes a JMP 8C84 AF51 AF53 44881 44883 SGN Jump instruction toa routine that returns a value which indi cates the sign of a number in Floating Point Accumulator 1 FAC 1 Procedure 1 Load the floating point value to FAC l 2 Call t...

Page 458: ...AF60 AF62 44896 44898 Jump instruction to a routine that moves a value from a specified location in RAM to Floating Point Accumulator 1 Procedure 1 Laad the LSB of the souree RAM address to register 2 Laad the MSB of the souree RAM address to register Y 3 Call this routine JSR AF66 NOTE Use the routine described at AF66 to move a value from FAC l toa location in RAM The entry point actually execut...

Page 459: ...a JMP 8C28 AF6C AF6E 44908 44910 Jump instruction toa routine that copies the content of FACl to FACZ Procedure Call the routine JSR AF6C This entry point actually executes a JMP 8C38 AF7B AF7D 44923 44925 This entry point actually executes a JMP 5A9B AF7E AF80 44926 44928 This entry point actually executes a JMP 51F3 AF81 AF83 44929 44931 This entry point actually executes a JMP 51F8 AF84 AF86 44...

Page 460: ... This entry point actually executes a JMP 5A81 AF9F AFA1 44959 44961 This entry point actually executes a JMP 50AO AFA2 AFA4 44962 44964 This entry point actually executes a JMP 92EA AFA5 AFA7 44965 44967 This entry point actually executes a JMP 4DCD Screen Editor ROM COOO CFFF The screen editor ROM contains a number of jump instructions for Ker nal and interrupt routines as well as some screen ro...

Page 461: ...e at C234 C009 COOB 49161 49163 Jump instruction to editor routine at C29B COOC COOE 49164 49166 Jump instruction to editor routine at C72D COOF C011 49167 49169 Jump instruction to SCREEN Kernal routine at CC5B See SCREEN at Kernal address FFED for more details C012 C014 49170 49172 Jump instruction to SCNKEY Kernal routine at C55D See SCKKEY at Kernal address FF9F for more details C015 C017 4917...

Page 462: ...lumn character set See Kernal address FF65 for more details C02A C02C 49194 49196 Jump instructien to Kernal SWAP routine at CDZE See Kernal address FF5F for more details C02D C02F 49197 49199 Jump instructien to editor routine at CA1B Screen Editor ROM Routines and Buffers C065 C07A 49253 49274 ROM version of editor indirects that are loaded to RAM 0334 0349 by the CINT Kernal routine C07B 49275 ...

Page 463: ...character ROM in the Bank 14 configuration and is available as RAM in bank configurations 0 1 2 and 3 1 0 Block Map Bank configured as an I 0 block DOOO through DFFF contains 1 The VIC 40 column text and video chip 2 SID sound chip 3 A dynamic memory management unit MMU chip 4 The 80 column video chip 5 40 column color memory 6 A complex interface adapter CIA for game paddles joysticks keyboard an...

Page 464: ... SDOOE 53262 Sprite 8 LSB of X position DOOF 53263 Sprite 8 Y position 0010 53264 9th bit of sprite X positions Bit 0 Sprite 1 Bit 1 Sprite 2 Bit 2 Sprite 3 Bit 3 Sprite 4 Bit 4 Sprite 5 Bit 5 Sprite 6 Bit 6 Sprite 7 Bit 7 Sprite 8 0011 53265 VIC control register 1 Bit 7 Raster campare bit Bit 6 Extended color flag 0 normal 1 extended color Bit 5 Bit map mode flag 0 normal 1 bit map mode Bit 4 Bla...

Page 465: ... Light pen latch for X position 0015 53269 Sprite display flag register 0 sprite off 1 spriteon 0016 Bit 0 Sprite 1 on off Bit 1 Sprite 2 on off Bit 2 Sprite 3 on off Bit 3 Sprite 4 on off Bit 4 Sprite 5 on off Bit 5 Sprite 6 on off Bit 6 Sprite 7 on off Bit 7 Sprite 8 on off 53270 VIC control register 2 Bits 6 7 Not used Bit 5 Always 0 Bit 4 Multicolor flag 0 standard 1 multicolor Bit 3 38 40 col...

Page 466: ...and sprite 6 Bit 6 Y expand sprite 7 Bit 7 Y expand sprite 8 53272 VIC internal address vectors Memory Mops 459 Bits 4 7 Video matrix base address Bits 0 3 Character dot base address D019 53273 VIC IRQ flags 0 na 1 yes DO lA Bit 7 Any IRQ Bits 4 7 Nat used Bit 3 Light pen IRQ Bit 2 Sprite to sprite callision IRQ Bit 1 Sprite to figure callision IRQ Bit 0 Raster campare IRQ 53274 VIC IRQ Mask 0 int...

Page 467: ...3276 Sprite multicolor enable flags 0 standard 1 multicolor D01D Bit 0 Sprite 1 color mode Bit 1 Sprite 2 color mode Bit 2 Sprite 3 color mode Bit 3 Sprite 4 color mode Bit 4 Sprite 5 color mode Bit 5 Sprite 6 color mode Bit 6 Sprite 7 color mode Bit 7 Sprite 8 color mode 53277 Sprite 2X horizontal expansion flags 0 normal 1 expand Bit 0 X expand sprite 1 Bit 1 X expand sprite 2 Bit 2 X expand spr...

Page 468: ...rite to sprite collisionsin Chapter 8 DOlF 53279 Sprite to figure callision detection flags 0 sprite not involved 1 sprite involved Bit 0 Sprite 1 callision Bit 1 Sprite 2 callision Bit 2 Sprite 3 callision Bit 3 Sprite 4 callision Bit 4 Sprite 5 callision Bit 5 Sprite 6 callision Bit 6 Sprite 7 callision Bit 7 Sprite 8 collision See a complete table of values for all possible combinations of spri...

Page 469: ...1 Low order nibble values are 0 through F 0 15 D026 53286 Sprite multicolor 2 Low order nibble values are 0 through F 0 15 D027 53287 Sprite 1 color Low order nibble values are 0 through F 0 15 D028 53288 Sprite 2 color Low order nibble values are 0 through F 0 15 D029 53289 Sprite 3 color Low order nibble values are 0 through F 0 15 D02A 53290 Sprite 4 color Low order nibble values are 0 through ...

Page 470: ... width registers 0402 54274 LSB of pulse wavefarm 0403 54275 MSB of pulse waveform bits 0 3 NOTE Bits 4 7 of D403 are not used D404 54276 Voice 1 control register 0 disable 1 enable D405 Bit 7 Random noise Bit 6 Pulse wavefarm Bit 5 Sawtooth wavefarm Bit 4 Triangular wavefarm Bit 3 Oscillator test bit Bit 2 Ring modulate 1 with 3 Bit 1 Synchronize 1 with 3 Bit 0 Start attack sustain decay gate 1 s...

Page 471: ...2 Voice 2 pulse width registers 0409 54281 LSB of pulse wavefarm 040A 54282 MSB of pulse waveform bits 0 3 NOTE Bits 4 7 of D40A are nat used D40B 54283 Voice 2 control register Data 0 disable 1 enable Bit 7 Random noise Bit 6 Pulse wavefarm Bit 5 Sawtooth wavefarm Bit 4 Triangular wavefarm Bit 3 Oscillator onloff 0 on 1 off Bit 2 Ring modulate 2 with 1 Bit 1 Synchronize 2 with 1 Bit 0 Start attac...

Page 472: ...287 MSB of voice 3 frequency D410 D4011 54288 54289 Voice 3 pulse width registers 0410 54288 LSB of pulse waveform 0411 54289 MSB of pulse waveform bits 0 3 NOTE Bits 4 7 of D411 are not used SD412 54290 Voice 3 control register Data 0 disable 1 enable Bit 7 Random noise Bit 6 Pulse waveform Bit 5 Sawtooth waveform Bit 4 Triangular waveform Bit 3 Oscillator test bit Bit 2 Ring modulate 3 with 2 Bi...

Page 473: ...of D415 are not used D417 54295 Filter control register Bits 4 7 Filter resonance 0 15 Bit 3 Filter external input 0 no 1 yes Bit 2 Filter voice 3 0 no 1 yes Bit 1 Filter voice 2 0 no 1 yes Bit 0 Filter voice 1 0 no 1 yes D418 54296 Filter mode and volume register Bit 7 Voice 3 disable 0 no 1 yes Bit 6 Select SID high pass filter 0 no 1 yes Bit 5 Select SID bandpass filter 0 no 1 yes Bit 4 Select ...

Page 474: ...lope output for voice 3 D41D D41F 54301 54303 Not used D420 D43F 54304 54335 Image of D400 D41F D440 D45F 54336 54367 Image of D400 D41F D460 D47F 54368 54399 Image of D400 D41F D480 D49F 54400 54431 Image of D400 D41F D4AO D4BF 54432 54463 Image of D400 D41F D4CO D4DF 54464 54495 Image of D400 D41F D4EO D4FF 54496 54527 Image of D400 D41F ...

Page 475: ...AM Bits 3 2 Allocation of 8000 BFFF 00 BASIC ROM 01 Internal ROM 10 External ROM 11 RAM Bit 1 Allocation of 4000 7FFF 0 BASICROM 1 RAM Bit 0 Allocation of 0000 DFFF 0 I 0 1 Character ROM See the RAM image of this register at FFOO and more details in Chapter 14 0501 0504 54529 54532 MMU Preconfiguration registers 0501 54529 Bank 0 0502 54530 Bank 1 0503 54531 Bank 14 0504 54532 All block 0 RAM exce...

Page 476: ...sed Memory Mops 469 Bit 0 Microprocessor select flag 0 Z 80 1 8502 0506 54534 RAM contiguration register 0507 0508 54535 54536 Starting location of virtual zero page 05 09 050A 54537 54538 Starting location of virtual page 1 050B 54539 System identification byte 20 for the current Commodore 128 050C 05FF 54538 54783 Not used 0600 54884 80 column chip register number port 0601 54885 80 column chip ...

Page 477: ...g keyboard scanning operations Reading from DCOO provides game port information When using joysticks Bit 4 Joystick 1 pushbutton switch 4 0 pressed 1 not pressed Bit 3 Joystick 1 switch 3 right 0 activated 1 not activated Bit 2 Joystick 1 switch 2 left Bit 1 Joystick 1 switch 1 down Bit 0 Joystick 1 switch 0 up When using paddles Bits 7 6 Select which paddie set 01 set 1 10 set 2 Bit 3 Paddle 2 pu...

Page 478: ... 0 pressed 1 not pressed Bit 3 Joystick 2 switch 3 right 0 activated 1 not activated Bit 2 Joystick 2 switch 2 left Bit 1 Joystick 2 switch 1 down Bit 0 Joystick 2 switch 0 up When using paddles Bit 3 Paddle 2 pushbutton 0 not pressed 1 pressed Bit 2 Paddle 1 pushbutton 0 not pressed 1 pressed When using the timers Bit 7 T4ner B pulse output Bit 6 Timer A pulse output DC02 56322 CIA l data directi...

Page 479: ...56327 MSB of timer DC08 DCOB 56328 56331 Time of day doek DC08 56328 Tenths of seconds DC09 56329 Seconds SDCOA 56330 Minutes DCOB 56331 Hours and AM PM Bits 3 0 hours Bit 7 AM PM flag DCOC 56332 Synchronous serial I 0 buffer DCOD 56333 CIA l IRQ controls DCOE 56334 CIA l control register A DCOF 56335 CIA l control register B DC10 DCFF 56336 56575 Images of DCOO DCFF ...

Page 480: ...S 232 C dear to send Bit 4 RS 232 C carrier detect Bit 3 RS 232 C ring indicator Bit 2 RS 232 C data terminal ready Bit 1 RS 232 C request to send Bit 0 RS 232 C data received 56578 CIA 2 data direction register for port A DD03 56579 CIA 2 data direction register for port B DD04 DD05 56580 56581 CIA 2 timer A 0004 56580 LSB of timer 0005 56581 MSB of timer DD06 DD07 56582 56583 CIA 2 timer B 0006 ...

Page 481: ...D 56589 CIA 2 IRQ controls DDOE 56590 CIA 2 control register A SDDOF 56591 CIA 2 control register B DD10 DDFF 56592 56831 Images of DDOO DDFF Character ROM Map Using the Bank 14 configuration uses DOOO through DFFF as bit mapped character ROM DOOO D3FF 53248 54271 Normal uppercase graphics character set D400 D7FF 54272 55295 Reverse uppercase graphics character set D800 DBFF 55296 56319 Normal upp...

Page 482: ...ludes the VECTOR routine described below User s pro grams should access the routine from the RESTOR Kernal at FF8A See FF8A in the Kernal jump tables for more information E05B 57435 Entry point for C128 VECTOR routine Swaps C128 veetors between user defined RAM and the Kernal vector tables at 0314 0333 User s programs should access the routine from the VECTOR Kernal at FF8D E073 E092 57459 57490 T...

Page 483: ...Kernal jump table for more information E33B 58171 Entry point fortheTALK routine Sets I 0 devicetosend data to the computer User s programs should access the routine from the TALK Kernal at FFB4 E33E 58174 Entry point for the LISTEN routine Sets I 0 device to accept data from the computer User s programs should access the routine from the LISTEN Kernal at FFB1 See FFB1 in the Kernal jump tables fo...

Page 484: ...grams should access the routine from the UNTLK Kernal at FFAB E526 58662 Entry point for the UNLSN routine Turns off the LISTEN mode User s programs should access the routine from the UNLSN Kernal at FFAE See FFAE in the Kernaljump tables for more information E5FB 58875 Entry point for the Kernal routine that sets fast disk drive I 0 User s programs should call this routine from FF47 See FF47 in t...

Page 485: ...whether default or custom should access the rou tine from the OPEN Kernal at FFCO See FFCO in the Kernal jump tables for more information F106 61702 Entry point for the CHKIN routine Opens a channel for input The system can be directed to a custom version by loading the LSB of the alternative address to Kernal vector at 031E and the MSB to 031F User s programs whether default or custom should acce...

Page 486: ...ustom should access the rou tine from the CLALL Kernal at FFE7 See FFE7 in the Kernal jump tables for more information F226 61990 Entry point for the CLRCHN routine Closes selected channels The system can be directed to a custom version by loading the LSB of the alternative address to Kernal vector at 0322 and the MSB to 0323 User s programs whether default or custom should access the rou tine fro...

Page 487: ...tlon F66E 6 l086 Entry point for the STOP routine Scans the keyboard and responds to a STOP keystroke The system can be directed toa custom version by loading the LSB of the alternative address to Kernal vector at 0328 and the MSB to 0329 User s programs whether default or custom should access the rou tine from the STOP Kernal at FFE1 See FFE1 in the Kernaljump tables for more information F731 632...

Page 488: ...ams should access the routine from the SETMSG Kernal at FF90 See FF90 in the Kernal jump tables for more information F75F 63327 Entry point for the SETMO routine Sets device timeout format User s programs should access the routine from the SETMO Kernal at FFAZ See fFFAZ in the Kernal jump tables for more information 63331 i Ent point for the MEMTOP routine Sets the highest RAM address use by BASIC...

Page 489: ...d file User s programs should access this routine from FF59 See FF59 in the Kernal jump table for more information F7A5 63397 Entry pointfora Kernal routine that does stash fetch swap and ver ify operations between C128 memory and expansion RAM User s programs should access the routine from the FF50 See more details at FF50 in the Kernal jump tables F7DO 63440 Entry point for a Kernal routine that...

Page 490: ...rnal routine that initializes a ROM cartridge and boots the disk drive User s programs should access the routine from FF56 See more details at FF56 in the Kernal jump tables F890 63632 Entry point for the Kernal routine that boots a program from the cur rent disk User s programs should access the routine from FF53 See FF53 in the Kernal jump tables for more information FA17 64023 Entry point for t...

Page 491: ...FF8D It is recommended that user s programs access this routine by execut ing an indirectjump to the NMI vector at FFFA JMP FFFA FF17 65303 IRQ Processes interrupts determined by addr ess veetors at 0314 and 0316 Those vectors and hence interrupt processing can be altered as required and later restored to the default routines by exe cuting RESTOR at FF8A See the CINV and CBINV veetors listed under...

Page 492: ...ry point actually executes a JMP E5FB FF4A FF4C 65354 65356 Kernaljump routine that doses all files opentoa specified device Procedure 1 Load the desired device number to register A 2 Call the routine JSR FF4A This entry point actually executes a JMP F23D FF4D FF4F 65357 65559 G064 Kernal Converts the system to the C64 mode without asking Procedure Jump to the routine JMP FF4D This entry point act...

Page 493: ...sh 1 fetch 2 swap 3 verify 11 Call the routine JSR FF50 This entry point actually executes JMP F7A5 f FF53 FF55 65363 65365 Kernal jump to a routine that boots a program from disk equivalent to BASIC s BOOTcommand Procedure 1 Laad the ASCII value of the drive number to register A 30 0 31 1 2 Load the value of the device number to register X 3 Call the routine JSR FF53 This entry point actually exe...

Page 494: ...e and device numbers for a designated secondary address Procedure 1 Load the desired secondary address to register A 2 Call the routine JSR FF5C 3 Read the file number in register A 4 Read the device number in register X 5 Read the secondary address in Y It invokes a FILE NOT FOUND error if the file cannot be found This entry point actually executes JMP F786 FF5F FF61 65375 65377 SWAP Kernal Each ...

Page 495: ... string address 3 Load the first of the three zero page addresses to register A 4 Load the function key number to register X 5 Load the lengthof the string to register Y 6 Call the routine JSR FF65 This entry point actually executes JMP C021 FF68 FF6A 65384 65386 Kernal jump to a routine that sets the bank contiguration for save load and verify operations Procedure 1 Use the SETNAM Kernal to set a...

Page 496: ...392 Kernal jump to a routine that does a JSR jump and return to a pro gram in any other bank Procedure 1 Load the destination bank number to 02 2 Load the MSB of the destination address to 03 3 Load the LSB of the destination address to 04 4 Carry the desired 8502 registers to the destination routine Status register to 05 Register A to 06 Register X to 07 Register Y to 08 5 Call the routine JSR FF...

Page 497: ... executes JMP 02E3 FF74 FF76 65396 65398 Kernal jump toa routine that fetches a byte from any bank In essence it executes a LDA addr Y to load register A with the indexed data Procedure 1 Laad the LSB and MSB of the target address in that order in a sequence of two zero page locations 2 Load the first of the two zero page addresses to register A 3 Laad the destination bank number to register X 4 L...

Page 498: ...the current bank It is equivalent to a CMP addr Y Procedure 1 Load the LSB and MSB of the target address in that order in a sequence of two zero page locations 2 Laad the first of the two zero page addresses to 02C8 3 Load the campare byte to register A 4 Load the destination bank number to register X 5 Load the index value to register Y 6 Call the routine JSR FF7A 7 Read the result in the process...

Page 499: ...ine JSR FF84 This entry point actually executes JMP E109 FF87 FF89 65415 65417 RAMTAS Kernal Restores default RAM allocation Procedure Call the routine JSR FF87 This entry point actually executes JMP E093 FF8A FF8C 65418 65420 RESTOR Kernal Restores all default Kernal and BASIC vectors Procedure Call the routine JSR FF8A This entry point actually executes JMP E056 FF8D 65421 VECTOR Kernal Swaps 16...

Page 500: ...8 USER ADDR 14 STOP F66E 032A USER ADDR 16 GETIN EEEB 032C USER ADDR 18 CLALL F222 032E USER ADDR IA USRCMD B006 0330 USER ADDR 1C ILOAD F26C 0332 USER ADDR 1E ISAVE F54E Procedure for transferring the user RAM version of the vector table to the standard vector tabie location 1 Load LSB of the user RAM block address to register X 2 Load MSB of the user RAM block address to register Y 3 Clear the c...

Page 501: ...s to register A 3 OR immediate with 60 4 Call SECOND This entry point actually executes JMP E4D2 FF96 65430 i TKSA Kernal Sends a secondary address to a device in TALK General procedure 1 Configure a devicetoTALK see FFB4 2 Load the secondary address to register A 3 Call TKSA This entry point actually executes JMP E4EO FF99 65433 MEMTOP Kernal Reads and sets the highest RAM address to be used for ...

Page 502: ...dress 1 Set the carry flag SEC 2 Call MEMBOT 3 Read the LSB of the address from register X 4 Read the MSB of the address from register Y Procedure for setting a bottorn RAM address 1 Load the LSB of the address to register X 2 Load the MSB of the address to register Y 3 Clear the carry flag CLC 4 CallMEMBOT This entry point actually executes JMP F772 FF9F 65439 SCNKEY Kernal Scans the keyboard and...

Page 503: ... executes JMP E43E FFA8 65448 CIOUT Kernal Sencts a byte of data from register A toa device on an open channel General procedure 1 Open a channel for LISTEN see FFB1 2 Load the byte to register A 3 Call CIOUT This entry point actually executes JMP E503 FFAB 65451 UNTLK Kernal Instructs aserial devicetostop sending data Turns off the TALK mode see FFB4 Setup procedure none This entry point actually...

Page 504: ...TALK Kernal Commands aserial devicetosend data to the computer General procedure 1 Load the device number to register A 2 Call TALK Use ACPTR FFA5 to receive data in register A and UNTLK FFAB toturn off the mode This entry point actually executes JMP E33B FFB7 65463 READST Kernal Returns the status of the last IlO operation After calling the routine register A returns the status codes This entry p...

Page 505: ...Laad the LSB of the file name string address to register X 4 Laad the MSB of the file name string address to register Y 5 Call SETNAM This entry point actually executes JMP F731 FFCO 65472 OPEN Kernal Opens a file previously defined by the SETLFS and SETNAM routines General procedure 1 Set up and execute SETNAM see Kernal FFBD 2 Set up and execute SETLFS see Kernal FFBA 3 Call OPEN This entry poin...

Page 506: ...ure 1 Set up and execute OPEN see FFCO 2 Load the file number the same one used in the previous OPEN operation to register X 3 Call CHKOUT This entry point actually executes JMP 0320 FFCC 65484 CLRCHN Kernal Clears all I 0 channels currently openandrestores the default channel configuration keyboard input screen output Procedure Call the routine JSR FFCC This entry point actually executes JMP 0322...

Page 507: ...hapter 6 and other I 0 applications in Chapter 12 This entry point actually executes JMP 0326 FFD5 65493 LOAD Kernal Loads or verifies a blockof data from an input device to a block of RAM It is normally used for loading files from cassette and disk systems General procedure 1 Specify device number file number and secondary address by executing SETLFS see FFBA 2 Specify a file name by executing SE...

Page 508: ...xecuting SETNAM see FFBD 3 Load the LSB of the starting address to Cl 193 4 Load the MSB of the starting address to C2 194 5 Load the LSB of the ending address to AE 174 6 Load the MSB of the ending address to AF 175 7 Call SAVE See Chapter 3 for more details and specific examples This entry point actually executes JMP F35E FFDB 65499 SETTIM Kernal Sets the three byte real time counter General pro...

Page 509: ...ine see FFEA If the STOP key is pressed the routine condudes with a 1 in the Z flag bit of the status register Otherwise the Z flag bit is deared to 0 General procedure 1 Call UDTIM FFEA 2 Call STOP 3 Complete the routine by using a branch statementbasedon the status of the Z flag bit BEQ or BNE See the description of the default STOP routine F66E for details on redirecting the operation to a cust...

Page 510: ... 032C FFEA 65514 UDTIM Kernal Updates the real time clocks The system normally calls this routine 60 times each secoud on an interrupt basis It is a useful programming tool only when devising custom interrupt rou tines that require doek updates Procedure Çall the routine JSR FFEA This entry point actually executes JMP F5F8 FFED 65517 SCREEN Kernal Fetches the current text screen row column pa rame...

Page 511: ...d the row number from register X 4 Read the column number from register Y See Chapter 6 for specific applications and examples This entry point actually executes JMP C018 FFF3 65523 IOBASE Kernal Returns the base or starting address of the sys tern s memory mapped IlO space General procedure 1 Call IOBASE 2 Read the LSB of the address from register X 3 Read the MSB of the address from register Y T...

Page 512: ...Memory Mops 505 FFF8 Vector to E224 FFFA Vector to NMI routine at FF05 FFFC Vector to system reset RST routine at FF3D FFFE Vector to IRQ routine at FF17 ...

Page 513: ......

Page 514: ...14 Memory Management Procedures ...

Page 515: ...m bank switching in order to take advantage of the system s full range of memory This chapter describes the banks that are currently available suggests some bank switching procedures and outlines some tech niques for swapping information between different banks The Standard Bank Contigurotions Table 14 1 summarizes the system s sixteen standard bank configura tions including the major address bloc...

Page 516: ...DOOO DFFF 53248 57343 RAM2 EOOO FEFF 57344 65279 RAM2 FFOO FF04 65280 65284 RAMO FF05 FFFF 65285 65535 RAM2 The Commodore 128 has no additional RAM allocated for RAM 2 so RAM 2 is the same as RAM 0 As a result the Bank 2 configuration is identical to Bank 0 Bank3 Address Range Hex 0000 03FF 0400 3FFF 4000 7FFF 8000 BFFF COOO CFFF DOOO DFFF EOOO FEFF FFOO FF04 FF05 FFFF Dec 0 1023 1024 16383 16384 ...

Page 517: ...57343 57344 65279 65280 65284 65285 65535 Function RAMO RAMl RAM1 Internal ROM Internal ROM IlO block Internal ROM RAMO Internal ROM Internal ROM is not shipped with the Commodore 128 An empty ROM socket is providedon the circuit board for such a device however Bank6 Address Range Hex 0000 03FF 0400 3FFF 4000 7FFF 8000 BFFF COOO CFFF DOOO DFFF EOOO FEFF FFOO FF04 FF05 FFFP Dec 0 1023 1024 16383 16...

Page 518: ... BankB Address Range Hex Dec Function 0000 03FF 0 1023 RAMO 0400 3FFF 1024 16383 RAMO 4000 7FFF 16384 32767 RAMO 8000 BFFF 32768 49151 External ROM COOO CFFF 49152 53247 External ROM DOOO DFFF 53248 57343 1 0 block EOOO FEFF 57344 65279 External ROM FFOO FF04 65280 65284 RAMO FF05 FFFF 65285 65535 External ROM Extemal RÇ M is an optional extemal program cartridge that is specifically designed for ...

Page 519: ...384 32767 RAM3 8000 BFFF 32768 49151 External ROM COOO CFFF 49152 53247 External ROM DOOO DFFF 53248 57343 IlO Block EOOO FEFF 57344 65279 External ROM FFOO FF04 65280 65284 RAMO FF05 FFFF 65285 65535 External ROM 1 The Commodore 128 has no additional RAM allocated for RAM 3 so RAM 3 is the same as RAM 1 As a result the Bank 11 configuration is identical toBank 9 2 External ROM is an optional exte...

Page 520: ...OOO DFFF 53248 57343 Character ROM EOOO FEFF 57344 65279 Kernal ROM FFOO FF04 65280 65284 RAMO FF05 FFFF 65285 65535 Kernal ROM Bank 15 Address Range Hex Dec Function 0000 03FF 0 1023 RAMO 0400 3FFF 1024 16383 RAMO 4000 7FFF 16384 32767 BASIC 7 0 ROM 8000 BFFF 32768 49151 BASIC 7 0 ROM COOO CFFF 49152 53247 Kernal ROM DOOO DFFF 53248 57343 110 Block EOOO FEFF 57344 65279 Kernal ROM FFOO FF04 65280...

Page 521: ... the same entity as Bank 1 Bank 6 is the same entity as Bank 4 Bank 7 is the same entity as Bank 5 Bank 10 is the same entity as Bank 8 Bank 11 is the same entity as Bank 9 For all practical purposes one should avoid any notion of writ ing programs that refer to Banks 2 3 6 7 10 and 11 Furthermore the Intemal ROM functions refer toa device that is not included in the Commodore 128 as it is shipped...

Page 522: ...ories A comparison of bank configurations 14 and 15 shows that the only difference is that 14 provides direct access to the character set ROM The remainder of the material in this chapter deals mainly with memory management procedures for bank configurations 0 1 14 and 15 Bank Switching Statements Registers and Procedures A number of procedures exists for switching between the standard bank config...

Page 523: ... cammand returns this sart of display from ROM 1 18000 48 45 4C 4C 4F HELLO You can confirm that the string was notsent to ROM 0 by exam ining the same address in Bank 15 by entering the F8000 monitor command Using the MMU Contiguration Register The summaries of bank configurations in Table 14 1 show a five byte segment of RAM 0 between FFOO and FF04 65280 65284 Those registers like zero page RAM ...

Page 524: ...K 0 1 2 3 MMU CONFIGURATION BYTE 0500 AND FFOO 7 6 5 0 0 0 1 1 0 1 1 COOO CFFF SEOOO SFFFF KERNAL ROM 0 INTERNAL ROM 0 EXTERNAL ROM 1 RAM 1 4 0 1 0 1 0 0 0 0 0 1 0 CHARACTER ROM 4000 7FFF 1 0 BASIC ROM RAM 8000 SBFFF BASIC ROM INTERNAL ROM EXTERNAL ROM RAM Bit 0 determines whether DOOO DFFF is used for I 0 or Char acter ROM Bank 14 is the only standard bank contiguration that uses a 1 in that loca...

Page 525: ...bits are allocated in the MMU Contiguration Register invites the possibility of setting up some potentially useful non standard bank configurations Consider the following binary value 01000000 Loading this value 40 or 64 to the MMU Configuration Regis ter produces the following non standard bank configuration 0000 03FF 0400 3FFF 4000 7FFF 8000 BFFF COOO CFFF 0000 SDFFF SEOOO SFEFF FFOO FF04 FF05 S...

Page 526: ... MMU Preconfiguration Register 2 Locations FF02 65282 0502 54530 Default value 7F 127 for Bank 1 MMU Preconfiguration Register 3 Locations FF03 65283 0503 54531 Default value 01 1 for Bank 14 The three preconfigurations serve their purpose in an unusual fashion writing ar POKEing any value to one of the registers invokes their bank configuration The write operation is what is significant Normal sy...

Page 527: ...65280 1 Method 2 POKE 65283 0 Method 3 LOA 01 STA SFFOO Method 4 STA FF03 A fourth MMU preconfiguration register perfarms the same fundion as the preceding three registers but specifies a non standard bank configuration MMU Preconfiguration Register 4 Locations SFF04 65284 0504 54532 Default value 41 65 for the following non standard bank configuration 0000 03FF 0400 3FFF 4000 7FFF 8000 SBFFF COOO...

Page 528: ...isters beginning at FFOO 65280 When Bank 1 RAM is used in conjunction with BASIC program mingin Bank 15 however you need to set a few minor limitations on how the Bank 1 contiguration can be used The difficulty is that BASIC programming which uses variables in conjunction with Bank 1 operations has to keep track of the values in a segment of the foreign RAM The default starting address for variabl...

Page 529: ...ecided to confine BASIC s usage of Bank 1 RAM to the area of 0400 0800 1 Make sure VARTAB ARYTAB and FRETOP are at the default values of 0400 2 Set STREND and MEMSIZ to the highest address to be used by BASIC 0800 for example A BASIC implementation of the procedure looks like the version in Listing 14 2 Listing 14 2 10 BA 47 20 POKE BA O POKE BA 1 16 30 POKE BA 2 0 POKE BA 3 16 40 POKE BA 4 0 POKE...

Page 530: ...ion to detail however The monitor cammand for saving a block of RAM has this gen eralform S filename 8 strtaddr endaddr where filename file name strtaddr starting address of the program endaddr ending address of the program If the program was composed in the Bank 1 configuration the starting and ending addresses must begin with a 1 digit The default bank configuration for the monitor is 0 so if yo...

Page 531: ... is BSAVE filename Bbankno Pstrtaddr TO Pendarrd where filename file name banhno bank configuration number of the block to be saved 1 in most examples cited in this chapter strtaddr decimal starting address of the block endaddr decimal ending address of the block The following example operates under BASIC s usual Bank 15 configuration but actually saves a segment of data 2048 through 2323 in the B...

Page 532: ... Contiguration Registers D500 54528 MMU configuration register determines the current bank config uration Bit 0 Content of DOOO DFFF 0 I 0 Block 1 Character ROM Bit 1 Content of 4000 7FFF 0 BASICROM 1 RAM Bits 2 and 3 Content of 8000 BFFF 00 BASIC ROM 01 Internal ROM 10 External ROM 11 RAM Bits 4 and 5 Content of COOO CFFFF and EOOO FFFF 00 Kernal ROM 01 Internal ROM 10 External ROM 11 RAM Bits 6 ...

Page 533: ...nge with the ROM based BASIC in terpreter The computer handles the situation by switching between RAM 0 and BASIC ROM The only bank configurations that can handle BASIC properly are Bank 14 and Bank 15 For most practical purposes BASIC pro grams are always executed intheBank 15 configuration This is not to say however that you cannot use a different bank contiguration in conjunction with a BASIC p...

Page 534: ... PRETOP Pointertostart of free RAM Bank 1 memory space 33 51 LSB of address 34 52 MSB of address Default address 0400 35 36 53 54 STREND Pointer toendof RAM Bank 1 BASIC string space plus 1 35 53 LSB of address 36 54 MSB of address Default address SFFOO 37 38 55 56 FRESPC Pointer to current string address in RAM Bank 1 37 55 LSB of address 38 56 MSB of address 39 3A 57 58 MEMSIZ Highest address us...

Page 535: ...ne 10 0pen the door to RAM 1 Lines 20 40 POKE letters of the alphabet to Bank 1 beginning from address 2048 Line 50 Close the door to RAM 1 and return to the Bank 15 configuration Line 60 Clear the text screen always a RAM 0 operation Line 70 Set up a FOR NEXT loop Line 80 Point to RAM 1 and get a character as C from that bank Line 90 Return to RAM 0 and POKE the character to video RAM Listing 14 ...

Page 536: ... BANK 1 REM BANK 15 REM READ FROM BANK 1 REM WRITE TOBANK 15 An alternative to POKEing bank configuration codes to the MMU configuration register is to POKE any value to the preconfig uration registers POKE 65281 0 BANK 0 POKE 65282 0 BANK 1 POKE 65283 0 BANK 14 A reference to Bank 15 is missing from that list but it happens to work into the scheme quite naturally via the MMU contiguration registe...

Page 537: ... ...

Page 538: ...A Number System Base Conversions ...

Page 539: ...no special actdressing or machine language work you will not need to be aware of hexadecimal or binary numbers Hexa decimal numbers however become quite helpful when you are doing extensive machine language programming Thus programmers who are working their way deeper into the Commodore 128 system will find themselves having to make conver sions between decimal and hexadecimal numbers and eventual...

Page 540: ...the left takes on the value from column 3 2560 The last two figures get their decimal equivalents from columns 2 and 1 48 and 15 respectively To get the true decimal value add those decimal equivalents 4096 2560 48 15 which equals 6719 In other words hexadecimal 1A3F is equal to decimal 6719 If you are converting a two place hexadecimal number use col umns 2 and 1 Hexadecimal C3 for instance is eq...

Page 541: ...ecimal number with the digit on the left being a 4 To get the next lower place value subtrad the table value 16384 from 19314 19314 16384 2930 The next lower decimal value in this case is 2816 from column 3 That turns up a Bas the next hexa decimal character So far the number is 4B Now subtrad the table value 2816 from 2930 2930 2816 114 The next lower decimal value from column 2 is 112 and its he...

Page 542: ...s Thus 04 converts to decimal4 and D2 converts to 210 The two byte version of decimal 1234 is thus 4 and 210 with 4 being the MSB and 210 being the LSB That takes care of the conversion of an ordinary decimal nuffi ber into a two byte version also in decimal Now you must POKE these numbers into decimal addresses 16787 and 16788 If you place the LSB of the two byte number into the lower numbered ad...

Page 543: ... conversions are carried out with one byte or eight bit binary numbers although sametimes you need to do the conversion from two byte 16 bit numbers Figure A 2 shows the breakdown of an eight bit binary number The positions are labeled 0 through 7 with zero indicating the least significant bit position Each of those eight bit locations contains either a 0 or a 1 MSB LSB Suppose that you want to PO...

Page 544: ... operations All you have to do is group the binary number into sets of four bits each beginning with the least significant bit Then find the hexadecimal value for each group Table A 3 helps with the latter operation Suppose the binary number is 10011101 There are two sets of four bits or nibbles here 1001 and 1101 The hexadecimal equivalent is 9 for the first set and D for the second set as Table ...

Page 545: ... idea is to convert the decimal number to its hexa decimal counterpart as described earlier in this appendix Then con vert the hexadecimal characters to their binary versions as described in the previous section As an example convert 1234 decimal to binary First as described earlier calculate the hexadecimal version of decimal 1234 Your answer should come out to 04D2 That hexadecimal number expres...

Page 546: ...19 13 00010011 67 43 01000011 20 14 00010100 68 44 01000100 21 15 00010101 69 45 01000101 22 16 00010110 70 46 01000110 23 17 00010111 71 47 01000111 24 18 00011000 72 48 01001000 25 19 00011001 73 49 01001001 26 lA 00011010 74 4A 01001010 27 1B 00011011 75 4B 01001011 28 1C 00011100 76 4C 01001100 29 1D 00011101 77 4D 01001101 30 1E 00011110 78 4E 01001110 31 1F 00011111 79 4F 01001111 32 20 0010...

Page 547: ...116 74 01110100 164 A4 10100100 117 75 01110101 165 A5 10100101 118 76 01110110 166 A6 10100110 119 77 01110111 167 A7 10100111 120 78 01111000 168 A8 10101000 121 79 01111001 169 A9 10101001 122 7A 01111010 170 AA 10101010 123 7B 01111011 171 AB 10101011 124 7C 01111100 172 AC 10101100 125 7D 01111101 173 AD 10101101 126 7E 01111110 174 AE 10101110 127 7F 01111111 175 AF 10101111 128 80 10000000 ...

Page 548: ... 204 CC 11001100 236 EC 11101100 205 CD 11001101 237 ED 11101101 206 CE 11001110 238 EE 11101110 207 CF 11001111 239 EF 11101111 208 DO 11010000 240 FO 11110000 209 Dl 11010001 241 Fl 11110001 210 D2 11010010 242 F2 11110010 211 D3 11010011 243 F3 11110011 212 D4 11010100 244 F4 11110100 213 D5 11010101 245 F5 11110101 214 D6 11010110 246 F6 11110110 215 D7 11010111 247 F7 11110111 216 D8 11011000...

Page 549: ......

Page 550: ...B Derived Trigonometrie Functions ...

Page 551: ...otangent Inverse hyperbalie sine Inverse hyperbalie eosine Inverse hyperbalie tangent Inverse hyperbalie secant Inverse hyperbalie casecant Inverse hyperbalie cotangent Equivalent 1 COS X 1 SIN X 1 TAN X ATN X SQR l X X k ATN X SQR l X X ATN SQR X X l SGN X l k ATN l SQR X X 1 SGN X 1 k ATN X k EXP X EXP X 2 EXP X EXP X 2 EXP X EXP X EXP X EXP X 2 EXP X EXP X 2 EXP X EXP X EXP X EXP X EXP X EXP X ...

Page 552: ...nes reserved variables for 102 3 familiarity with ix files open not to exceed 10 101 formats tokenized 106 10 general RAM usage of 1208 121A 442 43 jump veetors for 443 53 line numbers not to exeeed 63999 in 99 101 operations and programming procedures 23 110 operators 34 43 pointers to allocate Bank 1 RAM in 521 23 preeedencein 41 43 quotation marks to enclose a constant in 26 27 28 RAM addresses...

Page 553: ...nd their codes 264 67 colors for the 231 32 normal inverse format in 229 31 RAM based 269 71 ROM map of 474 75 switching 224 29 text 219 CHAR statement 49 241 42 Checksurn errors 116 17 CHKIN FFC6 routine 115 434 478 CHKOUT SFFC9 routine 115 435 478 CHRIN FFCF routine 115 435 478 CHROUT FFD2 routine 115 219 220 262 63 CHR function 49 50 CIA 1 device for peripherals 394 456 470 74 Circles and arcs ...

Page 554: ...19 Directory disk commands 170 displaying a 18 19 49 56 119 21 errors with the 118 organization of the 159 structuring a 119 Disk to mark splat files on a 85 backing up a 45 46 booting a 48 483 486 bytes on a 153 cleaning up a 140 43 clearing channels on a 54 closing selected files on a 54 camparing a file in memory with a file on 169 70 copying a file on 138 40 208 9 copying a file to the same 53...

Page 555: ... programs and files errors pertaining to 98 99 Kernal subroutine to set the 498 shown in the disk directory 19 FILESPEC CP M command 210 11 FILTER statement 61 62 362 Fire pushbutton on the joystick 394 95 398 400 Floating point notation 25 Floating point real values in numeric variables 30 FN statement See DEF FN function Formatting a disk 19 20 FOR NEXT statement 62 63 100 40 column text screen ...

Page 556: ...operations 499 500 jump toanother routine by 489 92 keyboard scanned for key pressed by 495 96 loading flles with 137 38 restoring the default function key assignments with 392 saving files with 129 30 vector swap 492 93 Keyboard abbreviations of BASIC operations 92 96 Keyboard unit of a Commodore 128 2 alphabetic keys on the 8 9 buffer main 387 89 440 502 3 custom windows set from the 246 ESC CON...

Page 557: ...C 28 30 0 ON GOSUB statement 73 74 ON GOTO statement 74 OPEN statement 74 75 114 123 24 154 402 3 407 10 478 OPEN FFCO routine 115 124 434 Operating modes 2 4 8 See also C128 mode CP M mode and C64mode Operating procedures for the Commodore 128 genera 1 21 DRA instruction 193 OR operator 75 Overheating problems caused by blocked air vents 2 p Paddie peripherals for the Commodore 128 See Game paddi...

Page 558: ...3 Kernal jump tables and hardware veetors FF47 FFFF 485 505 map 474 75 memory management registers FFOO FF04 484 screen editor 453 56 ROR instruction 195 RSPCOLOR function 82 RSPOS function 82 RSPRITE function 82 RS 232 C communications ix 406 14 438 40 441 42 RTI instruction 196 RTS instruction 196 RUN command 83 134 35 RUN STOP key 13 14 16 119 320 RWINDOW function 83 s SAVE CP M command 209 SAV...

Page 559: ...ction 89 TAN function 89 TAX instruction 199 TAY instruction 199 Television used as a display unit 2 TEMPO statement 89 357 58 TEST DEMO DISKETTE 143 44 Text ASCII files for 130 32 character sets 219 column formats for 216 18 cursor and screen control 219 20 504 erasing operations 253 55 extended color mode for some 238 41 files 112 144 52 inserting or deleting with the INST DEL key 14 15 plotting...

Page 560: ...s 120 21 Wildcard characters cont syntax errors with 117 Wildcard string 120 Wmdow registers 248 50 Window s text default 249 definition of 243 location of 92 218 241 42 registers to set 248 49 setting alternative 243 50 Index 553 WINDOW statement 92 244 45 x XOR Boolean operator 92 XREF CP M command 210 z Z 80 environment CPIM in a ix debuggerforthe 211 Zero page addresses 416 31 526 ...

Page 561: ...such human functions as reasoning creativity problem solving verbal communication and game planning Sample programs furnished ISBN 0 672 21785 6 9 95 D Computer Graphics User s Guide Andrew S G assner This is your idea book for using computer generated high res imagery for fun and profit Subjects include basic geometry fundamental computing turning your ideas into pictures and ways to transfer the...

Page 562: ...th tips for monoging all 128K of memory You don t have to know the quirks of the Commodore 64 or other Commodore machines to make full use of the information in these pages With a Commodore 128 and this book you are ready to explore all the possibilities Commodore 128 Reference Guide for Progrommers is a must for your computer bookshelf David L Heiserman hos been a freelance writer since 1968 He i...

Reviews: