You are on page 1of 63
The IM Underground Volume #1 Introduction The Geneva-12, Geneva-9, Athens-18, and Monaco-9 fonts are needed to correctly view and print the files on this disk. The applications MacPaint, MacWrite, and Consulir’s Edit are needed to fully view and print the files. MacWrite could be substituted for Edit as long as the ruler is set up to emulate 6 character tab settings and 9 font such as Monaco-9 is used The disk contains the following files: Schematics Memory (MacPaint) Control Logic (MacPaint) CPU & ROM (MacPaint) IWH & VIA (MecPaint) Serial Interface (MacPaint) Address Multiplexer (MacPaint) Keybosrd & Mouse (MacPaint) 128K/512K (MacPaint) Hardware Info Keyboard Hardware (Maciwrite) Video Hardware (MacWrite) Sound Hardware (MacWwrite) VIA Hardware (MacWrite) Mouse Hardware (MacWrite) Keyboard ROM 802 1PAGEO (Edit) 802 1PAGE1 (Edit) 802 1PAGE2 (Edit) 802 1PAGES (Edit) Register Usage (Edit) Tho I Undergremad eae ©1985 Cherts Video Timing (MacPaint) Hacker Chart (MacWwrite) Empty Folder (Yes -- it is empty!) ‘System Info The System Revesled (MacWrite) The Small System (MacWrite) Resource Flags (MacWrite) 512K Upgrade (MacWrite) Beyond 512K (MacWrite) We strongly suggest that the reader also obtein (if they don't already have it) the software documentation Anside Macintash tram Apple as it provides veluable information bout the inner workings of the operating system and device drivers Please notify us of any errors and/or omissions so that future releases can be corrected ‘The keyboard ROM listings are from sn 8021 MPU that did not have Apple's copyright in or on it ‘The circuit board schematies are traced from several Macintosh logie boards. Apple, Apple Care, Finder, ImageWriter, Inside Macintosh, Lisa, Mac, Macintosh, Macintosh XL, MaoPaint, MacsBug, MaclWorks, Macirite, QuickDraw, Resource Editor, and Resource Mover are trademarks of Apple Computer’, Ino. Consulair is a trademark of Consulair, Ine Intel is 3 trademark of Intel Corporation. Fedit is copyright by John Mitchell, Motorola is a trademark of Motorola, Ine. Rockwell is a trademark of Rockwell international Synertek is a trademark of Synertek, Inc. Zilog is a trademark of Zilog, ine. ‘The IM Underground Volume #1 is available for $25 from: ‘The IM Underground 715 Church Strest #16 Ann Arbor, Michigan 48104 The I Gnéergranad © 1985 8 CASODD. __GESEVER. isd RAMH- RRO: RAY RZ: RAS: ees ARE: RAZ: Re: OTs sew I e12 2s cs SERU D- ‘TTOLORG. R10 1K 15. 66720IH2- R39 3.3Ka Conly on new boards) F83 FS - F12 = 4164-200 Comer 6S - G12 = 4164-200 TESTS fs IS zugant ‘SOURDER- E12 , E13 = 74LS244 © 7-83360Hz- FI3 , F14 = 74LS166R E15 , F1S = 74LS161A E14 = ASG = PAL IERS oo ‘SOUND/VIDEO FETCH SOUND /u 1 DE0- The Unslargranad (Memory) S = = ° es 2 eS = = = a 3 > No Np oP gP jp gD ae gp 2 > RP 2.2K9 OREN ROM LOW 23256 old/new board pinout senesoen | senesaen 28 3. SKA sesrsoat eS WaNeW NOSE EISSESESIOET i oo @ i Bt oa 04 ss 05 7 ls nessoo0cs 22 R20 3.3Kn isc : OF. D1 oS E- 013 ae A DIS. ca ibs ‘RESET OPS. AS- TPCT. alse tee meas enti) @ The I Uadargromd Ones (CPU & ROM) HOUSE.x1 HOUSE.¥1 iPLi—_, tt a) t ee eet 09 p10 on , p12 013 014 ors at 2 ScCER—f ios a3 2200 | ys ap SCCAI . ae 3 md Wye #9, 10 = cH Fi leer samme it pat Ato 3-1 a7 F380 26.832 eH y Ss Note: R43 and R44 are replaced + = low noise supply Optional «old boards only? by @ direct connection on older boards =120 +120 su Video out J?-1—v1DEOOUT J7-2— yo R44 2200 Horizontal sync J?-3—~—AISYRCI fudio out —J?-4——SoUNDOUT Vertical sync J?-S-——USYRC 45 Volts 7-6: Ground 7-2. =12 Volts 7-8 Ground J?-9- +12 Volts J?-10: nn. +12Ue [cz le 45Ue pp ye Battery J?-11——4.5U I Sh a ce, c9, C17, C21, C29 ~ cae (Add C51 for’a 512K version? 1 uF Ne 13 cle[t{[sfolr H vyfelteli [ENT Fletrals[-Tr nN [es ofclelal7[ulyvi7 ra stxjulz{[slo{il|, [er atztoli[-fa var dl Ghaaag : ero] ne mel? ne Sone . Intel 8021H MPU... lis 470 vss 100uH t : 200K tox # re 10K ; dtu r AWB 1, UCC TRC re fee : ihe a id 20 NC eee toss low 19 2a - ied L-Option red R-Option - cer £ 1 9 v1 Jie U/0 interrupter 2—L — brown: 270 3> ce nr car ¥? | (0S 3—ON— green 2700 2700 z70n red [pe- 4 ohO-— Black > > suc - HNC - =3>— uP +—blue [> B+ orange: x1 - be x2- viet 3>- GND - ‘Tha Oaclergrasmnd] bee — yellow J are 1 >- UCC - +> GND - (Keyboard & Mouse) Keyboard Hardware This document covers the Macintosh keyboard and it’s communications protocol. Electrically, the keyboard appears as a two dimensional array of ‘apen/closed switches that can be scanned by sending @ signal out one set of wires and then checking 9 second set for the signal to return. if a key is depressed, it will connect the twa wires attached to it thus ceusing 6 signal sent out one of the wires to be returned via the other. in the Macintosh, the actual srrangement consists of a 6 by 9 array where the 9 wire set is used to output @ signel and the 6 wire set is used to detect this same signal This array provides locations for up ta Sd keys of which 52 ere used in the US version (53 on international versions) Such an arrangement has one intrinsic problem - when more than two keys are depressed, it is possible for “ghost” keys to eppeer. For exemple, when three keys in an L shaped pattern are depressed, 5 fourth key will “appear” at the jest vertice of @ squere containing these four keys Therefore, certain keys that are used in conjunction with others may not be in this erray. The Shift, Gption, Caps Lock, and Command ere thus connected directly to the keyboard controler. Programatically, they can be thought of 48 being in the same array as the rest of the keyboard even though they are physically separate. The keyboard is controlied (and scanned) by an Intel 8021 single chip microcomputer. This device contains 1024 bytes of progrem ROM and approximately 65 bytes of internal RAM. It can execute up to 100,000 operations per second. Electrical power is supplied vie two of the four wires in the keyboard cable. The other two wires ere used to communicate in serial with the Macintosh. An almost identical arrangement cen be found in Apple's numeric keypad. The biggest difference is that the keyboard array size has been changed. The keyboard serial interface operates in an isosynchronous mode where @ clock signal is supplied an one wire while data is sent (or received) aver the other. The reason for the separate clock is that the keyboard does not contain a precise frequency source The format of the deta sent is the seme as a 7 bit asynchronous link that has one start bit and a one stop bit. The only difference is that the high order data bit is sent first. When the Macintosh wishes to send to the keyboard, it sets it’s serial output to 9 logic O and then loads a register with the data to send. Eventually, the keyboard will notice the start bit end respond by supplying the clock signal to clock the data byte to it one bit at a time. Should the keyboard wish to send to the Macintosh, it simply places Tho I Gadergranad <1 © 1985 it's date on the serial data line and generates the clock which allows the Macintosh herdwere to receive the data. Note thet the keyboard always generates @ clock for either deta transfer direction. Also, data can be sent in both directions on the same wire. (The data rate used in this interface is near 3300 bits per second.) The softwere in the keyboard operates by scanning all of the keys repeatedly until 9 change is detected. This key is then “debounced" end the Macintosh told about the change. In greater detail: The softwere starts at the beginning of the key erray and compares the present key status (pushed/not pushed) of each key with what it saw previously. When s change is detected, the software waits several milliseconds and then checks if the key is still at it's new state. If so, a code byte for this change is constructed snd placed in a short buffer. Eventually, the keyboard will be ‘able to send this code to the Macintosh. Once per keyboard checking loop, the keyboard checks the serial data line for 6 start bit. If there is one, it tries to receive the dats, Also, the keyboard will be checking it’s buffer for ‘any date to send that it is allowed to send. if there is some, it will be sent. The communicetions format used by the keyboard, keypad, and Macintosh between themselves is @ loose daisy-chained master/slave type of architecture. For a slave to send data, it must have permission to send given to it by the mester. Since the interface is @ bidirectional system without collision detection, the rules for its operation need to be closely followed. There are severs! cases where they mey be broken due to a time-out. These are listed below. The system is configured such that the Macintosh is always © master and the keyboard is always a slave. Any keypads (there could be more than one - although the Mac could get confused) in between act as a slave to the Macintosh (or next higher element) and as a master to the keyboard (or next lower element). There are 5 different commands that may be sent by the master. Of these, the Permission to send and Self test keyboard commands (hex 10 and 76) are only sent by the Mecintesh itself. If slave receives any commands other than these, the slave ignores them. The commands are: Request to send (Hex cade 14) This code is sent when the master wants data. The slave has permission to respond with one byte of date which it should do immediately. if it has no real data, a hex 7B should be sent. The 1 Gndergremad 2° © 1985 Permission to send (Hex code 10) This code is sent by the master to give the slave permission to send one byte of dats when it is generated. After this one byte is sent, (it need not be immediately) permission will once again be with the master. Reset and identify (Hex cade 16) This code is sent by the master to reset the slave and have it identify itself. The slave has permission to respond with one af the following 3 codes. Hex 02 if it is just a keyboard, hex 10 if it is just @ keypad, and hex 12 if both a Keypad and a keyboard are present. (The result of this command can be found in the system global KbdType at memory location $21E in the Macintosh.) Perform self test (Hex cade 36) This code is sent by the master to have the slave perform a test of its RAM. The slave hes permission to send a single byte result cade. Hex 77 is sent if there was an error and 8 hex 7D is sent if the RAM tested out OK. Remote self test (Hex code 76) This code is only sent by the Macintosh when both keypad and keyboard are present. The Keypad will pass a self test command to the keyboard and then pass the result to the Mac. If no Keyboard is present or if it does not respond, the Keypad will send back a hex 77 as an error code. As normal, permission will revert to the Macintash (the master) efter this result is sent, In reality any byte with bit DS set will be passed through with this same bit cleared If the slave does not respond in a short time period to a command requesting immediate response, permission to send will revert back to the master. This is so that if a device is not present, the master will not get stuck in a loop waiting for the (non-existent) slave, This also allows the slaves to be disconnected/connected at any time without destroying the interface integrity. The Macintosh normally operates any slaves below it in the Permission to send mode. Thus the slaves have a timeout made where they send @ hex 78 to say that they have no date if no activity tekes place for about a querter second. The keyboard will load its FIFO with a 78 after ‘The I Gndergroand _ 1985 the timeout but will not send the byte unless it hes permission to send Thus, if it is opersted in Request for data mode only, these requests should be at ¢ reasonsbly fast rate. If the keypad times out, it will send a bute of data even if does not have permission. Thus it should be polled with request, for dats at 6 reasonable rete or the master should essume that it does not have permission to send. when 8 keypad is in the system, it will operate the slave under it in a request for deta mode. This polling occurs at 9 reasonable rate. The date sent to the Keypad is storea ina FIFO so that it can ister be sent upon request to the Macintosh Data sent bys slave 91-68 Codes for keys as they are pushed down. 81-£B Codes for keys as they are released. 6D/ED — Unused by keyboard/keyped. SF/EF CTRL pusi/release, Ti/F1 SHIFT push/release. 73/F3_ CAPS LOCK push/release. 75/FS OPTION push/release, 7 Error from memory test. 79 Prefix to flag following key code as keypad key, 78 No change in status. 7 Memory test passed. TF/FF Unused by keyboard/keuped F?-FD Unused by keyboard/keuped. Commends sent by ¢ master 10 Permission to send 14 Request to send date, 16 Reset and identify all devices. 36 Perform self test in first receiving device. 76 Pass a self test command to the next device Tao IM Cadergromed _ @ 1985 Video Hardware A raster-scan video display (such as the one in the Macintosh) operates by scanning a bem of electrons across the screen (CRT), normally from left to right end top to bottom. The beam is modulated by the video signal - thus selectively activating the phosphor in the tube end causing it to emit Tight Scanning must be repeated at approximately 60 Hertz since the phosphor quickly stops emitting light. This article describes how the modulating signal is made and the side affects that are produced. Since the electron beam scans each dat (pixel) on the screen individually, the information to contral it must be sent one unit at a time. in the Macintosh, each pixel can be either black or white, so one binary bit of information is sufficient for each pixel. As the electron beam scons, it needs a continuous supply of bits (one at a time). This bit stream is produced on the digital logic board by the video display herdwere. This hardware elso produces two other signals - one to tell the electron beam when to return to the left edge of the screen and one to tell it when to return to the top. while the electron beam does this, it is kept turned off to prevent white lines on the screen in it’s path. (Ina black and white momior, there really aren't individual dots on the screen - rather, the shape of the modulating signal delineates the boundaries between pixels. The entire process is similar to dragging a pen across a piece of paper and selectively lifting and dropping it.) To continualiy scan the display, the present image on the screen is kept in memory (RAM) and reed out by the video hardware as it is needed. The Macintosh memory is 16 bits wide - thus this many bits are read at a time A device called a shift register is used to convert the 16 bits into a bit stream that is 16 units of time long - thus defining 16 pixels on the CRT. Incidentally, reading the video display performs another vital function ~ ‘refreshing’ the memory. This is needed because dynamic memory (as used in the Macintosh) consists of many smail, leaky capacitors, These must be continuously discharged or recharged ta retain their data, A reed (or write) operation on the memory is enough to refresh 128 (or 256) memory locations. Any description of the video timing must elsa include the memory timing since the herdware for these is strongly intertwined. Proceeding with this ~ the memory cycles 1958400 times per second, Each cycle is therefore about about 511 nanoseconds (nS) long, These cycles are divided evenly between the CPU and video with each device using alternate cycles. While video refresh is active (i.e., not in a retrace) it's cycles ore used to fetch The I Gadargromnd 1- 1988 video data for the CRT. Since these words are reed every 1.021 microseconds (uS), just enough bits will be fetched to meet the needs of the 15.6672 MHz video shift rate. At the end of every horizontal retrace, the video cycie is used instead ta read the sound and disk speed information from their RAM buffers. The remaining video cycles are given to the CPU to sllow the system to run faster. This can be done because the electron beam is in retrace and needs no video signal. (See the MecPaint document “Video Timing’) The figure has been arranged such that it contains all the memory cycles that happen during one camplete screen refresh (frame). Inciuding the retrace times, there are 9 total of 88*370 or 32560 memory cycles in one frame. This resuits in 9 screen refresh rate of 1958400/32560 or 60.147 Hz. As can be seen from the figure, each of the first 342 scen lines of the CRT contain 32 video accesses snd 32 CPU accesses in the ective part, and 23 CPU accesses and 1 sound/disk-speed access in the inactive (retrece) part. Also, the last 26 scan lines (which occur during vertical retrace) contain 87 CPU accesses and 1 sound/disk-speed access. One important resuit of the above is that the 68000 CPU cannot run at it’s full 7.6336 MHz speed from the RAM since at that rete, it could use ali 1958400 memory cycles in each second. If the CPU requests access ta the RAM while it is Being used by the video hardware, it will be forced ta wait for it's turn. However, internally, the CPU can still run at it's full speed This can be used to advantage by assembly languege programmers by careful arrangement of operations. For example, suppose the contents of all 8 date registers (D0-D7) need to be multiplied by some constant and then 6 different constant needs to be added to the results, One immediately obvious way of doing this is to heve & MULU (ar MULS) operations in @ row and then & ADD opcodes in a row. This arrangement is the not the fastest possible - the ADD operations will be limited by the speed that these opcodes can be fetched by the 68000. A better methcd would be to alternate the MULU and ADD opcodes. This way, the ADD opcode will be read into the 68000's instruction queue while the preceding multiply is teking place. The result is that the 66000 runs at it's full speed internally The memory used by the Macintosh for it's video display normally starts at $01A700 ($07A700 in 512K versions). However, knowledge of this address is not needed to program the Macintosh since QuickDraw will automatically set up it's data structures to use the correct range of memory. The hardware itself supports the use of 6 different range (page) of memory as an alternate source of video date - this video page begins exactly 32K bytes below the first. Since the herdware cen instantly switch The ID Cadergrannad ope © 1985, between the two pages, they could be used in extremely fast graphics applications. (None of the ‘standard’ application programs out yet use the second video page ~ mainly because it leaves very littie memory left for the program ona 12K machine.) There is almost no support in the operating system to allow use of the second video page. It is limited to the ‘Launch’ end ‘Chain’ opereting system calls. Both of these allow e selector code ta determine which video page will be used by the application. However, this only allocates an extra 32K of memory after the stack memory if the second video page is selected. It does nothing to switch the actual memory used by the hardware Furthermore, when 8 program is run from the Finder, it will be run with the first video page selected ~ the only way to actually run @ program with the second video page selected is to write a short program that calls the main program with the correct page setup. Finally, the ‘Leunch’ and ‘Chain’ routines do not insure thet the second video page is actually usable - a debugging program such as MecsBug may occupy that memory The best way use the second video page is to leunch the program hormelly, Then check if the present system is a Macintosh (ie,, not a Lise running HacWorks) by checking such things as the screen size and operating system version numbers stored in global RAM memory variebles and exiting if they ere incorrect. The presence of MacsBug (or e RAMdisk) can be detected by checking if the system globals BufPtr (at $010C) ond Scrnésse (at $0824) ere the seme. After this, the program can set up to use the second video page in one of two ways. If the memory space between the two pages (10860 bytes) is not enough for the stack space needs of the program, it can manually set the stack top just below the stert of the second video page. Otherwise, the stack can be left where it is and the memory space for the second pege reserved. Setting the spplicetian heap limit to @ point just. below that memory would suffice to reserve it - however, this does nat prevent the CPU stack from growing down into the video display. A better way would be to manually (i.e, not via the operating system) make the second video page 8 non-relocatable memory block at the very end of the application heap. This will allow the stack-averflow sniffer to operate normally and detect any stack overflows The I Gadergremad “3° ©1985 Sound Hardware Qverall, the sound generator can be broken down into four pieces of which three are hardware. These four pieces can then be arranged in 8 hierarchy through which “commands” flow. At the highest level is a program that controls all the hardware below it. This is part of the Macintosh Operating System and thus not 8 subject of this document. The level just below this is an arbitrary waveform generator. This can be thought of as 8 black box that converts input data into any autput desired. If the output of this box were graphed on the y-axis of a graph while the x-axis was time, the data supplied to the box would be all the y coordinates needed to produce the desired output, However, because this could require an infinite amount of data to produce certain sounds, certain limitations are imposed by the hardware. The main one is that the y values are only supplied at discrete {not continuous) time intervals. A smaller limitation is that the y values can have only a limited smount of precision, When this data is provided to the “black box", the intervals between the points are filled by interpolation The output of the black box is then sent to the third part of this hierarchy which is an audio amplifier. The amplification (or resulting output volume) that this section provides can be controlled by software. The final element of this hierarchy is the speaker or external stereo system connected to the audio output jack of the Macintosh The arbitrary waveform generator is essentially a Digital to Analog Converter (DAC). in operation, the data that is sent to this DAC is held in memory (RAM) in a buffer - so that it can be generated before the hardware actually needs it. As data is needed, the DAC is given the contents of successive locations of this buffer. This buffer holds enough data to generate 1/60th of a second of sound. The DAC itself is built in a somewhat unconventional way. The sound data coming fram the buffer is first converted inte variable width pulses by @ counter circuit. These pulses sre then approximately integrated over time by an analog circuit. The output of this is a voltage that roughly relates to the pulse width (which was originally controlied by the date from the buffer). The pulse width can be from 0 ta 255 units of time. A width of 255 will result in a positive pesk to the speaker while a pulse width of 0 makes a negative peak As the system is running, data velues are taken (by hardware) from the buffer at the end of every horizontal retrace af the video monitor. This is a rate of 15.6672/70d MHz or ebout 222545 Hz. This data is then loaded into an 6 bit “up” counter. Ouring the next horizontal scan line, this counter will The I Gadergrannd -1- © 1985, the next section of sound. The main or default buffer used most often is called the First Sound Page while the second buffer is called (naturally) the Second Sound Page. Each buffer contains 1/60th of @ second of sound or 370 samples. The buffer used is determined by sn output bit thet is controllable by the program making the sound, In 128K Macintosh, the first sound page starts at $1FD00 or 130304 decimal while the second page starts at an address of $1A100 or 106752 decimal. After this starting address, the sound dats occupies the even numbered memory locations. The odd locations are used to controi the disk speed and thus should never be modified in the process of producing sound. The last address used in the first sound page is SIFFE2 or 131042 decimal while the lest used address in the second page is $1A3E2 or 107490 decimal The above method for praducing sound output is very good at producing ‘nigh quality sounds but it also will teke e large amount of computer cower to generate the 22255 samples needed every second to produce sound. Although it is possibie to generate 1/60th second of sound and then allow this data to repest continusliy, doing this will limit the sound output to those frequencies that can be evenly divided into 1/60 second intervals. Therefore, there are two other ways to produce sound thet are less demanding on the microprocessor, Both of these involve a special control line to the 8 bit up counter used to produce the varying pulse widths. Both methods will also result in square wave output. A square wave signal is not ‘4 “pure” sound but rather it is the sum of a large number of sine waves which each are mathematically 9 pure sound. While the control tine to the counter is active, it will force the counter to a value of 0. This will result ino pulse width output of indefinite length for as long as the control line is active. If the sound buffer is entirely filled with the velue of 255 and the control is turned on and off, sound will be produced, This is because the pulse width will essentielly be changed from 0% to 100% depending upon the control line. This control line can be changed in two ways. The simplest is for the microprocessor to change it as needed to produce the desired sound Another way is to program one of the large scale integration chips in the Macintosh to produce @ square wave frequency there, Thus the frequency of a sound con be controlled with minimal processor control. An interesting effect can also be performed with this circuitry. Instead of loading the sound buffer with a! 255s, a real sound can be stored there. The square wave being driven into the counter will then toggle the sound on and off. This essentially adds @ second sound signs! to the output. Since the only way to terminate @ pulse from the counter is for it to count up to 255, there Tho I Oaderground -3- ©1985 will be @ delay of about 32 microseconds as the counter does this counting Normally though, this will be of no affect. The control Tine also has a second use; when set up to be controlled directly by the CPU, it is used to turn the sound on and off. Thus between sounds, all audio output can be shut off, Several precautions should be observed when designing sound output. The first of these is the limited frequency range of the audio output circuitry. At low frequencies, the gain of the amplifier is reduced, This should not be 8 big problem since most of these low frequencies won't be heard. However, for frequencies that approach the low end of the range, some extra amplitude must be given to account for the loss in the amplifier. At the high end of the spectrum, mare problems can result. Since each audio cycle of output will need et least two samples to produce the frequency, the highest possible frequency that can be produced is 11127 Hz. Also, since the filter circuit converting the pulse width signal will be filtering high frequencies, @ loss of amplitude will occur, This loss will be large enough so that it can not be made up with a larger magnitude of values stored in the sound buffer. Another precsution to observe is to use the control line to turn the sound off instead of just filling the sound buffer with s constant value (The buffer could be filled with 255's with no {11 affect though). This is due to the fect that while the counter is praducing any sort of pulse output, the filter will allow some of it to appear at the speoker output in the form of 9 very quite high pitched noise. The internal speaker will nat reproduce this well, but a home stereo system attached vie the audio output jack might. Another precaution is that when the contro} line to the counter is active, the effective output pulse width is 352 units. Since the range of outputs for the counter (when it is being fed date from the sound buffer) is only from 0 to 255 units, activating the control line will [in all cases] cause 4 large sudden change in the audio output signal. This will sound like a click or pop and is the reason that certein sounds start and end sharply. There is no solution to this problem, however, having sounds end at 9 pulse width of 255 (by filling the sound buffer with 0's) will reduce the megnitude of the change to the smsllest possible value. The three volume control bits each have approximately o binary weight. In other words, as the value represented by these bits is increased in a binary menner, the volume will increase in approximately equal steps. However, this pattern is not exact - writing the control bits most significant to least significant end assigning the 000 setting to have the relative volume level of 1, the following relationship holds: 000 = 1.0 , 001 220, 010241, 011251, 100279, 101=89, 10= 110, 111-120 The I Cadergrennd ae 1985 Thus the volume setting of 7 is twelve times louder than the setting of 0 Note that s control panel setting of 0 results in the sound being turned off in some programs while other programs will use it es just enother volume setting AN the contra! signais for the sound hardware come from © 6522 Versatile Interface Adapter chip. This component is itself as complicated as the sound circuitry so only a minimal amount of information about it will be presented here. For programming purposes, it can be treated as a set of sixteen memory addresses af which two are of interest for this column. At the memory address of 1110-1xxx-Hxx 1-11 1e-xxxx-xxxO, DO through D2 of the byte are the sound volume control bits. D2 is the most significant bit, D1 the next, and 00 the least significant bit. In the above address, the x's represent bits that can be either 0 or 1 (Apple seems to prefer to set these to I's.) Thus the address is SEFFFFE or 15726636 decimal. Since the other bits in this byte are used for other systern uses, the present value should be read, modified, and then written beck (preferably with interrupts turned off), In BASIC to set the volume to 5, this would be: IRA = 15728638! - POKE IRA,PEEK(IRA) AND &HF OR &HOS. Note: this does not change the control pane} (master) volume setting At the same location that the volume can be modified, D4 selects which sound page will be used. Setting this bit to @ 1 will select the first sound page. Putting @ 0 into this bit will select the second sound page. This bit should probably never be modified since the disk speed control data sisa comes from this sare page. When this bit is changed from BASIC, the operating system will still be using the first sound page and if any disk usage is needed, the system will “hang” At the address of 1110-Ixxx-HxXO-O00x-xxxN-KxNO (SEFETFE or 15720958), the contro} line to the counter is found. A t will allow the counter to operate end thus produce sound while «0 will force the counter to the 0 state. This bit is found in D7 and cen be read/written just like the volume control bits. Several other locations in the 6522 chip cen be used to command this bit to be connected ta the output of a counter. This is how e square wave audio output can be generated. ‘The 1 Ghdengremnad - @ 1985 VIA Hardware This document describes 611 the inputs and outputs avatladle through the Macintosh’s 6522 Versatile interface Adapter (VIA) chip. Since this is a rather complicated chip, the various other functions it performs internally will not be described. (For further informetion on this chip's internal operations, consult the Synertek or Rockwell manual about it.) The entire chip consists of 16 different byte wide registers through which all of it’s operations can be controlled. Secause of the way that. it is attached, each of the 16 registers is located 512 bytes apart in the Macintosh memory map. To find the exact address of each register, the register number should be multiplied by 512 and 9 base address added to this result. The final result {s the memory address to use, Normally the offset (register number * 512) is fixed sa that it can be coded directly into @ program. The base address ts also fixed (in the Macintosh). Assembly lenguage programmers cen use the global var VIAT at memory location $104 to find the base address of the VIA. The code to do this is actually 2 bytes shorter than loading the base address 2s an immediate velue (using the global variable takes one to two microseconds longer though). This global veriable normally contains the value $EFEIFE Once the base address is in @ register, the address register with displacement mode can be used to get to the desired register in the VIA Register number 15 (offset of $1600 and address of $EFFFFE) is used to access the input and output bits located in Part A (PAn}. A read operation will return the current value on the chip's pins. A write operation will only affect the current output bits. Bits that are inputs will still latch the veiue written, however it won't appear as an output until the line is changed to be ‘an output. Register number 0 (offset of 0 and address of $EFEIFE) is used to access those bits found on Port B. Mast of the 14 remaining registers are not needed while doing simple operations with the VIA. SVO, SV1, and SV2 control the sound volume, A binery value of 000 produces the lowest volume while 4 binary value of 111 produces the maxirum volume. Normally these bits will be altered only by the operating system, (It will set them to match the volume selected from the control panel.) However, as there is no routine to change the volume, a program ‘would need to alter these bits directly should it need to change the current volume setting. Apple recommends that this be done with the 68000's interrupt priority level set to "3" so that an interrupt cannot occur while the bits are being changed. When OVERLAY is 4 1, ROM memory is available at memory address 0. This is used during system reset to allow the 68000 to read a reset vector The I Cadengremad 7 1995 line. At present, this input is not used by the operating system. A possible use is to perform flicker free video page switching at a certain point in the video refresh. Another use is as a time bese upon which some input sampling could be performed. Since it is of exactly the same frequency as the sound output sampling rate, it might be used to help digitize an input sound into the same number of samples needed to output it at a loter time. The SOUNDER cutput is used ta turn the sound hardware on and off as described in the Sound Herdware document. A value of 0 is the “on" state and a value of “!" is the off state. Chenging this bit from within & user program is harmless as the worst possible event is simply a constent sound output. The VSYNC input is used as an interrupt upon which many time related tasks are performed by the Macintosh operating system. it will go low during every vertical retrace. (A rate of 60.1474 Hz.) This input could aiso be used ta perform such things as flicker free video page switching. The KBD.CLK is generated by the keyboard/keypad to transfer dete to and from the shift register in the 6522. Date enters and exits vie the KBD.DATA line. These two lines are of use only when writing 6 replacement keyboard driver. Gverall, attempt to use an operating system routine to alter these 1/0 bits to retain compatibility with different herdware (such es the Lise) Where this is not possible, make sure that the system is @ Macintosh snd carefully alter the needed bits. PAO Output suo Low order bit of volume select PAT Output sui Niddie order bit of volume contre! PAZ Output sv2 High order bit of volume control PRS Output SNO.PG2 — Sound/disk page select PA Output OUERLAY © RON/ARN select PRS Output DISKOUT Disk command output PRE Output VID.PG2_ ‘Video page setect PR? input SCCU/REQ OMA request signal from SCC PEO Input/Output ATC.OATA Data to/from RIC pin 6 P81 Output RIC.CLK Data clock to RIC pin 7 82 Output RIC.EN Enable signal to ATC pin 5 PB3 Input MOUSE.SHC House button input Pe4 Input MOUSE.X2° House quadrature input PES Input MOUSE.¥2 House quadrature input PE6 Input HSYNC2 Horizontal syne signal FB? Output SOUNDEN Sound lilt enable/reset crt sync Vertical syne interrupt input cre, RIC. 1HZ 1 Hz square wave from ATC pin 1 cet KBO.CLK Data clock input from keyboard 82 Input/Output KBD.DATR Data to from keyboard The Ii Undergramad a ©1985 Mouse Hardware At any moment of time, the position of a mouse can undergo three possible state changes (for each axis af movement). These are: move left, stay in place, and move right. Informetion about these state changes must be sent out of the mouse, Basically, twa ways exist to do this: either the computer can be told of each change or the mouse cen output it's present position from which each change can be deduced. The first method is difficult to do with & limited amount of hardware since two (or more) successive “move left” operations must be distinguisheble from just one Thus the second method is employed in most mice. Encoding the full rouse pointer position in the mouse hardware itself is not practical because of the amount of data this would require. Thus, the mouse sends only the mintmurn amount of information needed to decode each movernent. (This mavement is then used to control the pointer movement.) Three distinguishable positions are enough to express ail of the three possible state changes, These three positions are: the next left, the present, and the next right positions. Because these must be encoded as binery number, et least 2 bits sre needed. However, 2 bits of data can encode 6 total of four values so thus four positions are used. Note thet at any time, only three of the four will be used Four consecutive positions of the mouse could be numbered 0, 1, 2, and 3. When the mouse is in positions 1 or 2, it always hes another position available to the right or left. This is not true for locations 0 snd 3. Therefore, the number codes repeat as the following endless sequence: 23012 12... As the mouse moves in either direction, it traverses this set of numbers. The encoding of these position numbers in binery must be done in @ special way. The initially sbvious way of mapping them in the stendard numerical binary sequence (0 to 00, 1 to 01, 2 to 10, and 3 to 11) will not work, Two of the transitions (1 <-> 2 and 3 <-> 0) in this type of coding hove more than one bit chenge. Since the binery values will be generated mechanically in the mouse, the two transitions cannot be gueranteed to be simultaneous. What is needed is a coding where one bit changes at a time. (This is known as 4 Gray cade.) The only 2 bit Gray code is: .., 10, 00, 01, 11, 10, 00,... read in either direction. The Macintosh mouse uses this cade When this sequence is graphed with respect to time, the result looks like two square waves that are 90 electrical degrees offset from each ather (one cycle is 360 degrees). For this reason, such signals are often seid to be in quadrature. The I Ondergreand 7 @ 1985, Listing | - Mouse signal demonstration program, 10 IRB=157209568* 20 MOUSEX1 = 10485754" 30 MOUSEY! = 10485752* 100 IF PEEK(MOUSEY 1} AND &H8 THEN PRINT “1°; ELSE PRINT “O°, 110 IF PEEK(IRB) AND &H20 THEN PRINT “1 *; ELSE PRINT “O. 120 IF PEEK(MOUSEX 1) AND &H8 THEN PRIN "; ELSE PRINT 130 IF PEEKCIRB) AND &H10 THEN PRINT "1"; ELSE PRINT “O 140 IF PEEK(IRB) AND &H8 THEN PRINT “1” ELSE PRINT “O" 150 GOTO 100 ‘The ID Gadergreand © 1985 -3- 00 02 808 004 008 ong O0E oro a12 014 oS, ar ar oe ow aE 20 022 023, 025 oz? 029 028, 020 s4 EY jS021PAGEO - Comments by The IM Underground = result flag $70 = OK $77 = Error 7 Fast of RAM reinitial ized Uses All SFiU1 RAM with one bit pattern NOU RO,#802 Load starting test address NOU RI,8$3E Load size to test (62) NOU SFO,*$AA Put value into RAM INC_ RO [Advance pointer Duti2 R1,$067 ‘Loop through all focations jOheck if ali locations heid this value 8, 9070 O74 O78 ore o7n or OPE OF oat 033 086 087 03a 88 ost osF 094 096 098 098 ogc 09 ORG on orc 89 §8 Fo 8 03 6, £9 B 18 29 Ey ES FO 18 03 36, 9 23 54 aes 3 02 35 ce 3 asa RB Bas 38, 53 a cc 20 HOU RI,#$3E Load size again NOU RO,8$02 Load start again HOY A, 8RO jFetch value there INC RO jAdvance pointer XRL A, ¢AA jSee if it was $AR uNz_ $080 Elf error, exit DUNZR1,9070 Loop for’rest of RAM JFIIL RAM with other bit pattern MOU RE,8§9E Load size again MoU RO,#§02 Load start again Moy @F0,*655 Put Fisk keyboard for data HOU A, #514 jkoad command byte cau S32 }Send the byte to the keuboard Jz $08 j1f the Keyboard took the byte Hou A, #880, Shead mask cALL $205) }Set keyboard absent flag SNP $007 Skip ahead HOU A, 8$7F jkoad mask CALL $201 [Clear keyboard absent flag CALL $380 HReceive return code fron the keyboard NOY 5,4 [Save it if no changes code pif 30, then don’t give to Hac NOU RD, FS Load FIFO pointer ALL $283 jSave the returned value jSean Keus and put result in the keypad FIFO CALL $28 jSean keys wt $00 SIT nothing changed HOU RO,583R Load FIFO pointar CALL $289 [Save result CALL $308 jGheck FIFOs for data se $0Fo jBon’t bother with qucke stuff if data to send jAecount for extra tine taken to talk to keyboard MOY fO,#820 — jLoad flag pointer HOU A, 9R0 jGet the Tiag byte FLC A jCheck the keyboard present flag SNE $0F iif present, send quake codes at faster rate Hou A, 802 jload ask XPL A, 8RO JFlip Ot of flag bute NOU 30,8 [Replace result NL A, #02 jCheck new status of Dt NZ $0FD iSend data at half rate if keyboard absent jOheck if “awake code” (or “no changes") should be sent MOY RO,892E Load pointer to another fiag INC 8RO [Count loops Moy A, 8RO jReplace result ca c jSet up for 6502 type AOD ADOC A,#SE4 Essentially see if A was less than 28 SHC $0FD Jif so, then continue MOU ERO,A jLoad new result (0) 112 114 118, We 119 18 110 WF 121 138 60 125 2 128 2c 120 12 74 08 Fe 25 80 78 Fo. 6 $B Be 20 Fo 5304 36 4? 36 a eA a2 EF 3 ac 86, 23.04 54 cc 4 FC wn SIF 1Send an awake code check for what needs to be done "OU RO,882F Load pointer to S10 flag byte NOU 8, 680 [Oct the value one $108 FIT tt contained @ commana CALL. $28F STest P20 input from tac $110 SLT inactive, retcop CALL sar jReceive the’ byte fron the Mac MRL ALS§14 [See if it a data request command a2 $1iF jSend a response to the tac nou A, 220 jet the byte again XALA,8$10 «Check if it was permission to send oz $125 5Lf 0 OU A, #80 [Get the byte again WAL ALe$16 Is it a reset command wz Sie SH 30 HOU A, ERO Jet command again PAL A.8$40 Check for special Keyboard self-test fag Oz $82 Mell the keyboard to test itself np $045 jheck for keypad self test or HHP jBrancn te top of leop in different page of ROM ANP $08C Yector to start of keypad loop up data or an quake code CALL $308 jCheck FIFOs for data se $125 Jif some data there HOU ERO,*§78 [Place response at ($30) sSend @ byte to the tac if it exists HOU RO,§9A Load pointer HOU A, Fo sSet the tute 2 $188 JI nothing in keypad FIFO Moy RD,9$2¢ Load flag pointer HOU A, BRO [Set contents FHL A, #504 jlask for 02 NZ $147 [if the prefix vas sent, send a data byte Send a $79 Keypad data prefix to the tac HOU RO,8895 —— j Load pointer NOU eR,#$79 Load data to be sent CALL $28R iClear tiner STF $102 JOn timeout, try to receive a byte CALL $25F Hest P20 ifput SNe $137 Sait until Hac does not want to send PALL $380 [Send a byte to the Hac ALL $286 jReset tiner and timeout pask HOU A, #604 Load mask eaLL $200 iSet prefix sent flag SEP $0RC jReloop 192 194 195 197 1968 Ba 34 Ft ce 99 Po jO021PAGEY - Comments by The 1M Underground 1985 jScan the keyboard and return the needed codes JEntry Hone [Exit P= 0 If me valid change : SY = 1 If a valid change A= AS = Result code jUses A,F,RO,R1,R2,R3,R4,AS,A6,A?, 22 NOU RI,8934 Load pointer inta FiFO HOU Raat {Set last bute in FIFO 2 $198 SIF roan in FIFO for another key cin A ee" THIS: 1S A BUBT ee jThe above line should be CLAS to flag no changes. As is, Jif the FIFO is full ond CY was set orion to calling th Jroutine, The last entry will be smashed with the present jeontents of RS. However, another pair of bugs that do rot jaliow the entire FIFO to be used, will cause this code to jnever find @ FIFO full condition and thus this bug is bypassed PET jDon"t scan if no soace erform a scan MOU R1,#620 Load pointer to key status array 12 8,367 Lead output data QUTL P2,A [Enable P21 cutput CALL SIE STest this row of keus HOU A,SSFF Load inactive data OUTL P2,A sTurn outputs off ue $198 JExit if there waz a change NGUA,S8FE Load starting scan code HOU RG,A pSave it eUTL P1,R }Select a scan iine from Pt ine RY [Advance key status table pointer CALL $tEE STest this row of keys NOU A,SSFF Load inactive value OUTL 1,8 jDeselect the port tine se $180 JExit if there was a chonge [Get current sean status [Set [Move the scan line to the ieft jReloop for another {ine [Advance table pointer to shift status [Get the shift key status [See if anything changed 51f thare was a change - process it [Flag ne changes done pCompute the key codes of a SHIFT type key Entry A= Change mask Pointer inte status table 0 If no valid change 1 If @ valid change JExit 102 14 1c 18 107 ice 1c9 1c 160 10 ice 100 11 103 195. 10? 108 10a 18 10 10F 160 11 tes 15 1ER iB 1c 10 tee 1EF 1Fo 12 1s 1F4 1F6 1? e? Bc 0? £9 £0 W ea £? oF £9 cy uses /F2,3,R4,85,81 CALL $267 Compute a change mask CALL $281 jDelay 4.2 as for dabounce ALL $206 [Read shift status again HOU A, 8A jet ofd status AML ARS SMask for only current key 109 FAA jSave the result HOU ALAS Now fetch the shift status AN. AFB Mask it for oniy the current key RL ALP [See If old and present status is sane v2 $1BC JExit if this key “bounced” HOY A, FS }Get the changed nask XRL A, 8A SChange the bit in the array HOU AIA [Replace the neo result NOY A, FS [Compute key number fron the mask PRC Al Slest if it was OPTION SNE $107 JIf not, skip to next test HOU 8, 8875) jOPTICN'= 58 ne $1ES [Skip to end Fac @ Has’ it SHIFT? ANE $180 SIT not, skip to next test O08, 8871 JSHIFT = 56 une $1E9 }Skip to end NOP HTake up waste space HOP Hake up waste space RRC A jSee if was CTRL oNC $187 i1f not, assume CAPS LOCK HOU A, #55F ='55 oiiP $1E9 iSkip to end HOU A, 887 JCAPS Lock = 57 ORL ALA2 }Conbine with pushed/releazed info NOU RS,8 jSave result cir [Put a zero there cL c JSet C¥ to show key FET [Done jDebounce a keyboard key read from PO [Entry At = Pointer to key status table 7 Forts set up to read the keys from PO [Bat GY = 0 Tf no valid keypush eY = 1 If a valid change q AL= RS = Result code [Uses 9,F,R2,R3,R4,F5,R6,R?, 81 oP jDelay IN A, PO iGet key status on 8, #800. jRemove non-scan lines Nou RSA [Save result XFL A, 8B jSee If there were any changes NZ IPB iIf so CLR Cc 2Flag one FET TExit then sBebounce @ key and compute it's return code “Changed nask” Ri = Pointar to key status table FS = Initial read status of keys Scan line sat up to read the keys Y= 0 If no valid change 1 If valid change 35. F,P2,R3,R4,A5,R6,R7,81 54? Compute aask of one of the kee 54 At ioeloy 4.2 n= FI tog Aart ioet the present status SB AML ALAS ‘ask it for oniy one key aC MoU R48 Save result FS HOU ALA [Get contents fE HOU RB, PUSH it BS 2C MOU RO, #$2C jLoad pointer FO HOU a, ard jet flag byte 87 RCA “check [2b Fett Jo $21 pif set (performed as if keypad) oo HOR jBeiay os IN APO Get status of Keys again Se AML A, iHask fer only the present one Of RL ABs [See if status change still present 98 27 nz $327 [Yes ~ then a vai id change FE HOU A, AS [POP aig AO contents 8 tou Fa, Sreptace then RS {Flag no changes RET ‘Done F nou aR jGet table pointer 03 24 RL RLAI24 See if 24 0807 wz S267 [Then status cones from PO 03 0? XRL8,#907 See if was 28 98 1 nz $210 If the sean is oul tiplexed oN ALF [Set keys fron here 44.09 UMP $209 join rest of code oa IN AP2 Get mul tipleved keys 7 mA Hess 43-79 OR A, 8SF9 Mask for oniy P22,P23 56 af JT1 $209 Gif OK, then join rest 53FE ANDALSIFE ‘Copy Ft to OD 44.09 UMP $209 jdoin rest of code 227 MOY RO,8$2C Load pointer to keypad fing byte 229 roy 9, €R0 jGet the flog 2A AND A, #$08 STest a bit (This wii! always te a > 220 NZ $241 [Skip 2-key ro! lover fini ting 2E HOU RO,#§20 Load pointer to # of keys pushed 230 HOU A, AS jGet scan resuit zt FNL ALAS Mask for the present key m2 2 $258 HIT it was pushed 2340 FO OY 8D [Get present vaiue 25 05 41 oz $241 fOon't let it go negative 270? A jRenove one 238 FO MOU eRO,A [Replace result 239 238 23C 2a 242 243 244 248 242 248 249 248 248 24C 249 Dae 24F 256 257 259 2A 25C 25E 2 260 262 264 265, 28? 268 209 26h 268 260 28E 270, 23 224 75 2 4441 une $241 jSkip to resaining code FO HOU A, €RO Net flag vatue 52.02 AML R,S#02 Sea if 2 KeUS pushed 9600 nz $200 HLT so, then don't take this one 10 INC 80 SCount’ keys pushed jSet mask JFlip status of that one key pRaploce result iGet table pointer jDonpute the offset from start (20) [Save value for multiply oy & iClear to allow 6502 style ADD sTimes 2 jTimes 4 jTines 5 Times 6 Add position in this row of the key jSet it (eas still clear? jMake 'sb a ene Cfor a stop bit? ;Combine vith pushed/released info 24ER MP $tEA fdoin exit code jScan keypad keys Entry None Exit’ C¥ = 0 if no change found tif change foun fesul t code 8, BO, 81, 2, RB, Ra, BS, R67, 82 jLoad buffer pointer [Get last byte of buffer [Get ready to show ne change jf space in buffer jon’ t do anything jhoad initia! nask value jload pointer to key status jSave port valu: }Select a scan jSean this group jload inactive value jDeselact the tine HIf a key change sas found [Advance table pointer Set it jGet present select byte jMove over to right SIf not done vet jGet status of sone nore keys 54.82 CALL $282 jTest these Fe 7a de $278 iia change 3 GNC RY Advance table pointer fa fe Delay os iN A,PO ‘oat remaining keys 4357 GAL A,AIE? Mask’ for only tuo’ lines 44°82 NP $282 pOheck these 28a 288 BC 28E 201 203 2c5 208 28 2cA 2c 20E 2c 200 62 16 BE 83, 7 on 53.01 6 cB 33 01 6 cB cd 83 B8ss cur a jload 0 jLoad a value to the tiner 5 This routine can be used to initialize the tiner [ond to clear the timer fiag [entry A= Data jSend it to tiner [Clear timer flag [Done sCopy P20 input to c¥ j. This routine will test the P20 serial tine, It [sill do a small anount of checking for noise also jéntry P20 = 1 Cto allow input) [Exit CY = P20 ses AF cua c iClear result flag IN 8, P2 Get F2 data FAL A, #601 jffask for P20 input from Hae a2 $23 SIF aetive, exit IN Ree Jat data again AML A,8E01 Check it again in case of noise 2 $288 Exit if active now cel jP20 was a one FET Bone jOF A to flag } This routine can be used to set bits in the options flag byte jEntry A= Mask [Exit A= Resuit : FO = $20 <$20) = ($20) OR A jUses A, RO, <$20) MoU RO,#820 Load address pointer ORL 8, 8RO Or naw value to old MOU GRO, A jReplace result RET [Done 201 203 204 205 206 207 208 208 20C 20 2E0 2Et 2E2 264 266 on 43 FO 56 DE 53 FE 53 6F Ro 08. 53 40 40 33 jANO A to fieg 5. This routine can be used to clear bits in the ‘options flag bute. fentry =Hask jexit A= Result m0 = $20 $20) = ($20) AND A jUses A,AO, ¢$20) MOU RO,8$22 Load address pointer AML A, SRO 58nd new value HOU 8RO, A [Replace result FET Done jRead special Keus from keyboard [This subroutine wili read the status of the Jspecial keus on the keyboard and return the Jrasuit in the format needed for tha key jtapte, Entry P06 = P22 = P23 = jExit a result (O = pushed) } 50 = OPTION Dy = SHIFT 02 = CTRL. q 2S = CAPS Lock 93-08,07 = 1 Wises 8,35 IN B,P2 jGet special key status AR Al pThrow auay P20 serial input OR A, 8969 jMask for oniy SHIFT and CTAL att $208 jTest OPTICN ANL A, 88FE STransfer it to 09 ith other keys FNL A, #88 jClear bit for CAPS LOCK status HOU RSA [Save resuit IN RPO jGet CAPS LOCK status NLA, #840) IMask for oniy it ORL 8 FS }Dombine with other status NOU RSA pReplace result RET [Sone jSet up masks for a keupush jThis routine will take @ mask vith t's at the locations juhere a key changed state and single out one of then Sand prepare a mask to use to process it further, Key jreleases are processed first so that the flac dogs not jsee more keys pushed at any tine than there real ly are,

You might also like