3-The Apple II
Mục Lục
3-The Apple II
CONTENTS
HARDWARE AND FIRMWARE
No hacker is completely satisfied with a project he is working on as long as it is possible to make improvements that make it better in some way. After Wozniak had completed design on the Apple-1, he already had in mind enhancements that would make his computer faster and more functional. He wanted to make it display in color. He worked to combine the terminal and memory functions of the Apple-1 by moving the display into main memory, allowing instant screen changes. None of these modifications were made specifically to make it a better product, or to make it more attractive for a customer to purchase. Wozniak stated:
A lot of features of the Apple II went in because I had designed Breakout for Atari. I had designed it in hardware. I wanted to write it in software now. So that was the reason that color was added in first — so that games could be programmed. I sat down one night and tried to put it into BASIC. Fortunately, I had written the BASIC myself, so I just burned some new ROMs with line drawing commands, color changing commands, and various BASIC commands that would plot in color. I got this ball bouncing around, and I said, “Well, it needs sound,” and I had to add a speaker to the Apple II. It wasn’t planned, it was just accidental… Obviously you need paddles, so I had to scratch my head and design a simple minimum-chip paddle circuit, and put on some paddles. So, a lot of these features that really made the Apple II stand out in its day came from a game, and the fun features that were built in were only to do one pet project, which was to program a BASIC version of Breakout and show it off at the club.[ ]
Wozniak added other features that he felt were important for a computer that was useful, one that he would want to own. Since the 6502 processor could address a total of 64K of memory, he designed the computer with the ability to use either 4K RAM chips, or the newer (and more expensive) 16K RAM chips. The first available Apple II computers came standard with 4K of memory, and more could be added, to a maximum of 12K (if using the 4K chips) or 48K (if using the 16K chips). Specially wired strapping blocks attached to the motherboard told the Apple II how much memory was present and where it was. According to the 1981 edition of the Apple II Reference Manual, the Apple could have memory in the following sizes: 4K, 8K, 12K,16K, 20K, 24K, 32K, 36K, or a full 48K. (These sizes were determined by the different ways that three RAM chips, either 4K or 16K, could be installed.) The strapping blocks were even designed with the flexibility of allowing blank spots in memory if there were no RAM chips available to fill those spots.
The first 4K of memory always had to have RAM present, since it was used by the 6502 processor, the ROM routines, and the text screen display. If, for example, you only had two other 4K RAM chips to install and you wanted to display hi-res graphics, you could strap one chip to the lower half of hi-res memory from $2000-$2FFF, and the other to the upper half of hi-res memory from $3000-$3FFF.[ ] Since 16K RAM chips cost about $500 when Wozniak designed the Apple II, not many users could afford them. Whereas the Commodore PET and the Radio Shack TRS-80 could not easily be expanded beyond the 4K they came with, the Apple II from the beginning was designed with expansion in mind.[ ]
The row of eight expansion slots was another feature about the Apple II that was a strong selling point. Unlike the TRS-80 or PET, you could easily expand the Apple II by simply plugging a card into one of these slots. This degree of expandability made it more expensive to build, however. Steve Jobs didn’t believe that anyone would ever need more than two slots, one for a printer and one possibly for a modem. Wozniak knew from his experience with computers at Hewlett-Packard that computer users would always find something to fill those extra slots, and insisted that they keep the number at eight.[ ]
MONITOR ROM
The built-in monitor program in ROM that Wozniak included with the Apple-1 made it easier to use out of the box than other first generation micro- computers. He wanted to increase this functionality, and provided additional commands to manage bytes at specific memory locations.
Wozniak’s friend Allen Baum helped code additional enhancements to his built-in ROM routines. This included code to handle screen text display, as well as the ability to create and handle different sized text windows (that is, make one or more user-defined text spaces within the standard 24 by 40 text screen, which scrolled text only within that space). The Monitor also in- corporated the cassette input/output routines, since the hardware supporting that was included in the Apple II.
Baum and Wozniak had previously published code for a 6502 disassem- bler in the September 1976 issue of Interface Age. This made it easier to examine and debug code, and was itself an outgrowth of the philosophy of the Homebrew Club of making all computer knowledge available to every- body. The published article was part of Apple’s culture of supplying software “free or at minimal charge”. An improved version of this disassembler was included in the Apple II Monitor. It became one of the most important and unique features of the Apple II, and a significant part of its open design; it allowed anyone to view the 6502 code that any program used.[ ] The increased functionality of the final code for the Monitor increased its size from 256 bytes (in the Apple-1) to 2,048 bytes (2K).
KEYBOARD
On the Apple-1, it was necessary for the owner to supply a keyboard. A specific keyboard that Apple recommended to its customers was one made by Datanetics, a company based in Fountain Valley, California. They had been in business since 1964, making keyboards for cash registers and adding machines. The computer keyboard sold by Datanetics had shaped key caps similar in feel to the popular IBM Selectric typewriter. As for keyboard layout, it was modeled after the keyboard on the classic Teletype model ASR-33.[ ]
(Note: The Datanetics keyboard was uppercase only. The version used on the Apple-1 and Apple II were very similar, with the exception of the common Teletype Control-key names stamped on the keys; the only named key that made it onto the Apple II version was the “BELL” printed on the G key.)
Steve Jobs asked Datanetics to make keyboards for the Apple II, and the company worked during the spring of 1977 to have enough available for the release of this new computer that summer. The shape and printing on the key caps was almost identical to the earlier Datanetics keyboard used on the Apple-1 with some small exceptions. A key for RESET was added, the arrow keys were added just above the right shift key, and the RETURN key was wid- ened. All of the Teletype remnant control code names were removed, with the exception of BELL on the G key. An unmarked special character was the right square bracket, “]”, accessed by pressing SHIFT-M.
Although the Teletype standard allowed entry of the left square bracket character, the backslash, and the underscore character (“[“, “\”, and “_”) from the keyboard, the Apple II did not offer a way to directly type those three characters.
BASIC
Having an expanded Monitor program in ROM and color graphics were not the only new features of the Apple II. Wozniak included an updated version of his Apple BASIC (known as Integer BASIC) in ROM. This was available immediately when the power was turned on, allowing non-hackers to easily write programs that used color graphics.
Apple never had an assembly source code listing for Wozniak’s Integer BASIC. He wrote it in machine language, assembling it by hand on paper:
I wrote this BASIC processor, and I wrote a little ALGOL simulator and got it simulated. It looked like it would work, but I had forgotten to build the machine. I had no assembler, that was another thing. To use an assembler, they figured that somebody was going to buy this processor to use for a company, and their company can pay a few thousand dollars in time-sharing charges to use an assembler that was available in time-share. I didn’t have any money like that, so a friend taught me that you just sort of look at each instruction, you write your instructions on the right side of the page, you write the addresses over on the left side, and you then look up the hex data for each instruction–you could assemble it yourself. So I would just sit there and assemble it myself. The BASIC, which we shipped with the first Apple II’s, was never assembled – ever. There was one handwritten copy, all handwritten, all hand-assembled. So we were in an era that we could not afford tools.[ ]
There never was an official source code listing of Integer BASIC at Apple. One of the few errors I am aware of in the Integer interpreter is one involving a single byte. If a line is entered that has too many parentheses, the “TOO LONG” error message is displayed instead of the “TOO MANY PARENS” message.[ ] Another error involved a FOR – NEXT loop too deeply nested (that is, having a FOR – NEXT loop within another FOR – NEXT loop). If the program repeatedly entered the beginning of the loop without hitting the NEXT statement, it would eventually cause a crash.[ ]
OTHER DESIGN FEATURES
One problem Apple had to deal with was getting FCC approval for the computer. The RF (radio frequency) modulator that had been designed gave off too much interference, and it was probable that the FCC would not approve it. (The RF modulator allowed a user to attach the Apple to a standard television receiver, instead of requiring the purchase of an expensive computer monitor.) Rather than have the release of the Apple II delayed for re-engineering of the RF modulator to get that FCC approval, Apple gave the specifications for the RF modulator to Marty Spergel. He ran a small company (called M&R Electronics) that specialized in obtaining hard-to-get parts that electronics and computer hackers wanted for their projects. Their agreement allowed M&R to make and sell the RF modulators, while Apple could concentrate on making and selling the Apple II. Dealers would sell an Apple II with a “Sup’R’Mod” (costing about $30) if the buyer wanted to see the graphics on their color TV. Jobs assured Spergel that the item would sell well, maybe as many as fifty units a month. (Years later Spergel estimated that he had sold about four hundred thousand Sup’R’Mods.) [ ]
Other features that Wozniak (and Allen Baum, who helped him with the project) included in the Apple II ROMs included the terminal software to do screen text display, expanded Monitor functionality, and cassette input/output routines. They added the ability to split the screen into different sized windows. They also wrote a disassembler, which was one of the most important features of the Apple II from the beginning and a significant part of its open design. It allowed anyone to view the 6502 code that any program used, and matched the philosophy of the Homebrew Club of making all computer knowledge available to everybody. In the Apple-1 days, when Apple was supplying software “free or at minimal charge”, Wozniak and Baum published an early version of their 6502 disassembler in a hacker’s magazine. It was designed to be loaded in memory on the Apple-1 from $800 to $9D8 and the routine could be executed from the monitor. This early code was quite similar to the disassembler that was later included in the Apple II ROM.[ ]
Having an expanded Monitor program in ROM and color graphics were not the only features in the Apple II that attracted people to it. Having Wozniak’s BASIC language in ROM, available immediately when the power was turned on, made it possible for non-hackers to write programs that used the Apple II color graphics.
MEMORY MAP
Wozniak devised the memory layout for the Apple II by using the Apple-1 as a template. Just as the cassette interface card on the Apple-1 started at $C100, on the Apple II the first slot used memory starting at the same location. Slot 2 started at $C200, and so on.
As on the Apple-1, Integer BASIC on the Apple II started at $E000 in memory, and covered most of the space left until the Monitor program started at $F800. Some of the space below the Monitor was also used for other utilities useful to assembly language programmers.
To understand the memory layout of the Apple II, consider this analogy: Imagine a cabinet with sixteen shelves, and sixteen separate slots or pigeonholes on each shelf (similar to those found in old roll-top desks). Each slot refers to a specific address in memory on the computer, and each slot can hold a number between 0 and 255. (Since a byte is eight bits wide, the largest number that can be represented by eight binary bits is 255.) The top shelf is row “0”, and the leftmost slot in that row is slot “0”. The address of that slot, then, is $00. As we move to the right, the addresses increase, $01, $02, $03, and so on to $0F at the end. We then go down to the next row, (row “1”), and the addresses continue in the same fashion with $10, $11, $12, and so on as before. The sixteenth row is row “F”, the rightmost slot in that row is slot “F”, and the address of that slot is $FF. This cabinet has, then, 256 slots (16 x 16), and represents what is called a “page” in the Apple memory. The cabinet itself has an address (since computers need addresses for everything), and this one’s address is “00”. The full address of row “5”, slot “A” on cabinet “00” is $005A, and the value that is at that location (in this example) is “6F”.
Page 00
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
0
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5
.
.
.
.
.
.
.
.
.
.
6F
.
.
.
.
.
6
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
7
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
8
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
9
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
A
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
B
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
C
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
D
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
E
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
F
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Only the Altair 8800 came with just 256 bytes of memory, so we have to account for the entire 64K memory space that the 6502 chip in the Apple II can handle. There is a cabinet sitting on top of cabinet “00”, and it is laid out in the same fashion with its 256 slots in sixteen rows. This is cabinet “01”, and on top of that one is cabinet “02”; this continues on up until we reach cabinet “FF” way up at the top. Apple programmers refer to these cabinets as “pages” of memory. There are 256 pages of memory, each with 256 bytes on a page, making a grand total of 256 x 256 = 65536 bytes of memory (or slots that can hold a number, if you prefer the analogy).
In discussing the memory map on the Apple II, we can refer to pages of memory with a hexadecimal two-digit number for shorthand if we wish. The general layout of the Apple II memory is as follows:
RAM Organization and Usage
Page #
Dec
Hex
Used for:
0
$00
System Programs
1
$01
System Stack
2
$02
Input Buffer
3
$03
Monitor Vector Locations
4
$04
5
$05
6
$06
7
$07
Text/Lo-Res Graphics
Primary Page Storage
8
$08
9
$09
10
$0A
11
$0B
Text/Lo-Res Graphics
Secondary Page Storage
FREE RAM
12
$0C
through
31
$1F
FREE RAM
32
$20
through
63
$3F
Hi-Res Graphics
Primary Page
Storage
FREE RAM
64
$40
through
95
$5F
Hi-Res Graphics
Seconary Page
Storage
FREE RAM
96
$60
through
191
$BF
FREE RAM
192
$C0
I/O and softswitches
193
$C1
through
199
$C7
I/O shared ROM space
Page $00:
used by the 6502 processor for storage of information that it can access quickly. This is prime real estate that is seldom available for general use by programmers without special care.
Page $01:
used by the 6502 for internal operations as a “stack.”
Page $02:
used by the Apple II firmware as an input buffer when using the keyboard from BASIC, or when a program uses any of the firmware input routines.
Page $03:
general storage area, up to the top three rows (from $3D0 through $3FF) which are used by the disk operating system and the firmware for pointers to internal routines.
Pages $04-$07:
used for the 40-column text screen.
Pages $08-$BF:
available for use by programs, operating systems, and for hi-res graphics. Within this space, Woz designated pages $08-$0A as a secondary text and lo-res graphics page (although it was not easy to directly use, as the firmware did not support it), pages $20-$3F for hi-res “page” one, and pages $40-$5F for hi-res “page” two.
Page $C0:
internal I/O and soft-switches
Pages $C1-$C7:
ROM assigned to each of the seven peripheral cards
Pages $C8-$CF:
switchable ROM available for each of the seven cards
Pages $D0-$D7:
empty ROM socket #1
Pages $D8-$DF:
empty ROM socket #2
Pages $E0-$F7:
Integer BASIC ROM
Pages $F8-$FF:
Monitor ROM
The memory space on the Apple II between $C000 and $CFFF was assigned to handle input and output. From $C000 to $C0FF the space was reserved for various soft-switches used to control the display, and various built-in I/O devices, such as the keyboard, paddles, annunciators, and the cassette port. (A soft-switch is simply a memory location that, when a number is stored there, changes something in the computer–such as switching on graphics mode.) The remainder of the memory locations for $C100 to $CFFF was reserved for use with the peripheral cards plugged into the slots. Each card was assigned 256 bytes that were unique for the slot in which the card was plugged; that is, a card in slot 1 used $C100-$C1FF, a card in slot 2 used $C200-$C2FF, and so on, up to slot 7 using $C700-$C7FF. Code written on a card was ordinarily written in such a way as to not make direct reference to the $Cx address, so it would work in any slot in which the card happened to be used.
Therefore, each slot had an additional 2K of ROM space to use, the space from $C800 to $CFFF was switched in for each card when it was being used. A hardware flag on each card could be set to indicate that code in that memory space would be used for that card. This hardware flag is set when the input/output line on that card is selected (though it does not apply to a card used in slot 0). When the address $CFFF is accessed, this hardware flag is reset, making the $C800-$CFFF space available to other cards. Often, code on a card would be written to hit this memory location before trying to use it, to be sure it had been disabled from the last card that used that space.
The memory from $D000 to $D7FF and $D800 to $DFFF was empty on all early Apple II computers. On the motherboard were two empty sockets that were available for the user to plug in their own ROM chips. The $D000-$D7FF space was most often used by a plug-in ROM chip sold by Apple, known as “Programmer’s Aid #1.” It contained various utilities for Integer BASIC programmers, including machine language routines to do the following:
- Renumber BASIC programs
- Append one BASIC program to the end of another
- Verify a BASIC program that had been saved on tape (to confirm it was an accurate save)
- Verify non-program data that had been saved on tape
- Relocate assembly language routines to a different location in memory (most would only run in one place in memory)
- Test the Apple II RAM
- Generate musical tones through the built-in speaker
- Handle hi-res graphics from BASIC, including code to clear the hi-res screen, set colors, plot points and lines, draw shapes and load shapes from tape.
All the routines on the Programmer’s Aid #1 ROM were written by Wozniak between June 1977 (the RAM test routine) and April 1978 (program renumber and append), except for the music routine, which was written by Gary Shannon.
The other empty ROM socket (covering memory from $D800 to $DFFF) was never filled by Apple. Various third-party vendors sold ROMs for that socket (or for the $D000-$D7FF socket used by the Programmer’s Aid #1 ROM), but none made enough of an inroad to be preserved in the INTBASIC file that would later be included on the DOS 3.3 System Master disk. In fact, the $D800-$DFFF space in the INTBASIC file on that disk contains an image of that same space taken directly from the Applesoft ROM! It is completely useless to Integer BASIC, of course, but disk files being what they are, Apple had to fill that space with something.
The Integer BASIC interpreter lived in the ROM space between $E000 and $F7FF. However, BASIC only used the space up to $F424. Between $F425-$F4FB and $F63D-$F65D could be found a floating-point math package that was not used by Integer BASIC, but was available for BASIC programmers who were astute enough to figure out how it worked. (An early Apple user group, the Apple Pugetsound Program Library Exchange, or A.P.P.L.E., sold a tape and notes by Steve Wozniak they called “Wozpak”, that documented some of these secrets of the Integer BASIC ROM.)
Between $F500-$F63C there was code that was known as the “miniassembler”, which was executed starting at the ominous address $F666. The miniassembler allowed you to enter short machine language programs using the standard 6502 mnemonics instead of entering the program byte by byte in the monitor. (These mnemonics were the three letter codes that referred to a specific type of operation; for example, “LDA #” represented the 6502 opcode $A9.) The $F689-$F7FC space contained Woz’s SWEET 16 interpreter. Wozniak wrote SWEET 16 to simulate a 16-bit processor; it simplified some routines he wrote for the Apple II ROMs, including the Programmer’s Aid #1 renumber, append, and relocate routines. Simply put, he took a series of hex bytes, defined them as “opcodes” the way he wanted them to function, and when executing the code used his SWEET 16 interpreter to translate the code into legal 6502 operations. It ran slower than standard 6502 code, but when memory space was at a premium it was better to have a slow program than to not have enough room for the program at all.
For those who are keeping count, there are a few unreferenced bytes in the latter part of the Integer ROM. Those bytes contained filler bytes that were not used as any program code.[ ],[ ],[ ]
The last part of the Apple II memory, from $F800-$FFFF, contained Wozniak’s Monitor program which has already been discussed above.