Understanding the Apple II by Jim Sather Foreword by Steve Wozniak ^, > QUTiLrry softw7ir€ $22.95 Understanding the Apple II A Learning Guide and Hardware Manual for the Apple II Computer Quality Software is pleased to present the definitive source of information about how the Apple works. Jim Sather has conducted an exhaustive analysis of the inner workings of the Apple II computer. Now he has documented his findings in a way that will benefit everyone interested in microcomputer technology. Understanding the Apple U— • Documents all motherboard circuits, including some discussed nowhere else. • Describes disk controller operation, including previously undocumented details of the lo^c state sequencer. • Explains RAM and ROM card operation. • Reveals previously unnoticed features of Apple graphics. • Contains 23 software and hardware Application Notes including shift key mod, disk write protect mod, and EPROM mods. • Includes a chapter on maintenance that provides simple troubleshooting steps. If you are at all curious about how the Apple II works, you are sure to find Understanding the Apple //very valuable. It is an ideal book for a microcomputer fundamentals course based on the Apple. About the Author James Fielding Sather, a former eiearonics field technical representative for ITT Gilfillan, is an independent author, programmer, and designer of circuits for microcomputers, specializing in the Apple H. Understanding the Apple //describes the Apple I J and Apple IF Plus. QUTiLrry However, some information, including ihal on disk controller operation, also applies to the A pple I le. SOFTW71R€ ISBN 0-912985-01-1 Printed in USA Understanding the Apple II r by James Fielding Sather Vn QUTILny SOFTW7IR€ h£J 21601 Marilla Street Chatsworth, California 9I3I1 K 2G( ^H i^ /9o Production Editor: Kathryn M. Schmidt Original Schematics and Diagrams: James Fielding Sather Art Director and Cover Design: Vic Grenrock Cover Art: George Garcia Schematic Art: Ron Widman Photography: Gainsforth Studios Compositor: American IVpesetting, Inc. Printed By: California Offset Printers nisj bif QiHiliti/ Soft ware. AH rights reserved. No part of this book may be reprinted, or Coiit/rif/ht ® reproduced, or utilized in any form or by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying and recording, or in any information storage and retrieval system, without permission in writing from the Publisher. No patent liability isaiisumed with respect to the useof the information contained herein. Whileevery precaution has been taken in the preparationof this book, the publisher assumes no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. International Standard Book Number: 0-912985-01-1 Printed in the United States of America BI 100/3S4105+01 liiiiiniiiL :lli;ii 111 mill, ibi iiiiliiUiiii foreword Ej-fmustcd after addremngan A pplefest audience Since the hardware and software (««/:*' were not in Anaheim, I woa- offered a ride to the airport by a partitioned in ad nance for separate groups to work atranger who wan ivriting a book on Homeihing Apple on, a tremendous synergy evolved. Understanding related and who tvanted to talk to tne. The traffic the Apple II respects this close interdependence. It congeHtion, miiised exits, anrf airport confmion ham conta ins discuH.^ion and example.'i throughout Hard- deeper meaning to a computer designer, but I shall ware and software developers alike (and enthusiast'! never forget the conversation we had for the next cou- and students too) wilt gain greatly from this manual. ple ofhoum. Jim Sather proceeded to explain details, This is especially true for Chapter 9 on the floppy , anomalieH. oifersight% and paradoxes of the Apple II disk and controller, one of the la.'!t indiridual com- hardware as we drone the LA freeways, Denigners puter project.'i and certainly my personal favorite. like muHelffind it cenj reivardingto encounter others Design consideratiQ}is mu.'it he resolned in new, who understand and appreciate what we feet are the creatine ways when they are not commonplace. tricka and magic of our circuits. I was able to add to Appreciate the challenge of striving for low compo- , the magic by explaining the unusual framework in nent count yet including many features of today's which the computer was denigned. personal com puter.t for the fi rst timeereron a lowcost The Apple II was detiigned as an interenting hobby computer. These features inclifde dynamic RAMs, project to "show off" at the local computer club. Only video terminal appearance, plastic case, BASIC in one or fico were intended to be built, and then far a ROM. color, hi-res graphics, paddles, speaker, market of one (myself). Component selection was switching power .Hupply, and more. Normally, large biased by what was easy to obtain and affordable. successful companies generate good product.einpr unit with asmall Iwdyamianumberofmetalpin.iorleads. andit executed: when a peripheral card performs DMA, when a pe- contains complex electronic circuitry inside. If you took inside ripheral card deactivates the READY sifrnal. and when the the Apple, you will see many little black chips plugped into RESET key is held down or the RESET' line i.^ otherwise held sockeUion the motherboard. The bittfcestof these chips theB502 i."! low. These special cases are e.xplaine(i in detail in later chapters. MPU. The Apple II— An Overview 1-3 Chapter 3. Until we ^et to that point, just say that Most locations which the MPU addresses are the 6502 operates at about 1 MHz. This, inciden- memory locations. Memory contains the stored tally, is slow by modern microprocessor standards. program which the MPU is executing and about There are 3 MHz 6502 MPUs available now, and half of the MPU's time is spent fetching that pro- other MPUs have faster clock pulse rates than that. gram. The program is stored sequentially, so fetch- With a given MPU, the faster the clock, the faster ing the program by the MPU simply involves the execution speed. incrementing the address output while reading the The structure of the Apple is that of multiple data input and interpreting it as a sequential pro- devices which can communicate with the MPU. gram. While not fetching the program, the MPU is Onceevery clockpulse, the MPU outputs the address executing it. This execution involves logical manip- of the location which is being communicated with, ulation of data, storage of data at or loading of data and it transmits data to or receives data from that from addressed locations determined by the pro- location. The addr^s which the MPU is putting out gram, changing the program fetching location to Apple is distributed to all addressable devices in the somewhere other than the next sequential address, via the address bus and data is transferred between or any combination of these and other functions. the MPU and the addressed location via the data Not all locations addressed by the MPU are bus. Associated and distributed with the address bus memory locations. Program instructions fetched is the read/write control output of the MPU. Read/ from memory may cause the MPU to address non- write control tells the addressed location whether memory locations such as the speaker or keyboard. data will be read from it or written to it. A memory Ification responds to a read at its address The 6502 has 16 address outputs, each connected by placing data on the data bus. The speaker * responds to a read or a write at its address with to one line (e ectr ical conductor) of the address bus. I It controls the 16 address lines and the read/write sound. The MPU thus controls the speaker via the line together by placing a high or a low voltage on address bus in an address decoding process. Ad- each line. The simultaneous condition of the 16 dress decoding is the only way a 6502 can control address lines is the 6502 address. The 6502 address other devices, so all programmed control of Apple is a number between $0 and $FFFF (65535), and the devices is via address decoding. 6502 can access any one of the $10000 (65536) addressed locations in that range. Memory The 6502 has eight data input/output lines, each General purpose microcomputers require two connected to one ine of the data bus. It controls the 1 types of memory— memory you can change (RAM) eight lines when writing and monitors the eight and memory you can't change (ROM).* RAM is lines when reading, and the simultaneous condition necessary so you can store general programs and of the eight lines is the 6502 data word. Like the data. ROM is necessary so the computer has a pro- address lines, each of the data lines is brought to a gram to run when it is first turned on. high or a low voltage when information is passed. Both ROM and RAM are random address memo- Each line can be one of two states (high or low), so the ries meaning any specific memory location can be information is said to be two state, or binary. Other accessed at its specific address. Computer memory common ways of referring to the two states of binary is like thousands of light bulbs, each of which may or information are true/false, one/zero, and on/off. may not be glowing. If the memory is random A unit of binary information is a bit. Whether a access, the microprocessor can communicate with line is high or low at a given instant is a bit of any light bulb it chooses by calling its number. It information. The 6502 reads or writes and manipu- can, for example, check if light bulb number 25,765 lates information eight bits at a time and is there- is glowing or not. This is analogous to reading fore classified as an 8-bit MPU. A group of eight bits memory. Telling light bulb number 7,682 to not is a byte. The 6502 manipulates and transfers data, glow is analogous to writing to memory; the MPU is one byte at a time, to an addressed location in the altering the state of light bulb 7,682. RAM and ROM Apple bus system. are functionally identical except that ROM is fixed As described in Chapters 2 and 4, the 6502 is not connected *ROM stands for Read Only Memory, which is accurate, and directly to the address bus and data bus. It is connected to the RAM stands for Random Access Memory, which is the most DM buses through isolating devices which jjive the Apple 1 1 a A famous misnomer in all of computer jargon. Both read only (Direct Menoory Access) capability and allow the 6502 to com- memory and read/write memory in the Apple are random access municate with the large number of electronic devices connected memory, and this book refers to them by their conventional to the address bus and data bus of the Apple 11. labels. ROM and RAM. M Understanding the Apple II as if it was etched in stone. You can't turn the light plugged. Behind the slots are hundreds of wires con- bulbs on or off. You can only check to see if they are necting the slots together in accordance with the de- on or off. sign purpose. Card cage architecture is like a house The MPU can not really tell whether a iig-ht bulb with an intercom system. Just as communication is is glowinff or not, but it can tell whether the voltage possible between various rooms of the house, com- on a line is high or low. RAM is capable of storing the munication is possible between the various cards high/low state of its data input when the MPU plugged into the card cage. Each slot in the card writes data to a RAM address. Both RAM and ROM cage is a different station in the intercom system. are capable of bringing their data outputs high or In a card cage microcomputer, part of the wiring low in accordance with stored data when the MPU which interconnects the slots is a multiline address reads data from a RAM or ROM address. In a posi- bus and data bus, similar to the buses on the Apple tive logic system like that of the Apple, storing or II motherboard. A microprocessor board can be reading a high voltage is thought of as storing or plugged into any slot, from where it can control saving a "1". Storing or reading a low voltage is communication in the card cage via the address bus. thought of as storing or saving a "0". A very nice modern card cage micro would have a Since the 6502 is an 8-btt MPU, memory must be multifunction single board microcomputer in one organized so that it is accessed eight bits, or one slot and a variety of devices in the other slots. The byte, at a time. The Apple motherboard has sockets Apple is exactly that computer, turned inside out. , for 49,152 bytes (393,216 bits) of RAM. This is nor- Instead of mountingthe main logic board inthecard | mally referred to as 48K of RAM meaning 48 Kilo- cage, they mounted the card cage on the main board. bytes. The Apple uses dynamic RAM vvhich must The Apple "card cage" consists of eight periph- be refreshed. Memory refresh must occur on a eral slots mounted on the back of the motherboard. periodic basis or dynamic RAM will not work. It's The address bus and data bus are connected to all like a fire that goes out unless someone is constantly the slots, maki ng them addressable extensions of the pumping the bellows. Dynamic RAM is n ice because Apple's basic communication system. Each slot has it's inexpensive, but it requires a lot of external a part of the 6502 address range assigned exclu- circuitry to support the refresh requirement. The sively to it, so the programs can make the 6502 Apple motherboard fully addresses and supports access a peripheral slot just as if it were a group of 48K of RAM in every way including refresh. memory locations. The Apple motherboard has sockets for 12.288 Some important 6502 input control signals are tied bytes (98,304 bits) of ROM, commonly referred to as to pins on the peripheral slots. They are RESET', 12K. Each ROM chip contains 2K of information so READY, NMr(Non-Maskable Interrupt), and IRQ' there are six sockets. 2K are taken up by the moni- (Interrupt ReQuest). These signals are all described tor ROM. This chip tells the Apple what to do when in greater detail in the 6502 section of Chapter 4. it turns on and contains valuable utilities which Their connection to the peripheral slots means that make the Apple hardware accessible to its user. The the processor can be interrupted, stopped, started, rest ofROM is taken up by either Applesoft or and reset from any peripheral card. It also means Integer BASIC. Applesoft is the newer BASIC that any peripheral card can be designed to respond written by Microsoft Corporation for the Apple. to these control signals. For example, pressing Integer BASIC is the original BASIC written for RESET at the keyboard resets the 6502 and addi- the Apple. Integer BASIC is a smaller program tionally turns off the floppy disk drive. The disk than Applesoft so there are two empty socketsROM drive controller is designed to respond to the RE- perm itting a total of 4K of user ROM on the Integer SET' signal which occurs when RESET is pressed. machine. The Apple with Applesoft on the mother- RESET', incidentally, is read "reset prime." In this board ROM is referred to as the Apple II Plus to book, the prime behind the name of a logic term is distinguish it from the Integer Apple. This book used to signify that a signal is active or true when a refers to both machines as the Apple or Apple II. low voltage is present* It is an aid to understanding Peripheral Slots •Most published computer literature will overscorea logic term, rather that placin^a prime symbol behind it. tosi^ify that it is The Apple peripheral slots are similar to a card active when law. In usingr the prime notation, Uit/f' cage. What is a card cage? A card cage is a very | n<' Rffoviici' AfaiiiKil. [n addition to signifyinBr that a term is versatile physical package for microcomputers and active when low. the prime symbol following a logic term can other electronic circuits. It is a row of slots mounted mean that the inversion of that loffic term is being referred to. close together into which printed circuit cards are Please see AppendLVL E for further discussion of this subject. The Apple ]l— An Overview 1-5 the logic functions of a given signal. Knowing this, All video modes use memory scanning to generate you could guess from the second sentence of this video. This means that certain areas of RAM are paragraph that the 6502 is interrupted and reset by designated as display memory. The designated areas low voltages on the NMl', IRQ', and RESET' line are: and enabled by a high voltage on the READY line. Another peripheral slot signal which affects the 6502 but isn't connected directly to it is the DMA' TEXT/LORES Page 1 400-7FF - (IK memory) signal. DMA stands for Direct Memory Access TEXT/LORES Page 2 - 800-BFF (IK memory) and refers to direct memory access from the periph- HIRES Page 1 - 2000-3FPF (8K memory) eral slots. The DMA' line does a bit more than giving HIRES Page 2 - 4000-5FFF (8K memory) the slots access to memory, however. It allows a card in a slot to isolate the 6502 from the address bus and data bus and take control of communication in the As an example, assume that the computer is in bus system. This means that a peripheral card can TEXT mode. PAGE 1, Then memory in the range control all hardwarefeaturesof the Apple. It is as if $400-$7FF will be scanned approximately 60 times you could plug a Suzy brain into Johnny and have a second and the data in that memory area will be the Suzy brain control Johnny's body, a concept processed for video output. Part of display memory much in vogue in some circles. is always being scanned while the computer is on. There are signals connected to the peripheral slots The Apple is designed so that this constant scanning other than those that have been mentioned. They satisfies the refresh requirement of the dynamic provide various capabilities so peripherals can be RAM. designed to be fully integrated into the Apple struc- An important consequence of the Apple's display ture. These signals include timing and control implementation is that the video display steals inputs, power supply voltages, and control signals memory from the user. The programmer must pro- decoded from address ranges on the address bus. gram around the display areas if he intends to use The purposes of these signals will be fully explained the associated displays. in later chapters. Scanning for video output is not performed by the MPU. It is performed by the video scanner, also Video Output referred to as the video scan counter or video syn- The primary output of the Apple 11 is video. chronizer. Signals from the video scanner are used The video is compatible with the video in an Amer- to develop television sync which means that the ican TV set. Motherboard "Eurapple" jumpers can memory scan in the Apple and the electron beam change the video for black and white compatibil- scan in the television tube are in sync. Memory ity with European TV systems, but a "Eurocolor" is scanned one time for every time the picture is card in slot seven is necessary for European color scanned. compatibility. The scanner accesses RAM in a way that is com- The problem with video output is that the input to pletely transparent to the MPU. During the first a television is not video but RF (Radio Frequency) half of every 6502 cycle period, the video scanner modulated by video. This means that you can use the addresses RAM. During the second half, the 6502 Apple with a television set, but the input to the addresses RAM. The scanner access to RAM is television must be an RF signal modulated by Apple always a read access and the data which comes from video. Generation of the RF signal and modulation is RAM during the scanner access is processed by the accomplished in a user supplied modulator. Another video generator to make video. The 6502 access can name for the user supplied modulator is a pain in the be either read or write and, on some cycles, the 6502 neck. may not access RAM at all. When the 6502 does There are three basic Apple video modes: TEXT, access RAM, RAM is accessed twice every 6502 LORES graphics (LOw RESolution colored blocks) cycle and is therefore accessed at 2 MHz. and HIRES graphics (High RESolution colored The programming method for controlling the points). Thedisplaysarestored (mapped) in memory Apple display is to compute or look up the address of so that video is generated by processing data from the desired screen location in the appropriate mem- memory. ory display area and modify that address to the 1-6 Understanding the Apple Figure 1 .1 TEXT and LORES Graph Ics. programmer's purpose. The video scan ner scans the LORES blocks and one text character as shown in display area determined by the display mode and Figure LI. the resulting memory data is processed as text or HIRES graphics is a programmable array of 280 graphics as determined by the display mode. columns and 192 rows of dots. Because of the way Text is stored in ASCII code (American Standard video is generated in the Apple, the color of any dot Code for Information Interchange). In addition to is dependent on its horizontal position. To draw a ASCII, code for norma! display (black on white), violet horizontal line, for instance, every other dot in inverse display (white on black), or flashing display one row is turned on. To draw a violet figure, only (alternating normal and inverse) are stored for each half of the columns of dots can be turned on. This is text character. One character is stored per byte of also true of the other HIRES colors; green, orange. display memory. As text is scanned, the coded data and blue. There is only 140 x 192 resolution when from memory is translated to 5x7 dot matrix video drawing these four colors. White (the absence of in normal, flashing, or inverse format. There are 64 color) and black (the absence of luminance) can also displayable text characters (one is the space). be displayed. The 280 dots in any row are divided The TEXT display is 40 columns by 24 lines. Only into 40 groups of seven dots. Each group of seven uppercase is available on older Apple ILs but new dots may be shifted together horizontally one half of ones have upper/lower case screen capabilities.* A a dot position, changing the colors of anv colored variety of 80 column upper/lower case display dots in that group of seven. Thus, there are 560 boards are available for the peripheral slots, horizontal dot positions in each row but only 280 dots LORES graphics is a programmable display of 40 are independently programmable. This brief state- columns and 48 rows of colored blocks. Each block ment of HIRES graphics capabilities is probably can be any one of 15 colors including black and just enough information to let the reader know that white. Apple claims 16 colors but the two grays are the subject of HIRES is complex. Full understand- identical in color and luminance. LORES is mapped ing is possible in the light of more detailed analysis in the same display area as TEXT so memory scan- and HIRES is covered in greater detail in Chapter ning is identical in the two modes. In LORES, 8. For now. let us summarize the graphic resolution rather than converting ASCII to video, the video of the Apple II screen as follows. There is 140 x 192 generator processes the bit pattern directly into dot resolution in six colors. There is 280 x 192 dot video. The code for each LORES block requ ires four resolution if color is ignored. There is 560 x 192 dot bits, thus there is code for two blocks in every byte of resolution for some applications. display memory. Also, there is a direct correspon- The HIRES memory display area is much larger dence between the screen location of a pair of than the TEXT/LORES area: 8192 bytes for a single display screen. This is the hardware cost of high *In Revision 7 ant! later Apples, an upper/lower ease screen di.splay capability can be realized by replacinfr the A.'! TEXT resolution. Each byte of display memory contains ROM. Please refer to the related Application Note at the end of the on/off conditions of seven dots plus the shift Chapter S. control bit which determines whether that group of The Apple It— An Overview 1 -7 seven dots is shifted half a dot or not. Durini? the II spends the majority of its life cycling through a HIRES memory scan, the data from memory is little firmware routine called KE YIN. This routine essentially shifted straight to the monitor or televi- samples the keyboard to see if a key has been pressed sion modulator via the VIDEO output line. and increments a random number counter. It checks Apple programs select the video mode via four the keyboard at a rate of about a quarter of a billion programmable toprgle switches, or soft switches. times an hour. If anyone asks you what an Apple The four video mode soft switches are: does, you can answer "mainly, it checks to see if a key has been pressed." Enough silliness. The keyboard input ia upper- GRAPHICS/ TEXT case only and there are a total of 52 keys on it. LORES/ HIRES SHIFT keys shift between numerals and symbols. PAGE 1 / PAGE 2 WhileSHIFT-M, SHIFT-N, and SHIFT-P produce NOMIX/ MIX codes which are interpreted as special characters, other alphabetic characters produce the same code whether SHI FT is pressed or not. The layout of the The first two svi^itches select TEXT, LORES keys is like it is on a teletype. This means that the graphics, or HIRES graphics. PAGE 1/PAGE 2 alphabetic and numeric characters are arranged simply selects between a primary memory display like those on a typewriter, but some of the symbols area and a secondary memory display area for each are in rather strange places. Keyboard input to the mode. PAGE 1 is normally used in all modes, but use computer is ASCII. Since the keyboard input and of PAGE 2 may suit the programmer's purpose. The text output are both ASCII, it is fairly easy to dis- most common use of alternate page displays is to play characters on the video as they are entered eliminate flicker in graphic animation. The pro- from the keyboard. This is done by keyboard input grammer updates an animated picture on the page routines in the Apple firmware. There are. however, that isn't being displayed, then changes the display three screen displayable text characters which can- by switching pages so that the updated picture is not be input from the keyboard. They are left displayed. PAGE 2 of TEXT is rarely used because bracket, backslash, and underscore. it serves little purpose, is not supported by firm- Special function keys on the keyboard are ESC, ware, and interferes with BASIC. PAGE 2 of CTRL, SHIFT, RESET, REPT. RETURN, left LORES graphics is rarely used for the same reasons. arrow, and right arrow. CTRL and SHIFT mod- The fourth programmable switch is MIX/NO ify the ASCII produced by other simultaneously MIX. MIX refers to mixed text and graphics. If pressed keys. RESET is tied to the 6502 RESET' in- MIX is selected and GRAPHICS is selected, there put. REPT causes any simultaneously held key to be are four lines of text at the bottom of the screen and repeated about 10 times a second. ESC, RETURN, LORES or HIRES graphics on the rest of the left arrow, and right arrow produce ASCII which screen. This is very useful, as far as it goes, because must be interpreted by the controlling program. The there are many times when the graphics program- code for ESC is unique, but RETURN, left arrow, mer needs to enhance a display with text. Four lines and right arrow are identical to CONTROL-M, at the bottom turn out to be inadequate for many CONTROL-H, AND CONTROL-U respectively. purposes, though. The HIRES screen has good In summary, the Apple II keyboard is notable enough resolution to draw text, and several pro- only for its limitations. These are: upper case only grams are available that make it relatively easy to alphabet, lack ofdedicated cursor move keys, lack of place upper/lower case text on the HIRES screen user programmable function keys, and lack of a via graphics. This type of text can be drawn along- numeric entry keypad. It is a little league keyboard side graphics to enhance graphic displays. on a big league computer.* The Keyboard The keyboard is the primary human input to the *The keyboard of the Apple lie is preatly impr-oved over the Apple II (as opposed to storage media input such as earlier Apples. The author's negativeoverallopinionof the Apple disk or cassette). Virtually all human alphanumeric 11 keyboard applies only to Apple 11 computers that predate the input is viathe keyboard, and the MPUof the Apple Apple He. 1-8 Understanding the Apple Other I/O are not TTL ports and really are not very useful for I/O is Input/Output. Our point of reference for transfering general digital information to anything this discussion is the motherboard, meaning that we but a tape recorder or other audio device. TTL de- speak of input to the motherboard and output from vicesoperate with two voltages corresponding to the the motherboard. The peripheral slots give the two states of digital logic. The TTL low voltage is Apple an extremely versatile I/O capability, but to 0.8 volts. The TTL high voltage is 2.4 to 5 volts. there is a good deal of additional I/O circuitry built These are the two voltage levels which represent into the Apple, The key board input and video output digital information throughout the Apple. are the most significant motherboard I/O. Addi- There is a 16-pin DIP (Dual In line Package) tionally. there are some useful serial I/O ports. socket on the Apple motherboard which is generally Serial data is data on one line. This is opposed to calledthegame I/O connector. A set of two paddles parallel data on more than one line (eight lines for or a joystick is normally connected here but there is instance). To transfer eight bits serially, each bit of a capability for multiple uses. Four of the pins are information is placed on the same line one after the annunciator outputs. These are independently pro- other. This takes eight times as long as an 8-bit par- grammable TTL levels. The programmer can make allel transfer but requ ires on ly one connecting wire. each level go high or low at will. A fifth TTL output The keyboard is a parallel input. The video is not a is called a strobe. This output is high unless a pro- simple digital output but a mildly complex signal gram triggers it. It then goes low for just 0.5 output with a serial data component. In addition to microseconds (half a 6502 cycle) then returns to its these I/O capabilities there are eleven serial I/O normal high state. ports and four resistance sensitive timer inputs. There are three TTL input ports on the game I/O The speaker output is a serial output port con- connector which can be read by a program. Two of nected to a speaker through an audio amplifier. The these are normally connected to pushbuttons on the cassette input and output are serial data transmit- joy.stick or game paddle.s. ted via audio phone jacks on the motherboard The paddles themselves are just potentiometers accessible from the back of the case. They are (variable resistors). The joysticks are two potenti- designed to connect directly to the earphone output ometers in a special mechanical arrangement. These and microphone input of a common audio tape potentiometers are connected through the game I/O recorder. Firmware routines in the Monitor ROM connector to two of the four resistance .sensitive read and write cassettes in Apple's storage format. timers. The way this works is that a program resets Usage of 5 1/4 inch floppy disks is .so prevalent the four timers all at the same time. Under program that cassette storage is rarely used by most Apple control, the CPU can time and check when any or all owners. Floppy disk I/O is not a built-in capability of the timers have timed out. The time for any timer of the motherboard, so the disk electronics are con- depends on its resistance input from the game I/O tained in the drive and on a peripheral card called connector which is varied by the person massaging the di.sk controller. Disk data is transferred in the joystick. parallel between the MPU and the controller and The game I/O connector can be used for a lot more serially between the controller and the drive. Con- than games, but not easily. The multiple I/O on one trol of the disk I/O requires an extensive program, socket implies that any device which plugs into the and the most commonly used program of this nature socket should have a built-in extension socket so is the DOS (Disk Operating System) supplied by other devices can use the remaining I/O lines. Apple Computer, Inc. Unfortunately, no one designs them this way (see The other serial I/O signals are TTL (Transistor Figure 1,2). Originally, Apples were supplied with a TVansistor Logic) compatible. TTL is a very common paddle set which was two paddles, each with a logic family of integrated circuits used for digital pushbutton, connected to a single 16-pin DIP plug. logic. The logic devices on the Apple motherboard With these paddies plugged in, the remaining I/O— are either TTL or interface directly to TTL.* A TTL four annunciators, two timers, one TTL in. and one output port will communicate directly with TTL strobe out— becomes inaccessible. This seems to compatible devices. The cassette and speaker ports have set a "no extension" design precedent which has stifled the development of hardware for the *M()st()f thfTTLfhips in ihf A ppltNin- LSTTL(I^w f'owereci. game I/O connector. Such products as programs for Scholtky-BarriordiocleL-lampedTTL). ROM. RAM, ami lhe6502 four paddlesor two joysticks don't exist. If you want are TTL compatible MOS (Metal Oxide Silicon) chips. to measure temperature at a timer input, you must i The Apple II— An Overview 1-9 TTTTin ro ^4 %, Figure 1 2 How the Game I/O Plug Should Be Designed. disconnect your joystick and plus in your tempera- SUMMARY ture sensitive resistor, or buy a^ame I/O extender. Thus, in most installations, the game I/O connector The Apple II is a single board, 6502 based micro- is merely a socket for two paddles or a joystick with computer with built-in memory and video genera- two buttons. tion circuitry. The board contains eight peripheral card slots which give the Apple II expansion capa- The Power Supply bilities comparable to more expensive card cage Household power in the United States is 1 15 Volts microcomputer designs. AC (Alternating Current). Most of the circuits in the The 6502 operates at 1.0205 MHz. IRQ'. NMI'. Apple require +5 Volts DC (Direct Current). A RESET', and READY signals to the 6502 are con- powersupply isadevice which converts AC power to nected to the peripheral bus. The DMA' signal DC power. Televisions, stereos, computers and such enables peripheral cards to isolate the MPU from all have power supplies built in. the rest of the motherboard. This enables control of The power supply in the Apple generates +,5VDC. the Apple II from secondary MPUs or other DMA -5VDC, +12VDC. and -12VDC. These voltages are devices in the peripheral slots.MPU control of the distributed throughout the motherboard to any various hardware featu?-es is via address decode. device that needs them. Additionally, all four volt- The motherboard contains sockets and address- ages are available at the peripheral slots to supply ing for 49152 bytes of dynamic RAM. 12288 bytesof power to peripheral cards. Some Apple lis were firmware include Applesoft or Integer BASIC and a supplied with a 110VAC/220VAC switch for com- system monitor containing a number of important patibility with foreign household power. utilities. 1-10 Understanding the Apple The video output is compatible with a video so, while the 6502 operates at 1 MHz. RAM is monochrome or color monitor. It can be used with a addressed at 2 MHz. In the process of scanning home TV when connected throug'h an inexpensive memory for video output, the memory is refreshed. modulator. Text is upper case only. 40 characters by In addition to I/O capabilities inherent with the 24 lines. 5x7 dot matrix representation. Graphics peripheral slots there are: a cassette input port, a modes include 40 by 48 LORES block mode in 15 cassette output port, an on board speaker, four TTL colors. 140 by 192 HIRES point mode in six colors, control outputs, one .5 microsecond TTL output and 280 by 192 HIRES point mode in black and strobe, four resistance sensitive timer inputs, three white. Some capabilities exist for mixing text and TTL inputs and a keyboard. The keyboard contains graphics. The video display in all modes is mapped 52 key switches with uppercase only on alphabetic in certain areas of RAM. Video display circuitry characters. continuously scans one of four possible memory The built-in Apple power supply provides +12V. areas while memory output is processed to generate -12V, +5V. and -5V. These voltages are distributed video. RAM addressing is time shared between the throughout the motherboard and to theeightperiph- system address bus and the video scanner. 6502 eral card slots. access toRAM alternates with video scanner access chapter 2 The Bus Structure of the Apple II There are many signals distributed throughout are collectively referred to as a bus. Physically, the Apple II, but the most fundamental data trans- then, a bus is an electrical distribution of multiline fer takes place on the data bus. and the most basic information. In the Apple, the address bus is a control information is distributed via the address sixteen line electrically distributed information bus. To understand how the Apple and other micro- group, and the data bus is an eight line electrically computers really work, it is very important to distributed information group. understand the bus structure. Fortunately, it's not Some devices connected to a bus are strictly that hard to understand. The basic concepts of the receivers of information. ROM is like this in its con- bus structure are within the pfrasp of nearly every- nection to the address bus. Receivers respond to the one who uses a microcomputer. high/low information on the lines of the bus without The bus structure is a natural starting point for appreciably affecting the bus information. Electri- learning what really goes on inside the Apple com- cally speaking, the receiver input presents a high puter. Discussing the bus structure will lead natu- impedance to the bus which enables other devices to rally to the discussion of the other microcomputer bring the bus lines high or low. If impedance is a elements that the bus is connected to. First though, new word to you, it may help to think of high impe- we need to find out what a bus is and how it is used. dance as high isolation. Some devices on a bus must be information COMPUTER BUSES AND THREE STATE transmitters capable of bringing the bus lines high or low. If more than one information transmitter is LOGIC connected to a bus. each transmitter must be able to Logic signals in the Apple are distributed electri- disconnect itself from control of the bus by present- cally via conductive paths on the motherboard. ing a high impedance to the bus. Only one device can When a number of signals are grouped functionally control the bus at a time. Instead of two state, the and distributed throughout a microcomputer, they outputs of these devices are said to be three state or 2-2 Understanding the Apple II OUTPUT ENABLE LINE DRIVER Information is transmitted to the bus by a device with tri-state outputs. LINE RECEIVER An information receiver presents a high impedance to the bus. DIRECTION CONTROL LINE TRANSCEIVER A bidirectional connection to the bus must present a high impedance to the bus when in receive mode. Figure 2.1 A Hvpotheti^il Four-Line Bus. Bus Structure of the Apple II 2-3 ADDRESS BUS DATA BUS AND R/W R W MPU ROM W R RAM R/W Figure 22 Basic Microcomputer Building Blocks. 2^4 Understanding the Apple II tri-state. The three states are high voltage, low volt- when its voltage is low. Here is a truth table for the age, and high impedance. All information transmit- tri-state line driver shown in Figure 2.1: ters to the data bus of the Apple are capable of OUTPUT presenting these states to their bus connections. The ROM output to the data bus is a typical three state INPUT ENABLE OUTPUT output. Any Low High Impedance High High High A third type of device, capable of transmitting to Low High Low or receiving from a bus, is called a transceiver (transmitter / receiver). The MPU, for instance, The control line either enables the high/low output receives (reads) data from and transmits (writes) or forces the output to high impedance. The high/- data to the data bus via an eight bit transceiver. low output, when enabled, follows the input While the MPU is reading, the transceiver presents It can be seen that the output enable controls of a high impedance to the data bus so the addressed the various information transmitters are the key to device can place data on the data bus. While the cohesive control of the bus. For a bus with many MPU is writing, the transceiver controls the data possible information transmitters, like the data bus bus. of the Apple, there has to be some intelligent man- Figure 2.1 shows a hypothetical four line bus. The agement of the various tri-state output enables. We symbols shown are schematic representations of a will see shortly how this is accomplished. In the tri-state line driver, a line receiver, and a line trans- followingdiseussions, remember that when a device ceiver. A triangle represents a single line driver. like a ROM chip responds to an address prompt by Triangles with a control line coming in from the side placing data on the data bus, this is accomplished are tri-state line drivers. A little circle at a control via an output enable to the tri-state outputs of the input to a triangle means that the input is active ROM chip. ADDRESS DATA AOORESS DATA BUS BUS BUS BUS A READ CYCLE A WRITE CYCLE Figure 2,3 Communication on the Bus System. Bus Structure of the Apple II 2-5 Figure 2.2 shows a highly simplified diagram of Apples in particular perform their functions in a the bus structure of the Apple II. There are two bus environment. distinctmultiiinesipnal paths: the address bus and the data bus. The R/W line (Read/ Write control) is THE PIGEONHOLE COMPUTER shown separate but in the same color as the address There is an old analogy for understanding digital bus. R/W can be thought of as an extension of the computer operation which you don't see often enough address bus controlli npr the direction of data flow on in personal computer instruction literature. It pos- the data bus. Communication takes place on every sibly is not that helpful for understanding BASIC 6502 cycle between the MPU and an addressed programming, but it is very much like the way a device. Dataflows between the MPU and the device microcomputer works. in a direction determined by the R/W line. The The analogy goes like this. A computer is like a MPU controls the R/W line and the address bus. gigantic row of pigeonholes with pieces of paper in Figure 2.3 shows the two types of busaecess which them. Each piece of paper has an instruction on it. occur in the Apple II. In a read access, the MPU There is a man who goes to each pigeonhole, one places an address on the address bus and reads the after the other, reading the instructions and doing data bus. In a write access, the MPU places an what they say. The man always gets the next address on the address bus and places data on the instruction from the next pigeonhole in the row data bus. This establishes a system of data bus con- unless an instruction tells him to go to some other trol that had to be implemented in the design of the pigeonhole. Apple. The control system works like this: That's the pigeonhole computer. The man is exe- 1. When the R/W line is low (write access), all cuting a stored sequential program. The man is the inputs to the data bus are disabled except the microprocessor. The row of pigeonholes is computer MPU. memory. The instructions are the program. The 2- When the R/W line is high (read access), all microprocessor issmartenough to sequence through inputs to the data bus are disabled except the memory and do what it's told, but it has to be told. It device which is addressed. has to have a program. This system concept keeps traffic flow orderly and is THE MPU, RAM, AND ROM a basic feature of microcomputer design. The only remaining points to be made about buses The microprocessor is the engineering marvel involve semantics. The peripheral slots are some- which made all the home computers possible. The times referred to as the peripheral bus or the 6502 MPU is what executes the programs in the Apple bus. In fact, the wiring of the slots fits our Apple. Viewed from the outside, its capabilities description of a bus as a functional group of distrib- include manipulation of the address bus and R/W uted signals. The slots are a bus whose distributed (Read/Write') control, writing data to the data bus, signals include the address bus. the data bus, and reading data from the data bus, logical and arith- other signals. Up to this point, the discussions have metic manipulation of data, and response to various avoided calling the slots a bus only to avoid confu- control inputs. These all add up to execution of a sion between the card cage bus and the more basic sequential program that comes from the data bus. address bus and data bus. The connections to the You see, the man from the pigeonhole computer RAM and ROM chips form two more distributed resides inside the MPU, The little guy has got this signal groups that can accurately be referred to as control line called R/W and he can put any address the RAM bus and the ROM bus. This book will from to 65535 on the address bus. He uses the R/W continue to use the word "bus" to refer to the address line to tell the outside world whether he's reading bus. the data bus, and the extensions of these two from or writing to the data bus. He uses the address basic communications paths. The peripheral bus. bus to tell the world where he wants the read data to RAM bus, ROM bus. and other distributed signals come from and the write data to go to. There are will be referred to using other terminologj'. plenty of things this man can do, but his most favor- By this time the reader should understand the ite thing in the whole world is to increment the conceptof the bus as a communication path. We will address bus and read the results on the data bus. now move on to how microcomputers in general and While he's reading, this little workaholic interprets 2-6 Understanding the Apple the data he reads as instructions. If there is an out- routine. This is an essential feature of microcompu- sidedevice that is responding to his address prompts ter design — the power-up routine in ROM. You with a valid sequential program, he will flat out might say it guarantees that the 6502 always gets execute the program. This means that you can out of bed on the right side. exploit his insatiable reading appetite and get him The other routine which a microcomputer always to do what you want if you're smart enough. That's has in ROM is a routine to load data from a storage all any microcomputer designer ever really expects device into RAM so that execution of saved pro- from an MPU- grams is possible. The Apple, however, has much The key requirement above was an outside device more than the bare necessities in its 12K of ROM responding to the address prompts. This device is space. The naked Apple is a cassette based system memory: ROM or RAM. Allof theaddressingon the in which BASIC in ROM and a system monitor Apple address bus is parceled out to var iousdevices. in ROM prevent unnecessary user aging while RAM gets addresses $0-$BFFF. ROM gets $D00()- waiting for the computer to become operational $FFFF. The peripheral slots are controlled bv at turn on. BASIC in ROM was an important $C080-?CFFF. $CO0O-$C07F is divided up among development in the popularizing of cassette based the keyboard and cassette and all the other built-in personal computers. devices. If the 6502 happens to be executing a pro- gram in the $D0O0-$FFFF range, then ROM is responding to the addressing with a series of data ADDRESS DECODING which the 6502 is interpreting as a program. If the Inside RAM and ROM. some pretty sophisticated ROM program tells the MPU to store a byte of data address decoding goes on so that data communica- MPU takes a microsecond to bring R/W at $400. the tion is with the correct memory location. Each RAM low, set the address bus to $400. and place the perti- chip in the Apple II has a capacity of 16:^84 individ- nent data on the data bus. The data is accepted by ually accessible bttsof information. Needless to say, address location $400 which is in RAM. That much of the circuitry in the memorychips is devoted pigeonhole of RAM owns address $400,iost as sure to decoding the address input. as your mailbox has a unique mailing address. Like memory, but on a much smaller scale, the Inside RAM, inside ROM, all along the address bus, Apple motherboard must decode addresses to con- address decoding takes place every 6502 cycle to trol its various functions. As has been stated pre- enable only one of 65536 possible addresses. viously, the address bus and R/W line are the way in The 6502 is continually executing a program which the 6602 commands the Apple devices to do while power is applied. If it gets lost and tries to things. There is a group of logic circuits on the execute a program where no program exists, it motherboard which detects certain addresses or interprets whatever jibberish is appearing on the address ranges, then outputs control signals to var- data bus as a program and executes it anyway. An ious functional areas of the Apple. The following unstoppable program-executing machine like this types of control are performed by address decode: has to have a starting point when you turn the com- puter on. It also needs a way to start from scratch 1. Gating(enabIing)of information to thedatabus, when it gets lost. This starting point is the RESET' including data from serial inputs.* 2. Direct control of serial output lines. input to the 6502. 3. Control of peripheral slots. The RESET' input to the 6502 goes low when the RESET key is pressed, when a peripheral card 4. Video mode control. makes it go low, or when the computer is turned on. Control by address decode gives cohesion to the bus Any one of these occurrences makes the 6502 stop structure. what it's doing, load the address of the next program The address and control functions of the address step from locations $FFFC and $FFFD in ROM, bus are not separate entities but different ways of and start executing at its special address. The con- look ing at the same th ing. Addressing memory loca- tents of $FFFC and $FFFD are the low and high tion $95FF can be thought of as controlling that bytes of the reset vector.* The reset vector in the memory location. Similarly, control of the cassette Autostart ROM is $FA62, the address of the reset output line may be thought of as addressing it. The address bus could be called the control bus. Two 8-bit RAM locations are required to store a Ifi-bit B502 address. The B,502 fetches a 16-bit address from art adjacent pair *When a digital siprnai ctintroli>l(' U the lines of the data bus are referred to as DO through D7. and the ines of the address bus are I other address commands perform the functions of referred to as AO throufrh Alh. D7 is the line nhich carries the motor control, drive selection, read/write configu- Bttstsigrnificant bit of dataon the data bus. Alois the line which ration, and head positioning. These commands are carries the most significant bit of the address on the address bus. decoded on the motherboard and controller. The ••The SCOfiX notation is used to indicate the $C060-$C06F motherboard circuits detect the $COEX range on address: ranf^e. the address bus and activate a signal that tells Slot 6 2-8 Understanding the Apple it is being accessed. The controller decodes AO bus, and the multiplexed RAM address bus alter- through A3 of the address busto determine which of nately contains information from the address bus 16 possible commands it is being given. and scanner output. The actual programming of disk I/O is very com- plex, requiring timed intervals, data encoding, and extensive software housekeeping. Regardless of DMA and the MPU this, all MPU control of the disk is via Ifi address The MPU address, R/W, and data connections commands on the address bus, and ail data transfer are connected to the address and data bus via a 17 bit is over the data bus. tri-state line driver and an eight bit line transceiver. There is no motherboard ROM routine to load The main purpose for these devices is to enable the programs from a disk drive when the Apple is first CPU to drive (supply required signal voltages to) all turned on. A 256 byte program does exist on the the circuitson two buses, includingapossiblevariety controller card, accessible at addresses $C600- of peripheral cards. A second purpose of the address $C6FF (assuming slot 6), which loads the extensive driver is to give the MPUa tri-state connection to Disk Operating System (DOS) from disk to RAM. the address bus. This is necessary to isolate the MPU After power up, the motherboard firmware turns from the address bus during DMA operation, be- control over to this controller firmware to get the cause the 6502 address and R/W outputs are not DOS up and running. tri-state. DMA (Direct Memory Access) is achieved from a peripheral card when the card pulls the DMA' line low. This DMA capability is actually a direct bu.s access which gives the peripheral card THE SECONDARY BUSES command oftheentireApple.Pullingthe DMA' line low forces the 17 bit line driver to high impedance, Up to this point only the address bus and data bus stops the clock to the MPU, forces the data MPU have been discussed, and the bus diagrams have terminals to input mode, and forces the eight bit shown functional areas connected to these two buses. transceiver to input from the data bus. Unless it is In actuality, both the RAM chips and the MPU are stated otherwise, our following discussions assume connected to the address bus and data bus through that no peripheral card is performing DMA. This isolating devices. This creates secondary buses means that the normal situation exists in which the which carry address(contro!) information and data, MPU controls the data bus during write cycles and but which are not connected directly to the two always controls the address bus. primary buses. RAM circuitry, in particular, is much more complex than has been represented. The addressing and data flow shown in Figures 2.2 and RAM Address Multiplexing and 2,4 is accurate, but substantial processing details of Data Distribution the address input and data output of RAM were left Besides the MPU address and data connections, out so that the essentia! points of MPU access to the other secondary buses shown in Figure 2.5 RAM could beclearly made. We are now at a point in are concentrated around RAM, This complexity our discussion where these complexities should no surrounding RAM is a result of two factors: the longer be ignored. transparent video scan of memory and the natural Figure 2.5 is the Apple's bus structure, expanded complexity of addressing 16K dynamic RAM. from Figure 2.4 to show the video scanner, video We don't want to get too steeped in RAM address- generator, and full I/O capability. It can be seen that ing right now, but the basic situation is that there the secondary buses are not major distribution net- are not enough pins on a 16K dynamic RAM chip to works like the address bus and data bus. They are address KiK memory cells simultaneously.* The relatively minor connecting paths for address and RAM is addressed with aone-two punch. First, half data information that must be distinguished from of the address information is input to RAM where it the address bus and data bus. Connections to MPU is saved. Then the second half of the address infor- address and data, keyboard data. RAM output data, mation is input and the data access takes place. Both and latched RAM output data are basically exten- sions of the address bus and data bus. The video •Throujrhout thia b^iMm^''^W will be used to refer to a scanner output and multiplexed RAM address bus unit of memory thatStoftis orte bitOf data. The word "location" are more their own entities. The scanner output is will be used to refer to eight associated memory cells that hold addressing information unrelated to the address one byte Df data in the Apple II, Bus Structure of the Apple 1 1 2-9 ADDRESS BUS PLUS R/W DATA BUS n W Figure 24 The Apple II Bus Structure Showlr\g Disk, Caswtte, and Serial I/O. 2-10 Understanding the Apple ADDflESS BUS PLUS R/W DATA BUS ROM ENABLES' I/O STROBE' I/O SELECTS' DEVICE SELECTS' KEYBOARD ENABLE' KEYBOARD STROBE RESET SCREEN CONTROL SERIAL INPUT CONTROL CASSETTE OUTPUT ADDRESS BUS ADDRESS BUS EXTENSION SPEAKER OUTPUT ANNUNCIATOR OUTPUTS 3 OATA BUS DATA BUS EXTENSION C040 STROBE- TIMER TRIGGER VIDEO SCAN Figure 2S Secondary Address and Data Connections Exfend the Address Bus and Data Bus. S Bus Structure of the Apple II 2-11 the first half and the second half of the address are This multiplexor is switched off tri-state device. input on the same seven pins of RAM, so fourteen during 6502 write cycles and when neither RAM bits of information from the address bus nnust be nor the keyboard is being accessed. The rest of the multiplexed onto seven lines to effect the one-two devices on the data bus— ROM, the serial input punch. This multiplexing is accomplished in the multiplexor, and the MPU transceiver — all have RAM address multiplexor and the seven line out- three state outputs. put of the multiplexor is the multiplexed RAM The keyboard input, like the latched data from iddress bus, shown in pink in Figure 2.5. Inciden- RAM, is eight bit parallel latched information. The laily. the other two bits of information from the 16 keyboard responds to its address like ROM, by plac- bit address bus are used to select one of three possi- ing data on the data bus, so the latched input can be ble rows of RAM chips. read any time just like memory. The MSB (Most The two halves of dynamic RAM addressing are Significant Bit— K7 of K0-K7) is the state of the referred to as the ROW address and the COLUMN keyboard strobe flip-flop that tells the MPU when kidress. Th is refers to conceptual rows and columns any key has been pressed. The keyboard read s' memory cells inside the RAM chips, not the rows address is $COOX, and the strobe flip-flop reset lad columns of RAM chips on the motherboard. address is $C01X. The RAM addressing would be complex enough, bat in the Apple, the RAM address lines are doubly multiplexed. Both the video scanner and the MPU Video Scanning mnst access RAM, so during every 6502 cycle, first The video scanner is not connected to the address the video scanner output, then the address bus must bus and is therefore not controllable by the MPU. be switched on to the multiplexed RAM address bus. The scanner is completely isolated from program Each access is accomplished in two halves (the one- control and shares RAM on an equal footing with the r«-o punch). The RAM address multiplexing iscycli- 6502. The scanner is like a second MPU, but much :al. resulting in the following repeating pattern of simpler than an actual MPU. In microcomputer i^eess to the multiplexed address bus: jargon, it is a built-in DMA device performing simultaneous direct memory access with the MPU. Even though it is a read access as opposed to a Tl - Video ROW address write access, video scanner access to RAM is of a T2 - Video COLUMN address different nature than MPU read access. The MPU T3 - MPU ROW address reads data from RAM, meaning that the MPU T4 - MPU COLUMN address addresses RAM, and data from RAM comes back to the MPU. In contrast, when the video scanner Tbedata bus is connected to the RAM data inputs addresses RAM, the data from RAM does not come Im- writing to RAM. but the RAM output is routed back to the scanner. The data goes out, instead, to rh an eight bit latch and a tr i-state data multi- the video generator for video processing and to the >r to the data bus for reading by the MPU. The data bus, when R/W' is high, for processing by EaM data is latched (locked— held constant) twice peripheral cards. As a result, this book does not ry 6502 cycle, once from the scanner access and refer to the video scanner as reading data from e from the MPU access. Latched data is routed RAM Instead, the video scanner is said to drive . be video generator for video processing and to data out of RA M to the video generator and the data dita. bus through the RAM/keyboard data bus. xor. Other than the fact that the video scanner and MPU both address RAM, their only operational tie is timing. Just as the 6502 executes a machine cycle Umfboard Input once every microsecond, the video scanner changes I>:Lr!ng a 6502 write cycle, the RAM data latch its memory address and accesses RAM once every ir:2«: be isolated from the data bus so theMPU can microsecond. Logically enough, the timing for the ler^ the lines of the data bus high or low without video scanner and MPU originate from the same TEierference. The keyboard input, like the RAM source. In fact, all timing on the motherboard origi- acih. is not tri-state and must be isolated from the nates at the same source. The timing involved in the 13 when it is not being accessed. The dual sharing of RAM is quite elaborate and is covered in mon of multiplexing and isolation is performed the chapters on timing generation and RAM (Chap- RAM/keyboard data multiplexor which is a ter 3 and Chapter 5). 2-12 Understanding the Apple II The output of the video scanner is routed to the from the scanner access to RAM is sometimes pres- video generator, as well as theRAM address multi- ent on the data bus. This interesting feature is plexor. In the video generator, scanner data is used further discussed in Chapter 5, but for now, it is to make up television sync signals and to locate much more important to note that when the MPU which part of a text letter or LORES block is being performsa read accessto RAM, the RAM SELECT' scanned. signal is activated to gate the output of the RAM/ keyboard data multiplexor to the data bus. Thus, regardless of direct memory access by the video Serial I/O and Address Decode scanner, the basic response of memory to a read at Figure 2.5 shows a full summary of the control its address range is intact. The MPU puts the functions decoded from the address bus of the Apple address on the address bus, and memory responds II. Most of the control functions are concerned with data on the data bus. directly or indirectly with I/O features. It can be seen that the other serial I/O is imple- THE COMPLETED BUS STRUCTURE mented very much like the cassette I/O, Speaker, annunciator, and C040 STROBE' output !ines are This chapter has presented a series of diagrams of controlled directly by address decode in a process the bus structure, building in complexity and com- which ignores the data bus. The speaker is a toggle pleteness as we progressed from basic ideas to output like the cassette output. T?he programmer detailed structure. The final diagram in this series can toggle the high/low state, but he never knows is a foldout at the back of the book entitled "The Bus whether the state is high or low. The annunciators Structure of the Apple II." This diagram adds little are on/off outputs which can be brought high or low. to Figure 2,5 by way of explaining Apple operation, For example. $C058 makes ANNUNCIATOR go but itdoes show some final details about the address low, and $C059 makes ANNUNCIATOR go high. bus and data bus connections to ROM and RAM. The C040 STROBE' simply goes low for .5 micro- ROM is seen to be implemented in six chips, each seconds any time $C040 is on the address bus. then storing 2048 bytes of firmware. Externally, ROM is returns high. much simpler than RAM with straightforward The serial inputs are all input through the serial addressing from the address bus and tri-state out- input multiplexor to line D7 of the data bus. Any puts to the data bus. The 2048 bytes of each chip are address in the $C06X range gates the serial input addressed by the low order eleven bits (AO-AIO) of multiplexortothedatabus. AO, Al,and A2from the the address bus. The eight bit output of each chip is address bus are connected directly to the serial gated to the data bus by a signal from address input multiplexor and select from four timer inputs decode which signifies that an address in that ROM (paddles), three TTL inputs (pushbuttons) and the chip's address range was detected on the address cassette input. bus. The six ROM chips are normally referred to by Other address decoded signals gate the keyboard their base address, thus we have the DO (for $D000), and ROM to the data bus and control the peripheral D8. EO, E8, FO, and F8 ROMs. slots and screen modes. Screen mode control is Each RAM chip is organized 16KxL This means implemented by translating the video scanner out- that eachRAM chip has 16,384 1-bit memory cells, put to appropriate RAM addressing in the RAM one data input line, and one data output line. 6502 address multiplexor and by processing RAM data microprocessor structure requires that memory be output as text, LORES, or HIRES in the video organized for eight bit parallel data transfer, so generator. eight chips provide 16,384 8-bit memory locations in Some readers may have noticed that there is no a 6502 system. RAM enable signal coming from the address decode To make up the 49.152 bytes of Apple II RAM. 24 block of Figure 2.5. There has to be a RAM enable chips are laid out on the motherboard in three rows signal which tells the RAM/keyboard data multi- of eight chips. Each row is the equivalent of a 16 plexor when to enable RAM data to the data bus. kilobyte RAM device with eight input lines and There is a RAM enable signal, RAM all right, called eight output lines, and only one row is enabled dur- SELECT'. It is not decoded directly from the ing aRAM access depending on the address range of addressbus, however, RAM SELECT' is decoded in the access. Row C is .$0000-$3FFF, row D is $4000- the RAM address multiplexor from the state of the $7FFF. and row F is $8000-$BFFF. address bus and R/W during MPU access to RAM, Within each row, each chip is associated with a and it is always active during scanner access to separate line of the data bus. For example, in row C, RAM when R/W is high. As a result, data resulting chip CIO is associated with line 7 of the data bus. Bus Structure of the Apple II 2-13 Chips DIO and ElO are also associated with line 7. important in the effort to understand the Apple 11 Line 7 of the data bus is connected directly to the computer. It is hoped that the reader can become data input of chips CIO, DlO, and ElO, The tri-state comfortable with the concepts of information flow outputs of CIO. DIO, and ElO are tied together and within the bus structure, because this chapter is the routed to the bit 7 input of the RAM data latch. The foundation upon which all that follows is built. The latched bit 7 is routed to line 7 of the data bus when remaining chapters are devoted to a more detailed the MPU reads RAM and at other times detailed in discussion of the various functional areas of the the chapter on RAM. Distribution of the other lines Apple II, beginning with the important subject of of RAM data is identical to that of line 7. timing. Understanding these detailed discussions This completes the discussion of the bus structure will be much easier if the reader attempts to visual- of the Apple. The author feels that study of the bus ize how each area performs its functions within the structure diagram at the back of the book is very bus structure. i chapter 3 Timing Generation and the Video Scanner V .^t operational aspectsof the Apple 11 have now Understanding the Apple //is to assist those readers :iscussed within the context of the bus struc- who desire to do so to analyze the operation of the ever. this discussion has left out one of the Apple II in depth. For this reason, some technically ii'> most important operational aspects— oriented analysis aids are presented in this chapter Timing synchronizes everything that goes _-. and succeeding chapters. These technical aids will Apple. To discuss it, we must get into real - '.ne be accompanied by technical language. Every per- .15 and bolts detail about computer operation. son reading these words is capable of understanding Up to this point, the subject matter of Ihidvr- the technical sections, but some readers may not ling the Apple II has been of a general nature. wish to, and others will find it a struggle. Every «nempt was made in Chapters land 2 to explain effort has been made to assist all readers in achiev- f finer points of Apple II operation. Having ing fullest possible understanding from the least understanding of the Apple's bus structure, , possible effort. piaare largely aware of the methods of communica- By way of warning, the details of some functional SiiB and control that take place in this computer. areas are just plain difficult, but most of the areas Ifcrfollowing chapters will build on this foundation are pretty painless.* In particular, most of the com- rf »Bderstanding. examining and discussing the plexity of the Apple is concentrated in the and RAM ^Tiilrril features of all functional areas of the Apple RAM address multiplexor circuitry. Some other complicated circuitry, like the internal workings of perceptive reader is probably getting the mes- the MPU. will not be discussed at all. Besides the ttfaal the going is about to become stickier. This RAM circuitry, the most difficult topics probably k attempts to explain as much as possible about •peration of the Apple in understandable En- There comes a point, however, beyond which *Even though it is not part of the motherboard circuitry, disk I/O illustration is achieved only with such techni- is the subject of a chapter of [hKlvrxtumliiin tin- A p/ilc II. Readers s as liming diagrams, truth tables, logic dia- intrepid enoujrh to tackle this chapter will find disk I/O to be a and schematic diagrams. One of the goals of complex but interesting area of study. 3-2 Understanding the Apple -^ RAS' ) V5 . V4 V3 -1> -( CAS' ) V2 V1 TIMING VIDEO VO GENERATOR < ™ ) SCANNHI VC VB - { phased) VA - PHASE l) ( -( ^^ 14M ) , V ^ LDPS' ) ( - ( LD194 ) Figure 3.1 Functional Flow: The Timing Generator and the Video Scanner. are the details of timing and video generation. Tim- The timing generator controls the timing and ing comes next, so put on your overshoes— we're affects all areas of the Apple. By contrast only one going wading. external area affects the timing generator. That area is the video scanner. The timing feedback from the video scanner elongates one system clock period at the end of each horizontal television scan. TIMING OVERVIEW This elongation is necessary to keep colors consis- Thg important timing signals in the Apple II a!! tent from scan to scan. It also means the clock period originate at a small group of circuits called the tim- of the 6502 is not constant but is elongated on every ing generator. You should appreciate this when 6.5th cycle. This book will refer to this elongated studying the Apple, because it makes a difficult job machine cycle as the long cycle. Because of the easier. Interrelated digital timing originating from feedback from the video scanner to the timing gen- multiple sources can scramble your brains. With a erator, the two areas are covered in this single single timing source we can assimilate the timing chapter, sequences and then apply them to the various func- Apple timing originates with a 14.31818 MHz tional areas in the following chapters. crystal oscillator.The output of the oscillator, re- Timing signals are distributed to all areas of the ferred to as 14M, is a voltage which switches from Apple, but the Apple's timing requirements are low to high and back very close to 14,318,180 times determined primarily by RAM usage. RAM is every second. The reason for using 14.31818 MHz accessed alternately by the 6502 processor and the instead of 14 MHz is that 14.318,180 Hz divided by video scanner. Executing a stored sequential pro- four is 3,579,545 Hz, the exact frequency at which gram and generating a color television video signal color information is passed in a television set. All of are two entirely different tasks, but the two tasks the distributed timing signals are clocked by low to are synchronized in the Apple. As we shall see, exe- high transitions of the 14 M clock, so the exact fre- cution of this double task dictates certain factsof life quencies at which events occur in the Apple are about Apple timing. determined by a television signal specification. The Tinning Generation and thie Video Scanner 3-3 proximate frequencies at which some functions Q3 is a 2 MHz clock used only in timing genera- ur are: tion. It is available at the peripheral slots. LDPS' (LoaD Parallel in/Serial out register) is a video timing term that increments the video scanner APPROXIMATE and loads text patterns into a register for the pur- FUNCTION FREQUENCY pose of shifting the information serially to the video 65«J2 Cycle IMHz output. LDPS' occurs once every 6502 cycle. Video Scanner Increment IMHz LD194 (LoaD LS194) is a video timing term which Address Bus Access IMHz loads graphics data from RAM to two 74LS194 uni- RAM Access 2 MHz versal shift registers for video processing. LD194 COLOR REFERENCE 3.5 MHz occurs once every normal 6502 cycle and twice dur- Video Output 3.5 or 7 MHz ing the long cycle. AB of these frequencies are determined by outputs «f tbe timing generator. APPLE FREQUENCIES THE TIMING SIGNALS It is very hard tomake precise statements about This section is a very brief description of the tim- the frequencies of sonne signals in the Apple. This ^signats which are the outputs of the timing gen- is because of the clockpulse elongation which oc- oator. All these signals aredescribed in detail later curs every 65th 6502 cycle. 14M, 7M, and COLOR this chapter. REFERENCE are not affected by this elongation. PHASE is the 1 MHz clock input to the 6502. It PHASE 0, PHASE L Q3, RAS', CAS', and AX are also is used to define when an MPU address is valid, affected. aad whether the MPU or the video scanner is If not for the long cycle, the frequencies of all tim- stressing RAM. ing signals could be computed by dividing 14, 3 18, 180 PHASE 1 is PHASE inverted or PHASE 0'. by 14, 7, 4, 2, or 1. In actuality, this works for com- COLOR REFERENCE a tU MHz clockpulseis puting the fixed frequencies. 14M occurs at 14.31818 w«;ch is used to make up the color burst portion of MHz; 7M occurs at 7.15909 MHz: COLOR REF- Ae video output. The color of any Apple video is de- ERENCE occurs at 3.579545 MHz. The 1 MHz and iHTninetJ bv its phase relationship with the COLOR 2 MHz signals are less straightforward. IFERENCE signal. The period of time required for a 14.31818 MHz 7M is a 7 MHz clock used in the shifting of text signal to go through a complete high/low cycle is d HIRES video. It is also available at the periph- 1/14318180 seconds or about 69.8 nanoseconds (69.8 i sbts. billionths of a second). All synchronized durations in 14M is the output of the Apple's 14 MHz eloek- the timing generator are multiples of this time palse oscillator. It is used in timing generation and period which we will cal! the PERIOD for this the shifting of LORES video. As mentioned in the discussion. TIMING OVERVIEW, 14M is the ultimate source The normal 6502 machi ne cycle lasts 14 PE RIODS rf Apple timing. or about .978 microseconds. The long cycle lasts 16 RAS' (Row Address Strobe) clocks ROW address PERIODS or about 1.12 microseconds. There are formation to RAM and clocks RAM data output to three frequencies involved here: the primary fre- Ifce data latch. It occurs twice every 6502 cycle, once quency at which the 6502 is operated for 64 out of 65 1** MPL' access and once for video scanner access. cycles, 1.0227 MHz; the secondary frequency at CAS' (Column Address Strobe) clocks COLUMN which the 6502 operates for 1 out of 65 cycles, .8949 abdress information to RAM. CAS' is used in the M Hz; and the composite frequency which actually is Ajj^ to select one of three rows of RAM chips with the number of machine cycles per second, 1.0205 CAS' being routed to only one row per access. CAS' MHz. •ernrs twice every 6502 cycle. The 2 MHz signals are similar to PHASE except AX (Address Multiplex) is used in the address that only one of every 130 cycles is elongated. Their hiplexor to select ROW or COLUMN informa- normal duration is seven PERIODS or about .489 tiiB at the RAM address multiplexor. AX occurs microseconds. Their long duration is nine PERI- • everj' 6502 cycle. ODS or about .629 microseconds. 3-4 Understanding the Apple The durations and frequenciesof thesignalsof the Figure 3.2 is an idealized timing diagram in timing generator are shown in Table 3.1 below. The which voltages switch instantly and there is no delay values are arithmetic derivations of 14.31818, car- between input change and output response (propa- ried to ten place accuracy. Actual frequencies will gation delay). In an idealized timing diagram, cause vary as the 14M oscillator varies from 14,318, 180 Hz and effect timing relationships are clearly illus- due to thermal environment and crystal tolerance. trated instead of being obscured by the details of It is reasonable to wonder why the exact frequen- propagation delay. This is often desirable when cies in the Apple should be of any concern. In fact, studying theory of operation. for most purposes, the exact frequencies are not Figure 3,2 shows three 6502 machine cycles, two important. They are important when discussing tel- norma! cycles, and one long cycle. For each normal evision compatibility, because television signals re- machine cycle, there are one PHASE cycle, two quire some specific frequencies which are not exact RAS', AX, CAS', and Q3 cycles, three and a half multiples of 1 MHz. Frequency is also important in COLOR REFERENCE cycles, seven 7M cycles and so far as it affectsMPU execution speeds. Knowl- fourteen14M cycles. For reference, the period of edge of 6502 clock speed is very important for Apple 14M is about 70 nanoseconds and the period of a programs with precision timing loops. For the most normal PHASE cycle is about 978 nanoseconds. part, we will continue to refer to frequencies in very For 64 PHASE cycles, a repeating pattern of rough estimates such as 1 MHz or 3.5 MHz. timing signals is generated. There is an alternating phase relationship between COLOR REFERENCE and PHASE 0. The HO signal (see Figure 3.2) is the leastsignificant bit of the video scanner. When HO is TIMING DIAGRAMS low.COLOR REFERENCE is low when PHASE Timing is usually summarized in timing dia- makes its high to low transition. When HO is high, grams. Figure 3.2 is a timing diagram showing the COLOR REFERENCE is high when PHASE outputs of the timing generator and some related makes its high to low transition. Other than COLOR signals. The timing diagram is a series of line REFERENCE the timing signals have identical graphs of voltage as a function of time. Voltage relation to each other on every normal cycle, and the changes vertically in the diagram as time passes other HO'/HO normal cycle pairs are identicai to the from left to right. one pictured in Figure 3.2. In the following discussions of timing signals, the Every 65th cycle, while HPE' is low, generation of reader is encouraged to refer to Figure 3.2 as neces- the 1 MHz and 2 MHz timing signals is delayed for sary to clarify relationships in his own mind. Time one half of a COLOR REFERENCE period. This periods will be measured in millionths of a sec- keeps the phase relationship between COLOR REF- ond (microseconds) and billionths of a second ERENCE and the slower signals correct. This rela- (nanoseconds). tionship is required in the overall Apple scheme of Table 3.1 Durations and Frequencies of Timing Signals. NORMAL LONG PRIMARY SECONDARY COMPOSITE DURATION DURATION FREQUENCY FREQUENCY FREQUENCY | SIGNAL (nsec) (nsec) (MHz) (MHz) (MHz) PHASE 977.7779019 1117.460459 1.022727143 .89488625 1.02048432 RAS',AX.CAS',Q3 488.888951 628.5715084 2.045454286 1.590908889 2.04096864 COLOR REFERENCE 279.3651148 3.579545 7M 139.6825574 7.15909 14M 69.84127871 14.31818 Timing Generation and the Video Scanner 3-5 nji iRnnnnjTJumAJirLn. innimnfLTi^^ «£ C2-15 _r J— CM4 1 \ L 1 r C2-13 n \ 1 r "U^r 1 r C212 1 r BV10 ~L T" B1-7 B1-6 "L 013-12 2LJ DELAY' D24 1 r HSCAN = 0090000 014-H B1-3 HSCAN =1111110 j-~L_r~L_r HSCAN = 1111111 r-\ r~LJ— J \ — \ \ r I HSCAN =1000000 1 s~ B1-15 011-2 1 r B12-S _jn_ n rLTL SZT'CLE Figure 32 tdeallzed Timing Diagram for the Timing Generator. 62-4 nmirinnnnnjinjin/mruinjirinn^^ CMS _ _r~L I J — J — L_ C2-14 T n r 1 \ \ r- T r C2-13 _ 1 J \ r -1 \ \ r 1 i L_ C2.12 _ "U_^ \ 1 r I \ L B1-10 1 n. B1-7 91-6 _ 013-12 ~ iXW DELAY' DZ-6 1 r = 1111110 HSCAN = 0000000 HSCAN =1000000 m 014-H ~L HSCAN HSCAN -3111111 1_ I COLOB REF ai-3 J \ r-L r 711 B1-15 LOPS' 01 'Z -T L3194 B1?-8 T_ — J~L n -TLTL Se CYCLE Figure iZ Timing Diagram for ttie Timing Generator, Showing Propagation Delay. 3-6 Understanding the Apple generating color video. The delay extends the high DETAILED DESCRIPTION OF THE TIMING duration of PHASE and extends the low duration SIGNALS of RAS', AX, CAS'. Q3, and LDPS'. It also causes a double LD194 pulse and the extension of the current The following sections describe in detail how the 6502 machine cycle. The logic signal which delays signals of the Apple II are used. The distribution of timing generation is labeled COLOR DELAY' in these signals among the various functional areas of Figure 3.2. the Apple is shown Figure 3.5. Please refer to in The B1-Q2 signal in Figure 3.2 is a tinning sig- Figures 3.2 and 3.3 as needed while reading these nal used in generating PHASE 0. B1-Q2 is not a tim- discussions. ing generator output, but is used only internally. PHASE lags B1-Q2 by one 14M period. PHASE and PHASE 1 Figure 3.3 is an alternate tinning diagram show- ing the same signals as Figure 3.2 but with typical PHASE is the MHz clockpulse input to the 1 propagation delay illustrated. The cause and effect 6502. As such, its frequency determines the execu- tion time of instructions in the Apple computer. The relationships in Figure 3,3 are not as easily dis- duration of a PHASE cycle is equal to the duration cerned as they are in Figure 3.2, but Figure 3.3 of a 6502 cycle. This duration is .98 microseconds in more accurately details the actual timing.* It is very difficult to illustrate minute propaga- a normal cycle and 1.12 microseconds in a long cycle, tion delay in a diagram with the time scale of Figure 3.3. Figure 3.4 more accurately depicts the delay PHASE 1simply PHASE inverted. It is high is when PHASE is low and vice versa. The PHASE hierarchy that exists. The rising edge of 14M is the master reference of Apple timing, and the basic cycle period is almost coincident with a 6502 ma- features of propagation delay are: chine cycle but slightly leads it. Speaking of PHASE land PHASE as positive gating signals. PHASE 1. RAS', AX, CAS', Q3, PHASE 0, PHASE 1, 7M, 1 occurs approximately during the first half of the 7M'. and COLOR REFERENCE are all clocked 6502 machine cycle and PHASE occurs approxi- by the risingedgeof 14M,and their propagation mately during the second half. The time relation- delay from the rising edge of 14M is typically ships of PHASE 1, PHASE 0, and the 6502 machine nine nanoseconds. cycle are shown in Figure 3.6. 2. LD194 and COLOR DELAY' are logic functions Clockpulse action takes place when the PHASE of other timing signals propagated through a line switches from high to low or low to high. These logic device. Thei r delay from the rising edge of transitions trigger actions inside the 6502 which 14M is typically 18 nanoseconds. will be discussed in greater detail in the next chap- 3. LDPS' is a logic function of AX and CAS' prop- ter. A high to low transition of PHASE causes the agated through two logic devices. Its delay from 6502 to begin a new machine cycle after a short the rising edge of 14M is typically 27 delay. nanoseconds. In addition to triggering6502 events, PHASE Ois 4. The video scanner is clocked by the rising edge used as a time reference on the motherboard. Dur- of LDPS'. The delay between the rising edge of ing PHASE the 6502 address is valid, so address 14M and HPE' or HO is typically 42 nanoseconds. decoding from the address bus takes place during 5. PHASE is routed to the 6502 through one logic PHASE 0. RAM is addressed by the MPU during device. Internal 6502 actions cause a further PHASE and by the video scanner during PHASE delay before the 6502 data clock (the falling 1. Also, since scanner access is during PHASE 1. the edge of the 6502 PHASE 2 clock). The typical 6502 internal delay is not specified in data RAM read/write control is set to "read" during PHASE 1 even if the 6502 R/W line is set to "write". sheets. The delay between PHASE falling at the peripheral slots and PHASE 2 falling at the 6502** was measured by the author at 32 14M, 7M, and COLOR REFERENCE nanoseconds. 14M, 7M. and COLOR REFERENCE (3.5M) are utility clocks which are used in the generation of video. The frequency of Apple video can be as high * Pi ({urt>K;j, 2 and H.;i.show the ti mi nfr.sijrnalsswitchinK instantly, as 7 MHz, so generating the video signal requires and both fiffurcsarcirlealiKwi in tliisKcnse. In reality, il La ke.s the fast clocks. liminft (funeralor sijfnalK abnul .^ix nan osteon* is in ri.se or fall. 14M, 7M, and COLOR REFERENCE are unaf- •*.Syni;rli!k KYfJOOii (mjirkinjf 7K:jfiO) in an Ajijik' li computer. fected by the long cycle and have fixed frequencies Timing Generation and the Video Scanner 3-7 Time in nanoseconds RAS' AX CAS' Q3 PHASE 1 PHASE B1-Q2 7M' 71V1 COLOR-REF V 18 AX' . CAS PHASE . DMA' LD194 COLOR DELAY' 27 LDPS' '\ 6502 PHASE 2 42 HPE' HO Figure 34 Propagation Delay Hierarchy. 3-8 Understanding the Apple II RIW ;^> ADDRESS DATA BUS BUS 10-j y 03 't-O .M J_LL DMA' PERIPHERAL SLOTS t t COLOR HEF 7M (SLOT 7 ONLY) •hO *1 CAS' AX LM RAM ADD- KEY- RAM BOARD RESS MUX RAM/ LDPS' KEY- BOARD DATA MUX VIDEO flAM SCAN- ATA NER RAS' LATCH -^ VIDEO V(DEO GEN. LD194 COLOR TT 7M14M LDPS' REF ^ V5 VERTICAL PRESET' VI i V3 1 V2 z 1 V1 c 1 VQ 1 VC a VB c 1 VA HP£' 1 HS HORIZONTAL H4 PRESET' H3 H2 H1 HO m RFI REV. R28 REPLACES PRESET A2-11 ANDAZ-8 VALUES TO MAKE SOFT 5 SOFTS TO ALL SOFT 5-11 TO ALL ^ SOFT 5-B TO ALL SCHEMATICS SCHEMATICS "iofftz^ 'SCHEMATICS 74LS00 7'tLSOO Figure 3.9 Schematic; The Video Scanner. Tinning Generation and the Video Scanner 3-15 made the Apple inventor do it in a complex way. The vertical section (VA-VC and VO- V5) is a 9-bit PHASE is generated by two fltp-flops in Bl and modulo 262 counter which counts every time the hor- onehalfofa4 to 1 multiplexor, CI. AH of this gener- izontal section equals 1111111. The vertical section ates a PHASE signal wliich simply toggles every presets on scanner overflow to 011111010. Its 262 time CAS' is high and Q3 is low. The way it is done in states are Oil 11 1010-11 11 11 11 l.Eurapple jumpers the Apple, 01 develops the logic equation change the vertical preset to 011001000 and change AX' . Q2 + AX(PHASE - Q3 + Q3' . PHASE 0'), the number of vertical count states to 312. where Q2 is B1-Q2 and Q3 is the Q3 output of the The vertical section increments on the LDPS' timing generator. This signal is the D-input to Bl- before HPE'. A typical count sequence is Q2. PHASE follows B1-Q2 by one 14M clock linOOOOO/lUmi; llllOOOOl/OOOOOOO; llllOOOOl/lOOOOOO. period. Analysis shows that this generates PHASE The vertical preset sequence is as pictured in Figures 3,2 and 3.3. iiiiiini/iiiini;oiniitiLo/ooooooo;Oiinioio/ioooooo. A point worth noticing in the timing generator is VA is located on the same LS161 as H4, H5, and that 74S devices are used to generate signals which HPE', and it is not controlled by the vertical preset, are widely distributed. Most Apple TTL is mecha- but by HPE'. However, it always resets at vertical nized with 74LS devices. 74S devices have more preset time becauseof its count logic. DuringHPE', drive capability than 74LS devices, and by the use of it holds its value. Thus, VA is effectively preset to 74S devices in the timing generator, the number of "0" at vertical preset time. 74LS devices which can be driven by timing genera- The video, scanner implementation is one of a tor signals is doubled. numberofexamplesofdesign resourcefulness in the VIDEO SCANNER HARDWARE Apple II, The design of a 65 state counter cascaded into a 262 state counter is a fairly simple task, but The video scanner is a television synchronous 16- bit counter implemented on four 74LS161 4-bit doing it with four and a quarter TTL chips involves less obvious methods. This makes the circuit harder counters. The scanner incrementson the rising edge to understand, but increases the educational value of LDPS'. The four chips (see Figure 3.9) are cas- of studying such a circuit. caded into a single counter by connecting the carry output of each chip to the count enable inputs of the The SOFT-5 signals shown in Figure 3.9 are not next chip in the string. just part of the video scanner. They are constantly The counter is divided into two separately preset high logic levels distributed throughout the moth- sections. The horizontal section (H0-H5 plus HPE') erboard to those logic devices which require them. is a 7-bit modulo 65 counter. The 65 states are In earlier Apples, SOFT-5 was developed by two 0000000 and 1000000 through 1111111. The low 74LS00 N AND gates with their inputs grounded. In state of bit 7 (HPE') presets the horizontal section to RFI Revision Apples. SOFT-5 is a connection to the 1000000. +5 volt line through a 1000 ohm resistor. 3-16 Understanding the Apple SOFTWARE APPLICATION SWITCHING SCREEN MODES IN TIMED LOOPS A horizontal scan in the Apple takes exactly 65 The assembly language program of Figure 3.10a, machine cycles of the 6502. A vertical scan takes when assembled, is a subroutine that performs the exactly 17030 machine cycles. This information can screen splitting. The BASIC program of Figure be used to switch screen modes in timed loops to give 3,10b sets up a color display and calls the machine apparent combination screen modes. language subroutine. For example, the screen can be split so that half of The example program causes the Apple to be in each horizontal line is LORES and the other half of LORES for 131 TV lines and in HIRES for 131 TV each horizontal line is HIRES by switch in-between lines. The display is aligned vertically by pressing modes in alternating B3 and 32 cycle loops. Sim- any key on the keyboard while simultaneously hold- ilarly, the screen can be split so that half of all the ing REPT. The result of running this program is the horizontal lines are LORES and the other half are split screen display pictured in Figure 8.9. A more HIRES by switching: back and forth every 8515 sophisticated method of combining Apple II screen cycles.The latter can be accomplished using the modes is discussed in an application note at the end sample programs listed in Figures 3.10a and 3.10b. of Chapter 5. SOURCE -It.Ei FIGURE I.IBA aeiti 1 eaea 2 • asaa » HIRES/LORES SPLIT eaee t 8515/9515 aflae : * BY JIM SATHER * eatsa 2/15/1963 esea * mea CBBO KBD EQU SCflBfl ceio KBOSTRB EOU SCflIB C054 PAGEl EOU Sce54 C356 LOttES EQU SC9 5S dseo • aads • THIS PROGRAH TOGGLES THE KIBES/LORES SWITCH Bseo * EVERY B515 CYCLES. eaee * — <-- NEXT OBJECT. FILE NAME IS FIGURE 3. left.OBJff IFflS 17 OSC $lF9a IFSfl AC 54 ca IBsPLir LDY PAGEl 1FB3 M 2 7 19 SLEW LDY 139 ;SLEW SCREEN If KEY PRESSED 1F85 20 27 IF 29 JSH WAITXia 1F03 BC 18 CB 21 LDY KBDSTRB IFUB AC IS Cfl 22 KEVCKK LOY KBD IFflE 38 71 23 BHI SLEW IFlfl 69 Bl 2A ADC 11 .TOGGLE HIRES/UIRES SWITCH IFU 29 «L 25 AND isei 1F14 AA 26 TAX IF15 BC 5 6 C0 27 LDY LORES, IPle B2 08 39 LDX IS LPJA 20 31 IF 29 .ISR WMTXIK ;WAIT aaflfl CYCLES IFID AO 31 3B LDY 149 IFIF 29 27 IF 31 JSR WAITX19 JWAIT 49B CYCLES 1F2J IB 32 CLC IF23 9a ti 33 acc KEYCHK 1.FJ5 34 * IF25 35 • TIMISG HOUTINES: IF25 36 ' WAIT«13 WAITS Y-REG TIMES 19 CYCLES. 1F25 37 * (MINI HUM WAIT 20 CYCLES 1 1-F25 39 * WAlTXlK WAITS IC-REG TIMES IffBB CYCLES. 1.F2S 39 * IP25 DB 91 ie LOOPlfl BNE SVCYCLES LF37 aa 41 WAITXIS DEY ;WAIT Y-REG TIMES IB LF2B 83 42 SVCYCLES DEY IF29 EA 43 NOP lF2A Dfl F9 44 SNE LOOP10 iFac ee 45 RTS IF2D 4a 4E LOOPIK PHA 1F2E S3 47 PLA 1F2F CA 43 NOP IF 30 EA 49 NOP IF31 Ad S2 53 WAITKIK LIIV 193 (WAIT X-REG TIMES 190B 1F33 2e 27 IF 51 JSR WAlTXia 1F36 ER 52 NOP IFll CR 53 DEX lF3a DB F3 54 BNE LOOP IK lP3h 6e 55 RTS *** SUCCESSFUL assembly: tic ERSofrs Figure 3.i0a Assembler Listing; A Screen Splitting Program. Timing Generation and the Video Scanner 3-1 10 REM 11 REM 12 REM SET UP LORES AND HIRES AND CALL SPLIT SCREEN. 13 REM 14 REM 20 PRINT CHR$ (4);"BL0AD SPLIT SCREEN-OBJ0" 30 HGR : HOME : VTAB 21: PRINT "1 7 D 2 8 E B 4 5 A36C9F8" 40 DIM COLR(39J ,X(21) 100 FOR A = TO 39: READ COLR(A): COLOR= COLR(A): VLIN 0,39 AT A: NEXT A 200 FOR A = TO 21: READ COLR(A): READ X (A) : HCOLOR= COLR(A) 210 HPLOT X{A),0 TO X{A),159: NEXT A 220 FOR A = 8319 TO 16383 STEP 128: POKE A, 64: NEXT A 300 CALL 7936 400 REM LORES DATA 410 DATA 1, i3, 7, 7, 0,13, 13, 0,2, 2, 0,8, 8, 0,14, 14,0, 11, llf0 420 DATA 4,4,0,0,5,0,0,10,0,3,0,6,0,12,0,9,0,15,0,8 500 REM HIRES DATA 510 DATA 4,0,3,20,4,21,3,41,4,42,7,62,7,83,7,104,3,10 5,7,12 5,3,126,7,159,3,161 520 DATA 7,180,3,182,3,206,7,220,3,233,7,247,3,262,3,263,7,279 Figure 3.1 Ot> BASIC Listing: A Split Screen Exampie. 3-18 Understanding the Apple II SOFTWARE APPLICATION APPLE TfMING LOOPS It is not generally known thatthe 6502 clock of the should be used for computing exact time durations Apple is not fixed frequency. The frequency and of Apple programs. stabilityof theMPU clock are important factors in When very precise time measurement is neces- precision tinned loop assembly lanj^uage prop;rams. sary, the programmer has to consider the impact of The Apple If Rcfcnnicv Man mil fc^ves. the 6502 fre- elockpulse jitter, vvhich is caused by the long cycle. quency as L028 MHz, but it also ^ives a hint that Since the Apple II has no real time clock, timed there is more involved. In the WAIT routine of the output must be done with program loops which take old Monitor ROM listing, there is an interesting a specific number of clock pulses to execute. When comment. It reads simply "1.D204 USEC." This is possible, these loops should be written in multiples 1.02048432 rounded off incorrectly. of 65 cycles. This will eliminate loop output jitter. The composite frequency of the Apple is 1.0205 Otherwise the application must be able to tolerate a MHz. (The profrram comment in the reference man- 140 nanosecond jitter. 140 nanoseconds is the differ* ual confuses frequency with time periods.) 1.0205 is ence between a normal cycle and a long cycle. The the result of 14.31818x(6,5/(65xl4+2)). The average programmer should be aware of Apple elockpulse period of du ration of an Apple 6502 machine cycle is jitter and determine its affect on his particular .9799268644 microseconds. This is the value which application. Tinning Generation and the Video Scanner 3-19 HARDWARE APPLICATION DETECTING TELEVISION SYNC There is no signal or interrupt in the Apple II to As an example of what this circuit will do when tellthe 6502 where the television scan is at any installed, the short 6502 assembly language pro- moment. Reading: television sync is of interest in gram listed below will create a mixed mode with several applications: screen mode splitting, video four lines of text at the top of the screen and a camerainterfacing.flickerless animation. and light graphics display for the rest of the screen. The pro- pen interfacing, to name four. This application note gram assumes that the interrupter is installed in has some suggested methods for gaining the capa- SlotO. Load this program and call 24576 $6000 Hn ( bility to detect television sync through peripheral the middle of any BASIC program. The BASIC card design. Since no signals from the video scanner program will continue to execute butthe screen will are connected to the peripheral slots, some less be split with text on the top four lines. Also, the obvious methods must be used to read the television BASIC program will run about 15% slower because scan. time is wasted between the interrupt and the period A simple but powerful form of television scan just before the fifth line of text. interruption is shown in Figure S.ll. This circuit This circuit has several strengths and weaknesses. generates an interrupt when the video scanner over- It is interrupt based, so it allows programs to exe- flows, 416 cycles before the start of the screen dis- cute normally, leaving the interrupt handler to pro- play. A jumper is connected between this peripheral cess tasks related to the video scan. Also, it is very card and Dll. pin 15 on the motherboard to give simple, requiring only one and a quarter integrated the card its scan reference. The interrupt can be circuits. Its primary weakness is that it is capable of acknowledged, enabled, or disabled under program interrupting at only one spot on the scan. Another control via references to its DEVICE SELECT' problem is that an interrupt does not stop [irogram addresses.* ifCOSO.X (slot number times $10 in X) flow until the current instruction is executed. This acknowledges the interrupt and inhibits further means the point in relation to the video scan at which interrupting. $C081,X acknowledges the interrupt the interrupt handler is entered will vary plus or and enables further interrupting. System RESETs minus three cycles, depending on the length of the also disable interrupts. Interrupted 6502 instruction. Another weakne,ss is the required jumper to the motherboard. It is pref- •AcknowledfrinR tKe interrupt allows the IRQ' line to return to erable to keep this sort of extraneous clutter to a I the hipfh state after the interrupt. minimum. 6000 LDA #$00 6002 STA 93FE 6005 LDA #$61 6007 STA $3FF juni Vector Fixed 600A CLI 600B LDA $C081 ;Enable Video Interrupter 600E RTS 610 LDA $C051 ;This is the IRQ handler 6103 LDA #$1C 6105 JSR FCA8 ;Wait 2351 6108 LDA #$03 610A JSR FCA8 ;Wait 76 610D LDA $45 ;Apple stored accumulator here 6110 BIT $C050 6112 BIT $C081 ^Acknowledge the interrupt and 6115 RTI lenable further interrupts 3-20 Understanding the Apple II i Jumper to VPE <2) IRQ' atD11-15onthe -* motherboard. iEVICE SELECT' ^ ^ AO Q} $C080,X: IRQ' DISABLED, IRQ' ACKNOWLEDGE $C081,X: IRQ' ENABLED, IRQ' ACKNOWLEDGE RESET' ^ Figure a.1 1 Circuit to Gerierate a 6502 Interrupt 41 6 Cycles Before Hie Start of the Screen Display. One way to make a jumper unnecessary is to more difficult to detect As described in Chapter 8. solder the wire between Dll-15and pin 35 or 19 on vertical sync is made up of four long duration nega- any slot between and 6. Pins 35 on Slots 0-6 are tive pulses. Figure 3.12 is a circuit to separate a connected together and the same is true of pin 19. No single vertical pulse from the television SYNC sig- sigrnal is connected to these pins, so they are grener- nal. It works by counting up while the SYNC signal ally available for some user defined purpose. You is low and counting down when it is high. If it counts can solder the long wire on the underside of the up to 15, then a vertical sync pulse is present and the motherboard, then tack it to the motherboard with VERTICAL SYNC flip-flop is set. When it counts several spots of glue. This entails removing the back down to zero, the vertical sync period is past, motherboard from the case, but it has the advantage and the VERTICAL SYNC flip-flop is reset. The of making the Figure 3.11 interrupter a cleaner vertical and horizontal sync may be used in any installation. number of Slot 7 designs, possibly to drive an inter- It is not actually necessary tojumper video scanner rupter like the one in Figure 3.1 1. signals to peripheral cards to allow them to sync to This Slot 7 sync separator will not work on all the television scan. Any slot can be synced with the Apples. The SYNC signal was not connected to pin video scanner, but it is a little easier in Slot 7, since 19 of Slot 7 in Revision 0. Also in Revision 0, the the television SYNC signal is available there on pin vertical sync was three times as long as later revi- 19. This signal is a composite of the horizontal and sions with no horizontal serrations. You can make vertical sync signals which cause horizontal and the sync separator work in Revision by jumpering vertical retrace on the television. The horizontal sig- SYNC (C 13-8) to pin 19 on any slot, but there would nal is easily detected by clocking a flip-flop or other be no horizontal sync to detect during the long verti- synchronous device on the failing edge of the televi- cal sync period. A second problem occurs in Revi- sion SYNC signaL The vertical signal is slightly sion 7 motherboards. In Revision 7, video generation L Timing Generation and the Video Scanner 3-21 was changed so that the three horizontal serrations the scanner simulator. Then devise hardware to in the vertical sync became double pulses. This dou- read flag bits from the data bus. Finally, cause the ble pulse was changed back to a single pulse in the scanner simulator to preset when the flag bits are RFI Revision. The result is that digital processing of detected. The flag bits are set up by a program, and the Apple SYNC signal must tolerate or mask out the scanner simulator preset is enabled by program the second pulse if it is to work with Revision 7 control. This only has to be done once, after which Apples. the two video scanners will remain in sync until Some readers might be surprised to find it is also power is removed from the Apple. possible to sync a non-Slot 7 peripheral card to the Figure 3.13 is a five chip circuit which duplicates video scanner without connecting jumpers to the the vertical portion of the video scanner on a periph- motherboard. In fact, it is possible to duplicate the eral card. It is made up of a mod-262 counter, a long entire video scanner on a peripheral card with no pulse detector, and a synchronizer to sync the count- jumpers to the motherboard. The reason for this is er to the vertical section of the video scanner. The that data from the video scanner is present on the long pulse detector simply detects the Apple's long data bus vi'hen PHASE rises on all 6502 read cycle, which occurs once every horizontal scan atthe cycles. Suppose you build a counter just like the beginning of the horizontal blanking period. This video scanner and put it on a peripheral card. Call it long pulse is easily detected from any peripheral The falling edge of the pin 19 signal represents 1/2 Of LSI 09 HORIZONTAL SYNC 5V 5V- 11 16 (l>5 i;6 I vcc LOAD PR QD J * VERTICAL TELEVISION SYNC UP7 74LS191 max; 12 li SYNC DOWN win UP/ DOWN COUNTER ^K PHASED @ ^-^> WQ CK T COUNT ENABLE !?7 aTTT CLR SLOT 7, PIN 19 ¥ Jl w VERTICAL SYNC: LS109. PIN 6 Figure 3.12 Circuit to Separate a Verttcal Sync Pulse from ttie felevision Sync Signal at Pin 19 or Slot 7. 3-22 Understanding the Apple 16 5V*- 74LS151 16 74LS161 74LS73 LONG PULSE DETECTION 74LS73 ,1mF 74LS02 74LS161 14 PO QO VB 13 PI Q1 -vc X" 12 P2 02 -vo 11 pa 03 VI CLR PE PROGRAMMED SYNCHRONIZER TC 74LS73 15 D6 12 l«} £g^)cie-C> 101 o. GET CEP 71 21 VrCK PHASED HASE ,-. 10 13 (S^ CLR D7 PE3= 74LS1S1 14 PO 00 -V2 13 PI 01 V3 DEVICE PZ 02 1^V4 SELECT 11 P3 03 V5 TC 15 :3K 13 11 12 DC Figure 3.1 3 Circuit that Duplicates the Vertical Section of the Video Scanner. Tinning Generation and tine Video Scanner 3-23 card, because the 7MHz clockpulse falls twice dur- vertical counter to start counting with the first insrPHASE • Q3' of the lonpr cycle, but only once long cycle at the beginning of line 1. during PHASE 0»Q3' of a normal cycle. In Fip:ure Figure 3.14 is an assembly language subroutine to 3.13. every time 7M falls twice durinj: PHASE • sync the video counter. After running this subrou- Q3'. the vertical counter counts. This means the ver- tine, the counter will remain in sync in all video tical counter counts horizontal scans. modes until the computer is turned off or an acci- The vertical counter is nearly identical to the ver- dental reference is made to $C080,X. Control com- tical portion of the video scanner. It uses 74LSlfil mands can be made at addresses with Al set counters which preset on overflow to -262. The LSB ($C082.X for example) and they will not affect the (VA> is mechanized on one half of a 74LS73 flip-flop. video counter. The main difference between this vertical counter Figure 3.15 is an example of what one could do and the video scanner is that this counter has its with the video scan information on a peripheral CLEAR input connected to the programmed syn- card. This circuit will generate an interrupt before chronizer. This circuit vi'ill detect the top displayed any one of the 256 horizontal scans beginning with line of the television scan and clear the vertical line 0. The eight bit interrupted scan number is counter. The synchronizer is designed to detect flags saved in an octal latch, and a pair of 74LS85 magni- stored in bits D6 and D7 of scanned memory. tude comparators tell when the video scan is equal to Memory is flagged as follows: the line number to be interrupted. The circuits of Figures 3,13 and 3.15 are com- 1. Clear all HIRES. Page 1 (.S2000'$3FFF). bined on the prototype card pictured in Figure 3. 16. HIRES. Page is selected because clearing it 1 This programmable scan interrupter represents a will not clobber BASIC or DOS. considerable enhancement to the Apple II. imple- 2. Place a $40 at memory location $3FD0. (See mented on just eight TTL chips. Program control of Figures 5.9 and 5.17.) This is the first byte this card in Slot would be as follows: scanned during line 191 displayed, and it isonly scanned once per television scan. 3. Place a $80 at memory location $3827. This is $C080 Synchronize scanner simula- the last byte scanned during line 6 displayed. tor as in P''igure 3.14 program. $C082 IRQ' disabled; IRQ' Once memory is flagged, the video counter is acknowledged. synced by performing a reference to $0080. X then $C083 IRQ' enabled; IRQ' waiting 21686 or more cycles in a non-writing wait acknowledged. Foutine. What happens is this: STA $C08X Set number of scan to be 1. The reference to $C080.X enables monitoring of interrupted. D7 and D6 while PHASE rises. 2. Within 17030 cycles, SSFDO is scanned, driving out D6 true. This causes the CLEAR line to drop The circuits shown in this application note are low, clearing the vertical counter and holding it useful by themselves but could also be used in com- clear. The resourceful de- bination with other circuits. 3. TheCLEAR line is held lowfor5045cycles until signer can use video scan synchronization, long $3827 is scanned, driving out D7 true. This pulse detection, scan interruption, and Slot 7 sync brings the CLEAR line high and disables fur- separation to create exciting new capabilities for ther monitoring of D7 and D6. This allows the the Apple. 3-24 Understanding the Apple II SOURCE FILE: SYNC INTERRUPTER SLOT? 0000 1 ********************************************************* 0000 2 * * « 0000 3 * 0000 4 * SYNCHRONIZE VIDEO SCAN SIMULATOR * 0000 5 * * 0000 6 * BY JIM SATHER * 0000 7 * * 0000 8 * 1/20/B3 * 0000 9 * * 0000 10 * * 0000 11 ********************************************************* 0000 12 * 0000 13 * 0006- 14 BASL EQU S06 0007 15 BASH EQU $07 0070' 16 SLOTNUM EQU $70 3827' 17 LINE6 EQU $3827 3FD0: 18 LINE191 EQU $3FD0 C050i 19 GRAFIX EQU 5C050 C052: 20 NOMIX EQU $C052 C054: 21 PAGE! EQU SC054 C057: 22 HIRES EQU SC057 0000: 23 * 0000 : 24 * 0000: 25 * ^ — _ _ -> M p vm nc3 T rtr^m trt T r r* ti ^ u Ct TO SYNC INTERRUPTER SLOT7.OBJ0 1000: 26 ORG $1000 1000:AD 50 C0 27 SYNC IT LDA GRAFIX 1003 :R0 52 C0 28 LDA NOMIX 1006 :AD 54 C0 29 LDA PAGRl 1009:AD 57 C0 30 LDA HIRES 100C:A9 20 31 LDA #S20 CLEAR SCREEN MEMORY 100E:AA 32 TAX 100F:85 07 33 STA BASH 1011:A9 00 34 LDA #0 1013:85 06 35 STA BASL 1015:A8 36 TAY 1016:91 06 37 BLANKLP STA (BASL) ,Y 1018:88 38 DEY 1019:D0 FB 39 BNE BLANKLP 101B:E6 07 40 INC BASH 101D:CA 41 DEX I01E:D0 F6 42 B^3E BLANKLP 1020: 43 * 1020: 44 * 1020:A9 40 45 LDA #S40 SET FLAGS 1022:8D D0 3F 46 STA LINE191 1025:A9 80 47 LDA #$80 1027:8D 27 38 48 STA LINE6 102A:A2 70 49 LDX JtSLOTNUM 102C:BD 80 C0 50 LDA $C080,X ENABLE D7 & 06 MONITORING 102F:A2 11 51 LDX #17 WAIT 21829 CYCLES L03I:S8 52 WAITLP DEY 1032:D0 FD 53 BNE WAITLP 1034:CA 54 DEX 1035:D0 FA 55 BNE WAITLP 1037: 60 56 RTS *** SUCCESSFUL ASSEMBLY: NO ERRORS Figure 3.14 Assembler Listing: Syncronlzlng the Video Scan Simulator. Timing Generation and the Video Scanner 3-25 w. 20 74LS377 10 ]L IE 3 ir 74LSa5 55 8 741565 14 7 74LE74 U 7 V5- < II 1) ^ -| 74LS03 _I fi/W*flB. Xl < > = VA- BO IN JO oai^)- DO 00 AO VB- 81 12 Q\(^)- m 01 A1 74LS85 14 VC- B2 COMPARATOR oi^y m f& 13 AZ vo- B3 mfii] D3 03 A3 OUT < > = 74LS377 OCTAL D-FLIPFLOP < > BO IN VI 04 04 m n- B1 !5 1? I [% {£ *^ 74LS85 V3- B2 COMPARATOR 1G 06 06 A2 I 19 V4- B3 07 @- 07 aCK 07 A3 < OUT •> = 5V 1 5 6 >3K Pfl 5 1 IRQ' D Q J LSQ3 P^30j "CK 741.S74 CLR "T SELECT' vV^ ilaL PR 12 AO©- D I CK CLR RESET' (3?)- Figure 3.15 A Programmable Interrupter. Generates an Interrupt Before Any One of 256 Selected Horizon- It tal Lines. 3-26 Understanding the Apple Figure 3.1 6 A Programmable Video Interrupter Card. chapter 4 The 6502 Microprocessor The 6502 was designed byMiiS Technology in the mentation of the 6502 in the Apple II computer. mid 1970s as part of their MCS6500 series micro- Volumes have been written about various aspects of processor family. It has been a popular choice as a the 6502, especially programming. The choice of microprocessor for personal computers, being used 6502 topics in this chapter was governed by the in computers produced by Apple. Atari. Commo- unique features of 6502 use in the Apple, and by the dore. Ohio Scientific, Rockwell International, and goal of this book to fill information gaps in Apple other manufacturers. Only the Z80 could com pete as literature available to the public. the MPU most often found in big selling microcom- Manufacturers of the 6502 are: puters. The 6502 gives adequate computing speed MOS Technology. Inc. and versatility at a very low cost. Its programming 950 Rittenhouse Rd. language is very simple, making it an idea! MPU for Norristown. Pa. 19403 the occasional computer programmer. Synertek. Inc. The most important 6502 related knowledge for P.O. Box 552 an Apple owner to attain is programming knowl- Santa Clara, Ca. 95052 edge. The ability to read and write 6502 assembly language programs greatly expands the horizons of Rockwell Internationa! an Apple computerist. 6502 assembly language is Microelectronic Devices not. however, a major topic of this book. These pages P.O. Box 3669, RC55 are concerned primarily with the hardware imple- Anaheim, Ca. 92803 ¥ 4-2 Understanding the Apple II VSSIGOOUNQI — to — REStr HtAD-r — 1 2 39 — PHASE? PHASE 1 -^ 3 31 SET OVERFLOW IRO — i Z7 — PHASE NC — i 36 NC NMI — i 3S MC SlfNC — 7 6502 MPU M i— niw VCCC5VI — t 33—M K.V „_ 9 32— 01 Al — 10 3T— 02 H 11 30— t)3 A3 — 1! » —M A4 — 13 n — DS AS — 14 !7—M A6 — IS » 07 A7 — 16 a — AIS AB — 17 2* All AS -^ IB n A13 AM — 19 22 _ All Alt — K 21 — VSS l&nOUNDl Figure 4.1 6502 Pin Assignments. clocks are available at pins 3 and 39 of the 6502. 6502 SIGNALS PHASE PHASE 2 is not connected in the Apple. 1 is There are 40 pins on a 6502, three of which serve used to control the direction of data flow in the no function. In addition to the address output and external MPU data bus transceiver during MPU data input/output, there are four outputs (R/W, write cycles. PHASE 1, PHASE 2, and SYNC) and six inputs (READY. IRQ', NMT'. PHASE 0, SET OVER- Address and R/W FLOW, and RESET'). There are three power During every machine cycle, the 6502 places an supply connections. One pin requires +5 volts and address on its address output. In association with two pins require ground. Figure 4.1 shows the 6502 the address it outputs, it brings its R/W line high or pin assignments. Figure 4.2 shows the 6502 hard- low, thereby telling the world whether it wants to ware implementation in the Apple. A brief discus- read or write data. With 16 address lines, the 6502 is sion of the 6502 signals with Apple implementation capable of producing 65536 different values at its notes follows. address output. The 6502 address and R/W outputs are not tri- state, but in the Apple these signals are connected to Clockpulses- PHASE 0, PHASE 1 PHASE 2 , the address bus through external tri-state bus The 6502 has most of its required clockpulse gen- drivers. This enables peripheral cards to gain eration circuitry built-in. Itrequiresonly an exter- access to the address bus via the DMA' line. nally generated time base which can be implemented the Apple, the PHASE in .several way.'i. In time Data Bus base is developed independent of 6502 internal cir- The data input/output of the 6502 is eight lines. cuits and fed as the clockpulse input to the 6502. This gives the 6502 its overall classification as an The 6502 generates its required PHASE 1 and 8-bit microprocessor. Data direction is inward ex- PHASE 2clocks from the PHASE input, PHASE cept during PHASE 2 of write cycles. 1 is high during the firsthalf of a machine cycle, and In the Apple, the 6502 data lines are connected to PHASE 2 is high during the second half of a the data bus through external bidirectional bus machinecycle. PHASE isnotthesimpleinversion 1 drivers. These drivers enable the 6502 to write to of PHASE 2. There is a slight delay between the the data bus with all the devices that are connected PHASE transitions and the PHASE 2 tran.sitions. 1 to it. Data direction in the external data drivers is The ri.sing edge of one always follows the falling from the data bus to the 6502 except during write edge of the other. The PHASE 1 and PHASE 2 cycles when the 6.502 PHASE 1 clock is low. The 6502 Microprocessor 4-3 74LS32 R/# jQfci7)og TWO 8T28S REPLACED INC MC Br ONE B304 IN ' 5V REVISION ADDRESS BUS t RFI AND R/W \r m la SYNC PHS2 VCC PHSl OATA BUS 2 R/W- 1 -kirDO H7/H8 6502 MPU PHSO RDV NMI' IRQ' BESET' VSS \fas SO 2" 4'1 40' I :i 3B,I ±: KEYBOARD ?4LS08 CONNECTOR (3,8) 2 PHASE DMA' Jbii)^ POWER-JP RESET BESET- IHQ' NMI' _m_ mx 2 ; s t SLOT SLOT SLOT SLOT SLOT 1 2 3 4 ^ Figure 42 Schematic: 6502 Connections In the Apple 11. 4^ Understanding the Appfe RESET' and cards which dump Apple memory to disk are based on non-maskable interrupts. The IRQ' line is The RESET' input to the 6502 causes the 6502 to tied to pin 80 of the peripheral slots and the NMI' start or restart. A RESET' causes the 6502 to dis- line is tied to pin 29. able interrupts and begin progrram execution at an address stored in locations $FFFC and $FFFD of READY ROM. 6502 operation is inhibited while RESET' is Bringing the READY input to the 6502 low dur- held low. The RESET' sequence beprins when ing the PHASE 1 clock in a read cycle causes the RESET' transits from low to high. 6502 to go into its wait state. In the wait state, the In the Apple the RESET' line is connected to pin 6502 holds the current address and does nothing. 31 of the peripheral slots, to the keyboard RESET The wait state lasts until READY is sensed high key, and to a circuit which generates a RESET' during PHASE 2. If the high to low transition when the computer is first turned on. A peripheral occurs during a write cycle, the wait state will not card can either cause a RESET', respond to a begin until the next read cycle. RESET', or ignore a RESET'. The wait state of the 6,502 can be used for interfac- ing to slow memories, single step operation, slow Interrupts- IRQ' and NMt' step operation, or just plain stopping the MPU The interrupts cause the 6502 to stop its sequen- indefinitely. It has no impact on the Apple's video tial program execution and execute interrupt hand- circuitry or on RAM refresh, so the video display ling routines. Interrupts are normally associated appears frozen on the screen when the6502 is halted with input/output functions, but they are a way for via the READY line. The READY line in the Apple any type of device to get the microprocessor's atten- is connected only to pin 21 of the peripheral slots. tion. The IRQ' (Interrupt ReQuest) is enabled or This 6502 capability has gone largely unexploited in disabled by program control, so the 6502 doesn't the Apple. have to respond to an IRQ'. The NMI'lNon-Maskable Interrupt) cannot be disabled by program control. SYNC An NMI' causes the (1502 to perform an interrupt The6502 SYNC outpiitgoes high when the6502 is sequence after the current 6502 instruction has performing an op code fetch. This is the first cycle in been executed. The 6502 saves its program location the execution of any instruction in which the 6502 counter and its Status Register (with BREAK flag fetches the one byte operational code of the instruc- reset) in an area of RAM called the stack. It disables tion. The SYNC signal can be used for single interrupt requests, then begins program execution instruction execution steps (in conjunction with the at the address stored in $FFFA and $FFFB of READY line) and otherwise identifying the op code memory. The NMI' input to the 6502 is edge sensi- of a 6502 instruction. The SYNC output of the 6502 tive, meaning the 6502 respondsonly to a high to low is not connected to anything in the Apple. It cannot transition of NMI'. To generate a second interrupt, be used in the Apple without modifying the mother- the NMI' line must be brought high, then low again. board or jumpering it to a circuit. An IRQ' causes the 6502 to perform an interrupt sequence after the current instruction has been exe- SET OVERFLOW cuted if the program has interrupt requestsenabled. The IRQ' sequence is identical to the NMI' sequence A high to low transition on the SET OVER- except the address of the IRQ' handling routine is FLOW line sets the overflow flag of the 6502. The stored at $FFFE and $FFFF. The IRQ' signal is not overflow flag is normally set or reset as a logical edge sensitive, so the IRQ' must go high before result of some 6502 instructions, but the SET interrupts are enabled again, or the same interrupt OVERFLOW input forces the flag regardless of will be answered more than once. instruction execution. I The SET OVERFLOW input has limited value ' The interrupt inputs to the 6502 are connected to the peripheral slots in the Apple. There are no as a control input, because it must be used only in motherboard devices which generate 6502 inter- conjunction with instructions that affect the over- rupts, and I/O in the Apple II is normally accom- flow flag or in avoidance of such instructions so as plished without interrupts. Most real time clock not to interfere with them. It is not used in the cards are capable of generating interrupt requests, Apple, but is tied directly to ground. The 6502 Microprocessor 4-5 6502 CONNECTIONS IN THE APPLE has special read/write uses for Page and Page 1. Page locations are used as indirect address loca- Figure 4.2 shows the6502 hardware implementa- tions in 6502 machine language. Additionally, the tion in the Apple. Address. R/W, and data connec- 6502 has a zero page addressing mode which tions are routed to the address bus and data bus speeds and compacts programs making heavy use of through external drivers. The PHASE clock zero page locations for various storage functions. As comes from the timing generator, gated by DMA' a result, bigmachine language programs like Apple- from the peripheral slots. All other signals are con- soft BASIC make heavy use of zero page locations. If nected directly to the peripheral slots. BASIC is operating and you indiscriminately POKE The method of tying the 6502 control inputs to values into zero page locations, you will deep six multiplesources is called wire-ORing or collector- BASIC, This is because the critical pointers of ORing. A logical OR function is achieved by tying BASIC will be lost. The following program must lines directly together. As an example, if Slot OR crash: Slot 1 OR any other slot pulls pin 29 low, the 6502 will sense a non-maskable interrupt. In a wire-OR circuit, the line is pulled high by avoltage through a 10 FOR A = TO 255 : POKE A,0 : resistor if no card is pullingthe line low. Peripheral NEXT A : END cards should not try to pull the wire-OR lines high. They either pull the line low or present a high imped- Page 1 is the 6502 stack. The stack of a micro- ance to the line, usually by driving the line with open collector TTL circuits. The 6502 iterature specifies 1 processor is an area of RAM which it uses as a last in— first out memory. To the computer program, that 3000 ohm pull-up resistors be used for wire-OR the stack is like a stack of playingcards which it can inputs to the 6502. Apparently this is not a particu- discard to or draw from. Conceptually, data is larly important specification because the Apple stored to the top of the stack or withdrawn from the works fine with 1000 ohm pull-up resistors. The tri-state address bus driver is necessary for top of the stack. The stack is actually part of RAM While the program pushes data to or pulls data from DM A operations because the 6502 address and R/W the stack, the MPU must increment or decrement a connections are not tri-state. The address drivers read address and keep track of where in memory the used in the Apple are 8T97 6-bit tri-state busdriver. "top" of the stack is. In the 6502. the location of the The data bus drivers are 8T28 4-bit transceivers in "top" of the stack is stored internally in an 8-bit older Apples. The two 8T28s were replaced by a register called the Stack Pointer. When thestack is single 8304 in the RFI Revision. These transceivers accessed, the 6502 addresses a location in Page 1 of increase the data bus driving capability of the 6502 on write cycles. On read cycles they have a different RAM determined by the Stack Pointer. Virtually all machine language programs access the stack via effect. The Apple data bus is a heavy capacitive load Jump SubRoutine and Return from SubRoutine and it takes a while for a device to bring it low or instructions, so at no time can a program indiscrim- especially to bring it high. The transceiver acts like inately modify Page 1.* The following BASIC pro- a threshold detector on read cycles. As the data bus gram will crash as surely as the earlier one: gradually changes states, the voltage at the trans- ceiver input reaches a threshold at which the trans- ceiver output rapidly changes states. This presents a 10 FOR A = 256 TO 511 : cleanly switched data input to the 6502 as opposed to POKE A,0 NEXT A : : END the dirty data bus. The 6502 also dictates that the highest memory 6502 MEMORY USAGE location is $FFI^F^ and that it will be assigned to Use of the 6502 in the Apple dictates various ROM. That $FFFF is the highest address is an aspects of the memory layout. For example, ad- obvious consequence of the fact that the 6502 has 16 dresses $0-$lFF are always RAM in a 6502 system. address lines. In a similar vein, the eight data lines Apart from design dictates, the 6502 also uses parts Exceptions are copy protect schemes which call for program- of memory so that they are normally not available ming without JSR, RTS, PHP, PLP. PHA. or PLA instructions. for Apple programs. In (.he.sesehemes, critical data is stored inPasel of memory, and Page and Page 1 ($0-$FF and $100-$1FF) of a most attempts to exam ine memory resu It in the loss of the critical 6502 system must be RAM simply because the 6502 Page 1 data. 4^ Understanding the Appfe APPLE PHASE ,f \ / APPLE PHASE V f \ 6502 PHASE 1 \ 6502 PHASE 2 1 r \ Figure 4^ 6502 Clockpulse Relationships. of the 6502 dictate that memory is organized into generated internally from the PHASE clock 8-bit locations. The reason for assigning the highest input. This is one of the 6502 improvements. address to ROM is that the 6502 RESET. NMl. and The relationship between the PHASE clock IRQ vectors must be stored in locations $P'FFA input and the PHASE 1 and PHASE 2 6502 clocks is through $FFFF. In particular, the RESET vector shown in Figure 4.3. The PHASE 1 and PHASE 2 in ROM enables the Apple to immediately begin clocks are not symmetrical but are low slightly executing a non-erasable program at power up. longer then they are high. The high period of one Since the 6502 has no special input/output control clock always fits neatly inside the low period of the features, it must control inpuVoutput functions other. The PHASE 1 and PHASE 2 transitions are with commands decoded from the address bus. In clocked by the transitions of the PHASE input in a the Apple, addresses are assigned to the peripheral repetitive cycle. The falling edge of PHASE is slots and built-in I/O functions which could be oth- followed by the falling edge of PHASE 2 and then erwise assigned to memory. This is referred to as the rising edge of PHASE 1. The rising edge of memory mapped I/O. It was logical in the Apple PHASE is followed by the falling edge of PHASE design to as.sign the address space between RAM 1 and the rising edge of PHASE 2. To put it differ- and ROM to I/O. That way there are three contigu- ently, PHASE falling clocks the end of PHASE 2 ous addressing groups RAM ($0-$BFFF). I/O then the beginning of PHASE 1. and PHASE ($COOO-$CFFF), and ROM ($DOOO-$FFFF). rising clocks the end of PHASE 1 then the begin- ning of PHASE 2. The effect of the long cycle on 6502 clocks is to elongate PHASE 2 by 140 nanoseconds. This has no particular ill effects outside of program timingcon- 6502 TIMING IN THE APPLE II siderations mentioned in the previous chapter. By The 6502 was designed to be similar to the Motor- lengthening PHASE 2, all response criteria for ola MC6800 microprocessor, but improved. The communicating with the 6502 become less critical. clock requirements of the 6502 are the same as the The following timing discussions are valid for either MC6800, two alternating po.sitive pulses. In the a normal cycle or a long cycle, but the diagrams MC6800. the two clocks must be generated exter- picture normal cycles. The timing specification.s of nally and input. In the 6502. the two clocks are the 6502 are not affected by the long cycle. The 6502 Microprocessor 4-7 The 6502 PHASE 1 clock is not the same as the Ten nanoseconds could probably be subtracted from PHASE 1 sig-nal developed in the timing generator. the clockpulse delay specifications to reflect the fact PHASE from the timing: jienerator is simply 1 that there is no load on PHASE 2 in the Apple. PHASE inverted. It was named PHASE 1 because The Synertek, MOS Technology, and Rockwell of its kinship with the 6502 PHASE 1 clock. Seman- International 6502s are probably all made the same. ticambiguity is a pcreat way to confuse those who When one company gives tighter specifications than would understand. The term which is distributed to another, itobligates itself to test its microprocessors the peripheral slots, address decode, and RAM is using more difficult criteria. We shall soon see that PHASE 1 from the timinp: generator. The 6502 the worst case timing specifications are pretty far PHASE 1 clock is used only inside the 6502 and for beyond typical operation in any case. They had bet- control of the external MPU bidirectional data bus ter be. because the Apple design doesn't meet the driver. In this chapter only, "PHASE 1" refers to MOS Technology/Synertek 100 nanosecond mini- the 6502 PHASE 1 clock. Outside of this chapter mum requirement for 6502 read data setup when "PHASE 1" refers to the inversion of PHASE 0. reading from RAM, distributed from the timing generator. Figure 4.5 is a diagram showing the timing rela- Timing specifications in the 6502 are referenced tionships actually found in one Apple. The mea- to the rising and falling edge of thePHASE 2 clock surements were made in an Apple using a Synertek (at the .4V point). Important 1 MHz timing specifi- SY6502 marked 78360 (December 26, 1978?). Fig- cations for MOS Technoloff>' 6502s are shown here ure 4.5 may be considered fairly typical of 6502 with Synertek and RockweU International ratings timing in the Apple. The important features of Fig- shown in parenthesis when they differ: ure 4.5 are: 1. The 6502 address and R/W line will be valid 1. PHASE 1 and PHASE 2 transitions occur within 300 nanoseconds (225 nsec Synertek: 225 roughly 30-35 nanoseconds after PHASE nsec Rockwell) after the falling edge of PHASE transitions at the peripheral slots. 2. They will stay valid until at least '^0 nanosec- 2. The 6502 address becomes valid 128 nanosec- onds after the next falling edge of PHASE 2. onds after PHASE falls at the peripheral The address becomes valid during PHASE 1. slots. This indicates a setup time of under 100 2, 6502 vvritedata will be valid within 200 nanosec- nanoseconds from PHASE 2 falling, far under onds (175 nsec Synertek; 175 nsec Rockwell) the 300 nanosecond maximum. In a typical after the rising edge of PHASE 2. The write Apple, the address is valid before Q3 falls dur- data wil! remain valid until at leastSO nanosec- ing PHASE 1. This is probably true of most onds (60 nsec Synertek) after the failing edge of Apples and perhaps all Apples. PHASE 2. 3. Write data becomes valid at the data bus 120 3. 6502 read data must be valid at least 100 nanoseconds after PHASE rises. This is well nanoseconds {50 nsec Rockwell) before the fal- under the MOS Technology maximum of 200 ling edge of PHASE 2 and must be held valid at nanoseconds setup time from PHASE 2 rising. least 10 nanoseconds after the falling edge of 6502 write data must be valid before CAS' falls PHASE 2. PHASE 2 falling is the 6502 data for it to be read by RAM. CAS' in the Apple falls transfer clock. 209.5 nanoseconds after PHASE rises, but 4, The maximum delay between PHASE falling CAS' falling is delayed to RAM by 20 nanosec- and PHASE 2 falling is 65 nanoseconds. The onds typical and 32 nanoseconds maximum. maximum delay between PHASE rising and Therefore, 6502 write data in the Apple that PHASE 2 rising is 75 nanoseconds. These values becomes valid on the data bus 200 nanoseconds are specified only by Synertek and only with a after PHASE 2 begins to rise will be read cor- 100 picofarad load on PHASE 2. rectly if the PHASE to PHASE 2 delay is no The time periods represent worst case conditions more than about 40 nanoseconds. over an operating range from to 70 degrees centi- 4. Read data from RAM becomes valid at the 6502 grade. Worst case timing specifications are shown just 35 nanoseconds before PHASE falls or in Figure 4.4. MOS Technolog\' time values are used about 67 nanoseconds before PHASE 2 falls. because they are more conservative than Synertek Thus the Apple design does not meet the 100 and Rockwell and, therefore, represent the actual nanosecond setup time required by MOS Tech- worst case. Synertek values for PHASE Oto PHASE nology and Synertek. A 100 nanosecond setup 2 delay are used because MOS Technology' and time is unusually long. One wonders which Rockwell don't publish this important specification. magician pulled that number out of his hat. 4-8 Understanding the Apple PHASE 2 falls 65 isec maximum after PHASE (alls. PHASE 2 begins to rise 7Snsec maximum alter PHASE rises. PHASE PHASE 2 Read Data must be ticid valid lOnsec mirsimum after PHASE 2 falls Write Data will be field 30 nsec minimum alter Address and R/W Write Data is PHASE 2 tails. are valid 300 valid 20O nsec ^ D Read Data must nsec maximum maximum after be present 100 alter PHASE 2 PHASE 2 begins nsec minimum falls. to rise. before PHASE 2 lalJs. Figure 44 Some Worst Case 6502 Specifications. Specifictimin^ of 6502 communication with var- nanoseconds after PHASE has fallen. 45 nano- ious Apple devices will be discussed in chapters seconds does not meet the MOS Technology/ covering those devices. Listed below are some gen- Synertek 100 nanosecond data setup specifica- eral guidelines for Apple peripheral design. They tion, but it is not necessary to do so. If it were, the serve to illustrate the basics of Apple bus manage- 6502 could not read RAM in the Apple. ment. The primary data bus management signal is 4. Atapproximately 60 nanoseconds after PHASE the RAM SELECT' term generated in the RAM falls, the latched RAM data output is gated to should present a high address mukiplexor. The RAM chapter should be the data bus. Peripherals studied to clarify the details of 6502 communication impedance to the data bus by this time. in the Apple. The requirements for read data being on the data 1. The 6502 address can be read before PHASE bus before and after PHASE 2 can be met in a in time to trigger a DMA action that same cycle. peripheral by gating read data with DEVICE 2. Write data from the 6502 can be clocked to a SELECT'. This signal does not overlap PHASE 2, but the data stays valid on the data bus until peripheral by the falling edge of PHASE 0. 3. Read data from peripherals should be valid on after PHASE 2 anyway. When the data bus of the the data bus by 45 nanoseconds before the end of Apple is floated {when all devices on the data bus PHASE 0, and should stay valid at least 40 present a high impedance to the data bus), the last The 6502 Microprocessor 4-9 «» « *^ 1 'S nl &« Q Vi trt 5- 3 CQ «1 v» « (/^ QJ (V a o TJ -o <. < I o ^ fCSI^ LU ui ,'|ii(: CO CO < < co < X "Iti©, I'SS^'. Q- a .a.:- 1 '&•• i3C' 4-10 Understanding the Apple PHASE PHASE 2 1 / \. DEVICE SELECT \ RAM SELECT' TO DATA BUS (B6-15) [ Data Bus floats during PHASE 2 falling, but data remains valid on the bus. Figure 4^ Reading the Disk Input Port Using Device Select'. valid data on the data bus at the time it was A 6502 machine language program is a series floated remains valid until the bus is brought of numeric bytes. The bytes are stored in sequence in back under positive control. Therefore, if the data memory where the 6502 accesses them by incre- bus is floated just before PHASE 2 falls, the 6502 menting the address bus and reading the program will still read the last valid data before the data bus while executing. 6502 machine language instruc- was floated.* As an example. Figure 4.6 shows a tions consist of one. two, or three bytes in succession. read access to a peripheral slot data input address. Each instructionconsistsof anopcodeand possibly a one or a two byte operand. Execution of a three byte instruction requires three cycles to fetch the APPLE PROGRAMMING instruction plus additional cycles to execute the instruction. There are four levels at which programs can be The 6502 has a set of interna! registers which are written in the 6502 based Apple: 6502 machine lan- manipulated by the program. A 6502 program per- g'uage,6502 assembly language, high level compiler forms its functions by overseeing the interplay language, and high level interpreter. The order of among the internal registers and memory. The 6502 listing is from most difficult to least difficult. internal register complement is made up of five 8-bit registers and the 16-bit Program Counter. The *I assume that the data is stored on the data bus via capacitive following is a list of the registersand their functions: charges. I am not sure how lon^ it would take to discharge the bus, because the bus is normally floated for a maximum of about 700 nanoseconds (during a LDA $C050 in a long 6502 cycle, for REGISTER FUNCTION example). It takes much longer to discharge the bus than to Program Counter Contains current address of charge it. A 74LS257 can bring the data bm to &3% of its high instruction being executed. state inaboulH5 nanoseconds. Assuminga collector impedance of 100 ohms in the LS257, this indicates a charging- capacitance of Accumulator Principle arithmetic and logi- 350 picofarads. The disk controller (see Chapter 9) is an example cal register. of a peripheral which uses DEVICE SELECT' tojjratedata tfl the X-register Index register. data bus for reading by the MPU. The controller could not suc- Y-register Index register. -^ cessfully transfer data to theMPU if it weren't for the slow Stack Pointer Contains current stack address. degradation of data when the data bus is fioated. Since the disk controller works reliably, it is my conclusion that the DEVICE Status Register Contains flags indicating 6502 SELECT' signal can be u.sed to gate data to the data bu.s for operating modes and logical transfer to the MPU in Apple peripheral designs. results of instructions. The 6502 Microprocessor 4-1 Generally, programs center around the Accumula- this is an assembler. An assembler takes an assem- tor and nnemory with the X- and Y-registers being bly language souf ce program and assembles from used for address indexing. Values of the Program it amachine language object program. Counter, Stack Pointer, and Status Register are 6502 programs can be assembled in disk-based automatically kept by the 6502 and don't usually Applesusinganyof several commercially available have to be accessed directly by the program. Provi- assemblers. This is the best way for most Apple sions exist for direct control of the Stack Pointer and owners to write extensive 6502 programs. Com- processor status. The Program Counter is controlled pared to almost any computer, minicomputer, or by the flow of the program. microprocessor machine language, 6502 machine The following is a three instruction 6502 machine language is very simple to use. This extends to 6502 language program listed in hexadecimal; assembly language. There are only 56 mnemonic codes to learn, and the logical selection of mnemon- OP ADDRESS ADDRE. ics makes this a simple learning task. CODE LOW HIGH The simple instruction set has advantages and AD ID disadvantages. The chief disadvantage is that in 89 some instances a program will require more instruc- 85 m tions to accomplishapurpose than it would if power- 00 ful special purpose instructionswere available. This can result in loss of speed and waste of memory The first instruction loads the 6502 Accumulator space in some programs. One should not get the idea from address $1D89. The second instruction stores that 6502 is without powerful features. It has a very the 6502 Accumulator contents at address $16, The versatile set of addressing modes and a decimal final instructionis a BREAK instruction which mode which speed execution of certain types of pro- terminates the program. The purpose of the pro- grams considerably. It's just that there are more gram is to transfer the contents of $1D89 to $16. f>owerful and complex microprocessors around. Machine language programs may be entered and The chief advantage of the simple instruction set executed from the Apple monitor using methods is ease of programming. A second advantage is that it described in the Apple II Referemr Manual. made it easier for the Apple designer to include Assembly language is a way of writing machine a 6502 disassembler and Mini-Assembler in language programs with computer assistance. Many the firmware of the original Apples. The Mini- aspects of machine language programming are per- Assembler in ROM is an invaluable aid to students formed better by computer than by humans. Some and practitioners of 6502 programming. It comes as such aspects are remembering op codes, addition an associated utility with Integer BASIC and is and subtraction of addresses, remembering ad- available to Apple users who have Integer BASIC, dresses of subroutines, and checking for syntax The Mini-Assembler has some characteristics of a errors. Assembly language assists the programmer full assembler. It automatically translates mne- with these and other details and allows the use of mon ic op codes and 6502 assembly language conven- English language symbology for addresses, oper- tion operands to 6502 machine language code. It also ands, and opcodes. A prime goal in computer automaticaly computes relative branch references language development is English language com- from absolute address entries and checks for syntax patibility. errors. In other words, it allows machine language The same program that was listed above in code to be immediately translated and entered from machine language is listed here in assembly assembly language keyboard entries. Some very language. important assembly language capabilities are lack- ing in the Mini-Assembler. There is no English lan- LABQ, OP OODE ADDRESS OOfWENT guage symbolism except for the op code mnemonics. RESTORE LDA $1D89 RESTORE SAVED POINTER Also, there is no relocatability feature which is sm $X6 inherent with full assemblers. 6502 machine lan- guage is usually not relocatable, but machine code can be assembled to operate at any valid memory This program contains English language which location from an assembly language source pro- cannot be executed by the 6502. A computer can, gram. Still, there is noeasier way to write and enter however, take this program and convert it to 6502 a short 6502 program than on the Apple's Mini- machine language program. A program that does Assembler. 4-12 Understanding the Apple As an example for Apple users who may never as with assemblers, symbolic source code must be have used the Mini-Assembler before, here is a short entered with the assistance of a text editor. The sequence of keystrokes to enter some 6502 code. compiler source code must be compiled into mach ine Start by enter ing Integ'er BASIC. If you do not have language object code before a program can be run. Integer BASIC, you probably don't have the Mini- In some ways, this process of converting a high Assembler. level language program to machine code is a nui- sance. The object code must be compiled before it SCREEN PROMPT / can be run and debugged. In an alternate process, a KEYBOARD ENTRIES REMARKS high level language program can be interpreted as >CALL~245S Enter Mini-Assembler it is run. The interpreting program examines the !1000: LDX #10 high level language commands during program •JSR FF3A Use Apple's BELL execution, and it directs program flow to resident routine !DEX machinelanguage routines which perform the indi- ! BNE 1002 cated functions. This is the process used with the 1 RTS Applesoft and Integer BASIC languages supplied ! [CTRL-RESET] Re-enter BASIC with the Apple II computer. >CALL 4096 Call Bellringec Both the compiling and interpreting processes are available for high level languages in the Apple This program calls the BELL routine in Apple II. In addition to the Applesoft and Integer BASIC firmware 16 times. This is the end of assembly lan- interpreters in common usage, compilers are avail- guage instruction in this book. Persons who wish to able that will compile stored Applesoft and Integer learn more can do so by reading the Apple II Man- programs into machine language routines. These ual and studying the listings of the Autostart ROM routines will execute much faster than an interpre- and Monitor ROM. There are several 6502 assembly ter performing the same function, because the time language books which one can purchase. The best consuming interpretation process is separated from way of all to learn is to buy an assembler and start execution. Compilers and interpreters for other programming. high level languages are also available. Another way to produce machine code involves — Which language should you program in assem- the use of compilers. Programs may be written in bly language or a high level language? The answer high level languages such as BASIC, Pascal, and depends not only on the programmer's background, FORTRAN, High level language programs consist experience, and personal preference, butalso on the \ of powerful symbolic commands such as "PRINT" requirements of the particular application. Assem- A and "=". 6502 cannot execute such commands, but bly language is fastest and provides the most effi- computer programs (compilers) can examine such cient use of memory space. Some programs re- commands and produce 6502 machine language quiring speed or large amounts of memory can be code which will cause the 6502 to perform the indi- written only in assembly language. Machine code cated functions. compiled from high level language source code A compiler is like an assembler in that it takes a offers a great combination of programming ease symbolic language source program and translates it and speed of execution. BASIC programs inter- to a machine language object program. It is differ- preted and executed by the firmware interpreter ent from an assembler in that whole machine lan- supplied with the Apple are the easiest of all to write guage routines are generated by a single compiled and debug, but very slow in execution. instruction. Only one machine language instruction Whatever languageyou program in, the 6502 will is generated by an assembly language instruction. be executing machine language code. All of the High level languages are much more powerful than important Apple operating systems— BASIC, Pas- assembly language in easing the task of the pro- cal, DOS, the monitor, and the Mini-Assembler— grammer. However, machine language code com- are machine language code which was originally piled from high level languages is generally less written in assembly language. efficient than code assembled from assembly lan- An important footnote while discussing Apple guage programs. The programmer has direct con- programming languages and operating systems is trol over the machine code generated in assembly the secondary MPU which may replace the 6502 via language, and human minds generate more effi- the DMA' line. These secondary MPUs greatly cient code than compiler programs. With compilers. expand the possibilities of what one might find ihe 6502 Microprocessor 4-13 operating in the Apple. Of particular importance is RAM by pulling DMA' low while PHASE is low the Z80 card and the associated CP/M operating and holding DMA' low until PHASE goes high system. CP/M (Control Program for Microproces- then low again. Pulling DMA' low forces the MPU sors}isadiskoperatingsystemdeveloped by Digital address bus driver to a high impedance state and Research company for which many programs are gatesoffthe PHASED clock inputto the MPU, With available. The Apple with Z80 card is potentially the DMA' low, even though PHASE goes high at pin most important CP/M computer, 40 of the peripheral slots and everywhere else on the motherboard, PHASE does not go high at pin ;^7 of the MPU. The 6502 waits with PHASE 1 high and DMA IN THE APPLE PHASE 2 low. PHASE 1 high forces thedirection of DMA (Direct Memory Access) refers to a form the MPU external data bus driver to be from the of fast I/O in which the I/O device directly accesses data bus to theMPU, The MPU is thus isolated from memory. In DMA, the MPU is removed from the the address bus and data bus, and the peripheral data transfer path between the device and RAM. card can take control of both buses and the R/W There is no program sequence loading data from the line.DMA devices should communicate with the source and storing it at the destination. data bus at the end of PHASE as the 6502 does. In The video scanner access to RAM while PHASE the Apple, PHASE 1 belongs to the video scanner is low is a form of DMA referred to as simultaneous and devices do not respond to addresses except dur- DMA. It is possible because RAM can be accessed ing PHASED. twice as fast as theMPU access in the Apple and Figure 4.7 shows the timing for stealing a cycle because actual MPU data transfers occur only dur- from the 6502 on the Apple. It would be wise not to ing a short period at the end of the 6502 machine steal too many cycles at a time, because if the clock is cycle. This simultaneous DMA is completely trans- stopped too long, the 6502 will lose its internal data parent to the MPU. It has no effect on program and the program will be bombed. It is not clear how execution since it does not affect the 650iJ machine long the clock can be stopped before the 6502 opera- cycle. tion becomes unreliable. "The MOS Technology data A second form of DMA is cycle stealing. In cycle sheet lists the maximum PHASE pulse width at stealing DMA. theclock input to the MPU is stopped 520 nanoseconds. This is clearly not accurate be- DMA device accesses for a machine cycle, and the cause every Apple in the world operates very well RAM while the MPU is stopped. Thus, a cycle is with a 629 nanosecond PHASE pulse on one out of stolen from the MPU. This type of DMA slows pro- 65 cycles. The Onbonic h & S-Bit Microprocessor gram execution. Handbook {copyright 1981, McGraw-Hill, Inc. by Cycle stealing DMA is implemented in the Apple. Adam Osborne and Gerry Kane) states that you The DMA' line is wired to pin 22 of the peripheral cannot stretch the PHASE 1 or PHASE 2 clocks on slots and any peripheral card can directly access MCS6500 microprocessors. Osborne and Kane must DMA DATA TRANSFER CLOCK \y PHASE PERIPHERAL PIN 40 1 / \_ DMA' PERIPHERAL PIN 22 PHASE 6502 PIN 37 1 1_ PHASE 1 6502 PIN 3 / Figure 4.7 Cycle Stealing DMA. 4-14 Understanding the Apple II have read the same data sheet. The Synertek data have you can be plugged in to allow eoiitrol of the sheet for SY650X microprocessors shows a maxi- Apple by the owner's favorite MPU. These cards mum cycle time of 40 microseconds. This seems to gain access to the Apple via the DMA' line. indicate that you can perform DMA in the Apple for The DMA' line has no effect on video scanner 40 consecutive PHASE cycles without adversely access to RAM, since the video scanner is isolated affecting the Apple. The Rocltwell International from the address bus. The DMA device must make data sheet shows a maximum cycle time of 10 its access during PHASE 0, however, for Apple microseconds which is probably a good number. devices to respond properly. Apple circuits listen to It happens that Steve Wozniak. the desijrner of the the address bus only during PHASE 0. Apple II, knows a Rreat deal about this subject. In a The 6502 designers intended that the READY conversation with the author. Mr. Wozniak revealed line be used for DMA. Their idea was to stop the that his original design for the Apple II used a dif- 6502 in a read cycle and bring an external tri-state ferent method of scanning memory for video output address bus driver to high impedance with the than the simultaneous DM A used in his final design. READY line while DMA took place. The READY When he was designing the Apple II, RAM chips line in the Apple has no effect on the tri-state which could be accessed at 2 MHz were just becom- address bus driver, so DMA can only be accom- ing available. As a consequence, the early design plished by pulling the DMA' line low. The DMA' had a 1 MHz (i502 from which 40 out of 65 cycles line can be pulled low in conjunction with the were stolen for memory scanning. The (i502, there- READY line, butafter a number of cycles the 6502 fore, effectively ran at about 885 KHx (25/65 x 1 will lose its internal data, because it has no input MHz). What Mr, Wozniak found out was that you clock. Long DMA operations with the MPU in a wait could hold off the clock on a new 6502 for 40 state must be accomplished by bringing the RE ADY microseconds, but that as the chip cooked in, this line low and performing cycle stealing if it is impor- hold off capability deteriorated. He found it neces- tant that the 6502 restarts coherently from where it sary to keep new 6502s handy so he could replace the stopped. MPU when the Apple started to malfunction. The There is a priority system of DMA operation in f)502s were not failing. They were just becoming the Apple in which the lowest peripheral slot has unable to retain data for 40 microseconds with the priority if more than one peripheral tries to perform clock stopped. Mr. Wozniak speculates that the rea- DMA at the same time. The priority system is son for this is a deter ioriati on in capacitance of implemented by a DMA in/DMA out priority chain interna] elements after the 6502 is run for a while. which goes from slot to slot. Pin 27 the DMA input is Mr, Wozniak never determined the maximum reli- on each peripheral slot which tells a card that no able hold off time of the 6502 experimentally. The higher priority card is performing DMA. Pin 24 is availability of faster RAM chips enabled him to the DMA output by which DM A from lower priority design the superior version of the AppSe II which cards is disabled. Slot has the highest priority and was eventually released. His feeling is that it is safe Slot 7 has the lowest priority. Pin 24 on each slot is to hold off the clock to a 6502 for five microseconds, tied to pin 27 on the next slot with Slotfl. pin 27 and which is the value used in Microsoft's Z-80 card. He Slot 7, pin 24 not connected as shown in F'igure7.9. also cautions that any experimental determination Please note that in Revision 7 and later Apples, pin of this capability would have to be performed on new 24 of Slot 7 is connected to jumper pad 7 as shown in 6502s, used 6502s, and very used 6502s. Figures 7,9 and 7.10. It's pretty obvious that the DMA' line can be used In the priority system, when pin 27 is low a card for more than just direct access to RAM. Since 6502 should not attempt DMA, because a higher priority control of the Apple is via address decode, any card is performing DMA. The card should also device controlling the address bus can control the bring pin 24 low so lower priority DMA cards are Apple. For example, a very simple peripheral card disabled. If pin 27 is high, a card may perform could change Apple screen modes via pushbutton. It DMA. It should bring pin 24 low while performing would just have to steal a single cycle from the 6502 DMA and bring it high while not performing DMA. and gate$C05X to the address bus during PHASE Non-DMA cards are always designed with pin 24 to select a screen mode depending on which button jumpered to pin 27 so they can be inserted between had been pressed. The most common use of the DMA cards in the peripheral slots. This keeps the DMA' line in the Apple is to operate an MPU other priority chain intact. There can be no empty slots than the 6502 from a peripheral slot. A Zilog Z80 between DMA cards in a priority chain. card, Motorola MC6809 card, Intel 8088. or what The 6502 Microprocessor 4-45 The DMA priority chain can be used to prioritize Stack Pointer is decremented while the three values other functions besides DMA. Apple does this with are being read from memory, as if data were being its firmware cards which substitute peripheral card pushed to the stack. Normally, the Stack Pointer is ROM for motherboard ROM. Several firmware incremented during pull operations and decre- cards can be placed in a priority chain which pre- mented during push operations. vents ROM on two separate cards from being simul- In the original Apples, the F8 ROM was called the taneously enabled. If two rroups of cards use the Monitor ROM because it contained the system DMA chain for different purposes, they may have to monitor, which is a program that enables the user to be separated by an empty slot or by a card with pin communicate with the Apple on a very basic level. A 27 or pin 24 open. For example, a firmware card in RESET' in the old monitor ROM caused the 6502 to Slot would interfere with the operation of a DMA vector to $FF59 which is an entry point to the moni- card in Slot 1. Even when a firmware card is tor. Thus, when the computer was turned on or enabled, cycles are available when RAM or I/O is RESET was pressed, the user found himself com- accessed in which the DMA priority line stays hiprh. municating with the Apple through the keyboard A DMA device down line from the firmware card and television screen as controlled by the system will operate if it needs only to steal an occasional monitor. evcle. and can wait for the firmware card to access Today's Apples have a different F8 ROM called RAM. the Autostart ROM. It still has the system monitor in it, but some old capabilities were lost and some 6502 INTERRUPTS IN THE APPLE new ones were gained. The response to RESET' is completely different. The RESET vector in the There are actually four types of 6502 interrupt: Autostart ROM is$FAfi2. The operation of RESET' RESET', NMI'. IRQ', and the BREAK instruction. with the Autostart ROM is fully explained in the Each has its own unique characteristics and pur- Apple II RefcrotccMnnnaLhutihe basic points are poses as determined by the 6502 design. The hard- given here. Most notably, the RESET' transfers ware interrupts are connected to the peripheral program control to a RAM vector. This means that slots, and RESET' is also connected to the RESET the ultimate response of the Apple's RESET key is key and power-up reset circuit. The BREAK controllable by software. At power up, the RAM instruction is asoftware interrupt. The response of RESET vector ($3F2 and $8F8) is set. and from that the 6502 to interrupts in the Apple is determined by point, it may be set to any value by whatever pro- propTfams contained in the F8 ROM. gram is controlling the Apple at a given moment. If the Apple has no disk drive, the RAM RESET vec- RESET^ tor is set to enter BASIC at power up. If there is a disk drive, the Apple enters the bootstrap routine Except for RESET', the general idea of the inter- contained in ROM RAM on the disk controller. The rupts is to interrupt the MPU. perform an interrupt RESET vector is usually set by software loaded handling routine, and then return to the interrupted from the disk. The automatic startup of the disk is program. The general idea of RESET' is to inter- what gives the Autostart ROM its name. rupt the MPU and go to a coherent program start. Autostart ROM firmware only boots the disk on a There are no provisions in the 6502 response to a RESET that occurs at power up. Other RESETs RESET' for saving internal registers and returning cause program flow to go to the address contained in to the place where the program was interrupted. the RAM RESET vector. The firmware uses a code The 6502 response to RESET' is as follows: at $.'?F4 to determine whether a given RESET' was 1. Pull three meaningless values from the stack. initiated at power up or not. The code is never prop- 2. Fetch the RESET routine address from $FFFC erly set at power up, but the power-up RESET sets and $FFFD, low byte first, the code so the following RESETs will not be "cold 3. Set IRQ' disable bit of Status Register: leave starts." The power-up byte {$;^F4) must be the other Status bits as they are. exclusive-OR between $A5 and the contentsof $3F3, 4. Begin execution of RESET routine. or a power-up RESET will be performed when The reason for the three meaningles.? stack accesses RESET is pressed. Any program can scramble the is that RESET' is a modified form of the other inter- power-up code and forcca "cold start" when RESET rupts with R/W forced high. Accordingly, the is pressed. 4-16 Understanding the Apple There are advantag'es and disadvantages in the 4. Normal pi'ogram flow is resumed with inter- softRESET vector. The chief advantage is that the rupt requests enabled or disabled as they were user has a versatile, programmable reset function. before the non-maskable interrupt occurred. The chief disadvantage is that the prime purpose of A second non-maskable interrupt will not interrupt a microprocessor reset can be defeated by a pro- NMF line held the routine of the first as long as the is gram. There is no way for the user to reset his com- low. Thus while NMF is not maskable by program puter if a program doctors the RAM RESET vector control, it is hardware maskable in the sense that for some other purpose. The Apple is set up so the any interrupting device can prevent further inter- user can be denied access to his own computer by rupting by hoidingNMF low. Recall thatpartof the accident or on purpose. Sometimes the Apple user is NMI sequence is the disablingof interrupt requests, required to turn off the computer and turn it back on so the IRQ' cannot interrupt an NMF handler unless when itgetshungup. At turn on, electronic circuits the handler enables it. are vulnerable to failure, so turning a computer off, A typical order of events with IRQ' is: then on, to achieve a reset is a chink in the armor. 1, The IRQ' drops low. 2, The interrupt routine execution is begun with NMl' and IRQ' interrupt requests disabled. 3. The interrupt is acknowledged and IRQ' goes The NMI' and IRQ' lines are both connected only high. to the peripheral slots in the Apple. The IRQ' is the 4. The interrupt routine execution is completed normal I/O interrupt signal because it can be and normal program flow is resumed with enabled or disabled under program control. The interrupt requests enabled. idea of a non-maskable interrupt is to take action which has higher priority than any programming Interrupt requests are d isabled by the IRQ' sequence purpose. For example, an Apple may be required to just as they are in the NMF sequence. This prevents take emergency action in the event of a failure in a the still low IRQ' from immediately generating a manufacturing robot it is controlling. The non- second interrupt. The program maskable IRQ' can maskable interrupt can also be used in monitoring be used in any variety of implementation methods. the Apple operation from a remote panel or single The program must acknowledge and enable inter- instruction step execution of 6502 programs, Those rupts in a manner consistent with the protocol of the applications would, of course, require peripheral interrupting hardware. The point with IRQ' is to card designs. acknowledge the interrupt before enabling further The interrupt sequence is similar for either NMI' interrupts so that multiple interrupts are not gen- or IRQ', The 6502 first completes execution of the erated inadvertently. Interrupt acknowledges in current instruction. Then the following sequence the Apple usually consist of an access to one of the occurs in the case of NMI' or IRQ' with interrupt peripheral slot assigned addresses. requests enabled: The enabling and disabling of IRQ' can be done 1. Program Counter is pushed on stack, high byte fairly effortlessly in many applications. Either NMF or IRQ' saves the Program Counter and processor first. Status Register on the stack before vectoring to the 2. Processor Status is pushed on stack with interrupt handler. The Status is saved before the BREAK bit reset. interrupt disable bit of the Status Register is set. If, ,3, Contents of interrupt vector (NMF = $FFFA- at the end of the interrupt handler, an RTI (ReTurn .$FFFB; IRQ' = $FFFE-$FFFF) are fetched, from Interrupt) instruction is e.xecuted, the Pro- low byte first. 4. Interrupt routine is begun with interrupt re- gram Counter and Status Register are restored. Along with the rest of the Status Register, the pre- quests disabled. interrupt state of the interrupt disable bit is re- There is a basic hardware difference between stored. Further interrupts are automatically dis- NMI' and IRQ' in the 6502. NMI' is edge sensitive abled by the interrupt sequence and the disable/ like aclockpulse input, and IRQ' is level sensitive. enable status is automatically restored by the RTI A typical order of events with NMI' is: instruction. The other 6502 registers( Accumulator, 1. The NMI' line drops low. X-register, Y-register, and Stack Pointer) are not 2. The NMI handling routine is executed with automatically saved by interrupts. These must be interrupt requests disabled. saved and restored by the interrupt handler if the 3. The NMI' line is brought high. application demands it. The 6502 Microprocessor 4-17 In some applications It would be desirable to ena- addresses of the IRQ' firmware are different. An ble interrupt handlers to be interrupted. This sort of NMI' simply vectors straight to $3FB, where a processing is handled well by the stack architecture. JUMP instruction to the software NMI' handler Return link information for each interrupt is simply must be stored. stacked over each other, possibly several interrupts The IRQ' is handled differently. A short firmware deep. All of the interrupts are eventually fully ser- routine is executed which determines whether a viced when the congestion is reduced. BREAK instruction or an interrupt request is being Any peripheral card may interrupt the 6502 in processed. Both IRQ' and the BREAK instruction the Apple. If there is a possibility of multiple inter- use $FFFE and $FFFF as their vector, and the rupt sources, the 6502 needs to be able to distinguish IRQ' handler must distinguish between BREAK among the interruptingdevices. This can be done by and an external interrupt request by checking the polling. In polling, the interrupt handler checks status that was pushed to the stack when the each peripheral slot to see if it caused the interrupt. BREAK or IRQ' occurred. When it is determined Each card in a polling system must be capable of that an external interrupt occurred, the program responding to an address prompt by placing its vectors to the contentsof $3FE and $3FF. $3FE and interrupt status on the data bus (normally D7 of the .$3FF should contain the addressof the IRQ' handler. data bus). In distinguishing between BREAK and IRQ', the The peripheral slots have an interrupt priority Apple firmware saves the contents of the 6502 chain which works exactly like the DMA priority Accumulator at $45 and then modifies the Accumu- chain. Card designs supporting the priority chain lator. The interrupted accumulator value must be follow the same protocol as described in the section retrieved from $45 if it is required for processing or on DMA. As in other priority operations, SlotO has restoration. Stacked interrupt applications requir- the highest priority and Slot 7 has the lowest prior- ing the savingof 6502 registers should save them on ity. Cards in a priority chain control interrupts at the stack. The accumulator value must be retrieved lower priority cards and are controlled by higher from $45 before pushing to the stack in the Apple. priority cards. The priority chain does noteliminate the need for polling in a multiple interrupt source environment. Nor is the priority chain necessary to The BREAK Instruction determine priority since this is determined implic- The BREAK instruction is a software generated itly by theorder in which the interrupt handler polls interrupt which is not disabled by the IRQ' disable the devices. Still, there are many conceivable uses bit of the Status Register. Its uses are not obvious, for the priority chain. For example, a card may even to an experienced computer programmer who perform operations which will not tolerate inter- has not been exposed to it. Why would a program rupts from lower priority devices, but will tolerate want to interrupt itself? interrupts from higher priority devices. Through One use of BREAK is to make it the terminating the priority chain, system designs can be imple- instruction of 6502programs rather than a RTS mented to selectively enable high priority inter- (ReTurn from Subroutine). The idea here is to havea rupts only. program terminating routine which directs pro- There is away in the Apple to determine priority gram flowtosome sortof system utility. In thissense of interrupts without any loss of time. This way the BREAK is a programmable HALT instruction. would be to have the interrupting card contain its A second way of using BREAK is as a debugging own IRQ vector. In the Apple, any peripheral card breakpoint. When debugging or investigating soft- can disable motherboard ROM and steal ROM ware, it is often useful to stop a program at a specific add resses. The interrupting card vvou Id only have to address and to examine program progress. The steal SFFFE and $FFFF to vector the Apple to its BREAK instruction is a very convenient way of handler. This system could use the interrupt prior- doing this. Instead of overwriting three bytes of code ity chain to prevent two cards from simultaneously with a JUMP instruction, only one byte is overwrit- responding to $FFFE or $FFFF. ten by the BREAK instruction. The program count- The firmware implementation of NMI' and IRQ' er and processor status are saved on the stack as handlers is very simple and nearly identical in the with IRQ' and NMF so a BREAK handler can be Monitor ROM and Autostart ROM. IRQ' and NMI' written to insert break points and resume flow after are handled the same in either ROM. but the investigation. 4-18 Understanding the Apple A third use of BREAK is to allow out of control BREAK flag exists only in RAM after a push to the 6502 prof^rams to bomb gracefully. A misdirected stack operation in accordance with the following program tends to lead program flow to an address rules: where no proprram has been stored. But the MPU doesn't know there is no program there. The 6502 is 1. PHP command sets bit 4 in RAM (no signif- like a dog in heat; it will try to execute anything it icance). finds on the data bus. This can be chaotic in any 2. Push Status resulting from NMI' resets bit4 in system but especially in a memory mapped I/O sys- RAM (no significance). tem like the Apple. Printers or disk drives can start 3. Push Status resulting from IRQ' resets bit 4 in operating when random addresses are accessed by RAM (identifies IRQ'). the MPU. It happens that, at power up. much of 4. Push Status resulting from BRK command sets RAM goes to a state of all zeroes. $00 is the op code of bit 4 in RAM (identifies BREAK interrupt). the BREAK instruction and, as a consequence, many bombed programs wind up executing a BREAK status is meaningful only in an IRQ' handler. It can be checked in an IRQ' handler with BREAK instruction. This is good, because the the following sequence: BREAK handler is usually designed to neatly ter- minate a program and enter a human communica- tion utility. In thisway the BREAK instruction redirects the indiscriminant6502. It is an interrupt upon crash instruction. The response ofthe 6502 to a PLA BREAK instruction consists of the following PHA sequence: AND #%000100O0 1. Program Count +2 is pushed to the stack, high BNE BREAK.HANDLER byte first. BEQ CONTINUE, IRQ 2. Status Register is pushed to stack (BREAK bit set). 3. BREAK/IRQ' address is fetched from $FFFE 'The handling of BREAK commands is different and $FFFF. low byte first. between the Monitor ROM and the Autostart ROM. 4. Program execution is begun at address con- tained in $FFFE and $FFFF with interrupt In both ROMs, the BREAK is first detected in the requests disabled. IRQ'/BREAK routine. Then the interrupted Status is restored, possibly enabling interrupt requests. The difference between the external interrupt Then all interrupted 6502 register states are stored request and the BREAK command is the BREAK in $3A, $30, and $45 through $49. At this point in flag, which is shown in 6502 literature as bit 4 of the the old Monitor ROM, the interrupted register Status Register. The BREAK flag is conceptually states are displayed, the instruction at interrupted different from the other status flags, however. It is Program Count +2 is disassembled and displayed, not tested by any 6502 instructions, and there is no and the system monitor is entered. At the same point set or clear instruction for the BREAK flag. It can in the Autostart ROM, the program flow vectors to only be checked after the Status Register has been the contents of $3F0 and $8Fl. The soft BREAK placed on the stack. It is checked by pulling the vector ($3F0 and $3F1) is loaded at power up with Status value from the stack and checking bit 4. the address of the same BREAK routine that was Rather than a hit of the Status Register, the contained in the old Monitor ROM. Therefore, the BREAK flag seems to be a characteristic of the BREAK routines in the two ROMs perform identi- way processor Status is pushed to the stack.* The cally after power up, but, from that point, the Auto- *The above concept of the BREAK fla^ is based strictly on my startBREAK handler can be changed. The old own experiments. In no lilL'raturewa.'il able to find a satisfactory monitor BREAK routine is fixed in ROM with no description of !(]>K-ificiilly when the BREAK fiagissetand reset. user programmable capability. The concept of BREAK statu.sbeinfr stored in bit 4 of the Status The Apple firmware routines are adequate for Rppister simpiy does not fit the way I found RREA K status to be terminating programs and inserting debugging stored and cheeked. Inside thefi5()2, there may well be a bit of the Status Register which Iteeps track of BREAK status. In any case, breakpoints. Program status saved by the BREAK BREAK status can only be checked by retrieving the it from handler isavailablefor res tartof flow via theG(GO) RAM after a push Status to the stack operation. command of the monitor. The 6502 Microprocessor 4-19 Priority Among Interrupts disable interrupt f !ag of the Status Register as part of their initial sequence. This disables external There are priority considerations among' the inter- interrupt requests only (IRQ'). rupts which determine what happens when more In theeventof simultaneous NMI', BREAK, and than one interrupt occurs at the same time. The IRQ' with IRQ' enabled, the processor would com- general priority of interrupts is as follows; plete theBREAK instruction, fetching the contents of the IRQ'/BREAK vector and disabling interrupt Highest RESET' requests. Then the NMI' sequence would occur. If NMI' the NMI' handler enabled interrupts and the IRQ' BREAK was still low, the IRQ' sequence would take place. Lowest IRQ' The more likely case would be for the NMI' to be serviced with interrupts disabled. Following the In the event of simultaneous interrupts, RESET' RTI at the end of the NMI' handler the IRQ'/ overrides all other processor actions. If NMI' drops BREAKhandler would be executed with bit 4 of the low while RESET' is low, the processor will not top byte of the stack identifying the interrupt as a respond to it. Once the RESET' routine has been BREAK. In the Apple, the pre-BREAK Status is entered, however, the processor can be interrupted pulled from the stack as soon as a BREAK is identi- by NMI' or BREAK. For this reason, it may be best fied. This would enable interrupt requests in our for a card to disable its NMI' generating circuitry example and allow the IRQ' sequence to begin, when RESET' occurs and leave it disabled until assuming IRQ' was still low. Following the RTI signaled by the 6502 that the RESET' routine is instruction at the end of the IRQ' handler, the accomplished. The idea of RESET' is to reset the BREAK routine would be reentered and its course whole sytem, notjust the 6502. All interrupts set the would be run. 4-20 Understanding the Apple II SOFTWARE APPLICATION 6502 INSTRUCTION DETAILS The state of the address bus and data bus on every There are other interesting points about 6502 cycle of operation are normally of no interest to the addressing. The read-mod ify-write instructions Apple proprrammer. However, there are non-obvious (ASL, LSR. ROL. ROR. INC. DEO always perform features of 6502 command execution which affect a double write to the valid address. The first write proprramminf? of I/O. This is a natural consequence cycle writes the same data that was read, and the of decoding I/O commands from the address bus. second write stores the modified data. Pulling data These address details are of particular interest to from the stack results in a superfluous access to a the assembly languaj^e programmer, but they affect wrong Page 1 address. All superfluous accesses to some BASIC prosrams too. wrong addresses are on read cycles, and the result- Table 4.1 contains an example of every type of ing data is ignored by the 6502. instruction sequence found in the 6502. It shows the Three software applications of 6502 addressing state of the address bus and data bus for each cycle details are in the controlling of the serial outputs, of execution. LDA. DEX. ASL. PHA. and PLA were the 16K RAM peripheral card, and the disk con- chosen to represent classes of instructions whose troller. The speaker and cassette are toggle outputs execution sequences were identical. Table 4.2 is which are usually made to toggle up and down at an keyed to Table 4.1. To find an example of any audio rate. The speaker, for example, should not instruction and address mode, look up the instruc- normally be accessed by instructions which make a tion in Table 4.2. then see the referenced example in double or quadruple access to $C0;^0. because that Table 4.1. would re.«>ult in the speaker line toggling back and The OP CODE of all instructions shown in Table forth at one megahertz. The idea is to toggle the 4.1 is assumed to reside at .$1000. The X- and Y- speaker, wait a thousand microseconds or so. then reffisters both contain S20 in all examples, Y- toggle it again. Similar considerations exist for the indexed instructions are represented by X-indexed C040 STROBE'. The programmer may select a sin- examples when Y-indexed execution is identical to gle, double, triple, or quadru{)le strobe by utilizing X-indexed execution. When possible, LDA exam- one of the following instructions: ples are used to represent storing instructions (STA. STX. STY), and in these examples the write cycles STA $C040 one Strobe of storing instructions have a "w" following: their STA $C040,X (X=0J two Strobes address. Cycles that are always write cycles have a ASL $C040 three Strobes "W" following their address. The letters "PX" stand ASL $C040,X (X=0) four Strobes for Page Crossing. A few examples show^ the first cycle of the next instruction. This is indicated by In BASIC, it helps to be aware of what machine "NEXT OP" on the data bus. language instruction actually performs the memory At times, the 6502 addresses parts of memory access when a PEEK or POKE instruction is exe- which have nothing to do with a given instruction. cuted. The following instructions perform theactual This occurs when the 6502 is performing an internal memory access in the Apple: operation in a cycle and really doesn't need to address anything. Indexing or branching across Applesoft PEEK - E76F; LDA($50),Y Y=0 page boundaries always results in a superfluous Applesoft POKE - £781.^ STACS50),y Y=0 access to an address in the wrong page. It takes an intf-qer PEEK - EEF9: LDA[$CE} ,Y 5C=0 integer POKE - Er0D; STA[5CE) ,Y if=0 extra cycle for the 6502 to increment or decrement the high portion of an address computed across a page boundary. A "LDA $5F72,X". for example. Correlatlngthe PEEK and POKE instructions with takes four cycles with no page crossing, and five examples 26 and 28 of Table 4.1 indicates that cycles with a page crossing. STA instructions in POKE instructions generate a double access to the which the possibility of a page crossing exists allow POKE'd address, and PEPZK instructions generate an extra cycle whether the page crossing occurs or a single access to the PEEK'd address. For this not. The.S'//Hr/-/r'/; Profirtun m n D MAnual Controller. AAAA A BUTTON BUTTON BUTTON BUTTON RW 7654 3 FUNCTION 0/1 2/3 4/5 6/7 W 0000 lie MEMORY MANAGE 8 STORE RAMRD RAMWRT SLOTCXROM W 0000 1 lie MEMORY MANAGE ALTZP SL0TC3R0M a0COL ALTCHARSET X 0010 X CASSETE OUT TOGGLE PUSH ANY BUTTON X 0011 X SPEAKER TOGGLE PUSH ANY BUTTON X 0100 X C040 STROBE' POSH ANY BUTTON X 0101 SCREEN MODE CTRL GR/TXT NMIX/MX PG2/PG1 LORES/HIRES X 0101 1 ANNUNCIATOR CTRL AN0 ANl AN2 AN3 X 0101 1 lie 560 POINT MODE ENA/DSBL X 1000 X FIRMWARE CARD CTRL ENA/DSBL ENA/DSBL ENA/DSBL ENA/DSBL X 1110 DISK HEAD CONTROL PHASE-0 PHASE-1 PHASE-2 PHASE-3 X 1110 1 DISK CONTROL OFF/ON DRIVE 1/2 SHIFT/LOAD READ/WRITE The 6502 Microprocessor 4-27 Figure 4.9 A Screen Mode Controller. with that card's operation. This can be pre- 4. DMA pards which do not support the prior- vented by opening the DMA IN jumper on D ity chain. Cards like these are like citizens who MAnual Controller. Lower priority firmware do not meet their responsibilities to society. Do cards are not interfered with by D MAnual Con- not operate the pushbuttons of D MAnual Con- troller, because the Controller does not generate troller when such cards are active. Only one addresses in the firmware card range. card at a time can perform DMA in the Apple. Disk or Cassette I/O. Disk and cassette I/O in Readers who wish to are encouraged to build D the Apple are normally performed in precise MAnual Controller for their own use. They may also timing loops. Any DMAdevice which is acti- purchase the Controller, assembled and tested. The vated in the midst of such loops will interfere Controller is being manufactured by the Southern with them and the associated data transfer. California Research Group of Goleta, California. Therefore, you should never operate a pushbut- Readers of this book may order D MAnual Con- ton of D MAnual Conti*o51er while cassette or troller by contacting: disk I/O is being performed, especially during- \vrite operations. Some hard disk or eight inch D MAnual Controller floppy disk Apple interfaces are DMA based. Southern California Research Group Any such devices should probably be mounted Post Office Box 2231-U in a higher priority slot than D MAnual Con- Goleta CA 981 18 troller, so that if they support the DMA priority (805) 685-1931 for information chain, the integrity of disk data transfer will be (800) 821-0774 In California, for orders only insured. (800) 635-8310 Outside California, for orders only Table 44 Selection ot 16K RAM Card or lie Bank Switched RAM from D MAnual Controller. AAAA A RW 7654 3 FUNCTION BUTTON OR 4 BUTTON 1 OR 5 BUTTON 2 OR 6 BUTTON 3 OR 7 R 1900 BANK 2 CTRL BEADON - WRTOFF READOFF READOFF - WRTOFF READON WRTCOUNT=0 WRTCOUNT+1 WRTCOUNT=0 WRTCOUNT+1 w 1000 BANK 2 CTRL READON - WRTOFF READOFF READOFF - WRTOFF READON V*RTCOUNT=0 WRTCOONT=0 WRTCOUNT=0 WRTCOONT=0 R 1000 1 BANK 1 CTRL READON - WRTOFF READOFF READOFF - WRTOFF READON WRTCOUNT=0 WRTCOUNT+1 WRTCOUNT=0 WRTCOUNT+1 W 1000 1 BANK 1 CTRL READON - WRTOFF READOFF READOFF - WRTOFF READON WRTCOUNT=0 WRTCOUNT=0 WRTCOONT=0 WRTCOUNT=0 4-28 Understanding the Apple II HARDWARE APPLICATION AN NMr BASED SINGLE STEPPER There is an inherent ability in tlie 6502 to inter- Figure 4.10 is the schematic of a very simple cir- rupt execution of every instruction. Tlie non- cuit which uses the hiprh priority features of the maskable interrupt is not used for anything: in most non-maskable interrupt to achieve a hardware based Apples and is available for any sortof hiffii priority HALT/STEP/TRACE capability. The operational control of the computer. An NMI' handled by firm- philosophy of this NMI STEPPER is to interrupt ware in SlotO can be made tooverrideany operating every instruction when the RUN/HALT switch is in software and gWe control of the Apple to its owner. the HALT position. The interrupt is serviced in a RUN- ASE Qr^ PHASE U Y? 03 DEVICE /Tv- SELECr ^^ 5 LS03 RESET' ©~ r PHASE LrLrLrLru^LrLrLrLTL SINGLE DEVICE' ^1_J~~ STEP RTI I*- -ftTllfJSTRUCTION- OPERATION my Frgure 4.10 Schematic; An NMI Based Single Stepper. The 6502 Microprocessor 4-29 Figure 4.1 1 The Author's Front Panel. uti lity designed for the STEPPER, then, as the con- 2. Replace cassette READ and WRITE routines of trol is passed back to the interrupted jiro^ram, cir- the F8ROM with user routines to handle NMIJ cuitry is trigp:ereNMI 1F07 8D FC 03 41 STA NVCTR+1 1F0A A9 IF 42 LDA #BEEP2 1F59: 8D F9 03 89 STA CYVCTR+1 1F5C: A9 IF 90 LDA # Lf3 -«j- c^ cv — 'tr"^ 5fc fy f«5 <; < ^ C cj T OC CE CC c3 < < < -F- esj a: tn a: t^ T— CM n -^ LTi yes &j cam 4 X?^ s^ S! ^ =^1S ),-• ^h J .1 I, ;. -I !, i^ciiOS 1 —fc— —i«;>-0 J fc g RAM in the Apple II 5-5 Another interestinpr point is that latched output falls in row E. It falls in row D when HIRES PAGE from the video scanner access is gated to the data 2 isbeingscanned.and itfalls in rowC when HIRES bus when the MPU is not writinj?. This data is not PAGE 2 is not being scanned. This means that all needed on the data bus by any motherboard device. screen memory is between $0000 and $3FFF except Its presence on the data bus means that it can be HIRES PAGE 2 which is between $4000 and $7FFF. read by peripheral cards when the MPU is not writ- Notice that CAS' is gated during PHASE 1 with no ing. Many conceivable peripheral designs could input from the video scanner. The screen modes are make use of this data. The programmable video an extension of the video scanner when it comes to scanner simulator, described in a Chapter 3 Appli- addressing RAM. Generally, the screen modes con- cation Note, is one such design (see Figure 3.13). trol the high order address bits, thus determining The propagation delay from RAS' rising to data what areas of RAM the video scanner reads. valid on the data bus is significant. Ittypically takes The RAM SELECT' term is one of the more 20 nanoseconds (30 max) for data to become valid at important signals in the Apple, being the primary the latch after RAS' rises. It typically takes 12 data bus management signal, When it is low, the nanoseconds 18 max) for data to propagate through i latched RAM data or the keyboard data is gated to the RAM/keyboard multiplexor. The total delay in the data bus. RAM SELECT' goes low when R/W is the author's Apple is 35 nanoseconds. Because of this high and the keyboard or RAM is accessed. The delay, the Apple does not meet the 100 nanosecond video scanner always accesses RAM during PHASE minimum read data setup time supposedly required 1. so latched RAM data is always on the data bus by Synertek and MOS Technology 6502s. shortly afterPHASE drops low unless R/W is low. The gating of video data to the data bus is an interesting feature, because it is not necessary for THE RAM ADDRESS MULTIPLEXOR generation of Apple video. The video data is not read The RAM address multiplexor can be function- by any motherboard device on the data bus. but it ally divided into two parts. The larger part develops can be read by peripheral cards. Additionally, the RAO through RA6, the multiplexed RAM address ability of the MPU to read the video data when the input The smallerpart develops the RAM SELECT data bus is floating is a very useful design accident. signal and CAS' for rows C, D. and E. The genera- The HIRES TIME signa! which is used in RAM tion of RA0-RA6 is a 4 to 1 multiplex operation addressing is developed in the video generator. It controlled by AX and PHASE 0. The generation of is high when the Apple is in HIRES. GRAPHICS, CAS'-C. CAS'-D, CAS'-E and RAM SELECT' ts a2 NO MIX mode or in HIRES, GRAPHICS. MIX to 1multiplex operation controlled by PHASE 0. mode when (V4 • V2) is false. The V4 • V2 gating The functions of the address multiplexor are sum- switches the scanned memory over to TEXT mem- marized in Figure 5.3. The CAS' table and MUL- ory for four lines of text at the bottom of the screen. TIPLEXED RAM ADDRESS table show which Naturally, the MIX ED mode requires switching be- address bus and video scanner outputs control CAS' tween GRAPHICS and TEXT in sync with the video and the RAM address at any moment. The various scanner. blocks show the general hardware elements of the The RAM address inputs are selected from the address multiplexor. address bus. the video scanner state, and the screen The gating of CAS' and the gating of RAM data to mode. The MULTIPLEXED RAM ADDRESS table the data bus are closely related. The high order in Figure 5.3 shows the way address bus lines and address bits contain the information that RAM is video scanner output lines are assigned to RA0-RA6 being accessed, and they also contain the informa- ROW and RA0-RA6 COLUMN. There are some tion that row C or D or E is being accessed. The CAS' significant aspects to these address assignments: table in Figure 5.3 shows that during PHASE 0, 1. Thescanner low order bits are assigned to RAM CAS' falls low at row C. row' D, or row E depending ROW address inputs so the RAM will be re- on A 15 and A14 of the address bus. In a sense. CAS' freshed by the video scanner. is part of the RAM address. Addresses $0000- 2. The address bus bit which controls a given RAM S3FFF access row C: address $4000'$7FFF access address will be equivalent to the scanner bit row D: and address 38000-.$BFFF access row E. which controls the same RAM address. For The CAS' gating partially defines screen memory example, AO controls RA2 during an MPU in the Apple. During scanner access. CAS' never ROW access, and HO controls RA2 during a 5-6 Understanding the Apple II ^ ^ LEJ rM LU I ^ UJ c ^ in O- to tD < < <: J- oe gl • ~- seULI ^ 3) • _j u5 ::: ^ to to UJ UJ ^^ CO crt 3 -- UJ xii^ I _) vy CD CO % o 3: UJ * QC w= <: (ji -« ' 1= > Csj C3 T— S .,_ o^ ^3 ^ UJ n: 31 > := X ^ro 4 E S U5 ^s DC xr UJ z X UJ «3 ° E Ln ;z CO o -r Ol to ^ => < < : *l — es « o ^E a J I < I— 2 < o UJ*= z. I " 5« ea SO to _ "J z m -* <: < < < CD LT! 1— UJ cj LU LU S ^ s s O CO =3 =) =3 ^ LJJ c/1 to to 05 t/5 1— Cvj C*J «cr >l /I f\ " rr, X 1— ^ 1 o 1- ^ LL Z U- LU Lfi X O C3 si u ? m CD ,^ •^ I =- >\ T =• CM H^l ^ ' I n u- CO ,- > ^1 ^ > >l -ST :g&^ + ^ T_ < F O 3 m rii O CO *r X CI > UJ t S? UJ ^ S3 tJL ta cc X =• T < a. a X P5 > en < X> *l RAM In the Apple II 5-7 scanner ROW access. This means that AO and Forty columns? Two strikes against you to start HO perform the equivalent RAM addressing: with. Didn't Wozniak ever hear of powers of two? function. Digital computers are based in binary numbers. 3. A12 and At3 are assiprned to RA6 aspartof the Use;i2,64, or 128 columns. This is as bad as the guys Apple scheme for operating with 4K or 1()K who designed 80-column typewritten page widths RAM chips. and 10-digit humans. 4, The other assignment features were probably The problem is that you want to address memory determined by convenience of mechanical sequentially with the output lines of the video layout. scanner. If the Apple line width had been 32 columns, you could just tie H0-H5 and V0-V4 Table 5.1 shows the equivalent address bus/video directly to the 4 to 1 address multiplexor. Memory scanner address bits. You can use this table to take would be very neatly divided up into 32 X 24 bytes. any screen mode and video scanner state and con- With 40 columns, you could still tie H0-H5 directly vert them to an equivalent MPU address. If you MPU address, to the 4 to 1 address multiplexor, and this would store a byte of data at the equivalent itwillbedrivenoutofRAMduringPHASEl when create an easy hardware connection, but there would be unused gaps in memory 24 bytes long for the video scanner reaches the chosen state. every 40 bytes used. This would waste 576 bytes of memory in TEXT/LORES modes and 4608 bytes in The Arithmetic of Video Scanner Memory HIRES mode. What good are 4608 bytes of memory Addressing divided up into 192 noncontiguous groups of 24 If the Apple isn't famous for the encrypted nature bytes? of its screen memory addressing, it should be. The In the Apple, it was accepted that there would be programmer has a very heavy burden in computing some waste of memory caused by the 40 character or looking up seemingly illogical addresses. There is lines, but the waste was minimized at the expense of logic to the Apple screen memory addressing. It is a little hardware complexity. Instead of using 40 the logic of binary manipulation. The way to under- bytes out of each 64-byte memory segment, 120 stand it is to look at the Apple from the designer's bytes out of each 128-byte memory segment are viewpoint. In 1975, how would you have gotten the used. This creates eight bytes of wasted memory for Apple to display HIRES color graphics, LORES every three horizontal scans in HIRES or every color graphics, and 40 columns of text? three lines of characters in TEXT. This results in a Table 5A MPU/Scanner Equivalent Address Bits. MPU VIDEO SCANNER AO HO Al HI A2 H2 A3 SUM-A3 A4 SUM-A4 A5 SUM-A5 A6 SUM-A6 A7 vo A8 VI A9 V2 AlO HIRES.VA TEXT/LOtES.PAGEl All HIRES. VB TEXT/LORES PAGE 2 • A12 HIRES -VC TEXT/LORES HBL • A13 H IRES. PAGE 1 — A14 HIRES . PAGE 2 — A15 1 5-8 Understanding the Apple II 12a BYTE MEMORY SEGMENTS r /N. FIRST 40 SECOND 40 THIRD 40 0-39 40-79 80-119 Figure 54 128-Byte Video Memory Segments Consist of Three 40-Byte Sections, Each Mapped Into a Different Part of ttie N^deo Screen. total wastage of 512 bytes in HIRES and 64 bytes in It can be seen that in the binary representations of TEXT/LORES. the 40-byte address sections, the lower three bits How do you implement this in hardware? Screen crossover from 111 to 000 atat! section boundaries. memory is divided into 128-byte segments. Each This means that these three bits can be identically segment is divided into the FIRST 40, theSECOND addressed in the FIRST 40. SECOND40. or THIRD 40. the THIRD 40, and eig-ht bytes of no man's 40, For example, the lowest three bits of the address memory (UNUSED 8). It so happens that the dis- of the left most character in any section is 000. For played television scan is neatly divided into three this reason HO, HI, and H2 are direct address inputs sections by V3 and V4 from the video scanner as to the 4 to 1 multiplexor and are address equivalents follows: of AO, Al,and A2. The next four address bits are different depend- V4'V3'- Top third of television screen ing on the 40-byte section that is being addressed. V4' V3 - Middle third of television screen They are 0000 through 0100 in the FIRST 40. 0101 V4 V3'- BottoTTi third of television screen through 1001 in the SECOND 40, and 1010 through V4 V3 - Undisplayed (VBL) 11 10 in theTHIRD40. These four bits are addressed by H5-H4-H.S plus an offset. The offset value is selected by V4 and V3 to place the scanned memory Because the three displayed portions of the screen address in the FIRST 40, SECOND 40, or THIRD can be so easily detected, they are mapped into the 40 of the current 128-byte segment. The offset is three 40-byte sections of each 128-byte memory added to H5-H4'H3 in a single chip4-bit adder, and segment as follows: the four bits of the resulting SUM become the scan- ning address bits equivalent to A3, A4, A5, and A6. LOCATION This book refers to the SUM bits as SUM-A3.SUM- ON TV LEAST SIGNIFICANT A4. SUM-A5, and SUM-A6. SCREEN BITS OF ADDRESS There are eight states of H5-H4-H3 but only five Top 0000000 -010011 1 (FIRST 40) of the states are displayed. 000 through 010 are Middle 0101000 ' 1001111 (SECOND 40) undisplayed and occur during the right margin, Bottom 1010000 - 1110111 (THIRD 40) horizontal retrace, and left margin of the television RAM in the Apple II 5-9 scan. 01 1 is the first displayed count, and when H5- A8. and A9 in all screen modes. A TEXT/LORES H4-H3 reaches Oil, it is time to address the first screen memory page is made up of eight adjacent byte of a 40-byte section. Suppose you built the fol- 128-byte segments. These eight adjacent segments lowing summing circuit: are defined by VO. Vl.and V2 in the scanner and by A7, AS, and A9 on the address bus. VA, VB, and VC H5 play no part In addressingTEXT/LORES memory. + V4 V3 V4 V3 Rather, the same 40-byte section of memory is SUM-A6 SUM-A5 SUM-A4 SUM-A3 scanned for eight adjacent horizontal television lines. It takes eight horizontal television lines to paintalineof textor two rows of LORES biocks. In This would create the three offsets 0. 101, and 1010 the video generator. VA, VB. and VC define which which are 40-byte offsets. This circuit would work, vertical part of a text character it is time to draw, but it would make screen memory address assijrn- and VC defines which of two LORES blocks it is ments even more complex than they are for the time to draw. Apple programmer. Since the display starts at H5- In TEXT/LORES, A15, A14, and A 13 equival- H4-H3 = Oil, we need to subtract Oil from the ents are false (low. ground, zip). A 12 equivalents are offsets 000. 101. and 1010 to make the FIRST 40 false during display and true during HBL (Horizon- start at a natural 128-byte segment boundary. The tal BLanking gate).* The All equivalent is PAGE 2 required offsets are 1101 010. and 111 (-3. 2. and 7 in and the Al() equivalent is PAGE 1. This results in . decimal). You need to address A6-A5-A4-A3 with thememoryscanned areas forTEXT/LORES shown the values H5-H4-H8 minus Oil in the FIRST 40. at the bottom of this page. The reason for scanning H.5-H4-H3 plus 010 in the SECOND 40, and H5-H4- different memory during HBL has nothing to do H3 plus 111 in the THIRD 40. These sums are clev- with video display. HBL on the RA6 ROW address erly created in the Apple by the following addition; line helps in the task of refreshing RAM. If not for 1 the refresh requirement, the TEXT/LORES equi- H5' H5 H4 m valent of A12 would be false and the memory scanned during HBL would be in the same range as V4 V3 V4 SUM-A6 SUM-A5 SUM-A4 SUM-A3 the memory scanned during HBL'. Figure 5,5 is the TEXT/LORES displayed mem- H5'-H5'-H4-H3 is equal to H5-H4-H3 minus 100 in ory map. This map shows the same information as 4-bit signed binary arithmetic. 001 minus 100 is the mapsof the Apple fI Re fere net' Manital. butthere -01 1so the needed offset is developed. It is easy to , is a difference in layout. The reference manual add 1 because of the carry input to the 4-bit adder. maps accent the 24 lines of text or 48 lines of The equivalent adding circuit is: LORES blocks, but Figure 5.5 accents the division of screen memory into 128-byte memory segments. 1 1 1 This should give the reader a second perspective H5 H4 H3 from which to view the screen mapping. V4 V3 V4 V3 SUM-A6 SUM-A5 SUM-A4 SUM-AS *HBL and VBL are sig-nals produced in the video Kenerator. [iBL Ithe horizontal blanking Rate) is hJKh rliiring tlie right TEXT/LORES Scanning and left margin of the Ajipk' video marsriii. horizontal retrace, display. VBLlverlical blankinKgaleHshifrhdurinK the bottom Beyond AO. scanning' address assignments deter- margin, vertical retrace, and top margin of the Apple video mine the memory blocks scanned in the various display. Refer to Chapter H for more information about these screen modes. VO, VI, and V2 areequivalent to A7. signals. SCREEN MODE BINARY HEXADECIMAL PAGE 1 Displayed 0000 01XX xxxx xxxx $04XX-$07XX PAGE 1 HBL 0001 01XX xxxx xxxx $14XX-$17XX PAGE 2 Displayed 0000 10XX xxxx xxxx $08XX-$0BXX PAGE 2 HBL 0001 10XX XXXX XXXX $18XX-$1BXX 5-10 Understanding the Apple TOP SCREEN/ MIDDLE SCREEN/ BOTTOM SCREEN/ BASE FIRST 40 SECOND 40 THIRD 40 UNUSED 8 ADDRESS LIN# RAtJGE LIN# RANGE LIN# RANGE RANGE $400 00 $400-$427 08 $428-$44F 16 $450-3477 $47a-$47F 1024 1024-1063 1064-1103 1104-1143 1144-1151 $480 01 $480-$4A7 09 $4A8-$4CF 17 $4D0-$4F7 $4F8-$4FF 1152 1152-1191 1192-1231 1232-1271 1272-1279 $500 02 $500-$527 10 $528-$54F 18 $550-$577 $578-$57F 1280 1280-1319 1320-1359 1360-1399 1400-1407 $580 03 $580-$5A7 11 S5A8-$5CF 19 $5D0-$5F7 $5F8-$5tF PAGE 1 1408 1408-1447 1448-1487 1488-1527 1528-1535 $600 04 $600-$627 12 $628-$64F 20 $650-$677 $678-367F 1536 1536-1575 1576-1615 1616-1655 1656-1663 $680 05 $680-$6A7 13 S6a8-$6CP 21 $6D0-$6F7 $6F8-$6Fb' 1664 1664-1703 1704-1743 1744-1783 1784-1791 $700 06 S700-$727 14 S728-S74F 22 $750-$777 $778-S77F 1792 1792-1831 1832-1871 1872-1911 1912-1919 $780 07 $780-$7A7 15 $7A8-$7CF 23 $7D0-$7F7 $7F8-$7FF 1920 1920-1959 1960-1999 2000-2039 2040-2047 $800 00 $800-$827 08 $828-$84F 16 $850-$877 S878-S87F 2048 204B-2087 2088-2127 2128-2167 2168-2175 $880 01 $880-$8A7 09 $8A8-$8CF 17 $8D0-$8F7 S8F8-S8FF 2176 2176-2215 2216-2255 2256-2295 2296-2303 $900 02 $900-$927 10 $928-$94F 18 $950-$977 $978-$97F 2304 2304-2343 2344-2383 2384-2423 2424-2431 $980 03 $980-$9A7 11 $9A8-$9CF 19 $9D0-$9F7 S9F8-$9tr PAGE 2 2432 2432-2471 2472-2511 2512-2551 2552-2559 $A00 04 $A00-$A27 12 $A28-$A4F 20 $A50-$A77 $A78-$A7F 1 2560 2560-2599 2600-2639 2640-2679 2680-2687 $A80 05 $A80-$AA7 13 $AA8-$ACF 21 $AD0-$AF7 $AF8-$AFF 2688 2688-2727 2728-2767 2768-2807 2808-2815 $B00 06 $B00-$B27 14 $B28-$B4F 22 $B50-$B77 SB78-$B7F 2816 2816-2855 2856-2895 2896-2935 2936-2943 $880 07 $B80-$BA7 15 $BA8-$BCF 23 $BD0-$BF7 $BFa-$BFi' 2944 2944-2983 2984-3023 3024-3063 3064-3071 Figure 5^ TEXT/LORES Displayed Memory Map. In addition to the displayed memory locations, there is reason to know what areas of memory are KBDSTRB EQU $C010 being scanned while nothing is being displayed. WAIT LDA KBDSTRB This knowledge has applications when software or BPL WAIT hardware syncs to the video scan by detecting the scanned memory output on the data bus. This is Some techniques of exploiting this capability are possible in software by reading an address which discussed in an Application Note at the end of this does not result in data being placed on the data bus. chapter. The point is that it is sometimes useful to For example, if you zero out all scanned memory know whatareas of memory are being scanned dur- except for the bytes in the blanking period preced- ing blanking periods. ing a given horizontal display tine, you can detect Figure 5.6 is a TEXT/LORES map showing the the beginning of that horizontal scan with the fol- areas of memory scanned during displayed and lowing loop. undisplayed periods. The layout is similar to the RAM in the Apple II 5-11 maps in the Aftptf U Reference Manual. The area of Step 20 of the above program is necessary memory scanned previous to every horizontal dis- because horizontal memory addressing wraps play period isshown directly to the left of the memory around at the 128-byte segment boundaries. scanned during that display period. The vertical 3. The first address of HBL is always addressed blanking period is shown at the bottom. The consid- twice consecutively, because H0-H5 is in the all erations which determine the memory scanned dur- zero state for two consecutive scans. ing the blanking periods are as follows: 4. During VBL (Vertical BLanking). VS and V4 1. HBL is equivalent to A12 in TEXT/LORES are both true. The horizontal offset sum becomes mode, so the memory scanned during' HBL is H5-H4-H;^ minus 0100. This is almost the same completely separate from the memory scanned as the top of the displayed screen (H4-H3-H2 during HBL'. This is not true in HIRES mode. m inus 00 11 ). The VBL base addresses are equal 2. HBL scanned memory begins $18 bytes before to the FIRST 40 base addresses minus eight display scanned memory plus $1000. The HBL bytes using 128-byte wraparound subtraction. base address can be computed from the dis- Example: $400 minus $8 gives $478; not $3F8. played base address using this Applesoft pro- 5. Horizontal scanning wraps around at the 128- gram sequence: byte segment boundaries. Example: the address 10 HBL = BASE-24 scanned before address $400 is $47F during 20 IF INT(HBL/128) OINTtBASE/128) VBL. The address scanned before $400 when THEN HBL = HBL+128 VBLisfalseis$147F. 30 HBL = HBL+I024. H0FT2OOTAL BLANKIliG tHBL) HORIZONTAL DISPLAY ENABLE LINE luiiin 1111U11U1U11122222222 NUM PAGE 1 PAGE 2 0O123456789ARCDEF01234567 pagf: 1 PftCF, 2 RI?.34567a9ABCDEF01234567P9AnCDEF01234567 S1468 5224 S1B68 ez4e f4-+ +++++ + It $4GQ 1324 3300 2048 (.+-n-(-+++++++++-»-++f+f ++++++ ++++++++++++++ S14E8 5352 SISES 6376 ++++++++4-I* S480 1152 S880 2176 + + ++++++++++++ +++4-++++++++ +++++++++++4++ S1568 5480 S1968 6504 SS00 1280 5900 2304 + +++ f + ++++•! H-+ (-+ -1-+ ++++++ ++ ++++!-+++++++++ SCREEN $15ES 5608 si9Ee 6632 ##++++++ + ++++(- S5B0 14BS $980 2432 H-++-l- + t+ + + + + + + + ++f ++ +++ + ++ + + 4.+ + +++ + + + + ++ TOP S1668 5736 SlA6a 6760 i S ++++++++++ -H- S600 1536 $A00 2560 + +++++++++ f ++ +++ -t-l- !•+++++++ ++++++++++++++ S16E8 5864 SlAEg 6SS8 ++++++++ t-S I S680 1664 SA80 2688 ++++ + + + + »- + ++ ++4-H-+-(-+ ++++ + + ++ + +++4-++++++ + S1768 5992 S1B68 7016 +++++++4.+IK III ++++++++++»+ S700 1792 5600 2816 + + + + f4-++ + ++ + + + + + + + + +++++ + + ++++++++++++++ S17E3 6120 SIBES 7J44 ++ + ++++4-».|# #t|t+4-++ + + + -l-++ + S780 192fl SBS0 2944 ++++ + 4.+ + + + + + + + -t-l-4-*-l-+++++++ ++++»++++++++ + 8 $1410 5136 S1310 6160 £423 1064 5823 2088 ++++++++++++++++++++++++++++++++++++++++ 9 514^0 5264 S1890 6268 +!+++++++## #!!++++ ++++++•-+ S4A8 1192 SSAB 221^ ++++++++++++++++++++++++++++++++++++++++ 10 S1510 5392 S1910 5416 +^.+++^+^-+||||++^+++++++^.+ 5523 1320 5923 2344 ++++++++++++++++++++++++++++++++++++++++ SCPEPN 11 S1590 SS20 S1990 6544 S5AH 1443 59A8 2472 ++++++++++++++++++++++++++++++++++++++++ MIDDLE 12 $1610 5648 $iAia 6672 +++++++++11 !#++++++++++++ S62S 1576 SA28 2600 ++++++++++++++++++++++++++++++++++++++++ 13 S1690 5776 S1A90 6890 +++++++++#)(#)| ++++++++++++ S6A8 1704 SAA8 2723 ++++++++++++++++++++++++++++++++++++++++ 14 S1710 5904 SIBICI 6928 +++++++++##!)++++++++++++ S728 1S32 5823 2356 ++++++++++++++++++++++++++++++++++++++++ 15 51790 6932 S1B90 7056 +++++++++####++++++++++++ S7A8 I960 5BA3 2984 ++++++++++++++++++++++++++++++++++++++++ 16 51438 5176 51339 6200 +++++++++111)++++++++++++ S450 1104 5850 2128 ++++++++++++++++++++++++++++++++++++++++ 17 S14BS 5304 siaaa 6328 +++++++++»###++++++++++++ $4Da 1232 S8D0 2256 ++++++++++++++++++++++++++++++++++++++++ 18 S15J5 5432 S1938 6456 +++++++ ++#))«|l ++++++++++++ 5550 1360 S9S0 2384 ++++++++++++++++++++++++++++++++++++++++ SCRE:EN 19 S15B3 5560 S19Be 6534 +++++++++*###++++++++++++ S5D0 1483 S9D0 2512 ++++++++++++++++++++++++++++++++++++++++ BOTTOM 20 S1638 5688 S1A38 6712 +++++++++## !(«+++++ + + +++++ 5650 1616 5A50 2640 ++++++++++++++++++++++++++++++++++++++++ 21 S16B8 5816 SlASa 6340 +++++++++ 1 1 S I++++++++++++ 56D0 1744 SAD0 2768 ++++++++++++++++++++++++++++++++++++++++ 22 51733 5944 SlB3a 6968 +++++++++»##)(++++++++++++ S75G 1872 SB50 2896 ++++++++++++++++++++++++++++++++++++++++ 22 S17B8 6072 S1BB8 7096 +++++++++!# !)#++++++++++++ 5700 2000 SBD0 3024 ++++++++++++++++++++++++++++++++++++++++ 24 51460 5216 S1860 6240 +++++++++#»##++++++++++++ S47S 1144 S878 2168 ++++++++++++++++++++++++++++++++++++++++ 25 S14E0 5344 S18Ea 6368 +++++++++(1)11++++++++++++ S4F8 1272 58FS 2296 ++++++++++++++++++++++++++++++++++++++++ 26 S1560 5472 $1960 6496 +++++++++##((#++++++++++++ S578 1403 5978 2424 ++++++++++++++++++++++++++++++++++++++++ VEKTICAL 27 S15Ea 5600 $19E0 6624 +++++++++##!#++++++++++++ S5r8 1528 S9F8 2552 ++++++++++++++++++++++++++++++++++++++++ BLANKING 23 51660 5728 S1A60 6752 t++++++++#»#«Mtl#l««ltlHt» S678 1656 5A78 2680 29 S16E0 5856 51AE0 6888 ++++++ t++M## ++++++++++++ sere 1734 SAF8 2808 ++++++++++++++++++++++++++++++++++++++++ 30 S1760 5984 $1B60 7003 +++++++++# #1 #++++++++++++ S77B 1912 SB78 2936 ++++++++++++++++++++++++++++++++++++++++ SnE0 G112 S1BE0 7136 +++++++++#!##++++++++++++ S7Fe 2040 SBF8 3064 ++++++++++++++++++++++++++++++++++++++++ T -31 the last row of memory is scanned 14 HORIZONTAL SYNC (REV-7 & LATER) VERTICAL SYNC consecutive times. All other rows are scanned 8 consecutive times. Rgure 5.6 TEXT/LORES Video Scanning Map. 5-12 Understanding the Apple 128 BYTES A vc-VB-VA r S2000 000 S24GO 001 S2800 01O S2C00 01 1 S3000 100 S3400 1 01 S3aoa 110 33cao 1 1 Rgure 5.7 HIRES Memory Areas (Page 1). HIRES Scannir\g VB. and VC affect the memory address in the Table 5.1 shows that HIRES video scanner ad- HIRES scan. dressing is identical to TEXT/LORES addressing Notice in Table 5.1 the oddity that VA, VB. and on bits A0-A9 and A15. The differences in bits AlO- VC address higher order bits of memory than VO, A14 reflect the facts that HIRES memory is eight VI, and V2, This causes the base addresses of adja- times as big as TEXT/LORES memory, and that cent HIRES lines to be separated by 1024 bytes HIRES memory is in a different location than rather than the logical 128 bytes. This extra compli- TEXT/LORES memory. cation of HIRES address computation could have During HIRES scanning, A13 is equivalent to been eliminated in the Apple design by the addition PAGE 1, and A14 is equivalent to PAGE 2. This of one chip. It wasn't, so the user suffers an extra results in a PAGE 1 base address of $2000 and a operational distraction. One way to look at the PAGE 2 base address of $4000. HIRES memory layout is as eight adjacent areas VA. VB, and VC are equivalent to AlO, All, and with each area the memory equivalent of a single A12 in HIRES. This is the most important point, TEXT/LORES page. VA, VB, and VC determine because it represents the great difference between vvhichoftheeightareasisbeingaddressed. Aseight HIRES and TEXT/LORES. In TEXT/LORES, 40 adjacent horizontal lines are scanned, one 64-byte bytes contain the display intelligence for eight (40 bytes displayed) section from each of the eight horizontal scans. In HIRES, 40 bytes contain the memory areas is scanned. As in TEXT/LORES, the display intelligence for one horizontal scan. The top. middle, and bottom thirds of the screen are HIRES scan must address a different 40-byte sec- accompanied by memory scanning of the FIRST 40, tion every scan, This is accomplished by letting VA. SECOND 40, and THIRD 40 sections respectively. RAM in the Apple II 5-13 One way to gain insight into the overall layout of Revision 7, and the RFI Revision. The syne genera- HIRES memory is to run the following BASIC tion depicted in Figures 5. Sand 5.9 is that of the RFI program: Revision. The scanning during blanking periods in HIRES 10 HGR POKE -16302,0 : : is very similar to that in TEXT/LORES with one REM HIRES, NO MIX major exception. HBL has no effect on memory 20 FOR A = 8192 TO 16383 addressing in HIRES, so during HBL, the memory 30 POKE A, 255 locations that are scanned are in the displayed 40 FOR B = TO 100 NEXT B: memory area. The memory locations scanned dur- REM DO IT SLOWLY ing HBL prior to a displayed line are the 24 bytes 50 NEXT A GO TO 10 : just below the displayed area, using 128-byte wrap- around addressing. This program fills the consecutive memory loca- VBL scanned memory is addressed in HIRES, tions of HIRES. PAGE 1 with '$¥¥[ slowly so you can just as in TEXT/LORES. The area scanned during watch the screen fill. When the program runs, the VBL is the same as the top third of the screen minus screen should fill as follows: eight bytes. Memory scanned by lines 256 through 1. Forty short lines are strung together at the top 261 is identical to memory scanned by lines 250 of the screen to form a long horizontal line. through 255, so those six 64-byte sections are scanned 2. The same thing happens at the first line of the twice, as shown in Figure 5.9. The memory scanning middle third of the screen. areas are summarized in Table 5.2. This same 3. The same thing happens at the first line of the information is displayed graphically in Figure5.17. bottom third of the screen. $2000-$2077 (120 bytes) has now been filled. Mixed Mode Scanning 4. The same thing happens on the ninth line from HIRES graphics mixed with TEXT is a special the top. The second line from the top will not be case when it comes to video scanner addressing. formed until the program gets to address $2400 Part of HIRES memory and part of TEXT/LORES (9216 decimal), memory must be scanned in this mode. The problem 5. The pattern of lines continues to be drawn until does not arise with LORES graphics mixed with there are 24 evenly spaced lines on the screen. TEXT, because TEXT memory scanning is identi- At this point the screen is one eighth fulK a cal to LORES memory scanning. 128-bytesegment from each of the eight memory The HIRES TIME term that is used to scan areas has been filled, and the program has memory addresses is not a direct input from the reached $2400. $C056/$C057 LORES/HIRES soft switch. Rather, 6. The program continues to add patterns of 24 it is a term developed in the video generator which is lines in a similar fashion until the screen is active when it is actually time to scan HIRES screen filled. memory. In HIRES MIXED mode, the HIRES Figure 5.8 is a HIRES displayed memory map TIME term switches low on the third RAS' (rising) accenting the division of screen memory into 128- after V4 • V2 becomes true (see Figures 8.6 and byte memory segments. This figure was printed out 8.13). HIRES TIME switches high on the third using an Applesoft program listed in Appendix D. RAS' (rising) after V4 • V2 becomes false. V4 • V2 Like the TEXT/LORES map of Figure 5.5, this identifies the last four lines of the TEXT display, figure gives a different perspective for viewing and the three RAS' delay prevents switching from HIRES memory usage. Figure 5.9 is the full HIRES HIRES to TEXT mode in the video generator before memory map showing addresses scanned during the last seven dots in line 159 of HIRES have been HBL and VBL as well as the displayed map. It was output to the television. also made by an Applesoft program listed in Ap- V4 • V2 actually identifies scan lines 160 through pendix D. For reference, "#" is used in Figure 5.9 to 191 and 224 through 261. The scanned memory show when horizontal or vertical television sync is sv^'itches to HIRES during the first part of VBL, output by the video generator. The #s in the middle back to TEXT for the second part of VBL, then back of every HBL period represent the horizontal sync to HIRES for the top of the screen. The switching which causes the horizontal retrace. The long strings during VBL is, of course, not visible on the screen. of #s in lines 224-227 represent the vertical sync This information is only important to those special which causes the vertical retrace. Please note that applications where it is important to know what is video sync in the Apple was changed in Revision 1. scanned during the blanking periods. 5-14 Understanding the Apple TOP SCREEN/ MIDDLE SCREEN/ BOTTOM SCREEN/ FIRST 40 SETOND 40 THIRD 40 UNUSED 8 PftGE 1 PAGE 2 LIN# PAGE 1 RANGE LIN# PAGE 1 RANGE LIN# PAGE 1 RANGE PAGE 1 RANGE $2000 8192 $4000 16384 600 $2000-52027 064 52028-S204F 128 S2050-S2077 S2078-$207F $2400 9216 $4400 17403 001 52400-52427 065 52428-$244F 129 $2450-$2477 S2473-S247F $2800 10240 54800 18432 002 $2800-52827 066 5282S-5284F 130 $2S5«-$2S77 $287a-$287F $2C00 11264 S4C00 194 55 003 S2C0O-$2C27 067 52C28-S2C4F 131 $2C50-$2C77 $2C78-52C?F $3000 12288 $5000 20480 004 $3000-53027 068 $3028-S304F 132 $3050-53077 S3073-5307F 53400 13312 $5400 21504 005 53400-53427 069 S3428-$344F 133 $3450-53477 $3473-S347F $3800 14336 $5800 22528 006 53800-53827 070 53828-$384F 134 53850-53877 $3878-S337F $3C00 15360 $5C00 23552 007 53C00-53C27 071 53C2e-S3C4F 135 $3C50-53C77 S3C73-$3C7F $2080 8320 54080 16S12 008 $2080-$20A7 072 $20A8-$20CF 136 $20D0-S20F7 S20F8-$20FF $2480 9344 54480 17536 009 $2430-$24A7 073 S24A8-$24CF 137 $2400-524 F7 S24F8-S24FF 52880 10368 54880 18560 010 $2880-528A7 074 528A8-S28CF 138 528D0-$28F7 $28F8-$28FF $2C80 11392 54C80 19584 011 52C80-52CA7 075 S2CA8-S2CCF 139 52CD0-52CF7 S2CF8-S2CFF $3080 12416 $5080 20603 012 53080-530A7 076 530A8-S30CF 140 $30D0-$36F7 S30F8-S30FF $3480 13440 §5480 21632 013 S34B0-$34A7 077 S34A8-S34CF 141 $34D0-$34F7 S34F3-S34FF $3880 14464 55880 22556 014 $3830-$38A7 078 $38A8-$38CF 142 $38D0-$38F7 $38Fa-$38FF $3C80 15488 $5C80 23630 015 53C80-S3CA7 079 S3CA8-$3CCF 143 $3CD0-53CF7 S3CF8-S3CFF 52100 8448 54100 16640 016 52100-52127 080 52128-5214F 144 52150-52177 52178-$217F $2500 9472 $45(J0 17664 017 $2500-52527 081 S2528-$254F 145 $2550-52577 S2578-S257F $2900 10496 $4900 18688 018 52900-52927 082 $2928-$294F 146 S2950-S2977 $2978-S297F $2D00 11520 54000 19712 019 $2D00-S2D27 083 $2D28-52D4F 147 52050 -S2D77 52D78-$2D7F $3100 12544 55100 20736 020 $3100-53127 084 $3128-$314F 148 53150-53177 $317a-$317F $3500 13568 $5500 21760 021 $3500-53527 0e5 $3528-$354F 149 53550-53577 S3578-S357F 53900 14592 $5900 22784 022 53900-S3927 086 $3928-5394F 150 53950-53977 53978-$397F 53D00 15616 $5000 23808 023 S3D00-S3D27 037 $3D28-$3D4F 151 S3D50-$3D77 $3D78-$3D7F 52180 8576 S4180 16768 024 52180-S21A7 088 $21A8-$21CF 152 $21D0-$21F7 $21F8-$21FF 52580 9600 $4590 17792 025 $2580-S25A7 089 525A8-S25CF 153 $25D0-S25F7 525F8-525FF 52980 10624 S4980 18816 026 S2980-S29A7 090 529A8-$29CF 154 52900 -$29F7 529F8-529FF 52D80 11648 S4D80 19840 027 $2Da0-52DA7 091 52DA8-52DCF 155 $2OD0-52DF7 52DF3-S2DFF 53180 12672 55180 20864 028 $3180-S31A7 092 531A8-531C:F 156 531D0-S31F7 S31F8-$31FF 53530 13696 $5580 21888 029 S3580-$35A7 093 S35A8-$35CF 157 535D0-535F7 $35F3-S35FF 53980 14720 $5980 22912 030 5 3980-5 39A7 094 539A8-S39CF 158 S39D0-S39F7 S39F8-S39FF S3D80 15744 $5D80 239 36 031 S3D80-$3DA7 095 $3DR8-S3DCF 159 $3[XI0-53DF7 S3DF8-S3DFF 52200 8704 $4200 16896 032 52200-52227 096 52228-S224F 160 S2250-S2277 S2278-5227F 52500 9728 S4600 17920 033 52600-52627 097 $2628-$264F 161 52650-52677 $2678-S267F 52A00 10752 $4a00 13944 034 $2A00-S2A27 098 52A28-S2A4F 162 $2A50-S2A77 $2A78-S2A7F 52E00 11776 $4f:00 19963 035 52E00~S2E27 099 S2E28-52E4F 163 52E50-52E77 52E78-S2E7F S3200 12800 $5200 20992 036 S3200-$3227 100 $322B-S324F 164 53250-53277 S3273-S327F 53500 13824 $5600 22016 637 53600-53627 101 S3628-S364F 165 53650-53677 S3678-S367F 53A00 14848 $5A00 23040 033 S3A00-$3A27 102 53A28-$3A4F 166 $3A50-53A77 S3A73-$3A7F S3E00 15872 S5E00 24064 039 $3E00-53E27 103 53E28-S3E4F 167 S3E50-$3E77 S3E78-S3E7F 52280 8832 S42B0 17024 040 52280-522A7 104 S22A8-$22CF 158 $22D0-$22F7 522F3-S22FF 52680 9856 S4680 18043 041 $2630-526A7 105 S26A8-$26CF 169 $26O0-S26F7 $26F8-S26FF 52A80 10880 S4A80 19072 042 52A80-$2AA7 106 $2AA8-52ACF 170 52AD0-52AF7 S2AF8-S2AFF $2E80 11904 S4ES0 20096 043 S2E:80-$2EA7 107 $2F^8-52BCF 171 52EO0-$2EF7 S2EF3-S2EFF 53280 12928 $5280 21120 044 53280-$32A7 103 $32A8-$32CF 172 $32O0-532F7 S32F8-S32FF 53580 13952 S5680 22144 045 S3680-$36A7 109 S36A8-536CF 173 536D0-$36F7 S36F8-S36FF S3A80 14976 ?5Re0 23168 046 $3A80-$3AA7 110 53AA8-S3ACF 174 $3AD6-$3AF7 $3AF8-S3AFF S3E80 16000 $5E80 24192 047 $3E80-$3FA7 111 S3F:A8-S30CF 175 53ED0-S3EF7 $3EFS-$3EFF S2300 8960 S4300 17152 043 $2300-$2327 112 52328-5234F 176 52350-52377 $2378-$237F S2700 9984 $4700 18175 049 $2700-52727 113 S2728-$274F 177 $2750-52777 $277&-S277F S2B00 11008 S4B00 19200 050 52B00-$2B27 114 $2B28-S2B4F 178 52B50-52B77 $2b78-$2B7F S2F00 12032 S4F00 20224 051 $2F00-S2F27 115 $2F28-52F4F 179 S2F50-S2F77 $2F78-S2F7F $3300 13056 55300 21248 052 53300-53327 116 S3328-S334F 130 53350-S3377 5337a-$337F S3700 14080 $5700 22272 053 $3700-53727 117 53728-5374F 181 53750-53777 $3778-5377F $3B00 15104 $5B00 23296 054 $3B00-53B27 118 S3B28-S3B4F 182 53B50-$3B77 , $3B78-S3B7F $3F00 16128 $5F00 24320 055 $3F00-S3F27 119 53F28-53F4F 133 $3F50-53F77 $3F78-$3F7F 52380 9088 $4380 17280 056 $2380-$23A7 120 $23A8-$23CF 134 523D0-$23F7 $23F8-S23FF 52780 10112 54780 18304 057 $2780-$27A7 121 $27A8-$27CF 185 527D0-S27F7 $27F&-527FF 52B80 11136 $4BS0 19328 058 S2B80-$2BA7 122 $2BA8-52BCF 186 52BD0-$2BF7 $2BF8-$2BFF 52F80 12160 $4FS0 20352 059 S2F80-52FA7 123 S2FA8-S2PCF 187 $2FD0-S2FF7 $2FF8-S2FFF 53380 13184 $5380 21376 060 $3380-$33A7 124 533A8-$33CF 188 S33D0-S33F7 $33F8-$33FF 53780 14208 55780 22400 061 S3730-S37A7 125 S37A8-537CF 189 S37D0-537F7 $37F8-S37FF S3B80 15232 $5B80 23424 062 S3B80-53BA7 126 53BA8-53BCF 190 53BO0-53BF7 S3BF8-$3BFF S3F80 16256 $5F80 24448 063 $3F30-S3FA7 127 $3FA8-$3FL-F 191 $3FD0-53FF7 $3FF8-$3ltT Figure 5.6 HIRES Displayed Memory Map. RAM in the Apple II 5-15 SCREEN TOP HORIZONTAL BLftNKiNG (HBL) HORIZONTAL DISPLAY EKMLE LIN£ Illlllll lUllllllinini22222222 HOM PAG E 1 PAGE 2 00123456789ABCDEF01234567 PACT. 1 PAGE 2 B123456789ftBCDEF0123456789ABCDEF01234567 52068 829 E 54063 16488 ++4-+++++-i-t J !#<+++++++++'-+ 52000 8192 S4000 16384 ++++++++++++++++++++++++++++++++++++++++ I $2466 9320 54463 17512 +t+++++++H ##++++++++++++ 52400 9216 S4400 17408 ++++++++++++++++++++++++++++++++++++++++ 2 S2SeB 10344 54868 18536 52800 10240 54800 1B432 ++++++++++++++++++++++++++++++++++++++++ 3 S2C6S 11368 S4C63 19560 +++++++++111 !#++++++++++++ S2C00 11264 S4C00 19456 ++++++++++++++++++++++++++++++++++++++++ 4 53068 12392 $5068 20584 +++++++++1111+++.+++++++++ 53000 12283 55000 20480 ++++++++++++++++++++++++++++++++++++++++ 5 S3468 13416 55468 21608 +++++++++Mii++ <+++++++++ 53400 13312 55400 21504 ++++++++++++++++++++++++++++++++++++++++ 6 53868 14440 55868 22r32 +++++++++IIH++++++++++++ S3S00 1433S 55800 22528 ++++++++++++++++++++++++++++++++++++++++ 7 S3C68 15464 55C6S Z3656 +++++++++)!!#++++++++++++ S3C00 15360 S5C00 23552 ++++++++++++++++++++++++++++++++++++++++ 3 $20EB 8424 540E8 16616 +++++4-n-+|#f f++++++4+t+++ 52080 3320 54080 16512 ++++++++++++++++++++++++++++++++++++++++ 9 524E8 9448 S44Ea 17640 +++++++++14*1?++++++++++++ 52480 9344 54480 17536 ++++++++++++++++++++++++++++++++++++++++ 10 S28E8 10472 543E3 18664 +++++++++IH #++++++++++++ 52880 10368 54880 18560 ++++++++++++++++++++++++++++++++++++++++ 11 52CE8 11496 S4CE8 19688 +++++++++ltt(H+++ +++++++++ 52C80 11392 54C80 19584 ++++++++++++++++++++++++++++++++++++++++ 12 S30E8 12520 5S0E8 20712 +++++++++ltti++++++++++++ 53080 12416 S50B0 20608 ++++++++++++++++++++++++++++++++++++++++ 13 S34E8 13544 554E8 21736 +++++++++(!##++++++++++++ 53480 13440 55480 21633 ++++++++++++++++++++++++++++++++++++++++ 14 53aE8 14568 $58Ea 22760 +++++++++I t*l ++++++++++++ $3880 14464 55880 22656 ++++++++++++++++++++++++++++++++++++++++ 15 S3CE8 155*2 SSCEa 23784 +++++++ + 1 ###++++++++++++ S3C30 154S8 S5CS0 23680 ++++++++++++++++++++++++++++++++++++++++ 4- 16 S216B 8552 54168 16744 +++++++++###*++++++++++++ S2100 9448 54100 16640 ++++++++++++++++++++++++++++++++++++++++ 17 S2568 9576 S456S 17768 +++++++++»##*++++++++++++ 52500 9472 54500 17664 ++++++++++++++++++++++++++++++++++++++++ IB 52968 10600 S4968 18792 +++++++++!# I++++++++++++ S2900 10496 54900 IS688 ++++++++++++++++++++++++++++++++++++++++ 19 52D63 11624 S4D68 19816 +++++++++tt#(l++++++++++++ 52D00 11520 5 4000 19712 ++++++++++++++++++++++++++++++++++++++++ 20 S3168 12648 55168 20840 +++++++++I I I I++++++++++++ 53100 12544 55100 20736 ++++++++++++++++++++++++++++++++++++++++ 21 53568 13672 S5568 21864 +++++++++#*##++++++++++++ 53500 13568 55500 21760 ++++++++++++++++++++++++++++++++++++++++ 22 S396S 14696 SS968 22B88 +++++++++lti»++++++++++++ 53900 14592 55900 22784 ++++++++++++++++++++++++++++++++++++++++ 23 S3D68 15720 S5D63 23912 +++++++++##11++++++++++++ $3000 15616 S5DO0 23808 ++++++++++++++++++++++++++++++++++++++++ 24 $21E8 86SQ S41EB 16B72 +++++++++!###++++++++++++ 52180 8576 54160 16768 ++++++++++++++++++++++++++++++++++++++++ 25 525E8 9704 S45E3 17396 +++++++++##11++++++++++++ S2580 9600 £4580 17792 ++++++++++++++++++++++++++++++++++++++++ 26 S29E8 10728 S49E8 18920 +++++++++#||i+t++++++++++ S2990 10624 $4980 1S816 ++++++++++++++++++++++++++++++++++++++++ 27 S2DE8 11752 S4DE8 19944 +++++++++((111+++++++++++ + S2D80 11648 S4D80 19840 ++++++++++++++++++++++++++++++++++++++++ 23 $31E8 12776 S51E8 20963 ++++f++++|||#++++++++++++ 53180 12672 55180 20864 ++++++++++++++++++++++++++++++++++++++++ 29 S3SE8 13800 S55E8 21992 +++++++++##11++++++++++++ $3580 13696 55530 21888 ++++++++++++++++++++++++++++++++++++++++ 30 S39E8 14824 S59E8 23016 +++++++++!###++++++++++++ 53980 14720 55980 22912 ++++++++++++++++++++++++++++++++++++++++ 31 $3DE8 1S848 55DE8 24040 +++++++++||(t#++++++++++++ S3DS0 15744 55D80 23936 ++++++++++++++++++++++++++++++++++++++++ 32 $2263 8808 54268 17008 +++++++++#)#|++++++++++++ 52200 8704 54200 16396 ++++++++++++++++++++++++++++++++++++++++ 33 52668 9832 54668 18024 +++++++++## !#++++++++++++ 52600 9728 54600 17920 ++++++++++++++++++++++++++++++++++++++++ 34 S2A68 10856 S4A68 19048 +++++++++|##t++++++++++++ $2AQ0 10752 S4A00 13944 ++++++++++++++++++++++++++++++++++++++++ 35 S2E68 11880 S4E68 20072 +++++++++#»##++++++++++++ S2F,00 11776 54E;00 19968 ++++++++++++++++++++++++++++++++++++++++ 36 $3268 12904 55268 21096 +++++++++##11++++++++++++ 53200 12800 55200 20992 ++++++++++++++++++++++++++++++++++++++++ 37 53668 13928 S5668 22120 +++++++++!###++++++++++++ 53600 13S24 S56efl 22016 ++++++++++++++++++++++++++++++++++++++++ 38 53A68 14952 $5AGB 23144 +++++++++##11++++++++++++ $3A00 14848 55A00 23040 ++++++++++++++++++++++++++++++++++++++++ 39 S3E68 15976 S5E6B 24168 +++++++++(#!#++++++++++++ 53E00 15872 55E00 24064 ++++++++++++++++++++++++++++++++++++++++ 40 522E3 8936 S42E8 17128 +++++++++1111++++++++++++ 52280 8832 54280 17024 ++++++++++++++++++++++++++++++++++++++++ 41 S26R3 9960 S46E8 18152 +++++++++tlH++++++++++++ 52680 9856 54680 18043 ++++++++++++++++++++++++++++++++++++++++ 42 S2AE8 10984 54AE8 19176 +++++++++H|#++++++++++++ 52A80 10830 54A80 19072 ++++++++++++++++++++++++++++++++++++++++ $ZEE:S 12003 S4EE8 202^0 +++++++++i#i(++++++++++++ $2E80 11904 54E80 20096 ++++++++++++++++++++++++++++++++++++++++ 43 44 S32E& 13032 S52E8 21224 +++++++++ii#i++++++++++++ 53280 12928 S52S0 21120 ++++++++++++++++++++++++++++++++++++++++ S36E:& 14056 S56E8 22248 +++++++++ii#i++++++++++++ 53680 13952 55680 22144 ++++++++++++++++++++++++++++++++++++++++ 45 46 S3AE8 15080 S5AEB 23272 + ++++++++I !#!++++++++++++ $3AS0 14976 S5A80 23168 ++++++++++++++++++++++++++++++++++++++++ 47 S3EE8 16104 S5EEe 24296 +++++++++ll»t+++++++t++++ S3F.60 16000 $5E30 24192 ++++++++++++++++++++++++++++++++++++++++ 48 52368 9064 54 368 17256 +++++++++(###++++++++++++ 52300 3960 54300 17152 ++++++++++++++++++++++++++++++++++++++++ 49 52768 10088 S476B 18280 +++++++++|#li++++++++++++ S2700 9984 $4700 18176 ++++++++++++++++++++++++++++++++++++++++ 50 52668 11112 54B63 19304 +++++++++HI#++++++++++++ $2B00 11003 $4B00 19200 ++++++++++++++++++++++++++++++++++++++++ 51 S2P68 12136 S4F6B 20328 +++++++++#||#++++++++++++ 52F00 12032 S4F00 20224 ++++++++++++++++++++++++++++++++++++++++ 52 53368 13160 55368 21352 +++++++++IIH++++++++++++ S3300 130S6 55300 2124B ++++++++++++++++++++++++++++++++++++++++ 53 53768 141B4 $5763 22376 +++++++++#li#++++++++++++ 53700 140B0 55700 22272 ++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++ 54 S3B68 15208 55B6B 23400 +++++++++IIII++++++++++++ S3B00 15104 55800 23296 55 S3F6a 16232 S5F68 24424 +++++++++##11++++++++++++ S3F00 16128 55F00 24320 ++++++++++++++++++++++++++++++++++++++++ 56 523E8 9192 S43E8 17384 +++++++++iHi++++++++++++ 52380 9088 54380 172S0 ++++++++++++++++++++++++++++++++++++++++ 57 $27Ea 10216 $47Efi 18408 +++++++++IHt++++++++++++ 52780 10112 54780 18304 ++++++++++++++++++++++++++++++++++++++++ 53 S2BE8 11240 54 BEE 19432 +++++++++II !#++++++++++++ 52B80 11136 $4BS0 19328 ++++++++++++++++++++++++++++++++++++++++ 59 $2FE8 12264 S4FE8 20456 +++++++++####++++++++++++ S2F8fl 12160 S4Fe0 20352 ++++++++++++++++++++++++++++++++++++++++ 60 S33E8 1328B 553ES 21480 +++++++++I III+++++++++++-+ 53330 13184 $5380 21376 ++++++++++++++++++++++++++++++++++++++++ 61 537E8 14312 557E8 22504 +++++++++#ll#++++++++++++ 537B0 14203 $5730 22400 ++++++++++++++++++++++++++++++++++++++++ 62 S3BE8 15336 55BE8 23528 +++++++++1111 +++++ +++++++ 53830 15232 S5B80 23424 ++++++++++++++++++++++++++++++++++++++++ 63 53FE8 16360 S5FE8 24552 +++++++++!( !#++++++++++++ S3FB0 16256 S5FS0 24448 ++++++++++++++++++++++++++++++++++++++++ Hgure 5.9 HIRES Video Scanning Map. (1 of 4} 5-16 Understanding the Apple i SCRKEN MICOLR HORIZONTM, BLANKING (flBL) HORIZONTAL DISPLAY ENABLE LINE lUlllll 111111111111111122222222 HUM PAGE 1 PWR 2 001234567a9ABCDEF01234567 1 PftBB 1 PAGE 2 01234 567S9MCDEF01234S67S9AnCDFF01234567 64 S2010 82a& S4010 16400 52028 823? 54028 16424 444+444++++++ t+++44+++4++44++ 44+44+4 44+4 65 S2410 9232 S4410 17424 +++++++++# ###++++++++++++ S2428 9256 S44ZB 17448 4+44+44+4+ 4++4+++44++4444 44 +++44+44+4 4+4 66 52810 10256 S4810 18448 52828 10280 54828 18472 +44++4+++4++44++++4++44+++++++++++++++++ 67 52C1C 11280 S4C10 19472 ++++++++f)tt*lt+t++t+++++++ 52028 11304 54C28 19496 +4+++444+++++44++ 44+ 44 44++ ++++++++++++++ 68 S30ie 12304 S5010 20496 +++++4 + ++(##t|+++++++4++++ 53028 12323 55028 20520 +444+ 444+4 +4+4 44+4+++444++++++++++++44++ 69 S34ie 13328 55410 21520 +++!-+++ + +)( (IK +4 ++++++++++ 53428 13352 55428 21544 ++++4+4++++++++4++ 44+44 44++++444+++++44+ 70 S3B10 143S2 S5810 22S44 4+4 ( + 4444|t|i4+++++ 4444++ S3828 14376 S5S28 22568 +++++++4++++++44+444+++++++++++4++++++++ 71 S3C10 15376 55C10 23568 44+4 + + 444(1(1 lt++44+44++4++ S3C2B 15400 S5C28 23592 ++++4+44++++++44++44+++44+4 4+4444444444+ 72 52090 8336 S4090 16528 ++4 4+ + 44+t|###+4+++4+++4++ $20AB 8360 540A8 16552 +++++++++++++444+++++++4++++++++++++++++ 73 S2490 9360 S4490 17552 44+t4++4+(H|f S+++++++++44+ 524A8 9384 544AB 17576 4+4+++4+++++4++4+++44+444+44++44++ ++++++ 74 52890 10384 S4890 18576 4+44 +444+1 tjjd 44+4444+444+ S28A8 10403 $48A8 18600 ++44+++++++++++++++ ++++++++ ++++++++++44+ 75 52C90 11408 S4C90 19600 +++44++++|t(||(+++++++++4++ S2CA8 11432 54CA8 19624 4+++++++++++++++++++ +++44+++++++ 4+44+444 76 53B90 12432 SS090 20624 4+44++44+##)t|++44++++444+ S30A8 12456 S50A8 20648 1-+.+t444 4+t+++444++ + + ++ + 4+444++44+++++44+ 77 53490 13456 55490 21648 +4+44+4 44 (t###++4+++++444+ S34A8 13480 554AB 21672 4+++++++++++++++++++ ++++++++++++4+44+4 4+ 78 53390 14430 S5S90 22672 4+44+ + 44+|#iJ(++4+++4+4444 S38AB 14504 $58AS 22696 +++++++++++++++++444+++ 44+44+++ +4+44++++ 79 53C90 1556(4 S5C90 23696 44 + 44+ 4 4 + It) ##+++4+4++++++ 53CA8 15S28 S5CA8 23720 4++++++++++++++ 4 4++4 +444 4+44+++ 44+++++44 80 52110 8464 S4110 15656 +++++++ ++(#)ti +++++++++++4 S212S 3488 54128 16680 4+44++44++444++4 4++++++++++4++++++++++44 81 52510 9488 S4510 17680 +++4.++4|. + t|l|#D+4t ++4+4+4++ S2528 9512 S4528 177C4 4++44+++++++t++44+44++++++++ +++++++44+44 S2 52910 10512 54910 13704 4+ 44 4+4 ++!### 4+ +++++++444 S2923 10536 $4928 18728 ++444+444+ +++++44+444+++4++4++++++++++44 81 S2D10 11536 S4D10 19728 44+44+44+|t(|((t++4++44++44+ S2D28 U560 54028 19752 44+44+444+ 4+4++444+44+++4444 4+4+4+44+444 84 53110 12560 SS110 20752 + ++ + ++ + + +l(tf((+++++44+++++ 53128 12584 S5128 20776 ++444+4++++++++++++t++++4+4+++++++4+++44 85 53510 13584 55510 21776 +++ + 4+ + ++|tH !(+++++++*+++ 53523 13608 S552B 21800 44+44++++++++4++4+++4+++4+444+++++++++++ 36 53910 14608 55910 22S00 4 4+44+ + ++Hltt+++++++++444 53928 14632 S592S 22824 ++++++++++++4+444+ +44+++4++44+++4+++++++ S7 S3D10 15632 $5[>lf 23324 +++ + +++ + +|)t t+++4+++++++4 53D28 15656 £5n28 23S48 44+444+++4+++4++4+++4++++++44+++4+++++++ (I 88 $2190 8592 S4190 16784 + 4+4 + + + + + tut ( + 444 + + + +++ + + S21Aa 3616 $41A8 16808 ++++4+4 44++++ 4+++++ +++++++++++++ ++++++++ (( 89 52590 9616 54590 17808 +++++++++ KttD *+++ + + •4+++++ S25AB 9640 545A8 17832 44+444++4+++++4444+444+++++44+++++++++++ 90 S2990 10640 34990 18832 4++ + 4++ + +tt|##++4+++++++44 529A8 10664 S49A8 18856 ++++++++ 4+++++ +++++++++++++++++ +4+++++++ 91 52D90 11664 S4D90 19856 ++ + + 4 + + 4 + (tH* + + +4+ + 44 +++ + S2r)AB 11688 S4nAe 19880 +4+444++44+++4+44+++4++++++44++++t4+4+44 92 53190 12688 55190 20380 ++ + + 4++ + 4i(tCll + + +++ + + + + 4+ + S3 IAS 12712 S51AB 20904 44+ 44 ++++++++++++++++ +++++++++++++++++++ 93 S3590 13712 S5590 21904 44 + 4 4 ++ + +(( (##+ + 4 4+444+444 S35A3 13736 S55A8 21928 4 4 + 44 ++ + +++ + + + + +++ + + + + + + 4 + + 4 + + 4 444 + 44 + 4 ! 94 53990 14736 55990 22926 44 + 44 + + + + (tttt(l++ + + + 4 + 4 +44 + S39A3 14760 S59A8 22952 44+++4+++4+++4 +44 +++++++++++++ +44 +++++4+ 95 S3D90 15760 S5D90 23952 + 4+ + 4 + 4 4 4jt((|#++4++ + 4+++44 530A8 15784 55m8 23976 4 4+44 +4444+44+444++ +++++4+++++++++++++4+ 96 52210 8720 54210 16912 + 4++44++ + #|ti|++ + 4+ + + 4++4 + 52228 3744 S4223 16936 +4+++++++4+++4++++ +4 4 4 ++++++ +++++++++++ 97 S261S 9744 54610 17936 +++++++++ #i++++++++++++ 52628 9768 54628 17960 4 4+++ +++4 44444444+44 4 + + +++++++4444444+44 It It 96 S2A10 10758 54A10 18960 ++++ + 4++4|t|t I »++ + + + + + + + + + + 52A28 10792 S4A2a 18984 4 + 4+++++ + ++++4+ + 4t + + 4++ + 4l- + 444 + 4444444t4 99 S2E10 11792 54E10 19984 44+444 + 44 to # + + 44 ++ + + 4+44 52E28 11816 S4E28 20008 t4+444++++++44++44+44l- + 44 + + 4t+++44+++++4 (t 100 S3210 12816 55210 21008 +44 + + + 4 + + #11 #+++++ +++ + +++ 53228 12840 S522B 21032 444+4+++++++++++4++44 4+++++++++++++tt4++ 101 S3610 13840 55610 22B32 44+ + 4+++4Slt##4+ + ++++ + ++44 53628 13B64 55628 22056 +4+444+444+444+444+ +44+++ ++++++++4+++++ 102 S3A10 14864 S5ftl0 23056 + 44+44++ + {li(t#+++4++4 + + + 44 S3A28 14888 S5A23 230S0 +++++++++++++++++++++++++++++++++4+44+4+ 103 S3E10 15888 S5E10 24080 44+++++++|##|++++++++++44 53E28 15912 S5E23 24104 +4++44++44++4++444+444+444+4 4++4 44++++++ 104 52290 8848 54290 17040 +44++44+4##^f+++4+++++++4 $22Aa 3372 542AS 17064 + +4 ++++++44+44++++++ +4 +++++++44++++ +44+4 105 S2690 987Z $4693 18064 444+44+4+i|J#4+++++++4444 5 26 A3 9396 S46A3 18088 444+44+444+444+++++4+44444+++++++4++++++ 106 $ZA90 1089S $4A90 190SS +++ ++4 +++ t ###++++++++ ++++ S2AA8 10920 54AA3 19112 444+4 44+++44+4++4444+4 4444+444+++4444444 107 S2C90 11920 54E90 20112 444+44+44####++++4+++++++ 52EA8 11944 S4EA8 20136 44++44++4++++4++44++4 4+444+44 ++4444+4+44 10S 53290 12944 55290 21136 ++++++ +++###!++++++++++++ $32AB 12968 S52A3 21160 44++++++++++++ +++++++++++++++ +++++++++++ 109 S3690 13968 S5698 22160 + + + + 44++4#t # + + + + ++ ++++++ 5 36 AS 13992 556 A8 22184 444+ 44++ 4+++44 ++++++++++++++++++ +4 ++++++ it 110 E3A90 14992 S5A93 23184 ++ + + ++4.+ + |||# + ++ + 4.++ + + +++ 53AA8 15016 55AA8 2320S + 44+44+++4 + 4 + 44+ + 4 + + + + 4++1-4 + 4 + + + + + + ++++ + 111 53E90 16016 55E90 24203 +++++++++####+++++++++++4 $3EAS 16040 S5EA8 24232 + 4 4+44++4+++ + 4444 4+4444 + + •"+444+444+444 + 4 112 S2310 8976 54313 1716S ++4++4+++####4+++++++4++4 52328 9000 54328 17192 444+444+444+4 44+44+44 4++ +4+444*4 +4444 4+4 113 52710 10000 $4719 IB192 +44+444++#tJ#4+++++++4+++ 52728 10024 54728 18216 44++44+++++++44+4++++++++ +++++++++++++++ 114 S2B10 11024 S4B10 19216 +++++++++!# I #++++++++44++ S2B2S 11043 S4B28 19240 +44+444+444+444+44 4+444+ ++++ ++4+++++++++ 115 S2F10 12048 S4F10 20240 +++++++++#!##+++ +4++++++4 S2F28 12072 54F28 20264 444+44 4+4444444++ !+ + 4 4 444 4++ + +++44+44444 116 53310 13072 55310 21264 4++4++4++I S|#+++++++++++4 53328 13096 S5328 21288 +44+++++++++++++44+++++++t++++++++++44+4 117 53710 14096 55710 22288 ++4++44++|i# I ++++++++++++ 53728 14120 55728 22312 444++4++++++++++4+++++ +++++++ 4+4 44+4++++ 118 53B10 15120 S5B10 23312 ++++++++ +)!### ++++++++++++ S3R2S 15144 S5B28 23336 ++4++44++44+++4+++4+44+++++++ 4 ++++++++++ 119 53F10 16144 S5Fia 24336 +++++++++####+++++++++444 S3F2:8 16168 5SF28 24360 +44+444+444+444444+444+444+++ +++4 4 ++++++ 120 52390 9104 54390 17296 +++4++44+t| 1 1 H +++++++++++4 S23A8 9128 543A8 17320 444+444+444+44+44444444+ ++++++++++++++++ 121 52790 10128 54790 1S320 +++++++++####++++++++++++ 527A8 13152 547Ae 18344 +44+4444444444+++++++ ++++4++++++++++++++ 122 S2B90 11152 $4B9a 19344 + ++ + ++ + + + tt##t44+ + + ++++++4 52BA8 11176 S4BA8 19368 444++++++++4++4+++++++ +++++++ +++++4+4+++ 123 52F90 12176 S4F9a 20368 ++4+ + + + ++jf ###+++++++++44+ 5 2 FAB 12200 S4FA8 20392 ++4+4+4++++++++++++++4+++4++4++++++4++44 124 53390 13200 55390 21392 4+444++ ++##»#++++++++++++ $33A8 13224 553A8 21416 +44+444++4+++4++444+44+44 4+ ++++++ 4444+44 125 53790 14224 55790 22416 +++++++++####++++++++++++ 537A8 14249 557A8 22440 44++++++++++++++4++++ +++++++++++ ++++++++ 126 S3B90 15248 S5B90 23440 +44+++++4I i # S++++++44+44 + S3BAa 15272 S5BA8 23464 ++++++++++++++++++++++++++++++++++++++++ 127 $3F9e 16272 55F90 24464 +++444+44* ###+++++++++444 $3FAB 16296 55FA8 24488 +++4++44++++++++ 4+444444444+44 4+44+4+4+4 Figure 5.9 HIRES Vfdeo Scanning Map. (2 of 4) RAM in the Apple II 5-17 SCREEN BOTTOM HORIZONTAL BLANKING (HBL) HORIZOHTAL DISPUV ENABLE LINE niiiiii 1111111UU1111122222222 MUM PAGE 1 pj^c jE n234567B9ftfiCOEFBi; 34567 PflGB t pacR 2 ai23156282ABCDEF0123456789?.flCDErai234567 Its S2S38 8248 S4038 16440 S2050 8272 54050 16464 t +++ + + + + + + + +++ + + + + + + + ++ + +t + f + + ++++ + + ++ + 4- 3243B 9272 S44 33 17464 +++++++*-+( #|#+++++++++«-++ S245B 9296 54450 17488 ++++++++++++++++++++++++++++++++++++++++ 130 S2838 10296 $4838 18488 $2850 10320 54850 18512 ++++++++++++++++++++++++++++++++++++++++ 131 S2C38 11320 S4C38 19512 ++.).+++.l-l.+| 1 11++++++++++++ 52C50 11344 S4C50 19536 ++++++++++++++++++++++++++++++++++++++++ 132 S393B 12344 S503B 2^536 +++++++++IIII++++++ ++++++ S3950 12368 55050 20560 ++++++++++++++++++ t+++++++f +++++++++++++ 133 S3418 13368 55438 21560 ++++++++4-JI ###+++++++++++ + S3450 13392 55450 21584 +++++++++++++++ +++++t++++++++++f ++++++++ 13-S 33838 14392 S5838 22584 +++++++++HII++++++++++++ S3850 14416 55850 22688 ++++++++++++++++++++++++++++++++++++++++ 135 S3C38 15416 S5C33 23608 + +++++++*(#!»*+++++++++++ S3C50 15440 S5C50 23632 ++++++++ ^+++++++t+++++^^+ +++++++++++++++ 136 S2Saa 8376 S4BB8 16568 +++++++++# I tt++++++++++++ S20DB 8400 $4000 16592 ++++++++++++++++++++++++++++++++++++++++ 137 324B8 9400 S44B8 17592 ++++f++++Mit+i-++++++++++ S24O0 9424 S44DG 17616 ++++++++++++++++++++++++++++++++++++++++ 138 S28Ba 19424 548B8 18616 +++++++++ J (t(|t++t ++++++++ S28D0 10448 $4800 18640 ++++++++++++++++++++++++++++++++++++++++ 139 S2CB8 11448 S4CB8 19648 +++<-+++++! Hit ++++++++++++ S2CD0 U472 S4CD0 19664 ff+++ff++ ++++++++++++++»++++ ++++++++++++ 140 S39Be 12472 S50B8 20664 +++++++++#((( #++++++++++++ S30O0 12496 $50M 20638 +++++++++++++++++++++++++++++++++++++++( 141 S34B8 13496 554B8 21633 +++f+++++M *•++++++++++++ 53403 13520 S54M 21712 *-++++++++++* + ++++++ f ++»+++++++ ++++++++++ 142 S33B8 14520 S58B8 22712 +++++f+++lttl#++++++++++++ S38DO 14544 $5800 22736 +++++++++++++++++++4- + + + + + ++++++ +++++++++ 143 $3CB8 15544 g5CB8 23736 +++++++++(( #1++++++++++++ S3CO0 15568 S5CD0 23763 ++++++++++++++++++++++++++++++++ f +++++++ 144 S213B 8504 54138 16696 +++++-n-++iifS+++++++++++ + S2150 3528 S4150 16720 +++++++++++++++++++++ + + + + ++++++++++++++(- 145 S2538 9528 S4538 17720 +++++++++1111++++++++++++ $2550 9552 S4550 17744 ++++++++++++ f ++++++ +++ + + +++++++++++++++ 4- 146 S2938 10552 54938 18744 +++++f+++#il»++++++++++++ ?2950 10576 S4950 18763 +++++++++++++++++++++++++++++++++*++++++ 147 S2DJ8 11576 S4D38 19768 ++++»-+-+++( 11++++++++++++ It S2D50 11600 34050 19792 +++++++++++++++++• + + + + +++ ff+ (+++++++++++ 14 S S3138 12603 S5138 20792 ++++^r^,+++||)f+++T++++++t+ S3150 12624 S515B 20816 ++++++++++++++++++++++++++++++++++++++++ 149 S3538 13624 S5538 21816 +++++++++ttij||++++++++++++ $3550 13648 55550 21840 ++++++++++++++++++++++++++++++++++++++++ 150 S3938 14648 55938 22840 +++++++++##!#++++++++++++ 53950 14672 S5950 22884 ++++++++++++++++++++++++++++++++++++++++ 151 S3D38 15672 S5D38 23864 +++++++++# S ##++++++++++++ $3050 15696 55050 23888 +++++++++++++++++++ t ++++++++++++++++++++ 152 S21B8 3632 S41B8 16S24 + ++!. + + + + + » t(IS++++++++ + ++ + 521D0 8656 S41D0 16848 +++++++++++++++ ++++t ++++++++++++++++++++ 153 S25B3 9656 S45B8 17843 f++++++++||tt ++++++++++++ S25D0 9680 S45D0 17872 ++++++++++++++++++++++++++++++++++++++++ 154 S29ES 19680 54968 15872 +++++++++#(#!++++++++++++ S29D0 10704 S49D0 18896 ++++++++++++++++++++++++++++++++ +++++f++ 155 S2DB3 11704 S4DB8 19896 ++++f++++#ffl++++++++++++ $2DD0 11728 S4me 19920 + + + + + + + + + + ++ ++++ + + (+ + +t+ + f+++f + +++ + + + + + 4- 156 531B8 1272S S51E)8 209 2fl +++++++++# S )(#++++ ++++++++ $31!>0 12752 S51D0 2fl944 ++++++++++++++++++++++++++++++++++++++++ 157 53538 13752 555B8 21944 i-++++++++Mll ++++++++++++ S35D0 13776 S55D0 2196B + +++ + + + + + + +++ + +++ + + + + + + + + +f+ ++)' + ++ + + + + + + 158 539B3 14776 S59B8 2296S +++++++++# (tit I ++++t+++++++ S39n0 14800 559D0 22992 + ++++ + ++++++ + + + + + + + + + + + + + + + + + + + + + + + + ++ 4- 4- 159 SIDES 15809 S50B8 23992 +++++++++ I (11 ++++++ ++++++ S3m0 15824 S5DD0 24016 + ++++++ + + + +++ + ++ + + + ++4- ++ + + + + + + + ++ + + +++ + 4- 16fl 52233 8760 S4238 16952 +++++++++# KM ++++++ ++++++ S2250 8784 S4250 16976 ++++++++++++++++++++++++++++++++++++++++ 161 $2638 9784 54638 17976 t4- ++++f++#MI+++++++++ + ++ S2650 9808 S4650 13000 ++++++++++ +++++++ + + + + +4'++++ + ++++++++++++ 162 $2A38 13908 54A38 19600 + + + ++! + + + ( (It) + + + + + + ++++ + + (I $2A50 10832 S4AS0 19024 +++++++++++++++++++ t +++++++ ++f+++++++f++ 163 $2E38 11832 S4E38 20024 +f+++++++#ltn ++++++++++++ S2ES0 11856 $4E50 20048 +++++++++++++++++ + + + + + + ++++++++++++++++(. 164 S3238 1235^ 55238 21048 +++++++++111 I++++++++++++ S3250 12880 55250 21072 ++++++++++++++++++++++++++++++++++++++++ 165 $3638 13880 55638 22072 +++++++++11 »(++++++++++++ S3650 13904 S565S 22096 +++++++++++++++++++++++++++++++++++ +f+++ 166 S3A38 14904 S5A3B 23096 +++++++++!## 1++++++++++++ S3A50 14928 S5A50 23120 + +++ + +++ + ++ + + ++( + ft + + + + + + ++ + + + ++ + + + + + + 4- 4- 167 S3E3B 15928 S5E38 24120 +++++++++11 1 H ++++++++++++ S3E50 15952 $5ES0 24144 +++++++++ f +++++++++++++++++++++++ +++++++ 168 S22Be 8888 S42B8 17080 ++ + ff++++#il)|++++++++++++ S22D0 8912 54230 17104 ++++++++++++++++++++++++++++++++++++++++ 169 $26B8 9912 S46B3 18104 ++*++++++! 1(11++++++++++++ 526D0 9936 54600 18128 + + + + + + + + + + + + + + + + + + + + +4.4.f + +++ + ++ ++ + + + ++ + 4- 170 $2AB8 10936 S4AB8 19128 +++++++++#!# (++++++++++++ S2AD0 10960 $4AD0 19152 + + ++ ++++ + + + + + + + + + + + + + + + + ++++ + + + + + ++++ + + 4^ 171 $2EB8 11960 S4EBe 20152 +++++++++#11 I ++++++++++++ S2ED0 11984 S4KD0 20176 ++ + + + + ++ + +++ + + + ++ ++ + + + + +++ + + *+++++ ++ + + + 4' 172 $32B8 12984 $52B8 21176 +++«.+++ ++11) H ++++++++++++ $3200 13008 S52O0 21200 ++++++++++++++++++++++++++++++++++++++ +t 173 $36a8 14308 S56B8 22200 +++++++++# tti++++++++++++ $36D0 14032 S56D8 22224 ++++++++++++++++++++++++++++++++++++++++ 174 $3AB8 15S32 S5ftBB 23224 +++++++++#!# 0++++++++++++ S3AD0 15056 55AD0 23248 ++++++++++++++++++++++++++++++++++++++++ 175 $3E38 16056 S5EB8 24248 +++++++++1111++++++++++++ SJEOe 16080 55EM 24272 ++++++++++++++++++++++++++++++++++++++++ 176 S2338 9016 54338 17208 +++++++++1111++++++++++++ S2350 9040 54350 17232 ++++++++++++++++++++++++++++++++++++++++ 177 $2738 10040 S4738 18232 +++++++++litt++++++++++++ S2750 10064 54750 18256 ++++++++++++++++++++++++++++++++++++++++ 178 $2B38 11064 54B38 19256 +++++++++1111++++++++++++ S2B50 11088 S4B50 19280 ++++++++++++++++++++++++++++++++++++++++ 179 $2F38 12088 $4F38 20280 +++++++++1111++++++++++++ S2F50 12112 S4F50 20304 ++++++++++++++++++++++++++++++++++++++++ 180 $3338 13112 S533E 21304 +++++++++### 1++++++++++++ $3350 13136 55350 21328 +++++++++++++++++++++++++++++++++++++ +f+ lei 53738 14135 S5738 22328 +++++++++111 )++++++++++++ $3750 1416Q 55750 22352 ++++++++++++++++++++++++++++++++++ t+++++ 182 $3B38 15160 S5B3a 23352 +++++++++|ill++++++++++++ $3B50 15184 55E50 23376 ++++++++++++++++++++++++++++++++++++++++ 183 S3r38 16184 S5F3B 24376 +++++++++*|i#++++++++++++ $3P50 1620B S5F50 24400 ++++++++++++++++++++++++++++++++++++++++ 184 523B8 9144 $43B8 17336 ++++++++ +#HI++++++++++++ $2300 916B 543D0 17360 ++++++++++++++++++++++++++++++++++++++++ 185 $27B8 10168 S47B8 18360 +++++++++flll+++++ +++++++ S27D0 10192 $4700 18384 ++++++++++++++++++++++++++++++++++++++++ 186 S2BBS 11192 S4BS8 19384 +++++++++IIII++++++++++++ S2BO0 11216 54BD0 19408 ++++++++++++++++++++++++++++++++++++++++ 187 S2FB8 12216 S4FB8 20408 +++++++++*##«++++++++++++ S2FD0 12240 S4FD0 20432 ++++++++++++++++++++++++++++++++++++++++ 18S 533ES 13249 553B8 21432 +++++++++»###++++++++++++ S33D0 13264 553D0 21456 ++++++++++++++++++++++++++++++++++++++++ 1B9 S37BS 14264 557B8 224B6 +++++++++*!#!++++++++++++ S37DO 142BB 55700 22480 ++++++++++++++++++++++++++++++++++++++++ 190 $3BB8 15288 556B8 23480 +++++++++# f ##++++++++++++ S3HD0 15312 S5i3O0 23504 ++++++++++++++++++++++++ ++++++++++++++++ 191 S3FB8 16312 55FB8 24504 +++++++++!###++++++++++++ $3FD0 16336 S5FD0 24528 ++ + ++++++ + + + + +4-+ + + + + + + + + + + + +++++++ + + + + ++ Figure 5.9 HIRES Video Scanning Mop. (3 of 4} \ 5-18 Understanding the Apple tl VERTICAL BLANKING PERIOD (VBL) HORIZONTAL BLANKING (HBLt HORIZOHTAL PISPLAV ENABLE LINE llllllll 111U11111U111122222222 MUM PAGE 1 PAGE 2 B0123456789ABCPEF01234567 PAGE 1 PAGE 2 01234 56789ABa)Er0123456789ftBCDEF0l234567 192 52060 8238 54060 16480 S2078 ~B312 54078 165B4 ++*+++++++++++++++++++++++++++++++++++++ 193 S2460 9312 S4460 17504 + + + + (-+ + + fit SI* + +++ + + + + + + ++ S2478 9336 54478 17528 +++++++++++++++++++++++++++++++•++++•'++'- 194 $2360 10336 $4S60 18528 +++++++++11* ++++++++ -H-H- 52878 10360 54878 IS552 +++++++++++++++++++++++++++++++++++•'•+++ It 195 32C60 11360 S4C50 19552 +++++++++tf«!ttt++++++++++++ SZC78 I13B4 S4C78 19576 ++++++++++++++++++++++++^+++++++++++^-++^-• 196 $3060 12334 S5060 20576 +++++++++# Sit #++++++++•<++ S3078 12408 S5078 20600 +++++++++++++++++++++++++++++++++++•++»•• 197 53460 13408 S5460 21600 +++++++++11)11++++++++++++ $3478 13432 55478 21624 +++++++++++++++++++++++++++++++++++•+++• 198 53860 14432 55860 22624 +++++++++##(#++++++++++++ $3878 14456 55878 22648 +++++++++++++++++++t++++++++++++++-n-++++ 199 53C60 15456 S5C60 23648 ++++++++#)( (!#++++++++++++ 53C78 15480 $5C78 23672 ++++++++++++++++++++++++++++++++++++++++ 2m S2DE:0 8416 S40EO 16608 +++++++++»!)#+++++++<-+++< 520F8 B440 S40F8 16632 ++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++»-+n-+++*-+^ 201 524E0 9440 S44E0 17632 +++++++++!( )(##+++ + ++++++++ S24F3 9464 S44F8 17656 202 S28Efl 10464 548E0 18656 + ++++++++# ##+++++ + ++++++ 5Z8F8 10488 548F8 18680 +++++++++++++++++++++++++++++++++++++++< It 203 S2CEa 11488 $4CE0 19680 +++++++++#»##++++++++++++ S2CF8 11512 54CF8 19704 ++++++++++++++++++++++++++++++++++<•+++++ 204 S30E0 12512 SS0E0 20794 +++++++++# 011+++ +++++++++ S3flF8 12536 S50Ffl 29723 ++++++++++++++++++ +++++++++++++++++++*+^- 205 S34E0 13536 S54EC 21728 +++++++++! f«j| ++++++++++++ 534 F8 13560 $54F8 21752 +++++++++++++++++++++++++++++++++++++++* S3BF;0 14560 558 E0 22752 +++++++++))###++++++ ++++++ S33F8 14584 S58Fn 22776 ++++++++++++++++++++++++++++++++++f+t+++ 2136 ++++++++++++++++++++++++++++++++++++1-+1-+ 207 53CE0 15584 55CEa 23776 +++++++++!((##++++'•++++'++ S3CF8 15608 S5CF8 23300 26& S2160 S544 S4160 16736 +++++++++«###+++++++<++++ 52178 8568 54178 16760 ++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++<++++++++'•+'' 209 S2560 9568 S4560 17760 +++++t+++fi#f ++++++++++++ S2578 9592 $4573 17784 +++++++++++++++++++++++++++++++++++++++»' 210 S2960 10592 S4960 18784 +++++++++#»##++++++++++++ S297B 10616 54978 13S08 ++++*+++»+++*•++*•++<+++* 211 32060 11616 S4D60 19808 +++++++++»###++++++++++++ S2D78 11640 $4D78 19832 +++++++ ++++++++ + +++++++++++++++++++++++++•^+++++^•++^*^^•++ 212 $3160 12640 55160 20832 +++++++++S)tfl !(++++++++++++ S317B 12664 S5178 20856 ++++++++++++<+++<++++++++ 213 S3569 13664 55560 21856 +++++++++8 !!«#+++ +++++++++ 53578 13688 S5578 21880 +++++++++++++++ 214 S3969 14638 55960 22880 +++++++++# (*!++++ ++++++++ 53978 14712 S5978 22904 ++++++++++++++++++++++++++++++++++''<+*-+ +++++++++t++++++++*++++«-++t'»'++++++»-+++l-+ 215 $31560 15712 S5D60 23904 +++++++++!##*++++++++++++ 53073 15736 S5D78 23928 216 $21E0 S672 S41E0 16864 +++++++++!)## #++++++ '-++'•'•+ $21F8 8696 $41F8 16838 +++++++++++++++++++++++++++*++++++++++++ ++++++++++++++++++++++++++++++++++++++++ 217 $25E0 9696 S45E0 17888 +++++++++!»# *++++++++++++ $25FS 9720 S45F8 17912 +++++++++++++++++^^++++++++++t+++ + ^*++++ 21i) $29E0 10720 S49E0 18912 +++++++++)(#((((++++++++++++ S29F8 10744 S49Fa 18936 219 52DE0 11744 S4DE0 19936 +++++++++ »!++++ ++++++++ $20F8 11768 S4r3F3 19960 +++++++++++++++++++++++++++++++++<++++++ It It +++++++++++++++++++++++++++++++++••++++++ 220 S31C0 12768 551 E0 20960 +++++++++)(((#(+++++<-++<+++ S3lFe 12792 55lFa 23984 221 S35E0 13792 S55E0 21984 +++++++++## I #+++•-++++•<+++ 535F8 13316 S55Fa 22008 ++++++++++++++++++++++++++++++++++++++*+ 222 S39E0 14816 559 F.0 23008 +++++++++##11++++++++++++ S39F8 14840 S59Fa 23032 ++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++t++++l-++++++++'^++»- 223 $3DE0 15840 S5DEa 24032 +++++++++####++++++++++++ S3DF8 15864 $5DFa 24056 224 52260 8800 S4260 16992 +++++++++ #( H M » t »# I #» * 52278 It 8824 S4278 17016 HI||Hi|Mtlil#»»tl»»IH(Ht»»i«lt»lttlH»ili«ltlMll it 225 S2660 9824 £4660 18016 +++++++++#!» tItiH I MtlHtit 52678 9848 54678 18040 «ltl««»illlli»l*t»*«i4*4lll>***ttlt*llllt»||«ltl 226 S2ft60 10848 S4A69 19040 ++++++++ + ## J *#* tP ## It M S2A78 10872 $4A78 19064 «|#||HlM«»IHI»l»tlli»»»#*»Mttlillt(t»»f tt )| tt 227 S2E60 11B72 54E60 20064 +++++++++# S)t(t(ISt## »«###* S2E78 11896 $4E78 20088 ilf#im**tt»»»#*tliti«Mlt«lt»#tMII»tlMM +++++++++++++++++++++++++++++++++•++++++ 228 S3260 12896 55260 21088 +++++++++### ++++++++++++ S3278 12923 S5278 21112 It 229 $3660 13920 55660 22112 +++++++++####++++++++++++ 53678 13944 55678 22136 +++++++++++++++++++++++++++++++-+++++++++ 230 S3A60 14944 55A60 23136 +++++++++##* )t++++++++++++ S3fl78 14968 55A73 Z316R ++++++++++++++++++++++++++++*<-<-+++++++++ ++++++++++++++++++++t+++++++i-+++t++»-++++ 231 S3F,60 15968 55E60 24160 +++++++++## * I++++++++++++ S3E78 15992 S5E78 241B4 +++++++++++++++++++++++++++++++++l-*++++»- 232 S22Ee 8928 542E0 17120 +++++++++##!#++++++++++++ S22F8 8952 S42F8 17144 ++++++++++++++++++++++++++++++++++++++++ 233 S26E0 9952 S46E0 13144 +++++++++I ##!++++++++++++ 526FS 9976 S46F8 18168 ++++++++++++++++++++++++++++++++++++++++ 234 $2AE0 10976 54fi.E0 19168 +++++++++## ( I++++++++++++ 52Apa 11000 S4AF8 19192 ++++++++++++++++++++++++++++++++++++++++ 235 52EE0 12000 54EEa 20192 +++++++++!( (##++++++++++++ S2EF8 12024 S4EF8 20216 +++++++++++++++++++++++++++++++*+»++++++ 236 532E0 13024 552Ea 21216 +++++++++I (#(++++++++++++ S32F8 13343 S52FS 21240 ++++++++++++++++++++++++++++++++++++++++ 237 $36E0 14048 S56E0 22240 +++++++++###!++++++++++++ $36FS 14072 S56F8 22264 ++++++++++++++++++++++++++++++++++++++++ 239 S3AE0 15072 S5AE0 23264 +++++++ ++(t #111++++++++++++ S3AFB 15096 S5AF8 23288 ++++++++++++++++++++++l-++n-+-'-<"'-'"''+++++++ 239 S3EE0 16096 S5EE0 24238 +++++++++#1 #++++++++++++ S3EF8 1612B 55EFB 24312 It 240 $2360 9056 54360 17248 +++++++++ 1 S #++!+++++++++ S2378 9080 54378 17272 ++++++++++++++++++++++++++++++++*++•*+-'+ It ++++++++++++++++++++++++++++++++++++++++ 241 82760 10080 $4760 18272 ++++++ +++#!» #+++++++++++4 52778 10184 54778 18296 242 $2B60 11104 S 41560 19296 +++++++++# *++++++++++++ 52B78 11128 54B78 19320 ++++++++++++++++++++++++++++++++++++++++ It It ++++++++++++++++++++++++++++++++++++++++ 243 SZF60 12123 S4F60 20320 +++++++++!# #»++4-+++++++++ 52r78 12152 S4F78 20344 244 53360 13152 55360 21344 +++++++++I ##++++++++++++ 53378 13176 55373 21368 ++++++++++++++++++++++++++++++++++++++++ It ++++++++++++++++++++++++++++++++++-^»-++++ 245 53760 14176 S5760 22368 +++++++++ 1 It ++++++++++++ 5377B 14200 55778 22392 II ++++++++++++++++++++++++++++++++++••+++++ 246 $3B60 15200 55360 23392 +++++++++# (!#++++++++++++ S3B78 15224 j$5B78 23416 247 S3F60 16224 S5F60 24416 +++++++++(!##++++++++++++ S3F7B 16248 55F78 24440 ++++++++++tt++t++^^+++++++++++^-+++++++++ ++++*+++++++ 243 S23E0 9184 $43E0 17376 +++++++++» 1*1++++++++++++ $23F8 9208 543F8 17400 ++++i-+++++++++++++++++++++++ $27E0 10208 $47EB 18400 +++++++++»##*++++++++++++ S27F8 10232 S47F8 18424 ++++++++++++++++++++++++++++++++++++++++ 249 ++++++++++++++++++++++++++++++++++++++++ 250 82BE0 11232 54BE0 19424 +++++++++(## #++++++++++++ S2BF8 11256 S4BF8 19448 ++++++++++++++++++++++++++++++++++++++++ 251 S2fE0 122S6 $4FE0 20448 +++++++++li##++++++++++++ $2FF8 12280 S4FF8 20472 ++++++++++++++++++++++++++++++++++++++++ 252 $33E0 13280 S53E0 21472 +++++++++!###++++++++++++ $33F8 13304 S53F3 21496 ++++++++++++++++++++++++++++++++++++++++ 253 S37E0 14304 557E0 22496 +++++++++ t#H+++ +++++++++ 537F8 14328 S57F8 22520 ++++++++++++++++++++++++++++++++++++•+++ 254 S3BE0 15328 55BE0 23520 +++++++++(( #!#++++++++++++ S3&FS 15352 S5BF8 23544 +++++++++++.++++++++++++++-4-++++++++++++++ 255 S3FE0 16352 $5FE0 24544 +++++++++# JII++++++++++++ 53FFa 16376 $5FFe 24568 If 256 52BE0 11232 54BE0 19424 +++++++++|jtj|++++++++++++ 52BF8 11256 54BF8 19448 +++++++++++t++++++++ + + 4-t-++-t-+++++++++++++ ++++++t+++++++++++++++++++++t+t+++++++++ 257 S2FE0 12256 $4FE0 20448 +++++++++» !!#++++++++++++ S2FFe 12280 S4FF6 20472 +++++++++++++++++++++++++++++++++-+++++++ 258 533E0 13280 553E0 21472 +++++++++|t|#++++++++++++ S33F8 13304 S53F8 21496 ++++++++++++++++++++++++++++++++++++++++ 259 S37Ee 14304 557 E0 22496 +++++++++( lit ++++++++++++ S37F8 14328 S57F8 22520 260 S3BE0 15328 S5BE0 23520 +++++++++(# #(++++++++++++ S30Fa 15352 S5BF8 23544 ++++++++++++++++++++++++++++++++++++++++ 261 S3FE0 16352 55FE0 24544 +++++++++(##*++++++++++++ S3FF8 16376 55FF8 24568 ++++++++++++++++++++++++++++++++++++++++ Figure 5.9 HIRES Video Scanning Map. (4 of 4) RAM in the Apple II 5-19 Table 52 Screen Memory Usage Summary. TEXT/LORES HIRES LOCATION HBL HBL' HBL HRi; SCREEN (Last 16 of FIRST 40 Last 16 of FIRST 40 TOP THIRD 40 and THIRD 40 and UNUSED 8) UNUSED 8 PLUS $1000 1 SCREEN (Last 24 of SECOND 40 Last 24 of SECOND 40 MIDDLE FIRST 40) FIRST 40 PLUS $1000 SCREEN (Last 24 of THIRD 40 Last 24 of THIRD 40 BOTTOM SECOND 40) SECOND 40 PLUS $1000 VBL (Last 24 of UNUSED 8 and Last 24 of UNUSED 8 and THIRD 40) First 32 of THIRD 40 First 32 of PLUS $1000 FIRST 40 FIRST 40 The following is a reference list for scanned If the Apple had been originally designed to oper- memory in the HIRES MIXED mode: ate with only 16K RAM chips, the RAM refresh re- LineO. HPE'+ 1 thru quirement could easily have been met by assigning Line 160. HPE' HIRES. Figure 5.9 HO. HI, H2. SUM-A3, SUM-A4. SUM-A5, and VO to Line 160, HPE' + l thru the RAM ROW addresses. The 4K/16K capability Line 192, HPE' TEXT, Fig-ure 5.6 adds a new requirement, however, which isn't met Line 192, HPE'+l thru by these assignments. Pin 13 is RA6 on a 16K RAM Line 224. HPE' HIRES. Fi^re 5.9 chip and chip select on a 4K RAM chip. In the 4K Line 224. HPE' + l thru configuration. A12 and A13 select among rows C, D, LineO. HPE' TEXT. Figure 5.6 and E via pin 13.Thisdictatesthat Al2and A13are also assigned to pin 13 in the 16K configuration. In HPE' occurs during the first video scanner state of other words, A12 and A13 must be assigned to the HBL. On the screen, the addressswitching point for ROW and COLUMN address of RA6. A 13 is equiv- HIRES MIXED mode comes just at the end of the alent to HIRES PAGE 1 during scanner access. This display on the right side. is not acceptable for a ROW address, because it doesn't change with the video scan. The natural REFRESHING RAM IN THE APPLE equivalent of Al 2 is H IRES • VC. This is not accept- The refresh requirementofl6K dynamic RAM is able for a ROW address, because it doesn't change that every ROW address be accessed at least once inTEXTor LORES mode. The Appledesigner made every two milliseconds. To achieve refresh in the A 12 work as a ROW assignment by changing its process of scanning RAM for video output, the scan nerequi%'a]ent to HIRES* VC + TEXT/LORES address inputs to RAM had to be assigned very care- • HBL. HBL changes during TEXT/LORES and fully. This assignment was made more complex in meets the refresh requirements. During HBL the the Apple design by the capability of using 4K or "wrong" addresses are selected but no harm is done , 16K RAM chips. because the screen is blanked during HBL. 5-20 Understanding the Apple Table 5.3 The Video Scanner Row Address does notshow the circuits required for 4K operation. Assignments. In older Apples configured for I6K RAM chips, the 74LSi;^9 at E2 serves no purpose and may be RAM Add ress Scanner Input used as a spare. There is no chip at E2 on newer Apples. The following circuits serve no purpose in RAO VO older 16K configured Apples and are not wired in RAl H2 newer Apples: RA2 HO RA3 VI RA4 SUM-AS LOCATION TYPE RA5 HI E2 LSI 39 RA6 HIRES VC + TEXT/LORES. HBL Jl sections a & b LS257 Hi pins 1.2.3,11,12, & 13 LS08 The other ROW address assignments are d ictated Cl4pinsl.2.&3 LS32 by the use of HBL as a refresh bit. HO, Hi, H2, and SUM-A3 run through a 16-state sequence at least Owners may dream up their own modifications to once every time H BL is high or low. SUM-A4. SUM- utilize these circuits. AS, and SUM-A6 are unacceptable, because they do In the address multiplexor, 4 to 1 multiplexing is not make a complete sequence every time HBL is accomplished in LSt53s, vvhile2 tol multiplexing is high. The remainingtwo ROW address assignments accomplished in LS257s. The horizontal address are VO and VI, offset is generated by an LS283 adder. CAS' and In HIRES mode, VC is a refresh input but VA and VB aren't For every state of Vl-VO-VC. all the RAM SELECT' are decoded in an LSI 39. Propagation delays in the CAS' and RAM SE- lower refresh bits go through their counts four LECT' lines are important. CAS' falling is delayed straight times (once for each state of VB-VA). This to RAM by the high to low propagation of the LSI 39 means that the maximum time between refresh at F2. This is listed as 21 nanoseconds typical and 32 states is no more than 29 horizontal scans (32-3) or nanoseconds maximum by the Texas Instruments 1.86 milliseconds, InTEXT/LORES mode, VA.VB. TTL Data Booh. This delay is 25 nanoseconds in the and VC are not refresh bits, so the maximum time author's Apple. The significance here is that RAS' between refresh states is 25 horizontal scans (32-7) rises only 178 nanoseconds after CAS' falls at the or 1,59 milliseconds. In both modes, the 2 millisecond maximum is met. RAM chips (210 minus 32 equals 178). The TCAC specification (maximum time from CAS' to read data valid) should be less than 178 nanoseconds in RAM chips used in the Apple II. RAM ADDRESS MULTIPLEXOR A second important delay period is the time from HARDWARE PHASE falling until RAM data becomes valid on the data bus after an MPU access to an address Figure 5,10 is a schematic diagram of the RAM above $COOF. This propagation delay represents the address multiplexor. The multiplexor is shown time after PHASE falls, by which any device other jumpered for 16K, but Revision 7 and later Apples than RAM must stop controlling the data bus. The are wired this way without jumpers. Figure 5.10 chain is listed below: LOCATION TYPE SIGNAL PATH TYPICAL MAXIMUM Jl LS257 pin 1 to pins 9,12 14nsec 21 nsec F2 LSI 39 pins 14,13 to pins 10,11,12 26 nsec 39 nsec D2 LS20 pin.s 9,10.12 to pin 8 9 nsec 15 nsec A2 LSOO pin 5 to pin 6 10 nsec 15 nsec B7.B6 LS257 pin 15 to pins 4,7,9.12 20 nsec 30 nsec TOTAL 79 nsec 120 nsec k RAM in the Apple II 5-21 CO tr LU < o CO to lU o Q LU a < > ^ o S o rr EC Ll. U- m tnoQ«- -f l=>> 6 & I 5-22 Understanding the Appie PHASED 1 / 1 I CAS' LJ If r CAS' Row C / W" CAS' Row D r CAS' Row E JBgure 5.1 1 LJ CAS' Signal Example. This time delay is 60 nanoseconds in the author's RAM TIMING IN THE APPLE II Apple. A very interesting feature of Apple RAM connec- Most aspects of RAM timing have already been tions is the termination reststorson the multiplexed covered in various other related discussions. The RAM address lines. RA0-RA6 on the right side of intention here is to reinforce the timing details of Figure 5.10. No RAM data sheet recommends pull- basic RAM access. up and pull-down resistors on the address inputs, so ne area of mportance is the gating of CAS' to the i why are they there? They are there because Steve three rows of RAM. Figure 5.11 shows the last two Wozniak found that stringing large numbers of cycles of the following instruction: RAM chips together can cause reflections on the RAM address lines. Presumably, this is because the 9000 LDA $5000 ;APPLE fC\C U IS Ll3 Cr Li inductance of the conductors and the capacitance at jCURRENTL .-CURRENTLY IN the RAM chip inputs give the RAM address lines a jTEXT MODE. characteristic impedance, just Hke television coaxial cable has a characteristic impedanceof 75 ohms. A The instruction is stored at $9000 through ,$9002. so coax cable or other distributed reactance transmis- instructions are being fetched from RAM row E. sion line needs to be terminated by an impedance The Apple is in TEXT mode, so the video scanner is equal to its characteristic impedance, or reflections accessing row C. The instruction is loading from {voltage pulses traveling backwards) will occur. In $5000, so on the last cycle, the MPU accesses row D. the Apple, these reflections were causing RAM ac- The operation is really very simple. CAS' at any cess to be unreliable. Wozniak is not a transmission RAM row goes low when that row is addressed and line expert, but he determined experimentally that when CAS' from the timing generator goes low. 1000 ohm puil-up and pull-down resistors would Figure 5.12 shows some basic details of a 6502/ make RAM access reliable. He says that this was RAM read cycle. There are several important later verified to be the theoretically correct termina- points illustrated here. For one thing, even though tion. The RA6 distribution path in older Apples was read data from the RAM chips is only valid for a such that reflections werenota problem. In Revision limited period, it is held valid on the data bus for 7, RA6 distribution was made similar to the other nearly half a microsecond by the RAM latch. When RAM address lines, and a pair of termination re- a program stored in RAM being executed. RAM is sistors for RA6 was added. output data is continuously controlling the data bus RAM in the Apple II 5-23 except durinff and after write cycles or access to 2. PHASE 1 • AX enables the video ROW address addresses above $BFFF. Another intereRtJiiR point RAM, and the ROW address is clocked to to is that while the MPU addresses RAM durinpr RAM by RAS' falling. PHASE 0, data from the MPU access is present on 3. PHASE . AX' enables the video COLUMN 1 the data bus during PHASE 1. rouRhly speaking. address to RAM and the COLUMN address is Similarly, the video data is present roughly during clocked to one row of Apple RAM by CAS' PHASEO. As Figure5.12shows, PHASE fl rising: is falling. a good clockpulse for clocking video data to periph- 4. Video data becomes valid at the output of RAM. eral cards during read cycles. The time at which this occurs will depend upon It ^oes without saying that data from the MPU the speed of the RAM chips being used in a read access is present on the data bus when 6502 given Apple. TC AC (Time - CAS' ACcess) should PHASE 2 falls. This is required of all read responses be shorter than 178 nano.seconds in chips RAM to the 6502, whether the responding device is RAM, used in the Apple. In all Apples, the data RAM ROM. or an input port. must become valid before RAS' rises and latches The order of important events in Figure 5.12 is: the RAM data. 1, PHASE 2falls, clocking thedata transfer of the 5. The data is latched by RAS' rising. previous 6502 machine cycle. 6. About 35 nanoseconds after RAS' rises, the 6502 PHASE 2 6S nsec typical PHASED ^ SCANNER ADDRESS Latch MPU ADDRESS Video data vafid on data bus Latcti MPU MPU input daia valid on data Ijus video RAS' data ::lil data :^ -TflAt- CAS' 1 T CAS' raw C / \ f -TCAC- AX ROW \ COLUMN / ROW \ COLUIVIN ROW I RAM DATA OUTPUT 3 Q -TOFF Load lext pattefr in video gerieraior o LDPS' i:iF " lrt:remenl video scanner DATA BUS r MPU DATA VIDEO DATA MPU DATA Figure 5.12 Timing Exomple: A 6502 Read Cycle to Address $1000. 5-24 Understanding the Apple i video data becomes valid on the data bus. The by the current state of the RAM latch and by the delay is due to propag-ation delay in the RAM current state of VA, VB. and VC, latch (LS174) and RAM/keyboard multiplexor 9. Just as in the scanner access, RAM data from (LS257). The latched RAM data is held on the MPU access becomes valid, is latched, and is the data bus throughout Figrure 5.12, because both propagated to the data bus. the video scanner and the MPU are reading 10. The RAM read data is clocked to the MPU by from RAM. PHASE 2 falling. 7. During PHASE 0, the MPU addresses RAM Figure 5.13 shows some basic details of a 6502/ in the same way the video scanner did dur- RAM write cycle. The RAS'. AX. CAS' address ing PHASE 1, with AX selecting ROW or COLr control is identical to a read cycle. The primary UMN and RAS' and CAS' docking the address difference between the read cycle and write cycle is to RAM. in data bus management. Also, the features of data 8. LDPS' drops low during PHASE 0. This is the bus management during write cycles are the same signal which loads Tp]XT patterns in the video whether the 6502 is writing to RAM addresses or to generator. The TEXT patterns are determined any other addresses. 6502 PHASE 2 PHASE SCANNER ADDRESS MPU ADDRESS RAS' Latch video data TRAC- Y JOOnSCE lypical Latch SFFitT. write cycle r~i CAS' rOFF 2ansec ' -TCAC- tyfiical CAS" row C / ] f RAMdala-^' output R/W RAM R/W Load tei^t pattern In video generator LDPS' N TJlf^ Increment video scanner 6502 PHASE lallmfi switches SFF to data bus RAM SELECT' Float data bjs 1 direction o) MPU .^ 27iiiec bidirectional bus driver 30 nSeC M . typical typical MPU FLOATIWGBUS STORES MPU DATA DATA BUS If^ DATA &502 WRITE DATA VALID ON DATA BUS SFF 6502 PHASE 1 nsing changes direction of MPU bidirectional bus driver Floating bus stores write data until H/W rises. Figure 5,13 Timing Example: A 6502 Write Cycle to Address $1000. RAM in the Apple II 5-25 In the write cycle, the video scanner makes its data bus until data from the current video read access to RAMduring PHASE 1 just as in the access is latched. A write cycle is always fol- read cycle. Nothing interrupts the scanner access to lowed by a period of time with $FF on the data RAM in an unmodified Apple. The latched video bus. data never gets to the data bus in a write cycle, The RAM SELECT' term is the primary data bus however. While R/W is low. the MPU {or DMA management signal in the Apple. When the MPU is peripheral) owns the data bus. not accessing RAM, RAM SELECT' defines when Excluding the scanner access which is the same as the data bus is available for other devices to respond in a read cycle, the order of important events in a toRAM. This timing is illustrated in Figure 5.14, write cycle is as follows: which shows a read to SCOIO. the keyboard strobe reset address. 1. PHASE 2 falls, clocking the data transfer of the $C010 is one of the Apple addresses which causes previous 6502 cycle. the data bus to float. The floating data bus stores the 2. The R/W line drops low at the same time the video data from the scanner access so that it can be 6502 address becomes valid (about 100 nanosec- read by the MPU. A read to a data responding onds after PHASE 2 falls). This forces RAM address like $F800 (ROM) will have very similar SELECT' high which disables the output of the timing, except that at some time during the floating RAM/keyboard multiplexor. No other device bus period, the responding device will take control takes control of the data bus at this time, so the of the data bus. The mainorder of events in Figure latched data from the previous MPU cycle 5.14 is as follows: remains valid on the data bus (because of the long bleed off time of data when the Apple's 1. The scanner accesses RAM during PHASE 1. data bus is floated). 2. About 35 nanoseconds after RAS' rises, the 3. PHASE rises, enabling MPU addressing at latched data from the video access is on the data the RAM address multiplexor and enabling bus. R/W to drop low at the RAM chips, The R AS'. 3. PHASE rises, routing the MPU address AX, CAS' addressing sequence is identical to through the address multiplexor. Since the the read cycle sequence. MPU is not addressing RAM or the keyboard, 4. 6502 PHASE 1 falls, causing the MPU bidirec- the RAM SELECT' goes high, floating the data tional bus driver to take control of the data bus. bus. It takes about 60 nanoseconds for RAM The 6502 write data is not yet valid, and until it SELECT' to go high after PHASE rising, becomes valid, the data bus in the author's because the logic must be propagated through Applestayslow if it was low and oscillates down four LSTTL devices, then up if it was high. The state of the data bus 4. After RAM SELECT' goes high, the data bus during this time period is not significant. floats, storing the latched video data. If a data 5. The 6502 write data becomes valid before CAS' responding device had been addressed, it could falls at the RAM chips. The Apple write cycle is take control of the data bus anytime during this what is referred to in RAM literature as an floating period. early write cycle (as opposed to a read/write 5. RAS' rises and latches ,$FF at the RAM data cycle). R/W drops low before CAS', and write latch. The RAM data output is floating when data must be valid at the RAM input before RAS' rises, because CAS' does not fall at any of CAS' drops. the three rows of Apple RAM. As in a write 6. RAS' rises. latching$FF in the RAM data latch. cycle, the floating RAM output is interpreted as During the write cycle, the output of RAM $"fF by the latch. floats. The response of the data latch to the float- 6. PHASE falls, causing the scanner to address ing input IS to bring its output lines high when RAM, RAS' ri.ses. 7. The 6502 PHASE 2 clock falls, clocking video 7. 6502 PHASE 1 rises, reversing the direction of data to the MPU. the bidirectional bus driver and floating the 8. RAM S ELECT' drops low about60 nanoseconds data bus. The 6502 write data remains valid on after PH AS EO. After a further short delay, the the floating data bus. latched RAM data ($FF) is gated to the data 8. R/W goes high, causing the RAM SELECT' bus. As in a write cycle, any MPU access to an signal to go low. This places the latched data address above ?BFFF is followed bya period of ($FF) on the data bus. $FF will remain on the time with $FF on the data bus. 5-26 Understanding the Apple II 6502 PHASE 2 \ r SCANNER ADDRESS MPL ADDRESS "1 PHASE I 1 — LATCH LATCH - VtDEO r SFF ----.r" '~~~^ RAS' I DATA \ RAM DATA — OUTPUT -c 1 — BOnsec lypical RAM SELECT [ ^ DATA BUS I MPU DATA li /IDEO )ATA 1 FLOATING BUS STORES VIDEO DATA — 1 SFF ngur© 5.14 Timing Example: A 6502 Read Cycle fo Address $C010. THE 16K RAM CARD an excess of 4K of RAM which is utilized by bank switching the $DOOO-$DFFF range. Installation of There are two common operational philosophies the 16K RAM card gives the Apple the full versatil- encountered in today's microcon^puters. One is to ity of a 60K disk based computer with the added have an extensive operating system, inchjding a features of 4K of bank switched auxiliary RAM and BASIC interpreter in ROM. These computers come 12K of instantaneously available firmware. up in BASIC and may use disk or cassette or both for The I6K RAM card was originally released as program and data storage. The other philosophy is part of the "Language System", which included the to have a strictly disk based system with little firm- RAM card and Pascal, Integer BASIC, and Apple- ware beyond a bootstrap program which loads soft BASIC on disk. 16K RAM cards eventually operating systems from disk to RAM. This philos- became available as stand alone products from a ophy yields far more versatility than the other for number of sources, and the card now supports sev- the obvious reason that any available operating sys- eral languages as well as CP/M when used in con- tem may be loaded, giving the computer a com- junction with aZ80 MPU card. pletely different personal ity. The Apple computer is This section will cover the operational features of of the former philosophy with a string attached. The the 16K RAM card produced by Apple: however, string is that installation of a 16K RAM card con- probably all 16K RAM cards made for the Apple verts it to a computer of the latter philosophy. will operate the same way. The basis for these dis- A card in any peripheral slot can inhibit mother- cussions will be the schematic diagram of Figure board ROM and respond, itself, to addresses $DOO0- 5. 15. This drawing was prepared by the author after $PFFF. 16K RAM cards use this feature to steal the study of a "Language System" RAM card and of an 12K addressing range from ROM and use it for ad- imitation purchased in Tokyo. The imitation turned dressing expansion RAM. Useof 16K chips creates out to be identical in all but a few details. RAM in the Apple II 5-27 am cc Hi' f^ 1 h —ST ;-* ::i: o. I : g 5 i 4 TT ?!)? ^ 1 as °- 1 I t 1 i i '" eg -,^. |i|5 g^^ e[ i[ ^ f i[ ^g $ s 5 9 a ss •A ^ =oA ^* cA ^A -fl f^A t^A -A f^A ™i m (i(i ^ S 5-28 Understanding the Apple Apple's 16K RAM card requires the owner to Bank switching of the 4K auxiliary bank is move a RAM chip from the motherboard to the RAM accomplished via RA6. This is natural when you card and connect a 16-pin DIP, jumper between the remember that RA6 is A 12 during ROW access and card and the vacated motherboard socket. This was AU-S during COLUMN access. The four possible Apple's way of getting around the necessity of de- multiplexed states of RA6 therefore partition the veloping: RAS' and ROW/COLUMN multiplexed 16K of expansion memory into its four most signifi- addresses on the card. RAM timing signals are not cant divisions. The $DO0O-$DFFF portion of expan- available at the peripheral slots, and developing sion memory addressing is identified by A12 • A13' equivalent signals is made difficult by the absence of meaning the ROW-COLUMN statesofRA6 are 1-0. 14M at the slots. Rather than tackle the problem of If bank 2 is selected, this ROW-COLUMN combina- developing timing signals and multiplexing the ad- tion is allowed to occur. If bank 1 is selected, the dress bus from 14 to 7 lines. Apple bypassed the ROW-COLUMN combination is forced to 0-0, caus- problem by connecting the jumper to the mother- ing access to a different 4K area of expansion board RAM socket. This probably lowered the cost memory. Bank 2 is selected at power up and, under of producing the hardware, although you wouldn't some conditions, by FP, INT. or RUN commands or have guessed it based on the retail priceof the "Lan- a RESET when DOS is active. Bank 2 is therefore guage System." normally accessed at $DOOO-$DFFF, and bank 1 is the auxiliary bank. The RAM chip that is transferred from the moth- erboard has all of its pins connected to pins of the The expansion RAM enabling and bank switch- ing circuitry is centered around the four flip- flopsof DIP jumper socket. This means that the transferred a 74LS175. These f!ip- flops save the current config- chip performs the same function it did on the moth- uration of expansion memory which is set up by erboard and that any RAM chip may be chosen for transfer as long as the jumper reaches the vacated DEVICE SELECT' commands. The assigning of these command functions was obviously designed socket. RA()-RA6 and RAS' are also distributed to for DOS compatibility, so the RAM card would look other points from the DIP jumper, RA0-RA5 are like the fi rmware card to DOS when it was checking connected directly to their respective pins on all for availability of Applesoft and Integer BASIC, eij?ht expansion RAM chips. RAS' and RA6 are This means that a write access to $C080 must enable gated to their respective pins on the eight chips during PHASE 1 with CAS' held high. This results a RAM card in Slot for reading only, and a write access to $Cfl81 must disable the Slot expansion in the same RAS'-only refresh during PHASE 1 card for reading. In their effort to maintain this that occurs on the motherboard. During PHASE 0, compatibility, Apple came up with a rather involved things get a little more involved. programming method for configuring expansion Enabling and disabling of transfer to and from RAM. The Slot configuration characteristics go the expansion RAM during PHASE is controlled like this: via RAS'. The RAM may be disabled, enabled for A3 controls the 4K bank selection. $C080-$C087 reading only, enabled for writing only, or enabled resets theBANK 1 flip-flop, enabling bank 2. for both reading and writing under program con- $C088-$C08F sets the BANK 1 flip-flop, ena- trol. When an address in the$DOOO-$FFFF range is bling bank 1. on the address bus during PHASE and expansion AG and Al control the READ ENABLE flip- RAM is enabled for the existingstate of R/ W, RAS' flop.Access to $C080, $C083, $C084, $0087. will be gated to the eight expansion RAM chips. $C088, $C08B. $C08C. or $C08F sets the READ Also during PHASE 0, CAS' will follow RAS', ENABLE flip-flop, enabling reading from delayed by one 7M period. This results in RAS' and expansion RAM. Aecessto$C081.$C082,$C085, CAS' falling at the expansion RAM at nearly the $C086, $0089, $C08A, $C08D, or $C08E resets same point as motherboard RAS' and CAS' with the the READ ENABLE flip-flop, disabling read- only difference being propagation delay. ing from expansion RAM, The tri-state outputs of the expansion RAM are Writing to expansion RAM is enabled when the connected directly to the data bus, not to an 8-bit WRITE ENABLE' flip-flop is reset. The con- latch as on the motherboard. This makes timing less trolling MPU program must set the PRE- critical because RAM read data does not have to be WRITE flip-flop before it can reset the WRITE valid when RAS' rises but must be valid when 6502 ENABLE' flip-flop. The PRE-WRITE flip-flop PHASE 2 falls. is set by an odd read access in the $C08X range. RAM in the Apple II 5-29 access in BIT $C081 WRTCOUNT + 1, READ It is reset bv an even access or a write DISABLE, BANK 2. the $C08X range. The WRITE ENABLE' flip- ENABLE WRITE, DISABLE flop is reset by an odd read access tn the $C08X READ, BANK 2. rang-e when the PRE-WRITE flip-flop is set. It is set by an even access in the $C08X range. Any BIT $C082 WRTCOUNT = 0, WRITE other type of access causes the WRITE ENA- DISABLE, READ DISABLE, BLE' flip-flop to hold its current state. DISABLE BANK 2. At power up. the RAM card is disabled for read- EXPANSION RAM. ing and enabled for writing. The PRE-WRITE flip-flop is reset, and bank 2 is selected. The STA $0081 WRTCOUNT = 0, NO power-up circuit of Ra and CI forces this con- EFFECT ON WRITE figuration by resetting the LS175 flip-flops. ENABLING, DISABLE The Apple II system RESET at pin 31 of the READ, BANK 2. RAM card has no effect on the RAM card con- figuration . The RE S ET h and H ng program must STA $C08B WRTCOUNT = 0, NO configure the RAM card. EFFECT ON WRITE ENABLING, ENABLE The write enabling flip-flops can be thought of as READ, BANK I, a write counter which counts odd read accesses in the $C08X range. The counter is set to zero by even the write BIT $C08B or write access in the $C08X range. If ENABLE READ/WRITE BIT $C08B counter reaches the count of 2, writing to expansion BANK 1 RAM becomes enabled. From that point, writing LDA $DXXX will stay enabled until an even access is made in the BIT SC083 ENABLE READ/WRITE $C08X "range. This means there is a feature of RAM BANK 2. card control not documented by Apple: write access TRANSFER BYTE FROM controls the STA $DXXX to an odd address in the $C()8X range BANK 1 TO BANK 2. READ ENABLE flip-flop without affecting the state of the WRITE ENABLE' flip-flop. As mentioned before, the unusual nature of the The Slot control characteristics are summarized RAM card configuration commands are a result of in Table 5.4. There are two address commands possi- making the RAM card compatible with DOS. This involves making it compatible with the short rou- ble for every function. The programming convention $C080-$C083 and $C088-$C08B. tine which starts at $A5B2 of DOS ILH. This is the is to use addresses Based on Table 5.4. here are some Slot pro- routine used by DOSto switch to Integer or Ar>ple- soft, It is entered with $20 in the accumulator when gramming examples. looking for Integer and $4C in the accumulator BIT $C080 WRTCOUNT = 0, WRITE when looking for Applesoft. These are the values DISABLE, READ ENABLE, found at address $EO00 of the two programs. With BANK 2. SIMULATES firmware card comments, the DOS language find- FIRMWARE CARD. ing routine looks like this: BIT $C083 WRTCOUNT + 1, READ A5B2: CMP $E000 ENABLE, BANK 2, A5B5: BEQ $A5C5 ;FOUND IT. BIT $C083 WRTCOUNT + 1, READ A5B7 : STA $C080 ;ENABLE FIRM- ENABLE, BANK 2. ;WARE CARD. ENABLE 12K OF EXPAN- A5BA: CMP $E000 SION RAM FOR READING A5BD: BEQ $A5C5 ;FOUND IT. AND WRITING, BANK 2. A5BF: STA $C081 jDISABLE FIRM ;WARE CARD. BIT $C081 WRTCOUNT + 1, READ A5C2: CMP $E000 DISABLE, BANK 2, A5C5: RTS 5-30 Understanding the Apple If the desired language is already selected, no action count, disable the RAM card for writing, select is taken. Otherwise, the language is looked for with bank 2. and enable then disable the RAM card for switching via STA $C080 first and STA $C081 reading. This means that with the RAM card second. installed and DOS connected, initialization of either If a RAM card is installed inSlotO, the comments Applesoft or Integer BASIC via FP. INT, RUN. or look more like this: RESET will select bank 2 and disable writingto the RAM card. Reentering a language, however, does A5B2: CMP $E000 not effect the RAM card configuration at all. For A5B5: BEQ $A5C5 ;FOUND IT, example, "RUNing" an Applesoft program when A5B7: STA $C080 fWRTCOUNT = 0, Applesoft is already active causes no change in the IDISABLE WRITE, status of RAM card read enable, write enable, or ;ENABLE READ, bank selection flip-flops. ;BANK 2. The action of RESET at the RAM card is of par- A5BA: CMP $£000 ticular interest. RESET performs no hardware A5BD: BEQ $A5C5 IFOUND IT. function at the RAM card. The power-up configura- A5BF: STA $C081 fWRTCOUNT = 0, tion of the RAM card is controlled by circuitry on ;N0 EFFECT ON the card which is not associated with the Apple IWRITE ENABLING, system RESET that occurs at power up. The only IDISABLE READ, effect RESET has on the RAM card is through the IBANK 2. RESEThanrilingprogram. If DOS is not connected A5C2: CMP $E000 or some other controlling program is not cognizant of A5C5: RTS the 16K RAM card, pressing RESET wifl do nothing to theRAM card. Apple supports only one RAM card installation, namely; RAM card in Slot 0. Autostart If the desired language is already selected, no action Monitor active, and DOS connected. The RESET is is taken. Otherwise the language is looked for via soft, and any variations from the normal installation storing commands which reset the write enable will require appropriate software support. Table 54 1 6K Rom Card Address Bus Comnrrands. BANK 2 BANK 1 ACTION C080 C088 _ 0*, WRITE DISABLE READ ENABLE WRTCOUNT C084 C08C RC081 RC089 WRTCOUNT = WRTCOUNT + 1* READ DISABLE RC085 RC08D WC081 WC089 WRTCOUNT ^ 0* READ DISABLE WC085 WC08D C082 C08A WRTCOUNT = 0*, WRITE DISABLE READ DISABLE C086 C08E RC08 3 RC08B WRTCOUNT = WRTCOUNT + 1* READ ENABLE RC087 RC08F WC083 WC08B WRTCOUNT ^ 0* READ ENABLE WC087 WC08F Writ UK U) expansian RAM is enabled when WRTCOUNT reaches 2. F RAM in the Apple II 5-31 The 16K RAM card also contains a socket for a RAS' and CAS' to fall during PHASE at the 2316 ROM or 2716 EPROM. To use 2716 EPROM. expansion RAM. It also disables the F8 ROM on one juniper pad must be cut and a second must be the RAM card, soldered. These config'uration pads are labeled 2716 :^. If an address in the $DOOO-$FFFF range is on on the RAM card. The ROM is an F8 ROM, meaning R/W low, and the expansion the address bus. is that it responds to addressing in the $F800-$FFFF RAM is enabled for writing. This also allows rangre. Operation is such that when the expansion RAS' and CAS' to fall at the expansion RAM RAM is disabled, the F8 ROM on the RAM card is during PHASE 0. It also disables the F8 ROM enabled for response to the $F800-SFFFF range. In on the RAM card. other words, when the RAM card is installed, the F8 The 16K RAM card normally mounted only in is ROM on the motherboard is never accessed and may Slot 0. in spite of the fact that the card will operate in as well not be installed. There must, however, be an any slot. Multiple RAM cards or combinations of F8 ROM installed on the RAM card. RAM cards and firmware cards are rare because It is the author's guess that the reason Apple little or no software exists to support such configu- included the ROM socket was as a vehicle for dis- rations. Also, unlike the firmware card, the RAM tributing the Autostart ROM to those persons who card does notutilizetheDMA priority chain to pro- were still using the old Monitor ROM. Addition- vide a fail-safe method of preventing two or more ally, they gave ownersof the "Language System" an cards from trying to steal $DOOO-$FFFF at the easy means of installing their own FS EPROM. same time. As a result, multiple RAM/firmware User beware! Some commercial software won't run card configurations would be susceptible to accid- correctly if anything other than the Autostart Mon- ental simultaneous enabling. The RESET key might itor or old Monitor programs are responding to be of little help in the resulting chaotic situation $F800-$FFFF. This is because some copy protection because RESET does not automatically disable schemes call for performing a checksum on this RAM cards. RESET does disable firmware cards if addressing range to ensure the user has not installed the switch in the back is down. The fact remains that copy busting firmware. If the checksum is incor- use of the RAM card anywhere but in Slot would rect, the program won't run. require very careful software support, probably The INHIBIT' output is the means by which the generated by the owner.* RAM card steals $DOOO-$FFFF addressing. Bring- One last point of detail in the RAM card schematic ing the INHIBIT' iine low disables motherboard is that RAU through RAG are all connected to an un- ROM response to thisaddressrange.The RAM card used LSTTL input. It is the author's assumption that brings the INHIBIT' line low: this is to prevent reflections which might otherwise 1. If an address in the $F800-aFFFF range is on be caused by transmitting RAM address informa- the address bus. tion via a DIP jumper to nine RAM chips on a periph- 2. If an address in the $DOOO-$FFFF range is on eral card. the address bus. R/W'ishigh. and the expansion *Miilli|)li' RAM card configurations are the subject of an Appli- RAM is enabled for reading. This also allows cation Note at the end of this chapter. 5-32 Understanding the Apple II HARDWARE APPLICATION UPGRADING APPLES TO 48K RAM There has been a dramatic decrease in the price of RAS' falls, the access is ROW-IimHed. CAS' falls 16K dynamic RAM chips since the Apple was first 140 nanoseconds after RAS' in the Apple, which is introduced. It is the author's perception that the not soon enough. ,so Apple RAM access is COLUMN- prime cause of this price reduction has been compe- limited. In other words, the TCAC specification is tition from Japanese manufacturers. Also, the 16K what determines the acceptability of a RAM chip RAM chip is becoming obsolete as a mass memory for u.se in the Apple. device. Early Apple owners paid hundreds of dol- In the Apple. RAM data output is latched by the lars to achieve the Apple's 48K capability. In 1980. rising edge of RAS', so TCAC on Apple RAMchips the author saved $;^00 from the price of his Apple by should be less than 178 nanoseconds to insure data is buyinjrthe 16K version, takin^atrainto Tokyo, and valid before RAS' rises. This criteria is met on 250 payinjf $(iO for the remaining ;^2K of RAM chips. In nanosecond or faster RAM (TCAC = 165 nanosec- 1 981. the advertised price in U.S. magazines for sets onds), but is not met by :?00 nanosecond RAM. Since of eig-ht lf>K dynamic RAM chips was $25. The TCAC is the critical specification, you can operate December. 1982 issue of BYTE magazine carried the Apple with 250 nanosecond RAM. The author's an ad for 200 nanosecond, IGK chip.s at$H) per setof computer was supplied with NEC 41(i-2 (200 nsec) eight. The point is this: you should have 48K of RAM chips. The computer was upgraded to 48K with in your Apple II. and you shouldn't pay very much Fujitsu 811«N (250 n.sec) chips. money to put it there. 'Table 5.5 is a list of manufacturer's part numbers The Apple supports 48K of motherboard RAM of 41 1() compatible 16K dynamic RAM chips. If you fully. Plug the chi!)s into the sockets and away it do not have a good discount supfdier. the best place goes. When changing' from 4K to 16K chips in older to get RAM is through the mail. It is recommended Apples, it will be necessary to buy or build 16K that you pcru.se microcomputer magazines to find a configuration plugs. You can modify old 4K plugs to hardware supplier you can live with. Strictly as a 16K plugs or build IfiK plugs out of IC sockets. The convenience to readers of this book, a list is included schematic of the IfiK jumper plug can be seen in here of some suppliers advertising 41 Ifi type RAM F'igure5.10. Inmost instances, coming up with 16K chips forunder$l5pereight in the December, 1982 jumper plugs won't be necessary because a I6K issue of BYTE Magazine. No endorsement of these Apple will come jumpered for 48K. Newer Apples suppliers is intended. The reader may wish to con- have no RAM jumpers, but are hard-wired for 16K tact one of them to acquire ordering information. chips. DoKay Computer Products Inc. The only remaining questions are what chips to :i25okeiIerSt. #9 buy and where to buy them. What tobuyis4116 type Santa Clara. Ca. 95050 16K RAM chips that are fast enough tooperate in the 1-800-5:^8-8800 Apple, which istosay. not exactly greased lightning, 1-800^848-8008 (Ca.) RAM chips are usually referred to as 250 nanosec- l-408-988-0(>97 ond RAM, or :^00 nanosecond RAM or something similar. This time is the read response time of the Jameeo Electronics l.'^55 Shorcway Road chip. There are two important read response times Belmont. Ca. 94002 in dynamic RAM— the maximum time after RAS' 1-415-592-8097 falls before data becomes valid (TRAC). and the maximum time after CAS' before the data becomes JDR Microdevices Inc. valid (TCACl, The TRAC period is usually the way 1224 S. Baseom Avenue the chips are referred to. Read data from 250 nano- San Jose. Ca. 95128 second RAM becomes valid a maximum of 250 1-800-588-5000 nanoseconds after RAS' falls, except not in the l-800-(ifi2-6279(Ca.) Apple, You see. when CAS' falls pretty soon after 1-408-995-5480 RAM in the Apple II 5-33 Tables^ i6K Dynamic RAM Chips. MANUFACTURER 120 nsec 150 nsec 200 nsec 250 nsec AMD 9016F 9016E 9016D Fairchild F4116-2 F4116-3 f4 116-4 Fujitsu MB8U6H MB8116E MB8116N Hitachi HM4716A-1 HM4716A-2 HM4716-3 HM4716A-4 Intel P2117-2 P2117-3 P2 117-4 Intersil IM4 116-2 IM4116-3 IM41164 ITT ITT4 116-2 ITT4 116-3 ITT4 116-4 Mitsubishi M5K4116-2 M5K4 116-3 M5K4116-4 Mostek MK4116-2 MK4116-3 MK4 116-4 Motorola MCM4116B-15 MCM4116B-20 MCM4116B-25 National MM52904 MM5290-2 MM5290-3 MM5290-4 NEC Micro UPD4I6-5 UPD416-3 UPD416-2 UPD416-1 Oki MSM3716-2 MSM3716-3 MSM3716'4 Panasonic MN4116 Siemens HYB4116-3 HYB4116-4 TI TMS4n6-15 -TMS4 116-20 TMS4 116-25 Toshiba TMM416-2 TMM416-3 TMM416-4 ZilOR Z6166-2 Z6 166-3 Z6166-4 Quest Electronics Solid State Sales P.O. Box 44;J()X P.O. Box 74 B Santa Clara. Ca. 95054 Sommerville, Ma. 02143 1-800-538-8196 (orders only) 1-800-343-5230 (orders only) 1-408-988-1640 1-617-547-7053 5-34 Understanding the Apple II HARDWARE APPLICATION BANK SWITCHING THE MOTHERBOARD RAM The Apple design includes a very versatile char- (short because F2 is close to the peripheral slots). acteristic in that the motherboard ROM can be The LS139 is plugged into a socket on the peripheral inhibited from the peripheral slots. This feature card where it performs the same functions it did on enables the design of very important peripherals the motherboard except that the outputs are enabled such as ROM and RAM expansion cards which work by bank switching logic. bystealinRROMaddressingr($D000-$FFFF).With Figure 5-16 shows the basic idea of how to bank thecomingof the64K RAM chip, wenow have64K, switch motherboard RAM. Only one half of the 128K. and bigprer Apple RAM expansion cards, LS139 is used and CAS' is gated by three separate divided up into 12K banks which are switched in tow level AND gates. This is very important, because and out and addressed at $DOOO-$FFFF with moth- the scheme causes no further delay in CAS' propa- erboard ROM disabled. gation than is normally tolerated in motherboard There is a trick, though, which the RAM card RAM operation. This will ensure correct operation, designers haven't picked up. The trick is that it is even with 250 nanosecond RAM. The AND gate quite possible and easy to disable motherboard propagation delay will actually be about 10 nano- RAM in the Apple. By disable, it is meant that you seconds less than in normal operation, making the can isolate the motherboard RAM from the data bus 6502 motherboard write data setup slightly more and aceessother devices at addresses $OO0O-$BFFF. critical. However, you would probably have to put a This opens up the possibility of peripheral card 6502 in a freezer to make it take 200 nanoseconds to desigrns with RAM or ROM switched in banks of up set up write data after its PHASE 2 clock rises. tofi4K. CAS' could be routed through an extra logic device Disabling of motherboard RAM is easy, because to completely equalize CAS' propagation time to the functions of Rating CAS' to the RAM chips and that of normal operation. gating RAM output data to the data bus are both The 64 K bank switched RAM could be controlled controlled from one chip, F2. This chip is the LSl,'i9 by any number of schemes. The most naturally im- decoder which decodes address bits to generate plemented scheme %vould be a 192K RAM card, giv- RAM SELECT' and CAS' for rows C, D. and E (see ing the expanded Apple a 256K byte capability in Figure 5.10). Consider what would happen if all four banks. The screen display is always stored outputs of F2 were forced high during PHASE 0, in motherboard RAM and special care would be regardless of the address bus. First, CAS' would not required for bank switching PAGE and PAGE 1, be generated for any RAM row. so no data transfer Expansion RAM is not the only possible applica- would take place to or from motherboard RAM. tion of the capability to inhibit motherboard RAM. Second, RAM SELECT' would stay high unless For example, a fairly inexpensive design could be $CO0X was being addressed, so latched data would built with the Apple DOS in EPROM, operating at not be gated to the data bus, even if the MPU was its normal address. Forabout$50in parts you could calling out a RAM address. Thus the data bus is leave behind forever the process of booting the DOS floating and available for control from a peripheral and the necessity of wasting disk spaceon the Apple card. Third, the scanner access is not interrupted, DOS. That would be a pretty nice improvement to because the F2 outputs are forced only during the disk controller. PHASE 0. So motherboard RAM is still refreshed The design suggestions in this Application Note as it is scanned for video output. are put forth in hopes of encouraging hardware The way to implement this is to pull the LSL^9 manufacturers to develop this previously overlooked from the F2 socket and connect the socket to the Apple capability. peripheral card via a short 16-line DIP jumper RAM in the Apple II 5-35 MOTHERBOARD — RAM ENABLE PHASE — 1 r> 5V 1 n Ea VSS row C 12 Oa YO y row D 11 Y1 D- 13 row E 10 Y2 3 16 PIN 74LS139 CAS' DIP SOCKET CAS' C 4 ^T> JUMPERED TO CAS'D 5 F2 CAS' E 5 GND -J¥ Figure 5.1 6 SchemaMc: Bank Switching Motherboard RAM. 5-36 Understanding the Apple SOFTWARE APPLICATION READING VIDEO DATA FROM A PROGRAM In the October, 1982 issue of SOFTAlK maga- $C080-$C7FF I/O Control (use if slot is zine, Bob Bishop reported an excitinR- discovery. empty) Any time a 6502 program reads an address from $CFFF Expansion ROM Disable which there is no data response, the video data from Of all these choices, the screen switches stand out as the previous scanner access is read by the MPU. Mr. having no chance of interfering with the operation Bishopmade a bij?mistakepublishine:this informa- ofsome device. Thescreen switches will normally be tion. He could have made a living making bets with used, because the task of polling and switchingcan Apple experts that you can sync an unmodified then be combined. Also, the polling loop is self doc- A pple to the video scan under program control. He'd umenting to investigators of the program. In the have made about a thousand dollars per sucker, rare instance that one of the screen switches will not Who would have thought that the dataon the floating do for video polling, the annunciators, the keyboard data bus would remain valid for over half a micro- strobe reset, the .$C040 strobe, and the cassette out- second. The article "Have an Apple Split" contains put addresses are likely choices. programmingexamples and is highly recommended Figure 5,17 is a diagram designed to aid the pro- reading. It is partly because of "Have an Apple grammer in selecting locations for syncing flags. It Split" that this book has endeavored to present should be used in conjunction with the memory extensive memory scanning maps for programmer maps from earlier sections of this chapter. From reference. this diagram, one can quickly see the prospects for One reason for syncing a program to the video successful syncing at a given point in a given mode. scan is to create displays that are a mixture of the The most obvious feature discerned from Figure normal Apple screen modes. For example, if you 5.17 is that HBL scanned memory in HIRES over- switch to HIRES before line 5 of every vertical scan laps HBL' scanned memory, butthe HBLand HBL' and switch to LORES before line lOof every vertical scanned memory areas of TEXT/LORES are dis- scan, you will have a stable combination of HIRES tinct. This means that different problems will ari.se and LORES graphics displayed on the screen. when choosing flags for these two different memory The method of read ng video sync from a program i scanning modes. is to set up flags in scanned memory at the point of A problem with HIRES is that most memory gets the television scan where the program needs to take scanned more than once every vertical scan. Only the an action, such asswitchingfrom LORES to HIRES. first 16 bytes of the SECOND 40 and the first 16 Then the program polls a nonresponding address bytes of the THIRD 40 are scanned just once per ver- such as the cassette output port until it detects the tical frame. This makes it more difficult to uniquely flag. The choice of flags and their location in flag a scan position. In TEXT/LORES, memory is memory will be dictated by the application. more uniquely scanned with only a partial overlap Programming a combination display requires the between the area scanned during VBL and during normal programmer's imagination to conceive of the top of the screen. However, one must deal with the display. Additionally, a thorough grasp of mem- the fact that critical non-displayed memory areas ory scanning details is a necessity. The purpose of are scanned. HBL scanned memory is in an area this application note is to provide some discussion of normally taken up by Applesoft programs or Integer techniques that might be used. BASIC variables, and the undisplayed eight bytes For starters, here is a list of addresses from which at the end of each 128 byte segment are used by the video data can be read: DOS for critical disk information (like active slot $COIX KEYBOARD STROBE FF Reset number). $C02X Cassette Output The following is a typical video polling loop: $C03X Speaker Output $C04X C04n STROBE' $C05X Screen Switches and Annun- POLLIT CMP $C050 ;FLAG VALUE ciator Outputs ;IN ACCUMU- $C06X Serial Inputs (D0-D6 only) LATOR, $C07X Timer IVigger BNE POLLIT RAM in the Apple II 5-37 BEGIN HBL SCAN > BEGIN HBL' SCAN FIRST AO SECOND 40 THIflQ40 A ^^ A "^V^ SCREEN LINES 1 TOP 0-63 > ~ B^^ SCREEN LINES r. Ir^A MIDDLE 6^-127 > ' HIRES SCREEN LINES BOTTOM 12B-191 i lilHiii VBl LINES 192261 ^^^^^1 SCREEN UNES TOP 0-63 1 SCREEN UNES TEXT/ MIDDLE S4-127 1 LORES SCREEN LINES +$1000 BOTTOM 128-191 r VBL LINES 192-261 ^^^H SCREEN LINES TOP 0-63 > SCREEN MIDOLE LINES 64-127 ^ TEXT/ SCREEN BOTTOM VBL LINES 128-191 LINES 192-261 ^^^^^H ^ mk 1 ^^H LORES Rgure5.17 Screen Memory Scanning. The loop takes seven clockpulses to execute and thus blank the other HBL scanned memory. Then poll for establishes one criteria for a screen flag. It must the flag as follows: occupy a minimum of seven adjacent scanned bytes of memory or six bytes if one of the bytes is the first POLLIT CMP $C051 ;ACCUMULATOR byte of a HBL scan. The first byte of a HBL scan is ;IS $5B scanned twice so six bytes here is the same as seven BNE POLLIT elsewhere. NOP Here isone way to flag PAGE 1 of TEXT memory CMP $C051 at the beginning of line 12 (the thirteenth line from BNE POLLIT the top if the first line is line 0). Store the value $5B at locations $1610-$1627. Figure 5.6 shows this is HBL scanned memory before line 12, and Figure This loop will not be exited without finding two $5 Bs 5.17 shows that this memory will only be scanned separated by eight bytes. This excludes accidentally once per vertical scan. $5B is the ASCII value of a syncing on anything in the UNUSED 8 and solves flashing left bracket which is very unlikely to be the problem without messing up the memory loca- found in text memory. It may be found in the tions used in disk I/O. Any Applesoft program UNUSED 8 or in other HBL scanned memory, beginning at $800 and extending beyond $140F is which creates a problem. One way to solve it is to clobbered. 5-38 Understanding the Apple II It is not necessary to uniquely flag a scan position. conjunction with timed execution loops. There It is only necessary that there is no interference in are 65 cycles in a horizontal scan— 25 cycles of detecting' a scan flag between the present scan posi- HBL and 40 cycles of HBL'. There are 262 tion and the flagged scan position. For example, — horizontal scans in a vertical scan 64 in each assume we switched from HIRES to LORES at the third of the display screen and 70 during VBL. middle of the display screen and we wish to detect When a group of flagged bytes is located, it is the beginning of VBL. A flag at $1460 through then possible to find a precise byte in the group $1477 will serve this purpose nicely. Even though by slewing backwards in 1 7029 cycle loops until parts of this memory are also scanned at the top of the first flagged byte is found. 17031 cycle loops the screen, the next time they are scanned is during can be used to slew forwards. HBL, before VBL. There Is no interference between 7. The first byte scanned during HBL is scanned the present location and the detection point. twice in a row. In TEXT/LORES, every memory Mr. Bishop showed an interesting flagging tech- line is scanned eight times in a row. except the nique in his 50F7!,4L/f article. He flags the middle lastlineofVBLis scanned 14 times. In HIRES. of the TEXT/LORES display area u-ith a string of every memory line is scanned once, but lines $EOs. He uses this to switch from TEXT to LORES. 250-255 are rescanned after line 255 (250 is These $E()sare printed as spaces on the text screen same a.s 256, 251 is same as 257, etc.). and as a row of black blocks and a row of aqua blocks 8. Switching rapidly between GRAPHICS and in LORES. By detecting this row of $EOs from TEXT mode will cause many televisions to lose TEXT mode then switching to LORES mode for the color sync. This is a factor of alignment and lower part of the screen, the program effortlessly response of the .3.58 MHz oscillator inside the transits from an empty text line to a LORES display television. Because of this unpredictability from with an upper aqua border. The program is short TV to TV. it is not possible to say what percent- and simple and illustrates that programmingmixed age of the time a program can leave the Apple in screen displays is a bit of an art form. TEXT mode and still hope to maintain color The further possible flagging techniques have not sync. Commercial programmers could be well all been dreamed up yet. Here are some related advised tokeepat least a 50% GRAPHICS mode ideas and facts: to TEXT mode ratio in their products if color stability is important. 1. Switching modes during HBL or VBL elimi- nates the unsightly display of switch points. 9. A very heavily loaded data bus may not reliably store video data long enough to be read by the This can be accomplished by flagging VBL or HBL or by flagging a display area and waiting MPU. Apparently, some commercially avail- for HBL or VBL with timed execution loops. able peripheral cards cause this condition when 2. The UNUSED 8 is the only undisplayed area of plugged in. Bewarel HIRES available for flagging. It is scanned Figures 5. 18 and 5. 19 are example programs that during HBL before the top third of the display will create a mixed display in which all the text on and just after HBL during VBL. The undis- the screen except the bottom line is underlined. played eight is of minimal use in flagging PAGE NORMAL. INVERSE, and FLASHING text are 1 of TEXT/LORES because of interference all underlined. The program works by setting up a with the DOS. LORES map of PAGE 1 text in PAGE 2. Then the 3. Bit 7 of HIRES may be used as a flag and screen mode is switched to LORES PAGE 2 for the cheeked with the BIT instruction. This is one top of every text line except line 0. then back to way offlagging the displayed HIRES area if bit TEXT PAGE 1 for the next seven lines. 7 isn't critical for color or positioning. Figure 5.18 is an Integer BASIC program which 4. Bit 7 is a good TEXT flag if there is no inverse sets up the PAGE 2 map and flags HBL scanned video on the screen. Other likely TEXT flags memory for both PAGE 1 and PAGE 2. The process are flashing ASCII, control ASCII, lowercase is pretty slow in BASIC, but this program is ASCII, and ASCII of characters not supported included for illustration and BASIC is easy to fol- by the Apple keyboard. low. Just give the program about thirty seconds to 5. When considering LORES flags in displayed work. Integer BASIC is used because Integer is very areas, bitsO-li control the upper block, and bits easy to work around when modifying low memory 4-7 control the lower block, just above $800. The actual screen splitting is done 6. The video polling method works very well in by the assembly language program in Figure 5.19. RAM in the Apple II 5-39 1 REM 2 REM 3 REM CALL UMDERLINE 4 REM 5 REM 6 REM FIRST MOVE INTEGER LOW POINTERS UP TO $1C40. 7 REM 8 REM 10 POKE 74,64: POKE 75,28: POKE 204,64: POKE 205,28 20 PRINT "BLOAD UNDERLINE OBJ0" . 22 POKE -16304,0: POKE -16299,0: POKE -16298,0: REM LOOK AT LORES PAGE 2, 25 REM 26 REM 27 REM NOW FILL PAGE 2 WITH THE UNDERLINES FOR THE CURRENT TEXT DISPLAY, 28 REM 29 REM 30 FOR P2=2048 TO 2176: POKE P2,0: NEXT P2 REM BLANK TOP LIME OF PAGE 2 : 40 FOR Pl=1024 TO 1919 : P2=Pl+ 11 52 GOSUB 160 : 45 NEXT Pi 50 FOR Pl=1920 TO 1999 : P2=P1+168 GOSUB 160 : 55 NEXT PI 60 REM 61 REM 62 REM NOW FLAG HBL SCANNED MEMORY WITH "S5B"S. 63 REM 65 REM 70 FOR A=0 TO 1920 STEP 128: FOR 8=0 TO 23 75 FLAG=0: IF B<6 THEN FLAG=91: REM 91 IS FLASHING LEFT BRACKEET 80 POKE 5136+A+B,FLAG: REM HBL BEFORE MIDDLE SCRBRN - FLAG 90 POKE 5176+A+B,FLAG: REM HBL BEFORE BOTTOM SCREEN = FLAG 100 NEXT B 110 FOR B=0 TO 31 115 FLAG=0: IF B<14 THEN FLAG=91: REM 91 IS FLASHING LEFT BRACKET 120 POKE 5216+A+B,FLAG: REM HBL BEFORE VBL AND TOP SCREEN = FLAG 130 NEXT B: NEXT A 140 CALL 7168: REM GO SPLIT THE SCREEN 150 END 155 REM 156 REM COLOR = OR 1 OR 15 157 REM 160 T= PEEK {P1):C0LR=1: REM UNDERLINE COLOR = 1 I 165 IF T''32 THEN C0LR=15: REM INVERSE SPACE? 170 IF T=96 OR T=160 OR T=224 THEN COLR=0: REM SPACE? 180 POKE P2,C0LR: RETURN Hgure 5.18 Integer BASIC Listing; Underline Program. The difficult part about a program of this nature middle and HBL before screen bottom. All other isdesigningaflaggingmethod. UNDERLINE uses HBL scanned bytes are cleared. Since the first byte string's of $5Bs as flags stored in the HBL areas. $5B of HBL scanned memory is driven out twice, this is the code for a flashing left bracket, which can flagging method results in seven $5Bs being driven safely be said to rarely be printed on the TEXT out every HBL before display and fifteen $5Bs being screen. A string of 14 $5Bs is stored beginning at driven out at HBL before VBL. HBL before VBL. Note from Figure 5,17 that this Here's the scheme for switching. First, wait for also stores six $5Bs in HBL before screen top. Addi- VBL. HBL before VBL is the only area which will tionally, six $5Bs are stored in HBL before screen respond to two consecutive polls with $5B. Once the 5^0 Understanding the Apple II SOURCE FILE: UNDERLINE 0000 ******* ******************************************* -j_ 0000 2 * * 0000 3 * * 0000 4 * UNDERLINE TEXT * 0000 5 * * 0000 6 * BY JIM SATHER * 0000 7 * * 0000 8 * 1/4/83 * 0000 9 * 0000 L0 * * 0000 11 ******* ******************************************* 0000 12 * 0000 13 C050 14 GRAPHIX EOU ?C050 C051 15 TEXT EQU $C051 C052 16 NOMIX EQU $C052 CQ54 17 PAG El EQU SC054 C055 18 PAGE2 EQU SC055 FCA8 19 WAIT EQU $FCAR 0000 20 * 0000 21 * 0000 22 * NEXT OBJECT FILE NAM E IS UNDERLINE. OBJ0 1C00: 23 ORG SIC00 1C00:8D 52 C0 24 DOSCRN STA NOMIX 1C03:8D 54 C0 25 STA PAGEl 1C06 :A9 5B 26 LDA #$5B 1C08 :CD 51 C0 27 SCRNLP CMP TEXT LOOK FOR STRING OF 15 "$5B"S 1C0B:D0 FB 28 BNE SCRNLP 1C0D:EA 29 NOP 1C0E:CD 51 C0 30 CMP TEXT 1C11:D0 31 BNE SCRNLP 1C13:A9 28 32 LDA #$28 GOT VBL 1C15:20 A8 FC 33 JSR WAIT WAIT 4553 CYCLES 1C18 :A9 5B 34 LDA #558 1C1A:A0 17 35 LDY #23 DO 23 LINES 1C1C:A2 08 36 LDX #8 1C1E:D0 02 37 BNE TEXTLP 1C20: 38 * 1C20; 39 * 1C20:A2 07 40 DOLINE LDX #7 7 TEXT LINES FOR 1 LINE OF GRAPHICS 1C22:CD 51 C0 41 TEXTLP CMP TEXT 1C25:D0 FB 42 BNE TEXTLP 1C27:CA 43 DEX GOT HBL 1C28:D0 F8 44 BNE TEXTLP 1C2A:8D 55 C0 45 STA PAGE2 SWITCH TO LORES 1C2D:CD 50 C0 46 LORESLP CMP GRAPHIX 1C30:D0 FB 47 BNE LORESLP 1C32:8D 54 C0 48 STA PAGEl GOT HBL 1C35:8D 51 C0 49 STA TEXT 1C38:88 50 DEY 1C39:D0 E5 51 BNE DOLINE 1C3B:F0 CB 52 BEQ SCRNLP *** SUCCESSFUL ASSEMBLY: NO ERRORS RgurQ 5.1 9 Auembler Listing: Underline Program. RAM in the Apple U 5-41 first line of VBL is located, wait 4553 cycles. This is BASIC program simply checks the PAGE 1 display a ball park fig-ure which waits until after HBL of the memory for space or no space, then maps corre- first displayed line. Now that the scan is past VBL, sponding LORES blocks into the adjacent line of Figure 5. 17 shows that there is no further possibility PAGE 2 memory. The bottom line of text is not of reading $5B in polling loops before the next VBL, underlined because there is no adjacent lower line to except that $5B will be read once within the first switch to LORES. seven bytes of every HBL. This creates a flagged With screen memory fully mapped, the task of the situation in which HBL can be detected before any screen splitting program is reduced to finding the displayed line. top of the screen precisely, then switching to LORES The given task is to underline the current PAGE 1 PAGE 2 for one line every eighth line. It's easy once TEXT display. The ground work for doing this is the flags are properly set. laid in the BASIC program. First understand that the top line of every text character pattern is blank. S ince the Apple is in TEXT mode most of the time This creates the space between the text lines. To during UNDERLINE, probably any television will underline the character at position 1 of line 0. you lose color sync and the underline will be white map a LORES block into the top of position 1 of line rather than colored. Readers may wish to experi- 1 inPAGE2. Then for the first scan of text, line 1 you ment with colors by changing lines 160 through 180 switch to GRAPHICS PAGE 2. During HBL of the of the BASIC program. Just don't POKE 91 into next scan, you switch back to TEXT PAGE 1. This LORE S displayed memory. 91 ($5B) is our flag, and creates an underline appearance for line 0. The it is reserved only for undisplayed memory. 5-42 Understanding the Apple HARDWARE APPLICATION MULTIPLE RAM CARD CONFIGURATIONS Installing a 16K RAM card in Slot makes a nice A second obstacle to multiple RAM card configu- improveTnent to the Apple. The capability of loading rations is loading on the RA0-RA6 multiplexed programs to high memory is inarguably desirable. RAM address lines. These lines drive 24 RAM chips But a natural question arises as to whether it is on the motherboard plus 1000 ohm pull-up and pull- possible to install more than one RAM card in an down resistors. Additionally, RA0-RA5 drive eight Apple and use the second card for auxiliary data or RAM chips and one LSTTL load on every RAM card program storage. The answer to this question is a installed, and RA06 drives two LSTTL loads on qualified "yes." It is possible to use more than one every RAM card installed. Presumably, this loading 16K RAM card in the Apple, but certain obstacles places a practical limitation on the number of RAM must be overcome. This Application Note discusses cards which can be installed in an Appte. I have the nature of the obstacles and offers some ways to made no attempt to define this limit through exper- overcome them. imentation, so I can only suggest that multipleRAM The first obstacle is the nature of the ROM ena- card users should be on the lookout for signs of bling circuitry on the RAM card. If the expansion unreliabletransferofRAM data. Symptoms of such RAM is not enabled on a RAM card, the ROM on the problems would quite possibly vary with operating card will respond to $F800-$FFPF addressing- temperature. period. There is no way to inhibitthis response with- If RA0-RA6 prove to be overloaded in your Apple, out modifying the RAM card. The result is that one trade-off you can consider is to replace the when a RAM card is installed, neither the mother- 74LS153S at CI, Ell, E12, and E13 on the mother- board nor any peripheral card can respond to F8 board with 74S153S (see Figure 5.10). STTL chips addressing. This "I own FS" philosophy of the 16K draw more current than LSTTL chips at their RAM card represents a degradation of the versatil- inputs, but they can drive more circuits connected to ity of the Apple which, fortunately, is easily over- their outputs. The trade-off is that changing to come. Just perform the following simple modifi- 74Sl53s will greatly increase the amount of RAM cation to each RAM card you want to install with chips that RA0-RA6 can drive, but it will cause other F8 stealing cards.* some increase of the load on the address bus. The 1. Remove the F8 ROM from the RAM card. desirability of this trade-off must be evaluated for 2. Remove the 74LS20 IC from the A5 socket of the your total peripheral card configuration. RAM card. The final obstacle to multiple RAM card configu- rations is that all software support must be gener- 3. Bend pin 6 of the 74LS20 IC so it will not go into the socket and reinstall the 74LS20 in the A5 ated by the user. This will, of course, be the most socket. time consuming obstacle to overcome. Important 4. Place the RAM card, component side down, on points to consider in your software are handling of your work table. Solder a bare wire jumper your configuration after a RESET, patching DOS between pins 4 and 5 of the A4 socket (A4 holds a and Pascal to support your configuration, and fail- safe software which avoids enabling two different 74LS09). 5. Install your primary F8 ROM in the F8 socketof RAM cards for reading. One programming trick is the motherboard. Leave the ROM socket on the to enable two RAM cards for writing simultane- 16K RAM card empty. ously when you want to fill their memories with identical data. Both RAM cards will accept the data The original versatility of your Apple is restored from a single storing instruction to the $D000- by this modification. The RAM card responds to F8 $FFFF range. addressing only when enabled for reading or writ- RAM When installing more than one card, a ing to RAM. Any RAM card, firmware card, or separate DIP jumper must be connected from a other peripheral card can steal access to F8 address- motherboard RAM socket to each RAM card. Just ing by pulling the INHIBIT' line low. If INHIBIT' select any convenient RAM socket for each RAM is high, the motherboard F8 ROM will respond to F8 card and move the RAM chip from that socket to the addressing. empty socket on the RAM card. The motherboard socket which you choose makes no difference because Please read the NOTE OF CAUTION at the beginning of the the signals which the RAM card uses (RAS' and book before making any modification to your hardware. RA0-RA6) are identical on every socket. s=a chapter 6 nooooa ROM in the Apple II Non-erasable, random access, read only memo- The sophistication of the ROM chips makes their ries have taken many forms in the history of digital connections in the Apple simple and easy to under- computers. From vacuum tubes to diodes to small stand. Nevertheless, the topic of ROM is involved scale integration to large scale integration, there enough to merit its own chapter. Since the hardware has always been a need for the general purpose connections are simple, let that be the starting point. computer to have a resident program ready to tel it 1 what to do at turn on With the com ing of large read . ROM HARDWARE only memories on single chips, the scope of pro- grams contained in ROM in general purpose com- The Apple II firmware is programmed into six puters has expanded greatly. Placing a BASIC 2316B type ROMs. The 2316B is a 24 pin. 2048 interpreter in ROM was a significant event in the byte, NMOS ROM with three programmable chip development of personal computers. selects and a 450 nanosecond access time. NMOS The Apple II design supports 12,288 bytes of stands for Negative channel, Metal Oxide Silicon motherboard ROM, addressed from $D000 through construction. These technical terms will help you if $FFFF. Additionally, several provisions exist for you look for the equivalent chip in a manufacturer's controlling the Apple via programs in ROM on data book. Look under NMOS, 2048x8 ROMS. peripheral cards. These include addressing periph- The 2316B goes by several different manufactur- eral ROM using a slot's assigned address area er's part numbers. This book refers to it as the 2316B $COnX DEVICE SELECT' range and its (its because that seems to be the most common identify- $CnXX I/O SELECT' range), addressing peripheral ing number. The Apple 11 Reference Manual refers ROM using the expansion ROM addresses ($C800- to the ROM as 9316B, which is the part number used $CFFF), and inhibiting motherboard ROM and by General Instruments for 2316B compatible ROM. stealing addresses $DOOO-$FFFF. All told, the Perhaps General Instruments was the ROM supplier Apple computer has a very versatile capability for when the Apple II was first introduced. Al! the operating under control of programs stored in Apples that the author has inspected have Synertek ROM, ROMs and the Synertek part number is 2316B. In 6-2 Understanding the Apple any case, the 2316B, 9316B, and all other 2316B during PHASE 0. The $C000-$C7FF signal is used compatible ROMs have the same characteristics. to enable I/O decoding as described in Chapter 7 and These ROMs are programmed by the manufac- illustrated in Figure 7.2. The $C800-CFFF signal is turer to the specifications of Apple Computer Inc. the I/O STROBE', which is tied to pin 20 of all Once the chip is built, only a casualty will cause peripheral slots. This signal enables the "seventh alteration of the stored data. In addition to specify- ROM chip" which can be installed on any peripheral ing the data to be contained in the ROM. Apple also card or several peripheral cards. The $C800-$CFFF specifies which of the three chip select inputs are addressing is shared by all peripheral cards under a active high and which are active low. This is why the protocol described in the next section. Within this chip selects are said to be programmable. protocol, any card can activate response to addresses The ROM connections in the Apple are shown in $C800-,$CFFF, thus supplying its own 2K program Figure 6.1. The ROM chips are wired in the way in firmware. The I/O STROBE' at pin 20 is the the most microcomputer hardware is wired, with repe- "C8" enable term for any card on which the "seventh titious, identical wiri ng going toallsixchips.lt takes ROM", or "expansion ROM", is active. eleven lines to address 2048 bytes and the eleven An interestingfeatureof the ROM connections in address inputs to the ROM chips are connected di- rectly to AO-AIO of the address bus. The ei^ht tri- ROM is not gated off by R/W', the Apple II is that This means that if a program writes to a ROM state data outputs are connected directly to the data address, the enabled ROM will compete with the bus. These address and data connections are pleas- "^ antly simple when contrasted to RAM connections. MPU bidirectional busdriverforcontrolof thedata bus. The possibility of "bus fights" like this is some- The only remaining connectionsare power supply thing microcomputer engineers try very carefully connections{+5VandGROUND)andthechipselect to eliminate from their designs. At least three bad inputs. The chip selects control the tri-state data things can happen in a "bus fight": hardware can be outputs, enabling the outputs when all three chip damaged; data transfer on the bus can be unreliable; selects are active. In other words, for an Apple ROM and current spikes created on the power supply and chip to take control of the data bus, its CSl' and ground lines by the "bus fight" can interfere with CS3' inputs must be low, and its CS2 input must be the operation of other circuits. It appears that none high. The CS2 input of all six ROM chips is tied to of these ill effects occurs when a program causes the the wire-OR INHIBIT' signal from pin 32 of the peripheral slots. This reveals the power of the MPU to write to aROM address in the Apple. INHIBIT' line. If any peripheral card pulls it low, The ICs involved are the 2316B ROM and the all motherboard ROM is isolated from the data bus. 8T28(8304 in the RFI Revision) bidirectional driver. This means that any peripheral can respond to When the 2316B and an 8T28 or 8304 fight for con- addresses ^DOOO-$FFFF in any way it wants when trol of a line, the 2316B loses. Surprisingly, even it has pulled INHIBIT' low. The only function of when the 231GB is trying to pull a line low, an 8T28 ROM is to put data on the data bus. When it is or 8304 can pull the line above 2 Volts. The current isolated from the data bus, ROM may as well not he drawn during this bus fight is not sufficient to dam- installed. age the 2316B, 8T28, or 8304, so hardware damage The CSl' and CS,3' inputs of each ROM chip are is not a likely result. The second possible ill effect, tied together and connected to one of six address unreliable data transfer on the bus, is not a factor. decoded ROM ENABLE' signals. These six signals Remember we are writing to ROM. an unusual pro- are decoded directly from the address bus during gramming action which is normally done only by PHASE and divide ROM addressing up into six accident (as when the programmer tries to write to a equal parts ($DOO0-$D7FF, $D800-$DFFF, etc.). 16K RAM card but neglects to enable the RAM Decoding of signals from a multiline input is a very card). Data transfer does not exist when the MPU common problem in digital design, so general pur- writes to ROM. because no device on the data bus is pose ICs exist which are tailor made to the task. configured to receive data. The third possible ill ef- Detecting the address range of each ROM chip and fect, interference caused by current spikes, appears generating the data bus management signals for not to occur. I ran a test program for twelve straight those six chips is accomplished by a single 74LS1?58 hours on my Revision 3 Apple. The program contin- decoder and an AND gate. uously wrote the complement of the data at $E000 to Two other outputs from the LS138 represent the that same address. No discernable operational mal- $C000-$C7FF and $C800-$CFFF address ranges functions occurred during this experiment. ROM in the Apple II 6-3 PERIPHERAL SLOTS ANY PERIPHERAL SLOT CAN INHIBIT MOTHERBOARD ROM BY PULLING PIN 32 LOW ADDRESS BUS INHIBIT' DATA BUS 18 f24 CS2 VCC 19 A10 22 A9 17_ D7 23 23168 A8 ROM 06 11. A7 00 D8 15_ D5 A6 EO IB D4 li. AS FO FB 03 IL A4 D2 IL A3 io_ 01 A2 9 DO A1 AO csr CS3' ^jT 20 721 5V VCC i 6 All F8 THERE ARE SIX ROM A Y7P \ ENABLE' SIGNALS, ONE A12 »S- FO FOR EACH ROM SOCKET B Y6 A13 ,10 E8 V5 A14 C J1 EO >-^ Y4 E> :> A15 E3 J2 D8 F1Z Y3 74LS03 74LS13S DECODER Y2 ^13 M J I/O STROBE' .14 C8 f—^E2' Y1 ^-TO PIN 20 OF ALL (3.8) - PERIPHERAL SLOTS PHASE J5 _Cg_^l/0 DECODE ENABLE' 1 YO (7.9} ^SEE FIGURE 7.2 T Figure 6.1 Schematic: ROM In the Apple 6-4 Understanding the Apple Even though there seems to be no real harnn in it, response to the I/O STROBE'. Suppose that the pro- purposefully writing to ROM addresses while the gram driven out at address $CIOO begins with: INHIBIT' line is high is not recommended. The C100: BIT $CFFF outcome of "bus fights" may not always be abso- C103: JMP $C800 lutely predictable, and the Apple designer would have done well to prevent the possibility by connect- On the last cycle of execution of the first instruction, ing R/W to one of the chip selectsof the motherboard response to the I/O STROBE' is deactivated on all ROM. A parallel situation to that of ROM exists with peripheral cards including Slot 1. However, on the first cycle of execution of the second instruction, the motherboard serial inputs. If a program stores data to address $C06X, both the MPU driver (8T28 SCIXX is back on the address bus and I/O STROBE' or 8304) and the serial input multiplexor (74LS251) response is again activated at Slot 1 It is now safe to . attempt to control D7 of the data bus at the same begin execution of programs stored in the "seventh time. As with ROM, purposely writing to the serial ROM" at Slot 1 The . ROM at Slot 2 will not interfere input addresses is not recommended. with Slot 1 access to $C800-$CFFF, because it is designed to ignore the I/O STROBE' after an access to$CFFF. It is possible for a peripheral card to store its THE SEVENTH ROM CHIP $CnXX program and its$C800-$CFFF program on asing!e2K ROM. This is accomplished by enabling As Figure 6.1 shows, the I/O STROBE' signal at pin 20 of the peripheral slots is generated identically the output of the ROM to the data bus when I/O to the six ROM ENABLE' signals. In fact. I/O SELECT' (pin 1) goes low or when I/O STROBE' response is activated and I/O STROBE' (pin 20) STROBE' is the ROM enabling signal for any pe- goes low. If the card is located at Slot 1 the 256 bytes , ripheral card on which $C800-$CFFF is currently at ?C1XX will be identical to the 256 bytes at active. There are no motherboard control signals to the various slots when they $C9XX. The 256 bytes at $C1 XX can be accessed at tell may or may not respond to the I/O STROBE', so Apple Computer any time. The 2048 bytes at $C800-$CFFF can be accessed only when I/O STROBE' response is acti- Inc. decided on the following protocol which cards vated {after a $C1XX access). responding to I/O STROBE' must follow: The "seventh ROM" capability should not be con- 1, When pin 1 (I/O SELECT') or pin 41 (DEVICE fused with the capability to steal addresses $D000- SELECT') goes low, a peripheral card may $FFFF via the INHIBIT' line. The former gives a begin to actively respond to the I/O STROBE' at peripheral card unlimited access to 2048 bytes of pin 20. addressing not used by motherboard devices. The 2. When $CFFF is on the address bus during latter gives a peripheral card access to 12.288 bytes PHASE 0, all peripheral cards must stop re- of addressing at the expense of disabling mother- sponding to the I/O STROBE'. board firmware. ActMS-lly .the Apple IF Reference Mamtai says only to use I/O SELECT' to activate response to the I/O FIRMWARE IN THE APPLE STROBE'. However, Slot shares $C80G-$CFFF The hard features of the Apple ultimately deter- addressing with the other slots and it has no I/O mine its capabilities and limitations. However, the SELECT' input. The only way Slot can activate computer is only as powerful as the program control- response to I/O STROBE' is through its DEVICE ling it at any given moment. Possibly the most im- SELECT' input at pin 41. It should be noted that portant programs ever written for the Apple are the Slot designs which respond to the I/O STROBE' ones stored in the motherboard ROM. These give life are either rare or nonexistent. to the machine and are used so often that we forget An example should clarify how the I/O STROBE' that they are just programs and that operational protocol works. Assume that Slot 1 and Slot 2 have features created by any program can be changed. peripheral cards installed and that both have a The contents of Apple II firmware has been the "seventh ROM" on board. A PR#1 is executed from subject of many writings which this book cannot BASIC which results in 6502 program flow vector- hope to match in a limited space. The goal here is ing to address $C100 for all character output. The just to give an overview of the Apple firmware and to card at Slot 1 responds to $C 1 XX addresses by plac- provide some insight into the importance of the pro- ing a program on the data bus, and by activating grams contained there. The approach is historical. ROM in the Apple II 6-5 was Integer BASIC, the Monitor First, there The Apple was one of the microcomputers which ROM.andsome6502 utilities. These prog-rams were led the transition from a monitor in ROM to BASIC written primarily by Steve Wozniak. thedesij^nerof in ROM as the primary human to machine interface the or iginal Apple computer. This was in the bad old for home computers. However, the Apple II does days before the proliferation of inexpensive disk have an extensive monitor in ROM, and the older drives and before Microsoft Inc. started supplying Apples came up in the system monitor, not in all the computer companies with more sophisticated BASIC. The system monitor is contained in the F8 BASIC interpreters. Integer BASIC takes up about ROM, and the F8 ROM was naturally called the 5K of memory and has some very important limita- Monitor ROM. tions: no floating point arithmetic, no HIRES graph- The Monitor ROM contained such important Ap- ics commands, and no subscripted string variables, ple utilities as entry to BASIC, keyboard input, to name three. This is not said to belittle the consid- video text and LORES graphics output, cassette erable design accomplishments of Mr. Wozniak. It's I/O, assignment of different peripheral slots as just that within a few years. Integer BASIC became primary input or output, memory display and modi- less than state-of-the-art fication, a 6502 disassembler, machine language The 6502 utilities included with Integer BASIC single step, trace, or normal subroutine execution, were some floating point arithmetic routines, the handlers for RESET', NMI', IRQ', and BREAK, "SWEET 16" double word length command inter- and some 16 bit multiply and divide routines. Con- preter, and most importantly, the Mini-Assembler. trol of the Monitor is via a highly usable command SWEET 16 is a small but sophisticated computer interpreter, the use of which is well described in the language which lets the programmer manipulate Reference Manual. data in 16 bit word lengths. It utilizes RAM ad- This, then, was the Apple: a cassette based system dresses $0 through $1F as 16 registers of 16 bits with a poor man's BASIC and a rich man's monitor each and has normal machine language commands in ROM and two empty ROM sockets for user firm- such as ADD. SUBTRACT, COMPARE. BRANCH, ware. Oh yes. one more important thing— Apple etc. Writing some programs in SWEET 16 will published a source/object listing of the Monitor make them take less space than the equivalent 6502 ROM, This was a risky move which paid off immea- program, but the 6502 program will run faster. surably. By publishing their listing, Apple opened The Mini-Assembler is the utility on which the way for investigators to learn thoroughly the uncounted numbers of Apple owners have first nuts and bolts operation of the Apple. They thus learned to program 6502 assembly language. Its use aided competitors in developing numerous software is fully described in the Referevn' Maiuml. and there and hardware applications for the Apple II. With is also some description in the 6502 programming this combination of extensive available applications section of Chapter 4 of this book. and freedom of information, the Apple II pulls off SWE ET 16 and the floating point routines are not the delicate trick of appealing not only to the masses described in any published Apple literature. In the who don't care how it works but also to more serious old red Reference Manual, there are source/object users who develop even more applications. listings of SWEET 16, the floating point routines, The contents of the Monitor ROM dictate many of and the Mini-Assembler. SWEET 16 is fully de- the operational characteristics of the Apple: what scribed in the November, 1977 edition of Byte mag- happens when the computer is turned on or RESET azine ("SWEET 16: the 6502 Dream Machine" by is pressed, the format of the screen text, the nature Steve Wozniak). of cursor moves, and the assignment of primary input and output devices. The monitor zero page assignments must be taken into account by software The Monitor ROM designers. Page 2 of RAM is thoughtof as the Apple In microcomputer terminology, a system monitor keyboard input buffer because that is the way the is a program containing the most basic utilities of monitor uses Page2, Cards capable of being primary the system. Before the innovation of BASIC in ROM, input or output devices must have programs at their a monitor in ROM was the primary user interface to I/O SELECT' addresses, because the firmware the microcomputer. Some basic routines of asystem assigns a slot as a primary input or output by jump- monitor are keyboard input routines, video output ing to the slot's first I/O SELECT' address (?C100 routines, memory display and modification rou- for Slot 1. $C200 for Slot 2, etc.). These features are tines, and storage media input/output routines. not inviolate in the Apple. They can be changed by 6-6 Understa nd ing the Apple loading a new operating system into RAM or by utilities were thus sacrificed for improved opera- replacing a single ROM chip, which is exactly what tional features. The small businessmen gained a sys- Apple did when they decided to change a few opera- tem that automatically loads and starts at power up, tional features of their computer. and the computer hacks lost the convenience of STEP and TRACE in ROM. The Apple II Plus The Apple II evolved rapidly in the late 1970's into The Impact of the RAM Card a more sophisticated machine than was originally A more recent development in the evolution of the introduced. The dynamic nature of the hardware Apple II has been the popularity of the 16K RAM and software support provided to the Apple II by card. With a disk based system, as the Apple is now, Apple in 1978 and 1979 is remarkable. In approxi- it is no longer as necessary to have extensive oper- mate order, ating systems in ROM as it was with a cassette based Applesoft BASIC became available on cassette, 1. system. The entire Integer BASIC program and 2. The Disk II was introduced with its powerful associated utilities can be loaded into the $E000- DOS, $F7FF area of the 16K card in a tolerably short 3. Applesoft became available on diskette, period of time, giving the user the equivalent of the 4. Applesoft became available on a firmware card, firmware card but more versatile. The system mon- 5. The Apple 11 Plus was released with Applesoft itor becomes alterable by the user and the number of and Autostart Monitor in ROM. operating systems that may possibly reside in high 6. The Language System was released with 16K memory becomes unlimited. The disadvantages of RAM card, Pascal language, and 16 sector disk the 16K RAM card are the possibility of overwriting capability, and high memory, occasional extra waiting for loading 7. DOS 3.3 was released with its 16 sector capabil- the program into the 16K RAMcard from disk, the ity (August 1980). impossibility of protecting 6502 vectors from pro- A popular Apple configuration became both Integer gram encrypting artists, and the lost capability of BASIC and Applesoft in ROM with automatic selec- other peripheral cards to respond to $F800-$FFFF tion between the two by the DOS when a program addressing. For most users the advantages of the was RUN. One BASIC resided in motherboard 16K RAMcard outweigh the disadvantages. ROM. and theother resided in ROM on a Slot firm- So now we have the Apple II as it was before the ware card. As this configuration demonstrates, introduction of the He in January, 19S3: Applesoft bank switching of firmware operating systems is a and system monitor in ROM with alternate oper- very powerful concept. ating systems in firmware or RAM peripherals, disk based, and who knows what other peripherals The availability of Applesoft BASIC greatly plugged in. A clean machine. improved the versatility of the Apple by making the manipulation of the HIRES screen, large disk text files, and floating point numbers practical. Unfortu- nate Applesoft weaknesses were incompatibility in ROM TIMING command and memory usage with Integer BASIC, ROM read timing is very simple and similar to a no AUTO numbering, no DSP(DiSPlay)command, read to any address above $COOF. The two main and the absence of the 6502 Mini-Assembler. Also, timingsignals involved are RAM SELECT' and the the SWEET 16 interpreter and old floating point ROM ENABLE' signal for the addressed ROM routines which are associated with Integer BASIC chip. The important specifications of the 2316B are not available with Applesoft, ROM are: The new Autostart ROM reflected the changing 1. The output data will become valid a maximum nature of the personal computer owner. It caused of 450 nanoseconds after the address input the Apple to conie up in BASIC instead of the system becomes valid, monitor, gave the Apple the capability to boot a disk 2. The output data will become valid a maximum at power up, and greatly improved the ESCape of 120 nanoseconds after the three chip selects mode cursor moves. In the process, the SINGLE become active. STEP and TRACE investigative utilities for ma- 3. The data output will go to high impedance a chine language programs and the 16-bit multiply maximum of 100 nanoseconds after one of the and divide routines were removed. Programmers' chip selects becomes inactive. . ROM in the Apple II 6-7 6502 PHASE 2 PHASE SCANNER ADDRESS RAM SELECT' FO ROM ENABLE' ROM DATA Is valid when PHASE 2 tails. DATA BUS MRU DATA . 450 nsec . r 65(K address becomes valid ROM DATA becomes valid no more typically 10O nanoseconds than 12C nsec alter the ROM ENABLE' alter PHASE 2 tails. signal and no more ttiat 450 nsec after the address becomes valid. In lh« Apple, the 450 nanosecond maximum delay from address valid to data valid is usually met betore ROM ENABLE' has been low lor 120 nsec. Figure 62 Timing Example: ROM Read. Address $FO0O. ROM read timing in the Apple is illustrated in 120 nanoseconds maximum after the ROM EN- Figure 6.2. The main order of events is: ABLE' signal falls, the ROM data becomes valid, assuming the address bus became valid 1. During PHASE 1, the video scanner performs early enough. With a typical 6502. the address its normal access to RAM. becomes valid early enough that the chip select 2. At approximately 100 nanoseconds after 6502 to data valid delay of the ROM chip will deter- PHASE 2 falls, the MPU address becomes mine when data becomes valid. In any ease, valid. ROM data will be valid 450 nanoseconds ROM data becomes valid w^ell before 6502 from this point if the ROM ENABLE' input has PHASE 2 falls, been low sufficiently long. 5. PHASE falls, causing the ROM ENABLE' sig- 3. PHASE rises, causing the ROM ENABLE' nal to rise, followed by 6502 PHASE 2 fall- signal todrop and the RAM SELECT' to rise. It ing, followed by RAM SELECT' falling. The takes longer for RAM SELECT to rise because time differences in the three events caused by PHASE is propagated through several logic PHASE fallingare the result of different prop- devices to RAM SELECT'. The data bus floats, agation delays. After ROM ENABLE' goes storing the video data until the ROM data high, the ROM chip holds data valid for a becomes valid. maximum of 100 nanoseconds. If the chip ROM 6-8 Understanding the Apple II stops holding data valid before PHASE 2 falls, six ROM chips. Unlike the LS138 on the mother- the floating data bus will hold the ROM data board, the LS138 on the firmware card is also gated valid anyway until after RAM SELECT' falls. by R/W, the DMA priority chain input, and the This ensures that PHASE 2 falling correctly output of a 74LS74 flip-flop. Any of the six ROM clocks the ROM data to the MPU. In the unlikely ENABLE' signals at the output of the LS138 can event that the ROM chip actually tries to control drop low only if all of the enabling criteria are met. the data bus for 100 nanoseconds after ROM Again, these criteria are: ENABLE' rises, it will fight with the RAM/ keyboard data multiplexor for control of the DMA priority chain input - high data bus for about 30 nanoseconds. When the R/W - high RAM/keyboard data multiplexor actually does A14 - high take control of the data bus. it will bring the A15 - high data bus to $FF as it always does following: a PHASE 1 - high read access to an address above $BFFF. As was flip-flop B2-B - reset noted in the chapter on RAM. this is because the RAM data latch interprets the floating output The reasons for some of these criteria are easy to of the RAM chips as $FF (all ones). explain. A 14 and A 1 5 being h igh defines the address range $C000-$FFFF.LS138outputscorresponding to the $COOO-$CFFF range are not connected. En- THE FIRMWARE PERIPHERAL CARD abling firmware card ROM only when R/W is high Not long after Applesoft was introduced on cas- prevents a fight for control of the data bus between sette tape, it became available on the Applesoft the firmware card and the MPUbusdriver in case a firmware card. Then, when Apple started putting write to a ROM address is accidentally performed. Applesoft in the motherboard ROM, Integer BASIC PHASE 1 low or PHASE high defines the time became available on a firmware card. These cards when all MPU access to Apple devices occurs. are supported by DOS 3.2 and DOS 3.3 in an amaz- The two other enabling criteria require more ingly usable manner. One simply types "RUN pro- detailed explanation. B2-B is the enable/disable flip- gram name" and the DOS automatically switches to flop for the firmware card. When B2-B is set. moth- the language that "program name" is written in and erboard ROM is enabled. B2-B gets set when a loads and runs the program. Unlike possibly any RESET occurs and the switch in the back of the card computer system prior to the Apple, this switchingof isdown. or when the MPU accesses any odd address high order languages is accomplished almost in- between $0081 and $C08F (assuming the firmware stantly by disabling one bank of ROM and enabl ing card is in Slot 0). When B2-B is reset, firm ware card another. ROM is enabled. B2-B gets reset when a RESET This switching is made to seem even more amaz- occurs and the switch in the back of the card is up. or ing than it is, because Apple doesn't supply a hint of when the MPU accesses any even address between how the firmware card works in any of their docu- $C080 and $C08E. Thus, the firmware card enable mentation. Here then, possibly for the first time in function can be controlled from software or by the print, is a description of the capabilities and limita- position of the switch in the back when a RESET tions of the firmware card. occurs. When controlled from software, the switch- Figure 6.3 is a schematic diagram of the firm- ing is clocked by the trailing edge of DEVICE ware card. I prepared Figure 6.3 after analyzing an SELECT' a few nanoseconds after PHASE falls. Applesoft card with my eyes and an ohmmeter. This insures that switching always occurs when all Please refer to this figure during the following the ROM ENABLE' signals are high. Switching in discussions. the middle of a ROM access could cause a program to crash. Enabling the Firmware Card The combination of DOS and the Autostart ROM The first thing to notice about the firmware card completely defeats the functions of the switch in the schematic is that there are six ROM chips with en- back of the firmware card. When a power-up RE- abling signals generated by a 74LS138, just like on SET occurs, the firmware card is first enabled or the motherboard. As on the motherboard, the LS138 disabled as a function of the switch in the back, but is enabled when A14 and AI5 are high during the DOS soon enables or disables the card based on PHASE to decode ROM ENABLE' signals for the the language of the "HELLO " program.If RESET ROM in the Apple II 6-9 i^-l i—J 4_^ fc_t (_l E_t U l—J i 6-10 Understanding the Apple is pressed and the DOS is linked up, the firmware This can be prevented by keeping an empty slot card ag-ain is enabled or disabled as a function of the between a firmware card chain and a DMA card switch in the back, but the DOS shortly reenters the chain or by modify! ng the lead ng or trail ing card in i last BASIC that was active. The result of all this is one of the chains so the lower priority chain ignores that the switch in the back usually serves no func- its priority input tion in a disk based Apple with an Autostart ROM. By usingthe DMA' priority chain to prioritize the In systems with no disk drive, it determines the firmware card, Apple implicitlystated that there is power-up BASIC and provides an inconvenient a priority by which the peripheral slots or the moth- method of switching back and forth between Integer erboard may respond to addresses $DOOO-$FFFF. and Applesoft. Slot has the highest priority, and the motherboard Even thougrh any addresses between $0080 and has the lowest priority. Then, in violation of their $C08F may be used to control the Slot firmware own implied guidelines, they produced the 16K card, the DOS always uses $C080 and $C08I to RAM card which steals ROM addressing without switch back and forth. The DOS doesn't care what supporting the DMA priority chain. This means ROM is in the motherboard and what ROM is in the that if one elected to put a RAM Card in Slot and a firmware card. It checks both ROMs to see if the firmware card in Slot 1, there would be no fail-safe BASIC it is lookinj? for is available. The firmware method of preventing accidental simultaneous en- card will operate in any slot, but the DOS only sup- abling of the two cards. In any case, the DOS does ports it in Slot 0. not support firmware cards anywhere but in Slot 0, so one would have to patch the DOS to achieve auto- The DMA Priority Chain matic selection of firmware other than in Slot 0. ThefinalenablingcriteriafortheLSl38isthatthe Hardware capabilities not supported by software DMA priority chain input be hipjh. This is because are of little use. Also, the concept of a priority chain the firmware card was designed so that you can have of 12K firmware cards is a bit obsolete. With today's several of them in adjacent peripheral slots. It uses ROM, you could easily put 64 kilobytes of firmware the DMA priority chain to make sure that two or on one card. more firmware cards do not accidentally become enabled at the same time. This is accomplished as The ROM ENABLE' Signals follows: When one of the six ROM ENABLE' signals goes 1. When the DMA' priority input is pulled low. all low, it means that the firmware card is enabled and ROM ENABLE' signals on a firmware card go theMPU is addressing ROM. These ROM EN- high and the firmware card is isolated from the ABLE' signals are each tied totheCSr input of one data bus. Also, the DMA priority output is of the six ROM chips. The ROM data from that chip pulled low, so all tower priority firmware cards then becomes valid within 120 nanoseconds. The are also inhibited. data is routed to the data bus through a 74 LS244 line 2. If the DMA priority input is high and a firm- driver, which is gated on by any ROM ENABLE' ware card is enabled (B2-B reset), an MPU read signal dropping low. to a ROM address results in one of six firmware The fact that one of the ROM ENABLE' signals is card ROM ENABLE' signals going low. This low is detected by a six input, low level OR gate causes the DMA priority output to drop low. consisting of three open collector AND gates on B3. disabling lower priority firmware cards. Also, This detected signal is labeled DE' (Data Enable') in motherboard ROM is inhibited, and the data Figure 6.3. Besides gating the LS244 outputs to the from the addressed ROM chip is gated to the data bus. DE' also causes INHIBIT' and the DMA data bus. priority output to drop low. Dropping INHIBIT' The firmware card does not perform DMA. It isolates the motherboard ROM from the data bus, so implements bank switching of addresses between the firmware card data is read by the MPU, Note $D000 and $FFFF. However, because of its use of that DE' and INHIBIT' are not identical logic the DMA priority chain, the firmware card will terms. DE' is the local "data enable" to the data bus, interfere with lower priority DM A cards, and it will but INHIBIT' is the low level wire-OR gate of the be interfered with by higher priority DMA cards. pin 32 output of all eight peripheral slots. ROM in the Apple II 6-11 The LS244 is not necessary for operation of the any time the computer was in Applesoft, the Auto- firmware card. You could remove the LS244 and start ROM would be active; and any time the com- short all the outputs to their respective inputs on the puter was in Integer BASIC, the old Monitor ROM empty socket, and the firmware card would still would be active. This would be desirable in that the work. Apple probably included the LS244 in the best features of both ROMs would be available. It design to reduce data bus loading. A gated OFF would be undesirable in that the owner would have LS244 loads the data bus less than six gated OFF to put up with the old cursor moves when in Integer 2316B ROMS. Notice that the address bus is not BASIC. An Application Noteattheend of thischap- treated with such tender respect. AO-AIO are con- ter shows how to modify the firmware card so that nected directly to the six ROM chips and AO is addi- the F8 ROM is selectable independently of the other tionally connected to the D-input of B2-B. five ROMs. By an easy modification the owner truly , gets full access to the best features of both ROMs. Firmware Card Jumpers There are three solder pad jumpers on a firmware Firmware Card Timing card. Twoof these jumpers configure the firmware ROM or 2716 EPROM. Apple ROM Timing for reading from the firmware card is card for Apple very similar to reading from motherboard ROM. chip selects are not programmed to be compatible The major difference is that the data bus acts differ- with 2716 EPROM. By placing a touch of solder on ently when the firmware card is read because of the the two jumper pads labeled 2716, the owner can ROM and replace it with EPROM con- LS244 buffering ROM from the data bus. The remove the important point is that the ROM data must still be tainingprogramsof hischoice.This is notabad idea valid on the data bus when 6502 PHASE 2 falls if it for people who have replaced their firmware card is to be correctly read by the MPU. with a RAM Card. Put your utilities in inEPROM The timing of a read from ROM on the firmware an empty peripheral slot.* Note that the jumper card is shown in Figure 6.4. The important events pads allow you to configure the firmware card as all EPROM or all ROM. It is very easy, however, to that are_ different from a motherboard ROM read are: modify the card's wiring so some of the sockets are EPROM configured and some are ROM configured. 1. PHASE rises, followed by a ROM ENABLE' The third solder pad jumper on the firmware card signal falling, LS244 DATA ENABLE' falling, is labeled F8 on the card. If this jumper is soldered, DMA priority outputfalling, INHIBIT' falling, the F8 ROM on the firmware card will be enabled or and RAM SELECT' rising. All of these events disabled with the other ROMson the firmware card. are gated by PHASE 0, but they differ in time of If this jumper is not soldered, the F8 ROM on the occurrence becauseof different propagation de- firmware card will never be enabled. Instead, the lays. It is interesting that the LS244 ENABLE' motherboard F8 ROM will remain active whether signal drops low about 20 nanoseconds before the firmware card is enabled or not. Apple has de- RAM SELECT' rises, causing the LS244 to com- livered firmware cards in at least two configura- pete with the RAM/keyboard data multiplexor tions: with F8 jumpered and the Autostart ROM for control of the data bus for a short period. installed, and with F8 not jumpered and no F8 ROM 2. Within 120 nanosecondsof ROM ENABLE' fall- installed. ing, the ROM data becomes valid and is propa- The F8 jumper gives the user some options for gated through the LS244 to the data bus. This configuring his Apple. If the owner has only one F8 assumes that the 6502 address became valid ROM, he should plug it into the motherboard F8 about 100 nanoseconds after PHASE 2 fell. socket and leave the F8 pad on the firmware card 3. PHASE falls, followed by ROM ENABLE' unsoldered. Suppose he has an Autostart ROM and rising, DATA ENABLE' rising, 6502 PHASE an old Monitor ROM. If he wants, he can plug one 2 falling, the DMA priority output rising. IN- into the firmware card and plug the other into the HIBIT' rising, and RAM SELECT' falling. motherboard. One such configuration would be that Again, all these events are triggered by PHASE falling. The data bus is floated by DATA •When aRAM card and firm ware card are installed inan Apple ENABLE' rising approximately at the same II at the same time, either the F8 jumper of the firmware card time PHASE 2 falls. As normal, the floating should be unsoldered, or the RAM card should be modified as described in the Application Note at the end of Chapter 5. See data bus keeps the ROM data valid until after "Hardware Application: Multiple RAM Card Configurations." RAM SELECT' rises. 6-12 Understanding the Appfe 6502 PHASE 2 r ~\ PHASE SCANNER ADDRESS MRU ADDRESS V RAM SELECT' B7-15 ISOLATE RAM FROM DATA BUS FIRMWARE CARD FO ROM ENABLE' B2-9 1 FO ROM ENABLE' / FIRMWARE CARD DATA ENABLE' B3-1 GATE LS244 TO DATA BUS r fSOLATE MOTHERBOARD INHIBIT ROM FROM DATA BUS B3-6 [ DMA PRIORITY DISABLE LOWER PRIORITY OUTPUT Aa-12 \ FIRMWARE CARDS DATA BUS MPU DATA "^ VIDEO X ROM DATA VALID SFF Jl_DAM_/ ROM OATA becomes valid on the data bus no more than 120 nanoseconds afler ROM ENABLE' falls plus the propagation delay of a 74LS244. Figure 64 Timing Example: A Head From Address $F000, Firmware Card Errabled. ROM in the Apple II 6-13 HARDWARE APPLICATION EPROM IN THE APPLE EPROM is Erasable Progrrammable Read Only There is a new type of EPROM called the Memory. It is like ROM except that it is user pro- EEPROM (Electrically Erasable and Program- grammable and user erasable. The program in mable Read Only Memory), The EEPROM requires ROM is placed there in the manufacturing process, no ultraviolet light source for erasure. Instead, it is never to be altered, The program in EPROM is both programmed and erased with combinations of placed there by an EPROM programming device, +25 and +5 volts. These are the same voltages re- never to be altered unless you shine ultraviolet light quired for programming an ultraviolet EPROM, through a little window in the top. Like ROM. it is and they are required on the same pins. For this nonvolatile memory, and the programs stored there reason, some programmable 2716 PROM burners are always ready to run the instant you turn your used in the Apple should be able to program and computer on. era.se 2716 compatible EEPROM like the Hitachi The 2316B ROMs used in the Apple II are physi- HN48016P. This appears to be the case with the cally and electrically compatible to 2716 EPROMs. author's PROM burner (made by John Bell Engi- This means that the owner can burn his own firm- neering), judging from its schematic diagram. Of ware and plug it into the ROM sockets of the course, the controlling software for burning and Apple— almost. It turns out that the Apple's ROM erasing EEPROM mustbedifferent. With the com- chip selects are incompatible with the 2716 chip ing of EEPROM, we may soon see computers capable selects. Remember that the ch ip selects of the 231 6B of programming and erasing resident firmware. are specified as active high or active low by the 2716 EPROM burners for the Apple are available buyer (in this case. Apple Computer. Inc.). The chip from several companies in the $1004200 price selects of the 27 16 are not programmable. Pin 18 is range. These EPROM burners dump a 2K block of active low. pin 20 is active low. and pin 21 is active memory to EPROM in about a minute and a half. high. Thus Apple's ROM sockets are incompatible Also available are inexpensive cards w^hich have with27l6 EPROM. Unfortunately the 2716 hadjust multiple sockets for 2716 EPROMs and make use come on the market when the Apple II was first of the $DO0O-$FFFF bank switching or $C800- designed, and the desirability of pin compatibility $CFFF "seventh ROM" capability. These cards with the 2716 was not forseen by the Apple designer. allow EPROM users to have the convenience of You can still use the 2716 EPROM in the Apple permanently accessible user firmware. The Apple- motherboard sockets ifyou plug them in through an soft or Integer Card may also be configured ta adapter. The adapter is made by taking two 24-pJn accept2716 EPROM instead of ROM. Another place DIP sockets and modifying them as shown in Figure to EPROM is in the text character generator use 6.5. This adapter is very cheap but will take about an (socket A5 on the motherboard). The ROM at this soc- hour of your time to construct if you are as slow as ket contains the dot patterns for Apple screen text. the author when working carefully. A ready made In Revision 7 or later Apple lis the A5 socket is com- adapter is available for about $10 from a company patible with 2716 EPROM and the owner can install named Microproducts, whose address is given at the his own upper case/lower case screen character set. endofthisApplicationNote.Theadaptercanbeused on the firmware card as well as on the motherboard, Jeffrey Mazur wrote a nice article about EPROM Texas Instruments and Motorola make a 2716 and the Apple for his "Hardtalk" column in Softalk EPROM which is not compatible with Apple ROM magazine. The article, which appears in the July or Intel type 2716 EPROM. The TMS2716 requires and August 1982 Softalk issues, contains product +12 volts on pin 19. The correct 2048 x 8 EPROMs to reviews and a thorough discussion of EPROM. This order from these companies are the Texas Instru- article is recommended for Apple owners wishingto ments TMS2516 and the Motorola MCM2716. learn more about EPROM. 6-14 Understanding the Apple II Listed below are some compan ies which manufac- ture products reiated to using E PROM in the Apple: John Bell Eng-ineering, Inc. 1014 Center St. San Carlos. Ca. 94070 415-592-8411 Microproducts 24627 Watt Road SDCE Ramona. Ca. 92065 714-789-6510 Mountain Computer 300 El Pueblo Scotts Valley, Ca. 95066 408-438-6650 Soft CTRL Systems Box 599 WestMilford. N.J. 07480 201-728-8750 Word Power P.O. Box 736 EI Toro. Ca. 92630 j / ROM in the Apple II 6-15 IB 19 20 21 UPPER SOCKET ' LOWER SOCKET i 18 19 20 21 sockets, choose pin 1 and mark it 1.Use two 24 pin DIP sockets. If pin 1 is not clearly marked on the with fingernail polish or other permanent marking, ^ -^ , 2 All pictured wiring is shown in phantom. Pins are bent inward, and wiring is routecT on inside of lengths as short as possible. sockets. Use 30 gauge insulated wire and keep wire a spare. 3 Remove pin 21 from lower socket. Save this pin as .^u make contact with the lower i 4 Bend pins 18 and 21 of the upper socket inward so they will not * carefully so the EPROM will still make socket when the sockets are mated. This must be done contact with the bent pins when it is inserted into the upper socket. pin 20 in the upper socket. Carefully 5 Solder a short jumper between bent pin 18 and the base ot with the matmg of the two sockets. dress the jumper at the base of pin 20 so it will not interfere upper socket and the base of pin 18 on the 6 Solder a short jumper between bent pin 21 on the 18 so it will not interfere with lower socket. Carefully dress the jumper at the base of pin plugging the completed adapter into a ROM socket, or with an ohmmeter to make 7 Push the upper socket into the lower socket. Inspect visually certain there is no contact between pins 18 on the upper and lower socket. With some sockets it that rt does not touch pm may be necessary to modify or insulate pin 18 on the lower socket so so pin 18 is firmly mounted in the lower 18 on the upper socket.This must be done carefully still socket. Hgure 65 ConstrucHon o* a Sockef Adaptor, EPROM to ROM. 6-16 Understanding the Apple II HARDWARE/SOFTWARE APPLICATION MODIFYING THE SYSTEM M^MlT^ The system monitor determines many of the oper- The deletion of STEP and TRACE routines from ational features of the Apple, and modifying the the system monitor opened space for two commands system monitor is one way of enhancing the Apple. in the command tables (CHRTBL and SUBTBL) of The monitor resides in the F8 ROM and in the $F800 the monitor. If you delete the cassette routines, that to$FFFFaddressingspaceofal6K RAM card. Itis will also open up two more command spaces since easily modified in RAM by the user and by commer- the READ and WRITE commands will no longer cial programs, so modifying the monitor in RAM function. will give you access to your persona! utilities but What sort of com mands can be instal led? Here are won't necessarily help you investigate programs some possibilities: written by others. If you want an unalterable modi- 1. Breakpoint insert and breakpoint remove com- fication, you must make it in E PROM and have your mands which facilitate the use of the 6502 Apple confiprured so that you can override software BREAK instruction as a debugging breakpoint. control to enable your EPROM. 2. Hex to decimal and decimal to he.K commands. The Autostart ROM contains a fine system moni- 3. Commands that link to large routine.s in the tor with some good utilities that you probably don't spare ROM space of Integer BASIC, even if want to delete. However, here are two parts of the Integer BASIC is not currently enabled. Autostart ROM which may not be too critical to you: 4. "Click on" and "click off" control of a keypress 1. Addresses $FCC9-$FD0B,$FECD-$FEF5. and click simulator. $FEFD4FF2C are cassette read/write rou- 5. Commands that enter Applesoft. Integer. Pas- tines. There is no reason to have these routines cal, or CP/M. in firmware if you own a disk drive and don't 6. Commands that connect and disconnect the usually use cassette I/O. Modify the cassette DOS. routines torunata RAM address and save them 7. A command to transfer the DOS from EPROM on diskette. This generates 156 bytes for your on a firmware card to RAM. personal firmware. This can be increased to 164 8. A dump screen to printer command that links to by moving the control-Y jump statement to your printer driver on the "seventh ROM." $FEC2. This is accomplished bV storing $4C, The possibilities are endless. $F8, and $03 at $FEC2-$FEC4 and bv storing You can modify the system monitor without chang- $Clat$FFE4. ing the command table. One idea is to change the 2. There are 14 consecutive unused bytes at ESCAPE handler to recognizespecial functions. For $FBB3-$FBC0. This can be increased to 18 by example, you can assign ESCAPE-G to Graphics, storing $80, $EC at $FBAD and $FBAE. This ESC APE-T to Text, and soon to give yourself control makes $FBAF-$FBCO unused and causes only of the screen modes from BASIC, the monitor, and a minor operational change. The change is that many other keyboard polling programs. pressing L will not cause the Apple to leave the Here is an example of a change to the Autostart ESCAPE mode. Even more space could be gen- ROM that does not delete any routines or capabilities erated by rewriting the ESCAPE handler so but would still benefit the Apple user. It modifies the ESCAPE-A.B.C, and D were not recognized. RESET routine to begin by checking to see if the last These old cursor moves are not needed because keyboard entry (not including the RESET kev) was far better cursor moves are included with Auto- "CONTROL-SHI FT-M." If the last keypress was start ROM. not "CONTROL-SHIFT-M." then the normal Auto- The idea in making a minor modification to the start RESET is performed. If the last kevpress was Autostart ROM is to create an EPROM that is identi- "CONTROL-SHIFT-M," then the old monitor RE- cal to the Autostart ROM except for small areas SET is performed. "CONTROL-SHIFT-M" stands which contain your data. One idea for modification is for Monitor and is not likely to be pressed acci- to increase the command repertoire of the monitor. dentally. With this modification in firmware, the ROM in the Apple II 6-17 user may cause a RESET entry to the monitor any- 3. Beginning at the address corresponding to time he wishes, but the normal RESET is still the $FBAD, store this program; Autostart RESET. This modification works because As a final word of advice, you should tag your pressing RESET does not change the state of the modified monitor so you can recognize when it is keyboard latch (read at SCOOX) and because a pro- active. It can be tagged audibly by changing loca- gram cannot modify the contents of the keyboard tion $FBE5 from $0C to $16. Th is noticeably lowers latch. the pitch of the Apple's BELL so that you can verify To create an EPROM with this modification, per- your EPROMis active by pressing CONTROL-G or form the following steps: RESET. You can tag your EPROM visually at 1. Using the monitor MOVE command, transfer power-up by changingthe contents of $FB09'$FB10 the AutostartROM contents to the area of RAM to an ASCII message of your choice. For example, used as the 2K output buffer by your PROM instead of "Apple 11" you might have your screen burner. display "KAZOO 11" or some other pertinent title. 2. StoreSAF and $FB at the addresses correspond- ing to $FFFC and $FFFD. This changes the 6502 RESET vector to IFBAF. fbad: b0 EC BCS $FB9B ;Save four bytes by not ; looking for ESCAPE-L. FBAF: 8D 10 C0 STA $C010 ;Look for CONTROL-SHIFT-M FBB2: AD 00 C0 LDA $C000 FBB5: C9 ID CMP #$1D ; CONTROL- SHI FT-M? FBB7: D0 03 BNE $FBBC FBB9: 4C 59 FF JMP $FF59 ;Do old monitor RESET FBBC: 4C 62 FA JMP $FA62 ;Do Autostart RESET 6-18 Understanding the Apple HARDWARE APPLICATION MODIFYING THE FIRMWARE CARD FOR INDEPENDENT SELECTION OF THE Fd ROM The importance of the F8 Rom to the App[e should the F8 enable switch just before PHASE falls dur- be well understood by the reader. The RESET inter- ingan MPU access to an F8 address. It is possible for rupt and Non-Maskable Interrupt vectors reside 6502 PHASE 2 to fall while the data bus is in an in- there and determine who has ultimate control of the valid state, causing a program crash, This would not Apple, the owner or the author of the currently normally happen, but it will happen once in a while. operating- program. Moreover, the system monitor The crash occurrence rate will be inversely propor- determines much of the personality of the Apple. tional to the quality of your switch since there is no This becomes very apparent to people who owned debouncing circuitry. Because of switch bounce, the Apple when the Autostart ROM came out. The throwing the F8 enable switch while the firmware Autostart Mon itor and the old monitor are 90% iden- card is selected can result tn multiple toggles be- tical, but with the latter the Apple is more of a tween the motherboard and firmware card F8 ROM, hacker's computer, and with theformer ittsmoreof This does no harm in itself, because the programs an appliance. that will be running when the switch is thrown are Thereareagood number of theold Monitor ROMs identical in the Autostart Monitor and old monitor. lying around g'atherinff dust, because standard However, multiple toggles increase the probability Apple hardware does not facilitate independent that F8 control will be switched during the critical switching of the FS ROM. Certainly this switching period just before PHASE falls. is a capability of the Apple — they just haven't If, in spite of the occasional crash, you elect to in- designed the peripherals todo it. The purpose of this stall this easy modification, here are some installa- Application Note is to show some schemes for modi- tion suggestions: fyinp: your firmware card to add some versatility to F8 ROM switchinp:. Figure 6.3 should be referred to 1, Mount the switch in the bottom of a cable slot in while reading this Note. the back of the Apple case. This gives reasonable Remember from the firmware card discussion access to a switch you won't throw all that often. that the F8 ROM on the firmware card can be dis- It would be difficult to mount a second switch on abled or enabled via the F8 solder jumper. Suppose the back of the card. you wired an on/off toggle switch across the F8 2, Connect the switch to the board using a two pin solder jumper as shown in Figure 6.6a. This is the jack/plug combination. This way you can easily simplest way to achieve selectability between the disconnect the switch and remove the firmware Autostart ROM on the motherboard and the old card from its slot. One way to do this is to take Monitor ROM on a firmware card in SlotO. Theold short speaker extension cable and cut it in half. Monitor ROM is enabled when the firmware card is Solder the cut end of one cable half to the switch. enabled and the F8 switch is on. Otherw'ise the Solder the cut end of the other cable half to the Autostart ROM is enabled. Normal operation with firmware card. this setup is with the F8 switch off, enabling the Autostart ROM. To enter the old monitor, turn the With afew extra wires, it is possible to synchronize F8 switch on, lift the firmware card enable switch the switching of the F8 ENABLE' signal. This isae- and press RESET. For sure, this will get you an complished by wiring up the unused half of the asterisk and a blinking cursor on the screen, just 74LS74dual flip-flop at B2. The wiring is shown in like the good old Apples. You then may do as you like Figure6.6b. This modification is functionally identi- with the Apple, including initiation of STEP and cal to the one shown in Figure 6.6a, but there is no TRACE commands from the old monitor. You can possibility of invalid ROM data being read by the also force the Apple to power up in the old monitor MPU. The flip-flop synchronizes the enabling and by having the F8 switch on and the firmware card enable switch up. There is one problem with this modification. Sup- •Please read the NOTE OF CAUTION at the beginning of the pose that the firmware card is enabled and you flip bock before making any modification to your hardware. ROM in the Apple II 6-19 Hgur© 6^ An Added Switch to Control tti© Ffl ROM on ttie Firmware Card. Vo S2 7M(i> This Circuit SyncronlJtes Switching to Prevent Possible Program Rgure 6j6b Crashing. I disabling- of F8 on the firmware card to the rising enable switch right before PHASE falls, there is edge of the 7MHz clockpulse. This prevents switch- no time, including propagation delays, for the newly ing of the F8 ENABLE' signal during the critical enabled ROM to take control of the data bus before period before PHASE Switch bounce still falls. PHASE 2 falls. occursbutanyFS ENABLE' bounce is synchronized The following is an installation procedure for to 7M rising. modification shown in Figure 6.6b: Several hardware facts of life in the Apple are The following is an installation procedure for involved in the operation of this circuit. ROM modification shown in Figure 6.6b:* enable/disable time is 120 nanoseconds maximuni. 1. Use 30 gauge, solid, insulated wire to make con- The 7MHz clockpulse is the only available rising nections on the firmware card. Solder the wires edge during PHASE which can synchronize the to the protruding ends of the pins of the IC F8 ENABLE' signal. During the critical period. 7M sockets. Glue long wires to the board using a hot rises 140 nanoseconds before PHASE falls and at glue gun or other effective glue. the same time PHASE falls. If you flip the F8 Desolder the FS solder jumper. enable switch 140 nanoseconds before PHASE 0, 2. there is plenty of time to disable one ROM, enable the other, and get the new data to the data input of •Please read the MOTE OF CAUTION at the beginning of the the 6502 before PHASE 2 falls. If you flip the F8 book before making any modification to your hardware. 6-20 Understanding the Apple 3. Desolder and disconnect the end of R3 nearest two small holes near the edge connector and the F8 solder jumper. R3 will be used to pull up leading the wires in one hole and out the other the D-input to the synchronizing flip-flop. Bend near the pin to which the wire will be soldered. the open lead of R3 away from the board so it 5. Connect a wire from one terminal of an on/off will not accidentally touch any conductors. switch to the disconnected lead of R3 and the Remove all solder from the hole that was vacated lead from LS74, pin 2. Solder this connection when the R3 lead was removed. An insulated now. The connections to the switch should be via wire will be strung through this hole, twin lead through an easily disconnected plug/ 4. Connect the following points by soldering wires jack connection. between them: [insert 6-3] 6. Connect a wire between the other terminal of the on/off switch and pin 7 of the 74LS138. This LS74.1 to LS74-14 connection can be made mechanically stronger LS74-5toLS09-l LS74-4 to pin 40 of the edge connector by looping the switch wires through the small hole just above the DO ROM socket. LS74-3 to pin 36 of the edge connector LS74-2 to the disconnected lead of R3 (no solder) Figure 6.6 is far from the last word in modifying the firmware card for versatile F8 selection. It's just The wire between LS74-2 and the disconnected the simplest. Figure 6.7 shows another more versa- lead of R3 should be strung through the hole tilescheme thatdoes not require a second switch but vacated by R3. Do not solder this connection yet does require a new chip. Figure 6.7 uses the second because another wire will be connected here. half of the LS74 as a completely independent F8 When soldering a wire to an edge connector pin, ROM selector flip-flop, with F8 selectable under carefully solder the wire to the upper part of the program control. A 74LS30 is added to the firm- pin that does not actually make contact with the ware card to detect F8 ROM addressing, even when motherboard socket pins. These connections can the main select flip-flop is in the motherboard be made more mechanically sound by drilling enabled state. The Slot software control of the F8 PHASED A^ RESET' SWITCH UP FROM B2-13 ROM ENABLE FROM B^S All FR0MB4.1 74LS30 At; FROM B4.2 A1 FROM AI3FR0MBi|.J ROM D8, PIN 7 FIRMWARE CARD The 74LS30 is added F8 ENABLE at location B1 DEVICE SELECT FR0MB2-11 RESET' SWITCH DOWN FROM B2-10 Bgure 6.7 Circuit to Allow Independent Selection of ttie F8 ROM. ROM in the Apple II 6-21 firmware card modified to this confipruration is as you do not drill through conductiv^e traces on either follows: side of the board when drilling pin holes. Here is one last modification suggestion for the $D000-$F7FF $F800-3FFFF firmware card which many Apple owners could use. This modification is to configure the card for COMMAND LOCATION LOCATION EPROM in the F8 socket and ROM in the other five $C080 Firmware Card Motherboard sockets. To make this modification, pull the F8 ROM $C081 Motherboard Motherboard from its socket and look at the board through the top $0082 Firmware Card Firmware Card of the socket. You can see conductive traces running $C083 Motherboard Firmware Card across to the other sockets. Counting down from the top, the third and sixth traces from the top are the Since DOS only uses $C080 and $C081 for firmware CSS and CS2 chip select lines (see Figure 6.8). Cut card manipulation, it will always disable the firm- these two traces with a razor knife and curl the ware card F8 ROM. You can reverse this situation traces back slightly to insure the conductive path is by connecting pin 1 1 of the LS30 to pin 6 of the LS74 broken.* This isolates the chip selects on the F8 instead of pin 5. Another feature of operation is that ROM from the chip selects on the other five ROMs. the switch in the back controls the F8 ROM flip-flop Now solder the 2716 jumper pads. This configures in the event of RESET, but it is not necessarily F8 for 2716 EPROMs. Finally, on any ROM socket defeated by DOS in this function as it is in an except F8, solder wire jumpers between pins 24 and unmodified firmware card. DOS normally controls 18 and between pins 12 and 21, configuring the the firmware card after an Autostart RESET. If remaining five sockets for ROM. The F8 socket is the RESET selects an F8 ROM containing a firm now ready to accept your personal firmware in 2716 RESET (like the Monitor ROM), program flow EPROM, but you can reconfigure it for ROM by never vectors to DOS. removing the solder from the 2716 jumper pads. There is actually room for two new chips below The modifications presented here may give you the DO ROM socket of the firmware card. The way to other ideas on personalizing your firmware card. install a new chip is to mark and drill holes for the Remember that control of the F8 ROM in a Slot pins of a DIP socket.* Then attach the socket to the card is the secret to maintaining control of your board using epoxy cement, carefully avoiding get- Apple. ting any epoxy on the contact areas of the pins. Wire can then be soldered to the protruding pins of the * PI ease read the NOTE OF CAUTION at the bejrinninR of the socket. Choose the location of the new socket so that book before making any modification to your hardware. 6 Cut these circuit traces with a razor knife. F8 Rgure 6^6 Method for Isolating the FB Chip Selects from Other ROM Chip Selects. 5 DQQOQQOa chapter 7 Ti ^ ^ = ^T^ TT It Ji Address Decoding and Input/Output It bears repeating. MPU command of all devices what the MPU is doing. in the Apple computer is via sigrnals decoded from Address decoding in the Apple is the process of the address bus. All persons who proprram the Apple selecting one of 65..586 addressed locations from a become aware of this sooner or later, and all users of 16-bit address. It is one thing to say you can repre- the Apple can save themselves problems if they sent 65.536 different states with a 16-bit number, understand command by addressing. Theconeeptof and quiteanotherthingtodiscern between all those data transfer between the MPU and a memory loca- states in the space of half a microsecond. As was tion is very easily grraaped, but it must be understood mentioned in Chapter 2 (Bus Structure), much that the MPU also controls partsof the computer via address decoding goes on inside RAM and ROM the address bus with no related transfer of data on which we take for granted. In this chapter, we will the data bus. look at how Apple addressing is divided up into Now there is no "Control Address Bus" command major categories, such as ROM, I/O. and RAM. We in the (i502's repertoire. The 6502 reads from or will also look at the subdivisions of I/O control, an writes to the data bus on every cycle. So what does address area which is not conveniently carved up the programmer do when he wants to toggle the into thousands of addresses by single chips as RAM speaker? He does a "LD A SC030" or a "CPX $C030" and ROM are. or a "WHO GIVES A DARN $C030" and ignores In studying the details of I/O address decoding, it the meaningless data bus. This is why you can pro- For this is natural to discuss all topics related to I/O. gram the speaker with a statement like "SOUND = reason, address decoding and Apple Input/Output PEEK(-163S6)." The object is not to "PEEK" into are covered in this single chapter. Figure 7.1 is a memory. The object is to get $C030 on to the address general block diagram showing the areas of discus- bus, commanding the speaker to toggle. Beneath the sion. It can be readily seen that the majority of lid of the Apple, on every cycle, whether memory or address decoded signals are directly related to I/O acontrol function is being addressed, the state of the functions. Video output is not a topic of this chapter address bus is decoded to tell the rest of the Apple but the sole subject of the next chapter. 7-2 Understanding the Apple ADDRESS DECODE -^ tDZEL ism ROM ENABLE' EEEEEZ nz'n JoAilA ?°."S'*. p^-'q fa'O. 6£id PHASE 0- F8 FO E3 EO D8 ROM ROM ROM ROM ROM ROM ROM C7KX MUX C5X)i I/O SELECT' fcT5sr Twr NC- AO- i A1- I/O CaCO-CFFF PERIPHERAL STROBE- 20 20 20 ?0 20 20 20 20 SLOTS A2- T5i '41 7^1 T^ ,,41 ,,41 ,,41 i civ A3- 5 ma DEVICE SELECT' A4- cflfy A5- SERIAL A6- IN' A7- OUAD 00 04 1ENABLE TIMER A8- TfMER CC7K 01 05 OUT TRIGGER SERIAL TRIGGER Q2 INPUT A9- a3 MUX -AO RO R1 R2 R3 AID- All CASSETTE/ IN t > DO -A1 -A2 c»ajg 'OLD PDL POL POL 5V A12- ANO AN1 AMI GAME P90 A13- CCSCJD SOCKET , AX2 PSI AN2 COSEff A14- AN3 AN3 PB? STRB A16- STflOBE' CASSETTE CIK)( /:::^OUT CASSETTE SPEAKER >- SPEAKER KEYBOARD ENABLE' y KUIC MHD •line R/W- ^=o ^ STROBE cod: ENABLE STROBE-FF SEl -Ud7 RESET KEYBOARO RAM/ -»-os LATCH K4 KEraOARD -*-D4 VIA K3 DATA KEYBOARD TH" MUX -»-02 CONNECTOR -*-D1 ciaoji -».CRAf>HICS/rEKT SCREEN MODE TTTTTTTT SCREEN -^NCIMMfMIK I TOm QEN 00 a DQO'D L L U L L L L L MODE -*-fAeE i^PACE AND RAM 7 e S 4 3 2 10 C056,'7 -*-lOfl£S/mHES ADDRESS MUX LATCHED RAM DATA Figure 7.1 Schematic: Address Decode. I Address Decoding and Input/Output 7-3 All of the decoded signals in Figrure 7.1 are in the The annunciator outputs are off/on switches like address ran^e $C0OO through $FFFF. in other the screen mode switches, but the annunciator sig- words, everything except RAM. The decoding of nals are tied directly to output pins on the game I/O RAM addresses is covered in the chapter on RAM. connector: Oneway of looking at Fig-ure 7.1 isasan illustration ofeverythingthathappens in the Apple when RAM $C058/$C059 ANNUNCIATOR OFF/ON is not being addressed. Here are two points about $C05A/$C05B ANNUNCIATOR 1 OFBVON Figure 7.1. First. PHASE and the address bus are $C05C/$C05D ANNUNCIATOR 2 OFF/ON shown as the only inputs. PHASE 1 is actually used $C05E/$C05F ANNUNCIATOR 3 OFF/ON at several active-low enabling inputs. The low state of PHASE 1 is PHASE 0. Second, the little circles The C040 STROBE' is a signal that goes low during on an output or input nnean the signal is active low. PHASE while $C04X is on the address bus. It is As an example, when $C060 is on the address bus tied directly to an output pin on the game I/O during PHASE 0, the C06X signal goes low. When connector. C06X goes low at the serial input nnultiplexor, the $COIX and $C07X perform special I/O functions multiplexor's output is enabled to D7 of the data bus. as follows: THE ADDRESS DECODED SIGNALS $C01X Reset keyboard strobe The address decoded signals occur during PHASE flip-flop. 0, or more accurately, the address decoded signals $C07X Trigger paddle timers. slightly lag PHASE 0. There is always some lag of a logic term behind the signal that controls it. In the The last category of signals controls the peripheral Apple. PHASE is a safe time to read the address slots: bus. because the 6502 address is always valid. This way, the address decoded signals respond to 6502 $C080-$C0FF DEVICE SELECTS' generated addresses. $C100-$C7FF I/O SELECTS' Some of the address decoded signals are data bus $C800-$CFFF I/O STROBE' management gates. The function of these signals is to gate data to the data bus for reading by the MPU, These signals and their functions are: The functions of these address decoded signals were described at some length in previous chapters, $coox Gate keyboard data to data and some of the functions are pretty obvious from bus. Figure 7.1. However, alittleelaboration concerning $C06X Gate serial inputs to D7 of the the signals won't hurt. data bus. The DEVICE SELECTS', I/O SELECTS', AND $DOOO'$FFFF Gate ROM data to data bus. I/O STROBE' are connected to the peripheral slots where they can control peripheral cards. Decoding Other signals control serial toggle outputs: these signals on the motherboard, rather than on the cards themselves, eliminates redundant hardware $C02X Toggle cassette output. on the peripheral cards. It also makes it easy to $C03X Toggle speaker. design cards so they will operate in any slot. Have a look at the game socket in Figure 7.1. The The screen modes are controlled by off/on soft pins on this socket are available to external devices switches. such as joysticks with pushbuttons. Additionally, $C050/$C051 GRAPHICS/TEXT the four annunciator signals and the C040 STROBE' ?C052/$C053 NOMIX/MIX are tied directly to pins of the game socket. The $C054/$C055 PAGE1/PAGE2 three pushbutton inputs (PBO, PBl. and PB2) are $C056/$C057 LORES/HIRES actually TTL inputs to the serial input multiplexor. 7-4 Understanding the Apple II They could be used for all sorts of serial input but LSTTL flip-flop is not capable of driving a 2 1/4" are normally used for pushbuttons. The four paddle speaker. The screen mode control signals are not inputs (PDLO, PDLl, PDL2. and PDL3) are tied to a output signals, but they control the Apple's primary quad timer. These inputs are not high/low binary output, video. They do this by selecting screen voltage inputs like the pushbuttons. For that mat- memory in the RAM address multiplexor and by ter, the timers are not d igital devices, although they selecting the processing mode in the video generator. do have TTL coimpatible outputs to the serial input The last thing to discuss in Figure 7.1 is the key- multiplexor. board input. The 7-bit ASCII representation of The way each timer works is this; first, the timers whatever key was last pressed is stored in a big IC on are triggered by a $C07X access. The outputs of the the keyboard itself. This 7-bit latched keyboard data four timers then go high and each one stays high for isconnected through a short DIP jumper to the a period of time determined by the position of the RAM/keyboard data multiplexor. Another out- paddle connected to its input pin. The paddles are put from the big keyboard chip is the keyboard really variable resistors which vary the time con- STROBE, which goes high for about 20 micro- stant of the input circuits to the timers. The timer seconds when any key is pressed. The leading edge outputs are connected to the serial input multi- of the STROBE sets a flip- flop on the motherboard plexor so their high/low states can be read by a whose output is connected to the most significant bit program. The programming method is to trigger input of the RAM/keyboard data multiplexor. When thefourtimers, then poll the output of the pertinent a read to$COOX is performed, the keyboard word is timer in a loop while counting the program loops placed on the data bus for reading by the MPU. The before the timer resets. MPU reads the 7-bit latched keyboard ASCII and The eighth input to the serial input multiplexor is the state of the keyboard strobe flip-flop. the cassette input. The cassette input jack of the The strobe flip-flop is reset on power up and by Apple is connected to a high gain amplifier/shaper. any access to $C01X. This enables the programmer The amplifier takes the small signal from the ear- to check for a keypress by resetting the strobe flip- phone jack of a cassette player and converts it to flop, then polling $C000 until he finds the most sig- high and low voltages which can be read correctly nificant bit set. by the serial input multiplexor. Of course, you can The I/O assignments of various addresses are sti II ad ju st the cassette p ay er volu me too h igh or too I important information for Apple programmers. low, but the amplifier gives you a very reasonable Table 7.1 can serve as a reference for address chance of selecting a volume which works. decoded software commands. It can also serve as a The serial input multiplexor selects one of its memory map of the ^COOO-SFF'FF^ address range in eight inputs for output to D7 based on AO, Al, and the Apple. Figure 7.1 and Table 7.1 go a long way in A2 from the address bus. This is a good example of describing the particular programmable features how things come in groups of eight or other powers of the Apple II computer. of two in digital computers. Three address lines can be in eight different states, so 8 to 1 multiplexors exist for computer designers to use. This naturally ADDRESS DECODE HARDWARE leads to a computer with eight serial inputs. There is Let's look at the hardware which produces all an operational oddity in the Apple that there are these signals by monitoring the address bus. The four paddle inputs but only three pushbutton inputs. circuitry is pictured in Figure 7.2. Would you It becomes logical in the light of hardware conve- believe it? It's done with just five LSTTL integrated nience. Eight serial inputs minus four timer inputs circuits, four LS138s and an LS259. The LS138 is minus one cassette input leaves room for three designed to do exactly this sort of task and make it pushbutton inputs. look easy. What it does is take a 3-bit address input Moving along, we come to some fairly obvious and bring one of eight lines low depending on the signals at the bottom of Figure 7.1. The cassette state of the address inputs. Eight lines, eight slots, output simply toggles every time $C02X is accessed. two to the power of three: what a nice number of The toggling device is just a flip-flop whose output is slots to have in a digital computer. reduced to the level of a signal from a microphone Here's the scheme for dividing up the $C00O- then routed to the cassette output jack. The speaker $FFFF address range. First, divide the range into output is also a toggled output, but the output of its eight 2048 byte sections using the LS138 at F 12 (see togglingfljp-flop is routed to the speaker through an Figures 7.2 and 7.3). These eight sections are ad- amplifier. The amplifier is necessary because an dressing for the six ROM chips, the "seventh ROM" I Address Decoding and Input/Output 7-5 {$C8G0-$CFFF), and the I/O Section ($C000- Most of these control signals are not broken down $C7FF). Then divide tlie I/O Section into eight 256 any further, For example, the cassette output line byte sections using the LS138 at H12. These eight can be toggled by a reference to any of the 16 sections are the seven I/O SELECT' ranges and the addresses in the $C02X range. The programming rest of I/O control ($COOO-$COFF). The $C000- convention is to address these 16-bit ranges by their $COFF range is divided in two groups by A7 and A7' lowest address. $C030 for example. The $C05X gating. The A7 group is divided into eight 16 byte range is broken down into eight off/on soft switches sections by the LS138 at H2, These are the eight by the LS259 at F14. These are the annunciators and DEVICE SELECT' ranges. The A7' group is screen mode control signals. The $C06X signal per- divided into eight 16 byte sections by the LS138 at forms the function of gating the serial input multi- F13, These are the motherboard control signals. plexor (See Figure 7.5) to D7 of the data bus. One of Table 7.1 Address Decoded Signals. FUNCTION HEX RANGE DECIMAL RANGE DECIMAL COMPLEMENT RAM* $0000 to $BFFF 00000 to 49151 -65536 to -16385 READ KEYBOARD ICOOX 49152 to 49 167 -16384 to -16369 RESET KEYBOARD STROBE $C01X 49168 to 49183 -16368 to -16353 TOGGLE CASSETTE OUTPUT $C02X 49184 to 49199 -16352 to -16337 TOGGLE SPEAKER $C03X 49200 to 49215 -16336 to -16321 C040 STROBE $C04X 49216 to 49231 -16320 to -16305 GRAPHICS $C050 49232 -16304 TEXT $C051 49233 -16303 NOMIX $C052 49234 -16302 MIX $C053 49235 -16301 PAGEl $C054 49236 -16300 PAGE 2 $C055 49237 -16299 LORES $C056 49238 -16298 HIRES $C067 49239 -16297 ANO LOW $C058 49240 -16296 ANO HIGH $C059 49241 -16295 ANl LOW $C05A 49242 -16294 ANl HIGH $C05B 49243 -16293 AN2 LOW $C05C 49244 -16292 AN2 HIGH $C05D 49245 -16291 AN3 LOW $C05E 49246 -16290 AN3HIGH $C05F 49247 -16289 READ CASSETTE INPUT $C060/$C068 49248/49256 -16288/-16280 READ PUSHBUTTON $C061/$C069 49249/49257 -16287/-16279 READ PUSHBUTTON 1 $C062/$C06A 49250/49258 -16286/-16278 READ PUSHBUTTON 2 $C063/$CO6B 49251/49259 -16285/-16277 READ TIMER $C064/$CO6C 49252/49260 -16284/-16276 READ TIMER 1 $CO65/$C06D 49253/49261 -16283/^16275 READ TIMER 2 $C066/$C06E 49254/49262 -16282/-16274 READ TIMER 3 $C067/$CO6F 49255/49263 -16281/-16273 TIMER TRIGGER $C07X 49264 to 49279 -16272 to -16257 DEVICE SELECTS' $C080 to $COFF 49280 to 49407 -16256 to -16129 I/O SELECTS' $Cl00to|C7FF 49408 to 51199 -16128 to -14337 I/O STROBE' $C800 to ICFFF 51200 to 53247 -14336 to -12289 ROM ENABLES' $D000to$FFFF 53248 to 65535 -12288 to -00001 *RAMSELECT' is not decoded directty froiri the address bus. t is decoded from the screen rnode during PHASE 1 and from the address bus during PHASE:o. 7-6 Understanding the Apple II PHASE 1 53 ROM ENABLE \ FQ TOM ENABLE' £8 ROM ENABLE' ^(6.1) EO ROM ENABLE' ROM ENABLE' D8 ROM ENABLE' DO ROM ENABLE'/ I/O STROBE'TO PIN 20 OF ALL PERIPHERAL SLOTS (710) USER1 '^^'^''^'^ USER 1 FROM PiN39 0FALL PERIPHERAL SLOTS —O O- 8< ' (7.10) >L-™-!/0 SELECT' 7 "^ A10- Y6|ci-2^|/0 SELECT' A9 — Y5 o!5-5^^l'0 SELECT' WX I A3 74LS13B ^ 11 1^0 SELECT' -(7,9) I/O SELECT' DECODER )2 C3XX |,Q g^L^Qy, 3 ^ 5V^ 16 :>!^-^^^l/0 SELECT' vcc GND )!iil^ I/O SELECT' 1 > 15 COXX D- PHASE 1_ (3.8) A7- CONTROL ^^- DEVICE SELECT' PHASE - 16 {S 6_QlOl (3.8)' E3 El yjv j ^^^^ TIMER TRIGGER (7.5) E3 E2 El Y7D^ — -^22LdEVICE SELECT' 7\ C5EX_pgyu,g g^LECT' 6 *6 —2. Y6 ^3 A6- Y6 joL-COe^LsERIAL IN (75) 10 CODX A5- Ft3 Y4 >!1™*^:M0 STROBE (75) AS HZ Y5 ^ pgyi^g 5^,^^^,^. 5, 74LS138 74LS138 jll^"^^ S PEAKER (75) A^ Y4 ^1L-^2£L DEVICE SELECT' 4 A4- DECODER (7.9) DECODER y^^12 COBX ^13 C02X CASSETTE OUT (7,5) DEVICE SELECT' ^IJCOIX p^gggT KEYBOARD STROBE (77) Y2 q1^—5M_DEVICE SELECT' 2 Y1 ^°^^ VO ^15 CQOX_ p^g KEYBOARD ^y ig Y1 g1^ DEVICE SELECT' 1 5V_ 15 VCC (5.2. 5.10) VCC V5 ^10 GfJD YO ^IL-^LdevICE SELECT' 0> GND C05X T 16 C(B0/CO51 VCC E -GRAPHICS/TEXT (8.6) C052/CO53 A3- -NOMIX/MIX (8.6) C054/C055 SOFT SWITCHES A2- -PW5E1/F1AGEZ(5,10) F14 74LS259 C056/C057 A1- A -LORES/HIRES (8.6) ADDRESSABLE C058/C059 LATCH Q4 -ANO OFF/ON^ 10 CQ5A;C05B AO- DATA Q5 -AN1 QFF^ON IN (75) C05C/C05D Q6 -AN2 OFF/ON SOFT 5-11 15, ^ 12 C05E/C05F (3.9) ^' -AN3 Offm GND J Rgur© 72 Schematic: Generation of Address Decoded Signals. Address Decoding and Input/Output 7-7 ROM EWABLE' F12 HI I/O SELECT' I/O CONTROL H12 F13 i r nTTTTTT f I 1 I l I I i I I ^ H M I I I M H2 DEVICE SELECT SERIAL IN MUX H14 iTTMTTTi \aaaaaaaX F14 SOFTSWITCH C7XX C6XX C5XX C4XX F8 FO E8 EO D8 DO C8 C3XX C2XX C1XX imiHNiiiiii ^COXX Hgure 7^ Address Decoding In the Apple Is an Exercise In Division by Eiglit. 7'6 Understanding the Apple I eight serial inputs are selected by this multiplexor there are eight peripheral slots; there are only based on AO, Al, and A2 from the address bus. This seven I/O SELECT' signals; the I/O addressing divides the $C06X range into two identical octets. range is the same size as a 2K ROM; six I/O $C060'$C067 and $C068-$C06F. The programming control address ranges are 16 bytes wide, result- convention is to address the lower octet when read- ing in a wastage of 90 bytes; there is only one ing a serial input. Therefore $C064 should be read trigger for the four timers instead of a separate when checking Timer 0, not $C06C. trigger for each timer, and there is no timer There are several interesting subtleties of the reset signal. connections in Figure 7.2: 1. F12, H12, F13/H2. and F14 are connected in a chain, F14 must be enabled before any of the other ICs in the chain can be enabled. Thus, a I/O TIMING single AND gate connection to F12 detects the I/O timing is the timing of the address decoded $COOO-$FFFF range for all these ICs from A14 signals. All motherboard I/O and most peripheral and A15. slot I/O is controlled by these signals. An access to a 2. PHASE 1 is connected to an active low enable DEVICE SELECT' address is sufficient to illus- input to F12. so PHASE high is a prerequisite trate timing for all the address decoded signals for any address decoded action above $BFFF. because of the enabling chain which winds through Then why is PHASE 0/PHASE 1 gating also the LS138S. For example, before any DEVICE connected to F 13 and H2? It takes a long time to SELECT' signal can drop low, the COXX signal bring the F13 and H2 outputs high or low when must drop low. The COXX signal is identical in tim- the enabling term is propagated through three ing to the I/O SELECT' signals, so I/O SELECT' LS138S. Connecting PHASE 1 and PHASE timing is also illustrated. directly to F13 and H2 results in a quicker Figure 7,4 shows the read and write timing for an cutoff of outputs of these chips after PHASE access to $0080. The read and write are identical falls. Apparently, the Apple designers did not except for data bus management. Data bus man- want the DEVICE SELECTS' and C06X to lin- agement in a write to $C080 is identical to that of ger past PHASE 0.* RAM in a write cycle, because R/W dropping 3. If the USERl jumper is connected and a peri- always isolates the data bus for control by the MPU. pheral card brings pin 39 low. all address de- The read cycle data bus management is different coding between $C000 and $C7FF is inhibited. from that of a RAM read cycle, because RAM This 2K of addressing then becomes available SELECT' rises during PHASE when reading for any sort of peripheral card response. The six from an address above $CO0F. ROM ENABLE' signals and I/O STROBE' are When accessing $C080. the C000-C7FF, COXX, notaffected by USERl. and C08X signals fall in succession after PHASE "4. R/W gating is not connected to the address rises. The LS138 chain is ready to be controlled by decode chain. Therefore command of Apple fea- PHASE since the MPU address has long since tures can be via read or write access. However, been valid on the address bus. The typical high to if you write to aROM address or a serial input low propagation time of an active low enable signal address, the ROM or serial input multiplexor through a LS138 is 21 nanoseconds, so the DEVICE will compete with the MPU bidirectional data SELECT' signal falls about 63 nanoseconds after bus driver for control of the data bus. This is an PHASE rises. This is true of any signal in the undesirable situation which should be avoided. $COXX range, $C06X for example. This means that 5. The division of $COOO-$FFFF addressing in the the DEVICE SELECTS' are identical to the mother- Apple is a very admirable example of design board serial input data bus gate. The implication is efficiency and creativity. It is a real work of art, that the DEVICE SELECT' is a valid data bus considering how usable the Apple turned out to management signal for peripheral cards. In fact, be. The decoding layout results in operational the I/O SELECTS', the DEVICE SELECTS', and features of the Apple which we take for granted: the I/O STROBE' all work very nicely for data bus management. This is in spite of the fact that they all *Steve Wozniak ffives Alan Baum much of the credit for the design of this area. I feel that they would have been better off to rise before 6502 PHASE 2 falls. The reason they let DEVICE SELECT' linger a bit past PHASE 0. and I suspect work is because of the slow bleed off of data from the that Woitniak and Baum wou Idn't argue the point too vigorously. floating data bus. Address Decoding and Input/Output 7-9 6502 PHASE 2 I PHASE SCANNER ADDRESS MPU ADDRESS CO00-C7FF F12-15 (ROM ENABLE' EQUIVALENT COXX H12-15 (I/O SELECT' EQUIVALENT) C08X H2-15 (DEVICE SELECT) RAM SELECT' READ CVCLE FLOATING BUS IS AVAILABLE FOfl DATA BUS MPU DATA SFF CONTROL BY PERIPHERAL CARD "N R/W I WRITE RAM SELECT' 6502 Phase 1 controls the. r CYCLE direction o( the MPU bi-directlDnal bus driver FLOATING BUS STORES MPU DATAl DATA BUS MPU DATA 6502 WRITE DATA VALID ON DATA BUS I J Floatinci data bus stares write data until after R/W rises Figure lA Timing Example: 6502 Access to $C080. SERIAL I/O HARDWARE The standard paddle set has two pushbuttons, one for each paddle. These pushbuttons are designed to Figure 7.5 is a schematic of Apple's serial I/O bring the input of an LS251 (the serial input multi- devices. The only connection to the outside world for plexor) high or low for transfer to D7 of the data bus. most of these I/O devices is through the game I/O When a button is pushed, 5 volts is applied to the socket, and the inputs are connected to D7 of the LS251 input. When the button is released, the LS251 data bus through the serial input multiplexor. Fig- input is pulled to ground through a 560 ohm resistor. ure 7.5 shows a standard joystick or paddle set con- The two pull-down resistors in a paddle set are nected to the game I/O socket. This illustrates the installed in the plug which is inserted in the game fact that plugging a standard paddle set into the I/O socket. They are well hidden to confuse hard- game I/O socket makes eight serial input or output ware investigators who are trying to figure out how ports inaccessible. the Apple works. Just kidding. Apple, do you know 7-10 Understanding the Apple s 3 IE ^1 ^i fol cm! tol cr>A (Ol CD SS 03 3 O ,"^ U. ii >C S Z 2 CJ U S Address Decoding and Input/Output 7-1 how much production cost you could have saved on typical timer polling routine. Needless to say, pro- 750,000 Apple lis by mounting pull-down resistors gram speed is inversely proportional to the time on the motherboard instead of wiringthem into that spent polling the timers. Were the Apple designed tiny little DIP plug? today one would suspect that modern multichannel The paddle knobs are attached to 150,000 ohm quick response analog to digital converters would be potentiometers (variable resistors). Each of these used for paddle input rather than timers. potentiometers is part of an R/C (Resistance/Capac- A final interesting feature of the Apple timer itance) network which determines the pulse width connections are the open-collector outputs. What is of one of the outputs of a quad timer. They are interesting is that there are no pull-up resistors con- designed so that the pulse width in microseconds nected to them. One would have to walk all the way will be equal to (RP + 100) X .022 where RP is the to Omaha to find another successful commercial resistance of a paddle. Since the paddles are 1 50,000 design with open collectors driving LSTTL inputs ohm pots, the timer outputs can be varied from 2 without pull-up resistors. It works without pull-up {100 X .022) to 3300 (150100 X .022) microseconds. resistors, but the conventional wisdom says to pull The four timer outputs are connected to the serial up open collector outputs to achieve satisfactory input multiplexor so their duration can be counted noise immunity. I wonder why they didn't bother in in a polling loop by the controlling program. Of the case of the Apple timer inputs to the serial input course, a standard paddle set uses only two of the multiplexor. four available timers. After the timers and pushbuttons, the remaining The NE558/SE558 quad timer has a RESET serial input is the cassette input. What we have here input w^hich brings all four outputs low and inhibits is an electronic circuit which answers the question, triggering. This feature is not utilized in the Apple. "when is an operational amplifier not an operational Each timer has its own input trigger, but in the amplifier?" The answer is that an LM741 opera- Apple, all four triggers are tied to the C07X line. To tional amplifier is not an operational amplifier achieve the reset and individual trigger capabilities when there is no degenerative feedback. It then would have required extra addressdecoding circuit- becomes a saturated amplifier and, in the case of the ry and possibly would have decreased the perfor- Apple cassette input, a threshold detector/signal mance/cost ratio of the Apple. As it is, the common shaper. Mild apologies for all that electronic lan- trigger gives the capability of simultaneously read- guage, but this is an electronic circuit. What it does ing two or more paddles, and the lack of reset merely is this: requires waiting for timer reset at the beginning of 1. Blocking capacitor CIO removes any DC com- timer polling routines. Unfortunately, neither or ponent of the input voltage and makes the pin 2 these realities is supported by Apple firmware. input to the LM741 vary above and below The timer set up in the Apple is an astonishingly volts. cheap way to achieve a four channel analog to digital 2. The LM741 acts like a threshold detector. If the input capability. Variable resistors exist whose re- voltage at pin 2 rises above .15 volt (very sistance is proportional to light, heat, linear motion, approximately), the voltage at pin 6 will go as rotational motion, chemical composition, and prob- negative as an LS741 can bring it (about -4.3V) ably a lot of other pertinent things. This means that operating from a -5 volt negative supply. If the you can monitor all these qualities with an Apple voltage at pin 2 lowers below -.15 volt (very computer via the quad timer. Of course, it takes a approximately), the voltage at pin 6 will go as while to read these resistances, 22 microseconds per positive as an LM741 can bring it (about +4.3V) thousand ohms. On the other hand, how much is the operating from a +5 volt positive supply. Thug, temperature going to change in a thousand as long as the cassette input exceeds the input microseconds? threshold, the voltage at pin 6 will be an 8.6 volt The one thing the timers are the least suited to do p-p squared signal that switches high or low as is the thing they are used quite often for, game the input crosses the low threshold or high controllers for real time arcade type games. A threshold. sophisticated HIRES arcade game on the Apple 3. Pin 6 of the LM741 is connected to the serial requires all of a programmer's skill if the result is input multiplexor through a 12 thousand ohm fast paced realistic action. The 6502 in the Apple resistor. While K13-6 is at +4,3 volts, 4.1 volts or executes an instructionevery three or four microsec- so is felt at H14-4. While K13-6 is at -4.3 volts, onds. It takes about 500 times as long to perform a the negative input clamp of the LS251 holds the 7-12 Understanding the Apple I Square wave which stored digital information to cassette recorder Distorted playback signal is present at cassette input jack HIGH THRESHOLD LOW THRESHOLD *4.3V Originally stored square wave is reproduced at pin 6 of the LM741. -4,3V ngure 7 A Cassette Input Wove Shaping voltage at pin 4 very close to zero volts, and the The audio output is also controlled via a toggling 12 thousand ohm resistor limits input current to flip-flop. The output of the audio flip-flop controls a about .36 milUamps. simple amplifier which drives the Apple's speaker. The neat thing about the cassette input circuit is Current flow through the speaker is in only one direction so the speaker action is tension/relax that even when your cheap tape recorder distorts a digital square wave, a square wave of correct pulse rather than push/pull. Alternate references to width is presented to the input of the serial input $C03X tension the speaker d iaphragm then relax it, multiplexor. Figure 7.6 shows what happens when a but the program cannot determine whether a $C03X reference causes tension or relaxation. This damp- $30 tape player makes a sine wave out of your square wave. The LM741 still switches at points separated ens the possibilities of complex program control of the speaker tension. In any ease, an audio cycle con- in time by multiples of the period of the program sists of a tension half cycle and a relaxation half loop that stored the information to cassette. Of cycle, so two $C03X references are required per course, there are limits to the distortion which an Apple can work with. audio cycle. For example, to program a 1000 Hz tone, you reference |C03X 2000 times a second. The Apple 11 Reference Manual states that the nominal voltage required at the cassette input is 1 volt peak to peak. This is a voltage one would rea- sonably expect to find at the earphone output of a THE APPLE I r KEYBOARD cassette recorder. The cassette output of the Apple is a much smaller voltage, comparable in amplitude to Consideringthestatureofthe Apple II computer, the signal out of a microphone. This voltage is the its keyboard has rather modest features. In particu- output of a 74LS74 flip-flop reduced by a factor of lar, the ability to enter only upper ease from the 121. The flip-flop toggles once every access to keyboard has always been a serious draw back to the $C02X. Its output swings back and forth between Apple in sophisticated text handling applications. It and 3 volts while it is being toggled, so the cassette was a disappointment to many users for years that output jack swings between and .025volts(3/l21 = Apple did not upgrade the overall text handling .025), capability of the Apple II via improvements to the Address Decoding and Input/Output 7-13 keyboard, screen display, and firmware. It is a bit of doubt about it, they really didn't want to fool with a nuisance to resort to peripheral cards and modifi- lower case alphabetics. cations just to make a computer acceptable for word I looked at the states of unconnected B8 and B9 processing.* with an oscilloscope just to see what was pro- Actually. Apple did sig-nificantly upgrade their grammed in there. B8 is a parity bit for B1-B7. If an keyboard (circa 1979). They cured an old headache even number of lines Bl through B7 are low, BSgoes by requiring the CTRL key to be pressed before the low. If an odd number of lines Bl through B7 are RESET key can function. They also gave the key- low. B8 goes high. This means you could do a parity board an upper/lower ease capability, but they cheek on the keyboard input by connecting up a didn't tell owners how to take advantage of it or even little hardware, but it would serve no useful pur- that it was there, This upgraded keyboard came out pose. I could make no sense of B9. Outputs B1-B4 at approximately the same time as the Apple II and B9 are not affected by the SHIFT or CONTROL Plus, so we will be referring to it as the 11 Plus inputs to an MM5740. In the Apple, B9 is pro- keyboard. Apple has never published the II Plus grammed to drop low if RETURN, N, left arrow, keyboard schematic for the general public. The period, dash, colon, zero, or space is pressed. It goes schematic in the Apple II Reference Manual is the high on all other matrix keypresses. schematic of the old keyboard. The keys on the Apple keyboard are spring Figure 7.7 is a schematic diagram of the old key- loaded, normally open switches with plastic covers board. It is based on the National Semiconductor which can be pried off if a switch fails and needs to MM5740 keyboard encoder ROM. which is no be replaced. The keys are labeled 1 through 55 with longer manufactured. The MM5740 supports up to no #27 or #41 key. The power-on indicator is labeled 90 keys in a 9 x 10 matrix, and it works by scanning #54 even though it is not a switch. Forty-seven of the through its X-drivers while checking its Y-sensors. keys are in the MM5740 input matrix. All keys on The code that is generated from each keypress is the matrix perform no function except to produce specified by the buyer of the encoder ROM (Apple code which must be interpreted by a program. The Computer Inc.). The code is latched every time a key RESET key is connected directly to the system in the matrix is pressed and it is gated to nine output RESET' line. The left SHIFT, right SHIFT, and pins through tri-state outputs. The fact that the out- CONTROL keys are addressing inputs to the puts are latched means that you can press a key and MM5740 which select among four possible sets of its 7-bit ASCII can be checked anytime before output code. The SHIFT line is also active at power another key is pressed. In the Apple, two of the up although I am baffled as to why the encoder outputs are not connected (B8 and B9). and the tri- should be up-SHIFTED at power up. The REPT state outputs are always enabled by a ground at pin key enables a 10 Hz oscillator which feeds the 15. The B1-B7 outputs, which are active low, are MM5740 REPEAT input. When REPT and a matrix inverted and routed through the 16-line keyboard key are pressed simultaneously, the 5740 puts out a jumper to the tri-state RAM/keyboard data STROBE 10 times a second to simulate 10 key- multiplexor. presses per second. This REPEAT rate can be The MM5740 is capable of producing different increased by reducing the value of R3 or vice versa. code at outputs B5, B6, B7, and B8 for ALONE, The MM5740 requires an input clock between 10 CTRL. SHIFT, and CTRL-SHIFT input modes. KHz and 200 KHz. The Apple supplies this from a This means that the Apple could have come with ring oscillator which runs at 50 KHz in the author's upper and lower case alphabetic character input Apple. The freq uency of th is type of oscillator is very from the keyboard at no extra manufacturing cost. unpredictable, but it is perfectly adequate for this Rather than doing this, they specified that the purpose. encoder output code for all alphabetic keys except Pin 1 on the MM5740 is a keybounce mask input. M, N, and P would be the same whether SHIFT was The MM5740 data sheet shows that the encoder will pressed or not. The MM5740 also has a SHIFT mask keybounees for 8 milliseconds if pin 17 is con- LOCK input which is not connected in the Apple. No nected to ground through a .001 microfarad capaci- tor. In the Apple, pin 17 is connected to +5 Volts through a .001 microfarad capacitor. Apparently Most readers are probably aware that the text hatidlintr capabil- this works. If you often get two letters on the screen ity of the Apple lie is greatly superior to that of the Apple II. from one keypress, you can experiment with in- Please remember that these discussions apply to the Apple II only as it was before the introduction of the Apple lie in early creasing the value of C4, and you might try connect- 1983. ing C4 to ground instead of +5 volts. 7-14 Understanding the Apple I a o^ I S iE Address Decoding and Input/Output 7-15 The encoder outputs a positive STROBE one time encoder ROM, a General Instrument AY-5-3600 when a matrix key is pressed, and 10 times per instead of the MM5740. This encoder is very similar second if a matrix itey is held simultaneously with to the MM5740 with a 9 x 10 switch matrix, nine low the REPT key. When pin 13 istied to pin 14, as it is in level outputs and. -^5V/-12V power supply require- the Apple, the STROBE stays high for one period of ments. As an option, Apple could have specified that the input clock. This is 20 microseconds with a 50 the encoder would have an output enable pin like the KHz clock. The Apple II Reference Manual says the MM5740, but they chose not to since the Apple STROBE lasts a maximum of 10 microseconds. This design doesn't utilize this feature. is probably a safe number they arrived at, figuring A major difference in the mechanical package in the ring oscillator would never get above 100 KHz. the II Plus keyboard is that all electronics are The STROBE output of the MM5740 is routed removed to a small card, physically separate from through two inverting stages to the motherboard the main card. The big card contains only key where its rising edge sets the keyboard strobe flip- switches and the power indicator. The small card, flop. The strobe flip-flop is reset under program called the encoder board, is connected to the big control by a $C01X access. card via a 25-pin connector with exposed pins. The Figure 7.7 also shows the Apple's power-up reset pins of this connector, PLUG 1 on the encoder board, generator which is installed on all Revision 1 or later are shown in Figure 7,8 as numbers in circles. motherboards. This is a 555 timer which outputs a .3 The keyboard/motherboard jumper is connected second pulse when the Apple is turned on. This pulse to a 16-pin DIP socket, JACK 1, on the encoder resets the keyboard strobe flip-flop and also forces board, The pin assignments are identical to the key- the RESET' line low. The 6502 reset sequence actu- board connector on the old keyboard. It may not be ally begins when RESET' rises. The .3 second possible, buttry not to confuse JACK 1 with PLUG 1 RESET pulse at turn on gives the Apple power on the small board. They are not the same, but are supply voltages time to stabilize before the 6502 and considered part of two separate PLUG 1/JACK I the rest of the Apple are off and running. Next time combinations following some perverse engineering you turn an Apple on. listen carefully. There is a logic. perceptible .3 second delay before the BELL sounds A third connector on the encoder board, JACK 2, and the disk starts running. If you have a Revision is not actually there. There are mounting holes for board and a Disk II controller, the controller will JACK 2, and they are fully wired so you can solder a generate a .1 second power-up reset. If you have a jack in and plug a numeric keypad into it. The four Revision board and no Disk 11 controller, your matrix scanners X5 through X8 are used only by the unmodified Apple will not automatically reset at numeric keypad, which isshown installed in Figure power up. 7.8. The pins of JACK 2 are represented by little This, then, was the Apple keyboard before the squares with numbers in them in Figure 7.8. The Apple II Plus modifications; 52 keys, uppercase dedication of four X-drivers to a numeric keypad is alphabetics only, no numeric keypad, no SHIFT possible because the keyboard has only 47 matrix LOCK switch, no user programmable function keys, switches and can operate with just a 5 by 10 switch no automatic repeat, no dedicated cursor move keys, matrix. Apple has never sold a keypad that supports no dedicated screen mode selection keys, teletype JACK 2, but at least one has been built by an outside style placement of symbolic characters, latched source. Yet a 16-key numeric keypad for the Apple output flagged by a program resettable strobe flip- II Plus would be very cheap to manufacture, because flop whose state is read in the MSB of the keyboard the capability is built in. Also, it would be easy to input word. After the II Plus? Pretty much the same bui Id your own 16-key keypad from a surplus calcu- operationally but quite different in hardware lator entry panel. A 24-key keypad requires elec- mechanization with some unadvertised attainable tronic circuitry to decode a 4 x 6 matrix and switch capabilities. Take a look. between the keypad and the keyboard at the key- board connector. The Apple II Plus Keyboard The SHIFT keys and CTRL key are connected up Figure 7.8 is a schematic diagram of the Apple 11 very much as in the old keyboard, except there is no Plus keyboard. I drew the schematic after studying forced SHIFT-up at power on. The RESET key is an actual keyboard. The 11 Plus keyboard has an different though. There is a slide switch, SI, by underlying similarity to the old keyboard with some which the owner can select CTRL required or CTRL obvious changes. Most obviously it uses a different not required for RESET. Believe it or not, I knew an 7-16 Understanding the Apple If U5 AY-5-3600 KEYBOARD ENCODER ROM xo xi n X3 u )C5 !<6 ti xe J1 16 PIN DIP 40T m_ IT 371 361 35 34 33 32 JUMPSR TO M) (14) MOTHERBOARD (13) (11 POWER t CR--4PC + 5V ai INDICATOR I 1 ^^^ lc3'-^dS-f^ Ici ^VF^^g)MO yVF GND-!3 ' 1 -j-— ISA ^Ih 27 .IjlF 15 ^12V VGG vriFr, 12 fo 3^ -.- 39 ^ CR Hirg IM 7404 12 12 ^ 'KO 21' 58 >, .49 25 • YB i>> ii 2? + 37 < ^ 10 13 I 24 B2 V7 uiL L H 1 47 ?3 J2 6 10 -».K2 ye 83 D^ JO 35 46 ,53 SP 22 LATCHED YS KEVBOABD m;> -#-K3 ^ J .34 DATA TO RAM/ Y4 42 B6> NC „ -NC ¥1 NCt^ -MC \s.\ -NC 30 . 7400 -NC YO B7 "7 U3J03 -K6 ) —c^o- r^ LSHin;(40) SHIFT RESET RESET FROM 3 R2 R. SHIFT, (51) P1-22 SEE 12M^ec 4.7K* 5V "^4 ™0 7400 } FIG DWA ?7 READY STROBE ft3 7400 ,2 STROBE —CT CONTROL. (27) 0-(3> 47K< 28 COMTBOL I Re POOR MANS ONE SHOT SI flE^ a3) ' RESET V>. TOJ1-3 CONTROL 0-(22V^ ^^ KEYBOARD CONNECTOR 23)0 7400 7400 1 NC^ 5V BOKHz CK3 7400 NC R1 ^ C6 5« 51 49 $AE $AE $BE $BE $AE $AE $BE $BE / ? 52 50 $AF $AF $BF $BF $AF $AF $BF $BF 10 10 $B0 $B0 $B0 $B0 $B0 $B0 $B0 $B0 1 1 1 1 $B1 $B1 $A1 $A1 $B1 $B1 $A1 $A1 2 " 2 2 $B2 $B2 $A2 $A2 $B2 $B2 $A2 $A2 3 # 3 3 $B3 $B3 $A3 $A3 $B3 $B3 $A3 $A3 4 $ 4 4 $B4 $B4 $A4 $A4 $B4 $B4 $A4 $A4 5 % 5 5 SB5 $B5 $A5 $A5 $B5 $B5 $A5 $A5 6 & 6 6 $B6 $B6 $A6 $A6 $B6 $B6 $A6 $A6 7 7 7 $B7 $B7 $A7 $A7 $B7 $B7 $A7 $A7 8 8 8 $B8 $B8 $A8 $A8 $B8 $B8 $A8 $A8 ( 9 9 9 SB9 $B9 $A9 $A9 $B9 $B9 $A9 $A9 ) • * 11 11 SBA $BA $AA $AA $BA $BA $AA $AA ; + 38 37 $BB $BB $AB $AB $BB 5BB $AS $AB A 29 28 $C1 $81 $C1 $81 $E1 $81 $C1 581 B 47 45 $C2 $82 $C2 $82 $E2 $82 $C2 $82 e 45 43 $C3 $83 $C3 $83 $E3 $83 $C3 $83 7-48 Understanding the Apple II Table 72 Relation of ASCI to Keypress. (2 of 2) 1 APPLE II APPLE II Plus APPLE II Pius NORMAL LOWER CASE ENABLEC ) KEY swi'ix:h# SWITCH* ALONE CONTROL SHIFT BOTH ALONE CONTROL SHIFT BOTH D 31 30 $C4 $84 $C4 $84 $E4 $84 $C4 $84 m 17 17 $C5 $85 $C5 $85 $E5 $85 $C5 $85 w 32 31 $C6 $86 $C6 $86 $E6 $86 $C6 $86 Q 33 32 $C7 $87 $C7 $87 $E7 $87 $C7 $87 H 34 33 $C8 $88 $C8 $88 $E8 $88 SC8 $88 1 arrow 39 38 $88 $88 $88 $88 $88 $88 $88 $88 I 22 22 $C9 $89 $C9 $89 $E9 $89 $C9 $89 1 3 35 34 $CA $8A $CA $8A $EA $8A $CA $8A K 36 35 $CB $8B $CB $8B $EB $8B $CB $8B L 37 36 $0C $8C $CC $8C $BC $8C $CC $8C M ] 49 47 Sm $8D $DD $9D $ED $8D $CD $9D E^ETORN 26 26 $8D $8D $8D $8D $8D $8D $8D $8D " 48 $CE $8E 1 N 46 $DE $9E $EE $8E $CE $9E b 23 23 SCF $aF $CF $8F $EF $8F $CF $8F p ? 24 24 $D0 $90 $C0 $80 $F0 $90 $D0 $80 Q 15 15 $D1 $91 $D1 $91 $F1 $91 $D1 $91 R 18 18 $D2 $92 $D2 $92 $F2 $92 $D2 $92 S^ 30 29 $D3 $93 $D3 $93 $F3 $93 $D3 $93 f 19 19 $D4 $94 $D4 $94 $F4 $94 $D4 $94 u 21 21 $D5 $95 $D5 $95 $F5 $95 $D5 $95 r arrow 40 39 $95 $95 $95 $95 $95 $95 $95 $95 \ V 46 44 $D5 $96 $D6 $96 $P6 $96 $D6 $96 w 16 16 $D7 $97 $D7 $97 $F7 $97 $D7 $97 i X 44 42 $D8 $98 $D8 $98 $F8 $98 $D8 $98 Y 20 20 $D9 $99 $D9 $99 $F9 $99 $D9 $99 z 43 41 $DA $9A $DA $9A $FA $9A $DA $9A ESC 14 14 $9B $9B $9B $9B $9B $9B $9B $9B RESET 13 13 REPT 25 25 CTRL 28 27 . SHIFT,! 42 40 ' SHIh'i',r 53 51 II Plus KEYPAD \ $B0 $B0 $B0 $B0 $B0 $B0 $B0 $B0 I 1 $B1 $B1 $B1 $B1 $B1 $B1 $B1 $B1 2 $B2 $B2 $B2 $B2 $B2 $B2 $B2 $B2 1 3 $B3 $B3 $B3 $B3 $B3 $B3 $B3 $B3 1 4 $B4 $B4 $B4 $34 $34 $B4 $B4 $B4 5 $B5 $B5 $B5 $B5 $B5 $B5 $B5 $B5 6 $B6 $B6 $B6 $B6 $B6 $B6 $fl6 $B6 7 $B7 $B7 $B7 $87 $B7 $B7 $B7 $B7 8 $B8 $B8 $B8 $B8 $B8 $B8 $B8 $B8 9 $B9 $B9 $B9 $09 $B9 $B9 $B9 $B9 space §A0 $A0 $A0 $A0 $A0 $A0 $A0 $A0 + $AB $AB $AB $AB $AB $AB $AB $AB t f $AC $AC $AC $AC $AC $AC $AC $AC - $AD $AD $AD $AD $AD $AD $AD $AD t m $A£ $AE $AE $AE $AE $AE $AE $AE RETURN $8D $8D $8D $8D $8D $8D $8D $8D Address Deccding and Input/Output 7-19 ADDRESS DECODE (7.2) VIDEO SYNC (B.6, 8.7) 14H (3.81 > DMA PRIORITY CHAI^ nc GRAPHICS TIME • 3 HAS' SuMPEnS*^^" INTERRUPT PRIORITY CHAIN NC— (B.5!BS-2| y 35 BEV 1 6 LATEd REVO Figure 7.9 Peripheral Slot Connections. 7-20 Understanding the Apple II The power supply voltages, for instance, are all No signal exists, however, which allows a peri- grouped together. One quickly sees that all the pheral card to steal the $0000-$BFFF range. This is power supply voltages available in the Apple are unfortunate since we now have 64K RAM chips and also available at the peripheral slots. would like to bank switch RAM in banks of 64K. An Paramount in importance among the peripheral Application Note at the end of the chapter on RAM slot signals are the address bus with R/W, the data (Chapter 5) shows how to steal the $O0O0-$BFFF bus, and the timing nputs. Consider what we know i address range with a DIP jumper to a motherboard about MPU control of the Apple. All data transfer is chip socket (see Figure 5,16). over the data bus under control of the address bus The USERl inhibit signal represents a poten- during PHASE 0. All I/O control is via the address tially powerful control feature that is rarely if ever bus. The correct inference is that you can duplicate used. As an example of how it could be used, suppose any motherboard action with a peripheral card you had a peripheral card which needed to lock out design. This gives you an ideaof the variety of tasks the $C08X DEVICE SELECT' signal. The card that can be accomplished. Of course, most of the could look for $C08X on the address bus during the things people are going to stuff into Apple peri- last part of PHASE 1. A $C08X detection causes a pheral slots haven't even been dreamed of yet. USERl flip-flop to nip. bringing USERl low. Other timing signals besides PHASE are avail- PHASE falling causes the flip-flop to flop return- ing USERl to its normal high state. USERl stays able at the peripheral slots. You can't have too many low for about three quarters of a cycle and inhibits of these signals at hand to help synchronize peri- the normal DEVICE SELECT' generated by $C08X pheral card functions to the motherboard. PHASE on the address bus during PHASE 0. This is really 1, Q3. 7M, COLOR REFERENCE (Slot 7), and pretty neat stuff, creating far ranging peripheral video SYNC (Slot 7) are present. Notably absent are design possibilities. 14M, RAS', CAS', AX, video scanner signals (like V5), and 6502 SYNC. With signals like these beg- The DEVICE SELECT', I/O SELECT', and I/O ging to be connected, it's surprisingthat pins 19and STROBE' are address decoded signals which iden- tify addresses on the address bus in the ranges 35 of Slots through 6 have no signal connected to assigned to the peripheral slots. These address them. Pins 19 on these slots are all tied together, and so are pins 35, yet Apple has not defined any func- rangescould have been assigned by convention only. tion for these connections. For example, a Slot peripheral card could easily decode the $C08X address range without the aid of Important 6502 control inputs are connected to its DEVICE SELECT' input, but then how could the peripheral slots. These are IRQ', NMF, RESET', you operate that card in a slot other than SlotO? The and RDY. They are connected in a wire-OR config- card would have to have switches to configure it for uration with one thousand ohm pull-up resistor.s so different slots. Also, having DEVICE SELECT' any card can cause an interrupt, reset the Apple, or decoded on the motherboard lends the force of stop the 6502 via the READY line. The RESET' tine hardware reality to the convention that |C08X is also connected to the keyboard and the power-up belongs to Slot 0. This is fairly important consider- reset circuit which generates a RESET' when the ing the diversity of sources for Apple peripheral Apple is first turned on. cards. Needless to say, decoding the address ranges Other wire-OR lines from the peripheral slots are on the motherboard also reduces the chip count of the DMA' line, the INHIBIT' line, and the USERl most peripheral cards. line. DMA' allows a peripheral card to isolate the The DEVICE SELECT' inputto each peripheral MPU from the address bus and data bus so it can slot identifies a 16-bit address range assigned spe- gain control of the Apple for fast I/O or other pur- cifically to that slot. This range is normally used to pose.INHIBIT' disables motherboard ROM and command a peripheral to do things like gate data to opens up $DOOO-$FFFF addressing for any sort of the data bus or disable one of its functions. A card response. If the USERl jumper is installed, USERl design may require only one programmed com- disables all address decoded signals in the $C000- mand like a speech synthesis board which says a $C7FF range and opens that range for peripheral word when you store a value to its only address. This card response. Note that between INHIBIT', type of card can use the DEVICE SELECT' to USERl, and the I/O STROBE' disable protocol trigger its action and it requires noon board address $CFFF disables all I/O STROBE' (reference to decoding circuitry. The Apple Firmware card has response), provisions exist for stealing the entire only two commands, enable and disable. It uses AO $COOO-$PFPF address range from the motherboard, to differentiate between the two possible commands. Address Decoding and Input/Output 7-21 A card can distinguish between 32 possible com- Their solution was to steal the DMA priority chain mands in the DEVICE SELECT' range by decod- and hang the consequences. Then they changed ing the states of AO, Al. A2. A3, and R/W. their minds with the 16K RAM cards and decided The I/O SELECT' signal identifies a 256 byte they didn't need an INHIBIT' priority chain after addressing range uniquely assigned to each of Slots all; so they jumpered the DMA IN pin to the DMA 1 through 7. This address range is normally used by OUT pin. With no published usage guide, and a 256 byte program in ROM or PROM. It has to be Apple's inconsistent example, the DMA and inter- taken up by a 256 bvte program if the card is to be rupt priority chains are really available for any sort capable of response to BASIC "PR#" and "INr of serial communication between slots. commands. What these commands do is cause pro- Some changes were made in Revision 7 which did gram flow to vector to the first address of the I/O not get into the schematic diagram in the Adden- SE LECT' range, so there must be a program stored dnm to the Reference ManjiaL I traced these out on a there if PR# and IN# are going to work. PR#0 and "dash C," RFI Revision Apple II. Figure 7.10 is the INftO are different. They cause program flow to vec- result. Basically, some video timing signals were tor to the video output and keyboard input routines made available to Slot 7 and to a 4-pin connector rather than to a nonexistent program in Slot 0. mounted between B2 and C2 on the motherboard. There is no I/O SELECT' for Slot so the card in Also, there are mounting holes for a switch and Slot will not normally be the type of card which is resistor at the E1/E2 position on the motherboard. capable of replacing the keyboard and television as A reasonable guess is that these changes support the Apple's primary input and output devices. SlotO some real or planned Slot 7 peripheral card. normally contains a memory expansion card of one $DOOO-$FFFF sort or "another which steals the THE APPLE I/O SYSTEM: KSW AND CSW addressing range from motherboard ROM. The I/O STROBE' identifies $CSOO-$CFFF The peripheral slot capabilities are determined addressing for all eight peripheral slots. This ad- by the signals connected to them, but our perception dress range could have been taken up by a seventh of how they work is very much colored by the operat- ROM on the motherboard, but the Apple designer ing systems that normally control them. The prece- elected to make it available to all of the peripheral dents for I/O control in the Apple were established slots. The idea is to store a big I/O handl ing program by the old Monitor ROM, The main precedent is on a 2K ROM or PROM on a peripheral card and that memory locations $36 and $37 always contain then give that card sole access to $C800-$CFFF the address of the Apple's primary output routine, when it is active for input or output. As is described and locations $38 and $39 always contain the in detail in Chapters, the peripheral cards utilizing address of the Apple's primary input routine. $36 this "seventh ROM" must deactivate response to and $37 are referred to in the monitor listing as the I/O STROBE' when $CFFF is detected on the CSW (Character output SWitch). and $38 and $39 data bus during PHASE 0. This protocol prevents are referred to as KSW (Keyboard input SWitch). two ROMs from simultaneously trying to control the The way the Apple presented itself to us with the data bus when I/O STROBE' goes low. The "seventh old monitor was this: at power up, KSW was set to ROM" capability makes possible such peripherals the address of a firmware routine (KEYIN) which as smart printers, smart 80-column cards, and waits for a keypress while it flashes a cursor; CSW smart EPROM programmers with driving pro- was set to the address of a firmware routine grams stored in firmware. (COUTl) which stores the accumulator in TEXT The remaining four peripheral signals are DMA memory while keeping track of the next screen IN, DMA OUT. INTERRUPT IN, and INTER- memory address. Then the monitor command inter- RUPT OUT, These are the DMA and interrupt preter was entered. This program, as well as BASIC, priority chain connections described in great detail talks to humans through the GETLN (GET LiNe) in the 6502 chapter. They are there to keep two or routine, GETLN gets a series of characters from the more cards from trj'ing to simultaneously perform primary input device which it finds by doing a similar functions. Only one card can perform DMA JUMP INDIRECT to KSWL ($38). After it gets or interrupt the MPU at a time. The priority chains each character, it stores it in an Input Buffer can be used to keep order by giving high priority to (memory locations $200-$2FF) and sends it to the lower numbered slots. When Apple designed their primarv output device by doing a JUMP INDI- firmware card, they realized that what they needed RECT to CSWL ($36). GETLN continues to input but didn't have was an INHIBIT' priority chain. and output characters until it receives a carriage 7-22 Understanding the Apple II MOUNTING HOLES FOR A SWITCH AND RESISTOR REPLACE THE RAM JUMPER PLUG AT El AND THE IC AT E2 LD194 SLOT 7 ^ SOLDER HOLES (3.8) AVAILABLE 23 GRAPHICS TIME ^ (8.6:613-13) 24 VERTICAL PRESET' (3.9:011-8) SOFTS 6RAPHIXTIME PLUS3RAS' (8.6:B&-2) 1 14M (3.8) Figure 7.10 Some RevJsion<7 Additions. return code from the input device. The program character is also output to the screen. which called GETLN is then able io examine the Any peripheral slot can be assigned as the Apple's "line" of data in the input buffer and take action primary input or output device. Slots 1 through 7 based on its contents. The GETLN roijtine is largely can be so assigned by doing a "PR#n" or "IN#n" responsible for our impression of how the Apple from BASIC or a "n CONTROL-P" or "n CON- talks to us. TROL-K" from the monitor. When a PR#1 is per- The Autostart ROM utilizes the same GETLN formed, $00 and $Cl are stored at locations $36 and routine with its JUMP INDIRECTs to KSW and $37. This means that if you do a PR#1, the card in CSW for input and output. The main difference is Slot 1 had better respond to $C1XX addressing with that if a disk drive is installed, the Autostart ROM a program, because the 6502 is going to be executing boots the DOS at power up, and the DOS connects at that address real soon. itself to KSW and CSW. In both monitors, the same To assign the card in Slot as the primary input or system is in effect where every input is followed output, you must link a Slot driving routine to the immediately by output, and the input and output Apple via KSW or CSW. In normal practice, Slot routines are determined by KSW and CSW. will not contain a card that is capable of being the CSW and KSW are the I/O links. You can ink the 1 Apple's primary input or output device. driving program for any device to the Apple and In disk based systems KSW and CSW are nor- make it the primary input or output device. This is mally set to addresses $9F81 and $9EBD in the because most programs perform input or output by DOS. Then all input/output passes through the jumping to the address contained in KSW or CSW. DOS, which checks to see if it is disk related. For As an example, you can connect a serial output example, "CATALOG" is not a valid BASIC com- device to one of the annunciator ports and place a mand, but it can be executed from BASIC while the control program in RAM. You then make this device DOS is connected, because it is a valid DOS com- the Apple's primary output by placing the entry mand. While you are entering BASIC code from the address of your control program at CSW. If your keyboard with DOS connected, entries are checked program is typical, after it outputs each character to for DOS validity before control is passed to the your device, it jumps to the COUTl routine so the BASIC interpreter for command processing. If a Address Decoding and Input/Output 7-23 BASIC program is actually running, the DOS does $CnXX, those capable of being the Apple's primary little processing of input or output data except to input or output device which have no $CnXX firm- check output data for a leading "CONTROL-D" ware, and those which would normally not be the character. The "CONTROL-D" is a flag which tells Apple's primary input or output device. The first the DOS that a disk related command follows. category includes such cards as 80-column cards, smart printer interfaces, remote terrninal inter- Entering PR#2 while the DOS is connected does faces, and the disk controller. The presence of not make Slot 2 the primary output slot. KSW and onboard firmware with response to the simple PR#n CSW still will contain $9E81 and $9EBD. The DOS and IN#n commands should be an important factor intercepts the PR#2 and does its own output setting in an Apple owner's choice among similar commer- routine. DOS maintains its own I/O links— we will cial products. call them DOSKSW and DOSCSW. DOSKSW is The second category of cards is like the first $AA55 and $AA56, and DOSCSW is $AA53 and except the user must load the driving software from $AA54. The PR#2 with DOS connected results in disk or other medium. This driving software will $AA53 and $AA54 being set to $00 and $C2. Slot 2 typically burv itself above "HIMEM" and link itself becomes the secondary output behind the DOS. If a to the Apple via CSW and KSW or DOSCSW and PR#2 is performed from a running program, Slot 2 DOSKSW. This is a definite step down in conve- will probably actually become the primary input nience from smart cards with firmware at $CnXX and output device, or it may not become connected at and possibly$C800-$CFFF. The program at$CnXX all. depending on its$C2XX firmware. If the$C2XX goes a little beyond offering the convenience of firmware automatically sets both CSW and KSW to PR#n and IN#n commands. Commercial programs some value, then DOS will be disconnected and Slot such as word processors, assemblers, and data base 2 will be connected as primary input and output. If managers allow records to be output to any slot, if the $C2XX firmware leaves DOS connected at the slot has a $CnXX driver. These programs usu- KSW, then the first time an input is performed, the RAM ally make no provision for linking output to a DOS will disconnect Slot 2 and reset CSW to address. $9EBD. The way to dp a PR#2 from a running The third category of cards is not normally linked BASIC program and leave the DOS connected is to to the Apple via KSW and CSW. A 16K RAM card is do a PRINT CHR$(4); "PR#2". The CHR$(4), CON- not a conventional I/O device but simple memory TROL-D, flags the DOS that a disk related com- expansion. A 128K card, however, may come with mand is following. The DOS typePR#2 is performed, an associated diskemulator program which does get making Slot 2 the secondary output behind the DOS. 1inked. The DMA based manual controller shown in Similar steps must be taken in assembly language Figure 4.8 is a device which would not be thought of programs. If you change CSW to $9000, then the in connection with the links. A secondary MPU card first time a character input is called for, DOS will would not be linked. A speech synthesis card might change CSW back to $9EBD. You can do one of three be linked, but it would just as often be driven by things to get around this. You can change CSW to special purpose subroutines in a larger program. $9000 and change KSW to $FD1B. disconnecting Understanding which of the three categories the the DOS entirely and connecting the keyboard as cards in a given Apple fall into is a big step in primary input. You can modify DOSCSW (AA53/4) understanding what is going on in that Apple. The to $9000. leaving DOS connected. You can also store concept of peripheral slots integrated with the bus $9000 at CSW and do a "JSR $3EA." This is a DOS structure of the motherboard is so powerful that the routine which takes the value you stored at CSW or "spirit" of the Apple may be under the control of any KSW and transfers it to DOSCSW or DOSKSW, card or associated control program. When the con- then restores CSW and KSW to $9EBD and $9E8L trol breaks down and things do not function as they $3EA is easy to remember if you remember "3 should, the owner has only his own intellect to fall EACH." back on to sort things out. Know your peripheral The various peripheral cards can be divided into cards; know your motherboard; know your operat- three categories: those with onboard firmware at ing systems; know your Apple. 7-24 Understanding the Apple SOFTWARE APPLICATION PROGRAMMING THE GAME PADDLES The PRE AD routine of the monitor is pointed out Apple. 256 loops of 12 cycles take 3011 microsec- by the Apple II Reference Manual as a convenient onds. Eleven cycle loops are a good duration to use subroutine for readingany of the four paddle inputs with plus or minus 10% tolerance components, but a to the Apple. Actually. PRE AD is used by the very small number of resistance/capacitance com- Applesoft and Integer BASIC PDL(n) expressions, binations might never allow the PREAD routine to and it is called by many programs you might pur- reach a count of 255. It is possible that Apple speci- chase for the Apple. There are some limitations to fies plus or minus 5% on the capacitors or the poten- PREAD which are not irreversible limitations of tiometers. Most Apple paddles have a large slack the Apple. They're just weaknesses in a program. area on the clockwise side where PREAD returns This Application Note explores the PREAD routine 255 no matter where you set the paddle. This is and illustrates some alternate prog^ramming because PREAD allows for component tolerance. methods for reading the timers. An improved Apple would have a large resistance PREAD is designed to read the paddle whose trimmer pot across each paddle which would let the number (0-3) is contained in the X-register. For ownercalibrate his paddlesettoeleven cycle polling instance, if you want to read Paddle l.you place 1 in loops. the X-register and do a"JSR$FBIE." PREAD will So the PREAD routine polls the timer in a loop return with the Accumulator scrambled and a which takes into account realistic possibilities of number from to 255 in the Y- register which component variation. That is all to the good, and represents the position of the paddle. The way PREAD is an adequate utility for many purposes. PREAD works is this: There are. however, some weaknesses in PREAD. 1. It begins by triggering the four timers (LDA Try running the following Applesoft program: $C070). 2. After 10 cycles, it begins polling the pertinent 10 FOR A = TO 500 : NEXT : timer {$C064,X) in an eleven cycle loop. The A = PDL(0) Y-register is incremented in the loop and thus 20 B = PDL{1) : HOME : accumulates the number of loop executions. PRINT A;" ";B : GO TO 10 Program flow exits from PREAD when the per- tinent timer is found to be reset. It simply reads the paddle inputs and prints them. 3. If the polling loop is executed 256 times, the The FOR/NEXT loop is a short delay to minimize routine is exited immediately with 255 in the screen flicker. With the program running. leave Y-register. Paddle 1 fully clockwise and change Paddle to The PREAD comment in the monitor listing savs some low setting. The result is that Paddle inter- "COUNT Y-REG EVERY 12 USEC." This is not feres with Paddle 1. This is because all four timers true; the Y-register counts approximately every 11 are triggered every time $C07X is accessed. In the microseconds. Possibly the programmer made an Applesoft program, the "A=PDL(0)" causes PREAD error when computing the execution cycles of the to be called with in the X-register. This triggers all instructions involved, and possibly the comment is four timers, and when the Timer pulse is short, the the only error. The routine may have originally been PREAD routine is exited in a relatively short period written for 12 cycle loops then changed to 11 cycle of time. However Timer 1 will still be set if Paddle 1 loops because some marginal tolerance components is further clockwise than Paddle 0, When the would not work with 12 cycles. Perhaps they forgot "B=PDL(1)" statement is executed. PREAD is to change the comment. entered with X=l, and the timers are triggered The basis of the workings of PREAD is this: yon again. However the timer pulse may still be high want a number between and 255 returned. The from the previous PREAD routine which read timer duration will vary between 2 and 3302 micro- Timer 0, and the timers are not retriggered by seconds with a 160000 ohm paddle and a .022 micro- C07X if they have not yet reset from the previous farad input capacitor. However if the values of both trigger. This means that the Timer 1 pulse will be of these components are 10% low, the timer duration dropping after a short period of time after PREAD will vary between 2 and 2673 microseconds. The 256 is entered, even though Paddle 1 is a long ways loops of 11 cycles take 2760 microseconds in the clockwise. Address Decoding and Input/Output 7-25 There are two ways which this sort of interference An aspect of PREAD that should be well under- may be avoided in BASIC programs. One is to stood is that it takes a long time and that the time it always insure there is a time delay between reading takes gets longer as you turn the paddle clockwise. different paddles. It does not take much in BASIC. This can be used to advantage in a paddle variable "15 FOR C ^ TO ;NEXT" in the above program delay routine which allows the user to vary execu- does the trick, or just insert a few instructions tion speed by adjusting a paddle. More often, the between PDL(n) expressions. The second way is to time delay is a nuisance, causing unwanted time poll the timer in BASIC to make sure it is reset delays in a computer that can't afford them. One before trying to read it. In the above program: "15 waytospeed programscalling PREAD is toonly use IF PEEK(-16283) > 127 THEN 15." Actually, the counts 0-63. The paddle tweaker becomes aware delay in this last cure is probably long enough to that there is no control when he goes too far clock- ensure that Timer 1 is reset by the time -16283 is wise and controls his Formula-1 racer with less actually examined, but you will be sure if you use it. paddle range. Average paddle reading time is The interference between timers is more pro- reduced by 75% and the sensitivity of the computer nounced when calling PREAD from assembly lan- action to the paddle tweaker's touch becomes greater. guage programs. This is because machine language This is tolerable with a paddle set but less tolerable is so fast that hundreds of instructions can be exe- with a one inch joystick which is already very sensi- cuted after a PREAD routine, and some of the tive to the touch. timers may still be set. It is also possible for a Assembly language programmers should not feel PREAD to a timer to interfere with a subsequent tied to PREAD. PREAD is handy and often ade- PREAD to the same timer. Consider the following quate, but it's not the last word in reading paddles. program sequence: Figure 7,11 is a program which reads Paddle and Paddle 1 simultaneously, an obviouscapability since all timers are triggered simultaneously. This paired LDX #0 paddle poller polls the pair of paddles precisely in 22 JSR PREAD cycle loops and therefore returns values equal toone JSR PREAD half of what they would have been if read by STY SAVEP0 PREAD. The Paddle value is returned in the Y- register and the Paddle 1 value is returned in the You may have wanted to cause a paddle variable X-register. The values can each be shifted left for delay with this sequence. Now if Paddle is fully compatibility with PREAD if this is desirable. The clockwise, the first PREAD is done normally, but advantage of reading the two paddles together is the second one returns a low value instead of 255. that paddle reading time is cut in half. The full This is because the first PREAD is exited as soon as mechanical range of each paddle is used and the 256 polling loops have been performed. Timer is number returned is to approximately 160. It can still set though, and it is therefore already set when be argued that no resolution is lost since 1/256 reso- the second PREAD is entered. The result is a return lution exceeds the practical resolution of a 3/4" value in the Y-register of 70 or so instead of the diameter carbon potentiometer and possibly the expected 255. stability of a 558 timer. In other words, it's hard to Misreading a timer due to a previous call to find a point on the pot where the PREAD routine PREAD can be avoided by preceding all calls to returns a single value that does not jump back and PREAD with a check like this: forth between readings. Itisalsovery hard to adjust the paddle so as to increase or decrease the returned value by one. Resolution of 1/160 is easily good LDX PDLNUM enough for this hardware. NOTRDY LDA PDL0,X A final recommendation for speeding paddle BMI NOTRDY reading is to integrate the timer polling with other JSR PREAD program execution. The time delay problem exists as long as normal program flow must wait thou- This simply waits until a timer is reset before sands of microseconds for a timer to reset. When the attempting to trigger and read it. Of course, there paddles must be read often and speed is important, it may be necessary to arrange routines so that they would have been no problem in BASIC or assembly language if this cheek had been included at the can check the timer states occasionally, only inter- beginning of PREAD. rupting program flow momentarily. For example, 7-26 Understanding the Apple II SOURCE FIL E: SIMULREAD 0000 1 ******************************************************* 0000 2 * * 0000 3 * * 0000 4 * SIMULTANEOUS READ OF PADDLE-0 AND PADDLE-1 * 0000 5 * * 0000 6 * BY JIM SATHER * 0000 7 * , * 0000 3 * 1/24/8 3 * 0000 9 * * 0000 10 * * 0000 11 ******************************************************* 0000 12 * ^ 0000 13 * 0000 14 * PADDLE'0 DIVIDED BY 2 IN Y-REG 0000 15 * PADDLE-1 DIVIDED BY 2 IN X'REG 0000 16 * 0000: 17 * SIMULTANEOUS READ PROGRAM LOOP IS 22 CLOCKPULSES. 0000: 18 * 0000: 19 * MONITOR PREAD ROUTINE PROGRAM LOOP IS IL CLOCKPULSES. 0000: 20 * 0000: 21 * C064; 22 PDL0 EQU $C064 C06 5: 23 PDLl EQU $C065 C070: 24 PTRIG EQU SC070 0000: 25 * 0000: 26 * ^ ""• --'-• k11 ctvm 1.1IC/V 1 OBJECT FILE NAME IS S IMULREAD.OBJ0 1F00: 27 ORG S1F00 1F00:AD 70 C0 28 DOIT LDA PTRIG 1F03:A2 00 29 LDX #0 1F05:A0 00 30 LDY #0 1F07:48 1F08:68 m 32 PHA PLA GIVE SOME SPACE FOR COUNT = 1F09:24 00 33 GOTPDLl BIT S0 1F0B:AD 64 C0 34 CHKPDL0 LDA PDL0 1F0E:10 0D 35 BPL GOTPDL0 1F10:EA 36 NOP 1F11:C8 37 INY 1F12:AD 65 C0 38 LDA PDLl 1FLS:30 02 39 BMI NOGOTS XF17:10 F0 40 BPL GOTPDLl 1F19:E8 41 NOGOTS INX 1F1A:4C 0B IF 42 JMP CHKPDL0 IFID: 43 * IFID: 44 * 1F1D:24 00 45 GOTPDL0 BIT $0 1F1F:AD 65 C0 46 « - ^ LDA PDLl 1F22:30 F5 47 • BMI NOGOTS 1F24: 60 RTS *** SUCCESSFUL ASSEMBLY: NO ERRORS Rgure 7.1 1 Assembler Listing: A Paddle Read Program. Address Decoding and Input/Output 7-27 suppose that you are computing HIRES plot coordi- about 1/33 which really is sufficient for many tasks. nates in a 100 cycle loop. At the end of each loop, you Of course, this would be a complicated program, but can cheek the previously triggered timer to see if it the results would be rewarding. Complicated pro- has reset yet and increment a counter if it hasn't. grama are within the capabilities of any reader of You wind up reading the timer with a resolution of this book who has the time and the urge. 7-28 Understanding the Apple HARDWARE APPLICATION EXTENDING THE GAME I/O SOCKET Have you ever seen an Apple with two joysticks are used by the paddle sets. Switch inputs can be plug'ffed in? Why not? It's a capability of the Apple. paralleled, so one of several switches can operate a The answer is that when a standard joystick or pad- given pushbutton input. Potentiometers, however, dle set is pluprg-ed in to the prame I/O socket, the pins cannot be connected simultaneously to a timer for one pushbutton input, two paddle inputs, four input. They would interfere with each other. annunciator outputs, and the C040 STROBE' be- The benefits of the extension socket are obvious, come inaccessible. Several grame I/O extenders are but the modification must be performed carefully to available commercially. This Application Note ensure mechanical strength. The first step is to buy shows two extension circuits you can build yourself. a high quality 16-pin DIP socket. You will also need One is simple, allowing you to plug a joystick or to buy a 16-pin plug and cover like the one used on paddle set in and stiil have a 16-pin DIP socket Apple paddle sets. We assume that the plug to be available with the remaining: I/O pins accessible. modified on the paddle set or joystick is so thor- The other is more complex, allowinpyou to have two oughly glued and sealed that you cannot hope to paddle sets and two joysticks simultaneously con- solder a socket to it Here is the procedure to mount nected with switched control between paddles or the extender socket on your paddle set: joysticks. This irame I/O extender also contains an 1 Separate the cover from the plug on your paddle extension socket for connection to other devices. set. If you think you can solder a socket to this Let's look at the simpler circuit first. It is pictured mess, proceed to step 6. in the photos of Figure 7.12. What this is is a paddle 2. If you cannot salvage the old plug, remove the set with an extension socket soldered on top of its two 560 ohm resistors from it and cut the wires 16-pin plug. Pins 6 and 10 are removed from the from it which lead to the paddles. upper socket because these are the PADDLE and 3. Strip one inch of the outer insulation from the PADDLE 1 inputs which are being used by the wire bundle going to each paddle. This exposes paddle set. PUSHBUTTON and PUSHBUTTON three insulated wires in each bundle. If Apple is 1 are fed to the extension socket even though they consistent, the green wire goes to +5V, the white -nnnn Hgure 7.12 A ModMied Game i/O Plug. Address Decoding and Input/Output 7-29 5V WIRES BUnON-0 WIRE BUTTON-1 WIRE PADDLE-0 WIRE PADDLE-1 WIRE TO TO PADDLE PADDLE 1 Hgur©7.13 Wiring a Paddle Set Plug. wire is the pushbutton wire, and the black wire If necessary sand down the corner of your socket is the paddle wire. This should be verified with so the plug cover will slip over it. Pull pins 6 and an ohmmeter. With the ohmmeter, find the two 10 out of the socket or cut them off if the plastic wires connected to the pot. The resistance across is molded around the pins. them will vary between and 150,000 ohms as Fit the socket over the paddle set plug and hold this assembly lightly together in a soft jawed the paddle is turned. The wire left over is the vise. All wires should be dressed inside the pins pushbutton wire. Now find which wire is shorted of the socket and the socket pins should be out- to the pushbutton wire when the pushbutton is pressed. This is the 5 Volt wire, and the other side of the plug pins. Solder the fourteen pins of wire is the paddle wire. the socket to the appropriate pins on the plug. 4. Cut the paddle "wires for each paddle back 1/2 Check out the operation of your paddle set and inch. Leave the other four wires at their present extension socket. length. Strip 1/8 inch of insulation off the end of If you desire, fill the area between the plug and all six wires. expansion socket with epoxy or a sealant like 5. Figure 7.13 shows the wiring of the plug. Install RTV. This will give your assembly more mechan- ical strength. Do not seal the assembly until you the two 560 ohm resistors first, making sure the leads do not extend very far beyond the solder are certain it works correctly. posts. Connect the wires and solder. Use a low 10 Cut the top off the plug cover so the topless plug wattage iron and do not overheat the pins or the cover is 5/16" high. Cut out a small notch for the plastic base will be damaged. Insert the plug wires to pass through. Slip the cover over your into a spare socket while soldering to keep the assembly and glue it on with a small amount of pins aligned if the plastic becomes soft from epoxy cement. Remember that you may want to overheating. get back in there some day. 7-30 Understanding the Apple Figure 7.14 This Game I/O Extender Can Support Two Sets of Paddles and Two Joysticks Simuttaneously. PADDLE A PADDLE B JOYSTICK CONFIGURATION 1 JOYSTICK CONFIGURATION 2 JOYSTICK A JOYSTICK B JOYSTICK A JOYSTICK B Figure 7.15 Game I/O Extender Configurations. Address Decoding and Input/Output 7-31 INPUT EXTND PDLA PDLB JSTKA JSTKB 5V 1 o -o —o— —O— =—O — C040 5 o O' O- -o GROUND 8 NC 9 0- AN3 12 O- —o- -o -o AN2 13 O- -o- -o- ^m 14 O- ANO 15 O- PBO rs^ PB1 PB2 SHIFT POLO PDL1 PDL2 P0L3 SI S2 Figure 7,16 Schematic: Gome I/O Extender. Figures 7.14 and 7.16 are photos and a schematic time. Switch SI enables either the joystick or the diagram of the more ambitious ^ame I/O extender. paddles. This unit is meant to sit outside of the computer case, A third switch is necessary if you have a button PUSHBUTTON 2 and the SHIFT key connected to the game I/O socket via a 16-pin DIP connected to jumper, It is basically six 16-pin sockets wired mod is installed. The SHIFT key mod works by together with some configuration switches. The connecting the SHIFT key to PUSHBUTTON 2, scheme is this: two of the sockets are meant for but neither the SHIFT key mod nor a pulled down paddle sets. One of the paddle sockets is connected pushbutton will work if both are connected to I normally but the other is connected so a standard PUSHBUTTON 2 at the same time. The game I/O paddle set will control Timers 2 and 3. Two of the extender allows you to have both installed by select- sockets are meant for joysticks. The joystick sockets ing between them via S3. The normal SHIFT key are wired so all four timers are utilized by two joy- mod is to connect one of the SHIFT keys to pin 4 of sticks. Switch S2 places the joysticks in one of two the game I/O socket. With the game I/O extender possible configurations as shown in Figure 7.15. The the SHIFT key should be connected to pin 16 (nor- paddles and joysticks may be connected at the same mally not connected) of the game I/O socket. Then 7-32 Understanding the Apple switch S3 can select between pin 16 and a paddle or through. A nibbling tool is good for cutting the joystick pushbutton for routing to the PUSHBUT- holes. The procedure is: install the installation TON 2 input. sockets in the board; wire the board and switches as The construction technique is to mount the six shown in Figure 7.16; mount the board and switches sockets on a general purpose IC board. Use the type in the ease. The appearance of your extender will with feed through solder holes so wires can be con- vary with your selection of switch styles and enclo- nected on both sides of the board. The board is sure. Enjoy your extender. It's really pretty handy. mounted in acase with six holes which the sockets fit Address Decoding and Input/Output 7-33 HARDWARE APPLICATION USING PADDLES AND JOYSTICKS NOT DESIGNED FOR THE APPLE Supposeyou seeaspecialon 100.000 ohm joysticks push the joystick into the vertical or horizontal stop at your local electronics store and wanted to plug as appropriate and adjust the calibration pot so the one into your Apple. Could you do it? Sure you could, screen just reads 255. but you'd need to make a little modification to your You can also calibrate a standard Apple paddle Apple so the nonstandard joystick would work with set so there is no unused 255 slack at the clockwise PREAD. end. This is done by taking the paddle apart and The modification is to change capacitors C7 and connecting a 1.5 megohm calibration pot across the C8, the Timer and Timer 1 input capacitors so the two connected terminals of the 150.000 ohm pot. two timers will output 2760 microseconds pulses or Run a paddle read and display program and adjust greater when the joystick is against the high resis- the calibration pot so 255 is just displayed when the tance stop. This will allow PRE AD to return a value paddle is fully clockwise. Then measure the calibra- in the range from to 255, If your joysticks are tion pot with a high resistance ohmmeter (a digital exactly 100,000 ohms, the required capacitance volt/ohm meter works) and solder the equivalent value is 2760/100000 - .027 microfarad. The closest fixed resistor across the 150,000 ohm pot. standard capacitor value higher than .027 is .033 Here's another suggestion for a modification to a microfarad so this is the value you would install. paddle set or joystick. If Timer 2 and Timer 3 are not This would give the identical time constant that is connected to anything in your Apple, why not con- found in a standard paddle set with unmodified nect fixed resistors from their input pins to 5 Volts. motherboard (150000 x .022 = 100000 x .033). This will give you two fixed timing references for You can buy 16-pin DIP plugs with covers just like programm ng use. a poor man's real time clock. For i they use on the Apple paddle sets. One mail order example, a 4700 ohm resistor would give a 100 supplier that carries them is Jameeo Electronics, microsecond time reference, and a 47,000 ohm resis- 1355 Shoreway Road. Belmont, CA„ 94022. You can tor would give a 1000 microsecond reference. The wire your joystick to this plug and glue the cover on exact duration of the fixed time references in any for a clean installation.The paddle schematic in machine could be determined by PREAD. Figure 7.5 should be your guide to connecting the To install these fixed resistors, buy a new 16-pin joystick (see also Figure 7.13). The vertical pot DIP plug and cover like the ones already connected should be connected between pin 10 and pin 1. The to the paddle set. Then pry the cover off the old horizontal pot should be connected between pin 6 paddle set plug. If the old plug is full of glueor if you and pin 1. Pushbutton connections will depend upon damage it prying it apart, you will have to use your what type of switches your joystick has. It will most new plug, wiring it identically to the old plug. commonly have normally open, on/off, momentary Solder a 4700 ohm resistor between pins 7 and I and switches just like the Apple paddle set These solder a 47.000 ohm resistor between pins 11 and 1. require a 560 ohm pull down resistor to pin 8 which This makes Timer 2 the 100 microsecond reference can be installed on the DIP plug. and Timer 3 the lOOO microsecond reference. Glue You may also wish to install small calibration the cover back on and you're on the road. potentiometers across the main pots so you can Rebuilding the plug is also a cheap way of extend- exactly calibrate your joystick to PREAD, A good ing the game I/O socket. If you've got an input or calibration pot, in the case of 100.000 ohm paddles output you wish to connect in addition to a paddle and .033 microfarad capacitors, would be a one set, pry or cut the cover off the paddle set plug and megohm pot. You could calibrate a given Apple/ solder your add-on device directly to the appro- joystick combination with a calibration pot. then priate pin. Your paddle set is now a combination measure the pot to get a calibration resistance. Then paddle set/light pen or whatever. Reiterating, be you buy a fixed resistor of this value and solder it sure you have a spare plug before you start prying acrossyour main joystick potentiometers. Your cali- apart the old one. You may well destroy the old plug bration program, written in BASIC, simply reads because of the big glob of glue they use when they the joystick and prints the values on the screen. You put the plug together. 7-34 Understanding the Apple II HARDWARE APPLICATION MODIFYING THE KEYBOARD SO CTRL AND RESET MUST BE PRESSED TO CAUSE A RESET A notorious foible of the original Apple II was the gauge wire since ground for the entire keyboard location and shape of the RESET key. It sits next to will flow through this wire. 22 gauge wire is heavy the dash/equal key and the RETURN key where it is enough. The wire jumpers can be connected to pins often aceidentaily pressed by the operator causing extendingthrough the PC board, and they should be aggravation, crashes, and fear of equal signs. Addi- soldered. Keep wire length as short as possible so tionally every one year old offspring of a thousand wires will not hang loosely. The following is an home enthusiasts learned where the button was that installation procedure:* caused all the commotion. It was bad enough that 1. Separate the bottom assembly from the white various RESET lockout schemes were sold com- case following the procedure in Appendix J. mercially, and Apple competitors advertised that 2. Remove the keyboard from the case by remov- you couldn't hit their RESET key accidentally. The ing the three screws on either end. author used to keep a cardboard cover over his 3. There are two ground traces which must be cut, RESET key and, to this day. does not reach for the one on each side of the PC board. Their location upper right hand corner of the keyboard without is shown in Figure 7.17. Cut these two traces second thoughts. with a pocket knife, verifying discontinuity. As Apple pretty well solved the problem in the Apple shown in Figure 7.17, one trace must be peeled 11 Plus by installing the CTRL-requ ired slide switch back slightly to form a little tail to which a wire on the keyboard. If this switch ia in the correct posi- can be connected and soldered. tion, both CTRL and RESET must be held down 4. Solder ajumper between pin 8 of the 16-pin DIP simultaneously to make RESET' go low. This nicely jumper socket and the peeled back ground prevents accidental RESETs and takes little get- trace. This wire should be 22 gauge. ting used to. The purpose of this Application Note is 5. Solder a jumper between the right terminal of to show how to modify older keyboards so CTRL will switch 13 and pin 13 of Ul as shown in Figure be required to make the RESET key function. 7.17. As Figure 7.7 shows, both the CTRL switch and 6. The installation is complete. Operation can be RESET switch operate by placing a ground on a line verified by setting the keyboard on an insulated pulled up by a resistor. The modification consists of surface next to the base assembly, connecting removing the ground connection from the RESET the keyboard jumper to the motherboard, and switch and connecting the RESET switch to the applying power. After verification, disconnect CTRL line. After this, the RESET switch causes the the keyboard from the motherboard, install the RESET' line to go low only if the CTRL line is low. keyboard in the white case, and install the base The ground is removed from the RESET switch assembly on the white case. Don't forget to by cutting current traces on the keyboard PC card reconnect all wires, including the keyboard and wire jumping the broken ground path around jumper. the RESET key. Then another wire jumper con- nects the CTRL line to the RESET switch. The *PleaSe read the NOTE OF CAUTION at tKe bep-innJTifrof the ground connection should be made with a heavier book before making any modification to your hardware. Address Decoding and Input/Output 7-35 CONDUCTOR SIDE COMPONENT SIDE Jumper wires Cut trace © oooooooo o o Cut trace Keyboard Keyboard jumper jumper socket socket U1 SN7400 Rgure 7 A 7 The CTRl-RESET ModHicatlon, (or Older Keyboards. 7-36 Understanding the Apple HARDWARE APPLICATION MAKING THE SHIFT KEY MODIFICATION When the Apple was first put together, its designer other end to the base of pin 4 on a high quality 16-pin could hardly have envisioned the variety of purposes DIP socket. Clip the spring clip to pin 24 of PLUG 1 for which his creation would be used. He obviously and insert the socket into the game I/O connector. did not envision word processing as an Apple task, Other devices may then be inserted into the socket. or he would have included an upper/lower case key- The SHIFT key mod is more difficult to install on board and an 80 column text display. Undaunted, the older keyboards predating the Apple II Plus. thousands of people use the Apple for word process- There is no convenient exposed pointon the SHIFT' ing anyway, and make the Apple an acceptable line to which a spring loaded clip can be attached. word processing computer by installing an 80 You may solder a wire directly to Key 42 or Key 53 column video board and the SHIFT key modifica- and connect the other end to pin 4 of the game I/O tion. socket. Whatever connection method is used should The SHIFT key mod was the bright idea of some allowf the jumper to be easily disconnected in case forgotten soul who noted that the PUSHBUTTON 2 the white enclosure needs to be separated from the input to the game I/O socket was rarely used. He base assembly. The method shown here is to connect connected the SH IFT key output to pin 4 of the game the SHIFT' line to the game I/O socket usinga spare I/O socket and interpreted PUSHBUTTON 2 as line on the 16-pin keyboard connector. This takes a determining upper or lower case for alphabetic little effort, but when you're finished the SHIFT key input from the keyboard. This modification has mod is fully integrated with the Apple mechanical become significant because most word processing package with no loose wires to be connected or dis- programs support it, allowing persons to enter connected. Here is the installation procedure:* upper and lower case to word processors via the 1. Separate the bottom assembly from the white SHIFTkeys. The monitor GETLN routine, of course, case following the procedure in Appendix J. does not support the SHIFT key mod, so BASIC still 2. Remove the keyboard from the white case by will communicate with the keyboard only in upper removing the three screws on either end. case. 3. Lay the keyboard face down and solder an insu- The SHIFT key mod will not work if a pulled lated wire jumper between Key 53 and pin 4 of down pushbutton is also connected to the PUSH- the keyboard connector as shown in Figure 7.18. BUTTON 2 input. This is because the SHIFT key 4. Remove the motherboard from the base assem- line is pulled up, and you cannot wire-0R a pulled up bly following the procedure in Appendix J. line and a pulled down line. For this reason, some 5. Place the motherboard bottom side up and joysticks with three buttons will be incompatible solder an insulated wire jumper between ptn 4 with the SHIFT key mod. of the game I/O socket and pin 4 of the keyboard The SHIFT key mod is most easily installed on the socket as shown in Figure 7. 18. This wire can be Apple II Plus. This is because the SHIFT' line is held tightly to the motherboard with spots of highly accessible on the exposed pins of PLUG 1, glue. A hot glue gun works well for this purpose. which connects the main keyboard PC card to the 6. Reinstall the motherboard on the base assembly, keyboard encoder card This plug can be seen by . 7. The installation is complete. Operation can be removing the Apple's cover and looking in from the verified by setting the keyboard on an insulated rear. The SHIFT' line is pin 24, the second pin from surface next to the base assembly, connecting the left. Take a wire which is terminated on both the keyboard jumper to the motherboard, and ends with a spring loaded clip. With the computer applying power. After verification, disconnect turnedoff, cliponeendtopin24of PLUG L Remove the keyboard from the motherboard, install the your joystick or paddle set from the game I/O socket keyboard in the white case, and install the base and clip the other end of the jumper to pin 4 on the assembly in the white case. Don't forget to joystick plug. Reinsert the joystick or paddle set reconnect all cards and wires, including the with the clip attached and you're finished. keyboard jumper. Here is a method which takes a little more work but is more usable. Take a wire which is terminated Please read the NOTE OF CAUTION at the beginning of the on one end with a spring loaded clip. Solder the book before making any modification to your hardware. Address Decoding and Input/Output 7-37 CONDUCTOR SIDE OF KEYBOARD PC CARD -O. n n VIDEO CASSETTE oooooooo KEYBOARD OUT I IN I 4 JUMPER CASSETTE CONDUCTOR SIDE OF o ooooaooo SOCKET OUT MOTHERBOARD (BOTTOM SIDE UP) o s J14 i GAME I/O SOCKET O Wire jumper Long wire jumper Wire jumper is held close to the motherboard with beads of glue. A7 8 KEYBOARD 4 1 JUMPER i SOCKET Rgure 7.1S Installation of SHIF Key Mod, for Older Keyboards. There is an alternate method to the SHIFT key ing at your pleasure. Even though the keyboard will mod for obtaining the upper/lower case alphabet output upper and lower ease ASCII to the MPU, the from the keyboard in the Apple II Plus. The key- monitor GETLN routine assumes everything is I board encoder ROM is fully programmed for upper and lower case in the II Plus, and there are holes and upper case only. The keyboard will communicate in upper and lower case only to the limited number of connections for a slide switch to enable or disable programs written for the Apple which look for alphabetic shifting. The switch connections are lower case alphabetic ASCII in the keyboard input. normally jumpered so alphabetic shifting is dis- Your word processor may or may not support this abled. You can change the configuration so that capability in addition to the more prevalent SHIFT I alphabetic shifting is enabled, or yo\i can mount a key mod. slide switch and disable or enable alphabetic shift- 7-38 Understanding the Apple Install side-mounted, 2 pole. 2 throw switch ! Cut here Rgure 7.19 Enciblirtg Lower Case, Apple II Plus. A drawback to consider when enabling alpha- 2. Lay the white case upside down on a soft sur- betic shifting this way is that you will have to press face. Remove the small electronic assembly SHIFT in addition to I, J, M. and K to make CUR- board from the main keyboard PC card by SOR moves in the ESCAPE mode. This is another pinching the two white plastic retainers while case of a hardware capability being minimized by working the board off. lack of program support. Of course, you can easily 3. Orient the small board so the holes marked S2 install the switch then disable alphabetic shifting if are as shown in Figure 7.19. you find its use is not convenient in your system. 4. Cut the two bow tie solder jumpers with a pocket Here is a procedure for enabling alphabetic shifting knife. Verify discontinuity. on the Apple II Plus keyboard:* 5. Install a miniature double pole, double throw slide switch in the holes and solder. 1 Separate the base assembly from the white case Reinstall the small board on the main keyboard . 6. following the procedure in Appendix J. PC card. Install the motherboard base assembly back on the white case. Be sure to connect all cards and wires including the 16-pin keyboard Please read the NOTE OF CAUTION at the beBinning of the book before making any modification to your hardware. jumper. Address Decoding and Input/Output 7-39 HARDWARE APPLICATION INSTALLING A VOLUME CONTROL ON THE APPLE'S SPEAKER Did you ever wish you could turn down the com- A suitable signal for connection to an audio amp is puter tooter on your Apple when the family was the signal at the cathode of CRl, You can tap into sleeping, but you were being a midnisrht computer this signal as follows:* fool? How did I guess? Here are two suggestions on 1. Remove power from the Apple. how to silence your Apple. They are illustrated in 2. Cut a length of twin lead wire long enough to Figure 7.20. reach from the motherboard to your amplifier First, you can connect a 2500 ohnn or greater input. This wire should be terminated on one potentiometer in series with the speaker. This end with a plug which will fit into your ampli- potentiometer should be mounted on the case where fier input jack. you can reach it, in a slot in the back or in a hole you 3. Locate CRl. which is marked IN914 or CRl on drill near the keyboard perhaps. You need to con- the motherboard. It is situated between the nect the pot to one of the two speaker wires using game I/O socket and the cassette output jack some sort of plug/jack rig. Don't solder wires directly close to integrated circuit J13 (see Figure 7.20). from case mounted components to base assembly 4. You have two cut wire ends on your connecting components. Make it so the pot can be easily un- lead. One is a ground lead which goes to the plugged. Buy any sort of two wnre plug jack connec- grounded portion of your audio input plug. tion. Break one of the speaker wires at a convenient Wrap the ground lead around the anode of CRl place, and connect the two resulting wire ends to the andsolder. Theanodeistheendof CRl which is terminals of your jack. Your jack may be perma- away from the game I/O socket. nently attached to the base assembly. Connect two 5. Wrap the other lead around the cathode of CRl wires to your plug, then connectthe other ends to the and solder. The cathode is toward the game I/O center terminal and one side terminal of the potenti- socket. ometer. Make certain volume increases as the pot is 6. Disconnect the Apple speaker from the mother- turned clockwise. If necessary reverse the pot con- board, wind the wire up in a coil, and tape it to nections. Mount the pot. put a knob on it. join your the base assembly. plug and jack together, and youVe done. 7. Plug your connecting lead into the audio amp. An easier alternative is available if your television turn the Apple and audio amp on. and verify or monitor ha.s an audio input jack to an ampli- operation. If the Apple won't turn on. turn the fier/speaker associated with afront mounted volume power switch off immediately. You probably control. You can disconnect the Apple's speaker and have the leads in backwards, or you may have rigaconnection between the Apple audio signal and the Apple connected to another grounded device the audio in put to your external amplifier. Unfortu- with the wires backwards. Determine which nately, the speaker jack mounted on the mother- leads are reversed and swap them out in the board is unsuitable for connection to most audio most convenient place. amps, because one pin is connected to 5 Volts. The *Please read the NOTE OF CAUTION at the beRinninp: of the circuit is not meant to drive an audio amplifier. book before making any modification to your hardware. 7-40 Understanding the Apple II CASSETTE OUT A 2500U potentiometer mounted near keyboard U CONNECTOR TO AUDIO AMP User supplied plug & jack J13 LS74 B J14 GAME Motherboard ^JA I/O speaker connector Rgure 750 Two Vblum© Control Methods. Chapter 8 — w u u. u— — — y V v V[j_ V V ^ Video Generation The marriage of data processing and video dis- scheme which allows Apple programs to control the play technology has been one of the most important video output. developments in the advance of computers. Com- Figure 8.1 is a simplified diagram of the video bined with the keyboard, the video display provides display control processesof the Apple, As Figure 8.1 a direct communication link between people and shows, the MPU controls the output of video in a computers that makes the old, expensive, physically very indirect way. Under direction of the control- large computers seem to be just machines. Imagine ling program, the MPU sets the screen mode, com- communication with your Apple using a teletype putes a correct address in memory, and stores terminal with no video display. How would that selected code at that memory address. In so doing, affect important applications like word processing, the MPU is setting up a small area of the screen spread sheet accounting, data base management, map. The extent of MPU, and, by extension, pro- graphics display, and Donkey Kong? Without video, grammer involvement in outputting video consists the Apple wouldn't be worth owning. entirely of setting up this screen map. The actual Of course, the Apple does have a video display output of video is controlled by the video scanner capability, and a large portion of the motherboard which scans memory and drives out the map, and by hardware is related to the generation of video. We the video generator which processes the map to pro- have seen in other chapters that many features of duce the VIDEO signal. You can actually stop the bus structure, timing, and RAM addressing in the MPU by pulling READY or DMA' low, and the Apple II are dictated by the fact that the dissimilar Apple will continue to output the video to the screen tasks of stored program execution and video display under the control of the map which was set up by the generation are performed simultaneously in this MPU before you stopped it. computer. Additionally, the video scanner and Compare this indirect MPU involvement to a video generator are functional areas that exist for — printer output port where the MPU under pro- the sole purpose of making up the video display. All — gram control as always actually stores coded data of these functional areas are interconnected in a at a special address to output it to the printer. The 8-2 Understanding the Apple II MPU (Chapter 4) PHASE MAP ADDRESS DATA IN PHASE 1 SCREEN VIDEO ADDRESS MAP IN SCANNER (Chapter 3) BAM (Chapter 5) MAP DATA FROM SCANNER ACCESS TO RAM vmEo VIDEO SIGNAL GENERATOR [Chapter 8.1 Figure 8.1 The MPU. Video Scanner, RAM, and Video Generator Ali Ploy a Part in Creating ttie Video Display. sneaking access to RAM by the video scanner is an to discuss the nature of the VIDEO signal, how it is example of DMA, which is like some one else sleep- produced in the video generator, and operational ing with your spouse. RAM in the Apple is very features of the Apple II resulting from the way the promiscuous. It goes to bed with the video scanner VIDEO signal is produced. Other chapters of the every other niprht. Then on most off nights, it groe.s to book contain detailed descriptions which are impor- bed with the MPU. The MPU has no idea what tant in achieving a broad understanding of how the unfaithful RAM is up to during PHASE 1. tasks of video generation and program execution The video generator must take the offspring of the are intcrgrated in the Apple II. These include des- scanner/RAM affair and interpret it as text. LORES criptions of overall video generation {Chapter 1), graphics, or HIRES prraphics to produce a signal video scanning within the context of bus structure which causes a television or monitor to produce the (Chapter 2). the video scanner {Chapter 3), and computer display. This signal is referred to as the RAM addressing(Chapter4). The subjectat hand is VIDEO signal, and it is one of the more complex the video generator, and we begin our discussion signals in the Apple. The purpose of this chapter is with a description of the Apple II VIDEO signal. Video Generation 8-3 Figure 8.2 shows the characteristics of the Apple THE APPLE VIDEO OUTPUT SIGNAL VIDEO signal. It is made up of three components: Let's watch a television show for a minute; how the PICTURE signal, SYNC, and the COLOR about. Ta.r)? That Louie is really something. The REFERENCE BURST. The signals are added picture we see originates with a camera which out- together in such a way that a television can tell them puts composite video, a signal composed of picture. apart. The television can separate the SYNC from synchronization, and color information. This signal the VIDEO signal because, during SYNC pulses, is routed to a transmitter which modulates a radio the VIDEO signal is at a lower vo!tage than at any frequency signal with the composite video and with other time. It also can detect the COLOR BURST, audio from a microphone. The radio frequency sig- because it knows where to look for it— right behind nal is distributed nationwide to local stations which the horizontal sync pulse on the "back porch" of the transmit the signal to receivers in their area. The horizontal blanking gate. television in your home is a receiver/processor There is a voltage point on the VIDEO signal which extracts the audio and composite video from called the black reference. Voltages above the the radio frequency signal and processes it to form black reference cause the picture tube electron the picture we see and the sound we hear. beam to strike the interior face of the tube with The previous paragraph could be describing tele- enough velocity for light emission to result. The vision in any number of countries or continents in VIDEO signal goes above the black reference only the world which broadcast television signals based when it is time to paint, and it stays below the black on similar principles. The exact details of various reference the rest of the time. The SYNC pulses are signals vary, however, among several standard sys- blacker than black, extending below the blanking tems used in various areas of the world. The Ameri- signal to a point where they are detected as sync, not can standards were formulated by the NTSC a picture signal, by the television. We thus have (National Television System Committee) and adopt- three signal levels, the white level, the black level, ed by the FCC. which allowed black and white tele- and the sync level. The Apple signal is immensely vision broadcasting after July 1. 1941. Updated less complicated than normal television composite NTSC standards for color television broadcasting video in this regard. The level of the picturesignal in were adopted by the FCC on December 17. 1953. composite video can be any voltage between the The American television must be designed to receive black level and white level at any instant. This is the and process NTSC standard signals. way television reproduces the remarkable variety of When the Apple was built, the FCC frowned on lightingshades found in a norma! television picture. the idea of computers outputting radio frequency Even black and white television is really black and signals to a television because it is possible for a tiny white and innumerable shades of gray. The Apple amount of the computer signal to be radiated and video, when color information is not present, is truly cause interference with television reception in the black and white. neighborhood. Please note that this level of radia- The hori^jontal and vertical .sync pulses both de- tion leakage is not a health hazard and is smaller scend below the black level. Any .^sharp negative than the man-made electromagnetic fields we all edge in the sync level is interpreted by the television live in. To avoid conflict with FCC regulations, the as horizontal sync. Any longduration negative pulse Apple was designed to output composite video which in the sync level is interpreted as vertical sync. The will drive an NTSC standard composite video moni- vertical syne pulse in the Apple lasts for four com- tor. If you modulate a radio frequency signal with plete horizontal scans. As in normal television video, the Apple's VIDEO signal, that radio frequency there are sharp serrations in the vertical sync pulse signal will drive an NTSC standard television so that horizontal sync can be detected, even in the receiver. Of course, your thirty dollar RF modulator middle of the vertical sync pulse. may tend to leak RF radiation and interfere with There are 262 horizontal sync pulses for every neighborhood television reception. The television vertical sync pulse in the Apple, The horizontal sync front end takes the radio frequency signal and con- pulses occur in the middle of HBL, the 25 cycle verts it back to the same VIDEO signal that left the horizontal blanking gate. During HBL, the Apple's video output jack. From this point in its VIDEO signal is held below the black reference circuitry, the television is identical to a composite level, creating the right and left black margins on video monitor. the screen. The picture signal occurs between the 8-4 Understandfng the Apple II VERTICAL BLAMKING PERIOD WHITE LEVEL IBV BLACK REFERENCE " BLACK LEVEL 5V SYNC LEVEL m SHORT LONS HOfll^OMTAL HORIZONTAL LINE LINE DOT WHITE « URf * ^ UDI i BOTTOM TOP HORIZONTAL HORIZONTAL -VEflTICALSYNC- MARGIN MARGIN BLACK (REV 1 THflOUGH REV 6 REFERENCE ^ BLANKING BLANKIMG ANDflFIHEVj HORIZONTAL SYNC BLACK HORIZONTAL SYNC WHITE -, ^ COLOR \ flEFEflENCE BURST LEFT MARGIN RIGHT MARGIN — r _y r REV 7 AND LATER 1 PRtOR TO REV 7 BLACK HOR. HORIZONTAL UNWANTED SYNC SYNC BURST SVNC I BURST SPIKE Figure 82 The Appte II Video Signal. horizontal blanking gates, naturally, creating the holds the VIDEO signal in the black. The horizontal screen display between the left margin and right sync pulse causes the beam to retrace very rapidly to margin. The vertical sync pulse occurs in the middle the left side (none of this slow poke 14,000 MPH ofVBL,the4550cycle(70 horizontal scans) vertical stuff) so it can scan across left-to-right again. This blanking gate. The VIDEO signal is held below the cycle continues as the beam moves across again and black reference level during the entire VBL period, again and less speedily down the screen to the first creating the lower and upper black margins on the displayed line, about an inch from the top of the screen. screen. Assume the electron beam is at the top left corner In the last undisplayed line, VBL ends about an of the screen, and that the Apple display window on inch from the right side, but HBL begins at the same your television is 10 inches across, The beam is mov- time, so the screen is stilt blanked. After the beam ing left to right as you look at the screen, at about 10 scans past the right edge, horizontal sync occurs, inches per 40 microseconds or about 14,000 miles an causing retrace, and the beam begins the first dis- hour. Since we are at the top, the vertical sync pulse played line. When the beam gets about an inch from has just occurred and it is the second half of VBL. the leftside of the screen, HBL ends and the VIDEO The beam scans across to the right side of the screen, signal begins switching back and forth between the but we don't see light on the screen because VBL black level and the white level, decreasing and Video Generation 8-5 increasing the energy in the electron beam to cause tions in the vertical sync were changed to double bright spots and lines on the screen interspersed pulses. In the RFI Revision, the double pulse serra- with black spots and lines. tions were converted back to single pulse serrations About an inch from the right side of the screen. as they were prior to Revision 7. Through all of these HBL forces the VIDEO signal into the black where sync changes, the Apple was able to sync most tele- it remains until the beam has scanned past the left visions and monitors. Presumably the changes were margin of the next line. This cycle continues for 192 made to offset problems found in certain types of displayed horizontal scans. At the end of the display video display equipment. Also, a side effect of reduc- period of the last displayed line, VBL and HBL ing the horizontal sync width in Revision 7 was that begin together, marking the start of the bottom the little voltage spike at the end of HBL was margin. The beam scans the rest of the way to the eliminated. bottom in the black, then the vertical sync pulse causes a rapid retrace to the top of the screen, where COLOR SIGNALS we began our description of the continuous cycle of the electron beam. The COLOR REFERENCE BURST is a 14 cycle In NTSC standard television scanning, a process sample of the COLOR REFERENCE signal from known as interlacing takes place. In interlacing, the timing generator. Color television sets are alternate vertical scans are displaced vertically by designed to look for a 3.58 MHz signal after the half the distance between two horizontal scans. This horizontal sync pulse. From this short burst, the means it takes two vertical scans to actually paint television is capable of reconstructing the whole the complete television picture, and it is a tricky way COLOR REFERENCE signal. It does this by "phase of increasing vertical resolution without increasing locking" an oscillator to the COLOR BURST. By flicker. In NTSC scanning, there are 262.5 horizon- this method, the COLOR REFERENCE is trans- mitted to the television, but it is not present at the tal scans in each vertical scan for a picture com- posed effectively of 525 lines. The Apple SYNC is same time as picture information, so it does not not set up to cause interlacing. It causes a straight- interfere with the picture. Since theCOLOR BURST forward vertical scan of 262 lines. 192 of which are occurs during HBL, it is not displayed on the screen. displayed. On some television sets, with Apples prior to Revi- In earlier Apples, there is a little negative spike on sion 7, you can actually see the COLOR BURST on the VIDEO signal at the end of HBL, about a the screen if you turn the brightness and contrast microsecond before the first display spot on the way up. It appears as a series of vertical lines at the screen. This spike is an undesirable switchingglitch far left side of the screen. generated in the logic which produces the horizontal In the oldest Apple lis (Revision 0), the COLOR sync pulse. The spike causes a vertical black line in BURST was always present on the VIDEO signal. the left margin of the screen about one text charac- This resulted in distracting green and violet text ter width before the first displayed dot. It is espe- characters. A Color Burst Killer was added in Revi- cially noticeable when television brightness is turned sion 1 to eliminate the COLOR BURST in TEXT up so there is some brightness level in the margins. MODE. This removed the colors from the text Under some circumstances the line appears to be because the television uses the presence of the reddish, and it can be a little distracting. It's no big COLOR BURST to determine whether an incoming deal, but youVe probably noticed it and now you signal a color signal or a monochrome signal. is know what causes it. When no COLOR BURST is present, it completely There are differences in sync generation among inhibits color generation in the television so the pic- the various revisions of the Apple II. In Revision 0, ture is black and white with no color noise. In vertical sync lasted 16 horizontal scans and had no MIXED mode, the four lines of text at the bottom of horizontal serrations. Horizontal sync lasted the screen are still green and violet because the through eight states of the video scanner. In Revi- COLOR BURST is present. sion 1, the 50 Hz Eurapple jumpers were added. Picture information in an NTSC standard televi- vertical sync was reduced to four horizontal scans sion signal is divided into two components, the color with horizontal serrations as is shown in Figure 8.2. component and the brightness component. The In Revision 7. the horizontal sync pulse was reduced chrominance signal contains the color information in width to four states of the video scanner. Also, of the picture, and the luminance signal contains possibly through oversight, the horizontal serra- the brightness information of the picture. The two I S-6 Understanding the Apple signals are transmitted simultaneously and pro- nance amplifier to the synchronous demodulator cessed together in the radio frequency and interme- where it is compared with the reconstructed COLOR diate frequency stages of a television set. Once the REFERNCE to produce red, green, and blue color television signal has been converted fron? radio fre- signals. Thus, the Apple VIDEO signals which pro- quency to composite video, the television separates duce colored displays on the screen are those with a the chrominance signal from the luminance signal 3.58 MHz PICTURE signal* and processes them individually. Processing in a composite video monitor is simitar The chrominance signal is a highly complex com- to that in the video sections of a television, but the bination of two 3.58 MHz signals 90 degrees out of high frequency square waves may or may not have phase with each other. In an amazingmathematical/ been converted to sine waves by the time they reach electronic manipulaLion, the chrominance signal the chrominance and luminanceamplifier inputs. If contains the color information of each spot on the they are not already sine waves, the high frequency screen while the luminance signal contains the square waves will be converted to sine waves in the brightness information of each spot. Part of this luminance and chrominance amplifiers. In high mathematical manipulation is that the chrominance frequency response, monochrome monitors, there is and luminance signals are present together in over- no chrominance amplifier. The video amplifiers of lapping frequencies, yet do not interfere with each these monitors will pass the square waves of the other. In television video processing, the chromi- Apple VIDEO signal with little distortion. An nance signal is separated from the composite video, exception is LORES gray PICTURE signals, which then red, blue, and green color signals are extracted will be converted to sine waves by monitors of less from the chrominance signal by comparing it to the than 21 MHz frequency response. color reference. The features of Apple graphics are largely In Apple video, the PICTURE signal takes the dependent on the way the Apple passes color intelli- place of the luminance and chrominance signals of gence to the television. There is no need to store normal broadcast NTSC composite video. The PIC- HIRES color information in memory. The color TURE signal is a simple binary signal that goes information is part of dot positioning. Dot position high or low in accordance with text or graphics determines color. Think of the savings in memory patterns produced from the screen map during dis- over a system where the color information of dots is play periods. stored as separate intelligence. The flip side of this In television processing, the Apple VIDEO signal coin is: think of the elaborate programs required to is recovered from the modulated carrier wave and is produce colored displays dependent on dot position. present at the output of the "second defector." The There are four classes of Apple video concerning higher frequency components will, however, look color. One is black, the absence of luminance. Two is different than they did at the video output jack of the white, the absence of color caused by PICTURE Apple. This is because the square waves of the signals less than 3.58 MHx. This occurs when adja- VIDEO signal are converted to their sine wave cent HIRES dots are turned on, increasing signal components that are within the bandwidth of the pulse width and decreasing frequency so there is no television signal paths. In televisions with the nor- 3.58 MHz signal for the TV to interpret as chromi- = mal 4.2 MHz IF bandwidth, those square waves nance. Additionally, white occurs in a "COLOR greater than about 1.37 MHz are converted to sine 15" LORES block, which is identical to seven adja- waves of the square wave frequency. This includes cent HIRES dots in four adjacent horizontal scans. the COLOR REFERENCE BURST and higher White also occurs in TEXT mode where there is no frequency PICTURE signals, such as those which COLOR BURST. Three is gray, the absence of color produce color in the Apple's display. This modified caused bv 7 MHz PICTURE signals. This occurs in Apple video is present at the input to the luminance "COLOR = 5" and "COLOR = 10" LORES Blocks. and chrominance amplifiers, as well as other sec- LORES colors 5 and 10 are identical to each other in tions of the television. shade and intensity and are the same as white The modified PICTURE signal (a high frequency except less bright. White horizontal lines are caused sine wave, a low frequency square wave, or medium by long periods of white level VIDEO signal. Gray is frequency combination) is passed by the luminance caused by 7 MHz oscillation of the VIDEO signal amplifier and ultimately controls the brightness of Some exceptions to this rule and further discussion on telev ision the display. Ifthe modified picture signal is oscillat- processinjT are contained in a Technical Note at the end of this ing at 3.58 MHz. it will also be passed by the chromi- chapter. Video Generation 8-7 between white level and black level. The alternatinR one for GRAPHICS and one for TEXT. In a fairly black level causes gray to be less bright than white. complex scheme, the GRAPHICS shifter can be Fourth is colored video. This video is 8.58 MHz configured for HIRES shifting (an 8-bit shift regis- ter) or for LORES shifting (two 4-bit end around whether it is HIRES or LORES. There are four such shift registers). The two configurations are shown HIRES colors and twelve such LORES coSors. Four separatelv in Figure 8.3 for illustration, but there is of the LORES colors are identical to HIRES colors: green, violet, orange, and blue. The remaining eight only one GRAPHICS shift register, and it is con- colors come in four tones: light and dark blue, light tained on chips B4 and B9, and dark magenta, light and dark blue-green, and The GRAPHICS patterns are loaded directly light and dark brown. Of these eight colors, seven from the RAM data latch. In HIRES, the lower can be produced in HIRES as interference between seven bits of the loaded data are shifted to the PIC- adjacent bytes of graphics data with DL7 set on one TURE signal where they control the white and byte and reset on the other. black level of seven dot positions. In LORES only half of the loaded data is used in a given video cycle. This explanation of Apple color is based on anal- ysis of the hardware and timing of the video genera- Remember that in TEXT/LORES scanning, each thou displayed memory line is scanned eight times con- tor. The details are a little involved, but tread secutively. Duringthe firstfour scan lines, the lower in my footsteps, tenacious reader, and thy tootsies will not freeze. four bits'of RAM data are used to create the upper block. The upper four bits are used during the second four scan lines, creating the lower block. The first four scan lines are identified by VC. and the VIDEO GENERATOR HARDWARE second four are identified by VC. In the LORES OVERVIEW shift the 4-bit patterns are circulated 3.5 times per block width. This creates colored patterns which A block diagram of the video generator is shown in Figure 8.3. The upper part is video scanner logic seem like solid color blocks on the screen. gating and the lower part is PICTURE signal The TEXT patterns are not loaded directly from the RAM latch to the TEXT shifter. Rather, the generation. Video scanner logic gating produces SYNC, the VIDEO BLANKING gate, latched RAM output addresses a ROM which con- television and HBL from the states of the video scanner. It also tains TEXT dot patterns (see Figure 8.4). Recall that the data stored in TEXT screen memory is uses the scanner states to gate the COLOR BURST GRAPHICS modes and to determine GRAPHICS ASCII. In TEXT scanning, the ASCII for a given in character position is driven out in eight consecutive time and TEXT time in MIXED mode. The PIC- scans. VA, VB, and VC contain the information as to TURE signal generation circuitry monitors latched which of these eight lines is currently beingseanned. data from RAM and the screen mode to produce the part of the VIDEO signal which controls the dis- and are therefore part of the TEXT ROM address- ing. Suppose the code for "A" $C 1 has been latched played picture. The PICTURE signal is added to the , , SYNC and COLOR BURST to produce the Apple RAM output and VA, VB. and VC are all high. at the VIDEO signal. The TEXT ROM is programmed to output the The heart of screen mode selection is the PIC- eighth row of the "A" dot pattern when it is addressed this way. A dot pattern is loaded to the TURE signal selection multiplexor at A9. It selects one of seven possible patterns for the PIC- TEXT shifter every cycle and shifted out similarly TURE signal based on its three select inputs. There to a HIRES dot pattern. are four LORES inputs, two HIRES inputs, and one The two upper bits of screen TEXT ASCII do not TEXT input to the picture MUX. The selection of address theTEXT ROM in earlier Apples. They are inputs depends on current screen mode, DL7 in connected instead to some circuits which interpret HIRES, and VC and HO in LORES. The nature of them to cause NORMAL. INVERSE, or FLASH- the seven inputs will become apparent as we ING dot patterns to be shifted out. DL7 high forces a progress. NORM AL character (white on black). If DL7 is low, PICTURE signal generation is a load and shift DL6 low forces an INVERSE character (black on white), and DL6 high forces the character to alter- process. Video patterns are loaded every cycle, nate between NORMAL and INVERSE at about based on the data resulting from the video scanner four alternations per second. This scheme was access to RAM. Then the patterns are shifted to the PICTURE signal line. There are two shift registers, changed slightly in Revision 7. A much larger 8-8 Understanding the Apple SYNC COLOR BURST -AA/*— APPLE —^AAr- VIDEO SIGNAL COLOR HEF- VIDEO HBL TO RAM ADDRESS MUX SCAN VIDEO BLAMKING GATE LOGIC VIDEO SCA^I^ER GRAPHICS TIME GATING M B< SOFT H0-H5. VA-V5 HIRES TIME TO cutout tm s re bit m RAM ADDRESS MUX | | [ | 7 j t j TEXT C050/1 AB LS257 HIRES 0056^7 SELECT PICTURE MIX C052/3 *- ^>- SEL SERIAL INPUT AND CONFIGURE GRAPHICS SHIFT REGISTER IT TO GRAPHICS PICTURE SIGNAL DL0-DL7 IS LATCHEO L0194—» LOjAlDj SHIFT REG. RAM DATA OUTPUT LORES SHIFT LSI94 LORES GRAPHICS TIME O^^ 14M'CKJ X SVCHRONIZES PICTURE SIGNAL /dL7- S3 SI SO SELECTION LORES GRAPHICS. VC HO DLS- 07 DL5- OUT LORES GRAPHICS .VC HO' O DL4- 4 D6 BtO 14M CP wit DELAY pw LU DC DL3- ^» — CO I DL?- LORES GRAPHICS -VC* HO D5 -q-Z tuj 1 DL1- LORES GRAPHICS . VC . HO' 04 DLO- TJ HIRES DL7- 7 SHIFT A9 EVERY PICTURE 0L6- OTHER CCOXQC 14M CK T SIGNAL DL5- SELECTOR UJC/3 — CJ DL4- (8T01 MUX) DL3- NOT LORES' GRAPHICS. 017' D2 DL2- DL1- V DLO- 14M NOT LORES. GRAPHICS. DL7^ CP 03 DELAY f VC VB VA u A3 A2 AT 7M- LL CK2 CKI LOAD \ SHIFTER TEXT, 01 :^l> c DLO- A4 05 00 DL1- ^^ AS " 0" 0L2- A6 TEXT A3 ROM 03 I— DL3- X A7 02 01 TEXT DL4- A0 0L7 [JL6 DL5- A9 I L INVEflSE L ,H FLASH DL6- IKVERT H L NORMAL TEXT NORMAL V DL7- H H Figure 6^ Video Geneiator FuncMonal Row Diagram. Video Generation 8-9 DUOUHIDIO 1011 1100 1101 1110 1111 Figure 6 A Apple Text Patterm. TEXT ROM is used and DL6 and DL7 are address- the middle of VBL. The television SYNC in the ing-inputs to it. These later Apples function the middle of long blanking gates creates the Apple same way as the older ones when you buy them, but displayed window surrounded by black margins on , ROM all sides (see Figure 8.5). It is normal to think of the TEXT can be replaced by your personal EPROM with alternate screen character sets con- horizontal scan lines as beginning with horizontal trolled by DL6 and DL7. sync, but in the Apple it is logical to think of horizon- tal scan lines as beginning with HPE', the first cycle of HBL. This is because HPE' is the preset of the horizontal portion of the video scanner, and it is the VIDEO SCANNER LOGIC GATING point where the vertical portion increments. Inside The video scanner logic gating is pretty straight- the Apple, video related signals tend to switch just forward. COLOR BURST, television SYNC, and after the display period ends. So as not to confuse it video blankinp: gates are generated by simple logic with the television horizontal scan, we will refer to gates with modifications possible via "Eurapple" the 65 cycle period beginning with HPE' as the jumpers. The Revision 1 schematic diagram of this horizontal PERIOD. logic gating is shown, along with the rest of the video Generationof the video SYNC signal was changed generator, in Figure 8.6. The parts of the video gen- in every major revision to the Apple II, so it's a little difficult not to get confused. The memory HIRES erator which are different in later revisions are shown in Figure 8.7. scanning map of Figure 5.9 shows very clearly when VBL (Vertical BLanking) is V4 • V3, true during SYNC occurs in the RFI Revision Apple. SYNC generation in the other revisions differs slightly. 70 states of the vertical portion of the video scanner. HBL (Horizontal BLanking) is H5' • (H3' + H4'), Reference to Figures 5,9. 8.2, 8.6, and 8.7 should true for 25 cycles starting with HPE'. The VIDEO help clarify the points of the following discussion.^ BLANKING gate is VBL + HBL, and it is connected In Revision 0, horizontal sync is HBL • H3. This to the enabling input of the PICTURE signal MUX makes SYNC go low for eight cycles beginning on via a flip-flop which synchronizes it to LD194, an the tenth cycle of HBL. The Revision horizontal shown the lower right important video output timing signal. When the sync pulse is in detail in synchronized VIDEO BLANKING gate goes high, corner of Figure 8.2. The vertical sync in Revision is V4 • V3 • V2 • VI'. This makes SYNC go low the VIDEO signal is forced into the black. The during the 16 vertical scanner states 111100000- LD194 synchronization results in blanking starting and ending just as PICTURE signal generation 111101111 (horizontal PERIODS 224-239 assuming ends and begins. the top displayed line is scanned during PERIOD 0). The television SYNC signal goes low for short The Revision vertical sync pulse would be illus- periods of time (horizontal sync) in the middle of trated in Figure 5.9 as solid rows of ns in lines HBL and for long periods of time (vertical syne) in 224-239. 8-10 Understanding the Apple Figure 8^ Blanking During Television Scanning Causes me Black Margin Around the Apple Display. Video Generation 8-11 In Revisionthe vertical sync equation was 1. unwanted spike could have been eliminated by changed to V4.V3*V2.V1'.V0'-VC'.{H5 + H4). routing H3 through a couple of LSTTL devices Adding VO' • VC to the equation reduces vertical before connection to pins 10 and 11 of C13. In Revi- + sion 7, H2' became partof the horizontal sync logic. sync to four horizontal PERIODS. Adding (H5 Its propagation delay through Q7 (A14 in^ RFI H4) puts little positive pulses or serrations in the vertical sync, so a negative edge occurs right where Apples) is sufficient to mask the unwanted spike at horizontal sync would normally cause a negative C13. edge to occur. These serrations are a feature of an A new IC was added to the motherboard at A14 in NTSC standard signal, and Apple probably added Revision 8 or Revision 9. The purpose of A14 was to them in Revision 1 to improve horizontal stability. add logic gating to the COLOR BURST generation circuitry to cure a problem in theColor Burst Killer. The Revision 1 vertical sync is accurately illustrated inFigure8.2andinSines224-227ofFigure5.9.The The Q6 Color Burst Killer was added to the Apple in horizontal sync in Figure 5.9 is not accurate for Revision 1 to eliminate color from the screen charac- Revision 1. because it shows only four #s. Eight Us ters in text mode. This is good, but QQ lets a small would accurately portray the eight cycle pulse residual amount of the COLOR BURST get through to the video signal. Some televisions and monitors width of horizontal sync in Apples prior to Revision occasionally lock upon this residual COLOR BURST 7. In Revision 7. the horizontal sync equation was and create an unreadable display of white text with colored ghosts. The Revision 8/9 change causes the changed from HBL • H3 to HBL • H3 • H2'. This reduced the pulse width of the horizontal sync from COLOR BURST to be gated off in TEXT mode eight cycles to four cycles as is shown in the lower using LSTTL logic before the signal ever gets to Q6. left corner of Figure 8.2. A change was also neces- This cures the unreadable text problem. sary to the COLOR BURST gating logic so it would The RFI Revision eliminated the double serration stilibe positioned correctly. The COLOR BURST that was introduced to the vertical syne in Revision 7. It also eliminated transistor Q7, which is present equation was changed from COLOR REFERENCE' • HBL . H4 • H2' to COLOR REFERENCE' • HBL only in Revisions 7. 8. and 9. The double serration • H3 • H2. 1 n either equation, the COLOR BURST is was removed by changing the {H5 -*• H4) portion of the vertical syne equation to(H5 + H4 + H8). Q7 was a sample of fourteen COLOR REFERENCE cycles occuring immediately after the horizontal sync. eliminated by performing its functions in A14. The Prior to Revision 7. the horizontal sync held the new gating logic caused an inversion in the COLOR SYNC signal low during the first eight cycles of the REFERENCE sample used for generation of vertical sync period. When the horizontal sync pulse COLOR BURST. This was countered by distribut- was reduced in width in Revision 7, a four cycle gap ing COLOR REFERENCE' to the video generator wascreated in the vertical sync. This would be illus- rather than the COLOR REFERENCE signal of earlier Apples. trated in Figure 5.9 by changing the fifth through eighth #s in lines 224-227 to +s. This effectively Video scanner logic gating is also used in switch- makes the horizontal serrations into double pulses ing between GRAPHICS and TEXT in the Apple's and probably detracts from .sync stability. Some MIXED screen mode. In MIXED mode. V2 • V4 digital video monitors which interpret every nega- identifies TEXT time. It is true during the last 32 tive edge on the SYNC signal as a horizontal sync displayed horizontal PERIODS and during the last pulse would not be able to operate with this double 38 undisplayed horizontal PERIODS of VBL. This pulse. This situation was corrected in the RFI means that in MIXED mode the Apple switches to Revision. GRAPHICS then back toTEXT during VBL, but it is not significant because the screen is blank during The author isn't certain why the horizontal sync pulse width was reduced in Revision 7. but he does VBL. Any time the screen mode is switched between know of one effect. It eliminates the little switching GRAPHICS and TEXT, including a MIXED mode spike that causes the vertical black line in the left switching, the switchover is delayed until the third margin of older Apples. The spike is present on the time RAS' rises after the switch logic changes. The SYNC signalatC13-8of the older Apples. It is there purpose of this is to delay the MIXED mode switch because HBL and H3 do not switch simultaneously. from HIRES to TEXT until the last HIRES pattern Since HBL is generated from the video scanner out- isshifted out. The fact that RAS' is used for syn- puts, it goes low a few nanoseconds after H3 goes chronizing mode switching is coincidental. There high at start display time of every scan. The are four RAS' clocked flip-flops not used by the 8-12 Understanding the Apple i 13.91 COLOB BEf - fvs.- FROM Rgure t& Schematic: Video GenerdtlOfi. Video Generation 0-13 BEV9' B*) COLOR BEF Pi) TEXT COM' (3 9) ^ I (J9) Hi Rgui© 8.7 Schemaflc: Revlslon-7 and RFI Vferston Changes to Video GenerciHon. 8-14 Understanding the Apple RAM data latch at B5 and B8. Three of these flip- PERIODS 73, 74. 75, and 76 of VBL in Eurapple flops are connected as a shift register to produce the scanning. By way of comparison, normal Apples mode switching delay required by the Apple design. have 36 PERIODS in VBL up through vertical svnc and 34 PERIODS in VBL afterwards. The Eurap- ple has 76 PERIODS in VBL up through vertical Eurapple Scanning syne and 44 PERIODS in VBL afterwards. The The discussions have been assuming the Apple critical states of VA-V5 in both NTSC standard would be driving an NTSC standard TV, just as the Apples and Eurapples are summarized inTableS.l, original Apple designer assumed it would be. In the The Eurapple jumpers give an Apple scanning Revision-1 board, Apple changed this by adding compatibility with European television, but not "Eurapple" jumpers which change the scanning colorsignal compatibility. Also as partof Revision 1, features of the Apple to be compatible with Euro- Apple brought television SYNC and COLOR REF- pean TV. This is accomplished by adding 50 horiz- ERENCE to previously unused pins 19 and 35 of ontal scans to the video scanner and by shifting the peripheral Slot 7. One can install a Eurocolor card vertical sync to maintain approximately equal black in Slot 7 which outputs a video signal compatible margins at the top and bottom of the screen. The with PAL or SECAM system televisions, both of horizontal scanning is not affected by the Eurapple which are found in Europe. The 14M crystal must jumpers. also be changed to a value equal to four times the European television has 625 horizontal scans in frequency of the chrominance signal used in a given two interlaced fields as compared to NTSC stan- system. dard 525 scans. Also, European TV scans vertically about 50 times per second as opposed to NTSC stan- dard 60 vertical scans per seconds. The Eurapple jumpers in the Apple cause the vertical portion of the video scanner to preset to 011001000, fifty less VfDEO GENERATION TIMING SIGNALS than the normal 011111010. This adds 50 scans to Video generation timing is based on several sig- the normal 262 for 312 horizontal scans in a Eurap- nals developed in the timing generator with LDPS' ple. All 50 of these scans are added to VBL so that and LD194 defining video output cycles. These and VBL is 120 scans long instead of 70. other timing signals are shown in Figure 8.8 along I n the video generator, Eurapple jumpers change with several examples of video output in the three the vertical sync equation to V5' • V4 • V3 • V2' • VO' modes. Actually, LDPS' and LD194 are used to • VC. (Ho + H4).The{H5 + H4) portion is(H5 + H4 + define the same time period, with LDPS' being used H3) in RFI Revision Apples and this horizontal logic when an active low signal is required. In the video adds serrations to the vertical sync identically to 60 generator, TEXT and GRAPHIC patterns are Hz configured Apples. In Eurapple scanning, the loaded byl4M rising when LDPS' tslow.7M is low, vertical sync lasts for four horizontal PERIODS, and LD194 is high. The patterns are shifted the rest just as in American scanning. These are horizontal of the time. Table 8.1 Eurapple/NTSC Differences. VERTICAL PRESET ON VERTICAL START VBL SYNC OVERFLOW SYNC END VBL VS43210CBA V543210CBA V5432ieCBA V543210CBA V54321flCBA NTSC 111000000 1I11000XX 011111010 100000000 EURAPPLE 111000000 011001000 011010OXX 100000000 Video Generation 8-15 A video output cycle lasts .98 microseconds, just 180 degrees out of phase in adjacent video cycles. In I ike a normal 6502 cycle. In this period of time there LORES this is compensated for by switching the are 14 cycles of 14M, 7 cycles of 7M, and 3.5 cycles of phase of the video pattern based on HO. There is no COLOR REFERENCE. During a video cycle, one compensation in HIRES, so the programmer must byte of data from memory is processed for video process even memory locations different than odd output, so there are 40 video cycles per display line. memory locations when producing colored HIRES displays. As an example, to produce a short green In HIRES and TEXT modes, seven dot positions are scanned per video cycle and the output is therefore line, 00101010 is stored at an even address or shifted every other 14M rising. More specifically. 01010101 is stored at an odd address. HIRES and TEXT loading and shifting are clocked by 14M rising- when 7M is low. Note that this is not TEXT VIDEO OUTPUT the same as 7M rising because of propagation delay of 7M after 14M. The LORES shift clock is 14M Text processing is very straightforward in the rising. Apple. The pattern from the TEXT ROM is loaded Video output timing is related to RAM timingand to A3 when 14M rises during LDPS' and it is shifted video scanner timing, naturally. Data from the to an exclusive-OR gate. The exclusive-OR acts like scanner access is latched at the RAM output by a selectable inverter, feeding the pattern to the pic- RAS' rising during PHASE 1 Then 14M rises dur- . ture MUX when INVERT TEXT is low and feeding ing LD194 before the next RAS', loading GRAPH- the complement of the pattern to the picture MUX ICS or TEXT patterns at the video generator. Then when INVERT TEXT is high. INVERT TEXT is the video scanner increments just before shiftingfor latched at the same time the dot pattern is loaded, so it will not switch in the middle of a TEXT output this video cycle begins. This means that the video output lags the scanner address by approximately cycle. As has been mentioned before, the inversion of one video cycle. LORES picture selection is based on video is dependent on DL6 and DL7 of the text scanner outputs HO and VC as they were for most of ASCII and the current state of the 2 Hz text flasher the previous video cycle. In LORES, HO and VC are when DL6 is high and DL7 is low. latched every LD194 and held for the entire follow- At the same time the dot pattern is loaded, the ing video cycle. Therefore even though HO may be INVERT TEXT signal is loaded into bit A of the high for most of the first video cycle shovim in Figure TEXT shifter. Then, during the TEXT shift, 8.8. LORES picture selection is based on HO low as INVERT TEXT determines whether the serial was the case when 14M went high during LD194. input to the shifter is high or low. This is mentioned Because of this latching action, Figure 8.8 illus- only because it is true and in spite of the fact that it trates video processing of an even screen memory serves no function. It makes a schematic diagram address followed by an odd screen memory address. investigator very nervous to say something like this. The saving of EQ and VC during LD194 is Why would they bother connecting wires that serve accomplished in a 4-bit latch at AlO. Besides HO and no function? Be that as it may, whatever is loaded or VC, other signals which change during the video shifted into bit A of the TEXT shifter never is cycle are synchronized to the videocycle by AlO and shifted to bit H before the shifter is reloaded by 14M used in piCTURE signal selection. These signals rising during LDPS'. are GRAPHICS TIME, DL7, the VIDEO BLANK- TEXT ROM was a In the original Apple II. the 2513 upper case character ING gate, and the INVERT TEXT signal. General Instrument A fact of life, when dealing with a 1 MHz video generator ROM. It is the contents of this character cycle and a 3.5 MHz COLOR REFERENCE, is that generator, illustrated in Figure 8.4. which deter- there are 3.5 COLOR REFERENCE cycles per mine the screen characters that are available in the video cycle. The result is that the COLOR REFER- Apple TEXT mode. The 2513 contains 512 5-bit ENCE*begins every cycle 180 degrees out of phase words arranged into 64 eight word characters. In from the way it was on the previous video cycle. Revision 7, thewiringof the TEXT ROM socket was Timing is set up so that COLOR REFERENCE is changed to accommodate the 8 x 2048 bit2316 ROM. always low at the beginning of even video cycles Apple puts exactly the same upper case character (cycles which process data stored at even memory set into the 2316. but it is set up so you can put more addresses). This is the purpose of the long cycle, to character sets in your own 2716 EPROM and substi- maintain this relationship in spite of an odd number tute it for the supplied 2316 ROM. That was a pretty of cycles (65) in a horizontal scan. Still, the fact neat thing to do. In any case, the modification did remains that identical dot patterns produce colors nothing to alter the TEXT load/shift cycle. 8-16 Understanding the Apple Figure 8.8 shows the output of the bottom dot COLOR REFERENCE to make up the VIDEO sig- patterns of an ampersand and an inverse amper- nal. As the dot pattern is shifted through the TEXT sand to the first two character positions at the left of shifter, the picture flip-flop will follow QH. lagging the screen. At the far left of the TEXT vvaveforms in it by approximately one 14M period. Figure 8.8. Ho through HO of the video scanner are The picture flip-flop ensures that all types of at 011000 meaning HBL and VIDEO BLANKING Apple PICTURE signal are begun at identical have just gone low. The RAM Latch contains $A6, TEXT points on the screen. For example, if it takes ASCII for a normal ampersand, driven out of RAM patterns longer than LORES patterns to be propa- by the scanner access. The combination of VA, VB, gated through the picture MUX, it doesn't matter. and VC all high and DL5-DL0 equal to 100110 All types of video are clocked by 14M rising on the drives01101outofthG2513TEXTROMor00011010 picture flip-flop. An interesting point about the pic- out of the 2316 ROM used in Revision 7 and later ture flip-flop is this: its low-to-high propagation Apples. delay (time after 14M rises for pin 5 to go from low to About 390 nanoseconds after the video data high) is 1,'^ nanoseconds typical, but its high-to-low becomes valid at the RAM Latch, 14M rises with propagation delay is 25 nanoseconds typical. Since LDPS' and 7M low, loading the dot pattern to the the PICTURE signal rises more quickly than it shifter. Leading and trailing zeroes are loaded on drops, the white portions tend to be a little wider either side of the five-dot pattern, although this can than otherwise equal black portions. For example, a be changed with the TEXT ROM in later Apples. white dotof a normal TEXT pattern would be about The access time of the TEXT ROM in the Apple 24 nanoseconds longer than the black dot of an must be under 390 nanoseconds. The typical time of inverted TEXT pattern. You can easily prove this to the 2513 is 250 nanoseconds, but the guaranteed yourself by displaying some normal TEXT next to maximum is 450 nanoseconds, so Apple was shading some inverted TEXT on a high frequency response their margin of error with this ROM. It is possible in video monitor. The "black dots" are not as wide as later Apples that they use 350 nanosecond 2316 the white dots. ROMs, and certainly you should use 3.50 nanosecond EPROM in your custom TEXT ROM. Of course, if The shifting of the normal ampersand progresses you have a 450 nanosecond EPROM that gives a until the value that was loaded to QB has been shifted toQH. The nextTEXTclockpulse will occur good display in a warm or cold room at power up and after two hours of operation, use it. There is no law during LDPS' low, so it will cause a load rather than against a 450 nanosecond memory which can be a shift. At the time of this loading clock, $26 ( inverse accessed in 390 nanoseconds. ampersand) will have been valid at the RAM Latch for 390 nanoseconds. The identical pattern is driven At the same time the dot pattern is loaded, the picture MUX ENABLE' signal is latched low, and out of ROMthat the normal ampersand caused since the INVERT TEXT signal is latched low. The the ROMaddress inputs are the same. When the former event shows the logic behind synchronizing loading clock rises, the pattern is loaded and VIDEO BLANKING to LD194. The blanking INVERT TEXT is latched high (because DL7 and becomes inactive at the exact time dot patterns DL6 are low). This pattern is shifted to the become ready for output at the leftside of the screen. exclusive-OR just as the previous one was, but The latter event occurs under control of DL7. When because INVERT TEXT is low, the inversion of the DL7 is high at LD194, INVERT TEXT is latched pattern is propagated through the exclusive-OR. low for the whole video cycle. If ASCII is driven out of RAM with DL7 low and The QH output of the TEXT shifter is felt at the DL6 high, the INVERT TEXT signal is latched DO and Dl inputs to the picture MUX shortly after high or low depending on the 2 Hz flasher. This the dot pattern is loaded. Either DO or Dl will be results in the flash coded screen positions alternat- selected by the MUX in TEXT mode, because S2 ing between INVERSE and NORMAL four times a (LORES TIME) and SI (GRAPHICS TIME + 1 second. This is true even if the ASCII is$60, code for RAS' + 1 LD194) are both low. Therefore. QH is a flashing space. In fact, a flashing character is the clocked to the picture flip-flop at BIO by the first way the monitor's RDKEY routine forms the flash- 14M rising after the pattern is loaded. It is the out- ing cursor while waiting for a key to be pressed. put of this flip-flop that is added to SYNC and More often than not, this is a flashing space. Video Generation 8-17 14M RISING 1 1 1 1 II II 1 1 1 FOUR FORMS QF THE HIRES V PATTERN 1011 OTO ^ 0300 IBH HORIZONTALLY liini|tiEii)l(]ii[i|(»ii WDiliioolotif) oo! 1 HKnj»w|an[iJM' 1001 nm MnjllWlllltB 01 TO 1001 oo[ciiiii 0011 100-1 nooj'^^i'^ ADJACENT CQL0R=9 LORES BLOCKS. VC EVEN LORES 7 'iw|otii ton IOOD Otllo|M10((X)Ol[lOOOJI |Diii|ioti|iir,t iii9|i]m||o'^ioia oioi iow|aioi|ii)m|ciiot|niic|i)ici|"|7T FOLLOWED BV ODD LORES 10 PRODUCES BROWNISH BORDER Figure d.8 Video Output Examples. 8-18 Understanding the Apple HIRES GRAPHICS OUTPUT for HIRES and select HIRES orTEXT based on the signal, GRAPHICS TIME + 1 HAS' latched by The HIRES output has similarities to the TEXT LD194, The HIRES dot pattern is shifted through output. Both the HIRES and TEXT PICTURE sig- QO of the GRAPHICS shifter to D2 of the picture nals are straightforward serial outputs of 7-bit dot MUX and through a delay flip-flop to D3 of the patterns. For this reason, it is possible to draw text MUX. D2/D3 is selected by the picture picture using HIRES graphics with the same 5 by 7 dot MUX, because SI and S2 are low in the HIRES patterns generated by the 2513 ROM. The HIRES configuration. DL7, latched by LD194, selects be- TEXT will have coloring however, because the tween HIRES (D2) and HIRES delayed (D3), COLOR BURST is enabled. Besides the COLOR The top HIRES pattern in FigureS.S is formed by BURST, important differences are: 01011010 being driven out of RAM by scanner 1. HIRES patterns are stored directly in RAM, access to an even address followed by an odd seven dots per byte. TEXT ASCII is stored in address. Just as in TEXT shifting, the pattern RAM, one character per byte, and TEXT patt- stored at LD194 is shifted every other 14M rising, erns are stored in ROM, eight rows of seven dots and the pattern is clocked to the PICTURE signal per ASCII code. by the picture flip-flop. As the leading 010 isshifted 2. The eighth-bit of the HIRES pattern, DL7. is out, the PICTURE signal starts black, swings white, not output to the screen. Rather its high/low then swings black, creating a square wave identical state is latched at load pattern time, and the in frequency to the COLOR REFERENCE. 3.58 HIRES pattern is delayed by a 14M entire MHz. The television will pass this signal through its period if DL7 was latched high. chrominance amplifier and phase compare it to the Figure 8.8 shows the same 7-dot HIRES pattern COLOR REFERENCE which it has reconstructed output in four different phase relationships with the from the COLOR BURST. The result of this phase COLOR REFERENCE. The result is the same pic- comparison will be color signals resulting in a ture pattern colored four different ways. The four HIRES green coloring of the dot on the screen. different colorings are produced by storing the pat- Compare the green dot position to the COLOR tern 1011010 at adjacent memory locations with D7 REFERENCE. Any PICTURE signal which goes reset and at adjacent memory locations with D7 set. white then black in this relationship with the We'll look at these output sequences, but first we COLOR REFERENCE will produce green coloring need to see how the video generator is configured in on the television. HIRES mode. Shifting along we come to the two adjacent white Since the Apple is in HIRES mode, the following dots. These dots are producfed by a signal that goes logical setup exists: white then black at 1.79 MHz. one half the fre- quency of the COLOR REFERENCE. Very little of this signal can get through the chrominance ampli- PIX MUX S2 = LORES TIME - low fier. The result is absence of color signals and subse- PIX MUX SI GRAPHICS TIME - high = quent white illumination. Anv\^'here on the screen, PIX MUX SO - DL7 latched COLOR BURST or no COLOR BURST, bringing during the PICTURE signal to the white level for a full LD194 period of COLOR REFERENCE will result in a GRAPHICS SHIFT MODE - 8-bit serial white picture. GRAPHICS LOAD/SHIFT The white pulse is followed by a violet pulse, iden- CLOCK - 14M rising tical in pulse width to the green pulse but occuring while 7M low in opposite phase relationship when compared to HIRES TIME - high COLOR REFERENCE. HIRES green and HIRES violet complement each other; that is, they are 180 The setup gets more complicated during switching degrees out of phase. between modes, but we assume the Apple is not When the identical 1011010 pattern is loaded currently switching modes. The burden of establish- from an odd address and shifted out, the PICTURE ing this configuration lies primarily with the LS257 signal swings from white to black and back just as it at A8. Its select input is tied to LORES TIME and did when the pattern was loaded from an even the logic of configuration goes like this: if it is address. The COLOR REFERENCE, however is LORES TIME, configure for LORES; if it is not 180 degrees outof phase from the way it was during LORES TIME, configure the GRAPHICS shifter the adjacent video cycle. The coloring of the screen Video Generation 8-19 dots is therefore the complement of the pattern out- turned on will be white. We will see shortly that put in the adjacent video cycle. Green becomes there are really only 139 orange positions. This is violet, violet becomes green, and white remains because an orange dot on the far right of the screen white. will be cutoff by HBL to make it dark brown. Also, The nature of HIRES green and violet video two adjacent delayed dots at the far right will be should now be fairly clear. The HIRES dot is exactly light blue green, not white, and the far left blue dot the width of half a COLOR REFERENCE period. will be violet or blue depending on the contents of r Visualize the COLOR REFERENCE alternating- up and down as the beam crosses the screen, starting- the last byte of memory scanned during the preced- ing HBL. with COLOR REFERENCE high as the display If color is of no concern, there is uninhibited pro- begins. If even position dots are turned on, they gramming of a 192 X 280 matrix of dots. With res- coincide with COLOR REFERENCE high and are trictions, this becomes 192 x 560. The main violet. Similarly odd dots are green, and twoor more restriction is that a delayed dot cannot be in the adjacent dots are white. This was the extent of same 7-bit group as an undelayed dot. For example, HIRES patterns in the Revision Apple II: 280 you can draw a slanted straight line close to the programmable dots per scan with violet, green, or vertical with 192 x 560 resolution. You can also draw white coloring. In Revision 1, the D7 delay option a very nice vertically oriented parabola with 560-dot was added which enables the delay of each 7-dot horizontal resolution at the portions where the slope pattern by one fourth of a COLOR REFERENCE ismore vertical. The other restriction on 560-dot period. resolutionis the interference at the boundary The output of the same 1011010 dot pattern, between adjacent delayed and undelayed patterns stored at adjacent memory locations with D7 set is which will be detailed shortly. also shown in Figure 8.8. The picture pattern is For coherent violet, green, blue, and orange identical, but since it is delayed by one 14M period, a colored displays, there is 192 x 140 dot resolution as pair of complementary colors are produced. nevt' long as certain pairs of colors don't get too close to The new colors are a result of the fact that delayed each other. Anytime you plot a green dot in the same dots have a different phase relationship with 7-dot pattern as an orange dot, that orange dot turns COLOR REFERENCE than undelayed dots. The to green, because D7 had to be reset in that memory mechanization of the delay is straightforward. DL7 location to plot the green dot. Similar considerations high, latched at LD194. causes the picture MUXto exist for mixing blue and violet. Any two adjacent select delayed QO for the HIRES PICTURE signal. dots will always be white. Delaying the 7-dot patterns was a tricky way of Why do colored HIRES objects appear solid if sprucing up the HIRES display; violet and green every other dot is turned off? Shouldn't a violet got a little old. Programming HIRES video became object appear to be numerous horizontal rowsof dots even more of an abstract art, however, with each rather than solid lines? The object appears solid group of seven dots having a color and position char- vertically because the horizontal scans are so close acteristic. Add this to the facts that alternating dot together. If you look at the violet object up close, you positions produce different colors, screen memory will see that it appears to be numerous horizontal addresses are difficult tocompute, and delayed lines. The reason that the object appears solid hori- HIRES patterns interfere with adjacent undelayed zontally is that a multichannel color television is not HIRES patterns; and you've got real programming capable of turning its beam intensity on and off comple.xity. cleanly at 3.58 MHz. Instead, the dots are blurred Delayed and undelayed HIRES patterns inter- into continuous horizontal lines. For the same rea- fere with each other? They sure do, but before we get son, Apple text is fairly blurred when displayed on a into that, let's summarize the characteristics of television set. HIRES video based on the discussion to this point. Now if you inject the same VIDEO signal into a First, there are 192 horizontal rows of dots. In each high frequency response video monitor, you will row. 280 dots (40 x 7) may be turned on or off. but clearly see the black spots between the dots in the since each group of seven dots may be shifted right lines that were violet on the television. It is very half a dot width, there are 560 dot positions in a row. educational to compare all forms of Apple video to Color depends on position, and there are 140 violet simultaneous displays on a television and high fre- positions, 140 green positions, 140 blue positions, quency monitor. HIRES and LORES graphics and 140 orange positions. Any two adjacent dots modes use the "slowness" of a television to display 8-20 Understanding the Apple colored solids, but the monitor shows the dot pat- Now think about the last 14M period of a delayed terns which produce the solids. The "slowness" of a PICTURE signal pattern. It is not shifted to the television is why computers that are designed to before the next video cycle begins. If the next video output TEXT to a television have a display of 40 pattern is also delayed, it will begin by completing TEXT characters or less. It is also for this reason the current dot pattern. If the next video pattern is that if you use an 80-column card with the Apple, not delayed, it will cut off the tail of the current you must support it with a hig'h frequency response pattern. The result is that continuous undelayed or video monitor. delaj'ed patterns fit snugly together, but a delayed pattern extends the last dot of a preceding unde- layed pattern by a 14M period, and an undelayed pattern cuts the last dot of a preceding delayed pat- Interference Between Adjacent Delayed tern in half. Cutting off or extending a dot has the and Undetayed HIRES Patterns effect ofslightly changing the dot pattern and. more The 7-dot HIRES patterns fit snugly together if noticeably, changing the coloring of the border dots. the adjacent patterns are all delayed or undelayed, As a result the HIRES programmer has one more but problems can be caused when they are mixed thing that affects color to educate himself about and together. This can be seen by comparing the delayed take into account. On the plus side, the programmer and undelayed HIRES patterns of Figure 8.8. can draw vertical lines at pattern borders in nine The sequence of starting a delayed pattern shift colors that are not otherwise available in HIRES. goes like this: He does this simply by turning on a right hand dot then extending or cutting it offviaDLT of the follow- ing pattern. In some instances, no dots need be 14M 1: Load pattern and latch DL7 high. turned on in the following pattern. 14M 2: Shift delayed QO to picture and load Figure 8.9 is a photograph illustrating the gener- delay flip-flop with first dot of pattern. ation of LORES colors at borders between delayed 14M 3: Shift first dot to picture. and undelayed 7-dot HIRES patterns. The program which generated this display is listed in Figure 3. 10. The point is that delayed QO is selected for output The mixed LORES/HIRES display is created by before the delay flip-flop has loaded the state of the switching screen modes in a 8515 cycle loop as is first dot position. What does the delay flip-flop con- discussed in an Application Note in Chapter 3. As tain at the first output clock of this video cycle? It the photo shows, any LORE^S color exceptdark blue- contains the state of the last dot position from the green (4) can be produced at a limited number of previous 7-dot pattern. This means that the first screen positions. LORES colors 3, 6, C, and 9 are 14M period of a delayed pattern to the screen is natural equivalents of the HIRES colors. LORES controlled by the last dot of the previous pattern. colors 7 and 2 can be produced at even/odd memory Figure S.9 The Output of the Screen Splitting Program (Figure 3.10). Video Generation 8-21 i addressing borders. Colors D and 8 can be produced BLANKING gate is precisely aligned to undelayed at odd/even borders. Colors B and E can be pro- video, and this doesn't change if the first and last duced at odd/even or even/odd borders. LORES patterns are delayed. Therefore, a delayed pattern color 7 can also be produced at the far left of the in the first video cycle of a display period extends bit HIRES screen, and LORES color E can also be D6 of the last byte of HBL scanned memory into the produced at the far right of the HIRES screen. Color display. In other words, half of an undisplayed 1 can be produced only at the far left of the HIRES memory bit gets displayed. On the right side of the screen. Finally, orange HIRES dots at the right side screen the last delayed dot is in an orange dot posi- of the screen are LORES dark brown {8). tion. This dot is cutoff by the VIDEO BLANKING Figure 8.10 shows some patterns created by mix- gate so the dot is dark brown rather than orange. ing delayed and undelayed dot patterns. Compari- Similarly, adelayed white pair at the far right is cut son to Figure 8.11 in the following LORES section off to make it light blue-green. will show that these patterns have the same phase The right side cut off is no great problem to deal relationship with COLOR REFERENCE as var- with, because it is predictable. The left side display ious LORES colors. The exception is the case where of a HBL scanned dot can be more confusing, The a trailing 1-0 delayed pattern is cut off by an unde- following Applesoft program is an example of what layed 1-0 pattern. This creates a green or violet with can happen: a different shade than any HIRES or LORES color. The general rule of all these HIRES interference 10 HGR : HC0LOR=5 : HPLOT 5,159 patterns is that delayed extends undelayed, and undelayed cuts off .delayed. TO 5,0 TO 279,0 TO 279,159 : The extreme left and right dot positions are spe- cial cases for delayed patterns. The VIDEO REM HCOLOR 5 IS ORANGE EVEN ODD ODD EVEN COLOR REF 01000000 10000000 r COLOR REF 01000000 1000O0O0 T_ EXTEND GREEN INTO EltTEKO VIOLET INTO L....JI LORES LIGHT eROWN(D) LORES LIGHT BLUE I?)' 11000000 oooooooo ItOOOOOO 00000000 CUTOFF BLUE WITH BLACK TO CUT OFF ORANGE WITH BLACK TO PRODUCE LORES DARK BLUE (2) PRODUCE LORES DARK BROWN (B)' 11000000 OOOOOOOl 11000000 OOOOOOOl CUT OFF ORANGE WITH VIOLET TO CUT OFF BLUE WITH GflEEN TO PRODUCE LORES LIGHT BLUE-GflEEN IE) L PRODUCE LORES LIGHT MAGENTA (B| L 1 1100000 OOOOOOOO 11100000 oooooaoo CUT OFF WHITE WITH CUT OFF WHITE WITH r- BLACK TO PRODUCE LORES BLACK ro PRODUCE LORES LIGHT MAGENTA (B) LIGHT BLUE-GREEN (E)-' -* OOOOOOOl 10100000 OOOOOOOl 10100000 CUT OFF BLUE.BLACK CUT OFF ORANGE,BLACK WITH GflEEN TO PRODUCE BRIGHT GHEEN ~1_ I- WITH VIOLET TO PRODUCE BRIGHT VIOLET J I L XIXXXXXX 10000000 LORES DARK MAGENTA (1) CAN 8E PRODUCED AT THE FAR LEFT OF THE SCREEN BY SETTING BIT SIX OF THE LAST BYTE OF HBL SCANNED MEMORY AND EXTENDING IT INTO DISPLAY TIME WITH 10000000 •L0RESLIGHTBLUEi7IMW ALSO BE PHOUSJCEDATTHEFARLEFT OF THE SCREEN BV SETTING BIT SIX OF THE LASTBYTEOFHBL SCANNED MEMOHV AND EXTENDING IT INTO DISPLAY TIME WITH lODOfflBI " THIS IS IDENTICAL TO THE CUT OFF OF A OELAVED PATTERN BV THE VIDEO BLANKING GATE AT THE RIGHT SIDE OF THE SCREEN Hgure 8.10 HIRES Interference at Pattern Borden. 8-22 Understanding the Apple What do you think will be drawn and in what color? erns will often be more trouble than they're worth. If you think the four points (5, 159), (5,0), (279,0). and Color and the presence of dots at the left margin (279,159) will be connected by three orange lines, depends on the presence or absence of dots at the then you're wrong. What happens is that (5,159), right margin or in undisplayed memory. One help- (5,0), and (279,0) are connected by two orange lines. ful hint: erase all $XX7F and $XXFF bytes of (279,0) and (279, 159) are connected by a dark brown HIRES memory as part of your erase routines. Then line, because VIDEO BLANKING cuts the orange don't use these bytes except to purposely manipulate dots off and makes them brown. Then (0,191) is the far left dots in the upper third of the screen. connected to (0,64) by a dark naagenta line. This last This section has shown how interference borders line is there because having the far left pattern can be used to display isolated dots or vertical line delayed extends the last dot of the last byte of HBL segments in HIRES that are not one of the four scanned memory into the display area. The last byte HIRES colors. Mostly, though, interference borders of HBL scanned memory for lines 64 through 191 is are a nuisance. Anytime two different colors get the last byte of display scanned memory for lines close to each other horizontally, the video pattern at through 127. Therefore, the last display dot of the their border is different than either of the solid top two thirds of the screen is extended to the first colors when compared to COLOR REFERENCE. display dot of the bottom two thirds by left hand Awareness of the causes of off color fringes should delay patterns. Dot (279,0) is extended to dot (0.64); help you experiment with color combinations that dot (279,1) is extended to dot (0,65) and so on. produce eye pleasing displays. Here's another line to add to the above program: 20 FOR A = 8319 TO 16383 STEP LORES GRAPHICS OUTPUT 128 POKE A, 64 : NEXT : LORES blocks are not generated the way you This line completes the magenta line at the left side would expect from lookingata television. You would up to (0,0). Did you catch those numbers? If BASIC expect big one microsecond pulses on the PICTURE used hexadecimal addresses, the line would read: signal would be required to produce those big one microsecond wide blocks. In reality, the only pulses 20 FOR A = $207F TO $3FFF STEP that are one microsecond wide in LORES are white $80 : POKE A, $40 NEXT : blocks. The colored blocks are made up of a string of narrow pulses, too narrow for a television to paint without blurring them into blocks, and narrow Those addresses are the last byte of the eight byte enough that they will be passed by the television's unused memory segments spread throughout chrominance amplifier. HIRES memory. They are the last bytes scanned Like the HIRES colored picture, the LORES before display time in the top third of the screen. colored picture signal swings back and forth They are supposed to be undisplayed, but line 20 between the black and white levels at 3.58 MHz. But causes dots to be displayed by POKING values to where the HIRES colored signals are nearly sym- them. Here's another example. Enter these metrical, the LORES colored signal may or may not keystrokes: be symmetrical This is why there is a greater var- iety of colors available in LORES. HGR ;HIRES mode, clear The logical configuration in LORES is as follows: I screen CALL-151 ;enter monitor .PIX MUX S2 = LORES TIME -high 2000:80 ;upper left pattern PIXMUXSl - VC latched by ; delayed LD194 207F:40 ;set last dot of PIX MUX SO - HO latched by ;undisplayed byte LD194 GRAPHICS SHIFT MODE - dual 4-bit end This is an example of the same thing. You should be around able to predict what happens. Try it. GRAPHICS LOAD CLOCK - 14M rising dur- The result of the extension of HBL scanned ing LD194 memory into the display is that far left delayed patt- GRAPHICS SHIFT CLOCK - 14M rising Video Generation 8-23 This establishes the natureof the LORES shift. Only waves whose 3.58 MHz sinusoidal component is four of the eight pattern bits are used in a video passed by the television's chrominance amplifier to cycle; DL0-DL3 in B4 are selected during latched produce different colors. The assymetrical square VC, and DL4-DL7 in B9 are selected during latched waves are produced by patterns with only one bit set VC. Latching the scanner states during LD194 syn- or only one bit reset. Those with only one bit set chronizes them to the video cycle. The VC control of produce dark colors, because the PICTURE signal the picture MUX results in bits DL0-DL3 control- spends most of its time in the black. Conversely, the ling the upper block and DL4-DL7 controlling the patterns with only one bit reset produce bright lower block. colors. As the example shows, the picture pattern at Since each 4'bit section of the GRAPH ICS shifter the border between colors 0111 and 1000 is a combi- circulates as clocked by 14M, the sections circulate nation of the two separate patterns. Even 0111 fol- 3.5 times per video cycle. Nice coincidence, that: 3.5 lowed by odd 1000 produces a pinkish border. million circulations per second— the same frequency The light blue block shows that some things are as COLOR REFERENCE. As the selected 4-bit predictable about bordering colors in LORES pattern is rotated, either itsleastsignificantbit(QO} blocks. Any odd pattern which ends in the white or its third leastsignificantbit(Q2) isclocked to the level will combine with the left side of even 0111 to picture flip-flop. QO is selected in video cycles where form a white border. The bright colors are particu- HO was latched low (even memory addresses), and larly prone to forming white borders, because Q2 is selected in video cycles where HO was latched they're only one black period away from being white high (odd memory addresses). This is what compen- themselves. sates for the alternating phase relationship between The third LORES example in Figure 8.8 is even the video cycle and COLOR REFERENCE. 0101 followed by odd 1010. These are the two gray Thebottom of Figure 8-8 shows the output of three LORES patterns. They are gray, because the PIC- different pairs of LORES blocks. These examples TURE signal they produce is 7 MHz, which will not illustrate the nature of LORES timing. The exam- be passed by the television's chrominance amplifier. ples shown all assume that latched VC is low. Tim- Now gray is really white in a dark disguise. White ing is identical when latched VC is high except B9 light can come in many intensities as evidenced by a outputs are selected for the PICTURE signal instead black and white television picture, and LORES ofB4. patterns 0101 and 1010 are just less intense white. The first example shows two adjacent 1001 blocks They are equal to each other in intensity, and are being output. In the even cycle, this pattern is output therefore identical shades of gray. This is why the 3.5 times beginning with the LSB: 10011001100110. technical overview stated there were 15. not 16. In the odd cycle, the pattern is output beginning LORES colors including black and white. with the third LSB: OllOOllOOllOOI. In either an Even though the two grays produce the same even or odd cycle the PICTURE signal is a symmet- medium intensity, colorless blocks, they are 180 rical square wave with the same relationship to degrees out of phase with each other. Thus, when COLOR REFERENCE as HIRES orange. The 1010 follows 0101 there is a discontinuity in the coloring of the left and right edge of the block waveform at the border between them and a result- depends on the pattern of the adjacent blocks. If ing color fringe. This can be done on purpose to adjacent clocks are the same pattern, the PICTURE separate two gray solids horizontally, or it can be signal is continuous, meaning orange mates to avoided by using only 0101 or 1010 in a display. A orange with no off color fringe between two blocks. good practice would be to choose one gray over the Different colors mate together with a joining pat- other to minimize unpleasant fringe borders with tern which is not the same as either of the joining other colors. colors, creating a color fringe which is more or less When the LORES colors are displayed side by prominent depending on the colors and whether side in numerical sequence, there is no apparent they meet at an odd-even or even-odd junction. The color continuity between them. The fact is that they examples are marked with an X at the left and right form a circular pattern of eight color tones deter- sides to show that the color there depends on the mined by the phase relationship to COLOR REF- adjacent patterns. ERENCE. This is not apparent when they are in The second example in Figure 8.8 is even 0111, numerical sequence, because video processing treats light blue, followed by odd 1000, dark brown. These the 4-bit color data as a dot pattern, not a numerical patterns produce assymetrical 3.58 MHz square value. 8-24 Understanding the Apple COLOR REFERENCE J 1 0001 DARK MAGENTA J L 1 1 1011 LIGHT MAGENTA 1 1 1 1 0011 HIRES VIOLET 1 1 1 0010 DARK BLUE 1 1 f 1 0111 LIGHT BLUE 1 1 • 0110 HIRES BLUE f 1 0100 DARK BLUE-GREEN 1 f 1 1110 LIGHT BLUE-GREEN 1 f 1 1 1 1100 HIRES GREEN n f 1 1000 DARK BROWN 1_ J 1101 LIGHT BROWN 1 1 1001 HIRES ORANGE 1 1 1 J 0101 S5 GREY 1 1 1 1 1 r 1010 $A GREY 1 f 1 f 1 f 1 1 1111 WHITE 0000 BLACK Hgura 6.11 LORES Patterns ol BIO, Pin 5. Video Generation d-25 Figure 8.11 shows the PICTURE signals, com- tones are in different sectors of a circle (if you can pared to COLOR REFERENCE, which are pro- picture a rectangular circle) and brightness is rep- duced by the various LORES patterns. White levels resented radially in the circle with dark at the cen- are a longer than equivalent black levels little ter and white at the outside. Black, gray, and white because high to lo\^' propagation on the picture flip- cover all sectors of the circle, because they have no flop takes longer than low to high propagation. The coloring. Black is the darkest color. Then comes colors are shown in an order in which the picture 0001, 0010, 0100, and 1000. The grays. 0101 and puke shifts right as the colors progress from top to 1010, are the sanie brightness as the HIRES equi- bottom. A very interesting point becomes evident valents, 0011, 0110, 1100, and 1001. Next brightest when looking at this figure. There are four color are 0111, 1110, 1101, and 1011. Brightest of all is tone pairs: dark and light magenta, dark and light white. Looking at the colors in this way should give blue, dark and light blue green, and dark and light you insights when you are trying to produce pleas- brown. For example, the dark magenta pulse is sur- ing LORES displays. rounded equally on both sides by the light magenta pulse, and the horizontal center of both pulses is at the same point on the COLOR REFERENCE. As a result, they produce the same color tone, but a series MIXED MODE SWITCHING of wide pulses is brighter and wh iter than the series of narrow pulses with the same color tone. A final topic to consider in the video generator is Now color 0001 is usually referred to as magenta. MIXED mode scanning. This is the reason we have and color 1011 is usually referred to as pink. This to live with those RAS' delayed terms, so we'll have a book has been calling pink "light magenta" to make closer look. the point that color 1011 looks like color 0001 with a Figure 8.13 is a timing diagram of the last display lot ofwhiteness in it. Anyone who wants to is cycle of line 159 in MIXED mode. At the leftside of encouraged to call pink "pink." this figure you can see the horizontal section of the Figure 8. 12 is a photograph of the LORES colors videoscannerswitch from 1111111 to OOOOOOO.This based on their circular nature. This display was is the beginning of HBL and the beginning of the generated by drawing the LORES display in long cycle, which has two LD194 pulses instead of LORES, drawing the color numbers in HIRES, and the normal one. At the same time the horizontal switching between LORES and HIRES in a 17030 section of the scanner goes to zeroes, the vertical cycle loop. This sort of screen mode switching pro- section goes to 010100000 making the term V4 • V2 duces a pronounced flicker which is very annoying true. This identifies TEXT time, but you can't when viewed. The flicker goes away in the photo- immediately switch to TEXT because the final dis- graph, however, which was taken at l/30th of a played GRAPHICS pattern is not yet output. For second exposure. In this display, the different color that matter you can't start blanking yet either. Bgure 8.1 2 LORES Colors. 8-26 Understanding the Apple PICTURE SIGNAL FROM LAST VIDEO CYCLE I 1 I nn 14M RISING Ill I I I I I r~i r~L 1_ '""' LD194 . _rL rLTL VSCAN = 010100000 VSCAN = 010100000 VSC AN = 010011111 HSCAN = OOOOOOO HSCAN = 1000000 HO HSCAN = 1)11111 VIDEO C14-6 BLANKING PICTURE MUX A9-7 -* BLANK PIX ENABLE' GRAPHICS TIME + 1 RAS' B5-2 GRAPHICS TIME + 3 RAS' 68-2 PIX MUX 81 A9-10 hr SELECT TEXT IF HIRES HIRES TIME B11-6 IF HIRES MIXED MODE 1 LORES TIME (PIX MUX S2) A12-13 IF LORES MIXED MODE t SELECT TEXT Hgure 6.13 Switching from GRAPHICS fo TEXT In MIXED Mode. What happens is that the GRAPHICS TIME sig- nal into the black, and' it exactly coincides with nal is shifted through three flip-flops which are the end of the lastvideo pattern. If, however, the clocked by RAS' rising. This creates the terms last video pattern is delayed HIRES, the blank- GRAPHICS TIME + 1 RAS' and GRAPHICS TIME ing forces the PICTURE signal to the black + 3 RAS'. These are the signals which control the prematurely, cutting the last dot in half. This video generator configuration. Here is an order of happens at the end of any HIRES scan, not just events after V4 • V2 goes high: line 159. 1. RAS' rises, bringing GRAPHICS TIME plus 4. RAS' rises, bringing GRAPHICS TIME plus one RAS' low. three RAS' low. This is followed closely by 2. 14M rises during LD194, signifying the end of HIRES TIME falling in HIRES mode, and by the video cycle. This loads meaningless data to LORES TIME falling in LORES mode. HIRES the GRAPHICS and TEXT shifters that will TIME is used in the RAM address multiplexor not be output to the screen. It latches the picture to cause HIRES memory addressing or TEXT/ MUX ENABLE' signal high (since VIDEO LORES memory addressing. Bringing it low BLANKING is now high). This forces the pic- just after RAS' rises switches TEXT/LORES ture MUX output low. Picture select Si MUX memory addressing in time so that RAS' falling also goes low at this time; in HIRES because will correctly clock the next TEXT memory GRAPHICS TI ME plus one RAS' is low and in ROW address to RAM. LORES TIME' is the LORES because VC is low. In HIRES MIXED select input to the LS2B7 configuration control mode, TEXT is now selected at the picture chip (A8). and LORES TIME is the S2 select MUX. input to the picture MUX. Bringing LORES 3. 14M rises again, clocking the low from the pic- TIME low here selects TEXT at the picture ture MUX output to the picture flip-flop. This is MUX in LORES MIXED mode. the instant that HBL forces the PICTURE sig- Video Generation fl-27 The switch back to graphics is made at the same and from text via the $C050/$C051 toggle, but point in the horizontal scan, and the delayed timing switching does not necessarily occur during a blank- similarly prevents display of the last video pattern ing gate. of line 261. The timing is similar when switching to 8-28 Understanding the Apple II SOFTWARE APPLfCATION ASPECT RATIO IN THE APPLE DISPLAY The aspect ratio of an NTSC standard television Let's say there are 1000 units vertically and 1225 is 4 to 3. This is the ratio between the horizontal size units horizontally in the display. The distance verti- of the display and the vertical size of the display. cally between HIRES dot centers would be 1000/192 Since the ratio ofdisplayed to undisplayed scanning = 5.21 units. In 280 point graphics, the distance is different in the Apple than in an NTSC standard horizontally between dot centers would be 1225/280 broadcast, the aspect ratio of the Apple displayed = 4.87 units. The dots are therefore further apart windowisnot4to3.Hovk'ever, we can utilize knowl- vertically than they are horizontally. More pre- edge of television scanning and Apple scanning to cisely, the ratio of the distance between horizontal compute the aspect ratio of A pple graph ics displays. dots to the distance between vertical dots is4.37/5.21 Progrannming computations can use this informa- = .84. This will vary with television alignment, but it tion to make squares square and circles circular. is very practical to use .84 and its inverse. 1,19. as The 4 to 3 aspect ratio is the ratio of displayed linearity compensation figures in programs. Here is horizontal and vertical travel of the beam. The tele- an example: vision horizontal display gate is about53.6 microsec- onds compared to 10 microseconds blanking, so 10 HGR HCOLOR = 3 : HPLOT 0,0 : 53.6/63.6 or 84.3% of the horizontal cycle is dis- TO 0,159 TO (159*L.19+.5) ,159 played. Vertical ly 242.5 out of 262.5 lines or92,4% of TO (159*1. 19+. 5) ,0 TO 0,0 : the horizontal scans are displayed. Let HD be the REM ADD .5 TO ROUND OFF. distance a beam would travel at horizontal trace speed during a horizontal cycle period. Let VD be This Applesoft program draws a square, because the distance a beam would travel at vertical trace the number of horizontal units is equal to the speed in a vertical cycle period. Then: number of vertical units times the ratio 1.19. (.843HD)/(.924 VD) = 4/3 In 140 point graphics computations, the horizon- and tal to vertical distance ratio would be doubled to HD/VD = L46 1.68. In 560 point graphics computations, the ratio would be cut in half to .42. LORES blocks are 7 Now in Apple scanning, 560outof 912 14M peri- HIRES dots wide by 4 HIRES dots high, so the ods are displayed in a horizontal cycle (remember horizontal distance between centers of blocks is the long cycle), so 61.4% of the horizontal cycle (7/4K.84)=1.47 times the vertical distance between period is displayed. Vertically 192/262 or 73.3% of centers of blocks. The horizontal distance between the vertical cycle Is displayed The aspect ratio of the . the centers of text characters is (7/8){ .84)=.735 times Apple display window is therefore: the vertical distance. The 5x7 text character itself is (.614HD}/(.733VD) = .838 (HD/VD) = 1.225 (4/6)(.84)=.56 times as wide as it is high (measuring This means the display window is 1,226 times as between the centers of the corner dots), All of these wide as it is high. ratios are summarized in Table 8.2. Table &2 Size/Distance Ratios on the Apple Screen. PLOTTING MODE HORI ZOHTAL/VERTICAL VERTICAL/HORIZONTAL DISPLAY WINDOW SIZE L.225 816 HIRES L40 Point Distance L.680 595 HIRES 280 Point Distance .840 ,191 HIRES 560 Point Distance .420 ,381 LORES Distance 1.47 .68 Text Distance .735 ,361 Text Size .560 ,786 Video Generation 8-29 HARDWARE APPLICATION ELIMINATING COLORED SHADOWS FROM TEXT In Revision 1, a Color Burst Killer circuit was killer adjustment in the back, so most new televi- added which turns off theCOLOR BURST in TEXT sions don't have it. If it is there, feel free to tweak on Mode. This is nice, because white letters are much it and try to eliminate your color shadows that way. easier to read than violet and green letters. The rlust make .sure that you still get color in GRAPH- problem with this circuit is that it does not com- ICS mode and on broadcasts if you also use the TV pletely eliminate the COLOR BURST but reduces it for normal reception. to a very small level. Some televisions lock up on this If no color killer adjustment is accessible on your residual COLOR BURST in an odd way that adds television, there is a second option which works well very unpleasant color shadows to text. In a recent on my Apple. Increase the size of R6, the COLOR mod to the Apple II Plus, this problem was elimi- BURST summing resistor. The size of this resistor nated by shutting off the COLOR BURST with a determines the amplitude of the COLOR BURST TTL gate before it gets to the sometimes ineffective when it is added to the PICTURE signal. By Color Burst Killer. Q6. This Application Note offers increasing the resistor, you decrease the size of the some suggestions for eliminating color shadows COLOR BURST and the amount of residual signal from older Apples on which the COLOR BURST is that gets through the Color Burst Killer. The trick is not quite dead in TEXT mode. to select a resistor that eliminates color shadows There is a color killer adjustment on the back of from the screen but doesn't prevent color graphics many television sets, especially older ones. This generation. This depends on the television rather adjustment sets the sensitivity of the television cir- than the computer. With my composite video moni- cuit which detects the presence of the color burst on tor, increasing R6 from 2.7 Kilohmsto4.7 Kilohms the back porch of the horizontal blanking gate. This worked nicely. adjustment is labeled "color killer" if it's there, and Disconnect the power cord before doing any work it may be just a hole in the back through which you on the motherboard. R6 is right next to the game I/O can stick a plastic screwdriver to engage the slot in a socket and is labeled 2.7K. You can remove it from potentiometer. the top of the motherboard with a soldering iron and DO NOT REMOVE THE BACK OF THE TELE- needlenose pliers. After R6 removal, desolder the VISION SET UNLESS YOU ARE A QUALI- holes with a solder sucker. Try a 4.7K resistor with- FIED ELECTRONIC TECHNICIAN. THE out solder to see if it solves the problem in a satisfac- VOLTAGES ARE LETHAL, tory way. If 4.7 Kilohms doesn't work, experiment. The television color killer adjustment is very sim- When you have the right resistor size, solder it in. ple to make. You simply adjust it so color broadcasts and you're done,* have color in them but monochrome broadcasts don't It is so simple thatour Asian television suppli- Please read the NOTE OF CAUTION at the beginning of the ers have figured out you don't really need a color book before performing any modifications to your hardware. 8-30 Understanding the Apple II HARDWARE APPLICATION PROGRAMMING SCREEN CHARACTER SETS IN EPROM In Revision 7 and later Apples, ones with 2316 HIRES pattern causes the pattern to be delayed half TEXT ROMs, you can install your own screen char- a dot position. In the DOS TOOL KIT sets. DL7 is acter sets. You nnay design your own upper ease/ occasionally set to improve the smoothness of a lower case set or use an existing upper case/lower character. These characters would look a little cock- case set. You may also design your own INVERSE eyed without the delay, so they need to be modified set and FLASHING set which will be output any- before using them in your TE XT EPROM. The way time a program outputs inverse or flashingtext, but to do this would be to load the set into ANIMATRIX they don't have to be inverted or flash ing characters. where the few delayed patterns can be easily spotted This Application Note contains some suggestions and the character modified for symmetry with no for burning screen character E PROMS for Apples pattern delays. Needless to say. if you use ANIMA- that will accept them. Please refer to Figure 8.7 TRIX to design your EPROM text patterns from during these discussions. scratch, don't use the delay feature. There are three groups of characters to consider Several other character generating programs are when building character sets: symbols and numbers, available, one very nice one at no cost. The August, upper case alphabet, and lower case alphabet These 1980 edition of KILOBAUD Microeompntimf mag- I will be referred to here as symbols, upper ease, and azine contains the listingof a character generating lower case. Character patterns for each group aid for the Apple and includes a full ASCII set. The require 256 bytes of storage so a complete character article is "Graphics Character Generator" by Robin set requires 768 bytes. You should place your pri- B. Moore. This character generator does not use mary character set in the top 768 bytes of the 2716 delayed patterns, so there would be no problem EPROM with symbols at addresses $500-$5FF, adopting the character set for your TEXT EPROM. upper case at $600-$6FF, and lower case at $700- If you have selected a HIRES character set for S'ZFF. This will result in word processing and sim- your primary ASCII patterns, you must move it to ilar programs being able to output lower case to your EPROM programmingbuffer in reverseorder. your screen. These 768 bytes will be driven out by Here is a little program sequence which can be used Apple character codes in the $AO-$FF range. in a transfer loop; Where can you get a full ASCII set of text pat- terns? There are numerous sources for character set patterns. One source is the DOS TOOL KIT distri- LDA (FONT) ,Y ;Get byte from buted by Apple. Among other things, this valuable ;source font disk contains21 character sets and ANIMATRIX. a LDX #7 program which implements computer aided design MOVELP LSR A ;Transfer D6-D0 in of other character sets. These HRCG(HIRES Char- ;reverse ROL WORK ;shift pattern to acter Generator) sets are meant to draw text on the ;intermediate loc'n HIRES screen, but they may be adapted for your DEX TEXT EPROM. The main difference between a BNE MOVELP HIRES character pattern and a TEXT ROM pat- LDA WORK tern is that they are reversed. The Apple's 2316 AND #$7F ;Reset FLASH ;control bit TEXT ROM is connected to the TEXT shifter so STA (BUFR) ,y that the most significant bit is shifted out first. HIRES patterns are shifted out least significant bit first, so HIRES patterns are in reverse order. A second adaptation that must be made to HRCG The 256 bytes of your EPROM just below the character sets is to offset the different effect of bit 7 primarv set will not be utilized by most commercial in theTEXT ROM and in a HIRES pattern. Bit 7 of programs. This area of ASCII (,$80-$9F) is the your EPROM fonts will control flashing in the lower CONTROL codes. You may place any sort of alpha- 1024 bytes of the EPROM. In the upper 1024 bytes. betic or symbolic set in this area of your EPROM bit7 will have no effect, butitsagood ideato leave it and output these symbols to the screen by storing reset any time you are not specifically program- codes $80-$9F in Text memory. This will also let you ming a character you want to flash. Bit seven set in a know when any program is storing control codes in Video Generation 8-31 text mernory. You will store the CONTROL patterns alphabetic section, the first one and last five are at$400-$4FF of your EPROM. symbols. Therefore, when installing lower case The lower 1024 bytes are the INVERSE area($0- patterns in the INVERSE Area, reserve addresses $1FF) and the FLASHING area ($200-$3FF). The $0-$7 and $D8-$FF of your EPROM for patterns ASCII codes which will drive out these patterns will from an upper case set. be in the $00'$7F range. If you leave 07 (EPROM To transfer the symbolic section of a TOOL KIT Output 7) reset in these patterns, the resulting char- set to the INVERSE Area, transfer the first third of acters will be inversions of your patterns. If you set the TOOL KIT set to $100-$1FF of the EPROM 07, the resulting characters will flash. You may buffer. The alphabetic part of the INVERSE area is force normal characters (white on black) in these $0-$FF of the EPROM, Lower case for this area can addresses by storing' inverted patterns and leaving be gotten from the last third of a TOOL KIT set. 07 reset In both the INVERSE area and the Upper case for this area can be gotten from the FLASHING area, there is space available for a middle third of a TOOL KIT set 07 in each byte of symbolic set and an upper or lower case set. the EPROM should be reset for no flashing, set for Notice that the upper half of the codes are d ivided flashing. To make the set normal instead of inverse into CONTROL, symbolic, upper case, and lower you must store the inversion of the TOOL KIT pat- case, but the lower half isn't. The upper half is terns at the EPROM buffer, this in addition to divided like true ASCII. The lower half is tailored to reversing order of the ones and zeroes as in the Apple features, giving the user a symbolic/upper- earlier programming example. In the earlier ex- case INVERSE set and a symbolic/uppercase ample, 07 was reset by ANDing the pattern with FLASHING set. Since Applesoft INVERSE and #$7F. You can invert the pattern and leave 07 reset FLASH commands and the monitor "I" command by following the AND instruction with an EOR: support this division, you would be well advised to maintain it in your EPROM. An idea for your INVERSE set is to make it nor- mal rather than inverse, and let the alphabet be AND #$7F lower case. This will give you a convenient way of EOR #$7F outputting lower case to the screen from Applesoft. STA (BUFR) If you do this, any alphabetic screen output from Applesoft with INVERSE active will be normal lower case. You may want to use one of the different Programming the FLASHING area of your TOOL KIT sets for this purpose, so you will know EPROM is exactly like programming the IN- when the INVERSE set is being used. VERSE area: 07 high causes flashing; the lower There are a few symbols associated with the upper half ($200-$2FF} is the alphabet; the upper half case and lower case alphabetic sections. If you store ($300-$3FF) is symbols. There is a restriction you lower ease patterns in an upper case area like the should place on your FLASHING set. The FLASH- INVERSE area, it is best to install upper case asso- ING set must be very easily distinguished from any ciated symbols there. Of the 32 characters in an other set, because the Apple cursor is generated by Table e^ The Division of Screen Text Patterns in a 2048 x 8 ROM. I APPLESOFT COMMAND CATEGORY ASCII EPROM ADDRESS INVERSE ALPHABET S00-S1F $000-$0FF SYMBOLS $20-$3F $100-$1FF FLASH ALPHABET $40-$5F $200-$2FF SYMBOLS $60-$7F $300-S3FF NORMAL CONTROL $80-$9F $400-S4FF SYMBOLS $A0-$BF $500-$5FF UPPER ALPHA $C0-$DF $600-$6FF LOWER ALPHA ?E0-$FF $700-$7FF 8-32 U ndersta nding the Apple 1 flashing the text character under the cursor. You What's wrong with letting FLASHING charac- may make your FLASHING set distinguishable by ters flash and INVERSE characters be inverted? having it flash, inverting it, putting a mark on it Nothing— it's just that customizing your Apple is (like a dot in the upper left corner of every charac- fun and rewarding. Burning your special screen ter), or by using an odd HRCG set in the FLASH- character EPROM is an easy way to do this, and the ING area. As an example, you could use the symbolic capability is a nice feature of newer Apples. and upper case "OUTLINE" set from the DOS A final" word of advice is to use 350 nanosecond TOOL /f/Tin the FLASHING area. Your CURSOR EPROM for your TEXT pattern ROM rather than position would then be identified by a text character the more commonly available 450 nanosecond vari- ety. The Apple design only gives a 390 nanosecond changing to the interesting OUTLINE form. You would want to let the symbols be displayed inverted address setup time before the ROM data must be valid. 450 nanosecond EPROM will probably work, or flashing because the symbols and numbers in the OUTLINE set are not distinct enough from a nor- but if your screen text starts looking odd on a hot mal set. summer day, you'll know what's causing it. Video Generation 8-33 TECHNICAL NOTE DETAILS OF TELEVISION PROCESSING OF APPLE VIDEO A rigorous examination of the television process- the reconstructed color reference sine and cosine ing of the Apple signal involves technical details waves to produce color signals. It is also processed beyond the scope of ViiderHtauiiitig the Apple II. by the luminance amplifier to produce the lumi- Brief descriptions of some of these technical details nance signal. are presented here for those readers who wish to Many televisions have a 3,58 MHz trap in the study television processing of Apple II video in luminance path which reduces color interference depth. with the luminance signal. The effect of this trap is Asquarewaveisthesumoftheoddharnrioniesofa to remove the 3.58 MHz variation, and pass a gray sine wave of the same frequency. For example, a 3 luminance level which lasts for the duration of the MHz square wave can be produced by summing the 3.58 MHz presence. A similar effect is felt on the 7 following- sine waves: MHz modulation envelope produced by LORES 5 3 MHz at amplitude A and 10 colors. The? MHz + carrier frequency is out 9 MHz at amplitude A/3 of the band pass of the IF strip, so the 7 MHz varia- 15 MHz at amplitude A/5 tions are removed and replaced by a gray level. These solid gray !evels do not degrade the Apple luminance signal, but enhance it. We cannot see 3.58 MHz variations in picture brightness at normal viewing distance. We Just see solid blocks of bright- The more harmonics added, the more perfect the ness. Conversion of 7 MHz and 3.58 MHz signals to square wave. This sinusoidal make-up of a square solid gray levels does not, therefore, degrade the wave is significant because tuned circuits such as picture we perceive. those found in a television receiver respond to the A very interesting special case among Apple sinusoidal components of signals. A square wave PICTURE signals is that created by turning alter- will be processed as the sum of its sinusoidal nating groups of three HIRES dots on and off. Con- components. ventional Apple wisdom is that this will create a Generally, Apple PICTURE signals, which pro- horizontal dashed line with white coloration of the duce color displays, are 3.58 MHz square waves. dashes because they are three adjacent dots. How- These square waves modulate a television carrier ever, the picture signal produced by this pattern is a frequency in the user supplied modulator, creating square wave of 3.58 MHz/3. This square wave has a radio frequency with a square modulation enve- MHz sinusoidal content, since 3.58 significant 3.58 lope. Sinusoidally, the square wave intelligence is MHz is the third harmonic of the fundamental carried by the following series of frequencies: square wave frequency. This produces a 3.58 MHz carrier sine wave at the output of the chrominance ampli- carrier + 3.58 MHz fier about one third the amp! itude of the signal pro- carrier + (3.58 MHz) x 3 duced by a3.58 MHz PICTURE signal. The result is carrier + (3.58 MHz) x 5 a washed out coloring of the 3,58 MHz/3 PICTURE signal, not nearly as intense as the coloring of 3.58 MHz PICTURE signals. The chrominance ampli- MHz to 4.1 MHz, so fier frequency band is from 3.1 The IF strip of the television will pass the sine any PICTURE signal from 3.1 MHz/3 to 4.1 MHz/3 wave carrier and those sine wave frequencies above should have some coloration. the carrier, up to carrier + 4.2 MHz. Only the carrier A second television phenomenon is less predict- and carrier + 3.58 MHz of the above distribution are able. Many televisions have a coupling transformer within this range. As a result, the 3,58 MHz square or inductor/capacitor combination at the input to envelope is converted to a 3.58 MHz sinusoidal enve- the chrominance amplifier. I have found that this lope, and the output of the second detector in the input circuit has a marked tendency to ring at 3.58 television is a 3.58 MHz sine wave. This sine wave is MHz when the PICTURE signal switches from passed by the chrominance amplifier to the syn- white to black or black to white. This ringing pro- chronous demodulator, where it is processed with duces an output from the chrominance amplifier of a-34 Understanding the Apple II 1 about the same ampl itude as that produced by a 3.58 227(horizontal frequency)" and the "carrier -t- MHz/3 PICTURE signal. One result )s edge color- 228{horizontal freq)" energy concentrations of the ing of white screen displays. The 3.58 MHz ringing luminancesignal. The "carrier + n(horizontal freq)" should vary greatly from television to television, and luminance distribution is thus interlaced with the may be reponsible for many of the off-color edges "carrier + 227.5{horizonta! freq) + n(horizontal found in Apple displays. freq)" distribution. This reduces interference be- In a normal television broadcast signal, the lumi- tween the chrominance and luminance signals. nance signal energy is concentrated at multiples of The Apple PICTURE signal is high in horizontal the horizontal frequency removed from the picture frequency harmonic content, just like the normal carrier. This is because the luminance signal itself television luminancesignal and color signals. There- has a very high content of harmonics of the line fore, the energj' of the modulated carrier should be scanning frequency. When the luminance signal distributed primarily at "carrier + n{horizontal modulates the carrier, the energy is largely distrib- freq)" intervals. The process of modulating a 3.58 uted in groups centered at the following frequencies: MHz subcarrier with a color signal does not take place, so the "carrier + 3.58 MHz + n(horizontal earner freq)" energy distribution should not exist to the carrier + horizontal frequency same extent as it does in a normal television chromi- carrier + 2(horizontal frequency) nance signal. However, the 3.58 MHz PICTURE signal with horizontal frequency harmonic perio- dicity should create some elements of the "carrier + 3.58 MHz + n(horizontal freq)" distribution when the carrier is modulated. It is. therefore, interesting The color signals have a similarly high content of to note that the 3,58 MHz COLOR REFERENCE horizontal frequency harmonics. When the 3.58 signal of the Apple is 228 times the horizontal fre- MHz color subcarrier is modulated by a color signal, quency, not 227.5 times the horizontal frequency as the energy is largely distributed at in a normal television signal. This means that the MHz (suppressed) "carrier + n(horizontal freq)" energ\^ distribution is 3.58 3.58 MHz + horizontal frequency superimposed, rather than interlaced, with the 3.58 MHz + 2(horizontal frequency) ' "carrier + 3,58 MHz + n( horizontal freq)" distribu- tion. My conclusion is that the energy of a carrier wave modulated by Apple video is largely distrib- uted at multiples of the horizontal frequency removed from the carrier frequency, with no inter- The 3.58 MHz color subcarrier is used because car- laced distribution induced by the chrominance rier + 3,58 MHz resides between the "carrier + element. i DATA BUS chapter 9 DATA REGISTER The Disk Controller CONTROL HEAD PULSE READ INTER- LOGIC FACE STATE SEQUENCER WRITE SIGNAL > CONTROLLER DISK DRIVE The coming of age of inexpensive floppy disk disk I/O is merely faster and more convenient than drives has been a very important factor in the cur- cassette I/O. But for important computer uses such rent proliferation of personal computers. By the as word processing, data base management, busi- same token, the timely introduction of the Apple ness accounting, and file handling, the disk drive or Disk II and its associated Disk Operating System its equivalent is mandatory. There can be no doubt was a very important factor in the growth of Apple's that for most owners the disk drive is the most share of the market. important peripheral in the Apple II computer. There has been a real personality change in the Since the original Apple II was strictly cassette Apple II since it was introduced. It was originally a based, the interface to the Disk II had to be built on a neat, cassette based machine whose creative and peripheral card. The extent of motherboard support versatile design made it an initial success. The orig- of the Disk II is an empty card slot and the Autostart inal hardware and firmware are the rock upon ROM. The Autostart ROM has no disk handling which the Apple empire has been built. Assets from routines but only looks for disk handling routines in the original success put the com pany in a position to the peripheral slots and jumps to them at power up. keep the Apple competitive with improvements The Bootstrap program and the circuits that inter- such as Applesoft. RAM and ROM cards, and the face the computer with the drive are on the disk Disk II. Combined with substantial software and controller, which is a peripheral card usually hardware support from other vendors, these improve- installed in Slot 6, The disk controller is connected ments made the Apple 11 into what it is today one — by a 20 wire ribbon cable to the disk drive, which of the world's most popular personal computers. contains more electronic circuits as well as the drive The long term success of the Apple II could not mechanisms. It is primarily the controller circuits have come about without the development of the and the DOS which determine the features of disk Disk II. For simple storage of data and programs, operation that are unique to the Apple, and it is the 9-2 Understanding the Apple II "O" rU V kUJ — UJ S 3 00,1 CQ| •a. ' small. Mike Markkula, Figure 9.1 is a functional diagram of Apple disk the chairman of the board, presented the group with I/O. Data transfer between the MPU and the con- troller is eight bit parallel via the data bus. Control a list of products needed to be developed for the Apple. At the top of the list was a floppy disk drive by the MPU is via the address bus, of course.* Data transfer between the controller and the drives is for the Apple IL Within a very short period of time, serial, and control of the drives is via multiple con- Apple developed the Disk 11 and released it along trol lines serving various functions. The controller is with its operating system, DOS 3. primarily adigital data processing device, while the The disk drive chosen by Apple was a Shugart SA400. Apple designed their controller card analog circuit card in the disk drive primarily per- (mounted in a peripheral slot), analog card (mounted forms the functions of amplification, shaping, and gating. Control of the disk is software intensive, in the disk drive), and data formats around this standard drive. More recently, a subsidiary of Apple meaning very little is done automatically by Computer Inc. makes the Disk II drives, but these hardware. drives are nearly identical to the old Shugart drives. Hard sectored disks are disks with little holes in Other companies make drives and controllers them which divide the disk into a number of sectors. Disk drives supporting hard sector formats have a which will work in the Apple 11. If you are inter- sensor in them which signals the host computer ested, a review of various 5 1/4" disk drives avail- able for the Apple was presented in Jeffrey Mazur's when a hole is passing by and allows a program to determine where the disk is in its circular trip. The "Hardtalk" column in the September, 1982 edition Disk II does not have this feature, and the Apple of So/talk magazine. Other compatible drives and controllers will be similar, but the discussions in DOS doesn't require it. Instead, the Apple uses a soft sectored format in which positional informa- this chapter detail the operation of the Disk II con- tion is stored on the disk in uniquely identifiable troller and, to a lesser extent, the Disk 11 drive. address fields. These address fields are the "holes" Floppy disks are magnetic media,Just like audio which divide the disk into sectors and identify rota- and video tapes. Reading and writing is performed tional position. The address fields contain an address by rotating the disk while a stationary read/write field identifier and a volume-traek-sector address head presses against it. Disk speed is 300 RPM which translates to 48.4 inches per second on the from which programs can locate specific address fields. Behind each address field, there is a data inner track. This is a great deal faster than audio field with space for 256 bytes of data. An address cassette tape speed so the rate of data transfer is greater than that achieved in a cassette storage fieldand the data field that follows it make up a sector of disk information.** system. In between read or write periods, the head may be positioned radially so that different tracks can be written to or read from. The head is positioned pre- cisely by a stepper motorunder 6502 program con- trol. There are thirty-five tracks on the Disk II, but some second source drives have forty or more tracks MPU *In this chapter there is much discussion of the role of the in which can be utilized by modifying the DOS. There disk I/O. The reader will do well to remember that whiJe the is no hardware sensor that can be used to determine MPU has certain capabilities of manipulating the Disk II hard- ware, these capabilities can only be utilized under program con- trol. In other words, a 6502 program must supervise the role of the MPU in disk I/O. •Operation of the DOS is well documented in the book, Bmeaih Appie DOS. by Don Worth and Pieter Lechner. Quality Software, The Apple Disk 1 1 and DOS will work with hard sectored disks, 1^2. but the holes in the disk will be ignored. 9-4 Understanding the Apple DATA BUS V DATA REGISTER CONTROL READ PULSE READ <- INTER- LOGIC FACE STATE SEQUENCER WRITE SIGNAL — ^ l>t^ CONTROLLER DISK DRIVE Figure 92 Data Transfer in Disk i/O. The DOS writes 16 sectors (address fields fol- call to RWTS: FORMAT, READ, WRITE, and lowed by null data fields) in its FORMAT routine. SEEK (head position only). FORMAT writes iden- The 16 sector format is not unconditionally dic- tifying information for 16 sectors on all thirty-five tated by hardware. It is just a very reasonable tracks. READ positions the head and reads a speci- number of sectors to have, considering the facts that fied track/sector, and WRITE positions the head the 6502 addressing nnodes are best suited for and writes to a specified track/sector. SEEK moves manipulation of data blocks up to 256 bytes in size, the head to a specified track. that 256 bytes is a workable size for data blocks in Ignoring elaborate copy protection methods, the disk I/O, and that the Disk II is capableof storing 16 normal method of reading a sector is to position the sectors of 256 bytes on a track in the DOS 3,3 format. head and poll the disk input port until the desired As an example, the hardware will let you store data identifying leader, or address field, is found, Then in eight sectors of 512 bytes each. Sixteen sectors of the following data is read into an area of RAM the 256 bytes, however, is the only format supported by size of the sectors being used.Data is written one DOS 3.3 and its RWTS subroutine, and the only sector at a time. The DOS writing method is to find reasons to deviate from it are for copy protection or the pertinent sector on a formatted disk as when to have fun (using the word "fun" in a very broad reading, but to overwrite the following data area sense). after the desired sector address field has been found. The nuts and bolts details of disk I/O in most Figure 9.2 shows the paths data takes duringdisk Apples are handled by the RWTS (Read or Write a I/O. Data is transferred between the MPU and the TVack and Sector Subroutine) of the DOS, The data register on the controller, one byte at a time majority of the DOS is concerned with such tasks as over the data bus.* Data is shifted serially between command interpretation and execution, file man- agement, track and sector mapping, and cataloging. Anytime it actually reads or writes disk informa- •The data resrister is referred to in some writings as the data tion, however, it uses RWTS. There are four types of latch. The Disk Controller 9-5 the controller and the d isk drive under control of the analyze the sequencer in great detail, but first we logic state sequencer on the controller. The logic need to lay the groundwork by looking at the hard- state sequencer is a ROM and some flip-flops wired ware environment. up to act ike a ittle 2 MHz computer. It has a stored 1 I prog-ram which it sequences through while exe- THE DISK II DRIVE cuting commands that control the data register. Some writings refer to the sequencer as the "state Figure 9.3 is a functional diagram of the Disk 11 machine," but logic state sequencer more accu- drive. The intention here is not to explain all details rately describes its functions. Via address bus of floppy disk drive operation, but only to establish commands, a 6502 program can configure the the basis of control of the di^ive from the computer. sequencer to shift out write data, shift in read data, In addition to Figure 9.3, reference to Figure 9.1 or shift in the state of the write protect switch in the should help clarify the points of discussion. Even disk drive. though only the Apple Disk II is spoken of, most of In the write process, a 6502 program causes the the discussion will also be valid for substitute drives. MPU to store a byte of data in the data register of the As Figure 9.1 indicates, all connections to the drive controller. The logic state sequencer shifts this are routed to the controller. information, monitoring each bit individually. Every time the sequencer sees a one, it toggles the Power Supply WRITE signal. This changes the direction of mag- The drive takes its power supply voltages from the netic field in the read/write head. As the disk Apple's main power supply. +12V, -12V, and -5V are passes across the head during write operation, the all utilized, but only +12V is used for motor drive. surface of the disk near the head is magnetized, and Since +12V is used both to position the head and the direction of field in the head determines the rotate the disk, the load on +12V is significant, espe- direction of the magnetic field on the disk. When the cially at disk start-up. The drive has a high capacity writing stops, the data remains on the disk in the +12V input filter to assist the Apple's power supply form of transitions or lack of transitions in the mag- in supplying motor start-up current. netic field. Disk I/O is identical to cassette I/O in this regard. Serial data is stored in the form of magnetic The DRIVE ENABLE' Input field reversals on the medium. A ONE is a field The ENABLE' input is low at drive 1 or drive 2, reversal. A ZERO is the lack of a field reversal. but not both, when a drive is being accessed. At the Reading is the reverse of writing as far as the enabled drive, the drive motor is on, the IN USE read/write head is concerned. As the disk rotates. indicator glows, head positioning is enabled, and the magnetic field reversals on the moving disk surface read pulse output and the state of the write protect cause voltages to be induced in the head. The voltage switch are enabled to the controller. Speed of disk pulses are sensed by a special purpose floppy disk rotation is regulated by a motor speed control board read interface chip which puts out a nice square in the back of the drive. This speed is adjustable via read pulse for every magnetic field reversal on the a potentiometer on the speed regulator board. disk. The sequencer monitors these read pulses and shifts ON Es and ZEROs into the data register based The Head Positioning Mechanism on the presence or absence of the read pulse at the normal write interval. The head assembly is positioned precisely, via a The sequencer syncs up on the read data if it was stepper motor. The stepper motor, which rotates, is written properly. This means that it will shift data linked mechanically to the head assembly, which into the data register until a complete byte is shifted travels linearly. A 6502 program positions the head in, then it holds that complete byte long enough for a assembly by directly controlling the four phased 6502 program to detect it by polling the data regis- inputs to the stepper motor. ter. The program recognizes that the data register Figure 9.4 is a functional diagram of a four phase holds a valid byte when the most significant bit of stepping motor, which can provide a basis for the register is set. When a valid byte is detected, the understanding the positioning of the read/write program must quickly process or store the byte and head. The rotor is a cogged ferrous drum whose cogs start checking the data register for the next one. may be attracted by one of four electromagnets. The It can be seen from this overview that the key to electromagnets are activated sequentially under understanding how data is transferred to and from program control. There may be any number of cogs the disk is the logic state sequencer and how it is on the rotor, but only one of them is next to one of the manipulated by the 6502 program. Later, we will four electromagnets at any time. 9-6 Understanding the Apple OPEN COLLECTOR COIL DRIVERS 20 RN RIBBON CABLE CONNECTOR TO CONTROLLER PLUG 1 STEPPER Phase-0 [2 "CL) ULAA^ STEPPER 1 Ptiase-1 4 -CD UJLA-/ STEPPER 2 Phase-2 6 "UULAJ" Phase-3 8 "UULAJ" STEPPERS 1,3,5.7 •TO WRITE/ ERASE GATE "DRIVE MOTOR DRIVE 1141 ENABLE''^* f^^ ^ , V^A/^-»—(X) ^ MOTOR CONTROL r^ WRITE PROTECT "^^ <1> ENABLE* GATED +12V READ a PULSE ^TU^ WRITE REQUEST' Qir*^ WRITE jTa l , ^^=>U=H>C\ i ERASE HEAD SIGNAL Vlr* DISK 11.12 MOTION [r>--12V Rguro9J S1mpim«d RjncHonal Pkigfam of DMc H Driva. The Disk Controller 9-7 Phase-O Phase-1 Phase'2 Phase-3 RETURN figure 9^ A Stepping Motor. To rotate the rotor one step to the right in Figure write protected. Configuring the drive for writing 9.4, energize the phase-2 magnet, then deenergize consists of allowing the WRITE signal to control the phase-1 magnet. Magnetic attraction will then the current in the coil of the read/write head, and of align the cog with the phase-2 magnet. To go three applying a direct current to a second head referred steps left from this new position, perform this pro- to here as the erase head. The WRITE SIGNAL gression: phase-1 on, phase-2 off, wait, phase-0 on, control of the current in the read/write head is such phase-1 off. wait, phase-3 on, phase-0 off, wait. The that the high/low state of the WRITE signal deter- wait is for the response time of the motor, which is mines the direction of the magnetic field set up in slow compared to the MPU. Summarizing, to step the read/write head. left, sequence through the phases in descending Current in the read/write head tends to produce order. To step right, sequence in ascending order. magnetic fields on the disk parallel to disk motion. The Apple disk drive uses a four phase stepper Current in the erase head tends to produce magnetic motor for head positioning. The controller has pro- fields on the disk perpendicular to disk motion. The visions for bringing the control voltage for each actual strength and direction of the fields produced phase high or low individually. In the drive, these are a result of the vector sum of the WRITE signal voltages will turn on or cut off current to the elec- field and the erase field (see Figure 9.5). The pres- tromagnets in the stepper motor. A good deal of the ence of the erase field means that there is always software overhead is required to position the head some field in the head assembly while writing, even and remember its location (See PROGRAMMING in the middle of a WRITE signal field reversal. The EXAMPLES FROM RWTS later in this chapter). absence of a field in the head assembly would allow Two phases must be stepped through to position the previous field alignment on the disk to remain head one track, and the Disk II and DOS support unchanged. Thus, the erase field causes the pre- thirty-five tracks. viously written data to be erased when the WRITE signal component of the field vector has an ampli- Writing to the Disk tude of zero. There are two write related inputs from the con- As was mentioned in the overview, data bits are troller to the drive, WRITE REQUEST' and the stored on the disk as field reversals, or the lack of WRITE signal. WRITE REQUEST' causes the field reversals, at a regular interval. This fact is not drive to be configured for writing unless the disk is- changed by the presence of the erase component in 9-a Understanding the Apple MAGNETIC FIELD REVERSAL AEAO/WniTE HEAD ERASE HEAD n~> WHILE WRIUNG Figure 9^ The Write Field is the Viector Sum of ttie WRITE and ERASE Relds. the field. Just understand that the erase, or radial, The WRITE PROTECT signal and the read pulse component is constant, while the read/write, or tan- are the only two outputs from the drive to the con- gential, coniponent reverses depending on the troller (see Figures 9.1 and 9.3). Both are output WRITE signal. through tri-state drivers which are gated by the The Write Protect Switch drive ENABLE' input. This allows the two drives to There is a spring loaded switch in the drive which share control of the read pulse and write protect lines. is open when a write protected disk is installed. A write protected disk is one with no notch on the left An interesting feature of the write protect circui- edge or one with the notch covered up. Having this try is that its activating voltage is the phase-1 vol- switch open causes the WRITE PROTECT signal to tage input to the head positioning motor (see PLUG be high, which isolates the WRITE signal from the 1. pin 4 in Figure 9.3). Asa result, phase-1 must be read/write head even if WRITE REQUEST' is low. turned off after head positioning or writing to the The WRITE PROTECT signal is also routed from disk is impossible. This is probably a way of forcing the enabled drive to the controller so a 6502 pro- the programmer turn off all phases (not just phase- gram can determine the state of the write protect 1) after head positioning. This seems to imply that switch. keeping a stepper motor input active causes an The Disk Controller 9-9 undesirable effect: perhaps a tiny vibration or over- tures of the MC3470 clean up job include amplifica- heating of the motor. In any case, the RWTS head shaping, filtering, and noise rejection. The tion, positioning routines leave all four phases off after MC3470 detects positive and negative voltage peaks head positioninp:. The boot routine on the controller on the read pick-up signal, then waits about two card, however, leaves phase-0 energized after send- microseconds to verify that a second opposite polar- ing- the head to track 0. ity peak has not occurred. The purpose of this is to prevent narrow noise pulses from generating invalid The Read Pulse read pulses. After the two microsecond mask period, When writing is not enabled, passing a field re- a one microsecond read pulse is output. Even with versal on the surface of the disk over the read/write this sophisticated interface, the controller must be head induces a voltage in the coil. This induced volt- able to reliably monitor a read pulse whose timing age will alternate in polarity for every field rever- interval will vary significantly. In addition, it must sal. The induced voltage is sensed by a special be able to interpret either the presence or the purpose chip which is designed for this function. absence of the read pulse at the distorted interval. The special purpose chip, a Motorola MC3470. out- The two microsecond delay period between peak puts a positive one microsecond pulse for every field detection and read pulse output turned out to be too reversal (see Figure 9,6). This read pulse is routed short for the new format when Apple came out with from the enabled drive to the controller. DOS 3.3. Apple solved this problem by replacing Now we come to the biggest problem with reading fixed resistor R21 with a potentiometer on the a disk. The signal coming off the read/write head is analog card in the disk drive. Technicians align the a dirty little voltage. The shape and size of this read potentiometer for an optimum delay, which works pick-up signal will vary with disk speed, tempera- out to be approximately three microseconds. Old ture, humidity, head alignment, disk warpage, and cards causing unreliable data transfer because of Murphy's Law in the read environment as opposed the two microsecond delay are replaced by Apple as to the same factors in the write environment. The if the card were still under warranty. Your dealer MC3470 has to clean up the imperfect read pick-up will still charge you for labor and alignment in event signal and pass it to the controller. The basic fea- of such replacement. THE WRITE INTERVAL IS FOUR MPU CYCLES WRITE SIGNAL CORRESPONDING READ PICK-UP VOLTAGE READ PULSE FROM MC3470 ngure 9 A When Reading, the Lack of a Read Pul$e at a Regular Interval Represents a ZERO. 9-10 Understanding the Apple I/O SELECT (SC6XX) D3 BOOTSTRAP DATA ROM I BUS (SCOEX) DEVICE SELECT- M 3J. 0E2 0E1 WRITE SHFTRT C3 PROTECT INPUT OA DATA REGISTER "T" DATA HEG. CONTROL I CLOCK 0000 CLEAR 1000 NOP 1001 SHIFT LEFT 1010 SHIFT RIGHT ADDRESS 1011 LOAD BUS 1101 SHIFT LEFT 1 DEVICE SELECT' C0E0-C0E7 HEAD POSITIONING ENABLE COEA/B DRIVE }/Z ENABLE DRIVE 1 COMMAND ENABLE CONTROL DECODER DRIVE 2 1SEC C0E8/9 DRIVE OF=f= DRIVE ON CLR RfVE OFF/ON DELAY . SEQUENCER CLOCK POWEfl SYSTEM UP RESET -L^»- RESET 1SEC Figure 9.7 Block Diagram of the Disk II Confroller, The Disk Controller 9H The combination of the read/write head and the This program has just enough code to get the con- MC3470 responds very well to field reversals on the tents of track 0, sector into RAM. Then program moving disk as long as there is not too much space control is passed to that part of RAM so that the between them. However, if there is too much space bootstrap procedure can be continued. The Boot- between field reversals on the disk, the MC3470 strap ROM is connected to the address bus and data starts putting out false read pulses. This means that bus naturally, and its output enable is the I/O you can't utilize copy protect schemes that call for SELECT' input to the slot. This response to the I/O isolated field reversals on the disk separated by SELECT' input causes the DOS to be booted when large intervals of constant field direction. In other PR#n or lN#n is executed from BASIC* words, the MC3470 will reliably produce read pulses The Autostart power-up RESET routine uses the while data of normal density is moving past the contents of the Bootstrap ROM to detect the pres- read/write head, but reduction of this density will ence of a Disk 1 1 controller in the Apple. It does this cause spurious read pulses to be generated. The by starting with slot 7 and working downward, write interval in the Apple is four MPU cycles, and checking each slot for the presence of $20, $00, $03, we will see that in the DOS formats the maximum and $3C at locations $CnOL $Cn03, $Cn05. and time between field reversals on a disk will be three $Cn07. When itfinds this combination, itstarts exe- write intervals. cuting at $CnOO on that slot, thus booting the DOS. The Command Decoder THE DISK II CONTROLLER * The overseeing 6502 program manages the con- troller via address bus commands in the DEVICE The Disk II controller contains that part of disk SELECT' range of the controller's slot($C080,X I/O electronics which needs to be positioned close to through $C08F.X with slot number times $10 in the the motherboard. This includes a Bootstrap ROM, a X-register). This range is divided up into eight data register, a logic state sequencer, and a com- on/off switches by an LS259on the controller identi- mand decoder. Figure 9.7 shows the functional flow cally to the way the $C06X range on the mother- of the controller, and Figure 9.8 is a full schematic. board is divided up (see the F14 chip in Figure 7.2). In other words, there are eight on/off soft switches The Bootstrap ROM by which a program can manage disk I/O. Like the The Bootstrap ROM is referred to as the P5 ROM motherboard screen mode switches and annuncia- by Apple. It contains a 256 byte program which tors, thedisk switches are set OFF by even addresses begins the bootstrap procedure that reads the DOS and ON by odd addresses. Table 9. 1 is a brief listing from adisk, puts it into RAM, and initializes it. This of the functions of these address decoded commands, 256 byte program is the only 6502 program which but more detailed explanations follow. resides on the controller, and it may be accessed any *See Chapter 7. PERIPHERAL SLOT CONNECTIONS and time at CnXX where n is the controller slot number. THE APPLE I/O SYSTEM: KSW AND CSW. Table 9.1 Disk II Controller Commands. SWITCH OFF FUNCTION ON FUNCTION Q0 $C080,X - PHASE OFF $0081, X ~ PHASE ON Ql 5C082,X - PHASE 1 OFF $0083 rX - PHASE 1 ON Q2 $0084, X - PHASE 2 OFF $C085,X - PHASE 2 ON Q3 $0086, X - PHASE 3 OFF $C087,X - PHASE 3 ON Q4 $C0B8,X - DRIVES OFF $C089,X - SELECTED DRIVE ON Q5 $C08A,X - SELECT DRIVE 1 $C08B,X - SELECT DRIVE 2 Q6 $C08C,X - SHIFT WHILE WRITING/ $C08D,X - LOAD WHILE WRITING/ READ DATA READ WRITE PROTECT Q7 5C08E,X - READ $C08F,X - l-JRITE 1. RESET' forces all switches off 2, Access to even addresses causes the data register contents toibe transferred to the data bus. 9-12 Understanding the Apple II rO!] 5V rill] SELECr ''® L iJa ^ ic6 Ic?- 3 T-VF T.I^F T.ljiF p1)jF -r IfiF HI] GND(26 -*{«) D4 H^D5 »<4|)D7 5V 36 '? t'3 '6 14 "5 15 "4 '16 J20 WBIPftCTECI OEI OE? OH C3 •NC LS323 RW£ Tl EISA C D 0SLI8 DATA ON _ 03 e OA REGISTER MPSU51 iCK SO SI CLR GND 1? 41 "ir-j^9 ID LSOS m. 6 la E2 01 00 03 A1 20 vcc COEC/D SHIR/LOAD 83 MEE/FREAD/WRITE 6309-P6 02 Q3@- mM A? LS132 jiQ (S116 12 LS05 LOGiC STATE SEQUENCER ROM El J5 nS HEAD PULSE 131 fn & CLRVCC MLS171HEXFF 4d5 10 ': K LS132 GND 10 1J.SEC 17 DO A5 12 15 1. oc AO 13 18. oc A6 14 19. QC A7 mm H ^ WRITE SIGNAL REQUEST' -«H2l LS05 DRIVE ON DEVICE/7i^ Hr fiESET(3^ IN@ INT INTOUTta) Q SLOT EDGE CONNECTOR I 1 20 PIN DRII/E CONNECTOR Figure 9.8 Schdmatic: The Disk II Controller (Addres* References Assume Slot 6). The Disk Controller 9-13 The second half of the NE556 timer is used to Drive Off/On and Drive Select generate a .1 second power-up RESET. This is The $C088,X/$C089,X switch disables the drives overridden by the motherboard .3 second power-up or enables a drive, while the $C08A,X/$C08B,X RESET on Revision 1 and later boards, but on Revi- switch selects drive 1 or drive 2 for enabling. Here is boards, the controller generated RESET is sion an illustrative, but otherwise useless program necessary to achieve the autostart capability. sequence: Head Positioning Commands LDX #$60 JSLOT 6 Address bus commands $C080,X through $C087.X CMP $C08B,X jSELECT DRIVE are translated directly into four phase-off/phase-on CMP $C089,X jDRIVE 2 ON stepper motor controls. These control voltages are CMP $C08A,X fDRIVE 2 OFF routed to the drives where they are amplified and ;DRIVE 1 ON applied to the head positioning motor. Ascending CMP $C088,X ; DRIVES OFF references to $C080.X through $C087.X cause the head assembly on the enabled drive to move toward the inner track (track 34). Descending references Turning a drive on ($C089,X) perfornns the follow- cause movement toward track 0. The controlling ing at the controller: program must wait approximately 20 milliseconds 1. Applies +5V power to the sequencer ROM and for motor response after turning a phase on. The the sequencer flip-flops at A3. actual motor response will "vary with momentum, 2. Applies Q3' to the cbckpulse inputs of the data and the RWTS head positioning routine reduces register and the sequencer control flip-flops. positioning time by varying the waiting period with The sequencing and data transfer clock is Q3 expected momentum. falling. (DRIVES OFF forces the control flip- The motor must be stepped two phases per flops to clear.) track, so there are really 70 head positions, RWTS 3. Enables the outputs of the sequencer ROM. writes at the phase-0 aligned and the phase-2 aligned 4. Enables sequencer control of the data register. positions, but copy protected disks may have data (DRIVES OFF forces the data register to hold written on the half-tracks, the phase-1 aligned and its present state.) phase-3 aligned positions. The head assembly has a 5. Causes the ENABLE 1' or the ENABLE 2' sig- mechanical stop— an electrical stop in some alter- nal to go low depending on which drive is nate drives— at track 0. One method to absolutely selected by the drive 1/drive 2 switch. At which- ascertain the head position is to step outward eighty ever drive is enabled, this turns on the drive phases as the bootstrap program does. The head will motor and IN USE indicator, and it enables run against the track stop, and you will be at track head positioning, writing, and control of the 0. The head/stepper motor linkage is aligned so that read pulse and write protect inputs to the the motor will be phase-0 aligned at track 0, so controller. from track it is known that stepping inward must be begun by turning phase-1 on by a reference to The drive off/on signa! is routed through one half $C083,X. From this point, the head position can be of an NE556 timer. The effect of this timer is to stored in RAM, apd the phase alignment can be delay drive turn-off until one second after a refer- determined from the head position. After head posi- ence to $C088.X. This gives the drive apparent tioning, the four phases should all be turned off, momentum, keeping it runningafter it is turned off. because, if phase-1 is left on, the drive will behave as The result is that the drive never turns off between if a write protected disk is installed. closely spaced accesses, and in these instances, Read/Write access time is reduced because there is no delay $C08E.X/$C08F,X the controller's READ/ while the disk comes up to speed. This is why the is computer is ready to process after a "CATALOG" WRITE soft switch. It is an addressing input to the well before the IN USE light goes out on the drive. sequencer and divides the sequencer into its two The one second turn off delay does not apply to turn- most significant parts, the READ sequence and ing off the drive via a RESET. Pressing RESET the WRITE sequence. It also is inverted to become causes the delay timer to clear and turns off the the WRITE REQUEST' signal to the drives. Thus, drive almost immediately. the RE A D/ WRIT E sw itch conf igu res the controller 9-14 Understanding the Apple for reading or writing via sequencer addressing, controller to perform such complex control with so and it configures the enabled drive for writing via few chips. It uses a 256 byte ROM with four of its the WRITE REQUEST' line unless a write pro- data outputs (04-07) connected through flip-flops to tected disk is installed. four of its address inputs (A5. AO. A6. and A7). The flip-flops are clocked by Q3 falling while a drive is SHIR/LOAD enabled.* SHIFT/LOAD is a fairly inadequate label for the There are eight address inputs to the sequencer $C08C,X/$C08D,X soft switch, but any label would ROM. so let's refer to the four flip-flop latched end be. It is chosen because, during writing, $C08C,X around inputs as the sequencing inputs and the causes shifting of the data register on every eighth other four address bits the partitioning inputs. sequencer clock, and $C08D.X causes loading of the Assume for a moment that the four partitioning data register from the data bus on every eighth inputs are fixed. The overall ROM address will then sequencer clock. In reality, the SHIFT/LOAD change every time Q3 falls, and the contents of bits switch performs several functions which defy sum- 04-07 of any addressed location will determine the marization in a short label, address after the next clockpulse. These four data SHIFT/LOAD is an addressing input to the bits thus contain flow information, and they are sequencer and it divides both the READ sequence programmed so the flow will proceed in an orderly and the WRITE sequence into two parts. As men- manner from clock to clock. There are 16 states of tioned above, it is a programmable SHIFT/LOAD the four sequencing address inputs and 16 states of control for the data register. When the RE ADZ- the four partitioning address inputs. The sequencer WRITE switch is low, the SHIFT/LOAD function is ROM is thus divided into 16 partitions of 16 changed to READ/CHECK WRITE PROTECT. sequencer states each. These sequencer control functions are summarized The four partitioning inputs are; in Table 9.2. The operation should become clearer when we study the sequencer listings. Al - QA. the MSB of the data register $C08C,X and $C08D.X are also the normal input A2 - SHIFT/LOAD, the $C0SC,X/$C08D.X and output port addresses used by RWTS for switch transfer of disk data. In reality any even address A3 - READ/WRITE, the $C08E,X/$C08F.X could be used to load data from the data register to switch the MPU, although $C088 (DRIVES OFF) and A4 - The read pulse from the disk drive $C08A (SELECT DRIVE 1) would be inapprop- riate for this purpose. Use of $C08D,X as the output address goes hand in hand with the fact that it The A2 and A3 inputs allow the 6502 programmer causes loading of the data register from the data to configure the sequencer for loading while writ- bus. ing, shifting while writing, reading data from the disk, or checking the write protect switch. The Al and A4 inputs allow the sequencer flow to deviate The Logic State Sequencer and Data Register As mentioned before, the logic state sequencer is *The sequencer clock isactuallytherisinged&eofQ3', developed by gatinsr Q3 through a 74LS132 NAND gate (see Fisrure 9.8). a ROM wired up to behave like a little 2 MHz com- Due to propagation delay, the clock iseffeetivei.vQSfallinsrplus puter. It is this powerful sequencer that enables the approximately 15 nanoseconds. Table 92 Functions of the $C08C^$C08DX and SC08E/SC08F Switch. SHIFT/LOAD READ/WRITE Sequencer Function $C08C,X $C08F,X Data register shift every eighth sequencer clock while writing. 1^080 rX $C08F,X' Data register load every eighth sequencer clock while writing. $C08C,X $C08E,X Enable READ sequencing. $C08D,X $C08E,X Check state of write protect switch and initialize sequencer for writing. The Disk Controller 9-15 state of the data register at any time, a program can dependingon the presence or absence of a read pulse store data to the data register only when the and depending on the state of shifted data in the data register. sequencer is performing a load. As a result, the write operation involves getting the 6502 program The data register is a very versatile 8-bit IC that in syne with the sequencer and keeping it there by can shift left, shift right, load parallel or store paral- performing write operations in exact timing loops. lel based on its control inputs. The renriaining four If the data register is to accept data from the MPU, outputs of the sequencer ROM are connected to the 6502 program must store the data to the data inputs of the data register, vi^hich completes our register at exact multiples of the bit writing picture of the sequencer. Four of the ROM data bits internal. This interval is eight cycles of the are programmed to control sequencing and the sequencer or four cycles of the MPU. other four data bits are programmed to control the It is important to make a distinction here between data register. There are only six distinct commands which the sequencer can cause the data register to what can be done and what normally is done. A perform, but there are 16 possible states of the program can store data at any multiple of the bit command bits. This is because there are redundant writing interval— 8, 12, 16. 20, etc. MPU cycles— and the data register will accept it. The DOS, how- states which command the data register to do the ever, only stores data to the data register at 32, 36, same thing. Table 9.3 shows the 16-bit states in hex- adecimal and binary with an asterisk next to the six and 40 cycle intervals. There are very practical rea- states used by Apple to perform commands in their sons for this which will become apparent as these discussions progress. 3.2 and 3.3 ROMs. In addition to the sequencer control of the data Both the sequencer control flip-flops and the data register are clocked by Q3 falling when a drive is register, any reference to even addresses in the enabled. This means the sequencer operates at DEVICE SELECT' range of the controller slot will approximately 2 MHz, twice the frequency of the cause the contents of the data register to be placed 6502. Additionally, the read pulse from the enabled on the data bus. For this reason, programs should not cause the MPU to write to even addresses or the drive is synchronized to the Q3 falling clock, quant- ized in pulse width toone Q3 period, and inverted in MPU bidirectional driver will compete with the data register for control of the data bus. It is impor- the process to form a negative pulse. It is this syn- chronized, negative read pulse which is applied to tant to note that while a 6502 program can check the Table 9.3 Logic State Sequencer Command. 07-06 -05-04 HEX BINARY MNEMONIC FUNCTION *0 0000 CLR CLEAR DATA REGISTER 1 0001 CLR 2 0010 CLR 3 0011 CLR 4 0100 CLR 5 0101 CLR 6 0110 CLR 7 0111 CLR *8 1000 NOP NO OPERATION *9 1001 sus SHIFT ZERO LEFT INTO DATA REGISTER *A 1010 SR SHIFT WRITE PROTECT SIGNAL RIGHT INTO DATA REGISTER *B 1011 LD LOAD DATA REGISTER FROM DAPA BUS C 1100 NOP *D 1101 SLl SHIFT ONE LEFT INTO DATA REGISTER E 1110 SR F 1111 LD *These are the codes actually used by Apple. » 9-16 Understanding the Apple I A4 of the sequencer ROM, and the read pulse is can then be read by the MPU by addressing $C6XX therefore monitored in the same 500 nanosecond (assumes Slot 6). Of course, your disk drive won't tinne frame as the other addressing inputs to the work with the controller configured this way. but ROM. In a further attempt to stabilize the shaky you can save the data to cassette tape and then read pulse, a Schmidt trigger type NAND gate is transfer it to a disk file when your controller is back used in the read pulse quantizing eircuit{see Figure to normal. 9.8). Use of this type of gate increases noise immun- This data can be listed to a printer using the moni- ity and ensures smooth transitions of the A4 input to tor, but it is not particularly readable in this form. I the sequencer ROM. have written a BASIC program to format the data During both reading and writing, the data regis- into a readable listing. Figures 9.9 through 9.11 ter is shifted left while the most significant bit. QA. contain listings of the Applesoft BASIC formatting is monitored. In writing, the state of QA is moni- program, the DOS 3.2 sequencer, and the DOS 3.3 tored and the WRITE SIGNAL is toggled at the bit sequencer respectively. The program was written in writing interval when QA is set. In reading, ONEs BASIC rather than assembly language so it could be and ZEROs are shifted into the data register more easily understood by readers who choose to depending on the presence or absence of a read pulse study it. Also, readers should find it very easy to at the bit writing interval. When QA becomes set, manipulate the sequencer listing because it is for- the sequencer holds the data register long enough matted as a 16 by 16 BASIC subscripted string for a 6502 program to detect the valid byte with a variable. The program takesa little over a minute to seven MPU cycle polling loop. Then the data regis- run. It will list any sequencer ROM designed to run ter is cleared and the next byte is shifted in from the in the Disk II controller as long as its source file is disk. read from the D3 socket of the controller. The source file needs to be resident on diskette as a binary file Decoding the Contents of the Sequencer named "SEQROM." However, it would be easy to ROM change line 50 of the program so the source file was In the past, the contents of the logic state sequencer obtained elsewhere. Before running the program, ROM have been a mystery in the world of Apple enable your 80 column printer or 80 column video users. The basic reason for this is that no one who card. understood the contents ever bothered to publish The manipulations of the program are based on any information about them. A primary aim of this the following features of controller wiring: chapter is to fill this gap in Apple lij^erature by 1. Address bus A5 is connected to the A7 input to providing formatted listings of the DOS 3.2 and the D3 socket. Address bus A7 is connected to DOS 3.3 sequencer ROM contents and discussing the A5 input to the D3 socket. operational aspects of disk I/O which are deter- 2. Data bus D4 through D7 is connected to outputs mined by the contents. 07 through 04 on the D3 socket in reverse This section shows how to make the contents of the order. sequencer ROM accessible to the MPU and provides 3. A natural significance order of addressing a program which makes formatted listings of those ROM is WHITE- inputs to the sequencer contents. The program will accurately list the con- tents of any ROM designed to operate in the B3 READ PULSE-SHIFT/LOAD-QA-07- 06—05—04. This does not correspond to the socket of the Disk II controller. It is not necessary for way they are connected to A7 through AC on the the reader to go through the exercise of making sequencer ROM. listings of the DOS 3.2 and DOS 3.3 sequences since 4. The read pulse applied to A4 of the sequencer these listings are furnished in Figures9.10and9.n. ROM is a negative pulse. He may, however, find it interesting and educa- tional to make his own listings. These wiring connections were not designed to The MPU cannot normally read the contents of confuse us, although they serve the purpose. They the sequencer ROMbecause the ROM is not con- were designed to minimize wire cross over on the nected to the data bus. You can change this situation mechanical layout. A design engineer can swap the by removing the bootstrap ROM from the D3 socket address and data pin assignments on a ROMuntil he and moving the sequencer ROM from the B3 socket finds his own version of peace of mind, then he com- to the D3 socket. The contents of the sequencer ROM pensates for the scrambled pin assignments when The Disk Controller 9-17 he writes the ROM program.* The sequencer ROM We begin our analysis by making two simplifying formatting program must account for this by read- observations. First, if WRITE is selected at the ing each byte of data, unscrambling address bits to READ/WRITE switch (.$C08F.X), the left four find where that data is in the sequence, and revers- columns(READ PULSE) are identical to the right ing dalabits before storingthem ina 16by 16string four columns (NO READ PULSE). This means that variable matrix from which listings can easily be read data has no effect on the WRITE sequence and it can be ignored for purposes of writing. This is a made. necessity because meaningless read pulses will The result is the listings of Figures 9.10 and 9.11.** The WRITE and READ sequences are normally be present while writing. Second, all separated from each other, and the listing is other- entries of the READ— LOAD sequence states are wise divided into columns of 16 sequencer states. OA. This means that READ— LOAD sets the This is a natural division since 16 different values sequencer state to and idly shifts the state of the can be represented by the four sequencing data bits. write protect switch right into the data register The far left hand column is the sequencer state, and where it can by checked by a6502 program. Thus we the other columns hold the contents of the ROM for have the basis for checking if a disk is write pro- that sequencer state. The left digit of each number tected, namely: is the next sequencer state, and the right digit is the command. Next to each number is a mnemonic LDA $C08D,X ;CHECK WRITE PROTECT for the command digit. ;IF READ. As a quick example of interpreting this listing, LDA SC08E,X ;READ. assume that the sequencer is at the top of the fifth BMI ERROR ;BRANCH TO WRITE PROTECT column of the WRITE sequence in Figure 9.10. This ; ROUTINE IF QA SET. means the sequencer is at State and the partition- ingaddressbitsareWRITE-NO READ PULSE- SHIFT— QA'. The data being driven out of the These are the program steps used by RWTS to check sequencer ROM is 18. The 1 is the next sequencer for write protection before writing a sector. A rou- state which will occur when Q8 falls. The 8 is the tine such as this must be performed every time command which will be executed when Q3 falls, a before writing. It not only checks if a disk is write NOP. A quick scan through the WRITE listing will protected, it also clears QA if the disk is not write show that it contains mostly NOPs and that it nor- protected and sets the sequencer to State 0. This mally flows from one sequencer state to the next. initializes the sequencer for writing, and it is the only way an M PU program can establish the state of The WRITE Sequence the sequencer. The WRITE sequence and WRITE PROTECT In the above program steps, the data register was sequence are the same in the 3.2 and 3.3 controllers, cheeked via a LDA $C08E.X. This sets READ/ so this section pertains to both. Please refer to the 3.3 WRITE to READ, shifts the state of the write pro- listing duringthese discussions, usingthe 3.2 listing tect switch into QA of the data register, and places for comparison. this shifted value on the data bus so the MPU can •Since writinfr this paragraph, 1 have learned that Steve Woz- load it to its accumulator. Now, in reality, any time niak designed the Disk II controller. Workinj? with Randy Wig- you would run this program, the READ/WRITE ginlon. Wozniak completed this complicated and innovative switch will already be set to READ, because we are desiirn in the space of one week (the fina! week of 1977). Steve is preparing to write. If READ/WRITE were set to very proud of the meehanicat layout and at one time redid the layout for the .sole purpose of reducing the number of feed- WRITE and a disk with no write protect were rotat- throug-h hole.s from three to two. I had always assumed that much ing, the logic state sequencer would be merrily of Apple's disk interface technology had been borrowed from stomping the flux out of all the data on the track. Shugart. but I couldn't have been further from the truth. The When you write to the disk, the program waits until format and circuitry represent a notable creative effort by the moment, switches READ/WRITE to the right Apple Kroup. Besides the controller desig-n, Wozniak wrote RWTS. Randy Wigginton wrote the rest of theoriginal DOS. and WRITE, then stores a few hundred bytes of data to Rod Holt designed the analog board of the disk drive. the data register in precision loops, then switches •The formatted listings presented here are my own representa- back to READ. So, since the READ/WRITE switch tions which resulted from lengthy investigation. The mnemonics, was already in the READ above, the "LDA address labels, and layout won't, therefore, be the same as those $C08D,X" is not intended to switch READ/WRITE used by Apple Computer engineers. Who knows what they use? I to READ. It is intended solely to load the contents of submit, though, that my representation provides adequate illus- the data register from the only appropriate even tration in the absence of any labels and formats published by Apple. controller address $C08E,X. 9-18 Understanding the Apple 10 REM 12 REM LIST LOGIC STATE SEQUEfJCER ROM 13 REM 14 REM BY JIM SATHER 15 REM 2/22/83 16 REM 30 REM THIS PROGRAM FX)RMATS AND LISTS THE PROGRAM CONTAINED IN THE 32 REM DISK 11 LOGIC STATE SEQUENCER. BEFORE RUNNING THIS PROGRAM, 33 REM YOU MUST CREATE A BINARY SOURCE FILE ON A DISK AND 34 REM NAME IT "SBQROM". THE SOURCE FILE IS CREATED BY PLACING 36 REM THE B3 ROM IN THE D3 SLOT OF THE DISK CONTROLLER. THE 38 REM SOURCE FILE IS WRITTEN TO CASSETTE FROM $C600-$C6FF. WHEN THE 40 REM CONTROLLER IS RESTORED, THE CASSETTE FILE IS TRANSFERRED TO DISK. 42 REM 50 PRINT CHRS (4) ?"BLOAD SEQROM,A7936" 100 DIM LST(15,15): DIM ASWAP(7): DIM DFIX(I5): DIM HRX$(15): DIM aiND$Cl5) 110 FOR X = TO 7: READ ASmP(X) : NEXT L20 FOR X = TO 15: READ DFIX(X): NEXT "'" 130 FOR X = TO 15: READ HEX$ (X) : NFXT 140 FOR X = TO 15: READ C>IND${X): NEXT 150 GR COLOR= 6: REM SOMETHING TO WATCH WHILE WAITING : 200 REM 201 REM FORMAT DATA INTO 16 X 16 MATRIX 202 REM 210 FOR COL = TO 15: FOR ROW = TO 15:WRK = ROW + 16 * COL 300 REM 301 REM GET BINARY FORM OF WRK 302 REM 305 FOR X = TO 7:A(X) = 310 WRK% = WRK / 2:WRK = WRK / 2: IF (WRK - WRK%) THEN A(X) = 1 320 WRK = WRK%: NEXT X 400 REM 401 REM RECONSTRUCT DECIMAL WRK WITH ADDRESS BITS SWAPPED: 402 REM A7-A6-A5-A4-A3-A2-Al-Ag -— > A0-A2-A3-A6-A7-A5-A4-A1 403 RP^ THE DATA WILL THEN BE ADDRESSED BY THE WORD: 404 REM WRITE-RE;AD PULSE-SHirr/L0AD-QA-07-06-O5-O4. 405 REM 408 P0WER0F2 = 1 410 FOR X = TO 7: IF A{ASWAP(X)) THEN WRK% = lfmK% + P0WER0F2 420 P0WER0F2 = P0WER0F2 * 2: NEXT 500 REM 502 REM SWAP BITS D7-D4 OF DATA BEFORE SAVING, BECAUSE THESE 503 REM BITS ARE SWAPPED ON THE 03 ROM. 504 REM 507 OTA = PEEK CWRK% + 7936) :HI = INT (DTA / 16) 510 LST(COL,ROW) = 16 * (DFIX(HI) + DTA / 16 - HI) 520 PLOT ROW, COL: NEXT ROW: NEXT COL: TEXT 600 REM 601 REM 602 REM ADDRESS SWAP TABLE 610 DATA 1,4,5,7,6,3,2,0 620 REM 630 REM DATA SWAP TABLE 640 DATA 0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15 650 REM 660 REM DECIMAL TO HEX CONVERSION TABLE 670 DATA 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F 630 REM 690 REM SEQUENCER COMMAND TABLE 695 DATA -CLR , -CLR , -CLR , -CLR , -CLR , -CLR , -CLR , -CLR 700 DATA -NOP,-SL0,-SR ,-LD ,-NOP,-SH,-SR ,-LO Hguie 9.9 BASIC LIsMng: Program to List State Sequencer ROM. (1 of 2) The Disk Controller 9-49 REM 801 REM 802 REM AT THIS POINT IN THE PROGRAM, THE SEQUENCER LISTING COLUMNS 810 REN RESIDES IN 16 COLUMNS OF 16 SEQUENCES. THESE EACH COLUMN CONTAINS THE COMPLETE SEQUENCE 82(3 REM ARE ARRANGED SO 830 REN FOR A STATE OF THE ADDRESS WORD: 840 REM WRITE-READ PULSE-SHI rr/LOAD-QA. REM 9(J1 REM ********* LIST WRITE SEQUENCE 902 REM REM PRINT WRITE HEADING. 910 QOSUB 2000: GOSUB 2100: GOSUB 2200: GOSUB 2300: 920 FOR ROW = TO 15: PRINT HEXS(RC«); 930 FOR COL = 8 TO 15 HI%) * 16 940 HI% = LST{C0L,ROW) / 16:L0% = (LST(C0L,ROW) / 16 I 950 PRINT " ";HEX$(HI%);HEX$(L0%);CNND$(LO%>; 960 NEXT COL: PRINT : NEXT ROW 999 GET B$: PRINT PRIOT : 1000 REM 1001 pgf^ ********* LIST READ SEQUENCE 1002 REM WHEN THE 1010 REM THE READ PROGRAM IS EASIER TO UNDERSTAND SEPARATE FRCW THE SHIFT PORTICM WC 1020 REM LOAD PORTION IS REM WHEN QR' (QA [X)W) IS SEPERATED FROM QA. THEREFORE 1024 RFJkD LISTIt«^. 1030 REM THE COLUMN ORDER IS Cl-IANGED IN THE 1040 REM 1045 REM COLUMN ORDER DATA FOR READ LISTING 1050 DATA 0,4,1,5,2,6,3,7 1055 IF FLAG THEN 1079 1060 FOR X = TO 7: READ CSWAP(X) : NEXT :FLAG = 1 1070 REM 2700: REM PRINT RFJffi HEADING. 1080 GOSUB 2400: GOSUB 2500: GOSUB 2600: GOSUB "-"; ; 1090 FOR ROW = TO 15: PRINT HEXS (ROW) 1100 FOR COL = TO 7 ,, / c urai * 16 = (LST (CEWAP (COL) ,ROW) / 16 - HI%) , 1110 HI% = LST(CSWAP(C0L),ROW) / 16iL0% 1120 PRINT " "•HEX$(HI%);HEX$(LO%);CMND$(LO%); 1130 NEXT COL: PRINT : NEXT ROW: PRINT 1160 GET B$: PRINT PRINT : 1170 PRINT "CODE MNEMONIC RINCTION" 1180 PRINT CLR CLEAR DATA REGISTER" 1190 PRINT 3 NOP NO WERATION" 1200 PRIWr 9 SL0 SHIFT ZERO LEFT INTO DATA RiSGISTER" 1210 PRINT A SR SHIFT WRITE PROTECT SIGNAL RIGHT INTO DATA REGISTER 1220 PRINT B LD LOAD DATA REGISTER FROM DATA BUS" 1230 PRINT D SLl SHIFT ONE LEFT INTO DATA REGISTER" 1240 END 1990 REM 1992 REM PRINT SPC( 37),-"WRITE": PRINT RETURN 2000 PRINT *_. READ PULSE *.. -NO READ PULSE- 2100 PRINT 2110 RETURN * *" * -LOAD- .* -SHIFT LOAD- 2200 PRINT SHIFT- 2210 RETURN -QA- *•• 2300 —^ ^ PRINT "SEQ *--QA'— * -QR---*— QA --*— QA- _^*^_ QA'- ._* QA *__ QA' . * 2310 PRIOT : REH^RN 2400 PRINT SPCt 37); "READ ; PRINT RETURN : * --SHIFT- -LOAD- 2500 PRINT " 2510 RETURN *" * -QA- -QA*- -QA- 2600 PRINT " -QA'. 2610 RETTURN 2700 PRINT "SEQ *— RP- *-N0 RP— *-— RP— -*-N0 RP— *— RP— -*-N0 RP--* RP— *-N0 RP- *" 2710 PRIOT : RETURN Hgure 9 .9 BASIC Li«Hng: Program to Lift Stcrte Sequence ROM (2 o« 2) . 9-20 Understanding the Apple WRITE * , READ PULSE * fjO READ PULvSE * * SHIFT * LOAD * SHIFT * LOAD * SEQ * --QA '--*-- -QA---*--QA '---*----QA- -nA---*-- 0- 18-NOP 18-NOP 18-NOP 18-NOP la-NOP 18-NOP 18-NOP 18-NOP 1- 28-NOP 28-NOP 28-HOP 28-NOP 28-NOP 28-NOP 28-NOP 28-NOP l- 39-SL0 39-SL0 3B-LD 3B-LD 39-SL0 39-SL0 3B-LD 3B-LD i- 48-NOP 48-NOP 48-NOP 48-NOP 48-NOP 48-NOP 48-NOP 48-NOP 4- 58-NOP 58-NOP 58-NOP 5a-N0P 58-NOP 58-NOP 58-NOP 58-NOP b- 68-NOP 68-NOP 68-NOP 68-NOP 68-NOP 68-NOP 68-NOP 68-NOP 6- 78-NOP 78-NOP 78-NOP 78-NOP 78-MOP 78-NOP 78-NOP 73-NOP /- 08-NOP 33-NOP 08-NOP 3B-N0P 0B-NOP 88-NOP 08-NOP 88-NOP B- 98 -NOP 98-NOP 98-NOP 98-NOP 98-NOP 98-NOP 98-NOP 98-NOP y- A8-N0P A3-N0P A8-M0P A8-N0P A8-N0P A8-N0P A8-N0P A8-N0P A- B9-SL0 D9-SL0 BB-LD BB-LD B9-SL0 B9-SL0 BB-LD BB-LD B- C8-N0P C8-N0P C8-N0P C8-N0P C8-N0P C8-N0P C8-N0P C8-N0P C- D8-N0P D8-N0P D8-N0P D8-N0P D8-N0P D8-N0P D3-N0P D8-N0P D- E8-N0P E3-N0P E8-N0P E8-N0P E8-N0P E8-N0P E8-NOP E8-N0P t:- F8-M0P F3-N0P F8-N0P F8-N0P F8-N0P F8-N0P Fa-NOP F8-N0P F- 8B-M0P 08-NOP 88-NOP 08-NOP 88-NOP 08-NOP 8a-N0P 08-NOP READ - SHIFT „..*._. ----LOAD- * * QA' --•>' *-- ---* QA QA' ---QA- -* SEQ * -RP *_tJO RP--* RP *-N0 Rp--*-- RP- -*-N0 RP--* RP---*-N0 RP-* 0- D8-N0P 18-NOP 18-NOP 08-NOP 0A-SR 0A-SR 0A-SR 0A-SR 1- D8-N0P 28-NOP 23-NOP 28-NOP 0A-SR 0A-SR 0A-SR 0A-SR 2- D8-N0P 38-NOP 38-NOP 38-NOP 0A-SR 0A-SR 0A-SR 0A-SR 3- D8-N0P 48-NOP D8-N0P 48-NOP 0A-SR 0A-SR 0A-SR 0A-ER 4- D8-N0P 58-NOP D8-N0P 58-NOP 0A-SR 0A-SR 0A-SR 0A-SR 5- D8-N0P 68-NOP D8-N0P 68-NOP 0A-SR 0A-SR 0A-SR 0A-SR 6- D8-N0P 78-NOP D8-N0P 78-NOP 0A-SR 0A-SR 0A-SR 0A-SR 7- D8-N0P 88-NOP D3-N0P 88-NOP 0A-SR 0A-SR 0A-SR 0A-SR 8- D8-N0P 98-NOP D8-N0P 98-NOP 0A-SR 0ft-SR 0A-SR 0A-SR 9- D8-N0P 09-$L0 D8-N0P A8-N0P 0A-SR 0A-SR 0A-SR 0A-SR A- CD-SLl BD-SLl D8-N0P B8-N0P 0A-SR 0A-SR 0A-SR 0A-SR B- D9-SL0 39-SL0 D8-N0P C8-N0P 0A-SR 0A-SR 0A-SR 0A-SR C- D9-SL0 D9-SL0 D3-N0P A0-CLR 0A-SR 0A-SR 0A-SR 0A-SR D- ID-SLI 0D-SL1 E8-N0P E8-N0P 0A-SR 0A-SR 0A-SR 0A-SR E- FD-SLl FD-SLl F8-N0P F8-N0P 0A-SR 0A-SR 0A-SR 0A-SR F- DD-SLl 4D-SL1 E0-CLR E0-CLR 0A-SR 0A-SR 0A-SR 0A-SR CODE MNEMONIC FUNCTION CLR CLEAR DATA REGISTER 8 NOP NO OPERATION 9 SL0 SHIFT ZERO LEFT INTO DATA REGISTER ft SR SHIFT WRITE PROTECT SIGNAL RIGHT INTO DATA REGISTER B LD LOAD DATA REGISTER FROM DATA BUS SLl SHIFT ONE LEFT INTO DATA REGISTER Rgure 9.10 The DOS 3^ Logic State Sequencer. The Disk Controller 9-21 WRITE f * * READ PULSE --* NO READ PULSE — LOAD — *--QA'— — QA--* * * SEQ *--QA'— *-— QA- — *--QA'— — QA— *— QA'— — -QA- * SHIFT * LOAD * SHIFT * * * 0- 18-NOP 18-NOP 18-NOP 18-NOP 18-NOP 18-NOP 18 -NOP 18-NOP 1- 28-NOP 23-NOP 23-NOP 28-NOP 28-NOP 28-NOP 28-NOP 28-NOP 2- 39-SLfe) 39-SL0 3B-LD 3B-LD 39-SL0 39-SL0 3B-LD 3B-LD 3- 48-NOP 48-NOP 48-NOP 48-NOP 48-NOP 48-NOP 48-NOP 48-NOP 4- 58-WOP 58-NOP 58-NOP 58-NOP 58-NOP 58-NOP 58-NOP 58-NOP 5- 68-NOP 68-NOP 68-NOP 68-NOP 68-NOP 68-NOP 68-NOP 68-NOP 6- 78-NOP 78-NOP 78-NOP 78-NOP 7a-N0P 7S-NdP 78-NOP 78-NOP 7- HB-HOP 88-NOP 08-NOP 88-NOP 08-NOP S8-N0P 08-NOP 88-NOP a- 98-NOP 98-NOP 98-NOP 98-NOP 9 8-NOP 58-NOP 98-NOP 98-NOP 9- A8-N0P A 8- NOP A8-N0P A8-N0P A8-N0P A8-N0P A8-N0P A8-N0P A- B9-SL0 B9-SL0 BB-LD BB-LD B9-SL0 B9-SL0 BB-LD BB-LD B- C8-N0P C8-N0P C8-N0P C8-N0P C8-N0P C8-N0P C8-N0P C8-N0P C- D8-N0P D8-N0P DB-NOP D8-N0P D8-N0P D8-N0P D8-N0P D8-N0P D- E8-N0P E8-N0P E8-N0P E8-N0P E8-N0P E8-N0P E8-N0P E8-N0P E- F8-N0P F8-N0P F8-N0P F8-N0P F8-N0P F8-N0P F8-N0P F8-N0P F- 88-NOP 08-NOP 88-NOP 08-NOP 88-NOP 0a-NOP 88-NOP 08-NOP READ * LOAD -* * SHIFT * QA' * QA * —^-QA' * QA- — * SEQ * — RP ^*-N0 RP--* RP *-N0 RP--* RP *-N0 RP--* RP *-W0 RP-* 0- 18-NOP 18-NOP 18-NOP 18-NOP 0A-SR 0A-SP 0A-SR 0A-SR 1- 2D-SL1 2D-SLI 38-NOP 38-NOP 0A-SR 0A-SR 0A-SR 0A-SR 2- D8-tJ0P 38-NOP 8-NOP 28-NOP 0A-SR 0A-SR 0A-SR 0A-SR 3- D3-N0P 48-NOP 48-NOP 48-NOP 0A-SR 0A-SR 0A-SR 0A-SR 4- D8-N0P 58-NOP D8-N0P 58-NOP 0A-SR 0A-SR 0A-SR 0A-SR 5- D8-N0P 68-NOP D8-N0P 68-NOP 0A-SR 0A-SR 0A-SR 0A-SR 6- DB-NOP 78-NOP D8-N0P 78-NOP 0A-SR 0A-SR 0A-SR 0A-SR 7- D8-N0P 88-NOP D8-N0P B8-N0P 0A-SR 0A-SR 0A-SR 0A-SR 8- D8-N0P 98-NOP D8-N0P 98-NOP 0A-SR 0A-SR 0A-SR 0A-SR 9- D8-N0P 29-SLb' D8-N0P A8-N0P 0A-SR 0A-SR 0A-SR 0A-SR A- CD-SLl BD-SLl D8-N0P B8-N0P 0A-SR 0A-SR 0A-SR 0A-SR B- D9-SL0 59-SL0 D8-N0P C8-N0P 0A-SR 0A-SR 0A-SR 0A-SR C- D9-SL0 D9-SL0 D8-N0P A0-CLR 0A-SR 0A-SR 0A-SR 0A-SR D- D8-N0P 08-NOP E8-N0P E8-N0P 0A-SR 0A-SR 0A-SR 0A-SR E- FD-SLl FD-SLl F8-N0P FB-NOP 0A-SR 0A-SR 0A-SR 0A-SR F- DD-SLl 4D-SL1 E0-CLR E0-CLR 0A-SR 0A-SR 0A-SR 0A-SR CODE MNEMONIC FUNCTION CLR CLEAR DATA REGISTER 8 NOP NO OPERATION 9 SL0 SHIFT ZERO LEFT INTO DATA REGISTER A SR SHIFT WRITE PROTECT SIGNAL RIGHT INTO DATA REGISTER B LD LOAD DATA REGISTER FROM DATA BUS D SLl SHIFT ONE LEFT INTO DATA REGISTER Hgure 9.i 1 The DOS 3 J Logic State Sequencer. 9-22 Understanding the Apple If for some reason, the RWTS write protect check Now look at the WRITE sequence in Figure 9,11 was entered with the READ/WRITE switch in (finally). We are at the top of column seven where a WRITE, the write protect switch would still be read 18-NOP is found. At the next sequencer clock correctly. This is some pretty fast addressing, shift- nothing is done to the data register, but the sequencer ing, storing-, and loading, the timing for which is moves up to State 1. State 1 contains a 28-NOP, i llustrated n Figure 9. 12. This figure shows the last i which causes sequencing to State 2 at the next clock. PHASE period of an MPU access to the READ/ State 2 contains a 3B-LD. which causes sequencing \y RITE or SHIFT/LOAD switch. The whole opera- to State 3 at the next clock as well as the loading of tion depends on the very brief access time (70 the data register from the data bus. nanoseconds) of the 6309 PROM that Apple uses for Now look again at Figure 9.13, The sequencer the sequencer ROM. This enables DEVICE clock edge in State 2 occurs while the MPU is plac- SELECT' to fall, the accessed switch to change ing valid data from the "STA $CQ8F.X" instruction states, and data out of the sequencer ROM to become on the data bus. and it therefore has succeeded in valid in plenty of time for the data register to be storing data to the data register. Note that a "STA newly configured when the controller clock rises. $COEF" (assumes Slot 6) would not have worked The controller clock is Q3 falling or. more accu- here because MPU data would have been on the data rately. Q3 inverted rising with a typical propaga- bus at State instead of State 2. Clearly. Apple tion delay of 15 nanoseconds experienced in the designed the WRITE sequence to support the inversion. The data register then responds to its features of the 6502 "STA ABSOLUTE.X" in- clock well before PHASEf al Is. allowi ng the MPU struction with no page crossing^. to load the new state of the data register. All this Now look back at Figure 9.11. Assume that when means that the following general rule applies: when the MPU stored data in the data register, it set QA. the MPU reads the data register, the sequencer In fact, if the data was written by RWTS, it's a sure responds to any new configuration, performs a thing— Q A is set. We will see that all data that resulting operation on the data register, and then RWTS stores to the disk has its MSB set. This means gates the contentsof the data register to the data bus that instead ofsequencingto State 3 in column 7, the for reading by the MPU. sequencer goes to State 3 of column 8. Ft makes no Now assume a 6502 program has checked the difference here, but it will when we reach State 7. write protect switch and found it can now write to Until that point is reached nothing happens. At the disk. The program can then write a byte of data State 7, if QA is set. sequencing up the states con- to the disk with these st«ps: tinues, but if Q A is reset, the sequencer loops back to State 0. Right now. QA is set, so the next state is LDA DATAl State 8. STA $C08F,X ;WRITE CMP When State 8 is entered from State 7. the WRITE $C08C,X ;SHIFT signal switches from low to high. Why? Because the Figure 9.1,3 shows the timing of what happens here. WRITE signal is connected to the A7 input of the The "STA $C08F,X" without indexing across a page sequencer ROM. The sequencing address bits are boundary actually puts $C08F,X on the address bus A7— A6—AO— A5, so A? is low in states 0-7 and high for the last two MPUcycles of this four cycle in states 8-F (see Figure 9.8). Now think about the instruction. The first $C08F,X cycle is a read access decision that was made at State 7 in this light. If QA and the second is a write access with the MPU con- was reset, the WRITE signal was left alone. If trolling the data bus during the greater part of QA was set, the WRITE signal was toggled. PHASE 0. The first $C08F,X cycle causes READ/ Continuing on in column 8. State A is reached WRITE to switch to WRITE about 90 nanoseconds before the next event. Remember that "STA after PHASE rises. Within 70 nanoseconds of this $C08F.X" was followed by "CMP $C08C.X." Just as event, the sequencer ROM's data outputs have we arrive at State A, this second instruction switches responded to the new address input. The sequencer SHIFT/LOAD to SHIFT, causing us to arrive at state is still 0. That won't change until the sequenc- State A in column 6 instead of 8. This is just in time ing flip-flops sense a clock edge. The sequencer is to cause shifting instead of loading at State A, therefore waiting for a clock edge, sitting at State because there is a SLO in column 6 compared to the 0-WRITE-LOAD-QA'. There may or may not LD in column 8. The "CMP $C08C,X" is barely short be a read pulse, but we don't care. Assume there is enough to meet the timing requirements for switch- no read pulse. ing SHIFT/LOAD to SHIFT. The Disk Controller 9-23 6502 PHASE J v_ DEVICE SELECT' I r I READ/WRITE OR SHIFT/LOAD SWITCH 70 nsec max SEQUENCER ROM DATA OUTPUT 70 nsec max CONTROLLER CLOCK (A2-3) \ L SEQUENCER CONTROL FLIP-FLOPS 1 Swltehei Rgure 9.1 2 Timing Example: Sequsfvcer Control While Changing ttie READ/WRITE or SHIFT/LOAD 6502 PHASE \_ J SC08F.X VAUD ON ADDRESS BUS READ /WRITE (SCOBE,X/SC08F,X) / „, ..,.,, Clock data bus J 6502 WRITE DATA - \ vai in ON DATA BUS to data register CONTROLLER \ 1 \ j I I \ CLOCK {A2-3) 1 1 1 ' 1 ' ^ SEQUENCER STATE Rguie 9.1 3 Timing Example: Switching to Write After Checking Write Protect. 9-24 Understanding the Apple II The SLO causes the next bit to be shifted into QA, CMP $C08C,X ;SHIFT (4CP) while QH, the LSB of the data regrister, is filled with PHA ; C3CP) a ZERO. SLO is functionally similar to the 6502 PLA ;{4cp) instruction, ASL. From this point, we sequence up PHA ;(3CP) to State F in column 5 or 6 depending on whether PLA ; {4CP) QA was set or reset by the SLO. From State F. the BIT $0 ; (3CP) sequencer will loop back to State if QA is set, NOP ; (2CP) toggling the WRITE signal, or it will loop back to LDA DATA2 ; (4CP) State 8, leaving the WRITE signal high, if QA is STA $C08D,X ;LOAD {5CP) reset ; TOTAL = 32CP Now let's step back and look at what's happening. CMP $C08C,X ; SHIFT Writing to the disk is a load and shift process, a The above example illustrates the principle of little like HIRES pattern outputs but much slower. writing continuous bytes of data: initiate the WRITE Also, the MPU takes a very active role in the loading sequence, then store data every 32 cycles. This will and shifting of disk write data. There are two 8-state normally be accomplished in 32 cycle loops. After loops in the WRITE sequence. After initializing the storing the last byte to be written, wait 32 cycles, WRITE sequence, data is stored in the data register switching READ/WRITE to READ on the 32nd at a critical point in the A7' loop. As quickly there- cycle. You don't have to write in 32 cycle loops. You after as a 6502 can do it, the sequencer is configured can store 6-bttdata words in 24 cycle loops if you can to shift left at the critical point instead of loading. figure out some purpose for it. You can store data in Then the MPU goes about its business while the any multiple of 4 cycles and the data register will sequencer continues looping, shifting the data regis- accept it. RWTS writes read syncing leaders by ter. If the sequencer senses QA high, flow vectors 'storing $FF to the data register in 36 cycle loops in to the opposite loop, toggling the WRITE signal. DOS 3.2 and 40 cycle loops in DOS 3.3,* This creates Figure 9.14 is a flowchart of the WRITE sequence, aseriesof llllllUOor UUUllOO strings which, which may help you interpret the listing. The flow- we will see, syncs up the sequencer for reading fol- chart is reminiscent of the schematic of a flip-flop. lowing data. This is notsurprising because the WRITE sequence has functional similarities to a toggling flip-flop. Disk Data Formats So, the sequencer outputs eight bits of data. What then? Well, if the program controlling the MPU did There is an inherent problem with stor ng data oni nothing more, after the eighth bit was shifted out floppy disks. As their name suggests, floppies are the data register would be all zeros, and no more less than rigid. This and other factors contribute to field reversals would be written on the disk. This the following fact of life: just because some Apple constant field condition cannot be read by the drives wrote data to a disk at a four cycle bit interval but results in sporadic read pulses. In other words, doesn't mean that read pulses are going to come the MPU needs to stay involved. Normally, the back from the disk at the same interval. In the first MPU program will wait until the last bit has been place, the Apple has a built-in clockpulse jitter with shifted to the disk, then switch SHIFT/LOAD to every 65th MPU cycle longer than the rest. This LOAD with a STA instruction at the precise moment elongates some write intervals by 140 nanoseconds, that the data register will accept it. This moment and it doesn't help. But normal problems with the occurs once every sequencer write loop, once every floppy medium and drive inconsistencies are more eight sequencer clocks, or once every four MPU significant in causing read pulse variations. cycles. It takes 32 MPU cycles tooutput eight bits of Realizingthat the read pulse varies a lot, consider information, so to continuously shift out informa- how this variation affects trying to detect the tion in 8-bit groups, the MPU must store data at absenceof apulse. In reading the absence of a pulse, $C08D,X every 32 cycles, then immediately the READ sequence must wait a certain amount of enable shifting with a read access to $C08C,X. time past the last actual pulse, then decide "there This e-vample writes two bytes to the disk: was definitely no pulse there; that sure was a LDA $C08D,X ;LOAD ZERO." In the absence of a clockpulse coming off the disk, the previous read pulse, or ONE. becomes LDA $C08E,X ;READ the time reference for the absence of a read pulse, or BMI ERROR ;WRITE PROTECT a ZERO. ;ERROR LDA DATAL •In some literature, the read syncing- leaders are referred to as STA $C08F,X ; WRITE DATAl series ofautosync bytes or se!f-9ync bytes. The Disk Controller 9-25 ( START ) READ COBC.X LOAD COSD.X SHIFT -writf X, "EAD RIGHT CHECK W PROTECT WRITE NOP NOP 1 NOP NOP LOAD (C0BO.X) SHIFT/\ L0AD{C08D.X) LOAD 1 SHIFT 1C08C XI SHIFT (COeC X) LOAD DATA LOAD DATA SHIFT LEFT, REGISTER SHIFT LEFT. REGISTER FROM FROM ZERO FILL ZERO FILL DATA BUS DATA BUS ¥ NOP B NOP 4 NOP NOP NOP NOP 6 NOP NOP RESET QA SET SET GA RESET * ^ - -Y" — y\^ ~y _y WRITE SIGNAL LOW WRITE SIGNAL HIGH Rgure9.14 Rowchart of the Wrfte Sequence. 9-26 Underetanding the Apple What if you have twoZEROs in a row? Well the are MSB set and no two adjacent bits reset. All last ONE bit is the time reference for the second and sector datawas written using the following 32 all succeed ingZEROs in a string. Suppose the read- values; ing drive rotates at 280 RPM but the disk was writ- ten using a drive that rotated at 320 RPM. You WRITE TABLE FROM DOS 3,2.1 cannot read a long string of ZEROs under these conditions, because while the write interval was BC9A - AB AD AE AF B5 B6 eight controller cycles, the read interval could be ten BCA0 - B7 BA BB BD BE BF D6 D7 cycles. Furthermore, in the absence of field rever- BCA8 - DA DB DD DE DF EA EB ED sals on the disk for too long, the read interface chip BCB0 - EE EF F5 F6 F7 FA FB FD in the drive begins to generate invalid read pulses. BCB8 - FE FF You simply cannot read a long string of ZEROs, because your time reference is unstable and your The values D5 and A A are also valid, and they are used as the first two identifying values which pre- read interface can't do it anyway. cede every address field and data field. A 5-bit word How may ZEROs in a row can be read reliably? can contain .32 values, so the 3.2 writing process Two. In DOS 3.3, RWTS never writes more than involves taking a 256-byte data block and translat- twoZEROs in a row, and RWTS 3.2 never writes ing it into 410 5-bit words. The 410 5-bit words do more than one ZERO in a row. Of course, normal not directly index the write table to find the byte to data bytes very often have more than two adjacent be written. Rather, the first word written directly zero bits. These normal data bytes cannot be stored indexes the write table. The second index is an directly to the disk but must be translated to disk excIusive-OR between the first and second words. compatible 8-bit words. It takes more than one LOAD-SHIFT cycle to output a data byte, because Each following index is an exclusive-OR between the current and previous word. At the end, a 411th 256 possible numbers can be represented in a nor- word is written. The last word of the coded buffer mal byte, but not nearly as many can be represented directly indexes the write table for this word. When if you place restrictions on the number of adjacent this process is reversed in the read operation, each ZEROs. byte has to be correctly read for the fo lowing bytes There is a second restriction on data which the I to be read correctly. The 4 11 th word read serves as a Apple stores to the disk. The MSB is always set. The MSB is used by both the READ sequencer and check sum and must be equal to the 410th decoded 6502 programs to define when a byte of read data is word or the read will be deemed unsuccessful and revert to a try again loop. This check sum procedure in the data register. The MSB is therefore not data is an effective method of verifying the validity of but the BYTE FLAG.* It serves as a data gap which disk data transfer. allows the READ sequencer to hold the previous byte in the data register for a long enough time that Apple increased their disk data density in the a 6502 program can detect the presence of a com- DOS 3.3 upgrade by easing the restriction on adja- cent ZEROs. The 3.2 controller can read this data, plete byte in a seven cycle polling loop: but it's a struggle and the possibility of reading errors is great. Apple improved the read reliability POLLIT LDA SC08C,X by changing the sequencer ROM. They also made BPL POLLIT the questionable move of changing the Bootstrap ROM and bootstrap procedure, the most notable result of which is that a 3.3 controller will not boota The Apple Disk II was first released with DOS 3 3.2 disk. This incompatibility is due solely to pro- and the associated controller. Then the DOS was gram based conventions. The 3.3 controller is fully upgraded to 3.1, then 3.2, then 3.2.1 with no change capable of reading anything written on 3.2 disks. in written data format. This format will be referred The DOS 3.3 restrictions on written data are MSB to here as the 3.2 format. The 3.2 data restrictions set, no more than one pair of adjacent ZEROs, and at least one pair of adjacent ONEs in bits 6 through 0. Steve Wozfiiak devised the Apple II disk formats. In a speech given in Anaheim, California, on April 17. 1983, he said that his D5 and AA are still used only as field identifiers, idea for nagging groups of data by having every eighth bit set and they don't meet the pair of adjacent ONEs came direclly from, the "stop bit" used in RS232 data requirements. This is notable because it helps dis- transmission. tinguish D5 and AA from the other valid written The Disk Controller 9-27 words. The restriction requiring a pair of adjacent always be in sync* RWTS 3.2 syncing leaders are ONEs rules out 95, A5, A9. and CA. Besides D5 and series of FF36s. RWTS 3.2 uses more than seven, AA, the DOS 3.3 written values are: which works fine, but only seven are necessary. RWTS 3.3 uses FFs written in 40 cycle loops as read WRITE TABLE FROM DOS 3.3 syncing leaders. A string of four FF40s followed by valid data will ensure that following data will be in BA29 - 96 97 9A 9B 9D 9E 9F sync. The use of FF40s allows RWTS 3.3 to sync in a BA3E( - A6 A7 AB AC AD AE AF B2 shorter period of time, slightly increasing the space BA38 - B3 B4 B5 B6 B7 B9 BA BE available for data. BA40 - BC BD BE BF CB CD CE CF There are two different times that RWTS writes BA48 - D3 D6 D7 D9 DA DB DC DD to a disk. One time is when it formats the disk, BA50 - DE DF E5 E6 E7 E9 EA EB writing sector information for 16 (3.3) or 13 (3.2) BA58 - EC ED EE EF F2 F3 F4 F5 sectors on 35 tracks. The other time is when the data BA50 - F6 F7 F9 FA FB FC FD FE field for a sector on a track is written. This consists BA68 - FF of positioning the head, then reading until the speci- fied sector address field is found. After the desired There are 64 values in the write table, so you can address field has passed by, the data field is written guess that six bits are written per LOAD-SHIFT from a 342 byte (410 if DOS 3.2) buffer. cycle, and a 256-byte block is written in 342 LOAD- The 3.2 and 3.3 sector formats are shown in Fig- SHIFT cycles. With the size of the data field in a ure 9.15. Other than the three extra sectors, there sector thus reduced, Apple was able to increase the are several basic differences. The address field number of sectors per track from 13 to 16. identifiers are different, D5 A A B5 in 3.2 and D5 The whole gist of this discussion about data for- AA 96 in 3,3, causing bootstrap incompatibility. The mats is that you can write any sort of bit stream you read syncing leaders are different as was men- desire, but you must write something that can be tioned. DOS 3.2 overwrites each track with 9984 read by the logic state sequencer. The sequencer FF36s before writing the sectors, but DOS 3.3 was designed to read a certain data format, and it's doesn't. DOS 3.2 reserves space for data by writing all it can do to read this floppy data reliably. Copy 431 FF32S after each address field while format- protect artists must study the READ sequence very ting. DOS 3.3 reserves space by actually writing a thoroughly to discover ways to write bit streams data field, with unwritten gaps of about 50 MPU which can be synced by the READ sequence with cycles on either side. The gaps are too short to enable some secret manipulation by a 6502 program. accidental detection of a false data field identifica- We will see that the READ sequence will properly tion string so they don't hurt anything. In either 3.2 read streams of data written from the 3.2 and 3.3 or 3.3 format, the data space behind an address field write tables in 32 cycle loops. It does take an indefi- is partially overwritten with a leader and data field nite period of time for the sequencer to sync up when when a "write sector" call to RWTS is made. it first encounters a random stream of data. How- An interesting point about DOS formats is the DE ever, random data streams in the DOS format are AA EB series that follows every address field and always preceded by read syncing leaders which data field. Apple has always had trouble writing the force the READ sequence into sync very quickly. EB. In RWTS 3.2 they cut off the EB at the end of These leaders consist of a series of 111111110 or the data field by neglecting to wait 32 cycles before 1 1 1 1 1 1 UOO data streams. They are written by stor- switching READ/WRITE to READ after storing ing $FF in the data register in 36 cycle loops EB in the data register. They changed that in (111111110) or 40 cycle loops (lllllUlOO) before RWTS 3.3, so the EB is actually written at theend of flowingdirectly into the 32 cycle data writing loops. the data field. However, RWTS 3.3 cuts off the EB Writing data at intervals greater than 32 cycles at the end of the address field. Those cut off EBs are results in trailing ZEROs (see WRITE sequence, not really written, so don't bother trying to read State 2:39-SL0), This causes the ZEROs behind the them. RWTS doesn't try either. eight ONEs in the read syncing leaders. When a string of read pulses from a read syncing leader is applied to the sequencer, bytes of data *FF36 and FF40 refer to $FF bytes written using 36 or 40 cycle following the seventh FF36 or fourth FF40 will loops, 9-28 Understanding the Apple DOS 3.2 FORMATTED SECTOR SXNCING LEADER ADDRESS FIELD DATA SPACE NEXT 16-80 FFS 431 FFS SECTOR FF FF *-FF FF D5 AA 85 VOL VOL TRK TRK SCT SOT SUM SUM DE AA EB 36 36 36 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 SYNCING LEADER DATA FIELD 11 FFS RWTS COMMAND- 2- FF FF- FF D5 AA AD 410 WORDS SUM DE AA EB DATA 36 36 36 32 32 32 CODED 5/a 32 32 32 14 I LAST EB OF 3.2 1 FIELD NOT COMPt WRITTEN. DOS 3.3 FORMATTED SECTOR SYNCING LEADER ADDRESS FIELD ZIP DATA SPACE ZIP 5-40 FFS D5 AA 96 VOL VOL TRK TRK SCT SCT SUM SUM DE AA EB GAP NULL GAP - 40 40 40 32 32 32 32 32 32 32 32 32 32 32 32 32 32 16 50 DATA FIELD 53 LAST EB OF 3.3 ADDRESS FIELD- t ^ NOT COMPLETELY WRITTEN. SYNCING LEADER DATA FIELD 5 FFS RWTS COMMAND- 2- FF FF FF FF FF D5 AA AD 34 2 WORDS SUM DE AA EB n DATA 40 40 40 40 36 32 32 32 CODED 6/8 32 32 32 32 :- Figure 9.15 Diskette Formatting. The Disk Controller 9-29 The READ Sequence Now assume QA sets as the result of an SLO or SLl This breaks the loop, shifting flow to State 2 of . There is an odd contrast in Apple Disk II I/O. The column four, a 28-NOP. We are at State 2; the next 6502 program works the tail off the MPU to write state is State 2; we are going nowhere until a read WRITE sequence, then storing data, initializing the pulse occurs. This is the QA WAIT location, out- coded data in precise timing loops. Yet, the WRITE lined in both the 3.3 and 3.2 listings. If the sequence listing is really pretty simple. Reading is sequencer is in sync with the data stream, the just the opposite. The MPU program sits back and fact thatQA is set means that a valid eight bit lets the sequencer do all the work. The program word is now in the data register just as it was merely polls the data register, waiting for the when it was stored there to be written. We will sequencer to lay a complete byte at its feet. The assume for now that the sequencer is in sync with READ sequence is not simple. Our discussion will the data stream. This means that the next read pulse concentrate on the 3.3 sequencer, which is very will be the MSB set pulse of the next word. nearly the same as the 3.2 sequencer. So we're sitting at QA WAIT waiting for the We start by assuming that the sequencer is con- BYTE FLAG of the next eight bit group. The read figured for reading ($C08E.X; $C08C,X) and that a pulse occurs. Do we clear the data register and do an valid data field is passing across the READ/WRITE SLl? No way, Jose. That's a valid byte sitting in the head with every eighth bit set. Further assume that data register. We're going to hold that information QA of the data register is not set, there is no read as long as possible so that the 6502 program can pulse present, and the sequencer is at State 2. You've figure out it's good stuff. The read pulse shifts the got to start somewhere, and we are starting at State sequencer to State 2 of column 3 (08-NOP). Then the 2 of column 2 in the READ sequence listing of Fig- read pulse goes away and we sequence to column 4, ure 9.11. State (18-NOP), then State 1 {38-NOP), then State At this location in the sequencer there is a 38- 3 (48-NOP), etc. We are sequencing now. waiting for NOP. At State 3. there is a48-NOP. At State4. there the read pulse that means the second MSB is a ONE is a 58-NOP. We are sequencing through the states, or the decision point that means the second MSB isa waiting for a read pulse. Assume a read pulse occurs ZERO. at State 6, switching the sequencer to column 1. The We'll say a read pulse occurs at State 8. The read pulse will last for one sequencer clock because sequencer goes to column 3, State 8 (D8-N0P), it is synchronized to the clock by a pair of flip-flops column 4. State D (E8-N0P). State E (F8-N0P). and a N AND gate. There is a D8-N0P at State 6 in State F (EO-CLR). The data register is finally column 1 In fact if you look at column 1 a read pulse . , cleared. It was held from the last read pulse or at any of the states would have resulted in a decision point of the previous word until past the D8-n6p. BYTE FLAG pulse and second MSB pulse of this When the read pulse goes away after the next word. The sequencer then goes to column 2, State E clock, the sequencer goes to State D in column 2, a (FD-SLl), then to column 2, State F (4D-SL1). We 08-NOP. This means move down to State 0(18-NOP) shift ONE twice, once for the BYTE FLAG and and then up to State 1 (2D-SL1 ). This SHIFT LEFT once for the second MSB set, then flow to State 4 of ONE is a direct consequence of the read pulse. A column 2 in the exact condition in which we started: read pulse occurred, so a ONE was shifted in. QA reset, sequencing along, waiting for a read Assume the SLl does not cause QA to become set. pulse. and don't get tired of assumptions. We now sequence Now we shift in six more bits of data which sets to State 2 in column 2, right where we started, mov- QA and puts us at Q A WAIT. You should notice that ing down the line, waiting for a read pulse. QA is set precisely when a complete eight bit word, This time let's say no read pulse occurs before we lead by the BYTE FLAG, is completely shifted in. reach State 9. This is the point at which the We made an assumption earlier that we were in sequencer decides it can't wait for a ONE any sync, but no further assumptions are required. more— that was a ZERO bit. State 9 is a 29-SLO. A Once we are in sync with a continuous stream of ZERO is shifted in. We'll say QA is still not set and MSB set data, we stay in syne. we're back to State 2. waiting for a read pulse. This We are at QA WAIT, waiting for the BYTE FLAG cycle will continue until QA becomes set after an pulse that starts the next word. Suppose somebody SLO or SLl. The sequencer is shifting in data based had written the word we just read using a 36 cycle on the presence or absence of read pulses. loop instead of 32. There would beaZERO following 9-30 Understanding the Apple II the eight bits of data prior to the BYTE FLAG sequencer groups the first data into eight bits lead pulse. You can't read ZEROs from QA WAIT. by a ONE in some random way. This is illustrated in There is no decision point here. The only thing the the first entry of Table 9.4, IXXXBXXX. The B sequencer will respond to is a read pulse, so that represents the BYTE FLAG pulse. It is a normal ZERO passes right by and is not shifted to the data read pulse, like that generated by any other ONE, register. but it is represented by B here for illustration. When Assunne the next BYTE FLAG pulse occurs, this the sequencer is in sync, the BYTE FLAG will be time followed by a ZERO. From QA WAIT the the first ONE of every group. sequencer takes the same path it did previously, At the firstentry of Table 9.4, the BYTE FLAG is except no read pulse occurs. The decision point is in the fifth bit position from the left. If the bit follow- reached at column 4, State C (AO-CLR) followed by ing this group is a ONE, that ONE becomes the first column 2, State A (BD-SLl), State B (59-SLO), State bit of the next group, and the BYTE FLAG stays in 5 (68-NOP), etc. The sequencer cleared the data the fifth bit position. If, however, the bit following register, shifted a ONE, shifted a ZERO, then con- this group is a ZERO, the ZERO is lost and the tinued processing of the next six bits. BYTE FLAG moves closer to the MSB of the next The whole idea of the QA WAIT is this: the group. Eventually, several ZEROs will have been sequencer always knows the next bit is aONE so encountered between groups, and the BYTE FLAG it is not monitoring the next puise as data; it is will reach the MSB. From that point, the monitoring the next pulse as the BYTE FLAG. It sequencer will stay in sync because the bit monitors the pulse that follows the BYTE FLAG as following each group of eight always be a ONE. data, and after monitoring this second pulse, it In data written by RWTS, the sequencer is never clears the data register and shifts in a ONE, ZERO left to randomly sync on a data stream. All data is or a ONE, ONE. In the process, the valid data word preceded by read syncing leaders which insure the is held in the data register for a long time with the sequencer is in sync when following data is encoun- MSB set, a condition which a 6502 program can tered. A string of seven or more FFs written in 36 easily detect. cycle loops or four or more FFs written in 40 cycle How does the sequencer get in sync with a data loops will insure synchronization. These nine and stream? The QA WAIT will cause the sequencer to ten bit write cycles cause synchronization because eventually sync on nearly any valid data stream it they are longer than the eight bit groups. When encounters. This is because it ignores ZEROs while encountered, these strings quickly are aligned into sitting at QA WAIT. What the READ sequence groups of eight ONEs followed by one or two does is to give theMPU a look at the data stream ZEROs. Table 9.4 shows the worst case conditions in groups of eight bits. Every such grotip has a for syncing to strings of FF36s and FF40s. leading ONE. ZEROs between a group and the next ONE are lost. In the READ sequence examples we went Suppose the sequencer encounters a stream of through, many events could have occurred which we data which was written in 32 cycle loops with the did not take into account. It would not be practical or MSB set on every 8-bit word. Being out of sync, the useful to try to step through all possible events. Table 94 Syncing ttie READ Seauence to Data. SYimmilO A RANDOM DATA STREAM SYNCING TO FF36S SYNCING TO FF40S IXXXBXXX 10B11111 100B1111 1XXXBXXX0 110B1111 11100B11 LXXBXXXX 1110B111 1111100B IXXBXXXX 11110B11 111111100 1XXBXXXX00 11111031 E111111100 IBXXXXXX 1111110B B111111100 1BXXXXXX0 11111110 BXXXXXXX B11111I10 BXXXXXXX B111U110 The Disk Controller 9-31 ( OAWAIT J NO < PULSE > SECOND READ PULSE 4-1Z CLOCKS AFTEfl FIRST 3CPN0P CLEAR QA QA QA' QA' SHIFT LEFT 1 SHIFT LEFT 1 SHIFT LEFT SHIFT LEFT 1 A. B, 5-9 VES YES 1CP ATRP NOP NO NO /"V NO / RP ATdP- 6-11 YES SHIFT LEFT 2-9 READ PULSE ^ NO READ f UlSE 2 CP NOP SHIFT LEFT SHIFT LEFT 1 RESET OA? SET Hgure 9.16 SJmptiried Rowchart of the Read Sequence. 9-32 Understanding the Apple II Deeper analysis shows that the read sequence is write interval while reading strings of ZEROs. It designed to correctly interpret read pulses while makes no difference with DOS 3.2 data formats, but tolerating an expected variation in the pulse inter- it makes reading less reliable with DOS 3.3 formats. val. Figure 9.16 is my attempt to put the basic flow The skew in the 3.2 READ sequence is shown in of the 3.3 READ sequence in perspective in a simple Figure 9.17. While the 3.3 sequencer always makes diagram. The pertinent sequencer states are listed a shift decision on the third clock period past an next to each block to aid readers in correlating the expected pulse, the 3.2 sequencer starts making the flow chart to the sequencer listing. decision at the wrong point after the first ZERO. In this flowchart, it was assumed that the read There are never more than two ZEROs in a row in pulse interface circuits were successful in produc- DOS 3.3 data, but the sequencer will handle more ing a read pulse which was actually one clock period than two if drive improvements make it a possibil- in width. In the READ sequence, there are provi- ity. Note that the 3.2 sequencer will read 3.3 format- sions to handle the rare event that a two clock read ted data, especially if the reading drive is slightly pulse occurs. This is an extra ounce of reliability slow. The 3.3 sequencer reads 3.3 data more reliably which would clutter up the flowchart and obstruct though. understandingof normal flow. I have monitored the If a read pulse occurs on the twelfth sequencer read pulse with an oscilloscope and have never seen clock after the previous read pulse, it is smack in the any read pulses that were not properly synchronized middle of the two points where the sequencer to the sequencer clock. expects a pulse. Is this an early pulse caused by a Please direct your attention to the 8CP WAIT fast drive or a late pulse caused by a slow drive? The decision block near the bottom of Figure 9.16. This sequencer treats this pulse as an early pulse when it represents the time when the sequencer is sequenc- occurs, no doubt because it takes less room in the ing up column 2. waiting for a read pulse. The 8CP sequencer ROM to do so. As a result, the sequencer WAIT indicates that a ZERO will be shifted if a read tolerates a fast reading drive or a slow writing pulse hasn't occurred by the eleventh sequencer drive better than the opposite condition when read- clock after a read pulse, and following ZEROs will ing the data format it was designed to read. be shifted every eight clocks after the first ZERO. For reference, I have tabulated the intervals The write interval is eight clocks, of course, so there which the sequencer can tolerate for various types of is an allowable distortion of three clock pulses for writtendata. Figure 9. 18 shows this tabulation, and the first pulse position after a read pulse. This is the you can see that it shows what would happen with main difference between the 3.2 sequence and the one data stream the DOS doesn't use. This is 3.3 sequence. After the first ZERO, following sequencer performance, not drive and disk perfor- ZEROs are shifted every 10 clocks in the 3,2 mance. The use of a string of three ZEROs is not sequence. This represents a skew away from the recommended, although a copy protect scheme READ READ READ READ READ PULSE PULSE PULSE PULSE PULSE EXPECTED EXPECTED EXPECTED EXPECTED i I 1 n M- O O O DOS 3.3 DECISiON POINT. DOS 3.2 DECtSION POINT. Figure 9 A 7 Decision Points for Itoading ZEROS. The Disk Controller 9-33 •* 1 A tt - "i D r ' ^ 1 - F- 1 h h r 1 \L - - 0- J] n 1 r 1 1 "* —G "^ n n o- o — J *- - n 1 j^ — , BYTE SYNC DOS 3.2 DOS 3.:i MfN AVG MAX MIN AVG MAX A 3 8 12 4 8 12 B 13 16 21 13 16 19 C 5 a 11 5 8 11 , D 12 16 21 12 16 19 E 22 24 31 20 24 27 F 2 8 11 4 8 11 G 22 24 31 20 24 27 H 12 16 21 12 16 19 1 22 24 31 20 24 27 J 32 32 41 28 32 35 ALL VALUES l« SEQUENCER CLOCK PERIODS Figure 9.10 Read Performance of ttie Logic State Sequencer. might use such astring. As an example of interpret- average data valid period for some data streams is ing Figure 9.18, interval A is the case of a BYTE tabulated in Table 9.5, Values are in sequencer FLAG pulse followed by a second MSB pulse. The clocks, so the number of MPU cycles many. is half as expected interval between these two pulses is eight In the Table 9.5 DATA STREAM entries, "B" sequencer clocks. The 3.2 sequencer will read the represents the BYTE FLAG pulse which follows the second pulse correctly if it occurs anywhere from 3 valid data. As always, variations in disk surface to 12 clocks after the BYTE FLAG pulse. The 3.3 speed at the read/ write head are most likely to cause sequencer will read the second pulse correctly if it errors in the presence of one or two consecutive occurs anywhere from 4 to 12 clocks after the BYTE ZEROS. FLAG pulse. The average data valid period must be at least 14 The amount of time a valid data word is held in the sequencer clocks if the MPU is to detect it in a data register depends on the second MSB of the next normal 6502 polling loop. Notice that the 3.2 word, normal pulse interval variations, and, in the sequencer would have trouble meeting this require- 3.2 sequencer, the least significant bits of the word. menton data which has two trailing ZEROs. This is The only bad thing that can happen is that the data one more reason that a 3.2 sequencer would have an will be valid for too short a period of time due to a easier time with 3.3 formatted data if the reading fast reading drive, a slow writing drive, or both. The drive were a little slow. 9-34 Understanding the Apple Table 9& Data Nftilfd Periods In Sequence Clocks. DATA STREAM 3.2 AVERAGE VALID PERIOD 3.3 AVERAGE VALID PERIOD XXIBI is 16 X10B1 16 16 100B1 14 16 XX1B0 19 17 X10B0 17 17 100B0 15 17 The selection of D5 AA as the field identifier in The switch from B5 to 96 as an address field iden- DOS 3.2 and 3.3 was no accident. D5 and AA both tifier inDOS 3,3 may have been required to main- consist of alternating strings of ONEs and ZE ROs. a tain the normal level of reliability in Apple Disk II fact which gives them a more unique identity in an I/O. I hope it was worth the cost of bootstrap inca- environment filled with strings of FFs and other patibility between DOS 3.2 and DOS 3.3. If so, my valid DOS data. Even when it is not in sync, the apologies to Apple for suggesting they could have sequencer should never produce the D5 AA combi- done better to stick with D5 A A B5 as the address nation from a valid data stream. This is because the field identifier. 1101010110101010, 11010101010101010. and 1 10101010010101010 combinations do not exist in a A A should not be The Read Sequence as a Finite State valid data stream. Obviously, if D5 accidentally read, then the D5 AA AD, D5 AA B5, Automaton and D5 AA 96 combinations should not be acciden- A reviewer of the rough draft of this book, engi- tally read either. Reliability is even greater because neer/programmer Jim Aalto, used the Figure 9.11 the AA AD combination itself should not be acciden- listing of the DOS 3.3 read sequence to construct his tally produced by DOS 3.2 data or DOS 3.3 data. own illustrative tool for studying the read sequence. The AA B5 combination should not be acciden- This tool is valuable enough that we decided to tally produced by DOS 3.2 data, but it can be pro- include it in the book (see Figure 9.19). Jim depicts duced by an out of sync encounter with DOS 3.3 the read sequence as a "finite state automaton." Like data. Specifically, the strings EA 96 AX or EA 96 a flow chart, Figure9.19 shows the logical paths the BX can be grouped as AA B5 if the sequencer is out sequencer may take, but the flow is in step with the of sync: sequencer clocks pictured at the top. The average read pulse interval is also pictured, so sequencer Xll. 101010100. 10110101.x performance with pulses arriving at various inter- vals is clearly illustrated. It is recommended that my speculation that this is the reason the readers studying this figure attempt to relate it to It is the read sequence listing of Figure 9.11. address identifier was changed to D5 AA 96 in DOS 3.3, causing the DOS 3.3 controller to be unable to boot 3.2 disks. It is my further speculation that this PROGRAMMING EXAMPLES FROM RWTS is why DOS 3.3 data words all have at least one pair There are several levels at which you can program of adjacent ONEs in bits through 6. This elimi- disk I/O. The DOS is setup with a very versatile file nates longer strings of ONEs alternating with handling capability which can be utilized from ZEROs which might tend to be interpreted as field BASIC as shown in the DOS Manual. If one had a identifiers in an unstable read pulse environment. desire, he could also perform such direct control In particular, the data EA A5 9X or EA A5 AX or functions as turning drives on and off. selecting EA A5 BX could be grouped as AA 96 if the use of drive 1 or 2, positioning the head, checking for write A5 were allowed: protect, and checking to see if a drive is turned on from BASIC via PEEK instructions. As an exam- Xll. 10101010. 100 10110.x ple, the following Applesoft subroutine will tell you The Disk Controller 9-35 i_ tn E/: %0 ^ tfi J r? —" Ld r^ 3- uj S uj cE c: Q o (J- " oc o o < z oc tr < ac CO UJ Q. Z — «t n. I /- "~\ } c* ?* t s = I o § ti tiJ tf) S> o 3 5 O _l UJ ^ § = S Z o 3 3 crt °- 3 DC < «r f LU LU o_ < gC UJ S 1- UJ < o o- g < = 3: o 1- a «" ^ < o) o cc _i a B CO CO GC ^: lu -I _i « o z 1M ~ ° " * |©E]| 9-36 Understanding the Apple II ( JSR S3D9 j GET im EDIT SLOT » OHIVEON EDIT DRIVE* CODE YES WRITE DATA ;56-342 SVNCCNI=j![I TRACK =0 & READ POSITION ADDRESS HEAD FIELD WRITE ie BAMGIT ADDRESS ALLOW 4 MORE AND DATA POSITIONS FIELDS POSITION FORMAT TRACK REDUCE HEAD ERROR EQUALS SYNCCNT (S08) TflACKM BY 2 on 1 ALLOW 48 RETRIES NO CSVNCCNT Two POSITION FORMAT VES ^ TO ERROR TRACK (SOfl) vy WRITE DATA FIELD finon \No /-TN DRIVE OFF ( RETURN J Figure 9^ Flowcharf of tNflS RouHne. The Disk Controller 9-37 if a disk in Slot 6, drive 1 is write protected: $CnFF while you're at it. Reference to the RWTS general flowchart in Figure 9.20 should also help 10 SL0T6 = 49376 : REM $C0E0 you keep your bearings. 20 DRIVEl = PEEK (SLOTS 4 10) 30 REED = PEEK (SL0T6 + 14) Drive Turn-On 40 DRIVESTART = PEEK tSL0T6 + 9) Drive turn-on is easy. Always configure for read- 50 LODE = PEEK (SLOTS + 13) ing first (LDA $C08E,X)i, select the drive 60 WPROTECT = PEEK {SL0T6 + 8) ($C08A,X/$C08B,X), and turn it on ($C089,X). Wait 70 REM LINE 60 GETS DATA about a second after turn-on for the disk to get up to REGISTER AND TURNS DRIVE OFF speed and then you can read and write. The RWTS 80 IF WPROTECT > 127 turn-on procedure, which begins at $BDO0, isa good THEN PRINT "WRITE PROTECTED" deal more sophisticated than this. It takes into 90 IF WPROTECT < 128 account all sorts of factors to get optimum perfor- THEN PRINT "NOT WRITE mance in a general purpose routine. PROTECTED" First, RWTS checks to see if the slot being 100 RETURN accessed is the same as the slot that was accessed last Note that the DOS does not have to be resident for time RWTS was called ($BD13). If not ($BD19) it this program to work. It bypasses the DOS and goes makes sure that a drive in the last slot accessed is not straight to the controller. still rotating before proceeding. Remember that it More sophisticated progranns may make direct takes one second for a drive to turn off after access to use of the DOS subroutines to perform special func- $C088,X. RWTS will not turn on two drives at once, tions. You do not have to be an expert on the DOS to presumably because of loading on the +12V power do this in your programs. The DOS manual shows line. you how to read a sector, write a sector, position the It is possible to check whether a drive at a slot is on head to a track, or format a disk by making calls to by configuring for reading data and monitoring the RWTS. In Beneath Apple DOS, Don Worth and data register. If a drive is turned on, the data regis- Pieter Lechner thoroughly explain the DOS and ter will be changing and vice versa. This is the check show you how to make direct calls to the DOS File used by RWTS: Manager. Worth and Lechner also offer worthy perspectives of RWTS and RWTS data formats and ORG $BD22 provide programming examples which should be of LDA 5C08E,X READ interest to students of Apple II disk I/O. STILLON LDY #$08 Even more sophisticated programs may bypass LDA C08C,X ;SHIFT RWTS or modify substituting different routines it, NOTSURE CMP C08C,X to manipulate the controller and transfer data to BNE STILLON and from the disk in formats not utilized by the DEY DOS. To learn how to do this, you should study this BNE NOTSURE chapter to see how the controller works, and you should study RWTS to see how DOS formats are written and read. RWTS is located at $B800-$BFFF This routine loops until the drive at the previous slot of the DOS (assuming 48K of RAM). Its entry point turns off. It will hang in this loop until RESET is is $BDOO, although it can be called by a JSR $3D9 in pressed if a call is made to RWTS that specifies a order to disable interrupts during RWTS process- new slot and the last slot was never turned off. ing and to ensure compatibility with future versions RWTS itself always finishes by turning off the of DOS. Upon return from RWTS. 6502 status is accessed drive. interpreted as an error flag (carry set indicates that After processing the old slot, RWTS checks if the anerrorocccurred in RWTS). The following discus- new slot has a rotating drive ($BD34). This will be sion points out some examples from RWTS which the case if the one second turn-off delay hasn't show how communication with the disk can be elapsed. If the drive is already rotating, there is no accomplished. Unless stated otherwise, these dis- need to wait for it to get up to speed. RWTS saves the cussions refer to RWTS as it is in DOS 3.3. You are rotating/not rotating status($BD4E), then turns the urged to make a listing of RWTS using your printer, drive on ($BD4F). This prevents a still rotating so you can refer to it while reading this section. drive from turning off after its one second lease on Make a listing of the Bootstrap ROMat $CnOO- life. » 9-38 Understanding the Apple Kext, RWTS checks to see if the specified drive is previously rotating, RWTS will go no further than the same as the last call to RWTS ($BD6A}. If not the count and wait loop at $BD9E until the motor ($BD6E), it then assumes that if a drive was rotat- count reaches $0000. This will complete the turn-on ing earlier, it was the wrong one. Therefore, it sets procedure, which takes one second plus small change the rotating/not rotating status to not rotating for a not previously rotating drive and whatever ($BD73). It also selects the drive via the $C08A,X/ time it takes to position the head for a previously $C08B,X switch {$BD74). rotating drive. Now if the selected drive was not previously rotat- ing, RWTS waits 150 to 175 milliseconds ($BD85) Positioning the Head in RWTS then calls the head positioning routine, 150 milli- At bootstrap time, the Apple finds track by seconds is not enough time that the drive is up to banging the head assembly against the outer stop. speed, but RWTS saves time by positioning the head The programming sequence which does this is at while waiting for drive speed to stabilize. The 150 steps $Cn3B through $Cn50 of the 3.3 Bootstrap millisecond delay accomplishes two things. First, it ROM {the PSA ROM). This routine shows a very avoids trying to position the head just after a drive economical way to step the head in terms of software has been turned on, which is a period of heavy cur- overhead. Just wait 20 milliseconds for motor rent flow on the +12 Volt line. Second, if the opposite response before turning off a stepper phase. The drive has just been disabled, the 12 Volts may not bootstrap routine uses 80 on-off descending refer- have yet bled off from the disabled drive.* This ences to $C0E0-$C0E7 (assumes Slot 6) to drive the might accidentally cause positioning of the disabled head 38 or 40 tracks outward depending on initial drive if RWTS tried to step the enabled drive too phase alignment. The timing is $COEO, $C0E1, soon. wait. $C0E0. $C0E7, wait. $C0E6. $C0E5. wait. Before DOS 3.2.1, this delay before positioning $C0E4, $C0E3. wait,.... $C0E4. $C0E3, wait, $C0E2, did notexist in RWTS. Apple added it in DOS 3.2.1. $C0E1, wait. The wait period is 20 milliseconds. presumably to improve performance, but they Note that phase-0 is left energized on the stepper botched it up. The way it is written in DOS 3,2.1, the motor after positioning. This is indicativeof the fact delay before head positioning is dependent primar- that even numbered tracks are phase-0 aligned and ily on the random state of $46E6 when RWTS is odd numbered tracks are phase-2 aligned. It also called and to a lesser extent on $46E6,X, The error is contradicts every theory I can think of as to why the in the JSR $BA7F which is stored at $BD7E. This analog card was designed so that leaving phase- 1 on should be changed to JSR $BA7B to make the wait- forces write protection. ing subroutine entry point correct The ferror does The head does not have to be banged against the not exist in DOS 3.3. stop to locate its position. The track number is writ- After the 150 millisecond delay in drives which ten as part of the address field in front of every were not previously rotating and almost imme- sector on a formatted disk. The head location can be diately in previously rotating drives, the head is determined at any time by simply reading an positioned to the selected track{$BD94). During the address field. Of course banging the head against 150 millisecond delay and during head positioning, the stop is the best way to absolutely determine head the motor-on time count is incremented at $46 and position, and there is no room in the bootstrap ROM $47. This two byte counter counts the amount of time for a routine that reads an address field and then a drive has been rotating at the rate of one count per tiptoes out to track 0. 100 microseconds. The preset count is part of the The RWTS positioning routine is far more sophis- Device Characteristics Table used in a call to ticated, and there are two calls you can make. Both RWTS. The DOS uses a value of $D8EF which is calls are made with slot number times $10 in the equal to -$2711 or -10001 in decimal. This converts X-register You can do a JSR $B9A0 with the desti- . to minus one second. nation track times two in the accumulator and the After head positioning, the motor count will have current track times two at $478. This will simply partially counted up to $0000. If the drive was not position the head using two phases per track. You can also do a JSR $BE5A with the destination track *I measured +12V bleed off time in my Disk 11 drive at 2 in the accumulator, a Device Characteristics Table milliseconds. set up, and some RAM locations correctly set up. The Disk Controller 9-39 This will edit the RAM locations and do a JSR than Commands and 4. even commands cause $B9A0. The RAM assignments are: writing of a sector's data field, and odd Commands cause reading of a sector's data field, but only $3C, $3D - Device Characteristics Table Commands 2 and 1 are normally used. Command 2 location. and 1 processing is the part that gives RWTS its $35 - MSB set if drive 1. MSB reset name. if drive 2. The FORMAT routine starts at $BEAF. It works $478 plus slot $B - Drive 1 last accessed track by starting at track ($BEBB), then formatting times 2. each track one by one. It starts by guessing there $4F8 plus slot $B - Drive 2 last accessed track will be 40 FFs in the read syncing leaders which times 2. precede every sector ($BED0). It then writes the 16 sectors with 128 FF40s before sector ($BFOD) and The $B9A0 routine isthe actual positioning 40 FF40s before the other sectors. Sectors are writ- routine for either type of call. It uses a technique of ten in order from to F, but they are effectively programming duration periods of the stepper motor interleaved because the sector specified in the lOB controls to maximize acceleration in the first part of is not actually the one that is read during a Com- head travel then to reduce head velocity near the mand 1 or 2 call to RWTS. Rather, the specified destination track to prevent overshoot and minimize sector indexes the Sector Interleave Table at settling time. For this purpose, the routine utilizes a $BFB8. wait after phase-on table at $BA11 and a wait Writing a sector while formatting consists of writ- after phase-off table at $BA1D, These amount to ing the address field ($BF17) which is preceded by a momentum tables for a typical head assembly. The read syncing leader, then writing a data field values in the table can be multiplied by .1 milli- ($BriC), which is also preceded by a read syncing seconds to give the wait time. leader. The write coded data buffer contains all As an example, the Slot 6 phase control for step- ZEROs ($BEBB), which means the data in the data ping from track $10 to track $11 is as follows: field will be a string of $96s. $C0E3. wait$01. $COE0. wait $70. $C0E5. wait $30, After writing the last sector on a track, the MPU $C0E2, wait $2C, wait $100, $C0E4, This is phase-1 waits for a number of cycles equal to about 200 plus on, phase-0 off, phase-2 on, phase-1 off. phase-2 off. 50 times the number of sync bytes {50 cycle loop at The above wait periods in decimal add up to .1 + 1 1.2 $BF3A). An attempt is then made to read the + 4.8 + 4.4 + 25.6 ~ 46.1 milliseconds which is the address field of sector 0. At 40 sync bytes, the sector single track response time of the Disk II operating address field will probably be long gone, in which with RWTS. not including a millisecond or so of case the size of the address field syncing leader will general computing time. The final wait of 25.6 mil- be reduced by two ($BF52), then the tail end of liseconds doesn't come from the watt tables but sector F will be found ($BF71), and the sectors will comes from looping through the 100 microsecond be written again starting at the same point on the wait routine ($BAOO} 256 times at the end of every disk as before ($BFOD). This cycle continues until head positioningsequence. This is the settling time the sectors fit evenly on the disk. The sync count is of the Disk II head positioning assembly. reduced by twos until it reaches 16. then by ones As mentioned previously, the 100 microsecond until it reaches 5, If 16 sectors do not fit on the disk waiting loop that is used to generate delay periods with a 5-byte leader, the disk speed is probably also increments the motor-on counter. This is part of adjusted way too high and a formatting error (error the scheme by wh ich the head is positioned while the code $08) is signalled ($BF60). motor gets up to speed .killing two welfare bills with When the sectors fit well on the track, all the one Republican. address fields ($BF62) and data fields ($BF67) are read and validated. As each sector is validated Formatting the Disk (Command 4) ($BF6A). an FF is stored in the correct spot in the Once the head is positioned and the disk is up to Sector Initialization Map at $BFA8. Examining speed. RWTS looks at the command entry of the this map may give you hints about the cause of for- lOB (I/O Block) to see what it is supposed to do matting errors. When all the sectors are validated (5BDAB). Command ($BDAF) causes an imme- the track number is checked ($BF98). If it is track diate exit with drives off and no error indicated. and the sync count is greater than 15, then two is Command 4 ($BDB3) causes the disk to be format- subtracted from the sync count ($BFA2), Other- ted with 16 sectors written on every track. Other wise, the sync count is left alone for the next track. 9-40 Understanding the Apple I Since the optimum sync count is found while for- banging the head against the track stop, then matting track the other tracks take much less time repositioning to the specified track. Only one major to format. track recalculation is allowed because the number After a track is completely formatted, flow returns of recalculation tries issettooneatthebeginningof to$BEDC.Anaddressfie]d($BEEB)and data field RWTS ($BD04). A major track recalculation is also ($BEF4) are read and the next track is stepped to, or performed if the correct sector cannot be located RWTS is exited with the drive off if all tracks have after reading 48 address fields. Another 48 attempts been formatted. The drive will actually turn off are made after recalculation before a DRIVE about one second after RWTS is exited. Waiting ERROR is indicated (error code $40). until a data field is just past before switching tracks Once the correct address field has been read, the means that anytime the track number is incre- command is checked again ($BE32). Read opera- mented on a formatted disk, an address field will be tions consist of reading the data field ($BE35), de- ready to be read. Also, if all sectors are validated coding the buffer 342 to 256 ($BE40), turning the without incident, the adjacent track sectors would motor off ($BE4D), and exiting. Write operations be interleaved so that you could start at track and consist of writing the coded data to the data field read a single sector on every track, stepping imme- ($BE51), turning the motor off ($BE4D). and exit- diately inward after reading each sector, and the ing. It takes longer to begin writing than it does to sector number read would be the same on every begin reading, so the reading will start just before track. The track-to-track sector interleaving serves the read syncing leader is encountered if the data the purpose of minimizing access time when step- field was written by a Command 2 on the same ping inward. drive. Data fields written by Command 2 are not a! igned with those written during formatting. Writing of Reading and Writing Sectors the data field during formatting begins 50 cycles (Commands 1 and 2) after writing of the address field ends. Writing of Reading and writing sectors are very similar the data field during Command 2 begins 1 12 cycles operations in RWTS. Both operations cause drive after the DE AA is detected at the end of the address selection and turn-on, head positioning, location of field. This is the equivalent point in time at which pertinent sector, reading or writing of a data field, the 16 cycle EB is stored while writing the address and drive turn-off. Additionally, write data must be field plus to 6 cycles for MFU detection of AA. As a coded from 256 bytes to 342 6-bit words before locat- result, Command 2 should begin writing a data field ing the specified sector, and read data must be about 49 cycles (112 + 3 - 16 - 50) after the NULL decoded from 342 6-bit words to 256 bytes after data field is written while formatting. reading a data field. There are only 53 cycles between the end of the If the RWTS command is not a or 4, read/write NULL data field and the beginning of the syncing processing begins at $BDB5. First, the command leader of the next address field. If it takes six cycles type is checked and saved ($BDB5). If a data field is for the MFU to see the A A at the end of the address to be written, the 256 bytes of data specified by the field, the data field written by Command 2 will lOB (I/O Block) are coded into 342 6-bit words bump up against the syncing leader of the following ($BDB9). After write data coding ($BDBC), read address field. It seems likely that the first address and write processing take the same path. A retry field sync byte will occasionally be overwritten by count is set to $30 indicating 48 attempts will be Command 2. Furthermore, if the Command 2 drive made to read the correct address field. The address is faster than the formatting drive, destruction of field is read ($BDC4), then checked for correct track the first part of the address field leader seems a ($BDED), volume ($BE10). and sector ($BE26}. certainty. This should cause no problem unless the Unless volume is specified, finding the wrong formatting drive was very fast, causing very short volume causes a return from RWTS with the drive address field leaders. off and a VOLUME MISMATCH ERROR indica- Command 1 should still be able to read the NULL tion (error code $20). Finding an incorrect track data field written by Command 4. Command 1 will number causes up to four repositioning attempts cause the MPU to start looking at the data register (count preset at $BD09), followed by a major track while the data field syncing leader is still passing recalculation ($BDCE), and up to four more reposi- the read/write head. The data field leader is 192 tioning attempts ($BDDC) before a DRIVE ERROR cycles long so the 49 cycle misalignment should not is indicated. A major track recalculation consists of cause the data field identifier to be missed. The Disk Controller 9-41 The misalignment between the Command 2 and and the values D5 and AA are not used in the storing Command 4 data fields is caused by the long" pro- of data. The D5 is placed in the data register 32 cessing time used in verifying volume, track, and cycles after the last FF of the syncing leader, so sector numbers during Commands 2 and 1. If they there are no ZEROs following the last FF and it were concerned. Apple could easily and substan- serves no read syncing purpose. tially reduce the misalignment by fetching volume The volume ($BC88), track ($BC8D), and sector and sector from the lOB and Sector Interleave Table ($BC92) numbers are written next, followed by a before reading the address field instead of after. checksum which is the exclusive-OR of the volume, The error detection circuitry in RWTS is very track, and sector numbers. These four values cannot sophisticated, allowing as it does for the possible be stored directly to the disk, but RWTS writes problems that might occur in data transfer. Not so them in a pair of 32 cycle loops following a simple sophisticated is the error indication found in the coding scheme. First, the value to be stored is lOB after a return from RWTS. There are three shifted left and ORed with AA. After storing this types of error codes: VOLUME MISMATCH ($20). result to the disk in a 32 cycle loop, the unshifted error during Command 2 or 1 ($40), and error dur- value is ORed with AA and stored to the disk. The ing Command 4 ($08). With a little extra program- result is that four of the bits are encoded in each ming RWTS could give such indications as storage cycle, and only valid data words are stored. ADDRESS FIELD CHECK SUM ERROR, DATA There are 16 possible storage words in this 4-4 FIELD CHECK SUM ERROR, CANT FIND encoded storage format: AA, AB, AE, AF, BA, ADDRESS FIELD IDENTIFIER, CAN'T FIND BB, BE. BF, EA, EB, EE, EF. FA. FB, FE, and DATA FIELD INDENTIFIER, CAN'T FIND FF. The use of AA here slightly degrades the integ- END OF ADDRESS FIELD, CAN'T FIND END rity of the D5 AA field identifier, but the system OF DATA FIELD, CAN'T FIND TRACK, CAN'T works anyway. FIND SECTOR. SYNC COUNT < 5. and soon. As The 4-4 CODE AND WRITE routine begins at it is. such DOS indications as DRIVE ERROR or $BCC4. This coding method offers less density than I/O ERROR mean only that something went wrong the 6-8 coding method, but it cou Id be the basis for a in RWTS. low overhead read/write subroutine which would transfer 2500 byte blocks of data directly between RAM and a track on the disk. Such a low overhead Write Routines subroutine would serve the purpose of many Apple There are several routines related to writing in users. RWTS. One is the WRITE ADDRESS FIELD After the checksum is written, the WRITE routine at $BC56. This routine writes the syncing ADDRESS routine finishes up by writing the values leader and address fieJd shown in Figure 9. 15 and it DE and AA, then part of an EB, The EB is trun- is only called when a disk is being formatted. The cated to a 11 10 since the controller's RE AD/ WRITE input parameters are: switch is switched to READ ($BCBD) on the 16th MPU clock after the EB is stored in the data regis- Y Reg - Number of FFs in syncing leader ter. Switching to READ here results in a 50 cycle $41 - Volume gap between the address field and data field. The 50 $44 - Track cycle gap causes no harm, because it is not long $3F - Sector enough to randomly produce a three word data field $AA - Contains the value $AA identifier (D5 AA % or D5 AA AD). Another write related routine is a routine which The routine checks for write protection first codes a 256 byte data block into 342 6-bit words. This ($BC57), then stores the first FF in the data register "PRENIBBLE" routine begins at $B800. The ($BC61). then continues to write FFs in a 40 cycle address of the 256 byte data block must be stored at loop ($BC69-$BC77). The number of FFs is adjusted $3E and $3F and the 6-bit words will be stored in a by the format routine so the 16 sectors fit on each pair of coded buffers in the OOXXXXXX format. track without a large gap between sector and sec- The six MSBs of the 256 data bytes are stored in a tor 15. The minimum number of FFs in the leader 256 word buffer beginning at $BBOO. and the 2 will be 5. LSBs of the 256 data bytes are grouped together in After the sync writing loop is exited, the series D5 an 86 word buffer beginning at $BCOO. The 256 AA 96 is stored directly to the data register at 32 word and 86 word buffers are the source file for the cycle intervals. This is the address field identifier. write data field routine at $B82A. 9-42 Understanding the Apple l[ The WRITE DATA FIELD routine is called in and sector are not those desired, RWTS calling rou- formatting a disk (RWTS Command 4) and in writ- tines will attempt to find the correct sector 48 times, ing data to a sector (RWTS Command 2). In format- bang the head against the stop, then reposition, then ting, the 256-word and 86-word coded data buffers try to find the correct sector 48 more times before contain all ZEROa, so a NULL data field is written giving up and deciding there is an error. Reading of 50 cycles after the end of an address field. In a the incorrect volume, however, causes the imme- Command 2 write, first data is coded using the diate return with a VOLUME MISMATCH error PRE NIBBLE routine, then the desired- address unless volume was specified in the lOB. field is read, then the data is written with the The sector which is read is not taken directly from WRITE DATA FIELD routine using the coded data the lOB. Rather, the lOB value is used to index the buffers as a source file. This "real" data field is not Sector Interleave T^ble at $BFB8 which contains 0. centered on the NULL data field but lags it by D, B. 9. 7, 5. 3. 1, E, C. A, 8, 6, 4. 2, F. As an example, approximately 50 cycles. if the lOB specifies sector 1, the sector which will be The WRITE DATA FIELD routine checks for sought will be sector D. This leads to the following write protection ($B830). writes four FF40s fol- effective order of sectors on each track: 0, 7, E, 6, D, lowed by an FF36($B83D), then stores the data field Presumably it is chosen to 5, C, 4, B. 3. A, 2, 9, 1, 8, F. identifier. D5 A A AD. directly to the data register minimize access time to sequential sectors in the at 32 cycle intervals. Then the coded data buffers DOS environment. are written in 32 cycle loops, using the exclusive-OR The READ DATA FIELD routine is at $B8DC. of thecurrent 6-bit word and the previous 6-bit word This is called when the sector writing is verified to index the Write Table at $BA29 to obtain the while formattingor when a Read Sector (Command value to be written. This odd storage method is rev- 1) call is made to RWTS. Reading begins after the ersed in the read operation, and it creates a check- desired sector is located via the READ ADDRESS sum by which the validity of data transfer is FIELD routine. checked. The 86-word buffer is read first for output Since the READ DATA FIELD routine is always from the top down ($B862), then the 256-word called after the address field has been read and buffer is read from the bottom up ($BA7B). After- verified, the data field should pass under the read/ wards, the DE A A EB trailer is written with the EB write head very soon. If more than 32 valid words completed. This is opposed to the incomplete EB at are read ($B8DC) and D5 AA AD isn't found, the the end of the DOS 3.3 address field and DOS 3.2 routine is exited with carry set to indicate an error. data field. Oddly, finding D5 AA XX other than D5 AA AD Read Routines gives the routine 86 extra chances to find D5 AA The READ ADDRESS FIELD routine is at AD. $B944. This routine is used to locate any address After finding the identifier, the data field is read field, fetch the volume, track, and sector, and to into the 86 word buffer, top byte first ($B8FF) and check validity of the read. It is performed in format- into the 256 word buffer, bottom byte first ($B913). ting to verify correct sector distribution and con- Each valid word read from the data register is used tent, and it is used in reading or writing the data to index the Read l^bie which begins at $BA96. field of a sector to locate the correct sector. This table is the inverse of the Write Table. Each The routine starts by looking for any D5 AA 96 table value is exclusively ORed with the "running sequence. This should occur within roughly 385 total" to get the value stored in the big and little valid data register words from any point on the disk. buffers. This is the inversionof the writing process If it doesn't occur within 772 valid data words and the running total is checked for correctness at ($10000 minus $FCFC). the routine is exited $B92A, A nonmatching checksum or absence of a ($B94D) with the carry status set, indicating an trailing DE AA causes return with carry set, indi- error condition. After finding D5 AA 96, the four cating a read error. parameters are read in a 4-4 read loop while accum- The formatting routine calls the READ DATA ulating the checksum ($B96D). Volume, Track, Sec- FIELD routine just to check the carry status and to tor, and Checksum are stored at $20, $2B, $2A, and verify its own handiwork. When reading the data $29 respectively. Next, the presence of the trailing field in a Command 1 call to RWTS, the data must be DE AA is verified. Checksum failure or absence of decoded from the six bit words in the big and little DE AA causes the carry to be set, indicating an buffers into the 256 byte RAM block that was speci- error condition. The calling routine will not process fied by the lOB. A "POSTNIBBLE" routine which the data if the error flag is set or the volume, track performs this is located at $B8C2, The Disk Controller 9-43 HARDWARE APPLICATION INSTALLING A WRITE PROTECT SWITCH ON THE DISK II DRIVE Did you ever want to store information on a write The bypass position of the switch allows you to protected diskette? This involves removinj^the write write on a protected disk. This might be of use in protect tab or cutting a write protect notch, writing writing on disks you have protected for your own the file, then sticking on a new write protect tab. reasons, writing on special diskettes that have no Here's another one. Did you ever delete a file, then notch, and writingon the backs of single sided disks immediately regret it? If you haven't run into one of if you do that sort of thing. If you happen to be a these situations, then I'll only say that your ball sure software publisher, this mod is a must. bounces more nicely than mine does. This Applica- The idea of the write protect switch is not my own. tion Note details a simple modification to the Disk II It was pointed out to me that the modification had drive which enables you to write on write protected been suggested in magazine articles. Once it is real- disks and also gives you ti me to have second thoughts ized that such a modification is possible, the design about writing files to or deleting files from a disk. of the modification is fairly obvious. The modification involves installing a single Figure 9.21 shows the modification. Before per- switch on the front of the Disk II drive. The three forming the modification, please read the NOTE position switch allows selection between normal OF CAUTION in the front of this book. What is operation, forced write protection, or bypass of involved is installation of the new switch and rewir- write protection. If you normally leave the switch in ing of the already present switch which is activated the protect position, you will always have to take an by the write protect notch. The type of switch extra step to write, delete or rename a file. This is a required is a ON-OFF-ON SPOT (Single Pole, fairly normal feature of expensive storage peri- Double Throw) switch. The installation procedure pherals associated with mainframe computers. given here involves installing it on the front of the Normally, taking the extra step required to over- drive, but you may prefer to put the switch on a write data makes the operator think twice about remotebox. When buyingthe switch, select one that possible destruction of important data. switches very easily so a minimum of stress is placed i PHASE1-*<^4 WRITE CONTROL PROTECT NORMAL WRITE PHASE 1 CONTROL Cl> PROTECT MODIRED Notch in side of disk Figure 9,21 A Single Switch on the Front of the Drive Allows the User to Select Normal Forced Write Pioiect, or , Bypass Write Protect. 9-44 Understanding the Apple Figure 922 A Drive With ttie Wrfte Ptotect Switch tnstalled. on the plastic front panel of the drive. Since the two plugs at the back and by removing the four- notch activated switch is mounted below the disk pin read/write head plug. Remove the retaining slot, the new switch should also be mounted below screw on either side, and the analog card slides the slot so wires will not interfere with disk inser- out. You may wish to clean the head with alcohol tion. Choose a mounting point near a reinforcing and cotton swabs at this point. structure on the back of the front panel to give added Remove the two beveled head machine screws strength to your installation. All wiring should be from each side of the front panel. Position the soldered, and 24 gauge insulated wire works nicely. panel to the side, attempting not to strain the Thepurposeof steps 5.7, and 11 is to improve acces.s- wires connected to the IN USE indicator. ibi ty and you may elect not to perform them if you 1 i . Use a fine lead pencil to outline the position of are good at working in tight spaces. the notch activated switch. This way you can Installation Procedure: reinstall it in the same position. It will also help to slide a disk in and out of the drive while you 1.Turn off the computer and remove the controller observe the switch action, so you will be able to from its slot, Mark pin 1 of the 20-pin ribbon reproduce the same action at reinstallation. cable connector and plug with fingernail polish Remove the two alien screws which hold the so you will not reinstall the cable incorrectly. switch to the side of the drive. Disconnect the ribbon cable from the controller A black wire is connected to the normally closed and move the drive to a convenient work area. contact of the notch activated switch. Desolder 2. Remove the four screws from the bottom of the the black wire. This wire needs to be connected drive. Remove the white ease by holding the to the ON-OFF-ON switch and it will probably drive on your palm and sliding the case to the require a short splice. Splice a short jumper rear. between the black wire and the center or com- 3. The notch activated switch can be seen toward mon contact of the ON-OFF-ON switch. Solder the front on the left side of the drive. Select the both connections and insulate the splice connec- location of your ON-OFF-ON switch .so that tion with electrical tape or by another suitable wires can be connected between the two switches method. in a way that drive mechanisms are not inter- Connecta wire between thedesoldered terminal fered with. Hold the switch near the selected of the notch activated switch and the NORMAL spot to make sure no problems will arise. The mode contact of your ON-OFF-ON switch. If location shown in Figure 9.22 works well with a you choose to have NORMAL mode be the down small bodied switch. position, then the upper contact will be the 4. Mark and drill a hole for your switch. Clean out NORMAL mode contact, and vice versa. any plastic filings which fall into the drive. 10. A brown wire is connected to the common con- 5. The big horizontally mounted card is the analog tact of the notch activated switch. Solder one card. You may remove it by disconnecting the end of a jumper wire to the same contact as the The Disk Control ler 9-45 brown wire. Solder the other end to the BYPASS You should mark the functions of the new switch mode contact of your ON-OFF-ON switch. The on the front panel, I used white dry transfer letters, BYPASS mode contact will be opposite the available in electronic stores, for this purpose. NORMAL mode contact, Afterwards, I sprayed the switch area with an 11. Remount the notch activated switch to the side acrylic coating, also available in electronic stores, to of the drive, aligning it to the outline you drew protect the lettering. All drive openings should be with a pencil. Slide a disk in and verify that the covered when spraying with acrylic coating to pre- switch clicks on and off as the disk notch is vent accidental coating of the read/write head. engaged and disengaged. Some alternate source drives for the Apple use a 12. Mount the ON-OFF-ON switch to the front light emitter and photo switch to check for write panel. protection. Rewiring the photo switch in conjunc- 13. Reinstall the front panel on the drive, making tion with a new ON-OFF-ON switch should also be sure the spindle engagement mechanism mates possible on most or all such drives. I happen to own a with the grooves on the hinged door on the front FOURTH DIMENSION drive manufactured by panel. Siemens. I added the write protect switch mod to it 14. The remainder of reinstallation is the reverse of by splicing into the wires going to the photo switch. the dismantling steps. You can easily verify On the 4D drive, the photo switch is mounted over operation by attempting to delete some test files the disk slot. The white wire is the input to the photo and observing the write protect indication. Do switch and is the equivalent of the brown wire in the not operate with any disk containing important above procedure. The yellow wire is theoutputof the files until you have verified correct operation of photo switch and is the equivalent of the black wire the modified drive. in the above procedure. I chapter 1 Maintenance and Care of the Apple II business system. In this chapter, attention will be The modern microcomputer is such a marvelous given to the maintenance philosophy of the Apple thing. Just think of the accumulated knowledge and industrial capability of the human race represented computer. There will be some discussion of what options you have when your system fails, and of some by such a machine. Invented by man, feared by man. exploited by man. and hated by man. Especially simple fault isolation steps which can be taken by hated by man when it doesn't work right. After you in your home. We also will discuss ways of reduc- ing the probability of hardware failure in your years of having computer systems subjecting us to impersonal and illogical errors, we have advanced system. in our to the point where we have computer systems and own homes subjecting us to personal illogical AFPLE HARDWARE RELIABILITY errors. The vast majority of computer m istakes are caused There is no electronic circuitry more reliable than by imperfect programs. The more involved a pro- modern digitai electronic circuitry. Digital ICs rou- tinely operate for thousands of hours without fail- gram, the greater the chance of an oversight by the programmer. We used to curse the computers. Now, ure, and they are easy to replace if they do fail. The when a husband writes a program that allows his Apple computer is consequently a very reliable wife to enter her kitchen recipes, then destroys them machine. There are, however, less reliable facets of gets a computer than the ICs that populate it. Some weak in milliseconds, it's not the computer that Yes. today's computers are very personal. links in the reliability chain are discussed here. cursed. Occasionally, computer malfunctions will actu- Tinkering Users ally be caused by a hardware failure rather than a If you are very involved with your hardware, try- program in disarray. This should be a fairly rare occurrence, because digital electronics circuitry is ing new and different things all the time, you are so reliable. Yet, hardware failures do occur, and bound to make some mistakes which cause hard- most of us encounter them eventual ly in our home or ware casualties. People who like to tinker with their 10-2 Understanding the Apple computer should do so, because it's as fun as all get This is because DO is adjacent to +12 Volts on the out. Those same people would be naive to think they peripheral slot pins and they may get shorted may not occasionally mess something up. Even together. Combining two reliability hazards, you though my wife thinks otherwise, I have probably come up with the most common cause of hardware set no records in this area. I do, however, consider failure in the Apple, a tinkering owner who installs myself an Apple clobberer of the first degree. The and removes cards while power is applied. personality traits necessary to reach this plateau of One of the worst things that can happen while destructive potential are an infantile curiosity and installingorremovinga peripheral card isthatflex- terminal absentmindedness. ing the motherboard might cause a hairline frac- The possibility of causing hardware failure by ture of a current trace or solder joint. Of course the tinkering leads to the following common sense rule. same thing could happen if you drop your Apple or if If your Apple is your bread and butter— if it costs a manufacturing defect starts to show symptoms. you money when it's not running— don't mess with The resulting marginal electrical contact can cause it. If your Apple is your creative outlet, then play system problems to come and go in a random way with your toy any way you please. based on such variables as temperature, mother- board stress, and the price of hogs in Kansas City. A The Peripheral Slots good computer technician might be able to isolate a It is this author's opinion that the most important problem like this on a good day if you can afford the hardware feature contributing to the Apple's mar- wages of a good technician for a whole day. keting success is the concept of peripheral slots, mounted on the motherboard with address decoded Peripherals with Moving Parts control signals generated on the motherboard. The Moving parts are a reliability problem in any peripheral slots do represent a reliability weak industrial creation. Compare an automobile to a point though. Suppose you had a television which computer. The automobile might run 100.000 miles allowed the owner to enhance it in all sorts of ways before its effective life is over. This will be 5000 by lifting the lid on the television and installing operating hours at 20 miles per hour with many cards in slots on a big motherboard. Surely, every parts replaced along the way. Yet you could turn on owner who reconfigured his television a lot would your Apple and let it run for 208 days in a row (5000 mess it up eventually. The TV repair industry would hours) and have a very reasonable chance of expe- be happy with the extra business, but give them riencing no hardware failure. If a part fails, you can another bonus. Mount the motherboard on a few replace it and go another few thousand hours with- nylon posts so that it flexes terribly when someone out a failure. The main limiting factor on effective installs or removes a card, and make sure a lot of life is obsolescence. different manufacturers make the cards so that Now take a disk drive, an electro-mechanical some of the cards will fit too tightly. How interesting device with precise mechanical alignment. Don't it was of Apple to combine such admirable elec- expect to run a disk drive for 208 solid days without tronic engineering and such ghastly mechanical hardware failure. Friction can cause the motors or engineering in the same peripheral slot concept. head assembly to wear out, and like the front end Recent Apples have a greatly improved mother- alignment of a car, drive alignment sometimes goes board mounting with a steel bar reinforcing the out. Cleanliness becomes a factor. If you are really motherboard near the peripheral slots. puttingalotof hours on your Apple, then you should The sort of thing that can go wrong when pulling expect to eventually have to have some disk drive or removing cards is that a card might get installed maintenance performed. The same is true of a prin- backwards. I'veonly donethistwice. It tends to wipe ter. Heavy usage results in wear on the moving parts out one or more chips on the card. As soon as a chip and in probable eventual maintenance requirements. shorts a power supply voltage to ground, the power This is why printer manufacturers will advertise supply shuts itself off and damage to further chips is how few moving parts there are in their products. prevented. An impatient owner might remove or install a card with power applied to the Apple. You The Power Supply can usually get away with this, but when you see a In the hypothetical 208 day reliability test that spark, cross your fingers. I've never burned up more was mentioned earlier, if any unit failed, it would than one chip at a time doing this, but it's possible to most likely be the power supply. This is because the wipe out every chip connected to DO of the data bus. electric currents in the power supply are so much Maintenance and Care of the Apple II 10-3 greater than in any IC. Of course the power supply is 4. Don't operate the Apple on an unstable power rated to handle a lot of current, but high current source. Be wary of operating during electrical devices are usually more apt to fail than low current storms because power may fall. devices. Also, if the AC line voltage fluctuates, the 5. Connect power to the Apple through a bus bar or power supply is the unit most likely to be damaged other device with a switch on it and turn the by the resulting current surges. Apple on and off using this switch to save wear Application and removal of power to the Apple on the power supply switch. The bus bar may can be thought of as a controlled fluctuation. The ICs have current surge suppressors built in which and power supply are designed to handle the cur- help stabilize the power applied. rent surge thatoccurs when the switch is turned on. 6. You may elect to reduce the operating tempera- Still, there is no time when your computer is more ture of the Apple by mounting a fan on the case. likely to fail than when the power is fluctuating, Products are available which perform the three including when you turn the power switch on. This tasks of providing an external switch, surge sup- means you should turn the Apple off if power starts pression, and temperature reduction. None of these fluctuating, as when the lights in the house go dim is necessary for operation of the Apple, but it can be during a storm. It also means that you should not argued that each one could improve its reliability. needlessly turn the power to the Apple off and on. Necessity of temperature reduction is the most A particular reliability problem with the Apple questionable. The Apple uses commercial grade (as power supply is the power switch. The switch arcs opposed to military grade) components which are sometimes at power up, and this can eventually guaranteed tooperate within specifications over the cause the switch to malfunction. The problem is 0-70 degrees Centigrade (32-158 degrees Fahren- compounded because the Autostart ROM allows heit) operating range. My measurements of the software to hang the system in a way that pressing Apple's operating temperature indicate that it RESET will not help. The user has no choice, in this operates under 130 degrees Fahrenheit just above instance, but to turn the Apple off, then on to reini- the 6502, which is the hottest spot I could find. This tialize the system. This causes extra wear on the is well within the 158 degree specification of the switch and exposes the computer to possible power- components. Reducing this operating temperature up casualties. In more recent Apples, the power should still reduce thermal expansion, reduce the switch is rated for 10 amps instead of the 8 amps of possibility of malfunctioning of components that are older Apples. Maybe this reduced the likelihood of not up to specifications, and reduce the possibility of switch failures. More importantly. Apple now allows malfunctioning due to overloading of signals by too computer stores to replace the switch instead of many peripheral slot cards. Also, by reducing power effectively requiring them to replace the whole supply temperature, one would expect to increase power supply as they used to do. This allows a repu- the amount of current that can be supplied before table store to repair the problem for about one overheating and failure of power supply compo- fourth of the previous cost. nents occurs. To see for myself the effect of using a fan on the operating temperature of the Apple, I ran a four IMPROVING YOUR APPLE'S RELIABILITY hour test, measuring the temperature at the top of The reliability weak links give some hints on how the power supply and just above the MPU with and to improve the reliability of your own Apple: without a fan running. The fan used was a Super 1. Above all else, never remove or install peri- Fan II made for the Apple by R. H. Electronics. It pheral cards or ICs with power applied. hangs from the left side of the case and has an exter- 2. To improve reliability, don't tinker with the nal on/off switch and surge suppression. Four peri- Apple or peripherals. This must be each per- pheral cards were installed in the Apple under test, son's compromise between the conflicting desires which was a Revision 7D Apple II PLUS. The of wanting a reliable computer and wanting to temperature measuring device was a pyrometer tinker. You probably know that my personal which utilizes a thermocouple for a probe. The choice is to tinker all I want. results of the test are shown in the graph in Figure 3. Keep the Apple covered when not in use so that 10.1. As the graph indicates, it gets very warm near the electronics stay clean and nothing is acci- the surface of the MPU. Also, the fan reduces the dentally dropped inside. Don't set coffee or operating temperature by about 15 degrees Fahren- sodasonthe Apple, because you may spill them. heit. Whether or not this is worth the price tag is 10-4 Understanding the Apple TEMPERATURE Cover removed IN DEGREES F. from Apple End test Move temperature probe mm above to point 2 MPU. Temperalure indication drops wtiile moving probe Start test by turning Apple on. Fan oft. Temperature probe al top of power supply. i —i— — — —I— —;— — — I ] 1—1 I j I 300 TIME IN MINUTES Figure 10.1 Temperature Measurements Inside an Apple II Plus. a subjective matter. Please note that the graph is do not exist in digital equipment, because most of probably a g'ood indication of the relative tempera- the circuitry is made up of two-state electronic tures with the fan off and on, but that there are switches. In most circuit elements, either current nnany variables which affect the absolute reading, flows or it doesn't flow. This is a simple condition including the temperature of the room, probe place- compared to the infinite variety of signal conditions ment, and instrument accuracy. The measurements which exist in analog electronics. made at the surface of the power supply were prob- The complexity of digital equipment lies not in ably closest to the ambient air temperature in an complex electronics but in complex logical capabili- Apple. It would be fairly accurate to say that the ties. As a result, any difficulty in the repair task will ambient air temperature in the Apple cabinet is often be due to this logical complexity. This is good, about 30 degrees F. greater than room temperature because it means many hardware functions in a and that the temperature differential can be reduced computer can be verified, and many casualties can by about 15 degrees F. with a fan. be isolated by self diagnostic programs. More trouble- some problems can be diagnosed by externa! com- puters designed and programmed to troubleshoot REPAIR OF THE APPLE II certain classes of problems. Since computer casual- Repair of a broken digital computer is different ties are often logical malfunctions, what better way than repair of other sorts of electronic equipment. is there to solve them than by logical analysis usinga Many uncertainties of electronic circuit operation computer? Maintenance and Care of the Apple II 10-5 I shop can change the analog card in a disk drive, There isvirtually noend user self diagnostic capa- bility in tJie Apple II computer. There is no hardware but they can't change the drive motor. Also, with or firmware based timing verification, I/O verifica- few exceptions, Apple won't accept a modified tion, ormemory verification. RAM based diagnostic assembly. One exception is the shift key mod when programsareavailableon disks to computer dealers wired to pin 4 of the game I/O socket or pin 1 of but are not available to owners. There is, therefore, socket H14 (the same point electrically). Apple liked very little an owner can do by way of isolating diffi- that mod so much, they included it as part of the cult casualties unless there is an in house computer Apple He, technician with some test equipment. There are Apple's no swap rule for modified assemblies is some cheeks that can be made by anybody, but more fairly reasonable considering that they must make on that later. their own repair operation cost effective. An exam- The typical computer retailer will have what ple of where this rule was carried too far is the Apple calls a Level I repair capability. They will power supply switch. Apple did not allow any repair often have a shop and a computer technician. They work on the power supply and put two rivets in the will also have several disks full of diagnostic pro- bottom so it was hard to gain access to the internal grams and a pipeline to Apple. If their diagnostics components. If those two rivets were removed, then will load, they will verify and isolate faults in RAM, Apple wouldn't accept that assembly for swap out ROM. the keyboard, video display, and Apple manu- without special permission. As a result, if the switch factured peripheral devices. The technician or sales- went bad, the customer was required to pay $90 for a man can then replace components that are indicated power supply swap out when switch replacement to be bad and hopefully fix the malfunctioning should only be about $25 for parts and labor. Then Apple very cheaply. The dealers also have disk drive Apple changed the power supply from the silver alignment disks and procedures which allow their colored one to the gold colored one, to which access technicians to precisely align the Disk II drive. can be gained by simply removing some screws. Dealerships with more sophisticated repair capa- They now allow dealers to change the switch on bilities will also work on some products not manu- either type power supply, although some dealers factured by Apple, such as 80 column cards or will still swap out the whole power supply at a $90 printers. Ifthere is a resident Apple technician with cost. an oscilloscope, he probably will repair many prob- The primary hardware based self diagnostic fea- lems not pointed out or isolated by the diagnostics. ture of the Apple is an empty peripheral slot. An When a problem is beyond the capability of a empty slot becomes a diagnostic port when you plug dealership or the repair of a problem will be so time a specially designed test fixture into it. There can be consuming that it will not be cost effective for the no doubt that Apple must use such test fixtures for dealer or customer, the dealer will swap out a major production check out as well as fault isolation, assembly for a very reasonable cost. For example, a because they are an obvious necessity. What can you motherboard swap costs $120. a power supply costs tell about an Apple from a peripheral slot? You can $90. and a disk controller card costs $55.* He then verify power supply voltages, verify timing, cheek sends your repairable assembly to an Apple Level 11 RAM and ROM and all address bus command fea- repair facility. Apple can repair the assembly more tures via DMA, measure for shorts at all pins, exer- easily because they have sophisticated test fixtures, cise the 6502 with a test program via the INHIBIT' documentation, and assets not found in a computer line, and verify correct interrupt response. Prob- dealership. Other companies besides Apple will also lems with individual memory chips can be isolated have a turn around policy on their Apple compatible to the chip while other problems may be isolated products. Therefore, when a peripheral card fails, only to an area. Further isolation of problems can be you may well be able to get a quick swap at a com- performed by attaching jumpers from the smart puter dealership. test fixture to various ICs. Apple probably has an Apple will not allow Level I repair shops to per- area full of engineers who do nothing but design test form some tasks. They maintain this control by fixtures for Apple products, program them, and refusing to swap assemblies upon which unauthor- write test procedures for them. ized work has been performed. For example, a Level We pay for this diagnostic capability when we buy 'Suggested prices recommended by Apple for out of warranty Apple products, even though it isn't built into the repairs. Augrusl 1, 1981, Still valid as of March 15. 1983. Apple. Large scale automated checkout and fault 10-^ Understanding the Apple i isolation of a product is the only way to provide is repaired. Even when a peripheral is malfunction- quality assurance and service a complex mass pro- ing, it is a good idea to check operation with all other duction device in a cost effective way. Money for peripheral cards removed. For example, your disk developing this capability must come from sales and controller may be loading down the RESET' line service revenues. and causing the firmware card to misbehave. This procedure of isolating a problem to a peripheral card will be referred to as the peripheral card WHEN YOUR APPLE BREAKS check. Other than this most basic of checks, your When your Apple breaks, chances are that you course of action will depend on your symptoms. The will have to take it to a computer dealer for repair. most easily recognized symptom is a completely Yet there are Sonne very simple checks you can make dead Apple, normally indicating a power supply which might get your Apple up in ahurry. These are problem. checks which can be made by anyone, and they are the kind of checks a salesman might make if you brought your Apple in on the service technician's Power Supply Problems day off. Be aware that any damage you cause while There are two symptoms you will normally en- making these checks will void your warranty if it is counter with power supply problems. The Apple is still in effect. Also, any use of test equipment by dead and there is a low level clicking noise coming unauthorized service personnel might put your from the power supply, or the Apple is dead and warranty in jeopardy. silent too. If there is a clicking noise, the power In these discussions, the use of a multimeter, logic supply is quite likely good, but a motherboard or probe, or oscilloscope will be occasionally called for. peripheral card malfunction is causing an overload If you do not have access to the instrument men- condition. If the Apple is dead silent, there may be a tioned, or you do not know how to use it. it is time to get casualty in the power supply itself. your system to a dealer. Incidentally, you can buy a The clicking noise is the tinkerer's symptom. logic probe and a multimeter for $20 each at Radio Chances are very good that somebody was instal- Shack and learn how to use them in a few minutes. ling, removing, or modifying something in the If you manage to find the exact cause of a problem, Apple. When any casualty symptom follows tinker- you can buy most Apple components in computer ing, concentrate your investigations in the areas electronics stores or, more expensively, at computer that were tinkered with. If something was touched, dealers. The computer dealer will charge you more look it over. because he is not in business to sell electronic com- When the clicking noise occurs, turn the computer ponents. Like virtually all American maintenence off immediately. If a component has just shorted, it operations, the computer dealer will put a big mark- may be hot or show evidence of burning. Visually up on his parts prices to improve the profitablity of inspect the motherboard and peripheral cards under his service department good lighting. Look for such things as ash or black There are hazardous voltages inside the Apple, marks on the components. Touch all the ICs lightly but they are all in the power supply. Nevertheless, it to see if any are hot. Be careful or you might burn is a good idea to pull the plug on the Apple anytime your finger when you get to the right one. Check that you are working inside. Never work on the power all cards, plugs, and ICs that may have been tin- supply with the line cord attached. Many of the kered with are correctly installed, not reversed, and power supply components are not isolated from the with no shorted pins. Perform the peripheral card line voltage and there are numerous dangerous volt- check, but don't leave the computer on with the age points in the power supply. clicking noise for any longer than necessary. The peripheral card check will indicate whether the The Peripheral Card Check motherboard or a peripheral card is the probable A check that should be made at an early point for cause. It can be further determined that the prob- almost any persistent symptom is to turn off the lem is not in the keyboard by disconnecting the key- Apple, remove all the cards, turn the Apple on, and board plug from its motherboard socket. see if the symptom disappears. If it does, you can If you were unable to isolate the exact problem find which card is causing the fault by turning the cause, it may be time for you to take your system to a computer on with each card installed by itself. Then dealer for repair. At this point, you will be able to you can operate the Apple, losing only the capabili- describe the symptoms to the service technicianon a ties represented by the malfunctioning card until it level which will be helpful to him. He will probably Maintenance and Core of the Apple II 10-7 Figure A02 A Power Supply With the Bottom Off. verify a short to ground exists with a multimeter accept the older ones with rivets drilled out. If you and try to isolate the short by removing ICs from the enlarge the mounting hole on an older supply to motherboard or peripheral card in groups until the make ittake a standard sized rocker switch, it prob- short goes away. You can do this yourself, but ably will not be accepted for swap out if a more beware. Even experienced technicians damage ICs serious casualty occurs in the future. While the cost or install them incorrectly on occasion. If you remove of a power supply with turn in is $90, the cost with- all the ICs from a card and put them back in. you out turn in is $300. You should, therefore, weigh the very well may create some casualties that weren't consequences before embarking on any course of there when you started. Also, the problem may be action. Also, even though Apple has been accepting more difficult than a dead short, and you might end older power supplies with the rivets removed, they up requiring a board replacement if it is toodiff icult. have not made any public announcement to that The second bad power supply symptom that can effect. Neither Quality Software nor myself can be be observed is a completely dead Apple with no held responsible for any consequences of your possi- clicking noise. This can be verified to be a power ble decision to remove the rivets and attempt to supply problem by measuring the +12, -12, +5, and -5 replace the switch. If you do make such a decision, Volt lines at any peripheral slot with a multimeter. here is a rough procedure: If the voltages are good, then a timing problem is 1.Turn the Apple off, indicated. If incorrect voltages are present, there is 2. Remove the power cord from the power supply. probablyapowersupply problem which will require 3. Disconnect the power supply plug from the a $90 swap out from a dealer. If no voltages are motherboard connector. present, you may still have a $90 swap out coming, 4. Remove the power supply (four screws through but you may only have a bad switch. Apple base plate). In this event, you have two options. You may take 5. Drill out the middle rivet on both sides of the the computer to a dealer who might verify the power supply {1/8" bit). switch is bad and replace it or who might insist on a Remove four screws from both sides and separ- $90 swap out. You may also verify the switch is bad ate top from bottom. yourself and replace it. Replacement is easier to 7. Verify switch casualty with ohmmeter. accomplish in the newer, gold colored supply. This is 8. Replace switch. because the newer supply is not riveted closed and 9. Reverse the dismantling procedure except for because theswitch isastandard sized rocker switch. installation of rivets. The switch on the older, silver colored supply is undersized and not easily found in part stores. Any DO NOT APPLY POWER TO THE POWER Apple dealer can obtain either switch from Apple SUPPLY WHILE INTERNAL COMPONENTS It used to be that Apple would not accept an older ARE EXPOSED. THE VOLTAGES INSIDE ARE supply for swap out if the rivets had been removed, VERY HAZARDOUS WHILE POWER IS but since the newer supply was introduced, they APPLIED. 10-8 Understanding the Apple Peripheral Failures damaged on three separate occasions. On two of those occasions, the LS125 failure was caused by a It is sometimes fairly obvious that the only prob- person plugging the 20-pin ribbon cable connector lem lies in a peripheral or its interface card. If every- into the controller incorrectly. The symptom was thing else works, but a printer won't print, it's that the drive was always configured for writing, pretty cut and dried. Other peripheral failures are even when the controlling program was attempting less obvious. Cards that steal ROM addressing like to read data. Booting or cataloging a disk, for exam- the firmware or RAM card areso integrated into the ple, would clobber the disk. A typical operator will overall operation that when one fails, symptoms can clobber several disks under these circumstances be the same as motherboard failures. before realizing what he is doing. He thinks he is When you are certain that a fault lies with a peri- trying to read bad disks, but he is really making pheral, there are some steps you can take to try to disks go bad by trying to read them. If you encounter determine the exact cause. First, with the computer these symptoms, try replacing the LS125 on the off, remove all the other peripheral cards to be cer- analog card of the offending drive or drives. Then tain that one of them isn't somehow causing the verify operation with disks containing non-critical problem. If that doesn't help, turn the computer off, data. This tip also pertains to most second source and give the suspect peripheral card a visual inspec- 5-1/4 inch drives available for the Apple. They gen- tion. Assuming the iCs are mounted in sockets, wig- erally use an LS125 for the same functions as theone gle them all to make sure that they're properly in the Disk II drive. seated. Verify that any plugs are properly installed. Clean the contacts of the card's edge connector with a pencil eraser or with alcohol and cotton swabs, Other Symptoms preferably the latter. Reinstall the card and verify There are no error lights built into the Apple, but that the problem still exists. You can perform the there are some very distinct error indications which same steps on any cards mounted in the peripheral you can interpret if you understand the Apple. itself. First, does it beep when you turn it on? The beep Just the act of removing a peripheral card and isn't made by some oscillator. It's made by pro- installing it will often cure many problems, at least grammed control of the speaker by the MPU. It temporarily. Some lower quality contact materials means that a power-up RESET was generated, the will tend to make poor electrical contact when the 6502 works and is capable of address bus and data temperature rises. Just wiggling the card can cure bus control and data bus reception, the F8 ROM the problem, but be sure to wiggle it with the com- works, timing works, page and 1 of RAM work, puter turned off. Cards with gold plated contacts and a good portion of the address decoding circuitry are much less likely to cause this sort of trouble. works. If you can get to the monitor, you can try the Another thingyou can try is to run the peripheral following RAM test: in a different slot than its ordinary one. assuming it is not slot dependent. If it is slot dependent, try running another peripheral in that slot, the object *1 CTRL-P (ENABLE PRINTER) being to prove there is nothing wrong with the slot's *C050 C0S3 C054 C057 N 265:FF N 266<265. signals or connections. If the problem persists, you BFFEM 266<265.BFFEV 265:0 N 266<265-BFFE may as well start calling computer dealers to find M 266<265.BFFEV 34:14 (CR) one who will work on your peripheral. If you cause a malfunction by removing a card with power applied, suspect that ICs connected to Please note that there is a space between the ending the IN HIBIT' line are burned out. Tb is includes the "34:14" and the RETURN. These keystrokes, when 74LS09 on a firmware card or a RAM card. You can entered from the monitor, will enable the Slot 1 burn up these LS09s by removing any card from any printer and then take turns filling RAM with ONEs slot with the power on and accidently shorting pin then ZE ROs. It verifies the transfer of each byte and 32 (INHIBIT') to pin 33 (-12V). If you are less lucky, prints out any errors. RAM locations $265 through you might short pin 50 (+12V) to pin 49 (DO). In the $BFFF are checked out, and the test can be cycled latter instance, vou may possibly destroy numerous indefinitely with every error recorded on the prin- ICs. ter. The video display gives a visual indication that Here is one last tip for a special situation. I have the test is in progress. It can be terminated by press- known the LS125 on the Disk II analog card to be ing RESET. Maintenance and Care of the Apple II 10-9 It is important to verify the errorless operation of the presence of the timing generator signals RAM because a random error in niemory transfer using a logic probe or oscilloscope. Refer to Fig- can cause seemingly illogical program crashes. ures 3.2, 3.8, and 3.9, and replace possible mal- Most 6502 programmers could write a good RAM functioning ICs if you have spares. diagnostic program and save it on disk, but what 2. No beep, display window present. Timing is good would it do if a RAM casualty prevented the good, but the computer does not execute a stored operation of DOS? In fact, what good are any disk sequential program. Use a logic probe or oscil- based diagnostics if any casualty prevents the oper- loscope to verify whether or not signals are ation of DOS? This is why the little monitor based normal atali pins on one of the peripheral slots. RAM diagnostic can be pretty handy. Pay particular attention to the address bus, The second big indicator of the nature of a prob- data bus. INHIBIT, RESET', and other 6502 lem is the video display. The scanning of RAM for control lines. The condition of the peripheral video output is done independently of the MPU, the slot signals should guide you to possible causes. address bus, and the data bus. The only common 3. Beep, no display window. Most of timing is bond is timing. The address bus, data bus, MPU, good, but check LDPS' and LD194 with a logic RAM and ROM can all be burned to a crisp, and you probe or oscilloscope. Also check the video will still have the display window on the screen. The scanner outputs and the BLANKING, SYNC, contents would be jibberish, but the window would PICTURE, and VIDEO output signals in the be there with its black margins on all sides. The video generator. presence of the window means that timing, the video 4. Beep, window present, programs crash. The scanner, and most of the video generator are computer executes programs but gets into working. trouble in certain cases. Turn off the computer The four possible combinations of the two opera- and remove and reinstall your firmware card or tional indicators can greatly narrow the field of pos- RAM card to see if that is the problem. Try sible causes of a given problem. The following operating with all cards removed except the interpretations of symptoms should help. In all firmware card or RAM card as well as doing the cases, perform the peripheral card check, visually normal peripheral card check. Attempt the inspect the motherboard, and verify that all ICs are monitor based RAM diagnostic that was shown properly seated. Refer to the foldout in the back of earlier. Verify various ROM locations using the the book entitled "Motherboard Component Loca- monitor. It is helpful to have the Applesoft and tions" to see which functional areas are affected by Integer programs stored on disk. If disk I/O various ICs. works, you can load either program into RAM and verify your firmware using the VERIFY 1. No beep, no display. This isone dead Apple and feature of the monitor. Check all the signals on a power supply problems are the probable cause. peripheral slot with a logic probe or oscilloscope. This can be verified by measuring the +5V, -5V, +12V, and -12V supplies at any peripheral slot Intermittent problems are the bain of all comput- with a multimeter. If any of the voltages is er servicemen as well as computer users. They are incorrect, read the Povv^er Supply Problems often dependent on the temperature and they are section of this chapter for an indication of how to often the product of a mechanical defect like imper- proceed. If the power supply voltages are good, fect electrical contact. They are sometimes impossi- timinggenerator problems are indicated. Verify ble to repair in a cost effective way and the best Figure 10.3 Some People Just Shouldnl Handle iCs. 10-10 Understanding the Apple I thing that can be done in this instance is to swap out faults in a digital computer. It is good for Apple the defective assembly at a computer dealership. owners to possess this level of understanding, and it There are two tricks which can be used to make the is also good for them to locate computer dealerships problems become more regular so the causes can be which employ service personnel with this level of identified, One is to subject the equipment to a understanding. severe mechanical jolt, like Humphrey Bogart in The African Queen. This will tend to prove or dis- prove the notion that there is a mechanical problem. A Note of Thanks Less drastically, you can flex the motherboard and In preparing this chapter, I benefited from being reseatsuspectperipheral cards and ICs, The second allowed to spend a day in the excellent repair trick is to raise and lower temperature to make the department at Rainbow Computing, 9719 Reseda problem occur. "Cold problems" can be made to Boulevard, Northridge, CA 91324. I was able to appear by spraying cold spray, available at elec- discuss Apple maintenance with Roger Wilbur and tronic stores, on suspected areas. "Hot problems" Eric Waller, who are experts at repairing Apples, can be made to appear by directing a heat gun, or, and I was also allowed to assist them in some main- less effectively, a hair dryer at the suspected area. tenance tasks. Eric has been working on Apples so There are no doubt many symptoms not covered long that when he first called Apple Computer by the guidelines that have been given here. The about a hardware problem, the phone was answered intention was only to give some helpful hints, not a by Steve Job's mother, who called Steve Wozniak in full blown maintenance aid. Serious readers of this from the garage to answer the phone! While Roger book, however, should be in a very good position to and Eric are not responsible for my interpretations correctly interpret the symptoms of any malfunc- of our discussions, they both contributed measura- tions which occur in their machines. In the absence bly to my understanding of Apple maintenance of sophisticated diagnostic aids, full understanding procedures. My thanks to them and to the manage- of operation is the most important asset in isolating ment of Rainbow Computing. glossary address bus. A multi-line electrical eonnection assembler. A program which converts an assembly from the MPU to various devices in a micro- language source file into a machine language computer by which the MPU specifies the loca- object file, tion with which it will communicate. The assembly language. A language which specifies address bus in the Apple is 16 lines and the machine language commands on a one to one MPU can specify 65536 different locations for basis but in which the computer manages many data transfer. of the details of generating machine language ampere, amp. The unit of measure of electrical code. current, bank switching. A method of accessing more analog. Pertaining to quantities which vary through memory locations than the norma! addressing a continuous range such as a voltage which range an MPU will allow. In bank switching, ranpfes from +5V to -5V. See digital. the MPU is allowed by hardware to address AND gate. A logic gate from which the output will more than one memory bank using the same be true if and only if all of its inputs are true. address range. An example is the firmware Applesoft BASIC. The floating point BASIC inter- card, which allows the MPU to access Applesoft preter language written for the Apple by or Integer BASIC at the $DO00-$FFFF address Microsoft Corp. and distributed by Apple Com- range. puter, Inc. BASIC, Beginners All-purpose Symbolic In- ASCII, American Standard Code for Informa- struction Code. The primary high level lan- tion Interchange. A code for representing guage used in personal computers. It was numbers, letters, and symbols in computers. originally developed at Dartmouth College as a ASCII is used in the Apple for representing text training language, and has been developed into in the keyboard input, text screen map, printer a powerful and usable tool by the microcom- output, and DOS text files. puter industry. 2 Understanding the Apple binary numbering system. A system based on impact point on the screen is controlled by powers of 2, as opposed to powers of 10 in the deflecting the electron stream via an electro- decimal system. The two symbols of the binary magnetic or electrostatic field. The picture tube system are and 1. See hexadecimal. in a television is a CRT. bit. A two state unitof information. The information central processing unit, CPU. The electronic is in one state or the other— on or off, for assembly which performs the arithmetic and example. logical operations of a computer. bomb, crash. When a program is bombed or when it chip. See integrated circuit. simply crashes, it loses control of the computer color burst. In a television color video signal a short , and must be restarted and possibly reloaded. It sample of the color reference signal which is particularly likely for a program to crash occurs just after the horizontal sync pulse. when it is first written and still has bugs in it. From the color burst, a television or monitor can bootstrap. The process by which a computer loads reconstruct the color reference. large operating systems using a small firmware compiler. A program which converts high level program, language source programs into machine lan- buffer. (1) A temporary holding area in memory in guage object programs. which data resides before, during or after complement. The complement of a binary number transfer operations. (2) Any hardware device is a binary number in which binary I's replace which provides electrical isolation between two and O's replace I's in the original number. O's, electrical points or sets of points. Forexample, UOlOisthecomplementofOOlOl. litis. A multi-line electrical connection which dis- complementary colors. Pertaining to the Apple, tributes an associated group of signals among colors produced by signals 180 degrees out of two or more communicating devices. phase with each other— HIRES green and bus driver. A group of amplifiers which allow a HIRES violet for example. group of signals to control a heavily loaded bus. composite video. A complex video display signal The driver gives electronic leverage to the con- containing horizontal and vertical sync, lumi- trol signals so they can "drive" many devices. nance and chrominance signals, and a color byte. A group of 8 bits. The 6502 is an 8-bit MPU, burst. The video output of the Apple can loosely thus, it transfers and manipulates data one byte be called composite video. at a time. current. The motion of charged particles due to BYTE FLAG. A term used in this book to describe voltage. Generally, in electronics, the move- the sync bit which leads groups of eight bits in ment of electrons through conductive paths. the Apple DOS data formats. Current is measured in amperes. card cage. A row of receptacles into which printed data bus. A multi-line electrical connection over circuit cards with edge connectors are plugged. which data passes between the MPU and var- The receptacles are wired in the back in a ious devices in a microcomputer. The data bus method which serves the design purpose of the in the Appie is 8 lines, so one byte can be trans- cage. ferred per MPU cycle. cascaded. Being arranged in stages such that each debug. To perfect a program by removing the bugs stage depends on the preceding stages. We per- (defects) from it. form counting and arithmetic in a cascaded numbering system, utilizing carry and borrow decimal numbering system. The system by which processing. In a computer, logic devices can be we normally represent numeric quantities. Ten cascaded to form a larger device conceptually symbols (0-9) represent quantities, while the similar to the devices which make it up. For position of each symbol in a number represents example, four 4-bit counters can be connected in the significance or weight of that symbol. The cascade to form a 16-bit counter, as is the case in weight increases by powers of ten as position the Apple's video scanner. shifts right to kft. cathode ray tube, CRT. A device in which a screen digital. Pertaining to quantities which vary in dis- display is created by a high velocity stream of crete increments such as integer numbers. See electrons striking a phosphor coating. The analog. Glossary 3 DIP, dual in line package. A type of IC structure flux. Lines of force used to represent a magnetic in which the pins run lengthwise in two parallel field. The linesof force provideamenta! picture rows. All ICs in the Apple are DIP ICs. for visualizing the substance of a magnetic disassembler. A program which attennpts to inter- field. In theoretical calculations, field strength pret data in memory as a machine languag-e is proportional to flux density. program and converts it to an assembly lan- font, character. Patterns of ones and zeroes stored guage listing. A firmware disassembler in the in memory which represent the dot image of dot Apple can be called via the monitor "L" matrix text or graphics characters. command. gate. A logic curcuit having one output and more DMA, Direct Memory Access. Direct access to than one input. Like a gate in a fence, the logic memory from devices other than the MPU. In gate allows intelligence to pass when the inputs the Apple, data is directly accessed from memory are correct. AND gates and OR gates are two by the video scanner/video generator combina- types of gates. When an input activates a logic tion without passing through the MPU. Addi- device, it is said to "gate" it on. tionally, a card in any peripheral slot can directly access memory and other motherboard general purpose computer. A computer whose stored program may be altered to change its devices by pulling the DMA' line low. purpose. This is normally achieved by storing dot matrix. A method of forming displayed or the program in random access, read/write printed characters in which individual dots at memory. See special purpose computer. fixed positions in a matrix are displayed as necessary to form the characters. hacker, hack, computer hack. A person who builds or modifies computer electronic assem- dynamic memory. Memory in which data will blies, mostly for fun. bleed off and lose its validity if it is not regularly refreshed. RAM in the Apple is dynamic and handier. A program designed to handle a specific must be refreshed every 2 milliseconds. occurance such as an interrupter system reset Easter egging. A troubleshooting method where hardware. The components and assemblies of possibly failed components or assemblies are which a computer and its peripherals are made. replaced with known good units. Easter eggers Hertz, Hz. A measurement of frequency which can sometimes repair equipment they know used to be referred to more sensibly as cycles little or nothing about. per second or cps. exclusive OR gate. A logic gate from which the output will be true if and only if at least one, but hexadecimal numbering system. A system based on powers of 1 6, as opposed to the powers of 1 in not all, inputs are true. the decimal system. The 16 symbols of the hexa- firmware. Programs and data stored in ROM, decimal system are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, Firmware determines many of the operational C. D, E and F. features of the Apple 11. flag. A memory location used by a program to sig- high level language. A computer language whose nify some sort of status. A common way to use a commands correspond to machine language routines. High level languages are easy to use location as a flag is to set or reset its most signif- icant bit. and powerful. The predominate high level lan- guage of the Apple II is Applesoft interpreter flip-flop.A 1-bit storage device capable of storing BASIC. data in response to its logical inputs and a clockpulse. Registers of older computers were horizontal scan. The movement of the electron comprised of a number of flip-flops with a sub- beam in a television from left to right across the stantial amount of associated logic gating. face of the CRT. float. If all devices capableof controlling the voltage impedance. The quality of hindrance of an electri- on an electrical conductor are isolated from the cal device to current flow at a given signal conductor, the conductor is said to float. In the frequency or range of signal frequencies. Impe- Apple, all conductors on the address bus or data dance, like resistance, is measured in ohms. In bus can be isolated from control, so these buses computer three-state logic, the three states are sometimes float. Logic which creates this condi- high voltage, low voltage, and high impedance tion floats the bus. (high isolation). 4 Understanding the Apple II input/output, I/O. The process of moving intelli- LSTTL, Low Powered Schottky TTL. A type of 1 gence to and from a computer, as in keyboard TTL which provides a good compromise of high input, video output, disk I/O, and printer output. speed and low power consumption. Most Apple Integer BASIC. The original BASIC interpreter TTL is LSTTL. The name comes from Sehottky- language supplied with the Apple 11. It was Barrier clamping and coupling diodes inside written by Steve Wozniak, the principle designer thelC. of the Apple II computer. machine cycle. A clocked cycle of an MPU. The integrated circuit, IC, chip. An electronic compo- machine cycle of the 6502 in the Apple is the nent into which the functions of many other period between high to low transitions of the components are integrated. IVpically, a chip PHASE 2 clock. will be the equivalent of thousands of diodes, machine language. The language of the central transistors, and resistors. interface. Communication circuitry between two processor of a computer (6502 machine lan- I guage in the Apple). devices, such as the interface between an Apple and a printer. mainframe computer. When computers were physically large, the structure which held the interlacing. A technique in which alternating tele- central processorwas called the mainframe. vision vertical scans are displaced from each Computers which have such separate struc- other. This increases vertical resolution without tures are mainframe computers. introduction of screen flicker. Megahertz, MHz. One million Hertz. One million interpreter. A program which interprets stored cycles per second. sequences of high level commands and executes them via fixed machine language subroutines. memory cell. A portion of memory capable of stor- The Apple II is supplied with Applesoft and ing one bit of information. Integer BASIC interpreters. memory mapped I/O. A method of I/O implemen- interrupt. A signal or instruction which, when tation in which addresses which might other- active, causes a computer to interrupt sequen- wise be assigned to memory are assigned to I/O tial program execution and branch to an inter- functions. In the Apple, addresses $C000 to rupt handling program. The 6502 has four types $CFFF are assigned to I/O functions. of interrupts: RESET, the Non-Maskable In- memory mapped video. A method of computer terrupt, the Interrupt Request, and the BREAK video display generation in which a map of the instruction, screen display is placed in memory. In the I/O port. The conceptual entry point through which Apple, the MPU builds the screen map in data flows in I/O operations. For example, in memory, and the memory map is independently the Apple, $C00O is the address of the keyboard scanned for video processing by the video input port, and keyboard data is loaded from scanner. address $0000. microprocessing unit, MPU, microprocessor. joysticlc. A device which converts the two dimen- The one chip central processing unit of a micro- sional motion of a lever into measureable elec- computer. This definition is a good subject for trical equivalents of the X and Y components of an argument. the motion. Normally an Apple joystick will be made of two potentiometers, one which responds microsecond, ^ec. One millionth of a second. One to y-axis motion of the lever and one which thousand nanoseconds. responds to x-axis motion. millisecond, msec. One thousandth of a second. One least significant bit, LSB. The bit of a binary word thousand microseconds. or number which has the least weight or signifi- modulate. To vary a high frequency signal as a cance. The rightmost bit of a binary number. function of a lower frequency signal. The video linear IC. A type of IC used in linear amplification output signal of the Apple can be used to ampli- and other analog functions, as opposed to digital tude modulate a television frequency signal, switching functions. Some linear ICs used in the and that modulated signal can be received by a Apple are 555, 556, and 558 timers and the 741 television set. The high frequency signal carries cassette input amplifier. the video to the TV and is called an RF carrier. Glossary 5 monitor. A program which provides for communi- aVOM (Volt-Ohm Meter) or multimeter which cation with a computer at a very basic level. performs other functions besides resistance Common capabilities include program start up, measurement. memory modification, and monitoring of com- op code, operation code. The part of a machine puter registers. language instruction which specifies the com- monitor, video. An electronic device which gener- mand which is to be performed. The op code of ates a display fronn a video input signal. It is not each 6602 instruction is the first byte of that capable of television radio frequency signal instruction. reception. operand. The entity operated on by a machine lan- monochrome. Of one color. A name for black and guage instruction. In "LDA $00", the operand is white television which accurately describes the the contents of memory location 0. In "SEC", the fact that there is only one color tone displayed. operand is the carry bit of the 6502 Status MOS, integrated circuit. A chip using metal-oxide Register. semiconductor technologj'. MOS ICs in the OR gate. A logic gate from which the output will be Apple include the 6502. ROM. and RAM. true if. and only if, any of its inputs are true. most significant bit, MSB. The bit of a binary word oscilloscope. A test instrument which produces a or number which has the greatest weight. The cathode ray tube display of a test voltage, plot- i leftmost bit of a binary number. motherboard. A printed circuit card into which ted against time, PAGE. (1) The 6502 memory addressing range of smaller printed circuit cards can be plugged. $10000 bytes is divided up into $100 pages of multimeter. An instrument which can measure $100 bytes each. $000-$0FF is PAGE 0; $100- electrical voltage, resistance, or current, $1FF is PAGE 1; etc. (2) There are four areas of memory wh ich can be scanned for video output multiplex. To combine multiple sources of informa- in the Apple. These are TEXT/LORES PAGE 1, tion onto one line. There are numerous exam- ples of time-multiplexing in the Apple in which TEXT/LORES PAGE 2, HIRES PAGE 1, and several possible signals are switched onto a ine, I HIRES PAGE 2. In any screen mode, the PAGE 1 memory map may be selected for scanning via one after the other. programmed reference to $C054, and the PAGE NAND gate. A logic gate from which the output 2 memory map can be selected by reference to will be false if, and only if, all of its inputs are $C055. true. parallel data transfer. Simultaneous transfer of n nanosecond, nsec. One billionth of a second. bits of data on n lines, as in 8-bit parallel data negative logic. A system of logic analysis in which transfer between the MPU and memory in the the high voltage state is considered to be false or Apple. zero, and the low voltage state is considered to peripheral slots, peripheral bus, Apple bus. The be true or one. See positive logic. eight slots in the back of the Apple and their NOR gate. A logic gate from which the output will associated electrical connections. be false if, and only if, any of its inputs are true. phase. The angular position of a cyclical event ref- object file. The result of an operation which pro- erenced to some event of the same frequency. cesses a group of data and stores the result else- For example, HIRES violet video is 180 degrees where. In assembly language processing, the out of phase with HIRES green video, assembly language source file is assembled into pipelining. A process by which program execution a machine language object file. speed is increased in the 6502. In pipelining, the octal numbering system. A system based on pow- next instruction's op code is fetched during the ers of 8, as opposed to the powers of 10 in the last execution cycle of instructions which do not decimal system. The eight symbols of the octal write to the data bus. system are 0, 1, 2, 3, 4, 5. 6, and 7. positive logic. A system of logical analysis in which ohm. The unit for measuring electrical resistance the high voltage state is considered to be true or and impedance. one, and the low voltage state is considered to be ohmmeter. A device which measures electrical false or zero. The Apple and most modern com- resistance. Usually resistance is measured with puters use positive logic. See negative logic. I 6 Understanding the Apple potentiometer, pot. A mechanically variable resis- resistance. The quality of hindrance of an electrical tor. Typically, resistance will be proportional to device to direct current flow. Resistance in a the shaft rotation of the pot. The Apple paddles current path may be controlled by installing are pots. fixed or variable resistors. The unit of meas- power supply. An electronic assembly which con- urement of electrical resistance is the ohm. verts an AC (alternating current) line voltage to RF modulator. A device which varies a high fre- usable DC (direct current) power. The Apple quency signal as a function of a lower frequency power supply converts household power to +12V, signal. See modulate. -12V, +5V, and -5V referenced to ground. ROM, read only memory, non- volatile memory, printed circuit card, PC board. A thin card made non-alteraiale memory. A type of memory of an insulating material upon which electronic which the computer cannot write to or other- connponents are mounted. The component wir- wise alter. It holds programs and data which ing is "printed" on the board. The printing pro- are always available when power is applied, cess involves starting with a card completely such as BASIC and the monitor in the Apple. coated with conductive metal, then etching away everything but the desired conductive serial access memory. Memory which can only be parts using photo-chemical methods. accessed by sequencing through locations until the correct location is found. High speed mag- program counter, A counter in a computer which netic tape and bubble memory are examples of contains the memory address of the instruction serial memories. See random access memory. being executed. The 6502 has an internal 16-bit program counter. serial data transfer. Ti-ansfer ring data one bit at a propagation delay. The time it takes for a signal or time over a single line, as in the shifting of text voltage to travel between two points. In logic patterns to the PICTURE signal. gating, the time required for an output to software. Programs and data stored in RAM and on respond to a change in associated inputs. storage media such as disks. RAM, alterable memory, read/write memory. source file. A source of data for data processing. In Memory in which a computer can store or access assembly language processing, the assembly data. language source file is assembled intoamachine random access memory. Memory in which any language object file. location can be accessed at will, such as the special purpose computer. A computer whose RAM and ROM in the Apple. See serial access function cannot be changed by altering a stored memory. program. The functions of a special purpose raster. The pattern of scan lines produced on the computer may be hard wired, or the computer screen of a monitor or television. The Apple ras- may execute fixed programs stored in ROM. ter contains 262 lines with no interlacing. stack. In microcomputers, an area of memory set read cycle. A machine cycle in which the MPU aside for temporary storage and subroutine receives data from the addressed location via return link information. In programming, the the data bus. stack is conceptually similar to a stack of cards refresh. (1) The process of renewing data in which can be drawn from or discarded to, one dynamic memory before it bleeds off. (2) The card at a time. process of renewing an image on a cathode ray static memory. Memory which requires no refresh- tube by rescanning the image before it fades away. ing to retain its data, such as the static ROM in the Apple. register. A temporary storage device which holds more than one bit of information. It will nor- status register. A register in a central processor mally serve some special logic purpose. Exam- which contains control information. In the 6502, ples include the 6502 internal registers and the the status register contains indicatorsof the log- data register of the Disk II controller. ical results of various executed commands. relocatable program. A program which does not strobe. A short pulse that performs a triggering or have to be in one specific memory range to be clocking action. Strobes in the Apple include properly executed. It can be relocated to differ- RAS', CAS', the C040 STROBE', and the key- ent memory areas for execution. press strobe from the keyboard. Glossary 7 television sync. That part of the television signal video. A signal which can be used to control the which synchronizes thescanningof the electron energy of the electron beam of a CRT. thus con- beam in the CRT. It includes horizontal and trolling display intensity, as in television video, vertical sync. radar video, and oscilloscope video. In television tri-state logic, three-state logic. A logic system in processing, the combination of picture, sync, which there are three states: high voltage, low and color information is commonly referred to voltage, and high impedance. Devices connected as video. to the Apple data bus have tri-state outputs so volt. A unit for measuring voltage. Voltages of +12, the various devices are able to share control of -12, +5, and -5 volts are distributed throughout the data bus. the Apple. troubleshoot. To isolate and repair the casualties in voltage, electromotive force, EMF. A force of a failed piece of hardware, nature which, when present, causes charged TTL, Transistor Transistor Logic. The logic fam- particles to move. The force which causes elec- which most general purpose ICs in the ily to tric current. Voltage is measured in volts. Apple belong. Both the inputs and outputs of TTL chips are connected to transistors inside wetware. A gray matter found within the cranium the chip. As opposed to MOS devices like RAM, of most humans. ROM. and the 6502. TTL circuits are made wire-OR, collector-OR. A low level OR gate using bipolar technology. formed by wiring various signals together. The underware. A substitute for firmware used by RESET', IRQ'. NMT, INHIBIT', DMA', and some of Apple's competitors to cut costs. USERl' signals of the Apple II are examples of vector. An address or jump instruction stored in a wire-OR connections. Any peripheral card may memory location which contains program flow bringanyof the wire-OR lines low, but cards not information in case of certain events. An exam- bringing a line low must present a high impe- ple is the interrupt vectors stored in high dance to that line. If no per ipheral card is bring- memory in a 6502 based computer. ing a wire-OR line low, a 1000 ohm motherboard resistor will pull the line high. vertical scan. The movement of the electron beam in a television down the face of the CRT. In the write cycle. A machine cycle in which the MPU Apple. 262 horizontal scans occur during every sends data to the addressed location via the data vertical scan. bus. appendix A References Apple Computer, Inc, Apple IF Reference Manual. January 1978. Apple Computer, Inc, Applesoft II BASIC Programming Reference Manual. 1978. Apple Computer. Inc. The Applesoft Tutorial. 1979. Apple Computer, Inc. (Christopher Espinoaa). Apple II Reference ManuaL1979. Apple Computer, Inc. (orig-inallyby Phyllis Cole and Brian Howard). The DOS Manual, 1980. Apple Computer, Inc. (Allen Watson). Apple II Reference Manual for lie Only. 1982. Bishop. Bob. "Have an Apple Split." SOFTALK, p. 54, Oct. 1982. Brown, Chris and Maloney, Eric."FCCTakes Aim Against RFI Polluters." Merocompuimfif, p. 30, April 1981. Ciotti, Paul. "Revenge of the Nerds." California, p. 73, July 1982. Derfler, Frank J. "Trying to Live in Harmony with Ro-rmonics." MicrocomputiTig, p. 36, April 1981. Devry Institute of Technology. Electronics Technology. Volumes 7 and 10, 197 1 This textbook . was the primary source of information relating to television. Gayler. Winston D. The Apple 11 Circuit Description. Howard W. Sams & Co, Inc., 1983. Lancaster, Don. TTL Cookbook. Howard W. Sams & Co, Inc., 1974. Leventhal, Lance A. 6502 Assembly Language Programming. OSBORNE/McGraw-Hill, 1979. Mazur, Jeffrey. "HARDTALK." SOFTALK, p. 46, July 1982. Concerns EPROM. Mazur, Jeffrey. "HARDTALK." SOFTALK, p. 168, Aug. 1982. Concerns EPROM. Mazur, Jeffrey. "HARDTALK." SOFTALK, p. 208, Sept. 1982. Concerns disk drives. Moore, Robin B. "Graphics Character Generator." Microcomputing, p. 108, Aug. 1980. A-2 Understanding the Apple MOS Technolo^, Inc. MCS6500 Microcomputer Family Hardware ManuaL 1976. Osborne, Adam. An Introduction to Microcomputers, Volume 1, Basic Concepts. Adam Osborne and Associates, 1976, Osborne, Adam and Kane, Gerry. Osborne 4 & 8 bit Microprocessor Handbook. OSBORNE/ McGraw-Hill. 1981. Slppl, Charles J . Microcomputer Dictionary. 2nd edition, Howard W. Sams & Co, Inc., 1981. Synertek, Inc, SY6500/MCS6500 Microcotnputer Family Programmimg ManuaL Aug. 1976. Synertek, Inc. Applications Information AN2, SY6500 Microprocessor Family, Microproces- sor Product.?. Oct. 1981. Texas Instruments, Inc. Designing imth TTL Integrated Circuits. 1971, White, Robert M. "Disk-Storage Technology." Scientific American, p. 112, Aug. 1980. Williams, Richard. "How to Use the Hooks." MICRO, p. 30:7, Nov. 1980. Worth, Don and Lechner, Pieter. Beneath Apple DOS. Quality Software, 1981. Wozniak, Stephen. "The Apple II: System Description." BYTE, p. 34, May 1977. Wozniak, Stephen. "SWEET16: The 6502 Dream Machine." BYTE. p. 150. Nov. 1977. Wozniak, Stephen. Speech made at Applefest. Anaheim, CA, April 17, 1983. Component Data: Fairchild. MOS Memory Data Book. 1981. Fujitsu Microelectronics. MOS I638i-Bit Dynamic Random Access Memory. July. 1981. General Instrument Corp. Microelectronics Data Catalog. 1982. General Instrument Corp. ROM 3. no date. Hitachi America, Ltd. IC Memories, no date. Jameco Electronics. 198S Catalog, p. 12. MOS Technology, Inc. 6,500 Microprocessors. March 1980. Motorola Semiconductors. MC.U70 Floppy Disk Read Amplifier System. 1978. National Semiconductor. MM5740 90-Key Keyboard Encoder: 1973. National Semiconductor. Interface Databook. 1980. National Semiconductor. Memory Databook. 1980. National Semiconductor. Logic Databook. 1981, National Semiconductor. Liwmr i>ata6ooA:. 1982. Rockwell International. R8500 Microcomputer Systein Data Sheet. Rev. 4, Nov. 1981. Synertek. 1981-1982 Data Catalog. Texas Instruments, Inc. The TTL Data Book for Design Engineers. 1976. United Technical PuhUcations. IC MASTER. 1981. appendix B Trademarks The following is a listof Registered Trademarks referred to in the \extoi Understanding the Apple II. Apple Apple Computer, Inc. Apple II Apple Computer. Inc. Apple II Plus Apple Computer, Inc. Apple He Apple Computer, Inc. Applesoft Apple Computer, Inc. CP/M Digital Research, Inc. Donkey Kong Nintendo Microsoft Microsoft, Inc. Softcard Microsoft, Inc. TRI-STATE National Semiconductor Corporation Z80 Zilog, Inc. appendix C 6502 Data j In attempting to analyze Apple timing, it is dis- reprinted with the permission of Rockwell Interna- couraging to f nd that the three 6502 manufacturers i tional Corporation, Copyright 1981, all rights have different specifications, even though the reserved, Rockwell's timing specification charts are MSC6502, R6502, and SY6502 should all perform followed by the author's compilation of the 1 MHz identically. It is even more discouraging to find that timing charts of the Synertek, Rockwell Interna- the specifications are well beyond the range of typi- tional, and MOS Technology data sheets. Every cal operations. I therefore feel that Figure 4.5. attempt was made to make the data in this compila- which shows some measurements made in an tion faithfully represent the data contained in each SY6502 in an Apple, is a more realistic indicator of manufacturer's data sheet. The final page of this 6502 timing than the manufacturers' data sheets. appendix is a layout of the author's which shows the Nevertheless, a partial reproduction of Rockwell execution periods of the various 6502 instructions. International's data sheet is given here. This data is Appendix C-2 R6500 Microcomputer System DATA SHEET R6500 MICROPROCESSORS (CPU) SYSTEM ABSTRACT FEATURES The 8 bit R6500 microcomputer iystem is produced with N- Single -t-BV supply Charnel. Silicon Gale lechnoiogy Its performance speeds are N channel, silicon gate, depletion load technology etihianced hv aduarced iystem architecture. This inoouative Eight bit parallel processing architecture results in smaller chips - the semiconductor threshold 56 Instructions is costeffectivitv. System cost-effect ivitv is further enhanced by Decimal and binary arithmetic providing i family of 10 software-compatible microprocesior Thirteen addressing modes (CPU) devices, described in this document. Rockwell also pro- True indexing capability vides memory arvd microcomputer jysiem— as well as low-cost Programmable stack pointer design aids and documentation. Variable length stack Interrupt capability Non-maskabJe interrupt R6500 MICROPROCESSOR (CPU) CONCEPT Use with any type of speed memory 8 bit Bidirectional Data Bus Ten CPU devices are awailable. All sre softtAiare-compatible. Addressable memory range of up to 64K bytes Thev provide options of addressable memory, interrupt input. "Ready" input on-chip clock oscillators and drivers. All are bus-compatible Direct IVIemory Access capability with earlier gefieraiion microproceijori like the M6&00 devices. Bus compatible with M6S00 1 MHj. 2 MHi. and 3 MHi versions The family includes six microprocessors wuh on-board dock Choice of external or on-chip clocks oscillators and drivers and four microprocessors driven bv external On-the chip clock options clocks. The on-chip clock versions are aimed at high oerformaflCfip - External single clock input low cost applications where single phase inputs, crystal or RC - Crystal time base input inputs provide the time base. The emernai clock versions are Commercial and industrial temperature uersions geared ior multiprocessor system applications where maximum Pipeline architecture timing control is mandatory All R6S00 microprocassofs are also available in a variety of packaging (ceramic an<4 pfasticl. operating frequency (1 MHi, 2 MH2 and 3 MHii and temperature (commercial and IndustfiaM versions. MEMBERS OF THE R6500 MICROPROCESSOR (CPU» FAMILY Microprocessors with Internsl Tvi/o Phase Clock Generstor Ordering Information Modtl Addressable Memory Order Number: R65XX R6502 6AK Bytes R6503 4K Bytes Temperature flange: RSSCM 8K Bytes No Suffix = QOC to +70°C RSSOS 4K Bytes E = .40«C 10 +85°C R6506 4K Bytes (Industrial) R6507 8K Bytes — ' Package: C - Ceramic Microprocessors witlt Edtemal Two Phase Clock Input P = Plastic - Frequency Range: McKial Addressabta Memory No suffix - MHt 1 A = 2lWlHz R6512 64K Bytes 8 = SfVlHi R6513 4K Bytes R6514 3K Bytes ' Model Designator: R6S1S 4K Bytes XX « 02, 03,04, 15 C-3 Understanding the Apple R6500 Signal Description Clocks (0^, <>_i Nan-Maskable Interrupt INMI) The R651X requires a two phase non-oyarlapping clock that runs A negative going edge On this input requests that a non-rn askable at the V-- voltage level. interrupt sequence be generated within the microprocessor. The R650X clocks are supplied with arrinternal clock generator. NMI is an unconditional interrupt. Following completion of the The frequency of rheSe docks is externallv controlled. current instruction, the sequence of operations defined for IRQ will be performed, regardless of the state interrupt mask flag. The Addren Bus IA0-A15I yector address loaded into the program counter, low and high, are These outputs are TTL coinpailble, capable of driving one standard locationsFFFA and FFFB respectively, thereby transferring pro- TTL load and 30 pF. 1 gram control to the memory vector located at these addresses. The instructions loaded at these locations cause the microproc- Data Bus (OO-D?) essor to branch to a non-maskable interrupt routine in memory. Eight pins are used for the data bus. This is a bidirectional bus, NMI also requires an external SKHregister to V-,_ for proper transferring data to and from the device and peripherals. The out- wire-OR operations. puts are tri-state buffers capable of driving one standard TTL load Inputs IRQ and NMI are hardware interrupts- lines that are sam- and 130pF. pled during 0^ (phase 2) and will begin the appropriate interrupt Data Bus Ertable (DBE) routine on the 0. {phase 1) following the completion of the cur* rent instruction. This TTL compstibie input allows external control of the tri-state data output buffers and will enable the microprocessor bus driver when in the high state.In normal operation QBE iArould be driven S«t Overflow Flag (S.O.I by the phase two i0j) clock, thus allowing data output from A negative going edge on this input sets the overflow bit in the microprocessor Only during 4>2- During the read cycle, the data Status Code Register. This signal is sampled on the trailing edge of bus drivers are interriialtv disabled, becoming essentially an open circuit. To disable data bus drivers externallv. DBE should be held 01 and mtAit be externally synchronized. low. SYNC Ready (RDY) This output line is provided to identifv these cycles in which the This input signal allows the user to halt or single cycle the micro- microprocessor is doing an OP CODE fetch. The SYNC line goes processor On all cycles except write cycles. A negative transition high during 0. of an OP CODE fetch ar>d stays high for the to the low state during or coincident with phase one (0.) will halt remainder of that cycle. If the RDY line is pulled low during the the microprocessor with the output address lines reflecting the 0.| clock pulse in which SYNC went high, the processor will stop current address being fetched, (f Ready is low during a write in its current state and will regain in the State until the RDY line cycle, it is ignored until the following read operation. This con- goes high.In this manr^er, the SYNC signal can be used to control dition will remain through a subsequent phase two (0_) in which RDY to cause single instruction execution. the Ready signal is tow. This feature allows microprocessor inter- facing with the low speed PROMs as well as Direct Memory Access (DMA). Rsnl Intarrupt Raquest (IRQ^ This input is used to reset or start the microprocessor from a This TTL level input request* thai an interrupt sequence begin power down condition. During the time that this line is held low, within the microprocessor. The microprocessor will complete the writing to or from the microprocessor is inhibited. When a posi- current instruction being executed before recognizing the request. tive edge is detected on the input, the microprocessor vuill imme- At that time, the interrupt mask bit in the Status Code Register diately begin the reset sequence. will be examined. If the interrupt rrvask flag is not set, the micro- After a system initialization time of six clock cycles, the mask processor will begin an interrupt sequence. The Program Counter interrupt flag will be set and the microprocessor will load the pro- and Processor Status Register are stored in the stack. The micro- gram counter from the memory vector locations FFFCand FFFD. processor will then set the interrupt mask flag high so that no fur- This is the start location for program control. ther interrupts may occur. At the end of this cycle, the program After V-p reaches 4,75 volts in a power up routine, reset must be counter low will be loaded from address FFFE, and program counter high from location FFFF, therefore transferring program held low for at least two clock cycles. At this time the RW and control to the memory vector located at these addresses. (SYNC) signal will become valid. The RDY signal must be in the high state for arvy interrupt to be rec- When the reset signal goes high following these two clock cvcIm, ognized, A 3Kn external resistor should ba utad for proper the microprocessor will proceed with the normal reset procedure wire-OR operation. detailed above. Appendix C-4 REGISTER SECTION CONTROL SECTION RES IRQ NUI AS ADDftess BUS B891I, >3. 1*. '5 *I3""" R6S0J, 03. 04. 06, «, 07 A13- Hau: 1. Ctock G>n«r*wr liflot Ineludad on RSB1I, 13. 14. 1& I. Addraiilng Cipabilitv 'nd cantrix oetlom nary with «cn of tfit A6S00 Products. R6S00 Internal Architwiura C-5 Understanding the Apple SPECIFICATIONS Maximum Rating* Rating Symbol Value Unit Supply Voltage -0,3 to +7.0 Vdc Input Voltage -0,3 to +7.0 in Operating Temperature T CommerciBl to +70 Industrial -40 to +B5 Storage Temperature -55 to +150 ^STG NOTE This tJeuice contains input protection ag^insi dsrnage to high static vcoUages or electric tieids: however, precautions should be taken to avoid spplieation of voltages higher than the maximurTi rating Electrical Characterittics tVj.(,»B.0±5%.Vg5 = OI pui Lour Voltage Vdc ^.3 08 -0.3 0.4 Input Leakage Current *iA fV,^ ' to S.25V. Vj,^, - Oi Logic lEitcl Rdv.S.O.) 2.5 *r*2 100 ^olinl 10.0 Three-State (Off State! Input Curfent 'tsi »iA (V.^ = 0.4 to 3.4V, Vj,^ = 5.2SV) Data Lines 10 Output High Voltage "oh Vdc "load " ""'° ^'^'^''- ^CC ' '*^^^' SYNC.Data, A0-A15, RyW, * ^SS^=?* Output LovK Voltage 'OL Vdc "load " ''^ '"*=''=' ^CC ^ ^-'svi SYNC, Data. AO-A 15. R/W, ^SS^O" Power Dissipation mW t and 2 MHi 700 3 MHz Capacitance at 25 C 800 pF i (V.^ = 0. f = 1 MHz) Logic 10 Data 15 A0-A15. R/W, SVNC T3 out *. biin) C0 o(in) 15 SO 80 . NOTE IRQ and MM) require 3K pull^ip resistor. \ Appendix C-6 R65XX Timing D« IVpBI'TI 1 MHi 2MHl 3MHl Charactarinic Symbol Min Max MIn Mw MIn Maa Unit 225 140 110 ns R/W Setup Time Trws 30 30 IB nj Hrn Hold T.ire Thrw 140 110 ns AddrcH Setup Time Taos AddreH Hold Time Tha 30 30 15 ni 6&0 310 170 ni Read Acceti Time Tacc Read Data Setup Time Tdsu 50 40 36 n Read Oaia Hold Time thr 10 10 10 n& Wiiie Data Setup Time Tmds ITS 100 86 Write Data Hold Time thw 30 30 30 nt JO IE nj SVNC Hold Time TSYH 30 RDV Setup Time* Trdv 100 SO 35 nl S.D.SeiupTime TSO 100 SO 35 ni SYNC Setup Time TSVN 225 t76 100 ni MOTE •BOV m«n r*«t twiKh iiatet within Rroy to tfld of *2 LOAD - ISO pF + TTL t mnX CPU Clo«ic Tlmina • V«av *ff Jn V \ 1 MHi 2MHJ 3 MHi Ch Hvc tkf ictic Svnit»l Mil Mh Min Max MIn Mh Unit Cvcitt Time TcYC 10 10 05 10 0.33 10 460 240 160 n» *otln}'-«"Time Tl*o "'*'''''" 470 240 160 ns *3(ln' 10 10 ns Riia ai>d Fill Time* 10 (> .. . ^fl0"^F0 *° Klie Width TPWH*! 4E0 235 16B ns 470 240 160 ni $2 PuluWidin TpWHtPj ns Petav Between ^i and ^2 ^''"'* 25 25 15 ns *1' *2 ^"* ^"^ ^'" NOTE •Measuned between O.B and 2.0 ecini! on wavetorm load 130 pF + 1 TTL. C-7 Understanding the Apple if Table C.I 6502 Timing Comparisons. SYNERTEK ROCKWHi M5S rSSOKXOGS PABftMETEE SYMBOL mn MAX MIN MAX MIN T5fP MAX UNITS CYCLE TIME TCYC i.g 40 1.0 10 1.0 - us - PHS0 LOW TIME PHS0 HIGH TIME PHS0 PULSE WIDTH TLB TH0 PWHO 480 (2) 460(2J 480 470 — _-_ _ - ns ns 460(7) 520(7) ns PHSO RISE/FALL TIME TR0/TF0 0(1) 30 10(6) - 10 ns PHSl PULSE WIDTH TPWHl TLK-20 TL0 460 TL0-20(7) - TL0(7) ns PHS2 PULSE WIDTH TPWH2 TLO-40 TLO-10 470 TLO-40 (7) - TL0-10(7) ns DELAY BETWEEN PHSl AND PHS2 TD 5 _-- 5(7) - ns PHSl, PHS2 RISE/FALL TIMES TR/TF 25(1) (3) 25{6) - 25(8) ns PHS0 NEG TO PHSl POS DELAY TG1 + 10(5} 70(5) - ns PHS0 NBG TO PHS2 NEG DELAY T02- 5(5) 65(5) -,»_ - ns PHS0 POS TO PHSl NEG DELAY PHS0 POS TO PHS2 POS DELAY R/W' SETUP TIME T01- T02+ TRWS 5(5) 15(5) 65(5) 75(5) 225 225 — - - 100 —_^ 300 ns ns ns R/W' HOLD TIME TRWH 30 30 30 60 ns ADDRESS SETUP TIME TADS 225 225 100 300 ns ADDRESS HOLD TIME READ ACCESS TIME READ DATA SETUP TIME TADH TACC TDSU 30 100 650 — 30 50 650 30 100 60 _ - 575 ns ns ns READ DATA HOLD TIME THR 10 _— 10 10 _ ^^— ns WRITE DATA SETUP TIME TM3S 22 175 175 150 200 ns WRITE DATA HOLD TIME SYNC SETTUP TIME SYWC HOLD TIME THW TSYS TSYH — 60 150 350 30 225 30 — .- 60 - _ 350 ns ns 30 30 ns RDY SETUP TIME TSS 200(4) „__ 100(4) 100 "* ns S.O. SETUP TIME TSO 100 100 ns (1) Measured between 10% and 90% points on waveform, (2) Measured at 50% points. (3) Load = 1 TTL load +30 pF. (4) RDY must never switch states within TRS to end of PHS2. (5) Load = 100 pF. (6) Measured between .8v and 2.0v points on waveform, load 130 pF + 1 TTL. (7) Measured at L5v. (8) Measured .8v to 2.0v, Load 1/2 30pF 1/3 1 TTL. Appendix C-8 Table C2 6502 Instruction Execution Periods In Machine Cycles. IMP REL IMM ACC 0PG 0PG 0PG ABS ABS ABS IND I I'D IND X Y X Y X Y ADC AND CMP EOR 2 3 4 4 4* 4* 6 5* LDA ORA SBC ASL LSR ROL ROR 2 5 6 6 7 BCC BCS BEQ BMI 2+n BNE BPL BVC BVS ** CLC CLD CLI CLV 2 DEX DEY I NX I NY NOP SEC SED SEI TAX TAY TSX TXA TXS TYA BIT 3 4 BRK 7 cpx cpy 2 3 4 DEC INC 5 6 6 7 JMP 3 5 JSR 6 LDX 2 3 4 4 4* LDY 2 3 4 4 4* PHA PHP 3 PLA PLP 4 RTI 6 RTS 6 STA 3 4 4 5 5 6 5 STX 3 4 4 STY 3 4 4 * +1 cycle if indexing crosses page boundary. ** n=0 if brancfi does not occur. n=l if branch within page occurs. n=2 if branch across page boundary occurs. appendix D BASIC Program Listings The following pages contain the BASIC program listings which produce Figures 5.8 and 5.9. Appendix D-2 a REM 1 REM 2 REM 3 REM HIRES MEMORV HAP - DlSPtAYED SCAN OKLY. 4 REM 5 HEM 6 REM 10 DIM HXSdS) 20 DATA "0","l","2","3",'M","5",%","7","8","9","A","B",'-C","D","r,'T" 30 FOR A = B TO IS: READ H3t5(A): NEXT h 40 TEXT : HOME 50 PBIPIT ' TOP SCREW/ MIUDLE SCREEN/ BOTTOM SCREEN/" " FIRST 49 SECOND 40 THIRD 40 IMJBEB 8" 60 PRIOT LIN* PAGR 1 RANGE LIN* PAGE 1 RANGE PAGE 1 RANGE" 70 PRIOT " PAGE 1 PAGE 2 LINI PAGE 1 RANGE 90 REM 91 REM IBB FOE A = e TO 7: FOR B = TO 7^aASE = A * 128 + B • 1024 + B192 110 LN$ = "$":DBC = BASE: QOSUB SB00: SD1 GFT PAGE 1 HEX 190 REM 191 R»1 200 DECS = STSS (CASE) : IF UTti (DKIS) « 5 THEN LNS = LNS + " " 210 u)5 - LN6 + " " + one? + " S" 22B DEC = past: + 8192: GOSUB 5000: REM GET PftGE 2 HEX 230 LNS = LNS + " " + ETR$ (DEC) + " " 290 REM 291 REM 300 SCAN = 8 • fl + B: GOSOB 699(5: REM GET SCAN NU^BF.R 3ie DEC = BASE: GOSUB 5000 320 LNS = LNS + "-S" 330 DEC = aASE + 39: GOS(TB 5000 340 LNS ^ LNS + " 390 REM 391 REM 400 ECAK = SCAM + 64: OOSUB 6000 410 DEC = BASE + 40: GOSUB 5003 420 LtJS - LNS + "-S" 430 DEC * BASE • 79; GOSUB 5000 " 440 LNS * EJUS * 490 REM 491 REM 50 B SCAN = SCAN * 64: OOSUB 6000 5ia DEC BASE + 80: GOSUB 5000 520 LNS = LNS + "-S" 530 DEC = BASE + 119: GOSUB 5000 599 REM 591 R&1 600 LNS = LNS + " 5" 610 DEC = BASE + 120! OOSUB 5000 629 LNS = UOS + "-S" 630 DEC = BASE + 127: GOSUB 5000 640 PRINT LNS: NEXT B: NEXT A fi'^n PHTHT • PRiwr 660 PRINT "FIGURE 5.8 - HIFF^ DISPLAYED MEMORY MAP. PAGE 1 AND PAGE 2 ARE EACH HADE UP OP 64 13R-BVTE MEMOPV SffiHEHTS. 670 CRT BS: a© 4090 PFW 4091 REM 4092 REM 4093 R&1 SUBROUTINE 5000 CONVERTS THE DECIMAL ADDRESS IN DEC TO 4094 REn HEXADECIMAL AND CONCATINATES THE HEX NUMBER TO LNS. 4095 REM 4096 HEM 4097 REM 5000 H4 = DEC / 4096 !H4% = H4 5010 H3 = (H4 - H4*) * 16:H3% = H3 5020 H2 = W3 - H3%) * 16:H2% = H2 5030 Hl% = (H2 - H2%) * 16 + .5 5040 LNS = LNS + HXS(H4%) + HX5(H3t) + HXS(H2%} + BXS(Hll) S050 RETURN 5190 REM 5191 PIN 5192 REM 5193 REM SUBROUTINE 6^88 ADDS LEMJING ZESOES TO THE SCAN I 5194 REM 5195 REM 5196 Sm 6000 IF SCAN <:100 THEN UlS = LNS + "0" "0" 6010 IF SCAN < 10 THEN LNS = LMS + 6020 LNS = LNS + STRS (SCAN) + " $" 6030 RETURN Hgure D.I BASIC Listing: Program that Produces Figure 5A. [W Understanding the Apple REM 3 Rffl POUR PAGE HIRES HQIORy MAP - INCLUOra VBL & HBL. 6 HEW 10 DIM HXS[15) 20 DATA "0" , "1" , "2" , "3" , "4 " , "5" , "6" , "7 " , "B" , "9" , "A" "B" , "C" "O" ,"E" , "F" 30 eon A = TO 15: HEAD HXS (A) NEXT A: 40 SCAN = - 1 100 SE» 102 PRINT TAn( 56)"SCREKH TOP": PRINT : PRINT 110 GOSUB 4000: REM PRIWT HEADINGS 120 FOR A = TO 7: FOR B = TO 7:BftSE = A * 12B + H * W24 * 8192 130 GOSUB 1000: REM DO LINE 140 NEXT B: NEXT A 150 GOSUB 5000: GET AS 200 RBI ******************** 202 PRINT ; PRINT : PRINT TAB( 55) "SCREEN MIDDLE": PRINT : PRINT 210 GOSUB 4000 220 FOR A = TO 7: POR B = TO 7:BASE = A ' 128 *• P • 1024 + 8232 230 GOSUe 1000 240 NEXT B: NEXT A 250 GOSUB 5000: GET AS 300 REM ******************** 301 PRINT PRINT : PRINT TAP( 55) "SCPPEN BOTTOM": PRINT : PRINT : 310 GOSUB 4000 320 FOR A = TO 7: FOR = TO 7:BASC - A • 128 + B * 1024 + 8272 330 GOSUB 1000 340 NEXT B: NEXT A 350 GOSUB 5000: GET AS 400 REM ******************** 401 PRINT : PRINT : PRINT tm( 46) "VRRrriCAL Bf,Afn INT (BASE / 128) THEN HBL = HBL + 129 1040 DEC = HBL: GOSUB 3000: HEM 00 PAGE 1 1050 DEC = HBL + 8192: GOSUB 3000: RQI DO PAGE 2 " 1060 SYMB0LS5 = "++++++++++++ ": IF SCAN > 223 ANI3 SCAN < 228 THEN SYMBOLSS = "tlllttftllf t 1065 LNS = LNS + "+++++++++###1" + SYMBOLSS 1070 DEC = BASE: ODSUB 3000: REM 00 PAGE 1 1080 DK: = BASE + 8192: GOSUB 3000: Rffl DO PAGE 2 1090 S^MBOLES = "+++++++++++++++++++++++++++++++++4-++++++" 1100 IF SOW > 223 AND SCAN < 22B THEN SYMBOLSS = "«t»#i»l«tl#l#ltltHI#»Um((t«tSSil*#t«»iif 1110 LNS = UJS + SYMBOLSS: PRINT LNS 1120 RETURN 3000 REM 3002 Rffl GET HEX & DECIMAL STRINGS 3004 REM 3005 H4 = DEC / 4096 :H4* = H4 3010 H3 = (H4 - H4I) * 16:H3i = H3 3020 H2 = (H3 - H3i) • 16:H2% = H2 3030 Hli = (H2 - H2i) * 16 + ,5 " 3040 LNS = LN$ + "S" + HXS(H41) + KXS(H3*) + HXS(H2*) + HXStHU) + " " 3050 DECS = STRS (DBC) : IF LEN (DECS) < 5 THEN LNS = LNS + " 3060 LNS = LNS + DEC? + " " 3070 RETURN 4000 REM 4002 REM PRINT HEADINGS 4004 REM 4010 PRINT " HORIZONTAL BLANKING (HBL} HORIZONTAL DlSPLAif RfJMLE" 4015 PRINT 4020 PRINT "LINE llllllll U11U1111UU11222Z2222" 4030 PRINT "Nm PAGE 1 PAGE 2 00123456789AaCDEF01234567 PAGE 1 PAGE 2 al234S6789ABCDEFai23456789AaCDEFai234567" 4040 RETURN 5000 REM 5002 REM PRINT FIGURE NUhBER 5004 REM 5005 PRINT : PRINT 5010 PRINT "FIGURE 5,9 - THIS KIRES SCANNING MAP SHOWS THE ADDRESSES SCRNNHl DUBiNC DISPLftiT PERIODS AND BLAKKIHG PERIODS." 5020 RBItJraj Figure D2 BASIC Usiing: Progiam that h^oduces Figure 5.9. appendix E A Logic CircuHs Primer Bits of information in a computer are generally This AND function is identical to the 6502 AND represented by voltages. In positive level logic like instruction, except that the 6502 instruction is per- that used in the Apple, a high voltage (about 3 volts) formed on 8 bits simultaneously and is logically is considered to be true, and a low voltage (about equivalent to 8 two input AND gates. volts) is considered to be false. The electronic cir- A way of demonstrating a logic function is a truth cuits in the Apple are designed primarily to treat table- The truth table shows the state of an output signal voltages as true or false indications and to for every possible combination of inputs. The true process them logically. In studying the Apple, it state can be represented by T or 1 or H (for high is advisable to concentrate on the logical function assuming positive logic), and the false state can be represented by F or or L, We will use H and L of the components rather than their electronic because this usually eliminates possible ambigui- function. The most basic functional building blocks are ties. The truth table for the positive logic AND gate simple logic gates. For example, a two input AND is: gate will bring its output high if and only if both INPUT A INPUT A OUTPUT inputs are high. In other words, both input A AND L L input B must be true if the output is to be true. The L H two input AND gate is represented in logic dia- H L grams as follows: U . K This clearly demonstrates that both inputs of the positive logic AND gate must be high before the output will go high. Table E shows the truth table, INPUT A INPUT B > OUTPUT schematic representation, and equivalent 6502 in- struction, where applicable, of some simple logic gates used in this book. E-2 Understanding the Apple Table E Basic Logtc Gates. 4 SECONDARY TRUTH TABLE 6502 NAME REPRESENTATION REPRESENTATION B A OUT EQUIVALENT AND A— \ L L AND XXXX B- )-OUT B^IXOUT L H OR L ORA XXXX H B^I>-0^^ :-: y^^^ H H NAND H AND XXXX A— H EOR ^FF B^ \5-0UT :^:>o^T H L NOR H ORA XXXX L EOR #SFF B^O°^^ :=^i>- L L EXCLUSIVE L EOR XXXX OR H ^^r>o- H H H L AMPLIFIER A-^>^OUT A^^>o-QUT L NOP H INVERTER H EOR#SFF A-h>c^OUT A^0>^OUT L TRI-STATE 6 Z AMPLIFIER z HIGH A-[]>— OUT L ENABLE H TRI-STATE B Z INVERTER HIGH A - ^po- OUT Z H ENABLE L i B TRI-STATE L AMPLIFIER H LOW A-[^>^OUT Z ENABLE Z B TRI-STATE H INVERTER L A -[]>>- OUT LOW H Z ENABLE H H Z Appendix E-3 The little circles on the gates represent the con- clocked D input. Bringing PRESET low forces Q cepts of inversion and active- when-low signals. The high and Q' low. Bringing CLEAR low forces Q low two concepts are closely related and sometimes and Q' high. innpossible to separate. Inversion is the process of The clockpuise adds synchronization to logic. If turning a signal into the logically opposite signal. the same clockpuise triggers a hundred different When a signal is low, its inversion is high, and vice actions, then the actions all occur simultaneously. versa. When examining a logic gate, the absence of This clockpuise synchronization is common to all circles can be read as active-when-high and the cir- digital computers. Certain devices react to the cles can be read as active-when-low. For example, clock. Other devices react to those clocked devices, the NAND gate has a circle on its output, meaning and so on. After a given period of time, all reactions both inputs must go high to make the output go low. are complete and the logic signals are all stable, This can be stated in a second way. If either input waiting for the next clock. The computer thus oper- goes low, the output will go high. This results in a ates one cycle at a time. second way of representing the NAND gate, as an As an example of clocked operation, Figure E.2 OR gate with little circles on the inputs. The circles shows a logic function similar to the 6502 AND take a little getting used to and are used in some instruction. In the AND instruction, the value in the pretty unusual ways in some drawings. Just asso- accumulator is ANDed with a different value to get ciate the circle with the word "low" and you should the new accumulator value. In Figure E.2, the flip- get the message. flop represents one bit of the accumulator. When the The tri-state amplifiers of Table E represent a flip-flop clock rises, the flip-flop goes to a state different sort of logic device. In addition to the nor- determined by its old value ANDed with a second mal binary states of high and low voltage, the tri- value. state device has a third state, high isolation or high Most logical circuitry is made up of some combi- impedance. The line coming in from the side is the nation of simple logic gates and flip-flops or their output enable line and it controls the isolation. When equivalents inside an integrated circuit. In modern the output enable is not active, the device is isolated computers, many complex functions are available from the output line, so another device can control packaged in integrated circuits. TVpical of such the output line. In electronic terms, the device pre- complex functions are comparison, counting, cod- sents a high impedance to the output line. In the ing, decoding, and shifting. Even more complex are truth tables of Table E, the high impedance state is the functions of chips like the 6502, RAM, and ROM represented by a "Z". A more detailed discussion of in the Apple. A good way to familiarize yourself tri-state logic is contained in the chapter on bus with the variety of logic functions available is to structure. peruse the data books published by manufacturers. A building block of equal importance to the logic Of particular help in the Apple is a TTL data book. gates is the clocked flip-flop. This is a 1-bit storage TTL (Transistor Transistor Logic) is the name of the logic family to which most of the Apple's general device which will respond to its logic inputs when it purpose chips belong. National Semiconductor is a senses an active transition on its clockpuise input. Figure E.l shows a diagram of a D type flip-flop and company which is very good at making their data books available to the public at reasonable prices. its truth table. The flip-flop shown is clocked by a Their TTL data is contained in the Logic Databook, low-to-high transition of its clockpuise input and is priced at $9.00 as of March, 1982. Books can be like the 74LS74 flip-flop used several places in the obtained by writing: Apple. The Q output will follow the D input every time the clockpuise rises, and the Q' output will be National Semiconductor Corporation the inversion of the Q output. The CLEAR and ATTN: Literature Distribution MS/14208 PRESET inputs cause the flip-flop to change states 2900 Semiconductor Drive without requiring a clock, and actually override the Santa Clara, CA 95051 E-4 Understanding the Apple TRUTH TABLE INPUTS OUTPUTS PRESET CLEAR CLOCK D P 0' L H X X H L H L X X L H L L X X H H H H t H H L H H + L L H H H L X HLD HLD H H H X HLO HLD TYPICAL OPERATION CLOCK D 1 CLEAR — PRESET Q Q' Figure E.I A D-T/pe Flip Hop. Understanding the Apple 11 uses logic equations to in fact, referred to as Boolean algebra, after sym- describe the logical makeup of certain signals. A bolic logic pioneer, George Boole. typical logic equation is VERTSYNC = VBL. V2. VI'- V0» VC (H4+H5), •In representing the NOT function with a prime symlDo], this which is read VERTSYNC = VBL AND V2 AND book is following the sensible lead of the Apple lie Reference MnitHni.The more common convention is tooveriscore the term or NOT VI AND VO AND NOT VC AND (H4 OR H5). terms to which the NOT function is applied. The overscore is not a The dot represents the AND function, the plus sign particularly workable representation because it is notacommon represents the OR function, and the prime symbol typogrraphical symbol and, more importantly, there is no code for represents the NOT or INVERSION function,* it in standard computer text coding systems such as ASCII, This selection of symbols makes the equation look Engineering and manufacturing printouts normally use an asterisk or prime symbol aftera term to which the NOT function like an equation of common algebra, and it's no is to be applied. Apple should be commended for taking the lead accidental coincidence. The manipulation of such in using this notation in published docunnents. Now. what are equations has parallels in the field of algebra and is, they going to do about that dot that represents the AND function? Appendix E-5 COMPARISON INPUT 1/8 OF THE ACCUMULATOR Rgure E2 The Circuit Equivalent of ttie 6502 AND Instruciion. Other functions besides AND, OR, NOT, and is only to describe some details of signal generation parenthesis grouping can be represented in logic in a concise way. No algebraic manipulations are equations, but only these basic functions are repre- described, and none are required on the part of the sentedin logic equations in this book. The purpose in reader. using such equations in Understanding the Apple II appendix F A Number S^em Primer In our daily lives, we represent numerical quanti- is a bit of information. The simultaneous states of ties in the base 10, or decimal, numbering system. eig'ht binary switches can be combined into an 8-bit For example, by 359 we mean the sum of 9 x (10 binary word such as 10011110. Because of the two EXP0)p]us5x(10EXPl)plus3x(10E^P2).This state nature of digital computer building blocks, use of the decimal numbering system gives us some digital analysis and design has been performed unusual biases that would occur only to mathemati- since day one using the base 2, or binary, numbering cians if we used a different base for our numbering system. In this system, there are twodigits— 1 and D. systems. For instance, we place special significance The binary number 110 represents the sum of x (2 on numbers like 1,000,000 (10 EXP 6) but not on EXP 0) plus 1 X (2 EXP 1) plus 1 X (2 EXP2), which 2,986.984 (12 EXP 6, equal to 1,000,000 in the base- is equal to 6 in decimal 12 or duodecimal numbering system). Mathemati- Actual performance of binary arithmetic is very cians have studied number systems for years, but unwieldy, particularly if you consider fractions. now, because of thegrowing influence of computers, Addition and subtraction of 6502 addresses would knowledge ofnumberin^systemsotherthan base 10 require 16 digits. For example, subtracting decimal is becoming very common indeed. address 35000 from 35003 looks like this: You see, the electronics of digital computers is based on hundreds of thousands of two state, or binary, electronic switches which can be on or off. The on or off state of each binary switch can be 1000100010111011 represented numerically as a ONE or a ZERO, and 1000100010111000 the information as to whether the switch is on or off 11 /^pencfix F-2 If that looks clumsy, you should try multiplying 143 The hexadecimal system has 16 digits, 0-9, A, B, x247: C, D, E, and F. The use of letters to represent 11110111 numbers is sometimes confusing, but that's the con- X10001111 vention we're stuck with. When converting between 11110111 binary and hexadecimal, the binary number is 11110111 divided into groups of four digits starting from the 11110111 right: 11110111 1000 1001 1111 1001 = 89F9 (base 16). 11110111000 6502 programming convention calls for use of the 1000100111111001 hexadecimal numbering system for representing addresses, machine language code, and much data. To prevent carrying out operations like this, com- Convention further calls for preceding hexadecimal puter programmers use other number systems numbers with a dollar sign ($89F9) and binary based on powers of two, such as octal (base 8) and numbers with a percent sign (%10001001), to distin- hexadecimal (base 16), Arithmetic is much easier to guish them from decimal numbers. Following con- perform in these systems and conversion to and vention, the Apple monitor represents all numbers from binary is soeasy that you can do it on sight with in hexadecimal. As a result, some skill in hexadec- a little practice. For example, the above product can imal arithmetic and hexadecimal/decimal conver- be read as hexadecimal 89F9or octal 104771. sion is very desirable for Apple programmers. In Conversion between binary and octal consists of addition, the well rounded computer programmer dividing the binary number into groups of three, will be familiar with the binary and octal systems. from right to left: Here are two numerical facts of life about 6502 1 000 100 111 111 001 = 104771 (base 8) based microcomputers like the Apple. First, there These patterns of three digits can each be converted are 16 address lines connected to the 6502. 16 lines toone of eight octal digits from the table below. With can be in 65536 different possible combinations of exposure, these patterns become very familiar. As states (0-65535. $0-$FFFF, or %0-%llll 1111 1111 you would guess, there are eightsymbols in the octal 1111). Second, there are eight data lines connected system, 0-7. to the 6502. E ight lines can be in 256 different possi- Table F Number System Equivalent Representations. DECIMAL BINARY HEXADECIMAL OCTAL QOOB 1 0001 1 1 2 0010 2 2 3 0011 3 3 4 0100 4 4 5 0101 5 5 6 0110 6 6 7 0111 7 7 8 1000 8 10 9 1001 9 11 10 1010 A 12 11. 1011 B 13 12 1100 C 14 13 1101 D 15 14 1110 £ 16 15 1111 F 17 M Understanding the Apple ble combinations of states (0-255, $0-$FF, or %0- toggled by a reference to any address in the range i %11111111). These numerical features of the 6502 $C02X ($C020-$C02F) than the range 49184-49199. account for some limiting numbers which occur Dear reader, the effort you spend learning your in the BASIC language like 65536, 255, 32767, binary and hex systems will be well worth it. and 127. If this is your first exposure to number systems, Addresses are normally referred to in hexadec- then you have just scratched the surface. It is highly imal in Understanding the Apple II. This is because recommended that you spend some time with the hexadecimal representations make sense and mathematics or computer arithmetic courses, solv- are easy to remember. Numbers like $10000, $C000, ing problems and familiarizing yourself with this and $2000-$3FFF are much more to the point than sort of numerical manipulation. You need to get a 65536. 49152, and 8192-16384 when representing little used to thinking like a computer. Probably the the number of Apple addresses, the start of I/O best exercise possible for you would be to write some addressing, and the address range of the HIRES 6502 assembly language programs. You'll sink or PAGE 1 memory map. It is also far easier to swim in hexadecimal and binary number systems. remember that the Cassette output port can be appendix G Revisional Information There have been three important revisions to the tant revisions and getting permission to reproduce Apple II motherboard: Revision 1, Revision 7, and them in his book, The Apple 11 Circuit Description the RF"! Revision (Radio Frequency Interference (Howard W. Sams & Co. Inc.. 1983). The Apple !I reduction). Revision 1 and Revision 7 corrected var- Circuit Description is highly recommended for its ious minor bugs and added circuits which enhanced schematics and timingdiagrams, and because it can the operational features. The RFI Revision was a provide alternate perspectives of those portions of direct response to a crackdown by the FCC on com- this book devoted tocircuitdescriptionsof the Apple puter manufacturers whose products emitted RFI. II motherboard. Virtually all personal computer manufacturers The part number of the original Apple II mother- were affected by this FCC action. board is 820-0001-00. The "-00" indicates it is Revi- Between the important revisions, there were a sion 0, and the author suspects it was called Revision number of inconsequential revisions, some of which only when Revision 1 came out, Apple got up to were apparently never released. Information about "-09" before they wore out the old part number, and these minor revisions is sketchy because Apple's switched to 820-0044-01 when the RFI revision documentation of the revisions has been sketchy. came out. Then they quickly ran out of numbers and Revision 1 was documented in the A pfjie II Reference switched over to letters to differentiate between Manual. The next documentation to appear was an revisions. Do not be bothered if the numbering sys- addendum to the reference manual which shows the tem seems illogical to you. You probably just do not schematic of the RFI Revision Apple IL What hap- communicate with yourself on the same level that a pened in each of the interim revisions is a subject of big company communicates with itself. Table G.l is speculation and it is possible that no one person an attempt to categorize the revisional part knows what each revision accomplished. Mr. Win- numbers. Question marks mean that, as far as the ston Gayler achieved a bit of a breakthrough in this author knows, a particular revision may not exist or area by obtaining Apple schematics for the impor- may not have been released to the public. G-2 Understanding the Apple Table G Apple II Revision Numbers. 10. Reduction of vertical sync pulse width and addi- - tion of horizontal syncing serrations during the vertical sync pulse. PART NUMBER REVISION You can tell you have Revision 1 or later by examin- ing the screen text on a color television or monitor. 820-0001-00 REVISION In Revision 0. all screen text is colored violet, green. 820-0001-01 REVISION 1 820-0001-02 and white. In Revision 1 or later, TEXT mode text is 820-0001-03 white, but MIXED MODE text is violet, green, and white. 820-0001-04 820-0001-05 ? 820-0001-06 ? Revisions 2 through 6 820-0001-07 REVISION 7 This is a very gray area in which very minimal 820-0001-08 ? changes were made. It would be very nearly correct 820-0001-09 ? to say all of these revisions are the same as Revision 820-0044-01 RFI REVISION 1. In Revision 4, Apple started soldering 16K RAM 820-0044-A ? configuration plugs into the motherboard instead of 820-0044-B ? sockets. From this point on, the obsolete 4K RAM 820-0044-C capability was eliminated. To the author's knowl- 820-0044-D edge, Revisions 5 and 6 were never released. You probably can read the part number of your APPLE 11 PLUS Apple on your motherboard. There was no part The Apple II Plus came out when some revision number printed on Revision motherboards. The between and 6 was in production, although it did 1 part number of motherboards prior to the RFI Revi- not represent a revision to the motherboard. The sion can be seen by removing the 6502 chip or by only operational difference between the Apple II lookingat the bottom of the motherboard. RFI Revi- and the Apple 11 Plus is in firmware. The Apple II sion motherboards have the part number printed in has Integer BASIC and the old Monitor in ROM, plain view near the Fl socket. Some notes about the while the Apple II Plus has Applesoft BASIC and revisions follow. the Autostart Monitor in ROM. At approximately Revision 1 the same time as the introduction of the II Plus, the keyboard was changed so CTRL could be required Revision 1 was the most important revision from the for RESET to function, and the keyboard electron- standpoint of operational enhancements. The addi- ics were moved to a separate card. Numerous ver- tion of delayed HIRES video, the power-up RESET. sions of the keyboard have been available, but this and the TEXT mode COLOR BURST killer were one major operational difference is associated with significant improvements. The changes made in the Apple II Plus. Apple may have produced the Revision 1 are documented mthe Apple IJ Reference Apple II and the Apple II Plus concurrently for a Manual. They include: while, but they soon switched to the II Plus exclu- 1. Addition of a COLOR BURST killer circuit to sively. The author's Apple II has a Revision 3 remove colors from text. motherboard, so the Apple II was still available 2. Addition of power-up RESET circuitry. when Revision 3 was in production. 3. Addition of the HIRES delayed video feature which gives the blue and orange colors. Revisions 7 through 9 4. Solving a memory addressing problem for Apples with 20K or 24K of RAM. Revision 7 was the next important revision after 5. Addition of 50 Hz Eurapple jumpers. Revision 1. Its most significant effect was to change 6. Connection of COLOR REFERENCE and video the screen text ROM from a 2513 to a 2316B. This SYNC signals to pins 35 and 19 of slot 7. enabled the owner to substitute his own upper/lower 7. Addition of a wire wrap post which is connected case E PROM for the standard ROM. The Revision 7 to theVIDEO output signal. changes include: 8. Disconnection of the speaker output from the 1. Replacement of 2513 screen text ROM with cassette output. 2316B ROM. The 2316B is fully pin compatible 9. Redesign of the cassette input amplifier. with 2716 EPROM. Appendix G-3 2. Removal of RAM configuration sockets and IC products into compliance with part 15. This was E2. extended to January 1, 1981 because the first dead- 3. Reduction of horizontal sync pulse width from line proved to be unrealistic. Apple requested and eight to four microseconds. (IVansistor Q7 was was granted a waiver until April 1981. What Apple added as part of this logic.) was doing during this period was finalizing the RFI 4. Change to double pulse horizontal syncing ser- Revision, which was the next important revision rations during vertical sync. after Revision 7. 5. Addition of jumper pads 7 and 8 and a 4-pin Reduction of RFI involved adding shielding to the connector (see Figure 7.9). cabinet and peripheral connecting cables, increas- Revision 7 and later motherboards are easily ing the width of motherboard printed conductors, RAM configuration addition of filtering circuits, and interchanging identified by the absence of the +5 volt and ground distribution so the +5 volt plugs at CI, El, and Fl. bus is on the top and the ground bus is on the bot- Revisions 8 and 9 tom, A steel bar is firmly attached between the motherboard and the base plate in the rear. This The author has never seen a Revision 8 or 9 bar reinforces the rinotherboard (Allah be praised) motherboard but he is told they exist. A 14 was and connects the base plate to ground on the probably added to the motherboard in one of these motherboard. These changes represent a substan- revisions for the purpose of improving the effective- tial engineering effort by Apple, and the extent ness of COLOR BURST killing in TEXT mode (See of the differences no doubt, what prompted is, Figure 8.7, top right). This removed some distract- Apple to change the base part number of the RFI ing colored "ghosts" which occurred on some televi- motherboard. sions or monitors in TEXT mode. Other minor Some minor functional changes were also made in changes were probably made. the RFI Revision. These changes included: RFI Revision 1. Changing the double pulse serration in the ver- tical sync, introduced in Revision 7, back to sin- After home computers began to proliferate, the gle pulse serrations. FCC became cognizant of the fact that mostof them could interfere with nearby radio frequency recep- 2. Replacement of two 8T28 ICs with one 8304 as tion under some circumstances. The FCC conse- the MPU data bus driver. quently revised its regulations to include computing 3. Elimination of Q7. The function of Q7 is per- devices. The pertinent restrictions are in part 15 of formed by A14 on RFI Revision motherboards, 4. Generation of SOFT 5 with a 1000 ohm pull up FCC regulations. Part 15 sets limits on the amount resistor instead of two gates on A2 as was done of radio frequency emmission that devices like tele- in previous revisions. SOFT 5 is a voltage which visions, garage door openers, and computers can represents a constant logical true or "1" in the give off. The Apple is a class B computing device, meaning that it is intended for use in residential Apple II. 5. Addition of a high frequency rejection filter at areas. Restrictions on class B computers are tougher the video output jack. than they are for class A (industrial use) computers, because of the large number of radio frequency There have been at least two revisions to the RFI receiving devices in residential areas. motherboard. These revisions were made solely to In October 1979, the FCC set a deadline of July 1, reduce RFI emmission and had no operational 1980 for computer manufacturers to bring their effect. appendix H Historical Notes The original Apple was designed in late 1975 by In fall of 1976, Wozniak completed the design of Steve Wozniak, a talented, 25 year old college drop- the Apple II. This new computer far surpassed its out who designed computers for fun. At some point predecessor in sophistication with HIRES and in time, Wozniak entered into a partnership with his LORES graphics capability, 48K of RAM. BASIC friend Steve Jobs, named the machine after a fruit, and system monitor in ROM, built in cassette I/O, and sold a few hundred of these Apples. This origi- and eight peripheral expansion slots with mother- nal Apple had a 6502 microprocessor, 8K of RAM, board decoded slot control signals. The Apple II, no no motherboard ROM beyond the screen text ROM, doubt, borrowed many features of hardware and a motherboard power supply, and a single slot into program structure from the 1975 Apple, but most which a cassette interface board plugged. The people would not recognize the older computer as Apple was sold only as a circuit card, but enclosures an Apple. and keyboards were available. While developing his Apple designs, Wozniak was Of central importance to the first Apple was the not a lone talent working in solitude at his cerebral 6502 microprocessor, which was then brand new. pastime. He was a member of the Homebrew Com- The 6502 was simple, powerful, and available for puter Club, the club to end all clubs, from whose $20,00 over the counter to all comers. This accessi- membership rolls have come several microcom- bility made it an inviting MPU for an independent puter industry leaders. His friends were very inter- designer like Wozniak. Steve was apioneer in build- ested in Steve's Apple and made substantial con- ing hardware around the6502 and in programming tributions to the Apple. Steve gives Allen Baum the 6502. His BASIC interpreter was probably the much of the credit for the peripheral slot structure. first BASIC written for the 6502. This program was In his "Apple II: System Description,"* he mentions written directly in machine code, as were the system Baum for originating the Apple II debug software, monitor and Wozniak's other early programs for the Apple. *BYTE Magazine, May 1977 Appendix H-2 Doug Kraul for helpful suggestions on I/O struc- Scott who came over from National Semiconductor ture, and Randy Wiggington and Chris Espinosafor to be company president. Wozniak has a recollection testing Apple BASIC. of Scott answering phone calls to Apple while dub- The contributions of Steve Jobs to the Apple II bing cassette tapes on a string of tape recorders. The were of a different nature. Jobs was not very inter- company shipped its first Apple II in June of 1977 ested in designing computers, but he was very inter- and had paid off all its debts by December of the ested in selling the Apple. It was Jobs who thought same year. Growth of Apple II sales has increased big, who thought the Apple could be sold, and who ever since. pushed Wozniak in his development of a computer The spectacular success of the Apple II seems to which was getting better and better. It was Jobs have resulted from a fortunate combination of tim- who talked big to people who counted: to Rod Holt ing and talented individuals. Appearances suggest who came over from Atari to help with electronic that the most critical talents were those of Wozniak, engineering tasks such as power supply design, to Jobs, and Markkula. At this writing, Jobs and suppliers who were giving them components at dis- Markkula still hold top management positions with count prices with 30 days credit, to Mike Markkula the company. Wozniak has separated himself from who gave the new company business leadership and Apple's executive processes and does his own thing. a quarter of a million green backs in seed money. Apple attempts gamely to infuse the magic of the The Apple computer company officially came into Apple II into newer products, while we wait and existence in January of 1977. Company leaders hope for their eventual success. included Markkula, Jobs, Wozniak, Holt, and Mike appendix I A Technical Conversation witfi Steve Woznialc The first draft of Understanding the Apple II was who does not take notes and drive in LA traffic at the submitted to Quality Software in March 1983. Since same time. The conversation is def in itely not Steve's this was an investigative worlc, there were many exact words, or the author's, for that matter. questions in the author's mind about points of the design of the Apple II: why things were done the S. Did Apple design the analog card in the disk way they were and why other things had not been drive or did Shugart? done. Because of luck and the generosity of Steve W. Rod Holt designed the analog card. We took a Wozniak. the author received the answers to a Shugart SA400 drive and designed the inter- number of his questions from Mr. Woz, himself. face on our own. Motorola had just come out My conversation with Steve occurred on the even- with a new read interface chip for floppy disks, ingof April 17, 1983, after the Applefest Convention and we used it in the design. We saw how the in Anaheim. Although he was tired and wanted only head could be positioned through program con- to get home to his family, Steve submitted himself to The whole interface was originated at trol. a ride to the airport in the author's 1972 Nova, a car Apple. which sometimes reaches its destination without malfunctioning. During the ride, we talked of S. The DEVICE SELECT' signal to a peripheral slot goes away before PHASE 2 falls on the nothing but the design of the Apple II computer, 6502, Was that a design oversight? which, it turns out, is something Steve loves to talk about and had not seriously talked about in years. I W. I gave consideration to distributing PHASE 2 would like to share with the reader a paraphrased instead of PHASE throughout the mother- synopsis of the comments he made about the design board, but PHASE was much easier to work of the Apple 11. Please be cautioned that these com- with. I felt that PHASE probably clocked the ments are as reliable as the memory of the author, data to the 6502, but I no longer think that is Appendix 1-2 true. We could have changed the timing, but feJt W. Advanced programming techniques have been that we could control the situation since Apple developed to overcome that. It takes a little would be designing all the peripheral cards. We work, but graphics displays can be updated just had no idea that many companies would be as fast as if the memory were contiguous. We designing peripherals for the Apple. never dreamed how many people would be writ- ing assembly language programs to manipulate S. Ithink the long bleed off time of the data on the floating data bus will make the DEVICE the graphics. Our expectation was that most SELECT' a valid transfer bus management programs not written by Apple would be writ- ten in BASIC. signal in any design. W. Yes. that's what makes some peripherals work, S. In my book, I call the ROM on the disk controller with the sequencing program a logic state but some designs have had problems. You must sequencer instead of a state machine. Was it you be aware of the situation when design! ng periph- that called it a state machine? erals for the Apple. There are no other areas where Apple timing doesn't meet component W. Yes, that's my title. I guess it could be called a specifications. sequencer. S. There are a couple of other areas. One is the text S. Iwent to great lengths to explain the sequencer ROM. Apple timing doesn't give the 2513 char- program in my book. I made up mnemonics for acter generator 450 nanoseconds to put out the the sequencer commands and printed a pro- text patterns, gram listing. W. That doesn't sound right. We were very careful W. I have a lot of material on that subject which you in that area, but 1 don't remember the details. It could have used. There's a person named Gibson may be that Apple uses 350 nanosecond parts. who wrote an assembler for the sequencer You should call Peter Baum at Apple. He will be which actually assists in writing programs for very interested."* it. He sent me a copy of it. S. Is that Allen Baum's brother? S. Iread that you had a frustrating problem with reflectionson conductors of the motherboard. Is W. Yes. Allen contributed greatly to the Apple. He that the reason for the resistors connected to the did most of the work in devising the peripheral slot structure. RAM address lines? S. Did anyone else work on the motherboard W. Yes, that was a big problem. design? S. It was a big problem with me. The RAM data sheets don't recommend it and I wasn't sure of W. Except for the peripheral slots, I designed ever- their purpose. thing. The I/O STROBE' to the slots was one good thing we did with the slots. We just had W. Exactly. We had to figure out what was going on that signal sitting there and decided to use it for for ourselves. Rod Holt was trying to analyze it expansion ROM That made it possible for cards . with an oscilloscope, but I experimented with like modems to come with their own driving resistors to make the problem go away. Some- firmware. That was very important in the one did a theoretical analysis later and found cassette based Apple and it gave us a big boost. that the resistors I'd used were almost perfect. Do you know that by addition of two chips S. Why didn't RA6 have termination resistors I could have made Apple screen memory until the RAM configuration plugs were taken contiguous? out of the Apple? S. You should have done it. Two chips would have W. Because RA6 did not have as long a conductor been a small price to pay to make the graphics when the configuration plugs were there. easier to program. S. On the 16K RAM card, the RAM address inputs are tied to the unused inputs of ICs. Is that to •I did call Peter Baam and he was very interested. He agreed eliminate reflections? that it sounded like the Apple timing did not meet the 450 nanosecond specification of a standard 2513 or 23i6B ROM. Of W. I'm not sure, but it sounds right. Something else course, with the Apple lie in prcduction.atimingabnormality in to consider is that leaving pins open on an IC can the old Apple Ills not a particularly lively issue in Cupertino. cause the IC to draw more power. That may be 1-^ Understanding the Apple the reason for the connections on the RAM card. Apple II to take advantage of it. I've told Syner- Incidentally, one difference between the Apple tek about the problem but they haven't changed He and the older Apples is in the way the RAM their specification. New 6502s can be stopped card handles resets. The reset did not cause the for 40 microseconds, but they deteriorate. They old RAM card to be automatically disabled; the are dynamic devices that store data in internal reset handling program had to disable the RAM capacitive elements. As the 6502 wears in, its card if it was going to get disabled. In the He, capacitive elements become less efficient. the reset automatically disables the built-in S. I'm very glad you brought this up. Descriptions RAM card.* inmy book are very vague about how long you S. In my book, I show how you can bank switch could stop the 6502 during DMA. The data motherboard RAM from a peripheral card in sheets are inconsistent. Synertek says 40 micro- the old Apple. seconds, Rockwell says 10 microseconds, and W. I don't think there's much application for it. I MOS Technology doesn't say at all. think Apple made a mistake in bank switching W. Rockwell changed theirs to 10 microseconds? the auxiliary RAM in the He. That's great. S. I like the idea of having two applications resi- S. Do you think 10 microseconds is a good number? dent in RAM simultaneously with instantane- W. I'd stick with five or six. That's what Microsoft ous switching between them. It's like having uses on their Z80 Softcard. It refreshes the 6502 Apple A and Apple B with selection between every few cycles to keep it active. The 6502 is them. still used for things like d isk I/O, even when the W. That sounds pretty good. One problem that I Z80 card is activated. have with the auxiliary RAM slot of the He is S. The R/W line on the Apple II does not disable that it won't easily support 256K RAM chips. ROM, If a program writes to a ROM address, You run into problems because only the multi- the ROM fights with the 8T28 bus driver for plexed RAM address bus for 64K RAM chips is control of the data bus. available at the auxiliary slot. W. Yes, that's right. That probably could have been S. I'd never thought of that. Large auxiliary bank done differently. switched memory units might be easier to design for the peripheral slots than the auxil- S. You could have connected R/W to the third chip iary slot. select input to ROM. W. I'll tell you about a timing problem that will W. That's an interesting idea, but there may be interest you. My first design for the Apple II reasons why it w^on't work. I'd have to study the used a display method in which the 6502 was timing and schematics, stopped for 40 microseconds. The Synertek data S. You said ' your speech that Mike Scott in sheet said you could stop it for 40 microseconds, assembled the old red reference manual and but I was having problems. The G502s would Chris Espinosa wrote the more recent one. work for a while, but the Apple would eventu- W. Yes. Chris started working with us when he was ally stop working, I always had to have a new still in high school. He got in trouble at home for 6502 in my pocket in case it happened. staying up late working with us. He did a ter- S. You mean the 6502 operated for 25 cycles, then rific job on the reference manual and he was Just the video display operated for 40 cycles? a college student. I was very glad to see Apple list his name as the author inside the cover. He W. That's right. When I designed the Apple II, dynamic RAM was just becoming available that deserves a lot of credit. could be accessed at two Megahertz. When it did S. Programming is a very slow process for me. I'm become available, I changed the design of the amazed at your ability to effortlessly knock out **The Apple lie has an area of RAM. referred to by Apple as the a program like Integer BASIC. bank switched RAM, which behaves almost identically to the W. You've got that entirely wrong. It takes me 16K RAM card in older Apples. Another difference, besides the forever to write involved programs, too, I just one Steve pointed out, is that the old RAM card did not react to the INHIBIT' line of the peripheral slots. Pulling the INHIBIT' work very long hours for days on end when I'm line low in the lie inhibits the bank switched RAM, giving firm- on a project. Writing Integer BASIC was not ware cards and the like priority over the bank switched RAM, easy for me. Appendix 1-4 S. It's too bad your BASIC doesn't do floating point W. Yes. he made considerable contributions. arithmetic. S. Who first wrote the DOS? W. I've often regretted not changing it to floating W. I wrote the parts that communicated directly point. The problem was that I had reached the with the controller, and Randy wrote the rest. limits of the program structure and it would major S. You came up with those phase control tables for have been d iff icult to expand it without a stepping the head. rewrite. Inyour speech, you talked about Randy working W. That's right. I did all of that stuff. S. with you on the disk controller. Is that Randy Arrival at the PSA terminal ends our conversation. Wiggington? Have a nice flight, Steve, and take care. appendix J Baseplate and Motherboard Removal Separation of Baseplate from White Case Removal of Motherboard from Baseplate 1. Unplug the Apple and remove all peripheral L Disconnect the speaker and power supply plugs cards. Disconneetthe video cable and any extra- from the motherboard. neous wires. 2. In older Apples, there is a nut on a screw pro- 2. Move the Apple to a convenient work area. Place truding through the center of the motherboard. it face down on a soft surface which won't mar Remove the nut using a nutdriver or socket and the case. driver. 3. Remove the ten screws pictured in Figure J. 3. On newer Apples, there is a metal reinforcing bar in the back between the motherboard and 4. Place one hand underneath the Apple and one the baseplate. It is held in by two or four screws. hand on top. Carefully turn the computer right Remove the retaining screws and si ide the rein- side up while holding the baseplate against the forcing bar out. case. 4. There are a number of white plastic retainers 5. Remove the keyboard plug from its socket on the protruding through the motherboard. Pinch the motherboard and separate the b^eplate from clips on each retainer together in turn and the white case. gradually work the motherboard off. 6. Reassembly is the reverse of disassembly. 5. Reassembly is the reverse of disassembly. Appendix J-2 BOTTOM VIEW OF APPLE II COMPUTER Figure J Remove the 10 Screws Pfctured to Separate ttie Baseplate from ttie White Case. appendix K List of Figures and Tabies Figure 1.1 TEXT and LORES Graphics. Figure 4.7 Cycle Stealing DMA. Figure 1.2 How the Game I/O Plug Should Be Designed. Figure 4.8 Schematic: D MAnual Ccmtroller, Figure 2.1 A Hypothetical Four-Line Bus. Figure 4,9 A Screen Mode Controller, Figure 2.2 Basic Microcomputer Building Blocks. Figure 4,10 Schematic: An NMI Based Single Stepper, Figure 2.3 Communication on the Bus System. Figure 4.11 The Author's Front Panel. Figare 2,4 The Apple II Bus Structure Showing Disk, Figure 4.12 Assembler Listing: NMI Stepper Routines, Cassette, and Serial I/O. Figure 4,13 Design Concept for a Hardware Breakpoint Figure 2.5 Secondary Address and Data Connections Generator. Extend the Address Bus and Data Bus. Figure 5.1 RAM Timing Signals from the Timing Figure 3.1 Functional Flow: The Timing Generator and Generator, the Video Scanner. Figure 5.2* Schematic: Apple II RAM. Figure 3,2 Idealized Timing Diagram for the Timing Figure 5.3 The Functions of the Address Multiplexer. Generator. Figure 5.4 128-Byte Video Memory Segments Consi.st of Figure 3.3 Timing Diagram for the Timing Generator, Three 40-Byte Sections, Each Mapped Into a Showing Propagation Delay, Different Part of the Video Screen. Figure 3.4 Propagation Delay Hierarchy. Figure 5.5 TEXT/LORES Displayed Memory Map. Figure 3.5 Distribution of Timing Generator Outputs, Figure 5.6 TEXT/LORES Video Scanning Map. Figure 3.6 The 6502 Machine Cycle Slightly Lags the Figure 5.7 HIRES Memorj' Areas (Page 1). PHASE Clockpulse. Figure 5-8 HIRES Displayed Memory Map- Figure 3,7 Exaggerated View of a Television Scan. The Figure 5.9 HIRES Video Scanning Map. Apple Scans 262 Times Horizontally for Each Figure 5.10 Schematic: The Address Multiplexor. Vertical Sean. Figure5.il CAS' Signal Example, Figure 3.8* Schematic Diagram: The Timing Generator. Figure 5.12 Timing Example: A 6502 Read Cycle to Figure 3.9* Schematic Diagram: The Video Scanner. Address $1000. Figure 3.10a Assembler Listing; A Screen Splitting Figure 5.13 Timing Example: A 6502 Write Cycle to Program. Address $1000. Figure 3.10b BASIC Listing: A Split Screen Example, Figure 5.14 Timing Example: A 6502 Read Cycle to Figure 3.11 Circuit to Generate a 6502 Interrupt 416 Cycles Address $C010. Before the Start of the Screen Display. Figure 5,15* Schematic: The 16K RAM Card. Figure 3,12 Circuit to Separate a Vertical Sync Pulse from Figure 5,16 Schematic: Bank Switching Motherboard the Television Syne Signal at Pin 19 of Slot 7. RAM, Figure 3.13 Circuit that Duplicates the Vertical Section of Figure 5,17 Screen Memory Scanning. the Video Scanner, Figure 5.18 Integer BASIC Listing: Underline Program, Figure 3.14 Assembler Listing: Syncronizing the Video Figure 5.19 Assembler Listing: Underline Program. Scan Simulator, Figure 6.1* Schematic: ROM in the Apple II. Figure 3.15 A Programmable Interrupter, It Generates an Interrupt Before Any One of 256 Selected Figure 6,2 Timing Example: ROM Read, Address $FO00. Horizontal Lines. Figure 6,3* Schematic: The Firmware Card. Figure 3.16 A Programmable Video Interrupter Card, Figure 6.4 Timing Example: A Read From Address Figure 4.1 6502 Pin Assignments. 5F0O0. Firm ward Card Enabled. Figure 4,2* Schematic; 6502 Connections in the Apple II. Figure 6.5 Construction of a Socket Adaptor, EPROM to Figure 4.3 6502 Clockpulse Relationships. ROM. Figure 4.4 Some Worst Case 6502 Specifications. Figure 6.6a An Added Switch to Control the F8 ROM on Figure 4-6 Experimental 6502 Timing Relationships, the Firmware Card. Figure 4.6 Reading the Disk Input Port Using Device Figure 6.6b This Circuit Syncronizes Switching to Prevent Select'. Poasible Program Crashing. i Appendix K-2 Figure 6.7 Circuit to Allow Independent Selection of the Figure 9.11 The DOS 3.3 Logic State SeAuencer. F8R0M. Figure 9.12 Timing Example: Sequencer Control While Figure 6.8 Method for Isolating the F8 Chip Selects from Changing the READ/WRITE or Other ROM Chip Sele<;ts. SHIFT/LOAD Switches, FigTirc7.1 Schematic: Address Decode. Figure 9,13 Timing Example: Switching to Write After Figure 7.2* Schematic: Generation of Address Decoded Checking Write Protect. Signals. Figure 9.14 Flowchart of the Write Sequence. Address Decoding in the Apple is an Exercise Figure 9.15 Diskette Formatting. Figure 7.3 in Division by Eight. Figure 9.16 Simplified Flowchart of the Read Sequence. Timing Example: 6502 Access to $C080. Figure 9.17 Decision Points for Reading ZEROS. Figure 7.4 Figure 7.6* Schematic: Serial I/O Devices. Figure 9.18 Read Performance of the Logic State Cassette Input Wave Shaping. Sequencer. Figure 7,6 Figure 7.7* Schematic: The Apple II Keyboard. Figure 9.19 Jim Aalto's FiniteState Automaton Diagram. Schematic: The Apple II Plus Keyboard and Figure 9.20 Flowchart of RWTS Routine, Figure 7.S* Encoder Board. Figure 9.21 A Single Switch on the Front of the Drive Peripheral Slot Connections. Allows the User to Select Normal, Forced Figure 7.9* Figure 7.10 Some Revision-7 Additions. Write Protect, or Bypass Write Protect, Figure 7.11 Assembler Listing: A Paddle Read Program. Figure 9.22 A Drive With the Write Protect Switch Installed. Figure 7.12 A Modified Game I/O Plug. Wiring a Paddle Set Plug. Figure 10.1 Temperature Measurements Inside an Apple II Figure 7. 13 Figure 7.14 This Game I/O Extender Can Support Two Plus. Sets of Paddles and Two Joysticks Figure 10.2 A Power Supply With the Bottom Off. Simultaneously. Figure 10.3 Some People Just Shouldn't Handle ICs. Figure 7.15 Game I/O Extender Configurations. Figure D,l BASIC Listing: Program that Produces Figure Figure 7.16 Schematic: Game I/O Extender. 5.8. Figure 7.17 The CTRL-RESET Modification, for Cider Figure D.2 BASIC Listing: Program that Produces Figure Keyboards. 5.9. Figure 7.18 Installation of SHIFT Key Mod, for Older Figure E.l A D-Type Flip Flop. Keyboards. Figure E,2 The Circuit Equivalent of the 6502 AND Enabling Lower Case. Apple II Plus. Instruction. Figure 7.19 Figure 7.20 Two Volume Control Methods. Figure J Remove the 10 Screws Pictured to Separate the The MPU, Video Scanner, RAM, and Video Baseplate from the White Case. Figure 8.1 Generator All Play a Part in Creating the I^ble 3.1 Durations and Frequencies of Timing Signals. Video Display. Table 4.1 6502 Instructions. Figure 8.2 The Apple II Video Signal. Table 4.2 6502 Instruction Cross Reference. Video Generator Functional Flow Diagram. Table 4.3 Operation of Soft Switches from D MAnual Figure 8.3 Controller. Figure 8.4 Apple Text Patterns. Figure 8.5 Blanking During Television Scanning Causes Tkble 4.4 Selection of 16K RAM Card or lie Bank the Black Margin Around the Apple Display. Switched RAM from D MAnual Controller. Figure 8.6* Schematic; Video Generation, Table 5,1 MPU/Scanner Equivalent Address Bits. Schematic: Revision-7 and RFI Version Table 5.2 Screen Memory Usage Summary, Figure 8,7* Changes to Video Generation. T^bie 5.3 The Video Scanner Row Address Assignments, Figure 8.8 Video Output Examples. T^ble 5.4 16K Ram Card Address Bus Commands. Figure S.9 The Output of the Screen Splitting Program Table 5,5 16K Dynamic RAM Chips. (Figure 3.10). 'I^ble7.1 Address Decoded Signals, HIRES Interference at Pattern Borders. Table 7.2 Relation of ASCII to Keypress. Figure 8.10 Figure 8.11 LORES Patterns at BIO. Pin 5. Table 8.1 Eurapple/NTSC Differences. LORES Colors. T^ble 8.2 Size/Distance Ratios on the Apple Screen. Figure 8,12 Figure 8.13 Switching from GRAPHICS to TEXT in Table 8.3 The Division of Screen Text Patterns in a 2048 MIXED Mode. x8R0M. Functional Diagram of the Disk Interface. Ibble 9.1 Disk II Controller Commands. Figure 9.1 Figure 9.2 Data Transfer in Disk I/O. Tible 9.2 Functions of the $C08C,X/$C08D,X and Figure 9.3 Simplified Functional Diagram of Disk 11 $C08E/$C08F Switch. Drive. Table 9.3 Logic State Sequencer Command. Figure 9.4 A Stepping Motor. Table 9.4 Syncing the READ Sequence to Data. Figure 9.5 The Write Field is the Vector Sum of the Table 9.5 Data Valid Periods in Sequence Clocks. WRITE and ERASE Fields. Tabled 6502 Timing Comparisons. Figure 9.6 When Reading, the Lack of a Read Pulse at a Table C.2 6502 Instruction Execution Periods in Machine Regular Interval Represents a ZERO. Cycles. Figure 9.7 Block Diagram of the Disk II Controller. Table E Basic Logic Gates. Figure 9.8* Scheniatic: The Disk II Controller (Address T^ble F Number System Equivalent Representations. References Assume Slot Gj. Table G Apple II Revision Numbers. Figure 9.9 BASIC Listing: Program to List State Sequencer ROM. •This schematic can be found in the Schematic Diagranri section, Figure 9.10 The DOS 3.2 Logic State Sequencer, as well as In the text. J SchemoNc Diagrams For ease of reference, most of the schematic dia- Apple II are layouts created by the author in an grams which appear in the various chapters of the attempt to make the information contained there book are grouped together here. This includes the more understandable to the reader. The primary schematics of the hardware manufactured by Apple sources of detail for these drawings were the sche- Computer, Inc. The schematics in this section are matics contained in the Apple U Reference Manual, identified in Appendix K with an asterisk next to and the The DOS Manual. Schematics of the firm- the figure number. ware card, the 16K RAM card, the Apple II Plus Numbers in parentheses next to signal terms in keyboard, the read/write head assembly, and some the schematics are figure references showing the undocumented Revision 7 changes are the result of number of the figure where a signal is generated or investigationsof the actual hardware by the author. to which asignal is sent. Small circles with numbers Some changes were made to the schematics to in them on peripheral card schematics represent reflect revisional information which is contained in pins on the card's edge connector. The Apple II Circuit Description by Winston Gay ler, The schematics contained in Understanding the {Howard W. Sams & Co., Inc. 1983). 2 Understanding the Apple s ::S 3 3 n1 Hi' I ,1 f-nf— 111 a ^* —Ww-T 5 3 + ^S Schematics 3 7^LS04 V'p^ 9 (3.ai LDPS' 15 V VCC >rCK 03 V5 P3 D11 12 74LS161 Q2 -*V4 P2 4-BIT PRESETTABLE 13 P1 COUNTER Q1 -*>V3 PO 14 QO -*-VZ -iKdPR CET CEP CLR GND "TiF 50Hz SOFT 5-11 .5V ^>^ JUMPER 15 IN REV-1 VERTICAL tT" VCC V6 A«D LATER PRESET PR Q3 -VI V4 P3 P2 m 74LS161 02 12 -VO V3 4- BIT P1 PRESETTABLE 01 13 -VC COUNTER V2 PO 14 kJ;k QO VB VI I cet cep cih GND ' yi VO +16 |7 SOFT 5-11 VC 15 SV VB TC VCC P3 03 •VA P2 VA SOFT 5-11- Dt3 12 PI 74LS161 Q2 HPE' HPE' 4-BIT PO PRESETTABLE 13 COUNTER 01 -.-H5 H5 T 2 kCK 14 HORIZONTAL QO -»-H4 H4 PRESET -4jPR CE T CEP CLR GNO 10 T TJ- H3 SOFT 5-11 H2 15 SV HI TC VCC PR 11 03 •H3 HO P3 IN RFI REV, 014 12 R2B REPLACES -*P2 74LS161 Q2 -H2 PRESET A2-11 ANDA2-B 4BIT VALUES TO MAKE SOR 5 PI PO PRESETTABLE COUNTER 01 13 -*-H1 ^ — ^- i5V 14 .CK QO -^HO GND R2S ^CET CEP CLR 1K *10 t7 7^ -*S0Fr5 TO ALL jtlAZ ^ SCHEMATICS _-, SOFT 5-11 TO ALL j|«>a SOFT 5-8 TO ALL 'SCHEMATICS SCHEMATICS 74LS00 74LS00 The Video Scanner (Figure 3.9) 4 Understanding the Apple 74LS32 R/W' TWO 8T28s REPLACED NC NC BY ONE 3304 IN jy ADDRESS BUS AND R/W ^ t? 139 |8 BTS7 SrNC PHS2 VCC PHS1 34 R/WV- Da R/W 12 AO-*- 'H5 AO A1-^ Z»* A1 A2*- im A2 A3-*- 'HS A3 H7/H8 13 6502 :m* A4 MPU 14 A5-*- :hi A5 rH3 A6 16 A7-*- LH3 A? 1? :h3 A8 A9-- "M3 A9 AIO-^ :b4 AID 12^ £0 All All-*- 22 A12-*- A12 2 ^ 23 A13.*- A13 13. Jis 14 _ 24 A14 25 A15-<- :m 14 . A15 PHSO RDY HMr IRQ' RESET' VSS VSS SO ~stI Jl 64 44 ioT il zil jei 74LS04 RA01 IKn -£ ^(777.8) KEYBOARD 74LS08 CONMECTOR S[^ (3.8) 2 PHASE" DMA' POWER-UP RESET 3 5 (7.7) BtSET' IQ" mv DMA" : 2 2f 3 : 3 2 2 3 ; ; ; 3 ; 1 i 1 9 fl 9 1 SLOT SLOT SLOT SLOT SLOT SLOT SLOT SLOT 1 2 3 4 5 6 7 6502 Connections in the Apple II (Figure 42) Schematics 5 r^l <£>[ Lnj g'l g^l -r (Ni m «f m u3 6 Understanding the Apple gg^ « I ^ Si" 2 f\i ^3 ^r ' ^ S r^ < Bgsagsgig:;^ 5 S 9 5 9 5 5 a 'a 5e S ~g S Schematics 7 PERIPHERAL SLOTS ^ A "^ ANY PERIPHERAL SLOT CAN INHIBIT MOTHERBOARD ROM »RA01 BYPULLINePlN32L0W 32 32 3 32 32 32 p p 32 INHIBIT' DATA BUS ADDRESS BUS ts f24 CS2 vcc 19 A10 22 A9 17 D7 23 2316B AS 16 ROM 06 A7 DO 15 D8 DS A6 EO 14 EB D4 A5 FO 13 F8 03 A4 11 D2 A3 10 01 A2 00 A1 AO csr CS3' TF "?20 Y21 5V vcc F8 THERE ARE SIX ROM All Y7 O EMABLE' SIGNALS. ONE A FO A FOR EACH ROM SOCKET A12 Y6P^ B E8 A13 Y5 lo^a. C A14 Y4 .11 EO > E3 J2 D8 A15 FIZ ¥3 74LS08 74LS138 DECGOER Y2 j3 og J I/O STROBE' J4 C8 -TO PIN 20 OF ALL E2' Y1 (3.8) - PERIPHERAL SLOTS J5 CO ^1/0 DECODE ENABLE' PHASE 1 Er YO (7.9) SEE FIGURE 7,2 ROM in the Apple II (Figure 6.'!) 8 Understanding the Apple k ^ lO 4o r^ Schematics 9 PHASE1 MLSB F3D0-FFFF -F8R0ME^A8LE' F000-F7FF ,F0 ROM ENABLE' EBOO-EFFF _EB ROM' ENABLE' h(6,1) EO00-E7FF -EO BOM ENABLE' ROM ENABLE' DflOO-DFFF -Oe ROM EMABLE' MOO-DrFF -00 ROM ENABLE' C800-CFfF -I/O STROBE' TO PIN 20 OF ALL PERIPHERAL SLOTS (7.10) C0OO-C7FF USER1 ROM JUf^™ =< USER 1 PIM 39 OF ALL PERIPHERAL SLOTS —O O- ' (7.10) 7 C7XX ^ p "''"' 1,0 SELECT' 7 1/0 SELECT' Y5|q!LC5»L|/0 SELECT' Y4|oIL "^ i/0 SELECT' ' (7.9) I/O SELECT' ^2 C3XX ^^Q SELECT- 3 t^^- p !3 ifO SELECT' 2 ^14 cm i^Q 55LECT' 1 PHASE 1^ (3.8) CONTROL ''— DEVICE SELECT' PHASED (3.8)' v7V:h-£5™_TIMER TRIGGER (75) DEVICE SELECT' 7^ SERIAL IN (75) AB_i DEVICE SELECT' 6 d!1^5*L_CEM0 STROBE (75) *5 - Y5|3 ^° ^™ DEVICE SELECT' 5 3!!?.°^'^ -SPEAKER (75) . M- DEVICE SELECT' 4 ^(7.9) ^13C02X cftssEHE OUT (7.5) Y3jq]2_™L DEVICE SELECT' 14Ci3W pgg^ KEYBOMO STROBE (77) DEVICE SELECT' 7 ^ ^ISCCOX ^ g^p KEVBOARD ^^ ^g loll-^^ DEVICE SELECT' 1 (5.2, 5 10) 3l5_£5E_ DEVICE SELECT C050/C051 GRAPHICS/TEXT (8.6) 5 C052/CO53 NOMIX/MIX (8.6) 6 C0S4/C055 SOFT SWITCHES PAGE1/RftGE2(5.10) J 7 C056/C057 ^ LORES/HIRES (8 6) 9 C05fl/C059 ANO off/on'' J to CO5A/C05B AM OFF/ON J .(75) 11 C05C/C05D AN2 OFF/ON J SOFT 5-11 15, 12 C05E/C05F (3.9) AN3 OFF/ON J Generation <^ Address Decoded Signals (Figure 72) 1 Undensta nd ng the Apple i 1 5-^ s 5 a 535 Schematics 1 sso Si < O K 1 SS; £1 a -^ S" in' 2 :i '- *^ LJ L J I—111 0-^ Hi' ^1- ^ i i i _Q_ 1 CO cnca aa cqo 4-i iTiA (d| K^i ?|4 ?! "iT^" — sL'^d-. M. M J. O _^1 M. m: Ml- -^_st_iit -^ ^ ^/ 1 •vvw .vl ^. M.^ai._3^ «!l ^ < at o ^ ^ M. I 5-^^- M- _5t ^ ^ ^ M M. _st ^ M.:_ai ^ 12 Understanding the Apple ji 16 PIN DIP JUMPER TO MOTHERBOARD LATCHED KEyBOARD DAW TO RAM/ KEVBOiW) /^ PLUG 1 PINS \^' (KEYBOAHQ/ENCODER SWRD) Q] JACK Z PINS (NUMERiC WD) The Apple II Plus Keyboard and Encoder Board (Figure 7^) Schematics 13 a -A sv KEYBOARD CONNECTOR ^AAA- (7 7) POWEH-UP 21 2S 30 f31 DMA aOV NMI' IRO' RESET' Wlff At5 A 14 (Ill Aid AS EIGHT ADDRESS AS BUS A7 PERIPHERAL t£ SLOTS AS A4 A3 A3 Al AO £H_ PHASE TIMING mi_ r PHASE t CM? GENERATION BUS (3-8) flU_ m COLOBBEf (SLOTrONWI usEm DEVICE SELECT' ifOsrmBE' I/O SELECT- VIDEO (SLOTS 1-7 QWLV) GENERATION 'IDEO SYNC (SLOT 7 ONLY) 'MAIN DMA OUT tMMIBir NTERRUPTIN INIERRUPrOU! REVO REV I £ LATER VIDEO SYNC (8 6. B.7) DMA PfllORtTY CHAIN NC- HM (3.8) ] INTERRUPT PRIORtTV CHAIN NC- (O.Q.bD^^r 1 -t mOBREFO.B) REV 1 i LATER Peripheral Slot Connections (Figure 7.9) 14 Understanding the Apple II 3,91 SOFT 5-11 (3 91 TM- -IJV SV .1 , 1 12 III at3 MLS17J 14 T-ILS^J 16 e MLS35? IS B 74LS151 16 e 7JI.St*l on tn.& lEXT r 'i iNVCHT 14 MLSSr ? u kA^H T6 a i 71 1U H L NOfiH H H NiR'tr _ Video Generation (Figure 6/>) Schematics 15 (T21 TEXTCOMH ^4=^»^-pfe>^^'" flEV 8? 11 LSK (3 91 W-{i^»M>^ (SX) COlOfl RSF (TI) TEXT OlSOf TEXT PICTURE SISNM Revlsion-7 and RFI Version Changes to Video Generation (Figure 8.7> 16 Understanding the Apple SELECT" DEVICE [-7?, 1*- innaEi;Q. ADDRESS _ C0E6;7 — ' ABLE Q3 47K, A LATCH 22mF '" DRIVE COEa/9 I^ TH OFF DZ 04 DRIVE OFF/ON DELAY NE566 LSK rin CLH VCC CLR GHa (1SEC1 DUAL TIMER CU POWER RESET@K- i-^ OUT UP RESETt f.1 SEC) fi; INT IN(ffl) INT 0UT(5) in(^ DMAf24V Q SLOT EDGE CONNECTOR OUT^-^ 1^20 PIN DRIVE CONNECTOR The Disk II Controfler (Address References Assume Slot 6) (Figura 9 A} Index POl and F02 refer to the foldouts. and Apple 11 reliability 10-3 and disk boot 4-15, 9-1, 9-il Aalto. Jim 9-34 and interrupts 4-15 to 4-18 active- when -high E-3 and I/O links 7-22 active-when-low E-S. 1-4 to 1-5 and monitor modification 6-16 to 6-17 address bus 1-3. 2-1 to 2-13, FOl and RESET 4-16, 6-16 to 6-17, 9-11 and address decoding 2-6 to 2-12, 7-1 to 7-8 and 16K RAM card 5-31 and DMA 2-9, 4-5. 4-13 to 4-14 on firmware card 6-11. 6-18 to 6-21 andMPU 4-2 to 4-5, 4-7 to 4-9 (also see monitor) and peripheral slots 7-17 to 7-20 AX signal 3-3 to 3-10. 5-2. 5-6, 5-23 to 5-25 and RAM address multiplexor 2-9 to 2-11. 5-1 to 5-9, 5-21 and ROM 6-2 to 6-4 and serial I/O 2-6 to 2-12. 7-2 to 7-10 bandwidth 8-6, 8-33 to 8-34 and 6502 instructions 4-20 to 4-23 bank switching address decoding 2-6 to 2-12, 7-1 to 7-8. FOl motherboard RAM 5-34 to 5-35, 1-2 to 1-3 andR/W 7-8 motherboard ROM 6-1 7-19 to 7-20 , and 6502 1-3.4-6 RAM card bank 1/bank 2 5-26 to 5-30 list of functions 7-5 (also see INHIBIT') address fields. DOS 9-3. 94. 9-26 to 9-28, 9-39 to 9-42 baseplate 1-2 {also see DOS data formats) removal J-1 AND gate E-1 to E-3, gl-l BASIC vi. 1-1 to 1-2, 6-5 to 6-6, gl-1. 1-2 to 1-4 AND instruction E-1 to E-5 and disk I/O 9-34,9-,37 and paddle programming 7-25 ANIMATRIX 8-30 and Page 0/Page 1 4-5 annunciator 1-8, 2-12. 7-2 to 7-3, 7-6, 7-10, FOl and 6502 instruction details 4-20 to 4-21 Apple Computer. Inc. 5-26, 5-28. 6-2. 6-4, 6-6. 6-8. vi. 3-9. 4-1. in ROM 1-1 to 1-4, 2-6, 6-1. 6-5 to 6-6 6-13. 7-20, 7-34, 9-3. 9-4, 9-9. 9-11. 9-17, 9-34, 9-41, 10-3. programming 4-12 10-5. 10-7. B-1, G-1 to G-3. H-1 to H-2, 1-1 to 1-3 (also see Applesoft BASIC; Integer BASIC) Apple I! Baum.Alan 7-8. H-1, 1-2 history H-1 to H-2. 1-! to 1-4 Baum, Peter 1-2 overview 1-2 to 1-10 Beneath A pple DOS 9-3, 9-37 A pple II Circuit De)!criptimi G-1 Schematics-1 , bidirectional bus drivers 4-2 to 4-3. 4-5, G-3 Apple II Plus 1-4.6-6.G-2 and DMA 4-13 keyboard 7-13, 7-15 to 7-18 and write cycle 5-24 to 5-25. 7-9 Apple II Reference Manual v. 1-4, 3-9. 3-18. 4-11. 4-12. 4-15, (also see MPU; transceiver) 5-9. 5-11. 6-1, 6-4. 6-3. 7-12. 7-13. 7-15, 7-22. 7-24, A-l, E-4, binary information 1-3, F-1 to F-3 G-1 G-2. Sehcmatics-1 , binary number system vi. F-1 to F-3, gl-2 Apph II Reference Manual Addendum 3-9, 7-21 Bishop. Bob 5-36 Apple 11 Reference Manual for lie Onhj 1-4, E-4 bit 1-3, F-1, gl-2 Apple lie V, 1-7, 4-26, 7-13, 10-5, 1-2 to 1-3 blanking 3-10 to 3-12, 8-3 to 8-5, 8-28 Applesoft Basic 1-4, 4-12. 4-20 to 4-21, 6-6, 6-8. G-2, gl-1 (also see HBL; VBL; video signals) Applenoft Tutorial v Boole, George E-4 A pplesofi II BASIC Programming Reference Manual v Boolean algebra E-4 to E-5 Application Notes (see Hardware. Software Applications) Bootstrap ROM (also see ROM) 9-1, 9-10 to 9-12. gi-2 ASCII V, 1-6. 1-7. 7-17 to 7-18, 8-30 to 8-32, gl-1 BREAK aspect ratio 8-28 nag 44,4-18 assembler 4-11 to 4-12 handler 4-17 to 4-18 assembly language vi, 4-11 to 4-12, gl-1 instruction 4-17 to 4-19 Atari, Inc. 4-1, H-2 vector 4-18 audio (see Speaker) breakpoint Autostart ROM 6-6 hardware 4-29 to 4-32 and Apple II Plus 6-6, G-2 software 4-17, 6-16 2 Understanding the Apple bus 2-lto2-3,gl-2, FOl data fields, DOS 9-3 to 9-4, 9-26 to 9-28. 9-39 to 9-42 address (see address bus) debounce 4-24 to 4-25, 6-18. 7-13 to 7-17 Apple 2-3 decimal number system F-1. gl-2 drivers 2-1 to 2-3, 4-2 to 4-3, 4-5, ffl-2 fights 6-2 to 6-4, 6-8, 6-1 1 1-3 . DEVICE SELECT 4-8 to 4-10. 7-2 to 7-9, 7-19 to 7-21 multiplexed RAM address (see RAM) Digital Research 4-13. B-1 peripheral 2-3 (sm peripheral slots) DIP (Dual In line Package) 1-8, gl-3 RAM 2-3 disassembler 4-U, gl-2 ROM 2-3 disk controller 9-10 to 9-34 secondary buses 2-9 to 2-12 and bus structure 2-7 to 2-9 byte 1-3. gV2 Bootstrap ROM 9-1, 9-10 to 9-12 BYTE FLAG 9-26. 9-29 to 9-S4, gl-2 eommanddecoder 9-llto9-14 BYTE Magazine 5-32. 6-5 data register 9-17 to 9-24, 9-29 to 9-31 card cage 1-4, k1-2 drive select 9-13 (also see peripheral slots) head positioning commands 9-13 logic state sequencer (see logic state sequencer) CAS' 3-3 to 3-10. 5-2 to 5-6, 5-20 to 5-35 power-up reset 9-13 cassette I/O 1-8, 7-10 to 7-12, FOl read pulse processing 9-15 to 9-16, 9-29 to 9-35 and address decoding 7-2 to 7-6 and bus structure 2-6 to 2-8 READ/WRITE 9-13 to 9-14 and D MAnual Controller 4-27 SHIFT/LOAD 9-14 read/write routines 6-16 WRITE PROTECT signal 9-8, 9-12, 9-17 WRITE REQUEST' 9-7. 9-8, 9-13 to 9-14 schematics 7-6,7-10 WRITE signal 9-7. 9-22 to 9-24 cathode ray tube (CRT) gl-2 (also see video) disk drive 9-5 to 9-11 character sets 8-9. 8-30 to 8-32 analog card 9-3, 9-6, 9-17, 1-l chip select, ROM 6-1 to 6-3, 6-13, 6-21 apparent momentum 9-13 chrominance signal v, 8-5 to 8-6, 8-83 to 8-34 enabling 9-5.9-13 circuit symbols 2-2 to 2-3. E-1 to E-5 erase head 9-6 to 9-8 clockpulse 1-2 to 1-3, 3-2 to 3-S, 4-2, 4-6 to 4-10. E-3 motor speed up time 9-38 clockpulse jitter 1-2, 3-18, 9-24 (also see long cycle) power supply 9-5, 9-38 cold start reset 4-15 read interface chip 9-9 to 9-11 collector-OR (see wire-OR) read pick up signal 9-9 read pulse 9-9 to 9-1 COLOR BURST 3-9, 8-3 to 8-6, 8-8 to 8-13 read/write head 9-5 to 9-7 Color Burst Killer 8-11 to 8-13, 8-29, G-2 to G-3 reliability and repair 10-2, 10-5 COLOR DELAY' 3-5 to 3-7 stepper motor 9-2 to 9-7 color graphics 1-5 to 1-6, 8-6 to 8-7, 8-18 to 8-25 stepper motor response time 9-7. 9-38 to 9-39 COLOR REFERENCE 3-3 to 3-9, 8-5, 8-15. 8-18 to 8-25 write protect switch 9-8 to 9-9 color signals 8-5 to 8-7, 8-15, 8-18 to 8-25, 8-33 to 8-34 write protect .switch bypass installation 9-43 to 9^5 color subcarrier 8-33 to 8-34 writing to disk 9-7 to 9-8 colors 1-6, 8-6 to 8-7, 8-18 to 8-25 disk I/O 2-7 to 2-9. 9-1 to 9-45 COLUMN address 2-11, 3-9, 5-1 to 5-6. 5-23 to 5-24 bypassing write protection 9-43 to 9-45 COLUMN limited RAM access 5-32 controller (see disk controller) data formats (see DOS data formats) Command decoder 9-2, 9-10 to 9-14 data paths 9-1 to 9-5 (also see disk controller) DOS (see DOS) Commodore 4-1 drive (see disk drive) complement g)-2 hard sector 9-3 complementary colors g-1-2, 8-15, 8-18 to 8-19 head positioning 9-5 to 9-7. 9-11, 9-13. 9-38 to 9-39 compilers 4-12. gl-2 programming 9-11 to 9-15. 9-17 to 9-24, 9-29, 9-.34 to 9-42 composite video 8-3, 8-6. ffl-2 (also see video) read process 9-4 to 9-5 COUTl 7-21 to 7-22 RWTS (seeRWTS) CP/M (Control Program for Microprocessors) soft sector 9-3 to 9-4 4-13, 5-26 CSW (Character output SWitch) write process 9-5 7-21 to 7-23 write protection 9-6. 9-8 to 9-9. 9-12. 9-17 to 9-22 cursor 8-31 to 8-32 display, video (see video: screen) cursor moves 1-7, 6-6, 6-11. 6-16 cycle stealing 4-13 to 4-14, 4-24 DMA (Direct Memory Access) 1-5, 2-9, 4-13 to 4-15. gl-3 andMPU 1-5, 2-9, 4-2 to 4-5, 4-12 to 4-14 data bus 1-3, 2-1 to 2-13, FOl and maximum PHASE hold off 4-13 to 4-14 and DMA 2-9.4-13 and READY 4-14 andMPU 2-4 to 2-10, 4-2 to 4-5, 4-7 to 4-10 cycle stealing 4-13, 4-24 to 4-26 and peripheral slots "7-17 to 7-20 delayed video 1-6, 8-18 to 8-22 fan. cooiinff 10-3 to 10-4 distance ratios 8-28 FCC regulations 8-3. G-1, G-3 generation 8-8, 8-12, 8-15. 8-18 to 8-19 interference 8-20 to 8-22 fijTUres (see appendix K) memory scanning 5-12 to 5-21, 5-36 to 6-38 firmware 1-1 to 1-4, 2-6. 6-4 to 6-6, 9-1 resolution 1-6,8-19 (also see Applesoft; Autostart; BASIC: Integer: monitor; ROM) (also see LORES; video) firmware jicripheral card 1-8, 6-6 to 6-8. G-2, 1-2 Holt. Rod 9-21, H-2. 1-l. 1-2 and DMA Controller 4-26 to 4-27 and DMA priority chain 4-15, 4-26, 5-31. 6-10 Homebrew Computer Club H-1 jumpers 6-11. 6-18 to 6-21 horizontal blanking (see HBL) modifications 6-18 to 6-21 horizontal counter 3-11, 3-14 to 3-15 timing 6-UU)6-I2 horizontal PERIOD 8-9toS-14 flashing text 1-6, 8-7 to 8-8, 8-12 to 8-13, S-17, 8-30 to 8-32 horizontal retrace 3-11, 5-13, 8-4, 8-10 flip-flop 9-24, E-3, gI-3 horizontal scan 3-10 to 3-12. 8-4 to 8-5. 8-10 floating bus 4-8 to 4-10, .^-25 to 5-26. 5-36, 7-8. 1-2 horizontal sync 3-10, 5-11 , 5-15 to 5-18, 8-3 to 8-5. 8-9 to 8-13 (also see timing diagrams) HRCG (HIRES Character Generator) 8-30 floating point routines 6-5 to 6-6 I/O (Input/Output) 1-4 to 1-9, 2-6 to 2-12. Chapters 7-9 floppy disks 9-3.9-24 and address decoding 2-6 to 2-12, 7-1 to 7-8 Fourth Dimension 9-45 and bus structure 2-6 to 2-12 frequencies, Apple 3-3 to 3-4, .3-18 and firmware 6-5. 7-21 to 7-23 front panel 4-29 cassette 7-2 to 7-12 Fujitsu 5-32 disk 9-1 to 9-45 F8R0M 4-15.6-5,6-16 game socket 7-2 to 7-1 6-1 1. 6-18 to 6-21 kevboard 7-12 to 7-18 and firmware card links (CSW and KSW) 7-21 to 7-23 and 16K RAM card 5-3] port 1-8. 2-7. 7-9, gl-4 (also see monitor; ROM) peripheral slots 7-19 to 7-23 game I/O socket 1-8. 7-2 to 7-4, 7-9 to 7-11 serial 1/0 2-12, 7-2 to 7-12 and SH FT kev mod I 7-36 to 7-37 speaker 7-1 to 7-12 extending 1-8 to 1-9, 7-28 to 7-33 timing 7-8 to 7-9 gates (logic) 2-6, E-1 to E-5, gi-3 video 3-10 to 3-16, 8-1 to 8-34 4 Understanding the Apple I/O SELECT' 6^4, 7-2 to 7-9. 7-19 to 7-21 RAM card 5-27, 5-31 and disk controller 9-10 to 9-12 TEXT ROM 8-13 I/O STROBE' ti-2 to 6-4. 7-2 to 7-9, 7-19 to 7-21, 1-2 USERl 7-6,7-8,7-19,7-20 protocol 6-4 7 and 8 7-19.7-21,7-22,0-3 (also see seventh ROM) Kane, Gerry 4-13 IC 4pple II Bus Sfructure SLOT SLOT SLOT SLOT SLOT aoT SLOT SLOT 1 2 3 4 5 6 7 ADDRESS BUS JADOnESSSUS EXTENSION DATA BUS I DATA BUS EXTENSION VIDEO SCAN TIMING GENERATOR TIMING TO ALL BLOCKS r r Motherboard Componeni Locations VIDtU S(;ANNtH ROM RAM ADDRESS MUX RAM VIDEO GENERATOR -'OWER'UP RESET A DDflESS DECODE m PERIPERAL SLOTS m RAM DATA LATCH DATA MUX KEYBOARD izn SERIAL I/O POWER TIMING SENERATOR „ „ .VIDEO noflh ViDEO VIDEO 04 MPSA13 SPEAKER AMP . a3ZN3904VIDEODRIVER J GAME IfO m ! USERt lOIII LSOS ISBB 8197 8T97 8T57 6S02 ei2e ffT28 LStffi Wi LSSl \/ TWO BTJ8S REPLACED BY ONEa304mHFIHEV RAM JLfMPERE AND E2 REMOVE!) IN REV'7, II JUMPER LSI39 2315B 2316B 2316B 23166 231ffi Q ZSIfiS LStS LS!38 LS25S |]62N39Q4C0L0n6UlftST KILLER ii JUMPER LSIS 4116 1)16 4116 4116 4116 4116 4116 4116 ions LS1S3 LSB3 LS153 LS2S3 I JUMPERS 12-16 ARE 50H JUMPERS (REV-1 ANO LATER). 14C* JUMPER LS20 41ie 4116 4116 4116 411E 4116 4116 4116 LS161 LS161 LSB1 LS161 ^ LS153 S195 yyysyyoD nil' 411^ 4116 4116 4116 4116 4116 411& 1116 LStW L2S7 LSB1 LS32 JUMPERS 7-11 ON REV-7 AND LATER 7 B S175 S36 5S5 LS194 B mm ii LS174 LS2S7 LS2S7 LS174 LSW LS74 LSIB LS11 LS02 LSO? ^^" | Q52N39aitP0WER-