Apple® Ile Technical Reference Manual A VV Addison-Wesley Publishing Company, Inc. Reading, Massachusetts Menlo Park, California Don Mills, Ontario Wokingham, England Amsterdam Sydney Singapore Tokyc Mexico City Bogota Santiago San Juan Copyright © 1985 by Apple Computer, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Published simultaneously in Canada. ISBN 0-201-17720-X ABCDEFGHIJ-DO-898765 First printing, July 1985 Apple® Ile Technical Reference Manual Contents List of Figures and Tables XViil Radio and Television Interference XXV PREFACE About This Manual XXVIl Contents of This Manual xxvii The Enhanced Apple Ile xxix Physical Changes xxix Startup Drives xxix Video Firmware Xxx Video Enchancements xxx Applesoft 80-Column Support xxx Applesoft Lowercase Support xxxi Apple II Pascal xxxi System Monitor Enhancements xxxi Interrupt Handling xxxi Symbols Used in This Manual xxxii CHAPTER 1 Introduction l Removing the Cover 2 The Keyboard 3 The Speaker 3 The Power Supply 4 The Circuit Board 4 Connectors on the Circuit Board 6 Connectors on the Back Panel 8 Contents CHAPTER 2 Built-in 1/O Devices The Keyboard 10 Reading the Keyboard 12 The Video Display Generator 16 Text Modes 18 Text Character Sets 19 40-Column Versus 80-Column Text 20 Graphics Modes 22 Low-Resolution Graphics 22 High-Resolution Graphics 23 Double-High-Resolution Graphics 25 Video Display Pages 26 Display Mode Switching 28 Addressing Display Pages Directly 30 Secondary Inputs and Outputs 37 The Speaker 37 Cassette Input and Output 38 The Hand Control Connector Signals 39 Annunciator Outputs 40 Strobe Output 40 Switch Inputs 41 Analog Inputs 42 Summary of Secondary I/O Locations 42 Contents CHAPTER 3 Built-in 1/O Firmware 45 Using the I/O Subroutines 47 Apple II Compatibility 48 The 80-Column Firmware 49 The Old Monitor 50 The Standard 1/O Links 50 Standard Output Features 51 COUT Output Subroutine 51 Control Characters With COUT1 and BASICOUT 52 The Stop-List Feature 54 The Text Window 54 Inverse and Flashing Text 56 Standard Input Features 57 RDKEY Input Subroutine 57 KEYIN Input Subroutine 58 Escape Codes 58 Cursor Motion in Escape Mode 58 GETLN Input Subroutine 60 Editing With GETLN 61 Cancel Line 61 Backspace 61 Retype 62 Monitor Firmware Support 62 BASICOUT 63 CLREOL 63 CLEOLZ 64 CLREOP 64 CLRSCR 64 v] Contents CLRTOP 64 COUT 64 COUT1 64 CROUT 64 CROUT1 65 HLINE 65 HOME 65 PLOT 65 PRBL2 65 PRBYTE 65 PRERR 65 PRHEX 66 PRNTAX 66 SCRN 66 SETCOL 66 VTABZ 66 VLINE 66 I/O Firmware Support 67 PINIT 67 PREAD 67 PWRITE 68 PSTATUS 69 Contents Vil CHAPTER 4 Memory Organization (gl Main Memory Map 72 RAM Memory Allocation 74 Reserved Memory Pages 75 Page Zero 75 The 65C02 Stack 75 The Input Buffer 76 Link-Address Storage 76 The Display Buffers 76 Bank-Switched Memory 79 Setting Bank Switches 80 Reading Bank Switches 83 Auxiliary Memory and Firmware 84 Memory Mode Switching 86 Auxiliary-Memory Subroutines 88 Moving Data to Auxiliary Memory 89 Transferring Control to Auxiliary Memory 90 The Reset Routine 91 The Cold-Start Procedure 92 The Warm-Start Procedure 92 Forced Cold Start 98 The Reset Vector 93 Automatic Self-Test 95 Vili Contents CHAPTER 5 Using the Monitor 97 Invoking the Monitor 98 Syntax of Monitor Commands 99 Monitor Memory Commands 100 Examining Memory Contents 100 Memory Dump 100 Changing Memory Contents 103 Changing One Byte 103 Changing Consecutive Locations 104 ASCII Input Mode 104 Moving Datain Memory 105 Comparing Data in Memory 107 Searching for Bytes in Memory 108 Examining and Changing Registers 108 Monitor Cassette Tape Commands 109 saving Dataon Tape 109 Reading Data From Tape 110 Miscellaneous Monitor Commands 112 Inverse and Normal Display 112 Back to BASIC 112 Redirecting Input and Output 113 Hexadecimal Arithmetic 114 Special Tricks With the Monitor 114 Multiple Commands 114 Filling Memory 115 Repeating Commands 116 Creating YourOwn Commands 117 Contents ix Machine-Language Programs 118 Running a Program 118 Disassembled Programs 119 The Mini-Assembler 121 Starting the Mini-Assembler 121 Restrictions 121 Using the Mini-Assembler 122 Mini-Assembler Instruction Formats 124 Summary of Monitor Commands 125 Examining Memory 125 Changing the Contents of Memory 126 Moving and Comparing 126 The Examine Command 126 The Search Command 126 Cassette Tape Commands 126 Miscellaneous Monitor Commands 127 Running and Listing Programs 127 The Mini-Assembler 128 CHAPTER 6 Programming for Peripheral Cards Peripheral-Card Memory Spaces 180 Peripheral-Card1/O Space 130 Peripheral-Card ROM Space 1381 Expansion ROM Space 132 Peripheral-Card RAM Space 184 Xx Contents I/O Programming Suggestions 185 Finding the Slot Number With ROM Switched In 186 [/O Addressing 136 RAM Addressing 1388 Changing the Standard I/O Links 1389 Other Uses of 1/0 Memory Space 140 Switching I/O Memory 141 Developing Cards for Slot 3 148 Pascal 1.1 Firmware Protocol 144 Device Identification 144 I/O Routine Entry Points 145 Interrupts on the Enhanced Apple Ile 146 What Is an Interrupt? 147 Interrupts on Apple Ile Series Computers 148 Rules of the Interrupt Handler 149 Interrupt Handling on the 65C02 and 6502 150 The Interrupt Vector at $FFFE 150 The Built-in Interrupt Handler 151 Saving the Apple Ile’s Memory Configuration 152 Managing Main and Auxiliary Stacks 152 The User’s Interrupt Handler at $3FE 154 Handling Break Instructions 155 Interrupt Differences: Apple Ile Versus Apple IIc 156 Contents X] CHAPTER 7 Hardware Implementation Environmental Specifications 158 The Power Supply 159 The Power Connector 161 The 65C02 Microprocessor 161 65C02 Timing 162 The Custom Integrated Circuits 164 The Memory Management Unit 164 The Input/Output Unit 166 The PAL Device 168 Memory Addressing 168 ROM Addressing 169 RAM Adaressing 170 Dynamic-RAM Refreshment 170 Dynamic-RAM Timing 171 The Video Display 173 The Video Counters 174 Display Memory Addressing 175 Display Address Mapping 176 Video Display Modes 179 Text Displays 179 Low-Resolution Display 182 High-Resolution Display 188 Double-High-Resolution Display 185 Video Output Signals 186 xii Contents Built-in I/O Circuits 187 The Keyboard 187 Connecting a Keypad 188 Cassette 1/O 189 The Speaker 189 Game 1/0 Signals 190 Expanding the Apple Ile 192 The Expansion Slots 192 The Peripheral Address Bus 192 The Peripheral Data Bus 193 Loading and Driving Rules 193 Interrupt and DMA Daisy Chains 193 Auxiliary Slot 197 80-Column Display Signals 197 APPENDIX A The 65C02 Microprocessor 205 Differences Between 6502 and 65C02 206 Different Cycle Times 206 Different Instruction Results 207 Data Sheet 207 APPENDIX B Directory of Built-in Subroutines 217 Contents Xill APPENDIX C Apple II Family Differences AS Keyboard 226 Apple Keys 226 Character Sets 226 80-Column Display 227 Escape Codes and Control Characters 227 Built-in Language Card 227 Auxiliary Memory 228 Auxiliary Slot 228 Back Panel and Connectors 228 Soft Switches 228 Built-in Self-Test 229 Forced Reset 229 Interrupt Handling 229 Vertical Sync for Animators 229 Signature Byte 230 Hardware Implementation 230 APPENDIX D Operating Systems and Languages 231 Operating Systems 282 ProDOS 282 DOS 3.3 282 Pascal Operatiing System 232 CP/M 233 X1V Contents Languages 233 Assembly Language 233 Applesoft BASIC 233 Interger BASIC 238 Pascal Language 234 FORTRAN 284 APPENDIX E Conversion Tables Bits and Bytes 236 Hexadecimal and Decimal 238 Hexadecimal and Negative Decimal 240 Graphics Bits and Pieces 242 Eight-Bit Code Conversions 244 APPENDIX F Frequently Used Tables 208 APPENDIX G Using an 80-Column Text Card 267 Starting Up With Pascalor CP/M 268 Starting Up With ProDOS or DOS 3.8 269 Using the GET Command 269 When to Switch Modes Versus When to Deactivate 270 Display Features With the Text Card 270 INVERSE, FLASH, NORMAL, HOME 270 Contents XV Tabbing With the Original Apple IIe 271 Comma Tabbing With the Original Apple Ile 271 HTAB and POKE 1403 272 Using Control-Characters With the Card 272 Control Characters and Their Functions 273 How to Use Control-Character Codes in Programs 274 A Word of Caution to Pascal Programmers 275 APPENDIX H Programming With the Super Serial Card 277 Locating the Card 278 Operating Modes 278 Operating Commands 279 The Command Character 280 Baud Rate, nB 280 Data Format, nD 281 Parity, nP 281 Set Time Delay, nC, nL, andnF 282 Echo Characters to the Screen, E_E/D 288 Automatic Carriage Return, C 2838 Automatic Line Feed, LE/D 284 Mask Line Feed In, M_E/D 284 Reset Card, R 284 Specify Screen Slot, S 284 Translate Lowercase Characters, nT 284 Suppress Control Characters, Z 285 Find Keyboard, F_E/D 285 XOFF Recognition, X_E/D 286 Tab in BASIC, T_E/D 286 Xvi Contents Terminal Mode 286 Entering Terminal Mode, T 286 Transmitting a Break, B 287 Special Characters, S_E/D 287 Quitting Terminal Mode, Q 287 SSC Error Codes 287 The ACIA 289 SSC Firmware Memory Use 289 Zero-Page Location 290 Peripheral Card 1/O Space 290 Scratchpad RAM Location 292 APPENDIX | Monitor ROM Listing 293 Glossary olf Bibliography 399 Index 401 Tell Apple Card Contents XVll Figures and Tables CHAPTER 1 Introduction Figure 1-1 Removing the Cover 2 Figure 1-2 The Apple Ile With the Cover Off 2 Figure 1-3 The Apple Ile Keyboard 3 Figure 1-4 The Circuit Board 5 Figure 1-5 The Expansion Slots 7 Figure 1-6 The Auxiliary Slot 7 Figure 1-7 The Back Panel Connectors 8 CHAPTER 2 Built-in I/O Devices Figure 2-1 The Keyboard 11 Table 2-1 Apple Ile Keyboard Specifications 11 Table 2-2 Keyboard Memory Locations 12 Table 2-3 Keys and ASCII Codes 14 Table 2-4 Video Display Specifications 17 Table 2-5 Display Character Sets 20 Figure 2-2 40-Column Text Display 21 Figure 2-3 80-Column Text Display 21 Table 2-6 Low-Resolution Graphics Colors 28 Figure 2-4 High-Resolution Display Bits 24 Table 2-7 High-Resolution Graphics Colors 25 Table 2-8 Double-High-Resolution Grahics Colors 26 Table 2-9 Video Display Page Locations 28 Table 2-10 Display Soft Switches 29 Figure 2-5 Map of 40-Column Text Display 32 Figure 2-6 Map of 80-Column Text Display 33 Figure 2-7 Map of Low-Resolution Graphics Display 34 XV Figures and Tables Figure 2-8 Map of High-Resolution Graphics Display 35 Figure 2-9 Map of Double-High-Resolution Graphics Display 36 Table 2-11 Annunciator Memory Locations 40 Table 2-12 Secondary I/O Memory Location 48 CHAPTER 3 Built-in 1/O Firmware 45 Table 3-1 Monitor Firmware Routines 46 Table 3-2 Apple II Mode 48 Table 3-3a Control Characters With 80-Column Firmware Off 52 Table 3-3b Control Characters With 80-Column Firmware On 52 Table 3-4 Text Window Memory Locations 55 Table 3-5 Text Format Control Values 56 Table 3-6 Escape Codes 59 Table 3-7 Prompt Characters 60 Table 3-8 Video Firmware Routines 62 Table 3-9 Port 3 Firmware Protocol Table 67 Table 3-10 Pascal Video Control Functions 68 CHAPTER 4 Memory Organization fal Figure 4-] System Memory Map 73 Figure 4-2 RAM Allocation Map 74 Table 4-1 Monitor Zero-Page Use 77 Table 4-2 Applesoft Zero-Page Use 77 Table 4-3 Integer BASIC Zero-Page Use 78 Table 4-4 DOS 3.3 Zero-Page Use 78 Table 4-5 ProDOS MLI and Disk-Driver Zero-Page Use 79 Figures and Tables xix Figure 4-38 Bank-Switched Memory Map 80 Table 4-6 Bank Select Switches 82 Figure 4-4 Memory Map With Auxiliary Memory 85 Table 4-7 Auxiliary-Memory Select Switches 87 Table 4-8 48K RAM Transfer Routines 88 Table 4-9 Parameters for AUXMOVE Routine 89 Table 4-10 Parameters for XFER Routine 90 Table 4-11 Page 3 Vectors 94 CHAPTER 5 Using the Monitor 97 Table 5-1 Mini-Assembler Address Formats 124 CHAPTER 6 Programming for Peripheral Cards 129 Table 6-1 Peripheral-Card I/O Memory Locations Enabled by DEVICE SELECT’ 181 Table 6-2 Peripheral-Card ROM Memory Locations Enabled by I/O SELECT’ 1382 Figure 6-1 Expansion ROM Enable Circuit 133 Figure 6-2 ROM Disable Address Decoding 183 Table 6-3 Peripheral-Card RAM Memory Locations 134 Table 6-4 Peripheral-Card I/O Base Addresses 137 Figure 6-3 I/O Memory Map 141 Table 6-5 I/O Memory Switches 142 Table 6-6 Perpheral-Card Device-Class Assignments 144 Table 6-7 I/O Routine Offsets and Registers Under Pascal 1.1 Protocol 146 XX Figures and Tables Figure 6-4 Interrupt Handling Sequence 151 Table 6-8 BRK Handler Information 155 Table 6-9 Memory Configuration Information 155 CHAPTER 7 Hardware Implementation Vat Table 7-1 Summary of Environmental Specifications 158 Table 7-2 Power Supply Specifications 159 Table 7-3 Power Connector Signal Specifications 161 Table 7-4 65C02 Microprocessor Specifications 162 Table 7-5 65C02 Timing Signal Descriptions 163 Figure 7-1 65C02 Timing Signals 163 Figure 7-2 The MMU Pinouts 165 Table 7-6 The MMU Signal Descriptions 165 Figure 7-3 The IOU Pinouts 167 Table 7-7 The IOU Signal Descriptions 167 Figure 7-4 The PAL Pinouts 168 Table 7-8 The PAL Signal Descriptions 168 Figure 7-5 The 2364 ROM Pinouts 169 Figure 7-6 The 2316 ROM Pinouts 169 Figure 7-7 The 23383 ROM Pinouts 169 Figure 7-8 The 64K RAM Pinouts 170 Table 7-9 RAM Address Multiplexing 171 Figure 7-9 RAM Timing Signals 172 Table 7-10 RAM Timing Signal Descriptions 173 Table 7-11 Display Address Transformation 176 Figure 7-10 4)-Column Text Display Memory 177 Table 7-12 Display Memory Addressing 178 Figures and Tables Table 7-13 Memory Address Bits for Display Modes 178 Figure 7-lla 7 MHz Video Timing Signals 180 Figure 7-11b 14 MHz Video Timing Signals 181 Table 7-14 Character-Generator Control Signals 182 Table 7-15 Internal Video Connector Signals 186 Table 7-16 Keyboard Connector Signals 188 Table 7-17 Keypad Connector Signals 188 Table 7-18 Speaker Connector Signals 189 Table 7-19 Game I/O Connector Signals 191 Figure 7-12 Peripheral-Signal Timing 194 Table 7-20 Expansion Slot Signals 195 Table 7-21 Auxiliary Slot Signals 198 Figure 7-18 Schematic Diagram 200 APPENDIX A The 65C02 Microprocessor 205 Table A-1 Cycle Time Differences 206 APPENDIX i Conversion Tables 200 Table E-1 What a Bit Can Represent 236 Figure E-1 Bits, Nibbles, and Bytes 237 Table E-2 Hexadecimal/Decimal Conversion 238 Table E-3 Hexadecimal to Negative Decimal Conversion 240 Table E-4 Hexadecimal Values for High-Resolution Dot Patterns 242 Table E-5 Control Characters, High Bit Off 245 Table E-6 Special Characters, High Bit Off 246 XXll Figures and Tables Table E-7 Uppercase Characters, High Bit Off 247 Table E-8 Lowercase Characters, High Bit Off 248 Table E-9 Control Characters, High Bit On 249 Table K-10 Special Characters, High Bit On 250 Table E-11 Uppercase Characters, High Bit On 251 Table E-12 Lowercase Characters, High Bit On 252 APPENDIX F Frequently Used Tables 200 Table 2-3 Keys and ASCII Codes 254 Table 2-2 Keyboard Memory Location 255 Table 2-4 Video Display Specifications 256 Table 2-8 Double-High-Resolution Graphics Colors 257 Table 2-9 Video Display Page Locations 257 Table 2-10 Display Soft Switches 258 Table 3-1 Monitor Firmware Routines 259 Table 3-3a Control Characters With 80-Column Firmware Off 260 Table 3-3b Control Characters With 80-Column Firmware On 260 Table 3-5 Text Format Control Values 261 Table 3-6 Escape Codes 262 Table 3-10 Pascal Video Control Functions 263 Table 4-6 Bank Select Switches 264 Table 4-7 Auxiliary-Memory Select Switches 265 Table 4-8 48K RAM Transfer Routines 265 Table 6-5 1/0 Memory Switches 266 Table 6-6 1/0 Routine Offsets and Registers Under Pascal 1.1 Protocol 266 Figures and Tables XXlll APPENDIX G Using an 80-Column Text Card 267 Table G-1 Control Characters With 80-Column Firmware On 273 APPENDIX H Programming With the Super Serial Card 217 Table H-1 Baud Rate Selections 280 Table H-2 Data Format Selections 281 Table H-3 Parity Selections 281 Table H-4 Time Delay Selections 282 Table H-6 Lowercase Character Display Options 285 Table H-6 STSBYTE Bit Definitions 287 Table H-7 Error Codes and Bits 288 Table H-8 Memory Use Map 289 Table H-9 Zero-Page Locations Used by the SSC 290 Table H-10 Address Register Bits Interpretation 291 Table H-11 Scratchpad RAM Locations Used by the SSC 292 XXIV Figures and Tables Radio and Television Interference The equipment described in this manual generates and uses radio-frequency energy. If it is not installed and used properly—that is, in strict accordance with our instructions—it may cause interference with radio and television reception. This equipment has been tested and complies with the limits for a Class B computing device in accordance with the specifications in Subpart J, Part 15, of FCC rules. These rules are designed to provide reasonable protection against such interference in a residential installation. However, there is no guarantee that the interference will not occur in a particular installation, especially if a “rabbit ear” television antenna is used. (A “rabbit ear” antenna is the telescoping-rod type usually contained on television receivers.) You can determine whether your computer is causing interference by turning it off. If the interference stops, it was probably caused by the computer or its peripherals. To further isolate the problem, disconnect the peripheral devices and their input/output cables one at a time. If the interference stops, it was caused by either the peripheral device or the I/O cable. These devices usually require shielded I/O cables. For Apple A shielded cable is a cable that uses a peripherals, you can obtain the proper shielded cable from your dealer. metallic wrap aroun d the wires to reduce For non-Apple peripheral devices, contact the manufacturer or dealer for the potential effects of radio frequency assistance. interference. If your computer does cause interference to radio or television reception, you can try to correct the interference by using one or more of the following measures: o Turn the television or radio antenna until the interference stops. O Move the computer to one side or the other of the television or radio. O Move the computer farther away from the television or radio. Radio and Television Interference XXV oO Plug the computer into an outlet that is on a different circuit than the television or radio. (That is, make certain the computer and the radio or television set are on circuits controlled by different circuit breakers or fuses.) O Consider installing a rooftop television antenna with coaxial cable lead-in between the antenna and television. If necessary, you should consult your Apple-authorized dealer or an experienced radio/television technician for additional suggestions. XXVl Radio and Television Interference Preface About This Manual This is the reference manual for the Apple Ile personal computer. It contains detailed descriptions of all of the hardware and firmware that make up the Apple Ile and provides the technical information that peripheral-card designers and programmers need. This manual contains a lot of information about the way the Apple Ile works, but it doesn’t tell you how to use the Apple Ile. For this, you should read the other Apple Ile manuals, especially the following: Oo Apple Ile Owner’s Manual oO The Applesoft Tutorial Contents of This Manual Tee SSS a ee a ea ae he Ce ae ee we The material in this manual is presented roughly in order of increasing intimacy with the hardware; the farther you go in the manual, the more technical the material becomes. The main subject areas are oO introduction: Preface and Chapter 1 o use of built-in features: Chapters 2 and 3 O how the memory is organized: Chapter 4 O information for programmers: Chapters 5 and 6 O hardware implementation: Chapter 7 O additional information: appendixes, glossary, and bibliography. Chapter 1 identifies the main parts of the Apple Ile and tells where in the manual each part is described. The next two chapters describe the built-in input and output features of the Apple Ile. This part of the manual includes information you need for low-level programming on the Apple Ile. Chapter 2 describes the built-in 1/0 features and Chapter 8 tells you how to use the firmware that supports them. Contents of This Manual XXV1l Chapter 4 describes the way the Apple IIe’s memory space is organized, including the allocation of programmable memory for the video display buffers. Chapter 5 is a user manual for the Monitor that is included in the built-in firmware. The Monitor is a system program that you can use for program debugging at the machine level. Chapter 6 describes the programmable features of the peripheral-card connectors and gives guidelines for their use. It also describes interrupt programming on the Apple Ile. Chapter 7 is a description of the hardware that implements the features described in the earlier chapters. This information is included primarily for programmers and peripheral-card designers, but it will also help you if you just want to understand more about the way the Apple Ile works. Additional reference information appears in the appendixes. Appendix A is the manufacturer’s description of the Apple Ile’s microprocessor. Appendix B is a directory of the built-in I/O subroutines, including their functions and starting addresses. Appendix C describes differences among Apple II family members. Appendix D describes some of the operating systems and languages supported by Apple Computer for the Apple Ile. Appendix E contains conversion tables of interest to programmers. Appendix F contains additional copies of some of the tables that appear in the body of the manual. The ones you will need to refer to often are duplicated here for easy reference. Appendix G contains information about using Apple Ile 80-column text cards with the Apple Ile and high level languages. Appendix H discusses programming on the Apple Ile with the Apple Super Serial Card. Appendix I|contains the source listing of the Monitor firmware. You can refer to it to find out more about the operation of the Monitor subroutines listed in Appendix B. Following Appendix I is a glossary defining many of the technical terms used in this manual. Some terms that describe the use of the Apple Ile are defined in the glossaries of the other manuals listed earlier. Following the glossary, there is a selected bibliography of sources of additional information. XXVIli Preface: About. This Manual The Enhanced Apple lle TO EES SS a ae ee ee ee ee ee eee) Changes have been made in the Apple Ile since the original version was introduced. The new version is called the enhanced Apple Ile and is described in this manual. Where there are differences in the original Apple Ile compared with the enhanced Apple Ile, they will be called out in the manual. Otherwise, the two machines operate identically. You can tell whether you have an original or enhanced Apple Ile when you start up the system. An original Apple [le will display Apple 1¢ at the top of the monitor screen, while an enhanced Apple Ile will display Apple //e. The changes embodied in the enhanced Apple IIe are described in the following sections of this preface. Physical Changes SaaS ee The enhanced Apple Ile includes the following changes from the original Apple Ile: Oo The 65C02 microprocessor, which is a new version of the 6502 microprocessor found in the original Apple Ile. The 65C02 uses less Opcode is short for operation code and is power, has 27 new opcodes, and runs at the same speed as the 6502. used to describe the basic instructions (See Chapter 7 and Appendix A.) eons meena eis aMer o Anew video ROM containing the same MouseText characters found in the Apple IIc. (See Chapter 2. ) oc New Monitor ROMs (the CD and EF ROMs) containing the enhanced Apple Ile firmware. (See Chapter 5.) co The identification byte at $FBCO has been changed. In the original Apple Ile it was $A (decimal 234), in the enhanced Apple Ile it is $E0 (decimal 224). Startup Drives You can use startup (boot) devices other than a Disk II to start up ProDOS on the enhanced Apple Ile. Apple II Pascal versions 1.3 and later may start up from slots 4, 5, or 6 on a Disk II, ProFile, or other Apple II disk drive. Apple II Pascal versions 1.0 through 1.2 must start up from a Disk II in slot 6. DOS 3.38 may be started from a Disk II in any slot. The Enhanced Apple Ile x When you turn on your Apple Ile, it searches for a disk drive controller to start up from, beginning with slot 7 and working down toward slot 1. As soon as a disk controller card is found, the Apple Ile will try to load and execute the operating system found on the disk. If the drive is not a Disk II, then the operating system of the startup volume must be either ProDOS or Apple II Pascal (version 1.3 or later). If it is a Disk II, then the startup volume may be any Apple II operating system. Video Firmware i er re) The enhanced Apple Ile has improved 80-column firmware: oO The enhanced Apple Ile now supports lowercase input. Oo [E] passes most control characters to the screen. oO traps most control characters before they get to the screen. Oo [R] was removed because uppercase characters are no longer required by Applesoft. Video Enhancements Both 80-column Pascal and 80-column mode Applesoft output are faster than before and scrolling is smoother. 40-column Pascal performance is unchanged. In the original Apple IIe, characters echoed to COUT1 during 80-column operation were printed in every other column; the enhanced Apple Ile firmware now prints the characters in each column. Applesoft 80-Column Support Se ee en eee The following Applesoft routines now work in 80-column mode: oO HTAB oO TAB oO SPC oO Comma tabbing in PRINT statements XXX Preface: About This Manual Applesoft Lowercase Support SS ee ee ee ee ee ater eaet Applesoft now lets you do all your programming in lowercase. When you list your programs, all Applesoft keywords and variable names automatically are in uppercase characters; literal strings and the contents of DATA and REM statements are unchanged. Appie Il Pascal EEE SS ee Apple II Pascal (version 1.2 and later) can now use a ProFile hard disk through the Pascal ProFile Manager. To find out more, see the Pascal ProFile The Pascal 1.1 firmware no longer supports the control character that Manager Manual. switches from 80-column to 40-column operation. This control character is no longer supported because it can put Pascal in a condition where the exact memory configuration is not known. System Monitor Enhancements Enhancements to the Apple Ile’s built-in Monitor (described in Chapter 5 in this manual) include the following: O lowercase input O ASCII input mode oO Monitor Search command oO the Mini-Assembler Interrupt Handling SS SSS SS SS Interrupt handler support in the enhanced Apple Ile firmware now handles any Apple Ile memory configuration. The Enhanced Apple [le XXX] Symbols Used in This Manual 0 See ee ee ee ee ee eS as Special text in this manual is set off in several different ways, as shown in these examples. AWarning |Important warnings appear in red like this. These flag potential danger to the Apple Ile, its software, or you. Important! The information here is important, but non-threatening. The ways in which the original Apple Ile differs from the enhanced Apple IIe are called out this way with the tag Original IIe in the margin. By the Way: Information that is useful but is incidental to the text is set off like this. You may want to skip over such information and return to it Definitions, cross-references, and other later. short items appear in marginal glosses like this. Terms that are defined in a marginal gloss or in the glossary appear in boldface. XXXII Preface: About This Manual Chapter | Introduction This first chapter introduces you to the Apple Ile itself. It shows you what the inside looks like, identifies the major components that make up the machine, and tells you where to find information about each one. Removing the Cover Eee SESE ————E—————————————e a | Remove the cover of the Apple Ile by pulling up on the back edge until the fasteners on either side pop loose, then move the cover an inch or so toward the rear of the machine to free the front of the cover, as shown in Figure 1-1. What you will see is shown in Figure 1-2. Figure 1-1. Removing the Cover Figure 1-2. The Apple Ile With the Cover Off ee ft e tie § i PE ine: 4 me ot EEE CCUUUUUTUETEEE PORDRDG ia oie ee St i * ie.tea; * "2 ae 4 cae gor * : ‘ saad + ¥ a g 8eRt . % 4s * ‘ 4 e wrnte tee poe Pa Seet- 84 ge sae : 8 # @peia“computar ie inc. J Chapter 1: Introduction AWarning There is a red LED (light-emitting diode) inside the Apple Ile, in the left rear corner of the circuit board. If the LED is on, it means that the power is on and you must turn it off before you insert or remove anything. To avoid damaging the Apple Ile, don’t even think of changing anything inside it without first turning off the power. The Keyboard ae ee | The keyboard is the Apple Ile’s primary input device. As shown in Figure 1-3, it has a normal typewriter layout, uppercase and lowercase, with ASCII stands for American Code for all of the special characters in the ASCII character set. The keyboard is Information Interchange. fully integrated into the machine; its operation is described in the first part of Chapter 2. Firmware subroutines for reading the keyboard are described in Chapter 3. Figure 1-3. The Apple Ile Keyboard The Speaker NNT eeee eee ene The Apple Ile has a small loudspeaker in the bottom of the case. The speaker enables Apple Ile programs to produce a variety of sounds that make the programs more useful and interesting. The way programs control the speaker is described in Chapter 2. The Speaker 3 The Power Supply RMR a a ee The power supply is inside the flat metal box along the left side of the interior of the Apple Ile. It provides power for the main board and for any peripheral cards installed in the Apple Ile. The power supply produces four different voltages: +5V, -5V, +12V, and -12V. It is a high-efficiency switching supply; it includes special circuits that protect it and the rest of the Apple Ile against short circuits and other mishaps. Complete specifications of the Apple Ile power supply appear in Chapter 7. AWarning The power switch and the socket for the power cord are mounted directly on the back of the power supply’s metal case. This mounting ensures that all the circuits that carry dangerous voltages are inside the power supply. Do not defeat this design feature by attempting to open the power supply. The Circuit Board ee NET ee eee ————————— All of the electronic parts of the Apple Ile are attached to the circuit board, which is mounted flat in the bottom of the case. Figure 1-4 shows the main integrated circuits (ICs) in the Apple IIe. They are the central processing unit (CPU), the keyboard encoder, the keyboard read-only memory (ROM), the two interpreter ROMs, the video ROM, and the custom integrated circuits: the Input/Output Unit (OU), the Memory Management Unit (MMU), and the Programmed Array Logic (PAL) device. 4 Chapter 1: Introduction Figure 1-4. The Circuit Board a ae ae BE. BS 8. RE ee Yeo ¥E a SEE BBS BTR, BE. ER CPU i? te PA L Poe eee pb b MMU & we ee ee IOU eS 84 ~0040 ts te BEM ee Interpreter ROMS V ideo ROM Keyboard ROM Keyboard Encoder The CPU is a 65C02 microprocessor. The 65C02 is an enhanced version of the 6502, which is an eight-bit microprocessor with a sixteen-bit address bus. It uses instruction pipelining for faster processing than comparable microprocessors. In the Apple Ile, the 65C02 runs at 1.02 MHz and performs up to 500,000 eight-bit operations per second. The specifications of the 65C02 and its instruction set are given in Appendix A. The original version of the Apple Ile uses the 6502 microprocessor. You can tell which version of Apple Ile that you have by starting up your machine. An original Apple Ile displays Apple 1¢ at the top of the screen during startup, while an enhanced Apple Ile displays Apple //e. This manual will call out specific areas where the two versions of the Apple Ile are different. Original Ile | The 6502 is very similar to the 65C02, but lacks 10 instructions and 2 addressing modes found on the 65C02. The 6502 is an NMOS device and sO uses more power than the CMOS 65C02. Except for the differences listed above, and some minor differences in the number of clock cycles used by some instructions, the two microprocessors are identic al. The keyboard is decoded by an AY-3600-type integrated circuit and a read-only memory (ROM). These devices are described in Chapter 7. The interpreter ROMs are integrated circuits that contain the Applesoft BASIC interpreter. The ROMs are described in Chapter 7. The Ap plesoft language is described in the Applesoft Tutorial and the Applesoft BASIC Programmer's Reference Manual. Two of the large ICs are custom-made for the Apple IIe: the MMU and the JOU. The MMU IC contains most of the logic that controls memory addressing in the Apple Ile. The organization of the memory is described in Chapter 4: the circuitry in the MMU itself is described in Chapter 7. The JOU IC contains most of the logic that controls the built-in input/output features of the Apple Ile. These features are described in Chapter 2 and Chapter 3; the IOU circuits are described in Chapter 7. Connectors on the Circuit Board I EE EEEEE SSS SS Se ee ee aes The seven slots lined up along the back of the Apple Ile circuit board are the expansion slots, sometimes called peripheral slots. (See Figure 1-5.) These slots make it possible to attach additional hardware to the Apple Ile. Chapter 6 tells you how your programs deal with the devices that plug into these slots; Chapter 7 describes the circuitry for the slots themselves. 6 Chapter 1: Introduction Figure 1-5. The Expansion Slots in CASSE Coe ae “< te * en ia — sien th - ern ae My ce gn, —, e ni ha o . ' “f ww jo" 2ee oh 306 4.8 5 Eeanaes Ge Pos - ae NE = saa * The large slot next to the left-hand side of the circuit board is the auxiliary slot (Figure 1-6). If your Apple [le has an Apple IIe 80-column text card, it will be installed in this slot. The 80-column display option is fully integrated into the Apple Ile; it is described along with the other display features in Chapter 2. The hardware and firmware interfaces to this card are described in Chapter 7. Figure 1-6. The Auxiliary Slot oo of. ‘ ‘ oy : . ee a ed ¢ HERHKKAKRARRKKRA BA KKKRR RRA RR R AA pAUM. CONNECTOR ‘ & a There are also smaller connectors for game I/O and for an internal RF (radio frequency )modulator. These connectors are described in Chapter 7. Connectors on the Circuit Board 7 Connectors on the Back Panel aae a a eR ea ee a The back of the Apple Ile has two miniature phone jacks for connecting a cassette recorder, an RCA-type jack for a video monitor, and a 9-pin D-type miniature connector for the hand controls, as shown in Figure 1-7. In addition to these, there are spaces for additional connectors used with the peripheral cards installed in the Apple Ile. The installation manuals for the peripheral cards contain instructions for installing the peripheral connectors. Figure 1-7. The Back Panel Connectors 8 Chapter 1: Introduction Chapter 2 Built-in I/O Devices This chapter describes the input and output (1/0) devices built into the Apple Ile in terms of their functions and the way they are used by programs. The built-in I/O devices are the keyboard the video-display generator the speaker the cassette input and output 0 the game input and output. Oodadda At the lowest level, programs use the built-in I/O devices by reading and writing to dedicated memory locations. This chapter lists these locations for For descriptions of the built-in I/O each I/O device. It also gives the locations of the internal soft-switches that hardware refer to Chapter 7. select the different display modes of the Apple Ile. Built-in I/O Routines: This method of input and output—loading and storing directly to specific locations in memory—is not the only method Built-in 1/0 firmware routines are you can use. For many of your programs, it may be more convenient to described in Chapter 3. call the built-in I/O routines stored in the Apple Ile’s firmware. The Keyboard FE ae a ee ee ee eee The primary input device of the Apple Ile is its built-in keyboard. The keyboard has 68 keys and is similar to a typewriter keyboard. The Apple Ile keyboard has automatic repeat on all keys: hold the key down to repeat. It also has N-key rollover, which means that you can hold down any number of keys while typing another. Of course, if you hold the keys down much longer than the length of time you would hold them down during normal typing, the automatic-repeat function will start repeating the last key you pressed. The keyboard arrangement shown in Figure 2-1 is the standard one used in the United States. The specifications for the keyboard are given in Table 2-1. Apple IIe’s manufactured for sale outside the United St ates have a slightly different standard keyboard arrangement and include provisions for switching between two different arrangements. Chapter 2: Built-in I/O Devices Figure 2-1. The Keyboard CAPS Table 2-1. Apple Ife Keyboard Specifications Number of keys: 63 Character encoding: ASCII Number of codes: 128 Features: Automatic repeat, two-key rollover Special function keys: (RESET],(G], (#] Cursor movement Keys: (~),(),@), (4), (RETURN), (DELETE), Modifier keys: [CONTROL},[SHIFT], [CAPS LOCK], Electrical Interface: AY-5-3600 keyboard encoder In addition to the keys normally used for typing characters, there are four cursor-control keys with arrows: left, right, down, and up. The cursor-control keys can be read the same as other keys; their codes are $08, $15, $0A, and $0B. (See Table 2-3.) Three special keys, [CONTROL],(SHIFT],and (CAPS LOCK], change the codes generated by the other keys. The key is similar to the ASCII CTRL Key. Three other keys have special functions: the key, and two keys marked with apples, one outlined, or open ((G}), and one solid, or closed ((é]). Pressing the key with the key depressed resets the Apple Ile, as described in Chapter 4. The Apple keys are connected to the one-bit game inputs, described later in this chapter. The Keyboard 1] See Chapter 7 for a complete description of The electrical interface between the Apple Ile and the keyboard is a ribbon the elecrtical interface to the keyboard. cable with a 26-pin connector. This cable carries the keyboard signals to the encoding circuitry on the main board. Reading the Keyboard S=S SSS The keyboard encoder and ROM generate all 128 ASCII codes, so all of the special character codes in the ASCII character set are available from the keyboard. Machine-language programs obtain character codes from the keyboard by reading a byte from the keyboard-data location shown in Table 2-2. Table 2-2. Keyboard Memory Locations Location Hex Decimal Description $C000 49152 -16384 Keyboard data and strobe $C010 49168 -16368 Any-key-down flag and clear-strobe switch Your programs can get the code for the last key pressed by readin g the keyboard-data location. Table 2-2 gives this location in three diffe rent Hexadecimal refers to the base-16 number forms: the hexadecimal value used in assembly language, indicated by a system, which uses the digits 0 through 9 preceding dollar sign ($); the decimal value used in Applesoft BASIC, and and the six letters A through F to represent the complementary decimal value used in Apple Integer BASIC. (Integer values from 0 to 15. BASIC requires that values greater than 32767 be written as the mumber obtained by subtracting 65536 from the value. These are the decimal numbers shown as negative in tables in this manual; refer to the Apple J] BASIC Programming Manual.) The low-order seven bits of the byte at the keyboard location contain the character code; the high-order bit of this byte is the strobe bit, described later in this section. Your program can find out whether any key is down, except the (RESET], [CONTROL},[SHIFT], (CAPS LOCK], (c], and (é] keys by reading from location 49168 (hexadecimal $C010 or complementary decimal -16368). The high-order bit (bit 7) of the byte you read at this location is called any-key-down, it is 1 if a key is down, and 0 if no key is down. The value of this bit is 128; if a BASIC program gets this information with a PEEK, the value is 128 or greater if any key is down, and less than 128 if no Key is down. 12 Chapter 2: Built-in I/O Devices The (G] and (#] keys are connected to switches 0 and 1 of the game I/O connector inputs. If [G]is pressed, switch 0 is “pressed,” and if (é)is pressed, switch 1 is “pressed.” The strobe bit is the high-order bit of the keyboard-data byte. After any key has been pressed, the strobe bit is high. It remains high until you reset it by reading or writing at the clear-strobe location. This location is a combination flag and switch; the flag tells whether any key is down, and the switch clears the strobe bit. The switch function of this memory location is called a soft switch because it is controlled by software. In this case, it doesn’t matter whether the program reads or writes, and it doesn’t matter what data the program writes: the only action that occurs is the resetting of the keyboard strobe. Similar soft switches, described later, are used for controlling other functions in the Apple Ile. important! Any time you read the any-key-down flag, you also clear the keyboard strobe. If your program needs to read both the flag and the strobe, it must read the strobe bit first. After the keyboard strobe has been cleared, it remains low until another key is pressed. Even after you have cleared the strobe, you can still read the character code at the keyboard location. The data byte has a different value, because the high-order bit is no longer set, but the ASCII code in the seven low-order bits is the same until another Key is pressed. Table 2-38 shows the ASCII codes for most of the keys on the keyboard of the Apple Ile. There are several special-function keys that do not generate ASCII codes. For example, you cannot read the [CONTROL|,(SHIFT],and keys directly, but pressing one of these Keys alters the character codes produced by the other keys. Another key that doesn’t generate a code is (RESET],located at the upper-right corner of the keyboard; it is connected directly to the Apple Ile’s circuits. Pressing with depressed normally causes the system to stop whatever program it’s running and restart itself. This The reset routine is de scribed in Chapter 4. restarting process is called the reset routine. Two more special keys are the Apple keys, (G] and (6), located on either side of the bar. These keys are connected to the one-bit game inputs, which are described later in this chapter in the section “Switch Inputs.” Pressing them in combination with the and keys causes the built-in firmware to perform special reset and self-test cycles, described with the reset routine in Chapter 4. The Keyboard 13 Table 2-3. Keys and ASCII Codes Note: Codes are shown here in hexadecimal; to find the decimal equivalents, refer Normal Control Shift Both Key Code Char Code Char Code Char Code Char (F DEL (F DEL iF DEL (F DEL 08 BS 08 BS 08 BS 08 BS TAB 09 HT 09 HT 09 HT 09 HT G] OA LF OA LF OA LF OA LF [+] OB VT OB VT OB VT OB VT OD CR OD CR OD CR OD CR 15 NAK 15 NAK 15 NAK 15 NAK 1B ESC 1B ESC 1B ESC 1B ESC 20 SP 20 SP 20) SP 20) SP ™ 27 7A| 22 : 22 a4 2C ; 2C : 3C < 3C < a 2D : 1F US 5F = IF US > 2E 2E 3 > 3k > 12 oF O/ OF / SF? 3F ? 0) 30 0 30 0 29 ) 29 ) 1! 31 1 3] l 2] | 21 ! 2@ 32 00 NUL 40 @ 00 NUL 3# 33 3 33 3 23 # as # 4$ 84 4 34 4 24 $ 24 $ 5% 35 5 35 5 25 % 25 % 6° 36 6 1E ~=RS 5E ° 1E RS 7& of (i 37 (i 26 & 26 & 8* 38 8 38 8 2A : 2A i 9( 39 9 39 9 28 ( 28 ( 3B 3B 3A 3A = + 3D = 3D = 2B + 2B aa [{ 5B 1B ESC 7B { 1B ESC \| 5C 1C FS le | 1C FS }} 5D 1D GS 7D } 1D GS : 60 ; 60 ; TE " TE : Chapter 2: Built-in I/O Devices Table 2-3—Continued. Keys and ASCII Codes Note: Codes are shown here in hexadecimal, to find the decimal equivalents, refer to Table E-2. Normal Control Shift Both A @ Row on) $2000 8192 FOOTE TEE soo sl TTTTTTLILLiLert LeeLee FF FALE LLL si sus | |TTLILiLi titer soiso sve | 111111111 EE LLL LEE soo smal | TTT TTT TTT Ti cee FT soso wel | TTT TTT Tritt fei LET LL sao sol | TITTITIfTiiiittLLeL Litt Lee ALLL sso ost | TTT TIT P Prt i A sos 2 | [TTT ATLL soas 301 | ( {TTI TITTLE LT EE sae owe [TTT TTT TTT TTT RO S21A8 8616 SROSRRRRORERREEE) oT SOGRRRERRREE $2228 8744 sons s72(| 11111 PPP 1 [l(t TITTTT tT+ 0 +80000 ees oo TT) Ft sons et LLELELLELLELLLN ale sco wre TT, |PY et seono seoo | LELELELELLLELLLLL A $2150 85281 | | | | |i ty t yd ddd tid tl [LILILLIT I +3072 +$0C00 servo sess TTT TLPPLLLP LEE somo ml TILTL LLLILILLL) CTT LT IL [J +10 +8100 eno we TET) a st sesso sot LLELELLELLELELLELLLA wooo oes TET 7d oa +80 CTT TTT) +2 00 The Video Display Generator 30 Figure 2-9. Map of Double-High-Resolution Graphics Display Main Memory . $01 $02 $03 $04 $05 $06 $20 $21 $22 $23 $24 $25 $26 $27 Le O_1 oa 43 44 ~#«5 6 _32__33_34_35_—386_—7 BCD oe TT CTO FOr =s) $2000 $2080 ool TTA PCPA $2100 wel TTT (CEC $2180 6 TPT TTT I CCE $2200 wml TCT TTT et $2280 ee TTT ACCEPT $2300 oo [TTT TO $2380 vos TTT $2028 ee TTT ee Se ee eS ee Oe $20A8 so [TTT se CECECELE EEE Soe —om) $2128 $21A8 8616 $2228 matTTTTTT CCOCILEY: 0 =-80000 $22A8 72 11 ttt tt ttt tt th CLLLLLL J sites +s010 $2328 000 TTT $23A8 we TCT —- $2050 ee ST LEELLLELELELLAN PT J oa +o $20D0 wo TECECEEEEEE $2150 ee TOT N CLL J +re + 80000 $21D0 woes FC CEELELELELLLY \a ne $2250 mee CTT \ PY sn $22D0 we CELELLLELELLLLAN $2350 oo OOO) $23D0 v8 OY VET J estes +8100 $00 $01 $02 $03 $04 $05 $06 $07 Se csi 0 1 2 38 #4 5 6 7 Auxiliary Memory 36 Chapter 2: Built-in 1/0 Devices Secondary Inputs and Outputs In addition to the primary I/O devices—the keyboard and display—there are several secondary input and output devices in the Apple Ile. These devices are Oo the speaker (output) O cassette input and output O annunciator outputs O strobe output O switch inputs O analog (hand control) inputs. These devices are similar in operation to the soft switches described in the previous section: you control them by reading or writing to dedicated memory locations. Action takes place any time your program reads or writes to one of these locations; information written is ignored. Important! Some of these devices toggle—change state—each time they are accessed. If you write using an indexed store operation, the Apple IIe’s microprocessor activates the address bus twice during successive clock cycles, causing a device that toggles each time it is addressed to end up back in its original state. For this reason, you should read, rather than write, to such devices. The Speaker Electrical specifications of the speaker The Apple Ile has a small speaker mounted toward the front of the bottom circuit appear in Chapter 7. plate. The speaker is connected to a soft switch that toggles; it has two states, off and on, and it changes from one to the other each time it is accessed. (At low frequencies, less than 400 Hz or so, the speaker clicks only on every other access.) If you switch the speaker once, it emits a click; to make longer sounds, you access the speaker repeatedly. You should always use a read operation to toggle the speaker. If you write to this soft switch, it switches twice in rapid succession. The resulting pulse is so short that the speaker doesn’t have time to respond; it doesn’t make a sound. Secondary Inputs and Outputs af The soft switch for the speaker uses memory location 49200 (hexadecimal $C030). From Integer BASIC, use the complementary address -16386. You can make various tones and buzzes with the speaker by using co mbinations of timing loops in your program. There is also a routine in the built-in BELLI is described in Appendix B. irmware to make a beep through the speaker. This routine is called BELLI. Cassette Input and Output hate Re enIN Se Ne al Ese adee ee ea ers There are two miniature phone jacks on the back panel of the Apple Ile. You can use a pair of standard cables with miniature phone plugs to connect an ordinary cassette tape recorder to the Apple Ile and save programs and data on audio cassettes. The phone jack marked with a picture of an arrow pointing towards a cassette is the output jack. It is connected to a toggled soft switch, like the Detailed electrical specifications for the speaker switch described above. The signal at the phone jack switches from cassette input and output are given in zero to 25 millivolts or from 25 millivolts to zero each time you access the Chapter 7. soft switch. If you connect a cable from this jack to the microphone input of a cassette tape recorder and switch the recorder to record mode, the signal changes you produce by accessing this soft switch will be recorded on the tape. The cassette output switch uses memory location 49184 (hexadecima. $C020; complementary value -16352). Like the speaker, this output will toggle twice if you write to it, so you should only use read operations to control the cassette output. The standard method for writing computer data on audio tapes uses tones with two different pitches to represent the binary states zero andl one. To store data, you convert the data into a stream of bits and convert the bits into the appropriate tones. To save you the trouble of actually programming the tones, and to ensure consistency among all Apple II cassette tapes, there WRITE is described in Appendix B. is a built-in routine called WRITE for producing cassette data out put. 38 Chapter 2: Built-in 1/0 Devices The phone jack marked with a picture of an arrow coming from a cassette is the input jack. It accepts a cable from the cassette recorder’s earphone jack. The signal from the cassette is 1 volt (peak-to-peak) audio. Each time the instantaneous value of this audio signal changes from positive to negative, or vice-versa, the state of the cassette input circuit changes from zero to one or vice-versa. You can read the state of this circuit at memory location 49248 (hexadecimal $C060, or complementary decimal -16288). When you read this location, you get a byte, but only the high-order bit (bit 7) is valid. If you are programming in machine language, this is the sign bit, so you can perform a Branch Plus or Branch Minus immediately after reading this byte. BASIC is too slow to keep up with the audio tones used for data recording on tape, but you don’t need to write the program: there is a READ is described in Appendix B. built-in routine called READ for reading data from a cassette. The Hand Control Connector Signals i ee ee Several inputs and outputs are available on a 9-pin D-type miniature connector on the back of the Apple Ile: three one-bit inputs, or switches, and four analog inputs. These signals are also available on the 16-pin IC connector on the main circuit board, along with four one-bit outputs and a data strobe. You can access all of these signals from your programs. Complete electrical specifications of these Ordinarily, you connect a pair of hand controls to the 9-pin connector. The inputs and outputs are given in Chapter 7. rotary controls use two analog inputs, and the push-buttons use two one-bit inputs. However, you can also use these inputs and outputs for many other jobs. For example, two analog inputs can be used with a two-axis joystick. Table 7-19 shows the connector pin numbers. Secondary Inputs and Outputs 39 Annunciator Outputs The four one-bit outputs are called annunciators. Each annunciator can be used to turn a lamp, a relay, or some similar electronic device on and off. For electrical specifications of the Each annunciator is controlled by a soft switch, and each switch uses a pair annunciator outputs, refer to Chapter 7. of memory locations. These memory locations are shown in Table 2-11. Any reference to the first location of a pair turns the corresponding annunciator off; a reference to the second location turns the annunciator on. There is no way to read the state of an annunciator. Table 2-11. Annunciator Memory Locations Annunciator Address No. Pin* State Decimal Hex 0 15 off 49240 -16296 $0058 on 49241 -16295 $0059 ] 14 off 49242 -16294 $CO5A on 49243 -16298 $CO5B 2 13 off 492.44 -16292 $C05C on 49245 -16291 $C05D 3 12 off 49246 -16290 $C05E on 49247 -16289 SCO5F * Pin numbers given are for the 16-pin IC connector on the circuit board. Strobe Output The strobe output is normally at +5 volts, but it drops to zero for about half a microsecond any time its dedicated memory location is accesse d. You can use this signal to control functions such as data latching in extermal devices. If you use this signal, remember that memory is addressed twice by a write; if you need only a single pulse, use a read operation to activate the strobe. The memory location for the strobe signal is 49216 (hexadecimal $C040 or complementary -16320). 40 Chapter 2: Built-in I/O Devices Switch Inputs The three one-bit inputs can be connected to the output of another electronic device or to a pushbutton. When you read a byte from one of these locations, only the high-order bit—bit 7—is valid information; the rest of the byte is undefined. From machine language, you can do a Branch Plus or Branch Minus on the state of bit 7. From BASIC, you read the switch with a PERK and compare the value with 128. If the value is 128 or greater, the switch is on. The memory locations for these switches are 49249 through 49251 (hexadecimal $C061 through $C063, or complementary -16287 through -16285), as shown in Table 2-12. Switch 0 and switch 1 are permanently connected to the (G]and (#] keys on the keyboard; these are the ones normally connected to the buttons on the hand controls. Some software for the older models of the Apple II uses the third switch, switch 2, as a way of detecting the shift key. This technique requires a hardware modification known as the single-wire shift-key mod. You should be sure that you really need the shift-key mod before you go ahead and do it. It probably is not worth it unless you have a program that requires the shift-key mod that you cannot either replace or modify to work without it. AWarning If you make the shift-key modification and connect a joystick or other hand control that uses switch 2, you must be careful never to close the switch and press at the same time: doing so produces a short circuit that causes the power supply to turn off. When this happens, any programs or data in the computer's internal memory are lost. Shift-Key Mod: To perform this modification on your Apple Ile, all you have to do is solder across the broken diamond labelled X6 on the main circuit board. Remember to turn off the power before changing anything inside the Apple Ile. Also remember that changes such as this are at your own risk and may void your warranty. Secondary Inputs and Outputs 4] Analog Inputs The four analog inputs are designed for use with 150K ohm variable resistors or potentiometers. The variable resistance is connected between the +5V supply and each input, so that it makes up part of a timing circuit. Refer to the section “Game I/O Signals” in The circuit changes state when its time constant has elapsed, and the time Chapter 7 for details. constant varies as the resistance varies. Your program can measure this time by counting in a loop until the circuit changes state, or times out. Before a program can read the analog inputs, it must first reset the timing circuits. Accessing memory location 49264 (hexadecimal $C070 or complementary -16272) does this. As soon as you reset the timing circuits, the high bits of the bytes at locations 49252 through 49255 (hexadecimal $C064 through $C067 or complementary -16284 through -16281) are set to 1. If you PEEK at them from BASIC, the values will be 128 or greater. Within about 3 milliseconds, these bits will change back to 0—byte values less than 128—and remain there until you reset the timing circuits again. The exact time each of the four bits remains high is directly proportional to the resistance connected to the corresponding input. If these inputs are open— no resistances are connected—the corresponding bits may remain high indefinitely. To read the analog inputs from machine language, you can use a program loop that resets the timers and then increments a counter until the bit at the appropriate memory location changes to 0, or you can use the built-in PREAD is described in Appendix B. routine called PREAD. High-level languages, such as BASIC, also include convenient means of reading the analog inputs: refer to your language manuals. Summary of Secondary I/O Locations —— Table 2-12 shows the memory locations for all of the built-in I/O devices except the keyboard and display. As explained earlier, some soft s-witches should only be accessed by means of read operations; those switches are marked. 42 Chapter 2: Built-in 1/0 Devices Table 2-12. Secondary I/O Memory Locations For connector identification and pin numbers, refer to Tables 7-18 and 7-19. Address Function Decimal Hex Access Speaker 49200 -16336 $C030 Read only Cassette out 49184 -16352 $0020 Read only Cassette in 49248 -16288 $0060 Read only Annunciator 0 on 49241 -16295 $0059 Annunciator 0 off 49240 -16296 $0058 Annunciator | on 49243 -16298 $C05B Annunciator | off 49242 -16294 $CO5A Annunciator 2 on 492.45 -16291 $C05D Annunciator 2 off 492.44 -16292 $C05C Annunciator 3 on 49247 -16289 SCO5F Annunciator 3 off 49246 -16290 $CO5E Strobe output 49216 -163820 $C040 Read only Switch input 0 (()) 49249 -16287 $0061 Read only Switch input 1 ((#)]) 49250 -16286 $0062 Read only Switch input 2 49251 -16285 $0063 Read only Analog input reset 49264 -16272 $0070 Analog input 0 49252 -16284 $0064 Read only Analog input 1 49253 -16283 $0065 Read only Analog input 2 49254 -16282 $0066 Read only Analog input 3 49255 -16281 $C067 Read only Secondary Inputs and Outputs 43 Chapter 3 Built-in I/O Firmware 45 Almost every program on the Apple Ile takes input from the keyboard and The Monitor, or System Monitor, is a sends output to the display. The Monitor and the Applesoft and Integer computer program that is used to operate BASICs do this by means of standard 1/0 subroutines that are built into the the computer at the machine language Apple Ile’s firmware. Many application programs also use the standard 1/0 level. subroutines, but Pascal programs do not; Pascal has its own I/O subroutines. This chapter describes the features of these subroutines as they are used by the Monitor and by the BASIC interpreters, and tells you how to use the standard subroutines in your assembly-language programs. Important! High-level languages already include convenient methods for handling most of the functions described in this chapter. You should not need to use the standard 1/0 subroutines in your programs unless you are programming in assembly language. Table 3-1. Monitor Firmware Routines Location Name Description $C305 BASICIN With 80-column dirmware active, displays solid, blinking cursor. Accepts character from keyboard. $C307 PASICOUT Displays a character on the screen; used w hen the 80-column firmware is active (Chapter 8). SFC9C CLREOL Clears to end of line from current cursor position. SFC9E CLEOLZ Clears to end of line using contents of Y register as cursor position. $FC42 CLREOP Clears to bottom of window. $F832 CLRSCR Clears the low-resolution screen. $F836 CLRTOP Clears top 40 lines of low-resolution screen. SFDED COUT Calls output routine whose address is stored in CSW (normally COUT], Chapter 3). $FDFO COUT Displays a character on the screen (Chapter 3). SFD8E CROUT Generates a carriage return character. $FD8B CROUT1 Clears to end of line, then generates a carrkage return character. SFD6A GETLN Displays the prompt character; accepts a string of characters by means of RDKEY. $F819 HLINE Draws a horizontal line of blocks. $FC58 HOME Clears the window and puts cursor in uppe r-left corner of window. 46 Chapter 8: Built-in 1/O Firmware Table 3-1—Continued. Monitor Firmware Routines Location Name Description $FDIB KEYIN With 80-column firmware inactive, displays checkerboard cursor. Accepts character from keyboard. $F 800 PLOT Plots a single low-resolution block on the screen. $FO4A PRBL2 Sends | to 256 blank spaces to the output device. $FDDA PRBYTE Prints a hexadecimal byte. $FF2D PRERR Sends Err and Control-G to the output device. $FDE3 PRHEX Prints 4 bits as a hexadecimal number. $F941 PRNTAX Prints contents of A and X in hexadecimal. $FDOC RDKEY Displays blinking cursor; goes to standard input routine, normally KEYIN or BASICIN. $F87 1 SCRN Reads color value of a low-resolution block. $F 864 SETCOL Sets the color for plotting in low-resolution. $FC24 VTABZ Sets cursor vertical position. $F828 VLINE Draws a vertical line of low-resolution blocks. The standard I/O subroutines listed in Table 8-1 are fully described in this chapter. The Apple Ile firmware also contains many other subroutines that you might find useful. Those subroutines are described in Appendix B. Two AUXMOVE and XFER are described in the of the built-in subroutines, AUXMOVE and XFER, can help you use the section “Auxiliary-Me mory Subroutines” in optional auxiliary memory. Chapter 4. Using the I/O Subroutines afk Before you use the standard I/O subroutines, you should understand a little about the way they are used. The Apple Ile firmware operates differently when an option such as an 80-column text card is used. This section describes general situations that affect the operation of the standard I/O subroutines. Specific instances are described in the sections devoted to the individual subroutines. Using the I/O Subroutines 47 Apple |i Compatibility sie ese nani einnoes ee aan Compared to older Apple II models, the Apple IIe has some additional keyboard and display features. To run programs that were written for the older models, you can make the Apple Ile resemble an Apple II Plus by turning those features off. The features that you can turn off and on to put the Apple Ile into and out of Apple II mode are listed in Table 3-2. Table 3-2. Apple II Mode Apple Ile Apple II Mode Keyboard Uppercase and lowercase Uppercase only Display characters Inverse and normal only Flashing, inverse, and normal Display size 40-column; also 80-column 40-column only with optional card If the Apple Ile does not have an 80-column text card installed in the auxiliary slot, it is almost in Apple II mode as soon as you turn it on or reset it. One exception is the keyboard, which is both uppercase and lowercase. Original lle On an original Apple Ile, DOS 3.3 commands and statements in Integer BASIC and Applesoft must be typed in uppercase letters. To be compatible with older software, you should switch the Apple Ile keyboard to uppercase by pressing [CAPS LOCK]. Another feature that is different on the Apple Ile as compared to the Apple II is the displayed character set. An Apple II displays only uppercase characters, but it displays them three ways: normal, inverse, and flashing. The Apple Ile can display uppercase characters all three ways, and it can display lowercase characters in the normal way. This combination is called The primary and alternate character sets the pramary character set. When the Apple Ile is first turned on or reset, are described in Chapter 2 in the section it displays the primary character set. “Text Character Sets.” The Apple Ile has another character set, called the alternate character set, that displays a full set of normal and inverse characters, with. the inverse uppercase characters between $40 and $5F replaced on enhanced Apple IIe’s with MouseT ext characters. Original lle In the original Apple Ile, uppercase inverse characters appear in place of the MouseText characters of the enhanced Apple IIe and the Apple IIc. The ALTCHAR soft switch is describedin You can switch character sets at any time by means of the ALTCHAR soft Chapter 2. switch. 48 Chapter 3: Built-in I/O Firmware The 80-Column Firmware There are a few features that are normally available only with the optional 80-column display. These features are identified in Table 3-3b and Table 3-6. The firmware that supports these features is built into the Apple Ile, but it is normally active only if an 80-column text card is installed in the auxiliary slot. When you turn on power or reset the Apple Ile, the 80-column firmware is inactive and the Apple Ile displays the primary character set, even if an 80-column text card is installed. When you activate the 80-column firmware, it switches to the alternate character set. The built-in 80-column firmware is implemented as if it were installed in expansion slot 3. Programs written for an Apple II or Apple II Plus with an 80-column text card installed in slot 3 usually will run properly on a Apple Ie with an 80-column text card in the auxiliary slot. See the section “Switching I/O Memory” in If the Apple Ile has an 80-column text card and you want to use the Chapter 6 for details. 80-column display, you can activate the built-in firmware from BASIC by typing PR#3 To activate the 80-column firmware from the Monitor, press [3], then (CONTROL }{P}. Notice that this is the same procedure you use to activate a card in expansion slot 8. Any card installed in the auxiliary slot takes precedence over a card installed in expansion slot 3: Important! Even though you activated the 80-column firmware by typing PR#3, you should never deactivate it by typing PR#0, because that just disconnects the firmware, leaving several soft switches still set for 80-column operation. Instead, type the sequence [CONTROL }{Q]. (See Table 3-6.) If there is no 80-column text card or other auxiliary memory card in your Apple Ile, you can still activate the 80-column firmware and use it with a SLOTC8ROM is described in Chapter 6 in 40-column display. First, set the SLOTC3ROM soft switch located at $CO0A the section “Switching 1/0 Memory.” (49162). Then type PR#8 to transfer control to the firmware. When the 80-column firmware is active without a card in the auxiliary slot, it does not work quite the same as it does with a card. The functions that clear the display (CLREOL, CLEOLZ, CLREOP, and HOME) work as if the For more information about interrupts, see firmware were inactive: they always clear to the current color. Also, Chapter 6. interrupts are supported only with a card installed in the auxiliary slot. Using the I/O Subroutines 49 AWarning If you do not have an interface card in either the auxiliary slot or slot 3, don’t try to activate the firmware with PR#8. Typing PR#8 with no card installed transfers control to the empty connector, with unpredictable results. Programs activate the 80-column firmware by transferring control to address $C300. If there is no card in the auxiliary slot, you must set the SLOTC8ROM soft switch first. To deactivate the 80-column firmware from a program, write a Control-U character via subroutine COUT. The Old Monitor Apple II’s and Apple II Pluses used a version of the System Monitor different from the one the Apple Ile uses. It had the same standard I/O subroutines, but a few of the features were different; for example, there were no arrow keys for cursor motion. If you start the Apple IIe with a DOS or BASIC disk that loads Integer BASIC into the bank-switched area in RAM, the old Monitor (sometimes called the Autostart Monitor) is also loaded with it. When you type INT from Applesoft to activate Integer BASIC, you also activate this copy of the old Monitor, which remains active until you either type FP to switch back to Applesoft, which uses the new Monitor in ROM, or type PR#3 to activate the 80-column firmware. Part of the firmware’s initialization procedure checks to see which version of the Monitor is in RAM. If it finds the old Monitor, it replaces it with a copy of the new Monitor from ROM. After the firmware has copied the new Monitor into RAM, it remains there until the next time you start up the system. The Standard |/O Links When you call one of the character I/O subroutines (COUT and RDKEY), the first thing that happens is an indirect jump to an address stored in programmable memory. Memory locations used for transferring control to other subroutines are sometimes called vectors; in this manual, the locations used for transferring control to the I/O subroutines are called I/O links. In a Apple Ile running without a disk operating system, each I/O link is normally the address of the body of the subroutine (COUT1 or KEYIN). If a disk operating system is running, one or both of these links hold the addresses of the corresponding DOS or ProDOS I/0 routines instead. (DOS and ProDOS maintain their own links to the standard I/O subroutines. ) 00) Chapter 8: Built-in I/O Firmware By calling the I/O subroutines that jump to the link addresses instead of calling the standard subroutines directly, you ensure that your program will work properly in conjunction with other software, such as DOS or a printer driver, that changes one or both of the I/O links. For more information about the I/O links, For the purposes of this chapter, we shall assume that the I/O links contain see the section “Changing the Standard 1/0 the addresses of the standard I/O subroutines—COUT1 and KEYIN if the Links” in Chapter 6. 80-column firmware is off, and BASICOUT and BASICIN if it is on. Standard Output Features en ee The standard output routine is named COUT, pronounced C-out, which stands for character out. COUT normally calls COUT1, which sends one character to the display, advances the cursor position, and scrolls the display when necessary. COUT] restricts its use of the display to an active area called the text window, described below. COUT Output Subroutine eee ee eee Your program makes a subroutine call to COUT at memory location $FDED with a character in the accumulator. COUT then passes control via the output link CSW to the current output subroutine, normally COUT1 (or BASICOUT), which takes the character in the accumulator and writes it out. If the accumulator contains an uppercase or lowercase letter, a number, or a special character, COUT! displays it; if the accumulator contains a control character, COUT] either performs one of the special functions described below or ignores the character. Each time you send a character to COUT1, it displays the character at the current cursor position, replacing whatever was there, and then advances the cursor position one space to the right. If the cursor position is already at the right-hand edge of the window, COUT1 moves it to the left-most position on the next line down. If this would move the cursor position past the end of the last line in the window, COUT] scrolls the display up one line and sets the cursor position at the left end of the new bottom line. The cursor position is controlled by the values in memory locations 36 and 37 (hexadecimal $24 and $25). These locations are named CH, for cursor horizontal, and CV, for cursor vertical. COUT! does not display a cursor, but the input routines described below do, and they use this cursor position. If some other routine displays a cursor, it will not necessarily put it in the cursor position used by COUT]. Standard Output Features bl Control Characters With COUT1 and BASICOUT COUT1 and BASICOUT do not display control characters. Instead, the control characters listed in Tables 3-3a and 3-3b are used to initiate some action by the firmware. Other control characters are ignored. Most of the functions listed here can also be invoked from the keyboard, either by typing the control character listed or by using the appropriate escape code, as described in the section “Escape Codes With KEYIN” later in this chapter. The stop-list function, described separately, can only be invoked from the keyboard. Table 3-3a. Control Characters With 80-Column Firmware Off Control ASCII Apple Ile Character Name Name Action Taken by COUT1 Control-G BEL bell Produces a 1000 Hz tone for 0.1 second. Control-H BS backspace Moves cursor position one space to the left; from left edge of window, moves to right end of line above. Control-J LF line feed Moves cursor position down to next line in window; scrolls if needed. Control-M CR return Moves cursor position to left end of next line in window; scrolls if needed. Table 3-3b. Control Characters With 80-Column Firmware On Control ASCII Apple IIe Character Name Name Action Taken by BASICOUT Control-G BEL _ bell Produces a 1000 Hz tone for 0.1 second. Control-H BS backspace Moves cursor position one space to the left; from left edge of window, moves to right end of line above. Control-J LF line feed Moves cursor position down to next line in window; scrolls if needed. Control-KT VT clear EOS — Clears from cursor position to the end of the screen. Control-LT FF home Moves cursor position to upper -left corner and clear of window and clears window. OZ Chapter 3: Built-in I/O Firmware Table 3-3b—Continued. Control Characters With 80-Column Firmware On Control ASCII Apple IIe Character Name Name Action Taken by BASICOUT Control-M CR return Moves cursor position to left end of next line in window; scrolls if needed. Control-Nt SO normal Sets display format normal. Control-Ot SI inverse Sets display format inverse. Control-Qt DCl 40-column Sets display to 40-column. Control-Rt DC2 80-column Sets display to 80-column. Control-S* DC3 stop-list Stops listing characters on the display until another key is pressed. Control-U ¢ NAK quit Deactivates 80-column video firmware. Control-V fT SYN scroll Scrolls the display down one line, leaving the cursor in the current position. Control-W tf ETB scroll-up Scrolls the display up one line, leaving the cursor in the current position. Control-X CAN disable Disable MouseText character display; use MouseText inverse uppercase. Control-Y tf EM home Moves cursor position to upper-left corner of window (but doesn’t clear). Control-Z t SUB clear line Clears the line the cursor position is on. Control-[ KSC enable Map inverse uppercase characters to MouseText MouseText characters. Control-\t forward Moves cursor position one space to the space right; from right edge of window, moves it to left end of line below. Control-]t clear EOL Clears from the current cursor position to the end of the line (that is, to the right edge of the window). Control-_ US up Moves cursor up a line, no scroll. * Only works from the keyboard. + Doesn’t work from the keyboard. Standard Output Features 00 The Stop-List Feature SSS SSS SSS el When you are using any program that displays text via COUT1 (or BASICOUT), you can make it stop updating the display by holding down and pressing (s ].Whenever COUT] gets a carriage return from the program, it checks to see if you have pressed [CONTROL H S$}. If you have, COUT 1 stops and waits for you to press another key. When you want COUT! to resume, press another key; COUT1 will send the carriage return it got earlier to the display, then continue normally. The character code of the key you pressed to resume displaying is ignored unless you pressed (CONTROL }{C ].COUT] passes Control-C back to the program; if it is a BASIC program, this enables you to terminate the program while in stop-list mode. The Text Window ESS Sea After starting up the computer or after a reset, the firmware uses the entire display. However, you can restrict video activity to any rectangular portion of the display you wish. The active portion of the display is called. the text window. COUT1 or BASICOUT puts characters into the window only; when it reaches the end of the last line in the window, it scrolls only the contents of the window. You can set the top, bottom, left side, and width of the text window by storing the appropriate values into four locations in memory. This enables your programs to control the placement of text in the display and to protect other portions of the screen from being written over by new text. Memory location 32 (hexadecimal $20) contains the number of the leftmost column in the text window. This number is normally 0, the number of the leftmost column in the display. In a 40-column display, the maximum value for this number is 89 (hexadecimal $27); in an 80-column display, the maximum value is 79 (hexadecimal $4F). Memory location 33 (hexadecimal $21) holds the width of the text. window. For a 40-column display, it is normally 40 (hexadecimal $28); for an 80-column display, it is normally 80 (hexadecimal $50). Original lle COUT! truncates the column width to an even value on the original Apple Ile. o4 Chapter 3: Built-in I/O Firmware AWarning On an original Apple Ile, be careful not to let the sum of the window width and the leftmost position in the window exceed the width of the display you are using (40 or 80). If this happens, it is possible for COUT1 to put characters into memory locations outside the display page, possibly into your current program or data space. Memory location 34 (hexadecimal $22) contains the number of the top line of the text window. This is normally 0, the topmost line in the display. Its maximum value is 23 (hexadecimal $17). Memory location 35 (hexadecimal $23) contains the number of the bottom line of the screen, plus 1. It is normally 24 (hexadecimal $18) for the bottom line of the display. Its minimum value is 1. After you have changed the text window boundaries, nothing is affected until you send a character to the screen. AWarning Any time you change the boundaries of the text window, you should make sure that the current cursor position (stored at CH and CV) is inside the new window. If it is outside, it is possible for COUT 1 to put characters into memory locations outside the display page, possibly destroying programs or data. Table 3-4 summarizes the memory locations and the possible values for the window parameters. Table 3-4. Text Window Memory Locations Window Location Minimum Normal Values Maximum Values Parameter Value 40 col. 80 col. 40 col. 80 col. Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Left Edge 82 =:$20 00 $00 00 $00 00 $00 39 $27 19 $4F Width 83 «$21 00 $00 4() $28 80 $50 40 $28 80) $50 Top Edge 84 = $22 00 $00 00 $00 00 $00 Ze $17 23 $17 Bottom Edge 85 «$28 01 $01 24 $18 24 $18 24 $18 24 $18 Standard Output Features bd Inverse and Flashing Text a ead Subroutine COUT! can display text in normal format, inverse format, or, with some restrictions, flashing format. The display format for any character in the display depends on two things: the character set being used at the moment, and the setting of the two high-order bits of the character’s byte in the display memory. As it sends your text characters to the display, COUT1 sets the high-order bits according to the value stored at memory location 50 (hexadecimal $32). If that value is 255 (hexadecimal $FF), COUT] sets the characters to display in normal format; if the value is 63 (hexadecimal $3F), COUT! sets the characters to inverse format. If the value is 127 (hexadecimal $7F) and if you have selected the primary character set, the characters will be displayed in flashing format. Note that flashing format is not available in the alternate character set. Table 3-5. Text Format Control Values Note: These mask values apply only to the primary character set (see text). Mask Value Dec Hex Display Format 255 $FF Normal, uppercase, and lowercase 127 $7F Flashing, uppercase, and symbols 63 $3F Inverse, uppercase, and lowercase To control the display format of the characters, routine COUT1 uses the value at location 50 as a logical mask to force the setting of the two high-order bits of each character byte it puts into the display page. It does this by performing the logical AND function on the data byte and the mask byte. The result byte contains a 0 in any bit that was 0 in the mask. BASICOUT, used when the 80-column firmware is active, changes only the high-order bit of the data. Important! If the 80-column firmware is inactive and you store a mask value at location 50 with zeros in its low-order bits, COUT1 will mask out those bits in your text. As a result, some characters will be transformed into other characters. You should set the mask to the values given in Table 8-5 only. o6 Chapter 3: Built-in I/O Firmware If you set the mask value at location 50 to 127 (hexadecimal $7F), the high-order bit of each result byte will be 0, and the characters will be displayed either as lowercase or as flashing, depending on which character Switching between character sets is set you have selected. Refer to the tables of display character sets in described in the section “Display Mode Chapter 2. In the primary character set, the next-highest bit, bit 6, selects Switching” in Chapter 2. flashing format with uppercase characters. With the primary character set you can display lowercase characters in normal format and uppercase characters in normal, inverse, and flashing formats. In the alternate character set, bit 6 selects lowercase or special characters. With the alternate character set you can display uppercase and lowercase characters in normal and inverse formats. Original lle On the original Apple Ile, the MouseText characters are replaced by uppercase inverse characters. Standard Input Features are a a Re MF Se The Apple Ile’s firmware includes two different subroutines for reading from the keyboard. One subroutine is named RDKEY, which stands for read key. \t calls the standard character input subroutine KEYIN (or BASICIN when the 80-column firmware is active) which accepts one character at a time from the keyboard. For more information on GETLN, see the The other subroutine is named GETLN, which stands for get line. By section “Editing With GETLN,” later in this making repeated calls to RDKEY, GETLN accepts a sequence of characters chapter. terminated with a carriage return. GETLN also provides on-screen editing features. RDKEY Input Subroutine SaaS ee ee ee A program gets a character from the keyboard by making a subroutine call to RDKEY at memory location $FD0C. RDKBY sets the character at the cursor position to flash, then passes control via the input link KSW to the current input subroutine, which is normally KEYIN or BASICIN. RDKEY displays a cursor at the current cursor position, which is immediately to the right of whatever character you last sent to the display (normally by using the COUT routine, described earlier). The cursor displayed by RDKEY is a flashing version of whatever character happens to be at that position on the screen. It is usually a space, so the cursor appears as a blinking rectangle. Standard Input Features of KEYIN Input Subroutine SS SS Se eee KEYIN is the standard input subroutine when the 80-column firmware is inactive; BASICIN is used when the 80-column firmware is active. When called, the subroutine waits until the user presses a key, then returns with the key code in the accumulator. If the 80-column firmware is inactive, KEYIN displays a cursor by alternately storing a checkerboard block in the cursor location, then storing the original character, then the checkerboard again. If the firmware is active, BASICIN displays a steady inverse space (rectangle), unless you are Escape mode is described in the next in escape mode, when it displays a plus sign (+) in inverse format. section, “Escape Codes.” KEYIN also generates a random number. While it is waiting for the user to press a key, KEYIN repeatedly increments the 16-bit number in memory locations 78 and 79 (hexadecimal $4E and $4F). This number keeps increasing from 0 to 65535, then starts over again at 0. The value of this number changes so rapidly that there is no way to predict what it will be after a key is pressed. A program that reads from the keyboard can use this value as a random number or as a seed for a random number routine. When the user presses a key, KEYIN accepts the character, stops displaying the cursor, and returns to the calling program with the character in the accumulator. Escape Codes KEYIN has special functions that you invoke by typing escape codes on the keyboard. An escape code is obtained by pressing [ESC], releasing it, and then pressing some other key. See Table 3-6; the notation in the table means press [ESC], release it, then press the key that follows. Table 3-6 includes three sets of cursor-control keys. The first set consists of followed by A, B, C, or D. The letter keys can be either uppercase or lowercase. These keys are the standard cursor-motion keys on older Apple II models; they are present on the Apple Ile primarily for compatibility with programs written for old machines. Cursor Motion in Escape Mode The second and third set of cursor-control keys are listed together because they activate escape mode. In escape mode, you can keep using the cursor-motion keys without pressing again. This enables you to perform repeated cursor moves by holding down the appropriate k ey. 58 Chapter 3: Built-in I/O Firmware When the 80-column firmware is active, you can tell when BASICIN is in escape mode: it displays a plus sign in inverse format as the cursor. You leave escape mode by typing any key other than a cursor-motion key. The escape codes with the directional arrow keys are the standard cursor-motion keys on the Apple Ile. The escape codes with the I,J, K, and M keys are the standard cursor-motion keys on the Apple II Plus, and are present on the Apple [le for compatibility with the Apple II Plus. On the Apple Ile, the escape codes with the I,J, K, and M keys function with either uppercase or lowercase letters. Table 3-6. Escape Codes Escape Code Function Le] Clears window and homes cursor (places it in upper-left corner of screen), then exits from escape mode. [Esc }[A] or [a] Moves cursor right one line; exits from escape mode. (Esc }[B} or (b] Moves cursor left one line; exits from escape mode. [Esc}(c}or(c} Moves cursor down one line; exits from escape mode. [Esc}(D}or(a} Moves cursor up one line; exits from escape mode. (esc }(E}or[e} Clears to end of line; exits from escape mode. [esc }[F] or (4) Clears to bottom of window; exits from escape mode. [esc ](1J or (iJor (esc}{+} Moves the cursor up one line; remains in escape mode. See text. (esc }[J} or (jJor esc} [~] Moves the cursor left one space; remains in escape mode. See text. [esc }[k] or [k] or (Esc ][+] Moves the cursor right one space; remains in escape mode. See text. [esc ](m} or(m] or (esc) [) Moves the cursor down one line; remains in escape mode. See text. [esc ][4] If 80-column firmware is active, switches to 40-column mode; sets links to BASICIN and BASICOUT; restores normal window size; exits from escape mode. If 80-column firmware is active, switches to 80-column mode; sets links to BASICIN and BASICOUT; restores normal window size; exits from escape mode. [ESC ][CONTROL }{D ] Disables control characters; only carriage return, line feed, BELL, and backspace have an effect when printed. [ESC ][CONTROL }[E ] Reactivates control characters. [Esc [CONTROL }{@ ] If 80-column firmware is active, deactivates 80-column firmware; sets links to KEYIN and COUT1; restores normal window size; exits from escape mode. Standard Input Features 59 GETLN Input Subroutine Programs often need strings of characters as input. While it is pos sible to call RDKEY repeatedly to get several characters from the keyboard, there is a more powerful subroutine you can use. This routine is named GETLN, which stands for get /2ne, and starts at location $FD6A. Using repeated calls to RDKEY, GETLN accepts characters from the standard input subroutine—usually KEYIN—and puts them into the input buffer located in the memory page from $200 to $2FF. GETLN also provides the user with on-screen editing and control features, described in the next section “Editing With GETLN.” The first thing GETLN does when you call it is display a prompting character, called simply a prompt. The prompt indicates to the user that the program is waiting for input. Different programs use different prompt characters, helping to remind the user which program is requesting the input. For example, an INPUT statement in a BASIC program displays a question mark ( ? )as a prompt. The prompt characters used by the different programs on the Apple Ile are shown in Table 3-7. GETLN uses the character stored at memory location 51 (hexadecimal $33) as the prompt character. In an assembly-language program, you can change the prompt to any character you wish. In BASIC, changing the prompt character has no effect, because both BASIC interpreters and the Monitor restore it each time they request input from the user. Table 3-7. Prompt Characters Prompt Character Program Requesting Input i User’s BASIC program (INPUT statement) Applesoft BASIC (Appendix D) > Integer BASIC (Appendix D) * Firmware Monitor (Chapter 5) As you type the character string, GETLN sends each character to the standard output routine—normally COUT 1—which displays it at the previous cursor position and puts the cursor at the next available position on the display, usually immediately to the right. As the cursor travels across the display, it indicates the position where the next character willl be displayed. 60 Chapter 3: Built-in I/O Firmware GETLN stores the characters in its buffer, starting at memory location $200 and using the X register to index the buffer. GETLN continues to accept and display characters until you press (RETURN};then it clears the remainder of the line the cursor is on, stores the carriage-return code in the buffer, sends the carriage-return code to the display, and returns to the calling program. The maximum line-length that GETLN can handle is 255 characters. If the user types more than this, GETLN sends a backslash ( \ ) and a carriage return to the display, cancels the line it has accepted so far, and starts over. To warn the user that the line is getting full, GETLN sounds a bell (tone) at every keypress after the 248th. important! In the Apple II and the Apple II Plus, the GETLN routine converts all input to uppercase. GETLN in the Apple Ile does not do this, even in Apple II mode. To get uppercase input for BASIC, use (CAPS LOCK]. Editing With GETLN aaa Se ee ey Subroutine GETLN provides the standard on-screen editing features used by the BASIC interpreters and the Monitor. For an introduction to editing with these features, refer to the Applesoft Tutorial. Any program that uses GETLN for reading the keyboard has these features. Cancel Line Any time you are typing a line, pressing causes GETLN to cancel the line. GETLN displays a backslash ( \ ) and issues a carriage return, then displays the prompt and waits for you to type a new line. GETLN takes the same action when you type more than 255 characters, as described earlier. Backspace When you press (~], GETLN moves its buffer pointer back one space, effectively deleting the last character in its buffer. It also sends a backspace character to routine COUT, which moves the display position and the cursor back one space. If you type another character now, it will replace the character you backspaced over, both on the display and in the line buffer. Each time you press [=], it moves the cursor left and deletes another character, until you reach the beginning of the line. If you then press [~} one more time, you have cancelled the line, and GETLN issues a carriage return and displays the prompt. Standard Input Features 6] Retype has a function complementary to the backspace function. When you press [+], GETLN picks up the character at the display position just as if it had been typed on the keyboard. You can use this procedure to pick up characters that you have just deleted by backspacing across them. You can use the backspace and retype functions with the cursor-motion functions to edit data on the display. (See the earlier section “Cursor Motion in. Escape Mode.”) Monitor Firmware Support Table 3-8 summarizes the addresses and functions of the video display support routines the Monitor provides. These routines are described in the subsections that follow. Table 3-8. Video Firmware Routines Location Name Description $C307 BASICOUT Displays a character on the screen when 80-column firmware is active. $FC9C CLREOL Clears to end of line from current cursor position. SFC9E CLEOLZ Clears to end of line using contents of Y register as Cursor position. $FC42 CLREOP Clears to bottom of window. $F 832 CLRSCR Clears the low-resolution screen. $F836 CLRTOP Clears top 40 lines of low-resolution screen. $FDED COUT Calls output routine whose address is stored in CSW (normally COUT1, Chapter 3). $FDFO COUT] Displays a character on the screen (Chapter 3). $FD8E CROUT Generates a carriage return character. $FD8B CROUT 1 Clears to end of line, then generates a carriage return character. $F819 HLINE Draws a horizontal line of blocks. 62 Chapter 3: Built-in I/O Firmware Table 3-8—Continued. Video Firmware Routines Location Name Description SFC58 HOME Clears the window and puts cursor in upper-left corner of window. S800 PLOT Plots a single low-resolution block on the screen. SFO4A PRBL2 Sends | to 256 blank spaces to the output device whose address is in CSW. SFDDA PRBYTE Prints a hexadecimal byte. SFF2D PRERR Sends ERR and Control-G to the output device whose output routine address is in CSW. $FDES PRHEX Prints 4 bits as a hexadecimal number. $F941 PRNTAX Prints contents of A and X in hexadecimal. $F871 SCRN Reads color value of a low-resolution block on the screen. $F864 SETCOL Sets the color for plotting in low-resolution. $FC24 VTABZ Sets cursor vertical position. (Setting CV at location $25 does not change vertical positon until a carriage return.) $F828 VLINE Draws a vertical line of low-resolution blocks. BASICOUT, $C307 BASICOUT is essentially the same as COUT1—BASICOUT is used instead of COUT1 when the 80-column firmware is active. BASICOUT displays the character in the accumulator on the display screen at the current cursor position and advances the cursor. It places the character using the setting of the inverse mask (location $32). BASICOUT handles control characters; see Table 3-3b. When it returns control to the calling program, all registers are intact. CLREOL, $FC9C CLREOL clears a text line from the cursor position to the right edge of the window. This routine destroys the contents of A and Y. Monitor Firmware Support 63 CLEOLZ, $FC9E CLEOLZ clears a text line to the right edge of the window, starting at the location given by base address BASL, which is indexed by the contents of the Y register. This routine destroys the contents of A and Y. CLREOP, $FC42 CLREOP clears the text window from the cursor position to the bottom of the window. This routine destroys the contents of A and Y. CLRSCR, $F832 CLRSCR clears the low-resolution graphics display to black. If you call this routine while the video display is in text mode, it fills the screen with inverse-mode at-sign ((@) characters. This routine destroys the contents of A and Y. CLRTOP, $F836 CLRTOP is the same as CLRSCR, except that it clears only the top 40 rows of the low-resolution display. COUT, $FDED COUT calls the current character output subroutine. (See the section “COUT Output Subroutine’ earlier in this chapter.) The character to be sent to the output device should be in the accumulator. COUT calls the subroutine whose address is stored in CSW (locations $36 and $87 ), which is usually the standard character output subroutine COUT1 (or BASICOUT). COUT1, $FDFO See the section “Control Characters With COUT] displays the character in the accumulator on the display screen at COUT1 and BASICOUT,” earlier in this the current cursor position and advances the cursor. It places the character chapter for more information on COUT]. using the setting of the inverse mask (location $32). It handles these control characters: carriage return, line feed, backspace, and bell. When it returns control to the calling program, all registers are intact. CROUT, $FD8E CROUT sends a carriage return to the current output device. 64 Chapter 38: Built-in I/O Firmware CROUT1, $FD8B CROUT!1 clears the screen from the current cursor position to the edge of the text window, then calls CROUT. HLINE, $F819 HLINE draws a horizontal line of blocks of the color set by SETCOL on the low-resolution graphics display. Call HLINE with the vertical coordinate of the line in the accumulator, the leftmost horizontal coordinate in the Y register, and the rightmost horizontal coordinate in location $2C. HLINE returns with A and Y scrambled and X intact. HOME, $FC58 HOME clears the display and puts the cursor in the upper-left corner of the screen. PLOT, $F800 PLOT puts a single block of the color value set by SETCOL on the low-resolution display screen. Call PLOT with the vertical coordinate of the line in the accumulator, and its horizontal position in the Y register. PLOT returns with the accumulator scrambled, but X and Y intact. PRBL2, $F94A PRBL2 sends from 1 to 256 blanks to the standard output device. Upon entry, the X register should contain the number of blanks to send. If X = $00, then PRBLANK will send 256 blanks. PRBYTE, $FDDA PRBYTE sends the contents of the accumulator in hexadecimal to the current output device. The contents of the accumulator are scrambled. PRERR, $FF2D PRERR sends the word ERR, followed by a bell character, to the standard output device. On return, the accumulator is scrambled. Monitor Firmware Support 65 PRHEX, $FDE3 PRHEX prints the lower nibble of the byte in the accumulator as a single hexadecimal digit. On return, the contents of the accumulator are scrambled. PRNTAX, $F941 PRT AX prints the contents of the A and X registers as a four-digit hexadecimal value. The accumulator contains the first byte printed, and the X register contains the second. On return, the contents of the accumulator are scrambled. SCRN, $F871 SCRN returns the color value of a single block on the low-resolution display. Call it with the vertical position of the block in the accumulator and the horizontal position in the Y register. The block’s color is returned in the accumulator. No other registers are changed. SETCOL, $F864 SETCOL sets the color used for plotting in low-resolution graphics to the value passed in the acumulator. The colors and their values are listed in Table 2-6. VTABZ, $FC24 VTABZ sets the cursor vertical position. Unlike setting the position at location $25, change of cursor position doesn’t wait until a carriage return character has been sent. VLINE, $F828 VLINE draws a vertical line of blocks of the color set by SETCOL on the low-resolution display. Call VLINE with the horizontal coordinate of the line in the Y register, the top vertical coordinate in the accumulator, and the bottom vertical coordinate in location $2D. VLINE returns with the accumulator scrambled. 66 Chapter 3: Built-in I/O Firmware 1/O Firmware Support SSS a a ae ae ee ee ee ee ee Ce ee Apple Ile video firmware conforms to the I/O firmware protocol of Apple II Pascal 1.1. However, it does not support windows other than the full 80-by-24 window in 80-column mode, and the full 40-by-24 window in 40-column mode. The video protocol table is shown in Table 3-9. Table 3-9. Slot 3 Firmware Protocol Table Address Value Description $C30B ~—Ss $001 Generic signature byte of firmware cards $C30C ~—s-_:$88 80-column card device signature $C30D _iSii $C3ii is entry point of initialization routine (PINIT). $C30E —s $rr $C3rr is entry point of read routine (PREAD). $C30F $ww $C3wwisentry point of write routine (PWRITE). $C310 — $ss $C8ss is entry point of the status routine (PSTATUS). PINIT, $C30D PINIT does the following: O Sets a full 80-column window. Oo Sets 80STORE ($C001). o Sets 80COL ($CO00D). Oo Switches on ALTCHAR ($CO0F). O Clears the screen; places cursor in upper-left corner. oO Displays the cursor. PREAD, $C30E PREAD reads a character from the keyboard and places it in the accumulator with the high bit cleared. It also puts a zero in the X register to indicate IORESULT = GOOD. I/O Firmware Support 67 PWRITE, $C30F PWRITE should be called after placing a character in the accumulator with its high bit cleared. PWRITE does the following: o Turns the cursor off. o If the character in the accumulator is not a control character, turns the high bit on for normal display or off for inverse display, displays it at the current cursor position, and advances the cursor; if at the end of a line, does carriage return but not line feed. (See Table 3-10 for control character functions.) When PWRITE has completed this, it o turns the cursor back on (if it was not intentionally turned off) O puts a zero in the X register JORESULT = GOOD) and returns to the calling program. Table 3-10. Pascal Video Control Functions Control- Hex Function Performed Eore $05 Turns cursor on (enables cursor display). F or f $06 Turns cursor off (disables cursor display). Gorg $07 Sounds bell (beeps). Horh $08 Moves cursor left one column. If cursor was at beginning of line, moves it to end of previous line. Jor] $0A Moves cursor down one row; scrolls if needed. Kork $0B Clears to end of screen. Lor] $0C Clears screen; moves cursor to upper-left of screen. Morm $0D — Moves cursor to column 0. Norn $0E Displays subsequent characters in normal video. (Characters already on display are unaffected. ) Chapter 3: Built-in I/O Firmware Table 3-10—Continued. Pascal Video Control Functions Control- Hex Function Performed Ooro SOF Displays subsequent characters in inverse video. (Characters already on display are unaffected.) Vorv $16 Scrolls screen up one line; clears bottom line. Worw = $17 Scrolls screen down one line; clears top line. Yory $19 Moves cursor to upper-left (home) position on screen. Z or z SIA Clears entire line that cursor is on. lor \ $1C Moves cursor right one column; if at end of line, does Control-M. bor] $1D Clears to end of the line the cursor is on, including current Cursor position; does not move cursor. “or6 = $1E GOTOxy: initiates a GOTOxy sequence; interprets the next two characters as x+32 and y+82, respectively. zz $IF If not at top of screen, moves cursor up one line. PSTATUS, $C310 A program that calls PSTATUS must first put a request code in the accumulator: either a 0, meaning “Ready for output?” or a 1, meaning “Is there any input?” PSTATUS returns with the reply in the carry bit: 0 (No) or 1 (Yes). PSTATUS returns with a 0 in the X register (IORESULT = GOOD), unless the request was not 0 or 1; then PSTATUS returns with a 3 in the X register (IORESULT = ILLEGAL OPERATION). I/O Firmware Support 69 Chapter 4 Memory Organization a! The Apple Ile’s microprocessor can address 65,536 (64K) memory locations. All of the programmable storage (RAM and ROM) and input and output devices are allocated locations in this 64K address space. Some functions share the same addresses—but not at the same time. For information about these shared address spaces, see the section “Bank-Switched Memory” in this chapter and the sections “Other Uses of I/O Memory Space” and “Expansion ROM Space” in Chapter 6. Original lle The original version of the Apple Ile, as well as the Apple II Plus and Apple II, use the 6502 microprocessor. The 6502 lacks ten instructions and two addressing modes found on the 65C02 of the enhanced Apple Ile, but is otherwise functionally similar. For more information about the differences between the two processors, see Appendix A. In this manual, unless otherwise stated, the two processors are effectively the same. For details of the built-in 1/O features, refer All input and output in the Apple Ile is memory mapped. This means that to the descriptions in Chapters 2 and 3. all devices connected to the Apple Ile appear to be memory locations to the For information about I/O operations with computer. In this chapter, the I/O memory spaces are described simply as peripheral cards, refer to Chapter 6. blocks of memory. Programmers often refer to the Apple Ile’s memory in 256-byte blocks called pages. One reason for this is that a one-byte address counter or index register can specify one of 256 different locations. Thus, page 0 consists of memory locations from 0 to 255 (hexadecimal $00 to $FF), inclusive. Page 1 consists of locations 256 to 511 (hexadecimal $0100 to $01FF); note that the page number is the high-order part of the hexadecimal address. Don’t confuse this kind of page with the display buffers in the Apple IIe, which are sometimes referred to as Page 1 and Page 2. Main Memory Map The map of the main memory address space in Figure 4-1 shows the functions of the major areas of memory. For more details on the I/O space from 48K to 52K ($C000 through $CFFF), refer to Chapter 2 and Chapter 6: the bank-switched memory in the memory space from 52K to 64K ($D000 through $FFFF) is described in the section “Bank-Switched Memory” later in this chapter. 72 Chapter 4: Memory Organization Figure 4-1. System Memory Map FFFF Bank- Switched RAM 1/0 BFFF 8000 (FFF 4000 OFFF Main Memory Map 73 RAM Memory Allocation As Figure 4-1 shows, the major portion of the Apple Ile’s memory space is allocated to programmable storage (RAM). Figure 4-2 shows the areas allocated to RAM. The main RAM memory extends from location 0 to location 49151 (hex $BFFF), and occupies pages 0 through 191 (hexadecimal $BF). There is also RAM storage in the bank-switched space from 53248 to 65535 (hexadecimal $D000 to $FFFF), described in the section “Bank-Switched Memory” later in this chapter, and auxiliary RAM, described in the section “Auxiliary Memory and Firmware’ later in this chapter. Figure 4-2. RAM Allocation Map Page 2 High-Resolution Graphics Display Buffers Page 1 Page 2 | Text and Low-Resolution Page 1 Graphics Display Buffers ~+——————— Reserved Pages 74 Chapter 4: Memory Organization Reserved Memory Pages SESE = SS SSS Most of the Apple Ile’s RAM is available for storing your programs and data. However, a few RAM pages are reserved for the use of the Monitor firmware and the BASIC interpreters. The reserved pages are described in the following sections. Important! The system does not prevent your using these pages, but if you do use them, you must be careful not to disturb the system data they contain, or you will cause the system to malfunction. Page Zero Several of the 65C02 microprocessor’s addressing modes require the use of addresses in page zero, also called zero page. The Monitor, the BASIC interpreters, DOS 3.3, and ProDOS all make extensive use of page zero. To use indirect addressing in your assembly-language programs, you must store base addresses in page zero. At the same time, you must avoid interfering with the other programs that use page zero—the Monitor, the BASIC interpreters, and the disk operating systems. One way to avoid conflicts is to use only those page-zero locations not already used by other programs. Tables 4-1 through 4-5 show the locations in page zero used by the Monitor, Applesoft BASIC, Integer BASIC, DOS 3.3, and ProDOS. As you can see from the tables, page zero is pretty well used up, except for a few bytes here and there. It’s hard to find more than one or two bytes that aren’t used by either BASIC, ProDOS, the Monitor, or DOS. Rather than trying to squeeze your data into an unused corner, you may prefer a safer alternative: save the contents of part of page zero, use that part, then restore the previous contents before you pass control to another program. The 65C02 Stack The 65C02 microprocessor uses page 1 as the stack—the place where subroutine return addresses are stored, in last-in, first-out sequence. Many programs also use the stack for temporary storage of the registers (via push and pull operations). You can do the same, but you should use it sparingly. The stack pointer is eight bits long, so the stack can hold only 256 bytes of information at a time. When you store the 257th byte in the stack, the stack pointer repeats itself, or wraps around, so that the new byte replaces the first byte stored, which is now lost. This writing over old data is called stack overflow, and when it happens, the program continues to run normally until the lost information is needed, whereupon the program terminates catastrophically. RAM Memory Allocation fis The Input Buffer The GETLN input routine, which is used by the Monitor and the BASIC interpreters, uses page 2 as its keyboard-input buffer. The size of this buffer sets the maximum size of input strings. (Note: Applesoft uses only the first 237 bytes, although it permits you to type in 256 characters.) If you know that you won't be typing any long input strings, you can store temporary data at the upper end of page 2. Link-Address Storage For more information about links, see the The Monitor, ProDOS, and DOS 8.3 all use the upper part of page 3 for link section “Changing the Standard I/O Links” addresses or vectors. in Chapter 6. BASIC programs sometimes need short machine-language routines. These routines are usually stored in the lower part of page 3. The Display Buffers The primary text and low-resolution-graphics display buffer occupies memory pages 4 through 7 (locations 1024 through 2047, hexadecimal $0400 through $07FF). This entire 1024-byte area is called text Page 1, and it is not usable for program and data storage. There are 64 locations in this area that See Chapter 6 for information on the are not displayed on the screen; these locations are reserved for use by the memory locations that are reserved for peripheral cards. peripheral cards. Text Page 2, the alternate text and low-resolution-graphics display buffer, occupies memory pages 8 through 11 (locations 2048 through 3071, hexadecimal $0800 through $0BFF). Most programs do not use Page 2 for displays, so they can use this area for program or data storage. The primary high-resolution-graphics display buffer, called high-resolution Page 1, occupies memory pages 32 through 63 (locations 8192 through 16383, hexadecimal $2000 through $3FFF). If your program doesnt use high-resolution graphics, this area is usable for programs or data. High-resolution Page 2 occupies memory pages 64 through 95 (locations 16384 through 24575, hexadecimal $4000 through $5FFF). Most programs use this area for program or data storage. For more information about the display The primary double-high-resolution-graphics display buffer, called buffers, see the section “Video Display double-high-resolution Page 1, occupies memory pages 32 through 63 Pages” in Chapter 2. (locations 8192 through 16383, hexadecimal $2000 through $8FFF') in both main and auxiliary memory. If your program doesn’t use high-reso lution or double-high-resolution graphics, this area of main memory is usabLe for programs or data. 76 Chapter 4: Memory Organization Table 4-1. Monitor Zero-Page Use High Nibble Low Nibble of Address of Address $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $A $B SC $D SE SF $00 $10 ex $20 e e e °® e @ 2) @ @ o e e $30 @ eo eo °®@ e @ e @ e oO e e $40 @ oO e @ e @ e e $50 @ ‘e) $60 $70 $80 $90 SA0 $B0 $C0 $D0 $0 SFO * Byte used in original Apple Ile ROMs, now free. Table 4-2. Applesoft Zero-Page Use High Nibble Low Nibble of Address of Address $0 $4 $5 $6 $7 $8 $9 $A $B SC SD $E $F $00 $10 $20 $30 $40 $50 $60 $70 $80 $90 SA0 $B0 $C0 3D0 $E0 SFO RAM Memory Allocation i Table 4-3. Integer BASIC Zero-Page Use High Nibble Low Nibble of Address of Address $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $A $B SC $D $E $F $00 0 $10 $20 $30 $40 $50 $60 $70 $80 $90 $A0 $B0 $C0 $D0 SEO SFO Table 4-4. DOS 8.3 Zero-Page Use High Nibble Low Nibble of Address of Address $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $A $B SC $D SE $F $00 $10 $20 oO ® e ® @ ® ® $30 e e e @ e ® $40 ® @ ® ® @ e © e oO @ e e e $50 $60 e e e oO 370 © $80 $90 $A0 $B0 ° $C0 e ® ® @ $D0 0 SEO SFO 78 Chapter 4: Memory Organization Table 4-5. ProDOS MLI and Disk-Driver Zero-Page Use High Nibble Low Nibble of Address of Address $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $A $B SC $D SE $F $00 ee $10 $20 $30 e @ e e e e $40 ® ® ® @ @ @ ® @ @ ® e @ ® © e $50 $60 $70 $80 $90 SA0 $B0 $C0 3D0 $E0 SFO Bank-Switched Memory The memory address space from 52K to 64K (hexadecimal $D000 through $FFFF) is doubly allocated: it is used for both ROM and RAM. The 12K bytes of ROM (read-only memory) in this address space contain the Monitor and the Applesoft BASIC interpreter. Alternatively, there are 16K bytes of RAM in this space. The RAM is normally used for storing either the Integer BASIC interpreter or part of the Pascal Operating System (purchased separately). You may be wondering why this part of memory has such a split personality. Some of the reasons are historical: the Apple Ile is able to run software written for the Apple II and Apple II Plus because it uses this part of memory in the same way they do. It is convenient to have the Applesoft interpreter in ROM, but the Apple Ile, like an Apple II with a language card, is also able to use that address space for other things when Applesoft is not needed. Bank-Switched Memory 19 You may also be wondering how 16K bytes of RAM is mapped into only 12K bytes of address space. The usual answer is that it’s done with mirrors, and that isn’t a bad analogy: the 4K-byte address space from 52K to 56K (hexadecimal $D000 through $DFFF) is used twice. Switching different blocks of memory into the same address space is called bank switching. There are actually two examples of bank switching going on here: first, the entire address space from 52K to 64K ($D000 through $FFFF) is switched between ROM and RAM, and second, the address space from 52K to 56K ($D000 to $DFFF) is switched between two different blocks of RAM. Figure 4-3. Bank-Switched Memory Map Setting Bank Switches (eee ak Se ee en a | You switch banks of memory in the same way you switch other functions in the Apple Ile: by using soft switches. Read operations to these soft switches do three things: select either RAM or ROM in this memory space; enable or inhibit writing to the RAM (write-protect); and select the first or second 4K-byte bank of RAM in the address space $D000 to $DFFF. AWarning Do not use these switches without careful planning. Careless switching between RAM and ROM is almost certain to have catastrophic effects on your program. 80 Chapter 4: Memory Organization Table 4-6 shows the addresses of the soft switches for enabling all combinations of reading and writing in this memory space. All of the hexadecimal values of the addresses are of the form $C08x. Notice that several addresses perform the same function: this is because the functions are activated by single address bits. For example, any address of the form $C08x with a 1 in the low-order bit enables the RAM for writing. Similarly, bit 3 of the address selects which 4K block of RAM to use for the address space $D000-$DFFF; if bit 3 is 0, the first bank of RAM is used, and if bit 3 is 1, the second bank is used. When RAM is not enabled for reading, the ROM in this address space is enabled. Even when RAM is not enabled for reading, it can still be written to if it is write-enabled. When you turn power on or reset the Apple Ile, it initializes the bank switches for reading the ROM and writing the RAM, using the second bank of RAM. Note that this is different from the reset on the Apple II Plus, which didn’t affect the bank-switched memory (the language card). On the Apple Ile, you can’t use the reset vector to return control to a program in bank-switched memory, as you could on the Apple II Plus. Reset With Integer BASIC: When you are using Integer BASIC on the Apple Ile, reset works correctly, restarting BASIC with your program intact. This happens because the reset vector transfers control to DOS, and DOS resets the switches for the current version of BASIC. Bank-Switched Memory 8] Table 4-6. Bank Select Switches Note: R means read the location, W means write anything to the location, R/W means read or write, and R7 means read the location and then check bit 7. Name Action Hex Function R $C080 Read RAM; no write; use $D000 bank 2. RR $C081 Read ROM; write RAM; use $D000 bank 2. R $C082 Read ROM; no write; use $D000 bank 2. RR $C0838 Read and write RAM; use $D000 bank 2. R $C088 Read RAM; no write; use $D000 bank 1. RR $C089 Read ROM; write RAM; use $D000 bank 1. R $C08A Read ROM; no write; use $D000 bank 1. RR $C08B _—«Read and write RAM; use $D000 bank 1. RDBNK2 ~—R7 $CO11 Read whether $D000 bank 2.(1) or bank 1 (0). RDLCRAM R7 $C012 Reading RAM (1) or ROM (0). ALTZP W $C008 Off: use main bank, page 0 and page 1. ALTZP W $C009 On: use auxiliary bank, page 0 and page 1. RDALTZP = R7 $C016 Read whether auxiliary (1) or main (0) bank. Reading and Writing to RAM Banks: Note that you can’t read one RAM bank and write to the other; if you select either RAM bank for reading, you get that one for writing as well. Reading RAM and ROM: You can’t read from ROM in part of the bank-switched memory and read from RAM in the rest: specifically, you can’t read the Monitor in ROM while reading bank-switched RAM. If you want to use the Monitor firmware with a program in bank-switched RAM, copy the Monitor from ROM (locations $F800 through $FFCB) into bank-switched RAM. You can’t do this from Pascal or ProDOS. Chapter 4: Memory Organization To see how to use these switches, look at the following section of an assembly-language program: C8 LDA $C 983 *SELECT 2@ND 4K BANK & READ/WRITE C8 LDA $C883 *BY TWO CONSECUTIVE READS LDA #$D8 "SET UPs« STA BEGIN * as NEW... LDA *SFF *...MAIN-MEMORY... STA END *,..-POINTERS... C9 JSR RAMTST *...FOR 12K BANK C8 LDA $CO8B *SELECT 1ST 4K BANK C9 JSR RAMTST *USE ABOVE POINTERS C8 LDA $C 888 *SELECT 1ST BANK & WRITE PROTECT LDA #$80 INC TSTNUM C9 JSR WPTSINIT C8 LDA $C 080 *SELECT 2@ND BANK & WRITE PROTECT INC TSTNUM LDA #PAT12K C9 JSR WPTSINIT Cé LDA $CO8B *SELECT 1ST BANK & READ/WRITE Cé LDA $CO88B *BY TWO CONSECUTIVE READS INC RWMODE *FLAG RAM IN READ/WRITE INC TSTNUM LDA #PAT4K C9 JSR WPTSINIT The LDA instruction, which performs a read operation to the specified memory location, is used for setting the soft switches. The unusual sequence of two consecutive LDA instructions performs the two consecutive reads that write-enable this area of RAM; in this case, the data that are read are not used. Reading Bank Switches —EeEL—EEEEE—ES You can read which language card bank is currently switched in by reading the soft switch at $C011. You can find out whether the language card or ROM is switched in by reading $C012. The only way that you can find out whether the language card RAM is write-enabled or not is by trying to write some data to the card’s RAM space. Bank-Switched Memory 83 Auxiliary Memory and Firmware I a ea ee ea ee ee eee By installing an optional card in the auxiliary slot, you can add more memory to the Apple Ie. One such card is the Apple Ile 80-Column Text Card, which has 1K bytes of additional RAM for expanding the text display from 40 columns to 80 columns. Another optional card, the Apple Ile Extended 80-Column Text Card, has 64K of additional RAM. A 1K-byte area of this memory serves the same purpose as the memory on the 80-Column Text Card: expanding the text display to 80 columns. The other 63K bytes can be used as auxiliary program and data storage. If you use only 40-column displays, the entire 64K bytes is available for programs and data. AWanrning Do not attempt to use the auxiliary memory from a BASIC program. The BASIC interpreter uses several areas in main RAM, including the stack and the zero page. If you switch to auxiliary memory in these areas, the BASIC interpreter fails and you must reset the system and start over. As you can see by studying the memory map in Figure 4-4, the au xiliary memory is broken into two large sections and one small one. The largest section is switched into the memory address space from 512 to 49151 ($0200 through $BFFF). This space includes the display buffer pages: as described in the section “Text Modes” in Chapter 2, space in auxiliary memory is used for one half of the 80-column text display. You can switch to the auxiliary memory for this entire memory space, or you can switch just the display pages: see the next section, “Memory Mode Switching.” Soft Switches: If the only reason you are using auxiliary memory 1s for the 80-column display, note that you can store into the display page in auxiliary memory by using the 80STORE and PAGE2 soft switches described in the section “Display Mode Switching” in Chapter 2. The other large section of auxiliary memory is switched into the memory address space from 52K to 64K ($D000 through $FFFF). This mernory space and the switches that control it are described earlier in this chapter in the section “Bank-Switched Memory.” If you use the auxiliary RAM im this space, the soft switches have the same effect on the auxiliary RAM that they do on the main RAM: the bank switching is independent of the auxiliary-RAM switching. 84 Chapter 4: Memory Organization Figure 4-4. Memory Map With Auxiliary Memory FFFF Main Auxiliary Bank- Bank- Switched Switched RAM RAM aT BFFF 1/0 Main RAM 8000 | Auxiliary (FFF RAM 6000 5FFF 4000 High-Resolution _ OF FF Graphics Display Buffers Text and Low-Resolution a Graphics Display Buffers Stack and Zero Page—> Bank Switches: Note that the soft switches for the bank-switched memory, described in the previous section, do not change when you switch to auxiliary RAM. In particular, if ROM is enabled in the bank-switched memory space before you switch to auxiliary memory, the ROM will still be enabled after you switch. Any time you switch the bank-switched section of auxiliary memory in and out, you must also make sure that the bank switches are set properly. When you switch in the auxiliary RAM in the bank-switched space, you also switch the first two pages, from 0 to 511 ($0000 through $01FF). This part of memory contains page zero, which is used for important data and base addresses, and page one, which is the 65C02 stack. The stack and zero page are switched this way so that system software running in the Auxiliary Memory and Firmware 85 bank-switched memory space can maintain its own stack and zero page while it manipulates the 48K address space (from $0200 to $BFFF’) in either main memory or auxiliary memory. Memory Mode Switching —S=S a eSeee ee Switching the 48K section of memory is performed by two soft switches: the switch named RAMRD selects main or auxiliary memory for reading, and the one named RAMWRT selects main or auxiliary memory for writing. As shown in Table 4-7, each switch has a pair of memory locations dedicated to it, one to select main memory, and the other to select auxiliary memory. Enabling the read and write functions independently makes it possible for a program whose instructions are being fetched from one memory space to store data into the other memory space. AWarning Do not use these switches without careful planning. Careless switching between main and auxiliary memories is almost certain to have catastrophic effects on the operation of the Apple Ile. For example, if you switch to auxiliary memory with no card in the slot, the program that is running will stop and you will have to reset the Apple Ile and start over. Writing to the soft switch at location $C003 turns RAMRD on and enables auxiliary memory for reading: writing to location $C002 turns RAMRD off and enables main memory for reading. Writing to the soft switch at location $C005 turns RAMWRT on and enables the auxiliary memory for writing; writing to location $C004 turns RAMWRT off and enables main memory for writing. By setting these switches independently, you can use any of the four combinations of reading and writing in main or auxiliary memory. Auxiliary memory corresponding to text Page 1 and high-resolution graphics Page 1 can be used as part of the address space from $0200 to $BFFF by using RAMRD and RAMWRT as described above. These areas in auxiliary RAM can also be controlled separately by using the switches described in the section “Display Mode Switching” in Chapter 2. Those switches are named 80STORE, PAGE2, and HIRES. As shown in Table 4-7, the 80STORE switch functions as an enabling switch: with it on, the PAGE2 switch selects main memory or auxiliary memory. With the HIRES switch off, the memory space switched by PAGE2 is the text Page 1, from $0400 to $07FF; with HIRES on, PAGE2 switches both text Page 1 and high-resolution graphics Page 1, from $2000 to $3FFF. If you are using both the auxiliary-RAM control switches and the auxiliary-display-page control switches, the display-page control switches take priority: if 830STORE is off, RAMRD and RAMWRT work for the entire 86 Chapter 4: Memory Organization memory space from $0200 to $BFFF, but if 80STORE is on, RAMRD and RAMWERT have no effect on the display page. Specifically, if 80STORE is on and HIRES is off, PAGE2 controls text Page 1 regardless of the settings of RAMRD and RAMWRT. Likewise, if 80STORE and HIRES are both on, PAGE2 controls both text Page 1 and high-resolution graphics Page 1, again regardless of RAMRD and RAMWRT. A single soft switch named ALTZP (for alternate zero page) switches the bank-switched memory and the associated stack and zero page area The next section, “Auxiliary-Memory between main and auxiliary memory. As shown in Table 4-7, writing to Subroutines,” describes firmware that you location $C009 turns ALTZP on and selects auxiliary-memory stack and can call to help you switch between main zero page; writing to the soft switch at location $C008 turns ALTZP off and and auxiliary memory. selects main-memory stack and zero page for both reading and writing. Table 4-7. Auxiliary-Memory Select Switches. Name Function Location Notes Hex Decimal RAMRD _ Read auxiliary memory $C0038 49155 -16381 Write Read main memory $0002 49154 -16382 Write Read RAMRD switch $0013 49171 -16865 Read RAMWRT Write auxiliary memory $C005 49157 +-16879 Write Write main memory $C004 49156 -16880 Write Read RAMWRT switch $0014 49172 -163854 Read SOSTORE On: access display page $C001 49153-16883 — Write Off: use RAMRD, RAMWRT $C000 49152-16384 Write Read 80STORE switch $C018 49176 -16360 Read PAGE2 _ Page.2 on (aux. memory) $C055 492387 -16299 * Page 2 off (main memory) $C054 49236 -16800 * Read PAGE2 switch $C01C 49180 -16356 Read HIRES On: access high-res. pages $C057 49239 -16297 ft Off: use RAMRD, RAMWRT _ $C056 49238 -16298 t Read HIRES switch $COID 49181 -16855 Read ALTZP Auxiliary stack & z.p. $C009 49161 -16373 ~~ Write Main stack & zero page $C008 49160 -16874 Write Read ALTZP switch $C016 49174 -16852 Read * When 80STORE is on, the PAGE2 switch selects main or auxiliary display memory. TtWhen 80STORE is on, the HIRES switch enables you to use the PAGE2 switch to switch between the high-resolution Page-1 area in main memory or auxiliary memory. Auxiliary Memory and Firmware 87 There are three more locations associated with the auxiliary-memory switches. The high-order bits of the bytes you read at these locations tell you the settings of the three soft switches described above. The byte you read at location $C013 has its high bit set to 1 if RAMRD is on (auxiliary When these switches are on, auxiliary memory is read-enabled), or 0 if RAMRD is off (the 48K block of main memory is being used; when they are off, memory is read-enabled). The byte at location $C014 has its high bit set to 1 main memory is being used. if RAMWRT is on (auxiliary memory is write-enabled), or 0 if RAMWRT is off (the 48K block of main memory is write-enabled). The byte at location $C016 has its high bit set to 1 if ALTZP is on (the bank-switched area, stack, and zero page in the auxiliary memory are selected), or 0 if ALTZP is off (these areas in main memory are selected). Sharing Memory: In order to have enough memory locations for all of the soft switches and remain compatible with the Apple II and Apple II Plus, the soft switches listed in Table 4-7 share their memory locations with the keyboard functions listed in Table 2-2. The operations—read or write—shown in Table 4-7 for controlling the auxiliary memory are just the ones that are not used for reading the keyboard and clearing the strobe. Auxiliary-Memory Subroutines SSS SSS ee If you want to write assembly-language programs that use auxiliary memory but you don’t want to manage the auxiliary memory yourself, you can use the built-in auxiliary-memory subroutines. These subroutines make it possible to use the auxiliary memory without having to manipulate the soft switches described in the previous section. important! The subroutines described below make it easier to use auxiliary memory, but they do not protect you from errors. You still have to plan your use of auxiliary memory to avoid catastrophic effects on your program. You use these built-in subroutines the same way you use the I/O subroutines described in Chapter 3: by making subroutine calls to their starting locations. Those locations are shown in Table 4-8. Table 4-8. 48K RAM Transfer Routines Name Action Hex Function AUXMOVE JSR $C312 Moves data blocks between main and auxiliary 48K memory. XFER JMP $C314 Transfers program control between main and auxiliary 48K memory. 88 Chapter 4: Memory Organization Moving Data to Auxiliary Memory In your assembly-language programs, you can use the built-in subroutine named AUXMOVE to copy blocks of data from main memory to auxiliary memory or from auxiliary memory to main memory. Before calling this routine, you must put the data addresses into byte pairs in page zero and set the carry bit to select the direction of the move—main to auxiliary or auxiliary to main. AWarning Don't try to use AUXMOVE to copy data in page zero or page one (the 65C02 stack) or in the bank-switched memory ($D000-$FFFF). AUXMOVE uses page zero all during the copy, so it can’t handle moves in the memory space switched by ALTZP. The pairs of bytes you use for passing addresses to this subroutine are called Al, A2, and A4, and they are used for parameter passing by several of the Apple Ile’s built-in routines. The addresses of these byte pairs are shown in Table 4-9. Table 4-9. Parameters for AUXMOVE Routine Note: The X, Y, andA registers are preserved by AUXMOVE. Name Location Parameter Passed Carry 1 = Move from main to auxiliary memory 0 = Move from auxiliary to main memory A1L $3C Source starting address, low-order byte AlH $38D Source starting address, high-order byte A2L $3E Source ending address, low-order byte A2H $3F Source ending address, high-order byte A4L $42 Destination starting address, low-order byte A4H $43 Destination starting address, high-order byte Put the addresses of the first and last bytes of the block of memory you want to copy into Al and A2. Put the starting address of the block of memory you want to copy the data to into A4. The AUXMOVE routine uses the carry bit to select the direction to copy the data. To copy data from main memory to auxiliary memory, set the carry bit; to copy data from auxiliary memory to main memory, clear the carry bit. Auxiliary Memory and Firmware 89 When you make the subroutine call to AUXMOVE, the subroutine copies the block of data as specified by the A byte pairs and the carry bit. When it is finished, the accumulator and the X and Y registers are just as they were when you called AUXMOVE. Transferring Control to Auxiliary Memory You can use the built-in routine named XFER to transfer control to and from program segments in auxiliary memory. You must set up three parameters before using XFER: the address of the routine you are transferring to, the direction of the transfer (main to auxiliary or auxiliary to main), and which page zero and stack you want to use. Table 4-10. Parameters for XFER Routine Note: The X, Y, andA parameters are preserved by XFER. Name or Location Parameter Passed Carry 1 = Transfer from main to auxiliary memory ( = Transfer from auxiliary to main memory Overflow 1 = Use page zero and stack in auxiliary memory () = Use page zero and stack in main memory $038ED Program starting address, low-order byte $03EE Program starting address, high-order byte Put the transfer address into the two bytes at locations $03ED and $03EE, with the low-order byte first, as usual. The direction of the transfer is controlled by the carry bit: set the carry bit to transfer to a program in auxiliary memory; clear the carry bit to transfer to a program in main memory. Use the overflow bit to select which page zero and stack you want to use: clear the overflow bit to use the main memory; set the overflow bit to use the auxiliary memory. After you have set up the parameters, pass control to the XFER routine by a jump instruction, rather than a subroutine call. XFER saves the accumulator and the transfer address on the current stack, then sets up the soft switches for the parameters you have selected and jumps to the new program. 90 Chapter 4: Memory Organization AWarning It is the programmer's responsibility to save the current stack pointer at $0100 in main memory and the alternate stack pointer at $0101 in auxiliary memory before calling XFER and to restore them after regaining control. Failure to do so will cause program errors. The Reset Routine To put the Apple Ile into a known state when it has just been turned on or after a program has malfunctioned, there is a procedure called the reset routine. The reset routine is built into the Apple Ile’s firmware, and it is initiated any time you turn power on or press while holding down (CONTROL].The reset routine puts the Apple Ile into its normal operating mode and restarts the resident program. When you initiate a reset, hardware in the Apple Ile sets the memory-controlling soft switches to normal: main board RAM and ROM are enabled, and, if there is an 80-column text card in the auxiliary slot, expansion slot 3 is allocated to the built-in 80-column firmware. Auxiliary RAM is disabled and the bank-switched memory space is set up to read from ROM and write to RAM, using the second bank at $D000. The reset routine sets the display-controlling soft switches to display 4(-column text Page 1 using the primary character set, then sets the window equal to the full 40-column display, puts the cursor at the bottom of the screen, and sets the display format to normal. For information about the I/O links, see the The reset routine sets the keyboard and display as the standard input and section “Changing the Standard I/O Links” output devices by loading the standard I/O links. It turns annunciators 0 in Chapter 6. and 1 off and annunciators 2 and 8 on, clears the keyboard strobe, turns off For more information about peripheral-card any active peripheral-card ROM and outputs a bell (tone). ROM, see the section ‘‘Peripheral-Card ROM Space” in Chapter 6. The Apple Ile has three types of reset: power-on reset, also called cold-start reset; warm-start reset; and forced cold-start reset. The procedure described above is the same for any type of reset. What happens next depends on the reset vector. The reset routine checks the reset vector to determine whether it is valid or not, as described later in this chapter in the section “The Reset Vector.” If the reset was caused by turning the power on, the vector will not be valid, and the reset routine will perform the cold-start procedure. If the vector is valid, the routine will perform the warm-start procedure. The Reset Routine Q] The Cold-Start Procedure If the reset vector is not valid, either the Apple Ile has just been turned on or something has caused memory contents to be changed. The reset routine clears the display and puts the string Apple //e (Apple 1{ onan original Ile) at the top of the display. It loads the reset vector and the validity-check byte as described below, then starts checking the expansion slots to see if there is a disk drive controller card in one of them, starting with slot 7 and working down. If it finds a controller card, it initiates the startup (bootstrap) routine that resides in the controller card’s firmware. The startup routine then loads For more information about ProDOS and DOS or ProDOS from the disk in drive 1. When the operating system has the startup procedure, see the ProDOS been loaded, it displays other messages on the screen. If there is no disk in Technical Reference Manual. the disk drive, the drive motor just keeps spinning until you press RESET|. If the reset routine doesn’t find a controller card, or if you press again before the startup procedure has been completed, the reset routine will continue without using the disk, and pass control to the built-in Applesoft interpreter. The Warm-Start Procedure ———SSS————————EESSSSSS_———_SS Aaa Whenever you press when the Apple Ile has already completed a cold-start reset, the reset vector is still valid and it is not necessary to reinitialize the entire system. The reset routine simply uses the vector to transfer control to the resident program, which is normally the built-in Applesoft interpreter. If the resident program is indeed Applesoft, your Applesoft program and variables are still intact. If you are using DOS, it is the resident program and it restarts either Applesoft or Integer BASIC, whichever you were using when you pressed [CONTROL H RESET |. important! A program in bank-switched RAM cannot use the reset vector to regain control after a reset, because the Apple Ile hardware enables ROM in the bank-switched memory space. If you are using Integer BASIC, which is in the bank-switched RAM, you are also using DOS, and it is DOS that controls the reset vector and restarts BASIC. 92 Chapter 4: Memory Organization Forced Cold Start SSS S| If a program has loaded the reset vector to point to the beginning of the program, as described in the next section, pressing causes a warm-start reset that uses the vector to transfer control to that program. If you want to stop such a program without turning the power off and on, you can force a cold-start reset by holding down (G] and (CONTROL}, then pressing and releasing [RESET}. Unconditional Restart: When you want to stop a program unconditionally—for example, to start up the Apple Ile with some other program—you should use the forced cold-start reset, [G}{CONTROL }{ RESET ], instead of turning the power off and on. Whenever you press [CONTROL }{ RESET ],firmware in the Apple Ile always checks to see whether either Apple key is down. If the (é] key is down, with or without the (G) key, the firmware performs the self-test described later in this chapter. If only the [G] key is down, the firmware starts a forced cold-start reset. First, it destroys the program or data in memory by writing two bytes of arbitrary. data into each page of main RAM. The two bytes that get written over in page 3 are the ones that contain the reset vector. The reset routine then performs a normal cold-start reset. The Reset Vector =a ee eee ea When you reset the Apple Ile, the reset routine transfers control to the resident program by means of an address stored in page 3 of main RAM. This address is called a vector because it directs program control to a specified destination. There are several other vector addresses stored in page 3, as shown in Table 4-11, including the interrupt vectors described in the section “Interrupts on the Enhanced Apple Ile” in Chapter 6, and the ProDOS and DOS vectors described in the ProDOS Technical Reference Manual and the Apple IT DOS Programmer's Manual. The cold-start reset routine stores the starting address of the built-in Applesoft interpreter, low-order byte first, in the reset vector address at locations 1010 and 1011 (hexadecimal $03F2 and $03F3). It then stores 4 validity-check byte, also called the power-up byte, at location 1012 (hexadecimal $03F4). The validity-check byte is computed by performing an exclusive-OR of the second byte of the vector with the constant 165 (hexadecimal $A5). Each time you reset the Apple Ile, the reset routine uses this byte to determine whether the reset vector is still valid. The Reset Routine 93 You can change the reset vector so that the reset routine will transfer control to your program instead of to the Applesoft interpreter. For this to work, you must also change the validity-check byte to the exclusive-OR of the high-order byte of your new reset vector with the constant 165 ($A5). If you fail to do this, then the next time you reset the Apple Ile, the reset routine will determine that the reset vector is invalid and perform a cold-start reset, eventually transferring control to the disk startup routine or to Applesoft. The reset routine has a subroutine that generates the validity-check byte for the current reset vector. You can use this subroutine by doing a subroutine call to location -1169 (hexadecimal $FB6F). When your program finishes, it can return the Apple Ile to normal operation by restoring the original reset vector and again calling the subroutine to fix up the validity-check byte. Table 4-11. Page 3 Vectors Vector Address Vector Function $3F0 Address of the subroutine that handles BRK requests (normally $3F1 $59, $FA). $3F2 Reset vector (see text). $3F3 $3F4 Power-up byte (see text). $3F5 Jump instruction to the subroutine that handles Applesoft & $3F6 commands (normally $4C, $58, $FF). $3F7 $3F8 Jump instruction to the subroutine that handles user $3F9 (CONTROL }{y] commands. $3FA $3FB Jump instruction to the subroutine that handles non-rmaskable $3FC interrupts. $3FD See “The User’s Interrupt Handler at $3FE” $3FE Interrupt vector (address of the subroutine that handLes in Chapter 6. $3FF interrupt requests). 94 Chapter 4: Memory Organization Automatic Self-Test SSS See as ee ee) If you reset the Apple Ile by holding down (#6) and while pressing and releasing (RESET|,the reset routine will start running the built-in self-test. Successfully running this test assures you that the Apple Ile is operational. AWarning The self-test routine tests the Apple Ile’s programmable memory by writing and then reading it. All programs and data in programmable memory when you run the self-test are destroyed. The self-test takes several seconds to run. The screen will display some patterns in low resolution mode which will change rapidly just before the self-test finishes. If the test finishes normally, the Apple Ile displays System OK and waits for you to restart the system. If you have been running a program, some soft switches might be on when you run the self-test. If this happens, the self-test will display a message such as IOU FLAG ES: 1 Turn the power off for several seconds, then turn it back on and run the self-test again. If it still fails, there is really something wrong; to get it corrected, contact your authorized Apple dealer for service. The Reset Routine 95 Chapter 5 Using the Monitor 97 The System Monitor is a set of subroutines in the Apple Ile firmware. The Monitor provides a standard interface to the built-in I/O devices described in Chapter 2. The I/O subroutines described in Chapter 3 are part of the System Monitor. ProDOS, DOS 3.3, and the BASIC interpreters use these subroutines by The starting addresses for all of the direct calls to their starting locations, as described for the I/O subroutines standard subroutines are listed in in Chapter 3. Appendix B. If you wish, you can call the standard subroutines from your programs in the same fashion. You can perform most of the Monitor functions directly from the Keyboard. This chapter tells you how to use the Monitor to O look at one or more memory locations oO change the contents of any location O write programs in machine language to be executed directly by the Apple Ile’s microprocessor o save blocks of data and programs onto cassette tape and read them back in again move and compare blocks of memory search for data bytes and ASCII characters in memory invoke other programs from the Monitor QO invoke the Mini-Assembler. a O Invoking the Monitor The System Monitor starts at memory location $FF69 (decimal 65385 or -l51). To invoke the Monitor, you make a CALL statement to thas location from the keyboard or from a BASIC program. When the Monitor is running, its prompting character, an asterisk (*), appears on the left side off the display screen, followed by a blinking cursor. To use the Monitor, you type commands at the keyboard. When you have finished using the Monitor, you return to the BASIC language you. were previously using by pressing [CONTROL }{ RESET |, by pressing then [RETURN], or by typing 3D9G, which execute s the resident program—usually Applesoft—whose address is stored in a jump instruction at location $3D0. 98 Chapter 5: Using the Monitor Syntax of Monitor Commands To give acommand to the Monitor, you type a line on the keyboard, then press [RETURN}.The Monitor accepts the line using the standard I/O subroutine GETLN, described in Chapter 3. A Monitor command can be up to 255 characters in length, ending with a carriage return. A Monitor command can include three kinds of information: addresses, data values, and command characters. You type addresses and data values in hexadecimal notation. Hexadecimal notation uses the ten decimal digits (0-9) and the first six letters (A-F) to represent the sixteen values from (0 to 15. A pair of hexadecimal digits represent values from 0 to 255, corresponding to a byte, and a group of four hexadecimal digits can represent values from 0 to 65,536, corresponding to a word. Any address in the Apple Ile can be represented by four hexadecimal digits. When the command you type calls for an address, the Monitor accepts any group of hexadecimal digits. If there are fewer than four digits in the group, it adds leading zeros; if there are more than four hexadecimal digits, the Monitor uses only the last four digits. It follows a similar procedure when the command syntax calls for two-digit data values. See “Summary of Monitor Commands” at Each command you type consists of one command character, usually the the end of this chapter. first letter of the command name. When the command is a letter, it can be either uppercase or lowercase. The Monitor recognizes 28 different command characters. Some of them are punctuation marks, some are letters, and some are control characters. Note: Although the Monitor recognizes and interprets control characters typed on an input line, they do not appear on the screen. This chapter contains many examples of the use of Monitor commands. In the examples, the commands and values you type are shown in a normal typeface and the responses of the Monitor are in a computer typeface. Of course, when you perform the examples, all of the characters that appear on the display screen will be in the same typeface. Some of the data values displayed by your Apple Ile may differ from the values printed in these examples, because they are variables stored in programmable memory. Syntax of Monitor Commands 99 Monitor Memory Commands When you use the Monitor to examine and change the contents of memory, it keeps track of the address of the last location whose value you inquired about and the address of the location that is next to have its value changed. These are called the last opened location and the next changeable location. Examining Memory Contents a SC ees | When you type the address of a memory location and press [RETURN], the Monitor responds with the address you typed, a dash, a space, and the value stored at that location, like this: * E000 EG80- 20 #33 8033- AA # Each time the Monitor displays the value stored at a location, it saves the address of that location as the last opened location and as the next changeable location. Memory Dump A When you type a period (.) followed by an address, and then press (RETURN],the Monitor displays a memory dump: the data values stored at all the memory locations from the one following the last opened |ocation to the location whose address you typed following the period. The Monitor saves the last location displayed as both the last opened location and the next changeable location. In these examples, the amount of data displayed by the Monitor depends on how much larger than the last opened location the address after the period is. Chapter 5: Using the Monitor *20 8020- 00 * 2B 8821- 28 66 18 BOF BC 68 BB 8828- ASB 86 DB B87 *300 8388- 99 * 315 6301- BS 66 88 BA BA BA 99 6368- 68 68 C8 D® F4 AGB 2B AD 8318- 69 8S 27 AD CC 63 * 32A 8316- 85 41 6318- 84 48 BA 4A 4A 4A 4A 89 6328- CHO 8S 3F AID SD 8S 3E 28 8328- 43 863 20 # When the Monitor performs a memory dump, it starts at the location immediately following the last opened location and displays that address and the data value stored there. It then displays the values of successive locations up to and including the location whose address you typed, but only up to eight values on a line. When it reaches a location whose address is a multiple of eight—that is, one that ends with an 8 or a 0—it displays that address as the beginning of a new line, then continues displaying more values. After the Monitor has displayed the value at the location whose address you specified in the command, it stops the memory dump and sets that location as both the last opened location and the next changeable location. If the address specified on the input line is less than the address of the last opened location, the Monitor displays only the address and value of the location following the last opened location. Monitor Memory Commands 101 You can combine the two commands, opening a location and dum ping memory, by simply concatenating them: type the first address, a period, and the second address. This combination of two addresses separated by a period is called a memory range. *300.32F §83606- 99 BS 88 868 BA BA BA 99 6368- 86 868 C8 DB F4 AG 2B AY 6318- 69 85 27 AD CC 83 85 41 §8318- 84 468 BA 4A 4A 4A 4A B89 8328- C8 8S 3F AS SD 85S 3E 28 8328- 43 63 28 46 O93 AS 3D 4D *30.40 8630- AA 68 FF AA BS C2 B65 Ce 8838- 1B FD D# 83 3C 68 48 BB 8648- 38 *£015.E025 E@1G6- 4C ED FD E#18- AQ 28 CS 24 BB BC AQ BD E@20- AB 87 28 ED FD AQ + Pressing by itself causes the Monitor to display one line of a memory dump; that is, a memory dump from the location following the last opened location to the next multiple-of-eight boundary. The Monitor saves the address of the last location displayed as the last opened location and the next changeable location. *0 880S- 88 *| RETURN 86 88 *| RETURN 6808- 66 68 08 66 OB 8B B88 8B *32 8832- FF *LRETURN AA 88 C2 85 C2 *LRETURN | 6038- 1B FD D@ 63 3C 68 3F B28 # 102 Chapter 5: Using the Monitor Changing Memory Contents FF eR i eo ee a ee eee) The previous section showed you how to display the values stored in the Apple Ile’s memory; this section shows you how to change those values. You can change any location in RAM—programmable memory—and you can also change the soft switches and output devices by changing the locations assigned to them. AWarning Use these commands carefully. If you change the zero-page locations used by Applesoft, ProDOS, or DOS, you may lose programs or data stored in memory. Changing One Byte SS SS eee The previous commands keep track of the next changeable location; these commands make use of it. In the next example, you open location 0, then type a colon (:) followed by a value. *() O6008- 96 *:5F The contents of the next changeable location have just been changed to the value you typed, as you can see by examining that location: *() 8000- SF # You can also combine opening and changing into one operation by typing an address followed by a colon and a value. In the example, you type the address again to verify the change. #302:42 #302 6382- 42 # When you change the contents of a location, the value that was contained in that location disappears, never to be seen again. The new value will remain until you replace it with another value. Changing Memory Contents 103 Changing Consecutive Locations You don’t have to type a separate command with an address, a colon, a value, and for each location you want to change. You can change the values of up to 85 consecutive locations at a time (or even more, if you omit leading zeros from the values) by typing only the initial address and colon followed by all the values separated by spaces, and ending with (RETURN].The Monitor will duly store the consecutive values in consecutive locations, starting at the location whose address you typed. After it has processed the string of values, it takes the location following the last changed location as the next changeable location. Thus, you can continue changing consecutive locations without typing an address on the next input line by typing another colon and more values. In these examples, you first change some locations, then examine them to verify the changes. *300:69 01 20 ED FD 4003 *300 8380- 69 *[RETURN 01 20 ED FD 4C a8 O63 *10:0128 #4567 #10.17 6010- 88 81 82 83 B84 8S O86 B7 # ASCIl Input Mode —————— eee ered The enhanced Apple Ile has an ASCII input mode that lets you enter ASCII characters just as you can their hexadecimal ASCII equivalents bry preceding the literal character with an apostrophe (’). This means that ’A is the same as $C1 and ’Bis the same as $C2 to the Monitor. The ASCII value for any character following an apostrophe is used by the Monitor. Chapter 5: Using the Monitor Each character to be placed in memory should be delimited by a leading apostrophe (’) and a trailing space. The only exception to this rule is that the last character in the line is followed with a return character instead of a space. The following example would enter the string “Hooray for sushi!” at $0300 in memory. *800:'H ’o’o’r’a’y’ 'f’o’r’ ’s’u’s’h'i’! Important! ASCII input mode sets the high bit of the code for a character that you enter. So ’A will equal $C1, not $41. Original lle | The original Apple Ile does not have an ASCII input mode. Moving Data in Memory Se ae EE ei 8 et ein You can copy a block of data stored in a range of memory locations from one area in memory to another by using the Monitor’s MOVE command. To move a range of memory, you must tell the Monitor both where the data is now situated in memory (the source locations) and where you want the copy to go (the destination locations). You give this information to the Monitor by means of three addresses: the address of the first location in the destination and the addresses of the first and last locations in the source. You specify the starting and ending addresses of the source range by separating them with a period. You separate the destination address from the range addresses with a less-than character (<_), which you may think of as an arrow pointing in the direction of the move. Finally, you tell the Monitor that this is a MOVE command by typing the letter M (in either lowercase or uppercase). The format of the complete MOVE command looks like this: \destination| < jstart} . jend} M When you type the actual command, the words in braces should be replaced by hexadecimal addresses, and the braces and spaces should be omitted. Changing Memory Contents 105 Here are some examples of Monitor commands, including some memory moves. First, you examine the values stored in one range of memory, then store several values in another range of memory; the actual MOV E commands end with the letter M. *(0.F G@6088- SF 68 85 87 B88 86 86 6B 668608- 669 66 868 86 68 66 88 68 *300:A9 8D 20 ED FD AQ 45 20 DA FD 4C 00 03 *300.30C 83668- AS BD 26 ED FD AQ 45 28 6368- DA FD 4C 68 63 *()<300.300M *().C 66080- AY 8D 26 ED FD AS 45 28 8868- DA FD 4C 68 63 *310<8.AM *310.312 8319- DA FD 4C *2<7.9M *0.C 6688- AO 8D 26 DA FD AS 45 28 6688- DA FD 4C 88 83 # The Monitor moves a copy of the data stored in the source range of locations to the destination locations. The values in the source range are left undisturbed. The Monitor remembers the last location in the source range as the last opened location, and the first location in the source range as the next changeable location. If the second address in the source range specification is less than the first, then only one value (that of the first location in the range) will be moved. If the destination address of the MOVE command is inside the source range of addresses, then strange (and sometimes wonderful) things happen: the See the section “Special Tricks With the locations between the beginning of the source range and the destination Monitor” later in this chapter for an address are treated as a sub-range and the values in this sub-range are interesting application of this feature. replicated throughout the source range. 106 Chapter 5: Using the Monitor Comparing Data in Memory arr ee ee eer ee You can use the VERIFY command to compare two ranges of memory using the same format you use to move a range of memory from one place to another. In fact, the VERIFY command can be used immediately after a MOVE command to make sure that the move was successful. The VERIFY command, like the MOVE command, needs a range and a destination. The syntax of the VERIFY command is {destination} < {start} . {end} V The Monitor compares the values in the source locations with the values in the locations beginning at the destination address. If any values don’t match, the Monitor displays the address at which the discrepancy was found and the two values that differ. In the example, you store data values in the range of locations from 0 to $D, copy them to locations starting at $300 with the MOVE command, and then compare them using the VERIFY command. When you use the VERIFY command after you change the value at location 6 to $E4, it detects the change. *0:D7 F2 E9 F4 F4 E5 EE AO E2 F9 AO C3 C4 C5 *300<0.DM *300<0.DV *6:E4 *300<0.DV 8BBG-E4 CEE) # If the VERIFY command finds a discrepancy, it displays the address of the location in the source range whose value differs from its counterpart in the destination range. If there is no discrepancy, VERIFY displays nothing. The VERIFY command leaves the values in both ranges unchanged. The last opened location is the last location in the source range, and the next changeable location is the first location in the source range, just as in the MOVE command. If the ending address of the range is less than the starting address, the values of only the first locations in the ranges will be See the section “Special Tricks With the compared. Like the MOVE command, the VERIFY command also does Monitor” later in this chapter. unusual things if the destination address is within the source range. Changing Memory Contents 107 Searching for Bytes in Memory ea yee ae es Oe ee el The SEARCH command lets you search for one or two bytes (either hexadecimal values or ASCII characters) in a range of memory. You must type in the ASCII string (or hexadecimal number or numbers) in reverse of the order that they appear in memory. Think of the SEARCH command as looking for items in a last-in, first-out queue. The syntax of the SEARCH command is {value or ASCII} <|start}.end/S If the byte (or two byte sequence) that you specify is in the specified memory range, the Monitor will return with a list of the addresses where that byte (or byte sequence) occurs. If the byte (or byte sequence) is not in the range, the Monitor just displays the prompt. The following example looks for the character string ZO in memory between $0300 and $03FF. *O’'L<300.3FFS High Bit Set: Remember that ASCII input mode sets the high-order bit of each character that you enter. The next example searches for the two-byte sequence $FF11. *11FF<3800.3FFS You can't search for a two-byte sequence with a high byte of 0. The Monitor ignores the high byte and searches for the low byte only. The sequence QOFF is seen by the Monitor SEARCH command as FF. Original lle The Monitor in the original Apple Ile does not recognize the SEARCH command. Examining and Changing Registers Na a PE ae eR re | The microprocessor’s register contents change continuously whenever the Apple Ile is running any sort of program, such as the Monitor. The Monitor lets you see what the register contents were when you invoked the Monitor or a program that you were debugging stopped at a break (BRK). The Monitor also lets you set 65C02 register values before you execute a program with the GO command. 108 Chapter 5: Using the Monitor When you call the Monitor, it stores the contents of the microprocessor’s registers in memory. The registers are stored in the order A, X, Y, P (processor status register), and S (stack pointer), starting at location $45 (decimal 69). When you give the Monitor a GO command, the Monitor loads the registers fromm these five locations before it executes the first instruction in your program. Pressing and then invokes the Monitor’s EXAMINE command, which displays the stored register values and sets the location containing the contents of the A register as the next changeable location. After using the EXAMINE command, you can change the values in these locations by typing a colon and then typing the new values separated by spaces. In the following example, you display the registers, change the first two, and then display them again to verify the change. *| CONTROL } E | A=@A X=FF Y=D8 P=#B9 S=F8 *-BO 02 *LCONTROL }{ E_ A=B@# X=62 Y=D8 P=BO S=F8 * Monitor Cassette Tape Commands The Apple Ile has two jacks for connecting an audio cassette tape recorder. With a recorder connected, you can use the Monitor commands described later in this section to save the contents of a range of memory onto a standard cassette and recall it for later use. Saving Data on Tape a ee eS The Monitor's WRITE command saves the contents of up to 65,536 memory locations on cassette tape. To save a range of memory on tape, give the Monitor the starting and ending addresses of the range, followed by the letter W (for WRITE), like this: start} . jend| W Monitor Cassette Tape Commands 109 Don’t press yet: first, put the tape recorder in record mode and let the tape run for a second, then press [RETURN}.The Monitor will write a ten-second tone onto the tape and then write the data. The tone acts as a leader: later, when the Monitor reads the tape, the leader enables the Monitor to get in step with the signal from the tape. When the Monitor is finished writing the range you specified, it will sound a bell (beep) and display a prompt. You should rewind the tape and label it with the memory range that’s on the tape and what it’s supposed to be. Here’s a small example you can save and use later to try out the READ command. Remember that you must start the cassette recorder in record mode before you press after typing the WRITE command. *(:FF FF AD 30 CO 88 D0 04 C6 01 FO 08 CA DO F6 A6 00 4C 02 00 60 *().14 BOO8- FF FF AD 36 C8 88 DB 64 8608- C6 61 FH 88 CA DOB FE AG 6019- 66 4C B82 88 6B *0.14W It takes about 35 seconds total to save the values of 4,096 memory locations preceded by the ten-second leader onto tape. This works out to an average data transfer rate of about 1,350 bits per second. The WRITE command writes one extra value on the tape after it has written the values in the memory range. This extra value is the checksum, which is the eight-bit partial sum of all values in the range. When the Monitor reads the tape, it uses this value to determine if the data has been written and read correctly. (See the next section.) Reading Data From Tape pe ee ee eee Once you've saved a memory range onto tape with the Monitor’s WRITE command, you can read that memory range back into the computer by using the Monitor's READ command. The data values you’ve stored on the tape need not be read back into the same memory range from whence they came; you can tell the Monitor to put those values into any memory range in the computer’s memory, provided that it’s the same size as the range you saved. 110 Chapter 5: Using the Monitor The format of the READ command is the same as that of the WRITE command, except that the command letter is R: start} . {end} R Once again, after typing the command, don’t press [RETURN]}.Instead, start the tape recorder in play mode and wait a few seconds. Although the WRITE command puts a ten-second leader tone on the beginning of the tape, the READ command needs only three seconds of this leader to lock on to the signal from the tape. You should let a few seconds of tape go by before you press to allow the tape recorder’s output to settle down toa steady tone. This example has two parts. First, you set a range of memory to zero, verify the contents of memory, and then type the READ command, but don’t press [RETURN}. *0:000000000000000000000 *(.14 8600- 686 66 BH 66 B68 B86 BB OB 8088- 66 66 BH 668 B86 BB BH BB 6018- 68 66 BH BH 68 *().14R Now start the cassette running in play mode, wait a few seconds, and press (RETURN}.After the Monitor sounds the bell (beep) and displays the prompt, examine the range of memory to see that the values from the tape were read correctly: *(.14 OO06- FF FF AD 38 CB 88 DO 84 86088- C6 61 FB B88 CA DB FE AG 6618- 66 4C B2 B88 6B # After the Monitor has read all the data values on the tape, it reads the checksum value. It computes the checksum on the data it read and compares it to the checksum from the tape. If the two checksums differ, the Monitor sends a beep to the speaker and displays ERR. This warns you that there was a problem reading the tape and that the values stored in memory aren't the values that were recorded on the tape. If the two checksums match, the Monitor will just send out a beep and display a prompt. Monitor Cassette Tape Commands lll Miscellaneous Monitor Commands IS892 SSR eRe 8 a cE i Pe me TE | These Monitor commands enable you to change the video display format from normal to inverse and back, and to assign input and output to accessories in expansion slots. Inverse and Normal Display SSS SS Se eee You can control the setting of the inverse-normal mask location used by the COUT subroutine (described in Chapter 3) from the Monitor so that all of the Monitor’s output will be in inverse format. The INVERSE command, I, sets the mask such that all subsequent inputs and outputs are displayed in inverse format. To switch the Monitor's output back to normal format, use the NORMAL command, N. *0.F 8600- BA OB BC OD BE BF DB B4 6O888- C6 81 FB B88 CA DO FE AG *] *().F 8O000- BA 8B OC BD BE OF DB B4 8808- C6 61 FH 868 CA DO FE AG *N *().F 86600- BA 8B BC BD BE BOF DB 84 86808- C6 81 FH 868 CA DB FE AG % Back to BASIC SSS SS a Use the BASIC command, [CONTROL }{B], to leave the Monitor and enter the BASIC that was active when you entered the Monitor. Normally, this is Applesoft BASIC, unless you deliberately switched to Integer BASIC. Any program or variables that you had previously in BASIC will be los t. If you want to reenter BASIC with your previous program and variables intact, use the CONTINUE BASIC command, (CONTROL } C]. liZ Chapter 5: Using the Monitor If you are using DOS 3.8 or ProDOS, press or type 3D8G to return to the language you were using, with your program and variables intact. That's a Number Not a Letter: If you use 8D0G, make sure that the third character you type is a zero, not a letter O. The letter G is the Monitor’s GO command, described in the section “Machine-Language Programs” later in this chapter. Redirecting Input and Output Se ee The PRINTER command, activated by a[CONTROL}{P}], diverts all output normally destined for the screen to an interface card in a specified expansion slot, from 1 to 7. There must be an interface card in the specified slot, or you will lose control of the computer and your program and variables may be lost. The format of the command is {slot number} (P A PRINTER command to slot number 0 will switch the stream of output characters back to the Apple Ile’s video display. AWanrning Don’t give the PRINTER command with slot number 0 to deactivate the 80-column firmware, even though you used this command to activate it in slot 3. The command works, but it just disconnects the firmware, leaving some of the soft switches set for 80-column display. In much the same way that the PRINTER command switches the output stream, the KEYBOARD command substitutes the interface card in a specified expansion slot for the Apple IIe’s normal input device, the keyboard. The format for the KEYBOARD command is {slot number} K] A slot number of 0 for the KEYBOARD command directs the Monitor to accept input from the Apple Ile’s built-in keyboard. The PRINTER and KEYBOARD commands are the exact equivalents of the BASIC commands PR# and IN#. Miscellaneous Monitor Commands Ls Hexadecimal Arithmetic SSS ee ee ea ey The Monitor will also perform one-byte hexadecimal addition and subtraction. Just type a line in one of these formats: pa + |value} \value; - |value; The Apple Ile performs the arithmetic and displays the result, as shown in these examples: #20413 =33 #4A-C =3E *PR+4 =83 #3-4 =FF Special Tricks With the Monitor CNET OOOO nee This section describes some more complex ways of using the Monitor commands. Multiple Commands eS ee one You can put as many Monitor commands on a single line as you like, as long as you separate them with spaces and the total number of characters in the line is less than 254. Adjacent single-letter commands such as L, S, I, and N need not be separated by spaces. You can freely intermix all of the commands except the STORE (: ) command. Since the Monitor takes all values following a colon and places them in consecutive memory locations, the last value ina STORE must be followed by a letter command before another address is encountered. You can use the NORMAL command as the required letter command in such cases; it usually has no effect and can be used anywhere. 114 Chapter 5: Using the Monitor In the following example, you display a range of memory, change it, and display it again, all with one line of commands. * 300.307 300:18 69 1 N 300.302 8308- 66 06 6H 08 68 66 88 BB 8300- 18 69 61 + If the Monitor encounters a character in the input line that it does not recognize as either a hexadecimal digit or a valid command character, it executes all the commands on the input line up to that character, then grinds to a halt with a noisy beep and ignores the remainder of the input line. Filling Memory SS aa ee The MOVE command can be used to replicate a pattern of values throughout a range of memory. To do this, first store the pattern in the first locations in the range: *300:11 22 33 # Remember the number of values in the pattern: in this case, it is 3. Use the number to compute addresses for the MOVE command, like this: istart+number! ‘i < !start! [+ . |'end-number! I M This MOVE command will first replicate the pattern at the locations immediately following the original pattern, then replicate that pattern following itself, and so on until it fills the entire range. *303<00.32DM *300.32F §6388- 11 22 33 11 22 33 11 22 §6388- 33 11 22 33 11 22 33 11 6318- 22 33 11 22 33 11 22 33 §8318- 11 22 33 11 22 33 11 22 §8320- 33 11 22 33 11 22 33 11 8328- 22 33 11 22 33 11 22 33 # Special Tricks With the Monitor 115 You can do a similar trick with the VERIFY command to check whether a pattern repeats itself through memory. This is especially useful to verify that a given range of memory locations all contain the same value. In this example, you first fill the memory range from $0300 to $0820 with zeros and verify it, then change one location and verify again, to see the VERIFY command detect the discrepancy: *300:0 #301 <300.31FM #301<300.31FV *304:02 *301<300.31FV 8363-68 (82) 6384-62 (66) # Repeating Commands SS ee You can create a command line that repeats one or more commands over and over. You do this by beginning the part of the command line that you want to repeat with a letter command, such as N, and ending it wath the sequence 34:n, where nis a hexadecimal number that specifies the position in the line of the command where you want to start repeating; for the first character in the line, n=0. The value for n must be followed with a space in order for the loop to work properly. This trick takes advantage of the fact that the Monitor uses an index register to step through the input buffer, starting at location $0200. Each time the Monitor executes a command, it stores the value of the index at location $34; when that command is finished, the Monitor reloads the index register with the value at location $34. By making the last comma.nd change the value at location $34, you change this index so that the Monitor picks up the next command character from an earlier point in the buffer. Chapter 5: Using the Monitor The only way to stop a loop like this is to press [CONTROL }{ RESET };that is how this example ends. *N 300 302 34:0 8308- 11 9382- 33 6308- 11 8302- 33 8308- 11 8302- 33 O308- 11 8382- 33 8300- 11 8392- 33 8300- 11 8302- 33 636 Creating Your Own Commands ae eee es The USER command, forces the Monitor to jump to memory location $08F8. You can put a JMP instruction there that jumps to your own machine-language program. Your program can then examine the Monitor’s registers and pointers or the input buffer itself to obtain its data. For example, here is a program that displays everything on the input line after the (CONTROL HY]. The program starts at location $0300; the command line that starts with $03F8 stores a jump to $0300 at location $03F8. *300:A4 34 BY 00 02 20 ED FD C8 C9 8D D0 F5 4C 69 FF * 3F8:4C 00 03 *(CONTROL HY] THIS IS A TEST THIS IS A TEST Special Tricks With the Monitor 117 Machine-Language Programs The main reason to program in machine language is to get more speed. A program in machine language can run much faster than the same program written in high-level languages such as BASIC or Pascal, but the machine-language version usually takes a lot longer to write. There are other reasons to use machine language: you might want your program to do something that isn’t included in your high-level language, or you might just enjoy the challenge of using machine language to work directly on the bits and bytes. Boning Up on Machine Language: If you have never used machine language before, you'll need to learn the 65C02 instructions listed in Appendix A. To become proficient at programming in machine language, you'll have to spend some time at it and study at least one of the books on 6502 programming listed in the bibliography. With the books and Appendix A, you'll have the needed information to program the 65C02. You can get a hexadecimal dump of your program, move it around in memory, or save it on tape and recall it using the commands described in the previous sections. The Monitor commands in this section are intended specifically for you to use in creating, writing, and debugging machine-language programs. Running a Program ee The Monitor command you use to start execution of your machine-language program is the GO command. When you type an address and the Ietter G, the Apple Ile starts executing machine language instructions starting at the specified location. If you just type the G, execution starts at the last opened location. The Monitor treats this program as a subroutine: it should end with an RTS (return from subroutine) instruction to transfer control back to the Monitor. 118 Chapter 5: Using the Monitor The Monitor has some special features that make it easier for you to write and debug machine-language programs, but before you get into that, here is a small machine-language program that you can run using only the simple Monitor commands already described. The program in the example merely displays the letters A through Z: you store it starting at location $0300, examine it to be sure you typed it correctly, then type 300G to start it running. *300:A9 C1 20 ED FD 18 69 1 C9 DB DO F6 60 *300.80C 6308- AS Ci 26 ED FD 18 69 61 63608- C9 DB D# FE 68 *300G ABCDEFGHI JKLMNOPQRSTUVWXYZ Disassembled Programs a Oe a Machine-language code in hexadecimal isn’t the easiest thing in the world to read and understand. To make this job a little easier, machine-language programs are usually written in assembly language and converted into machine-language code by programs called assemblers. Since programs that translate assembly language into machine language are called assemblers, a program like the Monitor’s LIST command that translates machine language into assembly language is called a disassembler. The Monitor’s LIST command displays machine-language code in assembly-language form. Instead of unformatted hexadecimal gibberish, the LIST command displays each instruction on a separate line, with a The word mnemonic comes from the same three-letter instruction name, or mnemonic, and a formatted hexadecimal root as memory and refers to operand. The LIST command also converts the relative addresses used in abbreviations that are easier to remember branch instructions to absolute addresses. than the hexadecimal operation codes themselves: for examaple, for clear carry The Monitor LIST command has the format you write CLC instea d of $18. location} L Machine-Language Programs 119 The LIST command starts at the specified location and displays as much memory as it takes to make up a screenfull (20 lines) of instructions, as shown in the following example: *300L 68366 - AS C1 LDA #$C1 §8362- 28 ED FD JSR $F DED 6366- 18 CLC 6366- 69 61 ADC #361 6368- CS DB CMP #$DB 836A- D@ FG BNE $8362 636C- 68 RTS 636D- 66 BRK O36E- 66 BRK 636F - 66 BRK 6316- 66 BRK 6311- 66 BRK 6312- 66 BRK 6313- 66 BRK 6314- 66 BRK 6316- 68 BRK §8316- 68 BRK 6317- 66 BRK §318- 08 BRK §319- 68 BRK The first seven lines of this example are the assembly-language form of the program you typed in the previous example. The rest of the lines are BRK instructions only if this part of memory has zeros in it: other values will be disassembled as other instructions. The Monitor saves the address that you specify in the LIST command, but not as the last opened location used by the other commands. Instead, the Monitor saves this address as the program counter, which it uses only to point to locations within programs. Whenever the Monitor performs a LIST command, it sets the program counter to point to the location immediately following the last location displayed on the screen, so that if you type another LIST command it will display another screenful of instructions, starting where the previous display left off. 120 Chapter 5: Using the Monitor The Mini-Assembler Without an assembler, you have to write your machine language program, take the hexadecimal values for the opcodes and operands, and store them in memory using the commands covered in the previous sections. That is exactly what you did when you ran the previous examples. The Monitor includes an assembler called the Mini-Assembler that lets you enter machine-language programs directly from the keyboard of your Apple. ASCII characters can be entered in Mini-Assembler programs, exactly as you enter them in the Monitor. Note that the Mini-Assembler doesn’t accept labels; you must use actual values and addresses. Starting the Mini-Assembler To start the Mini-Assembler first invoke the Monitor by typing CALL- 151 (RETURN],and then from the Monitor, type ! followed by [RETURN]. The Monitor prompt character then changes from * to !. When you finish using the Mini-Assembler, press from a blank line to return to the Monitor. Restrictions The Mini-Assembler supports only the subset of 65C02 instructions that are found on the 6502. Original lle Before you can use the Mini-Assembler on the original Apple Ile, you have to be running Integer BASIC. When you start up the computer using DOS or either BASIC, the Apple Ile loads the Integer BASIC interpreter from the file named INTBASIC into the bank-switched RAM. Here’s how to start the Mini-Assembler on an original Apple Ile: 1. Start Integer BASIC from DOS 3.3 by typing INT [RETURN]. 2. After the Integer prompt character (> )and a cursor appear, enter the Monitor by typing CALL - 151 [RETURN]. 3. Now start the Mini-Assembler by typing F666G [RETURN]. The Mini-Assembler [Z1 Using the Mini-Assembler —eEeEeE——EeE>EEE—————————————— The Mini-Assembler saves one address, that of the program counter. Before you start to type a program, you must set the program counter to point to the location where you want the Mini-Assembler to store your program. Do this by typing the address followed by a colon. After the colon, type the mnemonic for the first instruction in your program, followed by a space and the operand of the instruction. Now press (RETURN].The Mini-Assembler converts the line you typed into hexadecimal, stores it in memory beginning at the location of the program counter, and then disassembles it again and displays the disassermbled line. It then displays a prompt on the next line. Now the Mini-Assembler is ready to accept the second instruction in your program. To tell it that you want the next instruction to follow the first, don’t type an address or a colon: just type a space and the next instruction’s Formats for operands are listed in Table mnemonic and operand, then press (RETURN}.The Mini-Assembler 5-1. assembles that line and waits for another. '300:LDX #02 O300- A2 82 LDX #$02 ' LDA $0,X 9302- BS Oo LDA $00,X t STA $10,X 9304 95 18 STA $10,X ' DEX 9386- CA DEX 1 STA $C0380 9307- 8D 30 Ca STA $C 830 1 BPL $302 @30A- 10 F6 BPL $9302 ' BRK @30C- 8 BRK If the line you type has an error in it, the Mini-Assembler beeps loudly and displays a caret ( * )under or near the offending character in the input line. Most common errors are the result of typographical mistakes: misspelled mnemonics, missing parentheses, and so forth. The Mini-Assembler also rejects the input line if you forget the space before or after a mnermonic or 122 Chapter 5: Using the Monitor include an extraneous character in a hexadecimal value or address. If the destination address of a branch instruction is out of the range of the branch (more than 127 locations distant from the address of the instruction), the Mini-Assembler flags this as an error. There are several different ways to leave the Mini-Assembler and reenter the Monitor. On an enhanced Apple [le only, simply press ata blank line. Original Ile | Onanoriginal Apple Ile, type the Monitor command $FF69G. On any Apple Ile, you can press [CONTROL }{ RESET },which warm starts BASIC, then type CALL -151 Your assembly-language program is now stored in memory. You can display it with the LIST command: *3001 0308- A2 #2 LDX #$82 0302- BS 00 LDA $88,X 0304- 95 18 STA $108,X 9306- CA DEX 0307- 8D 38 CB STA $C836 O30A- 10 FE BPL $6302 O30C- 68 BRK O38D- 00 BRK O30E- O80 BRK O30F- 98 BRK 0310- 200 BRK 0311- 00 BRK 0312- 68 BRK 9313- 68 BRK 0314- 60 BRK 0316- 00 BRK 9316- 08 BRK 0317- 60 BRK 0318- 900 BRK 0319- 08 BRK + The Mini-Assembler 123 Mini-Assembler Instruction Formats SSS SaaS ae ee ee et al The Apple Mini-Assembler recognizes 56 mnemonics and 13 addressing See Appendix A for more information about formats. These constitute the 6502 subset of the 65C02 instruction set. The 65C02 (and 6502) instructions. mnemonics are standard, as used in the Synertek Programming Manual (Apple part number A2L0003), but the addressing formats are somewhat different. Table 5-1 shows the Apple standard address-mode formats for 6502 assembly language. Table 5-1. Mini-Assembler Address Formats Addressing Mode Format Accumulator . Implied Immediate #${value} Absolute ${address} Zero page ${address} Indexed zero page $/address!,X fadareaty Indexed absolute $/address} X jeden Relative ${address} Indexed indirect (${address},X) Indirect indexed (${address}),Y Absolute indirect (${address}) * These instructions have no operands. An address consists of one or more hexadecimal digits. The Mini-Assembler interprets addresses the same way the Monitor does: if an address has fewer than four digits, the Mini-Assembler adds leading zeros; if the address has more than four digits, then it uses only the last four. Dollar Signs: In this manual, dollar signs ($) in addresses signify that the addresses are in hexadecimal notation. They are ignored by the Mini-Assembler and may be omitted when typing programs. 124 Chapter 5: Using the Monitor There is no syntactical distinction between the absolute and zero-page addressing modes. If you give an instruction to the Mini-Assembler that can be used in both absolute and zero-page mode, the Mini-Assembler assembles that instruction in absolute mode if the operand for that instruction is greater than $FF, and it assembles it in zero-page mode if the operand is less than $0100. Instructions in accumulator mode and implied addressing mode need no operands. Branch instructions, which use the relative addressing moue, require the target address of the branch. The Mini-Assembler calculates the relative distance to use in the instruction automatically. If the target address is more than 127 locations distant from the instruction, the Mini-Assembler sounds a bell (beep), displays a caret (* ) under the target address, and does not assemble the line. If you give the Mini-Assembler the mnemonic for an instruction and an operand, and the addressing mode of the operand cannot be used with the instruction you entered, the Mini-Assembler will not accept the line. Summary of Monitor Commands Here is asummary of the Monitor commands, showing the syntax for each one. Examining Memory SSS SS SS SSS ee) \adrs| Examines the value contained in one location. {adrs1|./adrs2} Displays the values contained in all locations between {adrs1} and jadrs2}. Displays the values in up to eight locations following the last opened location. Summary of Monitor Commands 125 Changing the Contents of Memory Stores the values in consecutive memory locations starting at jadrs}. Stores values in memory starting at the next changeable location. Moving and Comparing \dest| <|start}.jend|M Copies the values in the range istart}./end) into the range beginning at jdest}. \dest} a known RTS instruction... -.ethat you set up TSX get high byte of the... LDA $01866,X - return address from stack AND #$6F low-order digit is slot no. PLP we we restore status The slot number can now be used in addressing the memory allocated to the peripheral card, as shown in the next section. I/O Addressing Sea ees Once your peripheral-card program has the slot number, the card can use the number to address the I/O locations allocated to the slot. Table 6-4 shows how these locations are related to sixteen base addresses starting with $C080. Notice that the difference between the base address and the desired I/O location has the form $n0, where n is the slot number. Starting with the slot number in the accumulator, the following example computes this difference by four left shifts, then loads it into an index regis ter and uses the base address to specify one of sixteen I/O locations. ASL ; get n into... ASL : ASL 1 ASL ; «--ehigh-order nybble... TAX : . of index register. LDA $C@88,X ; load from first I/0 location Chapter 6: Programming for Peripheral Cards Selecting Your Target: You must make sure that you get an appropriate value into the index register when you address I/O locations this way. For example, starting with 1 in the accumulator, the instructions in the above example perform an LDA from location $C090, the first I/O location allocated to slot 1. If the value in the accumulator See the section “Setting Bank Switches” in had been 0, the LDA would have accessed location $C080, thereby setting Chapter 4 for more information. the soft switch that selects the second bank of RAM at location $D000 and enables it for reading. Table 6-4. Peripheral-Card I/O Base Addresses Base Connector Number Address 1 2 3 4 3D 6 7 $C080 $C090 $COA0 $COBO $COCO $COD0 $COEO $COFO $C081 $C091 $COAL $COB1 $COC1 $COD1 $COE1 SCOF1 $C082 $C092 SCOA2 $COB2 $C0C2 $COD2 $COE2 $COF2 $C083 $C093 $COA8 $COB3 $C0C3 $COD3 $COE3 $COF3 $C084 $C094 $COA4 $COB4 $C0C4 $COD4 $COEK4 $COF4 $0085 $C095 $COA5 $COB5 $COC5 $COD5 $COE5 $COF5 $C086 $C096 SCOA6 $COB6 $C0C6 $COD6 $COE6 $COF6 $C087 $C097 $COA7 $COB7 $COC7 $COD7 $COE7 SCOF7 $0088 $C098 SCOA8 $COB8 $C0C8 $COD8 SCOE8 $COF8 $C089 $C099 $COA9 $COB9 $COCI $COD9 $COE9 SCOF9 $CO8A SCO9A SCOAA SCOBA $COCA $CODA SCOEA SCOFA 3C08B $CO9B SCOAB $COBB $COCB $CODB SCOEB SCOFB sC08C $CO9C SCOAC SCOBC $COCC $CODC $COEC $COFC $C08D sCO9D SCOAD $COBD dCOCD $CODD SCOED $COFD SCO8E SCO9E SCOAE $COBE $COCE $CODE SCOEE SCOFE $CO8F $CO9F SCOAF $COBF $COCF $CODF SCOEF $COFF I/O Programming Suggestions 137 RAM Addressing —SEEE—————————————— A program on a peripheral card can use the eight base addresses shown in Table 6-3 to access the eight RAM locations allocated for its use. The program does this by putting its slot number into the Y index register and using indexed addressing mode with the base addresses. The base addresses can be defined as constants because they are the same no matter which slot the peripheral card occupies. If you start with the correct slot number in the accumulator (by using the example shown earlier), then the following example uses all eight RAM locations allocated to the slot. TAY LDA $0478,Y STA $04F8,Y LDA $6578,Y STA $OSF8,Y LDA $6678,Y STA $06F8,Y LDA $0778,Y STA $07F8,Y AWarning You must be very careful when you have your peripheral-card program store data at the base-address locations themselves since they are temporary storage locations; the RAM at those locations is used by the disk operating system. Always store the first byte of the ROM location of the expansion slot that is currently active ($Cn) in location $7F'8, and the first byte of the ROM location of the slot holding the controller card for the startup disk drive in location $5F8. Chapter 6: Programming for Peripheral Cards Changing the Standard 1!/O Links eeee ee ee There are two pairs of locations in the Apple IIe that are used for controlling character input and output. They are called the I/O links. In a Apple Ile running without a disk operating system, the I/O links normally contain the starting addresses of the standard input and output routines—KEYIN and COUT] if the 80-column firmware is not active, BASICIN and BASICOUT if the 80-column is active. If a disk operating system is running, one or both of See “The Standard I/O Links” in Chapter 3. the links will hold the addresses of the operating system input and output routines. The link at locations $36 and $37 (decimal 54 and 55) is called CSW, for character output switch. Individually, location $36 is called COWL (CSW Low) and location $37 is called CSWH (CSW High). CSW holds the starting address of the subroutine the Apple Ile is currently using for single-character output. This address is normally $FDFO, the address of COUT1 and BASICOUT are described in routine COUT1, or $C307, the address of BASICOUT. Chapter 3. When you issue a PR#n from BASIC or ann from the Monitor, the Apple Ile changes this link address to the first address in the ROM memory space allocated to slot number n. That address has the form $Cn00. Subsequent calls for character output are thus transferred to the program on the peripheral card. That program can use the instruction sequences given above to find its slot number and use the I/O and RAM locations allocated to it. When it is finished, the program can execute an RTS (return from subroutine) instruction to return control to the calling program, or jump to the output routine COUT! at location $FDF0 to display the output character (which must be in the accumulator) on the screen, then let COUT return to the calling program. A similar link at locations $38 and $39 (decimal 56 and 57) is called KSW, for keyboard input switch. Individually, location $38 is called KSWL (for KSW low) and location $89 is called KSWH (KSW high). KSW holds the starting address of the routine currently being used for single-character KEYIN and BASICIN a re described in input. This address is normally $FD1B, the starting address of KEYIN, or Chapter 3. $C305, the address of BASICIN. I/O Programming Suggestions Loe When you issue an IN#n command from BASIC or ann from the Monitor, the Apple Ile changes this link address to $Cn00, the beginning of the ROM memory space that is allocated to slot number n. Subsequent calls for character input are thus transferred to the program on the accessory card. That program can use the instruction sequences given above to find its slot number and use the I/O and RAM locations allocated to it. The program should put the input character, with its high bit set, into the accumulator and execute an RTS instruction to return control to the program that requested input. When a disk operating system (ProDOS or DOS 8.3) is running, one or both of the standard [I/O links hold addresses of the operating system’s input and output routines. The operating system has internal locations that hold the addresses of the character input and output routines that are currently active. important! If a program that is running with ProDOS or DOS 3.3 changes the standard link addresses, either directly or via IN# and PR# cornmands, See the ProDOS Technical Reference the operating system is disconnected. Manual for more about using link addresses. To avoid disconnecting the operating system each time a BASIC program initiates I/O to a slot, it should use either an IN# or a PR# command from inside a PRINT statement that starts with a Control-D character. For assembly-language programs, there is a DOS 3.3 subroutine call to use when Refer to the section on input and output changing the link addresses. After changing CSW or KSW, the program calls link registers in the DOS Programmer's this subroutine at location $03EA (decimal 1002). The subroutine transfers Manual and the ProDOS Technical the link address to a location inside the operating system and then restores Reference Manual for further details. the operating system address in the standard link location. Other Uses of |/O Memory Space 2SUS Ck eyelet | The portion of memory space from location $C000 through $CFFE (decimal 49152 through 53247) is normally allocated to 1/0 and program memory on the peripheral cards, but there are two other functions that also use this memory space: the built-in self-test firmware and the 80-column display firmware. The soft switches that control the allocation of this memory space are described in the next section. 140 Chapter 6: Programming for Peripheral Cards Figure 6-3. 1/0 Memory Map CFFF Internal Peripheral ROM and Expansion Peripheral ROM Expansion ROM Internal C800 ROM C700 Slot 6 ROM C600 C500 C400 C300 sero |[ao Slot 2 ROM Slot 1 ROM Internal Soft Switches and Peripheral 1/0 Switching |/O Memory The built-in firmware uses two soft switches to control the allocation of the I/O memory space from $C000 to $CFFF. The locations of these soft switches, SLOTCXROM and SLOTC3ROM, are given in Table 6-5. Note: Like the display switches described in Chapter 2, these soft switches share their locations with the keyboard data and strobe functions. The switches are activated only by writing, and the states can be determined only by reading, as indicated in Table 6-5. Other Uses of I/O Memory Space 14] Table 6-5. 1/0 Memory Switches Location Name Function Hex Decimal Notes SLOTC3ROM Slot ROM at $C300 $COOB 49168 -163873 Write Internal ROM at $C300 $COOA 49162 -16374 Write Read SLOTC3ROM switch $C017 49175 -16361 Read SLOTCXROM § Slot ROM at $Cx00 $C006 49159 -16377 Write Internal ROM at $Cx00 $C007 49158 -16378 Write Read SLOTCXROM switch $C015 49173 -16363 Read When SLOTC3ROM is on, the 256-byte ROM area at $C300 is available to a peripheral card in slot 3, which is the slot normally used for a terminal interface. If a card is installed in the auxiliary slot when you turn on the power or reset the Apple Ile, the SLOT3ROM switch is turned off. Turning SLOTC3ROM off disables peripheral-card ROM in slot 8 and enables the built-in 80-column firmware, as shown in Figure 6-3. The 80-column firmware is assigned to slot-3 address space because slot 3 is normally used with a terminal interface, so the built-in firmware will work with programs that use slot 3 this way. The bus and I/O signals are always available to a peripheral card in slot 3, even when the 80-column hardware and firmware are operating. Thus it is always possible to use this slot for any I/O peripheral that does veo¢ have built-in firmware. When SLOTCXROM is active (high), the I/O memory space from $C100 to $C7FF is allocated to the expansion slots, as described previously. Setting SLOTCXROM inactive (low) disables the peripheral-card ROM and selects built-in ROM in all of the I/O memory space except the part from $C000 to $COFF (used for soft switches and data I/O), as shown in Figure 6-3. In addition to the 80-column firmware at $C300 and $C800, the built-in ROM includes firmware that performs the self-test of the Apple Ile’s hardware. Note: Setting SLOTCXROM low enables built-in ROM in all of the I/O memory space (except the soft-switch area), including the $C300 space, which contains the 80-column firmware. 142 Chapter 6: Programming for Peripheral Cards Developing Cards for Slot 3 Original lle In the original Apple Ile firmware, the internal slot 3 firmware was always switched in if there was an 80-column card (either 1K or 64K) in the auxiliary slot. This means that peripheral cards with their own ROM were effectively switched out of slot 8when the system was turned on. With the enhanced Apple Ile Monitor ROM, the rules are different. A peripheral card in slot 3 is now switched in when the system is started up or when is pressed ifthe card’s ROM has the following ID bytes: $0305 = $38 $C307 = $18 The enhanced Apple Ile firmware requires that interrupt code be present in the $C8 page (either external or internal). A peripheral card in slot 3 must have the following code to support interrupts. After this segment, the code continues execution in the internal ROM at $C400. $C3F 4: IRQDONE STA $C081 Read ROM, write RAM JMP $FC7A ;Jump to $F8 ROM IRQ BIT $C015 ‘slot or internal ROM STA $C987 force in internal ROM When programming for cards in slot 38: o You must support the AUXMOVE and XFER routines at $C312 and $0314. For more information about the $C300 o Don’t use unpublished entry points into the internal $Cn00 firmware, firmware, see the Monitor ROM listing in because there is no guarantee that they will stay the same. Appendix I of this manual. Especially note the portion from $C300 through $C420. o If your peripheral card is a character I/O device, you must follow the Pascal 1.1 firmware protocol, described in the next section. Developing Cards for Slot 3 143 Pascal 1.1 Firmware Protocol Ee SSS Se ee ey The Pascal 1.1 firmware protocol was originally developed to be used with Apple Pascal 1.1 programs. The protocol is followed by all succeeding versions of Apple II Pascal, and can be used by programmers using other languages as well. The Pascal 1.1 firmware protocol provides Apple Ile programmers with oO astandard way to uniquely identify new peripheral cards oO astandard way to address the firmware routines in peripheral cards. Device Identification aaa ey ee a) The Pascal 1.1 firmware protocol uses four bytes near the beginning of the peripheral card’s firmware to identify the peripheral card. Address Value $Cs05 $38 (like the old Apple II Serial Interface Card) $Cs07 ~—«-$18 (like the old Apple II Serial Interface Card) $CsOB $01 (the generic signature of new cards) $Cs0C —_— $ci (the device signature) The first hexadecimal digit, c, of the device signature byte identifies the device class and the second hexadecimal digit, 1,of the device signature byte is a unique identifier for the card, used by some manufacturers for their cards. Table 6-6 shows the device class assignments. Table 6-6. Peripheral-Card Device-Class Assignment Digit Device Class $0 Reserved $1 Printer $2 Joystick or other X-Y input device $3 Serial or parallel I/O card $4 Modem $5 Sound or speech device $6 Clock $7 Mass storage device $8 80-column card $9 Network or bus interface SA Special purpose (none of the above) $B-F Reserved for future expansion 144 Chapter 6: Progranuning for Peripheral Cards For example, the Apple II Super Serial Card has a device signature of $31: the 38 signifies that it is a serial or parallel 1/0 card, and the 1 is the low-order digit supplied by Apple Technical Support. Although version 1.1 of Pascal ignores the device signature, applications programs can use them to identify specific devices. I/O Routine Entry Points ———_—————— es Indirect calls to the firmware in a peripheral card are done through a branch table in the card’s firmware. The branch table of I/O routine entry points is located near the beginning of the Cs00 address space (s being the slot number where the peripheral card is installed). The branch table locations that Pascal 1.1 firmware protocol uses are as follows: Address Contains $CsOD Initialization routine offset (required) $CsOE Read routine offset (required) $CsOF Write routine offset (required) $Csl10 Status routine offset (required) $Cs11 $00 if optional offsets follow; non-zero if not $Csl2 Control routine offset (optional) $Csl3 ‘Interrupt handling routine offset (optional) Notice that $Cs11 contains $00 only if the control and interrupt handling routines are supported by the firmware. (For example, the SSC does not support these two routines, and so location $Cs11 contains a non-zero firmware instruction.) Apple II Pascal 1.0 and 1.1 do not support control and interrupt requests, but such requests are implemented in Pascal 1.2 and later versions and in ProDOS. Pascal 1.1 Firmware Protocol 145 Table 6-7 gives the entry point addresses and the contents of the 65C02 registers on entry to and on exit from Pascal 1.1 I/O routines. Table 6-7. 1/O Routine Offsets and Registers Under Pascal 1.1 Protoco] Addr. Offset for X Register Y Register A Register $CsOD Initialization On entry $Cs $s0 On exit Error code (unchanged) (unchanged) $CsOE Read On entry $Cs $s0 On exit Error code (unchanged) Character read $CsOF Write On entry $Cs $50 Char. to write On exit Error code (unchanged) (unchanged) $Csl0 Status On entry $Cs $s0 Request (0 or 1) On exit Error code (changed) (unchanged) Interrupts on the Enhanced Apple Ile Ee The original Apple Ile offered little firmware support for interrupts. The enhanced Apple Ile’s firmware provides improved interrupt support, very much like the Apple IIc’s interrupt support. Neither machine disables interrupts for extended periods. For more about interrupt support in Interrupts work on enhanced Apple [le systems with an installed 80-column ProDOS, see the ProDOS Technical text card (either 1K or 64K) or a peripheral card with interrupt-handling Reference Manual. ROM in slot 3. Interrupts are easiest to use with ProDOS and Paseal 1.2 For information about interrupt handling because they have interrupt support built in. DOS 3.3 has no built-in with Apple Pascal 1.2, see the Device and interrupt support. Interrupt Support Tools Manual which is part of the Apple IT Device Support Tools The new interrupt handler operates like the Apple IIc interrupt handler, package (A2W0C14). using the same memory locations and operating protocols. The main purpose of the interrupt handler is to support interrupts in any memory configuration. This is done by saving the machine’s state at the tame of the interrupt, placing the Apple in a standard memory configuration before calling your program’s interrupt handler, then restoring the original state when your program’s interrupt handler is finished. 146 Chapter 6: Programming for Peripheral Cards What Is an Interrupt? An interrupt is a hardware signal that tells the computer to stop what it is currently doing and devote its attention to a more important task. Print spooling and mouse handling are examples of interrupt use, things that don’t take up all the time available to the system, but that should be taken care of promptly to be most useful. For example, the Apple Ile mouse can send an interrupt to the computer every time it moves. If you handle that interrupt promptly, the mouse pointer’s movement on the screen will be smooth instead of jerky and uneven. Interrupt priority is handled by a daisy-chain arrangement using two pins, INT IN and INT OUT, on each peripheral-card slot. As described in Chapter 7, each peripheral card breaks the chain when it makes an interrupt request. On peripheral cards that don’t use interrupts, these pins should be connected together. The daisy chain gives priority to the peripheral card in slot 7: if this card opens the connection between INT IN and INT OUT, or if there is no card in this slot, interrupt requests from cards in slots 1 through 6 can’t get through. Similarly, slot 6 controls interrupt requests (IRQ) from slots 1 through 5, and so on down the line. When the IRQ’ line on the Apple Ile’s microprocessor is activated (pulled low), the microprocessor transfers control through the vector in locations $FFFE-$FFFF. This vector is the address of the Monitor’s interrupt handler, which determines whether the request is due to an external IRQ or a BRK instruction and transfers control to the appropriate routine via the vectors stored in memory page 3. The BRK vector is in locations $03F0-$03F1 and ProDOS uses the IRQ vector in locations $03FE-$03FF. (See Table 4-11.) The Monitor normally stores the address of its reset routine in the IRQ vector; you should substitute the address of your program’s interrupt-handling routine. Apple Pascal doesn’t use the BRK vector at $03F0-$03F1, but it does use the IRQ vector at $03FE-$03FF. Interrupts on the Enhanced Apple Ile 147 Interrupts on Apple Il Series Computers a an ca NE AEs ee The interrupt handler built in to the enhanced Apple Ile’s firmware saves the contents of the accurnulator on the stack. (The original Apple Ile saves the contents of the accumulator at location $45.) DOS 3.3, as well as the Monitor, rely on the integrity of location $45, so this change lets both DOS 3.3 and the Monitor continue to work with active interrupts on the enhanced Apple Ile. Original lle Since the built-in interrupt handler on the original Apple Ile uses location $45 to save the contents of the accumulator, the operating system fails when an interrupt occurs under DOS 3.3 on the original Apple Lle. If you want to write programs that use interrupts while running on the original Apple Ile, Apple II Plus, or Apple II, you must use either ProDOS or Apple II Pascal 1.2 (or later versions). Both these operating s ystems give you full interrupt support, even though these versions of tlhe Apple II don’t include interrupt support in their firmware. (Versions of Pascal before 1.2 do not work with interrupts enabled on an original A pple Ile.) Some other manufacturer’s hardware, such as co-processor cards , don’t work properly in an interrupting environment. If you are trying to develop an application and encounter this problem, check with the manufacturer of the card to see if a later version of the hardware or its software will operate properly with interrupts active. You may not be able to use interrupts if an interrupt-tolerant version isn’t available. Interrupts are effective only if they are enabled most of the time. Interrupts that occur while interrupts are disabled will not be serviced. Pascal, DOS 3.8, and ProDOS turn off interrupts while performing disk operations because of the critical timing of disk read and write operations. Some peripheral cards used in the Apple Ile disable interrupts while reading and writing. Original lle Although the enhanced Apple Ile firmware never disables interrupts during screen handling, the original Apple Ile periodically turns interrupts off while doing 80-column screen operations. The efffect is most noticeable while the screen is scrolling. 148 Chapter 6: Programming for Peripheral Cards Important! Don’t use PR#6 to restart your Apple Ile while running ProDOS with interrupts enabled since PR#6 doesn’t disable interrupts. If you try it, ProDOS will fail as it starts up since its interrupt handlers aren't yet set up. If you have to restart, use [CONTROL } RESET ], or make sure that your program disables interrupts before it ends. Rules of the Interrupt Handler —————_——— EEE SS ee aes Unlike the Apple IIc, the enhanced Apple Ile’s interrupt handling firmware is not always switched in. Here are the reasons why this is so and the implications that necessarily follow. There is xo part of memory in the Apple Ile that is always switched in. Thus, there is no location for an interrupt handler that works for all memory configurations. However, the $C3 page of firmware is present on all systems that have 80-column text cards in their auxiliary slots, so it was selected as the starting location of the built-in interrupt handling routine. There are two factors that determine if the $C3 firmware is switched in and therefore whether or not interrupts will be usable: o Is there an 80-column text card in the auxiliary slot? O If not, is there a peripheral card in slot 8 with built-in ROM with bytes $C305 = $38 and $0307 = $18? The Apple IIe’s memory is switched according to the following rules at both powerup and reset: oO If there is a ROM card in slot 3, but no text card in the auxiliary slot, the firmware on the ROM card is switched in. This is necessary for Pascal to work. oO If there is a text card in the auxiliary slot, but no ROM card in slot 3, the internal $C3 firmware is switched in. o If there is both a text card in the auxiliary slot and a ROM card in slot 3, the firmware on the ROM card is switched in. Important! These rules mean that systems without 80-column text cards in the auxiliary slot do not have their internal $C3 firmware switched in. Such systems cannot handle interrupts or breaks (the software equivalent of See the section “Developing Cards for interrupts). An application program must swap in the $C3 firmware both Slot 3” earlier in this c hapter. on initialization and after reset to make interrupts function properly on such a machine configuration. (ProDOS versions 1.1 and later do this for you during startup.) Interrupts on the Enhanced Apple Ile 149 Another implication of the decision to have interrupt code in the $C3 page affects the shared $C800 space in the Apple IIe. When the $C3 page is referenced, the Ile hardware automatically switches in its own $C800 space. When the interrupt handler finishes, it restores the $C800 space to the original owner using MSLOT ($07F8). This means that it is very important for a peripheral card to place its slot address in MSLOT to support interrupts while code is being executed in its $C800 space. Interrupt Handling on the 65C02 and 6502 ES]a ee ee) There are three possible conditions that will allow interrupts on the 65C02 and 6502: oO The IRQ line on the microprocessor is pulled low after a CLI instruction has been used (interrupts are not masked). This is the standard technique that devices use when they need immediate attention. o The microprocessor executes a break instruction (BRK = opcode $00). o Anon-maskable interrupt (NMI) occurs. The microprocessor services this interrupt whether or not the CLI instruction has been used. An NMI is completely independent of the interrupts discussed in this manual. The microprocessor saves the current program counter and status byte on the stack when an interrupt occurs and then jumps to the routine whose address is stored in $FFFE and $FFFF. The sequence of operations performed by the microprocessor 1s as follows: 1. It finishes executing the current instruction if an IRQ is encountered. (If a BRK instruction is encountered, the current instruction is already finished.) . It pushes the high byte of the program counter onto the stack. . It pushes the low byte of the program counter onto the stack. . It pushes the processor status byte onto the stack. ©. Itexecutes a JMP ($FFFE) instruction. DS OI mm The Interrupt Vector at $FFFE Three separate regions of memory contain address $FFFE in an A pple Ile with an Extended 80-Column Text Card: the built-in ROM, the bank-switched memory in main RAM, and the bank-switched memory in auxiliary RAM. The vector at $FFFE in the ROM points to the built-in interrupt handling routine. You must copy the ROM’s interrupt vector to the other banks yourself if you plan to use interrupts with the bank-s-witched memory switched in. 150 Chapter 6: Programming for Peripheral Cards The Built-in Interrupt Handler The enhanced Apple Ile’s built-in interrupt handler records the computer’s current memory configuration, then sets the computer’s memory configuration to a standard state so that your program’s interrupt handler always begins running in the same memory configuration. Next the built-in interrupt handler checks to see if the interrupt was caused by a break instruction, and handles it as just described under “Interrupt Handling on the 65C02 and 6502.” If it was not a break, it passes control to the interrupt handling routine whose address is stored at $8FE and $8FF of main memory. Normally, that would be the operating system’s interrupt Interrupt handler installation is described | handler, unless you have installed one of your own. in the ProDOS Technical Reference _ a Manual and the Device and Interrupt After your program’s interrupt handler returns (with an RTI), the built-in Support Tools Manual, which is part of interrupt handler restores the memory configuration, and then does another the Apple Ile Device Support Tools package ~~RT to return to where it was when the interrupt occurred. Figure 6-4 (A2ZWO0014). illustrates this entire process. Each of these steps is explained later in this chapter. Figure 6-4. Interrupt-Handling Sequence Interrupted Program Processor Built-in Handler User’s Handler Program ———* Push Address Push Status JMP ($FFFE) ——* Save old and set new memory configuration If BRK, then go to break handler ($FA47). —————____ Our interrupt? NO: Push Address Push Status JMP ($3FE) — Handle interrupt YES: Handle it. Restore memory “— RTI configuration Pull Status “—— RTI Program “—— Pull Address Interrupts on the Enhanced Apple Ile 151 Saving the Apple lle’s Memory Configuration SSS aa a ee ee The built-in interrupt handler saves the Apple IIe’s memory configuration and then sets it to a known state according to these rules: oO Text Page 1 is switched in (PAGE2 off) so that main screen holes are accessible if 80STORE and PAGE2 are on. Main memory is switched in for reading (RAMRD off). Main memory is switched in for writing (RAMWRT off). $D000-$F FFF ROM is switched in for reading (RDLCRAM off). Main stack and zero page are switched in (ALTZP off). 0 The OoOaqd0auxiliary stack pointer is preserved, and the main stack pointer is restored. (See the next section, “Managing Main and Auxiliary Stacks.”) Important! Because main memory is switched in, all memory addresses used later in this chapter are in main memory unless otherwise specified. Managing Main and Auxiliary Stacks a a a ed Apple has adopted a convention that allows the Apple Ile to be run with two separate stack pointers since the Apple Ile with an Extended 80-Column Text Card has two stack pages. Two bytes in the auxiliary stack page are used as storage for inactive stack pointers: $0100 for the main stack pointer when the auxiliary stack is active, and $0101 for the auxiliary stack pointer when the main stack is active. When a program using interrupts switches in the auxiliary stack for the first time, it must place the value of the main stack pointer at $0100 (in the auxiliary stack) and initialize the auxiliary stack pointer to $FF (the top of the stack). When it subsequently switches from one stack to the other, it must save the current stack pointer before loading the pointer for the other stack. The current stack pointer is stored at $0101, and the main stack pointer is retrieved from $0100 when an interrupt occurs while the auxiliary stack is switched in. Then the main stack is switched in for use. The stack pointer is restored to its original value after the interrupt has been handled. 162 Chapter 6: Programming for Peripheral Cards Important! The built-in XFER routine does not support this procedure. If you are using XFER to swap stacks, you must use code like the following to set up the stack pointers and stack. This example transfers control from a code segment running using the main stack to one running using the aux stack. XFERALT PHP ;preserve interrupt status in A PLA SEI ;disable interrupts TSX ;Save main stack pointer at $168 STA SETALT2ZP ;and swap zero pages STX $188 LDX $161 ;now restore aux stack pointer TXS PHA sand interrupt status * +—- i) WM WOONO AWN ss PLP LDA #DESTL sset destination address STA $3ED LDA #DESTH STA $3EE SEC/CLC sset direction of transfer BIT RTS ;V=1 for alt zero page CRTS=$60) oe ak ok ==WA WD NO JMP XFER sdo transfer To transfer control the other direction, change the following lines STX $181 LDX $1686 NOW STA SETSTDZP 16 CLV ;V=8 for main zp Interrupts on the Enhanced Apple Ile The User’s Interrupt Handler at $3FE _———S>ES>SEE—EE——ESEE——————S—— SS ee aed If your program has an interrupt handler, it must place the entry address of that handler at $03FE. After it sets the machine to a standard state, the IIe’s internal interrupt handler transfers control to the routine whose address is in the vector at $03FE. It is very important for a peripheral card to place its slot address in MSLOT to support interrupts whenever it is executing code in its $C800 space. Whenever the $C3 page is referenced, the IIe automatically switclies in its own $C800 ROM space. When the interrupt handler finishes, it restores the $C800 space to the original owner using MSLOT ($07F8). AWarning Be careful to install interrupt handlers according to the rules of the operating system that you are using. Placing the address of your program’s interrupt handler at $03FE disconnects the operating system’s interrupt handler. The $03FE interrupt handler must do these things: 1. Verify that the interrupt came from the expected source. 2. Handle the interrupt as desired. 8. Clear the appropriate interrupt soft switch. 4. Return with an RTT. Here are some things to remember if you are dealing with programs that must run in an interrupt enviroment: oO There is no guaranteed maximum response time for interrupts because the system may be doing a disk operation that lasts for several seconds. oO Once the built-in interrupt handler is called, it takes at least 150 to 200 microseconds for it to call your interrupt handling routine. After your routine returns, it takes 40 to 140 microseconds to restore memory and return to the interrupted program. Oo If memory is in the standard state when the interrupt occurs, the total overhead for interrupt processing is about 150 microseconds less than if memory is in the worst state. (The worst state is one that requires the most work to set up for: 30STORE and PAGE2 on; auxiliary memory switched in for reading and writing; bank-switched memory page 2 in the auxiliary bank switched in for reading and writing: and interna] $Cn00 ROM switched in). oO Interrupt overhead will be greater if your interrupt handler is installed through an operating system’s interrupt dispatcher. The length of delay depends on the operating system, and on whether the operating system dispatches the interrupt to other routines before calling yours. 154 Chapter 6: Programming for Peripheral Cards Handling Break Instructions SSS a ee ere The 65C02 treats a break instruction (BRK, opcode $00) just like a hardware interrupt. After the interrupt handler sets the memory configuration, it checks to see if the interrupt was caused by a break (bit 4 of the status byte is set), and if it was, jumps to a break handling routine. This routine saves the state of the computer at the time of the break as shown in Table 6-8. Table 6-8. BRK Handler Information Information Location Program counter (low byte) $3A Program counter (high byte) $3B Encoded memory state $44 Accumulator $45 X register $46 Y register $47 Status register $48 Finally the break routine jumps to the routine whose address is stored at $3F0 and $3F1. The encoded memory state in location $44 is interpreted as shown in Table 6-9. Table 6-9. Memory Configuration Information Bit 7 = 1 if auxiliary zero page and auxiliary stack are switched in Bit 6 = 1 if 830STORE and PAGE2 both on Bit5 = 1 if auxiliary RAM switched in for reading Bit 4 = 1 if auxiliary RAM switched in for writing Bit 38 = 1 if bank-switched RAM being read Bit 2 = | if bank-switched $D000 Page 1 switched in and RAMREAD set Bit 1 = ] if bank-switched $D000 Page 2 switched in and RAMREAD set Bit 0 = 1 if internal Cs ROM was switched in (Ile only) Interrupts on the Enhanced Apple Ile 155 Interrupt Differences: Apple lle Versus Apple Ilc A oe vn ie Ba Oks ie Sg A ee SE a If you are writing software for both the Apple Ile and the Apple IIc, you should know that there are several important differences between the interrupts on the enhanced Apple Ile and those on the Apple IIc. They are O In the IIc ROM, $FFFE points to $C803; in the IIe ROM, to $C3FA. To ensure that the proper interrupt vectors are placed into the Language Card RAM space, always copy them to the RAM from the ROM. (When you initialize built-in devices on the IIc, these vectors are automatically updated). There is no shared $C800 ROM in the IIc. Peripheral cards share this space in the Ile. Thus it is crucial that the slot address of the peripheral card using the $C800 space is stored in MSLOT ($07F8). When the interrupt handler goes to the internal $C3 space, the IIe hardware switches in its own $C800 space. When the interrupt handler finishes, it restores the $C800 space to the slot whose address is in MSLOT. The IIc $C800 space is always switched in. The enhanced Ile’s interrupt handler preserves the state of the $C800-space switch and then switches in the slot I/O space. This means that when restoring the state of the system using the value placed in location $44, break handling routines must restore one more value on the Apple Ile than on the Apple IIc. 156 Chapter 6: Programming for Peripheral Cards Chapter 7 Hardware Implementation Most of this manual describes functions—what the Apple Ile does. This chapter, on the other hand, describes objects: the pieces of hardware the Apple Ile uses to carry out its functions. If you are designing a piece of peripheral hardware to attach to the Apple Ile, or if you just want to know more about how the Apple Ile is built, you should study this chapter. Environmental Specifications eeee eee eee a a ae See The Apple Ile is quite sturdy when used in the way it was intend ed. Table 7-1 defines the conditions under which the Apple Ile is designed to function properly. Table 7-1. Summary of Environmental Specifications Operating Temperature: 0° to 45° C (80° to 115° F) Relative Humidity: 5% to 85% Line Voltage: 107 to 182 VAC You should treat the Apple Ile with the same kind of care as any other electrical appliance. You should protect it from physical violence, such as hammer blows or defenestration. You should protect the mechanical keyboard and the electrical connectors inside the case from spilled liquids, especially those with dissolved contaminants, such as coffee and cola drinks. In normal operation, enough air flows through the slots in the cas e to keep the insides from getting too hot, although some of the parts inside the Apple Ile normally get rather warm to the touch. If you manage to overheat your Apple Ile, by blocking the ventilation slots in the top and bottom for example, the first symptom will be erratic operation. The memory devices in the Apple Ile are sensitive to heat: when they get too hot, they occasionally change a bit of data. The exact result depends on what kind of program you are running and on just which bit of memory is affected. 158 Chapter 7: Hardware Implementation The Power Supply eee eee aa ea The power supply in the Apple Ile operates on normal household AC power and provides enough low-voltage electrical power for the built-in electronics plus a full complement of peripheral cards, including disk controller cards and communications interfaces. The basic specifications of the power supply are listed in Table 7-2. The Apple Ile’s power cord should be plugged into a three-wire 110- to 120-volt outlet. You must connect the Apple Ile to a grounded outlet or to a good earth ground. Also, the line voltage must be in the range given in Table 7-2. If you try to operate the Apple Ile from a power source with more than 140 volts, you will damage the power supply. Table 7-2. Power Supply Specifications Line voltage: 107V to 182V AC Maximum power consumption: 60W continuous 80W intermittent* Supply voltages: +5V +3% +11.8V +6% -5.2V + 10% -12V + 10% Maximum supply currents: +5V: 2.5A +12V: 1.5A continuous, 2.5A intermittent* -5V: 250mA -12V: 250mA Maximum case temperature: 55° C (130° F) * Intermittent operation: The Apple Ile can safely operate for up to twenty minutes at the higher load if followed by at least ten minutes at normal load. The Power Supply 159 The Apple Ile uses a custom-designed switching-type power supply. It is small and lightweight, and it generates less heat than other types of power supplies do. The Apple Ile’s power supply works by converting the AC line voltage to DC and using this DC voltage to power a variable-frequency oscillator. The oscillator drives a small transformer with many separate windings to produce the different voltages required. A circuit compares the voltage of the +5-volt supply with a reference voltage and feeds an error signal back to the oscillator circuit. The oscillator circuit uses the error signal to control the frequency of its oscillation and keep the output voltages in their normal ranges. The power supply includes circuitry to protect itself and the other electronic parts of the Apple Ie by turning off all four supply voltages whenever it detects one of the following malfunctions: O any supply voltage short-circuited to ground oO the power-supply cable disconnected O any supply voltage outside the normal range Any time one of these malfunctions occurs, the protection circuit stops the oscillator, and all the output voltages drop to zero. After about half a second, the oscillator starts up again. If the malfunction is still occurring, the protection circuit stops the oscillator again. The power supply will continue to start and stop this way until the malfunction is corrected or the power is turned off. AWarning If you think the power supply is broken, do not attempt to repair it yourself. The power supply is in a sealed enclosure because some of its circuits are connected directly to the power line. Special equipment is needed to repair the power supply safely, so see your authorized Apple dealer for service. Chapter 7: Hardware Implementation The Power Connector _a ee eee ee) The cable from the power supply is connected to the main circuit board by a six-pin connector with a strain-relief catch. The connector pins are identified in Table 7-3 and Figure 7-18d. Table 7-3. Power Connector Signal Specifications PinNumber Name Description 12 Ground Common electrical ground 3 +5V +5V from power supply 4 +12V +12V from power supply D -12V -12V from power supply 6 -\V -5V from power supply The 65C02 Microprocessor eea AN Saale. en The enhanced Apple Ile uses a 65C02 microprocessor as its central processing unit (CPU). The 65C02 in the Apple Ile runs at a clock rate of 1.023 MHz and performs up to 500,000 eight-bit operations per second. You should not use the clock rate as a criterion for comparing different types of microprocessors. The 65C02 has a simpler instruction cycle than most other microprocessors and it uses instruction pipelining for faster processing. The speed of the 65C02 with a 1MHz clock is equivalent to other types of microprocessors with clock rates up to 2.65MHz. See Appendix A for a Cescription of the The 65C02 has a sixteen-bit address bus, giving it an address space of 64K 65C02’s instruction set and electrical (2 to the sixteenth power or 65536) bytes. The Apple Ile uses special characteristics. techniques to address a total of more than 64K: see the sections “Bank-Switched Memory” and “Auxiliary Memory and Firmware’ in Chapter 4 and the section “Switching I/O Memory” in Chapter 6. The 65C02 Microprocessor 161 Table 7-4. 65C02 Microprocessor Specifications Type: 65C02 Register Complement: 8-bit Accumulator (A) 8-bit Index Registers (X,Y) 8-bit Stack Pointer (S) 8-bit Processor Status (P) 16-bit Program Counter (PC) Data Bus: Eight bits wide Address Bus: Sixteen bits wide Address Range: 65,536 (64K) Interrupts: IRQ (maskable) NMI (non-maskable) BRK (programmed) Operating Voltage: +5V (+ 5%) Power Dissipation: 5 mW (at 1 MHz) 65C02 Timing ————E—SSS The operation of the Apple Ile is controlled by a set of synchronous timing signals, sometimes called clock signals. In electronics, the word clock is used to identify signals that control the timing of circuit operations. The Apple Ile doesn’t contain the kind of clock you tell time by, although its internal timing is accurate enough that a program running on the Apple Ile can simulate such a clock. The frequency of the oscillator that generates the master timing signal is 14.381818 MHz. Circuitry in the Apple Ile uses this clock signal, called 14M, to produce all the other timing signals. These timing signals perform two major tasks: controlling the computing functions, and generating the video display. The timing signals directly involved with the operation of the 65C02 (and 6502 on the original version of the Apple Ile) are described in this section. Other timing signals are described in this chapter in the sections “RAM Addressing,” “Video Display Modes,” and “The Expansion Slots.” The main 65C02 timing signals are listed in Table 7-5, and their relationships are diagrammed in Figure 7-1. The 65C02 clock signals are 1 and $0, complementary signals at a frequency of 1.02273 MHz. The Apple Ile signal named ¢0 is equivalent to the signal called @2 in the hardware manual. (It isn’t identical: it’s a few nanoseconds early.) 162 Chapter 7: Hardware Implementation Table 7-5. 65C02 Timing Signal Descriptions Signal Name Description 14M Master oscillator, 14.318 MHz; also 80-column dot clock VID7M Intermediate timing signal and 40-column dot clock Q3 Intermediate timing signal, 2.045 MHz with asymmetrical duty cycle 0 Phase 0 of 65002 clock, 1.0227 MHz; complement of ¢1 gl Phase 1 of 65C02 clock, 1.0227 MHz; complement of ¢0 Figure 7-1. 65C02 Timing Signals 14M 7M 280 ns : 210 ns Q3 a o— oe CPU Phase | -— ns e ee Oes = |-—§140 ns (Max.) 380 ns a — ADDR From 65C02 Ge > ae 60 ns (Min.) 100 ns (Max.) — /+-— DATA From 65002 (Write) XX 50 ns (Min.) —-| b—— DATA to 65C02 (Read) XX 10 ns (Min.) —- -— The 65C02 Microprocessor 163 The operations of the 65C02 are related to the clock signals in a simple way: address during $1, data during ¢0. The 65C02 puts an address on the address bus during $1. This address is valid not later than 140 nanoseconds after @1 goes high and remains valid through all of 60. The 65C02 reads or writes data during ¢0. If the 65C02 is writing, the read/write signal is low during 0 and the 65C02 puts data on the data bus. The data is valid not later than 75 nanoseconds after ¢0 goes high. If the 65C02 is reading, the read/write signal remains high. Data on the data bus must be valid no later than 50 nanoseconds before the end of ¢0. The Custom Integrated Circuits EEE SS Se a ee Se ene eo Sd Most of the circuitry that controls memory and I/O addressing in the Apple Ile is in three custom integrated circuits called the Memory Management Unit (MMU), the Input/Output Unit (JOU), and the Programmed Array Logic device (PAL). The soft switches used for controlling the various I/O and addressing modes of the Apple Ile are addressable flags inside the MMU and the IOU. The functions of these two devices are not as independent as their names suggest; working together, they generate all of the addressing signals. For example, the MMU generates the address signals for the CPU, while the IOU generates similar address signals for the video display. The Memory Management Unit SSS ee ee ee ee) The circuitry inside the MMU implements these soft switches, which are described in the indicated chapters in this manual: O Page 2 display (PAGE2): Chapter 2 High resolution mode (HIRES): Chapter 2 Store to 80-column card (80STORE): Chapter 2 Select bank 2: Chapter 4 Enable bank-switched RAM: Chapter 4 Read auxiliary memory (RAMRD): Chapter 4 Write auxiliary memory (RAMWRT): Chapter 4 Auxiliary stack and zero page (ALTZP): Chapter 4 Slot ROM for connector #3 (SLOTC38ROM): Chapter 6 ooSlot ROM in I/O space (SLOTCXROM): Chapter 6 Of eb oO Oo ba 164 Chapter 7: Hardware Implementation The 64K dynamic RAMs used in the Apple Ile use a multiplexed address, as described later in this chapter in the section “Dynamic-RAM Timing.” The MMU generates this multiplexed address for memory reading and writing by the 65C02 CPU. The pinouts and signal descriptions of the MMU are shown in Figure 7-2 and Table 7-6. Figure 7-2. The MMU Pinouts Table 7-6. The MMU Signal Descriptions Pin Al Number Description 2 A2 3 A3 Power and signal common 4 A4 65C02 address input 4) A5 Clock phase 0 input 6 A6 Timing signal input 7 AT Memory row-address strobe 8 A8 Multiplexed address output 9 A9 10 Al0 65C02 read-write control signal 1] All Inhibits main memory (tied to +5 V) 12 Al2 Controls data bus for DMA transfers 13 Al3 Enables auxiliary RAM 14 Al4 Enables keyboard data bits 0-6 15 Al5 ROMEN2’ Enables ROM (tied to ROMEN1’) 16 +5V ROMEN]’ Enables ROM (tied to ROMEN2’) 17 CXXXx MD7 State of MMU flags on data bus bit 7 18 RAMEN’ RW’245 Controls 74LS245 data-bus buffer 19 R/W’ 245 RAMEN’ Enables main RAM ROMEN1’ 20 MD7 CXXxx Enables peripheral-card memory +5V Power Al5-Al 65C02 address input The Custom Integrated Circuits The Input/Output Unit Ee a ee ee eel The circuitry inside the Input/Output Unit (JOU) implements the following soft switches, all described in Chapter 2 in this manual: Page 2 display (PAGE2) High resolution mode (HIRES) Text mode (TEXT) Mixed mode (MIXED) 80-column display (80COL) Text display mode select (ALTCHAR) Any-key-down Annunciators eoVertical oOo Db oo oop blanking (VBL) The 64K dynamic RAMs used in the Apple Ile require a multiplexed address, as described later in this chapter in the section “Dynamic-RAM Timing.” The IOU generates this multiplexed address for the data transfers required for display and memory refresh during clock phase 1. The way this address is generated is described later in this chapter in the section “Display Address Mapping.” The pinouts and signal descriptions for the IOU are shown in Figure 7-3 and Table 7-7. 166 Chapter 7: Hardware Implementation Figure 7-3. The IOU Pinouts Table 7-7. The IOU Signal Descriptions Pin ] Number Description 2 3 ] Power and signal common 4 2 Graphics mode enable 5 3 In text mode, works with VC (see pin 5) and SEGB 80VID’ 6 to determine character row address CASSO 7 In text mode, works with VC (see pin 5) and SEGA; SPKR 8 in graphics mode, selects high-resolution when low, MD? 9 low-resolution when high ANO ANI Display vertical counter bit: in text mode, SEGA, AN2 SEGB and VC determine which of the eight rows of AN3 a character’s dot pattern to display; in R/W’ low-resolution, selects upper or lower block defined RESET’ by a byte. (n.c.) 80VID’ 80-column video enable RAO CASSO Cassette output signal RAL SPKR Speaker output signal RA2 MD7 Internal IOU flags for data bus (bit 7)3 RA3 | ANO-AN3 Annunciator outputs R/W’ 65C02 read-write control signal RESET’ Power on and reset output Nothing is connected to this pin. RAO-RA7 Video refresh multiplexed RAM address (phase 1) PRAS’ Row-address strobe (phase 0) Master clock phase 0 Intermediate timing signal Power Address bit 6 from 65C02 1/0 address enable Any-key-down signal KSTRB Keyboard strobe signal Video display data bits Video display control bits Color-burst gate (enable) Display blanking signal Display synchronization signal Display horizontal timing signal (low bit of character counter) The Custom Integrated Circuits 167 The PAL Device aa SS SSS ee) A Programmed Array Logic device, type PAL 16R8, generates several timing and control signals in the Apple Ile. These signals are listed in Table 7-8. The PAL pinouts are given in Figure 7-4. Figure 7-4. The PAL Pinouts Table 7-8. The PAL Signal Descriptions Pin ] Number Name Description 2 3 1 14M 14.31818 MHz master timing signal 4 2 7M 7.15909 MHz timing signal 5 3 3.58M 3.579545 MHz timing signal 6 4 HO Horizontal video timing signal 7 VID7 Video data bit 7 8 6 SEGB Video timing signal ) 7 GR Video display graphics-mode enable —0 8 RAMEN’ RAM enable (CAS enable) 9 80VID’ Enable 80-column display mode 10 GND Power and signal common 11 ENTMG Enable master timing 12 LDPS’ Video shift-register load enable 13 VID7M Video dot clock, 7 or 14 MHz 14 ol Phase 1 system clock 15 b0 Phase 0 system clock 16 Q3 Intermediate timing and strobe signal 17 PCAS’ RAM column-address strobe 18 N.C. (This pin is not used.) 19 PRAS’ RAM row-address strobe 20) +5V Power Memory Addressing The Apple Ile’s microprocessor can address 65,536 locations. The Apple Ile uses this entire address space, and then some: some areas in memory are used for more than one function. The following sections describe t he memory devices used in the Apple Ile and the way they are addressed. Input and output also use portions of the memory address space; refer to the section “Peripheral-Card Memory Spaces” in Chapter 6 for information. Chapter 7: Hardware Implementation Figure 7-5. The 2364 ROM Pinouts ROM Addressing ae ar ee ee ee ee ee eel In the Apple Ile, the following programs are permanently stored in two type ve ey 2364 8K by 7-bit ROMs (read-only memory): AT BV oO Applesoft editor and interpreter : ie o System Monitor A4 All oO 80-column display firmware 2 oo Oo self-test routines Al Ck’ These two ROMs are enabled by two signals called ROMEN] and ROMENZ. AO MD? The ROM enabled by ROMEN1, sometimes called the Diagnostics ROM, one “e occupies the memory address space from $C100 to $DFFF. The address MD? MD4 space from $C300 to $C3FF and from $C800 to $CFFF contains the GND MD3 80-column display firmware. Those address spaces are normally assigned to ROM on a peripheral card in slot 3; for a discussion of the way the 80-column firmware overrides the peripheral card, see the section “Other Uses of 1/0 Memory Space” in Chapter 6. The pinouts of the 2864 ROMs are given in Figure 7-5. Two other portions of the Diagnostics ROM, addressed from $C100 to $C2FF and from $C400 to $C7FF, contain the built-in self-test routines. These address spaces are normally assigned to the peripheral cards; when the self-test programs are running, the peripheral cards are disabled. The remainder of the Diagnostics ROM, addressed from $D000 to $DFFF, contains part of the Applesoft BASIC interpreter. The ROM enabled by ROMEN2, sometimes called the Monitor ROM, occupies the memory address space from $E000 to $FFFF. This ROM contains the rest of the Applesoft interpreter, in the address space from $E000 to $EFFF, and the Monitor subroutines, from $F000 to $FFFF. The other ROMs in the Apple IIe are a type 2316 ROM used for the keyboard character decoder and a type 2333 ROM used for character sets for the video display. This 2833 ROM is rather large because it includes a section of straight-through bit-mapping for the graphics modes. This way, graphics display video can pass through the same circuits as text without additional switching circuitry. The 2316's pinout is given in Figure 7-6, and the 2333's pinout is given in Figure 7-7. Memory Addressing 169 Figure 7-8. The 64K RAM Pinouts RAM Addressing Ena a ea The RAM (programmable) memory in the Apple Ile is used both for program +5V GND and data storage and for the video display. The areas in RAM that are used MDx | CAS’ for the display are accessed both by the 65C02 microprocessor and by the R /W’ MDx RAS’ | | RA video display circuits. In some computers, this dual access results in RAT | RA4 addressing conflicts (cycle stealing) that can cause temporary dropouts in RAD | RA3 the video display. This problem does not occur in the Apple Ile, thanks to RA6 | RA2 the way the microprocessor and the video circuits share the memory. +5V | &©OT oo “Oo DO RAO The memory circuits in the Apple Ile take advantage of the two-phase system clock described earlier in this chapter in the section “65C02 Timing” to interleave the microprocessor memory accesses and the display memory accesses so that they never interfere with each other. The microprocessor reads or writes to RAM only during ¢0, and the display circuits read data only during ¢l. Dynamic-RAM Refreshment The image on a video display is not permanent; it fades rapidly and must be refreshed periodically. To refresh the video display, the Apple Ile reads the data in the active display page and sends it to the display. To prevent visible flicker in the display, and to conform to standard practice for broadcast video, the Apple Ile refreshes the display sixty times per second. The dynamic RAM devices used in the Apple Ile also need a kind of refresh, because the data is stored in the form of electric charges which diminish with time and must be replenished every so often. The Apple Ile is designed so that refreshing the display also refreshes the dynamic RAMs. The next few paragraphs explain how this is done. The job of refreshing the dynamic RAM devices is minimized by the structure of the devices themselves. The individual data cells in each RAM device are arranged in a rectangular array of rows and columns. When the device is addressed, the part of the address that specifies a row is presented first, followed by the address of the column. Splitting information into parts that follow each other in time is called multiplexing. Since only half of the address is needed at one time, multiplexing the address reduces the number of pins needed for connecting the RAMs. Different manufacturers’ 64K RAMs have cell arrays of either 128 rows by 512 columns or 256 rows by 256 columns. Only the row portion of the address is used in refreshing the RAMs. 170 Chapter 7: Hardware Implementation Now consider how the display is refreshed. As described later in this chapter in the section “The Video Counters,” the display circuitry generates a sequence of 8,192 memory addresses in high-resolution mode; in text and low-resolution modes, this sequence is the 1,024 display-page addresses repeated eight times. The display address cycles through this sequence 60 times a second, or once every 17 milliseconds. The way the low-order address lines are assigned to the RAMs, the row address cycles through all 206 possible values once every two milliseconds. (See Figure 7-9.) This more than satisfies the refresh requirements of the dynamic RAMs. Table 7-9. RAM Address Multiplexing Mux’d Row Column Address Address Address RAO AO AQ RAI Al A6 RA2 A2 Al0 RA3 A38 All RA4 A4 Al2 RAD Ad Alb RA6 A’ Al4 RA? A8 Ald Dynamic-RAM Timing The Apple Ile’s microprocessor clock runs at a moderate speed, about 1.023 MHz, but the interleaving of CPU and display cycles means that the RAM is being accessed at a 2 MHz rate, or a cycle time of just under 500 nanoseconds. Data for the CPU is strobed by the falling edge of ¢0, and display data is strobed by the falling edge of #1, as shown in Figure 7-9. Memory Addressing 17] Figure 7-9. RAM Timing Signals vu UU UU UU UU UU gat tat tof ” | CPU Phase ¢1 Video Phase RAS’ | CAS’ RAO-RAT 4th — MDO-MD7 172 Chapter 7: Hardware Implementation The RAM timing looks complicated because the RAM address is multiplexed, as described in the previous section. The MMU takes care of multiplexing the address for the CPU cycle, and the IOU performs the same function for the display cycle. The multiplexed address is sent to the RAM ICs over the lines labelled RAO-RA7. Along with the other timing signals, the PAL device generates two signals that control the RAM addressing: row-address strobe (RAS) and column-address strobe (CAS). Table 7-10. RAM Timing Signal Descriptions Signal Name Description g0 Clock phase 0 (CPU phase) gl Clock phase 1 (display phase) RAS Row-address strobe CAS Column-address strobe Q3 Alternate RAM/column-address strobe RAO-RA7 Multiplexed address bus MDO0-MD7 Internal data bus The Video Display SSS SSS SSS a a a ee ee a Ceti] The Apple Ile produces a video signal that creates a display on a standard video monitor or, if you add an RF modulator, on a black-and-white or color television set. The video signal is a composite made up of the data that is being displayed plus the horizontal and vertical synchronization signals that the video monitor uses to arrange the lines of display data on the screen. Video Standards: Apple Ile’s manufactured for sale in the U.S. generate a video signal that is compatible with the standards set by the NTSC (National Television Standards Committee). Apple Ile’s manufactured for sale in European countries generate video that is compatible with the standard used there, which is called P.A.L. (for phase alternating lines). This manual describes only the NTSC version of the video circuits. The Video Display 173 The display portion of the video signal is a time-varying voltage g enerated from a stream of data bits, where a 1 corresponds to a voltage that generates a bright dot, and a 0 to a dark dot. The display bit stream is gener ated in bursts that correspond to the horizontal lines of dots on the video screen. The signal named WNDW’ is low during these bursts. During the time intervals between bursts of data, nothing is displ ayed on the screen. During these intervals, called the blanking intervals, the display is blank and the WNDW’ signal is high. The synchronization sign als, called sync for short, are produced by making the signal named SYNC’ low during portions of the blanking intervals. The sync pulses are at a voltage equivalent to blacker-than-black video and don’t show on the screen. The Video Counters SS ee een The address and timing signals that control the generation of the video display are all derived from a chain of counters inside the IOU. Only a few of these counter signals are accessible from outside the IOU, but they are all important in understanding the operation of the display generation process, particularly the display memory addressing described in the next section. The horizontal counter is made up of seven stages: HO, H1, H2, H8, H4, H6, and HPE’. The input to the horizontal counter is the 1 MHz signal that controls the reading of data being displayed. The complete cycle of the horizontal counter consists of 65 states. The six bits HO through H5 count normally from 0 to 63, then start over at 0. Whenever this happens, HPE’ forces another count with HO through Hd held at zero, thus extending the total count to 65. The IOU uses the forty horizontal count values from 25 through 64 in generating the low-order part of the display data address, as described later in this chapter in the section “Display Address Mapping.” The IOU uses the count values from 0 to 24 to generate the horizontal blanking, the horizontal sync pulse, and the color-burst gate. Chapter 7: Hardware Implementation When the horizontal count gets to 65, it signals the end of a line by triggering the vertical counter. The vertical counter has nine stages: VA, VB, VG, VO, V1, V2, V8, V4, and V5. When the vertical count reaches 262, the IOU resets it and starts counting again from zero. Only the first 192 scanning lines are actually displayed; the IOU uses the vertical counts from 192 to 261 to generate the vertical blanking and sync pulse. Nothing is displayed during the vertical blanking interval. (The vertical line count is 262 rather than the standard 262.5 because, unlike normal television, the Apple Ile’s video display is not interlaced. ) Smooth Animation: Animation displays sometimes have an erratic flicker caused by changing the display data at the same time it is being displayed. You can avoid this on the Apple Ile by reading the vertical-blanking signal (VBL) at location $C019 and changing display data while VBL is low only (data value less than 128). Display Memory Addressing CSS Se Sa nae fal As described in Chapter 2 in the section “Addressing Display Pages Directly,” data bytes are not stored in memory in the same sequence in which they appear on the display. You can get an idea of the way the display data is stored by using the Monitor to set the display to graphics mode, then storing data starting at the beginning of the display page at hexadecimal $400 and watching the effect on the display. If you do this, you should use the graphics display instead of text to avoid confusion: the text display is also used for Monitor input and output. If you want your program to display data by storing it directly into the display memory, you must first transform the display coordinates into the appropriate memory addresses, as shown in the section “Video Display Pages” in Chapter 2. The descriptions that follow will help you understand how this address transformation is done and why it is necessary. They will not (alas!) eliminate that necessity. The address transformation that folds three rows of forty display bytes into 128 contiguous memory locations is the same for all display modes, so it is described first. The differences among the different display modes are then described in the section “Video Display Modes.” The Video Display I%b Display Address Mapping Consider the simplest display on the Apple Ile, the 40-column text mode. To address forty columns requires six bits, and to address twenty-four rows requires another five bits, for a total of eleven address bits. Addressing the display this way would involve 2048 (2 to the eleventh power) bytes of memory to display a mere 960 characters. The 80-column text mode would require 4096 bytes to display 1920 characters. The leftover chunks of memory that were not displayed could be used for storing other data, but not easily, because they would not be contiguous. Instead of using the horizontal and vertical counts to address memory directly, the circuitry inside the IOU transforms them into the new address signals described below. The transformed display address must meet the following criteria: co Map the 960 bytes of 40-column text into only 1024 bytes. The requirements of the RAM refreshing oO Scan the low-order address to refresh the dynamic RAMs. are discussed earlier in this chapter inthe + Continue to refresh the RAMs during video blanking. section “Dynamic-RAM Refreshment. The transformation involves only horizontal counts H3, H4, and Hd, and vertical counts V3 and V4. Vertical count bits VA, VB, and VC address the lines making up the characters, and are not involved in the address transformation. The remaining low-order count bits, H0, H1, H2, ‘V0, V1, and V2 are used directly, and are not involved in the transformation. The JOU performs an addition that reduces the five significant count bits to four new signals called SO, $1, $2, and S38, where S stands for surn. Figure 7-10 is a diagram showing the addition in binary form, with V3 appearing as the carry in and Hd appearing as its complement H5’. A constant value of 1 appears as the low-order bit of the addend. The carry bit generated with the sum is not used. Table 7-11. Display Address Transformation V8 Carry in Hp: V3 H4 H3 Augend V4 H5’ V4 1 Addend 83 S2 Sl SO Sum 176 Chapter 7: Hardware Implementation If this transformation seems terribly obscure, try it with actual values. For example, for the upper-left corner of the display, the vertical count is 0 and the horizontal count is 24: HO, H1, H2, and Hd are 0’s and H8, and H4 are 1’s. The value of the sum is 0, so the memory location for the first character on the display is the first location in the display page, as you might expect. Horizontal bits HO, H1, and H2 and sum bits SO, $1, and S2 make up the transformed horizontal address (A0 through A6 in Table 7-12). As the horizontal count increases from 24 to 63, the value of the sum (S3 $2 51 SO) increases from 0 to 4 and the transformed address goes from 0 to 89, relative to the beginning of the display page. The low-order three bits of the vertical row counter are V0, V1, and V2. These bits control address bits A7, A8, and A9, as shown in Table 7-12, so that rows 0 through 7 start on 127-byte boundaries. When the vertical row counter reaches 8, then VO, V1, and V2 are 0 again, and V3 changes to 1. If you do the addition in Table 7-11 with H equal to 24 (the horizontal count for the first column displayed) and V equal to 8, the sum is 5 and the horizontal address is 40: the first character in row 8 is stored in the memory location 40 bytes from the beginning of the display page. Figure 7-10. 40-Column Text Display Memory Memory locations marked with an asterisk (*) are reserved for use by peripheral 1/0 firmware: refer to the section “Peripheral-Card RAM Space’ in Chapter 6. es 128 Byles 8 4) Bytes—e |+4 Byes —+| —a Byes |e Bytes $400 $480 $500 $580 $600 $680 $700 $780 The Video Display lit Figure 7-10 shows how groups of three forty-character rows are stored in blocks of 120 contiguous bytes starting on 127-byte address boundiaries. This diagram is another way of describing the display mapping shaown in Figure 2-5. Notice that the three rows in each block of 120 bytes are not adjacent on the display. Table 7-12 shows how the signals from the video counters are assigned to the address lines. HO, H1, and H2 are horizontal-count bits, and VO, V1, and V2 are vertical-count bits. SO, $1, S2 and $3 are the folded address bits described above. Address bits marked with asterisks (*) are different for different modes: see Table 7-13 and the four subsections under th section “Video Display Modes.” Table 7-12. Display Memory Addressing Memory Display Memory Display Address Bit Address Bit Address Bit Addres s Bit AO HO A8 Vl Al H1 A9 V2 A2 HZ Al0 id A3 S50 All = A4 51 Al2 Ad 2 Al3 os A6 53 Al4 " AZ VO Ald GND ™ For these address bits, see text and Table 7-18. Table 7-13. Memory Address Bits for Display Modes _ means logical AND; “means logical NOT. Display Modes Address Text and High-Resolution and Bit Low-Resolution Double-High-Resolution Al0 8OSTORE+PAGE2’ VA All 8OSTORE’.PAGE2 VB Al2 0 VC Al3 () 80STORE+PAGE2’ Al4 0 80STORE’.PAGE2 Chapter 7: Hardware Implementation Video Display Modes ee eeseee The different display modes all use the address-mapping scheme described in the previous section, but they use different-sized memory areas in different locations. The next four sections describe the addressing schemes and the methods of generating the actual video signals for the different display modes. Text Displays The text and low-resolution graphics pages begin at memory locations $0400 and $0800. Table 7-13 shows how the display-mode signals control the address bits to produce these addresses. Address bits Al0 and All are controlled by the settings of PG2 and 80STORE, which are set by the display-page and 80-column-video soft switches. Address bits Al2, A138, and Al4 are set to 0. Notice that 80STORE active inhibits PG2: there is only one display page in 80-column mode. The bit patterns used for generating the different characters are stored in a 32K ROM. The low-order six bits of each data byte reach the character generator ROM directly, via the video data bus VIDO-VID5. The two high-order bits are modified by the IOU to select between the primary and alternate character sets and are sent to the character generator ROM on lines RAY and RA1O. The data for each row of characters are read eight times, once for each of the eight lines of dots making up the row of characters. The data bits are sent to the character generator ROM along with VA, VB, and VC, the low-order bits from the vertical counter. For each character being displayed, the character generator ROM puts out one of eight stored bit patterns selected by the three-bit number made up of VA, VB, and VC. The bit patterns from the character generator ROM are loaded into the 74166 parallel-to-serial shift register and output as a serial bit stream that goes to the video output circuit. The shift register is controlled by signals named LDPS’ (for load parallel-to-serial shifter) and VID7M (for video 7 MHz). In 40-column mode, LDPS’ strobes the output of the character generator ROM into the shift register once each microsecond, and bits are sent to the screen at a 7 MHz rate. The Video Display 179 The addressing for the 80-column display is exactly the same as for the 40-column display: the 40 columns of display memory on the 80-column card are addressed in parallel with the 40 columns in main memory. The data from these two memories reach the video data bus (lines VID0-VID7) via separate 74LS374 three-state buffers. These buffers are loaded simultaneously, but their outputs are sent to the character generator ROM alternately by ¢0 and @1. In 80-column mode, LDPS’ loads data from the character generator ROM into the shift register twice during each microsecond, once during $0 and once during ¢1, and bits are sent to the screen at a 14 MHz rate. Figures 7-11a and 7-11b show the video timing signals. Figure 7-1la. 7 MHz Video Timing Signals 14M au f CPU Phase d, | $l | Video Phase DATABUS §-KK VIDEO LATCH LDPS’ and EN80’ [| pO VIDEO BUS Into CHARGEN ——! OUTPUT BUS Into SPI (Shift Register) XK e=™*—K SPI Serial Output (VID7M and 14M) | | | | | | | | 180 Chapter 7: Hardware Implementation Figure 7-11b. 14 MHz Video Timing Signals 14M oO f CPU Phase b | $1 | Video Phase | | b | DATA BUS VIDEO LATCH ) nn OT ALTERNATE BUS><_ALT, ! 80 LATCH ALT, - (EN80’ Always On) | | : | | VIDEO BUS Into CHARGEN Gt a, D, OUTPUT BUS Into SPI (Shift Register) an ae D SPI Serial Output (14M Clock) {| || The Video Display 181 Low-Resolution Display In the graphics modes, VA and VB are not used by the character generator, so the IOU uses lines SEGA and SEGB to transmit HO and HIRES’, as shown in Table 7-14. Table 7-14. Character-Generator Control Signals Display Mode SEGA SEGB SEGC Text VA VB VC Graphics _H0 HIRES’ VC The low-resolution graphics display uses VC to divide the eight display lines corresponding to a row of characters into two groups of four lines each. Each row of data bytes is addressed eight times, the same as in text mode, but each byte is interpreted as two nibbles. Each nibble selects one of 16 colors. During the upper four of the eight display lines, VC is low and the low-order nibble determines the color. During the lower four dispLay lines, VC is high and the high-order nibble determines the color. The bit patterns that produce the low-resolution colors are read from the character-generator ROM in the same way the bit patterns for characters are produced in text mode. The 74166 parallel-to-serial shift register converts the bit patterns to a serial bit stream for the video circuits. The video signal generated by the Apple Ile includes a short burst of 3.08 MHz signal that is used by an NTSC color monitor or color TV set to generate a reference 3.58 MHz color signal. The Apple IIe’s video signal produces color by interacting with this 3.58 MHz signal inside the monitor or TV set. Different bit patterns produce different colors by changing the duty cycles and delays of the bit stream relative to the 3.58 MHz color signal. To produce the small delays required for so many different colors, the shift register runs at 14 MHz and shifts out 14 bits during each cycle of the 1-MHz data clock. To generate a stream of fourteen bits from each eight-bit pattern read from the ROM, the output of the shift register is connected back to the register’s serial input to repeat the same eight bits; the last two bits are ignored the second time around. Chapter 7: Hardware Implementation Each bit pattern is output for the same amount of time as a character: .98 microseconds. Because that is exactly enough time for three and a half cycles of the 3.58 MHz color signal, the phase relationship between the bit patterns and the signal changes by a half cycle for each successive pattern. To compensate for this, the character generator ROM puts out one of two different bit patterns for each nibble, depending on the state of HO, the low-order bit of the horizontal counter. High-Resolution Display The high-resolution graphics pages begin at memory locations $2000 and $4000 (decimal 8192 and 16384). These page addresses are selected by address bits Al3 and A14. In high-resolution mode, these address bits are controlled by PG2 and 80STORE, the signals controlled by the display-page (PAGE2) and 80-column-video (80COL) soft switches. As in text mode, 8OSTORE inhibits addressing of the second page because there is only one page of 80-column text available for mixed mode. In high-resolution graphics mode, the display data are still stored in blocks like the one shown in Figure 7-10, but there are eight of these blocks. As Table 7-12 and Table 7-13 show, vertical counts VA, VB, and VC are used for address bits A10, All, and Al2, which address eight blocks of 1024 bytes each. Remember that in the display, VA, VB, and VC count adjacent horizontal lines in groups of eight. This addressing scheme maps each of those lines into a different 1024-byte block. It might help to think of it as a kind of eight-way multiplexer: it’s as if eight text displays were combined to produce a single high-resolution display, with each text display providing one line of dots in turn, instead of a row of characters. The high-resolution bit patterns are produced by the character-generator ROM. In this mode, the bit patterns simply reproduce the eight bits of display data. The low-order six bits of data reach the ROM via the video data bus VIDO-VID5. The IOU sends the other two data bits to the ROM via RAQ and RA10. The high-resolution colors described in Chapter 2 are produced by the interaction between the video signal the bit patterns generate and the 3.58 MHz color signal generated inside the monitor or TV set. The high-resolution bit patterns are always shifted out at 7 MHz, so each dot corresponds to a half-cycle of the 3.58 MHz color signal. Any part of the video signal that produces a single white dot between two black dots, or vice versa, is effectively a short burst of 3.58 MHz and is therefore displayed as color. In other words, a bit pattern consisting of alternating 1’s and 0's The Video Display 183 gets displayed as a line of color. The high-resolution graphics subroutines produce the appropriate bit patterns by masking the data bits with alternating 1’s and 0’s. To produce different colors, the bit patterns must have different phase relationships to the 3.58 MHz color signal. If alternating 1’s and 0’s produce a certain color, say green, then reversing the pattern to 0’s and 1’s will produce the complementary color, purple. As in the low-resolution mode, each bit pattern corresponds to three and a half cycles of the color signal, so the phase relationship between the data bits and the color signal changes by a half cycle for each successive byte of data. Here, however, the bit patterns produced by the hardware are the same for adjacent bytes; the color compensation is performed by the high-resolution software, which uses different color masks for data being displayed in even and odd columns. To produce other colors, bit patterns must have other timing relationships to the 8.58 MHz color signal. In high-resolution mode, the Apple Ile produces two more colors by delaying the output of the shift register by half a dot (70 ns), depending on the high-order bit of the data byte being displayed. (The high-order bit doesn't actually get displayed as a dot, because at 7 MHz there is only time to shift out seven of the eight bits.) As each byte of data is sent from the character generator to the shift register, high-order data bit D7 is also sent to the PAL device. If D’7 is off, the PAL device transmits shift-register timing signals LDPS’ and VID‘7M normally. If D7 is on, the PAL device delays LDPS’ and VID7M by 70 nanoseconds, the time corresponding to half a dot. The bit patterm that formerly produced green now produces orange; the pattern for purple now produces blue. A Note About Timing: For 80-column text, the shift register is clocked at twice normal speed. When 80-column text is used with graphics in mixed mode, the PAL device controls shift-register timing signa ls LDPS’ and VID7M so that the graphics portion of the display works correctly even when the text window is in 80-column mode. 184 Chapter 7: Hardware Implementation Double-High-Resolution Display Double-high-resolution graphics mode displays two bytes in the time normally required for one, but uses high-resolution graphics Page 1 in both main and auxiliary memory instead of text or low-resolution Page 1. Note: There is a second pair of pages, high-resolution Page 2, which can be used to display a second double-high-resolution page. Double-high-resolution graphics mode displays each pair of data bytes as 14 adjacent dots, seven from each byte. The high-order bit (color-select bit) of each byte is ignored. The auxiliary-memory byte is displayed first, so data from auxiliary memory appears in columns 0-6, 14-20, and so on, up to columns 547-552. Data from main memory appears in columns 7-18, 21-27, and so on, up to 553-559. As in 80-column text, there are twice as many dots across the display screen, so the dots are only half as wide. On a TV set or low-bandwidth monitor (less than 14 MHz), single dots will be dimmer than normal. Note: Except for some expensive RGB-type monitors, any video monitor with a bandwidth as high as 14 MHz will be a monochrome monitor. Monochrome means one color: a monochrome video monitor can have a screen color of white, green, orange, or any other single color. The main memory and auxiliary memory are connected to the address bus in parallel, so both are activated during the display cycle. The rising edge of #0 clocks a byte of main memory data into the video latch, and a byte of auxiliary memory data into the 80 latch. Phi 1 (¢1) enables output from the (auxiliary) 80 latch, and 0 enables output from the (main) video latch. Output from both latches goes to CHARGEN, where GR and SEGB’ select high-resolution graphics. LDPS operates at 2 MHz in this mode, alternately gating the auxiliary byte and main byte into the parallel-to-serial shift register. VID7M is active (kept true) for double-high-resolution display mode, so when it is ANDed with 14M, the result is still 14M. The 14M serial clock signal gate shift register then outputs to VID, the video display hybrid circuit, for output to the display device. The Video Display 185 Video Output Signals i = ee ee eee The stream of video data generated by the display circuits described above goes to a linear summing circuit built around transistor Q1 where it is mixed with the sync signals and the color burst. Resistors R8, Rd, R7, R10, R18, and R15 adjust the signals to the proper amplitudes, and a tank circuit (L3 and C32) resonant at 3.58 MHz conditions the color burst. The resulting video signal is an NTSC-compatible composite-video signal that can be displayed on a standard video monitor. The signal is similar to the EIA (Electronic Industries Association) standard positive composite video (see Table 7-15). This signal is available in two places in the Apple Ile: oO At the phono jack on the back of the Apple Ile. The sleeve of this jack is connected to ground and the tip is connected to the video output through a resistor network that attenuates it to about 1 volt and matches its impedance to 75 ohms. oO At the internal video connector on the Apple Ile circuit board near the RCA jack, J13 in Figure 7-18c. It is made up of four Molex-type pins, ().25 inches tall, on 0.10 inch centers. This connector carries the video signal, ground, and two power supplies, as shown in Table 7-15. Table 7-15. Internal Video Connector Signals Note: Pin 1 is the pin closest to the keyboard, pin 4 is at the back. Pin Name Description I GROUND System common ground Z VIDEO NTSC-compatible positive composite video. White level is about 2.0 volts, black level is about 0.75 volts, and sync level is 0.0 volts. This output is not protected against short-circuits. 3 -5V -5 volt power supply 4 +12V +12 volt power supply 186 Chapter 7; Hardware Implementation Built-in 1/O Circuits aa a a a a DL a ee ean a eee The use of the Apple Ile’s built-in 1/0 features is described in Chapter 2. This section describes the hardware implementation of all of those features except the video display described in the previous sections. The IOU (Input/Output Unit) directly generates the output signals for the speaker, the cassette interface, and the annunciators. The other I/O features are handled by smaller [Cs, as described later in this section. The addresses of the built-in 1/0 features are described in Chapter 2 and listed in Table 2-2, Table 2-11, and Table 2-12. All of the built-in I/O features except the displays use memory locations between $C000 and $C070 (decimal 49152 and 49264). The I/O address decoding is performed by three ICs: a 74LS188, a 74LS154, and a 74L8251. The 74LS138 decodes address lines A8, AY, Al0, and A1] to select address pages on 256-byte boundaries starting at $C000 (decimal 49152). When it detects addresses between $C000 and $COFF, it enables the IOU and the 74LS154. The 74LS154 in turn decodes address lines A4, Ad, A6, and A7 to select 16-byte address areas between $C000 and $COFF. Addresses between $0060 and $CO6F enable the 74LS251 that multiplexes the hand control switches and paddles; addresses between $C070 and $CO7F reset the NE558 quadruple timer that interfaces to the hand controls, as described later in the section “Game I/O Signals.” The Keyboard SSS Sa The Apple Ile’s keyboard is a matrix of keyswitches connected to an AY-3600-type keyboard decoder via a ribbon cable and a 26-pin connector. The AY-3600 scans the array of keys over and over to detect any keys pressed. The scanning rate is set by the external resistor-capacitor network made up of C70 and R82. The debounce time is also set externally, by C71. The AY-3600’s outputs include five bits of key code plus separate lines for (CONTROL], (SHIFT],any-key-down, and keyboard strobe. The any-key-down and keyboard-strobe lines are connected to the IOU, which addresses them as soft switches. The key-code lines, along with and [SHIFT],are inputs to a separate 2316 ROM. The ROM translates them to the character codes that are enabled onto the data bus by signals named KBD’ and ENKBD’. The KBD’ signal is enabled by the MMU whenever a program reads location $C000, as described in the section “Reading the Keyboard” in Chapter 2. Built-in I/O Circuits 187 Table 7-16. Keyboard Connector Signals PinNumber Name Description 1,2,4,6,8, 10, Y0-Y9 Y-direction key-matrix connections 23,20,12,22 3 +5 +5 volt supply 5,7,9,15 nc. l LCNTL’ Line from key 13 GND System common ground 14,16,20,21, § X0-X7 X-direction key-matrix connections 19,26,17 24 LSHFT’ Line from key Connecting a Keypad There is a smaller connector wired in parallel with the keyboard connector. You can connect a ten-key numeric pad to the Apple Ile via this c onnector. Table 7-17. Keypad Connector Signals PinNumber Name Description 1,2,5,3,4,6 Y0-Y5 Y-direction key-matrix connections (i nc. 911,108 X4-X7 X-direction key-matrix connections Chapter 7: Hardware Implementation Cassette !|/O The two miniature phone jacks on the back of the Apple Ile are used to connect an audio cassette recorder for saving programs. The output signal to the cassette recorder comes from a pin on the IOU via resistor network R6 and R9, which attenuates the signal to a level appropriate for the recorder’s microphone input. Input from the recorder is amplified and conditioned by a type 741 operational amplifier and sent to one of the inputs of the 74LS251 input multiplexer. The signal specifications for cassette I/O are oO Input: 1 volt (nominal) from recorder earphone or monitor output. Input impedance is 12K ohms. O Output: 25 millivolts to recorder microphone input. Output impedance is 100 ohms. The Speaker a a) The Apple [le’s built-in loudspeaker is controlled by a single bit of output from the IOU (Input Output Unit). The signal from the IOU is AC coupled to Q5, an MPSA18 Darlington transistor amplifier. The speaker connector is a Molex KK100 connector, J18 in Figure 7-18b, with two square pins 0.25 inches tall and on 0.10-inch centers. A light-emitting diode is connected in parallel across the speaker pins such that, when the speaker is not connected, the diode glows whenever the speaker signal is on. This diode is used as a diagnostic indicator during assembly and testing of the Apple Ile. Table 7-18. Speaker Connector Signals Pin Number Name Description 1 SPKR Speaker signal. This line will deliver about 0.5 watts into an 8-ohm speaker. 2 +5 +5V power supply. Note that the speaker is not connected to system ground. Built-in I/O Circuits 189 Game |/O Signals ie ae ee ee ee as | Several I/O signals that are individually controlled via soft switches are collectively referred to as the game signals. Even though they are normally used for hand controls, these signals can be used for other simple I/O applications. There are five output signals: the four annunciators, numbered AO through A38, and one strobe output. There are three one-bit inputs, called swztches and numbered SWO through SW2, and four analog inputs, called paddles and numbered PDLO through PDL38. The annunciator outputs are driven directly by the IOU (Input Output Unit). These outputs can drive one TTL (transitor-transitor logic) load each; for heavier loads, you must use a transistor or a TTL buffer on these outputs. These signals are only available on the 16-pin internal connector. (See Table 7-19.) The strobe output is a pulse transmitted any time a program reads or writes to location $C040. The strobe pin is connected to one output of the 74LS154 address decoder. This TTL signal is normally high; it goes low during ¢0 of the instruction cycle that addresses location $C040. This signal is only available on the 16-pin internal connector. (See Table 7-19.) The game inputs are multiplexed along with the cassette input signal by a 74LS251 eight-input multiplexer enabled by the C06X’ signal from the 74LS154 1/0 address decoder. Depending on the low-order address, the appropriate game input is connected to bit 7 of the data bus. The switch inputs are standard low-power Schottky TTL inputs. To use them, connect each one to 560-ohm pull-down resistors connected to the ground and through single-pole, momentary-contact pushbutton switches to the +5 volt supply. The hand-control inputs are connected to the timing inputs of an NE558 quadruple 555-type analog timer. Addressing $C0O7X sends a signal from the 74LS154 that resets all four timers and causes their outputs to go to 1 (high). A variable resistance of up to 150K ohms connected between one of these inputs and.the +5V supply controls the charging time of one of four ().022-microfarad capacitors. When the voltage on the capacitor passes a certain threshold, the output of the NE558 changes back to 0 dow). Programs can determine the setting of a variable resistor by reset ting the timers and then counting time until the selected timer input changes from high to low. The resulting count is proportional to the resistance. 190 Chapter 7: Hardware Implementation The game I/O signals are all available on a 16-pin DIP socket labelled GAME I/O on the main circuit board inside the case. The switches and the paddles are also available on a D-type miniature connector on the back of the Apple Ile; see J8 and J15 in Figure 7-138d. Table 7-19. Game I/O Connector Signals Internal- Back-Panel- Connector Connector Pin Number Pin Number Signal Name Description 2 +5V +5V power supply. Total current drain from this pin must not exceed 100mA. 7,1,6 PBO-PB2 Switch inputs. These are standard 74LS inputs. STROBE’ Strobe output. This line goes low during #o of a read or write instruction to location $C040. 6,10,7,11 0,8,4,9 PDLO-PDL3 Hand control inputs. Each of these should be connected to a 150K-ohm variable resistor connected to +5V. 8 GND System ground. 15,14,18,12 ANO-ANB Annunciators. These are standard 74LS TTL outputs and must be buffered to drive other than TTL inputs. 9,16 ILC. Nothing is connected to these pins. Built-in [/O Circuits heal Expanding the Apple lle TO a ———————— The main circuit board of the Apple Ile has eight empty card con nectors or slots on it. These slots make it possible to add features to the Apple Ile by Chapter 6 describes the standards for plugging in peripheral cards with additional hardware. This section programming peripheral cards for the describes the hardware that supports them, including all of the signals Apple Ile. available on the expansion slots. The Expansion Slots SSS See The seven connectors lined up across the back part of the Apple Ile’s main circuit card are the expansion slots, also called peripheral slots or simply slots, numbered from 1 to 7. They are 50-pin PC-card edge connectors with pins on 0.10-inch centers. A PC card plugged into one of these comnectors has access to all of the signals necessary to perform input and output and to execute programs in RAM or ROM on the card. These signals are described briefly in Table 7-20. The following paragraphs describe the signals in general and mention afew points that are often overlooked. For further details, refer to the schematic diagram in Figures 7-18a, 7-18b, 7-18c, and 7-18d. The Peripheral Address Bus The microprocessor’s address bus is buffered by two 74LS244 octal three-state buffers. These buffers, along with a buffer in the microprocessor’s R/W’ line, are enabled by a signal derived from. the DMA’ daisy-chain on the expansion slots. Pulling the peripheral line DMA’ low disables the address and R/W’ buffers so that peripheral DMA circuitry can control the address bus. The DMA address and R/W’ signals sup plied by a peripheral card must be stable all during ¢0 of the instruction cy cle, as shown in Figure 7-12. Another signal that can be used to disable normal operation of the Apple Ile is INH’. Pulling INH’ low disables all of the memory in the Apple Ile except the part in the 1/0 space from $C000 to $CFFF. A peripheral card that uses either INH’ or DMA’ must observe proper timing; in order to disable RAM and ROM cleanly, the disabling signal must be stable all during @0 of the instruction cycle (refer to the timing diagram in Figure 7-12). 192 Chapter 7: Hardware Implementation The peripheral devices should use I/O SELECT’ and DEVICE SELECT’ as enables. Most peripheral [Cs require their enable signals to be present for a certain length of time before data is strobed into or out of the device. Remember that I/O SELECT’ and DEVICE SELECT’ are only asserted during $0 high. The Peripheral Data Bus The Apple Ile has two versions of the microprocessor data bus: an internal bus, MD0-MD7, connected directly to the microprocessor; and an external bus, D0-D7, driven by a 74LS245 octal bidirectional bus buffer. The 65C02 is fabricated with MOS circuitry, so it can drive capacitive loads of up to about 130 pF. If peripheral cards are installed in all seven slots, the loading on the data bus can be as high as 500 pF, so the 74LS245 drives the data bus for the peripheral cards. The same argument applies if you use MOS devices on peripheral cards: they don’t have enough drive for the fully-loaded bus, so you should add buffers. Loading and Driving Rules Table 7-20 shows the drive requirements and loading limits for each pin on the expansion slots. The address bus, the data bus, and the R/W’ line should be driven by three-state buffers. Remember that there is considerable distributed capacitance on these busses and that you should plan on tolerating the added load of up to six additional peripheral cards. MOS devices such as PIAs and ACIAs cannot switch such heavy capacitive loads. Connecting such devices directly to the bus will lead to possible timing and level errors. Interrupt and DMA Daisy Chains The interrupt requests (IRQ’ and NMI’) and the direct-memory access (DMA’) signal are available at all seven expansion slots. A peripheral card requests an interrupt or a DMA transfer by pulling the appropriate output line low (active). If two peripheral cards request an interrupt ora DMA transfer at the same time, they will contend for the data and address busses. To prevent this, two pairs of pins on each connector are wired as a priority daisy chain. The daisy-chain pins for interrupts are INT IN and INT OUT, and the pins for DMA are DMA IN and DMA OUT, as shown for J1-J7 in Figure 7-18d. Expanding the Apple Ile 193 Each daisy chain works like this: the output from each connector goes to the input of the next higher numbered one. For these signals to be useful for cards in lower numbered connectors, all of the higher numbered connectors must have cards in them, and all of those cards must connect DMA IN to DMA OUT and INT IN to INT OUT. Whenever a peripheral card uses pin DMA’, it must do so only if its DMA IN line is active, and it must disable its DMA OUT line while it is using DMA’. The INT IN and INT OUT lines must be used the same way: enable the card’s interrupt circuits with INT IN, and disable INT OUT whenever IRQ’ or NMI’ is being used. Figure 7-12. Peripheral-Signal Timing - | | CPU Phase $1 | Video Phase | Address —> |-—140 ns (Max.) 30 ns aes! |— A0-A15, R/W’ INH’, DMA’ Peripheral Select 1/0 SELECT’ DEVICE SELECT 1/0 STROBE’ 194 Chapter 7: Hardware Implementation Table 7-20. Expansion Slot Signals Name Description I/O SELECT Normally high; goes low during @0 when the 65C02 addresses location $CnXX, where n is the connector number. This line can drive 10 LS TTL loads.* A0-A15 Three-state address bus. The address becomes valid during @1 and remains valid during #0. Each address line can drive 5 LS TTL loads.* R/W’ Three-state read/write line. Valid at the same time as the address bus; high during a read cycle, low during a write cycle. It can drive 2 LS TTL loads.” SYNC’ Composite horizontal and vertical sync, on expansion slot 7 only. This line can drive 2 LS TTL loads.* 20 1/0 STROBE’ Normally high; goes low during ¢0 when the 65C02 addresses a location between $C800 and $CFFF. This line can drive 4 LS TTL loads. 21 RDY Input to the 65C02. Pulling this line low during ¢1 halts the 65C02 with the address bus holding the address of the location currently being fetched. This line has a 3300 ohm pullup resistor to +5V. 22 DMA’ Input to the address bus buffers. Pulling this line low during @1 disconnects the 65C02 from the address bus. This line has a 3300 ohm pullup resistor to +5V. 23 INT OUT Interrupt priority daisy-chain output. Usually connected to pin 28 (INT IN).t 24 DMA OUT DMA priority daisy-chain output. Usually connected to pin 22 (DMA IN). 25 +5V +5-volt power supply. A total of 500mA is available for all peripheral cards. 26 GND System common ground. 27 DMA IN DMA priority daisy-chain input. Usually connected to pin 24 (DMA OUT). 28 INT IN Interrupt priority daisy-chain input. Usually connected to pin 23 (INT OUT). 29 NMI’ Non-maskable interrupt to 65C02. Pulling this line low starts an interrupt cycle with the interrupt-handling routine at location $08FB. This line has a 3300 ohm pullup resistor to +5V. Expanding the Apple Ile 195 Table 7-20—Continued. Expansion Slot Signals Pin Name Description 30 IRQ’ Interrupt request to 65C02. Pulling this line low starts an interrupt cycle only if the interrupt-disable (1) flag in the 65C02 is not set. Uses the interrupt-handling routine at location $03FE. This line has a 3300 ohm pullup resistor to +5V. 3l RES’ Pulling this line low initiates a reset routine, as described in Chapter 4. 32 INH’ Pulling this line low during @1 inhibits (disables) the memory on the main circuit board. This line has a 3300 ohm pullup resistor to +5V. 38 -12V -12 volt power supply. A total of 200mA is available for all peripheral cards. 34 -5V -5 volt power supply. A total of 200mA is available for all peripheral cards. 30 3.08M 3.58 MHz color reference signal, on slot 7 only. This line can drive 2 LS TTL loads.* 36 7M System 7 MHz clock. This line can drive 2 LS TTL loads.* 3” Q3 System 2 MHz asymmetrical clock. This line can drive 2 LS TTL loads.* 38 gl 65C02 phase 1 clock. This line can drive 2 LS TTL loads.* 39 uPSYNC The 65C02 signals an operand fetch by driving this line high during the first read cycle of each instruction. 40 p0 65C02 phase 0 clock. This line can drive 2 LS TTL loads.* 4] DEVICE Normally high; goes low during @0 when the 65C02 SELECT’ addresses location $COnX, where n is the connector number plus 8. This line can drive 10 LS TTL loads.* 42-49 DO0-D7 Three-state buffered bi-directional data bus. Data becomes valid during ¢0 high and remains valid until @0 goes low. Each data line can drive one LS TTL load.* 50 +12V +12 volt power supply. A total of 250mA, is available for all peripheral cards. * Loading limits are for each card. t On slot 7 only, this pin can be connected to the graphics-mode signal GR: se e text for details. 196 Chapter 7: Hardware Implementation Auxiliary Slot The large connector at the left side of the Apple IIe’s main circuit card is the auxiliary slot. It is a 60-pin PC-card edge connector with pins on 0.10-inch centers. A PC card plugged into this connector has access to all of the signals used in producing the video display. These signals are described briefly in Table 7-21. For further details, refer to the schematic diagram in Figures 7-13a, 7-13b, 7-18c, and 7-13d. Many of the internal signals that are not available on the expansion slots are on the auxiliary slot. By using both kinds of connectors, manufacturing and repair personnel can gain access to most of the signals needed for diagnosing problems in the Apple Ile. 80-Column Display Signals The additional memory needed for producing an 80-column text display is on the 80-column text card, along with the buffers that transfer the data to the video data bus, as described earlier in this chapter in the section “Text Displays.” The signals that control the 80-column text data include the system clocks #0 and ¢1, the multiplexed RAM address RAO0-RA7, the RAM address-strobe signals PRAS’ and PCAS’, and the auxiliary-RAM enable signals, EN80’ and R/ W80. The EN80’ enable signal is controlled by the S8OSTORE soft switch described in Chapter 4. Data is sent to the auxiliary memory via the internal data bus MD0-MD7; the data is transferred to the video generator via the video data bus VIDO-VID7. Expanding the Apple Ile 197 Table 7-21. Auxiliary Slot Signals Pin Name Description 3.08M 3.58 MHz video color reference signal. This line can drive two LS TTL loads. VID7M Clocks the video dots out of the 74166 parallel-to-serial shift register. This line can drive two LS TTL loads. SYNC’ Video horizontal and vertical sync signal. This line can drive two LS TTL loads. PRAS’ Multiplexed RAM row-address strobe. This line can drive two LS TTL loads. VC Third low-order vertical-counter bit. This line can drive two LS TTL loads. COTX’ Hand-control reset signal. This line can drive two LS TTL loads. 7 WNDW’ Video non-blank window. This line can drive two LS TTL loads. 8 SEGA First low-order vertical counter bit. This line can drive two LS TTL loads. 51,10,49,48, RAO-RA7 Multiplexed RAM-address bus. This line can drive 13,14,46,9 two LS TTL loads. 11,12 ROMEN1, Enable signals for the ROMs on main circuit board. ROMEN2 44,43,40,39, MDO-MD7 Internal (unbuffered) data bus. This line can drive 21,20,17,16 two LS TTL loads. 45,42,41,38, VIDO-VID7 Video data bus. This three-state bus carries video 22,19,18,15 data to the character generator. 23 p0 65C02 clock phase 0. This line can drive two LS TTL loads. 24 CLRGAT’ Color-burst gating signal. This line can drive two LS TTL loads. 25 80VID’ Enables 80-column display timing. This line can drive two LS TTL loads. 26 EN80’ Enable for auxiliary RAM. This line can drive two LS TTL loads. 27 ALTVID’ Alternative video output to the video summing amplifier. 28 SEROUT’ Video serial output from 74166 parallel-to-serial shift register. 29 ENVID’ Normally low; driving this line high disables the character generator such that the video dots from the shift register are all high (white), and alternative video can be sent out via ALTVID’. This lime has a 1000 ohm pulldown resistor to ground. 198 Chapter 7: Hardware Implementation Table 7-21—Continued. Auxiliary Slot Signals Pin Name Description 30 +5 +5 volt power supply. 31 GND System common ground. 32 14M 14.38 MHz master clock signal. This line can drive two LS TTL loads. 33 PCAS’ Multiplexed column-address strobe. This line can drive two LS TTL loads. 34 LDPS’ Strobe to video parallel-to-serial shift register. This signal goes low to load the contents of the video data bus into the shift register. This line can drive two LS TTL loads. 35 R/W80 Read/write signal for RAM on the card in this slot. This line can drive two LS TTL loads. 36 gl 65C02 clock phase 1. This line can drive two LS TTL loads. 37 CASEN’ Column-address enable. This signal is disabled (held high) during accesses to memory on the card in this slot. This line can drive two LS TTL loads. 47 HO Low-order horizontal byte counter. This line can drive two LS TTL loads. 50) AN3 Output of annunciator number 3. This line can drive two LS TTL loads. D2 R/W’ 65C02 read/write signal. This line can drive two LS TTL loads. 3 Q3 2 MHz asymmetrical clock. This line can drive two LS TTL loads. 4 SEGB Second low-order vertical-counter bit. This line can drive two LS TTL loads. ay) FRCTXT’ Normally high; pulling this line low enables 14MHz video output even when GR is active. 06,57 RAQ’,RA10° Character-generator control signals from the IOU. This line can drive two LS TTL loads. 08 GR Graphics-mode enable signal. This line can drive two LS TTL loads. 9 7M 7 MHz timing signal. This line can drive two LS TTL loads. 60 ENTMG’ Normally low; pulling this line high disables the master timing from the PAL device. This line has a 1000 ohm pulldown resistor to ground. Expanding the Apple Ile 199 adnbry“vg]-2 oeweyog ‘Weiselq Weg [ 200 (a) O] (4: Va Se nee (2) ¢ (Xc-1] Ce) 0 22Cd-13 Ts) eT Q wLNO/NE (2) NAS 6eG-ir t) wNISV) Org) 9e% af (wuer (@) @) po (2) ™OOND — Zaye) szh-ire) v i) v ov Cm om Sv Cmov i sv : sv R( ZU CKO eS ewe wit a =D c= ev ev es acv ev Se gx on _] ant q oD gar 8¥ls = | Wis ry = aa pels glia] a] oe sf _]fr re] = — | eel ee > a) OU” 0.6 COO o.)6 [ae] - = 2| = = = = os = = anod “© 21-9(0) ee ed ee ee Cee 6 séO™”™;*™*™*™”;~;#*dYY:COCSd ”CSdSC=“‘ i, |. ec eB) = 2du pl » a po : 739 3 eqzisgez 9 ot Goma (w)st-OF : - 2 . . G+ VY é; vuvuvvyvyV 7) ' 21 ve 91680296 : re ‘ ° deldel To ete 7 CC @HNI 3 (p)ie 2e(z- 201 See {2-@]On (Wy) en qi whe ! : zo edu: 1¢|_ Sl = = Ge @ a rez”té‘“‘CSC;Cé*dSCSC *TIND W-2ir w2-2ir a oe #1 3HS di-210°@-91° a i é 92-210 *Gt-oi¢ re 3 aukna Z ae xial 6I- Zit “1-91 | l2-dir°6-91F 1906-04€ a Cs eX @2-air o1-2it Cs on ps (amc Oa E @i-2ir .0CU ox wi-air es ra pee sd ek 22-air 21-2it Cw) (433d) ‘ oa Cae idl G2-di s8 a a *— €2- rT = = @-zif ‘w-91° a x 9-2If “€-91F a ry w-2if °S-91¢ (“on J E a °2-91 2-21f (2) - 1-210 °1-91F bl f x4.) ie ZoeoR 6-2i1f if Cw) St Cw) Ze ce-19¢ Wy) weet WIDOW) a «Wy ce) sece-19¢ Expanding the Apple Ile Cw) ov) STNTOR dv2-00P tas (1) ee (i-13t ah (@) ey G-13¢ Od 1-SIC°6-Of CH) 210 4-SIC‘ vr cH) iw-at iv-9F a5 @-SIF'S-Ef (H) iw-st ee “we a10d Cw) 9-SIF°S-@f aL -2e B3K31¢1 LNA id WeAI Iv- If SG zmS ¥GIC‘9-OF (CH) TWvo/t €-SIP “1-OF°S-2IF Cw) 9- OF x78) 2-SIP “2-9 “d-410 CH) 1dv0/GaS (ew) S-SIr “als ; a MZIS WI viu>d Zig wn w2i inn #973901 SP “@ 673501 oie (¥)¢ 1-0f “® y350) (St@] v 60 © SOTISOI er “8273501 1 I °-13801 ie (> *xKOD (520 ag (wOZL1IF ~~ yEHisOTT 2 re | G Hed ‘WeIBEIG ONVWIYOS “gE]-Z a4nbry aunbry‘agy-z oeWsyS Welseig OVWeg 202 aAOJ (é- OF (~) @1NOW2S (v) L2-OF ® GIL (v) 92-9r Oe OF @OIAND i-@on (1) ON < 6 254 $0 91 _ 901A 425,soE ee san 20s : : 2 34 - an ae TTT 0° TTT 137) a aS | ee aici =se ee Er] giv 6v 30 i 3D aN id . ee ee, es 0 SS aes ee Sa () ez-er en OF *€- (9) 61-20 aR s-gr) “os @) )9s-9r vais @-@F(») —WEG OF (H) £2-20'8S- “ove OF dS (0) ove “PE (1)95-OF ae 2-9r(v) 4g (v)S2-9r Wel Oss) 6 veel [-O)va OF (o) (1) ee (wiv-OF na (v)sesit T (v)wi-sir WELSIPR) ea (v) @S-Or*2I-Sir “te [e-t}e [2-1 St Co) Chapter 7: Hardware Implementation Wor wive-pr enews 9-9r(1) (v) (») e£-0F(1) pe 8 (1) (¥) eU-Jrres-Or £1} si we ae a. ae a coree(zi]r'9¢-ercan!) ay =e (ZK) U-Irez-er Oo tv) >. tTGE ig NK ET PNPO Wee ery tow ai (>) 28-or ver Vers UGS EE 9 WEE-L1- &) Gl-if ; B) 16) -B]ro = (vot (1-)r’es-or 3sere! 06z2el Co) -OF 9 — = bc es 1 £6)sezz 203 QuvOGA 3» QVd JINJIAAN HORIND yo Hoof}—< WaSt> CBR >-WJ0 CALOIA>s]0 ote WL > > <2 > IVS TIS fe oF CTEVITIAS >< yo ~—J0 o-—-< A> HEV sale tg ENV > EIT TINT AELLED ra> t5<_ cu> _> 8A 1° 93S Deate teea H0 << OX > YSIS 5> ELISIO>{]0 tee sheex <_ 8d O/T anv ove > 5 <#X189> Ce ar? tai YOLDINNOD YIMOd C_iwe Da ry LO SX Daye ge £% > wie C2VE este eel > ee a EVE DS I°egy eon > TSK Desi te5 ano |]@ @ |}ONS EVEaye ete tOW > CTR Dag 155<_ 5 > 2 /Ge @)| 245+ SVE >a He os PON > an s-|Le @ }}a- CSE f° Mtg SON > TVS He ot<5 SENT >= Heot <_1On> Expanding the Apple Ile — CBE >—h0 ot CIA Deey® Gas OF SOO TP pg << L> LU BV > 510 <0 > CZOA> fe te Oey? Tax Cay ep tp29 > EGAag es £2 > CHOTA>ashe ot CSUR >ae t= Wvl > PY aye Tap Se = CSO>Se of NOT? te | CHOIRS a0 <0 re ee CY aT? 30 Sep Ia RTE Date ot<< On > ac Cet tO JSle — >a rare le p weg ‘Wessel oyeWayog “‘pr]-2 a4nbry Appendix A The 65C02 Microprocessor This appendix contains a description of the differences between the 6502 and the 65C02 microprocessors. It also contains the data sheet for the 65C02 microprocessor. The 6502 microprocessor was used in the original Apple IIe, Apple II Plus, and Apple II. The 65C02 is a 6502 that uses less power and has ten new instructions and two new addressing modes. The 65C02 is used in both the enhanced Apple IIe and the Apple IIc. In the data sheet tables, execution times are specified in number of cycles. One cycle time for the Apple Ile equals 0.978 microseconds, giving a system clock rate of about 1.02 MHz. Note: If you want to write programs that execute on all computers in the Apple II series, use only those 65C02 instructions that are also present on the 6502. Differences Between 6502 and 65C02 aae aa Se a aap em SRDS a Cn a ee) The data sheet lists the instructions and addressing modes of the 65C02. This section supplements that information by listing those instructions whose execution times or results differ in the 6502 and the 65C02. Different Cycle Times Sa EE | A few instructions on the 65C02 operate in different numbers of c ycles than their 65C02 equivalents. These instructions are listed in Table A-1. Table A-1. Cycle Time Differences 6502 65C02 Instruction /Mode Opcode Cycles Cycles ASL Absolute, X 1E 7 6 DEC Absolute, X DE 7 6 INC Absolute, X FE fi 6 JMP (Absolute) 6C 5 6 LSR Absolute, X DE f 6 ROL Absolute, X OE 7 6 ROR Absolute, X (E 7 6 206 Appendix A: The 65C02 Microprocessor Different Instruction Results ae ea ee ge ee) It is important to note that the BIT instruction when used in immediate mode (opcode $89) leaves processor status register bits 7 (N) and 6 (V) unchanged on the 65C02. On the 6502, all modes of the BIT instruction have the same effect on the status register: the value of memory bit 7 is placed in status bit 7, and memory bit 6 is placed in status bit 6. Also note that if the JMP indirect instruction (code $6C) references an indirect address location that spans a page boundary, the 65C02 fetches the high-order byte of the effective address from the first byte of the next page, while the 6502 fetches it from the first byte of the current page. For example, JMP ($02FF) gets ADL from location $02FF on both processors. But on the 65C02, ADH comes from $0300; on the 6502, ADH comes from $0200. Data Sheet The remaining pages of this appendix are copyright 1982, NCR Corporation, Dayton, Ohio, and are reprinted with their permission. Data Sheet 207 NCR65C02 « GENERAL DESCRIPTION » PIN CONFIGURATION The NCR CMOS 6502 is an 8-bit microprocessor which is soft- ware compatible with the NMOS 6502. The NCR65CO02 hardware interfaces with all 6500 peripherals. The enhancements include ten additional instructions, expanded operational codes and two new addressing modes. This microprocessor has all of the ad- vantages of CMOS technology: low power consumption, increased noise immunity and higher reliability. The CMOS 6502 is a low power high performance microprocessor with applications in the consumer, business, automotive and communications market. s FEATURES @ Enhanced software performance including 27 additional OP codes encompassing ten new instructions and two additional addressing modes. ® 66 microprocessor instructions. @ 15 addressing modes. @ 178 operational codes. © 1MHz, 2MHz operation. eee consumption (pseudo-static: stop during @2 high). " NCR65SCO2 BLOCK DIAGRAM @ Compatible with NMOS 6500 series | microprocessors. _--- - REGISTERSECTION CONTROL SECTION —- = © 64 K-byte addressable memory. 1 i1 e Interrupt capability. C. [ cay | LOGIC @ Lower power consumption. x 4mA @ 1MHz. a @ +5 volt power supply. ac Aa @ §8-bit bidirectional data bus. -" © Bus Compatible with M6800. ae @ Non-maskable interrupt. ADORESS Bus @ 40 pin dual-in-line packaging. © §8-bit parallel processing ag Ore eae Qo (IN) ® Decimal and binary arithmetic. PROCESSOA STATUS ras REGISTER P @1 (OUT) INPUT DATA @ Pipeline architecture. INTERNAL AOH LATCH @2 (OUT) @ Programmable stack pointer. RW @ Variable length stack. DATA BUS BUFFER INSTRUCTION REGISTER e Optional_internal pullups for (ROY, IRQ, SO, NMI and RES) LEGENO fi 08 BIT LINE Specifications are subject to 81 6IT LINE change without notice. Copyright ©1982 by NCR Corporation, Dayton, Ohio, USA 208 Appendix A: The 65C02 Microprocessor NCR65C02 ® ABSOLUTE MAXIMUM RATINGS: (Vop = 5.0V + 5%, Vsg =O V, Ta = 0’ to + 70°C) RATING UNIT SUPPLY VOLTAGE V INPUT VOLTAGE V OPERATING TEMP. °C STORAGE TEMP. °C » PIN FUNCTION PIN FUNCTION AQ -Ai5 Address Bus DO - D7 Data Bus Interrupt Request Ready Memory Lock Non-Maskable Interrupt Synchronize Reset Set Overflow No Connection Read/Write Power Supply (+5V) Internal Logic Ground Clock Input 01,02 Clock Output *This pin has an optional internal pullup for a No Connect condition. « DC CHARACTERISTICS = L | MIN. | TYP. | | MAX Input High Voltage @o (IN) Vss + 2.4 =] Wop | gar Input High Voltage RES, NMI, RDY, IRQ, Data, S.O. Vsg + 2.0 - Input Low Voltage Oo (IN) RES, NMi, RDY, IRQ, Data, S.O. - Vsg + 0.8 Input Leakage Current (Vin =0 to 5.25V, Wop = 5.25V) With pullups +30 Without pullups +1.0 Three State (Off State) | nput Current (Vin = 0.4 to 2.4V, Voc =5.25V) Data Lines BA Output High Voltage (lon =-100 féAde, Von =4.75V SYNC, Data, AO-A15, R/W) S= Out Low Voltage (lo = 1.6mAdc, Vp p = 4.75V SYNC, Data, AO-A15, R/W) S are) Supply Current f = 1MHiz =.aA ciz Supply Current f = 2MHiz lpo Capacitance (Vin =0, Ta = 25°C, f = 1MHz) Logic Cin Data A0-A15, R/W, SYNC Cout Qo (IN) COg (IN) Data Sheet 209 NCR65C02 ® TIMING DIAGRAM tra tea, 0 01 02 tel —--- —-— ADDR, FW i a Sc a t OHR ce tl = READ DATA LLL ] | XU , ris tonw wn reAT a oom > aeee __ ee tecs 50 > Note: All timing is referenced from a high voltage of 2.0 volts and a low voltage of 0.8 volts. »s NEW INSTRUCTION MNEMONICS HEX MNEMONIC DESCRIPTION 80 BRA Branch relative always [Relative] 3A DEA Decrement accumulator [Accum] 1A INA Increment accumulator [Accum] DA PHX Push X on stack [Implied] 5A PHY Push Y on stack [Implied] FA PLX Pull X from stack [Implied] 7A PLY Pull Y from stack [Implied] 9C STZ Store zero [Absolute] 9E STZ Store zero [ABS, X] 64 STZ Store zero (Zero page] 74 STZ Store zero [ZPG,X] 1C TRB Test and reset memory bits with accumulator [Absolute] 14 TRB Test and reset memory bits with accumulator [Zero page] oc TSB Test and set memory bits with accumulator [Absolute] 04 TSB Test and set memory bits with accumulator [Zero page} s ADDITIONAL INSTRUCTION ADDRESSING MODES HEX MNEMONIC DESCRIPTION 72 ADC Add memory to accurnulator with carry [(ZPG) ] 32 AND “AND” memory with accumulator [((ZPG)] 3C BIT Test memory bits with accumulator [ABS, X] 34 BIT Test memory bits with accumulator [ZPG, X] D2 CMP Compare memory and accumulator [(ZPG) ] 52 EOR ‘Exclusive Or’’ memory with accumulator [(ZPG) ] 7C JMP Jump (New addressing mode) (ABS(IND,X)] B2 LDA Load accumulator with memory [(ZPG)] 12 ORA “OR” memory with accumulator [(ZPG)] F2 SBC Subtract memory from accumulator with borrow [(ZPG)] 92 STA Store accumulator in memory [(ZPG) ] 210 Appendix A: The 65C02 Microprocessor NCR65C02 s MICROPROCESSOR PROGRAMMING MODEL 7 0 NiIvililelolilzic| PROCESSOR STATUS 7 0 REG ‘’P [ad ACCUMULATOR A —_ | INDEX REGISTER Y CARRY 1 = TRUE ZERO 1 = RESULT ZERO — oa INDEX REGISTER X TRG DISABLE 1 = DISABLE 18 DECIMAL MODE 1 = TRUE PCH PCL PROGRAM COUNTER PC BRK COMMAND 1 = BRK ft} stack poner s 7 OVERFLOW 1 = TRUE NEGATIVE 1 = NEG. » FUNCTIONAL DESCRIPTION Timing Control The timing control unit keeps track of the instruction Accumulator cycle being monitored. The unit is set to zero each time The accumulator is a general purpose 8-bit register that an instruction fetch is executed and is advanced at the stores the results of most arithmetic and logic operations, beginning of each phase one clock pulse for as many and in addition, the accumulator usually contains one of cycles as is required to complete the instruction. Each the two data words used in these operations. data transfer which takes place between the registers de- pends upon decoding the contents of both the instruc- Index Registers tion register and the tim ing control unit. There are two 8-bit index registers (X and Y), which Program Counter may be used to count program steps or to provide an The 16-bit program counter provides the addresses which index value to be used in generating an effective address. step the microprocessor through sequential instructions When executing an instruction which specifies indexed in a program. addressing, the CPU fetches the op code and the base Each time the microprocessor fetches an instruction address, and modifies the address by adding the index from program memory, the lower byte of the program register to it prior to performing the desired operation. counter (PCL) is placed on the low-order bits of the Pre- or post-indexing of indirect addresses is possible (see address bus and the higher byte of the program counter addressing modes). (PCH) is placed on the high-order 8 bits. The counter is incremented each time an instruction or data is fetched Stack Pointer from program memory. The stack pointer is an 8-bit register used to control the addressing of the variable-length stack on page one. The Instruction Register and Decode stack pointer is automatically incremented and decre- Instructions fetched from memory are gated onto the mented under control of the microprocessor to perform internal data bus. These instructions are latched into the stack manipulations under direction of either the program instruction register, thers decoded, along with timing and or interrupts (NMI and IRQ). The stack allows simple interrupt signals, to generate control signals for the var- implementation of nested subroutines and multiple level ious registers. interrupts. The stack pointer should be initialized before any interrupts or stack operations occur. Arithmetic and Logic Umit (ALU) All arithmetic and logic operations take place in the Processor Status Register ALU including incrementing and decrementing internal The 8-bit processor status register contains seven status registers (except the program counter). The ALU has no flags. Some of the flags are controlled by the program, internal memory and is used only to perform logical and others may be controlled both by the program and the transient numerical oper ations. CPU. The 6500 instruction set contains a number of conditional branch instructions which are designed to allow testing of these flags (see microprocessor program- ming model). Data Sheet 211 NCR65C02 e AC CHARACTERISTICS vVop = 5.0v + 5%, Ta = 0°C to 70°C, Load = 1 TTL + 130 pF pM MZ MHZ Parameter | Symbol | Min | Max |) Min | =Max |) Min | Max | Unit Delay Time, Op (Wto@ (OUT) [tory | - | 60 | - | 60 | 2 | 60 | vs Delay Time,1(OUT) 17 (OUT|_| |torva Cycle Time | -20 | 20 | -20 | 20 | -2 | 2 | nS tcye | 10 | 5000" | 0.50 | 5000" | 0.33 | 5000" | Clock Pulse Width Low rir | 460 | - | 220] - | to | - | 1s Clock Pulse Width High rtew | 460 | - | 20 | - | 160 | - | +s Fall Time, Rise Time fte.ta | - | 2% ||20- || % | - | |. Address Hold Time | 20 | Address Setup Time ltans | - Access Time |tacc|| 650 ta | 310 | = es ns Read Data Hold Time ota. ae a ee ee ee nS Read Data Setup Time Rw a ee ae ee ee ns Write Data Delay Time ‘twos | - | 30 | - | 30 | - | 30 | Write Data Hold Time [toww | 20 | - | 20 | - [18 |= SO Setup Time itso | 100 | = | too | - | 100 | - | os Processor Control Setup Time"* | tecs_ | 200 | ~=- =| 150 | - | 150 | - | SYNC Setup Time ftsyvc | = | 225 | - | 140 | - | 100 | ML Setup Time ptm. | = | 228 | | 40 |= 100 Input Clock Rise/Fall Time tego trgo ee ee ee ee *NCR65CO2 can be held static with @ 2 high. **This parameter must only be met to guarantee that the signal will be recognized at the current clock cycle. » MICROPROCESSOR OPERATIONAL ENHANCEMENTS | Punction = NMOS 6502 Microprocessor NCR65CO2 Microprocessor Indexed addressing across page boundary. | Extra read of invalid address. E xtra read of last instruction byte. Execution of invalid op codes. Some terminate only by reset. Results |All are NOPs (reserved for future use). are undefined. Op Code Bytes Cycles X2 2 2 X3, X7, XB, XF 1 1 44 2 3 54, D4, F4 2 4 5C 3 8 DC, FC 3 4 Jump indirect, operand = XXFF. Page address does not increment. Page address increments and adds one additional cycle. Read/modify/write instructions at One read and two write cycles. Two read and one write cycle. effective address. Decimal flag. Indeterminate after reset. Irvitialized to binary mode (D=0) after reset and interrupts. Flags after decimal operation. Invalid N, V and Z flags Valid flag adds one additional cycle Interrupt after fetch of BRK instruc- Interrupt vector is loaded, BRK vector |BRK is executed, then interrupt is tion. is ignored, executed. » MICROPROCESSOR HARDWARE ENHANCEMENTS | Function sss | CNMOSG502_ |CNCRGSCOD Assertion of Ready RDY during Ignored. Stops processor during @2. write operations. Unused input-only pins (TRO, NMI, Must be connected to low impedance | Connected internally by a high- RDY, RES, §0). signal to avoid noise problems. resistance to Vop (approximately 250 K ohm.) ale Appendix A: The 65C02 Microprocessor NCR65C02 » ADDRESSING MODES Fifteen addressing modes are available to the user of the it establishes a destination for the conditional branch. NCR65C0O2 microprocessor. The addressing modes are The second byte of the instruction becomes the operand described in the following paragraphs: which is an “Offset’’ added to the contents of the pro- gram counter when the counter is set at the next in- Implied Addressing [Implied] struction. The range of the offset is —128 to +127 In the implied addressing mode, the address containing bytes from the next instruction. the operand is implicitly stated in the operation code of Zero Page Indexed Indirect Addressing [((ND, X)] the instruction. With zero page indexed indirect addres: ing (usually re- ferred to as indirect X) the second byte of the instruction Accumulator Addressing [Accum] is added to the contents of the X index register; the This form of addressing is represented with a one byte carry is discarded. The result of this addition points to a instruction and implies an operation on the accumu- memory location on page zero whose contents is the low- lator. order eight bits of the effective address. The next mem- Immediate Addressing [ Immediate] ory location in page zero contains the high-order eight With immediate addressing, the operand is contained in bits of the effective address. Both memory locations the second byte of the instruction; no further memory specifying the high- and low-order bytes of the effective addressing is required. address must be in page zero. Absolute Addressing [A bsolute] *Absolute Indexed Indirect Addressing [ABS(IND, X)] For absolute addressing, the second byte of the instruc- (Jump Instruction Only) tion specifies the eight low-order bits of the effective With absolute indexed indirect addressing the contents of address, while the third byte specifies the eight high-order the second and third instruction bytes are added to the bits. Therefore, this addressing mode allows access to the X register. The result of this addition, points to a memory total 64K bytes of addressable memory. location containing the lower-order eight bits of the effective address. The next memory location contains Zero Page Addressing [Zero Page] the higher-order eight bits of the effective address. Zero page addressing allows shorter code and execution times by only fetching the second byte of the instruction Indirect Indexed Addressing [(IND), Y] and assuming a zero high address byte. The careful use This form of addressing is usually referred to as Indirect, of zero page addressing can result in significant increase Y. The second byte of the instruction points to a mem- in code efficiency. ory location in page zero. The contents of this memory location are added to the contents of the Y index regis- Absolute Indexed Addressing [ABS, X or ABS, Y] ter, the result being the low-order eight bits of the effec- Absolute indexed addressing is used in conjunction with tive address. The carry from this addition is added to the X or Y index register and is referred to as ‘‘Absolute, X,”’ contents of the next page zero memory location, the and ‘‘Absolute, Y.’’ The effective address is formed by result being the high-order eight bits of the effective adding the contents of X or Y to the address contained address. in the second and third bytes of the instruction. This mode allows the index register to contain the index or *Zero Page Indirect Addressing [(ZPG)] count value and the instruction to contain the base In the zero page indirect addressing mode, the second address. This type of indexing allows any location refer- byte of the instruction points to a memory location on encing and the index to modify multiple fields, resulting page zero containing the low-order byte of the effective in reduced coding and execution time. address. The next location on page zero contains the high-order byte of the effective address. Zero Page Indexed Add ressing [ZPG, X or ZPG, Y] Zero page absolute adidressing is used in conjunction Absolute Indirect Addressing [(ABS)] with the index register and is referred to as ‘‘Zero Page, (Jump Instruction Only) X" or ‘‘Zero Page, Y.’’ The effective address is calculated The second byte of the instruction contains the low-order by adding the second byte to the contents of the index eight bits of a memory location. The high-order eight register. Since this is a form of ‘‘Zero Page’’ addressing, bits of that memory location is contained in the third the content of the second byte references a location in byte of the instruction. The contents of the fully speci- page zero. Additionally, due to the ‘’Zero Page’’ address- fied memory location is the low-order byte of the effec- ing nature of this modle, no carry is added to the high- tive address. The next memory location contains the order eight bits of mermory, and crossing of page boun- high-order byte of the effective address which is loaded daries does not occur. into the 16 bit program counter. Relative Addressing [Relative] Relative addressing is used only with branch instructions; NOTE: * = New Address Modes Data Sheet 213 NCR65C02 2® SIGNAL DESCRIPTION Address Bus (A0-A15) Ready (RDY) AO-A15 forms a 16-bit address bus for memory and |/O This input allows the user to single-cycle the micropro- exchanges on the data bus. The output of each address cessor on all cycles including write cycles. A negative line is TTL compatible, capable of driving one standard transition to the low state, during or coincident with TTL load and 130pF. phase one (04), will halt the microprocessor with the out- put address lines reflecting the current address being Clocks (09, 04, and 02) fetched. This condition will remain through a subsequent Qo is a TTL level input that is used to generate the inter- phase two (@2) in which the ready signal is low. This fea- nal clocks in the 6502. Two full level output clocks are ture allows microprocessor interfacing with low-speed generated by the 6502. The @2 clock output is in phase memory as well as direct memory access (DMA). with 09. The @1 output pin is 180° out of phase with Oo. (See timing diagram.) Reset (RES) This input is used to reset the microprocessor. Reset must be held low for at least two clock cycles after Data Bus (D0-D7) VOD reaches operating voltage from a power down. A The data lines (DO-D7) constitute an 8-bit bidirectional positive transistion on this pin will then cause an initiali- data bus used for data exchanges to and from the device zation sequence to begin. Likewise, after the system has and peripherals. The outputs are three-state buffers been eperating, a low on this line of at least two cycles capable of driving one TTL load and 130 pF. will cease microprocessing activity, followed by initial- Interrupt Request (/RQ) ization after the positive edge on RES. This TTL compatible input requests that an interrupt When a positive edge is detected, there is an initialization sequence begin within the microprocessor. The IRQ is sequence lasting six clock cycles. Then the interrupt sampled during @9 operation; if the interrupt flag in the mask flag is set, the decimal mode is cleared, and the pro- processor status register is zero, the current instruction gram counter is loaded with the restart vector from loca- is completed and the interrupt sequence begins during tions FFFC (low byte) and FFFD (high byte). This is @4. The program counter and processor status register the start location for program control. This input should are stored in the stack. The microprocessor will then set be high in normal operation. the interrupt mask flag high so that no further !RQs may occur. At the end of this cycle, the program counter Read/Write (R/W) low will be loaded from address FFFE, and program This signal is normally in the high state indicating that counter high from location FFFF, transferring program the microprocessor is reading data from memory or |/O control to the memory vector located at these addresses. bus. In the low state the data bus has valid data from the The RDY signal must be in the high state for any inter- microprocessor to be stored at the addressed memory rupt to be recognized. A 3K ohm external resistor should location. be used for proper wire OR operation. Set Overflow (SO) Memory Lock (ML) = A negative transition on this line sets the overflow bit in In a multiprocessor system, the ML output indicates the the status code register. The signal is sampled on the trail- need to defer the rearbitration of the next bus cycle to ing edge of 01. ensure the integrity of read-modify-write instructions. ML goes low during ASL, DEC, INC, LSR, ROL, ROR, Synchronize (SYNC) TRB, TSB memory referencing instructions. This signal This output line is provided to identify those cycles dur- is low for the modify and write cycles. ing which the microprocessor is doing an OP CODE fetch. The SYNC line goes high during 0; of am OP CODE Non-Maskable Interrupt (NMI) fetch and stays high for the remainder of that cycle. If A negative-going edge on this input requests that a non- the RDY line is pulled low during the @1 clock pulse in maskable interrupt sequence be generated within the which SYNC went high, the processor will stop in its microprocessor. The NMI is sampled during @2; the cur- current state and will remain in the state until the RDY rent instruction is completed and the interrupt sequence line goes high. In this manner, the SYNC signal can be begins during @1. The program counter is loaded with used to control RDY to cause single instruction execu- the interrupt vector from locations FFFA (low byte) tion. and FFFB (high byte), thereby transferring program con- trol to the non-maskable interrupt routine. Note: Since this interrupt is non-maskable, another NMI can occur before the first is finished. Care should be taken when using NMI to avoid this. 214 Appendix A: The 65C02 Microprocessor NCR65C02 s INSTRUCTION SET — ALPHABETICAL SEQUENCE AOC Add Memory to Accumulator with Carry LDX Load Index X with Memory AND “AND” Memory with Accumulator LDY Load Index Y with Memory ASL Shift One Bit Left LSR Shift One Bit Right BCC Branch on Carry Clear NOP No Operation BCS Branch on Carry Set ORA “OR” Memory with Accumulator BEQ Branch on Result Zero PHA Push Accumulator on Stack BIT Test Memory Bits with Accumulator PHP Push Processor Status on Stack BM! Branch on Result Minus * PHX Push Index X on Stack BNE Branch on Result not Zero * PHY Push Index Y on Stack BPL Branch on Result Plus PLA Pull Accumulator from Stack “BRA Branch Always PLP Pull Processor Status from Stack BRK Force Break *PLX Pull index X from Stack BVC Branch on Overflow Clear *PLY Pull Index Y from Stack BVS Branch on Overflow Set ROL Rotate One Bit Left CLC Clear Carry Flag ROR Rotate One Bit Right CLD Clear Decimal Mode ATI Return from Interrupt CLI Clear Interrupt Disable Bit ATS Return from Subroutine CLV Clear Overflow Flag SBC Subtract Memory from Accumulator with Borrow CMP Compare Memory and Accumulator SEC Set Carry Flag CPX Compare Memory and Index X SED Set Decimal Mode CPY Compare Memory and Index Y SEI Set Interrupt Disable Bit *DEA Decrement Accumulator STA, Store Accumulator in Memory DEC Decrement by One STX Store index X in Memory DEX Decrement | ndex X by One STY Store Index Y in Memory DEY Decrement | ndex Y by One *STZ Store Zero in Memory EOR “Exclusive-or’’ Memory with Accumulator TAX Transfer Accumulator to Index X * INA Increment Accumulator TAY Transfer Accumulator to Index Y INC Increment by One *TRB Test and Reset Memory Bits with Accumulator INX Increment Index X by One *TSB Test and Set Memory Bits with Accumulator INY Increment Imdex Y by One TSX Transfer Stack Pointer to Index X JMP Jump to New Location TXA Transfer Index X to Accumulator JSR Jump to New Location Saving Return Address TXS Transfer Index X to Stack Pointer LDA Load Accumulator with Memory TYA Transfer Index Y to Accumulator # Note: = New Instruction » MICROPROCESSOR OP CODE TABLE 7 ORA TSB* ORA ASL TSB* ORA ind, X zpg zpg zpg abs abs ne BPL ORA |ORA‘T TRB*| ORA ASL TRB* ORA ASL rel ind, Y (zpg) zpg zpg, X | zpg,X abs abs, X abs, X JSR BIT AND ROL BIT AND ROL abs zpg zpg zpg abs abs abs AND |AND*Tt BIT* | AND ROL SE BIT*Tt AND ROL ind, Y (zpg) zpg, X ae zpg, Xx abs, Y abs, X abs, X abs, X LSR JMP EOR peek zpg abs abs BVC EOR |EOR*T EOR LSR CL OR EOR LSA rel ind, Y | (zpg) oe zpg, X Oa Y abs, X | abs, X RATS ADC ae ar PL AOC JMP ADC ROR ind, X zpg imm (abs) abs abs BVS ADC |ADC*‘tT er ADC aon ADC PLY® JMP*t ADC ROR 7 rel ind, Y (z2pg) zpg, X | zpg,X | zpg,X abs, Y abs (ind, X)| abs, X abs, X BRA®* STA ae DEY BIT? TXA STY STA STX rel ind, X pe imm abs abs abs BCC STA |STA°T a a TYA STA TXS STZ° STZ* rel ind, Y (zpg) zpg, X | zpg, ue? zpg, Y abs, Y abs ae. abs, X LDY | LDA LDXx LDY LDA LOX TAY LDA | TAX LDY LDA LDX imm ind, X iram zpg zpg zpg imm abs abs abs LDA LDA‘T LOY LDA LDX CLV LOA | TSX LDY LDA LOX ind, Y (zpg) zpg, X | zpg, X | zpg, Y abs, Y abs, X abs, X abs, Y CPY CMP CPY CMP DEC INY CMP CPY imm ind, x zpq zpg zpg imm abs CMP crept CMP DEC CLO CMP CMP ind, Y (zpg) zpg, X | zpg, X abs, Y abs, X an SBC INC SBC sBc rn zpg imm abs sec ind, Y sect ( zpg) Ee INC zpg, X pee dae | TL ats fan] | abs, Y abs, X pot 1 {2tste}s {oe f{7ts fo {afte} ¢c |ofe {er}| = = New OP Codes Note: t = New Address Modes Data Sheet 215 NCR65C02 » OPERATIONAL CODES, EXECUTION TIME, AND MEMORY REQUIREMENTS IMME-| ABSO- |ZERO IM- oe RELA- PROCESSOR matmul PAGE PLIED 2PG, Y ABS, Y} TIVE es haa OPERATION ADC|A+M+CrA = 71 . ANDI|IAAM?*A 2 31 Branch if C=0 90 Branch if C=1 80 Branch if Z2=1 (2) n °o AAM (4,5) 89 Branch if N=1 (2) 30 Branch if Z=0 00 Branch if N=0 10 Branch Always 80 Break 00|7 Branch if V=0 50 Branch if V=1 70 o°c 18/2 : Jump to new loc Jump Subroutine MeA (1) Mex S+1*S MP S+1*S Mex $+1*°S Mey oF —a-te (1) Cee4 (1) 76 Return from Inter. Return from Subr. pape CT TO Notes: 1. Add 1 to ‘’n”’ if page boundary is crossed. X Index X + Add n No. Cycles 2. Add 1 to ‘‘n’’ if branch occurs to same page. Y Index Y — Subtract # No. Bytes Add 2 to ‘‘n”’ if branch occurs to different page. A Accumulator A And Mg Memory bit 6 3. Add 1 to ’’n” if decimal mode. M Memory per effective address V Or M7 Memory bit 7 4. V bit equals memory bit 6 prior to execution. Ms Memory per stack pointer MV Exclusive or N bit equals memory bit 7 prior to execution. *5, The immediate addressing mode of the BIT instruction leaves bits 6 & 7 (V & N)in the Processor Status Code Register unchanged. 216 Appendix A: The 65C02 Microprocessor Appendix B Directory of Built-in Subroutines 217 Here is a list of useful subroutines in the Apple IIe’s Monitor. To use these subroutines from machine-language programs, store data into the specified memory locations or microprocessor registers as required by the subroutine and execute a JSR to the subroutine’s starting address. After the subroutine performs its function, it returns with the 65C02’s registers changed as described. AWarning For the sake of compatibility between the Apple II Plus, Apple IIc, and the Apple Ile, do not jump into the middle of Monitor subroutines. The starting addresses are the same for all models of the Apple II, but the actual code is different. BASICIN _ Read the keyboard $0305 When the 80-column firmware is active, BASICIN is used instead of KEYIN. BASICIN operates like KEYIN except that it displays a solid, non- blinking cursor instead of a blinking checkerboard cursor. BASICOUT Output to screen $C307 When the 80-column firmware is active, BASICOUT is used instead of COUT1. BASICOUT displays the character in the accumulator on the Apple Ile’s screen at the current output cursor position and advances the output cursor. It places the character using the setting of the Normal/Inverse location. It handles control codes; see Table 3-3b-. BASICOUT returns with all registers intact. BELL Output a bell character SFF3A BELL writes a bell (Control-G) character to the current output device. It leaves the accumulator holding $87. BELLI Sends a beep to the speaker $FBDD BELL] generates a 1 kHz tone in the Apple Ile’s speaker for 0.1 second. It scrambles the A and X registers. CLREOL _ Clear toend of line $FC9C CLREOL clears a text line from the cursor position to the right edge of the window. CLREOL destroys the contents of A and Y. Appendix B: Directory of Built-in Subroutines CLEOLZ Clear toend of line $FC9E CLEOLZ clears a text line to the right edge of the window, starting at the location given by base address BASL, which is indexed by the contents of the Y register. CLEOLZ destroys the contents of A and Y. CLREOP Clear to end of window $FC42 CLREOP clears the text window from the cursor position to the bottom of the window. CLREOP destroys the contents of A and Y. CLRSCR Clear the low-resolution screen $F832 CLRSCR clears the low-resolution graphics display to black. If you call CLRSCR while the video display is in text mode, it fills the screen with inverse-mode at-sign (@) characters. CLRSCR destroys the contents of A and Y. CLRTOP Clear the low-resolution screen $F836 CLRTOP is the same as CLRSCR (above), except that it clears only the top 40 rows of the low-resolution display. COUT Output a character $FDED COUT calls the current character output subroutine. The character to be output should be in the accumulator. COUT calls the subroutine whose address is stored in CSW (locations $36 and $37), which is usually one of the standard character output subroutines, COUT1 or BASICOUT. COUT1 Output to screen $FDF0 COUT! displays the character in the accumulator on the Apple Ile’s screen at the current output cursor position and advances the output cursor. It places the character using the setting of the Normal/Inverse location. It handles the codes for carriage return, linefeed, backspace, and bell. It returns with all registers intact. CROUT Generate a carriage return character $FD8E CROUT sends a carriage return character to the current output device. CROUTI1 — Generate carriage return, clear rest of line $FD8B CROUT! clears the screen from the current cursor position to the edge of the text window, then calls CROUT. Appendix B: Directory of Built-in Subroutines 219 GETLN Get an input line with prompt $FD6A GETLN is the standard input subroutine for entire lines of characters, as described in Chapter 3. Your program calls GETLN with the prompt character in location $33; GETLN returns with the input line in the input buffer (beginning at location $0200) and the X register holding the length of the input line. GETLNZ Get aninput line $FD67 GETLNZ is an alternate entry point for GETLN that sends a carriage return to the standard output, then continues into GETLN. GETLN1 Get an input line, no prompt SFD6F GETLN1 is an alternate entry point for GETLN that does not issue a prompt before it accepts the input line. If, however, the user cancels the input line, either with too many backspaces or with a [CONTROL }{x], then GETLN1 will issue the contents of location $33 as a prompt when it gets another line. HLINE Draw a horizontal line of blocks $F819 HLINE draws a horizontal line of blocks of the color set by SETCOL on the low-resolution graphics display. Call HLINE with the vertical coordinate of the line in the accumulator, the leftmost horizontal coordinate in the Y register, and the rightmost horizontal coordinate in location $2C. HLINE returns with A and Y scrambled, X intact. HOME Home cursor and clear $FC58 HOME clears the display and puts the cursor in the home position: the upper-left corner of the screen. IOREST Restore all registers $FFSF IOREST loads the 65C02’s internal registers with the contents of memory locations $45 through $49. IOSAVE _ Saveall registers SFF4A IOSAVE stores the contents of the 65C02’s internal registers in locations $45 through $49 in the order A, X, Y, P, S. The contents of A and X are changed and the decimal mode is cleared. 220) Appendix B: Directory of Built-in Subroutines KEYIN Read the keyboard $FDIB KEYIN is the keyboard input subroutine. It reads the Apple Ile’s keyboard, waits for a keypress, and randomizes the random number seed at $4E-$4F. When a key is pressed, KEYIN removes the blinking cursor from the display and returns with the keycode in the accumulator. KEYIN is described in Chapter 3. MOVE Move a block of memory $FE2C MOVE copies the contents of memory from one range of locations to another. This subroutine is the same as the MOVE command in the Monitor, except that it takes its arguments from pairs of locations in memory, low-byte first. The destination address must be in A4 ($42-$48), the starting source address in Al ($3C-$3D), and the ending source address in A2 ($3E-$3F) when your program calls MOVE. Register Y must contain $00 when your program calls MOVE. NEXTCOL Increment color by 3 $F85F NEXTCOL adds 8 to the current color (set by SETCOL) used for low-resolution graphics. PLOT Plot on the low-resolution screen $F'800 PLOT puts a single block of the color value set by SETCOL on the low-resolution display screen. The block’s vertical position is passed in the accumulator, its horizontal position in the Y register. PLOT returns with the accumulator scrambled, but X and Y intact. PRBLNK Print three spaces $F948 PRBLNK outputs three blank spaces to the standard output device. On return, the accumulator usually contains $A0, the X register contains 0. PRBL2 Print many blank spaces $F9O4A PRBL2 outputs from 1 to 256 blanks to the standard output device. Upon entry, the X register should contain the number of blanks to be output. If X=$00, then PRBL2 will output 256 blanks. PRBYTE Print a hexadecimal byte $FDDA PRBYTE outputs the contents of the accumulator in hexadecimal on the current output device. The contents of the accumulator are scrambled. Appendix B: Directory of Built-in Subroutines 221 PREAD Read a hand control SFBIE PREAD returns a number that represents the position of a hand control. You pass the number of the hand control in the X register. If this num ber is not valid (not equal to 0, 1, 2, or 3), strange things may happen. PREAD returns with a number from $00 to $FF in the Y register. The accumulator is scrambled. PRERR Print ERR $FF2D PRERR sends the word ERR, followed by a bell character, to the standard output device. On return, the accumulator is scrambled. PRHEX Print a hexadecimal digit $FDE3 PRHEX prints the lower nibble of the accumulator as a single hexadecimal digit. On return, the contents of the accumulator are scrambled. PRNTAX Print Aand X in hexadecimal $F941 PRNTAX prints the contents of the A and X registers as a four-digit hexadecimal value. The accumulator contains the first byte output, the X register contains the second. On return, the contents of the accumulator are scrambled. RDCHAR _ Get aninput character or escape code $FD35 RDCHAR is an alternate input subroutine that gets characters from the standard input subroutine, and also interprets the escape codes listed in Chapter 3. RDKEY Get an input character $FDOC RDKEY is the character input subroutine. It places a blinking cursor on the display at the cursor position and jumps to the subroutine whose address is stored in KSW (locations $38 and $39), usually the standard input subroutine KEYIN, which returns with a character in the accumu lator. READ Read a record from a cassette SFEFD READ reads a series of tones at the cassette input port, converts t hem to data bytes, and stores the data in a specified range of memory locations. Before calling READ, the address of the first byte must be in Al ($3C-$3D) and the address of the last byte must be in A2 ($3E-$8F). 222 Appendix B: Directory of Built-in Subroutines READ keeps a running exclusive-OR of the data bytes in CHKSUM ($2). When the last memory location has been filled, READ reads one more byte and compares it with CHKSUM. If they are equal, READ sends out a beep and returns; if not, it sends the string ERR through COUT, sends the beep, and returns. SCRN Read the low-resolution graphics screen $F871 SCRN returns the color value of a single block on the low-resolution graphics display. Call it with the vertical position of the block in the accumulator and the horizontal position in the Y register. Call it as you would call PLOT (above). The color of the block will be returned in the accumulator. No other registers are changed. SETCOL Set low-resolution graphics color $F864 SETCOL sets the color used for plotting in low-resolution graphics to the value passed in the accumulator. The colors and their values are listed in Table 2-6. SETINV Set inverse mode SFE80 SETINV sets the dislay format to inverse. COUT] will then display all output characters as black dots on a white background. The Y register is set to $8F, all others are unchanged. SETNORM Set normal mode $PE84 SETNORM sets the display format to normal. COUT] will then display all output characters as white dots on a black background. On return, the Y register is set to $FF, all others are unchanged. VERIFY = Compare two blocks of memory $FE36 VERIFY compares the contents of one range of memory to another. This subroutine is the same as the VERIFY command in the Monitor, except it takes its arguments from pairs of locations in memory, low-byte first. The destination address must be in A4 ($42-$43), the starting source address in Al ($8C-$3D), and the ending source address in A2 ($3E-$3F) when your program calls VERIFY. Appendix B: Directory of Built-in Subroutines 228 VLINE Draw a vertical line of blocks $F828 VLINE draws a vertical line of blocks of the color set by SETCOL on the low-resolution display. You should call VLINE with the horizontal coordinate of the line in the Y register, the top vertical coordinate in the accumulator, and the bottom vertical coordinate in location $2D. VLINE will return with the accumulator scrambled. WAIT Delay $FCA8 WAIT delays for a specific amount of time, then returns to the program that called it. The amount of delay is specified by the contents of the accumulator. The delay is 1/2(26+27A+5A * 2) microseconds, where A is the contents of the accurmulator. WAIT returns with the accumulator zeroed and the X and Y registers undisturbed. WRITE Write a record on a cassette $FECD WRITE converts the data in a range of memory to a series of tones at the cassette output port. Before calling WRITE, the address of the first data byte must be in Al ($3C-$3D) and the address of the last byte must be in A2 ($3E-$3F). The subroutine writes a ten-second continuous tone as a header, then writes the data followed by a one-byte checksum. 224 Appendix B: Directory of Built-in Subroutines Appendix C Apple II Family Differences [wo[wma pea This appendix lists the differences among the Apple II Plus, the original and the enhanced Apple Ile, and the Apple IIc. If you're trying to write software to run on more than one version of the Apple II, this appendix will help you avoid unexpected problems of incompatibility. The differences are listed here in approximately the order you are likely to encounter them: obvious differences first, technical details later. Each entry in the list includes references to the chapters in this manual where the item is described. Keyboard The Apple Ile and Apple IIc have a full 62-key uppercase and lowercase keyboard. The keyboard includes fully-operational and keys. It also includes four directional arrow keys for moving the cursor. Chapter 2 includes a description of the keyboard. The cursor-motion keys are described in Chapter 3. Apple Keys The keyboard of the Apple Ile and Apple IIc have two keys marked with the Apple logo. These keys, called the Open-Apple key ((G]) and Solid-Apple key ({@]), are used with the key to select special reset functions. They are connected to the buttons on the hand controls, so they can be used for special functions in programs. The Apple II and the Apple II Plus do not have Apple keys. Character Sets The Apple Ile and Apple IIc can display the full ASCII character set, uppercase and lowercase. For compatibility with older Apple II’s, the standard display character set includes flashing uppercase instead of inverse-format lowercase; you can also switch to an alternate character set with inverse lowercase and uppercase, but no flashing. Chapter 2 includes a description of the display character sets. Chapter 3 tells you how to switch display formats. 226 Appendix C: Apple II Family Differences The Apple IIc and the enhanced Apple Ile include a set of “graphic” text characters, called MouseText characters, that replace some of the inverse uppercase characters in the alternate character set of the original Apple Ile. MouseText characters are described in Chapter 2. 80-Column Display TT A aa aa ee ee a a With the addition of an 80-column text card, the Apple IIe can display 80 columns of text. The 80-column display is completely compatible with both graphics modes—you can even use it in mixed mode. (If you prefer, you can use an old-style 80-column card in an expansion slot instead.) Chapter 2 includes a description of the 80-column display. The Apple IIc has a built-in extended 80-column card. Escape Codes and Control Characters a On the Apple Ile and Apple IIc, the display features mentioned above (and many others not mentioned) can be controlled from the keyboard by escape sequences and from programs by control characters. Chapter 3 includes descriptions of those escape codes and control characters. Built-in Language Card CEE eee The 16K bytes of RAM you add to the Apple II Plus by installing the Language Card is built into the Apple Ile and Apple IIc, giving the Apple Ile a standard memory size of 64K bytes. (The Apple IIc has a built-in extended 80-column text card as well, giving it a standard memory size of 128K bytes.) In the Apple Ile, this 16K-byte block of memory is called the bank-switched memory. It is described in Chapter 4. Built-in Language Card 227 Auxiliary Memory By installing the Apple Ile Extended 80-Column Text Card, you can add an alternate 64K bytes of RAM to the Apple Ile. Chapter 4 tells you how to use the additional memory. (The Extended 80-Column Text Card also provides the 80-column display option.) The Apple IIc has a built-in extended 80-column text card. Auxiliary Slot In addition to the expansion slots on the Apple II Plus, the Apple [le has a special slot that is used either for the 80-Column Text Card or for the Extended 80-Column Text Card. This slot is identified in Chapter 1 and - described in Chapter 7. The Apple IIc has the functions of the auxiliary slot built in. Back Panel and Connectors The Apple Ile has a metal back panel with space for several D-type connectors. Each peripheral card you add comes with a connector that you install in the back panel. Chapter | includes a description of the back panel; for details, see the installation instructions supplied with the peripheral cards. The Apple IIc back panel has seven built-in connectors. Soft Switches Sa ae ee The display and memory features of the Apple Ile and the Apple [Ic are controlled by soft switches like the ones on the Apple II Plus. On the Apple Ile and the Apple IIc, programs can also read the settings of the soft switches. Chapter 2 describes the soft switches that control the display features, and Chapter 4 describes the soft switches that control the memory features. 228 Appendix C: Apple If Family Differences Built-in Self-Test a See Oe eS, Ee Se ee | The Apple Ile has built-in firmware that includes a self-test routine. The self-test is intended primarily for testing during manufacturing, but you can run it to be sure the Apple Ile is working correctly. The self-test is described in Chapter 4. The Apple llc also has built-in diagnostics. Forced Reset TO es Some programs qn the Apple II Plus take control of the reset function to keep users from stopping the machine and copying the program. The Apple Ile and Apple IIc have a forced reset that writes over the program in memory. By using the forced reset, you can restart the Apple Ile (or Apple IIc) without turning power off and on and causing unnecessary stress on the circuits. The forced reset is described in Chapter 4. Interrupt Handling aNN ee a ees Even though most application programs don’t use interrupts, the Apple Ile (and Apple IIc) provide for interrupt-driven programs. For example, the 80-column firmware periodically enables interrupts while it is clearing the display (normally a long time to have interrupts locked out). Interrupts are discussed in Chapter 6. Vertical Sync for Animators Oeer ee Programs with animation on the Apple Ile and Apple IIc can stay in step with the display and avoid flickering objects in their displays. Chapter 7 includes a description of the video generation and the vertical sync. Vertical Syne for Animators 229 Signature Byte ee a a A program can find out whether it’s running on an Apple Ile, Apple IIc, Apple III (in emulation mode), or on an older model Apple II by reading the byte at location $FBB3 in the System Monitor. In the Apple IIe Monitor, this byte’s value is $06; in the Autostart Monitor (the standard Monitor on the Apple II Plus), its value is $EA. (Note: if you start up with DOS and switch to Integer BASIC, the Autostart Monitor is active and the value at location $FBB8 is $EA, even on an Apple Ile.) Obviously, there are lots of other locations that have different values in the different versions of the Monitor, location $FBB3 was chosen because it will have the value $06 even in future revisions of the Apple IIe Monitor. Hardware Implementation CEE TE eee The hardware implementation of the Apple Ile is radically different from the Apple II and Apple II Plus. Three of the more important differences are All of these features are described in oO the custom ICs: the IOU and MMU Chapter 7. o the video hardware, which uses ROM to generate both text and graphics Oo the peripheral data bus, which is fully buffered. The Apple IIc For more information about the Apple IIc, O shares some of the custom ICs of the Apple Ile see the Apple IIc Reference Manual. O has some new ones all its own O lacks the slots of the Apple Ile, replacing some of them with built-in 1/0 ports. 230 Appendix C: Apple II Family Differences Appendix D Operating Systems and Languages 231 This appendix is an overview of the characteristics of operating systems and languages when run on the Apple Ile. It is not intended to be a full account. For more information, refer to the manuals that are provided with each product. Operating Systems EESSS Se! This section discusses the operating systems that can be used with the Apple Ile. ProDOS eres ProDOS is the preferred disk operating system for the Apple IIe. It supports interrupts, startup from drives other than a Disk II, and all other hardware and firmware features of the Apple Ile. DOS 3.3 eae ae era The Apple Ile works with DOS 8.3. The Apple Ile can also access DOS 3.2 disks by using the BAS/C'S disk. However, neither version of DOS takes full advantage of the features of the Apple IIe. DOS support is provided only for the sake of Apple II series compatibility. Pascal Operating System SS a ee ee ee The Apple II Pascal operating system was developed from the UCSD Pascal system from the University of California at San Diego. While it shares many characteristics of that system, it has been extended by Apple in several areas. Pascal versions 1.2 and later support interrupts and all the hardware and firmware features of the Apple Ile. The Apple II Pascal system uses a disk format different than either ProDOS or DOS 3.3. 232 Appendix I): Operating Systems and Languages CP/M ae) CP/M® is an operating system developed by Digital Research that runs on either the Intel 8080 or Zilog Z80® microprocessors. This means that a co-processor peripheral card, available from several manufacturers for the Apple Ile, is required to run CP/M. Several versions of CP/M from 1.4 through 3.0 and later can be run on an Apple [le with an appropriate co-processor card. Languages T_T RSS a Aa fC SyOTTOMAN ek) RRL Se This section discusses special techniques to use, and characteristics to be aware of, when using Apple programming languages with the Apple Ile. Assembly Language SSS See An aid for assembly-Language programming Programs written in assembly language have the potential of extracting the is ProDOS Assembler Tools (A2W0018). most speed and efficiency from your Apple Ile, but they also require the most effort on your part. Appiesoft BASIC SS Sa) The focus of the chapters in this manual is assembly language, and so most addresses and values are given in hexadecimal notation. Appendix E in this manual includes tables to help you convert from hexidecimal to the decimal notation you will need for BASIC. In BASIC, use a PEEK to read a location (instead of the LDA used in assembly language), and a POKE (instead of STA) to write to a location. If you read a hardware address from a BASIC program, you get a value between 0 and 255. Bit 7 holds a place value of 128, so if a soft switch is on, its value will be equal to or greater than 128: if the switch is off, the value will be less than 128. Integer BASIC (re Integer BASIC is not included in the Apple Ile firmware. If you want to run it on your Apple Ile, you must use DOS 3.3 to load it in to the system. ProDOS does not support Integer BASIC. Languages 230 Pascal Language Se ee) The Pascal language works on the Apple Ile under versions 1.1 and later of the Pascal Operating System. However, for best performance, use Pascal 1.2 or a later version. FORTRAN ee ete eens FORTRAN works under version 1.1 of the Pascal Operating System which does not detect or use certain Apple Ile features, such as auxiliary memory. Therefore, FORTRAN does not take advantage of these features. 234 Appendix D: Operating Systems and Languages Appendix E Conversion Tables 230 This appendix briefly discusses bits and bytes and what they can represent. It also contains conversion tables for hexadecimal to decimal and negative decimal, for low-resolution display dot patterns, display color values, and a number of 8-bit codes. These tables are intended for convenient reference. This appendix is not intended as a tutorial for the materials discussed. The brief section introductions are for orientation only. Bits and Bytes Te en ey ee a) This section discusses the relationships between bit values and their position within a byte. The following are some rules of thumb regarding the 65C02 and 6502. oO A bit is a binary digit; it can be either a 0 or a 1. oO A bit can be used to represent any two-way choice. Some choices that a bit can represent in the Apple Ile are listed in Table E-1. Table E-1. What a Bit Can Represent Context Representing 0= = Binary number Place value 0 1 x that power of 2 Logic Condition False True Any switch Position Off On Any switch Position Clear* Set Serial transfer Beginning Start Carrier (no informa tion yet) Serial transfer Data Qvalue 1value Serial transfer Parity SPACE MARK Serial transfer End Stop bit(s) Serial transfer Communication BREAK Carrier state P reg. bit N Neg. result? No Yes P reg. bit V Overflow? No Yes P reg. bit B BRK command? No Yes P reg. bit D Decimal mode? No Yes P reg. bit I IRQ interrupts Enabled Disabled (masked out) P reg. bit Z Zero result? No Yes P reg. bit C Carry required? No Yes * Sometimes ambiguously termed reset. 2.36 Appendix E: Conversion Tables O Bits can also be combined in groups of any size to represent numbers. Most of the commonly used sizes are multiples of four bits. o Four bits comprise a nibble (sometimes spelled nybble). O One nibble can represent any of 16 values. Each of these values is assigned a number from 0 through 9 and (because our decimal system has only ten of the sixteen digits we need) A through F. Oo Eight bits (two nibbles) make a byte (Figure E-1). Figure E-1. Bits, Nibbles, and Bytes High Nibble Low Nibble ———— ee, MSB LSB (| 6 D 4 3 2 l 0 $80 $40 $20 $10 $08 $04 $02 $01 Hexadecimal 128 64 32 16 8 4 2 l Decimal Binary Hex Dec 0000 $00 0 0001 $01 1 0010 $02 2 0011 $03 3 0100 $04 4 0101 $05 5 0110 $06 6 0111 $07 7 1000 $08 8 1001 $09 ) 1010 $0A ~=:10 1011 $0B ll 1100 $0C =. 12 1101 $0D =18 1110 $0E 14 1111 $OF Ib O One byte can represent any of 16 x 16 or 256 values. The value can be specified by exactly two hexadecimal digits. Oo Bits within a byte are numbered from bit 0 on the right to bit 7 on the left. O The bit number is the same as the power of 2 that it represents, in a manner completely analogous to the digits in a decimal number. Bits and Bytes 231 oO One memory position in the Apple Ile contains one eight-bit byte of data. oO How byte values are interpreted depends on whether the byte is an instruction in a language, part or all of an address, an ASCII code, or some other form of data. oO Two bytes make a word. The sixteen bits of a word can represent any one of 256 x 256 or 65536 different values. Oo The 65C02 uses a 16-bit word to represent memory locations. It can therefore distinguish among 65536 (64K) locations at any given time. o Amemory location is one byte of a 256-byte page. The low-order byte of an address specifies this byte. The high-order byte specifies the memory page the byte is on. Hexadecimal and Decimal aa ee Use Table E-2 for conversion of hexadecimal and decimal numbers. Table E-2. Hexadecimal/Decimal Conversion Digit $x000 $0x00 $00x0 $000x F 61440 3840 240 15 07344 3004 224 14 D 53248 3328 208 13 C 49152 8072 192 12 B 45056 2816 176 1] A 40960 2560 160 10 9 36864 2304 144 9 8 32768 2048 128 8 ij 28672 1792 112 (f 6 24576 1536 96 6 4) 20480 1280 80) ) 4 16384 1024 64 4 3 12288 768 48 3 2 8192 012 32 2 4096 256 16 ] 238 Appendix E: Conversion Tables To convert a hexadecimal number to a decimal number, find the decimal numbers corresponding to the positions of each hexadecimal digit. Write them down and add them up. Examples: $3C = ? $FD47 = ? $30 = 48 $F000 = 61449 $09C = 12 $¢$ DO0 = 3328 eee Sees $ 40 = 64 $ 7s 7 $3C = 66 9 Lon neeeeuuuee $FD47 = 64839 To convert a decimal number to hexadecimal, subtract from the decimal number the largest decimal entry in the table that is less than the number. Write down the hexadecimal digit (noting its place value) also. Now subtract the largest decimal number in the table that is less than the decimal remainder, and write down the next hexadecimal digit. Continue until you have zero left. Add up the hexadecimal numbers. Example: 16215 = $ ? 1621S - 12288 = 3927 12288 = $7008 3927 - 3848 = 87 3848 = $ FOB 87 - 88 = 7 86 = $ SB 7 7 = $ 7 Hexadecimal and Decimal 239 Hexadecimal and Negative Decimal ee Se a a ee ee a eee se eee ee a ee ee ee If a number is larger than decimal 32767, Applesoft BASIC allows and Integer BASIC requires that you use the negative-decimal equivalent of the number. Table E-3 is set up to make it easy for you to convert a hexadecimal number directly to a negative decimal number. Table E-3. Hexadecimal to Negative Decimal Conversion Digit $x000 $$0x00 $$00x0 $$000x F 0 0 0 =i i -4096 -256 -16 -2 D -8192 512 -32 -3 C -12288 -768 -48 -4 B -16384 -1024 -64 5 A -20480 -1280 -80 6 ) -24576 -1536 -96 7 8 -28672 -1792 -112 -8 7 -2048 -128 9 6 -2304 -144 -10 D -2560 -160 -l] 4 -2816 -176 -12 3 -8072 -192 -13 2 -38328 -208 -14 l -3084 -224 -15 0 -3840 -240) -16 To perform this conversion, write down the four decimal numbers corresponding to the four hexadecimal digits (zeros included). Then add their values. The resulting number is the desired negative decimal number. Example: $CO18 = - ? $CH00: -12288 $¢ 800: - 3848 $ 10: - 224 $¢ 6: - 16 $C018 -16368 240 Appendix E: Conversion Tables To convert a negative-decimal number to a positive decimal number, add it to 65536. (This addition ends up looking like subtraction. ) Example: -151 = + ? 65536 + €-151) = 65536 - 151 = 65385 To convert a negative-decimal number to a hexadecimal number, first convert it to a positive decimal number, then use Table E-2. Hexadecimal and Negative Decimal 24] Graphics Bits and Pieces Table E-4 is a quick guide to the hexadecimal values corresponding to 7-bit high-resolution patterns on the display screen. Since the bits are displayed in reverse order, it takes some calculation to determine these val ues. Table E-4 should make it easy. Table E-4. Hexadecimal Values for High-Resolution Dot Patterns Bits in Data Byte Bit Pattern x=0 # x=1 Bit Pattern x=0 #£x=l x0000000 $00 $80 x0100000 $02 $82 x0000001 $40 $C0 x0100001 $42 $C2 x0000010 $20 $A0 x0100010 $22 $A2 x0000011 $60 $0 x0100011 $62 $H2 x0000100 $10 $90 x0100100 $12 $92 x0000101 $50 $D0 x0100101 $52 $D2 x0000110 $30 $B0 x0100110 $32 $B2 x0000111 $70 $F0 x0100111 $72 $F2 aC code, Seneea x0001000 $08 $88 x0101000 $0A $8A x0001001 $48 $C8 x0101001 $44 $CA x0001010 $28 $A8 x0101010 $2A $AA x0001011 $68 $58 x0101011 $64 $EA x0001100 $18 $98 x0101100 $1A $9A x0001101 $58 $D8 x0101101 $54 §$DA x0001110 $38 $B8 x0101110 $3A $BA x0001111 $78 $F8 x0101111 $7A = SFA x0010000 $04 $84 x0110000 $06 $86 x0010001 $44 $04 x0110001 $46 $C6 x0010010 $24 $A4 x0110010 $26 $A6 x0010011 $64 $h4 x0110011 $66 $K6 x0010100 $14 $94 x0110100 $16 $96 x0010101 $54 $D4 x0110101 $56 $D6 x0010110 $34 $B4 x0110110 $36 $B6 x0010111 $74 $F4 x0110111 $76 $F6 x0011000 $0C $80 x0111000 SOE $8E x0011001 $40 $CC x0111001 $4— $CE x0011010 $2C $AC x0111010 $2E $A x0011011 $6C $EC x0111011 $6E $EE x0011100 $10 $9C x0111100 $1E $98 x0011101 $5C $DC x0111101 $5E $DE x0011110 $380 $BC x0111110 $3E $BE x0011111 $7C $FC xO111111 $7E =:$FE 242 Appendix E: Conversion Tables The x represents bit 7. Zeros represent bits that are off; ones bits that are on. Use the first hexadecimal value if bit 7 is to be off, and the second if it is to be on. For example, to get bit pattern 00101110, use $3A; for 10101110, use $BA. Table E-4—Continued. Hexadecimal Values for High-Resolution Dot Patterns Bit Pattern x=0 # x=1l Bit Pattern x=0 #£x=1 x 1000000 $01 $81 x1100000 $03 $83 x1000001 $41 $C1 x1100001 $43 $03 x1000010 $21 $Al x1100010 $23 $A3 x1000011 $61 $E1 x1100011 $63 $E3 x1000100 $11 $91 x1100100 $13 $93 x1000101 $51 $D1 x1100101 $53 $D3 x1000110 $31 $B1 x1100110 $33 $B3 x1000111 $71 $F1 x1100111 $73 $F3 x 1001000 $09 $89 x1101000 $0B $8B x1001001 $49 $C9 x1101001 $4B $CB x1001010 $29 $A9 x1101010 $2B $AB x1001011 $69 $E9 x1101011 $6B $EB x1001100 $19 $99 X1101100 $1B $9B x1001101 $59 $D9 x1101101 $5B $DB x1001110 $39 $B9 x1101110 $3B $BB x1001111 $79 $F9 X1101111 $7B $FB x1010000 $05 $85 x1110000 $07 $87 x1010001 $45 $C5 x1110001 $47 $C7 x1010010 $25 $A5 X1110010 $27 $A7 x1010011 $65 $E5 X1110011 $67 $E7 x1010100 $15 $95 x1110100 $17 $97 x1010101 $55 $D5 X1110101 $57 $D7 x1010110 $35 $B5 X1110110 $37 $B7 x1010111 $75 $F5 x1110111 $77 $F7 x1011000 $0D $8D x1111000 $0F $8F x1011001 $4D $CD x1111001 $4F $CF x1011010 $2D $AD x1111010 $2F SAF x1011011 $6D $ED x1111011 $6F SEF x1011100 $1D $9D x1111100 $1F $9F x1011101 $5D $DD x1111101 $5F $DF x1011110 $3D $BD X1111110 $3F $BF x1011111 $7D $FD xl111111 $7F $FF Graphics Bits and Pieces 248 Eight-Bit Code Conversions RR a ae a ae ee Tables E-5 through K-12 show the entire ASCII character set twice: once with the high bit off, and once with it on. Here is how to interpret these tables. O The Binary column has the 8-bit code for each ASCII character. C) The first 128 ASCII entries represent 7-bit ASCII codes plus a high-order bit of 0 (SPACE parity or Pascal)—for example, 010010000 for the letter . The last 128 ASCII entries (from 128 through 255) represent 7-bit ASCII codes plus a high-order bit of 1 (MARK parity or BASIC)—for example, 11001000 for the letter H. A transmitted or received ASCII character will take whichever form is appropriate if odd or even parity is selected—for example, 11001000 for an odd-parity H, 01001000 for an even-parity H. The ASCII Char column gives the ASCII character name. The /nterpretation column spells out the meaning of special symbols and abbreviations, where necessary. The What to Type column indicates what keystrokes generate the ASCII character (where it is not obvious). The columns marked P77 and Alt indicate what displayed character results from each code when using the primary or alternate display character set, respectively. Boldface is used for inverse characters; italic is used for flashing characters. Note that the values $40 through $5F (and $CO through $DF) in the The MouseText characters are shown in alternate character set are displayed as MouseText characters if Table E-7. MouseText is turned on. 244 Appendix E: Conversion Tables Note: The primary and alternate displayed character sets in Tables E-5 through E-12 are the result of firmware mapping. The character generator ROM actually contains only one character set. The firmware mapping procedure is described in the section “Inverse and Flashing Text,” in Chapter 3. Table E-5. Control Characters, High Bit Off ASCII Binary Dec Hex Char Interpretation What to Type Pri Alt 0000000 0 $00 NUL Blank (null) (CONTROL }[@] 0000001 1 $01 SOH Start of Header 0000010 2 $02 STX Start of Text 0000011 3 $03 ETX End of Text 0000100 4 $04 EOT End of Transm. (CONTROL }(D] 0000101 5 $05 ENQ Enquiry (CONTROL HE] 0000110 6 $06 ACK Acknowledge 0000111 fi $07 BEL Bell (CONTROL }{G] 0001000 8 $08 BS Backspace (CONTROL }{H] or [=] 0001001 9 $09 HT Horizontal Tab (CONTROL }{1] Or 0001010 10 $0A LF Line Feed or] 0001011 11 $0B VT Vertical Tab (CONTROL }{Kk] or [7] 0001100 12 $0C FF Form Feed 0001101 13 $0D CR Carriage Return (CONTROL }(M] Or 0001110 14 $0E SO Shift Out (CONTROL }(N] 0001111 15 SOF SI Shift In (CONTROL }{O] 0010000 16 $10 DLE Data Link Escape = (CONTROLHP] 0010001 17 $11 DCl Device Control 1 (CONTROL }([Q] 0010010 18 $12 DC2 Device Control 2 (CONTROL }(R] 0010011 19 $13 DC3 Device Control 3 [CONTROL }{S] 0010100 20 $14 DC4 Device Control 4 0010101 21 $15 NAK Neg. Acknowledge or (=} 0010110 22 $16 SYN Synchronization 0010111 28 $17 ETB Endof Text Blk. (ConTROL}(W] 0011000 24 $18 CAN Cancel 0011001 25 $19 EM End of Medium 0011010 26 $14 SUB Substitute (CONTROL }{Z] 0011011 27 $1B ESC Escape (CONTROL HT) or 0011100 28 $1C FS File Separator 0011101 29 $1D GS Group Separator (CONTROL }(7] 0011110 30 $1E RS Record Separator EHIME OVOZZM MES SMOOWE® AU TOA OHE MR OWPEA MEOH AMO AUTO INK RDOVOZZM 001111] 31 $1F US Unit Separator [CONTROL }{_ ] = = Eight-Bit Code Conversions 245 Table E-6. Special Characters, High Bit Off ASCII Binary Dec Hex Char Interpretation Pri 0100000 32 $20 SP Space 0100001 33 $21 0100010 34 $22 0100011 i) $23 0100100 36 $24 0100101 3¢ $25 0100110 38 $26 0100111 39 $27 Closing Quote 0101000 40) $28 0101001 4] $29 0101010 42 $2A 0101011 43 $2B 0101100 44 $2C Comma 0101101 45 $2D Hyphen wm Qo se a}a * 0101110 46 $2E Period 0101111 47 $2F 0110000 48 $30 0110001 49 $31 0110010 50 $32 0110011 ol $33 0110100 52 $34 0110101 OB $35 0110110 o4 $36 0110111 OD $37 0111000 56 $38 0111001 ot 339 coon O™.* ooo YOK Gt — S™°* rh, = OD conan 0111010 58 S3A OS™" OO fH OON ee— 0111011 a9 $3B ~~. ee © 0111100 60 $3C 0111101 61 $3D 0111110 62 $3E Ol11111 63 $3F Sy At s\n An aril 246 Appendix E: Conversion Tables Table E-7. Uppercase Characters, High Bit Off ASCII Binary Dec Hex Char Interpretation a a. E 1000000 64 $40 @ 1000001 65 341 1000010 66 $42 1000011 67 $43 1000100 68 $44 1000101 69 $45 1000110 70 $46 1000111 71 $47 1001000 72 $48 1001001 73 $49 1001010 74 S4A 1001011 75 $4B lde: O® My TeéRN< 1001100 76 $4C 1001101 77 $4D 1001110 78 $45 1001111 79 S4F 1010000 80 $50 1010001 81 $5] 1010010 82 $52 1010011 83 $53 1010100 84 $54 1010101 85 $55 1010110 86 $56 1010111 87 $57 1011000 88 $58 1011001 89 $59 1011010 90 $5A 1011011 9] $5B Opening Bracket 1011100 92 $5C Reverse Slant 1011101 93 $5D Closing Bracket STATIN CHNDOVOSAZZMACT*IOBVWMmOADS SM KM avre® SERBS »~—~NwWRSETO 1011110 94 $5E Caret 1011111 95 $5F Underline 2eve et LV I lO_UN Fl Kight-Bit Code Conversions 247 Table E-8. Lowercase Characters, High Bit Off ASCII Binary Dec Hex Char Interpretation What to Type Pri 1100000 96 $60 Opening Quote 1100001 97 $61 1100010 98 $62 1100011 99 $63 1100100 100 $64 1100101 101 $65 1100110 102 $66 1100111 103 $67 Go sO yo & + ~ 1101000 104 $68 1101001 105 $69 1101010 106 $6A 1101011 107 $6B #*#~™~N + 1101100 108 $6C 1101101 109 $6D “ee ’ 1101110 110 $6E 1101111 11] $6F 1110000 112 $70 1110001 113 $71 1110010 114 $72 1110011 115 $73 1110100 116 $74 1110101 117 $75 1110110 118 $76 1110111 119 377 1111000 120 $78 1111001 121 $79 DO" AD Co GO ~~ GT %\ D 1111010 122 $7A 1111011 123 $7B Opening Brace 1111100 124 $7C Vertical Line 1111101 125 $7D Closing Brace ~~ & AO ho OD Rm ta Mew Gd son eee tr so oe Md ~N Oo 1111110 126 $7E —sovpos7 Soa Oo DO TK 6 ee rm & 3i i Overline (Tilde) 1111111 127 STF DEL Delete /Rubout Ar Vl DEL 248 Appendix E: Conversion Tables Table E-9. Control Characters, High Bit On ASCII Binary Hex Char Interpretation What to Type a)=f = et 10000000 $80 NUL Blank (null) [CONTROL }{@} 10000001 $81 SOH Start of Header [CONTROL }{A] 10000010 $82 STX Start of Text [CONTROL }{B] 10000011 $83 ETX End of Text [CONTROL }{C] 10000100 $84 KOT End of Transm. [CONTROL }[D] 10000101 $85 ENQ Enquiry [CONTROL }[E 10000110 $86 ACK Acknowledge [CONTROL }{F] 10000111 $87 BEL Bell [CONTROL }{G] 10001000 $88 BS Backspace [CONTROL }{H] OF[=] 10001001 389 HT Horizontal Tab [CONTROL }{1Jor[TAB] 10001010 $8A LF Line Feed [conTROL }[J] or[+] 10001011 $8B VT Vertical Tab [CONTROL }{K] or[1] 10001100 $8C FE Form Feed [CONTROL }{L] 10001101 38D CR Carriage Return [CONTROL }(M ]OF[RETURN ] 10001110 $8E SO Shift Out [CONTROL }[N] 10001111 SOF SI Shift In [CONTROL }[0] 10010000 $90 DLE Data Link Escape [CONTROL }{P] 10010001 $91 DC1 Device Control 1 [CONTROL }(Q} 10010010 $92 DC2 Device Control 2 [CONTROL }{R] 10010011 $93 DC3 Device Control 3 [CONTROL }[S] 10010100 $94 DC4 Device Control 4 [CONTROL }[T] 10010101 $95 NAK Neg. Acknowledge [CONTROL }{U] or[=] 10010110 $96 SYN Synchronization [CONTROL }{Vv] 10010111 $97 KTB End of Text BIk. [CONTROL }{W] 10011000 $98 CAN Cancel [CONTROL }[x] 10011001 $99 KM End of Medium [CONTROL }{Y } 10011010 S9A SUB Substitute [CONTROL }{Z] 10011011 $9B KSC Escape [CONTROL }[[) or[ESC] 10011100 $9C FS File Separator [CONTROL }[\ 10011101 $9D GS Group Separator [CONTROL }{1) SMV AOWS® SES ACTA CHNDO KM TAT N NMDHOTVOAZZUMATT Se) aAW TW KM AOI SSC NK 10011110 $9E RS Record Separator [CONTROL }{*] 10011111 SOF US Unit Separator [CONTROL }{_] Eight-Bit Code Conversions 249 Table E-10. Special Characters, High Bit On ASCII Binary Hex Char Interpretation What to Type 10100000 $A0 SP Space SPACE bar 10100001 $Al 10100010 $A2 10100011 $A3 10100100 $A4 10100101 SA5 10100110 $A6 10100111 SAT Closed Quote (acute accent) 10101000 $A8 10101001 $A9 10101010 SAA 10101011 SAB 10101100 SAC Comma 10101101 SAD Hyphen 10101110 SAB Period 10101111 SAF 10110000 $B0 10110001 $B] 10110010 $B2 10110011 $B3 10110100 $B4 10110101 $B5 10110110 $B6 10110111 $B7 10111000 $B8 10111001 $B9 oon where O™* rP cjooon oof O™." HR GC O™.°* OTS DO co CO SO SI G *wrn + 10111010 SBA 10111011 SBB 10111100 SBC 10111101 $BD 10111110 SBE 10111111 SBF hesyif ye Sy At” Vy At 200 Appendix E: Conversion Tables Table E-11. Uppercase Characters, High Bit On ASCII Binary Dec Hex Char Interpretation a =F = et 11000000 192 $0 @ 11000001 193 $Cl 11000010 194 $02 11000011 195 $03 11000100 196 $C4 11000101 197 $C5 11000110 198 $C6 11000111 199 $C7 11001000 200 $C8 11001001 201 $C9 11001010 202 $CA 11001011 203 $CB 11001100 204 $CC 11001101 205 $CD 11001110 206 $CE 11001111 207 $CF 11010000 208 $D0 11010001 209 $D1 11010010 210 $D2 11010011 211 $D3 11010100 212 $D4 11010101 213 $D5 11010110 214 $D6 11010111 215 $D7 11011000 216 $D8 11011001 217 3D9 11011010 218 SDA 11011011 219 SDB Opening Bracket 11011100 220 $DC Reverse Slant 11011101 221 $DD TATN Closing Bracket SAK CHNRDOVOAZMACTMIOIMwSOWS KM 11011110 222 $DE Caret CHNADOVOZZORO“ ES STAT NK 11011111 223 $DF Underline Eight-Bit Code Conversions 251 Table E-12. Lowercase Characters, High Bit On ASCII Binary Dec Hex Char Interpretation What to Type = Alt , 11100000 224 SEO Open Quote 11100001 220 $1 11100010 226 $E2 11100011 227 $E3 11100100 228 $E4 11100101 229 SE5 11100110 230 SE6 11100111 23] SE7 11101000 232 SES 11101001 233 SEQ 11101010 234 SEA 11101011 235 SEB 11101100 236 SEC 11101101 237 SED 11101110 238 SEE 11101111 239 SEF 11110000 240 SFO 11110001 241 $F1 11110010 242 $F2 11110011 243 $F3 11110100 244 SF4 11110101 245 SF5 11110110 246 3F6 11110111 247 SF7 11111000 248 SF8 11111001 249 SF9 11111010 250 SFA 11111011 251 SFB Opening Brace 11111100 252 SFC Vertical Line 11111101 253 $FD Closing Brace TTA AZ WAN oh OA S ATA ODO ETH pT se SM SS BES oO ao ODORH TWINK KM eo PTT TMB ESS TA 11111110 254 SFE Ssn i — & mm a o f.O ee Tna™ 0 oF —-ovpvo 38 Overline (Tilde) Hill 250 SFF DEL Delete (Rubout) DELETE DEL DEL 202 Appendix E: Conversion Tables Appendix F Frequently Used Tables This appendix contains copies of the tables you will need to refer to frequently, for example, ASCII codes and soft-switch location. The figures all have their original figure numbers. Table 2-3. Keys and ASCII Codes Note: Codes are shown here in hexadecimal; to find the decimal equival ents, refer to Table E-2. Normal Control Shift Both Key Code Char Code Char Code Char Code Char (F DEL 7F DEL F DEL 7F DEL 03 BS 08 BS 08 BS 08 BS 09 HT O09 HT 09 HT 09 HT o 0A LF OA LF OA LF. OA LF a 0B VT oB VT OB VI OB. VT 0 CR OD CR OD CR OD CR =] 15 NAK 15 NAK 15 NAK 15 NAK IB ESC 1B ESC 1B ESC 1B ESC 20 SP 0 SP 2 SP 20 °& SP ” 27 27 Ys . Ze : ,< 2C 20 , 3C <— 3C < - 2D - lF US oF = IF US > 2E 2E 3E = 3k > ye 2F / 2F / OF : oF : 0) 30 «0 30 0 299 ~~ «CY 29 ) 1 31 l 31 l 21 | 21 | 2@ 320 00 NU 4 #£=@ 00 NUL 3# 30 3 33 5) 23 # ye # 4$ 34 4 34 4 24 $ 24 $ 5% 35 D BD D 25 % 25 % 6 36 6 IE ~—sRS 5E : 1E RS 7& OL ‘i 37 ij 26 & 26 & 8* 38 8 38 8 2A : 2A . 9( 39 ) 39 g 28 ( 28 ( 3B 3B 3A 3A = + 38D = 3D = 2B + 2B “- { 5B 1B ESC 7B { 1B ESC \| 5C \ 1C FS 7C | 1C FS |} 5D 1D GS 7D \ 1D GS 60 60 7E 7E Appendix F: Frequently Used Tables Table 2-3—Continued. Keys and ASCII Codes Note: Codes are shown here in hexadecimal, to find the decimal equivalents, refer to Table E-2. Normal Control Shift Both Key Code Char Code Char Code Char Code Char A 61 a 01 SOH 41 A 01 SOH B 62 b 02 STX 42 B 2 STX C 63 c 03 ETX 43 C 03 ETX D 64 d 04 EOT 44 D (4 EOT E 65 e 05 ENQ 45 E, 05 ENQ F 66 f 06 ACK 46 F 06 ACK G 67 g 07 BEL 47 G 07 BEL H 68 h 08 BS 48 H 08 BS | 69 1 09 HT 49 I 09 HT J 6A j OA LF 4A J OA LF K 6B k OB VT 4B K OB VT L 6C l OC FF 4C L OC FF M 6D m OD CR 4D M OD CR N 6E n OE SO 4 N OE SO O 6F 0 OF S] 4F O OF SI P 70 D 10 DLE 50 P 10 DLE Q (a q 1] DCl ol Q) ll DC1 R 72 r [2 DC2 D2 R 12 DC2 S 13 S 13 DC3 D3 S 13 DC3 T 74 t 14 DC4 o4 il 14 DC4 U 15 u 15 NAK dO U 15 NAK 1) 76 V 16 SYN 56 V 16 SYN W ai Ww 17 ETB 57 W 17 ETB X 18 X 18 CAN 58 X 18 CAN Y 79 y 19 EM 59 Y 19 EM Zs 1A Z 1A SUB 5A ZL 1A SUB Table 2-2. Keyboard Memory Locations Location Hex Decimal Description $Cc000 49152 -16884 Keyboard data and strobe $0010 49168 - -16368 Any-key-down flag and clear-strobe switch Appendix F: Frequently Used Tables 250 Table 2-4. Video Display Specifications Display modes: 40-column text; map: Figure 2-2 80-column text; map: Figure 2-3 Low-resolution color graphics; map: Figure 2-7 High-resolution color graphics; map: Figure 2-8 Double-high-resolution color graphics; map: Figure 2-9 Text capacity: 24 lines by 80 columns (character positions) Character set: 96 ASCII characters (uppercase and lowercase) Display formats: Normal, inverse, flashing, MouseText (Table 2-5) Low-resolution graphics: 16 colors (Table 2-6) 40 horizontal by 48 vertical; map: Figure 2-7 High-resolution graphics: 6 colors (Table 2-7) 140 horizontal by 192 vertical (restricted) Black-and-white: 280 horizontal by 192 vertical; map: Figure 2-8 Double-high-resolution 16 colors (Table 2-8) 140 horizontal by 192 vertical graphics: (no restrictions) Black-and-white: 560 horizontal by 192 vertical: map: Figure 2-9 256 Appendix F: Frequently Used Tables Table 2-8. Double-High-Resolution Graphics Colors Repeated Color ab0 mb1l ab2 mb3 Bit Pattern Black $00 $00 $00 $00 0000 Magenta $08 $11 $22 $44 0001 Brown $44 $08 $11 $22 0010 Orange $40 $19 $33 $66 0011 Dark Green $22 $44 $08 $1] 0100 Gray 1 $2.A $55 $2A $55 0101 Green $66 $4C $19 $33 0110 Yellow $6E $5D $3B $77 0111 Dark Blue $11 $22 $44 $08 1000 Purple $19 $33 $66 $4C 1001 Gray 2 $55 $2A $55 $2A 1010 Pink $5D $3B $77 $6E 1011 Medium Blue $33 $66 $4C $19 1100 Light Blue $3B $77 $6E $5D 1101 Aqua $77 $6E $5D $3B 1110 White $7F $7F $7F $7F 1111 Table 2-9. Video Display Page Locations Display Lowest Address Highest Address Display Mode Page Hex Dec Hex Dec 40-column text, l $0400 1024 $O7FF 2047 low-resolution iu $0800 2048 $OBFF 3071 graphics 80-column text 1 $0400 1024 SO7FF 2047 a $0800 2048 $OBFF 3071 High-resolution l $2000 8192 $3FFF 16383 graphics 2 $4000 16384 $5FFF 24575 Double-high- 1t $2000 8192 $3FFF 16383 resloution graphics af $4000 163884 $5FFF 24575 * This is not supported by firmware; for instructions on how to switch pages, refer to the section “Display Mode Switching” in Chapter 2. t See the section “Double-High-Resolution Graphics,” in Chapter 2. Appendix F: Frequently Used Tables pot Table 2-10. Display Soft Switches Note: W means write anything to the location, R means read the location, R/W means read or write, and R7 means read the location and then check bet 7. Name Action Hex Function ALTCHAR W $CO0E Off: display text using primary character set ALTCHAR W $COOF On: display text using alternate character set RDALTCHAR R7 $CO1E Read ALTCHAR switch (1 = on) 80COL W $COOC Off: display 40 columns 80COL W $CO0D On: display 80 columns RD80COL R7 $COIF Read 80COL switch (1 = on) 80STORE W $C000 Off: cause PAGEZ2 on to select auxiliary RAM 80STORE W $0001 On: allow PAGE2 to switch main RAM areas RD80STORE R7 $C018 Read 80STORE switch (1 = on) PAGE2 R/W $C054 Off: select Page 1 PAGE2 R/W $C055 On: select Page 2 or, if 80STORE on, Page 1 in auxiliary memory RDPAGE2 R7 $C01C Read PAGE2 switch (1 = on) TEXT R/W $C050 Off: display graphics or, if MIXED on, mixed TEXT R/W $C051 On: display text RDTEXT R7 $CO1A Read TEXT switch (1 = on) MIXED R/W = $C052 Off: display only text or only graphics MIXED R/W $C053 On: if TEXT off, display text and graphics RDMIXED R7 $CO1B Read MIXED switch (1 = on) HIRES R/W $C056 Off: if TEXT off, display low-resolut ion graphics HIRES R/W = $C059 On: if TEXT off, display high-resoluttion or, if DHIRES on, double-high-resolution graphics RDHIRES R7 $C01D Read HIRES switch (1 = on) IOUDIS $CO7E On: disable IOU access for addresses $C058 to $CO5F; enable access to DHIRES sw itch * IOUDIS $CO7F Off: enable IOU access for addresses $C058 to $CO5F: disable access to DHIRES switch * RDIOUDIS R7 $CO7E Read IOUDIS switch (1 = off) t DHIRES R/W $CO05E On: (if IOUDIS on) turn on double-high-res. DHIRES R/W $CO5F Off: Gif IOUDIS on) turn off double-high-res. RDDHIRES R7 $CO7F Read DHIRES switch (1 = on) f * The firmware normally leaves IOUDIS on. See also T. + Reading or writing any address in the range $C070-$C07F also triggers the p-addle timer and resets VBLINT (Chapter 7). 258 Appendix F: Frequently Used Tables Table 3-1. Monitor Firmware Routines Location Name Description $0305 BASICIN With 80-column dirmware active, displays solid, blinking cursor. Accepts character from keyboard. $0307 BASICOUT Displays a character on the screen; used when the 80-column firmware is active (Chapter 8). SFC9C CLREOL Clears to end of line from current cursor position. SFC9E CLEOLZ Clears to end of line using contents of Y register as cursor position. SFC42 CLREOP Clears to bottom of window. $F832 CLRSCR Clears the low-resolution screen. $F836 CLRTOP Clears top 40 lines of low-resolution screen. $FDED COUT Calls output routine whose address is stored in CSW (normally COUT1, Chapter 3). SFDFO COUT] Displays a character on the screen (Chapter 3). $F D8E CROUT Generates a carriage return character. $FD8B CROUT] Clears to end of line, then generates a carriage return character. SFD6A GETLN Displays the prompt character; accepts a string of characters by means of RDKEY. F819 HLINE Draws a horizontal line of blocks. SFC58 HOME Clears window; puts cursor in upper-left corner of window. $FDIB KEYIN With 80-column firmware inactive, displays checkerboard cursor. Accepts character from keyboard. F800 PLOT Plots a single low-resolution block on the screen. SFO4A PRBL2 Sends 1 to 256 blank spaces to the output device. $FDDA PRBYTE Prints a hexadecimal byte. $FF2D PRERR Sends ERR and Control-G to the output device. $FDE3 PRHEX Prints 4 bits as a hexadecimal number. $941 PRNTAX Prints contents of A and X in hexadecimal. $FDOC RDKEY Displays blinking cursor; goes to standard input routine, normally KEYIN or BASICIN. F871 SCRN Reads color value of a low-resolution block. SF 864 SETCOL Sets the color for plotting in low-resolution. $FC24 VTABZ Sets cursor vertical position. $F828 VLINE Draws a vertical line of low-resolution blocks. Appendix F: Frequently Used Tables 259 Table 3-38a. Control Characters With 80-Column Firmware Off Control ASCII Apple Ile Character Name Name Action Taken by COUT1 Control-G BEL bell Produces a 1000 Hz tone for 0.1 second. Control-H BS backspace Moves cursor position one space to the left; from left edge of window, moves to right end of line above. Control-J LF line feed Moves cursor position down to next line in window; scrolls if needed. Control-M CR return Moves cursor position to left emd of next line in window; scrolls if needed. Table 3-3b. Control Characters With 80-Column Firmware On Control ASCII Apple Ie Character Name Name Action Taken by BASICOUT Control-G BEL bell Produces a 1000 Hz tone for 0.1 second. Control-H BS backspace Moves cursor position one space to the left; from left edge of window, moves to right end of line above. Control-J LF line feed Moves cursor position down to next line in window; scrolls if needed. Control-K ¢ VT clear EOS Clears from cursor position to the end of the screen. Control-L f FF home Moves cursor position to upper-left corner and clear of window and clears window. Control-M OR return Moves cursor position to left exd of next line in window; scrolls if needed. Control-N ¢ SO normal Sets display format normal. Control-O t SI inverse Sets display format inverse. Control-Q tf DCl 40-column Sets display to 40-column. Control-R t DC2 80-column Sets display to 80-column. Control-S * DC3 stop-list Stops listing characters on the display until another key is pressed. 260 Appendix F: Frequently Used Tables Table 3-3b—Continued. Control Characters With 80-Column Firmware On Control ASCII Apple Ile Character Name Name Action Taken by BASICOUT Control-U t NAK — quit Deactivates 80-column video firmware. Control-V f¢ SYN © scroll Scrolls the display down one line, leaving the cursor in the current position. Control-W + ETB _ scroll-up Scrolls the display up one line, leaving the cursor in the current position. Control-X CAN disable Disable MouseText character display; use MouseText inverse uppercase. Control-Y tf EM home Moves cursor position to upper-left corner of window (but doesn’t clear). Control-Z f SUB clear line Clears the line the cursor position is on. Control-| ESC enable Map inverse uppercase characters to MouseText MouseText characters. Control-\ FS forward Moves cursor position one space to the space right; from right edge of window, moves it to left end of line below. Control-]t GS clear EOL Clears from the current cursor position to the end of the line (that is, to the right edge of the window). Control-_ US up Moves cursor up a line, no scroll. * Only works from the keyboard. t Doesn't work from the keyboard. Table 3-5. Text Format Control Values Note: These mask values apply only to the primary character set (see text). Mask Value Dec Hex Display Format 255 SFF Normal, uppercase, and lowercase 127 $7F Flashing, uppercase, and symbols 63 $3F Inverse, uppercase, and lowercase Appendix F: Frequently Used Tables 26] Table 3-6. Escape Codes Escape Code Function [e] Clears window and homes cursor (places it in upper-left corner of screen), then exits from escape mode. [Esc ][A]}or [a] Moves cursor right one line; exits from escape mode. (Esc ](B) or [b} Moves cursor left one line; exits from escape mode. [esc }[C}or(c} Moves cursor down one line; exits from escape mode. [esc }(0}or (a) Moves cursor up one line; exits from escape mode. (esc }(E}or[e) Clears to end of line; exits from escape mode. (esc }(F) or(£) Clears to bottom of window; exits from escape mode. [esc] Jor(i)orCesc} (+) Moves the cursor up one line; remains in escape mode. See text. [esc }(J) or {Jor (esc}[~} Moves the cursor left one space; remains in escape mode. See text. (Esc) (k] or {k)or (Esc }(=] Moves the cursor right one space; remains in escape mode. See text. (esc ](M)or{m] or (esc }(+) Moves the cursor down one line; remains in escape mode. See text. [esc }(4] If 80-column firmware is active, switches to 40-column mode; sets links to BASICIN and BASICOUT; restores normal window size; exits from escape mode. If 80-column firmware is active, switches to 80-column mode; sets links to BASICIN and BASICOUT; restores normal window size; exits from escape mode. CONTROL }/D_ Disables control characters; only carriage return, line feed, BELL, and backspace have an effect when printed. [ESC ][CONTROL }{E] Reactivates control characters. [ESC ][CONTROL}[Q] If 80-column firmware is active, deactivates 80-colunm firmware; sets links to KEYIN and COUT]; restores normal window size; exits from escape mode. 262 Appendix F: Frequently Used Tables Table 3-10. Pascal Video Control Functions Control- Hex Function performed Kore $05 Turns cursor on (enables cursor display). Forf $06 Turns cursor off (disables cursor display). Gorg $07 Sounds bell (beeps). Horh $08 Moves cursor left one column. If cursor was at beginning of line, moves it to end of previous line. Jorj SOA Moves cursor down one row; scrolls if needed. Kork $0B Clears to end of screen. Lor| $0C Clears screen; moves cursor to upper-left of screen. Morm $0D Moves cursor to column 0. Norn $0E Displays subsequent characters in normal video. (Characters already on display are unaffected.) O oro SOF Displays subsequent characters in inverse video. (Characters already on display are unaffected. ) Vorv $16 Scrolls screen up one line; clears bottom line. W orw $17 Scrolls screen down one line; clears top line. Yory $19 Moves cursor to upper-left (home) position on screen. Zorz SIA Clears entire line that cursor is on. lor\ $1C Moves cursor right one column, if at end of line, does Control-M. bor] $1D Clears to end of the line the cursor is on, including current cursor position; does not move cursor. $S1E a~ or 6 GOTOxy: initiates a GOTOxy sequence; interprets the next two characters as x+32 and y+382, respectively. SIF If not at top of screen, moves cursor up one line. Appendix F: Frequently Used Tables 263 Table 4-6. Bank Select Switches Note: R means read the location, W means write anything to the location, R/W means read or write, and R7 means read the location and then check bit 7. Name Action Hex Function $C080 Read RAM; no write; use $D000 bank 2. $C081 Read ROM; write RAM; use $D000 bank 2. $0082 Read ROM; no write; use $D000 bank 2. $C083 Read and write RAM; use $D000 bank 2. $C088 Read RAM; no write; use $D000 bank 1. $C089 Read ROM; write RAM; use $D000 bank 1. $CO8A Read ROM; no write; use $D000 bank 1. $C08B Read and write RAM; use $D000 bank 1. RDBNK2 $C011 Read whether $D000 bank 2 (1) or bank 1 (0) RDLCRAM $0012 Reading RAM (1) or ROM (0). ALTZP $C008 Off: use main bank, page 0 and page 1. ALTZP $C009 On: use auxiliary bank, page 0 and page 1. RDALTZP $0016 Read whether auxiliary (1) or main (0) bank 264 Appendix F: Frequently Used Tables Table 4-7. Auxiliary-Memory Select Switches Location Name Function Hex Decimal Notes RAMRD _ Read auxiliary memory $003 49155 =-16881 Write Read main memory $002 49154 -16382 Write Read RAMRD switch $C013 49171 -16865 Read RAMWRT Write auxiliary memory $C005 49157 -16379 Write Write main memory $0004 49156 -16380 Write Read RAMWRT switch $0014 49172 -163854 Read 80STORE On: access display page $C001 49158 -16883 Write Off: use RAMRD, RAMWRT — $C000 49152 -16384 Write Read 80STORE switch $C018 49176 -16860 Read PAGE2 Page 2 on (aux. memory) $C055 49237-16299 * Page 2 off (main memory) $C054 49236 -16800 * Read PAGE2 switch $COIC 49180 -16356 Read HIRES On: access high-res. pages $C057 49239 -16297 t+ Off: use RAMRD, RAMWRT ~~ $C056 49238 -16298 + Read HIRES switch $C01D 49181 -16355 Read ALTZP Auxiliary stack & z.p. $C009 49161 -163873 Write Main stack & zero page $008 49160 -16874 Write Read ALTZP switch $C016 49174 -16852 Read *When 80STORE is on, the PAGE2 switch selects main or auxiliary display memory. + When 80STORE is on, the HIRES switch enables you to use the PAGE2 switch to switch between the high-resolution Page-1 area in main memory or auxiliary memory. Table 4-8. 48K RAM Transfer Routines Name Action Hex Function AUXMOVE JSR $C312 Moves data blocks between main and auxiliary 48K memory. XFER JMP $C314 Transfers program control between main and auxiliary 48K memory. Appendix F: Frequently Used Tables 260 Table 6-5. 1/0 Memory Switches Location Name Function Hex Decimal Notes SLOTC3ROM Slot ROM at $C300 $COOB 49163 -16373 Write Internal ROM at $C300 $COOA 49162 -16374 Write Read SLOTC3ROM switch $CO17 49175 -16361 Read SLOTCXROM Slot ROM at $Cx00 $C006 49159 -16377 Write Internal ROM at $Cx00 $C007 49158 -163878 Write Read SLOTCXROM switch $C015 49178 -16363 Read Table 6-7. 1/O Routine Offsets and Registers Under Pascal 1.1 Protocol Addr. Offset for X Register Y Register A Register $Cs0D Initialization On entry $Cs $80 On exit Error code (unchanged) (unchanged) $CsOE Read On entry $Cs $s0 On exit Error code (unchanged) Character read $CsOF Write On entry $Cs $s0 Char. to write On exit Error code (unchanged) (unchanged) $Cs10 Status On entry $Cs $s0 Request (0 or 1) On exit Error code (changed) (unchanged) 266 Appendix F: Frequently Used Tables Appendix G Using an 80-Column Text Card 267 This appendix explains how to use 80-column text cards with high-level languages. Information about using 80-column text cards with assembly language programs through the Apple Ile Monitor firmware is found in Chapter 3 of this manual. The information in this appendix applies to the Apple Ie 80-Column Text Card and the Apple Ile Extended 80-Column Text Card. If you are using Applesoft, ProDOS, or DOS you can choose to leave the 80-column text card inactive after installing it. You will want to do this when running software that does not take advantage of the 80-column display capability. The startup procedure for displaying 80 columns of text on your Apple Ile depends on which operating system you plan to use. Starting up the system with Apple II Pascal or CP/M® is very easy; the operating system does it for you; the procedures for starting up with ProDOS or DOS 3.8 are slightly more complicated, but not difficult. Starting Up With Pascal or CP/M Pascal programmers don’t have to activate the text card because Pascal does it for them. If you use the Pascal language or the CP/M operating system, displaying 80 columns of text is automatic once you've imstalled the card. Simply start up your system with any Pascal or CP/M startup disk. CP/M: CP/M (Control Program for Microprocessors) is a trademark of Digital Research. To use the CP/M operating system with your Apple Ile, make sure the SOFTCARD® by Microsoft or the Z-Engine™ by Advanced Logic Systems is correctly installed before you start up the computer. Co-Processor Cards and Interrupts: Some co-processor cards that were designed for use in the Apple II Plus may not work with an Apple Ile without some modification. There could be problems if you want to use interrupts on the Apple Ile. If you are having problems with a coprocessor card, check with the card’s manufacturer for their recommendations. Refer to the operating system reference When using Apple II Pascal 1.1, you'll probably want to run the program manual for your version of Apple Pascal for SETUP to make the (+] and (4] keys functional. SETUP is a more information. self-documenting program on the Pascal disk APPLES. Pascal ver sions 1.2 and later are already configured to use the (+] and (4) keys. 268 Appendix G: Using an 80-Column Text Card Starting Up With ProDOS or DOS 3.3 SSS inj ProDOS and DOS 3.8 both look for a startup program on the startup (boot) disk as soon as the operating system has been loaded and begins executing. If the operating system finds the program, called STARTUP on a ProDOS disk and usually called HELLO on a DOS 3.3 disk, it will execute the program. You can write a customized startup program that will set up the 80-column text card in any state you need. Just be sure it is on your startup disk and has the startup filename. Here is a sample Applesoft startup program that works with both ProDOS and DOS 3.8: 186 HOME: D$=CHR$(C4) 26 PRINT D$;"PR#3" 38 END You can do whatever you wish with the program from line 20 on. Note that the screen will have switched to 80-column text mode after line 20. By the Way: If you arrange to have the card active automatically, you will still, of course, be able to switch into 40-column mode. Using the GET Command Sn RR a wh a a a | The presence of an active 80-column text card in the Ile requires that BASIC programmers use some alternate to Applesoft’s INPUT command if their programs are to be userproof. Applesoft programmers should use either the GET command or the RDKEY or GETLN subroutines. This is because the escape sequences used to switch back and forth between modes or to deactivate the card sometimes make it necessary to accept escape sequences in INPUT mode when using an 80-column card. Because the program accepts escape sequences typed from the keyboard, your program will not be userproof against accidental sequences typed in response to an INPUT command. To get around this problem, you can use the GET command instead. The program does not read escape sequences typed from the keyboard in response to a GET command. This means that your users can err in their responses without endangering the display. Using the GET Command 269 When to Switch Modes Versus When to Deactivate When using BASIC, deactivate the text card whenever a previous (BASIC) program has left the card active (leaving a solid cursor on the screen) or whenever you want to send output to a peripheral device. Switch back and forth between 40-column and 80-column displays for visual appeal. For full use of the control charaeters described later, your card must be active, although it can display in either 40-column or 80-column mode. Original lle Tabbing in Applesoft: You must switch to a 40-column display to use Applesoft comma tabbing or the HTAB command. Display Features With the Text Card eea hee en With an active 80-column card you can issue BASIC and PRODOS commands in lowercase characters. You can also issue commands in lowercase from the keyboard, that is, in immediate mode. This is particularly convenient because REM statements and data within quotes remain in lowercase as they were typed. If you are using DOS 3.3, you must issue commands in uppercase: whether or not your card is active. INVERSE, FLASH, NORMAL, HOME TTT ka There are several commands you can give your computer from A _pplesoft BASIC to affect the appearance of text on the screen. All of these features are described in the Applesoft BASIC Programmer’s Reference Manual. O INVERSE tells the computer to display black characters on a white background instead of the normal display of white characters on a black background. This command is normally only available for uppercase characters, but with an active 80-column text card it is available for uppercase and lowercase characters. co FLASH causes subsequently printed characters to blink quick ly between inverse and normal characters. You can turn off the FLASH command by typing the NORMAL command. The FLASH command is normally available only with uppercase characters; it is not available at all while the card is active. 270 Appendix G: Using an 80-Column Text Card oO NORMAL tells the computer to turn off the INVERSE or FLASH command and to display subsequently printed characters normally. It works the same way with the card active or inactive. oO HOME clears the screen and returns the cursor to the upper-left corner of the screen. Both the NORMAL HOME and INVERSE HOME commands are available while the card is active, but INVERSE HOME works a little differently when the card is active. By the Way: The FLASH and INVERSE commands can be used to highlight important screen messages within a BASIC program. Important! If you are using the FLASH command (which means the 80-column text card is inactive) and then type PR#8 to activate the card, the screen turns white as the cursor goes to the HOME position. Whatever you type appears in black characters on the white screen. If you list or run an Applesoft BASIC program, some of the characters will appear as MouseText characters. To avoid this, remember to use either the NORMAL or INVERSE command before you exit the program. Tabbing With the Original Apple lle You cannot use conventional 40-column tabbing in BASIC with the original model Apple Ile with an 80-column display. You do not have to turn off your card, but you must switch out of 80-column mode to use the HTAB command or to use comma tabbing. When an original Apple Ile is displaying 80-column text, you should use the POKE 14038 command for horizontal tabbing in the right half of the screen instead of the HTAB command. Comma Tabbing With the Original Apple Ile SS ec ae ae ee eed In BASIC you can use commas in PRINT statements to instruct the computer to display all or part of your output in columns. This is known as comma tabbing. You can use this method of tabbing as long as the screen is displaying 40 columns (that is with the card inactive or after issuing an command to switch to 40-column mode). You cannot use this method of tabbing with an 80-column display. If you try to do so, characters will be placed in memory outside the screen area and may change programs or data in memory. Tabbing With the Original Apple Ile 271 HTAB and POKE 1403 SSS ee eee The VTAB (vertical tab) and HTAB (horizontal tab) statements can be used to place the cursor at a specific location on the screen before printing characters. The largest value you can use with the VTAB statement is 24: the largest for HTAB is 255. The VTAB command works just the same in an 80-column display as it does in a 40-column display. On the original Apple Ile, the HTAB command causes the cursor to wrap around to the next line after it reaches the 40th column, so you cannot use this command to position the cursor in the last 40 columns while the screen is displaying 80 columns. POKE 1408 is specifically designed to solve this problem. Using the POKE 1403 command allows you to tab horizontally across the extra 40 columns provided by the 80-column text card. If you want to tab past column 40 while the card is active and the screen is displaying 80 columns, use the following, where n is a number from 0 to 79: POKE 1463,N When you use the HTAB command, HTAB 1 places the cursor at the leftmost position on the screen. When you use the POKE 1408 command, POKE 1403,0 places the cursor at the leftmost position on the screen. Using Control Characters With the Card Using BASIC with an active 80-column text card increases the number of functions you can perform with control characters. Originally control-character commands were so named because they were given from the keyboard by pressing the key in conjunction with another key. You can perform the same functions from your programs by using an equivalent control-character code. Commands based on these two-key combinations are called control-character commands even when they must be issued from a program. Appendix G: Using an 80-Column Text Card Control Characters and Their Functions ar Sd a een ee) Table G-1 lists the control-character commands supported by BASIC with an 80-column card. The table includes the corresponding command code, its function and whether a given command can be executed from the keyboard as well as from a program. Table G-1. Control Characters With 80-Column Firmware On Control ASCII Apple IIe Character Code Name Action Taken by BASICOUT Control-G BEL bell Produces a 1000 Hz tone for 0.1 second. Control-H BS backspace Moves cursor position one space to the left; from left edge of window, moves to right end of line above. Control-J LF line feed Moves cursor position down to next line in window; scrolls if needed. Control-K t VT clear EOS Clears from cursor position to the end of the screen. Control-L ¢ FF home Moves cursor position to upper-left corner and clear of window and clears window. Control-M CR return Moves cursor position to left end of next line in window; scrolls if needed. Control-N tf SO normal Sets display format normal. Control-O t SI inverse Sets display format inverse. Control-Q t DC1 40-column Sets display to 40-column. Control-R t DC2 ~~ 80-column Sets display to 80-column. Control-S * DC3 __ stop-list Stops listing characters on the display until another key is pressed. Control-U t¢ NAK — quit Deactivates 80-column video firmware. Control-V t SYN _ scroll Scrolls the display down one line, leaving the cursor in the current position. Control-W t ETB _ scroll-up Scrolls the display up one line, leaving the cursor in the current position. Control-X CAN _ disable Disable MouseText character display; use MouseText inverse uppercase. Using Control Characters With the Card 213 Table G-1—Continued. Control Characters With 80-Column Firmware On Control ASCII Apple IIe Character Code Name Action Taken by BASICOUT Control-Y fT EM home Moves cursor position to upper-left corner of window (but doesn’t clear). Control-Z ft SUB clearline — Clears the line the cursor position is on. Control-[ ESC enable Map inverse uppercase characters to MouseText MouseText characters. Control-\ tf FS forward Moves cursor position one space to the space right; from right edge of window, moves it to left end of line below. Control-}f GS clearEOL Clears from the current cursor position to the end of the line (that is, to the right edge of the window). Control-_ US up Moves cursor up a line, no scroll. * Only works from the keyboard. + Doesn’t work from the keyboard. How to Use Control-Character Codes in Programs To issue a control-character command from a program, use the ASCII decimal code that corresponds to the control-character. (See Table G-1.) The following example shows how to use ASCII decimal codes in an Applesoft BASIC program. Type HOME [7] NEW 18 PRINT CHR$C15): PRINT “MAKE HAY" 26 PRINT CHR$C194): PRINT “WHILE THE SUN SHINES" RUN (CHR$ is the Applesoft BASIC command that signifies that a control-character function is to be performed.) 274 Appendix G: Using an 80-Column Text Card See Chapter 3 in this manual for a The ASCII decimal codes for inverse video (Control-O) and normal video description of control-character functions. (Control-N) are 15 and 14. When the PRINT statements in the example are executed, the display switches to inverse and prints MAKE HAY, then switches back to a normal display and prints WHILE THE SUN SHINES. A Word of Caution to Pascal Programmers Sa ee eee Avoid writing Control-U or Control-Q to the console from a Pascal program. Either one puts the system into a state that will cause Pascal to eventually crash. You can’t send control characters from the keyboard to the 80-column firmware when using Pascal. The only exceptions to this rule are Control-M (CR) and Control-G (BEL). Using Control Characters With the Card 215 AppendixH Programming With the Super Serial Card This appendix briefly describes how to use the Apple II Super Serial Card For more information about the installation (SSC) from programs, how to find the SSC through software, and the and operation of the SSC, see the Super commands supported by the SSC. Serial Card manual. The SCC is one of the most common serial interface cards used with the Apple Ile, and the Apple IIc’s serial ports operate very much like the Super Serial Card. This similarity should make it easier for you to write programs for both the Apple Ile and Apple IIc. Locating the Card Locations $Cs05, $Cs07, $CsOB, and $Cs0C (where s is the number of the The Pascal 1.1 firmware protocol is slot where the SSC is installed) contain the identification bytes for the described in Chapter 6. Super Serial Card. The identification byte’s values are $Cs05 $38 $Cs07 $18 $Cs0B $01 $Cs0C $31 Operating Modes The Super Serial Card has two main operating modes: printer mode and communications mode. There is nothing you can do from software to change from one mode to the other since they are set by the position of the jumper block. Note to Software Developers: If you are writing software that depends on the SSC being in a given operating mode, make sure that your documentation tells the user to set up the SSC in the proper way. In printer mode, the SSC is set to send data to a printer, local terrninal, or other serial device. In communications mode, the SSC is set to operate with a modem. From communications mode, the SSC can enter a speciial mode called terminal mode. In terminal mode the Apple Ile acts like an unintelligent terminal. 278 Appendix H: Programming With the Super Serial Card Operating Commands i a ee eee Sa ee ee a as For each of the operating modes, you can control many aspects of data transmission such as baud rate, data format, line feed generation, and so forth. Your program can change these aspects by sending control codes as commands to the card. All commands are preceded by a command character and followed by a carriage return character ($0D). The command character is usually Control-I in printer mode and Control-A in communications mode and terminal mode. In the command examples in the following sections, Control-I is used unless the command being described is available only in communications mode or terminal mode. A carriage return character is represented by its ASCII symbol, CR. There are three types of command formats: o Anumber, represented by n, followed by an uppercase letter with no space between the characters (for example, 4D to set data format 4). o An uppercase letter by itself (for example, R to reset the SSC). Oo An uppercase letter followed by a space and then either E to enable or D to disable a feature (for example, L D to disable automatic insertion of line feed characters). The allowable range of n is given in each command description that follows. The choice of enable or disable is indicated with E/D. The underscore character (__) before the E/D in commands that allow enable/disable is to remind you that a space is required there. The SSC checks only numbers and the first letters of commands and options. (All such letters must be uppercase. )Further letters, which you can add to assist your memory, have no effect on the SSC. For example, XOFF Enable is the same as X E. The SSC ignores invalid commands. important! The spaces in command examples are there for clarity; generally you will not use spaces in a command string. Where a space is required in a command string, an underscore (__) character will appear in the text as a reminder. Operating Commands 279 The Command Character SS ae ee ee eee eee) The normal command character is Control-I (ASCII $09) in printer mode, or Control-A (ASCII $01) in communications mode. If you want to change the command character from Control-I to Control-something else, send Control-I Control-something else. For example, to change the command character to Control-W, send Control-I Control-W. To change back, send Control-W Control-I. No return character is required after either of these commands. You can send the command character itself through the SSC by sending it twice in a row: Control-I Control-I; no return character is required after this command. This special command allows you to transmit the command character without affecting the operation of the SSC, and without having to change to another command character and then back again later. Here is how to generate this character in BASIC and Pascal: Applesoft BASIC: PRINT CHR$C9);"command" Pascal: WRITELN CCHRC9), ‘command’ ); Baud Rate, nB You can use this command to override the physical settings of switches SW1-1 through SW1-4 on the SSC. For example, to change the ba ud rate to 135, send Control-I 4B CR to the SSC. Table H-1. Baud Rate Selections n SSC Baud Rate n SSC Baud Rate 0 use SW1-1 to SW1-4 8 1200 1 a) 9 1800 2 15 10 2400 3 109.92 (110) tH 3600 4 134.58 (185) 12 4800 5) 150 13 7200 6 300 14 9600 i 600 15 19200 Appendix H: Prograinming Witti the Super Serial Card Data Format, nD ee a eo eS You can override the settings of switch SW2-1 with this command. The table below shows how many data and stop bits correspond to each value of n. For example, Control-I 2D CR makes the SSC transmit each character in the form one start bit (always transmitted), six data bits, and one stop bit. Table H-2. Data Format Selections n Data Bits Stop Bits 0 8 1 l fi l 2 6 l 3 i) l 4 8 a" D i 2 6 6 2 7 5 2T *1 with Parity options 4 through 7 + 1% with Parity options 0 through 3 Parity, nP You can use this command to set the parity that you want to use for data transmission and reception. There are five parity options available, described in Table H-3. Table H-3. Parity Selections n Parity to Use 0,2,40r6 None (default value) l Odd parity (odd total number of ones) 3 Even parity (even total number of ones) 5 MARK parity (parity bit always 1) (i SPACE parity (parity bit always 0) Operating Commands 281 For example, the command string Control-I 1P CR makes the SSC transmit and check for odd parity. Odd parity means that the high bit of every character is 0 if there is an odd number of 1 bits in that character, or 1 if there is an even number of 1 bits in the character, making the total number of 1 bits in the character always odd. This is an easy (but not foolproof) way to check data for transmission errors. Parity errors are recorded in a status byte. Set Time Delay, nC, nL, and nF Some printers can’t Keep up with the Apple Ile when they are doing certain operations. You may need to change default settings on the SSC to give a printer the time it needs. The nC command overrides the setting of switch SW2-2 on the SSC. That switch provides two choices: either no delay or a 250 millisecond delay after the SSC sends a carriage return character. The nL command allows time after a line feed character for a printer platen to turn so the paper is vertically positioned to receive the next line. The nF command allows time after a form feed character for the printer platen to move the paper form to the top of the next page (typically a longer time than a line feed). Table H-4. Time Delay Selections n Time Delay 0 none ] 32 milliseconds 2 200 milliseconds (1/4 second) 3 2 seconds Appendix H: Programming With the Super Serial Card Consult the user manual for a given printer to find out how much time it takes to move its print head and platen so you can determine an appropriate set of values for these three delays. The idea is to have at least enough time for the printer parts to move the required distance, but not so much time that overall printing speed is slowed down drastically. Many printers require no delays because they have a buffer built in to keep accepting characters even while they are doing form feeds and so on. A typical setup for a very slow printer would be Control-I 2C CR, Control-I 2L CR, Control-I 3F CR; that is, the SSC waits 250 milliseconds after transmitting carriage returns, 250 milliseconds after transmitting line feeds, and 2 seconds after transmitting form feed characters. Echo Characters to the Screen, E_E/D For the Apple Ile, as for most computers, displaying (echoing) a character on the video screen during communications is a separate step from receiving it from the keyboard, though we tend to think if these as one step, as on a typewriter. For example, if you send Control-A E_D CR, the SSC does not forward incoming characters to the Apple Ile screen. This can be used to hide someone’s password entered at a terminal, or to avoid double display of characters. This command is used in communications mode only. Automatic Carriage Return, C —————————— a Sending Control-I C CR to the SSC causes it to generate a carriage return character (ASCII CR) whenever the column count exceeds the current printer line width limit. This command is used in printer mode only. Important! Once this option is on, only clearing the high-order bit at location $578+s (where s is the slot the SSC is in) can turn this option back off. This option is normally off. Operating Commands 283 Automatic Line Feed, L_E/D You can use this command to have the SSC automatically generate and transmit a line feed character after each carriage return character. This overides the setting of switch SW2-5. For example, send Control-] L_E CR to your printer to print listings or double-spaced manuscripts for editing. Mask Line Feed In, M_E/D If you send Control-I M_E CR to the SSC, it will ignore any incoming line feed character that immediately follows a carriage return character. Reset Card, R Sending Control-I R CR to the SSC has the same effect as sending a PR#0 and an IN#0 to a BASIC program and then resetting the SSC. This command cancels all previous commands to the SSC and puts the physical switch settings back into force. Specify Screen Slot, S Sa ee ee ree ea In communications mode, you can specify the slot number of the device where you want text or listings displayed with this command. (Normally this is slot 0, the Apple Ile video screen.) This allows chaining of the SSC to another card slot, such as an 80-column text card. For the firmware in the SSC to pass on information to the firmware in the other card, the other card must have an output entry point within its $Cs00 space; this is thre case for all currently available 80-column cards for the Apple Ile. For example, let’s say you have the SSC in slot 2 with a remote terminal connected to it, and an 80-column card in slot 3. Send Control-A 3S CR to cause the data from the remote terminal to be chained through the card in slot 3, so that it is displayed on the Apple Ile in 80-column format. (Not available in Pascal.) Translate Lowercase Characters, nT a aaa ea Rs ie ie eer eee The Apple IIe Monitor translates all incoming lowercase characters into uppercase ones before sending them to the video screen or to a BASIC program. The nT command has four options, which are shown in Table H-5. 284 Appendix H: Programming With the Super Serial Card Table H-5. Lowercase Character Display Options es er n Action 0 Change all lowercase characters to uppercase ones before passing them to a BASIC program or to the video screen. This is the way the Apple Ile monitor handles lowercase. l Pass along all lowercase characters unchanged. The appearance of the lowercase characters on the Apple II screen is undefined (garbage). 2 Display lowercase characters as uppercase inverse characters (that is, as black characters on a white background). 3 Pass lowercase characters to programs unchanged, but display lowercase as uppercase, and uppercase as inverse uppercase (that is, as black characters on a white background). Suppress Control Characters, Z Bane Sane eee es rs) If you issue the Z command described here, all further commands are ignored; this is useful if the data you are transmitting, such as graphics data, contains bit patterns that the SSC can mistake for control characters. Sending Control-I Z CR to the SSC prevents it from recognizing any further control characters (and hence commands )whether coming from the keyboard or contained in a stream of characters sent to the SSC. Important! The only way to reinstate command recognition after the Z command is to either reinitialize the SSC, or clear the high-order bit at location $5F8+s (where s is the number of the slot in which the SSC is installed). Find Keyboard, F_E/ D Eee Ee ee eee eee ee You can use this command to make the SSC ignore keyboard input. For example, you can include Control-I F_D CR in a program, followed by a routine that retrieves data through the SSC, followed by Control-I F_E CR to turn the keyboard back on. Operating Commands 280 XOFF Recognition, X_E/D aee eine Sending Control-I X__E CR to the SSC causes it to look for any XOFF ($18) character coming from a device attached to the SSC, and to respond to it by halting transmission of characters until the SSC receives an XON ($11) from the device, signalling the SCC to continue transmission. In printer mode, this function is normally turned off. Caution In printer mode, full duplex communication may not work with XOFF recognition turned on, so be careful. Tab in BASIC, T E/D —SEE—E———— In printer mode only, if you send Control-I T_E CR to the SSC, the BASIC horizontal position counter is left equal to the column count. All tabs work, including back-tabs. Tabs beyond column 40 require a POKE to location 36. Commas only work as far as column 40, and BASIC programs wil] be listed in 40-column format. Note that this use of tabbing is specific to the SSC—it doesn’t go through the 80-column firmware. Terminal Mode From communications mode, the SSC can enter terminal mode and make the Apple Ile act like an unintelligent terminal. This is useful for connecting the Apple Ile to a computer timesharing service, or for conversing with another Apple II. Entering Terminal Mode, T SSS ee ee ee Send Control-A T CR to enter terminal mode. This causes the Apple Ile to function as a full-duplex unintelligent terminal. You can use this command together with the Echo command to simulate the half-duplex terrninal mode of the old Apple I] Communications Card. By the Way: If you enter terminal mode and don’t see what you type echoed on the Apple video screen, probably the modem link has not yet been established, or you need to use the Echo Enable command (Control-A K_E CR). 286 Appendix H: Programming With the Super Serial Card Transmitting a Break, B Sending Control-A B CR causes the SSC to transmit a 233-millisecond break signal, recognized by most time-sharing systems as a signoff. Special Characters, S_E/D rae ee ee ae If you send Control-A S__D CR, the SSC will treat the key like any other key. Quitting Terminal Mode, Q SS ee ee ee eee ee Send Control-A Q CR to the SSC to exit from terminal mode. SSC Error Codes eee eee ee ETT a ee et ee The SSC uses I/O scratchpad address $678+s (s is the number of the slot that the SSC is in) to record status after a read operation. The firmware calls this byte STSBYTE. Table H-6 lists the bit definitions of this byte. Table H-6. STSBYTE Bit Definitions Bit “1” Means “0” Means 0 Parity Error occurred. No Parity Error occurred. | Framing Error occurred. No Framing Error occurred. 2 Overrun occurred. No Overrun occurred. 3 Carrier lost. Carrier present. D Error occurred. No error occurred. The terms Parity, Framing Error, and Overrun are defined in the glossary. Bits 0, 1, and 2 are the same as the corresponding three bits of the ACIA Status Register of the SSC. Bit 3 indicates whether or not the Data Carrier Detect (DCD) signal went false at any time during the receive operation. SSC Error Codes 287 Bit 5 is set if any of the other bits are set, as an overall error indicator. If bit 5 is the only bit set, an unrecognized command was detected. If all bits are (),no error occurred. These error codes begin with the number 32 to avoid conflicting with previously defined and documented system error codes. In BASIC, you can check this status byte via a PEEK $678+s (s is the SSC slot), and reset it with a POKE command at the same location. In Pascal, the IORESULT function returns the error code value. By the Way: Any character—including the carriage return at the end of a WRITELN staterment—will cause posting of a new value in JORESULT. Table H-7 shows the possible combinations of error bits corresponding to these decimal error codes. Table H-7. Error Codes and Bits Error Carrier Framing Parity Code* Lost Overrun Error Error 0 no error 32 illegal command 33 no no no yes 34 no no yes no 30 no no yes yes 36 no yes no no 3 no yes no yes 38 no yes yes no 39 no yes yes yes 40) yes no no no 4] yes no no yes 42 yes no yes no 43 yes no yes yes 44 yes yes no no 45 yes yes no yes 46 yes yes yes no 47 yes yes yes yes * Result of PEEK $678+s in BASIC or IORESULT in Pascal. 288 Appendix H: Programming With the Super Serial Card The ACIA aea Na I aee ae ae em Nehcp rg ee ey The Asynchronous Communication Interface Adapter (ACIA) chip is the heart of the Super Serial Card. It takes the 1.8482 MHz signal generated by the crystal oscillator on the SSC and divides it down to one of the fifteen baud rates that it supports. The ACIA also handles all incoming and outgoing signals of the RS232-C serial protocol that the ACIA supports. The ACIA registers control hardware handshaking and select the baud rate, data format, and parity. The ACIA also performs parallel to serial and serial to parallel data conversion, and buffers data transfers. SSC Firmware Memory Use Table H-8 is an overall map of the locations that the SSC uses, both in the Apple Ile and in the SSC’s own firmware address space. Table H-8. Memory Use Map Address Name of Area Contents $0000-$00FF Page zero Monitor pointers, I/O hooks, and temporary storage. $04xx-$07xx Peripheral slot Locations (8 per slot) in Apple Ile pages $04 (selected Scratchpad RAM _ through $07. SSC uses all 8 of them. locations) $C0(8+s)0- Peripheral card I/O Locations (16 per slot) for general I/0; SSC $CO(8+s)F — space uses 6 bytes. $Cs00-$CsFF Peripheral card One 256-byte page reserved for card in slot s; ROM space first page of SSC firmware. $C800-$CFFF Expansion ROM Eight 256-byte pages reserved for 2K ROM or PROM; SSC maps its firmware onto $C800-$CEFF. SSC Firmware Memory Use 289 Zero-Page Locations SS eed The SSC uses the zero-page locations described in Table H-9. Table H-9. Zero-Page Locations Used by the SSC Address Name Description $24 * CH Monitor pointer to current position of cursor on screen $26 SLOTI6 Usually (slot x 16); that is, $s0 $27 CHARACTER. Input or output character $28 * BASL Monitor pointer to current screen line $2A ZPTMP1 Temporary storage (various uses) $2B ZPTMP2 Temporary storage (various uses) $35 ZPTEMP Temporary storage (various uses) $36 * CSWL BASIC output hook (not for Pascal) $37 * CSWH High byte of CSW $38 * KSWL BASIC input hook (not for Pascal) $39 * KSWH High byte of KSW $4E * RNDL Random number location, updated when looking for a keypress (not used when initialized by Pascal) * Not used when Pascal initializes SSC. Peripheral Card !/O Space |Se ee as en ea) There are 16 bytes of I/O space allocated to each slot in the Apple Ile. Each set begins at address $C080 + (slot x 16); for example, if the SSC is in slot 3, its group of bytes extends from $C0B0 to $COBF. Table H-10 inter prets the 6 bytes the SSC uses. 290) Appendix H: Programming With the Super Serial Card Table H-10. Address Register Bits Interpretation Address Register Bits Interpretation $C081+s0 DIPSW1 0 SW1-6 is OFF when 1, ON when 0 (SWL-x) 1 SW1-5 is OFF when 1, ON when 0 4.7 Same as above for SW1-4 through SW1-1 $C082+s0DIPSW2 0 Clear To Send (CTS) is true when 0 (SW2-x) 13 Same as above for SW2-5 through SW2-3 5,7 Same as above for SW2-2 and SW2-1 $C088+s0TDREG 0-7 ACIA transmit register (write) RDREG —O-7 ACIA receive register (read) $(089+s0 STATUS ACIA status /reset register 0 Parity error detected when 1 1 Framing error detected when 1 9 Overrun detected when 1 3 ACIA receive register full when 1 4 ACIA transmit register empty when 1 5 Data Carrier Detect (DCD) true when 0 6 Data Set Ready (DSR) true when 0 7 Interrupt (IRQ) has occurred when 1 $C08A+s0COMMAND ACIA command register (read/write) 0 Data Terminal Ready (DTR): enable (1) or disable (0) receiver and all interrupts 1 When 1, allow STATUS bit 8 to cause interrupt 9.3 Control transmit interrupt, Request To Send (RTS) level, and transmitter 4 When 0, normal mode for receiver; when 1, echo mode (but bits 2 and 8 must be 0) 5-7 Control parity $C08B+s0CONTROL ACIA control register (read/write) 0-3 Baud rate: $00 = 16 times external clock; See Table H-1. 4 When 1, use baud rate generator; when 0, use external clock (not supported) 5-6 Number of data bits: 8 (bit 5 and 6 = 0)7 (5 = 1, 6 = 0), 6(5 = 0, 6 = 1) or 5 (bit 5 and 6 both = 1) 7 Number of stop bits: 1 if bit 7 = 0; if bit 7 = 1, then 1-1/2 (with 5 data bits, no parity), 1 (8 data plus parity), or 2 SSC Firmware Memory Use 29] Scratchpad RAM Locations The SSC uses the scratchpad RAM locations listed in Table H-11. Table H-11. Scratchpad RAM Locations Used by the SSC Address Field name Bit Interpretation $0478+s DELAYFLG Form feed delay selection Line feed delay selection Carriage return delay selection Translate option $04F8+5 PARAMETE Accumulator for firmware’s command processor $0578+s STATEFLG Command mode when not 0 Slot to chain to (communications mode) Set to 1 after lowercase input character Terminal mode when 1 (communications mode) Enable CR generation when 1 (printer mode) $05F8+s CMDBYTE Printer mode default is Control-I; communications mode default is Control-A —~ Set to 1 to Zap control commands $0678+s STSBYTE Status and IORESULT byte $06F8+s CHNBYTE Current screen slot (communication mode); when NS slot = 0, chaining is enabled. $Cs00 space entry point (communications mode) PWDBYTE o~a~ Current printer width; for listing compensation, auto-CR (printer mode) $0778+s BUFBYTE One-byte input buffer (communications mode); used in conjunction with XOFF recognition Set to 1 when buffer full (communications mode) COLBYTE Current-column counter for tabbing and so forth (printer mode) $O7F8+s MISCFLG Generate line feed after CR when 1 Printer mode when 0; comminications mode when 1 Keyboard input enabled when 1 Control-S (XOFF), Control-R, and Control-T input checking when 1 Pascal operating system when 1; BASIC when 0 Discard line feed input when 1 Enable lowercase and special character generation when 1 (communications mode) Tabbing option on when 1 (printer mode) oO ~“ Echo output to Apple Ile screen when 1 292 Appendix H: Programming With the Super Serial Card Appendix | Monitor ROM Listing 00: 0000 1] TEST EQU 0 :REAL VERSION 0000 LST ON ;DO LISTING AND SYMBOL TABLES 0000: MSB ON ;SET THEM HIBITS 0000: 0001 IROTEST EQU 1 0000: 0000 DO TEST S F8ORG EQU $1800 S) C1ORG EQU $2100 S) C30RG EQU $2300 S C80RG EQU $2800 0000: ELSE 0000: F800 F8ORG EQU $F800 0000: C100 C1ORG EQU $c100 0000: C300 C30RG EQU $c300 0000: c800 C80RG EQU $c800 0000 FIN 0000 MSB ON 0000: INCLUDE EQUATES 0000 KHKKKKKKKKKEKRKEKEREKEKEEEKEREREREK AKA KRK KK 0000 * 0000 * Apple //e Video Firmware 0000 x 0000: # RICK AURICCHIO 08/81 0000: x E. BEERNINK, R. WILLIAMS 1984 0000 * 0000 * (C) 1981,1984 APPLE COMPUTER INC. 0000 * ALL RIGHTS RESERVED 0000: * 0000: KRREEKEKKEKEREKREKEREKREREKERKKKRERKKRRRRKKEK 0000: * 0000: 0006 GOODF8 EQU 6 -F8 ROM VERSION 0000 * 0000 * HARDWARE EQUATES: 0000: k 0000: co00 KBD EQU $c000 ;Read keyboard 0000: C000 CLR80COL EQU $C000 ;Disable 80 column store 0000: cool SET80COL EQU $CO01 ;Enable 80 column store 0000: c002 RDMAINRAM EQU $C002 ;Read from main RAM 0000: C003 RDCARDRAM FQU $C003 ;Read from auxiliary RAM 0000: C004 WRMAINRAM EQU $CO004 ;sWrite to main RAM 0000: C005 WRCARDRAM EQU $CO0O5 ;Write to auxiliary RAM 0000: C006 SETSLOTCXROM EQU $C0O06 ;Switch in slot CX00 ROM 0000: C007 SETINTCXROM EQU $CO07 ;Switch in internal CX0O0O ROM 0000: c008 SETSTDZP EQU $C008 ;Switch in main stack/zp/lang.card 0000: C009 SETALTZP EQU $C009 ;Switch in aux stack/zp/lang.card 0000: COOA SETINTC3ROM EQU SCOOA ;Switch in internal $C3 ROM 0000: COOB SETSLOTC3ROM EQU SCOOB ;Switch in slot $C3 space 0000: COOC CLR80VID EQU $COOC ;Disable 80 column video 0000: CcOOD SET80VID EQU $COOD ;Enable 80 column video 0000: COOE CLRALTCHAR EQU $COOE ;Normal Apple II char set 0000: COOF SETALTCHAR EQU $COOF ;Norm/inv LC, no flash 0000: C010 KBDSTRB EQU $C010 ;Clear keyboard strobe 0000: c011 RDLCBNK2 EQU $C011 32127 if LC BANK2 in use 0000: C012 RDLCRAM EQU $CO12 32127 1£ LC is read enabled 294 Appendix I: Monitor ROM Listings c013 RDRAMRD EQU $C013 3>127 if main RAM read enabled CO1lS4 RDRAMWRT EQU $C014 3>127 if main RAM write enabled c015 RDCXROM EQU SCO15 ;>127 if ROM CX space enabled C016 RDALTZP EQU $C016 32127 if alt. zp & le enabled C017 RDC3ROM EQU $CO17 3>127 if slot C3 space enabled C0138 RD80COL EQU $C018 32127 if 80 column store enabled c019 RDVBLBAR EQU $C019 3>127 if mot vertical blanking COLA RDTEXT EQU SCO1A ;>127 if text mode CO1C RDPAGE2 EQU $COI1C 32127 if page 2 COlLE ALTCHARSET EQU SCOI1LE 3>127 if alt char set switched in CO1F RD8O0VID EQU SCOIF 32127 if 80 column video enabled c030 SPKR EQU $C030 ;toggle speaker C054 TXTPAGE] EQU $C054 ;switches in text page l C055 TXTPAGE2 EQU $CO55 ;switches in text page 2 C05 D CLRAN2 EQU SCO5D sannunciator 2 C05F CLRAN3 EQU SCOSF sannunciator 3 C061 BUTNO EQU $C061 ;open-apple key C062 BUTNI EQU $C062 ;closed-apple key C081 ROMIN EQU §$C081 sswap in DOOO-FFFF ROM C08 3 LCBANK2 EQU $C083 ;swap in LC bank 2 C08 B LCBANK] EQU SCO8B ;swap in LC bank 1 * * MONITOR EQUATES: k FBBR3 F8VERSION EQU F80RG+$3B3 ;F8 ROM ID FD1 B KEYIN EQU F8ORG+$51B ;normal input FDF0O COUTL EQU F80ORG+S5FO ;normal output FF6-9 MONZ EQU F8ORG+$769 ;monitor entry point * * ZEROPAGE EQUATES: # 0000 LOCO EQU 0O sused for doing PR# 0001 LOC] EQU 1 sused for doing PR# DSECT 0020 ORG $20 0001 WNDLFT DS l :scrolling window left 0001 WNDWDTH DS l ;scrolling window width 0001 WNDTOP DS l ;scrolling window top 0001 WNDBIM DS l ;scrolling window bottom+tl 0001 CH DS l ;cursor horizontal 0001 CV DS l scursor vertical 0002 DS 2 ;GBASL ,GBASH 00Q@2 BASL DS Z ;points to current line of text 0029 BASH EQU BASLtl 0002 BAS2L DS 2 ;pointer used for scroll OO2B BAS2H EQU BAS2L+1 k OO2F ORG $2F 0001 LENGTH DS l ;length for mnemonics 0002 DS 2 0001 INVFLG DS l 3>127=normal, <127=inverse 0001 PROMPT DS l sused by monitor upshift 0001 YSAV DS 1 ;input buffer index for mini 0001 SAVY 1 DS l ;for restoring Y Appendix I: Monitor ROM Listings 295 0036 0002 CSWL z shook for output routine 0038 0037 CSWH CSWL+1 0038 0002 KSWL 2 shook for input routine 003A 0039 KSWH KSWL+1 003C 003C $3C 003C 0002 ALL 4 ;Monitor temps for MOVE 003E 003D AlH ALL+1 003E 0002 A2L 2 0040 003F A2H A2L+1 0040 0002 2 ;A3 NOT USED 0042 0002 ASL 2 0044 0043 A4H A4SL+1 0044 0001 MACSTAT 1 smachine state on breaks OO4E OO4E S4E O04E 0002 RNDL 2 srandom number seed 0050 OO4F RNDH RNDL+1 0000 0000: * 0000: 0200 BUF EQU $200 sinput buffer 0000: * Permanent data in screenholes 0000 *& 0000 * Note: these screenholes are only used by 0000: * the 80 column firmware if an 80 column card 0000: * is detected or if the user explicitly activates 0000: * the firmware. If the 80 column card is not 0000 * present, only MODE is trashed on RESET. 0000: * 0000: * The success of these routines rely on the 0000 & fact that if 80 column store is on (as it 0000: * normally is during 80 column operation), that 0000 * text page 1 is switched in. Do not call the 0000: * video firmware if video page 2 is switched in!! 0000 k 0000: 07F8 MSLOT EQU $7F8 3=$Cn ;n=slot using $C800 0000 & 0000 047B OLDCH EQU $478+3 ;LAST CH used by video firmware 0000: O4FB MODE EQU S4F8+3 ;svideo firmware operating mode 0000 057B OURCH EQU $578+3 380 column CH 0000 O5FB OURCV EQU S5F8+3 380 column CV 0000 067B CHAR EQU $678+3 scharacter to be printed/read 0000 O6FB XCOORD EQU S6F8+3 ;GOTOXY X-coord (pascal only) 0000 077B TEMP] EQU $778+3 ;temp 0000 077B OLDBASL EQU $778+3 slast BASL (pascal only) 0000 O07 FB TEMP2 EQU $7F8+3 ;temp 0000 07 FB OLDBASH EQU $7 F8+3 slast BASH (pascal only) 0000: * 0000: * BASIC MODE BITS 0000: * 0000: * Oveveeee BASIC active 0000: * Lesceses Pascal active 0000 * oDeeeoee 0000 * elesesee 0000 * oeDeccee Print control characters 0000: * ialocede a - Don't print ctrl chars. 296 Appendix I: Monitor ROM Listings oo eQeoee cocleoee coe eQeee Print control characters ecovclece Don't print next ctrl char coccelee eocvcclee coe cece eocccol. eeveeeQ Mouse text inactive ere es | Mouse text active 0040 EQU $40 002.0 | rc i) EQU $20 ;Don't print controls 0010 EQU $10 0008 EQU $08 PF (omy ;Temp ctrl disable 0004 EQU $04 0002 EQU $02 0001 OUSE EQU $01 Zenaran Pascal Mode Bits Oeeccces BASIC active Lececees Pascal active eOvscees eleccoee o Deceee coleccee ceeQeeee Cursor always on cocleoes Cursor always off cceeDoee - GOTOXY n/a cooclece GOTOXY in progress coeeeQee - Normal Video eocceles Inverse Video ececee(De PASCAL 1.1 F/W ACTIVE coccoel. PASCAL 1.0 INTERFACE eoceeeed Mouse text inactive ere ee | Mouse text active a i ee CC ee CC ee a 0080 M.PASCAL EQ U $80 ;Pascal active 0010 M.CURSOR EQU $10 ;Don't print cursor 0008 M.GOXY EQU $08 ;GOTOXY LN PROGRESS 0004 M.VMODE EQU $04 ;PASCAL VIDEO MODE 0002 M.PAS1.0 EQU $02 -PASCAL 1.0 MODE k * F8 ROM entries * FA4&7 NEWBREAK EQU F80RG+$247 FC74 IRQUSER EQU F80RG+S$474 FC7A IRQDONE2 EQU F80RG+S$47A F8B/7 TSTROM EQU F8ORG+$B7 INCLUDE BFUNC NEXT OBJECT NAME IS REFLIST.O C100 ORG C1ORG c100 BFUNCPG EQU * Appendix I: Monitor ROM Listings 297 C100: FECS FUNCEXIT EQU F8ORG+$6C5 ;RETURN ADDRESS C100: FCFO MINI EQU F8ORG+$4F0 C100: * C100: * BASIC FUNCTION HOOK: C100: x C100: * $C100 is called by the patched $F8 ROM. C100: * It provides an extension to $F8 routines C100: * that do not work in 80 columns. C100: * C100: * Before jumping here, the $F8 rom disabled C100: * slot I/0 and enabled ROM I/O. This makes C100: * the entire space from $C100 — SCFFF with the C100: * exception of the $C300 page available. C100: k C100: * On exit slot I/0 is restored if necessary. C100: x C100: * INPUT: Y=FUNCTION AS FOLLOWS: C100: k C100: * 1 = KEYIN C100: * 2 = Fix escape char C100: * 3 = BASCALC C100: * 4 = VTAB or VTABZ C100: * 5 = HOME C100: * 6 = SCROLL C100: * 7 = CLREOL C100: % 8 = CLREOLZ C100: % 9 = RESET C100: * A = CLREOP C100: * B = RDKEY C100: * C = SETWND C100: * D = Mini Assembler C100: * E = set 40 columns on PR#0/IN#0 C100: * F = Fix pick for monitor C100: k C100: * Stack has PHP for status of internal SCNO0O ROM C100: st C100: k Note: If 80 Vid is on and the MODE byte is valid, C100: x this call will be dispatched to an 80 column routine C100: * by B.FUNCO. Otherwise it will be dispatched to a C100: * 40 column routine by B-OLDFUNC. In all cases return C100: * to the Autostart ROM is done through F.RETURN. C100: * C100: B.FUNC JMP DISPATCH ;figure out what to do C103: ve C103: F.CLREOP LDY CH ; ESC F IS CLR TO END OF PAGE C105: LDA CV C107: CLEOP1] PHA C108: JSR VTABZ C1OB: JSR X.CLREOLZ C1OE: LDY #$00 C110: PLA Clll: Apc #S00 ;(carry set) C113: CMP WNDBIM C115: C107 BCC CLEOP1 298 Appendix I: Monitor ROM Listings Clil?: Cl4D BCS GVTZ s=>always to VTABZ C119: * C119: F HOME LDA WNDTOP C1l1B: STA CV C11D: LDY #$00 GILF? STY CH Ci21: C107 BEQ CLEOP1 ;(ALWAYS TAKEN) Cl23; *% C123: F.SCROLL LDA WNDTOP Cl25: PHA C126: 03 CE JSR VTABZ C129: SCRL1 LDA BASL C12B: STA BAS2L C12D: LDA BASH C12F: STA BAS2H C131: LDY WNDWDTH C133: DEY C134: PLA C135: ADC #$01 C137: CMP WNDBTM C139: C148 BCS SCRL3 C13B: PHA Cl3Gz 03 CE JSR VTABZ C13F: SCRL2 LDA (BASL),Y C141: STA (BAS2L),Y C143: DEY C144: C13F BPL SCRL2 C146: C129 BMI SCRL1 C148: SCRL3 LDY #$00 C14A: F4 Cl JSR X-CLREOLZ Cl4D: GVTZ LDA CV C14F: 03 CE GVTZ2 JMP VTABZ sset vertical base CL52% x C152: C152 F.SETWND EQU Be C152: LDA #40 C154: STA WNDWDTH C156: LDA #24 C158: STA WNDBTM C1L5A: LDA #23 C15C: STA CV CL5E: C14F BNE GVTZ2 3=>go do vtab, exit C160: * C160: * Load Y from BAS2L and clear line C160: * C160: F.CLREOLZ LDY BAS2L ;set up by SF8 ROM C162: JMP X.CLREOLZ ;and clear line C165: * C165: * 80 column routines begin here C165: * C165: EB CB B.SCROLL JMP SCROLLUP ;D0 IT FOR CALLER C168: * C168: * Clear to end of line using Y = OURCH C168: * C168: 9A CC B.CLREOL JMP X.GS sclear to end of line Appendix I: Monitor ROM Listings 299 C1l6B: * C1l6B: * Clear to end of line using Y = BAS2L Cl6B: * which was set up by the $F8 ROM C1L6B: * C1l6B: B.CLREOLZ LDY BAS2L sget Y Cl6D: JMP X.GSEOLZ j;clear to end of line C170: x C170: B.CLREOP JMP X.VT ;CLEAR TO EOS C173: B.SETWND JMP B.SETWNDX C176: B.RESET JMP B.RESETX ;MUST BE IN BFUNC PAGE C179: B.RDKEY JMP B.RDKEYX Clic: * C17G: B.-HOME JSR X.FF ;HOME & CLEAR C17F: LDA OURCH C182: STA CH sCOPY CH/CV FOR CALLER C184: STA OLDCH ; REMEMBER WHAT WE SET C187: JMP VTAB scalc base & return C18A: rs C18A: * Complete PR# or IN# call. Quit video firmware C18A: * if PR#O and it was active (B.QUIT). Complete call C18A: * if inactive (F.QUIT). C18A: te C18A: C18A B -QUIT EQU * C18A: LDY LOCO,X swas it PR#O/IN#0? C18Cc: C19D BEQ NOTO s=>no, not slot 0 C18E: CPY #KEYIN swas it IN#0? C190: C1 A0 BEQ ISO ;=>yes, update high byte C192: CD JSR QUIT ;quit the firmware C195: F.QUIT LDY LOCO,X ;get low byte into Y C197: C19D BEQ NOTO snot slot O, firmware inactive C199: F8HOOK LDA #no, set to SFDOC C1lA6: C8 JMP C3IN selse set to $C305, exit A=SC3 C1A9: C1A9: F.RDKEY LDY CH ;else do normal 40 cursor C1LAB: LDA (BASL),Y grab the character C1AD: C1LAE: AND #S$3F sset screen to flash C1B0: ORA #540 C1B2: STA (BASL),Y j;and display it C1B4: F.NOCUR PLA C1B5: RTS sreturn (A=char) C1B6: * C1B6: F.BASCALC TAY srestore Y C1B/: LDA BASL ;restore A C1B9: BA CA JSR BASCALC ;calculate base address C1BC: 4C C20A BCC F.RETURN ;BASCALC always returns BCC! C1BE: 300 Appendix I: Monitor ROM Listings CIBE: B.ESCFIX EQU * C1BE: JSR UPSHFT supshift lowercase CIC1L: B.ESCFIX] LDY #4-1 ;SCAN FOR A MATCH Cic3: B.ESCFIX2 EQU * C1C3: CMP ESCIN,Y ;1S IT? C1C6: BNE B.ESCFIX3 3=>NAW C1Cc8: LDA ESCOUT,Y ;sYES, TRANSLATE IT C1CB: B.ESCFIX3 EQU * C1CB: DEY C1CC: BPL Be ESCFIX2 CICE: BMI F.RETURN ;RETURN:CHAR IN AC C1D0: * C1D0: c8 F.BOUT JSR BOUT sprint the character C1D3: C2 JMP F.RETURN ;AND RETURN C1D6: * C1D6: * Do displaced mnemonic stuff C1D6: * C1D6: MNNDX TXA ;get old acc C1D7: AND #$03 smake it a length C1D9: STA LENGTH C1DB: LDA BAS2L sget old Y into A C1DD: AND #S8F C1DF: CA JMP DOMN ;and go to open spaces ClE2: * CIE2% FC GOMINI JSR MINI ;do mini-—assembler C1E5: TXA ;X=0. Set mode to 0, and counter ClE6: STA YSAV sso not CR on new line ClE8: RTS C1E9: * ClE9: * Pick an 80 column character for the monitor ClE9: * ClE9: 7B 05 FIXPICK LDY OURCH sget 80 column cursor C1lEC: CE JSR PICK ;pick the character ClEF: 80 #$80 salways pick as normal C1Fl: sand return C1F2: * C1F2: * Load CH into Y and clear line C1F2: * C1lF2: ClF2 F.CLREOL EQU * C1F2: XeCLREOL LDY CH ;get horizontal position C1F4: X.CLREOLZ LDA #$A0 ;store a normal blank C1F6: co BIT ALTCHARSET ;unless alternate char set C1F9: C201 BPL XCLREOL2 ClFB: BIT INVFLG ;and inverse C1FD: C201 BMI X.CLREOL2 C1FF: LDA #$20 suse inverse blank C201: CC X.CLREOL2 JMP CLR40 sclear to end of line C204: * C204: * Call VTAB or VTABZ for 40 or 80 columns. Acc (CV) C204: * is saved in BASL. C204: * C204: F.VTABZ TAY ;restore Y C205 :A5 28 LDA BASL sand A C207 :20 03 CE JSR VTABZ sdo VTABZ Appendix I: Monitor ROM Listings 301 C20A: * C20A: * EXIT. EITHER EXIT WITH OR WITHOUT C20A: * ENABLING I/O SPACE. C20A: & C20A: C20A F.RETURN EQU * C20A: PLP sGET PRIOR 1/0 DISABLE C20B: 03 C210 F.RET2 BMI F.RETI 3;=>LEAVE IT DISABLED C20D: C5 FE JMP FUNCEXIT ;=>EXIT & ENABLE I/0 C210: C8 FE F.RET] JMP FUNCEXIT+3 ;EXIT DISABLED C213: * C213: * Do BOUT, E SCFIX, BASCALC, and KEYIN immediately C213: * to avoid destroying Accumulator. C213: *& C213: DISPATCH DEY C214: BA C1D0 BMI F.BOUT scode 0 = 80 column output C216: C217: A5 C1BE BeESCFIX ;code 1 = ESCFIX C219: C21A: 9A C1B6 F.BASCALC ;code 2 BASCALC C21C: C21D: 3D C25C B.KEYIN ;code 3 = KEYIN C21F: C220: E2 C204 F.VTABZ scode 4 = VTABZ C222: C222: * First push address of generic return routine C222: C222: C2 #F .RETURN-1 C227: C228: C228: * If any of 5 bits in S$4FB (MODE) is on, then the mode is not C228: * valid for video firmware. Use old routines. C228: C228: FB 04 LDA MODE sno, is mode valid? C22B: AND #M.PASCAL+M.6+M.4+M.2+M.1 C22D: C23C BNE GETFUNC ;=>no, use 40 column routines C22F: TYA 380 column routines in C230: CLC ;2nd half of table C231% ADC #TABLEN C233: PHA C234: JSR CSETUP ;set up 80 column cursor C237: JSR VTAB ;calc base C23A: PLA C23B: TAY srestore Y C23C: * C23C: * Now push a ddress of routine C23C: k C23C: Cl GETFUNC LDA #F.HOME-1 3;(5) 40 column HOME 6245: 283 DFB #>F.SCROLL-1 ;(6) 40 column scroll C246: 284 DFB #>F.CLREOL-1 ;(7) 40 column clear line C247: 285 DFB #>F.CLREOLZ-1 ;(8) 40 column clear with Y set C248: 286 DFB #>B.RESET-1 ;(9) 40/80 column reset C249: 287 DFB #>F.CLREOP-1 ;(A) 40 column clear end of page C24A: 288 DFB #>F.RDKEY-1 ;(B) readkey w/flashing checkerboard C24B: 289 DFB #>F.SETWND-1 ;(C) Set 40 column window C24C: 290 DFB #>GOMINI-1 ;(D) Mini-assembler C24D: DFB #>F.QUIT-1 ;(E) quit before IN#0,PR#0 C24E: DFB #>FIXPICK-1 ;(F) fix pick for 80 columns C24F: DFB #>MNNDX-1 ;(10) calc mnemonic index C250: C250: 000C 295 TABLEN EQU *-F.TABLE C250: # C2502 DFB #>B.HOME-1 ;(11) 80 column HOME C2512 DFB #>B.SCROLL-1 ;(12) 80 column scroll C252: DFB #>B.CLREOL-1 ;(13) 80 column clear line G293% DFB #>B.CLREOLZ-1 ;(14) 80 column clear with Y set C254: DFB #>B.RESET-1 ;(15) 40/80 column reset C255: DFB #>B.CLREOP-1 3;(16) 80 columm clear end of page C256: DFB #>B.RDKEY-1 ;(17) readkey w/inverse cursor C257* DFB #>B.SETWND-1 ;(18) 40/80 column VTAB C258: DFB #>GOMINI-1 ;(19) Mini-Assembler C259% DFB #>B.QUIT-1 ;(1A) quit before IN#0, PR#O C25A: DFB_ #>FIXPICK-1 ;(1B) fix pick for 80 columns C25B: DFB #>MNNDX-1 3;(1C) calc mnemonic index C25C3 x C25C: C25c 310 B.KEYIN EQU * C25C :2C 1F CO BIT RD80VID 380 columns? C25F: 10 06 C267 312 BPL B.KEYINI ;=>no, flash the cursor C261 2:20 74 C8 JSR BIN ;get a keystroke C264 :4C OA C2 314 GOF.RET JMP F.RETURN ;and return C267: 315 # C267: 316 B.KEYINI TAY ;preserve A C268: 317 TXA ;put X on stack C269: 318 PHA C26A: 319 TYA ;restore A C26B: 320 PHA ;save char on stack C26C: 321 PHA sdummy for cursor/char test C26D: 22 k C26D: 323 NEW.CUR PLA ;get last cursor C26E :C9 FF 324 CMP #SFF swas it checkerboard? C270 :FO 04 C276 325 BEQ NEW.CURI] ;=>yes, get old char Appendix I: Monitor ROM Listings 303 C272:A9 FF 326 LDA #SFF sno, get checkerboard C274:D0 02 C278 327 BNE NEW.CUR2 ;=>always C276:68 328 NEW.CURI1 PLA sget character C277:48 329 PHA sinto accumulator C278:48 330 NEW.CUR2 PHA ;save for next cursor check C279:A4 24 331 LDY CH sget cursor horizontal C27B:91 28 332 STA (BASL),Y sand save char/cursor C27D: 333 * C27D: 334 * Now leave char/cursor for awhile or C27D: 335 * until a key is pressed. C27D: 336 * C27D:E6 4E 337 WAITKEY1 INC RNDL ;bump random seed C27F:DO0 OA C28B 338 BNE WAITKEY4 3;=>and check keypress C281:A5 4F 339 LDA RNDH sis it time to blink yet? C283:E6 4F 340 INC RNDH C285:45 4F 341 EOR RNDH C287:29 40 342 AND #$40 C289:DO E2 C26D 343 BNE NEW.CUR s=>yes, blink it C28B:AD 00 CO 344 WAITKEY4 LDA KBD ;Ivories been tickled? C28E:10 ED C27D 345 BPL WAITKEY1] sno, keep blinking C290: 346 * C290:68 347 PLA ;pop char/cursor C291 :68 348 PLA ;pop character C292:A4 24 349 LDY CH ;and display it C294:91 28 350 STA (BASL),Y 3;(erase cursor) C296:68 351 PLA srestore X C297: AA 352 TAX C298:AD 00 CO 353 LDA KBD snow retrieve the key C29B:8D 10 CO 354 STA KBDSTRB ;clear the strobe C29E:30 C4 C264 355 BMI GOF.RET s=>exit always C2A0: 356 * C2A0: C2A0 357 B.SETWNDX EQU * C2A0:20 52 Cl 358 JSR F.SETWND ;set 40 column width C2A3:2C 1F CO 359 BIT RD80VID ;80 columns? C2A6:10 02 C2AA 360 BPL SKPSHFT 3=>no, width ok C2A8:06 21 361 ASL WNDWDTH smake it 80 C2AA:A5 25 362 SKPSHFT LDA CV C2AC:8D FB 05 363 STA OURCV ;update OURCV C2AF:60 364 RTS C2B0: 365 * C2B0: 366 * HANDLE RESET FOR MONITOR: C2B0: 367 * C2B0: C2B0 368 B.RESETX EQU * C2B0:A9 FF 369 LDA #SFF s;DESTROY MODE BYTE C2B2:8D FB 04 370 STA MODE C2B5:AD 5D CO 371 LDA CLRAN2 ; SETUP C2B8:AD 5F CO 372 LDA CLRAN3 ; ANNUNCIATORS C2BB: 373 * C2BB: 374 * IF THE OPEN APPLE KEY C2BB: 375 * (ALIAS PADDLE BUTTONS 0) IS C2BB: 376 * DEPRESSED, COLDSTART THE SYSTEM C2BB: 377 * AFTER DESTROYING MEMORY: C2BB: 378 * C2BB:AD 62 CO 379 LDA BUTNI ‘GET BUTTON 1 (SOLID) 304 Appendix I: Monitor ROM Listings 03 C2C3 380 BPL NODIAGS s=>Up, no diags 24C 00 C6 381 JMP DIAGS ;=>else go do diagnostics : AD 61 co 382 NODIAGS LDA BUTNO ;GET BUTTON 0 (OPEN) 1A C2E2 383 BPL RESETRET ;=>NOT JIVE OR DIAGS 384 * 385 * BLAST 2 BYTES OF EACH PAGE, 386 * INCLUDING THE RESET VECTOR: 387 * BO 388 LDY #$BO ;LET IT PRECESS DOWN 00 389 LDA #0 3C 390 STA AIL BF 391 LDA SBF s;START FROM BFXX DOWN 392 SEC ;FOR SUBTRACT C2D1 393 BLAST EQU * 3D 394 STA AIH 395 PHA ;Save acc to store AO 396 LDA #SA0O sblanks E16 397 STA (AI1L),Y 398 DEY 3C 399 STA (AIL),Y 400 PLA srestore acc for counter Ol 401 SBC #1 ;BACK DOWN TO NEXT PAGE Ol 402 CMP #1 ;STAY AWAY FROM STACK! EF C2D1 403 BNE BLAST 404 * 405 * If there is a ROM card plugged into slot 3, 406 * don't switch in the internal ROM C3 space. If not, 407 * only switch them in if there is a RAM card 408 * in the video slot. 409 * 410 * NOTE: The //e powers up with internal $C3 ROM switched 411 * in. TSTROMCARD switches it out, RESETRET may or may 412 * not switch it back in. 413 * C2E2 414 RESETRET EQU * co 415 STA SETSLOTC3ROM ;swap in slot 3 CA 416 JSR TSTROMCRD ;ROM or no card plugged in? C2ED 417 BNE GORETNI 3=>ROM or no card, leave $C3 slot co 418 STA SETINTC3ROM ;card, enable internal ROM 419 GORETNI RTS 420 * 8A 8B 421 ESCIN DFB $88,$95,$8A,S8B 422 * 423 B.eRDKEYX LDY CH sget cursor position 424 LDA (BASL),Y j;and character 425 BIT RN80VID 380 columns? C2ED 426 BMI GORETNI 3s=>don't display cursor 427 JMP INVERT selse display cursor, exit 428 * 0002 429 ZSPAREC2 FEQU C30RG-* 0002 430 DS C30RG-*,0 000 431 IFNE *-C30RG 432 FAIL 2,'C300 overflow' 433 FIN Appendix I: Monitor ROM Listings 305 C300: INCLUDE C3SPACE C300: RAKKKKKKKKEKERAERERKEKRERERREAKKEK REE KAKKK AK C300: C300: THIS IS THE $C3XX ROM SPACE: C300: Note: This page must not be used by any routines C300: called by the F8 ROM. When it is referenced, it claims C300: the C800 space (kicking out anyone who was using it). C300: This also means that peripheral cards cannot use the AUXMOVE C300: and XFER routines from their C800 space. C300: WH © SE HNO*& +F ee te OoOnN C300: RHEKEKKKEEKERKEKKEKRERERKKREKEREKKERERKKEKE C300: C300 CNOO EQU * C300: C300 BASICINT EQU * C300 :2C 43 CE BIT SEV sset vflag (init) C303: 70 12 ~=C317 BVS BASICENT ;( ALWAYS TAKEN) C305: k C305: * BASIC input entry point. After a PR#3, this is the C305: * address that is called to input each character. C305: k C305: C305 BASICIN EQU * C305 238 cee oe oe el oo | od cell Ol ell — WH & nn Om Oo CO SEC C306 :90 DFB $90 ;BCC OPCODE (NEVER TAKEN) C307: k C307: * BASIC output entry point. After a PR#3, this is the C307: * address that is called to output each character. C307: x C307: C307 BASICOUT EQU * C307 :18 KH DN Bh HD ho bo po&= WH SNM CLC C308 :B8 CLV ;CLEAR VFLAG (NOT INIT) C309 >50 OC C317 BVC BASICENT ;(ALWAYS TAKEN) C30B: * DOOo Ww NO C30B: * Pascal 1.1 Firmware Protocol table: C30B: * C30B: * This tables identifies this as an Apple //e 80 column C30B: * card. It points to the four routines available to C30B: * programs doing 1/0 using the Pascal 1.1 Firmware C30B: * Protocol. C30B: WH x WwwWwW& WwW — “SDN C30B: 01 DFB $01 ;GENERIC SIGNATURE BYTE C30C: 88 DFB $88 ;DEVICE SIGNATURE BYTE C30D: Ww & © OO* C30D: 4A DFB #>JPINIT ;PASCAL INIT C30E 250 DFB_ #>JPREAD ;PASCAL READ C30F: 56 DFB #>JPWRITE ;PASCAL WRITE C310 Hey& DFB #>JPSTAT ;PASCAL STATUS C311: KHKKKKKRKAKKERKRAKERERERER AER ERER AK KEKKRERE C311: k C311: Nh * ee? DP eeWw =SOU 128K SUPPORT ROUTINE ENTRIES: C311: > oO & C311 :4C 76 C3 49 JMP MOVE ;MEMORY MOVE ACROSS BANKS C314 >4C C3 C3 50 JMP XFER ; TRANSFER ACROSS BANKS C317: KHAAKKAKKKKK KKK KKKKREK AKER ARERR RRR C317: Ww= * bp C317 :8D 7B 06 oF BASICENT STA CHAR 306 Appendix I: Monitor ROM Listings C31A:98 TYA ; AND Y C31B:48 PHA C31C:8A TXA ; AND X C31D:48 PHA C31E:08 PHP ;SAVE CARRY & VFLAG C31F: C31F: If escape mode is allowed, the high bit of MSLOT is C31F: clear. Set M.CTL to flag that 1) escapes are allowed, and C31F: 2) that control characters should not be echoed. C31F: M.CTL is cleared by BPRINT. C31F: F eee + C31F:AD LDA MODE ;else esc enable, ctl disable C322:2C BIT MSLOT ;get MSLOT C325:30 BMI NOGETLN s=>Esc disable, ctl char enable C327:09 ORA #M.CTL C329:8D STA MODE C32C: * C32C: NOGETLN EQU C32C:20 JSR SETC8 ; SETUP C8 INDICATOR C32F:28 PLP ;GET VFLAG (INIT) C330:70 BVS JBASINIT ;=>D0O THE INIT C332: C3322 If a PR#O has been done, input should be transferred Gi32% from the video firmware to KEYIN. This is detected C332: if the high bit of the mode byte is set. C332: +& C332:90 C344 JC8 ;=DPoutput , no problem C334:AA ;test mode C335:10 C344 JC8 svideo firmware is on C337:20 CD SETKEYIN ;else set FDIB as input C33A:68 ;restore registers C33B:AA C33C :68 C33D:A8 C33E:AD 06 CHAR C341 :6C 00 (KSWL) ;go input the character C344: * C344:4C JC8 JMP C8BASIC ;GET OUT OF CN SPACE C347:4C JBASINIT JMP BASICINIT ;=>GOTO C8 SPACE C34A: * C34A: JPINIT EQU k C34A:20 JSR SETC8 sSETUP C8 INDICATOR C34D:4C JMP PINIT sXFER TO PASCAL INIT C350: JPREAD EQU k C350:20 JSR SETC8 ;SETUP C8 INDICATOR C353:4C JMP PREAD sXFER TO PASCAL READ C356: JPWRITE EQU & C356:20 JSR SETC8 ;SETUP C8 INDICATOR C359:4C JMP PWRITE ;XFER TO PASCAL WRITE C35C: * C35C: AA JPSTAT TAX sis request code = 0? C35D: FO 08 BEQ PIORDY ;=Pyes, ready for output C35F:CA DEX ;check for any input C360:D0 07 BNE PSTERR ;=>bad request, return error Appendix I: Monitor ROM Listings 307 C362 :2C 00 CO BIT KBD ;look for a key C365: 10 04 C36B BPL PNOTRDY 3=>no keystroked C367: PIORDY SEC C368: RTS C369: # C369: 03 PSTERR LDX #3 selse flag error C36B: PNOTRDY CLC C36C: RTS C36): KHKKKKKK KKK KKKKRERERRERKEKRKAKKKKK KK KKKAK KR C36D: * NAME : SETC8 C36D: * FUNCTION: SETUP IRQ $C800 PROTOCOL C36D: * INPUT : NONE C36D: * OUTPUT : NONE C36D: * VOLATILE: NOTHING C36D: * CALLS : NOTHING C36D: KREKEKKKKKEKKEKEKREREEEEKEKRERERERKE KKK C36D: * C36D: SETC8 EQU rs C36D: A2 LDX #CARD C376: * CLR=CARD-->MAIN C376: * OUTPUT : NONE C376: * VOLATILE: NOTHING C376: * CALLS : NOTHING C376: RAKEAKKERIKKEKEKRERKEREKEKEEEKKK KKK C376: * C376: C376 MOVE EQU C376: ;SAVE AC C377: ; AND Y C378: C379: 13 co LDA RDRAMRD ;SAVE STATE OF C37C: PHA ; MEMORY FLAGS G37D: 14 co LDA RDRAMWRT C380: PHA C381: * C381: * SET FLAGS FOR CROSSBANK MOVE: C381: * C381: BCC MOVEC2M ;=>CARD—->MAIN C383: STA RDMAINRAM ;SET FOR MAIN C386: STA WRCARDRAM ; TO CARD C389: BCS MOVESTRT ;=>(ALWAYS TAKEN) C38B: * C38B: MOVEC2M EQU * C38B: STA WRMAINRAM ;SET FOR CARD C38E: STA RDCARDRAM ; TO MAIN 308 Appendix J: Monitor ROM Listings C391: 162 * C391: C391 163 MOVESTRT EQU * C391: 00 164 LDY #0 ;DUMMY INDEX C393: 165 * C393: C393 166 MOVELOOP EQU * C393: 3C 167 LDA (A1IL),Y 3GET A BYTE C395: 42 168 STA (A4L),Y *MOVE IT C397: 42 169 INC C399: 02 C39D 170 BNE C39B: 43 171 INC C39N: 3C 172 NXTAI1 LDA C39F: 3E 173 CMP C3Al: 3D 174 LDA C3A3: 3F 175 SBC C3A5: 3C 176 INC C3A7: 02 C3AB 177 BNE C3A9: 3D 178 INC AlH C3AB: E6 C393 179 col BCC MOVELOOP ;=>MORE TO MOVE C3AD: 180 * C3AD: 181 * RESTORE ORIGINAL FLAGS: C3AD: 182 * C3AN: 04 CO 183 STA WRMAINRAM ;CLEAR FLAG2 C3B0: 184 PLA ;GET ORIGINAL STATE C3B1: 03 C3B6 185 BPL C03 ;=>IT WAS OFF C3B3: 05 CO 186 STA WRCARDRAM C3B6: C3B6 187 C03 EQU * C3B6: 02 CO 188 STA RDMAINRAM ;CLEAR FLAG1 C3B9: 189 PLA ;GET ORIGINAL STATE C3BA: 03 C3BF 190 BPL MOVERET 3=>IT WAS OFF C3BC: 03 CO 191 STA RDCARDRAM C3BF: C3BF 192 MOVERET EQU k C3BF: 193 PLA ;RESTORE Y C3CO0: 194 TAY C3Cl: 195 PLA ; AND AC C302: 196 RTS C3C3: 197 BRRKERKERKEKKKKREKRERKEKEREKERERERKRKKEKKEREKKE C3C3: 198 NAME > XFER C3C3: 199 FUNCTI ON: TRANSFER CONTROL CROSSBANK C3C3: 200 INPUT : S$O3ED=TRANSFER ADDR C3C3: 201 : CARRY SET=XFER TO CARD C3C3: 202 CLR=XFER TO MAIN C3C3: 203 : VFLAG CLR=USE STD ZP/STK C3C3: 204 SET=USE ALT ZP/STK C3C3: 205 OUTPUT : NONE C3G3: 206 VOLATI LE: SO3ED/03EE IN DEST BANK C3C3: 207 CALLS : NOTHING C3C3: 208 FFe eeNOTE HF ee : ENTERED VIA JMP, NOT JSR C3C3: 20Q KRRRKKKRKKKKAKKKKEKEKREKKKEREREEKREA KKK KKK C3c3: 210 * c3G3: C3C3 211 XFER EQU * C3C3 248 212 PHA ;SAVE AC ON CURRENT STACK C3C4: 213 * C3C4: 214 * COPY DESTINATION ADDRESS TO THE C3C4: 215 * OTHER BANK SO THAT WE HAVE IT Appendix I: Monitor ROM Listings 309 C3C4: 216 * IN CASE WE DO A SWAP: C3C4: 217 * C3C4:AD ED 03 218 LDA $03ED ;GET XFERADDR LO C3C7:48 219 PHA ;SAVE ON CURRENT STACK C3C8:AD EE 03 220 LDA SO3EE ;GET XFERADDR HI C3CB:48 221 PHA “SAVE IT TOO C3CC: 222 % C3CC: 223 * SWITCH TO APPROPRIATE BANK: C3CC: 224 * C3CC:90 08 C3D6 225 BCC XFERC2M *>=>CARD-—>MAIN C3CE:8D 03 CO 226 STA RDCARDRAM ;SET FOR RUNNING C3D1:8D 05 CO 227 STA WRCARDRAM ; IN CARD RAM C3D4:B0 06 C3DC 228 BCS XFERZP 3=> always taken C3D6: C3D6 229 XFERC2M EQU * C3D6:8D 02 CO 230 STA RDMAINRAM ;SET FOR RUNNING C3D9:8D 04 CO 231 STA WRMAINRAM ; IN MAIN RAM C3DC: 232 * C3DC: C3DC 233 XFERZP EQU * ;SWITCH TO ALT ZP/STK C3DC :68 234 PLA ;STUFF XFERADDR C3DD:8D EE 03 235 STA SO3EE ; HI AND C3E0 :68 236 PLA C3E1:8D ED 03 237 STA S$0O3ED ; LO C3E4 :68 238 PLA ;RESTORE AC C3E5:70 05 C3EC 239 BVS XFERAZP ;=>switch in alternate zp C3E7:8D 08 CO 240 STA SETSTDZP j;else force standard zp C3EA:50 03 C3EF 241 BVC JMPDEST s=>always perform transfer C3EC:8D 09 CO 242 XFERAZP STA SETALTZP ;switch in alternate zp C3EF:6C ED 03 243 JMPDEST JMP (S$03ED) ;=>off we go C3F2: 244 * C3F2: 0002 245 DS C3ORG+SF4-%,0 spad to interrupt stuff C3F4: 246 * C3F4: 247 * This is where the interrupt routine returns to. C3F4: 248 * At this point the ROM is not necessarily switched in so... C3F4: 249 * C3F4:8D 81 CO 250 IRQDONE STA _ S$CO081 sread ROM, write RAM C3F7:4C 7A FC 251 JMP IRQDONE2 ;and jump to ROM C3FA: 252 * C3FA: 253 * This is the main entry point for the interrupt C3FA: 254 * handler. This switches in the internal ROM and C3FA: 255 * jumps to the main part of the interrupt handler C3FA: 256 * at $C400. C3FA: 257 * C3FA:2C 15 CO 258 irq bit rdcxrom ;Test internal or external rom C3FD:8D 07 CO 259 sta setintcxrom ;Force in ROM to get to interrupt handler C400: 260 * C400: 261 * Fall into $C400 which is now switched in!! C400: 262 * C400: 20 INCLUDE IRQ C400: 1 * C400: 2 * Here is the main interrupt handler C400: 3% C400: L KRAKKKKKKEKRKKKKEKKEKEKERERERERKKER ARERR C400: C400 5 newirq equ * C400 :D8 6 cld ;make no assumptions!! 310 Appendix I: Monitor ROM Listings C401: 7 sec ;C=1 if internal slot space C402: 8 bmi irqintcx C404: 9 cle C405: 10 irqintcx pha ;Save A on stack instead of $45 C406: 11 pha ;Make room for rts if needed C407: 12 pha C408: 13 txa ;Save X C409: 14 tsx ;Get stack pointer for BRK bit C40A: 15 inx ;Can't do add cause we need C C40B: 16 inx C40C: 17 inx C40D: 18 inx C40E: 19 pha C40F: 20 tya sand Y C410: 21 pha C4ll: 01 22 lda $100,x ;Get status for break test C414: 23 and #$10 sA = $10 if break C416: 24 tay ;Save it for later C417: 25 * Now test & set the state of the machine. Don't alter Y C417: 26 lda rd80col ;Test for 80 store and page 2 C41A: 27 and rdpage2 C41D: 28 and #580 ;Make it 0 or $80 C41F: 29 beq irq2 ;Branch if no change needed C421: 30 lda #$20 ;Set shifted page 2 reset bit C423: 31 sta txtpagel ;Set page l C426: 32 irq2 rol A ;Align bit & shift in slotcx bit C427: 33 bit rdramrd ;Are we reading from aux ram? C42A: 34 bpl irqg3 ;Branch if main ram read C42C: 35 sta rdmainram ;Else, switch main in C42F: 36 ora #$20 sand record the event C431: 37 irq3 bit rdramwrt ;Do the same for ram write C434: 38 bpl irq4 C436: 39 sta wrmainran C439: 40 ora #$10 C43B: 41 irq4 equ k C43B: 42 irq5 bit rdlcram ;Determine if language card active C43E: 43 bpl irq/ C440: 44 ora #S0C ;Sets two bits. Second is redundant C442: 45 bit rdlcbnk2 ;if INC used to restore. C445: 46 bpl irq ;Branch if not page 2 of $DO00 C447: 47 eor #506 ;Set bits for page 2 C449: 48 irq6 sta romin ;Enable ROM STA leaves write enable alone C44c: 49 irq/ bit rdaltzp ;Last..eand very important C44F: 50 bpl irq8 ;If alternate stack C451: 51 tsx ;store current stack pointer at $101 C452: 52 stx $101 C455: 53 ldx $100 ;Retreve main stack pointer from $100 C458: 54 txs C459: 55 sta setstdzp C45C: 56 ora #$80 ;Mark stack switched C45E: 57 irqg8 dey ;Was it a break? C45F: C46D 58 bmi irq9 C461: 59 sta macstat ;Save state of machine C463: 60 pla ;Restore registers Appendix I: Monitor ROM Listings dll tay pla tax pla pla ;A stored where RTS address would go jmp newbreak 3;Go to normal break routine stuff irq9 pha ;save state of machine on stack lda mslot ;Save mslot pha lda #irqdone ;so when interrupt does RTI pha ;[t returns to irqdone php ;Status for user's RTI FC jmp irquser ;OffF to the user The user's RTI returns here BEWARE The rom must be reenabled with a LDA romin This way if the LC was write protected, it still is it was write enabled, it still is it was being write enabled ( 2 ldas), it still will be restore loop uses an INC because some of the switches are read some are write. It must be an INC abs,x since both the 6502 amd 65C02 do two reads before the write. C47C:AD 81 lda romin ;Must be lda! pla ;Recover machine state C480:10 07 bpl irqdnl ;Branch if main ZP C482:8D 09 sta setaltzp C485:AE Ol ldx $101 ;Get alt stack pointer txs C489:A0 06 irgdnl ldy #S06 sY = index into table of switch addresses C48B:10 06 irqdn2 bpl irqdn3 ;Branch if no change C48D:BE Cl ldx irqtble,y ;Get soft switch address C490:FE 00 inc $cO00 ,x ;Hit the switch. NO PAGE CROSS! irqdn3 dey C494:30 03 bmi irqdn4 asl A sGet next bit to check C497:DO F2 bne irqdn2 irqdn4 asl A ;C = 1 if internal slot space asl A pla ;Restore the registers tay tsx ;save the stack pointer lda #$40 ;RTL opcode pha lda #setslotcxrom adc #0 ;Add 1 if internal slot space pha lda #S8D ;STA setslotcxrom pha 312 Appendix I: Monitor ROM Listings C4AC:9A 114 txs ;Restore stack pointer C4AD:8A 115 txa ;Make return address on stack point to code on stack C4AE:69 03 116 adc #3 3;C = O from earlier adc C4B0:AA 117 tax C4B1 :38 118 sec C4B2:E9 07 119 sbc #7 ;Point to where code starts C4B4:9D 00 01 120 sta $100,x C4B7 :E8 121 inx C4B8:A9 Ol 122 lda #$1 C4BA:9D 00 O01 123 sta $100 ,x C4BD:68 124 pla C4BE:AA 125 tax C4BF:68 126 pla C4C0 :60 127 rts 3;Go to code on stack C4C1:83 8B 8B 129 irqtble dfb >1lcbank2,>1lcbankl ,>lcbankl C4c4:05 03 55 130 dfb >wrcardram,>rdcardram,>txtpage2 C4C7: 21 INCLUDE DIAGS Sa NEXT OBJECT FILE NAME IS REFLIST.1 C600 C600 l ORG C30RG+$300 C600 2 These routines test all 64K RAM, as well as the 64K on an Auxiliary C600 3 memory card (when present). With the exception of the INTCXROM switch C600 4 of the IOU, all combinations of the IOU switches are tested and ver- C600: 5 ified. All configurations of the MMU switches are also tested. C600 6 C600 7 In the event of any failure, the diagnostic is halted. A message C600 8 is written to screen memory indicating the source of the failure. C600 9 When RAM fails the message is composed of "RAM ZP" (indicating failure C600 10 detected in the first page of RAM) or "RAM" (meaning the other 63./75K), C600: 11 followed by a binary representation of the failing bits set to se ae C600: 12 For example, "RAM 0110 000 0" indicates that bits 5 and 6 were C600 13 detected as failing. To represent auxiliary memory, a "*" symbol is C600 14 printed preceeding the message. C600: 15 C600: 16 When the MMU or IOU fail, the message is simply "MMU" or "IOU". C600: 17 C600: 18 The test will run continuously for as long as the Open and Closed C600: 19 Apple keys remain depressed (or no keyboard is connected) and no C600: 20 failures are encountered. The message "System OK" will appear in c600: 21 the middle of the screen when a successful cycle has been run and C600: 22 either of the Apple keys are no longer depressed. Another cycle C600: 23 may be initiated by pressing both Apple keys again while this message C600: 24 is on the screen. To exit diagnostics, Control-Reset must be pressed C600: 25 without the Apple keys depressed. c600: 26 FKH HEHEHE HSH HH He Fe HF HH eee eH C600 C051 27 TEXT equ $c051 C600: 00009 28 IOUIDX equ $09 C600: 0001 29 MMU IDX equ $01 C600: O5B8 30 SCREEN equ S5B8 c600: C0300 31 IOSPACE equ $c000 C600: 32 * C600 C&00 33 DIAGS equ *k Appendix I: Monitor ROM Listings 313 C600 78D 50 CO Sta $C050 C603: * Test Zero-Page, then all of memory. Report errors when encountered. C603: * Accumulator can be anything on entry. All registers used, but no stanot 128K C6B/7: OC ASL $c00 ;shift test byte C6BA: ASL A C6BB: 0c CMP $c00 ;check memory Appendix I: Monitor ROM Listings 315 COBE: C736 SWCHTST1 BNE SWCHTST s=>not 128K C6C0: CMP $800 ;look for shadowing C6C3: C736 BEQ SWCHTST ;=>not 128K C6C5: txa C6C6: STA SETALTZP ;swap in alt zero page C6C9: jmp TSTZPG ; and test it! C6CC: MEMERROR sec sindicate main ram failure C6CD: BADBITS tax ;save bit pattern in x for now C6CE: lda RDRAMRD ;determine if primary or auxillary RAM C6D1: clv swith V-FLG C6D2: bpl bbitsl ;branch if primary bank C6D4: bit setv C6D7: bbitsl lda #5 AO ;try to clear video screen C6D9: ldy #6 CODB: clrsts sta IOSPACE~2,y CODE: sta LOSPACE+6,y C6EL: dey C6E2: dey C6E3: bne clrsts C6E5: sta TEXT COE8: sta TXTPAGE1 C6EB: clrs sta $400,y C6EE: sta $500,y C6F1: sta $600 ,y C6OF4: sta $700,y C6F/7: iny COF8: bne clrs C6FA: txa stest for switch test failure COFB: beq BADSWTCH ;branch if it was a switch C6FD: ldy #3 C6FF: bcs badmain sbranch if ZP ok C701: ldy #5 C7032 badmain lda #SAA ;mark aux report with an asterisks C7055 bvc badprim C707: sta screen-8 C70A: badprim lda rmess,y C70D: sta screen—/,y C710: dey Gfils bpl badprim smessage is either "RAM" or "RAM ZP" C713: ldy #$10 ;print bits C715% bbits2 txa C716: lsr a Crl7: tax C718: lda #$58 sbits are printed as ascii O or 1 C71A: rol a C71B: 05 sta screen-2,y C/71E% dey C71F: dey C720: C715 bne bbits2 Ci2z2: C722 hangx beq hangx shang forever and ever C724; BADSWICH ldy #2 C726: C7 bswtchl lda smess,y C729: C72E bec bswtch2 ;branch if MMU in error C72B: C7 lda smess+3,y ;else indicate I0U error 316 Appendix I: Monitor ROM Listings C72E: 05 bswtch2 sta screen,y C731: dey C732: C726 bpl bswtchl sprint "MMU" or "IOU" C734: C734 hangy bmi hangy ;branch forever C736: SWCHTST ldy #MMULDX C738: swtstl lda #S7F C73A: swtst2 ror a sset switches of the LOU/MMU to match Accumulator C73B: C7 ldx SWTBLO,y C7 3Ei C74¥F beq swtst4 sbranch if done setting switches C740: C745 bec swtst3 ;branch if setting switch to O-state C742: C7 ldx SWTBLI,y ;else get index to set switch to l C745: BF swtst3 sta IOSPACE-1,x ;set switch C748: iny C749: C73A bne swtst2 sbranch always taken... C74B: & C74B: co click ldx $C030 C74E: rol a C74F: swtst4 dey C750: C7 ldx RSWTBL,y snow verify the settings just made C753% C763 beq swtst6 ;branch if done this pass C755: C74B bmi click ;branch if this switch no to be verified. C757: rol a C758: C761 bec swtst5 C75A: CO asl IOSPACE,x C75D: C776 bee swerr C75F: C74F bes swtst4 ;branch always C761: co swtst5 asl IOSPACE,x C764: C7746 bes swerr C766: C74F bee swtst4 ;branch always C768: * C768: swtst6 rol ;restore original value C769: iny > and IOU/MMU index C76A: sec C7 6B: sbc #1 ;try next pattern C76D: C73A bcs swtst2 C76F: dey ;was MMU just tested? C770: C77D bne BIGLOOP ;branch if IOU was just tested C772: ldy ##LOULDX ;else, go test IOU. C774; C738 bne swtstl ;branch always taken... C776: C776: swerr ldx #0 ;indicate switch error C778: cpy # LOULDX+1 ;set carry if IOU was cause C77A: jmp bbitsl C77D: BIGLOOP lsr $80 C77F: C736 bne SWCHTST C781: blp2 lda #SA0 C783: ldy #0 C785: blp3 sta $400,y ;clear screen for success message C788: sta $500,y C78B: sta $600,y C78E: sta $700,y C791: iny Appendix I: Monitor ROM Listings 317 C792:D0 Fl C785 246 bne blp3 C794:AD 61 CO 247 blp4 LDA $C061 ;test for both Open and Closed Apple C797:2D 62 CO 248 AND $C062 3; pressed C79A:0A 249 asl a s;put result in carry C79B:E6 FF 250 INC SFF C79D:A5 FF 251 LDA SFF C79F:90 03 C7A4& 252 bee dquit C7A1:4C 00 C6 253 jmp DIAGS C7A4: 254 * C7A4:AD 51 CO 255 dquit lda TEXT ;put success message on the screen C7A7:A0 08 256 ldy #8 C7A9:B9 F6 C7 257 suc2 lda_ success,y C7AC:99 B8& 05 258 sta SCREEN,y C7AF :88 259 dey C7B0:10 F7 C7A9 260 bpl suc2 C7B2:30 EO C794 261 bmi blp4 ;loop forever C7B4: 262 * C7BA4: C7B4 263 setv equ * C7B4:53 43 2B 29 264 ntbl dfb 83,67,43,41,7 C7B9:00 89 31 03 265 swtbl0 dfb $00,$89,$31,$03,$05,$09,$0b,$01,$00,$83,$51,$53,$55,$57,S0F, SOD c7C9:00 81 31 04 266 swtbll dfb $00,$81,$31,$04,$06,S0A,S$0C,$02,$00,$84,$52 ,$54,$56,$58,$10, SOE C7D9:00 11 FF 13 267 rswtbl dfb $00,$11,$FF,$13,$14,$16,$17,$18,$00,$12,$1A,$1B,$1C,$1D,$1E, $1F,$00 C7EA: 268 MSB ON C7EA:D2 Cl CD AO 269 rmess asc "RAM zp" C7FO:CD CD D5 C9 270 smess = asc "MMUIOU" C7F6:D3 F9 F3 F4 272 success asc "System OK" C7FF: C7FF 273 zzzend equ * C7FF: 22 INCLUDE C8SPACE C7FF: 0001 1 DS C80ORG-*,0 ;pad to C800 C800: 2 %* c800: 3 * This entry point is only used by Pascal 1.0 c800: 4 % C800:4C BO C9 5 JMP PINIT1.0 ;PASCAL 1-0 INIT C803: 6 * C803: 7 * BASIC initialization: C803: 8 * C803: 9 * This is called by the $C3 space only after a PR#3 or C803: 10 * the equivalent (a JSR $C300). C803: ll * C803: 12 * It causes a copy of the $F8 ROM to be placed in the C803: 13 * language card if the language card is switched in and C803: 14 * the ID byte doesn't match. It sets up all the C803: 15 * screenhole variables to support its operation. If the C803: 16 * 80 column card is detected, it sets things up for 80 column C803: 17 * operation, else 40 column operation. Then it clears the C803: 18 * screen and prints the character that was in the accumulator C803: 19 * upon entry. C803: 20 * C803: C803 21 BASICINIT EQU * C803:20 F4 CE 22 JSR COPYROM ;If LC in, copy F8 to it C806:20 2A C8 23 JSR C3HOOKS sout=$C307, in=$C305 C809:20 2E CD 24 JSR DO40 sset full 40-col window 318 Appendix I: Monitor ROM Listings :A9 01 LDA #M.MOUSE ;init with mouse text off :8D FB 04 STA MODE ;Set BASIC video mode * * IS THERE A CARD? * JSR TESTCARD ;SEE IF CARD PLUGGED IN C8LE BNE CLEARIT ;=>IT'S 40 ASL WNDWDTH ;SET 80-COL WINDOW STA SET80COL ;ENABLE 80 STORE STA SET80VID ; AND 80 VIDEO * * HOME & CLEAR: x CLEARIT EQU * STA SETALTCHAR ;SET NORM/INV LCASE JSR X.FF ;CLEAR IT LDY OURCH ;set up cursor for store JMP BPRINT ;always print a character x C3HOOKS LDA #>BASICOUT ;set output hook first STA CSWL LDA #BASICIN ;set input hook STA KSWL LDA #NOPE co STA KBDSTRB ;CLEAR STROBE RTS x KAKKKKKK RARER IRE RE RIKER KK BREAKER IA *% * PASCAL 1.0 INPUT HOOK: k 0003 DS C8ORG+S4D-*,0 ;pad to 1.0 hooks 0000 IFNE *-C80RG-$4D ;ERR IF WRONG ADDR FAIL 2, 'C84D HOOK ALIGNMENT! FIN 24C 50 C3 JMP JPREAD ;=>GO TO STANDARD READ KKEKKEKKKKKKKR AKER RERE KKK EEK REREEREKERA x * CSETUP compensates for everything that the user * can do to change the cursor status: poke CV, CH, * OURCH, WNDWDTH. It updates the video firmware's Appendix I: Monitor ROM Listings 319 C850: * versions of these values for its own use. C850: * COPY USER'S CURSOR IF IT DIFFERS FROM C850: * WHAT WE LAST PUT THERE: C850: k C850: CSETUP LDA CV ;set up OURCV C852: 05 STA OURCV C855: LDY CH ;GET IT C857: 04 CPY OLDCH 31S IT THE SAME? C85A: C85F BEQ CS2 3=>YES, USE OUR OWN C85C: 05 STY OURCH ;update our cursor C85F: CS2 LDA WNDWDTH scursor horizontal must not C861: CLC ;be greater than window width C862: 05 SBC OURCH 3if it is, then put cursor C865: C86C BCS CS3 sat left edge of window C867: LDY #0 C869: 05 STY OURCH C86C: 05 Gs3 LDY OURCH sexit with Y = CH C86F: RTS C870: k C870: * BIN and BOUT are used when characters are C870: * input and output by the $F8 ROM while 80VID C870: * is on. They cannot use the $C3 entry points C870: * because that switches in the $C8 space, causing C870: * possible conflict with other $C8 users. C870: * These routines are only called by the $C1LOO-SC2FF space. C870: * C870: * These entry points will only work if the card was C870: * first initialized using a PR#3. 80 columns will not C870: * work simply by turning on the 80VID flag. C870: # C870: 35 BOUT LDY SAVY1 sload Y stuffed by SF8 ROM C872: CLC ;signal an output C873: FE C873 BCS * sskip SEC C874: C874 ORG *-1 C874: BIN SEC ;signal an input C875: 7B 06 STA CHAR ssave the char C878: TYA ;save Y C879: PHA C87A: TXA ;save X C87B: PHA C87C: C8/C C8BASIC EQU #* *BASIC IN/OUT C87C: 5E C8DC BCS BINPUT ;=>input a character 0000: 0000 TEST EQU O -REAL VERS LON C87E: LST ON,A,V C87E: INCLUDE BPRINT C87E: * C87E: *& This is the place where characters printed using the C87E: * CSW hook are actually printed (or executed if they are C87E: * control characters). C87E: * C87E: BPRINT JSR CSETUP ;setup user cursor C881: LDA CHAR ;GET CHARACTER C884: CMP #S8D ‘1S: IT G/R? C886: BNE NOWALT s=>don't wait, OURCH ok 320 Appendix I: Monitor ROM Listings C888: KBD ;1S KEY PRESSED? C88B: NOWAIT ; NO C88D: #$93 31S IT CTL-S? C88F: NOWAIT 3;NO, IGNORE IT C891: KBDSTRB ;CLEAR STROBE C894: KBDWAIT KBD ;WAIT FOR NEXT KEYPRESS C897: KBDWAIT C899: #$83 ;1F CTL-C, LEAVE IT C89B: NOWAIT ; IN THE KBD BUFFER C89D: KBDSTRB ;CLEAR OTHER CHARACTER C8A0: NOWAIT #S7F ;drop possible hi bit C8A2: #$20 ;IS IT CONTROL CHAR? C8A4: BPNCTL 3=>NOPE C8A6: CTLCHARO sexecute CTL if M.CTL ok C8A9: CTLON ;=>enable ctl chrs C8AC: k C8AC: * NOT A CTL CHAR. PRINT IT. C8AC: * C8AC: BPNCTL EQU * C8AC: AD 7B LDA CHAR 3;get char (all 8 bits) C8AF :20 38 JSR STORCHAR sand display it C8B2: C8B2: * BUMP THE CURSOR HORIZONTAL: C8B2: C8B2: INY ;bump it C8B3: STY OURCH ;are we past the C8B6: CPY WNDWDTH ; end of the line? C8B8: C8BD BCC CTLON 3=>NO, NO PROBLEM C8BA: JSR XeCR sYES, DO C/R C8BD: C8BD: M.CTL is set by RDCHAR and cleared here, after each C8BD: character is displayed. C8BD: +* & C8BD: CTLON LDA MODE ;enable printing of control chars C8CO0: AND #255-M.CTL C8C2: STA MODE C8C5: BIORET LDA OURCH ;get newest cursor position c8cs: BIT RD80VID ;IN 80-MODE? C8CB: C8CF BPL SETALL 3=>no, set other cursors C8CD: LDA #0 ;pin CH to O for 80 columns C8CF: SETALL STA CH C8D1: STA OLDCH ;REMEMBER THE SETTING C8D4: GETREGS PLA ; RESTORE C8D5: TAX C8D6: PLA 3X AND Y C8D/7: TAY C8D8: 7B 06 LDA CHAR C8DB: RTS ;RETURN TO BASIC C8DC: INCLUDE BINPUT C8DC: C8DC: BASIC input entry point called by entry point in the C8DC: $C3 space. This is the way things normally happen. C8DC: ee + C8DC: A4 24 BINPUT LDY CH Appendix I: Monitor ROM Listings d21 C8DE:AD 7B 06 6 LDA CHAR C8E1:91 28 7 STA (BASL),Y C8E3:20 50 C8 8 JSR CSETUP sget newest cursor C8E6:20 26 CE 9 Be INPUT JSR INVERT sinvert that char C8E9:20 3B C8 10 JSR GETKEY ;GET A KEY C8EC:8D 7B 06 11 STA CHAR ;SAVE IT C8EF:20 26 CE 12 JSR INVERT ;REMOVE CURSOR C8F2:A8 13 TAY ;preserve acc. C8F3: 14 * C8F3: 15 * On pure input, an uninterpreted character code should C8F3: 16 * be returned. If M.CTL is set, however, escape functions C8F3: 17 * are enabled, and CTL-U causes the character under the C8F3: 18 * cursor to be picked up from the screen. C8F3: 19 * M.CTL is set whenever a character is requested using C8F3: 20 * RDCHAR in the S$F8 ROM. C8F3: 21 * C8F3:AD FB 04 22 LDA MODE 3is escape mode enabled? C8F6:29 08 23 AND #M.CTL C8F8:FO CB C8C5 24 BEQ BIORET 3=>no,return C8FA:CO 8D 25 CPY #$8D swas it a CR C8FC:D0 08 C906 26 BNE NOTACR ;=>nope, not a CR C8FE:AD FB 04 27 LDA MODE C901:29 F7 28 AND #255-M.CTL ;else end of line... C903:8D FB 04 29 STA MODE ; disable escape C906: C906 30 NOTACR EQU * C906:CO 9B 31 cPy #S9B sESCAPE KEY? C908:F0 11 C91B a2 BEQ ESCAPING ;=>YES IT IS C9OA: 33 * C90A: 34 * Not an escape sequence. Check for control-u. C9IOA: 35 * C90A:CO 95 36 CPy #$95 sis it control-U? C90C:DO B7 C8C5 37 BNE BIORET sno, return to caller C9OE:AC 7B 05 38 LDY OURCH sget horizontal position C911:20 44 CE 39 JSR PICK sand pick up the char C914:09 80 40 ORA #S80 salways pick as normal C916:8D 7B 06 41 STA CHAR ;save keystroke C919:DO AA cC8C5 42 BNE BIORET ;=>(always) return to caller C9O1B: 43 * C91B: 44 * Start an escape sequence. If the next character C9O1B: 45 * pressed is one of the following, it is executed. C9OLB: 46 * Otherwise it is ignored. C9OLB: 47 % C9O1B: 48 * @ - home & clear C91B: 49 * E - clear to end of line C91B: 50 * F - clear to end of screen C9O1B: 51 * I - move cursor up C91B: 52 * J - move cursor left C9O1B: 53 * K - move cursor right C91B: 54 * M - move cursor down CO1B: 57 * 4 - enter 40 column mode C91B: 58 * 8 - enter 80 column mode C9O1B: 59 * CTL-D- disable the printing of control characters COLB: 60 * CTL-E- enable the printing of control characters C9O1B: 61 * CTL-Q- quit (PR#0/IN#0) 322 Appendix I: Monitor ROM Listings C91B: 62 * The four arrow keys (as IJKM) COLB: 63 * CO1B: 64 MSB OFF C9O1B: C91B 65 ESCAPING EQU * C91B:20 Bl CE 66 JSR ESCON ;ESCAPE CURSOR ON C91E:20 3B C8 67 JSR GETKEY ;GET ESCAPE FUNCTION C921:20 C4 CE 68 JSR ESCOFF ;REPLACE ORIGINAL CHARACTER C924:20 14 CE 69 JSR UPSHFT supshift the char C927:29 7F 70 AND #S7F sDROP HI BIT C929:A0 10 71 LDY #ESCNUM-1 ;COUNT/ INDEX C92B:D9 7C C9 72 ESC2 CMP ESCTAB,Y ;I1S IT A VALID ESCAPE? C92E:FO 05 C935 73 BEQ ESC3 3S=>YES C930 :88 74 DEY C931:10 F8 C92B 75 BPL ESC2 sTRY 'EM ALL... C933:30 OF C944 76 BMI ESCSPEC s=>MAYBE IT'S A SPECIAL ONE C935: 77 * C935: C935 = 78 ~ESC3 EQU * C935:B9 6B C9 79 LDA ESCCHAR,Y ;GET CHAR TO "PRINT" C938:29 7F 80 AND #S7F ;DROP HI BIT (FLAG) C93A:20 D6 CA 81 JSR CTLCHAR ;EXECUTE IT C93D:B9 6B C9 82 LDA ESCCHAR,Y ;GET FLAG C940:30 D9 C9I1B 83 BMI ESCAPING ;=>STAY IN ESCAPE MODE C942:10 A2 C8E6 84 BPL B.INPUT s=>QUIT ESCAPE MODE C944; 85 * C944; C944 86 ESCSPEC EQU * C944:A8 87 TAY ;put char here C945:AD FB 04 88 LDA MODE 3sO we can put this here C948:C0 11 89 cPy #$11 swas it Quit? C94A:D0 OB C957 90 BNE ESCSP1 $=>no C94C:20 4D CD 91 JSR X.NAK ;do the quitting stuff C9O4F:A9 98 92 LDA #$98 smake it look like C951:8D 7B 06 93 STA CHAR ;CTL-X was pressed C954:4C C5 C8 94 JMP BIORET ;=>quit the card forever C957: 95 * C957:C0 05 96 ESCSP1 cCPY #S$05 swas it CTL-E for enable C959:D0 08 C963 97 BNE ESCSP4 3=>no C95B:29 DF 98 AND #255-M.CTL2 ;yes, enable ctl chars C95D:8D FB 04 99 ESCSP2 STA MODE ;save new mode C960:4C E6 C8 100 ESCSP3 JMP B.INPUT 3=> exit escape mode C963: 101 * C963:CO 04 102 ESCSP4 cCPY #$04 swas it CTL-D for disable C965:DO F9 c960—s:1103 BNE ESCSP3 3=>no, exit escape mode C967:09 20 104 ORA #M.CTL2 sdisable ctl chars C969:D0 F2 C95D 105 BNE ESCSP2 3=> exit escape mode C96B: 106 * C96B: 107 * This table contains the control characters which, C9O6B: 108 * when executed, carry out the escape functions. If C96B: 109 * the high bit of the character is set, it means that C96B: 110 * escape mode should not be exited after execution of C96B: 111 * the character. C9I6B: 112 * C96B: C96B 113 ESCCHAR EQU * C96B:0C 114 DFB SOC 3@: FORMFEED C96C:1C 115 DFB SIC sA: FS Appendix I: Monitor ROM Listings C96D:08 116 DFB $08 3B: BS C96E:0A 117 DFB SOA “Cy. LF C96F:1F 118 DFB SIF 3D: US C970:1D 119 DFB $1D sE: GS C971:0B 120 DFB SOB 3F: VT C972:9F 121 DFB $1F+$80 sI: US (STAY ESC) C973:88 122 DFB $08+$80 ;J: BS (STAY ESC) C974:9C 123 DFB $1C+$80 ;K: FS (STAY ESC) C975:8A 124 DFB S$0OA+S$80 sM: LF (STAY ESC) C976:11 125 DFB $11 34 :DCl C977:12 126 DFB $12 358 :DC2 C978:88 127 DFB $08+$80 3<-:BS (STAY ESC) C979:8A 128 DFB S$0OA+S$80 ;DN: LF (STAY ESC) C97A:9F 129 DFB S$1F+$80 ;UP:US (STAY ESC) C97B:9C 130 DFB $1C+$80 s->:FS (STAY ESC) C97C: 131 * C97C: 132 MSB OFF shigh bit already masked C97C: c97C 133 ESCTAB EQU * C97C:40 134 ASC ‘@! C97D:41 135 ASC ‘A! ;HANDLE OLD ESCAPES C97E:42 136 ASC 'B! C97F:43 137 ASC ‘C' C980 :44 138 Asc 'D! C981:45 139 ASC 'E' C982:46 140 ASC 'F! C983:49 14] Asc 'I' C984:4A 142 ASC ‘'J' C985:4B 143 ASC 'K' C986:4D 144 ASC '‘M' C987 :34 145 ASC ‘4! C988:38 146 Asc ‘8! C989:08 147 DFB $08 ;LEFT ARROW C9BA:0A 148 DFB SOA ;DOWN ARROW C98B:0B 149 DFB $OB -UP ARROW C98C:15 150 DFB $15 ;sRITE ARROW C98D: 0011 151 ESCNUM EQU *-ESCTAB C98D: 152 MSB ON C98D: 153 * C98D: 154 * Tack on diag 128K test here C98D: 155 * C98D:2C 13 CO 156 STAUX BIT RDRAMRD ;aux done yet? C990:30 11 C9A3 157 BMI XSTAUX s=>yes, exit C992:A9 EE 158 LDA #SEE sget test pattern C994:8D 05 CO 159 STA WRCARDRAM ;write AUX RAM C997:8D 03 CO 160 STA RDCARDRAM ;read AUX RAM C99A:8D 00 OC 161 STA $C00 ;test this byte C99D:8D 00 08 162 STA $800 sand this is IK off C9A0:CD 00 OC 163 CMP $COO shas $COO been updated? C9A3:60 164 XSTAUX RTS ;check in main diags. C9A4: 165 * C9A4: 166 * ESCOUT used by ESCFIX in $Cl page C9A4: 167 * C9IA4: 168 MSB ON C9A4:CA CB CD C9 169 ESCOUT ASC ‘'‘JKMI' ;The arrows 324 Appendix I: Monitor ROM Listings 170 MSB OFF 26 INCLUDE PASCAL KHKKKKKKKKKRKKKREKERKEREKEREKKEEERIKERERRERK * PASCAL 1.0 OUTPUT HOOK: KRKARKEKRAKKEKERERERERRERERERRRERERRERKEKK 0002 DS C80RG+$1 AA-* ,0 0000 IFNE *-C80RG-S1AA FAIL 2,'C9AA HOOK ALIGNMENT’ FIN 7B 06 LDA CHAR ;GET OUTPUT CHARACTER 56 C3 omn~”nW” &WwNhM e JMP JPWRITE 3=>USE STANDARD WRITE 10 KEKKKEKRERKEKKKEERERREKRKEKKEKKERERKEREREKAKKKKE ll *& 12 REEREKREKRRKEREEREREREREEKKERERERRRKERKKRKRKKE 13 * PASCAL INITIALIZATION: 14 * Disable printing of mouse text 15 KERKKRKKKRKEERKEEKRRREKREKREKREREKKIRKKEKAKKK C9IBO 16 PINITL.O EQU * :A9 83 17 LDA #M.PASCAL+M. PAS] .O+M. MOUSE :DO 02 C9IB6 18 BNE PINIT2 ;=Dalways CIB4 19 PINIT EQU k :A9 81 20 LDA #M.PASCAL+M.MOUSE ;SAY WE'RE 21 * C9IB6 ZZ PINIT2 EQU & 248 23 PHA ;save version ID 24 * 25 * SEE IF THE CARD'S PLUGGED IN: 26 * :20 90 CA 27 JSR TESTCARD ;I1S IT THERE? : FO 04 C9ICO 28 BEQ PIGOOD ;=>YES 268 29 PLA ;discard ID byte :A2 09 30 LDX #9 ; LORESULT='NO DEVICE' :60 31 RTS 32 & C9CO 33 PIGOOD EQU :68 34 PLA ;get version ID :8D FB 04 35 STA MODE ; and save it :8D 01 co 36 STA SET80COL ;ENABLE 80 STORE :8D OD co 37 STA SET80VID ; AND 80 VIDEO :8D OF co 38 STA SETALTCHAR ;NORM+INV LCASE 220 D4 CE 39 JSR PSETUP ;set window and cursor 220 90 CC 40 JSR X.FF ;HOME & CLEAR IT 24C 1F CA 4] JMP DOBASL ;fix OLDBASL/H, display cursor, exit 42 KHEKKKKKKKREKKKKKREKKEKKREKEREEREKKICRRARERKEKK 43 * PASCAL INPUT: 44 * 45 * Character always returned with high bit clear. 46 * 47 KREEKKEKKREKEREKREREKEKREREREREKKK KKK KKREKK 48 PREAD EQU * ‘20 D4 49 JSR PSETUP ;OETUP ZP STUFF 220 3B 50 JSR GETKEY ;GET A KEYSTROKE 229 7F 51 AND #S7F ;DROP HI BIT :8D 7B 52 STA CHAR ;SAVE THE CHAR Appendix I: Monitor ROM Listings 320 C9E1 :A2 LDX #0 ; LORESULT='GOOD' C9E3: AD 04 LDA MODE ;ARE WE IN 1.0-MODE? C9E6:29 AND #M.PAS1.0 C9E8 : FO C9EC BEQ PREADRET2 3 =>NOPE C9EA:A2 LDX #Doing X or Y? COFD:8A TXA snow check for control char C9OFE:2C CA BIT PRTS sis it control? CAO1:FO CA53 BEQ PCTL ;=>yes, do control CAO3 : AC 05 LDY OURCH ;get horizontal position CA06:24 BIT INVFLG scheck for inverse CA08 :10 CAOC BPL PWRI sinverse, go store it CAOA:09 ORA #$80 CAO0C:20 CE PWRI JSR STORIT snow store it (erasing cursor) CAOF:C8 INY -INC CH CA10:8C 05 STY OURCH CA13:C4 CPY WNDWDTH CAL5:90 CALIF BCC DOBASL CA17:A9 LDA #0 ;do carriage return CA19:8D 05 STA OURCH CA1C:20 CB JSR X.LF sand linefeed CAILF:A5 DOBASL LDA BASL ;save BASL for pascal CA21:8D 07 STA OLDBASL CA24:A5 LDA BASH CA26:8D 07 STA OLDBASH CA29:20 CE PWRITERET JSR PASINV ;display new cursor CA2C:A2 PRET LDX #$0 ;return with no error CA2E:60 PRTS RTS CA2F: * CA2F: * HANDLE GOTOXY STUFF: CA2F: k CA2F:20 CE GETX PAS INV sturn off cursor CA32:8A sget character CA33:38 CA34:E9 20 #32 sMAKE BINARY CA36:2C 06 XCOORD sdoing X? CA39:30 30 CA6B PSETX 3=>yes, set it CA3B: 326 Appendix I: Monitor ROM Listings CA3B: 107 * Set Y and do the GOTOXY CA3B: 108 * CA3B:8D FB 05 109 GETY STA OURCV CA3E:85 25 110 STA CV CA40:20 BA CA lll JSR BASCALC scalc base addr CA43:AD FB 06 112 LDA XCOORD CA46:8D 7B O05 113 STA OURCH sset cursor horizontal CA49:A9 F7 114 LDA #255-M.GOXY ;turn off gotoxy CA4B:2D FB 04 115 AND MODE CA4E:8D FB 04 116 STA MODE CA51:DO CC CAIF 117 BNE DOBASL s=>DONE (ALWAYS TAKEN) CA53: 118 * CA53:20 1F CE 119 PCTL JSR PASINV sturn off cursor CA56:8A 120 TXA ;get char CA57:C9 1E 121 CMP #S1E sis it gotoXY? CA59:FO 06 CA61 122 BEQ STARTXY ;=>yes, start it up CA5B:20 D6 CA 123 JSR CTLCHAR sEXECUTE IT IF POSSIBLE CASE:4C IF CA 124 JMP DOBASL ;=>update BASL/H, cursor, exit CA61: 125 * CA61: 126 * START THE GOTOXY SEQUENCE: CA61: 127 * CA61: CA61 128 STARTXY EQU * CA61:A9 08 129 LDA #M.GOXY CA63:0D FB 04 130 ORA MODE ;turn on gotoxy CA66:8D FB 04 131 STA MODE CA69:A9 FF 132 LDA #SFF sset XCOORD to -l CA6B:8D FB 06 133 PSETX STA XCOORD ;set X CA6E:4C 29 CA 134 JMP PWRITERET ;=>display cursor and exit CA71: 27 INCLUDE SUBS1 CA71: CA7 1 1 DOMN EQU * CA71:AA 2 TAX ;SAVE IT CA72:A5 2A 3 LDA BAS2L ;GET OPCODE AGAIN CA74:A0 03 4 LDY #$03 CA76:E0O 8A a CPX #S8A CA78:FO OB CA8 5 6 BEQ MNNDX3 CA7A:4A 7 MNNDX] LSR A CA7B:90 08 CA8 5 8 BCC MNNDX3 ;FORM INDEX INTO MNEMONIC TABLE CA7D:4A 9 LSR A CA7E:4A 10 MNNDX2 LSR A ; 1) 1XXX1010 => 00101XxXxX CA7F:09 20 ll ORA #$20 ; 2) XXxyyyY0Ol => 00111Xxx CA81:88 12 DEY s 3) XXXYYY1O => 00110XXx CA82:DO FA CA7 E 13 BNE MNNDX2 ; 4) XxxyYl00 => 00100XXx CA84:C8 14 INY ; 5) XXXXX000 => OOOXXXXX CA85:88 15 MNNDX3 DEY CA86:DO F2 CA7 A 16 BNE MNNDX1 CA88 : 60 17 RTS CA89: 18 * CA89: 19 * Switch in slot 3, then test for a ROM card. CA89: 20 * If none found, test for 80 column card, CA89: 21 * else return with BNE. CA89: 22 * CA89: CA8 9 23 TSTROMCRD EQU * CA89:20 B/7 F8 24 JSR TSTROM stest for ROM card CA8C:DO 02 CAI 0 25 BNE TESTCARD 3;=>no ROM, check for 80 column card Appendix I: Monitor ROM Listings CA8E:C8 26 INY smake BNE for return CA8F:60 27 RTS CA90: 28 * CA90: DQ KKKKKKAKKRKRERRRKERERRRKERERERER REREKREKRER CA90: 30 * NAME : TESTCARD CA90: 31 * FUNCTION: SEE IF 80COL CARD PLUGGED IN CA90: 32 * INPUT : NONE CA90: 33 * OUTPUT : 'BEQ' IF CARD AVAILABLE CA90: 34 * : 'BNE' IF NOT CA90: 35 * VOLATILE: AC,Y CA90: 36 RRAKKKKKHKKAKKRKREKERKERERRRERERAERERERKKK CA90: 37 * CA90: CA9I0 38 TESTCARD EOU * CA90:AD 1C CO 39 LDA RDPAGE2 ;REMEMBER CURRENT VIDEO DISPLAY CA93:0A 40 ASL A ; IN THE CARRY CA94:A9 88 41 LDA #588 sUSEFUL CHAR FOR TESTING CA96:2C 18 CO 42 BIT RD80COL ;REMEMBER VIDEO MODE IN '‘'N' CA99:8D 01 CO 43 STA SET80COL ;ENABLE 80COL STORE CA9IC:08 44 PHP ;SAVE 'N* AND 'C' FLAGS CA9D:8D 55 CO 45 STA TXTPAGE2 ;SET PAGE2 CAAO:AC 00 04 46 LDY $0400 ;GET FIRST CHAR CAA3:8D 00 04 47 STA $0400 sSET TO A '*! CAA6:AD 00 04 48 LDA $0400 ;GET IT BACK FROM RAM CAA9:8C 00 04 49 STY $0400 sRESTORE ORIG CHAR CAAC :28 50 PLP ;RESTORE 'N' AND 'C' FLAGS CAAD:B0O 03 CAB2 51 BCS STAY2 sSTAY IN PAGE2 CAAF:8D 54 CO 52 STA TXTPAGE]L ;RESTORE PAGE] CAB2: CAB2 53 STAY2 EQU * CAB2:30 03 CAB/ 54 BMI STAY80 ;=>STAY IN 80COL MODE CAB4:8D 00 CO 55 STA CLR80COL ;TURN OFF 80COL STORE CAB/7: CAB/ 56 STAY80 EQU * CAB/:C9 88 57 CMP #S$88 ;WAS CHAR VALID? CAB9 :60 58 RTS ;RETURN RESULT AS BEQ/BNE CABA: 59 * CABA: 60 * Do the normal monitor ROM BASCALC CABA: 61 * CABA: CABA 62 BASCALC EQU * CABA:48 63 PHA CABB:4A 64 LSR A CABC:29 03 65 AND #$03 CABE:09 04 66 ORA #S04 CACO:85 29 67 STA BASH CAC2 :68 68 PLA CAC3:29 18 69 AND #518 CAC5:90 02 CAC9 70 BCC BSCLC2 CAC7:69 7F 71 ADC #S$7F CAC9:85 28 72 BSCLC2 STA BASL CACB:0A 73 ASL A CACC:0A 74 ASL A CACD:05 28 75 ORA BASL CACF:85 28 76 STA BASL CAD1:60 77 RTS CAD2: 78 * 328 Appendix I: Monitor ROM Listings KRERERRKEREKREEREKRREREKRKEERKRKRERKRERRERERER * NAME : CTLCHARO * FUNCTION: Execute C TL char if M.CTL=0 * INPUT : AC=CHAR * OUTPUT "BCS' if not executed * "BCC' if executed * VOLATILE: NOTHING * CALLS : MANY THINGS KHKKKAKKKKKEKRERERKERREREREKE KK RREKEKKKKKK * <2C 06 CB CTLCHARO BIT SEV1 sset V (use M.CTL) 250 FE CAD5 BVC * ;skip CLC CAD6 ORG |} & KAKKKKKKKKKKKKKKEKEKRERERKRKKKK KKK AKKKKKKKK NAME : CTLCHAR FUNCTION: Always ex ecute CTL char INPUT : AC=CHAR OUTPUT "BCS' if not executed F + FF "BCC' if ctl executed * VOLATILE: NOTHING * CALLS : MANY THINGS KHRKARKKKKKK KKK EK EKEEKRERKEKREEKK KARR KKK KK * :B8 CTLCHAR CLV sclear V (ignore M.CTL) :8D 7B 07 STA TEMP1 ;TEMP SAVE OF CHAR 748 PHA s;SAVE AC 298 TYA “SAVE Y 748 PHA : AC 7B 07 LDY TEMP 1 ;GET CHAR IN QUESTION :CO 05 CPY #$05 ;IS IT NUL..EOT? :90 13 CAF/ BCC CTLCHARX s=DYES, NOT USED :B9 B4 CB LDA CTLADH-5 »Y ;Get high byte of address SFO OE CAF/ BEQ CTLCHARX ;=>ctl not implemented 250 12 CAFD BVC CTLGOO ;=> CLTCHAR: always execute 0000 DO TEST BPL CTLGOO ;=>CR,BEL,LF,BS always done ELSE 330 10 CAFD BMI CTLGOO 3=>CR, BEL,LF,BS always done FIN :8D 7B 07 STA TEMP] ;save high byte of address : AD FB 04 LDA MODE 3if control chars 329 28 AND #M.CTL+M ~CTL2 ;are enabled : FO 03 CAFA BEQ CTLGO ;=>then go do them * CAF/7 CTLCHARX EQU * 238 SEC ;SAY ‘NOT CTL' : BO 09 CB03 BCS CTLRET 3=>DONE * : AD 7B 07 CTLGO LDA TEMP1 sget address back CAFD CTLGOO EQU * Appendix I: Monitor ROM Listings 329 0000 DO TEST AND #S7F ;for test, hi bit clear ELSE :09 80 ORA #$80 shi bit always set 720 O7 CB CTLXFER ;EXECUTE SUBROUTINE ;SAY ‘CTL CHAR EXECUTED' CBO3 CTLRET EQU ; RESTORE i a ; AND AC SEV1 RTS * CBO7 CTLXFER EQU * ;PUSH ONTO STACK FOR :B9 99 CB CTLADL-5,Y ; TRANSFER TRICK ;XFER TO ROUTINE * * Turn cursor on for Pascal only * :AD FB 04 X.CUR.ON LDA MODE ;get mode byte 710 05 CBl7 BPL CURON.X 3=>not pascal, don't do it 729 EF AND #255-M.CURSOR ;clear cursor bit :8D FB 04 ~SAVCUR STA MODE ;save it CURON.X RTS sand exit * * Turn cursor off for Pascal only. * Cursor is not displayed during call. * :AD FB 04 X-CUR.OFF LDA MODE ;get mode byte 2:10 FA CB17 BPL CURON.X s=>not pascal, don't do it ORA #M.CURSOR ;turn on cursor bit :DO F3 CB14 BNE SAVCUR ;save and exit * * EXECUTE BELL: * CB21 XeBELL EQU x LDA #$40 ;RIPPED OFF FROM MONITOR :20 34 CB JSR WAIT LDY #$C0 BELL2 LDA #SOC 720 34 CB JSR WAIT :AD 30 CO LDA SPKR DEY :DO F5 CB28 BNE BELL2 RTS CB34 WAIT EQU ;RIPPED OFF FROM MONITOR ROM SEC WAIT2 PHA :E9 Ol WAIT3 SBC :DO FC CB36 BNE 330 Appendix I: Monitor ROM Listings CB3A: PLA CB3B: 01 SBC #1 CB3D: F6 CB35 BNE WAIT2 CB3F: RTS CB40: * CB40: * EXECUTE BACKSPACE: CB40: * CB40: X-BS EQU * CB40: DEC OURCH ;BACK UP CH CB43: BPL BSDONE ;=>DONE CB45: LDA WNDWDTH ;BACK UP TO PRIOR LINE CB47: STA OURCH ;9ET CH CB4A: DEC OURCH CB4D: JSR X.US ;NOW DO REV LINEFEED CB50: BSDONE EQU *& CB50: RTS CB51: * CB51: * EXECUTE CARRIAGE RETURN: CB51: * CB51: X-eCR EQU * CB51: LDA #0 ;BACK UP CH TO CB53: STA OURCH ; BEGINNING OF LINE CB56: LDA MODE sARE WE IN BASIC? CB59: BMI XeCRRET 3=> Pascal, avoid auto LF CB5B: JSR X.LF ;EXECUTE AUTO LF FOR BASIC CB5E: XeCRRET EQU * CB5E: RTS CB5F: * CBSF: * EXECUTE HOME: CBSF: k CB5F: CBSF Xe EM EQU * CB5F: LDA WNDTOP CB6l: STA CV CB63: LDA #0 CB65: STA OURCH ;sSTUFF CH CB68: JMP VTAB ;set base for OURCV CBO6B: * CBOB: * EXECUTE FORWARD SPACE: CB6B: * CB6B: X.FS EQU * CBOB: INC OURCH ;BUMP CH CB6E: LDA OURCH ;GET THE POSITION CB/71: CMP WNDWDTH ;OFF THE RIGHT SIDE? CB73: BCC Xe FSRET s=>NO, GOOD CB/5: JSR X-CR 3=>YES, WRAP AROUND CB78: * CB/78: Xe FSRET EQU * CB78: RTS CB/9: * CB/9: * EXECUTE REVERSE LINEFEED: CB/79: * CB79: 22 X.US LDA WNDTOP sare we at top? CB/7B: C5 CMP CV CB/N: BO 1E CB9D BCS X.USRET s=>yes, stay there Appendix |: Monitor ROM Listings 33] CB/F: C6 25 DEC CV ;else go up a line CB81 24C FE CD JMP VTAB sexit thru VTAB (update OURCV) CB84: * CB84: * EXECUTE "NORMAL VIDEO" CB84: * CB84: X.SO EQU * CB84: LDA MODE ;SET MODE BIT CB87: BPL X.SOl sdon't set mode for BASIC CB89: AND #255-M.VMODE ;SET '‘NORMAL' CB8B: X.SOl LDY #255 CB8D: BNE STUFFINV ;( ALWAYS) CB8F: * CB8F: * EXECUTE “INVERSE VIDEO" CB8F: k CB8F: X.SI * CB8F: MODE ;SET MODE BIT CB92: X.SI1 sdon't set mode for BASIC CB94: #M.VMODE ;SET 'INVERSE' CB96: X.SI1 #127 CB98: STUFFINV STA MODE ;SET MODE CB9OB: INVFLG ;STUFF FLAG TOO CB9D: Xe USRET CB9E: * CB9E: CB9E CTLADL * CB9E: #>X.CUR.ON-1 ;ENQ CB9F: #>X.CUR.OFF-1 ;ACK CBAO: #>X.BELL-1 ;BEL CBAIL: #>X.BS-1 ;BS CBA2: 0 ;HT CBA3: #>X.LF-1 ;LF CBA4: #>X.VT-L ss VT CBA5: #>X.FF-1 ;FF CBA6: #>X.CR-1 ;CR CBA7: #>X.SO-1 ;SO CBA8: #>X.SI-1 ;SI CBA9: 0 ; DLE CBAA: #>X.DC1-1 ;DCl CBAB: #>X.DC2-1 ;DC2 CBAC: 0 3DC3 CBAD: 0 ;DC4 CBAE: #>X.NAK-1 ;NAK CBAF: #>SCROLLDN-1 ;SYN CBBO: #>SCROLLUP-1 ;ETB CBBl: ##>MOUSEOFF-1 CBB2: #>X.EM-1 ;EM CBB3: #>X.SUB-1 ;SUB CBB4: ##>MOUSEON-1 CBB5: #>X.FS-1 =; FS CBB6: #>X.GS-1 sGS CBB/7: 0 RS CBB8: #>X.US-1 ;US CBB9: CBB9: CBB9 * CBB9: #go do scroll CBD8: * CBD8: * EXECUTE LI NEFEED: CBD8: & CBD8: CBD& X.LF EQU CBD8: INC CBDA: LDA ;SEE IF OFF BOTTOM CBDC: 05 STA CBDF: CMP ;OFF THE END? CBE]: CBEG BCS 3=>yes, scroll screen CBE3: CE JMP sexit thru VTABZ CBE6: & CBE6: CBE®G X.LF2 EQU CBE6: 05 DEC ;back up to bottom CBE9: DEC sand fall into scroll CBEB: CBEB: 01 SCROLLUP LDY ;direction = up CBED: SCROLLIT TXA ;save X CBEE: PHA CBEF: 7B 07 STY TEMP1 ssave direction Appendix I: Monitor ROM Listings 333 CBF2:A5 21 28 LDA WNDWDTH sget width of screen window CBF4:48 29 PHA s;save original width CBF5:2C IF CO 30 BIT RD80VID sin 40 or 80 columns? CBF8:10 1C CCl6 31 BPL GETST1 3=>40, determine starting line CBFA:8) 01 CO 32 STA SET80COL j;make sure this is enabled CBFD:4A 33 LSR A sdivide by 2 for 80 column index CBFE:AA 34 TAX sand save CBFF:A5 20 35 LDA WNDLFT stest oddity of right edge CCO1:4A 36 LSR A sby rotating low bit into carry CCO2: B8 37 CLV ;V=0 if left edge even CCO3:90 03 ccos 38 BCC CHKRT s=>check right edge CCO5:2C 06 CB 39 BIT SEV1 ;V=l if left edge odd CC08:2A 40 CHKRT ROL A srestore WNDLFT CC09:45 21 41 EOR WNDWDTH s;get oddity of right edge CCOB:4A 42 LSR A ;C=1 if right edge even CCO0C:70 03 CCll 43 BVS GETST sif odd left, don't DEY CCOE:BO O01 CCl1 44 BCS GETST 3if even right, don't DEY CC10:CA 45 DEX 3if right edge odd, need one less CC11:86 21 46 GETST STX WNDWDTH ;save window width CC13:AD 1F CO 47 LDA RD80VID sN=l if 80 columns CC16:08 48 GETST1 PHP ssave N,Z,V CC17:A6 22 49 LDX WNDTOP sassume scroll from top CC19:98 50 TYA sup or down? CC1A:D0 03 CC1F 51 BNE SETDBAS ;=>up CC1C:A6 23 52 LDX WNDBTM sdown, start scrolling at bottom CC1E:CA 53 DEX ;really need one less CCIF: 54 * CC1F:8A 55 SETDBAS TXA ;sget current line CC20:20 03 CE 56 JSR VTABZ ;calculate base with window width CC23: 57 * CC23:A5 28 58 SCRLIN LDA BASL scurrent line is destination CC25:85 2A 59 STA BAS2L CC27:A5 29 60 LDA BASH CC29:85 2B 61 STA BAS2H CC2B: 62 * CC2B:AD 7B 07 63 LDA TEMP1 stest direction CC2E:FO 32 CC62 64 BEQ SCRLDN ;=>do the downer CC30:E8 65 INX sdo next line CC31:E4 23 66 CPX WNDBITM sdone yet? CC33:BO 32 CC67 67 BCS SCRLL3 3;=>yup, all done CC35:8A 68 SETSRC TXA ;set new line CC36:20 03 CE 69 JSR VTABZ s;get base for new current line CC39:A4 21 70 LDY WNDWDTH ;get width for scroll CC3B:28 71 PLP sget status for scroll CC3C:08 72 PHP sN=l if 80 columns CC3D:10 1E CCSD’ 73 BPL SKPRT s=>only do 40 columns CC3F:AD 55 CO 74 LDA TXTPAGE2 ;scroll aux page first (even bytes) CC42:98 75 TYA stest Y CC43:FO 07 CcCc4c' 76 BEQ SCRLFT sif Y=0, only scroll one byte CC45:Bl 28 77 SCRLEVEN LDA (BASL),Y CC47:91 2A 78 STA (BAS2L),Y CC49 :88 79 DEY CC4A:D0 F9 CC45 = 80 BNE SCRLEVEN ;do all but last even byte CC4C:70 04 Ccc52 #£«81 SCRLFT BVS' SKPLFT ;odd left edge, skip this byte 334 Appendix I: Monitor ROM Listings CC4E: LDA (BASL),Y CC50: STA (BAS2L),Y CC52: co SKPLFT LDA TXTPAGE] ;now do main page (odd bytes) CC55: LDY WNDWDTH ;srestore width CCD7: cc 5D BCS SKPRT ;even right edge, skip this byte CC59: SCRLODD LDA (BASL) ,Y CC5B: STA (BAS2L),Y CCSD: SKPRT DEY CC5E: cc 59 BPL SCRLODD CC60: CC 23 BML SCRLIN 3=> always scroll next line CC62: * CC62: SCRLDN DEX ;do next line CC63: CPX WNDTOP ;done yet Cc65: cc 35 BPL SETSRC 3=>nope, not yet CC67: * CC67: SCRLL3 PLP ;pull status off stack CC68: PLA ;restore window width CC69: STA WNDWDTH CCOB: CC JSR X.SUB ;clear current line CCOE: CD JSR VTAB srestore original cursor line CC71: PLA sand X CC72: TAX CC73: RTS sdone! !! CC74: * Cc74: * EXECUTE CLR TO EOS: Cc74: * CC74: CC X.VT JSR X.GS ;CLEAR TO EOL CC77: LDA CV sSAVE CV CC/9: PHA CC7A: CC 82 BPL Xe-VTNEXT ;DO NEXT LINE (ALWAYS TAKEN) CC7C: CE XeVTLOOP JSR VTABZ ;set base address CC7F: CC JSR X.SUB ;CLEAR LINE CC82: X.VINEXT INC CV CC84: LDA CV CC86: CMP WNDBTM ;OFF SCREEN? CC8B8: cc 7C BCC X.VTLOOP ;=>NO, KEEP GOING CC8A: PLA ; RESTORE CC8B: STA CV oy CC8D: CD JMP VTAB sreturn via VTAB (blech) Cc90: k CC90: * EXECUTE CLEAR: CC90: * Cc90: cc 90 X.FF EQU * Cc90: CB JSR X-EM ;HOME THE CURSOR CC93: CC JMP X.VT ;RETURN VIA CLREOS (UGH!) CC96: * CC96: * EXECUTE CLEAR LINE CCc96: k CC96: X.SUB LDY #0 ;start at left CC98: CC 9D BEO X.GSEOLZ sand clear to end of line CC9A: ke CC9A: * EXECUTE CLEAR TO EOL: CC9A: * CC9A : AC 7B 05 X.GS LDY OURCH sget CH Appendix I: Monitor ROM Listings 380 CC9D: 136 X.GSEOLZ LDA INVFLG smask blank CC9OF: 137 AND #$80 swith high bit of invflg CCAI1: 138 ORA #$20 smake it a blank CCA3: 139 BIT RD80VID sis it 80 columns? CCA6: 140 BMI CLR80 s=>yes do quick clear CCA8: 141 CLR40 STA (BASL),Y CCAA: 142 INY CCAB: 143 CPY WNDWDTH CCAD: CCA8 144 BCC CLR40 CCAF: 145 RTS CCBO: 146 k CCBO: 147 * Clear right half of screen for 40 to 80 CCBO: 148 * screen conversion CCBO: 149 * CCBO: 150 CLRHALF STX BAS2L ;save X CCB2: 151 LDX #SD8 sset horizontal counter CCB4: 152 LDY #20 CCB6: 153 LDA INVFLG sset (inverse) blank CCB8: 154 AND #$A0 CCBA: cc 155 JMP CLR2 CCBD: 156 CCBD: 157 * Clear to end of line for 80 columns CCBD: 158 CCBD: 2A 159 CLR80 STX BAS2L ;save X CCBF: 160 PHA sand blank CCCO: 161 ;get count for CH CCCl1: 162 ;save for left edge check CCC2: 163 scount=WNDWDTH-Y-1 CcCc3: 21 164 WNDWDTH CCC5: 165 ;save CH counter CCC6: 166 ;div CH by 2 for half pages CcG7: 167 CCC8: 168 CCCc9: 169 srestore original ch CCCA: 170 WNDLFT ;get starting page CCCC: 171 A CCCD: CCD2 L72 CLRO CCCF: CCD2 173 CLRO CCD1: 174 ;iff WNDLFT odd, starting byte odd CCD2: 175 CLRO PLA ;get blank CCD3: CCEO 176 CLRI ;starting page is 1 (default) CCD5: co 177 CLR2 BIT TXTPAGE2 ;else do page 2 CCD8: 178 (BASL),Y CCDA: CO 179 TXTPAGE]L j;now do page l CCDD: 180 CCDE: CCE6 181 CLR3 ;all done CCEO: 182 CLRI1 STA (BASL),Y CCE2: 183 sforward 2 columns CCE3: 184 snext ch CCE4: CCD5 185 CLR2 snot done yet CCE6: 186 BAS2L ;restore X CCE8: 187 ;good exit condition CCE9: 188 sand return CCEA: 189 336 Appendix I: Monitor ROM Listings 190 * EXECUTE '40COL MODE': 191 * CCEA 192 X.DCl EQU * FB 04 193 LDA MODE sdon*t convert if Pascal 4D 194 BMI X.DCIRTS ;=>it's Pascal 31 CD 195 X.DC1A JSR SETTOP sset top of window (0 or 20) 1F CO 196 BIT RD80VID sare we in 80 columns? 12 CDO9 197 BPL X.DCI1B 3=>no, no convert needed 91 CD 198 JSR SCRN84 selse convert 80 to 40 OD cDdO9 199 BCC X.DCIB ;=>always set new window 200 * 201 * Set 80 column mode 202 * CCFC 203 X.DC2 EQU * 90 CA 204 JSR TESTCARD ;is there an 80 column card? 3B CD3C 205 BNE X.DCIRTS' ;=>no, can't do this 1F CO 206 BIT RD80VID sare we in 40 columns? 03 CD09 207 BMI X.DCI1B 3=>no, mo convert needed C4 cn 208 JSR SCRN48 ;else convert 40 to 80 209 * 7B 05 210 X.DC1B LDA OURCH ;get cursor 211 CLC ;since new window left = 0 20 212 ADC WNDLFT ; NEWCH=OLDCH+OLDWNDLFT 1F CO 213 BIT RD80VID sin 80 columns? 06 CDIA 214 BMI X.DCIC s=>yes, CH is ok 28 215 CMP #40 ;else if CH is too big, 02 CDIA 216 BCC X.DCIC sset it to 39 27 217 LDA #39 7B 05 218 X.DC1C STA OURCH ;save new CH 24 219 STA CH 25 220 LDA CV ; base BA CA 221 JSR BASCALC 1F CO 222 BIT RD80VID sin 80 columns? 05 CD2E 223 BPL D040 s=>no, set forty column window 224 * 71 °CD 225 DO80 JSR FULL80 sset 80 column window 03 CD31 226 BEQ SETTOP 3=Dalways branch 227 * 6D CD 228 DO40 JSR FULL40 sset 40 column window 00 229 SETTOP LDA #0 sassume normal window 1A CO 230 BIT RNDTEXT stext or mixed? 02 CD3A 231 BMI DO4O0A s=>text, all ok 14 232 LDA #20 22 233 DO4OA STA WNDTOP ;set new top 234 X.DCIRTS RTS 235 * 236 * EXECUTE MOUSE TEXT OFF 237 * FB 04 238 MOUSEOFF LDA MODE 01 239 ORA #M.MOUSE ;set mouse bit 05 CD49 =240 BNE SMOUSF sto disable mouse chars 241 * 242 * EXECUTE MOUSE TEXT ON Appendix |: Monitor ROM Listings CD44: 243 * CD44:AD FB 04 244 MOUSEON LDA MODE CD47:29 FE 245 AND #255-M.MOUSE ;clear mouse bit CD49:8D FB 04 246 SMOUSE STA MODE ;to enable mouse chars CD4C :60 247 RTS CD4D: 248 * CD4D: 249 * EXECUTE 'QUIT': CD4D: 250 * CD4D: CD4D 251 X.NAK EQU * CD4D:AD FB 04 252 LDA MODE sONLY VALID IN BASIC CD50:30 1A CD6C 253 BMI SKRTS signore if pascal CD52:20 2E CD 254 JSR D040 sforce 40 column window CD55:20 80 CD 255 JSR QUIT sdo stuff used by PR#O0 CD58:20 64 CD 256 JSR SETCOUT] j;set output hook CD5B: 257 * CD5B:A9 FD 258 SETKEYIN LDA #KEYIN CD61:85 38 261 STA KSWL CD63 :60 262 RTS CD64: 263 * CD64:A9 FD 264 SETCOUT1 LDA #COUT1 CD6A:85 36 267 STA CSWL CD6C :60 268 SKRTS RTS CD6D: 269 * CD6D: 270 RREKRRKREAKERER ERK KKK AKERRERRERERIRERER ER CD6D: 271 * NAME : FULL4O CD6D: 272 * FUNCTION: SET FULL 40COL WINDOW CD6D: 273 * INPUT : NONE CD6D: 274 * OUTPUT : WINDOW PARAMETERS, A=0 CD6D: 275 * VOLATILE: AC CD6D: 276 RERKKRKKKRREKRRERERKERERERERKK KR RK RK RAK CD6D: 277 * CD6D: CD6D 278 FULL40 EQU * CD6D:A9 28 279 LDA #40 ;set window width to 40 CD6F:D0 02 CD73 280 BNE SAVWDTH 3=>(always taken) CD71: 281 * CD71: 282 HHRKKAKKKKHREKKEKREKRERRERERERREKE AKER CD71: 283 * NAME : FULL80 CD71: 284 * FUNCTION: SET FULL 80COL WINDOW CD/1: 285 * INPUT : NONE CD71: 286 * OUTPUT : WINDOW PARAMETERS, A=0 CD71: 287 *® VOLATILE: AC CD71: 2BQ KRKKKRKKRKKKRAAE RAK AKKERREKKKARKEKER ERK RRR CD71: 289 * CD71:A9 50 290 FULL80 LDA #80 sset full 80 column window CD73:85 21 291 SAVWDTH STA WNDWDTH CD/75:A9 18 292 LDA #24 CD77:85 23 293 STA WNDBITM CD79:A9 00 294 LDA #0 CD/B:85 22 295 STA WNDTOP CD7D:85 20 296 STA WNDLFT 338 Appendix I: Monitor ROM Listings CD/F :60 RTS CD80: * CD80: * QUIT is used by PR#0 to turn off everything CD80: * CD80: CD&0 QUIT EQU * CD80: co BIT RD80VID ;were we in 80 columns? CD83: CD&8 BPL QUIT2 3=> not a chance CD85: CC JSR X.DCI1A sswitch to 40 columns CD88: co QUIT2 STA CLRALTCHAR ;don't use lower case CD8B: LDA #SFF *DESTROY THE CD8N: 04 STA MODE ; MODE BYTE CD90: RTS CD91: k CD91: * SCRN84 and SCRN48 convert screens between 40 & 80 cols. CD91: * WNDTOP must be set up to indicate the last line to CD91: * be done. All registers are trashed. CD91: x CD91: SCRN84 TXA ssave X CD92: PHA CD93: LDX #23 sstart at bottom of screen CD95: co STA SET80COL j;allow page 2 access CD98: SCRI TXA scalc base for line CD99: CA JSR BASCALC CD9C: LDY #39 sstart at right of screen CD9E: SCR2 STY BAS2L ;save 40 index CDAO: TYA sdiv by 2 for 80 column index CDA1: LSR A CDA2: CDA? BCS SCR3 CDA4: BIT TXTPAGE2 j;even column, do page 2 CDA7: SCR3 TAY sget 80 index CDA8: LDA (BASL),Y ;get 80 char CDAA: BIT TXTPAGE] j;restore pagel CDAD: LDY BAS2L sget 40 index CDAF: STA (BASL),Y CDB1: DEY CDB2: BPL SCR2 ;do next 40 byte CDB4: DEX ;do next line CDB5: BMI SCR4 ;=>done with setup CDB?7: CPX WNDTOP ;at top yet? CDB9: BCS SCRI CDBB: SCR4 STA CLR80COL ;clear 80STORE for 40 columns CDBE: STA CLR80VID ;clear 80VID for 40 columns CDC1: JMP SCRNRET ;calc base, restore X, exit CDC4: * CDC4: SCRN48 TXA ;save X CDC5: PHA CDC6: LDX #23 sstart at bottom of screen CDC8: SCR5 TXA ;set base for current line CDCI: CA JSR BASCALC CDCC: LDY #0 sstart at left of screen CDCE: co STA SET80COL ;enable page2 store CDD1: SCR6 LDA (BASL),Y ;get 40 column char CDD3: SCR8 STY BAS2L s;save 40 column index CDD5: PHA ;save char Appendix I: Monitor ROM Listings 389 CDD6: TYA sdiv 2 for 80 column index CDD/7: LSR A CDD8: 03 CDDD BCS SCR/7 ;save on pagel CDDA: 55 CO STA TXTPAGE2 CDDD: SCR7 TAY szet 80 column index CDDE: PLA snow save character CDDF: 28 STA (BASL),Y CDE1: 54 CO STA TXTPAGEL 3;flip pagel CDE4: 2A LDY BAS2L srestore 40 column index CDE6: INY ;move to the right CDE?: 28 CPY #40 sat right yet? CDE9: E6 CDD1 BCC SCR6 3=>no, do next column CDEB: BO CC JSR CLRHALF sclear half of screen CDEE :CA DEX ;else do next line of screen CDEF: 04 CDF5 BMI SCR9 ;=>done with top line CDF1: 22 CPX WNDTOP 3;at top yet? CDF3: D3 CDC8 BCS SCR5 CDF5: OD CO SCRI STA SET80VID_ ;convert to 80 columns COF8: FE CD SCRNRET JSR VTAB ;update base CDFB: PLA srestore X CDFC: TAX CDFD: RTS CDFE: k CDFE: 25 VTAB LDA CV sget 80 column CV CEOO: FB 05 STA OURCV ;copy to OURCV CEO33 BA CA VTABZ JSR BASCALC scalc base address CEO6: 20 LDA WNDLFT sand add window left to it CEO8: 1F CO BIT RD80VID sis it 80 columns? CEOB: 01 CEOE BPL VTAB40 ;swindow width ok CEOD: LSR A selse divide width by 2 CEOE: VTAB40 CLC ;prepare to add CEOF: 28 ADC BASL sadd in window left CEl1l: 28 STA BASL ;and update base CE13: VTABX RTS sand exit CE14: INCLUDE SUBS3 CE14 :C9 El UPSHFT CMP #SEl sis it lowercase? CE16: 06 BCC UPSHFT2 ;=>nope CE18: FB CMP #SFB ;lowercase? CEI1A: 02 BCS UPSHFT2 ;=>nope CEI1C: DF AND #SDF selse upshift CELE: UPSHFT2 RTS CEILF: k CELF: KHKKKKKEKREKIKKEKRKRKERREAREKRREKKKKKREKKERRER CEILF: * NAME INVERT CEI1F: * FUNCTION: INVERT CHAR AT CH/CV CEIF: : Unless Pascal and M.CURSOR=1 CELF: * INPUT : NOTHING CEIF: * OUTPUT : CHAR AT CH/CV INVERTED CEILF: * VOLATILE: NOTHING CEIF: * CALLS : PICK, STORCHAR CEILF: REKEKKKEAREEKREEKKERRKEREEERKKRKKEKRRKRKRRRKRKKKRE CEIF: * CELF:AD FB 04 PASINV LDA MODE scheck pascal cursor flag CE22:29 10 AND #M.CURSOR ;before displaying cursor 340 Appendix I: Monitor ROM Listings CE24: 11 CE37 BNE INVX 3=>cursor off, don't invert CE26: INVERT PHA ;save AC CE27: TYA ; AND Y CE28: PHA CE29: 7B 05 LDY OURCH ;GET CH CE2C: 44 CE JSR PICK ;GET CHARACTER CE2F: EOR #$80 ;FLIP INVERSE/ NORMAL CE31: 70 CE JSR STORIT ; ONTO SCREEN CE34: PLA ;RESTORE Y CE35: TAY ; AND AC CE36: PLA CE37: INVX RTS CE38: HREKKEKKEKKEKEKEKEERERREKREREKRERRERKEERERRRERKK CE38: * NAME : STORCHAR CE38: * FUNCTI ON: STORE A CHAR ON SCREEN CE38: x INPUT : AC=CHAR CE38: * >: Y=CH POSITION CE38: * OUTPUT : CHAR ON SCREEN CE38: * VOLATI LE: NOTHING CE38: * CALLS : SCREENIT CE38: KEKKKKREKREREREKREREKKKEKREKEKEEKE AREER KK CE38: * CE38: CE38 STORCHAR EQU * CE38: PHA ;SAVE AC CE39: a2 BIT INVFLG sNORMAL OR INVERSE? CE3B: 02 CE3F BMI STOR2 ;=>NORMAL CE3D: 7F AND #S7F sinverse it CE3F: CE3F STOR2 EQU * CE3F: 70 CE JSR STORIT ;=>do it!! CE42: PLA s;RESTORE AC CE43: SEV RTS CE44: REEKEKREREKEKEEKRERKEEREREREEKKRKRK KKK KKK CE44: * NAME : PICK CE44: * FUNCTI ON: GET A CHAR FROM SCREEN CE44: * INPUT : Y=CH POSITION CE44: * OUTPUT : AC=CHARACTER CE44: * VOLATI LE: NOTHING CE44: * CALLS : SCREENIT CE44: KHKKKKKRKKKKEKEKEKER ERE KER RERAEKKK KEREKRERE KE CE44; * CE44: PICK (BASL),Y sget 40 column character CE46: RD8OVID 380 columns? CE49: CE64 PICK3 s=>no, do text shift CE4B: SET80COL sforce 80STORE for 80 columns CE4E: BAS2L ;temp store for position CE50: ;divide CH by two CE51: WNDLFT ;C=1 if char in main RAM CE53: A ;get low bit into carry CE54: PICKl 3=>store in main memory CE56: TXTPAGE2 ;else switch in page 2 CE59: sfor odd left, aux bytes CE5A: PICK] sdivide position by 2 CE5B: sand use carry as CE5C: ;page indicator Appendix I: Monitor ROM Listings 34] CE5D: PICK2 LDA (BASL),Y ;get that char CE5F: BIT TXTPAGE] ;flip to page 1 CE62: LDY BAS2L CE64: PICK3 BIT ALTCHARSET ;only allow mouse text CE67: BPL PICK4 sif alternate character set CE69: CMP #$20 CE6B: BCS PICK4 CE6D: ORA #$40 CE6F: PICK4 RTS CE/0: 83 * CE/0: HEKKKKAKIKREKEREREKRKEEEEREKKREARKAK RAKE KKEKK CE/70: * NAME : STORIT CE/0: * FUNCTION: STORE CHAR CE70: * INPUT : AC=char for store CE/0: * Z=high bit of char CE/0: *% : Y=CH POSITION CE/0: * OUTPUT : AC=CHAR (PICK) CE/0: * VOLATILE: NOTHING CE/0: * CALLS : NOTHING CE70: KAKKKKEKAKRERKKRKKEKKEKREKEKREEKKKKKKKKRKKKKKKE CE/70: 94 & CE/0: 95 STORIT PHA ;save char CE71: AND #SFF ;if high bit set... CE73: CE8B BMI STORE] ;=>not mouse text CE75: LDA MODE sis mouse text enabled? CE78: ROR A suse carry as flag CE79: PLA sand restore char CE7A: PHA sneed to save it too CE/B: BCC STORE] CE7D: BIT ALTCHARSET ;only do mouse text if CE80: BPL STOREIL salt char set switched in CE82: EOR #$40 sdo mouse shift CE84: BIT HEX60 ;is it in proper range? CE87: BEQ STORE] s=>yes, leave it CE89: EOR #$40 selse shift it back CE8B: * CE8B: STORE] BIT RD80OVID 380 columns? CE8E: BPL STOR4O ;=>no, 40 columns CE90: STA SET80COL_ ;force 80STORE for 80 columns CE93: PHA ;save shifted character CE94: STY BAS2L ;temp storage CE96: TYA ;Zet position CE97: EOR WNDLFT ;C=1 if char in main RAM CE99: LSR A CEQA: 04 CEAO BCS STORE2 s=>yes, main RAM CE9C: 55 LDA TXTPAGE2 j;else flip in main RAM CE9F: INY sdo this for odd left bytes CEAO: STORE2 TYA ;get position CEAIL: LSR A ;and divide it by 2 CEA2: TAY CEA3: STORIT2 PLA ;restore acc CEA4: 28 STA (BASL),Y ;save to screen CEA6: co LDA TXTPAGEL ;flip to page l CEA9: 2A LDY BAS2L 342 Appendix J: Monitor ROM Listings CEAB: 68 128 PLA ;restore true Acc CEAC :60 129 HEX60 RTS sand exit CEAD: 130 os CEAD 291 28 131 STOR4O STA (BASL),Y j;quick 40 column store CEAF: 68 132 PLA ;restore real char CEBO :60 133 RTS CEB1: 134 REKKKEKKKEREKRAEKRRERERERERKRKKKK RKKKKKKEKK CEBI: 135 * NAME : ESCON CEB1: 136 * FUNCTION: TURN ON 'ESCAPE' CURSOR CEB1: 137 * INPUT : NONE CEB1]: 138 * OUTPUT "CHAR'=ORIGINAL CHAR CEB1L: 139 * VOLATELE: NOTHING CEB1: 140 * CALLS : PICK,STORCHAR CEB1: 141 KREKKKAKEKREKAEKKRERERERKEEEEKKRKKKK KK KKK KKK CEB1: 142 k CEB1: CEBL 143 ESCON EQU * CEB1 248 144 PHA ;SAVE AC CEB2 298 145 TYA ; AND Y CEB3 248 146 PHA CEB4 : AC 7B 05 147 LDY OURCH ;GET CH CEB/ :20 44 CE 148 JSR PICK sGET ORIGINAL CHARACTER CEBA: 8D 7B 06 149 STA CHAR ; AND REMEMBER FOR ESCOFF CEBD: 29 80 150 AND #$80 ;SAVE NORMAL/INVERSE BIT CEBF 249 AB 151 EOR #SAB sMAKE IT AN INVERSE '+' CEC1 :4C CD CE 152 JMP ESCRET sRETURN VIA SIMILAR CODE CEC4: 153 KREKKKKEKKKKKKKKKKKKKKKKKKKKK KKK KKK KKK CEC4: 154 * NAME : ESCOFF CEC4: 155 * FUNCTION: TURN OFF 'ESCAPE' CURSOR CEC4: 156 * INPUT "CHAR'=ORIGINAL CHAR CEC4: 157 * OUTPUT : NONE CEC4: 158 * VOLATILE: NOTHING CEC4: 159 * CALLS : STORCHAR CEC4: 160 KHKKKKKKKKKKKREKEKRERERERERAKKKKKKRKKKKRKKKE CEC4: 161 * CEC4: CEC4 162 ESCOFF EQU * CEC4 248 163 PHA ;SAVE AC CEC5 298 164 TYA ; AND Y CEC6 748 165 PHA CEC7 : AC 7B 05 166 LDY OURCH ;GET CH CECA: AD 7B 06 167 LDA CHAR ;GET ORIGINAL CHARACTER CECD: CECD 168 ESCRET EQU #* ;USED BY ESCON CECD :20 70 CE 169 JSR STORIT ; EXACTLY AS IT WAS CEDO 268 170 PLA ;RESTORE Y CEDI :A8 171 TAY CED2 268 172 PLA - AND AC CED3 :60 173 RTS CED4: 174 PTETITTTTITITILTTTLILLIE LTT TT LLL Ee Le LLL. tt.) CED4: 175 * NAME : PSETUP CED4: 176 * FUNCTION: SETUP ZP FOR PASCAL CED4: 177 * INPUT : NONE CED4: 178 * OUTPUT : NONE CED4: 179 * VOLATILE: AC CED4: 180 * CALLS : NOTHING CED4: 181 KKKEKKKEKKEEKIEREEKEEKKKKKKKK KKK KKK Appendix I: Monitor ROM Listings 343 CED4: * CED4: CED4 PSETUP EQU * CED4: cD JSR FULL80 ‘SET FULL 80COL WINDOW CED/7: 1880 LDA #255 CED9: STA INVFLG ; ASSUME NORMAL MODE CEDB: x CEDB: 04 LDA MODE CEDE: AND #M.VMODE CEEO: CEE4 BEQ PSETUPRET ;=>IT'S NORMAL CEE2: LSR INVFLG ;MAKE IT INVERSE CEE4: * CEE4: CEE4 PSETUPRET EQU * CEE4: 07 LDA OLDBASL ;SET UP BASE ADDRESS CEE/7: STA BASL CEE9: 07 LDA OLDBASH CEEC: STA BASH CEEE: 05 LDA OURCV ;sget user's cursor vertical CEF1: STA CV sand set it up CEF3: RTS CEF4: KKEKKKEKRKEKEKKEREKEERERERREKEEEKEKK KEERKEKE CEF4: 2 CEF4: * COPYROM is called when the video firmware is CEF4: * initialized. If the language card is switched CEF4: * in for reading, it copies the F8 ROM to the CEF4: * language card and restores the state of the CEF4: * language card. CEF4: * CEF4: co COPYROM BIT RDLCRAM sis the LC switched in? CEF/7: CF36 BPL ROMOK 3=>no, do nothing CEF9: LDA #GOODF8 syes, check S$F8 RAM CEFB: FB CMP F8VERSION ;does it match? CEFE: CF36 BEQ ROMOK ;=> assum ROM is there CFO0: LDX #3 sindicate bank 2, RAM write enabled CFO2: co BIT RDLCBNK2 ;is it bank 2? CFOS: CFO9 BMI BANK2 s=Pyes, we were right CFO7: LDX #5SB sno, bank 1, RAM write enabled CFO9: FB BANK2 STA F8VERSION ;write to see if LC is CFOC: co BIT $c080 swrite protected (read RAM) CFOF: FB LDA F8VERSION ;did it change? CF1l2: CMP #GOODF8 CF14: CF1/7 BEQ WRTENBL 3;=>yes, write enabled CF16: INX selse indicate write protect CFl?7: co WRTENBL BIT $C081 ;read ROM, write RAM CFIA: co BIT $C081 stwice is nice CF1D: LDY #$0 snow copy ROM to RAM CFIF: LDA #SF8 CF21: STA CSWH shooks set later CF23: STY CSWL CF25: COPYROM2 LDA (CSWL),Y j;get a byte CF27: STA (CSWL),Y ;and move it CF29: INY CF2A: CF25 BNE COPYROM2 CF2C: INC CSWH snext page CF2E: CF25 BNE COPYROM2 ;finish copy CF30: CO LDA $C080,x sread RAM CF33: co LDA $C080,x CF36: ROMOK RTS ;done with ROM copy 344 Appendix I: Monitor ROM Listings 0000 TEST EQU 0 LST On,A,V 0001 IRQTEST EQU l MSB ON ;SET THEM HIBITS 0000 DO TEST F80RG EQU $1800 IOADR EQU $2000 ;For setting PR# hooks C1ORG EQU $2100 C30RG EQU $2300 C80RG EQU $2800 ELSE F800 F80ORG EQU S$F800 C100 C1ORG EQU $c100 C300 C30RG EQU $c300 C800 C80RG EQU $c800 FIN REKEKEEERKEKEKEERERKEERREREKKRKRKEKRERE APPLE II MONITOR II COPYRIGHT 1978, 1981, 1984 BY APPLE COMPUTER, INC. ALL RIGHTS RESERVED Se WOZNIAK 1977 A. BAUM 1977 JOHN A 1978 R. AURICCHIO 1981 E. BEERNINK 1984 He HF FF &+ HF 0001 APPLE2E EQU 1 ;COND ASSM/RRAO981 * RKERKEKKKKEEKKKEREKKKEEKKREKERRKKRAKER F800 ORG F80RG 2000 OBJ $2000 REKKEEKEKRKEKEKERKEKRKEKK RR RRRK * * Zero Page Equates * 0000 LOCO EQU $00 ;vector for autost from disk 0001 EQU $01 00 20 EQU $20 ;left edge of text window 0021 | EQU $21 swidth of text window 00 22 EQU $22 ;top of text window 00 23 EQU $23 sbottomtl of text window 00 24 EQU $24 ;cursor horizontal position 00 25 EQU $25 ;cursor vertical position 00 26 EQU $26 ;lo-res graphics base addr. 00 27 EQU $27 00 28 EQU $28 stext base address Appendix |: Monitor ROM Listings 345 F800: 0029 BASH EQU $29 F800: 002A BAS2L EQU S$2A ;temp base for scrolling F800: 002B BAS2H EQU $2B F800: 002C H2 EQU $2C ;temp for lo-res graphics F800: 002C LMNEM EQU $2C ;temp for mnemonic decoding F800: 002D V2 EQU $2D stemp for lo-res graphics F800: 002D RMNEM EOU $2D ;temp for mnemonic decoding F800: 002E MASK EQU S2E ;color mask for lo-res gr. F800: O002E CHKSUM EQU S2E ;temp for opcode decode F800: 002E FORMAT EQU S2E ;temp for opcode decode F800: 002F LASTIN EQU $2F ;temp for tape read csum F800: 002F LENGTH EQU S2F ;temp for opcode decode F800: 0030 COLOR EQU $30 ;color for lo-res graphics F800: 0031 MODE EQU $31 ;Monitor mode F800: 0032 INVFLG EQU $32 snormal/inverse(/flash) F800: 0033 PROMPT EQU $33 ;prompt character F800: 0034 YSAV EQU $34 ;position in Monitor command F800: 0035 YSAV1 EQU $35 ;temp for Y register F800: 0036 CSWL EQU $36 ;character output hook F800: 0037 CSWH EQU $37 F800: 0038 KSWL EQU $38 ;character input hook F800: 0039 KSWH EQU $39 F800: 003A EQU S3A ;temp for program counter F800: 003B EQU S3B F800: 003C FOU $3C ;Al-A5 are Monitor temps F800: 003D EQU $3D F800: O003E EQU S3E F800: 003F EQU S3F F800: 0040 EQU $40 F800: 0041 EQU $41 F800: 0042 EQU $42 F800: 0043 EQU $43 F800: 0044 EQU S44 F800: 0044 EQU $44 smachine state for break F800: 0045 EQU $45 F800: 0045 EQU $45 sAcc after break (destroys ASH) F800: 0046 EQU $46 3X reg after break F800: 0047 EQU $47 ;Y reg after break F800: 0048 EQU $48 ;P reg after break F800: 0049 EQU $49 ;SP after break F800: OO4E EQU $4E ;random counter low F800: OO4F EQU S4F ;random counter high F800: F800: 0095 EQU $95 ;CONTROL-U character F800: F800: 0200 EQU $0200 ;input buffer for GETLN F800: F800: * Page 3 vectors F800: * F800: 03F0 BRKV EQU SO3F0O svectors here after break F800: O3F2 SOFTEV EQU SO3F2 svector for warm start F800: O3F4 PWREDUP EQU SO3F4 sTHIS MUST = EOR #SA5 OF SOFTEV+1 F800: O3F5 AMPERV EQU $O3F5 sAPPLESOFT & EXIT VECTOR F800: O3F8 USRADR EQU S$O3F8 ;Applesoft USR function vector 346 Appendix I: Monitor ROM Listings F800: 03FB EQU SO3FB sNMI vector F800: O3FE EQU SO3FE ;Maskable interrupt vector F800: F800: 0400 EQU $0400 sfirst line of text screen F800: 07F8 EQU $07F8 scurrent user of $C8 space F800: F800: 0000 DO TEST F800: ELSE F800: c00O IOADR EQU $C000 F800: FIN F800: F800: Cc00O KBD EQU $c000 F800: c006 SLOTCXROM EQU $C006 senable slots 1-7 F800: c007 INTCXROM EQU $C007 ;swap out slots for firmware F800: C010 KBDSTRB EQU $c010 F800: COlLF RD80VID EQU SCOIF F800: C020 TAPEOUT EQU $c020 F800: C030 SPKR EQU $c030 F800: C050 TXTCLR EQU $c050 F800: co051 TXTSET EQU $co051l F800: C052 MIXCLR EQU $c052 F800: C053 MIXSET EQU $c053 F800: C054 LOWSCR EQU $c054 F800: c055 HISCR EQU $c055 F800: C056 LORES EQU $c056 F800: c057 HIRES EQU $C057 F800: C058 SETANO EQU $c058 F800: c059 CLRANO EQU $c059 F800: CO5A SETAN] EQU SCO5A F800: CO5B CLRAN}L EQU SCO5B F800: cO5C SETAN2 EQU S$CO5C F800: c0O5D CLRAN2 EQU $CO5D F800: CO5SE SETAN3 EQU SCOSE F800: CO5F CLRAN3 EQU SCOSF F800: C060 TAPEIN EQU $C060 F800: COG4 PADDLO EQU $C064 F800: C070 PTRIG EQU $c070 F800: * F800: C3FA IRQ EQU C30RG+SFA ;IRQ entry in $C3 page F800: C47C ITROFIX EQU C30RG+$17C ;Restore state at IRQ F800: * F800: C5@/7 XHEADER EQU C30RG+$267 F800: cS5SD1 XREAD EQU C30RG+S$2D1 F800: CS AA WRITE2 EQU C30RG+S2AA F800: * F800: CFFF CLRROM EQU SCFFF F800: E000 BASIC EQU SEO00 F800: E0Q3 BASIC2 EQU S$E003 F800: * F800: PLOT LSR A ;Y-COORD/2 F801: PHP ; SAVE LSB IN CARRY F802: JSR GBASC ALC ;CALC BASE ADR IN GBASL,H F805: PLP ;RESTORE LSB FROM CARRY F806: LDA #S0F ;MASK SOF IF EVEN Appendix I: Monitor ROM Listings 347 F808: F80C 146 BCC RTMASK F80A: 147 ADC #SEO ;MASK SFO IF ODD F80C: 148 RTMASK STA MASK F80E: 149 PLOT] LDA (GBASL),Y ; DATA F810: 150 EOR COLOR ; XOR COLOR F812: 151 AND MASK ; AND MASK F814: 152 EOR (GBASL),Y ; XOR DATA F816: 153 STA (GBASL),Y ; TO DATA F818: 154 RTS F819: 155 *& F819: F8 156 HLINE JSR ;PLOT SQUARE F81C: 157 HLINE] CPY ; DONE? F81E: F831 158 BCS ; YES, RETURN F820: 159 INY ; NO, INCR INDEX (X-COORD) F821: F8 160 JSR ;PLOT NEXT SQUARE F824: F81C BCC ;ALWAYS TAKEN F826: VLINEZ ADC ;NEXT Y—COORD F828: VLINE PHA ; SAVE ON STACK F829: F8 JSR ; PLOT SQUARE F82C: PLA F82D: CMP ; DONE? F82F: F826 BCC ; NO, LOOP. F831: RTS1 RTS F832: * F832: CLRSCR LDY sMAX Y, FULL SCRN CLR F834: F838 BNE sALWAYS TAKEN F836: CLRTOP LDY “MAX Y, TOP SCRN CLR F838: CLRSC2 STY ;STORE AS BOTTOM COORD F83A: 9 FOR VLINE CALLS F83A: LDY sRIGHTMOST X-COORD (COLUMN) F83C: CLRSC3 LDA sTOP COORD FOR VLINE CALLS F83E: STA *CLEAR COLOR (BLACK) F840: F8 JSR sDRAW VLINE F843: DEY sNEXT LEFTMOST X-COORD F844; F83C BPL ;LOOP UNTIL DONE. F846: RTS F847: & F847: GBASCALC PHA ;FOR INPUT OODEFGH F848: LSR F849: AND F84B: ORA ;GENERATE GBASH=000001FG F84D: STA F84F:; :AND GBASL=HDEDEO00 F850: F852: F856 F854: F856: GBCALC STA F858: ASL F859: ASL F385A: ORA F85C: STA F85E: RTS F85F: k F85F: NXTCOL LDA ; INCREMENT COLOR BY 3 348 Appendix I: Monitor ROM Listings F861: CLC F862: ADC #$03 F864: SETCOL AND #SOF ;SETS COLOR=17*A MOD 16 F866: STA COLOR F868: ASL A ;BOTH HALF BYTES OF COLOR EQUAL F869: ASL A F86A: ASL A F86B: ASL A F86C: 30 ORA COLOR F86E: 30 STA COLOR F870: RTS F871: * F871: SCRN LSR A ;READ SCREEN Y-COORD/2 F872: PHP ;SAVE LSB (CARRY) F873: 47 F8 JSR GBASCALC ;CALC BASE ADDRESS F876: 26 LDA (GBASL),Y ;GET BYTE F878: PLP ;RESTORE LSB FROM CARRY F879: 04 F87F SCRN2 BCC RTMSKZ ;LF EVEN, USE LO H F87B: LSR A F87C: LSR A F87D: LSR A ;SHIFT HIGH HALF BYTE DOWN F87E: LSR A F87F: OF RTMSKZ AND #SOF ;MASK 4-BITS F881: RTS F882: x F882: INSDS1] LDX PCL ;PRINT PCL,H F884: LDY PCH F886: FD JSR PRYX2 F889: F9 JSR PRBLNK ; FOLLOWED BY A BLANK F88C: LDA (PCL,X) ;GET OPCODE F88E: INSDS2 TAY F88F: LSR A ;EVEN/ODD TEST F890: F89B BCC IEVEN F892: ROR A ;BIT 1 TEST F893: F8A5 BCS ERR ;XXXXXX11 INVALID OP F895: CMP #SA2 F897: F8A5 BEQ ERR ;OPCODE $89 INVALID F899: AND #$87 ;MASK BITS F8 9B: IEVEN LSR A ;LSB INTO CARRY FOR L/R TEST F89C: TAX F89D: LDA FMT1,X ;GET FORMAT INDEX BYTE F8A0: JSR SCRN2 ;R/L H-BYTE ON CARRY F8A3: BNE GETFMT F8A5: ERR LDY #$80 ; SUBSTITUTE $80 FOR INVALID OPS F8A7: LDA #$00 ;SET PRINT FORMAT INDEX TO 0 F8A9: GETFMT TAX F8AA: F9 LDA FMT2,X ; INDEX INTO PRINT FORMAT TABLE F8AD: STA FORMAT ; SAVE FOR ADR FIELD FORMATTING F8AF: ; (O=1 BYTE, 1=2 BYTE, 2=3 BYTE) F8AF: x F8AF: * Move code to Cl-C2 because the code F8AF: * that tests for ROM in slot 3 must be in F8AF: * the F8 ROM. F8AF: * Appendix I: Monitor ROM Listings 349 F8AF : AA TAX ssave ACC in X F8B0 :84 2A STY BAS2L ;and Y in scrolling temp F8B2:A0 10 LDY #$10 scall = finish mnemonics F8B4 :4C B4 FB JMP GOTOCX soff to C100 F8B7: F8B7: Test slot 3 for a card containing ROM. F8B/7: If there is one, we'll not switch in our internal F8B7: slot3 firmware (for 80 columns). F8B/7: On entry Y has a high value like $F2, so the F8B/7: H +eROM/bus is read a bunch of times F8B/7: x F8B7 :8D TSTROM STA SLOTCXROM ;swap in slots F8BA:A2 TSTROMO LDX #2 ;check 2 ID bytes F8BC:BD TSTROM1 LDA $c305,X sat C305 and $C307 F8BF:DD CMP CLREOL,X swith two bytes that are same F8C2 :DO BNE XTST F8C4:CA DEX scheck next ID byte F8C5:CA DEX F8C6:10 BPL TSTROM1] F8C8 :88 DEY F8C9:DO EF BNE TSTROMO ;if ROM ok, exit with BEQ F8CB:8D XTST STA INTCXROM ;swap internal ROM F8CE:60 RTS sand return there F8CF: F8CF:EA NOP ;line things up F8D0: F8D0:20 82 INSTDSP INSDS1 ;GEN FMT, LEN BYTES F8D3 :48 ;SAVE MNEMONIC TABLE INDEX F8D4 : Bl 3A PRNTOP (PCL),Y F8D6 : 20 DA PRBYTE F8D9:A2 01 #$01 ;PRINT 2 BLANKS F8DB:20 4A PRNT BL PRBL2 F8DE:C4 2F LENGTH ;PRINT INST (1-3 BYTES) F8E0 :C8 ;IN A 12 CHR FIELD F8E1 :90 Fl F8D4 PRNTOP F8E3:A2 03 #$03 ;CHAR COUNT FOR MNEMONIC INDEX F8E5:CO 04 #$04 F8E7 :90 F2 F8DB PRNTBL F8E9 :68 ;RECOVER MNEMONIC INDEX F8EA:A8 F8EB: B9 co F9 MNEML,Y F8EE :85 2C LMNEM ;FETCH 3-CHAR MNEMONIC F8FO:B9 00 FA MNEMR,Y ; (PACKED INTO 2-BYTES) F8F3:85 2D RMNEM F8F5:A9 00 PRMNI1 #500 F8F7 : AO 05 #S05 F8F9:06 2D PRMN2 RMNEM ;SHIFT 5 BITS OF CHARACTER INTO A F8FB:26 2C LMNEM F8FD:2A A ; (CLEARS CARRY) F8FE:88 F8FF :DO F8 F8F9 PRMN2 F901 :69 BF #SBF sADD "2" OFFSET F903:20 ED FD COUT -OUTPUT A CHAR OF MNEM F906:CA 300 Appendix I: Monitor ROM Listings F907:DO EC F8F5 308 BNE PRMNI F909:20 48 F9 309 JSR PRBLNK ;OUTPUT 3 BLANKS F9OC:A4 2F 310 LDY LENGTH FIOE:A2 06 311 LDX #506 ;CNT FOR 6 FORMAT BITS F910:EQ 03 312 PRADRI CPX #$03 F912:FO 1C F930 313 BEQ PRADRS5 ;1F X=3 THEN ADDR. F914:06 2E 314 PRADR2 ASL FORMAT F916:90 OE F926 315 BCC PRADR3 F918:BD B3 F9 316 LDA CHAR1-1,X F91B:20 ED FD 317 JSR COUT F91E:BD B9 F9 318 LDA CHAR2-1,X F921:FO 03 F926 319 BEQ PRADR3 F923:20 ED FD 320 JSR COUT F926:CA 321 PRADR3 DEX F927:DO E7 F91O 322 BNE PRADRI F929:60 323 RTS F92A:88 324 PRADR4 )NEY F92B:30 E/7 F914 325 BMI PRADR2 F92D:20 DA FD 326 JSR PRBYTE F930:A5 2E 327 PRADR5 LDA FORMAT F932:C9 E8 328 CMP #SE8 ;HANDLE REL ADR MODE F934:Bl 3A 329 LDA (PCL),Y >SPECIAL (PRINT TARGET, F936:90 F2 FIZA 330 BCC PRADR4 ; NOT OFFSET) F938:20 56 F9 331 RELADR JSR PCADJ3 F93B:AA 332 TAX ;PCL,PCH+OFFSET+1 TO A,Y F93C:E8 333 INX F93D:D0 Ol F940 334 BNE PRNTYX ;+l1 TO Y,X F93F:C8 335 INY F940:98 336 PRNTYX TYA F941:20 DA FD 337 PRNTAX JSR PRBYTE sOUTPUT TARGET ADR F944:8A 338 PRNTX TXA ; OF BRANCH AND RETURN F945:4C DA FD 339 JMP PRBYTE F948: 340 * F948:A2 03 341 PRBLNK LDX #$03 ; BLANK COUNT F94A:A9 AO 342 PRBL2 LDA #SAO ;LOAD A SPACE F94C:20 ED FD 343 PRBL3 JSR COUT s;OUTPUT A BLANK FO4F:CA 344 DEX F950:DO F8 F9O4A 345 BNE PRBL2 ;LOOP UNTIL COUNT=0 F952 :60 346 RTS F953: 347 * F953:38 348 PCADJ SEC -O=1 BYTE, 1=2 BYTE, F954:A5 2F 349 PCADJ2 LDA LENGTH ; 2=3 BYTE F956:A4 3B 350 PCADJ3 LDY PCH F958:AA 351 TAX ;TEST DISPLACEMENT SIGN F959:10 Ol F95C 352 BPL PCADJ4 ; (FOR REL BRANCH) F95B:88 353 DEY ;EXTEND NEG BY DECR PCH F95C:65 3A 354 PCADJ4 ADC PCL F95E:90 Ol F961 355 BCC RTS2 ;PCL+LENGTH(OR DISPL)+1l TO A F960:C8 356 INY ; CARRY INTO Y (PCH) F961 :60 357 RTS2 RTS F962: 358 ; F962: 359 ; FMT1 BYTES: XXXXXXYO INSTRS F962: 360 ; IF Y=0 THEN LEFT HALF BYTE F962: 361 ; IF Y=1 THEN RIGHT HALF BYTE Appendix I: Monitor ROM Listings F962: 362 ; (X=INDEX) F962: 363 ; F962: 364 FMT1l DFB F963: 365 DFB F964: DFB F965: DFB F966: DFB F967: DFB F968: DFB F969: DFB F96A: DFB F96B: DFB F96C: DFB F96D: DFB F96E: DFB F96F: DFB F970: DFB F971: DFB F972: DFB F973: DFB F974: DFB F975: DFB F976: DFB F977: DFB F978: DFB F979: DFB F97A: DFB F97B: DFB F97C: DFB F97D: DFB FO7E: DFB FO7F: DFB F980: DFB F981: DFB F982: DFB F983: DFB F984: DFB F985: DFB F986: DFB F987: DFB F988: DFB F989: DFB F98A: DFB F98B: DFB F98C: DFB F98D: DFB F98E: DFB F98F: DFB F990: DFB F991: DFB F992: DFB F993: DFB F994: DFB F995: DFB Appendix I: Monitor ROM Listings DFB SOD DFB $80 DFB $04 DFB $90 DFB $01 DFB $22 DFB S44 DFB $33 DFB SOD DFB $80 DFB $04 DFB $90 DFB $26 DFB $31 DFB $87 DFB S9A ; ZZXXXY01 INSTR'S ’ FMT2 DFB $00 ERR DFB $21 ; [IMM DFB $81 : Z-PAGE DFB $82 ; ABS DFB $00 > IMPLIED DFB $00 ; ACCUMULATOR DFB $59 ; (ZPAG ,X) DFB S4D ;(ZPAG),Y DFB $91 ;ZPAG ,X DFB $92 ;ABS,X DFB $86 ;ABS ,Y DFB S4A *( ABS) DFB $85 ;ZPAG,Y DFB S9D *RELATIVE CHARI] DFB SAC Ft DFB SAI ae SAC et DFB DFB $A3 oti DFB SA8 ae eg DFB SA4 a CHAR2 DFB $D9 ety" DFB $00 DFB SD8 ony' DFB SA4 etS! SA4 atc! DFB DFB $00 MNEML DFB S$1C DFB S8A DFB $1C DFB $23 DFB $5D DFB $8B DFB S1B DFB SAl DFB $9D Appendix I: Monitor ROM Listings 303 F9C9: DFB S8A F9CA: DFB $1D F9CB: DFB $23 F9CC: DFB $9D F9ICD: DFB S8B F9CE: DFB S$1D F9OCF: DFB SAl F9DO: DFB $00 F9D1L: DFB $29 F9D2: DFB $19 F9D3: DFB SAE F9D4: DFB $69 F9D5: DFB SA8 F9D6: DFB $19 F9D7: DFB $23 F9D8: DFB $24 F9D9: DFB $53 F9ODA: DFB S1B FODB: DFB $23 F9ODC: DFB $24 FODD: DFB $53 FODE: DFB $19 ; (A) FORMAT ABOVE FODF: DFB SAl F9EO: DFB $00 F9EL: DFB SIA F9E2: DFB SSB F9E3: DFB S5B F9E4; DFB SA5 F9ES: DFB $69 F9E6: DFB $24 ; (B) FORMAT F9E7: DFB $24 FOES: DFB SAE F9E9: DFB SAE F9EA: DFB SA8 FOEB: DFB SAD F9EC: DFB $29 F9ED: DFB $00 F9OEE: DFB $7C ; (C) FORMAT F9OEF: DFB $00 F9FO: DFB $15 F9OF1: DFB $9C FOF2: DFB S6D F9F3: DFB S9C FOF4: DFB SA5 FOF5: DFB $69 F9F6: DFB $29 ; CD) FORMAT F9OF/7: DFB $53 F9OF8: DFB $84 FOF9: DFB $13 FOFA: DFB $34 F9OFB: DFB $11 F9OFC: DFB SA5 F9FD: DFB $69 FOFE: DFB $23 > (E) FORMAT 304 Appendix I: Monitor ROM Listings F9OFF: DFB SAO FAOO: 525 MNEMR DFB SD8 FAO]: DFB $62 FAO2: DFB S5A FAQ3: DFB $48 FAO4: DFB $26 FAQS: DFB $62 FAO6: DFB $94 FAO7: DFB $88 FA08: DFB $54 FAO9: DFB S44 FAOA: DFB Sc8 FAOB: DFB S54 FAOC: DFB $68 FAOD: DFB $44 FAOE: DFB SE8 FAOF: DFB $94 FA1O: DFB $00 FAL1: DFB SB4 FA12: DFB $08 FA13: DFB $84 FAL4: DFB $74 FAL5: DFB SB4 FAL6: DFB $28 FA17: DFB S6E FAL8: DFB $74 FA19: DFB SF4 FAIA: DFB SCC FAIB: DFB S4A FAIC: DFB $72 FAID: DFB SF2 FALE: DFB SA4 ; (A) FORMAT FAIF: DFB SBA FA20: DFB $00 FA21: DFB SAA FA22: DFB SA2 FA23: DFB SA2 FA24: DFB S74 FA25: DFB $74 FA26: DFB $74 - (B) FORMAT FA27: DFB $72 FA28: DFB $44 FA29: DFB $68 FA2A: DFB $B2 FA2B: 568 DFB $32 FA2C: 569 DFB SB2 FA2D: 570 DFB $00 FA2E: 571 DFB $22 - (C) FORMAT FA2F: 572 DFB $00 FA30: 573 DFB SIA FA31: 574 DFB S1A FA32: 575 DFB $26 FA33: 576 DFB $26 Appendix J: Monitor ROM Listings 300 FA34:72 DFB $72 FA35:72 DFB $72 FA36:88 DFB $88 ; (D) FORMAT FA37:C8 DFB $c8 FA38:C4 DFB $c4 FA39:CA DFB SCA FA3A:26 DFB $26 FA3B:48 DFB $48 FA3C:44 DFB $44 FA3D:44 DFB $44 FA3E:A2 DFB SA2 ; (E) FORMAT FA3F:C8 DFB $c8 FA4O: * FA40: C3FA NEWIRQ EQU SC3FA snew IRQ entry FA4O: * FA40:85 OLDIRQ STA $45 ;(should never be used) FA42:A5 LDA $45 sfor those who save A to $45 FA44:4C C3 JMP NEWIRQ ;go to interrupt handler FA47: * FA47 :8D co NEWBREAK STA SETSLOTCXROM ;force in slots FA4A:85 STA ACC ssave accumulator FA4C: * FA4C:28 BREAK PLP FA4D:20 FF JSR SAV1 ;SAVE REG'S ON BREAK FA50:68 ; INCLUDING PC FA51:85 PCL FA53:68 FA54:85 PCH FA56 :6C ( BRKV) ;BRKV WRITTEN OVER BY DISK BOOT FA59: FA59:20 INSDS1 ;PRINT USER PC FA5C:20 RGDSP1 ; AND REGS FASF:4C MON ;GO TO MONITOR (NO PASS GO, NO $200!) FA62:D8 RESET ;DO THIS FIRST THIS TIME FA63:20 SETNORM FA66:20 INIT FA69:20 SETVID FA6C:20 SETKBD FA6F:AD INITAN SETANO ; ANO TTL LO FA72:AD SETANI ; ANI TTL LO FA75:A0 #9 : CODE=INIT/RRA0981 FA/7:20 GOTOCX ;DO APPLE2E INIT/RRA0981 FA7A:EA -/RRAO981 FA7B:AD CLRROM ; TURN OFF EXTNSN ROM FA7E:2C KBDSTRB ; CLEAR KEYBOARD FA81:D8 NEWMON FA82:20 BELL ; CAUSES DELAY IF KEY BOUNCES FA85: AD SOFTEV+1 -IS RESET HI FA88:49 #SA5 :A FUNNY COMPLEMENT OF THE FA8A:CD PWREDUP ; PWR UP BYTE 2??? FA8D: DO PWRUP ; NO SO PWRUP FA8F:AD SOFTEV : YES SEE IF COLD START FA92:DO NOF IX ; HAS BEEN DONE YET? FA94:A9 #SEO ; DOES SOFT ENTRY VECTOR POINT AT BASIC? 306 Appendix I: Monitor ROM Listings FA96:CD F3 03 631 CMP SOFTEV+1 FA99:DO 08 FAA3 632 BNE NOFIX ; YES SO REENTER SYSTEM FA9B:A0 03 633 FIXSEV LDY #3 ; NO SO POINT AT WARM START FA9D:8C F2 03 634 STY SOFTEV ; FOR NEXT RESET FAAON:4C 00 EO 635 JMP BASIC ; AND DO THE COLD START FAA3:6C F2 03 636 NOFIX JMP (SOFTEV) ; SOFT ENTRY VECTOR FAA6: 637 KRRARAKKAKKKKRERKKE FAA6:20 60 FB 638 PWRUP JSR APPLETII FAAS: FAAQO 639 SETPG3 EQU * ; SET PAGE 3 VECTORS FAA9:A2 05 640 LDX #5 FAAB:BD FC FA 641 SETPLP LDA PWRCON-1,X 3; WITH CNTRL B ADRS FAAE:9D EF 03 642 STA BRKV-1,X ; OF CURRENT BASIC FAB] :CA 643 DEX FAB2:DO F/ FAAB 644 BNE SETPLP FAB4:A9 C8 645 LDA #SC8 ; LOAD HI SLOT +1 FAB6:86 00 646 STX LOCO : SETPG3 MUST RETURN X=0 FAB8:85 01 647 STA LOC1 ; SET PTR H FABA: 648 * FABA: 649 * Check 3 ID bytes instead of 4. Allows devices FABA: 650 * other than Disk II's to be bootable. FABA: 651 * FABA:AO 05 652 SLOOP LpyY #5 sY is byte ptr FABC:C6 Ol 653 DEC LOCI FABE:A5 O01 654 LDA LOC1 FACO:C9 CO 655 CMP #SCO ; AT LAST SLOT YET? FAC2:FO D7 FAIB 656 BEQ FIXSEV ; YES AND IT CAN'T BE A DISK FAC4:8D F8 07 657 STA MSLOT FAC7:Bl 00 658 NXTBYT LDA (LOCO),Y ; FETCH A SLOT BYTE FAC9:D9 Ol FB 659 CMP DISKID-1,Y ; IS IT A DISK ?? FACC:DO EC FABA 660 BNE SLOOP ; NO, SO NEXT SLOT DOWN FACE :88 661 DEY FACF:88 662 DEY ; YES, SO CHECK NEXT BYTE FADO:10 F5 FAC/ 663 BPL NXTBYT ; UNTIL 3 BYTES CHECKED FAD2:6C 00 OO 664 JMP (LOCO) ; GO BOOT... FADS: 665 * FAD5:EA 666 NOP FAD6:EA 667 NOP FAD/7: 668 * FAD7:20 8E FD 669 REGDSP JSR CROUT ;DISPLAY USER REG CONTENTS FADA:A9 45 670 RGDSP1 LDA #$45 ;WITH LABELS FADC:85 40 671 STA A3L FADE: A9 00 672 LDA #$00 FAEO:85 41 673 STA A3H FAE2:A2 FB 674 LDX #SFB FAE4:A9 AO 675 RDSP1 LDA #SA0 FAE6:20 ED FD 676 JSR COUT FAE9:BD 1E FA 677 LDA RTBL-251,X FAEC:20 ED FD 678 JSR COUT FAEF:A9 BD 679 LDA #SBD FAF1:20 ED FD 680 JSR COUT FAF4:B5 4A 681 LDA ACC+5,X FAF6:20 DA FD 682 JSR PRBYTE FAF9:E8 683 INX FAFA:30 E8 FAE4 684 BMI RDSP1 Appendix I: Monitor ROM Listings FAFC: FAFD: * FAFD: PWRCON OLDBRK FAFF: $00 ,$E0O,$45 FBO2: DISKID $20,$FF,$00,$FF FBO6: $03 ,SFF,$3C FBO9: "Apple }C' FB11: XLTBL * FB11: $c4 ,$C2,$Cl FB14: SFF,$C3 FB16: SFF,SFF,$FF FB19: FB19: $C1,$D8,$D9 ;REGISTER NAMES FOR REGDSP: FBIC: $D0 ,$D3 : "AXYPS* FBLE: PTRIG ;TRIGGER PADDLES FB21: #500 - INIT COUNT FB23: ;COMPENSATE FOR 1ST COUNT FB24: FB25: PREAD2 PADDLO,X ;COUNT Y-REG EVERY 12 USEC. FB28: FB2E RTS2D FB2A: FB2B: FB25 PREAD2 SEXIT AT 255 MAX FB2D: FB2E: FB2F: FB2F: #500 ;CLR STATUS FOR DEBUG SOFTWARE FB31: STATUS FB33: LORES FB36: LOWSCR ; INIT VIDEO MODE FB39: SETTXT TXTSET ;SET FOR TEXT MODE FB3C: #500 ; FULL SCREEN WINDOW FB3E: SETWND FB40: SETGR TXTCLR ;SET FOR GRAPHICS MODE FB43: MIXSET ;LOWER 4 LINES AS TEXT WINDOW FB46: CLRTOP FB49: #514 FB4B: SETWND WNDTOP ;SET FOR 40 COL WINDOW FB4D: #500 ;TOP IN A-REG, FB4F: WNDLFT ; BOTTOM AT LINE $24 FB51: #SC :CODE=SETWND /RRAO981 FB53: FBB4 GOTOCX FB55: #$18 FB57: WNDBTM FB59: #$17 -VTAB TO ROW 23 FB5B: TABV CV ;VIABS TO ROW IN A-REG FB5D: FC VTAB FB60: * FB60: FC APPLEII HOME ;CLEAR THE SCRN FB63: #9 FB65: FF STITLE TITLE-1,Y ;GET A CHAR FB68: 04 LINE1+14,Y ;PUT IT AT TOP CENTER OF SCREEN FBOB: FB6C: FB65 STITLE FB6E: 308 Appendix J: Monitor ROM Listings FBOF: 31 * FBOF: F3 03 32 SETPWRC LDA SOFTEV+1 ;ROUTLNE TO CALCULATE THE 'FUNNY FB/72: A5 33 EOR #SA5 *COMPLEMENT' FOR THE RESET VECTOR FB/4: F4 03 34 STA PWREDUP FB/7: 35 RTS FB/78: 36 & FB/8: 37 VIDWAIT EQU * ;CHECK FOR A PAUSE (CONTROL-S). FB78: 8D 38 CMP #S8D sONLY WHEN I HAVE A CR FB7A: 18 39 BNE NOWAIT sNOT SO, DO REGULAR FB/C: 00 cO 40 LDY KBD -IS KEY PRESSED? FB/F: 13 41 BPL NOWAIT -NO. FB81: 93 42 CPY #$93 sYES —-- IS IT CTRL-S? FB83: OF 43 BNE NOWAIT -NOPE - IGNORE FB85: 10 CO 44 BIT KBDSTRB *CLEAR STROBE FB88: 00 CO 45 KBDWAIT LDY KBD *WAIT TILL NEXT KEY TO RESUME FB8B: FB 46 BPL KBDWAIT WAIT FOR KEYPRESS FB8D: 83 47 CPY #$83 :IS IT CONTROL-C? FB8F: 03 48 BEQ NOWAILT sYES, SO LEAVE IT FB91: 10 CO 49 BIT KBDSTRB CLR STROBE FB94: FD FB 50 NOWAIT JMP VIDOUT “DO AS BEFORE FB97: 51 k FB97: 52 ESCOLD SEC s INSURE CARRY SET FB98: 2C FC 53 JMP ESCl FBOB: 54 ESCNOW TAY USE CHAR AS INDEX FB9IC: 48 FA 55 LDA XLTBL-$C9,Y ;TRANSLATE IJKM TO CBAD FBOF: 97 FB 56 JSR ESCOLD ;DO THE CURSOR MOTION FBA2: 21 FD 57 JSR RDESC ;GET LJKM, ijkm, ARROWS/RRA0981 FBA5S: CE 58 ESCNEW CMP #SCE -IS THIS AN 'N'? FBA?7: EE FB97 59 BCS ESCOLD ;'N' OR GREATER - DO IT! FBAY: C9 60 CMP #SC9 “LESS THAN 'I'? FBAB: EA FB97 61 BCC ESCOLD sYES, SO DO OLD WAY FBAD: CC 62 CMP #SCC -IS IT AN 'L'? FBAF: E6 FB97 63 BEQ ESCOLD ;DO NORMAL FBBI: E8 FB9 B 64 BNE ESCNOW ;GO DO IT FBB3: 65 * FBB3: COO 6 66 SETSLOTCXROM EQU $CO06~ ;/RRAO981 FBB3: C007 67 SETINTCXROM EQU $C007 ; /RRAO981 FBB3: cO15 68 RDCXROM EQU SCO15 ; /RRAO 981 FBB3: 69 * /RRAO981 FBB3 :06 70 VERSION DFB $06 FOR LDCHECK/RRA0981 FBB4: 71 * FBB4: FBB4 72 GOTOCX EQU * ; /RRAO 981 FBB4 S20 15 co 73 BIT RDCXROM -GET CURRENT STATE/RRA0981 FBB/ :08 74 PHP >SAVE ROMBANK STATE/RRAO981 FBB8 :8D 07 CO 75 STA SETINTCXROM ;SET ROMS ON/RRAO0981 FBBB: 4c 00 Cl 76 JMP CLORG °=>OFF TO CXSPACE/RRAO981 FBBE: ii * FBBE :00 78 DFB O FBBF: 00 79 DFB 0 FBCO: 80 * FBCO: EO 81 ZIDBYTE DFB SEO ;//e ROM rev ID byte FBC1: 82 * FBC1 748 83 BASCALC PHA sCALC BASE ADDR IN BASL,H FBC2 4A 84 LSR A ;FOR GIVEN LINE NO. Appendix I: Monitor ROM Listings 309 FBC3: #$03 ; O<=LINE NO.<=$17 FBC5: #$04 ;ARG = OOOABCDE, GENERATE FBC7: BASH ; BASH = OOOO01CD FBC9: ; AND FBCA: #518 ; BASL = EABABOOO FBCC: FBDO BASCLC2 FBCE: #S7F FBDO: BASCLC2 BASL FBD2: FBD3: FBD4: FBD6: FBD8: FBD9: FBD9: ;BELL CHAR? (CONTROL-G) FBDB: FBEF ; NO, RETURN. FBDD: ; YESe.ee FBDF: FC ;DELAY .Ol1 SECONDS FBE2: FBE4: BELL2 -TOGGLE SPEAKER AT 1 KHZ FBE6: FC - FOR .1 SEC. FBE9: co FBEC: FBED: FBE4 FBEF: RTS2B FBFO: * FBFO: STORADV CH ;CURSOR H INDEX TO Y-REG FBF2: (BASL),Y ;STORE CHAR IN LINE FBF4: ADVANCE CH s INCREMENT CURSOR H INDEX FBF6: CH ; (MOVE RIGHT) FBF8: WNDWDTH sBEYOND WINDOW WIDTH? FBFA: FC62 CR ; YES, CR TO NEXT LINE. FBFC: RTS3 ; NO, RETURN. FBFD: * FBFD: VIDOUT #SA0 ;sCONTROL CHAR? FBFF: FBFO STORADV ; NO, OUTPUT IT. FCOL: ; INVERSE VIDEO? FCO2: FBFO STORADV ; YES, OUTPUT IT. FCO4: #S8D CR? FCO6: FC62 ; YES. FCO8: ;LINE FEED? FCOA: FC66 ; IF SO, DO IT. FCOC: ;BACK SPACE? (CONTROL-H) FCOE: FBD9 ; NO, CHECK FOR BELL. FC10: BS ;DECREMENT CURSOR H INDEX FC12: FBFC RTS3 ;IF POSITIVE, OK; ELSE MOVE UP. FC14: WNDWDTH ;SET CH TO WINDOW WIDTH - l. FC16: CH FC18: CH ;(RIGHTMOST SCREEN POS) FCI1A: UP WNDTOP ;CURSOR V_ INDEX FCIC? FCIE: FBFC ;1[F TOP LINE THEN RETURN FC20: ;DECR CURSOR V INDEX FC2Z2: 360 Appendix I: Monitor ROM Listings FC22: VTAB CV ;GET CURSOR V INDEX FC24: VTABZ BASL ;temporarily save Acc FC26: sand Y FC27: #$4 ;this is VTABZ call FC29: FBB4 GOTOCX] GOTOCX 3=> always perform call FC2B: * FC2B: FC2C: FC2C: ESC1 #$CO ;ESC '@'? FC2E: FC58 HOME ; LF SO DO HOME AND CLEAR FC30: #SFD ;ESC-A OR B CHECK FC32: FBF4 ADVANCE ; A, ADVANCE FC34: FC1O ; B, BACKSPACE FC36: ;ESC-C OR D CHECK FC38: FC66 - C, DOWN FC3A: FCLA ; D, GO UP FC3C: sESC-E OR F CKECK FC3E: FC9OC ; E, CLEAR TO END OF LINE FC40: FBFC : ELSE NOT F,RETURN FC42: * FC42: FC42 CLREOP ;/RRAO981 FC42: #SA ; CODE=CLREOP/RRA0981 FC44: FC29 GOTOCX1 ;DO 40/80 /RRA0981 FC46: FC46: co RD80VID sin 80 columns? FC49: FC4F NEWVW1 ;=>not 80 columns FC4B: #$0 ;Print a character FC4D: FC5A GOTOCX3 ;through video firmware FC4F: NEWVW1 ;get masked character FC50: ;and set up for vidwait FCS1: FB VIDWAIT ;print the character FC54: ;restore Acc FC55: YSAV1 sand Y FC57: FC58: FC58: FC58 HOME * ;/RRAO981 FC58: #5 s CODE=HOME /RRAO98 1 FCSA: FB GOTOCX3 GOTOCX sdo 40/80 FC5D: * FC5D: FC5E: FC5SF: FC60: FC61: FC62: FC62: CR ;CURSOR TO LEFT OF INDEX FC64: ;(RET CURSOR H=0) FC66: LF ;INCR CURSOR V. (DOWN 1 LINE) FC68: FC6A: ;OFF SCREEN? FC6C: FC24 BCC - NO, SET BASE ADDR FC6E: DEC sDECR CURSOR V. (BACK TO BOTTOM) FC70: * FC70: FC 70 SCROLL EQU ;/RRAO981 Appendix I: Monitor ROM Listings 361 FC70: AO 06 193 LDY #6 ; CODE=SCROLL/RRAO981 FC72: DO B5 FC29 194 BNE GOTOCX1 ;DO 40/80 /RRAO0981 FC74: 195 * FC74: 196 * Jump here to swap out ROMs FC74: 197 * for interrupt handlers in peripheral cards FC74: 198 * FC74 :8D 06 co 199 IROQUSER STA SETSLOTCXROM ;switch in slots FC77 :6C FE 03 200 JMP ($3FE) ;and jump to user FC7A: 201 * FC7A: 202 * IRQDONE ($C3F4) jumps here after interrupt FC7A: 203 * because this cannot be done from $Cn00 space FC7A: 204 * FC7A: 205 IRQDONE2 PLA ;Fix $C800 space FC7B: 206 STA MSLOT ;restore MSLOT FC7E: 207 CMP #SC1 svalid Cn? FC80: 208 BCC IRQNOSLT FC82: 209 STA SCFFF ;Deselect all $C800 FC85: 210 LDY #0 FC87: 211 LDX $] FC89: 212 STA $1 FC8B: 213 LDA ($0),Y ;do $Cn00 reference FC8D: 214 STX $1 ;fix zp location FC8F: co 215 IRQNOSLT STA SETINTCXROM FC92: C4 216 JMP IRQFIX ;and restore the machine state FC95: 217 * FC95: FC99 218 DOCOUT1 BCC DOCOUT2 sdon't mask controls FC97: 219 AND INVFLG ;sapply inverse mask FC99: FD 220 DOCOUT2 JMP COUTZ1 3g0 back to COUTI FC9C: 221 * FC9IC: 0000 222 DS F8ORG+$49C-*,0 ;pad to clreol FC9C: 223 * FCIC: 224 * Note: bytes CLREOL and CLREOLZ ($38 and $18) FC9C: 225 * are used by slot test at S$FBB7. FC9C: 226 * FC9C: 227 CLREOL SEC ;say it is EOL FC9D: 228 DFB $90 ;'BCC' opcode FC9E: 229 CLREOLZ CLC ;say it is EOLZ FC9F: 230 STY BAS2L ;save Y in temp FCAL: 231 LDY #7 ;code=CLREOL FCA3: FD1D 232 BCS GOTOCX2 sdo it FCAS: 233 INY ;code 8=CLREOLZ FCA6: FD1D 234 BNE GOTOCX2 FCA8: 235 FCA8: 236 WAIT SEC senter with count in A FCA9: 237 WAIT2 PHA ;delay is: FCAA: 238 WAIT3 SBC #S$01 FCAC: FCAA 239 BNE WAIT3 313+11*A+5*A*A cycles FCAE: 240 PLA ;@ 1.023 usec per cycle FCAF: 241 SBC #S01 FCBI: FCA9 242 BNE WAIT2 FCB3: 243 RTS FCB4: 244 FCB4: 42 245 NXTA4 INC ASL -INCR 2-BYTE A4 FCB6: 02 FCBA 246 BNE NXTAI ; AND Al 362 Appendix I: Monitor ROM Listings FCB8: 43 247 INC A4H FCBA: 3C 248 NXTA1 LDA ALL ;LNCR 2-BYTE Al. FCBC: 3E 249 CMP A2L ; AND COMPARE TO A2 FCBE: 3D 250 LDA AlH ; (CARRY SET IF >=) FCCO: 3F 251 SBC A2H FCC2; 3C 252 INC ALL FCC4: 02 FCC8 233 BNE RTS4B FCC6: 3D 254 INC AlH FCC8: 255 RTS4B RTS FCC9: 256 FCC9: 07 co 257 HEADR STA SETINTCXROM ;force internal ROM FCCC: 67 C5 258 JSR XHEADER ;swrite header FCCF: c5 FE 259 JMP RETCX1 sforce slots and return FCD2: 260 FCD2: 261 For the disassembler to be able to do I/O to slots, FCD2: 262 it cannot make calls to the 1/0 routines with the FCD2: 263 internal ROM switched in. This stuff switches the FCD2: 264 ROM out for such instances. FCN2: 265 *+FF FCD2 :8D 06 co 266 ERR3 STA SETSLOTCXROM ;force slot ROM FCD5 220 4A F9 267 JSR PRBL2 ;tab to the error FCD8 :A9 DE 268 LDA #SDE ;to primt a caret "“" FCDA: 20 ED FD 269 JSR COUT ;print it FCDD: 20 3A FF 270 JSR BELL sand beep FCEO :4C FQ) FC a JMP GETINSTlL j;and go get next instruction FCE3: 272 * FCE3 :8D 06 CO 273 DISLIN STA SETSLOTCXROM ;force slot ROM FCE6 220 DO F8 274 JSR INSTDSP sdisassemble the instruction FCE9 220 a3 FY 275 JSR PCADJ scalculate new PC FCEC 384 3B 276 STY PCH ;and update PC FCEE: 85 3A 277 STA PCL FCFO: 278 * FCFO: 279 * NOTE: The entry point GETINST1 is hard-coded in FCFO: 280 * BFUNC of the Video firmware. FCFO: 281 * FCFO :A9 Al 282 GETINST1 LDA #SA1 szet mini-prompt FCF2 785 33 283 STA PROMPT FCF4 :20 67 FD 284 JSR GETLNZ 3g0 get a line of input FCF/ :8D 07 CO 285 STA SETINTCXROM ;force internal ROM FCFA: 4C 9C CF 286 JMP DOINST sand return to CX space FCFD: 287 * FCFD: B9 00 02 288 UPMON LDA IN,Y ;get character FDOO :C8 289 INY ;point to next char FDO1 :C9 El 290 CMP #SE] sis it lowercase? FDO3 :90 06 FD OB 291 BCC UPMON2 3;=>nope FDO5 :C9 FB 292 CMP #SFB ;lowercase? FDO7: BO 02 FDOB 293 BCS UPMON2 ;=>nope FDO9 329 DF 294 AND SDF selse upshift FDOB :60 295 UPMON2 RTS FDOC: 296 * FDOC : AO OB 297 RDKEY LDY #SB ;code=RDKEY FDOE :DO 03 FD 13 298 BNE RDKEYO sallow $FDLO entry FD10 :4C 18 FD 299 FD10O JMP RDKEY 1 ;if enter here, do nothing FD13 220 B4 FB 300 RDKEYO JSR GOTOCX ;display cursor Appendix |: Monitor ROM Listings 363 FD16: EA NOP FD1/ :EA NOP FD18: 6C 38 RDKEY 1 JMP (KSWL) ;GO TO USER KEY-IN FDIB: * FDIB: FD1B KEYIN EQU * FDIB: AO 03 LDY #3 - RDKEY/RRA0981 FDID: 4C B4 GOTOCX2 JMP GOTOCX -/RRAOI81 FD20 7EA NOP ; /RRAOI81 FD21: * FD21: RDESC EQU * FD21 :20 OC JSR RDKEY ;sGET A KEY FD24 : AO 01 LDY #1 s CODE=FIXIT FD26 :DO F5 BNE GOTOCX2 ;=Palways FD28: * FD28: * Flag to the video firmware that escapes are allowed. FD28: * This routine is called by RDCHAR which is called by FD28: * GETLN. The high bit of MSLOT is set by all cards FD28: * that use the C800 space. FD28: * FD28: 07 NEWRDKEY LSR MSLOT 3<128 means escape allowed FD2B: FD JMP RDKEY snow read the key FD2E: NOP FD2F: FD2F: FD JSR RDESC ;/RRAO9 81 FD32: FB JSR ESCNEW ;HANDLE ESC FUNCTION. FD35: FD JSR NEWRDKEY ;Flag RDCHAR and read key FD38: CMP #S9B sTESC'? FD3A: FD2F BEQ ESC ; YES, DON'T RETURN. FD3C: RTS FD3D: FD3D: PICKFIX LDY #SF ;code = fixpick FD3F: FB JSR GOTOCX 3do 80 column pick FD42: LDY CH ;restore Y FD44: 02 STA IN,X sand save new character FD47: *#03 AUTOST2 Auto~Start Monitor ROM 27-AUG-84 PAGE 20 FD47: ED FD NOTCR JSR COUT ;echo typed char FD4A: NOP FD4B: NOP FD4C: NOP FD4D: 02 LDA IN,X FD50: CMP #588 ;CHECK FOR EDIT KEYS FD52: FD71 BEQ BCKSPC ; 7— BACKSPACE FD54: CMP #598 FD56: FD62 BEQ CANCEL ; — CONTROL-X FD58: CPX #SF8 FD5A: FD5F BCC NOTCRI ;MARGIN? FDSC: FF JSR BELL ; YES, SOUND BELL FD5F: NOTCRI INX ;ADVANCE INPUT INDEX FD60: FD75 BNE NXTCHAR FD62: * FD62: CANCEL LDA #SDC ; BACKSLASH AFTER CANCELLED LINE FD64: FD JSR COUT FD67: FD GETLNZ JSR CROUT sOUTPUT 'CR! 364 Appendix I: Monitor ROM Listings FD6A: GETLN LDA PROMPT ;OUTPUT PROMPT CHAR FD6C: FD JSR COUT FD6F: LDX #$01 ; INIT INPUT INDEX FD/1: BCKSPC TXA FD72: FD67 BEQ GETLNZ ;WILL BACKSPACE TO 0 FD/4: DEX FD/5: FD NXTCHAR JSR RDCHAR FD/8: CMP #595 ;USE SCREEN CHAR FD7A: FD84 BNE ADDINP ; FOR CONTROL-U FD/C: LDA (BASL),Y ;do 40 column pick FD/E: co BIT RD80VID 380 columns? FD81: FD 3D BMI PICKFIX s=Dyes, fix it FD83: NOP FD84: 02 ADDINP STA IN,X ;ADD TO INPUT BUFFER FD87: CMP #S8D FD89: FD47 BNE NOTCR FD8B: FC JSR CLREOL -CLR TO EOL IF CR FD8E: LDA #S8D FD90: FDED BNE COUT : (ALWAYS) FD92: FD92: LDY AlH sPRINT CR,Al IN HEX FD94: LDX ALL FD96: FD JSR CROUT FD99: F9 JSR PRNTYX FD9C: LDY #500 FD9E: LDA #SAD sPRINT '-' FDAO: FD JMP COUT FDA3: FDA3: XAM8 LDA ALL FDA5S: ORA #$07 ;SET TO FINISH AT FDA/7: STA A2L ; MOD 8=7 FDA9: LDA AlH FDAB: STA A2H FDAD: MO A1LL FDAF 229 AND #$07 FDBI: FDB6 BNE DATAOUT FDB3: FD XAM JSR PRAL FDB6: DATAOUT LDA #SA0 FDB8: FD JSR COUT ;OUTPUT BLANK FDBB: LDA (ALL) ,Y FDBD: FD JSR PRBYTE ;OUTPUT BYTE IN HEX FDCO: FC JSR NXTAI1 FDC3: FDAD BCC MOD8CHK ;NOT DONE YET. GO CHECK MOD 8 FDC5: RTS4C RTS ; DONE. FDC6: * FDC6: XAMPM LSR A ;DETERMINE IF MONITOR MODE IS FDC7: EA FDB3 BCC XAM ; EXAMINE, ADD OR SUBTRACT FDC9: LSR FDCA: LSR FDCB: 3E LDA FDCD: 02 FDD1 BCC FDCF: FF EOR ;FORM 2'S COMPLEMENT FOR SUBTRACT. FDD1: 3C ADD ADC Appendix I: Monitor ROM Listings 365 FDD3 :48 FDD4: A9 BD #S$ BD ;PRINT '=', THEN RESULT FDD6:20 ED FD COUT FDD9 :68 FDDA:48 PRBYTE ;PRINT BYTE AS 2 HEX DIGITS FDDB:4A A ; (DESTROYS A-REG) FDDC:4A A FDDD:4A A FDDE:4A A FDDF:20 ES FD PRHEXZ FNE2 :68 FNE3 :29 OF PRHEX #SOF ;PRINT HEX DIGIT IN A-REG FDE5 :09 BO PRHEXZ #SBO ;LSBITS ONLY. FDE7:C9 BA #SBA FDE9 :90 02 FDED COUT FDEB: 69 06 #$06 FDED: FDED:6C 36 00 (CSWL) ;VECTOR TO USER OUTPUT ROUTINE FDFO: FDFO:48 ;save original character FDF1:C9 AO #S$A0 ;is it a control? FDF3:4C 95 FC DOCOUT1 s=>mask if not; return to COUTZ]I FDF6: FDF6:48 COUTZ ;save original character FDF7 :84 35 COUTZ1 YSAV1 ;save Y FDF9:A8 ;save masked character FDFA:68 ;get original char FDFB:4C 46 FC NEWVW snew entry to vidwait FDFE:EA FDFF:EA FEOO: FEOO :C6 YSAV FEO2:FO FDA3 XAM8 FEO4:CA -BLANK TO MON FEO5:DO FE1D SETMDZ ;AFTER BLANK FEO7:C9 #SBA :DATA STORE MODE? FEO9: DO FDC6 XAMPM ; NO; XAM, ADD, OR SUBTRACT. FEOB:85 STOR MODE *KEEP IN STORE MODE FEOD:A5 A2L FEOF :91 (A3L),Y ;STORE AS LOW BYTE AT (A3) FE11:E6 A3L FE1L3:DO FE17 RTS5 -INCR A3, RETURN. FE1L5:E6 A3H FE17:60 RTS5 FE18: x FE1L8:A4 SETMODE YSAV sSAVE CONVERTED ':', '+! FE1A: B9 01 IN-1,Y '-") 4.1 AS MODE FE1D:85 SETMDZ MODE FELF:60 FE20: * FE20:A2 LT #$01 FE22:B5 LT2 A2L,X sCOPY A2 (2 BYTES) TO FE24:95 AGL,X > A4 AND AS FE26:95 ASL,X 366 Appendix [: Monitor ROM Listings FE28: DEX FE29: FE22 BPL LT2 FE2B: RTS FE2ZC: FE2C: MOVE LDA (AIL),Y ;MOVE (Al) THRU (A2) TO (A4) FE2E: STA (A4L),Y FE30: FC JSR NXTA4 FE33: FE2C BCC MOVE FE35: RTS FE36: FE36: VFY LDA (ALL),Y sVERIFY (Al) THRU (A2) FE38: CMP (A4L),Y ; WITH (A4) FE3A: FE58 BEQ VFYOK FE3C: JSR PRAIL FE3F: LDA (A1L),Y FE41: JSR PRBYTE FE44: LDA #SAO FE46: JSR COUT FE49: LDA #SA8 FE4B: JSR COUT FE4E: LDA (ASL) ,Y FE5O: JSR PRBYTE FE53: LDA #SA9 FE55: JSR COUT FE58: VFYOK JSR NXTA4 FE5B: FE 36 BCC VFY FESD: RTS FE5SE: FE5SE: FE JSR Al PC ;MOVE Al (2 BYTES) TO FE61: LDA #S14 ; PC IF SPEC'D AND FE63: PHA ; DISASSEMBLE 20 INSTRUCTIONS. FE64: F8 JSR INSTDSP FE67: F9 JSR PCADJ ;ADJUST PC AFTER EACH INSTRUCTION. FE6A: STA PCL FEO6C: STY PCH FE6E: PLA FE6F: SEC FE70: SBC #$01 ;NEXT OF 20 INSTRUCTIONS FE72: FE63 BNE LIST2 FE74: RTS FE/5: * FE/5: Al1PC TXA ;IF USER SPECIFIED AN ADDRESS, FE/6: FE/F BEQ Al PCRTS ; COPY IT FROM Al TO PC. FE/78: Al PCLP LDA ALL,X sYEP, SO COPY IT. FE7A: STA PCL,X FE/C: DEX FE7D: FE78 BPL Al PCLP FE/F: AlPCRTS RTS FE80: * FE80: SETINV LDY #S3F ;SET FOR INVERSE VID FE82: FES6 BNE SETIFLG ; VIA COUT1 FE84: SE'TNORM LDY #SFF ;oET FOR NORMAL VID FE86: SETIFLG STY INVFLG FF88: RTS Appendix I: Monitor ROM Listings 367 a15 * 516 SETKBD LDA #$00 -pDO ‘IN#O' INPORT STA A2L ;DO 'IN#AREG' INPRT LDX #KSWL LDY #KEYIN FE9B BNE IOPRT k SETVID LDA #800 -DO 'PR#HO! OUTPORT STA A2L ;DO0 'PRHAREG' OUTPRT LDX #CSWL LDY #COUT1 IOPRT LDA A2L *SET INPUT/OUTPUT VECTORS AND #SOF FEA5 BEQ IOPRT1 ORA #CORRECT CKSUM AT CREATE TIME. XBASIC JMP BASIC ;TO BASIC, COLD START BASCONT JMP BASIC2 ;TO BASIC, WARM START GO JSR AILPC ;ADDR TO PC IF SPECIFIED JSR RESTORE ;RESTORE FAKE REGISTERS JMP (PCL) ;AND GO! REGZ JMP REGDSP ;GO DISPLAY REGISTERS TRACE RTS ;TRACE IS GONE NOP STEPZ RTS ;STEP IS GONE * * Return here from GOTOCX k * NOTE: This address is hard-coded in BFUNC of the * video firmware k FEC5:8D 06 co RETCX1] STA SETSLOTCXROM ;restore bank RETCX2 RTS ;simply return NOP * USR JMP USRADR ; JUMP TO CONTROL-Y VECTOR IN RAM k WRITE LDA #$40 WRT2 STA SETINTCXROM ;set internal ROM JSR WRITE2 swrite to tape BEQ RD2 ;=Dalways set slots, beep * SEARCH is called with a Monitor command of the form * HHLLyes, only look for low byte FEDD: CMP (AIL),Y ;check high byte first FEDF: FEEB BNE SRCH2 ;=>no match, try next byte FEE]: SRCH1 DEY smatch, mow check low byte FEE2: LDA ASL ;get low byte FEE4: CMP (A1L),Y sdoes it match? FEFR6: FEEB BNE SRCH2 ;=>no match, try next byte FEE8:: JSR PRA] ;bytes match, print address FEEB: JSR NXTA1 sincrement address FEEE: FED/ BCC SEARCH sset Y back to l FEFO: RTS FEF]: FEF]: LDY #$D ;dispatch mini-assembler call to FEF3: JSR GOTOCX ;get internal ROM switched in FEF6: FEF6: JSR BL1 ;HANDLE CR AS BLANK FEF9: PLA THEN POP STACK FEFA: PLA AND RETURN TO MON FEFB: BNE MONZ ; (ALWAYS) FEFD: FEFD: STA SETINTCXROM ;set internal ROM FFOO: JSR XREAD ;do tape read FFO3: STA SETSLOTCXROM ;restore slot CX FFO6: BEQ BELL sread (write) ok, beep FFO8: BNE PRERR serror, print message FFOA: FFOA: TITLE ASC "Apple //e" FF13: * FF13: * NNBL gets the next non-blank for the mini-assembler FF13: * FF13: NNBL JSR UPMON ;get char, upshift, INY FF16: CMP #S$A0 sis it blank? FF18: BEQ NNBL ;syes, keep looking FFIA: RTS FFIB: * FFIB: LOOKASC BCS DIG ;it was a digit FF1D: CMP #$AO scheck for quote (') FFIF: BNE RTS6 snope, return char FF21: LDA $200,Y ;else get mext char FF24: LDX #7 ;for shifting asc into A2L and A2H FF26: CMP #$8D swas it CR? FF28: BEQ GETNUM syes, go handle CR FF2A: INY sadvance index FF2B: BNE NXTBIT 3=>(always) into A2L and A2H FF2D: FF2D: PRERR LDA #SC5 ;PRINT 'ERR', THEN FALL INTO FF2F: JSR COUT FWEEPER. FF32: LDA #$D2 FF34: JSR COUT Appendix I: Monitor ROM Listings 369 FF37:20 ED FD 623 JSR COUT FF3A: 624 * FF3A:A9 87 625 BELL LDA #587 ;sMAKE A JOYFUL NOISE, THEN RETURN. FF3C:4C ED FD 626 JMP COUT FF3F: 627 * FF3F:A5 48 628 RESTORE LDA STATUS ;sRESTORE 6502 REGISTER CONTENTS FF41:48 629 PHA ; USED BY DEBUG SOFTWARE FF42:A5 45 630 LDA ASH FF44:A6 46 631 RESTRI1 LDX XREG FF46:A4 47 632 LDY YREG FF48:28 633 PLP FF49 360 634 RTS6 RTS FF4A: 635 * FF4A:85 45 636 SAVE STA ASH ;SAVE 6502 REGISTER CONTENTS FF4C:86 46 637 SAV1 STX XREG ; FOR DEBUG SOFTWARE FF4E:84 47 638 STY YREG FF50:08 639 PHP FF51:68 640 PLA FF52:85 48 641 STA STATUS FF54:BA 642 TSX FF55:86 49 643 STX SPNT FF57:D8 644 CLD FF58:60 645 RTS FF59: 646 * FF59:20 84 FE 647 OLDRST JSR SETNORM ;sSET SCREEN MODE FF5C:20 2F FB 648 JSR INIT ; AND LNIT KBD/SCREEN FF5F:20 93 FE 649 JSR SETVID ; AS I/O DEVS. FF62:20 89 FE 650 JSR SETKBD FF65: 651 * FF65:D8 652 MON CLD ;sMUST SET HEX MODE! FF66:20 3A FF 653 JSR BELL ; FWEEPER. FF69:A9 AA 654 MONZ LDA #SAA >'*' PROMPT FOR MONITOR FF6B:85 33 655 STA PROMPT FF6D:20 67 FD 656 JSR GETLNZ ;READ A LINE OF INPUT FF70:20 C7 FF 657 JSR ZMODE ;CLEAR MONITOR MODE, SCAN IDX FF/73:20 A/7 FF 658 NXTITM JSR GETNUM ;GET LTEM, NON-HEX FF76:84 34 659 STY YSAV ; CHAR IN A-REG. FF78:A0 17 660 LDY #$17 ; X-REG=0 IF NO HEX INPUT FF/7A:88 661 CHRSRCH DEY FF/7B:30 E8 FF65 662 BMI MON sCOMMAND NOT FOUND, BEEP & TRY AGAIN. FF/D:D9 CC FF 663 CMP CHRTBL,Y ;FIND COMMAND CHAR IN TABLE FF80:D0O F8 FF7A 664 BNE CHRSRCH ;NOT THIS TIME FF82:20 BE FF 665 JSR TOSUB sGOT LT! CALL CORRESPONDING SUBROUTINE FF85:A4 34 666 LDY YSAV ;PROCESS NEXT ENTRY ON HIS LINE FF87:4C 73 FF 667 JMP NXTITM FF8A: 668 * FF8A:A2 03 669 DIG LDX #$03 FF8C:0A 670 ASL A FF8D:0A 671 ASL A ;GOT HEX DIGIT, FF8E:0A 672 ASL A ; SHIFT INTO A2 FF8F:0A 673 ASL A FF90:0A 674 NXTBIT ASL A FF91:26 3E 675 ROL A2L FF93:26 3F 676 ROL A2H 370 Appendix I: Monitor ROM Listings FF95: ;LEAVE X=SFF IF DIG FF96: FE90 NXTBIT FF98: NXTBAS MODE FF9A: FFA2 NXTBS2 ;IF MODE IS ZERO, FF9IC: A2H,X ; THEN COPY A2 TO Al AND A3 FF9E: AlH,X FFAO: A3H,X FFA2: FFA3: FF98 NXTBAS FFAS: FF AD NXTCHR FFA/: FFA/7: #$00 sCLEAR A2 FFA9: A2L FFAB: A2H FFAD: FC NXTCHR UPMON ;get char, upshift, INY FFBO: ; INY now done in UPMON FFB1: #$BO FFB3: #SOA FFBS: FF8A DIG >BR IF HEX DIGIT FFB/: #$88 FFB9: #SFA FFBB: FF LOOKASC ;scheck for ASCII input FFBE: FFBE: #BASCONT-1 ;*C (BASIC warm start) FFE4: 737 DFB >USR-1 a 4 (not used) FFE5: 738 DFB >REGZ-1 ;*E (open and display registers) FFE6: 739 DFB >MINI-1 ;mini assembler FFE/: 740 DFB >VFY-1 3V (memory verify) FFE8: 741 DFB DINPRT-1 3K CIN#SLOT) FFE9: 742 DFB >SEARCH-1 ;search for pattern FFEA: 743 DFB >OUTPRT-1 ;7P (PR#SLOT) FFEB: 744 DFB >XBASIC-1 ;*B (BASIC cold start) FFEC: 745 DFB >SETMODE-1 ;'-' (subtraction) FFED: 746 DFB >SETMODE-1 ;'+' (addition) FFEE: 747 DFB >MOVE-1 3M (memory move) FFEF: 748 DFB >LT-1 3'<' (delim for move,vfy) FFFO: 749 DFB >SETNORM-1 ;N (set normal video) FFF1: 750 DFB >SETINV-1 ;I (set inverse video) FFF2: 751 DFB >LIST-1 -1, (disassemble 20 instrs) FFF3: 752 DFB >WRITE-1 ;W (write to tape) FFF4: 753 DFB >GO-1 3G (execute program) FFFS: 754 DFB >READ-1 ;R (read from tape) FFF6: 755 DFB >SETMODE-1 ;':' (memory fill) FFF7: 756 DFB >SETMODE-1 ;'.' (address delimiter) FFF8: 757 DFB >CRMON-1 ;'CR' (end of input) FFF9: 758 DFB >BLANK-1 ;BLANK FFFA: 759 * FFFA: 03 760 DW NMI ; NON-MASKABLE INTERRUPT VECTOR FFFC: FA 761 DW RESET ;RESET VECTOR FFFE: C3 762 DW IRQ ; INTERRUPT REQUEST VECTOR 0000: INCLUDE MINI 0000: * 0000: * Apple //e Mini Assembler 0000: x 0000: * Got mnemonic, check address mode 0000: C4C8: C4C8 ORG C30ORG+$1C8 C4C8: C4C8: AMOD1 JSR NNBL ;get next non-blank C4CB: STY YSAV ;save Y C4CD: CMP CHARI ,X C4D0: BNE AMOD2 C4D2: JSR NNBL ;get next non-blank C4D5: CMP CHAR2,X C4D8: BEQ AMOD3 C4DA: LDA CHAR2,X ;done yet? C4DD: BEQ AMOD4 C4DF: CMP #SA4 sif "S" then done C4El: BEQ AMOD4 C4E3: oo on ee cee eel _ LDY YSAV srestore Y C4E5: 20 AMOD2 CLC C4E6: 21 AMOD4 DEY 312 Appendix I: Monitor ROM Listings C4E7: AMOD3 ROL A5L sshift bit into format C4E9: #$03 C4EB: C4FA AMOD6 C4ED: FF GETNUM C4F0: A2H ;get high byte of address C4F2: C4F5 AMOD5 => C4F4: C4F5: YSAV1 C4F7: #$03 C4F9: C4FA: AlH C4FC: C4FD: C4c8 AMOD1 C4FF: C500: CF3A: CF3A ORG C80RG+$73A CF3A: * CF3A: * Calculate offset byte for relative addresses CF3A: * CF3A: REL SBC #$81 ;calc relative address CF3C: LSR A CF3D: CF53 BNE GOERR ;bad branch CF3F: LDY A2H CF41: LDX A2L CF43: CE46 BNE RELI] CF45: DEY ;point to offset CF46: RELI DEX ;displacement - 1 CF47: TXA CF48: CLC CF49: SBC PCL ssubtract current PCL CF4B: STA A2L sand save as displacement CF4D: CF50 BPL REL2 ;check page CF4F: INY CF50: REL2 TYA sget page CF51: SBC PCH ;check page CF53: CF95 GOERR BNE MINIERR sdisplay error CF55: x CF55: * Move instruction to memory CF55: * CF55: MOVINST LDY LENGTH ;get instruction length CF57% 00 MOV1 LDA Al1H,Y ;get a byte CF5SA: STA CPCL);Y 3;and move it CFSC: DEY CF5D: CF5/ BPL MOVI1 CF5F: CFF: * Display instruction CF5F: CF5F: 48 F9 JSR PRBLNK sprint blanks to make ProDOS work CF62: 1A FC JSR UP ;move up 2 lines CF65% 1A FC JSR UP CF68: E3 FC JMP DISLIN ;disassemble it, =>DOINST CF6B: CFO6B: * Compare disassembly of all known opcodes with CF6B: * the one typed in until a match is found Appendix J: Monitor ROM Listings 373 CF6B: 76 * CF6B: 3D 77 GETOP LDA AlH ;get opcode CF6D: 8E F8 78 JSR INSDS2 sdetermine mnemonic index CF/70: 79 TAX 3X = index CF71: FA 80 LDA MNEMR,X ;get right half of index CF74: 81 CMP A4L sdoes it match entry? CF/6: 13 CF8B 82 BNE NXTOP ;=>try next opcode CF78: F9 83 LDA MNEML ,X sget left half of index CF7B: 84 CMP A4H ;does it match entry? CF/7D: OC CF8B 85 BNE NXTOP ;=>no, try next opcode CF/F: 86 LDA ASL ;found opcode, check address mode CF81: 87 LDY FORMAT sget addr. mode format for that opcode CF83: 88 CPY #S9D sis it relative? CF85: CF3A 89 BEQ REL s=>yes, calc relative address CF87: 90 CMP FORMAT ;does mode match? CF89: CF55 91 BEQ MOVINST ;=>yes, move instruction to memory CF8B: 92 NXTOP DEC AlH ;@lse try next opcode CF8D: CF6B 93 BNE GETOP 3=>go try it CF8F: 94 INC ASL ;else try next format CF91: 95 DEC YSAVI CF93: CF6B 96 BEQ GETOP 3=>go try next format CF95: 97 CF95: 98 Point to the error with a caret, beep, and fall CF95: 99 *+& into the mini-assembler. CF95: 100 & CF95: 34 101 MINIERR LDY YSAV ;get position CF97 298 102 ERR2 TYA CF98: 103 TAX CF99 :4C D2 FC 104 JMP ERR3 sdisplay error, =>DOINST CFIC: 105 * CFIC: 106 * Read a line of input. If prefaced with " ", decode CFIC: 107 * mnemonic. If 'S'" do monitor command. Otherwise parse CF9C: 108 * hex address before decoding mnemonic. CFIC: 109 * CF9C :20 C7 FF 110 DOINST JSR ZMODE sclear mode CF9F: AD 00 02 111 LDA $200 sget first char in line CFA2 :C9 AO 112 CMP #SAO ;if blank, CFA4: FO 12 CFB8 113 BEQ DOLIN ;=>go attempt disassembly CFA6 2C9 8D 114 CMP #$ 8D sis it return? CFA8: DO 01 CFAB 115 BNE GETI1 3=>no, continue CFAA :60 116 RTS selse return to Monitor CFAB: 117 * CFAB: 20 A7 FF 118 GETI1 JSR GETNUM ;parse hexadecimal input CFAE :C9 93 119 CMP #$93 slook for "ADDR:" CFBO :DO ES CF97 120 GOERR2 BNE ERR2 sno ":", display error CFB2 :8A 121 TXA ;X nonzero if address entered CFB3: FO E2 CF97 122 BEQ ERR2 sno "ADDR", display error CFB5S: 123 CFB5: 20 78 FE 124 JSR Al PCLP smove address to PC CFB8: A9 03 125 LDA #$03 ;get starting opcode CFBA: 85 3D 126 STA AlH ;and save CFBC: 20 13 FF ew JSR NNBL ;get next non-blank CFBF: OA 128 ASL A svalidate entry CFCO :E9 BE 129 SBC #SBE 374 Appendix I: Monitor ROM Listings CFC2: C2 130 CMP #$C2 CFC4: Dl CF9/ 131 BCC ERR2 3;=>flag bad mnemonic CrC6: 132 * CFC6: 133 * Form mnemonic for later comparison CFC6: 134 * CFC6: 135 ASL CFC?7: 136 ASL CFC8: 137 LDX CFCA: 138 NXTMN ASL CFCB: 139 ROL CFCD: 140 ROL CFCF: 141 DEX CFDO: CFCA 142 BPL CFD2: 143 DEC ;decrement mnemonic count CFD4: CFCA 144 BEQ CFD6: CF BC 145 BPL NXTCH CFD8: 146 #$5 ;index into address mode tables CFDA: C8 C4 147 AMOD1 ;do this elsewhere CFDD: 148 A5L ;get format CFDF: 149 A CFEO: 150 A CFE1: 151 YSAV1 CFE3: 152 #$20 CFE5: CFED 153 AMOD/ CFE/7: 154 YSAV1 ;get our format CFE9: CFED 155 AMOD7 CFEB: 156 #$80 CFED: 157 AMOD/7 ASL ;update format CFEF: 158 YSAV ;update position CFF1: 159 $0200,Y ;get next character CFF4: 160 #SBB sis it a ‘':'"? CFF6: 161 AMOD8 ;=>yes, skip comment CFF8: 162 #$8D ;is it carriage return CFFA: 163 GOERR2 CFFC: 164 AMOD8 GETOP ;get next opcode CFFF: 165 * CFFF: 166 $00 sbyte for making CTOD checksum ok Appendix I: Monitor ROM Listings 375 Glossary accumulator: The register in the range of values. For example, a Apple IIe: A transportable 65C02 microprocessor where most conventional 12-hour clock face is personal computer in the Apple II computations are performed. an analog device that represents the family, with a disk drive and time of day in terms of the angles of 80-column capability built in. ACIA: Acronym for Asychronous the clock’s hands. Compare digital. Communications Interface Apple IIe: A personal computer in Adapter. The ACIA is a chip that analog data: Data in the form of the Apple II family. converts data from parallel to serial continuously variable physical Apple IIe 80-Column Text Card: form and vice versa. Its internal quantities. Compare digital A peripheral card that plugs into the registers control and keep track of data. Apple Ile’s auxiliary slot and the sending and receiving of data. analog signal: A signal that varies converts the computer’s display of Firmware and software set and continuously over time. text from 40-column width to change the status of these internal 80-column width. registers. analog-to-digital converter: A device that converts quantities from Apple IIe Extended 80-Column acronym: A word formed from the analog to digital form. For example, Text Card: A peripheral card that initial letters of a name or phrase, hand controls used on Apple II plugs into the Apple Ile’s auxiliary such as ROM, from read-only family computers convert the slot and converts the computer's memory. position of the control dial (an display of text from 40-column address: A number that specifies a analog quantity )into a discrete width to 80-column width while single byte of memory. Addresses number (a digital quantity) that extending its memory capacity by can be given as decimal integers or changes abruptly even when the 64K bytes. as hexadecimal integers. A 64K dial is turned smoothly. Apple II Pascal: A software system has addresses ranging from AND: A logical operator that system that lets you create and 0 to 65535 (in decimal) or from produces a true result if both of its execute programs written in the $0000 to $FFFF (iin hexadecimal). operands are true, a false result if Pascal programming language, algorithm: A step-by-step either or both of its operands are adapted by Apple Computer from procedure for solving a problem or false; compare OR, exclusive OR, the UCSD (University of California, accomplishing a task. NOT. San Diego) Pascal Operating System and sold for use with the Apple II analog: Represented in terms of a ANSI: Acronym for American family of computers. physical quantity that can vary National Standards /nstitute, smoothly and continuously over a which sets standards for many fields and is the most common standard for terminals. Glossary 377 Applesoft BASIC: An extended to 127 stand for text characters— auxiliary slot: The special version of the BASIC programming including the letters of the alphabet, expansion slot inside the Apple Ile language used with the Apple II the digits 0 through 9, punctuation used for the Apple 80-Column Text family of computers. An interpreter marks, special characters, and Card or Extended 80-Column Text for creating and executing programs control characters—used for Card. in Applesoft is built into the representing text inside a computer base address: In indexed computer’s firmware. Compare and for transmitting text between addressing, the fixed component of Integer BASIC. computers or between a computer an address. and a peripheral device. application program: A program BASIC: Acronym for Beginner’s that puts the resources and assembler: A language translator All-purpose Symbolic Instruction capabilities of the computer to use that converts a program written in Code. A high-level programming for some specific purpose or task, assembly language into an language designed to be easy to such as word processing, data base equivalent program in machine learn and use. Two versions of management, or graphics. Compare language. BASIC are available from Apple system program. assembly language: A low-level Computer for use with all Apple II argument: The value on which a programming language in which family systems: Applesoft (built into function operates. individual machine-language firmware) and Integer BASIC instructions are written ina (provided on the ProDOS User's arithmetic expression: A symbolic form more easily Disk). combination of numbers and understood by a human programmer arithmetic operators (such as baud: Unit of signaling speed taken than machine language itself. 3+ 5) that indicates some operation from the name Baudot. The speed in to be carried out. asserted: Made true (positive in bauds is equal to the num ber of positive-true logic; negative in discrete conditions or sigmal events arithmetic operator: An negative-true logic). per second regardless of tIhe operator, such as +, that combines information content of those signals. numeric values to produce a asynchronous transmission: Often equated (though not numeric result. Compare Not synchronized by or with a precisely )with bits per second. relational operator, logical clocking signal. Transmission in Compare bit rate. operator. which each information character is individually synchronized, usually ASCII: Acronym for American by the use of start and stop bits. The Standard Code for Information gap between each character isn't Interchange, pronounced ASK ee. necessarily fixed. Compare A code in which the numbers from 0 synchronous transmission. 378 Glossary binary: The representation of body: The statements or buffer: A memory area that holds numbers in terms of powers of two, instructions that make up a part of a information until it can be using the two digits 0 and 1. program, such as a loop ora processed. Commonly used in computers subroutine. bug: An error in a program that because the values 0 and 1 can boot: To start up a computer by causes it not to work as intended. easily be represented in physical loading a program into memory form in a variety of ways, such as bus: A group of wires that transmit from an external storage medium the presence or absence of current, related information from one part of such as a disk. Often accomplished positive or negative voltage, or a a computer system to another. by first loading a small program white or black dot on the display whose purpose is to read the larger byte: A sequence of eight bits that screen. A single binary digit—a 0 or program into memory. The program represents an instruction, a letter, a a 1—is called a bit. is said to pull ztselfup by its own number, or a punctuation mark. binary digit: The smallest unit of bootstraps—hence the term cable: A group of wires used to information in the binary number bootstrapping or booting. carry information between two system. Also called a bit. boot disk: See startup disk. devices. How many wires are used binary operator: An operator that varies with the type of connection. bootstrap: See boot. combines two operands to produce a call: To request the execution of a result; for example, + is a binary bps: See bit rate. subroutine or function. arithmetic operator, < 1s a binary branch: To send program relational operator, and OF is a card: See peripheral card. execution to a line or statement binary logical operator. Compare other than the next in sequence. carriage return: An ASCII unary operator. character (decimal 13) that BREAK: A SPACE (0) signal, sent bit: The smallest item of useful ordinarily causes a printer or over a communication line, of long information a computer can handle. display device to place the enough duration to interrupt the Usually represented as a 1 or a0. subsequent character on the left sender. This signal is often used to Eight bits equal one byte. margin. end a session with a time-sharing bit rate: The speed at which bits service. carrier: The background signal on are transmitted, usually expressed a communication channel that is BRK: An instruction that causes as bps or bits per second. modified to carry the information. the 65C02 microprocessor to halt. Compare baud. Under RS282-C rules, the carrier signal is equivalent to a continuous board: See printed-circuit MARK (1) signal; a transition to 0 board. then represents a start bit. Glossary 379 carry flag: A status bit in the code: (1) A number or symbol used computer: An electronic device 65C02 microprocessor, used to hold to represent some piece of that performs predefined the high-order bit (the carry bit) in information in a compact or easily (programmed) computations at high addition and subtraction. processed form. (2) The statements speed and with great accuracy. A or instructions making up a machine that is used to store, central processing unit: See program. transfer, and transform information. processor. cold start: The process of starting computer language: See character: Any symbol that has a up the Apple II when the power is programming language. widely understood meaning. Some first turned on (or as if the power characters—such as letters, computer system: A computer had just been turned on ) by loading numbers, and punctuation—can be and its associated hardware, the operating system into main displayed on the monitor screen and firmware, and software. memory, then loading and running a printed on a printer. Others are used program. conditional branch: A branch to control various functions of the that depends on the truth of a computer. See control character. column: A vertical arrangement of condition or the value of an graphics points or character spaces character code: A number used to expression. Compare on the monitor screen. represent a text character for unconditional branch. processing by a computer system. command: A word or character configuration: The hardware and that causes the computer to do character set: The entire set of software arrangement of a system. something. characters that can be either shown connector: A physical device such on a monitor or used to code compiler: A language translator as a plug, socket, or jack, used to computer instruction. In a printer, that converts a program written in a connect two devices to one another. the entire set of characters that the high-level programming language printer is capable of printing. into an equivalent program in some console: The Apple Ile’ s video lower-level language (Such as display and keyboard together make circuit board: A collection of machine language) for later up the console. This is the part of integrated circuits (chips) on a execution. Compare interpreter. the Apple Ile you communicate with board. directly. composite video: A video signal Clear To Send: An RS232-C signal that includes both display constant: A symbol in a program from a DCE to a DTE that is information and the synchronization that represents a fixed, unchanging normally kept false until the DCE (and other) signals needed to value. Compare variable. makes it true, indicating that all display it. circuits are ready to transfer data out. 380 Glossary (CONTROL|}: A key that when controller card: A peripheral card data bits: The computer sends pressed in conjunction with another that connects a device such as a and receives information as a string key makes that other key behave printer or disk drive to an Apple IIe of bits. These are called data bits. differently. and controls the operation of the Data Carrier Detect: An RS232-C device. [CONTROL }{RESET }: This signal from a DCE (such as a combination of keystrokes usually copy-protect: To prevent someone modem) to a DTE (such as an causes an Applesoft program or from duplicating the contents of a Apple Ile) indicating that a command to stop immediately. If a disk. Compare write-protect. communication connection has program disables the been established. CPU: Abbreviation for central feature, you processing unit. See processor. Data Communication need to turn the computer off to get Equipment: As defined by the the program to stop. current input device: The source, RS232-C standard, any device that such as the keyboard or a modem, control character: A non-printing transmits or receives information. from which a program is currently character that controls or modifies Usually this is a modem. However, receiving its input. the way information is printed or when a modem eliminator is used, displayed. Control characters have current output device: The the Apple Ile itself looks like a DCE ASCII values between 0 and 31, and destination, such as the display to the other device, and the other are typed from a keyboard by screen or a printer, to which a device looks like a DCE to the holding down while program is currently sending its Apple Ile. pressing some other key. For output. data set: A device that performs example, the character Control-M cursor: A symbol displayed on the the modulation/demodulation (ASCII code 13) means “return to screen that marks where the user’s control functions necessary to the beginning of the line” and is next action will take effect or where provide the compatibility between equivalent to pressing (RETURN}. the next character typed from the business machines and control code: One or more keyboard will appear. communications facilities. See non-printing characters included in modem. DAC: See digital-to-analog a text file whose function Is to converter. Data Set Ready: An RS232-C change the way a printer prints the signal from a DCE to a DTE text. See control character. data: Information, especially raw indicating that the DCE has or unprocessed information, used or established a connection. operated on by a program. Glossary 381 Data Terminal Equipment: As deferred execution: The saving device: A piece of computer defined by the RS2382-C standard, of an instruction in a program for hardware—such as a disk drive, a any device that generates or absorbs execution at a later time as part of a printer, or a monitor—other than information, thus acting as a complete program; occurs when the the computer itself. Devices may be terminus of a communication statement is typed with a line built in or peripheral. connection. number. Compare immediate execution. device driver: A program that Data Terminal Ready: An manages the transfer of information RS232-C signal from a DTE to a DCE (DELETE|: A key on the upper-right between the computer and a indicating a readiness to transmit or corner of the Apple Ile and IIc peripheral device. receive data. keyboards that, when pressed, device handler: See device usually erases the character DCD: See Data Carrier Detect. driver. immediately preceding the cursor. DCE: See Data Communication digit: (1) One of the char acters 0 delimiter: A character that is used Equipment. through 9, used to express numbers to mark the beginning or end of a in decimal form. (2) One of the debug: To locate and correct an sequence of characters, and which characters used to express numbers error or the cause of a problem or therefore is not considered part of in some other form, such as 0 and 1 malfunction in a computer system. the sequence itself. For example, in binary or 0 through 9 and A Typically used to refer to Applesoft uses the double quotation through F in hexadecimal. software-related problems. Compare mark () as a delimiter for string troubleshoot. constants: the string DOG consists digital: Represented in a discrete of the three characters D, O, and G, (noncontinuous) form, such as decimal: The common form of and does not include the quotation numerical digits. For exarnple, number representation used in marks. In written English, the space contemporary digital clocks display everyday life, in which numbers are character is used as a delimiter the time in numerical forrn (such as expressed in terms of powers of ten, between words. 2:57) instead of using the positions using the ten digits 0 through 9. of a pair of hands on a clock face. demodulate: To recover the default: A value, action, or setting Compare analog. information being transmitted by a that is assumed or set in the modulated signal; for example, a digital data: Data that can be absence of explicit instructions conventional radio receiver represented by digits—that is, data otherwise. demodulates an incoming broadcast that are discrete rather than signal to convert it into sound continuously variable. Compare emitted by a speaker. analog data. 382 Glossary digital-to-analo g converter: A disk envelope: A removable display: v. To exhibit information device that converts quantities from protective paper sleeve used when visually. 7. (1) Information digital to analog form. handling or storing a disk. It must be exhibited visually, especially on the removed before inserting the disk in screen of a display device, such as a DIP: See dual in-line package. a disk drive. Compare disk jacket. video monitor. (2) A display device. DIP switch: A bank of tiny diskette: A term sometimes used display color: The color currently switches, each of which can be for the small (54-inch), flexible being used to draw high-resolution moved manually one way or the disks on which information is or low-resolution graphics on the other to represent one of two values stored. display screen. (usually on and off). disk jacket: A permanent display device: A device that disassembler: A language protective covering for a disk, exhibits information visually, such translator that converts a usually made of black paper or as a television set or video monitor. machine-language program into an plastic. The disk is never removed equivalent prograrn in assembly DOS 3.2: Anearly Apple II from the jacket, even when inserted language, more easily understood by operating system. DOS stands for in a disk drive. Compare disk a human programrner. The opposite Disk Operating System. 3.2 is the envelope. of an assembler. version number. disk operating system: One of disk: An information-storage DOS 3.3: One of the operating several optional software systems medium consisting of a flat, systems used by the Apple II family for the Apple II family of computers circular, magnetic surface on which of computers. DOS stands for Disk that enables the computer to control information can be recorded in the Overating System. 3.3 is the and communicate with one or more form of small magnetized spots, in a version number. disk drives. manner similar to the way sounds drive: See disk drive. are recorded on tape. Disk II drive: One of a number of types of disk drive made and sold by DSR: See Data Set Ready. disk controller card: A circuit Apple Computer for use with the board that provides the connection DTE: See Data Terminal Apple II family of computers. It uses between one or two disk drives and Equipment. 54-inch flexible (floppy) disks. the Apple Ile. DTR: See Data Terminal Ready. disk-resident: Stored or held disk drive: A device that reads permanently on a disk. information from disks into the memory of the com puter and writes information from the memory of the computer onto a disk. Glossary 383 dual in-line package: An emulate: To behave in an identical escape mode: A state of the integrated circuit packaged in a way. The Apple II 2780 /3780 computer, entered by press ing narrow rectangular box with a row Protocol Emulator and the Apple I] [Esc], in which certain keys on the of metal pins along each side. Often 3270 BSC Protocol Emulator, for keyboard take on special meanings referred to as a DIP switch. example, allow your Apple II, Il for positioning the cursor and Plus, or Ile, together with the Apple controlling the display of text on the Dvorak keyboard: An alternate Communications Protocol Card screen. keyboard layout, also known as the (ACPC), to emulate the operations simplified keyboard. escape sequence: A sequence of of IBM 3278 and 3277 terminals and keystrokes, beginning with [ESC], effective address: In 3274 and 3271 control units. used for positioning the cursor and machine-language programming, end-of-command mark: A controlling the display of text on the the address of the memory location punctuation mark used to separate screen. on which a particular instruction commands sent to a peripheral actually operates, which may be even parity: Use of an extra bit set device such as a printer or plotter. arrived at by indexed addressing or to 0 or 1 as necessary to make the Also called a command some other addressing method. total number of 1 bits (among the terminator. data bits plus the parity bit) an even 80-column text card: A circuit end-of-line character: Any number. board that converts the computer's character that tells the printer that display of text from 40 columns to even/odd parity check: A check the preceding text constitutes a full 80 columns. that tests whether the nurmber of line and may now be printed. digits in a group of binary digits is 80/40 column switch: A switch, error code: A number or other even (even parity check) or odd either hardware or software, that symbol representing a type of error. (odd parity check). controls the number of horizontal columns or characters across your error message: A message exclusive OR: A logical operator screen. A television can display a displayed or printed to notify the that produces a true result if one of maximum of 40 characters across, user of an error or problem in the its operands is true and the other while a video monitor can display 80 execution of a program. false, a false result if its operands characters across the screen. are both true or both false. Compare Escape character: An ASCII OR, AND, and NOT. embedded: Contained within. For character that allows you to perform example, the string special functions when used in execute: To perform the actions HUMPTY DUMPTY is Said to contain combination keypresses. specified by a program command or an embedded space. sequence of commands. 384 Glossary expansion slot: A connector lie at the right end of the number so form feed: An ASCII character inside the Apple Ife in which a that the number is interpreted as an (decimal 12) that causes a printer or peripheral card can be installed. integer. Compare floating-point. other paper-handling device to sometimes called a peripheral advance to the top of the next page. flag: A variable whose contents slot. (usually 1 or 0, standing for trwe or FORTRAN: A contraction of the expression: A formula ina false) indicate whether some phrase FORmula TRANslator. A program that describes a calculation condition holds or whether some widely used, high-level to be performed. event has occurred. Used to control programming language especially the program’s actions at some later suitable for applications requiring FIFO: First in, first out. time. extensive numerical calculations, file: An ordered collection of such as in mathematics, flexible disk: A disk made of information stored as a named unit engineering, and the sciences. A flexible plastic. Often called a on a peripheral storage medium version called Apple II Fortran is floppy disk. Compare rigid disk. such as a disk. sold by Apple Computer for use with floating-point: A method of the Apple II Pascal Operating firmware: Software stored representing numbers inside the System. permanently in hardware: programs computer in which the decimal in read-only memory (ROM). Such framing error: In serial data point (more correctly, the binary programs (for example, the transfer, absence of the expected point) is permitted to float to Applesoft Interpreter and the stop bit(s) at the end of a received different positions within the Monitor program) are built into the character. number. Some of the bits within the computer at the factory. They can number itself are used to keep track frequency: The number of be executed at any time but cannot of the point’s position. Compare complete cycles transmitted per be modified or erased from main fixed-point. second. Usually expressed in hertz memory. Compare hardware, (cycles per second), kilohertz software. floppy disk: See flexible disk. (kilocycles per second), or fixed-point: A method of format: 7. The form in which megahertz (megahertz per second). representing numbers inside the information is organized or full duplex: Capable of computer in which the decimal presented. v. (1) To specify or simultaneous, two-way point (more correctly, the binary control the format of information. communication. Compare half point) is considered to occur at a (2) To prepare a blank disk to duplex. fixed position within the number. receive information by dividing its Typically, the point is considered to surface into tracks and sectors. Also initialize. Glossary 380 function: A pre-programmed hand controls: Optional sequence of four binary digits, or calculation that can be carried out peripheral devices, with rotating bits. Hexadecimal numbers are on request from any point in a dial and pushbuttons, that can be preceded by a dollar sign C$). program. An instruction that connected to the Apple Ile hand high ASCII characters: ASCII converts data from one form to control connector. Typically used to characters with decimal walues of another. control game-playing programs, but 128 to 255. Called hagh ASCII can be used in more serious GAME I/O connector: A special because their high bit (first binary applications as well. 16-pin connector inside the digit) is set to 1 (for ov) rather than Apple Ile originally designed for hang: For a program or system to 0 (for off). connecting hand controls to the spin its wheels indefinitely, high-level language: A computer, but also used for performing no useful work. programming language that is connecting some other peripheral hardware: The physical relatively easy for humans to devices. Compare hand-control machinery that makes up a understand. A single statement in a connector. computer system. Compare high-level language typically graphics: (1) Information firmware, software. corresponds to several instructions presented in the form of pictures or of machine language. High-level hertz: The unit of frequency of images. (2) The display of pictures languages available for the Apple Ile vibration or oscillation, also called or images on a computer’s video include BASIC, Pascal, Logo, and cycles per second. Named for the display screen. Compare text. PILOT. physicist Heinrich Hertz and half duplex: Capable of abbreviated Hz. The 65C02 high-order byte: The more communication in only one microprocessor used in the Apple Ile significant half of a memory address direction at a time. Compare full operates at a clock frequency of 1 or other two-byte quantity. In the duplex. million hertz, or 1 megahertz (MHz). 65C02 microprocessor, the low-order byte of an address is usually stored hand-control connector: A 9-pin hexadecimal: The representation first, and the high-order byte connector on the back panel of the of numbers in terms of powers of second. Apple Ile, used for connecting hand sixteen, using the ten digits 0 controls to the computer. Compare through 9 and the six letters A high-resolution graplnics: The GAME I/0 connector. through F. Hexadecimal numbers display of graphics on a display are easier for humans to read and screen as a $i1x-color array of points, understand than binary numbers, 280 columns wide and 192 rows but can be converted easily and high. When the text window is in directly to binary form. Each use, the visible high-resolution hexadecimal digit corresponds to a graphics display is 280 by 160 points. 386 Glossary hold time: In computer circuits, indexed address, contained in an input/output: Abbreviated I/O. the amount of time a signal must index register and added to the base The means by which information is remain valid after some related address to form the effective transferred between the computer signal has been turned off. Compare address. and its peripheral devices. setup time. indexed addressing: A method of input routine: A Hz: See hertz. specifying memory addresses used machine-language routine that in machine-language programming. performs the reading of characters. IC: See integrated circuit. The standard input routine reads index register: A register in a immediate execution: The characters from the keyboard. A computer processor that holds an execution of an program instruction different input routine might, for index for use in indexed addressing. as soon as it is typed. Occurs when example, read them from an The 65C02 has two index registers, the line is typed without a line external terminal. the X register and the Y register. number. This means that you can instruction: A unit of a try out nearly every statement index variable: A variable whose machine-language or immediately to see how it works. value changes on each pass through assembly-language program Compare deferred execution. a loop. Often called control corresponding to a single action for variable or loop variable. implement: To realize or bring the computer’s processor to about; for example, a language infinite loop: A section of a perform. translator implements a particular program that will repeat the same integer: A whole number language. sequence of actions indefinitely. represented inside the computer in IN#: This command designates initialize: (1) To set to an initial fixed-point form. Compare real the source of subsequent input state or value in preparation for number. characters. It can be used to some computation. (2) To prepare a Integer BASIC: A version of the designate a device in a slot or a blank disk to receive information by BASIC programming language used machine-language routine as the dividing its surface into tracks and by the Apple II family of computers. source of input. sectors. Also format. Integer BASIC is older than index: (1) A number used to initialized disk: A disk that is Applesoft and capable of processing identify a member of a list or table organized into tracks and sectors. numbers in integer (fixed-point) by its sequential position. (2) A list form only. Compare Applesoft input: Information transferred into or table whose entries are identified BASIC. a computer from some external by sequential position. (8) In source, such as the keyboard, a disk machine-language programming, drive, or a modem. the variable component of an Glossary 387 integrated circuit: Networks of inverse video: The display of text keyboard input connector: The microfine wire that conduct on the computer’s display screen in special connector inside the electrical impulses. They are etched the form of dark dots on a light (or Apple Ie by which the keyboard is on silicon wafers and embedded in other single phosphor color) connected to the computer. black plastic. background, instead of the usual keystroke: The act of pressing a light dots on a dark background. interface: The devices, rules, or single key or a combination of keys conventions by which one 1/0: Input/output. The transfer of (such as [CONTROL HC ]) on the component of a system information into and out of a keyboard. communicates with another. computer. See input, output. keyword: A special word or interface card: A peripheral card 1/0 device: Input/output device. sequence of characters that that implements a particular A device that transfers information identifies a particular type of interface (such as a parallel or serial into or out of a computer. See input, statement or command, such as interface) by which the computer output, peripheral device. RUN or PRINT. can communicate with a peripheral I/O link: A fixed location that kilobyte: A unit of information device such as a printer or modem. contains the address of an consisting of 1K (1024) bytes, or 8K interpreter: A language translator input/output subroutine in the (8192) bits. See K. that reads a program instruction by computer’s Monitor program. KSW: The symbolic name of the instruction and immediately joystick: An accessory that moves location in the computer’s memory translates each instruction for the creatures and objects in game where the standard input link is computer to carry out. Compare programs. stored. ASW stands for keyboard compiler. switch. See 1/0 link. K: Two to the tenth power, or 1024 interrupt: A temporary (from the Greek root Az/o, meaning language: See programming suspension in the execution of a one thousand); for example, 64K language. program by a computer in order to equals 64 times 1024, or 65,536. perform some other task, typically leading zero: A zero occurring at in response to a signal from a keyboard: The set of keys built the beginning of a number, deleted peripheral device or other source into the Apple Ile, similar to a by most computing programs. external to the computer. typewriter keyboard, used for least significant bit: The entering information into the right-hand bit of a binary number as computer. written down. Its positional value is Qor 1. 388 Glossary LIFO: Acronym for last in, first logical operator: An operator, low-resolution graphics: The out. such as AND, that combines logical display of graphics on a display values to produce a logical result. screen as a sixteen-color array of line feed: An ASCII character Compare arithmetic operator, blocks, 40 columns wide and 48 (decimal 10) that ordinarily causes relational operator. rows high. When the text window is a printer or video display to advance in use, the visible low-resolution to the next line. loop: A section of a program that is graphics display is 40 by 40 blocks. executed repeatedly until a limit or line number: A number condition is met, such as an index LS: See low-power Schottkey. identifying a program line in an variable reaching a specified ending Applesoft program. Line numbers machine language: The form in value. are necessary for deferred which instructions to a computer execution. loop variable: See index are stored in memory for direct variable. execution by the computer’s line width: The number of processor. Each model of computer characters that fit on a line on the low-level language: A processor (such as the 65C02 screen or on a page. programming language that is microprocessor used in the relatively close to the form that the list: A verb in cornputer jargon, Apple Ile) has its own form of computer's processor can execute meaning to display on a monitor, or machine language. directly. Low-level languages print on a printer, the contents of available for the Apple Ile include main logic board: A large circuit the computer memory or a file. 6502 machine language and 6502 board that holds RAM, ROM, the load: To transfer information from assembly language. microprocessor, custom-integrated a peripheral storage medium (such circuits, and other components that low-order byte: The less as a disk) into main memory for use; make the computer a computer. significant half of a memory address for example, to transfer a program or other two-byte quantity. In the main memory: The memory into memory for execution. 65C02 microprocessor, the low-order component of a computer system location: See me mory location. byte of an address is usually stored that is built into the computer itself first, and the high-order byte and whose contents are directly logic board: See main logic second. accessible to the computer. board. low-power Schottkey: A type of MARK parity: A bit of value 1 TTL integrated circuit having lower appended to a binary number for power and higher speed than a transmission. The receiving device conventional TTL integrated circuit. can then check for errors by looking for this value on each character. Glossary 389 mask: A pattern of bits for use in microprocessor: A computer Monitor program: A system bit-level logical operations. processor contained in a single program built into the firm ware of integrated circuit, such as the 65C02 the Apple Ile, used for directly memory: A hardware component microprocessor used in the inspecting or changing the contents of a computer system that can store Apple Ile. of main memory and for operating information for later retrieval. See the computer at the main memory, random-access microsecond: One millionth of a machine-language level. memory, read-only memory, second. Abbreviated ps. read-write memory. most significant bit: The millisecond: One thousandth of a leftmost bit of a binary number as memory location: A unit of main second. Abbreviated ms. written down. This bit represents 0 memory that is identified by an mode: A state of a computer or or | times 2 to the power one less address and can hold a single item system that determines its behavior. than the total number of bits in the of information of a fixed size. In the A manner of operating. binary number. For example, in the Apple IIe, a memory location holds binary number 10000, which one byte, or eight bits, of modem: Acronym for contains five digits, the / represents information. MOdulator/DEModulator; a 1 times two to the fourth power—or peripheral device that enables the memory-resident: (1) Stored sixteen. computer to transmit and receive permanently in main memory as information over telephone lines by mouse: A small device that you firmware. (2) Held continually in converting digital signals to analog roll around on a flat surface next to main memory even while not in use. signals, and vice-versa. your Apple II family system. A DOS is memory resident. small pointer on the screen tracks modulate: To modify or alter a menu: A list of choices presented the movement of the mouse. signal so as to transmit information. by a program, usually on the display For example, conventional nanosecond: One billionth (in screen, from which the user can broadcast radio transmits sound by British usage, one thousand- select. modulating the amplitude millionth) of a second. Abbreviated MHz: Megahertz; one million hertz. (amplitude modulation, or AM) or NS. See hertz. the frequency (frequency nested loop: A loop contained modulation, or /’M/) of a carrier microcomputer: A computer, within the body of another loop and signal. such as any of the Apple II family of executed repeatedly during each computers, whose processor is a monitor: See video monitor. pass through the containing loop. microprocessor. 390 Glossary nested subroutine call: A call to opcode: See operation code. output: Information transferred a subroutine from. within the body from a computer to some external operand: A value to which an of another subrou tine. destination, such as the display operator is applied. The value on screen, a disk drive, a printer, or a nibble: A unit of information equal which an opcode operates. modem. to half a byte, or four bits. A nibble operating system: The most can hold any value from 0 to 16. output routine: A fundamental program in a Sometimes spelled nybble. machine-language routine that computer. It organizes the actions of performs the sending of characters. NOT: A unary logical operator that the various parts of the computer The standard output routine writes produces a true result if its operand and allows it to use other programs. characters to the screen. A different is false, a false res ult if its operand operation code: The part of a output routine might, for example, is true. Compare AND, OR, machine-language instruction that send them to a printer. exclusive OR. specifies the operation to be overflow: The condition that NTSC: (1) Abbreviation for performed. Often called opcode. exists when an attempt is made to National Televiszon Standards operator: A symbol or sequence of put more data into a memory area Committee. The committee that characters, such as + or AND, than it can hold. defined the standard format used specifying an operation to be for transmitting broadcast video override: To modify or cancel a performed on one or more values signals in the United States. (2) The long-standing instruction with a (the operands) to produce a result. standard video format defined by temporary one. See arithmetic operator, the NTSC. relational operator, logical overrun: A condition that occurs object code: See object operator, unary operator, when the processor does not program. binary operator. retrieve a received character from the receive data register of the object program: The translated option: An argument that is ACIA before the subsequent form of a program produced by a optional. character arrives. The ACIA language translator such as a OR: A logical operator that automatically sets bit 2(OVR) of its compiler or assembler. Also called produces a true result if either or status register; subsequent object code. Compare source both of its operands are true, a false characters are lost. The receive data program. result if both of its operands are register contains the last valid data odd parity: Use of an extra bit set false. Compare exclusive OR, word received. to 0 or 1 as necessary to make the AND, NOT. total number of 1 bits an odd number. Glossary 391 page: (1) A segment of main PC board: See printed-circuit physically separate from the memory 256 bytes long and board. computer and connected to it by beginning at an address that is an wires, cables, or some other form of peek: To read information directly even multiple of 256 bytes. (2) An interface, typically by means of a from a location in the computer’s area of main memory containing peripheral card. memory. text or graphical information being peripheral slot: See expansion displayed on the screen. (3) A peripheral: At or outside the slot. screenful of information on a video boundaries of the computer itself, display. With the Apple Ile, a page either physically (as a peripheral phase: (1) A stage in a periodic consists of 24 lines of 40 or 80 device) or in a logical sense (as a process. A point in a cycle. For characters each. peripheral card). example, the 65C02 micro processor uses a Clock cycle consisting of two page zero: See zero page. peripheral bus: The bus used for phases called ¢0 and 1. (2) The transmitting information between parallel interface: An interface relationship between two periodic the computer and peripheral in which many bits of information signals or processes. For example, in devices connected to the computer's (typically eight bits, or one byte) are NTSC color video, the color of a expansion slots. transmitted simultaneously over point on the screen is expressed by different wires or channels. peripheral card: A removable the instantaneous phase of the Compare serial interface. printed circuit board that plugs into video signal relative to the color one of the expansion slots in the reference signal. parity: Maintenance of a sameness Apple Ile. It expands or modifies the of level or count, usually the count PILOT: Acronym for computer’s capabilities by of 1 bit in each character, for error Programmed Inquiry, Learning, connecting a peripheral device or checking. Or Teaching. A high-level performing some subsidiary or programming language designed to Pascal: A high-level programming peripheral function. enable teachers to create language with statements that peripheral device: An auxiliary computer-aided instruction (CAI) resemble English sentences. Pascal piece of equipment—such as a lessons that include color graphics, was designed to teach programming video monitor, disk drive, printer, or sound effects, lesson text, and as a systematic approach to problem modem—used in conjunction with a answer checking. A version called solving. Named after the computer and under the computer’s Apple II PILOT is sold by Apple philosopher and mathematician, control. Often (but not necessarily ) Computer for use with the Apple II Blaise Pascal. family of computers. pass: A single execution of a loop. 392 Glossary pipelining: A feature of a pop: To remove the top entry from procedure: In the Pascal processor that enables it to begin a stack. programming language, a set of fetching the next instruction before instructions that work as a unit; power supply: A box that draws it has finished executing the current equivalent to the subprogram in electrical power from a power outlet instruction. All else being equal, BASIC. and converts it to the power the processors that have this feature computer can use to do its processor: The hardware run faster than those without it. computing. component of a computer that plotting vector: A code performs the actual computation by power supply case: The metal representing a single step in directly executing instructions case inside the Apple Ile that houses drawing a shape on the represented in machine language the power supply. high-resolution graphics screen, and stored in main memory. specifying whether to plot a point at PR#: The PR# command sends ProDOS: An Apple II operating the current screen position and in output toa slot ora system designed to support mass what direction to move (up, down, machine-language program. It storage devices like the ProFile as left, or right) before processing the specifies an output routine in the well as flexible disk storage devices. next vector. ROM on a peripheral card or in a ProDOS stands for Professional machine-language routine in RAM point of call: The point ina Disk Operating System. by changing the address of the program from which a subroutine or standard output routine used by the ProDOS command: Any one of function is called. computer. the 28 commands recognized by pointer: An item of information ProDOS. Each has its own syntax, precedence: The order in which consisting of the memory address of all can be used within programs, operators are applied in evaluating some other item. For example, and all but five (text file an expression. Applesoft maintains internal commands) can be used from pointers to (among other things) the printed-circuit board: A immediate mode. most recently stored variable, the hardware component of a computer program: 7. A set of instructions most recently typed program line, or other electronic device, describing actions for a computer to and the most recently read data consisting of a flat, rectangular perform in order to accomplish some item. piece of rigid material, commonly task, conforming to the rules and fiberglass, to which integrated poke: To store information directly conventions of a particular circuits and other electronic into a location in the computer’s programming language. In components are connected. memory. Applesoft, a sequence of program lines, each with a different line number. v. To write a program. Glossary 393 programmer: The author of a push: To add an entry to the top of random-access text file: A text program; one who writes programs. a stack. file that is partitioned into an unlimited number of uniform-length programming: The activity of queue: A list in which entries are compartments called records. When writing programs. added at one end and removed at you open a random-access text file the other, causing entries to be programming language: A set of for the first time, you must specify removed in FIFO (first-in first-out) rules or conventions for writing its record length. No record is placed order. Compare stack. programs. in the file until written to. Hach radio-frequency modulator: A record can be individually read from prompt: 7. A message on the device that transforms your or written to—hence, screen. v. To remind or signal the television set into a computer random-access. user that some action is expected, display device. typically by displaying a distinctive raster: The pattern of parallel symbol, a reminder message, or a RAM: See random-access lines making up the image ona menu of choices on the display memory. video display screen. The image is screen. produced by controlling the random-access memory (RAM): brightness of successive dots on the prompt character: A text Memory in which the contents of individual lines of the raster. character displayed on the screen to individual locations can be referred prompt the user for some action. to in an arbitrary or random order; read: To transfer information into Often also identifies the program or the readable and writable memory the computer’s memory from a component of the system that is of the Apple Ile. Its contents are source external to the com puter doing the prompting: for example, usually filled with programs from a (such as a disk drive or modem) or the prompt character |is used by disk, and they are lost when the into the computer’s processor from a the Applesoft BASIC interpreter, > Apple Ile is turned off. This term is source external to the processor by Integer BASIC, and * by the often used misleadingly to refer to (such as the keyboard or main system Monitor program. Also called read-write memory, but, strictly memory). prompting character. speaking, both read-only and read-only memory (ROM): read-write memory can be accessed prompt line: A message displayed Memory whose contents can be read in random order. Random-access on the screen to prompt the user for but not written; used for storing means that each unit of storage has some action. Also called prompting firmware. Information is written a unique address and a method by message. into read-only memory once, during which each unit can be immediately manufacture; it then remains there protocol: A set of rules for sending read from or written to. Compare permanently, even when the and receiving data on a read-only memory, read-write computer's power is turned off, and communications line. memory. 394 Glossary can never be erased or changed. reserved word: A word or save: To transfer information from Compare random-access sequence of characters reserved by main memory to a peripheral memory, read-write memory. a programming language for some storage medium for later use. special use, and therefore read-write memory: Memory scroll: To change the contents of unavailable as a variable name in a whose contents can be both read all or part of the display screen by program. and written; often misleadingly shifting information out at one end called random-access memory, or resident: See memory-resident, (most often the top) to make room RAM. The information contained in disk-resident. for new information appearing at read-write memory is erased when the other end (most often the return address: The point ina the computer’s power is turned off, bottom), producing an effect like program to which control returns on and is permanently lost unless it that of moving a scroll of paper past completion of a subroutine or has been saved on a more a fixed viewing window. See function. permanent storage medium, such as window. a disk. Compare random-access RF modulator: See serial interface: An interface in memory, read-only memory. radio-frequency modulator. which information is transmitted real number: A number that may ROM: See read-only memory. sequentially, one bit at a time, over include a fraction al part; a single wire or channel. Compare routine: A part of a program that represented inside the computer in parallel interface. accomplishes some task subordinate floating-point form. Compare to the overall task of the program. setup time: The amount of time a integer. signal must be valid in advance of row: A horizontal arrangement of register: A location in a computer some event. Compare hold time. character spaces or graphics points processor where an item of on the screen. silicon: A non-metallic, information is held and modified semiconducting chemical element under program control. RS232 cable: Any cable that is from which integrated circuits are wired in accordance with the RS232 relational operator: An operator, made. Not to be confused with standard, which is the common data such as >, that compares numeric silica—that is, silicon dioxide, such communications interface standard. values to produce a logical result. as quartz, opal, or sand—or with Compare arithmetic operator, run: (1) To execute a program. silicone, any of a group of organic logical operator. (2) To load a program into main compounds containing silicon. memory from a peripheral storage medium, such as a disk, and execute It. Glossary 395 simple variable: A variable that is space character: A text character step value: The amount by which not an element of an array. whose printed representation is a the index variable changes on each blank space, typed by pressing the pass through a loop. simplified keyboard: The bar. Dvorak keyboard. string: An item of information stack: A list in which entries are consisting of a sequence of text 6502: The type of microprocessor added or removed at one end only characters. used in the Apple II, I] Plus, and (the top of the stack), causing them original Ile. strobe: A signal whose change is to be removed in LIFO (last-in used to trigger some action. 65C02: The type of microprocessor first-out) order. Compare queue. used in the enchanced Apple Ile and subroutine: A part of a program standard instruction: An the Apple IIc. that can be executed on request instruction automatically present from any point in the program, and slot: A narrow socket inside the when no superseding instruction which returns control to the point of computer where you can install has been received. the request on completion. peripheral device cards. start up: To get the system synchronous transmission: A soft switch: A means of changing running. For example, In the transmission process that requires some feature of the computer from context of ProDOS, starting up is the an integral number of unit (time) within a program; specifically, a process of reading the ProDOS intervals between any two location in memory that produces program (in the files PRODOS and significant instances. In some special effect whenever its BASIC.SYSTEM) from the disk, and synchronous communications, the contents are read or written. running it. transmitter and receiver are in step software: Instructions that tell the starting value: The value with each other, and characters computer what to do. They're assigned to the index variable on being transmitted follow one after usually stored on disks. Compare the first pass through a loop. the other at regular intervals. hardware, firmware. Compare asynchronous startup disk: A disk containing an transmission. source program: The original operating system and a self-starting form of a program given to a program. syntax: The rules governing the language translator such as a structure of statements or statement: A unit of a program in compiler or assembler for instructions in a programming a high-level language that specifies conversion into another form; language; a representation of a an action for the computer to sometimes called source code. command that specifies al the perform, typically corresponding to Compare object program. possible forms the command can several instructions of machine take. language. 396 Glossary system: A coordinated collection of terminal: A device consisting of a TTL: See transistor-transistor interrelated and interacting parts typewriter-like keyboard and a logic. organized to perform some function display device, used for turnkey disk: A disk that or achieve some purpose. communicating between a computer executes a specific application system and a human user. Personal system configuration: See program when you use that disk to computers such as those in the configuration. start the computer. Apple II family of computers system program: A program that typically have all or part of a turnkey program: A program, makes the resources and terminal built into them. such as a game or application, that capabilities of the computer runs automatically when the disk text: (1) Information presented in available for general purposes, such that the program is on is used to the form of characters readable by as an operating system or a start up the computer. humans. (2) The display of language translator. Compare characters on a display screen. unary operator: An operator that application pro gram. Compare graphics. applies to a single operand; for system software: The component example, the minus sign (-) in a text window: An area on the video of a computer system consisting of negative number such as -6 is a display screen within which text is system programs. unary arithmetic operator. Compare displayed and scrolled. binary operator. TAB: An ASCII character that traces: Electrical roads that commands a device such as a unconditional branch: A branch connect the components on a circuit printer to start printing at a preset that does not depend on the truth of board. location (called a tab stop). There any condition. Compare are two such characters;: horizontal transistor-transistor logic conditional branch. tab (hex $09) and vertical tab (hex (TTL): (1) A type of integrated value: An item of information that SOB). circuit used in computers and can be stored in a variable, such as a related devices. (2) A standard for television set: A display device number or a string. interconnecting such circuits that capable of receiving broadcast video defines the voltages used to variable: (1) A location in the signals (such as commercial represent logical zeros and ones. computer’s memory where a value television) by means of an antenna. can be stored. (2) The symbol used Can be used in combination with a troubleshoot: To locate and in a program to represent such a radio-frequency modulator as a correct the cause of a problem or location. Compare constant. display device for the Apple Ile. malfunction in a computer system. Compare video monitor. Typically used to refer to hardware-related problems. Compare debug. Glossary 397 vector: (1) The starting address of word: A group of bits of a fixed size X register: One of the index a program segment, when used as a that is treated as a unit; the number registers in the 65C02 common point for transferring of bits in a word is a characteristic microprocessor. control from other programs. (2) A of each particular computer. Y register: One of the index memory location used to hold a write: To transfer information registers in the 65C02 vector, or the address of such a from the computer to a destination microprocessor. location. external to the computer (such as a zero page: The first page (256 video: (1) A medium for disk drive, printer, or modem) or bytes) of memory in the Apple Ile, transmitting information in the form from the computer’s processor to a also called page zero. Since the of images to be displayed on the destination external to the processor high-order byte of any address in screen of a cathode-ray tube. (2) (such as main memory). this page is zero, only the low-order Information organized or write-enable notch: The square byte is needed to specify a zero-page transmitted in video form. cutout on one edge of a disk’s jacket address; this makes zero-page video monitor: A display device that permits information to be locations more efficient to address, capable of receiving video signals by written on the disk. If there is no in both time and space, than direct connection only, and which write-enable notch, or if it is covered locations in any other page of cannot receive broadcast signals with a write-protect tab, memory. such as commercial television. Can information can be read from the be connected directly to the disk but not written onto it. computer as a display device. write-protect: To protect the Compare television receiver. information on a disk by covering volume: A general term referring the write-enable notch with a to a storage device; a source or write-protect tab, preventing any destination of information. A new information from being written volume has a name and a volume onto the disk. Compare copy directory with the same name. Its protect. information is organized into files. write-protect tab: A small window: The portion of a adhesive sticker used to collection of information (such as a write-protect a disk by covering the document, picture, or worksheet) write-enable notch. that is visible on the display screen. 398 Glossary Bibliography Addendum to the Design Guidelines. Cupertino, Calif.: Apple Computer, Inc., 1984. Apple II Monitors Peeled. Cupertino, Calif.: Apple Computer, Inc., 1978. Currently not updated for Apple [le and IIc, but a good introduction to Apple II series input/output procedures; also useful for historical background. Apple Ile Design Guidelines. Cupertino, Calif.: Apple Computer, Inc., 1982. Applesoft BASIC Programmer’s Reference Manual, Volumes 1 and 2. For the Apple II, Ile, and IIc. Reading, Mass.: Addison-Wesley, 1982, 1985. ISBN 0-201-17722-6. Applesoft Tutorial. Reading, Mass.: Addison-Wesley, 1983, 1985. ISBN 0-201-17724-2. “Characteristics of Television Systems.” C.C.L.R. Report, Rep. 624 (1970-1974), pp. 22-52. “Colorimetric Standards in Colour Television.” C.C..R. Report, Rep. 476-1 (1970-1974), pp. 21-22. Leventhal, Lance. 6502 Assembly Language Programming. Berkeley, Calif.: Osborne/McGraw-Hill, 1979. Sims, H. V. Principles of PAL Colour Television and Related Systems. London, England: Newnes-Butterworth, 1969. ISBN-0-592-05970-7. Synertek Hardware manual. Santa Clara, Calif.: Synertek Incorporated, 1976. Does not contain instructions new to 65C02, but is the only currently available manufacturer's hardware manual for 6500 series microcomputers. Bibliography 399 Synertek Programming manual. Santa Clara, Calif.: Synertek, Incorporated, 1976. The only currently available manufacturer’s programming manual for 6500 series microcomputers. “Video-Frequency Characteristics of a Television System to Be Used for the International Exchange of Programmes Between Countries That Have Adopted 625-Line Colour or Monochrome Systems.” C°.C.L.R., Recommendation 472-1 (1970-1971), pp. 58-54. Watson, Allen, III. “A Simplified Theory of Video Graphics, Part I.” Byte Vol. 5, No. 11 (November, 1980). -— ~~ “A Simplified Theory of Video Graphics, Part II.” Byte Vol. 5, No. 12 (December, 1980). ~-——-~“More Colors for Your Apple.” Byte Vol. 4, No. 6 (June, 1979). ———~“True Sixteen-Color Hi-Res.” Apple Orchard Vol. 5, No. 1 (January, 1984). Wozniak, Steve: “System Description: The Apple II.” Byte Vol. 2, No. 5 (May, 1977). -——--- “SWEET16: The 6502 Dream Machine.” Byte Vol. 2, No. 10 (October, 1977). 400 Bibliography Index Cast of Characters 80-column text 20-21 any-key-down flag 12 differences in Apple II family 227 Apple keys 11, 13 * asterisk) as prompt character 60 display pages 27 differences in Apple II family 226 * (caret) 122, 125 generation 179 Applesoft BASIC xxx, 12, 108, 233 :(colon) as Monitor command 103 map 33 and lowercase xxxi > (greater than sign) as prompt signals 197 and uppercase 48 character 60 with Applesoft xxx 80-column support xxx (=) 61 with Pascal xxx tabbing with original Apple Ile (G) 11, 18, 226 with TV set 16 271-272 . (period) as Monitor command 100 80-Column Text Card 84, 132, 149, use of zero page 77 0 (phi 0) 162-164, 170, 171, 180-181 268-275 Apple II compatibility with Apple Ile 1 (phil) 162-164, 170, 171, 180-181 80STORE soft switch 29, 31, 84, 86, 87, 48-50 pa (phi 2) 162 197 Apple II family differences 226-230 ? (question mark) prompt character 60 Apple IIc interrupt differences 156 (=) 62 ](right bracket) as prompt character A Apple Ile, differences between original and enhanced Xxix-xxxi 60 Aregister 146 ASCII input mode 105 (@} 11, 18, 226 Al 89 COUT] subroutine 54 14M signal 163 A2 89 interrupt support 130, 148 40-column text 20-21 A4 89 microprocessor 6 display pages 27 accumulator 136, 148 Mini-Assembler 12] generation 179 ACIA 289 Monitor Search command 108 memory map 32, 177 address bus 162 MouseText 16, 20 with TV set 16 address transformation 176 slot 3 148 6502 microprocessor 5,6 addressing tabbing in Applesoft 271-272 differences from 65C02 206-207 display pages 30-36, 175-178 65C02 microprocessor xxix, 5, 6, using [CAPS LOCK] 48 I/O locations 1386-137 Apple Ile 80-Column Text Card 84, 206-216 RAM 188, 170-178 132, 268-275 data sheet 208-216 ROM 169 Apple Ile Extended 80-Column Text differences from 6502 6, 206-207 addressing, indirect 75 Card 84, 132, 268-275 specifications 161-164 addressing, relative 119, 125, 135 arithmetic, hexadecimal 114 timing 162-164 ALTCHAR soft switch 29 arrow keys 61, 62 65C02 stack 75 alternate character set 19-20, 226 ASCII codes 14-15 80COL soft switch 29 on original Ile 20 ASCII input mode 104-105 80-column firmware xxx, 49-50 ALTZP soft switch 82, 87, 89 assemblers 119 activating 49 analog inputs 42, 43 assembly language 233 control characters with 273-275 animation 229 asterisk (*) as prompt character 60 annunciators 40, 43 auxiliary firmware 84-91 Index 40] auxiliary memory 84-91 baud rate for SSC 280 CLEOLZ subroutine 49, 64, 219 differences in Apple II family 228 BEL character 52 clock rate 161 map 85 BELL subroutine 218 clock signals 162 moving data to 89 BELLI subroutine 38, 218 CLREOL subroutine 49, 63, 218 soft switches 87 bit definition 236 CLREOP subroutine 49, 64, 219 subroutines 88 bit mapping of graphics 24-26 CLRSCR subroutine 64, 219 auxiliary RAM 84 booting 268-269 CLRTOP subroutine 64, 219 auxiliary slot 7, 49 break intructions 155 cold-start reset 92 differences in Apple II family 228 BRK handler 155 colon (:) as Monitor command 103 signals 197-199 BRK instruction 155 color graphics with black-and-white AUXMOVE subroutine 88, 89, 143 BRK vector 147 monitors 16 BS character 52 colors B byte definition 237 double-high-resolution graphics 26 high-resolution graphics 24-25, 183 backspacing 61 C low-resolution graphics 23 bank-switched memory 79-88 , 85, 227 command characters, Monitor 99 map 80 canceling lines 61 comma tabbing with origin al Apple Ile bank switches 80-83, 85 CAN character 53 271-272 reading 83 I] complementary decimal values 12 BASIC, Applesoft xxx,12, 108, 233 for older software compatibility 48 connectors and lowercase Xxxi caret (~) 122, 125 back panel 8 and uppercase 48 carriage returns with SSC 283 cassette 1/0 8, 38 80-column support Xxx cassette I/O 38-39, 189 D-type 8 tabbing with original Apple Ile commands 109-111 game I/O 7,13 271-272 soft switches 38 hand control 8, 39-42 use of page 3 76 central processing unit (CPU) 6 9-pin 8, 39 use of zero page 77 See also 65C02 microprocessor phone jacks 8, 38 BASIC, Integer 12, 288 CH 51 power 161 and bank-switched memory 79 changing memory contents 103-108 RCA-type jack 8 and reset 81 character code 12 video monitor 8, 186 and uppercase 48 character generator ROM 179 control characters 245, 249 use of page 3 76 character sets, text 19-20 with BASICOUT 52-53 use of zero page 78 differences among Apple II models with COUT] 52 BASICIN subroutine 57, 218 226-227 with 80-column firmware 273-275 address in I/O link 51 CHARGEN signal 185 with Pascal I/0 protocol 68-69 BASIC Monitor command 112 circuit board 4-5 Control-U 50 BASICOUT subroutine 68, 218 connectors 6 1] address in I/O link 51 clear-strobe switch 12 Monitor command 112 402 Index (CONTROL }({E] Monitor command 109 decimal values 12 DMA daisy chain 193-194, 208 (CONTROL }{K] Monitor command 113 converting to hexadecimal 238-239 DOS 3.3 xxix, 140, 232 (CONTROL }{P] Mon itor command 113 negative 240-241 and uppercase 48 61 device assignment, peripheral card starting up with 269 Monitor command 117 144 use of page3 76 COUT subroutine 51, 64, 219 device identification 144 use of zero-page 78 deactivating 80-column firmware 50 DEVICE SELECT’ signal 181 double-high-resolution graphics 17, 18, COUT1 subroutine 51, 64, 184, 219 DHIRES soft switch 29 25-26 address in 1/0 link 50 Diagnostics ROM 169 colors 26 on original Apple Ile 54 differences among Apple II models display pages 27 cover 2 226-230 generation 185 CP/M 233 differences between original and map 386 starting up with 268 enhanced Apple Ile xxix-xxxi memory pages 25 CPU 6 ASCII input mode 105 double-high-resolution Page 1 76 See also 65C02 microprocessor COUT] subroutine 54 CR character 53 interrupt support 130, 148 EK CROUT subroutine 64, 219 microprocessor 6 CROUT!1 subroutine 65, 219 Mini-Assembler 12] editing with GETLN 61 CSW link 139 Monitor Search command 108 80COL soft switch 29 current, supply 159 MouseText 16, 20 80-column firmware xxx, 49-50 cursor-control keys 11 slot3 148 activating 49 cursor motion in esc ape mode 58-59 tabbing in Applesoft 271-272 control characters with 273-275 cursor position 51-57 using (CAPS LOCK] 48 80-column text 20-21 custom IC’s 164-168 disassemblers 119 differences in Apple II family 227 CV 51 display, video 16-36 display pages 27 cycle stealing 170 address transformation 176-177 generation 179 double-high-resolution graphics 185 map 33 D 80-column text 179 signals 197 formats 17,56 with Applesoft xxx D-type connector 8 40-column text 179 with Pascal xxx daisy chains, interrupt and DMA generation 173-185, 230 with TV set 16 193-194, 208 high-resolution graphics 183-184 80-Column Text Card 84, 132, 149, data bus 162 low-resolution graphics 182-183 268-275 data format for SSC 281 memory addressing 175-178 80STORE soft switch 29, 31, 84, 86, 87, DC1 character 53 modes 17, 20-26, 28-80, 179-185 197 DC2 character 58 pages 26-28, 30-36, 76 EM character 53 DC3 character 53 refreshing 170 EN80’ signal 197 specifications 17 text 179-181 Index 403 enhanced Apple Ile See differences G H between original and enhanced Apple Ile game I/O hand control connectors 8, 89-42 ENKBD’ signal 187 connectors 13 hard disk with Pascal xxxi entry points for I/O routines 145-146 signals 190-191] hexadecimal arithmetic 114 escape codes 58-59 GET command 269 hexadecimal values 12 escape mode 58-59 GETLN subroutine 57, 60-62, 220 converting to decimal 238-239 ESC character 53 editing with 61 converting to negative decimal ETB character 53 input buffer 76 240-241 EXAMINE command 108-109 line length 61 high-resolution graphics 17, 18, 23-25 examining memory 100 used by Monitor 99 addressing display pages 31, 35 expansion ROM space 132-134 with 80-column card 269 bit patterns 242-243 expansion slot 3 49 GETLN1 subroutine 220 colors 24-25, 183 expansion slots 6-7, 180-143 GETLNZ subroutine 220 display pages 27 signals 192-196 GO command 118 generation 183-184 Extended 80-Column Text Card 84, graphics, double-high-resolution 17, map 35 132, 268-275 18, 25-26 high-resolution Page 1 23, 27, 76 colors 26 high-resolution Page 2 23, 76 display pages 27 HIRES soft switch 29, 86, 87 F generation 185 HLINE subroutine 65, 220 FF character 52 map 36 HOME command 270-271 firmware memory pages 25 HOME subroutine 49, 65, 220 auxiliary 84-91 graphics, high-resolution 17, 18, 23-25, HTAB command xxx 80-column xxx, 49-50 addressing display pages 31, 35 with original Apple Ile 272 1/0 46-69 bit patterns 242-243 humidity, operating 158 Monitor subroutines 46-69 colors 24-25, 183 Pascal 1.1 protocol 67-69, 144-146 display pages 23, 27 I,J slot3 67 generation 183-184 flag, any-key-down 12 map 35 I/O FLASH command 270-271 graphics, low-resolution 17, 18, 22-23, addressing 136-137 flashing format 18-19, 56-57 colors 23 circuits 187-191 forced cold-start reset 93 display pages 27 devices, built-in 10-42 FORTRAN 234 generation 182-183 entry points 145-146 40-column text 20-21 map 34 firmware, built-in 46-69 display pages 27 with TV set 16 links 50-51, 76, 189-140 generation 179 graphics modes 22-26 memory for peripheral cards memory map 382, 177 bit-mapping 24-26 130-181 with TV set 16 greater than sign (>) as prompt memory map 141 FS character 53 character 60 Pascal protocol 67-69, 148, 144-146 GS character 53 switching memory 141-142 404 Index I/O SELECT’ signal] 181-132 IOREST subroutine 220 LIST command 119 identification byte xxix, 230 IOSAVE subroutine 220 low-resolution graphics 17, 18, 22-23 IN# command 113 IOU (Input/Output Unit) 5, 6, 166-167, colors 23 index register 136 187 display pages 27 indirect addressing 75 IOUDIS soft switch 29 generation 182-183 input buffer 76 IRQ vector 147 map 34 INPUT command 269 IRQ’ signal 147 with TV set 16 input devices See 1/0 devices input/output See I/O K M Input/Output Unit CIOU) 5, 6, 166-167, 187 KBD’ signal 187 machine language 118-120 inputs keyboard 3, 10-15 mapping display addresses 176-177 analog 37, 42 automatic repeat function 10 maps See memory maps hand control 37 circuits 187-188 memory secondary 37-42, 43 differences in Apple II family 226 addressing 168 switch 37-41 memory locations 12 auxiliary 84-91 See also 1/0 devices rollover 10 bank-switched 79-83, 86-88, 227 INT IN pin 147 specifications 11 changing contents 103-108 INT OUT pin 147 KEYBOARD command 113 display 175-178 Integer BASIC 12, 288 keyboard encoder 5, 12 examining 100 and bank-switched memory 79 keyboard ROM 5 filling 115-116 and reset 81 keyboard strobe 13 for peripheral cards 180-135 and uppercase 48 KEYIN subroutine 57, 58-59, 221 I/O space 141-142 use of page 3 70 address in I/O link 50 organization 72-95 use of zero page 7 8 keypad 188 sharing 88 interpreter ROM 5 keys and ASCII codes 14-15 text window locations 55 interrupt handler KSW link 1389 used by SSC 289 built-in 146, 149-1 50 memory dump 100-102 user's 154 L Memory Management Unit (MMU) 5, interrupts xxx, 146-156 6, 164-165 and card in auxiliary slot 49 language card 83 memory maps daisy chain 193-194, 208 differences in Apple II family 227 auxiliary memory 85 definition 147 LED 3 bank-switched areas 80 original Apple Ile differences 148 (+)key 61 double-high-resolution graphics 36 priority 147 LF character 52 80-column text 33 sequence 15] line feeds with SSC 284 40-column text 32, 177 interrupt vector 150 links, 1/0 50-51 high-resolution graphics 35 INVERSE command 270-271 address storage 70 I/O 141 inverse display format 18-19, 56-57, changing 139-140 low-resolution graphics 34 112 main memory 73 RAM 74 Index 405 memory pages, reserved 75-79 0 period (.) as Monitor command 100 microprocessor See 65C02 and 6502 peripheral address bus 192-193, 194 microprocessors (G) 11, 18, 226 peripheral cards Mini-Assembler 121-125 operating systems 232-233 device assignment 144 errors 122 original Apple Ile I/O memory space 180-131, 141 instruction formats 124-125 ASCII input mode 105 programming for 130-156 starting 121 COUT! subroutine 54 RAM space 184-135 MIXED soft switch 29 interrupt support 180, 148 ROM space 181-182 Monitor, System 98-128 microprocessor 6 peripheral data bus 193 command summary 125-128 Mini-Assembler 12] differences in Apple II famaily 230 command syntax 99 Monitor Search command 108 peripheral slots See expansion slots creating commands 117 MouseText 16, 20 0 (phi0) 162, 164, 170, 171, 180-181 enhancements xxvi slot 3 148 gl (phil) 162, 164, 170, 171, 180-181 firmware subroutines 46-69 startup display 6 g2 (phi 2) 162 returning to BASIC 112 tabbing in Applesoft 271-272 phone jacks 8, 88 ROM listings 294-375 using (CAPS LOCK] 48 PINIT subroutine 67 use of page 3 76 output See 1/0 pipelining 161 use of zero page 77 overheating 158 PLOT subroutine 65, 221 Monitor ROM 169 POKE command 272 listings 294-375 P power connector 161 MouseText characters 17, 19, 247 power supply 4, 159-160 Page 1, double-high-resolution 76 MOVE command 105, 115 PR#¥ command 118 Page 1, high-resolution 23, 27, 76 MOVE subroutine 221 PRBL2 subroutine 65, 221 Page 1, text 27 MSLOT 150, 154 PRBLNK subroutine 221 Page 2, high-resolution 23, 76 PRBYTE subroutine 65, 221 Page 2, text 27 N PREAD subroutine 42, 67, 222 page 3 vectors 94 PRERR subroutine 65, 222 NAK character 53 page zero See zero page PRHEX subroutine 66, 222 negative decimal values 12 PAGE2 soft switch 29, 31, 84, 86, 87 primary character set 19-20 converting 240 pages, reserved memory 75-79 PRINTER command 113 NEXTCOL subroutine 221 PAL device 168 PRNTAX subroutine 66, 222 9-pin connectors 8, 39 parity for SSC 281-282 ProDOS 108, 140, 282 NORMAL command 270-271 Pascal xxix, 234, 275 interrupt support 148 normal format 18-19, 112 and bank-switched memory 79 starting up with 269 NTSC standard 16, 24, 178 I/O subroutines 46 use of page 3 76 starting up with 268 use of zero-page 79 Pascal 1.1 firmware protocol 67-69, 143, 144-146 Pascal operating system 232 406 Index ProFile hard disk xxl refreshing the display 170 self-test 13, 95 Programmed Array Logic (PAL) device registers 146, 162 differences in Apple II family 229 5, 168 A register 146 SETCOL subroutine 66, 223 prompt characters 60 accumulator 1386, 148 SETINV subroutine 223 PSTATUS subroutine 69 examining and changing 108-109 SETNORM subroutine 223 PWRITE subroutine 68 index 136 1] X register 146 shift-key mod 41 Y register 146 short circuits 160 Q relative addressing 119, 125, 135 SI character 58 Q3 signal 163 reserved memory pages 75-79 signals question mark (?) prompt character 60 11, 18, 226 auxiliary slot 197-199 reset routine 91-95 expansion slot 192-196 R and bank switches 81 game I/O connector 191 differences in Apple II family 229 IOU 167 R/W80 signal 197 reset vector 93-94 keyboard connector 188 radio frequency modulator 7 (RETURN ] Monitor command 125 keypad connector 188 RAM retype function 62 MMU 165 addressing 138, 170-178 RF modulator 7 PAL device 168 allocation 74-79 RGB-type monitor 185 RAM timing 172-178 auxiliary 84 62 65C02 timing 163 space for peripheral cards 134-135 right bracket (]) as prompt character speaker connector 189 timing signals 171-173 60 video connector 186 RAMRD soft switch 86, 87 rollover, N-key 10 video timing 180-181, 184 RAMWR soft switch 86, 87 ROM signature byte 230 random number generator 58 addressing 169 6502 microprocessor 6 RDALTCHAR soft switch 29 expansion 182-134 differences from 65C02 6, 206-207 RDALTZP soft switch 82 interpreter 5 65C02 microprocessor xxix, 5, 6, RDBNK2 soft switch 82 keyboard 5 206-216 RDCHAR subroutine 222 Monitor listings 294-375 comparison with 6502 6, 206-207 RDDHIRES soft switch 29 space for peripheral cards 1381-132 data sheet 208-216 RD80COL soft switch 29 video 5 specifications 161-164 RD80STORE soft switch 29 ROMEN] signal 169 timing 162-164 RDHIRES soft switch 29 ROMEN2 signal 169 slot, auxiliary 7, 49 RDIOUDIS soft switch 29 slot number, finding 136 RDKEY subroutine 47, 57, 60, 222, 269 slot3 49, 149 RDLCRAM soft switch 82 5 firmware 67 RDMIXED soft switch 29 schematic diagram 200-203 in original Apple Ile 143 RDPAGE2 soft switch 29 SCRN subroutine 66, 223 slots, expansion 6-7, 180-148 RDTEXT soft switch 29 SEARCH command 108 signals 192-196 READ subroutine 39, 222 READ tape command 110-111 Index 407 SLOTC3ROM soft switch 49, 142 subroutines text Page 1 27,76 SLOTCXROM soft switch 142 directory of 218-224 text Page 2 27,76 SO character 53 output 62-66 TEXT soft switch 29 soft switches Pascal I/O protocol 67-69 text window 54-55 auxiliary memory 84, 87 standard 1/O 46-69 memory locations 55 bank switches 80-83, 85 See also names of subroutines timing signals differences in Apple II family 228 Super Serial Card 278-293 expansion slots 194 display 28-30 command character 280 RAM 172-173 for bank switching 83,85 commands 280-287 65C02 microprocessor 162-164 I/O memory 141-142 error codes 287-288 video 180-181, 184 implemented by IOU 166 memory use 289-292 implemented by MMU 164 scratchpad RAM 292 U speaker 38 terminal mode 286-287 () 11, 18, 226 switch 0 41, 43 US character 53 SPC command xxx switch1 41, 48 user's interrupt handler 154 speaker 38, 37, 189 switches See soft switches connector 189 switch inputs 41, 43 V soft switch 38 SYN character 53 specifications, environmental 158 System Monitor See Monitor, System vectors stack pointers 75, 152 BRK 147 stack interrupt 150 T IRQ 147 auxiliary 152-153 main 152-153 tabbing page 3 94 65C02 75 TAB command xxx reset 93-94 standard I/O links 50-51 with original Apple Ile 271-272 VERIFY command 107, 116 address storage 76 television set 16 VERIFY subroutine 223 changing 139-140 temperature vertical syne 229 Starting up 268-269 case 159 VID7M signal 163 startup display 6 operating 158 video counters 174-175 Startup drives xXiX-XXX text cards 84, 182, 149, 268-275 video display See display, video Stop-list feature 54 text character sets video display pages 28, 25, 26-28 strobe bit 13 alternate 19-20 video monitor 16 strobe output 40, 48 primary 19-20, 226, 227 connector 8, 186 STSBYTE 287 text display 18-21, 179-181 video output signals 186 SUB character 53 flashing format 56-57 video ROM 5 inverse format 18, 56-57 normal format 18 See also 40-column text and 80-column text 408 Index video standards 173 W Y VLINE subroutine 66, 224 WAIT subroutine 224 Y register 146 voltage warm-start reset 92 line 158 WRITE subroutine 38, 224 supply 159 VT character 52 WRITE tape command 109-110 zero page 75, 77-79 VTABZ subroutine 66 X XFER subroutine 88, 90, 148, 153 X register 146 Index 409